{"text": "\\section{Markov chain Monte Carlo (MCMC)}\n\nIn this thesis, Markov chains were used to train the presented \\acl{sorn}. Before the specific methods are addressed, some theory about Markov chains is introduced.\n\n%%%%% Markov chains %%%%%\n\\subsection{Markov chains}\n\n\\emph{Markov chains} contain a number of states which are changing with a specific probability. The \\emph{markov property} states that the probability of the current state only depends on the immediate previous state. Therefore, the Markov property in the discrete case can be defined as follows:\n\n\\begin{definition}[Markov property]\nLet $(\\Omega, \\mathcal{F}, \\Pb)$ be a probability space and $(S, \\mathcal{S})$ a measurable space, where $S = \\{x_1, x_2, ... \\}$ is a countable set, called state space. A stochastic process $X = \\{ X_t : \\Omega \\to S\\}_{t\\in\\N}$ is said to possess the Markov property if and only if for each $x_0, ..., x_{t+1}\\in S$ and $t\\in\\N$\n\n\\begin{equation}\n\\label{eq:markov-chain}\n\\Pb(X_{t+1} = x_{t+1} | X_{t} = x_{t}, X_{t-1} = x_{t-1}, ..., X_0 = x_0) = \\Pb(X_{t+1} = x_{t+1} | X_{t} = x_{t}).\n\\end{equation}\n\\end{definition}\n\nThe Markov property is also called \\emph{memorylessness}, since it is sufficient to memorize the probability of the state before, no further information is necessary.\n\nThe probability of changing from one state to another is called \\emph{transition probability}, which is defined as\n\n\\begin{equation}\n\\label{eq:trans-prob}\np_{ij}(t) = \\Pb(X_{t+1} = x_j | X_{t} = x_i),\n\\end{equation}\n\nwhere $x_i, x_j \\in S$ and $i,j \\in \\N$. The transition probabilities can be summarized in a \\emph{transition matrix}. A transition matrix for a finite Markov chain where $i,j \\in \\{1, ..., n\\}$ with $n \\in\\N$ has the form\n\n\\begin{equation}\n\\label{eq:trans-matrix}\nM(t) = (p_{ij}(t))_{i,j \\in \\{1,...,n\\}} = \\begin{bmatrix}\np_{11}(t) & p_{12}(t) & \\hdots  & p_{1n}(t)\\\\\np_{21}(t) & \\ddots &  & \\vdots \\\\\n\\vdots &  & \\ddots & \\vdots \\\\\np_{n1}(t) & \\hdots & \\hdots & p_{nn}(t)\n\\end{bmatrix}.\n\\end{equation}\n\n\\nomenclature{$M$}{Transition matrix of a Markov chain}\n\n% transition graph\n% reference to graph from properties\n\n%%%%% Properties %%%%%\n\\subsection{Properties of Markov chains}\n\\label{sec:markov-properties}\n\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}{\\textwidth}\n    \t\\centering\n        \\includegraphics[width=0.7\\textwidth]{sorn_markov/mc-irreducible}\n        \\vspace{5pt}\n        \\caption{In irreducible Markov chains every state is reachable in finite time, independent of the present state. The first chain on the left side fulfills this property, while the center and right chain do not. The center chain may start in $A$ or $B$, but if $C$ is reached, $A$ and $B$ are not reachable any more. In the right chain, states $A$ and $B$ are totally separated from $C$ and $D$.}\n        \\vspace{15pt}\n        \\label{fig:irreducible}\n    \\end{subfigure}\n    \\begin{subfigure}{\\textwidth}\n    \t\\centering\n        \\includegraphics[width=0.7\\textwidth]{sorn_markov/mc-aperiodic}\n        \\vspace{5pt}\n        \\caption{A state is periodic, if it returns back to the same state periodically, if not, the state is aperiodic. In the chain on the left side every state is periodic, since every state returns after $4$ steps. Therefore, the whole chain is periodic. On the right side, only state $B$ returns periodically every second time, states $A$ and $C$ are not periodic.}\n        \\vspace{15pt}\n        \\label{fig:aperiodic}\n    \\end{subfigure}\n    \\begin{subfigure}{\\textwidth}\n    \t\\centering\n        \\includegraphics[width=0.7\\textwidth]{sorn_markov/mc-recurrent}\n        \\vspace{5pt}\n        \\caption{If a state will be reached again almost surely, it is recurrent, otherwise transient. Two simple examples are given on top left. In the first small chain, both states $A$ and $B$ will be reached again all the time. In the second example $A$ directly goes to $B$ and will not be active any more. State $A$ is transient. On the top right, states $A$ and $B$ are transient. If $C$ is activated the first time, the chain will never reach $A$ and $B$ again. On the other hand, $C$ and $D$ are recurrent, both can be reached again all the time. The last example on the bottom shows a null recurrent case. Shown is a Markov chain with infinite states. Since the probability of going back to $A$ is decreasing with a sequence $1/n$ for $n \\to\\infty$, the time to go back to $A$ is $\\E[T_A] = \\infty$. Regarding the last chain, more details can be found in a proof in appendix in section \\ref{sec:proof-null-recurrent}.}\n        \\label{fig:recurrent}\n    \\end{subfigure}\n    \\caption[Markov chain properties]{Three properties of Markov chains are shown: irreducibility, periodicity and recurrence. If no probability is written at an arrow, the probability is simply $p > 0$.}\n    \\label{fig:mc-properties}\n\\end{figure}\n\n\\paragraph{a) Homogeneous / Stationary Markov chain}\n\nIf the transition probabilities $p_{ij}(t)$ from state $x_i$ to state $x_j$ are independent from time $t$, i.e. $p_{ij}(t) = p_{ij}$ for all $t\\in\\N$, the Markov chain is called \\emph{homogeneous} or stationary Markov chain. It means that\n\n\\begin{equation}\n\\label{eq:markov-homo}\np_{ij} = \\Pb(X_{t+1} = x_j | X_t = x_i) =  \\Pb(X_t = x_j | X_{t-1} = x_i).\n\\end{equation}\n\n\\paragraph{b) Irreducible Markov chain}\n\nIn \\emph{irreducible} Markov chains, any state is reachable in finite time, independent of the present state. Formally a Markov chain is irreducible if there exists any $m < \\infty$ with\n\n\\begin{equation}\n\\Pb(X_{t+m} = x_j | X_t = x_i) = p_{ij}^{(t+m)} > 0\n\\end{equation}\n\nfor all $i,j$. Examples for reducible and irreducible Markov chains are given in figure \\ref{fig:irreducible}.\n\n\\paragraph{c) Aperiodic Markov chain}\n\nIf a state $x_i$ returns with a multiple of $k$ again to state $x_i$, it is called \\emph{periodic}, otherwise \\emph{aperiodic}. Formally a \\emph{period} is defined as\n\n\\begin{equation}\nk = \\text{gcd} \\{ t > 0\\,:\\,\\Pb(X_t = x_i | X_0 = x_i) = p_{ii}^{(t)} > 0 \\},\n\\end{equation}\n\nwhere $\\text{gcd}$ is the greatest common divisor. If the set is empty, the period is not defined. In case that $k=1$ the state $x_i$ is aperiodic and otherwise, if $k>1$, $x_i$ is periodic.\n\nIf all states are aperiodic, the Markov chain is called aperiodic. Examples for periodicity and aperiodicity are given in figure \\ref{fig:aperiodic}.\n\n\\paragraph{d) Recurrent Markov chain}\n\nA state $x_i$ of a Markov chain is called \\emph{recurrent} if it  will be reached again almost surely. Therefore, the probability to come back to state $x_i$ is one. Let\n\n\\begin{equation}\n\\label{eq:first-comeback}\nT_{x_i} = \\inf\\{ t \\ge 0 \\,:\\, X_t = x_i | X_0 = x_i \\}\n\\end{equation}\n\n\\nomenclature{$T_{x_i}$}{Number of steps until a Markov state is reached again for the first time}\n\nbe a random variable, which defines the number of steps until state $x_i$ is reached again for the first time and let $\\Pb(T_{x_i} = t)$ the probability to reach $x_i$ again for the first time after exactly $t$ steps. Then state $x_i$ is recurrent, if and only if\n\n\\begin{equation}\n\\label{eq:recurrent}\n\\Pb(T_{x_i} < \\infty) = \\sum_{t=1}^\\infty \\Pb(T_{x_i} = t) = 1,\n\\end{equation}\n\nIf a state is not recurrent, it is called \\emph{transient}, which is the case if $\\Pb(T_{x_i} < \\infty) < 1$. It means that the state will not be reached again almost surely.\n\nFurthermore, if the state is recurrent and the expected value is finite, thus\n\n\\begin{equation}\n\\label{eq:first-comeback-expect}\n\\E[T_{x_i}] = \\sum_{t=1}^\\infty t \\cdot \\Pb(T_{x_i} = t) < \\infty,\n\\end{equation}\n\nthe state is called \\emph{positive recurrent}. Otherwise, if $\\E[T_{x_i}] = \\infty$, it is called \\emph{null recurrent}.\n\nIf all states are (positive) recurrent, the Markov chain is called (positive) recurrent. Examples for recurrent and transient Markov chains are given in figure \\ref{fig:recurrent}. A proof for the null recurrent chain in the figure can be found in the appendix in section \\ref{sec:proof-null-recurrent}.\n\n%%%%% Stationary %%%%%\n\\subsection{Stationary distribution}\n\\label{sec:stat-markov}\n\n%* Definition of stationary distribution\\\\ \n%* Theorems about stationary distribution\n\n\\begin{definition}[Stationary distribution]\n\nGiven a homogeneous Markov chain in discrete time $t \\in \\N$ on state space $S = \\{x_1, x_2, ...\\}$, the distribution $\\Pb_\\pi$ is called stationary distribution if and only if\n\n\\begin{equation}\n\\label{eq:markov-stat}\n\\bm\\pi_{x_j} = \\Pb_\\pi(X_t = x_j) = \\sum_{x_i \\in S} \\Pb_\\pi(X_t = x_i)\\,p_{ij} \\overset{\\eqref{eq:markov-homo}}{=} \\sum_{x_i \\in S} \\Pb_\\pi(X_t = x_i)\\,\\Pb(X_t = x_j | X_{t-1} = x_i)\n\\end{equation}\n\nfor all $x_j \\in S$.\n\\end{definition}\n\n\\nomenclature{$\\bm\\pi$}{Stationary distribution of a Markov chain}\n\nThe stationary distribution should not be confused with the stationary Markov chain. While the stationary Markov chain is stationary regarding the transition probabilities, the stationary distribution is stationary regarding the probability of the states. Furthermore, the presence of a stationary Markov chain (homogeneous Markov chain) is a condition for the existence of a stationary distribution.\n\nIt is not always given that a stationary distribution exists. Furthermore a stationary distribution is not necessarily unique. In the following, first, the general Perron-Frobenius-Theorem \\parencite{seneta2006non, pillai2005perron} is presented. Based on this theorem, a statement about the stationary distribution can be derived. While this theorem is highly useful, it assumes aperiodic Markov chains, which are not given in any case. Hence, afterwards another theorem is introduced, which lowers the assumption. At that point I want to remind, that a \\emph{homogeneous} Markov chain is assumed in the following.\n\n\\begin{definition}[Primitive matrix]\nGiven a squared matrix $Q = (q_{ij})_{i,j \\in\\N}$, it is called a primitive matrix if all items are non-negative, $q_{ij} > 0 \\,\\forall i,j$, denoted by $Q > 0$ and if a $k \\in \\N$ exists, such that all items of the matrix $Q^k$ ($k$-th power of $Q$) are positive, denoted by $Q^k > 0$.\n\\end{definition}\n\n\\begin{theorem}[Perron-Frobenius]\n\\label{eq:perron-frobenius}\nSuppose $Q$ is an $n \\times n$ non-negative primitive matrix. Then there exists an eigenvalue $r$, called Perron-Frobenius eigenvalue, such that:\n\n\\begin{enumerate}\n\\item $r$ is real and positive, $r>0$.\n\\item $r$ can be associated with strictly positive left and right eigenvectors.\n\\item $r > |\\lambda|$ for any other eigenvalue $\\lambda \\neq r$.\n\\item The eigenvectors associated with $r$ are unique to constant multiples.\n\\item If $0 \\le B \\le Q$ and $\\beta$ is eigenvalue of $B$, then $|\\beta| \\le r$. Moreover, $|\\beta| = r$ implies $B = Q$.\n\\item $r$ is a simple root of the characteristic equation of $Q$.\n\\end{enumerate}\n\\end{theorem}\n\nA proof is given in \\textcite[Theorem 1.1]{seneta2006non}. Using the Perron-Frobenius theorem it is possible to state in which cases a unique solution for the stationary distribution can be found.\n\n\\begin{theorem}\n\\label{th:markov-stat}\nLet $M$ be a transition matrix and $\\bm 1$ a vector where all entries are one. An irreducible and aperiodic Markov chain has a unique stationary distribution given by the solution $\\bm\\pi$ of $\\bm\\pi^T M = \\bm\\pi^T$, where $\\bm\\pi^T \\mathbf{1} = 1$.\n\\end{theorem}\n\nThis theorem will be proven, but two corollaries are necessary.\n\n\\begin{corollary}\n\\label{co:primitive}\nAn irreducible and aperiodic matrix is primitive.\n\\end{corollary}\n\n\\begin{corollary}\n\\label{co:smallest-largest}\nLet $Q$ be a positive square matrix. Then the minimal row sum is a lower bound and the maximal row sum is an upper bound of the the largest eigenvalue of $Q$.\n\\end{corollary}\n\n\\begin{proof}[Proof for theorem \\ref{th:markov-stat}]\nSince any transition matrix $M$ is per definition square and non-negative, the statements of the Perron-Frobenius theorem hold for transition matrix $M$, if the Markov chain is primitive. Since corollary \\ref{co:primitive} states that any irreducible and aperiodic matrix is primitive, the assumptions of the theorem are clarified.\n\nFurthermore, it holds that\n\n\\begin{equation*}\nM\\mathbf{1} = \\mathbf{1},\n\\end{equation*}\n\nsince every row sums to one by definition of the transition matrix. Hence, $M$ has an eigenvalue of $1$ and an eigenvector of $\\mathbf{1}$. With corollary \\ref{co:smallest-largest}, the largest eigenvalue is exactly the row sum $1$, since all rows of $M$ have the same sum. Therefore, the eigenvalue $r=1$ is the Perron-Frobenius eigenvalue, since property (3) of the theorem states that all other eigenvalues are smaller in absolute. The corresponding right Perron-Frobenius eigenvector is $\\mathbf{1}$.\n\nAssuming that a vector $\\bm v^T$ is normed, such that $\\bm v^T \\mathbf{1} = 1$, the eigenvalue problem for the left eigenvector $\\bm v^T$ has the following form:\n\n\\begin{equation*}\n\\bm v^T M = r \\bm v^T = \\bm v^T\n\\end{equation*}\n\nFrom statement (2), we know that the left eigenvector regarding $r$ is strictly positive. Therefore, $\\bm v^T = \\bm\\pi^T$ is a distribution, the stationary distribution.\n\nFinally, statement (4) of the Perron-Frobenius theorem states that $\\bm\\pi$ is unique.\n\\end{proof}\n\nAs a side note, using theorem \\ref{th:markov-stat}, the stationary distribution can be calculated as a right eigenvalue problem, just by transposing both sides $(\\bm\\pi^T M)^T = (\\bm\\pi^T)^T$, which results in $M^T \\bm\\pi = \\bm\\pi$.\n\nTheorem \\ref{th:markov-stat} is limited to aperiodic Markov chains. Another theorem lowers the assumptions.\n\n\\begin{theorem}\n\\label{th:irr-rec}\nAn irreducible and positive recurrent Markov chain has a unique stationary distribution $\\bm\\pi$ given by\n\n\\begin{equation}\n\\pi_{x_i} = \\frac{1}{\\E[T_{x_i}]}\n\\end{equation}\n\\end{theorem}\n\nA proof is given in \\textcite[Corollary 1.2.29]{bladt2017matrix}. The theorem uses the definition of the random variable $T_{x_i}$ from equation \\eqref{eq:first-comeback}, which indicates the number of steps, necessary to come back to state $x_i$ again for the first time. Furthermore $\\E[T_{x_i}]$ was defined in equation \\eqref{eq:first-comeback-expect}.\n\n\\begin{theorem}\nAn irreducible and finite Markov chain is positive recurrent.\n\\end{theorem}\n\nThis theorem is proven in \\textcite[Theorem 3.3]{bremaud2013markov}. It shows, that theorem \\ref{th:irr-rec} is highly practical for finite Markov chains. Since, in case of finite Markov chains, only the property of irreducibility needs to be fulfilled.\n\nThe Perron-Frobenius theorem has a slight advantage, compared to theorem \\ref{th:irr-rec}. Using the Perron-Frobenius theorem, it can be shown that even a \\emph{limiting distribution} can be obtained. It is defined by $\\pi_i = \\lim_{t \\to\\infty} \\Pb(X_t = x_i)$. In case of theorem \\ref{th:irr-rec}, this is not necessarily the case. If we assume for example a periodic Markov chain with just two states, which are alternating $(0,1,0,1,0,1, ...)$, the Markov chain has no limiting distribution, but a unique stationary distribution. However, for calculating stationary distributions, in most cases theorem \\ref{th:markov-stat} was used.\n\n%%%%% Measures %%%%%\n\\subsection{Measures}\n\\label{sec:markov-measures}\n\nTo evaluate the stationary distribution many measures can be used, which are common for any distribution, not only for Markov chains. Two types are introduced, which are used in the results. At first, information measures, namely variance and Kullback-Leibler divergence, are defined and afterwards a measure for the concentration of a distribution is presented, where the Lorenz curve and the Gini coefficient are introduced. Note that the Gini coefficient is directly derived from the Lorenz curve.\n\n\\paragraph{Information measures}\n\nFor simplification, the state space can be defined as $S = \\{1, ..., n\\}$ where $n \\in\\N$. A simple measure for the stationary distribution is the deviation of the probabilities from their mean probability. Therefore an empirical variance measure is used by calculating\n\n\\begin{equation}\n\\label{eq:variance-estimate}\n\\sigma^2_\\pi = \\frac{1}{n} \\sum_{k=1}^n (\\pi_k - \\bar\\pi)^2,\n\\end{equation}\n\nwhere $\\bar\\pi = \\frac{1}{n} \\sum_{k=1}^n \\pi_k$. In the following it is just called \\emph{variance}.\n\n% If $\\Pi = (\\Pi_1, ..., \\Pi_n)^T$ denotes a random variable for the stationary distribution, the variance of the stationary distribution is given by\n\n% \\begin{equation}\n% \\label{eq:variance}\n% \\Var(\\Pi) = \\E[(\\Pi - \\E[\\Pi])^T (\\Pi - \\E[\\Pi])],\n% \\end{equation}\n\n% which can be interpreted as the expected squared distances between the probabilities of the stationary distribution and their expectation value.\n\n% Since the random variable $\\Pi$ depends on the stochastic transition matrix, with probabilities $\\Pb(X_{t+1} = x_i | X_t = x_j)$, where $X_t$ is the random variable of the current state at time $t$, it is not easy to obtain the variance analytically. Therefore, a simple estimator is suggested, defined by\n\n% \\begin{equation}\n% \\label{eq:variance-estimate}\n% \\widehat{\\Var(\\Pi)} = \\sigma^2_\\pi = \\sum_{k=1}^n (\\pi_k - \\bar\\pi)^2,\n% \\end{equation}\n\n% where $\\bar\\pi = \\frac{1}{n} \\sum_{k=1}^n \\pi_k$.\n\nAnother measure uses the Kullback-Leibler divergence. If $\\bm\\pi' \\in \\{\\pi'_1, ..., \\pi'_n\\} = \\{1/n, ..., 1/n\\}$ is a stationary distribution where all states are equally probable, the Kullback-Leibler divergence can be obtained by\n\n\\begin{equation}\n\\label{eq:kullbackleibler}\n\\DKL = \\sum_{i=1}^n \\pi_i \\ln{\\left(\\frac{\\pi_i}{\\pi'_i}\\right)}.\n\\end{equation}\n\nThe Kullback-Leibler divergence can be understood as relative entropy. It describes the increase in information which is necessary to describe $\\bm\\pi$, when $\\bm\\pi'$ is given. It is important to note that the Kullback-Leibler divergence is an asymmetric measure. The value of the measure depends on the order of the distributions and therefore the divergence does not fulfill the properties of a \\emph{metric}. It is in particular different from the \\emph{total variation distance} $\\delta(\\bm\\pi, \\bm\\pi')$. A link between the total variation distance and the Kullback-Leibler divergence is given by \\emph{Pinsker's inequality}. However, \\emph{Gibb's inequality} states that\n\n\\begin{equation}\n\\label{eq:kullbackleibler-gibbs}\n\\DKL \\ge 0\n\\end{equation}\n\nand $\\DKL = 0$ if and only if $\\bm\\pi = \\bm\\pi'$, which means that a divergence of $0$ indicates a match between the distributions $\\bm\\pi$ and $\\bm\\pi'$.\n\n\\begin{SCfigure}[0.6][!b]\n    \\includegraphics[width=0.45\\textwidth]{sorn_markov/lorenz}\n    \\caption[Lorenz curve]{Illustration of a Lorenz curve. On the $x$-axis is the cumulative share of the probabilities from the states of an equally distributed stationary distribution. On the $y$-axis is the cumulative share of the probabilities of the actual stationary distribution. If the actual distribution is equally distributed, the Lorenz curve reaches the line of equality. The Gini coefficient is calculated by $G = A / (A+B)$.}\n    \\label{fig:lorenz-illustration}\n\\end{SCfigure}\n\n\\paragraph{Concentration measures}\n\nAnother way of evaluating the properties of a Markov chain is to plot the \\emph{Lorenz curve} and calculate the \\emph{Gini coefficient}. Traditionally, both is often applied to indicate inequality regarding income, used in social sciences. But the Lorenz curve shows the concentration of a distribution in general, whereas the Gini coefficient is a related measure for the intensity of the concentration of the given distribution.\n\nFirst, assume that $\\bm\\pi = (\\pi_1, ..., \\pi_n)^T$ is sorted in a sense that $\\pi_1 \\le ... \\le \\pi_n$ and denote $r_i = 1/n$ as the share of a state with probability $\\pi_i$, where $n\\in\\N$ is the number of states. Furthermore $R_k = \\sum_{i=1}^k r_i = \\sum_{i=1}^k 1/n = k/n$ is the cumulative share of the states. On the other hand, $P_k = \\sum_{i=1}^k \\pi_i$ is the cumulated probability of $\\bm\\pi$. The \\emph{Lorenz curve} shows the cumulated share of states $R_k$ at the $x$-axis and the cumulated probability $P_k$ at the $y$-axis. If all probabilities are equal, it will result in a straight diagonal line. The more the distribution $\\bm\\pi$ is concentrated, the more the line will appear in the right bottom corner. An illustration is given in figure \\ref{fig:lorenz-illustration}.\n\nFinally, the \\emph{Gini coefficient} $G$ is the ratio of the area that lies between the diagonal line, where all states are equal probable, and the area between the actual Lorenz curve and the diagonal. The more the Lorenz curve tends to the corner and, therefore, the more the stationary distribution is unequal, the more the Gini coefficient will tend to $1$, where $1$ represents a perfect concentrated situation. It means that the whole probability is concentrated at one state, the other states are zero. If the distribution is perfectly equal, the Gini coefficient will reach $0$. It can be shown that $G \\in [0,1]$ is half of the \\emph{relative mean absolute difference}. Hence, for the discrete case, the Gini coefficient is defined as\n\n\\begin{equation}\n\\label{eq:gini}\nG = \\frac{\\sum_{i=1}^n \\sum_{j=1}^n |\\pi_i - \\pi_j|}{2n\\cdot \\sum_{i=1}^n \\pi_i}.\n\\end{equation}\n\n%%%%% Monte Carlo %%%%%\n\\subsection{Markov Chain Monte Carlo (MCMC)}\n\nA \\emph{Monte Carlo simulation} is a stochastic procedure where random samples are drawn many times. As a result, numerical solutions for analytically difficult or even impossible problems are obtained. \\textcite{thomopoulos2012essentials} described the process as follows:\n\n\\begin{quote}\nTo apply the Monte Carlo method, the analyst constructs a mathematical model that simulates a real system. A large number of random sampling of the model is applied yielding a large number of random samples of output results from the model.\n\\end{quote}\n\nSpecifically, if random samples are drawn from the distribution of a Markov chain, it is called \\acfi{mcmc} method which includes a broad class of algorithms. Famous and well known algorithms are the \\emph{Metropolis–Hastings algorithm} \\parencite{hastings1970monte} or the \\emph{Gibbs sampler} \\parencite{geman1984stochastic}. These techniques are often used in Bayesian inference to evaluate posterior distributions.\n\nThere are many different possibilities to understand the behavior of neural networks under the perspective of \\acs{mcmc} sampling. For example, there are applications for Boltzmann machines \\parencite{osogami2017boltzmann} or energy-based models in general \\parencite{goodfellow2007deep}. In \\acs{sorn}, it is possible to view the learned time-dependent input patterns under the perspective of \\acs{mcmc} sampling. The approach will be introduced in methods (section \\ref{sec:methods}) and many illustrative implementations will be given in results (section \\ref{sec:results}).\n\n%%%%% MCMC / ANN %%%%%\n%\\subsection{MCMC and neural networks}\n\n%An overview to MCMC methods in neural networks is given in \\cite{andrieu2003introduction}.\n\n%Boltzmann machines, which are a special kind of a stochastic recurrent neural networks, highly depend on a MCMC approach. They are trained by stochastic gradient, where expected values need to be calculated. In many cases those expected values cannot be calculated analytically. Therefore MCMC methods, especially Gibbs sampling can be used to finally train Boltzmann machines \\parencite{osogami2017boltzmann}. The MCMC approach can also be used for the broader class of energy-based models \\parencite{goodfellow2007deep}.\n\n%MCMC can also be used for model selection. It can for example applied to estimate the number of neurons in a network (3 citations).\n% http://www.cs.ubc.ca/~arnaud/andrieu_defreitas_doucet_jordan_intromontecarlomachinelearning.pdf (Seite 23)\n\n%Sampling Maas / Sampling perspective\n\n%It can be summarized that MCMC plays an important role in specific applications of neural networks. The last application should be kept in mind, since in methods section another perspective is introduced, which is inspired by the approach of (paper Maas).\n\n%Where was it used in literature before? link to neural networks?\n\n%Introduce perspective to SORN networks -> In methods\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "19683cf9c0371ed9adad3ae022d24ebc3ca1e525", "size": 24048, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/5-markov.tex", "max_stars_repo_name": "sagacitysite/mastatistik", "max_stars_repo_head_hexsha": "9ef17edb27bee88b54c4241c6f9e3b78e49ef50c", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/5-markov.tex", "max_issues_repo_name": "sagacitysite/mastatistik", "max_issues_repo_head_hexsha": "9ef17edb27bee88b54c4241c6f9e3b78e49ef50c", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/5-markov.tex", "max_forks_repo_name": "sagacitysite/mastatistik", "max_forks_repo_head_hexsha": "9ef17edb27bee88b54c4241c6f9e3b78e49ef50c", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.7049180328, "max_line_length": 928, "alphanum_fraction": 0.7418496341, "num_tokens": 6820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464796, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7499632432701706}}
{"text": "%!TEX root = TTK4150-Summary.tex\n\\section{Perturbation theory and averaging}\n\\begin{equation}\\label{eq:perturbed}\n\t\\dot{x} = f(x) + \\epsilon g(t,x,\\epsilon)\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Periodic perturbation of autonomous systems}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{Definition of $P_\\epsilon(x)$:}\n$\\phi(t;t_0,x_0,\\epsilon)$ is the solution of \\eqref{eq:perturbed} that starts at $(t_0,x_0)$. $P_\\epsilon(x)$ is\n\\begin{equation}\n\tP_\\epsilon(x) = \\phi(T;0,x,\\epsilon)\n\\end{equation}\n\n\\paragraph{Lemma 10.1}\nThe system \\eqref{eq:perturbed} has a T-periodic solution iff\n\\begin{equation}\n\tx = P_\\epsilon(x)\n\\end{equation}\nhas a solution.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Averaging}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "dd1012df7f592cc2fbf3084827de6a91ea34c18d", "size": 758, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK4150 Nonlinear control systems/sec-perturbation-theory-and-averaging.tex", "max_stars_repo_name": "jakoblover/ntnu-course-summaries", "max_stars_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-11T02:42:40.000Z", "max_issues_repo_path": "TTK4150 Nonlinear control systems/sec-perturbation-theory-and-averaging.tex", "max_issues_repo_name": "jakoblover/ntnu-course-summaries", "max_issues_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TTK4150 Nonlinear control systems/sec-perturbation-theory-and-averaging.tex", "max_forks_repo_name": "jakoblover/ntnu-course-summaries", "max_forks_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.1538461538, "max_line_length": 113, "alphanum_fraction": 0.6081794195, "num_tokens": 230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7499632319898111}}
{"text": "\\section{Volumes}\r\n\\subsection{Volumes from Cross Sections}\r\nImagine we want to find the volume of some complex object.\r\nOne way we could approximate it is by slicing it into narrow cross sections.\r\nThe volume of each cross section would roughly be the area of the cross sectional face, times the width of the cross section.\r\n\r\n\\begin{figure}[H]\r\n\t\\label{volumes}\r\n\t\\centering\r\n\t\\includegraphics[width=0.5\\textwidth]{./applications_integrals/volumes.png}\r\n\t\\caption{\\hyperref{https://tutorial.math.lamar.edu/classes/calci/Area\\_Volume\\_Formulas.aspx}{}{}{Paul's Online Notes - Area and Volume Formulas}}\r\n\\end{figure}\r\n\r\nAdding the volumes of these cross sections up, we'd get our approximation, which would get better and better the narrower the width of each cross section.\r\nIn the limit, this is exactly the definition of an integral.\r\n\r\n\\begin{definition}\r\n\tThe volume of a solid with integrable corss sectional area $A(x)$ from $x=a$ to $x=b$ is given by\r\n\t\\begin{equation*}\r\n\t\tV = \\int_{a}^{b}{A(x)\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\r\n\r\nLet's start by finding the volume of a solid we already know.\r\n\\begin{example}\r\n\tFind the volume of a cube with sidelength $a$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tFor any slice of a cube, the cross section is a square with sidelength $a$.\r\n\t\\begin{align*}\r\n\t\tA(x) &= a^2 \\\\\r\n\t\tV &= \\int_{0}^{a}{a^2\\d{x}} \\\\\r\n\t\t&= a^2x\\biggr\\rvert_0^a \\\\\r\n\t\t&= a^3.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\r\nNow let's find the volume of a slightly more complicated shape.\r\n\\begin{example}\r\n\tFind the volume of a square pyramid with base sidelength $a$ and height $h$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tLike the cube, any slice of the square pyramid is a square.\r\n\tHowever, the sidelength of the square depends on the height of your slice.\r\n\tA slice at the very tip of the pyramid would have sidelength 0, while a slice at the very bottom of the pyramid would have sidelength $a$.\r\n\tThe sidelength grows linearly from $x=0$ to $x=h$, so it must be $\\frac{a}{h}x$.\r\n\t\\begin{align*}\r\n\t\tA(x) &= \\left(\\frac{a}{h}x\\right)^2 \\\\\r\n\t\tV &= \\int_{0}^{h}{\\frac{a^2}{h^2}x^2\\d{x}} \\\\\r\n\t\t&= \\frac{a^2}{3h^2}x^3 \\biggr\\rvert_0^h \\\\\r\n\t\t&= \\frac{a^2h}{3} \\\\\r\n\t\t&= \\frac{1}{3}a^2 h.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsection{Solids of Revolution}\r\nYou can think of solids of revolution as a special case of volumes from cross sections.\r\nWe'll tend to be on the lookout for a function that defines the radius, and we can then use the formula for the area of a circle to get the cross sectional area.\r\n\\begin{equation*}\r\n\tA(x) = \\pi r^2(x).\r\n\\end{equation*}\r\n\r\n\\begin{example}\r\n\tFind the volume of the cone formed by rotating the line $y=x/3$ about the $x$-axis for $0 \\leq x \\leq 6$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tThe radius is simply the distance from the $x$-axis, which is just another name for $y$.\r\n\tSo,\r\n\t\\begin{equation*}\r\n\t\tA(x) = \\pi \\left(\\frac{x}{3}\\right)^2.\r\n\t\\end{equation*}\r\n\t\r\n\tIntegrating,\r\n\t\\begin{align*}\r\n\t\tV &= \\int_{0}^{6}{\\pi\\left(\\frac{x}{3}\\right)^2\\d{x}} \\\\\r\n\t\t&= \\frac{\\pi}{9}\\int_{0}^{6}{x^2\\d{x}} \\\\\r\n\t\t&= \\frac{\\pi}{9}\\left(\\frac{x^3}{3}\\biggr\\rvert_0^6\\right) \\\\\r\n\t\t&= 8\\pi.\r\n\t\\end{align*}\r\n\t\r\n\tThis is the volume of a cone with radius 2 and height 6: $\\frac{1}{3}\\pi(2)^2(6)=8\\pi$.\r\n\\end{answer}\r\n\r\n\r\nLet's try a more complicated solid.\r\n\\begin{example}\r\n\tFind the volume of the solid of revolution bounded by $y=2+x\\cos{x}$ from $-\\frac{\\pi}{2} \\leq x \\leq \\frac{\\pi}{2}$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tAgain, the radius is simply the distance from the $x$-axis, which is $y$.\r\n\t\\begin{align*}\r\n\t\tA(x) &= \\pi \\left(2+x\\cos{x}\\right)^2 \\\\\r\n\t\t&= \\pi \\left(4 + 4x\\cos{x} + x^2\\cos^2{x}\\right) \\\\\r\n\t\tV &= \\int_{-\\pi/2}^{\\pi/2}{\\pi \\left(4 + 4x\\cos{x} + x^2\\cos^2{x}\\right)\\d{x}} \\\\\r\n\t\t&= \\pi\\left(\\int_{-\\pi/2}^{\\pi/2}{4\\d{x}}+\\int_{-\\pi/2}^{\\pi/2}{4x\\cos{x}\\d{x}}+\\int_{-\\pi/2}^{\\pi/2}{x^2\\cos^2{x}\\d{x}}\\right) \\\\\r\n\t\t&= \\pi\\left(4\\pi + 0 + \\frac{1}{24}\\pi\\left(\\pi^2-6\\right)\\right) \\text{ (use integration by parts)}\\\\\r\n\t\t&= \\frac{\\pi^4}{24} + \\frac{15\\pi^2}{4}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{Washer Method}\r\nImagine now we want to find the volume of a solid of revolution with a ``hole.''\r\nIf we were to take a cross section of such a solid, it'd look like a washer with an outer radius $R(x)$ and inner radius $r(x)$.\r\n\r\n\\begin{figure}[H]\r\n\t\\label{washers}\r\n\t\\centering\r\n\t\\includegraphics[width=0.33\\textwidth]{./applications_integrals/Washer-1.png}\r\n\t\\caption{\\hyperref{https://www.shelovesmath.com/calculus/integral-calculus/applications-integration-area-volume/}{}{}{She Loves Math - Applications of Integration: Area and Volume}}\r\n\\end{figure}\r\n\r\n\r\nWe can think of this in a similar way as the area between curves in 2D.\r\nWe'll find the volume swept by the outer radius and the subtract the volume swept and removed by the inner radius.\r\n\\begin{equation*}\r\n\tV = \\pi\\int_{a}^{b}{(R^2(x)-r^2(x))\\d{x}}.\r\n\\end{equation*}\r\n\r\n\\begin{example}\r\n\tFind the volume of shape formed by revolving the area enclosed by the $y$-axis, $y=\\cos{x}$, and $y=\\sin{x}$ around the $x$-axis.\r\n\\end{example}\r\n\\begin{answer}\r\n\tIn the first quadrant, $\\cos{x} \\geq \\sin{x}$ for $x \\leq \\frac{\\pi}{4}$, so our bounds are $0 \\leq x \\leq \\frac{\\pi}{4}$, $R(x)=\\cos{x}$, and $r(x)=\\sin{x}$.\r\n\t\\begin{align*}\r\n\t\tV &= \\pi\\int_{0}^{\\pi/4}{(\\cos^2{x}-\\sin^2{x})\\d{x}} \\\\\r\n\t\t&= \\pi\\int_{0}^{\\pi/4}{\\cos{(2x)}\\d{x}} \\\\\r\n\t\t&= \\pi\\left(\\frac{\\sin{2x}}{2}\\right)\\biggr\\rvert_0^{\\pi/4} \\\\\r\n\t\t&= \\frac{\\pi}{2}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{Cylindrical Shells Method}\r\nAll the previous methods for finding the volumes of solids of rotation have relied on summing the volumes of thin cross sectional slices that are perpendicular to the axis of rotation.\r\nHowever, we can instead sum the volume of thin cylindrical shells that grow outwards from and parallel to the axis of revolution.\r\n\r\n\\begin{figure}[H]\r\n\t\\label{shells}\r\n\t\\centering\r\n\t\\includegraphics[width=0.5\\textwidth]{./applications_integrals/shells.png}\r\n\t\\caption{\\hyperref{https://en.wikipedia.org/wiki/Shell\\_integration}{}{}{Wikipedia - Shell Integration}}\r\n\\end{figure}\r\n\r\n\r\nEach cylindrical shell will have a radius $r(x)$, a height $h(x)$, and a thickness $\\d{x}$, meaning a volume of $2\\pi r(x)h(x)\\d{x}$.\r\n\\begin{equation*}\r\n\tV = 2\\pi\\int_{a}^{b}{r(x)h(x)\\d{x}}.\r\n\\end{equation*}\r\n\r\n\\begin{example}\r\n\tFind the volume of the area bounded by the $y$-axis, $y=4-x^2$, and $y=x$ revolved around the $y$-axis.\r\n\\end{example}\r\n\\begin{answer}\r\n\tEach shell's height is parallel to the axis of rotation.\r\n\tIn this case that's the distance between the two curves.\r\n\t\\begin{equation*}\r\n\t\th(x) = 4-x^2-x \\text{ and } r(x)=x.\r\n\t\\end{equation*}\r\n\t\r\n\tThe two curves intersect at $x=\\frac{-1+\\sqrt{17}}{2}$.\r\n\tFinding the volume,\r\n\t\\begin{align*}\r\n\t\tV &= 2\\pi\\int_{0}^{\\frac{-1+\\sqrt{17}}{2}}{x(4-x^2-x)\\d{x}} \\\\\r\n\t\t&= 2\\pi\\left(-\\frac{x^4}{4}-\\frac{x^3}{3}+2x^2\\right)\\biggr\\rvert_{0}^{\\frac{-1+\\sqrt{17}}{2}} \\\\\r\n\t\t&= \\frac{\\pi}{12}\\left(121-17\\sqrt{17}\\right).\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tFind the volume of the area bounded by the $x$-axis and the curve $y=(x-1)^2(x-2)^2$ rotated about the $y$-axis.\r\n\\end{example}\r\n\\begin{answer}\r\n\tThe height of the shell is parallel to the $y$-axis.\r\n\tIn this case it's exactly equal to the value of the bounding curve.\r\n\t\\begin{equation*}\r\n\t\th(x)=(x-1)^2(x-2)^2 \\text{ and } r(x)=x.\r\n\t\\end{equation*}\r\n\t\r\n\tFinding the volume,\r\n\t\\begin{align*}\r\n\t\tV &= 2\\pi\\int_{1}^{2}{x(x-1)^2(x-2)^2\\d{x}} \\\\\r\n\t\t&= 2\\pi\\left(\\frac{x^6}{6}-\\frac{6x^5}{5}+\\frac{13x^4}{4}-4x^3+2x^2\\right)\\biggr\\rvert_{1}^{2} \\\\\r\n\t\t&= \\frac{\\pi}{10}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{Other Axes of Rotation}\r\nAlthough rotating about the $x$ and $y$ axes are the most common, the methods we have here apply to rotating about any axis parallel to the $x$ or $y$ axis.\r\nThe includes any lines of the form $y=k$ or $x=k$ where $k$ is some constant. \\\\\r\n\r\n\r\nOne valid approach is simply to rewrite the equations for your bounding curves by shifting them such that your axis of rotation is the $x$ or $y$ axis.\r\nHowever, it's often more convenient to not rewrite the equations and simply apply the methods.\r\n\r\n\\begin{example}\r\n\tFind the volume of the solid generated by rotating the region in the first quadrant bounded by $y=x^2$ and $y=2x$ about the line $x=-2$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe can use the washer method (although shells also works).\r\n\tSince we're rotating about a line parallel to the $y$-axis, we'll have to rewrite our equations in the form $x=\\ldots$.\r\n\t\\begin{equation*}\r\n\t\tx = \\sqrt{y} \\text{ and } x = \\frac{y}{2}.\r\n\t\\end{equation*}\r\n\t\r\n\tThe inner radius is given by the distance from $x=-2$ to $x=y/2$, and the outer radius is given by the distance from $x=-2$ to $x=\\sqrt{y}$.\r\n\tThe curves intersect at $y=0$ and $y=4$.\r\n\t\\begin{align*}\r\n\t\tr(x) = 2 + \\frac{y}{2} &\\text{ and } R(x) = 2 + \\sqrt{y} \\\\\r\n\t\tV &= \\pi\\int_{0}^{4}{(2+\\sqrt{y})^2-\\left(2+\\frac{y}{2}\\right)^2\\d{y}} \\\\\r\n\t\t&= \\pi\\int_{0}^{4}{\\left(4\\sqrt{y}-y-\\frac{y^2}{4}\\right)\\d{y}} \\\\\r\n\t\t&= 8\\pi.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tFind the volume of the solid generated by rotating the region bounded by $y=x^2$ and $y=x+2$ about the line $x=3$.\r\n\\end{example} \r\n\\begin{answer}\r\n\tWe can use the shells method.\r\n\tOur height is simply the difference in $y$ values between the two curves.\r\n\tThe radius is the distance between the lines $x=3$ and $x+2$.\r\n\t\\begin{equation*}\r\n\t\th(x) = x+2-x^2 \\text{ and } r(x) = 3-x.\r\n\t\\end{equation*}\r\n\t\r\n\tThe curves intersect at $x=-1$ and $x=2$.\r\n\tFinding the volume,\r\n\t\\begin{align*}\r\n\t\tV &= 2\\pi\\int_{-1}^{2}{(3-x)(x+2-x^2)\\d{x}} \\\\\r\n\t\t&= 2\\pi\\left(\\frac{x^4}{4}-\\frac{4x^3}{3}+\\frac{x^2}{2}+6x\\right)\\biggr\\rvert_{-1}^{2} \\\\\r\n\t\t&= \\frac{45\\pi}{2}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{Surface Area}\r\nCan apply the idea behind shell integration to derive a formula for surface area of a solid of rotation.\r\nA cylindrical shell would have height $\\d{s}$, which is given to us by the arc length formula, and radius $x$ or $y$, if the axis of rotation is the $y$ or $x$ axis respectively.\r\n\\begin{align*}\r\n\tS &= \\begin{cases}\r\n\t\t2\\pi\\int{y\\d{s}} & \\text{Rotation about $x$-axis} \\\\\r\n\t\t2\\pi\\int{x\\d{x}} & \\text{Rotation about the $y$-axis}\r\n\t\\end{cases} \\\\\r\n\t& \\text{where } \\\\\r\n\t\\d{s} &= \\begin{cases}\r\n\t\t\\sqrt{1+\\left(\\dd{y}{x}\\right)^2}\\d{x} & y=f(x) \\\\\r\n\t\t\\sqrt{1+\\left(\\dd{x}{y}\\right)^2}\\d{y} & x=g(y) \\\\\r\n\t\\end{cases}.\r\n\\end{align*}\r\n\r\n\\begin{example}\r\n\tFind the surface area of a sphere with radius $r$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe can obtain a sphere by rotating $y=\\sqrt{r^2-x^2}, -r\\leq x\\leq r$ about the $x$-axis.\r\n\t\\begin{align*}\r\n\t\t\\dd{y}{x} &= \\frac{-x}{\\sqrt{r^2-x^2}} \\\\\r\n\t\t\\left(\\dd{y}{x}\\right)^2 &= \\frac{x^2}{r^2-x^2} \\\\\r\n\t\tS &= 2\\pi\\int_{-r}^{r}{y\\sqrt{1+\\frac{x^2}{r^2-x^2}}\\d{x}} \\\\\r\n\t\t&= 2\\pi\\int_{-r}^{r}{\\sqrt{r^2-x^2}\\frac{r}{\\sqrt{r^2-x^2}}\\d{x}} \\\\\r\n\t\t&= 2\\pi\\int_{-r}^{r}{r\\d{x}} \\\\\r\n\t\t&= 4\\pi r^2.\r\n\t\\end{align*}\r\n\\end{answer}", "meta": {"hexsha": "66b72f826b55b1388bdb84a272e065c2203541aa", "size": 10951, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/applications_integrals/volumes.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/applications_integrals/volumes.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/applications_integrals/volumes.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 41.4810606061, "max_line_length": 185, "alphanum_fraction": 0.6418591909, "num_tokens": 3925, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.7499254259904969}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\n\\title{Proving the Quadratic Formula}\n\\author{Ethan Xu}\n\\date{September 2021}\n\n\\usepackage{chngcntr}\n\\usepackage{amssymb}\n\\usepackage{ragged2e}\n\\usepackage{amsmath,amsthm}\n\n\\renewcommand{\\qed}{\\hfill\\square}\n\n\\counterwithin*{equation}{section}\n\\counterwithin*{equation}{subsection}\n\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Introduction}\n\nThe quadratic formula states that:\n\n\\begin{equation}\n    x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}\n\\end{equation}\n\nwhen given a quadratic equation such as:\n\n\\begin{equation}\n    ax^2+bx+c=0\n\\end{equation}\n\n\\section{Proof}\n\n\\begin{equation}\n    ax^2+bx+c=0\n\\end{equation}\n\n\\begin{equation}\n    ax^2+bx=-c\n\\end{equation}\n\n\\begin{equation}\n    x^2+\\frac{b}{a}x=-\\frac{c}{a}\n\\end{equation}\n\n\\begin{equation}\n    x^2+\\frac{b}{a}x+\\frac{b^2}{4a^2}=-\\frac{c}{a}+\\frac{b^2}{4a^2}\n\\end{equation}\n\n\\begin{equation}\n    (x+\\frac{b}{2a})^2=-\\frac{c}{a}+\\frac{b^2}{4a^2}\n\\end{equation}\n\n\\begin{equation}\n    x+\\frac{b}{2a}=\\pm\\sqrt{-\\frac{c}{a}+\\frac{b^2}{4a^2}}\n\\end{equation}\n\n\\begin{equation}\n    x=-\\frac{b}{2a}\\pm\\sqrt{-\\frac{c}{a}+\\frac{b^2}{4a^2}}\n\\end{equation}\n\n\\begin{equation}\n    x=-\\frac{b}{2a}\\pm\\frac{\\sqrt{-\\frac{c}{a}\\cdot(2a)^2+\\frac{b^2}{4a^2}\\cdot(2a)^2}}{2a}\n\\end{equation}\n\n\\begin{equation}\n    x=-\\frac{b}{2a}\\pm\\frac{\\sqrt{-4ac+b^2}}{2a}\n\\end{equation}\n\n\\begin{equation}\n    x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}\n\\end{equation}\n\n$\\qed$\n\n\\end{document}\n\n", "meta": {"hexsha": "6afd062fe1cf35ac26aef2b251daceef5594030a", "size": 1441, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "random-proofs/quadratic-formula/quadratic.tex", "max_stars_repo_name": "waitblock/gists", "max_stars_repo_head_hexsha": "3dfe65a4f0f593ab4378eb3b518c98e2e882844d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-06-10T18:44:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-19T02:48:38.000Z", "max_issues_repo_path": "random-proofs/quadratic-formula/quadratic.tex", "max_issues_repo_name": "waitblock/side-projects", "max_issues_repo_head_hexsha": "3dfe65a4f0f593ab4378eb3b518c98e2e882844d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "random-proofs/quadratic-formula/quadratic.tex", "max_forks_repo_name": "waitblock/side-projects", "max_forks_repo_head_hexsha": "3dfe65a4f0f593ab4378eb3b518c98e2e882844d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.3614457831, "max_line_length": 91, "alphanum_fraction": 0.654406662, "num_tokens": 616, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.8723473680407889, "lm_q1q2_score": 0.7499254164302945}}
{"text": "In this chapter we explore some consequences of a basic mathematical fact called the \\textbf{Pigeonhole Principle}. Although the statement itself is very elementary, the various consequences and results that one can obtain as a consequence of this basic fact are very deep and surprising. In the first section we will explore the pigeonhole principle's application in the finite case and the infinite case.\n\n\\section{The Pigeonhole Principle}\n\\input{Ch9/pigeonhole}\n\n\\section{Ramsey's Theorem}\n\n\\subsection{Infinite Ramsey Implies Finite Ramsey}\n\\input{Ch9/infImpliesF.tex}\n", "meta": {"hexsha": "6540862bff7b3a7804909e53972112ffe9721c93", "size": 574, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch9/main.tex", "max_stars_repo_name": "jonlin1000/discr_math", "max_stars_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:31:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T02:26:40.000Z", "max_issues_repo_path": "Ch9/main.tex", "max_issues_repo_name": "jonlin1000/discr_math", "max_issues_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch9/main.tex", "max_forks_repo_name": "jonlin1000/discr_math", "max_forks_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.4, "max_line_length": 406, "alphanum_fraction": 0.8170731707, "num_tokens": 128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7498999309987943}}
{"text": "% based on example 7 in pythontex_gallery\n% https://github.com/gpoore/pythontex/\n\n\\documentclass[12pt]{mmalatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{Step-by-step integration}\n\nThis is another nice example drawn from the Pythontex gallery, see\n\\ \\url{https://github.com/gpoore/pythontex}.\n\nIt shows the step-by-step computations of a simple triple integral.\n\n\\vspace{12pt}\n\n\\lstset{numbers=left}\n\\begin{mathematica}\n   xmax = 2;  ymax = 3;  zmax = 4;\n   xmin = 0;  ymin = 0;  zmin = 0;\n\n   fun = f[x,y,z];\n\n   mytmp = HoldForm[Integrate[#1, {z, #6, #7},\n                                  {y, #4, #5},\n                                  {x, #2, #3}]] & @@ {fun, xmin, xmax, ymin, ymax, zmin, zmax};   (* mma(lhs.01,mytmp) *)\n\n   fun = x y + y Sin[z] + Cos[x+y];\n\n   myint = HoldForm[Integrate[#1, {z, #6, #7},\n                                  {y, #4, #5},\n                                  {x, #2, #3}]] & @@ {fun, xmin, xmax, ymin, ymax, zmin, zmax};   (* mma(rhs.01,myint) *)\n\n   myansx =          Integrate[#1, {x, #2, #3}] & @@ {fun, xmin, xmax};\n   myintx = HoldForm[Integrate[#1, {z, #4, #5},\n                                   {y, #2, #3}]] & @@ {myansx, ymin, ymax, zmin, zmax};           (* mma(rhs.02,myintx) *)\n\n   myansxy =          Integrate[#1, {y, #2, #3}]  & @@ {myansx, ymin, ymax};\n   myintxy = HoldForm[Integrate[#1, {z, #2, #3}]] & @@ {myansxy, zmin, zmax};                     (* mma(rhs.03,myintxy) *)\n\n   myansxyz = Integrate[#1, {z, #2, #3}] & @@ {myansxy, zmin, zmax};                              (* mma(rhs.04,myansxyz) *)\n\n   myapprox = N[myansxyz,15];                                                                     (* mma(rhs.05,myapprox) *)\n\\end{mathematica}\n\n\\begin{minipage}[t]{0.65\\textwidth}\n\\begin{align*}\n   \\mma{lhs.01} &= \\mma{rhs.01}\\\\\n                &= \\mma{rhs.02}\\\\\n                &= \\mma{rhs.03}\\\\\n                &= \\mma{rhs.04}\\\\[8pt]\n                &\\approx \\mma{rhs.05}\n\\end{align*}\n\\end{minipage}\n\\hskip 1cm\n\\lower16pt\\hbox{%\n\\begin{minipage}[t]{0.35\\textwidth}\n\\begin{latex}\n   \\begin{align*}\n      \\mma{lhs.01} &= \\mma{rhs.01}\\\\\n                   &= \\mma{rhs.02}\\\\\n                   &= \\mma{rhs.03}\\\\\n                   &= \\mma{rhs.04}\\\\[8pt]\n                   &\\approx \\mma{rhs.05}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}}\n\n\\end{document}\n", "meta": {"hexsha": "de35a8ddc3b251e1016e5c172da76b352a855388", "size": 2317, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mathematica/examples/example-03.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "mathematica/examples/example-03.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mathematica/examples/example-03.tex", "max_forks_repo_name": "leo-brewin/hybrid-latex", "max_forks_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-27T03:29:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:17:18.000Z", "avg_line_length": 32.6338028169, "max_line_length": 124, "alphanum_fraction": 0.4708675011, "num_tokens": 802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505273888291, "lm_q2_score": 0.8289388040954684, "lm_q1q2_score": 0.7498999262980308}}
{"text": "\\section*{Exercises}\n\n\\begin{ex} \\label{exer-linear-transf}\nConsider the following functions which map $\\R^{n}$ to $\\R^{n}$.\n\n\\begin{enumerate}\n\\item $T$ multiplies the $j\\th$ component of $\\vect{x}$ by a non-zero\nnumber $b$.\n\n\\item $T$ replaces the $i\\th$ component of $\\vect{x}$ with $b$ times the\n$j\\th$ component added to the $i\\th$ component.\n\n\\item $T$ switches the $i\\th$ and $j\\th$ components.\n\\end{enumerate}\n\nShow these functions are linear transformations and describe their matrices $A$ such that $T(\\vect{x}) = A\\vect{x}$.\n\\begin{sol}\n\\begin{enumerate}\n\\item The matrix of $T$ is the elementary matrix which multiplies\nthe $j\\th$ diagonal entry of the identity matrix by $b$.\n\\item The matrix of $T$ is the\nelementary matrix which takes $b$ times the $j\\th$ row and adds to the $%\ni\\th$ row.\n\\item The matrix of $T$ is the elementary matrix which switches the $%\ni\\th$ and the $j\\th$ rows where the two components are in the $i\\th$\nand $j\\th$ positions.\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} You are given a linear transformation $T:\\R^{n}\\rightarrow\n\\R^{m}$ and you know that\n\\begin{equation*}\nT(A_{i})=B_{i}\n\\end{equation*}\nwhere $\\begin{mymatrix}{ccc}\nA_{1} & \\cdots & A_{n}\n\\end{mymatrix} ^{-1}$ exists. Show that the matrix of $T$ is of the form\n\\begin{equation*}\n\\begin{mymatrix}{ccc}\nB_{1} & \\cdots & B_{n}\n\\end{mymatrix} \\begin{mymatrix}{ccc}\nA_{1} & \\cdots & A_{n}\n\\end{mymatrix} ^{-1}\n\\end{equation*}\n\\begin{sol}\nSuppose\n\\[\n\\begin{mymatrix}{c}\n\\vect{c}_{1}^{T} \\\\\n\\vdots \\\\\n\\vect{c}_{n}^{T}\n\\end{mymatrix} =\\begin{mymatrix}{ccc}\n\\vect{a}_{1} & \\cdots & \\vect{a}_{n}\n\\end{mymatrix}^{-1}\n\\]\nThus $\\vect{c}_{i}^{T}\\vect{a}_{j}=\\delta _{ij}$. Therefore,\n\\begin{eqnarray*}\n\\begin{mymatrix}{ccc}\n\\vect{b}_{1} & \\cdots & \\vect{b}_{n}\n\\end{mymatrix} \\begin{mymatrix}{ccc}\n\\vect{a}_{1} & \\cdots & \\vect{a}_{n}\n\\end{mymatrix} ^{-1}\\vect{a}_{i} &=&\n\\begin{mymatrix}{ccc}\n\\vect{b}_{1} & \\cdots & \\vect{b}_{n}\n\\end{mymatrix} \\begin{mymatrix}{c}\n\\vect{c}_{1}^{T} \\\\\n\\vdots \\\\\n\\vect{c}_{n}^{T}\n\\end{mymatrix} \\vect{a}_{i} \\\\\n&=&\\begin{mymatrix}{ccc}\n\\vect{b}_{1} & \\cdots & \\vect{b}_{n}\n\\end{mymatrix} \\vect{e}_{i} \\\\\n&=&\\vect{b}_{i}\n\\end{eqnarray*}\nThus $T\\vect{a}_{i}=\\begin{mymatrix}{ccc}\n\\vect{b}_{1} & \\cdots & \\vect{b}_{n}\n\\end{mymatrix} \\begin{mymatrix}{ccc}\n\\vect{a}_{1} & \\cdots & \\vect{a}_{n}\n\\end{mymatrix} ^{-1}\\vect{a}_{i} =  A\\vect{a}_{i}$. If $\\vect{x}$ is\narbitrary, then since the matrix $\\begin{mymatrix}{ccc}\n\\vect{a}_{1} & \\cdots & \\vect{a}_{n}\n\\end{mymatrix} $ is invertible, there exists a unique $\\vect{y}$ such that $\n\\begin{mymatrix}{ccc}\n\\vect{a}_{1} & \\cdots & \\vect{a}_{n}\n\\end{mymatrix} \\vect{y}=\\vect{x}$ Hence\n\\[\nT\\vect{x}=T\\paren{\\sum_{i=1}^{n}y_{i}\\vect{a}_{i}}\n=\\sum_{i=1}^{n}y_{i}T\\vect{a}_{i}=\\sum_{i=1}^{n}y_{i}A\\vect{a}\n_{i}=A\\paren{\\sum_{i=1}^{n}y_{i}\\vect{a}_{i}} =A\\vect{x}\n\\]\n\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose $T$ is a linear transformation such that\n\\begin{eqnarray*}\nT\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n-6\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n5 \\\\\n1 \\\\\n3\n\\end{mymatrix} \\\\\nT\\begin{mymatrix}{r}\n-1 \\\\\n-1 \\\\\n5\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n5\n\\end{mymatrix} \\\\\nT\\begin{mymatrix}{r}\n0 \\\\\n-1 \\\\\n2\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n5 \\\\\n3 \\\\\n-2\n\\end{mymatrix}\n\\end{eqnarray*}\nFind the matrix of $T$. That is find $A$ such that $T(\\vect{x})=A\\vect{x}$. \\vspace{1mm}\n\\begin{sol}\n\\[\n\\begin{mymatrix}{rrr}\n5 & 1 & 5 \\\\\n1 & 1 & 3 \\\\\n3 & 5 & -2\n\\end{mymatrix} \\begin{mymatrix}{ccc}\n3 & 2 & 1 \\\\\n2 & 2 & 1 \\\\\n4 & 1 & 1\n\\end{mymatrix} =\\begin{mymatrix}{ccc}\n37 & 17 & 11 \\\\\n17 & 7 & 5 \\\\\n11 & 14 & 6\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose $T$ is a linear transformation such that\n\\begin{eqnarray*}\nT\\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n-8\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n1 \\\\\n3 \\\\\n1\n\\end{mymatrix} \\\\\nT\\begin{mymatrix}{r}\n-1 \\\\\n0 \\\\\n6\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n2 \\\\\n4 \\\\\n1\n\\end{mymatrix} \\\\\nT\\begin{mymatrix}{r}\n0 \\\\\n-1 \\\\\n3\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n6 \\\\\n1 \\\\\n-1\n\\end{mymatrix}\n\\end{eqnarray*}\nFind the matrix of $T$. That is find $A$ such that $T(\\vect{x})=A\\vect{x}$. \\vspace{1mm}\n\\begin{sol}\n\\[\n\\begin{mymatrix}{rrr}\n1 & 2 & 6 \\\\\n3 & 4 & 1 \\\\\n1 & 1 & -1\n\\end{mymatrix} \\begin{mymatrix}{ccc}\n6 & 3 & 1 \\\\\n5 & 3 & 1 \\\\\n6 & 2 & 1\n\\end{mymatrix} =\\begin{mymatrix}{ccc}\n52 & 21 & 9 \\\\\n44 & 23 & 8 \\\\\n5 & 4 & 1\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose $T$ is a linear transformation such that\n\\begin{eqnarray*}\nT\\begin{mymatrix}{r}\n1 \\\\\n3 \\\\\n-7\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n-3 \\\\\n1 \\\\\n3\n\\end{mymatrix} \\\\\nT\\begin{mymatrix}{r}\n-1 \\\\\n-2 \\\\\n6\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n1 \\\\\n3 \\\\\n-3\n\\end{mymatrix} \\\\\nT\\begin{mymatrix}{r}\n0 \\\\\n-1 \\\\\n2\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n5 \\\\\n3 \\\\\n-3\n\\end{mymatrix}\n\\end{eqnarray*}\nFind the matrix of $T$. That is find $A$ such that $T(\\vect{x})=A\\vect{x}$. \\vspace{1mm}\\vspace{1mm}\n\\begin{sol}\n\\[\n\\begin{mymatrix}{rrr}\n-3 & 1 & 5 \\\\\n1 & 3 & 3 \\\\\n3 & -3 & -3\n\\end{mymatrix} \\begin{mymatrix}{ccc}\n2 & 2 & 1 \\\\\n1 & 2 & 1 \\\\\n4 & 1 & 1\n\\end{mymatrix} = \\begin{mymatrix}{rrr}\n15 & 1 & 3 \\\\\n17 & 11 & 7 \\\\\n-9 & -3 & -3\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose $T$ is a linear transformation such that\n\\begin{eqnarray*}\nT\\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n-7\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n3 \\\\\n3 \\\\\n3\n\\end{mymatrix} \\\\\nT\\begin{mymatrix}{r}\n-1 \\\\\n0 \\\\\n6\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n3\n\\end{mymatrix} \\\\\nT\\begin{mymatrix}{r}\n0 \\\\\n-1 \\\\\n2\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n1 \\\\\n3 \\\\\n-1\n\\end{mymatrix}\n\\end{eqnarray*}\nFind the matrix of $T$. That is find $A$ such that $T(\\vect{x})=A\\vect{x}$. \\vspace{1mm}\n\\begin{sol}\n\\[\n\\begin{mymatrix}{rrr}\n3 & 1 & 1 \\\\\n3 & 2 & 3 \\\\\n3 & 3 & -1\n\\end{mymatrix} \\begin{mymatrix}{ccc}\n6 & 2 & 1 \\\\\n5 & 2 & 1 \\\\\n6 & 1 & 1\n\\end{mymatrix} =\\allowbreak \\begin{mymatrix}{ccc}\n29 & 9 & 5 \\\\\n46 & 13 & 8 \\\\\n27 & 11 & 5\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose $T$ is a linear transformation such that\n\\begin{eqnarray*}\nT\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n-18\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n5 \\\\\n2 \\\\\n5\n\\end{mymatrix} \\\\\nT\\begin{mymatrix}{r}\n-1 \\\\\n-1 \\\\\n15\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n3 \\\\\n3 \\\\\n5\n\\end{mymatrix} \\\\\nT\\begin{mymatrix}{r}\n0 \\\\\n-1 \\\\\n4\n\\end{mymatrix} &=&\\begin{mymatrix}{r}\n2 \\\\\n5 \\\\\n-2\n\\end{mymatrix}\n\\end{eqnarray*}\nFind the matrix of $T$. That is find $A$ such that $T(\\vect{x})=A\\vect{x}$. \\vspace{1mm}\n\\begin{sol}\n\\[\n\\begin{mymatrix}{rrr}\n5 & 3 & 2 \\\\\n2 & 3 & 5 \\\\\n5 & 5 & -2\n\\end{mymatrix} \\begin{mymatrix}{ccc}\n11 & 4 & 1 \\\\\n10 & 4 & 1 \\\\\n12 & 3 & 1\n\\end{mymatrix} =\\begin{mymatrix}{ccc}\n109 & 38 & 10 \\\\\n112 & 35 & 10 \\\\\n81 & 34 & 8\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Consider the following functions $T:\\R^{3}\\rightarrow \\R^{2}$.\nShow that each is a linear transformation and determine for each the matrix $A$ such that\n$T(\\vect{x})=A\\vect{x}$.\n\n\\begin{enumerate}\n\\item $T\\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{c}\nx+2y+3z \\\\\n2y-3x+z\n\\end{mymatrix} $\n\n\\item $T\\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{c}\n7x+2y+z \\\\\n3x-11y+2z\n\\end{mymatrix} $\n\n\\item $T\\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{c}\n3x+2y+z \\\\\nx+2y+6z\n\\end{mymatrix} $\n\n\\item $T\\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{c}\n2y-5x+z \\\\\nx+y+z\n\\end{mymatrix} $\n\\end{enumerate}\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Consider the following functions $T:\\R^{3}\\rightarrow \\R^{2}$.\nExplain why each of these functions $T$ is not linear.\n\n\\begin{enumerate}\n\\item $T\\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{c}\nx+2y+3z+1 \\\\\n2y-3x+z\n\\end{mymatrix} $\n\n\\item $T\\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{c}\nx+2y^{2}+3z \\\\\n2y+3x+z\n\\end{mymatrix} $\n\n\\item $T\\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{c}\n\\sin x+2y+3z \\\\\n2y+3x+z\n\\end{mymatrix} $\n\n\\item $T\\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{c}\nx+2y+3z \\\\\n2y+3x-\\ln z\n\\end{mymatrix} $\n\\end{enumerate}\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose\n\\begin{equation*}\n\\begin{mymatrix}{ccc}\nA_{1} & \\cdots & A_{n}\n\\end{mymatrix} ^{-1}\n\\end{equation*}\n exists where each $A_{j}\\in \\R^{n}$ and let\nvectors  $\\set{B_{1},\\ldots,B_{n}} $ in $\\R^{m}$ be given.\nShow that there \\textbf{always }exists a linear\ntransformation $T$ such that $T(A_{i})=B_{i}$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex}  Find the matrix for $T(\\vect{w}) = \\proj_{\\vect{v}}(\\vect{w}) $\nwhere $\\vect{v}=\\begin{mymatrix}{rrr}\n1 & -2 & 3\n\\end{mymatrix} ^{T}$.\n\\begin{sol}\n Recall that $\\proj_{\\vect{u}}(\\vect{v}) =\\frac{\\vect{v}\\dotprod\\vect{u} }{\\norm{\\vect{u}} ^{2}}\\vect{u}$ and so the desired matrix\nhas $i\\th$ column equal to $\\proj_{\\vect{u}}(\\vect{e}_{i})$. Therefore, the matrix desired is\n\\[\n\\frac{1}{14}\\begin{mymatrix}{rrr}\n1 & -2 & 3 \\\\\n-2 & 4 & -6 \\\\\n3 & -6 & 9\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  Find the matrix for $T(\\vect{w}) = \\proj_{\\vect{v}}(\\vect{w}) $\nwhere $\\vect{v}=\\begin{mymatrix}{rrr}\n1 & 5 & 3\n\\end{mymatrix} ^{T}$.\n\\begin{sol}\n\\[\n\\frac{1}{35}\\begin{mymatrix}{rrr}\n1 & 5 & 3 \\\\\n5 & 25 & 15 \\\\\n3 & 15 & 9\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find the matrix for $T(\\vect{w}) = \\proj_{\\vect{v}}(\\vect{w}) $\nwhere $\\vect{v}=\\begin{mymatrix}{rrr}\n1 & 0 & 3\n\\end{mymatrix} ^{T}$.\n\\begin{sol}\n\\[\n\\frac{1}{10}\\begin{mymatrix}{ccc}\n1 & 0 & 3 \\\\\n0 & 0 & 0 \\\\\n3 & 0 & 9\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose $A$ is a $3\\times 3$ antisymmetric matrix such that $A^{T}=-A$. Show\nthere exists a vector $\\vect{v}$ such that for all $\\vect{u}\\in\n\\R^{3}$\n\\begin{equation*}\nA\\vect{u}=\\vect{v} \\times \\vect{u}\n\\end{equation*}\n\\textbf{Hint: }Explain why, since $A$ is antisymmetric it is of the form\n\\begin{equation*}\nA=\\begin{mymatrix}{ccc}\n0 & -\\omega _{3} & \\omega _{2} \\\\\n\\omega _{3} & 0 & -\\omega _{1} \\\\\n-\\omega _{2} & \\omega _{1} & 0\n\\end{mymatrix}\n\\end{equation*}\nwhere the $\\omega _{i}$ are numbers. Then consider $\\omega _{1}\\vect{i}\n+\\omega _{2}\\vect{j}+\\omega _{3}\\vect{k}$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "81c291640ac142cb6e2e793ca685980a5f9cb6bb", "size": 10042, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/exercises/LinearTransformations-Matrix.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/exercises/LinearTransformations-Matrix.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/exercises/LinearTransformations-Matrix.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 19.4612403101, "max_line_length": 131, "alphanum_fraction": 0.6045608445, "num_tokens": 4469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681086260461, "lm_q2_score": 0.8740772236840656, "lm_q1q2_score": 0.7497555669525864}}
{"text": "\\section{Uniqueness of Solutions to Laplace equation}\nAssume 2 solutions $\\phi_1$ and $\\phi_2$ with\n$\\phi_2\\ne \\phi_1$.\n$\\phi_1,\\phi_2$ satisfy some boundary conditions,\nDirichlet or Neumann\n$\\vec{\\nabla}\\cdot\\hat{n}$.\n\nConsider $U=\\phi_2 - \\phi_1$.\nWe know $\\nabla^2 U=0$ so\n\\begin{align}\n    \\int d^3x\\,\n    \\underbrace{\n    U \\nabla^2 U\n    }_{\n    \\vec{\\nabla}\\cdot\\left( U\\vec{\\nabla} U \\right)\n    -\n    \\left( \\vec{\\nabla} U \\right)^2\n    }\n    &=0\\\\\n\\end{align}\nwhich implies\n\\begin{align}\n    \\int_V d^3x\\,\n    |\\vec{\\nabla} U|^2\n    &=\n    \\underbrace{\n    \\int_V d^3x\\, \\vec{\\nabla}\\cdot\\left( U\\vec{\\nabla}U \\right)\n    }_{\n    \\oint_S dS\\, U\\left( \\vec{n}\\cdot\\vec{\\nabla}U \\right)\n    }\n\\end{align}\nhence\n\\begin{align}\n    \\int_V d^3x\\, |\\vec{\\nabla}U|^2\n    &=\n    \\oint_S dS\\, U\\left( \\vec{\\nabla} U\\cdot\\hat{n} \\right)\n\\end{align}\nFor Dirichlet boundary conditions,\nvalue of $\\phi$ is specified on boundary $S$.\nThen $U=0$ on $S$\nand\n\\begin{align}\n    \\int d^3x\\,\n    |\\vec{\\nabla}U|^2 = 0\n\\end{align}\nand we're integrating a positive quantity to be zero,\nwhich means\n\\begin{align}\n    \\vec{\\nabla}U = 0\n\\end{align}\neverywhere in $V$\nand so $U$ is constant.\nBut since $U=0$ on boundary,\n$U=0$ everywhere.\n\nFor Neumann case,\n$\\hat{n}\\cdot\\vec{\\nabla}\\phi$ is specified on the boundary.\nThis is basically saying the normal component of the electric field is\nspecified.\nThen $\\vec{n}\\cdot\\vec{\\nabla}U=0$\non the boundary.\n\nSo once again,\n\\begin{align}\n    \\int d^3x \\left| \\vec{\\nabla} U\\right|^2 = 0\n\\end{align}\nNow by exactly the same logic,\n$U$ is a constant everywhere.\nBut we don't know it's actually zero on the boundary.\nAnd so this is as far as we can go.\nSo all we can really show is that\n$\\phi_2 - \\phi_1$\nis a constant in $V$.\nSo the solution is unique up to an arbitrary constant.\n\nYou can always shift the minimum of the potential,\nyou can change your potential by a constant everywhere and the electric field\ndoesn't change.\nIt's the potential differences that matter,\nnot the absolute value.\n\nYou specify the Neumann boundary conditions,\nyou're just specifying the electric field of the boundary,\nthe normal component.\nSince you didn't specify the potential anywhere,\nyou can choose your zero potential anywhere,\nso you can shift your potential by a constant and the electric field will still\nbe the same.\n\nIn that sense the solution is unique,\nbecause the physical thing,\nwhich is the electric field,\nis unique and doesn't change.\n\nThe electric field everywhere is completely specified.\n\nThe next thing to consider is electrostatics.\n\n\\section{Electrostatic Energy}\nChange $q_1$ located at $\\vec{x}_1$.\nPotential at $\\vec{x}$ is due to $\\vec{q}_1$.\n\\begin{align}\n    \\phi\\left(\\vec{x}\\right)\n    &=\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\frac{q_1}{\\left|\\vec{x} - \\vec{x}_1\\right|}\n\\end{align}\nNow move another charge $q_2$ from $\\infty$\nto $\\vec{x}_2$.\nPotential energy is the work done\n\\begin{align}\n    W &=\n    q_2 \\phi\\left( \\vec{x}_2 \\right)\\\\\n    &=\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\frac{q_1 q-2}{\\left|\\vec{x}_2 - \\vec{x}_1\\right|}\n\\end{align}\nAnd now if we bring in a third charge $q_3$,\nyou have to include the potential of the two existing charges.\n\\begin{align}\n    W &=\n    \\frac{1}{4\\pi\\epsilon_0_0}\n    \\left\\{ \n    \\frac{q_1 q_2}{\\left| \\vec{x}_2 - \\vec{x}_1 \\right|}\n    + \\frac{q_1 q_3}{\\left| \\vec{x}_3 - \\vec{x}_1 \\right|}\n    + \\frac{q_2 q_3}{\\left| \\vec{x}_3 - \\vec{x}_2 \\right|}\n    \\right\\}\n\\end{align}\nThis generalizes pretty easily to the case where you have $N$ charges.\nYou add it all up,\nup to when you bring the $n$th charge to one point and consider the potential of\nall the other $N-1$ charges.\n\nThis generalizes in a simple way.\nIn the case of $n$ charges,\n\\begin{align}\n    W &=\n    \\sum_{i=1}^{n}\n    \\sum_{j<i}\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\frac{q_i q_j}{\\left| \\vec{x}_i - \\vec{x}_j \\right|}\\\\\n    &=\n    \\frac{1}{2}\n    \\sum_{i=1}^{n}\n    \\sum_{j=1: i\\ne j}^{n}\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\frac{q_i q_j}{\\left| \\vec{x}_i - \\vec{x}_j \\right|}\n\\end{align}\nFor continuous charge distributions,\n\\begin{align}\n    W &=\n    \\frac{1}{2}\n    \\int d^3\\vec{x}\n    \\int d^3\\vec{x}\\,\n    \\frac{\\rho\\left( \\vec{x} \\right) \\rho\\left( \\vec{x}' \\right)}{\n    \\left| \\vec{x} - \\vec{x}' \\right|\n    }\n    \\frac{1}{4\\pi\\epsilon_0}\n\\end{align}\nNotice that almost all those factors are there.\nWe can rewrite this in terms of the potential\n$\\phi(\\vec{x})=\\frac{1}{4\\pi\\epsilon_0} \\frac{\\rho(\\vec{x}')}{\n\\left|\\vec{x} - \\vec{x}'\\right|}$\nto get\n\\begin{align}\n    W &=\n    \\frac{1}{2}\n    \\int d^3x\\,\n    \\rho\\left( \\vec{x} \\right)\n    \\phi\\left( \\vec{x} \\right)\n\\end{align}\nAnd now what we can do is use Poisson's equation to eliminate this.\nUsing Poisson's equation,\nthis becomes\n\\begin{align}\n    W &=\\frac{1}{2}\\epsilon_0 \\int d^3x\\,\n    \\underbrace{\\phi\\left( \\vec{x} \\right) \\nabla^2 \\phi(\\vec{x})}_{\n    \\vec{\\nabla}\\cdot\\left\\{ \n    \\phi \\vec{\\nabla} \\phi\n    \\right\\}\n    -\n    \\left( \\vec{\\nabla} \\phi \\right)^2\n    }\\\\\n    &=\n    \\frac{1}{2}\\epsilon_0 \\int d^3x\\,\n    \\left( \\vec{\\nabla}\\phi \\right)^2\n    -\n    \\frac{1}{2}\\epsilon_0\n    \\underbrace{\n    \\int d^3x\\,\n    \\vec{\\nabla}\\cdot\\left\\{ \n    \\phi \\cdot \\vec{\\nabla} \\phi\n    \\right\\}\n    }_{\n    \\int_S dS \\phi\\left( \n    n\\cdot \\underbrace{\\vec{\\nabla}\\phi}_{=0}\n    \\right)\n    }\n\\end{align}\nwhere the surface we are integrating over is at infinity.\nSo then\n\\begin{align}\n    W &=\n    \\frac{1}{2} \\epsilon_0 \\int d^3x\\,\n    \\left( \\vec{\\nabla}\\phi \\right)^2\\\\\n    &=\n    \\frac{1}{2}\n    \\epsilon_0\n    \\int d^3x\\,\n    \\left|\\vec{E}\\right|^2\n\\end{align}\nNote even far apart,\nthere is self energy of the charges.\nOn the other hand,\nyou're calculating the work needed (change in potential energy)\nto bring charges from infinity into your configuration.\nThat is a physical thing,\nbecause it's a potnetial energy difference.\nThat's a convnetion.\n\nThe self-energy has a long and interesting history I could give several lectures\non, but we don't have time for that.\nThe energy density stored in electrostatic field.\n\\begin{align}\n    w &=\n    \\frac{1}{2}\n    \\epsilon_0\n    \\left| \\vec{E} \\right|^2\n\\end{align}\nSo you can think of the energy density per unit energy stored in the electric\nfield.\n\n\\section{Force on a conducting surface}\nThere are two ways you can compute this.\n\\begin{enumerate}\n    \\item Energy change from a virtual displacement.\n    \\item Directly from the electric field.\n\\end{enumerate}\n\nFirst method.\nThe energy density is $u = \\frac{1}{2} \\epsilon_0 \\left| \\vec{E} \\right|^2$.\nAt the surface of conductor $\\vec{E} = \\sigma/\\epsilon_0$\ndirected normal to the surface.\n\nConsider a small displacement $\\Delta x$ in a direction normal to a surface\nelement $\\Delta A$.\n\nChange in energy\n\\begin{align}\n    \\Delta W &=\n    -\\frac{\\epsilon_0}{2}\n    |\\vec{E}|^2 \\Delta A \\Delta x\\\\\n    &=\n    -\\frac{1}{2\\epsilon_0} \\sigma^2 \\Delta A \\Delta x\n\\end{align}\nSo the force is\n\\begin{align}\n    F &=\n    -\\frac{\\Delta W}{\\Delta x}\\\\\n    &=\n    \\frac{\\sigma^2 \\delta A}{2\\epsilon_0}\n\\end{align}\ndirected outward from surface.\nForce per unit area is\n\\begin{align}\n    f &=\n    \\frac{\\sigma^2}{2\\epsilon_0}\n\\end{align}\noutwards.\nTo get the total force on conductor integrate $f$ over the surface of conductor\nbar.\n\nSecond method.\nThe force on an element of area $\\Delta A$\nis given by\n\\begin{align}\n    \\vec{F} &=\n    \\left( \\sigma \\Delta A \\right)\\vec{E}_{ext}\n\\end{align}\nwhere $\\vec{E}_{ext}$ is the electric field after contribution from $\\Delta A$\nhas been removed.\nThe force is thus\n\\begin{align}\n    F &=\n    \\left( \\sigma \\Delta A \\right)\n    \\frac{\\sigma}{2\\epsilon_0}\\\\\n    &=\n    \\frac{\\sigma^2}{2\\epsilon_0} \\Delta A\n\\end{align}\noutwards.\nThe hard part is finding the charge distribution $\\sigma$,\nbut once you've found it,\nit's easy to get the force.\n\n\\section{Capacitance}\nThe capacitance is defined as\ncharge divided by potential\n\\begin{align}\n    C := \\frac{Q}{\\phi}\n\\end{align}\nAn object with large capacitance means it can hold a large amount of charge\nwithout much potential.\n\nTwo conductors carrying equal and opposite charge\n$+Q$ and $-Q$,\nwith potential difference $\\Delta \\phi$\nbetween them,\nthe capacitance is by definition\n\\begin{align}\n    C &:=\n    \\frac{Q}{\\Delta \\phi}.\n\\end{align}\n\n\\section{Boundary Value Problems}\n\\subsection{Method of images}\nImagine a charge near a conducting surface.\n\n\\begin{example}\n    A grounded conducting sphere of radius $a$ is centred at the origin.\n    A point of charge $q$ is located at point $\\vec{y}$.\n    Find the potential in the region outside the sphere.\n\\end{example}\nThe potential due to $q$ and $q'$ is\n\\begin{align}\n    \\phi(\\vec{x})\n    &=\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\left\\{ \n    \\frac{q}{\\left| \\vec{x} - \\vec{y} \\right|}\n    \\right\\}\n    +\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\left\\{ \n    \\frac{q'}{\\left| \\vec{x} - \\vec{y}' \\right|}\n    \\right\\}\n\\end{align}\nLet $\\hat{n}$ be the unit vector in direction of $\\vec{x}$.\nLet $\\hat{n}'$ be in the direction of $y$.\nThen\n\\begin{align}\n    \\hpi\\left( \\vec{x} \\right)\n    &=\n    \\frac{1}{4\\pi\\epsilon_0}\\left\\{ \n    \\frac{q}{\\left| x\\hat{n} - y\\hat{n}'\\right|}\n    + \\frac{q'}{\\left| x\\hat{n} - y\\hat{n}'\\right|}\n    \\right\\}\n\\end{align}\nwhere\n\\begin{align}\n    |\\vec{x}| &= x\\\\\n    |\\vec{y}| &= y\\\\\n    |\\vec{y}'| &= y'\n\\end{align}\nWe need $\\phi\\left( |\\vec{x}| = a \\right) = 0$.\nThen\n\\begin{align}\n    \\phi(\\vec{x}=a)\n    &=\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\left\\{ \n    \\frac{q}{a\\left| \\hat{n} - \\frac{1}{a} \\hat{n}'\\right|}\n    + \\frac{q'}{y'\\left| \\hat{n}' - \\frac{1}{y'} \\hat{n}\\right|}\n    \\right\\}\n\\end{align}\nIf we choose\n\\begin{align}\n    \\frac{q}{a}\n    &=\n    - \\frac{q'}{y'}\n\\end{align}\nand\n\\begin{align}\n    \\frac{y}{a} &= \\frac{a}{y'}\n\\end{align}\nthen $\\phi\\left( |\\vec{x}| = a \\right) = 0$\nfor all $\\hat{n}$ and $\\hat{n}'$.\nThen the position and magnitude of the image charge is\n\\begin{align}\n    q' &= -\\frac{a}{y}q\\\\\n    y' &= \\frac{a^2}{y}\n\\end{align}\n", "meta": {"hexsha": "3666c979770f011a23b8d516828298dd7eaaf6e9", "size": 9918, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys610/lecture22.tex", "max_stars_repo_name": "ehua7365/umdphysnotes", "max_stars_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-11T12:53:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-11T12:53:46.000Z", "max_issues_repo_path": "phys610/lecture22.tex", "max_issues_repo_name": "ehua7365/umdphysnotes", "max_issues_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "phys610/lecture22.tex", "max_forks_repo_name": "ehua7365/umdphysnotes", "max_forks_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.9633507853, "max_line_length": 80, "alphanum_fraction": 0.6388384755, "num_tokens": 3451, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.8740772351648678, "lm_q1q2_score": 0.7497555640880741}}
{"text": "\\lab{The Discrete Fourier Transform}{The Discrete Fourier Transform}\n\\objective{The analysis of periodic functions has many applications in pure and applied mathematics, especially in settings dealing with sound waves.\nThe Fourier transform provides a way to analyze such periodic functions.\nIn this lab, we introduce how to work with digital audio signals in Python, implement the discrete Fourier transform, and use the Fourier transform to detect the frequencies present in a given sound wave.\nWe strongly recommend completing the exercises in a Jupyter Notebook.}\n\n\\section*{Digital Audio Signals} % ============================================\n\nSound waves have two important characteristics: \\emph{frequency}, which determines the pitch of the sound, and \\emph{intensity} or \\emph{amplitude}, which determines the volume of the sound.\nComputers use \\emph{digital audio signals} to approximate sound waves.\nThese signals have two key components: \\emph{sample rate}, which relates to the frequency of sound waves, and \\emph{samples}, which measure the amplitude of sound waves at a specific instant in time.\n\nTo see why the sample rate is necessary, consider an array with samples from a sound wave.\nThe sound wave can be arbitrarily stretched or compressed to make a variety of sounds.\nIf compressed, the sound becomes shorter and has a higher pitch.\nSimilarly, the same set of samples with a lower sample rate becomes stretched and has a lower pitch.\n% This is shown by Figure \\ref{fig:DFT_comp_wave}.\n\n\\begin{figure}[H]\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.425\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/tada.pdf}\n    \\caption{The plot of \\texttt{tada.wav}.}\n    \\label{fig:DFT_tada}\n\\end{subfigure}\n\\qquad\n\\begin{subfigure}{.425\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/fast_tada.pdf}\n    \\caption{Compressed plot of \\texttt{tada.wav}.}\n    \\label{fig:DFT_fasttada}\n\\end{subfigure}\n\\caption{Plots of the same set of samples from a sound wave with varying sample rates.\nThe plot on the left is the plot of the samples with the original sample rate.\nThe sample rate of the plot on the right has been doubled, resulting in a compression of the actual sound when played back.}\n\\label{fig:DFT_comp_wave}\n\\end{figure}\n\nGiven the rate at which a set of samples is taken, the wave can be reconstructed exactly as it was recorded.\nIn most applications, this sample rate is measured in \\emph{Hertz} (Hz), the number of samples taken per second.\n% \\footnote{Hertz is ``cycles per second'' and has units $1/s$.}\nThe standard rate for high quality audio is $44100$ equally spaced samples per second, or $44.1$ kHz.\n\n\\subsection*{Wave File Format} % ----------------------------------------------\n\nOne of the most common audio file formats across operating systems is the \\emph{wave} format, also called \\texttt{wav} after its file extension.\nSciPy has built-in tools to read and create \\texttt{wav} files.\nTo read a \\texttt{wav} file, use \\li{scipy.io.wavfile.read()}.\nThis function returns the signal's sample rate and its samples.\n\n\\begin{lstlisting}\n# Read from the sound file.\n>>> from scipy.io import wavfile\n>>> rate, samples = wavfile.read(\"tada.wav\")\n\\end{lstlisting}\n\nSound waves can be visualized by plotting time against the amplitude of the sound, as in Figure \\ref{fig:DFT_comp_wave}.\n% This plots in the \\emph{time domain}.\nThe amplitude of the sound at a given time is just the value of the sample at that time.\nSince the sample rate is given in samples per second, the length of the sound wave in seconds is found by dividing the number of samples by the sample rate:\n\\begin{align}\n\\label{eq:dft-xaxis-time}\n\\frac{\\mbox{num samples}}{\\mbox{sample rate}}\n= \\frac{\\mbox{num samples}}{\\mbox{num samples/second}}\n= \\mbox{second.}\n\\end{align}\n\n\\begin{problem} % SoundWave.__init__(), SoundWave.plot().\nWrite a \\li{SoundWave} class for storing digital audio signals.\n\\begin{enumerate}\n\\item The constructor should accept an integer sample rate and an array of samples.\nStore each input as an attribute.\n\\item Write a method that plots the stored sound wave.\nUse \\eqref{eq:dft-xaxis-time} to correctly label the $x$-axis in terms of seconds, and set the $y$-axis limits to $[-32768,32767]$ (the reason for this is discussed in the next section).\n\\end{enumerate}\nUse SciPy to read \\texttt{tada.wav}, then instantiate a corresponding \\li{SoundWave} object and display its plot.\nCompare your plot to Figure \\ref{fig:DFT_tada}.\n\\label{prob:fft-SoundWave-init}\n\\end{problem}\n\n\\subsection*{Scaling} % -------------------------------------------------------\n\nTo write to a \\texttt{wav} file, use \\li{scipy.io.wavfile.write()}.\nThis function accepts the name of the file to write to, the sample rate, and the array of samples as parameters.\n\n\\begin{lstlisting}\n>>> import numpy as np\n\n# Write a 2-second random sound wave sampled at a rate of 44100 Hz.\n>>> samples = np.random.randint(-32768, 32767, 88200, dtype=np.int16)\n>>> wavfile.write(\"white_noise.wav\", 44100, samples)\n\\end{lstlisting}\n\nFor \\li{scipy.io.wavfile.write()} to correctly create a \\texttt{wav} file, the samples must be one of four numerical datatypes: 32-bit floating point (\\li{np.float32}), 32-bit integers (\\li{np.int32}), 16-bit integers (\\li{np.int16}), or 8-bit unsigned integers (\\li{np.uint8}).\nIf samples of a different type are passed into the function, it may still write a file, but the sound will likely be distorted in some way.\nIn this lab, we only work with 16-bit integer samples, unless otherwise specified.\n\nA 16-bit integer is an integer between $-32768$ and $32767$, inclusive.\nIf the elements of an array of samples are not all within this range, the samples must be scaled before writing to a file: multiply the samples by 32767 (the largest number in the 16-bit range) and divide by the largest sample magnitude.\nThis ensures the most accurate representation of the sound and sets it to full volume.\n\\begin{align}\n\\label{eq:dft-scale-samples}\n\\texttt{np.int16}\\left(\\left(\\frac{\\mbox{original samples}}{\\mbox{$\\max$(|original samples|)}}\\right) \\times 32767\\right) =\\mbox{scaled samples}\n\\end{align}\n\nBecause 16-bit integers can only store numbers within a certain range, it is important to multiply the original samples by the largest number in the 16-bit range \\emph{after} dividing by the largest sample magnitude.\nOtherwise, the results of the multiplication may be outside the range of integers that can be represented, causing overflow errors.\nAlso, samples may sometimes contain complex values, especially after some processing.\nMake sure to scale and export only the real part (use the \\li{real} attribute of the array).\n\n\\begin{info} % Embedding sound in a Jupyter Notebook\nThe IPython API includes a tool for embedding sounds in a Jupyter Notebook.\nThe function \\li{IPython.display.Audio()} accepts either a file name or a sample rate (\\li{rate}) and an array of samples (\\li{data}); calling the function generates an interactive music player in the Notebook.\n\\begin{center}\n\\includegraphics[width=\\textwidth]{figures/notebook_audio.pdf}\n\\end{center}\n% See \\href{https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html?highlight=display.Audio}{\\texttt{https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html}} for more info.\n\\end{info}\n\n\\begin{warn}\n\\textbf{Turn the volume down before listening to any of the sounds in this lab.}\n%, especially if you are using headphones.\n\\end{warn}\n\n\\begin{problem} % SoundWave.export().\nAdd a method to the \\li{SoundWave} class that accepts a file name and a boolean \\li{force}.\nWrite to the specified file using the stored sample rate and the array of samples.\nIf the array of samples does not have \\li{np.int16} as its data type, or if \\li{force} is \\li{True}, scale the samples as in \\eqref{eq:dft-scale-samples} before writing the file.\n\nUse your method to create two new files that contains the same sound as \\texttt{tada.wav}: one without scaling, and one with scaling (use \\li{force=True}).\nUse \\li{IPython.display.Audio()} to display \\texttt{tada.wav} and the new files.\nAll three files should sound identical, except the scaled file should be louder than the other two.\n\\end{problem}\n\n\\section*{Generating Sounds} % ================================================\n\nSinusoidal waves correspond to pure frequencies, like a single note on the piano.\nRecall that the function $\\sin(x)$ has a period of $2\\pi$.\nTo create a specific tone for $1$ second, we sample from the sinusoid with period $1$,\n\\[\nf(x) = \\sin(2\\pi xk),\n\\]\nwhere $k$ is the desired frequency.\nAccording to \\eqref{eq:dft-xaxis-time}, generating a sound that lasts for $s$ seconds at a sample rate $r$ requires $rs$ equally spaced samples in the interval $[0, s]$. % (these are the $x$ values).\n\n\\begin{problem} % Generate simple tones.\nWrite a function that accepts floats $k$ and $s$.\nCreate a \\li{SoundWave} instance containing a tone with frequency $k$ that lasts for $s$ seconds.\nUse a sample rate of $r = 44100$.\n\nThe following table shows some frequencies that correspond to common notes.\nOctaves of these notes are obtained by doubling or halving these frequencies.\n\\begin{center}\n\\begin{tabular}{c|c}\nNote & Frequency (Hz) \\\\\n\\hline\nA & $440$ \\\\\nB & $493.88$ \\\\\nC & $523.25$ \\\\\nD & $587.33$ \\\\\nE & $659.25$ \\\\\nF & $698.46$ \\\\\nG & $783.99$ \\\\\nA & $880$ \\\\\n\\end{tabular}\n\\end{center}\nUse your function to generate an A tone lasting for 2 seconds.\n\\label{prob:generate_note}\n\\end{problem}\n\n\\begin{problem} % Make a chord and a changing sound.\nDigital audio signals can be combined by addition or concatenation.\nAdding samples overlays tones so they play simultaneously; concatenated samples plays one set of samples after the other with no overlap.\n\n\\begin{enumerate}\n\\item Implement the \\li{__add__()} magic method for the \\li{SoundWave} class so that if \\li{A} and \\li{B} are \\li{SoundWave} instances, \\li{A + B} creates a new \\li{SoundWave} object whose samples are the element-wise sum of the samples from \\li{A} and \\li{B}.\nRaise a \\li{ValueError} if the sample arrays from \\li{A} and \\li{B} are not the same length.\n\nUse your method to generate a three-second A minor chord (A, C, and E together).\n\n\\item Implement the \\li{__rshift__()} magic method\\footnote{The \\lstinline[basicstyle=\\footnotesize\\ttfamily]{>>} operator is a \\emph{bitwise shift operator} and is usually reserved for operating on binary numbers.} for the \\li{SoundWave} class so that if \\li{A} and \\li{B} are \\li{SoundWave} instances, \\li{A >> B} creates a new \\li{SoundWave} object whose samples are the concatenation of the samples from \\li{A}, then the samples from \\li{B}.\nRaise a \\li{ValueError} if the sample rates from the two objects are not equal.\n\\\\(Hint: \\li{np.concatenate()}, \\li{np.hstack()}, and/or \\li{np.append()} may be useful.)\n\nUse your method to generate the arpeggio A $\\rightarrow$ C $\\rightarrow$ E, where each pitch lasts one second.\n\n\\end{enumerate}\nConsider using these two methods to produce elementary versions of some simple tunes.\n\\label{prob:minor_chord_example}\n\\end{problem}\n\n\\section*{The Discrete Fourier Transform} % ===================================\n\nAs with the chords generated above, all sound waves are sums of varying amounts of different frequencies (pitches).\nIn the case of the discrete samples $\\f = \\begin{bmatrix}f_0 & f_1 & \\cdots & f_{n-1}\\end{bmatrix}\\trp$ that we have worked with thus far, each $f_i$ gives information about the amplitude of the sound wave at a specific instant in time. \nHowever, sometimes it is useful to find out what frequencies are present in the sound wave and in what amount.\n\nWe can write the sound wave sample as a sum\n\\begin{align}\n\\f = \\sum_{k=0}^{n-1} c_k {\\w_n}^{(k)},\n\\end{align}\nwhere $\\{\\w_n^{(k)}\\}_{k=0}^{n-1}$, called the \\emph{discrete Fourier basis}, represents various frequencies.\nThe coefficients $c_k$ represent the amount of each frequency present in the sound wave. \n\nThe \\emph{discrete Fourier transform (DFT)} is a linear transformation that takes $\\f$ and finds the coefficients  $\\c = \\begin{bmatrix}c_0 & c_1 & \\cdots & c_{n-1}\\end{bmatrix}\\trp$ needed to write $\\f$ in this frequency basis.\nLater in the lab, we will convert the index $k$ to a value in Hertz to find out what frequency $c_k$ corresponds to.\n\nBecause the sample $\\f$ was generated by taking $n$ evenly spaced samples of the sound wave, we  generate the basis $\\{\\w_n^{(k)}\\}_{k=0}^{n-1}$ by taking $n$ evenly spaced samples of the frequencies represented by the oscillating functions $\\{e^{-2 \\pi i k t  / n}\\}_{k = 0}^{n-1}$.\n(Note that $i = \\sqrt{-1}$, the imaginary unit, is represented as  \\li{1j} in Python).\nThis yields  \n\\begin{align}\n\\w_n^{(k)} = \\begin{bmatrix}\\omega_n^0 & \\omega_n^{-k} & \\cdots & \\omega_n^{-(n-1)k}\\end{bmatrix}\\trp,\n\\end{align}\nwhere $\\omega_n = e^{2 \\pi i / n}$.\n\nThe DFT is then represented by the change of basis matrix \n\\begin{align}\nF_{n} = \\frac{1}{n} \\begin{bmatrix}\\w_n^0 & \\w_n^1 & \\w_n^2 & \\cdots & \\w_n^{n-1} \\end{bmatrix}\n= \\frac{1}{n}\\left[\\begin{array}{*{5}c} \n1 & 1 & 1 & \\cdots & 1 \\\\\n1 & \\omega_n^{-1} & \\omega_n^{-2} & \\cdots & \\omega_n^{-(n-1)} \\\\\n1 & \\omega_n^{-2} & \\omega_n^{-4} & \\cdots & \\omega_n^{-2(n-1)} \\\\\n\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n1 & \\omega_n^{-(n-1)} & \\omega_n^{-2(n-1)} & \\cdots & \\omega_n^{-(n-1)^2} \\\\\n \\end{array}\\right],\n \\label{eq:dft-matrix}\n\\end{align}\n\nand we can take the DFT of $f$ by calculating \n\\begin{align}\n\\c = F_n \\f.\n\\label{eq:dft}\n\\end{align}\n\nNote that the DFT depends on the number of samples $n$, since the discrete Fourier basis we use depends on the number of samples taken.\nThe larger $n$ is, the closer the frequencies approximated by the DFT will be to the actual frequencies present in the sound wave.\n\n\\begin{warn}\nThere are several different conventions for defining the DFT.\nFor example, instead of \\eqref{eq:dft}, \\li{scipy.fftpack.fft()} uses the formula\n\\begin{align*}\n\\c = n F_n \\f,\n\\end{align*}\nwhere $F_n$ is as given \\eqref{eq:dft-matrix}.\nDenoting this version of the DFT as $\\hat{F}_n\\f = \\hat{\\c}$, we have $nF_n = \\hat{F}_n$ and $n\\c = \\hat{\\c}$.\nThe conversion is easy, but it is very important to be aware of which convention a particular implementation of the DFT uses.\n\\end{warn}\n\n\\begin{problem} % naive DFT.\nWrite a function that accepts an array $\\f$ of samples.\nUse \\ref{eq:dft} to calculate the coefficients $\\c$ of the DFT of $\\f$. Include the $1/n$ scaling in front of the sum.\n\nTest your implementation on small, random arrays against \\li{scipy.fftpack.fft()}, scaling your output $\\c$ to match SciPy's output $\\hat{\\c}$. \nOnce your function is working, try to optimize it so that the entire array of coefficients is calculated in the one line.\n\\\\(Hint: Use array broadcasting.)\n\\label{prob:dft-naive}\n\\end{problem}\n\n\\subsection*{The Fast Fourier Transform} % ------------------------------------\n\nCalculating the DFT of a vector of $n$ samples using only (\\ref{eq:dft}) is at least $O(n^2)$, which is incredibly slow for realistic sound waves.\nFortunately, due to its inherent symmetry, the DFT can be implemented as a recursive algorithm by separating the computation into even and odd indices.\nThis method of calculating the DFT is called the \\emph{fast Fourier transform} (FFT) and runs in $O(n\\log{n})$ time.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{simple\\_fft}{$\\f$, $N$}\n    \\Procedure{split}{$\\g$}\n        \\State $n \\gets \\size{\\g}$\n        \\If{$n \\le N$}\n            \\label{step:fft-base-case-a}\n            \\State \\pseudoli{return} $n F_n \\g$\n                \\Comment{Use the function from Problem \\ref{prob:dft-naive} for small enough $\\g$.}\n                \\label{step:fft-base-case-b}\n        \\Else{}\n            \\State \\li{even} $\\gets$ \\li{SPLIT}$(\\g_{::2})$\n                \\Comment{Get the DFT of every other entry of $\\g$, starting from $0$.}\n            \\State \\li{odd} $\\gets$ \\li{SPLIT}$(\\g_{1::2})$\n                \\Comment{Get the DFT of every other entry of $\\g$, starting from $1$.}\n            \\State $\\z \\gets\\zeros{n}$\n            \\For{$k = 0,1,\\ldots,n-1$}\n                \\Comment{Calculate the exponential parts of the sum.}\n                \\label{step:fft-loop-a}\n                \\State $z_k \\gets e^{-2\\pi i k / n}$\n                    % \\Comment{This part can be done with array broadcasting.}\n                    \\label{step:fft-loop-b}\n            \\EndFor\n            \\State{$m \\gets n\\,$\\li{//}$\\,2$}\n                \\Comment{Get the middle index for $\\z$ (\\li{//} is integer division).}\n            \\State \\pseudoli{return} $[$\\li{even}$\\ +\\ \\z_{:m} \\odot $\\li{odd}$,\\ $\\li{even}$\\ +\\ \\z_{m:} \\odot $\\li{odd}$]$\n                \\Comment{Concatenate two arrays of length $m$.}\n                % \\Comment{$\\odot$ is component-wise multiplication.}\n                \\label{step:fft-concatenate}\n        \\EndIf\n    \\EndProcedure\n    \\State \\pseudoli{return} \\li{SPLIT}$(\\f)\\,/\\,\\size{\\f}$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The fast Fourier transform for arrays with $2^a$ entries for some $a \\in \\mathbb{N}$.}\n\\label{alg:FFT}\n\\end{algorithm}\nNote that the base case in lines \\ref{step:fft-base-case-a}--\\ref{step:fft-base-case-b} of Algorithm \\ref{alg:FFT} results from setting $n = 1$ in \\eqref{eq:dft}, yielding the single coefficient $c_0 = g_0$.\nThe $\\odot$ in line \\ref{step:fft-concatenate} indicates the component-wise product\n\\begin{align*}\n\\f\\odot\\g = \\begin{bmatrix}f_0g_0 & f_1g_1 & \\cdots & f_{n-1}g_{n-1}\\end{bmatrix}\\trp,\n\\end{align*}\nwhich is also called the \\emph{Hadamard product} of $\\f$ and $\\g$.\n\nThis algorithm performs significantly better than the na\\\"ive implementation of the DFT, but the simple version described in Algorithm \\ref{alg:FFT} only works if the number of original samples is exactly a power of $2$.\nSciPy's FFT routines avoid this problem by padding the sample array with zeros until the size is a power of $2$, then executing the remainder of the algorithm from there. % TODO: This might not be true!! See https://stackoverflow.com/questions/6855169/convolution-computations-in-numpy-scipy.\nOf course, SciPy also uses various other tricks to further speed up the computation.\n\n\\begin{problem} % simple FFT.\nWrite a function that accepts an array $\\f$ of $n$ samples where $n$ is a power of $2$.\nUse Algorithm \\ref{alg:FFT} to calculate the DFT of $\\f$.\n\\\\(Hint: eliminate the loop in lines \\ref{step:fft-loop-a}--\\ref{step:fft-loop-b} with \\li{np.arange()} and array broadcasting, and use \\li{np.concatenate()} or \\li{np.hstack()} for the concatenation in line \\ref{step:fft-concatenate}.)\n\nTest your implementation on random arrays against \\li{scipy.fftpack.fft()}, scaling your output $\\c$ to match SciPy's output $\\hat{\\c}$.\nTime your function from Problem \\ref{prob:dft-naive}, this function, and SciPy's function on an array with $8192$ entries.\n\\\\(Hint: Use \\li{<p<\\%time>p>} in Jupyter Notebook to time a single line of code.)\n\\label{prob:fft-simple}\n\\end{problem}\n\n\\section*{Visualizing the DFT} % ==============================================\n\nThe graph of the DFT of a sound wave is useful in a variety of applications.\nWhile the graph of the sound in the time domain gives information about the amplitude (volume) of a sound wave at a given time, the graph of the DFT shows which frequencies (pitches) are present in the sound wave.\nPlotting a sound's DFT is referred to as plotting in the \\emph{frequency domain}.\n\nAs a simple example, the single-tone notes generated by the function in Problem \\ref{prob:generate_note} contain only one frequency.\nFor instance, Figure \\ref{fig:dft_a} graphs the DFT of an A tone.\nHowever, this plot shows two frequency spikes, despite there being only one frequency present in the actual sound.\nThis is due to symmetries inherent to the DFT; for frequency detection, the second half of the plot can be ignored as in Figure \\ref{fig:dft_a_half}.\n\n\\begin{figure}[H]\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/dft_a.pdf}\n    \\caption{The DFT of an A tone with symmetries.}\n    \\label{fig:dft_a}\n\\end{subfigure}\n% \\qquad\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/dft_a_half.pdf}\n    \\caption{The DFT of an A tone without symmetries.}\n    \\label{fig:dft_a_half}\n\\end{subfigure}\n\\caption{Plots of the DFT with and without symmetries.\nNotice that the $x$-axis of the symmetrical plot on the left goes up to $44100$ (the sample rate of the sound wave) while the $x$-axis of the non-symmetric plot on the right goes up to only $22050$ (half the sample rate).\nAlso notice that the spikes occur at $440$ Hz and $43660$ Hz (which is $44100 - 440$).}\n\\end{figure}\n\nThe DFT of a more complicated sound wave has many frequencies, each of which corresponds to a different tone present in the sound wave.\nThe magnitude of the coefficients indicates a frequency's influence in the sound wave; a greater magnitude means that the frequency is more influential.\n% See Figure \\ref{fig:dft_tada} for an example.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=.7\\textwidth]{figures/dft_tada.pdf}\n\\caption{The discrete Fourier transform of \\texttt{tada.wav}.\nEach spike in the graph corresponds to a frequency present in the sound wave.\nSince the sample rate of \\texttt{tada.wav} is $22050$ Hz, the plot of its DFT without symmetries only goes up to $11025$ Hz, half of its sample rate.}\n\\label{fig:dft_tada}\n\\end{figure}\n\n\\subsection*{Plotting Frequencies} % ------------------------------------------\n\nSince the DFT represents the frequency domain, the $x$-axis of a plot of the DFT should be in terms of Hertz, which has units $1/s$.\nIn other words, to plot the magnitudes of the Fourier coefficients against the correct frequencies, we must convert the frequency index $k$ of each $c_k$ to Hertz.\nThis can be done by multiplying the index by the sample rate and dividing by the number of samples:\n\\begin{align}\n\\label{eq:fft-cycles-conversion}\n\\frac{k}{\\mbox{num samples}} \\times \\frac{\\mbox{num samples}}{\\mbox{second}}\n= \\frac{k}{\\mbox{second}}.\n% = k\\ \\mbox{Hz}\n\\end{align}\nIn other words, $kr/n = v$, where $r$ is the sample rate, $n$ is the number of samples, and $v$ is the resulting frequency.\n\n% Plotting the DFT of a sound wave without any other considerations results in an $x$-axis that corresponds to the index of the coefficients in the DFT, not their frequencies.\n% To label the $x$-axis with the frequencies measured in Hz, or cycles per second, the units must be converted.\n% The sample rate is measured in samples per second, so dividing the frequency index by the number of samples and multiplying by the sample rate results in cycles per second, or Hz.\n\n\\begin{problem} % plotting the DFT.\nModify your \\li{SoundWave} plotting method from Problem \\ref{prob:fft-SoundWave-init} so that it accepts a boolean defaulting to \\li{False}.\nIf the boolean is \\li{True}, take the DFT of the stored samples and plot---in a new subplot---the frequencies present on the $x$-axis and the magnitudes of those frequencies (use \\li{np.<<abs>>()} to compute the magnitude) on the $y$-axis.\nOnly display the first half of the plot (as in Figures \\ref{fig:dft_a_half} and \\ref{fig:dft_a_half}), and use \\eqref{eq:fft-cycles-conversion} to adjust the $x$-axis so that it correctly shows the frequencies in Hertz.\nUse SciPy to calculate the DFT.\n\nDisplay the DFT plots of the A tone and the A minor chord from Problem \\ref{prob:minor_chord_example}.\nCompare your results to Figures \\ref{fig:dft_a} and \\ref{fig:dft_chord}.\n\\end{problem}\n\n\\begin{figure}[H] % DFT of the minor chord.\n\\centering\n\\includegraphics[width=.7\\textwidth]{figures/dft_chord.pdf}\n\\caption{The DFT of the A minor chord.}\n\\label{fig:dft_chord}\n\\end{figure}\n\nIf the frequencies present in a sound are already known before plotting its DFT, the plot may be interesting, but little new information is actually revealed.\nThus, the main applications of the DFT involve sounds in which the frequencies present are unknown.\nOne application in particular is sound filtering, which will be explored in greater detail in a subsequent lab.\nThe first step in filtering a sound is determining the frequencies present in that sound by taking its DFT.\n\nConsider the DFT of the A minor chord in Figure \\ref{fig:dft_chord}.\nThis graph shows that there are three main frequencies present in the sound.\nTo determine what those frequencies are, find which indices of the array of DFT coefficients have the three largest values, then scale these indices the same way as in \\eqref{eq:fft-cycles-conversion} to translate the indices to frequencies in Hertz.\n\n\\begin{problem} % Mystery chord.\nThe file \\texttt{mystery\\_chord.wav} contains an unknown chord.\nUse the DFT and the frequency table in Problem \\ref{prob:generate_note} to determine the individual notes that are present in the sound.\n\\\\(Hint: \\li{np.argsort()} may be useful.)\n\\end{problem}\n\n\\begin{comment}\n\\newpage\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Stereo vs Mono} % ------------------------------------------------\n\nMono has a single channel so sample arrays are one-dimensional; stereo sounds have channels for left and right speakers, so sample arrays are 2-dimensional: one COLUMN for the left channel, and one COLUMN for the right channel.\n\n\\subsection*{Improvements to the SoundWave Class} % ---------------------------\n\n\\subsection*{Other Implementations of the FFT} % ------------------------------\n\nFASTEST FOURIER TRANSFORM IN THE WEST!!!\n\\url{https://en.wikipedia.org/wiki/FFTW}\n\\url{http://www.fftw.org/}\n\n\\end{comment}\n", "meta": {"hexsha": "00c085cdb174e49e557aac8ebe563a348a2b359c", "size": 25733, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume2/FourierTransform/FourierTransform.tex", "max_stars_repo_name": "chrismmuir/Labs-1", "max_stars_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 190, "max_stars_repo_stars_event_min_datetime": "2015-07-17T01:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T19:16:19.000Z", "max_issues_repo_path": "Volume2/FourierTransform/FourierTransform.tex", "max_issues_repo_name": "chrismmuir/Labs-1", "max_issues_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 184, "max_issues_repo_issues_event_min_datetime": "2015-07-16T17:56:06.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T23:47:14.000Z", "max_forks_repo_path": "Volume2/FourierTransform/FourierTransform.tex", "max_forks_repo_name": "chrismmuir/Labs-1", "max_forks_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 76, "max_forks_repo_forks_event_min_datetime": "2015-08-06T02:53:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T11:08:57.000Z", "avg_line_length": 58.885583524, "max_line_length": 445, "alphanum_fraction": 0.7185714841, "num_tokens": 6906, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8311430562234878, "lm_q2_score": 0.9019206712569267, "lm_q1q2_score": 0.7496251031796217}}
{"text": "\\chapter{Computer Science}\r\n\\section{Basics}\r\n{\\bf Definitions:}\r\n$f \\in O(g) \\leftrightarrow\r\ng \\in \\Omega (f) \\leftrightarrow\r\nL_{x \\rightarrow \\infty} {\\frac {f(x)} {g(x)}} < \\infty$.\r\n$f \\in o(g) \\leftrightarrow\r\ng \\in \\omega (f) \\leftrightarrow\r\nL_{x \\rightarrow \\infty} {\\frac {f(x)} {g(x)}} = 0 $.  $G_1 \\subset (G,E)$ is a\r\n\\emph{strongly connected component} iff $x,y \\in G_1$ means there is a directed path\r\n$x \\rightarrow y$ and a directed path $y \\rightarrow x$.\r\n\\\\\r\n\\\\\r\n{\\bf Recurrences:}  Suppose $T(n)= aT(n/b) + f(n)$.  \r\nIf $f(n)= O(n^{log_b(a)-\\epsilon})$ then $T(n)= \\Theta(n^{log_b(a)})$.\r\nIf $f(n)= \\Theta(n^{log_b(a)})$ then $T(n)= \\Theta(n^{log_b(a)}lg(n))$.\r\nIf $f(n)= \\Omega(n^{log_b(a)+\\epsilon})$ and $af(n/b) \\le c f(n), c<1$\r\nthen $T(n)= \\Theta(f(n))$.\\\\\r\n\\\\\r\n{\\bf Binary arithmetic:}\r\nAdding an $m$ bit number and $n$ bit number takes $O(max(m,n))$ time and $O(m+n)$ space.\r\nMultiplying an $m$ bit number and $n$ bit number takes $O(mn)$ time and $O(m+n)$ space.\r\nThe \\emph{extended gcd} of an $m$ bit number and $n$ bit number takes \r\n$O(mn)$ time and $O(m+n)$ space.\r\n$GCD(u, v)$ average running time:\r\n$O((1+{\\frac {max(u,v)} {(u,v)}}) lg(min(u, v)))$.\r\n$A^E \\jmod{M}$ where $M$ is an $m$ bit number and $E$ is an $n$ bit number \r\ntakes $O(n m^2)$ time. \r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nGiven $\\epsilon>0$ there is a multiplication algorithm such that the number\r\nof elementary operation $T(n)$ needed to multiply two $n$-bit numbers\r\nsatisfies\r\n$T(n) <c(\\epsilon)n^{1+\\epsilon}$.  Strassen: $T(n)=O(n lg(n))$.\r\n\\\\\r\n\\\\\r\n{\\bf Floating Point Numbers:} $f \\times b^{e-q}$ is represented as $(e, f)$.\r\n\\\\\r\n\\\\\r\n{\\bf Heapsort:} For a node, $t$, the \\emph{heap property} is\r\n$value(t) \\geq value(LEFT(t))$ and $value(t) \\geq value(RIGHT(t))$.  \r\nA heap list $A[1], A[2] , \\ldots, A[n]$ can represent a heap with \r\n$LEFT(A[i])= A[2i]$ and $RIGHT(A[i])= A[2i+1]$.  Note that a path \r\nfrom a node to an edge is linearly ordered and\r\nso largest element is at root.  Usually the\r\nheap is arranged so that $value(LEFT(t)) \\geq value(RIGHT(t))$.\r\n\\begin{multicols} {2} {\r\n\\begin{verbatim}\r\nheapify(A,i,j,n) \r\n{\r\n    if(i is not a leaf) {\r\n        k= child of i with largest elment;\r\n        if(A[k]>A[i]) {\r\n            swap (A[i], A[k]);\r\n            heapify (A, k, j, n);\r\n        }\r\n    }\r\n}\r\n\\end{verbatim}\r\n\r\n\\begin{verbatim}\r\nbuildheap(A,n) \r\n{\r\n    for(i=n;i>1;i--) {\r\n        heapify(A,i,n,n);\r\n    }\r\n}\r\n\r\nheapsort(A,n) \r\n{\r\n    buildheap(A,n);\r\n    for(i=n;i>1;i--) {\r\n        swap(A[1], A[i]); \r\n        heapify(&A[1],i-1, i-1);\r\n    }\r\n}\r\n\\end{verbatim}\r\n}\r\n\\end{multicols}\r\n\r\n{\\bf Shortest Path:} between x and y in $G=(V, E)$ where\r\n$l(e)>0$ is the weight of $e \\in E$ is $O(e lg(n))$. d(v) contains an overestimate\r\nof the shortest path from s to v.\r\n$prev(v)$ contains the previous element in the\r\nshortest path from s to v.  (Ford-Bellman version works for negative weights.)\r\n\\begin{multicols} {2} {\r\n\\begin{verbatim}\r\nshortestpath(V,E,s)  {\r\n    for (v in V) {\r\n        d(v):= infinity;\r\n        prev(v):= empty-set;\r\n        }\r\n    H:= empty-set; \r\n    d(s)= 0; \r\n    mark(s);\r\n    while (H is not empty) {\r\n        h= deletemin(H);\r\n        for e=(v, w) in E, w unmarked) {\r\n            if(d(w)>(d(v)+l(e))) {\r\n                d(w)=d(v)+l(e);\r\n                prev(w)= v;\r\n                insert(w, H);\r\n                }\r\n            }\r\n        }\r\n    }\r\n\\end{verbatim}\r\n}\r\n\\end{multicols}\r\n\r\n{\\bf Union-find:}  Link(x, y): make x and y kids of a common parent.  Parent node\r\npoints to itself.  $m$ UNION-FIND operations on $n$ elements is $O((m+n) lg(n))$.\r\n\r\n\\begin{multicols} {2} {\r\n\\begin{verbatim}\r\nmakeset(x) {\r\n    p(x)= x;\r\n    rank(x)= 0;\r\n    } \r\n\r\nfind(x) {\r\n    if(x != p(x))\r\n        p(x)=  find(p(x)); \r\n   return(p(x));\r\n   }\r\n\r\nlink(x, y) {\r\n    if(rank(x)>rank(y)) swap(x, y);\r\n    if(rank(x)==rank(y)) rank(y)++;\r\n    p(x)= y;\r\n    return(y);\r\n    }\r\n\r\nunion(x,y) {\r\n    link(find(x), find(y));\r\n    }\r\n\\end{verbatim}\r\n}\r\n\\end{multicols}\r\n\r\n{\\bf Order statistics:} The algorithm below satisfies the recurrence \r\n$T(n) \\leq T({\\frac n 5}) + T({\\frac {3n} 4} + cn)$.\r\n\\\\\r\n\\\\\r\nSelect(k,S) \\\\\r\n\\{\\\\\r\n\\jt if($k<50$)\r\n\\jt \\jt sort and return k'th element;\\\\\r\n\\jt Partition $S$ into $5$ sequences $S_1, \\ldots , S_{\\lfloor {\\frac{|S|} 5} \\rfloor}$, $T$,\r\nwhere $T$ contains the up to $4$ leftovers;\\\\\r\n\\jt Sort each $5$ set;\\\\\r\n\\jt Let $M$ be the set of the medians for the $S_i$;\\\\\r\n\\jt m= Select($\\lceil {\\frac {|M|} 2} \\rceil$;\\\\\r\n\\jt let $S_1$, $S_2$, $S_3$ be the sets of elements $<, =, > m$ respectively;\\\\\r\n\\jt if($|S_2|>k$)\\\\\r\n\\jt \\jt return Select($k, S_1$);\\\\\r\n\\jt if($|S_1|+|S_2|>k$) \\\\\r\n\\jt \\jt return $m$;\\\\\r\n\\jt return($k-|S_1|-|S_2|$, $S_3$);\\\\\r\n\\}\r\n\\\\\r\n\\\\\r\n{\\bf $2-3$ Trees:} Interior node has smallest key of 2nd and 3rd descendant.\r\nInsert: Do membership test stop at terminal position; id 2 kids, add one, if\r\nnot, split into two, $(n, n')$.  Add $n'$ using insert.  \r\nDelete: If two kids left, done.\r\nOtherwise, try to move node of a siblings under common parent; if you can't,\r\ntransfer this node to a sibling.  If this leaves a singleton, in the parent,\r\nrecurse the transfer on parent.\r\n\\\\\r\n\\\\\r\n{\\bf Minimal spanning trees:}  Consider a graph,\r\n$G= (V,E)$, each edge $e \\in E$ having weight $wt(e)$.  \r\n\\\\\r\n\\emph{Kruskal:}\r\n\\\\\r\n Initialize a forest of trees consisting of $V$.\\\\\r\nwhile( there is more than one component) \\\\\r\n\\jt 1. Remove edge from $E$ of minimum weight.\\\\\r\n\\jt 2. Add it if it unites two trees.  Discard it if it creates a cycle.\\\\\r\n\\\\\r\n\\emph{Prim:}\\\\\r\n1. Choose an arbitrary vertex $S= \\{x\\}$, $M=\\emptyset$.\\\\\r\n2. while($S \\ne V$) \\\\\r\n\\jt 3. Choose an edge $e=(x, y), x \\in S$ of minimum weight.\\\\\r\n\\jt 4. If $y \\in S$, discard.  Otherwise $M= m \\cup \\{e\\}$\r\n\\\\\r\n\\\\\r\n{\\bf NP Completeness:}\r\n$P \\subseteq N$.  If $A \\le B$ \r\n\\footnote{$A \\le B$ means problem $A$ can be transformed to problem $B$ in polynomial time;\r\nthis is called a reduction \\emph {from} $A$ \\emph{to} $B$.}\r\nand $B \\in P$ then $A \\in P$.  $L \\in NPC$ if and only if \r\n$L \\in NP$, $A \\in NP \\rightarrow A \\le L$.  Classical computation theory classifies\r\nproblems by a ``certain'' solution on all instances.  The class of problems which\r\ncan be solved in polynomial time\r\n``up to an arbitrary error, $\\epsilon$'' is called $RP$ for ``randomized\r\npolynomial.''  $P \\subseteq RP \\subseteq NP$.\r\n\\\\\r\n\\\\\r\n{\\bf Problems in P and NP:}\r\nP: MST.  Given a weighted graph, G, and a weight, K $\\exists$ a tree,\r\nNP: TSP.  Given a weighted graph, G, and a weight, K $\\exists$ a cycle,\r\nC, that connects all nodes  of G with weight $\\leq K$.\\\\\r\nP: Circuit value.  NP: Circuit SAT.\\\\\r\nP: 2-SAT: Use $\\phi= (a_1 \\vee b_1  )  \\wedge ... \\wedge (a_n \\vee b_n )$ to form graph with \r\nnodes $a_i, b_i, {\\overline {a_i}}, {\\overline {b_i}}$ insert\r\nedges ${\\overline {a_i}} \\rightarrow b_i$\r\nand ${\\overline {b_i}} \\rightarrow a_i$.  Find strongly connected components.  If no\r\nstrongly connected component contains a variable and its negation, it is satisfiable;\r\notherwise not.  So 2-SAT is not NP hard.  NP: 3-SAT.  Note in disjunctive normal form \r\nSAT is easy but translating is hard.\r\n\\\\\r\nP: matching.  NP: 3D matching.\\\\\r\nP: Linear Programming.   NP: Integer Programming.\\\\\r\n\\\\\r\n{\\bf Ford-Fulkerson:} Augmenting path p is a simple path from s to t that\r\nincreases the flow.\r\n\\begin{verbatim}\r\n    Initialize flow, f to 0;\r\n    while (there is an augmenting path, p)\r\n        augment flow along p;\r\n    return f;\r\n\\end{verbatim}\r\n{\\bf Undecidability:} Suppose $Term(P,X)$ is a boolean function which takes a program,\r\n$P$, and an input $X$.\r\n$Term(P,X)$ returns true iff $P$ terminates on $X$.\r\n$Term(P,X)$ returns false iff $P$ does not terminate on $X$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  $Term(P, X)$ does not exist.  Suppose it did. Set\r\n\\begin{verbatim}\r\ndiag(P,X) {\r\n  if $Term(P,P)$==true \r\n    loop\r\n    }\r\n\\end{verbatim}\r\n$diag(diag)$ terminates iff it doesn't terminate.  Contradiction.\\\\\r\n\\\\\r\n{\\bf Stable Matching} (up to $n^2$ rounds). (1) Boy goes to favorite girl\r\non list.  (2) Girl tells highest choice ``maybe'', tells everyone else\r\nNo.  (3) Boy crosses off girls that have said no.\r\n(4) terminate in the round when every girl has\r\ntold one boy ``maybe'', convert ``maybe'' to yes.\\\\\r\n\\\\\r\n{\\bf Linear Programming Standard Form:}\r\nMaximize $x= C^{T}X$, subject to $AX= B$, $X \\geq 0$.  \r\nProblem:  There may be exponentially\r\nmany corners. (Reason: introduce to $n$ constraint inequalities $m$ slack variables;  the\r\ncorner points occur when $m$ variables are $0$.  There are ${{m+n} \\choose m}$ ways to select\r\nthe variables to be set to $0$.)\r\nSimplex idea: move along growing paths instead of trying all corners randomly.\r\nDual, minimize $x= B^{T}W$, subject to $A^{T}W= C$, $W \\geq 0$.\\\\\r\n\\\\\r\n{\\bf Notation:} \\emph{basic variables} $\\ne 0$, \\emph{non basic variables} $=0$.  \r\nA is an $m \\times n$\r\nmatrix, with $m$ variables (including slack) and $m$ constraints.\r\nTableau has basic variables and their values in two first columns.  Top row is\r\nall variables as labels middle is matrix (A).\r\nRightmost column is constants (B).  Bottom row is $C-C^{T}X$ in terms of the\r\nnon-basic variables.  Basic algorithm is:\r\n\\begin{enumerate}\r\n\\item Locate most negative coefficient in bottom row, call column containing it $x_{j}$.\r\n\\item Compute ${\\frac {B_{i}} {A_{ij}}}$.  The smallest one, denoted $k$, is the pivot.\r\n\\item Convert pivot to 1 and eliminate all coefficients in the same column.\r\n\\item Replace $x_{k}$ row by $x_{j}$.\r\n\\item repeat until no negative numbers in bottom row.\r\n\\end{enumerate}\r\n{\\bf SAT/$k$-sat reduction:}\r\n$l_1 \\vee l_2 \\vee \\ldots \\vee l_n \\rightarrow\r\nl_1 \\vee l_2 \\vee x_1 \\wedge\r\n{\\overline {x_1}} \\vee l_3 \\vee x_2 \\wedge \\ldots\r\n{\\overline {x_{n-3}}} \\vee l_{n-1} \\vee \\ldots \\vee l_n$.\r\nPhase transition for SAT: ${\\frac {clauses} {variables}} \\approx 4.3$.\r\n3-SAT $\\rightarrow$ MQ.  Replace $+$ with $\\vee$, $\\cdot$ with $\\wedge$ , 1 with true,\r\n0 with false.  If $c_i= x_{i_1} \\vee x_{i_2} \\vee x_{i_3}$ add\r\n$x_{i_1} + x_{i_2} + x_{i_3} x_{i_4}$ and\r\n$x_{i_1} \\cdot x_{i_2} + x_{i_2} \\cdot x_{i_3} + x_{i_1} \\cdot x_{i_3} = x_{i_5}$\r\nand $x_{i_4} + x_{i_5} + x_{i_4} \\cdot x_{i_5} =1$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} The following problems are\r\nNP Complete: SAT, $k$-SAT ($k>2$), k-clique, Vertex Cover, Independent set,\r\nSubset Sum, Partition, Bin Packing, Hamilton circuit.\r\n\\emph{Clique/SAT reduction:} Each occurrence of a variable is a vertex, edges\r\nbetween vertices if their occurrence in the clauses have same complementarity.\r\n$k$ is number of clauses.\r\n\\\\\r\n\\\\\r\n{\\bf Hard core bit:} Let $f$ be a one-way function from\r\n$\\{0,1\\}^n$ to $\\{0,1\\}^n$,\r\n$x \\in \\{0,1\\}^n$ ,\r\n$r \\in \\{0,1\\}^n$ ,\r\nand let $G$ be a function that takes\r\n$\\{0,1\\}^n$ to $\\{0,1\\}^{n+1}$ by $G(x,r)= f(x), r, <x,r>$.  Let $P$ be a\r\nprediction function.  Goldreich-Levin: If there is an algorithm $A$ such\r\nthat $| Prob_r [A(f(x), r) = <x,r>] - {\\frac {1} {2}} | \\geq \\epsilon$ then\r\nthere is an algorithm $I$ that produces a list $L$ of size $\\leq\r\n{\\frac {1} {{\\epsilon^2}}}$ with $x$ in $L$, (2) $I$ runs in time\r\npolynomial in $n$ and ${\\frac {1} {\\epsilon}}$ and doesn't compute $f$.\r\nA function is \\emph{negligible:} smaller that inverse of any polynomial.\r\nWitness: $w:\\Sigma^* \\rightarrow P( \\Gamma^* )$.  \\emph{Decision problem:}\r\n$A_w \\subseteq \\Sigma^*$, $A_w= \\{ x \\in\r\n\\Sigma * | w(x) \\ne 0 \\}$.\r\n\\emph{Example:} $x \\in \\Sigma^*$ is an encoding of a Boolean Form.\r\n$y \\in \\Gamma *$\r\nis an encoding of a truth assignment.\r\n$\\#P$ is class of witnesses, $w$, such that: (i) there is a P-time algorithm\r\nto decide if $x \\in w(x)$ and (ii)\r\n$\\exists k \\in N$ such that $\\forall y \\in\r\nw(x),\r\n|y| \\leq |x|^k$.  $w \\in \\#P \\rightarrow A_w \\in NP$ and\r\n$A \\in\r\nNP \\rightarrow \\exists w, A=A_w$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nCounting perfect matchings of a bipartite graph is $\\#P$ complete.\r\n\\\\\r\n\\\\\r\n{\\bf Finite State Machine:} Finite alphabet, $A$, finite states, $S$, two functions:\r\n$\\delta: S \\times A \\rightarrow S$ and\r\n$\\gamma: S \\times A \\rightarrow A$.\\\\\r\nFinite State Automata is FSM without output.\\\\\r\n\\\\\r\n{\\bf Regular expressions:}\r\nLanguage $L$ is a subset of $A^*$.\r\n\\emph{Regular expression}, $R$ over alphabet, $A$ with letters \r\n$a \\in A$: (1) $ \\epsilon \\in R$,\r\n(2) $a \\in A$, (3) $r^* \\in R$ if $r \\in T$,\r\n(4) $r_1 r_2 \\in R$ if $r_1 , r_2 \\in R$,\r\n(4) $r_1 \\vee r_2 \\in R$ if $r_1 , r_2 \\in R$.\r\nLanguage associated with a regular expression: (1) $ L(\\epsilon)=\\{ \\epsilon \\}$,\r\n(2) $L(a)= \\{a\\}$, (3) $L(r^*) L(r)^*$,\r\n(3) $L(r_1 r_2)= L(r_1 ) L(r_2)$,\r\n(4) $L(r_1 \\vee r_2) = L(r_1) \\cup L(r_2)$.\r\n$L$ is a \\emph{regular language} if $\\exists r \\in R$ with $L=L(r)$.\r\n\\emph{Phrase structured Grammar}, \r\n$G$, consists of (1) Vocabulary $V$, (2) terminals (denoted by lower case letters) \r\n$T \\subseteq V$, (3) variables or non-terminals $V \\setminus T$ (denoted\r\nby upper case letters), (4) a designated non-terminal $S$, called the start symbol, (5)\r\na finite set $P$ of productions: $\\alpha \\rightarrow \\beta$.\r\n$w \\Rightarrow w'$ iff $\\exists u,v, w=u \\alpha v$ and $w'= u \\beta v$.\r\n\\\\\r\n\\\\\r\n{\\bf Grammars:}\r\nGrammar types are defined by production rule limitation: (1) Type 0: no limitations,\r\n(2) Type 1: production rules of the form\r\n$\\alpha \\rightarrow \\beta$, $|\\alpha| \\leq |\\beta|$ or\r\n$\\alpha \\rightarrow \\epsilon$,\r\n(3) Type 2: production rules of the form $A \\rightarrow \\beta$,\r\n(4) Type 3: production rules of the form\r\n$A \\rightarrow a$ or $A \\rightarrow aB$,\r\n(5) \\emph{context free:} production rules of the form $A \\rightarrow \\beta$,\r\n(6) \\emph{context sensitive:} production rules of the form\r\n$\\alpha A \\alpha' \\rightarrow \\alpha \\beta \\alpha'$,\r\n(7) regular: production rules of the form\r\n$A \\rightarrow a$, $A \\rightarrow aB$ or $S \\rightarrow \\epsilon$.\r\nBackus-Naur form for type 2 context free grammar:\r\n(i) ::= replaces $\\rightarrow$,\r\n(ii) non-terminals enclosed in brackets $<>$ and\r\n(iii) all productions with the same non-terminal\r\nLHS are combined into a single RHS.\r\n\\emph{Example:} \r\n$\\langle sentence  \\rangle$ ::= \r\n$\\langle noun$ $phrase \\rangle\\langle verb$ $phrase \\rangle$, \r\n$\\langle noun$ $phrase \\rangle$ ::= \r\n$\\langle noun \\rangle|\\langle article \\rangle\\langle noun \\rangle$,\r\n$\\langle noun \\rangle$::= boy.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nA language $L$ can be generated by a type 3 (regular) grammar iff there is a finite\r\nautomaton $M$ that accepts $L$.\r\nPushdown automata (with infinite stack) recognize $L$ iff $L$ is context free.\r\n$L$ is recognized by a linear bounded automata  (tape linearly bounded in length of\r\ninput) iff $L$ is context sensitive.\r\n\\\\\r\n\\\\\r\n{\\bf Minimizing state machines:} Two states, $s_i$, $s_j$, are $0$ equivalent if\r\nthe states have the same output for every input.  States are $k+1$ equivalent if they\r\nhave the same outputs for any input and their successor states are $k$ equivalent.\r\nMinimization procedure:  Define $\\pi_0$ as all states that are $0$ equivalent.  Do until\r\nno further refinement happens: sub-partition $\\pi_{k}$ into $\\pi_{k+1}$ into subblocks are\r\n$k+1$ equivalent.  This terminates.  When it does, merge equivalent states.\r\n\\\\\r\n\\\\\r\n{\\bf Pumping Lemma:}  Let $L$ be a finite state grammar accepted by a finite state\r\nmachine, $M$, with $n$ states.\r\nIf $\\alpha$ is a string accepted by $M$ of length at least $n$, then\r\n$\\alpha = u||v||w$ where $u||v^i||w$ is also in $L$.\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nTuring machines are FSMs with a bi-directionally infinite tape with a finite\r\nnumber of pre-marked squares and an additional transition function\r\n$\\sigma: S \\times A \\rightarrow \\{L, R, HALT\\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Huffman algorithm:}  Label each node with frequency.  As long as more than one\r\nnode is present, take the two nodes with the lowest frequency and combine them\r\ninto a single node with the two combinants as children.\r\nNew node has combined frequency.  Left subnode has lower of two frequencies,\r\nright the higher.  Read code by traversing from root.  Left traversal at parent is\r\n0, right, 1.\r\n\\\\\r\nResulting code is prefix free.  Further $H(X) \\leq l(x) \\leq H(X)+1$.\r\n\\subsection{Concurrency}\r\n\\begin{verbatim}\r\nECMA Consistency\r\n    1. Reads and writes cannot move before volatile read.\r\n    2. Reads and writes cannot move after volatile write.\r\n\r\nCompareExchange(ref int loc, int value, int comp) {\r\n    Monitor.Enter;\r\n    ret= loc;\r\n    if(ret==comp) loc= value;\r\n    Monitor.Exit;\r\n    return ret;\r\n}\r\n\r\nclass SpinLock {\r\n    volatile int isEntered=0;   // 1 if lock acquired\r\n    int Enter() {\r\n        while(CompareExchange(isEntered,1,0)!=0);\r\n        }\r\n    Exit() {\r\n        isEntered= 0;\r\n    }\r\n}\r\n\r\nMemory Consistency Rules\r\n    1. Behavior of Thread in isolation is unaffected\r\n    2. Reads cannot move before lock\r\n    3. Writes cannot move after lock\r\n\\end{verbatim}\r\n\r\n\\begin{multicols} {2} {\r\n\\begin{verbatim}\r\n\r\nDPLL(C,A) {     \r\n// C: clauses, A: literal assignments\r\n//      Termination:\r\n//              empty clause: unsatisfiable\r\n//              empty set of clauses: satisfiable\r\n    if(A is empty) \r\n        return SATISFIED;\r\n    if(A has an empty clause) \r\n        return UNSATISFIABLE;\r\n// unit clause is a clause with one literal\r\n    if unit clause (l) occurs in A  \r\n        return DPLL (assign(l,C), A + l));\r\n    if l occurs with same polarity throughout\r\n        return DPLL (assign(l,C), A + l));\r\n    l= choose-literal(A);\r\n    return DPLL (assign(l,C), A + l)) OR \r\n           DPLL (assign(not l,C), A + not l));\r\n    }\r\nNote: If A, B, C are p-free, \r\n(A | p) & (B|!p) &C) is inconsistent iff (A|B)&C is.\r\n\r\nChase(C,x) {\r\n    set x to t;\r\n    delete all clauses containing x from C;\r\n    delete all occurences of !x from clauses in C;\r\n    if (empty clause) \r\n        return UNSATISFIABLE;\r\n    if (unit clause l) \r\n        return Chase(l,t);\r\n    if (C is empty)  \r\n        return SATISFIED;\r\n\\end{verbatim}\r\n}\r\n\\end{multicols}\r\n\\begin{multicols} {2} {\r\n\\begin{verbatim}\r\nPriority Queue (arrays start at 1 here)\r\n\r\nExtractMax(A) {\r\n    if(heapsize(A)<1) \r\n        return error;\r\n    max= A[1];\r\n    A[1]= A[heapsize(A)];\r\n    heapsize(A)=heapsize(A)-1;\r\n    Heapify(A,1);\r\n    return max;\r\n}\r\n\r\nInsert(A,k) {\r\n    heapsize(A)=heapsize(A)+1;\r\n    i= heapsize(A);\r\n    while(i>1 & A[parent(i)]<k) {\r\n        A[i]= A[parent(i)];\r\n        i= parent(i);\r\n        }\r\n    A[i]= k;\r\n    }\r\n\\end{verbatim}\r\n}\r\n\\end{multicols}\r\n\\begin{multicols} {2} {\r\n\\begin{verbatim}\r\nSelect(A,k) {      \r\n    // select kth element from A[1,...n-1]\r\n    if(k==0) return min(A);\r\n    // For randomized, choose x in A at random\r\n    x= SideSelect(A);\r\n    Set B= < y in A: y <=x>\r\n    Set C= < y: y>x >\r\n    if(k<|B|) return Select(B,k)\r\n    return Select(C,|B|-k);\r\n    }\r\n\r\nSideSelect(A,k) {\r\n    for(i<=0<=n=INT(size(A)/5))\r\n        Sort successive 5 elements \r\n        // A[5i]<=A[5i+1]<=A[5i+2]<=A[5i+3]<=A[5i+4] \r\n    R= < A[5i+2] > , 0<=i<=n\r\n    x= SideSelect(R,Size(R)/2);       \r\n    // note x <= 3*INT((n-5)/10) elements.\r\n    }\r\n// Note E(T(n))= E(T(sn))+n,  x ~ 3/4\r\n\\end{verbatim}\r\n}\r\n\\end{multicols}\r\n\\begin{multicols} {2} {\r\n\\begin{verbatim}\r\nstruct semaphore {\r\n    int count;\r\n    ProcessQueue queue;\r\n    };\r\n\r\nvoid P(semaphore s) {\r\n    if(s.count>0) {\r\n         (s.count)--;\r\n    else\r\n         s.queue.Insert(); // block\r\n    }\r\nvoid V(semaphore s) {\r\n    if(s.queue.empty())\r\n        (s.count)++;\r\n    else\r\n        s.queue.remove(); //schedule process\r\n    }\r\n\r\nshared semaphore s= 1;\r\n     P(s);\r\n     //critical section\r\n     V(s);\r\n\\end{verbatim}\r\n}\r\n\\end{multicols}\r\n\\begin{multicols} {2} {\r\n\\begin{verbatim}\r\nMap()\r\nReduce()\r\nScan()      // || prefix\r\nScatter()\r\nGather()\r\n\r\nReaders/writers\r\nlinear sweep\r\n\r\n\\end{verbatim}\r\n}\r\n\\end{multicols}\r\nArchitecture and current PCs:\r\n$P= C \\times V^2 \\times f$.  \r\n\\emph{Big endian} word: $0, 1, 2, 3$ (descending byte address).\r\n\\emph{Little endian} word: $3, 2, 1, 0$ (descending byte address).\r\n\\begin{center}\r\n\\begin{tabular} {|l|c|r|}\r\n\\hline\r\n{\\bf Optimization Level} & {\\bf Description} & {\\bf Level}\\\\\r\n\\hline\r\nHigh & Procedure inlining & 3\\\\\r\nLocal & common subexpression & 1\\\\\r\nLocal & constant propagation & 1\\\\\r\nLocal & stack height reduction (expression tree) & 1\\\\\r\nGlobal & global common subexpression & 2\\\\\r\nGlobal & global constant propagation & 2\\\\\r\nGlobal & code motion & 2\\\\\r\nGlobal & induction variable elimination & 2\\\\\r\nGlobal & loop unrolling & 4\\\\\r\nGlobal & strip mining & 4\\\\\r\nArch specific & strength reduction & 1\\\\\r\nArch specific & pipeline scheduling & 1\\\\\r\nArch specific & branch offset & 1\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nEffect on performance of Bubblesort (100K items).  Base is 300MHz Sparc Ultra.\r\n\\begin{center}\r\n\\begin{tabular} {|r|r|r|r|r|}\r\n\\hline\r\n{\\bf Optimization level} & {\\bf Relative performance} & {\\bf Clocks} & {\\bf Instructions} & {\\bf CPI}\\\\\r\n\\hline\r\n0 & 1.00 & 158,615 & 114,938 & 1.38 \\\\\r\n1 & 2.37 & 66,990  & 37,470 & 1.79 \\\\\r\n2 & 2.38 & 66,521 & 39,993 & 1.66 \\\\\r\n3 & 2.41 & 65,747 & 44,993 & 1.46\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nSRAM: $.5-1 ns$, $4,000 \\$/GB$.\r\nDRAM: $50-70 ns$, $100 \\$/GB$.\r\nDisk: $10^7 ns$, $1 \\$/GB$.  \r\nDram address setup: 1 memory cycle, access time: 15 cycles, data transfer: 1 cycle.\r\n4-way interleave plus multiword block gets time down to 20 cycles on average.\r\nMiss penalty to main: 500 cycles, to L2: 25 cycles.  TLB: 512 entries.  Miss: 100 cycles.\r\nMiss percentage; .5-1.\r\nDisk seek latency: 10 ms, rotational latency: 5 ms, transfer rate: 50 MB/s, MTTF:\r\n$10^6$ hours.  Bus speed: system (800 MHz), NB (266 MHz), SB (33 MHz).  Bandwidth:\r\n\\begin{center}\r\n\\begin{tabular} {|r|r|}\r\n\\hline\r\n{\\bf Device} & {\\bf Bandwidth} \\\\\r\n\\hline\r\nMemory & 3.2GB/sec \\\\\r\nDisk & 150 MB/sec\\\\\r\nAGP & 2.1 GB/sec\\\\\r\nPCI& 132 MB/sec\\\\\r\nNIC & 20 MB/sec\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n{\\bf Dwarves:}\r\nFinite state machines, combinatorics, graphs, Structured/unstructured grids, dense matrix, sparse\r\nmatrix, map-reduce, backtrack/branch-and-bound, $N$-body, FFT, Graphical models.\\\\\r\n\\\\\r\n$LU${\\bf-factorization:}  Let $A \\ne 0$ be an $m \\times n$ matrix.  There are permutation matrices\r\n$P,Q$ such that $P^T A Q= LU$ where $L$ is lower triangular and $U$ is upper triangular.\r\n$QR$-factorization: Let $X \\in {\\mathbb C}^{n \\times p}$ have rant $p$ then\r\n$x= QR$ where $Q$ is an orthogonal matrix and $R$ is an upper triangular matrix.  \r\n$QR$-factorization via unitary operations is used in the least square approximation problem.\r\nSpectral decomposition: $U^H A U= diag( \\lambda_1 , \\lambda_2 , \\ldots , \\lambda_n)$.\r\nThe eigenvalues of $X^H X$ are the sequence of singular values of $X$.\r\nFor a $p \\times q$ matrix, row major storage is \r\n$A[1,1]= a[1]$,\r\n$A[1,2]= a[2]$, \\ldots, $A[2,1]=a[q+1]$, \r\netc., \r\nand in general,\r\nrow major storage is $A[i,j]= a[(i-1)q+j]$,\r\ncolumn major storage is\r\n$A[1,1]= a[1]$,\r\n$A[1,2]= a[q+1]$, \\ldots, $A[2,1]=a[2]$,  etc.,\r\nand in general,\r\ncolumn major storage is $A[i,j]= a[(j-1)p+i]$.  One step of Gaussian Elimination:\r\n$$\r\n\\left(\r\n\\begin{array}{cc}\r\n\\alpha_{11} & \\alpha_{12}^T\\\\\r\n\\alpha_{21} & A{22}\\\\\r\n\\end{array}\\right)=\r\n\\left(\r\n\\begin{array}{c}\r\n\\beta_1\\\\\r\nb_2\\\\\r\n\\end{array}\r\n\\right)\r\n\\rightarrow\r\n\\left(\r\n\\begin{array}{cc}\r\n\\alpha_{11} & \\alpha_{12}^T\\\\\r\n0 & A{22}- \\alpha_{11}^{-1}\\alpha_{21}\\alpha_{12}^T\\\\\r\n\\end{array}\r\n\\right)=\r\n\\left(\r\n\\begin{array}{c}\r\n\\beta_1\\\\\r\nb_2- \\alpha_{11}^{-1} \\beta_1 \\alpha_{21}\\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\n{\\bf Definition:}\r\nA \\emph{hard core predicate} of a one-way function, $f$ is easy to compute given $x$ but not\r\ngiven $f(x)$.  If $f$ is a one-way function, $g(x,r)= (f(x),r)$ is a hard core predicate.\r\nLet $B_x(y): \\{0,1\\}^n \\rightarrow \\{0,1\\}$ be a probabilistic oracle with\r\n$\\epsilon$ advantage for $(x,y)$, that\r\nis, $Pr(B_x(y)=(x,y))= {\\frac {1+\\epsilon} 2}$ and let $EQ_x(y)$ be an oracle for $x=y$.\r\nDefine \r\n$Gd_B= \\{ y: B_x(y)= (x,y) \\}$ and\r\n$Bd_B= \\{ y: B_x(y) \\ne (x,y) \\}$ so \r\n$|Gd_B|= {\\frac {1 + \\epsilon} 2} 2^n$ and\r\n$|Bd_B|= {\\frac {1 - \\epsilon} 2} 2^n$.\r\n\\\\\r\n\\\\\r\n{\\bf Goldreich-Levin:}\r\nLet  $R= \\langle r_1, \\ldots, r_m \\rangle$ be a random selection of elements from\r\n$[n]$, $z \\in [n]$ and $b_j=(x,r_j)$.  Let $\\langle S_j \\rangle$ be a fixed\r\nenumeration of the subsets of $[m]$.  $R[S]= \\sum_{j \\in S} r_j$.\r\nDefine the following algorithm:\\\\\r\n\\\\\r\n$STRONG-SC^{B_x}(z, r_1, \\ldots, r_m, b_1, \\ldots , b_m)$ \\\\\r\n\\jt $sum= 0;$ \\\\\r\n\\jt for($i=1; i \\leq 2^m)$) \\{\\\\\r\n\\jt \\jt $R(S_i)= \\sum_{j \\in S_i} r_j;$ \\\\\r\n\\jt \\jt $B[S_i]= \\sum_{j \\in S_i} b_j;$ \\\\\r\n\\jt \\jt $c= B_x(z+R[S_i]) -b[S_i];$ \\\\\r\n\\jt \\jt $sum+= c;$\\\\\r\n\\jt \\jt \\}\\\\\r\n\\jt return $sum > {\\frac {2^m} 2}$;\\\\\r\n\\\\\r\nDefine the following algorithm:\\\\\r\n\\\\\r\n$RECOVER^{B_x, EQ_x}(1^n)$ \\\\\r\n\\jt Pick $r_1, \\ldots r_m \\in [n]$ at random;\\\\\r\n\\jt for($i=1; i \\leq 2^m)$) \\{\\\\\r\n\\jt \\jt $(b_1, \\ldots, b_m)_2 = i-2;$\\\\\r\n\\jt \\jt for($k=1; k \\leq n$)\\\\\r\n\\jt \\jt \\jt $y^{(k)}= STRONG-SC^{B_x}(e_k, r_1, \\ldots, r_m, b_1, \\ldots, b_m);$\\\\\r\n\\jt \\jt $y= y^{(1)}||y^{(2)} || \\ldots || y^{(n)};$\\\\\r\n\\jt \\jt if ($EQ_x(y)==1)$ \\\\\r\n\\jt \\jt \\jt return $y$;\\\\\r\n\\jt \\jt \\}\\\\\r\n\\\\\r\n{\\bf Notation:}\r\nLet \r\n$q_B$ be the number of calls to $B_x$,\r\n$q_E$ be the number of calls to $EQ_x$,\r\n$\\epsilon$ be the advantage for $B_x$,\r\n$n$ the length of the strings and $t$  the running time of\r\n$RECOVER^{B_x, EQ_x}(1^n)$. We have the following:\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} Let $m$ be a parameter and $M=2^m$.  There is an algorithm, $A$ which\r\nmakes $q_B= nM$ calls to $B_x$, $q_E= M$ calls to $EQ_x$ and runs in time\r\n$t=O(nM^2)$ which determines $x$ with probability \r\nat least $1-\\delta, \\delta= {\\frac n {\\epsilon^2 M}}$.\\\\\r\n\\\\\r\nFirst some lemmas and notation.  Let $R= \\langle r_1, \\ldots , r_m \\rangle$ and\r\n$X_1, X_2, \\ldots , X_M: S \\rightarrow R$ be a set of real valued random variables on\r\nthe sample space $S$.\\\\\r\n\\\\\r\n{\\bf Lemma 1:} If \r\n$X_1, X_2, \\ldots , X_M: S \\rightarrow R$ are pairwise independent and\r\n$X= X_1 + X_2 + \\ldots + X_M$ then\r\n$Var(X)= Var(X_1) + Var(X_2 )+ \\ldots + Var(X_M)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$Var(X)= E(X^2)-E(X)^2= \r\nE(\\sum_{i,j} X_i X_j) -\r\n\\sum_{i,j} E(X_i) E(X_j)\r\n= \\sum_i [E(X_i^2) - E(X_i)^2]- \\sum_{i\\ne j} [E(X_i X_j)- E(X_i)E(X_j)]$.  The\r\nfinal bracketed sum is $0$ by pairwise independence.\r\n\\end{quote}\r\n{\\bf Lemma 2:} If \r\n$X_1, X_2, \\ldots , X_M: S \\rightarrow R$ are pairwise independent, \r\n$X= X_1 + X_2 + \\ldots + X_M$  and $\\mu= E(X)= \\sum_{i=1}^M E(X_i)$ then\r\n$Pr(|x-\\mu| \\geq A) \\leq {\\frac {\\sum_{i=1}^M Var(X_i)} {A^2}}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nBy Chebychev, $Pr(|X-\\mu| \\geq A) \\leq {\\frac  {Var(X)} {A^2}}$ and by the previous lemma,\r\n$Var(X)= Var(X_1) + Var(X_2) + \\ldots + Var(X_M)$.\r\n\\end{quote}\r\n{\\bf Lemma 3:} Let $M=2^m$.\r\nFor any $z \\in \\{0, 1\\}^n$,\r\n$Pr(STRONG-SC^{B_x}(z, r_1, \\ldots, r_m, b_1, \\ldots , b_m) \r\n\\ne (z,x)) \\leq {\\frac 1 {M \\epsilon^2}}$.\r\n\\begin{quote}\r\n\\emph{Proof:} For $R= \\langle r_1, r_2, \\ldots, r_m \\rangle$ and $S_1, S_2, \\ldots,\r\nS_{2^m}$ a fixed enumeration of $[m]$, define a random variable $X_i(R)=1$ if\r\n$B_x(z+R[S_i])= (x,z)+ b[S_i]$ and $0$ otherwise.  $X_i(R)$ and $X_j(R)$ are pairwise\r\nindependent since there is an $r_l \\in R$ that is included in \\emph{either} the sum\r\n$R[S_i]$ or $R[S_j]$ but not both.  $E(X_i)= Pr(z+R[S_i] \\in Gd_B)= {\\frac {1 + \\epsilon} 2}$.\r\nSince $E(X_i^2)= E(X_i)$, $Var(x_i)= E(X_1^2)=E(X_i)^2= E(X_i)-E(X_1)^2= E(X_1)(1-E(X_i))=\r\n{\\frac {1+\\epsilon} 2}\r\n{\\frac {1-\\epsilon} 2} =\r\n{\\frac {1-\\epsilon^2} 4} $.  Note that $\\mu= {\\frac {M(1+\\epsilon)} 2}$ and so by the\r\nprevious lemma,  $P(X < {\\frac {M} {2}}) =\r\nP(|X-\\mu| > {\\frac {M \\epsilon} {2}})  \\leq\r\n{\\frac {M(1-\\epsilon^2)/4} {(M \\epsilon/2)^2}} \\leq {\\frac 1 {M \\epsilon^2}}$.\r\n\\end{quote}\r\n{\\bf Proof of Theorem:} Let $M=2^m$.\r\nFor any $z \\in \\{0, 1\\}^n$,\r\n$Pr(RECOVER^{B_x, EQ_x}(1^n) \\ne x) \\leq {\\frac n {M \\epsilon^2}}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nThe loop in $RECOVER$ calls $STRONG-SC^{B_x}$ $n$ times.  Each call is wrong with \r\nprobability at most ${\\frac 1 {M \\epsilon^2}}$ so the probability that $RECOVER$ returns\r\nthe wrong answer is at most\r\n${\\frac n {M \\epsilon^2}}$.\r\n\\end{quote}\r\nNote that obtaining $x$ with $p= {\\frac 1 2}$ occurs with $M= 2n\\epsilon^{-2}$ and the\r\nrunning time is $O(n^3 \\epsilon^{-4})$ with\r\n$q_B= O(n^2 \\epsilon^{-2})$ and\r\n$q_E= O(n \\epsilon^{-2})$.\r\n", "meta": {"hexsha": "e662778f2db8506d98bd82c940d6d58590784ad2", "size": 28209, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "science/cs.tex", "max_stars_repo_name": "jlmucb/class_notes", "max_stars_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "science/cs.tex", "max_issues_repo_name": "jlmucb/class_notes", "max_issues_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "science/cs.tex", "max_forks_repo_name": "jlmucb/class_notes", "max_forks_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.7982233503, "max_line_length": 104, "alphanum_fraction": 0.6066149101, "num_tokens": 9939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843132, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7496250931387852}}
{"text": "\\subsection{Matrix Representation for Rational Bézier Surface}\n\\label{oct_sec:mrep}\n\\paragraph{}\nThe intersection between a straight line and a NURBS surface is calculated using matrix representation method.\nThe method in 2D (NURBS curve) has been introduced in Sec.~\\ref{adap_sec:mrep}.\nA tensor-product rational bézier surface of degree $(p_1,p_2)$ can be expressed as\n\\begin{equation}\n\t\\phi(u,v)\\in\\mathbf{R}^2 \\rightarrow \\frac{\\sum_{i=0}^{p_1}\\sum_{j=0}^{p_2}w_{i,j}\\mathbf{P}_{i,j}B_i^{p_1}(t)B_j^{p_2}(t) }{\\sum_{i=0}^{p_1}\\sum_{j=0}^{p_2}w_{i,j}B_i^{p_1}(t)B_j^{p_2}(t)}\n\\end{equation}\n%\nFor the surface, $\\mathbf{L}$ and $\\mathbf{R}$ with order $(v_1,v_2)$\n\\begin{subequations}\n\\begin{align}\n\t\\mathbf{L} =\n\t\\begin{bmatrix}\n\t\tB_0^{v_1+p_1}(u)B_0^{v_2+p_2}(v) & B_1^{v_1+p_1}(u)B_0^{v_2+p_2}(v) & \\dots & B_{v_1+p_1}^{v_1+p_1}(u)B_{v_2+p_2}^{v_2+p_2}(v)\n\t\\end{bmatrix} \\\\\n\t\\mathbf{R} =\n\t\\begin{bmatrix}\n\t\tB_0^{v_1}(u)B_0^{v_2}(v)f_0(u,v) & B_0^{v_1}(u)B_1^{v_2}(v)f_0(u,v) & \\dots & B_{v_1}^{v_1}(u)B_{v_2}^{v_2}(v)f_3(u,v)\n\t\\end{bmatrix}\n\\end{align}\n\\end{subequations}\n%\nFollowing the same manner in Sec.~\\ref{adap_sec:mrep}, it can be derived that \n\\begin{equation}\n\t\\mathbf{S}_{\\left( (i+k)(v_2+p_2+1)+j+l, l(v1+1)+k\\right)} = \n\t\\frac{\\mathbf{C}_k^{v_1}\\mathbf{C}_l^{v_2}\\mathbf{C}_i^{p_1}\\mathbf{C}_j^{p_2}} \n\t\t{\\mathbf{C}_{i+k}^{v_1+d_2}\\mathbf{C}_{j+l}^{v_2+d_2}}c_{(i,j)}\n\\end{equation}\n%\n\\subsection{Properties of the $\\mathbf{M_v}$ Matrix}\nAs described in the previous sections, the $\\mathbf{M_v}$ matrix is defined so that\n\\begin{equation}\n\t\\begin{bmatrix}\n\t\\psi_1(t_0) \\dots \\psi_{m_v}(t_0)\n\t\\end{bmatrix}\n\t\\times\n\t\\mathbf{M_v(\\mathbf{P})}\n\t= \\vec{0}\n\\end{equation}\nwhere $\\mathbf{P}$ is a point on the rational bézier curve/surface.\nThe order $v$ shall be no less than a critical value and it is proofed to be\n\\begin{itemize}\n\t\\item $v>max(p-1,1)$ for rational bézier curve\n\t\\item $(v_1,v_2) > (2p_1 -1, p_2 -1)$ or  $(v_1,v_2) > (p_1 -1, 2p_2 -1)$\n\\end{itemize}\nThe following properties are proofed in \\citep{Laurent2014}\n\\begin{enumerate}\n\t\\item For all degrees $geq$ critical degree and all point $\\in\\mathbf{R}^3$ , rank($\\mathbf{M_v}(\\mathbf{P})$) $<m_v$ if and only if $\\mathbf{P}\\in$ the closure of $\\overline{Im}(\\phi)$.\n\t\\item If $\\mathbf{P}\\in\\mathbf{R}^3$ is a point with a unique pre-image by $\\phi$, the dimension of the null space of $\\mathbf{M_v}(\\mathbf{P})^T$ is one. \n\t\\item $\\delta\\mathbf{M_v}(\\mathbf{P}) = 0$ if $\\mathbf{P} \\in\\overline{Im}(\\phi)$\n\\end{enumerate}\nwhere \n\\begin{equation}\n\t\\delta\\mathbf{M_v}(\\mathbf{P}) = \\prod_{i=1}^{m_v}\\sigma_i(\\mathbf{M_v}(\\mathbf{P}))\n\\end{equation}\nand $\\sigma_i$ is the diagonal of $\\Sigma$ in the SVD decomposition of $\\mathbf{M_v}(\\mathbf{P})=U\\Sigma V^T$\n\n\\begin{enumerate}\n\t\\setcounter{enumi}{3}\n\t\\item $\\forall\\mathbf{P}\\in\\mathbf{R}^3$, $d(\\mathbf{P},\\overline{Im}(\\phi))^{n_1}\\leq c_1 \\delta\\mathbf{M_v}(\\mathbf{P})$\n\t\\item $\\forall\\mathbf{P}\\in\\mathbf{R}^3$, $\\delta\\mathbf{M_v}(\\mathbf{P})^{n_2}\\leq c_2 d(\\mathbf{P},\\overline{Im}(\\phi))^{n_2} $\n\\end{enumerate}\nwhere $c_1,c_2,n_1,n_2$ are constant.\\\\\nThese two properties give a distance function like function of the $M_v$ matrix. When the point get away to the surface, $\\delta\\mathbf{M_v}$ is getting larger and vice versa.\n\\paragraph{}\nIf the point is on the curve/surface, in which case $\\delta\\mathbf{M_v}(\\mathbf{P}) = 0$, the corresponding parameter value on the curve/surface can be easily found by a SVD numerically.\\\\\nThe computation of the null space of $\\mathbf{M_v}(\\mathbf{P}) $ will give a single vector $V=[v_1,v_2,\\dots,v_{m_v}]$based on 2 and $V$ will be proportional to \n\\begin{equation}\n\t\\begin{bmatrix}\n\t\\psi_1(t_0) \\dots \\psi_{m_v}(t_0)\n\t\\end{bmatrix}\n\\end{equation}\nMore specifically, it will be proportional to\n\\begin{equation}\n\t\\begin{bmatrix}\n\t\tB_0^v & B_1^v & \\dots\n\t\\end{bmatrix}\n\\end{equation}\nfor the rational bézier curves and\n\\begin{equation}\n\t\\begin{bmatrix}\n\t\tB_0^{v1}B_0^{v2} & B_0^{v1}B_1^{v2} & \\dots\n\t\\end{bmatrix}\n\\end{equation}\nfor the rational bézier surfaces.\n%\nThe calculation of the intersection is described in detail in \\citep{Buse2010} and \\citep{Ba2009}.\nAll intersections can be calculated at once by using matrix representation of the algebraic curve/surface.\n\\paragraph{} \nGiven a rational curve/surface $C1$\n\\begin{equation}\n\t\\mathbf{P}^1 \\xrightarrow{\\phi_1} \\mathbf{P}^n: (u,v) \\rightarrow(f_0,f_1,f_2,f_3)(u,v)\n\\end{equation}\nthe aim is to find the intersection via matrix representation method between it with another ration curve $C2$\n\\begin{equation}\n\t\\mathbf{P}^1 \\xrightarrow{\\phi_2} \\mathbf{P}^n: (t) \\rightarrow(g_0,g_1,g_2,g_3)(t)\n\\end{equation}\nis to find\n\\begin{equation}\n\t\\mathbf{M}_{v1}(\\phi_2(t) = 0\n\\end{equation}\nwhich leads to\n\\begin{equation}\n\t\\mathbf{M_0}g_0 + \\mathbf{M_1}g_1 + \\mathbf{M_2}g_2 + \\mathbf{M_3}g_3 = 0\n\t\\label{mRep_intec_base}\n\\end{equation}\nBy knowing $g_n$ is a polynomial function with order $p$, Eq.~\\eqref{mRep_intec_base} can be rearranged as\n\\begin{equation}\n\t\\mathbf{M}(t) = \\sum_{i=0}^p \\mathbf{M_i}t^i\n\\end{equation}\nAfter that, the generalized companion $q\\times p$-matrices $A,B$ with rank $\\rho$are introduced\n\\begin{equation}\n\tA = \n\t\\begin{bmatrix}\n\t\t0\t\t&I \t\t&\\dots \t\t&\\dots \t\t&0 \t\t\\\\\n\t\t0 \t\t&0 \t\t&I \t\t\t&\\dots \t\t&0 \t\t\\\\\n\t\t\\vdots \t&\\vdots &\\vdots \t&\\vdots \t&\\vdots \\\\\n\t\t0 \t\t&0 \t\t&\\dots\t\t&\\dots \t\t&I \t\t\\\\\n\t\tM_0^t \t&M_1^t \t&\\dots \t\t&\\dots \t\t&M_{d-1}^t\n\t\\end{bmatrix}\n\\end{equation}\n\\begin{equation}\n\tB = \n\t\\begin{bmatrix}\n\t\tI \t\t&0 \t\t&\\dots \t\t&\\dots \t\t&0 \t\t\\\\\n\t\t0 \t\t&I \t\t&0 \t\t\t&\\dots \t\t&0 \t\t\\\\\n\t\t\\vdots \t&\\vdots &\\vdots \t&\\vdots \t&\\vdots \\\\\n\t\t0 \t\t&0 \t\t&\\dots \t\t&I \t\t\t&0 \t\t\\\\\n\t\t0 \t\t&0 \t\t&\\dots \t\t&\\dots \t\t&-M_d^t \\\\\t\t\n\t\\end{bmatrix}\n\\end{equation}\nBefore the eigenvalues are calculated, the regular part of a non-square pencil of the matrices shall be extracted first which is done by the following step\n\\paragraph{} \n\\textbf{Step 1}\n\tTransform B into its column echelon form by SVD-decomposition.\n\t\\begin{equation}\n\t\\begin{aligned}\n\t\tB_1 = BV_0 = [\\underbrace{B_{1,1}}_{\\rho} |\\underbrace{0}_{q-\\rho}]\t\\\\\n\t\tA_1 = AV_0 = [\\underbrace{A_{1,1}}_{\\rho} |\\underbrace{A_{1,2}}_{q-\\rho}]\n\t\\end{aligned}\n\t\\end{equation}\n\\paragraph{} \n\\textbf{Step 2}\n\tTransform $A_{1,2}$ into its row echelon form\n\t\\begin{equation}\n\t\tU_1A_{1,2} = \n\t\t\\begin{bmatrix}\n\t\t\t\\underline{A^\\prime_{1,2}}\\\\\n\t\t\t0\n\t\t\\end{bmatrix}\n\t\\end{equation}\n\twhere $A^\\prime_{1,2}$ is in full row rank.\\\\\n\tAt the end of step 2, matrix $A$ and $B$ can be represented as\n\t\\begin{equation}\n\t\\begin{aligned}\n\tA^\\prime_1 &=\n\t\\begin{bmatrix}\n\t\tA^\\prime_{1,1} & A^\\prime_{1,2} \\\\\n\t\t\\cmidrule(lr){1-2}\n\t\tA_2 & 0\n\t\\end{bmatrix}\\\\\n\tB^\\prime_1 &=\n\t\\begin{bmatrix}\n\t\tB^\\prime_{1,1} & 0\\\\\n\t\t\\cmidrule(lr){1-2}\n\t\tB_2 & 0\n\t\\end{bmatrix}\n\t\\end{aligned}\n\t\\end{equation}\nwhere $A^\\prime_{1,2}$ has full row rank\\\\\n$\n\\begin{bmatrix}\n\\underline{B^\\prime_{1,1}}\\\\\nB_2\n\\end{bmatrix}\n$ has full column rank\\\\\n$\n\\begin{bmatrix}\n\\underline{B^\\prime_{1,1}}\\\\\nB_2\n\\end{bmatrix}\n$ and $B_2$ are in echelon form\n\\paragraph{}\n$A_2$ and $B_2$ will be the new $A$ and $B$ matrices for next iteration until $B$ has full rank. If $B$ has full row rank but not full rank, $A=A^T$, $B=B^T$.\n\\paragraph{}\nAfter these process, $A$ and $B$ become two square matrices and $B$ is invertible so that the solution for the intersection parameter $t$ can be determined from the eigenvalue of the matrix $AB^{-1}$\n", "meta": {"hexsha": "ad899fd4155a7f6962d7ebc9887dbb715f6ffda2", "size": 7359, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "octree/mrep3d.tex", "max_stars_repo_name": "fa93hws/thesis", "max_stars_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-30T12:14:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-30T12:14:47.000Z", "max_issues_repo_path": "octree/mrep3d.tex", "max_issues_repo_name": "fa93hws/thesis", "max_issues_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "octree/mrep3d.tex", "max_forks_repo_name": "fa93hws/thesis", "max_forks_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9365079365, "max_line_length": 199, "alphanum_fraction": 0.6715586357, "num_tokens": 3076, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.7495433021915594}}
{"text": "% jam 2004-09-10\n\n\\section{Maps between vector spaces}\n\\label{sec:maps}\n\nIn general, the functions discussed here map between real inner product spaces:\n$\\f:\\Vspace \\mapsto \\Wspace$, where $\\Vspace$ is the\n{\\it domain} and $\\Wspace$ is the {\\it codomain}.\nThe real inner product spaces are almost derived from some $\\Reals^n$.\n\nThe {\\it range} of $\\f$, $\\range(f)$, is the set $\\f(\\Vspace)$,\nwhich may be a proper subset of its codomain $\\Wspace$.\nThe {\\it kernel} of $\\f$, $\\kernel(f)$, is the set\n$\\kernel(\\f) = \\{ \\v \\in \\Vspace : \\f(\\v) = \\0 \\}$.\n\nI often use the words `map' and `function' interchangeably.\nWhen I want to distinguish between real- and vector-valued functions,\nI may use 'map' for vector-valued functions and\n'function' for real-valued ones.\n\nI use $\\Uspace$, $\\Vspace$, $\\Wspace$ for generic vector spaces,\n$\\u$, $\\v$, $\\w$, etc., for elements of vector spaces,\nand\n$\\f$, $\\g$, $\\h$ for vector-valued maps/functions.\nI generally do not distinguish $\\Reals$, the real numbers,\nand $\\Reals^1$, or any other 1-dimensional real vector space.\nI sometimes use $f$, $g$, $h$ for extra clarity in the special\ncase of real-valued functions.\n\nThe domains of many interesting functions,\nsuch as those that depend on vertex positions,\nare direct sum of inner product spaces.\nThe {\\it direct sum} $\\Vspace \\oplus \\Wspace$ is the inner product space\nconsisting of the ordered pairs $\\{ (\\v,\\w) : \\v \\in \\Vspace, \\w \\in \\Wspace \\}$\ninheriting the inner product space operations in the obvious way:\n$(\\v_0,\\w_0) \\bullet (\\v_1,\\w_1) = (\\v_0 \\bullet \\v_1) + (\\w_0 \\bullet \\w_1).$\nI will usually write an element of $\\oplus^n \\Vspace$ as\n$(\\v_0,\\ldots,\\v_{n-1})$\nand use\n$\\f(\\v_0,\\v_1,\\ldots,\\v_{n-1})$\nfor a function that depends on $n$ vectors.\n\n%-----------------------------------------------------------------\n\n\\subsection{Linear maps}\n\\label{sec:linear-maps}\n\nA map $\\Lmap(\\v):\\Vspace \\mapsto \\Wspace$\nis {\\it linear} iff\n$\\Lmap(a_0 \\v_0 + a_1 \\v_1) = a_0 \\Lmap(\\v_0) + a_1 \\Lmap(\\v_1)$.\nI will often write $\\Lmap\\v \\equiv \\Lmap(\\v)$.\n\nIts not hard to see that, for a linear map,\nthe range and kernel are linear subspaces of the codomain and\ndomain, respectively.\nThus any linear map between inner product spaces\ndivides its domain and codomain each into 2 orthogonal subspaces.\nThe domain is divided into $\\Vspace = \\kernel(\\Lmap) \\oplus \\kernel^{\\perp}(\\Lmap)$,\nand the codomain is divided into $\\Wspace = \\range(\\Lmap) \\oplus \\range^{\\perp}(\\Lmap)$.\n\nThe most common representation for linear maps is the {\\it matrix:}\nLet $\\Lmap(\\v):\\Vspace \\mapsto \\Wspace$ be linear,\n$\\{ \\e_0^{\\Vspace} \\ldots  \\e_{m-1}^{\\Vspace} \\}$ an orthonormal basis for $\\Vspace$,\nand\n$\\{ \\e_0^{\\Wspace} \\ldots \\e_{n-1}^{\\Wspace} \\}$ an orthonormal  basis for $\\Wspace$\nThen $\\Lmap$ can be expressed as\n\\begin{equation}\n\\Lmap\n =\n\\sum_{i=0}^{m-1} \\sum_{j=0}^{n-1} L_{ij} ( \\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace} )\n\\end{equation}\n$(L_{ij})$ is the matrix representation of $\\Lmap$ with respect to\nthe two bases\\cite{halmos1958finite}.\n\nIt is important to note that there are many usful\nrepresentations for linear maps other than matrices \\cite{mcdonald-1989b}.\nSometimes other representations are used for convenience,\nor to enforce some constraint like symmetry.\nIn some cases, a non-matrix representation must be used,\nbecause a particular linear transformation\ncannot be accurately represented by a matrix of floating point numbers.\n\nExamples:\n\n\\begin{itemize}\n\n\\item Column-wise:\n$\\Lmap = \\sum_{j=0}^{n-1} ( \\c_j^{\\Lmap} \\otimes \\e_j^{\\Vspace} )$\n\n$\\c_j^{\\Lmap} \\in \\Wspace$ are the 'columns' of $\\Lmap$.\n$\\linear_span\\{ \\c_0^{\\Lmap} \\ldots \\c_{n-1}^{\\Lmap} \\} = \\range(\\Lmap)$\n(see \\autoref{sec:spans-and-projections}).\n\n\\item Row-wise:\n$\\Lmap = \\sum_{i=0}^{m-1} ( \\e_i^{\\Wspace} \\otimes  \\r_i^{\\Lmap} )$\n\n$\\r_i^{\\Lmap} \\in \\Vspace$ are the 'rows' of $\\Lmap$.\n$\\linear_span\\{ \\r_0^{\\Lmap} \\ldots \\r_{m-1}^{\\Lmap} \\} =  \\kernel(\\Lmap)^{\\perp}$\n(see \\autoref{sec:spans-and-projections}).\n\n\\item Householder:\n$\\h_{\\v} = \\Identity_{\\Vspace} - \\frac{2}{\\| \\v \\|^2} (\\v \\otimes \\v)$\n\nHouseholder maps are usually chosen to zero the elements of\na vector, or a row or column of a matrix, for a contiguous range of\nindices, say, $[i_0,\\ldots,i_n)$.\n\n\\end {itemize}\n\n%-----------------------------------------------------------------\n\n\\subsection{Affine maps}\n\\label{sec:affine-maps}\n\nA function $\\Amap(\\v):\\Vspace \\mapsto \\Wspace$\nis {\\it affine} if distributes over affine combinations:\n$\\Amap(\\sum_{i=0}^{n-1} a_i \\v_i) = \\sum_{i=0}^{n-1} a_i \\Amap(\\v_i) $\nfor all $\\{a_i\\}$ such that $1 = \\sum_{i=0}^{n-1} a_i$.\n(Note that I am describing affine maps on vector (linear) spaces,\nrather than the slightly more general notion of affine maps on affine spaces.)\nAny linear map between vector spaces is automatically affine.\nThe other major class of affine maps on vector spaces are the translations.\nA {\\it translation,} $\\Tmap_{\\t}$, $\\Vspace \\mapsto \\Vspace$,\nsimply adds a vector ($\\t$) to its argument:\n$\\Tmap_{\\t} \\v = \\v + \\t$.\nIt's not hard to see that any affine map between two vector spaces\ncan be represented as the sum of a linear map and a translation.\nA typical representation for a general affine map $\\Amap : \\Vspace \\mapsto \\Wspace$\nis as a pair $(\\Lmap,\\t)$ where $\\Lmap : \\Vspace \\mapsto \\Wspace$ is linear,\n$\\t \\in \\Wspace$, and $\\Amap(\\v) = \\Lmap(\\v) + \\t$.\n\n%-----------------------------------------------------------------\n\n\\subsection{Spans and projections}\n\\label{sec:spans-and-projections}\n\nLet $\\Vspace$ be an $n$-dimensional inner product space.\n\nThe {\\it linear span} of a set of $m$ vectors in $\\Vspace$\nis the set of linear combinations of those vectors:\n\\begin{equation}\n\\linear_span\\{ \\v_0 \\ldots \\v_{m-1} \\} = \\{\\v \\in \\Vspace : \\v = \\sum_{i=0}^{m-1} a_i \\v_i\\}\n\\end{equation}\n$\\linear_span\\{ \\v_0 \\ldots \\v_{m-1} \\}$ is a linear subspace of $\\Vspace$.\n\nThe {\\it projection} $\\Projection_{\\Sset} \\v$ of a vector $\\v \\in \\Vspace$\nonto an arbitrary subset $\\Sset \\subset \\Vspace$\nis the closest point in $\\Sset$ to $\\v$.\nProjection onto a linear subspace is a linear map and\ncan be computed by summing\nelementary orthogonal projections onto an orthonormal basis for the subspace.\n\nAn orthonormal basis for $\\linear_span\\{ \\v_0 \\ldots \\v_{m-1} \\}$\n(and $\\linear_span\\{ \\v_0 \\ldots \\v_{m-1} \\}^\\perp$)\ncan be computed using the QR decomposition\nof the map $\\Vmap = \\sum_{i=0}^{m-1} \\v_i \\otimes \\e_i$,\n(the $n \\times m$ matrix whose columns are the $\\v_i$).\nSee Golub and Van Loan~\\cite[sec.~5.2]{golub-vanloan-1996}.\n\nThe {\\it affine span} of a set of $m+1$ vectors in $\\Vspace$\nis the set of affine combinations of those vectors:\n\\begin{equation}\n\\affine_span\\{ \\p_0 \\ldots \\p_{m} \\} = \\{\\v \\in \\Vspace : \\v = \\sum_{i=0}^{m} b_i \\p_i;\n1 = \\sum_{i=0}^{m} b_i \\}.\n\\end{equation}\n$\\affine_span\\{ \\p_0 \\ldots \\p_{m} \\}$ is an affine subspace of $\\Vspace$.\n$\\b = ( b_0 \\ldots b_m )$ are {\\it barycentric coordinates}\nfor $\\v$ with respect to $\\{ \\p_0 \\ldots \\p_{m} \\}$.\nThe barycentric coordinates are unique if $\\{ \\p_0 \\ldots \\p_{m} \\}$\nare affinely independent.\n\nAny affine subspace, $\\Aspace$, of a vector space, $\\Vspace$ can be represented as\nas a translation of a linear subspace of $\\Vspace$:\n$\\Aspace = \\Tspace(\\Aspace) + \\t$,\n$\\Tspace(\\Aspace)$ is the set of differences of elements of $\\Aspace$,\na linear subspace of $\\Vspace$.\nIf $\\t$ is any element of $\\Aspace$.\nthen projection onto $\\Aspace$\ncan be computed as a translation of an orthogonal projection onto $\\Tspace(\\Aspace)$:\n$\\Projection_{\\Aspace} (\\p) = \\t + \\Projection_{\\Tspace(\\Aspace)} (\\p - \\t)$.\nTypically, we pick $\\t$ to be the smallest element of $\\Aspace$.\nProjection onto an affine space is clearly an affine map.\n\nWe can represent the affine span of a set of $m+1$ vectors\nas a translation of a linear span:\n\\begin{equation}\n\\affine_span\\{ \\p_0 \\ldots \\p_{m} \\} = \\p_m + \\linear_span\\{\\v_0 \\ldots \\v_{m-1}\\}\n\\end{equation}\nwhere $\\v_i = \\p_i - \\p_m$,\nwhich allows us to compute the projection onto\n$\\affine_span\\{ \\p_0 \\ldots \\p_{m} \\}$\nagain using the QR decomposition\nof $\\Vmap = \\sum_{i=0}^{m-1} \\v_i \\otimes \\e_i$.\n\n%-----------------------------------------------------------------\n\n\\subsection{Inverses and pseudo-inverses}\n\\label{sec:Inverses-and-pseudo-inverses}\n\nA convenient definition for the {\\it true inverse}\nof a map $\\f(\\v):\\Vspace \\mapsto \\Wspace$ is\n$\\f^{-1}(\\w) = \\{ \\v : \\f(\\v) = \\w \\}$.\nThe usual definition of inverse treats $\\f^{-1}$\nas a map from $\\Wspace \\mapsto \\Vspace$,\nwhich is undefined where the value of the true\ninverse is not a set containing a single point.\n\nFor maps between inner product spaces,\nthe {\\it pseudo-inverse}, $f^{-}$, is a map $\\Wspace \\mapsto \\Vspace$\ndefined everywhere on $\\Wspace$.\nLet $\\hat{\\w}$ be an element of $\\Wspace$ closest to $\\w$\nsuch that $\\f^{-1}(\\w)$ is not empty.\nLet $\\hat{\\v}$ be a minimum norm element of $\\f^{-1}(\\hat{\\w})$.\nThen $\\f^{-}(\\w) = \\hat{\\v}$.\n\nIf $\\Lmap$ is linear, then it's not hard to see that\n$\\hat{\\w} = \\pi_{\\range(\\Lmap)} \\w$, the projection of $\\w$\non the range of $\\Lmap$\nand\n$\\hat{\\v}$ is the unique element of $\\kernel^{\\perp}(\\Lmap)$\nsuch that $\\Lmap(\\hat{\\v}) = \\hat{\\w}$.\n\nThe pseudo-inverse of a linear map can be characterized\nby the four Moore-Penrose conditions\n(see Golub and Van Loan\\cite[sec.~5.5.4]{golub-vanloan-1996}):\n\\begin{enumerate}\n\\item $\\Lmap \\Lmap^{-} \\Lmap = \\Lmap$\n\\item $\\Lmap^{-} \\Lmap \\Lmap^{-} = \\Lmap^{-}$\n\\item $\\left( \\Lmap \\Lmap^{-} \\right)^{\\dagger} = \\Lmap \\Lmap^{-}$\n\\item $\\left( \\Lmap^{-} \\Lmap \\right)^{\\dagger} = \\Lmap^{-} \\Lmap$\n\\end{enumerate}\n\nWhen the 'columns' of $\\Lmap$, $\\r_j^{\\Lmap}$\n($\\Lmap = \\sum_{j=0}^{n-1} ( \\Lmap_j^{\\Wspace} \\otimes \\e_j^{\\Vspace} )$)\nare linearly independent,\nthen a useful identity is:\n\\begin{equation}\n\\label{eq:full-rank-pseudo-inverse}\n\\Lmap^{-} = \\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1} \\Lmap^{\\dagger}\n\\end{equation}\n\nThe pseudoinverse can be computed\nusing standard matrix decompositions such as\nthe QR and SVD \\cite{golub-vanloan-1996}.\nThe pseudoinverse is an example of a linear transformation\nwhich should {\\em not} be represented by a matrix\n\\cite{mcdonald-1989b}.\n\nIf $\\Amap$ is affine,\nlet $\\Amap = \\Lmap + \\t$,\nwhere $\\Lmap$ is linear,\nand $\\t$ is an element of $\\range(\\Amap)$.\nThen $\\Amap^{-}(\\w) = \\Lmap^{-}( \\w - \\t )$.\n\n%-----------------------------------------------------------------\n\n\n", "meta": {"hexsha": "524f352446d6b91bcb9d4fae81dff818d4408b0f", "size": 10364, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fosm/maps.tex", "max_stars_repo_name": "palisades-lakes/les-elemens", "max_stars_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/old/fosm/maps.tex", "max_issues_repo_name": "palisades-lakes/les-elemens", "max_issues_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/old/fosm/maps.tex", "max_forks_repo_name": "palisades-lakes/les-elemens", "max_forks_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.1705426357, "max_line_length": 92, "alphanum_fraction": 0.6565032806, "num_tokens": 3458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7495432985262142}}
{"text": "\\lab{Line Search Algorithms}{Line Search Algorithms}\n\\label{lab:line_search}\n\\objective{Investigate various Line-Search algorithms for numerical optimization.}\n\n\\section*{Overview of Line Search Algorithms}\nImagine you are out hiking on a mountain, and you lose track of the trail. Thick fog\ngathers around, reducing visibility to just a couple of feet. You decide it is time\nto head back home, which is located in the valley located near the base of the mountain.\nHow can you find your way back with such limited visibility? The obvious way might be to\npick a direction that leads downhill, and follow that direction as far as you can, or\nuntil it starts leading upward again. Then you might choose another downhill direction,\nand take that as far as you can, repeating the process. By always choosing a downhill\ndirection, you hope to eventually make it back to the bottom of the valley, where you live.\n\nThis is the basic approach of line search algorithms for numerical optimization.\nSuppose we have a real-valued function $f$ that we wish to minimize. Our goal is to find the\npoint $x^*$ in the domain of $f$ such that $f(x^*)$ is the smallest value in the range of\n$f$. For some functions, we can use techniques from calculus to analytically obtain this\nminimizer. However, in practical applications, this is often impossible, especially when\nwe need a system that works for a wide class of functions. A line search algorithm starts with\nan initial guess at the minimizer, call it $x_0$, and iteratively produces a sequence of\npoints $x_1, x_2, x_3, \\ldots$ that hopefully converge to the minimizer $x^*$. The basic\niteration to move from $x_k$ to $x_{k+1}$ involves two steps: first, choosing a search direction $p_k$\nin which to proceed from the current point, and second, specifying a step size $\\alpha_k$ to travel\nin this direction. The next point is determined by the formula\n$$\nx_{k+1} = x_k + \\alpha_kp_k.\n$$\nThis procedure is called a line search because at each iteration, we are simply examining the\nfunction in a particular linear direction. The choice of the step size $\\alpha_k$ is often\nchosen by solving a one-dimensional optimization problem in the given direction. In this lab,\nwe will discuss approaches to choosing the step size and the search direction.\n\n%Line search procedures are an integral part of many nonlinear optimization techniques.\n%In some sense, they represent the simplest nontrivial case in general optimization, as\n%we only have to worry about one parameter. And yet far more sophisticated optimization\n%algorithms really crucially on the effectiveness and efficiency of line searches, since\n%higher-dimensional problems are often broken down into one-dimensional optimizations.\n%There are many different line search methods, and their effectiveness depends very much\n%on the nature of the optimization problem. Although the line search procedure is often\n%only a subroutine of the optimization algorithm at hand, understanding the basics of\n%the line search is necessary for understanding the robustness of the entire algorithm.\n%\\section*{Optimizing Functions on the Real Numbers}\n%\\subsection*{Derivative versus Derivative-Free Methods}\n%As you have seen in calculus classes, the derivative of a function gives information\n%about how the value of the function changes at each point, and can be used to determine\n%local optima. However, not all objective functions are differentiable, so we need other\n%techniques at our disposal. Line search methods may be broadly separated into two groups\n%based on whether they use the derivative of the objective function. We discuss two\n%simple examples to illustrate this distinction.\n%\n%\\subsection*{Golden Section Search}\n%This method is appropriate when minimizing a real-valued function on the reals over a\n%closed interval. The function must further satisfy the \\emph{unimodal} property, i.e.\n%it has just one local minimum, and is monotonic to the left and right of the minimum.\n%The goal, of course, is to find the\n%global minimum. We do this by making a sequence of guesses that we hope will converge\n%quickly to the minimum. Although we may not end up with the exact minimum, this method\n%will allow us to pin down the true minimum within an interval of any given width in a\n%finite number of steps.\n%\n%For the Golden Section Search, each step consists of evaluating the function at two\n%points within the current interval, comparing these values, and then reducing the size\n%of the interval for the next step. Let us consider a typical step in the algorithm. At\n%the outset, we have our function $f$ and a closed interval $[a, b]$ over which we seek\n%to minimize $f$. Choose two points $a'$ and $b'$ within the interval, and assume that\n%$a' < b'$. Now calculate $f(a')$ and $f(b')$, and assume that $f(a') \\geq f(b')$.\n%Because of the unimodal condition, we now know that the minimizer must be in the\n%interval $[a', b]$, for otherwise the function $f$ would have a local minimum in\n%both $[a, a']$ and $[a', b]$. In the next step, we repeat the process over the interval\n%$[a', b]$. If instead we had $f(b') \\geq f(a')$, then we choose the interval $[a, b']$\n%for the next step, and if the two values are equal, then it does not matter which\n%interval is chosen.\n%\n%We now have the basic description of the algorithm, but how do we choose the two test\n%points $a'$ and $b'$? There is in fact an optimal choice, which reduces the amount of\n%work we have to do. Given an interval $[a, b]$, choose $a'$ and $b'$ satisfying\n%\\begin{align*}\n%a' &= a + \\rho(b - a) \\\\\n%b' &= a + (1 - \\rho)(b - a),\n%\\end{align*}\n%where $\\rho = \\frac{1}{2}(3 - \\sqrt{5}) \\approx 0.382$. By choosing these particular\n%points, we need to only evaluate the function at one additional point in the next step.\n%To demonstrate this fact, the reader may verify that, within the interval $[a, b']$,\n%the point $a'$ already satisfies the equation\n%\\begin{equation*}\n%a' = a + (1 - \\rho)(b' - a),\n%\\end{equation*}\n%and so we need only evaluate the function at the point $c$ satisfying\n%\\begin{equation*}\n%c = a + \\rho(b' - a).\n%\\end{equation*}\n%(The constant $\\rho$ is not difficult to derive, and is related to the famous Golden Ratio, hence the name of this algorithm.)\n%\n%At each step, the interval is reduced by a factor of $1-\\rho$, which means that after\n%$n$ steps, we have pinned down the minimizer to within an interval approximately\n%$(0.61803)^n$ times the length of the original interval. Note that this convergence is\n%independent of the objective function.\n%\n%\\begin{problem}\n%Implement Golden Section Search as described above. Use this to minimize $e^x - 4x$\n%on the interval $\\lbrack 0, 3 \\rbrack$. How many steps do you need to take to get\n%within $.001$ of the true minimizer? Check that with the sentence preceding this\n%problem.\n%\\end{problem}\n\n\\subsection*{One-Dimensional Newton's Method}\nLet us first start out with a basic task: minimizing a function of one variable.\nWe will use a popular approach known as Newton's Method, which is a basic line search\nalgorithm that uses the derivatives of the function to select a direction and\nstep size.\n\nTo use this method, we need a real-valued function of a real variable that is twice\ndifferentiable. The idea is to approximate the function with a quadratic polynomial and\nthen solve the trivial problem of minimizing the polynomial. Doing so in an iterative\nmanner can lead us to the actual minimizer. Let $f$ be a function satisfying the\nappropriate conditions, and let us make an initial guess, $x_0$. The relevant quadratic\napproximation to $f$ is\n\\begin{equation*}\nq(x) = f(x_0) + f'(x_0)(x-x_0) + \\frac{1}{2}f''(x_0)(x-x_0)^2,\n\\end{equation*}\nor just the second-degree Taylor polynomial for $f$ centered at $x_0$. The minimum\nfor this quadratic function is easily found by solving $q'(x) = 0$, and we take the\nobtained $x$-value as our new approximation. The formula for the $(n+1)$-th\napproximation, which the reader can verify, is\n\\begin{equation*}\nx_{n+1} = x_n - \\frac{f'(x_n)}{f''(x_n)}.\n\\end{equation*}\nIn the one dimensional case, there are only two search directions: to the right ($+$)\nor to the left ($-$). Newton's method chooses the search direction \n$\\text{sign}(-f'(x_n)/f''(x_n))$ and the step size $|f'(x_n)/f''(x_n)|$.\n\nAs is typical with optimization algorithms, Newton's Method generates a sequence of\npoints or successive approximations to the minimizer. However, the convergence\nproperties of this sequence depend heavily on the initial guess $x_0$ and the function\n$f$. Roughly speaking, if $x_0$ is sufficiently close to the actual minimizer, and if\n$f$ is well-approximated by parabolas, then one can expect the sequence to converge\nquickly. However, there are cases when the sequence converges slowly or not at all.\nSee Figure \\ref{linesearch:newton}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{newton.pdf}\n\\caption{The results of Newton's Method using two\ndifferent initial guess. The global minimizer was\ncorrectly found with initial guess of 1. However,\nan initial guess of 4 led to only a local minimum.}\n\\label{linesearch:newton}\n\\end{figure}\n\n\\begin{problem}\nImplement Newton's Method as described using the following function declaration. \n\\begin{lstlisting}\ndef newton1d(f, df, ddf, x, niter=10):\n    '''\n    Perform Newton's method to minimize a function from R to R.\n    \n    Parameters\n    ----------\n    f : callable function object \n        The objective function (twice differentiable)\n    df : callable function object \n        The first derivative\n    ddf : callable function object\n        The second derivative\n    x : float\n        The initial guess\n    niter : integer\n        The number of iterations\n        \n    Returns\n    ------\n        min : float\n            The approximated minimizer\n    '''\n    pass\n\\end{lstlisting}\n\nUse this function to minimize $x^2 + \\sin(5x)$ with an initial guess of $x_0 = 0$.\nNow try other initial guesses farther away from the true minimizer, and note when the\nmethod fails to obtain the correct answer.\n\\end{problem}\n\n\\section*{General Line Search Methods}\n\\subsection*{Step Size Calculation}\nWe now examine Line Search methods in more generality. Given a differentiable function\n$f : \\mathbb{R}^n \\rightarrow \\mathbb{R}$ that we wish to minimize, and assuming that\nwe already have a current point $x_k$ and direction $p_k$ in which to search, how do we\nchoose our step size $\\alpha_k$? If our step size is too small, we will not make good progress\ntoward the minimizer, and convergence will be slow. If the step size is too large, however,\nwe may overshoot and produce points that are far away from the solution.\nA common approach to pick an appropriate step size involves the \\emph{Wolfe conditions}:\n\n\\begin{align*}\n&f(x_k + \\alpha_kp_k) \\leq f(x_k) + c_1\\alpha_k\\nabla f_k^Tp_k, &(0 < c_1 < 1),\n\\\\ &\\nabla f(x_k + \\alpha_kp_k)^Tp_k \\geq c_2\\nabla f_k^Tp_k, &(c_1 < c_2 < 1).\n\\end{align*}\n\nHere, we use the shorthand notation $\\nabla f_k$ to\nmean the gradient of $f$ evaluated at the point $x_k$. The search direction $p_k$ is\noften required to satisfy $p_k^T \\nabla f_k < 0$, in which case it is called a\n\\emph{descent direction}, since the function is guaranteed to decrease in\nthis direction. Generally speaking, choosing a step size $\\alpha_k$ satisfying these conditions\nensures that we achieve sufficient decrease in the function and also that we do not\nterminate the search at a point of steep decrease (since then we could achieve even\nbetter results by choosing a slightly larger step size). The first condition is known\nas the \\emph{Armijo} condition.\n\nFinding such a step size satisfying these conditions is not always an easy task, however.\nOne simple approach, known as \\emph{backtracking}, starts with an initial step size\n$\\alpha$, and repeatedly scales it down until the Armijo condition is satisfied.\nThat is, choose $\\alpha >0, \\rho \\in (0, 1), c\\in (0, 1)$, and while\n$$\nf(x_k + \\alpha p_k) > f(x_k) + c\\alpha\\nabla f_k^Tp_k,\n$$\nre-scale $\\alpha := \\rho\\alpha$. Once the loop terminates, set $\\alpha_k = \\alpha$. Note that the value\n$\\nabla f_k^Tp_k$ remains fixed for the duration of the backtracking algorithm, and hence need only\nbe calculated once at the beginning.\n%The second of the two conditions can be replaced by\n%\\begin{equation*}\n%| \\nabla f(x_k + \\alpha_kp_k)^Tp_k| \\leq c_2 | \\nabla f_k^Tp_k|,\n%\\end{equation*}\n%and in this case we have the \\emph{strong Wolfe conditions}.\n%\n%The \\emph{Goldstein conditions} for choosing step size:\n%\\begin{equation*}\n%f(x_k) + (1-c)\\alpha_k\\nabla f_k^Tp_k \\leq f(x_k + \\alpha_kp_k) \\leq f(x_k) +\n%c\\alpha_k\\nabla f_k^Tp_k,\n%\\end{equation*}\n%where $0 < c < 0.5$. Similar to the Wolfe conditions, the Goldstein conditions ensure\n%sufficient decrease in the function and prevent the step size from being too small. In\n%the area of quasi-Newton optimization methods, however, the Wolfe conditions are\n%preferred.\n\n\\begin{problem}\nImplement this backtracking algorithm using the following function declaration. \n\\begin{lstlisting}\ndef backtracking(f, slope, x, p, a=1, rho=.9, c=10e-4):\n    '''\n    Perform a backtracking line search to satisfy the Armijo condition.\n    \n    Parameters\n    ----------\n    f : callable function object\n        The objective function\n    slope : float \n        The value of grad(f)^T p\n    x : ndarray of shape (n,) \n        The current iterate\n    p : ndarray of shape (n,) \n        The current search direction\n    a : float \n        The intial step length (set to 1 in Newton and quasi-Newton methods)\n    rho : float \n        A number in (0,1)\n    c : float \n        A number in (0,1)\n    \n    Returns\n    -------\n        alpha : float\n            The computed step size satisfying the Armijo condition.\n    '''\n    pass\n\\end{lstlisting}\n\\end{problem}\n\n\\subsection*{Choosing a Search Direction}\nThere are many different ways to choose a search direction $p_k$. As noted earlier, it is usually\na requirement to choose a descent direction. We will compare two methods, both using derivative\ninformation about the function.\n\n\\emph{Gradient Descent.} Recall that the gradient of a function at a given point gives the direction\nin which the function is increasing fastest. Thus, the negative of the gradient points in the direction\nof fastest decrease. In the method of Gradient Descent, we choose our search direction to be\nthis direction of steepest descent, that is,\n$$\np_k = -\\nabla f_k.\n$$\nThis is a very natural choice, since we seem to be approaching the minimum value as fast as possible.\nHowever, depending on the nature of the objective function, convergence may be slow. See Figure\n\\ref{linesearch:comparison}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{comparison.pdf}\n\\caption{Paths generated by Gradient Descent (green) and Newton's Method (blue).\nNote that the Newton path takes a more direct route toward the minimizer (located\nat the origin).\n}\n\\label{linesearch:comparison}\n\\end{figure}\n\n\\emph{Newton's Method.} We now generalize the one-dimensional Newton's method presented above.\nWe use both the gradient and the Hessian matrix (which gives information on the curvature of the\nfunction at a given point) to choose a search direction. This is more computationally intensive,\nbut it leads to very fast convergence in many cases. See Figure\n\\ref{linesearch:comparison}. Our search direction is\n$$\np_k = -\\nabla^2 f_k^{-1} \\nabla f_k,\n$$\nwhere $\\nabla^2 f_k^{-1}$ is the inverse of the Hessian matrix of $f$ at the point $x_k$.\nIn other words, $p_k$ is the solution to the linear system\n$$\n\\nabla^2 f_k p_k = -\\nabla f_k.\n$$\n\n\\begin{problem}\nImplement the Gradient Descent algorithm and Newton's Method using the following function declarations.\nIn each function, you should call your backtracking function with\nvalues $\\alpha = 1, \\rho = .9$, and $c = 10^{-4}$. The \\li{scipy.linalg} module\nmay be useful when computing the search direction in Newton's Method.\n\\begin{lstlisting}\ndef gradientDescent(f, df, x, niter=10):\n    '''\n    Minimize a function using gradient descent.\n    \n    Parameters\n    ----------\n    f : callable function object \n        A differentiable real-valued function\n    df : callable function object \n        The gradient of the function\n    x : ndarray of shape (n,) \n        The initial point\n    niter : integer \n        The number of iterations to run.\n    \n    Returns\n    -------\n        pts: list of ndarrays \n            The sequence of points generated\n    '''\n    pass\n\ndef newtonsMethod(f, df, ddf, x, niter=10):\n    '''\n    Minimize a function using Newton's method.\n    \n    Parameters\n    ----------\n    f : callable function object\n        Real-valued, twice-differentiable function\n    df : callable function object\n        The gradient of the function\n    ddf : callable function object \n        The Hessian of the function\n    x : ndarray of shape (n,) \n        The initial point\n    niter : integer \n        The number of iterations\n        \n    Returns\n    -------\n    pts : list of ndarrays\n        The sequence of points generated\n    '''\n    pass\n\\end{lstlisting}\n\n\\end{problem}\n\n\\subsection*{Line Search in SciPy}\nThe SciPy module \\li{scipy.optimize} contains implementations of various optimization algorithms,\nincluding several line search methods. In particular, the module provides a useful routine for\ncalculating a step size satisfying the Wolfe Conditions described above, which is more robust\nand efficient than our simple backtracking approach. We recommend its use for the remainder of\nthis lab. The function is called \\li{line_search}, and accepts several arguments. We can typically\nleave the keyword arguments at their default values, but we do need to pass in the objective\nfunction, its gradient, the current point, and the search direction. The following code gives\nan example of its usage, using the objective function $f(x, y) = x^2+4y^2$.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy.optimize import line_search\n>>>\n>>> def objective(x):\n>>>     return x[0]**2 + 4*x[1]**2\n>>>\n>>> def grad(x):\n>>>     return 2*x*np.array([1, 4])\n>>>\n>>> x = np.array([1., 3.]) #current point\n>>> p = -grad(x)           #current search direction\n>>> a = line_search(objective, grad, x, p)[0]\n>>> print a\n0.125649913345\n\\end{lstlisting}\nNote that the function returns a tuple of values, the first of which is the step size. We have illustrated\nthe very basic use of this function. See the documentation for further uses.\n\n\\section*{Non-linear Least Squares Problems}\nWe now discuss a very important class of problems known as Least Squares problems. These\nare unconstrained optimization problems that seek to minimize an objective function of the form\n$$\nf(x) = \\frac{1}{2}\\displaystyle\\sum_{j=1}^m r_j^2(x),\n$$\nwhere each $r_i : \\mathbb{R}^n \\rightarrow \\mathbb{R}$ is smooth, and $m \\geq n$. Such problems\narise in many scientific fields, including economics, physics, and statistics. Linear Least\nSquares problems form an important subclass, and can be solved directly without the need for an\niterative method. At present we will focus on the non-linear case, which can be solved with a\nline search method.\n\nTo motivate the problem further, suppose you are given a set of data points, and you have some kind of model for the data.\nYou need to choose particular values for the parameters in your model, and you wish to do so in a way that ``best fits\"\nthe observed data. What do we mean by ``best fit\"? We need some way to measure the error between our model and the data set,\nand then minimize this error. The best fit will correspond to the choice of parameters that minimize the error function.\n\nMore formally, suppose we are given the data points $(t_1, y_1), (t_2, y_2), \\ldots, (t_m, y_m)$, where $y_i \\in \\mathbb{R}$\nand $t_i \\in \\mathbb{R}^n$ for $i = 1, \\ldots, m$. Let $\\phi(x, t)$ be our model for this data set, where $x$ is\na vector of parameters of the model, and $t \\in \\mathbb{R}^n$. We can measure the error at the $i$-th data point by the value\n$$r_i(x) := \\phi(x, t_i) - y_i,$$ and by summing the squares of these errors, we obtain our non-linear least squares objective\nfunction:\n$$\nf(x) = \\frac{1}{2} \\displaystyle \\sum_{j=1}^m  r_j^2(x).\n$$\n\nThe individual functions $r_i$ that measure the error between the model and the data point are known as \\emph{residuals},\nand we can aggregate these functions into a \\emph{residual vector}\n$$\nr(x) := (r_1(x), r_2(x), \\ldots, r_m(x))^T.\n$$\nThe Jacobian of $r(x)$ can be expressed in terms of the gradients of each $r_i$ as follows:\n$$\nJ(x) = \\begin{bmatrix} \\nabla r_1(x)^T \\\\ \\nabla r_2(x)^T \\\\ \\vdots \\\\ \\nabla r_m(x)^T \\end{bmatrix}\n$$\nYou can further verify that\n\\begin{align*}\n\\nabla f(x) &= J(x)^T r(x), \\\\\n\\nabla^2 f(x) &= J(x)^TJ(x) + \\displaystyle \\sum_{j=1}^m r_j(x) \\nabla^2r_j(x).\n\\end{align*}\nThat second term in the formula for $\\nabla^2 f$ involves second derivatives and can be problematic to compute. Often in practice,\nthis term is small, either because the residuals themselves are small, or are nearly affine in a neighborhood of the solution and\nhence the second derivatives are small.\nThe simplest method for solving the nonlinear least squares problem, known as the \\emph{Gauss-Newton Method}, exploits this\nobservation, simply ignoring the second term and making the approximation\n$$\n\\nabla^2 f(x) \\approx J(x)^TJ(x).\n$$\nThe method then proceeds in a manner similar to Newton's Method. In particular, at the $k$-th iteration, we choose a search\ndirection $p_k$ that solves the linear system\n$$\nJ_k^TJ_kp_k = -J_k^Tr_k.\n$$\n\nFor convenience, we summarize these steps in Algorithm \\ref{alg:guassnewton}.\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Gauss-Newton}{}\n    \\State \\textrm{Choose initial parameter vector } $x_0$\n    \\State $k \\gets 0$\n    \\While{$J_k^Tr_k \\neq 0$}\n        \\State \\textrm{solve } $J_k^TJ_kp_k = -J_k^Tr_k$\n        \\State \\textrm{choose step size } $\\alpha_k$ \\textrm{ satisfying Wolfe Conditions.}\n        \\State $x_{k+1} \\gets x_k + \\alpha_kp_k$\n        \\State $k \\gets k+1$\n    \\EndWhile\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Gauss-Newton Method}\n\\label{alg:guassnewton}\n\\end{algorithm}\n\n\\begin{problem}\nImplement the Gauss-Newton method using the following function declaration.\n\\begin{lstlisting}\ndef gaussNewton(f, df, jac, r, x, niter=10):\n    '''\n    Solve a nonlinear least squares problem with Gauss-Newton method.\n    \n    Parameters\n    ----------\n    f : callable function object\n        The objective function\n    df : callable function object\n        The gradient of f\n    jac : callable function object\n        The jacobian of residual vector\n    r : callable function object \n        The residual vector\n    x : ndarray of shape (n,) \n        The initial point\n    niter : integer \n        The number of iterations\n    \n    Returns\n    -------\n    min : ndarray of shape (n,)\n        The minimizer\n    '''\n    pass\n\\end{lstlisting}\n\nFeel free to use SciPy functions to solve linear systems and calculate step sizes in your algorithm.\n\\end{problem}\n\nLet us work through an example of a nonlinear least squares problem. Suppose we have data points\ngenerated from a sine function and slightly perturbed by gaussian noise. In Python we can generate such\ndata as follows:\n\\begin{lstlisting}\n>>> t = np.arange(10)\n>>> y = 3*np.sin(0.5*t)+ 0.5*np.random.randn(10)\n\\end{lstlisting}\nNow we write Python functions for our model, the residual vector, the Jacobian, the objective function,\nand the gradient. The calculations for all of these are straight forward.\n\\begin{lstlisting}\n>>> def model(x, t):\n>>>     return x[0]*np.sin(x[1]*t)\n>>> def residual(x):\n>>>     return model(x, t) - y\n>>> def jac(x):\n>>>     ans = np.empty((10,2))\n>>>     ans[:,0] = np.sin(x[1]*t)\n>>>     ans[:,1] = x[0]*t*np.cos(x[1]*t)\n>>>     return ans\n>>> def objective(x):\n>>>     return .5*(residual(x)**2).sum()\n>>> def grad(x):\n>>>     return jac(x).T.dot(residual(x))\n\\end{lstlisting}\nBy inspecting our data, we might make an initial guess for the parameters $x_0 = (2.5, 0.6)$.\nWe are now ready to use our \\li{gaussNewton} function to find the least squares solution.\n\\begin{lstlisting}\n>>> x0 = np.array([2.5,.6])\n>>> x = gaussNewton(objective, grad, jac, residual, x0, niter=10)\n\\end{lstlisting}\nWe can plot everything together to compare our fitted model with the data and the original sine\ncurve from which the data were generated.\n\\begin{lstlisting}\ndom = np.linspace(0,10,100)\nplt.plot(t, y, '*')\nplt.plot(dom, 3*np.sin(.5*dom), '--')\nplt.plot(dom, x[0]*np.sin(x[1]*dom))\nplt.show()\n\\end{lstlisting}\nThe results are shown in Figure \\ref{linesearch:gaussNewton}. As you can see, after just 10\niterations, we have found a very good fit.\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{gaussNewton.pdf}\n\\caption{Perturbed data (stars) generated from a sine curve (dashed line),\ntogether with the fitted sine curve (solid line).\n}\n\\label{linesearch:gaussNewton}\n\\end{figure}\n\n\\subsection*{Non-linear Least Squares in Python}\nThe module \\li{scipy.optimize} also has a method to solve non-linear least squares problem, and it\nis quite convenient. The function is called \\li{leastsq}, and in its most basic use, you only need\nto pass in the residual function and starting point as arguments. In the example above, we simply\nneed to execute the following code:\n\\begin{lstlisting}\n>>> from scipy.optimize import leastsq\n>>> x2 = leastsq(residual, x0)[0]\n\\end{lstlisting}\nThis should give us the same answer, but much faster.\n\\begin{problem}\nWe have census data giving the population of the United States every ten years since 1790.\nFor convenience, we have entered the data in Python below, so that you may simply copy and\npaste.\n\\begin{lstlisting}\n>>> #Start with the first 8 decades of data\n>>> years1 = np.arange(8)\n>>> pop1 = np.array([3.929, 5.308, 7.240, 9.638, 12.866,\n>>>                 17.069, 23.192, 31.443])\n>>>\n>>> #Now consider the first 16 decades\n>>> years2 = np.arange(16)\n>>> pop2 = np.array([3.929, 5.308, 7.240, 9.638, 12.866,\n>>>                 17.069, 23.192, 31.443, 38.558, 50.156,\n>>>                 62.948, 75.996, 91.972, 105.711, 122.775,\n>>>                 131.669])\n\\end{lstlisting}\nConsider just the first 8 decades of population data. By plotting the data and having\nan inclination that population growth tends to be exponential, it is reasonable to\nhypothesize an exponential model for the population, that is,\n$$\n\\phi(x_1,x_2,x_3,t) = x_1\\exp(x_2(t+x_3)).\n$$\nBy inspection, find a reasonable\ninitial guess for the parameters $(x_1, x_2, x_3)$ (i.e. $(150, .4, 2.5)$).\nWrite a function for this model in Python, along with the corresponding residual vector,\nand fit the model using the \\li{leastsq} function.  Plot the data against the fitted curve,\nto see how close you are.\n\nNow consider all 16 decades of data. If you plot your curve from above with this more complete\ndata, you will see that the model is no longer a good fit. Instead, the data suggest\na logistic model, which also arises from a differential equations treatment of population growth.\nThus, your new model is\n$$\n\\phi(x_1,x_2,x_3,t) = \\frac{x_1}{1+\\exp(-x_2(t+x_3))}.\n$$\nBy inspection, find a reasonable\ninitial guess for the parameters $(x_1, x_2, x_3)$ (i.e. $(150, .4, -15)$).\nAgain, write Python functions for the model and the corresponding residual vector,\nand fit the model. Plot the data against the fitted curve. It should be a good fit.\n\\end{problem} ", "meta": {"hexsha": "c2e2041dd5c601d2da798fe731d821fb686c91b2", "size": 27425, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/LineSearch/LineSearch.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Labs/LineSearch/LineSearch.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/LineSearch/LineSearch.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 46.0151006711, "max_line_length": 130, "alphanum_fraction": 0.7261987238, "num_tokens": 7301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.7495432948608686}}
{"text": "\\chapter*{RSA Algorithm comments}\\label{ch:rsa-algorithm-comments}\n\n\n\\section*{One way functions}\\label{sec:one-way-functions}\nOne way function -- is a function that is easy to compute on every input, but\nhard to invert given the image of a random input.\nFor instance, the function\n\\begin{equation*}\n    f(m) = m^e \\bmod N \\equiv C\n\\end{equation*}\nwhere $e, N$ are public constants is one-awy function,\nbecause it is easy to compute $C$ given $m$, however it is hard to compute $m$ given $C$.\n\n\n\\section*{Euler's totient theorem}\\label{sec:euler's-totient-theorem}\nGiven a number $N$ and its prime factorization $p_1^{e_1}\\cdot p_2^{e_2} \\cdots p_k^{e_k}$, then Euler's totient function\n$\\phi(N)$ is defined as\n\n\\[\n    \\phi(N) = (p_1^{e_1} - p_1^{e_1 - 1}) \\cdot (p_2^{e_2} - p_2^{e_2 - 1}) \\cdots (p_k^{e_k} - p_k^{e_k - 1})\n\\]\n\nIn particular, for positive number $M$ such that its factorization is $p1 \\cdot p2$, the $\\phi(M)$ is\n\n\\[\n    \\phi(M) = (p_1 -1) \\cdot (p_2 - 1)\n\\]\n\nEuler's theorem relates the modular division and exponent as follows, given number $m$, then\n\\[\n    m^{\\phi(N)} = 1 \\bmod N\n\\]\nIt means that reminder of division $m^{\\phi(N)}$ by $N$ is always 1.\nBy the equality $1^K = 1$\n\\[\n    M^{K \\cdot \\phi(N)} = 1 \\bmod N\n\\]\nIf we multiply both parts by $M$, we get\n\\[\n    M \\cdot M^{K \\cdot \\phi(N)} = M^{K \\cdot \\phi(N) + 1} = M \\bmod N\n\\]\n\n\n%! suppress = TooLargeSection\n\n\n\\section*{RSA Encryption algorithm}\\label{sec:rsa-encryption-algorithm}\nThe RSA algorithm is named after Ron Rivest, Adi Shamir and Len Adleman, who invented it in 1977 [\\cite{rivest1978method}].\nThe basic technique was first discovered in 1973 by Clifford Cocks [\\cite{cocks1973note}] of CESG (part of the British GCHQ)\nbut this was a secret until 1997.\nThe patent taken out by RSA Labs has expired.\n\nHistorically, the process of encryption is considered to be symmetric one.\nThat means that prior the communication, the sides conclude on the common key to be used in encryption.\nThis process is similar to the first sharing keys and only after that the locked chest with the message.\nSuch approach is highly cost since it requires to share the defined keys between each actor if the number of actors\nis greater than 2.\nMuch more simpler is to think about secured communication channel that in terms of asymmetric encryption.\nThe real life example would be if Alice shares with all actors an opened lock having key.\nSo that Bob receives an opened lock, writes letter to Alice, puts letter to the chest, locks this chest with received\nfrom Alice lock.\nThis way, only Alice will be able to open the chest and to read the letter.\nThis is an idea of the asymmetric encryption.\nHowever, such a simple from first glance idea requires complex number theory approach.\nA concept of opened lock may be interpreted in terms of one-way functions.\nOne way function -- is a function that is easy to compute on every input, but hard to invert given the image of\na random input.\nThus, it is much simpler to close the lock without key, but very difficult to open lock trying the combinations\nof the key.\nFor instance, the function\n\\begin{equation*}\n    f(m) = m^e \\bmod N = C\n\\end{equation*}\nwhere $e, N$ are public constants is one-awy function,\nbecause it is easy to compute $C$ given $m$, however it is hard to compute $m$ given $C$.\nSo, assume that Alice defines two positive integer constants $e, N$ and sends it to Bob.\nBob encrypts the secret message $m$ using $f(m)$\n\\[\n    f(m) = m^e \\bmod N = C\n\\]\nThen Bob sends encrypted message $C$ to the Alice.\nGiven $C$ Alice must fetch the Bob's message $m$.\nIn order to decrypt $C$, Alice has to compute\n\\[\n    C^d \\bmod N = m^{ed} \\bmod N \\equiv m,\n\\]\nwhere $e$ for encryption and $d$ for decryption.\nNow the problem is to define such $d$ that it is hard to the listener to fetch it.\nIn order to define the secret $d$, Alice chooses two enough big prime numbers: $P, \\; Q$, let's say around 150 digits\nboth.\nThen Alice multiplies these two prime numbers in order to get $N$\n\\[\n    N = P \\cdot Q\n\\]\nThe $N$ is around 300 digits.\nNow Alice can share $N$ with anyone, since it takes decades to find its prime factorization by the fundamental problem\nof prime factorization.\nNext, it is very important to know such a function, which depends on the knowledge of factorization of $N$.\nSuch function is an Euler's totient function.\nGiven a number $N$ and its prime factorization $p_1^{e_1}\\cdot p_2^{e_2} \\cdots p_k^{e_k}$, the Euler's totient function\n$\\phi(N)$ is defined as\n\\[\n    \\phi(N) = (p_1^{e_1} - p_1^{e_1 - 1}) \\cdot (p_2^{e_2} - p_2^{e_2 - 1}) \\cdots (p_k^{e_k} - p_k^{e_k - 1})\n\\]\nIn particular, for positive number $M$ such that its factorization is $p1 \\cdot p2$, the $\\phi(M)$ is\n\\[\n    \\phi(M) = (p_1 -1) \\cdot (p_2 - 1)\n\\]\nEuler's theorem relates the modular division and exponent as follows, given number $m$, then\n\\[\n    m^{\\phi(N)} = 1 \\bmod N\n\\]\nIt means that reminder of division $m^{\\phi(N)}$ by $N$ is always 1.\nBy the equality $1^K = 1$\n\\[\n    M^{K \\cdot \\phi(N)} = 1 \\bmod N\n\\]\nIf we multiply both parts by $M$, we get\n\\[\n    M \\cdot M^{K \\cdot \\phi(N)} = M^{K \\cdot \\phi(N) + 1} = M \\bmod N\n\\]\nIt follows that Alice is able to define the secret $d$ as follows\n\\begin{gather*}\n    e \\cdot d = K \\cdot \\phi(N) + 1\\\\\n    d = \\frac{K \\cdot \\phi(N) + 1}{e}\\\\\n\\end{gather*}\nThe following image demonstrates the concept of RSA approach\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=1\\textwidth]{Pictures/12_RSA_encryption_concept_diagram}\n    ~\\caption{RSA algorithm concept diagram. Source: [\\cite{mango2021figma}].}\\label{fig:figure8}\n\\end{figure}\nTo summarize, the process by the steps is as follows\n\\begin{itemize}\n    \\item Alice defines the large secret prime numbers $P, \\; Q$.\n    \\item Alice computes $N = P \\cdot Q$ and $\\phi = (P-1)(Q-1)$\n    \\item Alice chooses an integer $e$, $1<e< \\phi$ such that $\\gcd(e, \\phi) = 1$.\n    \\item Alice computes secret exponent $d$, $1<d< \\phi$ such that $ed \\equiv 1 \\bmod \\phi$.\n    \\item Alice shares public key $(N,e)$ with Bob and keeps private key $(d, p, q)$ is secret.\n    \\item Bob defines the message $m$, encrypts it as $C = m^{e} \\bmod N$.\n    \\item Bob sends $C$ to Alice.\n    \\item Alice decrypts $C$ using her secret $d$, so she gets $m$\n    \\[\n        m = C^d \\bmod N\n    \\]\n\\end{itemize}\nSecurity of the RSA approach is based on the complexity of fundamental problem of prime factorization,\nwhich takes decades to solve having enough large number.", "meta": {"hexsha": "426346c7aff59db401d498dcf987eb562da3cdeb", "size": 6468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/Appendices/annex-rsa-algorithm.tex", "max_stars_repo_name": "MangoInstantMessenger/MangoMessengerBachelorThesis", "max_stars_repo_head_hexsha": "61e607a24bab5081aa3cb5fbdf67a4d38e2905c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-03-05T12:04:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T15:18:44.000Z", "max_issues_repo_path": "src/Appendices/annex-rsa-algorithm.tex", "max_issues_repo_name": "MangoInstantMessenger/MangoMessengerBachelorThesis", "max_issues_repo_head_hexsha": "61e607a24bab5081aa3cb5fbdf67a4d38e2905c7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Appendices/annex-rsa-algorithm.tex", "max_forks_repo_name": "MangoInstantMessenger/MangoMessengerBachelorThesis", "max_forks_repo_head_hexsha": "61e607a24bab5081aa3cb5fbdf67a4d38e2905c7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.7027027027, "max_line_length": 124, "alphanum_fraction": 0.6983611626, "num_tokens": 1974, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248140158417, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7495171860088785}}
{"text": "\n\\subsection{IID}\n\n\\subsubsection{Identically distributed}\n\n\\(x\\) is identically distributed to \\(y\\) if:\n\n\\(\\forall i (\\exists x_i \\rightarrow P(x_i)=P(y_i))\\)\n\n\\subsubsection{Covariance matrix of IID variables}\n\nFor IID varaibles, the covariance  matrix is:\n\n\\(\\Sigma = \\sigma^2 I\\)\n\n", "meta": {"hexsha": "75d1db3217b22cbff9f979fdf32139d7f87d159c", "size": 286, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/iid/01-01-IIDIID.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/iid/01-01-IIDIID.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/iid/01-01-IIDIID.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.875, "max_line_length": 53, "alphanum_fraction": 0.7097902098, "num_tokens": 81, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947148047777, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7494809275279599}}
{"text": "% !TEX encoding = UTF-8 Unicode\n% !TEX spellcheck = en_US\n% !TEX root = ../../../ICMA2020.tex\n\n\\subsection{Optimal Excitation}\n\\label{subsec:OptimalExcitation}\n\nFor precise and robust parameter estimation an optimized trajectory needs to be generated. In this paper an optimized \\textsc{Fourier} series trajectory is used as a baseline for comparison. It is optimized by minimizing the condition number $\\kappa(\\boldsymbol{C})$ of the design matrix $\\boldsymbol{C}$ \\cite{Bona.2005,Kostic.2004,Olsen.2002,Swevers.1997}.\nThe \\textsc{Fourier} series for each joint $j$ is given by:\n\\begin{equation} \n\\label{eq:fourier_series}\nq_j(t) = \\alpha_{0,j} + \\sum \\limits_{k=1}^{n_\\mathrm{h}} \\left\\{ \\frac{\\alpha_{k,j}}{k \\omega_\\mathrm{b}} \\sin(k \\omega_\\mathrm{b} t) + \\frac{\\beta_{k,j}}{k \\omega_\\mathrm{b}} \\cos(k \\omega_\\mathrm{b} t) \\right\\}.\n\\end{equation}\nBased on the suggestions of \\cite{Swevers.1997,Bona.2005}, the order is set to $n_\\mathrm{h}=5$ and the base frequency is set to $\\omega_\\mathrm{b}=2\\pi \\cdot 0.1\\,\\mathrm{Hz}$. The amplitudes $\\alpha_{k,j}$ and $\\beta_{k,j}$ are varied by a genetic algorithm under consideration of the given boundary conditions, see below.\n% For the optimization a genetic algorithm from the \\textit{Global Optimisation Toolbox} in \\textsc{Matlab} was used. \nTo take into account the different magnitudes and units of the individual parameters, $\\boldsymbol{C}$ is normalized during the optimization according to \\cite{Sun.2008}.\n\n%\\textbf{(Aufgrund der begrenzten Seitenzahl würde ich hier bei dem Verweis auf die Quelle bleiben.)}", "meta": {"hexsha": "2e2dcbc7bcea3b7d30d426d0994e1e1e3e944683", "size": 1571, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/Chapters/Theoretical_Background/Optimal_Excitation/Optimal_Excitation.tex", "max_stars_repo_name": "SchapplM/robotics-paper_icma2020", "max_stars_repo_head_hexsha": "f81c6599ec7a9341e6a467a4ff9b31091aa50e75", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/Chapters/Theoretical_Background/Optimal_Excitation/Optimal_Excitation.tex", "max_issues_repo_name": "SchapplM/robotics-paper_icma2020", "max_issues_repo_head_hexsha": "f81c6599ec7a9341e6a467a4ff9b31091aa50e75", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/Chapters/Theoretical_Background/Optimal_Excitation/Optimal_Excitation.tex", "max_forks_repo_name": "SchapplM/robotics-paper_icma2020", "max_forks_repo_head_hexsha": "f81c6599ec7a9341e6a467a4ff9b31091aa50e75", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 87.2777777778, "max_line_length": 358, "alphanum_fraction": 0.745385105, "num_tokens": 468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218434359676, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7494001319502703}}
{"text": "\\chapter{Fundamental Properties of $q$-series and Theta functions}\n\n\\section{$q$-analogue of the Binomial Theorem}\n\nThe $q$-analogue of the binomial theorem is a generalization involving the parameter $q$ that returns the binomial theorem is the limit as $q \\to 1$ and we replace $a$ by $q^a$.\n\\begin{theorem}\nFor  $|q|, |z| < 1$\n\\begin{equation}\n    \\sum_{n = 0}^{\\infty} \\frac{(a)_n}{(q)_n}z^n = \\frac{(az)_\\infty}{(z)_\\infty}.\n\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\nNote that the product on the RHS of (2.1) converges uniformly on compact subsets of $|z| < 1$ and so represents an analytic function on $|z| < 1$. Thus we may write\n\\begin{equation}\n    F(z) = \\frac{(az)_\\infty}{(z)_\\infty} = \\sum_{n = 0}^\\infty A_n z^n\n\\end{equation}\nFrom the product representation in (2.2), we can readily verify that\n\\begin{equation}\n    (1-z)F(z) = (1-az)F(qz).\n\\end{equation}\nEquating coefficients of $z^n$ on both sides of (2.3), we get\n\\begin{align*}\n    A_n - A_{n-1} = q^n A_n - aq^{n-1}A_{n-1}\n\\end{align*}\nor\n\\begin{equation}\n    A_n = \\frac{1-aq^{n-1}}{1-q^n} A_{n-1}\n\\end{equation}\nUsing $A_0 = 1$ in (2.2), we deduce that\n\\begin{equation}\n    A_n = \\frac{(a)_n}{(q)_n}\n\\end{equation}\nUsing (2.5) in (2.2), we complete the proof for (2.1)\n\\end{proof}\n\n\\subsection{Euler's Corollaries}\n\\begin{equation}\n    \\sum_{n = 0}^{\\infty} \\frac{z^n}{(q)_n} = \\frac{1}{(z)_\\infty}\n\\end{equation}\n\\begin{equation}\n    \\sum_{n = 0}^{\\infty} \\frac{(-z)^nq^{n(n-1)/2}}{(q)_n} = (z)_\\infty\n\\end{equation}\n\nEuler discovered these corollaries by application of (2.1)\n\\newpage\n\\section{Jacobi Triple Product Identity}\nWe present Jacobi's Triple Product Identity, which is immensely useful in the study of partitions in simplification of $q$-series products.\n\\begin{theorem}\nFor $z \\neq 0$ and $|q| < 1$\n\\begin{equation}\n    \\sum_{n = -\\infty}^{\\infty} z^n q^{n^2} = (-zq;q^2)_\\infty (-q/z;q^2)_\\infty (q^2;q^2)_\\infty\n\\end{equation}\n\\end{theorem}\n\\begin{proof}\n    In (2.7), replace $q$ by $q^2$ and $z$ by $-zq$ to get\n\\begin{equation}\n\\begin{split}\n      (-zq;q^2)_\\infty &= \\sum_{n = 0}^{\\infty} \\frac{z^n q^{n^2}}{(q^2;q^2)_n} = \\frac{1}{(q^2;q^2)}\\sum_{n = 0}^{\\infty} z^n q^{n^2}(q^{2n+2};q^2)_\\infty \\\\\n    &= \\frac{1}{(q^2;q^2)}\\sum_{n-\\infty}^{\\infty} z^n q^{n^2}(q^{2n+2};q^2)_\\infty,\n\\end{split}\n\\end{equation}\nsince $(q^{2n+2};q^2)_\\infty = 0$ when $n$ is a negative integer.\n\nNow apply (2.7), again with replacing $q$ with $q^2$ and $z$ with $q^{2n+2}$. Thus from (2.9),\n\\begin{align*}\n(-zq;q^2)_\\infty &= \\frac{1}{(q^2;q^2)_\\infty}\\sum_{n = -\\infty}^{\\infty} z^nq^{n^2} \\sum_{r=0}^\\infty \\frac{(-1)^rq^{(2n+2)r+r^2-r}}{(q^2;q^2)_r}\\\\\n&= \\frac{1}{((q^2;q^2)_\\infty} \\sum_{r = 0}^{\\infty} \\frac{(-1)^rz^{-r}q^r}{(q^2;q^2)_r} \\sum_{n= -\\infty}^\\infty z^{n+r}q^{(n+r)^2}\n\\\\&= \\frac{1}{(q^2;q^2)_\\infty} \\sum_{r = 0}^{\\infty} \\frac{(-q/z)^r}{(q^2;q^2)_r} \\sum_{n= -\\infty}^\\infty z^mq^{m^2}\n\\\\&= \\frac{1}{(q^2;q^2)_\\infty(-q/z;q^2)_\\infty} \\sum_{n= -\\infty}^\\infty z^mq^{m^2}\n\\end{align*}\n\\newpage\nby (2.6) with $z$ replaced by $-q/z$ and $q$ replaced by $q^2$, and therefore the restriction $|q/z| < 1$. Rearranging the final equation completes the proof of (2.8) for $|q/z| < 1$. However by analytic continuation, it hold's for all complex $z \\neq 0$ completing the proof.\n\\end{proof}\n\n\\subsection{Corollory: Euler's Pentagonal Number Theorem}\nEuler's Pentagonal Number Theorem occurs as a special case of Jacobi's Triple Product Identity, which we state due to its combinatorial importance.\n\\begin{equation}\n    \\sum_{n = -\\infty}^{\\infty} (-1)^nq^{n(3n-1)/2} = \\sum_{n = -\\infty}^{\\infty} (-1)^nq^{n(3n+1)/2} = (q;q)_\\infty\n\\end{equation}\n", "meta": {"hexsha": "48e276c3e096cfdfdce3439774531cc697ac804a", "size": 3637, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter2.tex", "max_stars_repo_name": "Cheran-Senthil/BTP-Project", "max_stars_repo_head_hexsha": "93092556037234df1e2590f47c718a317cd40b96", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-29T04:25:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-29T04:25:43.000Z", "max_issues_repo_path": "chapter2.tex", "max_issues_repo_name": "Cheran-Senthil/BTP-Project", "max_issues_repo_head_hexsha": "93092556037234df1e2590f47c718a317cd40b96", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter2.tex", "max_forks_repo_name": "Cheran-Senthil/BTP-Project", "max_forks_repo_head_hexsha": "93092556037234df1e2590f47c718a317cd40b96", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-02-10T04:54:36.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-10T04:54:36.000Z", "avg_line_length": 44.9012345679, "max_line_length": 276, "alphanum_fraction": 0.6288149574, "num_tokens": 1567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517044, "lm_q2_score": 0.8774767986961403, "lm_q1q2_score": 0.7492886288258697}}
{"text": "\n% !TEX root = /Users/hzd88688126com/Desktop/USFD_Academic-_Report_LaTeX-Template/main.tex\n\\section{Adaptive Step Size}\n\\subsection{GASS}\nBased on the previous analysis, the step size should be large for fast convergence and getting small to reduce steady state errors. The gradient adaptive step-size (GASS) is implemented with time-varying step $\\mu(n)$. The MA(1) process $x(n)=0.9\\eta(n-1)+\\eta(n)$ with white noise $\\eta \\sim \\mathcal{N}(0, 0.5)$ is simulated. For the GASS, the gradient step will be controlled by a constant $\\rho$ and $\\psi(n)$. In addition, there are three algorithms which will update the $\\psi(n)$. As introduced in guidelines, the Benveniste applies a time-varying adaptive filter, which provides low pass filtering of the instantaneous gradient \\cite{mandic2009complex}. Thus, the Benveniste's algorithm is robust to the noise and should be more accurate. The Ang \\& Farhang's algorithm replaces the low-pass filter term with a constant $\\alpha$. And the Matthews \\& Xie's algorithm simplifies the the algorithm by Ang \\& Farhang by setting $\\alpha$ to zero, which only use the instantaneous gradient to update. Hence, the performance for this algorithm should be relative poor.\n\\begin{figure}[htbp]\n     \\centering{}\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/22/22a1.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/22/22a2.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/22/22a3.eps}\n     \\end{subfigure}\n      ~\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/22/22a4.eps}\n     \\end{subfigure}\n        \\caption{GASS estimated weights error and squared error}\n        \\label{fig:2_2_a}\n\\end{figure}\\\\\nFig.\\ref{fig:2_2_a} depicts the weight error and learning curves of three algorithms and standard LMS. When setting the initial $\\mu$ =0.01, the standard LMS with fixed step has the slowest convergence speed and large steady state error. The Benveniste's algorithm converges before 100 samples, whereas the Ang \\& Farhang's converges at 200 samples and Matthews is after 250 samples. However, even if the Matthews's algorithm perform worst among GASS algorithm, it is still slightly better than the standard LMS. When increasing the initial step $\\mu=0.1$, all of algorithms converge rapidly with squared error lower than -300$dB$. However, the GASS algorithm requires more computational complexity than the standard LMS.\n\\subsection{NLMS}\nGiven a the update weight $\\mathbf{w}(n+1)=\\mathbf{w}(n)+\\mu e_p(n)\\mathbf{x}(n)$, the relationship between posteriori error $e_p(n)$ and priori error $e(n)$can be derived by \n\\begin{align}\ne_p(n)&=d(n)-\\mathbf{x}^T(n)\\mathbf{w}(n+1)\\notag\\\\\n\t  &=d(n)-\\mathbf{x}^T(n)\\mathbf{w}(n)-\\mu e_p(n)\\mathbf{x}^T(n)\\mathbf{x}(n) \\notag\\\\\n\t  &=e(n)-\\mu e_p(n)\\|\\mathbf{x}(n)\\|^2\\notag\\\\\n\t  &=\\frac{e(n)}{1+\\mu \\|\\mathbf{x}(n)\\|^2} \\label{eq:ep}\n\\end{align}\nSubstituting Eq.\\ref{eq:ep} into update equation,\n\\begin{align}\n\t\\mathbf{w}(n+1)&=\\mathbf{w}(n)+\\mu e_p(n)\\mathbf{x}(n)\\notag\\\\\n\t\t\t\t   &=\\mathbf{w}(n)+ \\frac{\\mu}{1+\\mu \\|\\mathbf{x}(n)\\|^2} e(n)\\mathbf{x}(n)\\notag\\\\\n\t\t\t\t   &=\\mathbf{w}(n)+ \\frac{1}{\\frac{1}{\\mu}+\\|\\mathbf{x}(n)\\|^2} e(n)\\mathbf{x}(n)\\notag\\\\\n\t\t\t\t   &=\\mathbf{w}(n)+ \\frac{\\beta}{\\epsilon+\\mathbf{x}^T(n)\\mathbf{x}(n) } e(n)\\mathbf{x}(n)\\label{eq:nllms}\n\\end{align}\nThus, the update equation based on a posteriori error is equivalent to the NLMS algorithm, where $\\epsilon=\\frac{1}{\\mu}$ and $\\beta=1$.\n\\subsection{GNGD vs GASS}\nBased on the NLMS algorithm, the generalized normalized gradient descent (GNGD) applies a time-varying $\\epsilon(n)$. Compared with the Benveniste's algorithm, the GNGD algorithm converges rapidly of weight estimation approximately at 40 samples when the initial step $\\mu=0.1$. The squared error\nfor the GNGD is smaller as well. However, when increasing the initial step $\\mu=1$, the Benveniste's algorithm converges faster than the GNGD. Thus, the performance of the GASS algorithm is significantly affected by initial step $\\mu$, while it is not a problem for the GNGD algorithm.\n\\begin{figure}[htbp]\n     \\centering\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/22/22c1.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/22/22c2.eps}\n     \\end{subfigure}\n     ~   \n      \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/22/22c3.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/22/22c4.eps}\n     \\end{subfigure}\n        \\caption{GAGN and Benveniste's GASS estimated weights and squared error}\n        \\label{fig:2_2_c}\n\\end{figure}\\\\\nAs to the complexity of these two algorithms, the computation complexity is caused by the matrix product in step update process. The Benveniste's algorithm, as shown below,\n\\begin{equation}\n\t\\mathbf{\\psi}(n)=[\\mathbf I\\overbrace{-\\underbrace{\\mu(n-1)\\mathbf x(n-1)\\mathbf {x}^T(n-1)}_{N^2}]\\mathbf{\\psi}(n-1)+}^{2N}\\underbrace{e(n-1)\\mathbf x(n-1)}_{N}\n\\end{equation}\nhas $O(N^2)$ multiplications, if the model order is $N$. The reason is that the Benveniste's algorithm applies matrix outer production which introduces a matrix result. Therefore, the computational complexity of the Benveniste grows quadratically. For the GNGD, as shown below,\n\\begin{equation}\n\t\\epsilon(n+1)=\\epsilon{n}-\\rho\\mu\\frac{e(n)e(n-1)\\overbrace{\\mathbf x^T(n)\\mathbf x(n-1)}^{N}}{(\\epsilon(n-1)+\\underbrace{\\|\\mathbf x(n-1)\\|^2}_{N})^2}\n\\end{equation}\nIt only has inner product of $\\mathbf x(n)$, resulting in a numerical value. Hence, the computational complexity is reduced over order $M$ which is $O(N)$.\n\n\n\n\n\n\n\n", "meta": {"hexsha": "4638261c7018e9c97d67a448000878cee5d6cb35", "size": 6063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/sections/Part2/22.tex", "max_stars_repo_name": "zdhank/Adaptive-Signal-Processing", "max_stars_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-05T10:27:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-19T08:55:10.000Z", "max_issues_repo_path": "Report/sections/Part2/22.tex", "max_issues_repo_name": "zdhank/Adaptive-Signal-Processing", "max_issues_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/sections/Part2/22.tex", "max_forks_repo_name": "zdhank/Adaptive-Signal-Processing", "max_forks_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.3666666667, "max_line_length": 1069, "alphanum_fraction": 0.6996536368, "num_tokens": 1849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.749288614882723}}
{"text": "%!TEX root = problems.tex\n\n%\\printanswers\n\n\\noindent\nThe following problem comes from Douglas Hofstadter's book \\emph{Gödel, Escher, Bach}~\\cite{hofstadter79}.\nTake the time to try to solve this problem yourself.\nThe problem concerns strings of characters.\nThe only characters allowed/available are M, U and I.\n\n\\subsubsection*{Question}\nYou start with the string MI and the goal is to use the four rules below to convert it into the string MU.\nIn the rules, the letter x denotes any string.\nYou can use the rules any number of times and in any order, just so long as you get to MU~\\cite{muwikipedia}.\n\n\n\\begin{center}\n\\begin{tabular}{rlll}\n\n & Rule & Example & Explanation  \\\\\n\\midrule\n1 &\txI to xIU & MI\tto\tMIU & Append U to the end of a string ending in I. \\\\\n2 &\tMx to Mxx & MIU\tto\tMIUIU & Double the string after the M. \\\\\n3 &\txIIIy to xUy & MUIIIU\tto\tMUUU & Replace any III with a U. \\\\\n4 &\txUUy to xy & MUUU\tto\tMU & Remove any UU. \\\\\n\\bottomrule\n\\end{tabular}\n\\end{center}", "meta": {"hexsha": "cc5724c3b1d52fecf4665ac83480e5073e200495", "size": 979, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content.tex", "max_stars_repo_name": "theory-of-algorithms/problem-mu", "max_stars_repo_head_hexsha": "5f55e7472365f36a4ece8bb2c94be5fcdb75d8dd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "content.tex", "max_issues_repo_name": "theory-of-algorithms/problem-mu", "max_issues_repo_head_hexsha": "5f55e7472365f36a4ece8bb2c94be5fcdb75d8dd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "content.tex", "max_forks_repo_name": "theory-of-algorithms/problem-mu", "max_forks_repo_head_hexsha": "5f55e7472365f36a4ece8bb2c94be5fcdb75d8dd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.9642857143, "max_line_length": 109, "alphanum_fraction": 0.7272727273, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.8774767810736693, "lm_q1q2_score": 0.7492886072534023}}
{"text": "\\subsection{Group Theory}\r\n{\\bf Isomorphism Theorems:}  (1) If $\\varphi: G \\rightarrow H$ is a homomorphism,\r\n$G/ker(\\varphi) \\cong Im(\\varphi)$, \r\n(2)  If\r\n$G \\triangleright H$ and $G \\triangleright N$ and $N \\subseteq H \\subseteq G$\r\nthen $G/H \\cong (G/N)/(H/N)$, \r\n(3) If $G=HN$, $G \\triangleright N$ then\r\n$HN/N \\cong H/(H \\cap N)$.\\\\\r\n\\\\\r\n{\\bf Derived series:} $G^{[0]}=G$, $G^{[i+1]}= [G^{i]}, G^{[i]}]$.  $G$ is solvable iff\r\nderived series terminates at ${1}$.  Subnormal Series: \r\n$G= G_0 \\rhd G_1 \\rhd \\ldots \\rhd G_k =H$, if this happens, we say\r\n$G \\rhd \\rhd H$.  {\\bf Normal series:} Subnormal series where $G \\rhd G_i, \\forall i$.\r\n{\\bf Chief series:} Normal series with no repeated terms and no normal subgroup properly\r\nlying between two series elements.  \r\n{\\bf Zassenhaus Butterfly Lemma:}  If\r\n$A \\triangleleft A^{*}$ and $B \\triangleleft B^{*}$ then\r\n$A(A^{*} \\cap B) \\triangleleft A(A^{*} \\cap B^{*})$ and\r\n$B(B^{*} \\cap A) \\triangleleft B(B^{*} \\cap A^{*})$; further,\r\n${\\frac {A(A^{*} \\cap B^{*})} {A(A^{*} \\cap B) }} \\cong\r\n{\\frac {B(B^{*} \\cap A^{*})} {B(B^{*} \\cap A) }}$.\r\nLet $G$ be a finite group.  \r\nThe following are equivalent: (1) $G$ is solvable, (2) $G$ has a normal series \r\nterminating at the identity whose factor groups are abelian,\r\n(3) $G$ has a subnormal series with cyclic quotients.\\\\\r\n\\\\\r\n{\\bf Schreier:} Two normal series for $G$ have equivalent refinements.\r\nTwo compositions series for $G$ are equivalent.\r\nProof:  By induction on length ($l$) of shortest such\r\nseries.  If $l=1$, $G$ is simple.\r\nSuppose $G=G_0 \\ge G_1 \\ge \\ldots \\ge G_r = 1$ and\r\n$H=H_0 \\ge H_1 \\ge \\ldots \\ge H_t = 1$ and assume $l=r>t$ and that the theorem\r\nis true for all series of length less than $l$. If $H_1=G_1$ then we are done by induction\r\non the shortened series.  Assume $G_1 \\ne H_1$, $H_1 \\lhd G, G_1 \\lhd G$ then\r\n$G_1H_1 = G$ and $G/G_1 \\cong H_1/K, K= G_1 \\cap H_1$. Consider the two series\r\n$G_1 \\ge G_2 \\ldots \\ge G_r = 1$ and\r\n$G_1 \\ge K \\ge K_1 \\ldots \\ge K_t = 1$.  \r\nBy induction, $r-1=t+1$ and they are equivalent.\r\nThus,\r\n$H_1 \\ge H_2 \\ldots \\ge H_s = 1$ and\r\n$H_1 \\ge K \\ge K_1 \\ldots \\ge K_{r-2} = 1$ so $r=s$ and they\r\nare equivalent.\\\\\r\n\\\\\r\n$\\phi$ is a {\\bf normal endomorphism} iff\r\n$\\phi(a^{-1}xa)=\r\na^{-1} \\phi(x)a$, $\\forall x,a \\in G$.\r\nLemma 1: If $G$ satisfies ACC or DCC then $G$ is the direct product of indecomposable groups.\r\nLemma 2: If $G$ satisfies ACC (resp. DCC) on normal subgroups \r\nand $f$ is a normal endomorphism\r\nof $G$, then $f$ is an automorphism iff $f$ is an epimorphism (resp automorphism).\r\n{\\bf Lemma 3 (Fitting):}\r\nLet $G$ satisfy both chain conditions.  If $\\phi$ is a\r\nnormal endomorphism of $G$ then $G= Ker(f^n) \\times Im(f^n)$, some $n \\ge 1$.\r\nIf $G$ is an indecomposable group satisfying ACC and DCC on normal subgroups\r\nand if $f$ is a normal endomorphism then $f$ is nilpotent or an automorphism.\r\n{\\bf Krull-Schmidt:}  If $G$ has both chain conditions on normal subgroups and\r\n$G= H_1 \\times \\ldots \\times H_s = K_1 \\times \\ldots \\times K_t$ are\r\ntwo decompositions into indecomposable factors then $s=t$ and, after\r\nreindexing, $H_i \\cong K_i$ and for each $r<t$, $G= G_1 \\times G_2 \\times \\ldots\r\n\\times G_r \\times H_{r+1} \\times H_t$. Proof:  Let $P(0)$ be the statement\r\n$G= G_1 \\times G_2 \\times \\ldots \\times G_s$ and for $1 \\le r \\le min(s,t)$\r\nlet $P(i)$ be the statement\r\n$G= G_1 \\times G_2 \\times \\ldots \\times G_r \\times H_{r+1} \\times \\ldots H_t$.\r\n$P(0)$ is true by assumption, assume $P(r-1)$.  Let $\\pi_i$ (resp $\\pi_i'$ be the \r\ncanonical epimorphisms from\r\n$G_1 \\times G_2 \\times \\ldots \\times G_s$ (resp.\r\n$G_1 \\times G_2 \\times \\ldots \\times G_r \\times H_{r+1} \\times H_t$ and $\\lambda_i$\r\n(resp $\\lambda_i'$) be the inclusion maps, \r\n$\\varphi_i= \\lambda_i \\pi_i$\r\nand\r\n$\\phi_i= \\lambda_i' \\pi_i'$.  $\\varphi_r \\phi_i= 0_{|G}$ for $i<r$ and\r\n$\\varphi_1 (1_{|G})= \\varphi_r \\phi_1 + \\ldots + \\varphi_r \\phi_t=\r\n\\varphi_r \\phi_r + \\ldots + \\varphi_r \\phi_t$ so $(\\varphi_r \\phi_j)_{|G}$ is\r\nan automorphism of $G_r$.  $\\varphi_j \\phi_r$ must be an automorphism of $H_j$ and\r\n$\\phi_j:G_r \\rightarrow H_j$ is and isomorphism and so is $\\varphi_r: H_j \\rightarrow G_r$\r\nreindexing we have the first half of $P(r)$.  Let \r\n$g=g_1 g_2 \\ldots g_{r-1} h_r h_{r+1} \\ldots h_t$ define \r\n$\\theta(g)=g_1 g_2 \\ldots g_{r-1} \\varphi(h_r) h_{r+1} \\ldots h_t$.  \r\n$G=Im(\\theta)=G^*= G_1 \\times G_2 \\times \\ldots \\times G_r \\times H_{r+1} \\times H_t$ \r\nwhich completes the argument.\\\\\r\n\\\\\r\n{\\bf Lower Central Series:} $L_1(G)=G$, $L_{n+1}(G)= [L_n(G),G]$.  $G$ is \r\n{\\bf nilpotent} if\r\n$L_n(G)=1$ for some $n$.  Note $L_n(G)/L_{n+1}(G) \\subseteq Z(G/L_{n+1}(G))$.\r\n{\\bf Upper Central series:}\r\n$Z_0(G)=1$; Let $H^*= H/Z_n(G)$, define $Z_{n+1}(G)^*= Z(G/Z_n(G))$.\r\nUpper and Lower central series have same length.\r\nFinite nilpotent groups are direct products of\r\ntheir Sylow subgroups.\\\\\r\n\\\\\r\n$G$ is an {\\bf extension} of $K$ by $Q$ if $G \\triangleright K$ and $G/K \\cong Q$.\r\nIf $1 \\rightarrow N \\rightarrow_{i} G \\rightarrow_{\\varphi} Q \\rightarrow 1$, the following\r\nare equivalent\r\n(1) $\\exists Q^* \\subseteq G: Q^* \\rightarrow Q$ and\r\n(2) $\\exists s:Q \\rightarrow G$ such that $\\varphi \\cdot s = id$.\r\n(3) $G$ is a semi-direct product of $N$ by $Q$ written $N \\ltimes Q$; in this\r\ncase, we say $G$ is a split extension of $N$ by $Q$.\\\\\r\n\\\\\r\n$G$ is {\\bf complete} if it is centerless and every automorphism is inner.\r\nin which case $G \\cong Aut(G)$. $S_n$ is complete if $n \\ne 2,3$.  Proof:\r\nLet $T_k$ be the set of $k$ disjoint transpostions so $x \\in T_k \\rightarrow\r\nx^2=1$; note that if $\\theta \\in Aut(S_n), \\theta(T_1)= T_k$ for some $k$. Also\r\nobserve that $\\theta$ preserves transpositions iff $\\theta \\in Inn(S_n)$.\r\nNow we can show \r\n$|T_1|= {\\frac {n(n-1)} {2}}$ and\r\n$|T_k|= {\\frac {(n-2k+1)!} {(n-2k)! k! 2^k}}$.  Comparing the two $|T_1| = |T_k|$\r\nis possible only if $k=2 ,3$ and in fact, only if $k=3$.   If\r\n$\\theta \\in Out(S_6)$ and $\\tau$ is a transposition, $\\theta(\\tau)$ must\r\nbe a product of three transpositions and such an automorphism exists.\r\nIf $G$ is a non-abelian simple group, then $Aut(G)$ is complete.  If\r\n$K \\lhd G$ and $K$ is complete, $G= K \\times Q$.  $Hol(K) \\subset S_K$\r\nis $<K^l, Aut(K)>$, $K^l \\lhd Hol(K)$, $Hol(K)/K^l \\cong Aut(K)$ and\r\n$C_{Hol(K)}(K^l)= K^r$.  If $K$ is a direct factor whenever $K$ is a normal\r\nsubgroup then $K$ is complete.\\\\\r\n\\\\\r\nSuppose $G$ is an extension of $N$ by $H$ and let $\\phi: H \\rightarrow G/N$.  Pick\r\n$s:G \\rightarrow H$ such that $s(1)=1$ and $\\phi(h) = N s(h)$, then \r\n$\\exists f: H \\times H \\rightarrow N: s(h_1 h_2)= f(h_1, h_2) s(h_1 h_2)$\r\nand $f(h_1, h_2) f(h_1 h_2, h_3)= f(h_2, h_3)^{s(h_1)} f(h_1 , h_2 h_3)$.  Note\r\nthat $\\theta_h: n \\mapsto s(h) n s(h)^{-1}$ is in $Aut(N)$ and\r\n$\\theta_{h_1}(\\theta_{h_2}(n))= \\theta_{h_1 h_2}(n)^{f(h_1, h_2)}$.\r\nGiven $N,H$ with $\\theta_h \\in Aut(N)$ and $\\theta_1 = 1$ and a map\r\n$f: H \\times H \\rightarrow N$ with $f(1,h)=f(h,1)=1$ and\r\n$f(h_1, h_2) f(h_1 h_2 , h_3)= \\theta_{h_1}(f(h_2, h_3)) f(h_1, h_2 h_3)$, \r\nsuppose $f$ is compatible in the sense that \r\n$\\theta_{h_1}(\\theta_{h_2}(n))= \\theta_{h_1h_2}(n)^{f(h_1, h_2)}$ then the\r\noperation $(n_1, h_1) \\cdot (n_2, h_2) = (n_1 \\theta_{h_1}(n_2) f(h_1, h_2), h_1 h_2)$\r\ndefines a group $G$ which is an extension of $N$ by $H$.\\\\\r\n\\\\\r\nSuppose $T$ is a subset consisting of a representative of each coset\r\nof an $G/K$ which is called a {\\bf transversal}. \r\nIf $\\pi: G \\rightarrow Q$ is a surjective homomorphism with kernel\r\n$K$, $l: Q \\rightarrow G$ is a {\\bf lifting} if $\\pi(l(x))=x$.\r\n$G$ realizes $(Q, K, \\theta )$ with $K'=1$, $\\theta:Q \\rightarrow Aut(K)$ and\r\n$l:Q \\rightarrow G$ if $G$ is an extension of\r\n$K$ by $Q$ and every transversal $l: Q \\rightarrow G$ satisfies $xa = \\theta_x(a)\r\n= l(x) +a-l(x)$.  Note additive notation for non-abelian operation.\r\nIf $\\pi: Q \\rightarrow G$ is a surjective homomorphism with\r\nkernel $K$ and $l:Q \\rightarrow G$ is a transversal with $l(1)=0$ then\r\n$f: Q \\times Q \\rightarrow K$ defined by $l(x)+l(y)= f(x,y) + l(xy)$ is\r\ncalled a {\\bf factor set}.\r\n{\\bf Cocycle identity:} $xf(y,z)-f(xy,z)+f(x,yz)-f(x,y)=0$.  Note\r\n$xf(y,z)= l(x)f(y,z)l(x)^{-1}$.\r\nGiven ``data,'' $(Q, K, \\theta )$, $f:Q \\times Q \\rightarrow K$ is a factor set\r\niff it satisfies the cocycle identity and $f(1,y)=0=f(x,1)$.\r\nProof: Let $G= \\{(a, x): a \\in K,\r\nx \\in Q \\}$.  With $(a,x) + (b, y)= (a +xb+f(x,y), xy)$.\r\nThis is a group if the conditions hold.\\\\\r\n\\\\\r\nLet $G$ realize $(Q, K, \\theta )$ and $l$ and $l'$ be transversals with\r\n$l(1)=l'(1)=0$ giving rise to factor sets $f$ and $f'$ then there is an\r\n$h:Q \\rightarrow K$ with $h(1)=0$ such that \r\n$f'(x,y)-f(x,y)= xh(y)-h(xy)+h(x), \\forall x,h \\in Q$ and $g$ is called a\r\n{\\bf coboundary}.  The set of all coboundaries is \r\n${\\bf B^2 (Q,K,\\theta)}$.\r\n${\\bf Z^2 (Q, K, \\theta)}$ is the set of all {\\bf factor sets}.\r\n${\\bf H^2 (Q, K, \\theta) \\cong Z^2 (Q, K, \\theta) / B^2 (Q, K, \\theta)}$.\r\nTwo extensions are equivalent if the difference of\r\ntheir two factor sets is in $B^2 (Q, K, \\theta)$.\r\nThere is a bijection from $H^2(Q,K,\\theta)$ and the set of equivalence classes\r\nof extensions realizing $(Q, K, \\theta)$ taking $0$ to the class of the\r\nsemidirect product.  See proof of Schur-Zassenhaus.\\\\\r\n\\\\\r\n$G$, an extension of $K$ by $Q$, is a {\\bf central extension} if $K<Z(G)$.  Functorially,\r\na central extension $G$ is a pair $(H, \\pi)$ satisfying\r\n$\\pi: H \\rightarrow G, ker(\\pi) \\subseteq Z(H)$.  A cyclic extension $G$ of $N$ is\r\none where $G/N$ is cyclic.  Solvable groups are built from cyclic extensions.\r\n$\\alpha: (H_1 , \\pi_1) \\rightarrow (H_2, \\pi_2)$ is a morphism in this category. \r\nIf $(\\tilde{G}, \\tilde{\\pi})$ is universal if \r\n$\\forall (H, \\sigma), \\exists ! \\alpha : (\\tilde{G}, \\tilde{\\pi}) \\rightarrow\r\n(H, \\sigma)$.\r\n$G$ possesses a universal central extension iff $G$ is perfect.\r\nIf $(\\tilde{G}, \\pi)$ is a universal central extension then $ker(\\pi)$ is the\r\nSchur multiplier.\r\n{\\bf Homological version:} If $G>N$\r\nand $H>K$ are normal subgroups isomorphic under $\\phi$, the pullback\r\nis $(g, h)$ where $gN= \\phi(hK)$.\r\n$(Q, K, \\theta)$ is trivial iff every extension realizing $(Q, K, \\theta)$\r\nis a central extension.  There's a bijection between $H^2 (Q, K, \\theta)$\r\nand central extensions. {\\bf Schur multiplier:}\r\n$M(Q)=H^2 (Q, {\\mathbb C}^{\\times})$ ($\\theta$ is trivial).\r\nHere $f(1,y)=f(x,1)=1$, $f(x,y) f(xy,z)^{-1} f(x,yz) f(x,y)^{-1}=1$,\r\n$g: Q \\times Q \\rightarrow {\\mathbb C}^{\\times}$ is a coboundary\r\niff $\\exists h: Q \\rightarrow {\\mathbb C}^{\\times}$ with $h(1)=1$ such that\r\n$g(x,y)= h(y)(h(xy))^{-1}h(x)$.  Assume $G$ is perfect then a central extension\r\n$(E, \\phi)$ of $G$ is universal iff (a) $E$ is perfect and (b) all \r\ncentral extensions of $E$ are trivial. In that case,\r\n$1 \\rightarrow R \\rightarrow F \\rightarrow G \\rightarrow 1$, $F$, free and\r\n$E= [F,F][F,R] \\rightarrow [F,F]/R=G$.\\\\\r\n\\\\\r\n{\\bf Central Product:} $G= <G_i>$, $[G_i , G_j ]=1$ for $i \\ne j$.  Equivalently,\r\n$\\rho: (x_1, x_2, \\ldots , x_n) \\mapsto x_1 x_2 \\ldots x_n$ is a surjective homomorphism\r\nfrom $(G_1 \\times G_2 \\times \\ldots \\times G_n)$ to $G$ with $\\rho(D_i) = G_i$ where\r\n$\\pi_i (G_1, \\ldots , G_n)= D_i$ and $ker(\\rho) \\cap D_i = 1$, $ker(\\rho) \\subseteq Z(G)$.\r\nLet $Z<Z(A)) \\cap Z(B)$, $A \\times B / Z$ is a central product.\r\nBoth $D_8$ and\r\n$Q_8$ are central products of $Z_2$ by $Z_2 \\times Z_2$.\r\nLet $G_i, 1 \\le i \\le n$ be a family of groups with $Z(g_1)=Z(G_i)$ and\r\n$Aut_{G_i}(Z(G_i))=Aut(Z(G_i))$.  Then up to isomorphism there is a unique\r\ncentral product with $Z(G_1)=Z(G_i)$.\\\\\r\n\\\\\r\n{\\bf Wreath Product:} $G^*= G^{X}$ - maps from $X$ to $G$.  $fg(x)= f(x) g(x)$.\r\nLet $H$ act on $X$: $f^h(x)= f(xh^{-1})$.  Let $\\phi$ be the natural action of\r\n$H$ induced on $G^{|H|}$, then $G \\wr H = H \\rtimes_{\\phi} G^*$. If $G_x =\r\n\\{f: f(y)= 1 \\; if \\; x \\ne y \\}$.  $G^* = \\prod_X G_x$.\r\nPut $g_x (y)= g (y)$ if $x=y$, 1 otherwise.  Note that\r\n${g_x}^h= g_{xh}$.\r\nIf $H$ is finite and $G/K=H$, $G$ can be embedded in the\r\nregular wreath product $K \\wr H$:\r\n{\\bf Universal Embedding Theorem:}  Let $G \\rhd N$ and $K \\equiv G/N$, \r\n$\\exists \\phi : G \\rightarrow N \\; \\wr \\; K$ such that $\\phi$ maps $N$\r\nonto $im(\\phi) \\cap \\bigotimes_i N$.\r\n$exp(G)= min \\{e: x^e = 1, \\forall x \\in G \\}$.\r\nIf $Q$ is finite then $M(Q)$ is a finite abelian group and\r\n$exp(M(Q)) \\mid |Q|$.\\\\\r\n\\\\\r\n{\\bf Representations:}\r\nIf $V$ is a ${\\mathbb C}G$-module, $g$ induces a linear map\r\n$\\rho(g): V \\rightarrow V$;\r\nif ${\\cal B}$ is a basis of $V$, the matrix for the matrix representing the linear\r\nmap $\\rho(g)$ is denoted by $[g]_{\\cal B}$.\r\nTwo such \\emph {representations} are equivalent if they are\r\nrelated by a similarity.\r\nLet $V$ be a ${\\mathbb C}G$-module with basis ${\\cal B}$ and $\\rho: g \\mapsto [g]_{\\cal B}$ then\r\n(i) if ${\\cal B}'$ is a basis of $V$ and $\\phi(g)= [g]_{{\\cal B}'}$ is another representation,\r\n$\\rho$ is equivalent to $\\phi$; and, (ii) if $\\sigma$ is any equivalent representation to\r\n$\\rho$, $\\exists {\\cal B}': \\sigma(g)= [g]_{{\\cal B}'}$.\r\nLet $V, W$ be a ${\\mathbb C}G$-modules; $V \\cong W$ iff there are bases \r\n${\\cal B}_1$, ${\\cal B}_2$ of $V, W$ respectively such that\r\n$\\forall g \\in G: [g]_{{\\cal B}_1}= [g]_{{\\cal B}_2}$.\r\nLet $V, W$ be a ${\\mathbb C}G$-modules, $V \\cong W$ iff there are bases \r\n${\\cal B}_1$, ${\\cal B}_2$ of $V, W$ respectively such that\r\n$[g_{{\\cal B}_1}]$ and $[g_{{\\cal B}_2}]$ are equivalent.  \r\n{\\bf Maschke:}  If $V$ is a ${\\mathbb C}G$-module and\r\n$U$ is a ${\\mathbb C}G$-submodule, there is a \r\n${\\mathbb C}G$-submodule, $W$, of $V$ such that $V= U \\oplus W$.\r\n{\\bf Schur:}  If $V, W$ are irreducible ${\\mathbb C}G$-modules and $\\theta: V \\rightarrow W$ is a \r\n${\\mathbb C}G$ homomorphism then either $\\theta=0$ or $\\theta$ is an isomorphism.\r\nIf $V, W$ are ${\\mathbb C}G$-modules and $\\theta: V \\rightarrow W$ is a ${\\mathbb C}G$ module\r\nhomomorphism, $\\exists U$, a ${\\mathbb C}G$-submodule of $V$ such that $V= ker(\\theta) \\oplus U$.\r\n$Hom_{{\\mathbb C}G}(V,W)$ is a vector space over ${\\mathbb C}$.  \r\nIf $V,W$ are irreducible ${\\mathbb C}G$ modules,\r\n$dim_{{\\mathbb C}}(Hom_{{\\mathbb C}G}(V, W))$ is $1$ if $V \\cong W$ and $0$ otherwise.\r\n$dim_{{\\mathbb C}}(Hom_{{\\mathbb C}G}(V, W)) \\ne 0$ if $V$ and $W$ have a common composition\r\nfactor.\r\nLet $V$ be an ${\\mathbb C}G$ module, \r\n$V= U_1 \\oplus U_2 \\oplus \\ldots \\oplus U_r$ with $U_i$ irreducible; (a) if\r\n$W$ is an irreducible ${\\mathbb C} G$ module then \r\n$dim_{{\\mathbb C}}(Hom_{{\\mathbb C}G}(V, W))= dim_{{\\mathbb C}}(Hom_{{\\mathbb C}G}(W, V))$ is\r\nthe number of $U_i \\cong W$;\r\n(b) each $U_i$ is a composition factor in the Jordan Holder series.\r\n${\\mathbb C}G= U_1 \\oplus U_2 \\oplus \\ldots \\oplus U_r$ with $U_i$ irreducible;\r\nif $G$ is finite, there are finitely many irreducible ${\\mathbb C}G$ modules.\r\n$dim(Hom_{{\\mathbb C}G}(V_1 \\oplus \\ldots \\oplus U_r, W_1 \\oplus \\ldots \\oplus W_s)=\r\n\\sum_{i=1, j=1}^{r,s} dim(Hom_{{\\mathbb C}G}(V_i , W_j))$. Suppose $U$ is and irreducible\r\n${\\mathbb C}G$-module then \r\n$dim(Hom_{{\\mathbb C}G}({\\mathbb C}G, U))= dim(U)$. [Proof: \r\nLet $d=dim(U)$ and $u_1, u_2, \\ldots, u_d$ be a basis for $U$.  Define\r\n$r \\phi_i=u_i r$.  The $\\phi_i$ are a basis for $Hom_{{\\mathbb C}G}({\\mathbb C}G, U)$].\r\nIf $V_1, V_2, \\ldots, V_r$ are a complete set of irreducible ${\\mathbb C}G$-modules\r\nthen $|G|= \\sum_{i=1}^r dim(V_i)^2$.  [Proof: \r\n${\\mathbb C}G= U_1 \\oplus U_2 \\oplus \\ldots \\oplus U_k$, of these, $dim(V_i)$ are isomorphic\r\nto $V_i$ and each of these had dimension $dim(V_i)$]. \r\nIf $G$ is abelian, any \r\n${\\mathbb C}G$-module has dimension $1$.  If $G \\lhd N$ and $\\chi$ is a character of $G/N$,\r\ndefine $\\tilde{\\chi}(g)= \\chi(gN)$.  $\\tilde{\\chi}$ is a character of $G$ and is irreducile iff\r\n$\\chi$ is irreducible.\r\n\\\\\r\n\\\\\r\n{\\bf Characters:} \r\n$\\chi_{reg}= \\chi_1(1) \\chi_1(g) + \\chi_2(1) \\chi_2(g) + \\ldots + \\chi_r(1) \\chi_r(g)$.\r\nLet $U, V$ be non-isomorphic irreducible ${\\mathbb C}G$ modules with \r\ncharacters $\\chi, \\psi$, then $< \\chi, \\chi>=1$ and $<\\chi, \\psi>=0$. \r\n$\\chi(g)$ is real iff\r\n$\\chi(g)= \\chi(g^{-1}), \\forall \\chi$.  $N \\lhd G$ iff $\\exists \\chi_i, i= 1, \\ldots, k$\r\nsuch that $\\bigcap_{i=1}^k ker(\\chi_i)=N$.  $G$ is not simple iff $\\exists \\chi, g \\ne 1:\r\n\\chi(g)= \\chi(1)$.  $G$ has $|G/G'|$ linear characters.\r\nIf all irreducible representations of $G$ have dimension $1$, $G$ is abelian.\r\nDefine $(\\theta , \\eta)= {\\frac 1 {|G|}} \\sum_g \\theta(g) {\\overline {\\eta(g)}}$.\r\nIf $U = U_{1} \\otimes ... \\otimes U_{s}$, the number of these similar to $U_{1}$\r\nis ${\\frac {(\\theta, \\eta)} {(\\eta, \\eta)}}$.\r\n$(\\theta, \\rho_{G})= \\theta(1)$,\r\n$(\\chi_{i}, \\chi_{j})= \\delta_{ij}$,\r\n$\\sum_{g} \\chi(g) = |G| \\delta_{i1}$,\r\n$\\sum_{i} \\chi_{i}^{2}(1) = |G| $.\r\n$\\omega_{i}(R_{j})= |r_{j}|\\chi_{i}(g)/\\chi_{i}(1)$,\r\n$\\omega_{t}(R_{i}) \\omega_{t}(R_{j})= \\sum_{s} a_{ijs} \\omega_{t}(R_{s})$.\r\n$\\sum_{t} \\chi_{t}(g_{i}) {\\overline \\chi_{t}(g_{j})} =\r\n{\\frac {|G|}{|R_{j}|}} \\delta_{ij}$.\r\nThe number of conjugacy classes = number of irreducible representations.\r\n$\\omega_{i}(R_{j})$ is an algebraic integer.\r\n$\\chi_{i} | |G|$,\r\n$(|R|, \\chi(1))= 1, \\chi^{irred} \\rightarrow\r\n|\\chi(g)|= 1$ or $\\chi(g)= 0$.\r\nLet $H$ be the kernel of $\\theta$ then (i) $|\\theta(g)| \\leq \\theta(1)$,\r\n(ii) $\\theta(g) = \\theta(1)$, iff $g \\in H$,\r\n(iii) $|\\theta(g)| = \\theta(1)$, iff $gH$ is in the center if $G/H$.\r\n{\\bf Characters and group structure: }\r\nThe character table determines the normal subgroups and the nilpotent groups.\r\nGeneral procedure for calculating characters: (1) Derive a faithful representation,\r\n(2) generate group elements, (3) determine conjugacy classes, (4) determine structure\r\nconstants ($|C_i||C_j|= \\sum_k \\alpha_{ijk} |C_k|$), (5) get characters from structure\r\nconstants.\r\nIf $G \\subseteq S_n$, $\\alpha: G \\rightarrow {\\mathbb C}$ by $\\alpha(g)= |fix(g)|-1$,\r\nthen $\\alpha$ is a character of $G$. Define $ker(\\rho)= \\{g: \\chi_{\\rho}(g)= \\chi_{\\rho}(1) \\}$.\r\n$\\rho$ is faithful iff $ker(\\rho)=1$.  $N= \\{n: |\\chi(n)|= \\chi(1) \\} \\lhd G$.  If\r\n$N \\lhd G, \\exists \\chi_i: \\bigcap_{i=1}^r ker(\\chi_i) =N$.  \r\n$g \\sim h$ iff $\\chi(g)=\\chi(h), \\forall  \\chi$.  \r\nLet $x \\in A_n$; if there is an odd permutation that commutes with $x$,\r\n$ccl_{A_n}(x)=ccl_{S_n}(x)$ otherwise\r\n$ccl_{S_n}(x)$ splits into two conjugacy classes in $A_n$.\r\nLet $C_i= \\sum_{x \\in ccl(y)} x$ then the $C_i$ form a basis for ${\\mathbb Z}(FG)$.\r\nThere are $|G/G'|$ inequivalent linear representations (characters) of $G$.\r\n\\\\\r\n\\\\\r\n{\\bf Application of character theory:}\r\nSuppose $\\chi$ is a character of a ${\\mathbb C}G$-module, $V$, and $g \\in G$ has order\r\n$m$ then (1) $\\chi(1)=dim(V)$, (2) $\\chi(g)$ is a sum of $m$-th roots of unity,\r\n(3) $\\chi(g^{-1})= {\\overline {\\chi(g)}}$ and (4) $\\chi(g)$ is real iff $g \\sim g^{-1}$.\r\nIf $\\chi$ is an irreducible character, $\\chi(1) \\mid |G|$ \r\n(If $g_i$ is in the $i$th conjugacy class,\r\n${\\frac {|G|} {|C_G(g_i)|}} {\\frac {\\chi(g_i)} {\\chi(1)}}$ and ${\\overline {\\chi(g)}}$\r\nare algebraic integers so\r\n$\\sum_{i=1}^k {\\frac {|G|} {|C_G(g_i)|}} {\\frac {\\chi(g_i)} {\\chi(1)}}{\\overline {\\chi(g)}}\r\n={\\frac {|G|} {\\chi(1)}}$ is.) {\\bf Burnside's Lemma:} \r\n$|{\\frac {\\chi(g)} {\\chi(1)}}| \\le 1$ if\r\n$|{\\frac {\\chi(g)} {\\chi(1)}}| \\ne 1$ it is not an algebraic integer.  \r\nLet $p$ be a prime and $G$ a finite\r\ngroup with conjugacy class of size $p^r, r \\ge 1$, then $G$ is not simple.\r\n{\\bf Burnside's Theorem:} Every group of order $p^a q^b$ is solvable.\r\nLet $\\chi$ be an irreducible character and $C$ a conjugacy class.\r\nIf$(\\chi(1), |C|)=1$ then either $C \\subseteq Z(\\chi)$ or $\\chi(C)=0$.  If $G$\r\nis a non-abelian simple group $\\{1\\}$ is the only class with prime power\r\norder.  \r\n\\\\\r\n\\\\\r\n{\\bf Feit's moduleless treatment.}\r\nMaschke: If $char(F)$ does not divide $|G|$, then $F$-representations of $G$\r\nare completely reducible.  For $\\phi$ irreducible,\r\nif $\\exists S: \\forall g, S \\phi(g) = \\phi(g) S$ then S is non-singular.\r\nIf $A(g), B(g)$ are $k$-irreducible then (i) if $A$ is not similar to $B$,\r\nand,\r\n$\\sum_{g} a_{is}(g) b_{tj}(g^{-1}) = 0$; or,\r\n(ii) $A$, $B$ are absolutely irreducible and\r\n$\\sum_{g} a_{is}(g^{-1}) a_{tj}(g) =\r\n{\\frac {|G|} {n}} \\delta_{ij} \\delta_{st}$, where $n \\times n$ is the\r\ndimension of $(a_{is}(g))$.\r\nIf $A^{s}$ is absolutely irreducible then $a^{s}_{ij}(g)$ are linearly\r\nindependent and $\\sum_{s=1}^k n_{s}^{2} \\leq |G|$.\\\\\r\n\\\\\r\n{\\bf Induced representations:} If $H \\le G$ and $\\varphi$ a class function on $H$, define\r\n$\\varphi^G(g)= {\\frac 1 {|H|}} \\sum_{x \\in G} \\varphi^* (x^{-1}gx)$. {\\bf Frobenius\r\nReciprocity:} $(\\varphi^G , \\theta)= (\\varphi, \\theta_{|H})$.  \\\\\r\n\\\\\r\n{\\bf Brauer's Characterization of Characters:} $p$-elementary groups are the products of\r\na cyclic $p'$ group and $p$ group.  Every irreducible character is an induced character\r\nof a linear character of a $p$ elementary subgroup for some $p$.\\\\\r\n\\\\\r\n{\\bf RSK correspondence} for representations\r\nof the symmetric group: $\\exists$ bijection between $S_n$ and the set of ordered\r\ntableau of the same shape $g \\leftrightarrow (S,T)$, further\r\n$g^{-1} \\leftrightarrow (T,S)$.\r\n{\\bf Young's diagram:} $D(\\lambda )$, $n= n_1 + n_2 + \\ldots + n_k$,\r\n$n_1 \\geq n_2 \\geq \\ldots \\geq n_k$.\r\nNumber of tableaus with shape $\\lambda$:\r\n$f_{ \\lambda } = \\frac { n!} {\\prod_{i,j \\in D(\\lambda )} {h(i, j)}}$, where\r\n$h(i, j)$ = number of cells in hook $H_{i,j}$.\\\\\r\n\\\\\r\n{\\bf Fixed point free automorphisms:} \r\nLet $G$ be a transitive permutation group on $X$ and $1 \\ne g \\in G$ fixes\r\nno more than one element then $N= \\{g: X_g= \\emptyset \\}$ is a normal subgroup of $G$.\r\nThompson showed any finite group having a fixed point free automorphism is nilpotent.\\\\\r\n\\\\\r\n{\\bf Schrier and coset enumeration:}\r\nLet $G= < g_1 , g_2 , \\ldots , g_m >$.  Let $k_1 , k_2 , \\ldots ,\r\nk_s$ be a group of coset representatives for a subgroup $H<G$. ${\\overline g}$\r\nis the coset representative for $g$ in $G/H$ and $k_1 = 1$ then\r\n$H= < (k_i g_j ) {\\overline {(k_i g_j )^{-1}}} >$\r\nfor $i= 1, 2, 3, \\ldots , s$ and\r\n$j= 1, 2, 3, \\ldots , m$.  Maintain following tables: Coset, relation table\r\nfor each relation, subset table.  Column headers are generators, rows are\r\nright coset labels.\r\nTo calculate $|G|$, calculate orbit of point.  Calculate point stabilizer by\r\ncompleting paths in Schrier tree and using the resulting relations.\\\\\r\n\\\\\r\n${\\cal B}= < \\beta_1 , ... , \\beta_n>$ is a base for \r\n$G \\le Sym(\\Omega)$ if $G_{\\cal B} = 1$.\r\nIf $G^{[i]} = G_{\\beta_1 , ..., \\beta_i}$ and\r\n$G=G^{[1]} \\ge ... \\ge G^{[m+1]}=1$ then\r\n$S$ is a {\\bf strong generating set} relative to ${\\cal B}$ if\r\nit is a generating set and $S \\cap G^{[i]} = G^{[i]}$.  Can use this to get\r\norbit sizes.\r\nSchrier-Sims calculates base and strong generating set.\\\\\r\n\\\\\r\n{\\bf Coxeter groups:} $M= (m_{ij}), 1 \\le i,j \\le n, m_{ii}=1$, \r\n$m_{ij} \\in {\\mathbb Z}, m_{ij} \\ge 2$.  Associate to each\r\nsuch matrix a graph with nodes $i, 1 \\le i \\le n$, $(i,j)$ is an edge if $m_{ij}>0$ if\r\n$m_{ij}>2$, label it with $m_{ij}-2$.  The Coxeter group is $G$ generated by\r\n$S= \\{ s_i \\} , 1 \\le i \\le n$ with $(s_i s_j)^{m_{ij}}=1$.  Note the $s_i$'s must be\r\ninvolutions, $\\theta= {\\frac {\\pi} {m_{ij}}}$. \r\nGeometrically: If $\\Delta= \\{ r_1 , \\ldots , r_n \\}, ||r_i||=1$ \r\nis a {\\bf root system} with each\r\n$r_i$ defining a reflection along its associated hyperplane by $S_r (x) = x-2(r,x)r$ and\r\n$\\alpha_{ij}= -cos({\\frac {\\pi} {p_{ij}}})= (r_i , r_j)$.  Associate a marked\r\ngraph with edges labeled by $p_{ij}$ (unmarked edged have $p_{ij}=3$) and associated\r\nquadratic form $Q({\\vec x})= \\sum \\alpha_{ij} x_i x_j$.  The Coxeter group is generated\r\nby the involutions $S_r$ and $S_{r_i}S_{r_j}$ has order $p_{ij}$.  The quadratic forms\r\nare positive definite and the associated forms are irreducible iff the graphs are\r\nconnected.  The root system is effective iff the roots generate the underlying vector\r\nspace.  Union of the fundamental region under each element of $G$ is the vector\r\nspace.\\\\\r\n\\\\\r\n{\\bf Classical Groups:}\r\nEvery {\\bf transvection} in $SL_n(F)$ is conjugate if $n>2$.  Group orders:\r\n$PSL_n(q)= {\\frac 1 {(q-1)(n,q-1)}} (q^{m} -1) (q^{m} -q) (q^{m} -q^{2}) ...  (q^{m} -q^{m-1})$,\r\nsimple if $n>2$ or $q>3$.\r\n$PSp_{2l}(q)= {\\frac 1 {(2,q-1)}} q^{l^2}(q^{2} -1) (q^{4} -1) ...  (q^{2l} -1)$,\r\nsimple unless $(2l,q)= (2,2), (2,3), (4,2)$.\r\n$PSU_n(q^2)= {\\frac 1 {(n,q+1)}} (q^{\\frac {n(n-1)} 2} -1) (q^{2} -1) (q^{3} +1) \r\n(q^4 -1)...  (q^{n} - (-1)^n)$,\r\nsimple unless $(2l,q)= (2,4), (2,9), (3,4)$.\r\nFor next two, set $\\Omega_n(q)= (O_n(q))' \\subseteq SO_n(q)$.\r\n$P\\Omega_{2l+1}(q)= {\\frac 1 {(n,q-1)}}\r\nq^{l^2}(q^{2} -1) (q^{4} -1) ...  (q^{2l} -1)$,\r\nsimple if $l>1$.  Note \r\n$P\\Omega_{2l+1}(q)$ is not isomorphic to $PSp_{2l}(q)$ despite having the same order.\r\nFor $|\\epsilon|=1$,\r\n${P\\Omega^{\\epsilon}}_{2l}(q)= {\\frac 1 {(4,q^l - \\epsilon)}}\r\nq^{l(l-1)}(q^{2} -1) (q^{4} -1) ...  \r\n(q^{2l-2} -1)\r\n(q^{l} - \\epsilon)$,\r\nif $q=2^k$, simple if $l>2$.\\\\\r\n\\\\\r\n{\\bf Finite Simple Group Families: }\r\n${\\mathbb Z}_p$, Schur Multiplier: 1.\r\n$\\Sigma_n'$ simple if $n>4$,\r\nSchur Multiplier: 6 if $n= 6,7$, 2 if $n=5, n>7$.\r\n$A_n (q) = PSL_{n+1}(q)$ simple if $ n \\geq 1$, \r\nSchur Multiplier: $(n+1,q-1)$ except \r\n$A_1(4) [2]$,\r\n$A_1(9) [6]$,\r\n$A_2(4) [48]$,\r\n$A_3(2) [2]$.\r\n$B_n (q)= P\\Omega_{2n+1}(q)$\r\nsimple if $ n \\geq 1$ , Schur Multiplier: $(2,q-1)$ except\r\n$B_2(2)$,\r\n$B_3(2) [2]$,\r\n$B_2(2) [6]$;\r\n$C_n (q)= PSp_{2n} (q)$ simple if $n > 2$ , Schur Multiplier: \r\n$(2,q-1)$ except $C_3(2) [2]$.\r\n$D_n (q)= P\\Omega_{2n}^{+}(q)$ simple if $n \\geq 4$, \r\nSchur Multiplier: $(2,q-1)$ except $D_4(2) [4]$.\r\n$E_6 (q)$ of order \r\n${\\frac 1 {(3,q-1)}} q^{36} (q^{12}-1)(q^{9}-1) (q^{8}-1) (q^{6}-1) (q^{5}-1) (q^{2}-1)$, \r\nSchur Multiplier: $(3,q-1)$.\r\n$E_7 (q)$ \r\nof order \r\n${\\frac 1 {(3,q-1)}} q^{63} (q^{18}-1) (q^{14}-1) (q^{12}-1) \r\n(q^{10}-1) (q^{8}-1) (q^{6}-1) (q^{2}-1)$, \r\nSchur Multiplier: $(2,q-1)$.\r\n$E_8 (q)$ \r\nof order \r\n$q^{120} (q^{30}-1) (q^{24}-1) (q^{20}-1) \r\n(q^{18}-1) (q^{14}-1) (q^{12}-1) (q^{8}-1) (q^{2}-1)$, \r\nSchur Multiplier: $1$.\r\n$F_4 (q)$ of order $q^{24} (q^{12}-1) (q^{8}-1) (q^{6}-1) (q^{2}-1)$, \r\nSchur Multiplier: $1$ except $F_4(2)[4]$.\r\n$G_2 (q)$ simple except $G_2(2)$\r\nof order \r\n$q^{6} (q^{6}-1)(q^{2}-1)$, \r\nSchur Multiplier: $1$ except $G_2(3) [3]$, $G_2(4) [2]$.\r\n$^2A_n (q^2) = PSU_{n+1}(q)$ simple if $ n \\geq 2$, Schur Multiplier: \r\n$(n+1, q+1)$ except\r\n$^2A_3(2^2) [2]$,\r\n$^2A_3(3^2) [36]$,\r\n$^2A_5(2^2) [12]$ .\r\n$^2D_n (q)= P\\Omega_{2n}^{-}(q)$\r\nsimple if $ n \\geq 4$, Schur Multiplier: $(4, q^n+1)$.\r\n$^3D_4 (q^3)$ \r\nof order \r\n$q^{12} (q^{8}+q^4+1) (q^{6}-1) (q^{2}-1)$, \r\nSchur Multiplier: $1$ .\r\n$^2E_6 (q)$ \r\nof order \r\n$q^{36} (q^{12}-1) (q^{9}+1) (q^{8}-1) (q^{6}-1) (q^{2}-1)$, \r\nSchur Multiplier: $(3,q+1)$ except\r\n$^2E_6(2^2) [12]$.\r\n$^2B_2 (2^{2m+1})= Sz(2^{2m+1})$\r\nsimple if $ m > 1$ \r\nof order \r\n$q^{2} (q^{2}+1) (q-1)$, \r\nSchur Multiplier: $1, n>2$.\r\n$^2F_4 (2^{2m+1})$ (Ree) simple if $ m >1$\r\nof order \r\n$q^{12} (q^{6}+1) (q^{4}-1) (q^{3}+1) (q-1)$, \r\nSchur Multiplier: $1,m>1$.\r\n$^2G_2 (3^{2m+1})$ (Ree) simple if $ m > 1$\r\nof order \r\n$q^{3} (q^{3}+1) (q-1)$, \r\nSchur Multiplier: $1, m>1$.\\\\\r\n\\\\\r\n{\\bf Sporadic Groups:}\r\n$M_{11}$ ($2^4 \\cdot 3^2 \\cdot 5 \\cdot 11$), Schur: 1.\r\n$M_{12}$ ($2^6 \\cdot 3^3 \\cdot 7 \\cdot 11$), Schur: 2.\r\n$M_{22}$ ($2^{7} \\cdot 3^2 \\cdot 5 \\cdot 7 \\cdot 11$), Schur: 12.\r\n$M_{23}$ ($2^{7} \\cdot 3^2 \\cdot 5 \\cdot 7 \\cdot 11 \\cdot 23$), Schur: 1.\r\n$M_{24}$ ($2^{10} \\cdot 3^3 \\cdot 5 \\cdot 7 \\cdot 11 \\cdot 23$), Schur: 1.\r\n$J_1$ ($2^{3} \\cdot 3 \\cdot 5 \\cdot 7 \\cdot 11 \\cdot 19$), Schur: 1.\r\n$J_2 = HJ$ ($2^{7} \\cdot 3^3 \\cdot 5^2 \\cdot 7$), Schur: 2.\r\n$J_3 = HJM$ ($2^{7} \\cdot 3^5 \\cdot 5 \\cdot 17 \\cdot 19$), Schur: 3.\r\n$J_4$ ($2^{21} \\cdot 3^3 \\cdot 5 \\cdot 7 \\cdot 11^3 \\cdot 23 \\cdot 29 \\cdot 31 \\cdot 37 \\cdot 43$), Schur: 1.\r\n$Co_1$ ($2^{21} \\cdot 3^9 \\cdot 5^4 \\cdot 7^2 \\cdot 11 \\cdot 13 \\cdot 23$), Schur: 2.\r\n$Co_2$ ($2^{18} \\cdot 3^6 \\cdot 5^3 \\cdot 7 \\cdot 11 \\cdot 23$), Schur: 1.\r\n$Co_3$ ($2^{10} \\cdot 3^7 \\cdot 5^3 \\cdot 7 \\cdot 11 \\cdot 23$), Schur: 1.\r\n$HS$ ($2^{9} \\cdot 3^2 \\cdot 5^3 \\cdot 7 \\cdot 11$), Schur: 2.\r\n$Mc$ ($2^{7} \\cdot 3^6 \\cdot 5^3 \\cdot 7 \\cdot 11$), Schur: 3.\r\n$Sz$ ($2^{13} \\cdot 3^7 \\cdot 5^2 \\cdot 7 \\cdot 11 \\cdot 13$), Schur: 1.\r\n$Ly$ ($2^{8} \\cdot 3^7 \\cdot 5^6 \\cdot 7 \\cdot 11 \\cdot 31 \\cdot 37 \\cdot 67$), Schur: 1.\r\n$He$ ($2^{10} \\cdot 3^3 \\cdot 5^2 \\cdot 7^3 \\cdot 17$), Schur: 1.\r\n$Ru$ ($2^{14} \\cdot 3^3 \\cdot 5^3 \\cdot 7 \\cdot 13 \\cdot 29$), Schur: 1.\r\n$O'N-S$ ($2^9 \\cdot 3^4 \\cdot 5 \\cdot 7^3 \\cdot 11 \\cdot 19 \\cdot 31$), Schur: 3.\r\n$F_{22}$ ($2^{17} \\cdot 3^9 \\cdot 5^2 \\cdot 7 \\cdot 11 \\cdot 13$), Schur: 6.\r\n$F_{23}$ ($2^{18} \\cdot 3^{13} \\cdot 5^2 \\cdot 7 \\cdot 11 \\cdot 13 \\cdot 17 \\cdot 23$), Schur: 1.\r\n$F_{24}$ ($2^{21} \\cdot 3^{16} \\cdot 5^2 \\cdot 7^3 \\cdot 11 \\cdot 13 \\cdot 17 \\cdot 23 \\cdot 29$), Schur: 3.\r\n$F_3$ (Thompson) ($2^{15} \\cdot 3^{10} \\cdot 5^3 \\cdot 7^2 \\cdot 13 \\cdot 19 \\cdot 31$), Schur: 2.\r\n$F_5$ (Harada) ($2^{14} \\cdot 3^{6} \\cdot 5^6 \\cdot 7 \\cdot 11 \\cdot 19$), Schur: 1.\r\n$F_2$ (Baby Monster) ($2^{41} \\cdot 3^{13} \\cdot 5^6 \\cdot 7^2 \\cdot 11 \\cdot 13 \r\n\\cdot 17 \\cdot 19 \\cdot 23 \\cdot 31 \\cdot 47$), Schur: 2.\r\n$F_1$ (Monster) ($2^{46} \\cdot 3^{20} \\cdot 5^9 \\cdot 7^6 \r\n\\cdot 11^2 \\cdot 13^3 \\cdot 17 \\cdot 19 \\cdot 23 \\cdot 29 \\cdot 31 \\cdot 41 \\cdot 47 \\cdot \r\n59 \\cdot 71$), Schur: 1.\\\\\r\n\\\\\r\nLet $\\Delta$ be an orbit of $G$ and let $\\delta \\in \\Delta$.  For each $\\gamma \\in \\Delta$\r\nlet $v(\\gamma ) \\in G$ be such that $\\delta \\mapsto \\gamma$.  Finally, suppose $S$\r\ngenerates $G$.  Then $G_{\\delta}=<v(\\gamma)sv(\\gamma^{s})^{-1} | \\gamma \\in \\Delta,\r\ns \\in S>$.\\\\\r\n\\\\\r\n{\\bf System of imprimitivity for permutation \r\ngroup $G$:} ${\\cal B}=\\{ \\Delta_i\\}$ $|\\Delta_i|>1$ with\r\nthe property that for $\\Delta \\in {\\cal B}, g \\in G$ either \r\n$\\Delta \\cap \\Delta^g = \\phi$ or\r\n$\\Delta = \\Delta^g$.  {\\bf Primitive:} No set of imprimitivity.\r\n$\\Gamma$ is $G$ invariant if $\\Gamma^G= \\Gamma$ so $\\Gamma$ is a union of $G$ orbits.\r\n$G/G_{\\Gamma} \\equiv G^{\\Gamma}$.\r\nIf $\\Delta \\subseteq \\Gamma$ and $\\alpha \\in \\Omega$ then \r\n$\\psi = \\bigcap_{\\alpha \\in \\Delta^g} \\Delta^g$ is a block of a transitive\r\ngroup $G \\subseteq Sym(\\Omega)$.\r\nA transitive group is imprimitive iff $\\exists Z$: $G_{\\alpha} < Z < G$.\r\n$G$ is primitive iff $G_{\\alpha}$ is maximal.\r\nLet $G$ act transitively on $\\Omega$, $H \\lhd G$ then\r\n(1) The orbits of $H$ are blocks of $G$,\r\n(2) If $\\Delta$ and $\\Delta'$ are two $H$ orbits then they are permutation isomorphic,\r\n(3) If any point lies is fixed by all elements of $H$ then $H$\r\nlies in the kernel of the action on $\\Omega$,\r\n(4) The group $H$ has at most $|G:H|$ orbits, if finite, it divides $|G:H|$,\r\n(5) If $G$ acts primitively on $\\Omega$ then either $H$ is transitive or it\r\nlies in the kernel of the action.\\\\\r\n\\\\\r\nDefine ${\\cal G}(G, \\Omega )$ as the graph of $G$ acting on $\\Omega$ as follows:\r\n$G$ acts on $\\Omega \\times \\Omega$.  Diagonal orbital is\r\n$\\Delta_1 = \\{ (\\alpha , \\alpha )\\}$. If $\\Delta = \\{ (\\alpha , \\beta ) \\}$,\r\n$\\Delta^*= \\{ (\\beta, \\alpha) \\}$.  Self paired if $\\Delta^* = \\Delta$.\r\n$\\Delta(\\alpha)= \\{ \\beta : (\\alpha , \\beta ) \\in \\Delta \\}$ --- corresponds to \r\norbits of $G_{\\alpha}$. The {\\bf rank of the permutation group} is number of orbitals.\r\nOn a self-paired orbit $\\Delta$, the graph ${\\cal G}=(G, X,\\Delta)$ is \r\nsymmetric and $G$ is transitive on edges.\r\nLet $G$ be a transitive permutation group of even order and rank 3 with two\r\nnecessarily self-paired non-diagonal orbits $\\Delta$ and $\\Gamma$.  $G$ is primitive\r\niff ${\\cal G}$ is connected.\\\\\r\n\\\\\r\nA transitive permutation group is {\\bf regular} if $|X|= |G^X|$ or, equivalently \r\n$|G_x|=1, \\forall x \\in X$ and $G^X$, transitive.\r\nLet $X$ be a faithful primitive $G-set$ with $G_x$ simple.  The either $G$ is simple or\r\nevery non-trivial normal subgroup $H$ of $G$ is a regular normal subgroup.\r\n{\\bf Iwasawa:}  Let $G=G'$ and\r\n$X$ be a faithful primitive $G-set$.  If there is an $x \\in X$ and an Abelian normal\r\nsubgroup $K \\lhd G_x$ whose conjugates generate $G$ then G is simple.  {\\bf Permutation\r\nrepresentation:} Let $H \\le G$ and $Hg_1 , ..., Hg_n$ be the cosets; the map\r\n$\\pi(g): <Hg_1, ..., Hg_n> \\mapsto <Hg_1 g, ..., Hg_n g>$ is a map from $G$ to $\\Sigma_n$\r\nwhose kernel is the largest normal subgroup of $G$ in $H$.  Corollary:\r\nIf $H<G$ and $G$ is simple then $|G| \\mid |G:H|!$. \r\nIf $G^X$ is primitive and $1 \\ne N \\lhd G^X$ then $N^X$ is\r\ntransitive.  If $G^X$ is primitive and $G_x$ is simple then either (1) $G$ is simple, or\r\n(2) $\\exists N \\lhd G: N^X$ is regular. If $N$ is a regular normal subgroup of\r\n$G^X$ then $G_x$ acts on $N^\\#$.  If $A$ is transitive on $H^\\#$ then $H \\cong (Z_p)^n$,\r\nif 2-transitive, $H \\cong (Z_2)^n$ or $Z_3$, if 3-transitive, $H \\cong (Z_2)^2$.\r\n{\\bf Semi-regular action:}  $C_G(a)=1, \\forall a \\in A^{\\#}$.  Suppose $A$ acts semi-regularly\r\non $G$.  Then (1) $|G| = 1 \\jmod{|A|}$, (2) $A$ is semi-regular on each $A-$invariant\r\nsubgroups factor group of $G$, (3) $\\forall p \\in \\pi(G)$, $\\exists! A-$invariant\r\nSylow $p-$subgroup of $G$, (4) $\\forall a \\in A, g \\mapsto [g,a]$ is a permutation of\r\n$G$, (5) if $2 | |A|, \\exists t: |t|=2, t \\in A: g^t = g^{-1}, g \\in G$ and\r\n$G^{(1)}=1$.\r\n{\\bf Frobenius group:} Transitive permutation group with non-trivial stabilizers\r\nbut only the identity fixes more than one letter.  If $G$ is a Frobenius group\r\nthen the set $S$ of elements which fix no points together with $e$ form a normal\r\nsubgroup of order $|G:G_a|$; Thompson showed this normal subgroup is nilpotent.\\\\\r\n\\\\\r\n{\\bf Metacyclic:} $\\exists H \\lhd G: G/H ,H$ are cyclic. \r\n$Core_G(H)= \\bigcap_{g \\in G} H^g$ (Can use this to show $|G:Core_G(H)|\\le |G:H|!$).\r\n$O^{\\cal A}(G)= \\bigcap_{A \\lhd G, G/A \\in {\\cal A}} A$.\r\n$O_{\\cal A}(G)= \\prod_{A \\lhd G, A \\in {\\cal A}} A$.\r\n{\\bf Socle:} $soc(G)= <M>$ where $M$ is a non-trivial minimal normal subgroup of $G$.\r\n$O_{\\pi}(G)=$ maximal normal $\\pi-$subgroup of $G$.\r\n$O^{\\pi}(G)=$ smallest normal subgroup of $G$ such that $G/O^{\\pi}(G)$ is a $\\pi$-group.\r\n$G$ is $p-$closed if $O_p(G) \\in S_p(G)$.\r\n$SCN(P)=$ set of self centralizing normal subgroups of $P$.\r\n$SCN(p)= SCN(P)$ where $P \\in SCN(P)$.\r\n${\\cal N}_G(A, \\pi)=$ set of all $A-$ invariant $\\pi$ subgroups of $G$.\r\n${\\cal N}_G^*(A, \\pi)=$  maximal subgroups in ${\\cal N}_G(A, \\pi)$.  For a $p-$group, $P$,\r\n$\\Omega_n(P)= <x \\in P: x^{p^n}=1>$ and\r\n$\\mho_n(P)= <x^{p^n}: x \\in P>$.\r\n$H \\subseteq G$ and $S$ an $H$-invariant subset of $G$, $H$ is said to control fusion\r\nin $S$ if for $s \\in S$, $s^G \\cap S = s^H$.\r\nLet $X \\le H \\le G$.  $X$ is {\\bf weakly closed} in $H$ with respect to $G$ if\r\n$X^g \\cap H = \\{X\\}$.\r\n$G$ is {\\bf $p-$solvable} if it has a normal series whose factors are either\r\n$p-$groups or $p'$-groups.  \r\n$G$ is {\\bf $p$-constrained} if \r\n$P \\in S_p ( O_{p',p} (G))$ implies $C(P) \\subseteq O_{p',p} (G)$.\r\n$G$ is {\\bf $p$-stable} if $p \\ne 2$ and \r\nif $A \\in p(N(P))$ with $[P,A,A]= 1$ implies $A C(P)/C(P) \\subseteq O_p (N(P)/C(P))$.\r\n$m_p(P)$ is the rank of the largest elementary abelian $p$-group in $P$.\r\n$O_{\\infty}(G)=$ largest solvable normal subgroup of $G$.\r\n$F(G)$ is the unique maximal normal, nilpotent subgroup of $G$ and\r\n$F(G)= \\prod_p O_p(G)$ .\r\n$E_{p^n}$ denotes the elementary abelian $p-$group of rank $n$.\r\n$m_{2,p}(G) = max \\{ m_p (H) \\}$, where $H$ is 2-local.\r\n$e(G) = max \\{ m_{2,p} (G), p \\ne 2 \\}$ ($e(G)$ is a good approximation of\r\nthe Lie rank.).\r\n$O_{p'}(G)$ is called the {\\bf $p$-core} of $G$. $O_{2'}(G)$ is often called the\r\n{\\bf core} of $G$ and is sometimes denoted by $O(G)$.\r\nWalter: Let $G$ be a group with 2 rank $\\ge 5$ and $O_{2'}(G)=1$ with the property\r\nthat the centralizer of every involution is $2-$constrained then $O_{2'}(C(x))=1$ for\r\nevery involution $x$.\\\\\r\n\\\\\r\n{\\bf Modular Property:} If $A, B, C \\le G$ and $A \\le C$ then $AB \\cap C= A(B \\cap C)$.\r\n$[ab,c]= [a,c]^b [b,c]$ and $[a,bc]=[a,c] [a,b]^c$.  \r\n{\\bf Jacobi:} $ [x, y^{-1}, z] [y, z^{-1}, x] [z, x^{-1}, y]=1$.\r\nIf $x,y \\in C(z), z=[x,y]$ then\r\n$[x^n , y^m ]= z^{mn}$ and $(yx)^n= y^n x^n z^{\\frac {n(n-1)} 2}$.  \r\n{\\bf Three Subgroups:} $A, B, C \\subseteq G$ and\r\n$N \\lhd G$ with\r\n$[A,B,C] \\subseteq N$ and\r\n$[B,C,A] \\subseteq N$ then\r\n$[C,A,B] \\subseteq N$.\\\\\r\n\\\\\r\nLet $G$ be a group with $G/Z(G)$ finite, then $G^{(1)}$ is finite.  Proof:\r\nLet $n= |G/Z(G)|$.  For $z \\in Z(G)$ and $g,h \\in G$: $[g,hz]=[g,h]=[gz,h]$ so the \r\nset of commutators, $\\Delta$, is of order at most $n^2$.\r\nClaim: $g \\in G^{(1)}$ then $g= x_1 x_2 \\ldots x_m$, $x_i \\in \\Delta$ and\r\n$m \\le n^3$.\\\\\r\n\\\\\r\n{\\bf Critical subgroup of a $p$-group:}\r\n$H \\; char \\; G$ with $\\Phi(H) \\le Z(H) \\ge [G,H]$.\r\n$C_G(H)=Z(H)$.  Every $p-$group has a critical subgroup.\r\nA $p-$group $P$ is {\\bf special} if $\\Phi(G)=Z(G)=G'$ and {\\bf extra-special}\r\nif $Z(G)$ is cyclic.\r\nLet $G$ be a non-abelian group of order $p^n$ with cyclic subgroup\r\n$H$ of index $p$ then $G \\cong <p^n>, D_{2^n}, SD_{2^n}, Q_{2^n}$.\\\\\r\n\\\\\r\n{\\bf O-Nan-Scott:}  Let $G$ be a finite primitive permutation group of degree $n$ and\r\n$H=soc(G)$.  Then either (1) $H$ is a regular elementary abelian $p$ group for\r\nsome $p$ and $G$ is isomorphic to a subgroup of\r\n$AGL_m(P)$ ; or, (2) $H$ is isomorphic to $T^m$ where $T$ is a non-abelian simple group\r\nwith a bunch of conditions.\\\\\r\n\\\\\r\n{\\bf Mathieu Groups:}\r\n$M_{11}$: $\\pi_1= (123)(456)(789), \\pi_2= (147)(258)(369)$,\r\n$<\\pi_1, \\pi_2>= {\\mathbb Z}_3 \\times {\\mathbb Z}_3$, \r\n$\\rho_1= (2437)(5698), \\rho_2= (2539)(4876)$, $<\\rho_1 , \\rho_2> = Q \\cong Q_8$.  Set\r\n$M_9= <\\pi_1 , \\pi_2 , \\rho_1 , \\rho_2>$, $|M_9|=72$.  \r\nNow set $\\sigma= (1, 10)(4,5)(6,8)(7,9)$, $\\mu= (4,7)(5,8) (6,9) (10,11)$,\r\n$\\theta= (4,9) (5,7) (6,8)(11,12)$.  \r\n$M_{10}= M_9 \\cup M_9 \\sigma M_9$,  $(M_{10})_x= M_{9}$,\r\n$M_{11}= M_{10} \\cup M_{10} \\mu M_{10}$,  $(M_{11})_x= M_{10}$,\r\n$M_{12}= M_{11} \\cup M_{11} \\theta M_{11}$,  $(M_{12})_x= M_{11}$.  $|M_{11}|=7920$.\r\n$|M_{24}|= 24 \\cdot 23 \\cdot 22 \\cdot 21 \\cdot 20 \\cdot 48 $.  $M_{11}$ is simple:\r\nLet $N$ be a non-trivial normal subgroup, it is regular and all Sylow 11 subgroups\r\nare contained in it (there are 144 by sylow) and $G:N$= 5.  All Sylow 3 subgroups\r\nof $M_{11}$ are in N and $\\psi= \\pi_1 \\sigma \\pi_2^2 \\sigma^{-1}$ has order 5 which is a\r\ncontradiction.  Note symmetries of $S(4,5,11)$ also generate it.  Note that $(M_{11})_a= PSL_2(9)$\r\nand $(M_{22})_a = PSL_3(4)$.\\\\\r\n\\\\\r\n{\\bf Schur-Zassenhaus:}\r\nLet $G$ be a finite group, $H \\lhd G$ and $(|H|, |G:H|)=1$ and either are\r\nsolvable then $G$ splits over $H$ and $G$ is transitive on $H$ complements.\r\nProof of existence\r\nby induction:  Suppose it holds for all groups of order $<G$ and that $|G|=nm;\r\n(m,n)=1; N \\lhd G; |N|= n$.  If $\\exists K \\le G: |K|=m$ then the theorem is true.\r\nLet $P \\in S_p(N)$.  (1) We may assume $P \\lhd N$:  If not \r\n$G=N_G(P)N, N_N(P)=N_G(P) \\cap N \\lhd N_G(P)$ and \r\n$m=|G/N|=|N(P)N/N|=|N_G (P)/(N_G (P) \\cap N|= |N_G(P)/N_N(P)|$ and $N_G(P)$ has a\r\nnormal Hall group $N_N(P)$ so by induction $\\exists K \\subseteq N_G(P)$ with\r\n$|K|=m$ and $N_N(P)K=N_G(P)$, so $NK=G$. (2) We may assume $P=N$: If not,\r\n$|(G/P)/(N/P)|=m$ so $\\exists L/P: (N/P)(L/P)= G/P$ and \r\n$|L|=m |P|$, $|L \\cap N| \\mid (|L|, |N|)$;\r\nbut $(m, |N|)=1$ so $L \\cap N \\subset P$ and $L<G$ and $\\exists K \\subset L: |K|=m$.\r\n(3) May assume $N=P$ is abelian:  If not $1 \\ne Z=Z(N) \\; char ;\\ N \\lhd G$ and\r\n$|(G/Z)/(N/Z)|=m$ so $\\exists L/Z: (L/Z)(N/Z)=(G/Z)$ and $L \\cap N =Z, L < G$ and\r\n$(|Z|, |L/Z|)=1$ and $L$ and hence $G$ has a desired subgroup $K$.\r\n(4) So it suffices to show the theorem if $N$ is a normal abelian Hall $p-$group.\r\nLet ${\\overline H}= G/N$.  If $h \\in {\\overline H}$ and $t , u$ are two elements of\r\n$h$ then $t^{-1}u \\in N$ so $tnt^{-1}=unu^{-1}$.  Define $^tx=txt^{-1}, t \\in h$.\r\n$H$ acts on $N$ - i.e. $H \\subset Aut(N)$.\r\nSelect a transversal $\\{t_h | h \\in H \\}$.\r\n$ t^{-1}_{h_1h_2}N = (t_{h_1h_2}N)^{-1}=\r\n(h_1h_2)^{-1}= {h_1}^{-1}{h_2}^{-1}, \\forall h_1 , h_2 \\in H$, so \r\n$t_{h_1}t_{h_2} t^{-1}_{h_1 h_2} \\in N$.  Define $f: H \\times H \\rightarrow N$ by\r\n$f(h_1, h_2) t_{h_1 h_2} = t_{h_1} t_{h_2}$.  Since\r\n$t_{h_1}(t_{h_2} t_{h_3}) = (t_{h_1}t_{h_2}) t_{h_3}$, we get\r\n$ {^{h_1}} f(h_2, h_3)+ f(h_1, h_2 h_3)= f(h_1, h_2)+ f(h_1 h_2 , h_3)$.  If \r\n$\\exists c:H \\rightarrow N: f(h_1 , h_2)= c(h_1 h_2) -c(h_1) - {^{h_1}} c(h_2)$, then\r\n$c(h_1 h_2) t_{h_1 h_2}= c(t_1)t_{h_1} c(t_2) t_{h_2}$, this would be an isomorphism\r\nwhose image would satisfy the requirements of $K$.  Define: $e: H \\rightarrow N$ by\r\n$e(h) = \\sum_{k \\in H} f(h , k)$.\r\n$m f( h_1 , h_2 )=  -e(h_1 h_2) + e(h_1) + {^{h_1}}e(h_2)$.  Since $(m, |N|)=1$,\r\n${\\frac x m}$ is well defined for $ x \\in N$ and $c(x)= {\\frac {-1} m} e(x)$ satisfies the\r\ndesired properties.\r\nProof of conjugacy:\r\nSuppose $G/N$ is solvable and $\\pi$ is the set of primes dividing $m=|G:N|$ and\r\n$H,K \\le G$ and $|H|=|K|=m$, put $R=O_{\\pi}(G)$ so $O_{\\pi}(G/R) = 1$.  \r\nLet $L/N$ be a minimal\r\nnormal subgroup of $G/N$ then $L/N$ is an elementary abelian $p-$group for some $p$.\r\n$H\\cap L \\in S_p(L)$ and\r\n$S=(H \\cap L)=(K \\cap L)^g= K^g \\cap L$.  $S \\lhd <H, K^g>=J$.  If $J=G$, $S \\lhd J$\r\nand $S \\subseteq R=1$; thus $L$ is a $p'-$group which is a contradiction.  So\r\n$J \\ne G$ and by induction $K$, $K^g$ are $J$-conjugate.  \r\nThis concludes this case.  Suppose\r\n$N$ is solvable and again $|H|=|K|=m=|G:N|$.  \r\n$HN'/N' \\cong KN'/N'$ so $h^g \\subseteq KN'$ and\r\nagain by induction, $H^{gk}= K$.\\\\\r\n\\\\\r\n{\\bf Philip Hall's Theorem:} \r\nLet $G$ be a solvable group and $\\pi$ a set of primes then (i) $G$ has a $\\pi$-Hall\r\nsubgroup, (ii) $G$ acts transitively on its Hall $\\pi$-subgroups via conjugation, \r\n(3) any $\\pi$ subgroup is contained in a Hall $\\pi$ subgroup.\r\nProof: By induction on $|G|$.  Let $N$ be a minimal normal subgroup of $G$ then\r\n$1 \\ne N \\lhd G$.  $N$ is elementary abelian for some $p$ and $p \\mid mn$.   If\r\n$p \\mid m, |G/N|= {\\frac m p}$ and $\\exists L: |L/N|= {\\frac m p}, |L|= m$ and we're done.\r\nIf $p \\mid n, \\exists H: |H/N|=m, |H|= |N|m$.  If $|H| < |G|$, we're done by induction.\r\nOtherwise $H=G, N \\lhd G, |N|= n, |G:N|=m$ and $(m,n)=1$ so by Schur Zassenhaus,\r\n$\\exists K: |K|=m$.\\\\\r\n\\\\\r\n{\\bf Theorem: } Let $G$ be a finite group possessing a Hall $\\pi'$ subgroup for each $p$, then $G$ \r\nis solvable. (Proof requires Burnside $p^a q^b$ theorem.)\\\\\r\n\\\\\r\n{\\bf Frattini subgroup:} $\\Phi(G)$ is the intersection of all maximal subgroups of $G$.\r\n$\\Phi(G) \\; char \\; G$.  If $H= <X, \\Phi(H)>$ then $H= <X>$.  If $P$\r\nis a $p-$group $P/\\Phi(P)$ is elementary abelian.\r\nFrattini Argument: $H \\lhd G$, $P \\in S_p(H)$ then $G=H N_G(P)$.\\\\\r\n\\\\\r\nIf $A$ is a maximal abelian normal subgroup of $P$ and $Z=\\Omega_1(A)$.  Then\r\n(1) $(C_P(A/Z) \\cap C(Z))^{(1)} \\le A$, (3) if $p$ is odd $\\Omega_1(C_P(Z)) \\le C_P(A/Z)$.\r\nIf $p$ is odd and $Z$ is a maximal elementary abelian subgroup of $P$ then\r\n$Z \\setminus \\Omega_1 (C_P(Z))$.\\\\\r\n\\\\\r\n{\\bf Co-prime action 1:}\r\nIn this paragraph $A$ acts on $G$ and $(|A|, |G|)=1$ with either\r\n$A$ or $G$ solvable.  If $U \\leq G$ is $A-$invariant and $g$ satisfies $(Ug)^A=Ug$ then\r\n$\\exists c \\in C_G(A)$: $Ug=Uc$. If $N$ is an $A-$invariant normal subgroup of $G$ then\r\n(1) $C_{G/N}(A)= C_G(A)N/N$ (This shows $G=[G,A]C_G(A)$.) and (2) if $A$ acts\r\ntrivially on $N$ and $G/N$ then $G$ acts trivially on $G$. If $p \\mid |G|$ (the analogous\r\nresults hold for $\\pi$) then (1) $\\exists S \\in S_p(G): S^A=S$, (2) all such $A-$invariant\r\nSylow $p-$groups are conjugate under $C_G(A)$, (3) every $A-$invariant $p$-group of\r\n$G$ is contained in an $A-$invariant Sylow $p-$group.  \r\nIf $T=\\bigcap_{S \\in S_p(G), S^A=S} S$,\r\nthe $T$ is the largest $A-$invariant $p-$subgroup of $G$ normalized by $C_G(A)$.  If\r\n$P$ is an $A-$invariant Sylow $p-$group and $H \\le G$ with $H^A=H, H^{C_G}(G)=H$ then\r\n$P \\cap H \\in S_p(H)$.  If $A= P \\times Q$ acts on $M$ and $P, M$ are $p-$groups and\r\n$Q$ is a $p'-$group with $C_M(P) \\le C_M(Q)$ then $[M,Q]=1$. If $A$ acts trivially on\r\n$G/\\Phi(G)$ then $A$ acts trivially on $G$ and if $\\Phi(G)$ is a $p-$group then\r\nso is $A/C_A(G)$. \r\nApplying $P \\times Q$: If $p \\in \\pi(G)$ and ${\\overline G}= G/O_{p'}(G)$\r\nwith $C_{\\overline G}(O_p({\\overline G})) \\le O_p({\\overline G})$ then \r\n$\\forall P \\in p(G), O_{p'}(N_G(P))=O_{p'}(G) \\cap N_G(P)$.\r\n{\\bf Thompson:} Let $a$ be a $\\pi'$ automorphism of a $\\pi$ group $P$ and suppose\r\n$X \\lhd \\lhd P$ such that $[a,X]=1=[a,C_P(X)]$ then $a=1$.\r\n${\\bf P \\times Q}$ {\\bf Lemma:} Let $A= P \\times Q$, $P$ a $p-$group, $Q$ a $p'$-group.\r\nSuppose $M$ is a $p$-group and $C_M(P) \\le C_M(Q)$.  Then $Q$ acts trivially on $M$.\\\\\r\n\\\\\r\n{\\bf Co-prime action 2:}\r\nIf $P$ is a $p-$group and $Q$ a $p'-$ group with $Q \\mapsto Aut(P)$ then\r\n$Q$ is faithful on $P/\\Phi(P)$.\r\nA group of automorphisms $A$ of a group $P$ stabilizes a chain\r\n$1=P_n \\subseteq P_{n-1} \\subseteq \\ldots \\subseteq P_0 = P$ if\r\n$[A,P_i] \\subseteq P_{i+1}$.  If $P$ is a $\\pi$ group stabilized by\r\n$A$ then $A$ is a $\\pi$ group.  Proof: $a \\in A$ is a $\\pi'$ automorphism.\r\n$x^a =xy, y \\in P_1$.  Similarly, $x^{a^{|a|}}= x y^{|a|}=x$, so $y=1$ and\r\n$[a,P]=1$.\r\nIf $A$ is a $\\pi'$ group of automorphisms on a $\\pi$ group $P$ with\r\n$[P,A,A]=1$ then $[P,A]=1$.  Proof:  $A$ stabilizes\r\n$[P,A,A] \\subseteq [P,A] \\subseteq P$.\r\nLet $A$ be a $\\pi'$ group of automorphisms of a $\\pi$ group $P$.  Let $Q$ be\r\nan $A-$invariant normal subgroup of $P$.  Then $C_{P/Q}(A)= (C_P(A) Q)/Q$.  Proof\r\nuses Schur-Zassenhaus.\r\n$P$ is a $\\pi$ group, $A$ is a $\\pi'$ group.  $P= [P,A] C_P(A)$.  Proof:\r\n$[P,A] \\subseteq P$ and $A$ centralizes $P/[P,A]$.\r\n$P$ is an abelian $\\pi$ group, $A$ is a $\\pi'$ group.  $P= [P,A] \\oplus C_P(A)$.  Proof:\r\n$\\theta= {\\frac 1 {|A|}} \\sum_a a$.\\\\\r\n\\\\\r\nIf $G$ is solvable, (1) $C(F(G)) \\subseteq F(G)$, (2) if $P$ is a $p-$group\r\nof $G$ then $O_{p'}(C(P)) \\subseteq O_{p'}(G)$ and $O_{p'}(N_G(P)) \\subseteq O_{p'}(G)$.\r\nIf $P \\in p(G)$ with $N_G(P)$ $p-$constrained then $C_G(P)$ is also $p-$constrained.\r\n$|A|, |H| < \\infty, (|A|, |H|)=1$.  Suppose $A \\rightarrow Aut(H)$ and either are\r\nsolvable then (1) $\\exists A-$invariant Sylow $p-$group of $H$, \r\n(2) $C_H(A)$ is transitive on the $A-$invariant sylow $p-$subgroups of $G$,\r\n(3) If $K$ is an $A-$invariant normal subgroup of $H$ and $H^*=H/K$ then\r\n$C_{H^*}(A)= N_{H^*}(A)=(C_H(A))^*$. (5) Every $A-$invariant\r\n$p-$subgroup of $H$ is contained in an $A-$invariant Sylow $p-$group of $H$.\\\\\r\n\\\\\r\n{\\bf Transfer:} $|G|< \\infty, H \\le G$ .\r\n$|G:H|=n$ and\r\n$\\{ l_1 , l_2 , \\ldots , l_n \\}$ be a left traversal and suppose\r\n$gl_i= l_j x_i$ then $V(g)= \\prod_{i=1}^n x_i H'$.\r\n$\\exists h_1 , h_2 , \\ldots , h_m \\in H$ and  $n_1 , n_2 , \\ldots , n_m$. \r\n(1) $h_i \\in \\{ l_1 , l_2 , \\ldots , l_n \\}$,\r\n(2) $h_i^{-1} g^{n_i} h_i \\in H$,\r\n(3) $\\sum_{i=1}^m n_i = |G:H|$,\r\n(4) $V(g)= \\prod (h_i^{-1} g^{n_i} h_i ) H'$.\r\nIf $Q$ is an abelian subgroup of finite order $n$ in $G$ and if $Q \\subseteq Z(G)$ then\r\n$V(g)= g^n, \\forall g \\in G$.  Let $Q \\in S_p(G)$; if $g,h \\in C(Q)$ and $g$ and $H$ are\r\n$G$ conjugate then they are $N(Q)$ conjugate.\r\nLet $Hx_i g^j, 1 \\le i \\le r, 0 \\le j \\le n_i$, cycles of $g$ \r\non $G/H$.\r\n$X= \\{ x_i g^j \\}$ \r\nthen (a) $(g^{n_i})^{x_i^{-1}} \\in H$ for $1 \\le i \\le r$, (b) $\\sum_{i=1}^r n_i= |G:H|$ and\r\n(c) $V(g) = \\prod_{i=1}^r ((g^{n_i})^{x_i^{-1}})^{\\alpha}$.\\\\\r\n\\\\\r\nLet $G$ be a finite group $H \\le G$, $(p, |G:H|)=1, K \\lhd H$, $H/K$ abelian,\r\n$g$ a $p-$element in $H \\setminus K$: $g^{ma} \\in g^m K, \\forall m$, all $a \\in G$ such that\r\n$g^{ma} \\in H$ then $g \\notin G^{(1)}$.\\\\\r\n\\\\\r\n${\\bf p}${\\bf -constraint:}  If $O_{p'}(G)=1$ then $C_G(P) \\subseteq O_p(G)$.\r\n${\\bf \\pi}${\\bf -solvable:}  Normal series consists of either $\\pi'$-groups or a solvable\r\n$\\pi$-groups.  {\\bf Hall-Higman 1.2.3:}  Let $G$ be $\\pi$-solvable and $O_{\\pi'}(G)=1$, then\r\n$C_G(O_{\\pi}(G)) \\subseteq O_{\\pi}(G)$.  Let $P \\in S_p(G)$:\r\n(1) $N_G(P)$ controls fusion on $C_G(P)$.  \r\n(2) If $P \\subseteq Z(N(P))$ then $P$ has a normal $p$-complement.\r\n(3) If $p$ is the smallest prime dividing $|G|$\r\nand $P$ is cyclic then $P$ has a normal $p$-complement.\r\n(4) $P$ has a normal $p$-complement iff $P$ controls its own fusion in $G$.\r\nIf all sylow subgroups are cyclic, $P$ is solvable.  The following are equivalent:\r\n(a) $G$ has a normal $p$-complement; (2) $N_G(X)$ has a normal\r\n$p$-complement for all non-trivial $X \\in p(G)$;\r\n(c) $N_G(X)/C_G(X)$ is a $p$-group $\\forall X \\in p(G)$.  If $A$ is a $p'$-group,\r\nthen $A$ is failthful on $G/\\Phi(G)$.  $X$ is weakly closed in $H$ with respect to $G$ if\r\n$X^G \\cap H = X^H$.  {\\bf Baer:} Let $X$ be a $p$-group of $G$ then either\r\n$X \\le O_p(G)$ or $\\exists g: <X, X^g>$ is not a $p$-group.\r\n\\\\\r\n\\\\\r\n{\\bf Fusion:}\r\nLet $p$ be a prime, $T \\in S_p(G), W \\le T$ with $W$ weakly closed in $T$ with respect\r\nto $G$ and $D=C_G (W)$.  Then $N_G(W)$ controls fusion in $D$.\r\n$P \\in S_p(G)$.  $X \\in p(G)$ is a tame intersection of\r\n$Q, R \\in S_p (G)$ if $X= Q \\cap R$ and $N_Q (X), N_R (X) \\in S_p(N(X))$.\r\n{\\bf Alperin's Fusion Theorem:}\r\nIf $P \\in S_p(G), g \\in G$ and $<A, A^g> \\subseteq P$.  Then \r\nfor $1 \\le i \\le n$, $\\exists Q_i \\in S_p (G)$ and $x_i \\in N(P \\cap Q_i)$ such\r\nthat (1) $g= x_1 x_2 ... x_n$,\r\n(2) $P \\cap Q_i$ is a tame intersection of $P$ and $Q_i$ for each $i$,\r\n(3) $A \\subseteq P \\cap Q_1$ and\r\n$A^{x_1 x_2 ... x_i} \\subseteq P \\cap Q_{i+1}$.  Supporting lemmas:\r\n$R,Q \\in S_p(G)$.  Say $R \\rightarrow Q$ if \r\n$\\exists Q_i \\in S_p(G), X_i \\in N_G(P \\cap Q_i )$\r\nsuch that (1) $P \\cap Q_i$ is tame, (2) $P \\cap R \\le P \\cap Q_1$ and\r\n$P \\cap R)^{x_1 x_2 \\ldots x_i} \\le P \\cap Q_i$ and (3)\r\n$R^x=Q, x= x_1 x_2 \\ldots x_n$.  Sometimes say $R \\rightarrow_x Q$.\r\n(1) $Q \\rightarrow P, \\forall Q \\in S_p(G)$.  (2) $P \\rightarrow P$. \r\n(3) $\\rightarrow$ is transitive.\r\n(4) $S \\rightarrow_x P$, $Q^x \\rightarrow P$ and $P \\cap Q = P \\cap S$\r\nthen $Q \\rightarrow P$.  (5) Assume $P \\cap Q$ is tame and \r\n$S \\rightarrow P, \\forall S \\in S_p(G)$ with $|S \\cap P| > |Q \\cap P|$ and $S \\rightarrow P$\r\nthen $Q \\rightarrow P$.\\\\\r\n\\\\\r\n{\\bf Gaschutz:}  Let $K$ be a normal abelian p-subgroup of a finite group $G$ and let\r\n$P \\in S_p(G)$.  Then $K$ has a complement in $G$ iff $K$ has a complement in $P$.\r\nIf $K$ is an abelian normal subgroup of $G$ with $(|K|,|g:K|)=1$\r\nthen $K$ has a complement.  Proof: Set $\\sigma(x)= \\sum_{y \\in Q} f(x, y)$.\\\\\r\n\\\\\r\n{\\bf Focal Subgroup Theorem:}\r\n$S \\in S_p (G)$ then $S \\cap G' = <x^{-1} y | x,y \\in S, x \\sim _G y>$.\r\nSuppose $P \\in S_p(G)$ and $A_1, A_2 \\lhd G$, if $A_1^g=A_2$, then $\\exists y \\in N_G(P):\r\nA_1^g=A_2$.\r\n{\\bf Burnside Normal $p$-complement}: (proved using transfer):  \r\nIf $P \\in S_p(G)$ and $P \\subseteq Z(N(P))$ then $P$\r\nhas a normal $p$-complement.\r\nIf $P \\in S_p (G), P'=1$ then $P \\cap G' = P \\cap N_G(P)'$.\r\n{\\bf Frobenius Normal $p-$complement:}  The following are equivalent:\r\n(1) $G$ has a normal $p-$complement, \r\n(2) Each $p-$local subgroup of $G$ has a normal $p-$complement,\r\n(3) $Aut_G(P)$ is a $p-$group $\\forall P \\in p(G)$.\r\nIf $H \\le G$ and $H \\cap H^g = 1, \\forall g \\in (G \\setminus H)$ then $G=NH, N \\lhd G$.\r\n\\\\\r\n\\\\\r\n{\\bf Thompson subgroup:} $A(P)$: abelian subgroups of $P$ of maximal order.\r\n$J(P)= <\\{ A | A \\in A(P) \\} >$.  If $O_p(G) \\ne 1$, $G$ is $p$-stable\r\nand $p$-constrained, $p \\ne 2$.  If $P \\in S_p (G)$ then\r\n$G= O_{p'} (G) N(Z(J(P)))$.\r\n{\\bf Thompson Factorization:} Let $G$ be solvable with $F(G)=O_p(G)$, $P \\in S_p(G)$,\r\n$Z= \\Omega_1 (Z(P))$, $V=<Z^G>$, $G^* \\cong G/Z$.  The either (i) $G=N_G(J(P))C(Z)$; or\r\n(ii) $p \\le 3$ and $J(G)^*$ is a direct product of copies of\r\n$SL_2(p)$ permuted by $G$ and $J(P)^* \\in S_p(J(G)^*)$.  Note if\r\n$p=3$ and $G$ has an abelian Sylow $2-$subgroup, so (i) holds.\r\n{\\bf Thompson Normal $p-$Complement:}\r\nLet $p \\ne 2$ and $P \\in S_p(G)$.  Assume $N_G(J(P))$\r\nand $C_G(\\Omega_1(Z(P)))$ have a normal $p-$complement then so does $G$.\r\nBy Burnside transfer, $A \\in SCN(p) \\rightarrow C_G(A)= A \\times Q, Q \\in p'(G)$.\r\nProperty PC: If $G$ is a group in which the normalizer of every $p$ group is\r\n$p$-constrained we say $PC(G)$.\r\n{\\bf Thompson Transitivity Theorem:}  If $PC(G$) \r\nand if $A \\in SCN_3(p)$ then $C_G(A)$ permutes all\r\nmaximal $A$-invariant $q$ groups of $G$, $q \\ne p$. Consequence:\r\nUnder the TTT conditions, if $P \\in S_p(G), A \\in SCN_3(P)$ and $\\forall q \\ne p$,\r\n$P$ normalizes some $A-$invariant $q-$subgroup of $G$; so if $P$ normalizes no\r\n$p'$ subgroup of $G$, neither does $A$.  Used to show the \r\n{\\bf Maximal Subgroup Theorem:}\r\nIf $P \\in S_p(G), SCN_3(P) \\ne \\emptyset, p \\ne 2$ and every element of $N^*(P)$\r\nis $p-$constrained and $p-$stable and $\\exists 1 \\ne H \\lhd P$: $[Q,P]=1$ if $H \\in p'(G)$\r\nand $H^P=H$ then $N^*(P)$ has a unique maximal element.\\\\\r\n\\\\\r\n{\\bf Thompson (from N-group paper):} $G$ is not solvable iff \r\n$\\exists x, y, z \\in G \\setminus \\{1\\}$\r\nwith $(|x|, |y|)=(|y|,|z|)=(|x|,|z|)=1$ such that $xy=z$.  If $G$ is a non-abelian\r\nsimple group all of whose $p-$locals are solvable then $G$ is isomorphic to one\r\nof the following: (1) $PSL_2 (q), q>3$, (2) $Sz(q), q= 2^{2m+1}, m \\ge 1$ or (3)\r\n$A_7$, $PSL(2(3)$, $U_3(3)$, or $M_{11}$.\\\\\r\n\\\\\r\n{\\bf Quadratic action:}\r\nIf $V$ is an abelian $p-$group then $a$ acts quadratically on $V$ if $[V,a,a]=1$ or\r\n$v^{(a-1)^2}=0$.  If $G$ acts quadratically on $V$ then (a) $[v^n,a]=[v,a^n]=[v,a]^n$,\r\n(b) $|V| \\le |C_V(a)|^2$, (c) $G/C_G(V)$ is an elementary abelian $p-$group.\r\nIf $G$ acts on an $F_q$ vector space $W \\ne 0$, $q=p^m$.  Suppose $G=<a,b>$ and\r\n$a,b$ act quadratically on $W$, $G/C_G(W)$ is not a $p-$group, $|ab|=p^ek, k \\mid (p-1)$\r\nthen $\\exists \\varphi: G \\rightarrow SL_2(q)$.  $G$ is {\\bf $p-$stable} if $\\forall a \\in G,\r\n[V,a,a]=1$ implies $a C_G(V) \\in O_p ( G/C_G(V))$.  Let $p \\ne 2$ and $G$ be faithful on $V$.\r\nSuppose (1) $G=<a,b>$ where $a$ and $b$ act quadratically on $V$ and\r\n(2) $G$ is not a $p-$group then (1) the Sylow $2$ subgroups of $G$ are not abelian and\r\n(2) If $Q$ is a normal $p'$-subgroup of $G$ and $[Q,a] \\ne 1$ then $p=3$ and there\r\nis a section of $G$ isomorphic to $SL_2(3)$.  If $p \\ne 2$.  Suppose the action of\r\n$G$ on $V$ is faithful and not $p-$stable then (1) the Sylow $2$-subgroups of\r\n$G$ are non-Abelian and (2) if $G$ is $p-$separable ($G$ is said to be \r\n{\\bf $p$-separable} if two non conjugate elements of $G$ remain non-conjugate in \r\nsome finite $p$-group endomorphic image of $G$.) \r\nthen $p=3$ and there is a section of\r\n$G$ isomorphic to $SL_2(3)$.  Suppose $G$ acts faithfully on $V$ and $E_1 , E_2$ are\r\ntwo subnormal subgroups of $G$ \r\nsuch that $[V,E_1 , E_2 ]=1$ then $[E_1 , E_2 ] \\le O_p (G)$.  Let $G$ be a group\r\nand $C_G(O_p(G)) \\le O_p(G)$ then $V=< \\Omega(Z(S)) | S \\in S_p(G)>$ is an\r\nelementary abelian normal subgroup of $G$ and $O_p(G/C_G(V))=1$.\\\\\r\n\\\\\r\n$Q_8= <\r\n\\left(\r\n\\begin{array}{cc}\r\ni & 0 \\\\\r\n0 & -i \\\\\r\n\\end{array}\r\n\\right),\r\n\\left(\r\n\\begin{array}{cc}\r\n0 & -1 \\\\\r\n-1 & 0 \\\\\r\n\\end{array}\r\n\\right)>$.\r\nLet $m= max \\{ |A|, A \\in {\\cal E}(G) \\}$, ${\\cal A}(G)= \\{A \\in {\\cal E}(G) | |A|=m \\}$\r\nand $J(G)= < A | A \\in {\\cal A}(G) \\}$.  Let $A \\in {\\cal A}(G)$ acts quadratically\r\non $V$ and $A_0 = [V,A] C_A([V,A])$ then $A_0$ is in ${\\cal A}(G)$ and acts quadratically\r\non $V$ and if $[V,A] \\ne 1$ then $[V, A_0 ] \\ne 1$.  {\\bf Thompson factorizable}\r\nwith respect\r\nto $p$ if $G=O_{p'}(G) C_G( \\Omega(Z(S))) N_G(J(S))$.  Let $O_{p'}(G)=1$ and\r\n$V= < \\Omega (Z(S)) | S \\in S_p(G)>$ then $G$ is Thompson factorizable iff\r\n$J(G) \\le C_G(V)$.\\\\\r\n\\\\\r\n{\\bf Weilandt:} If \r\n$A \\lhd \\lhd G$ and $B \\lhd \\lhd G$ then $<A, B> \\lhd \\lhd G$; \r\nif $A \\lhd \\lhd <A,A^g>, \\forall g \\in G$ then $A \\lhd \\lhd G$.\r\n{\\bf Quasi-simple:} $L'=L$ and $L/Z(L)$ is simple.  $L$ is a {\\bf component} of $H$ if\r\n$L \\lhd \\lhd H$ and $L$ is quasi-simple.  Let $Comp(G)= \\{H: H$ is a component of $G \\}$.\r\n$E(G)= <Comp(G)>$ where $H$ is a component of $G$.  \r\nIf $K \\in Comp(G), U \\lhd \\lhd G$ then $K \\subseteq U$ or $[K,U]=1$.\r\n{\\bf Generalized Fitting Subgroup:} $F^*(G)=F(G)E(G)$. $C_G(F^*) \\subseteq F^*(G)$. \r\nLet $X/Z(X)$ be a non-abelian simple group then $X=X'Z(X)$ and $X'$ is\r\nquasi-simple.  Let $L \\in Comp(G)$, $H$ and $L-$ invariant subgroup, then\r\n(a) $L \\in Comp(H)$ or $[L,H]=1$, (b) If $H$ is solvable, $[L,H]=1$.\r\nIf $E^*=E(G)/Z(E(G))$ then (a)$Z=Z(L): L \\in Comp(G)>,$ \r\n(b) $E^*$ is a direct product of $<L: L \\in Comp(G)>$,\r\n$E$ is a central product of its components.\r\n$G$ is of {\\bf characteristic $p-$type}\r\nif  $F^*(H)=O_p(H)$ for every $p-$local, $H$ (Groups of Lie type over characteristic\r\n$p$ are, for example.).\r\n$G$ is of characteristic $p-$type if $P \\in p(G), N= N_G(P) \\rightarrow F^*(N)=O_p(N)$.\r\n$PSL_n(p^m)$ is of characteristic $p-$type.  Let $G$ be a non-abelian simple group,\r\n$G$ is of characteristic $p-$type iff $F^*(N(P))= O_p(N(P))$ for every maximal $p-$local.\r\nIf $F^*(G)$ is a $p-$group then so is $F^*(N(P)), \\forall P \\in p(G)$ (use $P \\times Q$).\r\n\\\\\r\n\\\\\r\n{\\bf Amalgams:} $P_1, P_2 \\le G$, $|P_i|< \\infty$.  Construct a graph $\\Gamma(G, P_1, P_2)=\\Gamma$\r\nas follows: \r\n$\\Gamma$ has verticies consisting of right cosets of $P_1$ and $P_2$; the verticies\r\n$P_i g_j$ and $P_n g_m$ are\r\njoined by an edge if \r\n$P_i g_j \\ne P_n g_m$ and\r\n$P_i g_j \\cap P_n g_m \\ne \\emptyset$.  $\\Delta(\\alpha)$ denotes the verticies\r\nadjacent to $\\alpha$.  $G$ act on graph by right multiplication on cosets.  \r\n$G \\rightarrow Aut(\\Gamma)$.  $\\Gamma$ is connected iff $G= <P_1 , P_2>$.  {\\bf Theorem:}\r\n(a) $G$ has $2$ orbits.  Every vertex stabilizer  $G_{\\alpha}$ is a $G-$conjugate of\r\n$P_1$ or $P_2$. (b) $G$ acts transitively on edges of $\\Gamma$; every edge stabilizer\r\nin $G$-conjugate of $P_1 \\cap P_2$.  (c) $G$ acts transitively on $\\Delta(\\alpha)$.\r\n$|\\Delta(\\alpha):\\Delta(\\alpha, \\beta)|= |G_{\\alpha}: G_{\\alpha, \\beta}|, \\beta \\in \\Delta(\\alpha)$.\r\n(d) $(P_1  \\cap P_2)_G$ (the largest normal subgroup of $G$ in $P_1 \\cap P_2$)\r\nis the kernal of the action of $G$ on $\\Gamma$. {\\bf Condition} ${\\cal A}$:  Let $G$ be a\r\nfinite group generated by \r\n$P_1, P_2$,\r\n$T= P_1 \\cap P_2$ satisfying: $C_{P_i}(O_2(P_i)) \\le O_2(P_i)$, $T \\in S_2(P_i)$,\r\n$T_G=1$, $P_i/O_2(P_i) \\approx S_3$ and $[\\Omega(Z(T)), P_i] \\ne 1$.  {\\bf Goldschmidt:}\r\nIf ${\\cal A}$ holds either (i) $P_1 \\approx P_2 \\approx S_4$ or \r\n(ii) $P_1 \\approx P_2 \\approx C_2 \\times S_4$.\r\n\\\\\r\n\\\\\r\n{\\bf Classification by \r\ncentralizers of involutions:}\r\nBrauer proved if $G=PSL_3(q), q = 3 \\jmod{4}$ and \r\n$x \\in Inv(G)$ then $C_G(t) \\cong GL_2(q)$\r\nand that the converse is true for $q>3$; if $q=3$ other possibilities are $PSL_3(3)$ and\r\n$M_{11}$.  Classifications fall into two steps: (I) Given $H= C_G(t), t \\in Inv(G)$, find\r\n$|G|$ and its structure and (II) find $C(t)$ for simple groups.   Note that all\r\nsimple groups are determined by their character table. Step (I)\r\nconsists of two steps:\r\n(A) $\\forall v \\in Inv(H)$, determine $C_G(v)$ and the fusion patterns of $Inv(C_G(v))$,\r\n(B) if $G$ has more than one conjugacy class, this determines the order, if not we must\r\nexamine all if $H$ using characters.  \r\nLet $L= SL_n(q), G=PSL_n(q) = L/Z(L)$, \r\n$t \\in Inv(G)$ corresponds to $T \\in L$ with $T^2= \\lambda I_n$ putting \r\n$Z= \\{ \\lambda I_n, \\lambda^n=1 \\}, d= |Z|= (n,q-1)$ and $C= \\{X \\in L: XT= \\mu TX \\}$,\r\n$C_G(t)= C/Z$.  Let $p \\ne 2$ and the eigenvalues of $T$ be $\\rho, -\\rho$ then $T$\r\nis conjugate to\r\n$\\left(\r\n\\begin{array}{cc}\r\n\\rho I_r & 0 \\\\\r\n0 & - \\rho I_s \\\\\r\n\\end{array}\r\n\\right)$,\r\nor\r\n$\\left(\r\n\\begin{array}{cc}\r\n0 & I_m \\\\\r\n- \\lambda I_m & 0 \\\\\r\n\\end{array}\r\n\\right)$,\r\ndepending on whether the minimum polynomial is $(x+ \\rho)(x- \\rho)$ or $(x^2- \\lambda)$\r\nwhich depends on whether the eigenvalue is in $GF(q)$ or $GF(q^2) \\setminus GF(q)$.\r\nLet $X \\in C$ with \r\n$X=\r\n\\left(\r\n\\begin{array}{cc}\r\nX_1 & X_2 \\\\\r\nX_3 & X_4 \\\\\r\n\\end{array}\r\n\\right)$, so either \r\n$X_2=X_3=0$ and $det(X_1) det(X_4)=1$ or\r\n$r=s$ and\r\n$X_1=X_4=0$ and $det(X_2) det(-X_3)=1$; let $\\delta: X \\mapsto det(X_1), K= ker(\\delta)$\r\nthen $K= SL_r(q) \\times SL_s(q)$.  Put $E=KZ/Z$, $E \\lhd C/Z$ and $E= K/(K \\cap Z)$ and\r\n$E$ is a central product.\\\\\r\n\\\\\r\n{\\bf Centralizers of the classical groups:}\r\nLet $G= PSL_n(q)$, $q$ odd, $t \\in Inv(G)$,  \r\n(1) if $n$ is odd $\\exists N \\lhd C(t)$ with\r\n$N$ the minimal central product of $SL_r(q)$ and $SL_s(q)$, $r+s=n$ (type *) and both\r\n$C(t)/N$ and $Z(N)$ are cyclic groups with orders dividing $q-1$;\r\n(2) if $n$ is even there is a centralizer as above and centralizers of two additional\r\ntypes: \r\n(A) $\\exists C_0 : |C(t):C_0|=2$ and $E \\lhd C(t)$ of type * with $r=s$ and\r\n$C(t)/E$ is {\\bf dihedral} and $C_0/Z$ and $Z(E)$ are cyclic --- there is an element of\r\norder 2 outside $C_0$ that interchanges the factors of $E$,\r\n(B) $\\exists C_0 : |C(t):C_0|=2$ and $E \\lhd C(t)$ of type * with $r=s$ and\r\n$E/Z(E) \\cong PSL_r(q^2)$ and $Z(E)$ is cyclic with order dividing $q+1$ and\r\n$C(t)/E$ is dihedral of order $q+1$ or $2(q+1)$; further, there is an element of order\r\ntwo in $C(t) \\setminus C_0$ which transforms elements in $E/Z(E)$ like the element\r\nof order $2$ in the Galois group of $GF(q^2)/GF(q)$.\r\nIf $G= PSp_{2m}(q)$ with $q$ odd and $t \\in Inv(G)$ then either\r\n(1) $C(t)$ is a minimal central product of \r\n$Sp_{2r}(q)$ and\r\n$Sp_{2s}(q)$ with $r+s=m, r \\ne s$, or\r\n(2) $\\exists C_1 \\lhd C(t)$ with $C_1$ a minimal central product of two copies\r\nof $Sp_{2l}(q), 2l=m$ and there is an element of order two in\r\n$C(t) \\setminus C_1$ that interchanges the two, or \r\n(3) $\\exists C_1 \\lhd C(t)$ with $C_1 \\cong GL_m(q)/\\{ \\pm I \\}$\r\nand there is an element of order two in\r\n$C(t) \\setminus C_1$ that corresponds to $A \\mapsto ^tA^{-1}$ and $q= 1 \\jmod{4}$, or\r\n(4) $\\exists C_1 \\lhd C(t)$ with $C_1 \\cong U_m(q)/\\{ \\pm I \\}$\r\nand there is an element of order two in\r\n$C(t) \\setminus C_1$ that corresponds to $A \\mapsto A^{\\tau}$ and $q= 3 \\jmod{4}$, \r\n$\\tau$ the generator of the Galois group.\r\nIf $G= PSU_{n}(q)$ with $q$ odd and $t \\in Inv(G)$ then either\r\n(1) $\\exists N \\lhd C(t)$ with $N$ a minimal central product of \r\n$SU_{r}(q)$ and\r\n$SU_{s}(q)$ with $r+s=m, r \\ne s$, both $C(t)/N$ and $Z(N)$ are cyclic with orders\r\ndividing $q+1$, \r\n(2) if $n$ is even there is a centralizer as above and centralizers of two additional\r\ntypes: \r\n(A) $\\exists C_0 : |C(t):C_0|=2$ and $E \\lhd C(t)$ of type * with $r=s$ and\r\n$C(t)/E$ is dihedral and $C_0/Z$ and $Z(E)$ are cyclic --- there is an element of\r\norder 2 outside $C_0$ that interchanges the factors of $E$,\r\n(B) $\\exists C_0 : |C(t):C_0|=2$ and $E \\lhd C(t)$ with $r=s$ , $Z(E)$ cyclic of order\r\ndividing $q-1$ and\r\n$E/Z(E) \\cong PSL_r(q^2)$ \r\nand there is an element of order two in\r\n$C(t) \\setminus C_1$ that corresponds to $A \\mapsto ^t(A^{\\tau})^{-1}$ \r\n$\\tau$ the generator of the Galois group.\r\nIf $G= P\\Omega_{n}(q)$ with $q$ odd and $t \\in Inv(G)$ then either\r\n(1) $\\exists E \\lhd C(t)$ with $C(t)/E$ solvable, $E'=E$ and $E$ is either\r\n$SL_{m}(q)/ \\{ \\pm I \\}$ and\r\n$SU_{m}(q)/ \\{ \\pm I \\}$  ($2m=n$ in both cases) or a central product of \r\n$\\Omega_r(q)$ and $\\Omega_s(q)$.  For $G= A_n$, let $H_1= \\Sigma_k, H_2= Z_2 \\wr \\Sigma_l$\r\nand $C(t) = H_1 \\times H_2$ with $(\\sigma, \\rho) \\in C(t), sign(\\sigma)= sign(\\rho)$.\\\\\r\n\\\\\r\nSince $C(F^*(G)) \\subseteq F^*(G)$, $G \\rightarrow Aut(G)$ has kernel $Z(F^* (G))$; \r\nfurther, $F^*(G)$ is uncomplicated and its embedding in $G$ is well behaved.  \r\nWant to study relationship\r\nof $F^*(G)$ and its $p-$locals.  Hard when $F^*(G)$ is a $p-group$ but then we\r\ncan use Thompson factorization.  Thompson $p-$complement\r\n$\\rightarrow$ nilpotence of Frobenius kernel.\\\\\r\n\\\\\r\n{\\bf Signalizers:} $r$, prime, $G$ finite and $A$ an abelian $r-$subgroup of $G$. An\r\n$A-$signalizer is a map $\\theta: A^{\\#} \\rightarrow {\\cal S}$ where ${\\cal S}$ is a\r\nset of $r'$ $A-$invariant subgroups such that $a,b \\in A^{\\#}$ and $\\theta(a) \\le C_G (a)$\r\nand\r\n$\\theta(a) \\cap C(b) \\le \\theta(b)$.  \r\n$\\theta$ is complete if $\\exists \\theta(G)$ an $r'$, \r\n$A-$invariant subgroup such that\r\n$\\theta(a)= C_{\\theta(G)}(a)$ for each $a \\in A^{\\#}$.  $\\theta(a)=C_X(a)$ is one such\r\nfunction; if $m(A)  \\ge 3$ then every $A-$signalizer functor is complete.  Under these\r\nconditions, for a solvable $A-$signalizer, ${\\cal N}_{\\theta}(A)$ has a unique maximal\r\nelement.  Goldschmidt proved this for solvable signalizer functors.\\\\\r\n\\\\\r\nLet $p,q \\in \\pi(A)$ then for $S \\subseteq A$. (1) $p \\ne 2$, $S_p(A) \\rightarrow$ $S$ is\r\ncyclic.  (2) $S \\in S_2(A)$ is cyclic or quaternion.  \r\n(3) $|S|=pq \\rightarrow S$ is cyclic.\r\n(4) $|S|= 1 \\jmod{2} \\rightarrow S$ is metacyclic.\\\\\r\n\\\\\r\nIf $x,y$ are two involutions in $G$ then $<x, y>$ is dihedral of order $2|xy|$.\r\nLet $G$ be even order with $Z(G)=1$, let $m$ be the number of involutions in $G$\r\nand $n=|G|/m$.  Then $G$ possesses a proper group of order at most $2 n^2$.\\\\\r\n\\\\\r\nLet $G$ be a simple group of even order,\r\n$t$ and involution and $n= |C_G (t)|$.  Then $|G| \\le (2n^2)!$. From this we get:\r\n{\\bf Brauer-Fowler:}  Let $H$ be a finite group.   There are at most a finite number\r\nof finite simple groups with $H \\cong C_G (t)$.\\\\\r\n\\\\\r\n{\\bf Feit-Thompson:}  The only finite simple groups or odd order are\r\n${\\mathbb Z}_p, p\\ne 2$. The proof follows the CN classification.\\\\\r\n\\\\\r\n{\\bf Thompson Order Formula:}\r\nAssume $G$ has more than two congugacy classes of involutions\r\n$\\{ {x_i}^G \\}$ and let $n_i$ be the number of ordered pairs $(u, v)$ with\r\n$u \\in {x_1}^G, v \\in {x_2}^G$ and $x_i \\in < uv>$ then\r\n$|G|= |C(x_1 )| |C(x_2 )| \\sum_{i=1}^k {\\frac {n_i} {|C(x_i )|}}$.\\\\\r\n\\\\\r\nLet $\\Omega$ be a collection of subgroups.  Define ${\\cal D} (\\Omega)$ as the graph\r\nformed by joining $A,B \\in \\Omega$ if $[A,B]=1$. If $k>0$ let, \r\n${\\cal E}^p_k (G)$\r\nbe the elementary abelian subgroups of $p$-rank at least $k$. $G$ is said to be\r\n$k-connected$ for prime $p$ if ${\\cal D} ( {\\cal E}^p_k (G))$\r\nis connected.\\\\\r\n\\\\\r\nIf $G$ is a non-abelian finite simple group\r\nwith $m_2(G) \\le 2$ then either (1) a Sylow 2-group is either dihedral, semi-dihedral\r\nor $Z_{2^n} \\; wr \\; Z_2$ and\r\n$G \\cong L_2(q)$,\r\n$G \\cong L_3(q)$,\r\n$G \\cong U_3(q)$ $q, $odd, or $M_{11}$; or,  (2)\r\n$G \\cong U_3(4)$.\r\nNote that $Q_8 \\in S_2(SL_2(3))$ and \r\n$\\left(\r\n\\begin{array}{cc}\r\n2 &  0 \\\\\r\n0 &  2 \\\\\r\n\\end{array}\r\n\\right)$ is the unique involution.\\\\\r\n\\\\\r\nIf $G$ is a non-abelian finite simple group\r\nwith $m_2(G) > 2$ and assume $G$ has a proper 2-generated 2-core, then either\r\n$G$ is a group of Lie type of characteristic 2 and Lie rank 1 or $G \\cong J_1$.\\\\\r\n\\\\\r\n{\\bf Glauberman $ZJ$:}  If $C_G(O_p(G)) \\le O_p(G)$ and the action of\r\n$G$ on its chief factors of $G$ is $p-$stable then $G=N_G(Z(J(S)))$. Every group\r\nadmitting a fixed-point-free automorphism of prime order is nilpotent.\r\n{\\bf Glauberman's $Z^*$ Theorem:}\r\nLet $G$ be a finite group and $t$ and involution in $G$ which is weakly closed in\r\n$C(t)$.  Then $t^* \\in Z(G^*)$  where $G^*= G/O_{2'} (G)$.\\\\\r\n\\\\\r\n{\\bf $B_p$ property:} Suppose $O_{p'}(G)=1$ and $x \\in G, |x|=p$ then\r\n$O_{p',E}(C(x))= O_{p'}(C(x))E(C(x))$.\r\nA {\\bf standard subgroup} for the prime $p$ is a group $H=C_G(x), |X|=p$ such that\r\n$H$ has a unique component, $L$, and $C_G(L)$ has a cyclic Sylow $p-$group.\r\n{\\bf Component Theorem:}\r\nLet $G$ be a finite group with $F^*(G)$ satisfying the $B_2$ property and with\r\nin involution, $t$ such that $O_{2', E} (C(t)) \\ne O_{2'} (C(t))$ then $G$ possesses\r\na standard subgroup for the prime $2$.\r\n{\\bf Standard Form} problem for $(L,r)$:   Determine all finite groups, $G$, possessing a \r\nstandard subgroup $H$ for the prime $r$ with $E(H) \\cong L$. {\\bf Aschbacher's program:}\r\nLet $G$ be a minimal counter-example to the classification theorem and assume $G$ \r\nis generic of even characteristic.  \r\nThen one of the following holds: (1) $G$ possesses a standard subgroup for some\r\n$p \\in \\sigma(G)$; (2) there is an involution $t \\in G$ such that $F^* (C(t))$ is a \r\n2-group of symplectic type; or, (3) $G$ is in the uniqueness case.\\\\\r\n\\\\\r\nIn real simple groups $O_{2'}(C(t))$ is cyclic and almost central.\r\n{\\bf Bender's Theorem:} For any group $X$, we have $C_X(F^*(X)) \\le F^*(X)$ and if\r\n$W \\lhd X$ and $C_X(W) \\le W$ then $E(X) \\le W$.  If $O_{p'}(X)=1$ then\r\n$F(X)=O_p(X)$ and every component of $X$ has order divisible by $p$ so\r\n$X$ is $p$-constrained iff $E(X)=1$ or, equivalently, $C_X(O_p(X)) \\le O_p(X)$.\r\nLet ${\\overline X}= E(X/O_{p'}(X))$, \r\n$L$ is a minimal normal subgroup subject to ${\\overline L}= E({\\overline X})$,\r\n${\\overline {L_i}}$ is a component of $E({\\overline X})$, $L_i= O^{p'}(L_i)$,\r\n$[L_i, L_i]= L_i$ and $[L_i, L_j] \\le O_{p'}(X)$, \r\n$L$ is called the {\\bf $p$-layer}.  $F^*(X)$ controls embedding of $X$ of\r\n$p'$-cores and the $p$-layer of every $p$-local.  $O_{\\pi}((X/O_{\\pi}(X)))=1$.\r\nIf $O_{\\pi}(X)=1$ then $F(X)$ is divisible by $p \\in \\pi$ and every component is\r\ndivisible by some $p \\in \\pi'$.\\\\\r\n\\\\\r\nRecall signalizers.  The idea is that\r\n$A-$invariant $p'$ subgroups of $G$ can be glued into a single $p'$\r\nsubgroup $\\theta(G,A)$ which is either normal or strongly $p-$embedded in $G$.\r\n$M \\subseteq G$ is {\\bf strongly $p-$embedded} if $p | |M|$ but $p$ does not divide\r\n$|M \\cap M^g |$ for $g \\in G-M$.  {\\bf Tightly embedded:} $p=2$. If $M$ is strongly\r\nembedded, $G$ fixes one point when acting on the cosets of $M$.\r\nBender identified all simple groups with strongly 2-embedded subgroups, namely,\r\n$SL_2(2^n), SZ(2^n), PSU_3(2^n)$.  No simple group of\r\n$p-rank \\ge 3$ has a strongly $2-$embedded $2'$ local subgroup.\\\\\r\n\\\\\r\n{\\bf Bender:} Let $G$ be a finite simple group and $S \\in S_2(G)$ then one of the following holds:\r\n(a) $S$ is dihedral, (b) $S$ is semidihedral, (c) $G$ has a strongly embedded subgroup,\r\n(d) $S$ has a non-cyclic characteristic elementary abelian subgroup, $A$, and\r\n$E=N_G(A)$ has conjugacy classes, $<z_i^G>$, that do not fuse in $G$ such that\r\n$G= <E, C_G(z_i )>$.  If $G$ is a finite simple group and\r\n$H<G$ with ${\\mathbb Z}(H)$ of even order and $h \\approx C_H(z)$ then $G$ is said\r\nto be of $H$-type.  Note we can construct a faithful transitive permutation representation\r\nof $G$ given a presentation of $H$.  A group has an $H$-satellite if there are non-isomorphic\r\ngroups of $h$-type.\r\nA finite simpe group, $G$, is uniquely determined by $C_H(z)$ for a $2-$central\r\ninvolution, $z$, if $G$ does not have any non-isomorphic $H$-satellites.\r\n\\\\\r\n\\\\\r\n{\\bf Netto:}  Let $x,y \\in S_n$ be selected randomly.  $Pr[<x,y>=S_n]= {\\frac 3 4}$.  \r\n{\\bf Irreducible\r\ncharacters of the symmetric group} $S_n$: $n= n-m, \\mu_1, \\ldots , \\mu_j$, $d_{n}(\\mu)$ is the dimension of the\r\nirreducible character determined by: $l_{j+1}= \\mu_j$, $l_j= \\mu_{j-1}+1$, $l_{j-1}= \\mu_{j-2}+2$,\r\n\\ldots, $l_1= n-m+j$.  $d_n(\\mu)= \\prod_{s>r} (l_r-l_s)$.\r\n\r\n", "meta": {"hexsha": "4baf92426581cc2ab003732b5aa31aedc4bf5a26", "size": 70570, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "science/math3.tex", "max_stars_repo_name": "jlmucb/class_notes", "max_stars_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "science/math3.tex", "max_issues_repo_name": "jlmucb/class_notes", "max_issues_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "science/math3.tex", "max_forks_repo_name": "jlmucb/class_notes", "max_forks_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.410871303, "max_line_length": 112, "alphanum_fraction": 0.5930423693, "num_tokens": 28937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7492599660768503}}
{"text": "\n\\subsection{Asymptotic normality}\n\nMany statistics are asymptotically normally distribution.\n\nThis is a result of the central limit theorem.\n\nFor example:\n\n\\(\\sqrt n S\\rightarrow^d N(s, \\sigma^2) \\)\n\n\\subsubsection{Confidence intervals for asymptotically normal statistics}\n\nWe have the mean and variance, and know the distribution. This allows us to calculare confidence intervals.\n\n", "meta": {"hexsha": "33a2091c765762480967ab5687a8a3f35c06ab07", "size": 385, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/stats/03-03-normal.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/stats/03-03-normal.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/stats/03-03-normal.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0625, "max_line_length": 107, "alphanum_fraction": 0.7922077922, "num_tokens": 87, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7492599623550407}}
{"text": "\\section{The Real and Complex Numbers}\r\n\\begin{definition}\r\n    The real numbers is a set $\\mathbb R$ such that\\\\\r\n    1. The rational numbers $\\mathbb Q$ is contained in $\\mathbb R$.\\\\\r\n    2. $\\mathbb R$ is an ordered field.\\\\\r\n    3. It satisfies the least-upper-bound property.\r\n\\end{definition}\r\n$\\mathbb R$ is a field if it has two binary operations $+,\\cdot$ such that $(\\mathbb R,+),(\\mathbb R\\setminus\\{0\\},\\cdot)$ are abelian groups and $\\forall a,b,c\\in\\mathbb R,(a+b)c=ac+bc$.\r\n\\begin{example}\r\n    1. $\\mathbb Q$ is a field.\\\\\r\n    2. $\\mathbb Z/p\\mathbb Z$ is a field for $p$ prime and no otherwise.\r\n\\end{example}\r\nAn ordered field means a field such that there is a total order $<$ on $\\mathbb R$ such that $a>b\\implies a+c>b+c$ and $a>0,b>0\\implies ab>0$.\r\n\\begin{example}\r\n    $\\mathbb Q$ is an ordered field but $\\mathbb Z/p\\mathbb Z$ is not.\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $X$ be an ordered set and $A\\subset X$.\r\n    We say $A$ has an upper bound in $X$ if $\\exists a\\in X,\\forall x\\in A,x\\le a$.\r\n    We call $a$ an upper bound for $A$.\r\n    If that is true, we say $A$ is bounded above.\\\\\r\n    We say $a\\in X$ is the least upper bound, or supremum of $A$ if it is an upper bound and $a'\\ge a$ whenever $a'$ is an upper bound of $A$.\r\n    So we write $a=\\sup A$ since it is obvious that supremums are unique.\r\n\\end{definition}\r\n\\begin{definition}\r\n    We say $X$ has the LUBP if any nonempty subset of $X$ that is bounded above has a supremum.\r\n\\end{definition}\r\nNote that $\\mathbb Q$ does not have LUBP by considering $\\{x\\in\\mathbb Q:x^2<2\\}$.\\\\\r\nThese definitions can be easily extended to lower bounds and greatest lower bounds and greatest-lower-bound property.\r\nWe write $\\inf$ or infermum for the greatest lower bound.\r\n\\begin{proposition}\r\n    1. Given the rational numbers, we can construct the real numbers satisfying the axioms.\r\n    2. If $X$ is an ordered field that satisfies the LUBP, then there is an isomorphism between ordered fields $\\phi:X\\to\\mathbb R$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Partially obvious.\r\n    Some might be covered later.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    1. The natural numbers is not bounded above.\\\\\r\n    2. $\\forall x\\in\\mathbb R,\\exists N\\in\\mathbb N,N>x$.\\\\\r\n    3. $\\forall x\\in\\mathbb R_{>0},\\exists N\\in\\mathbb N,1/N<x$.\\\\\r\n    4. $\\forall x,y\\in\\mathbb R,x<y\\implies\\exists q\\in\\mathbb Q,x<q<y$.\\\\\r\n    5. $\\forall x\\in\\mathbb R_{>0},\\exists y\\in\\mathbb R,y^2=x$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    All obvious.\r\n\\end{proof}\r\n\\begin{definition}\r\n    The complex numbers $\\mathbb C$ is\r\n    $$\\left\\{ z\\in M_{2\\times 2}(\\mathbb R):z=\\begin{pmatrix}\r\n        a&b\\\\\r\n        -b&a\r\n    \\end{pmatrix}\\right\\}$$\r\n    which becomes a field under matrix addition and multiplication.\r\n    Let $1=I$ and $i=\\left(\\begin{smallmatrix}\r\n        0&1\\\\\r\n        -1&0\r\n    \\end{smallmatrix}\\right)$, then we have an obvious bijection $\\mathbb R^2\\to\\mathbb C$ with $(a,b)\\mapsto a+bi$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    If $z=a+bi$, we set the modulus, or norm, by $|z|=\\sqrt{\\det z}=\\sqrt{a^2+b^2}$.\r\n\\end{definition}\r\nNote that $|zw|=|z||w|$.\r\n\\begin{proposition}\r\n    $\\forall z,w\\in\\mathbb C,|z+w|\\le |z|+|w|$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}", "meta": {"hexsha": "b814d20246714cbda1e80419750c601acc32aaee", "size": 3266, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/real.tex", "max_stars_repo_name": "david-bai-notes/IA-Analysis-I", "max_stars_repo_head_hexsha": "4209ac010e35cfcd72799530eeed7d96d6706a3c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1/real.tex", "max_issues_repo_name": "david-bai-notes/IA-Analysis-I", "max_issues_repo_head_hexsha": "4209ac010e35cfcd72799530eeed7d96d6706a3c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1/real.tex", "max_forks_repo_name": "david-bai-notes/IA-Analysis-I", "max_forks_repo_head_hexsha": "4209ac010e35cfcd72799530eeed7d96d6706a3c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.6571428571, "max_line_length": 188, "alphanum_fraction": 0.6500306185, "num_tokens": 1085, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7492599578498647}}
{"text": "\\subsection{Complex numbers}\\label{subsec:complex_numbers}\n\n\\begin{definition}\\label{def:set_of_complex_numbers}\n  We give a few equivalent definition of the \\hyperref[def:field]{field} \\( \\BbbC \\) \\term{complex numbers}. Informally, there are numbers of the form \\( a + bi \\), where \\( a, b \\in \\BbbR \\) and \\( i = \\sqrt{-1} \\). In order to find the multiplicative inverse of the nonzero polynomial \\( a + bi \\), we assume that division is well-defined and proceed as follows:\n  \\begin{equation}\\label{def:set_of_complex_numbers/inverse}\n    \\frac 1 {a + bi} = \\frac {a - bi} {(a + bi)(a - bi)} = \\frac{a - bi}{a^2 + b^2}.\n  \\end{equation}\n\n  The closest to this informal definition is \\fullref{def:set_of_complex_numbers/polynomials}.\n\n  \\begin{thmenum}\n    \\thmitem{def:set_of_complex_numbers/polynomials} The most \\enquote{algebraic} way to define complex numbers is as the \\hyperref[def:polynomial_algebra]{polynomial} quotient \\hyperref[thm:polynomial_quotient_rings_equinumerous_with_module_of_polynomials]{ring}\n    \\begin{equation*}\n      \\BbbC \\coloneqq \\BbbR[X] / \\braket{X^2 + 1}.\n    \\end{equation*}\n\n    Elements of \\( \\BbbC \\) can be identified with real polynomials of the form \\( bX + a \\). See \\fullref{ex:polynomial_quotient_rings_gaussian_integers} for a broader discussion.\n    Define \\( i \\coloneqq X \\). We have\n    \\begin{equation*}\n      i \\cdot i = X^2 = -1 \\pmod {X^2 + 1}.\n    \\end{equation*}\n\n    Thus, \\( i \\) is indeed the square root of \\( -1 \\). We will write\n    \\begin{equation*}\n      a + bi = bX + a.\n    \\end{equation*}\n\n    It is shown in \\fullref{ex:polynomial_quotient_rings_gaussian_integers} that multiplication modulo \\( X^2 + 1 \\) gives\n    \\begin{equation}\\label{def:set_of_complex_numbers/polynomials/multiplication}\n      (bX + a) (dX + c) = (ad + bc)X + (ac - bd) \\pmod {X^2 + 1}.\n    \\end{equation}\n\n    The multiplicative inverse of \\( a + bi \\) is then indeed \\fullref{def:set_of_complex_numbers/inverse}.\n\n    The canonical embedding \\( \\iota: \\BbbR \\to \\BbbC \\) is then the standard polynomial embedding.\n\n    \\thmitem{def:set_of_complex_numbers/matrices} The complex numbers can also be defined as the matrix \\hyperref[def:matrix_algebra]{ring}\n    \\begin{equation*}\n      \\BbbC \\coloneqq \\left\\{\n      \\begin{pmatrix}\n        a  & b \\\\\n        -b & a\n      \\end{pmatrix}\n      \\colon a, b \\in \\BbbR \\right\\}\n    \\end{equation*}\n    with the usual matrix multiplication. The canonical embedding \\( \\iota: \\BbbR \\to \\BbbC \\) is then\n    \\begin{equation*}\n      \\iota(a) \\coloneqq \\begin{pmatrix}\n        a & 0 \\\\\n        0 & a\n      \\end{pmatrix}\n    \\end{equation*}\n\n    \\thmitem{def:set_of_complex_numbers/tuples} Finally, we can define \\( \\BbbC \\) is the \\hyperref[def:algebra_over_semiring]{algebra} obtained from the vector space \\( \\BbbR^2 \\) with the multiplication operation emulating \\fullref{def:set_of_complex_numbers/polynomials/multiplication} as\n    \\begin{balign*}\n       & \\cdot: \\BbbC \\times \\BbbC \\to \\BbbC                     \\\\\n       & (a, b) \\cdot (c, d) \\coloneqq (ac - bd, ad + bc).\n    \\end{balign*}\n\n    The canonical embedding \\( \\iota: \\BbbR \\to \\BbbC \\) is then\n    \\begin{equation*}\n      \\iota(a) \\coloneqq (a, b).\n    \\end{equation*}\n  \\end{thmenum}\n\n  We define the unary \\term{complex conjugation} operation as \\( \\overline{a + bi} \\coloneqq a - bi \\) and the \\term{\\hyperref[def:absolute_value]{absolute value}} as\n  \\begin{equation*}\n    \\abs{a + bi} \\coloneqq \\sqrt{a^2 + b^2}.\n  \\end{equation*}\n\n  For a complex number \\( z = a + bi \\) we denote\n  \\begin{balign*}\n    \\real z = a &  & \\imag z = b\n  \\end{balign*}\n  and call them the \\term{real} and \\term{imaginary} parts of \\( z \\).\n\\end{definition}\n\n\\begin{theorem}[Fundamental theorem of algebra]\\label{thm:fundamental_theorem_of_algebra}\n  The field \\( \\BbbC \\) of complex numbers is algebraically \\hyperref[def:algebraically_closed_field]{closed}.\n\\end{theorem}\n\n\\begin{theorem}\\label{thm:linear_functionals_over_c}\n  Let \\( X \\) be a \\hyperref[def:vector_space]{vector space} over \\( \\BbbC \\). There is a bijection between the real-valued and the complex-valued linear functionals on \\( X \\).\n\\end{theorem}\n\\begin{proof}\n  Let \\( c: X \\to \\BbbC \\) be a complex-valued linear functional. Denote \\( a(x) \\coloneqq \\real c(x) \\) and \\( b(x) \\coloneqq \\imag c(x) \\). Then \\( a: X \\to \\BbbR \\) and \\( b: X \\to \\BbbR \\) are linear functionals. We will show that \\( a(x) \\) uniquely determines \\( b(x) \\) and hence \\( c(x) \\).\n\n  Note that \\( c(ix) = a(ix) + i b(ix) = i a(x) - b(x) \\). Therefore, \\( b(x) = a(ix) - c(ix) \\) and\n  \\begin{equation*}\n    c(x) = a(x) + i (a(ix) - c(ix)) = a(x) - a(x) + c(x) = c(x).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{remark}\\label{rem:linear_functionals_over_c}\n  \\Fullref{thm:linear_functionals_over_c} allows us to identify the dual space \\( X* \\) of a complex vector space \\( X \\) with \\( \\hom(X, \\BbbR) \\) in the case of an algebraic \\hyperref[def:dual_vector_space]{dual} or with the corresponding subspace in the case of a \\hyperref[def:continuous_dual_space]{continuous dual space}.\n\n  This allows us to reuse some of the theory for real vector spaces, for example hyperplane \\hyperref[def:hyperplane_separation]{separation}.\n\\end{remark}\n", "meta": {"hexsha": "52b639a8732e27ab5c7022c8b741c2c744cc62dd", "size": 5222, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/complex_numbers.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/complex_numbers.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/complex_numbers.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.7474747475, "max_line_length": 364, "alphanum_fraction": 0.6654538491, "num_tokens": 1704, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.749259954128055}}
{"text": "\\section*{Distributions}\n\n\\subsection{Bernoulli}\n\n\\begin{gather*}\nP(X = 1) = p \\\\\nP(X = 0) = 1 - p = q \\\\\nE(X) = p \\\\\nE \\left[ X^2 \\right] = P(X=1) \\cdot 1^2 + P(X=0) \\cdot 0^2 = p \\cdot 1 + q \\cdot 0 = p = E [X] \\\\\n\\mathcal{D}[X] = E[X^2] - E[X] = p - p ^2 = p(1-p) = pq\n\\end{gather*}\n\n\\subsection{Binomial}\n\n\\begin{gather*}\n    P(\\xi = k) = C_n^k p^k q^{n-k}, \\quad k = 0,1,2,3,\\ldots,n \\quad\n    p \\in [0, 1], \\quad q = 1-p \\quad n \\in \\mathbb{N} \\\\\n    E[X] = np \\\\\n    \\mathcal{D}[X] = np(1-p)\n\\end{gather*}\n\n\\subsection{Poisson}\n\n\\begin{gather*}\n    P(X=k) = \\frac{\\lambda^k e^{-\\lambda}}{k!} \\\\\n    \\lambda = E[X] = \\mathcal{D}[X]\n\\end{gather*}\n\n\\subsection{Hypergeometric}\n\\begin{gather*}\n    P(X=k) = \\frac{C_D^k \\cdot C_{N-D}^{n-k}}{C_N^n} \\\\\n    E[X] = \\frac{nD}{N} \\\\\n    \\mathcal{D}[X] = \\frac{n(D / N) (1 - D / N) (N - n)}{N - 1}\n\\end{gather*}\n\n\\subsection{Continuos Uniform}\n\\begin{gather*}\n    f_X(x) =\n    \\begin{cases}\n        \\frac{1}{b-a} & x \\in [a, b] \\\\\n        0 & x \\in [a,b]\n    \\end{cases} \\\\\n    P(X \\leq x) = \n    \\begin{cases}\n        0 & x < a \\\\\n        \\frac{x-a}{b-a} & a \\leq x \\leq b \\\\\n        1 & x \\geq b\n    \\end{cases} \\\\\n    E[X] = \\frac{a + b}{2} \\\\\n    \\mathcal{D}[X] = \\frac{(b-a)^2}{12}\n\\end{gather*}\n\n\\subsection{Normal}\n\n\\begin{gather*}\n    f(x) = \\frac{1}{\\sigma \\sqrt{2\\pi}} \\cdot e^{-\\frac{1}{2}\\left( \\frac{x-\\mu}{\\sigma} \\right)^2} \\\\\n    E[X] = \\mu \\\\\n    \\mathcal{D}[X] = \\sigma^2\n\\end{gather*}\n\n\\subsection{Exponential}\n\\begin{gather*}\n    f(x, \\lambda) = \n    \\begin{cases}\n        \\lambda e^{-\\lambda x} & x \\geq 0 \\\\\n        0 & x < 0\n    \\end{cases} \\\\\n    F(x, \\lambda) = \n    \\begin{cases}\n        1 - e^{-\\lambda x} & x \\geq 0 \\\\\n        0 & x < 0\n    \\end{cases} \\\\\n    E[X] = \\frac{1}{\\lambda} \\\\\n    \\mathcal{D}[X] = \\frac{1}{\\lambda^2}\n\\end{gather*}\n\n\\subsection{Cauchy}\n\\begin{gather*}\n    F(x, x_0, \\gamma) = \\frac{1}{\\pi} \\arctan\\left( \\frac{x-x_0}{\\gamma} \\right) + \\frac{1}{2}\n\\end{gather*}\n", "meta": {"hexsha": "f2387913a02189e4062a89813bd5ecbd0642f102", "size": 1963, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cources/statistics/distributions.tex", "max_stars_repo_name": "aipyth/notes", "max_stars_repo_head_hexsha": "59066a1110ea467b2aa43518da9295f23da89a32", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cources/statistics/distributions.tex", "max_issues_repo_name": "aipyth/notes", "max_issues_repo_head_hexsha": "59066a1110ea467b2aa43518da9295f23da89a32", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cources/statistics/distributions.tex", "max_forks_repo_name": "aipyth/notes", "max_forks_repo_head_hexsha": "59066a1110ea467b2aa43518da9295f23da89a32", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.2345679012, "max_line_length": 102, "alphanum_fraction": 0.4849719817, "num_tokens": 871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778061099871, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.7492254207766721}}
{"text": "%!TEX root=report.tex\n\\subsection{Kernel PCA}\n\nBefore delving into kernel methods, the standard PCA method will briefly be recapped.\nPCA as introduced in this report was done via SVD ($X = U\\Sigma V^T$). The columns of $U$ is the eigenvectors of $XX^T$. The projected space is then $Z = XV = U\\Sigma$. \nLooking at the dependencies of $U$, it is apparent that the principal component scores, will end up being linear combinations of basis in original input space $X$. \nIn most cases this suffices but what if there are no linear relationships in the $X$ space, standard PCA won't be appropriate.\n\n\\subsubsection{Motivating example}\n\\begin{figure}[H]\n\t\\center\n\t\\includegraphics[width=\\textwidth]{figures/kernel-pca-example}\n\t\\caption{Motivating kernel PCA example. Image courtesy of scikit-learn. License: BSD 3 clause. Authors: Mathieu Blondel and Andreas Mueller.}\n\t\\label{fig:kernel-pca-example}\n\\end{figure}\n\nAs is seen in Figure \\ref{fig:kernel-pca-example}, classes that wasn't linearly separable in the original space can be become linearly separable in the kernel space. This in turn makes clustering much easier and hopefully improves results.\n\n\\subsubsection{The Kernel Trick}\n\nIn kernel PCA, instead of working on $X X^T$, a nonlinear mapping $\\Phi: X\\rightarrow Y$ is used, such that the SVD is carried out on $\\Phi(X)\\Phi(X)^T = K(X, X^T)$. Specifically one define the inner product as a function of $(x_i, x_j)$, thus $\\Phi(X)\\Phi(X)^T$ is calculated, but without the need for the nonlinear mapping function $\\Phi$. This inner product function is the kernel.\n \nFor something to be a valid kernel, all the kernel needs to satisfy is to be function of an inner product in some vector space.\nFor the above to become more clear, let us give an example of a polynomial kernel in a 2-dimensional space. in the following $X$ is a vector and $X'$ is simply some other vector in the same space as $X$:\n\\begin{equation}\n\\begin{split}\nK(X,X') &= (1+X^T X')^2 = (1+x_1 x'_1+x_2 x'_2)^2 \\\\\n&= 1+x_1^2 {x'}_1^2 +2 x_1 x'_1 + 2 x_2 x'_2 + 2 x_1 x'_1 x_2 x'_2\n\\end{split}\n\\end{equation}\n\nFor the above to actually be a actual kernel there would have to be some transformed space in which the above was an inner product. From the coefficients above it can be deduced that the basis in this transformed space must be given as\n\\begin{equation}\n(1,x_1^2,x_2^2,\\sqrt{2} x_1, \\sqrt{2} x_2 , \\sqrt{2} x_1 x_2)\n\\end{equation}\n\nNow consider if one used a power of 100 instead of 2. Calculating the kernel in the non transformed  space is easy; $(1+X^T X')$ is just a number and raising it to the power of 100 can be done quickly.\nOn the other hand if one were to explicitly calculate the kernel as the inner product in the transformed space, a huge vector would have to be computed, transposed and be subjected to an the inner product in this space. This is clearly not very efficient.\n\nThe shortcut to define $K$ instead of $\\Phi$ is called the Kernel Trick.\n\n\\subsubsection{The Radial Basis Function (RBF) kernel}\n\nThe RBF kernel is commonly used when the amount of samples is much larger than the amount of dimensions in the original space.\n\nThe RBF kernel is defined as\n\\begin{equation}\nK(x,x')=\\mathrm{exp}(-\\gamma ||x-x'||^p_2)\n\\end{equation}\n\nThe above can easily be calculated. The following shows that the above is indeed an inner product. It is not a complete proof as $\\gamma=1, p=2$ and $x$ is a scalar not a vector.\n\n\\begin{equation}\n\\begin{split}\n\tK(x,x')&=\\mathrm{exp}(- ||x-x'||^2_2)=\\mathrm{exp}(- (x-x')^2) \\\\\n\t\t  &= \\mathrm{exp}(-x^2) \\mathrm{exp}(-{x'}^2) \\mathrm{exp}(2 x x')\n\\end{split}\n\\end{equation}\nsince $\\mathrm{exp}(2 x x')$ can be Taylor expanded to $\\sum_{k=0}^\\infty \\frac{2^k(x)^k (x')^k}{k!}$ it follows that:\n\\begin{equation}\nK(x,x') = \\sum_{k=0}^\\infty \\left(\\sqrt{\\frac{2^k}{k!}} (x)^k \\mathrm{exp}(-x^2)\\right)\\left(\\sqrt{\\frac{2^k}{k!}} (x')^k \\mathrm{exp}(-{x'}^2)\\right)\n\\end{equation}\n\nFrom the above it is seen that for any k, the term in the right parenthesis is exactly equal to the left parenthesis, if $x'$ was substituted with $x$. This means that in an expanded vector space, this correspond to the the inner product from the $\\ell^2$ Hilbert space. Do also note that since the sum is infinite, the transformed vector space is of infinite dimensional space and is thus impossible to calculate without the kernel trick.\n\n\\subsubsection{Mercer's Condition}\nProving that something is a kernel, is actually easier than shown above. It is done using Mercer's Condition, though it does not say anything about the size of the transformed space when $\\Phi$ is applied.\n\nThe theorem states, that given all real valued square integrable functions $g$ (${g \\in \\{\\mathbb{R} \\rightarrow \\mathbb{R}\\} \\cap L^2(\\mathbb{R})}$). That is the following must be true:\n\\begin{equation}\n\\int_{-\\infty}^{\\infty} g(x)^2 \\mathrm{d}x < \\infty\n\\end{equation}\n\nThen for all these $g$ functions, if the following condition holds:\n\\begin{equation}\n\\int \\int K(x, y) g(x) g(y) \\mathrm{d}x \\mathrm{d}y \\ge 0\n\\end{equation}\n\nThen $K$ is a valid kernel.\n\n\\subsubsection{Final notes of kernel PCA}\n\nIn kernel PCA the columns of $U$ is the eigenvectors of $K(X,X^T)$ and the columns of $V$ the eigenvectors of $K(X^T,X)$. The size of $X X^T$ and $X^T X$ is going to be $nxn$ and $pxp$ respectively where $n$ is the number of samples and $p$ the dimensions in transformed space. Thus when dealing with kernel PCA the calculation of $V$ is omitted and calculation of $U$ is expensive, but possible.\n\nIn the case of the GRACE data the size of $X$ is ($64800 \\times 341$). Memory wise this results in a $U$ matrix of size ($64800 \\times 64800$) with float32 numbers, that is approximately $15.64\\text{ GB}$. Furthermore kernel PCA also involves quite a lot of simple computing. So for practical purposes one should use a computer cluster (e.q. the DTU HPC cluster).\n", "meta": {"hexsha": "d07a3f9ddac1aee21acc48a9f573e16b00a7ea03", "size": 5862, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rapport/theory-kernelpca.tex", "max_stars_repo_name": "AndreasMadsen/grace", "max_stars_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-17T22:52:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-17T22:52:19.000Z", "max_issues_repo_path": "Rapport/theory-kernelpca.tex", "max_issues_repo_name": "AndreasMadsen/grace", "max_issues_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Rapport/theory-kernelpca.tex", "max_forks_repo_name": "AndreasMadsen/grace", "max_forks_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.1627906977, "max_line_length": 439, "alphanum_fraction": 0.7321733197, "num_tokens": 1689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245618, "lm_q2_score": 0.8856314617436728, "lm_q1q2_score": 0.7491932338647942}}
{"text": "\\section{Implicit Differentiation}\\label{sec:ImplicitDiff}\r\nAs we have seen, there is a close relationship \r\nbetween the derivatives of $\\ds e^x$ and $\\ln x$ because these functions\r\nare inverses. Rather than relying on pictures for our understanding,\r\nwe would like to be able to exploit this relationship\r\ncomputationally.  In fact this technique can help us find derivatives\r\nin many situations, not just when we seek the derivative of an inverse\r\nfunction. \r\n\r\nWe will begin by illustrating the technique to find what we already\r\nknow, the derivative of $\\ln x$. Let's write $y=\\ln x$ and then\r\n$\\ds x=e^{\\ln x}=e^y$, that is, $\\ds x=e^y$. We say that this equation\r\ndefines the function $y=\\ln x$ \r\nimplicitly because while it is not an explicit expression $y=\\ldots$, it is true\r\nthat if $\\ds x=e^y$ then $y$ is in fact the natural logarithm\r\nfunction. Now, for the time being, pretend that all we know of $y$ is\r\nthat $\\ds x=e^y$; what can we say about derivatives? We can take the\r\nderivative of both sides of the equation:\r\n$$\\frac{d}{dx}x=\\frac{d}{dx}e^y.$$\r\nThen using the chain rule on the right hand side:\r\n$$1 = \\left(\\frac{d}{dx}y\\right) e^y = y'e^y.$$\r\nThen we can solve for $y'$:\r\n$$y'=\\frac{1}{e^y} = \\frac{1}{x}.$$\r\nThere is one little difficulty here. To use the chain rule to compute \r\n$\\ds d/dx(e^y)=y'e^y$ we need to know that the function $y$ {\\it has} a\r\nderivative. All we have shown is that {\\it if} it has a derivative\r\nthen that derivative must be $1/x$. When using this method we will\r\nalways have to assume that the desired derivative exists, but\r\nfortunately this is a safe assumption for most such problems. \r\n \r\nThe example $y=\\ln x$ involved an inverse function defined implicitly,\r\nbut other functions can be defined implicitly, and sometimes a single\r\nequation can be used to implicitly define more than one\r\nfunction. \r\n\r\nHere's a familiar example.\r\n\r\n\\begin{example}{Derivative of Circle Equation}{impcircles}\r\nThe equation $\\ds r^2=x^2+y^2$\r\ndescribes a circle of radius $r$. The circle is not a function\r\n$y=f(x)$ because for some values of $x$ there are two corresponding\r\nvalues of $y$. If we want to work with a function, we can break the\r\ncircle into two pieces, the upper and lower semicircles, each of which\r\nis a function. Let's call these $y=U(x)$ and $y=L(x)$; in fact this is\r\na fairly simple example, and it's possible to give explicit\r\nexpressions for these: $\\ds U(x)=\\sqrt{r^2-x^2\\ }$ and\r\n$\\ds L(x)=-\\sqrt{r^2-x^2\\ }$.  But it's somewhat easier, and quite useful,\r\nto view both functions as given implicitly by $\\ds r^2=x^2+y^2$: both\r\n$\\ds r^2=x^2+U(x)^2$ and $\\ds r^2=x^2+L(x)^2$ are true, and we can think of \r\n$\\ds r^2=x^2+y^2$ as defining both $U(x)$ and $L(x)$.\r\n\r\nNow we can take the derivative of both sides as before, remembering\r\nthat $y$ is not simply a variable but a function---in this case, $y$\r\nis either $U(x)$ or $L(x)$ but we're not yet specifying which one.\r\nWhen we take the derivative we just have to remember to apply the\r\nchain rule where $y$ appears.\r\n\\begin{eqnarray*}\r\n\\frac{d}{dx}r^2&=&\\frac{d}{dx}(x^2+y^2)\\\\\r\n0&=&2x+2yy'\\\\\r\ny'&=&\\frac{-2x}{2y}=-\\frac{x}{y}\r\n\\end{eqnarray*}\r\nNow we have an expression for $y'$, but it contains $y$ as well as\r\n$x$. This means that if we want to compute $y'$ for some particular\r\nvalue of $x$ we'll have to know or compute $y$ at that value of $x$ as\r\nwell. It is at this point that we will need to know whether $y$ is\r\n$U(x)$ or $L(x)$. Occasionally it will turn out that we can avoid\r\nexplicit use of $U(x)$ or $L(x)$ by the nature of the problem. \r\n\\end{example}\r\n\r\n\\begin{example}{Slope of the Circle}{SlopeCircle}\r\nFind the slope of the circle $\\ds 4=x^2+y^2$ at the point\r\n$\\ds (1,-\\sqrt{3})$. \r\n\\end{example}\r\n\r\n\\begin{solution} \r\nSince we know both the $x$ and $y$ coordinates of the\r\npoint of interest, we do not need to explicitly recognize that this\r\npoint is on $L(x)$, and we do not need to use $L(x)$ to compute\r\n$y$ -- but we could. Using the calculation of $y'$ from above, \r\n$$y'=-\\frac{x}{y}=-\\frac{1}{-\\sqrt{3}}=\\frac{1}{\\sqrt{3}}.$$\r\nIt is instructive to compare this approach to others.\r\n\r\nWe might have recognized at the start that $\\ds (1,-\\sqrt{3})$ is on the\r\nfunction $\\ds y=L(x)=-\\sqrt{4-x^2}$. We could then take the derivative of\r\n$L(x)$, using the power rule and the chain rule, to get\r\n$$L'(x)=-{1\\over 2}(4-x^2)^{-1/2}(-2x)={x\\over\\sqrt{4-x^2}}.$$\r\nThen we could compute $\\ds L'(1)=1/\\sqrt{3}$ by substituting $x=1$.\r\n\r\nAlternately, we could realize that the point is on $L(x)$, but use the\r\nfact that $y'=-x/y$. Since the point is on $L(x)$ we can replace $y$\r\nby $L(x)$ to get\r\n$$y'=-\\frac{x}{L(x)}=-\\frac{x}{\\sqrt{4-x^2}},$$\r\nwithout computing the derivative of $L(x)$ explicitly. Then we\r\nsubstitute $x=1$ and get the same answer as before.\r\n\\end{solution}\r\n\r\nIn the case of the circle it is possible to find the functions $U(x)$\r\nand $L(x)$ explicitly, but there are potential advantages to using\r\nimplicit differentiation anyway. In some cases it is more difficult or\r\nimpossible to find an explicit formula for $y$ and implicit\r\ndifferentiation is the only way to find the derivative.\r\n\r\n\\begin{example}{Derivative of Function defined Implicitly}{FunctionDefinedImplicitly}\r\nFind the derivative of any function defined implicitly by \r\n$\\ds yx^2+y^2=x$. \r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe treat $y$ as an unspecified function and use the\r\nchain rule:\r\n\\begin{eqnarray*}\r\n\\frac{d}{dx}(yx^2+y^2)&=&\\frac{d}{dx}x\\\\\r\n(y\\cdot 2x+y'\\cdot x^2)+2yy'&=1\\\\\r\ny'\\cdot x^2+2yy'&=&-y\\cdot 2x\\\\\r\ny'&=&\\frac{-2xy}{x^2+2y}\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\n\\begin{example}{Derivative of Function defined Implicitly}{FunctionDefinedImplicitly2}\r\nFind the derivative of any function defined implicitly by \r\n$\\ds yx^2+e^y=x$. \r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe treat $y$ as an unspecified function and use the\r\nchain rule:\r\n\\begin{eqnarray*}\r\n\\frac{d}{dx}(yx^2+e^y)&=&\\frac{d}{dx}x\\\\\r\n(y\\cdot 2x+y'\\cdot x^2)+y'e^y &=& 1\\\\\r\ny'x^2+y'e^y&=& 1-2xy\\\\\r\ny'(x^2+e^y)&=& 1-2xy\\\\\r\ny'&=&\\frac{1-2xy}{x^2+e^y}\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\nYou might think that the step in which we solve for $y'$ could\r\nsometimes be difficult---after all, we're using implicit\r\ndifferentiation here because we can't solve the equation\r\n$\\ds yx^2+e^y=x$ for $y$, so maybe after taking the derivative we get\r\nsomething that is hard to solve for $y'$. In fact, {\\it this never\r\n  happens.} All occurrences $y'$ come from applying the chain rule,\r\nand whenever the chain rule is used it deposits a single $y'$\r\nmultiplied by some other expression. So it will always be possible to\r\ngroup the terms containing $y'$ together and factor out the $y'$, just\r\nas in the previous example. If you ever get anything more difficult\r\nyou have made a mistake and should fix it before trying to continue.\r\n\r\nIt is sometimes the case that a situation leads naturally to an\r\nequation that defines a function implicitly. \r\n\r\n\\begin{example}{Equation and Derivative of Ellipse}{Ellipse}\r\nDiscuss the equation and derivative of the ellispe.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nConsider all the points $(x,y)$ that have the property that\r\nthe distance from $(x,y)$ to $\\ds (x_1,y_1)$ plus the distance \r\nfrom $(x,y)$ to $\\ds (x_2,y_2)$ is $2a$ ($a$ is some constant). These\r\npoints form an ellipse, which like a circle is not a function but can be\r\nviewed as two functions pasted together. Since we know how to write\r\ndown the distance between two points, we can write down an implicit\r\nequation for the ellipse:\r\n$$\\sqrt{(x-x_1)^2+(y-y_1)^2}+\\sqrt{(x-x_2)^2+(y-y_2)^2}=2a.$$\r\nThen we can use implicit differentiation to find the slope of the\r\nellipse at any point, though the computation is rather messy.\r\n\\end{solution}\r\n\r\n\\begin{example}{Derivative of Function defined Implicitly}{FunctionDefinedImplicitly3}\r\nFind $\\ds\\frac{dy}{dx}$ by implicit differentiation if\r\n$$2x^3+x^2y-y^9=3x+4.$$\r\n\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nDifferentiating both sides with respect to $x$ gives:\r\n$$6x^2+\\left(2xy+x^2\\frac{dy}{dx}\\right)-9y^8\\frac{dy}{dx}=3,$$\r\n$$x^2\\frac{dy}{dx}-9y^8\\frac{dy}{dx}=3-6x^2-2xy$$\r\n$$\\left(x^2-9y^8\\right)\\frac{dy}{dx}=3-6x^2-2xy$$\r\n$$\\frac{dy}{dx}=\\frac{3-6x^2-2xy}{x^2-9y^8}.$$\r\n\\end{solution}\r\n\r\nIn the previous examples we had functions involving $x$ and $y$, and we\r\nthought of $y$ as a function of $x$.  In these problems we\r\ndifferentiated with respect to $x$. So when faced with $x$'s in the\r\nfunction we differentiated as usual, but when faced with $y$'s we\r\ndifferentiated as usual except we multiplied by a $\\frac{dy}{dx}$ for\r\nthat term because we were using Chain Rule.\r\n\r\nIn the following example we will assume that both $x$ and $y$ are\r\nfunctions of $t$ and want to differentiate the equation with respect\r\nto $t$.  This means that every time we differentiate an $x$ we will be\r\nusing the Chain Rule, so we must multiply by $\\frac{dx}{dt}$, and\r\nwhenever we differentiate a $y$ we multiply by $\\frac{dy}{dt}$.\r\n\r\n\\begin{example}{Derivative of Function of an Additional Variable}{FunctionAdditionalVariable}\r\nThinking of $x$ and $y$ as functions of $t$, differentiate the following equation with respect to $t$:\r\n$$x^2+y^2=100.$$\r\n\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nUsing the Chain Rule we have:\r\n$$2x\\frac{dx}{dt}+2y\\frac{dy}{dt}=0.$$\r\n\\end{solution}\r\n\r\n\\begin{example}{Derivative of Function of an Additional Variable}{FunctionAdditionalVariable2}\r\nIf $y=x^3+5x$ and $\\ds\\frac{dx}{dt}=7$, find $\\ds\\frac{dy}{dt}$ when $x=1$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nDifferentiating each side of the equation $y=x^3+5x$ with respect to $t$ gives:\r\n$$\\frac{dy}{dt}=3x^2\\frac{dx}{dt}+5\\frac{dx}{dt}.$$\r\nWhen $x=1$ and $\\frac{dx}{dt}=7$ we have:\r\n$$\\frac{dy}{dt}=3(1^2)(7)+5(7)=21+35=56.$$\r\n\\end{solution}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection*{Logarithmic Differentiation}\r\nPreviously we've seen how to do the derivative of a number to a function $(a^{f(x)})'$, and also a function to a number $[(f(x))^n]'$.\r\nBut what about the derivative of a function to a function $[(f(x))^{g(x)}]'$?\r\n\r\nIn this case, we use a procedure known as \\dfont{logarithmic differentiation}.\r\n\r\n\\begin{formulabox}[Steps for Logarithmic Differentiation]\r\n\\begin{itemize}\r\n\\item Take $\\ln$ of both sides of $y=f(x)$ to get $\\ln y=\\ln f(x)$ and simplify using logarithm properties,\r\n\\item Differentiate implicitly with respect to $x$ and solve for $\\ds\\frac{dy}{dx}$,\r\n\\item Replace $y$ with its function of $x$ (i.e., $f(x)$).\r\n\\end{itemize}\r\n\\end{formulabox}\r\n\r\n\\begin{example}{Logarithmic Differentiation}{LogarithmicDifferentiation}\r\nDifferentiate $y=x^x$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe take $\\ln$ of both sides:\r\n$$\\ln y=\\ln x^x.$$\r\nUsing log properties we have:\r\n$$\\ln y = x\\ln x.$$\r\nDifferentiating implicitly gives:\r\n$$\\frac{y'}{y}=(1)\\ln x+x\\frac{1}{x}.$$\r\n$$\\frac{y'}{y}=\\ln x+1.$$\r\nSolving for $y'$ gives:\r\n$$y'=y(1+\\ln x).$$\r\nReplace $y=x^x$ gives:\r\n$$y'=x^x(1+\\ln x).$$\r\n\r\nAnother method to find this derivative is as follows:\r\n\\begin{eqnarray*}\r\n\\frac{d}{dx}x^x&=&\\frac{d}{dx}e^{x\\ln x}\\\\\r\n&=&\\left(\\frac{d}{dx}x\\ln x\\right)e^{x\\ln x}\\\\\r\n&=&(x\\frac{1}{x}+\\ln x)x^x\\\\\r\n&=&(1+\\ln x)x^x\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\nIn fact, logarithmic differentiation can be used on more complicated\r\nproducts and quotients (not just when dealing with functions to the\r\npower of functions).\r\n\r\n\\begin{example}{Logarithmic Differentiation}{LogarithmicDifferentiation2}\r\nDifferentiate (assuming $x>0$):\r\n$$y=\\frac{(x+2)^3(2x+1)^9}{x^8(3x+1)^4}.$$\r\n\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nUsing product \\& quotient rules for this problem is a complete nightmare!\r\nLet's apply logarithmic differentiation instead.\r\nTake $\\ln$ of both sides:\r\n$$\\ln y=\\ln\\left(\\frac{(x+2)^3(2x+1)^9}{x^8(3x+1)^4}\\right).$$\r\nApplying log properties:\r\n$$\\ln y=\\ln\\left((x+2)^3(2x+1)^9\\right)-\\ln\\left(x^8(3x+1)^4\\right).$$\r\n$$\\ln y=\\ln\\left((x+2)^3\\right)+\\ln\\left((2x+1)^9\\right)-\\left[\\ln\\left(x^8\\right)+\\ln\\left((3x+1)^4\\right)\\right].$$\r\n$$\\ln y=3\\ln(x+2)+9\\ln(2x+1)-8\\ln x-4\\ln(3x+1).$$\r\nNow, differentiating implicitly with respect to $x$ gives:\r\n$$\\frac{y'}{y}=\\frac{3}{x+2}+\\frac{18}{2x+1}-\\frac{8}{x}-\\frac{12}{3x+1}.$$\r\nSolving for $y'$ gives:\r\n$$y'=y\\left(\\frac{3}{x+2}+\\frac{18}{2x+1}-\\frac{8}{x}-\\frac{12}{3x+1}\\right).$$\r\nReplace $y=\\frac{(x+2)^3(2x+1)^9}{x^8(3x+1)^4}$ gives:\r\n$$y'=\\frac{(x+2)^3(2x+1)^9}{x^8(3x+1)^4}\\left(\\frac{3}{x+2}+\\frac{18}{2x+1}-\\frac{8}{x}-\\frac{12}{3x+1}\\right).$$\r\n\\end{solution}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:ImplicitDiff}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind a formula for the derivative $y'$ at the point $(x,y)$:\r\n\\begin{multicols}{2}\r\n\\begin{enumerate}\r\n\t\\item\t$\\ds y^2=1+x^2$\r\n\t\\item\t$\\ds x^2+xy+y^2=7$\r\n\t\\item\t$\\ds x^3+xy^2=y^3+yx^2$\r\n\t\\item\t$\\ds 4\\cos x \\sin y = 1$\r\n\t\\item\t$\\ds\\sqrt{x} + \\sqrt{y} = 9$\r\n\t\\item\t$\\ds \\tan(x/y) = x+ y$\r\n\t\\item\t$\\ds \\sin (x+y ) =xy$\r\n\t\\item\t$\\ds\\frac{1}{x} + \\frac{1}{y} = 7$\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\t\\item\t$\\ds x/y$\r\n\t\\item\t$\\ds -(2x+y)/(x+2y)$\r\n\t\\item\t$\\ds (2xy-3x^2-y^2)/(2xy-3y^2-x^2)$\r\n\t\\item\t$\\ds \\sin(x)\\sin(y)/(\\cos(x)\\cos(y))$\r\n\t\\item\t$\\ds-\\sqrt{y}/\\sqrt{x}$\r\n\t\\item\t$\\ds (y\\sec^2(x/y)-y^2)/(x\\sec^2(x/y)+y^2)$\r\n\t\\item\t$\\ds (y-\\cos(x+y))/(\\cos(x+y)-x)$\r\n\t\\item\t$\\ds -y^2/x^2$\r\n\\end{enumerate}\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nA hyperbola passing through $(8,6)$ consists of all points whose distance\r\nfrom the origin is a constant more than its distance from the point (5,2).\r\nFind the slope of the tangent line to the hyperbola at $(8,6)$.\r\n\\begin{sol}\r\n\t$1$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nThe graph of the equation $\\ds x^2 - xy + y^2 = 9$ is an ellipse.\r\nFind the lines tangent to this curve at the two\r\n points where it intersects the $x$-axis. Show that these lines are\r\n parallel.\r\n\\begin{sol}\r\n\t$y=2x\\pm6$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nRepeat the previous problem for the points at which the\r\n ellipse intersects the $y$-axis.\r\n\\begin{sol}\r\n\t$y=x/2\\pm3$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n\tIf $\\ds y=\\log_a x$ then $\\ds a^y=x$. Use implicit\r\n\tdifferentiation to find $\\ds y'$.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind the points on the ellipse from the previous two problems\r\n where the slope is horizontal and where it is vertical.\r\n\\begin{sol}\r\n\t$\\ds (\\sqrt3,2\\sqrt3)$, $\\ds (-\\sqrt3,-2\\sqrt3)$, $\\ds (2\\sqrt3,\\sqrt3)$,\r\n$\\ds (-2\\sqrt3,-\\sqrt3)$ \r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind an equation for the tangent line to \r\n$\\ds x^4 = y^2 + x^2$ at $\\ds (2, \\sqrt{12})$. \r\n(This curve is the \\dfont{kampyle of Eudoxus}.)\r\n\\begin{sol}\r\n\t$\\ds y=7x/\\sqrt3-8/\\sqrt3$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind an equation for the tangent line to $\\ds x^{2/3} +\r\ny^{2/3} = a^{2/3}$ at a point $\\ds (x_1 ,y_1)$ on the curve, \r\nwith $\\ds x_1 \\neq 0$ and $\\ds y_1 \\neq 0$. (This curve is an {\\dfont astroid}.)\r\n\\begin{sol}\r\n\t$\\ds y=(-y_1^{1/3}x+y_1^{1/3}x_1+x_1^{1/3}y_1)/x_1^{1/3}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind an equation for the tangent line to $\\ds (x^2 +y^2 )^2 =x^2\r\n-y^2$ at a point $\\ds (x_1 , y_1)$ on the curve, with $\\ds x_1 \\neq 0, -1, 1$.\r\n(This curve is a \\dfont{lemniscate}.)\r\n\\begin{sol}\r\n\t$\\ds (y-y_1)/(x-x_1)=(2x_1^3+2x_1y_1^2-x_1)/(2y_1^3+2y_1x_1^2+y_1)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}  \r\nTwo curves are \\dfont{orthogonal} if at each point of intersection,\r\nthe angle between their tangent lines is $\\pi/2$. Two\r\nfamilies of curves, $\\cal{A}$ and $\\cal{B}$, are\r\n\\dfont{orthogonal trajectories} of each other if given any curve $C$\r\nin $\\cal{A}$ and any curve $D$ in $\\cal{B}$ the curves $C$\r\nand $D$ are orthogonal.\r\nFor example, the family of horizontal lines in the plane is\r\northogonal to the family of vertical lines in the plane.\r\n\\begin{enumerate}\r\n\t\\item\tShow that $\\ds x^2 -y^2 =5$ is orthogonal to $\\ds 4x^2 +9y^2\r\n\t=72$. (Hint: You need to find the intersection points of the two\r\n\tcurves and then show that the product of the derivatives at each\r\n\tintersection point is $-1$.)\r\n\t\\item\tShow that $\\ds x^2 +y^2 = r^2$ is orthogonal to\r\n\t$y=mx$. Conclude that the family of circles centered at the origin is\r\n\tan orthogonal trajectory of the family of lines that pass through the\r\n\torigin.\r\n\t\r\n\tNote that there is a technical issue when $m=0$. The circles fail to\r\n\tbe differentiable when they cross the $x$-axis. However, the circles\r\n\tare orthogonal to the $x$-axis. Explain why. Likewise, the vertical\r\n\tline through the origin requires a separate argument.\r\n\t\\item\tFor $k\\not= 0$ and $c \\neq 0$ show that $\\ds y^2 -x^2 =k$ is orthogonal to\r\n\t$yx =c$. In the case where $k$ and $c$ are both zero, the curves\r\n\tintersect at the origin. Are the curves $\\ds y^2 -x^2 =0$ and $yx=0$\r\n\torthogonal to each other?\r\n\t\\item\tSuppose that $m\\neq 0$. Show that the family of curves\r\n\t$\\ds \\{y=mx+b \\mid b\\in \\R \\}$ is orthogonal to the\r\n\tfamily of curves $\\ds \\{y=-(x/m)+c \\mid c \\in \\R\\}$.\r\n\\end{enumerate}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nDifferentiate the function $\\ds y={(x-1)^8 (x-23)^{1/2}\\over 27 x^6(4x-6)^8 }$\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nDifferentiate the function $\\ds f(x)=(x+1)^{\\sin x}$.\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nDifferentiate the function $\\ds g(x)=\\frac{e^x(\\cos x+2)^3}{\\sqrt{x^2+4}}$.\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "7ca64930572d700e8c2544eb897cfb7dde482eff", "size": 17431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-derivatives/4-8-imp-diff.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4-derivatives/4-8-imp-diff.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4-derivatives/4-8-imp-diff.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.259009009, "max_line_length": 135, "alphanum_fraction": 0.6599736102, "num_tokens": 5906, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619220634457, "lm_q2_score": 0.9086178963141964, "lm_q1q2_score": 0.7491208572164471}}
{"text": "\\section{Concepts and Background}\\label{sec:backgroundML}\nMachine learning refers to a set of techniques for understanding data. The theoretical subject of ``learning'' is related to prediction. Machine learning techniques involve building a statistical model for predicting, or estimating an output based on one or more inputs. Regression models are used when the output is a continuous value. In this work, we used three different machine learning methods: Linear Regression, Support Vector Machines and Random Forest. There exists other machine learning techniques with sophisticated learning process. However, in this work, we wanted to use simple models to prove that they achieve reasonable predictions.\n\n\\subsection{Linear Regression (LR)}\nLinear regression is a straightforward technique for predicting a quantitative response $Y$ on the basis of a single or multiple predictor variables $X_p$. It assumes that there is approximately a linear relationship between each $X_p$ and $Y$. It gives to each predictor a separate slope coefficient in a single model. Mathematically, we can write the multiple linear regression model as\n\\begin{equation}\nY \\approx \\beta_0 + \\beta_1 X_1 + + \\beta_2 X_2 + \\ldots + + \\beta_p X_p + \\epsilon\n\\end{equation}\nwhere $X_p$ represents the $p$th predictor and $\\beta_p$ quantifies the association between that variable and the response.\n\n\\subsection{Support Vector Machines (SVM)}\nSupport Vector Machines is a widely used technique for classification and regression problems. It belongs to the general category of kernel methods, which are algorithms that depend on the data only through dot-products. The dot product can be replaced by a kernel function which computes a dot product in some possibly high dimensional feature space $Z$. It maps the input vector $x$ into the feature space $Z$ though some nonlinear mapping. \n\n\\subsection{Random Forest (RF)}\nRandom Forests belong to decision tree methods, capable of performing both regression and classification tasks. In general, a decision tree with $M$ leaves divides the feature space into $M$ regions $R_m$, $1 \\leq m \\leq M$. The prediction function of a tree is then defined as $f(x) = \\sum_{m=1}^{M} c_m I(x, R_m)$, where $M$ is the number of leaves in the tree, $R_m$ is a region in the features space, $c_m$ is a constant corresponding to region $m$ and $I$ is the indicator function, which is 1 if $x \\in R_m$, 0 otherwise. The values of $c_m$ are determined in the training process. Random forest consists of an ensemble of decision trees and uses the mode of the decisions of individual trees.\n\n\\subsection{Extraction Features Techniques}\\label{ssec:ML}\n\nCorrelation techniques and hierarchical clustering algorithm were used in the phase of extraction features to reduce dimensionality of the features. Here, we show a short theoretical background of the techniques used in this work. \n\nThere exist different correlation functions, among them, Pearson, Spearman and Kendal. The Pearson's correlation evaluates the linear relationship between two continuous variables, but omit variation in different scales. The Spearman's correlation evaluates the monotonic relationship between two continuous or ordinal variables. Besides Spearman correlation consider relations in different scales and spaces of the features due to the rank variables.\n\nPearson's correlation is commonly represented by the greek letter ($\\rho$) when it is used for populations and by the letter $r$ when it is used for samples. We will denote it with the letter $r$, the formula for $r$ in a simplified form is\n\\begin{equation}\nr=\\frac{\\text{cov}(X,Y)}{\\sigma_{X}\\sigma_{Y}},\n\\end{equation}\nwhere, cov($X,Y$) is the covariance between two variables, $X$ and $Y$, $\\sigma_{X}$ is the standard deviation of $X$ and $\\sigma _{Y}$ is the standard deviation of $Y$.\n\nThe Spearman correlation coefficient is defined as the Pearson correlation coefficient between the ranked variables~\\citep{myers2010research}, for a sample of size $n$, the $n$ raw scores $X_{i}$, $Y_{i}$ are converted to ranks rg$X_{i}$ rg$Y_{i}$. Here, this correlation is denoted as $r_s$, the formula for $r_s$ in a short manner is\n\\begin{equation}\nr_{s}=\\frac{\\text{cov}(rgX,rgY)}{\\sigma_{rgX}\\sigma_{rgY}},\n\\end{equation}\nwhere cov($rgX,rgY$) is the covariance of the rank variables, and $\\sigma_{rgX}$ and $\\sigma_{rgY}$ are the standard deviations of the rank variables. \n\nHierarchical clustering creates groups from a distance matrix. Different metrics or distance functions exist in the literature, among them, Euclidean, Manhattan, Canberra, Binary or Minkowski, however, correlation functions can be also used. A heatmap of pair-wise correlations is a simple way to discover relationships between  pairs of quantitative variables in a dataset. A dendrogram is a tree diagram frequently used to illustrate the arrangement of the clusters produced by a hierarchical clustering algorithm. In Figure \\ref{fig:heatMaphClust} is shown a dendrogram with its respective distance matrix using a Spearman correlation function. We can see in this figure a dendrogram with 10 different features about the profile information. In this figure red cells have a high correlation while blue cells have a low correlation.\n\n\\begin{figure}[htpb]\n    \\centering\n    \\includegraphics[scale=.5]{./images/heatMap.pdf}\n    \\caption{Heatmap and Dendrogram of a correlation matrix with some features in the experiments}\n    \\label{fig:heatMaphClust}\n\\end{figure}\n\nA dendrogram is a tree diagram frequently used to illustrate the arrangement of the clusters produced by hierarchical clustering algorithms. In Figure \\ref{fig:heatMaphClust} is shown a dendrogram with its respective matrix of correlation. This dendrogram can be cut in a certain height to permit create a specific number of clusters.", "meta": {"hexsha": "4eca11a6c374a00062ead96900c95ed933f38f03", "size": 5819, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/thesis/sections/machine-learning.tex", "max_stars_repo_name": "marcosamaris/svm-gpuperf", "max_stars_repo_head_hexsha": "35b81711089273c775f143ecaeadae03ebf5910a", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-06-03T18:32:48.000Z", "max_stars_repo_stars_event_max_datetime": "2017-06-03T18:32:48.000Z", "max_issues_repo_path": "docs/thesis/sections/machine-learning.tex", "max_issues_repo_name": "marcosamaris/svm-gpuperf", "max_issues_repo_head_hexsha": "35b81711089273c775f143ecaeadae03ebf5910a", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/thesis/sections/machine-learning.tex", "max_forks_repo_name": "marcosamaris/svm-gpuperf", "max_forks_repo_head_hexsha": "35b81711089273c775f143ecaeadae03ebf5910a", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 132.25, "max_line_length": 834, "alphanum_fraction": 0.7898264307, "num_tokens": 1309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7491173004364012}}
{"text": "\\section*{Ex.34.2-8}\n\\subsection*{Show that TAUTOLOGY $\\in$ co-NP}\n\nThe question is analog to showing that $\\overline{\\text{TAUTOLOGY}}\\in$ NP, where $\\overline{\\text{TAUTOLOGY}}$ is the complement of TAUTOLOGY.\n\\\\\n$\\overline{\\text{TAUTOLOGY}}$ must be the language of boolean formulas, where changing the assignment of at least one variable will cause the formula $\\phi$ to evaluate to 0.\n\nIf we can verify a certificate in polynomial time, then $\\overline{\\text{TAUTOLOGY}}\\in$ NP. A certificate would be an assignment of variables, and we can check in polynomial time, that $\\overline{\\text{TAUTOLOGY}}$ evaluates to 0.\n\nSince $\\overline{\\text{TAUTOLOGY}}$ has fewer connectives than SAT, and no connectives that SAT does not, then $\\overline{\\text{TAUTOLOGY}}$ is a proper subset of SAT, i.e. $\\overline{\\text{TAUTOLOGY}} \\subset \\text{SAT}$. As SAT $\\in$ NP, this then implies that $\\overline{\\text{TAUTOLOGY}} \\in$ NP, which then means that TAUTOLOGY $\\in$ co-NP.", "meta": {"hexsha": "6fac1540f5162e919228f55eec434c16e1d54348", "size": 969, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge4/Ex.34.2-8.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge4/Ex.34.2-8.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge4/Ex.34.2-8.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 96.9, "max_line_length": 345, "alphanum_fraction": 0.7409700722, "num_tokens": 281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.7489924691612562}}
{"text": "\\section{The Derivative Function}\\label{sec:TheDerivativeFunction}\r\nIn Section \\ref{sec:Slope}, we have seen how to create, or derive, a new function $f'(x)$ from a\r\nfunction $f(x)$, and that this new function carries important\r\ninformation. In one example we saw that $f'(x)$ tells us how steep the\r\ngraph of $f(x)$ is; in another we saw that $f'(x)$ tells us the velocity\r\nof an object if $f(x)$ tells us the  position of the object at time\r\n$x$. As we said earlier, this same mathematical idea is useful\r\nwhenever $f(x)$ represents some changing quantity and we want to know\r\nsomething about how it changes, or roughly, the ``rate'' at which it\r\nchanges. Most functions encountered in practice are built up from a\r\nsmall collection of ``primitive'' functions in a few simple ways, for\r\nexample, by adding or multiplying functions together to get new, more\r\ncomplicated functions. To make good use of the information provided by\r\n$f'(x)$ we need to be able to compute it for a variety of such functions.\r\n\r\nWe will begin to use different notations for the derivative of a\r\nfunction. While initially confusing, each is often useful so it is\r\nworth maintaining multiple versions of the same thing.\r\n\r\nConsider again the function $\\ds f(x)=\\sqrt{625-x^2}$.\r\nWe have computed the derivative $\\ds f'(x)=-x/\\sqrt{625-x^2}$, and have\r\nalready noted that if we use the alternate notation\r\n$\\ds y=\\sqrt{625-x^2}$ then we might write $\\ds y'=-x/\\sqrt{625-x^2}$.\r\nAnother notation is quite different, and in time it will become clear\r\nwhy it is often a useful one. Recall that to compute the the\r\nderivative of $f$ we computed \r\n$$\r\n\\lim_{\\Delta x\\to0} {\\sqrt{625-(7+\\Delta x)^2} - 24\\over \\Delta x}.\r\n$$\r\nThe denominator here measures a distance in the $x$ direction,\r\nsometimes called the ``run'', and the numerator measures a distance in\r\nthe $y$ direction, sometimes called the ``rise,'' and ``rise over\r\nrun'' is the slope of a line. Recall that sometimes such a numerator is\r\nabbreviated $\\Delta y$, exchanging brevity for a more detailed\r\nexpression. So in general, we define a derivative by the following equation.\r\n\r\n\\begin{definition}{Defnition of Derivative}{DerDefn}\r\nThe derivative of $y=f(x)$ with respect to $x$ is\r\n$$y'=\\lim_{\\Delta x\\to0} {\\Delta y\\over \\Delta x}.$$\r\nSome textbooks use $h$ in place of $\\Delta x$ in the definition of\r\nderivative: $$f'(x)=\\lim_{h\\to 0}\\frac{f(x+h)-f(x)}{h}.$$ \r\n\\end{definition}\r\n\r\nTo recall the form of the limit, we sometimes say instead that\r\n$$\r\n{dy\\over dx}=\\lim_{\\Delta x\\to0} {\\Delta y\\over \\Delta x}.\r\n$$ \r\nIn other words, $dy/dx$ is another notation for the derivative, and\r\nit reminds us that it is related to an actual slope between two\r\npoints. This notation is called \\dfont{Leibniz notation}, \r\nafter Gottfried Leibniz, who developed the fundamentals\r\nof calculus independently, at about the same time that Isaac Newton\r\ndid.  Again, since we often use $f$ and $f(x)$ to mean the original\r\nfunction, we sometimes use $df/dx$ and $df(x)/dx$ to refer to the\r\nderivative. If the function $f(x)$ is written out in full we often\r\nwrite the last of these something like this\r\n$$f'(x)={d\\over dx}\\sqrt{625-x^2}$$\r\nwith the function written to the side, instead of trying to fit it into\r\nthe numerator.\r\n\r\n\\begin{example}{Derivative of $y=t^2$}{Derivative1}\r\nFind the derivative of $\\ds y=f(t)=t^2$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe compute \r\n\\[ \\begin{array}{rll}\r\ny' &=& \\ds\\lim_{\\Delta t\\to0}\\ds\\frac{\\Delta y}{\\Delta t}  \\\\\r\n\\\\\r\n\t&=&\\ds\\lim_{\\Delta t\\to0}\\ds\\frac{(t+\\Delta t)^2-t^2}{\\Delta t} \\\\\r\n\t\\\\\r\n&=&\\ds\\lim_{\\Delta t\\to0}\\ds\\frac{t^2+2t\\Delta t+\\Delta t^2-t^2}{\\Delta t} \\\\\r\n\\\\\r\n&=&\\ds\\lim_{\\Delta t\\to0}\\ds\\frac{2t\\Delta t+\\Delta t^2}{\\Delta t} \\\\\r\n\\\\\r\n&=&\\ds\\lim_{\\Delta t\\to0} 2t+\\Delta t=2t. \\\\\r\n\\end{array}\\]\r\n\\end{solution}\r\n\r\nRemember that $\\Delta t$ is a single quantity, not a ``$\\Delta$''\r\ntimes a ``$t$'', and so $\\ds \\Delta t^2$ is $\\ds (\\Delta t)^2$ not \r\n$\\ds \\Delta (t^2)$.\r\nDoing the same example using the second formula for the derivative with $h$ in place of $\\Delta t$ gives the following.\r\nNote that we compute $f(t+h)$ by substituting $t+h$ in place of $t$ everywhere we see $t$ in the expression $f(t)$,\r\n\\textit{while making no other changes} (at least initially). For example, if $f(t)=t+\\sqrt{(t+3)^2-t}$ then $f(t+h)=(t+h)+\\sqrt{((t+h)+3)^2-(t+h)}=t+h+\\sqrt{(t+h+3)^2-t-h}$.\r\n\r\n\\begin{example}{Derivative of $y=t^2$}{Derivative1b}\r\nFind the derivative of $\\ds y=f(t)=t^2$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe compute \r\n\\[ \\begin{array}{rll}\r\nf'(t) &=& \\ds\\lim_{h\\to0}\\ds\\frac{f(t+h)-f(t)}{h}  \\\\\r\n\\\\\r\n\t&=&\\ds\\lim_{h\\to0}\\ds\\frac{(t+h)^2-t^2}{h} \\\\\r\n\t\\\\\r\n&=&\\ds\\lim_{h\\to0}\\ds\\frac{t^2+2th+h^2-t^2}{h} \\\\\r\n\\\\\r\n&=&\\ds\\lim_{h\\to0}\\ds\\frac{2th+h^2}{h} \\\\\r\n\\\\\r\n&=&\\ds\\lim_{h\\to0} 2t+h=2t. \\\\\r\n\\end{array}\\]\r\n\\end{solution}\r\n\r\n\\begin{example}{Derivative}{Derivative2}\r\nFind the derivative of $y=f(x)=1/x$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nThe computation:\r\n\\begin{eqnarray*}\r\ny' &=& \\lim_{\\Delta x\\to0}{\\Delta y\\over\\Delta x}\\cr\r\n\\\\\r\n&=&\\lim_{\\Delta x\\to0}{ {1\\over x+\\Delta x} - {1\\over x}\\over \\Delta\r\n  x}\\cr\r\n\\\\\r\n&=&\\lim_{\\Delta x\\to0}{ {x\\over x(x+\\Delta x)} - \r\n{x+\\Delta x\\over x(x+\\Delta x)}\\over \\Delta x}\\cr\r\n\\\\\r\n&=&\\lim_{\\Delta x\\to0}{ {x-(x+\\Delta x)\\over x(x+\\Delta x)}\\over \\Delta x}\\cr\r\n\\\\\r\n&=&\\lim_{\\Delta x\\to0} {x-x-\\Delta x\\over x(x+\\Delta x)\\Delta x}\\cr\r\n\\\\\r\n&=&\\lim_{\\Delta x\\to0} {-\\Delta x\\over x(x+\\Delta x)\\Delta x}\\cr\r\n\\\\\r\n&=&\\lim_{\\Delta x\\to0} {-1\\over x(x+\\Delta x)}={-1\\over x^2}\\cr\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\n{\\bf Note:}  If you happen to know some ``derivative formulas'' from\r\nan earlier course, for the time being you should pretend that you do\r\nnot know them.\r\nIn examples like the ones above and the exercises below, you are required\r\nto know how to find the derivative formula starting from basic principles.\r\nWe will later develop some formulas so that we do not always need to\r\ndo such computations, but we will continue to need to know how to do\r\nthe more involved computations.\r\n\r\nTo recap, given any function $f$ and any number $x$ in the domain of $f$, we define\r\n$f'(x)=\\lim_{h\\to 0}\\frac{f(x+h)-f(x)}{h}$ wherever this limit exists, and we call\r\nthe number $f'(x)$ the derivative of $f$ at $x$. Geometrically, $f'(x)$ is the slope of\r\nthe tangent line to the graph of $f$ at the point $(x,f(x))$.  The following\r\nsymbols also represent the derivative:\r\n$$f'(x)=y'=\\frac{dy}{dx}=\\frac{df}{dx}=\\frac{d}{dx}f(x).$$ The symbol\r\n$d/dx$ is called a differential operator which means to take the\r\nderivative of the function $f(x)$ with respect to the variable $x$.\r\n\r\nIn the next example we emphasize the geometrical interpretation of derivative.\r\n\r\n\\begin{example}{Geometrical Interpretation of Derivative}{GeometricalInterpretationDerivative}\r\nConsider the function $f(x)$ given by the graph below.\r\nVerify that the graph of $f'(x)$ is indeed the derivative of $f(x)$ by analyzing slopes of tangent lines to the graph at different points.\r\n$$\\includegraphics[width=2.5in]{images/deriv1}$$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe must think about the tangent lines to the graph of $f$, because the slopes\r\nof these lines are the values of $f'(x)$.\r\n\r\nWe start by checking the graph of $f$ for horizontal tangent lines, since horizontal\r\nlines have a slope of 0. We find that the tangent line is horizontal at the points\r\nwhere $x$ has the values -1.9 and 1.8 (approximately). At each of these values of $x$,\r\nwe must have $f'(x)=0$, which means that the graph of $f'$ has an $x$-intercept (a point\r\nwhere the graph intersects the $x$-axis). \r\n\r\nNote that horizontal tangent lines have a slope of zero and these\r\noccur approximately at the points $(-1.9,-3.2)$ and $(1.8,3.2)$ of the\r\ngraph.  Therefore $f'(x)$ will cross the $x$-axis when $x=-1.9$ and\r\n$x=1.8$.  \r\n\r\nAnalyzing the slope of the tangent line of $f(x)$ at $x=0$ gives\r\napproximately $3.0$, thus, $f'(0)=3.0$.  Similarly, analyzing the\r\nslope of the tangent lines of $f(x)$ at $x=1$ and $x=-1$ give\r\napproximately $2.0$ for both, thus, $f'(1)=f'(-1)=2.0$.\r\n\\end{solution}\r\n\r\nIn the next example we verify that the slope of a straight line is $m$.\r\n\r\n\\begin{example}{Derivative of a Linear Function}{DerivativeLinearFunction}\r\nLet $m,b$ be any two real numbers.\r\nDetermine $f'(x)$ if $f(x)=mx+b$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nBy the definition of derivative (using $h$ in place of $\\Delta x$) we have,\r\n$$f'(x)=\\lim_{h\\to 0}\\frac{f(x+h)-f(x)}{h}=\\lim_{h\\to 0}\\frac{(m(x+h)+b)-(mx+b)}{h}$$\r\n$$=\\lim_{h\\to 0}\\frac{mh}{h}=\\lim_{h\\to 0}m=m.$$\r\n\r\nThis is not surprising. We know that $f'(x)$ always represents the slope of a tangent\r\nline to the graph of $f$. In this example, since the graph of $f$ is a straight line $y=mx+b$\r\nalready, every tangent line is the same line $y=mx+b$. Since this line has a slope of $m$,\r\nwe must have $f'(x)=m$.\r\n\\end{solution}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n% Subsections to include\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\input{4-derivatives/4-3-1-differentiable}\r\n\\input{4-derivatives/4-3-2-second-other-derivatives}\r\n\\input{4-derivatives/4-3-3-velocities}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:TheDerivativeFunction}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind the derivatives of the following functions.\r\n\\begin{enumerate}\r\n\t\\item\t$\\ds y=f(x)=\\sqrt{169-x^2}$\r\n\t\\item\t$\\ds y=f(t)=80-4.9t^2$\r\n\t\\item\t$\\ds y=f(x)=x^2-(1/x)$\r\n\t\\item\t$\\ds y=f(x)=ax^2+bx+c$, where $a$, $b$, and $c$ are constants.\r\n\t\\item\t$\\ds y=f(x)=x^3$\r\n\t\\item\t$\\ds y=f(x)=2/\\sqrt{2x+1}$\r\n\t\\item\t$y=g(t)=(2t-1)/(t+2)$\r\n\\end{enumerate}\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\t\\item\t$\\ds -x/\\sqrt{169-x^2}$\r\n\t\\item\t$-9.8t$\r\n\t\\item\t$\\ds 2x+1/x^2$\r\n\t\\item\t$2ax+b$\r\n\t\\item\t$\\ds 3x^2$\r\n\t\\item\t$\\ds -2/(2x+1)^{3/2}$\r\n\t\\item\t$\\ds 5/(t+2)^2$\r\n\\end{enumerate}\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nShown is the graph of a function $f(x)$. Sketch the graph of $f'(x)$\r\nby estimating the derivative at a number of points in the interval:\r\nestimate the derivative at regular intervals from one end of the\r\ninterval to the other, and also at ``special'' points, as when the\r\nderivative is zero. Make sure you indicate any places where the\r\nderivative does not exist.\r\n$$\\vbox{\\beginpicture\r\n\\normalgraphs\r\n\\setcoordinatesystem units <4.5truecm,4.5truecm>\r\n\\setplotarea x from -1 to 1, y from 0 to 1.6\r\n\\axis left ticks numbered from 0.2 to 1.6 by 0.2 /\r\n\\axis left shiftedto x=0 /\r\n\\axis bottom ticks numbered from -1 to 1 by 0.2 /\r\n\\setquadratic\r\n\\plot -0.900 0.800 -0.810 1.003 -0.720 1.148 -0.630 1.242 -0.540 1.291 \r\n-0.450 1.301 -0.360 1.280 -0.270 1.232 -0.180 1.166 -0.090 1.086 \r\n0.000 1.000 0.090 0.914 0.180 0.834 0.270 0.768 0.360 0.720 \r\n0.450 0.699 0.540 0.709 0.630 0.758 0.720 0.852 0.810 0.997 \r\n0.900 1.200  /\r\n\\linethickness 0.1truept\r\n\\axis left ticks in andacross from 0.1 to 1.6 by 0.1 /\r\n\\axis bottom ticks in andacross from -1 to 1 by 0.1 /\r\n\\endpicture}$$\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nShown is the graph of a function $f(x)$. Sketch the graph of $f'(x)$\r\nby estimating the derivative at a number of points in the interval:\r\nestimate the derivative at regular intervals from one end of the\r\ninterval to the other, and also at ``special'' points, as when the\r\nderivative is zero. Make sure you indicate any places where the\r\nderivative does not exist.\r\n$$\\vbox{\\beginpicture\r\n\\normalgraphs\r\n\\setcoordinatesystem units <1.8truecm,1.8truecm>\r\n\\setplotarea x from 0 to 5, y from 0 to 4\r\n\\axis left ticks numbered from 0 to 4 by 1 /\r\n\\axis bottom ticks numbered from 0 to 5 by 1 /\r\n\\plot 0 0 2 2 /\r\n\\setquadratic\r\n\\plot 2.000 2.000 2.135 1.747 2.270 1.531 2.405 1.351 2.540 1.209 \r\n2.675 1.103 2.810 1.034 2.945 1.002 3.080 1.007 3.215 1.049 \r\n3.350 1.128 3.485 1.244 3.620 1.396 3.755 1.586 3.890 1.812 \r\n4.025 2.075 4.160 2.375 4.295 2.712 4.430 3.086 4.565 3.497 \r\n4.700 3.945  /\r\n\\linethickness 0.1truept\r\n\\axis left ticks in andacross from 0.2 to 4 by 0.2 /\r\n\\axis bottom ticks in andacross from 0.2 to 5 by 0.2 /\r\n\\endpicture}$$\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind an equation for the tangent line to the graph of $\\ds f(x)=5-x-3x^2$ at the point $x=2$\r\n\\begin{sol}\r\n\t$y=-13x+17$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind a value for $a$ so that the graph of $\\ds f(x)=x^2+ax-3$ has a horizontal tangent line at $x=4$.\r\n\\begin{sol}\r\n\t$-8$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "4def631f7c5e801dacbc2b1802331d73d31ba91a", "size": 12493, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-derivatives/4-3-0-der-function.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4-derivatives/4-3-0-der-function.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4-derivatives/4-3-0-der-function.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.9606557377, "max_line_length": 174, "alphanum_fraction": 0.6650124069, "num_tokens": 4227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683105, "lm_q2_score": 0.8791467722591728, "lm_q1q2_score": 0.7489915559675984}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Compute $e^A$ and $\\cos A$ for the following matrices:\n  \\begin{equation*}\n    (a)\\quad\n    A = \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 2 \\\\\n    \\end{mymatrix},\n    \\quad\n    (b)\\quad\n    A = \\begin{mymatrix}{rr}\n      4  & 2  \\\\\n      -3 & -1 \\\\\n    \\end{mymatrix},\n    \\quad\n    (c)\\quad\n    A = \\begin{mymatrix}{rrr}\n      0 & 1 & 1 \\\\\n      1 & 0 & -1 \\\\\n      -1 & 1 & 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  The cube root is an analytic function. Compute the cube root of the\n  matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      22 & -21 \\\\\n      14 & -13 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Use matrix exponentials to find the solution to the\n  first-order linear differential equation\n  \\begin{equation*}\n    \\begin{mymatrix}{c}\n      x \\\\\n      y\n    \\end{mymatrix}^{\\prime} = \\begin{mymatrix}{rr}\n      0 & -1 \\\\\n      6 & 5\n    \\end{mymatrix} \\begin{mymatrix}{c}\n      x \\\\\n      y\n    \\end{mymatrix}\n  \\end{equation*}\n  with initial value\n  \\begin{equation*}\n    \\begin{mymatrix}{c}\n      x(0) \\\\\n      y(0)\n    \\end{mymatrix} =\\begin{mymatrix}{r}\n      2 \\\\\n      2\n    \\end{mymatrix}.\n  \\end{equation*}\n  Hint: form the matrix exponential $e^{At}$ and then the solution is\n  $e^{At}\\,\\vect{v}_0$, where $\\vect{v}_0$ is the initial vector.\n  \\begin{sol}\n    The solution is\n    \\begin{equation*}\n      e^{At}C = \\begin{mymatrix}{c}\n        8e^{2t} - 6e^{3t} \\\\\n        18e^{3t} - 16e^{2t}\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "0842beb8ff6beeff86d06d67d9ee64e672eed0ca", "size": 1572, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Eigenvalues-Application-Exponential.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Eigenvalues-Application-Exponential.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Eigenvalues-Application-Exponential.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 20.6842105263, "max_line_length": 69, "alphanum_fraction": 0.5298982188, "num_tokens": 614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7489915469641314}}
{"text": "\n\\section{Stack axioms}\n\\Label{sec:stack-axioms}\n\nTo specify the interplay of the stack access functions,\nwe use a set of axioms\\footnote{\nThere is an analogy in geometry:\nEuclid (e.g.\\ \\cite{Fitzpatrick.2008}) invented the use of\naxioms there, but still kept definitions of \\emph{point},\n\\emph{line}, \\emph{plane}, etc.\nHilbert \\cite{Hilbert.1968} recognized that the latter are not\nonly unformalizable, but also unnecessary, and dropped them,\nkeeping only the formal descriptions of relations between them.\n},\nall but one of them having the form of a conditional equation.\n\n\nLet $V$ denote an arbitrary type.\nWe denote by $S_c$ the type of stacks with capacity $c > 0$ of\nelements of type $V$.\nThe aforementioned functions then have the following signatures.\n\n\\begin{align*}\n\\mathrm{init} &:  S_c \\rightarrow S_c, \\\\\n\\mathrm{push} &: S_c\\times V \\rightarrow S_c, \\\\\n\\mathrm{pop} &: S_c \\rightarrow S_c,\\\\\n\\mathrm{top} &: S_c \\rightarrow V, \\\\\n\\mathrm{size} &: S_c \\rightarrow \\mathbb{N}.\\\\\n\\end{align*}\n\nWith $\\mathbb{B}$ denoting the \\emph{boolean}\ntype we will also define two auxiliary functions\n\\begin{align*}\n\\mathrm{empty} &: S_c \\rightarrow \\mathbb{B},\\\\\n\\mathrm{full} &: S_c \\rightarrow \\mathbb{B}.\n\\end{align*}\n\nTo qualify as a stack these functions must satisfy the following rules\nwhich are also referred to as \\emph{stack axioms}.\n\n\\subsection{Stack initialization}\n\nAfter a stack has been initialized its size is~0.\n\\begin{align}\n\\Label{eq:stack-init-size}\n\\mathrm{size}(\\mathrm{init}(s)) &= 0.\n\\end{align}\n\nThe auxiliary functions $\\mathrm{empty}$ and $\\mathrm{full}$\nare defined as follows\n\\begin{align}\n\\Label{eq:empty-stack}\n\\mathrm{empty}(s), & \\qquad\\text{iff}\\qquad \\mathrm{size(s)} = 0,  \\\\\n\\Label{eq:full-stack}\n\\mathrm{full}(s), & \\qquad\\text{iff}\\qquad  \\mathrm{size(s)} = c.\n\\end{align}\n\nWe expect that for every stack $s$ the following condition holds\n\\begin{align}\n\\Label{eq:stack-invariant}\n 0 \\leq \\mathrm{size}(s) \\leq c.\n\\end{align}\n\n\\clearpage\n\n\\subsection{Adding an element to a stack}\n\nTo push an element $v$ on a stack the stack must not be full.\nIf an element has been pushed on an eligible stack, its size increases by~1\n\\begin{align}\n\\Label{eq:stack-size-push}\n\\mathrm{size}(\\mathrm{push}(s, v)) &= \\mathrm{size}(s)+1, \n  &\\text{if}\\quad  \\neg\\mathrm{full}(s).\\\\\n\\intertext{Moreover, the element pushed on a stack is the top element of the resulting stack}\n\\Label{eq:stack-top-push}\n\\mathrm{top}(\\mathrm{push}(s, v)) &= v, \n  &\\text{if}\\quad \\neg\\mathrm{full}(s).\n\\end{align}\n\n\\subsection{Removing an element from a stack}\n\nAn element can only be removed from a non-empty stack.\nIf an element has been removed from an eligible stack the\nstack size decreases by~1\n\\begin{align}\n\\Label{eq:stack-size-pop}\n\\mathrm{size}(\\mathrm{pop}(s)) &= \\mathrm{size}(s)-1,\n  &&\\text{if}\\quad \\neg\\mathrm{empty}(s).\n%\n\\intertext{\nIf an element is pushed on a stack and immediately afterwards\nan element is removed from the resulting stack then the final stack\nis equal to the original stack}\n%\n\\Label{eq:stack-pop-push}\n\\mathrm{pop}(\\mathrm{push}(s, v)) &= s,\n  &&\\text{if}\\quad \\neg\\mathrm{full}(s). \\\\\n\\intertext{Conversely, if an element is removed from a non-empty stack\n  and if afterwards the top element of the original stack is\n  pushed on the new stack\n  then the resulting stack is equal to the original stack.}\n%\n\\Label{eq:stack-push-pop-top}\n\\mathrm{push}(\\mathrm{pop}(s),\\mathrm{top}(s)) &= s, &&\\text{if}\\quad \\neg\\mathrm{empty}(s). \n\\end{align}\n\n\\clearpage\n\n\\subsection{A note on exception handling}\n\nWe don't impose a requirement on \\inl{push(s, v)} if \\inl{s}\nis a full stack, nor on \\inl{pop(s)} or \\inl{top(s)} if \\inl{s} is an\nempty stack.\n%\nSpecifying the behavior in such \\emph{exceptional} situations is a\nproblem by its own; a variety of approaches is discussed in the\nliterature.\n%\nWe won't elaborate further on this issue, but only give an example to warn\nabout ``innocent-looking'' exception specifications that may lead to\nundesired results.\n\nIf we'd introduce an additional error value \\inl{err} in the element type \n$V$ and require \\inl{top(s) = err} if \\inl{s} is empty, we'd be faced\nwith the problem of specifying the behavior of \\inl{push(s, err)}.\n%\nAt first glance, it would seem a good idea to have \\inl{err} just been\nignored by \\inl{push}, i.e.\\ to require\n\\begin{align}\n\\Label{eq:err}\n\\mathrm{push}(s,\\mathrm{err}) & = s.\n\\end{align}\n\nHowever, we then could derive for any non-full and non-empty stack \\inl{s}, that\n\n\\begin{align*}\n\\mathrm{size}(s)\n   &=  \\mathrm{size}(\\mathrm{pop}(\\mathrm{push}(s, \\mathrm{err}))) && \\text{by \\ref{eq:stack-pop-push}}\\\\\n   &=  \\mathrm{size}(\\mathrm{pop}(s)) && \\text{as assumed in \\ref{eq:err}}\\\\\n   &=  \\mathrm{size}(s) - 1 && \\text{by \\ref{eq:stack-size-pop}}\\\\\n\\end{align*}\n%\ni.e.\\ no such stacks could exist, or all \\inl{int} values would be equal.\n\n\n", "meta": {"hexsha": "7fefcafdeed93bce989d199256a3de89b49bbd46", "size": 4853, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/stack/stack-axioms.tex", "max_stars_repo_name": "fraunhoferfokus/acsl-by-example", "max_stars_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2017-06-14T04:17:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T06:07:36.000Z", "max_issues_repo_path": "Informal/stack/stack-axioms.tex", "max_issues_repo_name": "fraunhoferfokus/acsl-by-example", "max_issues_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-10-18T13:30:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T07:10:16.000Z", "max_forks_repo_path": "Informal/stack/stack-axioms.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 33.2397260274, "max_line_length": 105, "alphanum_fraction": 0.7115186483, "num_tokens": 1498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.8175744717487329, "lm_q1q2_score": 0.7489878259040427}}
{"text": "%%% Title:    Formula for Post-2020 Standard Scoring Rule\n%%% Author:   Kyle M. Lang\n%%% Created:  2020-12-17\n%%% Modified: 2020-12-17\n\n\\documentclass[12pt]{article}\n\n\\usepackage[margin=1in]{geometry}\n\\usepackage{amsmath}\n\\usepackage{datetime2}\n\n\\title{Formula for Post-2020 Standard Scoring Formula}\n\\author{Kyle M. Lang}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Definition of Terms}\n\n\\begin{itemize}\n\\item Raw exam score: $X$\n\\item Minimum exam score: $X_0$\n\\item Number of questions: $N_q$\n\\item Number of response options: $N_o$\n\\item Score expected by guessing alone:\\begin{align*}\n    X_g = \\frac{N_q}{N_o}\n  \\end{align*}\n\\item Latent knowledge score\n  \\begin{align*}\n    K = \\frac{X - X_g}{N_q - X_g}\n  \\end{align*}\n\\item Knowledge score required to pass the exam: $K_p$\n\\end{itemize}\n\n\\section{Grade Calculation}\n\n\\begin{align*}\n  \\textit{Grade} =\n  \\begin{cases}\n    X_0 + \\frac{K (5.5 - X_0)}{K_p},~\\text{if}~K < K_p\\\\\n    5.5 + \\left[\\frac{K - K_p}{1 - K_p}\\right] \\times 4.5,~\\text{otherwise}\n  \\end{cases}\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "03baf1b2601a4ee492b7e2abe0e15c9cd84acf12", "size": 1047, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reference/gradingFormula.tex", "max_stars_repo_name": "kylelang/TiU-Exam-Merge", "max_stars_repo_head_hexsha": "1feded752cdeb05f330a5e2fddb27f54276f417c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "reference/gradingFormula.tex", "max_issues_repo_name": "kylelang/TiU-Exam-Merge", "max_issues_repo_head_hexsha": "1feded752cdeb05f330a5e2fddb27f54276f417c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "reference/gradingFormula.tex", "max_forks_repo_name": "kylelang/TiU-Exam-Merge", "max_forks_repo_head_hexsha": "1feded752cdeb05f330a5e2fddb27f54276f417c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2765957447, "max_line_length": 75, "alphanum_fraction": 0.6771728749, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7489220707223299}}
{"text": "\\section{Background}\n\\label{sec:back}\n\nLet $U = \\{ v_1, v_2, \\ldots , v_n \\}$ be a finite set of variables, each with a finite domain, and $V$ be the domain of $U$.\nA \\emph{potential} on $V$ is a function $\\phi$ such that $\\phi(v) \\geq 0$ for each $v \\in V$, and at least one $\\phi(v) > 0$.\nHenceforth, we say $\\phi$ is on $U$ instead of $V$.\nA \\emph{joint probability distribution} is a potential $P$ on $U$, denoted $P(U)$, that sums to one.\nFor disjoint $X,Y \\subseteq U$, a \\emph{conditional probability table} (CPT) $P(X|Y)$ is a potential over $X \\cup Y$ that sums to one for each value $y$ of $Y$.\nFor simplified notation, $\\{ v_1, v_2, \\ldots, v_n \\}$ may be written as $v_1 v_2 \\cdots v_n$, and $X \\cup Y$ as $XY$.\n\nA \\emph{Bayesian network} (BN) \\cite{pear88} is a \\emph{directed acyclic graph} (DAG) ${\\cal B}$ on $U$ together with CPTs $P(v_1 | Pa(v_1))$, $P(v_2|Pa(v_2))$, $\\ldots$, $P(v_n|Pa(v_n))$, where $Pa(v_i)$ denotes the parents (immediate predecessors) of $v_i$ in ${\\cal B}$.\nFor example, Figure \\ref{fig:dag} depicts a BN, where CPTs $P(a),P(b|a),\\ldots,P(m|g,l)$ are not shown.\nWe call $\\cal{B}$ a BN, if no confusion arises.\nThe product of the CPTs for $\\cal{B}$ on $U$ is a joint probability distribution $P(U)$.\n\n\\begin{figure}[htb]\n    \\begin{center}\n    \t\\includegraphics{figures/DAG.png}\n\t\t\\caption{A BN extended from \\cite{madsen99}.}\n\t\t\\label{fig:dag}\n    \\end{center}\n\\end{figure}\n\n\\emph{Variable elimination} (VE) \\cite{zhan94} computes $P(X|Y=y)$, where $X$ and $Y$ are disjoint subsets of $U$, and $Y$ is observed taking value $y$.\nIn VE (given as Algorithm \\ref{alg:ve} below), $\\Phi$ is the set of CPTs for ${\\cal B}$, $X$ is a list of query variables, $Y$ is a list of observed variables, $y$ is the corresponding list of observed values, and $\\sigma$ is an \\emph{elimination ordering} \\cite{Kja90} for variables $U - (XE)$.\nAll elimination orderings in this paper are determined using \\emph{weighted-min-fill} (WMF), which tends to be one of the best heuristics in practice \\cite{koll09}.\nEvidence may not be denoted for simplified notation.\n\n\\begin{algorithm}\n\\caption{Variable elimination}\n\\label{alg:ve}\n\\begin{algorithmic}[1]\n\\Function{Variable Elimination}{$\\Phi$, $X$, $Y$, $y$, $\\sigma$}\n    \\State Delete rows disagreeing with $Y=y$ from $\\phi \\in \\Phi$ \\label{alg:ve_delete}\n    \\While{$\\sigma$ is not empty} \\label{alg:ve_while}\n        \\State Remove the first variable $v$ from $\\sigma$\n        \\State $\\Phi$$ ~=~$ \\Call{sum-out}{$v,\\Phi$}\n    \\EndWhile \\label{alg:ve_end_while}\n    \\State $P(X,Y=y) ~=~ \\prod_{\\phi \\in \\Phi} \\phi$ \\label{alg:ve_posterior}\n    \\Return $P(X,Y=y) / \\sum_X P(X,Y=y)$ \\label{alg:ve_return}\n\\EndFunction\n\\end{algorithmic}\n\\end{algorithm}\n\nVE calls the sum-out algorithm, which eliminates $v$ from a set $\\Phi$ of potentials by multiplying together all potentials involving $v$ and then summing $v$ out of the product.\n\n\\begin{example}\nRun Algorithm \\ref{alg:ve} to compute $P(i,j,k,l,m | d=0)$ in the BN ${\\cal B}$ of Figure \\ref{fig:dag}.\n\\end{example}\n\n\\emph{d-Separation} \\cite{pear88} tests independencies in DAGs and can be presented as follows \\cite{darwiche09}.\nLet $X$, $Y$, and $Z$ be pairwise disjoint sets of variables in a DAG ${\\cal B}$.\nWe say $X$ and $Z$ are \\emph{d-separated} by $Y$, denoted $I(X,Y,Z)$, if at least one variable on every undirected path from $X$ to $Z$ is closed.\nOn a path, there are three kinds of variable $v$:\n\\begin{inparaenum}[(i)]\n\t\\item a \\emph{sequential} variable means $v$ is a parent of one of its neighbours and a child of the other;\n\t\\item a \\emph{divergent} variable is when $v$ is a parent of both neighbours; and\n\t\\item a \\emph{convergent} variable is when $v$ is a child of both neighbours.\n\\end{inparaenum}\nA variable $v$ is either open or closed.\nA sequential or divergent variable is \\emph{closed}, if $v \\in Y$.\nA convergent variable is \\emph{closed}, if $( v \\cup De(v) ) \\cap Y = \\emptyset$.\nA path with a closed variable is \\emph{blocked}; otherwise, it is \\emph{active}.\n[TODO] Inline example testing $I(a,d,k)$ with d-separation.\n\nThe linear implementation of d-separation given in Algorithm \\ref{alg:dsep} \\cite{koll09} has two phases.\nPhase I determines the ancestors $An(Y)$ of $Y$ in the DAG ${\\cal B}$ using the algorithm ANCESTORS (not shown).\nPhase II, uses the output of Phase I to determine all variables reachable from $X$ via active paths.\nThis is more involved, since the algorithm must keep track of whether a variable $v$ is visited from a child, denoted $(\\uparrow,v)$, or visited from a parent, denoted $(\\downarrow,v)$.\nIn Algorithm \\ref{alg:dsep}, $L$ is the set of variables to be visited, $R$ is the set of reachable variables via active paths, and $V$ is the set of variables that have been visited.\n\n\\begin{algorithm}[htb]\n\\caption{\\cite{koll09} Find nodes reachable from $X$ given $Y$ via active paths in DAG ${\\cal B}$}\n\\label{alg:dsep}\n\\begin{algorithmic}[1]\n\\Procedure{Reachable}{$X$,$Y$,${\\cal B}$}\n\t\\LineComment{Phase I: insert $Y$ and all ancestors of $Y$ into $A$}\n\t\\State $An(Y) \\leftarrow \\Call{Ancestors}{Y,{\\cal B}}$\n\t\\State $A \\leftarrow An(Y) \\cup Y$\n\t\\LineComment{Phase II: traverse active paths starting from $X$}\n\t\\For{$v \\in X$} \\Comment{(Node,direction) to be visited}\n\t\t\\State $L \\leftarrow L \\cup \\{(\\uparrow,v)\\}$\n\t\\EndFor\n\t\\State $V \\leftarrow \\emptyset$ \\Comment{(Node,direction) marked as visited}\n\t\\State $R \\leftarrow \\emptyset$ \\Comment{Nodes reachable via active path}\n\t\\While{$L \\neq \\emptyset$} \\Comment{While variables to be checked}\n\t\t\\State Select $(d,v)$ in $L$ \\label{alg:lin_select_dsep}\n\t\t\\State $L \\leftarrow L - \\{(d,v)\\}$\n\t\t\\If{$(d,v) \\notin V$}\n\t\t\t\\If{$v \\notin Y$}\n\t\t\t\t\\State $R \\leftarrow R \\cup \\{v\\}$ \\Comment{$v$ is reachable}\n\t\t\t\\EndIf\n\t\t\t\\State $V \\leftarrow V \\cup \\{(d,v)\\}$ \\Comment{Mark $(d,v)$ as visited}\n\t\t\t\\If{$d = \\uparrow$ and $v \\notin Y$}\n\t\t\t\t\\For{$v_i \\in Pa(v)$}\n\t\t\t\t\t\\State $L \\leftarrow L \\cup \\{(\\uparrow,v_i)\\}$\n\t\t\t\t\\EndFor\n\t\t\t\t\\For{$v_i \\in Ch(v)$}\n\t\t\t\t\t\\State $L \\leftarrow L \\cup \\{(\\downarrow,v_i)\\}$\n\t\t\t\t\\EndFor\n\t\t\t\\ElsIf{$d = \\downarrow$}\n\t\t\t\t\\If{$v \\notin Y$}\n\t\t\t\t\t\\For{$v_i \\in Ch(v)$}\n\t\t\t\t\t\t\\State $L \\leftarrow L \\cup \\{(\\downarrow,v_i)\\}$\n\t\t\t\t\t\\EndFor\n\t\t\t\t\\EndIf\n\t\t\t\t\\If{$v \\in A$}\n\t\t\t\t\t\\For{$v_i \\in Pa(v)$}\n\t\t\t\t\t\t\\State $L \\leftarrow L \\cup \\{(\\uparrow,v_i)\\}$\n\t\t\t\t\t\\EndFor\n\t\t\t\t\\EndIf\n\t\t\t\\EndIf\n\t\t\\EndIf\n\t\\EndWhile\n\t\\Return{$R$}\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{example}\nRun Algorithm \\ref{alg:dsep} to test $I(a,d,k)$ in BN ${\\cal B}$ illustrated in Figure \\ref{fig:dag}.\n\\end{example}\n", "meta": {"hexsha": "735279b444d237d8c2f2a3a663e0f2bb25c441b5", "size": 6554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "B - The Platform/Paper/sections/background.tex", "max_stars_repo_name": "andreeds/cs807-research-tasks", "max_stars_repo_head_hexsha": "6e05e548cfc76302af36cdb81096822b19c84c99", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "B - The Platform/Paper/sections/background.tex", "max_issues_repo_name": "andreeds/cs807-research-tasks", "max_issues_repo_head_hexsha": "6e05e548cfc76302af36cdb81096822b19c84c99", "max_issues_repo_licenses": ["RSA-MD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "B - The Platform/Paper/sections/background.tex", "max_forks_repo_name": "andreeds/cs807-research-tasks", "max_forks_repo_head_hexsha": "6e05e548cfc76302af36cdb81096822b19c84c99", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.2845528455, "max_line_length": 295, "alphanum_fraction": 0.670277693, "num_tokens": 2232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7489220619361588}}
{"text": "BFS and DFS are two of the most universal algorithms for solving practical problems. Each suits better than the other to specific type of problems. \n \\begin{itemize}\n     \\item For BFS, it suits problems that ask the shortest paths( unweighted ) from a certain source node to a certain destination, whether it is single sourced or all-pairs. Or in some cases, the questions requires us only traverse the graph for a certain steps (levels). Because BFS is iterative and can traverse the nodes level by level.\n     \\item For DFS, it is better for the weighted optimization problem, that we are required to count all possible paths or to get the best out of all possible paths. Because DFS has the advantage of saving the result of overlapping subproblem to avoid extra computation.\n     \\item Use either BFS or DFS when we just need to check correctness (whether we can reach a given state to another. \n \\end{itemize}\n \n \\section{Bidirectional Search: Two-end BFS}\n\\label{sec_bidirectional_search}\n\\paragraph{Definition} \nIn normal graph search using BFS/DFS we begin our search in one direction usually from source vertex $s$ toward the goal vertex $t$, but what if we start search form both direction simultaneously. Bidirectional search is a graph search algorithm which find \\textit{smallest path} from source to goal vertex. We just learned that Breadth-first-search suits well for shortest path problem. Because in Level-by-level BFS, it controls the visiting order of nodes by its order to the starting vertex. Therefore, Bidirectional search  runs \\textit{two simultaneous level-by-level BFS searches} which eventually ``meet in the middle\" (when two searches intersect) and terminates. \n\\begin{enumerate}\n    \\item Forward search starts form source/initial vertex $s$ toward goal vertex $t$.\n    \\item Backward search form goal/target vertex  $t$ toward source vertex $s$\n\\end{enumerate}\n\n\\paragraph{Time and Space Complexity} \nSuppose if branching factor of tree is b and distance of goal vertex from source is h, then the normal BFS/DFS searching complexity would be $O(b^h)$. On the other hand, if we execute two search operation then the complexity would be $O(b^{h/2})$ for each search and total complexity would be $O(b^{h/2}+b^{h/2})$ which is far less than $O(b^h)$. Therefore,  in many cases bidirectional search is way faster and dramatically reduce the amount of required exploration. Because we need to save nodes at each level in the queue, the maximum nodes we get at the middle $h/2$ will be $b^h$, this makes the space complexity to $O(b^h)$. \n\n\\paragraph{When and How}\n\\textbf{When} Bidirectional search can find the shortest path successfully if all the paths are assigned uniform costs. \n\n\\textbf{How} When the graph from each side is not balanced: each node has various branch factors.  We take two queues: sourceQueue for BFS in forward direction from source to target and targetQueue which is used to do the BFS from the target towards the source in backward direction. We try to alternate between the two queues: sourceQueue and targetQueue; basically in every iteration we choose the smaller queue for the next iteration for the processing which effectively helps in alternating between the two queues only when the swapping between the two queues is profitable.\n\nThis helps in the following way: As we go deeper into a graph the number of edges can grow exponentially. Since we are approaching in a balanced way, selecting the queue which has smaller number of nodes for the next iteration, we are avoiding processing a large number of edges and nodes by trying to having the intersection point somewhere in the middle.\n\nSince we are processing both the target and source queue we are not going to much depth from any direction, either in forward direction (i.e, while processing source queue) or in backward direction (i.e, target queue which searches from target to source in backward manner).\n\n\\paragraph{Implementation}", "meta": {"hexsha": "7d9a131152fd7a919fd38f8b9631ab0f9b64f561", "size": 3955, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Easy-Book/chapters/other_complete_search.tex", "max_stars_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_stars_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Easy-Book/chapters/other_complete_search.tex", "max_issues_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_issues_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Easy-Book/chapters/other_complete_search.tex", "max_forks_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_forks_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 136.3793103448, "max_line_length": 673, "alphanum_fraction": 0.788369153, "num_tokens": 851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938819, "lm_q2_score": 0.8918110519076929, "lm_q1q2_score": 0.7488840401861898}}
{"text": "\\chapter{Mathematical Background}\\label{chap:AppA}\nIn this part of the appendix we want to discuss some of the mathematical tools we used during the calculations presented in the scope of this thesis in a more formal manner. \nThe part on the York decomposition is mainly inspired by \\cite{Percacci2017}, whereas the conventions for the heat-kernel computations are taken from \\cite{PawlowskiNPgaugeLecture} and extended for the matter part, using the conventions from \\cite{CodelloPercacciRahmede2008}.\n\n\\section{York Decomposition}\nIn the discussion of gauge theories, it is often very useful to decompose the gauge field $A_{\\mu}$ into transversal and longitudinal parts:\n\\begin{align}\n\tA_{\\mu} = A_{\\mu}^{\\mathrm{T}} + \\nabla_{\\mu}\\phi.\n\\end{align}\nThe transversal part is characterized by the fact, that $\\nabla^{\\mu}A_{\\mu}^{\\mathrm{T}} = 0$. Using this decomposition, we are able to separate the pure gauge spin-$0$ degrees of freedom from the physical ones, contained in the spin-$1$ part $A_{\\mu}^{\\mathrm{T}}$.\\\\\nAssuming vanishing boundary terms, integration by parts allows us to change the integration variables in the functional integral, i.\\,e.\n\\begin{align}\n\t\\int_x \\sqrt{g} \\ A_{\\mu}A^{\\mu} = \\int_x \\sqrt{g} \\ A_{\\mu}^{\\mathrm{T}}A^{\\mathrm{T}, \\mu} + \\int_x \\sqrt{g} \\ \\phi\\left(-\\nabla^2\\right)\\phi.\n\\end{align}\nNote, that we have to take care of the Jacobian $J$ of this variable transformation:\n\\begin{align}\n\t\\left(\\dd A_{\\mu}\\right) \\longrightarrow J\\left(\\dd A_{\\mu}^{\\mathrm{T}}\\right)\\left(\\dd\\phi\\right).\n\\end{align}\nTo be able to determine the Jacobian for our transformation, the integration measure needs to be normalized. A quite convenient choice is to evaluate the Gaussian integral over the different fields $\\psi$ and set the result to one:\n\\begin{align}\\label{eqn:york_measure}\n\t\\int\\left(\\dd\\psi\\right) \\exp\\left\\{-\\int\\dd x \\ \\sqrt{g} \\ \\psi^2 \\right\\} = 1,\n\\end{align} \nwhere we are assuming an Euclidean signature and a curved background metric. With this condition we find:\n\\begin{align}\n\t1&=J \\int\\left(\\dd A_{\\mu}^{\\mathrm{T}}\\right) \\operatorname{e}^{-\\int \\dd x \\sqrt{g} \\ A_{\\mu}^{\\mathrm{T}} A^{\\mathrm{T}, \\mu}} \n\t\\int(\\dd\\phi) \\operatorname{e}^{-\\int \\dd x \\sqrt{g} \\  \\phi\\left(-\\nabla^{2}\\right) \\phi} = J\\left(\\operatorname{det}_{\\phi}^{\\prime}\\left(-\\nabla^{2}\\right)\\right)^{-1/2}.\n\\end{align}\nThis allows us to determine the Jacobian $J$ as follows:\n\\begin{align}\n\tJ = \\left(\\operatorname{det}_{\\phi}^{\\prime}\\left(-\\nabla^{2}\\right)\\right)^{1/2}.\n\\end{align}\nThe prime denotes the fact, that the zero mode has to be removed, when computing the determinant to obtain a consistent result. Physically this is in accordance with the fact, that a constant $\\phi$ does not contribute to $A_{\\mu}$.\\\\\nFor our computation in chapters \\ref{chap:EHT} and \\ref{chap:Matter}, we used the background field method, where we assume a linear split of the \\textit{full} metric $g_{\\mu\\nu}$ into a background metric $\\bar{g}_{\\mu\\nu}$ and a fluctuation field $h_{\\mu\\nu}$. There is an analogous way of decomposing the fluctuation field in the background field formalism. First, we split $h_{\\mu\\nu}$ into\n\\begin{align}\n\th_{\\mu\\nu} = h_{\\mu\\nu}^{\\mathrm{T}} + \\frac{1}{d}\\ \\bar{g}_{\\mu\\nu}h,\n\\end{align} \nwhere $h_{\\mu\\nu}^{\\mathrm{T}}$ is traceless, i.\\,e. $\\bar{g}^{\\mu\\nu}h_{\\mu\\nu}^{\\mathrm{T}}=0$ and $h=\\bar{g}^{\\mu\\nu}h_{\\mu\\nu}$. The traceless part can be further decomposed in flat space using the irreducible representations of the Lorentz group with spins 0, 1 and 2 respectively, but in our case a more sophisticated approach, the so-called \\textit{York decomposition} is chosen:\n\\begin{align}\n\th_{\\mu\\nu} = h_{\\mu\\nu}^{\\text{TT}} + \\bar{\\nabla}_{\\mu}\\xi_{\\nu} + \\bar{\\nabla}_{\\nu}\\xi_{\\mu} + \\left(\\bar{\\nabla}_{\\mu}\\bar{\\nabla}_{\\nu} - \\frac{1}{d} \\ \\bar{g}_{\\mu\\nu}\\bar{\\nabla}^2\\right)\\sigma + \\frac{1}{d} \\ \\bar{g}_{\\mu\\nu}h.\n\\end{align}\nHere, $ h_{\\mu\\nu}^{\\text{TT}}$ is a transverse-traceless, spin-2 degree of freedom, $\\xi_{\\mu}$ is transverse and carries a spin-1 d.\\,o.\\,f. and $\\sigma$ and $h$ possess spin-0. As before, we want to find the Jacobian $J$ for this variable transformation:\n\\begin{align}\n\t\\left(\\dd h_{\\mu\\nu}\\right) \\longrightarrow J\t\\left(\\dd h_{\\mu\\nu}^{\\mathrm{TT}}\\right) \\left(\\dd\\xi_{\\mu}\\right)\\left(\\dd\\sigma\\right)\\left(\\dd h\\right).\n\\end{align}\nThis is again possible after specifying a suitable normalization of the functional measure as\n\\begin{align}\n\t\\int (\\dd h_{\\mu\\nu}) \\exp\\left\\{-\\mathcal{G}(h, h)\\right\\} = 1,\n\\end{align}\nwhere $\\mathcal{G}$ is an inner product in the space of symmetric two-tensors, defined as\n\\begin{equation}\n\\begin{aligned} \n\\mathcal{G}(h, h)&= \\int_x \\sqrt{\\bar{g}} \\ \\left(h_{\\mu \\nu} h^{\\mu \\nu}+\\frac{a}{2} h^{2}\\right) \\\\[10pt]\n&= \\int_x \\sqrt{\\bar{g}} \\ \\left[h^{\\mathrm{TT}}_{\\mu \\nu} h^{\\mathrm{TT}, \\mu \\nu}+2 \\xi_{\\mu}\\left(-\\bar{\\nabla}^{2}-\\frac{\\bar{R}}{d}\\right) \\xi^{\\mu}\\right. \\\\\n&+\\left.\\frac{d-1}{d} \\sigma\\left(-\\bar{\\nabla}^{2}\\right)\\left(-\\bar{\\nabla}^{2}-\\frac{\\bar{R}}{d-1}\\right) \\sigma+\\left(\\frac{1}{d}+\\frac{a}{2}\\right) h^{2} \\right] \n\\end{aligned}\n\\end{equation}\nin the case of an Einstein type background metric\\footnote{A metric is of Einstein type, if $R_{\\mu\\nu}$ is a constant multiple of $g_{\\mu\\nu}$, i.\\,e. $R_{\\mu\\nu} = \\frac{1}{d} \\mathcal{R} g_{\\mu\\nu}$.}. This yields\n\\begin{align}\n\tJ=\\left(\\operatorname{det}_{\\xi}\\left(-\\bar{\\nabla}^{2}-\\frac{R}{d}\\right)\\right)^{1 / 2}\\left(\\operatorname{det}_{\\sigma}^{\\prime}\\left(-\\bar{\\nabla}^{2}\\right)\\right)^{1 / 2}\\left(\\operatorname{det}_{\\sigma}\\left(-\\bar{\\nabla}^{2}-\\frac{R}{d-1}\\right)\\right)^{1 / 2}.\n\\end{align}\nNote, that the prime has the same meaning and physical interpretation as in the previous case: If $\\sigma$ is constant, it does not contribute to $h_{\\mu\\nu}$. \\\\\n In both cases, the decomposition of the general gauge field and the York decomposition of the fluctuation field, appropriate rescalings of the fields $\\phi$, $\\xi_{\\mu}$ and $\\sigma$ respectively, help us to cancel the non-trivial Jacobians and to achieve, that all modes have the same mass dimension. For the sake of completeness, we present the rescaled versions of the fields:\n \\begin{align}\n\\hat{\\phi} &= \\sqrt{-\\nabla^2}\\ \\phi \\\\[10pt]\n \\hat{\\xi}_{\\mu} &= \\sqrt{-\\bar{\\nabla}^{2}-\\frac{\\bar{R}}{d}}\\  \\xi_{\\mu} \\\\[10pt]\n  \\hat{\\sigma} &= \\sqrt{-\\bar{\\nabla}^{2}} \\sqrt{-\\bar{\\nabla}^{2}-\\frac{\\bar{R}}{d-1}}\\ \\sigma. \n \\end{align}\n The resulting graviton two-point function, after decomposition of the fluctuation field has the following structure:\n\\begin{equation} \\Gamma^{(2)}_{hh} = \n\\begin{pmatrix}\n\\Gamma^{(2)}_{h^{\\mathrm{TT}}h^{\\mathrm{TT}}} & 0 & 0 & 0 \\\\[10pt]\n0 & \\Gamma^{(2)}_{\\xi\\xi}  & 0 & 0 \\\\[10pt]\n0 & 0 & \\Gamma^{(2)}_{h^{\\mathrm{Tr}}h^{\\mathrm{Tr}}}  & \\Gamma^{(2)}_{h^{\\mathrm{Tr}}\\sigma} \\\\[10pt]\n0 & 0 & \\Gamma^{(2)}_{\\sigma h^{\\mathrm{Tr}}} & \\Gamma^{(2)}_{\\sigma\\sigma} \\\\\n\n\\end{pmatrix}.\n\\end{equation}\n This concludes our discussion of the York decomposition, as a useful tool to simplify calculations in the background field method.\n \\newpage\n \\section{Heat-Kernel Techniques}\\label{sec:heat-kernel}\n\\vspace{-0.2cm}\nWe use heat-kernel techniques to evaluate the r.\\,h.\\,s. of the flow equation (\\ref{eqn:Wetterich}), where we need to compute the functional trace over functions depending on the Laplacian on a curved background. In general, the method can be understood as a curvature expansion on a flat background. \\\\\nThe general formula to compute such traces is given by\n\\begin{align}\n\t\\operatorname{Tr} f(\\Delta)= N \\  \\int\\kern-1.3em\\sum_{\\ell} \\rho(\\ell) f(\\lambda(\\ell)),\n\t\\label{eqn:heat-kernel}\n\\end{align}\nwith some normalization $N$, the spectral values $\\lambda(\\ell)$ and their corresponding multiplicities $\\rho(\\ell)$. \\\\\nOn flat backgrounds, the computation of (\\ref{eqn:heat-kernel}) is simply a standard momentum integral, whereas on curved backgrounds, consider for example a four-sphere $\\mathbb{S}^4$ with constant background curvature $r = \\frac{\\bar{\\mathcal{R}}}{k^2} > 0$, the spectrum of the Laplacian is discrete and we need to sum over all spectral values. \\\\\nFor our example of $\\mathbb{S}^4$, we have\n\\begin{align}\n\t\\lambda(\\ell) = \\frac{\\ell(3+\\ell)}{12}r \\qquad \\text{and} \\qquad \\rho(\\ell) = \\frac{(2\\ell + 3)(\\ell+2)!}{6\\ell!}.\n\\end{align}\nThe normalization is then given by the inverse of the four-sphere-volume $ \\left(V_{\\mathbb{S}^4}\\right)^{-1} = \\frac{k^4r^2}{384\\pi^2}$. This leads us to the formula for our computation of the r.\\,h.\\,s. of the flow equation on a background with constant positive curvature:\n\\begin{align}\n\\operatorname{Tr} f(\\Delta)=\\frac{k^{4} r^{2}}{384 \\pi^{2}} \\sum_{\\ell=0}^{\\infty} \\frac{(2 \\ell+3)(\\ell+2) !}{6 \\ell !} f\\left(\\frac{\\ell(3+\\ell)}{12} r\\right).\n\\end{align}\nThis is called spectral sum. For large curvatures $r$ the convergence of the series is rather fast, whereas in the limit $r\\rightarrow 0$ one finds exponentially slow convergence.\\\\\nThe master equation for heat-kernel computations reads\n\\begin{align}\n\t\\operatorname{Tr} f(\\Delta)=\\frac{1}{(4 \\pi)^{\\frac{d}{2}}}\\left[\\mathbf{B}_{0}(\\Delta) Q_{2}[f(\\Delta)]+\\mathbf{B}_{2}(\\Delta) Q_{1}[f(\\Delta)]\\right]+\\mathcal{O}\\left(\\mathcal{R}^{2}\\right),\n\\label{eqn:master-eqn}\n\\end{align}\nwith the heat-kernel coefficients \n\\begin{align}\n\t\\mathbf{B}_{n}(\\Delta)=\\int_x  \\sqrt{g} \\  \\operatorname{Tr} \\mathbf{b}_{n}(\\Delta)\n\\end{align}\nand \n\\begin{align}\n\tQ_{n}[f(x)]=\\frac{1}{\\Gamma(n)} \\int \\dd x \\ x^{n-1} f(x).\\label{eqn:Qfunc}\n\\end{align}\n\\newpage\nFor computations on $\\mathbb{S}^4$, the values for the heat kernel coefficients $\\mathbf{B}_n(\\Delta)$ are presented in the following:\n\\begin{table}[H]\n\t\\centering\n\t\\setlength{\\tabcolsep}{5mm}\n\t\\setlength\\extrarowheight{2mm}\n\t\\begin{tabular}{c | c c c}\n\t   & TT & TV & S\\\\ \\hline\n\t   $\\operatorname{Tr} \\mathbf{b}_{0}$ & 5 &  3 & 1\\\\\n\t  $\\operatorname{Tr} \\mathbf{b}_{2}$ & $-\\frac{5}{6}\\mathcal{R}$ & $\\frac{1}{4}\\mathcal{R}$& $\\frac{1}{6}\\mathcal{R}$\\\\\n\t\\end{tabular}\n\t\\caption{Heat-kernel coefficients for transverse-traceless tensors (TT), transverse vectors (TV) and scalars (S) for computations on $\\mathbb{S}^4$.}\n\\end{table}\n\nThe basic idea of the proof of equation (\\ref{eqn:heat-kernel}) is based on the Laplace transform\n\\begin{align}\n\tf(\\Delta) = \\int_0^{\\infty} \\dd s \\ \\operatorname{e}^{-s\\Delta}\\tilde{f}(s).\n\\end{align}\nWe insert this definition of the Laplace transform into equation (\\ref{eqn:heat-kernel}) and find\n\\begin{align}\n\t\\operatorname{Tr} f(\\Delta)=\\int_{0}^{\\infty} \\dd s \\ \\tilde{f}(s) \\operatorname{Tr} \\operatorname{e}^{-s \\Delta}.\n\\label{eqn:hk2}\n\\end{align}\nThe trace on the r.\\,h.\\,s. is explicitly the trace of the heat-kernel. We expand this term as follows:\n\\begin{align}\n\t\\operatorname{Tr} \\operatorname{e}^{-s \\Delta}=\\frac{1}{(4 \\pi)^{\\frac{d}{2}}} \\sum_{n=0}^{\\infty} s^{\\frac{n-d}{2}} \\mathbf{B}_{n}(\\Delta).\n\\end{align}\nThis is where the heat-kernel coefficients $\\mathbf{B}_n$ become important. We proceed by inserting this expanded version of the heat-kernel trace into equation (\\ref{eqn:hk2}) and find:\n\\begin{equation}\n\\begin{aligned} \n\\operatorname{Tr} f(\\Delta) &=\\frac{1}{(4 \\pi)^{\\frac{d}{2}}} \\sum_{n=0}^{\\infty} \\mathbf{B}_{n}(\\Delta) \\int_{0}^{\\infty} \\dd s \\ s^{\\frac{n-d}{2}} \\tilde{f}(s) \\\\[10pt] \n&=\\frac{1}{(4 \\pi)^{\\frac{d}{2}}} \\sum_{n=0}^{\\infty} \\frac{1}{\\Gamma\\left(\\frac{d-k}{2}\\right)} \\mathbf{B}_{n}(\\Delta) \\int_{0}^{\\infty} \\dd t \\ t^{\\frac{d-n}{2}-1} f(t) \\\\[10pt]\n &=\\frac{1}{(4 \\pi)^{\\frac{d}{2}}} \\sum_{n=0}^{\\infty} \\mathbf{B}_{n}(\\Delta) Q_{\\frac{d-n}{2}}[f(t)].\n\\end{aligned}\n\\end{equation}\nThis completes the derivation of the master equation (\\ref{eqn:master-eqn}) for heat-kernel computations. Note, that we used the definition of the $Q$-functionals, given in equation (\\ref{eqn:Qfunc}) and the relation $\\int_{s} s^{-x} \\tilde{f}(x)=\\frac{1}{\\Gamma(x)} \\int_{z} z^{x-1} f(z)$.\n\n\nWhen investigating matter fields, such as in chapter \\ref{chap:Matter}, we often encounter kinetic operators of the form $\\tilde{\\Delta} = -\\nabla^2\\cdot\\mathbbm{1} +  \\mathbf{E}$, where $\\mathbf{E}$ is a linear map acting on the spacetime and the internal indices of the fields. In this notation, $\\mathbbm{1}$ has to be understood as the identity in the respective field space. \\\\\nIf $\\left[\\Delta, \\mathbf{E}\\right] = 0$\\footnote{In the case of $\\left[\\Delta, \\mathbf{E}\\right] \\neq 0$, there would be additional terms including (higher order) commutators of $\\Delta$ and $\\mathbf{E}$ due to the Baker-Campbell-Hausdorff formula.}, we can relate the coefficients of the modified Laplacian $\\tilde{\\Delta}$ and those of the initially considered operator $-\\nabla^2$ via\n\\begin{align}\n\t\\operatorname{Tr} \\operatorname{e}^{-s\\left(-\\nabla^{2}+\\mathbf{E}\\right)}=\\frac{1}{(4 \\pi)^{\\frac{d}{2}}} \\sum_{k, l=0}^{\\infty} \\frac{(-1)^{\\ell}}{\\ell !} \\int_x \\sqrt{g} \\ \\operatorname{Tr} \\mathbf{b}_{k}(\\Delta) \\mathbf{E}^{\\ell} s^{k+\\ell-2}.\n\\end{align}\nThis results in the following, modified values for the coefficients we are interested in:\n\\begin{equation}\n\\begin{aligned}\n\t\\mathbf{b}_0 &= \\mathbbm{1} \\\\[10pt]\n\t\\mathbf{b}_2 &= \\frac{\\mathcal{R}}{6}\\cdot\\mathbbm{1} - \\mathbf{E}.\n\t\\label{eqn:coefficients}\n\\end{aligned}\t\n\\end{equation}\nFor further study and a more general treatment of the modified Laplacians, including higher order coefficients,\\ \\cite{CodelloPercacciRahmede2008, Percacci2017} are recommended.", "meta": {"hexsha": "01ecc199a0d5e84992a05554846f2ed4f5299e02", "size": 13374, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/appendices/A_maths.tex", "max_stars_repo_name": "mathieukaltschmidt/BSc-Thesis", "max_stars_repo_head_hexsha": "d930ee60ab526835c904252e68272408f3d6a16f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-22T15:05:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-22T15:05:57.000Z", "max_issues_repo_path": "Thesis/appendices/A_maths.tex", "max_issues_repo_name": "mathieukaltschmidt/BSc-Thesis", "max_issues_repo_head_hexsha": "d930ee60ab526835c904252e68272408f3d6a16f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Thesis/appendices/A_maths.tex", "max_forks_repo_name": "mathieukaltschmidt/BSc-Thesis", "max_forks_repo_head_hexsha": "d930ee60ab526835c904252e68272408f3d6a16f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-25T05:06:03.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-25T05:06:03.000Z", "avg_line_length": 82.0490797546, "max_line_length": 392, "alphanum_fraction": 0.685434425, "num_tokens": 4674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7488032595371841}}
{"text": "\\chapter{Mathematical Functions}\\label{math-functions.appendix}\n\nThis appendix provides the definition of several mathematical\nfunctions used throughout the manual.\n\n\\section{Beta}\\label{beta-appendix.section}\n\nThe beta function, $\\mbox{B}(\\alpha,\\beta)$, computes the normalizing\nconstant for the beta distribution, and is defined for $a > 0$ and $b\n> 0$ by\n%\n\\[\n\\mbox{B}(a,b)\n\\ = \\\n\\int_0^1 u^{a - 1} (1 - u)^{b - 1} \\, du\n\\ = \\\n\\frac{\\Gamma(a) \\, \\Gamma(b)}{\\Gamma(a+b)} \\, .\n\\]\n\n\\section{Incomplete Beta}\\label{inc-beta-appendix.section}\n\nThe incomplete beta function, $\\mathrm{B}(x; a, b)$, is defined for\n$x \\in [0, 1]$ and $a, b \\geq 0$ such that $a + b \\neq 0$ by\n\\[\n\\mathrm{B}(x; \\, a, b)\n\\ = \\\n\\int_0^x u^{a -  1} \\, (1 - u)^{b - 1} \\, du,\n\\]\n%\nwhere $\\mathrm{B}(a, b)$ is the beta function defined in\n\\refsection{beta-appendix}.  If $x = 1$, the incomplete beta function\nreduces to the beta function, $\\mathrm{B}(1; a, b) = \\mathrm{B}(a,\nb)$.\n\nThe regularized incomplete beta function divides the incomplete beta\nfunction by the beta function,\n\\[\nI_x(a, b) \\ = \\ \\frac{\\mathrm{B}(x; \\, a, b)}{B(a, b)} \\, .\n\\]\n\n\n\n\n\\section{Gamma}\\label{gamma-appendix.section}\n\nThe gamma function, $\\Gamma(x)$, is the generalization of the\nfactorial function to continuous variables, defined so that for\npositive integers $n$,\n\\[\n\\Gamma(n+1) = n!\n\\]\n%\nGeneralizing to all positive numbers and non-integer negative numbers,\n\\[\n\\Gamma(x) = \\int_0^{\\infty} u^{x - 1} \\exp(-u) \\, du.\n\\]\n\n\n\\section{Digamma}\\label{digamma-appendix.section}\n\nThe digamma function $\\Psi$ is the derivative of the $\\log \\Gamma$\nfunction,\n%\n\\[\n\\Psi(u)\n\\ = \\\n\\frac{d}{d u} \\log \\Gamma(u)\n\\ = \\\n\\frac{1}{\\Gamma(u)} \\ \\frac{d}{d u} \\Gamma(u).\n\\]\n", "meta": {"hexsha": "ddd49ea3dfef5e274cb96b3538cfbeaf57b67716", "size": 1711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/docs/functions/math.tex", "max_stars_repo_name": "yao-yl/stan", "max_stars_repo_head_hexsha": "b98073b6a9ee835f21c103f23ea5cec652ba7e92", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/docs/functions/math.tex", "max_issues_repo_name": "yao-yl/stan", "max_issues_repo_head_hexsha": "b98073b6a9ee835f21c103f23ea5cec652ba7e92", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/docs/functions/math.tex", "max_forks_repo_name": "yao-yl/stan", "max_forks_repo_head_hexsha": "b98073b6a9ee835f21c103f23ea5cec652ba7e92", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-08-28T12:09:08.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-28T12:09:08.000Z", "avg_line_length": 24.0985915493, "max_line_length": 70, "alphanum_fraction": 0.6458211572, "num_tokens": 592, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904956, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7487756184539679}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Sums of squares}\\label{sec:chi-squared}\n\nLet $X\\sim N(\\mu,\\sigma^2)$ where $\\mu$ is unknown, and let $X_1,X_2,\\ldots,X_n$ be a random sample from the distribution of $X$. The usual test statistic for deciding between $H_0:\\mu=\\mu_0$ and a suitable alternative is the standardised sum\n\\[\nZ = \\sum_{i=1}^n\\left(\\frac{X_i-\\mu_0}{\\sigma}\\right)\\ \\sim N(0,1)\\text{ under $H_0$.}\n\\]\n\nAnother test statistic is provided the standardized \\emph{sum-of-squares},\n\\[\nT = \\sum_{i=1}^n\\left(\\frac{X_i-\\mu_0}{\\sigma}\\right)^2\\ \\sim\\chi^2_n \\text{ under $H_0$.}\n\\]\nwhere $\\chi^2_n$ is the \\emph{chi-squared distribution} with $n$ degrees of freedom.\n\\begin{remark}\nIf $\\sigma^2$ is unknown we replace it by the sample variance $s^2$, in which case $T\\sim\\chi^2_{n-1}$.\n\\end{remark}\n%-----------------------------\n\\subsection{The $\\chi^2$ distribution}\n\n\\begin{definition}\\label{defn:chisquared_dist}\nThe $\\chi^2_{n}$ distribution is defined by the PDF\n\\[\nf(x) = \\begin{cases}\n\t\\displaystyle\\frac{1}{\\Gamma(n/2)2^{n/2}}\\,x^{n/2-1} e^{-x/2} & \\text{for $x>0$}, \\\\\n\t0\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t& \\text{otherwise,}\n\\end{cases}\n\\]\nwhere the parameter $n$ is called the \\emph{degrees of freedom}.\n\\end{definition}\nThe $\\chi^2_{n}$ distribution is a special case of the $\\Gamma(k,\\theta)$ distribution, where $k=n/2$ and $\\theta=2$ is a scale parameter. In particular, $\\expe(X) = n$ and $\\var(X)=2n$.\n%\nThe following theorem (which we shall not prove) asserts that the sum-of-squares of $n$ independent standard normal variables has the $\\chi^2_n$-distribution.\n\\begin{theorem}\nIf $Z_1,Z_2,\\ldots,Z_n$ are independent standard normal variables then $\\displaystyle\\sum_{i=1}^n Z_i^2\\sim\\chi^2_n$.\n\\end{theorem}\n\n\\begin{example}\nA quality control supervisor at a paint factory knows that the exact amount each tin contains will vary due to certain uncontrollable factors that affect the amount of fill. The mean fill is important, but equally important is the variation of each fill. If the variance $\\sigma^2$ of the fill is large, some tins will contain too much paint, and others too little. A regulatory agency specifies that the variance of the amount of fill in $250ml$ tins should be less than $3ml$. To determine whether or not the process is meeting this specification, the supervisor randomly selects 10 tins and measures the contents of each tin. The mean fill over the sample is found to be $250.78ml$, and the sample variance is $s^2 = 1.03$. Do the data indicate that the factory is operating within the regulatory limits?\n\\begin{solution}\nWe wish to test the null hypothesis $H_0:\\sigma^2 = 3$ against the alternative $H_1:\\sigma^2 < 3$. We assume that the distribution of the fill amounts is approximately normal, and consider the test statistic \n\\[\nT = \\sum_{i=1}^{n} \\left(\\frac{X_i-\\bar{X}}{\\sigma}\\right)^2 = \\frac{(n-1)s^2}{\\sigma^2},\n\\]\nwhere $s^2$ is the sample variance of the fill amounts. Taking $n=10$, the distribution of our test statistic under the null hypothesis $H_0:\\sigma^2 = 3$ is\n\\[\nT \\sim \\chi^2_9.\n\\]\n\\bit\n\\it From tables, the critical value for a lower-tailed test at $\\alpha=0.05$ is $T_{0.95} = 3.326$.\n\\it The observed value of the test statistic (under the null hypothesis) is\n\\[\nT = \\frac{(n-1)s^2}{\\sigma^2} = \\frac{9\\times 1.03}{3} = 3.09.\n\\]\n\\eit \nThe test statistic lies in the rejection region, so the supervisor can reject $H_0:\\sigma^2=3$ and conclude that the variance of the fill amounts is less than $3$. The supervisor can be confident that the factory is operating within the desired limits of variability. \n\\end{solution}\n\\end{example}\n\n%-----------------------------\n\\subsection{The $F$ distribution}\n\\begin{definition}\nLet $T_1$ and $T_2$ be independent random variables with $T_1\\sim\\chi^2_m$ and $T_2\\sim\\chi^2_n$. The distribution of the ratio\n\\[\nF = \\frac{T_1/m}{T_2/n}.\n\\]\nis called the \\emph{$F$-distribution with $m$ and $n$ degrees of freedom}, and denoted by $F\\sim F_{m,n}$.\n\\end{definition}\n\n\\begin{example}\nA researcher wants to compare the metabolic rates of mice subjected to different drugs. The weight of the mice may affect their metabolic rates, so the researcher wishes to obtain mice that are relatively homogeneous with respect to weight. Five hundred mice will be needed to complete the study. Currently, 16 mice from supplier 1 and another 13 mice from supplier 2 are available for comparison. The researcher weighs these mice and finds that the sample standard deviations are $s_1=0.2021$ and $s_2=0.0982$ respectively. Is there sufficient evidence to indicate a significant difference in the variance of the weight of mice obtained from the two suppliers at the $\\alpha=0.1$ level?\n\\begin{solution}\nLet $\\sigma^2_1$ and $\\sigma^2_2$ be the population variances for mice from Supplier 1 and Supplier 2 respectively. The null hypothesis is $H_0:\\sigma^2_1=\\sigma^2_2$, and our test statistic is the ratio of the sample variances,\n\\[\nF = \\frac{s^2_1}{s^2_2}\n\\qquad\\text{where}\\quad \n\\frac{(m-1)s^2_1}{\\sigma_1}\\sim\\chi^2_{m-1}\n\\quad\\text{and}\\quad \n\\frac{(n-1)s^2_2}{\\sigma_2}\\sim\\chi^2_{n-1}.\n\\]\nwith $m=16$ and $n=13$. Under $H_0:\\sigma^2_1=\\sigma^2_2$ we have that $F\\sim F_{15,12}$.\n\\bit\n\\it We reject $H_0$ if the observed $F$-ratio exceeds the tabulated value $F_{1-\\alpha/2}=F_{0.95} = 2.616$.\n\\it The observed value is $F=(0.2021)^2/(0.0982)^2=4.236$.\n\\eit\nThe observed value lies in the rejection region, so we reject the null hypothesis and conclude that the weights of mice from supplier 2 tend to be more homogeneous that the weights of mice from supplier 1.\n\n\\bigskip\nNote: $F_{0.975} = 3.277$, $F_{0.99} = 4.155$,  $F_{0.995} = 4.721$. Thus we would reject $H_0$ at $\\alpha=0.05$ and $\\alpha=0.02$, but retain $H_0$ at $\\alpha=0.01$.\n\\end{solution}\n\\end{example}\n\n%-----------------------------\n\\subsection{The non-central $\\chi^2$ distribution}\n\n\\begin{definition}\nLet $X_1,X_2,\\ldots,X_n$ be independent random variables with $X_i\\sim N(\\mu_i,1)$. The distribution of the sum-of-squares\n\\[\nW=\\sum_{i=1}^n X_i^2\n\\]\nis called the \\emph{non-central chi-squared distribution}, with $n$ degrees of freedom and non-centrality parameter \n\\[\n\\lambda = \\sum_{i=1}^n \\mu_i^2.\n\\]\n\\end{definition}\nWe write this as $W\\sim\\chi^2_n(\\lambda)$, in which case\n\\[\n\\expe(W)=n+\\lambda \\quad\\text{and}\\quad \\var(W)=2(n+2\\lambda).\n\\]\nWhen $\\lambda=0$, all $\\mu_i$ must be zero and the $\\chi^2_n(\\lambda)$ distribution reduces to the ordinary $\\chi^2_n$ distribution. Any non-zero mean $\\mu_i$ increases the value of $\\lambda$ and hence increases $\\expe(W)$ and $\\var(W)$ compared to those of the ordinary $\\chi^2_n$ distribution. \n\n\n%%--------------------------------------------------\n%\\subsubsection*{Sums of squares}\n%\n%Let $X\\sim N(\\mu,\\sigma^2)$. If $\\mu$ is unknown but $\\sigma^2$ is known, a test statistic for $H_0:\\mu=\\mu_0$ against a suitable alternative is the standardized \\emph{sum-of-squares},\n%\\[\n%T = \\sum_{i=1}^n\\left(\\frac{X_i-\\mu_0}{\\sigma}\\right)^2\\ \\sim\\chi^2_n \\text{ under $H_0$.}\n%\\]\n%\n%\\bit\n%\\it If $\\sigma^2$ is also unknown we replace it by the sample variance $s^2$, in which case $T\\sim\\chi^2_{n-1}$.\n%\\it If $\\mu\\neq\\mu_0$, then $T\\sim\\chi^2_n(\\lambda)$ where $\\lambda= n(\\mu-\\mu_0)^2$.\n%\\eit\n\n\n", "meta": {"hexsha": "7616050cf0ef7e8b8010a8a841e403e1c0dee03b", "size": 7252, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/11B_chi_squared.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/11B_chi_squared.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/11B_chi_squared.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 56.65625, "max_line_length": 807, "alphanum_fraction": 0.6960838389, "num_tokens": 2287, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8872046011730965, "lm_q1q2_score": 0.7487076178938323}}
{"text": "\\section{Bézier curves}\\label{sec:bezier-curves}\nTo achieve a smooth, parametric curve, widely used in computer graphics, animation and font creation, the Bézier curves are used.\nThey are named after Pierre Etienne Bézier (1910-1999) --- a French engineer and mathematician with merits in the field of mechanical engineering.\n\nThe Bézier curves are based on the \\textit{Berenstein polynomial basis}, which was \"introduced 100 years ago as a means to constructively prove the ability of polynomials to approximate any continuous function, to any desired accuracy, over a prescribed interval\"~\\cite{farouki2012bernstein}.\nIn other words, this is the constructive proof of the \\textit{Weierstrass theorem} (\\textit{approximation theorem}), which \"states that the continuous function $f(x)$ on an interval $[a, b]$ and a tolerance $\\epsilon > 0$, a polynomial $p_n(x)$ of sufficiently high degree $n$ exists, such that:\n\n\\begin{equation}\n    \\mid f(x) - p_n(x) \\mid \\leq \\epsilon, \\quad \\forall x \\in \\left[ a,b \\right]\\label{eq:weierstrass-error}\n\\end{equation}\n\nIn other words, polynomials can uniformly approximate any function that is merely continuous over a closed interval\"~\\cite{farouki2012bernstein}.\nIf so, some of the properties for the Bézier curves are derived immediately, for example, it is known that the basis functions are real, the curve generally follows the shape of the control polygon, the first and last points on the curve are coincident with the first and last points of the control polygon, and so on~\\cite{bezier-curves}.\n\nThe Bézier curve of $n+1$ control points are defined in~\\cite{farouki2012bernstein} as:\n\\begin{equation}\n    r(t) = \\sum_{k=0}^n p_k b_k^n(t),  \\quad t \\in [0,1]\\label{eq:bezier-control-points}\n\\end{equation}\n\nWhere the $p_0,\\dots,p_n$ are the \\textit{control points} and $b_k^n$ is the Berenstein polynomial:\n\\begin{equation}\n    b_k^n(t) = \\binom{n}{k} t^k (1-t)^{n-k}, \\quad \\binom{n}{k} = \\frac{n!}{k!(n-k)!}\\label{eq:berenstrain-polynomial}\n\\end{equation}\n\nFor example, the two-dimensional Bézier curve is described as a pair of a polynomials:\n\\begin{equation}\n    (x,y) = \\left( \\sum_{k=0}^n x_{k} b_k^n(t), \\sum_{k=0}^n y_{k} b_k^n(t) \\right)\\label{eq:bezier-point}\n\\end{equation}\n\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.4\\linewidth,scale=0.4]{resources/bezier-curve-example.png}\n    \\captionof{figure}{Example of Bézier curve fitting to the control points from~\\cite{farouki2012bernstein}}\n    \\label{fig:bezier-example}\n\\end{figure}\n\nThe control points $p_0,\\dots,p_n$ shape the control polygon for the Bézier curve, where the first and the last points on the Bézier curve are coincident with the control polygon (detailed proof and mathematical derivation can be found in~\\cite{farouki2012bernstein}).\nThe properties of the Bézier curve allow for creating the smooth shape, that is going through a set of predefined points and the curve is trying to `follow' the polygon.\nThis makes this solution convenient from the point of view of this work because the prepared bot is expected to make moves in a human-like manner, so the moves should be smooth and look natural.An example of the control polygon with the Bézier curve shaped by it can be seen in Fig.~\\ref{fig:bezier-example} from~\\cite{farouki2012bernstein}.\n", "meta": {"hexsha": "13414189adead400e9193900c929a25de018e61a", "size": 3295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chapters/theory/bezier-curves.tex", "max_stars_repo_name": "Mouse-BB-Team/Thesis", "max_stars_repo_head_hexsha": "24fe0f9dca4fa0b18137fdebd976feef9997d895", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "thesis/chapters/theory/bezier-curves.tex", "max_issues_repo_name": "Mouse-BB-Team/Thesis", "max_issues_repo_head_hexsha": "24fe0f9dca4fa0b18137fdebd976feef9997d895", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thesis/chapters/theory/bezier-curves.tex", "max_forks_repo_name": "Mouse-BB-Team/Thesis", "max_forks_repo_head_hexsha": "24fe0f9dca4fa0b18137fdebd976feef9997d895", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 82.375, "max_line_length": 341, "alphanum_fraction": 0.7605462822, "num_tokens": 928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7487076075344746}}
{"text": "\\item \\points{35} {\\bf Semi-supervised EM}\n\n\\def\\zsi{z^{(i)}}\n\\def\\xsi{x^{(i)}}\n\nExpectation Maximization (EM) is a classical algorithm for unsupervised learning (\\emph{i.e.,} learning with hidden or latent variables). In this problem we will explore one of the ways in which EM algorithm can be adapted to the semi-supervised setting, where we have some labeled examples along with unlabeled examples.\n\nIn the standard unsupervised setting, we have $\\nexp \\in \\mathbb{N}$ unlabeled examples $\\{x^{(1)},\\ldots,x^{(\\nexp)}\\}$. We wish to learn the parameters of $p(x,z;\\theta)$ from the data, but $\\zsi$'s are not observed. The classical EM algorithm is designed for this very purpose, where we maximize the intractable $p(x;\\theta)$ indirectly by iteratively performing the E-step and M-step, each time maximizing a tractable lower bound of $p(x;\\theta)$. Our objective can be concretely written as:\n\n\\begin{align*}\n    \\ell_{\\text{unsup}}(\\theta) &= \\sum_{i=1}^\\nexp \\log p(\\xsi;\\theta) \\\\\n    &= \\sum_{i=1}^\\nexp \\log \\sum_{\\zsi} p(\\xsi,\\zsi;\\theta)\n\\end{align*}\n\n\nNow, we will attempt to construct an extension of EM to the semi-supervised setting. Let us suppose we have an \\emph{additional} $\\tilde{\\nexp} \\in \\mathbb{N}$ labeled examples $\\{(\\tilde{x}^{(1)},\\tilde{z}^{(1)}),\\ldots,(\\tilde{x}^{(\\tilde{\\nexp})},\\tilde{z}^{(\\tilde{\\nexp})})\\}$ where both $x$ and $z$ are observed. We want to simultaneously maximize the marginal likelihood of the parameters using the unlabeled examples, and full likelihood of the parameters using the labeled examples, by optimizing their weighted sum (with some hyperparameter $\\alpha$). More concretely, our semi-supervised objective $\\ell_\\text{semi-sup}(\\theta)$ can be written as:\n%\n\\begin{align*}\n    \\ell_\\text{sup}(\\theta) &= \\sum_{i=1}^{\\tilde{\\nexp}} \\log p(\\tilde{x}^{(i)},\\tilde{z}^{(i)};\\theta) \\\\\n    \\ell_{\\text{semi-sup}}(\\theta) &= \\ell_\\text{unsup}(\\theta) + \\alpha \\ell_\\text{sup}(\\theta)\n\\end{align*}\n%\nWe can derive the EM steps for the semi-supervised setting using the same approach and steps as before. You are \\emph{strongly encouraged} to show to yourself (no need to include in the write-up) that we end up with:\n\n\\subsubsection*{E-step (semi-supervised)}\n\nFor each $i \\in \\{1,\\ldots,\\nexp\\}$, set\n\\begin{align*}\n    Q_i^{(t)}(\\zsi) := p(\\zsi|\\xsi;\\theta^{(t)})\n\\end{align*}\n\n\\subsubsection*{M-step (semi-supervised)}\n\n\\begin{align*}\n    \\theta^{(t+1)} &:= \\arg\\max_\\theta\\left[ \\sum_{i=1}^\\nexp\\left( \\sum_{\\zsi} Q^{(t)}_i(\\zsi) \\log \\frac{ p(\\xsi, \\zsi;\\theta) }{ Q^{(t)}_i(\\zsi)}\\right)  + \\alpha \\left(\\sum_{i=1}^{\\tilde{\\nexp}} \\log p(\\tilde{x}^{(i)},\\tilde{z}^{(i)};\\theta)\\right)\\right]\n\\end{align*}\n\n\\begin{enumerate}\n  \\input{semi_supervised_em/01-convergence}\n\\ifnum\\solutions=1 {\n  \\input{semi_supervised_em/01-convergence-sol}\n} \\fi\n\n\\end{enumerate}\n\n\n\\subsubsection*{Semi-supervised GMM}\nNow we will revisit the Gaussian Mixture Model (GMM), to apply our semi-supervised EM algorithm. Let us consider a scenario where data is generated from $k \\in \\mathbb{N}$ Gaussian distributions, with unknown means $\\mu_j \\in \\R^\\di$ and covariances $\\Sigma_j \\in \\mathbb{S}_+^\\di$ where $j \\in \\{1,\\ldots,k\\}$. We have $\\nexp$ data points $\\xsi \\in \\R^\\di, i \\in \\{1,\\ldots,\\nexp\\}$, and each data point has a corresponding latent (hidden/unknown) variable $\\zsi \\in \\{1,\\ldots,k\\}$ indicating which distribution $\\xsi$ belongs to. Specifically, $\\zsi \\sim \\text{Multinomial}(\\phi)$, such that $\\sum_{j=1}^k\\phi_j = 1$ and $\\phi_j \\ge 0$ for all $j$, and $\\xsi|\\zsi \\sim \\mathcal{N}\\left(\\mu_{\\zsi}, \\Sigma_{\\zsi}\\right)$ i.i.d. So, $\\mu$, $\\Sigma$, and $\\phi$ are the model parameters.\n\nWe also have additional $\\tilde{\\nexp}$ data points $\\tilde{x}^{(i)} \\in \\R^\\di, i \\in \\{1,\\ldots,\\tilde{\\nexp}\\}$, and an associated \\emph{observed} variable $\\tilde{z}^{(i)} \\in \\{1,\\ldots,k\\}$ indicating the distribution $\\tilde{x}^{(i)}$ belongs to. Note that $\\tilde{z}^{(i)}$ are known constants (in contrast to $\\zsi$ which are unknown \\emph{random} variables). As before, we assume $\\tilde{x}^{(i)}|\\tilde{z}^{(i)} \\sim \\mathcal{N}\\left(\\mu_{\\tilde{z}^{(i)}}, \\Sigma_{\\tilde{z}^{(i)}}\\right)$ i.i.d.\n\n\nIn summary we have $\\nexp$ + $\\tilde{\\nexp}$ examples, of which $\\nexp$ are unlabeled data points $x$'s with unobserved $z$'s, and $\\tilde{\\nexp}$ are labeled data points $\\tilde{x}^{(i)}$ with corresponding observed labels $\\tilde{z}^{(i)}$. The traditional EM algorithm is designed to take only the $\\nexp$ unlabeled examples as input, and learn the model parameters $\\mu$, $\\Sigma$, and $\\phi$.\n\n\nOur task now will be to apply the semi-supervised EM algorithm to GMMs in order to also leverage the additional $\\tilde{\\nexp}$ labeled examples, and come up with semi-supervised E-step and M-step update rules specific to GMMs. Whenever required, you can cite the lecture notes for derivations and steps.\n\n\n\\begin{enumerate}\n  \\setcounter{enumii}{1}\n  \\input{semi_supervised_em/02-e-step}\n\\ifnum\\solutions=1 {\n  \\input{semi_supervised_em/02-e-step-sol}\n} \\fi\n\n  \\input{semi_supervised_em/03-m-step}\n\\ifnum\\solutions=1 {\n  \\input{semi_supervised_em/03-m-step-sol}\n} \\fi\n\n\n  \\input{semi_supervised_em/04-impl-unsupervised}\n\\ifnum\\solutions=1 {\n  \\input{semi_supervised_em/04-impl-unsupervised-sol}\n} \\fi\n\n  \\input{semi_supervised_em/05-impl-semi-supervised}\n\\ifnum\\solutions=1 {\n  \\input{semi_supervised_em/05-impl-semi-supervised-sol}\n} \\fi\n\n  \\input{semi_supervised_em/06-comparison}\n\\ifnum\\solutions=1 {\n  \\input{semi_supervised_em/06-comparison-sol}\n} \\fi\n\n\\end{enumerate}\n", "meta": {"hexsha": "7977a1011f8fc234d336ee4405d716a5bccaa2e9", "size": 5542, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ps3/tex/semi_supervised_em/00-main.tex", "max_stars_repo_name": "Ziggareto/cs229", "max_stars_repo_head_hexsha": "10b03b68b24d252dad3e3437561976d9509ebdd0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ps3/tex/semi_supervised_em/00-main.tex", "max_issues_repo_name": "Ziggareto/cs229", "max_issues_repo_head_hexsha": "10b03b68b24d252dad3e3437561976d9509ebdd0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ps3/tex/semi_supervised_em/00-main.tex", "max_forks_repo_name": "Ziggareto/cs229", "max_forks_repo_head_hexsha": "10b03b68b24d252dad3e3437561976d9509ebdd0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.9772727273, "max_line_length": 787, "alphanum_fraction": 0.6957776976, "num_tokens": 1826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.8807970889295663, "lm_q1q2_score": 0.7486521438879908}}
{"text": "\\chapter{Set Theory}\n\\emph{Salute to Discrete Mathematics.}\n\n\\section{Sets}\n\\label{sec:Sets}\n(Informally,) A set is a collection of elements.\n\n\\section{Relations and Functions}\n\\label{sec:RelationsAndFunctions}\n\n\\subsection{Relations}\n\\label{sub:Relation}\nGiven $n$ sets $A_1,\\dots,A_n$, a relation $R$ over them is a subset of $A_1 \\times \\cdots \\times A_n$.\n\n\\begin{definition}[Binary Relation]\n    \\label{def:BinaryRelation}\n    A \\textbf{binary relation} $R$ is a relation over $A \\times B$ given some $A$ and $B$.\n    \\begin{itemize}\n        \\item The \\textbf{domain} of $R$, denoted by $\\textrm{dom}(R)$, is $\\{ x | \\exists y: \\langle x,y \\rangle \\in R \\}$\n        \\item The \\textbf{range} of $R$, denoted by $\\textrm{rng}(R)$, is $\\{ y | \\exists x: \\langle x,y \\rangle \\in R \\}$\n    \\end{itemize}\n\\end{definition}\n\nA binary relation is\n\\begin{itemize}\n    \\item \\textbf{Reflexive} iff $\\langle x, x \\rangle \\in R$ for each $x \\in A$.\n    \\item \\textbf{Symmetric} iff $\\langle x,y \\rangle \\in R \\longrightarrow \\langle y,x \\rangle \\in R$.\n    \\item \\textbf{Transitive} iff $\\langle x,y \\rangle \\in R \\land \\langle y,z \\rangle \\in R \\longrightarrow \\langle x,z \\rangle \\in R$.\n\\end{itemize}\n\nA relation is an \\textbf{equivalence relation} if it is reflexive, symmetric and transitive.\n\n\\subsection{Functions}\n\\label{sub:Function}\n\\begin{definition}[Functions]\n    \\label{def:Function}\n    A \\textbf{function} $f: A \\rightarrow B$ is a binary relation over $A \\times B$ satisfying:\n    \\begin{itemize}\n        \\item Its domain is $A$.\n        \\item For each $x \\in A$, there is a unique $y \\in B$ such that $\\langle x, y \\rangle \\in f$.\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[One-to-One (injective)]\n    \\label{def:Injective}\n    A function $f: A \\rightarrow B$ is \\textbf{one-to-one (injective)} if for each $x, y \\in A$,\n    \\[ f(x) = f(y) \\Longrightarrow x = y. \\]\n\\end{definition}\n\n\\begin{definition}[Onto (surjective)]\n    \\label{def:Surjective}\n    A function is \\textbf{onto (surjective)} if for each $y \\in B$, there is some $x \\in A$ such that $f(x) = y$.\n\\end{definition}\n\n\\begin{definition}[One-to-One Correspondence (bijective)]\n    \\label{def:Bijective}\n    A function is a \\textbf{one-to-one correspondence (bijective)} between $A$ and $B$ if $f$ is both one-to-one and onto.\n\\end{definition}\n\n\\subsection{Finite Sets}\n\\label{sub:FiniteSets}\n\\begin{definition}[Finite sets]\n    \\label{def:FiniteSets}\n    The set $X$ is \\textbf{finite} if there is a natural number $n$ and a one-to-one correspondence between $X$ and $\\{0, 1, \\dots, n\\}$。\n\n    The set $X$ is \\textbf{infinite} if it is not finite.\n\\end{definition}\n\nWe use the notion of one-to-one correspondence between infinite sets to talk about the ``sizes'' of these infinite sets.\n\n\\begin{definition}[Enumerable Sets]\n    \\label{def:EnumerableSets}\n    The set $X$ is \\textbf{enumerable} if there is a one-to-one correspondence between $X$ and $\\mathbb{N}$.\n\\end{definition}\n\n\\begin{definition}[Listing of Sets]\n    \\label{def:ListingOfSets}\n    Let $A$ be a set. The sequence $a_0, a_1, \\dots, a_n, \\dots$ is a \\textbf{listing} of $A$ if\n    \\begin{enumerate}\n        \\item $a_i \\in A$ for each $a_i$.\n        \\item Every member of $A$ is equal to $a_n$ for some $n \\in \\mathbb{N}$.\n    \\end{enumerate}\n\\end{definition}\n\n\\begin{theorem}\n    \\label{thm:ListingAndEnumerableSets}\n    The set $A$ is enumerable iff there is some listing without repetitions of $A$.\n\\end{theorem}\n\\begin{proof}\n    $\\Rightarrow$.\n\n    $\\exists f: A \\mapsto \\mathbb{N}$, and $f$ is a one-to-one correspondence. Therefore there exists an inverse function $f^{-1}: \\mathbb{N} \\mapsto A$.\n\n    Therefore we can construct a listing\n    $$ f^{-1}(0), f^{-1}(1), f^{-1}(2), \\cdots $$\n\n    $\\Leftarrow$.\n\n    Let $g(i) = a_i$. $g$ is one-to-one because the listing has no identical elements. $g$ is onto because every member in $A$ is equal to some $a_n$ in the listing.\n\n    $f = g^{-1}$.\n\\end{proof}\n\n\\begin{definition}[Countable Sets]\n    \\label{def:CountableSets}\n    A set is \\textbf{countable} if it is finite or enumerable. A set is \\textbf{uncountable} if it is not countable.\n\\end{definition}\n\n\\begin{theorem}\n    \\label{thm:CountableSets}\n    A set $X$ is countable iff there is a one-to-one mapping $f: X \\mapsto \\mathbb{N}$.\n\n    A set $X$ is countably infinite iff it is enumerable.\n\\end{theorem}\n\\begin{sketchproof}\n    $\\Rightarrow$: Straightforward. Follows immediately from the definition of finite \\ref{sub:FiniteSets} and enumerable \\ref{def:EnumerableSets} sets.\n    \n    $\\Leftarrow$: Let $B = \\textrm{rng}(f)$. Notice that $f$ is a one-to-one correspondence between $X$ and $B$.\n    \\begin{itemize}\n        \\item If $B$ is finite, then there exists some function $h: B \\mapsto \\{1,2,\\dots,n\\}$ s.t. $h$ is a one-to-one correspondence. Let $g = h \\circ f$, then $g$ is a one-to-one correspondence from $X$ to $\\{1,2,\\dots,n\\}$. Therefore by definition \\ref{def:FiniteSets}, $X$ is finite and is thus countable.\n        \n        \\item If $B$ is infinite, since $B \\subseteq \\mathbb{N}$, we can sort elements of $B$ in ascending order:\n        \\[ b_0 < b_1 < b_2 < \\cdots < b_n < \\cdots \\]\n        \n        We have constructed a listing of $B$, and therefore $B$ is enumerable. Therefore by definition \\ref{def:EnumerableSets}, there exists a one-to-one correspondence $h:B \\mapsto \\mathbb{N}$. Construct $g = h \\circ f$, then $g$ must also be a one-to-one correspondence between $X$ and $\\mathbb{N}$. Therefore by definition \\ref{def:EnumerableSets}, the set $X$ is enumerable and thus countable.\n    \\end{itemize}\n\\end{sketchproof}\n\n\\begin{theorem}\n    \\label{thm:ListingAndCountableSets}\n    The set $A$ is countable and nonempty iff there is some listing with possible repetitions of $A$.\n\\end{theorem}\n\\begin{sketchproof}\n    $\\Rightarrow$. If $A$ is enumerable, we are done by Theorem \\ref{thm:ListingAndEnumerableSets}. If $A$ is finite, we can construct a listing $a_0, a_1, \\cdots, a_n, a_n, \\cdots$.\n\n    $\\Leftarrow$. Let $a_0, a_1, \\cdots, a_n, \\cdots$ be the listing. Define $f:A \\mapsto \\mathbb{N}$ by $f(a_i) = \\min_j\\left\\{ j: a_j=a_i \\right\\}$. $f$ is one-to-one and by Theorem \\ref{thm:CountableSets} we can conclude that $A$ is countable.\n\\end{sketchproof}\n\n\\begin{proposition}\n    \\label{prop:SubsetOfEnumerableSetsIsCountable}\n    If $A$ is enumerable and $B \\subseteq A$, then $B$ is countable.\n\\end{proposition}\n\n\\begin{theorem}\n    \\label{thm:LotsOfCountableSets}\n    ~{}\n    \\begin{itemize}\n        \\item If $A$ and $B$ are countable, then $A \\cup B$, $A \\cap B$, and $A \\times B$ are all countable.\n        \\item If each of $A_0, \\dots, A_n, \\dots$ is countable, then the union of these sets is also countable.\n        \\item If $A$ is countable and nonempty, then the set of all finite sequences of members of $A$ is countable.\n    \\end{itemize}\n\\end{theorem}\n\n\\subsection{Constructing Infinite Sets}\n\\label{sub:ConstructingInfiniteSets}\n\n\\begin{definition}[Characteristic Functions]\n    \\label{def:CharacteristicFunctions}\n    Let $X$ be a set and let $A \\subseteq X$. FOr any $a \\in A$, let\n    $$ C_A(a) = \\begin{cases}\n        1, &\\quad a \\in A\\\\\n        0, &\\quad a \\notin A\n    \\end{cases} $$\n    $C_A(a)$ is called the characteristic function of $A$.\n\\end{definition}\n\n\\begin{definition}[Power Sets]    \\label{def:PowerSets}\n    Let $A$ be a set, the power set of $A$ is\n    \\[ \\mathcal{P}(A) = \\{ X|X \\subseteq A \\} \\]\n\\end{definition}\n\n\\begin{theorem}[Cantor's Theorem]\n    \\label{thm:CantorsTheorem}\n    $\\mathcal{P}(\\mathbb{N})$ is uncountable.\n\\end{theorem}\n\\begin{proof}\n    Proof by contradiction. Suppose $\\mathcal{P}(\\mathbb{N})$ is countable. Obviously $\\mathcal{P}(\\mathbb{N})$ is not finite, so it must be enumerable.\n\n    By Theorem \\ref{thm:ListingAndEnumerableSets}, we can construct a listing with no repetitions.\n\n    We can list all subsets of $A$ using characteristic functions.\n    \\[\\begin{bmatrix}\n        \\emptyset & \\begin{bmatrix} 0 & 0 & \\cdots & 0 \\end{bmatrix}\\\\\n        \\{0\\} & \\begin{bmatrix} 1 & 0 & \\cdots & 0 \\end{bmatrix}\\\\\n        \\{1\\} & \\begin{bmatrix} 0 & 1 & \\cdots & 0 \\end{bmatrix}\\\\\n        \\{0, 1\\} & \\begin{bmatrix} 1 & 1 & \\cdots & 0 \\end{bmatrix}\\\\\n        \\cdots & \\cdots\\\\\n    \\end{bmatrix}\\]\n\n    We can then select all the bits along the diagonal and flip these bits to form a new bit sequence. This sequence can also be interpreted as a listing of some subset of $\\mathcal{P}(\\mathbb{N})$. However, this listing cannot exist in the listed listings, because it has at least one bit that is different from any existing listings. This listing fails to enumerate all subsets of $\\mathcal{P}(\\mathbb{N})$, and therefore the set $\\mathcal{P}(\\mathbb{N})$ is uncountable.\n\\end{proof}\n\n\\begin{corollary}\n    $\\mathbb{R}$ is uncountable.\n\\end{corollary}\n\n\\subsection{Domination of Sets}\n\n\\begin{definition}[Domination of Sets]\n    \\label{def:SetDomination}\n    ~{}\n    \\begin{itemize}\n        \\item $A \\preceq B$ if there is a one-to-one function $f: A \\mapsto B$.\n        \\item $ A \\prec B$ if $A \\preceq B$ but $B \\npreceq A$.\n        \\item $A \\equiv B$ if $A \\preceq B$ and $B \\preceq A$.\n    \\end{itemize}\n\\end{definition}\n\n\\begin{theorem}[Cantor-Schr\\\"oder-Bernstein]\n    \\label{thm:CSB}\n    $A \\equiv B$ iff there is a one-to-one correspondence between $A$ and $B$.\n\\end{theorem}\n\\begin{proof}\n    Refer to supplementary material on Canvas.\n\\end{proof}\n\n\\begin{theorem}[Cantor's Theorem]\n    \\label{thm:Cantor}\n    For every set $A$,\n    \\[ A \\prec \\mathcal{P}(A) \\]\n\\end{theorem}\n\\begin{proof}\n    We need to prove 1) $A \\preceq \\mathcal{P}(A)$ and 2) $\\mathcal{P}(A) \\npreceq A$. 1) is easy because $\\forall a \\in A$, $\\{a\\} \\subseteq A$ and therefore $\\{a\\} \\in \\mathcal{P}(A)$.\n\n    To prove 2), assume $\\mathcal{P}(A) \\preceq A$, by theorem \\ref{thm:CSB} we have $\\mathcal{P}(A) \\equiv A$, and therefore there should exist a one-to-one correspondence $f: A \\mapsto \\mathcal{P}(A)$.\n\n    Let\n    \\[ B = \\{x \\in A|x \\notin f(x)\\} \\]\n\n    Then $B \\subseteq A$, and $B \\in \\mathcal{P}(A)$. Since $f$ is onto, there must exist some $b \\in A$ s.t. $f(b) = B$.\n\n    \\begin{enumerate}\n        \\item If $b \\in f(b) = B$. Then $b \\in f(b) \\Rightarrow b \\notin f(b)$. Boom.\n        \\item If $b \\notin f(b)$. Then $b \\in B = f(b)$. Boom.\n    \\end{enumerate}\n\n    Therefore $\\mathcal{P}(A) \\npreceq A$.\n\\end{proof}\n\\begin{corollary}\n    For every $A$ there exists a $B$ s.t. $A \\prec B$.\n\\end{corollary}\n\\begin{corollary}\n    $\\mathcal{P}(\\mathbb{N})$ is uncountable.\n\\end{corollary}\n\\begin{proof}\n    $\\mathcal{P}(\\mathbb{N}) \\npreceq \\mathbb{N}$.\n\\end{proof}\n\n\\subsection{Sets of Functions}\n\n\\begin{definition}[Set of Functions]\n    \\label{def:SetOfFunction}\n    $~^{A} B$ is the set of all functions that map $A$ into $B$.\n\\end{definition}\n\\begin{remark}\n    The set $~^A\\{0,1\\}$ is the set of all characteristic functions (\\ref{def:CharacteristicFunctions}).\n\\end{remark}\n\n\\begin{theorem}\n    There is a one-to-one correspondence between $~^{\\mathbb{N}}\\{0,1\\}$ and $\\mathcal{P}(\\mathbb{N})$.\n\\end{theorem}\n\\begin{remark}\n    A generalized version: there is a one-to-one correspondence between $~^{\\mathbb{A}}\\{0,1\\}$ and $\\mathcal{P}(\\mathbb{A})$\n\\end{remark}\n\\begin{corollary}\n    \\label{cor:RealIsUncountable}\n    $\\mathbb{R}$ is uncountable.\n\\end{corollary}\n\\begin{theorem}\n    \\label{thm:NNisUncountable}\n    $~^\\mathbb{N}\\mathbb{N}$ is uncountable.\n\\end{theorem}\n\\begin{proof}\n    Assume $~^\\mathbb{N}\\mathbb{N}$ is countable. Since $~^\\mathbb{N}\\{0,1\\} \\subseteq ~^\\mathbb{N}\\mathbb{N}$. $~^\\mathbb{N}\\{0,1\\}$ must be countable. Boom.\n\\end{proof}\n\n\\subsection{Generalized Continuum Hypothesis}\n\n\\begin{center}\n    \\textbf{Is there a set $A$ s.t. $\\mathbb{N} \\prec A \\prec \\mathbb{R} \\equiv \\mathcal{P}(\\mathbb{N})$?}\n\\end{center}\n", "meta": {"hexsha": "385cabee4a348bcfe331fdb09d07ee09b080173e", "size": 11795, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Logic/SetTheory.tex", "max_stars_repo_name": "YBRua/CourseNotes", "max_stars_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-20T10:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T08:15:15.000Z", "max_issues_repo_path": "Mathematical Logic/SetTheory.tex", "max_issues_repo_name": "YBRua/CourseNotes", "max_issues_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mathematical Logic/SetTheory.tex", "max_forks_repo_name": "YBRua/CourseNotes", "max_forks_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T11:31:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T11:31:00.000Z", "avg_line_length": 41.8262411348, "max_line_length": 473, "alphanum_fraction": 0.6595167444, "num_tokens": 3929, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.8807970779778825, "lm_q1q2_score": 0.7486521312319964}}
{"text": "\\section{Application to Bilinear Form}\r\nWe want to analyse bilinear forms by our study in spectral theory.\r\n\\begin{corollary}\r\n    Let $A\\in M_n(F)$ for $F=\\mathbb R$ (resp. $\\mathbb C$) be a symmetric (resp. Hermitian) matrix, then there is an orthogonal (resp. unitary) matrix $P$ such that $P^\\top AP$ is a real diagonal matrix.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Just take $P$ to be the basis of orthonormal eigenvectors that spans $V$ which exists by spectral theorem.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Let $V$ be a finite dimensional inner product space over $F=\\mathbb R$ (resp. $\\mathbb C$) and $\\phi:V\\times V\\to F$ be a symmetric bilinear (resp. Hermitian) form.\r\n    Then there is an orthogonal basis of $V$ in which $\\phi$ is diagonal.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Follows directly from the preceding corollary and the change-of-basis formula for bilinear/sesquilinear forms.\r\n\\end{proof}\r\n\\begin{remark}\r\n    The diagonal entries in above corollaries are, of course, the eigenvalues.\r\n\\end{remark}\r\n\\begin{corollary}[Simultaneous Diagonalisation]\r\n    et $V$ be a finite dimensional inner product space over $F=\\mathbb R$ (resp. $\\mathbb C$) and $\\phi,\\psi:V\\times V\\to F$ be symmetric bilinear (resp. Hermitian) forms.\r\n    Assume $\\phi$ is positive definite, then there exists a basis of $V$ in which both are diagonalised.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Define a new scalar product by $\\langle v,w\\rangle=\\phi(v,w)$ which works as $\\phi$ is positive definite.\r\n    Then just take the basis to be the basis in which $\\psi$ is diagonal under this new inner product.\r\n\\end{proof}\r\nNote that in this new basis that we described, $\\phi$ is actually represented the identity matrix.\r\n\\begin{corollary}\r\n    Let $A,B\\in M_n(F)$ where $F=\\mathbb R$ (resp. $\\mathbb C$).\r\n    Suppose they are both symmetric (resp. Hermitian) and assume that for any $x\\neq 0,x^\\top Ax>0$, then there exists $Q\\in M_n(F)$ such that both $Q^\\top AQ$ and $Q^\\top BQ$ are diagonal.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Just a restatement of the preceding corollary.\r\n\\end{proof}", "meta": {"hexsha": "ee728b2311ea1289fd00a440473bdf0894534c72", "size": 2084, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "24/bil.tex", "max_stars_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_stars_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "24/bil.tex", "max_issues_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_issues_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "24/bil.tex", "max_forks_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_forks_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.2941176471, "max_line_length": 205, "alphanum_fraction": 0.7135316699, "num_tokens": 605, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.8807970811069351, "lm_q1q2_score": 0.748652130544222}}
{"text": "\\subsection{Exponents}\n\nParentheses are required around negative exponents.\nFor example,\n\n{\\color{blue}\n\\begin{verbatim}\n10^(-3)\n\\end{verbatim}\n}\n\n\\noindent\ninstead of\n\n{\\color{blue}\n\\begin{verbatim}\n10^-3\n\\end{verbatim}\n}\n\n\\noindent\nThe reason for this is that the binding of the negative sign is not always obvious.\nFor example, consider\n\n{\\color{blue}\n\\begin{verbatim}\nx^-1/2\n\\end{verbatim}\n}\n\n\\noindent\nIt is not clear whether the exponent should be $-1$ or $-1/2$.\nHence the following syntax is required.\n\n{\\color{blue}\n\\begin{verbatim}\nx^(-1/2)\n\\end{verbatim}\n}\n\n\\noindent\nIn general, parentheses are always required when the exponent\nis an expression.\nFor example, \\verb$x^1/2$ is evaluated as $(x^1)/2$ which\nis probably not the desired result.\n\n{\\color{blue}\n\\begin{verbatim}\nx^1/2\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\tfrac{1}{2}x$\n\n\\bigskip\n\\noindent\nUsing \\verb$x^(1/2)$ yields the desired result.\n\n{\\color{blue}\n\\begin{verbatim}\nx^(1/2)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle x^{1/2}$\n", "meta": {"hexsha": "2607a0cb8b9a546a08423fccfdb111be6d79e95b", "size": 1009, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/exponents.tex", "max_stars_repo_name": "wuyudi/eigenmath", "max_stars_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2019-09-29T03:15:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T00:57:51.000Z", "max_issues_repo_path": "doc/exponents.tex", "max_issues_repo_name": "wuyudi/eigenmath", "max_issues_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2019-11-12T00:57:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T23:46:46.000Z", "max_forks_repo_path": "doc/exponents.tex", "max_forks_repo_name": "wuyudi/eigenmath", "max_forks_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2019-10-03T13:23:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T13:28:00.000Z", "avg_line_length": 14.8382352941, "max_line_length": 83, "alphanum_fraction": 0.7185332012, "num_tokens": 316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.8652240825770433, "lm_q1q2_score": 0.7486127070574774}}
{"text": "\\chapter{Probability}\n\n\\section*{2.2. Rules for three events}\n\\addcontentsline{toc}{section}{2.2. Rules for three events}\n\\begin{enumerate}[(a)]\n    \\item Consider three events, $A$, $B$, and $C$. \n        If they are all independent of each other,\n        show that\n        \\begin{equation*}\\tag{2.76}\n            P(A \\text{ and } B \\text{ and } C) = P(A) \\cdot P(B) \\cdot P(C) \n        \\end{equation*}\n\n    \\item If they are (possibly) dependent, show that \n        \\begin{equation*}\\tag{2.77}\n            P(A \\text{ and } B \\text{ and } C) = P(A) \\cdot P(B | A) \\cdot P(C | A \\text{ and } B) \n        \\end{equation*}\n\n    \\item If they are all mutually exclusive, show that\n        \\begin{equation*}\\tag{2.78}\n            P(A \\text{ or } B \\text{ or } C) = P(A) + P(B) + P(C)\n        \\end{equation*}\n\n    \\item If they are (possibly) nonexclusive, show that\n        \\begin{align*}\\tag{2.79}\n            P(A \\text{ or } B \\text{ or } C) =& P(A) + P(B) + P(C) \\\\\n                                          &- P(A \\text{ and } B) - P(A \\text{ and } C) - P(B \\text{ and } C) \\\\\n                                          &+ P(A \\text{ and } B \\text{ and } C)\n        .\\end{align*}\n\\end{enumerate}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item Using (2.9) we find that:\n            \\[\n                P(A \\text{ and } B \\text{ and } C) = P(A) \\cdot P(B \\text{ and } C | A) \n                = P(A) \\cdot P(B | A) \\cdot P(C | A \\text{ and } B)\n            .\\] \n            Because the events are independent, $P(B | A) = P(B)$ and $P(C | A \\text { and } B) = P(C)$, so\n            \\begin{equation*}\\tag{2.76}\n                P(A \\text{ and } B \\text{ and } C) = P(A) \\cdot P(B) \\cdot P(C). \n            \\end{equation*}\n\n        \\item Proved at (a).\n\n        \\item By (2.18), \n            \\begin{align*}\n                P(A \\text{ and } B \\text{ and } C) \n                    &= P(A) + P(B \\text{ or } C) - P(A \\text{ and } (B \\text{ or } C)) \\\\\n                    &= P(A) + P(B) + P(C) - P(B \\text{ and } C) - P(A) \\cdot P(B \\text{ or } C | A)\n            .\\end{align*}\n\n            We compute the subtracted member:\n            \\begin{align*}\n                P(A) \\cdot P(B \\text{ or } C | A) \n                    &= P(A) \\cdot (P(B|A) + P(C|A) - P(B \\text{ and } C | A))) \\\\\n                    &= P(A \\text{ and } B) + P(A \\text{ and } C) - P(A \\text{ and } B \\text{ and } C)\n            .\\end{align*}\n\n            By substituting in the initial expression, we get:\n            \\begin{align*}\\tag{2.79}\n                P(A \\text{ or } B \\text{ or } C) =& P(A) + P(B) + P(C) \\\\\n                                              &- P(A \\text{ and } B) - P(A \\text{ and } C) - \n                                                P(B \\text{ and } C) \\\\\n                                              &+ P(A \\text{ and } B \\text{ and } C)\n            .\\end{align*}\n\n            Since the events are mutually exclusive, all $\\emph{and}$ probabilities are 0, so:\n            \\begin{equation*}\\tag{2.78}\n                P(A \\text{ or } B \\text{ or } C) = P(A) + P(B) + P(C)\n            \\end{equation*}\n\n        \\item Proved at (c).\n    \\end{enumerate}\n\\end{proof}\n\n\\section*{2.7. Proofreading}\n\\addcontentsline{toc}{section}{2.7. Proofreading}\nTwo people each proofread the same book. One person finds 100 errors, and the other finds 60. \nThere are 20 errors common to both people. Assume that all errors are equally likely to be found (which is \nundoubtedly not true in practice), and also that the discovery of an error by a person is independent\nof the discovery of that error by the other person. Given these assumptions, roughly how many error \ndoes the book have? $\\emph{Hint:}$ Draw the picture similar to Fig. 2.1, and then find the probability \nof each person finding a given error.\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\hfill\n\n    Let $P(A)$ be the probability that a random error is one of the errors discovered \n    by the person with 100 errors, and respectively let $P(B)$ be the same for the person with 60 errors.\n    Also, let $N$ be the estimated number of total errors.\n    Since the discoveries of errors are independent events, \n    \\[\n        P(A \\text{ and } B) = P(A) \\cdot P(B) = \\frac{100}{N} \\cdot \\frac{60}{N} = \\frac{6000}{N^2}\n    .\\] \n    But we know that 20 errors are common between the two persons, so\n    \\[\n        P(A \\text{ and } B) = \\frac{20}{N}\n    .\\] \n    Therefore, we get the estimated total number of errors:\n    \\[\n        \\frac{20}{N} = \\frac{6000}{N^2} \\iff N = 300\n    .\\] \n\\end{proof}\n\n\\section*{2.9. Sock pairs}\n\\addcontentsline{toc}{section}{2.9. Sock pairs}\n\\begin{enumerate}[(a)]\n    \\item Four red socks and four blue socks are in a drawer. You reach in and pull out two socks at random.\n        What is the probability that you obtain a matching pair?\n\n    \\item Answer the same question, but now in the general case with $n$ red socks and $n$ blue socks.\n\n    \\item Presumably you answered the above questions by counting the relevant pairs of socks.\n        Can you think of a quick probability argument, requiring no counting, that gives the\n        answer to part (b) (and part(a))?\n\\end{enumerate}\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item The total number of possible extracted pairs is $\\binom{8}{2} = 28$ and the number\n            of possible matching pair (of any color) extractions is $2 \\cdot \\binom{4}{2} = 12$. \n            Therefore, the probability of pulling a matching pair is:\n            \n            \\[\n                \\frac{12}{28} = \\frac{3}{7} \\approx 0.428\n            \\] \n\n        \\item As before, the total number of possible extracted pairs is $\\binom{2n}{2} = n(2n - 1)$ and\n            the number of possible matching pair (of any color) extractions is \n            $2 \\cdot \\binom{n}{2} = n(n - 1)$. As a result, the probability of pulling a \n            matching pair is:\n            \\[\n                \\frac{n(n-1)}{n(2n - 1)} = \\frac{n - 1}{2n - 1} \\to \\frac{1}{2}\n            \\] \n        \\item The first sock can either be red or blue. After the extraction, the drawer contains\n            $2n - 1$ socks and $n - 1$ socks of the matching color, so the probability of pulling\n            a matching pair is given by:\n            \\[\n                \\frac{n - 1}{2n - 1} \\to \\frac{1}{2}\n            \\] \n    \\end{enumerate}\n\\end{proof}\n\n\\section*{2.11. At least one 6}\n\\addcontentsline{toc}{section}{2.11. At least one 6}\nThree dice are rolled. What is the probability of obtaining at least one 6? We solved\nthis in Section 2.3.1, but your task here is to solve it the long way, by adding up the\nprobabilities of obtaining exactly one, two, or three 6's.\n\n\\begin{proof}\n    Since each dice can take values from 1 to 6, the dices can be rolled in $6^3 = 216$ ways. \n    Then, there are $3 \\cdot 5 \\cdot 5 = 75$ ways in which only one dice is a 6 (we assume\n    each individual dice rolls a 6 and the other two roll differently), so the probability \n    of doing that is $\\frac{75}{216}$. Also, there are $3 \\cdot 5 = 15$  \n    ways of having exactly two 6 dices, so the probability of this event is $\\frac{15}{216}$. \n    Finally, the event of having all dices being rolled as sixes can occur in only one way, so the \n    probability of it happening is $\\frac{1}{216}$. In conclusion, the probability of rolling at least a 6 \n    from three dice rolls is given by:\n    \\[\n        \\frac{75}{216} + \\frac{15}{216} + \\frac{1}{216} = \\frac{91}{216} \\approx 0.421\n    \\] \n\\end{proof}\n\n\\section*{2.15 My birthday}\n\\addcontentsline{toc}{section}{2.15. My birthday}\n\\begin{enumerate}[(a)]\n    \\item You are in a room with 100 other people. Let $p$ be the probability that at least one\n        of these 100 people has your birthday. Without doing any calculations, state whether $p$ \n        is larger, smaller, or equal to 100/365.\n\n    \\item Now calculate the exact value of $p$.\n\\end{enumerate}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item Assuming all birthdays are equally likely to be encountered and that a year has 365 days,\n            the probability that at least one person of the 100 has the same birthday as me is strictly less\n            than $\\frac{100}{365}$, since some people may have the same birthday and only unique\n            birthdays are counted. The $\\frac{100}{365}$ probability would be acquired if we consider \n            the 100 people in the room as having unique birthdays.\n\n        \\item The probability that a random person doesn't have the same birthday as me is $\\frac{364}{365}$,\n            so the probability that none of the 100 people in the room has the same birthday as me is\n            $(\\frac{365}{365})^{100}$. Therefore, the probability that at least one of them has the \n            same birthday as me is:\n            \\[\n                p = 1 - \\bigg(\\frac{364}{365}\\bigg)^{100} \\approx 0.24\n            \\] \n    \\end{enumerate}\n\\end{proof}\n\n\\section*{2.16. My birthday, again}\n\\addcontentsline{toc}{section}{2.16. My birthday, again}\nWe saw at the end of Section 2.4.1 that 253 is the answer to the question, \"How many people (in addition to\nme) need to be present in order for there to be at least a 1/2 chance that someone else has $\\emph{my}$ \nbirthday?\" We solved this by finding the smallest $n$ for which $(364/365)^n$ is less than 1/2. Answer\nthis question again, by making use of the approximation in Eq. (7.14) in Appendix C. What is the answer\nin the general case where there are N days in a year instead of 365? Assume N is large.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We are given the approximation formula:\n    \\begin{equation*}\\tag{7.14}\n        (1 + a)^n \\approx e^{na}\n    \\end{equation*}\n\n    We consider two cases:\n    \\begin{enumerate}[(1)]\n        \\item A year has 365 days. We've seen in the previous exercise that the probability that at \n            least one of $n$ given people has the same birthday as me is given by the expression:\n            \\[\n                p_n = 1 - \\bigg(\\frac{364}{365}\\bigg)^n \n            \\] \n\n            Let's assume that $p_n \\approx \\frac{1}{2}$, then:\n            \\[\n                \\bigg(\\frac{364}{365}\\bigg)^n \\approx \\frac{1}{2} \\iff\n                \\bigg(1 - \\frac{1}{365}\\bigg)^n \\approx \\frac{1}{2} \n            \\] \n\n            Using (7.14), we have that:\n            \\[\n               e^{-\\frac{n}{365}} \\approx \\frac{1}{2}\n            \\] \n\n            By taking the logarithm of both sides and then negating the terms, we see that \n            $\\frac{n}{365} \\approx \\ln{2}$, so the number of people that should be present such\n            that there is a least $\\frac{1}{2}$ chance that someone else has my birthday is:\n            \\[\n                n = 365 \\ln{2} \\approx 253 \n            \\] \n\n        \\item A year has $N$ days. Similarly to the previous exercise, we see that the probability\n            of a person not having the same birthday as me is $\\frac{N - 1}{N}$. Then it is \n            easily deduced that the probability of a person having the same birthday as me is:\n            \\[\n                p_n = 1 - \\bigg(\\frac{N - 1}{N}\\bigg)^n \n            \\] \n\n            Let's assume that $p_n \\approx \\frac{1}{2}$, then:\n            \\[\n                \\bigg(\\frac{N - 1}{N}\\bigg)^n \\approx \\frac{1}{2} \\iff\n                \\bigg(1 - \\frac{1}{N}\\bigg)^n \\approx \\frac{1}{2} \n            \\] \n\n            Using (7.14), we have that:\n            \\[\n               e^{-\\frac{n}{N}} \\approx \\frac{1}{2}\n            \\] \n\n            By taking the logarithm of both sides and then negating the terms, we see that \n            $\\frac{n}{N} \\approx \\ln{2}$, so the number of people that should be present such\n            that there is a least $\\frac{1}{2}$ chance that someone else has my birthday is:\n            \\[\n                n \\approx N\\ln{2} \\approx 0.693N\n            \\]\n    \\end{enumerate}\n\\end{proof}\n\n\\section*{2.18. A random game-show host}\n\\addcontentsline{toc}{section}{2.18. A random game-show host}\nConsider the following variation of the Game-Show Problem we discussed in Section 2.4.2. A game-show\nhost offers you the choice of three doors. Behind one of these doors is the grand prize, and behind\nthe other two are goats. The host announces that after you select a door (without opening it), he will\n$\\emph{randomly}$ open one of the other doors, and the result happens to be a goat. He then offers\nyou the chance to switch your choice to the remaining door. Should you switch or not? Or does it \nnot matter?\n\n\\vspace{1em}\n\n\\begin{proof}\n    Since the doors can be reordered and not change the setup of the problem, we can pick the first\n    door without loss of generality. There are three equally likely possibilities\n    for what is behind the three doors: PGG, GPG, and GGP, where P denotes the prize and G denotes\n    a goat. Let us use the subscript $H$ to show that a door was opened by the host. Considering that\n    the host cannot choose our door (the first one), we have the following door layouts after the host \n    opens a door:\n\n    \\pagebreak\n\n    \\begin{table}[h]\n        \\centering\n        \\begin{tabular}{cc}\n            $PG_H G$ & $PGG_H$ \\\\ \n            $GP_HG$ & $GPG_H$ \\\\\n            $GG_HP$ & $GGP_H$\n        \\end{tabular}\n    \\end{table}\n\n    Since the host doesn't choose the door with the prize, those layouts have 0 probability of \n    occuring. The encounters of the other 4 layouts are equally likely, so they have a probability \n    of occuring of $\\frac{1}{4}$. We can see that if we keep the initial choice of the door,\n    there is a $\\frac{1}{2}$ possibility of winning. Likewise, if we switch the door, there \n    is a $\\frac{1}{2}$ probability of winning. Therefore, it does not matter if we switch our choice or not.\n\\end{proof}\n\n\\section*{2.19. Boy girl problem with general information}\n\\addcontentsline{toc}{section}{2.19. Boy girl problem with general information}\nThis problem is an extension of the Boy/Girl problem from Section 2.4.4. You should study that \nproblem thoroughly before tackling this one. As in the original version of the problem, assume\nthat all processes are completely random. The new variation is the following:\n\nYou bump into a random person on the street who says, \"I have two children. At least one of them\nis a boy whose birthday is in the summer.\" What is the probability that the other child is also \na boy? What if the clause is changed to, \"whose birthday is on August 11th\"? Or \"who was born\nduring a particular minute on August 11th\"? Or more generally, \"who has a particular characteristic\nthat occurs with probability $p$ \"? $\\emph{Hint:}$ Make a table of all of the various possibilities,\nanalogous to the tables in Section 2.4.4.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Without taking into account the particular characteristic, we have the following possible\n    children couples:\n    \n    \\begin{table}[h]\n        \\centering\n        \\begin{tabular}{c c c c}\n            BB & BG & GB & GG\n        \\end{tabular}\n    \\end{table}\n\n    , where B represents a boy and G a girl. Each of these groups is equally likely and\n    is encountered with a probability of $\\frac{1}{4}$. If we add a subscript C to the children\n    that possess the particular characteristic, we get the following possible pairs:\n\n    \\begin{table}[h]\n        \\centering\n        \\begin{tabular}{c c c c}\n            $B_CB_C$ & $B_CG_C$ & $G_CB_C$ & $G_CG_C$ \\\\\n            $B_CB$ & $B_CG$ & $G_CB$ & $G_CB$ \\\\\n            $BB_C$ & $BG_C$ & $GB_C$ & $GG_C$ \\\\\n            $BB$ & $BG$ & $BB$ & $GG$\n        \\end{tabular}\n    \\end{table}\n\n    Since the probability of a kid to have the characteristic is $p$, then the probability\n    of not having it is $1 - p$. We split the groups in 3 categories (following the \n    lines in the table):\n    \\begin{itemize}\n        \\item Line 1: Both children have the characteristic. The probability that one\n            given couple is of this type is $\\frac{1}{4}p^2$\n        \\item Lines 2 and 3: Only one kid has the characteristic. The probability that such\n            a group is encountered is $\\frac{1}{4}p(1 - p)$\n        \\item Line 4: None of the kids has the characteristic. The probability that a given\n            group is in this category is $\\frac{1}{4}(1 - p)^2$\n    \\end{itemize}\n\n    \\pagebreak\n\n    Now, we find that the groups that contain at least one boy who has the characteristic are:\n    \\begin{table}[h]\n        \\centering\n        \\begin{tabular}{c c c}\n            $B_CB_C$ & $B_CG_C$ & $G_CB_C$ \\\\\n            $B_CB$ & $B_CG$ & \\\\\n            $BB_C$ & & $GB_C$ \\\\\n        \\end{tabular}\n    \\end{table}\n\n    We have 3 groups that contain two boys and at least one of them has the characteristic\n    (first column). Also, there are a total of 7 groups containing at least a boy with the \n    characteristic (3 groups from the first line, 2 from the second\n    line and 2 from the third line). Therefore, knowing that one children is a boy that possesses\n    the characteristic $p$, the probability that the other kid is also a boy is:\n    \\[\n        P_{BB} = \\frac{\\frac{1}{4}p^2 + 2 \\frac{1}{4}p(1 - p)}{3 \\frac{1}{4}p^2 + 4 \\frac{1}{4} p(1 - p)}\n        = \\frac{p^2 + 2p(1 - p)}{3p^2 + 4p(1 - p)}\n        = \\frac{2p - p^2}{4p - p^2} \n        = \\frac{2 - p}{4 - p}\n    \\] \n\n    In the base case, the characteristic is \"having a birthday in the summer\", so $p = \\frac{1}{4}$.\n    We get that the probability of the other kid being a boy is:\n    \\[\n        P_{BB} = \\frac{2 - \\frac{1}{4}}{4 - \\frac{1}{4}} = \\frac{7}{15} \\approx 0.467\n    \\] \n\n    The second characteristic is \"having a birthday on August 11th\", so $p = \\frac{1}{365}$.\n    The sought probability is then\n    \\[\n        P_{BB} = \\frac{2 - \\frac{1}{365}}{4 - \\frac{1}{365}} = \\frac{729}{1459} \\approx \\frac{1}{2}\n    \\] \n\n    Finally, if the characteristic is \"being born during a particular minute on August 11th\", \n    so $p = \\frac{1}{365} \\frac{1}{1440} = \\frac{1}{525600}$\n    the probability that the other children is a boy is:\n    \\[\n        P_{BB} = \\frac{2 - \\frac{1}{525600}}{4 - \\frac{1}{525600}} = \\frac{1051199}{2102399} \\approx \\frac{1}{2}\n    \\] \n\\end{proof}\n\n\\section*{2.20. A second test}\n\\addcontentsline{toc}{section}{2.20. A second test}\nConsider the setup in the \"False positives\" example in Section 2.5. If we instead perform \n$\\emph{two}$ successive tests on each person, what is the probability that a person\nwho tests positive both times actually has the disease?\n\n\\begin{proof}\n    The setup provided in the \"False positives\" example is the following:\n    \\begin{itemize}\n        \\item 2\\% of the overall population has the disease.\n\n        \\item If a person $\\emph{does}$ have the disease, then the test has a 95\\% chance of correctly\n            indicating that the person has it. (So 5\\% of the time, the test incorrectly indicates\n            that the person doesn't have the disease.)\n\n        \\item If a person $\\emph{does not}$ have the disease, then the test has a 10\\% chance of\n            incorrectly indicating that the person has it; this is a \"false positive\" result.\n            (So 90\\% of the time, the test correctly indicates that the person doesn't have the \n            disease.)\n    \\end{itemize}\n\n    Let $N$ be the population number and let's consider two cases:\n    \\begin{enumerate}\n        \\item The person has the disease, and the tests were positive results.\n            The probability of a positive result for a diseased person is 90\\%.\n            Therefore the probability of a diseased person being diagnosed twice\n            as positive is $95\\% \\cdot 95\\% = 90.25\\%$. 2\\% of the population is diseased,\n            so the number of diseased persons that are tested twice as positive is \n            $2\\%N \\cdot 90.25\\% = 1.805\\%N$.\n\n        \\item The person does not have the disease, and both tests are \"false positives\".\n            The probability of a \"false positive\" for a healthy person is 10\\%.\n            As a result, the probability of a healthy person being tested twice as false positive\n            is $10\\% \\cdot 10\\% = 1\\%$. 98\\% of the population is healthy, so the number\n            of healthy people that are tested twice as \"false positives\" is \n            $98\\%N \\cdot 1\\% = 0.98\\%N$.\n    \\end{enumerate}\n\n    Therefore, the probability of a person who tests positive both times actually has the disease\n    is:\n    \\[\n        \\frac{1.805\\%N}{1.805\\%N + 0.98\\%N} = \\frac{1.805\\%N}{2.785\\%N} \\approx 0.6481 = 64.81\\%\n    \\] \n\\end{proof}\n", "meta": {"hexsha": "28cfec1bff9554b74d1db9fa51dc950e5c6a74ab", "size": 20472, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter2_probability.tex", "max_stars_repo_name": "thesstefan/morin_solutions", "max_stars_repo_head_hexsha": "0053de71a3743e99c94cee5fad0fd0f75aefa96b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/chapter2_probability.tex", "max_issues_repo_name": "thesstefan/morin_solutions", "max_issues_repo_head_hexsha": "0053de71a3743e99c94cee5fad0fd0f75aefa96b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter2_probability.tex", "max_forks_repo_name": "thesstefan/morin_solutions", "max_forks_repo_head_hexsha": "0053de71a3743e99c94cee5fad0fd0f75aefa96b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.004494382, "max_line_length": 112, "alphanum_fraction": 0.6008206331, "num_tokens": 5915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346599, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.748527468032178}}
{"text": "%!TEX root = ../Thesis.tex\n\\chapter{Harmonic Oscillator - Hamilton's Equations and Numerical Analysis}\n\n\\section{Equations of Motion}\n\\begin{figure}[ht!]\n\\centering \n\\includegraphics[scale=0.7]{fig/harmonic_oscillator.pdf}\n\\caption{The harmonic oscillator}\n\\label{fig:ho}\n\\end{figure}\n\\begin{description}\n\\item[Step 0 \\quad Lagrangian $L$] \\ \\\\[0.5cm]\nGeneralized coordinate: $x$. \\\\[0.2cm]\n$T = \\frac{1}{2} m \\dot{x}^2.$ \\\\[0.2cm]\n$V = \\frac{1}{2} k x^2$ \\\\[0.2cm]\n$L(x, \\dot{x}) = T - V = \\frac{1}{2} m \\dot{x}^2 - \\frac{1}{2} k x^2$\n\n\\item[Step 1 \\quad Generalized momentum $p$] \\ \\\\[0.2cm]\n$p(x,\\dot{x}) = \\dfrac{\\partial L}{\\partial \\dot{x}} = k \\dot{x}$\n\n\\item[Step 2 \\quad Transform $\\dot{x}$] \\ \\\\[0.5cm]\n$\\dot{x} = \\dot{x}(x, p) = \\dfrac{p}{k}$\n\n\\item[Step 3 \\quad The Hamiltonian $H(\\vec{q}, \\vec{p}, t) = \\sum\\limits_{i=1}^n p_i \\dot{q_i} - L$] \\ \\\\\n\\begin{align}\n\\notag H &= p \\cdot \\dot{x} - \\left(\\frac{1}{2} m \\dot{x}^2 - \\frac{1}{2} k x^2\\right) \\\\\n\\notag  &= p \\cdot \\dfrac{p}{m} - \\left(\\frac{1}{2} m \\left(\\frac{p}{m}\\right)^2 - \\frac{1}{2} k x^2\\right) \\\\\n&= \\dfrac{p^2}{2m} + \\dfrac{1}{2}k x^2\n\\end{align}\n, which we recognize simply as the total energy. The first term is the kinetic energy in terms of the momentum $p$ and the second term is the potential energy $V$.\n\n\\item[Step 4 \\quad Hamilton's Equations of Motion]\n\\begin{align}\n\\begin{split}\n\\label{eq:ho-eom}\n\\dot{x} = +\\dfrac{\\partial H}{\\partial p} &= \\dfrac{p}{m} ,\n\\\\[0.2cm]\n\\dot{p}_x = -\\dfrac{\\partial H}{\\partial x} &= - k x\n\\end{split}\n\\end{align}\n\\end{description}\n\n\\section{Numerical Analysis}\nWe will now solve the harmonic oscillator's equations of motion, \\eqref{eq:ho-eom}. For simplicity we'll set $k = m = 1$. Note that by choice of $m=1$ the momentum $p$ is equal to the velocity $v$. The first step is to discretize the equations\n\\begin{alignat}{2}\n&\\dod{x}{t} = p  & \\qquad \\implies \\qquad &\\Delta x = p \\Delta t \\\\[0.5cm]\n&\\dod{p}{t} = - x & \\qquad \\implies \\qquad &\\Delta p = - x \\Delta t\n\\end{alignat}\nThe solution for this linear system of equations is well known and can be expressed as\n\\begin{align}\n\\begin{split}\n\\label{eq:ho-analytical}\nx(t) = A \\cos{\\omega t} + B \\sin{\\omega t} \\\\\np(t) = -A \\sin{\\omega t} + B \\cos{\\omega t}\n\\end{split}\n\\end{align}\nA good way to test the validity and precision a numerical method is to compare it's solution to a problem of which we know an analytical solution. Hence we will use the analytical solution \\eqref{eq:ho-analytical} to analyze the $x(t)$ and $p(t)$ errors of the solutions found with the following three algorithms.\n\n\\subsection{Explicit Euler algorithm}\n\\begin{align}\n\\begin{split}\n\\label{al:ho-euler_e}\nx_{i+1} &= p_i\\Delta t + x_i \\\\\np_{i+1} &= -x_i\\Delta t + p_i\n\\end{split}\n\\end{align}\nIn the explicit Euler, time step $i+1$ only reference values from the old time step $i$.\n\n\\subsection{Implicit Euler algorithm}\n\\begin{align}\n\\begin{split}\nx_{i+1} &= p_{i+1}\\Delta t + x_i \\\\\np_{i+1} &= -x_{i+1}\\Delta t + p_i\n\\end{split}\n\\end{align}\nIn the implicit Euler, time step $i+1$ only reference the new values from the same time step. In general this leads to a system of equations that may not have an analytical solutions, and function roots would have to be found numerically using e.g. Newton Raphson. In the case of the harmonic oscillator we have a system of linear equations that can be solved analytically for $(x_{i+1},p_{i+1}$\n\\begin{align}\n\\notag &x_{i+1} = p_{i+1}\\Delta t + x_i \\\\\n\\notag &p_{i+1} = -x_{i+1}\\Delta t + p_i \\\\[0.4cm]\n\\notag & \\Downarrow \\\\[0.4cm]\n\\notag &x_{i+1} - p_{i+1}\\Delta t = x_i \\\\\n\\notag &p_{i+1} + x_{i+1}\\Delta t = p_i \\\\[0.4cm]\n\\notag &\\Downarrow \\\\[0.4cm]\n\\notag &\\begin{bmatrix}\n  1 & -\\Delta t \\\\\n  \\Delta t & 1\n\\end{bmatrix}\n\\begin{bmatrix}\n  x_{i+1} \\\\\n  p_{i+1}\n\\end{bmatrix}\n= \\begin{bmatrix}\n  x_i \\\\\n  p_i\n\\end{bmatrix} \\\\[0.4cm]\n\\notag &\\Downarrow \\\\[0.4cm]\n&\\begin{bmatrix} \\label{al:ho-euler_i}\n  x_{i+1} \\\\\n  y_{i+1}\n\\end{bmatrix}\n= \\dfrac{1}{{\\Delta t}^2 + 1}\n\\begin{bmatrix}\n  1 & \\Delta t \\\\\n  -\\Delta t & 1\n\\end{bmatrix}\n\\begin{bmatrix}\n  x_i \\\\\n  y_i\n\\end{bmatrix}\n\\end{align}\n\n\\subsection{Symplectic Euler algorithm}\n\\begin{align}\n\\begin{split}\n\\label{al:ho-euler_s1}\nx_{i+1} &= p_{i+1}\\Delta t + x_i  \\\\\np_{i+1} &= -x_i\\Delta t + p_i\n\\end{split}\n\\end{align}\nor\n\\begin{align}\n\\begin{split}\n\\label{al:ho-euler_s2}\nx_{i+1} &= p_{i}\\Delta t + x_i  \\\\\np_{i+1} &= -x_{i+1}\\Delta t + p_i\n\\end{split}\n\\end{align}\nIn the symplectic Euler, time step $i+1$ reference the new values one the coordinate equation and the old $i$ value in the momentum equation. This mixing of time step values makes the Euler method symplectic, i.e. energy conserving.\n\nIn the first version \\eqref{al:ho-euler_s1}, clearly $p_{i+1}$ needs to be run before $x_{i+1}$ in each time step. We can also do it the other way around as in \\eqref{al:ho-euler_s2}. They give essential identical solutions. In this case the only difference is a phase shift of the momentum error by $\\pi$ (Appendix \\ref{app:symplectic_difference}).\n\nAlgorithms \\crefrange{al:ho-euler_e}{al:ho-euler_s1} was implemented in Python (Appendix \\ref{app:ho}).\n\n\\section{Plots}\n\\begin{figure}\n    \\centering\n        \\subbottom[Explicit Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_x(t)_euler_explicit.pdf}\n            \\label{fig:ho_x(t)_euler_explicit}\n        }\n        \\subbottom[Implicit Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_x(t)_euler_implicit.pdf}\n            \\label{fig:ho_x(t)_euler_implicit}\n        }\n        \\subbottom[Symplectic Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_x(t)_euler_symplectic.pdf}\n            \\label{fig:ho_x(t)_euler_symplectic}\n        }\n        \\caption{Position x(t)}\n    \\label{fig:ho_x(t)_euler}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Explicit Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_p(t)_euler_explicit.pdf}\n            \\label{fig:ho_p(t)_euler_explicit}\n        }\n        \\subbottom[Implicit Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_p(t)_euler_implicit.pdf}\n            \\label{fig:ho_p(t)_euler_implicit}\n        }\n        \\subbottom[Symplectic Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_p(t)_euler_symplectic.pdf}\n            \\label{fig:ho_p(t)_euler_symplectic}\n        }\n        \\caption{Momentum p(t), equivalent to v(t) by choice of $m=1$}\n    \\label{fig:ho_p(t)_euler}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Explicit Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_x(t)-error_euler_explicit.pdf}\n            \\label{fig:ho_x(t)-error_euler_explicit}\n        }\n        \\subbottom[Implicit Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_x(t)-error_euler_implicit.pdf}\n            \\label{fig:ho_x(t)-error_euler_implicit}\n        }\n        \\subbottom[Symplectic Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_x(t)-error_euler_symplectic.pdf}\n            \\label{fig:ho_x(t)-error_euler_symplectic}\n        }\n        \\caption{Position x(t) error. Note the y-scale difference in symplectic \\ref{fig:ho_x(t)-error_euler_symplectic}}\n    \\label{fig:ho_x(t)-error_euler}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Explicit Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_p(t)-error_euler_explicit.pdf}\n            \\label{fig:ho_p(t)-error_euler_explicit}\n        }\n        \\subbottom[Implicit Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_p(t)-error_euler_implicit.pdf}\n            \\label{fig:ho_p(t)-error_euler_implicit}\n        }\n        \\subbottom[Symplectic Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_p(t)-error_euler_symplectic.pdf}\n            \\label{fig:ho_p(t)-error_euler_symplectic}\n        }\n        \\caption{Momentum p(t) error}\n    \\label{fig:ho_p(t)-error_euler}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Explicit Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_E(t)_euler_explicit.pdf}\n            \\label{fig:ho_E(t)_euler_explicit}\n        }\n        \\subbottom[Implicit Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_E(t)_euler_implicit.pdf}\n            \\label{fig:ho_E(t)_euler_implicit}\n        }\n        \\subbottom[Symplectic Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_E(t)_euler_symplectic.pdf}\n            \\label{fig:ho_E(t)_euler_symplectic}\n        }\n        \\caption{Normalized energy E(t)}\n    \\label{fig:ho_E(t)_euler}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Explicit Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_phase-space_euler_explicit.pdf}\n            \\label{fig:ho_phase-space_euler_explicit}\n        }\n        \\subbottom[Implicit Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_phase-space_euler_implicit.pdf}\n            \\label{fig:ho_phase-space_euler_implicit}\n        }\n        \\subbottom[Symplectic Euler]{\n            \\includegraphics[scale=0.24]{fig/ho/ho_phase-space_euler_symplectic.pdf}\n            \\label{fig:ho_phase-space_euler_symplectic}\n        }\n        \\caption{Phase-space}\n    \\label{fig:ho_phase-space_euler}\n\\end{figure}\n\nThings to note about the integrators from the figures \\crefrange{fig:ho_x(t)_euler}{fig:ho_phase-space_euler}:\n\\begin{itemize}\n    \\item Explicit and implicit drift in position amplitude but stay true in phase.\n    \\item Symplectic drift in phase but stay true in amplitude (and thereby energy).\n    \\item In terms of energy, symplectic stays close to the analytic solution for much longer time. This is what defines a symplectic integrator and it is it's primary benefit.\n    \\item Explicit tends to add energy to the system (spiral outwards in phase-space plot), implicit ends to remove energy from the system (spiral inward in phase-space plot). Symplectic stays in the same orbit in phase-space, i.e. conserves the energy.\n\\end{itemize}\n\n\\subsection{The Two Symplectic Euler Methods Compared} \\label{app:symplectic_difference}\nWe call the first version \\eqref{al:ho-euler_s1} ``Symplectic1'' and the second version \\eqref{al:ho-euler_s2} ``Symplectic2''. We see that they yield essential identical solutions. In this case the only difference is a phase shift of the momentum error by $\\pi$ in figure \\ref{fig:symplectic-difference}.\n\\begin{figure}\n    \\centering\n        \\subbottom[Symplectic1]{\n            \\includegraphics[scale=0.35]{fig/ho/ho_x(t)_euler_symplectic.pdf}\n        }\n        \\subbottom[Symplectic2]{\n            \\includegraphics[scale=0.35]{fig/ho/ho_x(t)_euler_symplectic2.pdf}\n        }\n        \\caption{Position x(t)}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Symplectic1]{\n            \\includegraphics[scale=0.35]{fig/ho/ho_x(t)-error_euler_symplectic.pdf}\n        }\n        \\subbottom[Symplectic2]{\n            \\includegraphics[scale=0.35]{fig/ho/ho_x(t)-error_euler_symplectic2.pdf}\n        }\n        \\caption{Position x(t) error}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Symplectic1]{\n            \\includegraphics[scale=0.35]{fig/ho/ho_p(t)_euler_symplectic.pdf}\n        }\n        \\subbottom[Symplectic2]{\n            \\includegraphics[scale=0.35]{fig/ho/ho_p(t)_euler_symplectic2.pdf}\n        }\n        \\caption{Momentum p(t)}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Symplectic1]{\n            \\includegraphics[scale=0.35]{fig/ho/ho_p(t)-error_euler_symplectic.pdf}\n        }\n        \\subbottom[Symplectic2]{\n            \\includegraphics[scale=0.35]{fig/ho/ho_p(t)-error_euler_symplectic2.pdf}\n        }\n        \\caption{Momentum p(t) error. Note the difference in phase.}\n    \\label{fig:symplectic-difference}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Symplectic1]{\n            \\includegraphics[scale=0.35]{fig/ho/ho_E(t)_euler_symplectic.pdf}\n        }\n        \\subbottom[Symplectic2]{\n            \\includegraphics[scale=0.35]{fig/ho/ho_E(t)_euler_symplectic2.pdf}\n        }\n        \\caption{Energy E(t)}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Symplectic1]{\n            \\includegraphics[scale=0.35]{fig/ho/ho_phase-space_euler_symplectic.pdf}\n        }\n        \\subbottom[Symplectic2]{\n            \\includegraphics[scale=0.35]{fig/ho/ho_phase-space_euler_symplectic2.pdf}\n        }\n        \\caption{Phase-space}\n\\end{figure}", "meta": {"hexsha": "7b84a4c0219e8816da4864c59a5ef629f4b3ccdb", "size": 12280, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/appendices/Harmonic_Oscillator.tex", "max_stars_repo_name": "GandalfSaxe/leto", "max_stars_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/appendices/Harmonic_Oscillator.tex", "max_issues_repo_name": "GandalfSaxe/leto", "max_issues_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/appendices/Harmonic_Oscillator.tex", "max_forks_repo_name": "GandalfSaxe/leto", "max_forks_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.6163522013, "max_line_length": 395, "alphanum_fraction": 0.6548045603, "num_tokens": 4041, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.8688267694452331, "lm_q1q2_score": 0.7485274592535973}}
{"text": "\\section{Fourier Analysis}\n\n$L(\\Omega_h)$ is the set of functions $\\Omega_h \\rightarrow \\mathbb{R}$; $L(\\Omega_h)$ is isomorphic, as $\\mathbb{R}^{(N-1)^2}$.\n\nThe function in $L(\\Omega_h)$ are extended to $\\overline{\\Omega_h}$ by setting value zero there.\n\nSo, we can now consider the Laplacian $\\Delta_h$ as an operator $L(\\Omega_h) \\rightarrow L(\\Omega_h)$.\n\nIs this operator invertible? Or, for $f_h \\in L(\\Omega_h)$, there exists a unique function $v_h$ such that:\n\\begin{equation*}\n\\Delta_h v_h = f_h\n\\end{equation*}\n\n\\begin{equation}\n\\Delta_h v_h(x, y) = f_h(x, y)  \\quad (x, y) in \\Omega_h\n\\end{equation}\n\n\\begin{equation}\nv_h(x, y) = 0 \\quad (x, y) \\in \\Gamma_h\n\\end{equation}\n\nThis means $\\Delta_h$ invertible.\n\nWe know that the previous problem has a unique solution.\n\nSo $\\Delta_h$ is invertible and $\\Delta_h^{-1}$ exists.\nIs $\\Delta_h^{-1}$ uniformly bounded with respect to $h$?\n\nConsider $L(\\Omega_h)$ with the $L^\\infty(\\Omega_h)$.\n\n\\begin{equation*}\n|| \\Delta_h^{-1} || = \\sup_{f_h \\in L^{\\infty}(\\Omega_h), f_h \\neq 0} \\frac{||v_h||_{L^{\\infty}(\\Omega_h)}}{||f_h||_{L^{\\infty}(\\Omega_h)}}\n\\end{equation*}\n\n$\\Delta_h^{-1}$ uniformly bounded with respect to $h$ means there exists $C \\ge 0$, independent of $h$, such that:\n\n\\begin{equation*}\n|| \\Delta_h^{-1} || \\le C\n\\end{equation*}\n\nFor the five-point discretization, we have:\n\n\\begin{equation*}\n||v_h||_{L^{\\infty}(\\Omega_h)} \\le \\frac{1}{8} ||f_h||_{L^{\\infty}(\\Omega_h)}\n\\end{equation*}\n\nfor any problem with right-hand side $f_h$.\n\nThen:\n\n\\begin{equation*}\n|| \\Delta_h^{-1} || \\le \\underbrace{\\frac{1}{8}}_{= C}\n\\end{equation*}\n\nThe relation between the convergence error:\n\n\\begin{equation*}\ne_h = u_h - {u|}_{\\Omega_h} \\in L(\\Omega_h)\n\\end{equation*}\n\nand the consistency error:\n\n\\begin{equation*}\n\\epsilon_h = \\Delta_h u|_{\\overline{\\Omega_h}} - (\\Delta u)|_{\\Omega_h} \\in L(\\Omega_h)\n\\end{equation*}\n\nis:\n\\begin{equation*}\n\\Delta_h e_h = - \\epsilon_h\n\\end{equation*}\n\nSo:\n\\begin{equation*}\ne_h = \\Delta_h^{-1}(-\\epsilon_h)\n\\end{equation*}\n\nand then:\n\\begin{equation*}\n||e_h||_{L^{\\infty}(\\Omega_h)} \\le || \\Delta_h^{-1} || {|| \\epsilon_h ||}_{L^\\infty(\\Omega_h)}\n\\end{equation*}\n\nand then:\n\\begin{equation*}\n||e_h||_{L^{\\infty}(\\Omega_h)} \\le C {|| \\epsilon_h ||}_{L^\\infty(\\Omega_h)}\n\\end{equation*}\n\n$L^\\infty$ on $L(\\Omega_h)$ is the discrete analogous of the $L^\\infty$ on $L(\\Omega)$.\n\nWe introduce a norm on $L(\\Omega_h)$ that is a discrete analogous of the $L^2$ norm on $L^2(\\Omega)$.\n\nFor $v: \\Omega \\rightarrow \\mathbb{R}$,\n\n\\begin{equation*}\n|| v || = \\sqrt{\\int_{(x, y) \\in \\Omega} v(x,y)^2 d(x, y)}\n\\end{equation*}\n\nis called the $L^2$ norm of $v$.\n\n$L^2(\\Omega)$ is the set of the function $\\Omega \\rightarrow \\mathbb{R}$ such that:\n\n\\begin{equation*}\n\\int_{(x, y) \\in \\Omega} v(x,y)^2 d(x, y) < \\infty\n\\end{equation*}\n\nOn $L^2(\\Omega)$, we can introduce the scalar product:\n\\begin{equation*}\n<v, w> = \\int_{(x, y) \\in \\Omega} v(x,y) w(x,y) d(x, y)\n\\end{equation*}\nwith $v, w \\in L^2(\\Omega)$.\n\nThen, the $L^2$ norm is the norm derived by this scalar product:\n\\begin{equation*}\n||v|| = \\sqrt{<v, v>}, \\quad L^2(\\Omega)\n\\end{equation*}\n\nNow, we introduce discrete forms of this scalar product and this norm on $L(\\Omega_h)$ and then to bound uniformly with respect to $h$ the operator norm:\n\n\\begin{equation*}\n|| \\Delta_h^{-1} || = \\sup_{f_h \\in L^{\\infty}(\\Omega_h), f_h \\neq 0} \\frac{||v_h||_h}{||f_h||_h}\n\\end{equation*}\n\nwhere $||.||_h$ is the discrete $L^2$ norm.\n\nFirst, we consider the $1D$ version of the Poisson problem.\n\n\\begin{equation*}\n\\Omega = (0, 1) =: I\n\\end{equation*}\n\\begin{equation*}\n\\Omega_h = \\{h, 2h, \\dots, (N-1)h \\} =: I_h\n\\end{equation*}\n\n$L^2(I)$ is the set of the functions $v: I \\rightarrow \\mathbb{R}$ such that:\n\n\\begin{equation*}\n\\int_{0}^{1} v(x)^2 d(x) < +\\infty\n\\end{equation*}\n\nThe scalar product on $L^2(I)$ is:\n\\begin{equation*}\n<v, w> = \\int_0^1 v(x) w(x) d(x), \\quad v, w \\in L^2(I)\n\\end{equation*}\n\nand the $L^2$ norm is:\n\\begin{equation*}\n||v|| = \\sqrt{\\int_0^1 v(x)^2 d(x)}, \\quad v \\in L^2(I)\n\\end{equation*}\n\nOn $L(I_n)$ we introduce the scalar product:\n\\begin{equation*}\n<v_h, w_h> = h \\sum_{k=1}^{N-1} v_h(k h) w_h(kh)\n\\end{equation*}\n\nand the norm:\n\\begin{equation*}\n{|| v_h ||}_h = \\sqrt{<v_h, v_h>} = \\sqrt{h \\sum_{k=1}^{N-1} v_h(k h)^2}, \\quad v_h \\in L(I_h)\n\\end{equation*}\n\n$||.||$ is the $L^2$ norm on $I_h$.\n\n\\subsubsection{Exercise}\nExplain why the previous scalar product and norm on $L(I_h)$ are discretizations of the scalar product and norm on $L^2(I)$.\n\n\\begin{equation*}\n\\int_{0}^{1} g(x) dx \\approx h \\sum_{k=1}^{N-1} g(kh) = \\sum_{k=1}^{N-1} g(kh) h\n\\end{equation*}\n\nWhen $g = v w \\rightarrow $ scalar product, $g = v^2 \\rightarrow L^2$ norm.\n\nIn $L^2(I)$ we have Fourier series. Consider the functions $\\Phi_m \\in L^2(I)$, $m \\in \\{1, 2, 3, \\dots \\}$ given by:\n\n\\begin{equation*}\n\\Phi_m(x) = sin(m \\pi x), \\quad x \\in (0, 1)\n\\end{equation*}\n\nThese functions are orthogonal:\n\\begin{equation*}\n<\\Phi_m, \\Phi_n> = 0 \\quad \\forall m \\neq n\n\\end{equation*}\n\nThey constitute an orthogonal base for $L^2(I)$; for any $v \\in L^2(I)$ we have the \\textit{Fourier series of $v$}:\n\\begin{equation*}\nv = \\sum_{m=1}^{\\infty} c_m \\Phi_m\n\\end{equation*}\n\nwith:\n\\begin{equation*}\nc_m = \\frac{<v, \\Phi_m>}{<\\Phi_m, \\Phi_m>}, \\quad m \\in \\{1, 2, 3, \\dots \\}\n\\end{equation*}\n\nThe Fourier series converges in $L^2$:\n\\begin{equation*}\n\\lim_{M \\rightarrow \\infty} || v - \\sum_{m = 1}^{M} c_m \\Phi_m || = 0\n\\end{equation*}\n\nWe have the \\textit{Parseval's identity}:\n\\begin{equation*}\n|| v ||^2 = \\sum_{m = 1}^\\infty c_m^2 || \\Phi_m ||^2, \\quad v \\in L^2(I)\n\\end{equation*}\n\nThe functions $\\Phi_m$, with $m \\in \\{1, 2, 3, \\dots\\}$ are eigenvectors of the 1D Laplacian: $\\Delta$ = \"second derivative\".\n\nFor $m \\in \\{1, 2, 3, \\dots \\}$, we have:\n\\begin{equation*}\n\\Delta \\Phi_m(x) = \\frac{d^2}{d x^2} \\sin(m \\pi x) = \\frac{d}{dx}(m \\pi \\cos(m \\pi x)) = m \\pi (-m \\pi \\sin(m \\pi x)) = -m^2 \\pi^2 \\sin(m \\pi x)\n\\end{equation*}\n\\begin{equation*}\n= - m^2 \\pi^2 \\Phi_m(x), \\quad x \\in (0, 1)\n\\end{equation*}\n\n$\\Phi_m$ is an eigenvector of $\\Delta$ with relevant eigenvalue $- m^2 \\pi^2 = \\lambda_m$.\n\nWe do the same for $L(I_h)$.\n\nWe introduce the functions $\\Phi_{m,h} \\in L(I_h), m \\in \\{1, 2, \\dots \\}$, given by:\n\\begin{equation*}\n\\Phi_{m,h}(x) = \\sin(m \\pi x), \\quad x \\in I_h\n\\end{equation*}\n\nThe functions $\\Phi_{m,h}, m \\in \\{1, 2, \\dots \\}$, are eigenvectors of the discrete laplacian:\n\\begin{equation*}\n\\Delta_h v_h(x) = \\frac{v_h(x-h) - 2v_h(x) + v_h(x + h)}{h^2}, \\quad x \\in I_h and v_h \\in L(I_h)\n\\end{equation*}\n\nFor $m \\in \\{1, 2, 3, \\dots \\}$,\n\\begin{equation*}\n\\Delta_h \\Phi_{m,h} (x) = \\frac{\\sin(m \\pi (x-h)) - 2 \\sin (m \\pi x) + \\sin(m \\pi (x + h))}{h^2}\n\\end{equation*}\n\nUsing Prostapheresis formulas:\n\\begin{equation*}\n= \\frac{2 \\sin(m \\pi x) \\cos(m \\pi x) - 2 \\sin(m \\pi x)}{h^2}\n\\end{equation*}\n\n\\begin{equation*}\n= - \\frac{1 - 2 \\cos(m \\pi x)}{h^2} \\underbrace{\\sin(m \\pi x)}_{\\Phi_{m,h}(x)}, \\quad x \\in I_h\n\\end{equation*}\n\n$\\Phi_{m,h}$ is an eigenvector of the discrete 1D laplacian with relevant eigenvalue:\n\n$\\lambda_{m, h} = -2 \\frac{1 - \\cos(m \\pi h)}{h^2} = -2 \\frac{2 \\sin^2(\\frac{m \\pi x}{2})}{h^2} = -4 \\frac{\\sin^2(\\frac{m \\pi x}{2})}{h^2}$ \n\nWe have:\n\\begin{equation*}\n0 > \\lambda_{1, h} > \\lambda_{2, h} > \\dots > \\lambda_{N - 1, h}\n\\end{equation*}\n\n\\subsubsection{Exercise}\n\nProve that:\n\\begin{enumerate}\n\t\\item $\\lim_{h \\rightarrow 0} \\lambda_m = - m^2 \\pi^2$\n\t\\item $\\lambda_{N - 1, h} > - \\frac{4}{h^2}$\n\t\\item $- 8 \\ge \\lambda_{1,h}$\n\\end{enumerate}\n\nProofs:\n\\begin{enumerate}\n\t\\item \n\\begin{equation*}\n\\lim_{h \\rightarrow 0} \\lambda_m = \\lim_{h \\rightarrow 0}( -4 \\frac{\\sin^2(\\frac{m \\pi x}{2})}{h^2})\n\\end{equation*}\n\tUsing the limit $\\lim_{x \\rightarrow 0} \\frac{\\sin x}{x} = 1$ and $\\lim_{x \\rightarrow 0} \\frac{\\sin^2 x}{x^2} = 1$\n\\begin{equation*}\n= -m^2 h^2 \\lim_{h \\rightarrow 0} (\\frac{\\sin(\\frac{m \\pi x}{2})}{\\frac{m \\pi x}{2}})^2 = - m^2 h^2\n\\end{equation*}\n\t\n\t\\item\n\\begin{equation*}\n\\lambda_{N - 1, h} = - 4 \\frac{\\sin^2(\\frac{(N-1) \\pi x h}{2})}{h^2} > -4 \\frac{\\sin^2(\\pi/2)}{h^2} = - \\frac{4}{h^2}\n\\end{equation*}\n\n\t\\item \n\\begin{equation*}\n\\lambda_{1,h} = - 4 \\frac{\\sin^2(\\frac{\\pi h}{2})}{h^2} = - \\pi^2 ( \\frac{\\sin (\\frac{\\pi h}{2})}{\\frac{\\pi h}{2}})^2\n\\end{equation*}\nAs a function of $h$, $\\lambda_{1, h}$ obtains the maximum value when $h$ is the maximum.\n\nThe maximum $h$ possible is $h = \\frac{1}{2}$.\n\n\\begin{equation*}\n\\lambda_{1,h} \\le \\lambda_{1, \\frac{1}{2}} = - 4 \\frac{\\sin^2(\\pi \\frac{1}{2})}{(\\frac{1}{2})^2} = -4 \\frac{\\sin^2(\\frac{\\pi}{4})}{\\frac{1}{4}} = - 16 (\\frac{\\sqrt{2}}{2})^2 = -8\n\\end{equation*}\n\n\\end{enumerate}\n\n$\\blacksquare$\n\n$\\Phi_{1,h}, \\dots, \\Phi_{N-1,h}$ are a bases for the space $L(I_h) = \\mathbb{R}^{N-1}$.\n\nSo for any $v_h \\in \\mathbb{R}^{N-1}$, we have $v_h = \\sum_{m=1}^{N-1} c_{m,h} \\Phi_{m,h}$.\n\nMoreover, observe that $\\Delta_h$ is symmetric and so $\\Phi_{1,h}, \\dots, \\Phi_{N-1,h}$ are orthogonal in the standard scalar product:\n\n\\begin{equation*}\n<v_h, w_h> = \\sum_{x \\in I_h} v_h(x) w_h(x)\n\\end{equation*}\n\nof $\\mathbb{R}^{N-1}$. The scalar product introduced in $L(I_h)$ is:\n\n\\begin{equation*}\n<v_h, w_h>_h = h <v_h, w_h>\n\\end{equation*}\n\nSo $\\Phi_{1,h}, \\dots, \\Phi_{N-1,h}$ are orthogonal also in the scalar product $<., .>_h$\n\n\\subsubsection{Exercise}\n\nFor $v_h \\in L(I_h)$, prove that:\n\n\\begin{equation*}\nc_{m,h} = \\frac{<v_h, \\Phi_{m,h}>}{||\\Phi_{m,h}||_h^2} = <\\Phi_{m,h}, \\Phi_{m,h}> \\quad, m \\in \\{1, \\dots, N-1\\}\n\\end{equation*}\n\nMoreover, prove that the discrete Parceval's identity:\n\n\\begin{equation*}\n||v_h||_h^2 = \\sum_{m=1}^{N-1} c_{m,h}^2 ||\\Phi_{m,h}||_h^2\n\\end{equation*}\n\nWe have:\n\\begin{equation*}\n<v_h, \\Phi_{m,h}>_h = <\\sum_{n=1}^{N-1} c_{n,h} \\Phi_{n,h}, \\Phi_{m,h}>_h = \\sum_{n=1}^{N-1} c_{n,h} \\underbrace{<\\Phi_{n,h}, \\Phi_{m,h}>_h}_{=0 \\;\\; \\forall n \\neq m} = c_{m,h} <\\Phi_{m,h}, \\Phi_{m,h}>\n\\end{equation*}\n\n\\begin{equation*}\n||v_h||_h^2 = <v_h, v_h>_h = <\\sum_{n=1}^{N-1} c_{n,h} \\Phi_{n,h}, \\sum_{m=1}^{N-1} c_{m,h} \\Phi_{m,h}>_h = \\sum_{n=1}^{N-1} \\sum_{n=1}^{N-1} c_{n,h} c_{m,h} <\\Phi_{n,h}, \\Phi_{m,h}>_h = \\sum_{m=1}^{N-1} c_{m,h}^2 \\underbrace{<\\Phi_{m,h}, \\Phi_{m,h}>}_{= ||\\Phi_{m,h}||}\n\\end{equation*}\n\nNow we're ready for the band of:\n\n\\begin{equation*}\n||\\Delta_h^{-1} || = \\sup_{f_h \\in L(I_h)} \\frac{||v_h||_h}{||f_h||_h}\n\\end{equation*}\n\nwhere $v_h$ is the solution of:\n\n\\begin{equation*}\n\\Delta_h v_h = f_h\n\\end{equation*}\n\nLet:\n\\begin{equation*}\nv_h = \\sum_{m=1}^{N-1} c_{m,h} \\Phi_{m,h}\n\\end{equation*}\nthe discrete Fourier series for $v_h$.\n\nWe have:\n\\begin{equation*}\nf_h = \\Delta_h v_h = \\Delta_h \\sum_{m=1}^{N-1} c_{m,h} \\Phi_{m,h} = \\sum_{m=1}^{N-1} c_{m,h} \\underbrace{\\Delta_h\\Phi_{m,h}}_{= \\lambda_{m, h}\\Phi_{m,h}} = \\sum_{m=1}^{N-1} (c_{m,h} \\lambda_{m, h}) \\Phi_{m,h}\n\\end{equation*}\nwhich is the discrete Fourier series of $f_h$.\n\nNow we use the discrete Parseval's identity:\n\\begin{equation*}\n||f_h||_h^2 = \\sum_{m=1}{N-1} (c_{m,h} \\lambda_{m,h})^2 ||\\Phi_{m,h}||_h^2 = \\sum_{m=1}{N-1} c_{m,h}^2 \\underbrace{\\lambda_{m,h}^2}_{= |\\lambda_{m,h}|^2} ||\\Phi_{m,h}||_h^2\n\\end{equation*}\n\n\\begin{equation*}\n-8 \\ge \\lambda_{1,h} \\ge \\lambda_{2,h} \\ge \\dots \\implies 8 \\le |\\lambda_{1,h}| \\le |\\lambda_{2,h}| \\le \\dots \n\\end{equation*}\n\n\\begin{equation*}\n\\ge \\sum_{m=1}^{N-1} 8^2 c_{m,h}^2 ||\\Phi_{m,h}||_h^2 = 8^2 \\underbrace{\\sum_{m=1}^{N-1} c_{m,h}^2 ||\\Phi_{m,h}||_h^2}_{= ||v_h||_h^2}\n\\end{equation*}\n\nSo, we have proved:\n\\begin{equation*}\n||v_h||^2 \\le \\frac{1}{8^2} \\dots\n\\end{equation*}\n\nSince $f_h \\in L(I_h)$ is arbitrary we have:\n\\begin{equation*}\n||\\Delta_h^{-1}|| \\sup_{f_h \\in L(I_h)} \\frac{||v_h||_h}{||f||_h} \\le \\frac{1}{8}\n\\end{equation*}\n\nNow we pass to the 2D case.\n\nIn the 2D case:\n\\begin{equation*}\n\\Omega = (0, 1)^2 = I^2\n\\end{equation*}\n\n\\begin{equation*}\n\\Omega_h = I^2 = \\{(mh, nh): m,n \\in \\{1, \\dots, N-1 \\}\\}\n\\end{equation*}\n\n$L(\\Omega_h)$ is isomorphic to $\\mathbb{R}^{(N-1)^2}$:\n\\begin{equation*}\nL(\\Omega_h) = \\mathbb{R}^{(N-1)^2}\n\\end{equation*}\n\nWe introduce, for $m,n \\in \\{1, \\dots, N-1\\}$, the functions $\\Phi_{m,n,h} \\in L(\\Omega_h)$ given by:\n\\begin{equation*}\n\\Phi_{m,n,h}(x,y) = \\Phi_{m,h}(x) \\Phi_{n,h}(y) \\quad (x,y) \\in \\Omega_h\n\\end{equation*}\n\nwhere $\\Phi_{m,h}$ and $\\Phi_{n,h}$ were defined in the 1D case.\n\nThe scalar product on $L(\\Omega_h)$ is:\n\\begin{equation*}\n<v_h, w_h> = h^2 \\sum_{m=1}^{N-1} \\sum_{n=1}^{N-1} v_h (m_h, n_h) w_h(m_h, n_h)\n\\end{equation*}\n\nand the $L^2$ norm is:\n\\begin{equation*}\n||v_h||_h = \\sqrt{<v_h, v_h>} = \\sqrt{h^2 \\sum_{m=1}^{N-1} \\sum_{n=1}^{N-1} v_h(m_h, n_h)^2}\n\\end{equation*}\nfor $v_h, w_h \\in L(\\Omega_h)$.\n\nFor $m, n \\in \\{1, \\dots, N-1\\}$, $\\Phi_{m,n,h}$ is an eigenvector of the 2D discrete laplacian $\\Delta_h$.\n\n\\begin{equation*}\n\\Delta_h \\Phi_{m,n,h}(x,y) = \\frac{\\Phi_{m,n,h}(x-h, y) - 2 \\Phi_{m,n,h}(x, y) + \\Phi_{m,n,h}(x+h, y)}{h^2} + \\frac{\\Phi_{m,n,h}(x, y-h) - 2 \\Phi_{m,n,h}(x, y) + \\Phi_{m,n,h}(x, y+h)}{h^2}\n\\end{equation*}\n\n\\begin{equation*}\n= \\frac{\\Phi_{m,h}(x - h) \\Phi_{n,h}(y) - 2 \\Phi_{m,h}(x) \\Phi_{n,h}(y) + \\Phi_{m,h}(x+h)\\Phi_{n,h}(y)}{h^2} + \\frac{\\Phi_{m,h}(x) \\Phi_{n,h}(y - h) - 2 \\Phi_{m,h}(x) \\Phi_{n,h}(y) + \\Phi_{m,h}(x)\\Phi_{n,h}(y+h)}{h^2}\n\\end{equation*}\n\n\\begin{equation*}\n= \\frac{\\Phi_{m,h}(x - h) - 2 \\Phi_{m,h}(x) + \\Phi_{m,h}(x+h) }{h^2} \\Phi_{m,h}(y) +  \\Phi_{m,h}(x) \\frac{\\Phi_{n,h}(y - h) - 2\\Phi_{n,h}(y) + \\Phi_{n,h}(y+h)}{h^2}\n\\end{equation*}\n\n\\begin{equation*}\n= \\lambda_{m,h} \\Phi_{m,h}(x) \\Phi_{n,h}(y) + \\Phi_{m,h}(x) \\lambda_{n,h} \\Phi_{n,y}(y) = (\\lambda_{m,h} + \\lambda_{n,h}) \\underbrace{\\Phi_{m,h}(x) \\Phi_{n,h}(y)}_{= \\Phi_{m,n,h}(x,y)}\n\\end{equation*}\n\nWe have proved that $\\Phi_{m,n,h}$ is an eigenvector of 2D $\\Delta_h$ with relevant eigenvalue $\\lambda_{m, h} + \\lambda_{n,h}$.\n\nNow, we prove that $\\Phi_{m,n,h}, m,n \\in \\{1, \\dots, N-1\\}$ are orthogonal in the scalar product of $L(\\Omega_h)$ we have introduced.\n\nFor $m,n,p,q \\in \\{1, \\dots, N-1\\}$ with $(m, n) \\neq (p, q)$:\n\\begin{equation*}\n<\\Phi_{m,n,h}, \\Phi_{p,q,h}>_h = h^2 \\sum_{k=1}^{N-1} \\sum_{l=1}^{N-1} \\Phi_{m,n,h}(kh, lh) \\Phi_{p,q,h}(kh, lh)\n\\end{equation*}\n\n\\begin{equation*}\n= h^2 \\sum_{k=1}^{N-1} \\sum_{l=1}^{N-1} \\Phi_{m,h}(kh)\\Phi_{n,h}(lh) \\Phi_{p,h}(kh)\\Phi_{q,h}(lh)\n\\end{equation*}\n\n\\begin{equation*}\n= h^2 (\\sum_{k=1}^{N-1} \\Phi_{m,h}(kh)\\Phi_{p,h}(kh)) (\\sum_{l=1}^{N-1} \\Phi_{n,h}(lh)\\Phi_{q,h}(lh))\n\\end{equation*}\n\n\\begin{equation*}\n= \\underbrace{<\\Phi_{m,h}, \\Phi_{p,h}>_h}_{1D scalar product} \\cdot \\underbrace{<\\Phi_{n,h}, \\Phi_{q,h}>_h}_{1D scalar product}\n\\end{equation*}\n\nRemember $(m,n) \\neq (p, q)$:\n\\begin{equation*}\nm \\neq p \\text{ or } m n \\neq q\n\\end{equation*}\nso the above scalar product is zero.\n\nSince the $(N-1)^2$ functions $\\Phi_{m,n,h}$, $m,n \\in \\{1, \\dots, N-1\\}$ are nonzero orthogonal functions, they $(N-1)^2$ linearly independent functions of $\\mathbb{R}^{(N-1)^2}$ and so they constitute a bases for $\\mathbb{R}^{(N-1)^2}$.\n\nSo any $v_h \\in L(\\Omega_h)$ can be written as:\n\\begin{equation*}\nv_h = \\sum_{m=1}^{N-1} \\sum_{n=1}^{N-1} \\dots\n\\end{equation*}\n\nExactly as in the 1D case, we have:\n\\begin{equation*}\nc_{m,n,h} = \\frac{<v_h, \\Phi_{m,n,h}>_h}{||\\Phi_{m,n,h}||} \\dots\n\\end{equation*}\n\n\\dots\n\nNow we are ready to give a bond for \n\\begin{equation*}\n||\\Delta_h^{-1}|| = \\sup_{f_h \\in L(\\Omega_h)} \\frac{||v_h||_h}{||f_h||_h}\n\\end{equation*}\n\nwhere $v_h$ is the solution of: $\\Delta_h v_h = f_h$\n\n\\dots\n\nLet $f_h \\in L(\\Omega_h)$ and let $v_h$ be the solution of $\\Delta_h v_h = f_h$. Let:\n\\begin{equation*}\nv_h = \\sum_{m=1}^{N-1} \\sum_{n=1}^{N-1} c_{m,n,h} \\Phi_{m,n,h}\n\\end{equation*}\nbe the Fourier series of $v_h$.\n\nWe have:\n\\begin{equation*}\nf_h = \\Delta_h v_h = \\sum_{m=1}^{N-1} \\sum_{n=1}^{N-1} c_{m,n,h} \\underbrace{\\Delta_h \\Phi_{m,n,h}}_{(\\lambda_{m,h} + \\lambda_{n,h})\\Phi_{m,n,h}} = \\sum_{m=1}^{N-1} \\sum_{n=1}^{N-1} c_{m,n,h} (\\lambda_{m,h} + \\lambda_{n,h}) c_{m,n,h} \\Phi_{m,n,h}\n\\end{equation*}\nwhich is the discrete Fourier series of $f_h$.\n\nSo:\n\\begin{equation*}\n||f_h||_h^2 = \\sum_{m=1}^{N-1} \\sum_{n=1}^{N-1} \\underbrace{(\\lambda_{m,h} + \\lambda_{n,h})^2}_{||\\Phi_{m,n,h}||_h^2} c_{m,n,h}^2\n\\end{equation*}\n\n\\begin{equation*}\n= \\sum_{m=1}^{N-1} \\sum_{n=1}^{N-1} (\\underbrace{|\\lambda_{m,h}|}_{\\ge 8} + \\underbrace{|\\lambda_{n,h}|}_{\\ge 8})^2 c_{m,n,h}^2 \\ge \\sum_{m=1}^{N-1} \\sum_{n=1}^{N-1} 16^2 c_{m,n,h}^2\n\\end{equation*}\n\nThen we have:\n\\begin{equation*}\n||v_h||_h^2 \\le \\frac{1}{16^2} ||f_h||_h^2\n\\end{equation*}\n\n\\begin{equation*}\n||v_h||_h \\le \\frac{1}{16} ||f_h||_h\n\\end{equation*}\n\nSince $f_h \\in L(\\Omega_h)$ is arbitrary:\n\\begin{equation*}\n||\\Delta_h^{-1}|| = \\sup_{f_h \\in L(\\Omega_h)} \\frac{||v_h||_h}{||f_h||_h} \\le \\frac{1}{16}\n\\end{equation*}\n\nRemember we have:\n\\begin{equation*}\n\\Delta_h \\underbrace{e_h}_{convergence error} = - \\underbrace{\\epsilon_h}_{consistency error}\n\\end{equation*}\n\nSo:\n\\begin{equation*}\n||e_h||_h \\le ||\\Delta_h^{-1}|| ||\\epsilon_h||_h \\le \\frac{1}{16} ||\\epsilon_h||_h\n\\end{equation*}\n\nIn case of the $L^\\infty$ norm, we had:\n\\begin{equation*}\n||e_h||_{L^\\infty(\\Omega_h)} \\le \\frac{1}{8} ||\\epsilon_h||_{L^\\infty(\\Omega_h)}\n\\end{equation*}\n\n\n\\subsubsection{Exercise}\n\nProve that, for $v_h \\in L(\\Omega_h)$, we have:\n\\begin{equation*}\n||v_h|| \\le ||v_h||_{L^\\infty(\\Omega_h)}\n\\end{equation*}\n\nand then conclude with the estimate:\n\\begin{equation*}\n||e_h||_h = O(h^2), h \\rightarrow 0\n\\end{equation*}\n\n\\begin{equation*}\n||v_h||_h = \\sqrt{h^2 \\sum_{m=1}^{N-1} \\sum_{n=1}^{N-1} \\underbrace{v_h(kh, nh)^2}_{\\le ||v_h||_{L^\\infty(\\Omega_h)}^2}}\n\\end{equation*}\n\n\\begin{equation*}\n\\le \\sqrt{h^2 \\sum_{m=1}^{N-1} \\sum_{n=1}^{N-1} ||v_h||_{L^\\infty(\\Omega_h} } = ||v_h||_{L^\\infty(\\Omega_h} \\sqrt{h^2 \\sum_{m=1}^{N-1} \\sum_{n=1}^{N-1} 1}\n\\end{equation*}\n\n\\begin{equation*}\n= ||v_h||_{L^\\infty(\\Omega_h} \\underbrace{\\sqrt{h^2 (N-1)}}_{= h (N-1)}\n\\end{equation*}\n\n\\begin{equation*}\n\\le ||v_h||_{L^\\infty(\\Omega_h} \\underbrace{h N}_{= 1} = ||v_h||_{L^\\infty(\\Omega_h}\n\\end{equation*}\n\nThen:\n\\begin{equation*}\n||e_h||_h \\le \\frac{1}{16} ||\\epsilon_h||_h \\le \\frac{1}{16} \\overbrace{||\\epsilon_h||_{L^\\infty(\\Omega_h)}}^{= O(h^2), \\, h \\rightarrow 0}\n\\end{equation*}\n\nand then:\n\\begin{equation*}\n\\qquad\\qquad\\qquad\\qquad\\qquad\\qquad ||e_h||_h = O(h^2), \\, h \\rightarrow 0   \\qquad\\qquad\\qquad\\qquad\\qquad\\qquad \\blacksquare\n\\end{equation*}\n\n\\section{Some notes needs to be copied from paper here}\n\n...\n\nWe proved: for $v: \\overline{\\Omega} \\rightarrow \\mathbb{R}$ of class $C^3$:\n\n..\n\nThe order of consistency error is only $O(h)$, not $O(h^2)$ as in the case of the square.\nWe have the discrete problem:\n\n\\begin{equation*}\n\\Delta_h u_h (x, y) = f(x, y), \\quad (x, y) \\in \\Omega_h\n\\end{equation*}\n\\begin{equation*}\nu_h(x, y) = g(x, y), \\quad (x,y) \\in \\Gamma_h\n\\end{equation*}\n\nThis is a linear system of M unknowns $u_h(x, y), \\quad (x,y) \\in \\Omega_h$, where $M$ is the number of points in $\\Omega_h$, into $M$ equations; we have an equation for any point in $\\Omega_h$.\n\nWith respect to the case of the square, the matrix of the system is in general non-symmetric, because:\n\n\\begin{equation*}\n\\Delta_h u_h(x, y) = \\frac{2}{h_1 (h_1 + h_2)} u_h(x - h_1, y) - \\frac{2}{h_1 h_2} (x, y) + \\frac{2}{h_2 (h_1 + h_2)} (x + h_2, y) + \\frac{2}{h_3 (h_3 + h_4)} u_h(x, y - h_3) - \\frac{2}{h_3 h_4} (x, y) + \\frac{2}{h_3 (h_3 + h_4)} (x, y + h_4) = f(x, y), \\quad (x,y) \\in \\Omega_h\n\\end{equation*}\n\nSymmetric matrix: $a_{ij} = a_{ji}$\nthe coefficient of the \\textit{j}-th matrix, in the \\textit{i}-th equation is equal to the coefficient of the \\textit{i}-th matrix in the \\textit{j}-th equation.\nThe coefficient in the \\textit{j}-th equation of the \\textit{i}-th unknown is \n\n\\begin{equation*}\n\\frac{2}{h_2 (h_2 + \\hat{h_2})} u_h(x, y) - \\frac{2}{h_2 \\hat{h_2}} u_h(x + h_2, y)+ \\frac{2}{\\hat{h_2}(h_2 + \\hat{h_2})} u_h(x + \\hat{h_2}, y)\n\\end{equation*}\n\nCharacteristics of the matrix that are maintained in the general case:\n\\begin{itemize}\n\t\\item sparsity (the matrix is sparse): in any row there are at most 5 non-zero elements;\n\t\\item diagonal elements are negative and off-diagonal elements are positive\n\t\\item diagonal dominance\n\\end{itemize}\n\nAn MxM matrix A is called diagonal dominant if:\n\n\\begin{equation*}\n\\forall i \\in \\{1, \\dots, M\\}: |a_{ii}| \\ge \\sum_{j=1, j \\neq i}^{M} |a_{ij}|\n\\end{equation*}\n\nMaximum sum of the off-diagonal elements is:\n\n\\begin{equation*}\n\\frac{2}{h_1 (h_1 + h_2)} + \\frac{2}{h_2 (h_1 + h_2)} + \\frac{2}{h_3 (h_3 + h_4)} + \\frac{2}{h_4 (h_3 + h_4)} = \\frac{2}{h_1 + h_2} (\\frac{1}{h_1} + \\frac{1}{h_2}) + \\frac{2}{h_3 + h_4 (\\frac{1}{h_3} + \\frac{1}{h_4})}\n\\end{equation*}\n\n\\begin{equation*}\n\\frac{2}{h_1 + h_2} \\frac{h_1 + h_2}{h_1 h_2} + \\frac{2}{h_3 + h_4} \\frac{h_3 + h_4}{h_3 h_4} = \\frac{2}{h_1 + h_2} + \\frac{2}{h_3 + h_4}\n\\end{equation*}\n\nWe have, by stability plus consistency of order one, convergence of order one. But\n\\begin{enumerate}\n\t\\item Points in $\\mathring{\\Omega}_h$ have consistency error $O(h^2)$;\n\t\\item number of points in $\\Omega_h \\mathring{\\Omega}_h$ (where the consistency error is $O(h)$)  divided by number of points in $\\mathring{\\Omega}_h$ (where the consistency error is $O(h^2)$) $= O(h)$\n\t\\item Points of $\\Omega_h \\\\ \\mathring{\\Omega}_h$ are at a distance $O(h)$ of the boundary $\\Gamma_h$, where the solution is known exactly.\n\\end{enumerate}\n\n", "meta": {"hexsha": "7cddbf258d8593e8a9d5072b26f99b85dbb41c40", "size": 21209, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/ch03.tex", "max_stars_repo_name": "bebosudo/advanced-numerical-analysis", "max_stars_repo_head_hexsha": "a46aea05b7bef661c689ca5facf10d5ea4a85d30", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/ch03.tex", "max_issues_repo_name": "bebosudo/advanced-numerical-analysis", "max_issues_repo_head_hexsha": "a46aea05b7bef661c689ca5facf10d5ea4a85d30", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/ch03.tex", "max_forks_repo_name": "bebosudo/advanced-numerical-analysis", "max_forks_repo_head_hexsha": "a46aea05b7bef661c689ca5facf10d5ea4a85d30", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.5585443038, "max_line_length": 278, "alphanum_fraction": 0.6100711962, "num_tokens": 9214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8688267762381844, "lm_q1q2_score": 0.7485274589284127}}
{"text": "\\subsection{Acceleration Field for a Rigid Body}\n\\begin{frame}\n\tAcceleration vector $\\vb{a}{}=\\xvec[:]{\\bm{r}}$ with respect to time $t$:\n\t\\[\\vb{a}{}= \\frac{d}{dt}(\\vb{v}{O} + \\vb{\\omega}{}\\times\\vb{r}{}) = \\xvec[.]{\\bm{r}}_{\\bm{M}}+\\xvec[.]{\\bm{\\omega}}\\times\\vb{r}{} + \\vb{\\omega}{}\\times\\xvec[.]{\\bm{r}} = \\vb{a}{0}+\\vb{\\alpha}{}\\times\\vb{r}{}+\\vb{\\omega}{}\\times(\\vb{\\omega}{}\\times\\vb{r}{})\\]\n\twhere $\\displaystyle \\vb{\\alpha}{} = \\xvec[.]{\\bm{\\omega}} = \\dot{\\omega}_x\\ih + \\dot{\\omega}_y\\jh + \\dot{\\omega}_z\\kh + \\omega_x\\frac{d\\ih}{dt} + \\omega_y\\frac{d\\jh}{dt}+\\omega_z\\frac{d\\kh}{dt}$\\\\\n\t$\\hskip 22mm\\displaystyle = \\alpha_x\\ih + \\alpha_y\\jh + \\alpha_z\\kh + \\omega_x\\vb{\\omega}{}\\times\\ih + \\omega_y\\vb{\\omega}{}\\times\\jh + \\omega_z\\vb{\\omega}{}\\times\\kh$\\\\\n\t$\\hskip 22mm\\displaystyle = \\alpha_x\\ih + \\alpha_y\\jh + \\alpha_z\\kh + \\vb{\\omega}{}\\times\\vb{\\omega}{}$\\\\\n\t$\\hskip 22mm\\displaystyle = \\alpha_x\\ih + \\alpha_y\\jh + \\alpha_z\\kh$\n\t\\begin{block}{Formula}\n\t\tFor any point of a rigid body, its acceleration equation is:\n\t\t\\[\n\t\t\\vb{a}{}=\\vb{a}{0}+\\vb{\\alpha}{}\\times\\vb{r}{}+\\vb{\\omega}{}\\times(\\vb{\\omega}{}\\times\\vb{r}{})\n\t\t\\]\n\t\twhere $\\vb{\\alpha}{}\\times\\vb{r}{}$ is tangential acceleration\\\\\\hskip10.5mm\n\t\t$\\vb{\\omega}{}\\times(\\vb{\\omega}{}\\times\\vb{r}{})$ is centripetal acceleration \n\t\\end{block}\n\\end{frame}\n\n\\begin{frame}\n\tIn matrix form, acceleration vector $\\vb{a}{M}$ of point $M$ relative to fixed reference frame $(O_0x_0y_0z_0)$ can be written as:\n\t\\[\n\t\\vb{a}{M}=\n\t\\begin{bmatrix}\n\ta_x\\\\a_y\\\\a_z\n\t\\end{bmatrix}=\n\t\\begin{bmatrix}\n\ta_{Ox}+(z\\alpha_y-y\\alpha_z)+\\omega_y(y\\omega_x-x\\omega_y)+\\omega_z(x\\omega_x-x\\omega_z)\\\\\n\ta_{Oy}+(x\\alpha_z-z\\alpha_x)+\\omega_z(z\\omega_y-y\\omega_z)+\\omega_x(x\\omega_y-y\\omega_z)\\\\\n\ta_{Oz}+(y\\alpha_x-x\\alpha_y)+\\omega_x(x\\omega_z-z\\omega_x)+\\omega_y(y\\omega_z-z\\omega_y)\n\t\\end{bmatrix}\n\t\\]\\hskip7mm\n\t$\\displaystyle= \\vb{a}{O}+\\vb{\\alpha}{}\\times\\vb{r}{MO} + \\vb{\\omega}{}\\times(\\vb{\\omega}{}\\times\\vb{r}{MO}) = \\vb{a}{O} +\\vb{a}{MO}^{\\bm t}+ \\vb{a}{MO}^{\\bm n}$\\\\\n\twhere \n\t\\[\n\t\\vb{a}{MO}^{\\bm t}=\n\t\\begin{cases}\n\t\\perp \\vb{r}{MO}\\rightturn \\vb{\\alpha}{}\\\\\\alpha r_{MO}\n\t\\end{cases}\n\t\\]\n\t\\[\n\t\\hskip 6mm\\vb{a}{MO}^{\\bm n}=\n\t\\begin{cases}\n\t\\uparrow\\uparrow \\vb{r}{MO}\\\\\\omega^2r_{MO}=\\frac{v_{MO}^2}{r_{MO}}\n\t\\end{cases}\n\t\\]\n\tFor planar motions: $\\vb{\\omega}{}\\times(\\vb{\\omega}{}\\times\\vb{r}{MO})=-\\vb{\\omega}{}^2\\vb{r}{MO}$\n\\end{frame}", "meta": {"hexsha": "37217d26a25be7df93d3c5cc1f61a16cac3fa7c4", "size": 2391, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Finished/velocity_acceleration_analysis_pdf/Sections/Introduction/Acceleration_field_rigid_body.tex", "max_stars_repo_name": "HungNguyenDang/literate-meme", "max_stars_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Finished/velocity_acceleration_analysis_pdf/Sections/Introduction/Acceleration_field_rigid_body.tex", "max_issues_repo_name": "HungNguyenDang/literate-meme", "max_issues_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Finished/velocity_acceleration_analysis_pdf/Sections/Introduction/Acceleration_field_rigid_body.tex", "max_forks_repo_name": "HungNguyenDang/literate-meme", "max_forks_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.8723404255, "max_line_length": 259, "alphanum_fraction": 0.6106231702, "num_tokens": 1051, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973295, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7485156748925617}}
{"text": "\n\\subsection{Probability unit (probit)}\n\n\\subsubsection{The function}\n\nThe cumulative distribution function of the normal distribution.\n\n\\(\\Phi (z)\\)\n\n\\subsubsection{The derivative}\n\nThe normal distribution:\n\n\\(\\Phi'(z)=\\phi (z)\\)\n\n\n", "meta": {"hexsha": "39aa0efda61b8582b21af5e74ec40268a835f79e", "size": 233, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/glm/03-04-probit.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/glm/03-04-probit.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/glm/03-04-probit.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.7058823529, "max_line_length": 64, "alphanum_fraction": 0.7296137339, "num_tokens": 56, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.926303732328411, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7485156694638311}}
{"text": "\\subsection{Conversions}\r\n\\begin{itemize}\r\n\t\\item From spherical to Cartesian\r\n\t\\begin{equation*}\r\n\t\t(\\rho, \\theta, \\phi) = (r\\cos{\\theta}\\sin{\\phi}, \\rho\\sin{\\theta}\\sin{\\phi}, \\rho\\cos{\\phi})\r\n\t\\end{equation*}\r\n\t\\item From Cartesian to Spherical\r\n\t\\begin{equation*}\r\n\t\t(x, y, z)=\\left(\\sqrt{x^2 + y^2 + z^2}, \\arctan{\\left(\\frac{y}{x}\\right)}, \\arccos{\\left(\\frac{z}{\\sqrt{x^2 + y^2 + z^2}}\\right)}\\right)\r\n\t\\end{equation*}\r\n\\end{itemize}", "meta": {"hexsha": "89316322f53749bcb354be87b93582f05ce55bff", "size": 440, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/curvilinearCoordinates/conversions_spherical.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/curvilinearCoordinates/conversions_spherical.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/curvilinearCoordinates/conversions_spherical.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 40.0, "max_line_length": 139, "alphanum_fraction": 0.6181818182, "num_tokens": 178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896845856297, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7484798370273625}}
{"text": "\\subsection{Statistical Analysis}\n\\label{sec:statistical-analysis}\n\nThe first stage in our engine is analyzing the expanded tuples.\nThis phase collects simple statistics including average, variance, standard deviation, and approximate cardinality on each column of the table and estimates which sets of columns are correlated.\n\nThese statistics have three purposes. \nFirst, they are used to detect univariate outliers, for example values that are several standard deviations from the mean in numerical attributes, or that have never occurred before in low cardinality attributes.\nSecond, they are used to determine which columns in the table are correlated. \nThird, these statistics precompute parameters required by certain data models, thus speeding up the training phase of the models.\n\nWe focus on two inter-column correlation strategies:\n\n\\begin{itemize}\n\\item For mostly non-numerical datasets, we use a cardinality-based measure, flagging groups of expanded columns as correlated when their joint cardinality is below a user-specified threshold. When two columns are correlated (e.g., when one is computed directly from the other), the number of distinct pairs in the columns is similar to the number of distinct items in either column. On the other hand, when two columns are independent, the number of distinct pairs is close to the product of the number of distinct values in each column.\n\\item For mostly-numerical datasets, we use Pearson's product-moment\n  correlation. It relies on the Pearson correlation coefficient,\n  which measures linear dependencies between two vectors.\n\n  Given two column vectors $X$ and $Y$, Pearson's coefficient $R$ is given by the following formula:\n  \\begin{align}\n    \\label{eqn:pearson}\n    R = \\frac{\\Covar(X,Y)}{\\sqrt{\\Var(X)\\Var(Y)}}\n  \\end{align}\n\n  $R$'s value always lies between $-1$ and $1$. An $R$ value close to 0 indicates little or no correlation, while values close to $+1$ or $-1$ indicate strong positive or negative correlations, respectively. Pairs of columns with a value of \\(R\\) above a user-specified threshold are added to a list of correlation hints, for use by the models.\n\\end{itemize}\n\nIt is debatable whether correlations between expanded tuple fields from the same original value lead to better outlier detection. On the one hand such dependencies may provide valuable insight about the data (e.g., an event that occurs every Monday of May and every Thursday of June). On the other hand, taking these subtuple correlations into account vastly increases the size of the search space, and may add spurious hits to the results. Experimentally, we found that disregarding intra-field correlations made the entire process faster and more robust, and did not hurt accuracy on our test sets.\n\nAll aforementioned statistics and correlation hints can be computed using a single pass over the data: the expanded tuples are analyzed one row at a time, and the final statistics and correlations are computed after the last tuple has been processed. This contrasts with more advanced approaches to the detection of correlations and soft functional dependencies, such as the one used in CORDS~\\cite{Ilyas2004}. Our simpler approaches yields a lower specificity, but still achieves good classification results, in part because each model only uses correlation hints as a guideline for interesting groups of columns to analyze. An excessive number of hints can thus affect performance, but does not significantly diminish the quality of the results. On the other hand, missing a correlation causes models to not analyze the corresponding group of columns, and thus to fail to uncover potential outliers. As with the other parts of our system, the correlation detector used in the statistical analysis phase is modular and could be replaced by any other scheme, including CORDS.\n\nThe results of the analysis pass are available to all models used at later stages in the tool.\n", "meta": {"hexsha": "e304a426c8c2a0a909728dc4e5047409caf7a076", "size": 3932, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "raha/tools/dBoost/paper/icde/statistical-analysis.tex", "max_stars_repo_name": "adrianlut/raha", "max_stars_repo_head_hexsha": "027ebeaf0ac4b524dc49df94e7bbc7be4391213d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2019-07-05T12:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T07:44:58.000Z", "max_issues_repo_path": "raha/tools/dBoost/paper/icde/statistical-analysis.tex", "max_issues_repo_name": "adrianlut/raha", "max_issues_repo_head_hexsha": "027ebeaf0ac4b524dc49df94e7bbc7be4391213d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-10T12:59:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-10T12:59:43.000Z", "max_forks_repo_path": "raha/tools/dBoost/paper/icde/statistical-analysis.tex", "max_forks_repo_name": "adrianlut/raha", "max_forks_repo_head_hexsha": "027ebeaf0ac4b524dc49df94e7bbc7be4391213d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2019-04-21T12:28:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-28T06:42:36.000Z", "avg_line_length": 115.6470588235, "max_line_length": 1075, "alphanum_fraction": 0.8021363174, "num_tokens": 795, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7484690774420835}}
{"text": "\\section{Linear Maps, Isomorphisms and the Rank-Nullity Theorem}\r\n\\begin{definition}[Linear Map]\r\n    Let $V,W$ are vector spaces over $F$, a function $\\alpha:V\\to W$ is linear if for any $\\lambda_1,\\lambda_2\\in F$ and $v_1,v_2\\in V$,\r\n    $$\\alpha(\\lambda_1v_1+\\lambda_2v_2)=\\lambda_1\\alpha(v_1)+\\lambda_2\\alpha(v_2)$$\r\n\\end{definition}\r\n\\begin{example}\r\n    1. Let $M$ be an $m\\times n$ matrix, then $\\alpha:\\mathbb R^n\\to\\mathbb R^m$ via $x\\mapsto Mx$ is a linear map.\\\\\r\n    2. The functional $\\alpha:C([0,1])\\to C^1([0,1])$ via\r\n    $$\\alpha(f)(x)=\\int_0^xf(t)\\,\\mathrm dt$$\r\n    is a linear map.\\\\\r\n    3. Fix $x\\in[a,b]$, then the evaluation map $\\alpha:C([a,b])\\to\\mathbb R$ via $f\\mapsto f(x)$ is a linear map.\r\n\\end{example}\r\n\\begin{remark}\r\n    The identity map is a linear map.\r\n    Composition of linear maps is also a linear map.\r\n\\end{remark}\r\n\\begin{lemma}\r\n    Let $V,W$ be vector spaces over $F$ and $B$ a basis for $V$.\r\n    Let $\\alpha_0:B\\to W$ be a function, then there is a unique linear map $\\alpha:V\\to W$ that extends $\\alpha_0$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    For any $(b_i)\\in B$, necessarily $\\alpha\\left(\\sum_i\\lambda_ib_i\\right)=\\sum_i\\lambda\\alpha_0(b_i)$.\r\n    This is sufficient.\r\n\\end{proof}\r\n\\begin{remark}\r\n    This lemma is true for infinite dimensional vector spaces as well.\r\n    Often, to define linear map, we often just define its values on a basis and extend it by this lemma.\r\n\\end{remark}\r\n\\begin{corollary}\r\n    Two linear maps that agree on a basis are the same.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    This is just the uniqueness statement.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $V,W$ be vector spaces over $F$.\r\n    A linear bijection $\\alpha:V\\to W$ is an isomorphism (of vector spaces).\r\n    If such a map exists, then we say $V,W$ are isomorphic (as vector spaces), written as $V\\cong W$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    If $\\alpha$ is an isomorphism, so is $\\alpha^{-1}$.\r\n\\end{remark}\r\n\\begin{lemma}\r\n    $\\cong$ is an equivalence relation on the class of all vector spaces over $F$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Just check.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    If $V$ is a vector space over $F$ of dimension $n$, then $V\\cong F^n$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Take a basis $\\{b_1,\\ldots,b_n\\}$ of $V$, then\r\n    $$\\alpha(x_1b_1+\\cdots+x_nb_n)=(x_1,\\ldots,x_n)$$\r\n    is an isomorphism.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Choosing a basis of $V$ is then just equivalent to choosing an isomorphism from $V$ to $F^n$.\r\n\\end{remark}\r\n\\begin{theorem}\r\n    Let $V,W$ be finite dimensional vector spaces over $F$.\r\n    Then $V\\cong W$ iff $\\dim V=\\dim W$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Any basis of $V$ induces a basis of $W$ via the isomorphism, so they have the same dimension.\r\n    Therefore are both isomorphic to $F^n$ where $n=\\dim V=\\dim W$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $\\alpha:V\\to W$ be a linear map.\r\n    We define the kernel of $\\alpha$ to be $\\ker\\alpha=\\{v\\in V:\\alpha(v)=0\\}$ and the image to be $\\operatorname{Im}\\alpha=\\alpha(V)=\\{w\\in W:\\exists v\\in V,\\alpha(v)=w\\}$.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    $\\ker\\alpha\\le V,\\operatorname{Im}\\alpha\\le W$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\n\\begin{example}\r\n    Take $\\alpha:C^\\infty(\\mathbb R)\\to C^\\infty(\\mathbb R)$ by $\\alpha(f)(t)=f^{\\prime\\prime}(t)+f(t)$.\r\n    Then $\\ker\\alpha$ is spanned by $t\\mapsto e^t$ and $t\\mapsto e^{-t}$ and $\\operatorname{Im}\\alpha=C^{\\infty}(\\mathbb R)$.\r\n\\end{example}\r\n\\begin{theorem}\r\n    Let $V,W$ be vector spaces over $F$ and $\\alpha:V\\to W$ be linear, then $V/{\\ker\\alpha}\\cong \\operatorname{Im}(\\alpha)$ via $v+\\ker\\alpha\\mapsto \\alpha(v)$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Just check.\r\n\\end{proof}\r\n\\begin{definition}\r\n    The rank of $\\alpha:V\\to W$ is $r(\\alpha)=\\dim\\operatorname{Im}\\alpha$ and nullity is $n(\\alpha)=\\dim\\ker\\alpha$.\r\n\\end{definition}\r\nHence in the finite dimensional case, we can rewrite the preceding theorem to get\r\n\\begin{theorem}[Rank-Nullity Theorem]\r\n    Let $\\alpha:V\\to W$ be linear where $V$ is finite dimensional.\r\n    Then $\\dim V=r(\\alpha)+n(\\alpha)$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Follows from the preceding theorem.\r\n\\end{proof}\r\n\\begin{corollary}[Classification of Isomorphism]\r\n    Let $V,W$ be finite dimensional vector spaces with $\\dim V=\\dim W$ and $\\alpha:V\\to W$ be linear, then the followings are equivalent:\\\\\r\n    1. $\\alpha$ is injective.\\\\\r\n    2. $\\alpha$ is surjective.\\\\\r\n    3. $\\alpha$ is an isomorphism.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Follows immediately by considering dimensions.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider\r\n    $$V=\\left\\{ \\begin{pmatrix}\r\n        x\\\\\r\n        y\\\\\r\n        z\r\n    \\end{pmatrix}\\in\\mathbb R^3:x+y+z=0\\right\\}$$\r\n    We want to compute $\\dim V$.\r\n    Consider $\\alpha:\\mathbb R^3\\to\\mathbb R$ via $(x,y,z)^\\top\\mapsto x+y+z$, then $r(\\alpha)=1$ and $n(\\alpha)=V$, so $\\dim V=3-1=2$.\r\n    Geometrically, $V$ is just a plane with normal $(1,1,1)^\\top$.\r\n\\end{example}", "meta": {"hexsha": "303d6ff380843ab57d7a914dbc94654c542842c6", "size": 4982, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/map.tex", "max_stars_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_stars_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4/map.tex", "max_issues_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_issues_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4/map.tex", "max_forks_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_forks_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.2203389831, "max_line_length": 174, "alphanum_fraction": 0.6469289442, "num_tokens": 1667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583169, "lm_q2_score": 0.9005297841157157, "lm_q1q2_score": 0.7484690694571281}}
{"text": "% !TEX root =../thesis-letomes.tex\n\\chapter{Using Hamiltonian Mechanics} \\label{apx:using-hamilton-mechanics}\n\n\\section{Hamilton's Equations - A 5-step Process}\nWe will now look at the procedure for using Hamiltonian mechanics in practice (this section is borrowed from \\cite{Saxe2015}). In the next chapter ``Numerical Methods'' we will then solve the equations of motion, in part to demonstrate the validity of Hamilton's equations of motion, and in part to analyze how various numerical techniques perform.\n\\begin{description}\n\\item[Step 0 \\quad Lagrangian $L$] \\ \\vspace{0.3cm}\n\\begin{enumerate}[label=(\\alph*)]\n\\item Define general coordinates $q_i$, $i=1,2 \\dots n$, where $n$ is the degrees of freedom for the system.\n\\item Determine kinetic energy $T(\\vec{q},\\dot{\\vec{q}}, t)$ = $\\frac{1}{2}m v^2$.\n\\item Determine potential energy $V(\\vec{q},\\dot{\\vec{q}}, t)$.\n\\item Lagrangian: \\begin{align}\nL = T - V.\n\\end{align}\n\\end{enumerate}\n\\item[Step 1 \\quad Generalized momenta $p_i$] \\ \\vspace{0.3cm}\n\\begin{align}\np_i(\\vec{q},\\vec{\\dot{q}}, t) = \\dfrac{\\partial L}{\\partial \\dot{q_i}},\n\\end{align}\nfor all $i = 1 \\dots n$.\n%\n\\item[Step 2 \\quad Transform all the $\\dot{q_i}$] \\ \\vspace{0.3cm} \\\\ \nTechnically called a Legendre transform, this is the step that takes us from Lagrangian mechanics to Hamiltonian mechanics. We basically isolate the $\\dot{q_i}$ in the $p_i$-equations from step 1, and eliminate all $\\dot{q_i}$ in the equations in favor of $p_i$. Thus we go from independent variables $(\\vec{q}, \\vec{\\dot{q}})$ to $(\\vec{q}, \\vec{p})$ by transforming:\n\\begin{align}\n\\dot{q_i} = \\dot{q_i}(\\vec{q}, \\vec{p}, t).\n\\end{align}\n%\n\\item[Step 3 \\quad The Hamiltonian $H$] \\ \\vspace{0.3cm}\n\\begin{align}\nH(\\vec{q}, \\vec{p}, t) = \\sum\\limits_{i=1}^n p_i \\dot{q_i} - L,\n\\end{align}\nfor all $n=1\\cdots n$, where it is understood that all the $q_i$ are substituted with expressions found in step 2.\n%\n\\item[Step 4 \\quad Hamilton's Equations of Motion]\n\\begin{align}\n\\begin{split}\n\\dot{q_i} &= +\\dfrac{\\partial H}{\\partial p_i},\n\\\\[0.2cm]\n\\dot{p_i} &= -\\dfrac{\\partial H}{\\partial q_i},\n\\end{split}\n\\end{align}\n\\end{description}\nfor $i = 1 \\dots n$, which gives us $2n$ 1st order coupled PDEs of $2n$ variables \\\\\n$(q_1,q_2,\\dots,q_n,p_1,p_2,\\dots,p_n)$.\n\nIn general $T$ and $V$ can be time-dependent (and therefore $L$ and $H$ can too). However in many applications, including the our model problem, they are not time-dependent.\n\nAn important property of the Hamiltonian is that if it is not explicitly time dependent then it is conserved $\\mathrm{d}H/\\mathrm{d}t = 0$ along the $(\\vec{p}(t),\\vec{q(t)})$ flow \\cite{Knudsen2002}.\n\n\n\\subsection{$H$ vs. $E$} \\label{ch:HvsE}\n\nAn important characteristic of a closed physical system is it's energy $E$. By a clever choice of coordinate system, it is possible to have systems where Hamiltonian $H$ is conserved, but the total mechanical energy $E$ is not. In that sense in can be argued that the Hamiltonian is a more general concept than energy. It can be shown that $H = E$ if and only if the following three conditions are met: \\cite[pp.~60--64]{Goldstein2002} \\cite{ucsd-quadratic} \\cite{unige-quadradic}\n\n\\begin{enumerate}\n    \\item Equations of constraints, $T$ and $V$ have no explicit time-dependency.\n    \\item $V$ is independent of $\\vec{\\dot{q}}$.\n    \\item T is a homogeneous quadratic in the $\\dot{q}$s, in particular if $T(\\vec{q},\\vec{\\dot{q}}) = \\frac{1}{2} \\vec{\\dot{q}}^\\top M(q)\\vec{\\dot{q}}$, where $M(q)$ is some symmetric and positive definite matrix.\n\\end{enumerate}\nMeeting these conditions also implies that the generalized impulses $p_i$ will be equal to well known conserved quantities such as linear momentum, angular momentum etc. We will later see that the equations for restricted three-body system satisfy the conditions. Another way to see if $T$ is a quadratic form is if its a homogeneous polynomial, i.e. all terms have same degree in a number of variables. For example $P(x,y) = 4x^2 + 2 x y + 3y^2$ \\cite{wiki-quadratic} is quadratic.", "meta": {"hexsha": "94a40031f5f4b536f415265dc3582aa0e209bf74", "size": 4024, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/appendices/APX2-Using-Hamiltonian-Mechanics.tex", "max_stars_repo_name": "GandalfSaxe/letomes", "max_stars_repo_head_hexsha": "5f73a4066fcf69260cb538c105acf898b22e756d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/appendices/APX2-Using-Hamiltonian-Mechanics.tex", "max_issues_repo_name": "GandalfSaxe/letomes", "max_issues_repo_head_hexsha": "5f73a4066fcf69260cb538c105acf898b22e756d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/appendices/APX2-Using-Hamiltonian-Mechanics.tex", "max_forks_repo_name": "GandalfSaxe/letomes", "max_forks_repo_head_hexsha": "5f73a4066fcf69260cb538c105acf898b22e756d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.0666666667, "max_line_length": 482, "alphanum_fraction": 0.7119781312, "num_tokens": 1264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.7484209173949846}}
{"text": "\\section{Complex Integration}\r\n\\subsection{Definition}\r\nWe want to generalize the notion of the real Riemann integration to the integration to complex valued functions on the complex plane.\r\n\\begin{definition}\r\n    If $f:[a,b]\\to\\mathbb C$ is continuous, then we define the integral of $f$ to be\r\n    $$\\int_a^b f(x)\\,\\mathrm dx :=\\int_a^b\\operatorname{Re}f(x)\\,\\mathrm dx+i\\int_a^b\\operatorname{Im}f(x)\\,\\mathrm dx$$\r\n\\end{definition}\r\nEasy to check that both integrals are well-defined and the integral is linear.\r\n\\begin{proposition}\r\n    $$\\left|\\int_a^bf(t)\\,\\mathrm dt\\right|\\le (b-a)\\sup_{t\\in [a,b]}|f(t)|$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    If the integral is zero then there is nothing to prove.\r\n    Otherwise we can write it in the form $re^{i\\theta}$ for some $r\\in\\mathbb R_{>0},\\theta\\in\\mathbb R$, so\r\n    \\begin{align*}\r\n        \\left|\\int_a^bf(t)\\,\\mathrm dt\\right|=r&=\\int_a^be^{-i\\theta}f(t)\\,\\mathrm dt\\\\\r\n        &=\\int_a^b\\operatorname{Re}(e^{-i\\theta}f(t))\\,\\mathrm dt\\\\\r\n        &\\le \\int_a^b|\\operatorname{Re}(e^{-i\\theta}f(t))|\\,\\mathrm dt\\\\\r\n        &\\le \\int_a^b|f(t)|\\,\\mathrm dt\\\\\r\n        &\\le (b-a)\\sup_{t\\in [a,b]}|f(t)|\r\n    \\end{align*}\r\n    As desired.\r\n\\end{proof}\r\nNote that the equality holds iff $f$ is constant.\r\n\\begin{definition}\r\n    Let $\\gamma:[a,b]\\to\\mathbb C$ be a $C^1$ curve, then the length of $\\gamma$ is\r\n    $$\\int_a^b|\\gamma^\\prime(t)|\\,\\mathrm dt$$\r\n    Also this curve is called simple iff $\\gamma(t_1)=\\gamma(t_2)\\iff t_1\\equiv t_2\\pmod{b-a}$\r\n\\end{definition}\r\n\\begin{definition}\r\n    Let $\\gamma:[a,b]\\to\\mathbb C$ be a $C^1$ curve and $f:U\\to\\mathbb C$ be continuous, then we define the integral of $f$ over $\\gamma$ by\r\n    $$\\int_\\gamma f(t)\\,\\mathrm dt=\\int_a^b(f\\circ\\gamma)(t)\\gamma^\\prime(t)\\,\\mathrm dt$$\r\n\\end{definition}\r\nOne can check that\r\n\\begin{proposition}\r\n    1.\r\n    $$\\left(\\int_{\\gamma}f\\right)+\\alpha\\left(\\int_\\gamma g\\right)=\\int_\\gamma(f+\\alpha g)$$\r\n    2. \r\n    $$\\int_{\\gamma\\pm\\delta}=\\int_\\gamma\\pm\\int_\\delta$$\r\n    3. Let $\\gamma,\\delta$ be two parameterizations of the same curve linked by an injective $C^1$ function, then\r\n    $$\\int_\\gamma=\\int_\\delta$$\r\n\\end{proposition}\r\nWhere the addition and substraction of paths are defined the way a sensible person would expect.\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{definition}\r\n    For continuous piecewise $C^1$ curves $\\gamma=\\gamma_1+\\gamma_2+\\cdots+\\gamma_n$, we set\r\n    $$\\int_\\gamma=\\sum_{k=1}^n\\int_{\\gamma_k}$$\r\n\\end{definition}\r\nNote that by additivity of the integral over paths, this is well-defined.\r\n\\begin{proposition}\r\n    For any continuous function $f:U\\to\\mathbb c$ and any (piecewise $C^1$) curve $\\gamma:[a,b]\\to U$, we have\r\n    $$\\left|\\int_\\gamma f(z)\\,\\mathrm dz\\right|\\le\\sup_{t\\in[a,b]}|f(\\gamma(t))|\\int_a^b|\\gamma^\\prime(t)|\\,\\mathrm dt$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Suffices to show the case when $\\gamma$ is $C^1$, then\r\n    \\begin{align*}\r\n        \\left|\\int_\\gamma f(z)\\,\\mathrm dz\\right|&=\\left|\\int_a^bf(\\gamma(t))\\gamma^\\prime(t)\\,\\mathrm dt\\right|\\\\\r\n        &\\le\\int_a^b|f(\\gamma(t))||\\gamma^\\prime(t)|\\,\\mathrm dt\\\\\r\n        &\\le\\sup_{t\\in[a,b]}|f(\\gamma(t))|\\int_a^b|\\gamma^\\prime(t)|\\,\\mathrm dt\r\n    \\end{align*}\r\n    As desired.\r\n\\end{proof}\r\n\\subsection{Cauchy's Theorem}\r\n\\begin{theorem}[Fundamental Theorem of Calculus for Complex Integrals]\r\n    For a continuous function $f:U\\to\\mathbb C$, if there is a holomorphic $F:U\\to\\mathbb C$ such that $F^\\prime=f$, then for any (piecewise $C^1$) curve $\\gamma:[a,b]\\to\\mathbb C$ we have\r\n    $$\\int_\\gamma f(z)\\,\\mathrm dz=F(\\gamma(b))-F(\\gamma(a))$$\r\n\\end{theorem}\r\nIn particular we have\r\n$$\\oint_\\gamma f(z)\\,\\mathrm dz=0$$\r\nFor closed $\\gamma$.\r\n\\begin{proof}\r\n    Again suffices to consider $\\gamma$ as $C^1$, then we have\r\n    $$\\int_\\gamma f(z)\\,\\mathrm dz=\\int_a^bF^\\prime(\\gamma(t))\\gamma^\\prime(t)\\,\\mathrm dt=\\int_a^b(F\\circ\\gamma)^\\prime(t)\\,\\mathrm dt=F(\\gamma(b))-F(\\gamma(a))$$\r\n    Done.\r\n\\end{proof}\r\n\\begin{example}\r\n    For $\\gamma:[0,\\pi]\\to\\mathbb C$ by $t\\mapsto Re^{2it}$, we have for $n\\neq -1$\r\n    $$\\oint_\\gamma z^n\\,\\mathrm dz=0$$\r\n    Indeed it is the derivative of the holomorphic function $z^{n+1}/(n+1)$.\\\\\r\n    But for $n=-1$,\r\n    $$\\oint_\\gamma z^{-1}\\,\\mathrm dz=2\\pi R$$\r\n    which is nonzero, hence it does not have an antiderivative defined on any open set containing $\\gamma$, so logarithm has no branch on $\\mathbb C^\\star$.\r\n\\end{example}\r\nWhat is interesting is the converse of the theorem.\r\n\\begin{theorem}\r\n    Let $U$ be a path-connected open set, and $f:U\\to\\mathbb C$ be continuous.\r\n    If for any (piecewise $C^1$) closed curve $\\gamma:[a,b]\\to U$ we have\r\n    $$\\oint_\\gamma f(z)\\,\\mathrm dz$$\r\n    then $f$ has an antiderivative on $U$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Fix $\\alpha\\in U$.\r\n    Consider the function $F:U\\to\\mathbb C$ with\r\n    $$F(z)=\\int_\\gamma f(z)\\,\\mathrm dz$$\r\n    where $\\gamma$ is a piecewise $C^1$ curve on $U$ connecting $\\alpha$ and $z$.\r\n    To see the existence of $\\gamma$, we know by path-connectedness of $U$ that there is a continuous curve from $\\alpha$ to $z$, then we can construct a piecewise $C^1$ one by a compactness argument.\\\\\r\n    Then such an $F$ is well defined by our condition.\r\n    One can simply check to see that $F$ is holomorphic and $F^\\prime=f$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A domain $U$ is star-shaped if $\\exists s\\in U$ such that any other $x\\in U$, there is a straight line joining $x$ and $s$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A triangle $T$ is the convex hull of three non-colinear points on the complex plane, so\r\n    $$T(z_1,z_2,z_3)=\\{az_1+bz_2+cz_3:a,b,c\\in [0,1],a+b+c=1\\}$$\r\n    We denote by $\\partial T$ the boundary of $T$, which is the union of three line segments, and we choose it to be with anticlockwise direction. \r\n\\end{definition}\r\n\\begin{corollary}\r\n    In any star-shaped domain, if for any triangle $T$ in the domain we have\r\n    $$\\oint_{\\partial T}f(z)\\,\\mathrm dz=0$$\r\n    then $f$ admits a holomorphic antiderivative.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Basically the same proof but take $\\alpha=s$ and take the path to be a straight line.\r\n\\end{proof}\r\n\\begin{theorem}[Cauchy's Theorem]\r\n    For a holomorphic $f$ and closed $\\gamma$,\r\n    $$\\oint_\\gamma f(z)\\,\\mathrm dz=0$$\r\n\\end{theorem}\r\n\\begin{theorem}[Cauchy's Theorem for Triangles]\r\n    Let $U\\subset C$ be open and $f:U\\to\\mathbb C$ holomorphic.\r\n    If $T$ is a triangle in $U$, then\r\n    $$\\oint_{\\partial T}f(z)\\,\\mathrm dz=0$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    We subdivide the triangles by joining the midpoints, so we disassembles $T$ into $4$ smaller triangles.\r\n    Call them $T^1,T^2,T^3,T^4$, and the directions of their boundaries are consistently given (anticlockwise), so we have\r\n    $$\\oint_{\\partial T}f(z)\\,\\mathrm dz=\\sum_{k=1}^4\\oint_{\\partial T^k}f(z)\\,\\mathrm dz$$\r\n    We set\r\n    $$\\eta(T)=\\oint_{\\partial T}f(z)\\,\\mathrm dz$$\r\n    So $\\eta(T)=\\sum_{k}\\eta(T^k)$, hence there is some $k$ such that $|\\eta(T^k)|\\ge|\\eta(T)|/4$, and $\\operatorname{length}(\\partial T^k)=\\operatorname{length}(\\partial T)/2$, so we repeat this process to get a nested sequence of triangles $T=T_0\\supset T_1\\supset T_2\\supset\\cdots$ such that $|\\eta(T_k)|/4\\le|\\eta(T_{k+1})|$ and $\\operatorname{length}(\\partial T_{k+1})=\\operatorname{length}(\\partial T_k)/2$.\r\n    But each $T_k$ is closed and the diameter goes to $0$, hence $\\bigcap_kT_k=\\{z_0\\}$ for some $z_0\\in\\mathbb C$.\r\n    For any $\\epsilon>0$, there is some $\\delta>0$ such that $|z-z_0|<\\delta\\implies |f(z)-f(z_0)-f^\\prime(z_0)(z-z_0)|<\\epsilon|z-z_0|$\r\n    For $n$ large enough, we have $T_n\\subset D_\\delta(z_0)$.\r\n    \\begin{align*}\r\n        |\\eta(T_n)|&=\\left|\\oint_{\\partial T_n}f(z)-(f(z_0)+f^\\prime(z_0)(z-z_0))\\,\\mathrm dz\\right|\\\\\r\n        &\\le\\sup_{z\\in \\delta T_n}|f(z)-(f(z)+f^\\prime(z_0)(z-z_0)|\\operatorname{length}(\\partial T_n)\\\\\r\n        &\\le\\epsilon\\sup_{z\\in\\partial T_n}|z-z_0|\\operatorname{length}(\\partial T_n)\\\\\r\n        &\\le\\epsilon(\\operatorname{length}(\\partial T_n))^2\r\n    \\end{align*}\r\n    So\r\n    $$\\frac{\\eta(T)}{4^n}\\le\\epsilon(\\operatorname{length}(\\partial T^n))^2=\\frac{\\epsilon(\\operatorname{length}(\\partial T))^2}{4^n}\\implies\\forall\\epsilon>0,\\eta(T)\\le \\epsilon(\\operatorname{length}(\\partial T))^2$$\r\n    Hence we must have $\\eta(T)=0$.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    Let $f:U\\to\\mathbb C$ be continuous.\r\n    If $S\\subset U$ is a finite set and if $f$ is holomorphic in $U\\setminus S$, then\r\n    $$\\oint_{\\partial T}f(z)\\,\\mathrm dz=0$$\r\n    for any triangle $T\\subset U$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Subdivide $T$ into $N=4^n$ parts as before to $T_1,T_2,\\ldots,T_N$, then $|I|\\le 6|S|$ where $I=\\{j:T_j\\cap S\\neq\\varnothing\\}$.\r\n    Hence we have, by Cauchy's Theorem on triangles,\r\n    \\begin{align*}\r\n        \\left|\\oint_{\\partial T}f(z)\\,\\mathrm dz\\right|&=\\left|\\sum_{j\\in I}\\oint_{\\partial T_j}f(z)\\,\\mathrm dz\\right|\\\\\r\n        &\\le\\sum_{j\\in I}\\sup_{z\\in\\partial T_j}|f(z)|\\operatorname{length}(\\partial T_j)\\\\\r\n        &\\le 6|S|\\sup_{z\\in\\partial T}|f(z)|\\operatorname{length}(\\partial T)\\frac{1}{2^n}\r\n    \\end{align*}\r\n    Letting $n\\to\\infty$ finishes the proof.\r\n\\end{proof}\r\n\\begin{corollary}[Cauchy's Theorem on Star-Shaped Domains]\r\n    Let $U\\subset C$ be a star-shaped domain and $f:U\\to\\mathbb C$ be continuous, and holomorphic on $U\\setminus S$ where $S$ is a finite set.\r\n    Then\r\n    $$\\oint_\\gamma f(z)\\,\\mathrm dz=0$$\r\n    for any closed curve on $U$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Follows directly.\r\n\\end{proof}\r\n\\subsection{Cauchy Integral Formula and Consequences}\r\n\\begin{theorem}[Cauchy's Integral Formula for a disk]\r\n    Let $D=D_r(a)$, and let $f:D\\to\\mathbb C$ be holomorphic, then for any $0<\\rho<r$ and any $w\\in D_\\rho(a)$, we have\r\n    $$f(w)=\\frac{1}{2\\pi i}\\oint_{\\partial D_\\rho(a)}\\frac{f(z)}{z-w}\\,\\mathrm dz$$\r\n    where $\\partial D_\\rho(a)$ denotes the curve $[0,1]\\ni t\\mapsto a+\\rho e^{2\\pi it}$\r\n\\end{theorem}\r\nIn particular,\r\n$$f(a)=\\int_0^1 f(a+\\rho e^{2\\pi it})\\,\\mathrm dt$$\r\nThis is known as the mean-value property.\r\n\\begin{proof}\r\n    We have\r\n    $$\\oint_{\\partial D_\\rho(a)}\\frac{f(z)-f(w)}{z-w}\\,\\mathrm dz=0$$\r\n    by the preceding theorem.\r\n    So we have\r\n    \\begin{align*}\r\n        \\oint_{\\partial D_\\rho(a)}\\frac{f(z)}{z-w}\\,\\mathrm dz&=f(w)\\oint_{\\partial D_\\rho(a)}\\frac{1}{z-w}\\,\\mathrm dz\\\\\r\n        &=f(w)\\oint_{\\partial D_\\rho(a)}\\frac{1}{z-a}\\,\\mathrm dz+f(w)\\oint_{\\partial D_\\rho(a)}\\sum_{n=1}^\\infty\\frac{(w-a)^n}{(z-a)^{n+1}}\\,\\mathrm dz\\\\\r\n        &=f(w)2\\pi i+f(w)\\sum_{n=1}^\\infty(w-a)^n\\oint_{\\partial D_\\rho(a)}\\frac{1}{(z-a)^{n+1}}\\,\\mathrm dz\\\\\r\n        &=f(w)2\\pi i\r\n    \\end{align*}\r\n    Note that we can change the order of integration and summation since the series (as a geometric series) converges uniformly (which is easy enough to prove).\r\n\\end{proof}\r\nSo we can prove that a bounded entire function is constant.\r\n\\begin{proof}[Proof of Theorem \\ref{holo_bdd_const}]\r\n    Let $f$ be a bounded entire function.\r\n    It suffice to assume that $f$ has sublinear growth since it is bounded.\r\n    So $|f(z)|\\le C(1+|z|^\\alpha)$ for some $C\\ge 0$ and $\\alpha\\in (0,1)$.\r\n    Let $w\\in\\mathbb C$, by Cauchy integral formula, for any $\\rho>|w|$ we have\r\n    $$f(w)=\\frac{1}{2\\pi i}\\oint_{D_\\rho(0)}\\frac{f(z)}{z-w}\\,\\mathrm dz$$\r\n    Also\r\n    $$f(0)=\\frac{1}{2\\pi i}\\oint_{D_\\rho(0)}\\frac{f(z)}{z}\\,\\mathrm dz$$\r\n    Hence\r\n    \\begin{align*}\r\n        |f(w)-f(0)|&=\\left|\\frac{1}{2\\pi i}\\oint_{D_\\rho(0)}f(z)\\left(\\frac{1}{z-w}-\\frac{1}{z}\\right)\\,\\mathrm dz\\right|\\\\\r\n        &=\\frac{|w|}{2\\pi}\\left|\\oint_{D_\\rho(0)}\\frac{f(z)}{z(z-w)}\\,\\mathrm dz\\right|\\\\\r\n        &\\le|w|\\rho\\sup_{z\\in D_\\rho(0)}\\frac{|f(z)|}{|z||z-w|}\\\\\r\n        &=\\sup_{z\\in D_\\rho(0)}\\frac{|w||f(z)|}{|z-w|}\\\\\r\n        &\\le\\sup_{z\\in D_\\rho(0)}\\frac{|w|C(1+\\rho^\\alpha)}{|z-w|}\\to 0\r\n    \\end{align*}\r\n    As $\\rho\\to\\infty$.\r\n    Hence $f(w)=f(0)$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Every nonconstant polynomial with complex coefficient has a root in $\\mathbb C$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Assume there is a complex polynomial $p(z)=a_nz^n+\\cdots+a_0$ with $n\\ge1,a_n\\neq 0$ which has no root, then $p$ is never $0$, hence $1/p$ is entire.\r\n    So it suffices to show that $p$ is bounded.\r\n    Note that for $z\\neq 0$ we have $|p(z)|=|z^n||a_n+a_{n-1}z^{-1}+\\cdots+a_0z^{-n}|\\to\\infty$ as $|z|\\to\\infty$.\r\n    Hence we can choose $R>0$ such that $p(z)\\ge 1$ for any $|z|>R$, so $p$ is bounded outside the disk $B_R(0)$, but it is also bounded inside it since $B_R(0)$ is compact.\r\n    So by Theorem \\ref{holo_bdd_const}, $p$ must be a constant, contradiction.\r\n\\end{proof}\r\n\\begin{theorem}[Local Maximum Modulus Principle]\r\n    Let $f:D_r(a)\\to\\mathbb C$ be holomorphic.\r\n    If $|f(z)|\\le|f(a)|$ for any $z\\in D_r(a)$, then $f$ is constant.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    We shall use the mean-value property.\r\n    $$f(a)=\\int_0^1 f(a+\\rho e^{2\\pi it})\\,\\mathrm dt$$\r\n    for any $0<\\rho<r$.\r\n    So\r\n    $$|f(a)|=\\left|\\int_0^1 f(a+\\rho e^{2\\pi it})\\,\\mathrm dt\\right|\\le\\sup_{t\\in [0,1]}|f(a+\\rho e^{2\\pi it})|\\le|f(a)|$$\r\n    So automatically all inequality must be equality, therefore $|f(a+\\rho e^{2\\pi it})|$ must be constant.\r\n    But this works for all $\\rho\\in (0,r)$, so $|f|$ is constant, which implies $f$ being constant by Cauchy-Riemann equation.\r\n\\end{proof}\r\n\\begin{theorem}[Taylor Series]\r\n    Let $f:D_r(a)\\to\\mathbb C$ be holomorphic.\r\n    Then $f$ has a convergent power series representation on $D_a(r)$ in the form\r\n    $$f(w)=\\sum_{n=0}^\\infty c_n(w-a)^n,c_n=\\frac{1}{2\\pi i}\\oint_{\\partial D_\\rho(a)}\\frac{f(z)}{(z-a)^{n+1}}\\,\\mathrm dz$$\r\n    for $|w|<\\rho<r$.\r\n\\end{theorem}\r\nOnce we have established this, we immediately know that $f$ is infinitely differentiable on $D_a(r)$, therefore $c_n=f^{(n)}(a)/n!$.\r\n\\begin{proof}\r\n    For any $w\\in D_r(a)$ and any $\\rho$ with $|w-a|<\\rho<r$ we have\r\n    \\begin{align*}\r\n        f(w)&=\\frac{1}{2\\pi i}\\oint_{\\partial D_\\rho(a)}\\frac{f(z)}{z-w}\\,\\mathrm dz\\\\\r\n        &=\\frac{f(z)}{2\\pi i}\\oint_{\\partial D_\\rho(a)}\\sum_{n=0}^\\infty\\frac{(w-a)^n}{(z-a)^{n+1}}\\,\\mathrm dz\\\\\r\n        &=\\sum_{n=0}^\\infty(w-a)^n\\frac{1}{2\\pi i}\\oint_{\\partial D_\\rho(a)}\\frac{f(z)}{(z-a)^{n+1}}\\,\\mathrm dz\r\n    \\end{align*}\r\n    We can change the order of integration since a geometrical series is uniform.\r\n    This gives us the desired series.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $f:U\\to\\mathbb C$ is holomorphic where $U$ is open, then $f$ has derivative of all orders and they are all holomorphic.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Follows directly.\r\n\\end{proof}\r\nA function, real or complex, is said to be analytic on an open set if it has a convergent power series representation there.\r\nSo for a complex function, being analytic is equivalent to being holomorphic.\r\nBut for real functions, even infinite differentiability does not imply a function is analytic, for example\r\n$$f(x)=\\begin{cases}\r\n    e^{-1/x^2}\\text{, for $x\\neq 0$.}\\\\\r\n    0\\text{, for $x=0$.}\r\n\\end{cases}$$\r\nFrom now on, we can use analytic and holomorphic interchangably.\r\nWe can also say now that if we decompose $f=u+iv$, then $u,v$ are automatically smooth given $f$ holomorphic.\r\n\\begin{theorem}[Morera's Theorem]\r\n    Let a complex function $f:U\\to\\mathbb C$ be continuous.\r\n    Suppose that its integral is $0$ along any closed curve, then $f$ is holomorphic.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    The antiderivative exists and is holomorphic, so its derivative $f$ is holomorphic.\r\n\\end{proof}\r\n\\begin{theorem}[Cauchy's Integral Formula for Derivatives]\r\n    For a holomorphic function $f:D=D_r(a)\\to\\mathbb C$ and for any $w\\in D$ and $|w|<\\rho<r$, we have\r\n    $$f^\\prime(w)=\\frac{1}{2\\pi i}\\oint_{\\partial D_\\rho(a)}\\frac{f(z)}{(z-w)^2}\\,\\mathrm dz$$\r\n    More generally,\r\n    $$f^{(n)}(w)=\\frac{n!}{2\\pi i}\\oint_{\\partial D_\\rho(a)}\\frac{f(z)}{(z-w)^{n+1}}\\,\\mathrm dz$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Consider the function $g(z)=f(z)/(z-w)$ and its derivative gives the $n=1$ case.\r\n    The general case follows from induction.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $U\\subset\\mathbb C$ be an open set and let $(f_n)$ be a sequence of complex functions.\r\n    We say it converges locally uniformly if for any $a\\in U$, there is some $r>0$ such that $(f_n)$ converges uniformly on $D_r(a)\\subset U$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    $(f_n)$ converges locally uniformly on $U$ iff it converges uniformly on any compact subset of $U$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Easy.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    Let $f_n:U\\to\\mathbb C$ be a sequence of holomorphic functions that converges to $f$ locally uniformly on $U$, then $f$ is holomorphic.\r\n    Moreover, $f_n^\\prime\\to f^\\prime$ locally uniformly on $U$.\r\n\\end{theorem}\r\n\\begin{remark}\r\n    This is totally not true in the real case since we can approximate any continuous function on a closed interval locally uniformly by polynomials (Weierstrass Approximation Theorem).\r\n\\end{remark}\r\n\\begin{proof}\r\n    $f$ is continuous since continuity is a local property and we already know that the uniform limit of continuous functions is continuous.\r\n    Pick any point $a\\in U,r>0$ with $B_r(a)\\subset U$ and $f_n\\to f$ uniformly on $B_r(a)$, the by Cauchy's Theorem on star-shaped domains, we have\r\n    $$\\oint_\\gamma f_n(z)\\,\\mathrm dz=0$$\r\n    for any closed $\\gamma$ on the disk.\r\n    Then by uniformity\r\n    $$\\oint_\\gamma f(z)\\,\\mathrm dz=\\oint_\\gamma\\lim_{n\\to\\infty}f_n(z)\\,\\mathrm dz=\\lim_{n\\to\\infty}\\oint_\\gamma f_n(z)\\,\\mathrm dz$$\r\n    So $f$ is holomorphic on the disk.\r\n    The derivative case follows from Cauchy Integral Formula for derivatives.\r\n\\end{proof}\r\n\\begin{theorem}[Principle of Isolated Zero]\r\n    Let $f:D_R(w)\\to\\mathbb C$ be holomorphic and not identically zero, then the zeros of $f$ are isolated, that is, there exists $0<r\\le R$ such that $f(z)\\neq 0$ for any $0<|z-w|<r$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{remark}\r\n    The zeros of a holomorphic function can have a limit point on the boundary of the domain.\r\n    For example, $f(z)=\\sin(1/z)$ on $\\mathbb C^\\star$.\r\n\\end{remark}\r\n\\subsection{Analytic Continuation}\r\nBy Taylor Series, we know that a holomorphic function $f$ on a disk $D_R(a)$ is completely determined by the values of the derivatives of $f$ at $a$.\r\nDoes this generalize to arbitrary domains?\r\n\\begin{theorem}\r\n    Let $D'\\subset D$ be domains and $f:D'\\to\\mathbb C$ be analytic.\r\n    Then there is at most one analytic function $g:D\\to\\mathbb C$ such that $g|_{D'}=f$.\r\n\\end{theorem}\r\nSuch a function $g$ is called an analytic continuation of $f$ to $D$.\r\n\\begin{proof}\r\n    Suppose there are two of the functions $g_1,g_2$ satisfying this condition, then $g_1|_{D'}=g_2|_{D'}=f$ and $h=g_1-g_2$.\r\n    Let $D_0=\\{z\\in D:\\exists r>0, h|_{D_r(z)}\\equiv 0\\}$.\r\n    Then $D_0$ is open.\r\n    We shall show that it is also closed, which shall finish our proof.\r\n    But $D_1=\\{z\\in D:\\exists n\\in\\mathbb N, h^{(n)}(z)\\neq 0\\}=D\\setminus D_0$ is also open in $D$, so one of them is empty by connectedness.\r\n    But $D'\\subset D_1$ hence $D_1$ is empty, therefore $h\\equiv 0\\implies g_1=g_2$.\r\n\\end{proof}\r\nActually this is a direct consequence of the Principle of Isolated Zeros, but one want to show that this depends entirely on the existence of Taylor series.\r\n\\begin{remark}\r\n    1. The proof depends on the result that the functions have convergent Taylor series at every point, so it is valid for real valued analytic functions.\\\\\r\n    2. Analytic continuations to larger domains need not always exist.\r\n    For example, the function\r\n    $$f(z)=\\sum_{n=0}^\\infty z^{n!}$$\r\n    is analytic on $D_1(0)$, but we will prove in example sheet that this cannot be extend to larger domains.\r\n    $\\partial D_1(0)$ is called the natural boundary of $f$.\r\n\\end{remark}\r\n\\begin{corollary}[Identity Principle]\r\n    Let $U\\subset \\mathbb C$ be a domain and let $f,g:U\\to\\mathbb C$ be holomorphic and the set $\\{z\\in U:f(z)=g(z)\\}$ has a non-isolated point, then $f\\equiv g$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\n\\begin{corollary}[Global Maximum Principle]\r\n    Let $U\\subset\\mathbb C$ be a bounded domain and let $f:\\bar{U}\\to\\mathbb C$ be continuous and holomorphic in $U$, then $\\sup|f|$ is attained on the boundary $\\partial U=\\bar U\\setminus U^\\circ$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Follows from the Local Maximum Principle and Identity Principle.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Some of the theorems can generalize even further to help us to solve elliptic PDEs as a generlization to Laplace's Equation.\r\n    For example, we also have an analogue of analytic continuation and we can show that harmonic functions in any dimensions are infinitely differentiable.\r\n    Also some analogue of the Local Maximum Modulus Principle also hold.\r\n    So does the mean value property (but this time only for harmonic functions instead of general functions satisfying elliptic PDEs).\r\n    In fact, if the mean value property hold, the function has to be harmonic.\r\n\\end{remark}", "meta": {"hexsha": "954608e030db09827af9931b5fcad5835506856f", "size": 21072, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/int.tex", "max_stars_repo_name": "david-bai-notes/IB-Complex-Analysis", "max_stars_repo_head_hexsha": "d67e2ff022d5fbc22bfdfd377f2414c23be532ed", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2/int.tex", "max_issues_repo_name": "david-bai-notes/IB-Complex-Analysis", "max_issues_repo_head_hexsha": "d67e2ff022d5fbc22bfdfd377f2414c23be532ed", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2/int.tex", "max_forks_repo_name": "david-bai-notes/IB-Complex-Analysis", "max_forks_repo_head_hexsha": "d67e2ff022d5fbc22bfdfd377f2414c23be532ed", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.5737704918, "max_line_length": 414, "alphanum_fraction": 0.6518602885, "num_tokens": 7120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.8887587964389112, "lm_q1q2_score": 0.7481799561164965}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{graphicx}\n\\usepackage[margin=1in,nohead,nofoot]{geometry}\n\\usepackage{wrapfig}\n\\usepackage{xcolor}\n\\usepackage{enumitem}\n\\setlist[itemize]{noitemsep}\n\\usepackage{hyperref}\n\\hypersetup{linkbordercolor=blue}\n\\usepackage{sidecap}\n\\usepackage{cite}\n\\usepackage{setspace}\n\\usepackage[backgroundcolor = blue!0,bordercolor = red]{todonotes}\n\\usepackage{xcolor}\n\\usepackage{amsmath}\n\n\n\\usepackage{fancyhdr}\n\\setlength{\\headheight}{60pt}\n\\setlength{\\topmargin}{-50pt}\n\\setlength{\\headsep}{10pt}\n\\pagestyle{fancy}\n\\rhead{\\textit{Robot to Camera Calibration}}\n\\lhead{} \n\\chead{} \n\\lfoot{March 3, 2016} \n\\cfoot{\\thepage} \n\\rfoot{Georgia Tech - Michael Sobrepera} \n\\renewcommand{\\headrulewidth}{0.1pt} \n\\renewcommand{\\footrulewidth}{0.1pt}\n\n\\usepackage[font=footnotesize,labelfont=bf]{caption}\n\\usepackage{subcaption}\n\n\n\n\\setlength{\\footskip}{20pt}\n\n%Eat whitespace\n\\singlespacing\n\\usepackage[subtle]{savetrees} \n\n\\begin{document}\n\t\n\t\\section{Motivation}\n\tWhen using a robot and a fixed camera together it is often necessary to calibrate the camera's coordinate frame to that of the robot base. This allows what is seen in the camera to be turned into meaningful commands for the robot. \n\t\n\tIn order to do this, I propose to use a single grid, arbitrarily mounted to the robot, past its final degree of freedom. By moving the grid to a number of different positions and capturing those positions kinematically from the robot and visually from the camera. This will generate a series of equations which can then be solved to determine the transformation from the camera to the robot. \n\t\n\t\\section{Setup}\n\tIn order to perform this procedure, the robot and camera should be fixed, with the camera viewing the robot. A checkerboard grid should be attached to the robot past the final joint, it is easiest to attach the grid to the tool flange. The grid should be asymmetrical and should have a white border. \n\t\n\t\\section{Math}\n\tThe center of this problem is finding a transformation given a set of parallel transformations and many sample points. This can be seen in \\autoref{fig:transformations}\n\t\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\def\\svgwidth{\\textwidth}\n\t\t\\input{transformatin_diagram.pdf_tex}\n\t\t\\caption{\\textbf{Transformations}. The transformation $C$ can be measured by tracking the grid, so long as the camera intrinsics are well calibrated. The transformation $G$ is unknown, however, it does not change as the grid is rigidly attached to the tool center point (TCP). The transformation $T$ can be gathered directly from the robots forward kinematics. The goal is to solve for the transformation $R$, which is unknown, but constant.}\n\t\t\\label{fig:transformations}\n\t\\end{figure}\n\t\n\tGiven \\autoref{fig:transformations} we can develop some math using dual quaternions to solve for $R$ given a number of matches pairs samples of $T$ and $C$. \n\t\n\tFirst we re-define $T$ a more useful version of $T$\n\t\\begin{equation}\n\tT = T^*\n\t\\end{equation}\n\t\n\tWe then define the transformation from the camera to the TCP using dual quaternions where given dual quaternion $q$ the dual quaternion can be decomposed into quaternions $q_r +  q_d$ which can be further decomposed to individual elements $q_{r_w} + q_{r_x} i + q_{r_y} j + q_{r_z} k + (q_{d_w} + q_{d_x} i + q_{d_y} j + q_{d_z} k)\\epsilon$.\n\t\n\tWe can now describe, in steps, the transformation from the camera to the UR Base. We begin by defining the transformation from the Camera to the Grid:\n\t\\begin{equation}\n\t\tC_r G_r+(C_r G_d + C_d G_r)\\epsilon\n\t\\end{equation}\n\tWe then extend this from the camera to the UR Base, which is equivalent to $R$:\n\t\\begin{equation}\n\t\tR = C_r G_r T_r + (C_r G_r T_d + (C_r G_d + C_d G_r)T_r)\\epsilon\n\t\\end{equation}\n\tWe then proceed to expand this into individual units and standard math:\n\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\tR_{r_w} = \\\\&\n\t\t\t(C_{r_w} G_{r_w}-C_{r_x} G_{r_x}-C_{r_y} G_{r_y}-C_{r_z} G_{r_z}) T_{r_w}+\\\\&(C_{r_x} G_{r_w}+C_{r_w} G_{r_x}-C_{r_z} G_{r_y}+C_{r_y} G_{r_z}) T_{r_x}+\\\\&(C_{r_y} G_{r_w}+C_{r_z} G_{r_x}+C_{r_w} G_{r_y}-C_{r_x} G_{r_z}) T_{r_y}+\\\\&(C_{r_z} G_{r_w}-C_{r_y} G_{r_x}+C_{r_x} G_{r_y}+C_{r_w} G_{r_z}) T_{r_z}\n\t\t\\end{split}\n\t\t\\label{eq:rrw}\n\t\\end{equation}\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\tR_{r_x} = \\\\&\n\t\t\t(C_{r_x} G_{r_w}+C_{r_w} G_{r_x}-C_{r_z} G_{r_y}+C_{r_y} G_{r_z}) T_{r_w}-\\\\&(C_{r_w} G_{r_w}-C_{r_x} G_{r_x}-C_{r_y} G_{r_y}-C_{r_z} G_{r_z}) T_{r_x}+\\\\&(C_{r_z} G_{r_w}-C_{r_y} G_{r_x}+C_{r_x} G_{r_y}+C_{r_w} G_{r_z}) T_{r_y}-\\\\&(C_{r_y} G_{r_w}+C_{r_z} G_{r_x}+C_{r_w} G_{r_y}-C_{r_x} G_{r_z}) T_{r_z}\n\t\t\\end{split}\n\t\t\\label{eq:rrx}\n\t\\end{equation}\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\tR_{r_y} = \\\\&\n\t\t\t(C_{r_y} G_{r_w}+C_{r_z} G_{r_x}+C_{r_w} G_{r_y}-C_{r_x} G_{r_z}) T_{r_w}-\\\\&(C_{r_z} G_{r_w}-C_{r_y} G_{r_x}+C_{r_x} G_{r_y}+C_{r_w} G_{r_z}) T_{r_x}-\\\\&(C_{r_w} G_{r_w}-C_{r_x} G_{r_x}-C_{r_y} G_{r_y}-C_{r_z} G_{r_z}) T_{r_y}+\\\\&(C_{r_x} G_{r_w}+C_{r_w} G_{r_x}-C_{r_z} G_{r_y}+C_{r_y} G_{r_z}) T_{r_z}\n\t\t\\end{split}\n\t\t\\label{eq:rry}\n\t\\end{equation}\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\tR_{r_z} = \\\\&\n\t\t\t(C_{r_z} G_{r_w}-C_{r_y} G_{r_x}+C_{r_x} G_{r_y}+C_{r_w} G_{r_z}) T_{r_w}+\\\\&(C_{r_y} G_{r_w}+C_{r_z} G_{r_x}+C_{r_w} G_{r_y}-C_{r_x} G_{r_z}) T_{r_x}-\\\\&(C_{r_x} G_{r_w}+C_{r_w} G_{r_x}-C_{r_z} G_{r_y}+C_{r_y} G_{r_z}) T_{r_y}-\\\\&(C_{r_w} G_{r_w}-C_{r_x} G_{r_x}-C_{r_y} G_{r_y}-C_{r_z} G_{r_z}) T_{r_z}\n\t\t\\end{split}\n\t\t\\label{eq:rrz}\n\t\\end{equation}\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\tR_{d_w} = \\\\&\n\t\t\t(C_{r_w} G_{r_w} - C_{r_x} G_{r_x} - C_{r_y} G_{r_y} - \n\t\t\tC_{r_z} G_{r_z}) T_{d_w} +\\\\& (C_{r_x} G_{r_w} + \n\t\t\tC_{r_w} G_{r_x} - C_{r_z} G_{r_y} + \n\t\t\tC_{r_y} G_{r_z}) T_{d_x} + \\\\&(C_{r_y} G_{r_w} + \n\t\t\tC_{r_z} G_{r_x} + C_{r_w} G_{r_y} - \n\t\t\tC_{r_x} G_{r_z}) T_{d_y} +\\\\& (C_{r_z} G_{r_w} - \n\t\t\tC_{r_y} G_{r_x} + C_{r_x} G_{r_y} + \n\t\t\tC_{r_w} G_{r_z}) T_{d_z} +\\\\& (C_{r_w} G_{d_w} - \n\t\t\tC_{r_x} G_{d_x} - C_{r_y} G_{d_y} - C_{r_z} G_{d_z} + \n\t\t\tC_{d_w} G_{r_w} - C_{d_x} G_{r_x} - C_{d_y} G_{r_y} - \n\t\t\tC_{d_z} G_{r_z}) T_{r_w} -\\\\& (C_{r_x} G_{d_w} + \n\t\t\tC_{r_w} G_{d_x} - C_{r_z} G_{d_y} + C_{r_y} G_{d_z} + \n\t\t\tC_{d_x} G_{r_w} + C_{d_w} G_{r_x} - C_{d_z} G_{r_y} + \n\t\t\tC_{d_y} G_{r_z}) T_{r_x} -\\\\& (C_{r_y} G_{d_w} + \n\t\t\tC_{r_z} G_{d_x} + C_{r_w} G_{d_y} - C_{r_x} G_{d_z} + \n\t\t\tC_{d_y} G_{r_w} + C_{d_z} G_{r_x} + C_{d_w} G_{r_y} - \n\t\t\tC_{d_x} G_{r_z}) T_{r_y} - \\\\&(C_{r_z} G_{d_w} - \n\t\t\tC_{r_y} G_{d_x} + C_{r_x} G_{d_y} + C_{r_w} G_{d_z} + \n\t\t\tC_{d_z} G_{r_w} - C_{d_y} G_{r_x} + C_{d_x} G_{r_y} + \n\t\t\tC_{d_w} G_{r_z}) T_{r_z}\n\t\t\\end{split}\n\t\t\\label{eq:rdw}\n\t\\end{equation}\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\tR_{d_x} = \\\\&\n\t\t\t(C_{r_x} G_{r_w} + \n\t\t\tC_{r_w} G_{r_x} - C_{r_z} G_{r_y} + \n\t\t\tC_{r_y} G_{r_z}) T_{d_w} -\\\\& (C_{r_w} G_{r_w} - \n\t\t\tC_{r_x} G_{r_x} - C_{r_y} G_{r_y} - \n\t\t\tC_{r_z} G_{r_z}) T_{d_x} +\\\\& (C_{r_z} G_{r_w} - \n\t\t\tC_{r_y} G_{r_x} + C_{r_x} G_{r_y} + \n\t\t\tC_{r_w} G_{r_z}) T_{d_y} - \\\\&(C_{r_y} G_{r_w} + \n\t\t\tC_{r_z} G_{r_x} + C_{r_w} G_{r_y} - \n\t\t\tC_{r_x} G_{r_z}) T_{d_z} +\\\\& (C_{r_x} G_{d_w} + \n\t\t\tC_{r_w} G_{d_x} - C_{r_z} G_{d_y} + C_{r_y} G_{d_z} + \n\t\t\tC_{d_x} G_{r_w} + C_{d_w} G_{r_x} - C_{d_z} G_{r_y} + \n\t\t\tC_{d_y} G_{r_z}) T_{r_w} + \\\\&(C_{r_w} G_{d_w} - \n\t\t\tC_{r_x} G_{d_x} - C_{r_y} G_{d_y} - C_{r_z} G_{d_z} + \n\t\t\tC_{d_w} G_{r_w} - C_{d_x} G_{r_x} - C_{d_y} G_{r_y} - \n\t\t\tC_{d_z} G_{r_z}) T_{r_x} - \\\\&(C_{r_z} G_{d_w} - \n\t\t\tC_{r_y} G_{d_x} + C_{r_x} G_{d_y} + C_{r_w} G_{d_z} + \n\t\t\tC_{d_z} G_{r_w} - C_{d_y} G_{r_x} + C_{d_x} G_{r_y} + \n\t\t\tC_{d_w} G_{r_z}) T_{r_y} + \\\\&(C_{r_y} G_{d_w} + \n\t\t\tC_{r_z} G_{d_x} + C_{r_w} G_{d_y} - C_{r_x} G_{d_z} + \n\t\t\tC_{d_y} G_{r_w} + C_{d_z} G_{r_x} + C_{d_w} G_{r_y} - \n\t\t\tC_{d_x} G_{r_z}) T_{r_z}\n\t\t\\end{split}\n\t\t\\label{eq:rdx}\n\t\\end{equation}\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\tR_{d_y} = \\\\&\n\t\t\t(C_{r_y} G_{r_w} + \n\t\t\tC_{r_z} G_{r_x} + C_{r_w} G_{r_y} - \n\t\t\tC_{r_x} G_{r_z}) T_{d_w} -\\\\& (C_{r_z} G_{r_w} - \n\t\t\tC_{r_y} G_{r_x} + C_{r_x} G_{r_y} + \n\t\t\tC_{r_w} G_{r_z}) T_{d_x} -\\\\& (C_{r_w} G_{r_w} - \n\t\t\tC_{r_x} G_{r_x} - C_{r_y} G_{r_y} - \n\t\t\tC_{r_z} G_{r_z}) T_{d_y} +\\\\& (C_{r_x} G_{r_w} + \n\t\t\tC_{r_w} G_{r_x} - C_{r_z} G_{r_y} + \n\t\t\tC_{r_y} G_{r_z}) T_{d_z} + \\\\&(C_{r_y} G_{d_w} + \n\t\t\tC_{r_z} G_{d_x} + C_{r_w} G_{d_y} - C_{r_x} G_{d_z} + \n\t\t\tC_{d_y} G_{r_w} + C_{d_z} G_{r_x} + C_{d_w} G_{r_y} - \n\t\t\tC_{d_x} G_{r_z}) T_{r_w} +\\\\& (C_{r_z} G_{d_w} - \n\t\t\tC_{r_y} G_{d_x} + C_{r_x} G_{d_y} + C_{r_w} G_{d_z} + \n\t\t\tC_{d_z} G_{r_w} - C_{d_y} G_{r_x} + C_{d_x} G_{r_y} + \n\t\t\tC_{d_w} G_{r_z}) T_{r_x} +\\\\& (C_{r_w} G_{d_w} - \n\t\t\tC_{r_x} G_{d_x} - C_{r_y} G_{d_y} - C_{r_z} G_{d_z} + \n\t\t\tC_{d_w} G_{r_w} - C_{d_x} G_{r_x} - C_{d_y} G_{r_y} - \n\t\t\tC_{d_z} G_{r_z}) T_{r_y} -\\\\& (C_{r_x} G_{d_w} + \n\t\t\tC_{r_w} G_{d_x} - C_{r_z} G_{d_y} + C_{r_y} G_{d_z} + \n\t\t\tC_{d_x} G_{r_w} + C_{d_w} G_{r_x} - C_{d_z} G_{r_y} + \n\t\t\tC_{d_y} G_{r_z}) T_{r_z}\n\t\t\\end{split}\n\t\t\\label{eq:rdy}\n\t\\end{equation}\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\tR_{d_z} = \\\\&\n\t\t\t(C_{r_z} G_{r_w} - \n\t\t\tC_{r_y} G_{r_x} + C_{r_x} G_{r_y} + \n\t\t\tC_{r_w} G_{r_z}) T_{d_w} + \\\\&(C_{r_y} G_{r_w} + \n\t\t\tC_{r_z} G_{r_x} + C_{r_w} G_{r_y} - \n\t\t\tC_{r_x} G_{r_z}) T_{d_x} - \\\\&(C_{r_x} G_{r_w} + \n\t\t\tC_{r_w} G_{r_x} - C_{r_z} G_{r_y} + \n\t\t\tC_{r_y} G_{r_z}) T_{d_y} - \\\\&(C_{r_w} G_{r_w} - \n\t\t\tC_{r_x} G_{r_x} - C_{r_y} G_{r_y} - \n\t\t\tC_{r_z} G_{r_z}) T_{d_z} + \\\\&(C_{r_z} G_{d_w} - \n\t\t\tC_{r_y} G_{d_x} + C_{r_x} G_{d_y} + C_{r_w} G_{d_z} + \n\t\t\tC_{d_z} G_{r_w} - C_{d_y} G_{r_x} + C_{d_x} G_{r_y} + \n\t\t\tC_{d_w} G_{r_z}) T_{r_w} -\\\\& (C_{r_y} G_{d_w} + \n\t\t\tC_{r_z} G_{d_x} + C_{r_w} G_{d_y} - C_{r_x} G_{d_z} + \n\t\t\tC_{d_y} G_{r_w} + C_{d_z} G_{r_x} + C_{d_w} G_{r_y} - \n\t\t\tC_{d_x} G_{r_z}) T_{r_x} +\\\\& (C_{r_x} G_{d_w} + \n\t\t\tC_{r_w} G_{d_x} - C_{r_z} G_{d_y} + C_{r_y} G_{d_z} + \n\t\t\tC_{d_x} G_{r_w} + C_{d_w} G_{r_x} - C_{d_z} G_{r_y} + \n\t\t\tC_{d_y} G_{r_z}) T_{r_y} +\\\\& (C_{r_w} G_{d_w} - \n\t\t\tC_{r_x} G_{d_x} - C_{r_y} G_{d_y} - C_{r_z} G_{d_z} + \n\t\t\tC_{d_w} G_{r_w} - C_{d_x} G_{r_x} - C_{d_y} G_{r_y} - \n\t\t\tC_{d_z} G_{r_z}) T_{r_z}\n\t\t\\end{split}\n\t\t\\label{eq:rdz}\n\t\\end{equation}\n\t\n\tWe have 6 terms which put together generate one unique equation set. Given enough samples, and with knowledge that $R$ and $G$ never change, this system becomes solvable. To do this, we will reformat the equations into a computationally friendly matrix form. \n\t\n\tLets try to make a matrix from this with the form:\n\t\\begin{equation}\n\t\t\\begin{bmatrix}\n\t\t\ta\n\t\t\\end{bmatrix}\n\t\t\\begin{bmatrix}\n\t\t\tcoeff\n\t\t\\end{bmatrix}\n\t\t=\n\t\t\\begin{bmatrix}\n\t\t\tb\n\t\t\\end{bmatrix}\n\t\t\\label{eq:generalFormMatrix}\n\t\\end{equation}\n\t\t\n\t\\begin{equation}\n\t\t\\begin{bmatrix}\n\t\t\ta_{0,0} & \\cdots & a_{1,15} \\\\\n\t\t\t\\vdots  & \\ddots & \\vdots   \\\\\n\t\t\ta_{n,0} & \\cdots & a_{n,15} \n\t\t\\end{bmatrix}\n\t\t\\begin{bmatrix}\n\t\t\tG_{r_w} \\\\\n\t\t\tG_{r_x} \\\\\n\t\t\tG_{r_y} \\\\\n\t\t\tG_{r_z} \\\\\n\t\t\tG_{d_w} \\\\\n\t\t\tG_{d_x} \\\\\n\t\t\tG_{d_y} \\\\\n\t\t\tG_{d_z} \\\\\n\t\t\tR_{r_w} \\\\\n\t\t\tR_{r_x} \\\\\n\t\t\tR_{r_y} \\\\\n\t\t\tR_{r_z} \\\\\n\t\t\tR_{d_w} \\\\\n\t\t\tR_{d_x} \\\\\n\t\t\tR_{d_y} \\\\\n\t\t\tR_{d_z}\n\t\t\\end{bmatrix}\n\t\t=\n\t\t\\begin{bmatrix}\n\t\t\t0\n\t\t\\end{bmatrix}\n\t\t\\label{eq:generalMatrix}\n\t\\end{equation}\n\t\n\tEach sample will generate a set of 8 equations ($R_{r_w}$, $R_{r_x}$, $R_{r_y}$, $R_{r_z}$, $R_{d_w}$, $R_{d_x}$, $R_{d_y}$, $R_{d_z}$) to add to the matrix. We group the equations by unknowns. \n\t\n\tFrom \\autoref{eq:rrw} we generate:\n\t\\begin{equation}\n\t    \\begin{split}\n\t0= \\\\&\n\tG_{r_w} (C_{r_w} T_{r_w}+C_{r_x} T_{r_x}+C_{r_y} T_{r_y}+C_{r_z} T_{r_z})+\\\\&\n\tG_{r_x} (-C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z})+\\\\&\n\tG_{r_y} (-C_{r_y} T_{r_w}-C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\\\&\n\tG_{r_z} (-C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}+C_{r_w} T_{r_z})+\\\\&\n\t R_{r_w}(-1)\n\t\\end{split}\n\t\\end{equation}\n\t\n\tWhich in turn generates a row of the $a$ matrix in \\autoref{eq:generalMatrix}:\n\t\n\t\\begin{equation}\n\t    \\begin{bmatrix}\n\t    C_{r_w} T_{r_w}+C_{r_x} T_{r_x}+C_{r_y} T_{r_y}+C_{r_z} T_{r_z}\\\\\n\t    -C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z}\\\\\n\t    -C_{r_y} T_{r_w}-C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\\\\n\t    -C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}+C_{r_w} T_{r_z}\\\\\n\t    0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ -1 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0\n\t    \\end{bmatrix}^T\n\t\\end{equation}\n\t\n\t\n\tFrom \\autoref{eq:rrx} we generate:\n\t\\begin{equation}\n\t    \\begin{split}\n\t0= \\\\&\n\tG_{r_y} (-C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}-C_{r_w} T_{r_z})+\\\\&\n\tG_{r_z} (C_{r_y} T_{r_w}+C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\\\&\n\tG_{r_w} (C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z})+\\\\&\n\tG_{r_x} (C_{r_w} T_{r_w}+C_{r_x} T_{r_x}-C_{r_y} T_{r_y}-C_{r_z} T_{r_z})+\\\\&\n\t R_{r_x}(-1)\n\t \\end{split}\n\t \\end{equation}\n\t\n\t Which in turn generates another row of the $a$ matrix in \\autoref{eq:generalMatrix}:\n\t\n\t \\begin{equation}\n\t     \\begin{bmatrix}\n\t     -C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}-C_{r_w} T_{r_z}\\\\\n\t     C_{r_y} T_{r_w}+C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\\\\n\t     C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z}\\\\\n\t     C_{r_w} T_{r_w}+C_{r_x} T_{r_x}-C_{r_y} T_{r_y}-C_{r_z} T_{r_z}\\\\\n\t     0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ -1 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0\n\t      \\end{bmatrix}^T\n\t  \\end{equation}\n\t\n\t\n\tFrom \\autoref{eq:rry} we generate:\n\t\\begin{equation}\n\t    \\begin{split}\n\t0= \\\\&\n\tG_{r_w} (C_{r_y} T_{r_w}-C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\\\&\n\tG_{r_x} (C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}+C_{r_w} T_{r_z})+\\\\&\n\tG_{r_y} (C_{r_w} T_{r_w}-C_{r_x} T_{r_x}+C_{r_y} T_{r_y}-C_{r_z} T_{r_z})+\\\\&\n\tG_{r_z} (-C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z})+\\\\&\n\t R_{r_y}(-1)\n\t \\end{split}\n\t \\end{equation}\n\t\n\t Which in turn generates another row of the $a$ matrix in \\autoref{eq:generalMatrix}:\n\t\n\t \\begin{equation}\n\t     \\begin{bmatrix}\n\t     C_{r_y} T_{r_w}-C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\\\\n\t     C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}+C_{r_w} T_{r_z}\\\\\n\t     C_{r_w} T_{r_w}-C_{r_x} T_{r_x}+C_{r_y} T_{r_y}-C_{r_z} T_{r_z}\\\\\n\t     -C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z}\\\\\n\t     0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ -1 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0\n\t      \\end{bmatrix}^T\n\t  \\end{equation}\n\t  \n\t  From \\autoref{eq:rrz} we generate:\n\t  \\begin{equation}\n\t      \\begin{split}\n\t  0= \\\\&\n\t  G_{r_w} (C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}-C_{r_w} T_{r_z})+\\\\&\n\t  G_{r_x} (-C_{r_y} T_{r_w}+C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\\\&\n\t  G_{r_y} (C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z})+\\\\&\n\t  G_{r_z} (C_{r_w} T_{r_w}-C_{r_x} T_{r_x}-C_{r_y} T_{r_y}+C_{r_z} T_{r_z})+\\\\&\n\t   R_{r_z}(-1)\n\t   \\end{split}\n\t   \\end{equation}\n\t  \n\t   Which in turn generates another row of the $a$ matrix in \\autoref{eq:generalMatrix}:\n\t  \n\t   \\begin{equation}\n\t       \\begin{bmatrix}\n\t       C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}-C_{r_w} T_{r_z}\\\\\n\t       -C_{r_y} T_{r_w}+C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\\\\n\t       C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z}\\\\\n\t       C_{r_w} T_{r_w}-C_{r_x} T_{r_x}-C_{r_y} T_{r_y}+C_{r_z} T_{r_z}\\\\\n\t       0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ -1 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0\n\t        \\end{bmatrix}^T\n\t    \\end{equation}\n\t    \nFrom \\autoref{eq:rdw} we generate:\n\\begin{equation}\n    \\begin{split}\n0= \\\\&\nG_{r_w} (C_{r_w} T_{d_w}+C_{r_x} T_{d_x}+C_{r_y} T_{d_y}+C_{r_z} T_{d_z}+C_{d_w} T_{r_w}+C_{d_x} T_{r_x}+C_{d_y} T_{r_y}+C_{d_z} T_{r_z})+\\\\&\nG_{r_x} (-C_{r_x} T_{d_w}+C_{r_w} T_{d_x}+C_{r_z} T_{d_y}-C_{r_y} T_{d_z}-C_{d_x} T_{r_w}+C_{d_w} T_{r_x}+C_{d_z} T_{r_y}-C_{d_y} T_{r_z})+\\\\&\nG_{r_y} (-C_{r_y} T_{d_w}-C_{r_z} T_{d_x}+C_{r_w} T_{d_y}+C_{r_x} T_{d_z}-C_{d_y} T_{r_w}-C_{d_z} T_{r_x}+C_{d_w} T_{r_y}+C_{d_x} T_{r_z})+\\\\&\nG_{r_z} (-C_{r_z} T_{d_w}+C_{r_y} T_{d_x}-C_{r_x} T_{d_y}+C_{r_w} T_{d_z}-C_{d_z} T_{r_w}+C_{d_y} T_{r_x}-C_{d_x} T_{r_y}+C_{d_w} T_{r_z})+\\\\&\nG_{d_w} (C_{r_w} T_{r_w}+C_{r_x} T_{r_x}+C_{r_y} T_{r_y}+C_{r_z} T_{r_z})+\\\\&\nG_{d_x} (-C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z})+\\\\&\nG_{d_y} (-C_{r_y} T_{r_w}-C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\\\&\nG_{d_z} (-C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}+C_{r_w} T_{r_z})+\\\\&\n R_{d_w}(-1)\n \\end{split}\n \\end{equation}\n\n Which in turn generates another row of the $a$ matrix in \\autoref{eq:generalMatrix}:\n\n \\begin{equation}\n     \\begin{bmatrix}\n     C_{r_w} T_{d_w}+C_{r_x} T_{d_x}+C_{r_y} T_{d_y}+C_{r_z} T_{d_z}+C_{d_w} T_{r_w}+C_{d_x} T_{r_x}+C_{d_y} T_{r_y}+C_{d_z} T_{r_z}\\\\\n     -C_{r_x} T_{d_w}+C_{r_w} T_{d_x}+C_{r_z} T_{d_y}-C_{r_y} T_{d_z}-C_{d_x} T_{r_w}+C_{d_w} T_{r_x}+C_{d_z} T_{r_y}-C_{d_y} T_{r_z}\\\\\n     -C_{r_y} T_{d_w}-C_{r_z} T_{d_x}+C_{r_w} T_{d_y}+C_{r_x} T_{d_z}-C_{d_y} T_{r_w}-C_{d_z} T_{r_x}+C_{d_w} T_{r_y}+C_{d_x} T_{r_z}\\\\\n     -C_{r_z} T_{d_w}+C_{r_y} T_{d_x}-C_{r_x} T_{d_y}+C_{r_w} T_{d_z}-C_{d_z} T_{r_w}+C_{d_y} T_{r_x}-C_{d_x} T_{r_y}+C_{d_w} T_{r_z}\\\\\n     C_{r_w} T_{r_w}+C_{r_x} T_{r_x}+C_{r_y} T_{r_y}+C_{r_z} T_{r_z}\\\\\n     -C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z}\\\\\n     -C_{r_y} T_{r_w}-C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\\\\n     -C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}+C_{r_w} T_{r_z}\\\\\n     0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ -1 \\\\ 0 \\\\ 0 \\\\ 0\n      \\end{bmatrix}^T\n  \\end{equation}\n  \n  From \\autoref{eq:rdx} we generate:\n  \\begin{equation}\n      \\begin{split}\n  0= \\\\&\n  G_{r_w} (C_{r_x} T_{d_w}-C_{r_w} T_{d_x}+C_{r_z} T_{d_y}-C_{r_y} T_{d_z}+C_{d_x} T_{r_w}-C_{d_w} T_{r_x}+C_{d_z} T_{r_y}-C_{d_y} T_{r_z})+\\\\&\n  G_{r_x} (C_{r_w} T_{d_w}+C_{r_x} T_{d_x}-C_{r_y} T_{d_y}-C_{r_z} T_{d_z}+C_{d_w} T_{r_w}+C_{d_x} T_{r_x}-C_{d_y} T_{r_y}-C_{d_z} T_{r_z})+\\\\&\n  G_{r_y} (-C_{r_z} T_{d_w}+C_{r_y} T_{d_x}+C_{r_x} T_{d_y}-C_{r_w} T_{d_z}-C_{d_z} T_{r_w}+C_{d_y} T_{r_x}+C_{d_x} T_{r_y}-C_{d_w} T_{r_z})+\\\\&\n  G_{r_z} (C_{r_y} T_{d_w}+C_{r_z} T_{d_x}+C_{r_w} T_{d_y}+C_{r_x} T_{d_z}+C_{d_y} T_{r_w}+C_{d_z} T_{r_x}+C_{d_w} T_{r_y}+C_{d_x} T_{r_z})+\\\\&\n  G_{d_w} (C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z})+\\\\&\n  G_{d_x} (C_{r_w} T_{r_w}+C_{r_x} T_{r_x}-C_{r_y} T_{r_y}-C_{r_z} T_{r_z})+\\\\&\n  G_{d_y} (-C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}-C_{r_w} T_{r_z})+\\\\&\n  G_{d_z} (C_{r_y} T_{r_w}+C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\\\&\n   R_{d_x}(-1)\n   \\end{split}\n   \\end{equation}\n   \n   Which in turn generates another row of the $a$ matrix in \\autoref{eq:generalMatrix}:\n  \n   \\begin{equation}\n       \\begin{bmatrix}\n       C_{r_x} T_{d_w}-C_{r_w} T_{d_x}+C_{r_z} T_{d_y}-C_{r_y} T_{d_z}+C_{d_x} T_{r_w}-C_{d_w} T_{r_x}+C_{d_z} T_{r_y}-C_{d_y} T_{r_z}\\\\\n       C_{r_w} T_{d_w}+C_{r_x} T_{d_x}-C_{r_y} T_{d_y}-C_{r_z} T_{d_z}+C_{d_w} T_{r_w}+C_{d_x} T_{r_x}-C_{d_y} T_{r_y}-C_{d_z} T_{r_z}\\\\\n       -C_{r_z} T_{d_w}+C_{r_y} T_{d_x}+C_{r_x} T_{d_y}-C_{r_w} T_{d_z}-C_{d_z} T_{r_w}+C_{d_y} T_{r_x}+C_{d_x} T_{r_y}-C_{d_w} T_{r_z}\\\\\n       C_{r_y} T_{d_w}+C_{r_z} T_{d_x}+C_{r_w} T_{d_y}+C_{r_x} T_{d_z}+C_{d_y} T_{r_w}+C_{d_z} T_{r_x}+C_{d_w} T_{r_y}+C_{d_x} T_{r_z}\\\\\n       C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z}\\\\\n       C_{r_w} T_{r_w}+C_{r_x} T_{r_x}-C_{r_y} T_{r_y}-C_{r_z} T_{r_z}\\\\\n       -C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}-C_{r_w} T_{r_z}\\\\\n       C_{r_y} T_{r_w}+C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\\\\n       0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ -1 \\\\ 0 \\\\ 0\n        \\end{bmatrix}^T\n    \\end{equation}\n\t\n\t\n\tFrom \\autoref{eq:rdy} we generate:\n\t\\begin{equation}\n\t    \\begin{split}\n\t0= \\\\&\n\tG_{r_w} (C_{r_y} T_{d_w}-C_{r_z} T_{d_x}-C_{r_w} T_{d_y}+C_{r_x} T_{d_z}+C_{d_y} T_{r_w}-C_{d_z} T_{r_x}-C_{d_w} T_{r_y}+C_{d_x} T_{r_z})+\\\\&\n\tG_{r_x} (C_{r_z} T_{d_w}+C_{r_y} T_{d_x}+C_{r_x} T_{d_y}+C_{r_w} T_{d_z}+C_{d_z} T_{r_w}+C_{d_y} T_{r_x}+C_{d_x} T_{r_y}+C_{d_w} T_{r_z})+\\\\&\n\tG_{r_y} (C_{r_w} T_{d_w}-C_{r_x} T_{d_x}+C_{r_y} T_{d_y}-C_{r_z} T_{d_z}+C_{d_w} T_{r_w}-C_{d_x} T_{r_x}+C_{d_y} T_{r_y}-C_{d_z} T_{r_z})+\\\\&\n\tG_{r_z} (-C_{r_x} T_{d_w}-C_{r_w} T_{d_x}+C_{r_z} T_{d_y}+C_{r_y} T_{d_z}-C_{d_x} T_{r_w}-C_{d_w} T_{r_x}+C_{d_z} T_{r_y}+C_{d_y} T_{r_z})+\\\\&\n\tG_{d_w} (C_{r_y} T_{r_w}-C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\\\&\n\tG_{d_x} (C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}+C_{r_w} T_{r_z})+\\\\&\n\tG_{d_y} (C_{r_w} T_{r_w}-C_{r_x} T_{r_x}+C_{r_y} T_{r_y}-C_{r_z} T_{r_z})+\\\\&\n\tG_{d_z} (-C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z})+\\\\&\n\t R_{d_y}(-1)\n\t \\end{split}\n\t \\end{equation}\n\t\n\t Which in turn generates another row of the $a$ matrix in \\autoref{eq:generalMatrix}:\n\t\n\t \\begin{equation}\n\t     \\begin{bmatrix}\n\t     C_{r_y} T_{d_w}-C_{r_z} T_{d_x}-C_{r_w} T_{d_y}+C_{r_x} T_{d_z}+C_{d_y} T_{r_w}-C_{d_z} T_{r_x}-C_{d_w} T_{r_y}+C_{d_x} T_{r_z}\\\\\n\t     C_{r_z} T_{d_w}+C_{r_y} T_{d_x}+C_{r_x} T_{d_y}+C_{r_w} T_{d_z}+C_{d_z} T_{r_w}+C_{d_y} T_{r_x}+C_{d_x} T_{r_y}+C_{d_w} T_{r_z}\\\\\n\t     C_{r_w} T_{d_w}-C_{r_x} T_{d_x}+C_{r_y} T_{d_y}-C_{r_z} T_{d_z}+C_{d_w} T_{r_w}-C_{d_x} T_{r_x}+C_{d_y} T_{r_y}-C_{d_z} T_{r_z}\\\\\n\t     -C_{r_x} T_{d_w}-C_{r_w} T_{d_x}+C_{r_z} T_{d_y}+C_{r_y} T_{d_z}-C_{d_x} T_{r_w}-C_{d_w} T_{r_x}+C_{d_z} T_{r_y}+C_{d_y} T_{r_z}\\\\\n\t     C_{r_y} T_{r_w}-C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\\\\n\t     C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}+C_{r_w} T_{r_z}\\\\\n\t     C_{r_w} T_{r_w}-C_{r_x} T_{r_x}+C_{r_y} T_{r_y}-C_{r_z} T_{r_z}\\\\\n\t     -C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z}\\\\\n\t     0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ -1 \\\\ 0\n\t      \\end{bmatrix}^T\n\t  \\end{equation}\n\t  \n\nFrom \\autoref{eq:rdz} we generate:\n\\begin{equation}\n    \\begin{split}\n0= \\\\&\nG_{r_w} (C_{r_z} T_{d_w}+C_{r_y} T_{d_x}-C_{r_x} T_{d_y}-C_{r_w} T_{d_z}+C_{d_z} T_{r_w}+C_{d_y} T_{r_x}-C_{d_x} T_{r_y}-C_{d_w} T_{r_z})+\\\\&\nG_{r_x} (-C_{r_y} T_{d_w}+C_{r_z} T_{d_x}-C_{r_w} T_{d_y}+C_{r_x} T_{d_z}-C_{d_y} T_{r_w}+C_{d_z} T_{r_x}-C_{d_w} T_{r_y}+C_{d_x} T_{r_z})+\\\\&\nG_{r_y} (C_{r_x} T_{d_w}+C_{r_w} T_{d_x}+C_{r_z} T_{d_y}+C_{r_y} T_{d_z}+C_{d_x} T_{r_w}+C_{d_w} T_{r_x}+C_{d_z} T_{r_y}+C_{d_y} T_{r_z})+\\\\&\nG_{r_z} (C_{r_w} T_{d_w}-C_{r_x} T_{d_x}-C_{r_y} T_{d_y}+C_{r_z} T_{d_z}+C_{d_w} T_{r_w}-C_{d_x} T_{r_x}-C_{d_y} T_{r_y}+C_{d_z} T_{r_z})+\\\\&\nG_{d_w} (C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}-C_{r_w} T_{r_z})+\\\\&\nG_{d_x} (-C_{r_y} T_{r_w}+C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\\\&\nG_{d_y} (C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z})+\\\\&\nG_{d_z} (C_{r_w} T_{r_w}-C_{r_x} T_{r_x}-C_{r_y} T_{r_y}+C_{r_z} T_{r_z})+\\\\&\n R_{d_z}(-1)\n \\end{split}\n \\end{equation}\n\n Which in turn generates another row of the $a$ matrix in \\autoref{eq:generalMatrix}:\n\n \\begin{equation}\n     \\begin{bmatrix}\n     C_{r_z} T_{d_w}+C_{r_y} T_{d_x}-C_{r_x} T_{d_y}-C_{r_w} T_{d_z}+C_{d_z} T_{r_w}+C_{d_y} T_{r_x}-C_{d_x} T_{r_y}-C_{d_w} T_{r_z}\\\\\n     -C_{r_y} T_{d_w}+C_{r_z} T_{d_x}-C_{r_w} T_{d_y}+C_{r_x} T_{d_z}-C_{d_y} T_{r_w}+C_{d_z} T_{r_x}-C_{d_w} T_{r_y}+C_{d_x} T_{r_z}\\\\\n     C_{r_x} T_{d_w}+C_{r_w} T_{d_x}+C_{r_z} T_{d_y}+C_{r_y} T_{d_z}+C_{d_x} T_{r_w}+C_{d_w} T_{r_x}+C_{d_z} T_{r_y}+C_{d_y} T_{r_z}\\\\\n     C_{r_w} T_{d_w}-C_{r_x} T_{d_x}-C_{r_y} T_{d_y}+C_{r_z} T_{d_z}+C_{d_w} T_{r_w}-C_{d_x} T_{r_x}-C_{d_y} T_{r_y}+C_{d_z} T_{r_z}\\\\\n     C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}-C_{r_w} T_{r_z}\\\\\n     -C_{r_y} T_{r_w}+C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\\\\n     C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z}\\\\\n     C_{r_w} T_{r_w}-C_{r_x} T_{r_x}-C_{r_y} T_{r_y}+C_{r_z} T_{r_z}\\\\\n     0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ -1\n      \\end{bmatrix}^T\n  \\end{equation}\n  \n  \nThese rows can then be put into a solver, such as numpy.linalg.lstsq, with the b matrix set to a single column of all zeros, equal in length to the height of the resulting $a$ matrix. \n\\end{document}", "meta": {"hexsha": "86e95d25cd2d388abfb5d68989c8754b7b672aa5", "size": 23583, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "maths/robot2cam_calib.tex", "max_stars_repo_name": "mjsobrep/robot2camera-calibration", "max_stars_repo_head_hexsha": "74520563ad5a729f3289a11fc6f17f351018177f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-04T01:43:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-04T01:43:47.000Z", "max_issues_repo_path": "maths/robot2cam_calib.tex", "max_issues_repo_name": "ancy13428281619/robot2camera-calibration", "max_issues_repo_head_hexsha": "74520563ad5a729f3289a11fc6f17f351018177f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "maths/robot2cam_calib.tex", "max_forks_repo_name": "ancy13428281619/robot2camera-calibration", "max_forks_repo_head_hexsha": "74520563ad5a729f3289a11fc6f17f351018177f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-26T02:31:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-26T02:31:37.000Z", "avg_line_length": 47.166, "max_line_length": 444, "alphanum_fraction": 0.592672688, "num_tokens": 12326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530937, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.7481799444314465}}
{"text": "\\chapter{Taxonomy}\n\nArtificial intelligence is constrained optimization.\nBrain minimizes free energy \\cite{friston2006free,friston2010free}.\n\nGenerate vs discriminative.\n\nType type of an \\emph{expert system} is \\(Facts \\to Query \\to Answer\\).\nDecision tree.\nLinearized decision tree.\n\nA learning algorithm is \\emph{stable} iff its generalization error is bounded.\n\n\\section{Voronoi classifier}\n\nFind out the cluster centers.\nLet the Voronoi diagram be the boundary.\n\n\\section{Hyperplane classifier}\n\nLet \\(h\\) be a hyperplane.\nDefine \\(m : \\Real^\\infty \\to \\{0,1\\}\\),\nthe \\emph{hard linear binary classifier} of \\(h\\),\nas \\(m~x = [h~x \\ge 0]\\)\nwhere \\([x]\\) is 1 iff \\(x\\) is true or 0 iff \\(x\\) is false.\nSoft classifier: define \\(m~x = \\tanh^{-1}~(h~x)\\).\n\n\\section{Support vector machine}\n\nA training point \\(x\\) is a support of \\(h\\) iff\nit is the closest point to \\(h\\)\namong all points in the class of \\(x\\).\n\nAlternative formulation:\nAn upper level is a hyperplane \\(h_u\\) such that \\(\\forall a \\in U : h_u~a > 0\\).\nA lower level is a hyperplane \\(h_l\\) such that \\(\\forall b \\in L : h_l~b < 0\\).\nLet \\(h_u\\) and \\(h_l\\) be parallel.\nMaximize the distance between \\(h_u\\) and \\(h_l\\).\nThen \\(h_u\\) is the upper margin and \\(h_l\\) is the lower margin.\nDefine \\(h\\) as the hyperplane exactly between \\(h_u\\) and \\(h_l\\).\n\nDefine \\(m : \\Real^\\infty \\to \\{0,1\\}\\),\nthe \\emph{support vector machine} (SVM) of \\(h\\),\nas \\(m~x = [h~x \\ge 0]\\).\nSuch SVM is a binary classifier.\n", "meta": {"hexsha": "f922cfe433cc1981e39de0c2604b291b7d4b5dad", "size": 1477, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/taxonomy.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/taxonomy.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/taxonomy.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 32.1086956522, "max_line_length": 81, "alphanum_fraction": 0.683141503, "num_tokens": 458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920262, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.748174577829938}}
{"text": "\\subsubsection{Geothermal Heat Flux}\nThe heat flux accross the basal boundary depends on past temperature variations since temperature perturbations penetrate the bed rock if the ice is frozen to the ground \\citep{Ritz1987}. \nThe heat equation for the bed rock layer is given by the diffusion equation\n\\begin{equation}\n  \\label{num.eq.diffu_rock}\n  \\frac{\\pd T}{\\pd t} = \\frac{k_{\\text{rock}}}{\\rho_{\\text{rock}}c_{\\text{rock}}}\\nabla^2T=\\frac{k_{\\text{rock}}}{\\rho_{\\text{rock}}c_{\\text{rock}}} \n  \\left(\\frac{\\pd^2 T}{\\pd x^2}+\\frac{\\pd^2 T}{\\pd y^2}+\\frac{\\pd^2 T}{\\pd z^2}\\right),\n\\end{equation}\nwhere $k_{\\text{rock}}$ is the thermal conductivity, $\\rho_{\\text{rock}}$ the density and $c_{\\text{rock}}$ the specific heat capacity of the bed rock layer. \n\nInitial conditions for the temperature field $T$ are found by applying the geothermal heat flux, $G$ to an arbitrary surface temperature $T_0$:\n\\begin{equation}\n  T(x,y,z)=T_0+\\frac{G}{k_{\\text{rock}}}z.\n\\end{equation}\nThis ensures that initially the geothermal heat flux experienced by the ice sheet is equal to the regional heat flux. The basal boundary condition of the bedrock layer is kept constant, i.e.\n\\begin{equation}\n  T(x,y,H_{\\text{rock}})=T_0+\\frac{G}{k_{\\text{rock}}}H_{\\text{rock}}.\n\\end{equation}\nLateral boundary conditions are given by\n\\begin{equation}\n  \\left.\\frac{\\pd T}{\\pd x}\\right|_{x=0} = \\left.\\frac{\\pd T}{\\pd x}\\right|_{x=L_x} = \\left.\\frac{\\pd T}{\\pd y}\\right|_{y=0} = \\left.\\frac{\\pd T}{\\pd y}\\right|_{y=L_y} = 0.\n\\end{equation}\nAt the upper boundary, the heat flux of the rock layer has to be matched with the heat flux in the basal ice layer when the ice is frozen to the bed, i.e.\n\\begin{equation}\n  \\label{num.eq.gthf_bc}\n  k_{\\text{rock}}\\left.\\frac{\\pd T}{\\pd z}\\right|_{z=-0}=k_{\\text{ice}}\\left.\\frac{\\pd T}{\\pd z}\\right|_{z=+0}.\n\\end{equation}\nOtherwise the temperature of the top bedrock layer is set to the surface temperature (if the cell has been occupied by ice, but there is no ice present) or the basal ice temperature (if there is ice). Equation \\eqref{num.eq.gthf_bc} is automatically fulfilled if we set the top bedrock temperature to the basal ice temperature \\emph{everywhere} and then calculate the geothermal heat flux to be used as boundary condition for Equation \\eqref{temp.eq.temp_z}.\n\n\n\n\\subsection{Numerical Solution}\nThe horizontal grid is described in Section \\ref{num.sec.grid}. The vertical grid is irregular like the vertical grid of the ice sheet model. However, it is not scaled. Also for now, I have ignored topography or isostatic adjustment, i.e. the bedrock layer is assumed to be flat and constant.\n\nThe horizontal second derivative in Equation \\eqref{num.eq.diffu_rock} becomes using finite--differences\n\\begin{equation}\n  \\left.\\frac{\\pd^2T}{\\pd x^2}\\right|_{x_i,y_i,z_i} = T_{xx,i,j,k} = \\frac{T_{i+1,j,k}-2T_{i,j,k}+T_{i-1,j,k}}{\\Delta x}\n\\end{equation}\nand similarly for $\\pd^2T/\\pd y^2$. The vertical second derivative $\\pd^2T/\\pd z^2$ is similar to Equation \\eqref{temp.eq.dsigma2}:\n\\begin{multline}\n  \\left.\\frac{\\pd^2 T}{\\pd z^2}\\right|_{x_i,y_i,z_i} = T_{zz,i,j,k} = \\frac{2T_{i,j,k-1}}{(z_k-z_{k-1})(z_{k+1}-z_{k-1})} - \\frac{2T_{i,j,k}}{(z_{k+1}-z_k)(z_k-z_{k-1})}\\\\\n  + \\frac{2T_{i,j,k+1}}{(z_{k+1}-z_k)(z_{k+1}-z_{k-1})}\n\\end{multline}\n\n\nUsing the Crank-Nicholson scheme, Equation \\eqref{num.eq.diffu_rock} becomes\n\\begin{equation}\n  \\label{num.eq.diffu_rock_disc}\n  \\frac{T_{i,j,k}^{t+1}-T_{i,j,k}^{t}}{\\Delta t}=D\\left\\{\\frac{T_{xx,i,j,k}^{t+1}+T_{xx,i,j,k}^{t}}2 + \\frac{T_{yy,i,j,k}^{t+1}+T_{yy,i,j,k}^{t}}2 + \\frac{T_{zz,i,j,k}^{t+1}+T_{zz,i,j,k}^{t}}2 \\right\\},\n\\end{equation}\nwith $D=k_{\\text{rock}}/(\\rho_{\\text{rock}}c_{\\text{rock}})$. Equation \\eqref{num.eq.diffu_rock_disc} is solved by gathering all $T^{t+1}$ terms on the LHS and all other terms on the RHS. The index $(i,j,k)$ is linearised using $\\iota = i+(j-1)N+(k-1)NM$. The resulting matrix system is solved using the same bi--conjugate gradient solver as for the ice thickness evolution.\n\n", "meta": {"hexsha": "818a0918c962d0f95ca39b99c92b156a92df2bdf", "size": 4004, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "models/glc/cism/glimmer-cism/doc/num/gthf.tex", "max_stars_repo_name": "fmyuan/clm-microbe", "max_stars_repo_head_hexsha": "9faee9ed7d6c092c4a9e4a207f32cbffab78b85c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-03-12T01:58:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-16T03:08:25.000Z", "max_issues_repo_path": "models/glc/cism/glimmer-cism/doc/num/gthf.tex", "max_issues_repo_name": "fmyuan/clm-microbe", "max_issues_repo_head_hexsha": "9faee9ed7d6c092c4a9e4a207f32cbffab78b85c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-21T01:51:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-21T01:51:13.000Z", "max_forks_repo_path": "models/glc/cism/glimmer-cism/doc/num/gthf.tex", "max_forks_repo_name": "email-clm/CLM-Microbe", "max_forks_repo_head_hexsha": "711c87faec2c1bfe2cea1a7ebd07e4373e82a184", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2016-03-08T21:04:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-16T03:29:35.000Z", "avg_line_length": 75.5471698113, "max_line_length": 458, "alphanum_fraction": 0.7027972028, "num_tokens": 1374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.7481627423316081}}
{"text": "%---------------------------Radius Ratio-----------------------------\n\\section{Radius Ratio}\n\nLet $h_{\\max}$ be the maximum length of all edges and diagonals\n\\[\n  h_{\\max} = \\max\\left(L_{\\max},D_{\\max}\\right)\n\\]\nand ${\\cal L}_2$ be the sum of the squares of all edge lengths\n\\[\n{\\cal L}_2 = \\sum_{i=0}^3\\normvec{L_i}^2\n\\]\nand ${\\cal A}_i$ be the area of one of the 4 triangles formed by pairs of quadrilateral neighboring edges\n\\[\n  {\\cal A}_i = \\left|\\frac{\\alpha_i}{2}\\right|.\n\\]\nThen the radius ratio of a planar quadrilateral is\n\\[\n  q = \\frac{{\\cal L}_2 h_{\\max}}{\\min_{i\\in\\{0,1,2,3\\}}{\\cal A}_i}.\n\\]\n\n\\quadmetrictable{radius ratio}%\n{$1$}%                                      Dimension\n{$[1,1.3]$}%                                Acceptable range\n{$[1,DBL\\_MAX]$}%                           Normal range\n{$[1,DBL\\_MAX]$}%                           Full range\n{$1$}%                                      Square\n{\\cite{pebay:04}}%                          Citation\n{v\\_quad\\_radius\\_ratio}%                   Verdict function name\n\n", "meta": {"hexsha": "11f4c908ea1e2e3c86de9bb3ae53aeebeb6546ed", "size": 1038, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadRadiusRatio.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadRadiusRatio.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadRadiusRatio.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 34.6, "max_line_length": 105, "alphanum_fraction": 0.4922928709, "num_tokens": 303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.7481262802757196}}
{"text": "\\section{Discussion}\n\nWe have implemented a prototype of the tool described above. Out of the features we had envised, the alotted time for this thesis allowed us to build a working prototype that can abstract programs running under PSO. In this section, we discuss our expectations of the tool's behaviour and performance. We also show the results of run time measurements made with the tool and we compare it to the implementation of Dan et al. \\cite{danetal13}.\n\n\\subsection{Complexity}\n\nWe examine the time- and space complexities of the individual phases of our computation:\n\n\\subsubsection{Buffer size analysis}\n\nComputing the buffer size increases caused by each program point has a time complexity linear to the number of program points. For PSO programs, computing the actual buffer sizes needed at each program point requires a comparison of all buffer sizes per variable per program point. For TSO programs however, differentiating between variables is not needed. Therefore, the overall time complexity for the buffer size analysis in itself is $\\mathcal{O}(mn)$ in PSO, and $\\mathcal{O}(m)$ in TSO, with $m$ being the number of program points in $P$, and $n$ being the number of global variables in $P$.\\\\\n\nExamining the replacement codes of both PSO and TSO, we see that the time we need to generate replacement code blocks is mainly the time of the actual output, as there is no more complex computation necessary to be able to output the code, than the output itself needs. Therefore, generating the replacement codes has the following complexity by statement and store order: store statements: $\\mathcal{O}(K)$ in both TSO and PSO; load statements: $\\mathcal{O}(K)$ in both TSO and PSO; fence statements: $\\mathcal{O}(n)$ in PSO, $\\mathcal{O}(K)$ in TSO; flush statements: $\\mathcal{O}(nK)$ for TSO and PSO. Therefore, we can conclude that the code replacements following the buffer size analysis are bounded by the $\\mathcal{O}(nK)$-complex flush replacement. Since all replaceable statements are program points, the entire process of replacing them is multiplied by $m$ in complexity.\\\\\n\nTherefore, the buffer size analysis stage has a time complexity of $\\mathcal{O}(mnK)$\n\n\\subsubsection{Predicate abstraction}\n\nOur implementation of the predicate abstraction performed in accordance with our expectation of the Z3 \\cite{z3} calls being by far the most time-consuming, with run time percentages ranging from an average of 43.5\\% for Dekker's algorithm, to an average of 76.3\\% for the alternating bit protocol, as shown in Table 1. This shows that while complexity reduction is always an issue as long as we have problems of an untractable complexity, reducing the number of satisfiability modulo theory (SMT) solver calls has the most potential for speedup.\\\\\n\nThe complexity of all function calls in the predicate abstraction phase is therefore much less significant than the complexity of the number of SMT calls. Employing the optimisations described in section 4., the number of SMT solver calls is bounded by $|E|$ to the power of the maximum number of terms in a cube. This bound is in practice significantly lower when implicative cubes are found that are below the specified size limit, but this number is highly specific to the algorithm and the corresponding predicates.\n\n\\subsection{Evaluation}\n\nWe have implemented the procedures as described so far in a tool we call SROTOGAP. Then, we have run numerous tests on the following concurrent algorithms: the alternating bit protocol, Lamport's Bakery Algorithm, Dekker's Algorithm, Peterson's Algorithm, a lock-free queue, and Szyma\\'nski's Mutual Exclusion Algorithm. All experiments were conducted on an Intel(R) Core(TM) i7-3770 3.40GHz with 8GB RAM. The key questions were whether the buffer size analysis has significantly shortened the time needed to perform a correct predicate abstraction, and whether the replacement techniques employed in the predicate abstraction stage have warded off the complexity explosion that would have resulted from the na\\\"ive execution of current predicate analysis methods on the additional predicates spawned from the buffer abstraction.\\\\\n\nWe compare our results to those of Dan et al. \\cite{danetal13}, as the measurements had been done on the same algorithms, and the methods were similar. To be more precise: this work seeks to improve on the methods described in \\cite{danetal13}, and we hope to show that our modifications have helped to improve the performance of those methods. The modifications done are as follows:\\\\\n\n\\paragraph{Buffer size analysis}\n\nAs opposed to Dan et al. \\cite{danetal13}, we perform a buffer size analysis on the program in order to be able to minimise the lines of code generated during our replacement phase by seeking to omit parts which we know never to be reached during run-time. We approach this task by statically analising the input, and performing replacements which can be generated in polynomial time.\\\\\n\n\\paragraph{Flush abstraction optimisation}\n\nIn \\cite{danetal13}, flushes have been modeled in a way that caused each iteration to shift at most $K$ variables, which would have effectively increased the run time of a flush, and the number of program states for each flush operation. In our implementation, the buffer is modelled to be ``immobile'', i.e. a value stored in the buffer is considered to remain in place until it has been flushed or otherwise deleted. This provides us with the following advantages: each flush iteration only adds one state to the set of program states; the time complexity of flushes is dominated by finding the value to be flushed, not iterating over every value in the buffer; and finally, if the buffer size is exceeded at run time, an immobile buffer tail will always trigger an overflow error at the $K + 1$st consecutive store, while the approach in \\cite{danetal13} would non-deterministically cause the buffer tail to recede from the buffer size limit with each flush - though this might be beneficial from an efficient resource allocation point of view, we would like to simplify reaching possible erroneous states for purposes of error detection.\\\\\n\n\\pagebreak\n\n\\begin{center}\n\\textbf{Table 1.} Boolean program generation\\\\\n\\begin{tabular}{|r|r|r|r|r|r|r|}\n\t\n\t\\hline\n\talgorithm & \\vtop{\\hbox{\\strut \\# input}\\hbox{\\strut predicates}} & \\vtop{\\hbox{\\strut \\# total}\\hbox{\\strut predicates}} & \\vtop{\\hbox{\\strut \\# unique}\\hbox{\\strut cubes}} & \\vtop{\\hbox{\\strut \\# SMT}\\hbox{\\strut calls}} & time (s) & \\vtop{\\hbox{\\strut maximum}\\hbox{\\strut cube size}}\t\\\\ \\hline\n\tDekker\t\t&\t7\t&\t27\t&\t15\t\t&\t566\t\t&\t6.01\t&\t1\t\\\\ \\hline\n\tPeterson\t&\t7\t&\t27\t&\t99\t\t&\t572\t\t&\t4.40\t&\t2\t\\\\ \\hline\n\tABP\t\t\t&\t8\t&\t12\t&\t129\t\t&\t488\t\t&\t2.36\t&\t2\t\\\\ \\hline\n\tSzyma\\'nski\t&\t20\t&\t70\t&\t801\t\t&\t1257\t&\t10.05\t&\t2\t\\\\ \\hline\n\tLF Queue\t&\t7\t&\t32\t&\t939\t\t&\t2556\t&\t15.24\t&\t4\t\\\\ \\hline\n\tBakery\t\t&\t15\t&\t75\t&\t25931\t&\t85268\t&\t974.71\t&\t4\t\\\\ \\hline\n\t\n\\end{tabular}\\\\\n\n\\paragraph{}\n\\textbf{Table 2.} Model checking until error state found\\\\\n\\begin{tabular}{|r|r|r|r|}\n\t\n\t\\hline\n\talgorithm & \\vtop{\\hbox{\\strut \\# states}\\hbox{\\strut before error}} & memory used (MB) & evaluation time (s) \\\\ \\hline\n\tDekker\t\t&\t98\t&\t5\t&\t0.030\t\\\\ \\hline\n\tPeterson\t&\t98\t&\t5\t&\t0.034\t\\\\ \\hline\n\tABP\t\t\t&\t327\t&\t4\t&\t0.045\t\\\\ \\hline\n\tSzyma\\'nski\t&\t247\t&\t7\t&\t0.043\t\\\\ \\hline\n\tLF Queue\t&\t157\t&\t24\t&\t0.388\t\\\\ \\hline\n\tBakery\t\t&\t310\t&\t36\t&\t0.323\t\\\\ \\hline\n\t\n\\end{tabular}\n\\end{center}\n\nAll measurements were done under PSO with $K = 5$, i.e. the implementation of the principles discussed for TSO is not included in this work. Furthermore, the model checker has judged all abstractions to be incorrect. This proves that the boolean programs generated by our prototype are not yet verifiable by Fender. Though there was no time to completely debug our code, we can still compare the overall performance of the tool, to get an idea of the potential changes in performance and complexity. Note that we omitted evaluating the ticket locking algorithm, although it had been tested in \\cite{danetal13}, as our definition of SALPL does not include blocks of atomic code.\\\\\n\nComparing the measurements in \\cite{danetal13} with ours, we first note that we have worked the sequential consistency predicates although we have abstracted programs under PSO, as it was our goal to abstract programs using only the predicates needed to prove correctness under sequential consistency constraints. The predicates actually generated by our program are far more numerous and their numbers are less expressive, as their number increases with the multitude of variables and the newly generated predicates do not cause any additional SMT calls.\\\\\n\nAnother fact we notice is that SROTOGAP generates about 100 times as many cubes as CUPEX \\cite{danetal13} for low cube sizes, but less cubes for high cube sizes. This result should be observed with caution however, as in all cases with the cube size limit being $> 2$, the largest cube disjunction, the disjunction of cubes implying $false$, has timed out in SROTOGAP, which has triggered a halt in that computation, thus preventing the inception of a number of cubes possibly orders of magnitude larger than their counterparts in \\danetal{13}. This comes as no surprise, as even without SMT calls, the cubes generated using heuristics grows with the number of total predicates $|E \\cup E'|$.\\\\\n\nThe numbers of model checker states are markably lower in our work than they were in \\cite{danetal13}. This metric however, along with the other two model checker metrics, is possibly the least significant for our intended comparison, as the model checker has obviously received erroneous outputs from SROTOGAP.", "meta": {"hexsha": "795f6ca4bdeb2d501f5825dc3d8f92e1f696c4b1", "size": 9656, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/writeup/discussion.tex", "max_stars_repo_name": "hetmeter/awmm", "max_stars_repo_head_hexsha": "8d65b1246898b27db1ac5a6542465f71e27b1603", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/writeup/discussion.tex", "max_issues_repo_name": "hetmeter/awmm", "max_issues_repo_head_hexsha": "8d65b1246898b27db1ac5a6542465f71e27b1603", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/writeup/discussion.tex", "max_forks_repo_name": "hetmeter/awmm", "max_forks_repo_head_hexsha": "8d65b1246898b27db1ac5a6542465f71e27b1603", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 127.0526315789, "max_line_length": 1143, "alphanum_fraction": 0.7736122618, "num_tokens": 2403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.931462503162843, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7481262792178203}}
{"text": "\\section{Fourier Series}\r\n\\subsection{Periodic Functions}\r\n\\begin{definition}\r\n    A function $f$ is periodic with period $T$ is $f(x+T)=f(x)$ for any $x$.\r\n\\end{definition}\r\n\\begin{example}\r\n    The physical quantities in a simple harmonic motion are periodic in time $t$.\r\n    For example, if we take a simple pendulum, then the height of the pendulum bulb can be described\r\n    \\footnote{Approximated.}\r\n    by $y=A\\sin(\\omega t)$, so $y$ is periodic (in $t$) with period $T=2\\pi/\\omega$.\r\n    So it has angular frequency $\\omega$ and frequency $f=1/T$.\\\\\r\n    In space, the wavelength is $\\lambda=2\\pi/k$ and the (angular) wavenumber is $k=2\\pi/\\lambda$.\r\n\\end{example}\r\nConsider the set of functions $g_n(x)=\\cos(n\\pi x/L)$ and $h_n(x)=\\sin(n\\pi x/L)$ where $n$ is taken as positive integer.\r\nThey are obviously all periodic with period $2L$.\r\n\\begin{definition}\r\n    For (sufficiently nice) $f,g:[0,2L)\\to\\mathbb R$, we define their inner product to be\r\n    $$\\langle f,g\\rangle =\\int_0^{2L}f(x)g(x)\\,\\mathrm dx$$\r\n\\end{definition}\r\n\\begin{proposition}\r\n    The functions $g_n,h_n$ are mutually orthogonal on the inteval $[0,2L]$ with respect to the inner product above.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Recall the identites we learnt half an eternity ago:\r\n    \\begin{align*}\r\n        \\cos A\\cos B&=\\frac{\\cos(A-B)+\\cos(A+B)}{2}\\\\\r\n        \\sin A\\sin B&=\\frac{\\cos(A-B)-\\cos(A+B)}{2}\\\\\r\n        \\sin A\\cos B&=\\frac{\\sin(A-B)+\\sin(A+B)}{2}\r\n    \\end{align*}\r\n    We can obtain, by simply integrating, that $\\langle h_n,g_m\\rangle=0$ for any $m,n$.\r\n    Similarly, for any $m\\neq n$, $\\langle h_n,h_m\\rangle=\\langle g_n,g_m\\rangle=0$.\r\n    So they are orthogonal.\r\n\\end{proof}\r\nWhat if $m=n$?\r\nBy integrating again, we can get\r\n$$\\langle g_n,g_n\\rangle=\\begin{cases}\r\n    L\\text{, if $n\\neq 0$}\\\\\r\n    2L\\text{, if $n=0$}\r\n\\end{cases},\\langle h_n,h_n\\rangle=\\begin{cases}\r\n    L\\text{, if $n\\neq 0$}\\\\\r\n    0\\text{, if $n=0$}\r\n\\end{cases}$$\r\nThis shows that $g_n$ and $h_n$ form a linearly independent set.\r\nWe decree that this set actually ``spans'' the space of ``well-behaved'' periodic functions with period $2L$.\r\nWe will get to the intuitive reason why we make such an assertion (and what does it actually mean) in a moment.\\\\\r\nIn finite dimensional vector spaces like $\\mathbb R^3$, we have the standard basis which forms a orthonormal basis.\r\nWe can make the analogy to the space of nice enough functions mentioned above so that we can say this set of trigonometric functions form a ``basis'' there given that we can indeed represent every (nice) function with a (possibly infinite) series of linear combinations of $f_n,g_n$.\r\n\\footnote{As you expect, something not rigourous shall start to happen.}\r\n\\subsection{Definition of a Fourier Series}\r\nWe assert that we can represent any ``well-behaved'' periodic functions $f$ with period $2L$ in the form\r\n$$\\frac{1}{2}a_0+\\sum_{n=1}^\\infty a_n\\cos\\frac{n\\pi x}{L}+\\sum_{n=1}^\\infty b_n\\sin\\frac{n\\pi x}{L}$$\r\nWe sure will want this series to converge to $f$ wherever $f$ is continuous.\r\nAs a jump discontinuity, we would want this series to converge to the average value of the upper and lower limits of $f$ at that point.\\\\\r\nIf these conditions are satisfied and we are allowed to exchange limiting operations, previous discussions then yield\r\n$$\\langle h_n,f\\rangle=Lb_n\\implies b_n=\\frac{1}{L}\\langle h_n,f\\rangle=\\frac{1}{L}\\int_0^{2L}f(x)\\sin\\frac{n\\pi x}{L}\\,\\mathrm dx$$\r\nSimilarly, for any $n$ we have\r\n$$a_n=\\frac{1}{L}\\langle g_n,f\\rangle=\\frac{1}{L}\\int_0^{2L}f(x)\\cos\\frac{n\\pi x}{L}\\,\\mathrm dx$$\r\n\\begin{note}\r\n    1. The coefficient $1/2$ in front of $a_0$ helped here as it makes the above formula work for $n=0$ too.\r\n    Actually $a_0/2$ is the average value of $f$ over the interval $[0,2L)$.\\\\\r\n    2. The range of integration actually does not matter much as long as its length is $2L$.\r\n    E.g. we can replace it by $[-L,L)$ as well.\\\\\r\n    3. We can think of the Fourier series of a function as decomposing the function into harmonics.\r\n\\end{note}\r\n\\begin{example}[Sawtooth wave]\r\n    Consider a $2L$-periodic function where $f(x)=x$ for $x\\in [-L,L)$.\r\n    Then obviously $a_n=0$ for any $n$ as $f$ is odd.\r\n    Whereas integration by part reveals that $b_n=2L(-1)^{n+1}/(n\\pi)$.\r\n    So the Fourier series has the form\r\n    $$2L\\sum_{n=1}^\\infty\\frac{(-1)^{n+1}}{n\\pi}\\sin\\frac{n\\pi x}{L}$$\r\n    We know this is (slowly) convergent by the alternating series test.\r\n    A plot of the truncated series seems to show that it does converge to what we want.\r\n\\end{example}\r\n\\begin{note}\r\n    In the above example, as $n\\to\\infty$, the Fourier series approximation improves and convergent where the original function is continuous.\r\n    Also, at the discontinuity, it does converge to the average value of the limits from two sides.\r\n    So this particular Fourier series behaves as advertised.\\\\\r\n    One should also observe that this Fourier series has a persistent ``overshoot'' near the discontinuity which is approximately $9\\%$.\r\n    This is known as the Gibbs' Phenomenon.\r\n\\end{note}\r\n\\subsection{The Dirichlet Conditions and Fourier's Theorem}\r\nA natural question is then which functions are allowed to have a proper Fourier series.\r\nSurprisingly, a big, yet hard to precisely characterise, class of functions has a convergent Fourier series that has the desired properties.\r\nThis class even includes some classical counterexamples in analysis.\r\nAs an applied course, we will just look at some of the sufficient conditions.\r\n\\begin{theorem}[Fourier's Theorem]\r\n    If $f$ is a bounded periodic function with period $2L$ with a finite number of minima, maxima, and discontinuities in $[0,2L)$, then its Fourier series converges to $f$ where it is continuous and converges to the average of the two side limits.\r\n\\end{theorem}\r\nThe conditions in this theorem is known as the Dirichlet conditions.\r\n\\begin{note}\r\n    1. These conditions are hella weak compared to our conditions for a function to have e.g. a Taylor series.\r\n    However, pathological functions like $1/x,\\sin(1/x),1_{\\mathbb R\\setminus\\mathbb Q}(x)$ are excluded from these conditions.\\\\\r\n    2. The converse is not true, as $\\sin(1/x)$ has a Fourier series we desire.\r\n\\end{note}\r\n\\begin{proof}\r\n    You don't really expect to see an actual proof here, do you?\r\n\\end{proof}\r\nAnother subject of interest is the rate of convergence of a Fourier series.\r\nPerhaps unsurprisingly, it depends on the smoothness of the function.\r\n\\begin{theorem}\r\n    If $f(x)$ is $p^{th}$ differentiable but $f^{(p)}$ is not continuous, then its Fourier series converges as $O(n^{-(p+1)})$ as $n\\to\\infty$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Ditto.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. Consider the square wave\r\n    $$f(x)=\\begin{cases}\r\n        1\\text{, for $0\\le x<1$}\\\\\r\n        -1\\text{, for $-1\\le x<0$}\r\n    \\end{cases}$$\r\n    That extends periodically with period $2$.\r\n    Then it has a Fourier series\r\n    $$4\\sum_{m=1}^\\infty\\frac{\\sin[(2m-1)\\pi x]}{(2m-1)\\pi}$$\r\n    which, as one can see both from the preceding theorem (with $p=0$) and observation, converges slowly.\\\\\r\n    2. Consider the general ``see-saw'' wave\r\n    $$f(x)=\\begin{cases}\r\n        x(1-\\xi)\\text{, for $x\\in[0,\\xi)$}\\\\\r\n        \\xi(1-x)\\text{, for $x\\in[\\xi,1)$}\r\n    \\end{cases}$$\r\n    which extends as an odd periodic function with period $2$.\r\n    This has Fourier series\r\n    $$2\\sum_{m=1}^\\infty\\frac{\\sin (n\\pi\\xi)\\sin (n\\pi x)}{(n\\pi)^2}$$\r\n    which converges with $p=1$ in the preceding theorem.\r\n    In particular, $\\xi=1/2$ gives\r\n    $$2\\sum_{m=1}^\\infty(-1)^{m+1}\\frac{\\sin[(2m-1)\\pi x]}{[(2m-1)\\pi]^2}$$\r\n    which can be seen, immediately, that it converges faster than the series in the previous example.\\\\\r\n    3. Take $f(x)=x(1-x)/2$ for $x\\in[0,1)$ that extends as an odd periodic function with period $2$.\r\n    Then its Fourier series is\r\n    $$4\\sum_{m=1}^\\infty\\frac{\\sin[(2m-1)\\pi x]}{[(2m-1)\\pi]^3}$$\r\n    which has $p=2$.\\\\\r\n    4. Take $f(x)=(1-x^2)^2$, then $a_n=O(n^{-4})$.\r\n\\end{example}\r\nOf course, we want to integrate and differentiate a Fourier series term-by-term.\r\nIntegration, as one expect, seldom yields problems as it imposed very few restrictions on the function.\r\nAnd indeed, we are just going to assume we can integrate any Fourier series term-by-term and they guarantee to yield a smoother function, which satisfies the Dirichlet conditions if the original function does.\\\\\r\nDifferentiation is more problematic when doing it term-by-term.\r\n\\begin{example}\r\n    Take the square wave again which is known to have Fourier series\r\n    $$4\\sum_{m=1}^\\infty\\frac{\\sin[(2m-1)\\pi x]}{(2m-1)\\pi}$$\r\n    which, after term-by-term differentiation, yields\r\n    $$4\\sum_{m=1}^\\infty\\cos[(2m-1)\\pi x]$$\r\n    which is clearly divergent.\r\n    This is perhaps unsurprising as the original function is not even continuous.\r\n\\end{example}\r\n\\begin{theorem}\r\n    If $f(x)$ is differentiable and both $f,f^\\prime$ satisfy Dirichlet conditions, then we can differentiate the Fourier series of $f$ term-by-term to get the Fourier series of $f^\\prime$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Haha.\r\n\\end{proof}\r\n\\begin{example}\r\n    If we differentiate the see-saw curve with $\\xi=1/2$, then we will get an offset of the Fourier series of the square wave.\r\n\\end{example}\r\n\\subsection{Parseval's Theorem}\r\nThere is some interesting relation between the integral of the square of a function and the square of the Fourier coefficients of that function.\r\nIf the function is nice enough to have a nice enough Fourier series, then by orthogonality,\r\n\\begin{align*}\r\n    \\int_0^{2L}f(x)^2\\,\\mathrm dx&=\\int_0^{2L}\\left( \\frac{a_0}{2}+\\sum_{n\\ge 1}a_n\\cos\\frac{n\\pi x}{2}+\\sum_{n\\ge 1}b_n\\sin\\frac{n\\pi x}{2} \\right)^2\\,\\mathrm dx\\\\\r\n    &=\\int_0^{2L}\\left( \\frac{a_0^2}{4}+\\sum_{n\\ge 1}a_n^2\\cos^2\\frac{n\\pi x}{2}+\\sum_{n\\ge 1}b_n^2\\sin^2\\frac{n\\pi x}{2} \\right)\\,\\mathrm dx\\\\\r\n    &=L\\left( \\frac{a_0^2}{2}+\\sum_{n\\ge 1}(a_n^2+b_n^2) \\right)\r\n\\end{align*}\r\nThis is also called the completeness relation as the left hand side would be greater than or equal to the right hand side if any basis functions are missing from the series.\r\nThis is known as Parseval's Theorem.\r\n\\begin{theorem}[Parseval's Theorem]\\label{parseval}\r\n    For a nice enough function $f$ with Fourier coefficients $a_n,b_n$, we have\r\n    $$\\int_0^{2L}f(x)^2\\,\\mathrm dx=L\\left( \\frac{a_0^2}{2}+\\sum_{n\\ge 1}(a_n^2+b_n^2) \\right)$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Above.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider the sawtooth curve with $f(x)=x,x\\in[-L,L)$ with period $2L$.\r\n    Then Parseval's Theorem reveals that\r\n    $$\\frac{2}{3}L^3=\\int_{-L}^Lx^2\\,\\mathrm dx=L\\sum_{n=1}^\\infty\\frac{4L^2}{n^2\\pi^2}=\\frac{4L^3}{\\pi^2}\\sum_{n=1}^\\infty\\frac{1}{n^2}\\implies \\sum_{n=1}^\\infty\\frac{1}{n^2}=\\frac{\\pi^2}{6}$$\r\n\\end{example}\r\n\\begin{remark}\r\n    If we think of the integral of the square as the inner product of a function with itself, then Parseval's Theorem can be thought of an analog of Pythagoras' Theorem in this space of functions.\r\n\\end{remark}\r\n\\subsection{Alternative Fourier Series}\r\nConsider a function $f:[0,L)\\to\\mathbb R$.\r\nWe can extend $f$ to a periodic function of period $2L$ in two ways:\\\\\r\n1. We can require the function to be odd, then $a_n=0$ for all $n$ and\r\n$$b_n=\\frac{2}{L}\\int_0^Lf(x)\\sin\\frac{n\\pi x}{L}\\,\\mathrm dx$$\r\nand the Fourier series would be $\\sum_{n\\ge 1}b_n\\sin(n\\pi x/L)$, which is called a Fourier sine series.\r\nThe sawtooth function is an example of this.\\\\\r\n2. We can require the function to be even, then $b_n=0$ for all $n$ and\r\n$$a_n=\\frac{2}{L}\\int_0^Lf(x)\\cos\\frac{n\\pi x}{L}\\,\\mathrm dx$$\r\nSo the Fourier series is $a_0/2+\\sum_{n\\ge 1}a_n\\cos(n\\pi x/L)$.\r\nThis is called a Fourier cosine series.\r\n$f(x)=(1-x^2)^2$ is an example (where $L=1$).\\\\\r\nThe actual thing we want is tp represent the Fourier series more neatly in terms of exponentials.\r\nWe know that\r\n$$\\cos\\frac{n\\pi x}{L}=\\frac{e^{in\\pi x/L}+e^{-in\\pi x/L}}{2},\\sin\\frac{n\\pi x}{L}=\\frac{e^{in\\pi x/L}-e^{-in\\pi x/L}}{2i}$$\r\nSo by writing $c_0=a_0/2$ and\r\n$$c_m=\\begin{cases}\r\n    (a_m-ib_m)/2\\text{, for $m>0$}\\\\\r\n    (a_{-m}+ib_{-m})/2\\text{, for $m<0$}\r\n\\end{cases}$$\r\nWe obtain\r\n$$\\frac{a_0}{2}+\\sum_{n=1}^\\infty a_n\\cos\\frac{n\\pi x}{L}+\\sum_{n=1}^\\infty b_n\\sin\\frac{n\\pi x}{L}=\\sum_{m=-\\infty}^\\infty c_me^{im\\pi x/L}$$\r\nEquivalently, if we extend our inner product to the complex functions\r\n$$\\langle f,g\\rangle=\\int_{-L}^Lf(x)g^*(x)\\,\\mathrm dx$$\r\nThen $\\langle e^{im\\pi x/L},e^{in\\pi x/L}\\rangle=2L\\delta_{mn}$, which means they are orthogonal as well and we can then obtain\r\n$$c_m=\\frac{1}{2L}\\langle f(x),e^{im\\pi x/L}\\rangle=\\frac{1}{2L}\\int_{-L}^Lf(x)e^{-im\\pi x/L}\\,\\mathrm dx$$\r\nBy thinking them as a set of basis of a space of nice-enough functions in the way we did for $\\sin$ and $\\cos$.\r\nParseval's Theorem can then be stated as\r\n$$\\int_{-L}^Lf(x)^2\\,\\mathrm dx=2L\\sum_{n=-\\infty}^\\infty|c_n|^2$$\r\n\\subsection{Some Motivations of Fourier Series}\r\n\\begin{definition}\r\n    The complex inner product $\\langle,\\rangle:\\mathbb C^N\\times\\mathbb C^N\\to\\mathbb C$ is defined by\r\n    $$\\langle\\underline{u},\\underline{v}\\rangle=\\underline{u}^\\dagger\\underline{v}$$\r\n\\end{definition}\r\nAn $N\\times N$  matrix $A$ is self-adjoint (or Hermitian) if\r\n$$\\forall\\underline{u},\\underline{v}\\in\\mathbb C^N,\\langle A\\underline{u},\\underline{v}\\rangle=\\langle\\underline{u},A\\underline{v}\\rangle$$\r\nOne can show easily that this is just saying $A^\\dagger=A$.\r\nIt can be easily shown that $A$ satisfies:\\\\\r\n1. All eigenvalues are real for all $n$.\\\\\r\n2. Eigenvectors associated with different eigenvalues are orthogonal with respect to $\\langle,\\rangle$.\\\\\r\nSpectral Theorem then shows that we have an orthonormal basis of $\\mathbb C^N$ consisting of eigenvectors $\\{\\underline{v}_1,\\ldots,\\underline{v}_N\\}$.\\\\\r\nNow, given any $\\underline{b}$, if we want to solve for $\\underline{x}$ in $A\\underline{x}=\\underline{b}$, then a way to do it is to express $\\underline{b}=\\sum_nb_n\\underline{v}_n$ and observe that if $\\sum_nc_n\\underline{v}_n$ is a solution then\r\n$$\\sum_nb_n\\underline{v}_n=A\\left(\\sum_{n=1}^Nc_n\\underline{v}_n\\right)=\\sum_{n=1}^Nc_n\\lambda_n\\underline{v}_n$$\r\nwhere $\\lambda_n$ is the eigenvalue associated with $\\underline{v}_n$.\r\nSo if $A$ is nonsingular, then none of the $\\lambda_n$ is zero and we can write $c_n=b_n/\\lambda_n$ and get the solution\r\n$$\\underline{x}=\\sum_{n=1}^N\\frac{b_n}{\\lambda_n}\\underline{v}_n$$\r\nThis means we can easily solve an linear equation if there is a basis consisting of eigenvectors of the matrix.\r\nWe want an analogy of this in solving linear ODEs.\r\nConsider the differential operator\r\n$$\\mathcal Ly=-\\frac{\\mathrm d^2y}{\\mathrm dx^2}$$\r\nand suppose we want to solve $\\mathcal Ly=f(x)$ for a function $f(x)$ subject to boundary conditions $y(0)=y(L)=0$.\r\nThe related eigenvalue problem is then $\\mathcal L y_n=\\lambda_ny_n$ with $y_n(0)=y_n(L)=0$ which has solutions\r\n$$y_n(x)=\\sin\\frac{n\\pi x}{L},\\lambda_n=\\left( \\frac{n\\pi}{L} \\right)^2$$\r\nSo we will want to write\r\n$$y(x)=\\sum_{n=1}^\\infty c_n\\sin\\frac{n\\pi x}{L},f(x)=\\sum_{n=1}^\\infty b_n\\sin\\frac{n\\pi x}{L},b_n=\\frac{2}{L}\\int_0^Lf(x)\\sin\\frac{n\\pi x}{L}\\,\\mathrm dx$$\r\nand ignore every convergence problem.\r\nThen this substitution yields\r\n$$\\sum_{n=1}^\\infty b_n\\sin\\frac{n\\pi x}{L}=\\mathcal Ly=-\\frac{\\mathrm d^2y}{\\mathrm dx^2}\\left( \\sum_{n=1}^\\infty c_n\\sin\\frac{n\\pi x}{L} \\right)=\\sum_{n=1}^\\infty c_n\\left( \\frac{n\\pi}{L} \\right)^2\\sin\\frac{n\\pi x}{L}$$\r\nHence, $c_n=b_n(L/(n\\pi))^2$ by orthogonality, so we can get a particular solution of the problem in the form\r\n$$y(x)=\\sum_{n=1}^\\infty \\frac{b_n}{\\lambda_n}y_n$$\r\nwhich is the analogy we wanted.\r\n\\begin{example}\\label{odd_sq_fourier_ode}\r\n    Let $L=1$ and set $f$ to be the odd square wave with $f(x)=1$ for $x\\in[0,1)$.\r\n    This has Fourier series\r\n    $$4\\sum_{m=1}^\\infty\\frac{\\sin[(2m-1)\\pi x]}{(2m-1)\\pi}$$\r\n    So the above discussion instantly yield a solution\r\n    $$y(x)=\\sum_{n=1}^\\infty \\frac{b_n}{\\lambda_n}y_n=4\\sum_{m=1}^\\infty\\frac{\\sin[(2m-1)\\pi x]}{[(2m-1)\\pi]^3}$$\r\n    which is the Fourier series of $y(x)=x(1-x)/2$ on $[0,1)$ extending as an odd periodic function with period $2$.\\\\\r\n    Indeed, as one can verifty, if we integrate $\\mathcal y=1$ directly with the appropriate boundary conditions, we can get basically the same solution.\r\n\\end{example}\r\n\\subsection{A Glimpse into Green's Functions}\r\nFix $L=1$ and consider an odd function $f$.\r\nWe have\r\n\\begin{align*}\r\n    y(x)&=\\sum_{n=1}^\\infty\\frac{b_n}{\\lambda_n}\\sin(\\pi x)\\\\\r\n    &=\\sum_{n=1}^\\infty\\frac{2}{(n\\pi)^2}\\left(\\int_0^1f(\\xi)\\sin(n\\pi\\xi)\\,\\mathrm d\\xi\\right)\\sin(n\\pi x)\\\\\r\n    &=\\int_0^12\\sum_{n=1}^\\infty\\frac{\\sin(n\\pi x)\\sin(n\\pi\\xi)}{(n\\pi)^2}f(\\xi)\\,\\mathrm d\\xi\\\\\r\n    &=\\int_0^1G(x,\\xi)f(\\xi)\\,\\mathrm d\\xi\r\n\\end{align*}\r\nwhere\r\n$$G(x,\\xi)=2\\sum_{n=1}^\\infty\\frac{\\sin(n\\pi x)\\sin(n\\pi\\xi)}{(n\\pi)^2}$$\r\nBut we have seen $G$ before!\r\nIt is exactly the general see-saw wave\r\n$$G(x,\\xi)=\\begin{cases}\r\n    x(1-\\xi)\\text{, for $x\\in[0,\\xi)$}\\\\\r\n    \\xi(1-x)\\text{, for $x\\in[\\xi,1)$}\r\n\\end{cases}$$\r\nThis is the Green's function for this ODE $\\mathcal Ly=f$.\r\nOne can actually solve this integral and get what we got in Example \\ref{odd_sq_fourier_ode}.", "meta": {"hexsha": "5b0a13d70fbb5336d14960651a16a3d2cfb1f896", "size": 17238, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/fourier.tex", "max_stars_repo_name": "david-bai-notes/IB-Methods", "max_stars_repo_head_hexsha": "b60135106d09d1e24d2f7b9c7e3eee1ca69f6907", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1/fourier.tex", "max_issues_repo_name": "david-bai-notes/IB-Methods", "max_issues_repo_head_hexsha": "b60135106d09d1e24d2f7b9c7e3eee1ca69f6907", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1/fourier.tex", "max_forks_repo_name": "david-bai-notes/IB-Methods", "max_forks_repo_head_hexsha": "b60135106d09d1e24d2f7b9c7e3eee1ca69f6907", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.3208955224, "max_line_length": 284, "alphanum_fraction": 0.6794291681, "num_tokens": 5769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.9099070115349838, "lm_q1q2_score": 0.7481156546697746}}
{"text": "\n\\subsection{Fisher information}\n\nThe Fisher information is the variance:\n\n\\(E[(\\dfrac{\\delta }{\\delta \\theta }\\log f(X, \\theta ))^2 |\\theta ]\\)\n\n\\(E[\\dfrac{\\delta^2 }{\\delta \\theta^2 }\\log f(X, \\theta ) |\\theta ]\\)\n\nSame as expectation of score squared, because centred around \\(0\\).\n\n\\subsection{Fisher information matrix}\n\nWe have \\(k\\) parameters.\n\n\\(I(\\theta )_{ij}=E[(\\dfrac{\\delta }{\\delta \\theta_i}\\log f(X, \\theta ))(\\dfrac{\\delta }{\\delta \\theta_j }\\log f(X, \\theta ))|\\theta ]\\)\n\n\\subsection{Observed Fisher information matrix}\n\nThe Fisher information matrix contains informatio about the population\n\nThe observed Fisher infoirmation is the negative of the Hessian of the log likelihood.\n\nWe have:\n\n\\begin{itemize}\n\\item \\(l(\\theta |\\mathbf X)=\\sum_i\\ln P(\\mathbf x_i|\\theta )\\)\n\\item \\(J(\\theta^*)=-\\nabla \\nabla^Tl(\\theta|mathbf X )|_{\\theta = \\theta^*}\\)\n\\end{itemize}\n\nThe Fisher information is the expected value of this.\n\n\\(I(\\theta )=E[J(\\theta)]\\)\n\n\n", "meta": {"hexsha": "4573de68ea6ab13010ee89e64c1478b3b54f419f", "size": 969, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/likelihood/03-01-fisher.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/likelihood/03-01-fisher.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/likelihood/03-01-fisher.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.9166666667, "max_line_length": 136, "alphanum_fraction": 0.6811145511, "num_tokens": 296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.748103775864062}}
{"text": "\n\\section{The Richardson iteration}\n\n\\begin{intro}\n  As a first example and prototype for all other iterative methods we\n  consider Richardson's method, which for matrices and vectors in\n  $\\R^n$ reads\n  \\begin{gather}\n    \\label{eq:richardson:1}\n    \\vec x^{(k+1)}\n    = \\vec x^{(k)}\n    - \\omega_k \\bigl(\\mat A \\vec x^{(k)} - \\vec b \\bigr).\n  \\end{gather}\n  $\\omega_k$ is a relaxation parameter, which can be chosen a priori\n  or can be changed in every step. We will for simplicity assume\n  $\\omega_k = \\omega$.\n\\end{intro}  \n\n\\begin{Lemma}{richardson-error-step}\n  \\label{lemma:richardson:1}\n  The error after one step of the Richardson method is given by\n  \\begin{gather}\n    \\label{eq:richardson:14}\n    \\vec x^{(k+1)} - x = \\mat E \\left(\n      \\vec x^{(k)} - x \\right),\n  \\end{gather}\n  where the \\putindex{error propagation operator} is\n  \\begin{gather}\n    \\label{eq:richardson:15}\n    \\mat E = \\mat I - \\omega \\mat A.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  Using the fact that $\\vec x = \\mat A^{-1} \\vec b$, we write\n  \\begin{gather*}\n    \\vec x^{(k+1)} - \\vec x \n    = \\vec x^{(k)}\n    - \\omega \\bigl(\\mat A \\vec x^{(k)} - \\vec b \\bigr) -  \\vec x^{(k)}\n    =  \\vec x^{(k)} - \\vec x - \\omega \\mat A \\bigl(\n     \\vec x^{(k)} -  \\vec x \\bigr).\n  \\end{gather*}\n\\end{proof}\n\n\\begin{Theorem}{richardson-convergence1}\n  \\label{theorem:richardson:1}\n  If $\\mat A$ is symmetric, positive definite, with extremal\n  eigenvalues $\\lambda>0$ and $\\Lambda>0$, then Richardson's method\n  converges if and only if $0 < \\omega < 2/\\Lambda$. The optimal\n  relaxation parameter is \n  \\begin{gather}\n    \\label{eq:richardson:2}\n    \\omega_{\\text{opt}} = \\frac{2}{\\lambda+\\Lambda},\n  \\end{gather}\n  which yields an optimal contraction rate of\n  \\begin{gather}\n    \\label{eq:richardson:4}\n    \\rho_{\\text{opt}}\n    = 1-\\frac{2\\lambda}{\\lambda+\\Lambda}\n    = \\frac{\\Lambda-\\lambda}{\\Lambda+\\lambda}\n    = \\frac{\\kappa-1}{\\kappa+1}\n    = 1 -\\frac2\\kappa + \\mathcal\n    O\\left(\\kappa^{-2}\\right),\n  \\end{gather}\n  where $\\kappa = \\Lambda/\\lambda$ is the so called \\define{spectral\n    condition number}.\n\\end{Theorem}\n\n\\begin{proof}\n  Convergence of this method is analyzed through the \\putindex{Banach\n    fixed-point theorem}, which requires contraction\n  property of the matrix $\\mat M = \\mat I - \\omega \\mat A$.\n  Alternatively, we studied a theorem that\n  states, that a matrix iteration converges if and only if the\n  spectral radius\n  \\begin{gather*}\n    \\rho(\\mat M) = \\max \\left|\\lambda(\\mat M)\\right| < 1,\n  \\end{gather*}\n  the maximum absolute value of the eigenvalues of $\\mat M$ is\n  strictly less than one.\n  \n  If $\\mat A$ is symmetric, positive definite, with eigenvalues\n  $\\lambda_i > 0$, we have that\n  \\begin{gather}\n    \\label{eq:richardson:13}\n    \\rho(\\mat M) = \\max_i \\left|1-\\omega \\lambda_i\\right|.\n  \\end{gather}\n  Let the extremal eigenvalues be determined by the minimum and\n  maximum of the Rayleigh quotient,\n  \\begin{gather}\n    \\label{eq:richardson:3}\n    \\lambda\n    = \\min_{x\\in \\R^n} \\frac{\\vec x^T\\mat A\\vec x}{\\vec x^T\\vec x},\n    \\qquad\\text{and}\\qquad\n    \\Lambda = \\max_{x\\in \\R^n} \\frac{\\vec x^T\\mat A\\vec x}{\\vec x^T\\vec x}.\n  \\end{gather}\n  Then, equation~\\eqref{eq:richardson:13} yields that the method\n  converges for $0 < \\omega < 2/\\Lambda$. Furthermore, for \n  $1/\\Lambda \\le \\omega \\le 2/\\Lambda$ we have\n  \\begin{gather*}\n    \\rho(\\mat M) = \\max \\bigl\\{ -1+\\omega \\Lambda,  1-\\omega \\lambda \\bigr\\}.\n  \\end{gather*}\n  The optimal parameter $\\omega$ is the one where both values are\n  equal and thus~\\eqref{eq:richardson:2} and~\\eqref{eq:richardson:4} hold.\n\\end{proof}\n\n\\begin{intro}\n  The analysis of finite element methods shows that it is beneficial\n  to give up the focus on finite dimensional spaces and rather use\n  theory that applies to separable Hilbert spaces. If results can\n  obtained in this context, they can easily be restricted to finite\n  dimensional subspaces and thus become uniform with respect to the\n  mesh parameter. Thus, we will first reformulate Richardson's method\n  for this case and then derive convergence estimates.\n\\end{intro}\n\n\\begin{intro}\n  Elements of an abstract Hilbert space $X$ will be denoted by\n  $u,v,w$, etc. On the other hand, coefficient vectors in $\\R^n$ are\n  denoted by letters $\\vec x,\\vec y,\\vec z$, etc.\n\\end{intro}\n\n\\begin{Definition}{richardson-method}\n  Let $X$ be a Hilbert space with inner product $\\scal(.,.)$. Let\n  $a(.,.)$ be a second bilinear form on $X$ and the domain of its\n  operator is $V$. Then, for any right hand\n  side $f\\in V$ and any start vector $u^{(0)}\\in V$,\n  \\define{Richardson's method} is defined by the iteration\n  \\begin{gather}\n    \\label{eq:richardson:5}\n    \\scal(u^{(k+1)},v) = \\scal(u^{(k)},v)\n    - \\omega_k \\bigl(a(u^{(k)},v) - \\scal(f,v)\\bigr), \\qquad \\forall v\\in X.\n  \\end{gather}\n  $\\omega_k$ is a suitable \\putindex{relaxation parameter}, chosen\n  such that the method converges.\n\\end{Definition}\n\n\\begin{intro}\n  The scalar products in~\\eqref{eq:richardson:5} become necessary,\n  since different from the case in $\\R^n$, the result of applying the\n  bilinear form $a(.,.)$ to $u^{(k)}$ in the first argument yields a\n  linear form on $X$. In order to convert this to a vector in $X$, we\n  have to apply the isomorphism induced by the \\putindex{Riesz\n    representation theorem}.\n\\end{intro}\n\n\\begin{Theorem}{richardson-convergence2}\n  \\label{theorem:richardson:2}\n  Let the bilinear form $a(.,.)$ be bounded and elliptic on $X\\times\n  X$, namely, let there exist positive constants $\\Lambda$ and $\\lambda$ such\n  that for all $u,v\\in X$ there holds\n  \\begin{gather}\n    \\label{eq:richardson:6}\n    a(u,v) \\le \\Lambda \\norm{u} \\norm{v},\n    \\qquad\n    a(u,u) \\ge \\lambda \\norm{u}^2.\n  \\end{gather}\n  Then, Richardson's iteration converges for\n  $\\omega_k = \\omega$ for any $\\omega \\in (0, 2\\lambda/\\Lambda^2)$.\n\\end{Theorem}\n\n\\begin{proof}\n  We define the iteration operator $T$ as the solution operator of\n  equation~\\eqref{eq:richardson:5}, namely $T u^{(k)} := u^{(k+1)}$. We\n  have to prove that $T$ is a contraction on $X$ under the assumptions\n  of the theorem.\n\n  For two arbitrary vectors $u^1, u^2 \\in X$, let $w = u^1-u^2$ be\n  their difference. Due to linearity, we have $T w = T u^1-T u^2$ and\n  \\begin{gather*}\n    \\scal(T w,v) = \\scal(w,v) - \\omega a(w,v) = \\scal(w-\\omega A w,v).\n  \\end{gather*}\n  Using $v=Tw$ as a test function, we obtain\n  \\begin{align*}\n    \\norm{Tw}^2\n    & = \\scal(w-\\omega A w,w-\\omega A w) \\\\\n    &= \\norm{w}^2 - 2\\omega a(w,w) + \\omega^2 \\norm{Aw}^2\\\\\n    & \\le \\norm{w}^2 - 2\\lambda\\omega \\norm{w}^2\n    +  \\Lambda^2 \\omega^2\\norm{w}^2\\\\\n    & = \\underbrace{\\bigl(1-2\\lambda\\omega\n      + \\Lambda^2\\omega^2\\bigr)}_{=:\\rho(\\omega)} \\norm{w}^2.\n  \\end{align*}\n  The function $\\rho(\\omega)$ is a parabola open to the top, which\n  at zero equals one and has a negative derivative. Thus, it is less\n  than one for small positive valuers of $\\omega$. The other\n  point where $\\rho(\\omega) = 1$ is $\\omega = 2\\lambda/\\Lambda^2$.\n\\end{proof}\n\n\\begin{remark}\n  The condition on $\\omega$ in Theorem~\\ref{theorem:richardson:2} is\n  more restrictive than in Theorem~\\ref{theorem:richardson:1}, since\n  $\\lambda/\\Lambda \\le 1$. This is\n  due to the fact, that in Theorem~\\ref{theorem:richardson:1} we\n  assume symmetry, and thus orthogonal diagonalizability of the matrix\n  $\\mat A$. With similar assumptions,\n  Theorem~\\ref{theorem:richardson:2} could be made sharper.\n\\end{remark}\n\n\\begin{remark}\n  It is clear that the boundedness and ellipticity\n  estimates~\\eqref{eq:richardson:6} hold for any finite dimensional\n  subspace $X_n\\subset X$, and thus the convergence\n  estimate~\\eqref{eq:richardson:4} becomes independent of $n$.\n  \n  More interesting and also more common is the case where the bilinear form\n  $a(.,.)$ is unbounded on $X$. While it is still bounded on each\n  finite subspace $X_n$, this bound cannot be independent of $n$ if\n  the sequence $\\{X_n\\}$ approximates $X$.\n\\end{remark}  \n\n\\begin{Definition}{riesz-isomorphism}\n  We define an operator $B:X\\to X^*$ such that $Bu = b(u,.) :=\n  \\scal(u,.)$. By the Riesz representation theorem, there is a\n  continuous inverse operator $B^{-1}: X^*\\to X$, which is often\n  called \\define{Riesz isomorphism}.\n\\end{Definition}\n\n\\begin{Definition}{p-richardson-method}\n  \\label{definition:richardson:2}\n  When we apply Richardson's method as in~\\eqref{eq:richardson:5} on a\n  computer, each step involves a multiplication with the matrix $\\mat A$,\n  but an inversion of the matrix $\\mat B$, corresponding to the iteration\n  \\begin{gather*}\n    \\mat B \\vec x^{(k+1)}\n    = \\mat B \\vec x^{(k)}\n    - \\omega_k \\bigl(\\mat A \\vec x^{(k)} - \\vec b \\bigr),\n  \\end{gather*}\n  or equivalently,\n  \\begin{gather}\n    \\label{eq:richardson:7}\n    \\vec x^{(k+1)}\n    = \\vec x^{(k)}\n    - \\omega_k \\mat B^{-1}\\bigl(\\mat A \\vec x^{(k)} - \\vec b \\bigr).\n  \\end{gather}\n\\end{Definition}\n\n\\begin{remark}\n  The iteration in~\\eqref{eq:richardson:7} is commonly referred to as\n  \\define{preconditioned Richardson iteration} and $\\mat B^{-1}$ as the\n  \\define{preconditioner}. Note that by introducing the iteration in\n  its weak form~\\eqref{eq:richardson:5}, the preconditioner arrives\n  naturally and with necessity.\n  \n  The goal of this chapter is finding preconditioners $\\mat B^{-1}$, or\n  equivalently inner products $\\scal(.,.)$, such that the bilinear\n  form $a(.,.)$ is bounded and the condition number\n  $\\kappa = \\Lambda/\\lambda$ is small.\n  \n  In order to reduce (or increase) confusion, we will refer to the\n  inner product that we search in order to bound the condition number\n  as $b(.,.)$ instead of $\\scal(.,.)$, this way separating the\n  Hilbert space $X$ more clearly from the task of\n  preconditioning. Thus, the operator $B$ and the matrix $\\mat B$ will\n  be associated with a bilinear form $b(.,.)$ and the final version of\n  the preconditioned Richardson iteration is\n  \\begin{gather}\n    \\label{eq:richardson:10}\n    b(u^{(k+1)},v) = b(u^{(k)},v)\n    - \\omega_k \\bigl(a(u^{(k)},v) - f(v)\\bigr), \\qquad \\forall v\\in X,\n  \\end{gather}\n  or in operator form\n  \\begin{gather}\n    \\label{eq:richardson:11}\n    u^{(k+1)} = u^{(k)} - \\omega_k B^{-1} (A u^{(k)} - f).\n  \\end{gather}  \n\\end{remark}\n\n\\begin{remark}\n  The space $X$ and is inner product does not appear anymore in this\n  formulation, since the bilinear form $b(.,.)$ has replaced\n  it. Thus, finding a preconditioner also amounds to changing the\n  space in which we iterate. This is reflected by the following:\n\\end{remark}\n\n\\begin{corollary}\n  Let the symmetric bilinear forms $a(.,.)$ and $b(.,.)$ in the\n  Richardson iteration~\\eqref{eq:richardson:10} be both bounded and\n  positive definite on the\n  same space $V$ and fulfill the\n  \\define{spectral equivalence} relation\n  \\begin{gather}\n    \\label{eq:richardson:12}\n    \\lambda b(u,u) \\le a(u,u) \\le \\Lambda b(u,u), \\quad \\forall u\\in V.\n  \\end{gather}\n  Then, if $\\omega_k \\equiv \\omega \\in (0,2\\Lambda)$, the iteration is\n  a contraction on $V$. The optimal contraction number is $\\rho$\n  according to equation~\\eqref{eq:richardson:4} for $\\omega$ chosen as\n  in~\\eqref{eq:richardson:2}.\n\\end{corollary}\n\n\\begin{proof}\n  This corollary is equivalent to Theorem~\\ref{theorem:richardson:2}\n  if the inner product $\\scal(.,.)$ is replaced by the bilinear form\n  $b(.,.)$.\n\\end{proof}\n\n\\begin{remark}\n  Originally, the space $V$ was chosen as the domain of $A$ which\n  essentially meant $V \\subset H^2(\\Omega)$, since we required $Av \\in\n  X$. An additional benefit of the preconditioned version is, that now\n  $V \\subset H^1(\\Omega)$ is sufficient and at least here no\n  regularity assumption is required.\n\\end{remark}\n\n\\begin{notation}\n  \\index{lambdaBA@$\\lambda(B,A)$}\n  \\index{Lambdaba@$\\Lambda(B,A)$}\n  In order to distinguish different preconditioners, we will also us\n  the notation $\\lambda(B,A)$ and $\\Lambda(B,A)$ to refer to the\n  constants in the norm equivalence~\\eqref{eq:richardson:12}.\n\\end{notation}\n\n\n\\begin{example}\n  Let us take the example~\\eqref{eq:itintro:1}.\n  By the Poincaré-Friedrichs inequality, $a(.,.)$ is an inner product\n  on $X$ and thus we can choose $\\scal(.,.) = a(.,.)$. In\n  particular, $\\lambda = \\Lambda = 1$ and the optimal choice is\n  $\\omega = 1$. Then, Richardson's iteration becomes\n  \\begin{gather*}\n    a(u^{(k+1)},v) = a(u^{(k)},v)\n    - \\bigl(a(u^{(k)},v) - f(v)\\bigr) =  f(v), \\qquad \\forall v\\in X,\n  \\end{gather*}\n  which converges in a single step, but we have to solve the original\n  equation for $u$. Thus, either the inversion of the matrix $A_n$ is\n  trivial on each finite dimensional subspace $X_n$, or the method is\n  useless. With usual finite element bases, the latter is true.\n\\end{example}\n\n\\begin{example}\n  In the other extreme, we would like to use the $\\R^n$ or $L^2$\n  inner product on $X_n$ or $X$, such that the Riesz isomorphism is\n  easily computable. But then, the bilinear form $a(.,.)$ is unbounded\n  on $X$. Thus, while for each finite $n$, the condition number\n  $\\kappa_n = \\Lambda_n/\\lambda_n$ exists, it converges to infinity if\n  $n\\to\\infty$.\n\\end{example}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End: \n", "meta": {"hexsha": "80c6cb1e3d87409484000c8f4c28288bb3068b43", "size": 13150, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "iteration/richardson.tex", "max_stars_repo_name": "ahumanita/notes", "max_stars_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "iteration/richardson.tex", "max_issues_repo_name": "ahumanita/notes", "max_issues_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-05-24T07:31:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-31T12:58:14.000Z", "max_forks_repo_path": "iteration/richardson.tex", "max_forks_repo_name": "ahumanita/notes", "max_forks_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-05-15T19:28:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-05T19:07:29.000Z", "avg_line_length": 38.3381924198, "max_line_length": 77, "alphanum_fraction": 0.6707224335, "num_tokens": 4326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789132480439, "lm_q2_score": 0.9230391568941467, "lm_q1q2_score": 0.7481037727649588}}
{"text": "\\subsection{Open Delta Neighborhoods}\r\n\\noindent\r\nAn open delta neighborhood of a point $x_0$ is defined as the set\r\n\\begin{equation*}\r\n\tN\\left(x_0, \\delta\\right) = \\left\\{x \\in \\mathbb{R}^n \\mid \\norm{x-x_0} < \\delta\\right\\}\r\n\\end{equation*}\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nThis simply means all points less than a distance $\\delta$ away from $x_0$.\\\\\r\nFor example, $N(\\langle 1, 2\\rangle, 7) = \\left\\{ (x,y) \\mid \\sqrt{(x-1)^2 + (y-2)^2}<7 \\right\\}$, which is a ball (filled-in circle) of radius 7 centered at $(1, 2)$.", "meta": {"hexsha": "1ec2ee840ee3be042ef7716fe443ec70b763e1f7", "size": 521, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/openDeltaNeighborhoods.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/openDeltaNeighborhoods.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/openDeltaNeighborhoods.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.4166666667, "max_line_length": 167, "alphanum_fraction": 0.6583493282, "num_tokens": 190, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7481003215093335}}
{"text": "\n\n    \\filetitle{difflog}{First log-difference pseudofunction}{modellang/difflog}\n\n\t\\paragraph{Syntax}\\label{syntax}\n\n\\begin{verbatim}\ndifflog(Expr)\ndifflog(Expr,K)\n\\end{verbatim}\n\n\\paragraph{Description}\\label{description}\n\nIf the input argument \\texttt{K} is not specified, this pseudofunction\nexpands to\n\n\\begin{verbatim}\n(log(Expr)-log(Expr{-1}))\n\\end{verbatim}\n\nIf the input argument \\texttt{K} is specified, it expands to\n\n\\begin{verbatim}\n(log(Expr)-log(Expr{K}))\n\\end{verbatim}\n\nThe two derived expressions, \\texttt{Expr\\{-1\\}} and \\texttt{Expr\\{K\\}},\nare based on \\texttt{Expr}, and have all its time subscripts shifted by\n--1 or by \\texttt{K} periods, respectively.\n\n\\paragraph{Example}\\label{example}\n\nThe following two lines of code\n\n\\begin{verbatim}\ndifflog(Z)\ndifflog(X{1}/Y{-1},-2)\n\\end{verbatim}\n\nwill expand to\n\n\\begin{verbatim}\n(log(Z)-log(Z{-1}))\n(log(X{1}/Y{-1})-log(X{-1}/Y{-3}))\n\\end{verbatim}\n\n\n", "meta": {"hexsha": "a988ba6c789fd280013d3ee8dc0b0374a7575acf", "size": 918, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "-help/modellang/difflog.tex", "max_stars_repo_name": "OGResearch/IRIS-Toolbox-For-Octave", "max_stars_repo_head_hexsha": "682ea1960229dc701e446137623b120688953cef", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-12-06T13:38:38.000Z", "max_stars_repo_stars_event_max_datetime": "2017-12-06T13:38:38.000Z", "max_issues_repo_path": "-help/modellang/difflog.tex", "max_issues_repo_name": "OGResearch/IRIS-Toolbox-For-Octave", "max_issues_repo_head_hexsha": "682ea1960229dc701e446137623b120688953cef", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-03-28T08:13:20.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-02T10:40:25.000Z", "max_forks_repo_path": "-help/modellang/difflog.tex", "max_forks_repo_name": "OGResearch/IRIS-Toolbox-For-Octave", "max_forks_repo_head_hexsha": "682ea1960229dc701e446137623b120688953cef", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-17T07:06:39.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-17T07:06:39.000Z", "avg_line_length": 19.125, "max_line_length": 79, "alphanum_fraction": 0.7156862745, "num_tokens": 287, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147438, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7481003215093334}}
{"text": "\\subsection{Topological groups}\\label{subsec:topological_groups}\n\n\\begin{definition}\\label{def:topological_group}\n  Let \\( G \\) be any \\hyperref[def:group]{group} and let \\( \\mscrT \\) be a topology on \\( G \\). The tuple \\( (G, \\cdot, \\mscrT) \\) is called a \\term{topological group} if the group structure and topological structure agree, that is, the operations \\( \\cdot: X \\times X \\to X \\) and \\( (-)^{-1}: X \\to X \\) are continuous with respect to \\( \\mscrT \\).\n\n  See \\fullref{rem:hausdorff_topological_groups} and \\fullref{def:category_of_topological_groups} for more nuances.\n\\end{definition}\n\n\\begin{remark}\\label{rem:hausdorff_topological_groups}\n  It is conventional to require the topology in a topological group to be \\( T_1 \\) (see \\fullref{def:separation_axioms}). We will not do this due to our goal of not assuming more than is necessary.\n\n  Due to \\fullref{thm:topological_group_t0_iff_t3.5}, it is immaterial whether we require the topology to be \\( T_0 \\) or \\( T_{3.5} \\) or anywhere in between. It is customary to call the space \\enquote{Hausdorff} (although stronger separation axioms actually hold) and require \\( T_1 \\) to hold (since it is simple to state).\n\n  We will explicitly mention when we want a topological group to be Hausdorff. This is usually, so when we speak of convergence.\n\\end{remark}\n\n\\begin{definition}\\label{def:category_of_topological_groups}\n  The category \\( \\cat{TopGrp} \\) of topological groups is a subcategory of both \\( \\cat{Top} \\) and \\( \\cat{Grp} \\). Its morphisms are the \\hyperref[def:global_continuity]{continuous} group \\hyperref[thm:group_homomorphism_single_condition]{homomorphisms}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:neighborhood_translations_in_topological_groups}\n  Fix \\( x, y \\in G \\) in a topological group \\( G \\). If \\( U \\) is a neighborhood of \\( x \\), then both \\( V = yx^{-1} U \\) and \\( W = U x^{-1}y \\) are neighborhoods of \\( y \\).\n\\end{proposition}\n\\begin{proof}\n  Since the group operations are continuous, for fixed \\( x \\) and \\( y \\), the function \\( f(z) \\coloneqq xy^{-1}z \\) is continuous.\n\n  Note that \\( U = f(V) \\), hence \\( V \\) is the preimage of \\( U \\) under \\( f \\) and it follows from the continuity of \\( f \\) that \\( V \\) is open.\n\n  Since \\( x \\in U \\), \\( yx^{-1}x = ye = y \\in V \\). Therefore, \\( V \\) is a neighborhood of \\( y \\).\n\n  The proof that \\( W \\) is a neighborhood of \\( y \\) is analogous.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:origin_neighborhoods_in_topological_groups}\n  In a topological group \\( G \\), every neighborhood is a translation of e neighborhood of the origin \\( e \\).\n\\end{corollary}\n\n\\begin{remark}\\label{rem:origin_neighborhoods_in_topological_groups}\n  \\Fullref{thm:origin_neighborhoods_in_topological_groups} provides a lot of uniformity by allowing us to only consider neighborhoods of zero when working with topological groups.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:topological_group_t0_iff_t3.5}\n  If a topological group is \\( T_0 \\), it is automatically \\( T_{3.5} \\).\n\\end{proposition}\n\n\\begin{proposition}\\label{thm:topological_group_uniform_space}\n  A Hausdorff topological group \\( G \\) can be made into a uniform space by the families of entourages\n  \\begin{balign*}\n     & V^l_A \\coloneqq \\{ (x, y) \\in G \\times G \\colon x^{-1} y \\in A \\}, \\\\\n     & V^r_A \\coloneqq \\{ (x, y) \\in G \\times G \\colon x y^{-1} \\in A \\},\n  \\end{balign*}\n  where \\( A \\) is a \\hyperref[def:neighborhood_set_types/symmetric]{symmetric} neighborhood of the origin \\( e \\).\n\n  If \\( G \\) is abelian, the two families of entourages coincide.\n\\end{proposition}\n\n\\begin{proposition}\\label{thm:limits_are_topological_group_homomorphisms}\n  If \\( \\{ a_\\alpha \\}_{\\alpha \\in \\mscrK} \\) and \\( \\{ b_\\alpha \\}_{\\alpha \\in \\mscrK} \\) are \\hyperref[def:topological_net]{nets} in a Hausdorff topological group \\( X \\) that converge to \\( a \\) and \\( b \\), correspondingly, then \\( a_\\alpha b_\\alpha \\to a b \\).\n\\end{proposition}\n\\begin{proof}\n  Special case of \\fullref{thm:linearity_of_sequence_limits}.\n\\end{proof}\n", "meta": {"hexsha": "77484afa6e3fd2268cf5ce64a53666e3ee6506b2", "size": 4042, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/topological_groups.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/topological_groups.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/topological_groups.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.1587301587, "max_line_length": 350, "alphanum_fraction": 0.7063334983, "num_tokens": 1233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.8740772286044095, "lm_q1q2_score": 0.7480799922115878}}
{"text": "\n\\sec{Higher order linear ODEs - linear algebra}\nThis section has more theory as compared to the other sections. However, these are some key concepts that must be known.\\\\\n\\subsection{Solutions}\nIn this section, we shall be considering equations of the following form.\n\\begin{defn}[Linear ODE]\n\tAn ordinary differential equation of the form\n\t\\begin{equation} \\label{eq:lininhom}\n\t\ty^{(n)} + p_{n-1}(x)y^{(n-1)} + \\cdots + p_1(x)y^{(1)} + p_0(x)y = r(x)\n\t\\end{equation}\n\tis a \\defin{linear ODE} of $n^{\\text{th}}$ order.\n\\end{defn}\nWe shall be assuming that all the $p_j$s are continuous on an open interval $I \\subset \\mathbb{R}.$\\\\\nNote very carefully that the coefficient of $y^{(n)}$ is assumed to be $1.$ (This could have been replaced with any nonzero constant.)\\\\\nThe ODE (\\ref{eq:lininhom}) is said to be \\defin{homogeneous} iff $r \\equiv 0,$ that is, $r(x) = 0$ for all $x \\in I.$\\\\\nGiven such a linear ODE, we have the \\defin{associated homogeneous linear ODE} defined as\n\\begin{equation} \\label{eq:linhom}\n\ty^{(n)} + p_{n-1}(x)y^{(n-1)} + \\cdots + p_1(x)y^{(1)} + p_0(x)y = 0.\n\\end{equation}\n\nNow, we make the following observation:\n\n\\begin{mdframed}[style=boxstyle, frametitle={}]\n\tIf $y_g(x)$ is the \\emph{general} solution of (\\ref{eq:linhom}) and $y_p(x)$ is a \\emph{particular} solution of (\\ref{eq:lininhom}), then\n\t\\[y_p(x) + y_g(x)\\]\n\tis the general solution of (\\ref{eq:lininhom}).\n\\end{mdframed}\n(Compare the above with what you saw in MA 106 regarding the null-space of $A$ and a particular solution of $A\\mathbf{x} = \\mathbf{b}$.)\n\n\\subsection{Dimensions}\nRecall the vector space of functions from $\\mathbb{R}$ to $\\mathbb{R}$. Let $V$ denote the set of functions which are solutions of (\\ref{eq:linhom}). It can be verified that $V$ is a vector space with the usual addition and scalar multiplication. (We use the fact that the ODE is homogeneous.)\n\\begin{thm} \n\t\\[\\dim V = n.\\] \n\tTo elaborate, the dimension of the solution space of\n\t\\[y^{(n)} + p_{n-1}(x)y^{(n-1)} + \\cdots + p_0(x)y = 0\\]\n\tis equal to $n.$\n\\end{thm}\n\n\\subsection{Linear independence and the Wronskian}\nWe recall the following from Linear Algebra.\n\\begin{defn}[Linear Independence]\n\tLet $f_1, \\ldots, f_n:I \\to \\mathbb{R}$ be functions defined on some open interval $I.$ The functions are said to be \\defin{linearly dependent} if there exist real numbers $a_1, \\ldots, a_n$ \\textbf{not all zero} such that\n\t\\[a_1f_1(x) + \\cdots + a_nf_n(x) = 0 \\quad \\forall x \\in I.\\]\n\tThe functions are said to be \\defin{linearly independent} if they are not linearly dependent.\n\\end{defn}\n\\begin{mdframed}[style=boxstyle, frametitle={A rephrasing}]\n\tIn other words, the functions are linearly independent if\n\t\\[a_1f_1(x) + \\cdots + a_nf_n(x) = 0 \\quad \\forall x \\in I\\]\n\timplies $a_1 = \\cdots = a_n = 0.$\\\\\n\tIn yet another words, their linear combination being identically zero is possible if and only if every scalar is $0.$\n\\end{mdframed}\n\\begin{defn}[Wronskian]\n\tLet $f_1, \\ldots, f_n:I \\to \\mathbb{R}$ be sufficiently differentiable functions defined on some open interval $I.$ Their \\defin{Wronskian} is another function defined on $I$ as:\n\t\\[W(f_1, \\ldots, f_n)(x) := \\det\\begin{bmatrix}\n\t\tf_1(x) & f_2(x) & \\ldots & f_n(x)\\\\\n\t\tf_1'(x) & f_2'(x) & \\ldots & f_n'(x)\\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots\\\\\n\t\tf_1^{(n-1)}(x) & f_2^{(n-1)}(x) & \\ldots & f_n^{(n-1)}(x)\\\\\n\t\\end{bmatrix}.\\]\n\\end{defn}\n\\exercise{%\n\\begin{enumerate}[leftmargin=*]\n\t\\item Show that if $f_1, \\ldots, f_n$ are linearly dependent, then their Wronskian is identically zero. This can be written as $W(f_1, \\ldots, f_n) \\equiv 0.$\n\t\\item Show that the converse is not true.\n\\end{enumerate}\n}\nWe now state a case when the converse \\emph{\\textbf{is}} true.\n\\begin{thm} \n\tIf $y_1(x), \\ldots, y_n(x)$ are solutions of a linear homogeneous ODE as (\\ref{eq:linhom}), then they are linearly dependent if and only if $W(y_1, \\ldots, y_n) \\equiv 0.$\n\\end{thm}\n\\begin{mdframed}[style=boxstyle, frametitle={A particular application}]\n\tSuppose $y_1$ and $y_2$ are solutions of\n\t\\[y'' + P(x)y' + Q(x)y = 0\\]\n\tover an open interval $I \\subset \\mathbb{R}.$ Let $a \\in I$ be such that\n\t\\[y_1(a) = 0, y_1'(a) = 1,\\quad y_2(a) = 1, y_2'(a) = 0.\\]\n\tThen, any other solution of the ODE is given by\n\t\\[c_1y_1(x) + c_2y_2(x).\\]\n\\end{mdframed}\nThe hypothesis tells us that $y_1$ and $y_2$ are two linearly independent solutions of the ODE. As the dimension of the solution space is $2,$ the functions must form a basis.\n\\begin{mdframed}[style=boxstyle, frametitle={A result}]\n\tSuppose $y_1$ and $y_2$ are solutions of\n\t\\[y'' + P(x)y' + Q(x)y = 0\\]\n\tover an open interval $I \\subset \\mathbb{R}.$ Let $a \\in I$ be such that\n\t\\[y_1(a) = y_2(a),\\quad y_1'(a) =y_2'(a).\\]\n\tThen, $y_1 = y_2.$\n\\end{mdframed}\nThis is to say that if two functions satisfy an ODE and have the same initial conditions, then they are identically equal.\n\\exercise{%\nShow that the following sets of functions are linearly independent on $\\mathbb{R}$ (unless otherwise mentioned):\n\\begin{enumerate}[leftmargin=*]\n\t\\item $\\{1, x, \\ldots, x^n\\}.$\n\t\\item $\\{e^{m_1x}, \\ldots, e^{m_nx}\\}$ where $m_1, \\ldots, m_n$ are distinct real numbers.\n\t\\item $\\{e^{mx}, xe^{mx}, \\ldots, x^ne^{mx}\\}.$\n\t\\item $\\{\\sin x, \\sin 2x, \\ldots, \\sin nx\\}.$ (Wronskian could get quite messy. Try integration. Recall inner products.)\n\t\\item $\\{x^m, x^m(\\ln x), \\ldots, x^m(\\ln x)^n\\}.$ Show that this is linearly independent on $(0, \\infty).$\n\\end{enumerate}\n}\n\n\\newpage\n\n\\subsection{Abel-Liouville Formula}\n\\begin{mdframed}[style=boxstyle, frametitle={The formula}]\n\tSuppose $y_1, \\ldots, y_n$ are solutions of\n\t\\[y^{(n)} + P_1(x)y^{(n-1)} + \\cdots + P_n(x)y = 0\\]\n\tover an open interval $I \\subset \\mathbb{R}.$\\\\\n\tLet $W$ denote their Wronskian.\tThen,\n\t\\[\\dfrac{dW}{dx} = -P_1(x)W.\\]\n\tHence, we have\n\t\\[W(x) = W(x_0)\\exp\\left(-\\int_{x_0}^{x} p(t) dt\\right)\\]\n\\end{mdframed}\n(Note that here, $P_1$ is the coefficient of $y^{(n-1)}$ and not $y'$.)\n\n\\begin{cor} \\label{cor:wronskian}\n\tThe above formula shows that either $W \\equiv 0$ or that the Wronskian \\textbf{never} vanishes. (In fact, it never changes sign.)\n\\end{cor}\n\n\n\\begin{mdframed}[style=boxstyle, frametitle={An application}]\n\tSuppose $y_1$ is a solution of \n\t\\[y'' + P(x)y' + Q(x)y = 0.\\]\n\tThen, a second \\emph{linearly independent} solution is given by\n\t\\[y_2(x) = y_1(x)\\int \\dfrac{1}{(y_1(x))^2}\\exp\\left(-\\int P(x) dx\\right) dx.\\]\n\\end{mdframed}", "meta": {"hexsha": "f16456419412ac29b6336bafacccfa96bdb1415a", "size": 6385, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tuts/ma-108/summary/linal.tex", "max_stars_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_stars_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-12-17T20:34:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T09:58:57.000Z", "max_issues_repo_path": "tuts/ma-108/summary/linal.tex", "max_issues_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_issues_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-03-04T10:23:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-28T10:29:01.000Z", "max_forks_repo_path": "tuts/ma-108/summary/linal.tex", "max_forks_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_forks_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-08-30T18:19:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-17T12:09:09.000Z", "avg_line_length": 51.9105691057, "max_line_length": 293, "alphanum_fraction": 0.6767423649, "num_tokens": 2342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.8976953016868439, "lm_q1q2_score": 0.7480715888553193}}
{"text": "\\chapter{Tetrahedral Quality Metrics}\n\nAll the metrics in this section are defined on a tetrahedral element with vertices\nshown in Figure~\\ref{f:tet}. Furthermore, we define the following edge vectors for\nconvenience\n\\begin{equation*}\n\\begin{array}{lcl}\n\\vec L_0 &=& \\vec P_1 - \\vec P_0\\\\\n\\vec L_1 &=& \\vec P_2 - \\vec P_1\\\\\n\\vec L_2 &=& \\vec P_0 - \\vec P_2\n\\end{array}\\rule{10em}{0pt}\n\\begin{array}{lcl}\n\\vec L_3 &=& \\vec P_3 - \\vec P_0\\\\\n\\vec L_4 &=& \\vec P_3 - \\vec P_1\\\\\n\\vec L_5 &=& \\vec P_3 - \\vec P_2\n\\end{array}.\n\\end{equation*}\n\n\\begin{figure}[htb]\n  \\begin{center}\n    \\includegraphics[height=2.0in]{tet}\n    \\caption{Vertices of a tetrahedron.%\n                                                                  \\label{f:tet}}\n  \\end{center}\n\\end{figure}\n\nThe tetrahedron edge lengths are denoted as follows:\n\\[\nL_0 = \\normvec{L_0}\\quad\nL_1 = \\normvec{L_1}\\quad\nL_2 = \\normvec{L_2}\\quad\nL_3 = \\normvec{L_3}\\quad\nL_4 = \\normvec{L_4}\\quad\nL_5 = \\normvec{L_5}\n\\]\nand the largest and smallest edge lengths are, respectively,\n\\[\nL_{\\min} = \\min\\left(L_0, L_1, L_2, L_3, L_4, L_5\\right)\n  \\rule{2em}{0pt}\nL_{\\max} = \\max\\left(L_0, L_1, L_2, L_3, L_4, L_5\\right)\n\\]\n\nThe volume can then be defined in terms of the edge vectors as\n\\begin{equation*}\nV = \\frac{\\left(\\vec L_2\\times\\vec L_0\\right)\\cdot\\vec L_3 }{6}.\n\\end{equation*}\n\nIn addition, we will respectively denote $R$ and $r$ the circumradius\nand the inradius of the tetrahedron, \\emph{i.e.}, respectively, the radii\nof the circumscribed and inscribed spheres of this tetrahedron.\nNote that the inradius is\n\\[\n r = \\frac { 3V } { A }\n\\]\nwhere $A$ is the  surface area of the tetrahedron:\n\\[\nA = \\frac{1}{2} \\left(\n      \\normvec{L_2 \\times \\vec L_0} + \n      \\normvec{L_3 \\times \\vec L_0} + \n      \\normvec{L_4 \\times \\vec L_1} + \n      \\normvec{L_3 \\times \\vec L_2}  \\right),\n\\]\nand that the the circumradius is\n\\[\n R = \\frac {\\Big\\lVert\n   \\normvec{L_3}^2 \\left( \\vec L_2 \\times \\vec L_0 \\right) + \n   \\normvec{L_2}^2 \\left( \\vec L_3 \\times \\vec L_0 \\right) + \n   \\normvec{L_0}^2 \\left( \\vec L_3 \\times \\vec L_2 \\right)\n   \\Big\\rVert}{12 V }. \n\\]\n\nSometimes, we will to refer to the edge vectors indexed by their endpoints:\n\\begin{equation*}\n\\begin{array}{lcl}\n\\vec L_{01} &=& \\vec L_0\\\\\n\\vec L_{12} &=& \\vec L_1\\\\\n\\vec L_{20} &=& \\vec L_2\n\\end{array}\\rule{10em}{0pt}\n\\begin{array}{lcl}\n\\vec L_{03} &=& \\vec L_3\\\\\n\\vec L_{13} &=& \\vec L_4\\\\\n\\vec L_{23} &=& \\vec L_5\n\\end{array}\n\\end{equation*}\n\n% -------------------Metric Table-------------------\n\\newcommand{\\tetmetrictable}[8]{%\n  \\begin{center}\n  \\begin{tabular}{ll}\n    \\multicolumn{2}{r}{\\textbf{\\sffamily\\Large tetrahedral #1}}\\\\\\hline\n    Dimension:                            & #2\\\\ \n    Acceptable Range:                     & #3\\\\ \n    Normal Range:                         & #4\\\\ \n    Full Range:                           & #5\\\\ \n    $q$ for unit equilateral tetrahedron: & #6\\\\\n    Reference:                            & #7\\\\\n    \\verd\\ function:       & \\texttt{#8}\\\\ \\hline\n  \\end{tabular} \n  \\end{center}\n}\n\\clearpage\n\\newpage \\input{TetEdgeRatio}\n\\newpage \\input{TetAspectBeta}\n\\newpage \\input{TetAspectDelta}\n\\newpage \\input{TetAspectFrobenius}\n\\newpage \\input{TetAspectGamma}\n\\newpage \\input{TetAspectRatio}\n\\newpage \\input{TetCollapseRatio}\n\\newpage \\input{TetCondition}\n\\newpage \\input{TetDistortion}\n\\newpage \\input{TetJacobian}\n\\newpage \\input{TetMinimumAngle}\n\\newpage \\input{TetRadiusRatio}\n\\newpage \\input{TetRelativeSizeSquared}\n\\newpage \\input{TetScaledJacobian}\n\\newpage \\input{TetShape}\n\\newpage \\input{TetShapeAndSize}\n\\newpage \\input{TetVolume}\n", "meta": {"hexsha": "af738a005de81d9a4fccff4d671cdd95fd6a576c", "size": 3590, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/Tet.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-01-07T20:50:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-29T18:22:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/Tet.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/Tet.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 30.1680672269, "max_line_length": 82, "alphanum_fraction": 0.6295264624, "num_tokens": 1334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7480715649966211}}
{"text": "\\chapter{Frequency Selective Filters in DT}\n\nRecall the response of stable DT LTI systems to periodic inputs. Given a stable LTI system with frequency response $H\\left(e^{j\\omega}\\right)$ the input-output relationship is\n\n\\[\nx[n] = \\sum\\limits_{k = N_0}^{N_0 + N-1} a_k e^{jk\\omega_0n} \\longrightarrow y[n] = \\sum\\limits_{k = N_0}^{N_0 + N-1} a_k H\\left(e^{jk\\omega_0}\\right) e^{jk\\omega_0n} \n\\]\n\nNote the output is equivalent to a signal with Fourier series coefficients $b_k = a_k H\\left(e^{jk\\omega_0}\\right)$. That is the Fourier coefficients are scaled by the frequency response at the harmonic frequency $k\\omega_0$.\n\nSimilarly for aperiodic signals, given a stable LTI system with frequency response $H\\left(e^{j\\omega}\\right)$ the input-output relationship is\n\\[\nx[n] = \\frac{1}{2\\pi} \\int_{2\\pi} X\\left(e^{j\\omega}\\right) e^{j\\omega n} \\; d\\omega \\longrightarrow y[n] = \\frac{1}{2\\pi} \\int_{2\\pi} X\\left(e^{j\\omega}\\right)H\\left(e^{j\\omega}\\right) e^{j\\omega n} \\; d\\omega\n\\]\nNote the output is equivalent to a signal with DT Fourier Transform $Y\\left(e^{j\\omega}\\right) = X\\left(e^{j\\omega}\\right) H\\left(e^{j\\omega}\\right)$. That is the Fourier transform at each continuous frequency $\\omega$ is scaled by the frequency response at that frequency. \n\nAs in CT, we can design the frequency response to modify the values of $a_k$ or $X\\left(e^{j\\omega}\\right)$ selectively, passing them unmodified, increasing (amplifying) them, or decreasing (attenuating) them. Such systems are called DT filters (or more colloquially digital filters). As in CT there are 4 basic types:\n\\begin{itemize}\n\\item Low-pass Filters attenuate high frequencies while passing through lower frequencies. They are often used to reduce the effects of high-frequency noise in a signal.\n\\item High-pass Filters attenuate lower frequencies while passing through higher frequencies. They are used, for example, to select high-frequency audio components in high-end audio systems.\n\\item Bandpass Filters attenuate frequencies outside a band of frequencies. They can be viewed as a combination of a high-pass and low-pass filter. They are commonly used to select a range of frequencies for further processing and are central to many communication technologies. \n\\item Notch or Bandstop Filters attenuate frequencies inside an often narrow band of frequencies. Common applications are the removal of one or more corrupting signals mixed into another signal.\n\\end{itemize}\n\nWhile the design of such filters is outside the scope of this course, you are now equipped to understand and apply them based on your knowledge of the Fourier methods covered over the past several weeks. This is similar to CT filtering, with the important exception that the frequency domain is periodic in $2\\pi$ for DT systems, so the filter frequency responses are periodic as well, with all the work being done in a range of frequencies from $(0,2\\pi)$ or equivalently from $(-\\pi,\\pi)$. \n\nDigital filters have a number of advantages over CT filters and are widely used now in place of CT filters in audio, communication, and control applications. Audio (and video) in particular is now almost exclusively processed, stored, and transmitted digitally, converting to CT only at the point of an amplifier and speaker. \n\n\\section{Ideal Filters}\n\nThe above filter types each have an ideal form.\n\nLow-pass filters remove frequency content above a threshold, $\\omega_c \\in [0,\\pi]$, called the \\emph{cutoff frequency}. They have an ideal frequency response ,for any integer multiple $k$, given by:\n\\[\nH(j\\omega) = \\left\\{ \\begin{array}{lc}\n  1 & 2\\pi k -\\omega_c < \\omega < 2\\pi k + \\omega_c\\\\\n  0 & \\text{else}\n\\end{array}\n\\right. \n\\]\nwith magnitude and phase plot\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/lowpass-ideal-dt.pdf}\n\\end{center}\nAs in CT filters, the range of frequencies $-\\omega_c \\leq \\omega \\leq \\omega_c$ are called the pass-band. The range of frequencies outside the pass-band are called the stop-band.\n\nHigh-pass filters remove frequency content below the cutoff frequency $\\omega_c\\in [0,\\pi]$. They have an ideal frequency response\n\\[\nH(j\\omega) = \\left\\{ \\begin{array}{lc}\n  0 & 2\\pi k -\\omega_c < \\omega < 2\\pi k + \\omega_c\\\\\n  1 & \\text{else}\n\\end{array}\n\\right. \n\\]\nwith magnitude and phase plot\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/highpass-ideal-dt.pdf}\n\\end{center}\n\nBandpass filters remove frequency content outside a band of frequencies called the pass-band. They have an ideal frequency response\n\\[\nH(j\\omega) = \\left\\{ \\begin{array}{lc}\n  1 & 2\\pi k -\\omega_0 - \\frac{B}{2} < \\omega < 2\\pi k -\\omega_0+\\frac{B}{2}\\\\[1em]\n  1 & 2\\pi k + \\omega_0 -\\frac{B}{2} < \\omega < 2\\pi k + \\omega_0+\\frac{B}{2}\\\\[1em]\n  0 & \\text{else}\n\\end{array}\n\\right. \n\\]\nwhere $\\omega_0\\in [0,\\pi]$ is the \\emph{center frequency} and $B < \\pi - \\omega_0$ is the \\emph{bandwidth}. The magnitude and phase plot looks like\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/bandpass-ideal-dt.pdf}\n\\end{center}\n\nFinally, notch or bandstop filters remove frequency content inside a band of frequencies (the stop band) defined by the center frequency $\\omega_0\\in [0,\\pi]$ and bandwidth $B < \\pi-\\omega_0$. The ideal frequency response is\n\\[\nH(j\\omega) = \\left\\{ \\begin{array}{lc}\n  0 & -\\omega_0 - \\frac{B}{2} < \\omega < -\\omega_0+\\frac{B}{2}\\\\[1em]\n  0 & \\omega_0 -\\frac{B}{2} < \\omega < \\omega_0+\\frac{B}{2}\\\\[1em]\n  1 & \\text{else}\n\\end{array}\n\\right. \n\\]\nwith magnitude and phase plot\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/bandstop-ideal-dt.pdf}\n\\end{center}\nOften the bandstop filter has a very narrow bandwidth, thus it \"notches\" out a frequency component of the input signal.\n\n\\section{Practical Filters}\n\nWhile ideal CT filters cannot be implemented in practice because they are non-causal, this more nuanced in DT systems. We have to make a distinction between \\emph{off-line} and \\emph{real-time} DT filters. Off-line DT filters, which we will discuss next time, can store as many samples as needed to arbitrarily approximate a non-causal filter, leading to an output that is delayed relative to the input by a significant amount. Real-time filters on the other hand must produce an output $y[n]$ for every input $x[n]$ with no delay. The distinction is important in some applications, controls in particular, and less so in other areas like audio or video where a delay is not noticeable. In the remainder of this lecture we assume a real-time filter implementation, which should be causal.\n\nPractical filters are described by a frequency response that is a ratio of two polynomials in $e^{j\\omega}$, i.e.\n\\[\nH\\left(e^{j\\omega}\\right) = \\frac{K \\cdot\\left(e^{j\\omega} + b_1\\right)\\cdot\\left(e^{j\\omega} + b_2\\right)\\cdots \\left(je^{j\\omega} + b_M\\right)}{\\left(e^{j\\omega} + a_1\\right)\\cdot\\left(e^{j\\omega} + a_2\\right)\\cdots \\left(e^{j\\omega} + a_N\\right)}\n\\]\nwhere $K$ is a constant that controls the gain at DC, and the zero or more complex coefficients $b_k$ and the one or more complex coefficients $a_k$ are called the \\emph{zeros} and \\emph{poles} of the filter respectively. Such systems correspond to difference equations as we have covered before and are realizable in real arithmetic if all poles and zeros are real or come in conjugate pairs. The processes of designing DT filters consists of choosing the poles and zeros, or equivalently choosing the coefficients of the numerator and dominator polynomials. This is covered in ECE 3704, ECE 4624, and other upper-level courses. \n\nThe general DT frequency response corresponds to a difference equation that when written in recursive form looks like\n\\[\ny[n] = \\underbrace{-\\frac{c_{N+1}}{c_1} y[n-N] -\\frac{c_{N}}{c_1}  y[n-N+1] + \\cdots -\\frac{c_{2}}{c_1} y[n-1]}_{\\text{auto-regressive}} + \\underbrace{\\frac{d_{N+1}}{c_1} x[n-N] + \\frac{d_{N}}{c_1} x[n-N+1] + \\cdots + \\frac{d_1}{c_1} x[n]}_{\\text{moving-average}}\n\\]\nThe terms corresponding to the weighted sums of previous outputs are called the \\emph{auto-regressive} portion of the filter. The terms corresponding to the weighted sums of previous inputs are called the \\emph{moving-average} portion of the filter.\n\nFilters without auto-regressive terms ($c_i = 0$ for $i > 1$) are called \\emph{finite impulse response} (FIR) filters, because their impulse response has only a finite number of non-zero values. Filters with auto-regressive terms are called \\emph{infinite impulse response} (IIR) filters, because their impulse response is non-zero for $n > 0$ (although they do approach zero as $n\\rightarrow \\infty$). \n\nPractical (real-time) DT filters differ from the ideal in that they cannot be zero over any finite range of frequencies and cannot transition discontinuously between stop and pass bands. Similar to CT filters, they must vary over the bands and transition smoothly, with a degree of variation and sharpness that is a function of the order of the filter and the exact form of the frequency response polynomials. Thus practical filters are described by additional parameters that define the stop and pass-bands.\n\nThe overall gain of the filter is the magnitude of the frequency response at a frequency that depends on the filter type, zero for a low-pass filter and the center frequency for a band-pass filter. The pass-band is defined by the frequency at which the magnitude of the frequency response drops below the overall gain, often -3dB = $\\frac{\\sqrt{2}}{2}$. The stop-band is defined similarly, as the frequency at which the magnitude of the frequency response drops further below the overall gain, often -20dB = 0.1 or -40dB = 0.01. The \\emph{transition bandwidth} is defined as the difference in the stop-band and pass-band frequencies. The \\emph{pass-band ripple} is defined as the maximum deviation from the overall gain, over the pass-band. For DT filters the frequencies are specified in radians per sample. After we discuss sampling we will see how to convert this to an equivalent CT frequency using the sample time.\n\n\\section{First-order and second-order systems as filters}\n\nGiven the equivalence of stable LTI systems and linear, constant-coefficient difference equations, block diagrams, impulse responses, and frequency responses, filters can be represented in any of these ways. We have covered extensively first-order and second-order DT systems and seen how they can be represented variously as circuits, difference equations, block diagrams, and as frequency responses. We now see how they can describe simple filters and serve as building blocks for higher-order filters.\n\n\\begin{example} Consider a first-order DT system\n\\[\ny[n+1] + ay[n] = b x[n+1] \n\\]\nIt can be represented as a block diagram\n\\begin{center}\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n      minimum height=2em, minimum width=2em]\n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (0,0) {};\n    \\node [left of=input] {$x[n]$};\n    \\node [sum, right of=input, node distance=5em] (sum) {$\\Sigma$};\n    \\node[block] at (3,-1) (block2) {$D$};\n    \\node [shape=coordinate, name=conn] at (4,0) {};\n    \\node[shape=coordinate] at (5,0) (output) {};\n    \\node [right of=output] {$y[n]$};\n    \n    \\draw [->] (input) -- node {$b$} (sum);\n    \\draw (sum) -- (conn);\n    \\draw [->] (conn) -- (output);\n    \\draw [->] (conn) |- (block2);\n    \\draw [->] (block2) -| node {$-a$} (sum);\n  \\end{tikzpicture}\n\\end{center}\nor as a recursive difference equation\n\\[\ny[n] = -ay[n-1] + bx[n] \n\\]\nor as an impulse response\n\\[\nh[n] = b(-a)^n u[n]\n\\]\nor as a frequency response if $|a| < 1$\n\\[\nH\\left(e^{j\\omega}\\right) = \\frac{b}{1+ae^{-j\\omega}} = \\frac{be^{j\\omega}}{e^{j\\omega}+a} \n\\]\n\nLet us examine two cases, where $a = \\tfrac{1}{2}, b=1-a = \\tfrac{1}{2}$ and $a = -\\tfrac{1}{2}, b=1+a = \\tfrac{3}{2}$. If we plot the frequency response when $a = \\tfrac{1}{2}, b=\\tfrac{1}{2}$ we see the DC gain is about -9.5 dB, and the response passes through -3dB at $\\pm 2.4$ rad/sample. Thus this corresponds approximately to a high-pass filter. \n\\begin{center}   \n  \\includegraphics[scale=0.7]{graphics/lecture25_1.png}\n\\end{center}\nIf we plot the frequency response when $a = -\\tfrac{1}{2}, b=\\tfrac{3}{2}$ we see the DC gain is 0 dB, and the response passes through -3dB at $\\pm 0.7$ rad/sample. Thus this corresponds approximately to a low-pass filter. \n\\begin{center}   \n  \\includegraphics[scale=0.7]{graphics/lecture25_2.png}\n\\end{center}\n\n\\end{example}\n\n\\begin{example} As with CT filters we can increase the sharpness of the filter by increasing the order. Consider a second-order DT system\n\\[\nc_1 y[n+2] + c_2y[n+1] + c_3y[n] = d_1x[n+2] + d_2x[n+1] + d_3x[n]  \n\\]\nIt can be represented as a block diagram\n\\begin{center}\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n      minimum height=2em, minimum width=2em]\n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (-2,0) {};\n    \\node [left of=input] {$x[n]$};\n    \\node [shape=coordinate, name=conn0] at (0,0) {};\n    \\node [sum] at (2,0) (sum1) {$\\Sigma$};\n    \\node [block] at (4,-1) (block1) {$D$};\n    \\node [block] at (4,-3) (block2) {$D$};\n    \\node [block] at (0,-1) (block3) {$D$};\n    \\node [block] at (0,-3) (block4) {$D$};\n    \\node [shape=coordinate, name=conn1] at (4,-2) {};\n    \\node [shape=coordinate, name=conn2] at (4,-4) {};\n    \\node [sum] at (2,-2) (sum2) {$\\Sigma$};\n    \\node [sum] at (2,-4) (sum3) {$\\Sigma$};\n    \\node [shape=coordinate, name=conn] at (4,0) {};\n    \\node [shape=coordinate] at (5,0) (output) {};\n    \\node [right of=output] {$y[n]$};\n    \\node at (3,-3.7) {$-\\frac{c_3}{c_1}$};\n    \\node at (3,-1.7) {$-\\frac{c_2}{c_1}$};\n    \\node at (1,-1.7) {$\\frac{d_2}{c_1}$};\n    \\node at (1,-3.7) {$\\frac{d_3}{c_1}$};\n    \\node at (1,0.3) {$\\frac{d_1}{c_1}$};\n    \n    \\draw (input) -- (conn0);\n    \\draw [->] (conn0) -- (sum1);\n    \\draw [->] (conn0) -- (block3);\n    \\draw [->] (block3) -- (block4);\n    \\draw [->] (block3) |- (sum2);\n    \\draw [->] (block4) |- (sum3);\n    \\draw (sum1) -- (conn);\n    \\draw [->] (conn) -- (output);\n    \\draw [->] (conn) -- (block1);\n    \\draw (block1) -- (conn1);\n    \\draw [->] (conn1) -- (sum2);\n    \\draw [->] (conn1) -- (block2);\n    \\draw [->] (block2) |- (sum3);\n    \\draw [->] (sum3) -- (sum2);\n    \\draw [->] (sum2) -- (sum1);\n  \\end{tikzpicture}\n\\end{center}\nor as a recursive difference equation\n\\[\ny[n] = -\\frac{c_3}{c_1} y[n-2] - \\frac{c_2}{c_1} y[n-1] + \\frac{d_3}{c_1} x[n-2] + \\frac{d_2}{c_1} x[n-1] + \\frac{d_1}{c_1} x[n] \n\\]\nor as a frequency response if $|\\gamma_i| < 1$ for all $i$ where $\\gamma_i$ are the roots of the characteristic equation\\\\ $c_1 E^2 + c_2 E + c_3 = 0$.\n\\[\nH\\left(e^{j\\omega}\\right) = \\frac{d_1 e^{j2\\omega} + d_2 e^{j\\omega} + d_3}{c_1 e^{j2\\omega} + c_2 e^{j\\omega} + c_3} \n\\]\nAs a concrete example, consider this system when c = [$c_1 = 1$, $c_2 = 0$, $c_3 = 0.1716$, $d_1 = 0.2929$, $d_2 = 0.5858$, and $d_3 = 0.2929$. If we plot the frequency response we see the filter gain is 0 dB at DC and passes through -3 dB at approximately $\\pm 1.57$ rad/sample. Thus it corresponds to a low-pass filter.\n\\begin{center}   \n  \\includegraphics[scale=0.7]{graphics/lecture25_3.png}\n\\end{center}\nOne thing to note is the attenuation drops off quickly after the passband. This is an advantage of DT filters; they can have small transition bands. Comparing them directly to an equivalent CT filter will have to be deferred until we discuss sampling.\n\nNote the autoregressive part of the filter is to the right of the summations, while the moving average part is to the left. The output of the delay blocks multiplied by non-zero coefficients are called \\emph{filter taps} in signal processing parlance. This repeating structure can be taken advantage of in the creation of general-purpose digital signal processing hardware.\n\\end{example}\n\n\\section{Higher-Order Filters}\n\nWe can continue to increase the steepness of the passband to stop-band transitions by increasing the order of the filter. While this can be accomplished using a serial connection of stages as in CT filters, since the implementation of DT filters requires just memory (delay blocks) and adders/multipliers it is common to just implement the filter with a larger number of delay blocks. \n\n\\newpage\nMatlab code for plotting the first-order frequency response plot:\n\\begin{verbatim}\na = 1/2;\nw = -pi:0.01:pi;\nH = a./(exp(j*w) + a);\n\n% Create a nice FR plot \nhFig = figure();\nhold on;\n\nsubplot(2,1,1);\nhm = plot(w,20*log10(abs(H)));\ngrid on;\naxis tight;\nhTitle  = title ('Frequency Response - first order a = 0.5');\nhYLabel1 = ylabel('Magnitude (dB)');\nset(gca, 'FontSize', 14, 'YTick', -20:5:5, 'LineWidth', 2);\n\nsubplot(2,1,2);\nhp = plot(w,unwrap(angle(H)));\ngrid on;\naxis tight;\nhYLabel2 = ylabel('Phase (radians)');\nhXLabel = xlabel('Frequency (rad/sample)');\nset(gca, 'FontSize', 14, 'LineWidth', 2);\n\nset(hm, 'linewidth', 2);\nset(hp, 'linewidth', 2);\n\nset([hXLabel, hYLabel1, hYLabel2]  , ...\n     'FontSize'   , 14          );\nset( hTitle                    , ...\n     'FontSize'   , 14          , ...\n     'FontWeight' , 'bold'      );\n\\end{verbatim}\n\n\\newpage\nMatlab code for plotting the second-order frequency response plot:\n\\begin{verbatim}\nc = [1,0,0.1716];\nd = [0.2929, 0.5858, 0.2929];\nw = -pi:0.01:pi;\nH = (d(1)*exp(j*2*w) + d(2)*exp(j*w) + d(3))./(c(1)*exp(j*2*w) + c(2)*exp(j*w) + c(3));\n\n% Create a nice FR plot \nhFig = figure();\nhold on;\n\nsubplot(2,1,1);\nhm = plot(w,20*log10(abs(H)));\ngrid on;\naxis tight;\nhTitle  = title ('Frequency Response - second order');\nhYLabel1 = ylabel('Magnitude (dB)');\nset(gca, 'FontSize', 14, 'YTick', -100:20:0, 'LineWidth', 2);\n\nsubplot(2,1,2);\nhp = plot(w,unwrap(angle(H)));\ngrid on;\naxis tight;\nhYLabel2 = ylabel('Phase (radians)');\nhXLabel = xlabel('Frequency (rad/sample)');\nset(gca, 'FontSize', 14, 'LineWidth', 2);\n\nset(hm, 'linewidth', 2);\nset(hp, 'linewidth', 2);\n\nset([hXLabel, hYLabel1, hYLabel2]  , ...\n     'FontSize'   , 14          );\nset( hTitle                    , ...\n     'FontSize'   , 14          , ...\n     'FontWeight' , 'bold'      );\n\\end{verbatim}\n", "meta": {"hexsha": "29036750791f0ea6a13ce89566dd0ecd455cb4ba", "size": 17996, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "21-dt-filters.tex", "max_stars_repo_name": "clwyatt/notes-2714", "max_stars_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "21-dt-filters.tex", "max_issues_repo_name": "clwyatt/notes-2714", "max_issues_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "21-dt-filters.tex", "max_forks_repo_name": "clwyatt/notes-2714", "max_forks_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.0032786885, "max_line_length": 919, "alphanum_fraction": 0.6964325406, "num_tokens": 5472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7480715614472457}}
{"text": "\\subsection{Decomposition of U}\n\\SecLabel{u}\n\nLet $\\alpha\\colon \\field{4} \\to \\field{4}$ be given by\n$$\n\\alpha(x) \\eqdef U_{x}(0)\n$$\nand let $U'_{\\hex{0}},\\ldots,U'_{\\hex{f}}$ be permutations of $\\field{4}$ given by\n$$\nU'_k(x) \\eqdef U_k(x) \\oplus \\alpha(k).\n$$\nIt follows that for all $k \\in \\field{4}$, $U'_k(0) = 0$. The codebook of $U'$ is given in \\FigRef{up}.\n\n\\FigTex{up-m.tex}\n\nIn~\\cite{LinAffEQ}, Biryukov~\\etal{} propose efficient algorithms for checking affine and linear equivalence of permutations. Applying these algorithms to the permutations $U'_i$ shows that all $U'_i$ are pairwise linear equivalent. Furthermore, they differ only by a linear layer in the output. Formally, let $M_{\\hex{0}}, \\ldots, M_{\\hex{f}}\\colon \\field{4} \\to \\field{4}$ be given by\n$$\nM_k(x) \\eqdef U'_k(x) \\circ U'^{-1}_{\\hex{0}}(x).\n$$\nThen, each $M_i$ is linear. The codebook of $M$ is given in \\FigRef{m}.\n\n\\begin{remark}\nIn the hindsight, it could be trivially checked that $U_i \\circ U_j^{-1}$ is linear for all $i,j \\in \\field{4}$. However, it is not always clear which properties or relations can be expected. For this reason, the linear/affine equivalence algorithms from~\\cite{LinAffEQ} and their improved variants by Dinur~\\cite{LinAffEQ2} are very useful tools for S-Box reverse-engineering.\n\\end{remark}\n\nThe next step is to observe that the functions $M_i$ have two interesting properties:\n\\begin{enumerate}\n    \\item the functions $M_i$ have orders $1,3,5,15$; those with order $15$ generate all $M_i$;\n    \\item the functions $M_i$ are linearly related: they are contained in linear subspace of dimension 4;\n\\end{enumerate}\nThese properties point towards a finite field structure. Let $b \\eqdef M_{\\hex{0}} \\oplus M_{\\hex{5}}$. Then $b$ is \\emph{linear-similar} to the multiplication by $X$ in the finite field\n$$\n\\fielde{4} \\simeq \\field{}[X]/(X^4 + X^3 + 1).\n$$\nBy ``linear-similar'' it is meant that\n$$\nb = l \\circ (\\cdot~\\fmult X) \\circ l^{-1}\n$$\nfor some linear bijection $l \\in \\linbij{4}$, where $(\\cdot~\\fmult X)$ denotes the multiplication in the finite field by $X$. In this case, $l = l' = \\swaplsb$, where\n$$\n\\swaplsb\\colon \\field{4} \\to \\field{4}, \\swaplsb(x_1,x_2,x_3,x_4) \\eqdef (x_1,x_2,x_4,x_3).\n$$\nAmong all choices of $b$ and the field defining polynomial, this choice results in the simplest mapping $l$.\n\nNote that similarity is preserved for powers, i.e. $b^i = \\swaplsb \\circ (\\cdot~\\fmult X^i) \\circ \\swaplsb$. It follows that for all $k \\in \\field{4}$, $\\swaplsb \\circ M_k \\circ \\swaplsb$ is the finite field multiplication by the power of $X$ equal to the discrete logarithm of $M_k$ base $b$. More precisely, let $\\gamma\\colon \\field{4} \\to \\field{4}$ be such that \n$$\n\\gamma(k) \\eqdef (\\swaplsb \\circ M_k \\circ \\swaplsb)(1).\n$$\nFurthermore, let $\\beta\\colon \\field{4} \\to \\field{4}$ be given by\n$$\n\\beta(x) \\eqdef U'_{\\hex{0}}(\\swaplsb(x)) \\oplus \\hex{c}.\n$$\nThen $U$ can be decomposed as follows:\n$$\nU_k(x) = \\alpha(k) \\oplus \\beta(\\gamma(k) \\fmult \\swaplsb(x)) \\oplus \\hex{c}.\n$$\n\nNote that $\\alpha$ is affine such that $\\alpha \\oplus \\hex{c}$ is linear:\n$$\n\\alpha(x_1,x_2,x_3,x_4) = (1, x_2 \\oplus 1, x_1, 0).\n$$\nThe constant part of $\\alpha$ cancels with the constant from $\\beta$ and the linear part can be merged with the outer linear encoding $L$. \nThe graphical representation of the final decomposition of $U$ and the codebooks of $\\alpha, \\beta, \\gamma$ and $\\swaplsb$ are given in \\FigRef{final-u}.\n\n\\FigTex{final-u.tex}", "meta": {"hexsha": "9bd41f51447918cd6cefd9bfb2a94f0afd1d8dd6", "size": 3466, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/9strKuz/11u.tex", "max_stars_repo_name": "hellman/thesis", "max_stars_repo_head_hexsha": "6ba1c2b241e63c07cf76108481c1b67f21a50f12", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2019-05-16T19:55:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T15:36:12.000Z", "max_issues_repo_path": "thesis-source/9strKuz/11u.tex", "max_issues_repo_name": "hellman/thesis", "max_issues_repo_head_hexsha": "6ba1c2b241e63c07cf76108481c1b67f21a50f12", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-08-09T11:26:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-09T11:26:45.000Z", "max_forks_repo_path": "thesis-source/9strKuz/11u.tex", "max_forks_repo_name": "hellman/thesis", "max_forks_repo_head_hexsha": "6ba1c2b241e63c07cf76108481c1b67f21a50f12", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-05T19:40:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T19:40:16.000Z", "avg_line_length": 53.3230769231, "max_line_length": 386, "alphanum_fraction": 0.69186382, "num_tokens": 1179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.748044383804661}}
{"text": "\\section{Kernels\n\\hfill\\normalfont $\\color{section-text-color}\\widehat{=} \\text{ \\sffamily scalar prod. in feature space } \\phi$}\n\n\\textbf{K. trick:}\\;\n$\\bm{x}_i\\!^\\top \\bm{x}_j \\overset{\\text{Mercer}}{\\rightsquigarrow}$\n\\highlight*{$ k(\\bm{x}_i, \\bm{x}_j) = \\phi(\\bm{x}_i)\\!^\\top \\phi(\\bm{x}_j)$}\n\n% ===\n\\emph{Properties of kernel}\n\n$k: \\mathcal{X} \\times \\mathcal{X} \\rightarrow \\mathbb{R}$ is an inn. prod. (symm., pos.-def.).\n\nNeed: \\enskip \\highlight{$K \\succeq 0 \\;\\forall \\bm{x}_i$}, \\enskip where $K_{i,j} = k(\\bm{x}_i,\\bm{x}_j)$\n\nHence:\n\\enskip $\\bullet$ check pos. eigenvalues \\textit{or better} \\par\n\\enskip $\\bullet$ $vKv^\\top = \\sum_i\\sum_j \\alpha_i\\alpha_j\\, k(\\bm{x}_i,\\bm{x}_j) \\geq 0$ \\par\n\\enskip $\\to$ check for $i\\!=\\!j\\!=\\!1$ for \\textit{counter example}\n\n% ===\n\\emph{Important kernels}\n{\\setstretch{0.9}\n\\begin{tabular}{@{}>{\\normalcolor}l l}\n\tConstant:\t& $k(x,y)=c \\text{ \\normalcolor with } c \\geq 0$\\\\\n\tLinear: \t& $k(x,y)=x^\\top y$\\\\\n\tPolynomial:\t& $k(x,y)=(x^\\top y + 1)^d$\\\\\n\tGaussian:\t& $k(x,y) = \\exp(-\\norm{x-y}_2^2/h^2)$\\\\\n\tLaplacian:\t& $k(x,y) = \\exp(-\\norm{x-y}_1/h)$\n\\end{tabular}\n}\n\n% ===\n\\emph{Composition rules}\\\\\n$\\circ$ $k=k_1+k_2$\n\\enskip\n$\\circ$ $k=c\\cdot k${\\footnotesize $\\color{gray},\\; c>0$}\n\\enskip\n$\\circ$ $k=k_1\\!\\cdot\\! k_2$\n\n$\\circ$ $k=f(k_1)${\\footnotesize \\color{gray}, $f$: exp. \\textit{or} polyn. with \\underline{all} pos. coeff.}\n\n% ===\n\\emph{Kernelized Perceptron / \\color{OrangeRed} SVM}\n\\vspace{-1pt}\n\n\\textbf{Ansatz:} $w^* \\in \\operatorname{span}(X) \\Rightarrow$ \\highlight*{$w = \\sum_{j=1}^n \\alpha_j y_j x_j$}\n\n\\vspace{-1pt}\n{\\small $\\alpha^\\ast {=}\n\\arg\\min\\limits_\\alpha \\frac{1}{n}\\sum_n \\max\\{ 0, {\\color{OrangeRed}1}{-}y_i\\alpha^\\top k_i \\} {\\color{OrangeRed}+ \\lambda\\alpha^\\top \\bm{D}_y\\bm{K}\\bm{D}_y \\alpha}$}\n\n$\\color{gray} \\text{with } k_i\\!=\\![.., y_j\\,k(x_i,x_j), ..] \\text{ and } D_y\\!=\\!\\operatorname{diag}(y_i)$\n\n\\textbf{Predict:} $\\hat y = \\operatorname{sign}(\\sum_{i=1}^n \\alpha_iy_ik(x_i, x))$\n\n% ===\n\\emph{Kernelized linear regression (KLR)}\n\n\\textbf{Ansatz:} \\highlight*{$w=\\sum_{j=1}^n \\alpha_j x_j$} $= \\sum_{j=1}^n \\alpha_j\\phi(x_j)$\n\n$\\alpha^\\ast =\n\\arg\\min\\limits_\\alpha \\frac{1}{n} \\norm{\\alpha^\\top K-y}_2^2 + \\lambda\\alpha^\\top K\\alpha$\n\\vspace{-1pt}\n\n\\textbf{closed form:} $\\alpha^\\ast = (K+\\lambda I)^{-1}y$\n\n\\textbf{Predict:} $\\hat y = \\sum_{i=1}^n \\alpha_i k(x_i,x)$\n\n% ===\n\\emph{Kernelized LogReg}\n\n$\\hat\\alpha \\!=\\! \\arg\\!\\min\\limits_\\alpha \\sum_{i=1}^n \\log(1\\!+\\!\\exp(-y_i\\alpha^\\top\\! K_i)) \\!+\\! \\lambda\\alpha^\\top\\! K\\alpha$\\vspace{-3pt}\\\\\n$P(y\\vert x,\\hat\\alpha) = \\big( 1+\\exp(-y\\sum_{j=1}^n\\alpha_j k(x_j,x)) \\big)^{-1}$\n\n% ===\n\\emph{Semi-parametric kernel}\n\nadditive combination of linear and non-linear kernel fct's, e.g. $x\\leftrightarrow \\sin(x\\!\\cdot\\!\\gamma)$ {\\small\\color{gray} ``periodic'' kernel}\n", "meta": {"hexsha": "027fd031e3dc9b785bf1886f2de6cf989e089ea4", "size": 2810, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/IML19/sections/Kernels.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/IML19/sections/Kernels.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/IML19/sections/Kernels.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.5696202532, "max_line_length": 167, "alphanum_fraction": 0.6149466192, "num_tokens": 1205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.7479996828718717}}
{"text": "\\section{$n$-step Bootstrapping}\n$n$-step methods allow us to observe multiple time-steps of returns before updating a state with the observed data and a bootstrapped estimate of the value of the $n$th succeeding state.\n\n\\subsection{$n$-step TD Prediction}\nDefine the $n$-step return\n\\begin{equation}\n    G_{t:t+n} \\doteq \\sum_{i=t}^{t+n-1}\\gamma^{i-t}R_{i+1} + \\gamma^n V_{t+n-1}(S_{t+n})\n\\end{equation}\nwhere $n \\geq 1$, $0 \\leq t < T - n$ and $V_i$ is the estimated state-value function as of time $i$. If $t + n > T$ then $G_{t+n} \\equiv G_t$, the standard return. The $n$-step return is the target for \\emph{$n$-step TD} methods, note that $n-1$ rewards are observed and the succeeding value is bootstrapped with the latest estimate of the value function. The corresponding update for state-values is\n\\begin{equation}\n    V_{t+n}(S_t) = V_{t+n - 1}(S_t) + \\alpha [G_{t:t+n} - V_{t+n-1}(S_{t})]  \\quad\\quad 0 \\leq t < T.\n\\end{equation}\nNote that Monte-Carlo can be thought of as TD($\\infty$)Pseudocode for $n$-step TD is given in the box below.\\\\\n\n\\includegraphics[width=\\textwidth]{\\NotesImages/n_step_td_state_values.png}\\\\\n\nThe $n$-step return obeys the \\emph{error-reduction property}, and because of this $n$-step TD can be shown to converge to correct predictions (given a policy) under appropriate technical conditions. This property states that the $n$-step return is a better estimate than $V_{t+n-1}$ in the sense that the error on the worst prediction is always smaller\n\\begin{equation}\n    \\max_s \\left|\\Epi[G_{t:t+n}|S_t=s] - v_\\pi(s)\\right| \\leq \\gamma^n \\max_s \\left|V_{t+n-1}(s) - v_\\pi(s)\\right|\n\\end{equation}\n\n\\subsection{$n$-step Sarsa}\n\\subsubsection*{Sarsa}\nWe develop $n$-step methods for control. We generalise Sarsa to $n$-step Sarsa, or Sarsa($n$). This is done in much the same way as above, but with action-values as opposed to state-values. The $n$-step return in this case is defined as\n\\begin{equation}\n    G_{t:t+n} \\doteq \\sum_{i=t}^{t+n-1}\\gamma^{i-t}R_{i+1} + \\gamma^n Q_{t+n-1}(S_{t+n}, A_{t+n})\n\\end{equation}\nwhere $n \\geq 1$, $0 \\leq t < T - n$ and $Q_i$ is the estimated action-value function as of time $i$. If $t + n > T$ then $G_{t+n} \\equiv G_t$, the standard return. The corresponding update is\n\\begin{equation}\n    Q_{t+n}(S_t, A_t) = Q_{t+n-1}(S_t, A_t) + \\alpha [G_{t:t+n} - Q_{t+n-1}(S_{t}, A_{t})]  \\quad\\quad 0 \\leq t < T.\n\\end{equation}\n\n\\subsubsection*{Expected Sarsa}\nWe define $n$-step expected Sarsa similarly\n\\begin{equation}\n    G_{t:t+n} \\doteq \\sum_{i=t}^{t+n-1}\\gamma^{i-t}R_{i+1} + \\gamma^n \\bar{V}_{t+n-1}(S_{t+n})\n\\end{equation}\nwhere $n \\geq 1$, $0 \\leq t < T - n$ and $\\bar{V}_i$ is the \\emph{expected approximate value} of state $s$\n\\begin{equation}\n    \\bar{V}_i(s) \\doteq \\sum_a \\pi(a|s)Q_i(s, a).\n\\end{equation} \nAs always, if $t + n > T$ then $G_{t+n} \\equiv G_t$, the standard return. The corresponding update is formally the same as above\\\\\n\n\n\\includegraphics[width=\\textwidth]{\\NotesImages/n_step_sarsa.png}\\\\\n\n\\subsection{$n$-step Off-policy Learning}\nWe can learn with $n$-step methods off-policy using the importance sampling ratio (target policy $\\pi$ and behaviour policy $b$)\n\\[\n    \\rho_{t:h} \\doteq \\prod_{k=t}^{\\text{min}(h, T-1)}\\frac{\\pi(A_k|S_k)}{b(A_k|S_k)}.\n\\]\nFor state-values we have \n\\[\n    V_{t+n}(S_t) \\doteq V_{t+n-1}(S_t) + \\alpha \\rho_{t:t+n-1}[G_{t:t+n} - V_{t+n-1}(S_t)]\n\\]\nand for action-values we have\n\\[\n    Q_{t+n}(S_t, A_t) = Q_{t+n-1}(S_t, A_t) + \\alpha \\rho_{t+1:t+n-1}[G_{t:t+n} - Q_{t+n-1}(S_t, A_t)]\n\\]\nnote that for action values the importance sampling ratio starts one time-step later, because we are attempting to discriminate between actions at time $t$.\\\\\n\n\\includegraphics[width=\\textwidth]{\\NotesImages/off_policy_n_step_sarsa.png}\\\\\n\n\\subsection{*Per-decision Methods with Control Variates}\nWe have the standard recursion relation for the $n$-step return\n\\[\n    G_{t:h} = R_{t+1} + \\gamma G_{t+1:h}.\n\\]\nFor an off-policy algorithm, one would be tempted to simply weight this target by the importance sampling ratio. This method, however, shrinks the estimated value functions when the importance sampling ratio is 0, hence increasing variance. We thus introduce the \\emph{control-variate} $(1 - \\rho_t)V_{h-1}(S_t)$, giving an off-policy update of \n\\[\n    G_{t:h} = \\rho_t (R_{t+1} + \\gamma G_{t+1:h}) + (1 - \\rho_t)V_{h-1}(S_t)\n\\]\nwhere $G_{h:h} = V_{h-1}(S_h)$. Note that the control-variate has expected value 0, since the factors are uncorrelated and the expected value of the importance sampling ratio is 1.\\\\\n\nWe can do a similar thing for action-values\n\\[\n    G_{t:h} \\doteq R_{t+1} + \\gamma \\rho_{t+1:h}\\left( G_{t+1:h} - Q_{h-1}(S_{t+1}, A_{t+1}) \\right) - \\gamma \\bar{V}_{h-1}(S_{t+1}),\n\\]\nwhere once again the importance sampling ratio starts one time-step later.\n\n\\subsubsection*{Control Variates in General}\nSuppose we want to estimate $\\mu$ and assume we have an unbiased estimator for $\\mu$ in $m$. Suppose we calculate another statistic $t$ such that $\\mathbb{E}\\left[t\\right]=\\tau$ is a known value. Then\n\\[\n    m^\\star = m + c\\left(t-\\tau\\right)\n\\]\nis also an unbiased estimator for $\\mu$ for any $c$, with variance\n\\[\n    \\textrm{Var}\\left(m^{\\star}\\right)=\\textrm{Var}\\left(m\\right) + c^2\\,\\textrm{Var}\\left(t\\right) + 2c\\,\\textrm{Cov}\\left(m,t\\right).\n\\]\n\nIt is easy to see that taking\n\n\\[\n    c = - \\frac{\\textrm{Cov}\\left(m,t\\right)}{\\textrm{Var}\\left(t\\right)}\n\\]\nminimizes the variance of $m^{\\star}$. With this choice\n\n\\begin{align}\n\\textrm{Var}(m^{\\star}) & =\\textrm{Var}(m) - \\frac{\\left[\\textrm{Cov}(m,t)\\right]^2}{\\textrm{Var}(t)} \\\\\n& = (1-\\rho_{m,t}^2)\\textrm{Var}(m)\n\\end{align}\nwhere $\\rho_{m,t}=\\textrm{Corr}\\left(m,t\\right) $ is the Pearson correlation coefficient of $m$ and $t$. The greater the value of $|\\rho_{m,t}|$, the greater the variance reduction achieved.\n\n\\subsection{Off-policy Learning Without Importance Sampling: The $n$-step Tree Backup Algorithm}\nWe introduce the $n$-step \\emph{tree-backup algorithm} algorithm using the return\n\\begin{equation}\n    G_{t:t+n} \\doteq R_{t+1} + \\gamma \\sum_{a \\neq A_{t+1}} \\pi(a|S_{t+1})Q_{t+n-1}(S_{t+1}, a) + \\gamma \\pi(A_{t+1}|S_{t+1})G_{t+1:t+n}\n\\end{equation}\nfor $t < T-1$, $n > 1$ and with $G_{i:i} = 0$ and $G_{T-1:t+n} = R_T$. This algorithm updates $S_t$ with bootstrapped, probability weighted action-values of \\emph{all} actions that were not taken all along the trajectory and recursively includes the rewards realised, weighted by the probability of their preceding actions under the policy. Pseudocode given below.\\\\\n\n\\includegraphics[width=\\textwidth]{\\NotesImages/n_step_tree_backup.png}\\\\\n    \n    \n\\subsection{*A Unifying Algorithm: $n$-step $Q(\\sigma)$}\nWe introduce an algorithm which, at each time step, can choose to either take an action as a sample as in Sarsa or to take an expectation over all possible actions as in tree-backup. \\\\\n\nDefine a sequence $\\sigma_t \\in [0, 1]$ that at each time step chooses a proportion of sampling vs. expectation. This generalises Sarsa and tree-backup by allowing each update to be a linear combination of the two ideas. The corresponding return (off-policy) is \n\\begin{align}\n    G_{t:h} \\doteq R_{t+1} &+ \\gamma \\left(\\sigma_{t+1}\\rho_{t+1}  (1- \\sigma_{t+1})\\pi(A_{t+1}\\vert S_{t+1})\\right) \\left( G_{t+1:h} - Q_{h-1}(S_{t+1}, A_{t+1}) \\right) \\\\ \n                           &+ \\gamma \\bar{V}_{h-1}(S_{t+1}),\n\\end{align}\nfor $t < h< T$, with $G_{h:h} \\doteq Q_{h-1}(S_h, A_h)$ if $h<T$ and $G_{T-1:T} \\doteq R_t$ if $h=T$. Pseudocode given below.\\\\\n\n\\includegraphics[width=\\textwidth]{\\NotesImages/off_policy_n_step_Q_sigma.png}\\\\\n\n    \n    \n    \n    \n    \n    \n    \n    \n    \n    \n\n", "meta": {"hexsha": "8a7763504b74efd3eb382ac6ee14d88b886dbfb1", "size": 7655, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/chapter7/chapter7_content.tex", "max_stars_repo_name": "ElliotMunro200/reinforcement_learning_an_introduction", "max_stars_repo_head_hexsha": "c4fccb46a4bb00955549be3505144ec49f0132e5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 234, "max_stars_repo_stars_event_min_datetime": "2018-09-01T00:26:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T03:55:50.000Z", "max_issues_repo_path": "notes/chapters/chapter7/chapter7_content.tex", "max_issues_repo_name": "15779235038/reinforcement_learning_an_introduction", "max_issues_repo_head_hexsha": "a0ac9e5da6eaeae14d297a560c499d1a6e579c2a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2018-11-29T21:04:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-13T17:11:50.000Z", "max_forks_repo_path": "notes/chapters/chapter7/chapter7_content.tex", "max_forks_repo_name": "15779235038/reinforcement_learning_an_introduction", "max_forks_repo_head_hexsha": "a0ac9e5da6eaeae14d297a560c499d1a6e579c2a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2018-07-31T04:53:21.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T04:03:43.000Z", "avg_line_length": 55.8759124088, "max_line_length": 400, "alphanum_fraction": 0.6792945787, "num_tokens": 2644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7478852726738098}}
{"text": "\\graphicspath{{Chapter2/Figs/}}\n\n\\section{MOFA Model description} \\label{mofa:model_description}\n\n\\subsection{Mathematical formulation}\n\nMulti-Omics Factor Analysis (MOFA) is a multi-view generalisation of conventional Factor Analysis to an arbitrary number of $M$ data modalities (or views). It is inspired from the Group Factor Analysis framework discussed in \\Cref{section:gfa}.\n\nThe input data consists of $M$ views $\\bfY^m \\in \\R^{N \\times D_m}$ with non-overlapping features. Views, or data modalities, often represent different assays, but there is flexibility in their definition. Formally, the input data is factorised as:\n\\begin{equation} \\label{mofa_master_equation}\n\t\\mathbf{Y}^m = \\mathbf{Z}(\\mathbf{W}^{m})^{T} + \\bepsilon^m\n\\end{equation}\nwhere $\\bfZ \\in \\R^{N \\times K}$ is a matrix that contains the factor values and $\\bfW^m \\in \\R^{D_m \\times K}$ are a set of $M$ matrices (one per view) that contain the feature weights. Finally, $\\bepsilon^m \\in \\R^{D_m}$ captures the residuals, or the noise, which is assumed to be normally distributed and heteroskedastic:\n\\begin{equation}\n\tp(\\epsilon^{m}_{d}) = \\Ndist{\\epsilon^{m}_{d}}{0,(\\tau_{d}^{m})^{-1}}\n\\end{equation}\nwhere $\\tau$ corresponds to the precision (inverse of the variance). Altogether, this results in the following likelihood:\n\\begin{equation}\n\tp(\\bfY|\\bfW,\\bfZ,\\bTau) = \\prod_{m=1}^{M} \\prod_{d=1}^{D_m} \\prod_{n=1}^{N} \\Ndist{y_{nd}^m}{\\bfz_{n}^T\\bfw_{d}^{m},(\\tau_d^m)^{-1}}\n\t% p(y_{nd}^m) = \\Ndist{y_{nd}^m}{\\bfz_{n,:}\\bfw_{d,:}^{mT},1/\\tau_d^m},\n\\end{equation}\n\nNon-Gaussian noise models can also be defined (see \\Cref{section:mofa_ngaussian}), but unless otherwise stated, I will always assume Gaussian residuals.\n\n\\subsubsection{Prior distributions for the factors}  \\label{section:mofa_factors}\n\nFor the factors, we can define an isotropic Gaussian prior, as commonly done in most factor analysis models:\n\\begin{equation}\n\tp(z_{nk}) = \\Ndist{z_{nk}}{0,1}\n\\end{equation}\nThis effectively  assumes (1) a continuous latent space and (2) independence between samples and factors. \n\n\\subsubsection{Prior distributions for the weights}  \\label{section:mofa_weights}\n\nThe key determinant to ensure that the model is interpretable lies on the regularization structure imposed on the weights. Here we encode two levels of sparsity on their prior distributions, (1) a view- and factor-wise ARD prior \\cite{Mackay1996} and (2) a feature-wise spike-slab prior \\cite{Mitchell1988}:\n\\begin{equation*}\n\tp(w_{dk}^{m}) = (1-\\theta_{k}^{m}) \\mathds{1}_0(w_{dk}^{m}) + \\theta_{k}^{m} \\Ndist{w_{dk}^{m}}{0, 1 / \\alpha_{k}^{m}}\n\\end{equation*}\nThe aim of the ARD prior is to disentangle the activity of factors to the different views, such that the weight vector $\\bfw_{:,k}^m$ is shrunk to zero if the factor $k$ does not explain any variation in view $m$. The spike-and-slab prior encourages zero values within active factors at the level of individual features.\n\nHowever, the standard formulation of the spike-and-slab prior contains a Dirac delta function, which is incompatible with the variational inference scheme. To solve this we adopt a re-parametrization of the weights $w$ as a product of a Gaussian random variable $\\hat{w}$ and a Bernoulli random variable $s$, \\cite{Titsias2011} resulting in the following prior distribution:\n\\begin{equation}\n\tp(\\hat{w}_{dk}^{m},s_{dk}^{m}) = \\Ndist{\\hat{w}_{dk}^{m}}{0, \\frac{1}{\\alpha_k^m}}  \\text{Ber}(s_{dk}^m \\,|\\,\\theta_k^m)\n\\end{equation}\nIn this formulation $\\alpha_k^m$ controls the activity of factor $k$ in view $m$ and $\\theta_k^m$ controls the corresponding fraction of non-zero weights (i.e. the sparsity levels).\\\\\n\nFinally, we define conjugate priors for $\\theta$ and $\\alpha$:\n\\begin{align}\n\tp(\\theta_k^m) &= \\Bdist{\\theta_k^m}{a_0^\\theta,b_0^\\theta}\\\\\n\tp(\\alpha_k^m) &= \\Gdist{\\alpha_k^m}{a_0^\\alpha, b_0^\\alpha}\n\\end{align}\nwith hyper-parameters $a_0^\\theta,b_0^\\theta =1$ and $a_0^\\alpha, b_0^\\alpha=1e^{-5}$ to get uninformative priors. Posterior values of $\\theta_k^m$ close to $0$ implies that most of the weights of factor $k$ in view $m$ are shrunk to $0$ (sparse factor). In contrast, a value of $\\theta_k^m$ close to $1$ implies that most of the weights are non-zero (non-sparse factor). A small value of $\\alpha_k^m$ implies that factor $k$ is active in view $m$. In contrast, a large value of $\\alpha_k^m$ implies that factor $k$ is inactive in view $m$.\n\nAll together, the joint probability density function of the model is given by\n\\begin{align}\n\t\\begin{split}\n\tp(\\bfY,\\hat{\\bfW},\\bfS,\\bfZ,\\btheta, \\balpha, \\btau)  = &\\prod_{m=1}^{M} \\prod_{n=1}^{N} \\prod_{d=1}^{D_m} \\Ndist{y_{nd}^m}{\\sum_{k=1}^{K} s_{dk}^m \\hat{w}_{dk}^m z_{nk},1/\\tau_d} \\\\\n\t& \\prod_{m=1}^{M}\\prod_{d=1}^{D_m} \\prod_{k=1}^{K} \\Ndist{\\hat{w}_{dk}^m}{0,1/\\alpha_k^m} \\text{Ber}(s_{d,k}^m|\\theta_k^m) \\\\\n\t& \\prod_{n=1}^{N} \\prod_{k=1}^{K} \\Ndist{z_{nk}}{0,1} \\\\\n\t& \\prod_{m=1}^{M} \\prod_{k=1}^{K} \\Bdist{\\theta_k^m}{a_0^\\theta,b_0^\\theta} \\\\\n\t& \\prod_{m=1}^{M} \\prod_{k=1}^{K} \\Gdist{\\alpha_k^m}{a_0^\\alpha, b_0^\\alpha} \\\\\n\t& \\prod_{m=1}^{M} \\prod_{d=1}^{D_m} \\Gdist{\\tau_d^m}{a_0^\\tau,b_0^\\tau}.\n\t\\label{likelihood}\n\t\\end{split}\n\\end{align}\nand the corresponding graphical model is shown below:\n\n\\begin{figure}[H]\n \t\\begin{center}\n\t\\input{graphical_models/mofa}\n\t% \\label{fig:MOFA_graphical_model}\n\t\\caption{\\textbf{Graphical model for MOFA}. Grey circles represent the observed variables whereas white circles represent hidden variables that are infered by the model. Each plate repsents a dimension of the model: $M$ for the number of views, $N$ for the number of samples, $K$ for the number of factors and $D_m$ for the number of features in the $m$-th view. The use of transparency in the top left nodes is intentional and becomes clear in Chapter 5.}\n\t\\end{center}\n\\end{figure}\n\nThis completes the definition of the MOFA model.\n\n\\subsubsection{Inference}\n\nTo make the model scalable to large datasets we adopt a Variational inference framework with a structured mean field approximation. A detailed overview is given in \\Cref{section:variational_inference}, and details on the variational updates for the MOFA model are given in Appendix~\\ref{appendix:mofa}. To enable efficient inference for non-Gaussian likelihoods we employ local bounds \\cite{Jaakkola2000,Seeger2012}. This is described in detail in \\Cref{section:mofa_ngaussian}.\n\n\\subsubsection{Missing values} \\label{section:mofa_missing_values}\n\nThe probabilistic formulation naturally accounts for incomplete data matrices, as missing observations do not intervene in the likelihood. In practice, we implement this using memory-efficient binary masks $\\mathcal{O}^m \\in \\mathbb{R}^{N\\times D_m}$ for each view $m$, such that $\\mathcal{O}_{n,d} = 1$ when feature $d$ is observed for sample $n$, 0 otherwise. \n\n\\subsection{Downstream analysis} \\label{mofa:downstream}\n\nOnce trained, the MOFA model can be queried for a set of downstream analysis (\\Cref{fig:MOFA}):\n\\begin{itemize}\n\t\\item \\textbf{Variance decomposition}: calculate the variance explained ($R^2$) by each factor in each view. This is the first and arguably the most important plot to be inspected once the model is trained, as it summarises the variation (i.e. the signal) in a complex multi-view data set using a simple heatmap. With a quick visual inspection, this plot can be used to determine which factors are shared between multiple data modalities and which ones are exclusive to a single data modality.\n\n\t\\item \\textbf{Visualisation of the samples on the latent space}: the samples can be visualised in the latent space using beeswarm plots for individual factors or scatterplots for combinations of factors.\n\n\t\\item \\textbf{Inspection of weights}: the feature weights can be interpreted as an importance score for each feature on each factor. Inspecting the top weights for a given factor can reveal the molecular signatures that underlie each factor.\n\n\t\\item \\textbf{Association analysis between factors and external covariates}: multi-omic datasets typically consist of a large set of molecular readouts that are used for model training, and a small set of additionals covariates or response variables such as clinical outcome measurements. The external covariates are not used for model training but they can be linked to the factors \\textit{a posteriori} using a simple association analysis.\n\n\t\\item \\textbf{Imputation}: the latent factors capture a condensed low-dimensional representation of the data that can be used to generate (denoised) reconstructions of the input data. This can be valuable for the inspection of very sparse datasets.\n\n\t\\item \\textbf{Feature set enrichment analysis}: when a factor is difficult to characterise based only on the inspection of the top weights, one can compute a statistical test for enrichment of biological pathways using predefined gene-set annotations.\n\n\\end{itemize}\n\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=1.0\\textwidth]{MOFA}\n\t\t\\caption{\\textbf{MOFA overview}.\\\\\n\t\t(a) The MOFA model takes as input $M$ data matrices ($\\bfY^1, \\cdots, \\bfY^M$), each one representing a separate view or data modality. Samples must be co-occurrent but the features are not necessarily related across data modalities. MOFA performs a multi-view matrix decomposition that results in a matrix of factors ($\\bfZ$) and $M$ matrices of feature weights, one for each data modality ($\\bfW^1, \\cdots, \\bfW^M$).\\\\\n\t\t(b) The trained MOFA model can be queried for different downstream analyses.}\n\t\t\\label{fig:MOFA}\n\t\\end{center}\n\\end{figure}\n\n\\subsubsection{Interpretation of the factors} \\label{section:interpretation_factors}\n\nThe interpretation of the factor values is intuitively similar to that of principal components in PCA. Each factor sorts cells along a one-dimensional axis with a mean of zero. Samples with different signs indicate opposite \\textit{effects} along this source of variation, with higher absolute value indicating a stronger effect.\n\nFor example, if the $k$-th factor captures the variability associated with commitment to cell type X, we could expect cells that belong to cell type X to be at one end of the factor (irrespective of the sign, only the relative positioning being of importance). In contrast, cells that do not belong to cell type X are expected to be at the other end of the factor.\n\n% mention prior \n\n\\subsubsection{Interpretation of the weights} \\label{section:interpretation_weights}\n\nThe weights provide a score for each feature on each factor. Features with no association with the factor are expected to have values close to zero (as specified by the prior distributions). In contrast, features with strong association with the factor are expected to have large absolute values. The sign of the weight indicates the direction of the effect such that a positive weight indicates that the feature is positively associated with the factor values. \n\nFollowing the example above, genes that are upregulated cell type X are expected to have large positive weights, whereas genes that are downregulated in cell type X (or, equivalently, upregulated in the other cell types) are expected to have large negative weights. Genes that do not change in expression between the cell types are expected to have a value of zero.\n\n\\subsubsection{Variance decomposition} \\label{section:variance_decomposition}\n\nThe first step in the downstream analysis is to calculate the percentage of variance explained for each factor $k$ in each view $m$ ($R^{2}_{m,k}$), which can be visualised using a heatmap (see \\Cref{fig:MOFA}b). This is done by adapting the coefficient of determination statistic that is traditionally used for linear regression analysis:\n\\begin{equation*}\n\tR^{2}_{m,k} = 100 \\frac{ (\\sum_{n=1}^{N} \\sum_{d=1}^{D_m} y_{n,d}^{m} - z_{nk} w_{dk}^{m})^2 }{ (\\sum_{n=1}^{N} \\sum_{d=1}^{D_m} y_{n,d}^{m})^2 }\n\\end{equation*}\n\n\\subsection{Model selection and consistency across random initilizations} \\label{section:mofa_robustness}\n\nThe optimisation problem in MOFA is not convex and the resulting posterior distributions depend on the initialisation of the model. Thus, when doing random initialisation of the parameters and/or expectations it becomes mandatory to perform model selection and assess the consistency of the factors across different trials. The strategy we adopted in this work is to train several MOFA models under different parameter initialisations, where the expectation of each node is randomly sampled from its underlying distribution. After fitting, we select the model with the highest ELBO for downstream analysis. In addition, we evaluate the robustness of the factors by plotting the Pearson correlations between factors across all trials (\\Cref{fig:MOFA_robustness}).\n\n\\begin{figure}[H]\n\t\\centering \t\n\t\\includegraphics[width=1.0\\textwidth]{MOFA_robustness}\n\t\\caption{ \\textbf{Model selection and robustness analysis in MOFA}.\\\\\n\tThe left plot the log ELBO (y-axis) for 25 model instances (x-axis). The arrow indicates the model with the highest ELBO that would be selected for downstream analysis. The right plot displays the absolute value of the Pearson correlation coefficient between pairwise combinations of all factors across the 25 model instances. A block-diagonal matrix indicates that factors are robustly estimated regardless of the initialisation.}\n\t\\label{fig:MOFA_robustness}\n\\end{figure}\n\n\n\\subsection{Learning the number of factors} \\label{section:mofa_nfactors}\n\nAs described in \\Cref{section:hierarchical_priors}, the use of an ARD prior allows factors to be actively pruned by the model if their variance explained is negligible. In the implementation we control the pruning of factors by a hyperparameter that defines a threshold on the minimum fraction of variance explained by a factor (across all views). Additionally, because of the non-convexity of the optimisation problem, different model instances can potentially yield solutions with different number of active factors. Thus, the optimal number of factors can be selected by the model selection strategy outlined in \\Cref{section:mofa_robustness}.\n\n\\subsection{Monitoring convergence}\n\nAn attractive property of Variational inference is that the objective function (the ELBO) increases monotonically at every iteration. This provides a simple way of monitoring convergence:\n\\begin{figure}[H]\n\t\\centering \t\n\t\\includegraphics[width=0.5\\textwidth]{elbo_convergence}\n\t\\caption{\\textbf{Training curve for two different instances of MOFA with random initialisations}. The y-axis displays the log of the ELBO, with higher values indicating a better fit. The x-axis displays the iteration number. The horizontal dash lines mark the value of the ELBO upon convergence. }\n\t\\label{fig:elbo_convergence}\n\\end{figure}\n\nTraining is stopped when the change in the lower bound becomes smaller than a predefined threshold.\n\n% COPIED\n%\\subsection{Guidelines for the selection of data modalities} \\label{section:guidelines_views}\n%Data modalities typically correspond to different molecular layers, but the user can also explore data-driven modalities that do not necessarily correspond to different molecular readouts (see for example Figure 3). Analogous to the number of samples per group, the size of the data modality can have an influence on the latent space, such that larger data modalities can contribute more to the latent space than small data modalities, simply because they have larger amounts of variation. The signal that can be extracted from small data modalities will depend on the degree of structure within the dataset, the levels of noise and on how strong the sample imbalance is between data modalities. Hence, in the case of a strong feature imbalance, we recommend the user to subset highly variable features in the large data modalities to maintain the number of features within the same order of magnitude.\n\n\n\\subsection{Modelling and inference with non-Gaussian data} \\label{section:mofa_ngaussian}\n\nGaussian likelihoods are sufficient to model the residuals of most types of continuous data. Thus, when possible, we advise the user to apply data transformations (i.e. $log$ transformation for example) and use the Gaussian likelihood model. However, there are cases where Gaussian likelihoods are not appropriate, even after data transformations, namely binary and (low) count data. However, non-Gaussian likelihoods are problematic because they are not conjugated with prior distributions, and this prevents the use of the efficient variational inference scheme for Gaussian likelihoods (see Appendix~\\ref{appendix:mofa}).\n\nTo implement efficient variational inference in conjunction with a non-Gaussian likelihood we adapt prior work from \\cite{Seeger2012}, where the full derivation can be found. The idea is to approximate non-Gaussian observations by a normally-distributed \\textit{pseudo-data} that is constructed using second-order Taylor expansions. This defines a lower bound that can be improved by adjusting parameters at each iteration. Denoting the parameters in the MOFA model as $\\bfX= (\\bfZ,\\bfW,\\balpha,\\btau,\\btheta)$, recall that the variational framework approximates the posterior $p(\\bfX | \\bfY )$ with a distribution $q(\\bfX)$, which is indirectly optimised by optimising a lower bound of the log model evidence. The resulting optimization problem can be re-written as\n\\begin{equation*}\n\\min_{q(\\bfX)} (-\\Lagr(\\bfX)) =  \\min_{q(\\bfX)} \\E_q \\big[ -\\log p(\\bfY|\\bfX) \\big] + \\KL[q(\\bfX)||p(\\bfX)].\n\\end{equation*}\nLet's now assume a general likelihood function $p(\\bfY|\\bfX)=f(\\bfY|\\bfC)$ with $\\bfC = \\bfZ\\bfW^{T}$ that we can write as\n\\begin{equation*}\n-\\log p(\\bfY|\\bfX) = \\sum_{n=1}^{N} \\sum_{d=1}^{D} f_{nd} (c_{nd})\n\\end{equation*}\nwith $f_{nd}(c_{nd}) = -\\log p(y_{nd}|c_{nd})$. For simplicity in the derivation I will assume a single view and thus drop the index $m$ for clarity.\n\nExtending \\cite{Seeger2012} to our heteroscedastic noise model, we require $f_{nd}(c_{nd})$ to be twice differentiable and upper bounded by a constant $\\kappa_d$. I do not prove this here, but this property holds true in many important models as for example the Bernoulli and Poisson likelihoods, as demonstrated in \\cite{Seeger2012}. Under this assumption a lower bound on the log likelihood can be defined using Taylor expansion:\n\\begin{equation*}\nf_{nd}(c_{nd}) \\leq \\frac{\\kappa_d}{2} (c_{nd} - \\zeta_{nd})^2 + f'(\\zeta_{nd})(c_{nd} - \\zeta_{nd}) + f_{nd}(\\zeta_{nd}) := q_{nd}(c_{nd},\\zeta_{nd}),\n\\end{equation*}\nwhere $\\zeta_{nd}$ are additional variational parameters that determine the location of the Taylor expansion and have to be optimised to make the lower bound as tight as possible. Plugging the bounds into the optimization problem above, we obtain:\n\\begin{equation*}\n\\min_{q(\\bfX),\\bZeta} \\quad \\sum_{d=1}^{D}\\sum_{n=1}^{N} \\E_q [ q_{nd}(c_{nd},\\zeta_{nd})] + \\KL[q(\\bfX)||p(\\bfX)]\n\\end{equation*}\n\nThe new objective function has two class of parameters to optimise: the parameters associated with the local bounds $\\bZeta$, and the parameters associated with the model $(\\bfX)$.\nThe algorithm proposed in \\cite{Seeger2012} alternates between updates of $\\bZeta$ and $\\mathrm{q}(\\bTheta)$. The update for $\\bZeta$ is given by\n\\begin{equation*}\n\\zeta \\leftarrow \\E[\\bfZ]\\E[\\bfW]^{T}\n\\end{equation*}\nwhere the expectations are taken with respect to the corresponding $q$ distributions.\\\\\n% In order to find the updates for $q(\\bTheta)$ we bring the taylor approximation of $q(f_{nd})$ in q audratic form:\n% \\begin{equation*}\n% q(f_{nd},\\zeta_{nd}) \\propto \\frac{\\kappa_d}{2}(f_{nd} - (zeta_{nd} - g(\\zeta_{nd})/\\kappa_d))^2\n% \\end{equation*}\n% and note that this is proportional to the log of a Gaussian distribution $-log \\Normal (\\hat{y}_{nd}|f_{ng},\\frac{1}{ng})$ where $\\hat{y}_{nd} = zeta_{nd} - g'(\\zeta_{nd})/\\kappa_d$ is defined as a pseudodata based on the zero-inflated observations.\n% Consequently, for fixed $\\zeta_{nd}$, the updates of the variational distributions $Q(X)$ and $Q(W)$ are equivalent to the ones derived in X, but with pseudodata $\\hat{Y}$ and precision $\\kappa_g$\nOn the other hand, the updates for $q(\\bfX)$ are identical to the standard variational Bayesian updates with Gaussian likelihoods, but with the observed data $\\bfY$ replaced by the \\textit{pseudo-data} $\\hat{\\bfY}$ and where the precisions $\\tau_{nd}$ (which were treated as random variables) are replaced by the constant terms $\\kappa_d$ introduced above. This might seem a minor change, but it is very important. In the Gaussian case the model infers a variance parameter for each feature which means that MOFA explicitly models heteroscedastic noise, but when using non-Gaussian likelihoods this is no longer possible.\n\nFinally, the general formula pseudodata is given by (derived in \\cite{Seeger2012}):\n\\begin{equation*}\n\\hat{y}_{nd} = \\zeta_{nd} - f'(\\zeta_{nd})/\\kappa_d\n\\end{equation*}\nwhere different log likelihood functions $f(\\cdot)$ yield different $\\kappa_d$ values. \n\nIn MOFA we implemented a Bernoulli likelihood model for binary data and a Poisson likelihood model for (low) count data.\n\n\\subsubsection*{Bernoulli likelihood for binary data}\n\nWhen the observations are binary, $y \\in \\{0,1\\}$, they can be modelled using a Bernoulli likelihood:\n\\begin{equation*}\n\tp(y|c) = \\frac{e^{yc}}{1+e^c}\n\\end{equation*}\nThe second derivative of the log likelihood is bounded by:\n\\begin{equation*}\n\tf''(c) = \\sigma(c)\\sigma(-c) \\leq 1/4 := \\kappa\n\\end{equation*}\nwhere $\\sigma$ is the sigmoid function $f(c) = 1/(1+e^{-c})$. \n\nThe pseudodata updates are given by\n\\begin{equation*}\n\t\\hat{y}_{nd} = \\zeta_{nd} - 4*(\\sigma(\\zeta_{nd}) - y_{nd})\n\\end{equation*}\n\n% \\begin{equation*}\n% \\bfY|\\bfZ,\\bfW \\sim \\text{Ber}(\\sigma(\\bfZ\\bfW^T)),\n% \\end{equation*} \n% where $\\sigma(a)=(1+e^{-a})^{-1}$ is the logistic link function and $\\bfZ$ and $\\bfW$ are the latent factors and weights, respectively. \n\n% As an approximation, here we adopt the Jaakkola upper bound \\cite{Jaakkola2000} on the negative log-likelihood. Denoting $c_{nd}=(\\bfZ\\bfW^T)_{nd}$ this is given by:\n% \\begin{align*} \\label{jaakkola}\n% \t\\begin{split}\n% \t\t-\\log\\left(p(y_{nd}|c_{nd})\\right) &= -\\log\\left(\\sigma\\left((2y_{nd}-1)  c_{nd}\\right)\\right)\\\\\n% \t\t& \\leq -\\log(\\zeta_{nd})-\\frac{(2y_{nd}-1)c_{nd}-\\zeta_{nd})}{2} +\\lambda(\\zeta_{nd})\\left(c_{nd}^2 -\\zeta_{nd}^2 \\right)\\\\\n% \t\t& =: b_J(\\zeta_{nd}, c_{nd},y_{nd} )\n% \t\\end{split}\n% \\end{align*}\n% with $\\lambda$ given by $\\lambda(\\zeta)=\\frac{1}{4\\zeta}\\tanh\\left(\\frac{\\zeta}{2}\\right)$.\\\\\n% This can easily be derived from a first-order Taylor expansion on the function $f(x) = - \\log(e^{\\frac{x}{2}}+e^{-\\frac{x}{2}}) = \\frac{x}{2}-\\log(\\sigma(x))$ in $x^2$ and by the convexity of \n% $f$ in $x^2$ this bound is global as discussed in \\cite{Jaakkola2000}.\\\\\n% In order to make use of this tighter bound but still be able to re-use the variational updates from the Gaussian case we re-formulate the bound as a Gaussian likelihood on pseudo-data $\\hat{\\bfY}$.\\\\\n% As above we can plug this bound on the negative log-likelihood into the variational optimization problem to obtain  \\begin{equation*}\n% \\min_{q(\\bfX),\\bZeta} \\quad \\sum_{d=1}^{D}\\sum_{n=1}^{N} \\mathbb{E}_q b_J(\\zeta_{nd}, c_{nd},y_{nd} ) + \\KL[q(\\bfX)||p(\\bfX)].\n% \\end{equation*}\n% This is minimized iteratively in the variational parameter $\\zeta_{nd}$ and the variational distribution of Z,W:\\\\\n% Minimizing in the variational parameter $\\zeta$ this leads to the updates given by\n% \\begin{equation*}\n% \t\\zeta_{nd}^2 = \\mathbb{E}[c_{nd}^2]\n% \\end{equation*}\n% as described in \\cite{Jaakkola2000}, \\cite{Bishop2006}.\\\\\n% For the variational distribution $q(\\bfZ,\\bfW)$ we observe that the Jaakkola bound can be re-written as \n% \\begin{equation*}\n% \tb_J(\\zeta_{nd}, c_{nd},y_{nd} ) = -\\log\\left(\\varphi\\left(\\hat{y}_{nd}; c_{nd}, \\frac{1}{2\\lambda(\\zeta_{nd})}\\right)\\right) + \\gamma(\\zeta_{nd}),\n% \\end{equation*}\n% where $\\varphi(\\cdot; \\mu, \\sigma^2)$ denotes the density function of a normal distribution with mean $\\mu$ and variance $\\sigma^2$ and $\\gamma$ is a term only depending on $\\bZeta$. This allows us to re-use the updates for $\\bfZ$ and $\\bfW$ from a setting with Gaussian likelihood by considering the Gaussian pseudo-data \n% \\begin{equation*}\n% \t\\hat{y}_{nd}= \\frac{2y_{nd}-1}{4 \\lambda(\\zeta_{nd})}\n% \\end{equation*}\n% updating the data precision as $\\tau_{nd} = 2\\lambda(\\zeta_{nd})$ using  updates generalized for sample- and feature-wise precision parameters on the data.\n\n\n\\subsubsection*{Poisson likelihood for count data}\n\nWhen observations are natural numbers, such as count data $y \\in \\N = \\{0,1,\\cdots\\}$, they can be modelled using a Poisson likelihood:\n\\begin{equation*}\n\tp(y|c) = \\lambda(c)^y e^{-\\lambda(c)}\n\\end{equation*}\nwhere $\\lambda(c)>0$ is a convex rate function. As done in \\cite{Seeger2012}, here we adopt the rate function $\\lambda(c)=\\log(1+e^c)$, which yields the following upper bound of the second derivative of the log-likelihood:\n\\begin{equation*}\n\tf''_{nd}(c_{nd}) \\leq \\kappa_d = 1/4 + 0.17*\\max(\\bfy_{:,d}).\n\\end{equation*}\n%The bound degrades with the presence of entries with large values. Thus, we follow common practice and clip overly large counts.\\\\\nThe pseudodata updates are given by\n\\begin{equation*}\n\t\\hat{y}_{nd} = \\zeta_{nd} - \\frac{\\mathrm{S}(\\zeta_{nd})(1-y_{nd}/\\lambda(\\zeta_{nd}))}{\\kappa_d}.\n\\end{equation*}\n\n\\pagebreak\n\t \n\\subsection{Theoretical comparison with published methods}\n\nA variety of latent variable models exist with the aim of perfoming multi-view data integration, most of them inspired by the Group Factor Analysis formulation. A summary is provided in the table below. MOFA is the only method that scales to large datasets (employs Variational Bayes inference instead of MCMC-based approaches), has a combination of ARD and spike-slab regularisation on the weights, and is also capable of handling non-gaussian modalities and missing values.\n\n\\begin{table}[H]\n\t\\begin{tabular}{@{}lllllll} \n\t\t\\toprule\n\t\t{\\textbf{Publication}} & {\\textbf{Inference}} & {\\textbf{\\parbox{2.1cm}{View-wise\\\\ sparsity}}} & {\\textbf{\\parbox{2.4cm}{Feature-wise\\\\ sparsity}}} & {\\textbf{\\parbox{1.3cm}{Missing\\\\ values}}} & {\\textbf{Likelihood}} &  \\parbox{1.5cm}{{\\textbf{Noise\\\\ model}}} \\\\ \\toprule\n\t\t\\parbox{2.2cm}{Shen2009} & \\parbox{2.1cm}{EM,\\\\ grid search} & \\parbox{2.1cm}{$L_1$- penalties} & $L_1$-penalty & No & Gaussian & \\parbox{1.5cm}{Hetero-\\\\scedastic} \\\\\\midrule\n\t\t\\parbox{2.2cm}{Mo2013} &  \\parbox{2.1cm}{EM,\\\\ grid search} & \\parbox{2.1cm}{$L_1$- penalties} & $L_1$-penalty & No &\\parbox{2cm}{Gaussian,\\\\Poisson,\\\\Bernoulli}  & \\parbox{1.5cm}{Hetero-\\\\scedastic} \\\\\\midrule\n\t\t\\parbox{2.2cm}{Virtanen2012} & VB & ARD & None & No & Gaussian & \\parbox{1.5cm}{Homo-\\\\scedastic} \\\\\\midrule\n\t\t\\parbox{2cm}{Klami2014} & VB & ARD & None & No & Gaussian & \\parbox{1.5cm}{Homo-\\\\scedastic} \\\\ \\midrule\n\t\t\\parbox{2cm}{Bunte2016}  & Gibbs & ARD & Spike-Slab & No & Gaussian & \\parbox{1.5cm}{Homo-\\\\scedastic} \\\\ \\midrule\n\t\t\\parbox{2cm}{Hore2016}  & VB  & None & Spike-Slab & Yes  & Gaussian & \\parbox{1.5cm}{Hetero-\\\\scedastic}  \\\\ \\midrule\n\t\t\\parbox{2cm}{Remes2016}  & VB & ARD & None & No & Gaussian & \\parbox{1.5cm}{Homo-\\\\scedastic} \\\\ \\midrule\n\t\t\\parbox{1.7cm}{Zhao2015} & Gibbs & ARD & \\parbox{2.5cm}{Three-parameter\\\\ beta prior} & No & Gaussian & \\parbox{1.5cm}{Hetero-\\\\scedastic} \n\t\t\\\\ \\midrule\n\t\t\\parbox{2.6cm}{Leppaaho2017} & {Gibbs} & {ARD} & {Spike-Slab} & {Yes} & {Gaussian} & \\parbox{2cm}{{Homo-}\\\\{scedastic}} \\\\ \\midrule\n\t\tMOFA  & VB & ARD & Spike-Slab & Yes & \\parbox{2cm}{Gaussian,\\\\Poisson,\\\\Bernoulli} & \\parbox{2cm}{Hetero-\\\\scedastic} \\\\  \\bottomrule\n\t\\end{tabular}\n\t\\caption{\\textbf{Overview of latent variable methods for multi-view data integration.} Abbreviations used: VB (variational Bayes inference), Gibbs (Gibbs sampling based inference), ARD(Automatic Relevance Determination)}\n\t\\label{GFAtable}\n\t\t\t\t\t\t\t\t\n\\end{table}\n\n% \\subsection{A note on the implementation}\n% The core of MOFA is implemented in Python, and the downstream analysis and visualisations are implemented in R. To facilitate adoption of the method, we deployed MOFA as open-source software available from Bioconductor\\footnote{\\url{https://www.bioconductor.org/packages/release/bioc/html/MOFA.html}} with multiple tutorials and a web-based analysis workbench\\footnote{\\url{http://www.ebi.ac.uk/shiny/mofa/}}.\n", "meta": {"hexsha": "cc3fc14cb75e58f8a93e0d9ddc1e25d6eff4a960", "size": 28327, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter2/model_description.tex", "max_stars_repo_name": "rargelaguet/thesis", "max_stars_repo_head_hexsha": "ff3f7b996710c06d6924b7e780a4a9531651a3a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-01-08T13:01:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T07:24:40.000Z", "max_issues_repo_path": "Chapter2/model_description.tex", "max_issues_repo_name": "rargelaguet/thesis", "max_issues_repo_head_hexsha": "ff3f7b996710c06d6924b7e780a4a9531651a3a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter2/model_description.tex", "max_forks_repo_name": "rargelaguet/thesis", "max_forks_repo_head_hexsha": "ff3f7b996710c06d6924b7e780a4a9531651a3a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-01-09T04:47:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-04T08:25:50.000Z", "avg_line_length": 90.5015974441, "max_line_length": 903, "alphanum_fraction": 0.7445546652, "num_tokens": 8215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133515091156, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7478496737628856}}
{"text": "\\documentclass[../research.tex]{subfile}\n\n\\subsection{Topological Manifolds}\n\\label{sec:3.1}\n\n  \\begin{prop}\n    We say a topological space $X$ is \\textnormal{second-countable} if the topology has a countable basis.\n\n    $\\R^n$ is second-countable.\n  \\end{prop}\n\n  \\begin{proof}\n    The set of open balls\n    $$S=\\{B_r(q):r\\in\\mathbb{Q},q\\in\\mathbb{Q}^n\\}$$\n    forms a basis for the Euclidean topology, since any real open ball $B_\\epsilon(x)$, where \n    $\\epsilon\\in\\R$ and $x\\in\\R^n$, is a countable union of open balls $(B_{r_i}(q_i))_{i\\in\\N}\\in \n    S$, where each $B_{r_i}(q_i)\\subset B_\\epsilon(x)$.\n  \\end{proof}\n\n  \\begin{definition}[Chart]\n    Let $M$ be a second-countable topological space. A \\textit{chart}, $(U,E,\\varphi)$, is an ordered \n    tuple of open subsets $U\\subset M,E\\subset\\R^n$ and a homeomorphism $\\varphi:U\\to E$.\n  \\end{definition}\n\n  \\begin{definition}[Atlas and manifold]\n    An \\textit{atlas} of $M$ is a collection of charts $\\{(U_i,E_i,\\varphi_i):i\\in I\\}$ such that the \n    $U_i$ cover $M$. I.e.,\n    $$\\bigcup_{i\\in I}{U_i}=M.$$\n    Then $M$ is said to be an \\textit{$n$-manifold} which, colloquialy, is said to be locally homeomorphic \n    to $\\R^n$.\n  \\end{definition}\n\n  \\begin{example}\n    The 2-sphere, \n    $$S^2=\\{x^2+y^2+z^2=r^2:x,y,z\\in\\R^3,r>0\\},$$\n    can be contructed as follows: \\\\\n    \n    We define an equivalence relation, $\\sim$ , on the 2-disk, \n    $$D^2=\\{x^2+y^2\\leq r^2:x,y\\in\\R^2,r>0\\},$$\n    by $x\\sim y\\text{ if and only if }x^2+y^2=r^2.$\n    Then the quotient space $D^2/\\sim$ is homeomorphic to $S^2$.\n\n    This amounts to ``gluing'' together the boundary points of $D^2$. $S^2$ is 2-manifold, that is, \n    locally homeomorphic to $\\R^2$.\n  \\end{example}\n\n  \\begin{definition}[Transition map]\n    Given two charts $(U_1,E_1,\\varphi_1),(U_2,E_2,\\varphi_2)$ such that $U_1\\cap U_2\\neq\\varnothing$, \n    we define the \\textit{transition map} between them by   \n    $$\\tau_{1,2}:\\varphi_1(U_1\\cap U_2)\\to\\varphi_2(U_1\\cap U_2).$$\n\n    Clearly $\\tau_{1,2}$ is a homeomorphism, since $\\tau_{1,2}=\\varphi_2\\circ\\varphi_1^{-1}$. Hence \n    $\\tau_{1,2}^{-1}=\\varphi_1\\circ\\varphi_2^{-1}:=\\tau_{2,1}$ is also a homeomorphism. Transition \n    maps give us a way of ``moving'' throughout an $n$-manifold in way that resembles \n    moving through $n$-dimensional Euclidean space.\n  \\end{definition}\n\n\\subsection{Differentiable Manifolds}\n\\label{sec:3.2}\n\n  \\begin{definition}[Differentiable manifold]\n    We say a topological $n$-manifold $M$ is \\textit{differentiable} if, for every pair of charts \n    $(U_i,E_i,\\varphi_i),(U_j,E_j,\\varphi_j)$ such that $U_i\\cap U_j\\neq\\varnothing$, the transition \n    maps $\\tau_{ij},\\tau_{ji}$ are differentiable in $\\R^n$. That is, all their partial derivatives \n    exist and are continuous.\n    % We call $\\tau_{ij}$ and $\\tau_{ji}$ \\textit{diffeomorphisms}, and say \n    % that $\\varphi_i(U_i\\cap U_j)$ and $\\varphi_j(U_i\\cap U_j)$ are \\textit{diffeomorphic}.\n  \\end{definition}\n\n  \\begin{definition}[Differentiable function]\n    Let $M$ be a differentiable $m$-manifold, $N$ a differentiable $n$-manifold, and $f:M\\to N$ a continuous function. Fix charts \n    $(U_1,E_1,\\varphi_1)$, $(U_2,E_2,\\varphi_2)$ be charts for $M$, $N$ respectively. We say that\n    $f$ is \\textit{differentiable} if the function \n    $$\\varphi_2\\circ f\\circ\\varphi_1^{-1}:\\R^m\\to\\R^n$$\n    is differentiable.\n\n    If $f$ is a homeomorphism, and $\\varphi_1\\circ f\\circ\\varphi_2^{-1}:\\R^n\\to\\R^m$ differentiable, then \n    we say $f$ is a \\textit{diffeomorphism}, and $M$ and $N$ are \\textit{diffeomorphic}.\n\n    Note this requires $m=n$, so that the Jacobian matrix of $\\varphi_2\\circ f\\circ\\varphi_1^{-1}$ is \n    invertible.\n  \\end{definition}\n\n  \\begin{example}\n    If we let $N=\\R^n$, then $f:M\\to\\R^n$ is differentiable if the function $f\\circ\\varphi^{-1}:\\R^m\n    \\to\\R^n$ is differentiable, for all charts $(U,E,\\varphi)$ of $M$.\n  \\end{example}\n\n  Given an $n$-dimensional differentiable manifold $M$, we can attach to every point of $M$ a \n  ``tangent space'' - a vector space isomorphic to $\\R^n$.\n\n  \\begin{definition}[Tangent space]\n    Fix $x\\in M$, and choose any chart $(U,E,\\varphi)$ with $x\\in U$. Let $\\Gamma$ be the set of \n    continuous and injective curves passing through $x$. That is,\n    $$\\Gamma=\\{\\gamma_i:(-1,1)\\to M:i\\in I\\text{ s.t. }\\gamma_i(0)=x\\}.$$\n    We then define an equivalence relation, $\\sim$ , on $\\Gamma$ by:\n    $$\\gamma_1\\sim\\gamma_2\\text{ if and only if }(\\varphi\\circ\\gamma_1)'(0)=(\\varphi\\circ\\gamma_2)'(0).$$\n    Then the \\textit{tangent space}, $T_xM$, is equal to the quotient space $\\Gamma/\\sim$. We call \n    the equivalence classes in $T_xM$ \\textit{tangent vectors}, which we denote $\\gamma_i':=[\\gamma_i]$.\n  \\end{definition}\n\n  \\textbf{Remark:} The definition of $\\Gamma$ is somewhat arbitrary. More generally, we can define \n  $$\\Gamma=\\{\\gamma_i:(a,b)\\to M:i\\in I\\text{ s.t. }\\gamma_i(c)=x\\},$$\n  where $a,b\\in\\R,a<b$, and $c\\in(a,b)$. Then $\\gamma_1\\sim\\gamma_2\\text{ if and only if }\n  (\\varphi\\circ\\gamma_1)'(c)=(\\varphi\\circ\\gamma_2)'(c),$ and we denote the tangent vectors $\\gamma_i'(c)$.\n\n  \\begin{prop}\n    If we define vector addition and scalar multiplication in $T_xM$ by \n    $$\\gamma_1'+\\lambda\\gamma_2':=\\{\\gamma:(\\varphi\\circ\\gamma)'(0)=(\\varphi\\circ\\gamma_1)'(0)\n    +\\lambda(\\varphi\\circ\\gamma_2)'(0),\\text{ where }\\gamma_1\\in\\gamma_1',\\gamma_2\\in\\gamma_2',\\lambda\\in\\R\\},$$\n    the identity element in $T_xM$ as the equivalence class of constant curves:\n    \\begin{align*}\n      \\gamma_0'&=\\{\\gamma:\\gamma(t)=c\\in U,\\,\\forall t\\in (-1,1)\\} \\\\\n               &=\\{\\gamma:(\\varphi\\circ\\gamma)'(0)=0\\},\n    \\end{align*}\n    and the inverse of $\\gamma'$ by\n    $$-\\gamma':=\\{-\\gamma:(\\varphi\\circ(-\\gamma))'(0)=-(\\varphi\\circ\\gamma)'(0),\\text{ where }\\gamma\\in\\gamma'\\}.$$\n    Then $T_xM\\cong\\R^n$.\n  \\end{prop}\n\n  \\begin{definition}[Directional derivative]\n    Given a differentiable $n$-manifold $M$ and a differentiable function $f:M\\to\\R^n$, we define \n    the \\textit{directional derivative} of $f$ in the direction $\\gamma'$ as \n    $$D_\\gamma(f):=(f\\circ\\gamma)'(0),\\,\\forall\\gamma\\in\\gamma'.$$\n  \\end{definition}\n\n  \\begin{definition}[Pushforward]\n    If $\\varphi:M\\to N$ is a differentiable function of differentiable manifolds, then we define the \n    \\textit{pushforward} of $\\varphi$ at $x$ as the linear map \n    $$d\\varphi_x:T_xM\\to T_{\\varphi(x)}N,$$\n    defined by $d\\varphi_x(\\gamma')=(\\varphi\\circ\\gamma)'(0)\\,\\,\\forall\\gamma\\in\\gamma'$.\n  \\end{definition}\n\n  \\subsubsection{Lie groups}\n  \\label{sec:3.2.1}\n\n  \\begin{definition}[Lie group]\n  \\end{definition}\n", "meta": {"hexsha": "4027d486eec5d86a57e9c4eff2e03c9eadd2b6f3", "size": 6623, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03-manifolds.tex", "max_stars_repo_name": "Jerrycaster/maths", "max_stars_repo_head_hexsha": "29706561f90442846e67348a75094e840a8124b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "03-manifolds.tex", "max_issues_repo_name": "Jerrycaster/maths", "max_issues_repo_head_hexsha": "29706561f90442846e67348a75094e840a8124b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "03-manifolds.tex", "max_forks_repo_name": "Jerrycaster/maths", "max_forks_repo_head_hexsha": "29706561f90442846e67348a75094e840a8124b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.6474820144, "max_line_length": 130, "alphanum_fraction": 0.6524233731, "num_tokens": 2359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392786908831, "lm_q2_score": 0.8459424334245617, "lm_q1q2_score": 0.7478463386586599}}
{"text": "%!TEX root=report.tex\n\\subsection{Phase and Amplitude}\n\nThe $\\hat{\\beta}$ parameter in the OLS problem contains the coefficients to the linear combinations of $\\cos(\\omega_i t)$ and $\\sin(\\omega_i t)$, there is are used to predict $Y$.\nSince there is a cosine and sine for each frequency in the design matrix $X$, one will end up with a linear combination of frequency function pairs. This makes interpretation difficult.\nInstead one should convert the $\\beta$ parameters for the trigonometric functions into amplitudes and phases corresponding to each pair of periodic functions such that only a cosine  $A_i \\cos(\\omega_i t - \\phi_i)$ is needed.\nThis is done by using Ptolemy's theorem\n\\begin{equation}\nA_i \\cos(\\omega_i t - \\phi_i) = A_i \\cos(\\phi_i) \\cos(\\omega_i t) + A_i \\sin(\\phi_i) \\sin(\\omega_i t).\n\\end{equation}\n\nComparing with the linear combination from OLS\n\\begin{align}\n\\hat{Y} = \\cdots + \\beta_{c,i} \\cos(\\omega_i t) + \\beta_{s,i} \\sin(\\omega_i t) + \\cdots\n\\end{align}\nIt is seen that\n\\begin{align}\n\\beta_{c,i} = A_i \\cos(\\phi_i) && \\text{ and } && \\beta_{s,i} = A_i \\sin(\\phi_i).\n\\end{align}\n\nBy dividing these two equations with each other, $\\phi_i$ can be calculated as \n\\begin{equation}\n\\frac{A_i \\sin(\\phi_i)}{A_i \\cos(\\phi_i)} = \\frac{\\beta_{s,i}}{\\beta_{c,i}} \\Rightarrow \\phi_i = \\arctan\\left(\\frac{\\beta_{s,i}}{\\beta_{c,i}}\\right).\n\\end{equation}\n\nTo isolate $A_i$, square both equations and add them together\n\\begin{equation}\nA_i^2 \\cos(\\phi_i)^2 + A_i^2 \\sin(\\phi_i)^2 = \\beta_{c,i}^2 + \\beta_{s,i}^2 \\Rightarrow A_i = \\sqrt{\\beta_{c,i}^2 + \\beta_{s,i}^2}.\n\\end{equation}\n\nThe result can be plotted with a circular color scale, using $\\phi_i$ (the hue) and $A_i$ (the intensity).\n", "meta": {"hexsha": "9aded53232faf1ddee06e763fdd10d2184787222", "size": 1707, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rapport/theory-hsv.tex", "max_stars_repo_name": "AndreasMadsen/grace", "max_stars_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-17T22:52:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-17T22:52:19.000Z", "max_issues_repo_path": "Rapport/theory-hsv.tex", "max_issues_repo_name": "AndreasMadsen/grace", "max_issues_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Rapport/theory-hsv.tex", "max_forks_repo_name": "AndreasMadsen/grace", "max_forks_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.34375, "max_line_length": 225, "alphanum_fraction": 0.7070884593, "num_tokens": 545, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7476370442468311}}
{"text": "\\addcontentsline{toc}{chapter}{Appendices}\n\n% The \\appendix command resets the chapter counter, and changes the chapter numbering scheme to capital letters.\n%\\chapter{Appendices}\n\\appendix\n\\chapter{Derivations}\n\\label{ap:derivations}\n% \\section{Classical Limit of Nuclear TDSE \\label{ap:polar_X}}\n% The time-dependent nuclear Schr\\\"odinger equation:\n% \\[i \\ \\hbar \\frac{\\delta}{\\delta t} \\chi (\\textbf{R}, t) = \\left( \\sum_{\\nu = 1}^{N_{n}} \\frac{[-i \\ \\hbar\\nabla_{\\nu} + \\textbf{A}_{\\nu}(\\textbf{R}, t)]^2}{2 M_{\\nu}} + \\epsilon(\\textbf{R}, t)\\right) \\chi (\\textbf{R}, t)\\]\n% Substituting the polar form $\\chi(\\textbf{R}, t) = |\\chi(\\textbf{R}, t)|e^{\\frac{i}{\\hbar}S(\\textbf{R}, t)}$\n% \\[i \\ \\hbar \\frac{\\delta}{\\delta t} |\\chi(\\textbf{R}, t)|e^{\\frac{i}{\\hbar}S(\\textbf{R}, t)} = \\left( \\sum_{\\nu = 1}^{N_{n}} \\frac{[-i \\ \\hbar\\nabla_{\\nu} + \\textbf{A}_{\\nu}(\\textbf{R}, t)]^2}{2 M_{\\nu}} + \\epsilon(\\textbf{R}, t)\\right) |\\chi(\\textbf{R}, t)|e^{\\frac{i}{\\hbar}S(\\textbf{R}, t)}\\]\n% We can remove the dependencies to neaten the equations up:\n% \\[i \\ \\hbar \\frac{\\delta}{\\delta t} |\\chi|e^{\\frac{i}{\\hbar}S} = \\left( \\sum_{\\nu = 1}^{N_{n}} \\frac{[-i \\ \\hbar\\nabla_{\\nu} + \\textbf{A}_{\\nu}]^2}{2 M_{\\nu}} + \\epsilon \\right) |\\chi |e^{\\frac{i}{\\hbar}S}\\]\n% Using chain rule to expand the time-derivative:\n% \\[i \\ \\hbar (|\\dot{\\chi}|e^{\\frac{i}{\\hbar}S} + |\\chi|\\dot{e^{\\frac{i}{\\hbar}S}}) = \\left( \\sum_{\\nu = 1}^{N_{n}} \\frac{[-i \\ \\hbar\\nabla_{\\nu} + \\textbf{A}_{\\nu}]^2}{2 M_{\\nu}} + \\epsilon \\right) |\\chi |e^{\\frac{i}{\\hbar}S}\\]\n% ...\n% \\[i \\ \\hbar (|\\dot{\\chi}|e^{\\frac{i}{\\hbar}S} + |\\chi|\\frac{i}{\\hbar}\\dot{S} e^{\\frac{i}{\\hbar}S}) = \\left( \\sum_{\\nu = 1}^{N_{n}} \\frac{[-i \\ \\hbar\\nabla_{\\nu} + \\textbf{A}_{\\nu}]^2}{2 M_{\\nu}} + \\epsilon \\right) |\\chi |e^{\\frac{i}{\\hbar}S}\\]\n% Tidying up the LHS a bit and removing totally imaginary parts:\n% \\[\\cancel{i \\ \\hbar |\\dot{\\chi}|e^{\\frac{i}{\\hbar}S}} - |\\chi|\\dot{S} e^{\\frac{i}{\\hbar}S} = \\left( \\sum_{\\nu = 1}^{N_{n}} \\frac{[-i \\ \\hbar\\nabla_{\\nu} + \\textbf{A}_{\\nu}]^2}{2 M_{\\nu}} + \\epsilon \\right) |\\chi |e^{\\frac{i}{\\hbar}S}\\]\n% Expanding out the squared bracket in the RHS:\n% \\[- |\\chi| \\dot{S} e^{\\frac{i}{\\hbar}S} = \\left( \\sum_{\\nu = 1}^{N_{n}} \\frac{(-i \\ \\hbar\\nabla_{\\nu})^2 + \\textbf{A}_{\\nu}^2 - i \\ \\hbar (\\nabla_{\\nu}\\textbf{A}_{\\nu}) -i \\ \\hbar \\textbf{A}_{\\nu}\\nabla_{\\nu}) }{2 M_{\\nu}} + \\epsilon \\right) |\\chi |e^{\\frac{i}{\\hbar}S}\\]\n% Treating just the RHS (multiplying out the bracket):\n% \\begin{dmath*}\n%   - |\\chi| \\dot{S} e^{\\frac{i}{\\hbar}S} = \\left( \\sum_{\\nu = 1}^{N_{n}} \\frac{1}{2 M_{\\nu}}\\left(\n%   \\underbrace{(- \\hbar^2 \\nabla_{\\nu}^2 |\\chi |e^{\\frac{i}{\\hbar}S})}_{(1)}\n%   + \\underbrace{(\\textbf{A}_{\\nu}^2|\\chi |e^{\\frac{i}{\\hbar}S})}_{(2)}\n%   - \\underbrace{(2 i \\ \\hbar \\nabla_{\\nu}\\textbf{A}_{\\nu} |\\chi |e^{\\frac{i}{\\hbar}}S)}_{(3)}\n%  \\right) + \\epsilon |\\chi |e^{\\frac{i}{\\hbar}S} \\right)\n% \\end{dmath*}\n%\n% \\noindent Treating term 1 and 3 seperately:\n%\n% \\subsection{Term 1 \\label{ap:polar_X_4}}\n% \\[TERM \\ 1 = -\\hbar^2\\nabla^2_{\\nu}|\\chi |e^{\\frac{i}{\\hbar}S}\\]\n% Taking a single derivative:\n% \\[TERM \\ 1 = -\\hbar^2\\nabla_{\\nu}\\left[ \\nabla_{\\nu}(|\\chi |)e^{\\frac{i}{\\hbar}S} + |\\chi |\\nabla_{\\nu}(e^{\\frac{i}{\\hbar}S}) \\right]\\]\n% Using chain rule:\n% \\[TERM \\ 1 = -\\hbar^2\\nabla_{\\nu}\\left[ \\nabla_{\\nu}(|\\chi |)e^{\\frac{i}{\\hbar}S} + |\\chi|\\frac{i}{\\hbar}e^{\\frac{i}{\\hbar}S} \\nabla_{\\nu}(S)  \\right]\\]\n% Taking the derivative again:\n% \\[TERM \\ 1 = -\\hbar^2\\left[(\\nabla_{\\nu}^2|\\chi |)e^{\\frac{i}{\\hbar}S} + (\\nabla_{\\nu}|\\chi |)\\frac{i}{\\hbar}e^{\\frac{i}{\\hbar}S} (\\nabla_{\\nu} S) + (\\nabla_{\\nu}|\\chi|)\\frac{i}{\\hbar}e^{\\frac{i}{\\hbar}S} (\\nabla_{\\nu} S) + |\\chi|\\frac{-1}{\\hbar^2}e^{\\frac{i}{\\hbar}S} (\\nabla_{\\nu}^2 S) \\right] \\]\n% Tidying up (taking the $e^{\\frac{i}{\\hbar}S}$ outside the bracket, gathering like terms and removing imaginary terms):\n% \\[TERM \\ 1 = -\\hbar^2\\left[\\nabla_{\\nu}^2|\\chi | + \\cancel{\\frac{2i}{\\hbar} (\\nabla_{\\nu}|\\chi |\\nabla_{\\nu} S)} - \\frac{|\\chi|}{\\hbar^2}(\\nabla_{\\nu}^2 S) \\right] e^{\\frac{i}{\\hbar}S} \\]\n% \\[TERM \\ 1 = -\\hbar^2\\left[\\nabla_{\\nu}^2|\\chi | - \\frac{|\\chi|}{\\hbar^2}  (\\nabla_{\\nu}^2 S)\\right] e^{\\frac{i}{\\hbar}S}\\]\n%\n% \\subsection{Term 3 \\label{ap:polar_X_2}}\n% \\[TERM \\ 3  = 2 i \\ \\hbar \\nabla_{\\nu}\\textbf{A}_{\\nu} |\\chi |e^{\\frac{i}{\\hbar}}S\\]\n% Using chain rule (and cancelling imaginary terms)\n% \\[TERM \\ 3  = 2 i \\ \\hbar \\left[ \\cancel{\\nabla_{\\nu}\\textbf{A}_{\\nu} |\\chi |e^{\\frac{i}{\\hbar}}S} + \\cancel{\\textbf{A}_{\\nu} \\nabla_{\\nu}|\\chi |e^{\\frac{i}{\\hbar}}S} + \\textbf{A}_{\\nu} |\\chi |\\nabla_{\\nu}e^{\\frac{i}{\\hbar}}S\\right]\\]\n% ...\n% \\[TERM \\ 3 = 2 i \\ \\hbar \\textbf{A}_{\\nu} |\\chi |\\frac{i}{\\hbar}e^{\\frac{i}{\\hbar}S} \\nabla_{\\nu}S \\]\n% Tidying up:\n% \\[TERM \\ 3 = -2 |\\chi |e^{\\frac{i}{\\hbar}S} \\textbf{A}_{\\nu} \\nabla_{\\nu}S \\]\n% \\subsection{Putting it all together \\label{ap:Polar_X_final}}\n% \\begin{dmath*}\n%   - |\\chi| \\dot{S} e^{\\frac{i}{\\hbar}S} = \\left( \\sum_{\\nu = 1}^{N_{n}} \\frac{1}{2 M_{\\nu}}\\left(\n%   -\\hbar^2\\left[\\nabla_{\\nu}^2|\\chi | - \\frac{|\\chi|}{\\hbar^2}  (\\nabla_{\\nu}^2 S)\\right] e^{\\frac{i}{\\hbar}S}\n%   + (\\textbf{A}_{\\nu}^2|\\chi |e^{\\frac{i}{\\hbar}S})\n%   + 2 |\\chi |e^{\\frac{i}{\\hbar}S} \\textbf{A}_{\\nu} \\nabla_{\\nu}S\n%  \\right) + \\epsilon |\\chi |e^{\\frac{i}{\\hbar}S} \\right)\n% \\end{dmath*}\n%\n% Dividing through by $-|\\chi |e^{\\frac{i}{\\hbar}S}$:\n% \\begin{dmath*}\n%   \\dot{S} = \\left( \\sum_{\\nu = 1}^{N_{n}} \\frac{1}{2 M_{\\nu}}\\left(\n%   \\hbar^2\\left[\\frac{\\nabla_{\\nu}^2|\\chi |}{|\\chi|} - \\frac{1}{\\hbar^2}  (\\nabla_{\\nu}^2 S)\\right]\n%   - \\textbf{A}_{\\nu}^2\n%   - 2 \\textbf{A}_{\\nu} \\nabla_{\\nu}S\n%  \\right) - \\epsilon \\right)\n% \\end{dmath*}\n% Tidying up:\n% \\begin{dmath*}\n%   \\dot{S} = \\left( \\sum_{\\nu = 1}^{N_{n}} \\frac{1}{2 M_{\\nu}}\\left(\n%   \\hbar^2\\frac{\\nabla_{\\nu}^2|\\chi |}{|\\chi|} - \\left( \\nabla_{\\nu}^2 S\n%   + \\textbf{A}_{\\nu}^2\n%   + 2 \\textbf{A}_{\\nu} \\nabla_{\\nu}S\\right)\n%  \\right) - \\epsilon \\right)\n% \\end{dmath*}\n% Factorising and more tidying:\n% \\begin{dmath*}\n%   \\dot{S} = \\left( \\underbrace{\\hbar^2 \\sum_{\\nu = 1}^{N_{n}} \\frac{1}{2 M_{\\nu}}\n%   \\frac{\\nabla_{\\nu}^2|\\chi |}{|\\chi|}}_{\\text{Quantum Potential}}  - \\epsilon - \\sum_{\\nu = 1}^{N_{n}} \\frac{(\\nabla_{\\nu}S\n%   + \\textbf{A}_{\\nu})^2}{2 M_{\\nu}} \\right)\n% \\end{dmath*}\n\n\\section{Preservation of the Norm \\label{ap:Norm_Pres}}\n\\subsection{Ehrenfest \\label{ap:Norm_Pres_Eh}}\nThe statement of the conservation of norm is:\n\\[ \\sum_{l}^{N_{states}} \\frac{d}{dt} \\vert C_{l}^{(I)} \\vert^2 = 0\\]\nUsing chain rule (and assuming this hold for each replica) we can write this as:\n\\[\\sum_{l}^{N_{states}} \\frac{d}{dt} \\vert C_{l} \\vert^2 = \\left(\\frac{d}{dt} C_{l}^{*}\\right)C_{l} + C_{l}^*\\left(\\frac{d}{dt} C_{l}\\right)\\]\nIf we write, $C_l = (a + bi)$ and $C_l^* = (a - bi)$ we can see the following relation holds:\n\\[\\sum_{l}^{N_{states}} \\frac{d}{dt} \\vert C_{l} \\vert^2 = \\sum_{l}^{N_{states}} \\left(\\frac{d}{dt} C_{l}^{*}\\right)C_{l} + C_{l}^*\\left(\\frac{d}{dt} C_{l}\\right) = \\sum_{l}^{N_{states}} 2\\mathcal{R} \\left[ C_{l}^*\\left(\\frac{d}{dt} C_{l}\\right) \\right]\\]\nWe have an expression for the time-derivative of the adiabatic expansion coefficient, under Ehrenfest (equation \\eqref{eq:adiab_elec}). Inserting this above we get:\n\\[\\sum_{l}^{N_{states}} \\frac{d}{dt} \\vert C_{l} \\vert^2 = \\sum_{l}^{N_{states}}2 \\mathcal{R}\\left[ C_{l}^* \\frac{-i}{\\hbar} C_{l} \\epsilon_{l} - \\sum_{k} C_{l}^{*} C_{k} d_{lk}^{ad} \\right]\\]\nThe first term is imaginary so we can remove it, as we're only interested in the real components:\n\\[\\sum_{l}^{N_{states}} \\frac{d}{dt} \\vert C_{l} \\vert^2 = - 2 \\sum_{l,k}^{N_{states}} \\mathcal{R}\\left[  C_{l}^{*} C_{k} d_{lk}^{ad} \\right]\\]\nThe next term is exactly zero due to the anti-symmetry of the NACE that is the equation above can be written as:\n\\[\\sum_{l}^{N_{states}} \\frac{d}{dt} \\vert C_{l} \\vert^2 = -2 \\sum_{k=2}^{N_{states}} \\sum_{l<k} \\mathcal{R}\\left[(C_{l}^{*}C_{k} - C_{k}^{*}C_{l})d_{lk}\\right] = 0\\]\n\n\\subsection{CTMQC \\label{ap:CTMQC}}\nThe proof of conservation of the norm in CTMQC is similar to Ehrnfest. Again we write:\n\\[\\sum_{l}^{N_{states}} \\frac{d}{dt} \\vert C_{l} \\vert^2 = \\sum_{l}^{N_{states}} 2\\mathcal{R} \\left[ C_{l}^*\\left(\\frac{d}{dt} C_{l}\\right) \\right]\\]\nThis time, the propagtion equation is slightly different:\n\\[\\sum_{l}^{N_{states}} \\frac{d}{dt} \\vert C_{l} \\vert^2 = \\sum_{l}^{N_{states}}2 \\mathcal{R}\\left[ C_{l}^* \\frac{-i}{\\hbar} C_{l} \\epsilon_{l} - \\sum_{k} C_{l}^{*} C_{k} d_{lk}^{ad} - \\sum_{\\nu=1}^{N_n}\\sum_{k}\\frac{\\mathcal{Q}_{lk,\\nu}^{(I)}}{\\hbar M_{\\nu}}\\cdot \\left(\\textbf{f}_{k,\\nu}^{(I)} - \\textbf{f}_{l,\\nu}^{(I)}\\right)|C_k|^2 C_l^{(I)}C_l^{* \\ (I)} \\right]\\]\n\nWe have seen that the Ehrenfest part of the above equation conserves the norm, so we can remove that. we can also combine the 2 $C_l$ terms on the end:\n\n\\[ \\sum_{l}^{N_{states}} \\frac{d}{dt} \\vert C_{l} \\vert^2 = -2 \\sum_{l,k}^{N_{states}} \\mathcal{R}\\left[ \\sum_{\\nu=1}^{N_n}\\frac{\\mathcal{Q}_{lk,\\nu}^{(I)}}{\\hbar M_{\\nu}}\\cdot \\left(\\textbf{f}_{k,\\nu}^{(I)} - \\textbf{f}_{l,\\nu}^{(I)}\\right)|C_k|^2 |C_l^{(I)}|^2 \\right] \\]\n\nBecause $\\mathcal{Q}_{lk,\\nu}^{(I)} = \\mathcal{Q}_{kl,\\nu}^{(I)}$ (and the diagonal is undefined) we can re-write the above equation as:\n\\[ \\sum_{l}^{N_{states}} \\frac{d}{dt} \\vert C_{l} \\vert^2 = -2 \\sum_{l}^{N_{states}} \\sum_{k<l} \\mathcal{R}\\left[ \\sum_{\\nu=1}^{N_n}\\frac{\\mathcal{Q}_{lk,\\nu}^{(I)}}{\\hbar M_{\\nu}}\\cdot \\left[ \\left(\\textbf{f}_{k,\\nu}^{(I)} - \\textbf{f}_{l,\\nu}^{(I)}\\right) + \\left(\\textbf{f}_{l,\\nu}^{(I)} - \\textbf{f}_{k,\\nu}^{(I)}\\right)\\right]|C_k|^2 |C_l^{(I)}|^2 \\right] = 0 \\]\n\nSo the norm should be conserved for each replica in CTMQC.\n\n\\section{Rabi Oscillation \\label{ap:Rabi}}\nBy only allowing one parameter to vary in the propagation one can isolate and test that. For the electronic propagation I held the nuclear positions constant resulting in rabi oscillation. This is due  to the Schr\\\"odinger equation changing from a partial differential equation to, an analytically solvable, ordinary differential equation  i.e:\n\\[i \\hbar \\frac{\\delta}{\\delta t} \\Phi(\\textbf{R}(t), t) = \\hat{H}(\\textbf{R}(t), t) \\Phi(\\textbf{R}(t), t)\\]\n\\[\\downarrow\\]\n\\[i \\hbar \\frac{d}{d t} \\Phi(t) = \\hat{H}(t) \\Phi( t)\\]\nWhich has the general solution:\n\\[\\Phi(t) = e^{i \\hbar \\hat{H}t} \\Phi(0)\\]\n\n\n\n\n% Side note:\n%http://tex.stackexchange.com/questions/1319/showcase-of-beautiful-typography-done-in-tex-friends\n", "meta": {"hexsha": "8c591b9b0643ff8438acb04f62054146afc05c73", "size": 10384, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendices.tex", "max_stars_repo_name": "95ellismle/Master_to_PhD_Upgrade_Report", "max_stars_repo_head_hexsha": "0dfd8e29e3ee6dd0b82b3ada219936244569b9c7", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Appendices.tex", "max_issues_repo_name": "95ellismle/Master_to_PhD_Upgrade_Report", "max_issues_repo_head_hexsha": "0dfd8e29e3ee6dd0b82b3ada219936244569b9c7", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Appendices.tex", "max_forks_repo_name": "95ellismle/Master_to_PhD_Upgrade_Report", "max_forks_repo_head_hexsha": "0dfd8e29e3ee6dd0b82b3ada219936244569b9c7", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 80.496124031, "max_line_length": 369, "alphanum_fraction": 0.5880200308, "num_tokens": 4662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.7476103084446377}}
{"text": "\\setcounter{section}{6}\n\\setcounter{subsection}{0}\n\\subsection{Functors}\n\nUniversal contruction is about to pick the ``best'' embodiment of an idea. \\eg.\nthere is a lot of product in the universe, so we pick the ``best'' one, the one\nthat every product gets factorized into. Thus comes the ``universal''\nconstruction.\n\nFunctors are just mapping between categories.\n\nWhy so important? We look for structures/patterns in categories and try to\nemphasize/extract the pattern from them. Functor is used to find these patterns\nand map them into a category when we can recognize these patterns.\n\n``Category is the definition of structure''. In orther words, ``to recognize a\ncertain structure in a category'' is the same as defining the pattern as a\ncategory. Being able to recognize a category inside another category is just\ndoing pattern recognition.\n\nThe mappings we are interested in are those which preserve structures. A\nfunction is a mapping from set to set, which does not have a structure. A single\nset represented in a category is just a category of bunches of objects and with\nno arrows except the identities. No structure. (Discrete category)\n\\\\\n\n\\begin{definition}{Functor}\n  $F$ is a map between categories that preserves the structure.\n  \\ie. it maps arrow to arrow.\n  For categories $C$, $D$, a functor is that for every\n  $f \\in C(a, b)$, $F$ maps it into $F~f \\in D(F~a, F~b)$ that preserves the\n  structure.\n\n\\[\n\\begin{tikzcd}[sep=huge]\n  a \\rar{F_a} \\dar[red]{f} & F~a \\dar[red]{F~f} \\\\\n  b \\rar{F_b} & F~b\n\\end{tikzcd}\n\\]\n\n  Since a hom-set is a set, a functor just defines this ``huge'' function.\n\n  Preserving the structure means for $g \\circ f \\in C$, $F (g \\circ f) = (F g)\n  \\circ (F f) \\in D$.\n\n  Naturally one have to also make sure\n  $\\forall a \\in C, F(id_a) = id_{F a} \\in D$.\n\\end{definition}\n\n\\subsubsection{Functor properties}\n\n\\begin{definition}{faithful/full}\nFunctors that don't collapse structure is called ``faithful''. A faithful\nfunctor is injective on \\emph{hom-sets}. Correspondingly, A functor is ``full'' when it\nis surjective. Functors that are ``full'' or ``faithful'' are only about\ninjective/surjective on the arrows, not about objects. Functor could map two\ndistinct objects\n$a, b\\in C$ into some $c \\in D$, as long as the arrows between $a$ and $b$\ndoesn't map to the same arrow in $D$, this functor could still be faithful.\n\\end{definition}\n\n\\newcommand{\\singletoncat}{%\n\\begin{tikzcd}[cramped]\n  \\cdot \\ar[loop]{r}{id}\n\\end{tikzcd}%\n}\n\n\\subsubsection{Interesting functors}\n\n\\begin{definition}{Selecting functor}\nThe possible functor mapping from category 1 (singleton category) to\nanother category $C$ is unique (up to iso), that is, to map $\\id \\in \\mathrm{Arr}(1)$ arrow\nto the $\\id$ arrow on some\nobject in $D$. This process is like ``selecting'' an element in $D$.\n\\end{definition}\n\\hfill\n\\begin{definition}{Constant functor}\nAnother important functor mapping from $C$ to $D$ is called constant functor, which maps\nall arrows in $C$ into the $\\id$ arrow of an object $c \\in D$. Constant functor\non object $c$ is denoted as $\\Delta_c$.\n\\end{definition}\n\\hfill\n\\begin{definition}{Endofunctor}\n  An endofunctor is a functor that maps from $C$ to itself, $F: C \\to C$. Haskell\n  functors are all endofunctors mapping from and to the $\\Hask$ category.\n  Haskell functors consists of two parts:\n  \\begin{enumerate}\n  \\item Mapping between types (types are objects in $\\Hask$), \\ie. Type constructors.\n  \\item Mapping between functions, \\ie. \\verb+fmap+.\n  \\end{enumerate}\n\\end{definition}\n\\hfill\n\\begin{remark}\n  Take this example,\n  \\begin{lstlisting}\nfmap :: (a -> b) -> (Maybe a -> Maybe b)\nfmap f Nothing = Nothing *'\\label{nothing}'*\nfmap f (Just x) = Just (f x)\n  \\end{lstlisting}\n\n  To haskell, which uses parametrically polymorphism, line \\ref{nothing}\n  is the only possible implementation for \\lstinline{fmap f Nothing}. However,\n  it's not true to math. For languages which doesn't use parametrically\n  polymorphism, it might be possible to return other values. \\eg. Return\n  \\lstinline{Just 0} for if type \\lstinline{a} is \\lstinline{Int}. Haskell is\n  imposing a stronger condition to be a functor.\n\n  \\newcommand{\\Maybe}{\\lstinline{Maybe}}\n  Let's check if \\Maybe~really is a functor. Questions to ask:\n  \\begin{enumerate}\n  \\item Does \\lstinline{fmap} preserves identity?\n  \\item Does \\lstinline{fmap} preserves composition?\n  \\end{enumerate}\n\n  Surely it does.\n\\end{remark}\n", "meta": {"hexsha": "e518faa00358155f983702e31267c1252cd2359e", "size": 4435, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "milewski-cat/chap6.1.tex", "max_stars_repo_name": "shouya/thinking-dumps", "max_stars_repo_head_hexsha": "a6fc111e02dc631f56302bb059d855446792bebc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-02-14T17:18:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-09T01:02:15.000Z", "max_issues_repo_path": "milewski-cat/chap6.1.tex", "max_issues_repo_name": "shouya/thinking-dumps", "max_issues_repo_head_hexsha": "a6fc111e02dc631f56302bb059d855446792bebc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-06-14T06:07:33.000Z", "max_issues_repo_issues_event_max_datetime": "2015-08-04T22:05:11.000Z", "max_forks_repo_path": "milewski-cat/chap6.1.tex", "max_forks_repo_name": "shouya/thinking-dumps", "max_forks_repo_head_hexsha": "a6fc111e02dc631f56302bb059d855446792bebc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-12-02T02:10:26.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-03T06:32:26.000Z", "avg_line_length": 37.905982906, "max_line_length": 91, "alphanum_fraction": 0.7301014656, "num_tokens": 1254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.747610308253354}}
{"text": "\\section{Methodology} \\label{methods}\n\n%This section introduce the methods that applied to this project.\n%Since both two methods are only work on square-free polynomials, the first step\n%of this project is applying square free decomposition to original polynomials to\n%avoid repeat roots. After square free decomposition, methods based on Budan's\n%Theorem and Continued Fraction will be applied. They both based on\n%Descartes' rule of sign to check how many real roots in a interval. The continued fraction\n%method also uses Mobius transformation, which will be introduce in Continued Fraction\n%subsection.\n\n\\subsection{Square Free Decomposition} \nIn mathematics, a square-free polynomial is a polynomial defined over a field\nthat does not have a divisor any square of a non-constant\npolynomial\\cite{Yuns}. Usually, a square-free polynomial refers to the\npolynomials with no repeated roots. This project applied Yun's\nalgorithm to perform square-free decomposition. It's based one the\nsuccession of Greatest Common Divisor(GCD).\n\n\\subsubsection{Greatest Common Divisor}\n\nIn algebra, the greatest common divisor of two polynomials is a polynomial, \nof the highest possible degree, that is a factor of both the two original\npolynomials. This concept is similar to the GCD of two integers. Ideally, both\npolynomials divided by their greatest common divisor should have no remainder.\n\nThis project uses Euclidean algorithm to compute the GCD of two polynomials.\nIn Algorithm~\\ref{alg1}, $rem(a,b)$ refers to the remainder of Euclidean division of\npolynomial $a$ and polynomial $b$.\n\n\\begin{algorithm}[H]\n\\label{alg1}\n\\SetAlgoLined\n  \\SetKwInOut{Input}{input}\n  \\SetKwInOut{Output}{output}\n\n  \\Input{$P1$: a univariate polynomial\\newline\n         $P2$: a univariate polynomial}\n  \\Output{Greatest common divisor of $P1$ and $P2$}\n\n  $r_0 = P1$\\;\n  $r_1 = P2$\\;\n  \\For{$i=1; r_i \\neq 0; i=i+1$}{\n    $r_{i+1} = rem(r_{i-1},r_i)$\n  }\n\n  \\Return{$r_{i-1}$}\n\n\\caption{GCD of two polynomials}\n\\end{algorithm}\n\n\\subsubsection{Yun's Algorithm}\n\nBased on the success of GCD, Yun developed a square-free decomposition\nalgorithm for univariate polynomials. \n\nGiven a primitive polynomial $P$, assume $P=P_1P_2^2...P_n^n$ is desired\nfactorization. Yun's algorithm will compute square-free polynomials $P_i$ and\nthe subscript refers to the times this square-free polynomial appears. Which\nmeans $P_i$ appears $i$ times in original polynomial. This process is described in\nAlgorithm~\\ref{alg2} formally.\n\n\\begin{algorithm}[H]\n\\label{alg2}\n\\SetAlgoLined\n  \\SetKwInOut{Input}{input}\n  \\SetKwInOut{Output}{output}\n\n  \\Input{Primitive polynomial $P$}\n  \\Output{List of square-free polynomials}\n\n  $G = GCD(P, dP/dx)$\\;\n  $C_1=P/G$\\;\n  $D_1 = (dP/dx)/G - dC_1/dx$\\;\n\n  \\For{$i=1,C_i\\neq 0;i=i+1$}{\n    $P_i= GCD(C_i,D_i)$\\;\n    $C_{i+1}= C_i/P_i$\\;\n    $D_{i+1}= D_i/P_i - dC_{i+1}/dx$\\;\n  }\n\n  \\Return{$P_1, P_2...P_n$}\n\n\\caption{Yun's Square-free Decomposition Algorithm}\n\\end{algorithm}\n\n\\subsection{Budan's Theorem}\n\nBudan's theorem is a theorem used for bounding the number of real roots in a\ngiven interval. Given a univariate polynomial $P$, we denote\n$\\#_{l,r}(P)$ as the number of real roots of $P$ in half-open interval $(l,r]$.\nThen we denote $v_h(P)$ as the number of sign changes in coefficients of\npolynomial $P_h$, where $P_h(x) = P(x+h)$.\n\nBudan's theorem states that $v_l(h) - v_r(h) - \\#_{l,r}(P)$ is a nonnegative\neven integer. From this statement, we can know that if $v_l(h) - v_r(h) = 1\n\\text{ or } 0$, there is only one or zero real root in interval $(l,r]$. \n\nBased on this theorem, this project combines bisection method with Budan's\ntheorem to isolate the real roots.  This process described in\nAlgorithm~\\ref{alg3}.\n\n\\begin{algorithm}[H]\n\\label{alg3}\n\\SetAlgoLined\n  \\SetKwInOut{Input}{input}\n  \\SetKwInOut{Output}{output}\n\n  \\Input{A square-free polynomial $P$} \n  \\Output{List of intervals contains only one real root}\n\n  $ret = []$\\;\n  $up\\_bound = Upper(P)$\\;\n  $low\\_bound = - up\\_bound$\\;\n  $search = [(low\\_bound, up\\_bound)]$\\;\n\n  \\While{$search$ not empty}{\n    $l, r = pop(search)$\\;\n    $vl = sign\\_change(P(x+l))$\\;\n    $vr = sign\\_change(P(x+r))$\\;\n    \\If{$vl - vr = 1$}{\n      $ret.append([l,r])$\\;\n    }\n    \\ElseIf {$vr - vl > 1$}{\n      \\If{$l - r \\geq MINIMAL\\_RANGE$} {\n        $mid = l + (r-l)/2$\\;\n        $search.append(mid, r)$\\;\n        $search.append(l, mid)$\\;\n      }\n      \\ElseIf{$(vl - vr) \\%2 = 1$} {\n        $ret.append([l,r])$\\;\n      }\n    }\n  }\n\n  \\Return{ret}\\;\n\\caption{Real-root isolation based on Budan's Theorem}\n\\end{algorithm}\n\n%\\begin{algorithm}[H]\n%\\label{alg3}\n%\\SetAlgoLined\n%  \\SetKwInOut{Input}{input}\n%  \\SetKwInOut{Output}{output}\n\n%  \\Input{A square-free polynomial $P$} \n%  \\Output{List of intervals contains only one real root}\n\n%  $ret = []$\\;\n%  $up\\_bound = Upper(P)$\\;\n%  $low\\_bound = - up\\_bound$\\;\n%  $search = [(low\\_bound, up\\_bound)]$\\;\n\n%  \\While{$search$ not empty}{\n%    $l, r = pop(search)$\\;\n%    $vl = sign\\_change(P(x+l))$\\;\n%    $vr = sign\\_change(P(x+r))$\\;\n%    \\If{$vl - vr = 1$}{\n%      $ret.append([l,r])$\\;\n%    }\n%    \\ElseIf {$r - l \\geq MINIMAL\\_RANGE $}{\n%      $mid = l + (r-l)/2$\\;\n%      $search.append(mid, r)$\\;\n%      $search.append(l, mid)$\\;\n%    }\n%  }\n\n%  \\Return{ret}\\;\n%\\caption{Real-root isolation based on Budan's Theorem}\n%\\end{algorithm}\n\nIn Algorithm~\\ref{alg3}, $Upper(P)$ returns the upper bound of real roots of\n$P$. This project uses Lagrange's bound\\cite{Lag} in this project. Assuming $P =\na_0 + a_1x + ... + a_nx^n$, Lagrange's bound is $max\\{1,\n\\sum_{i=0}^{n-1}|\\frac{a_i}{a_n}|\\}$.\n\n\n\n\n\n\\subsection{Continued Fraction}\n\nLet's first introduce some notations used in this algorithm. Let $M(x)$\nrepresent a Mobius transformation, which maps $x$ to $\\frac{ax+b}{cx+d}$. So\nthat the number of positive roots of $P(M(x))$ equals the number of roots in\ninterval $(\\frac{b}{d}, \\frac{a}{c}]$ of $P$. Denote the sign changes of \ncoefficients of $P$ as $s$.\n\nWe use $\\{a,b,c,d,p, s\\}$ to represent an interval. Where, $ad-bc \\neq 0$ and the\nroots of original polynomial $P$ in interval $(\\frac{b}{d},\\frac{a}{c}]$ are\nimages of positive roots of $p$.\n\nContinued fraction method can be formalized as Algorithm~\\ref{alg4}. \n\n\\begin{algorithm}[H]\n\\label{alg4}\n\\SetAlgoLined\n  \\SetKwInOut{Input}{input}\n  \\SetKwInOut{Output}{output}\n\n  \\Input{A square-free polynomial with no zero root $P$} \n  \\Output{List of intervals contains only one positive real root}\n\n  $s = sign\\_change(P)$\\;\n  \\If{$s=0$}{ \n    \\Return{[]};\n  }\n  \\ElseIf{$s=1$}{\n    \\Return{$[(0,\\infty)]$};\n  }\n\n  $ret = []$\\;\n  $intervals = [\\{1,0,0,1,P,s\\}]$\\;\n\n  \\While{$intervals$ not empty}{\n    $\\{a,b,c,d,p,s\\} = pop(intervals)$\\;\n    \\If{$s = 0$}{\n      continue;\n    }\n    $p' = p(x+1)$\\;\n\n    \\If{$p'(0)=0$}{\n      $ret.append([\\frac{a+b}{c+d},\\frac{a+b}{c+d}])$\\;\n      $p' = p'/x$\\;\n    }\n\n    $s' = sign\\_change(p')$\\;\n      $intervals.append(\\{a, a+b, c, c+d, p', s' \\})$\\;\n\n    \\If{$s-s' = 1$}{\n      $ret.append([\\frac{b}{d},\\frac{a+b}{c+d}])$\\;\n    }\n    \\ElseIf{$s-s' > 1$} {\n      % add A(b/(1 + x)),  M(b/(1 + x)) to L\n      $p'' = (x+1)^m p(1/(1+x))$\\;\n      $intervals.append(\\{b, a+b, d, c+d, p'', sign\\_change(p'') \\})$\\;\n\n    }\n  }\n\n  \\Return{ret}\\;\n\\caption{Real-root isolation based on Continued Fraction}\n\\end{algorithm}\n\nAlgorithm~\\ref{alg4} can only returns positive real roots, therefore,\nAlgorithm~\\ref{alg4} will be applied both on $P(x)$ and $P(-x)$. Zero roots\nshould be handled before using Algorithm~\\ref{alg4}. \n", "meta": {"hexsha": "087fefc188f9605fae295fc93337d9deef41ab0c", "size": 7509, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/040methodology.tex", "max_stars_repo_name": "willyii/PolynomialRootFinding", "max_stars_repo_head_hexsha": "18c7edd8fadf3dc48d2dc6480f0cf6f624cea80f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/040methodology.tex", "max_issues_repo_name": "willyii/PolynomialRootFinding", "max_issues_repo_head_hexsha": "18c7edd8fadf3dc48d2dc6480f0cf6f624cea80f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-13T00:53:54.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-13T00:53:54.000Z", "max_forks_repo_path": "report/040methodology.tex", "max_forks_repo_name": "willyii/PolynomialRootFinding", "max_forks_repo_head_hexsha": "18c7edd8fadf3dc48d2dc6480f0cf6f624cea80f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-13T12:54:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-13T12:54:48.000Z", "avg_line_length": 30.2782258065, "max_line_length": 91, "alphanum_fraction": 0.6493541084, "num_tokens": 2468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.8774767986961403, "lm_q1q2_score": 0.7475688206097458}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{n(n+1)}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution 1}\r\n\r\nRewrite $\\frac1{n(n+1)}$ using partial fraction decomposition:\r\n\\[ \\frac1{n(n+1)} = \\frac{A}{n} + \\frac{B}{n+1}\\]\r\nSo\r\n\\[ 1 = A(n+1) + Bn\\]\r\nUsing $n=0$, we get $A  = 1$. Using $n=-1$, we get $B=-1$. So\r\n\\[ \\frac1{n(n+1)} = \\frac{1}{n} - \\frac{1}{n+1}\\]\r\nTherefore, our original series can be rewritten:\r\n$\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{n(n+1)} =  \\displaystyle \\sum_{n=1}^\\infty \\left( \\frac{1}{n} - \\frac{1}{n+1} \\right)$\r\n\r\n\\vskip20pt\r\n\\noindent\r\nWe appear to have a telescoping series. After cancellations, the $n$th term of the sequence of partial sums is:\r\n\\[ s_n = \\frac{1}{1} - \\frac{1}{n+1}\\]\r\nThus,\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} s_n\r\n&=  \\lim_{n \\to \\infty} \\left( \\frac{1}{1} - \\frac{1}{n+1}\\right) \\\\\r\n&=  \\frac11 - 0\\\\\r\n&= 1\r\n\\end{align*}\r\nSo, (by definition), the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{n(n+1)}$ converges, and we furthermore know that the sum is $1$. Recall that it is unusual that we get to know the value of a convergent series.\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{n(n+1)}$ converges absolutely.\r\n\r\n\\subsection*{Solution 2}\r\n\r\nNote that $n(n+1) \\geq n^2$ for all $n \\geq 1$. So\r\n\\[ \\frac1{n(n+1)} \\leq \\frac{1}{n^2}\\]\r\nThe series $\\displaystyle \\sum_{n=1}^\\infty  \\frac{1}{n^2}$ converges by the $p$-test. Therefore, the series  $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{n(n+1)}$ converges by the Direct Comparison Test.\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{n(n+1)}$ converges absolutely.\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "0b4b1de7b209e0c08f9f5769eba199636239fcff", "size": 2384, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/f1.tex", "max_stars_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_stars_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "key/series/f1.tex", "max_issues_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_issues_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "key/series/f1.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 37.25, "max_line_length": 219, "alphanum_fraction": 0.6291946309, "num_tokens": 876, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528132451416, "lm_q2_score": 0.8774767890838836, "lm_q1q2_score": 0.7475688190173284}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Use elementary operations to solve the system of equations\n  \\begin{equation*}\n    \\begin{array}{c}\n      3x+y=3 \\\\\n      x+2y=1.\n    \\end{array}\n  \\end{equation*}\n\n  \\begin{sol}\n    $(x,y) = (1,0)$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Use elementary operations to find the point $(x,y)$\n  that lies on both lines $x+3y=1$ and $4x-y=3$.\n  \\begin{sol}\n    $\n    \\begin{array}{c}\n      x+3y=1 \\\\\n      4x-y=3\n    \\end{array}\n    $, Solution is: $(x,y) = \\paren{\\frac{10}{13},\\frac{1}{13}}$\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Use elementary operations to determine whether the three lines\n  $x+2y=1$, $2x-y=1$, and $4x+3y=3$ have a common point of intersection.\n  If so, find the point, and if not, tell why they don't have such a\n  common point of intersection.\n  \\begin{sol}\n    $\n    \\begin{array}{c}\n      x+2y=1 \\\\\n      2x-y=1 \\\\\n      4x+3y=3\n    \\end{array}\n    $, Solution is: $(x,y) = \\paren{\\frac{3}{5},\\frac{1}{5}}$\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Do the three planes, $x+y-3z=2$, $2x+y+z=1$, and $3x+2y-2z=0$ have a\n  common point of intersection? If so, find one and if not, tell why\n  there is no such point.\n  \\begin{sol}\n    No solution exists. $\n    \\begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n      x &+& y &-& 3z &=& 2 \\\\\n      2x &+& y &+& z &=& 1 \\\\\n      3x &+& 2y &-& 2z &=& 0\n    \\end{array}\n    $, after elementary operations:\n    $\n    \\begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n      x & &   &+& 4z &=& 0 \\\\\n        & & y &-& 7z &=& 0 \\\\\n        & &   & & 0 &=& 1\n    \\end{array}$.\n    Thus one of the equations says $0=1$ in an equivalent system of\n    equations.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Solve the following system of equations by back substitution.\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n      x &+& 3y &-& 2z &=& 5 \\\\\n        & & y  &+& 3z &=& 4 \\\\\n        & &    & & z  &=& 1.\n    \\end{array}\n  \\end{equation*}\n\n  \\begin{sol}\n    $(x,y,z) = (4,1,1)$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Write the following system of linear equations as an augmented\n  matrix. Caution: you first have to simplify and rearrange the\n  equations so that ``like'' variables are lined up in columns. Write\n  the variables in the order $x$, $y$, $z$.\n  \\begin{equation*}\n    \\begin{array}{c}\n      x - 3z + 2y = 5 \\\\\n      6 - x = 4 + y - z \\\\\n      2x + 3 = x + 3y.\n    \\end{array}\n  \\end{equation*}\n\n  \\begin{sol}\n    $\n    \\begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n      x &+& 2y &-& 3z &=& 5 \\\\\n      -x &-& y &+& z &=& -2 \\\\\n      x &-& 3y && &=& -3. \\\\\n    \\end{array}\n    $\n    As an augmented matrix:\n    $\n    \\begin{mymatrix}{rrr|r}\n      1 & 2 & -3 & 5 \\\\\n      -1 & -1 & 1 & -2 \\\\\n      1 & -3 & 0 & -3\n    \\end{mymatrix}.\n    $\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Four times the weight of Gaston is 150kg more than the weight of\n  Ichabod. Four times the weight of Ichabod is 660kg less than seventeen\n  times the weight of Gaston. Four times the weight of Gaston plus the weight\n  of Siegfried equals 290kg. Brunhilde would balance all three of the\n  others. Find the weights of the four people.\n  \\begin{sol}\n    $\n    \\begin{array}{c}\n      4g-I=150 \\\\\n      4I-17g=-660 \\\\\n      4g+s=290 \\\\\n      g+I+s-b=0\n    \\end{array}\n    $, Solution is : $\\set{g=60,I=90,b=200,s=50}$\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "32fafc27ba8630b56dbc97694faa3526ec10059e", "size": 3308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/SystemsofEquations-ElementaryOperations.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/SystemsofEquations-ElementaryOperations.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/SystemsofEquations-ElementaryOperations.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 24.6865671642, "max_line_length": 77, "alphanum_fraction": 0.5259975816, "num_tokens": 1343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.7475688170270315}}
{"text": "\\section{Robust Regression}\n\\subsection{Singular values decomposition (SVD)}\nAfter applying the SVD to both $\\mathbf X$ and $\\mathbf X_{noise}$ data, the Fig.\\ref{fig:1_6_a} illustrates the singular values. For the original data $\\mathbf X$, there are only three singular values which corresponding to its rank. Due to the randomness and independences of noise, the matrix $\\mathbf X_{noise}$ is full rank which has ten singular values. However, there are three significant singular values which represents the dimension of signal subspace. The magnitude of other non-zero singular values are approximate half of the signal singular values, whose difference can be used to detect the signal and noise subspace. Nevertheless, if the noise power is large, it becomes hard to identify the rank of $\\mathbf X_{noise}$.\n\\begin{figure}[htbp]\n    \\centering\n     \\begin{subfigure}{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/16/16a1.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/16/16a2.eps}\n     \\end{subfigure}\n    \\caption{SVD of $\\mathbf X$ and $\\mathbf X_{noise}$}\n    \\label{fig:1_6_a}\n\\end{figure}\n\\subsection{Low rank approximation}\nThe SVD algorithm could be used to recover the original matrix. Since the noise power is much less than the signal power, the recovered matrix is noiseless if only $k$ significant values are concerned, where $k$ is the rank of the original matrix. Fig.\\ref{fig:1_6_b} shows the error between the noise matrix and recovered noiseless matrix. As to the noiseless error curve, when the number of $k$ is equal to the actual rank, the error reaches the bottom point. In this experiment, the minimum point at rank 3 is 27.07, while it is 49.34 of noise error over all rank. Therefore, the rank and the dimension of signal subspace are determined.\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=0.4\\textwidth]{fig/16/16b.eps}\n    \\caption{Error in low rank approximation}\n    \\label{fig:1_6_b}\n\\end{figure}\n\\subsection{OLS vs PCR}\nThe parameter matrix $\\mathbf B$ is calculated based on the OLS and PCR method. Meanwhile, the square error between the actual $\\mathbf Y$ and estimated output on training and testing data are illustrated in Fig.\\ref{fig:1_6_c}. When the number of significant components $k$ is larger than 3, the PCR has the same performance with the OLS method. However, when testing the parameter matrix via $\\mathbf X_{test}$, the estimated error of the PCR increases with $k<3$, while the error of OLS decreases.\n\\begin{figure}[htbp]\n     \\centering\n     \\begin{subfigure}{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/16/16c1.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/16/16c2.eps}\n     \\end{subfigure}\n        \\caption{Training and testing error of OLS \\& PCR}\n        \\label{fig:1_6_c}\n\\end{figure}\n\\subsection{Realisations of OLS and PCR}\nTotally 50 realisations were simulated by OLS and PCR methods and its average error with test data are plotted in Fig.\\ref{fig:1_6_d}. Compared with the testing error shown in Fig\\ref{fig:1_6_c}, the average errors of both PCR and OLS algorithms are reduced to a large extent. The largest error of PCR is reduced from 85 to 65, while the OLS decreases to 37.81.\n\\vspace*{3in}\n\\begin{figure}[t!]\n    \\centering\n    \\includegraphics[width=0.4\\textwidth]{fig/16/16d.eps}\n    \\caption{Estimated error of realisations}\n    \\label{fig:1_6_d}\n\\end{figure}\n\n\n", "meta": {"hexsha": "560997c64f221e8516aaba239689938a41a620e2", "size": 3621, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/sections/Part1/16.tex", "max_stars_repo_name": "zdhank/Adaptive-Signal-Processing", "max_stars_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-05T10:27:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-19T08:55:10.000Z", "max_issues_repo_path": "Report/sections/Part1/16.tex", "max_issues_repo_name": "zdhank/Adaptive-Signal-Processing", "max_issues_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/sections/Part1/16.tex", "max_forks_repo_name": "zdhank/Adaptive-Signal-Processing", "max_forks_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.320754717, "max_line_length": 737, "alphanum_fraction": 0.7387462027, "num_tokens": 977, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7475688137854216}}
{"text": "\n\\subsection{Introduction}\n\nA single-variable polynomial is an equation of the form:\n\n\\(\\sum^n_{i=0} a_i x^i=0\\)\n\nFor example:\n\\begin{itemize}\n\\item \\(x=1\\)\n\\item \\(x^2=4\\)\n\\item \\(x^2-3x+2=0\\)\n\\end{itemize}\n\n\\subsection{Degrees}\n\nThe degree of a polynomial is the highest-order term.\n\nFor example \\(x^3+x=0\\) has degree \\(3\\).\n\n\\subsection{Roots of single-variable polynomials}\n\nA solution to a polynomial is a root.\n\nFor example \\(1\\) and \\(2\\) are roots of \\(x^2-3x+2=0\\)\n\n", "meta": {"hexsha": "4638a06d18bde40af366138b947716fdc4333f2e", "size": 476, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/polynomials/01-01-polynomialSingle.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/polynomials/01-01-polynomialSingle.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/polynomials/01-01-polynomialSingle.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.6296296296, "max_line_length": 56, "alphanum_fraction": 0.6764705882, "num_tokens": 160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308036221031, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7473905789702173}}
{"text": "\\subsection{Finding an $LU$ factorization by inspection}\n\nWhich matrices have an $LU$ factorization? It turns out it is those whose\n{\\ef} can be achieved without switching rows. In other words matrices which\nonly involve using row operations of type 2 or 3 to obtain the {\\ef}.\n\n\\begin{example}{An $LU$ factorization}{}\nFind an $LU$ factorization of $A=\\begin{mymatrix}{cccc}\n1 & 2 & 0 & 2 \\\\\n1 & 3 & 2 & 1 \\\\\n2 & 3 & 4 & 0%\n\\end{mymatrix}$.\n\\end{example}\n\nOne way to find the $LU$ factorization%\n\\index{LU factorization!by inspection} is to simply look for it directly.\nYou need\n\\begin{equation*}\n\\begin{mymatrix}{cccc}\n1 & 2 & 0 & 2 \\\\\n1 & 3 & 2 & 1 \\\\\n2 & 3 & 4 & 0%\n\\end{mymatrix} =\\begin{mymatrix}{ccc}\n1 & 0 & 0 \\\\\nx & 1 & 0 \\\\\ny & z & 1%\n\\end{mymatrix} \\begin{mymatrix}{cccc}\na & d & h & j \\\\\n0 & b & e & i \\\\\n0 & 0 & c & f%\n\\end{mymatrix} .\n\\end{equation*}\nThen multiplying these you get\n\\begin{equation*}\n\\allowbreak \\begin{mymatrix}{cccc}\na & d & h & j \\\\\nxa & xd+b & xh+e & xj+i \\\\\nya & yd+zb & yh+ze+c & yj+iz+f%\n\\end{mymatrix}\n\\end{equation*}\nand so you can now tell what the various quantities equal. From the first\ncolumn, you need $a=1,x=1,y=2$. Now go to the second column. You need $\nd=2,xd+b=3$ so $b=1,yd+zb=3$ so $z=-1$. From the third column, $h=0,e=2,c=6$.\nNow from the fourth column, $j=2,i=-1,f=-5$. Therefore, an $LU$\nfactorization is\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n1 & 1 & 0 \\\\\n2 & -1 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrrr}\n1 & 2 & 0 & 2 \\\\\n0 & 1 & 2 & -1 \\\\\n0 & 0 & 6 & -5\n\\end{mymatrix} .\n\\end{equation*}\nYou can check whether you got it right by simply multiplying these two.\n", "meta": {"hexsha": "837004a30937e26b3e457cb0aab873212353e399", "size": 1631, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/matricesLUFactorizationInspection.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/matricesLUFactorizationInspection.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/matricesLUFactorizationInspection.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 28.1206896552, "max_line_length": 77, "alphanum_fraction": 0.6364193746, "num_tokens": 633, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.8856314813647587, "lm_q1q2_score": 0.7473800767458997}}
{"text": "\\chapter{Bayesian Inference}\n\n\\begin{ex}\n  Let $f$ and $g$ be PDFs of normal distributions with means $\\mu_f$ and $\\mu_g$\n  and variances $\\sigma_f^2$ and $\\sigma_g^2$ respectively. Note that since\n  \\begin{align*}\n    \\frac{(x-\\mu_f)^2}{\\sigma_f^2}\n    +\\frac{(x-\\mu_g)^2}{\\sigma_g^2}\n     & =\\frac{\\sigma_g^2(x^2-2x\\mu_f+\\mu_f^2)+\\sigma_f^2(x^2-2x\\mu_g+\\mu_g^2)}{\\sigma_f^2\\sigma_g^2}                                                                                                      \\\\\n     & =\\frac{(\\sigma_f^2+\\sigma_g^2)x^2-2(\\sigma_g^2\\mu_f+\\sigma_f^2\\mu_g) x+\\sigma_g^2\\mu_f^2+\\sigma_f^2\\mu_g^2}{\\sigma_f^2\\sigma_g^2}                                                                  \\\\\n     & =\\frac{x^2-2\\frac{\\sigma_g^2\\mu_f+\\sigma_f^2\\mu_g}{\\sigma_f^2+\\sigma_g^2} x+\\frac{\\sigma_g^2\\mu_f^2+\\sigma_f^2\\mu_g^2}{\\sigma_f^2+\\sigma_g^2}}{\\frac{\\sigma_f^2\\sigma_g^2}{\\sigma_f^2+\\sigma_g^2}} \\\\\n     & =\\frac{\\left(x-\\frac{\\sigma_g^2\\mu_f+\\sigma_f^2\\mu_g}{\\sigma_f^2+\\sigma_g^2}\\right)^2}{\\frac{\\sigma_f^2\\sigma_g^2}{\\sigma_f^2+\\sigma_g^2}} +C,\n  \\end{align*}\n  for some $C$ not depending on $x$, we have\n  \\begin{align*}\n    f(x)g(x)\n     & \\propto \\exp\\left\\{-\\frac{(x-\\mu_f)^2}{2\\sigma_f^2}\\right\\}\n    \\exp\\left\\{-\\frac{(x-\\mu_g)^2}{2\\sigma_g^2}\\right\\}                                                                                                                                  \\\\\n     & \\propto \\exp\\left\\{-\\frac{1}{2}\\frac{\\left(x-\\frac{\\sigma_g^2\\mu_f+\\sigma_f^2\\mu_g}{\\sigma_f^2+\\sigma_g^2}\\right)^2}{\\frac{\\sigma_f^2\\sigma_g^2}{\\sigma_f^2+\\sigma_g^2}}\\right\\},\n  \\end{align*}\n  which, by inspection, is proportional to the PDF of a normal distribution with\n  mean\n  \\[\n    \\frac{\\sigma_g^2\\mu_f+\\sigma_f^2\\mu_g}{\\sigma_f^2+\\sigma_g^2}\n  \\]\n  and variance\n  \\[\n    \\frac{\\sigma_f^2\\sigma_g^2}{\\sigma_f^2+\\sigma_g^2}.\n  \\]\n\n  Consider the product of $n$ normal PDFs each with mean $X_i$ and variance\n  $\\sigma^2$. Since we can group it as the product of the first $n-1$ PDFs and\n  the last PDF, and since by the previous argument, the product of two normal\n  PDFs is proportional to a normal PDF, it follows by induction that so is the\n  product of $n$ PDFs. It only remains to figure out the mean and variance.\n  Note that for $n=2$ we have\n  \\[\n    \\sigma_2^2\n    =\\frac{\\sigma^2\\sigma^2}{\\sigma^2+\\sigma^2}=\\frac{\\sigma^2}{2}\n    \\text{ and }\n    \\mu_2\n    =\\frac{X_1\\sigma^2+X_2\\sigma^2}{\\sigma^2+\\sigma^2}\n    =\\frac{X_1+X_2}{2}\n    =\\Xbar_2.\n  \\]\n  Suppose that for $n-1$ we have\n  \\[\n    \\sigma_{n-1}^2=\\frac{\\sigma^2}{n-1}\n    \\text{ and }\n    \\mu_{n-1}=\\Xbar_{n-1},\n  \\]\n  and note that then\n  \\[\n    \\sigma_n^2\n    =\\frac{\\sigma_{n-1}^2\\sigma^2}{\\sigma_{n-1}^2+\\sigma^2}\n    =\\frac{\\frac{\\sigma^2}{n-1}\\sigma^2}{\\frac{\\sigma^2}{n-1}+\\sigma^2}\n    =\\frac{\\sigma^4}{n-1} / \\frac{n\\sigma^2}{n-1}\n    =\\frac{\\sigma^2}{n}\n    =\\se^2,\\text{ and }\n  \\]\n  \\[\n    \\mu_n\n    =\\frac{\\Xbar_{n-1}\\sigma^2+X_n\\sigma_{n-1}^2}{\\sigma_{n-1}^2+\\sigma^2}\n    =\\frac{\\Xbar_{n-1}\\sigma^2+X_n\\frac{\\sigma^2}{n-1}}{\\frac{\\sigma^2}{n-1}+\\sigma^2}\n    =\\frac{(\\sum_{i=1}^n X_i)\\sigma^2}{n-1}/\\frac{n\\sigma^2}{n-1}\n    =\\Xbar_n.\n  \\]\n  The result follows by induction.\n\n  Next, consider the product of $n$ normal PDFs with mean $X_i$ and\n  variance $\\sigma^2$ respectively, and a normal PDF with mean $a$ and variance\n  $b^2$. The product of the first $n$ PDFs is proportional to an\n  $N(\\Xbar, \\se^2)$ PDF, and therefore the full product is\n  proportional to an $N(\\overline{\\theta}, \\tau^2)$ PDF, where\n  \\[\n    \\tau^2=\\frac{\\se^2b^2}{\\se^2+b^2},\\text{ and}\n  \\]\n  \\begin{align*}\n    \\overline{\\theta}\n     & =\\frac{\\Xbar b^2+a \\se^2}{\\se^2+b^2}                        \\\\\n     & =\\frac{\\Xbar b^2}{\\se^2+b^2}+\\frac{a \\se^2}{\\se^2+b^2}      \\\\\n     & =\\Xbar\\frac{\\frac{1}{\\se^2}}{\\frac{1}{\\se^2}+\\frac{1}{b^2}}\n    +a\\frac{\\frac{1}{b^2}}{\\frac{1}{\\se^2}+\\frac{1}{b^2}}          \\\\\n     & =\\Xbar\\frac{\\frac{1}{\\se^2}}{\\frac{1}{\\se^2}+\\frac{1}{b^2}}\n    +a\\left[1-\\frac{\\frac{1}{\\se^2}}{\\frac{1}{\\se^2}+\\frac{1}{b^2}}\\right].\n  \\end{align*}\n\n  Finally, let $X_1,\\ldots,X_n\\sim N(\\theta,\\sigma^2)$, where $\\sigma^2$ is\n  known. We take a prior $\\theta\\sim N(a, b^2)$, and compute the\n  posterior for $\\theta$. Note that\n  \\[\n    f(\\theta\\,|\\, X^n)\n    \\propto \\L(\\theta\\,|\\, X^n)f(\\theta)\n    = f(\\theta)\\prod_{i=1}^n\\L(\\theta\\,|\\, X_i)\n    = f(\\theta)\\prod_{i=1}^n f_i(\\theta),\n  \\]\n  where $f_i$ is the PDF for an $N(X_i,\\sigma^2)$ distribution. However, this is\n  precisely the setting of our last proposition and therefore the result\n  follows.\n\\end{ex}\n\n\\begin{ex}~\n  \\inputminted{python}{../code/11-02.py}\n  \\inputminted{text}{../output/11-02.txt}\n\n  \\begin{enumerate}[(a)]\n    \\item[(b)] Let $f(\\mu)=1$. Recall that the posterior is proportional to the\n          product of the likelihood and the prior and that we therefore have\n          \\begin{align*}\n            f(\\mu\\,|\\,x^n)\\propto \\prod_{i=1}^n\\frac{1}{\\sqrt{2\\pi}}\n            \\exp\\left\\{-\\frac{(x_i-\\mu)^2}{2}\\right\\},\n          \\end{align*}\n          and therefore, by comparison to the probability density function of a\n          multivariate normal distribution,\n          \\begin{align*}\n            f(\\mu\\,|\\,x^n)=\n            (2\\pi)^{-n/2}\n            \\exp\\left\\{-\\frac{\\sum_{i=1}^n(x_i-\\mu)^2}{2}\\right\\}.\n          \\end{align*}\n\n          \\begin{figure}[H]\n            \\centering\n            \\includegraphics[scale=0.8]{../images/11-02b}\n            \\caption{Plot of the posterior density of $\\mu$.}\n          \\end{figure}\n    \\item[(c)]~\n          \\begin{figure}[H]\n            \\centering\n            \\includegraphics[scale=0.8]{../images/11-02c}\n            \\caption{Histogram of $1000$ simulated values drawn from the\n              posterior density of $\\mu$.}\n          \\end{figure}\n    \\item[(d)] Let $\\theta=e^\\mu$. We then have\n          \\begin{align*}\n            \\P{\\Theta\\leq \\theta\\,|\\,x^n}\n             & =\\P{e^\\mu\\leq \\theta\\,|\\,x^n}                            \\\\\n             & =\\P{\\mu\\leq \\log{\\theta}\\,|\\,x^n}                        \\\\\n             & =\\int_{-\\infty}^{\\log{\\theta}}\\!f(\\mu\\,|\\,x^n)\\,\\d{\\mu},\n          \\end{align*}\n          and therefore, by differentiating under the integral sign,\n          \\[\n            f(\\theta\\,|\\,x^n)\n            =\\frac{\\d}{\\d\\theta}\\P{\\Theta\\leq \\theta\\,|\\,x^n}\n            =\\frac{1}{\\theta}(2\\pi)^{-n/2}\n            \\exp\\left\\{-\\frac{\\sum_{i=1}^n(x_i-\\log{\\theta})^2}{2}\\right\\}.\n          \\]\n          \\begin{figure}[H]\n            \\centering\n            \\includegraphics[scale=0.54]{../images/11-02d}\n            \\caption{A histogram of $10,000$ simulated values of $\\theta$ drawn\n              using the posterior density of $\\mu$ (left) and a plot of the\n              exact analytically computed posterior distribution of $\\theta$\n              (right).}\n          \\end{figure}\n    \\item[(e)] As per the output of the code giving in the listing at the start\n          of this problem, a 95\\% posterior interval for $\\mu$ is given by\n          $[4.754, 5.146]$.\n    \\item[(f)] From the output of the code listing at the top, a 95\\%\n          posterior interval for $\\theta$ is given by $[116.004, 171.681]$. Note\n          that we are asked for a confidence interval, but per Theorem\n          11.5 we may approximate it with a Bayesian posterior interval instead.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Note that\n  \\[\n    \\L(\\theta, x_i)=\\begin{cases}\n      0          & \\theta < x_i,     \\\\\n      x_i/\\theta & \\text{otherwise},\n    \\end{cases}\n  \\]\n  and that therefore\n  \\[\n    \\L(\\theta, x^n)=\\begin{cases}\n      0                                  & \\theta < x_{(n)}, \\\\\n      \\frac{\\prod_{i=1}^n x_i}{\\theta^n} & \\text{otherwise}.\n    \\end{cases}\n  \\]\n  Thus, if $f(\\theta)\\propto 1/\\theta$,\n  \\[\n    f(\\theta\\,|\\, x^n)\\propto \\begin{cases}\n      0                                      & \\theta < x_{(n)}, \\\\\n      \\frac{\\prod_{i=1}^n x_i}{\\theta^{n+1}} & \\text{otherwise},\n    \\end{cases}\n  \\]\n  or, since\n  \\[\n    \\int_{x_{(n)}}^\\infty \\frac{\\prod_{i=1}^n x_i}{\\theta^{n+1}}\\,\\d\\theta\n    =\\frac{1}{n}\\prod_{i=1}^n\\frac{x_i}{x_{(n)}},\n  \\]\n  \\[\n    f(\\theta\\,|\\, x^n)=\\frac{n(x_{(n)})^n}{\\theta^{n+1}}I_{[x_{(n)},\\infty)}(\\theta).\n  \\]\n\\end{ex}\n\n\\begin{ex}~\n  \\begin{enumerate}[(a)]\n    \\inputminted{python}{../code/11-04.py}\n    \\inputminted{text}{../output/11-04.txt}\n    \\item By Exercise 9.7, the MLE for $\\tau$ is given by\n          \\[\n            \\tauhat = \\phat_1 -\\phat_2=X_1/n_1-X_2/n_2,\n          \\]\n          with\n          \\[\n            \\sehat=\\sqrt{\n              \\frac{\\phat_1(1-\\phat_1)}{n_1}\n              +\\frac{\\phat_2(1-\\phat_2)}{n_2}.\n            }\n          \\]\n          In particular, we have that the MLE for $\\tau$ is $0.2$. The estimated\n          standard error is $0.08944$, and a 90\\% confidence interval\n          is given by $[0.05288, 0.3471]$.\n    \\item From the code listing given at the start of the problem, we can see\n          that a 90\\% confidence interval for $\\tau$ using the parametric\n          bootstrap method is given by $[0.06, 0.34]$.\n    \\item Using the prior $f(p_1,p_2)=1$, it follows that the posterior mean of\n          $\\tau$ is $0.1953$, and a 90\\% posterior confidence interval is given\n          by $[0.04632, 0.3393]$.\n    \\item Let\n          \\[\n            \\psi=g(p_1,p_2)=\\log\\left(\n            \\left(\\frac{p_1}{1-p_1}\\right)\\div\n            \\left(\\frac{p_2}{1-p_2}\\right)\n            \\right),\n          \\]\n          and note that then\n          \\begin{align*}\n            \\nabla g=\\begin{pmatrix}\n              \\frac{1}{p_1-p_1^2} \\\\\n              \\frac{1}{p_2^2-p_2}\n            \\end{pmatrix}.\n          \\end{align*}\n          By the equivariance of the MLE, $\\psihat=g(\\phat_1,\\phat_2)$, and by\n          the multiparameter delta method\n          \\begin{align*}\n            \\sehat(\\psihat)\n             & =\\sqrt{\n              \\begin{pmatrix}\n                \\frac{1}{\\phat_1-\\phat_1^2} &\n                \\frac{1}{\\phat_2^2-\\phat_2}\n              \\end{pmatrix}\n              \\begin{pmatrix}\n                \\frac{\\phat_1(1-\\phat_1)}{n_1} & 0                              \\\\\n                0                              & \\frac{\\phat_2(1-\\phat_2)}{n_2}\n              \\end{pmatrix}\n              \\begin{pmatrix}\n                \\frac{1}{\\phat_1-\\phat_1^2} \\\\\n                \\frac{1}{\\phat_2^2-\\phat_2}\n              \\end{pmatrix}\n            }\n            =\\sqrt{\n              \\frac{1}{n_1(\\phat_1-\\phat_1^2)}+\n              \\frac{1}{n_2(\\phat_2^2-\\phat_2)}\n            }.\n          \\end{align*}\n          In particular, we have that the MLE of $\\psi$ is $0.9808$. The\n          estimated standard error is $0.2041$, and a 90\\% confidence interval\n          for $\\psi$ is given by $[0.6451, 1.317]$.\n    \\item Under the prior $f(p_1,p_2)=1$, the posterior mean of $\\psi$ is\n          $0.9693$, a 90\\% posterior confidence interval is given by\n          $[0.2244, 1.737]$.\n  \\end{enumerate}\n\\end{ex}\n\n% 5\n\\begin{ex}~\n  \\inputminted{python}{../code/11-05.py}\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.57]{../images/11-05a}\n    \\caption{\n      Plots of the prior distributions of $p$ given by\n      $\\text{Beta}(\\alpha, \\alpha)$ distributions for different values of\n      $\\alpha$. Note that in all cases, the distribution is centered at $1/2$,\n      but becomes more sharply peaked as $\\alpha$ increases.\n    }\n  \\end{figure}\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.57]{../images/11-05b}\n    \\caption{\n      Plots of the different posterior distributions for $p$ given the prior\n      distributions from the previous figure. Note that the larger $\\alpha$ is,\n      the less sensitive the posterior is to the data.\n    }\n  \\end{figure}\n\\end{ex}\n\n\\begin{ex}\n  Let $X_1,\\ldots,X_n\\sim\\text{Poisson}(\\lambda)$.\n  \\begin{enumerate}[(a)]\n    \\item Recall that if $\\lambda\\sim\\text{Gamma}(\\alpha,\\beta)$,\n          \\[\n            f(\\lambda)=\\frac{1}{\\beta^\\alpha\\Gamma(\\alpha)}\\lambda^{\\alpha-1}e^{-\\lambda/\\beta},\n          \\]\n          and that therefore\n          \\begin{align*}\n            f(\\lambda\\,|\\,x^n)\n             & \\propto \\left(\\prod_{i=1}^n e^{-\\lambda}\\frac{\\lambda^{x_i}}{x_i!}\\right)\n            \\frac{1}{\\beta^\\alpha\\Gamma(\\alpha)}\\lambda^{\\alpha-1}e^{-\\lambda/\\beta}     \\\\\n             & \\propto \\lambda^{\\alpha-1+\\sum_{i=1}^nx_i}e^{-\\lambda(\\beta n+1)/\\beta},\n          \\end{align*}\n          and hence\n          \\[\n            f(\\lambda\\,|\\,x^n)\n            =\\frac{1}{\\beta'^{\\alpha'}\\Gamma(\\alpha')}\\lambda^{\\alpha'-1}e^{-\\lambda/\\beta'},\n          \\]\n          where\n          \\[\n            \\alpha'=\\alpha+\\sum_{i=1}^nx_i,\\text{ and }\n            \\beta'=\\frac{\\beta}{n\\beta +1}.\n          \\]\n          Note that the mean of a $\\text{Gamma}(\\alpha', \\beta')$ distribution\n          is at $\\alpha'\\beta$, and that therefore the posterior mean is\n          \\[\n            \\left(\\alpha+\\sum_{i=1}^nx_i\\right)\n            \\left(\\frac{\\beta}{n\\beta +1}\\right).\n          \\]\n    \\item Recall that for a $\\text{Poisson}(\\lambda)$ distribution,\n          \\[\n            \\ell_n(\\lambda)=\\sum_{i=1}^n-\\lambda+x_i\\log(\\lambda)+\\log(x_i!),\n          \\]\n          and therefore\n          \\[\n            \\frac{\\d\\ell_n(\\lambda)}{\\d\\lambda}\n            =\\sum_{i=1}^n-1+x_i/\\lambda,\n            \\text{ and  }\n            \\frac{\\d^2\\ell_n(\\lambda)}{\\d\\lambda^2}\n            =-\\sum_{i=1}^n x_i/\\lambda^2.\n          \\]\n          Therefore, $I(\\lambda)=n/\\lambda$, and the Jeffreys' prior\n          $f(\\lambda)\\propto 1/\\sqrt{\\lambda}$. Hence,\n          \\begin{align*}\n            f(\\lambda\\,|\\,x^n)\n             & \\propto \\left(\\prod_{i=1}^n e^{-\\lambda}\\frac{\\lambda^{x_i}}{x_i!}\\right)\\frac{1}{\\sqrt{\\lambda}} \\\\\n             & \\propto \\lambda^{-1/2+\\sum_{i=1}^n x_i}e^{-\\lambda/n^{-1}},\n          \\end{align*}\n          and therefore the posterior is given by\n          \\[\n            f(\\lambda\\,|\\,x^n)\n            =\\frac{1}{n^{-(1/2+\\sum_{i=1}^nx_i)}\\Gamma(1/2+\\sum_{i=1}^nx_i)}\\lambda^{\\sum_{i=1}^nx_i+1/2-1}e^{-\\lambda/n^{-1}}.\n          \\]\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Let\n  \\[\n    \\psihat=\\frac{1}{n}\\sum_{i=1}^n\\frac{Y_iR_i}{\\xi_{X_i}}.\n  \\]\n  Then\n  \\begin{align*}\n    \\E{\\psihat}\n     & =\\E{\\frac{1}{n}\\sum_{i=1}^n\\frac{Y_iR_i}{\\xi_{X_i}}}               \\\\\n     & =\\frac{1}{n}\\sum_{i=1}^n\\E{\\frac{Y_iR_i}{\\xi_{X_i}}}               \\\\\n     & =\\frac{1}{n}\\sum_{i=1}^n\\E{\\cE{\\frac{Y_iR_i}{\\xi_{X_i}}}{Y_i,X_i}} \\\\\n     & =\\frac{1}{n}\\sum_{i=1}^n\\E{\\frac{Y_i}{\\xi_{X_i}}\\cE{R_i}{Y_i,X_i}} \\\\\n     & =\\frac{1}{n}\\sum_{i=1}^n\\E{Y_i}                                    \\\\\n     & =\\E{Y_i}                                                           \\\\\n     & =\\psi,\n  \\end{align*}\n  and since $\\delta\\leq \\xi_{X_i}\\leq 1-\\delta$,\n  \\begin{align*}\n    \\var{\\frac{Y_iR_i}{\\xi_{X_i}}}\n     & =\\E{\\frac{Y_i^2R_i^2}{\\xi^2_{X_i}}}\n    -\\left[\\E{\\frac{Y_iR_i}{\\xi^2_{X_i}}}\\right]^2 \\\\\n     & =\\E{\\frac{Y_iR_i}{\\xi^2_{X_i}}}\n    -\\left[\\E{\\frac{Y_iR_i}{\\xi_{X_i}}}\\right]^2   \\\\\n     & \\leq\\frac{1}{\\delta^2}\\E{Y_iR_i}\n    -\\frac{1}{(1-\\delta)^2}\\E{Y_iR_i}^2            \\\\\n     & \\leq\\frac{1}{\\delta^2},\n  \\end{align*}\n  and therefore\n  \\[\n    \\var{\\psihat}\n    =\\frac{1}{n}\\sum_{i=1}^n\\var{\\frac{Y_iR_i}{\\xi_{X_i}}}\n    \\leq\\frac{1}{n\\delta^2}.\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  We are testing the hypothesis $H_0:\\mu=0$ versus $H_1:\\mu\\neq 0$. We take the\n  priors $\\P{H_0}=\\P{H_1}=1/2$, and under $H_1$ we take the prior\n  $\\mu\\sim N(0, b^2)$. Recall from Section 11.8 that then\n  \\begin{align*}\n    \\cP{H_0}{X=x}\n    =\\frac{\\L(0)}{\\L(0)+\\int_{-\\infty}^\\infty \\L(\\mu)f(\\mu)\\,\\d{\\mu}}.\n  \\end{align*}\n  We have\n  \\begin{align*}\n    \\int_{-\\infty}^\\infty \\L(\\mu)f(\\mu)\\,\\d\\mu\n     & =\\int_{-\\infty}^\\infty \\frac{1}{\\sqrt{2\\pi}}\\exp\\left\\{-\\frac{(x-\\mu)^2}{2}\\right\\}\n    \\frac{1}{\\sqrt{2\\pi b^2}}\\exp\\left\\{-\\frac{\\mu^2}{2b^2}\\right\\}\\,\\d\\mu                 \\\\\n     & =\\frac{1}{\\sqrt{2\\pi}}\n    \\int_{-\\infty}^\\infty\\frac{1}{\\sqrt{2\\pi b^2}}\n    \\exp\\left\\{-\\frac{(x-\\mu)^2}{2}-\\frac{\\mu^2}{2b^2}\\right\\}\\,\\d\\mu                      \\\\\n     & =\\frac{1}{\\sqrt{2\\pi(b^2+1)}}\n    \\exp\\left\\{-\\frac{x^2}{2(b^2+1)}\\right\\}\n    \\int_{-\\infty}^\\infty\\frac{\\sqrt{b^2+1}}{\\sqrt{2\\pi b^2}}\n    \\exp\\left\\{\n    -\\frac{\\left(\\mu-\\frac{xb^2}{b^2+1}\\right)^2}{2b^2/(b^2+1)}\n    \\right\\}\\,\\d\\mu                                                                        \\\\\n     & =\\frac{1}{\\sqrt{2\\pi(b^2+1)}}\\exp\\left\\{-\\frac{x^2}{2(b^2+1)}\\right\\},\n  \\end{align*}\n  since\n  \\begin{align*}\n    b^2(x-\\mu)^2+\\mu^2\n     & =(b^2+1)\\mu^2-2xb^2\\mu+b^2x^2                                              \\\\\n     & =(b^2+1)\\left(\\mu^2-\\frac{2xb^2}{b^2+1}\\mu+\\frac{x^2b^4}{(b^2+1)^2}\\right)\n    -\\frac{x^2b^4}{b^2+1}+b^2x^2                                                  \\\\\n     & =(b^2+1)\\left(\\mu-\\frac{xb^2}{b^2+1}\\right)^2\n    +\\frac{-x^2b^4+b^4x^2+b^2x^2}{b^2+1}                                          \\\\\n     & =(b^2+1)\\left(\\mu-\\frac{xb^2}{b^2+1}\\right)^2\n    +\\frac{b^2x^2}{b^2+1}.\n  \\end{align*}\n\n  Therefore,\n  \\begin{align*}\n    \\cP{H_0}{X=x}\n     & =\\frac{\\L(0)}{\\L(0)+\\int_{-\\infty}^\\infty \\L(\\mu)f(\\mu)\\,\\d{\\mu}}              \\\\\n     & =\\frac{\\frac{1}{\\sqrt{2\\pi}}\\exp\\left\\{-\\frac{x^2}{2}\\right\\}}{\n      \\frac{1}{\\sqrt{2\\pi}}\\exp\\left\\{-\\frac{x^2}{2}\\right\\}\n      +\\frac{1}{\\sqrt{2\\pi(b^2+1)}}\\exp\\left\\{-\\frac{x^2}{2(b^2+1)}\\right\\}\n    }                                                                                 \\\\\n     & =\\frac{\\exp\\left\\{-\\frac{x^2}{2}\\right\\}}{\n      \\exp\\left\\{-\\frac{x^2}{2}\\right\\}\n      +\\frac{1}{\\sqrt{b^2+1}}\\exp\\left\\{-\\frac{x^2}{2(b^2+1)}\\right\\}}                \\\\\n     & =\\frac{\\sqrt{b^2+1}}{\\sqrt{b^2+1}+\\exp\\left\\{\\frac{x^2b^2}{2(b^2+1)}\\right\\}}.\n  \\end{align*}\n  The $p$-value of the Wald test is given by\n  \\[\n    \\P{|Z|>|x|}=2\\Phi(-|x|).\n  \\]\n\n  \\inputminted{python}{../code/11-08a.py}\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.54]{../images/11-08a}\n    \\caption{Comparison of the posterior probability of $H_0$ for different\n      values of $b$ and the Wald test $p$-value as a function of $x$.}\n  \\end{figure}\n\n  If instead we have a sample of size $n$,\n  \\begin{align*}\n     & \\int_{-\\infty}^\\infty \\L(\\mu)f(\\mu)\\,\\d\\mu                                                                       \\\\\n     & \\,=\\int_{-\\infty}^\\infty\\prod_{i=1}^n\\left[\\frac{1}{\\sqrt{2\\pi}}\\exp\\left\\{-\\frac{(x_i-\\mu)^2}{2}\\right\\}\\right]\n    \\frac{1}{\\sqrt{2\\pi b^2}}\\exp\\left\\{-\\frac{\\mu^2}{2b^2}\\right\\}\\,\\d\\mu                                              \\\\\n     & \\, =(2\\pi)^{-n/2}(b^2n+1)^{-1/2}\\exp\\left\\{-\\frac{\\beta-\\alpha^2/(b^2n+1)}{2}\\right\\}\n    \\int_{-\\infty}^\\infty \\frac{\\sqrt{b^2n+1}}{\\sqrt{2\\pi b^2}}\\exp\\left\\{\n    -\\frac{\\left(\\mu-\\frac{b^2\\alpha}{b^2n+1}\\right)^2}{2b^2/(b^2n+1)}\n    \\right\\}\\,\\d{\\mu}                                                                                                   \\\\\n     & \\, =(2\\pi)^{-n/2}(b^2n+1)^{-1/2}\\exp\\left\\{-\\frac{\\beta(b^2n+1)-\\alpha^2}{2(b^2n+1)}\\right\\},\n  \\end{align*}\n  since\n  \\begin{align*}\n    b^2\\sum_{i=1}^n(x_i-\\mu)^2+\\mu^2\n     & =(b^2n+1)\\mu^2-2b^2\\left(\\sum_{i=1}^nx_i\\right)\\mu+b^2\\left(\\sum_{i=1}^n x_i^2\\right)                                        \\\\\n     & =(b^2n+1)\\left(\\mu^2-2\\frac{b^2\\alpha}{b^2n+1}\\mu+\\frac{b^4\\alpha^2}{(bn^2+1)^2} \\right)-\\frac{b^4\\alpha^2}{b^2n+1}+b^2\\beta \\\\\n     & =(b^2n+1)\\left(\\mu-\\frac{b^2\\alpha}{b^2n+1}\\right)^2+b^2\\left(\\beta-\\frac{b^2\\alpha^2}{b^2n+1}\\right)                        \\\\\n  \\end{align*}\n  where $\\alpha=\\sum_{i=1}^n x_i$ and $\\beta=\\sum_{i=1}^n x_i^2$.\n\n  Therefore,\n  \\begin{align*}\n    \\cP{H_0}{X^n=x^n}\n     & =\\frac{\\L(0)}{\\L(0)+\\int_{-\\infty}^\\infty \\L(\\mu)f(\\mu)\\,\\d{\\mu}}                        \\\\\n     & =\\frac{(2\\pi)^{-n/2}\\exp\\left\\{-\\frac{1}{2}\\beta\\right\\}}{\n      (2\\pi)^{-n/2}\\exp\\left\\{-\\frac{1}{2}\\beta\\right\\}\n      +(2\\pi)^{-n/2}(b^2n+1)^{-1/2}\\exp\\left\\{-\\frac{\\beta (b^2n+1)-b^2\\alpha^2}{2(b^2n+1)}\\right\\}\n    }                                                                                           \\\\\n     & =\\frac{\\sqrt{b^2n+1}}{\\sqrt{b^2n+1}+\\exp\\left\\{\\frac{b^2\\alpha^2}{2(b^2n+1)}\\right\\}}    \\\\\n     & =\\frac{\\sqrt{b^2n+1}}{\\sqrt{b^2n+1}+\\exp\\left\\{\\frac{b^2n^2\\Xbar^2}{2(b^2n+1)}\\right\\}},\n  \\end{align*}\n  while the Wald test $p$-value for a sample of size $n$ is\n  \\[\n    \\P{|Z|>\\sqrt{n}|\\Xbar|}\n    =2\\Phi\\left(-\\sqrt{n}|\\Xbar|\\right).\n  \\]\n\n  \\inputminted{python}{../code/11-08b.py}\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.545]{../images/11-08b}\n    \\caption{Comparison of the posterior probability of $H_0$ for different\n      values of $b$ and the Wald test $p$-value as a function of the sample\n      average and for different sample sizes. Note that as $n$ increases, a\n      region forms in which the $p$-value is near $0$, but the conditional\n      probability of $H_0$ is near $1$.}\n  \\end{figure}\n\n\\end{ex}", "meta": {"hexsha": "95a7c4a7d40334f875ef54963612192b35fc6ded", "size": 20801, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/ch11.tex", "max_stars_repo_name": "dtrifuno/all-of-stats-solutions", "max_stars_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/tex/ch11.tex", "max_issues_repo_name": "dtrifuno/all-of-stats-solutions", "max_issues_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tex/ch11.tex", "max_forks_repo_name": "dtrifuno/all-of-stats-solutions", "max_forks_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.1926977688, "max_line_length": 204, "alphanum_fraction": 0.4974760829, "num_tokens": 7876, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762114, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7472984901527425}}
{"text": "\\chapter{Self-organizing Feature Maps}\nNeurons in layers excite its closest neighbours via \\emph{lateral connections} and inhibit the distance neighbours. \\emph{Lateral} interactions create \\emph{competition and cooperation} among them. \n\n\\section{Self-Organizing Neural Networks}\n\\begin{figure}[!h]\n\\centering\n\\includegraphics[width=8cm]{chapter9_1}\n\\end{figure}\n\n\\section{Similarity Measures}\nEuclidean distance:\n\\begin{equation*}\n\\begin{split}\ndistance &= \\|\\boldsymbol{x}_i - \\boldsymbol{x}_j \\| \\\\\n&= \\sqrt{(\\boldsymbol{x}_i - \\boldsymbol{x}_j)^{T} (\\boldsymbol{x}_i - \\boldsymbol{x}_j)} \\\\\n&= \\sqrt{\\sum_k (x_{ik} - x_{jk})^{2}}\n\\end{split}\n\\end{equation*}\nCosine similarity:\n$$\\cos \\theta = \\frac{\\boldsymbol{x}_i^{T} \\boldsymbol{x}_j}{\\|\\boldsymbol{x_i}\\|\\|\\boldsymbol{x_j}\\|}$$\n\n\\section{Kohonen's Neural Network}\nSynaptic input to the output layer:\n$$\\mathbf{u = Wx}$$\nThe ouput of the network:\n$$\\mathbf{y = f(u)}$$\n\n\\subsection{Winner-Takes-All Rule}\nIf winner is the $m$ th neuron, then:\n$$m = \\arg\\!\\max_{i=1...M} u_i$$\nThe output of the neuron:\n$$y_m = 1$$\nThe output of other neurons:\n$$y_i = 0$$\n\n\\subsection{Kohonen Learning Rule}\nPrior to learning, all the weight vectors are randomly initialized and then normalized:\n$$\\mathbf{\\hat{w}} = \\frac{\\mathbf{w}_j}{\\|\\mathbf{w}_j\\|}$$\nNext, \\emph{find the winner} and update its weight:\n\\begin{equation*}\n\\begin{split}\n\\mathbf{w}_m^{t+1} &= \\mathbf{\\hat{w}}_m^{t} + \\Delta \\mathbf{\\hat{w}}_m^{t} \\\\\n&= \\mathbf{\\hat{w}}_m^{t} + \\alpha^{t}(\\mathbf{x} - \\mathbf{\\hat{w}}_m^{t})\n\\end{split}\n\\end{equation*}\nThe new weight is then normalized.\n\n\\subsubsection{Neurons with the highest synaptic inputs are winner}\nWe want to find the closest weight vector $w$ to current input $x$:\n$$\\| \\mathbf{x} - \\mathbf{\\hat{w}}_m \\| = \\!\\min_{j=1...M} \\| \\mathbf{x} - \\mathbf{\\hat{w}}_j \\|$$\n\\begin{equation*}\n\\begin{split}\n\\| \\mathbf{x} - \\mathbf{\\hat{w}}_m \\| &= \\Big[(\\mathbf{x} - \\mathbf{\\hat{w}}_m)^{T}(\\mathbf{x} - \\mathbf{\\hat{w}}_m) \\Big]^{\\frac{1}{2}} \\\\\n&= \\Big(\\mathbf{x^{T}x - 2\\hat{w}_{m}x + 1} \\Big)^{\\frac{1}{2}}\n\\end{split}\n\\end{equation*}\nSearching for the closest weight vector is equivalent to:\n\\begin{equation*}\n\\begin{split}\n\\mathbf{\\hat{w}}_m^{T} \\mathbf{x} &= \\!\\max_{j=1...M} \\mathbf{\\hat{w}}_j^{T} \\mathbf{x} \\\\\nu_m &= \\!\\max_{j=1...M} u_j\n\\end{split}\n\\end{equation*}\n\n\\subsubsection{Impact of the Learning Rule}\nKohonen learning rule should increase the chances of winning of neuron $m$ after each iteration. It means that:\n$$u_m^{new} > u_m^{old}$$\nProof:\n$$u_m^{new} - u_m^{old} = \\alpha (\\| x \\|^{2} - \\| \\hat{w}_m^{T} \\| \\|x\\|\\cos \\theta)$$\nBut $\\cos \\theta \\le 1$, $1 > \\alpha > 0$ and $\\|\\hat{w}\\| = 1$, assume $\\|x\\| = 1$, so: \n$$u_m^{new} > u_m^{old}$$\nThat's why we need to normalize weight after each iterations.\n\n\\subsubsection{Geometrical Interpretation of the Learning Rule}\n$\\Delta \\mathbf{\\hat{w}}_m$ is a rotation of $\\mathbf{\\hat{w}}_m$ toward input vector $\\mathbf{\\hat{x}}$ without significant length change. \n\\begin{figure}[!h]\n\\centering\n\\includegraphics[width=5cm]{chapter9_2}\n\\end{figure}\n\n\\subsubsection{Initialization of the Weights}\nConvex combination:\n$$\\mathbf{w}_j^{0} = \\frac{1}{\\sqrt{n}} (1 1 ... 1)^{T}$$\n\n\\subsubsection{Limitation of Basic Kohonen Network}\n\\begin{enumerate}\n\\item Linearly non-separable pattern cannot be efficiently handled\n\\item Not always successful for linearly separable patterns\n\\item Neurons with initial weights far from any input vector may never win\n\\end{enumerate}\n\n\\section{Kohonen Self-Organizing Feature Maps}\nIn the training phase, we update weight vector of winning neuron $m$ \\emph{and its neighbours} according to the radius $N_m^{t}$. The weight of winning neuron is updated using the method described in previous section. The weight of neighbours is updated by:\n$$\\Delta \\mathbf{w}_j^{new} = \\alpha(j,t) (\\mathbf{x} - \\mathbf{w}_j^{old})$$\n$$\\forall j \\in N_m(t)$$\n\n\\section{Vector Quantization}\nVector quantizer $Q$ is a mapping:\n$$Q:\\mathbf{R}^{n} \\rightarrow C$$\n\\begin{center}where $C={c_1 c_2 \\ldots c_M}$ is a set of vectors or codewords\\end{center}\nFor an input vector $\\mathbf{x} \\in R^{n}$ the output of quantizer ca be implemented in competitive neural network\n$$Q(\\mathbf{x}) = c_m$$\n$$if\\ \\|\\mathbf{x-c_m} \\| = \\!\\min_{i} \\| \\mathbf{x-c_i} \\|$$\n\n\\subsection{LVQ1}\nLVQ is a supervised form of algorithm for Vector Quantization\n\\begin{enumerate}\n\\item The weight vector $\\mathbf{w_j}$ are defined using SOFM\n\\item For each input pattern, find winning neuron $m$\n\\item If the desired winner for $\\mathbf{x}$ is $q$\n$$\n\\mathbf{w}_m^{new} = \n\\begin{cases}\n\\mathbf{w}_m + \\alpha (\\mathbf{x} - \\mathbf{w}_m) & m = q \\\\\n\\mathbf{w}_m - \\alpha (\\mathbf{x} - \\mathbf{w}_m) & m \\ne q\n\\end{cases}\n$$\n$$w_j^{new} = w_j, \\forall j \\ne m$$\n\\end{enumerate}\n\n\\subsection{LVQ2}\nSame as LVQ1, but learning is applied only if:\n\\begin{enumerate}\n\\item The desired winner is not the winner, $m \\ne q$\n\\item The second closest prototype vector is $w_{m*}$ the correct class\n\\item The input vector is close to the boundary between $\\mathbf{w}_m$ and $w_{m*}$\n\\end{enumerate}\n\\begin{equation*}\n\\begin{split}\n\\mathbf{w}_{m*}^{new} &= \\mathbf{w}_{m*} + \\alpha (\\mathbf{x} - \\mathbf{w}_{m*}) \\\\\n\\mathbf{w}_{m}^{new} &= \\mathbf{w}_{m} + \\alpha (\\mathbf{x} - \\mathbf{w}_{m}) \\\\\nw_j^{new} &= w_j, \\forall j \\ne m, m*\\end{split}\n\\end{equation*}\n", "meta": {"hexsha": "5994edc26c26181f9ff7af86773dc2400309fa5f", "size": 5365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter9.tex", "max_stars_repo_name": "Andyccs/neural-network-summary", "max_stars_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter9.tex", "max_issues_repo_name": "Andyccs/neural-network-summary", "max_issues_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter9.tex", "max_forks_repo_name": "Andyccs/neural-network-summary", "max_forks_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.0373134328, "max_line_length": 257, "alphanum_fraction": 0.6767940354, "num_tokens": 1881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467643431002, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7472494122053649}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 7}\n\nProve that the following are equivalent.\n\\begin{enumerate}\n  \\item\n  \\begin{enumerate}\n    \\item $V_1$ is a vertex cover of $G$.\n    \\item $V - V_1$ is an independent set in $G$.\n  \\end{enumerate}\n  \\item\n  \\begin{enumerate}\n    \\item $V_2$ is an independent set in $G$.\n    \\item $V_2$ is a clique in $G^c$.\n  \\end{enumerate}\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}\n  \\item To prove 1(a) and 1(b) are equivalent, we need to show vertex cover and independent set problems are polynomially equivalent.\n  \\begin{enumerate}\n    \\item Objective is to prove any independent set of vertices $V_2$ for an undirected graph $G = (V, E)$ is reducible to a vertex cover on $G' = (V_1, E')$ where $V_1 = V - V_2$.\n    Since $V_1$ is an independent set, for any edge $e = (u,v) \\in E$ either $u\\in V_2$ or $v\\in V_2$ which means either $u \\in V_1$ or $v \\in V_1$. Since $E$, by definition, contains all the edges in graph $G$, any $e \\in E$ has at least one end in $V_1$, which means $V_1 = V - V_2$ is a vertex cover.\n    \\item Objective is to show any vertex cover $V_1 \\in V$ in $G(V, E)$ is reducible to an independent set of vertices $V_2 = V - V_1$. Proof is given by contradiction that $V_2$ must form an independent set. Suppose $V_2$ is not an independent set which means there is an edge $e = (u,v) \\in E$ such that both its endpoints are in $V_2$. Therefore $\\{u, v\\} \\notin V_1$ which means set of vertices $V_1$ does not cover $e$ and therefore $V_1$ is not a vertex cover of $G$ which is a contradiction.\n  \\end{enumerate}\n  Thus both problems 1(a) and 1(b) are polynomially reducible to each other which means they are equally hard.\n  \\item To prove 2(a) and 2(b) are equivalent, we need to show independent set and clique problems are polynomially equivalent.\n  \\begin{enumerate}\n    \\item Objective is to prove any independent set of vertices $V_2$ for an undirected graph $G = (V, E)$ is reducible to a clique on $G^c = (V, E')$. Since $V_2$ form an independent set, for any pair of vertices $\\{u, v\\} \\in V_2$, $e = (u, v) \\notin E$ which means $(u, v) \\in E'$. Thus since all vertices in $V_2$ are mutually connected in $G^c = (V, E')$, they form a clique in $G'$.\n    \\item Objective is to prove any set of vertices $V_2$ that form a clique in $G^c=(V, E')$ form an independent set in $G = (V, E)$. Similar to previous proof, for any pair of vertices $\\{u, v\\}\\in V_2$, $e = (u, v) \\in E'$ which means $(u,v) \\notin E$, i.e. no two vertices of $V_2$ are directly connected in $G=(V,E)$ which means they form an independent set.\n  \\end{enumerate}\n  Thus both problems 2(a) and 2(b) are polynomially reducible to each other which means they are equally hard.\n\\end{enumerate}\n", "meta": {"hexsha": "fe41ed2b815b735d51de42373f4cc49b9312085b", "size": 3078, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw06/hw06q07.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw06/hw06q07.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw06/hw06q07.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 75.0731707317, "max_line_length": 499, "alphanum_fraction": 0.6624431449, "num_tokens": 951, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711642563823, "lm_q2_score": 0.8791467643431002, "lm_q1q2_score": 0.7472493988409363}}
{"text": "\n\\subsection{Subrings}\n\nA subring is a subset of the ring, where the addition and multiplication operations on the subring result in elements also in the subring.\n\n\\subsubsection{Example}\n\nThe even numbers are a subring of the integers.\n\n", "meta": {"hexsha": "d030849b8b06d524a50599322199a7c2b32ca8f5", "size": 238, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/rings/06-01-subring.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/rings/06-01-subring.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/rings/06-01-subring.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.8, "max_line_length": 138, "alphanum_fraction": 0.7941176471, "num_tokens": 54, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632916317102, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7471137099626367}}
{"text": "\\section{Model}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Algorithm analysis}\n  \\begin{itemize}\n\t\\item Given a problem $P$\n\t\\item design an alg. $A$\n\t\\item input space $\\mathcal{X}_{n}$: inputs of size $n$\n  \\end{itemize}\n\n  \\pause\n  \\[\n\tW(n) = T_{\\text{worst-case}}(n) = \\max_{X \\in \\mathcal{X}_{n}} T(X)\n  \\]\n\n  \\pause\n  \\[\n\tB(n) = T_{\\text{best-case}}(n) = \\min_{X \\in \\mathcal{X}_{n}} T(X)\n  \\]\n\n  \\pause\n  \\[\n\tA(n) = T_{\\text{average-case}}(n) = \\sum_{X \\in \\mathcal{X}_{n}} T(X) \\cdot Pr(X) \\pause = E_{X \\in \\mathcal{X}_{n}} [T(X)]\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{(Problem 1.1.8)}\n  \\begin{align*}\n\tA &= \\sum_{X \\in \\mathcal{X}} T(X) \\cdot Pr(X) \\\\\n\t  &= T(1) Pr(1) + T(2) Pr(2) + \\cdots + T(n) Pr(n) \\\\\n\t  &= \\cdots  \\\\\n  \\end{align*}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Average-case analysis of Quicksort}\n  \\[\n\tA(n) = n-1 + \\frac{1}{n} \\sum_{i=0}^{i=n-1} (A(i) + A(n-i-1))\n  \\]\n\n  \\[\n\tA(n) = E_{X \\in \\mathcal{X}_{n}} [T(X)] = \\sum_{X \\in \\mathcal{X}_{n}} T(X) \\cdot Pr(X)\n  \\]\n\n  \\pause\n\n  \\begin{align*}\n\tA(n) &= E[T(X)] \\\\\n\t    &\\textcolor{red}{= E[E[T(X)|I]]} \\\\\n\t\t&= \\sum_{i=0}^{i=n-1} Pr(I = i)E[T(X) \\mid I = i] \\\\\n\t\t&= \\sum_{i=0}^{i=n-1} \\frac{1}{n} [n-1 + A(i) + A(n-i-1)]\n  \\end{align*}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "c8b59766fb3407d7f9fb80ab8d65d411a6ee1a00", "size": 1265, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/algorithm-tutorial-math-dc-20170329/sections/model.tex", "max_stars_repo_name": "hengxin/algorithm-ta-tutorial", "max_stars_repo_head_hexsha": "0bb0376d96f388671597903fc833f68d7946020e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 45, "max_stars_repo_stars_event_min_datetime": "2017-03-29T08:22:32.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-02T15:12:15.000Z", "max_issues_repo_path": "alg-ta-by-years/alg-ta-2017/algorithm-tutorial-math-dc-20170329/sections/model.tex", "max_issues_repo_name": "courses-at-nju-by-hfwei/algorithm-ta-tutorial", "max_issues_repo_head_hexsha": "0bb0376d96f388671597903fc833f68d7946020e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "alg-ta-by-years/alg-ta-2017/algorithm-tutorial-math-dc-20170329/sections/model.tex", "max_forks_repo_name": "courses-at-nju-by-hfwei/algorithm-ta-tutorial", "max_forks_repo_head_hexsha": "0bb0376d96f388671597903fc833f68d7946020e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-10T08:47:12.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-18T07:58:43.000Z", "avg_line_length": 23.4259259259, "max_line_length": 124, "alphanum_fraction": 0.4735177866, "num_tokens": 562, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545377452443, "lm_q2_score": 0.7879311881731379, "lm_q1q2_score": 0.7470805314973626}}
{"text": "\\documentclass{scrartcl}\n\n\\input{../../shared.tex}\n\\theoremstyle{definition}\n\\newtheorem{definition}{Definition}[section]\n\\newtheorem{lemma}{Lemma}[section]\n\\usepackage{enumerate}\n\n\\begin{document}\n\n\n\\section*{Problem set: Gradient descent and Fixed points}%\n\n\n\n\\paragraph{Exercise (i)} (1P)  Let $f_1, f_2, \\dots, f_m$ be smooth with parameters $L_1, L_2, \\dots L_m$. Show that the function $f:= \\sum_{i=1}^{m}f_i$f is smooth with parameter $\\sum_{i=1}^{m}L_i$.\n\n\\paragraph{Exercise (ii)} (1P)  Let $f$ be smooth with parameter $L$ and $A$ a matrix. Show that $f\\circ A$ is smooth with parameter $L \\Vert A \\Vert^2$.\n\n\n\n\n\\subsection*{Computing Fixed Points}%\n\nGradient descent turns up in a surprising number of situations which apriori have nothing to do with optimization.\nIn this exercise we will see how computing the fixed point of functions can be seen as a form of gradient descent.\nSuppose that we have a $1$-Lipschitz continuous function $g : \\R \\to \\R$ such that we want to solve for\n\\begin{equation}\n  g(x) = x .\n\\end{equation}\nA simple strategy for finding such a fixed point is to run the following algorithm: starting from an arbitary $x_0$,\nwe iteratively set\n\\begin{equation}\n  \\label{fpi}\n  x_{k+1} = g(x_k) .\n\\end{equation}\n\n\\paragraph{Exercise (iii)} (3P) Enter the missing code snippets in the jupyter notebook. Partial credit will be awarded.\n\nWe will try solve for $x$ starting from $x_0 = 1$ in the following two equations:\n\\begin{equation}\n  \\label{log}\n  x = \\log(1 + x), \\quad \\text{and} \\quad x = \\log(2 + x).\n\\end{equation}\nWhat difference do you observe in the rate of convergence between the two problems? Let’s understand why this happens:\n\n\\paragraph{Exercise (iv)} (3P) Theoretical fixed point questions.\n\\begin{itemize}\n  \\item We want to re-write the update~\\eqref{fpi} as a step of gradient descent. To do this, we need to find a function $f$\n        such that the gradient descent update is identical to~\\eqref{fpi}:\n        \\begin{equation}\n          x_{k+1} = x_k - \\alpha f'(x_k) = g(x_k) .\n        \\end{equation}\n        Derive such a function $f$.\n  \\item Give sufficient conditions on $g$ to ensure convergence of procedure~\\eqref{fpi}. What $\\alpha$ would you need to pick?\n        Hint: We know that gradient descent on f with fixed step-size converges if $f$ is convex and smooth. What\n        does this mean in terms of $g$?\n  \\item What condition does $g$ need to satisfy to ensure linear convergence? Are these satisfied for the problems in~\\eqref{log}\n\\end{itemize}\n\n\n\\end{document}\n", "meta": {"hexsha": "4b97174ea23b2ed6c06668fdc6259ceda2313509", "size": 2534, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/03_more_GD/exercises-GD.tex", "max_stars_repo_name": "lgru/optimization-for-DS-lecture", "max_stars_repo_head_hexsha": "7c3708dd0b9ae2d712235eec7b23644cccf8f44d", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/03_more_GD/exercises-GD.tex", "max_issues_repo_name": "lgru/optimization-for-DS-lecture", "max_issues_repo_head_hexsha": "7c3708dd0b9ae2d712235eec7b23644cccf8f44d", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/03_more_GD/exercises-GD.tex", "max_forks_repo_name": "lgru/optimization-for-DS-lecture", "max_forks_repo_head_hexsha": "7c3708dd0b9ae2d712235eec7b23644cccf8f44d", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.2222222222, "max_line_length": 200, "alphanum_fraction": 0.7134964483, "num_tokens": 735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.9086178919837705, "lm_q1q2_score": 0.7470557545868237}}
{"text": "\\problemname{Interval Product}\n%\\illustration{.5}{filename}{Image by \\href{url}{Author}}\n\nThere is an array of $N$ positive integers, $x_1, x_2, ... x_N$.\nYour friend gives you $Q$ queries, which can be:\n\\begin{itemize}\n\\item {\\tt q l r} : Consider the product $P = x_l \\times x_{l+1} \\times ... \\times x_{r-1} \\times x_r$. How many trailing zeroes are there in the binary representation of $P$? (Yay! Your friend no longer cares about the product being positive, negative, or zero.)\n\\item {\\tt s i v} : Set the value of $x_i$ to $v$.\n\\end{itemize}\nSince your friend have a large number of queries, you have to find a way to answer them efficiently.\n\n\\section*{Input}\nThe first line of the input has an integer $T$, the number of test cases.\\\\\nEach case has two integer $N, Q$ on the first line.\\\\\nThe next line has $N$ integers, $x_1, x_2, ... x_N$.\\\\\nEach of the next $Q$ lines gives a query, which can be one of the two types introduced above.\n\n\\section*{Output}\n\nFor each query of the first type, output the number of trailing zeroes in the binary representation of the interval product.\n\n\\section*{Constraints}\n\\begin{itemize}\n\\item $1 \\leq T\\leq 15$\n\\item $1 \\leq N, Q \\leq 10^5$\n\\item $1 \\leq l \\leq r \\leq N$ for all queries of the first type. $1 \\leq i \\leq N$ for all queries of the second type.\n\\item It is guaranteed that $1 \\leq x_i \\leq 10^9$ for $1 \\leq i \\leq N$ before the first query and after every query is processed.\n\\end{itemize}\n\n\\section*{Subtasks}\n\\begin{itemize}\n\\item There are only queries of the first type. That is, there will be no changes on the array.\n\\item Original constraints\n\\end{itemize}\n\nNote that the last sample case will not appear in the {\\it Small} subtask, as it contains queries of the second type.\n\n\\section*{Hint}\nThe number of trailing zeroes in the binary representation of a decimal integer $P$ equals how many times $P$ can be evenly divided by 2. For example, $44 = (101100)_2$ has two trailing zeroes and can be evenly divided at most twice: $44 / 2 = 22$, $22 / 2 = 11$, and $11$ is odd.\n", "meta": {"hexsha": "1d3527a996a9d14e584facfd95b3c30dd4907906", "size": 2043, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "server/test_root/problem/product/problem_statement/problem.en.tex", "max_stars_repo_name": "yubowenok/coda", "max_stars_repo_head_hexsha": "29f2fd090c644b9dc1f4fa506da2dee1bd4f4102", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-09-27T04:45:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-12T01:31:40.000Z", "max_issues_repo_path": "server/test_root/problem/product/problem_statement/problem.en.tex", "max_issues_repo_name": "yubowenok/coda", "max_issues_repo_head_hexsha": "29f2fd090c644b9dc1f4fa506da2dee1bd4f4102", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-07-18T09:28:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-10T16:03:33.000Z", "max_forks_repo_path": "server/test_root/problem/product/problem_statement/problem.en.tex", "max_forks_repo_name": "yubowenok/coda", "max_forks_repo_head_hexsha": "29f2fd090c644b9dc1f4fa506da2dee1bd4f4102", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-29T20:59:27.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-29T20:59:27.000Z", "avg_line_length": 51.075, "max_line_length": 280, "alphanum_fraction": 0.7170827215, "num_tokens": 612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.8652240895276223, "lm_q1q2_score": 0.7470272287693497}}
{"text": "\\section{Calculus with Vector Functions}\\label{sec:calculus with vector functions}\n\nA vector function $\\vect{r}(t)=\\langle f(t),g(t),h(t)\\rangle$ \\index{vector function}is a\nfunction of one variable---that is, there is only one ``input''\nvalue. What makes vector functions more complicated than the functions\n$y=f(x)$ that we studied in the first part of this book is of course\nthat the ``output'' values are now three-dimensional vectors instead\nof simply numbers. It is natural to wonder if there is a corresponding\nnotion of derivative for vector functions. In the simpler case of a\nfunction $y=s(t)$, in which $t$ represents time and $s(t)$ is position\non a line, we have seen that the derivative $s'(t)$ represents\nvelocity; we might hope that in a similar way the derivative of a\nvector function would tell us something about the velocity of an\nobject moving in three dimensions.\n\nOne way to approach the question of the derivative for vector\nfunctions is to write down an expression that is analogous to the\nderivative we already understand, and see if we can make sense of\nit. If we say that what we mean by the limit of a vector is the vector of\nthe individual coordinate limits, this gives us\n\\begin{align*}\n  \\vect{r}^{\\prime}(t)&=\\lim_{\\Delta t\\to0}{\\vect{r}(t+\\Delta t)-\\vect{r}(t)\\over\n  \\Delta t}\t\\\\\n  &=\\lim_{\\Delta t\\to0}{\\langle f(t+\\Delta t)-f(t),g(t+\\Delta t)-g(t),\n  h(t+\\Delta t)-h(t)\\rangle\\over \\Delta t}\t\\\\\n  &=\\lim_{\\Delta t\\to0}\\langle {f(t+\\Delta t)-f(t)\\over\\Delta t},\n  {g(t+\\Delta t)-g(t)\\over\\Delta t},\n  {h(t+\\Delta t)-h(t)\\over \\Delta t}\\rangle\t\\\\\n  &=\\langle f'(t),g'(t),h'(t)\\rangle,\n\\end{align*}\n\nStarting with a familiar\nexpression for what appears to be a derivative, we find that we can\nmake good computational sense out of it---but what does it actually\nmean?\n\nWe know how to interpret $\\vect{r}(t+\\Delta t)$ and $\\vect{r}(t)$---they\nare vectors that point to locations in space; if $t$ is time, we can\nthink of these points as positions of a moving object at times that\nare $\\Delta t$ apart. We also know what $\\Delta \\vect{r}= \\vect{r}(t+\\Delta t)-\\vect{r}(t)$\nmeans---it is a vector that points from the head of $\\vect{r}(t)$ to\nthe head of $\\vect{r}(t+\\Delta t)$, assuming both have their tails at\nthe origin. So when $\\Delta t$ is small, \n$\\Delta \\vect{r}$ is a tiny vector pointing from one\npoint on the path of the object to a nearby point. As $\\Delta t$ gets\nclose to 0, this vector points in a direction that is closer and\ncloser to the direction in which the object is moving; geometrically,\nit approaches a vector tangent to the path of the object at a\nparticular point.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <6truemm,6truemm>\n\\setplotarea x from 0 to 11, y from 0 to 5.1\n\\arrow <5pt> [0.17, 0.5] from 0 0 to 2 3\n\\arrow <5pt> [0.17, 0.5] from 2 3 to 7 4\n\\arrow <5pt> [0.17, 0.5] from 0 0 to 7 4\n\\put {$\\vect{r}(t)$} [l] <8pt,7pt> at 1 1.5\n\\put {$\\Delta\\vect{r}$} [br] <0pt,-10pt> at 4.5 3.5\n\\put {$\\vect{r}(t+\\Delta t)$} [tl]\n  <3pt,-3pt> at 3.5 2\n\\setquadratic\n%\\plot 0.000 1.926 0.275 2.117 0.550 2.293 0.825 2.454 1.100 2.602 \n%1.375 2.737 1.650 2.860 1.925 2.971 2.200 3.073 2.475 3.164 \n%2.750 3.247 3.025 3.321 3.300 3.389 3.575 3.450 3.850 3.505 \n%4.125 3.556 4.400 3.602 4.675 3.646 4.950 3.687 5.225 3.727 \n%5.500 3.766 5.775 3.805 6.050 3.844 6.325 3.886 6.600 3.930 \n%6.875 3.977 7.150 4.029 7.425 4.085 7.700 4.147 7.975 4.216 \n%8.250 4.292 8.525 4.376 8.800 4.469 9.075 4.572 9.350 4.685 \n%9.625 4.810 9.900 4.947 10.175 5.097 10.450 5.261 10.725 5.439 \n%11.000 5.633 /\n\\plot 0.000 0.850 0.275 1.243 0.550 1.603 0.825 1.930 1.100 2.227 \n1.375 2.494 1.650 2.733 1.925 2.946 2.200 3.134 2.475 3.299 \n2.750 3.443 3.025 3.565 3.300 3.669 3.575 3.756 3.850 3.827 \n4.125 3.884 4.400 3.928 4.675 3.961 4.950 3.984 5.225 3.999 \n5.500 4.007 5.775 4.010 6.050 4.010 6.325 4.007 6.600 4.003 \n6.875 4.001 7.150 4.000 7.425 4.004 7.700 4.012 7.975 4.028 \n8.250 4.052 8.525 4.086 8.800 4.132 9.075 4.190 9.350 4.262 \n9.625 4.351 9.900 4.457 10.175 4.582 10.450 4.727 10.725 4.894 \n11.000 5.085 /\n\\endpicture}}\n\\caption{Approximating the derivative. \\label{fig:vector derivative}}\n\\end{figure}\n\nUnfortunately, the vector $\\Delta\\vect{r}$ approaches 0 in length; the\nvector $\\langle 0,0,0\\rangle$ is not very informative. By dividing by\n$\\Delta t$, when it is small, we effectively keep magnifying the\nlength of $\\Delta\\vect{r}$ so that in the limit it doesn't disappear. Thus the\nlimiting vector $\\langle f'(t),g'(t),h'(t)\\rangle$ will (usually) be a\ngood, non-zero vector that is tangent to the curve.\n\nWhat about the length of this vector? It's nice that we've kept it\naway from zero, but what does it measure, if anything?\nConsider the length of one of the vectors that approaches the tangent\nvector:\n%$$\\eqalign{\n%|\\langle {f(t+\\Delta t)-f(t)\\over\\Delta t}&,\n%{g(t+\\Delta t)-g(t)\\over\\Delta t},\n%{h(t+\\Delta t)-h(t)\\over \\Delta t}\\rangle|=\\cr\n%&{\\sqrt{(f(t+\\Delta t)-f(t))^2+(g(t+\\Delta t)-g(t))^2+(h(t+\\Delta t)-h(t))^2}\n%\\over\\Delta t}\\cr\n%}$$\n$$\\left|{\\vect{r}(t+\\Delta t)-\\vect{r}(t)\\over\n\\Delta t}\\right|={|\\vect{r}(t+\\Delta t)-\\vect{r}(t)|\\over|\\Delta t|}$$\nThe numerator is the length of the vector that points from one position\nof the object to a ``nearby'' position; this length is approximately\nthe distance travelled by the object between times $t$ and $t+\\Delta\nt$. Dividing this distance by the length of time it takes to travel\nthat distance gives the average speed. As $\\Delta t$ approaches zero,\nthis average speed approaches the actual, instantaneous speed of the\nobject at time $t$. \n\nBy performing an ``obvious'' calculation to get something that\nlooks like the derivative of $\\vect{r}(t)$, we get precisely what we\nwould want from such a derivative: the vector $\\vect{r}'(t)$\npoints in the direction of travel of the object and its length tells\nus the speed of travel. In the case that $t$ is time, then, we call \n$\\vect{v}(t)=\\vect{r}'(t)$ the velocity vector. Even if $t$ is not time,\n$\\vect{r}'(t)$ is useful---it is a vector tangent to the curve.\\index{vector function!derivative}\n\n\\begin{example}{}{}\nWe have seen that $\\vect{r}=\\langle \\cos t,\\sin t,t\\rangle$ is a helix. Compute $\\vect{r}'$ and $|\\vect{r}'|$.\n\\end{example}\n\n\\begin{solution}\nWe compute $\\vect{r}'=\\langle -\\sin t,\\cos t,1\\rangle$, and\n$|\\vect{r}'|=\\sqrt{\\sin^2 t+\\cos^2 t+1}=\\sqrt2$. Thinking of this as\na description of a moving object, its speed is always $\\sqrt2$; see\nFigure~\\ref{fig:helix with tangent}.\n\\end{solution}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n\\put {\\hbox{\\epsfxsize5cm\\epsfbox{images/helix_with_tangent.eps}}} at 0 0\n\\endpicture}}\n\\caption{A tangent vector on the helix. \\label{fig:helix with tangent}}\n\\end{figure}\n\n\\begin{example}{}{}\nThe velocity vector for $\\langle \\cos t,\\sin\nt,\\cos t\\rangle$ is $\\langle -\\sin t,\\cos\nt,-\\sin t\\rangle$. As before, the first two coordinates mean that from\nabove this curve looks like a circle. The $z$ coordinate is now also\nperiodic, so that as the object moves around the curve its height\noscillates up and down. In fact it turns out that the curve is a\ntilted ellipse, as shown in Figure~\\ref{fig:tilted ellipse}.\n\\end{example}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n\\put {\\hbox{\\epsfxsize5cm\\epsfbox{images/tilted_ellipse.eps}}} at 0 0\n\\endpicture}}\n\\caption{The ellipse $\\vect{r}=\\langle \\cos t,\\sin\nt,\\cos t\\rangle$. \\label{fig:tilted ellipse}}\n\\end{figure}\n\n\\begin{example}{}{}\nThe velocity vector for $\\langle \\cos t,\\sin\nt,\\cos 2t\\rangle$ is $\\langle -\\sin t,\\cos\nt,-2\\sin 2t\\rangle$. The $z$ coordinate is now oscillating twice as\nfast as in the previous example, so the graph is not surprising; see\nFigure~\\ref{fig:roller coaster}.\n\\end{example}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n\\put {\\hbox{\\epsfxsize5cm\\epsfbox{images/coaster_with_tangent.eps}}} at 0 0\n\\endpicture}}\n\\caption{$\\langle \\cos t,\\sin\nt,\\cos 2t\\rangle$. \\label{fig:roller coaster}}\n\\end{figure}\n\n\\begin{example}{}{anglebetweencurves}\nFind the angle between the curves $\\langle t+1,t-2,t^2-4 \\rangle$ and \n$\\langle t+2,-t+3,t^2+1\\rangle$ where they meet.\n\\end{example}\n\\begin{solution}\nThe angle between two curves at a point is the angle between their\ntangent vectors---any tangent vectors will do, so we can use the\nderivatives. We need to find the point of intersection, evaluate the\ntwo derivatives there, and finally find the angle between them.\n\nTo find the point of intersection, we need to solve the equations\n\\begin{align*}\nt+1&=u+2\t\\\\\nt-2&=-u+3\t\\\\\nt^2-4&=u^2+1\n\\end{align*}\nSolving either of the first two equations for $u$ and substituting in\nthe third gives $t=3$. This together with\n$u=2$ satisfies all three equations. Thus the two curves meet at\n$(4,1,5)$, the first curve when $t=3$ and the second curve when\n$t=2$.\n\nThe derivatives are $\\langle 1,1,2t\\rangle$ and\n$\\langle 1,-1,2t\\rangle$; at the intersection point these are\n$\\langle 1,1,6\\rangle$ and $\\langle 1,-1,4\\rangle$. The cosine of the\nangle between them is then\n$$\\cos\\theta = {1-1+24\\over\\sqrt{38}\\sqrt{18}}={4\\over\\sqrt{19}},$$\nso $\\theta=\\arccos(4/\\sqrt{19})\\approx0.41$.\n\\end{solution}\n\nThe derivatives of vector functions obey some familiar looking rules,\nwhich we will occasionally need.\n\n\\begin{theorem}{Vector Derivative Properties}{vector derivative properties}\nSuppose $\\vect{r}(t)$ and $\\vect{s}(t)$ are differentiable vector functions,\n$f(t)$ is a differentiable function, and $a$ is a real number.\\index{vector function!derivative properties}\n\\begin{enumerate}\n\\item\t$\\ds {d\\over dt} a\\vect{r}(t)= a\\vect{r}'(t)$\n\\item\t$\\ds {d\\over dt} (\\vect{r}(t)+\\vect{s}(t))=\n\\vect{r}'(t)+\\vect{s}'(t)$\n\\item\t$\\ds {d\\over dt} f(t)\\vect{r}(t)= f(t)\\vect{r}'(t)+f'(t)\\vect{r}(t)$\n\\item\t$\\ds {d\\over dt} (\\vect{r}(t)\\cdot\\vect{s}(t))=\n\\vect{r}'(t)\\cdot\\vect{s}(t)+\\vect{r}(t)\\cdot\\vect{s}'(t)$\n\\item\t$\\ds {d\\over dt} (\\vect{r}(t)\\times\\vect{s}(t))=\n\\vect{r}'(t)\\times\\vect{s}(t)+\\vect{r}(t)\\times\\vect{s}'(t)$\n\\item\t$\\ds {d\\over dt} \\vect{r}(f(t))= \\vect{r}'(f(t))f'(t)$\n\\end{enumerate}\n\\end{theorem}\n\nNote that because the cross product is not commutative you must\nremember to do the three cross products in formula (5.) in the correct\norder. \n\nWhen the derivative of a function $f(t)$ is zero, we know that the\nfunction has a horizontal tangent line, and may have a local maximum\nor minimum point. If $\\vect{r}'(t)=\\vect{0}$, the geometric\ninterpretation is quite different, though the interpretation in terms\nof motion is similar. Certainly we know that the object has speed zero\nat such a point, and it may thus be abruptly changing direction. In\nthree dimensions there are many ways to change direction;\ngeometrically this often means the curve has a cusp or a point, as in\nthe path of a ball that bounces off the floor or a wall.\n\n\\begin{example}{}{}\nSuppose that $\\vect{r}(t)=\\langle 1+t^3,t^2,1\\rangle$, so\n$\\vect{r}'(t)=\\langle 3t^2,2t,0\\rangle$. This is $\\vect{0}$ at $t=0$, and\nthere is indeed a cusp at the point $(1,0,1)$, as\nshown in Figure~\\ref{fig:spacecurve cusp}.\n\\end{example}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n\\put {\\hbox{\\epsfxsize5cm\\epsfbox{images/spacecurve_cusp.eps}}} at 0 0\n\\endpicture}}\n\\caption{$\\langle 1+t^3,t^2,1\\rangle$ has a cusp at $\\langle 1,0,1\\rangle$. \\label{fig:spacecurve cusp}}\n\\end{figure}\n\nSometimes we will be interested in the direction of $\\vect{r}'$ but not\nits length. In some cases, we can still work with $\\vect{r}'$, as when\nwe find the angle between two curves. On other occasions it will be\nuseful to work with a unit vector in the same\ndirection as $\\vect{r}'$; of course, we can compute such a vector by\ndividing $\\vect{r}'$ by its own length. This standard unit tangent\nvector is usually denoted by $\\vect{T}$:\n$$\\vect{T}={\\vect{r}'\\over|\\vect{r}'|}.$$\\index{vector function!standard unit tangent vector}\nIn a sense, when we computed the angle between two tangent vectors we\nhave already made use of the unit tangent, since\n$$\\cos\\theta = {\\vect{r}'\\cdot\\vect{s}'\\over|\\vect{r}'||\\vect{s}'|}=\n{\\vect{r}'\\over|\\vect{r}'|}\\cdot{\\vect{s}'\\over|\\vect{s}'|}$$\n\nNow that we know how to make sense of $\\vect{r}'$, we immediately know\nwhat an antiderivative must be, namely\n$$\\int \\vect{r}(t)\\,dt = \\langle \\int f(t)\\,dt,\\int g(t)\\,dt,\\int h(t)\\,dt\n\\rangle,$$ if $\\vect{r}=\\langle f(t),g(t),h(t)\\rangle$. What about\ndefinite integrals?  Suppose that $\\vect{v}(t)$ gives the velocity of\nan object at time $t$. Then $\\vect{v}(t)\\Delta t$ is a vector that\napproximates the displacement of the object over the time $\\Delta t$:\n$\\vect{v}(t)\\Delta t$ points in the direction of travel, and $|\\vect{v}(t)\\Delta t|=|\\vect{v}(t)||\\Delta t|$ is the speed of the object\ntimes $\\Delta t$, which is approximately the distance travelled. Thus,\nif we sum many such tiny vectors:\n$$\\sum_{i=0}^{n-1}\\vect{v}(t_i)\\Delta t$$\nwe get an approximation to the displacement vector over the time\ninterval $[t_0,t_n]$. If we take the limit we get the exact\nvalue of the displacement vector:\n$$\\lim\\sum_{i=0}^{n-1}\\vect{v}(t_i)\\Delta t = \\int_{t_0}^{t_n}\\vect{v}(t)\\,dt = \\vect{r}(t_n)-\\vect{r}(t_0).$$\nThus, given the velocity vector we can compute the vector function\n$\\vect{r}$ giving the location of the object:\n$$\\vect{r}(t)=\\vect{r}_0+\\int_0^t \\vect{v}(u)\\,du.$$\n\n\\begin{example}{}{}\nAn object moves with velocity vector $\\langle \\cos t, \\sin t,\n\\cos t\\rangle$, starting at $(1,1,1)$. Find the function\n$\\vect{r}$ giving its location.\n\\end{example}\n\\begin{solution}\n\\begin{align*}\n\\vect{r}(t)&=\\langle 1,1,1\\rangle+\\int_0^t \\langle \\cos u, \\sin u,\n\\cos u\\rangle\\,du\t\\\\\n&=\\langle 1,1,1\\rangle+\\left.\\langle \\sin u, -\\cos u,\\sin u\\rangle\n\\right|_0^t\t\\\\\n&=\\langle 1,1,1\\rangle+\\langle \\sin t, -\\cos t,\\sin t\\rangle-\n\\langle 0,-1,0\\rangle\t\\\\\n&=\\langle 1+\\sin t, 2-\\cos t,1+\\sin t\\rangle\n\\end{align*}\nSee Figure~\\ref{fig:velocity cos sin cos}.\n\\end{solution}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n\\put {\\hbox{\\epsfxsize5cm\\epsfbox{images/path_with_tangent.eps}}} at 0 0\n\\endpicture}}\n\\caption{Path of the object with its initial velocity vector. \\label{fig:velocity cos sin cos}}\n\\end{figure}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:calculus with vector functions}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nFind $\\vect{r}'$ and $\\vect{T}$ for\n$\\vect{r} = \\langle t^2,1,t\\rangle$.\n\\begin{sol}\n\t$\\langle 2t,0,1\\rangle$, $\\vect{r}'/\\sqrt{1+4t^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $\\vect{r}'$ and $\\vect{T}$ for\n$\\vect{r} = \\langle \\cos t, \\sin 2t, t^2\\rangle$.\n\\begin{sol}\n\t$\\langle -\\sin t, 2\\cos 2t,2t\\rangle$,\n\t$\\vect{r}'/\\sqrt{\\sin^2t + 4\\cos^2(2t)+4t^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $\\vect{r}'$ and $\\vect{T}$ for\n$\\vect{r} = \\langle \\cos(e^t),\\sin(e^t),\\sin t\\rangle$.\n\\begin{sol} $\\langle -e^t\\sin(e^t),e^t\\cos(e^t),\\cos t\\rangle$,\n$\\vect{r}'/\\sqrt{e^{2t}+\\cos^2 t}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind a vector function for the line tangent to the helix\n$\\langle \\cos t,\\sin t, t\\rangle$ when $t=\\pi/4$.\n\\begin{sol} $\\langle \\sqrt2/2,\\sqrt2/2,\\pi/4\\rangle+\nt\\langle -\\sqrt2/2,\\sqrt2/2,1\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind a vector function for the line tangent to \n$\\langle \\cos t,\\sin t, \\cos 4t \\rangle$ when $t=\\pi/3$.\n\\begin{sol} $\\langle 1/2,\\sqrt3/2,-1/2\\rangle+\nt\\langle -\\sqrt3/2,1/2,2\\sqrt3\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the cosine of the angle between the curves $\\langle\n0,t^2,t\\rangle$ and $\\langle \\cos(\\pi t/2),\\sin(\\pi t/2), t\\rangle$\nwhere they intersect.\n\\begin{sol} $2/\\sqrt5/\\sqrt{4+\\pi^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the cosine of the angle between the curves $\\langle\n\\cos t,-\\sin(t)/4,\\sin t\\rangle$ and $\\langle \\cos t,\\sin t, \\sin(2t)\\rangle$\nwhere they intersect.\n\\begin{sol} $7\\sqrt{5}\\sqrt{17}/85$, $-9\\sqrt{5}\\sqrt{17}/85$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\\label{ex:derivative is perpendicular}\nSuppose that $|\\vect{r}(t)|=k$, for some constant $k$. This\nmeans that $\\vect{r}$ describes some path on the sphere of radius $k$\nwith center at the origin. Show that $\\vect{r}$ is perpendicular to $\\vect{r}'$ at every point. Hint: Use Theorem~\\ref{thm:vector derivative properties}, part (d).\n\\end{ex}\n\n\\begin{ex}\nA bug is crawling along the spoke of a wheel that lies along\na radius of the wheel. The bug is crawling at 1 unit per second and\nthe wheel is rotating at 1 radian per second. Suppose the wheel lies\nin the $y$-$z$ plane with center at the origin, and at time $t=0$ the\nspoke lies along the positive $y$ axis and the bug is at the origin. \nFind a vector function $\\vect{r}(t)$\nfor the position of the bug at time $t$, the velocity vector\n$\\vect{r}'(t)$, the unit tangent $\\vect{T}(t)$, and the speed of the bug\n$|\\vect{r}'(t)|$.\n\\begin{sol} $\\langle 0,t\\cos t,t\\sin t\\rangle$, \n$\\langle 0,\\cos t-t\\sin t,\\sin t+t\\cos t\\rangle$,\n$\\vect{r}'/\\sqrt{1+t^2}$, $\\sqrt{1+t^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nAn object moves with velocity vector $\\langle \\cos t, \\sin t,\nt\\rangle$, starting at $\\langle 0,0,0\\rangle$ when $t=0$. Find the function\n$\\vect{r}$ giving its location.\n\\begin{sol} $\\langle \\sin t,1-\\cos t,t^2/2\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nThe position function of a particle is given by $\\vect{r}(t) =\n\\langle t^2,5t,t^2-16t\\rangle$, $t\\geq 0$.  When is the speed of the particle\na minimum?\n\\begin{sol} $t=4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nA particle moves so that its position is given by\n$\\langle \\cos t, \\sin t, \\cos(6t)\\rangle$. Find the maximum and\nminimum speeds of the particle.\n\\begin{sol} $37$, $1$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nAn object moves with velocity vector $\\langle t, t^2,\n\\cos t\\rangle$, starting at $\\langle 0,0,0\\rangle$ when $t=0$.\n Find the function\n$\\vect{r}$ giving its location.\n\\begin{sol} $\\langle t^2/2,t^3/3,\\sin t\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nWhat is the physical interpretation of the dot product of two\n  vector valued functions?  What is the physical interpretation of the\n  cross product of two vector valued functions?\n\\end{ex}\n\n\\begin{ex}\nShow, using the rules of cross products and differentiation,\n  that\n$${d\\over dt} (\\vect{r}(t) \\times \\vect{r}'(t))= \n\\vect{r}(t) \\times \\vect{r}''(t).$$\n\\end{ex}\n\n\\begin{ex}\nDetermine the point at which $\\vect{f}(t)=\\langle t, t^2, t^3\n\\rangle$ and $\\vect{g}(t) =\\langle \\cos(t), \\cos(2t), t+1 \\rangle$\nintersect, and find the angle between the curves at that point.  (Hint:\nYou'll need to set this one up like a line intersection problem,\nwriting one in $s$ and one in $t$.) If these two functions were the\ntrajectories of two airplanes on the same scale of time, would the\nplanes collide at their point of intersection?  Explain.\n\\begin{sol} $(1,1,1)$ when $t=1$ and $s=0$; $\\theta=\\arccos(3/\\sqrt{14})$; no\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the equation of the plane perpendicular to the curve $\\vect{r}(t)\n = \\langle 2\\sin(3t),t,2\\cos(3t)\\rangle$ at the point $(0,\\pi,-2)$.\n\\begin{sol} $-6x+(y-\\pi)=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the equation of the plane perpendicular to \n$\\langle \\cos t, \\sin t, \\cos(6t)\\rangle$ when $t=\\pi/4$.\n\\begin{sol} $\\ds -x/\\sqrt2+y/\\sqrt2+6z=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nAt what point on the curve \n$\\vect{r}(t) = \\langle t^3,3t,t^4\\rangle$ is the\nplane perpendicular to the curve also parallel to the plane $6x+6y-8z=1$?\n\\begin{sol} $(-1,-3,1)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the equation of the line tangent to \n$\\langle \\cos t, \\sin t, \\cos(6t)\\rangle$ when $t=\\pi/4$.\n\\begin{sol} $\\langle 1/\\sqrt2,1/\\sqrt2,0\\rangle+t\\langle -1,1,6\\sqrt2\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "75d890b3c5b8f1768b46a755649c65ded05c6984", "size": 20043, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "13-vector-functions/13-2-calculus-with-vector-functions.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "13-vector-functions/13-2-calculus-with-vector-functions.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "13-vector-functions/13-2-calculus-with-vector-functions.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.8469184891, "max_line_length": 163, "alphanum_fraction": 0.6921119593, "num_tokens": 7168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782011, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.7470272241257575}}
{"text": "\\subsection{Computing Exact Trigonometric Ratios}\nThe \\dfont{unit circle} is often used to determine the \\ifont{exact} value of a particular trigonometric function.\n\n$$\\includegraphics[width=5in]{images/unit-circle}$$\n\nReading from the unit circle one can see that $\\cos (5\\pi/6)=-\\sqrt 3/2$ and $\\sin (5\\pi/6)=1/2$ (remember that the $x\\,$-coordinate is $\\cos\\theta$ and the $y$-coordinate is $\\sin\\theta$ for the unit circle).\nHowever, we don't always have access to the unit circle.\nIn this case, we can compute the exact trigonometric ratios for $\\theta=5\\pi/6$ by using \\dfont{special triangles} and the \\dfont{CAST rule} described below.\n\nThe first special triangle has angles of $45^\\circ,45^\\circ,90^\\circ$ (i.e., $\\pi/4,\\pi/4,\\pi/2$) with side lengths $1,1,\\sqrt 2$, while the second special triangle has angles of $30^\\circ,60^\\circ,90^\\circ$ (i.e., $\\pi/6,\\pi/3,\\pi/2$) with side lengths $1,2,\\sqrt 3$. They are classically referred to as the $1-1-\\sqrt{2}$ triangle, and the $1-2-\\sqrt{3}$ triangle, respectively, shown below.\n$$\\includegraphics[width=4.0in]{images/trig4}$$\n\n\\begin{formulabox}[Mnemonic]\nThe first triangle should be easy to remember. \nTo remember the second triangle, place the largest number ($2$) across from the largest angle ($90^\\circ=\\pi/2$).\nPlace the smallest number ($1$) across from the smallest angle ($30^\\circ=\\pi/6$).\nPlace the middle number ($\\sqrt 3\\approx 1.73$) across from the middle angle ($60^\\circ=\\pi/3$).\nDouble check using the Pythagorean Theorem that the sides satisfy $a^2+b^2=c^2$.\n\\end{formulabox}\n\nThe special triangles allow us to compute the exact value (excluding the sign) of trigonometric ratios, but to determine the sign, we can use the \\ifont{CAST rule}.\n\n\\begin{formulabox}[The CAST Rule]\nThe CAST rule says that in quadrant I all three of $\\sin\\theta$, $\\cos\\theta$, $\\tan\\theta$ are positive.\nIn quadrant II, only $\\sin\\theta$ is positive, while $\\cos\\theta$, $\\tan\\theta$ are negative.\nIn quadrant III, only $\\tan\\theta$ is positive, while $\\sin\\theta$, $\\cos\\theta$ are negative.\nIn quadrant IV, only $\\cos\\theta$ is positive, while $\\sin\\theta$, $\\tan\\theta$ are negative. \nTo remember this, simply label the quadrants by the letters C-A-S-T starting in the bottom right and labelling counter-clockwise.\n\\end{formulabox} \n\n$$\\includegraphics[width=2.5in]{images/trig5}$$\n\n\\begin{example}{Determining Trigonometric Ratios Without Unit Circle}{CASTRule}\nDetermine $\\sin (5\\pi/6)$, $\\cos (5\\pi/6)$, $\\tan (5\\pi/6)$, $\\sec (5\\pi/6)$, $\\csc (5\\pi/6)$ and $\\cot (5\\pi/6)$ exactly by using the special triangles and CAST rule.\n\\end{example}\n\n\\begin{solution} \nWe start by drawing the $xy$-plane and indicating our angle of $5\\pi/6$ in standard position (positive angles rotate \\ifont{counterclockwise} while negative angles rotate \\ifont{clockwise}).\nNext, we drop a perpendicular to the $x\\,$-axis (never drop it to the $y$-axis!).\n$$\\includegraphics[width=4in]{images/trig6}$$\nNotice that we can now figure out the angles in the triangle.\nSince $180^\\circ=\\pi$, we have an interior angle of $\\pi-5\\pi/6=\\pi/6$ inside the triangle. \nAs the \\ifont{angles of a triangle add up to $180^\\circ=\\pi$}, the other angle must be $\\pi/3$. \nThis gives one of our special triangles.\nWe label it accordingly and add the CAST rule to our diagram.\n$$\\includegraphics[width=3in]{images/trig7}$$\nFrom the above figure we see that $5\\pi/6$ lies in quadrant II where $\\sin\\theta$ is positive and $\\cos\\theta$ and $\\tan\\theta$ are negative.\nThis gives us the \\ifont{sign} of $\\sin\\theta$, $\\cos\\theta$ and $\\tan\\theta$.\nTo determine the \\ifont{value} we use the special triangle and SOH CAH TOA.\n\nUsing $\\sin\\theta=opp/hyp$ we find a value of $1/2$.\nBut $\\sin\\theta$ is positive in quadrant II, therefore, \n$$\\sin \\left(\\frac{5\\pi}{6}\\right)=\\frac{1}{2}.$$\n\nUsing $\\cos\\theta=adj/hyp$ we find a value of $\\sqrt 3/2$.\nBut $\\cos\\theta$ is negative in quadrant II, therefore, \n$$\\cos \\left(\\frac{5\\pi}{6}\\right) =-\\frac{\\sqrt 3}{2}.$$\n\nUsing $\\tan\\theta=opp/adj$ we find a value of $1/\\sqrt 3$.\nBut $\\tan\\theta$ is negative in quadrant II, therefore, \n$$\\tan \\left(\\frac{5\\pi}{6}\\right) =-\\frac{1}{\\sqrt 3}.$$\n\nTo determine $\\sec\\theta$, $\\csc\\theta$ and $\\cot\\theta$ we use the definitions:\n$$\\csc \\left(\\frac{5\\pi}{6}\\right)  = \\ds\\frac{1}{\\sin \\left(\\frac{5\\pi}{6}\\right)}  = 2,\n\\qquad \\sec \\left(\\frac{5\\pi}{6}\\right)  = \\ds\\frac{1}{\\cos \\left(\\frac{5\\pi}{6}\\right) } = -\\frac{2}{\\sqrt 3},\n\\qquad\\cot \\left(\\frac{5\\pi}{6}\\right) = \\ds\\frac{1}{\\tan \\left(\\frac{5\\pi}{6}\\right)} = -\\sqrt 3.$$\n\\end{solution}\n\n\\begin{example}{CAST Rule}{CASTRule2}\nIf $\\cos\\theta=3/7$ and $3\\pi/2<\\theta< 2\\pi$, then find $\\cot\\theta$.\n\\end{example}\n\n\\begin{solution} \nWe first draw a right angle triangle.\nSince $\\cos\\theta=adj/hyp=3/7$, we let the adjacent side have length $3$ and the hypotenuse have length $7$.\n$$\\includegraphics[height=1.1in]{images/trig8}$$\nUsing the Pythagorean Theorem, we have $3^2+(\\mbox{opp})^2=7^2$.\nThus, the opposite side has length $\\sqrt{40}$.\n$$\\includegraphics[height=1.1in]{images/trig9}$$\n%Recall that \\green{right angle triangles} can give us the \\red{value} of trigonometric ratios while the \\green{CAST rule} gives us the \\red{sign}.**\nTo find $\\cot\\theta$ we use the definition:\n$$\\cot\\theta=\\frac{1}{\\tan\\theta}.$$\nSince we are given $3\\pi/2<\\theta< 2\\pi$, we are in the fourth quadrant. By the CAST rule, $\\tan\\theta$ is negative in this quadrant.\nAs $\\tan\\theta=opp/adj$, it has a value of $\\sqrt{40}/3$, but by the CAST rule it is negative, that is,\n$$\\tan\\theta=-\\frac{\\sqrt{40}}{3}.$$\nTherefore,\n$$\\cot\\theta=-\\frac{3}{\\sqrt{40}}.$$\n\\end{solution}", "meta": {"hexsha": "935930f8329f9f5bd4047121c821d3613dd40692", "size": 5624, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1-review/1-3-3-exact-trig-ratios.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1-review/1-3-3-exact-trig-ratios.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1-review/1-3-3-exact-trig-ratios.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.9090909091, "max_line_length": 393, "alphanum_fraction": 0.7021692745, "num_tokens": 1843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.8633916047011595, "lm_q1q2_score": 0.747027206081746}}
{"text": "\\chapter{Foundamentals of Speech Signal Processing}\nThe basic concepts of signal processing have been covered in EI015 Signals and Systems,  and therefore will not be mentioned in this note.\n\nIn other words, I am lazy.\n\\newpage\n\\section{Discrete Fourier Transform}\nSimilar to the continuous case, given a periodic discrete signal $\\tilde{x}[n]$\\footnote{The tilde sign here means that $\\tilde{x}[n]$ is periodic.} with period $N$, it can be represented by \\emph{a discrete sum of sinusoids}, rather than an integral (Recall the DTFT Synthesis Formula. Thank you, EI015!).\n\n$\\tilde{x}[n]$ can be represented as a sum of complex exponentials with radian frequency $(2\\pi k / N)$, where $k=0,1,\\dots,N-1$.\n\\[ \\tilde{X}[k] = \\sum_{n=0}^{N-1}\\tilde{x}[n]e^{-j\\frac{2\\pi}{N}kn} \\]\n\nAnd the corresponding synthesis expression is\n\\[ \\tilde{x}[n] = \\frac{1}{N}\\sum_{k=0}^{N-1}\\tilde{X}[k]e^{j\\frac{2\\pi}{N}kn} \\]\n\nThis representation of a periodic discrete signal is \\emph{exact}. However, the DFT is generally used in another case, where $x[n]$ is a \\emph{finite} sequence of signal. Since performing DFT only need $\\tilde{x}[n]$ in a period $0 \\le n \\le N-1$, and whatever is out of this range does not matter, we may extend $x[n]$ and assume an ``implicit periodic sequence'' $\\tilde{x}[n]$:\n\\[ \\tilde{x}[n] = \\sum_{r = -\\infty}^{+\\infty} x[n + rN] \\]\n\nAnd here comes our DFT.\n\\begin{definition}[Discrete Fourier Transform]\n    \\[ X[k] = \\sum_{n=0}^{N-1} x[n]e^{-j\\frac{2\\pi}{N}kn} \\quad k = 1,2,\\dots,N-1 \\]\n    \\[ x[n] = \\sum_{k=0}^{N-1} X[k]e^{j\\frac{2\\pi}{N}kn} \\quad n = 1,2,\\dots,N-1 \\]\n\\end{definition}\n\\begin{remark}\n    Bear in mind that when using DFT representations, all signals behave as if they were implicitly \\emph{periodic}, as the DFT is originally defined on periodic signals.\n\\end{remark}\n\n\\section{Voiced, Unvoiced and Silence}\nThe speech waveform can be classified into basically 3 stages.\n\\paragraph*{Unvoiced} Produced by creating a constriction somewhere in the vocal tract tube and forcing air through that constriction, thereby creating turbulent air flow, which acts as \\emph{a broad-spectrum noise excitation of the vocal tract tube}. \n\\paragraph*{Voiced} Produced by forcing air through the glottis with the tension of the vocal cords adjusted so that they vibrate in a relaxation oscillation, leading to \\emph{quasi-periodic} waveforms.\n\\paragraph*{Silence} Usually occurs at the beginning or the end of speech, lacks characteristics of either voiced sounds or unvoiced sounds.", "meta": {"hexsha": "5059028e43fe4ca78b0ec77319715e53a8ed00e5", "size": 2502, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Speech Recognition/SpeechSignalProcessing.tex", "max_stars_repo_name": "YBRua/CourseNotes", "max_stars_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-20T10:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T08:15:15.000Z", "max_issues_repo_path": "Speech Recognition/SpeechSignalProcessing.tex", "max_issues_repo_name": "YBRua/CourseNotes", "max_issues_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Speech Recognition/SpeechSignalProcessing.tex", "max_forks_repo_name": "YBRua/CourseNotes", "max_forks_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T11:31:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T11:31:00.000Z", "avg_line_length": 80.7096774194, "max_line_length": 380, "alphanum_fraction": 0.7262190248, "num_tokens": 748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620468, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7469986013057388}}
{"text": "%!TEX root = ms.tex\n\\section{Introduction}\n\\subsection{Model selection under linear restrictions}\nConsider a linear regression problem with an $n\\times 1$ response vector $y$ and an $n\\times p$ design matrix $X$. The true model is generated from \n\\begin{equation}\ny=X \\beta_0 + \\epsilon,\n\\label{eq:truemodel}\n\\end{equation}\nwhere $\\beta_0$ is a $p \\times 1$ true coefficient vector, and the $n \\times 1$ vector $\\epsilon$ is independent of $X$, with $\\{\\epsilon_i\\}_{i=1}^n \\stackrel {iid} {\\sim} N(0,\\sigma_0^2)$. Note that $\\beta_0$ represents the true parameters, not an intercept term. \nWe consider an approximating model \n\\begin{equation*}\ny=X \\beta + u,\n%\\label{eq:approxmodel}\n\\end{equation*}\nwhere $\\beta$ is $p \\times 1$ and the $n \\times 1$ vector $u$ is independent of $X$, with $\\{u_i\\}_{i=1}^n \\stackrel {iid} {\\sim} N(0,\\sigma^2)$. For this approximating model, we further impose $m$ linear restrictions on the coefficient vectors $\\beta$ that are given by\n\\begin{equation}\n  R \\beta = r,\n  \\label{eq:restriction}\n\\end{equation}\nwhere $R$ is an $m \\times p$ matrix with linearly independent rows ($\\text{rank}(R)=m$) and $r$ is an $m \\times 1$ vector. Both $R$ and $r$ are nonrandom. Examples of such restrictions include setting some slopes equal to 0 (which corresponds to variable selection), setting slopes equal to each other (which corresponds to using the sum of predictors in a model), and setting sums of slopes to 0 (which for pairs of predictors corresponds to using the difference of the predictors in a model).\n\nSuppose first that $X$ is deterministic; we refer to this as the fixed-X design. Denote $f(y_i|x_i,\\beta,\\sigma^2)$ as the density for $y$ conditional on the $i$-th row of $x_i$. We have the log-likelihood function (multiplied by $-2$)\n\\begin{equation}\n-2 \\log f(y|X,\\beta,\\sigma^2) = -2 \\sum_{i=1}^n \\log f(y_i|x_i,\\beta,\\sigma^2) = n \\log (2\\pi \\sigma^2) + \\frac{1}{\\sigma^2} || y-X\\beta||_2^2.\n\\label{eq:loglike_fixedx}\n\\end{equation}\nBy minimizing \\eqref{eq:loglike_fixedx} subject to \\eqref{eq:restriction}, we obtain the restricted maximum likelihood estimator (MLE)\n\\begin{equation}\n\\begin{aligned}\n\\hat{\\beta} &= \\hat{\\beta}^f + (X^T X)^{-1} R^T ( R(X^T X)^{-1} R^T)^{-1} (r-R \\hat{\\beta}^f),\\\\ \n\\hat \\sigma^2 &= \\frac{1}{n} ||y-X \\hat{\\beta}||^2, \n\\end{aligned}\n\\label{eq:betahat_sigmahatsq}\n\\end{equation}\nwhere $\\hat{\\beta}^f = (X^T X)^{-1} X^T y$ is the unrestricted least squares estimator. Since the errors are assumed to be Gaussian, $\\hat\\beta$ is also the restricted least squares estimator. \n\nIn practice, a sequence of estimators $\\hat\\beta(R_i,r_i|X,y)$, each based on a different set of restrictions, is often generated, and the goal is to choose the one with the best predictive performance. This can be done on the basis of information criteria, which are designed to estimate the predictive accuracy for each considered model. Note that the notion of predictive accuracy can be as simple as distance of a predicted value from a future value, as is the case in squared-error prediction measures, but also can encompass the more general idea that the log-likelihood is a measure of the accuracy of a fitted distribution as a prediction for the distribution of a future observation. This idea can be traced back to \\citet{Akaike1973}, as noted in an interview with Akaike \\citep{findley1995conversation}; see also \\citet{efron1986biased}. \n\n\\subsection{Variable selection under fixed-X}\n\\label{sec:intro_subsetselection}\nAn important example of comparing models with different linear restrictions on $\\beta$ is variable selection. We consider fitting the ordinary least squares (OLS) estimator on a predetermined subset of predictors with size $k$, and without loss of generality, the subset includes the first $k$ predictors of $X$, i.e. $\\hat\\beta^f(X_1,\\cdots,X_k,y)$. By letting $R_k= \\irow{0 & I_{p-k}}_{(p-k) \\times p} $ and $r_k = \\irow{0}_{(p-k) \\times 1}$, it is easy to verify that $\\hat{\\beta}(R_k,r_k|X,y)=\\hat\\beta^f(X_1,\\cdots,X_k,y)$. Therefore, comparing OLS fits on different subsets of predictors falls into the framework of comparing estimators with different linear restrictions on $\\beta$.\n\nInformation criteria are designed to provide an unbiased estimate of the test error. We simplify the notation by denoting $\\hat\\beta(k) = \\hat{\\beta}(R_k,r_k|X,y)$. We also denote errF as the in-sample training error and ErrF as the out-of-sample test error. errF measures how well the estimated model fits on the training data $(X,y)$, while ErrF measures how well the estimated model predicts the new test data $(X,\\tilde{y})$, where $\\tilde{y}$ is an independent copy of the original response $y$, i.e. $\\tilde{y}$ is drawn from the conditional distribution of $y|X$. The notations of errF and ErrF are based on those in \\citet{efron2004estimation}, and the notation F here indicates that we have a fixed-$X$ design. \\citet{efron1986biased} defined the optimism of a fitting procedure as the difference between the test error and the training error, i.e.\n\\begin{equation*}\n\\text{optF} = \\text{ErrF} - \\text{errF},\n%\\label{eq:optF}\n\\end{equation*}\nand introduced the optimism theorem,\n\\begin{equation*}\nE_y(\\text{optF}) = E_y(\\text{ErrF}) - E_y(\\text{errF}),\n\\end{equation*}\nwhere $E_y$ represents the expectation taken under the true model with respect to the random variable $y$. The optimism theorem provides an elegant framework to obtain an unbiased estimator of $E(\\text{ErrF})$, \nthat is\n\\begin{equation*}\n\\widehat{\\text{ErrF}} = \\text{errF} + E_y(\\text{optF}),\n%\\label{eq:ErrFhat}\n\\end{equation*}\nwhere the notation $\\widehat{\\text{ErrF}}$ follows from \\citet{efron2004estimation}. It turns out that many existing information criteria can be derived using the concept of optimism. \n\nA typical measure of the discrepancy between the true model and an approximating model is the squared error (SE), i.e. \n\\begin{equation*}\n\\text{ErrF}_\\text{SE} = E_{\\tilde{y}}\\left( \\lVert \\tilde{y}-X\\hat{\\beta} \\rVert_2^2 \\right).\n%\\label{eq:ErrF_SE}\n\\end{equation*} \nThe training error is $\\text{errF}_\\text{SE} = \\displaystyle \\lVert y-X\\hat{\\beta} \\rVert_2^2$. \\citet{ye1998measuring} and \\citet{efron2004estimation} showed that for any general fitting procedure $\\hat\\mu$ and any model distribution (not necessarily Gaussian)\n\\begin{equation}\nE_y(\\text{optF}_\\text{SE}) = 2\\sum_{i=1}^n \\text{Cov}_y(\\hat\\mu_i,y_i),\n\\label{eq:EoptF_SE}\n\\end{equation}\nwhich is often referred to as the covariance penalty. For the OLS estimator $\\hat\\mu(k) = X\\hat\\beta(k)$ it is easy to verify that $E_y(\\text{optF}_\\text{SE}(k)) = 2 \\sigma_0^2 k$. We denote RSS$(k)$ as the residual sum of squares for the OLS estimator, i.e. $\\text{RSS}(k)=\\lVert y- X\\hat\\beta(k) \\rVert_2^2$. Hence,\n\\begin{equation*}\n\\widehat{\\text{ErrF}}_\\text{SE}(k) = \\text{RSS}(k) + 2 \\sigma_0^2 k\n\\end{equation*}\nis an unbiased estimator of $E_y(\\text{ErrF}_\\text{SE})$. As suggested by \\citet{mallows1973some}, typically $\\sigma_0^2$ is estimated using the OLS fit on all the predictors, i.e. $\\hat\\sigma_0^2=\\text{RSS}(p)/(n-p)$. We then obtain the Mallows' C$_p$ criterion \\citep{mallows1973some} \n\\begin{equation}\n\\text{C}_p(k) = \\text{RSS}(k) + \\frac{\\text{RSS}(p)}{n-p} 2k.\n\\label{eq:cp_subsetselection}\n\\end{equation}\nAn alternative is to use the OLS fit based on the $k$ predictors in the subset to estimate $\\sigma_0^2$. i.e. $\\hat\\sigma_0^2 = \\text{RSS}(k)/(n-k)$, which yields the final prediction error \\citep{akaike1969fitting,akaike1970statistical}\n\\begin{equation}\n\\text{FPE}(k) = \\text{RSS}(k)\\frac{n+k}{n-k}.\n\\label{eq:cptilde_subsetselection}\n\\end{equation}\n\n\nAnother commonly-used error measure is (twice) the Kullback-Leibler (KL) divergence \\citep[see, e.g.,][Section 3]{konishi2008information}\n\\begin{equation}\n\\text{KLF} = E_{\\tilde{y}}\\left[ 2\\log f(\\tilde{y} | X,\\beta_0,\\sigma_0^2 ) - 2\\log f(\\tilde{y} | X,\\hat\\beta,\\hat\\sigma^2 ) \\right].\n\\label{eq:KLF}\n\\end{equation}\nThe right-hand side of \\eqref{eq:KLF} evaluates the predictive accuracy of the fitted model, by measuring the closeness of the distribution of $\\tilde{y}$ based on the fitted model and the distribution of $\\tilde{y}$ based on the true model. The term $E_{\\tilde{y}}\\left[ 2\\log f(\\tilde{y} | X,\\beta_0,\\sigma_0^2 ) \\right]$ is the same for every fitted model. Therefore, an equivalent error measure is the expected likelihood\n\\begin{equation*}\n\\text{ErrF}_\\text{KL} = E_{\\tilde{y}}\\left[ -2\\log f(\\tilde{y} | X,\\hat\\beta,\\hat\\sigma^2 ) \\right].\n%\\label{eq:ErrF_KL}\n\\end{equation*}\nThe training error is \n\\begin{equation*}\n\\text{errF}_\\text{KL} = -2\\log f(y|X,\\hat\\beta,\\hat\\sigma^2).\n%\\label{eq:errF_KL}\n\\end{equation*}\nFor the OLS estimator $\\hat\\beta(k)$, \\citet{sugiura1978further} and \\citet{hurvich1989regression} showed that under the Gaussian error \\eqref{eq:truemodel}\n\\begin{equation*}\nE_y(\\text{optF}_\\text{KL}(k)) = n\\frac{n+k}{n-k-2}-n,\n%\\label{eq:EoptF_KL}\n\\end{equation*}\nand hence\n\\begin{equation*}\n\\widehat{\\text{ErrF}}_\\text{KL}(k) = n\\log\\left(\\frac{\\text{RSS}(k)}{n}\\right) + n\\frac{n+k}{n-k-2} + n\\log(2\\pi)\n\\end{equation*}\nis an unbiased estimator of $E_y(\\text{ErrF}_\\text{KL})$. Since the term $n\\log(2\\pi)$ appears in all of the models being compared, and thus is irrelevant when comparing criteria for the models, the authors dropped it and introduced the corrected AIC\n\\begin{equation}\n\\text{AICc}(k) = n \\log\\left( \\frac{\\text{RSS}(k)}{n}\\right) + n\\frac{n+k}{n-k-2}.\n\\label{eq:aicc_subsetselection}\n\\end{equation}\n\\citet{Hurvich1991} showed that AICc has superior finite-sample predictive performance compared to AIC \\citep{Akaike1973}\n\\begin{equation*}\n\\text{AIC}(k) = n \\log\\left( \\frac{\\text{RSS}(k)}{n}\\right) + n + 2(k+1),\n\\end{equation*}\nwhich does not require a Gaussian error assumption but relies on asymptotic results. The derivations of AICc and AIC require the assumption that the true model is included in the approximating models. Neither AICc nor AIC involve $\\sigma_0^2$, a clear advantage over C$_p$. Note that the second term of AICc can be rewritten as $n[1 + (2k+2)/(n-k-2)]$, which approximately equals the sum of the second and third terms of AIC when $n$ is large relative to $k$, demonstrating their asymptotic equivalence when $n\\rightarrow\\infty$ and $p$ is fixed.\n\n\\subsection{From fixed-X to random-X}\nThe assumption that $X$ is fixed holds in many applications, for example in a designed experiment where categorical predictors are represented using indicator variables or effect codings. However, in many other cases where the data are observational and the experiment is conducted in an uncontrolled manner, fixed-X is not valid and it is more appropriate to treat $(x_i,y_i)_{i=1}^n$ as $iid$ random draws from the joint distribution of $X$ and $y$. We refer to this as the random-X design. %For example, in the prostate cancer example from \\citet[p.~49]{hastie2009elements}, the response variable $y$ is the level of prostate-specific antigen, and the predictors $X$ are clinical measures such as the weight of prostate, the volume of cancer, the age of patient, and etc. The goal is to predict the level of prostate-specific antigen based on the clinical measures of a new unseen patient. This fits the random-X assumption.\n\nAs noted by \\citet{breiman1992submodel}, the choice between fixed-X and random-X is conceptual, and is normally determined based on the nature of the study. The extra source of randomness from $X$ results in larger test error compared to the fixed-X situation, and therefore the information criteria designed under fixed-X can be biased estimates of the random-X test error. Furthermore, when applied as selection rules, the authors showed in simulations that C$_p$ leads to significant overfitting under the random-X design. This motivates the derivation of information criteria for the random-X situation. \n\nFor the random-X design, we assume that the row vectors of $X$, $\\{x_i\\}_{i=1}^n$, are $iid$ multivariate normal with mean $E(x_i)=0$ and covariance matrix $E(x_i x_i^T)=\\Sigma_0$. Let $f(y_i,x_i|\\beta,\\sigma^2,\\Sigma)$ denote the joint multivariate normal density for $y_i$ and $x_i$. Let $g(x_i|\\Sigma)$ denote the multivariate normal density for $x_i$. By partitioning the joint density of $(y,X)$ into the product of the conditional and marginal densities, and by separating the parameters of interest, we have the log-likelihood function (multiplied by $-2$)\n\\begin{equation}\n\\begin{aligned}\n-2 \\log f(y, X|\\beta,\\sigma^2,\\Sigma) &= \\sum_{i=1}^n -2 \\log f(y_i, x_i|\\beta,\\sigma^2,\\Sigma) = -2 \\sum_{i=1}^n [\\log f(y_i|x_i,\\beta,\\sigma^2) + \\log g(x_i|\\Sigma)] \\\\\n&= \\left [ n \\log (2\\pi \\sigma^2) + \\frac{1}{\\sigma^2} || y-X\\beta||_2^2 \\right ] + \\left [np \\log(2\\pi) + n \\log |\\Sigma| + \\sum_{i=1}^n x_i^T \\Sigma^{-1} x_i \\right ].\n\\end{aligned}\n\\label{eq:loglike_randomx}\n\\end{equation}\nMinimizing \\eqref{eq:loglike_randomx} subject to \\eqref{eq:restriction}, we find that the MLE $(\\hat{\\beta}, \\hat{\\sigma}^2)$ of $(\\beta, \\sigma^2)$ remains the same as in the fixed-X design, i.e. \\eqref{eq:betahat_sigmahatsq}. The MLE of $\\Sigma$ is given by\n\\begin{equation*}\n\\hat \\Sigma = \\frac{1}{n} \\sum_{i=1}^n x_i \\, x_i^T = \\frac{1}{n} X^T X.\n%\\label{eq:Sigmahat}\n\\end{equation*}\n\nSince $\\hat\\beta$ is unchanged when we move from fixed-X to random-X, variable selection as an example of linear restrictions on $\\beta$ is based on the same parameter estimates as in Section \\ref{sec:intro_subsetselection}. Denote errR, ErrR and optR as the training error, test error and the optimism under random-X, respectively. We generate $X^{(n)}$ as an independent copy of $X$, where the rows $\\{x_i^{(n)}\\}_{i=1}^n$ are $iid$ multivariate normal $\\mathcal{N}(0,\\Sigma_0)$. The new copy of the response $y^{(n)}$ is generated from the conditional distribution $y|X^{(n)}$. The optimism for random-X can be defined in the same way as for fixed-X, i.e. $\\text{optR}=\\text{ErrR}-\\text{errR}$. \\citet{rosset2020fixed} discussed the optimism for general fitting procedures, when the discrepancy between the true and approximating models is measured by the squared error (SE), i.e.\n\\begin{equation*}\n\\text{ErrR}_\\text{SE} = E_{X^{(n)},y^{(n)}} \\left( \\lVert y^{(n)} - X^{(n)} \\hat\\beta \\rVert_2^2 \\right).\n%\\label{eq:ErrR_SE}\n\\end{equation*}\nThe training error is $\\text{errR}_\\text{SE} = \\lVert y - X \\hat\\beta \\rVert_2^2$. For the OLS estimator, the authors showed that \n\\begin{equation*}\nE_{X,y}(\\text{optR}_\\text{SE}(k)) = \\sigma_0^2 k \\left(2 + \\frac{k+1}{n-k-1} \\right),\n%\\label{eq:EoptR_SE}\n\\end{equation*}\nand hence\n\\begin{equation*}\n\\widehat{\\text{ErrR}}_\\text{SE}(k) = \\text{RSS}(k) + \\sigma_0^2 k \\left(2 + \\frac{k+1}{n-k-1} \\right)\n\\end{equation*}\nis an unbiased estimator of $E_{X,y}(\\text{ErrR}_\\text{SE})$. The result holds for arbitrary joint distributions of $(x_y,y_i)$ , and it only requires $x_i$ being marginally normal. As in the fixed-X case, if we use the unbiased estimate of $\\sigma_0^2$ based on the full OLS fit, we have the analog of the C$_p$ rule for random-X, \n\\begin{equation}\n\\text{RC}_p(k) = \\text{RSS}(k) + \\frac{\\text{RSS}(p)}{n-p} k\\left(2 + \\frac{k+1}{n-k-1}\\right).\n\\label{eq:rcp_subsetselection}\n\\end{equation}\nIf we use the alternative estimate of $\\sigma_0^2$ based on the OLS fit on the $k$ predictors in the subset, i.e. $\\hat\\sigma_0^2=\\text{RSS}(k)/(n-k)$, we have the analog of the FPE rule for random-X,\n\\begin{equation}\n\\text{S}_p(k) = \\text{RSS}(k)\\frac{n(n-1)}{(n-k)(n-k-1)}.\n\\label{eq:sp_subsetselection}\n\\end{equation}\n\\citet{hocking1976biometrics} refers to \\eqref{eq:sp_subsetselection} as the S$_p$ criterion of \\citet{sclove1969criteria}; see also \\citet{thompson1978a,thompson1978b}. Note that the notation used here is slightly different from that in \\citet{rosset2020fixed}, where the authors used RC$_p$ to denote the infeasible criterion involving $\\sigma_0^2$ and used $\\widehat{\\text{RC}}_p$ to denote the feasible criterion S$_p$. The RC$_p$ criterion in our notation was not studied in their paper. \n\nAnother class of selection rules is cross-validation (CV), which does not impose parametric assumptions on the model. A commonly used type of CV is the so-called K-fold CV. The data are randomly split into K equal folds. For each fold, the model is fitted using data in the remaining folds and is evaluated on the current fold. The process is repeated for all K folds, and an average squared error is obtained. In particular, the n-fold CV or leave-one-out (LOO) CV provides an approximately unbiased estimator of the test error under the random-X design, i.e. $E_{X,y}(\\text{ErrR}_\\text{SE})$. \\citet{burman1989comparative} showed that for OLS, LOOCV has the smallest bias and variance in estimating the squared error-based test error, among all K-fold CV estimators. LOOCV is generally not preferred due to its large computational cost, but for OLS, the LOOCV error estimate has an analytical expression: the predicted residual sum of squares (PRESS) statistic \\citep{allen1974relationship}\n\\begin{equation*}\n\\text{PRESS}(k) = \\sum_{i=1}^n \\left( \\frac{y_i-x_i^T\\hat\\beta(k)}{1-H_{ii}(k)} \\right)^2,\n%\\label{eq:press}\n\\end{equation*}\nwhere $H(k) = X(k)(X(k)^T X(k))^{-1}X(k)^T$ and $X(k)$ contains the first $k$ columns of $X$. \n\n\\subsection{General linear restrictions}\nVariable selection is a special case of linear restrictions on $\\beta$, where certain entries of $\\beta$ are restricted to be zero. In practice, we may restrict predictors to have the same coefficient (e.g. $\\beta_1=\\beta_2=\\beta_3$), or we may restrict the sum of their effects (e.g. $\\beta_1+\\beta_2+\\beta_3=1$). Using the structure in \\eqref{eq:restriction}, we formulate a sequence of models, each of which imposes a set of general restrictions on $\\beta$, where the goal is to select the model with best predictive performance. The previously defined information criteria and PRESS cannot be applied to this problem, although \\citet{tarpey2000note} derived the PRESS statistic for the estimator under general restrictions as\n\\begin{equation*}\n\\text{PRESS}(R,r) = \\sum_{i=1}^n \\left( \\frac{y_i-x_i^T\\hat\\beta}{1-H_{ii}+{H_Q}_{ii}} \\right)^2,\n%\\label{eq:press}\n\\end{equation*}\nwhere $H=X(X^T X)^{-1} X^T$ and $H_Q = X (X^T X)^{-1} R^T \\left[ R (X^T X)^{-1} R^T \\right]^{-1} R (X^T X)^{-1} X^T$.  \n\n\n\\subsection{The contribution of this paper}\nThe information criteria introduced in Section \\ref{sec:intro_subsetselection} have been studied primarily in the context of variable selection problems under fixed-X. In this paper we discuss how such criteria can be generalized to model comparison under general linear restrictions with either a fixed-X or a random-X (in both cases including the special case of variable selection). Note that a selection rule is preferred if it chooses the models that lead to the best predictive performance. This is related to, but not the same as, providing the best estimate of the test error. These two goals are fundamentally different \\citep[see, e.g.,][Section 7]{hastie2009elements}, and we focus on the predictive performance of the selected model.\n\nIn Section \\ref{sec:ic_fixedx}, we consider the fixed-X situation and derive general versions of AICc, C$_p$ and FPE for arbitrary linear restrictions on $\\beta$. Random-X is assumed in Section \\ref{sec:ic_randomx} and a version of RC$_p$ and S$_p$ for general linear restrictions is obtained. Furthermore, we propose and justify a novel criterion, RAICc, for general linear restrictions and discuss its connections with AICc. We further show that expressions of the information criteria for variable selection problems can be recovered as special cases of their expressions derived under general restrictions. In Section \\ref{sec:simulation}, we show via simulations that AICc and RAICc provide consistently strong predictive performance for both variable selection and general restriction problems. Lastly, in Section \\ref{sec:conclusion}, we provide conclusions and discussions of potential future work.\n\n", "meta": {"hexsha": "4112de6f36212e62f95fb33db29032f15056578c", "size": 19948, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/introduction.tex", "max_stars_repo_name": "sentian/RAICc", "max_stars_repo_head_hexsha": "0e3b620354733de1fe953a2a21559bcb20055b96", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/introduction.tex", "max_issues_repo_name": "sentian/RAICc", "max_issues_repo_head_hexsha": "0e3b620354733de1fe953a2a21559bcb20055b96", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/introduction.tex", "max_forks_repo_name": "sentian/RAICc", "max_forks_repo_head_hexsha": "0e3b620354733de1fe953a2a21559bcb20055b96", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 106.6737967914, "max_line_length": 992, "alphanum_fraction": 0.7375175456, "num_tokens": 6039, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964034, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.7469844541399929}}
{"text": "\\section{Generative models}\nIn unsupervised learning we want to find generative models which allow us to generate new data\nfrom previously made observations. We sometimes assume that observations are generated from a \nprocess which is not immediately observable from the data at hand. A general form of such a \ngenerative model can be written as:\n\\begin{align}\n\t\\mb{x} = f(\\mb{s})\n\t\\label{eq:GM}\n\\end{align}\nwhere $\\mb{x}$ is a $D \\times 1$ vector for a given observation, which is assumed to be \ngenerated by an arbitrary function $f(\\mb{s})$. $\\mb{s}$ is a $M \\times 1$ vector of\nsource signals for the given observation. If $\\mb{s}$ is known the problem of inferring\nfunction $f(\\mb{s})$ becomes a supervised learning task. However, if the sources are \nunknown the problem becomes an unsupervised learning task. UNder certain assumptions\nit possible to infer sources from observations, this is called blind source separation.\n\n\\subsection{The linear generative model (LGM)} \nIn the following we will only consider linear generative models for which equation \\eqref{eq:GM}\ntakes the form:\n\\begin{align}\n\t\\mb{x} = \\mb{A s}\n\t\\label{eq:LGM}\n\\end{align}\nwhere $\\mb{x}$ is an $D \\times 1$ observation vector, $\\mb{s}$ is the $M \\times 1$ vector\nof sources and $\\mb{A}$ is a $D \\times M$ transformation matrix. \nWe distinguish three classes of LGM dependent on the dimensionality of $\\mb{A}$:\n\n\\begin{enumerate}\n\t\\item Overcomplete LGM: \\textbf{A} is a fat matrix with $D<M$. \\\\\n\t\t  The number of source signals is assumed to be bigger than the dimensionality \n\t\t  of our observations. The generative model is overcomplete since blow up the number\n\t\t  of possible sources.\n\t\\item Undercomplete LGM: \\textbf{A} is a flat matrix with $D>M$. \\\\\n\t      The undercomplete case is the inverse case an overcomplete LGM where the observations\n\t      are assumed to be generated from less sources that the dimensionality of our observations.\n\t\\item Complete LGM: \\textbf{A} is a square matrix with $D=M$, full rank \n\t      and $\\forall m = 1,\\dots,M: \\, \\mathrm{Var}[\\mb{s_m}] > 0.$ \\\\\n\t      In the complete case the number of source signals is assumed to equal the dimensionality\n\t      of our observations. In the following we will focus on complete LGMs.    \n\\end{enumerate}\n\n% Table of UL algorithms used for different types of LGM\n\\begin{figure}[h]\n\\centering\n\\begin{tabular}{|l|l|}\n\\hline \nGenerative Model & Unsupervised Learning algorithm \\\\ \n\\hline \nComplete LGM & Principle Component Analysis (PCA), \\\\ \n             & Independent Components Analysis (ICA) \\\\ \n%\\hline \nOvercomplete LGM & Factor Analysis, Independent Factor Analysis \\\\ \n\\hline \n\\end{tabular} \n\\caption{Some examples of unsupervised leanring algorithms for the different classes of LGM. \nFor all those algorithms it is assumed that observations \\textbf{X} can be decomposed into \nsources $\\mb{S}$ and transformation matrix $\\mb{A}$.}\n\\end{figure}\n\n\\subsection{The complete LGM}\nIn this section we assume that our observations and signals have the same dimensionality,\ni.e. we are dealing with a complete LGM. We further assume that matrix $\\mb{A}$ is orthogonal\nwhich means that:\n\\begin{align}\n\t \\mb{A}\\TT \\mb{A} = \\mb{A} \\mb{A}\\TT = \\imat_D\n\\end{align}\n\\noindent\nWe will further focus on normally distributed source signals as this will be relevant for the\northogonality assumption with the application of principle component analysis. In fact orthogonality\nof $\\mb{A}$ is only guaranteed if our observations are normally distributed. We can show that given\nthe sources are normally distributed, our observations will be too:\n\n\n%% From lecture\n%\\textbf{Linear mappings of Gaussian RVs:} \\\\\n%$s \\sim \\\t{N}(\\mathbf{\\mu_s},\\mathbf{C_s})$\n%\\begin{align*}\n%\tx_k &= a_k s_1 + b_k s_2 \\\\\n%\ts_j &\\sim \\mathcal{N}(0,\\sigma_j^2); \\qquad \\rho(s_1,s_2) = \\rho(s_1)\\rho(s_2) \\\\\n%\t\\Rightarrow x_n &\\sim \\mathcal{N}(0,a_k^2 \\sigma_1^2 + b_k^2 \\sigma_2^2)\n%\\end{align*}\n\n\\begin{proposition}[Linear mappings of Gaussian random variables]\nGiven the sources are independent and normally distributed such that\n\\begin{align*}\n\t\\mb{s} \\sim \\mathcal{N}(\\greekvec{\\mu}_s,\\mb{C_s}); \\qquad\n\t\\rho(\\mb{s}) = \\prod_{m=1}^M \\rho(s_m); \\qquad\n\ts_m \\sim \\mathcal{N}(0,\\sigma_m^2) &\n\\end{align*}\nand the observations are linear mappings of the sources such that\n\\begin{align*}\n\tx_d = \\sum_{m=1}^M \\mb{A}_{dm} s_m\n\\end{align*}\nThe observations will be normally distributed according to\n\\begin{align*}\n\tx_d \\sim \\mathcal{N}(0, \\sum_{m=1}^M \\mb{A}_{dm}^2 \\sigma_m^2)\n\\end{align*}\n\\end{proposition}\n\n\\begin{proof}[Sketch of proof.]\n\t\\begin{align*}\n\t(i) &\\qquad (\\mb{A}_{dm} s_m) \\sim \\mathcal{N}(0,\\mb{A}_{dm}^2 \\sigma_m^2) \\\\\n\t(ii) &\\qquad \\text{generally for } \\\\\n\t\t &\\qquad z = u + v : \\rho(z) = \\underbrace{\\rho(u) \\Asterisk \\rho(v)}_{\\text{Convolution}}\\\\\n\t     &\\qquad \\Rightarrow \\underbrace{\\mathcal{F}[\\rho(z)]}_{\\text{Fourier transform}} \n\t       = \\underbrace{\\underbrace{\\mathcal{F}[\\rho(u)]}_{Gaussian} \\underbrace{\\mathcal{F}[\\rho(v)]}_{Gaussian} }_{Gaussian} \\\\\n\t     &\\qquad \\Rightarrow \\rho(z) = \\underbrace{\\mathcal{F}^{-1}(\\cdots)}_{Gaussian}\n\\end{align*}\n\\end{proof}\n\\noindent \nThe density of the sum of two random variables is obtained by convolving their individual densities. \nThe convolution of two Gaussians is a multiplication of two Gaussians in the Fourier space. Backtransformation again results\nin a Gaussian. Below we will see how the covariance $\\mb{C}_x$ of observations $\\mb{x}$ can be decomposed given an LGM.\n\n%Sketch of proof:\n%\\begin{align*}\n%\t(i) &\\qquad (a_k s_1) \\sim \\mathcal{N}(0,a_k^2 \\sigma_1^2) \\\\\n%\t    &\\qquad (b_k s_2) \\sim \\mathcal{N}(0,b_k^2 \\sigma_2^2)\t\\\\\n%\t(ii) &\\qquad \\text{generally for } \\\\\n%\t\t &\\qquad z = u + v : f(z) = f(u) + f(v)\\\\\n%\t     &\\qquad \\Rightarrow \\underbrace{\\mathcal{F}[f(z)]}_{\\text{Fourier transform}} \n%\t       = \\underbrace{\\underbrace{\\mathcal{F}[f(u)]}_{Gaussian} \\underbrace{\\mathcal{F}[f(v)]}_{Gaussian} }_{Gaussian} \\\\\n%\t     &\\qquad \\Rightarrow f(z) = \\underbrace{\\mathcal{F}^{-1}(\\cdots)}_{Gaussian}\n%\\end{align*}\n%Aside: The Fourier transform of a density $\\hat{=}$ the characteristic function $\\E_{\\rho(z)}[\\E^{ikz}]$\n\n\\begin{theorem}[Linear transform theorem]\nGiven $\\mb{x} = \\mb{A s}$ is a linear mapping and $\\mb{s}$ and $\\mb{x}$ are normally distributed such that\n\\begin{align*}\n\t\\mb{s} \\sim \\mathcal{N}(\\greekvec{\\mu}_s,\\mb{C}_s) \\qquad\n\t\\text{ and } \\qquad\n\t\\mb{x} \\sim \\mathcal{N}(\\greekvec{\\mu}_x,\\mb{C}_x) \\qquad\n\\end{align*}\nthen the expectation and covariance of $\\mb{x}$ are given by\n\\begin{align*}\n\t(i)& \\qquad \\greekvec{\\mu}_x = \\mb{A} \\greekvec{\\mu}_s \\\\\n\t(ii)&  \\qquad \\mathbf{C}_x = \\mathbf{A} \\mathbf{C}_s \\mathbf{A}\\TT %\n\\end{align*}\nwhere we refer to $(ii)$ as the \"Sandwich theorem\".\n\\end{theorem}\n\n\\begin{proof}[Derivation]\n\\qquad \\\\\n\\begin{minipage}{0.45\\textwidth}\n\\begin{align*}\n\t\\greekvec{\\mu}_x &= \\Ex{\\rho(\\mb{x})}{\\mb{x}} \\\\\n\t                 &= \\Ex{\\rho(\\mb{x})}{\\mb{A s}} \\\\\n\t                 &= \\mb{A} \\Ex{\\rho(\\mb{s})}{\\mb{s}} \\\\\n\t                 &= \\mathbf{A} \\greekvec{\\mu}_s \\\\\n\\end{align*}\n\\end{minipage}\n\\begin{minipage}{0.45\\textwidth}\n\\begin{align*}\n\t\\mb{C}_x &= \\Ex{}{\\mb{x x}\\TT} - \\Ex{}{\\mb{x}} \\Ex{}{\\mb{x}}\\TT \\\\\n\t\t     &= \\Ex{}{\\mathbf{A s s }\\TT \\mb{A}\\TT} \n\t\t\t\t    - \\Ex{}{\\mb{A s}} \\Ex{}{\\mb{s}\\TT \\mathbf{A}\\TT} \\\\\n\t\t\t\t &= \\mb{A} \\Ex{}{\\mathbf{s s}\\TT} \\mb{A}\\TT \n\t\t\t\t    - \\mb{A} \\Ex{}{\\mathbf{s}} \\Ex{}{\\mb{s}}\\TT \\mb{A}\\TT \\\\\n\t\t\t\t &= \\mathbf{A} \\left(\\Ex{}{\\mathbf{s s}\\TT} - \\Ex{}{\\mathbf{s}} \\Ex{}{\\mb{s}}\\TT \\right) \\mathbf{A}\\TT \\\\\n\t\t\t\t &= \\mathbf{A} \\mathbf{C}_s \\mathbf{A}\\TT \\\\\n\\end{align*}\n\\end{minipage}\n\\newline\n\\end{proof}\n\n%\\begin{align*}\n%\t\\mathbf{u} &= \\mathbf{W v} \\\\\n%\t\\rho(\\mathbf{v}) &= \\mathcal{N}(\\mathbf{v}|\\greekvec{\\mu_v},\\mathbf{C_v})\\\\\n%\t\\rho(\\mathbf{u}) &= \\mathcal{N}(\\mathbf{u}|\\greekvec{\\mu_u},\\mathbf{C_u})\\\\\n%\t\\greekvec{\\mu_u} &= \\Ex{\\rho(\\mathbf{u})}{\\mathbf{u}}\n%\t                  = \\Ex{\\rho(\\mathbf{u})}{\\mathbf{W v}}\n%\t                  = \\mathbf{W} \\E_{f(\\mathbf{u})}[\\mathbf{v}] = \\mathbf{W} \\greekvec{\\mu_v} \\\\\n%\t\\mathbf{C_u} &= \\E[\\mathbf{u u}\\TT] - \\E[\\mathbf{u}] \\E[\\mathbf{u}]\\TT \\\\\n%\t\t\t\t &= \\E[\\mathbf{W v v}\\TT \\mathbf{W}\\TT] \n%\t\t\t\t    - \\E[\\mathbf{W v}] \\E[\\mathbf{v}\\TT\\mathbf{W}\\TT] \\\\\n%\t\t\t\t &= \\mathbf{W} \\E[\\mathbf{v v}\\TT] \\mathbf{W}\\TT \n%\t\t\t\t    - \\mathbf{W} \\E[\\mathbf{v}] \\E[\\mathbf{v}]\\TT \\mathbf{W}\\TT \\\\\n%\\end{align*}\n\n%\\begin{proposition}[Rules for expectations of linear mappings]\n%\t\\begin{align*}\n%\t\t(i)& \\qquad \\Ex{}{\\mathbf{W v}} = \\mathbf{W} \\Ex{}{\\mathbf{v}} \\\\\n%\t\t(ii)&  \\qquad \\Ex{}{\\mathbf{A X B}} = \\mathbf{A} \\Ex{}{\\mathbf{X}} \\mathbf{B} %\n%\t\\end{align*}\t\t\n%\\end{proposition}\n%\n%\\begin{theorem}[Linear transform theorem]\n%\t\\begin{align*}\n%\t\t\\mathbf{u}  = \\mathbf{W v}\n%\t\\end{align*}\n%\n%\t\\begin{align*}\n%\t\t(i)& \\qquad \\greekvec{\\mu_u} = \\mathbf{W} \\greekvec{\\mu_v} \\\\\n%\t\t(ii)&  \\qquad \\mathbf{C_u} = \\mathbf{W} \\mathbf{C_v} \\mathbf{W}\\TT %\n%\t\\end{align*}\t\t\n%\tWe call this the \"Sandwich theorem\"\n%\\end{theorem}\n\n\\noindent We can now apply the sandwich theorem to calculate the covariance of a normally distributed random\nvariable with independent normally distributed sources as sketched above.\n\\begin{proposition}[Covariance matrix for observations from independent normally distributed sources]\nGiven\n\t\\begin{align*}\n\t\t\\mb{s} \\sim \\mathcal{N}(\\greekvec{\\mu}_s,\\mb{C_s}); \\qquad\n\t\t\\rho(\\mb{s}) = \\prod_{m=1}^M \\rho(s_m); \\qquad\n\t\t\\mb{C}_s = \\mathrm{diag}(\\sigma_1^2, \\dots ,\\sigma_M^2) &\n\t\\end{align*}\nthen\n\t\\begin{align}\n\t\t\\begin{split}\n\t\t\\mathbf{C}_x &= \\mb{A} \\mb{C}_s \\mb{A}\\TT \\\\\n\t\t             &= \\sum_{m=1}^M \\sigma_m^2 \\underbrace{\\mathbf{a_m a_m\\TT}}_{\\text{rank-1-matrix outer product}}\n\t\t             \\label{eq:Cx}\n\t\t\\end{split}\n\t\\end{align}\nwhere $\\mathbf{a_m}$ is a $D \\times 1$ basis vector of matrix $\\mb{A}$.\n\\end{proposition}\n\n\\noindent For visualization of the source covariance before transformation and the covariance of the observations\nafter applying $\\mb{A}$ to the sources we introduce another transformation which yields a one-dimensional \nmarginal distribution.\n\n\\begin{proposition}[Variance contour lines]\nTake an arbitrary $D \\times 1$ vector $\\mb{w}$ with $\\|\\mathbf{w}\\| = 1$ such that\n\t\\begin{align}\n\t\t&u = \\mathbf{w\\TT x}\n\t\\end{align}\n\\noindent yields a one-dimensional marginal distribution. For a covariance of $\\mb{x}$ as shown in equation\n\\eqref{eq:Cx} the variance of $u$ is given by\n\\begin{align}\n\\begin{split}\n\t\\mathrm{Var}[u] &= \\mathbf{w C_x w} \\\\\n\t                          &= \\mathbf{w}\\TT \\left(\\sum_{m=1}^M \\sigma_m^2 \\mathbf{a_m a_m\\TT}\\right) \\mathbf{w} \\\\\n\t                          &= \\sum_{m=1}^M \\sigma_m^2 (\\mathbf{w\\TT a_m}) (\\mathbf{a_m\\TT w}) \\\\\n\t                          &= \\sum_{m=1}^M \\sigma_m^2 (\\mathbf{w\\TT a_m})^2 \\label{eq:Cu}\n\\end{split}\n\\end{align}\nWe notice that the marginalization introduces a projection of the basis vectors of $\\mb{A}$ onto the axis that is\nspanned by $\\mb{w}$ where the variance $\\mathrm{Var}[u]$ is the variance along $\\mb{w}$. We can now calculate \nthe variance along any direction in the sample space and visualize it using variance contour lines.\n\\end{proposition}\n\n\\subsubsection{Example for three LGM with different source distributions}\nTo inspect the influence of the linear transformation on the covariance of the sources we utilize the above \nmarginalization to calculate variance contour lines. We will distinguish three cases of source distributions,\ntwo of which are Gaussians and one is a uniform distribution. For visualization purposes we will focus on 2-dimensional\nexamples although the approach can be applied to cases with higher dimensions.\n\n\\paragraph{Special case: Isovariance with $\\sigma_1^2 = \\dots = \\sigma_M^2 = \\sigma^2$}\n\\label{par:cov_isovar}\n\\qquad \\newline\nGiven\n\t\\begin{align*}\n\t\t\\mb{s} \\sim \\mathcal{N}(\\greekvec{\\mu}_s,\\mb{C_s}); \\qquad\n\t\t\\mathbf{C_s} &= \\sigma^2 \\imat_M &\n\t\\end{align*}\n\t\n\\begin{minipage}{0.45\\textwidth}\n\\begin{align*}\n\t\\mathbf{C_x} &= \\mathbf{A C_s A\\TT} \\\\\n\t             &= \\sigma^2 \\mathbf{A} \\imat_M \\mathbf{A}\\TT \\\\\n\t             &= \\sigma^2 \\underbrace{\\mathbf{A}\\mathbf{A}\\TT}_{\\mathbf{A}\\text{ is orthogonal}} \\\\\n\t             &= \\sigma^2 \\imat_M = \\mathbf{C_s} \\\\\n\\end{align*}\n\\end{minipage}\n\\begin{minipage}{0.45\\textwidth}\n\\begin{align*}\n\t\\mathrm{Var}[\\mb{w\\TT x}] &= \\mathbf{w\\TT C_x w} \\\\\n\t\t\t\t    &= \\mathbf{w\\TT C_s w} \\\\\n\t                &= \\sigma^2 \\mathbf{w}\\TT \\imat_M \\mathbf{w} \\\\\n\t                &= \\sigma^2 \\mathbf{w}\\TT \\mathbf{w} \\\\\n\t                &= \\sigma^2 \\|\\mathbf{w}\\|^2 = \\sigma^2 \\\\\n\\end{align*}\n\\end{minipage}\n\\newline\nWe see that given the source distribution has isovariance and the transformation matrix $\\mb{A}$ is orthogonal\nthe corvariance of observations will have the same covariance as the source distribution. In turn the variance\nof the introduced marginalization will be constant for any $\\mb{w}$ with $\\|\\mathbf{w}\\|^2 = 1$. \n\\figref{fig:LGM_isovar} illustrates the variance contour lines for the three cases.\nWith the next two cases we will focus on visual inspection of the contour lines without making any further\nderivations.\n\n\\begin{figure}\n\t\\includegraphics[width=\\textwidth]{./lecture10/lineartransform_geometricmeaning.pdf}\n\t\\caption{Variance contour lines before and after applying $\\mb{A}$.}\n\t\\label{fig:LGM_isovar}\n\\end{figure}\n\n\\paragraph{Non-degenerate case: $\\sigma_1^2 > \\sigma_1^2 > \\dots > \\sigma_M^2$}\nGiven the source distribution is a Gaussian with independent sources and unequal source variances.\nWe see that applying matrix $\\mb{A}$ can introduce a rotation of the variance contour line and in turn\nintroduces correlation for the dimensions of $\\mb{x}$. That is, although the source were perfectly \nindependent the matrix $\\mb{A}$ introduces correlations. It becomes apparent that if we find a matrix\n$\\mb{A}^{-1}$ which can be applied to the data, we can remove those correlations.\n\n\\paragraph{Non-Gaussian case: $\\sigma_1^2 > \\sigma_1^2 > \\dots > \\sigma_M^2$}\nIn this case we assume a uniform source distribution with unequal source variances. Although the\ndensity contour line differs from the variance contour line under the Gaussian assumption we see\nthat applying $\\mb{A}$ introduces the same correlations in the observations as in the Gaussian\ncase.\n\n\\subsection{Blind source separation}\nIf we make observations which are correlated and we assume that the sources are uncorrelated we\ncan find a tranform $\\mb{A}\\TT$ which removes correlations and recovers the uncorrelated signals.\nWe call this approach whitening. But how can we uniquely identify $\\mb{A}$?\n\n\\begin{proposition}[Sufficient condition]\n\tIf we assume that $\\sigma_1^2 > \\sigma_2^2 > \\dots > \\sigma_k^2$ and if we assume an orthogonal LGM\n\tthen we can uniquely identify $\\mathbf{A}$ and the solution is given by the Eigenvectors of the convariance\n\tmatrix $\\mathbf{C_x}$ of the data. This is what we call principle component analysis.\n\\end{proposition}", "meta": {"hexsha": "1cf4ee91108ffb19ab0e52dc538e62c333293952", "size": 14877, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "script/lecture10/lecture10.tex", "max_stars_repo_name": "mackelab/machine-learning-I", "max_stars_repo_head_hexsha": "fedd9ea0b9b257af5cd59036a3b49876aed5c77c", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2015-07-31T15:08:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T17:07:23.000Z", "max_issues_repo_path": "script/lecture10/lecture10.tex", "max_issues_repo_name": "cne-tum/msne_statsandprob_ss2018", "max_issues_repo_head_hexsha": "fedd9ea0b9b257af5cd59036a3b49876aed5c77c", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "script/lecture10/lecture10.tex", "max_forks_repo_name": "cne-tum/msne_statsandprob_ss2018", "max_forks_repo_head_hexsha": "fedd9ea0b9b257af5cd59036a3b49876aed5c77c", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2018-03-16T07:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-01T14:02:27.000Z", "avg_line_length": 47.8360128617, "max_line_length": 127, "alphanum_fraction": 0.6769509982, "num_tokens": 4840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778825, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.746887527182727}}
{"text": "\\section{Cayley-Hamilton Theorem and Multiplicity of Eigenvalues}\r\n\\begin{theorem}[Cayley-Hamilton Theorem]\r\n    Let $V$ be a finite dimensional vector space over $F$ and $\\alpha\\in L(V)$ with characteristic polynomial $\\chi_\\alpha(t)=\\det(\\alpha-t\\operatorname{id})$, then $\\chi_\\alpha(\\alpha)=0$.\r\n\\end{theorem}\r\nConsequently, $m_\\alpha|\\chi_\\alpha$.\r\n\\begin{proof}[Proof for $F=\\mathbb C$]\r\n    We know that $\\alpha$ is triangulable, so there is a basis $B$ such that it has matrix\r\n    $$[\\alpha]_B=\\begin{pmatrix}\r\n        a_1&&\\ast\\\\\r\n        &\\ddots&\\\\\r\n        0&&a_n\r\n    \\end{pmatrix}$$\r\n    Therefore $\\chi_\\alpha(t)=(t-a_1)\\cdots (t-a_n)$ (up to sign).\r\n    But then easily $\\chi_\\alpha(\\alpha)=\\chi_\\alpha([\\alpha]_B)=0$.\r\n\\end{proof}\r\n\\begin{proof}[Proof for the General Case]\r\n    For $A\\in M_n(F)$, we write\r\n    $$(-1)^n\\chi_A(t)=\\det(t\\operatorname{id}-A)=t^n+a_{n-1}t^{n-1}\\cdots+a_0$$\r\n    for some $a_i\\in F$.\r\n    Now if $\\operatorname{adj}(t\\operatorname{id}-A)=B_{n-1}t^{n-1}+\\cdots B_0$ for matrices $B_i$, then\r\n    $$(t\\operatorname{id}-A)(B_{n-1}t^{n-1}+\\cdots B_0)=(t^n+a_{n-1}t^{n-1}\\cdots+a_0)\\operatorname{id}$$\r\n    Equating the coefficients gives\r\n    $$\\operatorname{id}=B_{n-1},a_{n-1}\\operatorname{id}=B_{n-2}-AB_{n-1},\\ldots,a_0\\operatorname{id}=-AB_n$$\r\n    Therefore\r\n    \\begin{align*}\r\n        (-1)^n\\chi_A(A)&=A^n+a_{n-1}A^{n-1}\\cdots+a_0\\operatorname{id}\\\\\r\n        &=A^nB_{n-1}+A^{n-1}(B_{n-2}-AB_{n-1})+\\cdots+A^0(-AB_0)\\\\\r\n        &=0\r\n    \\end{align*}\r\n    by telescoping.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $\\alpha\\in L(V)$ and $\\lambda$ an eigenvalue of $\\alpha$, then the algebraic multiplicity $a_\\lambda$ of $\\lambda$ is the multiplicity of $\\lambda$ as a root of $\\chi_\\alpha(t)$.\\\\\r\n    The geometric multiplicity $g_\\lambda$ of $\\lambda$ is $\\dim\\ker(\\alpha-\\lambda\\operatorname{id})$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    Obviously $a_\\lambda,g_\\lambda\\ge 1$.\r\n\\end{remark}\r\n\\begin{lemma}\\label{alg_geom_mult_ineq}\r\n    $g_\\lambda\\le a_\\lambda$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Let $\\{v_1,\\ldots,v_{g_\\lambda}\\}$ be a basis of $V_\\lambda=\\ker(\\alpha-\\lambda\\operatorname{id})$ and extend it to a basis $B=\\{v_i\\}$ of $V$.\r\n    Then\r\n    $$[\\alpha]_B=\\begin{pmatrix}\r\n        \\lambda\\operatorname{id}_{g_\\lambda}&\\ast\\\\\r\n        0& A_1\r\n    \\end{pmatrix}$$\r\n    for some $A_1$.\r\n    Then\r\n    $$\\det(\\alpha-\\lambda\\operatorname{id})=\\det\\begin{pmatrix}\r\n        (\\lambda-t)\\operatorname{id}_{g_\\lambda}&\\ast\\\\\r\n        0&A_1-t\\operatorname{id}\r\n    \\end{pmatrix}=(\\lambda-t)^{g_\\lambda}\\chi_{A_1}(t)$$\r\n    which implies the claim.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Let $\\lambda$ be an eigenvalue of $\\alpha$ and write $c_\\lambda$ as the multiplicity of $\\lambda$ as a root of the minimal polynomial $m_\\alpha$.\r\n    Then $1\\le c_\\lambda\\le a_\\lambda$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    $c_\\lambda\\le a_\\lambda$ is obvious as $m_\\alpha|\\chi_\\alpha$.\r\n    To see $c_\\lambda\\ge 1$, as $\\lambda$ is an eigenvalue, we can find $v\\neq 0$ such that $\\alpha(v)=\\lambda v$, so $\\alpha^p(v)=\\lambda^pv$.\r\n    Hence $0=m_\\alpha(\\alpha)v=(m_\\alpha(\\lambda))v$ which means $m_\\alpha(\\lambda)=0$, hence $c_\\lambda\\ge 1$.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. Consider\r\n    $$A=\\begin{pmatrix}\r\n        1&0&-2\\\\\r\n        0&1&1\\\\\r\n        0&0&2\r\n    \\end{pmatrix}$$\r\n    then $\\chi_A(t)=(t-1)^2(t-2)$.\r\n    So $m_A(t)$ is either $(t-1)^2(t-2)$ or $(t-1)(t-2)$ by the preceding lemma.\r\n    Indeed the latter works and has a smaller degree, hence $m_A(t)=(t-1)(t-2)$.\\\\\r\n    2. Let $A$ be the Jordan block\r\n    $$A=\\begin{pmatrix}\r\n        \\lambda&1&&\\\\\r\n        &\\ddots&\\ddots&\\\\\r\n        &&\\lambda&1\\\\\r\n        &&&\\lambda\r\n    \\end{pmatrix}$$\r\n    Then as one can check, $g_\\lambda=1,a_\\lambda=c_\\lambda=n$.\\\\\r\n    3. Tak $A=\\lambda\\operatorname{id}$, then $g_\\lambda=a_\\lambda=n$ and $c_\\lambda=1$.\r\n\\end{example}\r\n\\begin{lemma}\r\n    Take $F=\\mathbb C$, $V$ a finite dimensional vector space over $F$ and $\\alpha\\in L(V)$, then the followings are equivalent:\\\\\r\n    (i) $\\alpha$ is diagonalisable.\\\\\r\n    (ii) For any eigenvalue $\\lambda$ of $\\alpha$ we have $a_\\lambda=g_\\lambda$.\\\\\r\n    (iii) For any eigenvalue $\\lambda$ of $\\alpha$ we have $c_\\lambda=1$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    We already know that (i) is equivalent to (iii) by Theorem \\ref{distinct_linear_diag}.\r\n    To see (i) is equivalent to (ii), let $\\lambda_1,\\ldots,\\lambda_k$ be distinct eigenvalues of $\\alpha$.\r\n    We have already seen that $\\alpha$ is diagonalisable iff $V=\\bigoplus_iV_{\\lambda_i}$.\r\n    But $\\dim V=n=\\deg\\chi_\\alpha=\\sum_ia_{\\lambda_i}$ by FTA and $\\dim\\bigoplus_iV_{\\lambda_i}=\\sum_ig_\\lambda$.\r\n    So $\\alpha$ is diagonalisable iff $\\sum_ig_{\\lambda_i}=\\sum_ia_{\\lambda_i}$ iff $a_{\\lambda_i}=g_{\\lambda_i}$ for all $i$ by Lemma \\ref{alg_geom_mult_ineq}.\r\n\\end{proof}", "meta": {"hexsha": "60460d02e46dd43bff52f49331499a28c4756628", "size": 4819, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "16/cayley.tex", "max_stars_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_stars_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "16/cayley.tex", "max_issues_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_issues_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "16/cayley.tex", "max_forks_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_forks_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.1734693878, "max_line_length": 190, "alphanum_fraction": 0.6202531646, "num_tokens": 1724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.8807970779778824, "lm_q1q2_score": 0.7468875170304777}}
{"text": "\\section{Conclusion}\n\nIn this assignment we implemented and trained a Rosenblatt perceptron on a randomly generated datasets.\nIn our experiments, we estimated the probability of success of the perceptron to find a linear separation in a set of random datapoints.\nFor a limited number of training iterations $n_{max}$ and features $N$, we obtained that the capacity of the Rosenblatt perceptron is about $\\alpha = 1.75$.\n\nThe difference from the theoretical results seems to be mainly caused by the limited number of training iterations:\nby allowing longer trainings, i.e. greater number of epochs, the plot of the success rate $Q_{l.s.}$ as a function of $alpha$ moves to the right and the capacity tends to the theoretical result $\\alpha = 2$.\n\nThe parameter $N$ influences the shape of the function:\nfor small values of $N$, the function is smooth in the regions before and after the step;\nfor higher values of $N$, the function gets closer to the theoretical step function.\n\nThe parameter $c$ in the training algorithm does not influence the performances of the perceptron:\nindeed, it only changes the magnitude of the weights $w$ learned during the training.\nHowever, since each training step in the algorithm can change the weights by at most $\\frac{1}{N}\\xi^{\\mu(t)} S^{\\mu(t)}$ (where $\\mu(t)$ denotes the current training example), the algorithm will take a longer time to converge for higher values of $c$.\n\nRosenblatt perceptrons only learns separation hyperplanes that goes through the origin.\nIn general, it may happen that the hyperplane that linearly separates the dataset does not pass through the origin.\nIt is possible to generalize the Rosenblatt perceptron to learn also inhomogeneous separation hyperplanes by adding an artificial dimension to the dataset and forcing it to a non-zero constant.\nThe success rate $Q_{l.s.}$ of inhomogeneous perceptrons seems to be slightly higher than homogeneous ones, even for random datasets distributed around the origin of the axes.\n", "meta": {"hexsha": "3602bb101488e42de46fb0d76f33a709f426c794", "size": 1991, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_1/report/05_conclusion.tex", "max_stars_repo_name": "davidepedranz/neural_networks_assignments", "max_stars_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_1/report/05_conclusion.tex", "max_issues_repo_name": "davidepedranz/neural_networks_assignments", "max_issues_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_1/report/05_conclusion.tex", "max_forks_repo_name": "davidepedranz/neural_networks_assignments", "max_forks_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 90.5, "max_line_length": 252, "alphanum_fraction": 0.7915620291, "num_tokens": 431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7468875148773417}}
{"text": "\\documentclass[inequalities.tex]{subfile}\n\n\\begin{document}\n\t\\section{Complex Numbers}\n\tWe may occasionally need complex numbers. So we provide a brief introduction here. A complex number $z$ is defined as\n\t\t\\begin{align*}\n\t\t\tz\n\t\t\t\t& = x+iy\n\t\t\\end{align*}\n\twhere $x,y$ are real numbers and $i$ is the imaginary unit such that $i^{2}=-1$. We call $x$ the real component and $y$ the complex component of $z$. Complex numbers follow the same properties as vectors which we established in \\autoref{sec:cs}. That is for two complex numbers $z_{1}=x_{1}+iy_{1}$ and $z_{2}=x_{2}+iy_{2}$,\n\t\t\\begin{align*}\n\t\t\tz_{1}\\pm z_{2}\n\t\t\t\t& = (x_{1}\\pm x_{2})+i(y_{1}\\pm y_{2})\\\\\n\t\t\t\\langle z_{1},z_{2}\\rangle\n\t\t\t\t& = x_{1}x_{2}+y_{1}y_{2}\n\t\t\\end{align*}\n\tHere $\\langle z_{1},z_{2}\\rangle$ is the dot product of $z_{1}$ and $z_{2}$. We define an additional operation $\\cdot$ as\n\t\t\\begin{align*}\n\t\t\tz_{1}\\cdot z_{2}\n\t\t\t\t& = x_{1}y_{2}-x_{2}y_{1}\n\t\t\\end{align*}\n\tThe \\textit{modulus} of $z$ is similar to $L_{2}$ norm.\n\t\t\\begin{align*}\n\t\t\t|z|\n\t\t\t\t& = \\sqrt{x^{2}+y^{2}}\n\t\t\\end{align*}\n\tWe have the following property.\n\t\t\\begin{align*}\n\t\t\t|z_{1}z_{2}|\n\t\t\t\t& = |z_{1}|\\cdot|z_{2}|\n\t\t\\end{align*}\n\tFor a complex number $z=x+iy$, the \\textit{conjugate} of $z$ is defined as\n\t\t\\begin{align*}\n\t\t\t\\bar{z}\n\t\t\t\t& = x-iy\n\t\t\\end{align*}\n\tSo, we have $z\\bar{z}=|z|^{2}=|\\bar{z}|^{2}$. The \\textit{argument} of $z$ is defined as\n\t\t\\begin{align*}\n\t\t\t\\arg(z)\n\t\t\t\t& = \\tan\\left(\\dfrac{y}{x}\\right)\n\t\t\\end{align*}\n\tYou can think of it as the angle the point $(x,y)$ creates with the positive $X$ axis and the origin.\n\t\t\\begin{problem}\n\t\t\tProve the triangle inequality for complex numbers.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t|z_{1}+z_{2}|\n\t\t\t\t\t\t& \\leq |z_{1}|+|z_{2}|\n\t\t\t\t\\end{align*}\n\t\t\tThis inequality can be generalized as the following.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t|z_{1}+\\ldots+z_{n}|\n\t\t\t\t\t\t& \\leq |z_{1}|+\\ldots+|z_{n}|\n\t\t\t\t\\end{align*}\n\t\t\tWhen does equality occur?\n\t\t\\end{problem}\n\\end{document}", "meta": {"hexsha": "392d9abee9fc4909c680479af932be310a323056", "size": 1949, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "complex.tex", "max_stars_repo_name": "ineq-tech/inequality", "max_stars_repo_head_hexsha": "ebf89351c843b6a7516e10e2ebf0d64e3f1f3f83", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-06T08:29:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-06T08:29:30.000Z", "max_issues_repo_path": "complex.tex", "max_issues_repo_name": "ineq-tech/inequality", "max_issues_repo_head_hexsha": "ebf89351c843b6a7516e10e2ebf0d64e3f1f3f83", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "complex.tex", "max_forks_repo_name": "ineq-tech/inequality", "max_forks_repo_head_hexsha": "ebf89351c843b6a7516e10e2ebf0d64e3f1f3f83", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.8035714286, "max_line_length": 325, "alphanum_fraction": 0.6136480246, "num_tokens": 775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995028, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7468715803404005}}
{"text": "\\subsubsection{Real Distinct Eigenvalues}\r\n\\noindent\r\nReal, distinct eigenvalues are the simplest case, similar to real, distinct roots of an auxiliary equation.\r\n\\begin{theorem}\r\n\tLet $\\left\\{\\lambda_1, \\ldots, \\lambda_n\\right\\}$ be the set of unique eigenvalues and $\\left\\{\\vec{v_1}, \\ldots, \\vec{v_n}\\right\\}$ be the corresponding set of non-zero, unique, eigenvectors for an $n \\times n$ matrix $A$. Then the set of fundamental solutions to the system $\\vec{x}' = A\\vec{x}$ is $\\left\\{e^{\\lambda_1 t}\\vec{v_1}, \\ldots, e^{\\lambda_n t}\\vec{v_n} \\right\\}$\r\n\\end{theorem}\r\n\r\n\\ifodd\\includeLinearSystemsExamples\\input{./linearSystems/homogeneousSystems/realDistinctEigenvalues_example.tex}\\fi", "meta": {"hexsha": "501224ea3992069cece2decfd2e7e3dd52624a78", "size": 693, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/homogeneousSystems/realDistinctEigenvalues.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/linearSystems/homogeneousSystems/realDistinctEigenvalues.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/linearSystems/homogeneousSystems/realDistinctEigenvalues.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 86.625, "max_line_length": 379, "alphanum_fraction": 0.7431457431, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.896251378675949, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7468683211429077}}
{"text": "\\subsection{Absolute Extrema}\\label{subsec:AbsoluteExtremaSubsection}\n\nAbsolute extrema are also commonly referred to as\n\\dfont{global extrema}. Unlike local extrema, which are\nonly ``extreme\" relative to points ``close to'' them, an\nabsolute (or global) extrema is ``extreme\" relative to \\emph{all}\nother points in the interval under consideration.\n\n\\begin{definition}{Absolute Maxima and Minima}{AbsMaxMinDef}\n\tA real-valued function $f$ has an \\deffont{absolute maximum}\n\ton an interval $I$ at $x_0$ if $f(x_0)$ is the largest value\n\tof $f$ on $I$; in other words, $f(x_0)\\geq f(x)$ for all $x$\n\tin the domain of $f$ that are in $I$.\n\t\n\t\\medskip\n\tA real-valued function $f$ has an \\deffont{absolute minimum}\n\ton an interval $I$ at $x_0$ if $f(x_0)$ is the smallest value\n\tof $f$ on $I$; in other words, $f(x_0)\\leq f(x)$ for all $x$\n\tin the domain of $f$ that are in $I$.\n\\end{definition}\n\n\\begin{example}{Absolute Extrema}{AbsoluteExtremaExamples}\n\tConsider the function $f(x)=x^2$ on the interval $(-\\infty,\\infty)$.\n\tThis parabola has an absolute minimum at $x=0$.\n\tHowever, it does not have an absolute maximum.\n\t\n\t\\medskip\n\tConsider the function $f(x)=|x|$ on the interval $[-1,2]$.\n\tThis graph looks like a check mark. It has an absolute minimum\n\tat $x=0$ and an absolute maximum at $x=2$.\n\t\n\t\\medskip\n\tConsider the function $f(x)=\\cos x$ on the interval $[0,\\pi]$.\n\tIt has an absolute minimum at $x=\\pi$ and an absolute maximum at $x=0$.\n\t\n\t\\medskip\n\tConsider the function $f(x)=e^x$ on any interval $[a,b]$,\n\twhere $a<b$. Since this exponential function is increasing,\n\tit has an absolute minimum at $x=a$ and an absolute maximum at $x=b$.\n\\end{example}\n\nLike Fermat's Theorem, the following theorem has an intuitive appeal.\nHowever, unlike Fermat's Theorem, the proof relies on a more advanced\nconcept called \\textbf{compactness}, which will only be covered in a course\ntypically entitled Analysis. So, we will be content with understanding the\nstatement of the theorem.\n\n\\begin{theorem}{Extreme-Value Theorem}{ExtremeValueTheorem}\n\tIf a function $f$ is continuous on a closed interval $[a,b]$,\n\tthen $f$ has both an absolute maximum and an absolute minimum on $[a,b]$.\n\\end{theorem}\n\nAlthough this theorem tells us that an absolute extremum exists, it\ndoes not tell us what it is or how to find it.\n\nNote that if an absolute extremum is inside the interval (i.e. not\nan endpoint), then it must also be a local extremum. This immediately\ntells us that to find the absolute extrema of a function on an interval,\nwe need only examine the local extrema inside the interval, and the\nendpoints of the interval.\n\nWe can devise a method for finding absolute extrema for a function $f$ on a closed interval $[a,b]$:\n\n\\begin{enumerate}\n\t\\item Verify the function is continuous on $[a,b]$.\n\t\\item Find the derivative and determine all critical values of $f$ that are in $[a,b]$.\n\t\\item Evaluate the function at the critical values found in Step 2 and the end points of the interval.\n\t\\item Identify the absolute extrema.\n\\end{enumerate}\n\nWhy must a function be continuous on a closed interval in order to\nuse this theorem? Consider the following example.\n\n\\begin{example}{Absolute Extrema of a $1/x$}{AbsExtReciprocal}\n\tFind any absolute extrema for $f(x)=1/x$ on the interval $[-1,1]$.\n\\end{example}\n\\begin{solution}\n\tThe function $f$ is not continuous at $x=0$. Since $0\\in [-1,1]$,\n\t$f$ is not continous on the closed interval:\n\t\\begin{align*}\n\t\t\\lim_{x\\to 0^+}f(x)&=+\\infty\t\\\\\n\t\t\\lim_{x\\to 0^-}f(x)&=-\\infty\\, ,\n\t\\end{align*}\n\tso we are \\emph{unable} to apply the Extreme-Value Theorem. Therefore,\n\t$f(x)=1/x$ does not have an absolute maximum or an absolute minimum on $[-1,1]$.\n\\end{solution}\n\nHowever, if we consider the same function on an interval where it is\ncontinuous, the theorem will apply. This is illustrated in the following example.\n\n\\begin{example}{Absolute Extrema of a $1/x$}{AbsExtReciprocal}\n\tFind any absolute extrema for $f(x)=1/x$ on the interval $[1,2]$.\n\\end{example}\n\\begin{solution}\n\tThe function $f$ is continous on the interval, so we can apply the\n\tExtreme-Value Theorem. We begin with taking the derivative to be\n\t$f'(x)=-1/x^2$ which has a critical value at $x=0$, but since this\n\tcritical value is not in $[1,2]$ we ignore it. The only points where\n\tan extrema can occur are the endpoints of the interval. To find the\n\tmaximum or minimum we can simply evaluate the function: $f(1)=1$ and\n\t$f(2)=1/2$, so the absolute maximum is at $x=1$ and the absolute minimum is at $x=2$.\n\\end{solution}\n\nWhy must an interval be closed in order to use the above theorem? Recall\nthe difference between open and\nclosed intervals. Consider a function $f$ on the open interval $(0,1)$.\nIf we choose successive values of $x$ moving closer and closer to $1$,\nwhat happens? Since 1 is not included in the interval we will not attain\nexactly the value of 1. Suppose we reach a value of 0.9999 --- is it\npossible to get closer to 1? Yes: There are infinitely many real numbers\nbetween 0.9999 and 1. In fact, any conceivable real number close to 1\nwill have infinitely many real numbers between itself and 1. Now, suppose\n$f$ is decreasing on $(0,1)$: As we approach 1, $f$ will continue to\ndecrease, even if the difference between successive values of $f$ is\nslight. Similarly if $f$ is increasing on $(0,1)$.\n\nConsider a few more examples:\n\n\\begin{example}{Determining Absolute Extrema}{AbsExtOne}\n\tDetermine the absolute extrema of $f(x)=x^3-x^2+1$ on the interval $[-1,2]$.\n\\end{example}\n\\begin{solution}\n\tFirst, notice $f$ is continuous on the closed interval $[-1,2]$, so\n\twe're able to use Theorem~\\ref{thm:ExtremeValueTheorem} to determine\n\tthe absolute extrema. The derivative is $f'(x)=3x^2-2x$, and the critical\n\tvalues are $x=0,2/3$ which are both in the interval $[-1,2]$. In order\n\tto find the absolute extrema, we must consider all critical values that\n\tlie within the interval (that is, in $(-1,2)$) \\emph{and} the endpoints of the interval.\n\t\\begin{align*}\n\t\tf(-1)&=(-1)^3-(-1)^2+1=-1\t\\\\\n\t\tf(0)&=(0)^3-(0)^2+1=1\t\\\\\n\t\tf(2/3)&=(2/3)^3-(2/3)^2+1=23/27\t\\\\\n\t\tf(2)&=(2)^3-(2)^2+1=5\n\t\\end{align*}\n\t\n\tThe absolute maximum is at (2,5) and the absolute minimum is at (-1,-1).\n\\end{solution}\n\n\\begin{example}{Determining Absolute Extrema}{AbsExtOne}\n\tDetermine the absolute extrema of $f(x)=-9/x-x+10$ on the interval $[2,6]$.\n\\end{example}\n\\begin{solution}\n\tFirst, notice $f$ is continuous on the closed interval $[2,6]$,\n\tso we're able to use Theorem~\\ref{thm:ExtremeValueTheorem} to \n\tdetermine the absolute extrema. The function is not continuous\n\tat $x=0$, but we can ignore this fact since 0 is not in $[2,6]$.\n\tThe derivative is $f'(x)=9/x^2-1$, and the critical values are\n\t$x=\\pm 3$, but only $x=+3$ is in the interval. In order to find\n\tthe absolute extrema, we must consider all critical values that\n\tlie within the interval \\emph{and} the endpoints of the interval.\n\t\\begin{align*}\n\t\tf(2)&=-9/(2)-(2)+10=7/2=3.5\t\\\\\n\t\tf(3)&=-9/(3)-(3)+10=4\t\\\\\n\t\tf(6)&=-9/(6)-(6)+10=5/2=2.5\n\t\\end{align*}\n\t\n\tThe absolute maximum is at (3,4) and the absolute minimum is at (6,2.5).\n\\end{solution}\n\nWhen we are trying to find the absolute extrema of a function on an\nopen interval, we cannot use the Extreme Value Theorem. However, if\nthe function is continuous on the interval, many of the same ideas apply.\nIn particular, if an absolute extremum exists, it must also be a local extremum.\nIn addition to checking values at the local extrema, we must check the behaviour\nof the function as it approaches the ends of the interval.\n\nSome examples to illustrate this method.\n\n\\begin{example}{Extrema of Secant}{SecantExtrema}\n\tFind the extrema of $\\sec(x)$ on $(-\\pi/2,\\pi/2)$.\n\\end{example}\n\\begin{solution}\n\tNotice $\\sec(x)$ is continuous on $(-\\pi/2,\\pi/2)$ and has one local minimum at 0. Also\n\t\\[\\lim_{x\\to(-\\pi/2)^+}\\sec(x)=\\lim_{x\\to(\\pi/2)^-}\\sec(x)=+\\infty\\, ,\\]\n\tso $\\sec(x)$ has no absolute maximum, but the point $(0,1)$ is the absolute minimum.\n\\end{solution}\n\nA similar approach can be used for infinite intervals.\n\n\\begin{example}{Extrema of $\\frac{x^2}{x^2+1}$}{ExtofRationalFraction}\n\tFind the extrema of $\\ds\\frac{x^2}{x^2+1}$ on $(-\\infty,\\infty)$.\n\\end{example}\n\\begin{solution}\n\tSince $x^2+1\\neq 0$ for all $x$ in $(-\\infty,\\infty)$ the function is continuous on this interval. This function has only one critical value at $x=0$, which is the local minimum and also the absolute minimum. Now, $\\lim_{x\\to\\pm\\infty}\\frac{x^2}{x^2+1}=1$, so the function does not have an absolute maximum: It continues to increase towards 1, but does not attain this exact value. \n\\end{solution}\n\n\n\\Opensolutionfile{solutions}[ex]\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section*{Exercises for \\ref{subsec:AbsoluteExtremaSubsection}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\n\tFind the absolute extrema for $f(x)=-\\frac{x+4}{x-4}$ on $[0,3]$.\n\t\\begin{sol}\n\t\tAbsolute maximum $(3,7)$; Absolute minimum $(0,1)$. \n\t\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n\tFind the absolute extrema for $f(x)=-\\frac{x+4}{x-4}$ on $[0,3]$.\n\t\\begin{sol}\n\t\tAbsolute maximum $(3,7)$; Absolute minimum $(0,1)$. \n\t\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n\tFind the absolute extrema for $f(x)=\\csc(x)$ on $[0,\\pi]$.\n\t\\begin{sol}\n\t\tAbsolute minimum $(\\pi/2,1)$; No absolute maximum.\n\t\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n\tFind the absolute extrema for $f(x)=\\ln(x)/x^2$ on $[1,4]$.\n\t\\begin{sol}\n\t\tAbsolute minimum $(1,0)$; Absolute maximum $(e^{1/2},\\frac{1}{2e})$.\n\t\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n\tFind the absolute extrema for $f(x)=x\\sqrt{1-x^2}$ on $[-1,1]$.\n\t\\begin{sol}\n\t\tAbsolute minimum $(1,0)$; Absolute maximum $(e^{1/2},\\frac{1}{2e})$.\n\t\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n\tFind the absolute extrema for $f(x)=xe^{-x^2/32}$ on $[0,2]$.\n\t\\begin{sol}\n\t\tAbsolute minimum $(0,0)$; Absolute maximum $(2,2e^{1/8})$.\n\t\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n\tFind the absolute extrema for $f(x)=x-\\tan^{-1}(2x)$ on $[0,2]$.\n\t\\begin{sol}\n\t\tAbsolute minimum $(1/2,\\frac{2-\\pi}{4})$; Absolute maximum $(2,2-\\tan^{-1}(4))$.\n\t\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n\tFind the absolute extrema for $f(x)=\\frac{x}{x^2+1}$.\n\t\\begin{sol}\n\t\tAbsolute maximum $(1,1/2)$; Absolute minimum $(-1,-1/2)$. \n\t\\end{sol}\n\\end{ex}\n\nFor the following exercises, sketch a potential graph of a continuous function on the closed interval $[0,4]$ with the given properties.\n\n\\begin{multicols}{2}\n\t\\begin{ex}\n\t\tAbsolute minimum at 0, absolute maximum at 2, local minimum at 3.\n\t\\end{ex}\n\t\n\t\\begin{ex}\n\t\tAbsolute maximum at 1, absolute minimum at 2, local maximum at 3.\n\t\\end{ex}\n\t\n\t\\begin{ex}\n\t\tAbsolute minimum at 4, absolute maximum at 1, local minimum at 2, local maxima at 1 and 3.\n\t\\end{ex}\n\\end{multicols}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "c3cf611b356990d198201ec5befd9e6d63e8d08f", "size": 10656, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-2-2-absolute-extrema.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5-applications-of-derivatives/5-2-2-absolute-extrema.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5-applications-of-derivatives/5-2-2-absolute-extrema.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.0601503759, "max_line_length": 383, "alphanum_fraction": 0.7011073574, "num_tokens": 3422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324938410783, "lm_q2_score": 0.9161096181702032, "lm_q1q2_score": 0.7468423286526928}}
{"text": "\\chapter{Continuous Time Markov Chain}\n\\emph{“为了把连续的情况说清楚它还要发明一堆黑话。”}\n\\newpage\n\n\n\\section{Definition of Continuous Time Markov Chains}\n    \\subsection{Continuous Time Markov Chain}\n        In the case of continuous time, it is technically difficult to specify the ``conditional probability given all of $X_r$ for all $r<s$''. Therefore instead, the Continuous Time Markov Chain is defined by\n\n        \\begin{definition}[Continuous Time Markov Chain]\\label{def:ContinuousTimeMarkovChain}\n            A stochastic process $X(t)$ is a \\textbf{Continuous Time Markov Chain} if $\\forall s,t \\ge 0$, $\\forall 0 \\le s_0 < \\cdots < s_n < s$\n            \\[ \\mathbb{P}[X_{s+t} = j | X_s = i, X_{s_n} = i_n,\\dots,X_{s_0}=i_0] = \\mathbb{P}[X_t=j | X_0 = i] \\]\n        \\end{definition}\n\n        Given the current state, the previous states in the past is irrelevant for predicting the future, so we can simply ``throw away'' the previous states before $s$.\n\n    \\subsection{Transition Probability}\n        In continuous case, the matrix-multiplication version of multistep transition probability cannot be applied directly. Instead we define a transition probability for each $t>0$.\n        \\[ p_t(i,j) = \\mathbb{P}[X_t=j|X(0)=i] \\]\n\n        Recall the Chapman-Kolmogorov Equality \\ref{thm:ChapmanKolmogorovEquality}, it still holds in the continuous case.\n\n        \\begin{theorem}[Chapman-Kolmogorov Equality, Continuous Case]\\label{thm:ContinuousChapmanKolmogorovEquality}\n            \\[ \\sum_{k}p_s(i,k)p_t(k,j) = p_{s+t}(i,j) \\]\n        \\end{theorem}\n        \\begin{remark}\n            This sugguests that if we know the transition probability for all $t<t_0$ (for some $t_0>0$), then we will be able to know the transition probability for all $t' \\in \\mathbb{R}$, by using the equality for sufficiently many times and keep doing the summation until $s+t=t'$.\n        \\end{remark}\n\n        This further suggests that $p_t$ can be determined by its derivative at $t=0$.\n        \\begin{definition}[Jump Rate]\\label{def:JumpRate}\n            If the limit exists (assume it always does),\n            \\[ q(i,j) = \\lim_{h \\to 0}\\frac{p_h(i,j)}{h} \\quad \\text{for $j \\neq i$} \\]\n            then $q(i,j)$ is defined as the \\textbf{jump rate} from $i$ to $j$.\n        \\end{definition}\n\n    \\subsection{A VERY Important Example}\\label{sub:CTMCCoreExample}\n        Let\\footnote{“因为这个例子太重要了所以我给它起了个名字叫Example Star”--Chihao}\n        \\begin{itemize}\n            \\item $Y_n$ is a Markov Chain with transition matrix $u(i,j)$.\n            \\item $N(t)$ be a Poison Process with rate $\\lambda$.\n            \\item $X(t)$ be a random variable defined as $X(t)=Y_{N(t)}$\n        \\end{itemize}\n        That is, the discrete Markov chain $Y_n$ takes a jump according to the transition probability at each new arrival of the Poisson process $N(t)$.\n\n        \\subsubsection{Jump Rate of VERY Important Example.}\n        By enumerating over all number of arrivals $n$\n        \\[ p_h(i,j) = \\sum_{n=0}^\\infty e^{-\\lambda h}\\frac{(\\lambda h)^n}{n!} \\cdot u^n(i,j) \\]\n\n        Notice that the probability of at least 2 jumps before time $h$ is 1 minus the probability of 0 and 1 jump,\n        \\[ 1 - (e^{-\\lambda h}+\\lambda h e^{-\\lambda h}) \\approx (\\lambda h)^2/2! = o(h) \\]\n        So it converges to 0 when divided by $h$ and as $h \\to 0$.\n        Therefore\n        \\[ \\frac{p_h(i,j)}{h} \\approx \\lambda e^{-\\lambda h}u(i,j) \\to \\lambda u(i,j) \\]\n\n\n\\section{More Examples}\n    \\subsection{The Poisson Process}\n        Let $X(t)$ be the number of arrivals up to time $t$ in $Poisson(\\lambda)$.\n\n        Notice that at each new arrival, $X$ goes from $i$ to $i+1$ (with probability 1).\n        \n        Therefore $\\forall n$\n        \\[ q(n, n+1) = \\lambda \\]\n\n    \\subsection{M/M/s Queue}\n        We now consider a queue. Customers arrive according to a Poisson process of rate $\\lambda$; the time to serve a customer is modeled by another Poisson process of rate $\\mu$; there are only $s$ counters.\n\n        Since the customers come in rate $\\lambda$, we have\n        \\[ q(n, n+1) = \\lambda \\]\n\n        Since the customers leave in rate $\\mu$, we can use an exponential race in \\ref{subs:ExponentialRace} to model the process, and therefore\n        \\[ q(n, n-1) = \\begin{cases}\n            \\mu n & \\quad n < s\\\\\n            \\mu s & \\quad n \\ge s\n        \\end{cases} \\]\n\n\n\\section{Constructing a CT Markov Chain}\n    \\subsection{Informal Construction}\n        Given a jump rate $q(i,j)$, the construction of a CTMC contains two steps, according to the formulation of \\ref{sub:CTMCCoreExample}: 1) Choose $s\\sim Exp(\\lambda)$ to determine the next jump time, and 2) Choose $X(t+s) \\sim u(i,\\cdot)$ to determine the next state. Following this intuition, we define\n        \\[ \\lambda_i = \\sum_{j \\neq i}q(i,j) \\]\n        $\\lambda_i$ is the rate that the chain leaves $i$.\n        \\begin{itemize}\n            \\item If $\\lambda_i = \\infty$, then the chain leaves $i$ immediately.\n            \\item If $\\lambda_i = 0$, then the chain will never leave $i$.\n        \\end{itemize}\n        Since if the next state is chosen to be $i$, it is equivalent to state not moved, so we may choose different $\\lambda_i$ so that in each jump we move into a different state. If we want identical $\\Lambda$, we may choose $\\Lambda = \\sup \\lambda_i$ and let $u(i,i)>0$.\n        \n        If $\\lambda_i > 0$, let\n        \\[ u(i,j) = \\frac{q(i,j)}{\\lambda_i} \\]\n        be the probability that the chain goes to $j$ when it leaves $i$.\n\n        \\begin{itemize}\n            \\item If $X_t$ is in a state $i$ with $\\lambda_i=0$, then the chain never leaves and we are done.\n            \\item If $X_t$ is in a state $i$ with $\\lambda_i > 0$, then we first let the chain stay at $i$ according to an Exponential distribution with rate $\\lambda_i$, then choose a destination according to $u(i,j)$.\n        \\end{itemize}\n\n\n\\section{Computing the Transition Probability}\n    Given the jump rate $q(i,j)$, in the previous section we constructed a CTMC. In this section we move on to compute the transition probability.\n    \\begin{align*}\n        p_{t+h}(i,j) - p_t(i,j) &= \\sum_k p_h(i,k)p_t(k,j) - p_t(i,j) \\quad \\text{(CK Equation \\ref{thm:ContinuousChapmanKolmogorovEquality})}\\\\\n        &= \\sum_{k \\neq i} p_h(i,k)p_t(k,j) + (p_h(i,i)-1)p_t(i,j)\\\\\n        &\\triangleq A + B\n    \\end{align*}\n\n    Multiply by $1/h$ and take limitation, then Expression A becomes\n    \\begin{align*}\n        \\lim_{h \\to 0} \\frac{1}{h}A &= \\sum_{k \\neq i}\\lim_{h \\to 0}\\frac{1}{h}p_h(i,k)p_t(k,j)\\\\\n        &= \\sum_{k \\neq i}q(i,k)p_t(k,j)\n    \\end{align*}\n\n    and Expression B becomes\n    \\begin{align*}\n        \\lim_{h \\to 0} \\frac{1}{h}B &= \\lim_{h \\to 0}\\frac{\\sum_{k \\neq i}p_h(i,k)}{h}p_t(i,j)\\\\\n        &= \\left(\\sum_{k \\neq i}q(i,k)\\right)p_t(i,j)\\\\\n        &= -\\lambda_i p_t(i,j)\n    \\end{align*}\n\n    And therefore\n    \\begin{equation}\\label{eq:TransitionProbabilityKeyEq}\n         \\lim_{h \\to 0}\\frac{1}{h}\\left(p_{t+h}(i,j) - p_t(i,j)\\right) = \\sum_{k \\neq i}q_(i,k)p_t(k,j) - \\lambda_i p_t(i,j) \n    \\end{equation}\n\n    Notice that the LHS of equation (\\ref{eq:TransitionProbabilityKeyEq}) is the derivative of $p_t(i,j)$, and therefore\n    \\[ p'_t(i,j) = \\sum_{k \\neq i}q_(i,k)p_t(k,j) - \\lambda_i p_t(i,j) \\]\n\n    Further notice that  hte first term $\\sum_{k \\neq i}q_(i,k)p_t(k,j)$ in RHS of (\\ref{eq:TransitionProbabilityKeyEq}) can be re-written in a matrix multiplication. Let\n    \\[ Q(i,j) = \\begin{cases}\n        q(i,j) &\\quad i \\neq j\\\\\n        -\\lambda_i &\\quad i = j\n    \\end{cases} \\]\n\n    And therefore\n    \\begin{equation}\\label{eq:KolmogorovBackwardEquation}\n        P'_t = QP_t\n    \\end{equation}\n    This equation is also known as the \\textbf{Kolmogorov Backward Equation}.\n\n    This looks similar to a differential equation and the solution is\n    \\[ P_t = e^{Qt} = \\sum_{n=0}^{\\infty}\\frac{(tQ)^n}{n!} \\]\n    where $e^{Qt}$ is defined as\n    \\[ e^Q = \\sum_{n=0}^{\\infty} \\frac{Q^n}{n!} \\]\n\n    Furthermore, if we write $\\sum_{k}p_t(i,k)p_h(k,j)$ instead of $\\sum_{k}p_h(i,k)p_t(k,j)$ in the first step of derivation, we will end up with the \\textbf{Kolmogorov Forward Equation}.\n    \\begin{equation}\\label{eq:KolmogorovForwardEquation}\n        P'_t = P_tQ\n    \\end{equation}\n\n    \\subsection{Example: Poisson Process Revisited}\n        In the previous sections, we know that given the jump rate $q(i,j)$, we are able to compute the transition probability and simulate the continuous time Markov chain.\n\n        Let $X(t)$ be the number of arrivals of a Poisson process up to time $t$. $p_t(i,j)$ is the probability that the number rises from $i$ to $j$ in time interval $t$. By definition of the Poisson process, the arrival between $0$ and $t$ has a Poisson distribution of rate $\\lambda t$, and $p_t(i,j)$ is simply the probability that the number of arrivals between $0$ and $t$ is $j-i$.\n        \\[ p_t(i,j) = e^{-\\lambda t}\\frac{(\\lambda t)^{j-i}}{(j-i)!} \\]\n\n        We can use the result to verify the forward and backward equation \\ref{eq:KolmogorovForwardEquation} and \\ref{eq:KolmogorovBackwardEquation}.\n\n    \\subsection{Example: Two State Markov Chain}\n        Suppose there are only two states $\\Omega = \\{1,2\\}$. The two-state continuous-time Markov chain can be specified by\n        \\[ q(1,2) = \\lambda \\quad q(2,1) = \\mu \\]\n        and\n        \\[ Q = \\begin{bmatrix}\n            -\\lambda & \\lambda\\\\\n            \\mu & -\\mu\n        \\end{bmatrix} \\]\n\n        By Kolmogorov backward equation \\ref{eq:KolmogorovBackwardEquation},\n        \\[\n        \\begin{bmatrix}\n            p'_t(1,1) & p'_t(1,2)\\\\\n            p'_t(2,1) & p'_t(2,2)\n        \\end{bmatrix} = \n        \\begin{bmatrix}\n            -\\lambda & \\lambda\\\\\n            \\mu & -\\mu\n        \\end{bmatrix}\n        \\begin{bmatrix}\n            p_t(1,1) & p_t(1,2)\\\\\n            p_t(2,1) & p_t(2,2)\n        \\end{bmatrix}\n        \\]\n\n        Since there are only two states, it suffices to compute $p_t(1,1)$ and $p_t(2,1)$ only.\n        \\[ p'_t(1,1) = -\\lambda p_t(1,1) + \\lambda p_t(2,1) \\]\n        \\[ p'_t(2,1) = \\mu p_t(1,1) - \\mu p_t(2,1) \\]\n\n        Therefore\n        \\[ \\left(p_t(1,1)-p_t(2,1)\\right)' = -(\\lambda + \\mu)\\left(p_t(1,1)-p_t(2,1)\\right) \\]\n\n        Solving the differential equation gives us\n        \\[ p_t(1,1) - p_t(2,1) = e^{-(\\lambda + \\mu)t} \\]\n\n        Plug the result back into the expression for $p'_t(1,1)$,\n        \\[ p'_t(1,1) = -\\lambda e^{-(\\lambda + \\mu)t} \\]\n\n        Integrate over $t$\n        \\[ p_t(1,1) = p_o(1,1) - \\lambda\\int_0^t e^{-(\\lambda + \\mu)s}\\mathrm{d}s = \\frac{\\mu}{\\mu + \\lambda}+\\frac{\\lambda}{\\mu + \\lambda} e^{-(\\lambda + \\mu)t} \\]\n\n\n\\section{Limiting Behaviour: Continuous Time}\n    \\subsection{Irreducibility, Continuous Case}\n        The intuition remains the same: the chain can jump from any state $i$ to any state $j$ in finite steps.\n        \\begin{definition}[Continuous Time Irreducibility]\n            A continuous-time Markov chain is \\textbf{irreducible} if there exists a sequence $k_0 = i, k_1, \\dots, k_n=j$ such that\n            \\[ q(k_{m-1},k_m) > 0 \\quad \\forall 1 \\le m \\le n \\]\n        \\end{definition}\n\n        \\begin{lemma}\\label{lem:NecessaryConditionOfIrreducibility}\n            If $X(t)$ is irreducible and $t>0$, then\n            \\[ p_t(i,j) > 0 \\quad \\forall i,j \\]\n        \\end{lemma}\n\n    \\subsection{Stationary Distribution}\n        \\begin{lemma}[Stationary Distribution, Continuous Case]\\label{lem:ContinuousTimeStationaryDistribution}\n            A distribution $\\pi$ is a stationary distribution if and only if\n            \\[ \\pi^T Q = 0 \\]\n            or equivalently, iff\n            \\[ \\pi^T P_t = \\pi^T \\quad \\forall t \\]\n            but this one is difficult to verify.\n        \\end{lemma}\n        \\begin{remark}\n            Using the definition of $Q$ we can prove that\n            \\[ \\sum_{i \\neq j}\\pi(i)q(i,j) = \\lambda_j\\pi(j) \\]\n            The LHS is the rate that the chain ``gets into'' state $j$, and the RHS is the rate that the chain ``gets out of'' state $j$. So the intuition of continuous-time stationary distribution is that the rate that a chain goes in and goes out of a state are equal.\n        \\end{remark}\n\n    \\subsection{Convergence}\n        \\begin{theorem}[Convergence of CT Markov Chain]\\label{thm:ConvergenceOfCTMarkovChain}\n            If a continuous time Markov chain is irreducible and has a stationary distribution $\\pi$, then\n            \\[ \\lim_{t\\to\\infty}p_t(i,j) = \\pi(j) \\]\n        \\end{theorem}\n        \\begin{remark}\n            Notice that we are not considering ``aperiodicity'' in CTMC, because a CTMC always has self-loops.\n        \\end{remark}\n\n    \\subsection{Detailed Balance Condition, Continuous Case}\n        \\begin{theorem}[Detailed Balance Condition]\\label{thm:DetailedBalanceConditionOfCTMarkovChain}\n            If\n            \\[ \\forall i \\neq j \\quad \\pi(i)q(i,j) = \\pi(j)q(j,i) \\]\n            then $\\pi$ is a stationary distribution.\n        \\end{theorem}\n", "meta": {"hexsha": "38bf4676d0efad8501778a980e0e284f8d406d4b", "size": 12916, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Stochastic Processes/ContinousTimeMarkovChain.tex", "max_stars_repo_name": "YBRua/CourseNotes", "max_stars_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-20T10:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T08:15:15.000Z", "max_issues_repo_path": "Stochastic Processes/ContinousTimeMarkovChain.tex", "max_issues_repo_name": "YBRua/CourseNotes", "max_issues_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Stochastic Processes/ContinousTimeMarkovChain.tex", "max_forks_repo_name": "YBRua/CourseNotes", "max_forks_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T11:31:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T11:31:00.000Z", "avg_line_length": 53.1522633745, "max_line_length": 388, "alphanum_fraction": 0.6169866832, "num_tokens": 4067, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807408, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7467705825201288}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\nLet $B = \\set{\\begin{mymatrix}{r}\n2 \\\\\n-1\n\\end{mymatrix}, \\begin{mymatrix}{r}\n3 \\\\\n2\n\\end{mymatrix} }$ be a basis of $\\R^2$ and let $\\vect{x} = \\begin{mymatrix}{r}\n5 \\\\\n-7\n\\end{mymatrix}$ be a vector in $\\R^2$. Find $C_B(\\vect{x})$.\n\\end{ex}\n\n\\begin{ex}\nLet $B = \\set{\\begin{mymatrix}{r}\n1 \\\\\n-1 \\\\\n2\n\\end{mymatrix}, \\begin{mymatrix}{r}\n2 \\\\\n1 \\\\\n2\n \\end{mymatrix}, \\begin{mymatrix}{r}\n-1 \\\\\n0 \\\\\n2\n\\end{mymatrix} }$\nbe a basis of $\\R^3$ and let $\\vect{x} = \\begin{mymatrix}{r}\n5 \\\\\n-1 \\\\\n4\n\\end{mymatrix}$ be a vector in $\\R^2$. Find $C_B(\\vect{x})$.\n\\begin{sol}\n $C_B(\\vect{x}) =\n\\begin{mymatrix}{r}\n2 \\\\\n1 \\\\\n-1\n \\end{mymatrix}$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $T: \\R^2 \\to \\R^2$ be a linear transformation defined by $T \\paren{\\begin{mymatrix}{r}\na \\\\\nb\n\\end{mymatrix}} = \\begin{mymatrix}{r}\na+b \\\\\na-b\n\\end{mymatrix}$.\n\nConsider the two bases\n\\[\nB_1 = \\set{\\vect{v}_{1}, \\vect{v}_{2} } = \\set{\\begin{mymatrix}{r}\n1 \\\\\n0\n\\end{mymatrix}, \\begin{mymatrix}{r}\n-1 \\\\\n1\n\\end{mymatrix}\n}\n\\]\n and\n\\[\nB_2 = \\set{\\begin{mymatrix}{r}\n1 \\\\\n1\n\\end{mymatrix}, \\begin{mymatrix}{r}\n1 \\\\\n-1\n\\end{mymatrix}\n}\n\\]\n\nFind the matrix $M_{B_2,B_1}$ of $T$ with respect to the bases $B_1$ and $B_2$.\n\\begin{sol}\n$\nM_{B_{2} B_{1}} = \\begin{mymatrix}{rr}\n\\vspace{0.05in}1 & 0 \\\\\n\\vspace{0.05in}-1 & 1\n\\end{mymatrix} $\n\\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "0a57522ff1294ca4e6a4030c629a84dafde11ed4", "size": 1353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/exercises/LinearTransformations-MatrixTwo.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/exercises/LinearTransformations-MatrixTwo.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/exercises/LinearTransformations-MatrixTwo.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 15.5517241379, "max_line_length": 90, "alphanum_fraction": 0.5883222469, "num_tokens": 615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463333, "lm_q2_score": 0.8705972751232809, "lm_q1q2_score": 0.7467705622302777}}
{"text": "\\section{Application: Cramer's rule}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Use Cramer's rule to solve a system of equations with\n    invertible coefficient matrix.\n  \\end{enumerate}\n\\end{outcome}\n\nAnother application of determinants is \\textbf{Cramer's rule} for\nsolving a system of equations. Recall that we can represent a system\nof linear equations in the form $A\\vect{x}=\\vect{b}$, where $\\vect{x}$\nis a vector of variables. Cramer's rule gives a formula for the\nsolutions $\\vect{x}$ in the special case that the coefficient matrix\n$A$ is a square invertible matrix. Note that Cramer's rule does not\napply if you have a system of equations in which there is a different\nnumber of equations than variables (in other words, when $A$ is not\nsquare), or when $A$ is not invertible.\n\n\\begin{theorem}{Cramer's rule}{cramers-rule}\n  Suppose $A$ is an invertible $n\\times n$-matrix and we wish to solve\n  the system $A\\vect{x}=\\vect{b}$, where\n  $\\vect{x}=\\mat{x_1,\\ldots,x_n}$.  Then $x_i$ can be computed by the\n  rule%\n  \\index{Cramer's rule}%\n  \\index{system of linear equations!Cramer's rule}%\n  \\index{determinant!Cramer's rule}\n  \\begin{equation*}\n    x_i = \\frac{\\det(A_i)}{\\det(A)},\n  \\end{equation*}\n  where $A_i$ is the matrix obtained by replacing the $i\\th$ column\n  of $A$ with $\\vect{b}$.\n\\end{theorem}\n\n\\begin{proof}\n  Since $A$ is invertible, the solution to the system\n  $A\\vect{x}=\\vect{b}$ is given by $\\vect{x}=A^{-1}\\vect{b}$.\n  By Theorem~\\ref{thm:inverse-and-determinant}, we have\n  \\begin{equation*}\n    A^{-1} ~=~ \\frac{1}{\\det(A)} \\adj(A),\n  \\end{equation*}\n  and therefore\n  \\begin{equation*}\n    \\vect{x}=\\frac{1}{\\det(A)}\\adj(A)\\vect{b}.\n  \\end{equation*}\n  Let $x_i$ be the $i\\th$ component of $\\vect{x}$ and $b_j$ be the $j\\th$\n  component of $\\vect{b}$. Recall that the $\\ijth$ entry of $\\adj(A)$ is\n  $\\cofactor{A}{ji}$, the $ji\\th$ cofactor of $A$. By definition of matrix\n  multiplication, we have\n  \\begin{equation*}\n    x_i = \\frac{1}{\\det(A)}(\\cofactor{A}{1i}\\,b_1+\\ldots+\\cofactor{A}{ni}\\,b_n).\n  \\end{equation*}\n  By the formula for the expansion of a determinant along a column,\n  this is equal to\n  \\begin{equation*}\n    x_i=\\frac{1}{\\det(A)}\\begin{absmatrix}{ccccc}\n      \\ast & \\cdots & b_1 & \\cdots & \\ast \\\\\n      \\vdots &  & \\vdots &  & \\vdots \\\\\n      \\ast & \\cdots & b_n & \\cdots & \\ast\n    \\end{absmatrix},\n  \\end{equation*}\n  where the $i\\th$ column of $A$ is replaced with the column vector\n  $\\vect{b}$. But this last formula is exactly Cramer's rule.\n\\end{proof}\n\n\\begin{example}{Using Cramer's rule}{cramers-rule}\n  Use Cramer's rule to solve the system of equations\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 1 \\\\\n      3 & 2 & 1 \\\\\n      1 & 4 & 1 \\\\\n    \\end{mymatrix} \\begin{mymatrix}{c}\n      x \\\\\n      y \\\\\n      z \\\\\n    \\end{mymatrix} =\\begin{mymatrix}{r}\n      3 \\\\\n      5 \\\\\n      6 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The matrices $A_1$, $A_2$, and $A_3$ are obtained by respectively\n  replacing the first, second, and third column of $A$ by $\\vect{b}$.\n  We compute\n  \\begin{equation*}\n    \\det(A) = \\begin{absmatrix}{rrr}\n      1 & 2 & 1 \\\\\n      3 & 2 & 1 \\\\\n      1 & 4 & 1 \\\\\n    \\end{absmatrix}\n    = 4,\n    \\qquad\n    \\det(A_1) = \\begin{absmatrix}{rrr}\n      3 & 2 & 1 \\\\\n      5 & 2 & 1 \\\\\n      6 & 4 & 1 \\\\\n    \\end{absmatrix}\n    = 4\n  \\end{equation*}\n  \\begin{equation*}\n    \\det(A_2) = \\begin{absmatrix}{rrr}\n      1 & 3 & 1 \\\\\n      3 & 5 & 1 \\\\\n      1 & 6 & 1 \\\\\n    \\end{absmatrix}\n    = 6,\n    \\qquad\n    \\det(A_3) = \\begin{absmatrix}{rrr}\n      1 & 2 & 3 \\\\\n      3 & 2 & 5 \\\\\n      1 & 4 & 6 \\\\\n    \\end{absmatrix}\n    = -4.\n  \\end{equation*}\n  Then by Cramer's rule,\n  \\begin{equation*}\n    x = \\frac{\\det(A_1)}{\\det(A)} = \\frac{4}{4} = 1,\\quad\n    y = \\frac{\\det(A_2)}{\\det(A)} = \\frac{6}{4} = \\frac{3}{2},\\quad\\mbox{and}\\quad\n    z = \\frac{\\det(A_3)}{\\det(A)} = \\frac{-4}{4} = -1.\\quad\n  \\end{equation*}\n  Thus, the solution is $(x,y,z)=(1,\\frac{3}{2},-1)$.\n\\end{solution}\n\nCramer's rule is sometimes useful in situations where row operations\nwould be difficult to do. One such situation is when a system of\nequations involves functions rather than numbers, as in the following\nexample.\n\n\\begin{example}{Using Cramer's rule for non-constant matrix}{cramers-rule-non-constant-matrix}\n  Solve the following system of equations for $z$.\n  \\begin{equation*}\n    \\begin{mymatrix}{ccc}\n      1 & 0 & 0 \\\\\n      0 & e^{t}\\cos t & e^{t}\\sin t \\\\\n      0 & -e^{t}\\sin t & e^{t}\\cos t\n    \\end{mymatrix}\n    \\begin{mymatrix}{c}\n      x \\\\\n      y \\\\\n      z\n    \\end{mymatrix}\n    = \\begin{mymatrix}{c}\n      1 \\\\\n      t \\\\\n      t^2\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We are asked to find the value of $z$ in the solution. By Cramer's\n  rule, we have\n  \\begin{equation*}\n    z ~=~ \\frac{\n      \\begin{absmatrix}{ccc}\n        1 & 0 & 1 \\\\\n        0 & e^{t}\\cos t & t \\\\\n        0 & -e^{t}\\sin t & t^2\n      \\end{absmatrix}\n    }{\n      \\begin{absmatrix}{ccc}\n        1 & 0 & 0 \\\\\n        0 & e^{t}\\cos t & e^{t}\\sin t \\\\\n        0 & -e^{t}\\sin t & e^{t}\\cos t\n      \\end{absmatrix}\n    }\n    ~=~ \\frac{e^t(t^2\\cos t - t\\sin t)}{e^{2t}}\n    ~=~ e^{-t}(t^2\\cos t - t\\sin t).\n  \\end{equation*}\n\\end{solution}\n", "meta": {"hexsha": "1d2b68cd31a91b448b175ee45b68f75dc110ccb7", "size": 5285, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Determinants-Application-Cramer.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Determinants-Application-Cramer.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Determinants-Application-Cramer.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 30.2, "max_line_length": 94, "alphanum_fraction": 0.5884578997, "num_tokens": 1939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.7465995054327057}}
{"text": "\\section{Definitions and Basic Properties}\r\nWe will make the following standing assumptions:\r\nFirst, the state space $I$ is a countable set which we will almost always label as $\\{1,2,\\ldots\\}$.\r\nAlso, we will be working in a probability space $(\\Omega,\\mathscr F,\\mathbb P)$ where all relevant random variables are defined.\r\n\\begin{definition}\r\n    A sequence of random variables $(X_n)_{n=0,1,\\ldots}$ is a Markov chain if, for all $n\\ge 0$ and $i_0,\\ldots,i_{n+1}\\in I$,\r\n    $$\\mathbb P[X_{n+1}=i_{n+1}|X_0=i_0,\\ldots,X_n=i_n]=\\mathbb P[X_{n+1}=i_{n+1}|X_n=i_n]$$\r\n    given that these conditional probabilities are well-defined.\\\\\r\n    A Markov chain is homogeneous if for all $i,j\\in I$,\r\n    $$\\mathbb P[X_{n+1}=j|X_n=i]=\\mathbb P[X_1=j|X_0=i]$$\r\n\\end{definition}\r\nWe are only interested in homogeneous Markov chains, so afterwards when we mention a Markov chain, we always mean a homogeneous one.\\\\\r\nThen, a Markov chain is characterised by the initial distribution $\\lambda=(\\lambda_i)_{i\\in I}$ given by $\\lambda_i=\\mathbb P[X_0=i]$ and the transition matrix $P=(p_{ij})_{i,j\\in I}$ with $p_{ij}=\\mathbb P[X_1=j|X_0=i]$.\\\\\r\nNote that $\\lambda$ is a distribution as $\\lambda_i$ is always nonnegative and sums up to $1$.\r\n$P$, at the same time, is a stochastic matrix, i.e. $p_{ij}$ is a distribution for every $i\\in I$.\r\n\\begin{definition}\r\n    $(X_n)$ is a Markov chain with initial distribution $\\lambda$ and transition matrix $P$, or $(X_n)\\sim\\operatorname{Markov}(\\lambda,P)$ if the above properties hold.\r\n\\end{definition}\r\n\\begin{theorem}\\label{markov_alt_defn}\r\n    $(X_n)\\sim\\operatorname{Markov}(\\lambda,P)$ iff for all $n\\ge 0$ and $i_0,\\ldots,i_n\\in I$,\r\n    $$\\mathbb P[X_0=i_0,\\ldots,X_n=i_n]=\\lambda_{i_0}p_{i_0i_1}\\cdots p_{i_{n-1}i_n}$$\r\n\\end{theorem}\r\nPretty obvious but let's write this out.\r\n\\begin{proof}\r\n    Suppose $(X_n)\\sim\\operatorname{Markov}(\\lambda,P)$, then\r\n    \\begin{align*}\r\n        &\\phantom{=}\\mathbb P[X_0=i_0,\\ldots,X_n=i_n]\\\\\r\n        &=\\mathbb P[X_n=i_n|X_0=i_0,\\ldots,X_{n-1}=i_{n-1}]\\mathbb P[X_0=i_0,\\ldots,X_{n-1}=i_{n-1}]\\\\\r\n        &=\\mathbb P[X_n=i_n|X_{n-1}=i_{n-1}]\\mathbb P[X_0=i_0,\\ldots,X_{n-1}=i_{n-1}]\\\\\r\n        &=p_{i_{n-1}i_n}\\mathbb P[X_0=i_0,\\ldots,X_{n-1}=i_{n-1}]\\\\\r\n        &=\\cdots=\\lambda_{i_0}p_{i_0i_1}\\cdots p_{i_{n-1}i_n}\r\n    \\end{align*}\r\n    Conversely, assume this is true, then set $n=0$ gives $\\mathbb P[X_0=i_0]=\\lambda_{i0}$, and that\r\n    \\begin{align*}\r\n        \\mathbb P[X_n=i_n|X_0=i_0,\\ldots,X_{n-1}=i_{n-1}]&=\\frac{\\mathbb P[X_0=i_0,\\ldots,X_n=i_n]}{\\mathbb P[X_0=i_0,\\ldots,X_{n-1}=i_{n-1}]}\\\\\r\n        &=p_{i_{n-1}i_n}\\\\\r\n        &=\\mathbb P[X_n=i_n|X_{n-1}=i_{n-1}]\r\n    \\end{align*}\r\n    which are exactly what we need.\r\n\\end{proof}\r\nLet $\\delta_i$ be the vector that has $1$ at $i^{th}$ entry and $0$ in other places.\r\n\\begin{theorem}\r\n    Let $(X_n)\\sim\\operatorname{Markov}(\\lambda,P)$, then conditioning on $X_m=i$, $(X_{m+n})_{n\\ge 0}\\sim\\operatorname{Markov}(\\delta_i,P)$ and is independent of $X_0,\\ldots,X_m$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    It suffices to show that\\\\\r\n    (i) $\\mathbb P[X_m=i_m,\\ldots,X_{m+n}=i_{m+n}|X_m=i]=\\delta_{ii_m}p_{i_mi_{m+1}}\\cdots p_{i_{m+n-1}i_{m+n}}$.\\\\\r\n    (ii) For every event $A$ determined by $X_1,\\ldots,X_m$ and every event $B$ determined by $X_m,X_{m+1},\\ldots$, we have\r\n    $$\\mathbb P[A\\cap B|X_m=i]=\\mathbb P[A|X_m=i]\\mathbb P[B|X_m=i]$$\r\n    In other words, ``independence of past and future given present''.\\\\\r\n    The previous theorem implies both for the elementary events\r\n    $$A=\\{X_0=i_0,\\ldots,X_m=i_m\\},B=\\{X_m=i_m,\\ldots,X_{m+n}=i_{m+n}\\}$$\r\n    Indeed, after multiplying the both sides by $\\mathbb P[X_m=i]$, (i) becomes\r\n    $$\\mathbb P[X_m=i_m,\\ldots,X_{m+n}=i_{m+n}]=\\delta_{ii_m}p_{i_mi_{m+1}}\\cdots p_{i_{m+n-1}i_{m+n}}\\mathbb P[X_m=i]$$\r\n    and (ii) becomes\r\n    $$\\mathbb P[A\\cap B]=\\mathbb P[A]\\mathbb P[B|X_m=i]=\\delta_{ii_m}\\mathbb P[A]\\mathbb P[B]$$\r\n    which are obviously true due to the theorem.\r\n    Decomposing every events into elementary ones then proves the theorem.\r\n\\end{proof}\r\nWe say an array $(\\lambda_i)$ as a distribution if $\\sum_i\\lambda_i=1$, and a measure if $\\lambda_i\\ge 0$ for all $i$.\r\nWhen we mention arrays like these, we always mean row vectors.\r\n\\footnote{Staggering, I know.}\r\nWe write $(P^n)_{ij}=P^{(n)}_{ij}$ as convention.\r\nWhen $\\lambda_i>0$, we write $\\mathbb P_i[A]=\\mathbb P[A|X_0=i]$.\r\nSo $(X_n)_{n\\ge 0}\\sim\\operatorname{Markov}(\\delta_i,P)$ under $\\mathbb P_i$.\r\n\\begin{theorem}\r\n    Let $(X_n)_{n\\ge 0}\\sim\\operatorname{Markov}(\\lambda,P)$.\r\n    Then for all $n,m\\ge 0$, we have\\\\\r\n    (a) $\\mathbb P[X_n=j]=(\\lambda P^n)_j$.\\\\\r\n    (b) $\\mathbb P_i[X_n=j]=p_{ij}^{(n)}$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider the general two-state Markov chain with\r\n    $$P=\\begin{pmatrix}\r\n        1-\\alpha&\\alpha\\\\\r\n        \\beta&1-\\beta\r\n    \\end{pmatrix}$$\r\n    As $P^{n+1}=P^nP$, we have $p_{11}^{(n+1)}=p_{12}^{(n)}\\beta+p_{11}^{(n)}(1-\\alpha)$.\r\n    Also $p_{12}^{(n)}+p_{11}^{(n)}=1$, so $p_{11}^{(n+1)}=p_{11}^{(n)}(1-\\alpha-\\beta)+\\beta$.\r\n    As one can verify oneself, this gives\r\n    $$p_{11}^n=\\begin{cases}\r\n        \\frac{\\beta}{\\alpha+\\beta}+\\frac{\\alpha}{\\alpha+\\beta}(1-\\alpha-\\beta)^n\\text{, if $\\alpha+\\beta>0$}\\\\\r\n        1\\text{, if $\\alpha+\\beta=0$}\r\n    \\end{cases}$$\r\n    And this basically told us the explicit formula of $P^n$, so this basic case of Markov chain can be solved easily.\r\n\\end{example}\r\nThe general method to compute the transition probability $p_{ij}^{(n)}$ for an $N$ state Markov chain is just as what we expect.\r\nFirst, compute the eigenvalues $\\lambda_1,\\ldots,\\lambda_N$ of $P$.\r\nIf the eigenvalues are all distinct, then $P$ is diagonalisable so we easily get\r\n$$p_{ij}^{(n)}=a_1\\lambda_1^n+\\cdots+a_N\\lambda_N^n$$ for some constants $(a_k)$ depending on $i,j$.\r\nIf an eigenvalue $\\lambda_l$ has multiplicity $k$, we can simply replace $a_l$ by a degree $k$ polynomial in $n$.\r\nThis can be justified by considering the Jordan Normal form of $P$.\r\nIn general, the eigenvalues are not real numbers, but the values of $p_{ij}^{(n)}$ will are of course always real (and most of the times can be represented by trigonometric functions).\r\n\\begin{example}\r\n    Consider the transition matrix\r\n    $$P=\\begin{pmatrix}\r\n        &1&\\\\\r\n        &1/2&1/2\\\\\r\n        1/2&&1/2\r\n    \\end{pmatrix}$$\r\n    We shall compute $p_{11}^{(n)}$.\r\n    Now $\\det(\\lambda I-P)=(\\lambda-1)(4\\lambda^2+1)/4$, so the eigenvalues are $1,i/2,-i/2$.\r\n    Therefore $p_{11}^{(n)}=a+b(i/2)^n+c(-i/2)^n$ for some constants $a,b,c$.\r\n    Observe that\r\n    $$\\left(\\pm\\frac{i}{2}\\right)^n=\\frac{1}{2^n}\\left(\\cos\\frac{\\pi n}{2}\\pm i\\sin\\frac{\\pi n}{2}\\right)$$\r\n    Therefore we can get rid of $i$ and write\r\n    $$p_{11}^{(n)}=\\alpha+\\frac{1}{2^n}\\left[\\beta\\cos\\frac{\\pi n}{2}+\\gamma\\sin\\frac{\\pi n}{2}\\right]$$\r\n    for some constants $\\alpha,\\beta,\\gamma$.\r\n    Plugging in initial values reveals that $\\alpha=1/5,\\beta=4/5,\\gamma=-2/5$, so\r\n    $$p_{11}^{(n)}=\\frac{1}{5}+\\frac{1}{2^n}\\left[\\frac{4}{5}\\cos\\frac{\\pi n}{2}-\\frac{2}{5}\\sin\\frac{\\pi n}{2}\\right]$$\r\n\\end{example}\r\nNow we can compute many data out of a Markov chain, but as good mathematicians we realise that there can be more properties in a Markov chain that can be explored.", "meta": {"hexsha": "f4f42862c882c0dc31c8013f9f1e890cfbb98a7c", "size": 7307, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/defn.tex", "max_stars_repo_name": "david-bai-notes/IB-Markov-Chains", "max_stars_repo_head_hexsha": "cef4f20b59106a1deaed4de2f503e594e3ffc61d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1/defn.tex", "max_issues_repo_name": "david-bai-notes/IB-Markov-Chains", "max_issues_repo_head_hexsha": "cef4f20b59106a1deaed4de2f503e594e3ffc61d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1/defn.tex", "max_forks_repo_name": "david-bai-notes/IB-Markov-Chains", "max_forks_repo_head_hexsha": "cef4f20b59106a1deaed4de2f503e594e3ffc61d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.5391304348, "max_line_length": 225, "alphanum_fraction": 0.6389763241, "num_tokens": 2694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604133, "lm_q2_score": 0.8723473829749844, "lm_q1q2_score": 0.7465994954435488}}
{"text": "\\subsection{Classification of surfaces}\n\nGiven surfaces $M_{1}$ and $M_{2}$ we can form a new surface $M_{3}=M_{1}\\#M_{2}$,\nthe connected sum, by removing from each the interior of ~disc, and\ngluing together along the boundaries with a homeomorphism $f$.\n\\begin{fact}\nEvery closed connected surface is homeomorphic to one of $S^{2}$,\n$M_{g}=T\\#T\\#\\cdots\\#T$ ($g$ copies of the torus $T=T^{2}$) or\n$N_{h}=P\\#P\\#\\cdots\\#P$ (h copies of $P=\\mathbb{R}P^{2})$.\n\\end{fact}\n$M_{g}$ can also be understood in a planar model as the $4g$-gon\nwith edges identified in pairs, i.e. according to the word\n\n\\begin{align*}\n[a_{1},b_{1}][a_{2},b_{2}]\\cdots[a_{g},b_{g}].\n\\end{align*}\n\n\n$N_{h}$ can be written as the $2h$-gon with edges identified according\nto the word\n\n\\begin{align*}\na_{1}^{2}a_{2}^{2}\\cdots a_{n}^{2}.\n\\end{align*}\n\n\nNote: We can see that these surfaces are all different (not homeomorphic)\nby considering the Abelianisations. We then have some corollaries.\n\\begin{cor}\nNo two $S^{2},M_{g},N_{h}$ are homeomorphic. In fact, two closed\nsurfaces are homeomorphic iff they have the same Abelian $\\pi_{1}$,\niff they are homotopically-equivalent.\n\\end{cor}\n\n\\begin{cor}\nA closed surface is simply connected iff it is homeomorphic to $S^{2}$.\n\\end{cor}\n\n", "meta": {"hexsha": "2b80837545b21fca830f0b8f2c3d39b9e37e8a1a", "size": 1250, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "classification_of_surfaces.tex", "max_stars_repo_name": "silky/alg-top-notes", "max_stars_repo_head_hexsha": "2e47a522a31a93487df6ab523ed555aaa2ca017c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-11-17T08:28:55.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-17T08:28:55.000Z", "max_issues_repo_path": "classification_of_surfaces.tex", "max_issues_repo_name": "silky/alg-top-notes", "max_issues_repo_head_hexsha": "2e47a522a31a93487df6ab523ed555aaa2ca017c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "classification_of_surfaces.tex", "max_forks_repo_name": "silky/alg-top-notes", "max_forks_repo_head_hexsha": "2e47a522a31a93487df6ab523ed555aaa2ca017c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.0512820513, "max_line_length": 82, "alphanum_fraction": 0.6984, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7465994922842096}}
{"text": "\n\\subsection{Abelian groups}\n\nA commutative group, that is where \\(a\\odot b=b\\odot a\\).\n\nThe following are abelian groups:\n\n\\begin{itemize}\n\\item Integers and addition\n\\item \\(\\{-1, 1\\}\\) and multiplication\n\\end{itemize}\n\nThe following are not abelian groups:\n\n\\begin{itemize}\n\\item Natural numbers above \\(0\\) and addition\n\\item Rational numbers and division\n\\item Natural numbers and addition\n\\item Natural numbers up to \\(10\\) and addition\n\\item \\(n\\times n\\) matrices with determinants other than \\(0\\)\n\\end{itemize}\n\n", "meta": {"hexsha": "537828b99261e550c5aeecb084ad9788eb725607", "size": 522, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/01-04-abelian.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/groups/01-04-abelian.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/groups/01-04-abelian.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.6956521739, "max_line_length": 63, "alphanum_fraction": 0.7394636015, "num_tokens": 146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529791457032, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7464840902855293}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\subsection{Worksheet - Review of Weeks 1-4}\n\\begin{p}\nWhich of these problems must be solved using the calculus of variations?\n\\newline 1. Find the period of small oscillations for a particle sliding (without friction) on the inside of a sphere.\n\\newline 2. Find the surface with fixed area that encloses the maximum volume.\n\\newline 3. Find the path between two points that minimizes the time for a particle to slide (without friction) between the points.\n\\newline 4. Find the path of a projectile (with no air resistance) that leads to the maximum range.\n\\end{p}\n\\begin{s}\nExactly two. For 1, we looked at the equations of motion and Taylor expanded around the minimum for small $\\phi$. So, we aren't looking for the path that minimizes some functional in this case, hence its not particularly a variational problem. For 2, we have an optimization problem; we are trying to extremize/maximize a volume. We can write an expression for the surface area, and add in a constraint (e.g. we could use Lagrange multipliers for example). We could optimize this with the Calculus of variations. 3 is the brachistochrone problem, obviously yes. 4 does not require varations; this is just a question of initial conditions of the trajectory.\n\\end{s}\n\n\\begin{p}\nA calculus of variations problem requires minimizing\n$$\nJ[y(x)]=\\int_{x_{1}}^{x_{2}} f\\left[y(x) ; y^{\\prime}(x) ; x\\right] d x\n$$\nWhen we solve Euler's equation\n$$\n\\frac{\\partial f}{\\partial y}-\\frac{d}{d x} \\frac{\\partial f}{\\partial y^{\\prime}}=0\n$$\nwhat do we learn?\n\\end{p}\n\\begin{s}\nWe learn of the path $y(x)$ that minimizes $J[y(x)]$; the EL equation gives a differential equation for the path $y(x)$ which minimizes $J[y(x)]$.\n\\end{s}\n\n\\begin{p}\nWhat is the Lagrangian of a particle of mass $m$ attached to a spring with spring constant $k$?\n\\end{p}\n\\begin{s}\n$\\LL = T - U = \\frac{1}{2}m\\dot{x}^2 - \\frac{1}{2}kx^2$ (the kinetic energy term minus the potential energy term).\n\\end{s}\n\n\\begin{p}\nWhat is the Lagrangian of a pendulum of mass $m$, length $l$? Assume the potential energy is zero when $\\theta$ is zero.\n\\end{p}\n\\begin{s}\n$\\LL(\\theta, \\dot{\\theta}, t) = \\frac{1}{2}ml^2\\dot{\\theta}^2 - mgl(1-\\cos\\theta)$\n\\end{s}\n\n\\begin{p}\nFor which of these systems could you use Lagrange's equations of motion?\n\\newline 1. A double pendulum: a pendulum (mass $\\mathrm{m}$, length 1 ) has a second pendulum (mass $\\mathrm{m}$, length l) connected to its bob.\n\\newline 2. A projectile moves in two dimensions with gravity and air resistance.\n\\newline 3. A bead slides without friction on a circular, rotating wire.\n\\end{p}\n\\begin{s}\nEverything but 2 works; with 2, we have friction/a non-conservative force and hence the Lagrange equations no longer apply (though we can add in a correction to account for this).\n\\end{s}\n\n\\begin{p}\nA particle moves in one dimension with Lagrangian $\\LL = T - U$. Suppose we shift the potential energy $U$ by a constant $C$. What changes?\n\\end{p}\n\\begin{s}\nThe value of $S$ changes ($S$ depends on the Lagrangian) but the physical path $x(t)$ taken by the particle remains invariant (that is, the path that gives $\\delta S = 0$); one way of seeing this is the equations of motion are given by derivatives of the Lagrangian, which would remove the effects of any constants.\n\\end{s}\n\n\\begin{p}\nA bead of mass $m$ slides on a circular wire of radius $R$, which rotates about a vertical axis with angular velocity $\\Omega$. The equation of motion of the bead is \\[\\ddot{\\theta} + \\frac{g}{R}\\sin\\theta - \\Omega^2\\sin\\theta\\cos\\theta = 0\\]\nWhat are the equilibrium values of $\\theta$?\n\\end{p}\n\\begin{s}\n$\\theta = 0$ and $\\theta = \\arccos(\\frac{g}{R\\Omega^2})$.\n\\end{s}\n\n\\begin{p}\nThe equation of motion for small motions about the equilibrium $\\theta = \\arccos(\\frac{g}{R\\Omega^2})$ above is given by:\n\\[\\ddot{\\theta} +\\Omega^2\\sin^\\theta_0\\theta = 0\\]\nWhat is the oscillation frequency of the bead?\n\\end{p}\n\\begin{s}\n$\\omega = \\Omega\\sin\\theta_0$\n\\end{s}\n\n\\begin{p}\nWhich of these systems are holonomic? E.g. which of these systems have a constraint that can be written as $f(q_1, \\ldots, q_n, t) = 0$?\n\\newline 1. The double pendulum, but with the lower mass attached by a spring instead of a spring.\n\\newline 2. The motion of a hockeyu puck around a frictionless air hockey table\n\\newline 3. A bead moving frictionless on a circular wire hoop spinning at fixed angular velocity.\n\\end{p}\n\\begin{s}\nA and C. With C, this is obviously possible (we constrain the radius). With B, the constraint is an inequality (e.g. the normal force is just such that the mass stays at the level of the table), which makes it non-holonomic. With A, we have that the lower mass can move more freely; the system is still holonomic, we just got rid of the constraint on the second mass. Note that if forces are dissipative, then we can also not write constrains as holonomic.\n\\end{s}\n\n\\begin{p}\nWhat is the constraint equation?\n\\begin{center}\n    \\includegraphics[scale=0.75]{Lecture-13/w13-img1.png}\n\\end{center}\n\\end{p}\n\\begin{s}\n$f(x,y) = \\frac{y}{x} - \\tan(\\alpha) = 0$. A typical holonomic constraint.\n\\end{s}\n\n\\begin{p}\nA particle of mass $m$ slides on the outside of a cylinder of radius $a$. A good choice of generalized coordinates is $(r, \\theta)$. What is the constraint equation?\n\\end{p}\n\\begin{s}\n$f(r,\\theta) = r - a = 0$\n\\end{s}\n\n\\begin{p}\nWhat can you conclude from the fact that $\\dpd{\\LL}{\\dot{x}_i}$ is constant for all $i$?\n\\end{p}\n\\begin{s}\nMomentum is conserved.\n\\end{s}\n\n\\begin{p}\nHow can we rewrite:\n\\[\\int_{t_1}^{t_2}p_j\\dod{}{t}\\delta q_j dt\\]\n\\end{p}\n\\begin{s}\nBy integrating by parts, we get:\n\\[-\\int_{t_1}^{t_2}\\dot{p}_j\\delta q_j dt\\]\n(the variation vanishes at the boundary, so it is discarded).\n\\end{s}\n\n\\end{document}", "meta": {"hexsha": "26fed5385c04b4ad5eb9d83bc4fa719dacd1b72b", "size": 5779, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-13/Worksheet-13.tex", "max_stars_repo_name": "RioWeil/PHYS306-notes", "max_stars_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture-13/Worksheet-13.tex", "max_issues_repo_name": "RioWeil/PHYS306-notes", "max_issues_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture-13/Worksheet-13.tex", "max_forks_repo_name": "RioWeil/PHYS306-notes", "max_forks_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.9837398374, "max_line_length": 656, "alphanum_fraction": 0.7233085309, "num_tokens": 1699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387956435734, "lm_q2_score": 0.9005297907896396, "lm_q1q2_score": 0.746484080218323}}
{"text": "\\section{Inverse Trigonometric Functions}\\label{sec:InvTrigFunctionsSection}\r\nThe trigonometric functions frequently arise in problems, and often it\r\nis necessary to invert the functions, for example, to find an angle with\r\na specified sine. Of course, there are many angles with the same sine,\r\nso the sine function doesn't actually have an inverse that reliably\r\n``undoes'' the sine function. If you know that $\\sin x=0.5$, you can't\r\nreverse this to discover $x$, that is, you can't solve for\r\n$x$, as there are infinitely many angles with sine\r\n$0.5$. Nevertheless, it is useful to have something like an inverse to\r\nthe sine, however imperfect. The usual approach is to pick out some\r\ncollection of angles that produce all possible values of the sine\r\nexactly once. If we ``discard'' all other angles, the resulting\r\nfunction does have a proper inverse.\r\n\r\nThe sine takes on all values between $-1$ and $1$ exactly once on the\r\ninterval $[-\\pi/2,\\pi/2]$. \r\n$$\\includegraphics[width=4in]{images2/inv-trig-sin}$$\r\nIf we truncate the sine, keeping only the\r\ninterval $[-\\pi/2,\\pi/2]$, then this truncated sine has an inverse function. We call this\r\nthe inverse\\index{inverse sine} sine or the arcsine\\index{arcsine}, and\r\nwrite it in one of two common notation: $y=\\arcsin(x)$, or $y=\\sin^{-1}(x)$.\r\n$$\\includegraphics[width=2in]{images2/inv-trig-arcsin}$$\r\n\r\nRecall that a function and its inverse undo each other in either\r\norder, for example, $\\ds (\\root3\\of x)^3=x$ and $\\ds \\root3\\of{x^3}=x$. This\r\ndoes not work with the sine and the ``inverse sine'' because the\r\ninverse sine is the inverse of the truncated sine function, not the\r\nreal sine function. It is true that $\\sin(\\arcsin(x))=x$, that is, the\r\nsine undoes the arcsine. It is not true that the arcsine undoes the\r\nsine, for example, $\\sin(5\\pi/6)=1/2$ and $\\arcsin(1/2)=\\pi/6$, so\r\ndoing first the sine then the arcsine does not get us back where we\r\nstarted. This is because $5\\pi/6$ is not in the domain of the\r\ntruncated sine. If we start with an angle between $-\\pi/2$ and $\\pi/2$\r\nthen the arcsine does reverse the sine: $\\sin(\\pi/6)=1/2$ and\r\n$\\arcsin(1/2)=\\pi/6$.\r\n\r\n\\begin{example}{Arcsine of Common Values}{Arcsine of Common Values}\r\nCompute $\\sin^{-1}(0)$,\\quad $\\sin^{-1}(1)$\\quad and\\quad $\\sin^{-1}(-1)$.  \r\n\\end{example}\r\n\r\n\\begin{solution}\r\nThese come directly from the graph of $y=\\arcsin x$:\r\n$$\\sin^{-1}\\left( 0\\right) =0\\qquad \\qquad \\sin^{-1}(1)=\\frac{\\pi}{2}\\qquad  \\qquad \\sin^{-1}(-1)=-\\frac{\\pi}{2}$$\r\n\\end{solution}\r\n\r\nWe can do something similar for the cosine function. As with the sine, we must\r\nfirst truncate the cosine so that it can be inverted, in particular, we use the interval $[0,\\pi]$. \r\n$$\\includegraphics[width=4in]{images2/inv-trig-cos}$$\r\nNote that the\r\ntruncated cosine uses a different interval than the truncated sine, so\r\nthat if $y=\\arccos(x)$ we know that $0\\le y\\le \\pi$.\r\n$$\\includegraphics[width=2in]{images2/inv-trig-arccos}$$\r\n\r\n\\begin{example}{Arccosine of Common Values}{Arccosine of Common Values}\r\nCompute $\\cos^{-1}(0)$,\\quad $\\cos^{-1}(1)$\\quad and\\quad $\\cos^{-1}(-1)$.  \r\n\\end{example}\r\n\r\n\\begin{solution}\r\nThese come directly from the graph of $y=\\arccos x$:\r\n$$\\cos^{-1}\\left( 0\\right) =\\frac{\\pi}{2}\\qquad \\qquad \\cos^{-1}(1)=0\\qquad  \\qquad \\cos^{-1}(-1)=\\pi$$\r\n\\end{solution}\r\n\r\nFinally we look at the tangent; the other trigonometric functions also\r\nhave ``partial inverses'' but the sine, cosine and tangent are enough\r\nfor most purposes. The truncated tangent uses an interval of $(-\\pi/2,\\pi/2)$.\r\n$$\\includegraphics[width=2.75in]{images2/inv-trig-tan}$$\r\nReflecting the truncated tangent in the line $y=x$ gives the arctangent function.\r\n$$\\includegraphics[width=3.5in]{images2/inv-trig-arctan}$$\r\n\r\n\\begin{example}{Arctangent of Common Values}{Arctangent of Common Values}\r\nCompute $\\tan^{-1}(0)$.\r\nWhat value does $\\tan^{-1}x$ approach as $x$ gets larger and larger?\r\nWhat value does $\\tan^{-1}x$ approach as $x$ gets large (and negative)? \r\n\\end{example}\r\n\r\n\\begin{solution}\r\nThese come directly from the graph of $y=\\arctan x$.\r\nIn particular, $\\tan^{-1}(0)=0$.\r\nAs $x$ gets larger and larger, $\\tan^{-1}x$ approaches a value of $\\frac{\\pi}{2}$, whereas, as $x$ gets large but negative, $\\tan^{-1}x$ approaches a value of $-\\frac{\\pi}{2}$.\r\n\\end{solution}\r\n\r\nThe cancellation rules are tricky since we restricted the domains of the trigonometric functions in order to obtain inverse trig functions:\r\n\r\n\\begin{formulabox}[Cancellation Rules]\r\n\\[ \\sin ( \\sin^{-1} x ) = x, \\ \\ \\ x \\in [-1, 1] \\qquad\\qquad \\sin^{-1} ( \\sin x) = x, \\ \\ \\ x \\in \\left[-\\frac{\\pi}{2}, \\frac{\\pi}{2} \\right] \\]\r\n\\[ \\cos ( \\cos^{-1} x ) = x, \\ \\ \\ x \\in [-1, 1] \\qquad\\qquad \\ \\ \\ \\cos^{-1} ( \\cos x) = x, \\ \\ \\ x \\in \\left[0, \\pi \\right]\\ \\ \\  \\]\r\n\\[ \\tan ( \\tan^{-1} x ) = x, \\ \\ \\ x \\in (-\\infty, \\infty) \\qquad\\qquad \\tan^{-1} ( \\tan x) = x, \\ \\ \\ x \\in \\left(-\\frac{\\pi}{2}, \\frac{\\pi}{2} \\right) \\]\r\n\\end{formulabox}\r\n\r\n\\begin{example}{Arcsine of $1/2$}{Arcsine of $1/2$}\r\nFind $\\sin ^{-1}\\left( 1/2\\right) $. \r\n\\end{example}\r\n\r\n\\begin{solution}\r\nSince $\\sin^{-1}(x)$ outputs values in $[-\\pi/2,~\\pi/2]$, the answer must be in this interval.\r\nLet $\\theta=\\sin^{-1}(1/2)$. \r\nWe need to compute $\\theta$. \r\nTake the sine of both sides to get $\\sin \\theta = \\sin(\\sin^{-1}(1/2))=1/2$ by the cancellation rule.\r\nThere are many angles $\\theta$ that work, but we want the one in the interval $[-\\pi/2,~\\pi/2]$.\r\nThus, $\\theta=\\pi/6$ and hence, $\\ds\\sin^{-1}\\left(\\frac{1}{2}\\right)=\\frac{\\pi}{6}$.\r\n\\end{solution}\r\n\r\n\\begin{example}{Arccosine and the Cancellation Rule}{Arccosine and the Cancellation Rule}\r\nCompute $\\cos ^{-1}(\\cos(0))$,\\quad $\\cos ^{-1}(\\cos(\\pi))$,\\quad $\\cos^{-1}(\\cos(2\\pi))$,\\quad $\\cos^{-1}(\\cos(3\\pi))$. \r\n\\end{example}\r\n\r\n\\begin{solution}\r\nSince $\\cos^{-1}(x)$ outputs values in $[0,~\\pi]$, the answers must be in this interval.  \r\nThe first two we can cancel using the cancellation rules:  \r\n$$\\cos ^{-1}(\\cos(0))=0\\qquad\\mbox{and}\\qquad\\cos ^{-1}(\\cos(\\pi))=\\pi.$$ \r\nThe third one we cannot cancel since $2\\pi\\notin[0,\\pi]$:\r\n$$\\cos ^{-1}(\\cos(2\\pi))\\mbox{\\quad\\red{is NOT equal to}\\quad}2\\pi.$$  \r\nBut we know that cosine is a $2\\pi$-periodic function, so $\\cos(2\\pi)=\\cos(0)$: \r\n$$\\cos ^{-1}(\\cos(2\\pi))=\\cos^{-1}(\\cos(0))=0$$\r\nSimilarly with the fourth one, we can \\red{NOT} cancel yet since $3\\pi\\notin[0,\\pi]$. Using $\\cos(3\\pi)=\\cos(3\\pi-2\\pi)=\\cos(\\pi)$:  \r\n$$\\cos ^{-1}(\\cos(3\\pi))=\\cos^{-1}(\\cos(\\pi))=\\pi.$$\r\n\\end{solution}\r\n\r\n\\begin{example}{The Triangle Technique}{The Triangle Technique}\r\nRewrite the expression $\\cos(\\sin^{-1}x)$ without trig functions.\r\nNote that the domain of this function is all $x\\in[-1,1]$.\r\n\\end{example}\r\n\r\n\\begin{solution}\r\nLet $\\theta=\\sin^{-1}x$. \r\nWe need to compute $\\cos\\theta$.\r\nTaking the sine of both sides gives $\\sin \\theta = \\sin(\\sin^{-1}(x))=x$ by the cancellation rule. \r\nWe then draw a right triangle using $\\sin\\theta=x/1$:\r\n$$\\includegraphics[width=1.5in]{images2/inv-trig-triangle-1}$$\r\nIf $z$ is the remaining side, then by the Pythagorean Theorem:\r\n$$z^2+x^2=1\\qquad\\to\\qquad z^2=1-x^2\\qquad\\to\\qquad z=\\pm\\sqrt{1-x^2}$$\r\nand hence $z=+\\sqrt{1-x^2}$ since $\\theta\\in[-\\pi/2,~\\pi/2]$.\r\nThus, $\\ds\\cos\\theta=\\sqrt{1-x^2}$ by SOH CAH TOA, so, $\\ds\\cos(\\sin^{-1}x)=\\sqrt{1-x^2}$.\r\n\\end{solution}\r\n\r\n\\begin{example}{The Triangle Technique 2}{The Triangle Technique 2}\r\nFor $x\\in(0,1)$, rewrite the expression $\\ds\\sin(2\\cos^{-1}x)$.  \r\nCompute $\\sin(2\\cos^{-1}(1/2))$. \r\n\\end{example}\r\n\r\n\\begin{solution}\r\nLet $\\theta=\\cos^{-1}x$ so that $\\cos\\theta = x$.  \r\nThe question now asks for us to compute $\\sin(2\\theta)$.  \r\nWe then draw a right triangle using $\\cos\\theta=x/1$:\r\n$$\\includegraphics[width=1.75in]{images2/inv-trig-triangle-2}$$\r\nTo find $\\sin(2\\theta)$ we use the double angle formula $\\ds \\sin(2\\theta)=2\\sin\\theta\\cos\\theta$.\r\nBut $\\sin\\theta=\\sqrt{1-x^2}$, for $\\theta\\in[0,\\pi]$, and $\\cos\\theta=x$. \r\nTherefore, $\\ds\\sin(2\\cos^{-1}x)=2x\\sqrt{1-x^2}$. \r\nWhen $x=1/2$ we have $\\ds\\sin(2\\cos^{-1}(1/2))=\\frac{\\sqrt 3}{2}$.\r\n\\end{solution}\r\n\r\n\r\nIn Figure \\ref{fig:domain_trig} we show the restrictions of the domains of the standard trigonometric functions that allow them to be invertible.\\\\\r\n\r\n%\\noindent %\\hskip-110pt%\r\n%\\noindent\\begin{minipage}{\\textwidth+200pt}\r\n\\small\\noindent\r\n%\\centering%\\begin{center}\r\n%\\noindent\\begin{minipage}[t]{.5\\textwidth}%\r\n\\begin{tabular}{cccccc}\r\nFunction & Domain & Range &\\parbox[b]{40pt}{\\centering Inverse Function} & Domain & Range\\\\ \\hline\r\n\\rule{0pt}{12pt} $\\sin x$ & $[-\\pi/2, \\pi/2]$ & $[-1,1]$&$\\sin^{-1} x$ & $[-1,1]$ & $[-\\pi/2, \\pi/2]$ \\\\\r\n\\rule{0pt}{12pt}$\\cos x$ & $[0,\\pi]$ & $[-1,1]$&$\\cos^{-1}(x)$ & $[-1,1]$ & $[0,\\pi]$ \\\\\r\n\\rule{0pt}{12pt}$\\tan x$ & $(-\\pi/2,\\pi/2)$ & $(-\\infty,\\infty)$&$\\tan^{-1}(x)$ & $(-\\infty,\\infty)$ & $(-\\pi/2,\\pi/2)$\t\\\\\r\n%\\rule{0pt}{12pt} $\\csc x$ & $[-\\pi/2,0)\\cup (0, \\pi/2]$ & $(-\\infty,-1]\\cup [1,\\infty)$&$\\csc^{-1} x$ & $(-\\infty,-1]\\cup [1,\\infty)$ & $[-\\pi/2,0)\\cup (0, \\pi/2]$  \\\\\r\n%the following makes integral of inverse function nicer\r\n\\rule{0pt}{12pt} $\\csc x$ & $[-\\pi/2,0)\\cup (0, \\pi/2]$ & $(-\\infty,-1]\\cup [1,\\infty)$&$\\csc^{-1} x$ & $(-\\infty,-1]\\cup [1,\\infty)$ & $(0,\\pi/2]\\cup (\\pi, 3\\pi/2]$  \\\\\r\n%\\rule{0pt}{12pt}$\\sec x$ & $[0,\\pi/2)\\cup (\\pi/2,\\pi]$ & $(-\\infty,-1]\\cup [1,\\infty)$&$\\sec^{-1}(x)$ & $(-\\infty,-1]\\cup [1,\\infty)$ & $[0,\\pi/2)\\cup (\\pi/2,\\pi]$ \\\\\r\n%the following makes integral of inverse function nicer\r\n\\rule{0pt}{12pt}$\\sec x$ & $[0,\\pi/2)\\cup (\\pi/2,\\pi]$ & $(-\\infty,-1]\\cup [1,\\infty)$&$\\sec^{-1}(x)$ & $(-\\infty,-1]\\cup [1,\\infty)$ & $[0,\\pi/2)\\cup [\\pi,3\\pi/2]$ \\\\\r\n\\rule{0pt}{12pt}$\\cot x$ & $(0,\\pi)$ & $(-\\infty,\\infty)$&$\\cot^{-1}(x)$ &  $ (-\\infty,\\infty)$ & $(0,\\pi)$\t\r\n\\end{tabular}\r\n%\\captionsetup{type=figure}\r\n\\caption{Domains and ranges of the trigonometric and inverse trigonometric functions. \\label{fig:domain_trig}}\r\n%\\end{center}\r\n%\\normalsize\r\n%\\end{minipage}\r\n%\\captionsetup{type=figure}%\r\n%\\caption{Domains and ranges of the trigonometric and inverse trigonometric functions.}\\label{fig:domain_trig}\r\n%\\end{minipage}\r\n%}\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for \\ref{sec:InvTrigFunctionsSection}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n\\begin{ex}\r\nCompute the following:\r\n\\begin{multicols}{2}\r\n\\begin{enumerate}\r\n\t\\item\t$\\sin^{-1}(\\sqrt{3}/2)$\r\n\t\\item\t$\\cos^{-1}(-\\sqrt{2}/2)$\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\t\\item\t$\\pi/3$\r\n\t\\item\t$3\\pi/4$\r\n\\end{enumerate}\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nCompute the following:\r\n\\begin{multicols}{2}\r\n\\begin{enumerate}\r\n\t\\item\t$\\sin^{-1}\\left(\\sin(\\pi/4)\\right)$\r\n\t\\item\t$\\sin^{-1}\\left(\\sin(17\\pi/3)\\right)$\r\n\t\\item\t$\\cos\\left(\\cos^{-1}(1/3)\\right)$\r\n\t\\item\t$\\tan\\left(\\cos^{-1}(-4/5)\\right)$\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\begin{sol}\r\n\\begin{multicols}{2}\r\n\\begin{enumerate}\r\n\t\\item\t$\\pi/4$\r\n\t\\item\t$-\\pi/3$\r\n\t\\item\t$1/3$\r\n\t\\item\t$-3/4$\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nRewrite the expression $\\tan\\left(\\cos^{-1}x\\right)$\r\nwithout trigonometric functions. What is the domain of this function?\r\n\\begin{sol}\r\n$\\sqrt{1-x^2}/x$ with domain $[-1,0)\\cup(0,1]$.\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "11e047f1a3283f9cc75ce3655803346c70380444", "size": 11248, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2-functions/2-6-inverse-trig.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2-functions/2-6-inverse-trig.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2-functions/2-6-inverse-trig.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.0683760684, "max_line_length": 177, "alphanum_fraction": 0.6370021337, "num_tokens": 4055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245618, "lm_q2_score": 0.8824278741843883, "lm_q1q2_score": 0.7464831832092045}}
{"text": "%================================\n\\section{Connectedness}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t[connectedness]\n\t\\label{def: connectedness}\n\tLet $(X, \\mathcal T)$ be a topological space. $(X, \\mathcal T)$ is said to be \\textit{connected} iff $X$ is not empty and it it not the union of any disjoint open sets. That is,\n\t$$\n\t\\forall U, V \\in \\mathcal T : X = U \\cup V : U \\cap V \\ne \\emptyset.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n\n%--------------------------------\n\\begin{definition}\n\t[path-connectedness]\n\t\\label{def: path-connectedness}\n\tLet $(X, \\mathcal T)$ be a topological space.\n\t\\begin{enumerate}[(i)]\n\t\t\\item A map $\\gamma: [0,1] \\to X$ is called a \\textit{path} in $X$ iff it is continuous. If $\\gamma(0) = x$ and $\\gamma(1)=y$, we say that $\\gamma$ is path from $x$ to $y$ in $X$.\n\t\t\\item $X$ is said to be \\textit{path-connected} iff for all $x, y \\in X$ there is a path from $x$ to $y$ in $X$.\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------", "meta": {"hexsha": "435c1ec8af4cb8dfac74fd02d643857095f8bd4d", "size": 1046, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-v0/connectedness.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-v0/connectedness.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-v0/connectedness.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.0689655172, "max_line_length": 181, "alphanum_fraction": 0.5267686424, "num_tokens": 315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7464831828033599}}
{"text": "\\documentclass[../algorithms.tex]{subfiles}\n\\begin{document}\nThis chapter is used to conclude all the algorithms and data structures relation by showing examples. For example, we show how we can model this problem using different data structure and end up solving this problem with different algorithms. For some example, we should how different algorithm matters. \n\\section{Complete Search VS Smart Search VS Dynamic Programming}\n\\begin{examples}\n\\item \\textbf{956. Tallest Billboard (hard).} You are installing a billboard and want it to have the largest height.  The billboard will have two steel supports, one on each side.  Each steel support must be an equal height. You have a collection of rods which can be welded together.  For example, if you have rods of lengths 1, 2, and 3, you can weld them together to make a support of length 6. Return the largest possible height of your billboard installation.  If you cannot support the billboard, return 0.\n\\begin{lstlisting}[numbers=none]\nExample 1:\n\nInput: [1,2,3,6]\nOutput: 6\nExplanation: We have two disjoint subsets {1,2,3} and {6}, which have the same sum = 6.\n\nExample 2:\n\nInput: [1,2,3,4,5,6]\nOutput: 10\nExplanation: We have two disjoint subsets {2,3,5} and {4,6}, which have the same sum = 10.\n\nExample 3:\n\nInput: [1,2]\nOutput: 0\nExplanation: The billboard cannot be supported, so we return 0.\n\\end{lstlisting}\nNote: 0 <= rods.length <= 20, 1 <= rods[i] <= 1000. The sum of rods is at most 5000.\n\n\\textbf{Solution 1: Naive Complete Search.} We need to have two billboard: left and right side. Given a state (x, y), which means the sum of left and right billboard is x and y respectively. Now, to add a new rod v into the state, we have three options: 1) not use v, (x, y); 2) put v to left side: (x+v, y); 3) put v to the right side (x, y+v). If x' and y' end up to be equal, we can track the maximal value. Given the array size of n, and initial state (0, 0), we use search, each state will have three branches because of the three options, therefore, the state transfer graph(tree) will expand to $\\sum(3^0, 3^1, 3^2, ..., 3^{n}) = 3^{n+1}-1$. The code is:\n\\begin{lstlisting}[language=Python]\ndef tallestBillboard(self, rods):\n    if not rods:\n        return 0\n    n = len(rods)\n    def helper(i, l, r, ans):\n        if l == r: \n            ans[0] = max(ans[0], l)\n        if i == n:\n            return\n        helper(i+1, l, r, ans)\n        helper(i+1, l+rods[i], r, ans)\n        helper(i+1, l, r+rods[i], ans)\n        return\n    ans = [0]\n    helper(0, 0, 0, ans)\n    return ans[0]\n\\end{lstlisting}\n\\textbf{Solution 2: Smart Complete Search.} Similar to Bidirectional Search, which decrease the time complexty from $n$ power to $n/2$ by starting searching simulatously from soure and goal, and save the final nodes, and its path length from its starting node. The total length can be obtained by the common final nodes (its complexity depends on its total number of states), and sum up its path length of each side. For this problem, we can do the same by dividing the array into half and half. In each half, we enumerate all possible states and save them in a dictionary. If we have (x, y) in the left, and (y, x) in the right, then we have a possible value, which is $x+y$.  In this problem, we can compress the states: assume we have state (x, x+d) and (y, y+d), x < y, the optimal value will always be decided by the second set (y, y+d), therefore, instead of saving all possible (x,y), we can save it as (x-y) and the value is the maximum left length.  \n\\begin{lstlisting}[language=Python]\ndef tallestBillboard(self, rods):\n    def make(A):\n        # enumerate all possible states\n        states = {(0, 0)}\n        for x in A:\n            states |= ({(a+x, b) for a, b in states} |\n                       {(a, b+x) for a, b in states})\n        # compress states\n        delta = {}\n        for a, b in states:\n            delta[a-b] = max(delta.get(a-b, 0), a)\n        return delta\n    N = len(rods)\n    Ldelta = make(rods[:N//2])\n    Rdelta = make(rods[N//2:])\n\n    # meet in the middle\n    ans = 0\n    for d in Ldelta:\n        if -d in Rdelta:\n            ans = max(ans, Ldelta[d] + Rdelta[-d])\n    return ans\n\\end{lstlisting}\n\\textbf{Snapsack\\_based Dynamic Programming.}  In this solution, we define a two-dimensional dp array, dp[i][j] means using the first i rods to get a difference j which is the $y-x$. The saved value is the maximum common height for states with the same difference.  The time complexity is bounded by $O(21\\times 5000)$. This is similar to the snapsack problem, the difference is within the state transfer function as shown in Fig~\\ref{fig:dp_956}. \n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.9\\columnwidth]{fig/956-ep234.png}\n    \\caption{Dynamic Programming}\n    \\label{fig:dp_956}\n    \\includegraphics[width=0.9\\columnwidth]{fig/956_dp_table.png}\n    \\caption{The dp table: the arrows of different color means different operation. Red: not use current item, copy from the previous state; Blue: put the item on the taller side, the result is not affected; Green: put the item at the shorter side. }\n    \\label{fig:dp_956_2}\n\\end{figure}\n\\begin{lstlisting}[language=Python]\n def tallestBillboard(self, rods):\n    maxHeight = sum(rods)\n    maxRods = len(rods)\n    dp = [float('-inf') for c  in range(maxHeight+1)]  # use difference\n    dp[0] = 0\n    for i in range(0, maxRods):\n        old_dp = dp[:] \n        for j in range(0, maxHeight+1-rods[i]):\n            if old_dp[j] < 0:\n                continue\n            # green arrow\n            if j >= rods[i]:\n                dp[j-rods[i]] = max(dp[j-rods[i]], old_dp[j]+min(rods[i], j))\n            else:\n                dp[rods[i]-j] = max(dp[rods[i]-j], old_dp[j]+min(rods[i], j))\n            # blue arrow\n            dp[j+rods[i]] = max(dp[j+rods[i]], old_dp[j])                \n            # the red line is saved in dp indirectly\n    return dp[0]\n\\end{lstlisting}\n\\end{examples}\n\\end{document}", "meta": {"hexsha": "38d937efc43c20698c2ed43bafdcb8d5a10d2f44", "size": 5967, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Easy-Book/chapters/part3_deprc/example.tex", "max_stars_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_stars_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Easy-Book/chapters/part3_deprc/example.tex", "max_issues_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_issues_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Easy-Book/chapters/part3_deprc/example.tex", "max_forks_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_forks_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.375, "max_line_length": 959, "alphanum_fraction": 0.6638176638, "num_tokens": 1695, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7463856993482915}}
{"text": "\\section[Permutations, binomial coefficients]{Permutations and binomial coefficients continued}\\label{permutationsBinomialCoefficient} \n\nThe following lecture discusses some more problems in which binomial coefficients arise and will lead us \nto the famous principle of exclusion and inclusion.\n\n\\subsection{The cab driver problem}\n\nWe will begin with the so called 'cab driver problem'. Suppose that we have a city with streets arranged in \na regular grid (like Manhattan) and suppose that our city contains $n$ blocks from north to south and $m$ blocks\nfrom west to east. Now, suppose that we have a cab driver that wants to drive from one point on the grid to another\npoint, say from $A$ to $B$. In figure \\ref{fig:cabdriverprobleminitialexample} the general setup is visualized.\n\n\\begin{figure}[ht]\n    \\centering\n    \\scalebox{.6}{\\incfig{cabdriverprobleminitialexample}}\n    \\caption{The Cap Driver Problem.}\n    \\label{fig:cabdriverprobleminitialexample}\n\\end{figure}\n\\noindent\n\\textbf{Question:} In how many ways can we get from $A$ to $B$? We are only allowed to go east or north and we are not allowed to go backwards.\n\\\\\n\\\\\nLet $P_{m,n}$ be the number of paths from $A$ to $B$. We notice first, that we can solve this problem by considering a sequence of letters. Let \nus denote \"going north\" by the letter \"N\" and \"going east\" by the letter \"E\", then a path from $A$ to $B$ corresponds to a sequence of N's and E's\nof length $m+n$ with $n$ N's and $m$ E's. The total number of such words is equal to the total number of paths from $A$ to $B$.\n\\\\\n\\\\\nThere is also another solution. Starting from any point in the above grid, there are only two choices: go north or go east. Let $A$ be the starting point\nand denote \"going north in the first step\" by $A'$ and \"going east in the second step\" by $A''$, then the total number of paths from $A$ to $B$ is equal to \nthe total number of paths from $A'$ to $B$ plus the total number of paths from $A''$ to $B$. The result is a so called recurrence relation given by the following equation.\n$$\nP_{A \\to B}=P_{A' \\to B} + P_{A'' \\to B}\n$$\nIn general, if we go one step north the first time, then there are $P_{m, n-1}$ paths left from this position to $B$. Similarly, if we go east first, then there are $P_{m-1, n}$\npaths left from this position to $B$. This results in the following relation.\n$$\nP_{m, n}=P_{m,n-1}+P_{m-1, n}\n$$\nGiven the initial conditions $P_{0,n}=P_{m,0}=1$, and $P_{m,1}=m+1$ and $P_{1,n}=n+1$, our final solution can be found quickly.\n$$\nP_{m,n}={m + n \\choose m}={m+n \\choose n}\n$$\n\n\\subsection{Balls in boxes and multisets}\n\nSuppose that we have $k$ balls and $n$ boxes. In how many ways can we put $k$ balls into $n$ boxes? If the maximal capacity of each box is $1$, the answer would be \n$n \\choose k$ if $n \\geq k$ and $0$ otherwise. What happens if there are no restrictions on the capacity of boxes?\n\\\\\nThis question leads us to the definition of a multiset. Let $X$ be a set.\n\n\\begin{defn}\nA multiset is a function $\\mu: X \\to \\mathbb{Z}_{\\geq  0}$. The size of a multiset is $\\sum_{x \\in X} \\mu (x)$.\n\\end{defn}\n\n\\begin{exmp}\nAssume that we have $5$ boxes, that is $X=\\{1, 2, 3, 4 ,5\\}$, and $\\mu(1)=1, \\mu(2)=0, \\mu(3)=3$ and $\\mu(4)=1$. Compare this with figure \\ref{fig:multisetboxesexample}. Notice that box $3$ contains \n$3$ balls. The size of $\\mu$ is $5$.\n\n\\begin{figure}[ht]\n    \\centering\n    \\scalebox{0.4}{\\incfig{multisetboxesexamples3}}\n    \\caption{Balls in boxes and mutlisets.}\n    \\label{fig:multisetboxesexample}\n\\end{figure}\n\\end{exmp}\n\nIt is easy to see that the number of configurations of $k$ balls into $n$ boxes corresponds to the number of multisets of $\\{1,2,\\cdots, n\\}$\nof size $k$. Now, let us interpret our problem in a slightly different way. Imagine $k$ balls and separators (visualized as \"$|$\") that correspond to a box. Then, the above configuration configuration \nlooks as follows.\n$$\n0\\ |\\ \\ |\\ 000\\ |\\ 0\n$$\nFor $4$ boxes, we only need $3$ separators, or in general for $n$ boxes we need $n-1$ separators. Thus, configurations of balls in boxes correspond to configurations of bars and balls.\nIf we consider balls and bars to be objects, then we have $k+n-1$ objects in total.\n\\begin{tikzcd}\n    & k \\text{ balls}  \\\\\nk+n-1 \\arrow[ru] \\arrow[rd] &                  \\\\\n    & n-1 \\text{ bars}\n\\end{tikzcd}\n\nThe above investigations encourage the following theorem.\n\n\\begin{theorem}\n$k$ balls can be put into $n$ boxes in ${n+k-1 \\choose k}$ ways. Equivalently, the number of $k$-element multisets in $\\{1, \\cdots, n\\}$ is ${n+k-1 \\choose k}$.\n\\end{theorem}\n\\noindent\nThe formal proof is left as an exercise for the reader.\n\n\\subsection{Integer compositions}\n\nWe are going to discuss integer compositions in the following section. We start with the formal definition.\n\n\\begin{defn}\nAn integer composition of $n \\in \\mathbb{Z}_{> 0}$ is a presentation of $n$ as  an ordered sum $n=n_1 + n_2 + \\cdots + n_k, n_1,\\cdots,n_k \\in \\mathbb{Z}_{> 0}$.\n\\end{defn}\n\n\\begin{exmp}\nFor $n=1$ there is only one trivial presentation, that is just $1$ itself. For $n=2$ there is one presentation, namely $2=1+1$. For $n=3$ there are $4$ presentations,\n namely $3=2+1=1+2=1+1+1$. Notice that this sums are ordered, thus $1+2$ and $2+1$ are considered to be different.\n For $n=4$ there are $8$ presentations, namely $4=3+1=1+3=2+2=2+1+1=1+2+1=1+1+2=1+1+1+1$.\n\\end{exmp}\n\n\\begin{theorem} The following statements are true.\n\\begin{enumerate}[(i)]\n    \\item The number of compositions of $n$ is $2^{n-1}$.\n    \\item The number of compositions of $n$ with exactly $k$ summands is ${n-1 \\choose k-1}$.\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\nWe start with $(ii)$. The composition of $n$ with exactly $k$ summands corresponds to configurations of $n$ balls \ninside $k$ boxes, s.t. each box is nonempty. This is the same as the number of configurations of $n-k$ balls in $k$ boxes, \nwhich is equal to\n$$\n{n-k+k-1 \\choose k-1} = {n-1 \\choose k-1}.\n$$\nWe continue with $(i)$. The answer is trivial. The total number of compositions follows from the following equation.\n$$\n{n-1 \\choose 0} + {n-1 \\choose 1} + \\cdots + {n-1 \\choose n-1}=2^{n-1}.\n$$\nThis completes the proof.\n\\end{proof}\n\n\\subsection[PIE]{Principle of inclusion and exclusion}\n\nIn the following section we are going to introduce the \"Principle of Inclusion and Exclusion (PIE)\". Let us introduce this topic\nwith an example.\n\n\\begin{exmp}\nSuppose that we have a room full of students. $25$ of them speak spanish, $24$ of them speak french and $8$ of them speak both spanish \nand french. How many students speak at least one foreign language? Denote the set of students speaking spanish by $S$ and the \nset of students speaking french by $F$. Now, consider the following Venn-diagram.\n\\begin{figure}[H]\n    \\centering\n    \\scalebox{0.6}{\\begin{tikzpicture}\n        \\begin{scope}[shift={(3cm,-5cm)}, fill opacity=0.45]\n            \\fill[green] \\secondcircle;\n            \\fill[blue] \\thirdcircle;\n            \\draw \\secondcircle node [above] {$F$};\n            \\draw \\thirdcircle node [below] {$S$};\n        \\end{scope}\n    \\end{tikzpicture}}\n    \\caption{Venn-diagram for two languages.}\n\\end{figure}\n\nThe number of students that speak at least one language is equal to $|S \\cup F|=|S| + |F|-|S \\cap F|=25+24-8=41$. Notice that we must substract their intersection \nor we count the students speaking both french and spanish twice.\\\\\\\\\nNow, suppose that $15$ students speak german, $6$ speak german and spanish, $7$ speak german and french and \n$4$ speak all three languages. Let us denote the set of students who speak german by $G$, the set of students who speak french by $F$ \nand the set of students that speak spanish by $S$. Consider the following Venn-diagram.\n\n\\begin{figure}[H]\n    \\centering\n    \\scalebox{0.6}{\\begin{tikzpicture}\n        \\begin{scope}[shift={(3cm,-5cm)}, fill opacity=0.45]\n            \\fill[red] \\firstcircle;\n            \\fill[green] \\secondcircle;\n            \\fill[blue] \\thirdcircle;\n            \\draw \\firstcircle node[below] {$G$};\n            \\draw \\secondcircle node [above] {$F$};\n            \\draw \\thirdcircle node [below] {$S$};\n        \\end{scope}\n    \\end{tikzpicture}}\n    \\caption{Venn-diagram for three languages.}\n\\end{figure}\nNow the result is very similar to the one before. The number of students that speak at least one language is equal to the following.\n$$\n|G \\cup S \\cup F|=|G| + |F| + |S| - |S \\cap F| - |S \\cap G| - |G \\cap F| + |S \\cap F \\cap G|=25+24+15-8-7-6+4=47.\n$$\n\\end{exmp}\n\nLet us generalize this by the following theorem.\n\n\\begin{theorem}(Principle of inclusion-exclusion)\nLet $A_1\\cdots, A_n$ be finite subsets of a set $X$. Then \n\\begin{align*}\n|A_1 \\cup \\cdots \\cup A_n|&=|A_1|+\\cdots+|A_n|\\\\\n&=\\sum_{1 \\leq i < j \\leq n} |A_i \\cap A_j|+\\sum_{1 \\leq i < j \\leq n} |A_i \\cap A_j \\cap A_k| - \\cdots + (-1)^{n-1}|A_1 \\cap \\cdots \\cap A_n|.\n\\end{align*}\n\\end{theorem}\n\n\\begin{proof}\nLet $x \\in A_1 \\cup \\cdots \\cup A_n$. How many times does $x$ appear on the right-hand-side? Suppose that $x \\in A_1 \\cap \\cdots \\cap A_p$ and \n$x \\notin A_{p+1}, A_{p+2}, \\cdots, A_n$. Then $x$ contributes to the right-hand-side with multiplicity \n$$\np- {p \\choose 2} + {p \\choose 3} - {p \\choose 4} + \\cdots + (-1)^{p-1} {p \\choose p}=1+\\biggl(-1 +p- {p \\choose 2} + {p \\choose 3} - \\cdots + (-1)^{p-1} {p \\choose p} \\biggr )=1.\n$$\n\\end{proof}\n\nThe standard proof of the above is via induction. This is left as an exercise for the reader.\n\n\\subsection{The derangement problem}\n\nIn this section we want to apply the principle of inclusion and exclusion to the so called derangement problem. But first, we note that sometimes it turns out that the \nproblem is symmetric in the following sense that $|A_{i1} \\cap \\cdots \\cap A_{ik}|$ does not depend on $A_{i1}, \\cdots, A_{ik}$, but only on $k$, that is $A^k=|A_{i1} \\cap \\cdots \\cap A_{ik}|$. \nThen, \n$$\n|A_1 \\cup \\cdots \\cup A_n|=n \\cdot A - {n \\choose 2} A^2 + {n \\choose 3} A^3 - \\cdots + (-1)^{n-1} A^n.\n$$\n\nNow, suppose that $n$ people leave their coats in the coatroom, each of them get back a random coat. \nWhat is the probability that everyone will get someone else's coat? Recall that the total number of permutations \n(that is the total number of configurations of coats) is given by $n!$. We might ask: How many permutations have \nnot fixed points, i.e. never map a number into itself?\\\\\n\\\\\nWe compute the number of permutations with fixed points. Define \n$$\nA_i=\\{\\text{permutations  bringing }i \\text{ to } i\\}\n$$ \nand \n$$\nA_{i1} \\cap \\cdots \\cap A_{ik}=\\{\\text{permutations bringing } i_1 \\mapsto i_i, \\cdots, i_k \\mapsto i_k\\}.\n$$\nThen, $|A_i|=(n-1)!$ and $|A_{i1} \\cap \\cdots \\cap A_{ik}|=A^k=(n-k)!$, hence\n\\begin{align*}\n|A_1 \\cup \\cdots \\cup A_n|&=n(n-1)!- {n \\choose 2} (n-2)! + \\cdots + (-1)^{n-1} \\cdot 0!\\\\\n&=\nn! - \\frac{n!}{2!}+ \\frac{n!}{3!} - \\cdots + \\frac{(-1)^{n-1}n!}{n!}\n\\end{align*}\nIt follows that\n$$\nn! - |A_1 \\cup \\cdots \\cup A_k|=n!\\biggr(1-1 + \\frac{1}{2!}- \\frac{1}{3!}+ \\cdots + \\frac{(-1)^n}{n!}\\biggl)\n$$\n\nThus, the desired probability follows from the following equations.\n\\begin{align*}\np(n)&=1-1+\\frac{1}{2!}-\\frac{1}{3!}+\\cdots + \\frac{(-1)^n}{n!}\\\\\ne^x&=1+x+\\frac{x^2}{2!}+\\frac{x^3}{3!}+ \\cdots + \\frac{x^n}{n!} + \\cdots\\\\\n&\\implies \\lim_{n \\to \\infty} p(n)=1-1+\\frac{1}{2!}-\\frac{1}{3!}+ \\cdots = e^{-1}=\\frac{1}{e}\n\\end{align*}\nwhere $e=2.71828 \\cdots$, thus $\\frac{1}{e} \\approx 0.37$.\n\\subsection{Exercises}\n\n\\begin{enumerate}\n    \\item Find the number of lattice paths from $(-2, -2)$ to $(3,3)$ passing through the point $(0,0)$ (each segment of a path goes north or east).\n    \\item In how many ways is it possible to permute the letters in the word \\textit{EUCLID} in such a way that the order of the vowels (\\textit{E,U,I}) is unchanged?\n    \\item Find the number of merry-go-rounds formed by $10$ carriages of two different colours.\n    \\item Find the number of positive integers not exceeding $300$ and \\textbf{not} divisible by any of $2,3,$ and $5$.\n\\end{enumerate}", "meta": {"hexsha": "6f5871581ac5628157e4dc773aa6cc5af7b8899a", "size": 11981, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/permutationsBionmialCoefficient.tex", "max_stars_repo_name": "pgrepds/Enumerative-Combinatorics", "max_stars_repo_head_hexsha": "ee8fbf2789cc1d17474d8ccbdd9a860788aa54ca", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/permutationsBionmialCoefficient.tex", "max_issues_repo_name": "pgrepds/Enumerative-Combinatorics", "max_issues_repo_head_hexsha": "ee8fbf2789cc1d17474d8ccbdd9a860788aa54ca", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/permutationsBionmialCoefficient.tex", "max_forks_repo_name": "pgrepds/Enumerative-Combinatorics", "max_forks_repo_head_hexsha": "ee8fbf2789cc1d17474d8ccbdd9a860788aa54ca", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.129707113, "max_line_length": 201, "alphanum_fraction": 0.6772389617, "num_tokens": 3922, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961427, "lm_q2_score": 0.8933094081846421, "lm_q1q2_score": 0.7463453113965038}}
{"text": "\\section{Subgradients}\n\\frame{\\tableofcontents[currentsection, hideothersubsections]}\n\n\\begin{frame}\n\\frametitle{Subgradients: Intro}\n\nWHAT:\\\\\napply GD to \\textbf{non}differentiable convex function\n\\vspace{5mm}\n\nHOW:\\\\\nuse subgradient of $f(\\mathbf{w})$ at $\\mathbf{w}^{(t)}$, instead of the gradient;\\\\\n(the analysis of the convergence rate remains unchanged)\n\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Subgradients: Intro}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.225]{lemma_14_3}\n\\end{figure}\n\n\\noindent\\makebox[\\linewidth]{\\rule{\\paperwidth}{0.4pt}}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.225]{def_14_4}\n\\end{figure}\n\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Subgradients: Intro}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.25]{fig_14_2}\n\\end{figure}\n\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Subgradients: Calculating Subgradients}\n\nHow do we construct subgradients of a given convex function?\n\\vspace{5mm}\n\nFor pointwise maximum functions:\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.225]{claim_14_6}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.225]{example_14_2}\n\\end{figure}\n\n\\end{frame}\n", "meta": {"hexsha": "5093fa1d3e74d6da5eb91af0222e076513a02974", "size": 1189, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "talk/tor/cvx-sgd-20180316/subgradient.tex", "max_stars_repo_name": "tttor/robot-foundation", "max_stars_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "talk/tor/cvx-sgd-20180316/subgradient.tex", "max_issues_repo_name": "tttor/robot-foundation", "max_issues_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "talk/tor/cvx-sgd-20180316/subgradient.tex", "max_forks_repo_name": "tttor/robot-foundation", "max_forks_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.1774193548, "max_line_length": 84, "alphanum_fraction": 0.7359125315, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7463452873166913}}
{"text": "\\section*{Related Work \\& Background}\n\n\\subsection*{Static Scene Reconstruction}\n\nStatic scene reconstruction is the problem of reconstructing a 3D model from a set of 2D views.\nNeural Radiance Fields (NeRFs)~\\cite{mildenhall2020nerf} are a recent technique for reconstructing new views of a scene from new camera positions. To represent highly-detailed scenes, NeRFs model a scene as a continuous volume of varying density, which emits different colored light depending on the view direction. This is based on traditional volume rendering techniques:\n\\[ I(r) = \\int_{t_n}^{t_f} T(t, r) \\sigma(r(t)) c(r(t), r_d)dt, \\]\nwhere \n\\[ T(t, r) = \\exp(-\\int_{t_n}^{t} \\sigma(r(s))ds), \\]\n\\noindent\nwhere $I(r)$ is the illumination along camera ray $r(t) = r_o + r_d t$, $r_o, r_d$ are the ray origin and direction respectively, and $t$ is some positive distance along the ray. NeRFs are able to accurately reconstruct high-frequency features by recovering $\\sigma$, the density at a given point, and $c$, the view-dependent color at a given point by modelling them as MLPs with an additional encoding scheme that can differentiate between extremely close points. NeRFs evaluate the above equations by performing ray-marching and computing $T(j,r) = \\Sigma -\\exp\\sigma_i c_i$, by partitioning the ray into evenly spaced bins and sampling randomly from within each bin.\n\nThere have been a significant number of extensions to NeRF, including optimizations on the encoding for differentiating positions in space~\\cite{tancik2020fourfeat}, better sampling approaches~\\cite{barron2021mipnerf}, and faster training~\\cite{yu2021plenoxels}.\n\n\\subsection*{Dynamic Scene Reconstruction}\n\nDynamic scene reconstruction is removing the assumption in static scene reconstruction that all views are under the same condition, such as the same lighting and that nothing has moved.\nNeRFs were designed to only handle static scenes, and thus cannot accurately reconstruct scenes which contain movement, alternative lighting conditions, or other changes between frames.\nIn order to model dynamic scenes, there have been two diverging approaches.\n\nOne kind of approach directly models the transformation in the time domain, by learning a function $\\sigma(x,t)=f(x\\in\\mathbb{R}^3, t\\in[0,1])$, which include works such as HyperNeRF~\\cite{park2021hypernerf}, NeRFies~\\cite{park2021nerfies}, and Space-Time Invariant Irradiance Fields~\\cite{xian2021space}. By directly modelling the variation of the density, these methods are able to reconstruct large deformations in latent spaces and reconstruct a wide variety of transformations from a single radiance field. These often allow for fun transformations in some learned space between many similar scenes, which allow novelty warping and interpolation.\n\nThe other kind of approach models movement directly as translation. NeRFs are not able to move the objects inside the scene since we can only evaluate the NeRF at a given $x$. Instead we bend the rays, warping what is visible from a given view. This is essentially a perspective shift of a transformation of the space being rendered. Instead of moving an object that is seen by ray $r$, we warp ray $r$ such that it is sees the object. The equation for density is defined as $\\sigma(x,t)=f(x+\\Delta(x,t))$. This formulation enforces a coherent canonical representation, while directly modelling movement, and has been shown to be able to reconstruct both synthetic scenes with D-NeRF~\\cite{pumarola2020dnerf} and real scenes in NR-NeRF~\\cite{tretschk2021nonrigid}.\n\nThe pros of directly including time as a function in the MLP are that we are able to represent a much broader class of functions, in theory every frame may be fully distinct from the previous, but the canonical formulation lends itself to smoothness between frames. Our approach falls into the canonization category, since we are interested in accurately reconstructing smooth movement as opposed to generalizing over many classes of movement.\n\n\n\\subsection*{Bezier Curves}\n\nBezier curves refer to a specific set of polynomials parametrized by a set of control points. They are most commonly used as cubic polynomials: $f(x) = ax^3 + bx^2 + cx + d$,\nwhere $x$ is the variable we are interested in interpolating over. An example of a Bezier Spline is shown in Figure~\\ref{fig:bezier_diagram}. The general formulation for\nthe Bezier basis functions is defined as $B^n(t) = \\Sigma^n_{i=0}\n{n \\choose i} (1-t)^{n-i} t^i$ where $n$\nis the degree of the Bezier polynomial. In order to give control of the Bezier curve, we\nintroduce \"control points\", which weigh different points along the curve differently:\n$B^n(t) = \\Sigma^n_{i=0} P_i {n \\choose i} (1-t)^{n-i} t^i$, where $P_i\\in\\mathbb{R}^3$ for 3D\nmovement. For a more comprehensive guide on Bezier splines, we refer the reader to a more\n\\href{https://pomax.github.io/bezierinfo/index.html}{complete reference}~\\cite{bezier_primer}.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{bezier_curve.png}\n    \\caption{\n        Bezier Curves are a low-dimensional polynomial representation that allows for smooth interpolation between a few control points. We reconstruct control points to produce smooth movement and induce a prior on continuity. Credit to Wikipedia~\\cite{bezier_diagram} for diagram.\n    }\n    \\label{fig:bezier_diagram}\n\\end{figure}\n\n", "meta": {"hexsha": "6d0c7497432da270c5d2a23073e82497a897ac2d", "size": 5358, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "c0_paper/background.tex", "max_stars_repo_name": "JulianKnodt/nerf_atlas", "max_stars_repo_head_hexsha": "6866713c498cea026cb215260a779a2c6c13246c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 57, "max_stars_repo_stars_event_min_datetime": "2021-05-25T12:57:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:27:44.000Z", "max_issues_repo_path": "c0_paper/background.tex", "max_issues_repo_name": "JulianKnodt/nerf_atlas", "max_issues_repo_head_hexsha": "6866713c498cea026cb215260a779a2c6c13246c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2021-07-26T22:28:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-29T20:51:59.000Z", "max_forks_repo_path": "c0_paper/background.tex", "max_forks_repo_name": "JulianKnodt/nerf_atlas", "max_forks_repo_head_hexsha": "6866713c498cea026cb215260a779a2c6c13246c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2021-05-25T12:36:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-28T04:20:12.000Z", "avg_line_length": 109.3469387755, "max_line_length": 764, "alphanum_fraction": 0.7842478537, "num_tokens": 1298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7462600964587689}}
{"text": "\n\\subsection{Scripts}\nScripting is a way of automatically running a sequence of calculations.\nA script is entered in the left-hand field of the Eigenmath window.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,0) {\\includegraphics[scale=0.2]{face.png}};\n\\draw (-2.4,0.1) node {Scripts go here.};\n\\end{tikzpicture}\n\\end{center}\n\nTo create a script, enter one calculation per line in the script field.\nNothing happens until the Run button is clicked. When the Run button is\nclicked, Eigenmath evaluates the script line by line. After a script runs,\nall of its symbols are available for immediate mode calculation.\nScripts can be saved and loaded using the File menu.\n\nHere is an example script that can be pasted into the script field\nand then run by clicking the Run button.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\n\"Solve for vector X in AX = B\"\nA = ((1,2),(3,4))\nB = (5,6)\nX = dot(inv(A),B)\nX\n\\end{Verbatim}\n\nAfter clicking the Run button, the following result is displayed.\n\n\\verb$Solve for vector X in AX = B$\n\n$\\displaystyle X=\\begin{bmatrix}-4\\\\ \\frac{9}{2}\\end{bmatrix}$\n\nA handy debugging aid is to include the line $trace=1$ in the script.\nWhen $trace=1$ each line of the script is displayed as it is evaluated.\nFor example, here is the previous script with the addition of\n$trace=1$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n\"Solve for vector X in AX = B\"\ntrace = 1\nA = ((1,2),(3,4))\nB = (5,6)\nX = dot(inv(A),B)\nX\n\\end{Verbatim}\n\nThe result is\n\n\\begin{Verbatim}\nSolve for vector X in AX = B\nA = ((1,2),(3,4))\nB = (5,6)\nX = dot(inv(A),B)\nX\n\\end{Verbatim}\n\n$X=\\begin{bmatrix}-4\\\\ \\frac{9}{2}\\end{bmatrix}$\n", "meta": {"hexsha": "a43f44dadc731175775b71627532913b73987da9", "size": 1629, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/scripting.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/scripting.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/scripting.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.7049180328, "max_line_length": 74, "alphanum_fraction": 0.7151626765, "num_tokens": 496, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.7461291935700294}}
{"text": "\\subsection{lag compensation}\n$$\nG_c(s) = K_c\\dfrac{s + \\dfrac{1}{T}}{s+\\dfrac{1}{\\beta T}}, \\quad \\beta > 1\n$$\nIn lag compensation we find out $K$ for steady state error.\n$$K = 5.1300$$\n$$\\gamma_d = 45^{\\circ} \\to \\bar{\\gamma_d} = 45 + 5 = 50^\\circ$$\n$$\n\\phi(\\omega_g) = 50 - 180 = -130^{\\circ}\n$$\nThe phase angle:\n\n$$\n\\angle G(j\\omega) = 0^{\\circ} + \\tan^{-1}\\dfrac{\\omega}{0.5} - \\tan^{-1}\\dfrac{\\omega}{1} - 3\\tan^{-1}\\dfrac{\\omega}{1.5} - \\tan^{-1}\\dfrac{\\omega}{2}\n$$\n$$\n\\angle G(j\\omega_g) = \n0^{\\circ} + \\tan^{-1}\\dfrac{\\omega_g}{0.5} - \\tan^{-1}\\dfrac{\\omega_g}{1} - 3\\tan^{-1}\\dfrac{\\omega_g}{1.5} - \\tan^{-1}\\dfrac{\\omega_g}{2} = -130^{\\circ}\n$$\nThis equation solved with MATLAB and code has attacked (Q1\\_b.m)\n$$\n\\omega_g =  1.2025\n$$\nThe amplitude ratio:\n$$\n\\left\\vert G_1(j\\omega) \\right\\vert = \\left\\vert KG(j\\omega) \\right\\vert = 5.1300\\dfrac{50\\sqrt{\\omega^2+0.5^2}}{\\sqrt{\\omega^2+1^2}\\times(\\sqrt{\\omega^2 + 1.5^2})^3\\times\\sqrt{\\omega^2 + 2^2}}\n$$\n$$\n\\beta = \\left\\vert G_1(j\\omega_g) \\right\\vert = \n5.1300\\dfrac{50\\sqrt{\\omega_g^2+0.5^2}}{\\sqrt{\\omega_g^2+1^2}\\times(\\sqrt{\\omega_g^2 + 1.5^2})^3\\times\\sqrt{\\omega_g^2 + 2^2}}\n$$\n\n$$\n\\beta = 5.1300\\dfrac{50\\sqrt{1.2025^2+0.5^2}}{\\sqrt{1.2025^2+1^2}\\times(\\sqrt{1.2025^2 + 1.5^2})^3\\times\\sqrt{1.2025^2 + 2^2}} = 12.8807\n$$\nAssume:\n$$\n\\dfrac{1}{T} = \\dfrac{\\omega_g}{2} \n\\to \\dfrac{1}{T}  = 0.6012 \\to T = 1.6632\n$$\n$$\n\\to \\dfrac{1}{\\beta T} = 0.0467, \\quad K_c = \\dfrac{K}{\\beta} = \\dfrac{5.1300}{12.8807} = 0.3983\n$$\n$$\nG_c(s) = K_c \\dfrac{s + \\dfrac{1}{T}}{s + \\dfrac{1}{\\beta T}}\n= 0.3983 \\dfrac{s + 0.6012}{s + 0.0467}\n$$\nBode diagram for lag compensation using MATLAB.\n\\begin{figure}[H]\n\t\\caption{lag compensation Bode diagram using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/b/controller.png}\n\\end{figure}\nNyquist plot for lag compensation using MATLAB.\n\\begin{figure}[H]\n\t\\caption{lag compensation Nyquist plot using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/b/controller_nyquist.png}\n\\end{figure}\n\nNow add lag compensation to system.\n$$\nG_c(s)G(s) = 0.3983 \\dfrac{s + 0.6012}{s + 0.0467}\\dfrac{50(s+0.5)}{(s+1)(s+1.5)^{3}(s+2)}\n$$\nBode diagram for system with adding lag compensation.\n\\begin{figure}[H]\n\t\\caption{Bode diagram for system with lag compensation using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/b/new_margin.png}\n\\end{figure}\nNyquist plot for system with adding lag compensation.\n\\begin{figure}[H]\n\t\\caption{Nyquist plot for system with lag compensation using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/b/new_nyquist.png}\n\\end{figure}\nAll bode diagram in one figure:\n\\begin{figure}[H]\n\t\\caption{all bode diagram using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/b/all_in_one.png}\n\\end{figure}\nAll Nyquist plot in one figure:\n\\begin{figure}[H]\n\t\\caption{all Nyquist plot using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/b/all_in_one_nyquist.png}\n\\end{figure}\nWe didn't get what we want in equation so we change our before assumption.\nassume:\n$$\n\\dfrac{1}{T} = \\dfrac{\\omega_g}{10} \n\\to \\dfrac{1}{T}  = 0.1202 \\to T = 8.3161\n$$\n$$\n\\to \\dfrac{1}{\\beta T} = 0.0093, \\quad K_c = \\dfrac{K}{\\beta} = \\dfrac{5.1300}{12.8807} = 0.3983\n$$\n$$\nG_c(s) = K_c \\dfrac{s + \\dfrac{1}{T}}{s + \\dfrac{1}{\\beta T}}\n= 0.3983 \\dfrac{s + 0.1202}{s + 0.0093}\n$$\nBode diagram for lag compensation using MATLAB.\n\\begin{figure}[H]\n\t\\caption{new lag compensation Bode diagram using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/b/new_controller.png}\n\\end{figure}\nNyquist plot for lag compensation using MATLAB.\n\\begin{figure}[H]\n\t\\caption{new lag compensation Nyquist plot using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/b/new_controller_nyquist.png}\n\\end{figure}\nNow add new lag compensation to system.\n$$\nG_c(s)G(s) = 0.3983 \\dfrac{s + 0.1202}{s + 0.0093}\\dfrac{50(s+0.5)}{(s+1)(s+1.5)^{3}(s+2)}\n$$\nBode diagram for system with adding lag compensation.\n\\begin{figure}[H]\n\t\\caption{Bode diagram for system with new lag compensation using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/b/new2_margin.png}\n\\end{figure}\nNyquist plot for system with adding lag compensation.\n\\begin{figure}[H]\n\t\\caption{Nyquist plot for system with new lag compensation using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/b/new2_nyquist.png}\n\\end{figure}\nAll bode diagram in one figure:\n\\begin{figure}[H]\n\t\\caption{all bode diagram using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/b/new_all_in_one.png}\n\\end{figure}\nAll Nyquist plot in one figure:\n\\begin{figure}[H]\n\t\\caption{all Nyquist plot using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/b/new_all_in_one_nyquist.png}\n\\end{figure}\nIn new lag compensation phase margin is $45.3^{\\circ}$ and we are near to question requirement.\nStep respond for close loop system.\n\\begin{figure}[H]\n\t\\caption{Step respond with lag compensation}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/b/step.png}\n\\end{figure}", "meta": {"hexsha": "4526f908f2f4b07ddd754d946152fbbcc5e30401", "size": 5034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW II/Report/Q1/b/b.tex", "max_stars_repo_name": "alibaniasad1999/Principle-Of-Controller-Design", "max_stars_repo_head_hexsha": "2a6285f627377a5e5edfb32c92e054ab213d311a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW/HW II/Report/Q1/b/b.tex", "max_issues_repo_name": "alibaniasad1999/Principle-Of-Controller-Design", "max_issues_repo_head_hexsha": "2a6285f627377a5e5edfb32c92e054ab213d311a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW/HW II/Report/Q1/b/b.tex", "max_forks_repo_name": "alibaniasad1999/Principle-Of-Controller-Design", "max_forks_repo_head_hexsha": "2a6285f627377a5e5edfb32c92e054ab213d311a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.0135135135, "max_line_length": 193, "alphanum_fraction": 0.6853396901, "num_tokens": 1909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7461291919240124}}
{"text": "\\chapter{Randomized Algorithms in Numerical Linear Algebra}\n\n%------------------------------------------------------------------------------------------------------\n\\section{Least Squares Problems}\nConsider the linear system\n\\begin{equation}\\label{AXB}\nA x =b ,\n\\end{equation}\nwhere $A \\in \\mathbb{R}^{m \\times n}, b \\in \\mathbb{R}^{m}, m \\gg n, $  and $rank(A) = n$.\nSystem (\\ref{AXB}) has the least squares solution\n\\begin{equation}\\label{OPT}\nx_{opt} = argmin_{x} \\| Ax -b\\|_2^2 .\n\\end{equation}\n$x_{opt}$ is also the solution of the normal equation\n\\begin{equation}\\label{NOR}\nA^T A x = A^T b.\n\\end{equation}\nSuppose $\\bold{y} = (y_1,\\cdots,y_n)'$  is the response or target variable.\n\n$$\\bold{X} = \\begin{bmatrix} x_{11} ,&\\cdots,& x_{1p}\\\\\n                                                \\cdots,&\\cdots,&\\cdots \\\\\n                                                x_{n1},&\\cdots,&x_{np} \\end{bmatrix}\n                 = (\\bold{x_1},\\cdots,\\bold{x_p})$$\nis the $n \\times p$ data matrix of the $n$ observations on the $p$ variables.\n\nThe linear regression is to find the parameter $\\bold{\\beta}$ for a 'best' prediction of $\\bold{y}$, which is to minimize the 2 norm of error\n$$\\| \\bold{y} - \\bold{X} \\bold{\\beta} \\|_2^2.$$\n\nThe least squares estimator $\\beta_{opt}$ is given by\n$$\n\\beta_{opt} = (\\bold{X}^T \\bold{X})^{-1} \\bold{X}^T \\bold{y}.\n$$\n%-----------------------------------------------------------------------------------------------------------------\n\\section{Traditional Methods}\n%------------------------------------------------\n\n\n\\subsection{QR Decomposition}\n\nCompute\n$$A = QR,$$\nwhere $Q$ is an orthogonal matrix and $R$ is an upper triangular matrix.\n\n \\begin{figure}[htbp]\n    \\includegraphics[width=1\\textwidth]{qrd}\n    \\caption{QR Decomposition}\n\\end{figure}\n\nComplexity of QR decomposition is {\\color{red} $O(mn^2)$}.\n\n\n\n%------------------------------------------------\n\\subsection{SVD Decomposition}\n\nCompute\n$$\nA = U \\Sigma V^T,\n$$\nwhere\n\\begin{itemize}\n\\item $U$ is a $m \\times m $ orthogonal matrix \\\\\n\\item $\\Sigma$ is a diagonal $m \\times n$ matrix with non-negative real numbers on the diagonal and \\\\\n\\item $V$ is a $n \\times n $ orthogonal matrix.\n\\end{itemize}\nThe diagonal entries are $\\sigma_i$ of $\\Sigma$ are known as the singular values of $A$. \\\\\n \\begin{figure}[htbp]\n    \\includegraphics[width=1\\textwidth]{svd2}\n\\end{figure}\nComplexity of SVD decomposition is {\\color{red} $O(mn^2)$}.\n\n\n%------------------------------------------------\n\n\n\n\\subsection{Conjugate Gradient Method}\n\nApply the conjugate gradient method to the normal equation (\\ref{NOR})\n$$\nA^T A x = A^T b.\n$$\nComplexity:\n\\begin{itemize}\n\\item The computation cost at each step is  $O(mn)$  for $A^T(Ax)$. \\\\\n\\item To achieve accuracy $\\epsilon$, we need $ k = log_{\\frac{\\sqrt{\\kappa(A^T A)} -1}{\\sqrt{\\kappa(A^T A)} +1}} \\frac{\\epsilon}{2} \\approx 2 |log(\\epsilon)|\\kappa(A)$ steps. \\\\\n\\item The total complexity is\n{\\color{red}\n$$\nO(m n \\kappa(A) |log(\\epsilon)|).\n$$\n}\n\\end{itemize}\n\n%------------------------------------------------\n\n\\subsection{Kaczmarz Method}\n\n\nDenote the rows and columns of $A$ by $A^{(1)}, \\cdots, A^{(m)}$ and $A_{(1)},\\cdots,A_{(n)},$ respectively (both viewed as columns vectors). The Kaczmarz Scheme is given by\n\\begin{tcolorbox}\nprocedure $(A,b,T)$ \\\\\n\\quad Set\\quad $ x^{(0)} $ \\quad to by any vector in the row space of $A$\\\\\n\\quad for $k = 0,1,2,\\cdots, T-1$ do \\\\\n\\quad \\quad $ik \\equiv k \\Mod{m}$ \\\\\n\\quad \\quad Set $x^{(k+1)} = \\mathcal{P}_{A^{(ik)},b_{ik}}(x^{(k)}) $\\\\\n\\quad end for \\\\\n\\quad Output $x^{(T)}$  \\\\\nend procedure\n\\end{tcolorbox}\n\n\n\\subsubsection{Orthogonal Projection}\nWe define the orthogonal projection of $\\mathbf{x}$ onto the hyperplane by \\quad $\\mathbf{c}^T \\mathbf{x} = d$:\n$$\n\\mathcal{P}_{\\mathbf{c},d}(\\mathbf{x}) = \\mathbf{x} - \\frac{\\mathbf{c}}{\\| \\mathbf{c} \\|_2} (\\mathbf{c} ^T \\mathbf{x} - d).\n$$\nThe operator does an orthogonal projection of the current estimate vector $\\mathbf{x}$ onto the hyperplane $\\mathbf{c}^T \\mathbf{x} =d$.\n\\begin{figure}[htbp]\n    \\includegraphics[width=\\textwidth]{kaczmarz-method1.png}\n    \\caption{Kaczmarz Method}\n    \\label{fig:kaczmarz method}\n\\end{figure}\n\n\\subsubsection{Convergence Analysis and Complexity}\n\\begin{theorem}\nThe cylic Kaczmarz iteration with approriately chosen relaxation parameter $\\omega$ and row scaling induced by $D$ for solving a linear system $Ax = b$ with $rank(A) = r \\leq min(m,n)$ possesses an error bound\n$$\n\\| x^{(k)} - x_{LS} \\|_2^2 \\leq \\left[ 1 - \\frac{C}{(ln(r)+1) \\kappa(A^T D^{-1} A)}\\right] ^k \\| x^{(0)} - x_{LS} \\|_2^2, \\quad k \\geq 1,\n$$\nwhere $C$ is an absolute constant.\n\\end{theorem}\n\nThe complexity of kaczmarz method is computed by the following steps.\n\\begin{itemize}\n\\item The complexity at each projection is {\\color{red} $O(n)$}.\n\\item To achieve accuracy $\\epsilon$, we need\n$$\\| x^{(k)} - x_{LS} \\|_2^2 \\leq \\epsilon^2 \\| x^{(0)} - x_{LS} \\|_2^2.$$\n\\item The expected number of iterations $k_{\\epsilon}$ to achieve the accuracy $\\epsilon$ is\n{\\color{red}$$  k_{\\epsilon} \\approx O ((ln(r)+1) \\kappa(A^TD^{-1}A) | log(\\epsilon)| ). $$}\n\\item The complexity of  Kaczmarz method is thus\n{\\color{red}\n$$  O (n (ln(r)+1) \\kappa(A^TD^{-1}A) | log(\\epsilon)| ). $$}\n\\item The complexity of CG applied to normal equation is\n{\\color{red}\n$$\nO(m n \\kappa(A) |log(\\epsilon)|).\n$$\n}\n\\end{itemize}\n\n%------------------------------------------------\n\\section{Randomized Algorithms}\n\\subsection{Sampling based randomized algorithm (SRA)}\nThe sampling based randomized algorithm (SRA) and projection based randomized algorithm (PRA) are from the paper \\cite{FLSA2011}.\n\n%------------------------------------------------\nInstead of solving the original problem is\n\\begin{equation}\\label{ORG}\n\\mathcal{Z} = min_{x \\in \\mathbb{R}^n} \\| Ax - b\\|_2\n\\quad \\text{with solution} \\quad\nx_{opt} = (A^T A)^{-1} A^T b = A^{\\dagger} b,\n\\end{equation}\nactually we solve\n\\begin{equation}\\label{ACT}\n\\tilde{\\mathcal{Z}} = min_{x \\in \\mathbb{R}^n} \\| X Ax - X b\\|_2\n\\quad \\text{with solution} \\quad\n\\tilde{x}_{opt} = (XA)^{\\dagger} X b.\n\\end{equation}\n\n%------------------------------------------------\n\\subsubsection{Theory}\n\\begin{lemma}[Drineas, Mahoney, Muthukrishnan and Sarlos(2011)]\nConsider the overconstrained least squares problem of (\\ref{ORG}) and let the matrix $U_A \\in \\mathbb{R}^{m\\times n}$ contain the top $n$ left singular vectors of $A$. Assume $X$ satisfies the two conditions\n\\begin{enumerate}\n\\item $\\sigma_{min}^2(X U_A) \\geq 1/\\sqrt{2}; $ \\\\\n\\item $\\| U_A^T X^T X b^{\\perp}\\|_2^2 \\leq \\epsilon \\mathcal{Z}^2 /2, \\quad (b^{\\perp} = b - A A^T b), $\n\\end{enumerate}\nfor some $\\epsilon \\in (0,1).$\n\nThen the solution $\\tilde{x}_{opt}$ to the least squares approximation problem (\\ref{ACT}) satisfies:\n\\begin{enumerate}\n\\item $\\| A \\tilde{x}_{opt} - b\\|_2 \\leq (1+ \\epsilon) \\mathcal{Z} $ , and \\\\\n\\item $\\| x_{opt} - \\tilde{x}_{opt} \\|_2 \\leq \\frac{1}{\\sigma_{min}(A)} \\sqrt{\\epsilon} \\mathcal{Z}. $\n\\end{enumerate}\n\\end{lemma}\n\n%------------------------------------------------\n\\subsubsection{Implementation: A sampling-based randomized algorithm}\nA sampling-based randomized algorithm (SRA) is to construct\n$$\nX = S^T H D,\n$$\n\n\\begin{itemize}\n\\item $S \\in \\mathbb{R}^{r \\times m}$ is the uniform sampling matrix, where $S_{r} = (\\sqrt{m/r}) e_{ir},$ where $ir$ is uniformly chosen from $[m],$\nand $e_{ir}$ is the standard basis. \\\\\n\\item $H \\in \\mathbb{R}^{m \\times m}$ is the Hadamard transform matrix defined recursively by\n$$\nH_m = \\begin{bmatrix} H_{m/2} & H_{m/2} \\\\ H_{m/2} & -H_{m/2} \\end{bmatrix}, \\quad \\text{with} \\quad H_2 = \\begin{bmatrix} +1 & +1 \\\\ +1 & -1 \\end{bmatrix}.\n$$\\\\\n\\item $D \\in \\mathbb{R}^{m \\times m}$ is the diagonal matrix with\n$$\nD_{ii} = \\begin{cases} &+1, \\quad \\text{with probability} \\quad 1/2;\\\\ &-1 \\quad \\text{with probability} \\quad 1/2. \\end{cases}\n$$\n\\end{itemize}\n\n$$\n\\tilde{x}_{opt} = (S^T H D A)^{\\dagger} S^T H D b.\n$$\n\n%------------------------------------------------\n\\subsubsection{Effect of the Randomized Hadamard Transform}\n{\\color{red} HD approximately 'uniformizes' information in the left singular subspace of the matrix $A$.}\n\\begin{lemma}\nLet $U$ be an $m \\times n$ orthogonal matrix and let the product $HD$ be the $m \\times m$ Randomized Hadamard Transform. Then with probability at least $0.95$,\n$$\n\\| (HDU)_{i} \\|_2^2 \\leq \\frac{2n \\ln(40 m n)}{m}, \\quad \\forall i \\in [m].\n$$\n\\end{lemma}\n\n%------------------------------------------------\n\n\n\\begin{theorem}[Convergence and Complexity of SRA]\nSuppose $A,b$ and $\\epsilon$ satisfy the input requirement of SRA. Run SRA with\n\\begin{equation}\\label{eq22}\nr = max \\left( 48^2 n \\ln(40 mn) \\ln(100^2 n \\ln(40 mn)) , 40n \\ln(40 mn) /\\epsilon \\right)\n\\approx O(n/\\epsilon).\n\\end{equation}\nand return $\\tilde{x}_{opt}.$ Then, with probability at least $0.8$, the following claims hold:\n\\begin{enumerate}\n\\item $\\tilde{x}_{opt}$ satisfies $\\| A \\tilde{x}_{opt} - b \\|_2  \\leq (1 + \\epsilon) \\mathcal{Z}; $ \\\\\n\\item If we assume that $\\| U_A  U_A^T b \\|_2 \\geq \\gamma \\|b\\|_2 $ for some $0< \\gamma \\leq 1$ then\n$$\n\\| x_{opt} - \\tilde{x}_{opt}\\|_2 \\leq \\sqrt{\\epsilon} \\left( \\kappa(A) \\sqrt{\\gamma^{-2} -1} \\right) \\| x_{opt}\\|_2.\n$$\\\\\n\\item $m(n+1) + 2m(n+1)log_2(r+1) + O(rn^2)$ time suffices to compute the solution $\\tilde{x}_{opt}. $\n\\end{enumerate}\n\\end{theorem}\nThe cost is reduced since $XA \\in \\mathbb{R}^{r \\times n}$ while $A \\in \\mathbb{R}^{m \\times n}.$\n\n\n%------------------------------------------------\n\\subsubsection{Projection Based Randomized Algorithm (PRA)}\nImplementation: A projection-based randomized algorithm\nProjection-based randomized algorithm (PRA) is to construct a smaller problem by performing a 'sparse projection' on the pre-processed problem.\n$$\nX = THD,\n$$\nwhere\n\\begin{itemize}\n\\item $H \\in \\mathbb{R}^{m \\times m}$ is the Hadamard Transform and $D \\in \\mathbb{R}^{m \\times m }$ is the randomized diagonal matrix as defined before. \\\\\n\\item $T \\in \\mathbb{R}^{k \\times m}$ is a randomized matrix given by\n$$\nT_{ij} = \\begin{cases} &+ \\sqrt{1/kq} \\quad \\text{with probability} \\quad q/2, \\\\\n                                   &-  \\sqrt{1/kq} \\quad \\text{with probability} \\quad q/2, \\\\\n                                   & 0 \\quad \\text{with probability} \\quad 1-q.\n             \\end{cases}\n$$\n\\end{itemize}\n$$\\tilde{x}_{opt} = (THDA)^{\\dagger} THDb. $$\n\n%------------------------------------------------\n\n\\begin{theorem}[Convergence and Complexity of PRA]\nSuppose $A,b$ and $\\epsilon$ satisfy the input requirement of FRA. Run FRA with\n\\begin{equation}\nq \\geq \\frac{C_q n \\ln(40mn)}{m} (2 \\ln(m) + 16n + 16);\n\\end{equation}\n\\begin{equation}\nk \\geq max \\left( C_k (118^2 n + 98^2), \\frac{60n}{\\epsilon} \\right)\n\\end{equation}\nand return $\\tilde{x}_{opt}.$ Then, with probability at least $0.8$, the following claims hold:\n\\begin{enumerate}\n\\item $\\tilde{x}_{opt}$ satisfies $\\| A \\tilde{x}_{opt} - b \\|_2  \\leq (1 + \\epsilon) \\mathcal{Z}; $ \\\\\n\\item If we assume that $\\| U_A  U_A^T b \\|_2 \\geq \\gamma \\|b\\|_2 $ for some $0< \\gamma \\leq 1$ then\n$$\n\\| x_{opt} - \\tilde{x}_{opt}\\|_2 \\leq \\sqrt{\\epsilon} \\left( \\kappa(A) \\sqrt{\\gamma^{-2} -1} \\right) \\| x_{opt}\\|_2.\n$$\\\\\n\\item $m(n+1) + 2m(n+1)log_2(mkq+1) + O(kn^2)$ time suffices to compute the solution $\\tilde{x}_{opt}. $\n\\end{enumerate}\n\\end{theorem}\n\n\n%------------------------------------------------\n\\subsection{A Fast Randomized Algorithm (FAR)}\nThe fast randomized algorithm (FAR) is from Rokhlin and Tygert's paper \\cite{SRFT2008}. The algorithm is given as follows.\n\\begin{tcolorbox}\n\\begin{enumerate}\n\\item Compute $E = TA$, where $T$ is the $r \\times m$ SRFT defined as follows, with $m \\geq r \\geq n. $ \\\\\n\\item Form a pivoted QR-decomposition of $E = Q R \\Pi$,  where $Q_{r \\times n}$ has orthonormal columns, $R_{n \\times n}$ is upper triangular and $\\Pi_{n \\times n}$ is the permutation matrix.  \\\\\n\\item Solve a preconditioned Least Squares Problem\n$$\n\\| AP^{-1} y - b\\|\n$$\nusing PCG where $P = R \\Pi$ is the preconditioning matrix.\n\\end{enumerate}\n\\end{tcolorbox}\n\n\n%------------------------------------------------\n\\subsubsection{Complexity for A Fast Randomized Algorithm (FAR)}\n\\begin{tcolorbox}\n\\begin{enumerate}\n\\item Applying $T$ to every column of $A$ : $O(mnlog(r))$.  \\\\\n\\item Computing the pivoted QR decomposition of $E$ : $O(n^2r) . $ \\\\\n\\item Applying $T$ to $b$: O(mlog(r)). Applying $Q^*$ to $Tb$: $O(nr)$.\n\n Applying $P^{-1} = \\Pi^{-1} R^{-1}$ to $Q^* Tb$ : $O(n^2). $ \\\\\n\\item Applying $A,A^T$ a total of $O(\\kappa(AP^{-1}) |log(\\epsilon)|)$ times: {\\color{red}$O(mn\\kappa(AP^{-1}) |log(\\epsilon)|).$} \\\\\n\\item Applying $P^{-1},(P^{-1})^*$ to a total of $O(\\kappa(AP^{-1}) |log(\\epsilon)|)$ times: {\\color{red}$O(n^2 \\kappa(AP^{-1}) |log(\\epsilon)|).$} \\\\\n\\item Applying $P^{-1}$ to $y$ : $O(n^2). $\n\\end{enumerate}\n\\end{tcolorbox}\nThus\n{\\color{red}\n$$\nC_{theoretical} = O((log(r) + \\kappa(AP^{-1}) |log(\\epsilon)|) mn +n^2r).\n$$}\n\n\n\n\n%------------------------------------------------\n\\subsubsection{SRFT Matrix}\nT is the sampled randomized Fourier transform (SRFT) Matrix defined by\n$$T _{r \\times m} = G_{r \\times m} H_{m \\times m}, \\quad  r \\leq m. $$\nG is the random matrix given by\n$$ G_{r \\times m} = S_{r \\times m} F_{m \\times m} D_{m \\times m}, $$\n\n\n\n\\begin{itemize}\n\\item $S$ is a random permutation matrix in each row j there is one column $s_j$ such that $S_{j,s_j} = 1$ and $S_{j,k} =0$ if $k \\neq s_j$. $s_j$'s are i.i.d. random variables distributed uniformly over $\\{ 1,\\cdots,m\\}. $ \\\\\n\\item $F$ is the $m \\times m$ discrete Fourier transform. \\\\\n\\item $D = diag(d_1,d_2,\\cdots,d_m)$\n           where $d_1,\\cdots,d_m$ are i.i.d. complex random variables distributed uniformly over the unit circle.\n\\end{itemize}\n\n\n\n%------------------------------------------------\n$$\nH_{m \\times m} =\\Theta_{m \\times m} \\Pi_{m \\times m} Z_{m \\times m} \\tilde{\\Theta}_{m \\times m}\\tilde{\\Pi}_{m \\times m} \\tilde{Z}_{m \\times m},\n$$\nwhere\n\n\n\\begin{itemize}\n\\item $\\Pi$ and $\\tilde{\\Pi}$ are permutation matrices chosen independently and uniformly at random. \\\\\n\\item $Z$ and $\\tilde{Z}$ are diagonal matrices whose diagonal entries are i.i.d. complex random variables distributed uniformly over the unit circle. \\\\\n\\item\n $\\Theta_{m \\times m} = \\begin{bmatrix} cos(\\theta_1)& sin(\\theta_1) & 0& \\cdots &0\\\\\n                                                                     - sin(\\theta_1)  & cos(\\theta_1) & 0 & \\cdots & 0 \\\\\n                                                                           0 & 0 & 1 & \\cdots & 0 \\\\\n                                                                               \\cdots & \\cdots & \\cdots & \\cdots & \\cdots  \\\\\n                                                                                  0 & 0 &0 & \\cdots & 1\n                                                   \\end{bmatrix}\n                                                                                  \\cdots\n                                                        \\begin{bmatrix} 1& \\cdots & 0& 0  &0\\\\\n                                                                             \\cdots  & \\cdots  & \\cdots & \\cdots & \\cdots \\\\\n                                                                              0 & \\cdots & 1 & 0 & 0 \\\\\n                                                                              0 & \\cdots & 0 & cos(\\theta_{m-1})& sin(\\theta_{m-1}) \\\\\n                                                                             0 & \\cdots &0 &  -sin(\\theta_{m-1}) & cos(\\theta_{m-1})\n                                                         \\end{bmatrix} ,$\n\n\n where $\\theta_k, \\quad k =1 ,\\cdots m-1$ are i.i.d. real random variables drawn uniformly from $[0,2\\pi]$.\n So is $\\tilde{\\Theta}$, but defined with different $\\tilde{\\theta}_k$.\n\n\\end{itemize}\n\n%------------------------------------------------\n\n\\subsubsection{Why SRFT works?}\n\\begin{corollary}\nSuppose that $\\alpha$ and $\\beta$ are real numbers greater than 1 and $r,m$ and $n$ are positive integers such that $m \\geq r \\geq (\\frac{\\alpha^2 +1}{\\alpha^2-1})^2 \\beta n^2. $ Suppose further that $T$ is the $r \\times m$ SRFT matrix. Suppose in addition that $U$ is an $m \\times n$ matrix whose columns are orthonormal.\nThen, the condition number of $TU$ is at most $\\alpha$ with probability at least $1 - \\frac{1}{\\beta}. $\n\\end{corollary}\n$\\kappa(TU)$ can be made arbitrarily close to 1 when $r$ is large enough.\n\n%------------------------------------------------\n\n\\begin{theorem}[Rokhlin and Tygert (2008)]\nSuppose that $r,m$ and $n$ are positive integers such that $m \\geq r \\geq n$. Suppose further that $A$ is a full rank $m \\times n$ matrix and the SVD of $A$ is\n$$\nA_{m \\times n} = U_{m \\times n} \\Sigma_{n \\times n} V^*_{n \\times n}.\n$$\nSuppose in addition that $T$ is an $r \\times m$ matrix such that the $r \\times n$ matrix $TU$ has full rank.\nThen\n$$\nT_{r \\times m} A_{m \\times n} = Q_{r \\times n} P_{n \\times n},\n$$\nwhere $Q$ has orthonormal columns.\nAnd\n$$\n\\kappa(AP^{-1}) = \\kappa(TU).\n$$\n\\end{theorem}\n\\small{$r \\geq 4n^2$ guarantees $\\kappa(TU) \\leq 3.$}\n\n\n\n\n%------------------------------------------------\n\\subsection{Blendenpik}\n\n%------------------------------------------------\nThe Blendenpik method is from the paper \\cite{BLEN2010}. In this paper, they emphasis on the coherence number of a matrix.\n\\begin{definition}[Coherence]\nLet $A$ be an $m \\times n$ full rank matrix, and let $U$ be an $m \\times n$ matrix whose columns form an orthonormal basis for the column space of $A$. The coherence of $A$ is defined as\n$$\n\\mu(A) = max\\| U_{i,*} \\|_2^2.\n$$\n\\end{definition}\n\nObviously,\n$$\n \\frac{n}{m} \\leq \\mu(A) \\leq 1.\n$$\n\n%------------------------------------------------\n\\subsubsection{Matrices Classified by Coherence}\nAccording to the coherence number, we can classify the matrices into 3 categories.\n\\begin{enumerate}\n\\item Incoherent matrix: $A = randn(m,n)$ since $\\mu(A)$ is small. \\\\\n\\item Semicoherent matrix: $$\nA_{m \\times n} =\n \\begin{bmatrix}\n  B & \\\\\n    \\quad & I_{n/2}\n \\end{bmatrix},\n$$\nwhere $B$ is an $(m - n/2) \\times n/2$ rectangular random matrix and $I_{n/2}$ is a square identity of dimension $n/2$.\n\n$\\mu(A) =1$ but only $n/2$ rows have a large norm in the orthogonal factor.\n\\item Coherent matrix:\n$$\nA_{m \\times n} =  \\begin{bmatrix}\n  D_{n \\times n} & \\\\\n   O_{(m-n) \\times n}\n \\end{bmatrix}\n + 10^{-8}\n \\begin{bmatrix}\n1 & \\cdots & 1 \\\\\n\\cdots & \\cdots & \\cdots \\\\\n1 & \\cdots &1\n \\end{bmatrix} ,\n$$\nwhere $D$ is a random diagonal matrix. The orthogonal factor has $n$ rows with a large norm.\n\\end{enumerate}\n\n\n%------------------------------------------------\n\\subsubsection{Blendenpik: How coherence influence sampling?}\nOne preconditioned method given by Rokhlin and Tygert to solve the least squares problems using the R factor of the sampled rows as a preconditioner in a Krylov-subspace method like LSQR.\n\\begin{lstlisting}\n[Q,R] = qr(SA,0);\nx1 = lsqr(A,b,eps,100,R);\n\\end{lstlisting}\nThe method fails when the coherence number is large.\nFor the semicoherent matrix: $$\nA_{m \\times n} =\n \\begin{bmatrix}\n  B & \\\\\n    \\quad & I_{n/2}\n \\end{bmatrix}.\n$$\\\\\nAfter uniform sampling, $SA$ is rank deficient with high probability. $R$ is ill conditioned. LSQR fails. One way to solve is to sample with the probability as leverage score $p_i = \\|U_i\\|_2^2/m$, where $A = UR$ is the reduced QR decomposition, which cost $O(n^3).$\n\n%------------------------------------------------\n\n\n\\begin{theorem}[Avron, Maymounkov and Toledo (2010)]\nLet $S$ be a random sampling operator that samples $r \\geq n$ rows from $A$ uniformly. Let $\\tau = C \\sqrt{m \\mu(A) log(r) /r},$\nwhere $C$ is some constant defined in the proof. Assume that $\\delta^{-1} \\tau <1$. With probability of at least $1 - \\delta$, the sampled matrix $SA$ is full rank, and if $SA = QR$ is a reduced QR factorization of $SA$, we have\n$$\n\\kappa(A R^{-1}) \\leq \\frac{1 + \\delta^{-1} \\tau}{1 - \\delta^{-1} \\tau}.\n$$\n\\end{theorem}\nIf $\\mu(A)$ is large we need a large sample size $r$ to balance, otherwise we will have a larger bound for $\\kappa(A R^{-1}).$\n\n%------------------------------------------------\n\\subsubsection{Blendenpik: Row Mixing}\n\\begin{theorem}[Avron, Maymounkov and Toledo (2010)]\nLet $A$ be an $m \\times n$ full rank matrix, where $m \\geq n$. Let $F$ be an $m \\times m$ unitary matrix, let $D$ be a diagonal matrix whose diagonal entries are independent and identically distributed Rademacher random variables ($P(D_{ii} = \\pm 1 ) = 1/2$), and let $\\mathcal{F} = FD$. With a probability of at least $0.95$, we have\n$$\n\\mu(\\mathcal{F} A) \\leq C n \\eta log m,\n$$\nwhere $\\eta = max | F_{ij} |^2$ and some constant $C$.\n\\end{theorem}\n\nThe seed matrix can be Walsh-Hadamard transform (WHT {\\color{red}$\\eta = 1/m$}), discrete cosine transform (DCT{\\color{red}$\\eta = 2/m$}) and discrete Hartley transform (DHT {\\color{red} $\\eta = 2/m$}). After row mixing, the coherence of $\\mathcal{F} A$ becomes small. Then uniform sampling and LSQR can be applied. Complexity of calculting $\\mathcal{F}A$: $O(mn log(m)).$\n\n%------------------------------------------------\n\\subsubsection{Blendenpik Algorithm}\n\\begin{tcolorbox}\n\\begin{enumerate}\n\\item Row Mixing : $F_{\\tilde{m}} DM$, where\n\\begin{itemize}\n\\item $\\tilde{m} = \\begin{cases}& 2^{[log_2 m]} , \\quad \\text{WHT} \\\\\n                                         & [m/1000]*1000, \\quad \\text{DCT or DHT}.\n                    \\end{cases}$\\quad  $M = \\begin{bmatrix} A\\\\ 0 \\end{bmatrix} \\in \\mathbb{R}^{\\tilde{m} \\times n}$. \\\\\n\\item $D$ is a diagonal matrix with $\\pm 1$ on its diagonal with equal probability. \\\\\n\\item $F_{\\tilde{m}}$ is the seed unitary transform (WHT/DCT/DHT) operations.\n\\end{itemize}\n\\item Sampling : $S \\in \\mathbb{R}^{\\tilde{m} \\times \\tilde{m}}$ be a random diagonal matrix with\n$S_{ii} = \\begin{cases} & 1 \\quad \\text{with probability}\\quad \\gamma n /\\tilde{m} \\\\\n                                   & 0 \\quad \\text{with probability}\\quad 1 - \\gamma n /\\tilde{m}.\n             \\end{cases}$\\\\\n\\item QR of Sampled Matrix : $S F_{\\tilde{m}} D M = Q R,$  reduced QR factorization ($R\\in \\mathbb{R}^{n \\times n} $). \\\\\n\\item Apply LSQR with preconditioner $R$. (If the iteration steps $>3$, solve using LAPACK and return).\n\\end{enumerate}\n\\end{tcolorbox}\n\n%------------------------------------------------\n\\subsubsection{Complexity of Blendenpik Algorithm}\n\\begin{tcolorbox}\n\\begin{enumerate}\n\\item Row Mixing : $O(mn log m).$ \\\\\n\\item QR of Sampled Matrix : $O(n^3).$\\\\\n\\item Each LSQR Iteration: $O(mn).$ The number of iterations grows slowly.\n\\end{enumerate}\nTotal: ${\\color{red} O(mn log m) + O(n^3) + O(mn k)}.$ $k$ is the number of LSQR iterations.\n\\end{tcolorbox}\n\n%--------------------------------------------------------------------\n\\section{Randomized MultiGrid Methods}\n%------------------------------------------------\nUse AMG to solve the least squares problems we have the complexity ${\\color{red} O(mn^2)}. $\n\\begin{tcolorbox}\n\\begin{enumerate}\n\\item \\textbf{Matrix Multiplication:} Compute $A^TA$. \\quad ${\\color{red} O(mn^2)} $ \\\\\n\\item \\textbf{Coarsening and Interpolation:} Use coarsenAMG to coarsen $A^TA$ and get the projection matrix $Pro$ and restriction Res. $n_c$ is the size of coarsened matrix.\n\\quad${\\color{red} O(n n_c)}$\n\\\\\n\\item \\textbf{V-cycle Multigrid Precondition:} Dominant cost: several Gauss Seidel iterations.\\quad${\\color{red} O(n^2)}$ \\\\\n\\item \\textbf{PCG:} Use PCG to solve $A^TA x = A^Tb$ with preconditioner constructed in Step 3.\n\\quad {\\color{red} $O(kmn)$, where k is the steps of iterations.}\n\\end{enumerate}\n{\\color{red} Total Complexity: $O(mn^2).$}\n\\end{tcolorbox}\n%------------------------------------------------\n\\subsection{Randomized MultiGrid Scheme}\nWe developed the Randomized Multigrid Methods by the following steps.\n\\begin{tcolorbox}\n\\begin{enumerate}\n\\item \\textbf{Normalization:} Normalized $A$ with diagonal matrix $D$ where $D_{jj} = \\|A^j\\|_2, \\quad j \\in [n], $ \\quad where\n$A^j$ is the j-th column of $A$. \\\\\n\\item \\textbf{Sampling:} Sample the row of $A$ to get $As_{sn \\times n}, s_n \\approx 4 n log(n)$ either by uniform sampling or row sampling. \\\\\n\\item \\textbf{Coasening:} Use coarsenAMG to coarsen $A_s^T A_s$ and get the projection matrix  $Pro$ and restriction $Res$. \\\\\n\\item \\textbf{Precondition:} Solve $A_s^T A_s e =r$ by TwoGrid/MultiGrid Method. \\\\\n\\scalebox{0.8}{\n\\begin{minipage}{\\textwidth}\n\\begin{itemize}\n\\item Presmoothing: 3 times forward Gauss Seidel apply to $A_s^T A_s e =r$; \\\\\n\\item Restriction: Calculate residual and use $Res$ to do restriction $rc = Res*r$;\\\\\n\\item Direct solve on the coarsest grid $ec = (Ac'*Ac)/rc$ where $Ac = A*Pro$;\\\\\n\\item Prolongation: Use $Pro$ to get prolongation $e = e + Pro*ec$; \\\\\n\\item Postsmoothing: 3 times backward Gauss Seidel apply to $A_s^T A_s e =r$.\n\\end{itemize}\n\\end{minipage}} \\\\\n\\item \\textbf{PCG:} Use PCG to solve $A^TA x = A^Tb$ with preconditioner constructed in Step 3.\n\\end{enumerate}\n\\end{tcolorbox}\n\n%------------------------------------------------\n\\subsection{Uniform Sampling and Row Sampling}\n\\begin{enumerate}\n\\item \\textbf{Uniform Sampling:}\n$$\nS_{ii} = \\begin{cases} & \\frac{1}{1/m} \\quad \\text{with probability} \\quad \\frac{1}{m}; \\\\\n                             & 0 \\quad \\text{otherwise.}\n                             \\end{cases}\n$$\\\\\n\\item \\textbf{Row Sampling:}\n$$\np_i = \\frac{\\| A_i \\|_2}{\\| A \\|_F}, \\quad \\text{where $A_i$ is the i-th column of $A$}.\n$$\n$$\nS_{ii} = \\begin{cases} & \\frac{1}{p_i} \\quad \\text{with probability} \\quad p_i; \\\\\n                             & 0 \\quad \\text{otherwise.}\n                             \\end{cases}\n$$\\\\\n\\end{enumerate}\nThe sampled matrix is\n$$\nA_s = SA.\n$$\n\n%------------------------------------------------\n\n\\subsection{Complexity}\nComplexity of Randomized MultiGrid Method is calculated as follows.\n\\begin{tcolorbox}\n\\begin{enumerate}\n\\item \\textbf{Normalization:} Calculate $\\|A^j\\|_2 $ for $j \\in [n]$ costs $O(mn)$. Multiplication $D A$ costs $O(mn)$.  \\\\\n\\item \\textbf{Sampling: } Interpolation $O(s_n m ) = O(n log(n) m), $ where \\quad $A_s \\in \\mathbb{R}^{s_n \\times n}. $ \\\\\n\\item \\textbf{Matrix Multiplication: } $A_s^T A_s.$ $O(s_n n^2) = O(n^3 log(n)). $ \\\\\n\\item \\textbf{Precondition:} 6 times Gauss Seidel apply to $A_s^TA_s e =r $: $O(n^2). $\\\\\n\\item \\textbf{PCG:} k times PCG until reaching threshold $\\epsilon$ costs  $O(k mn). $\n\\end{enumerate}\n\\end{tcolorbox}\n\n%------------------------------------------------\n\\subsection{Sampling Graph}\nGraphs of $A^T A$ and $As^T As$\n\\tiny{\n\\begin{lstlisting}\nTest matrix:  S = load('sparse_random_c_100.mat');   A = S.M{5};\n\\end{lstlisting}}\n\\begin{figure}[htbp]\n    \\includegraphics[width=1\\textwidth]{sampling.png}\n\\end{figure}\n\n\n\n%------------------------------------------------\n\n\\subsection{Performance}\n%------------------------------------------------\n\\subsubsection{Well Conditioned Incoherent Matrix}\nPerformance: Well Conditioned Incoherent Matrix\nThe incoherent matrix (coherence $\\mu(A)$ is small) is constructed by\n$$\nA = randn(m,n);\n$$\n\n\\begin{table}\\label{table_inc}\n\\centering\n\\caption{Incoherent Random Matrix}\n\\begin{tabular}{| l | l | l |l |l |l |l |l |l |l |}\\hline\n  m & n & Size  &   Conde    &    PCG.res    &  PCG.iter    &  TW.res    &  TW.iter  &   AMG.res    &  AMG.iter\\\\\\hline\n3000& 109 &  3.27e+05  & 8.0592  & 2.8265e-08  & 10  &  7.8964e-08  & 11  & 8.6322e-11 & 3   \\\\\\hline\n 5000 & 141 &7.05e+05  & 7.1294 &  6.3485e-08   & 9    & 5.0459e-08   & 11 & 6.8662e-12  & 3  \\\\\\hline\n  10000& 200 &   2e+06    & 7.6457   & 1.8065e-08   & 9    & 3.3853e-08   &11 &1.2271e-12   &3 \\\\\\hline\n   20000& 282 & 5.64e+06   &7.4708  &  3.6032e-08 &    8   &   3.4031e-08 &   11& 3.468e-13   &3  \\\\\\hline\n  40000& 400 &  1.6e+07  &  7.3094 &   8.8878e-08  &   7  &    2.8748e-08  &  11 &  3.6036e-14   & 3  \\\\\\hline\n\\end{tabular}\n\\end{table}\n\n\n%------------------------------------------------\n\\subsubsection{Well Conditioned Semicoherent Matrix}\n\nPerformance: Well Conditioned Semicoherent Matrix\n\\small\n{Semicoherent matrix is given by\n$$\nA_{m \\times n} =\n \\begin{bmatrix}\n  B & \\\\\n    \\quad & I_{n/2}\n \\end{bmatrix},\n$$\nwhere $B$ us an $(m - n/2) \\times n/2$ rectangular random matrix and $I_{n/2}$ is a square identity of dimension $n/2$. }\n\n\n\\begin{table}\\label{table_semi}\n\\centering\n\\caption{Semicoherent Matrix with Row Sampling}\n\\begin{tabular}{| l | l | l |l |l |l |l |l |l |l |}\\hline\n  m & n & Size  &   Conde    &    PCG.res    &  PCG.iter    &  TW.res    &  TW.iter  &   AMG.res    &  AMG.iter\\\\\\hline\n3000& 109 &  3.24e+05 &  3.7979   & 4.4898e-08  &  8    &   6.2979e-08    &13    &  3.7059e-13   &  3   \\\\\\hline\n 5000 & 141 &    7e+05  & 3.6879   & 2.3175e-08 &   8     &  3.6585e-08    &12 &    5.6326e-14    & 3   \\\\\\hline\n  10000& 200 &     2e+06  &  3.7234   & 5.1245e-08  &  7   &    3.7377e-08 &   13   &   6.3799e-08   & 2    \\\\\\hline\n   20000& 282 &  5.64e+06  & 3.6137  &  2.4414e-08  &  7   &    4.0871e-08 &   12   &  3.5634e-08  &  2   \\\\\\hline\n   40000 & 400 & 1.6e+07   &  3.4741  &   8.1149e-08  &   6     &   4.6966e-08  & 12 &  1.094e-08 &   2  \\\\\\hline\n\\end{tabular}\n\\end{table}\n\n\n%------------------------------------------------\n\\subsubsection{Ill Conditioned Sparse Random Matrix}\nPerformance: Ill Conditioned Sparse Random Matrix\nThe sparse random matrix is generated by the MATLAB's function $sprand$\n$$\n A = sprand(m,n,s,1/c);\n$$\nwhere $m$ is the number of rows, $n$ is the number of columns, $s$ is the sparsity and $c$ is the estimated condition number.\n\\\\\n\n\n%------------------------------------------------\nPerformance: Ill Conditioned Sparse Random Matrix\n\n\\begin{table}\\label{table_spc}\n\\centering\n\\caption{Sparse Random Matrix Using Uniform Sampling $m = 40000, n = 200.$}\n\\begin{tabular}{|*{8}{c|}}\\hline\n     Nnz    &   Conde     &  PCG.res    &  PCG.iter   &   TW.res   &   TW.iter   &   AMG.res    &  AMG.iter \\\\\\hline\n    38942  &      2132.1  &  8.7014e-08   & 106    &     6.5273e-08   & 33     &    3.7773e-08  &  23   \\\\\\hline\n    38228   &      12321   & 9.6274e-08    & 167    &     7.8268e-08   & 44     &    9.9291e-08  &  36    \\\\\\hline\n    37718    &     73525    & 2.8338e-05    & 200    &     4.6732e-08   & 79     &    6.1329e-08  &  57    \\\\\\hline\n    38178     &    71728    & 2.7356e-07    & 200     &    8.5303e-08    &52      &   3.6577e-08   & 42     \\\\\\hline\n    37730    & 3.9579e+05  &    0.002827   & 121    &     6.8812e-08   & 76      &   3.2188e-08  &  58     \\\\\\hline\n\\end{tabular}\n\\end{table}\n\\begin{table}\n\\centering\n\\caption{Sparse Random Matrix Using Row Sampling $m = 40000, n = 200.$}\n\\begin{tabular}{|*{8}{c|}}\\hline\n     Nnz    &   Conde    &    PCG.res    &  PCG.iter    &  TW.res    &  TW.iter  &   AMG.res    &  AMG.iter\\\\\\hline\n    38942  &      2132.1  &  8.7014e-08  &  106      &   5.3535e-08  &  30    &     3.6095e-08  &  23      \\\\\\hline\t\n    38228   &      12321   & 9.6274e-08   & 167       &  9.2237e-08   & 44      &   9.9291e-08   & 36      \\\\\\hline\n    37718    &     73525   & 2.8338e-05    & 200       &  8.9378e-08   & 75      &   6.1329e-08   & 57      \\\\\\hline\n    38178     &   71728    & 2.7356e-07    & 200        & 4.0376e-08    &58       &  3.8837e-08    &42      \\\\\\hline\n    37730    & 3.9579e+05  &    0.002827  &  121      &   4.7336e-08   & 81      &   6.2102e-08   & 57  \\\\\\hline\n\n\n\\end{tabular}\n\\end{table}\n\n\\begin{itemize}\n\\item The iteration steps depend weakly on the condition number $\\kappa(A). $\n\\end{itemize}\n\n%------------------------------------------------\n\\subsubsection{UDV Matrix}\nPerformance: UDV Matrix\nUDV matrix is a random matrix generated by\n$$\nA = U D V,\n$$\nwhere $U$ is an $m \\times n$ orthonormal matrix, $V$ is an $n \\times n$ orthonormal matrix and\n$D = diag[1,1+(c-1)/n,\\cdots,c]$.\n\n\\begin{table}\\label{}\n\\caption{UDV Matrix Using CoarsenAMGa and Row Sampling $m = 10000, n = 200.$}\n\\begin{tabular}{|*{8}{c|}}\\hline\n  Nnz    &   Conde  &      PCG.res   &   PCG.iter     & TW.res  &    TW.iter     &   AMG.res &     AMG.iter \\\\\\hline\n      40000  &      3468.1 &   9.1949e-08  &  112     &    9.4608e-08  &  29       & 9.9643e-08  &  25      \\\\\\hline\n    40000   &      16679  &  8.3161e-08 &   192     &    5.4534e-08   & 50           & 5.7913e-08    &43      \\\\\\hline\n    40000  & 1.0667e+05  &  3.5074e-06 &   198    &     9.0271e-08 &   73      &   7.1027e-08   & 61     \\\\\\hline\n    40000  &  4.0013e+05  &   2.199e-05  &  190     &    8.3462e-08  &  81       &  6.5267e-08   & 66     \\\\\\hline\n    40000   & 1.0203e+06  &  1.8215e-05  &  197    &     9.5749e-08   & 83        & 1.1792e-08  &  68    \\\\\\hline\n\\end{tabular}\n\\end{table}\n\n\n%------------------------------------------------\n\n\\subsubsection{Graph Laplacian Matrix}\nPerformance: Graph Laplacian Matrix\nGiven edges and generate the graph laplacian matrix $G$ by\n\\begin{lstlisting}\n        i = repmat(1:size(edge,1),1,2)';\n        i = i(:);\n        j = edge(:);\n        s = repmat([-1 1],size(edge,1),1);\n        s = s(:);\n        B = sparse(i,j,s);\n        G = B'*B;\n\\end{lstlisting}\n\n\n\\begin{table}\\label{}\n\\caption{Graph Laplacian Matrix Using CoarsenAMGc $m = 9314,n=100$}\n\\begin{tabular}{|*{8}{c|}}\\hline\n  Nnz    &   Conde  &      PCG.res   &   PCG.iter     & TW.res  &    TW.iter    &   AMG.res &     AMG.iter \\\\\\hline\n9214     &   10.273  &   4.0992e-08   & 17       &   4.4332e-08  &  12         &5.7114e-10  &   4    \\\\\\hline\n    9214  &      112.71 &   6.6875e-08  &  37    &      7.0856e-08 &   12      &   6.4333e-08&     7   \\\\\\hline\n    9214  &      1657.1 &   8.3804e-08  &  47    &       8.406e-08 &   15    &   9.248e-08  &   9     \\\\\\hline\n    9214  &       26188 &    4.0137e-08  &  51   &       8.7113e-08  &  17     &   4.2357e-08  &  10   \\\\\\hline\n    9214  &  4.1839e+05 &   6.1113e-08   & 41   &       3.2572e-08  &  19     &    3.5725e-08 &   11  \\\\\\hline\n\\end{tabular}\n\\end{table}\n\n\n\n\n\n%------------------------------------------------\n\n\\subsection{Convergence Analysis}\n\\begin{theorem}[Sum of Rank-1 Matrix]\nLet $y_1,y_2,\\cdots,y_n$ be i.i.d. random column vectors in $\\bbbc^d$ with\n$$\n\\| y_i \\| \\leq M \\quad \\text{and} \\quad \\|\\E[y_i y_i^*] \\| \\leq 1.\n$$\nThen for all $0 \\leq \\epsilon \\leq 1$\n$$\nPr \\left( \\| \\frac{1}{n} \\sum_{k=1}^n y_k y_k^* - \\E [y_1 y_1^T] \\| \\geq \\epsilon \\right) \\leq\n2d exp(-\\frac{3 n \\epsilon^2}{8 (M^2+1)}).\n$$\n\\end{theorem}\n\n%------------------------------------------------\n\\subsubsection{Row Sampling}\nLet\n$$\ny_k = \\begin{cases} & A_i^T/ \\sqrt{p_i}  \\quad \\text{with probability} \\quad p_i, \\quad 1 \\leq i \\leq m;  \\\\\n                               & 0 \\quad \\quad \\text{otherwise}.\n        \\end{cases}\n$$\n\n$$\n\\E [y_k y_k^T] = \\sum_{i=1}^m A_i^T A_i = A^T A.\n$$\n\nRandomly choose r $y_i$'s. Put them together to get the sampled matrix $As$. Then\n$$\nAs^T As = \\frac{1}{r} \\sum_{i=k}^r y_k y_k^T.\n$$\nBy the Theorem (Sum of Rank-1 Matrix)\n$$\n\\| As^T As - A^T A \\| \\leq \\epsilon  \\quad \\text{with high probability}.\n$$\n\n\n\\subsubsection{High Frequency and Low Frequency}\n\nWith high probability, $\\forall x \\neq 0,$\n\\begin{equation}\\label{star}\n|(A^TA x,x) - \\epsilon^2(x,x) | \\leq (As^T As x,x) \\leq (A^TA x,x) + \\epsilon^2(x,x).\n\\end{equation}\n\nFor the matrix $A^T A$ after normalization, $0 < \\lambda_{min} \\leq \\lambda_{max} \\leq c$. \\\\\nFor high frequency eigenvectors, i.e.\n$$\n(A^T Ax,x)  \\approx \\lambda_{max} \\|x\\|^2\n$$\nwe have\n$$\n(A_s^T A_s x,x) \\leq c (A^TAx,x).\n$$\n\nBut for low frequency eigenvectors, we need the coarsening part.\n\n\n\n\n\n\n%\\begin{thebibliography}{99}\n\n%\\bibitem{CON2015} Peter Oswald, Weiqi Zhou\n% Convergence analysis for Kaczmarz-type methods in a Hilbert space framework\n%\\emph{Linear algebra and its Applications} 478(2015),131-161.\n\n%\\bibitem{FLSA2011} P. Drineas, M. W. Mahoney, S. Muthukrishnan and T. Sarlos\n%\\newblock Faster least squares approximation\n%\\newblock \\emph{Numerische Mathematik} (2011) 117: 219. %doi:10.1007/s00211-010-0331-6\n\n%\\bibitem{SRFT2008} V. Rokhlin and M. Tygert\n%\\newblock A Fast Randomized Algorithm for Overdetermined Linear Least-Squares %Regression,\n%\\newblock  \\emph{Proceedings of the National Academy of Science of the United States of America,}  Vpl. 105, No.36(Sep.9,2008),pp. 13212-13217\n\n\n%\\bibitem{BLEN2010} H. Avron, P. Maymounkov and S. Toledo\n%\\newblock Blendenpik: Supercharging LAPACK's Least-Squares Solver\n%\\newblock \\emph{ SIAM Journal on Scientific Computing}\n%32.3 (2010): 1217. c2010 Society for Industrial and Applied Mathematics\n\n%\\bibitem{ARK01} Ji Liu and Stephen J. Wright, An Accelerated Randomized Kaczmarz Algorithm, \\emph{Mathematics of Computation}, Volume 85, Number 297, January 2016, pp. 153--178.\n\n%\\bibitem{ITE01}\n%Long Chen, Classical Iterative Methods, available at\n%\\url{http://www.math.uci.edu/~chenlong/226/Ch6IterativeMethod.pdf}.\n\n\n%\\bibitem{WikiRK} ] Randomized Kaczmarz Method, available at\n%\\url{https://en.wikipedia.org/wiki/Kaczmarz_method}.\n\n%\\end{thebibliography}\n", "meta": {"hexsha": "faba4ee8ecac3b4a11c7b17ae9ee624ce72b71d3", "size": 36753, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/RandomizedAlgorithmsLongChen0407.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/RandomizedAlgorithmsLongChen0407.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/RandomizedAlgorithmsLongChen0407.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.3910034602, "max_line_length": 372, "alphanum_fraction": 0.5751367235, "num_tokens": 12674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7461131909484554}}
{"text": "\\section{Substitution Rule}\\label{sec:SubRule}\r\nNeedless to say, most integration problems we will encounter will\r\nnot be so simply. That is to say we will require more than the basic\r\nintegration rules we have seen. Here's a slightly more complicated example: Find\r\n$$\\int 2x\\cos(x^2)\\,dx.$$\r\nThis is not a ``simple'' derivative, but a little thought reveals that\r\nit must have come from an application of the chain rule. Multiplied\r\non the ``outside'' is $2x$, which is the derivative of the ``inside''\r\nfunction $\\ds x^2$. Checking:\r\n$${d\\over dx}\\sin(x^2)  = \\cos(x^2){d\\over dx}x^2 = 2x\\cos(x^2),$$\r\nso \r\n$$\\int 2x\\cos(x^2)\\,dx=\\sin(x^2)+C .$$\r\n\r\nTo summarize: If we suspect that a given function is the derivative of\r\nanother via the chain rule, we let $u$ denote a likely candidate for\r\nthe inner function, then translate the given function so that it is\r\nwritten entirely in terms of $u$, with no $x$ remaining in the\r\nexpression. If we can integrate this new function of $u$, then the\r\nantiderivative of the original function is obtained by replacing $u$\r\nby the equivalent expression in $x$.\r\n\r\n\\begin{theorem}{Substitution Rule for Indefinite Integrals}{SubstitutionRule}\r\nIf $u=g(x)$ is a differentiable function whose range is an interval $I$ and $f$ is continuous on $I$, then\r\n$$\\int f(g(x))g'(x)\\,dx=\\int f(u)\\,du.$$\r\n\\end{theorem}\r\n\r\nEven in simple cases you may prefer to use this mechanical procedure,\r\nsince it often helps to avoid silly mistakes. For example, consider\r\nagain this simple problem:\r\n$$\\int 2x\\cos(x^2)\\,dx.$$\r\nLet $\\ds u=x^2$, then $du/dx = 2x$ or $du = 2x\\,dx$. Since we have exactly \r\n$2x\\,dx$ in the original integral, we can replace it by $du$:\r\n$$\\int 2x\\cos(x^2)\\,dx=\\int \\cos u\\,du=\\sin u +C = \\sin(x^2)+C.$$\r\nThis is not the only way to do the algebra, and typically there are\r\nmany paths to the correct answer. Another possibility, for example,\r\nis: Since $du/dx = 2x$, $dx=du/2x$, and then the integral becomes\r\n$$\\int 2x\\cos(x^2)\\,dx=\\int 2x\\cos u\\,{du\\over 2x}=\\int \\cos u\\,du.$$\r\nThe important thing to remember is that you must eliminate all\r\ninstances of the original variable $x$.\r\n\r\n\\begin{example}{Substitution Rule}{SubstitutionRuleex}\r\nEvaluate $\\ds\\int(ax+b)^n\\,dx$, assuming $a,b$ are\r\nconstants, $a\\not=0$, and $n$ is a positive integer.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe let $u=ax+b$ so $du=a\\,dx$ or $dx=du/a$. Then\r\n$$\r\n  \\int(ax+b)^n\\,dx=\\int {1\\over a} u^n\\,du={1\\over a(n+1)}u^{n+1}+C=\r\n  {1\\over a(n+1)}(ax+b)^{n+1}+C.\r\n$$\r\n\\end{solution}\r\n\r\n\\begin{example}{Substitution Rule}{SubstitutionRulex}\r\nEvaluate $\\ds\\int \\sin(ax+b)\\,dx$, assuming that $a$ and $b$ are\r\nconstants and $a\\not=0$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nAgain we let $u=ax+b$ so $du=a\\,dx$ or $dx=du/a$. Then\r\n$$\r\n  \\int\\sin(ax+b)\\,dx=\\int {1\\over a} \\sin u\\,du={1\\over a}(-\\cos u)+C=\r\n-{1\\over a}\\cos(ax+b)+C.\r\n$$\r\n\\end{solution}\r\n\r\n\\begin{formulabox}[Strategy for Substitution Rule]\r\nA general strategy to follow is:\r\n\\begin{enumerate}\\setlength{\\itemsep}{0 in}\r\n\\item Choose a possible $u=u(x)$. \\dfont{Tip:} Choose a substitution $u$ so that its derivate also appears in the integral (up to a constant).\r\n\\item Calculate $du=u'(x)~dx$.\r\n\\item Either replace $u'(x)~dx$ by $du$, or replace $dx$ by $\\ds{\\frac{du}{u'(x)}}$, and cancel.\r\n\\item Write the rest of the integrand in terms of $u$. If this is not possible, the substitution will not work: You must go back to step 1.\r\n\\item Find the indefinite integral. (Again, if this is not possible, try a different substitution, or a different method).\r\n\\item Rewrite the result in terms of $x$.\r\n\\end{enumerate}\r\n\\end{formulabox}\r\n\r\n\\begin{example}{Substitution}{Substitution}\r\nEvaluate the following integral: $\\ds\\int \\frac{2x}{\\sqrt{1-4x^2}}\\,dx.$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe try the substitution:\r\n$$u=1-4x^2.$$\r\nThen,\r\n$$du=-8x~dx$$\r\nIn the numerator we have $2x~dx$, so rewriting the differential gives:\r\n$$-\\frac{1}{4}du=2x~dx.$$\r\nThen the integral is:\r\n\\begin{eqnarray*}\r\n\\int \\frac{2x}{\\sqrt{1-4x^2}}\\,dx&=&\\int \\left(1-4x^2\\right)^{-1/2}(2x~dx)\\\\\r\n\\\\\r\n&=&\\int u^{-1/2}\\left(-\\frac{1}{4}du\\right)\\\\\r\n\\\\\r\n&=&\\left(\\frac{-1}{4}\\right)\\frac{u^{1/2}}{1/2}+C\\\\\r\n\\\\\r\n&=&-\\frac{\\sqrt{1-4x^2}}{2}+C\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\n\r\n\r\n\\begin{example}{Substitution}{Substitution}\r\nEvaluate the following integral: $\\ds\\int \\sech^2(7t-3)\\ dt$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\n We employ substitution, with $u = 7t-3$ and $du = 7dt$. We have:\r\n$$ \\int \\sech^2 (7t-3)\\ dt=  \\frac17 \\int \\sech^2 (u)\\ du= \\frac17\\tanh (u) + C = \\frac17\\tanh (7t-3) + C.$$\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\r\n\\begin{example}{Substitution}{Substitution2}\r\nEvaluate the following integral: $\\ds\\int \\cos x(\\sin x)^5\\,dx.$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nIn this question we will let $u=\\sin x$.\r\nThen,\r\n$$du=\\cos x~dx.$$\r\nThus, the integral becomes:\r\n\\begin{eqnarray*}\r\n\\int \\cos x(\\sin x)^5\\,dx&=&\\int u^5\\,du\\\\\r\n\\\\\r\n&=&\\frac{u^6}{6}+C\\\\\r\n\\\\\r\n&=&\\frac{(\\sin x)^6}{6}+C\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\n\\begin{example}{Substitution}{Substitution3}\r\nEvaluate the following integral:\r\n$\\ds\\int \\frac{\\cos(\\sqrt x)}{\\sqrt x}\\,dx.$\r\n%\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe use the substitution:\r\n$$u=x^{1/2}.$$\r\nThen,\r\n$$du=\\frac{1}{2}x^{-1/2}dx.$$\r\nRewriting the differential we get:\r\n$$2~du=\\frac{1}{\\sqrt x}~dx.$$\r\nThe integral becomes:\r\n\\begin{eqnarray*}\r\n\\int \\frac{\\cos(\\sqrt x)}{\\sqrt x}\\,dx&=&2\\int \\cos u\\,du\\\\\r\n\\\\\r\n&=&2\\sin u+C\\\\\r\n\\\\\r\n&=&2\\sin(\\sqrt x)+C\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\n\\begin{example}{Substitution}{Substitution4}\r\nEvaluate the following integral:\r\n$\\ds\\int 2x^3\\sqrt{x^2+1}\\,dx.$\r\n%\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nThis problem is a little bit different than the previous ones.\r\nIt makes sense to let:\r\n$$u=x^2+1,$$\r\nthen\r\n$$du=2x~dx.$$\r\nMaking this substitution gives:\r\n\\begin{eqnarray*}\r\n\\int 2x^3\\sqrt{x^2+1}\\,dx&=&\\int x^2\\sqrt{x^2+1}(2x)\\,dx\\\\\r\n\\\\\r\n&=&\\int x^2u^{1/2}\\,du\\\\\r\n\\end{eqnarray*}\r\nThis is a problem because our integrals can't have a mixture of two variables in them.\r\nUsually this means we chose our $u$ incorrectly.\r\nHowever, in this case we can eliminate the remaining $x$'s from our integral by using:\r\n$$u=x^2+1\\quad\\to\\quad x^2=u-1.$$\r\nWe get:\r\n\\begin{eqnarray*}\r\n\\int x^2u^{1/2}\\,du&=&\\int (u-1)u^{1/2}\\,du\\\\\r\n\\\\\r\n&=&\\int u^{3/2}-u^{1/2}\\,du\\\\\r\n\\\\\r\n&=&\\frac{2}{5}u^{5/2}-\\frac{2}{3}u^{3/2}+C\\\\\r\n\\\\\r\n&=&\\frac{2}{5}(x^2+1)^{5/2}-\\frac{2}{3}(x^2+1)^{3/2}+C\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\nThe next example shows how to use the Substitution Rule when dealing with definite integrals.\r\n\r\n\\begin{example}{Substitution Rule}{SubstitutionRuledefex}\r\nEvaluate $\\ds\\int_2^4 x\\sin(x^2)\\,dx$. \r\n\\end{example}\r\n\r\n\\begin{solution} \r\nFirst we compute the\r\nantiderivative, then evaluate the integral.\r\nLet $\\ds u=x^2$, so $du=2x\\,dx$ or $x\\,dx=du/2$. Then\r\n$$\r\n  \\int x\\sin(x^2)\\,dx=\\int {1\\over 2} \\sin u\\,du={1\\over 2}(-\\cos u)+C=\r\n  -{1\\over 2}\\cos(x^2)+C.\r\n$$\r\nNow\r\n$$\r\n  \\int_2^4 x\\sin(x^2)\\,dx=\\left.-{1\\over 2}\\cos(x^2)\\right|_2^4\r\n  =-{1\\over 2}\\cos(16)+{1\\over 2}\\cos(4).\r\n$$\r\nA somewhat neater alternative to this method is to change the original\r\nlimits to match the variable $u$. Since $\\ds u=x^2$, when $x=2$, $u=4$,\r\nand when $x=4$, $u=16$. So we can do this:\r\n$$\r\n  \\int_2^4 x\\sin(x^2)\\,dx=\r\n  \\int_4^{16} {1\\over 2} \\sin u\\,du=\\left.-{1\\over 2}(\\cos u)\\right|_4^{16}\r\n  =-{1\\over 2}\\cos(16)+{1\\over 2}\\cos(4).\r\n$$\r\nAn incorrect, and dangerous, alternative is something like this:\r\n$$\r\n  \\int_2^4 x\\sin(x^2)\\,dx=\\int_2^4 {1\\over 2} \\sin u\\,du=\r\n  \\left.-{1\\over 2}\\cos (u)\\right|_2^4=\r\n  \\left.-{1\\over 2}\\cos(x^2)\\right|_2^4=-{1\\over 2}\\cos(16)+{1\\over\r\n  2}\\cos(4).\r\n$$\r\nThis is incorrect because $\\ds\\int_2^4 {1\\over 2} \\sin u\\,du$\r\nmeans that $u$ takes on values between 2 and 4, which is wrong. It\r\nis dangerous, because it is very easy to get to \r\nthe point $\\ds\\left.-{1\\over 2}\\cos (u)\\right|_2^4$ and forget to substitute\r\n$\\ds x^2$ back in for $u$, thus getting the incorrect answer\r\n$\\ds -{1\\over 2}\\cos(4)+{1\\over 2}\\cos(2)$. An acceptable alternative is something like:\r\n$$ \r\n  \\int_2^4 x\\sin(x^2)\\,dx=\\int_{x=2}^{x=4} {1\\over 2} \\sin u\\,du=\r\n  \\left.-{1\\over 2}\\cos (u)\\right|_{x=2}^{x=4}=\r\n  \\left.-{1\\over 2}\\cos(x^2)\\right|_2^4=-{\\cos(16)\\over 2}+{\\cos(4)\\over2}.\r\n$$\r\n\\end{solution}\r\n\r\nTo summarize, we have the following.\r\n\r\n\\begin{theorem}{Substitution Rule for Definite Integrals}{SubstitutionRuledef}\r\nIf $g'$ is continuous on $[a,b]$ and $f$ is continuous on the range of $u=g(x)$, then\r\n$$\\int_a^b f(g(x))g'(x)\\,dx=\\int_{g(a)}^{g(b)}f(u)\\,du.$$\r\n\\end{theorem}\r\n\r\n\\begin{example}{Substitution Rule}{SubstitutionRuledef2}\r\nEvaluate $\\ds\\int_{1/4}^{1/2}{\\cos(\\pi t)\\over\\sin^2(\\pi t)}\\,dt$. \r\n\\end{example}\r\n\r\n\\begin{solution} \r\nLet $u=\\sin(\\pi t)$ so $du=\\pi\\cos(\\pi t)\\,dt$ or $du/\\pi=\\cos(\\pi\r\nt)\\,dt$.\r\nWe change the limits to $\\ds \\sin(\\pi/4)=\\sqrt2/2$ and \r\n$\\sin(\\pi/2)=1$.\r\nThen\r\n$$\r\n  \\int_{1/4}^{1/2}{\\cos(\\pi t)\\over\\sin^2(\\pi t)}\\,dt=\r\n  \\int_{\\sqrt2/2}^{1}{1\\over \\pi}{1\\over u^2}\\,du=\r\n  \\int_{\\sqrt2/2}^{1} {1\\over \\pi}u^{-2}\\,du=\r\n  \\left.{1\\over \\pi}{u^{-1}\\over -1}\\right|_{\\sqrt2/2}^{1}=\r\n  -{1\\over\\pi}+{\\sqrt2\\over\\pi}.\r\n$$\r\n\\end{solution}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:SubRule}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\nFind the following indefinite and definite integrals.\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int (1-t)^9\\,dt$\r\n\\begin{sol}\r\n $\\ds -(1-t)^{10}/10+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int (x^2+1)^2\\,dx$\r\n\\begin{sol}\r\n $\\ds x^5/5+2x^3/3+x+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int x(x^2+1)^{100}\\,dx$\r\n\\begin{sol}\r\n $\\ds (x^2+1)^{101}/202+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int {1\\over\\root 3 \\of {1-5t}}\\,dt$ \r\n\\begin{sol}\r\n $\\ds -3(1-5t)^{2/3}/10+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int \\sin^3x\\cos x\\,dx$\r\n\\begin{sol}\r\n $\\ds (\\sin^4x)/4+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int x\\sqrt{100-x^2}\\,dx$\r\n\\begin{sol}\r\n $\\ds -(100-x^2)^{3/2}/3+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int {x^2\\over\\sqrt{1-x^3}}\\,dx$\r\n\\begin{sol}\r\n $\\ds \\ds -2\\sqrt{1-x^3}/3+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int \\cos(\\pi t)\\cos\\bigl(\\sin(\\pi t)\\bigr)\\,dt$\r\n\\begin{sol}\r\n $\\ds \\sin(\\sin\\pi t)/\\pi+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int {\\sin x\\over\\cos^3 x}\\,dx$\r\n\\begin{sol}\r\n $\\ds \\ds 1/(2\\cos^2 x)=(1/2)\\sec^2x+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int\\tan x\\,dx$\r\n\\begin{sol}\r\n $-\\ln|\\cos x|+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n  $\\ds\\int_0^\\pi\\sin^5(3x)\\cos(3x)\\,dx$\r\n\\begin{sol}\r\n $0$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int\\sec^2x\\tan x\\,dx$\r\n\\begin{sol}\r\n $\\ds \\tan^2(x)/2+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int_0^{\\sqrt{\\pi}/2} x\\sec^2(x^2)\\tan(x^2)\\,dx$\r\n\\begin{sol}\r\n $1/4$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int {\\sin(\\tan x)\\over\\cos^2x}\\,dx$\r\n\\begin{sol}\r\n $-\\cos(\\tan x)+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int_3^4 {1\\over(3x-7)^2}\\,dx$\r\n\\begin{sol}\r\n $1/10$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int_0^{\\pi/6}(\\cos^2x - \\sin^2x)\\,dx$\r\n\\begin{sol}\r\n $\\ds \\sqrt3/4$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int {6x\\over(x^2 - 7)^{1/9}}\\,dx$\r\n\\begin{sol}\r\n $\\ds (27/8)(x^2-7)^{8/9}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int_{-1}^1 (2x^3-1)(x^4-2x)^6\\,dx$\r\n\\begin{sol}\r\n $\\ds -(3^7+1)/14$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int_{-1}^1 \\sin^7 x\\,dx$\r\n\\begin{sol}\r\n $0$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds\\int f(x) f'(x)\\,dx$ \r\n\\begin{sol}\r\n $\\ds f(x)^2/2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "a65f6fe06a2c8057bfd45245c226df2e1fde3f57", "size": 11787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7-techniques-of-integration/7-1-sub-rule_old.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "7-techniques-of-integration/7-1-sub-rule_old.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "7-techniques-of-integration/7-1-sub-rule_old.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.1589861751, "max_line_length": 143, "alphanum_fraction": 0.5982014083, "num_tokens": 4621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951143326725, "lm_q2_score": 0.8840392893839085, "lm_q1q2_score": 0.746036437189208}}
{"text": "If you haven't downloaded and unzipped \\href{https://libaoj.in/courses/2021f/MATH3341/zip/Math.3341.zip}{\\texttt{Math.3341.zip}}. Download and unzip it under \\verb|H:| (H Drive if you are working on the Remote Lab). Change the current working directory by typing \\verb|cd H:\\Math.3341\\Math.3341.Lab.03| in the Command Window, and type \\verb|edit lab_03_script| in the Command Window to edit \\verb|lab_03_script.m|.\n\n\n%---------------------------------------------\n\\section{Anonymous Functions}\n%---------------------------------------------\n\\begin{enumerate}[(a)]\n  \\item Define an anonymous function \\verb|rowSums| which calculates the row sums of a matrix of any dimension. Then define \\verb|magicMat5| and \\verb|magicMat7| to be a $5 \\times 5$ and a $7 \\times 7$ magic square matrix, respectively. Compute \\verb|magicMat5RowSums| by calling \\verb|rowSums(magicMat5)|, and compute \\verb|magicMat7RowSums| by calling \\verb|rowSums(magicMat7)|.\n  \\item Define anonymous functions \\verb|f| and \\verb|g|, where $f(x) = x \\ln(x)$ and $g(y) = y e^{y}$. Create another anonymous function \\verb|h| by composing \\verb|f| and \\verb|g|, i.e., $h(z) = g(f(z))$. Use \\verb|linspace| to define a \\emph{column vector} \\verb|z|, of which the range is from $1$ to $5$ with $11$ entries. Evaluate function \\verb|h| at \\verb|z|, and assign the result to \\verb|hz|.\n  \\item Define an anonymous function \\verb|matProd| for calculating the product of two matrices, that is, $matProd(A, B) = ABB^{T} A^{T}$. Define \\verb|A| and \\verb|B| using \\verb|colon|, \\verb|reshape| and \\verb|transpose| as follows,\n    \\begin{equation*}\n      A = \\begin{bmatrix}\n        1 & 2 & 3 \\\\\n        4 & 5 & 6\n      \\end{bmatrix},\n      B = \\begin{bmatrix}\n        7 & 10 & 13 & 16 \\\\\n        8 & 11 & 14 & 17 \\\\\n        9 & 12 & 15 & 18\n      \\end{bmatrix}.\n    \\end{equation*}\n    Store the result of \\verb|matProd(A, B)| to \\verb|matProdAB|.\n  \\item Define an anonymous function \\verb|p|, where\n    \\begin{equation*}\n      p(x) = \\begin{cases}\n        x^3 & \\text{if $x < -1$}, \\\\\n        x & \\text{if $-1 \\leq x \\leq 1$}, \\\\\n        x^2 & \\text{if $x > 1$}.\n      \\end{cases}\n    \\end{equation*}\n    Next visualize $p(x)$ using \\verb|fplot| on [-2, 2] (Use \\verb|help fplot| for more details about \\verb|fplot|). Then run \\verb|print(gcf, '-dpng', 'lab_03_1d.png')| to save the plot to a \\verb|.png| file.\n\\end{enumerate}\n\n%---------------------------------------------\n\\section{Function Files}\n%---------------------------------------------\n\\begin{minipage}[t]{0.50\\linewidth}\n\\begin{algorithm}[H]\n    \\label{alg:recursive}\n    \\caption{Recursive Factorial}\n    \\SetCommentSty{\\color{gray}}\n    \\SetAlgoLined\n    \\LinesNumbered\n    \\SetKwProg{Fn}{Function}{:}{end}\n    \\Fn{$\\operatorname{factorialRecursive}(n)$}{\n        \\KwIn{$n$: an nonnegative integer}\n        \\KwOut{$f$: $n!$}\n        \\uIf{$n = 0$} {\n            $f \\gets 1$\\;\n        }\n        \\Else {\n            $f \\gets n \\times \\operatorname{factorialRecursive}(n - 1)$\\;\n        }\n    }\n\\end{algorithm}\n\\end{minipage}\n\\hfill\n\\begin{minipage}[t]{0.48\\linewidth}\n\\begin{algorithm}[H]\n    \\label{alg:iterative}\n    \\caption{Iterative Factorial}\n    \\SetCommentSty{\\color{gray}}\n    \\SetAlgoLined\n    \\LinesNumbered\n    \\SetKwProg{Fn}{Function}{:}{end}\n    \\Fn{$\\operatorname{factorialIterative}(n)$}{\n        \\KwIn{$n$: an nonnegative integer}\n        \\KwOut{$f$: $n!$}\n        $f \\gets 1$\\;\n        \\For{$i \\gets 1$ \\KwTo $n$} {\n            $f \\gets f \\times i$;\n        }\n    }\n\\end{algorithm}\n\\end{minipage}\n\n\\begin{enumerate}[(a)]\n    \\item Create a function file \\verb|factorialRecursive.m| to implement the pseudocode in Algorithm \\ref{alg:recursive}.\n    \\item Create a function file \\verb|factorialIterative.m| to implement the pseudocode in Algorithm \\ref{alg:iterative}.\n    \\item In the script file \\verb|lab_03_script.m|, use a for-loop to calculate $n!$ where $n = 1, \\ldots, 20$ by calling the above two function files as follows\n        \\begin{lstlisting}[style=MATLAB]\nfprintf('%2s %20s %20s\\n', 'n', 'factorialRecursive', 'factorialIterative');\nfor n = 1:20\n    f1 = factorialRecursive(n);\n    f2 = factorialIterative(n);\n    fprintf('%2d %20d %20d\\n', n, f1, f2);\nend\n        \\end{lstlisting}\n\\end{enumerate}\n\n%---------------------------------------------\n\\section{Application: Real-Life Problems}\n%---------------------------------------------\n\n\\begin{enumerate}[(a)]\n  \\item Create a function file \\verb|dayOfWeek.m| to calculate day of week of a specific date. It is known that January 1st, 1970 is Thursday. In the script file \\verb|lab_03_script|, calculate the day of week for 01-07-1970, 03-07-1970, 03-08-1971, 08-08-1988, 09-09-1999, 02-10-2021. Here is the suggested syntax for the function: \\verb|d = dayOfWeek(year, month, day)|. For example, calling \\verb|dayOfWeek(1970, 1, 1)| should return \\verb|'Thursday'|. You may use the provided function file \\verb|isLeapYear.m|, use \\verb|help isLeapYear| for more information. You should use both \\verb|if| and \\verb|swtich| statements.\n\n    Hint: Given that 01-01-1970 is a Thursday, your job is to determine the day of week of a specific date. You can compute the total number of days elapsed since 01-01-1970, disregard the number of weeks past between the dates and add the remainder to the day of week of 01-01-1970 to obtain the day of week of the given date. For example,\n    \\begin{itemize}\n      \\item 01-02-1970: 1 day elapsed since 01-01-1970, Thursday + 1 day = Friday. Therefore, 01-02-1970 is a Friday;\n      \\item 01-08-1970: 7 days elapsed since 01-01-1970, Thursday + 7 days = Thursday + 1 week = Thursday. Therefore, 01-08-1970 is a Thursday;\n      \\item 03-02-1970: 31 (number of days in Jan) + 28 (number of days in Feb) + 2 (number of days past in March) $- 1 = 60$ days elapsed since 01-01-1970, Thursday + 60 days = Thursday + 8 week + 4 days = Thursday + 4 days = Sunday + 1 day = Monday. Therefore, 03-02-1970 is a Monday;\n    \\end{itemize}\n  \\item Shop A is selling a beverage which costs \\$2 per bottle and there are rules for promotional sales for the beverage:\n    \\begin{itemize}\n      \\item You can exchange 4 caps for 1 full bottle of the same beverage for free;\n      \\item You can exchange 2 empty bottles (without caps) for 1 full bottle of the same beverage for free.\n    \\end{itemize}\n    You have $\\$10$ in your pocket. What is the maximum number of bottles of the beverage you can get? Solve this question by writing a function \\verb|maxBeverageBottles|.\n    \\begin{itemize}\n      \\item The function can be called as below:\n\n        \\verb|maxBeverageBottles(money, pricePerNewBottle, capsPerNewBottle, emptyBottlesPerNewBottle)|\n        which returns the maximum number of bottles you can get with \\verb|money|.\n      \\item \\verb|money| is the amount of money available;\n      \\item \\verb|pricePerNewBottle| is the unit price for buying a new bottle;\n      \\item \\verb|capsPerNewBottle| is the number of caps needed for exchanging 1 free bottle;\n      \\item \\verb|emptyBottlesPerNewBottle| is the number of empty bottles needed for exchanging 1 free bottle.\n    \\end{itemize}\n    Then in the script file, store the result of calling \\verb|maxBeverageBottles(10, 2, 4, 2)| to \\verb|maxBottles1|. What if you have $\\$1000$ in your pocket, the beverage still costs $\\$2$/bottle, but $5$ caps/bottle or $3$ empty bottles/bottle for exchanging a new free bottle, how many bottles can you get? Store the result to \\verb|maxBottle2|. You may find \\verb|floor| and \\verb|mod| useful.\n\n    Hint: For each new bottle you get, you have a new pair of cap and empty bottle (after consumed). So you can get new bottles until no enough money/caps/empty bottles.\n\\end{enumerate}\n\nBefore proceeding, make sure you suppress the output in the function files and do \\textsc{not} suppress the output in the script file. In the Command Window, enter the command \\verb`diary('lab_03_output.txt')`, run the script file \\verb|lab_03_script.m|, then type \\verb`diary off` to store the output to \\verb`lab_03_output.txt`. Then upload the script file \\verb|lab_03_script.m|, plot file \\verb|lab_03_1d.png|, output file \\verb|lab_03_output.txt|, and function files \\verb|factorialIterative.m|, \\verb|factorialRecursive.m|, \\verb|dayOfWeek.m|, \\verb|maxBeverageBottles.m| to the folder \\verb|src| on Overleaf.\n\n", "meta": {"hexsha": "83a7a1c49823a2a22bc8117b668f5a266ff175ef", "size": 8321, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/Math.3341.Lab.03/exercise/body.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/Math.3341.Lab.03/exercise/body.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/Math.3341.Lab.03/exercise/body.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.5196850394, "max_line_length": 624, "alphanum_fraction": 0.6626607379, "num_tokens": 2566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8840392893839085, "lm_q1q2_score": 0.746036419835325}}
{"text": "\\lab{Markov Chains}{Markov Chains}\n\\label{lab:Markov}\n\\objective{\nA \\emph{Markov chain} is a finite collection of states with specified probabilities for transitioning from one state to another.\nThey are characterized by the fact that the future behavior of the system depends only on its current state.\nMarkov chains have far ranging applications; in this lab, we create a Markov chain for generating random English sentences.}\n\n% TODO: Changing column_sum = 1 to row_sum = 1 (transpose all transition matrices, ij^th entry --> probability of going from from state i to state j (instead of the other way around). Makes implementing everything easier.)\n\n% TODO: Update test driver, solutions+spec on class implementation.\n\n\\section*{State Space Models} % ===============================================\n\nMany systems can be described by a finite number of states.\n% A Markov chain is a collection of states, together with the probabilities of moving from one state to another.\nFor example, a board game where players move around the board based on die rolls can be modeled by a Markov chain.\nEach space represents a state, and a player is said to be in a state if their piece is currently on the corresponding space.\nIn this case, the probability of moving from one space to another only depends on the players current location: where the player was on a previous turn does not affect their current turn.\n\nFinite Markov chains have an associated transition matrix that stores all the information about the chain.\nThe $(ij)^{th}$ entry of the matrix gives the probability of moving from state $j$ to state $i$.\nThus the columns of the transition matrix must sum to 1. %\\footnote{This type of transition matrix is called \\emph{column-stochastic}. Row stochastic matrices are also often used ti model Markov chains.}\n% TODO: Note about column-stochastic v row-stochastic transition matrices.\n\nConsider a very simple weather model where the probability of being hot or cold depends on the weather of the previous day.\nIf the probability that tomorrow is hot given that today is hot is 0.7, and the probability that tomorrow is cold given that today is cold is 0.4, then by assigning hot to the $0^{th}$ row and column, and cold to the $1^{st}$ row and column, this Markov chain has the following transition matrix:\n\n\\[W = \\left[\\begin{array}{cc}\n0.7 & 0.6 \\\\\n0.3 & 0.4 \\end{array} \\right]\\] \n\n% TODO: insert a PICTURE of a this Markov chain!\n\nIf it is hot today, we examine the $0^{th}$ column of $W$.\nThere is a $70\\%$ chance that tomorrow will be hot ($0^{th}$ row), and a $30\\%$ chance that tomorrow will be cold ($1^{st}$ row).\nConversely, if it is cold today, there is a $60\\%$ chance that tomorrow will be hot, and a $40\\%$ chance that tomorrow will be cold.\n\n\\begin{problem} % Problem: stochasticity. \nTransition matrices for Markov chains are efficiently stored as NumPy arrays.\nWrite a function that accepts a dimension $n$ and returns the transition matrix for a random Markov chain with $n$ states.\n\\\\\n(Hint: use array broadcasting to avoid looping.)\n\\end{problem}\n\n\\subsection*{Simulating State Transitions} % ----------------------------------\n\nIn a general finite Markov chain, if we are in state $j$ then the $j^{th}$ column of the transition matrix gives the probabilities of moving to any other state $i$.\nBy definition, these probabilities sum to $1$.\nThus, the entries of each column partition the interval $[0, 1]$, and we can choose the next state to move to by generating a random number between $0$ and $1$.\n\nConsider again the weather model example from the previous section.\nSuppose that today is hot, and that we want to simulate tomorrow's weather.\nThe column that corresponds to ``hot'' in the transition matrix is $[0.7, 0.3]^T$.\nIf we generate a random number and it is smaller than $0.3$, then our simulation indicates that tomorrow will be cold.\nConversely, if the random number is between $0.3$ and $1$, then the simulation says that tomorrow will be hot.\nThe following code implements this idea.\n\n\\begin{lstlisting}\nimport numpy as np\n\ndef forecast():\n\t\"\"\"Forecast tomorrow's weather given that today is hot.\"\"\"\n\n\ttransition_matrix = np.array([[0.7, 0.6], [0.3, 0.4]])\n\t# Sample from the standard uniform distribution to choose a new state.\n\tif np.random.random() < transition_matrix[1,0]:\n\t\tprint \"Cold\"\n\t\treturn 1\n\telse:\n\t\tprint \"Hot\"\n\t\treturn 0\n\\end{lstlisting}\n\n\\begin{problem} % Problem: Forecasting over several days.\nModify \\li{forecast()} so that it accepts a parameter \\li{days} and runs a simulation of the weather for the number of days given.\nReturn a list containing the day-by-day weather predictions (0 for hot, 1 for cold).\nAssume the first day is hot, but do not include the data from the first day in the list of predictions.\nThe resulting list should therefore have \\li{days} entries.\n\\end{problem}\n\nFor Markov chains with very few states, the approach in \\li{forecast()} is practical and the implementation is fairly simple.\nHowever, small Markov chains are typically not very useful in applications.\n\n\\subsection*{Larger Chains} % -------------------------------------------------\n\nThe \\li{forecast()} function makes one random draw from a \\emph{uniform} distribution to simulate a state change.\nFor larger Markov chains, we draw from a \\emph{multinomial} distribution.\nA multinomial distribution is a multivariate generalization of the binomial distribution.\nA single draw from a binomial distribution with parameter $p$ indicates successes or failure of a single experiment with probability $p$ of success.\nThe classic example is a coin flip, where the $p$ is the probability that the coin lands heads side up.\nA single draw from a multinomial distribution with parameters $\\left(p_1, p_2, ..., p_n \\right)$ indicates which of $n$ outcomes occurs.\nIn this case the classic example is a dice roll, with $6$ possible outcomes instead of the $2$ in a coin toss.\n\n\\begin{lstlisting}\n# To simulate a single dice roll, store the probabilities of each outcome.\n>>> probabilities = np.array([1./6, 1./6, 1./6, 1./6, 1./6, 1./6])\n\n# Make a single random draw (roll the die once).\n>>> np.random.multinomial(1, probabilities)         \narray([0, 0, 0, 1, 0, 0])                       # The roll resulted in a 4.\n\\end{lstlisting}\n\n\\begin{problem} % Problem: 4 states instead of 2. Multinomial transitioning.\nLet the following be the transition chain for a Markov chain modeling weather with four states: hot, mild, cold, and freezing.\n\n\\[ W^\\prime = \\left[\\begin{array}{cccc}\n0.5 & 0.3 & 0.1 & 0\\\\\n0.3 & 0.3 & 0.3 & 0.3\\\\\n0.2 & 0.3 & 0.4 & 0.5\\\\\n  0 & 0.1 & 0.2 & 0.2\\end{array} \\right]\\]\nwith hot, mild, cold, and freezing corresponding to columns (and rows) 0, 1, 2, and 3, respectively.\n\nWrite a new function that accepts a parameter \\li{days} and runs the same kind of simulation as \\li{forecast()}, but that uses the new four-state transition matrix.\nThis time, assume the first day is mild.\nReturn a list containing the day-to-day results (0 for hot, 1 for mild, 2 for cold, and 3 for freezing).\n\\label{problem:transition}\n\\end{problem}\n\n\\begin{problem} % Problem: Analysis of results.\nWrite a function that investigates and interprets the results of the simulations in the previous two problems.\nSpecifically, find the average percentage of days that are hot, mild, cold, and freezing in each simulation.\nDoes changing the starting day alter the results?\nPrint a report of your findings.\n\\end{problem}\n\n\\section*{Using Markov Chains to Simulate English} % ==========================\n% TODO: is it okay to make this reference?\nOne of the original applications of Markov chains was to study natural languages.\\footnote{In computer science, a \\emph{natural language} is a spoken language, like English or Russian. See \\url{http://langvillea.people.cofc.edu/MCapps7.pdf} for some details on the early applications of Markov chains, including the study of natural languages.}\nIn the early $20^{th}$ century, Markov used his chains to model how Russian switched from vowels to consonants.\nBy mid-century, they had been used as an attempt to model English.\nIt turns out that Markov chains are, by themselves, insufficient to model very good English.\nHowever, they can approach a fairly good model of bad English, with sometimes amusing results.\n\nBy nature, a Markov chain is only concerned with its current state.\nThus a Markov chain simulating transitions between English words is completely unaware of context or even of previous words in a sentence.\nFor example, a Markov chain's current state may be the word ``continuous.''\nThen the chain would say that the next word in the sentence is more likely to be ``function'' rather than ``raccoon.''\nHowever, without the context of the rest of the sentence, even two likely words stringed together may result in gibberish.\n\nWe restrict ourselves to a subproblem of modeling the English of a specific file.\nThe transition probabilities of the resulting Markov chain will reflect the sort of English that the source authors speak.\nThus the Markov chain built from \\emph{The Complete Works of William Shakespeare} will differ greatly from, say, the Markov chain built from a collection of academic journals.\nWe will call the source collection of works in the next problems the \\emph{training set}.\n\n\\subsection*{Making the Chain} % ----------------------------------------------\n\nIn the weather models of the previous section, we chose a fixed number of states to simulate.\nHowever, in English, sentences are of varying length.\nTo capture this feature in a Markov model, we include a \\emph{start state} and an \\emph{end state} in the model in addition to the words of the training set.\nThe start state should only transition to words that appear at the beginning of a sentence in the training set, and only words that appear at the end a sentence in the training set should transition to the end state.\nThus if a training set has $N$ unique words, the transition matrix will be $(N+2) \\times (N+2)$.\n\nAfter determining the states in the Markov chain, we need to determine the transition probabilities between the states.\nAs with the weather models, each state must be assigned a row and column in the transition matrix.\nThen, while iterating through the sentences of the training set, we fill in the entries of the transition matrix.\nWhen word $b$ follows word $a$, we add one to the $(b,a)^{th}$ entry of the matrix.\nOnce we have done this for every adjacent pair of words in the training set, we normalize the columns so that they each sum to one.\n\nConsider the following small training set as an example.\n\n\\begin{lstlisting}\n<<I am Sam Sam I am.\nDo you like green eggs and ham?\nI do not like them, Sam I am.\nI do not like green eggs and ham.>>\n\\end{lstlisting}\n\nIf we include punctuation (so ``ham?'' and ``ham.'' are counted as distinct words) and do not alter the capitalization (so ``Do'' and ``do'' are also different), there are 15 unique words in this training set:\n\\begin{align*}\n\\text{``I'', ``am'', ``Sam'', ``am.'', ``Do'', ``you'', ``like'', ``green'',}\n\\\\\n\\text{``eggs'', ``and'', ``ham?'', ``do'', ``not'', ``them,'', and ``ham.''.}\n\\end{align*}\n\nWith start and stop states, the transition matrix should therefore be $17 \\times 17$.\nThe start state should transition to the words ``I'' and ``Do'', and the words ``am.'', ``ham?'', and ``ham?'' should transition to the end state.\nLetting ``{\\color[rgb]{.3,.6,.1}\\$tart}'' represent the start state and ``{\\color{red}\\$top}'' represent the stop state, we first count the number of times that each state transitions to another state:\n\n\\begin{align*}\n\\begin{blockarray}{cccccccc}\n& \\text{\\textcolor[rgb]{.3,.6,.1}{\\$tart}} & \\text{I} & \\text{am} & \\text{Sam} & & \\text{ham.} & \\text{\\textcolor[rgb]{1,0,0}{\\$top}} \\\\\n\\begin{block}{c(ccccccc)} % TODO: turn these into hard brackets?\n\\text{\\textcolor[rgb]{.3,.6,.1}{\\$tart}} \t& 0 & 0 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{I} \t\t& 3 & 0 & 0 & 2 & \\ldots & 0 & 0\\\\\n\\text{am} \t\t& 0 & 1 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{Sam} \t\t& 0 & 0 & 1 & 1 & \\ldots & 0 & 0\\\\\n& \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots\\\\\n\\text{ham.} \t& 0 & 0 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{\\textcolor[rgb]{1,0,0}{\\$top}} \t\t& 0 & 0 & 0 & 0 & \\ldots & 1 & 1\\\\\n\\end{block}\\end{blockarray}\n\\end{align*}\nNow we divide each column by the column sum so that each column sums to one.\n\n\\begin{align*}\n\\begin{blockarray}{cccccccc}\n& \\text{\\textcolor[rgb]{.3,.6,.1}{\\$tart}} & \\text{I} & \\text{am} & \\text{Sam} & & \\text{ham.} & \\text{\\textcolor[rgb]{1,0,0}{\\$top}} \\\\\n\\begin{block}{c(ccccccc)} % TODO: turn these into hard brackets?\n\\text{\\textcolor[rgb]{.3,.6,.1}{\\$tart}} & 0 & 0 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{I} \t\t& 3/4 & 0 & 0 & 2/3 & \\ldots & 0 & 0\\\\\n\\text{am} \t\t& 0 & 1/5 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{Sam} \t\t& 0 & 0 & 1 & 1/3 & \\ldots & 0 & 0\\\\\n& \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots\\\\\n\\text{ham.} \t& 0 & 0 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{\\textcolor[rgb]{1,0,0}{\\$top}} \t& 0 & 0 & 0 & 0 & \\ldots & 1 & 1\\\\\n\\end{block}\\end{blockarray}\n\\end{align*}\n\nThe $3/4$ correctly indicates that 3 out of 4 times, the sentences in the training set start with the word ``I''.\nSimilarly, the $2/3$ and $1/3$ tell us that ``Sam'' is followed by ``I'' twice and by ``Sam'' once in the training set.\nNote that ``am'' (without a period) always transitions to ``Sam'' and that ``ham.'' (with a period) always transitions the stop state.\nFinally, to avoid a column of zeros, we place a one in the bottom right hand corner of the matrix (the end state always transitions to itself).\n\nThe entire procedure of creating the transition matrix for the Markov chain with words from a file as states, with some hints for implementation, is summarized below in Algorithm \\ref{alg:MarkovSentencesTransitionMatrix}.\n\n\\newpage % Might be unnecessary in later editions.\n\n\\begin{algorithm} % Read a file and convert it into a Markov chain.\n\\begin{algorithmic}[1]\n\\Procedure{MakeTransitionMatrix}{}\n\\State Count the number of unique words in the training set.\n\\State Initialize a square array of zeros of the appropriate size to be the transition matrix (remember to account for the start and stop states).\n\\State Initialize a list of states, beginning with ``\\$tart''.\n\\For {each sentence in the training set}\n    \\State Split the sentence into a list of words.\n    \\State Add each \\emph{new} word to the list of states.\n    \\State Add 1 to the entry of the transition matrix corresponding to the start state transitioning to the first word of the sentence.\n   \t\\State For each consecutive pair $(a, b)$ of words in the list of words, add 1 to the entry of the transition matrix corresponding to moving from state $a$ to state $b$.\n\t\\item Add 1 to the entry of the transition matrix corresponding to the last word of the sentence transitioning to the stop state.\n\\EndFor\n\\State Make sure the stop state transitions to itself.\n\\State Normalize each column by dividing by the column sums (hint: array broadcasting).\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Convert a training set of sentences into a Markov chain.}\n\\label{alg:MarkovSentencesTransitionMatrix}\n\\end{algorithm}\n\n\\begin{problem} % Problem: Class that makes a Markov chain from a file.\nWrite a class called \\li{SentenceGenerator}.\nThe constructor should accept a filename (for the training set).\nRead the file and build a transition matrix from its contents.\nYou may assume that the file has one complete sentence written on each line.\n\\label{problem:MarkovClassPt1}\n\\end{problem}\n\n% TODO: Put a picture of the actual Markov chain here and discuss a little.\n\n\\begin{problem} % Problem: Create random sentences\nAdd a method to the \\li{SentenceGenerator} class called \\li{babble()}.\nBegin at the start state and use the strategy from Problem \\ref{problem:transition} to transition through the object's Markov chain.\nKeep track of the path through the chain and the corresponding path of words.\nWhen the stop state is reached, stop transitioning and terminate the sentence.\nReturn the resulting sentence as a single string.\n\nFor example, your \\li{SentenceGenerator} class should be able to create random sentences that sound somewhat like Yoda speaking.\n\\begin{lstlisting}\n>>> yoda = SentenceGenerator(\"Yoda.txt\")\n>>> for i in xrange(5):\n... \tprint(yoda.babble())\n...\n<<\nImpossible to my size, do not!\nFor eight hundred years old to enter the dark side of Congress there is.\nBut beware of the Wookiees, I have.\nFear leads to eat as well.\nBut agree on this, we must, and find your weapon!>>\n\\end{lstlisting}\n\\end{problem}\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Large Training Sets} % -------------------------------------------\n\nThe approach in the previous problems begins to fail as the training set grows larger.\nFor example, a single Shakespearean play may not be large enough to cause memory problems, but \\emph{The Complete Works of William Shakespeare} certainly will.\n\nTo accommodate larger data sets, consider use a sparse matrix for the transition matrix in instead of a regular NumPy array. %(use the \\li{lil_matrix} from the \\li{scipy.sparse} library). % Why lil_matrix?\nEnsure that the process still works on small training sets, then proceed to larger training sets.\nHow are the resulting sentences different if a very large training set is used instead of a small training set?\n\n% \\subsection*{Natural Language Processing Tools} % -----------------------------\n\n% TODO: A brief overview of the \\li{nltk} package.\n", "meta": {"hexsha": "197c332e3f96c6bbf43a5f3595c97c11b7369eae", "size": 17510, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol2A/MarkovChains/ColumnStochasticVersion.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol2A/MarkovChains/ColumnStochasticVersion.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol2A/MarkovChains/ColumnStochasticVersion.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 61.6549295775, "max_line_length": 344, "alphanum_fraction": 0.7236436322, "num_tokens": 4549, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7460364117040835}}
{"text": "\\subsection{Test 1}\r\n\\begin{enumerate}\r\n\t\\item Consider two intersecting lines $\\vec{r_1}(t) = \\langle 2, 3, 4t \\rangle$ and $\\vec{r_2}(t) = \\langle 2+t, 3+2t, 0 \\rangle$. Give the direction vector of each line. Find the equation of the plane which contains both lines. Draw a diagram of the lines, the plane, and the relevant vectors.\\\\\r\n\t\\indent\r\n\tThe direction vector of a line is the derivative of the position vector.\r\n\t\\begin{itemize}\r\n\t\t\\item Direction 1: $\\langle 0, 0, 4 \\rangle$\r\n\t\t\\item Direction 2: $\\langle 1, 2, 0 \\rangle$\r\n\t\\end{itemize}\r\n\tA the normal vector of the plane is the cross product of the direction vectors.\r\n\t\\begin{itemize}\r\n\t\t\\item $\\vec{n} = \\langle 0, 0, 4 \\rangle \\times \\langle 1, 2, 0 \\rangle = \\langle -8, 4, 0 \\rangle$\r\n\t\\end{itemize}\r\n\tThe lines intersect when $t = 0$ at $(2,3,0)$.\r\n\tSo, the plane equation is: $\\langle -8, 4, 0 \\rangle \\cdot \\langle x-2, y-3, z \\rangle = 0$\r\n\t\r\n\t\\begin{figure}[h]\r\n\t\t\\centering\r\n\t\t\\includegraphics[scale=.5]{Images/additionalMaterials/test1_plane}\r\n\t\\end{figure}\r\n\t\r\n\t\\item Given the VVF $\\vec{r}(t)\\langle 10t, 7\\cos{t}, 7\\sin{t} \\rangle$...\r\n\t\\begin{enumerate}[label=\\alph*.]\r\n\t\t\\item Compute the unit tangent vector $\\hat{T}(t)$ and the unit normal vector $\\hat{N}(t)$.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\hat{T} = \\frac{\\vec{r^\\prime}(t)}{\\norm{\\vec{r^\\prime}(t)}}\t\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{r^\\prime}(t) = \\langle 10, -7\\sin{t}, 7\\cos{t} \\rangle\t\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\norm{\\vec{r^\\prime}(t)} = \\sqrt{10^2 + (-7\\sin{t})^2 + (7\\cos{t})^2} = \\sqrt{149}\t\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\hat{T}(t) = \\frac{1}{\\sqrt{149}}\\langle 10, -7\\sin{t}, 7\\cos{t} \\rangle\t\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\hat{N}(t) = \\frac{\\mathrm{d}\\hat{T}/\\mathrm{d}t}{\\norm{\\mathrm{d}\\hat{T}/\\mathrm{d}t}}\t\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\frac{\\mathrm{d}\\hat{T}}{\\mathrm{d}t} = \\frac{1}{\\sqrt{149}} \\langle 0, -7\\cos{t}, -7\\sin{t} \\rangle\t\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\norm{\\frac{\\mathrm{d}\\hat{T}}{\\mathrm{d}t}} = \\frac{1}{\\sqrt{149}}\\sqrt{(-7\\cos{t})^2 + (-7\\sin{t})^2} = \\frac{7}{\\sqrt{149}}\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\hat{N}(t) = \\langle 0, -\\cos{t},-\\sin{t}\\rangle\r\n\t\t\\end{equation*}\r\n\t\t\r\n\t\t\\item Show that $\\hat{T}\\perp\\hat{N}$ for all $t$.\\\\\r\n\t\tIf $\\hat{T}\\perp\\hat{N}$, then $\\hat{T}\\cdot\\hat{N} = 0$ for all $t$.\\\\\r\n\t\t\\begin{align*}\r\n\t\t\t\\hat{T} \\cdot \\hat{N} &= \\frac{1}{\\sqrt{149}}\\langle 10, -7\\sin{t}, 7\\cos{t} \\rangle \\cdot \\langle 0, -\\cos{t}, -\\sin{t}\\rangle\t\\\\\r\n\t\t\t&= \\frac{1}{\\sqrt{149}}(0 + 7\\sin{t}\\cos{t} - 7\\sin{t}\\cos{t}) = 0 \\\\\r\n\t\t\t&\\implies \\hat{T}\\perp\\hat{N}\r\n\t\t\\end{align*}\r\n\t\\end{enumerate}\r\n\t\r\n\t\\item A cannon fires cannonballs with a speed of $20 \\text{ m} / \\text{s}$. Take acceleration due to gravity to be $g = 10 \\text{m} / \\text{s}^2$.\r\n\t\\begin{enumerate}[label=\\alph*.]\r\n\t\t\\item Starting with a constant acceleration function $\\vec{a} = \\langle 0, -g \\rangle$, find the velocity and position functions ($\\vec{r^\\prime}(t) \\text{ and } \\vec{r}(t)$ respectively) of the cannonball if the cannon is fired from an angle $\\theta$ with respect to the horizontal. Assume the cannonball is initially positioned at the origin.\\\\\r\n\t\tWe know that velocity is the integral of acceleration.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{v}(t) = \\vec{r^\\prime}(t) = \\langle c_1, c_2-gt \\rangle\t\r\n\t\t\\end{equation*}\r\n\t\tWe are given that the initial speed is $20 \\text{ m} / \\text{s}$ at an angle $\\theta$.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{v_0} = 20\\langle \\cos{\\theta}, \\sin{\\theta} \\rangle\t\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{v}(t) = \\langle 20\\cos{\\theta}, 20\\sin{\\theta}-gt \\rangle\t\r\n\t\t\\end{equation*}\r\n\t\tWe know that position is the integral of velocity.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{r}(t) = \\langle 20t\\cos{\\theta} + c_1, 20t\\sin{\\theta} - \\frac{1}{2}gt^2 + c_2 \\rangle\r\n\t\t\\end{equation*}\r\n\t\tWe are given that the cannonball starts at the origin.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{r}(t) = \\langle 20t\\cos{\\theta}, 20t\\sin{\\theta} - \\frac{1}{2}gt^2 \\rangle\t\r\n\t\t\\end{equation*}\r\n\t\tTaking $g = 10 \\text{m} / \\text{s}^2$,\\\\\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{r}(t) = \\langle 20t\\cos{\\theta}, 20t\\sin{\\theta}-5t^2 \\rangle\t\r\n\t\t\\end{equation*}\r\n\t\t\t\r\n\t\t\\item What angle $\\theta$ should the cannon be fired to hit a target on the ground at a distance $40\\text{ m}$ away?\\\\\r\n\t\tWe want to find a point on the trajectory where $y = 0$ and $x = 40$.\r\n\t\t$y = 0$ when $t = 0, 4\\sin{\\theta}$. We can reasonably eliminate $t = 0$ because this is when the cannon first fires and $x = 0$.\\\\\r\n\t\tPlugging in $t = 4\\sin{\\theta}$ to the x-component of position when $x = 40$,\r\n\t\t\\begin{align*}\r\n\t\t\t20\\cos{\\theta} \\cdot 4\\sin{\\theta} &= 40 \\\\\r\n\t\t\t2\\sin{\\theta}\\cos{\\theta} &= 1 \\\\\r\n\t\t\t\\sin{(2\\theta)}=1, 2\\theta &= \\pi/2 \\\\\r\n\t\t\t\\implies \\theta &= \\pi/4\t\t\t\r\n\t\t\\end{align*}\r\n\t\\end{enumerate}\r\n\t\r\n\t\\item Consider the following particle trajectory: $\\vec{r}(t) = \\langle R\\cos{e^t}, R\\sin{e^t}, \\frac{h}{2\\pi}e^t \\rangle$ for $t \\geq 0$. The shape of the trajectory is a helix with radius $R$ and vertical spacing $h$. Find the arc length function $s(t)$ of the trajectory starting with $s(0) = 0$. Give the arc length reparameterization of the helix.\r\n\t\\begin{align*}\r\n\t\ts(t) &= \\int_{0}^{t}{\\norm{\\vec{r^\\prime}(\\tau)}\\mathrm{d}\\tau}\\\\\r\n\t\t\\vec{r^\\prime}(t) &= \\langle -Re^{t}\\sin{e^t}, Re^{t}\\cos{e^t}, \\frac{h}{2\\pi}e^{t} \\rangle\r\n\t\\end{align*}\r\n\t\\begin{align*}\r\n\t\t\\norm{\\vec{r^\\prime}(t)} &= \\sqrt{(-Re^{t}\\sin{e^t})^2 + (Re^{t}\\cos{e^t})^2 + (\\frac{h}{2\\pi}e^t)^2} \\\\\r\n\t\t&= e^{t}\\sqrt{R^2 + \\frac{h^2}{4\\pi^2}}\r\n\t\\end{align*}\r\n\t\\begin{equation*}\r\n\t\ts(t) = \\int_{0}^{t}{e^{\\tau}\\sqrt{R^2 + \\frac{h^2}{4\\pi^2}}\\mathrm{d}\\tau} = \\sqrt{R^2 + \\frac{h^2}{4\\pi^2}(e^{t} - 1)}\r\n\t\\end{equation*}\r\n\tSolving for $t$,\r\n\t\\begin{equation*}\r\n\t\tt = \\ln{\\left(\\frac{s}{\\sqrt{R^2 + \\frac{h^2}{4\\pi^2}}} + 1\\right)}\t\r\n\t\\end{equation*}\r\n\t\\begin{equation*}\r\n\t\t\\vec{r}(s) = \\left< R\\cos{\\left(\\frac{s}{\\sqrt{R^2 + \\frac{h^2}{4\\pi^2}}} + 1\\right)}, R\\sin{\\left(\\frac{s}{\\sqrt{R^2 + \\frac{h^2}{4\\pi^2}}} + 1\\right)}, \\frac{h}{2\\pi}\\left(\\frac{s}{\\sqrt{R^2 +\\frac{h^2}{4\\pi^2}}} + 1\\right) \\right>\r\n\t\\end{equation*}\r\n\t\r\n\t\\item Let $\\vec{r}(t)$ be the position function of a particle trapped on the surface of a sphere centered at the origin. Show that $\\vec{r}(t)\\perp\\frac{\\mathrm{d}}{\\mathrm{d}t}\\vec{r}(t)$ for all $t$.\\\\\r\n\tSince $\\vec{r}(t)$ is on a sphere, $\\norm{\\vec{r}(t)} = R$ and $\\vec{r}(t) \\cdot \\vec{r}(t) = R^2$.\r\n\t\\begin{equation*}\r\n\t\t\\frac{\\mathrm{d}}{\\mathrm{d}t}(\\vec{r}(t) \\cdot \\vec{r}(t)) = 2\\vec{r}(t) \\cdot \\vec{r^\\prime}(t)\t\r\n\t\\end{equation*}\r\n\t\\begin{equation*}\r\n\t\t\\frac{\\mathrm{d}}{\\mathrm{d}t}(\\vec{r}(t) \\cdot \\vec{r}(t)) = \\frac{\\mathrm{d}}{\\mathrm{d}t}R^2 = 0\r\n\t\\end{equation*}\r\n\tSo, \r\n\t\\begin{equation*}\r\n\t\t2\\vec{r}(t) \\cdot \\vec{r^\\prime}(t) = 0\r\n\t\\end{equation*}\r\n\tand \r\n\t\\begin{equation*}\r\n\t\t\\vec{r}(t) \\cdot \\vec{r^\\prime}(t) = 0\t\r\n\t\\end{equation*}\r\n\t\\begin{equation*}\r\n\t\t\\implies \\vec{r}(t)\\perp\\vec{r^\\prime}(t)\t\r\n\t\\end{equation*}\r\n\\end{enumerate}", "meta": {"hexsha": "8acf7c2ea114bb3a7068578f562ba182fec92487", "size": 7006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/additionalMaterials/test1.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/additionalMaterials/test1.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/additionalMaterials/test1.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.1386861314, "max_line_length": 354, "alphanum_fraction": 0.5974878675, "num_tokens": 2942, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.7460364099686951}}
{"text": "\\chapter{Orbital rotations}\n\\label{appendix:orbital-rotations}\n\n\\begin{dfn}\n\\label{dfn:normal-matrix}\n\\thmtitle{Normal matrix}\nA square matrix satisfying $\\bo{N}\\dg\\bo{N}=\\bo{N}\\bo{N}\\dg$ is termed \\textit{normal}.\nSeveral important kinds of matrices meet this criterion:\n\\textit{Hermitian matrices}, $\\bo{H}\\dg=\\bo{H}$;\n\\textit{anti-Hermitian matrices}, $\\bo{A}\\dg=-\\bo{A}$;\nand\n\\textit{unitary matrices}, $\\bo{U}\\dg=\\bo{U}^{-1}$.\nNote that Hermitian and anti-Hermitian matrices can always be written as $\\bo{X}+\\bo{X}\\dg$ and $\\bo{X}-\\bo{X}\\dg$.\n\\end{dfn}\n\n\\begin{rmk}\n\\label{rmk:spectral-theorem}\nThe spectral theorem\\footnote{See \\url{https://en.wikipedia.org/wiki/Spectral_theorem}} for normal matrices says that $\\bo{N}=\\bo{V}\\widetilde{\\bo{N}}\\bo{V}\\dg$ where $\\bo{V}$ is unitary and $\\widetilde{\\bo{N}}$ is diagonal.\nA direct corollary\\footnote{Since there exists a basis in which $\\bo{N}$ is diagonal, statements about $\\bo{N}$ translate into statements about its eigenvalues.} is that the eigenvalues of Hermitian, anti-Hermitian, and unitary matrices can be written as follows.\n\\begin{align}\n  h^*\n=\n  h\n\\implies\n  h\n=\n  \\f\n&&\n  a^*\n=\n-\n  a\n\\implies\n  a\n=\n  i\\f\n&&\n  u^*\n=\n  u^{-1}\n\\implies\n  u\n=\n  e^{i\\f}\n&&\n  \\f\n\\in\n  \\mb{R}\n\\end{align}\nIn words, Hermitian eigenvalues are real, anti-Hermitian eigenvalues are pure imaginary, and unitary eigenvalues lie on the unit circle.\nNote that unitary eigenvalues have the form $u=\\text{exp}(a)$ where $a$ is an anti-Hermitian eigenvalue.\nThis implies that any unitary matrix $\\bo{U}$ can be written as $\\text{exp}(\\bo{A})$, where $\\bo{A}$ is anti-Hermitian.\n\\end{rmk}\n\n\\begin{rmk}\n\\label{rmk:spin-orbital-transformation-law}\nAccording to \\cref{dfn:normal-matrix} and \\cref{rmk:spectral-theorem}, unitary transformations of the spin-orbitals can be parametrized as\n\\begin{align}\n\\label{eq:spin-orbital-transformation}\n  \\y_p'\n=\n  \\sum_q\n  \\y_q\n  (\\text{exp}(\\bo{X} - \\bo{X}\\dg))_{qp}\n\\end{align}\nin terms of a square matrix $\\bo{X}$.\nThe form of this parametrization leads to redundancies.\nIn particular, notice that $(\\bo{X})_{pq}\\equiv z\\,\\delta_{pp'}\\delta_{qq'}$ generates the same transformation as $(\\bo{X})_{pq}\\equiv -z^*\\,\\delta_{pq'}\\delta_{qp'}$.\nThese redundancies are eliminated by setting the upper or lower triangle of $\\bo{X}$ to zero.\nThe creation operators for these orbitals are given by\n$\n  a_p^{\\prime\\,\\dagger}\n=\n  \\sum_q\n  a_q\\dg\n  (\\text{exp}(\\bo{X} - \\bo{X}\\dg))_{qp}\n$.\n\\end{rmk}\n\n\n\\begin{prop}\n\\label{prop:creation-operator-similarity-transform}\n\\thmstatement{\nThe identity\\ \\\n$\\ds{\n  \\text{exp}(G)\\,a_p\\dg\\,\\text{exp}(-G)\n=\n  \\sum_q\n  a_q\\dg\\,\n  (\\text{exp}(\\bo{G}))_{qp}\n}$\\\nholds for any\n$\n  G\n=\n  \\sum_{pq}\n  (\\bo{G})_{pq}\\,\n  a_p\\dg a_q\n$.\n}\\vspace{3pt}\n\\thmproof{\n  This follows from\n  $\n    [G,\\cdot\\,]^m(a_p\\dg)\n  =\n    \\sum_q\n    a_q\\dg\n    (\\bo{G}^m)_{qp}\n  $,\n  which we will prove by induction.\n  For $m=0$ the statement is trivially true.\n  If we assume it holds for $m$, then the following shows that it also holds for $m+1$,\\footnote{\n  The second equality here follows from expanding $G$ and using\n$\n  [a_r\\dg a_s, a_q\\dg]\n=\n  \\no{\n    a_r\\dg\n    \\ctr{}{a}{_s}{}\n    a_s a_q\\dg\n  }\n=\n  a_r\\dg\\,\n  \\delta_{sq}\n$.\n}\n\\begin{align*}\n\\ts{\n  [G,\\cdot\\,]^{m+1}(a_p\\dg)\n=\n  \\sum_q\n  [G, a_q\\dg]\\,\n  (\\bo{G}^m)_{qp}\n=\n  \\sum_{qr}\n  a_r\\dg\n  (\\bo{G})_{rq}\n  (\\bo{G}^m)_{qp}\n=\n  \\sum_r\n  a_r\\dg\n  (\\bo{G}^{m+1})_{rp}\n}\n\\end{align*}\n  which completes the induction.\n  Substituting this result into the Hausdorff expansion of\n$\n  \\text{exp}(G)\\,a_p\\dg\\,\\text{exp}(-G)\n$\nand  recognizing the Taylor expansion of $\\text{exp}(\\bo{G})$ completes the proof.\n}\n\\end{prop}\n\n\n\\begin{rmk}\nGiven \\cref{rmk:spin-orbital-transformation-law} and \\cref{prop:creation-operator-similarity-transform}, the transformation of particle-hole operators can be expressed as\n\\begin{align}\n\\label{eq:operator-transformation}\n\\begin{array}{r@{\\ }l}\n  a_p^{\\prime\\,\\dagger}\n&=\n  \\text{exp}(X - X\\dg)\n  a_p\\dg\\,\n  \\text{exp}(X\\dg - X)\n\\\\[4pt]\n  a_p^{\\prime}\n&=\n  \\text{exp}(X - X\\dg)\n  a_p\\,\n  \\text{exp}(X\\dg - X)\n\\end{array}\n&&\n  X\n=\n  \\sum_{p>q}\n  (\\bo{X})_{pq}\n  a_p\\dg a_q\n\\end{align}\nwhere the annihilation operator transformation is simply the adjoint of the one for creation operators.\n\\end{rmk}\n\n\n\\begin{rmk}\nIf $\\Th'$ is obtained by replacing all of the orbitals in the basis expansion of $\\Th\\in\\mc{F}$ with primed orbitals, then\n\\begin{align}\n  \\Th'\n=\n  \\text{exp}(X - X\\dg)\n  \\Th\n\\end{align}\nwhich follows from substituting equation~\\ref{eq:operator-transformation} into\n$\n  a_{p_1}^{\\prime\\,\\dagger}\n  \\cd\n  a_{p_n}^{\\prime\\,\\dagger}\n  \\kt{\\vac}\n$\nto prove that\n$\n  \\kt{\\F'_{(p_1\\cd p_n)}}\n=\n  \\text{exp}(X - X\\dg)\n  \\kt{\\F_{(p_1\\cd p_n)}}\n$\\footnote{\n  Note that\n$\n  \\text{exp}(X\\dg - X)\n=\n  \\pr{\\text{exp}(X - X\\dg)}^{-1}\n$\nand\n$\n  \\text{exp}(X\\dg - X)\n  \\kt{\\vac}\n=\n  \\kt{\\vac}\n$.\n}\nfor any basis state.\n\\end{rmk}\n", "meta": {"hexsha": "0204b31390f5342af81d3478f650d0429e1289ca", "size": 4887, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "handouts/sections/orbital-rotations.tex", "max_stars_repo_name": "GQCG-edu/chem-8950", "max_stars_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "handouts/sections/orbital-rotations.tex", "max_issues_repo_name": "GQCG-edu/chem-8950", "max_issues_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-07-13T12:11:58.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-13T15:31:47.000Z", "max_forks_repo_path": "handouts/sections/orbital-rotations.tex", "max_forks_repo_name": "GQCG-edu/chem-8950", "max_forks_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.1131221719, "max_line_length": 263, "alphanum_fraction": 0.6535706978, "num_tokens": 1843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7460266905498696}}
{"text": "\\section*{Bayesian teting and ``interval'' estimation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{The duality between estimation and testing}\nSimilarly to the frequentist case, in Bayesian inference there is an intimate relationship between testing hypotheses an estimating measurable functions of the parameters.\n\\begin{defn}[Test]\n Consider a statistical model $f(x \\mid \\theta)$  with $\\theta \\in \\boldsymbol{\\Theta}$. \n Given $\\boldsymbol{\\Theta}_0 \\subset \\boldsymbol{\\Theta}$, a \\textit{test} consists in answering the question of whether\n $$ H_0 : \\theta \\in \\boldsymbol{\\Theta}_0 $$\n is true.\n We call $H_0$ the \\textit{null hypothesis} and $\\boldsymbol{\\Theta}_0$ can often be a point, i.e. $\\boldsymbol{\\Theta}_0 = \\{\\theta_0 \\}$.\n\\end{defn}\nNotice that $\\mathbb{I}_{\\boldsymbol{\\Theta}_0}(\\theta)$ is measurable and thus we can define, for instance\n\\begin{equation*}\nL_1(\\theta, \\varphi) = \\begin{cases}\n1, \\varphi = \\mathbb{I}_{\\boldsymbol{\\Theta}_0}(\\theta),\\\\\n0, \\: \\text{otherwise},\n\\end{cases}\n\\end{equation*}\nwhich in turn leads to \n\\begin{equation*}\n\\varphi_1 = \\begin{cases}\n1, \\pr(\\theta \\in \\boldsymbol{\\Theta}_0 \\mid x) > \\pr(\\theta \\in \\boldsymbol{\\Theta}_0^c \\mid x),\\\\\n0, \\: \\text{otherwise}.\n\\end{cases}\n\\end{equation*}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A refinement}\n The loss function just seen can be refined to\n \\begin{equation*}\nL_2(\\theta, \\varphi) = \\begin{cases}\n0, \\varphi = \\mathbb{I}_{\\boldsymbol{\\Theta}_0}(\\theta),\\\\\na_0, \\theta \\in \\boldsymbol{\\Theta}_0, \\varphi = 0\\\\\na_1, \\theta \\in \\boldsymbol{\\Theta}_0^c, \\varphi = 1.\n\\end{cases}\n\\end{equation*}\nUnder this loss, we have\n\\begin{equation*}\n\\varphi_2 = \\begin{cases}\n1, \\pr(\\theta \\in \\boldsymbol{\\Theta}_0 \\mid x) >  a_1/(a_0 + a_1),\\\\\n0, \\: \\text{otherwise}.\n\\end{cases}\n\\end{equation*}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Example}\n\\begin{example}[\\textit{One} Normal test]\n  Take, for example, $x \\sim \\operatorname{Normal}(\\theta, \\sigma^2)$, with $\\theta \\sim \\operatorname{Normal}(\\mu_0, \\tau^2)$.\nThis implies $\\theta \\mid x \\sim \\operatorname{Normal}(\\mu(x), \\omega^2)$, where\n\\begin{align*}\n \\mu(x) &= \\frac{\\sigma^2\\mu_0 + \\tau^2x}{\\sigma^2 + \\tau^2};\n \\omega^2 = \\frac{\\sigma^2\\tau^2}{\\sigma^2 + \\tau^2}.\n\\end{align*}\nTo test $H_0: \\theta < 0$, we can compute\n\\begin{align*}\n \\pr(\\theta < 0 \\mid x) &= \\pr \\left(\\frac{\\theta-\\mu(x)}{\\omega} < \\frac{\\mu(x)}{\\omega}\\right), \\\\\n &= \\Phi\\left(\\frac{-\\mu(x)}{\\omega}\\right).\n\\end{align*}\nThis means that if $z_{a_0, a_1}$ is such that $\\Phi(z_{a_0, a_1}) = a_1/(a_0 + a_1)$, we can accept $H_0$ if \n$$\\mu(x) < -z_{a_0, a_1}\\omega. $$\n\\end{example}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Bayes factors}\nA central tool in Bayesian testing is the \\textbf{Bayes factor} -- see \\cite{Kass1995} for a review and guide for interpretation.\n\\begin{defn}[Bayes factor]\n \\label{def:Bayes_factor}\n The Bayes factor is the ratio of posterior odds and the prior odds over the null and the alternative:\n \\begin{align*}\n  B^\\pi_{01}(x) &= \\frac{\\pr(\\theta \\in\\boldsymbol{\\Theta}_0 \\mid x)}{\\pr(\\theta \\in\\boldsymbol{\\Theta}_1 \\mid x)}\\bigg/\\frac{\\pr(\\theta \\in\\boldsymbol{\\Theta}_0)}{\\pr(\\theta \\in\\boldsymbol{\\Theta}_1)},\\\\\n  &= \\frac{\\pr(\\theta \\in\\boldsymbol{\\Theta}_0 \\mid x)\\cdot\\pr(\\theta \\in\\boldsymbol{\\Theta}_1)}{\\pr(\\theta \\in\\boldsymbol{\\Theta}_1 \\mid x)\\cdot\\pr(\\theta \\in\\boldsymbol{\\Theta}_0)}.\n \\end{align*}\n\\begin{remark}\n When $\\boldsymbol{\\Theta}_0 = \\{\\theta_0\\}$ and  $\\boldsymbol{\\Theta}_1 = \\{\\theta_1\\}$ the Bayes factor simplifies to\n \\begin{equation*}\n  r_{01}(x) = \\frac{f(x\\mid\\theta_0)}{f(x\\mid\\theta_1)},\n \\end{equation*}\n also known as the \\textbf{likelihood ratio}.\n\\end{remark}\n\\end{defn}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A few more considerations on the Bayes factor}\nThe Bayes factor can also be written as \n\\begin{align*}\n  B^\\pi_{01}(x) &=  \\frac{\\int_{\\boldsymbol{\\Theta}_0} f(x\\mid t)\\pi_0(t)\\,dt }{\\int_{\\boldsymbol{\\Theta}_1} f(x\\mid t)\\pi_1(t)\\,dt} = \\frac{m_0(x)}{m_1(x)},\n\\end{align*}\nwhere $\\pi_0$ and $\\pi_1$ are the prior distributions under each hypothesis.\nAlso, if $\\hat{\\theta}_0$ and $\\hat{\\theta}_1$ are the MLE under each hypothesis, by making $\\pi_0$ and $\\pi_1$ Dirac masses at $\\hat{\\theta}_0$ and $\\hat{\\theta}_1$, respectively, we recover\n\\begin{equation}\n\\label{eq:bayes_lrt}\n R(x) = \\frac{\\sup_{\\theta \\in \\boldsymbol{\\Theta}_0}f(x \\mid \\theta)}{\\sup_{\\theta \\in \\boldsymbol{\\Theta}_1}f(x \\mid \\theta)}\n\\end{equation}\n\\begin{exercise}[Bayesian justifcation of LRT]\n Does (\\ref{eq:bayes_lrt}) offer a Bayesian justifcation for likelihood ratios?\n\\end{exercise}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Testing point-null hypotheses}\nHypotheses of the form $H_i : \\theta \\in \\{ \\theta_i \\}$, called point-null hypotheses, are hard to deal with from a probabilistic point of view.\n\\begin{remark}[Point-null hypotheses under continuous priors]\n Point-null cannot be tested under continuous prior distributions.\n More generally, if either $H_0$ or $H_1$ are \\textbf{impossible} \\textit{a priori}, then no amount of data can change that belief.\n\\end{remark}\n\\begin{idea}[Cromwell's law\\footnote{This idea is attributed to British statistician Dennis Lindley (1923-2013), one of the founders of modern Bayesian theory.}]\n In general, one not assign probability zero to events that are not logically or physically demonstrably impossible.\n Or, more eloquently, as  Oliver Cromwell writes to the General Assembly of the Church of Scotland on 3 August 1650:\n \\begin{quotation}\n  I beseech you, in the bowels of Christ, think it possible that you may be mistaken.\n \\end{quotation}\n\\end{idea} \n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Point-null hypotheses: modification of the prior}\nTesting point-null hypotheses involves a \\textbf{modification of the prior}\n If $H_0: \\theta \\in \\{\\theta_0\\}$  we can write $\\rho_0 = \\pr(\\theta = \\theta_0)$ and then\n \\begin{equation*}\n  \\tilde{\\pi}(\\theta) = \\rho_0 \\mathbb{I}_{\\boldsymbol{\\Theta}_0}(\\theta) + (1-\\rho_0)\\pi_1(\\theta),\n \\end{equation*}\nis our new prior, where $\\pi_1$ is the distribution with density $g_1(\\theta) \\propto \\pi(\\theta)\\mathbb{I}_{\\boldsymbol{\\Theta}_1}(\\theta)$ with respect to the dominating measure on $\\boldsymbol{\\Theta}_1$. \nThis gives a posterior probability\n\\begin{equation*}\n \\tilde{\\pi}(\\boldsymbol{\\Theta}_0 \\mid x) = \\frac{f(x \\mid \\theta_0)\\rho_0}{f(x \\mid \\theta_0)\\rho_0 + (1-\\rho_0)m_1(x)}.\n\\end{equation*}\nwhere $m_1(x) = \\int_{\\boldsymbol{\\Theta}_1} f(x \\mid t)g_1(t)\\,dt$.\nIt can be shown that\n\\begin{equation*}\n \\tilde{\\pi}(\\boldsymbol{\\Theta}_0 \\mid x) = \\left[1 + \\frac{1-\\rho_0}{\\rho_0}\\frac{1}{B^\\pi_{01}(x)}\\right]^{-1}, \n\\end{equation*}\nwhich makes clear the relationship between posterior probabilities and Bayes factors.\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Example}\nConsider $x \\sim \\operatorname{Binomial}(n, p)$ and consider testing $H_0: p = 1/2$ against $H_1: p \\neq 1/2$. \nTaking $g_1(p) = 1$, we have\n\\begin{equation*}\n  \\tilde{\\pi}(\\boldsymbol{\\Theta}_0 \\mid x) = \\left[1 + \\frac{1-\\rho_0}{\\rho_0}2^n B(x+1, n-x+1)\\right]^{-1}.\n\\end{equation*}\n \\begin{center}\n \\includegraphics[scale=0.45]{figures/posterior_prob_half.pdf}\n\\end{center}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Testing with improper priors}\n \\begin{idea}[Bayesian hypothesis testing with improper priors]\n  No. Just... No.\n \\end{idea}\nSee~\\cite{Degroot1973} for the many reasons why this is just a bad idea.\nIf you insist, please see Section 5.2.5 in \\cite{Robert2007} and references therein.\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{An interesting little paradox}\n\\begin{idea}[The Jeffreys-Lindley paradox]\nConsider $x \\sim \\operatorname{Normal}(\\theta, \\sigma^2)$ with $\\sigma^2$ known and suppose we are interested in testing $H_0: \\theta = \\theta_0$ against $H_1: \\theta \\neq \\theta_0$.\nWe can summarise the data using the sample mean $\\bar{x}$ and then compute $t_n = \\sqrt{n}(\\bar{x}-\\theta_0)/\\sigma$. \nEmploying a conjugate prior $\\theta \\sim \\operatorname{Normal}(\\mu_0, \\sigma^2)$,\nthe Bayes factor is\n\\begin{equation*}\nB_{01}(\\boldsymbol{x}) = \\sqrt{1 + n}\\exp\\left(-\\frac{nt_n^2}{2(1+n)}\\right),\n\\end{equation*}\nwhich goes to infinity with $n$, while the p-value:\n\\begin{equation*}\n p(t_n) = 1-2\\Phi(|t_n|),\n\\end{equation*}\nis constant in $n$.\nIn practice this means that, for instance $t_n = 1.96$ and $n = 16, 818$, we have 95\\% frequentist confidence that $\\theta \\neq \\theta_0$ whilst \\textbf{at the same time} having 95\\% belief that $\\theta = \\theta_0$.\n\\end{idea} \n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Another look at principled Bayesian testing}\n Before we were doing\n \\begin{equation*}\n  L_3(\\theta, \\varphi) = |\\varphi - \\mathbb{I}_{\\boldsymbol{\\Theta}_0}(\\theta)|.\n \\end{equation*}\nBut considering a strictly convex loss such as the quadratic loss \n \\begin{equation*}\n  L_4(\\theta, \\varphi) = \\left(\\varphi - \\mathbb{I}_{\\boldsymbol{\\Theta}_0}(\\theta)\\right)^2,\n \\end{equation*}\n leads to better (more adaptable) estimators in general.\n For instance, the Bayes estimator under $L_4$ is\n \\begin{equation*}\n  \\varphi_\\pi(x) = \\pr(\\theta \\in  \\boldsymbol{\\Theta}_0 \\mid x).\n \\end{equation*}\n \\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Credibility regions}\nAfter all of this work, we are finally ready to define credibility regions, the main object in Bayesian interval estimation.\n\\begin{defn}[Credibility region]\nFor a prior $\\pi$, a set $C_x$ is called an $\\alpha$-credible set if \n\\begin{equation*}\n \\pr(\\theta \\in C_x \\mid x) \\geq 1-\\alpha.\n\\end{equation*}\nWe call $C_x$ a highest posterior density (HPD) $\\alpha$-credible region if\n\\begin{equation*}\n \\left\\{\\theta : p(\\theta \\mid x) > k_\\alpha \\right\\} \\subset C_x \\subset \\left\\{\\theta : p(\\theta \\mid x) \\geq k_\\alpha \\right\\},\n\\end{equation*}\nsubject to the restriction that\n\\begin{equation*}\n \\pr(\\theta \\in C_x^\\alpha) \\geq 1-\\alpha.\n\\end{equation*}\n\\end{defn}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A couple remarks}\nCredibility regions have a few desirable properties that make them quite attractive as ``interval'' estimates.\n\\begin{remark}[No randomisation]\n One nice feature of credibility regions for discrete distributions is that, contrary to the frequentist approach, no randomisation is needed to attain a certain level $\\alpha$.\n\\end{remark}\nAlso,\n\\begin{remark}[Improper priors and credibility regions]\n In principle, the use of improper priors poses no problem for the derivation of credibility regions.\n\\end{remark} \n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Credibility regions: Example I}\nSometimes we will be able to provide Bayesian justifcation for frequentist confidence regions/intervals.\n\\begin{example}[Credibility intervals for the variance in the Normal]\n\\label{ex:cred_var_normal_Jeffreys}\nConsider $\\boldsymbol{x} = \\{ x_1, \\ldots, x_n \\}$, $x_i \\sim \\operatorname{Normal}(\\theta, \\sigma^2)$, with both parameters unknown.\nConsider\n$$ \\pi(\\theta, \\sigma^2) \\propto \\frac{1}{\\sigma^2}. $$\nMake $s^2 = \\sum_{i=1}^n (x-\\bar{x})^2$.\nIt can be shown that $p(\\sigma^2 \\mid  s^2) \\equiv \\operatorname{Gamma}(\\sigma^2; (n-1)/2, s^2/2)$.\nIn particular, this implies\n\\begin{equation*}\n \\frac{s^2}{\\sigma^2} \\mid \\bar{x} \\sim \\operatorname{Chi-square}(n-1),\n\\end{equation*}\nwhich the attentive student will notice leads to the same solution as the classical confidence approach.\n\\end{example}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Credibility regions: Example II}\n\\begin{example}[HPD for the normal mean]\n\\label{ex:cred_mean_normal_Jeffreys}\n Consider again the setting of example~\\ref{ex:cred_var_normal_Jeffreys}.\n Define $\\bar{s}^2 = s^2/(n-1)$ and take $t = F_{\\text{Student}}^{-1}(\\alpha; n-1)$.\n The classical ``T'' interval,\n \\begin{equation*}\n  C_t(\\bar{x}, \\bar{s}^2) = \\left(\\bar{x} - t\\sqrt{\\frac{\\bar{s}^2}{n}}, \\bar{x} + t\\sqrt{\\frac{\\bar{s}^2}{n}}\\right),\n \\end{equation*}\n is a HPD region under the Jeffreys's prior.\n Again, we can show that\n \\begin{equation*}\n  \\sqrt{n}\\frac{\\theta -\\bar{x}}{\\sqrt{\\bar{s}^2}} \\mid \\bar{x}, \\sqrt{\\bar{s}^2} \\sim \\operatorname{Student-t}(n-1).\n \\end{equation*}\n\\end{example}\n \n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A little decision theory can't hurt... Or can it?}\n Consider the loss\n \\begin{equation*}\n  L_1(C, \\theta) = \\operatorname{vol}(C) + (1-\\mathbb{I}_{C}(\\theta))a,\n \\end{equation*}\n which leads to the risk\n \\begin{equation*}\n  R(C_x, \\theta) = E[\\operatorname{vol}(C_x)] + \\pr(\\theta \\notin C_x).\n \\end{equation*}\nUnder this loss, the interval in Example~\\ref{ex:cred_mean_normal_Jeffreys} is dominated by \n\\begin{equation*}\n C_t^\\prime(\\bar{x}, \\bar{s}^2) = \\begin{cases}\nC_t(\\bar{x}, \\bar{s}^2), \\sqrt{\\bar{s}^2} < \\sqrt{n}c/(2t),\\\\\n\\{\\bar{x}\\}, \\: \\text{otherwise},\n\\end{cases}\n\\end{equation*}\nwhich is a bit weird -- why?\n\nNow, consider what happens under a \\textit{rational loss}\n\\begin{equation*}\n L_k(C, \\theta) = \\frac{\\operatorname{vol}(C)}{\\operatorname{vol}(C) + k} + (1-\\mathbb{I}_{C}(\\theta)), k >0.\n\\end{equation*}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{HPD (or HDI in one dimension)}\n \\begin{center}\n \\includegraphics[scale=0.5]{figures/HDI.pdf}\n\\end{center}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Recommended reading}\n\\begin{itemize}\n  \\item[\\faBook] \\cite{Robert2007}, Ch. 5.\n%  \\item \n \\item[\\faForward] Next lecture: \\cite{Robert2007} Ch. 7.\n \\end{itemize} \n\\end{frame}\n", "meta": {"hexsha": "5576639b800c42a661982c9191d8a46c44fec0d3", "size": 13603, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/lecture_6.tex", "max_stars_repo_name": "lucasmoschen/BayesianStatisticsCourse", "max_stars_repo_head_hexsha": "79fe17dd71fa9638ae4865c8e75eeb0f814d2ccb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-03-17T17:39:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T23:40:56.000Z", "max_issues_repo_path": "slides/lecture_6.tex", "max_issues_repo_name": "anhnguyendepocen/BayesianStatisticsCourse", "max_issues_repo_head_hexsha": "79fe17dd71fa9638ae4865c8e75eeb0f814d2ccb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-24T01:28:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T20:49:10.000Z", "max_forks_repo_path": "slides/lecture_6.tex", "max_forks_repo_name": "anhnguyendepocen/BayesianStatisticsCourse", "max_forks_repo_head_hexsha": "79fe17dd71fa9638ae4865c8e75eeb0f814d2ccb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-05-26T16:28:02.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T12:33:26.000Z", "avg_line_length": 47.3972125436, "max_line_length": 215, "alphanum_fraction": 0.6657354995, "num_tokens": 4475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069962657176, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7460266845415497}}
{"text": "\\section{Spherical and cylindrical coordinates}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Understand cylindrical and spherical coordinates.\n  \\item Convert points between Cartesian, cylindrical, and spherical\n    coordinates.\n  \\end{enumerate}\n\\end{outcome}\n\nSpherical and cylindrical coordinates are two generalizations of polar coordinates to three dimensions. We will first look at \\textbf{cylindrical coordinates}\\index{cylindrical coordinates}.\n\nWhen moving from polar coordinates in two dimensions to cylindrical coordinates in three dimensions, we use the polar coordinates in the $xy$\nplane and add a $z$ coordinate. For this reason, we use the notation $(r, \\theta, z)$ to express cylindrical coordinates.\nThe relationship between Cartesian coordinates $(x,y,z)$ and cylindrical coordinates $(r, \\theta, z)$ is given by\n\\begin{align*}\nx& =r\\cos (\\theta)  \\\\\ny& =r\\sin (\\theta)  \\\\\nz& =z\n\\end{align*}\nwhere $r\\geq 0$, $\\theta \\in \\lbrack 0,2\\pi )$, and $z$ is simply the Cartesian\ncoordinate. Notice that $x$ and $y$ are defined as the usual polar coordinates in the $xy$-plane. Recall that $r$ is defined as the length of the ray from the origin to the point $(x,y,0)$, while $\\theta$ is the angle between the positive $x$-axis and this same ray.\n\nTo illustrate this coordinate system, consider the following two pictures.\nIn the first of these, both $r$ and $z$ are known. The cylinder corresponds to a given value for $r$. A useful way to think of $r$ is\nas the distance between a point in three dimensions and the $z$-axis. Every point on the cylinder shown is at the same distance from the $z$-axis. Giving a value for $z$ results in a horizontal circle, or cross section of the cylinder at the given height on the $z$ axis (shown below as a black line on the cylinder). In the second picture, the point is specified completely by also knowing $\\theta$ as shown.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\node at (-5, 2.5){$z$};\n\\node at (-2.5, -2){$y$};\n\\node at (-7.5, -2){$x$};\n\\node at (-5,0){\\includegraphics[width=.25\\textwidth]{figures/cylinder.eps}};\n\\node at (-5,-3){$r$ and $z$ are known};\n\\draw(-1,-1,0)--(3,-1,0);\n\\draw(1,-1,0)--(1,2,0);\n\\draw[dotted](1,-1,-2)--(1,-1,0);\n\\draw(1,-1,0)--(1,-1,2);\n\\draw(1,1,0) circle [x radius=1.5cm, y radius=0.5cm];\n%\\draw[red](1,-1,0)--(1.5,0.55,0);\n\\draw[fill, red](1.5,0.55,0) circle [radius=2pt];\n\\draw[blue](1,-1,0)--(1.5,-1.5,0);\n\\draw[fill,blue](1.5,-1.5,0) circle [radius=2pt];\n\\draw[red](1.5,0.55,0)--(1.5,-1.5,0);\n\\draw[purple, dotted](1.5,0.55,0)--(1,0.65,0);\n\\draw[fill,purple](1,0.65,0) circle [radius=2pt];\n\\node[below right] at (1.5,0.55,0){$(x,y,z)$};\n\\node[right] at (1.5,-1.5,0){$(x,y,0)$};\n\\node[below] at (1,-1.2,0){$\\theta$};\n\\node[right] at (3,-1,0){$y$};\n\\node[above] at (1,2,0){$z$};\n\\node[below] at (1,-1,2){$x$};\n\\node[above] at (1.4,-1,0){$r$};\n\\node[left] at (1,0.65,0){$z$};\n\\node at (1, -3){$r$, $\\theta$ and $z$ are known};\n\\end{tikzpicture}\n\\end{center}\n\n Every point of $3$-dimensional\nspace other than the $z$ axis  has  unique cylindrical coordinates. Of course there are infinitely many cylindrical coordinates for the\norigin and for the $z$-axis. Any $\\theta $ will work if $r=0$ and $z$ is given.\n\nConsider now \\textbf{spherical coordinates}\\index{spherical coordinates}, the second generalization of polar form in three dimensions. For a point $(x,y,z)$ in $3$-dimensional space, the spherical coordinates are defined as follows.\n\\begin{equation*}\n\\begin{array}{l}\n\\rho: \\mbox{the length of the ray from the origin to the point}\\\\\n\\theta: \\mbox{the angle between the positive $x$-axis and the ray from the origin to the point $(x,y,0)$}\\\\\n\\phi: \\mbox{the angle between the positive $z$-axis and the ray from the origin to the point of interest}\n\\end{array}\n\\end{equation*}\nThe spherical coordinates are determined by $(\\rho ,\\phi\n,\\theta)$. The relation between these and the Cartesian coordinates $(x,y,z)$ for a point\nare as follows.\n\\begin{align*}\nx& =\\rho \\sin (\\phi) \\cos (\\theta) ,\\ \\phi \\in\n\\mat{0,\\pi}  \\\\\ny& =\\rho \\sin (\\phi) \\sin (\\theta) ,\\text{ }\\theta\n\\in \\lbrack 0,2\\pi ) \\\\\nz& =\\rho \\cos \\phi \\text{, }\\rho \\geq 0.\n\\end{align*}\n\nConsider the pictures below. The first illustrates the surface when $\\rho$ is known, which is a sphere of radius $\\rho$. The second picture corresponds to knowing both $\\rho $ and $\\phi$, which results in a circle about the $z$-axis. Suppose the first picture demonstrates a graph of the Earth. Then the circle in the second picture would\ncorrespond to a particular latitude.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\node at (-6, 2.5){$z$};\n\\node at (-3.5, -1){$y$};\n\\node at (-8.5, -1.5){$x$};\n\\node at (-6,0){\\includegraphics[width=.25\\textwidth]{figures/sphericalcoordinates.eps}};\n\\node at (-6,-3){$\\rho$ is known};\n\\node at (2,-3){$\\rho$ and $\\phi$ are known};\n\\node at (2,0){\\includegraphics[width=.25\\textwidth]{figures/rhoandphigiven.eps}};\n\\draw[red, ultra thick] (2,-0.9)--(3,0);\n\\node[right] at (1.9, -0.5){$\\phi$};\n\\node at (2, 2.5){$z$};\n\\node at (4.5, -2){$y$};\n\\node at (-0.5, -2){$x$};\n\\end{tikzpicture}\n\\end{center}\n\nGiving the third coordinate, $\\theta $ completely specifies the point of interest. This is demonstrated in the following picture. If the latitude corresponds to $\\phi$, then we can think of $\\theta$ as the longitude.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\draw(-1,-1,0)--(3,-1,0);\n\\draw(1,-1,0)--(1,2,0);\n\\draw[dotted](1,-1,-2)--(1,-1,0);\n\\draw(1,-1,0)--(1,-1,2);\n\\draw(1,1,0) circle [x radius=1.5cm, y radius=0.5cm];\n\\draw[red](1,-1,0)--(1.5,0.55,0);\n\\draw[fill, red](1.5,0.55,0) circle [radius=2pt];\n\\draw[blue](1,-1,0)--(1.5,-1.5,0);\n\\draw[fill,blue](1.5,-1.5,0) circle [radius=2pt];\n\\draw[dashed](1.5,0.55,0)--(1.5,-1.5,0);\n\\node[below] at (1,-1.2,0){$\\theta$};\n\\node[right] at (3,-1,0){$y$};\n\\node[above] at (1,2,0){$z$};\n\\node[below] at (1,-1,2){$x$};\n\\node[above] at (1.1,-0.4,0){$\\phi$};\n%\\node[right] at (1.4,0.1,0){$\\rho$};\n\\node at (1, -3){$\\rho$, $\\phi$ and $\\theta$ are known};\n\\end{tikzpicture}\n\\end{center}\n\nThe following picture summarizes the geometric meaning of the three coordinate systems.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\draw[->](0,0,0)--(3,0,0);\n\\draw[->](0,0,0)--(0,3,0);\n\\draw[->](0,0,0)--(0,0,4);\n\\draw[ultra thick, red](0,0,0)--(1.5,1.5,0);\n\\draw[fill, red](1.5,1.5,0) circle [radius=2pt];\n\\draw[ultra thick, blue](0,0,0)--(1.5,-1.5,0);\n\\draw[fill, blue](1.5,-1.5,0) circle [radius=2pt];\n\\draw[dotted](-1.25,-1.25,0)--(1.5,-1.5,0)--(2.5,0,0);\n\\draw[dotted](1.5,-1.5,0)--(1.5,1.5,0);\n\\node[right] at (3,0,0){$y$};\n\\node[above] at (0,3,0){$z$};\n\\node[below] at (0,0,4){$x$};\n\\node[right] at (1.5,-1.5,0){$(x,y,0)$};\n\\node[below] at (0,0,0){$\\theta$};\n\\node[above right] at (0,0.2,0){$\\phi$};\n\\node[right] at (0.75,0.75,0){$\\rho$};\n\\node[right] at (0.75,-0.75,0){$r$};\n\\node[right] at (1.5,1.5,0){$(x,y,z)$};\n\\node[right] at (1.5,2,0){$(r, \\theta, z)$};\n\\node[right] at (1.5,2.5,0){$(\\rho, \\phi, \\theta)$};\n\\end{tikzpicture}\n\\end{center}\n\nTherefore, we can represent the same point in three ways, using Cartesian coordinates, $(x,y,z)$, cylindrical coordinates, $(r, \\theta, z)$, and spherical coordinates $(\\rho, \\phi, \\theta)$.\n\nUsing this picture to review, call the point of interest $P$ for convenience. The Cartesian coordinates for $P$ are $(x,y,z)$. Then $\\rho $ is the distance between the origin and the point $P$. The angle between\nthe positive $z$ axis and the line between the origin and $P$\n is denoted by $\\phi$. Then $\\theta $ is the angle\nbetween the positive $x$ axis and the line joining the origin to the point\n$(x,y,0) $ as shown. This gives the spherical coordinates, $( \\rho, \\phi, \\theta)$. Given the line from the origin to $(x,y,0)$,  $r=\\rho \\sin(\\phi)$ is the length of this\nline. Thus $r$ and $\\theta $ determine a point in the $xy$-plane. In other words, $r$ and $\\theta $ are the usual polar coordinates and $r\\geq 0$ and $\\theta \\in \\lbrack 0,2\\pi )$. Letting $z$ denote the usual\n$z$ coordinate of a point in three dimensions,\n$(r,\\theta ,z) $ are the cylindrical coordinates of $P$.\n\nThe relation between spherical and cylindrical coordinates is that $r=\\rho\n\\sin(\\phi)$ and the $\\theta$ is the same as the $\\theta$ of cylindrical and polar\ncoordinates.\n\nWe will now consider some examples.\n\n\\begin{example}{Describing a surface in spherical coordinates}{}\nExpress the surface $z=\\frac{1}{\\sqrt{3}}\\sqrt{x^{2}+y^{2}}$ in spherical\ncoordinates.\n\\end{example}\n\n\\begin{solution}\nWe will use the equations from above:\n\\[\n\\begin{array}{l}\nx =\\rho \\sin (\\phi) \\cos (\\theta), \\phi \\in\n\\mat{0,\\pi}\\\\\n y =\\rho \\sin (\\phi) \\sin (\\theta) ,\\text{ }\\theta\n\\in \\lbrack 0,2\\pi ) \\\\\n z =\\rho \\cos \\phi \\text{, }\\rho \\geq 0\n\\end{array}\n\\]\n\nTo express the surface in spherical coordinates, we substitute these expressions into the equation.\nThis is done as follows:\n\\begin{equation*}\n\\rho \\cos (\\phi) =\\frac{1}{\\sqrt{3}}\\sqrt{(\\rho \\sin\n(\\phi) \\cos (\\theta)) ^{2}+(\\rho \\sin\n(\\phi) \\sin (\\theta)) ^{2}}=\\allowbreak\n\\frac{1}{3}\\sqrt{3}\\rho \\sin (\\phi).\n\\end{equation*}\nThis reduces to\n\\begin{equation*}\n\\tan (\\phi)=\\sqrt{3}\n\\end{equation*}\nand so $\\phi =\\pi /3$.\n\\end{solution}\n\n\\begin{example}{Describing a surface in spherical coordinates}{}\nExpress the surface $y=x$ in terms of spherical coordinates.\n\\end{example}\n\n\\begin{solution}\nUsing the same procedure as the previous example, this says $\\allowbreak \\rho \\sin (\\phi) \\sin (\\theta\n) =\\rho \\sin (\\phi) \\cos (\\theta)$. Simplifying,  $\\sin (\\theta) =\\cos (\\theta)$, which you could also write $\\tan (\\theta)=1$.\n\\end{solution}\n\nWe conclude this section with an example of how to describe a surface using cylindrical coordinates.\n\n\\begin{example}{Describing a surface in cylindrical coordinates}{}\nExpress the surface $x^{2}+y^{2}=4$ in cylindrical coordinates.\n\\end{example}\n\n\\begin{solution}\nRecall that to convert from Cartesian to cylindrical coordinates, we can use the following equations:\n\\[\nx =r\\cos (\\theta) , y=r\\sin (\\theta) , z =z\n\\]\n\nSubstituting these equations in for $x,y,z$ in the equation for the surface, we have\n\\[\nr^{2}\\cos ^{2} (\\theta) +r^{2}\\sin ^{2} (\\theta)=4\n\\]\nThis can be written as $r^2 ( \\cos^{2} (\\theta)+ \\sin^{2} (\\theta) ) = 4$. Recall that $ \\cos^{2} (\\theta)+ \\sin^{2} (\\theta)=1$.  Thus $r^{2} = 4$ or $r=2$.\n\\end{solution}\n", "meta": {"hexsha": "e5122023798c29c41897b2e886864b79b0e2d748", "size": 10230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/curvilinearSphericalCylindrical.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/curvilinearSphericalCylindrical.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/curvilinearSphericalCylindrical.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 44.672489083, "max_line_length": 409, "alphanum_fraction": 0.6641251222, "num_tokens": 3596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933183101078, "lm_q2_score": 0.9099070042057362, "lm_q1q2_score": 0.7460266730318503}}
{"text": "\\section{Resolution and Leakage of Periodogram-based Methods}\n\n\\begin{enumerate}[label=\\alph*), leftmargin=*]\n%% a)\n\\item\n%\n\nWe investigate the magnitude spectrum of the $N$-points Bartlett window, $W_{B}(w)$, for several values of $N$, illustrated at figure \\ref{fig:1_3_a_1}.\nWe note that its $3dB$ width of the main lobe varies as a function of $N$. Their inverse relationship is empirically shown in figure \\ref{fig:1_3_a_2}.\nLastly, the peaks of the side lobes as a function of $N$ are depicted in figure \\ref{fig:1_3_a_3}. Interestingly, the side lobes peaks are almost unaffected\nby $N$ ($1.5 dB$ change from $N=8$ to $N=1024$), unlike the $3dB$ width of the main lobe, which shrinks considerably for increasing values of $N$.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/a/bartlett-linear-N_8}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/a/bartlett-linear-N_128}\n    \\end{subfigure}\n    ~\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/a/bartlett-log-N_8}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/a/bartlett-log-N_128}\n    \\end{subfigure}\n    \\caption{$N$-points magnitude spectrum of Bartlett window, $W_{B}(w)$.}\n    \\label{fig:1_3_a_1}\n\\end{figure}\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/a/bartlett-3db-vs-N}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/a/bartlett-3db-vs-1_over_N}\n    \\end{subfigure}\n    \\caption{Bartlett window $3dB$ width of the main lobe as a function of $N$ and $1/N$.}\n    \\label{fig:1_3_a_2}\n\\end{figure}\n\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/a/bartlett-3db-peak-vs-N-linear}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/a/bartlett-3db-peak-vs-N-log}\n    \\end{subfigure}\n    \\caption{Bartlett window peaks of the side lobes as a function of $N$.}\n    \\label{fig:1_3_a_3}\n\\end{figure}\n\n\n\n%% b)\n\\item\n%\n\nLet the signal\n\n\\begin{equation}\n    x(n) = sin(2 \\pi f_{0} n) + sin(2 \\pi (f_{0} + \\frac{\\alpha}{N}) n)\n\\end{equation}\n\nwhere $\\alpha$ is a varying parameter and $N=256$ the fixed signal length. The PSD of $x(n)$ is ideally expected to have two peaks at frequencies\n$f_{0}$ and $f_{0} + \\frac{a}{N}$ (in Hz), therefore if the frequency resolution $\\Delta f$ is not sufficiently small, the two peaks are not\ndistinguishable, thus $\\Delta f \\leq \\frac{\\alpha}{N}$ is required.\nMoreover, due to the spectral leakage, the side lobes height make differentiation even harder, thus we will find the minimum $\\alpha$ value\nby experiments. Figure \\ref{fig:1_3_b_1} shows the empirical determination of $\\alpha$ using a \\textbf{rectangular window periodogram}.\nWe note that for $\\alpha \\lessapprox 0.62$ the two peaks are indistinguishable, while for greater $\\alpha$ values the peaks can be discriminated.\nLastly, figure \\ref{fig:1_3_b_2} illustrates some examples for different $\\alpha$ values.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[height=1.5in]{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/b/periodogram-resolution-threshold-alpha}\n    \\caption{Rectangular Window: Number of Peaks in Periodogram for varying $\\alpha$.}\n    \\label{fig:1_3_b_1}\n\\end{figure}\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/b/periodogram-example-alpha_0.2}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/b/periodogram-example-alpha_0.6}.pdf}\n    \\end{subfigure}\n    ~\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/b/periodogram-example-alpha_0.7}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/b/periodogram-example-alpha_1.0}.pdf}\n    \\end{subfigure}\n    \\caption{Rectangular window: Periodograms of $x(n)$ for varying $\\alpha$.}\n    \\label{fig:1_3_b_2}\n\\end{figure}\n\n%% c)\n\\item\n%\n\nRepeating the experiment using the \\textbf{Hamming-windowed periodogram method}, we obtain figures \\ref{fig:1_3_c_1} and \\ref{fig:1_3_c_2}.\nNote that since the Hamming window has a wider main lobe than the rectangular window, a larger value of $\\alpha$ is required, $\\alpha \\lessapprox 0.71$, in order to\ndistinguish the two peaks. Nonetheless, the Hamming window has better attenuation of the side lobes, depicted in figure \\ref{fig:1_3_c_2}.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[height=1.5in]{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/c/periodogram-hamming-resolution-threshold-alpha}\n    \\caption{Hamming Window: number of peaks in periodogram for varying $\\alpha$.}\n    \\label{fig:1_3_c_1}\n\\end{figure}\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/c/periodogram-hamming-example-alpha_0.2}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/c/periodogram-hamming-example-alpha_0.7}.pdf}\n    \\end{subfigure}\n    ~\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/c/periodogram-hamming-example-alpha_0.8}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/c/periodogram-hamming-example-alpha_1.0}.pdf}\n    \\end{subfigure}\n    \\caption{Hamming Window: periodograms of $x(n)$ for varying $\\alpha$.}\n    \\label{fig:1_3_c_2}\n\\end{figure}\n\n%% d)\n\\item\n\nLet the signal\n\n\\begin{equation}\n    x(n) = sin(2 \\pi f_{0} n) + a_{2} sin(2 \\pi (f_{0} + \\frac{\\alpha}{N}) n)\n\\end{equation}\n\nwhere $a_{2} \\in \\{1, 0.1, 0.01, 0.001\\}$ and $\\alpha \\in \\{4, 12\\}$ are varying parameters and $N=256$ the fixed signal length. Ideally, for an infinitely long $x(n)$,\nthe PSD is expected to comprise of two dirac deltas, however, since a finitely long sequence is used, spectral leakage is expected to degrade the quality of the periodogram.\nDifferent window functions trade $3dB$ width of the main lobe and the relative heights of the side lobes. The rectangular window used, has the smallest main lobe,\nhowever it also has the highest side lobes, resulting in the greatest spectral leakage. Consequently, the amplitude of the second sinusoid, $a_{2}$, affects significantly our\nability to identify the second sinusoidal term in the spectral estimate. Figure \\ref{fig:1_3_d} illustrates the periodograms for the different values of $a_{2}$ and $\\alpha$.\nWe observe that for higher $a_{2}$ values, $1.0$ and $0.1$, the second peak can be identified for both $\\alpha$ values. When $\\alpha=12$, the peak can also be observed for\n$a_{2}=0.01$, however it is rather unclear. Hence, even when the peaks are moved further apart (increased $\\alpha$) the spectral leakage deteriorates peak identification\nconsiderably.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/d/periodogram-leakage-rect-alpha_4.0-a2_1.000}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/d/periodogram-leakage-rect-alpha_4.0-a2_0.100}.pdf}\n    \\end{subfigure}\n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/d/periodogram-leakage-rect-alpha_4.0-a2_0.010}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/d/periodogram-leakage-rect-alpha_4.0-a2_0.001}.pdf}\n    \\end{subfigure}\n    ~\n    ~\n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/d/periodogram-leakage-rect-alpha_12.0-a2_1.000}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/d/periodogram-leakage-rect-alpha_12.0-a2_0.100}.pdf}\n    \\end{subfigure}\n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/d/periodogram-leakage-rect-alpha_12.0-a2_0.010}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/d/periodogram-leakage-rect-alpha_12.0-a2_0.001}.pdf}\n    \\end{subfigure}\n    \\caption{Rectangular window spectral leakage: periodograms of $x(n)$ for varying $a_{2}$ and $\\alpha$.}\n    \\label{fig:1_3_d}\n\\end{figure}\n\n\n%% e)\n\\item\n\nIn figure \\ref{fig:1_3_e} the amplitude of the Fourier Transform of the Bartlett window is provided. We note that at frequencies $k\\frac{2}{N}, k \\in \\mathbb{Z}$ there are zeros and thus \nat frequencies $\\frac{4}{N}$ and $\\frac{12}{N}$, too. Additionally, we observe that the side lobes of the window are not constant and they decrease as distance from the main lobe increases (increasing $\\alpha$).\nAs a result, the amplitude threshold identification is slightly easier at $\\alpha = 12$ because the peak of side lobes around $f = \\frac{12}{N}$ is slightly lower than the peak of side lobes around $f = \\frac{4}{N}$.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[height=1.5in]{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/e/bartlett-zeros-alpha}\n    \\caption{Bartlett window: periodogram and zeros at $f = \\frac{12}{N}$ and $f = \\frac{4}{N}$.}\n    \\label{fig:1_3_e}\n\\end{figure}\n\n%% f)\n\\item\n\nRepeating the experiment using the \\textbf{Chebyshev-windowed periodogram method}, we obtain figure \\ref{fig:1_3_f_1}. Thanks to the Chebyshev window side lobes high attenuation,\nwe notice that the two frequency components are distinguishable even in the case of the smallest $a_{2} = 0.001$. However, given the trade-off between side lobes attenuation\nand main lobe bandwidth, for $\\alpha = 4$, the two peaks overlap, making discrimination more difficult. Overall, this represents the tradeoff that windows have to make between\nthe width of the mainlobe as the height of the sidelobes.The rectangular window has a small mainlobe and thus the trouble in identification comes about because of the leakage effects\nwhereas the Chebyshev window cause more smearing and less leakage.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-chebyshev-alpha_4.0-a2_1.000}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-chebyshev-alpha_4.0-a2_0.100}.pdf}\n    \\end{subfigure}\n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-chebyshev-alpha_4.0-a2_0.010}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-chebyshev-alpha_4.0-a2_0.001}.pdf}\n    \\end{subfigure}\n    ~\n    ~\n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-chebyshev-alpha_12.0-a2_1.000}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-chebyshev-alpha_12.0-a2_0.100}.pdf}\n    \\end{subfigure}\n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-chebyshev-alpha_12.0-a2_0.010}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-chebyshev-alpha_12.0-a2_0.001}.pdf}\n    \\end{subfigure}\n    \\caption{Chebyshev window: periodograms of $x(n)$ for varying $a_{2}$ and $\\alpha$.}\n    \\label{fig:1_3_f_1}\n\\end{figure}\n\nUsing the \\textbf{Blackman-Tukey periodogram method} with $M = \\frac{N}{4} = 64$ lags for spectral estimation of $x(n)$, figure \\ref{fig:1_3_f_2} is obtained.\nWe notice that the two frequency peaks are obtained only in the case of $a_{2} = 1.0$, failing in all other cases, regardless $\\alpha$.\nThis method trades resolution, $\\Delta f_{BT} \\sim \\frac{1}{M}$ compared to $\\Delta f_{Per} \\sim \\frac{1}{N}$ for a rectangular window periodogram, for variance.\nHowever, the signal under investigation, $x(n)$, is purely deterministic (no stochastic term, since $\\sigma^{2} = 0$) and thus the reduction in variance does noy add any value to our estimate,\nleading solely to reduced resolution and hence unsuccessful identification of the two frequency components.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-blackman-alpha_4.0-a2_1.000}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-blackman-alpha_4.0-a2_0.100}.pdf}\n    \\end{subfigure}\n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-blackman-alpha_4.0-a2_0.010}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-blackman-alpha_4.0-a2_0.001}.pdf}\n    \\end{subfigure}\n    ~\n    ~\n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-blackman-alpha_12.0-a2_1.000}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-blackman-alpha_12.0-a2_0.100}.pdf}\n    \\end{subfigure}\n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-blackman-alpha_12.0-a2_0.010}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.225\\textwidth}\n        \\centering\n        \\includegraphics[height=0.75in]{{report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/assets/f/periodogram-leakage-blackman-alpha_12.0-a2_0.001}.pdf}\n    \\end{subfigure}\n    \\caption{Blackman-Tukey method: periodograms of $x(n)$ for varying $a_{2}$ and $\\alpha$.}\n    \\label{fig:1_3_f_2}\n\\end{figure}\n\n%\n\\end{enumerate}", "meta": {"hexsha": "24044dda9d58311ebac0889227060a975247b364", "size": 18210, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/index.tex", "max_stars_repo_name": "filangel/ASPMI", "max_stars_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-02-20T14:43:34.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-13T21:13:02.000Z", "max_issues_repo_path": "tex/report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/index.tex", "max_issues_repo_name": "AmjadHisham/ASPMI", "max_issues_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/report/spectrum-estimation/resolution-and-leakage-of-periodogram-based-methods/index.tex", "max_forks_repo_name": "AmjadHisham/ASPMI", "max_forks_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-07-17T08:32:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-12T18:26:18.000Z", "avg_line_length": 52.7826086957, "max_line_length": 216, "alphanum_fraction": 0.729324547, "num_tokens": 5479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.9124361580958426, "lm_q1q2_score": 0.7459845059039546}}
{"text": "\n\\subsection{Bayesian parameter estimation for dependent models}\n\n\\subsubsection{Recap}\n\nFor non-dependent models we had:\n\n\\(P(\\theta |y)=\\dfrac{P(y, \\theta)}{P(y)}\\)\n\n\\(P(\\theta |y)=\\dfrac{P(y| \\theta)P(\\theta )}{P(y)}\\)\n\nThe bottom bit is a normalisation factor, and so we can use:\n\n\\(P(\\theta |y)\\propto P(y| \\theta)P(\\theta )\\)\n\nWe have here:\n\n\\begin{itemize}\n\\item Our prior - \\(P(\\theta )\\)\n\\item Our posterior - \\(P(\\theta |y)\\)\n\\item Our likelihood function - \\(P(y| \\theta)\\)\n\\end{itemize}\n\n\\subsubsection{Bayesian regression for generative models}\n\nWe know:\n\n\\(P(\\theta |y,X)=\\dfrac{P(y, \\theta, X )}{P(y, X)}\\)\n\n\\(P(\\theta |y,X)=\\dfrac{P(y, X |\\theta )P(\\theta )}{P(y, X)}\\)\n\nThe bottom bit is a normalisation factor, and so we can use:\n\n\\(P(\\theta |y,X)\\propto P(y, X| \\theta)P(\\theta)\\)\n\nWe have here:\n\n\\begin{itemize}\n\\item Our prior - \\(P(\\theta )\\)\n\\item Our posterior - \\(P(\\theta |y,X)\\)\n\\item Our likelihood function - \\(P(y, X| \\theta )\\)\n\\end{itemize}\n\n\\subsubsection{Bayesian regression for discriminative models}\n\nWe know:\n\n\\(P(\\theta |y,X)=\\dfrac{P(y, \\theta, X )}{P(y, X)}\\)\n\n\\(P(\\theta |y,X)=\\dfrac{P(y| \\theta, X )P(\\theta, X)}{P(y, X)}\\)\n\n\\(P(\\theta |y,X)=\\dfrac{P(y| \\theta, X )P(\\theta )P(X|\\theta )}{P(y, X)}\\)\n\nWe assume \\(P(X|\\theta )=X\\) and so:\n\n\\(P(\\theta |y,X)=\\dfrac{P(y| \\theta, X )P(\\theta )P(X)}{P(y, X)}\\)\n\nThe bottom bit is a normalisation factor, and so we can use:\n\n\\(P(\\theta |y,X)\\propto P(y| X, \\theta)P(\\theta)\\)\n\nWe have here:\n\n\\begin{itemize}\n\\item Our prior - \\(P(\\theta )\\)\n\\item Our posterior - \\(P(\\theta |y,X)\\)\n\\item Our likelihood function - \\(P(y| X, \\theta )\\)\n\\end{itemize}\n\n", "meta": {"hexsha": "177269982ff2c559728767dc574b1b93bab0bcda", "size": 1636, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/bayesianDiscriminative/02-01-regressionBayes.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/bayesianDiscriminative/02-01-regressionBayes.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/bayesianDiscriminative/02-01-regressionBayes.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.3714285714, "max_line_length": 74, "alphanum_fraction": 0.6136919315, "num_tokens": 598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.8080672112416736, "lm_q1q2_score": 0.7458776799444495}}
{"text": "\\section{The SkipBlock Model}\n\\label{sec:skipbock}\n\nThe Skip List model works on a record unit, i.e., a synchronization point has a\nprobability p to appear in an inverted list of n records.\nThe SkipBlock model operates instead on \\emph{blocks} of records of a fixed\nsize, in place of the records themselves. Consequently, the probabilistic parameter\n$p$ is defined with respect to a block unit. A synchronization point is\ncreated every $\\frac{1}{p^i}$ blocks on a level $i$, thus every $\\frac{\\vert B\n\\vert}{p^i}$ records where $\\vert B \\vert$ denotes the block size. A\nsynchronization point links to the first record of a block interval. Compared\nto Figure~\\ref{fig:skiplists}, a SkipBlock structure with $p=\\frac{1}{8}$ and\n$\\vert B \\vert=2$ also has an interval of $\\frac{\\vert B \\vert}{p^1}=16$\nrecords. However, on level 2, the synchronization points are separated by\n$\\frac{\\vert B \\vert}{p^2}=128$ instead of 256 records. We note that with\n$\\vert B \\vert= 1$, the SkipBlock model is equivalent to the original Skip\nLists model, and therefore it is a generalization. The two properties of the\nSkip Lists are then translated to this model:\n\\begin{enumerate}\n  \\item the number of levels is defined by\n\\begin{equation}\nL_B(n)=\\left\\lfloor \\ln_{\\frac{1}{p}}\\left(\\frac{n}{\\vert B \\vert}\\right) \\right\\rfloor\n\\label{eq:skipblock-maxlevels}\n\\end{equation}\n  \\item the structure's size\n\\begin{equation}\nS_B(n)=\\sum_{i=1}^{\nL_B\\left(n\\right)}{\\left\\lfloor \\frac{n\\times p^i}{\\vert B \\vert}\n\\right\\rfloor}\n\\label{eq:skipblock-size}\n\\end{equation}\n\\end{enumerate}\n\n\\subsection{SkipBlock Search Algorithm}\n\\label{sec:search-skipblock}\n\nWith the block-based Skip Lists model, the search algorithm returns an\ninterval of blocks containing the target record. We discuss the search in\nthat interval in Section~\\ref{sec:search-interval}. The search walk is identical\nto the one presented in Section~\\ref{sec:search-skiplists}: we walk from the\ntop to the bottom level, and compare at each step the current synchronization\npoint with the target. The walk stops at the same termination criteria as in\nSkip Lists. The search complexity in the worst case becomes\n\\begin{equation}\nC_{SB}=\\frac{L_B(n)}{p}\n\\label{eq:skipblock-complexity}\n\\end{equation}\n\n\\subsection{Impact of the Self-Indexing Parameters}\n\\label{sec:block-probas-impact}\n\nIn this section, we discuss the consequences of the probabilistic parameter on\nthe Skip Lists data structure.\nTable~\\ref{tab:skiplists-proba} reports for low (i.e., $\\frac{1}{1024}$) and\nhigh (i.e., $\\frac{1}{2}$) probabilities\n\\begin{inparaenum}[(1)]\n\\item the complexity (\\ref{eq:skiplists-complexity}) to find the interval\ncontaining the target record, and\n\\item the size (\\ref{eq:skiplists-size}) of the Skip Lists structure.\n\\end{inparaenum}\nFor example with an interval $\\vert I \\vert = 1024$ and an\ninverted list of size $10^6$ (i.e., Skip Lists with one level), reaching a record\nlocated at the end of the inverted list incurs a lot of synchronization points\nat level 1 being read. With a smaller interval, e.g. 16, the number of\nsynchronization points read decreases because the $L(10^6)=4$ levels provide\nmore accessing points to the inverted list.\n\nLarge intervals give the possibility to skip over a large number of records by\nreading a few synchronization points. However this leads to less use cases of\nthe Skip Lists structure when the searched records are close to each other. In\nthe latter case, small intervals are then more adapted, but at the cost of a\nbigger structure. Moreover the more levels there are, the more walks up and\ndown on them there are.\n\nThere is a trade-off to achieve when selecting $p$: a high probability\nprovides a low search complexity but at a larger space cost, and a low\nprobability reduces considerably the required space at the cost of higher\nsearch complexity.\n\nThe SkipBlock model provides two parameters to control its Skip Lists\nstructure: the probabilistic parameter $p$ and the block size $\\vert B \\vert$.\nThe block size parameter enables more control over the Skip Lists structure. For\nexample, to build a structure with an interval of length 64, the original Skip\nLists model proposes only one configuration given by $p=\\frac{1}{64}$. For\nthis same interval length, SkipBlock proposes all the configurations that\nverify the equation $\\frac{\\vert B \\vert}{p}=64$.\nTable~\\ref{tab:skiplists-proba-block} reports statistics of some SkipBlock\nconfigurations for the same interval lengths as in\nTable~\\ref{tab:skiplists-proba}. Compared to Skip Lists on a same interval\nlength, SkipBlock shows a lower search complexity in exchange of a larger\nstructure.\n\n\\begin{table}\n\\begin{center}\n\\subfloat[Skip Lists with $\\vert I\\vert=\\frac{1}{p}$.]{\n\\centering\n\\ra{1.1}\n\\resizebox{0.39\\linewidth}{!}{%\n\\begin{tabular}{@{}lcc@{\\hs}c@{\\hs}c@{\\hs}c@{\\hs}c@{\\hs}}\n\\toprule\n$\\vert I \\vert$ & \\phantom{a} & 2 & 16 & 64 & 128 & 1024\\\\\n\\cmidrule{2-7}\n$S(n)$ & \\phantom{a} &\n\\numprint{99999988}&\\numprint{6666664}&\\numprint{1587300}&\\numprint{787400}&\\numprint{97751}\\\\\n$C$ & \\phantom{a} & 54 & 112 & 320 & 512 & 3072 \\\\\n\\bottomrule\n\\end{tabular}\n\\label{tab:skiplists-proba}\n}}\\quad%\n\\subfloat[SkipBlock with $\\vert I\\vert=\\frac{\\vert B \\vert}{p}$.]{\n\\ra{1.1}\n\\resizebox{0.54\\linewidth}{!}{%\n\\begin{tabular}{@{}lcc@{\\hs}c@{\\hs}cc@{\\hs}c@{\\hs}cc@{\\hs}c@{\\hs}cc@{\\hs}c@{\\hs}}\n\\toprule\n$\\vert I \\vert$ & \\phantom{a} & \\multicolumn{2}{c}{16} & \\phantom{a} &\n\\multicolumn{2}{c}{64} & \\phantom{a} & \\multicolumn{2}{c}{128} & \\phantom{a} &\n\\multicolumn{2}{c}{1024} \\\\\n\\cmidrule{3-4} \\cmidrule{6-7} \\cmidrule{9-10} \\cmidrule{12-13}\np:$\\vert B \\vert$ & \\phantom{a} & $\\frac{1}{4}$:4 & $\\frac{1}{8}$:2 & \\phantom{a} &\n$\\frac{1}{4}$:16 & $\\frac{1}{8}$:8 & \\phantom{a} & $\\frac{1}{4}$:32 &\n$\\frac{1}{8}$:16 & \\phantom{a} & $\\frac{1}{4}$:256 & $\\frac{1}{8}$:128 \\\\\n$S_B(n)$ & \\phantom{a} & \\numprint{8333328} & \\numprint{7142853} &\n\\phantom{a} & \\numprint{2083328} & \\numprint{1785710} & \\phantom{a} &\n\\numprint{1041660} & \\numprint{892853} & \\phantom{a} &\n\\numprint{130203} & \\numprint{111603} \\\\\n$C$ & \\phantom{a} & 48 & 64 & \\phantom{a} & 44 & 56 & \\phantom{a} &\n40 & 56 & \\phantom{a} & 36 & 48 \\\\\n\\bottomrule\n\\end{tabular}\n\\label{tab:skiplists-proba-block}\n}}%\n\\end{center}\n\\caption{Search and size costs of Skip Lists and SkipBlock with $n=10^8$.\n$\\vert I \\vert$ stands for an interval length. $C$ reports the search\ncomplexity to find an interval (Sections~\\ref{sec:search-skiplists}\nand~\\ref{sec:search-skipblock}).}\n\\end{table}\n\n\\section{Searching within an Interval}\n\\label{sec:search-interval}\n\nThe Skip Lists and SkipBlock techniques enables the retrieval of an interval\ngiven a target record. The next step is to find the target record within that\ninterval. A first strategy (S1) is to linearly scan all the records within\nthat interval until the target is found. Its complexity is therefore $O(\\vert I \\vert)$.\n\nSkipBlock takes advantage of the block-based structure of the\ninterval to perform more efficient search strategy. Here are defined four\nadditional strategies for searching a block-based interval, parameterized to a\nprobability p. The second strategy (S2) performs\n\\begin{enumerate}[(a)]\n\\item a linear scan over the blocks of the interval to find the block holding\nthe target and\n\\label{s2-linear-search-blocks}\n\\item a linear scan of the records of that block to find the target.\n\\label{s2-target-block}\n\\end{enumerate}\nThe search complexity is $\\frac{1}{p}+\\vert B \\vert$ with $\\frac{1}{p}$ denoting\nthe linear scan over the blocks and $\\vert B \\vert$ the linear scan over the\nrecords of one block. Similarly to S2, the third strategy (S3) performs the\nstep (\\ref{s2-linear-search-blocks}). Then, it uses to find the target an\ninner-block Skip Lists structure restricted to one level only. The complexity\nis $\\frac{1}{p}+\\frac{1}{q}+\\left\\lfloor\\vert B\\vert\\times q\\right\\rfloor$\nwith q the probability of the inner Skip Lists. In contrast to S3, the fourth\nstrategy (S4) uses a non-restricted inner-block Skip Lists structure. The\ncomplexity is $\\frac{1}{p}+\\frac{L(\\vert B \\vert)+1}{q}$ with q the inner Skip\nLists probability. The fifth one (S5) builds a Skip Lists structure on the\nwhole interval instead of on a block. Its complexity is then\n$\\frac{L\\left(\\frac{\\vert B\\vert}{p}\\right)+1}{q}$, with $q$ the inner Skip\nLists probability. The strategies S3, S4 and S5 are equivalent to S2 when the\nblock size is too small for creating synchronization points.\n\n\\section{Cost-Based Comparison}\n\\label{sec:cost-based-cmp}\n\nIn this section, we define a cost model that we use to compare five\nSkipBlock implementations and the original Skip Lists implementation.\n\n\\paragraph{Cost Model}\n\\label{sec:skipblock-cost-model}\nFor both the Skip Lists and the SkipBlock, we define a cost model by\n\\begin{inparaenum}[(a)]\n\\item the cost to search for the target, and\n\\label{cost-search}\n\\item the cost of the data structure's size.\n\\label{cost-size}\n\\end{inparaenum}\nThe search cost consists in the number of synchronization points traversed to\nreach the interval containing the target, plus the number of records scanned\nin that interval to find the target. The size cost consists in the total number\nof synchronization points in the data structure, including the additional ones\nfor S3, S4 and S5 in the intervals.\n\n\\paragraph{Implementations}\n\\label{sec:impl} \nWe define as the baseline implementation, denoted $I_1$, the Skip\nLists model using the strategy (\\emph{S1}). We define\nfive implementations of the SkipBlock model, denoted by $I_2$, $I_3$,\n$I_4$, $I_5$ and $I_6$, based on the five interval search strategies, i.e.,\n\\emph{S1}, \\emph{S2}, \\emph{S3},\\emph{S4} and \\emph{S5} respectively. The\ninner Skip Lists in implementations $I_4$, $I_5$ and $I_6$ is\nconfigured with probability $q=\\frac{1}{16}$. The inner Skip Lists in $I_5$ and\n$I_6$ have at least 2 levels. The size costs of the six implementations are \n\\begin{itemize}\n  \\item[$I_1$:] $S(n)$\n  \\item[$I_2$:] $S_B(n)$\n  \\item[$I_3$:] $S_B(n)+\\frac{n}{\\vert B \\vert}$\n  \\item[$I_4$:] $S_B(n)+\\left\\lfloor n\\times q\\right\\rfloor$\n  \\item[$I_5$:] $S_B(n)+\\frac{S(\\vert B \\vert)\\times n}{\\vert B \\vert}$  \n  \\item[$I_6$:]$S_B(n)+\\frac{S(p\\times\\vert B \\vert)\\times n}{p\\times\\vert B\n  \\vert}$\n\\end{itemize}\n\n\\paragraph{Comparison}\n\nWith respect to the SkipBlock model, we tested all the possible\nconfigurations for a given interval length. We report that all of them were\nproviding better search cost than the baseline. We only report in\nTable~\\ref{tab:cmp-costs} the configurations providing the best search cost\ngiven an interval length with the associated size cost. We observe that $I_2$\nalready provides better search cost than the baseline $I_1$ using the same\nsearch strategy \\emph{S1}, in exchange of a larger size cost. The other\nimplementations, i.e., $I_3$, $I_4$, $I_5$ and $I_6$ which use a more\nefficient interval search strategies further decrease the search cost. In\naddition, their size cost decreases significantly with the size of the\ninterval. On a large interval ($512$), $I_4$ is able to provide a low search\ncost ($64$) while sustaining a small size cost ($6.5e6$). The inner Skip\nLists of $I_5$ and $I_6$ are built on lists too small to provide benefits. To\nconclude, $I_4$ seems to provide a good compromise between search cost and\nsize cost with large intervals.\n\n\\begin{table}\n\\centering\n\\ra{1.1}\n\\resizebox{\\linewidth}{!}{%\n\\begin{tabular}{@{}lcc@{\\hs}c@{\\hs}c@{\\hs}c@{\\hs}c@{\\hs}c@{\\hs}cc@{\\hs}c@{\\hs}c@{\\hs}c@{\\hs}c@{\\hs}c@{\\hs}cc@{\\hs}c@{\\hs}c@{\\hs}c@{\\hs}c@{\\hs}c@{\\hs}cc@{\\hs}c@{\\hs}c@{\\hs}c@{\\hs}c@{\\hs}c@{\\hs}}\n\\toprule\n$\\vert I\\vert$&\\phantom{a}&\\multicolumn{6}{c}{8}\n&\\phantom{a}&\\multicolumn{6}{c}{16}\n&\\phantom{a}&\\multicolumn{6}{c}{512}\n&\\phantom{a}&\\multicolumn{6}{c}{1152}\\\\\n&\\phantom{a}& $I_1$ & $I_2$ & $I_3$ & $I_4$ & $I_5$ & $I_6$  &\\phantom{a}& $I_1$ & $I_2$ & $I_3$\n& $I_4$ & $I_5$ & $I_6$   &\\phantom{a}& $I_1$ & $I_2$ & $I_3$ & $I_4$ & $I_5$ & $I_6$  &\\phantom{a}& $I_1$ &\n$I_2$ & $I_3$ & $I_4$ & $I_5$ & $I_6$  \\\\\n\\cmidrule{3-8}\\cmidrule{10-15}\\cmidrule{17-22}\\cmidrule{24-29}\nSC&\\phantom{a}& $72$ & $56$ & \\multicolumn{4}{c}{$54$}\n&\\phantom{a}& $112$ & $62$ & \\multicolumn{4}{c}{$56$}\n&\\phantom{a}& $1536$ & $548$ & $120$ & $64$ & $86$ & $84$\n&\\phantom{a}& $3456$ & $1186$ & $154$ & $74$ & $84$ & $81$ \\\\\n\\cmidrule{3-8}\\cmidrule{10-15}\\cmidrule{17-22}\\cmidrule{24-29}\nZC$\\times e6$&\\phantom{a}& $14.3$ & $16.7$ & \\multicolumn{4}{c}{$50.0$}\n&\\phantom{a}& $6.7$ & $12.5$ & \\multicolumn{4}{c}{$25.0$}\n&\\phantom{a}& $0.2$ & $0.3$ &$1.8$ & $6.5$ & $7.0$ & $6.9$\n&\\phantom{a}& $0.09$ &$0.17$ & $1.7$&$6.4$ & $6.6$&$6.7$\\\\\n\\bottomrule\n\\end{tabular}\n}%\n\\caption{Search (i.e., SC) and size (i.e., ZC, in million) costs with $n=10^8$.\nSkipBlock implementations report the best search cost with the associated\nsize cost.}\n\\label{tab:cmp-costs}\n\\end{table}\n\n\\subsection{Skipping Analysis}\n\nThe SkipBlock structure, as a generalization of the Skip List, possesses the\nsame hierarchical layout. However the difference between the two is concrete:\nSkipBlock jumps over groups of blocks at a time, whereas Skip Lists jumps over\ngroups of records. The Table~\\ref{tab:skip-levels} reports the intervals at\neach levels for both structures, with a constant interval between towers of\n256 records. For a same interval length (e.g., 256 records in the table), we are\nable to yield more configurations with the SkipBlock than with the Skip List\nmodel. We remark that in both configurations of the SkipBlock, in-between\nlevels have been added in comparison to the original Skip List. These\nadditional levels give more skipping possibilities while searching. Moreover\nthis implies that more data will be read from a tower in a SkipBlock structure\nthan with the Skip List, for a same interval length.\n\n\\begin{table}\n\\ra{1.1}\n\\centering\n\\resizebox{0.45\\linewidth}{!}{%\n\\begin{tabular}{lc@{\\hs}rc@{\\hs}rr}\n\\toprule\nLevel & \\phantom{a} & Skip Lists & \\phantom{a} & \\multicolumn{2}{c}{SkipBlock}\\\\\n\\cmidrule{5-6}\n& & p=256 & \\phantom{a} & B=16 p=16 & B=64 p=4 \\\\\n\\cmidrule{5-6}\n1 & \\phantom{a} & 256 & \\phantom{a} & 256 & 256 \\\\\n2 & \\phantom{a} & \\uwave{\\numprint{65536}} & \\phantom{a} & \\numprint{4096} &\n\\numprint{1024} \\\\\n3 & \\phantom{a} & \\uwave{\\numprint{16777216}} & \\phantom{a} &\n\\uwave{\\numprint{65536}} & \\numprint{4096} \\\\\n4 & \\phantom{a} & \\ldots & \\phantom{a} & \\numprint{1048576} & \\numprint{16384}\\\\\n5 & \\phantom{a} & \\ldots & \\phantom{a} & \\uwave{\\numprint{16777216}} &\n\\uwave{\\numprint{65536}}\\\\\n\\bottomrule\n\\end{tabular}\n}\n\\caption{Interval length for each skip levels.}\n\\label{tab:skip-levels}\n\\end{table}\n\nThe SkipBlock structure will behave differently depending on the parameter\nconfigurations in comparison to the Skip list, since they yield different skip\nlevels. To have a better understanding of the differences between the two\nmodels, we discuss here the cost of reading skip data into memory and in which\ncase it outweighs the CPU saving thanks to an adaptation of the method from\n\\cite{moffat:96}.\n\nLet $t_r$ be the cost of reading one record or a synchronization point, both as\npart of a bulk read. Let also $t_d$ be the cost of decoding a\nrecord/synchronization point. Let further $k$ be the number of\n\\emph{candidates}, i.e., the records that will be lookup from the inverted\nlist thanks to the self-indexing structure. Then the total time $T$ required\nto search one inverted list of size $n$ in the worst case scenario (i.e., all\nlevels up to the maximum $L(n)$ are read) is given by the formula\n\\begin{displaymath}\nT=T_d+T_r=kt_d\\left( C + \\vert I \\vert \\right)+t_r\\left(n+2\\times S\\right) \n\\end{displaymath}\nwhere $T_d$ is the total time to decode pointers, $T_r$ the total time to read\ninto memory the inverted list and synchronization points. $ZC$ and $SC$ reports\nrespectively the size and the search costs. The numerical values of $t_d$ and\n$t_r$ are respectively $2.5\\times 10^{-6}$ and $0.5\\times 10^{-6}$, values\ntaken from \\cite{moffat:96}.\n\nThe Table~\\ref{tab:predicted-times} reports a numerical comparison between the\ntwo self-indexing models, with $n=60,000$ and $k=\\{60,\\;6000\\}$. With a bigger\nnumber of candidates we can expect a bigger processing time, since the\nself-indexing structure will be accessed more often. The SkipBLock structure's\nvalues are reported with the strategy S1 for the configurations that yields\nthe best processing time T. On small intervals (e.g., 16) the SkipBlock model\ndoes not provide significant better performance even though the complexity is\nbetter than the Skip List. This is explained by the difference in size, as the\namount of data to be read is greater, which is reflected by the greater\nrequired time to read data $T_r$. As the interval increases, we can see that\nthe processing times increase for both models. However the expected\nprocessing time is inferior with SkipBlock than with the original Skip List by\n2 times.\nThe reason is that even if the strategies for searching within intervals is\nthe same (i.e., linear), the additional levels that the SkipBlock model\nprovides give more skipping possibilities. This comforts the fact that the\nSkipBlock complexities are lower than the Skip List's. With the interval\n$\\vert I \\vert = 1024$, the structure's size increases by 30\\%, however both\nthe search complexity and the estimated processing time are twice as low as\nthe original model.\n\n\\begin{table}\n\\ra{1.1}\n\\centering\n\\resizebox{\\linewidth}{!}{%\n\\begin{tabular}{lc@{\\hs}rrrc@{\\hs}rrrc@{\\hs}rrc@{\\whs}rrrc@{\\hs}rrrc@{\\hs}rr}\n\\toprule\n$\\vert I \\vert$ & \\phantom{a} & \\multicolumn{10}{c}{Skip List} & \\phantom{a} &\n\\multicolumn{10}{c}{SkipBlock} \\\\\n\\cmidrule{3-12} \\cmidrule{14-23}\nk &\\phantom{a}& \\multicolumn{3}{c}{60} &\\phantom{a}& \\multicolumn{3}{c}{6000}\n&\\phantom{a}& & & \\phantom{a} & \\multicolumn{3}{c}{60} &\\phantom{a}&\n\\multicolumn{3}{c}{6000} & & \\\\\n\\cmidrule{3-5} \\cmidrule{7-9} \\cmidrule{14-16} \\cmidrule{18-20}\n& \\phantom{a} & $T_d$ & $T_r$ & T & \\phantom{a} & $T_d$ & $T_r$ & T &\n\\phantom{a} & SC & ZC & \\phantom{a} & $T_d$ & $T_r$ & T & \\phantom{a} &\n$T_d$ & $T_r$ & T & \\phantom{a} & SC & ZC \\\\\n16&\\phantom{a}&0.010&0.034&0.044\n&\\phantom{a}& 0.960 & 0.034 & 0.994 & \\phantom{a}& 64 & 3998\n&\\phantom{a}&0.006&0.035&0.041\n&\\phantom{a}& 0.600 & 0.035 & 0.635 & \\phantom{a}&40 & 4996 \\\\\n\n32&\\phantom{a}&0.019&0.032&0.051\n&\\phantom{a}& 1.92 & 0.032 & 1.952& \\phantom{a} & 128 & 1934\n&\\phantom{a}&0.008&0.034&0.042\n&\\phantom{a}& 0.81 & 0.034 & 0.844 & \\phantom{a}& 54 & 3743 \\\\\n\n256&\\phantom{a}&0.077&0.030&0.107\n&\\phantom{a}& 7.68 & 0.030 & 7.710& \\phantom{a} & 512 & 234\n&\\phantom{a}&0.041&0.030&0.071\n&\\phantom{a}& 4.08 & 0.030 & 4.110& \\phantom{a} & 272& 309 \\\\\n\n512&\\phantom{a}&0.154&0.030&0.184\n&\\phantom{a}& 15.36 & 0.030 & 15.390& \\phantom{a} & 1024 & 117 \n&\\phantom{a}&0.079&0.030&0.109\n&\\phantom{a}& 7.89 & 0.030 & 7.920 & \\phantom{a}& 526 & 229 \\\\\n\n1024&\\phantom{a}&0.307&0.030&0.337\n&\\phantom{a}&30.72 & 0.030 & 30.750& \\phantom{a} & 2048 & 58\n&\\phantom{a}&0.155&0.030&0.185\n&\\phantom{a}& 15.54 & 0.030 & 15.570 & \\phantom{a}& 1036 & 75 \\\\\n\n\\bottomrule\n\\end{tabular}}\n\\caption{Predicted processing times in seconds (n=60,000), with the\ncorresponding structure's search (i.e., SC) and size (i.e., ZC) costs. $T_d$\nstands for the time for decoding a record, $T_r$ for the time of reading into memory a\nrecord/synchronization point and T the sum of these two times. $k$ indicate the\nnumber of candidates.}\n\\label{tab:predicted-times}\n\\end{table}\n", "meta": {"hexsha": "b6b639bc10c799d9c4accd25362b8155c1c99a27", "size": 19402, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Methods/self-indexing.tex", "max_stars_repo_name": "scampi/report-compression-skiplists", "max_stars_repo_head_hexsha": "6ec36c77177642434a6ac4890d394ac2afea2c43", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Methods/self-indexing.tex", "max_issues_repo_name": "scampi/report-compression-skiplists", "max_issues_repo_head_hexsha": "6ec36c77177642434a6ac4890d394ac2afea2c43", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Methods/self-indexing.tex", "max_forks_repo_name": "scampi/report-compression-skiplists", "max_forks_repo_head_hexsha": "6ec36c77177642434a6ac4890d394ac2afea2c43", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.7487437186, "max_line_length": 193, "alphanum_fraction": 0.7159571178, "num_tokens": 6486, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7458569731056465}}
{"text": "% Section 2: standard form LP\n\n\\clearpage\n\\section{Standard Form LP}\n\\begin{equation}\n    \\begin{aligned}\n      \\min _{\\pi \\in \\mathbb{R}^{m \\times n}} & \\sum_{i=1}^{m} \\sum_{j=1}^{n} c_{i j} \\pi_{i j} \\\\\n      \\text { s.t. } & \\sum_{j=1}^{n} \\pi_{i j}=\\mu_{i}, \\quad \\forall i=1, \\ldots, m \\\\\n      & \\sum_{i=1}^{m} \\pi_{i j}=\\nu_{i}, \\quad \\forall j=1, \\ldots, n \\\\\n      & \\pi_{i j} \\geq 0\n    \\end{aligned}\n  \\end{equation}\n  \n  \\vspace{5ex}\n\n\\subsection{Calling Mosek and Gurobi}\n\nThe standard form can be vectorized as:\n\\begin{equation}\n    \\begin{aligned}\n      \\min _{\\pi \\in \\mathbb{R}^{m \\times n}} & c^T \\pi \\\\\n      \\text { s.t. } & A \\pi = b \\\\\n      & \\pi_{i j} \\geq 0\n    \\end{aligned}\n  \\end{equation}\n\nwhere \n$$\nc=\\left(c_{11}, c_{21}, \\dots c_{n 1}, \\dots, c_{1 n}, \\dots c_{n n}\\right)^{T}\n$$\n\n$$\n\\pi=\\left(\\pi_{11}, \\pi_{21}, \\ldots \\pi_{n 1}, \\ldots, \\pi_{1 n}, \\ldots \\pi_{n n}\\right)^{T}\n$$\n\n$$\nA=\\left(\\begin{array}{ccc}\n    {I_{m}} & {\\cdots} & {I_{m}} \\\\\n    {E_{1}} & {\\cdots} & {E_{n}}\n    \\end{array}\\right),\\left(E_{j}\\right)_{s t}=\\delta_{s j}\n$$\n\n$$\nb=\\left(\\mu_{1}, \\dots \\mu_{m}, \\nu_{1}, \\dots \\nu_{n}\\right)^{T}\n$$\n\nThen we could directly call linear programming solvers provided by Mosek and Gurobi.\n\n\\subsection{First Order Method: ADMM}\nFor convenience, we reformulate the original primal problem as:\n\n\\begin{equation}  \n\\begin{array}{rl}\n{\\mathrm{(primal)}} & {\\min_\\pi \\sum_{i=1}^{m} \\sum_{j=1}^{n} c_{i j} \\pi_{i j} + I_{\\mathbb{R}_+^{m\\times n}}(\\pi^\\dagger)} \\\\\n{\\text { subject to }} & {\\sum_{j=1}^{n} \\pi_{i j}=\\mu_{i} \\forall i=1, \\ldots, m} \\\\\n{} & {\\sum_{i=1}^{m} \\pi_{i j}=\\nu_{j} \\forall j=1, \\ldots, n} \\\\\n& \\pi = \\pi^{\\dagger}\n\\end{array}\n\\end{equation}\n\nThen we have the augmented Lagrangian: \n\n\\begin{equation}\n  \\begin{aligned}L(\\pi, \\pi^{\\dagger}, u, v, w)=& \\min_\\pi \\sum_{i=1}^{m} \\sum_{j=1}^{n} c_{i j} \\pi_{i j} + I_{\\mathbb{R}_+^{m\\times n}}(\\pi^\\dagger) \\\\&+\\sum_{i=1}^{m} u_{i}\\left(\\mu_{i}-\\sum_{j=1}^{n} \\pi_{i j}\\right)+\\sum_{j=1}^{n} v_{j}\\left(\\nu_{j}-\\sum_{i=1}^{m} \\pi_{i j}\\right)+\\sum_{i=1}^{m} \\sum_{j=1}^{n} w_{i j}\\left(\\pi_{i j}-\\pi^{\\dagger}_{i j}\\right) \\\\&+\\frac{\\rho}{2} \\sum_{i=1}^{m}\\left(\\mu_{i}-\\sum_{j=1}^{n} \\pi_{i j}\\right)^{2}+\\frac{\\rho}{2} \\sum_{j=1}^{n}\\left(\\nu_{j}-\\sum_{i=1}^{m} \\pi_{i j}\\right)^{2}+\\frac{\\rho}{2} \\sum_{i=1}^{m} \\sum_{j=1}^{n}\\left(\\pi_{i j}-\\pi^{\\dagger}_{i j}\\right)^{2}\\end{aligned}\n\\end{equation}\n\n$\\partial_{\\pi_{ij}} L = 0 $ gives: \n\n\\begin{equation}\n  \\sum_{k=1}^{n} \\pi_{i k}+\\sum_{k=1}^{m} \\pi_{k j}+\\pi_{i j}=\\frac{1}{\\rho}\\left(-e_{i j}+u_{i}+v_{j}-c_{i j}\\right)+\\mu_{i}+\\nu_{j}+\\pi_{ij}^{\\dagger}\n\\end{equation}\n\n$\\partial_{\\pi^{\\dagger}_{ij}} = 0$ gives:\n\n\\begin{equation}\n  {\\pi^{\\dagger}_{ij}} = (\\pi_{ij} + \\frac{w_{ij}}{\\rho})_+\n\\end{equation}\n\n\\vspace{2ex}\n    \\begin{algorithm}[htbp]\n        \\SetAlgoNoLine\n        \\caption{ADMM method for primal problem} \n        \\KwIn{parameters $\\mu$, $\\nu$, $c$}\n        \\KwIn{step size $\\alpha$, penalty $\\rho$}\n        Initialize variables $\\pi, \\pi^{\\dagger} = \\boldsymbol{0}$\\\\\n        Initialize variables $u, v, w = \\boldsymbol{0}$\\\\\n        \\While{ stopping criterion not met } \n        {  \n            Update $\\pi$: $\\boldsymbol{\\pi} \\leftarrow \\operatorname{argmin}_{\\pi} L(\\pi, \\pi^{\\dagger}, u, v, w)$\\\\\n            Update $\\pi^{\\dagger}$: $\\boldsymbol{\\pi}^{\\dagger} \\leftarrow \\operatorname{argmin}_{\\pi^{\\dagger}} L(\\pi, \\pi^{\\dagger}, u, v, w)$\\\\\n            Update $u$: $\\boldsymbol{u} \\leftarrow u + \\rho\\cdot \\alpha (\\mu - \\sum_j \\pi_{ij})$\\\\\n            Update $v$: $\\boldsymbol{v} \\leftarrow v + \\rho\\cdot \\alpha (\\nu - \\sum_i \\pi_{ij})$\\\\\n            Update $w$: $\\boldsymbol{w} \\leftarrow w + \\rho\\cdot \\alpha (\\pi - \\pi^{\\dagger})$\\\\\n        }\n    \\end{algorithm}", "meta": {"hexsha": "8cec9fe6b649845ac1aecb4ec3e72839e5350c48", "size": 3757, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/content-2.tex", "max_stars_repo_name": "CrazyIvanPro/Optimal_Transport", "max_stars_repo_head_hexsha": "aa782820a5ca5a01909ed3c32acbada43f6cfa0f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-09T10:37:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-06T09:24:30.000Z", "max_issues_repo_path": "doc/content-2.tex", "max_issues_repo_name": "CrazyIvanPro/Optimal_Transport", "max_issues_repo_head_hexsha": "aa782820a5ca5a01909ed3c32acbada43f6cfa0f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/content-2.tex", "max_forks_repo_name": "CrazyIvanPro/Optimal_Transport", "max_forks_repo_head_hexsha": "aa782820a5ca5a01909ed3c32acbada43f6cfa0f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-03T17:07:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-03T17:07:01.000Z", "avg_line_length": 39.5473684211, "max_line_length": 632, "alphanum_fraction": 0.5504391802, "num_tokens": 1613, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.7458499150631339}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath,amssymb,siunitx,graphicx}\n\\usepackage[margin=1in]{geometry}\n\\DeclareSIUnit\\ergs{ergs}\n\\DeclareSIUnit\\yr{yr}\n\\DeclareSIUnit\\AU{AU}\n\\DeclareSIUnit\\msun{\\ensuremath{\\mathrm{M}_{\\odot}}}\n\n\\title{Asteroid Defense}\n\\author{Matthias J. Raives}\n\n\\begin{document}\n\t\n        \\maketitle{}\n        \n\t\\section{Deflection}\t\n\tConsider an asteroid at some distance $R$ from Earth, heading directly towards the center of the Earth at a speed $v_{0}$.  To deflect it, we need to change its velocity such that it path just barely intersects the gravitational focusing radius $b$.\n\t\n\tThe gravitational focusing radius can be derived from a conservation of energy and angular momentum argument:\n        \\begin{align}\n                \\frac{1}{2}mv_{0}^{2} &= \\frac{1}{2}mv_{max}^{2} - \\frac{GM_{\\oplus}m}{R_{\\oplus}}\\\\\n                bv_{0} &= v_{max}R_{\\oplus}\n        \\end{align}\n        where $v_{max}$ is the velocity at impact.  We solve for $b$ as:\n        \\begin{equation}\n                b = R_{\\oplus}\\left(1+\\frac{v_{esc}^{2}}{v_{0}^{2}}\\right)\n        \\end{equation}\n        where $v_{esc}$ is the escape velocity from the surface of the Earth\n        \\begin{align}\n                v_{esc}^{2} = \\frac{2GM_{\\oplus}}{R_{\\oplus}}.\n        \\end{align}\n        \n        Now consider the incoming asteroid.  It has an initial momentum $\\mathbf{p}_{0}=m\\mathbf{v}_{0}$.  Consider our deflection to change it's momentum by some $\\Delta \\mathbf{p}$ but without changing the total energy, i.e., $|\\mathbf{p}_{0}|=|\\mathbf{p}_{1}|$.  This defines a triangle that can be solved as:\n        \\begin{equation}\n                \\sin\\frac{\\theta}{2} = \\frac{\\Delta p}{p_{0}}\n        \\end{equation}\n        where $\\theta$ is determined by\n        \\begin{equation}\n                \\sin\\theta = \\frac{b}{R}.\n        \\end{equation}\n        Using the small-angle approximation (valid if $R\\gg b$, i.e., $R\\gg R_{\\oplus}$ and $v_{0}\\gg v_{esc}$), we obtain\n        \\begin{equation}\n                \\Delta p = p_{0}\\frac{b}{R} = mv_{0}\\frac{R_{\\oplus}}{R}\\left(1+\\frac{v_{esc}}{v_{0}}\\right)\n        \\end{equation}\n        In the reference frame initially co-moving with the asteroid, the magnitudes of the initial and final momenta are not the same, and the change in energy (and thus, by conservation of energy, the energy required to change it's trajectory) is just:\n        \\begin{equation}\n                \\Delta E = \\frac{\\Delta p^{2}}{2m} = \\frac{1}{2}mv_{0}^{2}\\frac{R_{\\oplus}^{2}}{R^{2}}\\left(1+\\frac{v_{esc}}{v_{0}}\\right)^{2}\n        \\end{equation}\n        Suppose the asteroid is the same size as the Chicxulub impactor, and is detected at the moon's orbital distance.  The asteroid's mass can be determined assuming it has an average density of $\\rho=\\SI{5}{\\gram\\per\\cm\\cubed}$:\n        \\begin{equation}\n                m = \\frac{4\\pi}{3}\\rho R^{3} \\sim \\SI{3e18}{\\gram}.\n        \\end{equation}\n        If the earth-moon orbital distance is not known, it can be determined from Kepler's 3rd law:\n        \\begin{align}\n                \\left(\\frac{P}{\\si{\\yr}}\\right)^{2} &= \\left(\\frac{\\si{\\msun}}{M}\\right)\\left(\\frac{R}{\\si{\\AU}}\\right)^{3}\\\\\n                R &= \\left(\\frac{P}{\\si{\\yr}}\\right)^{2/3}\\left(\\frac{M}{\\si{\\msun}}\\right)^{1/3}\\:\\si{\\AU}\\\\\n                R &\\sim \\SI{2e-3}{\\AU} \\sim \\SI{3e5}{\\km}\n        \\end{align}\n        The initial velocity can be assumed to be the free-fall velocity at \\SI{1}{\\AU}, i.e.,\n        \\begin{equation}\n                v_{0} = \\sqrt{\\frac{2G\\si{\\msun}}{\\SI{1}{\\AU}}} \\sim \\SI{4e6}{\\cm\\per\\second}.\n        \\end{equation}\n        Thus, the energy required is:\n        \\begin{equation}\n                \\Delta E \\sim \\SI{1.5e28}{\\ergs}.\n        \\end{equation}\n        Note that gravitational focusing had a minimal effect on the answer.  This is because the asteroid is moving quickly; an object with a small relative velocity (say, small bodies near Earth during solar system formation) will be focused much more effectively.\n        \n        \\section{Destruction}\n        Smaller asteroids will have a smaller impact velocity as they have a smaller terminal velocity.  Terminal velocity is defined as the velocity at which the drag force and gravitational force balance out, so:\n        \\begin{align}\n                mg &= \\frac{1}{2}\\rho_{A} v_{T}^{2}c_{D}A\\\\\n                v_{T}^{2} &= {\\frac{2mg}{\\rho_{A} c_{D}A}},\n        \\end{align}\n        where $\\rho_{A}$ is the density of air, $A$ is the cross-sectional area of the falling object, and $c_{D}$ is the drag coefficient.  We can use $mg$ for the gravitational force because the height of the atmosphere is small compared to the radius of the earth, especially when you consider that the bulk of air resistance is in the lower atmosphere, where the air is more dense. The energy of the impact thus goes as:\n        \\begin{equation}\n                E = \\frac{1}{2}mv_{T}^{2} \\propto m^{2}A^{-1}.\n        \\end{equation}\n        The area can be written in terms of the mass if we know the density of the asteroid:\n        \\begin{align}\n                A &= \\pi R^{2}\\\\\n                m &= \\frac{4\\pi}{3}\\rho R^{3}\\\\\n                A &= \\pi \\left(\\frac{3m}{4\\pi\\rho}\\right)^{2/3}.\n        \\end{align}\n        Thus, we have:\n        \\begin{equation}\n                E\\propto m^{4/3}\n        \\end{equation}\n        Consider now, instead of one large asteroid of mass $m$, we have $N$ smaller asteroids, each of mass $m_{N}\\equiv \\frac{m}{N}$.  The energy then goes as\n        \\begin{equation}\n                \\Sigma{E} \\propto N\\left(\\frac{m_{N}}{N}\\right)^{4/3} \\propto N^{-1/3}\n        \\end{equation}\n        Thus, to reduce the total impact energy by a factor of 10, we would need to break the asteroid into $N=1000$ smaller impactors.\n\n\\end{document}\n", "meta": {"hexsha": "18ee16bae6162118235770d8bad17562fd3837bf", "size": 5784, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Asteroid Defense/Asteroid_Defense_Answer.tex", "max_stars_repo_name": "osugoom/questions", "max_stars_repo_head_hexsha": "5ad4fa6de9c9a8c60a3043adacfad41aef24ed4a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Asteroid Defense/Asteroid_Defense_Answer.tex", "max_issues_repo_name": "osugoom/questions", "max_issues_repo_head_hexsha": "5ad4fa6de9c9a8c60a3043adacfad41aef24ed4a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Asteroid Defense/Asteroid_Defense_Answer.tex", "max_forks_repo_name": "osugoom/questions", "max_forks_repo_head_hexsha": "5ad4fa6de9c9a8c60a3043adacfad41aef24ed4a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-01-10T21:05:11.000Z", "max_forks_repo_forks_event_max_datetime": "2018-01-10T21:05:11.000Z", "avg_line_length": 59.6288659794, "max_line_length": 424, "alphanum_fraction": 0.6071922545, "num_tokens": 1757, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7458499145576392}}
{"text": "\n\\subsection{Introduction}\n\nOLS:\n\n\\(\\hat \\theta =\\frac{\\sum_i (X_i-\\mu_X)(y_i-\\mu_y)}{\\sum_i(x_i-\\mu_X)^2}\\)\n\nTrimming\n\n\\(\\hat \\theta =\\frac{n^{-1}\\sum_i (X_i-\\mu_X)(y_i-\\mu_y)\\mathbf 1_i}{n^{-1}\\sum_i(x_i-\\mu_X)^2\\mathbf 1_i}\\)\n\nWhere:\n\n\\(\\mathbf 1_i=\\mathbf 1(\\hat f(z_i)\\ge b)\\)\n\nWhere \\(b=b(n)\\) is a trimming parameter, where:\n\n\\(b\\rightarrow 0\\) as \\(n\\rightarrow \\infty \\)\n\n", "meta": {"hexsha": "649f6aec273189fa700dc324966b018eed2c3a3a", "size": 381, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/ols/05-01-introduction.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/ols/05-01-introduction.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/ols/05-01-introduction.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.05, "max_line_length": 108, "alphanum_fraction": 0.6220472441, "num_tokens": 156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9559813513911655, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7456586668604356}}
{"text": "\\chapter{Polynomial and Rational Functions}\n\\section{Polynomials}\nA polynomial function of degree $n$ is defined as follows:\n\\begin{equation}\n  f(x)=a_nx^n+a_{n-1}x^{n-1}+a_{n-2}x^{n-2}+...+a_1x+a_0\n\\end{equation}\n\nFunctions of this classification for which $n=2$ are defined as\n\\textit{quadratic functions}, and look as follows: $f(x)=ax^2+bx+c$.\n\n\\begin{itemize}\n  \\item For all $a>0$, the parabola opens upward\n  \\item For all $a<0$, the parabola opens downwards\n\\end{itemize}\n\nThe standard form of a quadratic equation is given as follows:\n\\begin{equation}\n  f(x)=a(x-h)^2+k\n\\end{equation}\n\nTo identify the vertex of a function in this classification, simply use the\ncoordinate pair $(h,k)$.  If the quadratic is not in this format, simply\ncomplete the square, and you will have your $h$, $k$ pair.\n\nWhen a quadratic opens upwards and you have the vertex, then that is the\nrelative minimum of the function.  In the other case, you have the relative\nmaximum of that function.\n\n\\section{Higher-Order Functions}\nIf you are presented with a function that has a degree higher than 2, (i.e., it\nis not a quadratic), then you can at least determine the end-behavior of that\nfunction.  Consider the function $f(x)=3x^3+7x^2+6$:\n\n\\graph{3*x^3 + 7*x^2 + 6}\n\nWe can see that the function has two limits, namely:\n\\begin{itemize}\n  \\item $$\\lim_{x\\to\\infty} f(x)=\\infty$$\n  \\item $$\\lim_{x\\to-\\infty} f(x)=-\\infty$$\n\\end{itemize}\n\nWe can evaluate the limits of a function at $\\infty$ and $-\\infty$ simply by\nevaluating the leading term (by power), which in the case of $f(x)$ as defined\nabove is $3x^3$.  If we evaluate that function at both a large positive, and\nsmall negative value, the sign of the output will tell us whether the limit\napproaches positive or negative infinity.\n\n\\subsection{Zeros}\n\\begin{enumerate}\n  \\item $x=a$ is a zero of the function $f(x)$\n  \\item $x=a$ is a solution of the equation $f(x)=0$\n  \\item $(x-a)$ is a factor of the function $f(x)$\n  \\item $(a,0)$ is an $x$-intercept of the function $f(x)$\n\\end{enumerate}\n\n\\subsection{Multiplicity}\nFor any zero of a function, you can determine what it does at the x-axis\n(whether it crosses it or \"bounces\" across it) by determing the multiplicty of\nthat factor.  Consider the function $f(x)=x^3-7x^2+16x-12$ which factors into\n$f(x)=(x-2)^2(x-3)$.  The factor $(x-2)$ follows the form $(x-a)^k$, where\n$a=-2$ and $k=2$.  Therefore, at $x=2$, the function will bounce across the\nx-axis because $k$ is even.  If $k$ were to be odd, it would cross through the\naxis, as it does at $x=3$.\n\n\\subsection{Intermediate Value Theorem}\nIf $a$ and $b$ are real numbers, and $f(x)$ is continuous and defined upon the\ninterval $[a,b]$, there exists a $c$ such that $a<c<b$ and $f(a)<f(c)<f(b)$.\n\n\\section{Real Zeros of Polynomial Functions}\n\\subsection{Long Division}\nMuch like you did in second grade, you can prefom long division upon\npolynomials.\n\nTODO\n\nYou will end up with a function that can be composed as follows:\n\\begin{equation}\n  f(x)=d(x)q(x)+r(x)\n\\end{equation}\n\n\\subsection{Synthetic Division}\nIf the monomial that you are trying to divide into follows the form $(x-k)$,\nthen you can preform what is known as synthetic division.  To do synthetic\ndivision, take note of the following steps:\n\n\\begin{enumerate}\n  \\item Write all of the terms, by power order (0 for powers that don't exist in\n  the original equation) for all powers $n$ in the original polynomial\n  \\item Write $k$ on the left side of all of that such that $k$ is found in\n  $(x-k)$\n  \\item Drop the first term\n  \\item Multiply it by $k$ ($ka_n$)\n  \\item Place it up under the coeffiient $a_{n-1}$\n  \\item Add the two ($ka_n+a_{n-1}$)\n  \\item Repeat\n\\end{enumerate}\n\n\\subsection{The Remainder Theorem}\nIf a polynomial $f(x)$ is divided into $(x-k)$, the remainder is $r=f(k)$.\n\n\\subsection{The Ratioinal Zero Test}\nIf a polynomial is defined as follows:\n\\begin{equation}\nf(x)=a_nx^n+a_{n-1}x^{n-1}+a_{n-2}x^{n-2}+...+a_1x+a_0\n\\end{equation}\n\nThen all of the rational zeros must be defined in the set of numbers that look\nlike the following:\n\n\\begin{equation}\n  \\text{rational zeros}=\\frac{\\text{factors of the constant}}{\n    \\text{factors of the leading coefficient}}\n\\end{equation}\n\n\\section{Complex Numbers}\nSo far, we have learned about numbers that come in \\textit{standard form}, such\nas $1$, $3$, and others.  There is another classificaiton of numbers, called\n\\textit{complex numbers} that come in the form $a+bi$.\n\n$i$ is defined as follows:\n\n\\begin{equation}\n  i=\\sqrt{-1}\n\\end{equation}\n\nYou can easily raise $i$ to several different powers (1..4) and it will obey\ncertain, easily derivable rules:\n\n\\begin{enumerate}\n  \\item{$i^1=i$}\n  \\item{$i^2=-1$}\n  \\item{$i^3=i^2i^2=-i$}\n  \\item{$i^4=i^2i^2=1$}\n\\end{enumerate}\n\nAdding and subtracting complex numbers works as you'd expect. You add the real\nterms, and then add the complex terms, factoring out the $i$.\n\nMultiplying complex numbers is only slightly more complicated.  While it works\nnormally as you'd expect, you have to remember the power rules of $i$ as defined\nabove: sometimes you can end up with a negative number.\n\n\\subsection{Complex Conjugates}\nTo remove the complex part of a complex number, you can multiply it by the\n\\textit{complex conjugate} of itself.  The complex conjugate of $(a+bi)$ is\ndefined as $(a-bi)$.\n\n\\subsection{Principal Square Root}\nTo take the square root of a negative number, say $\\sqrt{-2}$, you can remember\nthe rules of the square-root, and expand the above expression into\n$\\sqrt{2}\\sqrt{-1}$, which is just $i\\sqrt{2}$.\n\n\\section{The Fundamental Theorem of Algebra}\nThe \\textit{Fundamental Theorem of Algebra} is defined such that for any\nfunction $f(x)$ which has degree $n$, there is at least one zero of $f$ in the\ncomplex number system.\n\n\\section{Asymptotes}\nAn asymptote of a function is defined as a part of a function ($f(x)$) such that\n$f(x)$ comes arbitrairly close to the asymptote, but never actually approaches\nit.  For example, $f(x)=ln(x)$ has a vertical asymptote at $x=0$.\n\n\\graph{ln(x)}\n\n\\begin{enumerate}\n  \\item{A horizontal asymptote can be evaluated by taking the limit of a\n      function as it approaches some endpoint.  As $x$ moves to some endpoint,\n    the function $f(x)$ will approach some value, $g(x)=b$.}\n  \\item{A vertical asymptote is evaluated by finding all of the $x$-values\n      outside the domain of $f(x)$.  If $f(x)$ is not defined for $x=a$, then\n      $x=a$ is a vertical asymptote of that function.}\n\\end{enumerate}\n\n\\section{Graphing Rational Functions}\nTo graph a rational function, one must simply take note of the following steps:\n\\begin{enumerate}\n  \\item{Simplify $f$, if possible}\n  \\item{Plot the $y$-intercept}\n  \\item{Plot the $x$-intercept(s)}\n  \\item{Sketch any asymptotes}\n  \\item{Use curves to complete the graph}\n\\end{enumerate}\n", "meta": {"hexsha": "30d86ab598b9415da0f4645845a090b9df719385", "size": 6822, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pre_calculus_h/chapters/2_polynomial_rational_functions.tex", "max_stars_repo_name": "ttaylorr/finals", "max_stars_repo_head_hexsha": "41f6a03e4a082768c10b9a77a0e042cfce2a6d7f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pre_calculus_h/chapters/2_polynomial_rational_functions.tex", "max_issues_repo_name": "ttaylorr/finals", "max_issues_repo_head_hexsha": "41f6a03e4a082768c10b9a77a0e042cfce2a6d7f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pre_calculus_h/chapters/2_polynomial_rational_functions.tex", "max_forks_repo_name": "ttaylorr/finals", "max_forks_repo_head_hexsha": "41f6a03e4a082768c10b9a77a0e042cfce2a6d7f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.2786885246, "max_line_length": 80, "alphanum_fraction": 0.7191439461, "num_tokens": 2049, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.8947894654011351, "lm_q1q2_score": 0.7456500691448626}}
{"text": "\\lesson{1}{Oct 11 2021 Mon (10:42:23)}{Greatest Common Factors and Special Products}{Unit 2}\n\n\\subsubsection*{Greatest Common Factor}\n\nA greatest common factor of two or more terms is the largest factor that all terms have in common. The greatest common factor of a polynomial should be factored out first before any further factoring is completed.\n\n\\begin{example}[GCF]\n    \\begin{align}\n        3r^6 + 27r^4 + 15r^2 &= 3r^2(r^4 + 9r^2 + 5) \\\\\n    \\end{align}\n    \n    When you multiply ($\\times$) variables, add the exponents:\n    \n    \\begin{align}\n         r^2 \\times r^4 &= rr \\times rrrr \\\\\n                        &= r^6\n    \\end{align}\n    \n    When factoring a \\bf{GCF}, subtract the exponents:\n    \n    \\begin{align}\n        \\rm{To factor $r^2$ from $r^6$: $r^{6 - 2} = r^4$} \\\\\n        rrrrrr = (rr)(rrrr) = r^2(r^4)\n    \\end{align}\n\\end{example}\n\n\\subsubsection*{Difference of Squares Binomials}\n\nA difference of \\bf{squares binomial} includes a \\bf{perfect square} term subtracted by another \\bf{perfect square term}.\n\n\\begin{example}[Difference of Squares Binomials]\n    \\begin{align}\n        a^2 - b^2 = (a + b)(a - b) \\\\\n        r^2 - 4 = (r + 2)(r - 2)\n    \\end{align}\n\\end{example}\n\n\\subsubsection*{Perfect Square Trinomials}\n\nA \\bf{perfect square trinomial} is a polynomial of \\bf{three terms} where the \\it{first} and \\it{last} terms are \\bf{perfect squares} and the \\bf{middle term} is \\bf{twice the product of the square roots} of those terms.\n\n\\begin{example}[Perfect Square Trinomials]\n    \\begin{center}\n        Pattern:\n    \\end{center}\n    \n    \\begin{align}\n        a^2 + 2ab + b^2 = (a + b)^2 \\rm{ OR } a^2 - 2ab + b^2 = (a - b)^2\n    \\end{align}\n    \n    \\begin{center}\n        Example:\n    \\end{center}\n    \n    \\begin{align}\n        r^2 + 12r + 36 = (r + 6)^2 \\rm{ OR } r^2 - 12r + 36 = (r - 6)^2\n    \\end{align}\n\\end{example}\n\n\\newpage\n", "meta": {"hexsha": "51323669bab1060a7e72cb4217c9f74f0efe8708", "size": 1869, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-2/lesson-1.tex", "max_stars_repo_name": "SingularisArt/notes", "max_stars_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-08-31T12:45:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T07:29:05.000Z", "max_issues_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-2/lesson-1.tex", "max_issues_repo_name": "SingularisArt/notes", "max_issues_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-2/lesson-1.tex", "max_forks_repo_name": "SingularisArt/notes", "max_forks_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.6393442623, "max_line_length": 220, "alphanum_fraction": 0.6051364366, "num_tokens": 635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7456500632014246}}
{"text": "% !TEX root = index.tex\n\n\\section{Principal Curvatures}\n\n\\epigraph{If you are receptive and humble, mathematics will lead you by the hand.}{Paul Dirac}\n\nFor the graph $z=f(x,y)$ the Gaussian and Mean curvatures are the determinant and trace of $\\hess(f)$ respectively, and are invariant under rotation of the $xy$-plane. We can ask: how much can we simplify $\\hess(f)$ by replacing it with a suitable $P^{-1} \\hess(f) P$?\\\\ Answer: A Lot.\\\\\n\nThe Hessian $ \\hess(f)$ is a symmetric $ 2 \\times 2$ matrix, hence by the \\textbf{Spectral Theorem}, there exist orthonormal vectors (eigenvectors) $ v_1, v_2$ and constants (eigenvalues) $ \\kappa_1, \\kappa_2$ such that for the matrix $ P$ whose columns are $v_1, v_2$ we have\n\\begin{align}\n\tP^{-1} \\hess(f) P  = \\begin{bmatrix} \\kappa_1 & \\\\ & \\kappa_2 \\end{bmatrix}\n\\end{align}\nThe set $\\{ \\kappa_1, \\kappa_2 \\}$ is uniquely determined by $\\hess(f)$.\n\n\\begin{definition}\n\tThe eigenvalues $ \\kappa_1, \\kappa_2$ of $ A$ are called the \\textbf{principal curvatures} and the eigenvectors $ v_1, v_2$ are called the \\textbf{principal directions} at $p$.\n\\end{definition}\n\\begin{remark}\n\tIn the case $ \\kappa_1 = \\kappa_2$ all directions are principal.\n\\end{remark}\n\\begin{ques}\n\tShow that the various curvatures are related as follows:\n\t\\begin{align}\n\t\t\\nonumber H &= (\\kappa_1 + \\kappa_2)/2 \\\\\n\t\t\\nonumber K &= \\kappa_1 \\kappa_2 \\\\\n\t\t\t\\label{eq:eigenvalues}\n\t\t&\\kappa_1, \\kappa_2 \\mbox{ are the roots of } \\kappa^2 - 2H \\kappa + K\n\t\\end{align}\n\\end{ques}\n\\begin{ques}\n\tFind the Principal Curvatures and Principal Directions of the curves you analyzed yesterday\n\t\\begin{description}\n\t\t\\item[The Perfect \\textbf{Potato Chip}: ]  $ z = x^2 - y^2 $\n\t\t\\item[Cylindrical Potato: ] $z = -\\sqrt{r^2 - x^2} $\n\t\t\\item[Spherical Potato: ] $z = -\\sqrt{r^2 - x^2 - y^2}$\n\t\t\\item[Parabolic Cylinder: ] $z =  x^2$\n\t\\end{description}\n\t(You can use the estimate $-\\sqrt{r^2 - \\alpha} \\approx -r + \\frac{\\alpha}{2r} $.)\n\\end{ques}\n\\noindent This is all the algebra we'll be needing. We'll now start analyzing the curvatures geometrically.\n\n\n\n% \\subsection{Principal Curvatures as Good Approximations}\n% We can rotate the $xy$-plane about the $z$-axis so that the two axes now point in the direction of the vectors $v_1$ and $v_2$. Without loss of generality let us assume that $v_1$, $v_2$ point in the $x, y$ direction to begin with. Then the Hessian becomes\n% \\begin{alignat*}{4}\n% \\hess(f) = &\t\\begin{bmatrix}\n% \t\tf_{xx} & f_{xy} \\\\\n% \t\tf_{xy} & f_{yy}\n% \t\\end{bmatrix} & \\quad = \\quad &\n% \t\\begin{bmatrix}\n% \t\t\\kappa_1 & 0         \\\\\n% \t\t0         & \\kappa_2\n% \t\\end{bmatrix}                                                   \\\\\n% \t\\Rightarrow \\quad &\n% \tf(x, y)                & \\approx \\quad & f(p) + \\kappa_1 \\cdot \\dfrac{x^2}{2} + \\kappa_2 \\cdot \\dfrac{y^2}{2}\n% \\end{alignat*}\n% We've seen such expressions before. The right hand side is the quadratic approximation of the function\n% \\begin{align*}\n% \tf(x,y) &= \\sqrt{ f(p)^2 - }\n% \\end{align*}\n%\n% This is the geometric significance of the principal directions and principal curvatures:\n% \\begin{prop}\n% \t\\label{thm:principal_curvatures}\n% \tIf $ \\kappa_1, \\kappa_2 $ are the principal curvatures of the graph of $f(x,y)$ at a critical point $ p$ then near $ p$, after possibly rotating the $xy$-plane about the $z$-axis, the quadratic function that \\textbf{best approximates} $f$ is\n% \t\\begin{align*}\n% \t\tf(p) + \\kappa_1\\dfrac{x^2}{2} + \\kappa_2\\dfrac{y^2}{2}\n% \t\\end{align*}\n% \\end{prop}\n% This is completely analogous the situation in one variable where the circle of radius $1/\\kappa$ provided a best approximation for a curve. In 2 dimensions, it's not enough to look at circles alone instead we need to allow for 2 variables {\\color{red}something}.\n%\n% \\begin{ques}\n% \tFor the graph $ z =f(x,y)$ show that the equation of the tangent plane at $ p = (0,0)$ is given by\n% \t\\begin{align*}\n% \t\tz = f(p) + f_x(p) x + f_x(p) y\n% \t\\end{align*}\n% \tCompare this to Proposition \\ref{thm:principal_curvatures}.\n% \\end{ques}\n\n\n\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=8cm]{normal_curvature}\n\t\\caption{Principal Directions and Normal Curvatures. Image from Wikipedia.}\n\\end{figure}\n\n\\subsection{Curves on a Potato}\nWithout any loss of generality assume that the $x, y$ axes are the principal directions with principal curvatures $\\kappa_1$, $\\kappa_2$ respectively. This is equivalent to saying that the degree 2 Taylor approximation of $ f$ is\n\\begin{align*}\n\tf(x,y) &\\approx f(0,0) + \\kappa_1 \\cdot \\dfrac{x^2}{2} + \\kappa_2 \\cdot \\dfrac{y^2}{2}\n\\end{align*}\nLet us look at the \\emph{curves on the surface} passing through $(0,0)$ and compute their curvature in terms of $ \\kappa_1, \\kappa_2$. We'll consider curves of the form\n\\begin{align*}\n\tc_\\theta(t)\n\t & = (t \\cos \\theta, t \\sin \\theta, f(t\\cos \\theta,t\\sin \\theta))\n\\end{align*}\nNote that upon projecting onto the $xy$-plane $c_\\theta(t)$ projects onto the straight line $y=\\tan \\theta \\cdot x$. Applying the formula for curvature we get:\n\\begin{align*}\n\tc'_\\theta(t) &= (\\cos \\theta, \\sin \\theta, f'(t\\cos \\theta,t\\sin \\theta) \\\\\n\tc''_\\theta(t) &= (0, 0, f''(t\\cos \\theta,t\\sin \\theta))\n\\end{align*}\nBecause $c(0)=(0,0)$ is the critical point, the tangent plane to $S$ at $(0,0)$ is horizontal and hence we must have $f'(t\\cos \\theta,t\\sin \\theta)|_{t=0}=0$ so that\n\\begin{align*}\n\tc'_\\theta(0) &= (\\cos \\theta, \\sin \\theta, 0)\n\\end{align*}\nwhich is unit length. By explicitly computing the cross product we get\n\\begin{align*}\n\t\\kappa\n\t&= |c''_\\theta \\times c'_\\theta|_{t=0} \\\\\n\t&= |f''(t\\cos \\theta,t\\sin \\theta)|_{t=0}\n\\end{align*}\nWe'll remove the absolute value $\\lvert - \\rvert$ and compute the \\textbf{signed curvature}\n\\begin{align*}\n\t\\kappa &= f''(t\\cos \\theta,t\\sin \\theta)|_{t=0}\n\\end{align*}\n\\begin{definition}\n\t\\label{def:normal_curvature}\n\tThe signed curvature of $c_\\theta(t)$ at $t=0$ is called the \\textbf{normal curvature} at $p$ along the direction $(\\cos \\theta, \\sin \\theta)$ (we will abbreviate this as just the direction $\\theta$).\n\\end{definition}\nWe can compute this using the Taylor approximation\n\\begin{align*}\n\tf(t\\cos \\theta,t\\sin \\theta) &\\approx f(0,0) + \\kappa_1 \\cdot \\dfrac{(t \\cos \\theta)^2}{2} + \\kappa_2 \\cdot \\dfrac{(t \\sin \\theta)^2}{2} + \\cdots \\\\\n\t\\Rightarrow \\qquad\n\tf''(t\\cos \\theta,t\\sin \\theta) &\\approx  \\kappa_1 \\cdot \\cos^2 \\theta + \\kappa_2 \\cdot \\sin^2 \\theta + \\cdots\n\\end{align*}\nWhen we plug in $t=0$ the higher degree terms in the Taylor approximation vanish and we get\n\\begin{align*}\n\t\\kappa = f''(t\\cos \\theta,t\\sin \\theta)|_{t=0} &=  \\kappa_1 \\cdot \\cos^2 \\theta + \\kappa_2 \\cdot \\sin^2 \\theta\n\\end{align*}\n\n\\begin{prop}\n\tWith the notation as above, the normal curvature at the point $p$ in the direction $\\theta$ equals\n\t  \\begin{align*}\n\t\t\t\\kappa &=  \\kappa_1 \\cdot \\cos^2 \\theta + \\kappa_2 \\cdot \\sin^2 \\theta\n\t  \\end{align*}\n\\end{prop}\n\n\\begin{thm}\n\t\\label{thm:extremal_curvatures}\n\tWithout any loss of generality assume that $\\kappa_1 \\ge \\kappa_2$. Then the maximum and minimum normal curvatures at the point $p$ are $\\kappa_1$ and $\\kappa_2$ respectively, in the corresponding principal directions.\n\\end{thm}\n\\noindent Proof is in the following exercise.\n\\begin{ques}\n\tAssume $\\kappa_1 \\ge \\kappa_2$. Prove that $\\kappa_1 \\cos^2 \\theta  + \\kappa_2 \\sin^2 \\theta$ attains it maximum at $ \\theta = 0, \\pi$ and minimum at $ \\theta = \\pi/2, 3 \\pi/2$ and the maximum value is $ \\kappa_1$ and the minimum value is $ \\kappa_2$.\n\\end{ques}\n\\begin{ques} There is another sense in which the Mean Curvature is the mean: it is the mean of all normal curvatures.\n\t\\begin{enumerate}\n\t\t\\item Plot $ r=\\kappa_1 \\cos^2 \\theta  + \\kappa_2 \\sin^2 \\theta$ in polar coordinates. Interpret this geometrically.\n\t\t\\item Show that\n\t\t\\begin{align*}\n\t\t\tH = \\dfrac{1}{2 \\pi} \\int \\limits_{0}^{2 \\pi } \\kappa_1 \\cos^2 \\theta  + \\kappa_2 \\sin^2 \\theta \\: d \\theta\n\t\t\\end{align*}\n\t\\end{enumerate}\n\\end{ques}\n\\begin{remark}\n\tBecause curvature does not change when we rotate $\\R^3$ we can drop the condition that $p$ is a critical point from the above theorem. It is worth rephrasing the theorem to state this.\n\\end{remark}\n\\begin{thm}\n\tAt every point $p$ on a surface $S$ there are two perpendicular directions (principal directions) along which the normal curvatures attain the maximum and minimum (principal curvatures).\n\\end{thm}\n\n\\subsection{Classification of Points}\nThe signs of the principal curvatures allow us to classify the points on the surface.\n\\begin{figure}[H]\n\t\\centering\n\\begin{tabular}{|l|l|l|}\n\t\\hline\n\t& the surface looks like a ... & such points are called ...\\\\ \\hline\n\t$\\kappa_1, \\kappa_2 $ both positive/negative & ellipsoid &  elliptic \\\\ \\hline\n\t$\\kappa_1, \\kappa_2$ have opposite signs & hyperboloid & hyperbolic \\\\ \\hline\n\t$\\kappa_1 \\kappa_2 = 0$ & cylinder/plane & parabolic \\\\\\hline\n\\end{tabular}\n\\end{figure}\n\\begin{figure}[H]\n  \\centering\n  \\begin{subfigure}[t]{0.30\\textwidth}\n    \\centering\n    \\includegraphics[width=4cm]{sphere}\n    \\caption{$ K > 0$}\n  \\end{subfigure}\n\t\\begin{subfigure}[t]{0.30\\textwidth}\n    \\centering\n    \\includegraphics[width=3cm]{wafer}\n    \\caption{$ K < 0 $}\n  \\end{subfigure}\n\t\\begin{subfigure}[t]{0.30\\textwidth}\n    \\centering\n    \\includegraphics[width=3cm]{parabola1}\n    \\caption{$K = 0$}\n  \\end{subfigure}\n\\end{figure}\nNote that because $K = \\kappa_1 \\kappa_2$ the above three classifications are essentially the classifications based on Gaussian curvature. This already suggests that the Gaussian curvature sees some \\emph{intrisic} curvature of surfaces.\\\\\n\n\\begin{ques}\n\tClassify the points on a torus as elliptic, hyperbolic, or parabolic.\n\t\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=10cm]{torus}\n  \\end{figure}\n\\end{ques}\n\n\\newpage\n\\subsection{Appendix: Spectral Theorem}\nA basis $ v_1, v_2, \\cdots, v_n$ of $ \\R^n$ is said to be \\textbf{orthonormal} if $ \\norm{v_i}=1 $ for each $ i$ and $ v_i \\cdot v_j = 0$ for $ i \\neq j$.\n\n\\begin{thm}[Spectral Theorem for Symmetric Matrices]\n\tLet $ A$ be a \\textbf{symmetric} $ n \\times n$ matrix with real entries. Then there exists an orthonormal basis $ v_1, v_2, \\cdots, v_n$ basis of $ \\R^n$ and real numbers $ \\kappa_i$ such that\n\t\\begin{align*}\n\t\tA v_i = \\kappa_i v_i\n\t\\end{align*}\n\tEquivalently, if $P$ is the matrix with columns $ v_i$ then\n\t\\begin{align*}\n\t\tP^{-1} A P =\n\t\t\\begin{bmatrix} \\kappa_1 &           &        &           \\\\\n\t\t\t          & \\kappa_2 &        &           \\\\\n\t\t\t          &           & \\ddots &           \\\\\n\t\t\t          &           &        & \\kappa_n\n\t\t\\end{bmatrix}\n\t\\end{align*}\n\tThe $ \\kappa_i$ (\\textbf{eigenvalues}) are unique up to permutations and the orthonormal basis $ v_1, v_2, \\cdots, v_n$ (\\textbf{eigenvectors}) and the matrix $ P$ are `essentially' unique.\n\\end{thm}\nThe following exercise outlines the proof for $n=2$.\n\n\n\\begin{ques}\n\tConsider the symmetric matrix $A = \\begin{bmatrix} a & b \\\\ b & c\\end{bmatrix}$. Assume that $A$ is not a scalar matrix i.e. $A \\not= \\begin{bmatrix} a & 0 \\\\ 0 & a\\end{bmatrix}=aI$ (this case is trivial).\n\t\\begin{enumerate}\n\t\t\\item Show that the equation\n\t\t\\begin{align*}\n\t\t\t\\det(A - \\kappa I) = \\det \\begin{bmatrix} a -\\kappa & b \\\\ b & c - \\kappa \\end{bmatrix} = 0\n\t\t\\end{align*}\n\t\thas 2 distinct real solutions $\\kappa_1, \\kappa_2$.\n\t\t\\item Argue that there exist 2 linearly independent unit length vectors $v_1, v_2$ satisfying\n\t\t$ A v_i = \\kappa_i v_i$\n\t\tfor $i = 1, 2$.\\hint{Look at the kernel of $A - \\kappa_i I$.}\n\t\t\\item Prove that $v_1 \\perp v_2$.\\hint{Find $v_1 ^ T A v_2$ in 2 different ways.}\n\t\\end{enumerate}\n\tLet $P$ be the matrix with column vectors $v_1, v_2$.\n\t\\begin{enumerate}[resume]\n\t\t\\item Prove that $P^T = P^{-1}$.\n\t\t\\item By an explicit computation show $P^T A P = \\begin{bmatrix} \\kappa_1 & 0 \\\\ 0 & \\kappa_2 \\end{bmatrix}$\n\t\\end{enumerate}\n\\end{ques}\n", "meta": {"hexsha": "d23e329f2e5ca2172ec1350d67b576f9df8d7883", "size": 11777, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03.tex", "max_stars_repo_name": "apurvnakade/mc2018-how-curved-is-a-potato", "max_stars_repo_head_hexsha": "d76acd32d3f030b4fbf3ed0cad3876639bdf4e8f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "03.tex", "max_issues_repo_name": "apurvnakade/mc2018-how-curved-is-a-potato", "max_issues_repo_head_hexsha": "d76acd32d3f030b4fbf3ed0cad3876639bdf4e8f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "03.tex", "max_forks_repo_name": "apurvnakade/mc2018-how-curved-is-a-potato", "max_forks_repo_head_hexsha": "d76acd32d3f030b4fbf3ed0cad3876639bdf4e8f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.6801619433, "max_line_length": 287, "alphanum_fraction": 0.6743652883, "num_tokens": 4090, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.826711776992821, "lm_q2_score": 0.9019206870747658, "lm_q1q2_score": 0.7456284539181657}}
{"text": "\n\\subsection{Definition and existence}\n\\begin{Definition}{qr-decomposition}\n  The \\define{QR decomposition} of a matrix $\\mata\\in\\C^{m\\times n}$\n  with $m\\ge n$ is the product\n  \\begin{gather}\n    \\mata = \\matq\\matr,\n  \\end{gather}\n  such that $\\matq \\in\\C^{m\\times n}$ is unitary and\n  $\\matr\\in \\C^{n\\times n}$ is upper triangular.\n\\end{Definition}\n\n\\begin{Lemma}{qr-columns}\n  Let $\\mata = \\matq\\matr$. Then, the column vectors of $\\mata$ and\n  $\\matq$ admit the relation\n  \\begin{gather}\n    \\va_k = \\sum_{i=1}^k r_{ik} \\vq_i.\n  \\end{gather}\n  If $r_{ii}\\neq 0$ for $i=1,\\dots,k$, this relation is uniquely\n  invertible. In particular,\n  \\begin{gather}\n    \\operatorname{span}\\{\\vq_1,\\dots,\\vq_k\\}\n    = \n    \\operatorname{span}\\{\\va_1,\\dots,\\va_k\\}.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Theorem}{qr-existence}\n  Every matrix $\\mata\\in\\C^{m\\times n}$ with $m\\ge n$ of full rank\n  admits a QR decomposition. It is unique under the condition that for\n  all $i$ there holds $r_{ii} > 0$.\n\\end{Theorem}\n\n\\subsection{Householder transformations}\n\n\\begin{Definition}{householder-transformation}\n  The \\define{Householder transformation}\n  associated with a vector $\\vw\\in\\C^n$ is\n  \\begin{gather}\n    \\matq_w = \\id - 2\\frac{\\vw\\vw^*}{\\vw^*\\vw}\n  \\end{gather}\n  It is also called \\define{Householder matrix} or, particularly in\n  the real case, \\define{Householder reflection}.\n\\end{Definition}\n\n\\begin{Lemma}{householder-symmetry}\n  For any vector $\\vw\\in\\C^n$ the Householder transformation\n  $\\matq_{\\vw}$ is Hermitian and orthogonal, that is,\n  \\begin{gather}\n    \\matq^{-1} = \\matq^* = \\matq.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Lemma}{householder-qr}\n  For any vector $\\vy\\in\\C^n$ there are vectors $\\vw_\\phi\\in\\C^n$ such\n  that $\\matq_{\\vw_\\phi} \\vy$ is a multiple of $\\ve_1$.\n\n  The vector of choice for numerical stability is\n  \\begin{gather}\n    \\vw = \\vy + e^{i\\phi} \\norm{\\vy}_2\\ve_1,\n  \\end{gather}\n  where $\\phi$ is the phase of $y_1$.\n\\end{Lemma}\n\n\\begin{proof}\n  The statement of the lemma says that for a suitable vector $\\vw$ there is a complex number\n  $\\alpha$ such that $\\matq_{\\vw} \\vy = \\alpha \\ve_1$. Since\n  $\\matq_{\\vw}$ preserves the Euclidean norm, we already know\n  \\begin{gather}\n    \\abs{\\alpha} = \\norm{\\vy}_2.\n  \\end{gather}\n  There holds\n  \\begin{gather}\n    \\alpha\\ve_1 = \\matq_{\\vw} \\vy\n    = \\vy - 2 \\frac{\\vw\\vw^*\\vy}{\\vw^*\\vw}\n    = \\vy - w \\frac{\\vw^*\\vy}{\\vw^*\\vw}\\vw.\n  \\end{gather}\n  Thus, $\\vw$ is in the span of $\\vy-\\alpha \\ve_1$. Since we divide by\n  its norm, its length does not matter and we let\n  \\begin{gather}\n    \\vw_\\phi =\n    \\begin{pmatrix}\n      y_1 - e^{i\\phi} \\norm{\\vy}_2\\\\y_2\\\\\\vdots\\\\y_n\n    \\end{pmatrix},\n    \\qquad\n    \\matq_{\\vw_\\phi}\\vy =\n    \\begin{pmatrix}\n      e^{i\\phi} \\norm{\\vy}_2\\\\0\\\\\\vdots\\\\0\n    \\end{pmatrix}.\n  \\end{gather}\n  Since the computation of the first component of $\\vw_\\phi$ is prone to loss of significance, we choose $\\phi$ as the phase of $-y_1$.\n\\end{proof}\n\n\\subsection{Givens rotation}\n\n\\begin{Definition}{givens}\n  The \\define{Givens-Rotation} $\\Omega_{jk}$ for $j<k$ with angle $\\theta$ is the matrix\n  \\begin{gather}\n      \\Omega_{jk} =\n    \\begin{pmatrix}\n      \\id \\\\\n      &c&\\cdots&s\\\\\n      &\\vdots&\\id &\\vdots\\\\\n      &-s&\\cdots&c\\\\\n      &&&&\\id\n    \\end{pmatrix}\n    \\in\\Cnn.\n  \\end{gather}\n  The corresponding mapping $\\Omega_{jk}\\colon x\\mapsto y$ is defined by\n  \\begin{gather}\n    y_i =\n    \\begin{cases}\n      c x_j + s x_k & i=j\\\\\n      -s x_j + c x_k & i=k\\\\\n      x_i &\\text{else}\n    \\end{cases}\n  \\end{gather}\n  where $c = \\cos\\theta$ and $s = \\sin\\theta$.\n\\end{Definition}\n\n\\begin{remark}\n  The entries $c$ and $s$ of the rotation matrix are in rows and\n  columns $j$ and $k$.  The identity matrices $\\id$ are of\n  corresponding dimensions.\n\n  Applying $\\Omega_{jk}$ to a matrix $\\mata$ from the left modifies rows  $j$ and $k$ of $\\mata$. Thus, it is a row operation similar to Gauss elimination.\n\n  The action of $\\Omega_{jk}$ on a vector corresponds to the rotation\n  in the plane spanned by $\\ve_j$ und $\\ve_k$. Thus, it is sufficient to investigated $2\\times2$-matrices.\n\n  Note that the notation $\\Omega_{jk}$ misses the angle $\\theta$. This\n  is due to the fact that it is always determined such that $y_k=0$.\n\\end{remark}\n\n\\begin{Lemma}{givens-computation}\n  Givens rotation $\\Omega_{jk}^*$ eliminates the second component of the vector\n  $(x_j,x_k)^T$ by choosing\n  \\begin{gather}\n    r = \\sqrt{x_j^2+x_k^2},\\qquad\n    c = \\frac{x_j}r,\\quad s = \\frac{x_k}r.\n  \\end{gather}\n  We obtain\n  \\begin{gather}\n    \\begin{pmatrix}\n      c & s \\\\ -s & c\n    \\end{pmatrix}\n    \\begin{pmatrix}\n      x_j\\\\x_k\n    \\end{pmatrix}\n    =\n    \\begin{pmatrix}\n      r\\\\0\n    \\end{pmatrix}\n    .\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{remark}\n  Computation of $r$ in the previous lemma is prone to numerical\n  overflow due to computation of $x_j^2$ or $x_k^2$, even if $r$\n  itself is within the numerical range. For the implementation, we can\n  use the function \\lstinline!hypot!. It computes the hypothenuse of a\n  right-angled triangle without overflow.\n\\end{remark}\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "5693c38c4d6fcacc1e155763fb6d74b8bd797937", "size": 5139, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nla/qr-decomposition.tex", "max_stars_repo_name": "guidokanschat/notes", "max_stars_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "nla/qr-decomposition.tex", "max_issues_repo_name": "guidokanschat/notes", "max_issues_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-05-24T07:31:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-31T12:58:14.000Z", "max_forks_repo_path": "nla/qr-decomposition.tex", "max_forks_repo_name": "guidokanschat/notes", "max_forks_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-05-15T19:28:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-05T19:07:29.000Z", "avg_line_length": 29.8779069767, "max_line_length": 155, "alphanum_fraction": 0.6450671337, "num_tokens": 1765, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117769928211, "lm_q2_score": 0.9019206666433899, "lm_q1q2_score": 0.7456284370273066}}
{"text": "\n\\graphicspath{{sec02/images/}{sec02/code/}}\n\\lstset{inputpath=sec02/code/}\n\n\\begin{frame}{Path}\n     \n     Path is the main TikZ essence.\n     \n    %  \\twocolImg{\n\\lstinputlisting[linerange={8-8, 11-13}]{pathmy.tex}\n% }{skipsmy}\n\n\\inclassFrag{what do you think ``(0,0)'', ``(0,1)'' for?}\n\n``(0,0)'', ``(0,1)'' is the simplest coordinate assignment. The (x, y) coordinate in units (typically 1cm)\n\n\\inclassFrag{Try to run the code}[4]\nThe \\ccol\\path\\ is not draw anything by itself!\n\\end{frame}\n\n\\begin{frame}{Draw}\\relax\n\\twocolImg{\n\\lstinputlisting[linerange={8-8, 14-16}]{drawmy1.tex}\n}{drawmy1}\n\n\\begin{columns}\n\\begin{column}{0.45\\textwidth}\n     \\lstinputlisting[linerange={8-8, 14-16}]{drawmy2.tex}\n\\end{column}\n \\begin{column}{0.45\\textwidth}\n %nothing    \n\\end{column}\n\\end{columns}\n\nUse \\ccol{\\draw} or \\ocol\\path[draw] to draw\n\\end{frame}\n\n\n\\begin{frame}{Fill}\\relax\n\\twocolImg{\n\\lstinputlisting[linerange={8-8, 14-16}]{fillmy.tex}\n}{fillmy}\n\nUse \\ccol{\\fill} or \\ocol\\path[fill] to fill. \n\nAnd {\\csk \\verb|--cycle| to make the path close}\n\\end{frame}\n\n\\begin{frame}{Options}\n\nLet us add some color!\n\n\\twocolImg{\n\\lstinputlisting[linerange={8-8, 14-17}]{fillcolormy.tex}\n}{fillcolormy}\n\nnew command \\ccol\\filldraw.\n\nNotice the \\textit{key=value} syntax!\n     \n\\end{frame}\n\n\\begin{frame}{Options}\n\nDraw another line\n\n\\twocolImg{\n\\lstinputlisting[linerange={8-8, 14-16}]{drawoptmy.tex}\n}{drawoptmy}\n\n\\end{frame}\n\n\\begin{frame}{Other figures}\n     \n\\twocolImg{\n\\lstinputlisting[linerange={9-9, 15-18}]{circlerectmy.tex}\n}{circlerectmy}\n      \n\\end{frame}\n\n\\begin{frame}{Nodes}\\relax\n\n\\twocolImg{\n\\lstinputlisting[linerange={9-9, 15-17}]{nodemy.tex}\n}{nodemy}\n\n\\ccol\\node\\ or \\ocol\\path[node]. Without optional arguments a node has no border\n     \n\\end{frame}\n\n\\inclassFrame{\n\\begin{frame}{Draw a snowman!}\n\\centering\n\\begin{tikzpicture}\n\n\\draw (0, 0) circle[radius=1.5cm];\n\\draw (0, 2.4) circle[radius=1cm];\n\\draw (0, 4) circle[radius=0.7cm];\n\\filldraw[fill=gray] (-0.5, 4.5) rectangle (0.5, 5.5);\n\\filldraw[fill=orange, draw=orange!50!red] (0.3, 4.1) -- (1.5, 4) -- (0.3, 3.9) -- cycle;\n\\draw[very thick, ->] (-4, 4.2) -- (-1, 3); \n\\node at (-4, 4.5) {snowman!};\n\\path (1, 3) -- (4, 5);\n\\end{tikzpicture}\n     \n\\end{frame}\n}\n\n\n\\begin{frame}{Vertical and horizontal}\\relax\n\\twocolImg{\n\\lstinputlisting[linerange={9-9, 15-17}]{curveverthor.tex}\n}{curveverthor}\n\nUse {\\csk -|} for ``first horizontal, than vertical''. Use {\\csk |-} for ``first vertical, than horizontal''\n\n\n\\skfootnote{\\tikzc{14.2.2}[152]}\n     \n\\end{frame}\n\n\n\\begin{frame}{Curves}\\relax\n\\vspace{-0.5cm}\n\\twocolImg{\n\\lstinputlisting[linerange={9-9, 15-20}]{curveinout.tex}\n}{curveinout}\n\\footnotesize\n\\ccol{to [out=.., in=..]} the angle on which curve flows out and the angle on which curve flows in.\n\n\\twocolImg{\n\\lstinputlisting[linerange={9-9, 15-19}]{curveibez.tex}\n}{curveibez}\n\n\\ccol{ .. controls <coord> and <coord> .. }\n\n\n\\skfootnote{\\url{https://en.wikipedia.org/wiki/Bezier_curve}}\n     \n\\end{frame}\n\n\n\\subsection{Coordinates}\n\n\\begin{frame}{``standart''}{x,y}\\relax\n\\twocolImg{\n\\lstinputlisting[linerange={15-21}]{coordinatesSimple.tex}\n}{coordinatesSimple}\n\\ccol{(<x-coord>, <y-coord>)}\n\\skfootnote{\\tikzc{13.2}[133]}\n\\end{frame}\n\\begin{frame}{``standart''}{x,y,z}\\relax\n\\twocolImg{\n\\lstinputlisting[linerange={15-21}]{coordinatesSimple2.tex}\n}{coordinatesSimple2}\n\\ccol{(<x-coord>, <y-coord>, <z-coord>)}\n\\skfootnote{\\tikzc{13.2}[133]}\n\\end{frame}\n\\begin{frame}{``standart''}{$\\theta$,r}\\relax\n\\twocolImg{\n\\lstinputlisting[linerange={15-21}]{coordinatesSimple3.tex}\n}{coordinatesSimple3}\n\\ccol{(<$\\theta$-coord>:<r-coord>)}\n\\skfootnote{\\tikzc{13.2}[133]}\n\\end{frame}\n\n\\begin{frame}[fragile]{``++'' and ``+=+'' cordinates}\\relax\n\\cprotect\\inclassFrag{Write\n\n\\begin{lstlisting}\n\\begin{tikzpicture}\n\\draw (-3,-3) rectangle (3,3);\n\\draw (2,0) node{1} -- (1,0) node{2}  -- (0,1)  node{3} -- (-1,0)  node{4} -- cycle;\n\\end{tikzpicture}\n\\end{lstlisting}\n\n\\begin{lstlisting}\n\\begin{tikzpicture}\n\\draw (-3,-3) rectangle (3,3);\n\\draw (2,0) node{1} -- ++(1,0) node{2}  -- ++(0,1)  node{3} -- ++(-1,0)  node{4} -- cycle;\n\\end{tikzpicture}\n\\end{lstlisting}\n\n\\begin{lstlisting}\n\\begin{tikzpicture}\n\\draw (-3,-3) rectangle (3,3);\n\\draw (2,0) node{1} -- +(1,0) node{2}  -- +(0,1)  node{3} -- +(-1,0)  node{4} -- cycle;\n\\end{tikzpicture}\n\\end{lstlisting}\n}[1]\n\\twocolImg{\n\\lstinputlisting[linerange={14-21}]{coordinatesPlus.tex}\n}{coordinatesPlus}\n \\begin{itemize}\n     \\item ``++'' use relative coordinate and set this new coordinate as ``current''\n     \\item ``+'' use relative coordinate and DOESN't set this new coordinate as ``current''\n      \n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{``Node''-based}\\relax\n\\twocolImg{\n\\lstinputlisting[linerange={16-22}]{coordinatesNode.tex}\n}{coordinatesNode}\n \n\\begin{enumerate}\n    \\item label node \\verb|\\node| \\ccol{(<label>)}\n    \\item refer to the node as \\ccol{(node cs:name=<label>)} \n    \\item you can also use things like <label>.west or <label>.right\n     \n\\end{enumerate}\n     \n\\end{frame}\n\n\\begin{frame}{Coordinate calculation\\magicPage}\\relax\n\\twocolImg{\n\\lstinputlisting[linerange={9-10, 15-20}]{coordinatesCalc.tex}\n}{coordinatesCalc}\n \n\\begin{enumerate}\n    \\item \\ccol\\usetikzlibrary\\{calc\\} \n    \\item syntax: {\\csk \\$<coord1>!fraction!<coord2>\\$}\n    \\item in this slide you can also see \\ccol\\foreach!\n     \n\\end{enumerate}\n     \n\\end{frame}\n\n\\begin{frame}{Coordinate intersection\\magicPage}\\relax\n\\twocolImg{\n\\lstinputlisting[linerange={9-10, 15-22}]{coordinatesInter.tex}\n}{coordinatesInter}\n \n\\end{frame}\n", "meta": {"hexsha": "e61e297b2a69c70c185cf5da9a2599f76f674ef5", "size": 5539, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2019_skoltech_ISP/03_TikZ_basis/sec02/sec02.tex", "max_stars_repo_name": "Lavton/latexLectures", "max_stars_repo_head_hexsha": "f8491351b2f74884689db24bbce2aa2270fa556a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-01-11T08:19:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-24T11:30:48.000Z", "max_issues_repo_path": "2019_skoltech_ISP/03_TikZ_basis/sec02/sec02.tex", "max_issues_repo_name": "Lavton/latexLectures", "max_issues_repo_head_hexsha": "f8491351b2f74884689db24bbce2aa2270fa556a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2019_skoltech_ISP/03_TikZ_basis/sec02/sec02.tex", "max_forks_repo_name": "Lavton/latexLectures", "max_forks_repo_head_hexsha": "f8491351b2f74884689db24bbce2aa2270fa556a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-20T17:52:16.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-20T17:52:16.000Z", "avg_line_length": 23.570212766, "max_line_length": 108, "alphanum_fraction": 0.6705181441, "num_tokens": 2038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436728, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.7455472837804432}}
{"text": "\\section{AMP: Adversarial Model Perturbation}\n\n\\begin{frame}{From Empirical Risk to AMP Loss}\n\n\\begin{columns}\n\n\\column{0.66\\textwidth}\n\nIn this paper, we optimize an alternative ``AMP loss''.\n\n\\vspace{1em}\n\n\\begin{equation*}\n\\mathcal{L}_\\mathrm{ERM}(\\boldsymbol{\\theta}):=\\frac{1}{|D|}\\sum_{(\\boldsymbol{x},\\boldsymbol{y})\\in\\mathcal{D}}\\ell(\\boldsymbol{x},\\boldsymbol{y};\\boldsymbol{\\theta})\n\\end{equation*}\n\n\\vspace{1em}\n\n\\begin{equation*}\n\\mathcal{L}_\\mathrm{AMP}(\\boldsymbol{\\theta}):=\\max_{\\Delta:\\Vert\\Delta\\Vert\\le\\epsilon}\\mathcal{L}_\\mathrm{ERM}(\\boldsymbol{\\theta}+\\Delta)\n\\end{equation*}\n\n\\vspace{2em}\n\n\\column{0.34\\textwidth}\n\n\\begin{figure}\n\\includegraphics[width=.8\\textwidth]{figs/loss_example_a.pdf}\n\\end{figure}\n\\vspace{-1.5em}\n\\begin{figure}\n\\includegraphics[width=.8\\textwidth]{figs/loss_example_b.pdf}\n\\end{figure}\n\\end{columns}\n\n\\vspace{2em}\n\n\\end{frame}\n\n\n\\begin{frame}{Training Algorithm}\n\nA mini-batch SGD is used for solving the ``min-max'' problem.\n\n\\vspace{-0.5em}\n\n\\begin{equation*}\n\\min_{\\boldsymbol{\\theta}}\\max_{\\Delta:\\Vert\\Delta\\Vert\\le\\epsilon}\\mathcal{L}_\\mathrm{ERM}(\\boldsymbol{\\theta}+\\Delta)\n\\end{equation*}\n\n\\begin{algorithm}[H]\n\\SetAlgoVlined\n\\While{$\\boldsymbol{\\theta}$ not converged}{\nInitialize perturbation $\\Delta$ with $\\boldsymbol{0}$\\;\n\\For{$n\\gets1\\text{ to }N$}{\nUpdate $\\Delta$ to maximize $\\!\\mathcal{L}_\\mathrm{ERM}(\\boldsymbol{\\theta}\\!+\\!\\Delta)\\!$ via gradient ascent with learning rate $\\zeta$\\;\n\\If{$\\Vert\\Delta\\Vert_2>\\epsilon$}{\nNormalize $\\Delta$ to restrict its norm $\\Vert\\Delta\\Vert_2$ to $\\epsilon$;\n}\n}\nUpdate $\\boldsymbol{\\theta}$ to minimize $\\mathcal{L}_\\mathrm{ERM}(\\boldsymbol{\\theta}\\!+\\!\\Delta)$ via gradient descent with learning rate $\\eta$\\;\n}\n\\caption{Adversarial Model Perturbation Training}\n\\end{algorithm}\n\n\\vspace{1em}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Implementation}\nSource code: \\url{https://github.com/hiyouga/AMP-Regularizer}\n\n\\begin{minted}[linenos]{python}\nfrom amp import AMP\noptimizer = AMP(model.parameters(), lr=0.1, epsilon=0.5, momentum=0.9)\nfor inputs, targets in dataset:\n    def closure():\n        optimizer.zero_grad()\n        outputs = model(inputs)\n        loss = loss_fn(outputs, targets)\n        loss.backward()\n        return outputs, loss\n    outputs, loss = optimizer.step(closure)\n\\end{minted}\n\\end{frame}\n", "meta": {"hexsha": "01750c317391febe232fb24ce5fb078ef96caf26", "size": 2318, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/amp.tex", "max_stars_repo_name": "hiyouga/AMP-Poster-Slides-LaTeX", "max_stars_repo_head_hexsha": "c1fd40aa5ef3216f17b4d27dc6e6092e3cc52e40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-05-25T11:56:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-20T07:12:01.000Z", "max_issues_repo_path": "slides/amp.tex", "max_issues_repo_name": "hiyouga/AMP-Poster-Slides-LaTeX", "max_issues_repo_head_hexsha": "c1fd40aa5ef3216f17b4d27dc6e6092e3cc52e40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-05-28T15:25:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-30T05:01:24.000Z", "max_forks_repo_path": "slides/amp.tex", "max_forks_repo_name": "hiyouga/AMP-Poster-Slides-LaTeX", "max_forks_repo_head_hexsha": "c1fd40aa5ef3216f17b4d27dc6e6092e3cc52e40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-05-26T01:39:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T06:36:04.000Z", "avg_line_length": 26.9534883721, "max_line_length": 167, "alphanum_fraction": 0.7079378775, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.7931059487389966, "lm_q1q2_score": 0.7454508690461922}}
{"text": "\\lab{Public Key Cryptography}{RSA}\n\\objective{Understand the fundamentals of RSA public key cryptography.}\n\nHow do you exchange information over unsecure, public channels fo communcations?\nHistorically, the answer has been to use some sort of cipher to obscure the meaning of a message.\nMany ciphers use a secret key which was used to encrypt and decrypt any sent messages.\nHowever, the problem then became how to keep the key secret and known only to the authorized recipients\nIf the key was obtained by any attackers, then the whole cipher was compromised.\n\nPublic key cryptography provides a way for each person to have their own keys.\nThere is no need to transmit any keys.\nThere are several public key crypto systems, but one of the most popular is RSA.\nIn the RSA system, each person has a public key and a private key.\nThe security of the system is founded in the difficulty of factoring large numbers.\n\nTo make RSA feasible, we need the following two results.\n\\section*{Fast Modular Exponentiation}\nHow would we compute $8^{3039} \\pmod{38}$?\nWe understand that one possible way of computing it would be\n\\[\n8*8*8*8*\\dots (3034 \\text{ more times}) *8 \\pmod{38}\n\\]\nCalculating $8^8 = 16777216$!\nMultiplying by $8$ each time leads to an enormous number which will finally be modded by $38$.\nThis will yield the answer $8^{3039} \\equiv 18 \\pmod{38}$.\nHowever, we end up taking the mod of a number that is $2746$ digits!\nImagine if our exponent was hundreds of digits!\nWe could quickly run out of memory.\n\nWe can avoid dealing such huge numbers by doing the mod after each multiplication.\nDoing the mod after each multiplication means that the largest number we have to deal with in this problem is 240.\nIn general, we wouldn't have to work with anything larger than $37^{2}$.\nHowever, if we still have large exponent, the loop doing the multiplication would still have to run $3039$ iterations.\n\n\\begin{problem}\nWrite a function that will naively calculate $b^{e} \\pmod{m}$.\nDo not use Python's built-in power function.\n\\label{prob:naivepower}\n\\end{problem}\n\nWe need a faster better way.\nThe most common method of modular exponentiation is the \\emph{right-to-left binary method}.\nThe essence of this method is to use the binary representation of the exponent.\nWe can quickly calculate the power up to the nearest power of two of the exponent.\nThis we simply calculate the remaining part the naieve way.\n\nCalculating a modular exponent in this way leads to a very desirable $O(\\log_2 e)$ runtime performance, where $e$ is the exponent.\n\n\\begin{problem}\nWrite a function that will perform modular exponentiation using the right-to-left binary method.\nCompare the performance of \\ref{prob:naivepower} and your new implementation.\nNote that Python's built-in function, \\li{pow()}, performs this type of fast modular exponentiation.\nWe expect you to use it instead of your own implementation in the future.\n\\label{prob:rlbpower}\n\\end{problem}\n\n\\section*{Fermat's Little Theorem}\nAn integral part of RSA relies on working with large prime numbers.\nPrime numbers are numbers that are only divisible by 1 and the number itself.\nIn the RSA algorithms, we need to start with two prime numbers, $p$ and $q$.\nWe multiply these numbers to get $n=pq$ which is our modulus.\nHowever, if $n$ is not that big, we can easily factor it, defeating the whole purpose of RSA.\nThe security of RSA largely reduces down to how well we choose starting primes.\nIf we pick primes that are too small, we sacrifice security.\nHow do we pick large primes?\nWe can use sieves to generate primes, but doing so would take lots of time and lots of memory.\nIt would be better if we could choose a number and determine if it is prime or not.\n\nFortunately, mathematics has developed a few tools that can help us out.\nOne of the first steps was given by Fermat.\n\\begin{theorem}[Fermat's Little Theorem]\nIf $p$ is prime, then for a natural number $a$, $a^{p-1} - 1 \\equiv 0 \\pmod{p}$\n\\end{theorem}\nBut, to use this we have start with a prime number.\nHowever, if we have a candidate for $p$ and it satisifies the condition can we say anything about $p$?\nThe answer is yes, but we cannot say that $p$ is prime.\nWe can only say that $p$ might be prime.\n\\begin{example}\nSuppose $p=37$.\nWe want to know if $p$ is prime.  We choose $a=8$.\n\\[\n8^{36} - 1 \\equiv 0 \\pmod{37} \n\\]\nWe call $8$ the witness number.  Think of as, \\emph{$8$ says that $37$ is prime}.\nThis is the probabilistic part of Fermat's theorem.\nWe try enough witness numbers until we are convinced that our candidate number is prime.\nTrying enough prime numbers, we will eventually be convinced that $37$ is prime, which it is.\n\\end{example}\n\n\\begin{example}\nLet's check the primality of $1729$.\nWe will use $a=145$ as a witness number.\n\\[\n145^{1728} \\equiv 1 \\pmod{1729}\n\\]\nIt appears that $1729$ is prime.\nLet's try another witness number, $a=583$.\n\\[\n583^{1728} \\equiv 1 \\pmod{1729}\n\\]\nLet's try one last witness number, $a=945$.\n\\[\n945^{1728} \\equiv 742 \\not\\equiv 1 \\pmod{1729}\n\\]\nWe have a problem.  \nOur candidate is not behaving like we would expect a prime to behave.\nBut several witnesses verified that our number was prime.  What happened?\nOur number, $1729$ is not really prime.  Its prime factors are $7$, $13$, and $19$. \nIt is a special number called a Carmichael number.\nBecause of these numbers, we have to be careful with Fermat's Little Theorem.\nMore stringent primality tests exist, but are beyond the scope of this lab.\n\\end{example}\nWe have to remember that the Fermat test is really a test for compositeness, not primality.\n\n\\begin{problem}\nFor any candidate prime number, $n$, all the integers $2 \\geq a < n$ can serve as a witness number.\nEach of these possible witness numbers will either prove the compositeness of $n$ or give no information.\nIf we randomly choose a witness number, we will select a number in one of these two sets.\nSupposing we chose a good random number generator, we can become convinced to a very high degree that $n$ is likely prime with just a few witness numbers.\n\nWrite a function that will return the number of witnesses that prove the compositeness of $n$.\nWhat is the ratio of these witness numbers to all the numbers $2 \\geq a < n$?\nSuppose we were to choose witness numbers at random.  \nHow many random witness numbers must we choose to be $99$\\% sure that $n$ is prime?\nRemember that each new witness number increases the confidence that $n$ is probably prime.\n\\label{prob:prime_confidence}\n\\end{problem}\n\n\\section*{RSA Algorithm}\nBob wants to send a secret message to Alice.\nEve is trying to intercept this message.\nBob and Alice agree to use RSA to exchange the secret message.\nBob and Alice need to generate their keys.\nEach generate a pair of keys, a private and a public one.\nBoth Bob and Alice need to keep their private keys secret.\nAnyone with Alice's public key can send her a message that only she can decrypt.\nBob obtains a copy of Alice's pulic key and encrypt his message using it.\nAlice decrypts Bob's message using her private key, and reads the message.\n\nRSA involves generating a private key and a public key.\n\nWe begin by finding two large prime numbers.\nBy large, we mean several hundred digits.\n\nRSA can be succinctly summarised as the following operations for encryption and decryption respectively\n\\[\nc \\equiv m^e \\pmod{n}\n\\]\n\\[\nm \\equiv c^d \\pmod{n}\n\\]\n\n\\begin{problem}\nGenerate a public/private key pair.\n\nWe do this by first multiplying the two primes, $p$ and $q$, together to get $n=pq$.\nThis will act as the modulus for future operations.\nNext we need to choose an encryption exponent, $e$, such that $1 < e < \\phi(n)$ and $\\gcd(e, \\phi(n)) = 1$.\nEuler's totient function is \nThen our decryption exponent, $d$, must naturally be an inverse of $e$ mod $\\phi(n)$.\nIn other words, we need $de \\equiv 1 \\pmod{\\phi(n)}$.\nYou will need to write your own function that finds the inverse of $e$ mod $\\phi(n)$ using the Extended Euclidean Algorithm.\nWe distribute $(e, n)$ as the public key and need to make sure that $(d, n)$ remains private.\nAfter the keys are created, we have no further need of $p$ or $q$.\n\\end{problem}\n\nBefore we can encrypt and decrypt a text message, we need to convert it to a number first.\nIt is useful to understand the code below.\n\\begin{lstlisting}\n# Recipe from itertools module in standard library\ndef grouper(iterable, n, fillvalue=None):\n    \"Collect data into fixed-length chunks or blocks\"\n    # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx\n    args = [iter(iterable)] * n\n    return izip_longest(fillvalue=fillvalue, *args)\n    \ndef a2i(msg):\n    '''Convert an ASCII message to an integer.'''\n    # bytearray will give us the ASCII values for each character\n    if not isinstance(msg, bytearray):\n        msg = bytearray(msg)\n    binmsg = []\n    # convert each character to binary\n    for c in msg:\n        binmsg.append(bin(c)[2:].zfill(8))\n    return int(''.join(binmsg), 2)\n\ndef i2a(msg):\n    '''Convert an integer to an ASCII message'''\n    # convert to binary first\n    binmsg = bin(msg)[2:]\n    # we need to pad the message so length is divisible by 8\n    binmsg = \"0\"*(8-(len(binmsg)%8)) + binmsg\n    msg = bytearray()\n    for block in grouper(binmsg, 8):\n        # convert block of 8 bits back to ASCII\n        msg.append(int(''.join(block), 2))\n    return msg\n\\end{lstlisting}\n\n\\begin{problem}\nEncrypt the message: \\emph{Simon sells seashells by the seashore.}\nLet $p=83285677$ and $q=2848968679$.\nChoose $e=65593$.\nVerify your encryption is correct by decrypting the message and checking the result.\n\\end{problem}\n\n\\begin{warn}\nThe security of RSA depends on keeping the private key secret.  \nIf an attacker is able to obtain the private key, then the security of the entire algorithm is compromised.\nWhen sharing keys, be absolutely sure that you are making only the public keys available and securely storing the private keys.\nThis is especially important with digital signatures since an attacker with a private key can impersonate the owner of that private key.\nIf a private key is compromised, generating a new RSA key is the only remedy.\n\\end{warn}\n\n\n\\subsection*{Digital Signatures}\nSuppose Alice wants to confirm that Bob was really the sender of a message.\nHow would she do this?\nUsing the RSA algorithm, you can easily sign a message to verify authenticity.\nThis is done by encrypting the message using Alice's public key and then decrypting the result with Bob's private key.\nOrder is very important.  \nSwitching the two steps will result in the same message, but there are security vulnerablilities doing that way.\n\nAnother, more commonly used, method for signing messages is to sign a hash of the message.\nUsing a known good hash function, we hash the message (before encrypting), sign the hash, and send it along with the encrypted message.\nThe exchange would be as follows for the message \\emph{Hi Alice! Bob.}\nSuppose Bob's private and public keys respectively are $(d, n) = (127890504297793865743357757627627807059, 618783157710153965827030630189807545377)$ and $(e, n)=(65323, 618783157710153965827030630189807545377)$.\nAlice's private and public keys respectively are $(d,n)=(16630354644972796093082980345041785609, 58576444815385640869376382633234713033)$ and $(e,n)=(54905, 58576444815385640869376382633234713033)$.\nFirst Bob would hash the message.  We will use MD5, but in practice we should a hash algorithm which is considered cryptographically secure.\nThe hash of the message (including the period symbol) in hexidecimal is: \\verb|\\x02\\xd2\\x0b\\xe2\\x00Vnd:\\xbdY\\x8c\\x1d\\x08/M|.\nBob would encrypt the message using Alice's public key obtaining: $1243069665756046897997663464501811921$.\nBob can then sign the hash of the message which results in: $378011416081119417777777120819271568111$.\nTo sign the hash of the message, he decrypts the hash with his private key (calculates $m^{d} \\mod n$).\n\nWhen Alice recieves Bob's message and signature she can decrypt the message using her private key.\nAlice decrypts the message: $1468662431139370234409485782180398$ which translates to \\emph{Hi Alice! Bob.}\nShe can then verify that the message came from Bob by encrypting the signature with Bob's public key.\nThis yeilds: $3749079344037002869620996734462734157$.\nNow she must hash the message that she decrypted (she would need to know that Bob used MD5 for the signature hash).\nShe compares the hash of the message she decrypted with the hash she obtained by encrypting Bob's purported signature.\nIf the two hashes are equal, she can be reasonably certain that the message she decrypted indeed came from Bob (since we assume that only Bob has his private key).\nShe verifies the hashes and they are equal.\nIf the hashes differed, then Alice would know that either the message was signed with someone else's private key, or the message itself was tampered with after it was signed.\nIn either event, Alice can choose to ignore the message because she can verify its authenticity.\n\n\\section{PyCrypto}\nRSA encryption in Python can be accomplished very easily with a library called PyCrypto.\nThis library contains many secure hash functions, random number generators, and encryption classes.\nMany programs use PyCrypto for their security needs.\n\\begin{warn}\nMake certain that you are using the latest version of PyCrypto.\nSecurity software is updated often to fix security vulnerablilities and bugs.\nThe current version of PyCrypto at the time of writing is version 2.6.1.\n\\end{warn}\n\nThe RSA module in PyCrypto is located in the PublicKey module.\nLet's try a small example using PyCrypto.\nThe library allows us to explicity construct a key, or generate a key automatically.\n\\begin{lstlisting}\n>>> from Crypto.PublicKey import RSA\n>>> from Crypto import Random\n>>> keypair = RSA.generate(2048) #generate a 2048-bit RSA key\n>>> publickey = keypair.publickey()\n>>> share_this = publickey.exportkey()\n\\end{lstlisting}\n\nThe RSA encryption and decryption methods on these keys are textbook approaches.\nHowever, to increase security, we will want to pad the messages so every message encrypted with a particular will become exactly as large (in bits) as the key itself.\nA commonly used padding algorithm is implemented in PyCrypto in the \\li{Crypto.Cipher.PKCS1_OAEP} module.\n\\begin{lstlisting}\n>>> from Crypto.Cipher import PKCS1_OAEP as oaep\n\n# generate a new key from the original RSA key.\n# This key can encrypt and decrypt\n>>> paddedkey = oaep.new(keypair)\n>>> encrypted = paddedkey.encrypt('hello world')\n>>> paddedkey.decrypt(encrypted)\n'hello world'\n\\end{lstlisting}\n\nTo sign the message we use PyCrypto's \\li{Crypto.Signature.PKCS1_PSS} module.\nWe first need to hash the message using a cryptographically secure hash, such as SHA.\nJust as only private keys can decrypt, only private keys can sign.\nPublic keys can decrypt and verify.\n\\begin{lstlisting}\n>>> from Crypto.Signautre import PKCS1_PSS as pss\n>>> from Crypto.Hash import SHA\n>>> sigkey = pss.new(keypair)\n>>> mhash = SHA.new(\"Hello World\")\n>>> sigkey.sign\n\\end{lstlisting}\n\n\n\\begin{problem}[Group Project]\nSplit into several groups of at least three individuals.\nEach group member should generate a private and public keypair using PyCrypto.\nShare your public keys with everyone in the group.\n\nYou might find it useful to transmit your messages as strings.\nHere are two functions that will read and write specially formatted strings for your messages.\n\\begin{lstlisting}\ndef print_msg(m_encrypted):\n    #print the encrypted message as a specially formatted string\n    out = (\"----BEGIN MESSAGE----\",\n           m_encrypted[0],\n           \"----END MESSAGE----\",\n           \"----BEGIN SIGNATURE----\",\n           m_encrypted[1],\n           \"----END SIGNATURE----\")\n    return '\\n'.join(out)\n\ndef read_msg(m_string):\n    d1 = m_string.find('----BEGIN MESSAGE----') + 21\n    d2 = m_string.find('----END MESSAGE----', d1)\n    \n    d3 = m_string.find('----BEGIN SIGNATURE----', d2) + 23\n    d4 = m_string.find('----END SIGNATURE----', d3)\n    message  = m_string[d1:d2]\n    sign = m_string[d3:d4]\n    return message.strip(), sign.strip()\n\\end{lstlisting}\n\n\\begin{enumerate}\n\\item Encrypt and sign a message for someone in the group and send it to the entire group.\nAttach the sender's name to the encrypted message (a claim that the message came from a particular sender).\nIn this exercise we will verify that the actual origin of the message is indeed the claimed origin.\nEach group member should do the following:\n\\begin{enumerate}\n\\item Decrypt and verify the message addressed for you.\n\\item Attempt to decrypt and verify message addressed for someone else in the group.\n\\item Report the message and verified signature.\n\\end{enumerate}\n\n\\item Encrypt and sign a different message for someone in the group and send it, anonymously, to the entire group.\nFor example, if Bob encrypts a message and sends it to Alice, he should claim the message came from another individual.\nEach group member should do the following:\n\\begin{enumerate}\n\\item Decrypt and verify the message address to you.\n\\item Report the message and verified signature.\n\\end{enumerate}\n\\end{enumerate}\n\\end{problem}\n\nThe security of RSA relies on the assumption that certain mathematical operations are not easily done.\nBreaking RSA reduces down to being able to factor the modulus into its two primes.  This is hard to do for large moduli.\nThere is no proof of security.  RSA can be broken depending on the laziness of the keyholder, or the cleverness of the attacker.\nTo keep ahead of advances in computing speed, the RSA key size is increased beyond the capability of existing hardware.\nHowever, larger keys mean that messages will take longer to encrypt and decrypt.\nThere are a new family of methods that rely on elliptic curves.\nThese methods can acheive the same security of RSA using smaller key sizes.\nFor example a $224$ bit elliptic curve key gives comparable security to a $2048$ bit RSA key.", "meta": {"hexsha": "3e0af7823b50680f2e3d4200d84c6844e981a89f", "size": 17882, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/RSA/PublicKey.tex", "max_stars_repo_name": "rachelwebb/numerical_computing", "max_stars_repo_head_hexsha": "e7416b43b97976060f6875fa46c7dca20a9f635f", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/RSA/PublicKey.tex", "max_issues_repo_name": "rachelwebb/numerical_computing", "max_issues_repo_head_hexsha": "e7416b43b97976060f6875fa46c7dca20a9f635f", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/RSA/PublicKey.tex", "max_forks_repo_name": "rachelwebb/numerical_computing", "max_forks_repo_head_hexsha": "e7416b43b97976060f6875fa46c7dca20a9f635f", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.8011363636, "max_line_length": 211, "alphanum_fraction": 0.7602617157, "num_tokens": 4377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240930029118, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.7454236143043316}}
{"text": "\\section{Conditional Probability}\n\n\\subsection{Conditional Probability}\n\n\\begin{theorem}\n    \\begin{equation}\n        \\probability{E} = \\begin{cases}\n            \\displaystyle \\sum_y \\probability{E|Y = y} p(Y=y) \\\\\n            \\displaystyle \\int_{-\\infty}^\\infty f_Y(y) \\dif{y}\n        \\end{cases}\n    \\end{equation}    \n\\end{theorem}\n\n\n\\subsection{Conditional Expectation}\n\n\\begin{definition}\n    The \\cindex{conditional probability mass function} of $X$ given $Y=y$ is \n    \\begin{equation}\n        p_{X|Y}(x|y) = \\dfrac{p(x,y)}{p_Y (y)}\n    \\end{equation}\n    \n    The \\cindex{conditional probability density function} of $X$ given $Y=y$ (where $f_Y (y) > 0$) is \n    \\begin{equation}\n        f_{X|Y}(x|y) = \\dfrac{f(x,y)}{f_Y (y)} = \\dfrac{f(x,y)}{\\displaystyle \\int_x f(x,y) \\dif{x}}\n    \\end{equation}\n\\end{definition}\n\n\n\n\n\n\\begin{definition}\n    The \\cindex{conditional expectation} of $X$ given $Y=y$ is \n    \\begin{equation}\n        \\displaystyle \\expect{X|Y=y} = \\begin{cases}\n            \\displaystyle \\sum_x x \\cdot p_{X|Y}(x|y) \\\\\n            \\displaystyle \\int_{-\\infty}^\\infty x f_{X|Y} (x|y) \\dif{s}\n        \\end{cases} \n    \\end{equation}\n\\end{definition}\n\nNote: $\\expect{X|Y}$ is a random variable of $Y$. $Y$ here may be an expression of $X$ as the following example shows.\n\n\\begin{example}\n    If $X$ and $Y$ are independent variable, calculate the conditional expectation of $X$ given $X+Y=n$.\n\\end{example}\n\n\n\\begin{theorem}\n    \\begin{equation}\n        \\begin{aligned}\n            \\expect{X} &= \\expect{ \\expect{X|Y}} \\\\\n            &= \\begin{cases}\n                \\displaystyle \\sum_y \\expect{X|Y = y} \\probability{Y=y} \\\\\n                \\displaystyle \\int_{-\\infty}^\\infty \\expect{X|Y=y} f_Y (y) \\dif{y}\n            \\end{cases}\n        \\end{aligned}\n    \\end{equation}\n\\end{theorem}\n\n\n\n\n\n% conditional variance\n\\subsection{Conditional Variance}\n\n\\begin{theorem}\n    \\begin{equation}\n    \\begin{aligned}\n        \\variance{X|Y=y} &= \\expect{(X - \\expect{X|Y=y})^2 | Y=y} \\\\\n        &= \\expect{X^2|Y=y}- \\left(\\expect{X|Y=y} \\right)^2\n    \\end{aligned}\n    \\end{equation}\n\\end{theorem}\n\n\\begin{theorem}\n \\begin{equation}\n        \\variance{X} = \\expect{\\variance{X|Y}} + \\variance{\\expect{X|Y}}\n    \\end{equation}    \n\\end{theorem}\n\n\n\n\n\n\n\n\n% example\n\\subsection{Example}\n\n\\begin{example}\n    A miner is trapped in a mine containing 3 doors. The first door needs to a tunnel that takes him to safety after 2 hours. The second door take him back after 3 hours and the third door takes him back after 5 hours. What is the expected length of time until the miner reaches out when he chooses the door equally?    \n    \\qed\n\\end{example}\n\n\\begin{example}\n    $n$ men through their hat into the room and randomly select one. They will leave the game if they have selected their own hat.\n    \\begin{enumerate}\n        \\item \\label{hatq1} what is the probability of no match in first round?\n        \\item \\label{hatq2} what is the probability of k match in first round?\n        \\item \\label{hatq3} what is the expected match in first round?\n        \\item \\label{hatq4} what is the variance of match in first round?\n        \\item \\label{hatq5} what is the expected number of rounds?\n        \\item \\label{hatq6} what is the variance of rounds?\n        \\item \\label{hatq7} what is the expected total number of selection?\n        \\item \\label{hatq8} what is the expected number of wrong selection for each man?\n    \\end{enumerate}    \n\\end{example}\n\\begin{proof}\n    define these variables:\n    \\begin{itemize}\n        \\item $R_n$: the number of rounds necessary for $n$ men.\n        \\item $S_n$: the total number of all selection.\n        \\item $C_i$: the number of all wrong selection by $i$th man.\n        \\item $X_n$: the number of matches in the first round.\n    \\end{itemize}\n    \n    For question (\\ref{hatq1}) let $E_n$ be the event that no match occurs in $n$ men scenario, $M$ be the event that the first man select its own hat. We have\n    \\begin{equation*}\n        \\probability{E_n} = \\probability{E_n|M} \\probability{M} + \\probability{E_n|M^c} \\probability{M^c}\n    \\end{equation*}\n\n    Because $\\probability{E|M} = 0$, $\\probability{E_n} = \\dfrac{n-1}{n} \\probability{E_n|M^c} $.\n    \n    In $M^c$ case, the first man selected the hat of another person. there are two possibilities on whether the other person select the hat of the first man:\n    \\begin{enumerate}\n        \\item the \"another\" man did not select the hat of first man. In this case, $\\probability{E_{n}|?} = \\probability{E_{n-1}}$.\n        \\item the \"another\" man did select the hat of the first man. In this case, $\\probability{E_{n}|?} = \\probability{E_{n-2}} \\probability{?} = \\dfrac{1}{n-1} \\probability{E_{n-2}}$.\n    \\end{enumerate}\n    \n    So \n    \\begin{equation*}\n        \\probability{E_n} = \\probability{E_{n-1}} + \\frac{1}{n-1} \\probability{E_{n-2}}\n    \\end{equation*}\n    \n    and $\\probability{E_n} = \\displaystyle \\sum_{i=2}^n \\frac{(-1)^i}{n!}$\n    \n    \n    For question (\\ref{hatq2}), for any fixed group of $k$ men that select their own hat, the probability is \n    \\begin{equation*}\n        \\frac{1}{n} \\frac{1}{n-1} \\cdots \\frac{1}{n-(k-1)} \\probability{E_{n-k}} = \\frac{(n-k)!}{n!} \\probability{E_{n-k}}\n    \\end{equation*}\n    \n    Because there are $\\binom{n}{k}$ choices of $k$ men, the result is\n    \\begin{equation*}\n        \\frac{(n-k)!}{n!} \\probability{E_{n-k}} \\binom{n}{k} = \\frac{1}{k!} \\sum_{i=2}^{n-k} (-1)^{n-k} \\frac{1}{i!}\n    \\end{equation*}\n    \n    Another way is to calculate the length $C$ of the cycle that contains the first man. we have \n    \n    \\begin{equation*}\n    \\begin{aligned}\n        \\probability{E_n} &= \\sum_{k=1}^n \\probability{E_n|C=k} \\probability{C=k} \\\\\n        &= \\sum_{k=1}^n \\probability{E_{n-k}} \\probability{C=k}\n    \\end{aligned}\n    \\end{equation*}\n    \n    We have \n    \\begin{equation*}\n        \\probability{C=k} = \\frac{n-1}{n} \\frac{n-2}{n-1} \\cdots \\frac{n-k+1}{c-k+2} \\frac{1}{n-k+1} = \\frac{1}{n}\n    \\end{equation*}\n    \n    So $\\displaystyle \\probability{E_n} = \\frac{1}{n} \\sum_{k=2}^n \\probability{E_{n-k}}$.\n    \n    \n    \n    For equestion question (\\ref{hatq3}), the probability $i$th man select its hat is $\\probability{H_i} = \\dfrac{1}{n}$, so \n    \\begin{equation*}\n        \\begin{aligned}\n            \\expect{\\sum_i H_i} &= \\sum_i \\expect{H_i} \\\\\n            &= \\sum_i \\frac{1}{n} \\\\\n            &= 1\n        \\end{aligned}\n    \\end{equation*}\n    \n    For question (\\ref{hatq4}), the $\\variance{ \\sum_i H_i} = 1$\n    \n    For question (\\ref{hatq5}), \n    \\begin{equation*}\n    \\begin{aligned}\n        \\expect{R_n} &= \\sum_{i=0}^n \\expect{R_n | X_n = i} \\probability{X_n = i} \\\\\n        &= \\sum_{i=0}^n (1 + \\expect{R_{n - i}}) \\probability{X_n = i} \\\\\n        &= 1 + \\expect{R_n} \\probability{X_n = 0} + \\sum_{i=0}^n \\expect{R_{n-i}} \\probability{X_n=i} \\\\\n        &= \\expect{R_n} \\probability{X_n = 0} + n(1 - \\probability{X_n = 0} )\n    \\end{aligned}\n    \\end{equation*}\n    \n    So the only solution is $\\expect{R_n} = n$.\n    \n    For question (\\ref{hatq6}), for the variance, we have\n    \\begin{equation*}\n        \\expect{R_n|X} = 1 + \\expect{R_{n-X}} = 1 + n - X\n    \\end{equation*}\n    \n    Also we have $\\variance{R_n|X} = \\variance{R_{n-X}}$. So we have\n    \\begin{equation*}\n        \\begin{aligned}\n            \\variance{R_n} &= \\expect{\\variance{R_n|X}} + \\variance{\\expect{R_n|X}} \\\\\n            &= \\expect{\\variance{R_{n-X}}} + \\variance{X} \\\\\n            &= \\sum_{i=0}^n \\variance{R_{n-j}} \\probability{X=j} + \\variance{X} \\\\\n            &= \\variance{R_n}\\probability{X = 0} + \\sum_{j=1}^n \\variance{R_{n-j}} \\probability{X=j} + \\variance{X}\n        \\end{aligned}\n    \\end{equation*}\n    \n    The solution is $\\variance{R_n} = n$.\n    \n    \n    For question (\\ref{hatq7}), for $S_n$, we have\n    \\begin{equation*}\n        \\expect{S_n} = n + \\expect{S_{n - X_n}}\n    \\end{equation*}\n    And the solution is $\\expect{S_n} = n + \\dfrac{n^2}{2}$.\n    \n    For question (\\ref{hatq8}),\n    \\begin{equation*}\n        \\begin{aligned}\n            \\sum_{j=1}^n (C_j + 1) & = S_n \\\\\n            \\expect{C_j} &= \\expect{C_j + 1} -1 \\\\\n            &= \\dfrac{\\expect{S_n}}{n}  -1\\\\\n            &= \\left( 1 + \\frac{n}{2} \\right) - 1 \\\\\n            &= \\frac{n}{2}\n        \\end{aligned}\n    \\end{equation*}\n\\end{proof}\n\n\\begin{example}\nwhat is the number of necessary trial to get $k$ consecutive success? Each trial has probability $p$ of being successful.\n\\end{example}\n\\begin{proof}\n    Let $N_k$ the number of $k$ consecutive success. $A_{k-1, k}$ be the additional trial from $k-1$ success to $k$ success, so\n    \\begin{equation*}\n        \\expect{N_k} = \\expect{N_{k-1}} + \\expect{A_{k-1, k}}\n    \\end{equation*}\n    \n    We have \n    \\begin{equation*}\n        \\expect{A_{k-1,k}} = 1 \\times p + (1 + \\expect{N_k}) (1-p) = 1 + (1-p) \\expect{N_k}\n    \\end{equation*}\n    So\n    \\begin{equation*}\n        \\expect{N_k} = \\frac{1}{p} + \\frac{\\expect{N_{k-1}}}{p}\n    \\end{equation*}\n    with \n    \\begin{equation*}\n        \\expect{N_1} = \\frac{1}{p}\n    \\end{equation*}\n    So\n    \\begin{equation*}\n        \\expect{N_k} = \\sum_{i=1}^k \\frac{1}{p^i}\n    \\end{equation*}\n\\end{proof}\n\n\n\\begin{example}\n    Analyse the quick sort algorithm    \n\\end{example}\n\\begin{proof}\n    Suppose there are $n$ numbers and all permutation are of equally likely. Let $M_n$ be the expected number of comparison needed for $n$ numbers. So\n    \\begin{equation*}\n    \\begin{aligned}\n        M_n &= \\sum_{j=1}^n \\expect{\\text{number of comparison} | \\text{pivot is the } i \\text{th smallest}} \\frac{1}{n} \\\\\n        &= \\sum_{j=1}^n (n - 1 + M_{j-1} + M_{n - j}) \\frac{1}{n} \\\\\n        &= n - 1 + \\frac{2}{n} \\sum_{k=1}^{n-1} M_k\n    \\end{aligned}\n    \\end{equation*}\n    \n    So\n    \\begin{equation*}\n        \\begin{aligned}\n            M_{n+1} &= 2(n+2) \\sum_{i=1}^n \\frac{i}{(i+1)(i+2)} \\\\\n            &\\approx 2(n+2) \\log{(n+2)}\n        \\end{aligned}\n    \\end{equation*}\n\\end{proof}\n\n\n\\begin{example}[compound random variable]\n    Let $X_i$ be identical independent random variable with mean $\\mu$ and variance $\\sigma^2$. Let $N$ be random variable. The random variable $\\displaystyle \\sum_{i=1}^N X_i$ is called \\cindex{compound random variable}. Its expectation is $\\displaystyle \\expect{\\sum_{i=1}^N X_i} = \\expect{N} \\expect{X}$, and the variance is $\\variance{\\sum_{i=1}^N X_i} = \\sigma^2 \\expect{N} + \\mu^2 \\variance{N}$\n\\end{example}\n\\begin{proof}\n    Let $\\displaystyle S = \\sum_{i=1}^N X_i $  be the random variable. \n    \\begin{equation*}\n        \\begin{aligned}\n            \\displaystyle \\expect{S| N = n} &= \\expect{\\sum_{i=1}^n X_i | N = n} \\\\\n            &= \\expect{\\sum_{i=1}^n X_i} \\\\\n            &= n \\expect{X}\n        \\end{aligned}\n    \\end{equation*}\n    Thus\n    \\begin{equation*}\n        \\expect{S} = \\expect{N \\expect{X}} = \\expect{N} \\expect{X}\n    \\end{equation*}\n    \n    \\begin{equation*}\n        \\begin{aligned}\n            \\displaystyle \\variance{S|N=n} &= \\variance{\\sum_{i=1}^n X_i | N = n} \\\\\n            &= \\variance{\\sum_{i=1}^n X_i} \\\\\n            &= n \\variance{X}\n        \\end{aligned}\n    \\end{equation*}\n    So $\\variance{S|N} = N \\variance{X}$, $\\expect{S|N} = N \\expect{X}$, and\n    \\begin{equation*}\n        \\begin{aligned}\n            \\variance{S} &= \\expect{\\variance{S|N}} + \\variance{\\expect{S|N}} \\\\\n            &= \\expect{N} \\variance{S} + \\variance{N}\\left(\\expect{S}\\right)^2\n        \\end{aligned}\n    \\end{equation*}\n\\end{proof}\n\n\\begin{example}\n    For $n$ distinct value, select the biggest one using the following rules:\n    \\begin{enumerate}\n        \\item determine the maximum of first $k$ value. reject all of them.\n        \\item select the first one that is larger than the maximum value just found.\n    \\end{enumerate}\n    What is the probability that the rule select the maximum among all $n$ values?\n\\end{example}\n\\begin{proof}\n    Let $X$ be the position of largest value and $P_k(\\text{best})$ be the probability that the best value is elected using the rule. We have\n    \\begin{equation*}\n        \\begin{aligned}\n            P_k (\\text{best}) &= \\sum_{i=1}^n P_k (\\text{best} | X = i) p(X=i) \\\\\n            &= \\frac{1}{n} \\sum_{i=1}^n P_k (\\text{best}|X=i)\n        \\end{aligned}\n    \\end{equation*}\n    Because the largest will be selected if the largest of first $k$ is also the largest of first $i-1$, we have\n    \\begin{equation*}\n        P_k(\\text{best} | X=i) = \\frac{k}{i-1}\n    \\end{equation*}\n    So\n    \\begin{equation*}\n        \\begin{aligned}\n            P_k(best) &= \\frac{1}{n} \\sum_{i=1}^n P_k (\\text{best}|X=i) \\\\\n            &= \\frac{k}{n} \\sum_{i=k+1}^n \\frac{1}{k-1} \\\\\n            &\\approx \\frac{k}{n} \\int_k^{n-1} \\frac{1}{x} \\dif{x} \\\\\n            &= \\frac{k}{n} \\log{\\frac{n-1}{k}}\n        \\end{aligned}\n    \\end{equation*}\n    The best $k$ is $\\dfrac{1}{e} n$.\n\\end{proof}\n\n\\begin{example}[The Ballot Problem]\n    In an election candidate A received $n$ notes and B received $m$ notes where $n > m$. What is the probability that A is always ahead of B?\n\\end{example}\n\\begin{proof}\n    Let $P_{n,m}$ denote the probability. By conditioning on who receive the last vote, we have:\n    \\begin{equation*}\n        P_{n,m} = \\frac{n}{n+m} P_{n-1,m} + \\frac{m}{n+m}P_{n,m-1}\n    \\end{equation*}    \n    The solution is $P_{n,m} = \\dfrac{n-m}{n+m}$\n\\end{proof}\n\n\n\\begin{example}\n    A coin has $p$ of being head. What is the probability that the total number of head equals tail after $2n$ flip?    \n\\end{example}\n\\begin{proof}\n    \\begin{equation*}\n        \\begin{aligned}\n            \\probability{\\text{first time } = 2n} &= \\probability{\\text{first time } = 2n | n \\text{ heads in first } 2n} \\binom{2n}{n} p^n (1-p)^n \\\\\n            &= P_{n,n-1} \\binom{2n}{n} p^n (1-p)^n \\\\\n            &=  \\frac{\\displaystyle \\binom{2n}{n} p^n (1-p)^n}{2n - 1}\n        \\end{aligned}\n    \\end{equation*}\n\\end{proof}\n\n\\begin{example}\n    What is the probability that the first time there are $i$ more heads than tails occurs after the $2n+i$   flip?\n\\end{example}\n\\begin{proof}\n    it occurs $\\iff$ starting from the final flip and working backwards, the head is always in the lead.\n\\end{proof}\n\n\n\n\n\n\n", "meta": {"hexsha": "8154cfaf094bfa74dc365f893f1f200b4d4419fa", "size": 14121, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/probability/p.2.conditional_expectation.tex", "max_stars_repo_name": "elvisren/machine-learning-notes", "max_stars_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-07T03:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-04T17:28:22.000Z", "max_issues_repo_path": "src/probability/p.2.conditional_expectation.tex", "max_issues_repo_name": "elvisren/machine-learning-notes", "max_issues_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/probability/p.2.conditional_expectation.tex", "max_forks_repo_name": "elvisren/machine-learning-notes", "max_forks_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-01T23:34:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-01T23:34:47.000Z", "avg_line_length": 36.9659685864, "max_line_length": 400, "alphanum_fraction": 0.5848735925, "num_tokens": 4819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.8652240756264638, "lm_q1q2_score": 0.7454236131757571}}
{"text": "\\chapter{Relationship between SA and SGD (Minibatch)}\n\\section{From SGD (minibatch) to SA}\nWe first consider the following lost function \n$$ \nF(x) = \\frac{1}{N} \\sum_{i=1}^N f_i(x),\n$$ \nwhere $N$ is the number of data point. The Minibatch SGD is written\nas \n\\begin{equation} \\label{equ:minibatch}\nx^{n+1} = x^n - \\Delta t_{n} \\nabla F_{B_n}(x^n),\n\\end{equation}\nwhere \n$$ \nF_{B_n}(x) = \\frac{1}{|B_n|} \\sum_{j \\in B_n} f_j(x).\n$$ \nNow, we rewrite \\eqref{equ:minibatch} as \n\\begin{equation} \\label{equ:minibach-SA}\nX^{n+1} = X^n - \\Delta t_{n} \\nabla F(X^n) + \\Delta {t}_n\n\\underbrace{[\\nabla F(X^n) - \\nabla F_{B_n}(X^n)]}_{Y^n}. \n\\end{equation}\n\n\\begin{equation} \\label{equ:minibach-SA}\nX^{n+1} = X^n - a_{n} \\nabla F(X^n) + a_n\n[\\nabla F(X^n) - \\nabla F_{B_n}(X^n)-\\frac{b_n}{a_n}] + b_nW_n \n\\end{equation}\n\\begin{equation} \\label{equ:minibach-SA}\nX^{n+1} = X^n - a_{n} [\\nabla F(X^n) + \\xi_n] + b_nW_n \n\\end{equation}\nwhere\n$$\na_n=\\Delta t_n, \\xi_n=\\nabla F(X^n) - \\nabla F_{B_n}(X^n)-\\frac{b_n}{a_n}W_n.\n$$\n\nLet $p_i$ is the probability of choosing the $i$-th component to\nthe minibatch. We note here that each component may be in the\nminibatch for more than once. Then, we have \n$$ \n\\begin{aligned}\n\\mathbb{E}(Y^n) &= \\nabla F(X^n) - \\mathbb{E} [\\nabla F_{B_n}(X^n)] \\\\\n&= \\frac{1}{N} \\sum_{i=1}^N \\nabla f_i(X^n) - \\frac{1}{|B_n|}\n\\mathbb{E}[\\sum_{j\\in B_n} \\nabla f_j(X^n)] \\\\\n&= \\frac{1}{N} \\sum_{i=1}^N \\nabla f_i(X^n) - \\mathbb{E}[\\nabla\nf(X^n)] \\qquad (\\text{independence}) \\\\\n&= \\frac{1}{N} \\sum_{i=1}^N \\nabla f_i(X^n) - \\sum_{i=1}^N p_i \\nabla\nf_i(X^n).\n\\end{aligned}\n$$ \nTherefore, we have the following condition\n\\begin{equation} \\label{equ:mean-condition}\n\\frac{1}{N}\\sum_{i=1}^N \\nabla f_i(x^n) = \\mathbb{E}[\\nabla f(X^n)].\n\\end{equation}\nFrom the above condition, a simple choice is $p_i = \\frac{1}{N}$,\nnamely uniform distribution. Condition \\eqref{equ:mean-condition}\ncan also be written as $\\mathbb{E}(Y^n) = 0$.\n\nNote that ${\\rm Var}(Y^n) = \\mathbb{E}[Y^n (Y^n)^T] - \\mathbb{E}(Y^n)\n\\mathbb{E}(Y^n)^T = \\mathbb{E}[Y^n (Y^n)^T]$. For simplicity,\nwe remove the dependence of $X^n$ in the following. Then, \n$$ \n\\begin{aligned}\n{\\rm Var}(Y^n) &= \\mathbb{E}[ (\\nabla F - \\nabla F_{B_n})\n(\\nabla F - \\nabla F_{B_n})^T ]\n\\\\\n&= \\mathbb{E}[\\nabla F_{B_n} (\\nabla F_{B_n})^T ] - \\nabla F (\\nabla\n    F)^T \\\\\n&= \\frac{1}{|B_n|^2} \\mathbb{E}_{i_1} \\mathbb{E}_{i_1} \\cdots\n\\mathbb{E}_{i_{|B_n|}}[ (\\sum_{j=1}^{|B_n|} \\nabla f_{i_j})\n  (\\sum_{j=1}^{|B_n|} \\nabla f_{i_j})^T ] - \\nabla F (\\nabla F)^T \\\\\n&= \\frac{1}{|B_n|^2} \\mathbb{E}_{i_1} \\mathbb{E}_{i_2} \\cdots\n\\mathbb{E}_{i_{|B_n|}}[ \\sum_{j,r=1 , i\\neq j}^{|B_n|} \\nabla f_{i_j}\n(\\nabla f_{i_r})^T] \\\\ \n& ~~ + \\frac{1}{|B_n|^2} \\mathbb{E}_{i_1} \\mathbb{E}_{i_2} \\cdots\n\\mathbb{E}_{i_{|B_n|}} [\\sum_{j=1}^{|B_n|} \\nabla\nf_{i_j} (\\nabla f_{i_j})^T]- \\nabla F (\\nabla F)^T \\\\ \n& = (1 - \\frac{1}{|B_n|}) \\mathbb{E}(\\nabla f) [\\mathbb{E}(\\nabla\n    f)]^T + \\frac{1}{|B_n|} \\mathbb{E}[ (\\nabla f) (\\nabla f)^T] -\n\\nabla F (\\nabla F)^T \\\\\n&= \\frac{1}{|B_n|} \\left( \\mathbb{E}[(\\nabla f) (\\nabla f)^T] -\n    \\mathbb{E}(\\nabla f) [\\mathbb{E}(\\nabla f)^T] \n    \\right) \\\\\n&= \\frac{1}{|B_n|} {\\rm Var}(\\nabla f).\n\\end{aligned}\n$$ \n\n\\begin{remark}\nSince the index here can be repeated, there is NO need that ${\\rm\nVar}(Y^n) = 0$ when $|B_n| = N$.\n\\end{remark}\n\nIn summary, we have \n\\begin{equation} \\label{equ:summary}\n\\mathbb{E}(Y^n) = 0, \\qquad {\\rm Var}(Y^n) = \\frac{1}{|B_n|} {\\rm\n  Var}(\\nabla f).\n\\end{equation}\nIt is conceivable that the result can be extended to the expectation\nversion of the lost function, namely, \n$$ \nF(x) = \\mathbb{E}_{\\xi} f(x, \\xi).\n$$ \n\n\n\\section{Convergence result}\nIn the SA scheme, \n\\begin{equation} \\label{equ:SA}\nX^{n+1} = X^n - \\Delta t_n \\nabla F(X^n) + \\sigma_n W_{\\Delta t_n},\n\\end{equation}\nthe convergence is proven under the following condition: \n$$ \n\\Delta t_n = \\mathcal{O}(n), \\qquad \\sigma_n^2 =\n\\mathcal{O}(\\frac{1}{n \\log\\log n})\n$$ \nCompare the variance of $\\sigma_n W_{\\Delta t_n}$ and $\\Delta t_n\nY^n$, we have \n$$ \n\\sigma_n^2 \\Delta t_n \\approx \\Delta t_n^2 {\\rm Var}(Y^n),\n$$ \nwhich implies that \n$$ \n\\frac{1}{|B_n|} {\\rm Var}(\\nabla f) =\n\\mathcal{O}(\\frac{\\sigma_n^2}{\\Delta t_n}) =\n\\mathcal{O}(\\frac{1}{\\log\\log n}).\n$$ \nWe conclude that, if the SGD is stagnated, namely ${\\rm Var}(\\nabla\nf)$ stays the almost the same, we need to slowly increase the size of\nminibatch in the way that \n\\begin{equation} \\label{equ:batch-size}\n|B_n| = \\mathcal{O}(\\log\\log n).\n\\end{equation}\n\n\n\\begin{remark}\nThe above argument requires that $\\nabla f(x, \\xi)$ is Gaussian on\n$\\xi$ for any $x$. This assumption holds for linear Gaussian\nregression. \n\\end{remark}\n\n\n\n", "meta": {"hexsha": "f1e470987d6d96df2868d6cb94c5a65d7f5587ef", "size": 4659, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/SA_minibatch.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/SA_minibatch.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/SA_minibatch.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.5179856115, "max_line_length": 77, "alphanum_fraction": 0.6149388281, "num_tokens": 2046, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388754, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.7453950487636856}}
{"text": "\\section{Probability}\nThis section is mostly an introduction (or a refresher?) to some tools and ideas from probability theory. One of the main reasons for including it is that it lets us give backround to the final sub-section on Brownian motion, but we'll also use some of the methods from here in the final section of the course on complex networks.\n\nPhysical variables can be either continuous or discrete. Continuous variables, like the spatial position of a particle ${\\bf r} = (x,y,z);$ $x\\rightarrow x+dx$ allow us to apply tools from differential calculus. Discrete variables (like the spin of an electron, the face of a playing card, or the energy level of a quantum particle) require a different approach. As the number of discrete states gets gets large, it is possible to approximate a discrete system by a continuous one. However, there are often statistical reasons why this is not always the best approach. (For an example of the issue of approximating a discrete distribution with a continuous one, see the article  Clauset, Shalizi, and Newman. ``Power-Law Distributions in Empirical Data.'' SIAM Review (2009) doi:10.1137/070710111) \n\n[It is probably a good idea to add a bibliography to the notes and use LaTex citations, (along with naming the reference in the text to make it more readable.)]\n\nHere we are going to look at some simple discrete distributions, including one of the simplest --- the binomial distribution which describes the probability of events that can take one of only two possible outcomes. The tool we will employ to study these distributions is \\emph{probability generating functions} (or generating functions for short). Although PGFs can be somewhat cumbersome, they provide a very powerful general tool that can applied to a wide range of situations involving discrete probabilities. In this sense they are like the Taylor series of discrete probability.\n\n\\subsection{Probability generating functions}\nA probability generating function (PGF) is a polynomial whose coefficients are the probabilities associated with each outcome of some random process.\nFor example, the PGF for an equal probability die is \n$$\\calG(x) = 0x^0+\\frac16x^1+\\frac16x^2+\\frac16x^3+\\frac16x^4+\\frac16x^5+\\frac16x^6.$$\nAs an example of how PGFs are a handy general tool, say we now wanted to find the PGF for the sum when we roll two such dice. We can just multiply the PGFs to get $\\calG'(x) = \\calG(x)\\calG(x) = 0x^0 + 0x^1+\\frac{1}{36}x^1x^1+\\frac{2}{36}x^1x^2+\\cdots+\\frac{1}{36}x^6x^6.$\n\nMore generally, the set of probabilities associated with any discrete distribution can be used as coefficients of $\\calG(x)$:\n$$\\calG(x) = P(X=r_0)x^0+P(X=r_1)x^1+\\cdots = \\sum_{n=0}^\\infty P(X=r_n)x^n.$$\n\n\\subsection{Properties of generating functions}\n\\begin{eqnarray*}\n\t\\calG(0)&=&P(X=0)\\\\\n\t\\calG(1)&=&\\text{sum over all probabilities}=1\n\\end{eqnarray*}\nThe two properties above are easy to see and are not unexpected. More interesting is the fact that derivatives of PGFs can be used to obtain expressions for the mean, and higher order moments, of the distribution associated with the PGF.\n\n\\begin{eqnarray*}\n\t\\frac{d}{dx}\\calG(x)=\\calG'(x)&=&\\sum_r rP_r x^{r-1},\\qquad\\text{and}\\\\\n\t\\calG''(x)&=&\\sum_r r(r-1)P_rx^{r-2}.\n\\end{eqnarray*}\n\nIf we evaluate the first derivative of the PGF at 1 we get\n$$\\calG'(1) = \\sum_r rP_r.$$\nThe expected value of an arbitrary function $f(r)$ is given by $\\langle f(r)\\rangle = \\sum_r f(r) P(X=r)$, therefore $\\calG'(1) = \\langle r\\rangle$ --- the expected value, or mean, of the distribution.\n\nSimilarly,  Evaluating $\\calG''(x)$ at 1 gives \n$$\\calG''(1) = \\sum_r r(r-1)P(X=r) = \\langle X(X-1)\\rangle.$$\n\nWhy would we care about being able to find $\\langle X(X-1)\\rangle = \\langle X^2 -X\\rangle$? Because the variance of X, is given by \n$$ V(X) = \\langle X^2\\rangle -\\langle X\\rangle^2.$$ We are therefore able to construct $V(X)$ from combinations of $\\calG$, $\\calG'$, and $\\calG''$.\nWe can use the fact that $\\langle X^2 -X\\rangle =\\langle X^2\\rangle-\\langle X\\rangle$ I.e. $\\sum(r^2-r)P(X=r)=\\sum r^2P(X=r)-\\sum rP(X=r)$ to get\n\n\\begin{eqnarray}\nV(X)&=&\\langle X^2\\rangle - \\langle X\\rangle^2\\\\\n&=&\\underbrace{\\langle X^2\\rangle -  \\langle X \\rangle}_{\\calG''(1)} + \\underbrace{\\langle X\\rangle}_{\\calG'(1)} - \\underbrace{\\langle X \\rangle^2}_{\\calG'(1)^2}\\\\\n&=& \\calG''(1) +\\calG'(1)-\\calG'(1)^2 \\label{eq:binvar}\n\\end{eqnarray}\n\n%Generating functions may not always be the shortest way to find the properties of some distribution, but they are a powerful way.\n\n\\subsection{The binomial distribution}\nThe binomial distribution describes the probability of getting $r$ identical outcomes from a sequence of $N$ events where each event has only two possible states, e.g. number of heads from a sequence of coin tosses, number of Au atoms from deposition of Au and Ag atoms in some sputtering process, or number of spin up electrons in an uncorrelated system.\n\nThe probabilities for the binomial distribution are given by\n$$P(X=r) = \\binom{N}{r}p^rq^{N-r}, ~\\text{ where } \\binom{N}{r} = \\frac{N!}{r!(N-r)!}, ~~r=0,1,\\ldots,N$$\nand where (mostly) $p+q=1$.\nThe PGF for the binomial distribution is therefore given by $\\calG(x) = \\sum_{r=0}^N\\binom{N}{r}p^rq^{N-r}x^r$. \nThe coefficients in the binomial distribution are (not surprisingly) the coefficients from the  binomial expansion theorem. This means that instead of writing the PGF as a sum, we can easily express it (and its derivatives) as a polynomial:\n\\begin{eqnarray*}\n\t\\calG(x)  &=& (xp +q)^N \\\\\n\t\\calG'(x) &=& N(xp+q)^{N-1}p\\\\\n\t\\calG''(x) &=& N(N-1)(xp+q)^{N-2}p^2. \n\\end{eqnarray*}\n\nEvaluating the above at $x=1$ gives:\n\t\\begin{eqnarray*}\n\t\\calG(1) &=& (p+x)^N = 1 ~\\text{ if } p+q=\\\\\n\t\\calG'(1) &=& N(p+q)^{N-1}P = Np  ~\\text{ if } p+q=1\\\\\n\t\\calG''(1) &=& N(N-1)(p+q)^{N-2}p^2 \\\\\n\t\t&=&N(N-1)p^2  ~\\text{ if } p+q=1.\n\\end{eqnarray*}\nAs expected, we have $\\langle X\\rangle =Np$ for the event associated with the probability $p$.\nSimilarly, we can calculate the variance of the binomial distribution using equation \\ref{eq:binvar}\n\\begin{eqnarray*}\n\tV(X) &=&\\calG''(1) - \\calG'(1) -\\calG'(1)^2\\\\\n\t\t&=& N^2p^2-Np^2+Np-N^2p^2\\\\\n\t\t&=& N(p-p^2)\\\\\n\t\t&=& Np(1-p)= Npq.\n\\end{eqnarray*}\n\nIf you are feeling enthusiastic, compare the calculation above with the usual method for finding the variation of the binomial distribution without using a PGF.\n\n\\subsection{The Poisson distribution}\nSince the Poisson distribution shows up quite often in stat mech, we will have a look at how its properties can be derived via PGFs.\nThe Poisson distribution describes the probability of $r$ distinct events occur in a time interval, given that the long-run average rate is $\\lambda$ per time interval. It has probabilities given by $P(X=r) = \\frac{\\lambda^r}{r!}\\exp(-\\lambda)$. The PGF for the Poisson distribution is given by\n$$G(x) = \\sum_r=0^\\infty \\frac{\\lambda^r}{r!}\\exp(-\\lambda)x^r = \\exp(-\\lambda)\\sum\\frac{(\\lambda x)^r}{r!}.$$\nNote that the sum in the last term of the expression above is the power series expansion for the exponential function. Handy --- we can now write:\n\\begin{eqnarray*}\n\\calG(x) &=& \\exp(-\\lambda)\\exp(\\lambda x)\\\\\n\\calG'(x) &=& \\lambda\\exp(-\\lambda)\\exp(\\lambda x)\\\\\n\\calG''(x)&=&\\lambda^2\\exp(-\\lambda)\\exp(\\lambda x)\n\\end{eqnarray*}\n\nSo we have $\\langle X \\rangle = \\calG'(1) = \\lambda$, as per the definition, and\n$$V(X) = G''(1) + G'(1) - G'(1)^2 = \\lambda^2+\\lambda-\\lambda^2 = \\lambda.$$\n\n\\subsection{The expected long-run outcome of a binary process}\nWhat is the net outcome we can expect from a sequence of $N$ binary events? What is the variance in this net outcome? How long can we expect the net outcome to remain positive? \n\nThink of a sequence of coin tosses where heads implies $+1$ and tails implies $-1$. We will denote the number of heads from $N$ events as $n_h$ and the number of tails as $n_t = N-n_h$, then the net outcome is $d = n_t-n_h = N-2n_h$. \n\nIf $p=q=\\frac12$ then the expected value of $d$ is $\\langle d\\rangle= 0$. (It's easy to check this: $\\langle d\\rangle = \\langle N-2n\\rangle = N-2\\langle n\\rangle = N-\\frac{2}{2}N=0.$)\n\nWe want to find the variation in $d$, or rather, the root-mean-squared deviation \n$$d_{rms} = \\left(\\langle d^2\\rangle - \\langle d\\rangle^2\\right)^{\\frac12} =  \\langle d^2\\rangle^{\\frac12}.$$\n\nAt this point we'll drop the subscript in $n$ since we only have $n_h$ and since the probabilities are equal. From $d=N-2n$ we have $$ \\langle d^2\\rangle = \\langle (N-2n)^2\\rangle = \\langle N^2 -4Nn+4n^2\\rangle.$$\nWe know that $\\langle n\\rangle = \\calG'(1)=Np=N/2$ and from the expressions for $\\calG''(1)$ and $\\calG'(1)$ we get $\\langle n^2 \\rangle = \\calG''(1) + \\calG'(1)$ where $\\calG''(1) = N^2p^2 = N^2/4-N/4$. We can now calculate $\\langle d^2 \\rangle$.\n\n\\begin{eqnarray*}\n\t\\langle d^2 \\rangle &=& N^2 -4N\\frac{N}{2}+4\\left(\\frac{N^2}{4}-\\frac{N}{4}+\\frac{N}{2}\\right)\\\\\n\t\t&=& N^2-2N^2+N^2+N\\\\\n\t\t&=& N.\n\\end{eqnarray*}\nSo, $d_{rms}=\\sqrt{N}$ and the variance in the net expected outcome scales like $\\sqrt{N}$ as $N$ increases. I.e. after $N$ steps we expect to be a rms distance of $\\pm \\sqrt{N}$ away from the mean of zero.\n\n[Draw/add a figure of this with N as the independent variable.]\n\nWe can now look at how this would change if the binary process had some small bias $\\alpha = |p-q| >0$. In this case, at each step, the expected outcome is $\\alpha$ and the bounds for the rms distance from the mean are $\\alpha N\\pm\\sqrt{N}$. \n\n[Draw/add this too.]\n\n\\subsection{Brownian motion}\nBrownian motion is a model that describes the behaviour of particles in suspension (e.g. of dust in air, fine silt in dirty water) that have some velocity but which are constantly changing direction as they are buffeted by other particles. Their motion can be understood through a calculation similar to that for the net outcome of the binary process above, but in 3D.\n\nThe conceptual model that is often used when discussing Brownian motion is that of a \\emph{random walk}. Consider a random walker who after $n$ steps is at the position ${\\bf r} = (x,y,z)$. Each step is given by ${\\bf s}_{n+1} = {\\bf r}_{n+1}- {\\bf r}_n$ and has step length $s_n$ in a random and uncorrelated direction ${\\bf\\hat{s}}_n$. Again (by symmetry) $\\langle {\\bf s}\\rangle =0$. We want to find how far a particle might have gone after $N$ steps. We will define $\\lambda^2= \\langle {\\bf s}^2\\rangle$ --- the average square step-length. We write ${\\bf r}_N$ for the position of the walker (or the particle) after $N$ steps, then\n\\begin{eqnarray*}\n\t\\langle {\\bf r}_N^2 \\rangle &=& \\bigg\\langle \\left(\\sum_{n=1}^N{\\bf s}_n\\right)^2 \\bigg\\rangle\\\\\n\t\t&=& \\bigg\\langle \\sum_{n=1}^N{\\bf s}_n^2 +2\\sum_{n=1}^{N-1}\\sum_{m=n+1}^N{\\bf s}_n\\cdot{\\bf s}_m \\bigg\\rangle\\\\\n\t\t&=& \\sum\\underbrace{\\langle {\\bf s}_n\\rangle}_{=\\lambda^2} + 2\\sum\\sum \\underbrace{\\langle {\\bf s}_n \\cdot {\\bf s}_m \\rangle}_{=\\langle {\\bf s}_n\\rangle \\cdot \\langle{\\bf s}_m \\rangle=0}\n\\end{eqnarray*}\n\nThe first term in the expression is the mean squared step-length while the second term is zero since there is no correlation between the directions of each of the steps. Hence $\\langle {\\bf r}_N\\rangle = N\\lambda^2$ and the rms displacement is $\\sqrt{N}\\lambda$. If the number of steps is proportionate to the length of time that the particles move for, then we have that the mean-square displacement scales like $\\sqrt{t}$. This is one of the key features of diffusive processes. \n\n\n\n\n", "meta": {"hexsha": "e308320ff98c74537f57879dc9f650cd2f077c9d", "size": 11404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03-probability.tex", "max_stars_repo_name": "wvan478/708Notes2018", "max_stars_repo_head_hexsha": "0a4ef44e261f2892b0e927aeadf7f06adda1b80b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-02-28T20:47:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-10T19:05:54.000Z", "max_issues_repo_path": "03-probability.tex", "max_issues_repo_name": "wvan478/708Notes2018", "max_issues_repo_head_hexsha": "0a4ef44e261f2892b0e927aeadf7f06adda1b80b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-03-07T20:07:07.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-18T20:53:19.000Z", "max_forks_repo_path": "03-probability.tex", "max_forks_repo_name": "wvan478/708Notes2018", "max_forks_repo_head_hexsha": "0a4ef44e261f2892b0e927aeadf7f06adda1b80b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2018-02-26T21:38:05.000Z", "max_forks_repo_forks_event_max_datetime": "2018-04-15T22:54:11.000Z", "avg_line_length": 83.2408759124, "max_line_length": 798, "alphanum_fraction": 0.7078218169, "num_tokens": 3571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.7453592026782963}}
{"text": "\\section{Basic Topology}\n\n\\subsection{Exercise 1}\nThe empty set has no elements, so all of its elements are vacuously also elements\nof every set.\n\n\\subsection{Exercise 2}\nThe roots of complex polynomials with integer coefficients can be expressed \nas elements of the countable cross product of $\\mathbb{N}$ with itself\n(cross $\\mathbb{N}$ with itself $n$ times for the coefficients, and then once\nmore to indicate which root).\n\n\\subsection{Exercise 3}\nIf all real numbers were algebraic, then the set of algebraic numbers would be\nuncountable (thus contradicting Exercise 2).\n\n\\subsection{Exercise 4}\nThe set of irrational numbers is $\\mathbb{R} / \\mathbb{Q}$, which\nmust be uncountable as otherwise $\\mathbb{R}$ would be countable.\n\n\\subsection{Exercise 5}\nWe can use $\\big(\\frac{n}{n+1}\\big)_{n \\in \\mathbb{N}} \\cup \\big(\\frac{2n}{n+1}\\big)_{n \\in \\mathbb{N}} \\cup \\big(\\frac{3n}{n+1}\\big)_{n \\in \\mathbb{N}} $ to get the three limit points $1, 2, 3$.\n\n\\subsection{Exercise 6} \nIf $p$ is a limit point of $E'$, then every neighborhood of $p$ contains\na limit point $q$ of $E$, and every neighborhood of $q$ contains a point\nof $E$ thereby implying that $p$ is a limit point of $E$. $E$ and $E'$ \ndo not need to have the same limit points, since $E'$ could be finite\nand thus have no limit points.\n\n\\subsection{Exercise 7}\n(a) If $p$ is a limit point of $\\overline{B_n}$, then every neighborhood\nof $p$ contains a point $q \\in A_i$. Since there are only finitely many $A_i$,\n$p$ must be a limit point for at least one of the $A_i$, as an infinite number\nof neighborhoods of $p$ must have non-zero intersection with some of the $A_i$.\n\n(b) If we take $A_i = \\big(\\frac{i n}{(i + 1)n+1}\\big)_{n \\in \\mathbb{N}}$, then\n1 is a limit point of $B_n$ despite not being a limit point of any of the $A_i$.\n\n\\subsection{Exercise 8}\nEvery point of an open set in $\\mathbb{R}^2$ is by definition a limit point of\nthe set, since the point must have a neighborhood contained in the set. The same\nis not true for closed sets, since we can just take a finite set.\n\n\\subsection{Exercise 10}\nEvery set in $X$ is open, since any set containing $p$ also contains $N_r(p)$ for $r < 1$.\nNo set in $X$ is closed, since $N_r(p) = p$ for $r < 1$. All infinite sets in $X$ are not\ncompact, since we can take balls of radius $r < 1$ around each point as an open cover.\n\n\\subsection{Exercise 12}\nTake any open cover of $K$. There must be some open set in this cover containing 0,\nwhich means that the same set contains all but a finite number of the elements of $K$ \n(since 0 is the only limit point of $K $). Take a union of this set as well as the finitely\nmany other sets containing the aforementioned points to get a finite subcover.\n\n\\subsection{Exercise 13}\nTake $\\cup_{k = 1}^\\infty \\{0, \\big(\\frac{n}{kn+1}\\big)_{n \\in \\mathbb{N}}, \\frac{1}{k}\\}$.\nThis set is closed and bounded, so it is compact by Heine-Borel. Its limit points\nare 0 and $\\big(\\frac{1}{k}\\big)_{n \\in \\mathbb{N}}$.\n\n\\subsection{Exercise 14}\nWe can use $\\cup_{n \\in \\mathbb{N}} (0, \\frac{n}{n + 1})$, which has no finite subcover\n(since we could choose $x \\in (0, 1)$ larger than the largest endpoint in the finite subcover).\n\n\\subsection{Exercise 15}\nFor closed, we can take $K_i = \\mathbb{N} / {0, ..., i - 1}$, since any $x \\in K_i$ will not\nbe in $K_j$ if $j > x$. For bounded, we can take $K_i = (0, \\frac{1}{i})$.\n\n\\subsection{Exercise 16}\n$E$ is by definition bounded, and $E$ is closed since $q^2 \\neq 3$ ($q$ is rational), and\n$q^2 > 3 \\implies \\exists \\epsilon \\: | \\: p  \\in N_{\\epsilon}(q) \\implies p^2 > 3$. Same\nlogic gives that $E$ is also open in $\\mathbb{Q}$. $E$ is, however, not compact, since\nwe can construct an open cover consisting of $G_n = \\{x \\: | \\: 2 < x^2 < 2 + \\frac{n}{n+1}\\}$.\n\n\\subsection{Exercise 17}\n$E$ is not countable by diagonalization. $E$ is not dense in $[0, 1]$, since $E \\cap [0, 0.1] = \\emptyset$.\n$E$ is not perfect, consider $N_{0.001}(0.77)$. $E$ is closed and therefore compact by Heine-Borel.\nTo see closed, suppose a limit point $q$ had a non-4/7 digit in the $i^{th}$ decimal spot. Then we could\ntake a neighborhood of size $10^{-(i + 1)}$.\n\n\\subsection{Exercise 18}\nOriginally I thought this was no, but this can actually be done with a modified version of the Cantor set \nconstruction. See \\href{https://math.stackexchange.com/questions/1064/perfect-set-without-rationals}{here} for\na discussion.\n", "meta": {"hexsha": "b08ccd19d913d0f6dd0ecd99229b73d1ee5dba8c", "size": 4400, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Principles_of_Mathematical_Analysis_Rudin/chapter_2.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "Principles_of_Mathematical_Analysis_Rudin/chapter_2.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Principles_of_Mathematical_Analysis_Rudin/chapter_2.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.7647058824, "max_line_length": 195, "alphanum_fraction": 0.7006818182, "num_tokens": 1402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7453592025145388}}
{"text": "\n\\subsection{Moving Average models (MA)}\n\nWe add previous error terms as input variables\n\nMA(\\(q\\)) has \\(q\\) previous error terms in the model\n\nUnlike AR models, the effects of any shocks wear off after \\(q\\) terms.\n\nThis is harder to fit the OLS, the error terms themselves are not observed.\n\n\n", "meta": {"hexsha": "a45d7e8700a9b10125ae4bb1fa69fdce164e6bb0", "size": 296, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/stochasticWold/02-01-MA.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/stochasticWold/02-01-MA.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/forecastingUni/03-01-MA.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.7692307692, "max_line_length": 75, "alphanum_fraction": 0.7364864865, "num_tokens": 70, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8104789178257653, "lm_q1q2_score": 0.7453508834555252}}
{"text": "\\documentclass[11pt]{amsart}\n\\usepackage{amsmath,amsfonts,amsthm,amssymb, amsaddr}\n\n\n\\title{Fourier Series}\n\n\\author{Joe Bentley}\n\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\newpage\n\n\\section{Periodicity}\n\nA function $f(x)$ is said to be periodic with period $L$ if it has the same value at $x$ and $x + L$,\n\n\\begin{align*}\n  f(x + L) = f(x)\n\\end{align*}\n\nIf a function has a period $L$ then it clearly also has period $nL$ for any positive integer $n$, as shown by,\n\n\\begin{align*}\n  f(x + 2L) = f\\left((x+L)+L\\right) = f(x+L) = f(x)\n\\end{align*}\n\nThe minimum period of a periodic function, which cannot be divided into any more sections, is called the fundamental period of the function. For example the fundamental period of $f(x) = \\sin{x}$ is $2\\pi$.\n\nIf we know the value of a periodic function $f(x)$ over an interval of the length of its fundamental period $L$, we know the value of the function everywhere, as it is just that interval repeated.\n\n\\section{Fourier Series}\n\nSine and cosine are periodic functions with a fundamental period of $2\\pi$. These functions are useful as we know much about them, for example we can integrate and differentiate them, and we can evaluate them for any value of $x$. Therefore it would be useful to be able to use them to represent a periodic function, much as we do with the maclaurin series except that instead of using a polynomial, we are using sines and cosines.\n\n$\\sin nx$ and $\\cos nx$ are also periodic over $2\\pi$, as we have shown earlier, as long as $n$ is a positive integer. It follows that $\\sin{\\frac{2\\pi nx}{L}}$ and $\\cos{\\frac{2\\pi nx}{L}}$ are periodic over length $L$. We can see this because if $x = L$, then it cancels to give $\\sin{2\\pi n}$, which we know represents a full cycle as the period of $\\sin{nx}$ is $2\\pi$. Think of this like the wavenumber, $k = \\frac{2\\pi}{\\lambda}$.\n\nAs we have mentioned, the idea of the Fourier series is to be able to write function $f(x)$ of period $L$ in terms of sines and cosines of the same period $L$ but different amplitudes.\n\n\\begin{align*}\n  f(x) = \\frac{1}{2}a_0 + \\sum\\limits_{n=1}^{\\infty}\\left[a_n\\cos{\\frac{2\\pi nx}{L}} + b_n\\sin{\\frac{2\\pi nx}{L}}\\right]\n\\end{align*}\n\nWe will show that we can find these coefficients for a function $f(x)$ by evaluating the overlap integral over a full period $L$,\n\n\\begin{align*}\n  a_0 &= \\frac{2}{L}\\int_0^L f(x) dx \\\\\n  a_n &= \\frac{2}{L}\\int_0^L f(x) \\cos{\\frac{2\\pi nx}{L}} dx \\\\\n  b_n &= \\frac{2}{L}\\int_0^L f(x) \\sin{\\frac{2\\pi nx}{L}} dx \\\\\n\\end{align*}\n\nNote that the limits do not have to be from $0$ to $L$, but just need to be over any length of the fundamental period, so for example can be from $-L/2$ to $L/2$.\n\n\n\\section{Orthogonality Relations}\n\nIn this section we will prove that the functions $\\sin{\\frac{2\\pi nx}{L}}$ (where $n = 1, 2, 3\\dots$) and $\\cos{\\frac{2\\pi nx}{L}}$ (where $n = 0, 1, 2\\dots$) can be considered mutually orthogonal, such that if $\\phi(x)$ and $\\psi(x)$ are two different functions from the set then,\n\n\\begin{align*}\n  \\int_0^L\\phi(x)\\psi(x) dx = 0\n\\end{align*}\n\nTo show this we will consider the three cases where, $\\phi = \\cos$ and $\\psi = \\cos$, $\\phi = \\sin$ and $\\psi = \\sin$, and $\\phi = \\sin$ and $\\psi = \\cos$.\n\nFirst consider the integral,\n\n\\begin{align*}\n  I_{mn} = \\int_0^L \\cos{\\frac{2\\pi mx}{L}} \\cos{\\frac{2\\pi nx}{L}} dx\n\\end{align*}\n\nFor this we will use a trigonometric product identity (which can be obtained from the addition formula),\n\n\\begin{align*}\n  \\cos{A}\\cos{B} = \\frac{1}{2}\\left[\\cos(A+B)+\\cos(A-B)\\right]\n\\end{align*}\n\nPlugging this into our integral,\n\n\\begin{align*}\n  I_{mn} &= \\frac{1}{2}\\int_0^L\\left[\\cos{\\frac{2\\pi(m+n)x}{L}}+\\cos{\\frac{2\\pi(m-n)x}{L}}\\right] dx \\\\\n         &= \\frac{L}{4\\pi}\\left[\\frac{1}{m+n}\\sin{\\frac{2\\pi(m+n)x}{L}}+\\frac{1}{m-n}\\sin{\\frac{2\\pi(m-n)x}{L}}\\right]_0^L\n\\end{align*}\n\nThis has different values for different $m$ and $n$. For $m \\neq n$, $I_{mn} = 0$, since both of the sine functions are periodic over the limits of $L$. For $m = n \\neq 0$, $I_{mn} = \\frac{1}{2} L$, and finally for $m = n = 0$, $I_{mn} = L$.\n\nNext we need to evaulate the integral,\n\n\\begin{align*}\n  J_{mn} = \\int_0^L \\sin{\\frac{2\\pi mx}{L}} \\sin{\\frac{2\\pi nx}{L}} dx\n\\end{align*}\n\nThis time we need the product identity for sine,\n\n\\begin{align*}\n  \\sin{A}\\sin{B} = \\frac{1}{2}\\left[\\cos(A-B)-\\cos(A+B)\\right]\n\\end{align*}\n\nThe result is simply the negative of what we had before,\n\n\\begin{align*}\n  J_{mn} = \\frac{1}{2}\\int_0^L\\left[\\cos{\\frac{2\\pi(m-n)x}{L}}-\\cos{\\frac{2\\pi(m+n)x}{L}}\\right] dx\n\\end{align*}\n\nThis time the results are the same unless $m = n = 0$. We have for $m \\neq n$, that $J_{mn} = 0$. For $m = n$ we have $J_{mn} = \\frac{1}{2} L$ (even if $m = n = 0$).\n\nFinally we need to consider the integral for sine and cosine. This time we need the product identity $\\sin{A}\\cos{B} = \\frac{1}{2}\\left[\\sin(A+B)+\\sin(A-B)\\right]$,\n\n\\begin{align*}\n  K_{mn} &= \\int_0^L\\sin{\\frac{2\\pi mx}{L}}\\cos{\\frac{2\\pi nx}{L}} dx \\\\\n         &= \\frac{1}{2}\\int_0^L\\left[\\sin{\\frac{2\\pi(m+n)x}{L}}+\\sin{\\frac{2\\pi(m-n)x}{L}}\\right] dx \\\\\n         &= \\frac{L}{4\\pi}\\left[-\\frac{1}{m+n}\\cos{\\frac{2\\pi(m+n)x}{L}}-\\frac{1}{m-n}\\cos{\\frac{2\\pi(m-n)x}{L}}\\right]_0^L \\\\\n         &= 0\n\\end{align*}\n\nAgain, by periodicity, $K_{mn} = 0$, for all $m$ and $n$.\n\nWe have shown therefore that the sine and cosine functions are orthogonal. This is similar to the scalar product, for example let's say we have a vector $\\mathbf{A} = A_x\\hat{\\imath}+A_y\\hat{\\jmath}+A_z\\hat{k}$, if we want the $x$ component of the vector we can use the scalar product $\\hat{\\imath}\\cdot\\mathbf{A} = A_x$. We can use this similarly to find the coefficients in the fourier series, but instead using an integral.\n\nIf we take the formula for the Fourier series and multiply both sides by $\\cos{\\frac{2\\pi nx}{L}}$ and then integrate,\n\n\\begin{align*}\n  \\int_0^L f(x)\\cos{\\frac{2\\pi nx}{L}} dx &= \\frac{1}{2} a_0 \\int_0^L\\cos{\\frac{2\\pi nx}{L}} dx \\\\\n                                          &+ \\sum\\limits_{m=1}^{\\infty}\\left[a_m\\int_0^L\\cos{\\frac{2\\pi mx}{L}}\\cos{\\frac{2\\pi nx}{L}} dx + b_m\\int_0^L\\sin{\\frac{2\\pi mx}{L}}\\cos{\\frac{2\\pi nx}{L}} dx\\right]\n\\end{align*}\n\nWe know that the first term goes to zero due to periodicity. We also know that the last term inside the sum will be zero for all $m$ and $n$. Finally we know that the first term in the sum will be zero if $m \\neq n$, but if $m = n \\neq 0$ it will be $\\frac{1}{2}L$, so we can represent this using the Kronecker delta $\\delta_mn$. Now the integral goes to,\n\n\\begin{align*}\n  \\int_0^L f(x)\\cos{\\frac{2\\pi nx}{L}} dx &= \\sum_{m=1}^{\\infty} a_m\\frac{1}{2}\\delta{mn} \\\\\n                                          &= \\frac{1}{2}L a_n\n\\end{align*}\n\nTherefore we have shown that the coefficient $a_n$ can be written in the form,\n\n\\begin{align*}\n  a_n = \\frac{2}{L}\\int_0^L f(x)\\cos{\\frac{2\\pi nx}{L}} dx\n\\end{align*}\n\nfor $n = 1, 2, 3\\dots$.\n\nIf we instead multiply by $\\sin{\\frac{2\\pi nx}{L}}$ and integrate, we get the same result,\n\n\\begin{align*}\n  b_n = \\frac{2}{L}\\int_0^L f(x)\\sin{\\frac{2\\pi nx}{L}} dx\n\\end{align*}\n\nfor $n = 0, 1, 2\\dots$.\n\nTo find the coefficient $a_0$, we take the formula for the Fourier series and integrate it alone,\n\n\\begin{align*}\n  \\int_0^L f(x)dx = \\frac{1}{2} a_0 \\int_0^L dx = \\frac{1}{2} L a_0\n\\end{align*}\n\nTherefore,\n\n\\begin{align*}\n  a_0 = \\frac{2}{L}\\int_0^L f(x) dx\n\\end{align*}\n\n\n\\section{Finding the Fourier Series}\n\nIn the following sections we will apply what we know to a few functions and evaluate their Fourier series.\n\nFirst let's consider what happens if our function $f(x)$, which we wish to evaluate the Fourier series for, is even such that $f(x) = f(-x)$. In this case,\n\n\\begin{align*}\n  b_n = \\frac{2}{L}\\int_{-\\frac{L}{2}}^{\\frac{L}{2}}f(x)\\sin{\\frac{2\\pi nx}{L}}dx = 0\n\\end{align*}\n\nso only $a_n$ terms remain.\n\nSimilarly, if $f(x)$ is odd such that $f(x) = -f(-x)$,\n\n\\begin{align*}\n  a_n = \\frac{2}{L}\\int_{-\\frac{L}{2}}^{\\frac{L}{2}}f(x)\\cos{\\frac{2\\pi nx}{L}}dx = 0\n\\end{align*}\n\nso only $b_n$ terms remain.\n\n\\section{Finding the Fourier Series: Example 1}\n\nConsider the periodic function which is defined over the interval $x\\in\\left(-\\frac{L}{2}, \\frac{L}{2}\\right)$ as $f(x) = |x|$. This can be written equivalently as,\n\n\\begin{align*}\n  f(x)=\n  \\begin{cases}\n    -x -\\frac{L}{2} \\leq & x \\leq 0 \\\\\n    x 0 \\leq & x \\leq \\frac{L}{2} \\\\\n  \\end{cases}\n\\end{align*}\n\nThis function is clearly even, as $f(x) = f(-x)$, so we only get cosine ($a_n$) coefficients,\n\n\\begin{align*}\n  a_n = \\frac{2}{L}\\int_{-\\frac{L}{2}}^{\\frac{L}{2}} |x| \\cos{\\frac{2\\pi nx}{L}} dx\n\\end{align*}\n\nSince the function is even, this means that it is symmetric over the limits, so we can just integrate over half the limits (for example from $0$ to $L/2$ instead of $-L/2$ to $L/2$) and then multiply by two,\n\n\\begin{align*}\n  a_n = \\frac{4}{L}\\int_0^{\\frac{L}{2}} x\\cos{\\frac{2\\pi nx}{L}} dx\n\\end{align*}\n\nTo simplify solving this we make the solution $y = \\frac{2\\pi nx}{L}$ and thus $x = \\frac{L}{2\\pi n} y$ and $dx = \\frac{L}{2\\pi n}dy$. The integral therefore becomes,\n\n\\begin{align*}\n  a_n &= \\frac{4}{L}{\\left(\\frac{L}{2\\pi n}\\right)}^2\\int_0^{\\pi n} y\\cos{y} dy \\\\\n      &= \\frac{L}{\\pi^2n^2}{\\left[y\\sin{y}+\\cos{y}\\right]}_0^{\\pi n} \\\\\n      &= \\frac{L}{\\pi^2n^2}\\left[\\cos{\\pi n} - 1\\right] \\\\\n      &= \\frac{L}{\\pi^2n^2}\\left[{(-1)}^n - 1\\right]\n\\end{align*}\n\nIn the third line we noted that $\\cos{\\pi n}$ will be negative for odd integers of $n$, and positive for even integers of $n$. If it is positive then it cancels out with the other $1$ to give zero in brackets. If it is negative it will add up to give two inside the brackets. This behaviour is summarized here,\n\n\\begin{align*}\n  a_n=\n  \\begin{cases}\n    -\\frac{2L}{\\pi^2n^2} & \\text{n is odd} \\\\\n    0 & \\text{n is even}\n  \\end{cases}\n\\end{align*}\n\nFinally we need to calculate our zeroth coefficient, $a_0$,\n\n\\begin{align*}\n  a_0 = \\frac{4}{L}\\int_0^{\\frac{L}{2}} x dx = \\frac{4}{L}{\\left[\\frac{1}{2}x^2\\right]}_0^{\\frac{L}{2}} = \\frac{L}{2}\n\\end{align*}\n\nWe now have all the information we need to subsitute into the Fourier series,\n\n\\begin{align*}\n  f(x) &= \\frac{L}{4}-\\frac{2L}{\\pi^2}\\sum\\limits_{\\text{n odd}}\\frac{1}{n^2}\\cos{\\frac{2\\pi nx}{L}} \\\\\n       &= \\frac{L}{4}-\\frac{2L}{\\pi^2}\\sum\\limits_{k=0}^{\\infty}\\frac{1}{{(2k+1)}^2}\\cos{\\frac{2\\pi(2k+1)x}{L}}\n\\end{align*}\n\nBy letting $x = 0$ we can find the value of the sum of $\\frac{1}{{(2k+1)}^2}$,\n\n\\begin{align*}\n  \\sum\\limits_{k=0}^{\\infty} \\frac{1}{{(2k+1)}^2} = \\frac{\\pi^2}{8}\n\\end{align*}\n\n\\section{The Riemann Zeta Function}\n\nIn this section we will explore the Riemann Zeta function, but this is not examinable material. The Riemann Zeta function is defined as,\n\n\\begin{align*}\n  \\zeta(z) = \\sum\\limits_{n=1}^{\\infty} \\frac{1}{n^z} \\qquad \\Re{z} > 1\n\\end{align*}\n\nFor other values of $z$ the value of $\\zeta{z}$ can be found by using analytic continuoations. From the definition we see that,\n\n\\begin{alignat*}{8}\n  \\zeta(2) &= 1 + &&\\frac{1}{2^2} &&+ \\frac{1}{3^2} &&+ \\frac{1}{4^2} &&+ \\frac{1}{5^2} &&+ \\frac{1}{6^2} &&+ \\frac{1}{7^2} &&+ \\dots \\\\\n  \\frac{1}{4}\\zeta(2) &= &&\\frac{1}{2^2} && &&+ \\frac{1}{4^2} && &&+ \\frac{1}{5^2} && &&+ \\dots \\\\\n  \\zeta(2) - \\frac{1}{4}\\zeta(2) = \\frac{3}{4}\\zeta(2) &= 1 && &&+ \\frac{1}{3^2} && &&+ \\frac{1}{5^2} && &&+ \\frac{1}{7^2} &&+ \\dots \\\\\n\\end{alignat*}\n\nWe can see that the last sequence is just equal to the sum that we found at the end of the last section, as it is just hte sum of all odd $n$ squared. Therefore $\\frac{3}{4}\\zeta(2) = \\frac{\\pi^2}{8}$, and it follows that,\n\n\\begin{align*}\n  \\zeta(2) = 1 + \\frac{1}{4} + \\frac{1}{9} + \\frac{1}{16} + \\frac{1}{25} + \\dots = \\frac{\\pi^2}{6}\n\\end{align*}\n\n$\\zeta(2n)$ where $n$ is a positive integer, is always a rational multiple of $\\pi^{2n}$. The general formula is given by,\n\n\\begin{align*}\n  \\zeta(2n) = \\frac{2^{2n-1} |B_{2n}|}{2n!} \\pi^{2n}\n\\end{align*}\n\nwhere $B_k$ are the Bernoulli numbers defined as,\n\n\\begin{align*}\n  \\frac{z}{e_z - 1} = \\sum\\limits_{k=0}^{\\infty}\\frac{B_k}{k!} z^k\n\\end{align*}\n\nThe only non-zero values of $B_k$ for odd $k$ is $B_1$, all others are odd. The first few Bernoulli numbers are,\n\n\\begin{align*}\n  B_0 = 1 \\qquad B_1 = -\\frac{1}{2} \\qquad B_2 = \\frac{1}{6} \\qquad B_4 = -\\frac{1}{30} \\qquad B_6 = \\frac{1}{42}\n\\end{align*}\n\n\n\\section{Parseval's Theorem}\n\nIn this section we return to examinable stuff. Consider the Fourier series of a periodic function $f(x)$ given by,\n\n\\begin{align*}\n  f(x) = \\frac{1}{2}a_0 + \\sum\\limits_{n=1}^{\\infty}\\left[a_n\\cos{\\frac{2\\pi nx}{L}} + b_n\\sin{\\frac{2\\pi nx}{L}}\\right]\n\\end{align*}\n\nIf we square $f(x)$ we get a complicated double series. It we then take the integral over a full period length $L$ then orthogonality means that we only get the diagonal (squared) terms, as we have shown that the integral over a full period of a product of two different cosines, two different sines, or a sine and a cosine is zero,\n\n\\begin{align*}\n  \\int_0^L f^2(x) dx = \\frac{1}{4}a_0^2\\int_0^Ldx + \\sum\\limits_{n=1}^{\\infty}\\left[\\int_0^L a_n^2\\cos^2{\\frac{2\\pi nx}{L}} dx + \\int_0^L b_n^2 \\sin^2{\\frac{2\\pi nx}{L}} dx\\right]\n\\end{align*}\n\nOr since $\\sin^2{x} + \\cos^2{x} = 1$ this can be written as,\n\n\\begin{align*}\n  \\int_0^L f^2(x) dx = \\frac{1}{2}L\\left[\\frac{1}{2}a_0^2 + \\sum\\limits_{n=1}^{\\infty}\\left(a_n^2+b_n^2\\right)\\right]\n\\end{align*}\n\nNote that the limits on the integral can be over any full period length, and don't have to be between $0$ and $L$.\n\n\n\\section{Finding the Fourier Series: Example 3}\n\nThe periodic function $h(x)$ is defined over the interval $x \\in (-\\frac{L}{2},\\frac{L}{2})$ as,\n\n\\begin{align*}\n  h(x) = \\frac{1}{2}x^2 sgn{x} - \\frac{1}{4}Lx\n\\end{align*}\n\nThe function is clearly odd, therefore we only need to calculate the $b_n$ coefficients, as the $a_n$ coefficients will all be zero. Using our formula from before to find $b_n$, as well as using the substitution $y = \\frac{2\\pi nx}{L}$ again from example one,\n\n\\begin{align*}\n  b_n &= \\frac{2}{L}\\int_{-\\frac{L}{2}}^{\\frac{L}{2}}h(x)\\sin{\\frac{2\\pi nx}{L}} dx \\\\\n      &= \\frac{4}{L}\\int_0^{\\frac{L}{2}}h(x)\\sin{\\frac{2\\pi nx}{L}} dx \\\\\n      &= \\frac{4}{L}\\int_0^{\\frac{L}{2}}\\left[\\frac{1}{2}x^2-\\frac{1}{4}Lx\\right]\\sin{\\frac{2\\pi nx}{L}} dx \\\\\n      &= \\frac{4}{L}\\int_0^{\\pi n}\\left[\\frac{1}{2}{\\left(\\frac{L}{2\\pi n}\\right)}^3y^2\\sin{y}-\\frac{1}{4}L{\\left(\\frac{L}{2\\pi n}\\right)}^2y\\sin{y}\\right] dy \\\\\n      &= \\frac{L^2}{4\\pi^3n^3}\\int_0^{\\pi n}y^2\\sin{y}dy-\\frac{L^2}{4\\pi^2n^2}\\int_0^{\\pi n}y\\sin{y}dy \\\\\n      &= \\frac{L^2}{4\\pi^3n^3}{\\left[-y^2\\cos{y}+2y\\sin{y}+2\\cos{y}\\right]}_0^{\\pi n} - \\frac{L^2}{4\\pi^2n^2}{\\left[-y\\cos{y}+\\sin{y}\\right]}_0^{\\pi n} \\\\\n      &= \\frac{L^2}{4\\pi^3n^3}\\left[-{(\\pi n)}^2\\cos{\\pi n}+2\\cos{\\pi n}-2\\right]-\\frac{L^2}{4\\pi^2n^2}\\left[-\\pi n\\cos{\\pi n}\\right] \\\\\n      &= \\frac{L^2}{2\\pi^3n^3}\\left[\\cos{\\pi n}-1\\right] \\\\\n      &= \\frac{L^2}{2\\pi^3n^3}\\left[{(-1)}^2-1\\right]\n\\end{align*}\n\nWe therefore have that the coefficients of the sine term are given by,\n\n\\begin{align*}\n  a_n=\n  \\begin{cases}\n    -\\frac{L^2}{\\pi^3n^3} & \\text{n odd} \\\\\n    0 & \\text{n even}\n  \\end{cases}\n\\end{align*}\n\nThe Fourier series can then be written as,\n\n\\begin{align*}\n  h(x) &= -\\frac{L^2}{\\pi^3} \\sum\\limits_{\\text{n odd}}\\frac{1}{n^3}\\sin{\\frac{2\\pi nx}{L}} \\\\\n       &= -\\frac{L^2}{\\pi^3} \\sum\\limits_{k=0}^{\\infty}\\frac{1}{{(2k+1)}^3}\\sin{\\frac{2\\pi(2k+1)x}{L}}\n\\end{align*}\n\nParseval's theorem for this function is given by,\n\n\\begin{align*}\n  \\int_{-\\frac{L}{2}}^{\\frac{L}{2}}h^2(x)dx&=\\frac{1}{2}L\\sum\\limits_{n=1}^{\\infty}b_n^2 \\\\\n                                           &=\\frac{1}{2}L\\left(\\frac{L^4}{\\pi^6}\\right)\\sum\\limits_{\\text{n odd}}\\frac{1}{n^6} \\\\\n                                           &=\\frac{L^5}{2\\pi^6}\\sum\\limits_{k=0}^{\\infty}\\frac{1}{{(2k+1)}^6}\n\\end{align*}\n\nBy evaluating the left side of the equation we get,\n\n\\begin{align*}\n  \\int_{-\\frac{L}{2}}^{\\frac{L}{2}}h^2(x)dx&=2\\int_0^{\\frac{L}{2}}{\\left[\\frac{1}{2}x^2-\\frac{1}{4}Lx\\right]}^2 dx \\\\\n                                           &=2\\int_0^{\\frac{L}{2}}\\left[\\frac{1}{4}x^6-\\frac{1}{4}Lx^3+\\frac{1}{16}L^2x^2\\right]dx \\\\\n                                           &=2{\\left[\\frac{1}{20}x^5-\\frac{1}{16}Lx^4+\\frac{1}{48}L^2x^3\\right]}_0^{\\frac{L}{2}} \\\\\n                                           &=2\\left[\\frac{1}{20}\\frac{L^5}{32}-\\frac{1}{16}\\frac{L^3}{16}+\\frac{1}{48}\\frac{L^5}{8}\\right] \\\\\n                                           &=\\frac{L^5}{1920}\n\\end{align*}\n\nTherefore we have,\n\n\\begin{align*}\n  \\frac{L^5}{1920}=\\frac{L^5}{2\\pi^6}\\sum\\limits_{k=0}^{\\infty}\\frac{1}{{(2k+1)}^6}\n\\end{align*}\n\nWhich we can rearrange to find an expression for the sum alone,\n\n\\begin{align*}\n  \\sum\\limits_{k=0}^{\\infty}\\frac{1}{{(2k+1)}^6}=\\frac{\\pi^6}{960}\n\\end{align*}\n\n\n\\section{Finding the Fourier series: Example 4}\n\nConsider the periodic function defined on the interval $x\\in(0, 2\\pi)$ as $f(x) = e^{ax}$. This function is neither even nor odd so we have to calculate both $a_n$ and $b_n$ coefficients. Our $a_n$ (cosine) coefficients are given by,\n\n\\begin{align*}\n  a_n &= \\frac{2}{2\\pi}\\int_0^{2\\pi}e^{ax}\\cos{nx}dx \\\\\n      &= \\frac{1}{\\pi} \\Re \\int_0^{2\\pi}e^{ax}\\cos{nx}dx \\\\\n      &= \\frac{1}{\\pi} \\Re \\int_0^{2\\pi}e^{(a+in)x} dx \\\\\n      &= \\frac{1}{\\pi} \\Re {\\left[\\frac{e^{(a+in)x}}{a+in}\\right]}_0^{2\\pi} \\\\\n      &= \\frac{1}{\\pi} \\Re \\left[\\frac{e^{2\\pi(a+in)} - 1}{a+in}\\right] \\\\\n      &= \\frac{1}{\\pi} \\Re \\left[\\frac{e^{2\\pi a}e^{2\\pi in} - 1}{a+in}\\right] \\\\\n      &= \\frac{e^{2\\pi a} - 1}{\\pi} \\Re \\left[\\frac{1}{a+in}\\right] \\\\\n      &= \\frac{e^{2\\pi a} - 1}{\\pi} \\Re \\left[\\frac{a-in}{a^2+n^2}\\right]\n\\end{align*}\n\nThe cosine coefficients are therefore given by,\n\n\\begin{align*}\n  a_n = \\frac{1}{\\pi}\\left[e^{2\\pi a} - 1\\right]\\frac{a}{n^2+a^2}\n\\end{align*}\n\nTo find the sine ($b_n$) coefficients we just need to take the imaginary part of the integral instead,\n\n\\begin{align*}\n  b_n = \\frac{1}{\\pi}\\int_0^{2\\pi}e^{ax}\\sin{nx}dx &= \\frac{1}{\\pi}\\Im\\int_0^{2\\pi}e^{(a+in)x}dx \\\\\n                                                   &= \\frac{1}{\\pi}\\left[e^{2\\pi a}-1\\right] \\Im\\left[\\frac{a-in}{a^2+n^2}\\right] \\\\\n                                                   &= -\\frac{1}{\\pi}\\left[e^{2\\pi a}-1\\right]\\frac{n}{n^2+a^2}\n\\end{align*}\n\nFinally we need to find the coefficient when $n = 0$ which can be found simply by setting $n = 0$ in our expression for $a_n$,\n\n\\begin{align*}\n  a_0 = \\frac{1}{\\pi a}\\left[e^{2\\pi a}-1\\right]\n\\end{align*}\n\nThe Fourier series for this function is therefore,\n\n\\begin{align*}\n  f(x)=\\frac{1}{\\pi}\\left[e^{2\\pi a}-1\\right]\\left\\{\\frac{1}{2a}+\\sum\\limits_{n=1}^{\\infty}\\frac{a\\cos{nx}-n\\sin{nx}}{n^2+a^2}\\right\\}\n\\end{align*}\n\nThe function is discontinuous at $x = 0$, as it has a sharp change. By setting $x = 0$ the Fourier series converges to the average value of the function,\n\n\\begin{align*}\n  \\frac{1}{2}\\left[f(0+)+f(0-)\\right] = \\frac{1}{2}\\left[1+e^{2\\pi a}\\right]\n\\end{align*}\n\nTherefore by plugging $x = 0$ into our Fourier series we get,\n\n\\begin{align*}\n  \\frac{1}{2}\\left[e^{2\\pi a}+1\\right]=\\frac{1}{\\pi}\\left[e^{2\\pi a}+1\\right]\\left\\{\\frac{1}{2a}+\\sum\\limits_{n=1}^{\\infty}\\frac{a}{n^2+a^2}\\right\\}\n\\end{align*}\n\nBy rearranging we can find that,\n\n\\begin{align*}\n  \\frac{\\pi\\left[e^{2\\pi a}+1\\right]}{\\left[e^{2\\pi a}-1\\right]}=\\frac{1}{a}+\\sum\\limits_{n=1}^{\\infty}\\frac{2a}{n^2+a^2}\n\\end{align*}\n\nMultiplying the top and bottom of the left hand side by $e^{-\\pi a}$,\n\n\\begin{align*}\n  \\frac{\\pi\\left[e^{\\pi a}+e^{-\\pi a}\\right]}{\\left[e^{\\pi a}-e^{-\\pi a}\\right]} &= \\frac{1}{a}+\\sum\\limits_{n=1}^{\\infty}\\frac{2a}{n^2+a^2} \\\\\n  \\pi\\coth{\\pi a} &= \\frac{1}{a}+\\sum\\limits_{n=1}^{\\infty}\\frac{2a}{n^2+a^2} \\\\\n  \\pi a\\coth{\\pi a} &= 1 + \\sum\\limits_{n=1}^{\\infty}\\frac{2a^2}{n^2+a^2}\n\\end{align*}\n\nUsing this we can find an expression for the Riemann Zeta $\\zeta(2k)$. First we let $a$ be small, so that we can expand using the Maclaurin series,\n\n\\begin{align*}\n  \\frac{a^2}{n^2+a^2}=\\frac{a^2/n^2}{1 + a^2/n^2} = \\frac{a^2}{n^2}\\left[1 - \\frac{a^2}{n^2} + \\frac{a^4}{n^4} - \\frac{a^6}{n^6} \\dots\\right]\n\\end{align*}\n\nOur previous equation therefore becomes,\n\n\\begin{align*}\n  \\pi a\\coth{\\pi a} &= 1 + 2\\sum\\limits_{n=1}^{\\infty}\\left[\\frac{a^2}{n^2}-\\frac{a^4}{n^4}+\\frac{a^6}{n^6} \\dots\\right] \\\\\n                    &= 1 + 2\\left[a^2\\zeta(2)-a^4\\zeta(4)+a^6\\zeta(6)\\dots \\right] \\\\\n                    &= 1 + 2\\sum\\limits_{n=1}^{\\infty} {(-1)}^{k+1}a^{2k}\\zeta(2k)\n\\end{align*}\n\nNext look at the definition of the Bernoulli numbers, which gives us,\n\n\\begin{align*}\n  \\frac{x}{e^x - 1} &= \\sum_{n=0}^{\\infty} \\frac{B_n}{n!}x^n \\\\\n                    &= x \\frac{e^{-\\frac{x}{2}}}{e^{\\frac{x}{2}}-e^{-\\frac{x}{2}}} \\\\\n                    &= \\frac{1}{2}x\\left[\\frac{e^{\\frac{x}{2}}+e^{-\\frac{x}{2}}}{e^{\\frac{x}{2}}-e^{-\\frac{x}{2}}} - 1\\right] \\\\\n                    &= \\frac{1}{2}x\\left[\\coth{\\frac{x}{2}} - 1\\right]\n\\end{align*}\n\nTherefore we have,\n\n\\begin{align*}\n  \\frac{1}{2}x\\left[\\coth{\\frac{x}{2}} - 1\\right] = \\sum\\limits_{n=0}^{\\infty}\\frac{B_n}{n!}x^n\n\\end{align*}\n\nSetting $x = 2\\pi a$ gives us the left hand side the same as our equation earlier,\n\n\\begin{align*}\n  \\pi a\\coth{\\pi a} - \\pi a = \\sum\\limits_{n=0}^{\\infty}\\frac{B_n}{n!}{(2\\pi a)}^n\n\\end{align*}\n\nBy comparing the coefficients of this equation with the other equation equal to $\\pi a\\coth{\\pi a} - \\pi a$ we find that the only term of the Bernoulli number expression that survives is when $n = 2k$, such that,\n\n\\begin{align*}\n  2{(-1)}^{k+1}\\zeta(2k) = \\frac{B_{2k}}{(2k)!}{(2\\pi)}^{2k}\n\\end{align*}\n\nTherefore we can now find an expression for the zeta,\n\n\\begin{align*}\n  \\zeta(2k) = \\frac{|B_{2k}|2^{2k-1}\\pi^{2k}}{(2k)!}\n\\end{align*}\n\n\n\\section{Complex Fourier Series}\n\nSo far we have written the Fourier series using sines and cosines to represent our function. Because of the deep relation between sines and cosines this means that we can write the Fourier series in terms of complex exponentials,\n\n\\begin{align*}\n  f(x) = \\sum\\limits_{n=-\\infty}^{\\infty} C_n e^{\\frac{2\\pi inx}{L}}\n\\end{align*}\n\nThe complex exponential functions $\\phi_n(x) = e^{2\\pi inx}{L}$ are orthogonal such that,\n\n\\begin{align*}\n  \\int_{x_0}^{x_0+L} \\phi_m^*(x)\\phi_n(x) dx &= \\int_{x_0}^{x_0+L}e^{-\\frac{2\\pi imx}{L}}e^{\\frac{2\\pi inx}{L}}dx \\\\\n                                             &= \\int_{x_0}^{x_0+L}e^{\\frac{2\\pi i(n - m)x}{L}} dx\\\\\n                                             &=\n  \\begin{cases}\n    0 & n \\neq m \\\\\n    L & n = m\n  \\end{cases}\n\\end{align*}\n\nThe integral is zero over the whole period because of the periodicity of the function $e^{\\frac{2\\pi ix}{L}}$. Therefore we have shown that the functions are orthogonal, which can be expressed by,\n\n\\begin{align*}\n  \\int_{x_0}^{x_0+L}\\phi_m^*(x)\\phi_n(x) dx = L\\delta_{mn}\n\\end{align*}\n\nThe coefficients $C_n$ can be extracted using these relations by performing an overlap integral of the form,\n\n\\begin{align*}\n  \\int_{x_0}^{x_0+L}f(x)\\phi^*(x)dx &= \\sum\\limits_{m=-\\infty}^{\\infty}C_m\\int_{x_0}^{x_0+L}\\phi_n^*(x)\\phi_m(x) dx \\\\\n                                    &= \\sum\\limits_{m=-\\infty}^{\\infty}C_m L \\delta_{mn} = LC_n\n\\end{align*}\n\nThe coefficients are therefore given by,\n\n\\begin{align*}\n  C_n = \\frac{1}{L}\\int_{x_0}^{x_0+L}f(x)e^{-\\frac{2\\pi inx}{L}} dx\n\\end{align*}\n\nParseval's theorem for this series can be found in the same way as usual, but we multiply the function by it's complex conjugate instead of just squaring it,\n\n\\begin{align*}\n  f(x)f^*(x) = \\sum\\limits_{m=-\\infty}^{\\infty}\\sum\\limits_{n=-\\infty}^{\\infty}C_m^*C_n\\phi_m^*(x)\\phi_n(x)\n\\end{align*}\n\nParseval's theorem is found by integrating over this over a whole period,\n\n\\begin{align*}\n  \\int_{x_0}^{x_0+L}{|f(x)|}^2 dx &= \\sum\\limits_{m=-\\infty}^{\\infty}\\sum\\limits_{n=-\\infty}^{\\infty}C_m^* C_n \\int_{x_0}^{x_0+L}\\phi_m^*\\phi_ndx \\\\\n                                  &= \\sum\\limits_{m=-\\infty}^{\\infty}\\sum\\limits_{n=-\\infty}^{\\infty}C_m^* C_N L \\delta_{mn} \\\\\n                                  &= L\\sum\\limits_{n=-\\infty}^{\\infty}{|C_n|}^2\n\\end{align*}\n\nWe can manipulate the complex Taylor series to find the real Taylor series quite easily. First we note that the complex conjugate of the coefficients $C_n$ are given by,\n\n\\begin{align*}\n  C_n^* = \\frac{1}{L}\\int_{x_0}^{\\infty}f(x)e^{\\frac{2\\pi inx}{L}} dx\n\\end{align*}\n\nTherefore, if $f(x)$ is real the coefficients are related by $C_n^* = C_{-n}$. It is possible to write the complex coefficients in terms of the real coefficients such that $C_n = \\frac{1}{2}(a_n - ib_n)$ as shown by,\n\n\\begin{align*}\n  C_n &= \\frac{1}{L}\\int_{x_0}^{x_0+L}f(x)e^{-\\frac{2\\pi inx}{L}} dx \\\\\n      &= \\frac{1}{L}\\int_{x_0}^{x_0+L}f(x)\\left[\\cos{\\frac{2\\pi nx}{L}}-i\\sin{\\frac{2\\pi nx}{L}}\\right] dx \\\\\n      &= \\frac{1}{2}(a_n - ib_n)\n\\end{align*}\n\nThe complex conjugate of the coefficients is thus $C^* = C_{-n} = \\frac{1}{2}(a_n + ib_n)$. Adding together the $C_n$ and $C_{-n}$ terms of the Taylor series gives us,\n\n\\begin{align*}\n  C_n e^{\\frac{2\\pi inx}{L}} + C_{-n}e^{-\\frac{2\\pi inx}{L}} &= C_n e^{\\frac{2\\pi inx}{L}} + C^*_{-n}e^{-\\frac{2\\pi inx}{L}} \\\\\n                                                             &= 2\\Re{C_n e^{\\frac{2\\pi inx}{L}}} \\\\\n                                                             &= \\Re{(a_n - ib_n)\\left(\\cos{\\frac{2\\pi nx}{L}} + i\\sin{\\frac{2\\pi nx}{L}}\\right)} \\\\\n                                                             &= a_n\\cos{\\frac{2\\pi nx}{L}} + b_n\\sin{\\frac{2\\pi nx}{L}}\n\\end{align*}\n\nWhich is just our real Taylor series.\n\n\\section{Fourier Transform}\n\nIn this section we will use the complex Fourier series to relate the time (or space) domain of a function to the frequency (or wavenumber) of the sine waves that make up the function in the Fourier series. First recall the form of the complex Fourier series,\n\n\\begin{align*}\n  f(x) = \\sum\\limits_{n=-\\infty}^{\\infty} C_n e^{\\frac{2\\pi inx}{L}}\n\\end{align*}\n\nThe coefficients $C_n$ are given by,\n\n\\begin{align*}\n  C_n = \\frac{1}{L}\\int_{-\\frac{L}{2}}^{\\frac{L}{2}} f(x) e^{-\\frac{2\\pi inx}{L}} dx\n\\end{align*}\n\nBy taking the factor of $L$ out of the expression for $C_n$ and instead writing it explicitly in $f(x)$ we can write these as,\n\n\\begin{align*}\n  f(x) &= \\sum\\limits_{n=-\\infty}^{\\infty} \\tilde{C_n}\\frac{1}{L}e^{\\frac{2\\pi inx}{L}} \\\\\n  \\tilde{C_n} &= \\int_{-\\frac{L}{2}}^{\\frac{L}{2}}f(x)e^{-\\frac{2\\pi inx}{L}} dx\n\\end{align*}\n\nIf we let the period $L$ go to infinity, then the wavenumber given by $k = \\frac{2\\pi n}{L}$ will become a real number, and the first sum will become an integral with $\\frac{2\\pi}{L}\\to dk$. Also renaming $\\tilde{C_n}$ as $\\tilde{f}(k)$ gives us,\n\n\\begin{align*}\n  f(x) = \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty}\\tilde{f}(k)e^{ikx} dk\n\\end{align*}\n\nwhere $\\tilde{f}(k)$ is the Fourier transform, given by,\n\n\\begin{align*}\n  \\tilde{f}(k) = \\int_{-\\infty}^{\\infty}f(x) e^{-ikx} dx\n\\end{align*}\n\nThe first equation $f(x)$ is called the inverse Fourier transform, as it takes the Fourier transform and gives us back the original function, the second equation $\\tilde{f}(k)$ is called the Fourier transform. Finding the function $\\tilde{f}(k)$ is called \\textit{taking the Fourier transform}. Finding $f(x)$ is called \\textit{taking the inverse Fourier transform}. The Fourier transform takes a function in terms of a space $x$ and gives us the amount of each sine wave with wavenumber $k = \\frac{2\\pi n}{L}$. That is, it transforms the function from the spatial domain to the wavenumber domain. Commonly, for example in a signal, the signal will be a function of time $f(t)$, but we want to know the frequencies that make it up in the Fourier series, so we use the Fourier transform to transform from the time domain $f(t)$ to the frequency domain $f(\\zeta)$.\n\nThe factor of $\\frac{1}{2\\pi}$ can be split up to make the definitions symmetrical,\n\n\\begin{align*}\n  \\tilde{f}(k) &= \\frac{1}{\\sqrt{2\\pi}}\\int_{-\\infty}^{\\infty}f(x)e^{-ikx} dx \\\\\n  f(x) &= \\frac{1}{\\sqrt{2\\pi}}\\int_{-\\infty}^{\\infty}\\tilde{f}(k)e^{ikx} dx\n\\end{align*}\n\nParseval's theorem for the Fourier transforms can be derived by starting at Parseval's theorem for the complex Fourier series,\n\n\\begin{align*}\n  \\int_{-\\frac{L}{2}}^{\\frac{L}{2}}{|f(x)|}^2 dx &= L\\sum\\limits_{n=-\\infty}^{\\infty}{|C_n|}^2 \\\\\n                                                 &= L\\sum\\limits_{n=-\\infty}^{\\infty}\\frac{1}{L^2}{|\\tilde{C_n}|}^2 \\\\\n                                                 &= \\frac{1}{2\\pi}\\sum\\limits_{n=-\\infty}^{\\infty}\\frac{2\\pi}{L}{|\\tilde{C_n}|}^2\n\\end{align*}\n\nBy letting $L$ go to infinity, $\\frac{2\\pi n}{x}$ go to $k$, and $\\tilde{c_n}$ go to $\\tilde{f(k)}$ we get the equivalent for the Fourier transform,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty}{|f(x)|}^2dx = \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty}{|\\tilde{f}(k)|}^2 dk\n\\end{align*}\n\n\\section{Example 1: Top Hat Function}\n\nConsider the top hat function of width $a$ defined as,\n\n\\begin{align*}\n  f(x) = T\\left(x; -\\frac{a}{2}, \\frac{a}{2}\\right) =\n  \\begin{cases}\n    1 & -\\frac{a}{2} < x < \\frac{a}{2} \\\\\n    0 & \\text{elsewhere}\n  \\end{cases}\n\\end{align*}\n\nThe Fourier transform is therefore just the integral over that region, as outside the region of width $a$ the value of the function is zero,\n\n\\begin{align*}\n  \\tilde{f}(k) &= \\int_{-\\infty}^{\\infty}f(x)e^{-ikx} dx \\\\\n               &= \\int_{-\\frac{a}{2}}^{\\frac{a}{2}}e^{-ikx} dx \\\\\n               &= {\\left[\\frac{e^{-ikx}}{-ik}\\right]}_{-\\frac{a}{2}}^{\\frac{a}{2}} \\\\\n               &= \\left[\\frac{e^{-ik\\frac{a}{2}}-e^{ik\\frac{a}{2}}}{-ik}\\right] \\\\\n               &= \\frac{2i\\sin{\\frac{ka}{2}}}{ik}\n\\end{align*}\n\nThe Fourier transform for the top hat function is therefore given by,\n\n\\begin{align*}\n  \\tilde{f}(k) = \\frac{2\\sin{\\frac{ka}{2}}}{k}\n\\end{align*}\n\nThis is our relationship that allows us to find the amplitude of the sine wave of a given wavenumber which makes up our function $f(x)$ in the Fourier series.\n\nAnother way to find the Fourier transform is to write the exponential in the form of sines and cosines, which is easier. First we note that $f(x)$ is even, so when multiplied by the sine term and integrated it goes to zero,\n\n\\begin{align*}\n  \\tilde{f}(k) &= \\int_{-\\infty}^{\\infty} f(x) \\left[\\cos{kx}-i\\sin{kx}\\right] dx \\\\\n               &= \\int_{-\\infty}^{\\infty} f(x) \\cos{kx} dx \\\\\n               &= 2 \\int_0^{\\infty} f(x) \\cos{kx} dx \\\\\n               &= \\frac{2\\sin{k\\frac{a}{2}}}{k}\n\\end{align*}\n\nNote that we arrived at the same result, but didn't have to mess with any imaginary numbers. Finally, we will come up with some notion of an uncertainty relationship as in quantum mechanics for the Fourier transform. First we come up with a vague notion of width. Suppose that our width is given by $\\Delta x = a$, that is, the width of one of the spatial function period. The corresponding width of the wavenumber is therefore given by $\\Delta k = \\frac{2\\pi}{a}$. By multiplying these together we find an uncertainty relationship much like Heisenberg's uncertainty principle, $\\Delta x \\Delta k = 2\\pi$.\n\nWe can also show how we can get back the original function $f(x)$ from the Fourier transform $\\tilde{f}(k)$ using the inverse Fourier transform! We simply substitute into our formula and then evaluate the integral,\n\n\\begin{align*}\n  f(x) &= \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty} \\tilde{f}(k) e^{ikx} dk \\\\\n       &= \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty} \\frac{2\\sin{k\\frac{a}{2}}}{k} e^{ikx} dk \\\\\n       &= \\frac{1}{\\pi}\\int_{-\\infty}^{\\infty} \\frac{\\sin{k\\frac{a}{2}}}{k} \\cos{kx} dk \\\\\n       &= \\frac{2}{\\pi}\\int_{0}^{\\infty} \\frac{\\sin{k\\frac{a}{2}}}{k} \\cos{kx} dk \\\\\n\\end{align*}\n\nIn the third line we expressed the complex exponential in trigonometric form. Since the integral is over even limits the sine from the Fourier transform (the big fraction) multiplied by the sine from the complex exponential will be zero when integrated over. Therefore we just have the cosine term of the complex exponential.\n\nNow we need to approach evaluating this integral. First we use one of our product rule identities for trigonometric functions, $\\sin{\\theta}\\cos{\\phi} = \\frac{1}{2}\\left[\\sin{(\\theta+\\phi)}+\\sin{(\\theta-\\phi)}\\right]$. The integral is therefore,\n\n\\begin{align*}\n  f(x) = \\frac{1}{\\pi}\\int_0^{\\infty}\\frac{1}{k}\\left\\{\\sin{\\left[k\\left(x+\\frac{a}{2}\\right)\\right]} - \\sin{\\left[k\\left(x-\\frac{a}{2}\\right)\\right]}\\right\\} dk\n\\end{align*}\n\nTo evaluate this, recall the result that,\n\n\\begin{align*}\n  \\int_0^{\\infty} \\frac{\\sin{\\alpha t}}{t} dt =\n  \\begin{cases}\n    \\frac{\\pi}{2} & \\alpha > 0 \\\\\n    0 & \\alpha = 0 \\\\\n    -\\frac{\\pi}{2} & \\alpha < 0\n  \\end{cases} = \\frac{\\pi}{2} sgn \\alpha\n\\end{align*}\n\nThe integral therefore evaluates to,\n\n\\begin{align*}\n  f(x) &= \\frac{1}{\\pi}\\left\\{\\frac{\\pi}{2} sgn\\left(x+\\frac{a}{2}\\right) - \\frac{\\pi}{2} sgn\\left(x-\\frac{a}{2}\\right)\\right\\} \\\\\n       &= \\frac{1}{2}\\left\\{sgn\\left(x+\\frac{a}{2}\\right) - sgn\\left(x-\\frac{a}{2}\\right)\\right\\} \\\\\n       &=\n  \\begin{cases}\n    0 & x > \\frac{a}{2} \\\\\n    1 & -\\frac{a}{2} > x > \\frac{a}{2} \\\\\n    0 & -\\frac{a}{2} > x \\\\\n  \\end{cases} \\\\\n  &= T(x; -\\frac{a}{2}, \\frac{a}{2})\n\\end{align*}\n\nTherefore as we see we have arrived back at our original function $f(x)$, the top hat function. You may be wondering what the point of this was, as we already knew that it was the inverse transform, but this was just done as some practise with applying the integral.\n\nFinally in this example let us apply Parsevel's theorem which we already found for the Fourier transform.\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} {|f(x)|}^2 dx = \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty}{\\left[\\frac{2\\sin{\\frac{ka}{2}}}{k}\\right]}^2 dk\n\\end{align*}\n\nIn this case, $f(x) = {|f(x)|}^2$ because it is the top hat function so only has a value of $1$ or $0$. The integral therefore becomes,\n\n\\begin{align*}\n  \\int_{-\\frac{a}{2}}^{\\frac{a}{2}}dx &= \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty}{\\left[\\frac{2\\sin{\\frac{ka}{2}}}{k}\\right]}^2 dk \\\\\n  a &= \\frac{2}{\\pi}\\int_{-\\infty}^{\\infty}\\frac{\\sin^2{\\frac{ka}{2}}}{k^2} dk\n\\end{align*}\n\nWe can therefore rearrange to show,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty}\\frac{\\sin^2{\\frac{ka}{2}}}{k^2}dk = \\frac{\\pi}{2}a\n\\end{align*}\n\nIf we set $a = 2$ we find a general result,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty}\\frac{\\sin^2{k}}{k^2}dk = \\pi\n\\end{align*}\n\n\n\\section{Example 2: Exponential}\n\nWe will now do another example, but instead of using a discrete top hat function, we will use a continuous exponential decay function of the form,\n\n\\begin{align*}\n  f(x) = \\exp{\\left(-\\lambda |x|\\right)}\n\\end{align*}\n\nThe Fourier transform is evaluated trivially using our formula,\n\n\\begin{align*}\n  \\tilde{f}(k) &= \\int_{0}^{\\infty}e^{-\\lambda x}e^{-ikx}dx + \\int_{-\\infty}^{0}e^{\\lambda x}e^{-ikx} dx \\\\\n               &= \\int_0^{\\infty}e^{-(\\lambda + ik)x}dx + \\int_{-\\infty}^0 e^{(\\lambda -ik)x}dx \\\\\n               &= {\\left[\\frac{e^{-(\\lambda + ik)x}}{-(\\lambda + ik)}\\right]}_0^{\\infty} + \\left[\\frac{e^{(\\lambda - ik) x}}{\\lambda - ik}\\right]_{-\\infty}^0 \\\\\n               &= \\frac{1}{\\lambda + ik} + \\frac{1}{\\lambda - ik} \\\\\n               &= \\frac{(\\lambda - ik) + (\\lambda + ik)}{(\\lambda + ik)(\\lambda - ik)} \\\\\n               &= \\frac{2\\lambda}{k^2 + \\lambda^2}\n\\end{align*}\n\nAgain we can take the inverse Fourier transform in the same way and find an interesting result,\n\n\\begin{align*}\n  f(x) &= \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty}\\tilde{f}(k)e^{ikx}dk \\\\\n       &= \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty}\\frac{2\\lambda}{k^2+\\lambda^2}e^{ikx}dk \\\\\n       &= \\frac{\\lambda}{\\pi}\\int_{-\\infty}^{\\infty}\\frac{1}{k^2+\\lambda^2}\\cos{kx}dk \\\\\n\\end{align*}\n\nIn the second line, we noticed that the first term in the integral is even in $k$, so we only get the cosine term of the complex exponential. We therefore find,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} \\frac{\\cos{kx}}{k^2+\\lambda^2} dk = \\frac{\\pi}{\\lambda}e^{-\\lambda |x|} \\quad \\text{for $\\lambda > 0$}\n\\end{align*}\n\n\\section{Example 4: Gaussian}\n\nTake a Gaussian function of the form $f(x) = e^{-\\frac{x^2}{2\\sigma^2}}$. To take the Fourier Transform we need to know the standard integral, $\\int_{-\\infty}^{\\infty} e^{-\\alpha x^2} dx = \\sqrt{\\frac{\\pi}{\\alpha}}$. Using our formula for the Fourier transform we have,\n\n\\begin{align*}\n  \\tilde{f}(k) &= \\int_{-\\infty}^{\\infty} e^{-\\frac{x^2}{2\\sigma^2}} e^{-ikx} dx \\\\\n               &= \\int_{-\\infty}^{\\infty} e^{-\\frac{1}{2\\sigma^2}\\left[x^2 + 2ik\\sigma^2 x\\right]} dx\n\\end{align*}\n\nThe reason we made this factorization is so that we have a quadratic the first term is $x^2$. Solving by completing the square,\n\n\\begin{align*}\n  \\tilde{f}(k) &= \\int_{-\\infty}^{\\infty} \\exp{\\left[-\\frac{1}{2\\sigma^2} \\left\\{ {\\left(x+ik\\sigma^2\\right)}^2 - {\\left(ik\\sigma^2\\right)}^2\\right\\}\\right]} dx \\\\\n               &= \\exp{\\left[-\\frac{1}{2}k^2\\sigma^2\\right]}\\int_{-\\infty}^{\\infty}\\exp{\\left[-\\frac{1}{2\\sigma^2}{\\left(x + ik\\sigma^2\\right)}^2\\right]} dx \\\\\n               &= e^{-\\frac{1}{2}k^2\\sigma^2}\\int_{-\\infty + ik\\sigma^2}^{\\infty + ik\\sigma^2} \\exp{\\left[-\\frac{1}{2\\sigma^2}u^2\\right]} du\n\\end{align*}\n\nIn the last line we let $u = x + ik\\sigma^2$, and therefore $du = dx$, our Fourier transform is therefore,\n\n\\begin{align*}\n  \\tilde{f}(k) &= \\sqrt{\\frac{\\pi}{1/2\\sigma^2}} e^{-\\frac{1}{2}k^2\\sigma^2} \\\\\n               &= \\sqrt{2\\pi\\sigma^2} e^{-\\frac{1}{2}k^2\\sigma^2}\n\\end{align*}\n\nThere we have the Fourier transform of the Gaussian function, not too shabby!\n\n\\section{Example 5: Delta Function}\n\nIn this example we will take the Fourier transform of the delta function,\n\n\\begin{align*}\n  f(x) = \\delta(x)\n\\end{align*}\n\nThe Fourier transform is simply,\n\n\\begin{align*}\n  \\tilde{f}(k) &= \\int_{-\\infty}^{\\infty} \\delta(x) e^{-ikx} dx \\\\\n               &= 1\n\\end{align*}\n\nThis is because the delta function is zero everywhere except at $x = 0$, at which point the exponential is equal to $1$.\n\n\\section{Example 6: Constant}\n\nIn this section we will find the Fourier transform of a constant $f(x) = 1$. The Fourier transform is therefore $\\tilde{f}(k) = \\int_{-\\infty}^{\\infty} e^{-ikx} dx$. We know from our continuous representation of the Heaviside function (look this up) that this is,\n\n\\begin{align*}\n  \\tilde{f}(k) = 2\\pi\\delta(k)\n\\end{align*}\n\nTherefore we see that the Fourier transform of a constant function is a delta function.\n\n\\section{Example 7: Cosine}\n\nIn this section we will find the Fourier transform of $f(x) = \\cos{k_0 x}$. The Fourier transform is,\n\n\\begin{align*}\n  \\tilde{f}(k) &= \\int_{-\\infty}^{\\infty} \\cos{k_0 x} e^{-ikx} dx \\\\\n               &= \\int_{-\\infty}^{\\infty} \\frac{1}{2}\\left(e^{ik_0 x} - e^{-ik_0 x}\\right) e^{-ikx} dx \\\\\n               &= \\frac{1}{2} \\int_{-\\infty}^{\\infty} e^{-i(k-k_0)x} + e^{-i(k+k_0)x} dx \\\\\n               &= \\frac{1}{2} \\left[2\\pi\\delta(k-k_0) + 2\\pi \\delta(k+k_0)\\right] \\\\\n               &= \\pi \\left[\\delta(k-k_0) + \\delta(k+k_0)\\right]\n\\end{align*}\n\n\\section{Fourier Transform as an Operator}\n\nIn this section, we will define the Fourier Transform operator $\\mathcal{F}\\left[f(x)\\right] = \\tilde{f}(k)$ so that $\\mathcal{F}$ is the operation of taking the Fourier transform. We will define and prove some rules about how this operator works.\n\nFirst we have a rule of linearity,\n\n\\begin{align*}\n  \\mathcal{F}\\left[\\alpha f(x) + \\beta g(x)\\right] = \\alpha\\tilde{f}(k)+\\beta\\tilde{f}(k)\n\\end{align*}\n\nThis follows from the linearity of integration,\n\n\\begin{align*}\n  \\mathcal{F}\\left[\\alpha f(x) + \\beta g(x)\\right] &= \\int_{-\\infty}^{\\infty} \\left[\\alpha f(x) + \\beta g(x)\\right] e^{-ikx} dx \\\\\n                                                   &= \\alpha\\int_{-\\infty}^{\\infty}f(x)e^{-ikx}dx + \\beta\\int_{-\\infty}^{\\infty}g(x)e^{-ikx}dx \\\\\n                                                   &= \\alpha\\tilde{f}(k) + \\beta\\tilde{g}(k)\n\\end{align*}\n\nNext, we have the shift rule,\n\n\\begin{align*}\n  \\mathcal{F}\\left[f(x-a)\\right] = e^{-ika} \\tilde{f}(k)\n\\end{align*}\n\nThis follows by making the substitution $x = y + a$,\n\n\\begin{align*}\n  \\mathcal{F}\\left[f(x-a)\\right] &= \\int_{-\\infty}^{\\infty} f(x-a) e^{-ikx} dx \\\\\n                                 &= \\int_{-\\infty}^{\\infty} f(y) e^{-ik(y+a)} dy \\\\\n                                 &= e^{-ika}\\int_{-\\infty}^{\\infty} f(y) e^{-iky}dy \\\\\n                                 &= e^{-ika}\\tilde{f}(k)\n\\end{align*}\n\nNext, we have a rule for transforms of the $n$-th derivative of a function,\n\n\\begin{align*}\n  \\mathcal{F}\\left[f^n(x)\\right] = {(ik)}^n \\tilde{f}(k)\n\\end{align*}\n\nThis follows by differentiating the inverse Fourier transform $n$ times,\n\n\\begin{align*}\n  f(x) &= \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} \\tilde{f}(k) e^{ikx} dk \\\\\n  f^n(x) &= \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} {(ik)}^n \\tilde{f}(k) e^{ikx} dk \\\\\n  \\mathcal{F}\\left[f^n(x)\\right] &= {(ik)}^n \\tilde{f}(k)\n\\end{align*}\n\nNext we have the inverse of that rule,\n\n\\begin{align*}\n  \\mathcal{F}\\left[{(-ix)}^n f(x)\\right] = \\tilde{f}^n(k)\n\\end{align*}\n\nThis follows by differentiating the Fourier transform $n$ times,\n\n\\begin{align*}\n  \\tilde{f}(k) &= \\int_{-\\infty}^{\\infty}f(x)e^{-ikx}dx\\\\\n  \\tilde{f}^n(k) &= \\int_{-\\infty}^{\\infty}{(-ik)}^nf(x)e^{-ikx} dx \\\\\n  \\tilde{f}^n(k) &= \\mathcal{F}\\left[{(-ik)}^n f(x)\\right]\n\\end{align*}\n\nNext we have the transform of a product,\n\n\\begin{align*}\n  \\mathcal{F}\\left[f(x)g(x)\\right] = \\frac{1}{2\\pi} \\tilde{f}*\\tilde{g}(k)\n\\end{align*}\n\nThis is proven as follows,\n\n\\begin{align*}\n  \\mathcal{F}\\left[f(x)g(x)\\right] &= \\int_{-\\infty}^{\\infty}f(x)g(x)e^{-ikx}dx \\\\\n                                   &= \\int_{-\\infty}^{\\infty}f(x) \\left[\\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} \\tilde{g}(q) e^{iqx} dq\\right] e^{-ikx} dx \\\\\n                                   &= \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} \\tilde{g}(q) dq \\left[\\int_{-\\infty}^{\\infty}f(x) e^{iqx}e^{-ikx} dx\\right] \\\\\n                                   &= \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} \\tilde{g}(q) dq \\left[\\int_{-\\infty}^{\\infty}f(x) e^{-i(k - q)x} dx\\right] \\\\\n                                   &= \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} \\tilde{f}(k-q) \\tilde{g}(q) dq \\\\\n                                   &= \\frac{1}{2\\pi} \\tilde{f}*\\tilde{g}(k)\n\\end{align*}\n\nFinally we have the inverse of this,\n\n\\begin{align*}\n  \\mathcal{F}\\left[f*g(x)\\right] = \\tilde{f}(k) \\tilde{g}(k)\n\\end{align*}\n\nThis is proven as follows,\n\n\\begin{align*}\n  \\mathcal{F}\\left[f*g(x)\\right] &= \\int_{-\\infty}^{\\infty} f*g(x) e^{-ikx} dx \\\\\n                                 &= \\int_{-\\infty}^{\\infty} \\left[\\int_{-\\infty}^{\\infty}f(x-y)g(y)dy\\right] e^{-ikx} dx \\\\\n                                 &= \\int_{-\\infty}^{\\infty} g(y) dy \\left[\\int_{-\\infty}^{\\infty} f(x-y) e^{-ikx} dx\\right] \\\\\n                                 &= \\tilde{f}(k) \\int_{-\\infty}^{\\infty} g(y) e^{-iky} dy \\\\\n                                 &= \\tilde{f}(k) \\tilde{g}(k)\n\\end{align*}\n\n\n\\section{Convolutions}\n\nConvolutions commonly occur when an instrument has an intrinsic distortion or blurring. The image produced is the convolution of the true image and the instrument's profile.\n\nTo obtain the true image one needs to deconvolve,\n\n\\begin{align*}\n  f*I \\to \\tilde{f}(k) \\tilde{I}(k) \\to \\tilde{f}(k) \\to f\n\\end{align*}\n\nGeometrically $f*g(x)$ is the area under the product $f(x-y) g(y)$. $f(x-y)$ is obtained from $f(y)$ by reflecting about the line $y = x$ and translating by $x$.\n\nNow we will do a couple of examples of convolutions. First, we will take two delta functions and convolute them with a top hat function.\n\n\\begin{align*}\n  f(y) &= \\delta{(y + \\frac{\\pi}{2})} + \\delta{(y + \\frac{\\pi}{2})} \\\\\n  g(y) &= \\Theta{(\\frac{d}{2} - |y|)} = T(y; -\\frac{d}{2}, \\frac{d}{2}) \\\\\n\\end{align*}\n\nIn this case the function is even so,\n\n\\begin{align*}\n  f(x - y) = f(y - x) = \\delta\\left(y - x + \\frac{a}{2}\\right) + \\delta\\left(y - x - \\frac{a}{2}\\right)\n\\end{align*}\n\nThe convolution can then be evaluated,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} f(x-y)g(y)dy &= \\int_{-\\infty}^{\\infty} \\left[\\delta\\left(y - x + \\frac{a}{2}\\right) + \\delta\\left(y - x - \\frac{a}{2}\\right)\\right] \\Theta\\left(\\frac{d}{2} - |y|\\right) dy \\\\\n                                       &= \\Theta\\left(\\frac{d}{2} - \\left|x - \\frac{a}{2}\\right|\\right) + \\Theta\\left(\\frac{d}{2} - \\left|x + \\frac{a}{2}\\right|\\right) \\\\\n                                       &= T\\left(x; \\frac{(a-d)}{2}, \\frac{(a+d)}{2}\\right) + T\\left(x; -\\frac{(a+d)}{2}, \\frac{(d-a)}{2}\\right)\n\\end{align*}\n\nThe Fourier transform is given by,\n\n\\begin{align*}\n  \\mathcal{F}\\left[f*g(x)\\right] = \\tilde{f}(k)\\tilde{g}(k) = \\left[2\\cos{\\frac{ka}{2}}\\right]\\left[2\\frac{\\sin{\\frac{kd}{2}}}{k}\\right]\n\\end{align*}\n\nNext we will do an example with two equal top hat functions,\n\n\\begin{align*}\n  f(y) = g(y) = \\Theta{(a - |y|)} = T(y; -a, a)\n\\end{align*}\n\nIf $x = 0$ in the convolution then the top hat functions are just on top of each other,\n\n\\begin{align*}\n  f*g(x=0) = \\int {[f(y)]}^2 dy = \\int_{-a}^{a} dy = 2a\n\\end{align*}\n\nAs the value $|x|$ increases, $f * g$ decreases linearly until it vanishes at $|x| = 2a$.\n\nIn this example the Fourier transform of the convolution is,\n\n\\begin{align*}\n  \\tilde{f}(k) \\tilde{g}(k) = {\\left[\\frac{2\\sin{ka}}{k}\\right]}^2\n\\end{align*}\n\n\nSee the notes on Canvas for an example with two Gaussians.\n\n\\section{Fourier Cosine Transform}\n\nIf $f(x)$ is a real, even function, then we may observe that the integral over the $i\\sin$ term in the Fourier transform goes to zero, so we are just left with the $\\cos$ term,\n\n\\begin{align*}\n  \\tilde{f}(k) &= \\int_{-\\infty}^{\\infty} f(x)\\left[\\cos{kx}-i\\sin{kx}\\right]dx \\\\\n               &= \\int_{-\\infty}^{\\infty} f(x)\\cos{kx} dx \\\\\n               &= 2 \\int_{0}^{\\infty} f(x)\\cos{kx} dx \\\\\n               &= 2 \\tilde{f_c}(k)\n\\end{align*}\n\nwhere $\\tilde{f_c}(k) = \\int_0^{\\infty}f(x)\\cos{kx}dx$ is called the Fourier cosine transform.\n\nIt follows that $\\tilde{f}(k)$ is a real and even function of $k$. To find the inverse transform we see that since $\\tilde{f}(k)$ is even, only the cosine term remains, as the integral over the sine term will be zero,\n\n\\begin{align*}\n  f(x) &= \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty} \\tilde{f}(k) e^{ikx} dk \\\\\n       &= \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty} \\tilde{f}(k) \\left[\\cos{kx}+i\\sin{kx}\\right] dk \\\\\n       &= \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty} \\tilde{f}(k) \\cos{kx} dk \\\\\n       &= \\frac{1}{\\pi}\\int_0^{\\infty} \\left[2\\tilde{f_c}(k)\\right] \\cos{kx} dk \\\\\n  f(x) &= \\frac{2}{\\pi}\\int_0^{\\infty} \\tilde{f_c}(k) \\cos{kx} dk\n\\end{align*}\n\nIn the symmetric form of the transform the $2/\\pi$ can be split equally as $\\sqrt{2/\\pi}$.\n\n\\section{Fourier Sine Transform}\n\nIf $f(x)$ is a real, odd function, then the cosine term will integrate to zero as it will be zero over symmetric limits,\n\n\\begin{align*}\n  \\tilde{f}(k) &= \\int_{-\\infty}^{\\infty} f(x) \\left[\\cos{kx} - i\\sin{kx}\\right] dx \\\\\n               &= -i\\int_{-\\infty}^{\\infty} f(x) \\sin{kx} dx \\\\\n               &= -2i\\int_0^{\\infty} f(x) \\sin{kx} dx \\\\\n               &= -2i \\tilde{f_s}(k)\n\\end{align*}\n\nwhere $\\tilde{f_s}(k) = \\int_0^{\\infty}f(x)\\sin{kx}dx$ is called the Fourier sine transform.\n\nIt follows that $\\tilde{f}(k)$ is an imaginary, odd function of $k$. To find the inverse note that the cosine term will disappear again over the symmetric limits as $\\tilde{f}(k)$ is odd,\n\n\\begin{align*}\n  f(x) &= \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty} \\tilde{f}(k) e^{ikx} dk \\\\\n       &= \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty} \\tilde{f}(k) \\left[\\cos{kx} + i\\sin{kx}\\right] dk \\\\\n       &= \\frac{1}{2\\pi} i \\int_{-\\infty}^{\\infty} \\tilde{f}(k) \\sin{kx} dk \\\\\n       &= \\frac{1}{2\\pi} i 2 \\int_0^{\\infty}\\left[-2i\\tilde{f_s}(k)\\right] \\sin{kx} dk \\\\\n  f(x) &= \\frac{2}{\\pi} \\int_0^{\\infty}\\tilde{f_s}(k)\\sin{kx} dx\n\\end{align*}\n\n\\section{Higher-dimensional Fourier Transforms}\n\nFor a function $f(x, y)$ of two vriables we can define a Fourier transform,\n\n\\begin{align*}\n  \\tilde{f}(k_x, k_y) = \\int_{-\\infty}^{\\infty}dx\\int_{-\\infty}^{\\infty}dy f(x, y) e^{-i(k_x+k_y+k_z)}\n\\end{align*}\n\nand the inverse transform,\n\n\\begin{align*}\n  f(x, y) = \\frac{1}{{(2\\pi)}^2} \\int_{-\\infty}^{\\infty}dk_x\\int_{-\\infty}^{\\infty} \\tilde{f}(k_x, k_y) e^{i(k_x, k_y)}\n\\end{align*}\n\nWe can add to this for higher dimensions but it quickly gets messy, so for $d$ dimensions we define $\\mathbf{r} = (x_1, x_2, \\dots x_d)$, and $\\mathbf{k} = (k_1, k_2, \\dots k_d)$. The Fourier transform and its inverse can then be defined as,\n\n\\begin{align*}\n  \\tilde{f}(\\mathbf{k}) &= \\int_V f(\\mathbf{r}) e^{-i\\mathbf{k}\\cdot\\mathbf{r}} d^d r \\\\\n  f(\\mathbf{r}) &= \\frac{1}{{(2\\pi)}^d} \\int_{\\tilde{V}} \\tilde{f}(\\mathbf{k}) e^{i\\mathbf{k}\\cdot\\mathbf{r}} d^d k\n\\end{align*}\n\nFor example, for plane waves defined as $f(\\mathbf{r}, t) = e^{i(\\mathbf{k}\\cdot\\mathbf{r} - \\omega t)}$ the fourier transform is,\n\n\\begin{align*}\n  \\tilde{f}(\\mathbf{k}, \\omega) &= \\int d^3r dt f(\\mathbf{r}, t) e^{i(\\omega t - \\mathbf{k}\\cdot\\mathbf{r})} \\\\\n  f(\\mathbf{r}, t) &= \\frac{1}{{(2\\pi)}^4} \\int d^3r dt \\tilde{f}(\\mathbf{k}, \\omega) e^{i(\\mathbf{k}\\cdot\\mathbf{r} - \\omega t)}\n\\end{align*}\n\n\\section{Radial Fourier Transform}\n\nConsider the Fourier transform of a 3D function $V(r)$ which depends only on $r = |\\mathbf{r}|$. The Fourier transform is defined as,\n\n\\begin{align*}\n  \\tilde{V}(k) = \\int d^3r V(r) e^{-\\mathbf{k}\\cdot\\mathbf{r}}\n\\end{align*}\n\nWe will use spherical polar coordinates, so that,\n\n\\begin{align*}\n  d^3r &= r^2\\sin{\\theta}dr d\\theta d\\phi \\\\\n  \\mathbf{k}\\cdot\\mathbf{r} &= kr \\cos{\\theta}\n\\end{align*}\n\nWe set the $z$-axis of our polars along the $\\mathbf{k}$ direction.\n\n\\begin{align*}\n  \\tilde{V}(k) &= \\int_0^{\\infty} r^2 V(r) dr \\int_0^{\\pi} e^{-ikr\\cos{\\theta}} \\sin{\\theta} d\\theta \\int_0^{2\\pi} d\\phi \\\\\n               &= \\int_0^{\\infty} 2\\pi r^2 V(r) dr \\int_0^{\\pi} e^{-ikr\\cos{\\theta}} \\sin{\\theta} d\\theta \\\\\n               &= \\int_0^{\\infty} 2\\pi r^2 V(r) dr {\\left[\\frac{e^{-ikr\\cos{\\theta}}}{ikr}\\right]}^{\\theta = \\pi}_{\\theta = 0} \\\\\n               &= \\int_0^{\\infty} 2\\pi r^2 V(r) dr \\left[\\frac{e^{ikr} - e^{-ikr}}{ikr}\\right] \\\\\n               &= \\int_0^{\\infty} 2\\pi r^2 v(r) dr \\left[\\frac{2i\\sin{kr}}{ikr}\\right] \\\\\n               &= \\frac{4\\pi}{k}\\int_0^{\\infty} r\\sin{kr} V(r) dr\n\\end{align*}\n\n\n$\\tilde{V}(k)$ is the radial Fourier transform of $V(r)$. For example, consider the Yukawa potential $V(r) = \\frac{1}{r} e^{-\\frac{r}{a}}$,\n\n\\begin{align*}\n  \\tilde{V}(k) &= \\frac{4\\pi}{k}\\int_0^{\\infty}r\\sin{kr} V(r) dr \\\\\n               &= \\frac{4\\pi}{k}\\int_0^{\\infty}\\sin{kr} e^{-\\frac{r}{a}} dr \\\\\n               &= \\frac{4\\pi}{k} \\Im \\int_0^{\\infty} e^{-r\\left(\\frac{1}{a}-ik\\right)} dr \\\\\n               &= \\frac{4\\pi}{k}\\Im {\\left[-\\frac{1}{\\frac{1}{a} - ik} e^{-r\\left(\\frac{1}{a} - ik\\right)}\\right]}_{r=0}^{r=\\infty} \\\\\n               &= \\frac{4\\pi}{k}\\Im\\left[\\frac{1}{\\frac{1}{a} - ik}\\right] \\\\\n               &= \\frac{4\\pi}{k}\\Im\\left[\\frac{\\frac{1}{a} + ik}{\\frac{1}{a^2} + k^2}\\right] \\\\\n               &= \\frac{4\\pi}{k}\\frac{k}{k^2 + \\frac{1}{a^2}}\n  \\tilde{V}(k) &= \\frac{4\\pi}{k^2 + \\frac{1}{a^2}}\n\\end{align*}\n\nTo get the Coulomb potential, let $a \\to \\infty$. For $V(r) = \\frac{1}{r}$,\n\n\\begin{align*}\n  \\tilde{V}(k) = \\frac{4\\pi}{k^2}\n\\end{align*}\n\nWith the constants $V(r) = \\frac{e^2}{4\\pi\\epsilon_0 r}$,\n\n\\begin{align*}\n  \\tilde{V}(k) = \\frac{e^2}{\\epsilon_0 k^2}\n\\end{align*}\n\n\n\\section{Solution of Poisson's Equation}\n\nSuppose we start from Maxwell's equations of electromagnetism, how do we derive Coulomb's law? In the static case, where there is no time dependence, M1 and M3 become,\n\n\\begin{align*}\n  \\nabla\\cdot\\mathbf{E} &= \\frac{\\rho}{\\epsilon_0} \\\\\n  \\nabla\\times\\mathbf{E} &= 0\n\\end{align*}\n\nFrom Helmholtz's theorem, since in the second equation the curl is equal to zero $\\nabla\\times\\mathbf{E} = 0$ this implies there is some scalar field $V(\\mathbf{r})$ such that $\\mathbf{E} = -\\nabla V$. Substituting $\\mathbf{E} = -\\nabla V$ into the first Maxwell equation gives,\n\n\\begin{align*}\n  \\nabla^2 V(\\mathbf{r}) = -\\frac{\\rho(\\mathbf{r})}{\\epsilon_0}\n\\end{align*}\n\nThis is called Poisson's equatoin. To solve Poisson's equation, write $V(\\mathbf{r})$ as a Fourier expansion,\n\n\\begin{align*}\n  V(\\mathbf{r}) = \\frac{1}{{(2\\pi)}^2}\\int d^3\\mathbf{k} \\tilde{V}(k) e^{i\\mathbf{k}\\cdot\\mathbf{r}}\n\\end{align*}\n\nOperating $\\nabla^2$ on $e^{i\\mathbf{k}\\cdot\\mathbf{r}}$ gives,\n\n\\begin{align*}\n  \\nabla^2 e^{i\\mathbf{k}\\cdot\\mathbf{r}} = \\left[\\frac{\\partial^2}{\\partial x^2} + \\frac{\\partial^2}{\\partial y^2} + \\frac{\\partial^2}{\\partial z^2}\\right] e^{i(k_x x + k_y y + k_z z)}\n\\end{align*}\n\n\\begin{align*}\n  \\nabla^2 e^{i\\mathbf{k}\\cdot\\mathbf{r}} &= \\left[-{k_x}^2 -{k_y}^2 -{k_z}^2\\right] e^{i\\mathbf{k}\\cdot\\mathbf{r}} \\\\\n                                           &= -k^2 e^{i\\mathbf{k}\\cdot\\mathbf{r}}\n\\end{align*}\n\nIt follows that,\n\n\\begin{align*}\n  \\nabla^2 V(\\mathbf{r}) = \\frac{1}{{(2\\pi)}^3}\\int d^3\\mathbf{k}(-k^2 \\tilde{V}(\\mathbf{k})) e^{i\\mathbf{k}\\cdot\\mathbf{r}}\n\\end{align*}\n\nWe can write the right hand side of Poisson's equation as a Fourier expansion,\n\n\\begin{align*}\n  -\\frac{\\rho(\\mathbf{r})}{\\epsilon_0} = \\frac{1}{{(2\\pi)}^3}\\int d^3\\mathbf{k} \\left(-\\frac{\\tilde{\\rho}(\\mathbf{k})}{\\epsilon_0}\\right) e^{i\\mathbf{k}\\cdot\\mathbf{r}}\n\\end{align*}\n\nSince $\\nabla^2 V(\\mathbf{r}) = -\\frac{\\rho(\\mathbf{r})}{\\epsilon_0}$, the bracketed terms in the Fourier transforms must be equal,\n\n\\begin{align*}\n  -k^2 \\tilde{V}(\\mathbf{k}) = -\\frac{\\tilde{\\rho}(\\mathbf{k})}{\\epsilon_0}\n\\end{align*}\n\nIt follows that,\n\n\\begin{align*}\n  \\tilde{V}(\\mathbf{k}) = \\frac{\\tilde{\\rho}(\\mathbf{k})}{\\epsilon_0 k^2} = \\tilde{\\rho}(\\mathbf{k}) \\tilde{G}(\\mathbf{k})\n\\end{align*}\n\nwhere $\\tilde{G}(\\mathbf{k}) = \\frac{1}{\\epsilon_0 k^2}$.\n\nFrom before with the Coulomb potential this Fourier transform $\\tilde{G}(\\mathbf{k})$ corresponds to\n\n\\begin{align*}\n  G(\\mathbf{r}) = \\frac{1}{4\\pi\\epsilon_0 r}\n\\end{align*}\n\nFrom the convolution theorem,\n\n\\begin{align*}\n  \\tilde{V}(\\mathbf{k}) &= \\tilde{\\rho}(\\mathbf{k})\\tilde{G}(\\mathbf{k})\n\\end{align*}\n\n\\begin{align*}\n  \\to V(\\mathbf{r}) &= \\rho * G(\\mathbf{r}) = \\int d^3 \\mathbf{r'} G(\\mathbf{r} - \\mathbf{r'}) \\rho(\\mathbf{r'})\n\\end{align*}\n\nHence we get the final result,\n\n\\begin{align*}\n  V(\\mathbf{r}) = \\int \\frac{\\rho(\\mathbf{r'})}{4\\pi\\epsilon_0 |\\mathbf{r} - \\mathbf{r'}|} d^3 \\mathbf{r'}\n\\end{align*}\n\nAnd therefore the eletric field is,\n\n\\begin{align*}\n  \\mathbf{E}(\\mathbf{r}) = -\\nabla V(\\mathbf{r}) = \\int \\frac{\\rho(\\mathbf{r'}) (\\mathbf{r} - \\mathbf{r'})}{4\\pi\\epsilon_0 {|\\mathbf{r} - \\mathbf{r'}|}^3} d^3 \\mathbf{r'}\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "4f195ab23a91be07fc423f9e199234ed2ef2bac3", "size": 54435, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "maths/fourier/fourier.tex", "max_stars_repo_name": "unanimousarc/physics", "max_stars_repo_head_hexsha": "7bc9cbd428defb7615f5a2e241d86fae71ece7b3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-03-13T14:28:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-06T14:27:57.000Z", "max_issues_repo_path": "maths/fourier/fourier.tex", "max_issues_repo_name": "unanimousarc/physics", "max_issues_repo_head_hexsha": "7bc9cbd428defb7615f5a2e241d86fae71ece7b3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "maths/fourier/fourier.tex", "max_forks_repo_name": "unanimousarc/physics", "max_forks_repo_head_hexsha": "7bc9cbd428defb7615f5a2e241d86fae71ece7b3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-29T08:14:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-29T08:14:51.000Z", "avg_line_length": 44.9133663366, "max_line_length": 862, "alphanum_fraction": 0.600551116, "num_tokens": 20710, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.8688267660487572, "lm_q1q2_score": 0.7452518949963307}}
{"text": "%!TEX root=ClassNotes.tex\n\\section{Trig, Exp, and Log functions}\nWe'll use the Fundamental Theorem of Calculus to compute the derivatives of trigonometric functions, exponentials, and logarithms.\n\\subsection{Trigonometric Functions}\nIn this section, we'll prove that\n\\begin{align*}\n\t(\\cos x)' &= -\\sin x\\\\\n\t(\\sin x)' &= \\cos x\n\t\\end{align*}\nWe'll only show this for $0 < x < \\pi/2$, however,  the statements are true for all real numbers $x$.\nWe'll do this by first computing $\\left(\\cos^{-1}x \\right)'$ using basic geometry and the Fundamental Theorem and then using the formula for the derivative of inverse functions.\n\n\\begin{exercise}\n\tConsider the unit circle $x^2 + y^2 = 1$. In the following figure, the shaded region is a sector of angle $\\theta$ (in radians), for $0 < \\theta < \\pi/2$, so that the corresponding point on the circle is $(\\cos \\theta, \\sin \\theta)$.\n\t\\begin{align*}\n\t\t\\adjincludegraphics[width=0.3\\textwidth, valign=c]{pie1.png}\n\t\t=\n\t\t\\adjincludegraphics[width=0.3\\textwidth, valign=c]{pie2.png}\n\t\t+\n\t\t\\adjincludegraphics[width=0.3\\textwidth, valign=c]{pie3.png}\n\t\\end{align*}\n\t\\begin{enumerate}\n\t\t\\item Argue that the above decomposition of areas can be expressed algebraically as\n\t\t      \\begin{align*}\n\t\t\t      \\dfrac{\\theta}{2}\n\t\t\t       & =\n\t\t\t      \\dfrac{x \\sqrt{1 - x^2}}{2}\n\t\t\t      +\n\t\t\t      \\int \\limits_x^1 \\sqrt{1 - t^2} \\: dt\n\t\t      \\end{align*}\n\t\t      which can further be simplified to\n\t\t      \\begin{align*}\n\t\t\t      \\dfrac{\\cos^{-1}x}{2}\n\t\t\t       & =\n\t\t\t      \\dfrac{x \\sqrt{1 - x^2}}{2}\n\t\t\t      +\n\t\t\t      \\int \\limits_x^1 \\sqrt{1 - t^2} \\: dt\n\t\t      \\end{align*}\n\n\t\t\\item Differentiate both sides to show that\n\t\t      \\begin{align*}\n\t\t\t      \\left(\\cos^{-1}x \\right)'\n\t\t\t       & =\n\t\t\t      -\\dfrac{1}{\\sqrt{1-x^2}}\n\t\t      \\end{align*}\n\n\t\t\\item Use the formula for the derivative of inverse function\\footnote{$\\left(f^{-1}(a)\\right)'= \\dfrac{1}{f'(f^{-1}(a))}$} to show that\n\t\t      \\begin{align*}\n\t\t\t      (\\cos \\theta)' = -\\sin \\theta\n\t\t      \\end{align*}\n\t\\end{enumerate}\n\\end{exercise}\n\n\n\\begin{exercise}\n\tDifferentiate both sides of the trig identity\n\t\\begin{align*}\n\t\t\\sin^2 x  + \\cos^2 x = 1\n\t\\end{align*}\n\tand use your computation of $(\\cos x)'$ to show that\n\t\\begin{align*}\n\t\t(\\sin x)' = \\cos x\n\t\\end{align*}\n\\end{exercise}\n\n\\begin{exercise}\n\t\\begin{enumerate}\n\t\t\\item Use the formula for the derivative of inverse function to compute the derivative of $\\sin ^{-1}x$.\n\t\t\\item What is the relationship between the derivatives of $\\sin ^{-1}x$ and $\\cos ^{-1}x$? Why do you think this is the case?\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tCompute the derivatives of $\\tan x$ and $\\tan^{-1} x$.\n\\end{exercise}\n\n\n\\subsection{Exponential Functions and Logarithms}\nExponential functions are a bit tricky to define from first principles as every natural definition of $e^x$ uses either limits of sequences or differential equations.\nWe'll instead give a more {\\it ad hoc} definition of logarithms as in the book and {\\it verify} that it satisfies the properties that logarithms are supposed to satisfy.\n\n\\begin{definition}\n\tDefine the {\\bf natural logarithm} to be the integral\n\t\t\\begin{align*}\n\t\t\t\\ln x = \\int_1^x \\dfrac{1}{t} \\: dt\n\t\t\\end{align*}\n\t\tfor $x > 0$.\n\\end{definition}\n\\begin{remark}\n\tAs $\\ln x$ is {\\it defined} to be the antiderivative of $ 1 / x$,\n\t\\begin{align*}\n\t\t\\left(\\ln x\\right)'= \\dfrac{1}{x}\n\t\\end{align*}\n\\end{remark}\n\\begin{exercise}\n\t\\begin{enumerate}\n\t\t\\item Draw the graph of $\\dfrac{1}{x}$ for $x > 0$.\n\t\t\\item {\\it Geometrically} argue that\n\t\t\t\\begin{align*}\n\t\t\t\t\\ln x \\mbox{ is }\n\t\t\t\t\\begin{cases}\n\t\t\t\t\t\\mbox{positive } & \\mbox{ if } x > 1\\\\\n\t\t\t\t\t0 & \\mbox{ if } x = 1\\\\\n\t\t\t\t\t\t\\mbox{negative } & \\mbox{ if } x < 1\n\t\t\t\t\\end{cases}\n\t\t\t\\end{align*}\n\t\t\\item Using u-substitution\\hint{In the u-substitution formula $\n\t\t\\int_a^z f(g(t)) g'(t)\\: dt = \\int_{g(a)}^{g(z)} f(u) \\: du$ use $g(t) = x \\cdot t$.} show that\n\t\t\\begin{align*}\n\t\t\t\\int_1^y \\dfrac{1}{t} \\: dt\n\t\t\t&=\n\t\t\t\\int_x^{xy} \\dfrac{1}{t} \\: dt\n\t\t\\end{align*}\n\t\tfor real numbers $x , y > 0$. (You should think about what this means geometrically.)\n\t\t\\item Show that this implies that\n\t\t\\begin{align}\n\t\t\t\\label{eq:log_identity}\n\t\t\t\\ln x + \\ln y = \\ln xy\n\t\t\\end{align}\n\t\\end{enumerate}\n\\end{exercise}\nThis last identity \\eqref{eq:log_identity} is the fundamental identity of logarithms.\n\n\\begin{definition}\n\tDefine $\\exp(x)$ to be the inverse function of $\\ln x$ i.e.\n\t\\begin{align*}\n\t\t\\exp(\\ln x) &= x \\\\\n\t\t\\ln(\\exp x) &= x.\n\t\\end{align*}\n\\end{definition}\n\\begin{definition}\n\tDefine $e$ to be the value of $\\exp(x)$ at $x = 1$.\n\\end{definition}\n\n\n\\begin{exercise}\n\t\\begin{enumerate}\n\t\t\\item Show that $\\exp(0) = 1$.\n\t\t\\item Show that Equation \\eqref{eq:log_identity} implies that\n\t\t\\begin{align*}\n\t\t\t\\exp(a + b) = \\exp(a) \\cdot \\exp(b)\n\t\t\\end{align*}\n\t\t\\item Use this to argue that\n\t\t\\begin{align*}\n\t\t\t\\exp(n) = e^n\n\t\t\\end{align*}\n\t\twhere $n$ is a positive integer.\n\t\t\\item {\\bf (Optional)} Extend the above statement first to negative integers and then to rational numbers.\n\t\\end{enumerate}\n\tIt follows then from continuity arguments that\n\t\\begin{align*}\n\t\t\\exp(x) = e^x\n\t\\end{align*}\n\tfor all real numbers $x$.\n\\end{exercise}\n\n\n\\begin{exercise}\n\tUse the formula for the derivative of inverse function to show that\n\t\\begin{align*}\n\t\t\\left(e^x\\right)'=e^x\\\\\n\t\\end{align*}\n\\end{exercise}\n\n\n\nThis completes the computation of derivatives of all the standard functions.\n\n\\begin{exercise}\n\tThe Fundamental Theorem of Calculus says that if $f'(x)=g(x)$ then $f(x) = \\int g(x)\\: dx + c $, where $\\int g(x)\\: dx$ stands for the indefinite integral.\n\tGo back to your derivative computations in this section and rewrite them as indefinite integrals.\n\\end{exercise}\n\nWe'll next use the u-substitution, and Integration by Parts to compute integrals of functions which can be written in terms of these standard functions.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\newpage\n\\subsection{Trigonometric Identities}\nWe'll need several trigonometric identities for computing integrals.\nWhile it is possible to derive these identities using Euclidean geometry, there is a much faster trick to derive these using {\\it Euler's identity}.\n\n\n\\subsubsection{Complex Numbers}\nFirst we need some basic algebraic facts about complex numbers. {\\bf Complex numbers} are numbers of the form\n\\begin{align*}\n\tz = a + b i\n\\end{align*}\nwhere $a$ and $b$ are real numbers and $i$ is a {\\it formal} variable that satisfies\n\\begin{align*}\n\ti^2 = -1.\n\\end{align*} The number $a$ is called the {\\bf real part} of $z$, denoted $\\mathrm{Re}(z)$, and the number $b$ is called it's {\\bf imaginary part}, denoted $\\mathrm{Im}(z)$.\n\nA real number $r$ can be thought of the complex number $ r + 0 i$. Thus the set of complex numbers contains the set of real numbers.\n\nAs with real numbers, we can add, subtract, multiply, and\ndivide complex numbers.\n\\begin{example} Multiplying complex numbers:\n\t\\begin{align*}\n\t\t\t(a + bi)(c - di)\n\t\t\t&= a(c - di) + bi(c - di) \\\\\n\t\t\t&= ac - adi + bci + bd  & \\mbox{ as } i^2 = -1\\\\\n\t\t\t&= (ac + bd) + i(-ad + bc)\n\t\\end{align*}\n\\end{example}\n\n\\begin{exercise}\n\t\\label{q:complex_conjugate}\n\tShow that\n\t\\begin{align*}\n\t\t(a + bi) (a - bi) = a^2 + b^2.\n\t\\end{align*}\n\\end{exercise}\n\nThe complex number $\\overline{z} = a - bi$ is called the {\\bf complex conjugate} of $z=a + bi$.\nBy the above exercise, we get a real number after multiplying a complex number by it's conjugate which is an extremely useful fact.\n\n\\begin{example}\n\t\tComplex conjugates are useful when dividing complex numbers. To simplify a fraction, we multiply and divide by the complex conjugate of the denominator.\n\t\t\\begin{align*}\n\t\t\t\\dfrac{a+bi}{c+di}\n\t\t\t&=\n\t\t\t\\dfrac{a+bi}{c+di} \\cdot\t\\dfrac{c - di}{c-di}\\\\\n\t\t\t&=\n\t\t\t\\dfrac{(a+bi)(c - di)}{c^2+d^2} & \\mbox{ by Exercise \\eqref{q:complex_conjugate}}\\\\\\\n\t\t\t&=\n\t\t\t\\dfrac{(ac + bd) + i(-ad + bc)}{c^2+d^2} \\\\\n\t\t\t&=\n\t\t\t\\dfrac{ac + bd}{c^2+d^2}\n\t\t\t+\n\t\t\ti\\cdot \\dfrac{-ad + bc}{c^2+d^2}\n\t\t\\end{align*}\n\\end{example}\n\n\\begin{exercise}\n\tFind the real and imaginary parts of the following complex numbers:\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $(2-3i)(i)$\n\t\t\t\t\\item $(2-3i)(1+i)$\n\t\t\t\t\t\\item $\\dfrac{1}{i}$\n\t\t\t\t\t\t\\item $\\dfrac{1}{1+i}$\n\t\t\t\t\t\t\t\\item $\\dfrac{2-3i}{i}$\n\t\t\t\t\t\t\t\t\\item $\\dfrac{2-3i}{1+i}$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\n\n\n\\subsubsection{Euler's Identity}\nIt is possible to extend trigonometric and exponential functions (but not logarithms) to complex numbers.\nThese functions have the same derivatives and integrals as in the real case.\nThe following {\\bf Euler's Identity} establishes a deep connection between trigonometric and exponential functions.\n\\begin{theorem}[Euler's identity]\n\\begin{align*}\n\t\te^{i \\theta} = \\cos \\theta + i \\sin \\theta\n\\end{align*}\nfor all real numbers $\\theta$.\n\\end{theorem}\nThe proof of this theorem requires us to extend the entire theory of calculus to complex numbers (called complex analysis) and is beyond the scope of this class.\nWe'll simply use it as a fast method of (re)deriving several trig identities, and later on for doing integrals computations.\n\n\\begin{example}\n\tWe know that\n\t\\begin{align*}\n\t\t&& e^{i \\theta} \\cdot e^{-i \\theta} &= e^0\n\t\\end{align*}\n\tSimplifying the left hand side we get,\n\t\\begin{align*}\n\t\t\\Rightarrow\n\t\t&&\n\t\t(\\cos \\theta + i \\sin \\theta) \\cdot (\\cos (-\\theta) + i \\sin (-\\theta)) &= e^0  \\\\\n\t\t\\Rightarrow\n\t\t&&\n\t\t(\\cos \\theta + i \\sin \\theta) \\cdot (\\cos \\theta - i \\sin \\theta) &= 1  \\\\\n\t\t\\Rightarrow &&\n\t\t\\cos^2 \\theta + \\sin^2 \\theta\n\t\t&= 1 & \\mbox{ by \\eqref{q:complex_conjugate}}\n\t\\end{align*}\n\twhich is the fundamental identity of trigonometric functions.\n\t(In the above derivation we used the fact that $\\cos(-\\theta) = \\cos \\theta$ and $\\sin (-\\theta) = - \\sin \\theta$.)\n\\end{example}\n\n\\begin{exercise}\n\tUsing Euler's identity and\n\t\\begin{align*}\n\t\t\\left(e^{i \\theta}\\right)^2 = e^{2i \\theta}\n\t\\end{align*}\n\tfind the formulae for $\\cos 2 \\theta$ and $\\sin 2 \\theta$. (These are called the {\\bf double angle formulae}.)\n\\end{exercise}\n\n\\begin{exercise}\n\t\\begin{enumerate}\n\t\t\\item\n\t\tUsing Euler's identity and\n\t\t\\begin{align*}\n\t\t\te^{i x} \\cdot e^{i y}  = e^{i (x + y)}\n\t\t\\end{align*}\n\t\tfind the formulae for $\\cos (x + y)$ and $\\sin (x + y)$.\n\t\t\\item\n\t\tUsing Euler's identity and\n\t\t\\begin{align*}\n\t\t\te^{i x} \\cdot e^{-i y}  = e^{i (x - y)}\n\t\t\\end{align*}\n\t\tfind the formulae for $\\cos (x - y)$ and $\\sin (x - y)$.\n\t\\end{enumerate}\n\\end{exercise}\n\n\n\\begin{exercise}\n\tUsing the previous exercise, show that\n \\begin{align*}\n\t\t 2 \\cos x \\cos y &= \\cos (x-y) + \\cos(x+y) \\\\\n\t 2 \\sin x \\sin y &= \\cos (x-y) - \\cos(x+y)\\\\\n\t\t2 \\sin x \\cos y &= \\sin (x-y) + \\sin(x+y)\n \\end{align*}\n\\end{exercise}\n\nWe'll now apply these identities to compute some definite integrals.\nIn later sections, we'll use these to compute indefinite integrals  such as $\\int e^{ax} \\sin {bx} \\: dx$.\n\n\\begin{exercise}\n\tLet $n$ be an integer.\n\t\\begin{enumerate}\n\t\t\\item Draw graphs of\n\t\t\\begin{align*}\n\t\t\t\\sin x, \\sin (-x), \\sin 2x, \\sin (-2x), \\\\\n\t\t\t\\cos x, \\cos (-x), \\cos 2x, \\cos (-2x),\n\t\t\\end{align*} for $ -\\pi \\le x \\le \\pi$.\n\t\t\\item Geometrically argue that\n\t\t\\begin{align*}\n\t\t\t\\int_{-\\pi}^{\\pi} \\cos (nt) \\: dt &=\n\t\t\t\\begin{cases}\n\t\t\t\t0 & \\mbox{ if } n \\neq 0 \\\\\n\t\t\t\t2 \\pi & \\mbox{ if } n = 0\n\t\t\t\\end{cases}\n\t\t\\end{align*}\n\t\t\\item Geometrically argue that\n\t\t\\begin{align*}\n\t\t\t\\int_{-\\pi}^{\\pi} \\sin (nt) \\: dt &= 0\n\t\t\\end{align*}\n\t\t\\item Why do we need to make two cases for $\\cos x$ but not for $\\sin x$?\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tLet $m$ and $n$ be positive integers. Using the previous two exercises, show that\n\t\t\\begin{align*}\n\t\t\t \\int_{-\\pi}^{\\pi} \\cos (nt) \\cos (mt) \\: dt\n\t\t\t &=\n\t\t\t \\begin{cases}\n\t\t\t \t0 & \\mbox{ if } m \\neq n \\\\\n \t\t\t \t\\pi & \\mbox{ if } m = n\n\t\t\t \\end{cases} \\\\\n\t\t\t \\int_{-\\pi}^{\\pi} \\sin (nt) \\sin (mt) \\: dt\n\t\t\t &=\n\t\t\t \\begin{cases}\n\t\t\t\t0 & \\mbox{ if } m \\neq n \\\\\n\t\t\t\t\\pi & \\mbox{ if } m = n\n\t\t\t \\end{cases} \\\\\n\t\t\t \\int_{-\\pi}^{\\pi} \\cos (nt) \\sin (mt) \\: dt\n\t\t\t &=\n\t\t\t 0\n\t\t\\end{align*}\n\\end{exercise}\nThese integrals are the foundational identities for Fourier analysis, which is one of the most powerful mathematical theories emerging out of elementary calculus.\n\n\n% \\begin{exercise} Verify that\n% \t\\begin{align*}\n% \t\t\t\\cos \\theta &= \\dfrac{e^{i \\theta} + e^{-i \\theta}}{2} \\\\\n% \t\t\t\t\t\\sin \\theta &= \\dfrac{e^{i \\theta} - e^{-i \\theta}}{2i}\n% \t\\end{align*}\n% \\end{exercise}\n%\n% \\begin{exercise}\n% \tCompute the indefinite integrals\n% \t\\begin{align*}\n% \t\t\\int\n% \t\\end{align*}\n% \\end{exercise}\n", "meta": {"hexsha": "19516f66dfdfd3bcd966231e49df558f89acf4d7", "size": 12444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2018/08TrigExpLog.tex", "max_stars_repo_name": "apurvnakade/jhu2017-18-honors-single-variable-calculus", "max_stars_repo_head_hexsha": "5b6cb3dde364990abe868ce155a697dce78302fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2018/08TrigExpLog.tex", "max_issues_repo_name": "apurvnakade/jhu2017-18-honors-single-variable-calculus", "max_issues_repo_head_hexsha": "5b6cb3dde364990abe868ce155a697dce78302fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2018/08TrigExpLog.tex", "max_forks_repo_name": "apurvnakade/jhu2017-18-honors-single-variable-calculus", "max_forks_repo_head_hexsha": "5b6cb3dde364990abe868ce155a697dce78302fa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5837563452, "max_line_length": 234, "alphanum_fraction": 0.6406300225, "num_tokens": 4255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7452518934168287}}
{"text": "\\documentclass[12pt, letterpaper, onside]{article}\n\\usepackage[affil-it]{authblk} % author institution\n\\usepackage{amsmath} % math\n\\usepackage{amssymb} % math symbol\n\\usepackage[backend=biber]{biblatex}\n\\usepackage{graphicx}\n\n\\addbibresource{reference.bib}\n\n\\newtheorem{definition}{Definition}[section]\n\\newtheorem{theorem}{Theorem}[section]\n\n\\newcommand\n{\\point}\n[1]\n{\\left(#1\\right)}\n\n\\newcommand\n{\\twoFunc}\n[1]\n{#1\\point{x, y}}\n\n\\newcommand\n{\\derv}\n{\\mathrm{d}}\n\n\\newcommand\n{\\fd} % [f]irst [d]erivative\n[3]\n{\\frac{\\derv#1}{\\derv#2}\\point{#3}}\n\n\\newcommand\n{\\sd} % [s]econd [d]erivative\n[3]\n{\\frac{\\derv^{2}#1}{\\derv#2^{2}}\\point{#3}}\n\n\\newcommand\n{\\fpd} % [f]irst [p]artial [d]erivative\n[3]\n{\\frac{\\partial{#1}}{\\partial{#2}}\\point{#3}}\n\n\\newcommand\n{\\spd} % [s]econd [p]artial [d]erivative\n[4]\n{\\frac{\\partial}{\\partial{#3}} \\left(\\frac{\\partial{#1}}{\\partial{#2}}\\right) \\point{#4}}\n\n\\newcommand\n{\\appCon} % h and k approach condition\n[2]\n{\\text{if } h \\to 0^{#1} \\text{ and } k \\to 0^{#2}}\n\n\\newcommand\n{\\counterFunc}\n{\n\\begin{equation*}\n    \\twoFunc{f} = \n    \\begin{cases}\n        \\twoFunc{\\phi} & \\text{if }x = 2y\\text{,}\\\\\n        \\twoFunc{\\psi} & \\text{otherwise}\\text{;}\n    \\end{cases}\n\\end{equation*}\nwhere\n\\begin{align*}\n    \\twoFunc{\\phi} &= x^{2} + y^{2} - 8x - 4y + 10\\text{,}\\\\\n    \\twoFunc{\\psi} &= x^{2} + y^{2} - 4x - 2y\n\\end{align*}\n}\n\n\\newcommand\n{\\mat}\n[1]\n{\\mathrm{#1}}\n\n\\newcommand\n{\\df} % [d]irectional [f]unction\n[1]\n{\\xi_\\vec{#1}}\n\n\\newcommand\n{\\R}\n{\\mathbb{R}}\n\n\\newcommand\n{\\itvec} % [i]nline 2d [vec]tor *inkscape*\n[2]\n{\\left[\\begin{array}{c}#1\\\\#2\\end{array}\\right]}\n\n\\newcommand\n{\\dirgraph} % [d]irection annotation for [graph] at (x, y) = (2, 1) *inkscape*\n[2]\n{\\itvec{x}{y} = \\itvec{2}{1} + k\\itvec{#1}{#2}}\n\n\\newcommand\n{\\hess}\n{\\mathrm{Hess} \\ f_{\\point{2, 1}}}\n\n\\newcommand\n{\\hessDet}\n{\\lvert\\hess\\rvert}\n\n\\renewcommand{\\vec}{\\mathbf}\n\\renewcommand{\\Rn}{\\mathbb{R}^n}\n\n\\title{\\textbf{Ridge Problem in Stochastic Gradient Descent: An Analytical Solution}}\n\\author{Tran Phong Binh\\thanks{Email: \\texttt{phongbinh2511@gmail.com}}}\n\\affil{Department of Computer Science, National Tsing Hua University}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\n% TODO\n\\end{abstract}\n\n\\section{Introduction}\nThe second partial derivative test is a renowed technique for determining local extremum points. This mathematical method had been well studied since the beginning era of calculus, and has been used extensively both in the academia and in real-world applications. Yet, upon studying the ridge problem of hill climbing\\cite{ridge}, we stumbled on a thought that the same issue could present in the forementioned test under a stochastic space setup.\n\nIn this work, we prove that such problem exists, proposing an analytical solution, and check our approach on two multivariable functions. We hope our finding further pushes knowledge boundaries of stochastic gradient descent in specific, and optimization in general. With this, researchers and practitioners can now surpass false local extremum points to navigate down true local optimization objectives, consolidating the robustness of their theories and systems.\n\n\\section{Proof}\nWe prove that ridge problem presents in the second partial derivative test by analyzing the multivariable function\n\\counterFunc\nat point $\\point{2, 1}$.\n\n\\subsection{First Partial Derivatives}\nWe begin by examining the first derivatives of $f$ at point $\\point{2, 1}$. Firstly, it is given that\n\\begin{equation*}\n    \\fpd{f}{x}{2, 1} = \\lim_{h \\to 0}{\\frac{f\\point{2 + h, 1} - f\\point{2, 1}}{h}}\\text{.}\n\\end{equation*}\nBecause the components on the numerator are\n\\begin{align*}\n    f\\point{2 + h, 1} & = \\psi\\point{2 + h, 1}\\text{,}\\\\\n        f\\point{2, 1} & = \\phi\\point{2, 1}\\\\\n                      & = -5\\\\\n                      & = \\psi\\point{2, 1}\\text{,}\n\\end{align*}\nit holds that\n\\begin{align}\n    \\label{eq:proveSpd} % [prove] [s]econd [p]artial [d]erivatives\n    \\fpd{f}{x}{2, 1} & = \\fpd{\\psi}{x}{2, 1}\\\\\n                     & = 2x - 4\\nonumber\\\\\n                     & = 0\\text{.}\\nonumber\n\\end{align}\nSimilarly,\n\\begin{align*}\n    \\fpd{f}{y}{2, 1} & = \\fpd{\\psi}{y}{2, 1}\\\\\n                     & = 2y - 2\\\\\n                     & = 0\\text{.}\n\\end{align*}\nHence\n\\begin{equation}\n    \\label{zeroGradient}\n    \\nabla_{f}\\point{2, 1} =\n    \\begin{bmatrix}\n        0\\\\\n        0\n    \\end{bmatrix}\\text{.}\n\\end{equation}\n\n\\subsection{Second Partial Derivatives}\nWe then consider the second partial derivatives of our function at the same point.\n\n\\subsubsection{Second Partial Derivative With Respect To $x$}\nWe start with $f_{xx}\\point{2, 1}$:\n\\begin{equation}\n    \\label{eq:fxxDef}\n    \\spd{f}{x}{x}{2, 1} = \\lim_{h \\to 0}{\\frac{\\fpd{f}{x}{2 + h, 1} - \\fpd{f}{x}{2, 1}}{h}}\\text{.}\n\\end{equation}\nAssessing the first component of the numerator\n\\begin{equation*}\n    \\fpd{f}{x}{2 + h, 1} = \\lim_{k \\to 0}{\\frac{f\\point{2 + h + k, 1} - f\\point{2 + h, 1}}{k}}\\text{,}\n\\end{equation*}\nwe observe that\n\\begin{align*}\n    f\\point{2 + h + k, 1} & =\n    \\begin{cases}\n        \\psi\\point{2 + h + k, 1} & \\appCon{-}{-}\\text{,}\\\\\n        \\phi\\point{2, 1} = -5 = \\psi\\point{2, 1} & \\appCon{-}{+}\\text{,}\\\\\n        \\phi\\point{2, 1} = -5 = \\psi\\point{2, 1} & \\appCon{+}{-}\\text{,}\\\\\n        \\psi\\point{2 + h + k, 1} & \\appCon{+}{+}\n    \\end{cases}\\\\\n    & = \\psi\\point{2 + h + k, 1}\\text{,}\n\\end{align*}\nand\n\\begin{equation*}\n    f\\point{2 + h, 1} = \\psi\\point{2 + h, 1}\\text{.}\n\\end{equation*}\nTherefore, our first entry of the forementioned numerator\n\\begin{equation}\n    \\label{eq:proveFxx}\n    \\fpd{f}{x}{2 + h, 1} = \\fpd{\\psi}{x}{2 + h, 1}\\text{.}\n\\end{equation}\nBy equations \\ref{eq:proveSpd} and \\ref{eq:proveFxx}, our equation \\ref{eq:fxxDef} becomes\n\\begin{align*}\n    \\spd{f}{x}{x}{2, 1} & = \\spd{\\psi}{x}{x}{2, 1}\\\\\n                        & = 2\\text{.}\n\\end{align*}\n\n\\subsubsection{Second Partial Derivative With Respect To $x$ Then $y$}\nWe continue by examining $f_{yx}\\point{2, 1}$:\n\\begin{equation}\n    \\label{eq:fyxDef}\n    \\spd{f}{x}{y}{2, 1} = \\lim_{h \\to 0}{\\frac{\\fpd{f}{x}{2, 1 + h} - \\fpd{f}{x}{2, 1}}{h}}\\text{.}\n\\end{equation}\nAgain, we assess the first component of the numerator\n\\begin{equation*}\n    \\fpd{f}{x}{2, 1 + h} = \\lim_{k \\to 0}{\\frac{f\\point{2 + k, 1 + h} - f\\point{2, 1 + h}}{k}}\\text{.}\n\\end{equation*}\nAnalogous to $f_{xx}\\point{2, 1}$, we learn that\n\\begin{align*}\n    f\\point{2 + k, 1 + h} & =\n    \\begin{cases}\n        \\psi\\point{2 + k, 1 + h} & \\appCon{-}{-}\\text{,}\\\\\n        \\psi\\point{2 + k, 1 + h} & \\appCon{-}{+}\\text{,}\\\\\n        \\psi\\point{2 + k, 1 + h} & \\appCon{+}{-}\\text{,}\\\\\n        \\psi\\point{2 + k, 1 + h} & \\appCon{+}{+}\n    \\end{cases}\\\\\n    & = \\psi\\point{2 + k, 1 + h}\\text{,}\n\\end{align*}\nand\n\\begin{equation*}\n    f\\point{2, 1 + h} = \\psi\\point{2, 1 + h}\\text{.}\n\\end{equation*}\nThus\n\\begin{equation}\n    \\label{eq:proveFyx}\n    \\fpd{f}{x}{2, 1 + h} = \\fpd{\\psi}{x}{2, 1 + h}\\text{.}\n\\end{equation}\nBy equations \\ref{eq:proveSpd} and \\ref{eq:proveFyx}, our equation \\ref{eq:fyxDef} becomes\n\\begin{align*}\n    \\spd{f}{x}{y}{2, 1} & = \\spd{\\psi}{x}{y}{2, 1}\\\\\n                        & = 0\\text{.}\n\\end{align*}\n\n\\subsubsection{Hessian Matrix}\nPerforming similar deductions for $f_{xy}\\point{2, 1}$ and $f_{yy}\\point{2, 1}$, we get\n\\begin{align*}\n    f_{xx}\\point{2, 1} & = 2\\text{,}\\\\\n    f_{yx}\\point{2, 1} & = 0\\text{,}\\\\\n    f_{xy}\\point{2, 1} & = 0\\text{,}\\\\\n    f_{yy}\\point{2, 1} & = 2\\text{.}\n\\end{align*}\nAs a result, the Hessian determinant at point $\\point{2, 1}$\n\\begin{align*}\n    \\hessDet & = f_{xx}\\point{2, 1}f_{yy}\\point{2, 1} - f_{yx}\\point{2, 1}f_{xy}\\point{2, 1}\\\\\n      & = 4\\text{.}\n\\end{align*}\nSince $f_{xx}\\point{2, 1} > 0$ and $\\hessDet > 0$,\n\\begin{equation}\n    \\label{positiveDetH}\n    \\hess \\succ 0\\text{.}\n\\end{equation}\n\n\\subsection{Second Partial Derivative Test Contradiction}\nAccording to \\cite{secondDerivativeTest}, by equations \\ref{zeroGradient} and \\ref{positiveDetH}, we shall conclude $(2, 1)$ is a local minimum point. However, this is incorrect, as for $h \\in \\R$, $h \\to 0^{+}$:\n\\begin{align}\n    f\\point{2 + 2h, 1 + h} & = \\phi\\point{2 + 2h, 1 + h}\\\\\n                           & < \\phi\\point{2, 1} = f\\point{2, 1}\n\\end{align}\nThat is, $\\point{2, 1}$ is not a local minimum point (proof in appendix). % TODO appendix\n\n\\section{Intuition}\n\\begin{figure}[h]\n    \\centering\n    \\def\\svgwidth{0.6\\textwidth}\n    \\input{f_graph.pdf_tex}\n    \\caption{Partial graph of the function $\\twoFunc{f}$}\n    \\label{fig:f}\n\\end{figure}\n\nConsidering our function's graph depicted in Figure \\ref{fig:f} at point $\\point{2, 1}$, we observe that the first derivatives in the $x$ and $y$ directions are zeroes, making the zero gradient. Furthermore, the curvature of the function is up in all directions at the point of interest, indicating the positive definite Hessian. With this premise, the second partial derivative test concludes that $\\point{2, 1}$ is a local minimum point.\n\nHowever, this is analytically and visually false. Even though the curvature along the $\\vec{v} = \\point{4, 2}$ direction is up, the corresponding first derivative differs from zero, invalidating the second partial derivative test.\n\n\\section{Solution}\nFor the tangent hyperplane of a multivariable function at a point to be flat, it is not enough for the gradient of the function at that point to be the zero vector, but the first derivatives of the function at the point of interest must equal to zero in all directions.\n\nIn this work, we provide an analytical solution to this issue by redefining what it takes for the tangent hyperplane of a function at a point to be flat. Firstly, we define the concept of directional function:\n\\begin{definition}\n    Given a multivariable function\n    \\begin{align*}\n        f \\colon \\Rn & \\longrightarrow \\R\\\\\n                        \\vec{x} & \\longmapsto f\\point{\\vec{x}}\n    \\end{align*}\n    where $\\vec{x} = \\point{x_{1}, x_{2}, \\dots, x_{n}}$. For a direction\\footnote{We exclude the vector $\\vec{0}$ from all of our discussions on directional function.} $\\vec{v} \\in \\Rn$, the directional function of $f$ at point $\\vec{x_{0}}$ is the single variable function\n    \\begin{align*}\n        \\df{v} \\colon \\R & \\longrightarrow \\R\\\\\n                                    k & \\longmapsto f\\point{\\vec{x_{0}} + k\\vec{v}}\n    \\end{align*}\n\\end{definition}\nWe are now ready to redefine flat tangent hyperplane:\n\\begin{definition}\n    Given a multivariable function $f$, its tangent hyperplane is flat at point $\\vec{x_{0}}$ iff for all directions $\\vec{v} \\in \\Rn$, the directional function $\\df{v}$ at that point has zero first derivative at $k = 0$ i.e.\\ iff $\\forall \\vec{v} \\in \\Rn \\colon \\fd{\\df{v}}{k}{0} = 0$.\n\\end{definition}\nFrom this definition, we can derive our new local mininimum test:\n\\begin{theorem}\n    \\label{th:localMin}\n    Given a multivariable function $f$, if its tangent hyperplane is flat at point $\\vec{x_{0}}$, and for all directions $\\vec{v} \\in \\Rn$, the directional function $\\df{v}$ at that point has positive second derivative at $k = 0$ i.e.\\ if $\\forall \\vec{v} \\in \\Rn \\colon \\fd{\\df{v}}{k}{0} = 0 \\land \\sd{\\df{v}}{k}{0} > 0$, then $\\vec{x_{0}}$ is a local minimum point.\n\\end{theorem}\n\n\\subsection{False Local Minimum}\nWe revisit our first example to see if the test works:\n\\counterFunc\nFor the direction $\\vec{v} = \\point{4, 2}$, our directional function at $\\vec{x_{0}} = \\point{2, 1}$ is\n\\begin{align}\n    \\df{v}\\point{k} & = f\\point{\\vec{x_{0}} + k\\vec{v}}\\\\\n    & = f\\point{\n    \\begin{bmatrix}\n        2\\\\\n        1\n    \\end{bmatrix}\n    + k\n    \\begin{bmatrix}\n        4\\\\\n        2\n    \\end{bmatrix}\n    }\\\\\n    & = f\\point{\n    \\begin{bmatrix}\n        2 + 4k\\\\\n        1 + 2k\n    \\end{bmatrix}\n    } \\text{ or } f\\point{2 + 4k, 1 + 2k}\n\\end{align}\nSince $x = 2y$,\n\\begin{align}\n    \\df{v}\\point{k} & = \\phi\\point{2 + 4k, 1 + 2k}\\\\\n    & = \\left(2 + 4k\\right)^{2} + \\left(1 + 2k\\right)^{2} - 8\\left(2 + 4k\\right) - 4\\left(1 + 2k\\right) + 10\\\\\n    & = 4 + 16k + 16k^{2} + 1 + 4k + 4k^{2} - 16 - 32k - 4 - 8k + 10\\\\\n    & = 20k^{2} - 20k - 5\n\\end{align}\nWe examine the directional function's first derivative at $k = 0$:\n\\begin{align}\n    \\fd{\\df{v}}{k}{0} & = 40k - 20\\\\\n    & = -20 \\neq 0\n\\end{align}\nHence $\\vec{x_{0}} = (2, 1)$ is not a local minimum point!\n\n\\subsection{True Local Minimum}\nWe consolidate our test with the well-known function\n\\begin{equation}\n    f\\point{\\vec{x}} = \\vec{x}^{\\intercal}\\mat{A}\\vec{x}\n\\end{equation}\nwhere $\\underset{n \\times n}{\\mat{A}} \\succ 0$. For any directions $\\vec{v} \\in \\Rn$, our directional function at $\\vec{x_{0}} = \\vec{0}$ is\n\\begin{align}\n    \\df{v}\\point{k} & = f\\point{\\vec{x_{0}} + k\\vec{v}}\\\\\n    & = \\left(k\\vec{v}\\right)^{\\intercal}\\mat{A}\\left(k\\vec{v}\\right)\\\\\n    & = k^{2}\\vec{v}^{\\intercal}\\mat{A}\\vec{v}\n\\end{align}\nWe examine the directional function's first derivative at $k = 0$:\n\\begin{align}\n    \\fd{\\df{v}}{k}{0} & = 2k\\vec{v}^{\\intercal}\\mat{A}\\vec{v}\\\\\n    & = 0\n\\end{align}\nFurthermore,\n\\begin{equation}\n    \\sd{\\df{v}}{k}{0} = 2\\vec{v}^{\\intercal}\\mat{A}\\vec{v}\n\\end{equation}\nSince $\\mat{A} \\succ 0$, $\\forall \\vec{v} \\neq \\vec{0} \\colon \\vec{v}^{\\intercal}\\mat{A}\\vec{v} > 0$. Thus, our directional function's second derivative is positive. According to Theorem \\ref{th:localMin}, $\\vec{x_{0}} = \\vec{0}$ is a local minimum point!\n\n\\section{Conclusion}\n\n\\section{Future Work}\n\n\\printbibliography\n\n\\end{document}\n", "meta": {"hexsha": "eafd65fea0e707b24fb6d107d8fbd301a2285864", "size": 13410, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper.tex", "max_stars_repo_name": "phogbinh/ridge-gradient", "max_stars_repo_head_hexsha": "96354975dce421866d8367ed6bcf9e5adfd0c86f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper.tex", "max_issues_repo_name": "phogbinh/ridge-gradient", "max_issues_repo_head_hexsha": "96354975dce421866d8367ed6bcf9e5adfd0c86f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper.tex", "max_forks_repo_name": "phogbinh/ridge-gradient", "max_forks_repo_head_hexsha": "96354975dce421866d8367ed6bcf9e5adfd0c86f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.2432432432, "max_line_length": 464, "alphanum_fraction": 0.6224459359, "num_tokens": 4940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463333, "lm_q2_score": 0.8688267728417087, "lm_q1q2_score": 0.7452518818690826}}
{"text": "\\section{Homomorphisms}\r\n\\begin{definition}\r\n    For groups $G,H$, a map $\\phi:H\\to G$ is called a homomorphism $H\\to G$ if\r\n    $$\\phi(h_1h_2)=\\phi(h_1)\\phi(h_2)$$\r\n    for any $h_1,h_2\\in H$.\\\\\r\n    If $\\phi$ is a bijection as well, then it is called an isomorphism.\r\n    In this case, we say $G,H$ are isomorphic.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. For any $H,G$, the function $f$ defined by $f(h)=e$ for any $h\\in H$ is a homomorphism.\\\\\r\n    2. If $H\\le G$, the inclusion map is a homomorphism.\\\\\r\n    3. Let $n|m$, the map $z\\mapsto z^{m/n}$ is a homomorphism between $C_n\\to C_m$.\\\\\r\n    4. The exponential function $\\exp:\\mathbb R\\to\\mathbb R_{>0}$ is a homomorphism $(\\mathbb R,+,0)\\to(\\mathbb R_{>0},\\times,1)$.\\\\\r\n    5. The determinant function $\\det:\\operatorname{Gl}_n(\\mathbb R)\\to\\mathbb R\\setminus\\{0\\}$ under multiplication.\r\n\\end{example}\r\n\\begin{lemma}\r\n    If $\\phi:H\\to G$ is a homomorphism, then\\\\\r\n    1. $\\phi(e_H)=e_G$ where $e_H$ is the identity of $H$ and $e_G$ the identity of $G$.\\\\\r\n    2. $\\forall a\\in G,\\phi(a^{-1})=\\phi(a)^{-1}$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    1. Consider $e^2=e$ where $e$ is the identity of any group, so\r\n    $$\\phi(e_H)^2=\\phi(e_H^2)=\\phi(e_H)\\implies \\phi(e_H)=e_G$$\r\n    2. we have\r\n    $$e_G=\\phi(aa^{-1})=\\phi(a)\\phi(a^{-1})\\implies \\phi(a^{-1})=\\phi(a)^{-1}$$\r\n    as desired.\r\n\\end{proof}\r\nIt also follows easily from definitions that compositions of homomorphisms is a homomorphism.\r\n\\begin{definition}\r\n    Let $\\phi:H\\to G$ be a homomorphism, then the image of $\\phi$ is defined as\r\n    $$\\operatorname{Im}\\phi=\\{g\\in G:\\exists h\\in H, \\phi(h)=g\\}$$\r\n    The kernel of $\\phi$ is defined as\r\n    $$\\ker\\phi=\\{h\\in H:\\phi(h)=e_G\\}$$\r\n    where $e_G$ is the identity of $G$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    $\\operatorname{Im}\\phi\\le G,\\ker\\phi\\le H$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    For the first part, suppose that $a,b\\in\\operatorname{Im}\\phi$, then suppose that $\\phi(h_1)=a,\\phi(h_2)=b$, we have $ab^{-1}=\\phi(h_1h_2^{-1})\\in\\operatorname{Im}\\phi$.\\\\\r\n    For the second part, suppose $a,b\\in\\ker\\phi$, then $\\phi(ab^{-1})=e_Ge_G^{-1}=e_G$ where $e_G$ is the identity of $G$.\r\n    So $ab^{-1}\\in\\ker\\phi$.\\\\\r\n    It is also immediate that both of them are nonempty, as $e_H\\in\\ker\\phi,e_G\\in\\operatorname{Im}\\phi$.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    A homomorphism is an isomorphism if and only if its kernel is the subgroup consisting of only the idenity of the domain and that its image is the entire codomain.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Take a homomorphism $\\phi: H\\to G$.\r\n    If it is an isomorphism then the condition is immediate.\\\\\r\n    Conversely, since $\\operatorname{Im}\\phi=G$, $\\phi$ is surjective.\r\n    At the same time, if $\\phi(h_1)=\\phi(h_2)$ for some $h_1,h_2\\in H$, then\r\n    $$\\phi(h_1h_2^{-1})\\in\\ker\\phi\\implies h_1h_2^{-1}=e_H\\implies h_1=h_2$$\r\n    where $e_H$ is the identity of $H$.\r\n    So it is also injective, it follows that it is a bijection, therefore it is an isomorphism.\r\n    \\footnote{Alternatively, like the lecturer did, we can construct an explicit inverse, which is not as clean as this approach in the author's opinion.}\r\n\\end{proof}\r\nNote as well that an inverse of an isomorphism is again an isomorphism.\r\nThe proof to this is trivial.", "meta": {"hexsha": "b0cf13a2e341a58b12734c7a404b45ca7c84a874", "size": 3288, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/morphism.tex", "max_stars_repo_name": "david-bai-notes/IA-Groups", "max_stars_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3/morphism.tex", "max_issues_repo_name": "david-bai-notes/IA-Groups", "max_issues_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3/morphism.tex", "max_forks_repo_name": "david-bai-notes/IA-Groups", "max_forks_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.7288135593, "max_line_length": 176, "alphanum_fraction": 0.6484184915, "num_tokens": 1155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463333, "lm_q2_score": 0.8688267728417087, "lm_q1q2_score": 0.7452518818690826}}
{"text": "\\section{Order of Magnitude and Taylor's Theorem}\r\n\\subsection{Asymptopic Behaviour}\r\nWhen we want to analyze the difference between functions, apart from their analytical properties, we would also be interested in the difference between their magnitudes.\r\nThe following notion arrives to serve this purpose\r\n\\begin{definition}[Little-$o$ notation]\r\n    Let $f, g$ be real functions and $x_0\\in\\bar{\\mathbb R}=\\mathbb R\\cup\\{\\pm\\infty\\}$, we say that $f(x)=o(g(x))$ as $x\\to x_0$ if\r\n    $$\\lim_{x\\to x_0}\\frac{f(x)}{g(x)}=0$$\r\n\\end{definition}\r\n\\begin{definition}[Big-$O$ notation]\r\n    Let $f, g$ be real functions and $x_0\\in\\mathbb R$, we say that $f(x)=O(g(x))$ as $x\\to x_0$ if $\\exists\\delta,M>0$ such that\r\n    $$|x-x_0|<\\delta\\implies |f(x)|\\le M|g(x)|$$\r\n    We say $f(x)=O(g(x))$ as $x\\to\\infty$ if $\\exists x_1,M>0$ such that\r\n    $$x>x_1\\implies |f(x)|\\le M|g(x)|$$\r\n    We say $f(x)=O(g(x))$ as $x\\to-\\infty$ if $\\exists x_1<0,M>0$ such that\r\n    $$x<x_1\\implies |f(x)|\\le M|g(x)|$$\r\n\\end{definition}\r\n\\begin{remark}\r\n    Remember that the equality sign of $f(x)=o(g(x))$ or $f(x)=O(g(x))$ is not really the usual equality sign we use.\r\n    It is more like $f(x)\\in o(g(x))$ or $f(x)\\in O(g(x))$, meaning that $f$ is one of those functions having this property on its magnitude.\r\n    The reason why we use the equality sign here is that we sometimes use the notations to denote \\textit{some} functions having this property, which we do not (need to) know any detail except its magnitude.\r\n\\end{remark}\r\n\\begin{example}\r\n    We have $x^2=o(x)$ as $x\\to0$ and $x^2=O(x)$ as $x\\to0$. In fact, whenever $f(x)=o(g(x))$ as $x\\to x_0$ we have $f(x)=O(g(x))$ as $x\\to x_0$ as well. The proof again is just checking definitions.\r\n\\end{example}\r\nNow, one of the most significant usage of the measurement of magnitude is that we can use it to approximate the rest of the terms in a series.\r\nFor example, if we take the series $1+x+x^2+x^3+\\ldots$, we can replace it by $1+x+x^2+x^3+o(x^3)$, in which way one can include information about the magnitude of the error term of the series.\r\n\\subsection{Taylor Series}\r\nThe idea of the Taylor series is to locally approximate a smooth enough function by polynomials.\r\nSurely, most functions have much worse analytical properties then polynomials, making it slightly problematic to analyze some of their properties.\r\nTaylor series provides a solution.\r\nBasically, we start by assuming a local approximation of the function by a polynomial.\r\nSay $f(x)\\approx a_0+a_1x+a_2x^2+\\cdots+a_nx^n$, then, by differentiating both sides recursively, we immediately have $a_n=f^{(n)}(0)/n!$.\r\nThe polynomial, which we will call $P_{n,0}(x)$, is called the Taylor polynomial.\r\nIn general, if we shift the polynomial by $x_0$, we have the general form:\r\n\\begin{definition}\r\n    The Taylor polynomial $P_{n,x_0}(x)$ of a function $f$ around a point $x_0$ is the polynomial\r\n    $$\\sum_{k=0}^{n}\\frac{f^{(k)}(x_0)(x-x_0)^k}{k!}$$\r\n\\end{definition}\r\nNow the big question is, we have (quite vaguely) obtained the form of the sequence of polynomials that looks as if it can approximate $f$ as $n$ is big enough.\r\nBut does it?\r\nObviously unless $f$ is a polynomial as well it has no chance that the polynomial will be equal to $f$, but what can we say about the magnitude of the error term?\r\nTaylor's theorem saves the day.\r\n\\begin{theorem}[Taylor's theorem]\r\n    Write $h=x-x_0$.\r\n\tProvided that $f^{(n+1)}$ exists, then\r\n    $$E_{n,x_0}(x)=f(x)-P_{n,x_0}(x)=O(h^{n+1})$$\r\n    as $h\\to 0$.\r\n\\end{theorem}\r\nActually $E_{n,x_0}=o(h^n)$ as $h\\to 0$ as well but the big-$O$ here is stronger.\r\n\\subsection{L'Hopital's Rule}\r\n\\begin{theorem}\r\n    If $f(x)$ and $g(x)$ are both differentiable at $x=x_0\\in\\bar{\\mathbb R}$, and that $f,g$ are both continuous at $x_0$ and $f(x_0)=g(x_0)=0$, then\r\n    $$\\lim_{x\\to x_0}\\frac{f(x)}{g(x)}=\\lim_{x\\to x_0}\\frac{f^\\prime(x)}{g^\\prime(x)}$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    The little-$o$ notations below are taken as $x\\to x_0$.\r\n    $$f(x)=f(x_0)+(x-x_0)f^\\prime(x_0)+o(x-x_0), g(x)=g(x_0)+(x-x_0)g^\\prime(x_0)+o(x-x_0)$$\r\n    by Taylor's theorem.\r\n    $$\\frac{f(x)}{g(x)}=\\frac{f^\\prime(x_0)+o(x-x_0)/(x-x_0)}{g^\\prime(x_0)+o(x-x_0)/(x-x_0)}\\to \\frac{f^\\prime(x_0)}{g^\\prime(x_0)}$$\r\n    as $x\\to x_0$.\r\n\\end{proof}\r\nNote that we can use L'Hopital's rule recursively given that the conditions still hold.\r\n", "meta": {"hexsha": "9eeeff7c219f444657d2d481c3d1d540805ef726", "size": 4374, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/taylor.tex", "max_stars_repo_name": "david-bai-notes/IA-Differential-Equations", "max_stars_repo_head_hexsha": "eba1ffe070fce235ce1c9611b23339c35c6d6931", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1/taylor.tex", "max_issues_repo_name": "david-bai-notes/IA-Differential-Equations", "max_issues_repo_head_hexsha": "eba1ffe070fce235ce1c9611b23339c35c6d6931", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1/taylor.tex", "max_forks_repo_name": "david-bai-notes/IA-Differential-Equations", "max_forks_repo_head_hexsha": "eba1ffe070fce235ce1c9611b23339c35c6d6931", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.4285714286, "max_line_length": 208, "alphanum_fraction": 0.674439872, "num_tokens": 1469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424528443251, "lm_q2_score": 0.8807970654616711, "lm_q1q2_score": 0.7451036300147297}}
{"text": "\\section{Additional Exercises}\\label{sec:MoreReviewExercises}\n\n\\Opensolutionfile{solutions}[ex]\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{enumialphparenastyle}\n\nThese problems require a comprehensive knowledge of the skills reviewed in\nthis chapter. They are not in any particular order. A proficiency in these\nskills will help you a long way as your learn the calculus material in the\nfollowing chapters.\n\n\\begin{multicols}{2}\n%%%%%%%%%%\n\\begin{ex}\nRationalize the denominator for each of the\nfollowing expressions. That is, re-write the expression in such a way that\nno square roots appear in the denominator. Also, simplify your answers if\npossible.\n\\begin{enumerate}\n\t\t\\item\t$\\dfrac{1}{\\sqrt{2}}$\n\t\\item\t$\\dfrac{3h}{\\sqrt{x+h+1}-\\sqrt{x+1}}$\n\\end{enumerate}\n\\begin{sol}\n\\begin{enumerate}\n\t\\item\t$\\dfrac{\\sqrt{2}}{2}$\n\t\\item\t$3(\\sqrt{x+h+1}+\\sqrt{x+1})$\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nSolve the following equations.\n\\begin{enumerate}\n\t\t\\item\t$2-5(x-3)=4-10x$\n\t\\item\t$2x^2-5x=3$\n\t\\item\t$x^2-x-3=0$\n\t\\item\t$x^2+x+3=0$\n\t\\item\t$\\sqrt{x^2+9}=2x$\n\\end{enumerate}\n\\begin{sol}\n\\begin{enumerate}\n\t\\item\t$-13/5$\n\t\\item\t$-1/2,3$\n\t\\item\t$(1\\pm\\sqrt{13})/2$\n\t\\item\tNo real solutions\n\t\\item\t$\\sqrt{3}$\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nBy means of counter-examples, show why it is wrong\nto say that the following equations hold for all real numbers for which the\nexpressions are defined.\n\\begin{enumerate}\n\t\t\\item\t$(x-2)^2=x^2-2^2$\n\t\\item\t$\\dfrac{1}{x+h}=\\dfrac{1}{x}+\\dfrac{1}{h}$\n\t\\item\t$\\sqrt{x^2+y^2}=x+y$\n\\end{enumerate}\n\\begin{sol}\nCounter-examples may vary.\n\\begin{enumerate}\n\t\\item\t$x=3$\n\t\\item\t$x=h=1$\n\t\\item\t$x=y=1$\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nFind an equation of the line passing through the\npoint $(-2,5)$ and parallel to the line $x+3y-2=0$.\n\\begin{sol}\n\t$x+3y-13=0$, or equivalents such as $y=-\\frac{1}{3}x+\\frac{13}{3}$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nSolve $\\dfrac{x^2-1}{3x-1}\\leq 1$.\n\\begin{sol}\n\t$(-\\infty,0]\\cup(\\frac{1}{3},3]$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nExplain why the following expression never\nrepresents a real number (for any real \\\\\nnumber $x$). \\\\\n$$\\sqrt{x-2}+\\sqrt{1-x}$$\n\\begin{sol}\n\tIt is impossible for both $x-2$ and $1-x$ to be non-negative\n\tfor the same real number $x$.\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nSimplify the expression \\\\\n$$\\dfrac{\\left( \\, 3(x+h)^2+4 \\, \\right)-\\left( \\, 3x^2+4 \\, \\right) }{h}$$ \n as much as possible.\n\\begin{sol}\n\t$6x+3h$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nSimplify the expression \\\\\n$$\\ds{\\frac{\\frac{x+h}{2(x+h)-1}-\\frac{x}{2x-1}}{h}}$$\n as much as possible.\n\\begin{sol}\n\t$-1/\\left[(2x+2h-1)(2x-1)\\right]$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nSimplify the expression \\\\\n$$\\ds{-\\sin x(\\cos x+3\\sin x)-\\cos x(-\\sin x+3\\cos x)}$$\n\\begin{sol}\n\t$-3$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nSolve the equation $\\,\\, \\cos x=\\frac{\\sqrt{3}}{2}$ on\nthe interval $0\\leq x\\leq 2\\pi$.\n\\begin{sol}\n\t$\\pi /6,$ $5\\pi /6$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nFind an angle $\\theta$ such that $0\\leq\\theta\\leq\\pi$ and $\\cos\\theta=\\cos\\frac{38\\pi}{5}$.\n\\begin{sol}\n\t$2\\pi/5$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nWhat can you say about \\\\\n$$\\ds{\\dfrac{\\left\\vert x\\right\\vert+\\left\\vert 4-x\\right\\vert}{x-2}} $$\n when $x$ is a large\n(positive) number?\n\\begin{sol}\n\tIt is equal to 2 for all $x$ larger than 4.\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nFind an equation of the circle with centre at $(-2,3)$ and passing through the point $(1,-1)$.\n\\begin{sol}\n\t$(x+2)^2+(y-3)^2=25$.\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nFind the centre and radius of the circle described\nby $\\,\\,x^2+y^2+6x-4y+12=3$.\n\\begin{sol}\n\tCentre is $(-3,2)$ and radius is 2.\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nIf $y=9x^2+6x+7$, find all possible values of $y$.\n\\begin{sol}\n\t$y$ could be any real number greater than or equal to 6.\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nSimplify $\\left(\\dfrac{3x^2 y^3 z^{-1}}{18x^{-1}yz^3}\\right)^2$.\n\\begin{sol}\n\t$x^6 y^4/(36z^8)$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nIf $y=\\dfrac{3x+2}{1-4x}$, then what is $x$ in\nterms of $y$?\n\\begin{sol}\n\t$x=(y-2)/(3+4y)$\n\\end{sol}\n\\end{ex}\n\n\\vfill \\null\n\\columnbreak\n%%%%%%%%%%\n\\begin{ex}\nDivide $x^2+3x-5$ by $x+2$ to obtain the\nquotient and the remainder. Equivalently, find polynomial $Q(x)$\nand constant $R$ such that\n\\[\\frac{x^2+3x-5}{x+2}=Q(x)+\\frac{R}{x+2}.\\]\n\\begin{sol}\n\t$Q(x)=x+1$, $R=-7$\n\\end{sol}\n\\end{ex}\n\n\\end{multicols}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "141ac03eb2ae966eef2d0fe3536d452ef35e710c", "size": 4515, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1-review/1-4-additional-exercises.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1-review/1-4-additional-exercises.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1-review/1-4-additional-exercises.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.8064516129, "max_line_length": 94, "alphanum_fraction": 0.6141749723, "num_tokens": 1786, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778825, "lm_q2_score": 0.8459424334245617, "lm_q1q2_score": 0.7451036234978533}}
{"text": "\\section{Basically a recap of what we did last time}\nPSet 1 due today. Last time, we showed:\n\\begin{theorem}\nThere exists a map $S_p(X)\\times S_q(Y)\\to S_{p+q}(X\\times Y)$ that is:\n\t\\begin{itemize}\n\t\\item Natural, in the sense that if $f:X\\to X^\\prime$ and $g:Y\\to Y^\\prime$, and $a\\in S_p(X)$ and $b\\in S_p(Y)$ so that $a\\times b\\in S_{p+q}(X\\times Y)$, then $f_\\ast(a)\\times g_\\ast(b)=(f\\times g)_\\ast(a\\times b)$.\n\t\\item Bilinear, in the sense that $(a+a^\\prime)\\times b=(a\\times b)+(a^\\prime\\times b)$, and $a\\times (b+b^\\prime)=a\\times b+a\\times b^\\prime$.\n\t\\item The Leibniz rule is satisfied, i.e., $\\partial(a\\times b)=(\\partial a)\\times b + (-1)^{|a|}a\\times \\partial b$.\n\t\\item Normalized, in the following sense. Let $x\\in X$ and $y\\in Y$. Write $i_x:Y\\to X\\times Y$ sending $y\\mapsto (x,y)$, and write $i_y:X\\to X\\times Y$ sending $x\\mapsto (x,y)$. If $b\\in S_q(Y)$, then $c^0_x\\times b=(i_x)_\\ast b\\in S_q(X\\times Y)$, and if $a\\in S_p(X)$, then $a\\times c^0_y=(i_y)_\\ast a\\in S_p(X\\times Y)$.\n\t\\end{itemize}\n\\end{theorem}\nWe were a little hasty in the end, so we're going to recall some things.\n\\begin{proof}[Proof sketch]\nThere were two steps.\n\\begin{enumerate}\n\\item It's enough to define $\\iota_p\\times \\iota_q\\in S_{p+q}(\\Delta^p\\times \\Delta^q)$ where $\\iota_n:\\Delta^n\\to\\Delta^n$ is the identity, because every other simplex is $\\iota_n$ pushed forward, and the cross product is supposed to be natural.\n\\item Induction on $p+q$. The first thing we use is the Leibniz rule, namely $\\partial(\\iota_p\\times\\iota_q) = (\\partial\\iota_p)\\times\\iota_q + (-1)^p\\iota_p\\times\\partial\\iota_q$. Is this a boundary? A necessary thing for anything to be a boundary is that it's a cycle. But because $\\Delta^p\\times\\Delta^q$ is homeomorphic to a star-shaped region, it's contractible - therefore $ H_{p+q-1}(\\Delta^p\\times\\Delta^q)=0$, a \\emph{sufficient} condition for something to be a boundary is that it's a cycle! We showed that $\\partial(\\iota_p\\times\\iota_q)$ is a cycle, and therefore a boundary. We just need to choose \\emph{some} class $[a]$ in $S_{p+q}(\\Delta^p\\times\\Delta^q)$ such that $\\partial([a])=(\\partial\\iota_p)\\times\\iota_q + (-1)^p\\iota_p\\times\\partial\\iota_q$, and this works.\n\\begin{enumerate}\n\\item Naturality is left to the reader.\n\\item Let's check the Leibniz rule. Let $\\sigma:\\Delta^p\\to X$ and $\\tau:\\Delta^q\\to Y$. What's $\\partial(\\sigma\\times\\tau)$? We start by asking how we define $\\sigma\\times \\tau$. Well, this is just $\\sigma_\\ast\\iota_p\\times\\tau_\\ast\\iota_q$. Because of naturality, this is just $(\\sigma\\times\\tau)_\\ast(\\iota_p\\times\\iota_q)$. This means that $\\partial(\\sigma\\times\\tau)=\\partial((\\sigma\\times\\tau)_\\ast(\\iota_p\\times\\iota_q))$. Now, we can use the naturality of the boundary map to see that this is just $(\\sigma\\times\\tau)_\\ast\\partial(\\iota_p\\times\\iota_q)$, which we can expand as:\n\\begin{align*}\n(\\sigma\\times\\tau)_\\ast\\partial(\\iota_p\\times\\iota_q)& =(\\sigma\\times\\tau)_\\ast((\\partial\\iota_p)\\times\\iota_q + (-1)^p\\iota_p\\times\\partial\\iota_q) \\\\\n& = \\sigma_\\ast(\\partial\\iota_p)\\times\\tau_\\ast\\iota_q + (-1)^{p}(\\sigma_\\ast\\iota_p\\times\\tau_\\ast(\\partial\\iota_q))\\\\\n& = \\partial(\\sigma_\\ast\\iota_p)\\times\\tau_\\ast\\iota_q + (-1)^{p}(\\sigma_\\ast\\iota_p\\times\\partial(\\tau_\\ast\\iota_q))\\\\\n& = \\partial\\sigma\\times\\tau + (-1)^{p}\\sigma\\times\\partial\\tau\n\\end{align*}\n\\end{enumerate}\n\\end{enumerate}\n\\end{proof}\nA key fact in this whole thing is that $ H_{p+q-1}(\\Delta^p\\times\\Delta^q)=0$. This method of proof, namely of reducing to things that have zero homology (aka acyclic spaces) is called the \\emph{method of acyclic models}.\n\nWhat happens on the level of homology? Let's abstract a little bit. Suppose we have three chain complexes $A_\\bullet$, $B_\\bullet$, and $C_\\bullet$, to be thought of as $S_\\ast(X)$, $S_\\ast(Y)$, and $S_\\ast(X\\times Y)$. Suppose we have maps $\\times: A_p\\times B_q\\to C_{p+q}$ that satisfies bilinearity and the Leibniz formula. What does this induce in homology?\n\\begin{lemma}\nThis determines a bilinear map $ H_p(A)\\times H_q(B)\\xrightarrow{\\times} H_{p+q}(C)$.\n\\end{lemma}\n\\begin{proof}\nLet $[a]\\in H_p(A)$ where $a\\in Z_p(A)$ such that $\\partial a=0$ (i.e., $a$ is a cycle). Let $[b]\\in H_q(B)$ where $b\\in Z_q(A)$ such that $\\partial b=0$. We want to define $[a]\\times [b]\\in H_{p+q}(C)$. We hope that $[a]\\times [b]=[a\\times b]$. We need to check that $a\\times b$ is a cycle; let's check. By Leibniz, $\\partial(a\\times b)=\\partial a\\times b+(-1)^pa\\times\\partial b$. Because $a,b$ are boundaries, this is zero. We still need to check that this thing is well-defined. Let's pick another $[a^\\prime]=[a]$ and $[b^\\prime]=[b]$. We want $[a\\times b]=[a^\\prime\\times b^\\prime]$. In other words, we need that $a\\times b$ differs from $a^\\prime\\times b^\\prime$ by a boundary. We can write $a^\\prime=a+\\partial\\overline{a}$ and $b^\\prime=b+\\partial\\overline{b}$. What's $a^\\prime\\times b^\\prime$? It's:\n\t\\begin{equation*}\n\ta^\\prime\\times b^\\prime=(a+\\partial\\overline{a})+(b+\\partial\\overline{b})\n\t= a\\times b+\\left(a\\times\\partial\\overline{b} + (\\partial\\overline{a})\\times b+(\\partial\\overline{a})\\times(\\partial\\overline{b})\\right)\n\t\\end{equation*}\nBut, well, $\\partial(a\\times\\overline{b})=\\partial a\\times\\overline{b}+(-1)^pa\\times\\partial\\overline{b}=(-1)^pa\\times\\partial\\overline{b}$, and $\\partial(\\overline{a}\\times b)=\\partial\\overline{a}\\times b$, and $\\partial(\\overline{a}\\times\\partial\\overline{b})=\\partial\\overline{a}\\times\\partial\\overline{b}$. This means that $a^\\prime\\times b^\\prime=a\\times b+\\partial((-1)^{-p}(a\\times \\overline{b}) + \\overline{a}\\times b + \\overline{a}\\times\\partial\\overline{b})$. They differ by a boundary, so it's well-defined.\n\nThe last step is to check bilinearity, which is left to the reader.\n\\end{proof}\nThis gives the following result.\n\\begin{theorem}\nThere is a map $ H_p(X)\\times H_q(Y)\\to H_{p+q}(X\\times Y)$ that's natural, bilinear, and normalized. This map is also \\emph{unique} (unlike the map $S_p(X)\\times S_q(Y)\\to S_{p+q}(X\\times Y)$, which isn't unique because we there are uncountably many choices of $\\iota_p\\times\\iota_q$, all differing by a boundary), because the map $\\times:S_p(X)\\times S_q(Y)\\to S_{p+q}(X\\times Y)$ is unique up to chain homotopy!\n\\end{theorem}\nLet's go back to homotopy invariance. Recall that if $f_0\\sim f_q:X\\to Y$, then $f_{0,\\ast}=f_{1,\\ast}:S_\\ast(X)\\to S_\\ast(Y)$. We proved this by showing that this reduces to showing that the two inclusions $i_0,i_1:X\\to X\\times I$ induce the same map on $S_\\ast(X)\\to S_\\ast(X\\times I)$. The chain homotopy $h_X:i_{0,\\ast}\\sim i_{1,\\ast}$ is defined as follows. Let $c\\in S_p(X)$. We need to give an element of $S_{p+1}(X\\times I)$, so if $\\iota:\\Delta^1\\to I$ is the obvious map, we just define $h_X(c)=(-1)^p c\\times\\iota$. Let's check that.\n\nLet's compute $\\partial h_Xc$. This is $\\partial((-1)^p c\\times \\iota)=(-1)^p\\partial(c\\times\\iota)$, which, expanded out, is:\n\t\\begin{equation*}\n\t\\partial((-1)^p c\\times \\iota)=(-1)^p\\partial(c\\times\\iota)=(-1)^p(\\partial c)\\times\\iota+(-1)^{2p}c\\times\\partial\\iota\n\t\\end{equation*}\nWell, $\\partial\\iota=c_1^0-c_0^0\\in S_0(I)$, so this is equal to $(-1)^p(\\partial c)\\times\\iota+c\\times c^0_1 - c\\times c_0^0$. But $c\\times c^0_1=(i_1)_\\ast c-(i_0)_\\ast c$. Therefore, this is $(-1)^p(\\partial c)\\times\\iota + (i_1)_\\ast c-(i_0)_\\ast c$. On the other hand, what's $h_X\\partial c=(-1)^{p-1}(\\partial c)\\times\\iota$. Let's add them together:\n\t\\begin{equation*}\n\t\\partial h_Xc+h_X\\partial c=(-1)^p(\\partial c)\\times\\iota + (i_1)_\\ast c-(i_0)_\\ast c+(-1)^{p-1}(\\partial c)\\times\\iota=(i_1)_\\ast c - (i_0)_\\ast c\n\t\\end{equation*}\nSo this is, by definition, a chain homotopy!\n\nI just want to mention that there's an explicit choice of $\\iota_p\\times\\iota_q$. This is called the Eilenberg-Zilber chain. You're highly encouraged to think about this yourself. We're going to consider $\\Delta^{p+q}\\to\\Delta^p\\times\\Delta^q$. They're all affine maps, sending vertices to pairs of vertices. We're going to think of an ordered map $\\omega:[p+q]\\to[p]\\times[q]$. We can complete the diagram to get:\n\t\\begin{equation*}\n\t\\xymatrix{ & [p]\\\\\n\t[p+q]\\ar[ur]^{pr_2\\omega}\\ar[dr]_{pr_1\\omega}\\ar[r]^\\omega & [p]\\times[q]\\ar[u]^{pr_2}\\ar[d]^{pr_1}\\\\\n\t & [q]}\n\t\\end{equation*}\nWe also want $\\omega$ to be injective (which requires that it takes $(0,0)$ to $(p,q)$). We can draw out a ``staircase'' in the $p\\times q$ grid, and the area under the staircase defined by $\\omega$ is denote $A(\\omega)$. Define $\\iota_p\\times\\iota_q=\\sum(-1)^{A(\\omega)}\\overline{\\omega}$ where $\\overline{\\omega}$ is the corresponding affine map $\\Delta{p+q}\\to\\Delta^p\\times\\Delta^q$. It's combinatorially annoying to check that this satisfies the conditions of the theorem, but it's a good exercise to check it out. It's in a paper by Eilenberg-Moore.\n", "meta": {"hexsha": "ffcfcaa3a1a29319e05b29ab5a63cc02e12f7b1c", "size": 8787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-7-eilenberg-zilber.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "old-905/lec-7-eilenberg-zilber.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "old-905/lec-7-eilenberg-zilber.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 127.347826087, "max_line_length": 810, "alphanum_fraction": 0.6939797428, "num_tokens": 3151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807408, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7451016761333816}}
{"text": "\\section{Appendix}\n\n\\subsection{Definitions}\n\\begin{definition}{(Scaled inverse $\\chi^2$ distribution).}\\label{def:scaledInverseChi}\n  Let $\\nu > 0$ and $\\tau^2 > 0$ be parameters representing degrees of freedom and scale, respectively. The family of \\emph{scaled inverse $\\chi^2$ distributions} is characterized by its probability density function, namely\n  \\begin{align*}\n    p(x) \\propto x^{-(1 + \\nu / 2)} \\EXP{\\frac{-\\nu \\tau^2}{2 x}} \\quad \\text{for} \\, x \\in (0, \\infty) \\,,\n  \\end{align*}\n  where the constant of integration is ignored for clarity.\n  We write $X \\sim \\scaledInvChi{\\nu, \\tau^2}$ to denote that the random variable $X$ follows a scaled inverse $\\chi^2$ distribution with parameters $\\nu$ and $\\tau^2$.\n\\end{definition}\n\n\\begin{definition}{(Conjugate prior).}\\label{def:conjugate_prior}\nLet the likelihood $p(y \\mid \\theta)$ be given and assume that the prior distribution $p(\\theta)$ is a member of some family $\\mathcal{F}$ of probability distributions.\nWe say that $p(\\theta)$ is a \\emph{conjugate prior} if the posterior $p(\\theta \\mid y)$ is also a member of $\\mathcal{F}$.\n\\end{definition}\n\n\\subsection{Figures}\n\n\\begin{figure}[H]\n\\begin{center}\n\\begin{tikzpicture}%\n  [vertex/.style={circle,draw=black,fill=white, minimum size=1cm},\n  node distance=2.5cm,\n  >=latex,\n  on grid]\n  \\node[vertex] (phi) {$\\phi$};\n  \\node[rectangle, draw=black, minimum size=0.9cm,left=2cm of phi] (zeta) {$\\zeta$};\n  \\node[vertex,below left=1.5cm and 2cm of phi] (theta1) {$\\theta_1$};\n  \\node[vertex,below right=1.5cm and 2cm of phi] (thetaJ) {$\\theta_J$};\n  \\node[below=1.5cm of phi] (dots1) {$\\dots$};\n  \\node[rectangle, draw=black, minimum size=0.9cm, left=2cm of theta1] (u1) {$u_1$};\n  \\node[rectangle, draw=black, minimum size=0.9cm, right=2cm of thetaJ] (uJ) {$u_J$};\n  \\node[vertex,below=2cm of theta1] (y1) {$y(1)$};\n  \\node[vertex,below=2cm of thetaJ] (yJ) {$y(J)$};\n  \\node[rectangle, draw=black, minimum size=0.9cm, left=2cm of y1] (x1) {$x(1)$};\n  \\node[rectangle, draw=black, minimum size=0.9cm, right=2cm of yJ] (xJ) {$x(J)$};\n  \\node[below=3.5cm of phi] (dots1) {$\\dots$};\n  \\draw[->]\n    (zeta) edge (phi)\n    (phi) edge (theta1)\n    (phi) edge (thetaJ)\n    (u1) edge (theta1)\n    (uJ) edge (thetaJ)\n    (theta1) edge (y1)\n    (thetaJ) edge (yJ)\n    (x1) edge (y1)\n    (xJ) edge (yJ);\n\\end{tikzpicture}\n\\end{center}\n\\caption{A generic two-level Bayesian hierarchical model depicted as a directed acyclical graph modeling generic observations $y(j)$ in groups $j = 1,\\mydots, J$. Circled parameters denote random quantities while parameters contained in squares denote fixed quantities.}\n\\label{fig:group_sem}\n\\end{figure}\n\\subsection{Proofs}\n\n\\begin{proof}[Derivation of Results in Table \\ref{tab:comp_uniform_bay_ml}.]\n  For the normal data problem at hand the derivation of the maximum likelihood estimators, $\\bar{y}$ for $\\mu$ and $(n-1) s^2 / n$ for $\\sigma^2$, is well known.\n  We note that the \"ML Variance\" denotes the theoretical variance of the estimators.\n  Further, the moments of the scaled inverse $\\chi^2$ distributions are available in closed form.\n  In particular, if $X \\sim \\scaledInvChi{\\nu, \\tau^2}$, then $\\Exp{X} = \\nu \\tau^2 / (\\nu - 2)$ and $\\var{X} = 2 \\nu^2 \\tau^4 / ((\\nu - 2)^2 (\\nu - 4))$.\n\n  Let us first consider the parameter $\\mu$.\n  As the t-distribution is parameterized over its mean and variance we can simply read off these values.\n  Further, as the t-distribution is symmetric the MAP is equal to its mean.\n\n  Let us now consider the parameter $\\sigma^2$.\n  Plugging in the respective parameters, we get\n  \\begin{align*}\n    \\Exp{\\sigma^2 \\mid y} = \\frac{n - 1}{n - 3} \\sigma^2\n  \\end{align*}\n  directly, and\n  \\begin{align*}\n    \\var{\\sigma^2 \\mid y} = \\frac{2 (n-1)^2}{(n-3)^2(n-5)} \\sigma^4 \\,.\n  \\end{align*}\n  To get the MAP for $\\sigma^2$ we need to maximize the posterior of $\\sigma^2$.\n  Note that we can drop any integration constants, i.e. we need to solve\n  \\begin{align*}\n    \\maximize_{x > 0} \\left\\{x^{-(1 + \\frac{n-1}{2})} \\EXP{\\frac{-(n-1) s^2}{2 x}}\\right\\} \\,,\n  \\end{align*}\n  where the term in curly brackets is just the posterior density of $\\sigma^2$ evaluated at $x$.\n  Using that the constant of integration is positive we can readily see that the posterior is concave.\n  Hence, differentiating with respect to $x$ and setting this to zero yields the desired result.\n\\end{proof}\n\n\\begin{proof}[Derivation of Results in Table \\ref{tab:comp_conjugate_bay_ml}.]\n  The proof from above applies here by mutatis mutandis.\n\\end{proof}\n\n\\begin{remark}\nThe subsequent proofs presented here follow \\citet{gelmanbda04}; however, we contribute detailed remarks.\n\\end{remark}\n\n\\begin{proof}[Proof of Proposition \\ref{prop:posterior_uniform}.]\n  Consider first the object $\\mu \\mid \\sigma^2, y$.\n  We get\n  \\begin{align*}\n    p(\\mu \\mid \\sigma^2, y) \\propto p(y \\mid \\mu, \\sigma^2) p(\\mu \\mid \\sigma^2) \\propto p(y \\mid \\mu, \\sigma^2) \\,,\n  \\end{align*}\n  where the last step follows as the priors are assumed to be independent.\n  Note then\n  \\begin{align*}\n    p(\\mu \\mid \\sigma^2, y) &\\propto \\EXP{-\\frac{1}{\\sigma^2}\\sum_i (y_i - \\mu)^2} = \\EXP{-\\frac{n}{\\sigma^2} \\frac{1}{n}\\sum_i (y_i^2 - 2y_i \\mu + \\mu^2)}\\\\\n    &=\\EXP{-\\frac{n}{\\sigma^2} (\\bar{y^2} - 2 \\bar{y} \\mu + \\mu^2)} \\propto\n    \\EXP{-\\frac{1}{\\sigma^2 / n} (\\mu - \\bar{y})^2} \\,,\n  \\end{align*}\n  where $\\bar{y^2} = \\frac{1}{n}\\sum_i y_i^2$ and the last step is only proportional as we switch $\\bar{y^2}$ for $\\bar{y}^2$.\n  Note that proportionality here is with respect to $\\mu$.\n  We thus get $\\mu \\mid \\sigma^2, y \\sim \\normal{\\bar{y}, \\sigma^2/n}$ as our first intermediate result.\n\n  Consider now $\\sigma \\mid y$.\n  As we already derived the joint posterior we can compute the marginal posterior of $\\sigma^2$ by integrating out $\\mu$.\n  Note that $\\sum_i (y_i - \\mu)^2 = [(n-1)s^2 + n(\\bar{y} - \\mu)^2]$, where $s^2$ denotes the (unbiased) sample variance. Hence\n  \\begin{align*}\n    p(\\sigma^2 \\mid y) &\\propto \\int p(\\mu, \\sigma^2 \\mid y) \\mathrm{d} \\mu\\\\\n    &\\propto \\int \\sigma^{-(n+2)} \\EXP{-\\frac{1}{2\\sigma^2}\\sum_i (y_i - \\mu)^2} \\mathrm{d} \\mu\\\\\n    &= \\sigma^{-(n+2)} \\int \\EXP{-\\frac{1}{2\\sigma^2}\\sum_i (y_i - \\mu)^2} \\mathrm{d} \\mu\\\\\n    &= \\sigma^{-(n+2)} \\int \\EXP{-\\frac{1}{2\\sigma^2}[(n-1) s^2 + n(\\bar{y} - \\mu)^2]} \\mathrm{d} \\mu\\\\\n    &= \\sigma^{-(n+2)} \\EXP{-\\frac{1}{2\\sigma^2}[(n-1) s^2]} \\int \\EXP{\\frac{1}{2\\sigma^2/n}(\\mu - \\bar{y})^2} \\mathrm{d} \\mu\\\\\n    &= \\sigma^{-(n+2)} \\EXP{-\\frac{1}{2\\sigma^2}[(n-1) s^2]} \\sqrt{2 \\pi \\sigma^2 / n} \\\\\n    &\\propto (\\sigma^2)^{-(n+1)/2} \\EXP{-\\frac{1}{2\\sigma^2}[(n-1) s^2]} \\,,\n  \\end{align*}\n  where the second to last step follows simply by considering the constant of integration of the normal distribution of $\\mu \\mid \\sigma^2, y$.\n  Note that here we consider proportionality with respect to $\\sigma^2$.\n  By inspection we see that $\\sigma^2 \\mid y \\sim \\text{scaled-Inv-} \\chi^2(n-1, s^2)$, which proves our first claim.\n\n  To finish the proof we integrate the joint posterior over $\\sigma^2$ to get the marginal posterior of $\\mu$.\n  We evaluate the integral by substitution using\n  $z = \\sfrac{a}{2 \\sigma^2}$ with $a = (n-1)s^2 + n(\\mu - \\bar{y})^2$.\n\n  Then,\n  \\begin{align*}\n    p(\\mu \\mid y) &= \\int_{(0, \\infty)} p(\\mu, \\sigma^2 \\mid y) \\mathrm{d}\\sigma^2\\\\\n    &\\propto  \\int_{(0, \\infty)} (\\sigma^2)^{-(n+2)/2} \\EXP{-\\frac{1}{2\\sigma^2}[(n-1) s^2 + n(\\mu - \\bar{y})^2]} \\mathrm{d} \\sigma^2\\\\\n    &\\propto \\int_{(0, \\infty)} (\\sigma^2)^{-(n+2)/2}\\EXP{-z} [(\\sigma^2)^2 / a] \\mathrm{d}z\\\\\n    &= \\int_{(0, \\infty)} (\\sigma^2)^{-(n-2)/2} / a \\EXP{-z} \\mathrm{d}z\\\\\n    &= a^{-n/2}\\int_{(0, \\infty)} z^{(n-2)/2}\\EXP{-z} \\mathrm{d}z\\\\\n    &= a^{-n/2} \\, \\Gamma(n/2)\\\\\n    &\\propto a^{-n/2}\\\\\n    &= [(n-1)s^2 + n(\\mu - \\bar{y})^2]^{-n/2}\\\\\n    &\\propto \\left[1 + \\frac{1}{n-1} \\frac{(\\mu - \\bar{y})^2}{s^2 / n}\\right]^{-n/2} \\,\n  \\end{align*}\n  where $\\Gamma$ denotes the gamma function (which is finite on the positive real numbers).\n  This concludes the proof by implying that $\\mu \\mid y \\sim t_{n-1}(\\bar{y}, s^2/n)$,\n\\end{proof}\n\n\n\\begin{proof}[Proof of Proposition \\ref{prop:posterior_conjugate}.]\nLet us first state equation \\ref{eq:conjugate_posterior} and the premise again.\nWe have to show that\n\\begin{align*}\n  p(\\mu, \\sigma^2 \\mid y) \\propto& (\\sigma^2)^{-\\frac{3 + \\nu_0 + n}{2}} \\times\\\\\n  & \\times \\EXP{-\\frac{1}{2 \\sigma^2} \\left[\\nu_0\\sigma_0^2 + \\kappa_0(\\mu - \\mu_0)^2 + (n-1)s^2 + n(\\bar{y} - \\mu)^2 \\right]}\n\\end{align*}\nis $\\NormalscaledInvChi{\\mu_n, \\sigma_n^2/\\kappa_n; \\nu_n, \\sigma_n^2}$ with $\\nu_n = \\nu_0 + n$, $\\kappa_n = \\kappa_0 + n$, $\\mu_n =\\frac{\\kappa_0}{\\kappa_0 + n}\\mu_0 + \\frac{n}{\\kappa_0 + n}\\bar{y}$, $\\sigma_n^2 = \\left[\\nu_0 \\sigma_0^2 + (n-1)s^2 + \\frac{\\kappa_0 n}{\\kappa_0 + n} (\\bar{y} - \\mu_0)^2\\right] /\\nu_n$.\nBy definition of the normal-scaled-inverse-$\\chi^2$ distribution $\\nu_n = \\nu_0 + n$ follows trivially.\nLet us therefore consider the term in square brackets in the exponential.\nWe have to show that\n\\begin{align*}\n  \\left[\\nu_0\\sigma_0^2 + \\kappa_0(\\mu - \\mu_0)^2 + (n-1)s^2 + n(\\bar{y} - \\mu)^2 \\right] = \\nu_n \\sigma_n^2 + \\kappa_n (\\mu - \\mu_n)^2 \\,.\n\\end{align*}\nPlugging in for $\\sigma_n^2$ we get for the right-hand side\n\\begin{align*}\n  \\nu_n \\sigma_n^2 + \\kappa_n (\\mu - \\mu_n)^2 = \\nu_0 \\sigma_0^2 + (n-1)s^2 + \\frac{\\kappa_0 n}{\\kappa_0 + n} (\\bar{y} - \\mu_0)^2 + \\kappa_n (\\mu- \\mu_n)^2 \\,.\n\\end{align*}\nTherefore we only need to check\n\\begin{align*}\n  \\kappa_0(\\mu - \\mu_0)^2 + n(\\bar{y} - \\mu)^2 = \\frac{\\kappa_0 n}{\\kappa_0 + n} (\\bar{y} - \\mu_0)^2 + \\kappa_n (\\mu- \\mu_n)^2 \\,.\n\\end{align*}\nExpanding the right-hand side we get\n\\begin{align*}\n\\frac{\\kappa_0 n}{\\kappa_0 + n} &(\\bar{y} - \\mu_0)^2 + \\kappa_n (\\mu- \\mu_n)^2\\\\\n&=\\frac{\\kappa_0 n}{\\kappa_n}\\left[\\bar{y}^2 - 2\\bar{y}\\mu_0 + \\mu_0^2 \\right] + \\kappa_n \\left[\\mu^2 - 2\\mu\\mu_n + \\mu_n^2 \\right]\\\\\n&=\\frac{\\kappa_0 n}{\\kappa_n}\\left[\\bar{y}^2 - 2\\bar{y}\\mu_0 + \\mu_0^2 \\right] + \\kappa_n \\left[\\mu^2 - 2\\mu\\frac{\\kappa_0}{\\kappa_n}\\mu_0 - 2\\mu\\frac{n}{\\kappa_n}\\bar{y} + \\frac{\\kappa_0^2}{\\kappa_n^2}\\mu_0^2 + \\frac{n^2}{\\kappa_n^2} \\bar{y}^2 + 2\\frac{\\kappa_0}{\\kappa_n} \\frac{n}{\\kappa_n}\\mu_0\\bar{y} \\right]\\\\\n&=\\frac{\\kappa_0 n}{\\kappa_n}\\left[\\bar{y}^2 - 2\\bar{y}\\mu_0 + \\mu_0^2 \\right] + \\kappa_n \\mu^2 - 2\\mu \\kappa_0 \\mu_0 - 2\\mu n\\bar{y} + \\frac{\\kappa_0^2}{\\kappa_n}\\mu_0^2 + \\frac{n^2}{\\kappa_n} \\bar{y}^2 + 2 \\kappa_0 n \\mu_0 \\bar{y} / \\kappa_n\\\\\n&= \\left(\\kappa_0 \\mu^2 -2\\mu \\kappa_0 \\mu_0 \\right) + \\left(n \\mu^2 - 2 n \\mu \\bar{y} \\right) + \\frac{\\kappa_0 n}{\\kappa_n}\\bar{y}^2 + \\frac{\\kappa_0 n}{\\kappa_n}\\mu_0^2 + \\frac{\\kappa_0^2}{\\kappa_n} \\mu_0^2 + \\frac{n^2}{\\kappa_n} \\bar{y}^2\\\\\n&= \\left(\\kappa_0 \\mu^2 -2\\mu \\kappa_0 \\mu_0 \\right) + \\left(n \\mu^2 - 2 n \\mu \\bar{y} \\right) + \\bar{y}^2 \\left(\\frac{\\kappa_0 n}{\\kappa_n} + \\frac{n^2}{\\kappa_n}\\right) + \\mu_0^2\\left(\\frac{\\kappa_0 n}{\\kappa_n} + \\frac{\\kappa_0^2}{\\kappa_n}\\right)\\\\\n&= \\left(\\kappa_0 \\mu^2 -2\\mu \\kappa_0 \\mu_0 + \\kappa_0 \\mu_0^2 \\right) + \\left(n \\mu^2 - 2 n \\mu \\bar{y} + n \\bar{y}^2\\right)\\\\\n&=\\kappa_0(\\mu - \\mu_0)^2 + n(\\bar{y} - \\mu)^2 \\,,\n\\end{align*}\nwhich was what we wanted.\n\\end{proof}\n\n\\begin{proof}[Proof of Proposition \\ref{prop:marginal_posterior}.]\nWe continue to use the notation of the previous proof.\nAs in the proof of proposition \\ref{prop:posterior_uniform} we first compute the distribution of $\\mu \\mid \\sigma^2, y$ and then derive the posterior of $\\sigma^2$ by integrating $\\mu$ out.\nNote that we actually defined $\\mu \\mid \\sigma^2 \\sim \\normal{\\mu_0, \\sigma^2/\\kappa_0}$.\nHence,\n\\begin{align*}\n  p(\\mu \\mid \\sigma^2, y) &\\propto p(y \\mid \\mu, \\sigma^2) p(\\mu \\mid \\sigma^2)\\\\\n  &\\propto \\EXP{-\\frac{1}{2\\sigma^2/n} (\\mu - \\bar{y})^2} \\EXP{-\\frac{1}{2\\sigma^2/\\kappa_0}(\\mu - \\mu_0)^2}\\\\\n  &= \\EXP{-\\frac{1}{2\\sigma^2}\\left[n(\\mu - \\bar{y})^2 + \\kappa_0(\\mu - \\mu_0)^2 \\right]}\\\\\n  &= \\EXP{-\\frac{1}{2\\sigma^2}\\left[\\mu^2(\\kappa_0 + n) - 2\\mu(\\kappa_0\\mu_0 + n\\bar{y}) + (\\mydots) \\right]}\\\\\n  &= \\EXP{-\\frac{1}{2\\sigma^2 / \\kappa_n}\\left[\\mu^2 - 2\\mu(\\kappa_0\\mu_0 + n\\bar{y})/\\kappa_n + (\\mydots)/\\kappa_n \\right]}\\\\\n  &= \\EXP{-\\frac{1}{2\\sigma^2 / \\kappa_n}\\left(\\mu - \\mu_n^2\\right) + (\\mydots)}\\\\\n  &\\propto \\EXP{-\\frac{1}{2\\sigma^2 / \\kappa_n}\\left(\\mu - \\mu_n^2\\right)} \\,,\n\\end{align*}\nwhich implies that $\\mu \\mid \\sigma^2, y \\sim \\normal{\\mu_n, \\sigma^2 / \\kappa_n}$, where we used $(\\mydots)$ to denote constants independent of $\\mu$.\n\nNow we can use this result as\n\\begin{align*}\n  p(\\sigma^2 \\mid y) &= \\int p(y, \\sigma^2 \\mid y) \\mathrm{d}\\mu\\\\\n  &\\propto \\int (\\sigma^2)^{-\\frac{3 + \\nu_n}{2}} \\EXP{\\frac{1}{2\\sigma^2} \\left[\\nu_n \\sigma_n^2 + \\kappa_n(\\mu_n - \\mu)^2 \\right]}\\mathrm{d}\\mu\\\\\n  &\\propto (\\sigma^2)^{-\\frac{3 + \\nu_n}{2}} \\int \\EXP{\\frac{1}{2\\sigma^2} \\nu_n \\sigma_n^2}\\EXP{\\frac{1}{2\\sigma^2 / \\kappa_n} (\\mu_n - \\mu)^2 }\\mathrm{d}\\mu\\\\\n  &\\propto (\\sigma^2)^{-\\frac{3 + \\nu_n}{2}}\\EXP{\\frac{1}{2\\sigma^2} \\nu_n \\sigma_n^2} \\int \\EXP{\\frac{1}{2\\sigma^2 / \\kappa_n} (\\mu_n - \\mu)^2 }\\mathrm{d}\\mu\\\\\n  &\\propto (\\sigma^2)^{-\\frac{3 + \\nu_n}{2}}\\EXP{\\frac{1}{2\\sigma^2} \\nu_n \\sigma_n^2} \\sqrt{2 \\pi \\sigma^2 / \\kappa_n}\\\\\n  &\\propto (\\sigma^2)^{-(1 + \\frac{\\nu_n}{2})} \\EXP{-\\frac{1}{2\\sigma^2}\\nu_n\\sigma_n^2}\\,,\n\\end{align*}\nfrom which we can conclude that $\\sigma^2 \\mid y \\sim \\scaledInvChi{\\nu_n, \\sigma_n^2}$.\n\nWe end the proof by deriving the marginal posterior of $\\mu$ using an analogous approach as in the proof of Proposition \\ref{prop:posterior_uniform}.\nDefine $a := \\left[\\nu_n\\sigma_n^2 + \\kappa_n(\\mu_n - \\mu)^2 \\right]$. We solve for the posterior by integrating $\\sigma^2$ out using the substitution $z = \\frac{a}{2\\sigma^2}$. Then\n\\begin{align*}\n  p(\\mu \\mid y) &= \\int_{(0, \\infty)} p(\\mu, \\sigma^2 \\mid y) \\mathrm{d}\\sigma^2\\\\\n  &\\propto \\int_{(0, \\infty)}(\\sigma^2)^{-\\frac{3 + \\nu_n}{2}} \\EXP{\\frac{1}{2\\sigma^2} \\left[\\nu_n \\sigma_n^2 + \\kappa_n(\\mu_n - \\mu)^2 \\right]}\\mathrm{d}\\sigma^2\\\\\n  &\\propto \\int_{(0, \\infty)}(\\sigma^2)^{-\\frac{3 + \\nu_n}{2}} \\EXP{\\frac{a}{2\\sigma^2}}\\mathrm{d}\\sigma^2\\\\\n  &\\propto \\int_{(0, \\infty)}(a / 2z)^{-\\frac{3 + \\nu_n}{2}} \\EXP{-z} \\frac{a}{2 z^2} \\mathrm{d}z\\\\\n  &\\propto \\int_{(0, \\infty)}a^{-\\frac{3 + \\nu_n}{2}}a z^{\\frac{3 + \\nu_n}{2}}z^{-2} \\EXP{-z} \\mathrm{d}z\\\\\n  &= a^{-\\frac{1 + \\nu_n}{2}} \\int_{(0, \\infty)} z^{\\frac{\\nu_n - 1}{2}} \\EXP{-z} \\mathrm{d}z\\\\\n  &= a^{-\\frac{1 + \\nu_n}{2}} \\Gamma\\left(\\frac{\\nu_n + 1}{2}\\right)\\\\\n  &\\propto a^{-\\frac{1 + \\nu_n}{2}}\\\\\n  &= \\left[\\nu_n \\sigma_n^2 + \\kappa_n(\\mu_n - \\mu)^2 \\right]^{-\\frac{1 + \\nu_n}{2}}\\\\\n  &= \\left[\\nu_n \\sigma_n^2\\left(1 + \\frac{1}{\\nu_n}\\frac{(\\mu_n - \\mu)^2}{\\sigma_n^2 / \\kappa_n}\\right) \\right]^{-\\frac{1 + \\nu_n}{2}}\\\\\n  &\\propto \\left[1 + \\frac{1}{\\nu_n}\\frac{(\\mu_n - \\mu)^2}{\\sigma_n^2 / \\kappa_n} \\right]^{-\\frac{1 + \\nu_n}{2}} \\,,\n\\end{align*}\nwhich concludes the proof by implying that $\\mu \\mid y \\sim t_{\\nu_n}(\\mu_n, \\sigma_n^2 / \\kappa_n)$.\n\\end{proof}\n", "meta": {"hexsha": "fe032e82cdf25f2a1bd350594758aa7f5d2bd5e4", "size": 14920, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/ch6.tex", "max_stars_repo_name": "timmens/bayesian-hierarchical-models", "max_stars_repo_head_hexsha": "80c174997ce2ac5ebfb2e1628df4f6aeae9c9b0b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-02-19T09:04:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-06T10:19:23.000Z", "max_issues_repo_path": "manuscript/ch6.tex", "max_issues_repo_name": "timmens/bayesian-hierarchical-models", "max_issues_repo_head_hexsha": "80c174997ce2ac5ebfb2e1628df4f6aeae9c9b0b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "manuscript/ch6.tex", "max_forks_repo_name": "timmens/bayesian-hierarchical-models", "max_forks_repo_head_hexsha": "80c174997ce2ac5ebfb2e1628df4f6aeae9c9b0b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-11-25T14:44:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T18:54:16.000Z", "avg_line_length": 65.7268722467, "max_line_length": 319, "alphanum_fraction": 0.620844504, "num_tokens": 6151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138366, "lm_q2_score": 0.8705972633721708, "lm_q1q2_score": 0.7451016600017598}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Statistical models}\\label{sec:statistical_models}\n\n%%-----------------------------\n%%\\subsection{Statistics}\n%\n%Let $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random vector.\n%\n%\\begin{definition}\n%Any transformation $T:\\R^n\\to\\R$ is called a \\emph{statistic}.\n%\\end{definition}\n%\n%There are two interpretations:\n%\\ben\n%\\it \n%$T(\\boldX)$ is a random variable on $(\\Omega,\\prob)$,\n%\\[\\begin{array}{rccl}\n%T(\\boldX):\t& \\Omega \t& \\to \t\t& \\R \\\\\n%\t\t\t& \\omega\t& \\mapsto\t& T\\big[\\boldX(\\omega)\\big]\n%\\end{array}\\]\n%\\it\n%$T$ is a random variable on $(\\R^n,\\prob_{\\mathbf{X}})$,\n%\\[\\begin{array}{rccl}\n%T:\t& \\R^n \t\t& \\to \t\t& \\R \\\\\n%\t& \\boldx\t& \\mapsto\t& T(\\boldx)\n%\\end{array}\\]\n%where $\\prob_X(B) = \\prob(\\mathbf{X}\\in B)$ is the probability measure induced on subsets of $\\R^n$ by $\\mathbf{X}$.\n%\\een\n%\n%For the latter interpretation to be useful, the distribution of $T$ (over subsets of $\\R$) must be determined from the distribution of the random vector (over subsets of $\\R^n$).\n\n%-----------------------------\n%\\subsection*{Statistical models}\n\nTo estimate the underlying distribution $F_X$ from a random sample $X_1,X_2,\\ldots,X_n$ of observations from the distribution of $X$, let us assume that $F_X$ belongs to some \\emph{parametric family} of distributions.\n%\\[\n%\\mathcal{M} = \\big\\{F(x\\,;\\mathbf{\\theta}) : \\mathbf{\\theta}\\in\\Theta\\big\\}\n%\\]\n%where $\\mathbf{\\theta}$ is an unknown vector of parameters and $\\Theta$ is the set of all such vectors.\n%\n\\begin{definition}\nA \\emph{statistical model} is a parametric family of CDFs,\n\\[\n\\mathcal{M} = \\big\\{F(x\\,;\\mathbf{\\theta}) : \\mathbf{\\theta}\\in\\Theta\\big\\}\n\\]\nwhere $\\mathbf{\\theta}$ is a vector of parameters, and $\\Theta$ is called the \\emph{parameter space}.\n%the set of all such vectors called the \n%\\it $\\mathcal{M}$ is called a \\emph{statistical model};\n%\\it $\\Theta$ is called the \\emph{parameter space}.\n%\\een\n\\end{definition}\n\n\\begin{example}\n\\bit\n\\it\nThe family of exponential distributions: \\par\n\\qquad $\\mathcal{M} = \\big\\{F(x;\\lambda): \\lambda>0\\big\\}$ where $F(x;\\lambda)=1-e^{-\\lambda x}$ for $x>0$.\n\\it \nThe family of uniform distributions: \\par\n\\qquad$\\mathcal{M} = \\big\\{F(x;a,b): a<b\\big\\}$ where $F(x;a,b)=\\displaystyle\\frac{x-a}{b-a}$ for $a\\leq x\\leq b$.\n\\eit\n\\end{example}\n\n%The members of a statistical model $\\mathcal{M}$ are indexed by the parameter $\\theta$. \n%Estimating the distribution of $X$ from a random sample of observations amounts to estimating $\\theta$.\n\n\\begin{remark}\nLet $\\mathcal{M}=\\big\\{F(x\\,;\\mathbf{\\theta}):\\mathbf{\\theta}\\in\\Theta\\big\\}$ be a statistical model and suppose that $F_X\\in\\mathcal{M}$. Then estimating $F_X$ amounts to estimating the ``true'' value of the parameter $\\theta$.\n\\end{remark}\n\n\\begin{definition}\n%Let $F_X\\in\\big\\{F(x\\,;\\mathbf{\\theta}):\\mathbf{\\theta}\\in\\Theta\\big\\}$.\n\\ben\n\\it To estimate a particular value for $\\theta$ is called \\emph{point estimation}.\n\\it To estimate a range of values for $\\theta$ is called \\emph{interval estimation}.  \n\\it To assert whether or not $\\theta$ lies in some range is called \\emph{hypothesis testing}.\n\\een\n\\end{definition}\n\n\n%-----------------------------\n\\subsection{Estimators}\n\n%Let $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random vector.\n\n\\begin{definition}\nLet $X$ be a random variable on $\\Omega$ and let $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random sample from the distribution of $X$. Any transformation $T:\\R^n\\to\\R$ of $\\mathbf{X}$ is called a \\emph{sample statistic}.\n\\end{definition}\n\nThere are two interpretations:\n\\ben\n\\it \n$T(\\boldX)$ is a random variable on $(\\Omega,\\prob)$,\n\\[\\begin{array}{rccl}\nT(\\boldX):\t& \\Omega \t& \\to \t\t& \\R \\\\\n\t\t\t& \\omega\t& \\mapsto\t& T\\big[\\boldX(\\omega)\\big]\n\\end{array}\\]\n\\it\n$T$ is a random variable on $(\\R^n,\\prob_{\\mathbf{X}})$,\n\\[\\begin{array}{rccl}\nT:\t& \\R^n \t\t& \\to \t\t& \\R \\\\\n\t& \\boldx\t& \\mapsto\t& T(\\boldx)\n\\end{array}\\]\nwhere $\\prob_{\\mathbf{X}}(B) = \\prob(\\mathbf{X}\\in B)$ is the distribution of $\\mathbf{X}$.\n\\een\n\nFor the latter interpretation to be useful, the distribution of the sample statistic $T$ over subsets of $\\R$ must be deduced from the distribution of the random sample $\\mathbf{X}$ over subsets of $\\R^n$. \n\n\\begin{definition}\n\\ben\n%\\it $\\theta$ is called the \\emph{true value} of the parameter.\n\\it A statistic $T(\\mathbf{X})$ used to estimate an unknown parameter $\\theta$ is called an \\emph{estimator} of $\\theta$.\n%These are commonly denoted by $\\hat{\\theta}(\\mathbf{X})$.\n\\it For any particular sample realisation $\\mathbf{x}$ the value $T(\\boldx)$ is called an \\emph{estimate} of $\\theta$.\n\\een\nNote that estimators of $\\theta$ are often denoted by $\\hat{\\theta}$.\n\\end{definition}\n\n\\begin{example}\\label{exa:estimate_bernoulli}\nA coin has an unknown probability $\\theta$ of landing on heads. \n%\\bigskip\nAn appropriate statistical model for this experiment is the family of \\emph{Bernoulli} distributions:\n\\[\n\\mathcal{M} = \\big\\{F(x\\,;\\theta):0\\leq\\theta\\leq 1\\big\\}\n\\qquad\\text{where}\\quad\nF(x;\\theta) = \\begin{cases}\n0\t\t\t\t& x < 0, \\\\\n1-\\theta\t\t& 0 \\leq x < 1, \\\\\n1\t\t\t\t& x \\geq 1. \\\\\n\\end{cases}\n\\]\nLet $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random sample from the $\\text{Bernoulli}(\\theta)$ distribution. An estimator for $\\theta$ is provided by the following statistic, called the \\emph{sample mean}:\n\\[\\begin{array}{rccl}\nT:\t& \\R^n \t\t& \\to \t\t& \\R \\\\\n\t& \\boldx\t& \\mapsto\t& \\displaystyle\\frac{1}{n}\\sum_{i=1}^n x_i.\n\\end{array}\\]\nThe distribution of $T$ is determined by the common distribution of the individual observations $X_i$. In this case $X_i\\sim\\text{Bernoulli}(\\theta)$ so %$nT\\sim\\text{Binomial}(n,\\theta)$ and \n\\[\n%\\prob(T = k/n) = \\binom{n}{k}\\theta^{k}(1-\\theta)^{n-k}.\n\\prob\\left(T = \\frac{k}{n}\\right) = \\binom{n}{k}\\theta^{k}(1-\\theta)^{n-k}\n\\qquad\\text{for $k=0,1,2,\\ldots,n$}.\n\\]\n\\end{example}\n\n\n", "meta": {"hexsha": "71f6590bf2a29818eb85085d2b6a5c003574b817", "size": 5836, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/07B_statistical_models.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/07B_statistical_models.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/07B_statistical_models.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 39.4324324324, "max_line_length": 228, "alphanum_fraction": 0.656442769, "num_tokens": 1963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7451016585650168}}
{"text": "\\lab{Weightloss and Predator-Prey Models}{Weightloss and Predator-Prey Models}\n\\label{lab:Weightloss}\n\n\\section*{A Weightloss Model}\nHere we will look at a model of weight change based on basic thermodynamics and kinematics.\nThe main idea behind weight change is simple.\nIf a person's energy intake is more than their energy expended, then they gain weight.\nIf their intake is less, then they lose weight.\nLet the \\emph{energy balance} $EB$ be the difference between \\emph{energy intake} $EI$ and \\emph{energy expenditure} $EE$, so that\n\\begin{equation}\n\\label{eqn:EB}\nEB = EI - EE.\n\\end{equation}\nWhen the energy intake is greater than the energy expended, the balance is positive and weight is gained.\nSimilarly, the balance is negative and weight is lost if the energy intake is less than the energy expended.\n\nBody weight at time $t$ is the sum of the weight of fat and lean tissue; that is,  $BW(t) = F(t) + L(t).$\nThese quantities can be described by the compartmental model\n\\begin{subequations}\n\\label{eqn:compartment}\n\\begin{align}\n\\rho_F \\dfrac{dF(t)}{dt} &= (1-p(t)) EB(t),\\label{eqn:compartment:a}\\\\\n\\rho_L \\dfrac{dL(t)}{dt} &= p(t) EB(t),\\label{eqn:compartment:b}\n\\end{align}\n\\end{subequations}\nwhere $p(t)$ and $1-p(t)$ represent the proportion of the energy balance ($EB(t)$) that results in a change in the quantity of lean or fatty tissue, respectively.\nConstants $\\rho_L$ and $\\rho_F$ represent the energy density of lean and fatty tissue (about $1800$ and $9400$ kcal/kg).\n\nNext we need to find expressions for $p(t)$ and $EB(t)$ in terms of $L$ and $F$ (the dependent variables), $PAL$ and $EI$ (possibly varying parameters), and other constant parameters.\n\n The proportion $p(t)$ will vary with $F$ and $L$; from Forbes' Law \\cite{Fo.2} we have that\n\\begin{equation}\n\\label{eqn:forbes}\n\\dfrac{dF}{dL} = \\dfrac{F}{10.4}.\n\\end{equation}\nHence,\n\\[\n\\dfrac{F}{10.4} = \\dfrac{dF}{dL} = \\dfrac{dF/dt}{dL/dt} = \\dfrac{\\dfrac{(1-p(t)) EB(t)}{\\rho_F}}{\\dfrac{p(t) EB(t)}{\\rho_L}} = \\dfrac{\\rho_L}{\\rho_F} \\dfrac{1-p(t)}{p(t)}.\n\\]\nSolving for $p(t)$ gives Forbes' equation\n\\begin{equation}\n\\label{eqn:Forbes2}\np(t) = \\dfrac{C}{C+F(t)}\\quad\\mbox{where}\\quad C=10.4\\dfrac{\\rho_L}{\\rho_F}.\n\\end{equation}\n\nWe will use two expressions for energy expenditure (EE).\nFirst, we have the formula\n\\begin{equation}\n\\label{eqn:EE0}\nEE = PAL \\times RMR,\n\\end{equation}\nwhere $PAL$ is your physical activity level and $RMR$ your resting metabolic rate.\nYour resting metabolic rate can be determined by using the Mifflin equation.\nThis equation is an estimate based on a population study and is widely used in the literature.\nIt takes into account your gender, age (A) in years, and height (H) in meters:\n\\begin{equation}\n\\label{eqn:RMR}\nRMR = \\begin{cases} 9.99 W + 625 H + 5 A + 5 & \\mbox{if male}\\\\ 9.99 W + 625 H + 5 A -161 & \\mbox{if female.}\\end{cases}\n\\end{equation}\nYour physical activity level can be determined by using the table below.\n\\begin{table}[h]\n\\begin{center}\n\\begin{tabular}{|l|l|}\n\\hline\n1.40--1.69 & People who are sedentary and do not exercise regularly, spend \\\\\n& most of their time sitting, standing, with little body displacement\n\\\\\n\\hline\n1.70--1.99 & People who are active, with frequent body displacement throughout  \\\\\n& the day or who exercise frequently\\\\\n\\hline\n2.00--2.40 & People who engage regularly in strenuous work or exercise for \\\\\n& several hours each day\\\\\n\\hline\n\\end{tabular}\n\\caption{This is a rough guide for physical activity level (PAL).\n% For more detailed estimates, see \\cite{Heym} and Appendix \\ref{PAL_appendix}.\n}\n\\end{center}\\label{tab:PAL_table}\n\\end{table}\n\nThe second expression for energy expenditure comes from decomposing more precisely the different ways that energy is expended:\n\\begin{equation}\n\\label{eqn:EE}\nEE = \\underbrace{\\delta BW}_\\text{\\parbox{1cm}{physical\\\\activity}} + \\underbrace{\\beta_{tef} EI}_\\text{\\parbox{1cm}{thermic\\\\effect of\\\\eating}} + \\underbrace{\\beta_{at} EI + \\gamma_F F + \\gamma_L L + \\eta_F \\dfrac{dF}{dt} + \\eta_L \\dfrac{dL}{dt}  + K}_\\text{resting metabolic rate (RMR)},\n\\end{equation}\nwhere $\\gamma_F = 22$ kcal/kg/d, $\\gamma_L = 3.2$ kcal/kg/d, $\\eta_F = 180$ kcal/kg, and $\\eta_L = 230$ kcal/kg; see \\cite{Hall.2, Hall.4}.\nFurther, we let $\\beta_{tef}=0.10$ and $\\beta_{at}=0.14$ denote the coefficients for the thermic effect of feeding and adaptive thermogenesis, respectively.\nThe parameter $\\delta$ is the coefficient representing the amount of energy expended from physical activity per kilogram of body mass.\nNotice that $\\gamma_L$ is significantly larger than $\\gamma_F$.\nThis means that lean tissue metabolizes energy much faster than fatty tissue.\nAs a result, there are instances where one may want to increase their lean body mass through resistance training so that they are better able to support a higher caloric intake without significant weight gain.\nFinally, we remark that the constant $K$ can be tuned to an individual's body type directly through RMR and fat measurement, and is assumed to remain constant over time.\n\n% Assumptions made/Areas to improve:\n% include more accurate approximation of PAL (given in appendix), BMI (show to vary with race), account for variation in body type.\n\nThus, since the input $EI$ is assumed to be known, we can use \\eqref{eqn:EE} and \\eqref{eqn:Forbes2} to write \\eqref{eqn:compartment} in terms of $F$ and $L$, thus allowing us to close the system of ordinary differential equations (ODEs).\n\nSpecifically, we have\n\\begin{align*}\nRMR(t) = \\frac{EE}{PAL}&= K + \\gamma_F F(t) + \\gamma_L L(t) + \\eta_F \\dfrac{dF}{dt} + \\eta_L \\dfrac{dL}{dt}  + \\beta_{at} EI\\\\\n% &= K + \\gamma_F F(t) + \\gamma_L L(t) + \\dfrac{\\eta_F}{\\rho_F} (1-p(t)) EB(t) + \\dfrac{\\eta_L}{\\rho_L} p(t) EB(t)  + \\beta_{at} EI,\\\\\n\\dfrac{1}{PAL}\\left(EE - EI + EI \\right) &= K + \\gamma_F F(t) + \\gamma_L L(t) \\\\\n&+ \\left(\\dfrac{\\eta_F}{\\rho_F} (1-p(t)) + \\dfrac{\\eta_L}{\\rho_L} p(t) \\right) EB(t) + \\beta_{at} EI.\\\\\n\\left(\\dfrac{1}{PAL}-\\beta_{at}\\right) EI &= K + \\gamma_F F(t) + \\gamma_L L(t) \\\\\n&+ \\left(\\dfrac{\\eta_F}{\\rho_F} (1-p(t)) + \\dfrac{\\eta_L}{\\rho_L} p(t) + \\dfrac{1}{PAL}\\right) EB(t).\n\\end{align*}\n% Thus,\n% \\[\n% \\left(\\dfrac{1}{PAL}-\\beta_{at}\\right) EI = K + \\gamma_F F(t) + \\gamma_L L(t) + \\left(\\dfrac{\\eta_F}{\\rho_F} (1-p(t)) + \\dfrac{\\eta_L}{\\rho_L} p(t) + \\dfrac{1}{PAL}\\right) EB(t).\n% \\]\nSolving for $EB(t)$ in the last equation yields\n\\begin{equation}\n\\label{eqn:EB2}\nEB(t) = \\dfrac{\\left( \\dfrac{1}{PAL} - \\beta_{at} \\right) EI - K - \\gamma_F F(t) - \\gamma_L L(t)}{\\dfrac{\\eta_F}{\\rho_F} (1-p(t)) + \\dfrac{\\eta_L}{\\rho_L} p(t) + \\dfrac{1}{PAL}}.\n\\end{equation}\n% To find $K$, we note that\n% \\begin{equation}\n% \\label{eqn:K}\n% K = \\left(\\dfrac{1}{PAL}-\\beta_{at}\\right) EI - \\gamma_F F(t) - \\gamma_L L(t) - \\eta_F \\dfrac{dF}{dt} - \\eta_L \\dfrac{dL}{dt}  - \\dfrac{1}{PAL} EB.\n% \\end{equation}\nIn equilibrium ($EB = 0$), this gives us\n\\begin{equation}\n\\label{eqn:K2}\nK = \\left(\\dfrac{1}{PAL}-\\beta_{at}\\right) EI - \\gamma_F F - \\gamma_L L.\n\\end{equation}\nThus, for a subject who has maintained the same weight for a while, one can determine $K$ by using \\eqref{eqn:K2}, if they know their average caloric intake and amount of fat (assume $L=BW-F$).\nThe function \\li{weight_odesystem} in the following code implements \\eqref{eqn:compartment}.\n\n\\begin{lstlisting}\nfrom math import log\n# Fixed Constants:\nrho_F = 9400.\nrho_L = 1800.\ngamma_F = 3.2\ngamma_L = 22.\neta_F = 180.\neta_L = 230.\nC = 10.4  # Forbes constant\nbeta_AT = 0.14  # Adaptive Thermogenesis\nbeta_TEF = 0.1   # Thermic Effect of Feeding\nK = 0\n\ndef forbes(F):\n    C1 = C * rho_L / rho_F\n    return C1 / (C1 + F)\n\ndef energy_balance(F, L, EI, PAL):\n    p = forbes(F)\n    a1 = (1. / PAL - beta_AT) * EI - K - gamma_F * F - gamma_L * L\n    a2 = (1 - p) * eta_F / rho_F + p * eta_L / rho_L + 1. / PAL\n    return a1 / a2\n\ndef weight_odesystem(t, y, EI, PAL):\n    F, L = y[0], y[1]\n    p, EB = forbes(F), energy_balance(F, L, EI, PAL)\n    return np.array([(1 - p) * EB / rho_F , p * EB / rho_L])\n\ndef fat_mass(BW, age, H, sex):\n    BMI = BW / H**2.\n    if sex == 'male':\n        return BW * (-103.91 + 37.31 * log(BMI) + 0.14 * age) / 100\n    else:\n        return BW * (-102.01 + 39.96 * log(BMI) + 0.14 * age) / 100\n\n\\end{lstlisting}\n\n\\begin{problem}\nConsider the initial value problem\n\\begin{subequations}\n\\label{eqn:weight_prob1}\n\\begin{align*}\n\\rho_F \\dfrac{dF(t)}{dt} &= (1-p(t)) EB(t),\\\\\n\\rho_L \\dfrac{dL(t)}{dt} &= p(t) EB(t),\\\\\nF(0) &= F_0, \\\\\nL(0) &= L_0.\n\\end{align*}\n\\end{subequations}\nThe ode is given above by the function \\li{weight_odesystem}.\nTo solve this IVP for a specific individual we need initial conditions $F_0$ and $L_0.$\nThe function \\li{fat_mass} given earlier calculates $F_0$ based on an individual's body weight (kg), age, height (meters), and gender.\n$L_0$ is then given by $L_0 = BW - F_0$.\n\nSuppose a 38 year old female, standing 5'8'' and weighing 160 lbs, reduces her intake from 2143 to 2025 calories/day, and increases her physical activity from little to no exercise (PAL=1.4) to exercising to 2-3 days per week (PAL=1.5).\nFind and graph the solution curve for this single-stage weightloss intervention over a period of 5 years.\n\nNote the provided code requires quantities in metric units (kilograms, meters, days) while our graph is converted to units of pounds and days.\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{weightloss.pdf}\n\\caption{The solution of the weight change model for problem 1.}\n\\label{fig:weightloss}\n\\end{figure}\n\n\\begin{problem}\nModify the preceding problem to handle a two stage weightloss intervention:\nSuppose for the first 16 weeks intake is reduced from 2143 to 1600 calories/day and physical activity is increased from little to no exercise (PAL=1.4) to an hour of exercise 5 days per week (PAL=1.7).\nThe following 16 weeks intake is increased from 1600 to 2025 calories/day, and exercise is limited to only 2-3 days per week (PAL=1.5).\n\nFind and graph the solution curve over a period of 32 weeks.\n\\end{problem}\n\n\\section*{Two Predator-Prey Models}\nThe Lotka-Volterra predator-prey model is a well-known\nsystem of odes given by\n\\begin{align*}\n\t\\frac{du}{dt} &= au - buv,\\\\\n\t\\frac{dv}{dt} &= -cv + duv.\n\\end{align*}\nIn these odes $u$ and $v$ represent the prey and predator populations, respectively. Here $a$ represents the rate of growth of the prey, and $bu$ the amount of prey being eaten.\nSimilarly, $c$ represents the rate of natural predator death, and $du$ the growth of the predator population due to the quantity of prey eaten.\n\nLet us look at the dynamics of this system.\nFirst we note that there are exactly two equilibria (fixed points): either $(u,v) = (0,0)$ corresponding to the extinction of both species, or $(u,v) = (\\frac{c}{d},\\frac{a}{b})$.\nFurthermore, from the odes we can see that if $v=0$ (there is an absence of any predators) then the population of prey will grow exponentially.\n\nTo get a better idea of the dynamics of this system we will graph its phase portrait.\nWe begin by nondimensionalizing the system to reduce the number of parameters:\nLet $U = \\frac{d}{c}u,$ $V = \\frac{b}{a}v$, $\\bar{t} = at,$ and $\\alpha = \\frac{d}{a}$.\nSubstituting into the original odes we obtain the nondimensional system of equations\n\\begin{align*}\n\t\\frac{dU}{d\\bar{t}} &= U(1-V),\\\\\n\t\\frac{dV}{d\\bar{t}} &= \\alpha V (U-1).\n\\end{align*}\nIn the following code we plot the phase portrait.\nTo plot the direction field for the equations we use \\li{numpy}'s \\li{meshgrid} function and \\li{matplotlib}'s \\li{quiver} function.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{Lotka_Volterra.pdf}\n\\caption{The solution of the nondimensionalized Lotka-Volterra predator-prey equations with parameter $\\alpha = 1/3$.\nThis solution has initial conditions $(u,v) = (3/4, 3/4)$.}\n\\label{fig:pred-prey_Lotka_Voterra}\n\\end{figure}\n\n\\begin{lstlisting}\nfrom scipy.integrate import odeint\na, b = 0., 13.                    # (Nondimensional) Time interval for one 'period'\nalpha = 1. / 3                    # Nondimensional parameter\ndim = 2                           # dimension of the system\ny0 = np.array([1 / 2., 1 / 3.])   # initial conditions\n\n# Note: swapping order of arguments to match the calling convention\n# used in the built in IVP solver.\ndef Lotka_Volterra(y, x):\n    return np.array([y[0] * (1. - y[1]), alpha * y[1] * (y[0] - 1.)])\n\nsubintervals = 200\n# Using the built in ode solver\nY = odeint(Lotka_Volterra, y0, np.linspace(a, b, subintervals))\n\n# Plot the direction field\nY1, Y2 = np.meshgrid(np.arange(0, 4.5, .2), np.arange(0, 4.5, .2), sparse=True, copy=False)\nU, V = Lotka_Volterra((Y1, Y2), 0)\nQ = plt.quiver(Y1[::3, ::3], Y2[::3, ::3],  U[::3, ::3],  V[::3, ::3], pivot='mid', color='b', units='dots',width=3.)\n# Plot the 2 Equilibrium points\nplt.plot(1, 1, 'ok', markersize=8)\nplt.plot(0, 0, 'ok', markersize=8)\n# Plot the solution in phase space\nplt.plot(Y[:,0], Y[:,1], '-k', linewidth=2.0)\nplt.plot(Y[::10,0], Y[::10,1], '*b')\n\nplt.axis([-.5, 4.5, -.5, 4.5])\nplt.title(\"Phase Portrait of the Lotka-Volterra Predator-Prey Model\")\nplt.xlabel('Prey',fontsize=15)\nplt.ylabel('Predators',fontsize=15)\nplt.show()\n\\end{lstlisting}\n\n\\begin{problem}\nCompute the solutions $(u,v)$ of\n\\begin{align*}\n\t\\frac{dU}{d\\bar{t}} &= U(1-V),\\\\\n\t\\frac{dV}{d\\bar{t}} &= \\alpha V (U-1).\n\\end{align*}\nfor initial conditions $(1/2, 3/4)$, $(1/16, 3/4)$, and $(1/40, 3/4)$.\nAdd these solutions to the phase portrait of the Lotka-Volterra model.\nCan you see any limitations of this model?\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{Lotka_Volterra_Phase_Portrait.pdf}\n\\caption{The phase portrait for the nondimensionalized Lotka-Volterra predator-prey equations with parameters $\\alpha = 1/3$.\nThe portrait includes the direction field, the two equilibrium points, and the graph of the solution with initial conditions $(u,v) = (3/4, 3/4)$. }\n\\label{fig:pred-prey_Lotka_Voterra_Phase_Portrait}\n\\end{figure}\n\nWe have already noticed that in the absence of predators, the Lotka-Volterra equations predict that the prey population will grow exponentially.\nThe logistic predator-prey equations change this dynamic by adding a term to give the prey population a carrying capacity $K$:\n\\begin{align*}\n\t\\frac{du}{dt} &= au\\left(1 -\\frac{u}{K}\\right) - buv,\\\\\n\t\\frac{dv}{dt} &= -cv + duv.\n\\end{align*}\nLet $U = \\frac{u}{K},$ $V = \\frac{b}{a}v$, $\\bar{t} = at,$  $\\alpha = \\frac{dK}{a}$, and $\\beta = \\frac{c}{dK}$.\nThen the nondimensional logistic equations are\n\\begin{align*}\n\t\\frac{dU}{d\\bar{t}} &= U(1-U-V),\\\\\n\t\\frac{dV}{d\\bar{t}} &= \\alpha V (U-\\beta).\n\\end{align*}\n\n\\begin{problem}\nCompute the solutions $(u,v)$ of\n\\begin{align*}\n\t\\frac{dU}{d\\bar{t}} &= U(1-U-V),\\\\\n\t\\frac{dV}{d\\bar{t}} &= \\alpha V (U-\\beta).\n\\end{align*}\nfor initial conditions $(1/3, 1/3)$ and $(1/2, 1/5)$.\nDo this for parameter values $\\alpha, \\beta = 1, .3$ and also for values $\\alpha, \\beta = 1, 1.1$.\nCreate a phase portrait for the logistic equations using both sets of parameter values.\nRemember to plot the direction field, all equilibrium points, and the orbits of the solutions.\n\\end{problem} ", "meta": {"hexsha": "19489156346dc6557dae9330c40b60aab5b31928", "size": 15095, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/WeightLoss/Weightloss.tex", "max_stars_repo_name": "marissa-graham/numerical_computing", "max_stars_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/WeightLoss/Weightloss.tex", "max_issues_repo_name": "marissa-graham/numerical_computing", "max_issues_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/WeightLoss/Weightloss.tex", "max_forks_repo_name": "marissa-graham/numerical_computing", "max_forks_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.9206349206, "max_line_length": 290, "alphanum_fraction": 0.6925472011, "num_tokens": 4960, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7450934358100478}}
{"text": "\\chapter{NP-Complete}\n\nThe complexity class known as \\emph{NP-Complete} is a special subset\nof $NP$, such that any problem in \\emph{NP} can be translated to a\nproblem in \\emph{NP-Complete} in polynomial time.\n\n\\section{CIRCUIT-SAT}\n\nGiven a boolean circuit, is it possible to provide a set of inputs\nthat cause the output to be \\emph{True}?\n\nIn 1971, Cook proved that \\emph{CIRCUIT-SAT} is \\emph{NP-Complete}.\nThe proof is beyond the scope of these notes.  Cook showed that all\noperations of a polynomial-sized Turing machine can be performed in\npolynomial time using an instance of this problem.  In other words,\nCook showed that a Turing machine can be implemented using circuits\n(surprise!!).\n\n\\section{Reduction}\n\nGiven at least one \\emph{NP-Complete} problem, we can prove any other\nproblem $L$ is \\emph{NP-Complete} by showing that $L \\in NP$ and that\ngiven an instance $x$ of a proven \\emph{NP-Complete} problem we can\ntranslate $x$ to an instance of $L$ in polynomial time, such that by\nsolving our generated instance of $L$, we can solve $x$.\n\nThe steps to do this are:\n\n\\begin{enumerate}\n\\item Show $L \\in NP$.  We do this by first showing that the\n  certificate for $L$ is polynomial with respect to the input, and\n  that a certificate for $L$ can be verified in polynomial time.\n\n\\item Select a known \\emph{NP-Complete} $L'$, ideally one that is\n  similar to $L$.\n\n\\item Describe a polynomial time algorithm that maps any instance $x\n  \\in L'$ to an instance $f(x) \\in L$.\n\n\\item Show that we can solve $x \\in L'$ if and only if we can solve\n  $f(x) \\in L$.\n\\end{enumerate}\n\n\\section{SAT}\n\nGiven a boolean formula, are there values of the variables that cause\nthe formula to be \\emph{True}?\n\nFirst let us show that $SAT \\in NP$ by using the truth values as a\ncertificate, which is clearly polynomial in size because it is\nnecessarily a subset of the input.  To verify, we evaluate the formula\ngiven the truth values and return the output.\n\nNext, we select \\emph{CIRCUIT-SAT} from which to reduce to this\nproblem.\n\nThen given an instance of \\emph{CIRCUIT-SAT}, we transform the circuit\nto a boolean formula such that the circuit is satisfiable if and only\nif the formula is satisfiable.  We can do this easily by mapping gates\nto boolean operators.\n\nSince the instances of each problem are equivalent, it should be easy\nto see that one is satisfiable if and only if the other is.\n\n\\section{3CNF-SAT}\n\nIs a given boolean formula in \\emph{3CNF} form satisfiable?  A boolean\nformula is said to be in \\emph{3CNF} form if there are no more than\n$3$ variables in each clause, and within a clause there are only\n\\emph{OR} operators and between clauses there are only \\emph{AND}\noperators.\n\nBy the same proof as \\emph{SAT} above, $3CNF-SAT \\in NP$.\n\nWe reduce from \\emph{SAT}.  Given an instance of \\emph{SAT}, we use\nequivalences to reduce all boolean operators to \\emph{AND}, \\emph{OR},\nand \\emph{NOT}.  Then we use DeMorgan's law to put the formula into\n\\emph{3CNF} form.\n\nSince the instances of each problem are equivalent, it should be easy\nto see that one is satisfiable if and only if the other is.\n\n\\section{CLIQUE}\n\nGiven a simple, undirected graph $G$, find a \\emph{complete} subgraph\nof $G$ of at least size $k$.\n\nLet the certificate be the set of vertices on which there is a\ncomplete subgraph.  Since this is necessarily a subset of the input\nvertices, it must be of polynomial size.  We can verify the set of\nvertices are complete by checking that every pair of vertices $i,j$\nwhere $i \\neq j$ are adjacent, and we can easily check if the set is\nof size $k$ by counting them.\n\nWe reduce from \\emph{3CNF-SAT}.  Given an instance $\\Phi$ of \\emph{3CNF-SAT}\nwith $k$ clauses, we would like to construct an instance of\n\\emph{CLIQUE}.  Our graph has $3k$ vertices, one for each variable in\neach clause.  Clause $r$ has vertices $v^r_1,v^r_2,v^r_3$.  We put an\nedge between $v^r_i$ and $v^s_j$ if and only if:\n\n\\begin{itemize}\n\\item $r \\neq s$\n\\item their literals are consistent\n\\end{itemize}\n\n\\begin{lemma}\n  If $\\Phi$ is satisfiable, then $G$ must contain a clique of size $k$.\n\\end{lemma}\n\n\\begin{proof}\n  Assume $\\Phi$ is satisfiable, which is to say that $\\Phi$ has a\n  satisfying truth assignment.  We select the vertices corresponding\n  to that truth assignment.  Since this truth assignment satisfies\n  $\\Phi$, there must exist one selected vertex in each box.  Each of\n  these is connected to every vertex in a different box, therefore\n  there exists a clique in $G$.\n\\end{proof}\n\n\\begin{lemma}\n  If $G$ contains a clique of size $k$, then $\\Phi$ is satisfiable.\n\\end{lemma}\n\n\\begin{proof}\n  Assume $G$ contains a clique of size $k$.  One vertex of the clique\n  must be in each box.  Assign all variables corresponding to the\n  vertices of the clique to be true.  This must be a satisfying\n  assignment because at least one true variable exists in each clause,\n  and there are no inconsistent truth values.\n\\end{proof}\n\n\\begin{theorem}\n  $\\Phi$ is satisfiable if and only if $G$ contains a clique of size $k$.\n\\end{theorem}\n\n\\begin{proof}\n  This follows from the above lemmas.\n\\end{proof}\n\n\\section{VERTEX-COVER}\n\nGiven a graph $G=(V,E)$, does there exist a set of vertices $V'$ of\nsize at most $k$ such that every edge in $E$ is incident to one vertex\nin $V'$?\n\nLet the certificate be the set of vertices $V'$.  This is a subset of\n$V$, so it is polynomial with respect to the input.  We can verify\nthat $V'$ is of size at most $k$ by counting the vertices in $V'$.  We\ncan verify that the vertices in $V'$ form a vertex cover of $G$ by\nchecking that every edge in $E$ is incident to at least one vertex in\n$V'$ in polynomial time.\n\nWe reduce from \\emph{Clique}.  Let $\\overline G = (V, \\overline E)$ be\nthe complement of the graph $G$, where $\\overline E = \\{ (u,v) | (u,v)\n\\not \\in E \\}$.\n\n\\begin{lemma}\n  $\\overline G$ has a vertex cover of size $|V| - k$ if $G$ has a\n  clique of size $k$.\n\\end{lemma}\n\n\\begin{proof}\n  Assume $G$ has a clique $V'$ of size $k$.  $V \\ V'$ is a vertex\n  cover of $G$.  Let $(u,v) \\in \\overline E$, $u$ and $v$ are not both\n  in $V'$.  Either $u$ or $v$ is in $V \\ V'$.\n\\end{proof}\n\n\\begin{lemma}\n  $G$ has a clique of size $k$ if $\\overline G$ has a vertex cover of\n  size $|V| - k$.\n\\end{lemma}\n\n\\begin{proof}\n  Assume $\\overline G$ has a vertex cover $V'$ of size $|V| - k$.  For\n  all edges $(u,v) \\in \\overline E$, either $u$ is in $V'$ or $v$ is\n  in $V'$.  For all vertices $u$,$v$ and $u \\neq v$ then if neither\n  $u$ nor $v$ is in $V'$ then $(u,v) \\in E$.\n\\end{proof}\n\n\\begin{theorem}\n  $G$ has a clique of size $k$ if and only if $\\overline G$ has a\n  vertex cover of size $|V| - k$.\n\\end{theorem}\n\n\\begin{proof}\n  This follows from the preceding lemmas.\n\\end{proof}\n\n\\section{HAM-CYCLE}\n\nGiven a graph $G=(V,E)$, does there exist a simple cycle of at least\nsize $k$ that contains every vertex in $V$?\n\nThe proof that this is \\emph{NP-Complete} is beyond the scope of these\nnotes, and not terribly interesting.\n\n\\section{TSP}\n\nGiven $G=(V,E)$ which is the complete graph on $n$ vertices and each\nedge $(u,v)$ has a cost $c(u,v)$, does $G$ have a cycle which visits\neach vertex (except the start) exactly once with total cost of at most\n$k$?  We call such a cycle a \\emph{TSP-tour}\n\nLet the certificate be a permutation of the vertices which is\n$\\BigOh{|V| + 1}$, so polynomial in size.  We can verify a certificate\nby summing the edges between each of the subsequent vertices in the\npermutation and checking that the sum is at most $k$.\n\nWe reduce from \\emph{HAM-CYCLE}.  Given a graph $G=(V,E)$ on which we\nwould like to solve \\emph{HAM-CYCLE}, we create $G'=(V,E')$ where $E'\n= \\{ (u,v) | u,v \\in V, u \\neq v \\}$.  And we create a cost function:\n\n\\begin{math}\n  c(u,v) = \\left\\{ \n    \\begin{array}{l l}\n      0 & \\text{if } (u,v) \\in E \\\\\n      1 & \\text{if } (u,v) \\not \\in E \\\\\n    \\end{array} \\right.\n\\end{math}\n\nIt should be easy to see that $G$ has a \\emph{HAM-CYCLE} if and only\nif $G'$ has a \\emph{TSP-tour} of $k \\leq 0$.\n\n\\section{SUBSET-SUM}\n\nGiven a set $S$ of integers, does there exist a subset whose sum is\nexactly $k$?\n\nLet the certificate be the subset of $S$, which is clearly polynomial\nwith respect to the input.  We can verify the subset by calculating\nthe sum and comparing it to $k$ in polynomial time.\n\nWe reduce from \\emph{3CNF-SAT}.  Given a \\emph{3CNF} formula over\nvariables $x_1, ..., x_n$, and clauses $c_1,...,c_k$, we assume\nwithout loss of generality that all variables appear in at least one\nclause and no clause contains a variable and its negation.\n\nWe create two tables the columns of which are labeled with the\nvariables in order then the clauses in order.  \n\nThe first table's rows are labeled by each variable followed by its\nnegation.  The value in the table at a given row and column is 1\neither if the column is labeled with a variable and the row is labeled\nwith either that variable or its negation; or the column is labeled\nwith a clause and that clause contains exactly that variable (or\nexactly that negated variable).\n\nThe second table's rows are labeled with $s_1,s_1'$ for $c_1$, and\nsimilarly for $c_2,...,c_k$.  The value in the row labeled $s_i$ is 1\nin the column labeled $c_i$, and the value in the row labeled $s_i'$\nis 2 in the column labeled $c_i$, and 0 otherwise.\n\nThe rows of these tables give the digits of numbers in some base\n(let's say 10), and the target sum is the number with $n$ 1's followed\nby $k$ 4's.\n\nIt should be easy to see that we can find a subset which is exactly\nthe target if and only if the \\emph{3CNF} formula is satisfiable.\n\n\\section{0/1-Integer Programming}\n\nBeyond the scope of these notes, but interesting.\n\n\\section{3-COLOR}\n\nGiven a graph $G=(V,E)$, can we label the vertices of a graph using 3\ncolors such that no adjacent vertices have the same color?\n\nBeyond the scope of these notes, but interesting.\n\n", "meta": {"hexsha": "84467ad38ec127480b65c13462849ecd70f388a3", "size": 9862, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "np_complete.tex", "max_stars_repo_name": "SteamedPears/AllTheAlgorithms", "max_stars_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-10-12T19:16:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-01T03:13:05.000Z", "max_issues_repo_path": "np_complete.tex", "max_issues_repo_name": "SteamedPears/AllTheAlgorithms", "max_issues_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "np_complete.tex", "max_forks_repo_name": "SteamedPears/AllTheAlgorithms", "max_forks_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.5259259259, "max_line_length": 76, "alphanum_fraction": 0.7163861286, "num_tokens": 2934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180245, "lm_q2_score": 0.8918110440002044, "lm_q1q2_score": 0.7450934308565078}}
{"text": "\\section{Discontinuity Types}\r\nThere are four major types of discontinuity.\r\n\\begin{enumerate}[label=]\r\n\t\\item \\textbf{Removable: } If $f$ is discontinuous at $c$ but we can remove the discontinuity by setting $f$ equal to its limit at $c$, then $f$ has a removable discontinuity at $c$.\r\n\t\\item \\textbf{Jump: } If $f$ is discontinuous at $c$, and both of the one-sided limits exist but are different, then $f$ has a jump discontinuity at $c$.\r\n\t\\item \\textbf{Infinite: } If $f$ has a vertical asymptote at $c$, meaning one or both sides go to $\\pm\\infty$, then $f$ has an infinite discontinuity at $c$.\r\n\t\\item \\textbf{Oscillating: } If $f$ oscillates without limit at $c$, then $f$ has an oscillating discontinuity at $c$. An example of such a function would be $\\sin{\\frac{1}{x}}$ at $x=0$.\r\n\\end{enumerate}\r\n\r\n\r\nIt might seem strange that $\\sin{\\frac{1}{x}}$ has an oscillating discontinuity at $x=0$ because we were able to find the limit as $x$ approaches of 0 of $x\\sin{\\frac{1}{x}}$, a very similar function.\r\nHowever, remembering how we applied the Ham Sandwich Theorem to find this limit, we see that the $x$ term bounds the amplitude of the oscillations, allowing the limit to be $0$.\r\n\r\n\\begin{example}\r\n\tFor the following function state the following: its domain, any discontinuities and their types, what values should redefine the function to remove any removable discontinuities (give the extended function).\r\n\t\\begin{equation*}\r\n\t\tf(x) = \\frac{x^3-7x-6}{x^2-9}\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tPolynomials are continuous on their entire domain of all real numbers.\r\n\tSo, rational functions like $f$ can only be discontinuous when the denominator is equal to $0$.\r\n\tThis happens in two places: $x=3$ and $x=-3$.\r\n\tWe'll check the limits from each side at each of these points to determine the type of discontinuity.\r\n\tFor $x=3$,\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to 3^+}{f(x)} = \\lim_{x\\to 3^-}{f(x)} = \\lim_{x\\to 3}{f(x)} = \\lim_{x\\to 3}{\\frac{(x+2)(x+1)(x-3)}{(x+3)(x-3)}} = \\lim_{x\\to 3}{\\frac{(x+2)(x+1)}{(x+3)}} = \\frac{20}{6} = \\frac{10}{3}.\r\n\t\\end{equation*}\r\n\t\r\n\tSo, $f$ has a removable discontinuity at $x=3$ because the left and right limits are the same.\r\n\tFor $x=3$,\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to -3^+}{f(x)} = -\\infty \\text{ and } \\lim_{x\\to -3^+}{f(x)} = \\infty.\r\n\t\\end{equation*}\r\n\t\r\n\tSo, $f$ has an infinite discontinuity at $x=-3$ because both of the left and right limits go to $\\pm\\infty$.\r\n\tThe value we got from the limits at $x=3$ gives us the value we need to redefine $f$ as to remove the discontinuity.\r\n\tThe extended function is therefore\r\n\t\\begin{equation*}\r\n\t\tf_{e}(x) = \\begin{cases}\r\n\t\t\tf(x) & x \\neq 3 \\\\\r\n\t\t\t\\frac{10}{3} & x = 3\r\n\t\t\\end{cases}\r\n\t\\end{equation*}\r\n\\end{answer}", "meta": {"hexsha": "3ee7a2cac2bd6f045f44ca38ac969923271f1dc3", "size": 2742, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/limits_continuity/discontinuity_types.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/limits_continuity/discontinuity_types.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/limits_continuity/discontinuity_types.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.9333333333, "max_line_length": 209, "alphanum_fraction": 0.6794310722, "num_tokens": 899, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.745015840407151}}
{"text": "\\chapter{First Order Logic}\n\n\\emph{\"All men are mortal. Socrates is a man. Socrates is mortal.\"}\n\n\\section{Syntax of First-Order Logic}\n\nWe start with the symbols of a \\textbf{first-order language} $\\mathbb{L}$\n\nThere are two types of symbols\n\n\\begin{itemize}\n    \\item \\textbf{Logical symbols}\n    \\item Non-logical symbols, a.k.a. \\textbf{parameters}\n\\end{itemize}\n\n\\subsection{Symbols}\n\n\\subsubsection{Logical Symbols}\n\nIn a first-order language $\\mathbb{L}$, we have the following symbols\n\n\\begin{enumerate}\n    \\item \\textbf{Parentheses}. Two symbols `(' and `)'.\n    \\item \\textbf{Logical connective symbols}. $\\to$ and $\\neg$\n    \\item \\textbf{Variables}. An enumerable list of symbols $v_1,\\dots,v_n,\\dots$\n    \\item \\textbf{Identity or Equalily Symbol} $=$ or $\\doteq$. It may or may not be present in a particular first-order language\n\\end{enumerate}\n\nNotice that we do not need $\\vee$, $\\wedge$. $\\leftrightarrow$ because $\\{\\to, \\neg\\}$ is complete.\n\n\\subsubsection{Parameters}\n\n\\begin{enumerate}\n    \\item \\textbf{Universal quantifier}. $\\forall$\n    \\item For each $n>0$, there is a set (possibly empty) of objects called n-ary (or n-place) \\textbf{predicate symbols}\n    \\item For each $n>0$, there is a set (possibly empty) of objects called n-ary (or n-place) \\textbf{function symbols}\n    \\item A set of (possibly empty) of objects \\textbf{constant symbols}\n\\end{enumerate}\n\n\\subsubsection{Further Requirements}\n\n\\begin{itemize}\n    \\item $\\doteq$ is a 2-ary predicate symbols\n    \\item There is at least one predicate symbol\n    \\item The symbols are distinct, and no symbol is equal to a finite sequence of other symbols\n\\end{itemize}\n\n\\subsubsection{Example: Set Theory as First-Order Logic}\n\nThe Set Theory can be described by the following language\n\n\\begin{itemize}\n    \\item Equality\n    \\item Predicate symbols: 2-place $\\dot{\\in}$\n    \\item Constant symbols: empty set $\\dot{\\emptyset}$\n    \\item Function symbols: None\n\\end{itemize}\n\nNote that the symbols are (currently) just interpreted as symbols and they do not have semantic meanings.\n\n\\begin{remark}\n    We do not put restrictions or requirements on number of predicate, function or constant symbols.\n\\end{remark}\n\n\\subsection{Expressions}\n\nAn \\textbf{expression} in a language $\\mathbb{L}$ is a finite sequence of symbols.\n\n\\subsubsection{Terms}\n\n\\begin{definition}[Term Building Operation]\n    \\label{def:TermBuildingOperation}\n    Given any n-ary function symbol $f$, the term-building operation $\\mathcal{F}_f$ is defined by\n    \\[ \\mathcal{F}_f (\\sigma_1,\\dots,\\sigma_n) = f \\sigma_1\\dots\\sigma_n \\]\n    We call $\\sigma_i$ the arguments to $f$\n\\end{definition}\n\n\\begin{definition}[Term]\n    \\label{def:Term}\n    A \\textbf{term} is an expression built up from constant symbols and variables by applying some finite times (zero or more times) of term-building operations.\n\\end{definition}\n\nFor example, let $f$ and $g$ be 2-ary and 3-ary function symbols, then $gfc_1c_2v_3c_1$ is a term.\n\n\\begin{definition}[Term Sequence]\n    \\label{def:TermSequence}\n    A \\textbf{term sequence} is a finite sequence $t_1,\\dots,t_n$ of expressions s.t. each $t_i$ is\n    \\begin{itemize}\n        \\item either a variable, a constant\n        \\item or is in the form of $f\\sigma_1\\dots\\sigma_k$ where $f$ is a $f$-ary function and each $\\sigma_1,\\dots,\\sigma_k$ occurs earlier in the sequence\n    \\end{itemize}\n\\end{definition}\n\n\\begin{proposition}\n    An expression $t$ is a term iff there is a term sequence $t_1,\\dots,t_n$ such that $t=t_n$\n\\end{proposition}\n\n\\subsubsection{Atomic Formulas}\n\n\\begin{definition}[Atomic Formula]\n    \\label{def:AtomicFormula}\n    An expression is an \\textbf{atomic formula} if it is of the form $P t_1\\dots t_n$ where $t_1,\\dots,t_n$ are terms and $P$ is a n-ary predicate symbol.\n\\end{definition}\n\n\\subsection{Well-Formed Formulas}\n\n\\begin{definition}[Formula-Building Operations]~{}\n    \\label{def:FormulaBuildingOperation}\n    \\begin{itemize}\n        \\item $\\xi_\\neg(\\alpha) = (\\neg \\alpha)$\n        \\item $\\xi_\\to(\\alpha, \\beta) = (\\alpha\\to\\beta)$\n        \\item $\\mathcal{Q}_i(\\gamma) = \\forall v_i\\gamma$\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[Well-Formed Formula]\n    A \\textbf{well-formed formula} (wff) is an expression built up from atomic formulas by applying some finite times of term-building operations.\n\\end{definition}\n\n\\begin{definition}[Well-Formed Sequence]\n    A \\textbf{well-formed sequence} is a finite sequence $\\alpha_1,\\dots,\\alpha_n$ of expressions such that each $\\alpha_i$ is\n    \\begin{itemize}\n        \\item either an atomic formula\n        \\item or is of the form of $(\\neg \\beta)$ or $(\\beta\\to\\gamma)$ where $\\beta$ and $\\gamma$ occur earlier in the list\n        \\item or is of the form $\\forall v_i\\beta$ where $\\beta$ occurs earlier in the list\n    \\end{itemize}\n\\end{definition}\n\n\\begin{proposition}\n    The expression $\\alpha$ is a wff if there is a well-formed sequence $\\alpha_1,\\dots,\\alpha_k$ such that $\\alpha = \\alpha_k$\n\\end{proposition}\n\n\\subsection{Abbreviations}\n\n\\begin{itemize}\n    \\item $(\\alpha\\vee\\beta)$ abbreviates $((\\neg\\alpha)\\to\\beta)$\n    \\item $(\\alpha\\wedge\\beta)$ abbreviates $(\\neg(\\alpha \\to (\\neg\\beta)))$\n    \\item $(\\alpha\\leftrightarrow\\beta)$ abbreviates $(\\alpha\\to\\beta)\\wedge(\\beta\\to\\alpha)$\n    \\item $\\exists x\\alpha$ abbreviates $(\\neg\\forall x(\\neg\\alpha))$\n    \\item $u\\doteq t$ abbreviates $\\doteq ut$\n    \\item $u \\dot{\\neq} t$ abbreviates $\\dot{\\neq} ut$\n    \\item Outer-most parentheses can be omitted\n    \\item $\\neg$, $\\forall$, $\\exists$ apply to as little as possible\n    \\item $\\wedge$, $\\vee$ apply to as little as possible, subject to previous operators\n    \\item Grouping for repeated connectives is to the right\n\\end{itemize}\n\n\\subsection{Free Occurrence of Variables}\n\n\\begin{definition}[Free Occurrence]\n    The variable $x$ \\textbf{occurs free} in an atomic wff $\\varphi$ iff it occurs in $\\varphi$.\n\n    $x$ \\textbf{occurs free} in $\\neg\\alpha$ iff $x$ occurs free in $\\alpha$.\n\n    $x$ \\textbf{occurs free} in $\\alpha\\to\\beta$ iff $x$ occurs free in $\\alpha$ or in $\\beta$.\n\n    $x$ \\textbf{occurs free} in $\\forall y \\alpha$ iff $x$ occurs free in $\\alpha$ and $x \\neq y$.\n\\end{definition}\n\n\\begin{definition}[Sentence]\n    $\\varphi$ is a \\textbf{sentence} iff no variable occurs free in $\\varphi$.\n\\end{definition}\n\\begin{remark}\n    Sentences are usually represented by $\\sigma$ or $\\tau$.\n\\end{remark}\n\nWe provide some examples\n\n\\begin{itemize}\n    \\item $\\dot{0} \\dot{<} \\dot{1}$ does not have any free occurrence. It is a sentence,\n    \\item $\\forall x(x\\dot{<}y)$. $y$ occurs free but $x$ does not.\n    \\item $\\forall x(\\neg x \\dot{<} \\dot{0})$. No free occurrence.\n    \\item $\\forall x\\forall y (x \\dot{<} y \\to \\exists z x\\dot{<}z\\wedge z\\dot{<}y)$. No free occurrence.\n\\end{itemize}\n\n\\section{Semantics of First-Order Logic}\n\n\\subsection{Structures}\n\n\\begin{definition}\n    Given a first order language $\\mathbb{L}$, a \\textbf{structure} $\\mathfrak{A}$ for $\\mathbb{L}$ consists of\n    \\begin{itemize}\n        \\item A non-empty set called the \\textbf{universe} or \\textbf{domain} of the structure, written as $|\\mathfrak{A}|$\n        \\item For each n-ary predicate symbol $P$ of $\\mathcal{L}$, other than $\\doteq$, an n-ary relation $\\mathbb{P}^{\\mathfrak{A}}$ on $|\\mathfrak{A}|$\n        \\item $\\doteq^{\\mathfrak{A}}$ is the identity relation on $|\\mathfrak{A}|$. $\\doteq^{\\mathfrak{A}} = \\{(a,b)|a,b\\in|\\mathfrak{A}, a =b|\\}$\n        \\item For each n-ary function symbol $f$ of $\\mathbb{L}$, an n-ary ooperation on the universe, i.e. an n-ary function $f^{\\mathfrak{A}}: |\\mathfrak{A}|\\times\\cdots\\times|\\mathfrak{A}|\\mapsto|\\mathfrak{A}|$\n        \\item For each constant symbol $c$ of $\\mathbb{L}$, $c^{\\mathfrak{A}}\\in|\\mathfrak{A}|$\n    \\end{itemize}\n\\end{definition}\n\n\\subsection{Assignments}\n\nLet $\\mathfrak{A}$ be a structure for language $\\mathbb{L}$. Let $V$ be the set of variables, and $T$ be the set of terms.\n\n\\begin{definition}[Assignment Functions]\n    An \\textbf{assignment} for $\\mathfrak{A}$ is a function $s:V\\mapsto|\\mathfrak{A}|$.\n\\end{definition}\n\n\\begin{definition}[Assignment to Terms]\n    An assignment $s$ is extended to a function $\\bar{s}:T\\mapsto|\\mathfrak{A}|$.\n    \\begin{itemize}\n        \\item $\\bar{s}(v) = s(v)$ if $v$ is a variable\n        \\item $\\bar{s}(c) = c^{\\mathfrak{A}}$ if $c$ is a constant\n        \\item $\\bar{s}(ft_1\\dots t_n) = f^{\\mathfrak{A}}(\\bar{s}(t_1),\\dots,\\bar{s}(t_n))$ if $f$ is a n-ary function symbol and $t_1,\\dots,t_n$ are terms\n    \\end{itemize}\n\\end{definition}\n\n\\subsubsection{Changing the Assignment Function}\n\nLet $s$ be an assignment function, $x$ be a variable and $a\\in\\mathfrak{A}$. Then $s(x|a)$ is the new assignment, where for each variable $y$\n\n\\[s(x|a)(y) = \\begin{cases}\n    s(y) &\\quad \\text{if $(y\\neq x)$}\\\\\n    a &\\quad \\text{if $(y=x)$}\n\\end{cases}\\]\n\nThis operation actually ``overrides'' the assignment of $s$ to $x$ and makes the assignment to $x$ equal to $a$.\n\n\\section{Satisfaction}\n\nGiven a first-order language $\\mathbb{L}$, let $\\mathfrak{A}$ be a structure for $\\mathbb{L}$, let $s$ be an assignment for $\\mathbb{L}$ and let $\\varphi$ be a wff in $\\mathbb{L}$. We denote $\\mathfrak{A}$ to satisfy $\\varphi$ with $s$ by $\\vDash_{\\mathfrak{A}}\\varphi[s]$\n\nInformally, it means ``\\emph{The translation of $\\varphi$ determined by $\\mathfrak{A}$, where a variable $x$ is translated as $s(x)$, is true}''\n\n\\subsection{Satisfaction for Atomic Formulas}\n\n\\begin{definition}\n    Given a language $\\mathbb{L}$ and a structure $\\mathfrak{A}$, let $s$ be an assignment, let $P$ be a n-ary predicate,\n    \\[ \\vDash_{\\mathfrak{A}} Pt_1\\dots t_n[s] \\Leftrightarrow (\\bar{s}(t_1),\\dots,\\bar{s}(t_n)) \\in P^{\\mathfrak{A}} \\]\n    \\[ \\vDash_{\\mathfrak{A}} \\doteq t_1t_2[s] \\Leftrightarrow \\bar{s}(t_1) = \\bar{s}(t_2) \\]\n\\end{definition}\n\n\\subsection{Satisfaction for WFF}\n\n\\begin{definition}\n    Suppose $\\vDash_{\\mathfrak{A}}\\alpha[s]$ and $\\vDash_{\\mathfrak{A}}\\beta[s]$ have been defined, then\n    \\begin{itemize}\n        \\item $\\vDash_{\\mathfrak{A}} \\neg\\alpha[s]$ iff not $\\vDash_{\\mathfrak{A}}\\alpha[s]$\n        \\item $\\vDash_{\\mathfrak{A}}\\alpha\\to\\beta[s]$ iff $\\vDash_{\\mathfrak{A}}\\alpha[s]\\Longrightarrow\\vDash_{\\mathfrak{A}}\\beta[s]$\n        \\item $\\vDash_{\\mathfrak{A}}\\forall x \\alpha[s]$ iff $\\forall a\\in|\\mathfrak{A}|$, $\\vDash_{\\mathfrak{A}}\\alpha[s(x|a)]$\n    \\end{itemize}\n\\end{definition}\n\nIf $\\vDash_{\\mathfrak{A}}\\varphi[s]$, we say \\emph{$\\mathfrak{A}$ satisfies $\\varphi$ with $s$}, or \\emph{$s$ satisfies $\\varphi$ in the structure $\\mathfrak{A}$}\n\n\\subsubsection{Satisfaction Depends Only on Variables that Occur Free}\n\n\\begin{lemma}\n    \\label{lem:LemmaForFreeOccurrenceThm}\n    Let $\\mathfrak{A}$ be a structure for $\\mathbb{L}$, $s_1, s_2$ be two assignment for $\\mathfrak{A}$ and $t$ be a term of $\\mathbb{L}$.\n\n    If $s_1(x)=s_2(x)$ for every $x$ that occurs in $t$, then\n    \\[ \\bar{s}_1(t) = \\bar{s}_2(t) \\]\n\\end{lemma}\n\\begin{proof}\n    Proof by induction on $t$.\n    \\begin{itemize}\n        \\item[Base] If $t=c$ is a constant. It is straightforward that $\\bar{s}_1(t) = \\bar{s}_2(t) = c$. If $t=x$ is a variable, then by assumption we know that $\\bar{s}_1(x) = s_1(x) = s_2(x) = \\bar{s}_2(x)$. So we are done.\n        \\item[Induction] Consider a term $t=ft_1\\dots t_n$. By inductive hypothesis we know that $\\forall i$, $\\bar{s}_1(t_i) = \\bar{s}_2(t_i)$. $\\bar{s}_1(t) = f^{\\mathfrak{A}}(\\bar{s}_1(t), \\dots, \\bar{s}_1(t) = f^{\\mathfrak{A}}(\\bar{s}_2(t), \\dots, \\bar{s}_2(t)) = \\bar{s}_2(t)$.\n    \\end{itemize}\n\\end{proof}\n\n\\begin{theorem}\n    Let $\\mathfrak{A}$ be a structure for $\\mathbb{L}$, $s_1, s_2$ be two assignment for $\\mathfrak{A}$ and $\\varphi$ be a wff of $\\mathbb{L}$.\n\n    If $s_1(x)=s_2(x)$ for every $x$ that occurs free in $\\varphi$, then\n    \\[ \\vDash_{\\mathfrak{A}}\\varphi[s_1] \\iff \\vDash_{\\mathfrak{A}}\\varphi[s_2] \\]\n\\end{theorem}\n\n\\begin{proof}\n    Prove by induction on $\\varphi$.\n    \\begin{itemize}\n        \\item[Base] If $\\varphi$ is an atomic formula $Pt_1\\dots t_n$.\n        \\[ \\vDash_{\\mathfrak{A}} \\varphi [s_1] \\Leftrightarrow P^{\\mathfrak{A}}(\\bar{s}_1(t_1),\\dots,\\bar{s}_1(t_n)) \\]\n        \\[ \\vDash_{\\mathfrak{A}} \\varphi [s_2] \\Leftrightarrow P^{\\mathfrak{A}}(\\bar{s}_2(t_1),\\dots,\\bar{s}_2(t_n)) \\]\n\n        We need to prove that the two RHSes are equivalent. By Lemma~\\ref{lem:LemmaForFreeOccurrenceThm} we know that all the terms are equal under $s_1$ and $s_2$, and therefore $\\vDash_{\\mathfrak{A}} \\varphi [s_1] = \\vDash_{\\mathfrak{A}} \\varphi [s_2]$.\n\n        \\item[Induction] Consider $\\varphi=\\neg\\alpha$.\n        \\[ \\vDash_{\\mathfrak{A}}(\\neg\\alpha)[s_1] \\Leftrightarrow \\nvDash_{\\mathfrak{A}}\\alpha[s_1] \\Leftrightarrow \\nvDash_{\\mathfrak{A}}\\alpha[s_2] \\Leftrightarrow \\vDash_{\\mathfrak{A}}(\\neg\\alpha)[s_2] \\]\n\n        The case $\\varphi = \\alpha\\to\\beta$ is similar.\n\n        Consider the case $\\forall x \\alpha$. We want to prove\n        \\[ \\sat{A}{\\forall x\\alpha}{s_1} \\Leftrightarrow \\sat{A}{\\forall x\\alpha}{s_2} \\]\n        which is equivalent to\n        \\[ \\forall a\\in|\\mathfrak{A}|\\sat{A}{\\alpha}{s_1(x|a)} \\Leftrightarrow \\forall a \\in |\\frakA| \\sat{A}{\\alpha}{s_2(x|a)} \\]\n\n        We only need to prove that\n        \\[ \\forall y \\text{occurring free in $\\alpha$}, s_1(x|a)(y) = s_2(x|a)(y) \\]\n\n        If $y\\neq x$, then $y$ is still occurring free in $\\alpha$, and by inductive hypothesis they should equal. If $y=x$, then both sides are $a$. So we are done.\n    \\end{itemize}\n\\end{proof}\n\\begin{remark}\n    This theorem is somewhat similar to the theorem in sentential logic, which states that we only need to consider sentence symbols. Similarly, in first-order logic, we only need to consider variables that occur free.\n\\end{remark}\n\n\\begin{definition}\n    Let $\\varphi$ be a wff s.t. all variables occurring free in $\\varphi$ are included amoing $v_1,\\dots,v_k$. Given $a_1,\\dots,a_k\\in\\frakA$.\n\n    \\[ \\assignSat{A}{\\varphi}{a_1,\\dots,a_k} \\]\n\n    means that $\\sat{A}{\\varphi}{s}$ for some $s:V\\mapsto|\\frakA|$ s.t. $s(v_i) = a_i$\n\\end{definition}\n\n\\begin{corollary}\n    If $\\sigma$ is a sentence then\n    \\begin{itemize}\n        \\item either $\\sat{A}{\\sigma}{s}$ for every assignment $s$. We say $\\sigma$ is true in $\\frakA$.\n        \\item or $\\unsat{A}{\\sigma}{s}$ for every assignment $s$. We say $\\sigma$ is false in $\\frakA$\n    \\end{itemize}\n\\end{corollary}\n\nTherefore a sentence does not depend on $s$, and we can simply write $\\sentSat{A}{\\sigma}$ or $\\sentunsat{A}{\\sigma}$.\n\n\\subsection{Elementary Equivalence}\n\n\\begin{definition}[Elementary Equivalence]\n    \\label{def:ElementaryEquivalence}\n    Let $\\mathfrak{A}$ and $\\mathfrak{B}$ be structures for the same language $\\mathbb{L}$. $\\mathfrak{A}$ and $\\mathfrak{B}$ are \\textbf{elementarily equivalent} ($\\mathfrak{A} \\equiv \\mathfrak{B}$) if for every \\emph{sentence} of $\\mathbb{L}$\n    \\[ \\sentSat{A}{\\sigma} \\iff \\sentSat{B}{\\sigma} \\]\n\\end{definition}\n\n\\begin{remark}\n    Elementary equivalence only take into consideration sentences.\n\\end{remark}\n\n\\begin{proposition}\n    $\\mathfrak{Q}$ and $\\mathfrak{R}$ are elementary equivalent. But this is beyond the scope of the course.\n\\end{proposition}\n\n\\section{Models}\n\n\\subsection{Models}\n\n\\begin{definition}[Model]\n    $\\mathfrak{A}$ is a \\textbf{model} of the sentence $\\sigma$ if $\\sentSat{A}{\\sigma}$, i.e. if $\\sigma$ is true in $\\mathfrak{A}$. $\\mathfrak{A}$ is a \\textbf{model} of a set $\\Sigma$ of sentences if $\\mathfrak{A}$ is a model for every sentence in $\\Sigma$. i.e. every sentence in $\\Sigma$ is true in $\\mathfrak{A}$.\n\\end{definition}\n\nFor example, consider a first-order language $\\mathbb{L}$, with 2-ary predicate symbols $\\dot{P}$ and $\\doteq$. Given a structure $\\mathfrak{A}$ of $\\mathbb{L}$,\n\n\\begin{itemize}\n    \\item $\\mathfrak{A}$ is a model of $\\forall x \\forall y x \\doteq y$\n    \\begin{itemize}\n        \\item $\\Leftrightarrow \\sat{A}{x\\doteq y}{s(x|a)(y|b)}$ for every $a,b \\in |\\mathfrak{A}|$\n        \\item $\\Leftrightarrow$ $a = b$ for every $a,b \\in|\\mathfrak{A}|$\n        \\item $\\Leftrightarrow$ $|\\mathfrak{A}|$ contains only one element.\n        \\item Note that $|\\frakA|$ cannot be empty because the universe of a structure must be non-empty.\n    \\end{itemize}\n    \\item $\\mathfrak{A}$ is a model of $\\forall x \\forall y \\dot{P}xy$\n    \\begin{itemize}\n        \\item iff $P^\\mathfrak{A}(a,b)$ for all $a,b\\in|\\mathfrak{A}|$\n        \\item iff $\\dot{P}^{\\frakA} = |\\frakA| \\times |\\frakA|$\n    \\end{itemize}\n    \\item $\\mathfrak{A}$ is a model of $\\forall x \\forall y \\neg\\dot{P}xy$\n    \\begin{itemize}\n        \\item iff $P^{\\frakA}(a,b)$ does not hold for all $a,b\\in|\\frakA|$\n        \\item iff $\\dot{P}^{\\frakA} = \\emptyset$\n    \\end{itemize}\n    \\item $\\frakA$ is a model of $\\forall x \\exists y \\dot{P}xy$\n    \\begin{itemize}\n        \\item iff forall $a\\in|\\frakA|$, there is a $b\\in|\\frakA|$ s.t. $\\dot{P}^{\\frakA}(a,b)$\n        \\item iff the domain of $\\dot{P}^{\\frakA}$ is $|\\frakA|$\n        \\item Conversely, if we want the range of $\\dot{P}^{\\frakA}$ is $|\\frakA|$, we can write $\\forall y \\exists x \\dot{P}xy$\n    \\end{itemize}\n\\end{itemize}\n\n\\subsection{Linearly Ordered Structures}\n\n\\begin{definition}[Trichotomy]\n    Let $R$ be a binary relation, $R$ satisfies \\textbf{trichotomy} if exactly one of the following is true\n    \\[ (a,b) \\in R \\quad (b,a) \\in R \\quad a = b \\]\n\\end{definition}\n\n\\begin{definition}[Linear Ordering]\n    A binary relation $R$ is a \\textbf{linear ordering} on $A$ if $R$ is transitive and satisfies trichotomy on $A$.\n\\end{definition}\n\n\\begin{definition}\n    Let $\\mathbb{L}$ be the language with a binary relation symbol $\\dot{R}$ and $\\doteq$ (and no other symbols). Let $\\frakA = (A,R)$, i.e. $A=|\\frakA|$ and $R = \\dot{R}^{\\frakA}$.\n    \\begin{itemize}\n        \\item $\\frakA$ is transitive if $R$ is transitive\n        \\item $\\frakA$ is a linearly ordered structure if $R$ is a linear ordering on $\\frakA$\n    \\end{itemize}\n\\end{definition}\n\nFor a set of structures with some certain properties, the set can be defined by a sentence.\n\nLet $\\frakA = (A,R)$,\n\\begin{itemize}\n    \\item $\\frakA$ is transitive iff $\\sentSat{A}{\\sigma}$, where $\\sigma=\\forall x \\forall y \\forall z \\dot{R}xy \\to \\dot{R}yz \\to \\dot{R}xz$. Therefore $\\sigma$ defines the set of all transitive structures\n    \\item $\\frakA$ is linearly ordered iff $\\sentSat{A}{\\sigma}$ where\n    \\begin{itemize}\n        \\item $\\sigma_1 = \\forall x \\forall y \\forall z \\dot{R}xy \\to \\dot{R}yz \\to \\dot{R}xz$\n        \\item $\\sigma_2 = \\forall x \\forall y (\\dot{R}xy \\vee x=y \\vee \\dot{R}yx)$\n        \\item $\\sigma_3 = \\forall x \\forall y (\\dot{R}xy \\to \\neg\\dot{R}yx)$\n        \\item $\\sigma = \\sigma_1 \\wedge \\sigma_2 \\wedge \\sigma_3$\n    \\end{itemize}\n    Therefore $\\sigma$ defines the set of all linearly ordered structures\n    \\item $\\domain{R} = A$ iff $\\sentSat{A}{\\sigma}$ where $\\sigma = \\forall x \\exists y \\dot{R}xy$\n    \\item $\\range{R} = A$ iff $\\sentSat{A}{\\sigma}$ where $\\sigma = \\forall y \\exists x \\dot{R}xy$\n    \\item $R$ is a (total) function iff $\\sentSat{A}{\\sigma}$ where\n    \\begin{itemize}\n        \\item $\\sigma_4 =  \\forall x \\exists y \\dot{R}xy$\n        \\item $\\sigma_5 = \\forall x \\forall y \\forall z \\dot{R}xy \\to \\dot{R}xz \\to x \\doteq z$\n        \\item $\\sigma = \\sigma_4 \\wedge \\sigma_5$\n    \\end{itemize}\n\\end{itemize}\n\n\\subsection{Elementary Class}\n\n\\begin{definition}[Elementary Class]\n    A set of strucutures $\\mathcal{K}$ is an \\textbf{elementary class} if there exists a sentence $\\sigma$ s.t.\n    \\[ \\mathcal{K} = \\{ \\frakA | \\frakA \\text{ is a model of $\\sigma$} \\} \\]\n    i.e.\n    \\[ \\mathcal{K} = \\{ \\frakA | \\sentSat{A}{\\sigma} \\} \\]\n\\end{definition}\n\nFor example, the set of all graphs is an elementary class.\n\nLet $\\mathbb{L}$ be the language with a binary predicate symbol $\\dot{E}$ and $\\doteq$, and no other symbols. A structure $\\mathfrak{G} = (G, E)$ for $\\mathbb{L}$ is a graph if\n\\begin{itemize}\n    \\item $E$ is symmetric (undirected graph)\n    \\item For every $a \\in G$, $(a, a) \\notin E$ (no self-loops)\n\\end{itemize}\n\nTo show that the set of graphs defined above is an elementary class, we need to show that there is a sentence $\\sigma$ s.t.\n\\[ \\text{$G$ is a graph} \\Leftrightarrow \\sentSat{G}{\\sigma} \\]\n\nTherefore $\\sigma$ should be able to represent the symmetric and non-reflexible properties.\n\n\\[\\sigma = (\\forall x \\forall y (\\dot{E}xy \\to \\dot{E}yx)) \\wedge (\\forall x(\\neg \\dot{E}xx))\\]\n\n\\subsubsection{In the Wider Sense}\n\n\\begin{definition}[Elementary Class in the Wider Sense]\n    A set of structures $\\mathcal{K}$ is an \\textbf{elementary class in the wider sense} ($EC_\\Delta$) if there is a set $\\Sigma$ of sentences s.t.\n    \\[ \\mathcal{K} = \\{ \\frakA | \\frakA \\text{ is a model of } \\Sigma \\} \\]\n    i.e.\n    \\[ \\mathcal{K} = \\{ \\frakA | \\sentSat{A}{\\sigma} \\text{ for every $\\sigma \\in \\Sigma$} \\} \\]\n\\end{definition}\n\nFor example, we can use a set $\\Sigma$ to define the set of strucutures whose univerise is infinite.\n\n\\[ \\Sigma = \\{ \\lambda_2, \\lambda_3, \\dots, \\lambda_n, \\dots \\} \\]\n\nwhere $\\lambda_i$ denotes ``At least $i$ elements exists in $|\\frakA|$'', for example $\\lambda_2 = \\exists x \\exists y x \\neq y$.\n\nHowever, it is hard to decide whether there is a single sentence $\\sigma$ s.t. $\\frakA$ is a model of $\\sigma$ iff $|\\frakA|$ is infinite.\n\n\\section{Logical Implications and Satisfiability}\n\n\\subsection{Logical Implications}\n\n\\begin{definition}\n    Let $\\Gamma$ be a set of wffs and $\\varphi$ be a wff. $\\Gamma$ \\textbf{logically implies} $\\varphi$, written as\n    \\[ \\Gamma \\vDash \\varphi \\]\n    if for every structure $\\frakA$ and every assignment $s$, if $\\frakA$ satisfies $\\Gamma$ with $s$, then $\\frakA$ satisfies $\\varphi$ with $s$\n\\end{definition}\n\n\\begin{theorem}\n    For a set of sentences $\\Sigma$, and a sentence $\\sigma$, $\\Sigma\\vDash\\sigma$ iff for every model $\\frakA$ of $\\Sigma$, $\\frakA$ is a model of $\\sigma$.\n\\end{theorem}\n\nAs before, we denote $\\{\\alpha\\}\\vDash\\beta$ by $\\alpha\\vDash\\beta$\n\n\\subsection{Logical Equivalence}\n\n\\begin{definition}[Logical Equivalence]\n    $\\alpha$ and $\\beta$ are logically equivalent, written as $\\alpha\\vDash\\Dashv\\beta$ if $\\alpha\\vDash\\beta$ and $\\beta\\vDash\\alpha$\n\\end{definition}\n\n\\subsection{Valid Formulas}\n\n\\begin{definition}[Valid WFFs]\n    Let $\\varphi$ be a wff in the language $\\mathbb{L}$. $\\varphi$ is \\textbf{valid} if $\\semanticalImply{\\emptyset}{\\varphi}$, written as $\\tautology{\\varphi}$.\n\\end{definition}\n\nFor example,\n\n\\begin{itemize}\n    \\item $x \\doteq x$ is valid\n    \\item $\\exists x \\doteq x$ is valid\n    \\item $\\forall x \\exists y x\\dot{\\neq}y$ is not valid\n    \\item $\\dot{P}x \\vee \\neg \\dot{P}x$ is valid\n    \\item $\\exists x(\\dot{P}x \\to \\forall x \\dot{P}x)$ is valid\n\\end{itemize}\n\nWe detail the proof of the last example\n\n\\begin{itemize}\n    \\item $\\sat{A}{\\exists x (Px\\to\\forall x Px)}{s}$\n    \\item[$\\Leftrightarrow$] There is some $a \\in |\\frakA|$ s.t. $\\sat{A}{Px \\to \\forall x Px}{s(x|a)}$\n    \\item[$\\Leftrightarrow$] $\\sat{A}{\\dot{P}(x)}{s(x|a)} \\Rightarrow \\sat{A}{\\forall x Px}{s(x|a)}$\n    \\item[$\\Leftrightarrow$] $\\sat{A}{\\dot{P}(x)}{s(x|a)} \\Rightarrow \\sat{A}{\\forall x Px}{s(x|a)}$\n    \\item[$\\Leftrightarrow$] There is some $a$ s.t. if $a \\in \\dot{P}^{\\frakA}$, then for every $b \\in |\\frakA|$, $b\\in\\dot{P}^{\\frakA}$\n    \\item If there is some $a$ s.t. $a \\notin \\dot{P}^{\\frakA}$, then the consequence holds trivially\n    \\item If there is no $a$ s.t. $a \\notin \\dot{P}^{\\frakA}$, this means that for every $a \\in |\\frakA|$, $a\\in\\dot{P}^{\\frakA}$. This is exactly the consequence so we are done\n\\end{itemize}\n\n\\subsection{Satisfiability}\n\n\\begin{definition}[Satisfiability]\n    \\begin{itemize}\n        \\item The wff $\\varphi$ is \\textbf{satisfiable} if there is some structure $\\frakA$ and some assignment $s$ s.t. $\\sat{A}{\\varphi}{s}$.\n        \\item The set of wffs $\\Gamma$ is \\textbf{satisfiable} if there is some structure $\\frakA$ and some assignment $s$ s.t. $\\sat{A}{\\varphi}{s}$ for every $\\varphi$ in $\\Gamma$.\n    \\end{itemize}\n\\end{definition}\n\n\\begin{theorem}\n    $\\varphi$ is not satisfiable iff $\\neg\\varphi$ is valid\n\\end{theorem}\n\n\\section{Definability}\n\n\\begin{definition}[Relations Defined by WFFs]\n    Let $\\frakA$ be a structure, and $\\varphi$ be a wff, and $n$ be such that the variables occurring free in $\\varphi$ are included among $v_1,\\dots,v_n$\n\n    The n-ary relation \\textbf{defined by $\\varphi$ in $\\frakA$} is\n    \\[ \\{ (a_1,\\dots,a_n) | \\assignSat{A}{\\varphi}{a_1,\\dots,a_n}\\} \\]\n\\end{definition}\n\nLet $\\mathfrak{N} = (\\mathbb{N},\\le, +, 1)$, the 2-ary relation $\\{(a,b)|a < b\\}$ is defined by\n\\[ v_1 \\dot{+}\\dot{1}\\doteq v_2 \\]\n\nTo show this, we will show that $(a,b) \\in R \\iff \\assignSat{N}{\\varphi}{a,b}$.\n\nIf $(a,b) \\in R$, $\\assignSat{N}{\\varphi}{a,b} \\iff a+1 \\le b$\n\nConversely, if $\\assignSat{N}{\\varphi}{a,b}$, it's equivalent to $a+1 \\le b$, which mathematically implies that $a < b$\n\n\\begin{definition}[Definability]\n    The relation $R$ is \\textbf{definable in the structure $\\frakA$} if there is some wff $\\varphi$ that defines it in $\\frakA$.\n\\end{definition}\n\nWe show some examples for definability of functions. Let $\\mathfrak{N} = (\\mathbb{N}, <, +, x, 0, 1)$.\n\n\\begin{itemize}\n    \\item $v_1 \\dot{+} v_2 \\doteq v_3$ defines $\\{ (a,b,c) | a + b = c\\}$ which is the same as function $f$, where $f(a,b) = a + b$.\n\\end{itemize}\n\n\\subsection{Definable Relations}\n\n\\begin{definition}[Relations Defined by WFFs]\n    Let\n    \\begin{itemize}\n        \\item $\\frakA$ be a structure\n        \\item $\\varphi$ be a wff and $n$ be such that the variables occurring free in $\\varphi$ are included among $v_1,\\dots,v_n$\n    \\end{itemize}\n\n    The $n$-ary relation defined by $\\varphi$ in $\\frakA$ is\n    \\[ \\{ (a_1,\\dots,a_n) | \\assignSat{A}{\\varphi}{a_1,\\dots,a_n} \\} \\]\n\\end{definition}\n\nFor example,\n\n\\begin{itemize}\n    \\item Let $\\mathfrak{R} = (\\mathbb{R},<,+,\\times,0,1)$. The $1$-ary relation $\\{ a \\in \\mathbb{R} | 0 \\le a \\}$ is defined by\n    \\[ \\exists v_2, v_1 \\doteq v_1 \\times v_2 \\]\n    \\item Let $\\mathfrak{R} = (\\mathbb{R},<,+,\\times,0,1)$。 The $2$-ary relation $\\{ (a,b) | a < b \\}$ is defined by\n    \\[ \\exists v_3 (v_1\\dot{+}(\\dot{1}\\dot{+}v_3)\\doteq v_2) \\]\n\\end{itemize}\n\n\\begin{definition}[Definable Relations]\n    The relation $R$ is \\textbf{definable in structure} $\\frakA$ if there is some wff that defines it in $\\frakA$\n\n    Let $f$ be a n-ary function $f$ whose domain is a subset $|\\frakA| \\times \\dots \\times |\\frakA|$ and whose range is a subset of $|\\frakA|$, $f$ is definable in $\\frakA$ if the $(n+1)$-ary relation\n    \\[ \\{ (a_1,\\dots,a_n, b) | f(a_1,\\dots,a_n) = b \\} \\]\n    is definable in $\\frakA$.\n\\end{definition}\n\nConsider $\\mathfrak{N} = (\\mathbb{N},<,+,\\times,0,1)$.\n\\begin{itemize}\n    \\item $v_1 + v_2 = v_3$ defines $\\{ (a,b,c) | a + b = c \\}$, which is the same as function $f(a,b) = a + b$\n    \\item $v_1 + v_3 = v_2$ defines $\\{ (a,b,c) | a+c = b \\}$, which is the same as function $f(a,b)$\n    \\[ f(a,b) = \\begin{cases}\n        b - a &\\quad a \\le b\\\\\n        Undefined &\\quad o.w.\n    \\end{cases} \\]\n\\end{itemize}\n\n\\begin{lemma}\n    Given a structure $\\frakA$, the set of definable relations is \\emph{enumerable}\n\\end{lemma}\n\\begin{lemma}\n    Not every subset of $\\mathbb{N}$ is definable.\n\\end{lemma}\n\nThe proof of the two lemmas are similar. Note that the set of wffs is enumerable, and every wff may define only one relation. And the set of all subsets of $\\mathbb{N}$ is uncountable.\n\nWe now move from $\\mathbb{N}$ to $\\mathbb{R}$ and consider a more generall case. Consider whether the following subsets of $\\mathbb{R}$ are definable in $\\mathfrak{R} = (\\mathbb{R}, <)$\n\n\\begin{itemize}\n    \\item $\\emptyset$. Yes.\n    \\item $\\mathbb{N}$. Yes.\n    \\item Anything else?\n\\end{itemize}\n\n\\section{Homomorphisms}\n\n\\begin{definition}[Homomorphism]\n    Let $\\mathfrak{A}$ and $\\mathfrak{B}$ be structures for $\\mathbb{L}$. A \\textbf{homomorphism} from $\\frakA$ to $\\mathfrak{B}$ is a function $h:|\\frakA| \\mapsto |\\mathfrak{B}|$ s.t.\n    \\begin{itemize}\n        \\item For every n-ary predicate symbol $R$, other than $\\doteq$, and $a_1,\\dots,a_n \\in |\\frakA|$,\n        \\[ (a_1,\\dots,a_n) \\in R^{\\frakA} \\iff (h(a_1),\\dots,h(a_n))\\in R^{\\mathfrak{B}} \\]\n        \\item For every n-ary function symbol $f$, and $a_1,\\dots,a_n \\in |\\frakA|$,\n        \\[ h(f^\\frakA(a_1,\\dots,a_n)) = f^\\mathfrak{B}(h(a_1),\\dots,h(a_n)) \\]\n        \\item For every constant symbol $c$\n        \\[ h(c^\\frakA) = c^\\mathfrak{B} \\]\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[Onto of Homomorphism]\n    $h$ is a homomorphism of $\\frakA$ \\textbf{onto} $\\mathfrak{B}$ if $h$ is a homomorphism from $\\mathfrak{A}$ to $\\mathfrak{B}$ and $h$ maps $\\frakA$ onto $\\mathfrak{B}$.\n\\end{definition}\n\n\\begin{definition}[Isomorphism]\n    A homomorphism $h$ from $\\mathfrak{A}$ to $\\mathfrak{B}$ is an \\textbf{isomorphism} if $h$ is one-to-one\n\\end{definition}\n\n\\begin{definition}[Isomorphic]\n    The structures $\\frakA$ and $\\mathfrak{B}$ are \\textbf{isomorphic}, denoted by $\\frakA \\cong \\mathfrak{B}$ if there is some \\emph{isomorphism} of $\\frakA$ \\emph{onto} $\\mathfrak{B}$. (One-to-one correspondence)\n\\end{definition}\n\n\\begin{definition}[Automorphism]\n    An \\textbf{automorphism} of $\\frakA$ is an isomorphism of $\\frakA$ onto $\\frakA$\n\\end{definition}\n\n\\subsubsection{Examples of Homomorphism}\n\nFor example, let $\\frakA = (\\naturalSet, <^\\naturalSet, +^\\naturalSet)$, $\\mathfrak{B} = (\\mathbb{E}, <^\\mathbb{E}, +^\\mathbb{E})$, where $\\mathbb{E}$ is the set of even non-negative integers. Then we claim that $h(n)=2n$ is an isomorphism of $\\mathfrak{A}$ onto $\\mathfrak{B}$\n\nTo do this, we show that 1) $h$ is a homomorphism; 2) $h$ is one-to-one; 3) $h$ is onto\n\n\\begin{itemize}\n    \\item[$\\dot{<}$] $(a,b) \\in <^\\mathbb{N} \\iff (h(a), h(b)) = (2a,2b) \\in <^\\mathbb{E}$\n    \\item[$\\dot{+}$] $h(a +^\\mathbb{N} b) = (h(a) +^\\mathbb{E} h(b)) = (2a +^\\mathbb{E} 2b)$\n\\end{itemize}\n\nHowever, let $\\mathfrak{C} = (\\mathbb{O}, <^\\mathbb{O}, +^\\mathbb{O})$, where $\\mathbb{O}$ is the set of all odd non-negative integers, then there is no isomorphism of $\\frakA$ onto $\\mathfrak{C}$. Infact $\\mathfrak{C}$ is not even a valid strucutre because $+^\\mathbb{O}$ is not closed.\n\n\\subsubsection{Automorphism of $\\mathfrak{R}=(\\realSet, <)$}\n\nConsider which of the following $h$ are automorphisms of $\\mathfrak{R}$. Note that to show this, we need to show that 1) $h$ is a homomorphism; 2) $h$ is one-to-one; 3) $h$ is onto; and 4) $h$ maps $\\realSet$ to $\\realSet$.\n\n\\begin{itemize}\n    \\item The identity function. Obviously yes.\n    \\item $h(a) = a + 3$. Yes.\n    \\item $h(a) = a - 4$. Yes.\n    \\item $h(a) = 2a$. Yes.\n    \\item $h(a) = -a$. Yes.\n    \\item $h(a) = ka + l$. Yes if $k>0$.\n    \\item $h(a) = a^3$. Yes.\n    \\item $h(a) = a^2$. No.\n\\end{itemize}\n\n\\subsubsection{Automorphism of $\\mathfrak{N} = (\\naturalSet, <)$}\n\nObviously the identity function is an automorphism. We consider other cases.\n\nIf we map $0$ to any $n>0$, i.e. $h(0) = n > 0$. Since $h$ is onto, there exists some $m > 0$ s.t. $h(m) = 0$. And here comes a problem\n\\[ m > 0 \\iff h(m) = 0 > h(0) = n > 0 \\]\nTherefore $0$ can only be mapped to $0$, i.e. $h(0) = 0$\n\nSimilarly, $h(1)$ can only be mapped to $1$, and for each $n$, $h(n) = n$. Therefore the identity function $h(n) = n$ is the \\emph{only} automorphism of $\\naturalStruct$.\n\n\\subsection{Substructures}\n\nWe now consider a special kind of isomorphism\n\n\\begin{definition}[Substructures]\n    Let $\\frakA = (A,\\dots)$ and $\\frakB = (B,\\dots)$ be structures for $\\mathbb{L}$. $\\frakA$ is a \\textbf{substructure} of $\\frakB$, denoted by $\\frakA \\subseteq \\frakB$ if\n    \\begin{itemize}\n        \\item $A \\subseteq B$\n        \\item For every $k$-ary predicate symbol,\n        \\[ P^\\frakA = P^\\frakB \\cap A^k \\]\n        Note that this is to guarantee that $(a_1,\\dots,a_k)\\in P^\\frakB \\Longrightarrow (a_1,\\dots,a_k)\\in P^\\frakA$\n        \\item For every $k$-ary function $f$ and every $k$-tuple of $A$\n        \\[ f^\\frakA(a_1,\\dots,a_k) = f^\\frakB(a_1,\\dots,a_k) \\]\n        \\item For every constant $c$\n        \\[ c^\\frakA = c^\\frakB \\]\n    \\end{itemize}\n\\end{definition}\n\\begin{remark}\n    Substructures are defined under identity map $h(x)=x$. The identity map is an isomorphism of $\\frakA$ into $\\frakB$ iff\n    \\begin{enumerate}\n        \\item For each predicate $P$, $P^\\frakA$ is the restriction of $P^\\frakB$ to $A$\n        \\item For each function $f$, $f^\\frakA$ is the restriction of $f^\\frakB$ to $A$\n        \\item $c^\\frakA = c^\\frakB$.\n    \\end{enumerate}\n    If these conditions are met, then $\\frakA$ is called a \\textbf{substructure} of $\\frakB$.\n\\end{remark}\n\n\\subsection{Homomorphism Theorem}\n\n\\begin{lemma}\n    \\label{lem:HomomorphismLemma}\n    Let $\\frakA$ and $\\frakB$ be structures for the language $\\mathbb{L}$. Let $h$ be a homomorphism from $\\frakA$ to $\\frakB$, and $s:V\\to|\\frakA|$ be an assignment for $\\frakA$. Then for every term $t$ of $\\mathbb{L}$\n    \\[ h(\\bar{s}(t)) = \\overline{h\\circ s}(t) \\]\n\\end{lemma}\n\\begin{proof}\n    Prove by induction.\n    \\begin{itemize}\n        \\item[] \\textbf{Base Case.} If $t=c$, then\n        \\[ h(\\bar{s}(c)) = h(c^\\frakA) = c^\\frakB = \\overline{h\\circ s(c)} \\]\n        If $t=v$, then\n        \\[ h(\\bar{s}(x)) = h(s(x)) = h \\circ s(x) \\]\n        \\item[] \\textbf{Inductive Case.} If $t = ft_1,\\dots,t_n$,\n        \\[ h(\\bar{s}(t)) = h(f^\\frakA(\\bar{s}(t_1),\\dots,\\bar{s}(t_n))) = f^\\frakB(\\bar{s}(t_1),\\dots,\\bar{s}(t_n)) \\]\n        \\[ \\overline{h\\circ s} = f^\\frakB(\\overline{h\\circ s}(t_1),\\dots,\\overline{h\\circ s}(t_n)) \\]\n        From inductive hypothesis we know $\\overline{h\\circ s}(t_k) = h(\\bar{s}(t_k))$, and we are done.\n    \\end{itemize}\n\\end{proof}\n\n\\begin{theorem}[Homomorphism Theorem]\n    \\label{thm:HomomorphismTheorem}\n    Let $h$ be a homomorphism form $\\frakA$ to $\\frakB$ and $s$ be an assignment function for $\\frakA$. The statement\n    \\[ \\sat{A}{\\varphi}{s} \\iff \\sat{B}{\\varphi}{h \\circ s} \\]\n    \\begin{itemize}\n        \\item is true for every quantifier-free wff $\\varphi$ not containing $\\doteq$\n        \\item is true for every quantifier-free wff $\\varphi$ if $h$ is one-to-one\n        \\item is true for every wff $\\varphi$ wff $\\varphi$ not containing $\\doteq$ if $h$ is onto\n        \\item is true for every wff $\\varphi$ if $h$ is an isomorphism of $\\frakA$ onto $\\frakB$ ($\\frakA \\cong \\frakB$)\n    \\end{itemize}\n\\end{theorem}\n\\begin{proof}\n    Prove by induction on $\\varphi$.\n    \\begin{itemize}\n        \\item[] \\textbf{Base Case.} Let $\\varphi = Pt_1\\dots t_n$.\n         Since $h$ is a homomorphism, by definition we have\n         \\[ (\\bar{s}(t_1),\\dots,\\bar{s}(t_n))\\in P^\\frakA \\iff (h(\\bar{s}(t_1)),\\dots, h(\\bar{s}(t_n))) \\in P^\\frakB \\]\n         Further, by Lemma~\\ref{lem:HomomorphismLemma},\n         \\[ (\\overline{h\\circ s}(t_1),\\dots,\\overline{h\\circ s}(t_2)) = (h(\\bar{s}(t_1)),\\dots, h(\\bar{s}(t_n))) \\in P^\\frakB \\]\n         So we are done.\n         \\item[] \\textbf{Inductive Case.}\\begin{itemize}\n             \\item If $\\varphi = \\neg \\alpha$, by induction hypothesis\n             \\[ \\sat{A}{\\alpha}{s} \\iff \\sat{B}{\\alpha}{h \\circ s} \\]\n             We can negate both sides\n             \\[ \\unsat{A}{\\alpha}{s} \\iff \\unsat{B}{\\alpha}{h \\circ s} \\]\n             Therefore,\n             \\[ \\sat{A}{\\neg\\alpha}{s} \\iff \\sat{B}{\\neg\\alpha}{h\\circ s} \\]\n             \\item If $\\varphi = \\alpha \\to \\beta$.\n             \\[ \\sat{A}{\\alpha\\to\\beta}{s} \\iff \\sat{B}{\\alpha\\to\\beta}{h\\circ s} \\]\n             is equivalent to\n             \\[ \\text{If} \\sat{A}{\\alpha}{s} \\text{then} \\sat{A}{\\beta}{s} \\iff \\text{If} \\sat{B}{\\alpha}{h \\circ s} \\text{then} \\sat{B}{\\beta}{s} \\]\n             By induction hypothesis, we are done.\n         \\end{itemize}\n    \\end{itemize}\n    Until now we have proved (a). We now further consider $\\doteq$ and $\\forall$\n\n    We start from $\\doteq$, which is a base case,\n    If $\\varphi = t_1\\doteq t_2$\n        \\[ \\sat{A}{t_1\\doteq t_2}{s} \\iff \\sat{B}{t_1\\doteq t_2}{h\\circ s} \\]\n        \\[ \\bar{s}(t_1) = \\bar{s}(t_2) \\iff \\overline{h\\circ s}(t_1) = \\overline{h\\circ s}(t_2) \\iff h(\\bar{s}(t_1)) = h(\\bar{s}(t_2)) \\]\n        $\\Leftrightarrow$ always holds. However, $\\Leftarrow$ requires an additional condition that $h$ is one-to-one.\n\n    Finally, consider $\\varphi=\\forall x\\alpha$ in the inductive case.\n    \\[ \\sat{A}{\\forall x \\alpha}{s} \\iff \\sat{B}{\\forall x \\alpha}{h\\circ s} \\]\n    \\[ \\text{For any $a\\in|\\frakA|$,} \\sat{A}{\\alpha}{s(x|a)} \\iff \\text{For any $b\\in|\\frakB|$,}\\sat{B}{\\alpha}{(h\\circ s)(x|b)} \\]\n    Assume LHS, we prove RHS. Note that since $a$ and $b$ are arbitrary, we cannot relate them without additional conditions. Therefore to prove this we would require $h$ to be \\emph{onto}. Then there is some $a'\\in|\\frakA|$ s.t. $h(a')=b$.\n    \\[ \\sat{B}{\\alpha}{(h\\circ s)(x|h(a'))} \\iff \\sat{B}{\\alpha}{h\\circ(s(x|a'))} \\]\n    By LHS, we have $\\sat{A}{\\alpha}{s(x|a')}$, and by hypothesis, we have $\\sat{B}{\\alpha}{h\\circ (s(x|a'))}$, so we are done.\n\n    Assume RHS, we prove LHS. Let $b=h(a)$,\n    \\[ \\sat{B}{\\alpha}{(h\\circ s)(x|h(a))} \\iff \\sat{B}{\\alpha}{h\\circ(s(x|a))} \\]\n    By hypothesis, we have $\\sat{A}{\\alpha}{s(x|a)}$. Done.\n\\end{proof}\n\n\\begin{corollary}\n    \\label{cor:HomomorphismToElementaryEquiv}\n    If $\\frakA \\cong \\frakB$, then $\\frakA \\equiv \\frakB$. Recall that $\\equiv$ means Elementary Equivalence (Def~\\ref{def:ElementaryEquivalence}).\n\\end{corollary}\n\nCorollary~\\ref{cor:HomomorphismToElementaryEquiv} follows immediately from Homomorphism Theorem~\\ref{thm:HomomorphismTheorem} because sentences do not care about assignments.\n\nBut the converse is not true. Take $\\mathfrak{R} = (\\realSet, <)$ and $\\mathfrak{Q}=(\\mathbb{Q}, <)$ as a counter example. We have claimed that they are elementary equivalent (though the proof is beyond the scope).\n\n\\begin{corollary}[Automorphism Theorem]\n    \\label{cor:AutomorphismTheorem}\n    Let $h$ be an automorphism of $\\frakA$. Let $R$ be an n-ary relation on $|\\frakA|$ that is definable in $\\frakA$. For every n-tuple $(a_1,\\dots,a_n)$ of elements of $\\frakA$,\n    \\[ (a_1,\\dots,a_n) \\in R \\iff (h(a_1),\\dots,h(a_n)) \\in R \\]\n\\end{corollary}\n\\begin{proof}\n    Since $R$ is definable in $\\frakA$,\n    \\begin{itemize}\n        \\item[] $(a_1,\\dots,a_n) \\in R$\n        \\item[$\\iff$] $\\assignSat{A}{\\varphi}{a_1,\\dots,a_n}$ \n        \\item[$\\iff$] $\\assignSat{A}{\\varphi}{h(a_1),\\dots,h(a_n)}$ \n        \\item[$\\iff$] $(h(a_1),\\dots,h(a_n))\\in R$ \n    \\end{itemize}\n\\end{proof}\n\nCorollary~\\ref{cor:AutomorphismTheorem} is often used for proving some relations are \\emph{not definable}. For example, consider $\\mathfrak{R} = (\\realSet, <)$, its subset $\\mathbb{N}$ is not definable in $\\realStruct$.\n\nAssume $\\naturalSet$ is definable in $\\realStruct$. Let $h(a)=a^3$. Obviously $h$ is an automorphism of $\\realStruct$.\n\n\\begin{itemize}\n    \\item[] $a \\in \\mathbb{N}$\n    \\item[$\\iff$] $\\assignSat{R}{\\varphi}{a}$\n    \\item[$\\iff$] $\\assignSat{R}{\\varphi}{h(a)}$\n    \\item[$\\iff$] $h(a)\\in\\naturalSet$\n    \\item[$\\iff$] $a^3 \\in \\naturalSet$.  \n\\end{itemize}\n\nThis leads to a contradiction. If $a^3 = 2$, then no $a \\in \\naturalSet$.\n", "meta": {"hexsha": "746c4e36889a99ff4ead85fdaccf870097dc97fe", "size": 39079, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Logic/FirstOrderLogic.tex", "max_stars_repo_name": "YBRua/CourseNotes", "max_stars_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-20T10:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T08:15:15.000Z", "max_issues_repo_path": "Mathematical Logic/FirstOrderLogic.tex", "max_issues_repo_name": "YBRua/CourseNotes", "max_issues_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mathematical Logic/FirstOrderLogic.tex", "max_forks_repo_name": "YBRua/CourseNotes", "max_forks_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T11:31:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T11:31:00.000Z", "avg_line_length": 48.4250309789, "max_line_length": 319, "alphanum_fraction": 0.6422119297, "num_tokens": 13763, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.7450158268310552}}
{"text": "%!TEX root = RBM.tex\n\n\\subsubsection{Annealed Importance Sampling\\protect\\footnote{Available at \\protect\\url{https://github.com/lzhbrian/MCMC/blob/ master/src/partition/AIS.m} in Matlab}}\n\n\\para{Algorithm} \nAnnealed Importance Sampling(AIS)\\cite{neal2001annealed,salakhutdinov2009learning} is probably one of the most preferable estimating methods avaible.\n\nPrevious work \\cite{mackay2003information} have shown that if $P_{A}$ and $P_{B}$ in the SIS method is not close enough, the estimator would be very poor.\n\nBased on SIS, the main idea of this algorithm is to gradually alter the value from an known $Z_{A}$ to our required $Z_{B}$ (or $Z_{K}$), by the following identity:\n\\begin{equation}\n\\frac{Z_{K}}{Z_{0}} = \\frac{Z_{1}}{Z_{0}} \\frac{Z_{2}}{Z_{1}} ... \\frac{Z_{K}}{Z_{K-1}}\n\\end{equation}\nwhere \n\\begin{equation}\n\\frac{Z_{K}}{Z_{k+1}} = \\frac{1}{M} \\sum_{i=1}^{M} \\frac{P_{k+1}^{*}(\\mathbf x^{(i)})}{P_{k}^{*}(\\mathbf x^{(i)})}\n~~where~ x^{(i)} \\sim P_{k}\n\\end{equation}\nin which we can get $x_{k+1}$ from:\n\\begin{equation}\n\\begin{aligned}\np(h^{A}_{j}=1|\\mathbf v) &= sigmoid\\Bigg( (1-\\beta_{k})\\Bigg(\\sum_{i}W^{A}_{ij}v_{i}+a^{A}_{j}\\Bigg) \\Bigg) \\\\\np(h^{B}_{j}=1|\\mathbf v) &= sigmoid\\Bigg( \\beta_{k}\\Bigg(\\sum_{i}W^{B}_{ij}v_{i}+a^{B}_{j}\\Bigg) \\Bigg) \\\\ \np(v'_{i}=1|\\mathbf h) &= sigmoid\\Bigg( (1-\\beta_{k})\\Bigg(\\sum_{j}W^{A}_{ij}h_{i}^{A}+b^{A}_{i}\\Bigg) \\\\\n& + \\beta_{k}\\Bigg(\\sum_{j}W^{B}_{ij}h_{j}^{B}+b^{B}_{i}\\Bigg) \\Bigg) \n\\end{aligned}\n\\end{equation}\nthis procedure is shown in Figure~\\ref{fig:xkxk1}.\n\n\\begin{figure}[tb]\n% \\vspace{-0.5in}\n  \t\\centering\n  \t\\includegraphics[width=0.4\\textwidth]{figure/xkxk1.png}\n% \\vspace{-0.2in}\n\t\\caption{The transition process from $x_{k}$ to $x_{k+1}$ which leaves $P_{k}(\\mathbf v)$ invariant.}\n\t\\label{fig:xkxk1}\n\\end{figure}\n\nNote that model A indicates an initial model which we can easily compute all its configurations. Commonly, we choose an RBM model with $\\theta = \\{0,0,0\\}$\n\n$\\mathbf \\beta$ in the above equations is defined by users as a set of inverse temperatures $\\{0= \\beta_{1} < \\beta_{2} < ... < \\beta_{K} =1\\}$, which can define a sequence of\n\\begin{equation}\nP_{k}(\\mathbf x) \\propto P_{A}^{*}(\\mathbf x)^{1-\\beta_{k}} P_{B}^{*}(\\mathbf x)^{\\beta_{k}}\n\\end{equation}\nwhere \n\\begin{equation}\nP^{*}_{k}(\\mathbf v)=\\sum_{h^{A}h^{B}}e^{(1-\\beta_{k})E(\\mathbf v, \\mathbf h^{A};\\theta_{A})+\\beta_{k}E(\\mathbf v,\\mathbf h^{B};\\theta_{B})}\n\\end{equation}\n\n\n\\para{Initialize $Z_{A}$ with dataset}\nIn \\cite{salakhutdinov2009learning}, Ruslan also notice a method to make $Z_{A}$ near $Z_{B}$. As the length \\& time limit, we will not specify the process here.\n\nOriginally, we initialize model A with a configuration of $\\theta=\\{0,0,0\\}$. This method can use the training data to initialize the visible bias $\\mathbf b$ to a desired value s.t. we can get a better outcome of the estimation.\n\nIn our real practice, we find that this method take less than 0.005 second to initialize $\\mathbf b$ even for a very big model (i.e.784 visible and 500 hidden units), but have strongly improved the result as we will mention in the next subsection.\n\n\n\t\\begin{algorithm}\n        \\caption{Annealed Importance Sampling}\n        \\begin{algorithmic}\n        \t\\Require Required $\\beta_{k}$ s.t. $0 = \\beta_{0} < \\beta_{1} < ... < \\beta_{K} = 1$\n        \t\\State Initialize $b_{A}$ by dataset\n        \t\\State Sample $\\mathbf x_{1}$ from $P_{A} = P_{0}$\n            \\For{$k = 1 \\to K-1$}\n                \\State Sample $\\mathbf x_{k+1}$ given $\\mathbf x_{k}$ using $T_{k}(\\mathbf x_{k+1} \\longleftarrow \\mathbf x_{k+1})$\n\t\t\t\\EndFor\n\t\t\t\\State Set $\\omega_{AIS} = \\prod_{k=1}^{K}P^{*}_{k}(\\mathbf x_{k})/P^{*}_{k-1}(\\mathbf x_{k})$\n        \\end{algorithmic}\n    \\end{algorithm}\n", "meta": {"hexsha": "a95dbd6edfa7697bcfbaf25d750a343d9676507d", "size": 3728, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/AIS.tex", "max_stars_repo_name": "lzhbrian/MCMC", "max_stars_repo_head_hexsha": "0dd3aadd1ed2833aff76bd7af4b014282739984b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-09-10T04:42:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-21T16:07:29.000Z", "max_issues_repo_path": "tex/AIS.tex", "max_issues_repo_name": "lzhbrian/MCMC", "max_issues_repo_head_hexsha": "0dd3aadd1ed2833aff76bd7af4b014282739984b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/AIS.tex", "max_forks_repo_name": "lzhbrian/MCMC", "max_forks_repo_head_hexsha": "0dd3aadd1ed2833aff76bd7af4b014282739984b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-03-03T17:34:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-24T10:54:53.000Z", "avg_line_length": 52.5070422535, "max_line_length": 247, "alphanum_fraction": 0.6555793991, "num_tokens": 1373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.744969758527996}}
{"text": "\\subsection{Transport equation}\nThe advection-diffusion-reaction equation is the same in form for any tracer. \nSELFE uses it to track salt, temperature and sediment concentration and water quality constituents. \nThe equation for a generic tracer $T$ is:\n\\beqa\n  \\frac{\\pd T}{\\pd t}+\\nabla \\cdot (\\bs{u}T)\n\t&=& \\frac{\\pd }{\\pd x} (\\kappa_h \\frac{\\pd T}{\\pd x}) + \\frac{\\pd }{\\pd y} (\\kappa_h \\frac{\\pd T}{\\pd y})\n\t+\\frac{\\pd }{\\pd z} (\\kappa \\frac{\\pd T}{\\pd z}) +\\hat{Q},\\label{tr1}\\\\\n\\eeqa\nwith vertical boundary conditions at the bed and free surface:\n\\beqa\n  \\kappa \\frac{\\pd T}{\\pd z} &=& \\hat{T}, \\mbox{ at } z=\\eta, \\label{tr2} \\\\\n  \\kappa \\frac{\\pd T}{\\pd z} &=& \\hat{T_b}, \\mbox{ at } z=-h, \\label{tr3}\n\\eeqa\nand concentration (Dirichlet, essential) boundary conditions at inflows and ocean boundaries.\nwhere \n\\begin{align*}\n&T(x,y,z,t)  &\\text{concentration of the tracer} &\\\\\n&\\bs{u}(x,y,z,t)  &\\text{3D velocity (m/s)}  &\\\\\n&\\kappa_{h} &\\text{horizontal diffusivity} (m^2s^{-1}) &\\\\\n&\\kappa   &\\text{vertical diffusivity}(m^2s^{-1}) &\\\\\n&\\hat{Q}  & \\text{mass source}  &\\\\\n\\end{align*}\n\nand the 3D velocity $\\bs{u}$ must be provided in a mass-conserving (divergence free) form:\n\\beq\n  \\nabla \\cdot (\\bs{u})=0 \\label{tr5}\n\\eeq\n\nHorizontal mixing of constituent concentration was ignored throughout our project, \nwhich is equivalent to $\\kappa_h=0$. When shear in the main flow field is adequately\nresolved, scaling arguments usually indicate that horizontal eddy diffusivity is very small\ncompared to the other terms and we assume that enough is introduced by the unavoidable horizontal\nnumerical diffusion introduced in solving the equations.\n\n\n\n", "meta": {"hexsha": "b8be3aeaf026beaf2a93edee612597decc97377f", "size": 1657, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/form_transport.tex", "max_stars_repo_name": "water-e/BayDeltaSCHISM", "max_stars_repo_head_hexsha": "b532b51ef58a6ef3dbb4e74f82008a46db0f7686", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-15T20:59:16.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-15T20:59:16.000Z", "max_issues_repo_path": "documents/form_transport.tex", "max_issues_repo_name": "water-e/BayDeltaSCHISM", "max_issues_repo_head_hexsha": "b532b51ef58a6ef3dbb4e74f82008a46db0f7686", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2018-06-05T16:01:48.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-20T18:52:48.000Z", "max_forks_repo_path": "documents/form_transport.tex", "max_forks_repo_name": "water-e/BayDeltaSCHISM", "max_forks_repo_head_hexsha": "b532b51ef58a6ef3dbb4e74f82008a46db0f7686", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-06-04T16:45:56.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-29T23:01:47.000Z", "avg_line_length": 43.6052631579, "max_line_length": 106, "alphanum_fraction": 0.6916113458, "num_tokens": 545, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362849986365571, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.744962743132796}}
{"text": "\\Lecture{Jayalal Sharma}{Sept 19, 2020}{05}{Multichoosing}{Narasimha Sai Vempati}{$\\alpha$}{JS}\n\n\\section{Introduction}\nConsider the definition of \\emph{set}. We know that it's a well defined collection of \\emph{distinct} objects. From a collection of $n$ distinct symbols, the number of ways to form a \\emph{set} of length $k$ is given by $\\binom{n}{k}$. Now let's consider the definition of \\emph{multi-set}. It's similar to that of a \\emph{set}, except that it allows repetition of objects. Now it's natural ask the following question: From a collection of $n$ distinct symbols, what is the number of ways to form a \\emph{multi-set} of length $k$. Multichoosing exactly answers this questions. In this lecture, we explore multichoosing in detail. We discuss several equivalent bijections to this problem and come-up with an algebraic expression for \\mulnom{n}{k} (spelled out as $n$ \\emph{multi-choose} $k$).\n\n\\section{Equivalent bijections} \\label{sec:equi-bij}\n\\subsection{Non-negative solutions}\\label{non-neq-sol-prob}\nFormally, \\mulnom{n}{k} is the number of ways of choosing $k$ objects from a set of $n$ objects where the order is not important but repetitions are allowed. For all $i=1,2,\\cdots,n$, if we denote by $x_i$ the number of copies of $i^{th}$ object we choose, then we have the equation \\begin{equation}\\label{eqn1}\n    x_1+x_2+\\cdots+x_n=k\n\\end{equation} where each $x_i \\geq 0$. Therefore, number of \\emph{non-negative} integral solutions to this equation gives us the required number of ways of choosing $k$ objects from $n$ objects with given conditions. Let's look at an equivalent problem and establish a bijection between these two.\n\n\\subsection{Voting problem}\\label{voting-prob} If $n$ candidates are contesting in an election and there are $k$ voters, how many ways can votes of those $k$ voters be distributed among $n$ candidates? \n\nIf we denote by $x_i$, the number of votes received by $i^{th}$ candidate and there are $k$ voters, we have $x_1+x_2+\\cdots+x_n=k$ and thus, the number of ways of dividing votes among candidates is the number of non-negative solutions to the equation \\ref{eqn1}. Formally, we can define a bijection $f$ from set of solutions to the equation \\ref{eqn1} to set of ways of dividing the votes among $n$ candidates. \n\\begin{description}\n\\item\\underline{Definition:}  $f$ takes the tuple $\\vecx=(x_1,x_2,\\cdots,x_n)$ and assign $x_i$ number of votes to $i^{th}$ candidate where $i=1,2,\\cdots,n$.\n\\item\\underline{Well defined:} $f$ is well defined because for every valid tuple $\\vecx=(x_1,x_2,\\cdots,x_n)$, we have $x_1+\\cdots+x_n=k$ and thus summing over votes received by $i^{th}$ where $i=1,2,\\cdots,n$ will be $k$ votes in total. \n%there is a unique way of dividing the votes among candidates. In other words, for any two distinct way of dividing $k$ votes among $n$ candidates, there must exists an $i$ such that number of votes received $i^{th}$ candidate is different and thus $x_{1_i} \\neq x_{2_i}$. Therefore $\\vecx_1\\neq\\vecx_2$. \n\\item\\underline{Injective:} $f$ is an injection because for every valid way of dividing the votes among candidates, there's a unique solution tuple in which $x_i = $ number of votes received by $i^{th}$ candidate. In other words, for any two $\\vecx_1\\neq\\vecx_2$, there exists an $i\\in[n]$ such that $x_{1_i}\\neq x_{2_i}$ and $i^{th}$ candidate gets different votes. Thus $f(\\vecx_1)\\neq f(\\vecx_2)$.\n\\item\\underline{Surjective:} $f$ is surjective because for every way of dividing $k$ votes among $n$ candidates, there is a pre-image $\\vecx=(x_1,\\cdots,x_n)$ which is a valid solution to the equation \\ref{eqn1} (as there are a total of $k$ voters, sum of number of votes received by each voter must sum up to $k$). \n\\end{description}\nThus $f$ is a bijection from the set of non-negative solutions to $x_1+\\cdots+x_n=k$ to the set of ways of dividing $k$ votes among $n$ candidates.\n\\subsection{Non-decreasing subsequences}\\label{non-dec-subseq-prob} Number of non-decreasing sequences of integers between $1$ and $n$ of length $k$. A non-decreasing sequence is of the form $\\{a_1,a_2,\\cdots,a_k\\}$ where $1\\leq a_1\\leq a_2\\cdots\\leq a_k\\leq n$. Lets define a bijection $f$ from set of non-negative integral solutions to Eqn. \\ref{eqn1} to set of non-decreasing sequences between $1$ and $n$ of length $k$. \n\\begin{description}\n\\item\\underline{Definition:} $f$ takes $\\vecx=(x_1,\\cdots,x_n)$ as input and writes the number $i$ $x_i$ times for all $i=1,2,\\cdots,n$ to obtain a sequence of length $k$.\n\\item\\underline{Well defined:} As $f$ constructs the sequence in increasing order from $1$ to $n$ by writing $i$ $x_i$ times, the resulting sequence will be non-decreasing. Therefore, $f$ is well defined.\n\\item\\underline{Injective:} For every $\\vecx_1\\neq\\vecx_2$, there exists an $i$ such that $x_{1_i} \\neq x_{2_i}$ and thus in the resulting sequences, number $i$ is written different number of times. Therefore, $f$ is injective.\n\\item\\underline{Surjective:} Every non-decreasing sequence of integers between $1$ and $n$ of length $k$ has a pre-image $\\vecx=(x_1,\\cdots,x_n)$  which is a valid solution to equation \\ref{eqn1} (where $x_i$ is the number of times the number $i$ is present in the sequence and as length of sequence is $k$, all $x_i$'s where $i=1,2,\\cdots,n$ sum up to $k$).\n\\end{description}\nThus $f$ is a bijection.\n\\subsection{Stars and bars problem}\\label{star-bar-prob} There are $k$ stars placed horizontally. Find the number of ways to place $n-1$ bars in between those $k$ stars. Lets define a bijection $f$ from set of non-negative integral solutions to Eqn. \\ref{eqn1} to set of ways of placing $n-1$ bars among $k$ stars.\n\\begin{description}\n\\item\\underline{Definition:} $f$ takes $\\vecx=(x_1,\\cdots,x_n)$ as input and place $x_i$ number of stars between $(i-1)^{th}$ bar and $i^{th}$ bar. We leave it as an exercise to prove that $f$ is well-defined, injective and surjective.\n\\end{description}\n\\jsay{Prove that $f$ is a bijection}\n\n\\section{Algebraic expression}\\label{alg-expr}\nSo far in Sec. \\ref{sec:equi-bij}, we have established bijections between \\emph{non-negatives integral} solutions of Eq. \\ref{eqn1} and various other problems and argued that number of ways of solving any particular problem is equal to the number of non-negative integral solutions to Eq. \\ref{eqn1}. In this section, we are interested in coming up with a concrete expression for \\mulnom{n}{k} by solving it's equivalent bijection.\n\n\\paragraph{Method 1} Let's solve the \\emph{stars and bars} problem defined in Sec. \\ref{star-bar-prob}. Let's use the fact that any placement of $n-1$ bars among $k$ stars can be equivalently thought of as a string of length $n+k-1$ over the alphabet $\\{\\star,|\\}$ with $k$ $\\star$'s. Therefore, \\begin{align*}\n    \\textrm{number of ways of placing } n-1 \\textrm{ bars among } k \\textrm{ stars } &= \\textrm{number of such strings}\\\\\n    &= \\binom{n+k-1}{k}\n\\end{align*}\n\n\\paragraph{Method 2} Let's solve the \\emph{Non-decreasing subsequences} problem defined in Sec. \\ref{non-neq-sol-prob}. Let's establish a bijection $f$ from set $\\beta$ of non-decreasing subsequences of integers between $1$ and $n$ of length $k$ to a set $\\Gamma$ of strictly increasing subsequences of integers between $1$ and $n+k-1$ of length $k$. A strictly increasing subsequence is of the form $1\\leq b_1<b_2<\\cdots<b_k\\leq n+k-1$\n\\begin{description}\n\\item{\\underline{Definition:}} $f$ takes as input a non-decreasing subsequence $(a_1,a_2,\\cdots,a_k)$ between $1$ and $n$ and for all $i=1,2,\\cdots,k$ set $b_i = a_i+i-1$ and output the sequence $(b_1,b_2,\\cdots,b_k)$\n\\item{\\underline{Well defined:}} For any $(a_1,a_2,\\cdots,a_k)\\in\\beta$, we have for all $i=1,2,\\cdots,k-1$, \\begin{align*}\n    a_i &\\leq a_{i+1}\\\\\n    a_i+i &\\leq a_{i+1}+i\\\\\n    a_i+i-1 &< a_{i+1}+i\\\\\n    b_i &< b_{i+1}\n\\end{align*}  Therefore, the subsequence $(b_1,\\cdots,b_k)$ is strictly increasing subsequence and thus $f$ is well defined.\n\\item{\\underline{Injective:}} For every non-decreasing subsequence $(a_1,\\cdots,a_k)$, there's a unique strictly increasing subsequence $(b_1,\\cdots,b_k)$ where for all $i=1,\\cdots,k$, $b_i = a_i+i-1$. Therefore $f$ is injective.\n\\item{\\underline{Surjective:}} For every strictly increasing subsequence $(b_1,\\cdots,b_k)$, there's a pre-image $(a_1,\\cdots,a_k)$ which is non-decreasing where for all $i=1,\\cdots,k$, $a_i=b_i-i+1$\n\\end{description}\n\n\nTherefore, $f$ is a bijection. The number of ways of choosing a strictly increasing subsequence $(b_1,\\cdots,b_k)$ between integers $1$ and $n+k-1$ is just choosing $k$ integers from first $n+k-1$ integers and arrange them in one way(increasing order). Therefore number of ways = $\\binom{n+k-1}{k}$. As $f$ is a bijection, therefore, the number of non-decreasing subsequences between $1$ and $n$ of length $k$ are $\\binom{n+k-1}{k}$\n\n\\paragraph{Method 3} Let's solve the \\emph{Voting} problem defined in Sec. \\ref{voting-prob}. Let's ask a slightly modified question. \n\\begin{description}\n\\item \\underline{Question:} How many ways to distribute $m$ votes among $n$ candidates such that each candidate gets at least one vote.\n\\item \\underline{Answer 1:} As every candidate gets at least one vote, let's first distribute one vote each to each of the $n$ candidate and the distribute the remaining $m-n$ votes among $n$ candidates. By the bijection defined in Sec. \\ref{voting-prob}, the number of ways of distributing $m-n$ votes among $n$ candidates is \\mulnom{n}{m-n}  \n\\item \\underline{Answer 2:} Let's interpret votes as $\\star$ s. Then the question essentially reduces to placing $n-1$ bars (since there are $n$ candidates, we divide by placing $n-1$ bars) among $m$ stars (since there are $m$ voters). $i^{th}$ candidate gets votes equal to number of stars between $(i-1)^{th}~|$ and $i^{th}~|$. However, there are two additional constraints \\begin{enumerate}\n    \\item\\label{cond1} A bar cannot be placed in the beginning or in the end (if not then either the first candidate or the last candidate gets $0$ votes)\n    \\item\\label{cond2} We cannot place two $|$ s between same two $\\star$ s (if we place $(i-1)^{th}~|$ and $i^{th}~|$ between same two $\\star$ s, the $i^{th}$ candidate gets $0$ votes)\n\\end{enumerate}\nHence, we have to choose $n-1$ gaps among the $m-1$ gaps (because we have $m+1$ gaps and by cond. \\ref{cond1} we remove two) to place $n-1~|$ s without repetitions (because repeating violates cond. \\ref{cond2}). Therefore, there are $\\binom{m-1}{n-1}$ ways of doing it. Thus \\mulnom{n}{m-n}=$\\binom{m-1}{n-1}$ and by substituting $m=n+k$, we have $$\\textrm{\\mulnom{n}{k}}=\\binom{n+k-1}{n-1}=\\binom{n+k-1}{k}$$\n\\end{description}\n\\section{Identities}\nIn this section, we discuss some identities on \\mulnom{n}{k} and argue their proofs using the idea of either double counting or bijections.\n\\paragraph{Identity 1} $$\\textrm{\\mulnom{n}{k}}=\\textrm{\\mulnom{k+1}{n-1}}$$\n\\begin{proof}\nLet's use the bijection method to prove this. Formally, lets define sets $S_1$ and $S_2$ and count their cardinalities independently and then establish a bijection from $S_1$ to $S_2$ proving that $|S_1|=|S_2|$.\n\\begin{description}\n\\item \\underline{$S_1$:} Configuration of $k~\\star$ s and $n-1~|$ s as described in Sec. \\ref{star-bar-prob}. By the bijection defined in it, $|S_1|=$ \\mulnom{n}{k}\n\\item \\underline{$S_2$:} Configuration of $n-1~\\star$ s and $k~|$ s as described in Sec. \\ref{star-bar-prob}. Again, by the bijection defined in it, $|S_2|=$\\mulnom{k+1}{n-1}\n\\item \\underline{Bijection:} Let's define a bijection $f$ from $S_1$ to $S_2$. $f$ takes a configuration from $S_1$ as input and interpret $\\star$ s as $|$ s and $|$ s as $\\star$ s. Therefore it ends up with a configuration with $n-1~\\star$ s and $k~|$ s which is a configuration is $S_2$. It's easy to observe that $f$ is a bijection.\n\\end{description}\nAs $f$ is a bijection from $S_1$ to $S_2$, we have $|S_1|=|S_2|$. This completes the proof \n\\end{proof}\n\n\\paragraph{Identity 2}\n$$k~\\textrm{\\mulnom{n}{k}}=n~\\textrm{\\mulnom{n+1}{k-1}}$$\n\\begin{proof}\nLet's use the method of double counting to prove this.\n\\begin{description}\n\\item \\underline{Question:} In how many ways can we construct a non-decreasing sequence $1\\leq a_1\\leq a_2\\cdots\\leq a_k\\leq n$ and mark one element?\n\\item \\underline{Asnwer 1:} By the bijection established in Sec. \\ref{non-dec-subseq-prob} we have \\mulnom{n}{k} number of non-decreasing subsequences and for every such subsequence, we can mark any one of the $k$ elements choose. Thus the answer is $k$ \\mulnom{n}{k} \n\\item \\underline{Answer 2:} Firstly, determine the value in $[n]$ which is to be marked. Let $r$ be this value. Now, consider a non-decreasing subsequence between $1$ and $n+1$ with $k-1$ elements. Using $r$ and the non-decreasing sequence chosen, we construct a unique non-decreasing sequence between $1$ and $n$ of length $k$ with $r$ as marked in the following way:\n\nLet $(b_1,b_2,\\cdots,b_{k-1})$ with $1\\leq b_1\\leq b_2\\leq\\cdots\\leq b_{k-1}\\leq n+1$ be the chosen sequence, \n\\begin{itemize}\n    \\item Insert marked-$r$ in the right most position so that the resulting sequence is still sorted.\n    \\item As long as there's an $n+1$ in the sequence, remove it and add it as $r$ to the right of marked-$r$ in the sequence\n\\end{itemize}\nTherefore, number of required sequences \n\\begin{align*}\n    &= \\textrm{ number of ways to choose }r \\times \\substack{\\textrm{ number of non-decreasing sequences of length }\\\\ k-1 \\textrm{ between } 1 \\textrm{ and } n+1}\\\\\n    &= n\\times \\textrm{\\mulnom{n+1}{k-1}}\n\\end{align*}\n\\end{description}\nThis completes the proof\n\\end{proof}\n\n\\begin{ex}\n    \\item Prove the following by combinatorial arguments $$\\textrm{\\mulnom{n}{k}}=\\sum\\limits_{m=1}^{n}\\textrm{\\mulnom{m}{k-1}}$$ \\emph{Hint: Look for bijection to number of non-decreasing subsequences}\n    \\item Prove the following by combinatorial arguments $$\\sum\\limits_{k=0}^{m}\\textrm{\\mulnom{n}{k}}=\\textrm{\\mulnom{n+1}{m}}$$ \\emph{Hint: Look for bijection to Voting problem}\n    \\item Prove the following by combinatorial arguments $$\\textrm{\\mulnom{n}{k}}=\\sum\\limits_{m=0}^{n}\\binom{n}{m}\\textrm{\\mulnom{m}{k-m}}$$\n\\end{ex}\n\n", "meta": {"hexsha": "4df04c86aafda95cc8e6c21bb33c058d43a4c434", "size": 14128, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture05.tex", "max_stars_repo_name": "narasimhasai07/theory-toolkit", "max_stars_repo_head_hexsha": "fde5621c515c2e05e3d91e8b021b745ea6ea2075", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lecture05.tex", "max_issues_repo_name": "narasimhasai07/theory-toolkit", "max_issues_repo_head_hexsha": "fde5621c515c2e05e3d91e8b021b745ea6ea2075", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture05.tex", "max_forks_repo_name": "narasimhasai07/theory-toolkit", "max_forks_repo_head_hexsha": "fde5621c515c2e05e3d91e8b021b745ea6ea2075", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 125.0265486726, "max_line_length": 791, "alphanum_fraction": 0.722819932, "num_tokens": 4466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744717487329, "lm_q2_score": 0.9111797069968975, "lm_q1q2_score": 0.7449572676161537}}
{"text": "\\section{Logistic Regression}\n\n\\textbf{For the linear classification model, we assumed the class-conditional distributions to be Gaussian}\n\\begin{itemize}\n\\item We assumed $x| (t=1) \\sim \\mathcal{N}(\\mu_+, \\Sigma_+)$ and $x| (t=-1) \\sim \\mathcal{N}(\\mu_-, \\Sigma_-)$, and two class-probabilities $P(t=1)$ and $P(t=-1)$.\n\\item  This is called an \\emph{generative model}, as we have written down a full joint model over the data. \n\\item  We saw that violations of the model assumption can lead to `bad' decision boundaries.\n\\end{itemize}\n\n\\begin{figure}\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture7/Figure44a.pdf}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture7/Figure44b.pdf}\n\t\\end{subfigure}\t\n\t\\caption{Figures taken from Bishop PRML}\n\\end{figure}\n\n\n\\textbf{For regression, we assumed Gaussian outputs, but did not need assumptions about the distribution of inputs.}\n\\begin{itemize}\n\\item For linear regression, we conditioned on $x$, and assumed a Gaussian distribution over $t$: $t|x \\sim \\mathcal{N}(y(x), \\gamma^2)$\n\\item  We maximized the conditional log-likelihood $L(\\omega)=\\sum_n \\log p(t_n|x_n, \\omega)$, i.e we assumed that the $x$ were given.\n\\item  Therefore, this approach to linear regression works for \\emph{any} distribution over $x$.\n\\item $x$ is typically high-dimensional, so it is difficult to make appropriate distributional assumptions for it. \n\\end{itemize}\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=.4\\textwidth]{./lecture7/Figure128.pdf}\n\t\\caption{Figure taken from Bishop PRML}\n\\end{figure}\n\n\n\\textbf{We can define a discriminative model for classification by modelling the conditional class probabilities.}\n\\begin{itemize}\n\\item From the homework-exercise, we know that $P(t=1 | z(x))=\\sigma(z(x))$ where $\\sigma(z)=1/(1+\\exp(-z))$ and $z(x)=\n\\omega^\\top x+\\omega_o$.\n\\item Notation is simpler if we use $0$ and $1$ as class labels, so we define $s_n=1$ as the label for the positive class, and $s_n=0$ als label for the negative class.\n\\item In other words, $s |x \\sim \\mbox{Bernoulli}(\\sigma(z(x))$.\n\\item Also, we set $y_n=\\sigma(z(x))$.\n\\item  The parameters of $z(x)=\\omega^\\top x+ \\omega_o$ can be learned by maximizing the conditional log-likelihood $L(\\omega)=\\sum_n \\log p(t_n|x_n, \\omega)$ [on board]\n\\item  This is an \\emph{discriminative} approach to classification, as we only model the labels, and not the inputs.\n\\item \n Decision rule and function shape of $p(t|x)$ will be the same for the generative (`Linear Discriminant Analysis') and the discriminative model, but the parameters were obtained differently.\n\\end{itemize}\n\n\\begin{bbbox}{Log-likelihood for logistic regression}\n\tPlease note that we drop $\\omega_0$ for simplicity, or similarly $\\omega_0 = 0$.\n\t\\begin{flalign*}\n\t\t& z(x) = \\omega^{\\top}x & \\\\\n\t\t& P\\left(\\lbrace t_n \\rbrace, \\lbrace x_n \\rbrace, \\omega \\right) = \\prod_{n=1}^N P(t_n|x_n,\\omega) & \\\\\n\t\t& \\qquad {} = \\prod_{n=1}^N \\left\\{\n\t\t\t\t\\begin{aligned}\n\t\t         \t& \\sigma(z(x)); & t_n = 1; & s_n = 1\\\\\n\t\t         \t&1-\\sigma(z(x)); & t_n = -1; & s_n = 0\n         \t\t\\end{aligned} \\right. &\\\\\n\t\t& \\qquad {} = \\prod_{n=1}^N \\left\\{\n\t\t\t\t\\begin{aligned}\n\t\t         \t& y_n; & t_n = 1; & s_n = 1\\\\\n\t\t         \t& 1-y_n; & t_n = -1; & s_n = 0\n         \t\t\\end{aligned} \\right. &\\\\\n\t\t& \\qquad {} = \\prod_{n=1}^N y_n^{s_n} (1-y_n)^{1-s_n} \\\\\n\t\t& L_\\omega = \\sum_{n=1}^N \\log \\left( p(t_n|x_n,\\omega) \\right) &\\\\\n\t\t& \\qquad {} = \\sum_{n=1}^N s_n \\log \\left( y_n \\right) + (1-s_n) \\log \\left( 1- y_n \\right)&\\\\\t\t\n\t\\end{flalign*}\n\\end{bbbox}\n\n\\subsection{Maximum likelihood estimation of Logistic Regression}\n\n\\textbf{Maximum likelihood estimation of Logistic Regression}\n\n\\begin{itemize}\n\\item This algorithm is called \\emph{logistic regression}, and is a \\emph{much} better algorithm than the algorithms we discussed last week.\n\\item Need to optimize log-likelihood numerically.\n\\item  People typically minimize the negative log-likelihood $\\mathcal{L}$ rather than maximize the log-likelihood...\n\\item  To numerically minimize the negative log-likelihood, we need its gradient (and maybe its hessian) [on board]\n\\end{itemize}\n\n\\begin{bbbox}{Gradient and Hessian for Logistic Regression}\n\tRather than maximizing the log-likelihood L people usually minimize the negative log-likelihood $\\mathcal{L}$. Since there is no close form solution for finding the minimum in the case of a logistic regression we utilize iterative algorithms. Those algorithms require that we calculate the gradient of $\\mathcal{L}$: \\\\\n\t\\begin{flalign*}\n\t\t& \\frac{\\partial \\mathcal{L}}{\\partial \\omega_i}\n\t\t    = - \\sum_{n=1}^N s_n \\frac{1}{y_n} y_n (1-y_n) x_n^{(i)}\n\t\t      + (1-s_n) \\frac{1}{1-y_n} y_n (-1) x_n^{(i)} & \\\\\n\t\t& \\qquad {} = - \\sum_{n=1}^N x_n^{(i)} \\left[ s_n - s_ny_n - y_n + s_ny_n \\right] & \\\\\n\t\t& \\qquad {} = \\sum_{n=1}^N \\left[ y_n -s_n \\right] x_n^{(i)} & \\\\\n\t\t& \\nabla \\mathcal{L} = \\sum_{n=1}^N \\left[ y_n -s_n \\right] x_n & \\\\\n\t\\end{flalign*}\nHowever some algorithms utilize the so called Hessian of our negative log-likelihood to reduce the number of iterations need for convergence. In word the Hessian is a square matrix of second order partial derivatives of $\\mathcal{L}$. Since we have already calculated the first order derivative we can use it to find the Hessian: \\\\\n\\begin{flalign*}\n\t& \\frac{\\partial \\mathcal{L}}{\\partial \\omega_i \\partial \\omega_j}\n\t\t= \\frac{\\partial}{\\partial \\omega_j} \\left[ \\frac{\\partial \\mathcal{L}}{\\partial \\omega_i} \\right]\n\t\t= \\frac{\\partial \\sum_{n=1}^N \\left[ y_n -s_n \\right] x_n^{(i)}}{\\partial \\omega_j}\n\t\t= \\sum_{n=1}^N \\left[ y_n (1- y_n) \\right] x_n^{(i)}x_n^{(j)} & \\\\\n\t& \\nabla \\nabla \\mathcal{L} = \\sum_{n=1}^N \\left[ y_n (1- y_n) \\right] x_n x_n^{\\top} & \\\\\n\t& \\text{where } \\left[x_n x_n^{\\top} \\right]_{ij} = x_n^{(i)}x_n^{(j)} &\n\\end{flalign*}\n\\end{bbbox}\n\n\\textbf{The cost-function for logistic regression is convex.}\n\\begin{figure}\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture7/Convex.pdf}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture7/NotConvex.pdf}\n\t\\end{subfigure}\t\n\\end{figure}\n\n\\begin{itemize}\n\\item  Fact: The negative log-likelihood is \\emph{convex} -- this makes life much more easier. \n\\item  There are no local minima to get stuck in, and there is good optimization techniques for convex problems. \n\\end{itemize}\n\n\\begin{bbbox}{Notes on convex functions and the Hessian}\n\tA function is convex whenever it's Hessian is positive definite.\\\\\n\tA matrix is positive definite if: $v^{\\top} M v > 0; \\forall v: \\|v\\| \\not= 0$ \\\\\n\tNote that having a symmetric matrix is not sufficient for a positive definite matrix. \\\\\n\tA convex funcion has only one minimum, i.e. minimizing guartuees global minimum.\n\\end{bbbox}\n\n\\textbf{\\emph{Gradient descent} is a simple method for numerically minimizing a function.}\n\\begin{itemize}\n\\item The gradient $\\nabla \\mathcal{L}$ of a function points into the direction of steepest descent.\n\\item  Gradient descent: 'run down the gradient' $\\omega_{new}=\\omega_{old}-\\alpha \\nabla \\mathcal{L}_\\omega$, with learning rate $\\alpha$.\n\\item  Slightly more sophisticated version: numerically optimize $\\alpha$ for each step by doing a \\emph{line search}.\n\\item  Convergence can be very slow if cost-function has `valleys'.\n\\end{itemize}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=.7\\textwidth]{./lecture7/BoydGradientDescent}\n\\caption{Figure taken from Boyd, Convex Optimization}\n\\end{figure}\n\n\\begin{figure}\n\t\\begin{subfigure}[b]{0.2\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture7/Newton0}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.2\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture7/Newton1}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.2\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture7/Newton2}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.2\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture7/Newton3}\n\t\\end{subfigure}\n\t\\\\\n\t\\begin{subfigure}[b]{0.2\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture7/Newton4}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.2\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture7/Newton5}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.2\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture7/Newton6}\n\t\\end{subfigure}\n\t\\caption{\\emph{Iterative Least Squares:} Approximate by parabola, minimze, iterate.}\n\\end{figure}\n\n\n\n\\textbf{\\emph{Iterative Least Squares} is a more efficient method for minimizing the cost-function}\n\\begin{itemize}\n\\item Newton-Raphson: $\\omega_{new}=\\omega_{old}-\\alpha (\\nabla \\nabla \\mathcal{L})^{-1}\\nabla L_\\omega$ \n\\item Pre-multiplying the gradient by the inverse-hessian speeds up convergence `along valleys' (analogy with LDA)\n \\item Motivation: For quadratic functions $F(x)=a+b^\\top x+ x^\\top B x$, Newton-Raphson finds the minimum in one iteration.\n \\item In this contex, Newton-Raphson (with $\\alpha=1$) is often called \\emph{iterative least squares}.\n \\item Note: Newtwn's method can be bad if problem is not convex, and can be slow if it is difficult to calculate/invert the Hessian. A large number of optimization algorithms exist which do not require the (complete) Hessian (quasi Newton/BFGS, etc..). \n% \\item Any (reasonable) optimization algorithm requires the gradient.\n\\end{itemize}\n\n\n\\textbf{Visualizing the cost-function of logistic regression}\n\n[on board]\n\n\n\\subsection{Bayesian Logistic Regression: Approximating the posterior distribution}\n\\textbf{Bayesian inference for this model does not have a closed form solution}\n\\begin{itemize}\n\\item Typically use Gaussian prior on $\\omega$.\n\\item For linear regression, posterior distribution was Gaussian, with closed-form solutions for the mean and covariance.\n\\item For logistic regression, the posterior distribution is non-Gaussian.\n\\item  Popular approximation: Approximate posterior by a Gaussian\n\\begin{align}\np(\\omega|D) \\approx \\mathcal{N}(\\mu_{post}, \\Sigma_{post})\n\\end{align}\n\\item  Different methods exist for finding `good' $\\mu_{post}$ and $\\Sigma_{post}$: Expectation Propagation (EP), Laplace Approximation, Variational Inference\n\\end{itemize}\n\n\\textbf{The Laplace-Approximation is a simple Gaussian approximation to the posterior}\n\\begin{itemize}\n\\item \\emph{Laplace approximation:} $\\mu_{post}=\\omega_{MAP}$, $\\Sigma_{post}=\\left(\\nabla \\nabla_\\omega L   \\right)^{-1}$. \n\\item Take MAP as mean, and inverse hessian at MAP as covariance.\n\\item  Motivation: Curvature matching, Taylor-expansion [on board]\n\\item  Q: When will the Laplace approximation fail?\n\\end{itemize}\n\\begin{figure}\n\\includegraphics[width=.49\\textwidth]{./lecture7/Figure414a.pdf}\n\\includegraphics[width=.49\\textwidth]{./lecture7/Figure414b.pdf}\n\\caption{Figure taken from Bishop PRML}\n\\end{figure}\n\n%\\textbf{The posterior distribution can be used to calculate the predictive distribution and to optimze hyper-parameters}\n%[on board]\n\n%\\section{LR's popular little brother-- support vector machines}\n\n%\\section{The exam}", "meta": {"hexsha": "c7c2815df593b0430b8c9f18fa01dc7d30054c7a", "size": 11042, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "script/lecture7/lecture7.tex", "max_stars_repo_name": "mackelab/machine-learning-I", "max_stars_repo_head_hexsha": "fedd9ea0b9b257af5cd59036a3b49876aed5c77c", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2015-07-31T15:08:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T17:07:23.000Z", "max_issues_repo_path": "script/lecture7/lecture7.tex", "max_issues_repo_name": "cne-tum/msne_statsandprob_ss2018", "max_issues_repo_head_hexsha": "fedd9ea0b9b257af5cd59036a3b49876aed5c77c", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "script/lecture7/lecture7.tex", "max_forks_repo_name": "cne-tum/msne_statsandprob_ss2018", "max_forks_repo_head_hexsha": "fedd9ea0b9b257af5cd59036a3b49876aed5c77c", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2018-03-16T07:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-01T14:02:27.000Z", "avg_line_length": 50.1909090909, "max_line_length": 332, "alphanum_fraction": 0.7172613657, "num_tokens": 3443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048443, "lm_q2_score": 0.8723473846343394, "lm_q1q2_score": 0.7449085664727405}}
{"text": "\\chapter{CT Systems as Linear Constant Coefficient Differential Equations}\n\nRecall a system is a transformation of signals, turning the input signal into the output signal. While this might seem like a new concept to you, you already know something about them from your differential equations course, i.e. MATH 2214 and your circuits course.\n\nFor example, consider the following circuit:\n\\begin{center}\n  \\begin{circuitikz}[american voltages,scale=0.8, every node/.style={transform shape}]\n    \\draw\n    (0,2.3) to[battery, l=$1\\mbox{ VDC}$] (0,0)\n    (3,2) node[spdt,xscale=-1,yscale=-1,anchor=in] (Sw) {}\n    (0,2.3) to[short] (Sw.out 2)\n    (Sw.out 1) to[short] (1.8,0)\n    (0,0) to[short, -o] (8,0)\n    (3,2) to[short] (4,2)\n    (4,2) to[open, v=$x(t)$] (4,0)\n    (4,2) to[R, l=$R$] (6,2)\n    (6,2) to[short, -o] (8,2)\n    (6,0) to[C, l=$C$] (6,2)\n    (8,2) to[open, v=$V_C(t)$] (8,0);\n  \\end{circuitikz}\n\\end{center}\nwhere the switch moves position at $t = 0$. The governing equation for the circuit when $t < 0$ is\n\\[\n\\frac{dV_c}{dt}(t) + \\frac{1}{RC}V_c(t) = 0\n\\]\na \\emph{homogeneous} differential equation of first-order. From a DC analysis, the initial condition on the capacitor voltage is $V_C(0^-) = 0$, so there is no current flowing prior to $t = 0$ and the solution is $V_C(t) = 0$ for $t < 0$.\n\nAfter the switch is thrown, the governing equation for the circuit when $t \\geq 0$ is\n\\[\n\\frac{dV_c}{dt}(t) + \\frac{1}{RC}V_c(t) = \\frac{1}{RC}\n\\]\nSince the voltage across the capacitor cannot change instantaneously $V_C(0^-) = V_C(0^+) = 0$, giving the auxillary condition necessary to solve this equation, which has the form\n\\[\nV_C(t) = A + Be^{-\\frac{1}{RC}t}\n\\]\nUsing the auxillary condition we find\n\\[\nV_C(0) = A + Be^{-\\frac{1}{RC}0} = A + B = 0 \\mbox{ which implies } B = -A \n\\]\nSubsitution back into the differential equation and equating the coefficients gives $A = 1$. Thus the voltage for $t \\geq 0$ is\n\\[\nV_C(t) = 1 - e^{-\\frac{1}{RC}t}\n\\]\n\nSuppose we consider the voltage after the switch as the input signal $x(t)$ to the system composed of the series RC. As we have seen previously a mathematical model of the switch is the unit step $x(t) = u(t)$. Suppose we consider the capacitor voltage at the outut of the system, so that $y(t) = V_C(t)$. Then we can consider the system to be represented by the \\emph{linear, constant-coefficient differential equation}\n\\[\n\\frac{dy}{dt}(t) + \\frac{1}{RC}y(t) = \\frac{1}{RC}x(t)\n\\]\nwhere $x(t) = u(t)$ and the solution $y(t)$ is the \\emph{step response}\n\\[\ny(t) = \\left(1 - e^{-\\frac{1}{RC}t}\\right)u(t)\n\\]\n\nAs we will see later this representation of systems is central to the course, so we take some time here to review the solution of such equations.\n \n\\section{Solving Linear, Constant Coefficient Differential Equations}\n\nA linear, constant coefficient (LCC) differential equation is of the form\n\\[\na_0\\, y + a_1\\, \\frac{dy}{dt} + a_2\\, \\frac{d^2y}{dt^2} + \\cdots + a_N\\, \\frac{d^Ny}{dt^N}  = b_0\\, x + b_1\\, \\frac{dx}{dt} + bb_2\\, \\frac{d^2x}{dt^2} + \\cdots + b_M\\, \\frac{d^My}{dt^M}\n\\]\nwhich can be written compactly as\n\\[\n\\sum\\limits_{k = 0}^{N} a_k\\, \\frac{d^ky}{dt^k} = \\sum\\limits_{k = 0}^{M} b_k\\, \\frac{d^kx}{dt^k}\n\\]\n\nIt is helpful to clean up this notation using the derivative operator $D^n = \\frac{d^n}{dt^n}$. For example\n$D^2y = \\frac{d^2y}{dt^2}$ and $D^0 y= y$. To give for form as\n\\[\n\\sum\\limits_{k = 0}^{N} a_k\\, D^k y = \\sum\\limits_{k = 0}^{M} b_k\\, D^k x\n\\]\n\nWe can factor out the derivative operators\n\\[\na_0y + a_1Dy + a_2D^2y + \\cdots + a_ND^Ny  = b_0\\, x + b_1\\, Dx + b_2\\, D^2x + \\cdots + b_M\\, D^M x\n\\]\n\\[\n\\underbrace{\\left(a_0 + a_1D + a_2D^2 + \\cdots + a_ND^N\\right)}_{\\text{Polynimial in } D, Q(D)} y = \\underbrace{\\left(b_0 + b_1 D + b_2 D^2 + \\cdots + b_M D^M\\right)}_{\\text{Polynimial in } D, P(D)} x\n\\]\nto give:\n  \n\\[\nQ(D)y = P(D)x\n\\]\nYou learned how to solve these in differential equations (Math 2214) as\n\\[\ny(t) = y_\\text{h}(t) + y_\\text{p}(t)\n\\]\n\nThe term $y_\\text{h}(t)$ is the solution of the homogeneous equation\n\\[\nQ(D)y = 0\n\\]\nGiven the $N-1$ auxillary conditions $y(t_0) = y_0$, $Dy(t_0) = y_1$, $D^2y(t_0) = y_2$, up to $D^{N-1}y(t_0) = y_{N-1}$.\n\nThe term $y_\\text{p}(t)$ is the solution of the particular equation\n\\[\nQ(D)y = P(D)x\n\\]\nfor a given $x(t)$.\n\nRather than recapitulate the solution to $y_\\text{h}(t)$ and $y_\\text{p}(t)$ in the general case we focus on the homogeneous solution $y_\\text{h}(t)$ only. The reason is that we will use the homogeneous solution to find the impulse response below and take a different approach to solving the general case for an arbitrary input using the impulse response and convolution (next week).\n\nTo solve the homogenous system:\n\n\\textbf{Step 1:} Find the \\emph{characteristic equation} by replacing the derivative operators by powers of an aribrary complex variable $s$.\n\\[\nQ(D) = a_0 + a_1D + a_2D^2 + \\cdots + a_ND^N\n\\]\nbecomes\n\\[\nQ(s) = a_0 + a_1s + a_2s^2 + \\cdots + a_Ns^N\n\\]\na polynomial in $s$ with $N$ roots $s_i$ for $i = 1, 2, \\cdots, N$ such that\n\\[\n(s - s_1)(s-s_2)\\cdots(s-s_N) = 0\n\\]\n\n\\textbf{Step 2:} Select the form of the solution, a sum of terms corresponding to the roots of the characteristic equation.\n\n\\begin{itemize}\n\\item For a real root $s_1\\in \\mathbb{R}$ the term is of the form\n  \\[\n  C_1 e^{s_1 t}.\n  \\]\n\\item For a pair of complex roots (they will always be in pairs) $s_{1,2} = a \\pm jb$ the term is of the form\n  \\[\n  C_1 e^{s_1 t} + C_2 e^{s_2 t} = e^{a t}\\left(C_3\\cos(bt) + C_4\\sin(bt)\\right) = C_5 e^{a t}\\cos(bt + C_6).\n  \\]\n\\item For a repeated roots $s_1$, repeated r times, the term is of the form\n  \\[\n  e^{s_1 t} (C_0 + C_1 t + \\cdots + C_{r-1} t^{r-1}).\\]\n\\end{itemize}\n\n\\textbf{Step 3:} Solve for the unknown constants in the solution using the auxillary conditions. \n\nWe now examine two common special cases, when $N=1$ (first-order) and when $N=2$ (second-order).\n\n\\subsection{First-Order Homogeneous LCCDE}\n\nConsider the first order homogeneous differential equation\n\\[\n\\frac{dy}{dt}(t) + ay(t) = 0 \\mbox{ for } a \\in \\mathbb{R}\n\\]\nThe characteristic equation is given by\n\\[\ns + a = 0\n\\]\nwhich has a single root $s_1 = -a$. The solution is of the form\n\\[\ny(t) = Ce^{s_1 t} = Ce^{-a t} \n\\]\nwhere the constant $C$ is found using the auxillary condition $y(t_0) = y_0$.\n\n\\textit{Example}: Consider the homogeneous equation\n\\[\n\\frac{dy}{dt}(t) + 3y(t) = 0 \\mbox{ where } y(0) = 10\n\\]\nThe solution is\n\\[\ny(t) = Ce^{-3 t} \n\\]\nTo find $C$ we use the auxillary condition\n\\[\ny(0) = Ce^{-3 \\cdot 0} = C = 10\n\\]\nand the final solution is\n\\[\ny(t) = 10e^{-3 t} \n\\]\n\\subsection{Second-Order Homogeneous LCCDE}\n\nConsider the second-order homogeneous differential equation\n\\[\n\\frac{d^2y}{dt^2}(t) + a\\frac{dy}{dt}(t) + by(t) = 0 \\mbox{ for } a,b \\in \\mathbb{R}\n\\]\nThe characteristic equation is given by\n\\[\ns^2 + as + b = 0\n\\]\n\nLet's look at several examples to illustrate the functional forms.\n\nExample 1:\n\\[\n\\frac{d^2y}{dt^2}(t) + 7\\frac{dy}{dt}(t) + 10y(t) = 0 \n\\]\nThe characteristic equation is given by\n\\[\ns^2 + 7s + 10 = 0\n\\]\nwhich has roots $s_1 = -2$ and $s_2 = -5$. Thus the form of the solution is\n\\[\ny(t) = C_1e^{-2t} + C_2e^{-5t}\n\\]\n\nExample 2:\n\\[\n\\frac{d^2y}{dt^2}(t) + 2\\frac{dy}{dt}(t) + 5y(t) = 0 \n\\]\nThe characteristic equation is given by\n\\[\ns^2 + 2s + 5 = 0\n\\]\nwhich has complex roots $s_1 = -1+j2$ and $s_1 = -1-j2$. Thus the form of the solution is\n\\[\ny(t) = e^{-t}\\left(C_1\\cos(2t) + C_2\\sin(2t)\\right)\n\\]\n\nExample 3:\n\\[\n\\frac{d^2y}{dt^2}(t) + 2\\frac{dy}{dt}(t) + y(t) = 0 \n\\]\nThe characteristic equation is given by\n\\[\ns^2 + 2s + 1 = 0\n\\]\nwhich has a root $s_1 = -1$ repeated $r=2$ times. Thus the form of the solution is\n\\[\ny(t) = e^{-t}\\left(C_1 + C_2t\\right)\n\\]\n\nIn each of the above cases the constants, $C_1$ and $C_2$, are found using the auxillary conditions $y(t_0)$ and $y\\prime(t_0)$.\n\n\\section{Finding the impulse response of a system described by a LCCDE}\n\nAs we will see next week an important response of a system is the one that corresponds to an impulse input, i.e. the \\emph{impulse response} $y(t) = h(t)$ when $x(t) = \\delta(t)$. Thus we focus here on a recipe for solving LCCDEs for this special case when $M \\leq N$. We will skip the derivation of why this works.\n\nOur goal is to find the solution to $Q(D)y = P(D)x$ when $x(t)=\\delta(t)$.\n\n\\textbf{Step 1:} Let $y_h(t)$ be the homogeneous solution to $Q(D)y_h = 0$ for auxillary conditions\n  \\[\n    D^{N-1}y_h(0^+) = 1 \\; , \\; D^{N-2}y_h(0^+) = 0 \\; , \\; \\text{etc.} \\; y_h(0^+) = 0 \n    \\]\n    \n\\textbf{Step 2:} Assume a form for $h(t)$ given by:\n  \\[\n  h(t) = \\underbrace{b_N\\delta(t)}_{=0 \\text{ unless } N=M} + \\underbrace{\\left[ P(D)y_h\\right]}_{\\text{apply } P(D) \\text{ to } y_n(t)}u(t)\n  \\]\n\nRecall from above the homogeneous solution depends on the roots of the characteristic equation $Q(D) = 0$.\n\n\\begin{itemize}\n\\item roots are either real, or\n\\item roots occur in complex conjugate pairs, or\n\\item repeated roots.\n\\end{itemize}\n\nExample 1: Find the impulse response of the LCCDE\n\\[\n\\frac{dy}{dt}(t) + y(t) = x(t)\n\\]\nThe characteristic equation is given by\n\\[\ns + 1 = 0\n\\]\nwhich has a single root $s_1 = -1$. The solution is of the form\n\\[\ny_h(t) = Ce^{-t} \n\\]\nwith the special auxillary condition $y(0) = 1$, so that\n\\[\ny_h(t) = e^{-t} \n\\]\nSince $P(D) = 1$ and $N = 1 \\neq M = 0$ the impulse response is\n\\[\nh(t) = \\underbrace{b_N\\delta(t)}_{=0} + \\left[ \\underbrace{P(D)}_{1}y_h(t)\\right]u(t) = e^{-t}u(t)\n\\]\n\nExample 2: Find the impulse response of the LCCDE\n\\[\n\\frac{dy}{dt}(t) + y(t) = \\frac{dx}{dt}(t) + x(t)\n\\]\nThe homogeneous solution is the same as in Example 1,\n\\[\ny_h(t) = e^{-t} \n\\]\nhowever now $M = N = 1$ with $b_1 = 1$ and $P(D) = D+1$. Thus, the impulse response is\n\\[\nh(t) = \\underbrace{b_N}_{=1}\\delta(t) + \\left[ \\underbrace{P(D)}_{D+1}y_h(t)\\right]u(t) = \\delta(t) + \\left\\{[D+1]e^{-t}\\right\\}u(t) = \\delta(t) + [- e^{-t} + e^{-t}]u(t) = \\delta(t) \n\\]\n\nExample 3: Find the impulse response of the LCCDE\n\\[\n\\frac{d^2y}{dt^2}(t) + 7\\frac{dy}{dt}y(t) + 10y(t) = x(t) \n\\]\nThe characteristic equation is given by\n\\[\ns^2 + 7s + 10 = 0\n\\]\nwhich has roots $s_1 = -2$ and $s_2 = -5$. Thus the form of the solution is\n\\[\ny_h(t) = C_1e^{-2t} + C_2e^{-5t}\n\\]\nThe special auxillary conditions are $y_h(0) = 0$ and $y^\\prime_h(0) = 1$. Using these conditions\n\\[\ny_h(0) = C_1e^{-2t} + C_2e^{-5t} |_{t = 0} = C_1 + C_2 = 0\n\\]\n\\[\ny^\\prime_h(0) = -2C_1e^{-2t} - 5C_2e^{-5t} |_{t = 0} = -2C_1 -5C_2 = 1\n\\]\nSolving for the constants gives $C_1 = \\frac{1}{3}$ and $C_2 = -\\frac{1}{3}$. Since $P(D) = 1$ and $N = 2 \\neq M = 0$ the impulse response is\n\\[\nh(t) = \\underbrace{b_N\\delta(t)}_{=0} + \\left[ \\underbrace{P(D)}_{1}y_h(t)\\right]u(t) = \\frac{1}{3} e^{-2t}u(t) - \\frac{1}{3} e^{-5t}u(t)\n\\]\n\n", "meta": {"hexsha": "3f1a0ae95b6ef40ca1db4ac0c13c0fc716d107a4", "size": 10689, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "04-ct-lccde.tex", "max_stars_repo_name": "clwyatt/notes-2714", "max_stars_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "04-ct-lccde.tex", "max_issues_repo_name": "clwyatt/notes-2714", "max_issues_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "04-ct-lccde.tex", "max_forks_repo_name": "clwyatt/notes-2714", "max_forks_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.8175895765, "max_line_length": 420, "alphanum_fraction": 0.6357938067, "num_tokens": 4182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7449085498632304}}
{"text": "\\section{Expressiveness}\n\\label{sec:expressiveness}\n\nA major advantage of ARX cipher family is the expressiveness\n\\footnote{The content is inspired by a question on StackExchange:\n\\url{https://crypto.stackexchange.com/questions/51412/}}.\nWith only three primitives, ARX cipher is able to perform almost all confusion and\ndiffusion techniques. Theoretically, it is shown that $\\textit{ARX}(n)$ primitives\ncan simulate all permutations over $\\mathbb{Z}_{2^n}$, hence replace the S-box in\nblock cipher constructions. A more general conclusion states that, $\\textit{ARX}(n)$\ncan represent all functions $\\mathbb{Z}_{2^n}^m\\rightarrow\\mathbb{Z}_{2^n}$ for any\npositive integer $m$.\n\n\\subsection{Simulating Permutations}\n\nA \\textit{permutation} of the finite set $X$ is a bijective function $\\pi:\\textit{X}\\rightarrow X$.\nSuch $\\pi$ is called a permutation over $X$. In other word, permutation is the\nrearrangement of a finite sequence. It is trivial to see that all permutations can be\ngenerated by solely swapping operations on any other permutation. The swapping on a\nfinite sequence is defined as follow:\n\n\\begin{definition}\nLet sequence $X=(x_1,x_2,\\cdots,x_n)$, \\textit{swapping} two elements $x_i$, $x_j$ in\n$X$ resulting another sequence $X'=(x'_1,x'_2,\\cdots,x'_n)$ such that:\n\\begin{align*}\nx_i &= x'_j \\\\\nx_j &= x'_i \\\\\nx_k &= x'_k\\ \\mathrm{for}\\ k\\notin\\{i,j\\}\n\\end{align*}\n\\end{definition}\n\nMany block ciphers adopt permutations as the nonlinear components, which also called\nthe \\textit{S-boxes} \\cite{stinson2005cryptography}. ARX cipher obtains its nonlinearity\nfrom the modular addition, which is able to form (or \\textit{simulate}) more complicated\nnonlinear components. A nice property of ARX family states that, it can simulate all\npermutations over the message space:\n\n\\begin{theorem}\n\\label{thm:perm}\nFor all permutations $\\pi$ over $\\mathbb{Z}_{2^n}$, $\\pi\\in\\textit{ARX}(n)$.\n\\end{theorem}\n\nGiven arbitrary permutation, say that, the permutation in natural ordering, it is able to\ngenerate any desired permutation by a pile of swapping operations on specific pairs of\npermutation elements. Then, by showing swapping can be realized by ARX operations,\nTheorem \\ref{thm:perm} can be proven:\n\n\\begin{proof}\nWe proof this by construction, that is, we will construct a function $\\sigma$ such that\n$\\sigma\\textit{(X)}$ swaps two particular elements in the permutation $X$. Note that\n$\\sigma$ doesn't consider the positions of the elements being swapped, however, since all\nelements in a permutation are unique, this definition does not introduce any ambiguity.\n\nThe problem can therefore be simplified as, constructing an ARX function $\\sigma$ such\nthat, for input pair $(a,b)$, there are $\\sigma(a)\\textit{=}b$, $\\sigma(b)\\textit{=}a$,\nand $\\sigma(x)\\textit{=}x$ for $x\\notin\\{a,b\\}$. Denote this function by $f_{a,b}(x)$.\nGiven multiple such functions, their composition is thus a permutation over the domain.\n\nWithout loss of generality, let $a\\neq b$. For simplicity, let $x-y=x+(2^n-y)$, and\n$\\mathrm{r}^{-b}(x)=\\mathrm{r}^{n-b}(x)$ (the right rotation). We then construct\n$f_{a,b}(x)$ by the following routine:\n\n\\begin{enumerate}\n\\setlength\\partopsep{0em}\n\\setlength\\topsep{0em}\n\\setlength\\itemsep{0em}\n\\setlength\\parskip{0em}\n\\item let $a'=0$, $b'=b-a$, the base function $f_0(x)\\textit{=}x-a$\n\\item find the integer $i$ such that $\\mathrm{r}^{-i}(b')$ is an odd number, set\n$b'=\\mathrm{r}^{-i}(b')$ and function $f_1(x)\\textit{=}\\mathrm{r}^{-i}(f_0(x))$, denoted\nby $f_1\\textit{=}\\mathrm{r}^{-i}(f_0)$\n\\item \\label{enum:loopcond} loop Step \\ref{enum:loop} for $b'\\neq1$, otherwise, go to\nStep \\ref{enum:loopout}\n\\item \\label{enum:loop} let $b'=(b'\\oplus1)-1$, function $f_i\\textit{=}(f_{i-1}\\oplus1)-1$\n\\item \\label{enum:loopout} let $f_k=f_{i}+2^n-2$, and the auxiliary function\n$g(x)=\\mathrm{r}^1(\\mathrm{r}^{-1}(x+2)-1)$\n\\item output function $\\sigma=f_k^{-1}(g(f_k))$ as $f_{a,b}$\n\\end{enumerate}\n\n\\noindent Here we take $f_i$ as the last function when the looping condition at Step\n\\ref{enum:loopcond} no longer holds. Also notice that $g(x)$ is equivalent to swapping\nfunction $f_{2^n-2,2^n-1}(x)$. The inverse function $f_k^{-1}$ can be easily calculated\nsince $f_k$ is a composition of ARX primitives.\n\nTo see $\\sigma$ swap $(a,b)$, calculate the following functions:\n\n\\begin{equation*}\n\\setlength{\\abovedisplayshortskip}{0em}\n\\setlength{\\abovedisplayskip}{0em}\n\\begin{split}\nf_0(a) &= 0\\\\\nf_1(a) &= 0\\\\\nf_i(a) &= 0\\\\\nf_k(a) &= 2^n-2\\\\\ng(f_k(a)) &= 2^n-1\\\\\n\\end{split}\n\\quad\\quad\n\\begin{split}\nf_0(b) &= b-a\\\\\nf_1(b) &= (b-a)/2^i\\\\\nf_i(b) &= 1\\\\\nf_k(b) &= 2^n-1\\\\\ng(f_k(b)) &= 2^n-2\\\\\n\\end{split}\n\\end{equation*}\n\n\\noindent Notice that $f_k(b)=2^n-1$ indicates the inverse function $f_k^{-1}(2^n-1)=b$,\nhence $\\sigma(a)=f_k^{-1}(g(f_k(a)))=b$. Similarly, there are $\\sigma(b)=a$.\n\nFor $x\\notin\\{a,b\\}$, there are $f_k(x)\\notin\\{2^n-2,2^n-1\\}$ and thus $g(x)=x$. It\nfollows that $\\sigma(x)=f_k^{-1}(g(f_k(x)))=f_k^{-1}(f_k(x))=x$ hence complete the proof.\n\\end{proof}\n\nA Python3 implementation of the above construction is presented in Appendix\n\\ref{ssec:permarx}, it shows that this construction is feasible at software level.\n\n\\subsection{Completeness of \\textbf{\\textit{ARX}(n)}}\n\nA more general statement regarding the expressiveness of ARX ciphers is given as:\n\n\\begin{theorem}\n\\label{thm:func}\nFor all function $f:\\mathbb{Z}_{2^n}\\rightarrow\\mathbb{Z}_{2^n}$, $f\\in\\textit{ARX}(n)$.\n\\end{theorem}\n\nFormally, it is said that ARX operations are functionally complete in the set of\nfunctions over $\\mathbb{Z}_{2^n}$ \\cite{khovratovich2010rotational}. Khovratovich and\nNikoli{\\'c} give a proof by construction for this theorem\\footnote{the proof here does\nnot strictly follow the origin, as it has several mistakes and is in different notation}:\n\n\\begin{proof}\nGiven a sequence $X=x_1x_2\\cdots x_n$, the task is to compute all functions $F(X)$ via\nARX primitives.\n\nFirstly, let $$s_i(X)=\\mathrm{r}^1\\Bigg(\\sum^{2^{n-1}}\\mathrm{r}^i(X)\\Bigg)$$ which\nmoves the $i$-th bit of X to the rightmost while keeps all other bits 0. To see this,\nnote that the innermost $\\mathrm{r}^i(X)=x_{i+1}...x_nx_1...x_i$, adding itself by\n$2^{n-1}$ times is equivalent to applying left-shifting by $n-1$ bits, that results\nin $x_i$ at the leftmost while all other bits are $0$s. In other word, $s_i(X)=00...0x_i$.\n\nThen define function $$M_k(X,Y)=\\mathrm{r}^{-1}\\Bigg(\\sum^2\\mathrm{r}^{-1}(s_k(X)+s_k(Y))\\Bigg)$$\nfor two sequences $X$ and $Y$. $M_k$ compute the product of two bits $x_k$ and $y_k$,\n\\ie, $M_k(X,Y)=x_ky_k$. This is equivalent to the bitwise-and of $x_k$ and $y_k$.\nThe innermost sum $s_k(X)+s_k(Y)=00...0(x_ky_k)(x_k\\oplus y_k)$. By rotating it by 1\nbit and multiplying by 2, the product $x_ky_k$ is left at the $n\\textrm{-}1$-th bit.\n\nNext, compute the equivalence trial $$j_C(X)=\\begin{cases}\n1\\textrm{ , if }X=C=c_1c_2...c_n\\\\\n0\\textrm{ , otherwise}\\\\\n\\end{cases}$$ the function can be realized by function $M_k$ and constant 1, that is,\n$j_C(X)=\\Big[\\bigoplus_{i=1}^nM_i(X,C)\\Big]\\oplus1$.\n\nFinally, let function $J_{C_1,C_2}(X)=C_2\\cdot j_{C_1}(X)$, that evaluates to $C_2$ if\n$X=C_1$ and to 0 for other values. The output function is $f=J_{\\textit{X}, F(\\textit{X})}$\n\\end{proof}\n\nActually, Khovratovich and Nikoli{\\'c} even proof that all functions can be realized by\nonly $AR(n)$. This is proofed by the fact that xor can be realized with $AR$ operations.\nThe reader may refer \\cite{khovratovich2010rotational} for the complete proof of this\nstatement.\n", "meta": {"hexsha": "e9d3c052abd684eccf82f6bec939e72cb4917e54", "size": 7485, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "expressiveness.tex", "max_stars_repo_name": "CirQ/arx_latex", "max_stars_repo_head_hexsha": "5d76131975d6a24ff71c1fff4c26d2ebbf16da0d", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "expressiveness.tex", "max_issues_repo_name": "CirQ/arx_latex", "max_issues_repo_head_hexsha": "5d76131975d6a24ff71c1fff4c26d2ebbf16da0d", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "expressiveness.tex", "max_forks_repo_name": "CirQ/arx_latex", "max_forks_repo_head_hexsha": "5d76131975d6a24ff71c1fff4c26d2ebbf16da0d", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.4906832298, "max_line_length": 99, "alphanum_fraction": 0.714495658, "num_tokens": 2475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7448949802558297}}
{"text": "\\section{Integrals of VVFs}\r\nVVFs can also be integrated. The integration operation also distributes inside the vector, for both definite and indefinite integrals.\r\n\\begin{equation*}\r\n\t\\int{\\vec{r}(t)\\mathrm{d}t} = \\left<\\int{x(t)\\mathrm{d}t},\\int{y(t)\\mathrm{d}t},\\int{z(t)\\mathrm{d}t}\\right>\r\n\\end{equation*}\r\nFor indefinite integrals, the result will have a vector of constants will be added.", "meta": {"hexsha": "4e618f0c247835e4b427e232f3e51a5cd0c57847", "size": 395, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorValuedFunctions/IntegralsOfVVFs.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/vectorValuedFunctions/IntegralsOfVVFs.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/vectorValuedFunctions/IntegralsOfVVFs.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.8333333333, "max_line_length": 135, "alphanum_fraction": 0.7367088608, "num_tokens": 123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7448587907466214}}
{"text": "\\chapter{Encryption}\n\n\\epigraph{Any one who considers arithmetical methods of producing random digits is, of course, in a state of sin.}{\\textit{John von Neumann}}\n\n\nWhen information is being transmitted, it is usually possible for the message to be read by people other than the intended recipient. The idea of encryption is to change the message in such a way that only a particular recipient will be able to recover the original message. This is achieved by altering a message using some kind of per-arranged secret information that has only been shared with the recipient you want to be able to read the message.\\\\\n\nThe original message is called the plaintext message. The encrypted message is called the ciphertext. And the secret information is called the key.\\\\\n\n\\section{One-Time Pad}\n\nThe first such algorithm we will look at is what is called a one-time pad. A one-time pad is a unique reference material that contains purely random values, which acts as the secret key. The first issue is how to get truly random anything, but assuming you have it you then make an exact copy of the one-time pad and share it with the person you wish to be able to send a message (and noone else). It is important that noone else be able to see this pad (the key), because anyone who has it will be able to read the message. So it must be shared in a known secure manner, such as in person. It might look something like the following.\\\\\n\n\\begin{center}\n\t\\begin{tabular}{c | c | c | c }\n\t\t \\texttt{zyhdjkxs} & \\texttt{noujnbpx} & \\texttt{erdtgnhb} & \\texttt{txqursil}\\\\\n\t\t \\texttt{armlijnm} & \\texttt{wkrcsjus} & \\texttt{xcmyrzfj} & \\texttt{iygoosom}\\\\\n\t\t \\texttt{woqzafpi} & \\texttt{neqxbysh} & \\texttt{afpvoxww} & \\texttt{kvepxkwu}\\\\\n\t\t \\texttt{boxllkib} & \\texttt{tiohhxsg} & \\texttt{zbylmrgp} & \\texttt{ipuilvvb}\\\\\n\t\t \\texttt{xedpjdqx} & \\texttt{yiyrrndi} & \\texttt{bbqptpmy} & \\texttt{oxstqgrn}\\\\\n\t\\end{tabular}\n\\end{center}\n\n\nAt some later time you can encrypt a message using the values on the one-time pad. Basically, each letter is assigned a number value. One random numeric value is added to one plaintext numeric value, and taking the modulus of the maximum number of possibilities. The result of this operation is the ciphertext.\\\\\n\n\n\\begin{center}\n\t\n\t\\begin{tabular}{c | c }\n\t\t\n\t\ta = 0 & n = 13 \\\\\n\t\tb = 1 & o = 14 \\\\\n\t\tc = 2 & p = 15 \\\\\n\t\td = 3 & q = 16 \\\\\n\t\te = 4 & r = 17 \\\\\n\t\tf = 5 & s = 18 \\\\\n\t\tg = 6 & t = 19 \\\\\n\t\th = 7 & u = 20 \\\\\n\t\ti = 8 & v = 21 \\\\\n\t\tj = 9 & w = 22 \\\\\n\t\tk = 10 & x = 23 \\\\\n\t\tl = 11 & y = 24 \\\\\n\t\tm = 12 & z = 25 \\\\\n\t\\end{tabular}\n\\end{center}\n\nSuppose I want to send the message \"Meet me at noon\", this is the plaintext and has 12 letters (ignoring the spaces). I have already shared the above one-time pad with the person that I want to read the message. Since the message has 12 letters, I need to use 12 random values from the one-time.\\\\", "meta": {"hexsha": "399f817f01c56c973ef523e9f1e86e4f7a8a4d1f", "size": 2875, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TeX_files/Encryption.tex", "max_stars_repo_name": "kcdodd/ecsp-book", "max_stars_repo_head_hexsha": "371e0e07140bc2fa5a8e3d424510900f368f885a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-07-27T18:34:02.000Z", "max_stars_repo_stars_event_max_datetime": "2015-07-27T18:34:02.000Z", "max_issues_repo_path": "TeX_files/Encryption.tex", "max_issues_repo_name": "kcdodd/ecsp-book", "max_issues_repo_head_hexsha": "371e0e07140bc2fa5a8e3d424510900f368f885a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TeX_files/Encryption.tex", "max_forks_repo_name": "kcdodd/ecsp-book", "max_forks_repo_head_hexsha": "371e0e07140bc2fa5a8e3d424510900f368f885a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.8958333333, "max_line_length": 636, "alphanum_fraction": 0.7116521739, "num_tokens": 859, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148512, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7448587863759971}}
{"text": "\\section{Partial Derivatives}\r\n\\noindent\r\nThe single-variable calculus idea of tangent lines doesn't work for higher dimensional surfaces because we can draw many different lines that are tangent to the surface, depending on which plane we use to slice the surface. That is, from which direction we approach the surface.\r\n\\input{./differentialMultivariableCalculus/partialDerivativesXYZ}\r\n\\input{./differentialMultivariableCalculus/tangentPlanes}\r\n\\input{./differentialMultivariableCalculus/linearApproximations}", "meta": {"hexsha": "be35fc930262bec98fa41706051b4254884cd175", "size": 512, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/partialDerivatives.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/partialDerivatives.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/partialDerivatives.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 85.3333333333, "max_line_length": 279, "alphanum_fraction": 0.837890625, "num_tokens": 113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.903294201497187, "lm_q2_score": 0.8244619306896956, "lm_q1q2_score": 0.7447316813471777}}
{"text": "\\section{More about categories}\n%moved defn of Fun(C,D) to prev. section\n%moved split epi/mono into single definition\n%the example on splitting changed to an exercise, since it was leaving stuff to the reader anyway\nLet $\\mathrm{Vect}_{\\mathbf{C}}$ be the category of $\\mathbf{C}$-vector spaces with $\\mathbf{C}$-linear transformations. Given such a vector space $V$, taking the dual gives another vector space $V^\\ast=\\Hom(V,\\mathbf{C})$, and a linear transformation $f:V\\to W$ dualizes to $f^\\ast:W^\\ast\\to V^\\ast$. This process resembles a functor $\\mathrm{Vect}_{\\mathbf{C}} \\to \\mathrm{Vect}_{\\mathbf{C}}$, except that it reverses the direction of morphisms.\n\\begin{definition}\nLet $\\cc$ be a category. Define its \\emph{opposite category} $\\cc^{op}$ to have the same objects as $\\cc$ but with morphisms reversed, so that for all $X,Y\\in\\mathrm{ob}(\\cc)$, we have $\\cc^{op}(X,Y) = \\cc(Y,X)$. Composition in $\\cc^{op}$ is the same as in $\\cc$.\n\nIf $\\cd$ is another category, then a \\emph{contravariant functor} $\\cc\\to \\cd$ is an ordinary (or \\emph{covariant}) functor $\\cc^{op}\\to\\cd$.\n\\end{definition}\nLet $\\cc$ be a category, and let $Y\\in\\mathrm{ob}(\\cc)$. Consider the functor $\\cc^{op}\\to\\set$ that takes $X\\in\\mathrm{ob}(\\cc)$ to the set $\\cc(X,Y)$, and takes a map $f\\colon X\\to W$ to the map $-\\circ f\\colon \\cc(W,Y)\\to \\cc(X,Y)$ which is precomposition by $f$. This functor, denoted $\\cc(-,Y)$, is called the functor \\emph{represented by $Y$}. Similarly, there is a functor $\\cc(-,Y)$ which is called the functor \\emph{corepresented by $Y$}. Note that $\\cc(-,Y)$ is contravariant and $\\cc(Y,-)$ is covariant.\n\nRecall that $\\Deltab$ has objects $[0],[1],[2],\\cdots$ and there is a functor $\\Deltab\\to\\mathbf{Top}$ that sends $[n]\\mapsto\\Delta^n$ (see Exercise \\ref{exer:simplicialidentities}). Let $X$ be a space, and consider the functor $\\mathbf{Top}^{op}\\to\\set$ represented by $X$. Composing these functors gives a functor $\\Delta^{op}\\to\\set$ which sends $[n]\\mapsto\\mathbf{Top}(\\Delta^n,X)=:\\Sin_n(X)$. This is precisely the singular simplicial set of $X$.\n\\begin{prop}\nSimplicial sets are precisely functors $\\Deltab^{op}\\to\\set$, i.e., $s\\set=\\mathbf{Fun}(\\Deltab^{op},\\set)$. More generally, simplicial objects in a category $\\cc$ are functors $\\Deltab^{op}\\to\\cc$, i.e., $s\\cc=\\mathbf{Fun}(\\Deltab^{op},\\cc)$.\n\\end{prop}\nIf $\\Deltab_{inj}$ is the subcategory of $\\Deltab$ whose morphisms are only the injective maps, then $ss\\cc:=\\mathbf{Fun}(\\Deltab^{op}_{inj},\\cc)$ is the category of semi-simplicial objects in $\\cc$ (which differ from simplicial objects in that they only have face maps).\n\\begin{definition}\nLet $X,Y\\in \\cc$. We say that a morphism $f\\colon X\\rightarrow Y$ is a \\emph{split epimorphism} if there exists $g:Y\\to X$ (often called a section or a splitting) such that $Y\\xrightarrow{g}X\\xrightarrow{f}Y$ is the identity $1_Y$.\n\nWe say that a morphism $g\\colon Y\\rightarrow X$ is a \\emph{split monomorphism} if there exists $f\\colon X\\to Y$ such that $Y\\xrightarrow{g}X\\xrightarrow{f}Y$ is the identity $1_Y$.\n\\end{definition}\n\\begin{example}\nLet $\\cc=\\set$. If $f:X\\to Y$ is a split epimorphism with $f\\circ g = 1_Y$, then for every $y\\in Y$, we have $f(g(y))=y$ and thus $f$ is surjective. Is every surjective map a split epimorphism? Constructing a splitting $g$ amounts to picking $g(y)\\in f^{-1}(y)$ for all $y\\in Y$, so this reduces to the axiom of choice.\n\nNow assume that $g: X\\to Y$ is a split monomorphism. Suppose that $y,y^\\prime\\in Y$ are such that $g(y)=g(y^\\prime)$. Applying $f$ gives $y=y^\\prime$, and thus split monomorphisms are injective. Conversely, if $Y$ is nonempty, then every injection $g:Y\\to X$ is a split monomorphism.\n\\end{example}\n\\begin{example}\nA morphism is an isomorphism if and only if it is both a split epi and a split mono.\n\\end{example}\n\\begin{lemma}\nIf $f:X\\to Y$ is a split epi (resp. split mono) in $\\cc$, and $F:\\cc\\to \\cd$, then $F(f)$ is a split epi (resp. split mono) in $\\cd$.\n\\end{lemma}\n\\begin{proof}\nIf $g$ splits $f$ in $\\cc$, then $F(g)$ splits $F(f)$ in $\\cd$.\n\\end{proof}\n\\begin{exercise}\\label{ex:split-epi-mono-isomorphism}\nSuppose $A,B\\in \\cc=\\mathbf{Ab}$ and $f:A\\to B$ is a split epi, so that $fg=1$ for some $g\\colon B\\rightarrow A$. Let $i\\colon \\ker f\\to A$ be the inclusion, and consider the sum $\\ker f\\oplus B\\xrightarrow{[i,g]} A$. Show that $[i,g]$ is an isomorphism.\n\nIf $g:B\\to A$ is a split mono, there exists $f:A\\to B$ so that $fg=1$. Let $p\\colon A\\rightarrow \\mathrm{coker}(g)$ be the quotient map, and consider the map $A\\xrightarrow{\\begin{pmatrix}\np \\\\ f\n\\end{pmatrix}}\\mathrm{coker}(g)\\oplus B$. Show that this is an isomorphism.\n\\end{exercise}\nWe have to get into some topology, since it's on our agenda. In the category $\\mathbf{Top}$, the one-point space $\\ast$ is terminal, meaning that for any space $X$ there is a unique map $X\\to\\ast$. This induces a map\n\\[H_n(X)\\to H_n(\\ast)=\\begin{cases}\\mathbf{Z} & n=0\\\\\n0 & \\text{else}\\end{cases}\\]\nwhich is called the \\emph{augmentation map}.\n\nTake a 0-cycle $\\sum a_ix_i$ where the $x_i$ are points in $X$. Consider its homology class $\\left[\\sum a_ix_i\\right]\\in H_0(X)$. Under the induced map above, this is sent to $\\left[\\sum a_i\\ast\\right]=\\left(\\sum a_i\\right)\\left[\\ast\\right]$. \n\\begin{definition}\nA \\emph{pointed space} is a pair $(X,\\ast)$, with $\\ast\\in X$ called the \\emph{basepoint}.\n\\end{definition}\nLet $\\ast\\to X\\to\\ast$ be the inclusion of the basepoint followed by the unique map to $\\ast$. In homology we get a map $\\mathbf{Z}\\xrightarrow{\\eta} H_\\ast(X)\\xrightarrow{\\epsilon}\\mathbf{Z}$, where the composition is the identity. The map $\\epsilon$ is the augmentation map described above, so we see that it is a split epimorphism. This means that, by Exercise \\ref{ex:split-epi-mono-isomorphism}, $ H_\\ast(X)\\cong \\mathbf{Z}\\oplus\\mathrm{coker}\\eta \\cong\\mathbf{Z}\\oplus\\ker\\epsilon$. The \\emph{reduced homology} of $(X,\\ast)$ is $ H_\\ast(X,\\ast)=\\mathrm{coker}\\eta$. It's isomorphic to $ H_\\ast(X)$ in dimensions greater than $0$, but differs by a factor of $\\mathbf{Z}$ in dimension $0$.\n\n", "meta": {"hexsha": "1c63bce74d9c4c282130851ce92fd7f860ff1f86", "size": 6074, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-4-more-on-categories.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "old-905/lec-4-more-on-categories.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "old-905/lec-4-more-on-categories.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 110.4363636364, "max_line_length": 693, "alphanum_fraction": 0.7001975634, "num_tokens": 2026, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.9032942021480236, "lm_q1q2_score": 0.7447316701957052}}
{"text": "\\section{Inner Product Space}\n\n\n\\subsection{Inner Product and Norm}\n\n\\begin{definition}\n\tAn \\cindex{inner product} on $V$ is a function $V \\rightarrow V \\rightarrow F$ ($F$ is either $C$ or $R$) that $\\forall x,y,z \\in V$ and $\\forall c \\in F$ that:\n\t\\begin{enumerate}\n\t\t\\item $\\innerproduct{x+z}{y} = \\innerproduct{x}{y} + \\innerproduct{z}{y}$ \\label{firstproductdefinition}\n\t\t\\item $\\innerproduct{cx}{y} = c \\innerproduct{x}{y}$ \\label{secondproductdefinition}\n\t\t\\item $\\overline{\\innerproduct{x}{y}} = \\innerproduct{y}{x}$\n\t\t\\item $\\innerproduct{x}{x} > 0$ if $x \\neq 0$\n\t\\end{enumerate}\n\tItem (\\ref{firstproductdefinition}) and (\\ref{secondproductdefinition}) means the inner product is \\emph{linear in first component}.\n\tPlease be noted that the result of inner product could be a complex value, but the result of $\\innerproduct{x}{x}$ is a non-negative real number.\n\t\\qed\n\\end{definition}\n\n\n\\begin{theorem}\n\tproperties of inner product:\n\t\\begin{enumerate}\n\t\t\\item $\\innerproduct{x}{y+z} = \\innerproduct{x}{y} + \\innerproduct{x}{z}$ \\label{firstproductproperty}\n\t\t\\item $\\innerproduct{x}{cy} = \\overline{c} \\innerproduct{x}{y} $ \\label{secondproductproperty}\n\t\t\\item $\\innerproduct{x}{x} = 0$ if and only if $x = 0$.\n\t\t\\item If $\\innerproduct{x}{y} = \\innerproduct{x}{z}$ for all $x \\in V$, then $y=z$.\n\t\\end{enumerate}\n\tItem (\\ref{firstproductproperty}) and (\\ref{secondproductproperty}) means the inner product is \\cindex{conjugate linear} in second component.\n\\end{theorem}\n\n\n\\begin{definition}\n\tthe \\cindex{standard inner product} on $F^n$ for $x=\\rowvector{a_1,a_2,\\dots,a_n}$ and $y=\\rowvector{b_1,b_2,\\dots,b_n}$ is:\n\t\\begin{equation}\n\t\t\\innerproduct{x}{y} = \\sum_{i=1}^n a_i \\overline{b_i}\t\t\n\t\\end{equation}\n\twhen $F=R$, it is usually called \\cindex{dot product} and denoted as $x \\cdot y$.\n\\end{definition}\n\n\\begin{definition}\n\tFor $A \\in M_{m \\times n}(F)$, the \\cindex{conjugate transpose} or \\cindex{adjoint} of $A$ is $A^* \\in M_{n \\times m}(F)$ that $(A^*)_{ij} = \\overline{A_{ji}}$. If $A$ is complex, $A^* = \\overline{A^\\top}$ . If $A$ is real, $A^*$ is $A^\\top$.\n\\end{definition}\n\n\\begin{definition}[Forbenius Inner Product]\n    Let $V=M_{n \\times n} (F)$, the \\cindex{Forbenius Inner Product} is defined as:\n    \\begin{equation}\n        \\innerproduct{A}{B} = \\trace{B^* A}\n    \\end{equation}\n\\end{definition}\n\n\\begin{theorem}\n    For square matrix $A_{n \\times n}$, we have \n    \\begin{equation}\n        \\innerproduct{A}{A} = \\sum_{i=1}^n \\sum_{j=1}^n \\absolutevalue{A_{ij}}^2 \\geq 0\n    \\end{equation}\n\\end{theorem}\n\n\n\\begin{definition}\\label{hinnerproductspace}\n\tThe continuous complex-valued function on interval $[0, 2\\pi]$ is a inner product space $H$:\n\t\\begin{equation}\n\t\t\\innerproduct{f}{g} = \\frac{1}{2\\pi} \\int_{0}^{2\\pi} f(t) \\overline{g(t)} dt\n\t\\end{equation}\n\\end{definition}\n\n\n\\begin{definition}\n\tthe \\cindex{norm} or \\cindex{length} of $x$ is:\n\t\\begin{equation}\n\t    \\norm{x} = \\sqrt{\\innerproduct{x}{x}}\n\t\\end{equation}\n\\end{definition}\n\n\\begin{theorem}\n\tthe property of norm:\n\t\\begin{itemize}\n\t\t\\item $\\norm{cx} = \\absolutevalue{c} \\cdot \\norm{x}$\n\t\t\\item $\\norm{x} = 0 \\iff x = 0$\n\t\t\\item \\cindex{Cauchy-Schwarz Inequality} $\\absolutevalue{\\innerproduct{x}{y}} \\leq \\norm{x} \\cdot \\norm{y}$\n\t\t\\item \\cindex{Triangle Inequality} $\\norm{x+y} \\leq \\norm{x} + \\norm{y}$\n\t\\end{itemize}\n\\end{theorem}\n\n\\begin{theorem}\\label{zerotforalltx}\n    If $\\forall x \\in C$,$\\innerproduct{T(x)}{x} = 0$. Then $T = 0$.\\footnote{For it to work in all $V$, $T$ needs to be self-adjoint. See \\thmref{zerotforalltxforselfadjoint} on page \\pageref{zerotforalltxforselfadjoint}.}\n\\end{theorem}\n\\begin{proof}\n    \\begin{equation*}\n        \\begin{aligned}\n            \\innerproduct{T(x+y)}{x+y} &= \\innerproduct{T(x)}{y} + \\innerproduct{T(y)}{x}  &= 0 \\\\\n            \\innerproduct{T(x+iy)}{x+iy} &= \\innerproduct{T(x)}{y} -\\innerproduct{T(y)}{x} &= 0            \n        \\end{aligned}\n    \\end{equation*}\n    So $\\forall y \\in V$, $T(x) = 0$. So $\\forall x \\in V$,$T(x) = 0$ and $T = 0$.\n\\end{proof}\n\n\\begin{theorem}\n    \\begin{equation}\n        \\norm{u+v}^2 + \\norm{u-v}^2 = 2 \\left(\\norm{u}^2 + \\norm{v}^2 \\right)\n    \\end{equation}    \n\\end{theorem}\n\n\n\n\n% orthogonal\n\n\\subsection{Orthogonal and Gram-Schmidt Process}\n\n\\begin{definition}\n\t$x$ and $y$ are \\cindex{orthogonal} if $\\innerproduct{x}{y} = 0$. A subset $S$ of $V$ is orthogonal if any two vectors in $S$ are orthogonal. A subset $S$ of $V$ is \\cindex{orthonormal} if $S$ is orthogonal and consists entirely of unit vectors.\n\\end{definition}\n\n\\begin{definition}\n    \\begin{equation}\n        \\innerproduct{x}{y} = \\norm{x} \\cdot \\norm{y} \\text{cos}(\\theta)\n    \\end{equation}    \n\\end{definition}\n\n\n\\begin{definition}\n\tA vector is \\cindex{unit vector} if $\\norm{x} = 1$. A \\cindex{normalizing} to non-zero $x$ is $\\dfrac{1}{\\norm{x}} x$.\n\\end{definition}\n\n\n\\begin{theorem}\n    Let $f_n (t) = e^{i nt}$ where $0 \\leq t \\leq 2 \\pi$. All $f_i$ are orthogonal.\n\\end{theorem}\n\\begin{proof}\n    \\begin{equation}\n        \\begin{aligned}\n            \\innerproduct{f_m}{f_n} &= \\frac{1}{2 \\pi} \\int_0^{2 \\pi} e^{imt} \\overline{e^{int}} \\dif{t} \\\\\n            &= \\frac{1}{2\\pi} \\int_0^{2\\pi} e^{i (m-n) t} \\dif{t} \\\\\n            &= \\eval{\\frac{1}{2\\pi (m-n)} e^{i(m-n)t}}_0^{2\\pi} \\\\\n            &= 0\n        \\end{aligned}\n    \\end{equation}\n\\end{proof}\n\n\\begin{theorem}[\\cindex{Pythagorean Theorem}]\n    Suppose $u$ and $v$ are orthogonal in $V$, then\n    \\begin{equation}\n        \\norm{u + v}^2 = \\norm{u}^2 + \\norm{v}^2\n    \\end{equation}    \n\\end{theorem}\n\n\\begin{theorem}\n    For a finite dimensional subspace $U$ of $V$, we have\n    \\begin{equation}\n        V = U \\oplus U^\\bot\n    \\end{equation}        \n\\end{theorem}\n\n\n\n\\begin{definition}\n\tA \\cindex{orthonormal basis} for $V$ is an ordered basis that is orthonormal.\n\\end{definition}\n\n\\begin{theorem}\n\tLet $S=\\set{ v_1, v_2, \\dots, v_k }$ be an orthogonal subset of $V$ consisting of non-zero vectors. If $y \\in \\vectorspan{S}$, then\n\t\\begin{equation}\n\t\ty = \\sum_{i=1}^k \\frac{\\innerproduct{y}{v_i}}{\\norm{v_i}^2} v_i\n\t\\end{equation}\n\tDefine the projection of vector $a$ onto vector $u$ as $\\projection{a}{u} = \\dfrac{\\innerproduct{a}{u}}{\\norm{u}^2}$. So \n\t\\begin{equation}\n\t    y = \\sum_{i=1}^k \\left(\\projection{y}{v_i}\\right) v_i\n\t\\end{equation}\n\tIf $S$ is orthonormal, then\n\t\\begin{equation}\n\t\ty = \\sum_{i=1}^k \\innerproduct{y}{v_i} v_i\n\t\\end{equation}\n\\end{theorem}\n\\begin{proof}\n\tlet $\\displaystyle y = \\sum_{i=1}^k a_i v_i$. we have\n\t\\begin{equation*}\n\t\t\\innerproduct{y}{v_i} = \\innerproduct{\\sum_{i=1}^k a_i v_i}{v_j} = \\sum_{i=1}^k a_i \\innerproduct{v_i}{v_j} = a_j \\norm{v_j}^2\n\t\\end{equation*}\n\tSo $a_j = \\dfrac{\\innerproduct{y}{v_j}}{\\norm{v_j}^2}$.\n\t\n\t\n\\end{proof}\n\n\\begin{theorem}\n\tAn orthogonal subset of $V$ is linearly independent.\n\\end{theorem}\n\n\\begin{definition}[\\cindex{Gram-Schmidt process}]\n\tLet $S=\\set{w_1, w_2, \\dots, w_n }$ be linearly independent subset of $V$. Define $S^\\prime=\\{v_1,v_2,\\dots,v_n  \\}$, where $v_1=w_1$ and \n\t\\begin{equation}\n\t\tv_k = w_k - \\sum_{j=1}^{k-1} \\frac{\\innerproduct{w_k}{v_j}}{\\norm{v_j}^2} v_j\n\t\\end{equation}\n\tthen $S^\\prime$ is an orthogonal set of non-zero vectors that $\\vectorspan{S^\\prime} = \\vectorspan{S}$. The process is that for the $k$-th basis $w_k$, first project it on top of the $k-1$ orthogonal vectors $\\displaystyle \\sum_{j=1}^{k-1} \\dfrac{\\innerproduct{w_k}{v_j}}{\\norm{v_j}^2} v_j$, and calculate the reciprocal vector $\\displaystyle w_k - \\sum_{j=1}^{k-1} \\dfrac{\\innerproduct{w_k}{v_j}}{\\norm{v_j}^2} v_j$.\n\t\\qed\n\\end{definition}\n\n\\begin{theorem}[\\cindex{QR Decomposition}]\n    Let $A_{m \\times n} = \\rowvector{a_1, a_2, \\dots, a_n}$ with $\\rank{A} = n$, so $\\set{a_i}$ is linearly independent. Use Gram-Schmidt process to form $n$ orthonomal basis:\n    \\begin{equation*}\n        \\begin{aligned}\n            u_1 &= a_1 & \\text{ , } e_1 = \\frac{u_1}{\\norm{u_1}} \\\\\n            u_2 &= a_2 - \\projection{a_2}{u_1} & \\text{ , } e_2 = \\frac{u_2}{\\norm{u_2}} \\\\\n            \\dots \\\\\n            u_n &= a_n - \\sum_{j=1}^{n-1} \\projection{a_n}{u_j} & \\text{ , } e_n = \\frac{u_n}{\\norm{u_n}} \n        \\end{aligned}\n    \\end{equation*}\n    Then $\\forall k$, $\\displaystyle a_k = \\sum_{j=1}^k \\innerproduct{a_k}{e_k} e_k$. So\n    \\begin{equation}\n        A = QR = [e_1, e_2, \\dots, e_n] \\times \\begin{bmatrix}\n            \\innerproduct{a_1}{e_1} & \\innerproduct{a_2}{e_1} & \\innerproduct{a_3}{e_1} & \\cdots & \\innerproduct{a_n}{e_1}\\\\\n            0 & \\innerproduct{a_2}{e_2} & \\innerproduct{a_3}{e_2} & \\cdots & \\innerproduct{a_n}{e_2}\\\\\n            0 & 0 & \\innerproduct{a_3}{e_3} & \\cdots & \\innerproduct{a_n}{e_3} \\\\            \n            \\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n            0 & 0 & 0 & 0 & \\innerproduct{a_n}{e_n}\n        \\end{bmatrix}\n    \\end{equation}\n    \n    The $Q$ is an orthonormal matrix. $R$ could be calculated by:\n    \\begin{equation}\n        R = Q^\\top Q R = Q^\\top A\n    \\end{equation}\n\\end{theorem}\n\n\n\\begin{theorem}\\label{vectorinorthonormalbasis}\n\tIf $V$ has an orthonormal basis $\\beta=\\set{v_1,v_2,\\dots,v_n}$, then $\\forall x\\in V$, \n\t\\begin{equation}\n\t\tx = \\sum_{i=1}^n \\innerproduct{x}{v_j} v_i\n\t\\end{equation}\n\\end{theorem}\n\n\\begin{definition}\n    Let $\\beta$ be an orthonormal subset (not basis) of $V$. For $x \\in V$, the \\cindex{Fourier coefficients} of $x$ relative to $\\beta$ are $\\innerproduct{x}{y_i}$ for all $y_i \\in \\beta$.\n\\end{definition}\n\n\n\\begin{theorem}\\label{matrixelementasinnerproductresult}\n\tLet $V$ with an orthonormal basis $\\beta=\\set{v_1,v_2,\\dots,v_n}$. $T$ is a linear operator on $V$ and let $A= \\coordinate{T}_\\beta$. then $A_{ij}=\\innerproduct{T(v_j)}{v_i}$.\n\\end{theorem}\n\\begin{proof}\n\tFrom \\thmref{vectorinorthonormalbasis} we have\n\t\\begin{equation*}\n\t\tT(v_j) = \\sum_{i=1}^n \\innerproduct{T(v_j)}{v_i} v_i\n\t\\end{equation*}\n\\end{proof}\n\n\\begin{definition}\n    Let $S$ be nonempty subset of $V$. The \\cindex{orthogonal complement} of $S$ is $S^\\bot$ that $\\forall x \\in S, \\forall y \\in S^\\bot, \\innerproduct{x}{y} = 0$.\n\\end{definition}\n\n\\begin{theorem}\\label{orthogonalprojection}\n    Let $W$ be a subspace of $V$. For $y \\in V$, there is \\emph{unique} $u \\in W$ and $z \\in W^\\bot$ that $y = u + z$. $u$ is the \\cindex{orthogonal projection} of $y$ on $W$. If $\\set{v_1, v_2, \\dots, v_k}$ is an orthonormal basis of $W$, then \n    \\begin{equation}\n        \\begin{aligned}\n            u &= \\sum_{i=1}^k \\innerproduct{y}{v_i} v_i \\\\\n            z &= y -   \\sum_{i=1}^k \\innerproduct{y}{v_i} v_i          \n        \\end{aligned}\n    \\end{equation}\n\\end{theorem}\n\n\n\\begin{theorem}\n    For $S=\\set{v_1, v_2, \\dots, v_k}$ be an orthogonal subset of $V$. For $\\forall y \\in V$, the orthogonal projection of $y$ on $S$ is $\\displaystyle u = \\sum_{i=1}^k \\dfrac{\\innerproduct{y}{v_i}}{\\norm{v_i}^2} v_i$. If $S$ are orthonormal, $\\displaystyle u = \\sum_{i=1}^k \\innerproduct{y}{v_i} v_i$. If $y$ is in span of $S$, then $y = u$.\n\\end{theorem}\n\n\n\n\\begin{theorem}\n    Let $y$,$u$,$z$ as defined in \\thmref{orthogonalprojection}. $u$ is the closest vector in $W$ to $y$ that is $\\forall x \\in W \\left(\\norm{y-x} \\geq \\norm{y - u} \\right)$.\n\\end{theorem}\n\\begin{proof}\n    \\begin{equation*}\n        \\norm{y - x}^2 = \\norm{u + z - x}^2 = \\norm{(u - x) + z}^2 = \\norm{u - x}^2 + \\norm{z}^2 \\geq \\norm{z}^2 = \\norm{y - u}^2\n    \\end{equation*}\n\\end{proof}\n\n\n\n\n\n\n\n% Adjoint of Linear Operator\n\\subsection{Adjoint of Linear Operator}\n\n\\begin{theorem}[\\cindex{Riesz Representation Theorem}]\\label{uniquelinearoperatortof}\n    Let $g: V \\rightarrow F$ be a linear transformation. Then there exist a unique $y \\in V$ that $\\forall x \\in V$, $g(x) = \\innerproduct{x}{y}$. The $y$ is \n    \\begin{equation}\n        y = \\sum_{i=1}^n \\overline{g(v_i)} v_i\n    \\end{equation}\n    \n    So every vector in the dual space\\footnote{Defined in \\thmref{dualspacedefinition} on page \\pageref{dualspacedefinition}.} can be represented by an inner product.\n\\end{theorem}\n\\begin{proof}\n    Define $h(x) = \\innerproduct{x}{y}$ with $y$ defined above. So\n    \\begin{equation*}\n        h(v_j) = \\innerproduct{v_j}{y} = \\innerproduct{v_j}{\\sum_{i=1}^n \\overline{g(v_i)} v_i} = \\sum_{i=1}^n \\innerproduct{v_j}{\\overline{g(v_i)} v_i} = \\sum_{i=1}^n g(v_i) \\innerproduct{v_j}{ v_i} = g(v_j)\n    \\end{equation*}\n\\end{proof}\n\n\n\n\\begin{theorem}\n    Let $T$ be a linear operator on $V$. Then there existing a unique linear operator $T^* : V \\rightarrow V$ that $\\innerproduct{T(x)}{y}=\\innerproduct{x}{T^*(y)}$ for all $x,y \\in V$. $T^*$ is called the \\cindex{adjoint} of $T$.\n\\end{theorem}\n\\begin{proof}\n    For each $y$, $\\innerproduct{T(x)}{y}$ is a linear operator from $V$ to $F$, so by \\thmref{uniquelinearoperatortof}, $\\exists y'$ that $\\innerproduct{T(x)}{y} = \\innerproduct{x}{y'}$. Define $T^*$ as $T^*(y) = y'$.\n\\end{proof}\n\n\\begin{theorem}\n    \\begin{equation}\n        \\begin{aligned}\n            \\innerproduct{T(x)}{y} &= \\innerproduct{x}{T^*(y)} \\\\\n            \\innerproduct{x}{T(y)} &= \\innerproduct{T^*(x)}{y}\n        \\end{aligned}        \n    \\end{equation}\n    So $^*$ is added to $T$ when change the location of $T$.\n\\end{theorem}\n\\begin{proof}\n    \\begin{equation*}\n        \\innerproduct{x}{T(y)} = \\overline{\\innerproduct{T(y)}{x}} = \\overline{\\innerproduct{y}{T^*(x)}} = \\innerproduct{T^*(x)}{y}\n    \\end{equation*}\n\\end{proof}\n\n\\begin{theorem}\n    Let $\\beta$ be a orthonormal basis for $V$. If $T$ is a linear operation on $V$ then\n    \\begin{equation}\n        [T^*]_\\beta = \\left([T]_\\beta \\right)^*\n    \\end{equation}\n    Let $A$ be an $n \\times n$ matrix. Then\n    \\begin{equation}\n        L_{A^*} = \\left(L_A \\right)^*\n    \\end{equation}\n\\end{theorem}\n\\begin{proof}\n    Let $A=[T]_\\beta$, $B=[T^*]_\\beta$, and $\\beta=\\{v_1, v_2, \\dots, v_n \\}$. Then according to \\thmref{matrixelementasinnerproductresult}:\n    \\begin{equation*}\n        B_{ij} = \\innerproduct{T^*(v_j)}{v_i} = \\overline{\\innerproduct{v_i}{T^*(v_j)}} = \\overline{\\innerproduct{T(v_i)}{v_j}} = \\overline{A_{ji}} = (A^*)_{ij}\n    \\end{equation*}\n\\end{proof}\n\n\\begin{theorem}\n    Let $T$ and $U$ be linear operator on $V$, then\n    \\begin{enumerate}\n        \\item $(aT+bU)^* = \\overline{a} T^* + \\overline{b} U^*$\n        \\item $(UT)^* = T^* U^*$\n        \\item $T^{**} = T$\n    \\end{enumerate}    \n\\end{theorem}\n\n\n\\begin{definition}\n    Let $T : V \\rightarrow W$ be a linear transformation where $V$ and $W$ are finite dimensional inner product space with inner product $\\innerproduct{\\cdot{}}{\\cdot{}}_V$ and $\\innerproduct{\\cdot{}}{\\cdot{}}_W$. A function $T^* : W \\rightarrow V$ is called \\cindex{adjoint} of $T$ if $\\innerproduct{T(x)}{y}_W = \\innerproduct{x}{T^*(y)}_V$.\n\\end{definition}\n\n\\begin{theorem}\n    Let $T^*$ be an adjoint of $T: V \\rightarrow W$. If $\\beta$ and $\\gamma$ are orthonormal basis for $V$ and $W$, then\n    \\begin{equation}\n        [T^*]_\\beta^\\alpha = \\left([T]_\\beta^\\alpha\\right)^*\n    \\end{equation}\n\\end{theorem}\n\n\\begin{theorem}\n    Let $T^*$ be an adjoint of $T: V \\rightarrow W$, we have:\n    \\begin{equation}\n        \\innerproduct{T^*(x)}{y}_V = \\innerproduct{x}{T(y)}_W\n    \\end{equation}\n\\end{theorem}\n\n\n\n\\begin{theorem}\\label{nullandreciprocaladjoint}\n    If $V$ is finite dimentional, let $T$ be a linear operator on $V$, then\n    \\begin{equation*}\n        \\begin{aligned}\n            \\rangespace{T^*}^\\bot &= \\nullspace{T}\\\\\n            \\rangespace{T^*} &= \\nullspace{T}^\\bot \\\\\n            \\rangespace{T}^\\bot &= \\nullspace{T^*}\\\\\n            \\rangespace{T} &= \\nullspace{T^*}^\\bot\n        \\end{aligned}\n    \\end{equation*}\n    So $\\rangespace{T^*} \\bot \\nullspace{T}$.\n\\end{theorem}\n\\begin{proof}\n    If $m \\in R(T^*)^\\bot$, $\\forall x \\in V$, $0 = \\innerproduct{m}{T^*x} = \\innerproduct{T(m)}{x}$, so $m \\in N(T)$.\n\\end{proof}\n\n\n\n% Example in statistics\n\\subsection{Examples in Statistics}\\label{consistentandinconsistentequation}\n\nThe following two examples show that for linear equation $Ax - y = 0$, \n\\begin{enumerate}\n    \\item if it is consistent, that is there is solution, we want to find the solution with minimal norm.\n    \\item If it is inconsistent, that is no solution, we want a result that has the least norm.\n\\end{enumerate}\n\nThe same topic is discussed in pseudo inverse.\n\n\n% Least Square Approximation\n\\subsubsection{Least Square Approximation}\n\n\\begin{definition}\n    The \\cindex{Least Square Approximation} is a problem that for $A = \\begin{bmatrix}\n        t_1 & 1 \\\\\n        t_2 & 1 \\\\\n        \\vdots & \\vdots \\\\\n        t_m & 1\n    \\end{bmatrix}$,  $y = \\begin{bmatrix}\n        y_1\\\\\n        y_2\\\\\n        \\vdots\\\\\n        y_m\n    \\end{bmatrix}$, find $x_0 = \\begin{bmatrix}\n        c \\\\\n        d\n    \\end{bmatrix}$ that minimize $\\norm{Ax-y}$.\n\\end{definition}\n\n\\begin{definition}\n    For $x,y \\in F^n$, define $\\innerproduct{x}{y}_n = y^* \\times x$.\n\\end{definition}\n\n\n\\begin{theorem}\n    Let $A \\in M_{m \\times n} (F)$, $x \\in F^n$, $y\\in F^m$, then\n    \\begin{equation}\n        \\innerproduct{Ax}{y}_m = \\innerproduct{x}{A^* y}_n\n    \\end{equation}\n\\end{theorem}\n\\begin{proof}\n    $\\innerproduct{Ax}{y}_m = y^* \\times (Ax) = (y^* \\times A) x = (A^* y)^* x = \\innerproduct{x}{A^* y}_n$\n\\end{proof}\n\n\\begin{theorem}\n    Let $A \\in M_{m\\times n} (F)$. Then\\footnote{See \\thmref{rankofadjoint} for another proof.}\n    \\begin{equation}\n        \\rank{A^*A} = \\rank{A}\n    \\end{equation}\n    So if $\\rank{A} = n$, $A^*A$ is invertible.\n\\end{theorem}\n\\begin{proof}\n    For equation $A^*Ax = 0$ and $Ax = 0$. $Ax=0$ implies that $A^*Ax =0$. Then assume $A^*Ax = 0$, then\n    \\begin{equation*}\n        0 = \\innerproduct{0}{x}_n = \\innerproduct{A^*Ax}{x}_n = \\innerproduct{Ax}{A^{**}x}_m = \\innerproduct{Ax}{Ax}_m\n    \\end{equation*}\n\\end{proof}\n\n\n\\begin{theorem}\n    Let $A \\in M_{m\\times n} (F)$, $y \\in F^m$. Then there exists $x_0 \\in F^n$ that $(A^*A) x_0 = A^* y$ and $\\forall x \\in F^n$, $ \\norm{Ax_0 - y} \\leq \\norm{Ax-y}$. If $\\rank{A} = n$, then $x_0 = (A^*A)^{-1} A^* y$.\n\\end{theorem}\n\\begin{proof}\n    Define $W=\\rangespace{L_A}$. There exists a $x_0$ that is closest to $y$ that $Ax_0 - y \\in W^\\bot$, so $\\innerproduct{Ax}{Ax_0 - y}_m = 0$. So $\\innerproduct{x}{A^*(Ax_0 - y)}_n = 0$, so $A^*(Ax_0 - y) = 0$ and $(A^*A) x_0 = A^* y$. \n\\end{proof}\n\n\n\n\n% Minimal Solution to Linear Equations\n\\subsubsection{Minimal Solution to Linear Equations}\n\n\\begin{definition}\n    A solution $s$ is \\cindex{minimal solution} of $Ax=b$ if $\\norm{s} \\leq \\norm{u}$ for any solution $u$.\n\\end{definition}\n\n\n\n\\begin{theorem}\n    Let $A \\in M_{m\\times n} (F)$, $y \\in F^m$. Suppose $Ax=y$ is consistent. Then there exists unique minimal solution $s \\in R(L_{A^*})$ of $Ax=y$. And $s$ is the only solution in $R(L_{A^*})$. If $u$ is a solution to $(AA^*) u = y$, then $s = A^* u$.\n\\end{theorem}\n\\begin{proof}\n    By \\thmref{nullandreciprocaladjoint} define $W = R(L_{A^*})$ and $W^\\bot = N(L_A)$. $\\forall x$ that $Ax = y$, we have $s \\in W$ and $t \\in W^\\bot$ that $x=s+t$. So $y = Ax = A(s + t) = As + At = As$. So $s$ is a solution to $Ax=y$. From \\thmref{equationfromoneandnullspace}, all solution to $Ax=y$ has the form $x' = s + t'$ where $t' \\in W^\\bot$. And $\\norm{x'}^2 = \\norm{s + t'}^2 = \\norm{s}^2 + \\norm{t'}^2 \\geq \\norm{s}^2$.\n\\end{proof}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "e08de6e7f6ea4d6c408ec2c3ec2a317c8b0908ef", "size": 19286, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/linear_algebra/la.6.inner_product_space.tex", "max_stars_repo_name": "elvisren/machine-learning-notes", "max_stars_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-07T03:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-04T17:28:22.000Z", "max_issues_repo_path": "src/linear_algebra/la.6.inner_product_space.tex", "max_issues_repo_name": "elvisren/machine-learning-notes", "max_issues_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/linear_algebra/la.6.inner_product_space.tex", "max_forks_repo_name": "elvisren/machine-learning-notes", "max_forks_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-01T23:34:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-01T23:34:47.000Z", "avg_line_length": 30.4195583596, "max_line_length": 432, "alphanum_fraction": 0.6122575962, "num_tokens": 7134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.7447316675127559}}
{"text": "\\documentclass{article}\r\n\\title{ALO for Elastic Net with Intercept through Generalized LASSO}\r\n\\author{Yuze Zhou}\r\n\\usepackage{amsmath}\r\n\\usepackage{amsfonts}\r\n\\usepackage{graphicx}\r\n\\begin{document}\r\n\\section{Dual Formulation of Elastic Net with Intercept}\r\n\\paragraph{}First, to write the optimization problem of elastic net in a matrix form, and denote $D =[0, I]$, the optimization problem becomes:\r\n\\begin{center}\r\n$\\hat{\\beta} = \\arg \\min\\limits_{\\beta} \\frac{1}{2}||y-X\\beta||_{2}^{2} + \\lambda_{1}||D\\beta||_{1}+\\lambda_{2}||D\\beta||_{2}^{2}$\r\n\\end{center}\r\n\\paragraph{}The augmented Lagrangian for the problem is:\r\n\\begin{center}\r\n$L = \\frac{1}{2}||y-z||_{2}^{2} + \\lambda_{1}||\\omega||_{1}+\\lambda_{2}||\\omega||_{2}^{2} + u^{\\tau}(z-X\\beta) + v^{\\tau}(\\omega-D\\beta)$\r\n\\end{center}\r\n\\paragraph{}By taking the derivatives with respect to $z$ and $\\beta$, we could obtain:\r\n\\begin{center}\r\n$0 = \\frac{\\partial L}{\\partial z} = z-y+u$\\\\\r\n$0 = \\frac{\\partial L}{\\partial \\beta} = -X^{\\tau}u-D^{\\tau}v$\r\n\\end{center}\r\n\\paragraph{}Since the first column of $X$ is filled with ones and the first column of $D$ is filled with zeros, the first row of $-X^{\\tau}u-D^{\\tau}v = 0$ gives $\\textbf{1}^{\\tau} u = 0$ and due to $D = [0,I]$, the rest rows give that $-X_{j}^{\\tau}u = v_{j}$. Moreover, since the rest dimensions of $\\omega$ is penalized element-wisely in the augmented Lagrangian, we can minimize over $\\omega$ by minimizing over each $\\omega_{i}, \\quad i \\geq 2$, that is, we have to minimize $\\lambda_{1}|\\omega_{i}| + \\lambda_{2}\\omega_{i}^{2} - u^{\\tau}X_{i}\\omega_{i}$ for each dimension of $\\omega$, where $X_{i}$ denotes the $i$th column of $X$, therefore:\r\n\\begin{center}\r\n$\\min\\limits_{\\omega_{i}} \\lambda_{1}|\\omega_{i}| + \\lambda_{2}\\omega_{i}^{2} - u^{\\tau}X_{i}\\omega_{i} $\\\\\r\n$ $\\\\\r\n$= \\left\\{\r\n\\begin{aligned}\r\n0 \\quad if \\quad |u^{\\tau}X_{i}| \\leq \\lambda_{1}\\\\\r\n-\\frac{(\\lambda_{1}-|u^{\\tau}X_{i}|)^{2}}{4\\lambda_{2}} \\quad if \\quad |u^{\\tau}X_{i}| > \\lambda_{1}\\\\\r\n\\end{aligned}\r\n\\right.\r\n$\r\n\\end{center}\r\n\\paragraph{}By taking all the above back to the Lagrangian, we obtain the dual problem as:\r\n\\begin{center}\r\n$d^{*} = \\min\\limits_{u} \\frac{1}{2}||y-u||_{2}^{2} + \\sum\\limits_{j: |X_{j}^{\\tau}u| > \\lambda_{1}}\\frac{(\\lambda_{1}-|u^{\\tau}X_{i}|)^{2}}{4\\lambda_{2}}$\\\\\r\n$subject \\quad to \\quad \\textbf{1}^{\\tau}u = 0$\r\n\\end{center}\r\n\\paragraph{}First denote $f(u) = \\sum\\limits_{j: |X_{j}^{\\tau}u| > \\lambda_{1}}\\frac{(\\lambda_{1}-|u^{\\tau}X_{i}|)^{2}}{4\\lambda_{2}}$, clearly $f(u)$ is of quadratic form, $f(u) = \\frac{1}{2}u^{\\tau}Au+a^{\\tau}u+b$, where $b$ is a constant and does not matter in the optimization of the dual problem, $A$ and $a$ are:\r\n\\begin{center}\r\n$A = \\frac{1}{2\\lambda_{2}}X_{E}X_{E}^{\\tau}$\\\\\r\n$E := \\{i: |X_{i}^{\\tau}u| > \\lambda \\}$\r\n\\end{center}\r\n\\begin{center}\r\n$a = \\frac{\\lambda_{1}}{2\\lambda_{2}}(\\sum\\limits_{i:X_{i}^{\\tau}<-\\lambda_{1}}X_{i}-\\sum\\limits_{i:X_{i}^{\\tau}>\\lambda_{1}}X_{i})$\r\n\\end{center}\r\n\\paragraph{}The dual problem could also be written in a proximal form:\r\n\\begin{center}\r\n$\\hat{u} = \\textbf{prox}_{\\tilde{f}}(y)$\\\\\r\n$\\tilde{f} = \\textbf{I}(\\textbf{1}^{\\tau}u=0)f(u) + \\textbf{I}(\\textbf{1}^{\\tau}u \\neq 0)\\infty$\r\n\\end{center}\r\n\\paragraph{}After transforming $f(u)$ into a quadratic form, we could write the Lagrangian for the dual problem back again:\r\n\\begin{center}\r\n$L = \\frac{1}{2}||y-u||_{2}^{2} + \\frac{1}{2}u^{\\tau}Au+a^{\\tau}u+b + \\lambda\\textbf{1}^{\\tau}u$\r\n\\end{center}\r\n\\paragraph{}By taking the derivative with respect to $u$, we could obtain:\r\n\\begin{center}\r\n$\\frac{\\partial L}{ \\partial u} = u - y +Au+a+\\lambda\\textbf{1} = 0$\r\n\\end{center}\r\n\\paragraph{}By shifting the terms, $u$ could be written as a formula of $y$ and $\\lambda$: $u = (I+A)^{-1}(y-a-\\lambda\\textbf{1})$, by taking the derivative with respect to $y$ at both sides, we could obtain the Jacobian matrix $J$ of the proximal operator $\\textbf{prox}(\\tilde{f})$ at $y$ as:\r\n\\begin{center}\r\n$J = (I+A)^{-1} -(I+A)^{-1}\\textbf{1}\\nabla(\\hat{\\lambda})^{\\tau}$\r\n\\end{center}\r\nwhere $\\nabla(\\hat{\\lambda})^{\\tau}$ denotes the gradient of $\\lambda$ as a function of $y$.\r\n\\paragraph{}By taking $u = (I+A)^{-1}(y-a-\\lambda\\textbf{1})$ back to the Lagrangian, the dual problem will become a second-order equation of $\\lambda$:\r\n\\begin{center}\r\n$d^{*} = \\max\\limits_{\\lambda} \\frac{1}{2}||y-(I+A)^{-1}(y-a-\\lambda\\textbf{1})||_{2}^{2}+\\frac{1}{2}(y-a-\\lambda\\textbf{1})^{\\tau}(I+A)^{-1}A(I+A)^{-1}(y-a-\\lambda\\textbf{1})+a^{\\tau}(I+A)^{-1}(y-a-\\lambda\\textbf{1})+\\lambda\\textbf{1}^{\\tau}(I+A)^{-1}(y-a-\\lambda\\textbf{1})$\r\n\\end{center}\r\n\\paragraph{}More specifically, the second-order term is:\r\n\\begin{center}\r\n$\\frac{1}{2}\\textbf{1}^{\\tau}(I+A)^{-2}\\textbf{1}+\\frac{1}{2}\\textbf{1}^{\\tau}(I+A)^{-1}A(I+A)^{-1}\\textbf{1}-\\textbf{1}^{\\tau}(I+A)^{-1}\\textbf{1}$\r\n\\end{center}\r\nand the first-order term is:\r\n\\begin{center}\r\n$2\\textbf{1}^{\\tau}(I+A)^{-1}(y-a)-\\textbf{1}^{\\tau}(I+A)^{-2}(y-a)-\\textbf{1}^{\\tau}(I+A)^{-1}A(I+A)^{-1}(y-a)$\r\n\\end{center}\r\n\\paragraph{}Thus by solving the second-order equation, we could obtain\r\n\\begin{center}\r\n$\\hat{\\lambda} = \\frac{2\\textbf{1}^{\\tau}(I+A)^{-1}(y-a)-\\textbf{1}^{\\tau}(I+A)^{-2}(y-a)-\\textbf{1}^{\\tau}(I+A)^{-1}A(I+A)^{-1}(y-a)}{\\textbf{1}^{\\tau}(I+A)^{-2}\\textbf{1}+\\textbf{1}^{\\tau}(I+A)^{-1}A(I+A)^{-1}\\textbf{1}-2\\textbf{1}^{\\tau}(I+A)^{-1}\\textbf{1}}$\r\n\\end{center}\r\nand the gradient\r\n\\begin{center}\r\n$\\nabla(\\hat{\\lambda}) = \\frac{2(I+A)^{-1}\\textbf{1}-(I+A)^{-2}\\textbf{1}-(I+A)^{-1}A(I+A)^{-1}\\textbf{1}}{\\textbf{1}^{\\tau}(I+A)^{-2}\\textbf{1}+\\textbf{1}^{\\tau}(I+A)^{-1}A(I+A)^{-1}\\textbf{1}-2\\textbf{1}^{\\tau}(I+A)^{-1}\\textbf{1}}$\\\\\r\n\\end{center}\r\n\\paragraph{}By taking the gradient back to $J = (I+A)^{-1} -(I+A)^{-1}\\textbf{1}\\nabla(\\hat{\\lambda})^{\\tau} = (I+A)^{-1} -\\frac{(I+A)^{-1}\\textbf{1}\\textbf{1}^{\\tau}(I+A)^{-1}}{\\textbf{1}^{\\tau}(I+A)^{-1}\\textbf{1}}$, we could obtain the Jacobian.\r\n\\section{Proof of the Equivalence between the primal and the dual solutions}\r\n\\paragraph{}First recall the alo formula from the dual approach $y^{/i} = y_{i}-\\frac{u_{i}}{J_{ii}} = \\frac{J_{ii}-1}{J_{ii}}y_{i}+\\frac{1}{J_{ii}}x_{i}\\hat{\\beta}$ and the primal formula from the primal approach $y^{/i} = x_{i}\\hat{\\beta} + \\frac{H_{ii}}{1-H_{ii}}(x_{i}\\hat{\\beta}-y_{i}) = -\\frac{H_{ii}}{1-H_{ii}}y_{i}+\\frac{1}{1-H_{ii}}x_{i}\\hat{\\beta}$. In the following section, we're going to show that $H+J =I$, thus giving $H_{ii}+J_{ii} = 1$, and that the solutions given by both the primal and the dual approach are equivalent.\r\n\\paragraph{}First, using matrix inverse lemma, we could calculate the inverse of $(I+A) = (I+\\frac{1}{2\\lambda_{2}}X_{E}X_{E}^{\\tau})$ as:\r\n\\begin{center}\r\n$\\begin{aligned}\r\n(I+A)^{-1} &= (I+\\frac{1}{2\\lambda_{2}}X_{E}X_{E}^{\\tau})^{-1}\\\\\r\n&= I - X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau}\r\n\\end{aligned}\r\n$\r\n\\end{center}\r\ntherefore the matrix $J$ is:\r\n\\begin{center}\r\n$\r\n\\begin{aligned}\r\nJ &= (I+A)^{-1} -\\frac{(I+A)^{-1}\\textbf{1}\\textbf{1}^{\\tau}(I+A)^{-1}}{\\textbf{1}^{\\tau}(I+A)^{-1}\\textbf{1}}\\\\\r\n&= I - X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau} - \\frac{(\\textbf{1}-X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau}\\textbf{1})(\\textbf{1}^{\\tau}-\\textbf{1}^{\\tau}X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau})}{\\textbf{1}^{\\tau}(I-X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau})\\textbf{1}}\r\n\\end{aligned}\r\n$\r\n\\end{center}\r\n\\paragraph{}Now recall that $H = [1,X_{E}]([1,X_{E}]^{\\tau}[1,X_{E}]+diag(0,2\\lambda_{2},\\cdots, 2\\lambda_{2}))[1,X_{E}]^{\\tau}$, by adopting block inverse, we could derive $H$ as:\r\n\\begin{center}\r\n$\r\n\\begin{aligned}\r\nH &= [1,X_{E}]\r\n\\left(\r\n\\begin{array}{cc}\r\nn & \\textbf{1}^{\\tau}X_{E}\\\\\r\nX_{E}^{\\tau}\\textbf{1} & X_{E}^{\\tau}X_{E} + 2\\lambda_{2}I\\\\\r\n\\end{array}\r\n\\right)\r\n[1,X_{E}]^{\\tau}\\\\\r\n&= [1,X_{e}]\\\\\r\n&\\left(\r\n\\begin{array}{cc}\r\n\\frac{1}{\\textbf{1}^{\\tau}(I-X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau})\\textbf{1}} & \\frac{-\\textbf{1}^{\\tau}X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}}{\\textbf{1}^{\\tau}(I-X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau})\\textbf{1}}\\\\\r\n\\frac{-(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau}\\textbf{1}}{\\textbf{1}^{\\tau}(I-X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau})\\textbf{1}}&(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}+\\frac{(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau}\\textbf{1}\\textbf{1}^{\\tau}X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}}{\\textbf{1}^{\\tau}(I-X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau})\\textbf{1}}\\\\\r\n\\end{array}\r\n\\right)\\\\\r\n&[1,X_{E}]^{\\tau}\\\\\r\n& = X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau} + \\frac{(\\textbf{1}-X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau}\\textbf{1})(\\textbf{1}^{\\tau}-\\textbf{1}^{\\tau}X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau})}{\\textbf{1}^{\\tau}(I-X_{E}(2\\lambda_{2}I+X_{E}^{\\tau}X_{E})^{-1}X_{E}^{\\tau})\\textbf{1}}\\\\\r\n& = I-J\r\n\\end{aligned}\r\n$\r\n\\end{center}\r\n\\paragraph{}Now that we have showed that $H+J=I$, we could also conclude that $J_{ii}+H_{ii}=1$ and that the alo solutions given by both the primal and dual approaches are equivalent.\r\n\\end{document}\r\n", "meta": {"hexsha": "eba13d6d20599fcf56e05467454f7cd98d7c613f", "size": 9135, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "elintdual.tex", "max_stars_repo_name": "Geophagus96/Summer-ALO", "max_stars_repo_head_hexsha": "a290326a917461dc6b0e516dfc762ce04ed3679a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-07-25T20:32:11.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-25T20:32:11.000Z", "max_issues_repo_path": "elintdual.tex", "max_issues_repo_name": "Geophagus96/Summer-ALO", "max_issues_repo_head_hexsha": "a290326a917461dc6b0e516dfc762ce04ed3679a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "elintdual.tex", "max_forks_repo_name": "Geophagus96/Summer-ALO", "max_forks_repo_head_hexsha": "a290326a917461dc6b0e516dfc762ce04ed3679a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.2045454545, "max_line_length": 650, "alphanum_fraction": 0.598467433, "num_tokens": 3914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7446765548366959}}
{"text": "\\subsection{Divergence}\r\n\\noindent\r\nIn 2D we define the divergence of a vector field $\\vec{F}(x,y) = \\langle P(x,y), Q(x,y) \\rangle$ as $\\text{div}(\\vec{F}) = P_x+Q_y$. This tells how the separation between particles in the vector field change over time. Positive divergence at some point means that particles tend to move away from each other, and that point is acting like a “source.” Negative divergence at some point means that particles tend to move towards each other, and that point is acting like a “sink.”\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nThis operation extends into higher dimensions. We define the ``del operator'' as\r\n\\begin{equation*}\r\n\t\\nabla = \\left< \\frac{\\partial}{\\partial x}, \\frac{\\partial}{\\partial y},\\ldots\\right> \\text{ so that } \\text{div}(\\vec{F}) = \\nabla \\cdot \\vec{F}.\r\n\\end{equation*}\r\nThe del operator is not coordinate system independent. The above version only works for Cartesian coordinates. For spherical coordinates,\r\n\\begin{equation*}\r\n\t\\nabla \\cdot \\vec{F} = \\frac{1}{\\rho^2}\\frac{\\partial(\\rho^2 F_\\rho)}{\\partial\\rho} + \\frac{1}{\\rho\\sin{\\theta}}\\frac{\\partial}{\\partial\\theta}(F_\\theta \\sin{\\theta}) + \\frac{1}{\\rho\\sin{\\theta}}\\frac{\\partial}{\\partial\\phi}F_\\phi  \\text{ where } \\vec{F} = \\langle F_\\rho, F_\\theta, F_\\phi \\rangle.\r\n\\end{equation*}\r\nThankfully, vector fields in spherical coordinates are rare, and it's usually easier to convert to Cartesian coordinates before doing any calculations.\\\\\r\n\r\n\\begin{definition}\r\n\tIf $\\nabla \\cdot \\vec{F} = 0$, then $\\vec{F}$ is incompressible.\r\n\\end{definition}\r\n\\noindent\r\nThis aligns with the idea of incompressible fluids in physics and can simplify or remove the need for some calculations.\r\n\r\n\\input{./vectorAnalysis/laplacian}", "meta": {"hexsha": "c32b04dd2869173163166b54d955f9c2a24fc48f", "size": 1722, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorAnalysis/divergence.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorAnalysis/divergence.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorAnalysis/divergence.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 71.75, "max_line_length": 479, "alphanum_fraction": 0.7241579559, "num_tokens": 492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7446725456890257}}
{"text": "\\section{Differentiation}\n\nDifferentiation is a really important concept of calculus.\nWith this you can calculate the slope of a function in a specific point.\n\n\\subsection{The product rule}\nThe product rule is a simple rule to differentiate two functions which are in a product.\nThe rule is as following:\n\n\\[(f * g)'(x)=f'(x) * g(x) + f(x) * g'(x)\\]\n\n\\subsection{The quotient rule}\nThe quotient rule is a rule to differentiate a function which contains the quotient of two differentiable functions.\nIt works as following:\n\n\\[\n  (\\frac{f}{g})'(x) =\n  \\frac{g(x) * f'(x) - g'(x) * f(x)}{{g'(x)}^2}\n\\]\n\n\\subsection{The chain rule}\nSome functions cannot be differentiated that easily.\nYou will need the chain rule for that.\nTake the next function:\n\n\\[f(x) = \\sqrt{x^2+1}\\]\nTo apply the chain rule you need to substitute a part of the function with \\(u(x)\\).\nYou should choose a part which, when removed, makes the function way easier.\nThe previous function would look like this:\n\n\\[f(x) = \\sqrt{u(x)}\\]\n\\[u(x) = x^2+1\\]\nNow you can differentiate the functions separately.\nThis would look as following:\n\n\\[\n  f'(x) =\n  \\frac{1}{2\\sqrt{u(x)}} * u'(x) =\n  \\frac{1}{2\\sqrt{x^2+1}} * 2x\n\\]\nYou can apply this to more than the square root, like power functions.\nA more general rule for the chain rule is as following:\n\n\\[(f \\circ g)'(x)=f'(g(x)) * g'(x)\\]\n\n\\subsection{Implicit differentiation}\nTill now we have assumed that we differentiate over a {\\bf explicit function}.\nThis means it has the form of \\(f(x) = y\\).\nBut this is not always the case.\nTake the following example:\n\n\\[x^3 + y^3 = 6xy\\]\nThis is {\\it not\\/} an easy function to differentiate.\nWith implicit differentiation you differentiate both sides with respect to \\(x\\).\nWe can differentiate \\(y^3\\) with the chain rule.\nSo \\(y^3\\) will become \\(3y^2 * \\frac{dy}{dx}\\).\nTrying to do that with the example function gives you:\n\n\\[(x^3 + y^3)' = (6xy)'\\]\n\\[3x^2 + 3y^2 \\frac{dy}{dx} = 6y + 6x \\frac{dy}{dx}\\]\n\\[y^2 \\frac{dy}{dx} - 2x \\frac{dy}{dx} = 2y - x^2\\]\n\\[\\frac{dy}{dx}(y^2 - 2x) = 2y - x^2\\]\n\\[\\frac{dy}{dx} = \\frac{2y - x^2}{y^2 - 2x}\\]\n\n\\subsection{Linear approximation}\nIf you zoom into a function with the respective tangent line it\\'ll start to look like that function.\nWith this you can approximate the value of a function with a tangent line close to that value.\nThe following is called the {\\bf linearization} of \\(f\\) in \\(a\\):\n\n\\[l(x) = f(a) + f'(a)(x-a)\\]\nFor example, if we want to calculate \\(f(x) = \\sqrt{x}\\) with \\(x = 4.36\\).\nWe take an \\(a\\) we know close to that point, \\(4\\) would make sense.\nThis gives the following function:\n\n\\[l(x) = 2 + \\frac{1}{4}(x - 4) = 1 + \\frac{x}{4}\\]\nNow we can fill in our \\(x\\) into \\(l(x)\\).\n\n\\[l(4.36) = 1 + \\frac{4.36}{4} = 1 + \\frac{109}{100} = 2.09 \\approx \\sqrt{4.36}\\]\n", "meta": {"hexsha": "c5312c4a47ffdcb80b0e9857bbdf607c46b3da7a", "size": 2789, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/chapters/differentiation.tex", "max_stars_repo_name": "dsluijk/TUD-CSE-summaries", "max_stars_repo_head_hexsha": "9157650c7a6af2e1c3072f6e66a6fd1e001460ce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Calculus/chapters/differentiation.tex", "max_issues_repo_name": "dsluijk/TUD-CSE-summaries", "max_issues_repo_head_hexsha": "9157650c7a6af2e1c3072f6e66a6fd1e001460ce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Calculus/chapters/differentiation.tex", "max_forks_repo_name": "dsluijk/TUD-CSE-summaries", "max_forks_repo_head_hexsha": "9157650c7a6af2e1c3072f6e66a6fd1e001460ce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.3037974684, "max_line_length": 116, "alphanum_fraction": 0.6622445321, "num_tokens": 890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474155747541, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.744618201511985}}
{"text": "%---------------------------Distortion-----------------------------\n\\section{Distortion}\n\nLet $A$ be the area as defined in \\S\\ref{s:quad-area}\nand $A_m = 4$ be the area of a ``master'' quadrilateral with vertices\n\\[\n\\begin{array}{lcrcrcrl}\n  \\vec P_0 &= (&-1&,&-1&,& 0&)\\\\\n  \\vec P_1 &= (& 1&,&-1&,& 0&)\\\\\n  \\vec P_2 &= (& 1&,& 1&,& 0&)\\\\\n  \\vec P_3 &= (&-1&,& 1&,& 0&).\n\\end{array}\n\\]\nNow define $|J|$ as the minimum value of the\ndeterminant of the Jacobian evaluated at all Gauss points of the element.\nThe distortion is then\n\\[\nq = \\frac{|J| A_m}{A} = \\frac{4|J|}{A}.\n\\]\nDistortion is a measure of how well-behaved the mapping from\nparameter space to world coordinates is.\n\n\\quadmetrictable{distortion}%\n{$1$}%                                      Dimension\n{$[0.5,1]$}%                                Acceptable range\n{$[0,1]$}%                                  Normal range\n{$[-DBL\\_MAX,DBL\\_MAX]$}%                   Full range\n{$1$}%                                      Unit square\n{\\cite{ideas:xx}}%                          Citation\n{v\\_quad\\_distortion}%                      Verdict function name\n\n", "meta": {"hexsha": "9bb4bd85b5f85db1cdce4605bf2370fdc607eca5", "size": 1111, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadDistortion.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadDistortion.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadDistortion.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 34.71875, "max_line_length": 73, "alphanum_fraction": 0.4896489649, "num_tokens": 330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418116217418, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7445183841568672}}
{"text": "\\section{Some theoretical background: } \n\nGIFMOD is equipped with two inverse modeling modules including a maximum-likelihood (deterministic) parameter estimation and a Bayesian probabilistic parameter estimation. The deterministic parameter estimation approach uses a Hybrid Genetic Algorithm to find combination of model parameters maximizing the likelihood of observing the measured data which the Bayesian approach uses Markov Chain Monte Carlo (MCMC) algorithm to produce samples of parameters representing the joint posterior distribution of model parameters designated to be estimated by the program. \n\nGIFMOD allows for any of the parameters in the model to be treated as unknown parameters and be estimated by providing their prior distributions while allowing the user to choose between three types of prior distributions: including normal, log-normal, and uniform. \nThe observed data can be specified to represent any of the state variables in the model including hydraulic (i.e.  flow rates, head, cross- sectional areas), as well as particle and constituent concentrations at each block. As is typically done in Bayesian inference, the error here is defined as a quantity encompassing measurement error, model structural error, and all other errors resulting from the uncertainties associated with the external forcing (input data) such as weather data, inflow rates, and concentrations, etc. The general form of the model error structure can be expressed using the following equation: \n\n\\begin{equation}\n\\label{eq:im1}\n\\tilde Y(t) = \\xi^{-1}[\\xi[Y(t)]+\\epsilon]\n\\end{equation}\nwhere $Y$ is the vector containing the model’s observed constituents, $\\tilde Y(t)$ represents the observed data vector, $\\xi$ represents the error structure function (e.g., for log-normal error structure, $\\xi$ is the natural logarithm function, while for Gaussian error structure, $\\xi$ is the identity function), and $\\epsilon$ is a random vector containing transformed measurement, structural and external forcing errors, which is assumed to collectively follow a multivariate normal distribution. \nThe Bayes’ theorem \\citep{kaipio2006} can be used to obtain the joint probability distribution of parameters given the observed data, namely, the posterior distribution of the parameters as:\n\\begin{equation}\n\\label{eq:im2}\np(\\vec{\\Psi}|\\vec{\\tilde Y})=\\frac{p(\\vec{\\tilde Y}|\\vec{\\Psi}) p(\\vec{\\Psi})}{p(\\vec{\\tilde Y})}\n\\end{equation}\n\nwhere $p(\\vec{\\tilde Y}|\\Psi)$ is the likelihood function that is the probability of observing the measured data $\\vec{\\tilde Y}$ given a parameter set $\\vec{\\Psi}$, $p(\\vec{\\Psi})$ represents the prior knowledge about the parameters and error structure, and $p(\\vec{\\tilde Y})$ is a normalizing factor. $\\vec{\\Psi}$ in Eq. (\\ref{eq:im2}) contains all the parameters that are intended to be estimated using the observed data and the elements of the variance-covariance matrix for the random error term $\\epsilon$ in eq. (\\ref{eq:im1}). The likelihood of observing $\\vec{\\tilde Y}(t)$ given a parameter set $\\vec{\\Psi}$ or simply the likelihood function $p(\\vec{\\tilde Y}|\\Psi) = p(\\vec{\\tilde Y}|\\vec{Y},\\vec{\\Gamma})$ can be theoretically calculated based on the error structure. If the errors due to the uncertainties associated with the external forcing are considered part of the observation error, then the external forcing can be considered deterministically, and thus the model outputs become a function of only model parameters. In this case, the error function can be re-written as $p(\\vec{\\tilde Y}|\\vec{\\Phi},\\vec{\\Gamma})$. In theory, each element of the variance-covariance matrix $\\vec{\\Gamma}$ should be estimated as part of the parameter estimation. However, this makes the total number of parameters to be estimated very large and imposes a large computational burden. Therefore, observation errors of different constituents are typically assumed to be independent, and the correlations between observed concentration errors of different constituents are ignored \\citep{walsh2012}. By making this assumption, the variance-covariance matrix becomes diagonal. If it is also assumed that errors of consecutive observations of individual data-sets used in parameter estimation are independent of each other, then the likelihood function of the observed vector can be computed as a function of the model parameters:\n\\begin{equation}\n\\label{eq:im3}\np(\\vec{\\tilde Y}|\\vec{\\Psi})=\\frac{\\prod_{i=1}^{NT} \\prod_{j=1}^{NS_i} \\xi'(\\tilde y_{ij})}{(2 \\pi \\prod_{i=1}^{NT} \\sigma_i^2)^{NS_i/2}}exp\\bigg[-\\sum_{i=1}^{NT} \\sum_{j=1}^{NS_i} \\frac{(y_{ij}-\\tilde y_{ij})^2}{2 \\sigma_i^2}\\bigg]\n\\end{equation}\n\nwhere $\\tilde y_{ij}\\in \\vec{\\tilde Y}$ is the $j^{th}$ data point of observed concentration of observed state variable $i$, $NT$ is the total number of different measured state variables, $j$ indicates the time and location of the measurement. $NS_i$ is the number of total samples (in time or location) of observed state variable $i$. The mapping function $\\xi$ in the likelihood function can be assumed to be any transformation depending on the distribution of the observed data or by performing trial and error to find the best transformation by comparing the posterior residuals with the presumed error structure, and $\\xi'$ is its derivative. For example, considering $\\xi$ to be the identity function implies a normally distributed and additive error structure, while assuming $\\xi$ to be the logarithm function results in a log-normally distributed and multiplicative error structure. Other error structures can be obtained by selecting a corresponding mapping function. $y_{ij}\\in \\vec{Y}$  is the predicted concentration of constituent $i$ at time/location $j$. $\\sigma_i$ is the standard deviation of observed constituent $i$. When the deterministic parameter estimation approach based on maximum likelihood approach is to be applied to estimate the parameters, the values of parameters that maximize Eq. \\ref{eq:im3} \\citep{montgomery2010} are found  using a hybrid genetic algorithm. \nThe second term in the numerator of Eq. \\ref{eq:im2} represents the prior knowledge about the probability density of the parameters. This information can be obtained from literature reviews, experts’ experience, or independently performed experimental results.\nIn the probabilistic parameter estimation module, the MCMC algorithm \\citep{gamerman2006} is used to generate random samples according to the posterior distribution in Eq. \\ref{eq:im2}. The MCMC algorithm implemented in the program is based on the Metropolis-Hasting method \\citep{metropolis1953}. MCMC algorithm that is implemented into GIFMOD automatically adjusts the perturbation factors to achieve an acceptance rate provided by the user. In the next section the way to set up an inverse problem in GIFMOD and the parameters adjusted by the user in order to do so are described.  \n\\section{Defining parameters and observed data}\nIn order to perform an inverse modeling, parameters and observed data should first be introduced. Parameters should be assigned to the specific properties of the model and each set of observed data should be attributed to a specific output of the model. \n\\subsection{Defining parameters and adjusting their properties: }\nIn order to add a parameter to the model right click on \\textbf{Inverse Modeling}$\\rightarrow$\\textbf{Parameters} and then click on \\textbf{Add parameters}. Each parameter has the following properties: \n\n\\begin{itemize}\n    \\item \\textbf{Name: } This indicates the name that is assigned to a parameter. The name of the parameter will be used to assign the parameter to specific properties of the model and when generating the results of inverse modeling.\n    \\item \\textbf{Value: } This is the value that will be assigned to the parameter if the modeling is conducted in forward mode. \n    \\item \\textbf{Maximum Value: } In deterministic inverse modeling, this indicates the upper bound for the parameter (search domain). In probabilistic inverse modeling, it indicates the 97.5 percentile of the prior distribution for this parameter. \n    \\item \\textbf{Minimum Value: } In deterministic inverse modeling, this indicates the lower bound for the parameter (search domain). In probabilistic inverse modeling, it indicates the 2.5 percentile of the prior distribution for this parameter.\n    \\item \\textbf{Prior distribution: } Indicates the mathematical form of the prior distribution of the parameters. The choices provided include \\textbf{Normal}, and \\textbf{Lognormal}. The mean and standard deviation of the prior distributions are calculated based on the maximum and minimum values. \n\\end{itemize}\n\n\\subsection{Defining observed data and assigning their properties: }\nObserved data can be added by right-clicking on \\textbf{Inverse Modeling}$\\rightarrow$\\textbf{Observations} and then clicking on \\textbf{Add observation}. Each observation includes a time-series representing an state variable of the model. Each observation has the following properties: \n\n\\begin{itemize}\n    \\item \\textbf{Name: } The name of an observation is used when generating results in deterministic and probabilistic inverse modeling. \n    \\item \\textbf{Standard Deviation ID: } This is an identification that is used to group observations that will be assigned the same standard deviation. The total number of groups of observations is equivalent to the parameter $NT$ in Eq. \\ref{eq:im3}. The observations having the same \\textbf{Standard Deviation ID} will be grouped together and a single observation error standard deviation, $\\sigma_i$ will be assigned to them. \n    \\item \\textbf{Block/connector: } This indicates whether the state variable to the observation correspond to is a block or a connector state variable. Concentrations, storages, hydraulic heads are always block state variables, while flow rates and interface areas are connector state variables. \n    \\item \\textbf{Error distribution: } This indicates the error structure ($\\xi$) in Eq. \\ref{eq:im1} that is used when computing the likelihood value.\n    \\item \\textbf{Location: } Indicate the block or the connector that this observed data corresponds to. \n    \\item \\textbf{Observed data: } This field allows loading the observed data time-series. The observed data time series is a .csv text file that should consist of two columns first representing times of measurement and the second the observed values. \n    \\item \\textbf{Quantity: } This field allows selecting the state variable that the observed data corresponds to. As for water quality and particles the drop-down menu containing the selectable state variables is populated depending on the constituents, phases, and particle types available. \n    \n\\end{itemize}\n\\subsection{Example: Estimation of bio-kinetic parameters of nitrification processes from an batch test: }\nThis case represent interpretation of an actual experiment to determine the rates of microbial activities during ammonia and nitrite oxidation. Four experiments were conducted using the same sludge sample. The variation of dissolved oxygen with respect to time was measured for each of the four experiments. The initial conditions for each of the experiments is shown in Table \\ref{table:inverse_example} and the observed variation of DO for the four cases are shown in Figure \\ref{fig:inverse_example1}. \n\n\\begin{table}[]\n    \\centering\n    \\begin{tabular}{c|c c c c}\n       Experiment  & $NO_3^{-1}(mg/L) $ & $NH_3(mg/L)$ & $DO(mg/L)$ & $VSS(mg/L)$ \\\\\n    \\hline\n        No Spike & 0 & 0 & UK* &  730  \\\\\n        $NO_2^{-1}$ Spike & 50 & 0 & UK & 695 \\\\\n        $NH_3$ Spike & 0 & 50 & UK & 645 \\\\\n        $NO_2^{-1}$ and $NH_3$ & 50 & 50 & UK & 660\\\\ \n    \\end{tabular}\n    \\caption{Initial condition for the declining DO test aimed at estimating AOB and NOB biokinetics. *- UK: The initial condition for DO is treated as a parameter to be estimated by the model}\n    \\label{table:inverse_example}\n\\end{table}\n\nThe processes considered in the model are shown in table \\ref{table:inverse_example2}. The only constituents that will be explicitly considered in the model include $DO$, $NH_3$, $NO_2^{-1}$, and $VSS$. $VSS$ is used as a surrogate for biomass (i.e. it is assumed to be proportional to AOB, NOB and OHO) and it is also assumed to stay unchanged throughout each experiment. the Petersen matrix is shown in table \\ref{table:inverse_example3}.\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[width=6cm]{Images/Figure35.png} \\\\\n\\caption{Temporal variation of DO for the four different experiments used to estimate nitrification bio-kinetics parameters}\\label{fig:inverse_example1}\n\\end{center}\n\\end{figure}\n\n\\begin{table}[]\n    \\centering\n    \\begin{tabular}{l l}\n       Process & Reaction Expression \\\\\n    \\hline\n        Ammonia oxidation (AO) & $21.9O_2 + \\frac{21.9}{3.43}NH_3 \\rightarrow \\frac{21.9}{3.43}NO_2^{-1}$  \\\\\n        Nitrite oxidation (NO) & $11.7O_2 + \\frac{11.7}{1.14}NO_2^{-1} \\rightarrow \\frac{11.7}{1.14}NO_3^{-1}$ \\\\\n        Ordinary heterotrophic growth (OHO) & $BOD + O_2 \\rightarrow CO_2$ \\\\\n    \\end{tabular}\n    \\caption{Reactions considered in the nitrification bio-kinetics parameter estimation example}\n    \\label{table:inverse_example2}\n\\end{table}\n\n\n\\begin{table}[]\n    \\centering\n    \\begin{tabular}{l|c |c c c c}\n       Process & Rate Expression & $O_2$ & $NH_3$ & $NO_2^{-1}$ & VSS  \\\\\n    \\hline\n        AO & $VSS \\mu_{AOB} \\frac{[O_2]}{(k_{OA} + [O_2]}\\frac{[NH_3]}{[NH_3]+k_{NH3}}$ & -21.9 & $-\\frac{21.9}{3.43}$ & $\\frac{21.9}{3.43}$ &   \\\\\n        NO & $VSS \\mu_{NOB} \\frac{[O_2]}{k_{ON} + [O_2]}\\frac{[NO_2^{-1}]}{[NO_2^{-1}]+k_{NO2}}$ & $-11.7$ &  & $-\\frac{11.7}{1.14}$ &   \\\\\n        OHO & $VSS \\mu_{OHO} \\frac{[O_2]}{k_{OH}+[O_2]}$ & $-\\frac{1-0.52}{0.52}$ & & &  \\\\\n    \\end{tabular}\n    \\caption{Petersen matrix for the nitrification bio-kinetics parameter estimation example}\n    \\label{table:inverse_example3}\n\\end{table}\n\n\\begin{table}[]\n    \\centering\n    \\begin{tabular}{l|c c c}\n       Parameter & 2.5\\% & 97.5\\% & Distribution  \\\\\n    \\hline\n        $\\mu_{AOB}$ & 0.005 & 0.5 & lognormal \\\\\n        $k_{OA}$ & 0.05 & 2.0 & lognormal \\\\\n        $\\mu_{NOB}$ & 0.005 & 0.5 & lognormal \\\\\n        $k_{ON}$ & 0.05 & 2.0 & lognormal \\\\\n        $k_{NH3}$ & & FIXED = 0.5 & \\\\\n        $k_{NO2}$ & & FIXED = 0.5 & \\\\\n        $\\mu_{OHO}$ & 0.0001 & 0.1 & lognormal \\\\\n        $k_{OH}$ & 0.00125 & 10 & lognormal \\\\\n    \\end{tabular}\n    \\caption{Prior range of parameters used in nitrification bio-kinetics example}\n    \\label{table:inverse_example4}\n\\end{table}\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[width=12cm]{Images/Figure36.png} \\\\\n\\caption{Reaction network for the nitrification parameter estimation example}\\label{fig:inverse_example2}\n\\end{center}\n\\end{figure}    \n\n\nTable \\ref{table:inverse_example4} shows the prior 95\\% ranges and the prior distributions of each of the parameters. In this particular case due to lack of information about $NH_3$ and $NO_2^{-1}$ concentration variation with time if $k_{NH3}$, and $k_{NO2}$ are considered unknown, there is a risk of problem becoming over-parametrized and therefore, we here assume the values of these two parameters to be fixed.   \n\n\\subsubsection{Steps to set-up the model: }\nTo construct the model in GIFMod follow the following steps: \n\\begin{itemize}\n    \\item \\textbf{Add a pond: } We will simulate the reactor using a \\textbf{Pond} block. Other media types can also be used. Add a pond by clicking on the pond icon \\includegraphics[width=0.5cm]{Icons/pond_icon.png} on the top tool bar. Set the following properties for the pond: \\\\\n    - \\textbf{Area: } 1$m^2$\\\\\n    - \\textbf{Initial water depth: } 1m\\\\\n    \\item \\textbf{Add the constituents: } Add constituents ($DO$, $NH_3$, $NO_2^{-1}$, $VSS$) by right-clicking on \\textbf{Water quality}$\\rightarrow$\\textbf{Constituents}. \\item \\textbf{Adding experiments: } The goal of this example is to infer the values of reaction parameters using four experiments in a holistic way. This means that the best parameter set that can collectively explain the results from the four experiments in sought for. There are two ways to consider four experiments in the model. The first way is to define four independent ponds with different initial conditions and the second way is to use \\textbf{Experiments}. Here we will use the second approach. \\\\ To add experiments click on the \\textbf{Add new experiment} button \\includegraphics[width=0.3cm]{Icons/newexperiment_icon.png} three times to add three new experiments. \n    \n    \\item \\textbf{Setting the duration of the simulation: } The duration of the experiments are all below 0.2 days. First from the experiment menu on the top tool bar select \\textbf{All experiments}. This forces the program to apply any changes in the properties to all the experiments. To set the simulation duration to 0.2 from \\textbf{Settings}$\\rightarrow$\\textbf{Project settings} and from the \\textbf{Properties} window right-click on the label for \\textbf{Simulation end time} and click on \\textbf{Enter number} from the drop-down menu that appears. Enter 0.2 in the dialog box that appears. \n    \n    \\item \\textbf{Adding reaction parameters: } Add the eight reaction parameters by right-clicking on \\textbf{Water quality}$\\rightarrow$\\textbf{Reactions}$\\rightarrow$\\textbf{Reaction parameters} according to table \\ref{table:inverse_example4}. For the two fixed parameters $k_{NH3}$ and $k_{NO2}$, enter a value of 0.5. \n    \\textbf{Add reaction network: } Right click on reaction  \\textbf{Water quality}$\\rightarrow$\\textbf{Reactions}$\\rightarrow$\\textbf{Reaction network}. Enter the processes according to the Petersen matrix shown in table \\ref{table:inverse_example3}. The finished reaction network window should look like figure \\ref{fig:inverse_example2}.\\\\\n    \\item \\textbf{Setting initial conditions: } From the \\textbf{Experiments} drop-down menu on the top tool bar, select \\textbf{Experiment1}. Click on the pond block and then from the \\textbf{Properties} window choose \\textbf{Constituent initial conditions}. Enter the initial conditions for experiment 1 according to Table \\ref{tab:inv_ini_cond}.\n   \\begin{table}[]\n    \\centering\n    \\begin{tabular}{l|c c c c}\n       Experiment & $DO(mg/L)$ & $NH_3(mg/L)$ & $NO_2^{-1}(mg/L)$ & VSS (mg/L) \\\\\n    \\hline\n        1 & 7.78 & 0 & 0 & 730 \\\\\n        2 & 7.76 & 50 & 0 & 645 \\\\\n        3 & 8.02 & 0 & 50 & 695 \\\\\n        4 & 7.8 & 50 & 50 & 660 \\\\\n    \\end{tabular}\n    \\caption{Initial conditions for the four experiments used for estimation of bio-kinetics and stoichiometric parameters of nitrification}\n    \\label{tab:inv_ini_cond}\n\\end{table} \n    \n    The initial condition window for the first experiment should look like Figure \\ref{fig:42}. \n    \n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[width=6cm]{Images/Figure42.png} \\\\\n\\caption{Initial conditions for the nitrification inverse modeling example}\\label{fig:42}\n\\end{center}\n\\end{figure}  \n\nChange the experiment to experiment2 from the \\textbf{experiments} drop down menu and similarly set the initial condition according to the second row of table \\ref{tab:inv_ini_cond}. \n\nSimilarly assign the initial conditions for experiment 3 and 4. \n    \n    \\item \\textbf{Setting up parameters to be estimated: } Add a parameter representing $\\mu_{AOB}$ by right-clicking of \\textbf{Inverse modeling}$\\rightarrow$\\textbf{Parameters} and clicking on \\textbf{Add parameters} from the drop-down menu. Assign the following parameter to the newly added parameter:\\\\\n    - \\textbf{Name:} $\\mu_{AOB}$\\\\\n    - \\textbf{Maximum value: } \\textit{0.5}\\\\\n    - \\textbf{Minimum value: } \\textit{0.005}\\\\\n    - \\textbf{Distribution: } \\textit{Log-Normal}\\\\\n    Repeat for the other parameters to be estimated including $k_{OA}$, $\\mu_{NOB}$, $k_{ON}$, $\\mu_{OHO}$,\nand $k_{OH}$ and assign the ranges and the distribution according to table \\ref{table:inverse_example4}. As for the \\textbf{Value} of the parameters respectively use $\\mu_{AOB}=0.05$, $k_{OA}=0.31$, $\\mu_{NOB}=0.05$, $k_{ON}=0.31$, $\\mu_{OHO}=0.003162$, $k_{OH}=0.111$. These values are used when the model is run in forward mode. \\\\Please note that the name of the parameters should not be identical to their corresponding reaction parameters. \\\\\n\n\n\\item \\textbf{Assigning the parameters to the corresponding model properties: } The parameters defined in the previous step should not be assigned to their corresponding properties in the model. Choose the reaction parameter $\\mu_{AOB}$ from \\textbf{Water quality}$\\rightarrow$\\textbf{Reactions}$\\rightarrow$\\textbf{Reaction parameters}, and the right click on the label of \\textbf{Value} property and from the drop-down menu select \\textbf{Parameters}$\\rightarrow$\\textbf{$\\mu_{AOB}$} figure \\ref{fig:inverse_example3}.\n\n\\item \\textbf{Setting observations: } Here we specify the properties of the observed data used to perform the parameter estimation. \\\\ Right-click on \\textbf{Project explorer}$\\rightarrow$\\textbf{Inverse modeling}$\\rightarrow$\\textbf{Observations} and click on \\textbf{Add Observation}.\\\\ \nSet the following properties for the first observation: \\\\\n\\underline{observation 1:} \\\\\n- \\textbf{Name: } \\textit{DO\\_no\\_spike}\\\\\n- \\textbf{Standard deviation ID: } \\textit{std} \\\\\n- \\textbf{Block/Connector: } \\textit{Block} \\\\\n- \\textbf{Error Distribution: } \\textit{Normal} \\\\\n- \\textbf{Location: } \\textit{Pond (1)} \\\\\n- \\textbf{Experiment: } \\textit{experiment1} \\\\\n- \\textbf{Observed data: }  \\textit{Obs\\_nospike.txt} \\\\\n\\textbf{Quantity} \\textit{DO:Aqueous} \\\\\n\nAdd three more observation and set the properties as follows: \n\n\\underline{observation 2:} \\\\\n- \\textbf{Name: } \\textit{DO\\_NH3\\_spike}\\\\\n- \\textbf{Standard deviation ID: } \\textit{std} \\\\\n- \\textbf{Block/Connector: } \\textit{Block} \\\\\n- \\textbf{Error Distribution: } \\textit{Normal} \\\\\n- \\textbf{Location: } \\textit{Pond (1)} \\\\\n- \\textbf{Experiment: } \\textit{experiment2} \\\\\n- \\textbf{Observed data: }  \\textit{Obs\\_NH3.txt} \\\\\n\\textbf{Quantity} \\textit{DO:Aqueous} \\\\\n\n\\underline{observation 3:} \\\\\n- \\textbf{Name: } \\textit{DO\\_NO2\\_spike}\\\\\n- \\textbf{Standard deviation ID: } \\textit{std} \\\\\n- \\textbf{Block/Connector: } \\textit{Block} \\\\\n- \\textbf{Error Distribution: } \\textit{Normal} \\\\\n- \\textbf{Location: } \\textit{Pond (1)} \\\\\n- \\textbf{Experiment: } \\textit{experiment3} \\\\\n- \\textbf{Observed data: }  \\textit{Obs\\_NO2.txt} \\\\\n\\textbf{Quantity} \\textit{DO:Aqueous} \\\\\n\n\\underline{observation 4:} \\\\\n- \\textbf{Name: } \\textit{DO\\_both}\\\\\n- \\textbf{Standard deviation ID: } \\textit{std} \\\\\n- \\textbf{Block/Connector: } \\textit{Block} \\\\\n- \\textbf{Error Distribution: } \\textit{Normal} \\\\\n- \\textbf{Location: } \\textit{Pond (1)} \\\\\n- \\textbf{Experiment: } \\textit{experiment3} \\\\\n- \\textbf{Observed data: }  \\textit{Obs\\_both.txt} \\\\\n\\textbf{Quantity} \\textit{DO:Aqueous} \\\\\n\n\\textbf{Note: } Entering the same \\textbf{Standard deviation ID} for all the observation forces the program to find a single observation error standard deviation for all the observation. In this case because the measured quantity for all observations is dissolved oxygen it is expected that the measurement error for all observation to have the same statistical distribution. \n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[width=6cm]{Images/Figure37.png} \\\\\n\\caption{Assigning parameters to model properties}\\label{fig:inverse_example3}\n\\end{center}\n\\end{figure}    \n\nRepeat for the other parameters to be estimated including $k_{OA}$, $\\mu_{NOB}$, $k_{ON}$, $\\mu_{OHO}$,\nand $k_{OH}$. \n\n\\item \\textbf{Running in forward mode: } When the model is run in forward mode, the values of the parameters as specified in the \\textbf{Value} field are used and a single simulation is performed. Click on the forward run icon \\includegraphics[width=0.3cm]{Icons/run_icon.png} and wait for the simulation to end. Choose an experiment from the \\textbf{Experiments} drop-down menu and then right click on the block and choose \\textbf{Plot water quality results}$\\rightarrow$\\textbf{DO}. \\\\\n\n- Right-click on \\textbf{Project Explorer}$\\rightarrow$\\textbf{Inverse modeling}$\\rightarrow$ \\textbf{Observations}$\\rightarrow$ \\textit{DO\\_NH3\\_spike} and then click on \\textbf{Plot modeled data}. This shows the corresponding model prediction to observations for experiment 2. You can also check the agreement plot. \n\n\\item \\textbf{Change the initial time-step: } The model results that are used to calculate the likelihood are interpolated at time-intervals specified in the \\textbf{initial time-step field}. Because the experiments in this example are short (0.1 day), the default initial time-step of 0.01 day is not adequate. From the project exploder choose \\textbf{Settings}$\\rightarrow$\\textbf{Solver Settings} and then from the \\textbf{Properties} window find \\textbf{Initial time step size} and change the value to 0.001 day. \n\n\\item{Inverse modeling: }\\\\ - Choose \\textbf{number of generations} from \\textbf{Inverse modeling}$\\rightarrow$\\textbf{Genetic Algorithm} and change the value to 100. This makes the number of generations in the Genetic Algorithm to 100. Keep the rest of the parameters unchanged.\n\n - Choose \\textbf{number of realizations} from \\textbf{Inverse modeling}$\\rightarrow$\\textbf{Markov chain Monte Carlo} and change the value to 1000. This makes the number of posterior prediction realizations to 1000. Keep the rest of the parameters unchanged. \n\n- Click on the inverse modeling icon \\includegraphics[width=0.5cm]{Icons/inverse_icon.png} on the left side tool bar. Inverse simulation can take up to one hour depending on the number and speed of the CPUs of the computer being used for the simulation. Wait until the deterministic inverse modeling and the MCMC is finished. The progress bars on the \\textbf{Simulation} window shows the percentage of each stage on inverse modeling being completed (Figures \\ref{fig:43} and \\ref{fig:44}). \n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[width=8cm]{Images/Figure43.png} \\\\\n\\caption{Inverse modeling progress window during deterministic parameter estimation stage}\\label{fig:43}\n\\end{center}\n\\end{figure}  \n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[width=8cm]{Images/Figure44.png} \\\\\n\\caption{Inverse modeling progress window during probabilistic parameter estimation}\\label{fig:44}\n\\end{center}\n\\end{figure}  \n\n\n\n\\item \\textbf{Estimated values of the parameters: } To see the estimated values of the parameters select a parameter from \\textbf{Project Explorer}$\\rightarrow$\\textbf{Inverse Modeling}$\\rightarrow$\\textbf{Parameters} and look at the \\textbf{Value} field. The value should be replaced by the estimated parameter value. \n\n\\item \\textbf{Checking the model vs. observed agreement: } Right-click on \\textbf{Project Explorer}$\\rightarrow$\\textbf{Inverse Modeling}$\\rightarrow$\\textbf{Observations}$\\rightarrow$\\textit{DO\\_nospike} and the choose \\textbf{Plot modeled data}. A graph will appear that will show observed data and the model prediction based on the estimated parameters. Do the same for other observation data (Figure \\ref{fig:48}).\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[width=10cm]{Images/Figure48.png} \\\\\n\\caption{Observed and predicted DO variation in all four experiments}\\label{fig:48}\n\\end{center}\n\\end{figure}  \n\n\n\n\\item \\textbf{Checking the posterior distributions of the parameters: }\\\\ - From \\textbf{Project Explorer}$\\rightarrow$\\textbf{Inverse Modeling}$\\rightarrow$\\textbf{Parameters} right-click on $\\mu_{NOB}$ and select \\textbf{Plot posterior distribution histogram}. A graph will appear that shows the posterior distribution of parameter $\\mu_{NOB}$ (Figure \\ref{fig:45}). Similarly inspect the posterior distribution for other parameters. (Figure \\ref{fig:46}). In this figure the box plot shows the 95\\% credible interval for the parameter while the solid line shows the median and the dot shows the expected value of the parameter. \n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[width=11cm]{Images/Figure45.png} \\\\\n\\caption{Posterior distribution of $k_{OH}$,  $\\mu_{OHO}$, $k_{ON}$,  $\\mu_{NOB}$}\\label{fig:45}\n\\end{center}\n\\end{figure}  \n\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[width=8cm]{Images/Figure46.png} \\\\\n\\caption{Posterior credible interval for }\\label{fig:46}\n\\end{center}\n\\end{figure}  \n\n\n- To see the 95\\% credible intervals for all the parameters right-click on \\textbf{Project Explorer}$\\rightarrow$\\textbf{Inverse Modeling}$\\rightarrow$\\textbf{Parameters} and select \\textbf{Plot Percentile data} (Figure \\ref{fig:47}). \n\n\n-  From \\textbf{Project Explorer}$\\rightarrow$\\textbf{Inverse Modeling}$\\rightarrow$\\textbf{Parameters} right-click on $\\mu_{NOB}$ and select \\textbf{Plot percentiles}. \n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[width=8cm]{Images/Figure47.png} \\\\\n\\caption{Posterior credible interval for all parameters}\\label{fig:47}\n\\end{center}\n\\end{figure} \n\n\\end{itemize}\n\\section{Maximum-likelihood Inverse Modeling Control Parameters}\n\nThis section describes the control parameters for the maximum-likelihood (deterministic) inverse modeling feature of GIFMod. The maximum-likelihood control parameters can be accessed through \\textbf{Project Explorer}$\\rightarrow$\\textbf{Inverse Modeling}$\\rightarrow$\\textbf{Genetic Algorithm}.\n\n\\begin{itemize}\n    \\item \\textbf{Name: } The name of Genetic Algorithm object. It can be ignored. \n    \\item \\textbf{Cross-over probability: } This indicates the probability of \\textit{individuals} undergoing a cross-over to generate the \\textit{off-springs}. The reminder of the \\textit{individuals} selected for mating will be copied to the next generations with only \\textit{mutation}. For example if the value of \\item \\textbf{Cross-over probability} is set to 0.8, 80\\% of the selected individuals will undergo cross-over while 20\\% will be directly copied to the next generation. \n    \\item \\textbf{GA output file: } The results of genetic algorithm optimization will be written in this file. The file that will be generated can be used for diagnosis of the GA performance. \n    \\item \\textbf{Initial GA population: } If a file name is provided here it will be considered as the initial population for the GA analysis. If this field is empty, the initial GA population will be created randomly. \n    \\item{Mutation probability: } This indicates the probability of mutation of each bit when copying from one generation to the other.\n    \\item{Number of generations: } Indicates the number of generation in the GA algorithm to obtain the optimal parameter set.\n    \\item{Perform local sensitivity analysis: } Indicates whether a local sensitivity analysis should be performed based on the deterministic parameter obtained by the GA algorithm. The results of the local sensitivity analysis will be saved in a text file called \"sensitivity\\_mat\\_lumped.txt\" in the working path. \n    \\item{Population: } Indicates the population number that will be used for the GA optimization.\n    \\item{Read GA analysis from file: } This field is used when the GA analysis has been previously done and only the post-processing is intended to be done using the results of the previous inverse modeling. The file name that will be entered is where GIFMod will load the results of the previous GA analysis from.\n    \\item{Shake scale: } When the maximum fitness in the population is not improved in three sequential generations, an offspring of the fittest individual is produced by adding a random noise to the parameter values. This scale indicate the magnitude of the random noise. The default value is 0.05 which indicate adding a normally distributed noise with a standard deviation equal to 5\\% of the value of each parameter. The purpose of this \\textit{shaking} is to find possible optimal solution in the neighborhood of the parameter set represented by the fittest individual. \n    \\item{Shake scale reduction factor: } If adding the noise does not result in an improved fitness, the shake-scale is gradually reduced (so a closer neighborhood is searched). The shake scale reduction factor is the factor by which this reduction in the shake scale is done. \n    \\item{Number of threads: } The number of CPU threads used for the GA and MCMC parameter estimation. \n\\end{itemize}\n\n\\section{Probabilistic Inverse Modeling Control Parameters}\nThis section describes the control parameters for the MCMC (stochastic) inverse modeling feature of GIFMod. The MCMC control parameters can be accessed through \\textbf{Project Explorer}$\\rightarrow$\\textbf{Inverse Modeling}$\\rightarrow$\\textbf{Markov chain Monte Carlo}.\n\n\\begin{itemize}\n\\item \\textbf{Create output realization including observation errors} Switching this property to \\textit{Yes} results in GIFMod to generate prediction confidence intervals while considering the observation error. \n\n\\item \\textbf{Generate output realizations: } Determines whether output realizations based on parameter samples from the posterior distribution should be generated. These realization will be used to determine confidence intervals of model predictions while accounting for parameter uncertainty. \n\\item \\textbf{Initial perturbation: } Determines whether the initial MCMC parameter sets should be obtained by perturbing the deterministically estimated parameters using GA or by using the non-perturbed values. MCMC used the parameters estimated by the GA as the initial point wither after perturbing the parameters or not. \n \\item{Save realization outputs in a file: } Switching this property to \\textit{Yes}, forces the program to create a file where the sampled parameter values from the posterior distribution to generate the posterior realizations are saved. \n \n ", "meta": {"hexsha": "808588d098b0a1f7c5a392fd86471932c8694c45", "size": 33679, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "GIFMod User's Manual/Inverse_modeling.tex", "max_stars_repo_name": "ArashMassoudieh/GIFMod_", "max_stars_repo_head_hexsha": "1fa9eda21fab870fc3baf56462f79eb800d5154f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-11-20T19:32:27.000Z", "max_stars_repo_stars_event_max_datetime": "2018-08-28T06:08:45.000Z", "max_issues_repo_path": "GIFMod User's Manual/Inverse_modeling.tex", "max_issues_repo_name": "ArashMassoudieh/GIFMod_", "max_issues_repo_head_hexsha": "1fa9eda21fab870fc3baf56462f79eb800d5154f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-07-04T05:40:30.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-04T05:43:37.000Z", "max_forks_repo_path": "GIFMod User's Manual/Inverse_modeling.tex", "max_forks_repo_name": "ArashMassoudieh/GIFMod_", "max_forks_repo_head_hexsha": "1fa9eda21fab870fc3baf56462f79eb800d5154f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-11-09T22:00:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-30T10:56:08.000Z", "avg_line_length": 98.1895043732, "max_line_length": 1927, "alphanum_fraction": 0.7569999109, "num_tokens": 8548, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7444786033543108}}
{"text": "\\graphicspath{ {./img/TheFEM/} }\n\\chapter{The Finite Element Method}\n\\section{Weighted residual methods}\nThis section introduces the concept of residual or difference from zero in a differential equation once its solution is approximated. For that purpose we will take as prototype equation the one obtained as our general model of BVP (see \\cref{eq:GenPDE}) and recalled here for completeness\n\\begin{equation}\n\\rho(\\vb x) \\pdv{u(\\vb x, t)}{t} + \\mathcal{L}u(\\vb x, t) = \\rho (\\vb x)F(\\vb x, t) \\enspace .\n\\label{eq:GenPDE2}\n\\end{equation}\n\nWe will assume that the actual solution to the generalized BVP given by \\cref{eq:GenPDE2} is approximated by $\\tilde u(\\vb{x})$ through a superposition like\n\\begin{equation}\n\\tilde u (\\vb{x}) = {N^I}(\\vb{x}){u^I}\n\\label{basicsuper}\n\\end{equation}\nwhere ${N^I}(\\vb{x})$ are interpolating functions and $I$ denotes a superposition index  varying like $I=1,2,...,K$ with $K$ being the number of points where the solution is known. In what follows we will use $u(\\vb{x})$ instead of $\\tilde u (\\vb{x})$ but will keep in mind that we are actually using the approximation given by \\cref{basicsuper}. Similarly, in order to keep the discussion simple for the time being we will drop the time effects reducing the generalized PDE to the simple form:\n\\begin{equation}\n\\mathcal{L}u(\\vb x) = \\rho (\\vb x)F(\\vb x) \\enspace .\n\\label{eq:GenPDE3}\n\\end{equation}\n\nNow, since we are using the approximation given by \\cref{basicsuper} this equation is not strictly satisifed but instead we will have the following ``unbalanced\" condition\n\\[\\mathcal{L}u(\\vb{x}) - \\rho (\\vb{x})F(\\vb{x}) \\equiv R \\ne 0\\]\nwhere the term $R$ corresponds to a residual error which is to be distributed throughout the solution domain. The so-called weighted residual methods differ in the form in which they distribute the residual between the different $K$ points conforming the computational domain.\n\nUsing \\cref{basicsuper} in \\cref{eq:GenPDE2} and the linearity in the differential operator yields\n\\[R = \\mathcal{L}({N^P}){u^P} - \\rho F\\, .\\]\n\nWe can see that the residual $R$ is a function defined over the domain of interest. The residual would be exactly zero for the solution of the differential equation, but it will not be zero in general. Thus, we want to make the function $R$ as close to zero as possible. To make $R$ as small as possible we need a function (a functional) where we can compare different approximation functions. After getting this functional we can minimize its value. For this minimization we could use the norm of the function, another option is to compute a weighted \\emph{average} of the function over the domain. This is what we call a weighted residual\n\\[\\Pi[u, w] = \\int\\limits_V w R(u) \\dd{V}\\, ,\\]\nand we want to minimize it by making\n\\[\\var{\\Pi}[u, w] = 0\\, ,\\]\n\nIn what follows we will consider different strategies to distribute or weight the residual $R$ over the computational domain.\n\n\\subsubsection{Galerkin method}\nIn the Galerkin scheme the interpolation functions are used also as weighting functions leading to:\n\\[\\int\\limits_V N^Q R\\dd{V} = 0 \\]\nor explicitly\n\\begin{equation}\n  \\int\\limits_V N^Q \\mathcal{L} (N^P)\\dd{V} u^P = \\int\\limits_V N^Q\\rho F\\dd{V}\\, .\n  \\label{eq:Galer}\n\\end{equation}\n\nImposing \\cref{eq:Galer} in the $K$ points conforming the computational domain or equivalently ranging $Q$ from $1$ to $K$ leads to the following system of algebraic equation\n\\begin{equation}\n{K^{QP}}{U^P} = {f^Q}\n\\label{eq:DGaler}\n\\end{equation}\n\nwhere $U^P$ is a vector that stores the point values of the function $u$ along te $K$ points of the computational domain, while $f^Q$ stores the corresponding point excitations.\n\n\\subsubsection{Least squares method}\nIn this method the integral of the square of the residual is minimized with respect to the $K$ point parameters or nodal values of the function. Accordingly,\n\\begin{align*}\n  &\\pdv{u^I}\\int\\limits_V R^2 \\dd{V} = 0\\\\\n  &\\int\\limits_V R \\pdv{R}{u^I} \\dd{V} = 0\\, ,\n\\end{align*}\n\nThe least squares method is a special case of the weighted residual method for the weight functions\n\\[w^I = \\pdv{R}{u^I}\\, .\\]\n\nExpanding the residual, and considering the operator $\\mathcal{L}$ as linear, we obtain\n\\begin{align*}\n  &\\pdv{u^I}\\int\\limits_V [\\mathcal{L}(N^P u^P) - \\rho F]^2 \\dd{V} = 0\\\\\n  &\\int\\limits_V [\\mathcal{L} N^P u^P - \\rho F] \\mathcal{L}(N^I) \\dd{V} = 0\\\\\n &\\int\\limits_V \\mathcal{L}(N^I) \\mathcal{L}(N^P) \\dd{V} u^P - \\rho \\int\\limits_V \\mathcal{L}(N^I) F \\dd{V} = 0\n\\end{align*}\nwhich can be written like\n\\begin{equation}\n  K^{IP} U^P = f^I\n  \\label{eq:Dsquares}\n\\end{equation}\n\n\\subsubsection{Collocation method}\nIn the collocation method the coefficients of the approximation are determined by forcing the residual to be exactly zero at $K$ points over the computational domain, i.e.,\n\\[\\mathcal{L}(N^I) u^I - \\rho F = 0\\, ,\\]\nor\n\\[\\mathcal{L}[N^I(x^J)] u^I - \\rho F(x^J) = 0\\, ,\\]\nwhere $J$ ranges between $1$ and $K$. This equation can be rewritten as a weighted-residual if we consider the residual to be $\\delta(x - x^I)$, the Dirac delta function over the selected points\n\nThe resulting system of algebraic equation can be written as\n\\begin{equation}\nK^{IP} U^P = f^I\\, .\n\\label{eq:Colo}\n\\end{equation}\n\n\\subsubsection{Subdomain method}\nThe zero value of the residual is imposed upon $K$ subdomains\n\\[\\int\\limits_{V^I} \\mathcal{L}(N^P)\\dd{V^I} u^P  - \\rho \\int\\limits_{V^I}  F\\dd{V^I}  = 0 \\qquad I=1,\\cdots,K\\, .\\]\n\nFor instance, for the $N$-th element it follows that\n\\[\\int\\limits_{V^N} \\mathcal{L}(N^P)\\dd{V^N} u^P  - \\rho \\int\\limits_{V^N} F\\dd{V^N}  = 0 \\qquad P=1,\\cdots,K\\, .\\]\n\nApplying the equation over the $K$ subdomains leads to the discrete system;\n\\begin{equation}\nK^{IP} U^P = f^I \\quad \\quad I=1,\\cdots,K\\, .\n\\label{eq:Subdomain}\n\\end{equation}\n\n\\subsubsection{Ritz method}\nIt operates directly upon the variational statement of the problem. For a given functional\n\\[\\Pi  = \\Pi (N^Q u^Q)\\]\nthe variational equation reads\n\\[\\var{\\Pi}  \\equiv \\pdv{\\Pi}{u^Q} \\var{u^Q} = 0\\]\nfrom which\n\\[\\pdv{\\Pi}{u^Q} = 0\\, .\\]\n\n\\subsubsection*{Problem: Discretization of the generalized parabolic equation.}\nLet us consider the case of the generalized parabolic equation and its discretization following the Galerkin method\n\\[\\rho(\\vb x) \\pdv{u(\\vb x,t)}{t} + \\mathcal{L}u(\\vb x, t) = 0\\]\nwhich can also be written using indicial notation\n\\[\\pdv{x_i}\\left[{p(x)\\pdv{u}{x_i} \\right] + q(x)u + \\rho \\pdv{u}{t} = \\rho F.\\]\n\nAssuming that $p(x)=1$ yields\n\\[ - \\int\\limits_V N^P N_{,ii}^Q \\dd{V} u^Q + \\int\\limits_V {q{N^P}{N^Q}dV{u^Q}}  + \\rho \\int\\limits_V {{N^P}{N^Q}dV{v^Q}}  - \\rho \\int\\limits_V {{N^P}FdV = 0} \\]\n\n\\[\\int\\limits_V {N_{,i}^PN_{,i}^Q} dV{u^Q} - \\int\\limits_S {{N^P}N_{,i}^Q{{\\hat n}_i}} dS{u^Q} + \\int\\limits_V {q{N^P}{N^Q}dV{u^Q}}  + \\rho \\int\\limits_V {{N^P}{N^Q}dV{v^Q}}  - \\rho \\int\\limits_V {{N^P}FdV = 0} \\]\n\n\\[\\int\\limits_V {\\left( {N_{,i}^PN_{,i}^Q + q{N^P}{N^Q}} \\right)dV{u^Q}}  + \\rho \\int\\limits_V {{N^P}{N^Q}dV{V^Q}}  = \\int\\limits_S {{N^P}N_{,i}^Q{{\\hat n}_i}} dS{u^Q} + \\rho \\int\\limits_V {{N^P}FdV} \\]\n\nwhich can be written in discrete form;\n\n\\[{K^{PQ}}{U^Q} + {C^{PQ}}{V^Q} = {f^p}\\]\n\n\n\n\\subsubsection*{Problem: Discretization of Navier equations.}\nIn this case the differential equations are written as\n\\[(\\lambda  + \\mu ){u_{j,ij}} + \\mu {u_{i,jj}} + {f_i} = 0 \\enspace .\\]\n\nWe can write the differential operator as\n\\[L_{ij} \\equiv (\\lambda  + \\mu )\\pdv[2]{}{x_i}{x_j} + \\mu \\pdv[2]{}{x_k}{x_k}\\delta_{ij}\\]\n\n\\begin{align*}\n&r_i =  - f_i\\\\\n&u_i = N_i^Q u^Q\\\\\n&\\mathcal{L}_{ij}(u_j) \\equiv (\\lambda  + \\mu )(N_j^Q{u^Q})_{,ij} + \\mu (N_j^Q{u^Q})_{,kk}\\delta_{ij}\\\\\n&\\mathcal{L}_{ij}(u_j) \\equiv (\\lambda  + \\mu )N_{j,ij}^Q u^Q + \\mu N_{i,kk}^Q u^Q\\\\\n&\\mathcal{L}_{ij}(u_j) \\equiv \\mathcal{L}_{ij}(N_j^Q) u^Q \\enspace .\n\\end{align*}\n\nIn the Galerkin scheme we use the trial function as weighting function.\n\\[R_i \\equiv L_{ij}(N_j^Q) u^Q + f_i\\]\nand we state \\dots\n\n\\[\\int\\limits_V {N_i^P{R_i}dV = 0} \\quad \\quad P=1,2,...,N. \\]\n\n\\[\\int\\limits_V {N_i^P{\\mathcal{L}_{ij}}(N_j^K)dV{u^K}}  + \\int\\limits_V {N_i^P{f_i}dV = 0} \\]\n\n\\[(\\lambda  + \\mu )\\int\\limits_V {N_i^PN_{j,ij}^KdV{u^K}}  + \\mu \\int\\limits_V {N_i^PN_{i,kk}^KdV{u^K}}  + \\int\\limits_V {N_i^P{f_i}dV = 0} \\]\n\nintegrating by parts;\n\n\\begin{align*}\n- (\\lambda  + \\mu )\\int\\limits_V {N_{i,j}^PN_{j,i}^KdV{u^K} + (\\lambda  + \\mu )\\int\\limits_S {N_i^PN_{j,i}^K{{\\hat n}_j}dS{u^K} - \\mu \\int\\limits_V {N_{i,k}^PN_{i,k}^KdV{u^K}} } } \\\\\n+ \\mu \\int\\limits_S {N_i^PN_{i,k}^K{{\\hat n}_k}dS{u^K}}  + \\int\\limits_V {N_i^P{f_i}dV = 0}\n\\end{align*}\n\nwhich can be written like;\n\n\n\\[{K^{PQ}}{U^Q} = {F^P}\\]\n\nwhere\n\n\\[{K^{PQ}} = (\\lambda  + \\mu )\\int\\limits_V {N_{i,j}^PN_{j,i}^QdV}  + \\mu \\int\\limits_V {N_{i,k}^PN_{i,k}^QdV} \\]\n\n\\[{F^P} = \\int\\limits_S {N_i^Pt_i^{(\\hat n)}dS + \\int\\limits_V {N_i^P{f_i}dV = 0} } \\]\n\n\\subsubsection*{Problem: Discretization of the acoustic wave equation.}\n\n\\[\\vec \\nabla  \\cdot \\left[ {\\frac{1}{\\rho }\\vec \\nabla p(\\vb{x})} \\right] - \\frac{\\partial }{{\\partial t}}\\left( {\\frac{1}{\\lambda }\\frac{{\\partial \\rho }}{{\\partial t}}} \\right) - q(\\vb{x}) = 0\\]\n\nwhere we recognize;\n\n\\[\\mathcal{L}() \\equiv \\vec \\nabla  \\cdot \\left( {\\frac{1}{\\rho }\\vec \\nabla } \\right) - \\frac{\\partial }{{\\partial t}}\\left( {\\frac{1}{\\lambda }\\frac{\\partial }{{\\partial t}}} \\right)\\]\n\nLet\n\n\\[p(x) = {N^K}{p^K}\\]\n\nthen\n\n\\[\\mathcal{L}(p) \\equiv \\vec \\nabla  \\cdot \\left( {\\frac{1}{\\rho }\\vec \\nabla {N^K}{p^K}} \\right) - \\frac{\\partial }{{\\partial t}}\\left( {\\frac{1}{\\lambda }\\frac{{\\partial {N^K}{p^K}}}{{\\partial t}}} \\right)\\]\n\nor in indicial notation\n\n\\[\\mathcal{L}(p) \\equiv {\\left( {\\frac{1}{\\rho }N_{,i}^K} \\right)_{,i}}{p^K} - \\frac{\\partial }{{\\partial t}}\\left( {\\frac{1}{\\lambda }\\frac{{\\partial {N^K}}}{{\\partial t}}} \\right){p^K}\\]\n\nwhich is equivalent to having;\n\n\\[\\mathcal{L}(p) \\equiv \\mathcal{L}({N^K}){p^K}\\]\n\nusing the trial functions as weighting functios and recalling the definition of the residual which in this case reads;\n\n\\[R = \\mathcal{L}({N^K}){p^K} - q\\]\n\nyields;\n\n\\[\\int\\limits_V {{N^J}RdV = 0} \\quad \\quad J=1,2,...,K \\]\n\n\\[\\int\\limits_V {{N^J}L({N^K})dV{p^K}}  - \\int\\limits_V {{N^J}qdV}  = 0\\]\n\n\\[\\int\\limits_V {{N^J}{{\\left( {\\frac{1}{\\rho }N_{,i}^K} \\right)}_{,i}}dV{p^K} - \\int\\limits_V {{N^J}\\frac{\\partial }{{\\partial t}}\\left( {\\frac{1}{\\lambda }\\frac{{\\partial {N^K}}}{{\\partial t}}} \\right)dV{p^K}} }  - \\int\\limits_V {{N^J}qdV}  = 0\\]\n\nIntegrating by parts the first term on the R.H.S gives us;\n\n\\[ - \\int\\limits_V {N_{,i}^J\\frac{1}{\\rho }N_{,i}^KdV} {p^K} + \\int\\limits_S {{N^J}\\frac{1}{\\rho }N_{,i}^K{{\\hat n}_i}dS{p^K}}  = \\int\\limits_V {{N^J}\\frac{\\partial }{{\\partial t}}\\left( {\\frac{1}{\\lambda }\\frac{{\\partial {N^K}}}{{\\partial t}}} \\right)dV{p^K}}  + \\int\\limits_V {{N^J}qdV} \\]\n\n\\[\\int\\limits_V {N_{,i}^J\\frac{1}{\\rho }N_{,i}^KdV} {p^K} + \\int\\limits_V {{N^J}\\frac{1}{\\lambda }{N^K}dV{{\\ddot p}^K}}  = \\int\\limits_S {{N^J}\\frac{1}{\\rho }N_{,i}^K{{\\hat n}_i}dS{p^K}}  + \\int\\limits_V {{N^J}qdV} \\]\n\n\\[{K^{JK}}{P^K} + {M^{JK}}{{\\ddot P}^K} + {f^J} = 0\\]\n\n\n\\section{A simple discrete system}\nThe simple problem of a spring-mass system considered next resembles most of the algorithmic aspects of a finite element code with the advantage that the problem is already a discrete mechanical system. The problem consists of an assemblage of masses joined by different springs submitted to time varying loads. Each spring plays the role of a finite element and each mass is analogous to a nodal point in a finite element algorithm. For instance the full system may be like the one shown in \\cref{fig:bathe}\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=10cm]{spring_system.pdf}\n\\caption{Typical assemblage of springs and masses.}\n\\label{fig:bathe}\n\\end{figure}\n\n\nConsider a typical spring (finite element) like the one shown in \\cref{fig:springel}\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=8cm]{springel.pdf}\n\\caption{Typical spring element.}\n\\label{fig:springel}\n\\end{figure}\n\nThe relation between the force and the relative displacement can be written like\n\\[f_1 = K(u_1 - u_2)\\]\nand from equilibrium we have\n\\[f_1 + f_2 = 0\\]\nwhich yields the following force-displacement relationship for a typical spring element:\n\\begin{equation}\n    \\begin{Bmatrix}\n        f_1\\\\\n        f_2\n    \\end{Bmatrix} =\n    K\\begin{bmatrix}\n          1.0 & -1.0\\\\\n        - 1.0 & 1.0\n    \\end{bmatrix}\n    \\begin{Bmatrix}\n        u_1\\\\\n        u_2\n    \\end{Bmatrix}\n    \\label{eq:Kspring}\n\\end{equation}\n\nOn the other hand, the equilibrium equation for a typical mass with displacement $u_j$  (see \\cref{fig:dclmass}) and attached to springs $i$ and $i+1$ reads\n\\begin{equation}\nf_2^i + f_1^{i + 1} + m_j \\dv{V_j}{t} = P_j.\n\\label{eq:equilmass}\n\\end{equation}\nwhich can be written in terms of displacements using \\cref{eq:Kspring} like\n\\[(K^i + K^{i + 1}) u_j - K^i u_{j - 1} - K^{i + 1} u_{j + 1} + m_j\\dv{V_j}{t} = P_j .\\]\n\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=8cm]{dcl_mass.pdf}\n\\caption{Free body diagram for a typical mass connected to springs $i$ and $i+1$.}\n\\label{fig:dclmass}\n\\end{figure}\n\n\nWriting the elemental equilibrium equations in terms of $u_{j - 1}$, $u_j$ and $u_{j + 1}$ we have:\n\n\\[\\left\\{ {\\begin{array}{*{20}{c}}\n{f_1^i}\\\\\n{f_2^i}\n\\end{array}} \\right\\} = \\left[ {\\begin{array}{*{20}{c}}\n{k_{11}^i}&{k_{12}^i}\\\\\n{k_{21}^i}&{k_{22}^i}\n\\end{array}} \\right]\\left\\{ {\\begin{array}{*{20}{c}}\n{{u_{j - 1}}}\\\\\n{{u_j}}\n\\end{array}} \\right\\}\\]\n\nand\n\n\\[\\left\\{ {\\begin{array}{*{20}{c}}\n{f_1^{i + 1}}\\\\\n{f_2^{i + 1}}\n\\end{array}} \\right\\} = \\left[ {\\begin{array}{*{20}{c}}\n{k_{11}^{i + 1}}&{k_{12}^{i + 1}}\\\\\n{k_{21}^{i + 1}}&{k_{22}^{i + 1}}\n\\end{array}} \\right]\\left\\{ {\\begin{array}{*{20}{c}}\n{{u_j}}\\\\\n{{u_{j + 1}}}\n\\end{array}} \\right\\}\\]\n\nwhich gives for the equilibrium equation of the $m_j$ mass:\n\n\\[k_{21}^i{u_{j - 1}} + (k_{22}^i + k_{11}^{i + 1}){u_j} + k_{12}^{i + 1}{u_{j + 1}} + {m_j}\\frac{{d{V_j}}}{{dt}} = {P_j}.\\]\n\nConsidering also the contributions from the springs $K^i$ and $K^{i+1}$ to the equilibrium of masses $m_{j-1}$ and $m_{j+1}$ respectively we have the following matrix block:\n\n\n\n\\[\\left[ {\\begin{array}{*{20}{c}}\n{}&{}&{}&{}\\\\\n{}&{k_{11}^i}&{k_{12}^i}&{}\\\\\n{}&{k_{21}^i}&{k_{22}^i + k_{11}^{i + 1}}&{k_{12}^{i + 1}}\\\\\n{}&{}&{k_{21}^{i + 1}}&{k_{22}^{i + 1}}\n\\end{array}} \\right]\\]\n\n\nConsidering now the complete system of masses and springs leads to a system of linear equations of the form\n\\begin{equation}\n\\left[ {{K_G}} \\right]\\left\\{ {{U_G}} \\right\\} + \\left[ M \\right]\\left\\{ {{A_G}} \\right\\} = \\left\\{ {{F_G}} \\right\\}.\n\\label{eq:global}\n\\end{equation}\nwhere each equation represents the equilibrium of a given mass. The coefficient matrix in \\cref{eq:global} can be assembled in a systematic way by establishing the connection between the global and local degrees of freedom. This can be accomplished through an operator storing in each row the global degrees of freedom corresponding to each element. For instance, \\cref{fig:IBC} shows elements $K^i$ and $K^{i+1}$ and the global degrees of freedom corresponding to masses $m_{j-1}$, $m_j$ and $m_{j+1}$. The corresponding entries of the $DME$ operator for these elements are given by:\n\n\n\\[DME = \\left[ {\\begin{array}{*{20}{c}}\n{}&{}\\\\\n{j - 1}&j\\\\\nj&{j + 1}\\\\\n{}&{}\n\\end{array}} \\right]\\]\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=12cm]{ibc}\n\\caption{Global degrees of freedom connected to the spring elements $K^i$ and $K^{i+1}$ respectively.}\n\\label{fig:IBC}\n\\end{figure}\n\nand the contribution from these elements to the global coefficient matrix for elements $i$ and $i+1$ reads respectively:\n\n\n\\[\\begin{array}{l}\n{K_{j - 1,j - 1}} \\leftarrow {K_{j - 1,j - 1}} + k_{11}^i\\\\\n{K_{j - 1,j}} \\leftarrow {K_{j - 1,j}} + k_{12}^i\\\\\n{K_{j,j - 1}} \\leftarrow {K_{j,j - 1}} + k_{21}^i\\\\\n{K_{j,j}} \\leftarrow {K_{j,j}} + k_{22}^i\n\\end{array}\\]\n\nand\n\n\\[\\begin{array}{l}\n{K_{j,j}} \\leftarrow {K_{j,j}} + k_{11}^{i + 1}\\\\\n{K_{j,j + 1}} \\leftarrow {K_{j,j + 1}} + k_{12}^{i + 1}\\\\\n{K_{j + 1,j}} \\leftarrow {K_{j + 1,j}} + k_{21}^{i + 1}\\\\\n{K_{j + 1,j + 1}} \\leftarrow {K_{j + 1,j + 1}} + k_{22}^{i + 1}\n\\end{array}\\]\n\nThe system given by \\cref{eq:global}, assembled with the aid of the $DME$ operator can be solved for the global displacements $U_G$. The pseudo-code shown in \\cref{algo:springs} presents all the steps required to solve the problem in the context of the finite element method. In that code the so-called DME operator is an equation assembly array indicating how each element contributes to the global stiffness and mass matrix.\n\n\\begin{algorithm}[H]\\label{algo:springs}\n    \\SetAlgoLined\n    \\KwData{Problem parameters; NUMNP, NUMEL, NMATP}\n    \\KwResult{Displacements and spring forces}\n    Create $DM$E operator\\;\n    Assemble $K^G$, $F^G$\\;\n    \\While{$j \\leq 1, NUMEL$}{\n        $K^G \\leftarrow K^G+K^i$\\\\\n        $F^G \\leftarrow F^G+F^i$\\\\\n    }\n    Solve $[K^G]U=F^G$\\\\\n    Find internal forces\n    \\caption{Springs Algorithm.}    \n\\end{algorithm}\n\n\\newpage\n\n\\inputminted[]{python}{src/engine.py}\n\n\\newpage\n\n\n\\section{Basic elements of interpolation theory}\nLet $f(x)$ be a function whose values are known at n discrete points ${x_1, x_2,...,x_n}$. We want to know (interpolate) the value of $f(x)$ at an arbitrary point $x \\in \\left[ {{x_1},{x_n}} \\right]$.\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=12cm]{img/interpol1.pdf}\n\\caption{Global interpolation of a function}\n\\label{fig:interpol1}\n\\end{figure}\n\nThe process of interpolation or computation of the unknown value of $f(x)$ using the known values $\\left\\{ {{f^1},{f^2},...,{f^n}} \\right\\}$ involves two steps:\n\n\\begin{itemize}\n\\item[i]  Fitting an interpolating function to the known data points.\n\\item[ii] Evaluating the function at the arbitrary point.\n\\end{itemize}\n\nWe can (i) use all the n-data points and fit an $(n-1)$-th order polynomial (which is cumbersome and difficult to code) or (ii) split the domain in sub-intervals and use local polynomials within each sub-interval. This last approach involves only a couple of polynomials and it is easy to code, however it may have some continuity issues.\n\nIn finite element analysis local interpolation is used in order to proceed systematically. Local interpolation uses a finite number of nearest-neighbors and generates interpolated values $f(x)$ that do not in general have continuous first or higher derivatives.\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=12cm]{img/interpol2.pdf}\n\\caption{Local or piecewise interpolation of a function}\n\\label{fig:interpol2}\n\\end{figure}\n\n\\subsubsection{Lagrange interpolation theorem}\nGiven a set of n-points $\\{ (x^1, y^1),\\cdots,(x^n, y^n)\\}$ where $y^n \\equiv f({x^n})$ then: ``there exists a unique polynomial $p(x)$ of order at most $(n-1)$ such $p(x^I) = f(x^I)$ for $I=1,2,\\cdots,n$\". The polynomial is given by;\n\\begin{equation}\\label{eq:pol}\n  p(x^I) = L^I(x) f(x^I)  \n\\end{equation}\nfor $I=1,2,...,n$ where\n\\begin{equation}\\label{eq:coef}\n  L^I(x) = \\prod_{\\substack{J = 1\\\\ I \\ne J}}^n \\frac{(x - x^J)}{(x^I - x^J)}\n\\end{equation}\nand where it should be noticed that\n\\[L^I(x^J) = \\delta^{IJ}.\\]\n\n\\subsubsection*{Example for n=3}\nConsider the domain $[ - 1,1]$ and the data points at ${x^1} =  - 1.0$, ${x^2} =  + 1.0$ and ${x^3} = 0.0$. We have\n\\begin{align*}\n& L^1(x) = \\frac{(x - x^2)(x - x^3)}{(x^1 - x^2)(x^1-x^3)} \\equiv  - \\frac{1}{2}(1 - )x\\\\\n& L^2(x) = \\frac{(x - x^1)(x - x^3)}{(x^2 - x^1)(x^2 - x^3)} \\equiv  + \\frac{1}{2}(1 + x)x\n\\end{align*}\nand\n\\[L^3(x) = \\frac{(x - x^1)(x - x^2)}{(x^3 - x^1)(x^3 - x^2)} \\equiv 1 - x^2.\\]\n\nThe resulting interpolating polynomials $L^I(x)$ and the interpolating function  are shown in \\cref{fig:pols} below\n\\begin{figure}[H]\n  \\centering\n  \\includegraphics[width=16cm]{func.pdf}\n  \\caption{Interpolating polynomials and the resulting interpolating function}\n  \\label{fig:pols}\n\\end{figure}\n\n\\subsubsection*{Example: Interpolation of a function using a global and a local scheme}\nAssume we have known values of the function:\n\n\\[f(x) = {x^3} + 4{x^2} - 10\\]\n\nin the interval $[-1.0, 1.0]$ and we wish to obtain an interpolated version of the function using different schemes.\n\n\n\\begin{figure}[H]\n\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{lineal.pdf}\n\t\t\\caption{Interpolation polynomials. }\n\t\\end{subfigure}\\,\n%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{interlin.pdf}\n\t\t\\caption{Actual and interpolated function.}\n\t\\end{subfigure}\\\\\n%\n\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{quadra.pdf}\n\t\t\\caption{Interpolation polynomials.}\n\t\\end{subfigure}\\,\n%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{interqua.pdf}\n\t\t\\caption{Actual and interpolated function.}\n\t\\end{subfigure}\\\\\n%\n\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{third.pdf}\n\t\t\\caption{Interpolation polynomials.}\n\t\\end{subfigure}\\,\n%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{intertri.pdf}\n\t\t\\caption{Actual and interpolated function.}\n\t\\end{subfigure}\n\\caption{Lineal interpolation of the function $f(x) = {x^3} + 4{x^2} - 10$.}\n\\label{fig:several interpol}\n\\end{figure}\n\n\\Cref{fig:several interpol} shows the interpolating polynomials and the resulting function for the case of first, second and fourth order polynomials respectively. Similarly, the first order derivative obtained out of the interpolated function is displayed in \\cref{fig:first der}. \n\n\\begin{figure}[H]\n\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{deriv2.pdf}\n\t\t\\caption{First order derivatives of the interpolation polynomials. }\n\t\\end{subfigure}\\,\n%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{firstder.pdf}\n\t\t\\caption{Interpolated first order derivative of the function.}\n\t\\end{subfigure}\\\\\n\n\\caption{Lineal interpolation of the function $f(x) = {x^3} + 4{x^2} - 10$.}\n\\label{fig:first der}\n\\end{figure}\n\nWe now proceed like in the finite element method and use the local first order polynomials shown in \\cref{fig:loc-pols} to interpolate the function under study.\n\n\\begin{figure}[H]\n  \\centering\n  \\includegraphics[width=10cm]{localone.pdf}\n  \\caption{Local interpolating polynomials}\n  \\label{fig:loc-pols}\n\\end{figure}\n\nThe resulting function and its numerically obtained first order derivateive are shown in \\cref{fig:fully local}. It is clear how the local interpolation destroys the global continuity in the first order derivative while the function itself remains continous.\n\n\n\\begin{figure}[H]\n\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{localfun.pdf}\n\t\t\\caption{Function interpolated with local first order polynomials. }\n\t\\end{subfigure}\\,\n%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{localfirst.pdf}\n\t\t\\caption{Interpolated first order derivative of the function.}\n\t\\end{subfigure}\\\\\n\n\\caption{Lineal interpolation of the function $f(x) = {x^3} + 4{x^2} - 10$.}\n\\label{fig:fully local}\n\\end{figure}\n\n\\subsection*{Extension to 2D domains}\nAssume we are now interested in conducting interpolation of a function over a spatial 2-dimensional domain where every point is specified by a position vector of the form $\\vb{x} = x \\hat{\\imath} + y\\hat{\\jmath}$. We want to know, via interpolation, the value of a function $f(\\vb{x})$ at an arbitrary point $\\vb{x}$ provided we know the set of n-points $\\{(\\vb{x}^1, f^1),\\cdots,(\\vb{x}^n, f^n)\\}$.\n\\begin{figure}[H]\\label{fig:element}\n  \\centering\n  \\includegraphics[width=10cm]{element.pdf}\n  \\caption{Basic square domain}\n\\end{figure}\n\nWe first fix $x = x^A$ and conduct 1-dimensional interpolation along the $y$ direction as discussed in the previous section as follows (see \\cref{fig:onedimn})\n\\[f(x^A,y) = L^1(y)f^1 + L^4(y)f^4\\]\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=10cm]{inter1D.pdf}\n\\caption{Interpolation along the $y$-direction}\n\\label{fig:onedimn}\n\\end{figure}\n\nSimilarly, we can fix $x = x^B$ and interpolate once again along the $y$ direction\n\\[f(x^B,y) = L^2(y)f^2 + L^3(y)f^3.\\]\n\nWe now conduct the interpolation along the $x$-direction using the functions $f(x^A,y)$ and $f(x^B,y)$ respectively as follows\n\\begin{align*}\n  &f(x,y) = L^A(x) f(x^A,y) + L^B(x)f(x^B,y)\\\\\n  &f(x,y) = L^A(x)\\{L^1(y)f^1 + L^4(y)f^4\\} + L^B(x)\\{L^2(y)f^2 + L^3(y)f^3\\}\\\\\n  &f(x,y) = L^A(x)L^1(y)f^1 + L^A(x)L^4(y)f^4 + L^B(x)L^2(y)f^2 + L^B(x)L^3(y)f^3 \\enspace ,\n\\end{align*}\nwhere\n\\begin{align*}\nL^A(x) & \\equiv L^1(x)\\\\\nL^B(x) & \\equiv L^2(x)\\\\\nL^1(y) & \\equiv L^1(y)\\\\\nL^2(y) & \\equiv L^1(y)\\\\\nL^3(y) & \\equiv L^2(y)\\\\\nL^4(y) & \\equiv L^2(x) \\enspace .\n\\end{align*}\n\nThe function of two variables is then written as the product of one-dimensional interpolations\n\\[f(x,y) = N^1(x,y)f^1 + N^2(x,y)f^2 + N^3(x,y)f^3 + N^4(x,y)f^4\\]\nwith\n\\begin{align*}\nN^1(x,y) & = L^1(x)L^1(y)\\\\\nN^2(x,y) & = L^2(x)L^1(y)\\\\\nN^3(x,y) & = L^2(x)L^2(y)\\\\\nN^4(x,y) & = L^1(x)L^2(y) \\enspace .\n\\end{align*}\n\nSee Figure \\ref{fig:four-nodes-interp} for the shape functions of a 4-nodes element.\n\\begin{figure}[H]\n\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{shape_func-4-nodes-1.pdf}\n\t\t\\caption{Shape function ${N^1(x,y)=\\frac{1}{4}(1-x)(1-y)}$. }\n\t\\end{subfigure}\\,\n%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{shape_func-4-nodes-2.pdf}\n\t\t\\caption{Shape function ${N^2(x,y)=\\frac{1}{4}(1+x)(1-y)}$.}\n\t\\end{subfigure}\\\\\n%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{shape_func-4-nodes-3.pdf}\n\t\t\\caption{Shape function ${N^3(x,y)=\\frac{1}{4}(1+x)(1+y)}$.}\n\t\\end{subfigure}\\,\n%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{shape_func-4-nodes-4.pdf}\n\t\t\\caption{Shape function ${N^4(x,y)=\\frac{1}{4}(1-x)(1+y)}$.}\n\t\\end{subfigure}\n\\caption{Shape functions for a 4-nodes element.}\n\\label{fig:four-nodes-interp}\n\\end{figure}\n\nSee Figure \\ref{fig:nine-nodes-interp} for the shape functions of a 9-nodes element.\n\\begin{figure}[H]\n\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-1.pdf}\n\t\t\\caption{Shape function $N^1(x,y)$. }\n\t\\end{subfigure}\\,\n%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-2.pdf}\n\t\t\\caption{Shape function $N^2(x,y)$.}\n\t\\end{subfigure}\\\\\n%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-3.pdf}\n\t\t\\caption{Shape function $N^3(x,y)$.}\n\t\\end{subfigure}\\,\n%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-4.pdf}\n\t\t\\caption{Shape function $N^4(x,y)$.}\n\t\\end{subfigure}\\\\\n\t%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-5.pdf}\n\t\t\\caption{Shape function $N^5(x,y)$.}\n\t\\end{subfigure}\\,\n%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-6.pdf}\n\t\t\\caption{Shape function $N^6(x,y)$.}\n\t\\end{subfigure}\n\t\\caption{Shape functions for a 9-nodes element.}\n\t\\label{fig:nine-nodes-interp}\n\\end{figure}\n%\n\\begin{figure} [H]\n\t\\ContinuedFloat\n\t\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-7.pdf}\n\t\t\\caption{Shape function $N^7(x,y)$.}\n\t\\end{subfigure}\\,\n%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-8.pdf}\n\t\t\\caption{Shape function $N^8(x,y)$.}\n\t\\end{subfigure}\\\\\n\t%\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\n\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-9.pdf}\n\t\t\\caption{Shape function $N^9(x,y)$.}\n\t\\end{subfigure}\n\\caption{Shape functions for a 9-nodes element. (Continued)}\n\\end{figure}\n\n\\section[Discretization of the PVW using FEM]{Discretization of the PVW via the FEM}\n\\subsection{Formulation of the finite element matrices}\nWe now discretize the principle of virtual work repeated below for completeness:\n\\begin{equation} \\label{pvw_2}\n\\intL_V \\sigma_{ij} \\delta u_{i,j} \\dd{V} - \\intL_V f_i \\delta u_i \\dd{V} - \\intL_{S_t} t_i^n \\delta u_i \\dd{S} = 0.\n\\end{equation}\n\nFor that purpose we will divide the complete domain $V$ into $N$-finite non-overlapping sub-domains over each one of which we will approximate the solution in terms of local interpolating functions (see \\cref{fig:fully local}). Since the PVW (or weak form of the BVP) has been cast into an integral representation, it is possible to build the total integral considering the contribution of the $N$-sub-domains like:\n\\begin{equation}\\label{pvw_dis}\n\\sum_{e=1}^{NEL} \\intL_{V^e} \\sigma_{ij} \\var{u}_{i,j} \\dd{V^e} - \\intL_V f_i \\var{u}_i \\dd{V^e} - \\intL_{S_t} t_i^n \\var{u}_i\\dd{S^e} = 0 \n\\end{equation}\n\nFor simplicity we consider only a single element or sub-domain, thus;\n\n\\begin{equation}\\label{pvw_sing}\n\\intL_V \\sigma_{ij} \\delta\\epsilon_{i,j} dV - \\intL_V f_i\\delta u_idV - \\intL_{S_t} t_i^n \\delta u_i dS = 0\n\\end{equation}\n\nwhere it is assumed that the discretized version of each element is later added up (or assembled) into the global equations for the complete model and where we have already used the fact that $\\sigma_{ij}$ is symmetric impliying that $\\sigma_{ij} \\delta u_{i,j} = \\sigma_{ij} \\delta\\epsilon_{i,j}$.\n\nThe involved functions (e.g., displacements, strain, stresses) will be approximated via interpolation of the solution over a determined number of points termed in what follows nodes. Assume for instance that over element $e$ containing $n$ such nodes we know the displacements vector $u_i$. For instance, \\cref{fig:simple element} below shows a typical square 4-noded element of side $2h$. The rectangular components of the displacement vector at each node are labeled like $[u_1, u_2,...,u_7, u_8]$.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=7cm]{lado2h.pdf}\n\\caption{Square element of side $2h$.}\n\\label{fig:simple element}\n\\end{figure}\n\n\nFurthermore, in a more general treatment, we let the displacements for an arbitrary $p$-node of a $3D$ problem $u^P=[u^P, v^P, w^P]$. Using ideas from interpolation theory it is now possible to approximate the displacements vector over an arbitrary point $\\vb{x}$ inside the element by;\n\n\\[u_i(\\vb x) = N_i^1(\\vb x)u^1 + N_i^2(\\vb x)u^2 + \\cdots + N_i^P(\\vb x)u^P + \\cdots + N_i^n(\\vb x)u^n\\]\n\nor in more general form\n\n\\begin{equation} \\label{bas_interpol}\n{u_i}(\\vb x) = N_i^Q(\\vb x){u^Q}\n\\end{equation}\n\nand where the caption superscripts indicate summation over the number of nodes of the element while the subscript refers to the physical character of the variable being interpolated.\n\nNow let us use the kinematic relationshio between strains and displpacements:\n\n\\[ \\varepsilon_{ij}(\\vb x) = \\frac{1}{2}( u_{i,j} + u_{j,i} ) \\]\n\ntogether with \\cref{bas_interpol}. Carrying the derivatives into the shape functions yields;\n\n\\[ \\varepsilon_{ij}(\\vb x) = \\frac{1}{2}\\left(\\pdv{N_i^Q}{x_j} + \\pdv{N_j^Q}{x_i} \\right){u^Q} \\]\n\nwhich can be written like\n\n\\begin{equation}\n\\varepsilon_{ij}(\\vb x) = B_{ij}^Q(\\vb x){u^Q}\n\\label{str-dis}\n\\end{equation}\n\nafter letting\n\n\\[ B_{ij}^Q = \\frac{1}{2}\\left(\\pdv{N_i^Q}{x_j} + \\pdv{N_j^Q}{x_i} \\right). \\]\n\nProceeding analogously for the virtual fields after using\n\\[ \\delta {u_i} = N_i^Q(\\vb x)\\delta {u^Q} \\]\ngives us:\n\\[ \\intL_V C_{ijkl} B_{kl}^P u^P B_{ij}^Q\\delta u^Q \\dd{V} - \\intL_V f_i N_i^Q\\delta {u^Q}\\dd{V}  - \\intL_{S_t} t_i^n N_i^Q\\delta {u^Q} \\dd{S} = 0 \\]\nwhich can be re-organized into\n\\[ \\delta {u^Q}\\intL_V B_{ij}^Q C_{ijkl} B_{kl}^P\\dd{V}{u^P} - \\delta {u^Q}\\intL_V N_i^Q{f_i}\\dd{V}  - \\delta {u^Q}\\intL_{S_t} N_i^Qt_i^n\\dd{S} = 0\\]\nwhich is the generalized discrete version of the PVW for a single element consistent with \\cref{pvw_sing}. Defining the terms corresponding to the integrals like:\n\\begin{equation}\n\\begin{aligned}\n{K^{QP}} & = \\int\\limits_V {{C_{ijkl}}B_{kl}^PB_{ij}^QdV} \\\\\nf_c^Q    & = \\int\\limits_S {N_i^Qt_i^ndS} \\\\\nf_V^Q    & = \\int\\limits_V {N_i^Q{f_i}dV}\n\\label{Rigi_3}\n\\end{aligned}\n\\end{equation}\n\n\nallows us to write:\n\n\n\\[ \\delta u^Q f_\\sigma ^Q - \\delta {u^Q}f_V^Q - \\delta u^Q f_c^Q = 0. \\]\n\nThis equation is once again the generalized discrete version of the PVW corresponding to the $Q$-displacement degree of freedom. The equation quantifies the work of the forces along the $Q$-th degree of freedom over the virtual displacements $\\delta u^Q$. If we now use the arbitrary character of the virtual field $\\delta u^Q $ we can write;\n\n\\begin{equation}\nf_\\sigma ^Q - f_V^Q - f_c^Q = 0.\n\\label{forces}\n\\end{equation}\n\nThis is now a mechanical equilibrium equation relating the forces along the $Q$-th degree of freedom associated to the internal element stresses $f_\\sigma ^Q$; the external body forces $f_V^Q$ and the applied external tractions $f_c^Q$. Introducing the stiffness of the element gives:\n\n\\begin{equation}\nK^{QP} u^P = f_V^Q + f_c^Q.\n\\label{Discreta}\n\\end{equation}\n\n\\subsubsection{Formulation of the stiffness matrix in perfectly square elements}\nIn the previous section we recognized:\n\n\\begin{equation}\n\\begin{aligned}\n{K^{QP}} & = \\int\\limits_V {{C_{ijkl}}B_{kl}^PB_{ij}^QdV} \\\\\nf_c^Q    & = \\int\\limits_S {N_i^Qt_i^ndS} \\\\\nf_V^Q    & = \\int\\limits_V {N_i^Q{f_i}dV}\n\\label{Rigi}\n\\end{aligned}\n\\end{equation}\n\n\n\nas the elemental stiffness matrix and the vectors of consistent contact and body forces for a single element. Let us assume that the domain of the single element is a perfect square of side $2h$ (see \\cref{fig:lado2h}), thus;\n\n\\begin{equation}\n\\begin{aligned}\nK & = \\int\\limits_{ - h}^{ + h} {\\int\\limits_{ - h}^{ + h} {{B^T}CBdxdy} } \\\\\n{f_c} & = \\int\\limits_{ - h}^{ + h} {{N^T}{t^n}ds} \\\\\n{f_v} & = \\int\\limits_{ - h}^{ + h} {\\int\\limits_{ - h}^{ + h} {{N^T}fdxdy} }\n\\label{ele2}\n\\end{aligned}\n\\end{equation}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=7cm]{lado2h.pdf}\n\\caption{Square element of side $2h$.}\n\\label{fig:lado2h}\n\\end{figure}\n\n\nand where $N$ and $B$ are the displacements interpolation matrix and the strain-displacements interpolation matrix respectively. For the linear 4-noded element shown in \\cref{fig:lado2h} these matrices have the form defined in the following interpolation equations:\n\n\n\\[\\left\\{ {\\begin{array}{*{20}{c}}\n{u(\\vec x)}\\\\\n{v(\\vec x)}\n\\end{array}} \\right\\} = \\left[ {\\begin{array}{*{20}{c}}\n{{N^1}(\\vec x)}&0&{{N^2}(\\vec x)}&0&{{N^3}(\\vec x)}&0&{{N^4}(\\vec x)}&0\\\\\n0&{{N^1}(\\vec x)}&0&{{N^2}(\\vec x)}&0&{{N^3}(\\vec x)}&0&{{N^4}(\\vec x)}\n\\end{array}} \\right]\\left\\{ {\\begin{array}{*{20}{c}}\n{{u^1}}\\\\\n{{u^2}}\\\\\n{{u^3}}\\\\\n{{u^4}}\\\\\n{{u^5}}\\\\\n{{u^6}}\\\\\n{{u^7}}\\\\\n{{u^8}}\n\\end{array}} \\right\\}\\]\n\n\n\\[\\left\\{ {\\begin{array}{*{20}{c}}\n{\\frac{{\\partial u}}{{\\partial x}}}\\\\\n{\\frac{{\\partial v}}{{\\partial y}}}\\\\\n{\\frac{{\\partial v}}{{\\partial x}} + \\frac{{\\partial u}}{{\\partial y}}}\n\\end{array}} \\right\\} = \\left[ {\\begin{array}{*{20}{c}}\n{\\frac{{\\partial {N^1}(\\vec x)}}{{\\partial x}}}&0&{\\frac{{\\partial {N^2}(\\vec x)}}{{\\partial x}}}&0&{\\frac{{\\partial {N^3}(\\vec x)}}{{\\partial x}}}&0&{\\frac{{\\partial {N^4}(\\vec x)}}{{\\partial x}}}&0\\\\\n0&{\\frac{{\\partial {N^1}(\\vec x)}}{{\\partial y}}}&0&{\\frac{{\\partial {N^2}(\\vec x)}}{{\\partial y}}}&0&{\\frac{{\\partial {N^3}(\\vec x)}}{{\\partial x}}}&0&{\\frac{{\\partial {N^4}(\\vec x)}}{{\\partial x}}}\\\\\n{\\frac{{\\partial {N^1}(\\vec x)}}{{\\partial x}}}&{\\frac{{\\partial {N^1}(\\vec x)}}{{\\partial y}}}&{\\frac{{\\partial {N^2}(\\vec x)}}{{\\partial x}}}&{\\frac{{\\partial {N^2}(\\vec x)}}{{\\partial y}}}&{\\frac{{\\partial {N^3}(\\vec x)}}{{\\partial x}}}&{\\frac{{\\partial {N^3}(\\vec x)}}{{\\partial y}}}&{\\frac{{\\partial {N^4}(\\vec x)}}{{\\partial x}}}&{\\frac{{\\partial {N^4}(\\vec x)}}{{\\partial y}}}\n\\end{array}} \\right]\\left\\{ {\\begin{array}{*{20}{c}}\n{{u^1}}\\\\\n{{u^2}}\\\\\n{{u^3}}\\\\\n{{u^4}}\\\\\n{{u^5}}\\\\\n{{u^6}}\\\\\n{{u^7}}\\\\\n{{u^8}}\n\\end{array}} \\right\\}\\]\n\nwith the independent shape functions being:\n\n\n\\begin{align*}\n{N^1}(x) & = \\frac{1}{4}(1 - x)(1 - y) \\\\\n{N^2}(x) & = \\frac{1}{4}(1 + x)(1 - y) \\\\\n{N^3}(x) & = \\frac{1}{4}(1 + x)(1 + y) \\\\\n{N^4}(x) & = \\frac{1}{4}(1 - x)(1 + y)\n\\end{align*}\n\n\n\n\nNotice that in the computation of the stiffness matrix we actually require the spatial derivatives of the shape functions given by;\n\n\\begin{align*}\n\\frac{{\\partial {N^1}(x)}}{{\\partial x}} & =  - \\frac{1}{4}(1 - y)           &  \\frac{{\\partial {N^1}(x)}}{{\\partial y}} & =  - \\frac{1}{4}(1 - x)\\\\\n\\frac{{\\partial {N^2}(x)}}{{\\partial x}} & =  + \\frac{1}{4}(1 - y)           &  \\frac{{\\partial {N^2}(x)}}{{\\partial y}} & =  - \\frac{1}{4}(1 + x)\\\\\n\\frac{{\\partial {N^3}(x)}}{{\\partial x}} & =  + \\frac{1}{4}(1 + y)           &  \\frac{{\\partial {N^3}(x)}}{{\\partial y}} & =  + \\frac{1}{4}(1 + x)\\\\\n\\frac{{\\partial {N^4}(x)}}{{\\partial x}} & =  - \\frac{1}{4}(1 + y)           &  \\frac{{\\partial {N^4}(x)}}{{\\partial y}} & =  + \\frac{1}{4}(1 - y)\n\\end{align*}\n\n\nThe contribution to the element matrix from a typical nodal point is thus given by;\n\n\n\n\\[K = \\int\\limits_{ - h}^{ + h} {\\int\\limits_{ - h}^{ + a} {\\begin{bmatrix}\n\n \\vdots &  \\vdots & \\vdots &  \\vdots & \\vdots & \\vdots \\\\\n \\cdots &  \\frac{{\\partial {N^K}(x)}}{{\\partial x}} & 0   & \\frac{{\\partial {N^K}(x)}}{{\\partial y}} &  \\cdots & \\cdots \\\\\n  \\cdots &  0 & \\frac{{\\partial {N^K}(x)}}{{\\partial y}}   & \\frac{{\\partial {N^K}(x)}}{{\\partial x}} &  \\cdots & \\cdots \\\\\n \\vdots &  \\vdots & \\vdots &  \\vdots & \\vdots & \\vdots \n\n\\end{bmatrix}\n%\n\\begin{bmatrix}\n A & B &  0\\\\\n B & A & 0 \\\\\n 0 &  0 & C\n\\end{bmatrix}\n%\n\\begin{bmatrix}\n \\cdots & \\frac{{\\partial {N^Q}(x)}}{{\\partial x}} & 0  & \\cdots \\\\\n \\cdots & 0 & \\frac{{\\partial {N^Q}(x)}}{{\\partial y}}  & \\cdots \\\\\n \\cdots & \\frac{{\\partial {N^Q}(x)}}{{\\partial y}} & \\frac{{\\partial {N^Q}(x)}}{{\\partial x}}  & \\cdots \n\\end{bmatrix} dxdy} } \\]\n\n\nwhile a typical element of the resultant stiffness matrix takes the general form:\n\\[K \\equiv A\\int\\limits_{- h}^{ + h} \\int\\limits_{-h}^{+h} \\pdv{N^K}{x}\\pdv{N^Q}{x}\\dd{x}\\dd{y}  + C\\int\\limits_{-h}^{+h} \\int\\limits_{-h}^{+h}\\pdv{N^K}{y}\\pdv{N^Q}{x}\\dd{x}\\dd{y}.\\]\nIt should be noticed that for the considered perfectly square element the resulting stiffness matrix can be partitioned into factors which depend upon the material properties only and into a single factor which depends on the size $h$. This last contribution can be obtained analytically.\n\nOnce the elemental matrices are obtained these are assembled into the final global system of equations. Details of the assembly process are discussed in \\autoref{chap: Computational Aspects}. The following Python script computes the stiffness matrix for the 4-noded element.\n\n\\inputminted[]{python}{src/stiff_4nodes.py}\n\n\\subsubsection{Formulation of the stiffness matrix for distorted elements: the continuum mechanics analogy}\nIn typical finite element equilibrium equations we need to perform integration over the reference element domain $V_0(\\vb{x})$ corresponding to originally arbitrarily shaped sub-domains as created during the meshing process.  In order to proceed with this integration it is useful to consider the following continuum mechanics analogy.\n\nFirst assume that the actual physical domain $V_0(\\vb{x})$ is the result of a deformation process imparted upon the natural domain as shown in \\cref{fig:natural domain}. In this analogy, the physical domain $V_0(\\vb{x})$ is regarded like a ``deformed'' configuration at an imaginary time $t=t$, while the natural ``undeformed'' domain $V(\\vb{r})$   is treated like a reference undeformed configurations at time $t=0$. Both configurations are assumed to be connected through a deformation process\n\\begin{equation}\n\\begin{aligned}\n\\vb{X}&=\\vb{X}(\\vb{r})\\\\\n\\vb{r}&=\\vb{r}(\\vb{X})\n\\end{aligned}\n\\label{eq:motion}\n\\end{equation}\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=8cm]{figure1.pdf}\n\\caption{Definition of the natural domain}\n\\label{fig:natural domain}\n\\end{figure} \n\nIn \\cref{eq:motion} we can understand $\\vb{r}$ like a material (Lagrangian) variable and $\\vb{X}$ like a spatial (or Eulerian) variable. Using the continuum mechanics analogy it is clear that the ``deformation'' process at the continuum level is fully characterized by the ``deformation'' gradient or Jacobian of the transformation \\cref{eq:motion} and defined according to\n\\begin{equation}\n\\dd{X}_i=\\pdv{X_i}{r_J}\\dd{r}_J\\equiv J_{iJ}\\dd{r}_{J}\n\\label{eq:gradient}\n\\end{equation}\nwhere $\\dd{r}_{J}$ and $\\dd{X}_i$ represent material vectors in the original and deformed configuration. From \\cref{eq:gradient} it is evident that the Jacobian contains all the information describing the change of the physical sub-domain with respect to the natural element. For the element integration process we will assume that every element $V(\\vb{r})$ in the natural domain deforms into the physical element $V_0(\\vb{X})$, thus allowing us to write typical terms like the ones in the material stiffness matrix\n\\begin{equation}\n\\intL_{V(\\vb{X})} \\hat{B}_{ij}^K(\\vb{X}) C_{ijkl} \\hat{B}_{kl}^P(\\vb{X}) dV(\\vb{X})\\equiv \\intL_{V_0(\\vb{r})} \\hat{B}_{ij}^K(\\vb{r}) C_{ijkl} \\hat{B}_{kl}^P(\\vb{r})J dV_0(\\vb{r})\n\\label{eq:matmatrix}\n\\end{equation}\nwhere we have used $dV(\\vb{X})=JdV(\\vb{r})$, with $J$ being the determinant of the deformation gradient and in general we transform functions between the natural and physical space making use of \\cref{eq:motion} according to\n\\begin{equation}\nf(\\vb{r})=F[\\vb{X}(\\vb{r})]\n\\label{eq:funtrans}\n\\end{equation}\n\n\n\\subsubsection*{Interpolation scheme}\nHaving identified the fact that the integration process will take place in the natural domain, we will approach the interpolation process directly in this natural space. In the case of the displacement based finite element method all the involved variables will then be obtained via interpolation of nodal displacements. For instance, assume that a given problem variable is defined in the physical space by the tensor $\\Phi_{ik...p}(\\vb{X})$. The interpolated variable is then written like;\n\n\\begin{equation}\n\\Phi_{ij...p}(\\vb{X})=H_{ij...p}^K(\\vb{r})\\hat{u}^K\n\\label{eq:interpol}\n\\end{equation}\n\nwhere $\\hat{u}^K$ represents a vector of nodal points displacements, see \\cref{fig:interpol nat dom}, and $H_{ij...p}^K(\\vb{r})$ is an interpolator which keeps the tensorial character of the original physical variable $\\Phi_{ik...p}(\\vb{X})$ and where the super-index makes reference to a nodal identifier (with the summation convention in place).\n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=4cm]{figure2.pdf}\n\\caption{General interpolation strategy in the natural domain}\n\\label{fig:interpol nat dom}\n\\end{figure}\n \n\n\nSince the primary variable corresponds to displacements it must be kept in mind that $H_{ij...p}^K(\\vb{r})$ corresponds to combinations of derivatives (or other arbitrary combinations) of the basic element shape functions defined in;\n\n\n\\begin{equation}\nu_i(\\vb{X})=N_i^K(\\vb{r})\\hat{u}^K\n\\label{eq:el interpol}\n\\end{equation}\n\n\n\nFor the general interpolation process we need two kinds of transformations.  First we need to transform integrals over the physical space into integrals into the natural space which corresponds to\n\\begin{equation}\n\\intL_{V(\\vb{X})} F(\\vb{X})dV(\\vb{X})\\equiv \\intL_{V_0(\\vb{r})} f(\\vb{r})J dV_0(\\vb{r})\n\\label{gen trans}\n\\end{equation}\n\n\n\nSecond we need to relate spatial differentiation in both, the physical and spatial domains.  Let us define these operators like $\\nabla_i^X$ and $\\nabla_I^r$ respectively. It then follows from \\cref{eq:funtrans} that\n\\begin{equation}\n\\dfrac{\\partial F}{\\partial X_i}=\\dfrac{\\partial f}{\\partial r_J}\\dfrac{\\partial r_J}{\\partial X_i}\n\\label{eq:chain}\n\\end{equation}\nfrom where we can establish the connection between the two operators like\n\n\n\\begin{equation}\n\\nabla_i^X=J_{iJ}^{-1}\\nabla_J^r\n\\label{eq:fundamental}\n\\end{equation}\n\n\n\\subsubsection*{The fundamental interpolator}\nWe further define the fundamental interpolator giving rise to gradients of the primary displacement variable in the physical space according to\n\\begin{equation}\nu_{i,j}(\\vb{X})=L_{ij}^K(\\vb{r})\\hat{u}^K\n\\label{eq:fund operator}\n\\end{equation}\n\n\nThis fundamental interpolator  $L_{ik}^K(\\vb{r})$ is derived after using \\cref{eq:el interpol} and \\cref{eq:fundamental} in the physical displacement gradient definition as shown next\n\\begin{align*}\nu_{i,j}(\\vb{X})&=\\nabla_j^X u_i(\\vb{X})\\\\\nu_{i,j}(\\vb{X})&=\\nabla_j^X N_i^K(\\vb{r})\\hat{u}^K\\\\\nu_{i,j}(\\vb{X})&=J_{jQ}^{-1}\\nabla_Q^r N_i^K(\\vb{r})\\hat{u}^K\\\\\nu_{i,j}(\\vb{X})&=J_{jQ}^{-1}N_{i,Q}^K(\\vb{r})\\hat{u}^K\n\\end{align*}\nthen\n\\begin{equation}\nL_{ij}^K(\\vb{r})=J_{jQ}^{-1}N_{i,Q}^K(\\vb{r})\n\\label{eq:fundamental interpolator}\n\\end{equation}\n\n\\subsubsection*{Elemental stiffness matrix}\nThe elemental material stiffness matrix computed in the natural domain of \\cref{fig:Nat domain} reads\n\n\\begin{equation}\nK^{KP}=\\intL_{V_0(\\vb{r})} \\hat{B}_{ij}^K(\\vb{r}) C_{ijkl} \\hat{B}_{kl}^P(\\vb{r})J dV_0(\\vb{r})\\equiv \\intL_{r=-1}^{r=+1}\\intL_{s=-1}^{s=+1} \\hat{B}_{ij}^K(r,s) C_{ijkl} \\hat{B}_{kl}^P(r,s)J(r,s) \\mathrm{d}r\\mathrm{d}s\n\\label{eq:elematrix}\n\\end{equation}\n\n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=6cm]{figure3.pdf}\n\\caption{Natural domain of integration}\n\\label{fig:Nat domain}\n\\end{figure}\n \n\nOnce the interpolator $\\hat{B}_{ij}^K(\\vb{r})$ has been identified the elemental stiffness matrix is obtained via numerical integration (quadrature) as described in \\eqref{eq:eleintegration}\n\n\\begin{equation}\n\\intL_{r=-1}^{r=+1}\\intL_{s=-1}^{s=+1} \\hat{B}_{ij}^K(r,s) C_{ijkl} \\hat{B}_{kl}^P(r,s)J(r,s) \\mathrm{d}r\\mathrm{d}s\\approx \\sum_{i,j=1}^\\text{NGPTS} \\alpha_i \\alpha_j \\hat{B}_{kl}^K(r_i,s_j)C_{ijkl} \\hat{B}_{kl}^P(r_i,s_j) J(r_i,s_j)\n\\label{eq:eleintegration}\n\\end{equation}\n\n\nand where NGPTS corresponds to the number of integration points, $\\alpha_j$ is a weighting factor and $r_i,s_j$   are the coordinates of a typical point $\\vb{r}$ in the natural space of \\cref{fig:Nat domain}.\n\n \n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=6cm]{figure4.pdf}\n\\caption{Natural integration domain showing quadrature evaluation nodes}\n\\label{fig:integration domain}\n\\end{figure}\t \n\n\nOne important aspect of the numerical integration that has to be kept in mind is accuracy.  Depending on the particularly selected integration scheme, the number of introduced integration points fixes the maximum polynomial order of the considered functions that can be integrated accurately.  In the case of the integrand in \\cref{eq:eleintegration}, it is clear that this order increases as the distortion of the physical element  with respect to the natural element increases.  One way of dealing with this dependency of accuracy with element distortion is to make use of adaptative integration techniques which are numerically expensive.  What is actually done in standard FEM analysis is to choose the number of quadrature points beforehand and introduce distortion related error criteria inside the code in such a way that some sort of validation is performed before the numerical integration process is started.\n\n\\subsubsection*{Strain displacement interpolator for the infinitesimal strain tensor}\nThe $Q$-th nodal contribution to the infinitesimal strain-displacement interpolator can be obtained in explicit form as follows. Let $L_x^Q$ and $L_y^Q$ be the spatial differential operators in $x$ and $y$ respectively. We have after expanding \\cref{eq:fundamental interpolator}\n%\n\\begin{align*}\nL_x^Q & = J_{xP}^{-1}\\frac{\\partial N^Q}{\\partial r_P} \\equiv J_{xr}^{-1}\\frac{\\partial N^Q}{\\partial r} + J_{xs}^{-1}\\frac{\\partial N^Q}{\\partial s}\\\\\nL_y^Q & = J_{yP}^{-1}\\frac{\\partial N^Q}{\\partial r_P} \\equiv J_{yr}^{-1}\\frac{\\partial N^Q}{\\partial r} + J_{ys}^{-1}\\frac{\\partial N^Q}{\\partial s}\n\\end{align*}\n%\nor in matrix form\n%\n\\begin{equation}\n\\begin{Bmatrix}\nL_x^Q\\\\\nL_y^Q\n\\end{Bmatrix} = \n\\begin{bmatrix}\nJ_{xP}^{-1} &J_{xs}^{- 1}\\\\\nJ_{yr}^{-1} &J_{ys}^{- 1}\n\\end{bmatrix}\n\\begin{Bmatrix}\n\\frac{\\partial N^Q}{\\partial r}\\\\\n\\frac{\\partial N^Q}{\\partial s}\n\\end{Bmatrix}\n\\end{equation}\n\nThe $Q$-th nodal contribution is then assembled as follows;\n\n\n\\begin{equation}\n\\begin{Bmatrix}\n\\pdv{u}{x}\\\\\n\\pdv{v}{y}\\\\\n\\pdv{u}{y} + \\pdv{v}{x}\n\\end{Bmatrix} =\n\\begin{bmatrix}\n &L_x^Q &0 \\\\\n\\cdots &0 &L_y^Q &\\cdots\\\\\n &L_y^Q &L_{xy}^Q\n\\end{bmatrix}\n\\begin{Bmatrix}\n\\vdots\\\\\nu^Q\\\\\nv^Q\\\\\n\\vdots\n\\end{Bmatrix}\n\\label{eq:strain inter}\n\\end{equation}\n\n\\begin{algorithm}[H]\n    \\SetAlgoLined\n    \\KwData{Nodal coordinates $x^Q$}\n    \\KwResult{Strain-displacement interpolator $B_{ij}^Q$ }\n    Compute Jacobian ${J_{iJ}} = \\pdv{N_i^Q}{r_J}{\\hat x}^Q$\\\\\n    Invert Jacobian  ${J_{iJ}} \\to J_{iJ}^{ - 1}$\\\\\n    Compute fundamental interpolator $L_{ij}^Q = J_{jP}^{ - 1}\\pdv{N_i^Q}{r_P}$\\\\\n    Assemble $B_{ij}^Q = \\frac{1}{2}\\left( {L_{ij}^Q + L_{ji}^Q} \\right)$ \n    \\caption{Strain-displacement interpolator}\n\\end{algorithm}\n\\newpage\n\\subsection*{Problems}\n\n\n\n", "meta": {"hexsha": "e2e102ee71c78162e607c703ed618a85f0686453", "size": 48790, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/thefem.tex", "max_stars_repo_name": "jomorlier/FEM-Notes", "max_stars_repo_head_hexsha": "3b81053aee79dc59965c3622bc0d0eb6cfc7e8ae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-15T01:53:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-15T01:53:14.000Z", "max_issues_repo_path": "src/thefem.tex", "max_issues_repo_name": "jomorlier/FEM-Notes", "max_issues_repo_head_hexsha": "3b81053aee79dc59965c3622bc0d0eb6cfc7e8ae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/thefem.tex", "max_forks_repo_name": "jomorlier/FEM-Notes", "max_forks_repo_head_hexsha": "3b81053aee79dc59965c3622bc0d0eb6cfc7e8ae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-25T17:19:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-25T17:19:53.000Z", "avg_line_length": 44.6794871795, "max_line_length": 918, "alphanum_fraction": 0.6765935643, "num_tokens": 17428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755218, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7444167119361945}}
{"text": "\\chapter{Time Series Data Mining For Visual Analysis}\nEven though most of the data around us have a temporal nature, we often transform them into spatial data by either fixing time or ignoring time completely. It is not because the time aspect is not essential, though it makes all tasks significantly more challenging as it increases the number of data points and adding relations between them.  For example, it is straightforward to compare temperatures in two places at a fixed time. However, once we want to compare their temperature profiles throughout the year, we cannot omit the temporal aspect of the data. Because the temporal aspect adds relations between points and increases the dimensionality of the data, the analysis becomes significantly more difficult. This effect is multiplied once we work with a dataset of time series \\cite{met:vis-data-help}. Mostly there, we see an opportunity where visual exploration could help.\n\nThis chapter will discuss the right choices for measuring the distance between time series and examine how to effectively apply them in the subsequent visual analysis. Then it goes through the clustering and anomaly detection methods available for large datasets. However, before we dive into the chapter, we will clarify the basic terminology.\n\nHaving a set of objects $X$, we define the \\textit{distance function} as:\n\\begin{equation}\n    d: X \\times X \\rightarrow R^{+}_0 \n\\end{equation}\nThe resulting non-negative real value is called a \\textit{distance} or \\textit{dissimilarity}. We call a distance function a \\textit{metric} if and only if it satisfies the following three axioms:\n\\begin{enumerate}\n    \\item $\\forall x, y \\in X: d(x, y) = 0 \\Leftrightarrow x = y $ (identity of indiscernibles)\n    \\item $\\forall x, y \\in X: d(x, y) = d(y, x)$ (symmetry)\n    \\item $\\forall x, y, z \\in X: d(x, y) + d(y, z) \\ge d(x, z)$ (triangle inequality)\n\\end{enumerate}\nA \\textit{semi-metric} is a distance function that satisfies the first two axioms, but it does not guarantee the triangle inequality.\n\\textit{A time series} is then defined as a sequence of data points ($X_t$) indexed by time ($t$).\n\n\\section{Distance Measures for Time Series}\nIn a typical scenario, a distance metric computes the distance for one specific data type (categorical, spatial, numerical). However, time series are a combination of multiple data types as each point has an order in time, and we have to take it into account when computing the distance.\n\nTo the best of our knowledge, there are over 30 used distance measures for time series today. As there is no \"universally best\" metric \\cite{met:universal}, we will go through the different types of distance measures used for time series, following the categorization proposed by Esling and Agon \\cite{met:classification}.\n\n\\subsection{Shape-Based Distance Measures}\nShape-based distance measures compare the overall shape of the time series \\cite{met:classification}. They are the closest derivation of commonly used distance measures adjusted for the time series data, making them easy to implement and understand. Regardless of their simple nature, they generally yield very competitive results and are considered a gold standard of time series distance measures \\cite{met:comparison-new, met:dtw-best-0, met:dtw-best-1, met:universal, met:fDTW}.\n\n\\subsubsection{Euclidian Distance and Other $L_p$ Norms}\nThe most basic and widely used distance measures for spatial and temporal data are Euclidian distance (ED) and other $L_p$ norms \\cite{met:lp-norm, met:lp-norm-usage}.\n\nA distance measure on a set of objects $X$ is a function $d:X\\times~X\\rightarrow[0; \\infty)$.\nGiven the two time series $X$ and $Y$, where $X=(x_1; x_2; ...; x_n)$ and $Y=(y_1; y_2;...; y_m)$, we define $L_p$ norms as listed in Table~\\ref{tab:lp-norms}.\n\\begin{table}[!htbp]\n\\begin{tabular}{ll}\n\\textbf{Norm}          & \\textbf{Definition}                               \\\\ \\hline\n$L_1$ - Manhattan      & $\\sum^{n}_{i=1}|x_i - y_i|$                       \\\\\n$L_2$ - Euclidian      & $\\sqrt{\\sum^{n}_{i=1}(x_i - y_i)^2}$              \\\\\n$L_p$ - Minkowski      & $\\sqrt[p]{\\sum^{n}_{i=1}(x_i - y_i)^\\frac{1}{p}}$ \\\\\n$L_\\infty$ - Infinite  & $\\max_{i=1..n}|x_i - y_i|$\n\\end{tabular}\n\\caption{$L_p$ norms for time series.}\n\\label{tab:lp-norms}\n\\end{table}\n\nAlthough the $L_p$ norms perform well, especially on larger datasets \\cite{met:universal, met:comparison-new, met:met-comparison}, they require time series of equal length and tend to be fragile to the noise, shifts, and different speeds in time series \\cite{met:classification}.\n\n\\subsubsection{Dynamic Time Warping}\nAn elegant solution to the above-mentioned limitations of the $L_p$ norms are elastic measures, especially the Dynamic Time Warping (DTW) \\cite{met:dtw}. DTW is a method to compute a distance between a pair of time series. When computing DTW distance between time series $X$ and $Y$, it finds the best alignment between them as a minimal cost warping path ($W=w_1 ,...,w_k ,...,w_K$) in $m \\times n$ matrix. Elements of the matrix represent the cost to align two corresponding points ($(x_i - y_j)^2$). The warping path starts in the bottom-left corner and ends in the upper-right one (Fig. \\ref{fig:dtw_warping}). It is formally defined as:\n\\begin{equation}\n    DTW(X; Y) = \\argmin_{W=w_1 ,...,w_k ,...,w_K} \\sqrt{ \\sum^{K}_{k=1; w_k=(i; j)} (x_i - y_j)^2}\n\\end{equation}\n\nWhen comparing DTW with the Euclidian distance, DTW finds the best possible alignment between time series (Fig. \\ref{fig:Euclid_vs_DTW}). That allows us to reasonably compare time series that could have different lengths, speeds, and shift \\cite{met:dtw, met:dtw-window}.\n\\begin{figure}[h]\n     \\centering\n     \\begin{subfigure}[b]{0.495\\textwidth}\n        \\centering\n        \\includesvg[width=\\textwidth]{img/dtw_warping_path.svg}\n        \\caption{}\n        \\label{fig:dtw_warping}\n     \\end{subfigure}\n     \\hfill\n     \\begin{subfigure}[b]{0.495\\textwidth}\n        \\centering\n        \\includesvg[width=\\textwidth]{img/dtw_vs_euclid.svg}\n        \\caption{}\n        \\label{fig:Euclid_vs_DTW}\n     \\end{subfigure}\n    \\caption{\n        (a) displays the optimal warping path between two time series. The darkness of color encodes the distance between the corresponding data points (darker is further away). (b) shows the alignment of data points between two time series using the Euclidian distance and DTW.\n    }\n\\end{figure}\n\nDynamic time warping is considered one of the best distance measures for time series and regularly outperforms other more sophisticated approaches \\cite{met:universal, met:comparison-new, met:dtw-best-1, met:dtw-best-0}, but its use comes with two main concerns:\n\\begin{enumerate}\n    \\item In practice, DTW is solved by dynamic programming with $O(n^2)$ time complexity.\n    \\item DTW is a semi-metric -- it does not guarantee triangle inequality, limiting the number of optimization techniques and structures we can use.  \n\\end{enumerate}\n\nThe time complexity of this algorithm becomes an issue when operating with long time series and their large amounts. As a solution to the DTW algorithm's time complexity, it is possible to either use lower and upper bounding constraints on the maximal allowed warping path \\cite{met:dtw-koegh-rata} or use a temporal constraint on the warping window size \\cite{met:dtw-window}. Among the most used are Sakoe-Chiba \\cite{met:dtw-window}, Itakura \\cite{met:dtw-itakura}, and upper bound to discard complex paths \\cite{met:DTW-zheng}. Another option is to use an approximate algorithm proposed by Salvador and Chan \\cite{met:FastDTW} called FastDTW, where the warping path is recursively projected and optimized from a lower resolution. This algorithm has linear time complexity. Using the bounding or approximate algorithm comes with faster computational speed and could help with better accuracy due to generalization \\cite{met:fDTW}.\n\nDTW is a semi-metric that makes it rather problematic to use with many machine learning algorithms that require a metric space. As there does not exist any complete solution to this issue, there are only partial answers, like Feature DTW from \\textcite{met:fDTW}. As we want to use a wide variety of algorithms for visual exploration, we will discuss this in more detail in the following section.\n\n\\subsubsection{SpADe, DISSIM, and OSB}\nIn 2007, three new distance measures for time series were proposed. The first one is the Spatial Assembling Distance (SpADe), a distance measure used for streaming data that recognizes matching patterns concerning shifting and scaling in temporal and amplitude axes \\cite{met:spade}.\n\nFor measuring similarity between trajectories with different sampling rates, Frentzos et al. \\cite{met:dissim} proposed the DISSIM as an approximation of the integral of Euclidian distance. \n\nBecause data tend to be noisy and include many outliers, Latecki et al. \\cite{met:osb} proposed Optimal Subsequence Bijection (OSB) for similarity search. This method automatically finds the most suitable subsequence for a sensible comparison. Its disadvantage is a higher computational cost.\n\n\\subsection{Other Distance Measures}\nExcept for the shape-based metrics used for time series data, other methods could be used for the distance calculation. These types of measures focus on specific properties shared among time series.\n \n\\textit{Edit-based} distances were originally designed for string comparison. The idea is to find the minimal number of basic string operations (insertion, deletion, and substitution) by which we can transform one string to another.  The most popular are techniques measuring the similarity by comparing the longest common subsequences (LCSS) \\cite{met:LCSS0, met:LCSS1, met:swale}. They are robust to outliers and noise in the data. Similar options are the Edit Distance on Real Sequence (EDR) \\cite{met:edr} and Edit Distance with a Real Penalty (ERP) \\cite{met:erp}. EDR finds the minimal number of edit operations to convert time series and penalizes unmatched regions' gaps by their lengths. On the other hand, ERP is a combination of DTW and EDR approaches. It uses the Manhattan distance as a penalization for local shifting. Edit-based distances tend to perform well, but generally are outperformed by DTW-like measures \\cite{met:dtw-best-0, met:dtw-best-1}. \n\n\\textit{Feature-based} distance measures use features extracted from the original time series, such as correlation \\cite{met:coss-col} or coefficients from discrete Fourier transformation and discrete wavelet transformation \\cite{met:dft-dwt}. It is possible to use them in specific applications but they overly show worse results than other techniques \\cite{met:comparison-new}.\n\n\\textit{Model-based} measures are an option for very long sequences, but they require prior knowledge of the time series generating process \\cite{met:classification}. After choosing and fitting the parametric temporal model on time series, the distance measure is a likelihood that time series came from the same model. Most standard models are using Hidden Markov models or ARMA models \\cite{met:hmm}.\n\n\\textit{Compression-based} strategies have been succesfully applied in bioinformatics and medical data applications \\cite{met:cdm, met:cdm-santos, met:cdm-espoti}. This approach uses the fact that concatenation and compression of similar time series should produce a higher compression ratio than for very diverse ones.\n\nMany of these techniques can outperform more common shape-based measures, particularly in specific domains, but lack wide usage and universality of shape-based approaches. Even though we would primarily use the shape-based measure in this thesis, the proposed techniques for time series analysis can use any underlying distance measure.\n\n\\section{Artificial Feature Space Representation}\nFrom the previous section, we can presume that shape-based distance measures, especially Dynamic Time Warping and its derivatives, are robust and accurate. The original DTW algorithm's time complexity can be reduced significantly by using bounding or approximation. However, we still need to consider its semi-metric nature because the triangle inequality is required for many machine learning algorithms \\cite{cluster:decade-review}. It significantly reduces the number of available algorithms that we could use, primarily as datasets' size increases. Partial answer to this problem is building a feature space representation, which we could consider to be in a metric space.\n\n\\subsection{Feature DTW Transformation}\n\\textcite{met:fDTW} introduced an idea to build a feature space representation by using DTW. He transforms the original dataset of time series into a new feature space on which it is possible to apply any technique that is used in a metric space.\n\nThe transformation works as follows. Having dataset $X$ consisting of time series $(X_1; X_2; ...; X_n)$, we define the Feature DTW transformation as function\n\\begin{equation}\n    f_{fDTW}: X \\times X \\rightarrow M\n\\end{equation}\nwhere $M=(m_{ij}) \\in \\mathbb{R}_{\\ge 0}^{n \\times n}$ is a distance matrix with $m_{ij}=DTW(X_i; X_j)$.\n \n In his paper, Kate sees an improved accuracy in classification tasks to widely used techniques using DTW directly. Further, he shows that using DTW with bonding and approximation increases the accuracy probably due to better generalization, and points out that any distance measure could be used instead of DTW. Another notable advantage of using the Feature DTW transformation is that it is possible to combine DTW obtained features with other measures and features. In his work, \\textcite{met:fDTW} combined DTW features with Euclidian ones, which led to an additional approvement in terms of accuracy. This technique's main drawback is space complexity as the distance matrix $M$ size is $n^2$ regarding the number of time series. \n\n\n\\subsection{Prototyped Feature DTW Transformation}\nThe result of Feature DTW transformation on two similar time series should produce very similar and correlated feature vectors. A statistical point suggests that we are adding very little new information while increasing the number of dimensions in the new feature space. An increase in dimensionality leads to a rise in computational and space requirements, while having multiple significantly correlated features is a problem for many machine learning algorithms. Iwana et al. \\cite{met:protofDTW} showed that using only a fraction of the original distance matrix $M$ could obtain comparable or better results than using the whole matrix.\n\nHaving the dataset $X=(X_1; X_2; ...; X_n)$ and a set of time series $P~ \\subseteq~X,$ $P=(P_1; P_2; ...; P_m)$ called \\textit{prototypes}, we define the transformation as function\n\\begin{equation}\n    f_{Iwana-fDTW}: X \\times X \\rightarrow K\n\\end{equation}\nwhere $K=(k_{ij}) \\in \\mathbb{R}_{\\ge 0}^{n \\times m}$ is a distance matrix with $k_{ij}=DTW(X_i; P_j)$.\n\nAs this method strongly depends on prototypes, their selection is crucial for the method's success. They proposed a supervised technique using the \\textit{AdaBoost} algorithm and weak learners on one feature at a time. Using this technique, they were able to use a smaller number of components while increasing the classification accuracy. Because this method is available only for supervised problems, they briefly discussed multiple statistical strategies to chose possible prototypes.\n\nAll of the approaches described in their work require prior computation of the whole distance matrix, which is problematic for larger datasets. In this thesis, we will propose methods that do not require a full distance matrix in advance but rather compute it interactively.\n\n\\section{Clustering}\nAnother part of our work is to determine the clusters in a dataset. Because we are using the Feature DTW transformation, we are not limited to clustering specific only for time series, but we can use a wide variety of clustering algorithms used for spatial data. Because we will be working with large datasets in our analysis, we will list only algorithms that are scalable to a large number of samples and features.\n\nWe will separate the clustering algorithms into three categories:\n\\begin{enumerate}\n    \\item Distance-based methods\n    \\item Methods using the nearest-neighbor graph\n    \\item Density-based methods\n\\end{enumerate}\n\n\\subsection{Distance-based Methods}\nDistance-based methods are directly using the distance between the data points to determine their affiliations to the clusters. The two main representatives of this category, that scale well  with dataset's size, are \\textit{K-means} and \\textit{Agglomerative Hierarchical Clustering} methods.\n\n\\subsubsection{K-means}\nThe \\textit{K-means} method \\cite{vis:kmeans} is a simple clustering algorithm that separates the data into $n$ clusters, minimizing the within-cluster sum of squares. It produces convex and isotropic clusters, and it is easily scalable to large datasets. The disadvantages of this method are that we have to define the number of clusters in advance, and in some cases, the clusters in data are neither convex nor isotropic. Nevertheless,  it is a solid starting point for any cluster analysis. \n\n\\subsubsection{Agglomerative Hierarchical Clustering}\nThe \\textit{Agglomerative Hierarchical Clustering} approach \\cite{vis:agg-cluster, vis:kmeans} uses a bottom-up strategy to join the two most similar data points or clusters into a single bigger one. The primary representation is a tree-like structure, where leaves are single data points, nodes represent clusters, and the root is a single unified cluster. The algorithm selects two closest nodes based on the merge strategy in each iteration and joins them into a single one, until the given number of clusters is met.\n\nThere are four main merge strategies called \\textit{linkages}:\n\\begin{enumerate}\n    \\item \\textit{Single linkage} -- the minimal distance among all tuples of data points from two clusters.\n    \\item \\textit{Complete linkage} -- the maximal distance among all tuples of data points from two clusters.\n    \\item \\textit{Average linkage} -- the average distance between all pairs of data points from two clusters.\n    \\item \\textit{Ward linkage} -- minimization of the within-cluster sum of squares, similar to the K-means.\n\\end{enumerate}\nThis clustering method is scalable with the increasing number of samples and, based on the linkage type, provides different cluster types. The ward linkage produces the most even-sized clusters among the merging strategies, but is usable only with Euclidian metrics, while also having much higher time complexity. If we want to use non-Euclidian metrics, the average linkage is a feasible alternative. Both single linkage and complete linkage are very efficient and scale well on large datasets. The drawback is that they are fragile to noise in the data, as they are using only the distance between two points from clusters.\n\n\\subsection{Methods Using the Nearest Neighbor Graph}\nAnother family of clustering algorithms is using the pre-constructed affiliation graph from data points. Usually, it uses the nearest neighbor graph. The two main representatives are the Affinity Propagation and Spectral clustering. \n\\subsubsection{Affinity Propagation}\nThe \\textit{Affinity Propagation} \\cite{vis:affini} sends messages between data points in the affiliation graph to determine cluster centers and the number of clusters. The disadvantage is that it is usable only for smaller datasets because of its quadratic time complexity, making it unusable for our datasets of interest.\n\n\\subsubsection{Spectral Clustering}\nThe \\textit{Spectral Clustering} \\cite{vis:spectral} starts with the nearest neighbor graph represented as a similarity matrix, where each row represents a data point and its graph distance to the other points. After selecting the number of clusters $n$, it computes the optimal graph cuts to create a connected component for every cluster. The drawback of spectral clustering is that it can be efficiently computed only for a small number of clusters.\n\n\\subsection{Density-based Methods}\nThe last group of clustering algorithms, density-based methods, uses the difference between dense and sparse regions to determine the optimal clustering. \nThe main challenge of these methods is to determine the correct density estimate of the dataset, which is problematic for high-dimensional datasets. As the number of dimensions increases, the volume of the space rises exponentially, thus making the dataset quickly sparse. This phenomenon is also known as the \\textit{Curse of Dimensionality} \\cite{exp:curse-of-dim}.\n\nDue to the expected size of datasets of our interest, and usage of the Feature DTW transformation, we will be interest and the usage with high-dimensional data. Therefore, we are not considering the most common density-based techniques such as \\textit{Gaussian Mixture Models} \\cite{vis:gauss-mixt} and \\textit{Mean Shift} \\cite{vis:mean-shift}, as they make assumptions about the underlying data distribution, or computationally expensive.\n\n\\subsubsection{DBSCAN}\nThe first density-based clustering algorithm in our work is the \\textit{Density-Based Spatial Clustering of Applications With Noise (DBSCAN)} \\cite{vis:dbscan}. This algorithm separates the dataset into dense clusters divided by sparse regions and outlying data points, considered as noise. Firstly it separates data points into three groups: core points, non-core points close to the core points, and noise.\n\nWe say that a point is a core point if and only if in its surrounding area with radius $\\epsilon$ there are at least $X$ other data points (the minimal number of data points). The non-core points close to the core points have a core point within the radius $\\epsilon$, yet they do not meet the minimal data points requirement within $\\epsilon$. Noise points do not have any core points in their surrounding area. Hence, the DBSCAN algorithm automatically detects the number of clusters and only requires the radius $\\epsilon$ and the minimal number of samples $X$. The disadvantage of DBSCAN is that it cannot detect clusters with very different density, as the radius is same for each point.\n\n\\subsubsection{OPTICS}\nThe \\textit{Ordering Points To Identify the Clustering Structure (OPTICS)} \\cite{vis:optics} is a partial solution of the DBSCAN's problem with clustering regions with different densities. OPTICS uses the minimal number of neighbors $X$, and instead of a single radius like in DBSCAN, it uses the maximal radius to consider $\\epsilon$. For each point, it computes the core distance, the minimal radius, in which is the point is considered as a core point, and reachability distance to every other point, which is either the core distance of the other point or the distance between them, whichever of them is bigger. If two neighboring points have a reachability distance smaller than the core distance, we consider them to be a part of the same cluster.\n\nBecause OPTICS computes both core distance and reachability, it has a much higher computational cost than DBSCAN. With the usage of spatial indexing trees, we could avoid a costly computation of the full distance matrix, making it applicable to larger datasets.\n\n\\subsubsection{HDBSCAN}\nThe \\textit{Hierarchical Density-based Spatial Clustering of Applications with Noise (HDBSCAN)} \\cite{vis:hdbscan} is another clustering algorithm originating in the DBSCAN. Like DBSCAN and OPTICS, it starts by computing the core distance of every point, which is a minimum radius in which there are at least $X$ data points (minimal number of data points) and the mutual reachability distance for every pair of data points -- the largest value among their core distances and their mutual distance.\n\nAfterwards, it finds the minimal spanning tree of a weighted graph, where data points are vertices, and edges between them have the weight of their mutual reachability distance (Fig.~\\ref{fig:hdbscan_tree}).\n\\begin{figure}[h]\n     \\centering\n     \\begin{subfigure}[b]{0.495\\textwidth}\n        \\centering\n        \\includesvg[width=\\textwidth]{img/hdbscan_dataset.svg}\n        \\caption{}\n        \\label{fig:hdbscan_dataset}\n     \\end{subfigure}\n     \\hfill\n     \\begin{subfigure}[b]{0.495\\textwidth}\n        \\centering\n        \\includesvg[width=\\textwidth]{img/hdbscan_tree.svg}\n        \\caption{}\n        \\label{fig:hdbscan_tree}\n     \\end{subfigure}\n    \\caption{The minimal spanning tree from HDBSCAN (a) using the mutual reachability distance on an artificially generated dataset (b).\n    }\n\\end{figure}\n\nThe next step clusters the tree vertices by single-linkage hierarchical clustering using the edge weights. In Fig.~\\ref{fig:hdbscan_hier}, we can see the dendrogram visualizing such clustering, where on the $y$ axis we can see the \\textit{mutual reachability distance} at which the nodes merge.\n\\begin{figure}[h]\n     \\centering\n     \\begin{subfigure}[b]{0.48\\textwidth}\n        \\centering\n        \\includesvg[width=\\textwidth]{img/hdbscan_hier.svg}\n        \\caption{}\n        \\label{fig:hdbscan_hier}\n     \\end{subfigure}\n     \\hfill\n     \\begin{subfigure}[b]{0.48\\textwidth}\n        \\centering\n        \\includesvg[width=\\textwidth]{img/hdbscan_cons.svg}\n        \\caption{}\n        \\label{fig:hdbscan_cons}\n     \\end{subfigure}\n    \\caption{HDBSCAN's single linkage hierarchy of connected components (a) and the most stable clusters in condensed cluster tree (b).\n    }\n\\end{figure}\n\nThe next step converts the tree into a hierarchy of connected components by sorting the edges and merging them in an ascending order (Fig.~\\ref{fig:hdbscan_hier}). To determine the number of clusters in the data, DBSCAN computes the stability of each cluster. As a measure, we are using the $\\lambda$ value, which is the reversed \\textit{mutual reachability distance} ($\\lambda = \\frac{1}{distance}$). For every cluster, HDBSCAN defines the distance when it is created as $\\lambda_c$ and the distance when it splits into multiple clusters as $\\lambda_d$. Then for every point $p$ in the cluster, it computes the value $\\lambda_p$, which is the value when the point leaves the cluster either by cluster split or complete separation. The stability of a cluster $C$ is then defined as:\n\\begin{equation}\n    \\sum_{p \\in C}(\\lambda_p - \\lambda_c)\n\\end{equation}\nFinally, HDBSCAN travels through the tree, starting from the leaves going up to the root node. For every node (cluster), if its stability is greater than the sum of its children's stabilities, HDBSCAN marks the cluster as a real cluster and unmarks all its descendants. Once the algorithm reaches the root node, it stops and returns all marked clusters as final data clustering (Fig.~\\ref{fig:hdbscan_cons}).\n\nEven though HDBSCAN consists of multiple computational steps, there are highly optimized implementations \\cite{vis:hdbscan-imp}, allowing HDBSCAN to be effectively used for large datasets.\n\n\\section{Anomaly Detection}\nIn the last part of our analysis, we want to detect and study the anomalous data points within a dataset. Here we will focus on two methods, \\textit{Isolation Forest} and \\textit{Lightweight On-line Detector of Anomalies}, which are widely used and efficient even for large high-dimensional datasets.\n\n\\subsection{Isolation Forest}\nOne of the widely used anomaly detection algorithms for large datasets is the \\textit{Isolation Forest} \\cite{vis:isoforest}. The central concept of this approach is that anomalous data points can be isolated faster than the rest of the dataset. \n\nTo find the anomalies, it constructs the forest of binary isolation trees. A binary isolation tree is a simple decision tree with restricted depth, where each node of the tree selects the random feature and random value in its range as a separator. The anomaly score of a data point is the average depth it reached in trees in the isolation forest.\n\nBecause of its simple nature, the Isolation Forest scales very well with the number of samples and number of features, while also achieving competitive results.\n\n\\subsection{Lightweight On-line Detector of Anomalies}\nThe \\textit{Lightweight On-line Detector of Anomalies (LODA)} is an anomaly detection method designed to process huge high-dimensional real-time data streams. LODA uses a combination of randomly generated sparse projections and histograms to determine the anomaly score of each data point.\n\nIn the first step, LODA generates $X$ random projection vectors with only $\\sqrt{d}$ non-zero taken from $N(0, 1)$ values, where $d$ is input data's dimensionality. Then, it constructs a histogram on every projection vector. The final anomaly score of each point is the negative average logarithm of probability obtained throughout all histograms.\n\nBecause LODA is using sparse projections and histograms as very simple density estimators, it has very fast training and execution time. Another advantage is that through the vectors' sparsity, it is possible to discover which feature contributed most to the data points anomaly score. We compute the \\textit{one-tailed two-sample t-test} between probabilities from histograms on projections with and without a specific feature. The higher the value of the \\textit{t-test}, the stronger is the feature significance.\n\n\\section{Chapter Summary}\nIn this chapter, we discussed distance measures for time series. Among them, shaped-based distances, particularly the Euclidian distance and Dynamic Time Warping (DTW) seem like the most promising ones. The main drawback of DTW is its semi-metric nature. To use the advantages of DTW in a metric space, we can use Feature DTW transformation to create a feature space representation of DTW. This representation then forms the input for other machine learning algorithms and can be combined with other distance measures and feature extraction algorithms.\n\nThere are several options for clustering of large datasets:\n\\begin{itemize}\n    \\item \\textit{K-means} is suitable when we know the number of clusters and want evenly sized convex clusters. It is a good starting technique as it scales very well with the dataset size.\n    \\item \\textit{Hierarchical agglomerative clustering} is suitable for medium to large datasets based on the chosen linkage. \\textit{Ward linkage} produces the most evenly sized clusters but has the highest complexity and is defined only in the Euclidian space. For non-Euclidian cases, the \\textit{average linkage} is a good alternative. While the \\textit{single linkage} is very efficient and can be used on large datasets, with the capability to produce non-convex clusters it is fragile to noise in the data.\n    \\item \\textit{OPTICS} and \\textit{HDBSCAN} are suitable for cases when we do not know the number of clusters in our data but want to specify only the minimal number of clusters. As these methods are density-based, we have to be aware of the curse of dimensionality, and consider transforming the dataset into a low-dimensional representation.\n\\end{itemize}\n\nIn the field of anomaly detection, we recommend the \\textit{Isolation Forest} and \\textit{LODA} approaches. Both methods are ensembles of simple estimators, giving them high-speed performance regardless of the dataset size. \\textit{LODA} also provides us with the capability for scoring the features based on their significance in the anomaly score.\n", "meta": {"hexsha": "a10e8d34593ebf1d46008c15283f9aa5279d6d26", "size": 31308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chapters/1_distance_measures.tex", "max_stars_repo_name": "H00N24/visual-analysis-of-big-time-series-datasets", "max_stars_repo_head_hexsha": "8c9c14ca5d16f5d9ef8b623c84f92fe62eee1f86", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-07-30T04:07:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T07:28:44.000Z", "max_issues_repo_path": "thesis/chapters/1_distance_measures.tex", "max_issues_repo_name": "H00N24/visual-analysis-of-big-time-series-datasets", "max_issues_repo_head_hexsha": "8c9c14ca5d16f5d9ef8b623c84f92fe62eee1f86", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thesis/chapters/1_distance_measures.tex", "max_forks_repo_name": "H00N24/visual-analysis-of-big-time-series-datasets", "max_forks_repo_head_hexsha": "8c9c14ca5d16f5d9ef8b623c84f92fe62eee1f86", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 119.4961832061, "max_line_length": 967, "alphanum_fraction": 0.7837293982, "num_tokens": 7090, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.893309411735131, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7444166984759722}}
{"text": "\\section{Circles}\n\n\\subsection{Defining a circle}\nCircle $(O,r)$ is the set of points at distance exactly $r$ from a point $O=(x_0,y_0)$.\n\nWe can also define it by equation\n\\[(x-x_0)^2 + (y-y_0)^2 = r^2\\]\nor parametrically as the set of all points\n\\[(x_0+r\\cos\\theta, y_0+r\\sin\\theta)\\]\nwith $\\theta$ in $[0,2\\pi)$, for example.\n\n\\centerFig{circle0}\n\n\\subsection{Circumcircle}\nThe \\term{circumcircle} of a triangle $ABC$ is the circle that passes through all three points $A$, $B$ and $C$.\n\n\\centerFig{circle1}\n\nIt is undefined if $A$, $B$, $C$ are aligned, and unique otherwise. We can compute its center $O$ this way:\n\\begin{lstlisting}\npt circumCenter(pt a, pt b, pt c) {\n    b = b-a, c = c-a; // consider coordinates relative to A\n    assert(cross(b,c) != 0); // no circumcircle if A,B,C aligned\n    return a + perp(b*sq(c) - c*sq(b))/cross(b,c)/2;\n}\n\\end{lstlisting}\n\nThe radius can then be found by taking the distance to any of the three points, or directly taking the length of \\lstinline|perp(b*sq(c) - c*sq(b))/cross(b,c)/2|, which represents vector $\\vv{AO}$.\n\n\\begin{mathy}\nThe formula can be easily interpreted as the intersection point of the line segment bisectors of segments $[AB]$ and $[AC]$, when considering coordinates relative to $A$. Consider the bisector of $[AB]$. It is perpendicular to $[AB]$, so its direction vector is $\\perpop(\\vv{AB})$, and it passes through the middle point $\\frac{1}{2}\\vv{AB}$, so its constant term (variable \\lstinline|c| in the \\lstinline|line| structure) is $\\perpop(\\vv{AB}) \\times \\frac{1}{2}\\vv{AB} = -\\frac{1}{2}|AB|^2$. Similarly, the bisector of $[AC]$ is defined by direction vector $\\perpop(\\vv{AC})$ and constant term $-\\frac{1}{2}|AC|^2$. We then just plug those into the formula for line intersection found in section~\\ref{line-line}:\n\\begin{align*}\n\\vv{AO} &= \\frac{(-\\frac{1}{2}|AB|^2)\\perpop(\\vv{AC}) - (-\\frac{1}{2}|AC|^2)\\perpop(\\vv{AB})}{\\perpop(\\vv{AB}) \\times \\perpop(\\vv{AC})} \\\\\n&= \\frac{\\perpop(|AC|^2\\vv{AB} - |AB|^2\\vv{AC})}{2\\ \\crossv{AB}{AC}}\n\\end{align*}\n\\end{mathy}\n\n\\subsection{Circle-line intersection}\nA circle $(O,r)$ and a line $l$ have either 0, 1, or 2 intersection points.\n\n\\centerFig{circle2}\n\nLet's assume there are two intersection points $I$ and $J$. We first find the midpoint of $[IJ]$. This happens to be the projection of $O$ onto the line $l$, which we will call $P$.\n\n\\centerFig{circle3}\n\nOnce we have found $P$, to find $I$ and $J$ we need to move along the line by a certain distance $h$. By the Pythagorean theorem, $h=\\sqrt{r^2-d^2}$ where $d$ is the distance from $O$ to $l$.\n\nThis gives the following implementation (note that we have to divide by $\\norm{\\dirof{l}}$ so that we move by the correct distance). It returns the number of intersections, and places them in \\lstinline|out|. If there is only one intersection, \\lstinline|out.first| and \\lstinline|out.second| are equal.\n\\begin{lstlisting}\nint circleLine(pt o, double r, line l, pair<pt,pt> &out) {\n    double h2 = r*r - l.sqDist(o);\n    if (h2 >= 0) { // the line touches the circle\n        pt p = l.proj(o); // point P\n        pt h = l.v*sqrt(h2)/abs(l.v); // vector parallel to l, of length h\n        out = {p-h, p+h};\n    }\n    return 1 + sgn(h2);\n}\n\\end{lstlisting}\n\n\\subsection{Circle-circle intersection}\nSimilarly to the previous section, two circles $(O_1,r_1)$ and $(O_2,r_2)$ can have either 0, 1, 2 or an infinity of intersection points (in case the circles are identical).\n\n\\centerFig{circle4}\n\nAs before, we assume there are two intersection points $I$ and $J$ and we try to find the midpoint of $[IJ]$, which we call $P$.\n\n\\centerFig{circle5}\n\nLet $d=|O_1O_2|$. We know from the law of cosines on $O_1O_2J$ that\n\\[\\cos(\\measuredangle{O_2O_1J}) = \\frac{d^2 + r_1^2 - r_2^2}{2dr_1}\\]\nand since $O_1PJ$ is a right triangle,\n\\[|O_1P| = r_1\\cos(\\measuredangle{O_2O_1J}) = \\frac{d^2 + r_1^2 - r_2^2}{2d}\\]\nwhich allows us to find $P$.\n\nNow to find $h=|PI|=|PJ|$, we apply the Pythagorean theorem on triangle $O_1PJ$, which gives $h=\\sqrt{r_1^2 - |O_1P|^2}$.\n\nThis gives the following implementation, which works in a very similar way to the code in the previous section. It aborts if the circles are identical.\n\\begin{lstlisting}\nint circleCircle(pt o1, double r1, pt o2, double r2, pair<pt,pt> &out) {\n    pt d=o2-o1; double d2=sq(d);\n    if (d2 == 0) {assert(r1 != r2); return 0;} // concentric circles\n    double pd = (d2 + r1*r1 - r2*r2)/2; // = |O_1P| * d\n    double h2 = r1*r1 - pd*pd/d2; // = h^2\n    if (h2 >= 0) {\n        pt p = o1 + d*pd/d2, h = perp(d)*sqrt(h2/d2);\n        out = {p-h, p+h};\n    }\n    return 1 + sgn(h2);\n}\n\\end{lstlisting}\n\n\\begin{mathy}\nLet's check that if $d \\neq 0$ and variable \\lstinline|h2| in the code is nonnegative, there are indeed 1 or 2 intersections (the opposite is clearly true: if \\lstinline|h2| is negative, the length $h$ cannot exist). The value of \\lstinline|h2| is\n\\begin{align*}\nr_1^2 &- \\frac{(d^2 + r_1^2 - r_2^2)^2}{4d^2}\\\\\n&= \\frac{4d^2r_1^2 - (d^2 + r_1^2 - r_2^2)^2}{4d^2}\\\\\n&= \\frac{-d^4-r_1^4-r_2^4+2d^2r_1^2+2d^2r_2^2+2r_1^2r_2^2}{4d^2}\\\\\n&= \\frac{(d+r_1+r_2)(d+r_1-r_2)(d+r_2-r_1)(r_1+r_2-d)}{4d^2}\n\\end{align*}\nLet's assume this is nonnegative. Thus an even number of those conditions are false:\n\\[d+r_1 \\geq r_2 \\qquad d+r_2 \\geq r_1 \\qquad r_1+r_2 \\geq d\\]\nSince $d,r_1,r_2 \\geq 0$, no two of those can be simultaneously false, so they must all be true. As a consequence, the triangle inequalities are verified for $d,r_1,r_2$, showing the existence of a point at distance $r_1$ from $O_1$ and distance $r_2$ from $O_2$.\n\\end{mathy}\n\n\\subsection{Tangent lines}\nWe say that a line is tangent to a circle if the intersection between them is a single point. In this case, the ray going from the center to the intersection point is perpendicular to the line.\n\n\\centerFig{circle6}\n\nHere we will try and find a line which is tangent to two circles $(O_1,r_1)$ and $(O_2,r_2)$. There are two types of such tangents: outer tangents, for which both circles are on the same side of the line, and inner tangents, for which the circles are on either side.\n\n\n\n\\centerFig{circle7}\n\nWe will study the case of outer tangents. Our first goal is to find a unit vector parallel to the rays $[O_1P_1]$ and $[O_2P_2]$, in other words, we want to find $\\vv{v} = \\vv{O_1P_1}/r_1$. To do this we will try to find angle $\\alpha$ marked on the figure.\n\n\\centerFig{circle8}\n\nIf we project $O_2$ onto the ray from $O_1$, this forms a right triangle with hypothenuse $d=|O_1O_2|$ and adjacent side $r_1-r_2$, which means $\\cos\\alpha = \\frac{r_1-r_2}{d}$. By the Pythagorean theorem, the third side is $h = \\sqrt{d^2-(r_1-r_2)^2}$, and we can compute $\\sin\\alpha = \\frac{h}{d}$.\n\nFrom this we find $\\vv{v}$ in terms of $\\vv{O_1O_2}$ and $\\perpop{\\left(\\vv{O_1O_2}\\right)}$ as\n\\begin{align*}\n\\vv{v} &= \\cos\\alpha \\left(\\vv{O_1O_2}\\,/d\\right) \\pm \\sin\\alpha \\left(\\perpop{\\left(\\vv{O_1O_2}\\right)}/d\\right)\\\\\n&= \\frac{(r_1-r_2)\\,\\vv{O_1O_2} \\pm h \\perpop{\\left(\\vv{O_1O_2}\\right)}}{d^2}\n\\end{align*}\nwhere the $\\pm$ depends on which of the two outer tangents we want to find.\n\nWe can then compute $P_1$ and $P_2$ as \n\\[P_1 = O_1 + r_1\\vv{v} \\quad \\mbox{and} \\quad P_2 = O_2 + r_2\\vv{v}\\]\n\n\\exo{\n    Study the case of the inner tangents and show that it corresponds exactly to the case of the outer tangents if $r_2$ is replaced by $-r_2$. This will allow us to write a function that handles both cases at once with an additional argument \\lstinline|bool inner| and this line:\n    \\lstinputlisting{code/bits/tangent-inner.cpp}\n}\n\nThis gives the following code. It returns the number of tangents of the specified type. Besides,\n\\begin{itemize}\n\\item if there are 2 tangents, it fills \\lstinline|out| with two pairs of points: the pairs of tangency points on each circle $(P_1,P_2)$, for each of the tangents;\n\\item if there is 1 tangent, the circles are tangent to each other at some point $P$, \\lstinline|out| just contains $P$ 4 times, and the tangent line can be found as \\lstinline|line(o1,p).perpThrough(p)| (see \\ref{perpThrough});\n\\item if there are 0 tangents, it does nothing;\n\\item if the circles are identical, it aborts.\n\\end{itemize}\n\\begin{lstlisting}\nint tangents(pt o1, double r1, pt o2, double r2, bool inner, vector<pair<pt,pt>> &out) {\n    if (inner) r2 = -r2;\n    pt d = o2-o1;\n    double dr = r1-r2, d2 = sq(d), h2 = d2-dr*dr;\n    if (d2 == 0 || h2 < 0) {assert(h2 != 0); return 0;}\n    for (double sign : {-1,1}) {\n        pt v = (d*dr + perp(d)*sqrt(h2)*sign)/d2;\n        out.push_back({o1 + v*r1, o2 + v*r2});\n    }\n    return 1 + (h2 > 0);\n}\n\\end{lstlisting}\n\nConveniently, the same code can be used to find the tangent to a circle passing through a point by setting \\lstinline|r2| to 0 (in which case the value of \\lstinline|inner| doesn't matter).\n", "meta": {"hexsha": "b8f88b7909579b3f9503d4d4ca7336e5fb95ba19", "size": 8779, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/basics/circle.tex", "max_stars_repo_name": "cbarnson/UVa", "max_stars_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_stars_repo_licenses": ["Unlicense", "MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-07T17:00:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-05T02:08:35.000Z", "max_issues_repo_path": "archives/codelibraries/cp-geo-master/basics/circle.tex", "max_issues_repo_name": "cbarnson/UVa", "max_issues_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_issues_repo_licenses": ["Unlicense", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "archives/codelibraries/cp-geo-master/basics/circle.tex", "max_forks_repo_name": "cbarnson/UVa", "max_forks_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_forks_repo_licenses": ["Unlicense", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.5279503106, "max_line_length": 713, "alphanum_fraction": 0.6793484452, "num_tokens": 3067, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7444166932239447}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage[a4paper,margin= 2cm]{geometry}\n\\usepackage{graphicx}\n\\usepackage{caption}\n\\usepackage{subcaption}\n\n\\title{\\LARGE{\\bf{Task 3 - Root Finding}}}\n\\author{\\Large{\\bf{Kirtan Patel - AE19B038}}}\n\\date{}\n\n\\begin{document}\n\n\\maketitle \n\n\\section{Introduction}\nThis week's Task is:\\\\\nGiven a function F(x), find a value x\\textsubscript{i} for which F(x\\textsubscript{i}) = 0. We will use a 3 methods to solve the problem. \n\\begin{enumerate}\n\t\\item Interval Bisection Method\n\t\\item Newton-Raphson Method\n\t\\item Secant Method\n\\end{enumerate}\n\n\\subsection{Interval Bisection Method}\nThis method is an algorithm to find a zero of a function by repeated bisection of an interval and determination of the subinterval where the zero must be found. It is simple and reliable, but relatively slow.The essence of the bisection method lies in the fact that the sign of a function f(x) changes on opposite sides of a root.\n\nConsider an interval [a,b] and a function f that has different signs at the boundaries of that interval: \\[f(a).f(b)<0\\]\n\nTherefore, for a continuous function f, there must be atleast one zero within the interval [a,b]. To numerically approach a zero x\\textsubscript{i} of f, the midpoint of the interval is taken as first approximation (with a1 = a , b1=b):\n\\[ c1 = a1 + \\frac{b1-a1}{2} = \\frac{a1 + b1}{2}\\]\n\nIf the function value at the midpoint is still larger than the permissible error $\\epsilon$, one has to repeat the bisection for the subiterval where the zero must be found. This can be determined from a change of sign of f,which can occur for one of the subintervals only (either for [a1,c1] or for [c1,b1]).\\\\\n\nTo determine which subinterval to continue the search in, we check the following:\n\\[if~~f(a1).f(c1)<0 \\Rightarrow a2=a1, b2=c1\\]\n\\[if~~f(b1).f(c1)<0 \\Rightarrow a2=c1, b2=b1\\]\n\nIn this new interval, we again determine the midpoint \\[c2 = \\frac{a2+b2}{2}\\] and check the error at this point. \\\\\n\nContinue this till we find a midpoint(root) which has an error less than the permissible error.\\\\\nWe can even set an upper-bound on the number of times we bisect the interval.\\\\\n\nThe code applied in the task takes both the above mentioned values as input and stops at whichever condition is met first.\n\n\n\\begin{figure} [h!]\n\t\\centering\n\t\t\\centering\n\t\t\\includegraphics[width=0.5\\linewidth]{bsm1}\n\t\t\\caption{Graphical Representation of Root Finding using Interval Bisection Method}\n\t\t\\label{fig1}\n\\end{figure}\n\n\\subsubsection{Remarks}\n\\begin{enumerate}\n\\item \\textbf {Non-detectable zeros}\\\\\nThe interval bisection method relies on a change of the sign of . However, might have a zero where the sign does not change, i.e. where the graph does not cross the axis but just touches it. Such a second-order zero cannot be found by the interval bisection method.\n\\item \\textbf {Multiple zeros}\\\\\nThe interval bisection method always converges to a zero. However, the given range might have several zeros in it . This will not be noticed by the interval bisection method, which therefore will find only one of them — but it is not clear which one will be found.\n\\item \\textbf {Numerical Stability}\\\\\nTo detect a change of the sign of , the interval bisection algorithm is formulated above in terms of a product of two function values. Since a zero of is approached, these values can become very small, so that their product may lead to numerical underflow. This can furthermore be confused with the case that accidentally the midpoint is the sought-after zero, i.e. not the product but already a single function value equals zero. A robust numerical implementation must take care of these possibilities and should not use products of function values.\n\\item \\textbf {Numerical Accuracy}\\\\\nIn general, the best accuracy that can be reached for the value of the zero does not equal the machine precision. This is related to the influence of the limited precision of floating-point arithmetic. Because of that, only the relative error can be used as a measure of numerical accuracy. In other words, the machine precision determines the smallest relative error reachable. Specifying an for the relative error smaller than the machine precision does not make sense and should be prevented. \\\\\n\\item \\textbf {Numerical Reliablity}\\\\\nAdditionally, not only the deviation with respect to the value might be of interest: It may happen that the function has a rather steep slope at the zero, so that despite of a small relative error, , a function value may occur that is still large. Therefore it is advisable to check this after a zero has been determined numerically. \\\\\nOn the other hand, if the function has a rather low slope at the zero, the interval of very small function values can be rather large, which implies that the problem of numerical underflow described in remark 3 above might occur already before the prescribed accuracy has been reached. Then, the algorithm will most likely exit with an unreliable value. Obviously, in such a case it does not make sense to specify too small an for the relative error.\n\\end{enumerate}\n\n\n\n\\pagebreak\n\\subsection{Newton-Raphson Method}\nThe Newton-Raphson Method is a simple algorithm to find an approximate solution for the root of a real-valued function f(x)=0. If the function f satisfies sufficient assumptions then after repeative steps the x\\textsubscript{n+1} given by:\\[x_{n+1} = x_n -\\frac{f(x_n)}{f'(x_n)}\\] will be a good approximation to the root.\\\\\n\nWe can set 2 control parameters to control the root search:\n\\begin{itemize}\n\t\\item error $\\epsilon$ \\\\\n\tIf f($x_n$) $<$ $\\epsilon$, then we stop the iterations\n\t\\item N$\\_$max \\\\\n\tIf the number of iterations crosses an upper-bound, then we stop the iterations and print the answer\n\\end{itemize}\nIf either of the conditions is met, then the iterations are stopped and the root is printed\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\centering\n\t\\includegraphics[width=0.8\\linewidth]{nrm1}\n\t\\caption{Graphical Representation of Root Finding using Newton-Raphson Method}\n\t\\label{fig2}\n\\end{figure}\n\\vspace{1cm}\n\\subsubsection{Remarks}\nNewton's method is only guaranteed to converge if certain conditions are satisfied. If the assumptions made in the proof of quadratic convergence are met, the method will converge. Failure of the method to converge indicates that the assumptions made in the proof were not met. \n\\begin{enumerate}\n\t\\item \\textbf {Bad Starting Points}\\\\\n\tIn some cases the conditions on the function that are necessary for convergence are satisfied, but the point chosen as the initial point is not in the interval where the method converges. In such cases a different method, such as bisection, should be used to obtain a better estimate for the zero to use as an initial point.\n\t\n\t\\item \\textbf{Iteration point is stationary}\\\\\n\tConsider a function \\[ f(x) = 1 - x^2\\]\n\tIt has a maximum at x = 0 and solutions of f(x) = 0 at x = $\\pm$1. If we start iterating from the stationery point $x_0 = 0$ (where derivative is zero), $x_1$ will be undefined, since the tangent at (0,1) is parallel to the x-axis.\\\\\n\t\n\tThe same issue occurs if, instead of the starting point, any iteration point is stationery. Even if the derivative is small but not zero, the next iteration will be a far worse approximation\n\t\n\t\\item \\textbf{Starting Point enters a cycle}\\\\\n\tFor some functions, some starting points may enter an infinite cycle, preventing convergence. Let  \\[ f(x) = x^3 -2x + 2\\]\n\tand take 0 as the starting point. The first iteration produces 1 and the second iteration returns to 0 so the sequence will alternate between the two without converging to a root. In fact, this 2-cycle is stable: there are neighborhoods around 0 and around 1 from which all points iterate asymptotically to the 2-cycle (and hence not to the root of the function).\n\t\\item \\textbf{Derivative Issues}\\\\\n\tThere can be several issues related to the derivative of the function.If the function is not continuously differentiable in a neighborhood of the root then it is possible that Newton's method will always diverge and fail, unless the solution is guessed on the first try.\n\t\n\tSuch cases include, derivative no being defined at the root and discontinuous derivatives.\n\t\\item \\textbf{Multiple Solutions}\\\\\n\tThe algorithm found a solution but it does not mean that this solution is unique. Actually it found the closest. In case of multiple roots, it finds only one\n\\end{enumerate}\n\\pagebreak\n\n\\subsection{Secant Method}\nThe secant method is very similar to the bisection method except instead of dividing each interval by choosing the midpoint the secant method divides each interval by the secant line connecting the endpoints. The secant method always converges to a root of f(x)=0 provided that f(x) is continuous on [a,b] and f(a).f(b)$<$0.\\\\\n\nThe secant method procedure is almost identical to the bisection method. The only difference it how we divide each subinterval.\n\nWith an initial interval satisfying the initial conditions(a1=a, b1=b), we first compute f($x_o$), where $x_o$ is given by the secant line \\[ x_o = a_o - f(a_o).\\frac{b_o - a_o}{f(b_o) - f(a_o)}\\]\n\nTo determine the next subinterval [$a_1, b_1$]:\n\\[if~~ f(a_o).f(x_o)<0 \\Rightarrow a_1=a_o, b_1=x_o\\]\n\\[if~~ f(b_o).f(x_o)<0 \\Rightarrow a_1=x_o, b_1=b_o\\]\n\nWe then find $x_1$ using the secant line formula and repeat the following steps till we reach son interval [$a_N, b_N$] which returns the value $x_N$, the x-intercept of the Nth subinterval\\\\\n\nHere too, we can set 2 control parameters as mentioned before.\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\centering\n\t\\includegraphics[width=0.6\\linewidth]{secm1}\n\t\\caption{Graphical Representation of Root Finding using Newton-Raphson Method}\n\t\\label{fig3}\n\\end{figure}\n\n\\subsubsection{Remarks}\nSecant Method is faster when compared to Bisection and Newton-Raphson methods as the order of convergence is higher in Secant Method. But there are some drawbacks too as follow:\n\\begin{enumerate}\n\t\\item \\textbf{It may not converge}\n\t\n\t\\item \\textbf{Derivative issues}\\\\\n\tIt is likely to have difficulty if f´(a) = 0 i.e the x-axis is tangent to the graph y=f(x) at x = a.\n\\end{enumerate}\n\n\\section{Results and Analysis}\nThe following results are obtained by keeping the permissible error $\\epsilon$ = 0.001, and varying the maximum number of iterations \\textit{N} for different root-finding methods.\n\nHere\n\\[ f1(x) = x^3 - 3x^2 - x + 9\\]\n\\[ f2(x) = (x^3 - 3x^2 - x + 9).e^x\\]\n\nFor each method, the results have been obtained for 2 sets of starting conditions. The below plots show the comparison between the results obtained.\n\\subsection{Interval Bisection Method}\n\\begin{figure} [h!]\n\t\\centering\n\t\\begin{subfigure}{0.55\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{bsm-f1-abs}\n\t\t\\caption{$\\|$f1(x)$\\|$ at the roots vs Max Number of Iterations}\n\t\t\\label{fig1:sub1}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{0.55\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{bsm-f2-abs}\n\t\t\\caption{$\\|$f2(x)$\\|$ at roots vs Max Number of Iterations}\n\t\t\\label{fig1:sub2}\n\t\\end{subfigure}\n\t\\caption{Results obtained using Bisection Method}\n\\end{figure}\n\n\\subsection{Newton-Raphson Method}\n\\begin{figure} [h!]\n\t\\centering\n\t\\begin{subfigure}{0.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{nrm-f1-abs}\n\t\t\\caption{$\\|$f1(x)$\\|$ at the roots vs Max Number of Iterations}\n\t\t\\label{fig2:sub1}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{0.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{nrm-f2-abs}\n\t\t\\caption{$\\|$f2(x)$\\|$ at the roots vs Max Number of Iterations}\n\t\t\\label{fig2:sub2}\n\t\\end{subfigure}\n\t\\caption{Results obtained using Newton-Ralphson Method}\n\\end{figure}\n\n\\subsection{Secant Method}\n\\begin{figure} [h!]\n\t\\centering\n\t\\begin{subfigure}{0.55\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{secm-f1-abs}\n\t\t\\caption{$\\|$f1(x)$\\|$ at the roots vs Max Number of Iterations}\n\t\t\\label{fig3:sub1}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{0.55\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{secm-f2-abs}\n\t\t\\caption{$\\|$f2(x)$\\|$ at roots vs Max Number of Iterations}\n\t\t\\label{fig3:sub2}\n\t\\end{subfigure}\n\t\\caption{Results obtained using Secant Method}\n\\end{figure}\n\n\\subsection{Comparison of Methods}\n\\begin{figure} [h!]\n\t\\centering\n\t\\begin{subfigure}{0.55\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{all-f1-abs}\n\t\t\\caption{$\\|$f1(x)$\\|$ at the roots vs Max Number of Iterations}\n\t\t\\label{fig4:sub1}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{0.55\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{all-f2-abs}\n\t\t\\caption{$\\|$f2(x)$\\|$ at roots vs Max Number of Iterations}\n\t\t\\label{fig4:sub2}\n\t\\end{subfigure}\n\t\\caption{Comparison of Results obtained}\n\\end{figure}\n\\pagebreak\n\\section{Special Case}\nTaking, \\[f_3(x) = x^3 - 2x + 2~~~and~~~x_o = 0\\]\nusing the Newton-Raphson Method to find the root, we get the following result.\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{special_case_newton-raphson}\n\t\\caption{Graphical Representation Special Case of Root Finding using Newton-Raphson Method}\n\t\\label{fig4}\n\\end{figure}\n\nHere we see one of the cases where the Newton-Raphson Method fails to converge to the root. The Starting Point is a part of a cycle.\n\nUsing,\\[x_{n+1} = x_n -\\frac{f(x_n)}{f'(x_n)}\\] and the fact that \\[f_3(x) = x^3 - 2x + 2 ~~ and ~~ f_3'(x) = 3x^2 - 2\\]\n\nFor $x_o = 0$, f$_3$(0) = 2 and f'$_3$(0) = -2, and thus we get \\[x_1 = 0 - \\frac{2}{-2} = 1\\]\n\nFor $x_1 = 1$, f$_3$(1) = 1 and f'$_3$(1) = 1, and thus we get \\[x_2 = 1 - \\frac{1}{1} = 0~~...\\]\nThis cycle goes on and we are not able to obtain the root. This is mentioned in the section 1.2.1 .\n\n\n\\section{Inference and Conclusion}\nIt is very rarely the case that one particular method is better than another in all instances. Typically different methods have different strengths and weaknesses which make them good for some problems but bad for others. This is why in numerical analysis, we like to keep a broad range of tools in our toolboxes.\\\\\n\nConsider, for example, a comparison of the bisection method and Newton’s method. When Newton’s method converges, it typically does so much faster than the Bisection method. We get the answer that we need with minimal computation, so it would seem that Newton’s method is better than the Bisection method. \n\nOn the other hand, we need to remember that Newton’s method does not always work. Since the iterative formula involves a division by the derivative of a function, the method will completely fail if that derivative is 0 for any particular iteration. The nice thing about the Bisection method is that as long as you start with an interval that contains the root, you are guaranteed to converge! So with a problem that makes Newton’s method fail, Bisection is clearly a better alternative.\\\\\n\nEvaluating the 3 methods of root-finding, we can see that while Bisection is very slow, it is always guaranteed to find a root once the process begins.\nCompare this to Newton’s Method, which doesn’t have such guarantees.This is pretty typical behavior for the two algorithms since Bisection has linear convergence while Newton’s method quadratic convergence.\n\nBisection only requires function evaluations, but Newton’s Method also requires a first deriva-\ntive. You may take this for granted in an academic setting, but in practical situations finding\nthe derivative can be impractical or expensive compared to a function evaluation. One way\nto get around finding exact expressions for the derivative is to use a finite difference ap-\nproximation for the derivative. The workaround is to use the Secant Method (Poor Man’s Newton Method), which approximates the derivative by the slope of a secant line. But this requires two starting guesses which are hopefully close to the root.\\\\\n\nA more efficient method though is a combination of the two — simply, start with the bisection until you get a rough estimate of the root, then use Newton’s method to refine your estimate.\\\\\n\n\nWe can even tweak either of these methods to make them work better, and thus there are many more variations, but again, each has its own strengths and weaknesses.\\\\\n\n\\section{References}\n\\begin{enumerate}\n\t\\item  https://x-engineer.org/undergraduate-engineering/advanced-mathematics/numerical-methods/the-bisection-method-for-root-finding/ \t\n\t\\item https://silviaximenametodos.blogspot.com/2010/06/bisection-method$\\_$29.html\n\t\\item https://www.tf.uni-kiel.de/matwis/amat/comp$\\_$math/kap$\\_$1/backbone/r$\\_$se19.html\n\t\\item https://predictivehacks.com/newton-raphson-method-in-python/\n\t\\item https://en.wikipedia.org/wiki/Newton's$\\_$method\n\t\\item https://www.quora.com/What-is-the-Newton-Raphson-method\n\t\\item https://secure.math.ubc.ca/~pwalls/math-python/roots-optimization/secant/\n\t\\item https://en.wikipedia.org/wiki/Secant$\\_$method\n\t\\item http://www.numericmethod.com/About-numerical-methods/roots-of-equations/secant-method\n\\end{enumerate}\n\n\n\n\n\\end{document}", "meta": {"hexsha": "1d5ed4d8d7fc977089ac3147b49915d9c55bf3be", "size": 16924, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "AS2101_Labwork/4.Submissions/Task 3/Task3.tex", "max_stars_repo_name": "kirtan2605/Coursework_Codes", "max_stars_repo_head_hexsha": "3455496e8ec0ae3a576cb3fc3b2ed01a055149c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "AS2101_Labwork/4.Submissions/Task 3/Task3.tex", "max_issues_repo_name": "kirtan2605/Coursework_Codes", "max_issues_repo_head_hexsha": "3455496e8ec0ae3a576cb3fc3b2ed01a055149c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "AS2101_Labwork/4.Submissions/Task 3/Task3.tex", "max_forks_repo_name": "kirtan2605/Coursework_Codes", "max_forks_repo_head_hexsha": "3455496e8ec0ae3a576cb3fc3b2ed01a055149c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.968641115, "max_line_length": 550, "alphanum_fraction": 0.7588631529, "num_tokens": 4572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8333245911726381, "lm_q2_score": 0.8933093989533707, "lm_q1q2_score": 0.7444166896734927}}
{"text": "\n\\subsection{Strong rules}\n\n\\subsubsection{Strong rules}\n\nWe use frequent patterns to generate strong rules, \\(R\\).\n\nAn example of a strong rule is \\(a\\rightarrow b\\).\n\nWe can look at this by comparing the support of \\(a\\) to \\(a\\land b\\).\n\n\\(supp(A\\rightarrow B)=P(A\\land B)\\)\n\n\\(conf(A\\rightarrow B)=P(B|A)\\)\n\n\\(conf(A\\rightarrow B)=\\dfrac{P(A\\land B)}{P(A)}\\)\n\n", "meta": {"hexsha": "20eeb99d7dd0d315a42fac0cfaa2a44fe1c1fbdd", "size": 364, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/association/01-02-strong.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/association/01-02-strong.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/association/01-02-strong.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.2222222222, "max_line_length": 70, "alphanum_fraction": 0.6675824176, "num_tokens": 113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541626630935, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.744406165286681}}
{"text": "\\lab{Applications}{Riemann Sphere and Mobius Transformations}{Riemann Sphere and Mobius Transformations}\n\n\\objective{Understand the Riemann Sphere in graphics applications.}\n\nWe have now examined several applications of complex numbers and functions.\nIn this lab we extend several of these ideas and develop some intuition about the Riemann sphere using visualization techniques in Python.\n\nRecall that the complex numbers are an extension of the real numbers that include the imaginary numbers.\nWe extend them even further in this section and examine the extended complex numbers.\nSimilar to the extended real numbers, the extended complex numbers are our regular set of complex numbers with the addition of a point at infinity.\nThis allows us to examine, for example, certain quotients that are undefined on the standard complex numbers.\n\nThe Riemann sphere construction allows a compact and intuitive construction of the extended complex numbers.\nConsider the standard complex plane, only now in 3-space instead of a 2 dimensional plane.\nLet the $x$-axis correspond to the real part of the complex numbers and let the $y$-axis correspond to the imaginary part.\nLet $z=0$ for all $x$ and $y$. \n\nNow consider a the unit sphere centered at $(0,0,1)$ combined with the complex numbers in 3-space.\nWe may map every point of the extended complex plane onto this sphere.\nLet infinity correspond to the point $(0,0,2)$ at the very top of the sphere.\nFor all other points on the complex plane consider the line between the point on the complex plane and the point at the top of the sphere.\nLet each point of the complex plane map to the point where this line intersects with the surface of the sphere.\nNote that for any complex number, there is exactly one such point.\nThis construction is illustrated in Figure \\ref{riemann:stereographic}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{StereographicIllustration.png}\n\\caption{Stereographic projection of a point in the complex plane onto the unit sphere.}\n\\label{riemann:stereographic}\n\\end{figure}\n\n\\begin{problem}  Write a function that, given a complex number, returns the coordinates of the corresponding point on the riemann sphere in 3-space.\n\\end{problem}\n\n\\begin{problem}\nWrite a function that, given the coordinates of a point on the Riemann Sphere, returns the corresponding point on the complex plane.\nIf the input point is $(0,0,2)$ have your function return \"infinity.\"\n\\end{problem}\n\n\\section*{Mobius Transformations}\n\nRecall from the previous chapter that a conformal mapping is a complex function that preserves angles between lines.\nWe now examine a special kind of conformal mapping called a Mobius transformation (not to be confused with the Mobius Transform), or a fractional linear transformation.\nWe first give the definition of a fractional linear transformation, and then examine what sorts of transformations we can do with them.\n\n\\begin{definition} A fractional linear transformation is a any complex function of the form\n\\[\nf(z) = \\frac{az + b}{cz + d}\n\\]\n Where a, b, c, and d are complex numbers with the restriction that $ad \\neq bc$.\n\\end{definition}\n\nFractional linear transformations are versatile enough to include translations, rotations, magnifications, or any combination of the same, of shapes in the complex plane.\nFor example, if we wish to magnify the unit disk by a factor of 2 and then translate it up 2 along the imaginary axis, we would use the following transformation:\n\\[\nf(z)=2z+2i\n\\]\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{mobius1.png}\n\\caption{The unit disk and its image under the transformation $2z+2i$.}\n\\label{riemann:mobius1}\n\\end{figure}\n\n\\begin{problem} Write a Python function that accepts arguments $a,b,c,$ and $d$.\nPerform the corresponding fractional linear transformation on a grid inside the box $[-1,1]\\times[-i,i]$, and then visualize the box before and after the transformation on the same plot, but using different colors.\n\\end{problem}\n\nWe now will mention some of the important properties of fractional linear transformations.\n\nWith some manipulation, it can be shown that:\n\n$$\\frac{az+b}{cz+d}=\\frac{a}{c}+\\frac{bc-ad}{c} \\frac{1}{cz+d}$$\n\nThis implies that any fractional linear transformation can be represented as the composition of the functions $\\alpha x$, $x+\\beta$, and $\\frac{1}{x}$ where $\\alpha$ and $\\beta$ are complex. \n\nThis allows us to determine some things about the properties of fractional linear transformations.\nSince each of those functions is holomorphic wherever it is defined, we may say the same of their composition.\nIn other words, our fractional linear transformation is holomorphic except at $z=-\\frac{d}{c}$, or if $c=0$, the transformation is holomorphic at all points in the complex plane. \n\nSince fractional linear transformations are holomorphic, they are also conformal.\nThis can also be readily derived by considering a fractional linear transformation as the composition of the functions above.\nIf each of the functions above is conformal on a domain, their composition will also be conformal on that domain. \n\nWe will now consider the effects of fractional linear transformations on points of the Riemann Sphere.\nFigures \\ref{riemann:mobius2} and \\ref{riemann:mobius3} show a grid on the complex plane, it's projection onto the Riemann Sphere, the image of the grid under the transformation $\\frac{1}{z}$, and it's projection onto the Riemann Sphere. \n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{mobius2.png}\n\\caption{The Riemann Sphere witha $3\\times 3$ grid projected onto it.}\n\\label{riemann:mobius2}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{mobius3.png}\n\\caption{The images of the Riemann Sphere and the $3\\times 3$ grid shown in Figure \\ref{riemann:mobius2} under the transformation $\\frac{1}{z}$.}\n\\label{riemann:mobius3}\n\\end{figure}\n\nNotice how both circles and lines on the complex plane are circles on the Riemann Sphere.\nA line on the complex plane is really just a circle on the Riemann Sphere that passes through the point at infinity.\nAn interesting property of fractional linear transformations is that they are circle preserving.\nThis means that the image of a circle on the Riemann Sphere under any fractional linear transformation is also a circle on the Riemann Sphere.\nIn terms of the standard complex plane, we may say that the image of any circle or line is a circle or line.\n\nThis can be proven analytically by considering the equation of a circle on the complex plane.\nLet $z=a=bi$.\nFor some circle centered at a point $E=\\alpha + \\beta i$ with radius $r$, $a$ and $b$ will satisfy the equation $(a-\\alpha)^2+(b-\\beta)^2=r^2$.\nExpanding this expression and simplifying we have:\n$$a^2-b^2-2a\\alpha-2b\\beta+\\alpha^2+\\beta^2-r^2=0$$\nLetting $D=\\alpha^2+\\beta^2-r^2$, we may rewrite the above equation as follows:\n$$z\\bar{z}+E\\bar{z}+\\bar{E}z+D=0$$\nThis gives motivation for the general equation of a circle in the complex plane.\n$$Az\\bar{z}+E\\bar{z}+\\bar{E}z+D=0$$\nWhere $A$ and $D$ are real and $E$ is complex.\nIf $A\\neq 0$ and $E\\bar{E}-AD>0$ then this is the equation of a circle.\nNote that if $A=1$, $E$ is the center of the circle.\nIf $A=0$ then this is the equation of a line (or a circle through infinity on the Riemann Sphere).\n\nNow to see that a fractional linear transformation is circle preserving, recall that it can be represented as the composition of the functions $\\alpha x$, $x+\\beta$, and $\\frac{1}{x}$ where $\\alpha$ and $\\beta$ are complex.\nIf each of these functions is circle preserving, their composition will also be circle preserving, and we will have the desired result. \n\nThe function $x+\\beta$ is a translation and will clearly be circle preserving.\n\nLetting $z=\\alpha w$, we have: \n$$A\\alpha \\bar{\\alpha} w\\bar{w}+\\bar{E}\\alpha z+E\\bar{\\alpha} \\bar{z}+D=0$$\nwhich may be rewritten as:\n$$A|\\alpha|^2 w\\bar{w}+\\bar{(E\\bar{\\alpha})}z+E\\bar{\\alpha} \\bar{z}+D=0$$\nwhich is still the equation of a circle, so the function $\\alpha z$ is also circle preserving.\n\nNow, letting $z=\\frac{1}{w}$, we have:\n$$\\frac{A}{w\\bar{w}}+\\frac{\\bar{E}}{w}+\\frac{E}{\\bar{w}}+D=0$$\nwhich we may rewrite as:\n$$Dw\\bar{w}+\\bar{E}\\bar{w}+Ew+A=0$$\nwhich is, again, the equation of a circle.\n\nSince each of these functions is circle preserving, any composition of these functions will also be circle preserving, so all fractional linear transformations are circle preserving.\n\n\\begin{problem}\nWrite a python function which accepts the constants $a$, $b$, $c$, and $d$ and returns the constants $A$, $E$, and $D$ of the general equation of the image of the unit circle under the corresponding fractional linear transformation.\nYou may say, without loss of generality, that $A=1$.\n\\end{problem}\n\nFractional linear transformations have varied effects on the Riemann Sphere.\nA simple example is the transformation $e^{\\frac{\\pi i}{4}}z$ which rotates the entire complex plane 45 degrees.\nThis transformation is shown in Figure \\ref{riemann:mobius4}.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{mobius4.png}\n\\caption{The images of the Riemann Sphere and the $3\\times 3$ grid shown in Figure \\ref{riemann:mobius2} under the transformation $e^{\\frac{\\pi i}{4}}z$.}\n\\label{riemann:mobius4}\n\\end{figure}\n\nWe can also rotate the Riemann Sphere in other directions.\nThe transformation $\\frac{2z+4}{-iz+2i}$ rotates the Riemann sphere 90 degrees in the x-z plane.\nFigure \\ref{riemann:mobius5} is a plot of the same grid under that transformation.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{mobius5.png}\n\\caption{The images of the Riemann Sphere and the $3\\times 3$ grid shown in Figure \\ref{riemann:mobius2} under the transformation $\\frac{2z+4}{-iz+2i}$.}\n\\label{riemann:mobius5}\n\\end{figure}\n\n\\begin{problem}\nThe matrix representation of the fracional linear transformation $\\frac{az+b}{cz+d}$ is:\n\\[\n\\begin{pmatrix}\na&b\\\\\nc&d\n\\end{pmatrix}\n\\]\nProve that for two fractional linear transformation $f$ and $g$ with matrix representations $F$ and $G$ that the matrix representation of $f(g(z))$ is $FG$.\n\\end{problem}\n\n\\begin{problem}\nIt turns out that we can define a fractional linear transformation by specifying 3 points and their images under the transformation.\nWrite a python function that accepts two lists of three complex numbers and returns the matrix representation of the fractional linear transformation that maps the numbers of the first list to the numbers of the second list.\n\\end{problem}\n", "meta": {"hexsha": "96588e28ec5350748ea5c685f3d1981c25582d18", "size": 10428, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/RiemannSphere/RiemannSphere_C.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/RiemannSphere/RiemannSphere_C.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/RiemannSphere/RiemannSphere_C.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.2569832402, "max_line_length": 238, "alphanum_fraction": 0.7687955504, "num_tokens": 2658, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.875787001374006, "lm_q1q2_score": 0.7443937071834861}}
{"text": "\\subsection{The Auxiliary Equation}\r\n\\noindent\r\nIt's not a coincidence that the coefficients of the polynomial that we had to find the 0's of in the above example matched the coefficients of the differential equation. We call this polynomial the auxiliary equation, and it can help us solve linear, homogeneous differential equations with constant coefficients of any order.\r\n\\begin{definition}\r\n\tA nth order, linear, homogeneous differential equation with constant coefficients has the form\r\n\t\\begin{equation*}\r\n\t\ta_ny^{(n)} + a_{n-1}y^{(n-1)} + \\ldots + a_1y' + a_0y = 0\r\n\t\\end{equation*}\r\n\tThe corresponding auxiliary equation is\r\n\t\\begin{equation*}\r\n\t\ta_nr^n + a_{n-1}r^{n-1} + \\ldots + a_1r + a_0 = 0\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\r\n\\noindent\r\nWe now have a method for solving these equations with the roots of the auxiliary equation are all unique. \r\n\\begin{theorem}\r\n\tLet $\\left\\{r_1, \\ldots, r_n\\right\\}$ be the set of unique roots to an auxiliary equation corresponding to a nth order, linear, homogeneous differential equation with constant coefficients. The set of fundamental solutions are $\\left\\{C_1e^{r_1x}, \\ldots, C_ne^{r_nx}\\right\\}$, and the general solution is\r\n\t\\begin{equation*}\r\n\t\ty = C_1e^{r_1x} + \\ldots + C_ne^{r_nx}\r\n\t\\end{equation*}\r\n\\end{theorem}\r\n\r\n\\noindent\r\nWe can easily extend this method to deal with roots of higher multiplicities.\r\n\\begin{theorem}\r\n\tLet $\\alpha$ be a root with multiplicity $k$ to an auxiliary equation corresponding to a nth order, linear, homogeneous differential equation with constant coefficients. Then $e^{\\alpha x}, xe^{\\alpha x}, \\ldots, x^{k-1}e^{\\alpha x}$ are fundamental solutions.\r\n\\end{theorem}\r\n\r\n\\input{./higherOrder/constCoeffs/complexRoots.tex}", "meta": {"hexsha": "a0a9f5634ffeb9bf5b319c4c29709bec0b0633f1", "size": 1723, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/constCoeffs/auxillaryEquation.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/higherOrder/constCoeffs/auxillaryEquation.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/higherOrder/constCoeffs/auxillaryEquation.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.4333333333, "max_line_length": 327, "alphanum_fraction": 0.7405687754, "num_tokens": 483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7443936983978766}}
{"text": "\\chapter{Logarithms}\n\nAfter the world had created exponents, it needed the opposite. We\ncould talk about the quantity $? = 2^3$, that is, ``What is the\nproduct of 2 multiplied by itself three times?''  We needed some way\nto talk about $2^? = 8$, that is ``2 to the what is 8?'' So we\ndeveloped the logarithm.\\index{logarithm} \\index{log}\n\nHere is an example:\n\n$$\\log_{2}8 = 3$$\n\nIn English, you would say ``The logarithm base 2 of 8 is 3.''\n\nThe base (2, in this case) can be any positive number. The argument\n(8, in this case) can also be any positive number.\n\nTry this one: What is the logarthim base 2 of 1/16?\n\nYou know that $2^{-4} = \\frac{1}{16}$, so $\\log_{2} \\frac{1}{16} = -4$.\n\n\\section{Logarithms in Python}\n\nMost calculators have pretty limited logarithm capabilities, but\npython has a nice \\pyfunction{log} function that lets you specify both\nthe argument and the base.  Start python, import the math module, and try taking a few logarithms:\\index{log!in python}\n\n\\begin{Verbatim}\n>>> import math\n>>> math.log(8,2)\n3.0\n>>> math.log(1/16, 2)\n-4.0\n\\end{Verbatim}\n\nLet's say that a friend offers you 5\\% interest per year on your\ninvestment for as long as you want. And you wonder, ``How many years\nbefore my investment is 100 times as large?'' You can solve this problem with logarithms:\n\n\\begin{Verbatim}\n>>> math.log(100, 1.05)\n94.3872656381287\n\\end{Verbatim}\n\nIf you leave your investment with your friend for 94.4 years, the\ninvestment will be worth 100 times what you put in.\n\n\\section{Logarithm Identities}\n\nThe logarithm is defined this way:\\index{logarithm!identities}\n\n$$\\log_b a = c \\iff b^c = a$$\n\nNotice that the logarithm of 1 is always zero, and $\\log_b b = 1$.\n\nThe logarithm of a product:\n\n$$\\log_b a c = \\log_b a + \\log_b c$$\n\nThis follows from the fact that $b^{a + c} = b^a b^c$. What about a quotient?\n\n$$\\log_b \\frac{a}{c} = \\log_b a - \\log_b c$$\n\nExponents?\n\n$$\\log_b \\left(a^c\\right) = c \\log_b a$$\n\nNotice that because logs and exponents are the opposite of each other, they can cancel each other out:\n\n$$b^{\\log_b a} = a$$\n\nand\n\n$$\\log_b \\left(b^a\\right) = a$$\n\n\\section{Changing Bases}\n\nI mentioned that most calculators have pretty limited logarithm\ncapabilities. Most calculators don't allow you to specify what base\nyou want to work with. All scientific calculators have a button for\n``log base 10''.  So you need to know how to use that button to get\nlogarithms for other bases.  Here is the change-of-base identity:\\index{logarithm!change of base}\n\n$$\\log_b a = \\frac {\\log_c a}{\\log_c b}$$\n\nSo, for example, if you wanted to find $\\log_2 8$, you would ask the\ncalculator for $\\log_{10} 8$ and then divide that by $\\log_{10} 2$.\nYou should get 3.\n\n\\section{Natural Logarithm}\n\nWhen you learn about circles, you are told that the circumference of a\ncircle is about 3.141592653589793 times its diameter.  Because we use\nthis unweildy number a lot, we give it a name: We say ``The\ncircumference of a circle is $\\pi$ times its diameter.''\n\nThere is a second unweildy number that we will eventually use a lot in\nsolving problems.  It is about 2.718281828459045 (but the digits\nactually go on forever, just like $\\pi$). We call this number $e$. (I'm\nnot going to tell you why $e$ is special now, but soon...)\\index{e}\\index{logarithm!natural}\n\nMost calculators have a button labeled ``ln''.  That is the\n\\textit{natural logarithm} button. It takes the log in base $e$.\\index{ln}\n\nSimilarly, in python, if you don't specify a base, the logarithm is done in base $e$:\n\n\\begin{Verbatim}\n>>> math.log(10)\n2.302585092994046\n>>> math.log(math.e)\n1.0\n\\end{Verbatim}\n\n\\section{Logarithms in Spreadsheets}\n\nSpreadsheets have three log functions:\n\\begin{itemize}\n\\item \\pyfunction{LOG} takes both the argument and the base. \\pyfunction{LOG(8,2)} returns 3.\n\\item \\pyfunction{LOG10} takes just the argument and uses 10 as the base.\n\\item \\pyfunction{LN} takes just the argument and uses $e$ as the base.\n\\end{itemize}\n\nHere is a plot from a spreadsheet of a graph of $y = LOG(x, 2)$.\n\n\\includegraphics[width=0.8\\textwidth]{log_graph.png}\n\nSpreadsheets also have the function \\pyfunction{EXP(x)} which returns\n$e^x$.  For example, \\pyfunction{EXP(2)} returns 7.38905609893065.\n\n", "meta": {"hexsha": "272eb4009cddad7e13eaf2a6e3f967ef870ee7e7", "size": 4202, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Spreadsheets/logs-en_US.tex", "max_stars_repo_name": "rajivjhoomuck/sequence", "max_stars_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/Spreadsheets/logs-en_US.tex", "max_issues_repo_name": "rajivjhoomuck/sequence", "max_issues_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/Spreadsheets/logs-en_US.tex", "max_forks_repo_name": "rajivjhoomuck/sequence", "max_forks_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 32.3230769231, "max_line_length": 119, "alphanum_fraction": 0.7237029986, "num_tokens": 1281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711642563823, "lm_q2_score": 0.8757869981319863, "lm_q1q2_score": 0.7443936944428465}}
{"text": "\\section{Analysis}\n\n\\subsection{Analytical}\n\nThis section will detail the time complexity of each method.\\\\\n\n\\begin{table}[t]\n\\centering\n\\begin{tabular}[t]{| l | l |}\n\t\\hline\n\t\\multicolumn{2}{| c |}{\\code{RedBlackTree}} \\\\ \\hline\n\t\\textbf{Method} & \\textbf{Time complexity} \\\\ \\hline\n\t\\code{isEmpty()} & O(1) \\\\ \\hline\n\t\\code{contains(Object)} & O(log n) \\\\ \\hline\n\t\\code{hasPredecessor(Object)} & O(1) \\\\ \\hline\n\t\\code{hasSuccessor(Object)} & O(1) \\\\ \\hline\n\t\\code{predecessor(Object)} & O(log n) \\\\ \\hline\n\t\\code{successor(Object)} & O(log n) \\\\ \\hline\n\t\\code{min()} & O(1) \\\\ \\hline\n\t\\code{max()} & O(1) \\\\ \\hline\n\t\\code{add(Object)} & O(log n) \\\\ \\hline\n\t\\code{delete(Object)} & O(log n) \\\\ \\hline\n\t\\code{iterator()} & O(1) \\\\ \\hline\n\t\\code{iterator(Object)} & O(log n) \\\\ \\hline\n\t\\code{toString()} & O(n) \\\\ \\hline\n\\end{tabular}\n\\begin{tabular}[t]{| l | l |}\n\t\\hline\n\t\\multicolumn{2}{| c |}{\\code{TreeIterator}} \\\\ \\hline\n\t\\textbf{Method} & \\textbf{Time complexity} \\\\ \\hline\n\t\\code{hasNext()} & O(1) \\\\ \\hline\n\t\\code{next()} & O(log n) \\\\ \\hline\n\t\\code{remove()} & O(log n) \\\\ \\hline\n\\end{tabular}\n\\caption{Summary of time complexity of each method.}\n\\end{table}\n\nRed-black trees have five main properties:\n\\begin{enumerate}\n\\item A node is either black or red.\n\\item The root node is black.\n\\item Every leaf node is black.\n\\item A red node has black children.\n\\item Every path from a node to a leaf descendent contains the same number of black nodes.\n\\end{enumerate}\n\nSince the height of the tree is referenced in demonstrating the worst-case time complexity of almost every method in the class, I first prove the following limit on the height of a red-black tree \\cite{clrs}:\n\\begin{equation*}\nh \\leq 2\\log_2(n+1)\n\\end{equation*}\n\\begin{proof}\nTo begin, we prove that a subtree with root node $n$ has a minimum of $2^{h_b(n)} - 1$ internal nodes (where $b_h(n)$, the `black-height' of $n$, is the number of black nodes on any path from the node $n$ to any leaf, not including $n$): we do this by induction. For the base case - if the black height of $n$ is zero, then $n$ must be a leaf - and so $2^0 - 1 = 0$ is the number of internal nodes. So it holds for $b_h(n) = 0$. Now we assume that a node $n$ has a positive height and two children (i.e. $n$ is an internal node). Then each child must have a height of $b_h(n)$ or $b_h(n) - 1$, depending on the colour of the child. We can then apply the inductive hypothesis to the children - then each child has $2^{b_h(n) - 1} - 1$ internal nodes. Therefore we can simply sum the number of internal nodes of the two child subtrees to prove the claim - the subtree rooted at $n$ will have at least $(2^{b_h(n) - 1} - 1) + (2^{b_h(n) - 1} - 1) + 1 = 2^{b_h(n)} - 1$ internal nodes.\n\nWith the above combined with red-black tree properties, we can complete the proof: if we have a tree of height $h$, then according to the fourth property of red-black trees, at least half of the nodes on any path from the root to a given leaf (not including the root) are black. So $b_h(r) \\geq \\frac{h}{2}$, where $r$ is the root node of the tree. Then $n \\geq 2^{\\frac h 2} - 1$, and $h \\leq 2\\log_2(n + 1)$ follows.\n\\end{proof}\n\n\\subsubsection{\\code{isEmpty()}}\nThis method performs a single null-check of the root node and is independent of the number of elements in the tree. Thus \\code{isEmpty()} runs in constant time O(1).\n\n\\subsubsection{\\code{contains(Object)}}\nThis method calls the helper method \\code{locate(Node)} which is linear in the height of the tree. \\code{locate(Node)} performs a basic iterative binary tree search, moving down the tree and comparing the node with the argument, then moving to the left or right child depending on the result of \\code{compareTo}. A binary tree search is linear in the height of the tree (O(h)) and since the height of a red-black tree is guaranteed to be logarithmic, the time complexity of this method is thus O(log n).\n\n\n\\subsubsection{\\code{hasPredecessor(Object)} and \\code{hasSuccessor(Object)}}\nThese methods make a single comparison with the current minimum/maximum of the dictionary, to ensure that there is a smaller/larger element in the dictionary. Since the extremum of the dictionary can be accessed in constant time, this comparison is independent of the size of the dictionary, so these methods are O(1).\n\n\\subsubsection{\\code{predecessor(Object)} and \\code{successor(Object)}}\nThese methods call the internal methods \\code{below(Node)} and \\code{above(Node)} respectively: I will show that \\code{below(Node)} runs in logarithmic time, and then \\code{above(Node)} is symmetric to this. \\code{below(Node)} starts at the root and then navigates down the tree in a similar fashion to \\code{locate(Node)}, generally moving to the right child if the argument is larger than the current node, and moving left if it's less than or equal to the current node. Since it moves strictly down the tree, it can iterate at most $h$ times - therefore being logarithmic.\nOnce it reaches some point in the tree - (where the right/left child is \\code{nil}) then it will, in the worst case, need to return call the \\code{predecessor(Node)} method and return the result. Since the \\code{predecessor(Node)} method also runs in O(log n) time (it either returns the maximum node of the left subtree or moves up the tree until it finds a node which is a right child), then the total time is on the order of O(log n + log n) = O(log n).\n\n\\subsubsection{\\code{min()} and \\code{max()}}\nThese two methods run in constant time as fields referencing the current minimum and maximum are kept updated upon insertions and deletions to the dictionary. So \\code{min()} and \\code{max()} simply access these fields, making them O(1).\n\n\\subsubsection{\\code{add(Object)}}\n\\code{add(Object)} first creates a new \\code{Node} and calls the \\code{insert(Node)} helper method, which is analogous to \\code{RB-INSERT(T, z)} in CLRS. A summary of the non-trivial parts of the method follows:\nfirst, the place to insert the new node in the tree is located - this takes at O(h) time since it moves strictly down the tree each iteration, and does constant time work inside the loop. After this is done, the node is made red and then the tree properties are restored using \\code{fixInsert(Node)}. \\code{fixInsert(Node)} is analogous to \\code{RB-INSERT-FIXUP(T, z)} in CLRS. The while loop in \\code{fixInsert(Node)} only repeats if the node's uncle is red, and if this occurs we move two levels up (or possibly terminate the loop). Everything inside the while loop takes constant time (in particular note that \\code{rotateLeft(Node)} and \\code{rotateRight(Node)} do constant work - they have O(1) time complexity). Therefore \\code{fixInsert(Node)} is O(h) $\\implies$ the whole insertion procedure takes O(log n) time.\n\nNote that if an item is successfully inserted into the dictionary, it is then compared with the minimum and maximum fields to check if we need to update them. This is a constant time procedure and doesn't affect the time complexity of \\code{add(Object)}. \n\n\\subsubsection{\\code{delete(Object)}}\n\\code{delete(Object)} was also implemented using CLRS as a foundation. Firstly note that the \\code{transplant(Node)} method runs in constant time since it simply replaces one subtree as a child of its parent with another subtree by modifying references, and is independent of the size of the tree. With this, we can see that the internal method \\code{delete(Node)}, at worst, takes O(log n) time when it has to find the minimum node of the right child's subtree. Then at the end of the method \\code{fixDelete(Node)} is called, which also takes O(log n) time: the while loop in the method only repeats when node's sibling is black and both of the sibling's children are black - in which case each iteration we move up the tree by assigning \\code{node = node.parent}. This can only happen at most O(h) times, so the overall complexity of \\code{delete(Object)} is O(log n).\n\nNB: if the element that was deleted was the minimum or maximum element in the dictionary, then \\code{minimum(Node)}/\\code{maximum(Node)} will be called with the root as the argument, in order to update the minimum/maximum references. This does not affect the time complexity, as O(2 log n) = O(log n).\n\n\\subsubsection{\\code{iterator()}}\nFirstly: the constructor for the internal class \\code{TreeIterator} runs in O(1) time, since it is passed the start node as an argument and stores this reference in a field in preparation for the first call to \\code{next()}. Since for this method we start at the minimum element in the dictionary and iterate through to the maximum, and we can access the minimum element in constant time and simply pass it as a parameter to the \\code{TreeIterator} constructor, the whole method takes O(1) time.\n\n\\subsubsection{\\code{iterator(Object)}}\nThis method, although similar in functionality to \\code{iterator()} does \\textit{not} take constant time: it first needs to find the least node with key greater than the input argument. The method makes a call to the private method \\code{ceiling(Node)}. The method \\code{ceiling(Node)} is very similar in functionality to \\code{above(Node)}, which is used in \\code{successor(Object)} - \\code{ceiling(Node)} just has a different edge case, and so it also runs in O(log n).\n\nIn addition to the time complexity analysis of returning a new iterator, I will also briefly detail the time complexity of the methods in the \\code{TreeIterator} class: clearly \\code{hasNext()} takes O(1) since it simply performs a `nil-check'; \\code{remove()} takes O(log n) since it calls \\code{delete(Node)}, which is shown to be O(log n) above; \\code{next()} also takes O(log n) since it calls the \\code{successor(Node)} method, and as above \\code{successor(Node)} runs in O(log n). Therefore iterating through the dictionary takes time O(n log n).\n\nI expect there is a more efficient way to do iteration - e.g. using a stack and pushing the left subtree onto the stack/pushing right child and its left subtree onto the stack with each call to \\code{next()}. Although I had this strategy working for iteration over the full tree, I could not find a way to successfully iterate in this fashion when given some start node that is not the minimum.\n\n\\subsubsection{\\code{getLogString()}}\n\\code{getLogString()} retrieves the string value of the \\code{StringBuilder} log field and then resets the log. This is independent of the number of elements in the dictionary, therefore running in O(1) time.\n\n\\subsubsection{\\code{toString()}}\nThis method was adapted from a \\href{http://stackoverflow.com/}{StackOverflow} post \\cite{stackoverflow}. The interface method \\code{toString()} calls the \\code{toString()} method of the root node, which is a recursive method that prints out the node itself and the string representation of its two children. This method will therefore consider each node in the dictionary only once, making the method O(n).\n\n\\subsection{Empirical}\n\nThis section gives experimental data on the efficiency of the implementation. The efficiency is quantified by the number of comparisons made when performing an operation in the \\code{Dictionary} interface.\n\nFor demonstration of experimental correctness, refer to the JUnit tests which can be found in the \\code{/test/java/DictionaryTest.java} file. JUnit 4.12 was used, and all tests passed at the time of project submission.\n\nExperimental data was obtained by repeatedly running a given method and averaging the result. Each run, the elements are randomly shuffled before being inserted into the dictionary to allow for various internal structures. MATLAB R2014a was used for data visualisation in the figures for \\code{add}, \\code{delete} and \\code{contains}.\n\nFor \\code{add}, \\code{delete} and \\code{contains}, plot data was averaged over 100 trials. Each trial recorded the number of comparisons made on dictionaries of size ranging from 0 to 10,000.\n\nPlots of the growth of the number of comparisons for adding, deleting and searching are below. Both linear-linear and log-linear graphs are provided to demonstrate the logarithmic growth of the functions.\n\nFor the other methods required by the \\code{Dictionary} interface, the average number of comparisons made on a 10,000-element dictionary is given in the table below. These results were averaged over 100 trials. For all tests, a new dictionary was created each time and the 10,000 elements were inserted in random order. This allows for a range of different possible tree structures to even out any possible biases in any individual trial.\n\n\\begin{table}[!htbp]\n\\centering\n\\begin{tabular}{| l | l | l |}\n\t\\hline\n\t\\textbf{Method} & \\multicolumn{2}{c |}{\\textbf{Comparisons}} \\\\ \\hline\n\t& \\textbf{Item in dictionary} & \\textbf{Item not in dictionary} \\\\ \\hline\n\t\\code{isEmpty()} & \\multicolumn{2}{l |}{0.0}  \\\\ \\hline\n\t\\code{contains(Object)} & 12.8 & 13.2 \\\\ \\hline\n\t\\code{hasPredecessor(Object)} & \\multicolumn{2}{l |}{1.0} \\\\ \\hline\n\t\\code{hasSuccessor(Object)} & \\multicolumn{2}{l |}{1.0}  \\\\ \\hline\n\t\\code{predecessor(Object)} & 14.3 & 13.6 \\\\ \\hline\n\t\\code{successor(Object)} & 14.1 & 14.0 \\\\ \\hline\n\t\\code{min()} & \\multicolumn{2}{l |}{0.0}  \\\\ \\hline\n\t\\code{max()} & \\multicolumn{2}{l |}{0.0}  \\\\ \\hline\n\t\\code{add(Object)} & 12.8 & 15.3 \\\\ \\hline\n\t\\code{delete(Object)} & 13.4 & 13.1 \\\\ \\hline\n\t\\code{iterator()} & \\multicolumn{2}{l |}{0.0} \\\\ \\hline\n\t\\code{iterator(Object)} & 12.9 & 14.1 \\\\ \\hline\n\t\\code{toString()} & \\multicolumn{2}{l |}{0.0} \\\\\n\t\\hline\n\\end{tabular}\n\\caption{Mean number of comparisons made on a dictionary of 10,000 elements, averaged over 100 trials and split into two columns depending on whether the argument is in the dictionary or not.}\n\\end{table}\n\nTable 3 is consistent with the analysis section. The constant time methods take 0 or 1 comparisons. \\code{contains(Object)} takes slightly longer if the element is not in the dictionary (since it has to search down the full height of the tree). \\code{add(Object)} takes around 2-3 comparisons more if the item is not already in the dictionary, since it also needs to check if it is necessary to update the \\code{min}/\\code{max} fields. \\code{delete(Object)} takes more comparisons if the element is not in the dictionary, for the same reason as \\code{contains(Object)}.\n\n\\begin{figure}[!htbpp]\n    \\centering\n    \\includegraphics[width=0.49\\textwidth]{resources/add}\n    \\includegraphics[width=0.49\\textwidth]{resources/add_log}\n    \\caption{The number of comparisons made when adding a random distinct element to a dictionary of size \\textit{n} (linear and log-linear scale)}\n\n\\end{figure}\n\n\\begin{figure}[!htbp]\n    \\centering\n    \\includegraphics[width=0.49\\textwidth]{resources/del}\n    \\includegraphics[width=0.49\\textwidth]{resources/del_log}\n    \\caption{The number of comparisons made when deleting a random element from a dictionary of size \\textit{n} (linear and log-linear scale)}\n\\end{figure}\n\n\\begin{figure}[!htbp]\n    \\centering\n    \\includegraphics[width=0.49\\textwidth]{resources/search}\n    \\includegraphics[width=0.49\\textwidth]{resources/search_log}\n    \\caption{The number of comparisons made when searching for a random element in a dictionary of size \\textit{n} (linear and log-linear scale)}\n\\end{figure}", "meta": {"hexsha": "f8a69b52e094922225eea97f6b65f6be851a1f87", "size": 15223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/analysis.tex", "max_stars_repo_name": "sam-marsh/Dictionary", "max_stars_repo_head_hexsha": "31f067612fc9b46216ac82c32010009f8a795c04", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2016-02-24T15:30:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-31T20:30:52.000Z", "max_issues_repo_path": "report/analysis.tex", "max_issues_repo_name": "sam-marsh/rb-tree", "max_issues_repo_head_hexsha": "31f067612fc9b46216ac82c32010009f8a795c04", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-07-13T02:59:00.000Z", "max_issues_repo_issues_event_max_datetime": "2015-07-13T02:59:00.000Z", "max_forks_repo_path": "report/analysis.tex", "max_forks_repo_name": "sam-marsh/Dictionary", "max_forks_repo_head_hexsha": "31f067612fc9b46216ac82c32010009f8a795c04", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 94.5527950311, "max_line_length": 981, "alphanum_fraction": 0.7434145701, "num_tokens": 4041, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.8757869835428965, "lm_q1q2_score": 0.744393678714202}}
{"text": "\\lab{Nearest Neighbor Search}{Nearest Neighbor Search}\n\\label{lab:NNS}\n\n\\objective{Teach about branch and bound and the curse of dimensionality using the nearest neighbor search problem.}\n\n\\section*{The Nearest Neighbor Search Problem}\n\nYou move into a city that has several post offices.\nYou want to know which one is the closest.\nThis problem is  known as the nearest neighbor search problem or the post-office problem.\nThe general problem is to find the closest of a set of points to any new point.\n\nThis has many applications which include computer vision, pattern recognition, internet marketing and data compression.\n\nThe naive way to solve this problem is to check the distance of all the data against the point.\n\n\\begin{problem}\nWrite a function that solves the nearest neighbor search problem by exhaustively checking all the distances.\nThe function should take in the set of points that is the data and a single point.\nThe output should be the distance to the closest data point and the index of that point.\nYour function should be able to take in data in an arbitrary dimension.\n\\end{problem}\n\nThe complexity of this algorithm is $O(kn)$.\nWhere  is the $k$ number of dimensions and $n$ is the number of data points.\n\n\\section*{K-D Trees}\n\nA faster way to solve this problem is to build a k-d tree and search the k-d tree for the nearest neighbor. \n\nA k-d tree is a binary tree where the nodes to the left of parent node have a lower value in the i-th dimension and the nodes to the right of the parent node have a greater value in the i-th dimension.\nWhich dimension you split the nodes alternates at different levels.\nIn the $3$ dimensional case the root node is divided in the $x$ dimension, children in the $y$ dimension, grandchildren in the $z$ dimension, and the great-grandchildren in the $x$ dimension and so on.\nEach node stores its location, left child and right child.\nThis requires sorting at each level so the complexity is $O(n log^2(n))$, but we only need to build the k-d tree once and after that we can query it as many times as we want.\n\nIncluded is a function that takes in a set of data and builds k-d tree.\nThe leaf nodes' children are  python's ``None\" object.\n\nThe search of the tree is done recursively.\nOur search function will accept a parent node on which to search, a search point to which we want to find the nearest neighbor, the current best point, the current best distance, and a dimension $i$.\nThe search function should return the best point and best distance currently held in the algorithm.\nWe start the algorithm on the root node of the tree using it's point and distance to the search point as the best point and best distance, and start with $0$ as the first dimension.\n\n\nFor each recursive step, we first check if the euclidean distance between the parent node's point to the search point is less than the current best.\nIf so, we update it the best distance and best point to match the parent node.\n\n\nWe then compare the values in the $i$-th dimension of the search point and the parent's point.\nIf the search point's value is less than that of the parent node's point we recursively call the search function again on the left child of the parent node on the dimension $i+1$, flipping the dimension to $0$ if necessary, and set best point and best distance to it's output.\nThen we have to check if the hypersphere around the point with radius being the current best distance crosses the dividing hyperplane created by the parent.\nIn code we accomplish this by adding the best distance to the point's value in the $i$-th dimension.\nIf this sum is greater than the parent's point value in the i-th dimension, we then search additionally the right child of the parent (using the dimension $i+1$) and update the best point and best distance to the output.\n\n\nIf the point's value was less than the parent's in th i-th dimension, we apply the last two steps mirrored to the right and left children.\nWe first search the right child with the $i+1$-th dimension and set the best point and best distance to the output.\nWe then check if the search point's value in the $i$-th dimension minus the best distance is less than the parent node's value in the $i$-th dimension. \nIf it is, we will also search the left child one the $i+1$-th dimension and set the best point and best distance to the output.\n\nBelow the algorithm summarized in pseudo code \n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{KDSearch}{search\\_point,parent\\_node,b\\_point,b\\_distance,i}\n    \\If { Distance(search\\_point,parent\\_node.point) $<$ b\\_distance }\n        \\State b\\_point = parent\\_node.point\n        \\State b\\_distance = Distance from search\\_point to parent\\_node.point\n    \\EndIf\n\n    \\If{search\\_point[i] $<$ parent\\_node.point[i]}\n        \\State b\\_point, b\\_distance =\n            \\State KDSearch(search\\_point,parent\\_node.left\\_child,b\\_point,b\\_distance,i+1)\n        \\If { search\\_point[i] + b\\_distance $geq$ parent\\_node.point} \n            \\State b\\_point, b\\_distance = \n                \\State KDSearch(search\\_point,parent\\_node.right\\_child,b\\_point,b\\_distance,i+1)\n        \\EndIf\n    \\Else\n        \\State b\\_point, b\\_distance = \n            \\State KDSearch(search\\_point,parent\\_node.right\\_child,b\\_point,b\\_distance,i+1)\n        \\If {search\\_point[i] + b\\_distance $leq$ parent\\_node.point} \n            \\State b\\_point, b\\_distance = \n                \\State KDSearch(search\\_point,parent\\_node.left\\_child,b\\_point,b\\_distance,i+1)\n        \\EndIf\n    \\EndIf\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Nearest Neighbor}\n\\label{alg:nearestneighbor}\n\\end{algorithm}\n\n\n\\begin{problem}\nWrite a function that solves the nearest neighbor search problem by searching through a k-d tree.\nThe function should take in k-d tree and a single point.\nThe output should be the distance to the closest data point and the coordinates of that point. \n\\end{problem}\n\n\\begin{problem}\nTime both the functions you have created with the number of data points being $10,000-100,000$ every multiple of $10,000$ with $4$ dimensions.\nTime only the searching of the k-d tree not the building of it.\nPlot both times on the same plot.\nHow do the two algorithms compare?\n\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{fourDTime.pdf}\n\\caption{Your graph should look like this.\nThe green line is the naive version and blue line is using a kd-tree.\nAs you can see the kd-tree is much faster.}\n\\label{fig:fourDTime}\n\\end{figure}\n\\end{problem}\n\nThe complexity of this algorithm is $O(klog(n))$ in optimal time.\nIts worst case is $O(k*n^{1-\\frac{1}{k}})$ where $k$ is the number of dimensions and $n$ is the number of points in the tree.\nThe reasons for this are discussed in the next section.\n\n\\section*{Curse of Dimensionality}\n\nAs you increase the number of dimensions the number of times that you have to go down both branches increases.\nYou get to the point where you eliminate very few points by using a k-d tree.\n\n\\begin{problem}\nTime both algorithms for the number of data points being $10,000-100,000$ every multiple of $10,000$ with $20$ dimensions.\nPlot both times on the same plot. Now how do the two algorithms compare?\n\\end{problem}\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{twentyDTime.pdf}\n\\caption{\nYour graph should look like this.\nThe green line is the naive version and blue line is using a kd-tree.\nAs you can see the kd-tree is slightly slower than the naive version.}\n\\label{fig:twentyDTime}\n\\end{figure}\n\n\\begin{problem}\nTime the SciPy built in function for searching a k-d tree (do not time the building of the kd-tree) for the number of dimensions points being $2-50$ with $20,000$ data points.\nPlot the time.\nWhat do you notice?\n\\li{from scipy.spatial import KDTree} will import the built in k-d tree.\nCreate the tree by \\li{tree = KDTree(data)} and search it by \\li{tree.query(point)}.\n\n\\li{scipy.spatial} includes a \\li{cKDTree} object which is implemented in C.\nIs it any better?\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{curseD.pdf}\n\\caption{\nYour graph should look similar to this.\nAround 15 dimensions the time jumps.\nAt that point using a kd-tree is not more effective than checking all the combinations.}\n\\end{figure}\n\\end{problem}\n\n\\section*{Classification}\nA common problem is correctly classifying data.  \nSuppose that you have a ten marbles, five of which are blue with a green stripe and the other five red with a purple stripe.  \nIf your friend gave you an eleventh marble that was blue with a brown stripe, which group would you put it in?  \nProbably you would include it with the other blue marbles.  \nWhat if the marble that your friend gave you was blue with a purple stripe?  \nThis marble shares characteristics with both groups.  \nWhere you end up grouping it will depend on which characteristics are most important to you.\n\nThis is the intuitive classfication problem.  \nIf we have data that is already grouped into distinct sets, into which set do we put new data?  \nClassification has myriad and sundry applications.  \nIn this lab we will use it in the context of optical character recognition.\n\n\\section*{Nearest Neighbor Classification}\nWe will now more formally describe the classification problem and explain the nearest neighbor classification algorithm.  \nSuppose we have a collection of vectors $\\{x_1, ..., x_m\\}$ in $\\R^n$ with corresponding labels $\\{l_1, ..., l_k\\}$ describing to which group each datum belongs.  \nThis collection of vectors and labels is called our training set.  \nEach entry of a vector is called a feature and $n$ is the size of our feature set.  \nFor example, consider the following vectors in $\\R^3$\n\n\\begin{center}\n\\begin{tabular}{cc}\n$(2,0,0)$ & $1$ \\\\\n$(3,0,0)$ & $1$ \\\\\n$(0,3,0)$ & $2$ \\\\\n$(0,2,0)$ & $2$ \\\\\n$(1/10,2,0)$ & $2$ \\\\\n$(0,0,4)$ & $3$ \\\\\n$(0,0,7)$ & $3$ \\\\\n\\end{tabular}\n\\end{center}\n\nIf we also have a metric on our space, we may determine the distance between all of these points.  \nIf we are given a new datum and we wish to decide which of the three groups to include it in, one option is to choose the group to which its closest neighbor belongs.  \nLet us use the euclidean metric to classify $(0,0,5)$ against our training set.  \nWe see that the distance from $(0,0,5)$ and $(0,0,4)$ is only $1$, while the distance to the remaining points is at least $2$.  \nThe label of $(0,0,4)$ is $3$, and so we assign $(0,0,5)$ the same label.\n\nNow, what if we wished to classify $(5/2,5/2,0)$?  \nThis presents a problem since this point is equidistant from the points in label $1$ and label $2$.  \nIn such a case it is up to the programmer to decide how to break the tie.\n\nOne case we need to consider is when the data that we are using in our search are on different scales. \nFor example, suppose we wished to classify people applying for a loan at a bank as `risky' or `safe.'  \nFurther suppose that we know their age, education level, current debt, and how many credit cards they have.  \nWe could encode their education level as integers between $0$ and $4$.\n\nSuppose that Bob is 30 years old, well educated, has a debt of \\$5000, and 3 credit cards.  \nLet's say that James is 18 years old, barely out of high school, \\$5000 dollars in debt, and owns 4 credit cards.  \nIf we were to use the Euclidean metric $d$ to measure how close Bob is to James, we would get a distance of\n\\[\nd((30,4,5000,3),(18,0,5000,4)) = 12^2 + 4^2 + 1^2 = 161.\n\\]\n\nHowever, if Alice is 29 years old, well educated, has a debt of \\$4900, and 3 credit cards, then her distance from Bob is\n\\[\nd((30,4,5000,3),(29,4,4900,3)) = 1^2 + 100^2 = 100001.\n\\]\n\nIs James closer to Bob than Alice?  Most Banks would say no.  \nIn order to classify these individuals better, we need to measure distance differently. \nThere are two different ways to handle this. \nThe first solution is to scale the data before inputting it into our algorithm. \nIn our previous example we could divide age by 100, education by 4, debt by 1000, and credit cards by 10 and then preform a nearest neighbor search on Bob. \nThen the distance from Bob to James is \n\\[\nd\\left( \\left( \\frac{30}{100},\\frac{4}{4},\\frac{5000}{1000},\\frac{3}{10} \\right),\\left(\\frac{18}{100},\\frac{0}{4},\\frac{5000}{1000},\\frac{4}{10}\\right)\\right) = .12^2 + 1^2 + .1^2 = 1.0244.\n\\]\nwhile the distace from Alice to Bob is\n\\[\nd\\left(\\left(\\frac{30}{100},\\frac{4}{4},\\frac{5000}{1000},\\frac{3}{10}\\right),\\left(\\frac{29}{100},\\frac{4}{4},\\frac{4900}{1000},\\frac{3}{10}\\right)\\right) = .1^2 + .01^2 = 0.0101.\n\\]\nSo now Bob is closer to Alice.\n\n\\begin{problem}\nWrite a function that takes in data points and the a vector that is used to be the scale. \nThe function outputs the scaled data points. \nSo if we were using it for our baking example it would take in the array representing the data Alice, Bob and James (where each person is a row) and the vector $[100,4,1000,10]$ and output the scaled data of Alice, Bob and James.\n\\end{problem}\n\nAnother alternative is to change the metric we use to measure distance with. \nIn both the examples above we used the Euclidean metric to measure distance. \nSuppose we wished to apply the Euclidean metric to data set of colors.\nWe could map each color to an integer, say red to 1, violet to 2, blue to 3, green to 4, yellow to 5, and orange to 6. \nIf we use Euclidean metric green is closer to red than orange is when we'd probably consider orange to be the same distance from red as violet is. \nIn this case the Euclidean metric is not satisfactory and so we might create a new metric to measure the distance between colors. \n\n\\section*{K-Nearest Neighbor Classification}\nOften we can improve the accuracy of a classifier by looking for other points besides the nearest neighbor.  \nInstead, we may choose an arbitrary number $k$ and give the point to be classified the majority label in from it's $k$ nearest neighbors. \n\nThere are pitfalls to this approach.  \nConsider a point that's closest neighbor has the label $0$.  \nIf we only considered the nearest neighbor, then we would be finished.  \nHowever, what if the next $10$ nearest neighbors all had the label $1$?  \nDo you think that we should still classify the point as $0$?  \nWhat if the nearest point has a distance of $0.1$ and the next $10$ points have a distance of at least $100$?  \nThe answer to these questions depend on the kind of data we are working with and the metric that we choose.  \nOne should ensure to consider how to treat situations like this when working on classification algorithms.\n\n\nThe sklearn library has a neighbors module with a class KNeighborsClassifier for solving the $k$ nearest neighbors problem\n\\begin{lstlisting}\nfrom sklearn import neighbors\nnbrs = neighbors.KNeighborsClassifier(n_neighbors=8, weights='distance', p=2)\n\\end{lstlisting}\n\nThe \\li{neighbors.KNeighborsClassifier} sets up the knearestnieghbor algorithm. \n\\li{n_neighbors} is how many neighbors you would like to find and \\li{weights} specifies how you would like to weight the neighbors you have to make the classification. \nWeights can be \\li{'uniform'}, where the majority classification of the $k$ nearest neighbors determines the new data point's classification, or \\li{'distance'}, where the neighbors nearer to the point have more weight than those farther away. \nThe argument \\li{p} correpsods to the distance metric. \nFor this lab we will use \\li{p=2} which is the Euclidean distance.  \n\n\\begin{lstlisting}\nnbrs.fit(points, labels)\n\\end{lstlisting}\nPoints and labels are your training data. \nThe \\li{fit} function makes \\li{nrbs} create a data structure containing those points and labels ready to be queried. \n\n\\begin{lstlisting}\nnbrs.predict(testpoints)\n\\end{lstlisting}\n\nThe function \\li{predict} takes in points to classify and outputs their respective labels.  \n%More information about this package can be found at http://scikit-learn.org/stable/modules/neighbors.html.\n\\begin{problem}\nGet the post office handwritten digit data set. Load them with\n\\begin{lstlisting}\nlabels, points, testlabels, testpoints = np.load('PostalData.npz').items()\n\\end{lstlisting}\nThis contains a training set and a test set. \nWhen you load the data the first entry of each array will be a name. \nSo \\li{points[1]} and \\li{labels[1]} point to the actual points and labels you want to use. \nEach point is a  image that is $28 \\times 28$ matrix of pixels that has been flattened. \nThe corresponding label indicates which number was written.  \nTry classifying the testpoints with \\li{n_neighbors} as 4 and then as 10 and with \\li{weights} \\li{'uniform'} and then \\li{'distance'}. Then do the classfication with \\li{n_neighbors} being 1. \nFor each one return a report indicating how your classifier performs in terms of misclassifications as a percentange (testlabels are the true labels that correspond to the testpoints). \nWhich combination gives the most correct classifications?\n(You may wish to streamline this process by writting a function that takes in \\li{n_neighbors} and \\li{weights} as arguments calls the neighbors functions appropriately)\n\n\nA similar classification process is used by the United States Postal Service to automatically determine the zip code to send a letter to.\n\n\\begin{figure}[H]\n\\includegraphics[width=.25\\textwidth]{Example.png}\n\\caption{An example of the number 6 taken from the data set}\n\\end{figure}\n\\end{problem}\n\n\n", "meta": {"hexsha": "8b79bb3d95d4adc4f27eda0c06ad4eda8e83ecf3", "size": 17289, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/NearestNeighbor/NearestNeighbor.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Labs/NearestNeighbor/NearestNeighbor.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/NearestNeighbor/NearestNeighbor.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 55.9514563107, "max_line_length": 276, "alphanum_fraction": 0.7523859101, "num_tokens": 4342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666335, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7442069473311166}}
{"text": "\\section{Application: Systems of linear differential equations}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Solve a system of second order linear differential equations.\n  \\end{enumerate}\n\\end{outcome}\n\n% ----------------------------------------------------------------------\n\\subsection{Differential equations}\n\nRecall from calculus that if $y=f(x)$ is a function, then $y' = f'(x)$\nis its derivative%\n\\index{derivative} and $y'' = f''(x)$ is its second derivative.  For\nexample,\n\\begin{equation*}\n  \\begin{array}{c@{~}c@{~}c}\n    y &=& \\sin(x), \\\\\n    y' &=& \\cos(x), \\\\\n    y''&=& -\\sin(x). \\\\\n  \\end{array}\n\\end{equation*}\nNote that if $y=\\sin(x)$, the second derivative $y''$ is exactly the\nnegative of $y$, i.e.,\n\\begin{equation*}\n  y'' = -y.\n\\end{equation*}\nThis last equation is called a \\textbf{differential equation}%\n\\index{equation!differential|see{differential equation}}%\n\\index{differential equation}. Unlike an ordinary equation, which is\nabout an unknown {\\em number}, a differential equation is about an\nunknown {\\em function}. Typically, a differential equation mentions\nthe function and one or more of its derivatives. A differential\nequation that only mentions the first derivative $y'$ is called a\n\\textbf{first-order}%\n\\index{differential equation!first order} differential equation. A\ndifferential equation that also mentions the second derivative $y''$\nis called a \\textbf{second-order}%\n\\index{differential equation!second order} differential equation.\nIf the equation is a linear function of $y$ and its derivatives, it is\ncalled a \\textbf{linear differential equation}%\n\\index{linear differential equation}%\n\\index{differential equation!linear}.\n\nWe say that the function $y=\\sin(x)$ is a \\textbf{solution}%\n\\index{differential equation!solution} of the differential equation\n$y'' = -y$. It is not the only solution. Another solution is\n$y=\\cos(x)$, because in that case, $y''=-\\cos(x)$, and therefore\n$y''=-y$. From calculus, we know that the \\textbf{general solution} to\nthe differential equation $y'' = -y$ is given by\n\\begin{equation*}\n  y = a\\sin(x) + b\\cos(x),\n\\end{equation*}\nwhere $a$ and $b$ are any real numbers, i.e., parameters. Using the\nterminology of linear algebra, we can say that the general solution of\nthe equation $y'' = -y$ is a \\textbf{linear combination}%\n\\index{linear combination!of basic solutions!of differential equation}\nof the \\textbf{basic solutions}%\n\\index{basic solution!of differential equation}%\n\\index{differential equation!basic solution} $y=\\sin(x)$ and\n$y=\\cos(x)$. More generally, we have the following theorem from\ncalculus:\n\n\\begin{theorem}{Solutions of $y''=qy$}{differential-equation}\n  Let $q$ be a positive real number.  The differential equation\n  \\begin{equation*}\n    \\begin{array}{l@{~~}l@{~}clllll}\n    y'' &=& -qy &\\quad\\mbox{has basic solutions}\\quad\\quad &\n    y = \\sin(\\sqrt{q}\\,x) & \\mbox{and} & y = \\cos(\\sqrt{q}\\,x), \\\\\n    y'' &=& 0 &\\quad\\mbox{has basic solutions}\\quad\\quad &\n    y = 1 & \\mbox{and} & y = x, \\\\\n    y'' &=& qy &\\quad\\mbox{has basic solutions}\\quad\\quad &\n    y = e^{\\sqrt{q}\\,x} & \\mbox{and} & y = e^{-\\sqrt{q}\\,x}. \\\\\n    \\end{array}\n  \\end{equation*}\n\\end{theorem}\n\n\\begin{proof}\n  By taking derivatives, it is easy to check that each of the six\n  functions is a solution of the corresponding differential\n  equation. For example, for $y=\\sin(\\sqrt{q}\\,x)$, we have\n  $y'=\\sqrt{q}\\cos(\\sqrt{q}\\,x)$ and\n  $y''=-q\\sin(\\sqrt{q}\\,x)$. Therefore, $y''=-qy$.\n\n  Note that we can obtain the general solution of each of the\n  differential equations as a linear combination of the basic\n  solutions. Thus, the general solution of $y''=-qy$ is\n  \\begin{equation*}\n      y = a\\sin(\\sqrt{q}x) + b\\cos(\\sqrt{q}x),\n  \\end{equation*}\n  the general solution of $y''=0$ is\n  \\begin{equation*}\n      y = a + bx,\n  \\end{equation*}\n  and the general solution of $y''=qy$ is\n  \\begin{equation*}\n      y = ae^{\\sqrt{q}\\,x} + be^{-\\sqrt{q}\\,x},\n  \\end{equation*}\n  where $a$ and $b$ are parameters. The fact that each of these\n  solutions is indeed the most general one is proved in a calculus\n  course.\n\\end{proof}\n\n% ----------------------------------------------------------------------\n\\subsection{Systems of linear differential equations}\n\nIn the same way that a system of linear equations consists of several\nlinear equations about several variables, a \\textbf{system of\n  differential equations}%\n\\index{system of differential equations}%\n\\index{differential equation!system of} consists of several\ndifferential equations about several unknown functions and their\nderivatives. For example, the following is a system of second order\nlinear differential equations:\n\\begin{equation*}\n  \\begin{array}{c@{~}c@{~}r@{~}r@{~}r}\n    y'' &=& 4y &-& 3z, \\\\\n    z'' &=& 6y &-& 5z. \\\\\n  \\end{array}\n\\end{equation*}\nIn reading these equations, it is important to understand that we are\nlooking for two unknown {\\em functions} $y=f(x)$ and $z=g(x)$ such\nthat their second derivatives satisfy both of the equations\n$y''=4y-3z$ and $z''=6y-5z$. The reason that this is in principle a\ndifficult problem is that the equation for $y''$ mentions not only\n$y$, but also $z$, and the equation for $z''$ mentions not only $z$,\nbut also $y$. Therefore, it is not possible to solve this system one\nfunction at a time. We say that the variables $y$ and $z$ are\n\\textbf{coupled}%\n\\index{coupled variables}%\n\\index{differential equation!coupled variables}.\n\nThe following example shows how we can use diagonalization to decouple\nthe variables in a system of differential equations. This makes it\npossible to solve the equations.\n\n\\begin{example}{A system of linear differential equations}{system-differential2}\n  Solve the following system of second order linear differential equations:\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}r@{~}r@{~}r}\n      y'' &=& 4y &-& 3z, \\\\\n      z'' &=& 6y &-& 5z. \\\\\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We start by writing the system in matrix form:\n  \\begin{equation*}\n    \\begin{mymatrix}{c} y'' \\\\ z'' \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rr} 4 & -3 \\\\ 6 & -5 \\end{mymatrix}\n    \\begin{mymatrix}{c} y \\\\ z \\end{mymatrix}.\n  \\end{equation*}\n  Let us write\n  \\begin{equation*}\n    \\vect{v} = \\begin{mymatrix}{c} y \\\\ z \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    A = \\begin{mymatrix}{rr} 4 & -3 \\\\ 6 & -5 \\end{mymatrix}.\n  \\end{equation*}\n  With these notations, the system of differential equations take the\n  form\n  \\begin{equation}\\label{eqn:system-differential2-1}\n    \\vect{v}'' = A\\vect{v}.\n  \\end{equation}\n  Our next step is to diagonalize the matrix $A$. Following the usual\n  diagonalization procedure, we find that $A=PDP^{-1}$, where\n  \\begin{equation*}\n    P = \\begin{mymatrix}{rr} 1 & 1 \\\\ 1 & 2 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    D = \\begin{mymatrix}{rr} 1 & 0 \\\\ 0 & -2 \\end{mymatrix}.\n  \\end{equation*}\n  With this, our equation takes the form\n  $\\vect{v}'' = PDP^{-1}\\vect{v}$, which we can also write as\n  $P^{-1}\\vect{v}'' = DP^{-1}\\vect{v}$. We now introduce a\n  \\textbf{change of variables}%\n  \\index{change of variables!for a differential equation}%\n  \\index{differential equation!change of variables}. Let\n  $\\vect{w} = P^{-1}\\vect{v}$. Then our system of differential\n  equations can be written as\n  \\begin{equation}\\label{eqn:system-differential2-2}\n    \\vect{w}'' = D\\vect{w}.\n  \\end{equation}\n  Note that the equation {\\eqref{eqn:system-differential2-2}} is of\n  exactly the same form as the equation\n  {\\eqref{eqn:system-differential2-1}}, but with the crucial\n  difference that the matrix in {\\eqref{eqn:system-differential2-2}}\n  is diagonal. Let us give a name to the components of $\\vect{w}$:\n  \\begin{equation*}\n    \\vect{w} = \\begin{mymatrix}{c} u \\\\ v \\end{mymatrix}.\n  \\end{equation*}\n  Then the equation {\\eqref{eqn:system-differential2-2}} can be\n  written as\n  \\begin{equation*}\n    \\begin{mymatrix}{c} u'' \\\\ v'' \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rr} 1 & 0 \\\\ 0 & -2 \\end{mymatrix}\n    \\begin{mymatrix}{c} u \\\\ v \\end{mymatrix},\n  \\end{equation*}\n  or equivalently,\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}c}\n      u'' &=& u, \\\\\n      v'' &=& -2v. \\\\\n    \\end{array}\n  \\end{equation*}\n  Note that the variables $u$ and $v$ are not coupled! This happened\n  because the matrix $D$ is diagonal. We can therefore use\n  Theorem~\\ref{thm:differential-equation} to solve the equations for\n  $u$ and for $v$ separately. By\n  Theorem~\\ref{thm:differential-equation}, the general solution for\n  the equation $u'' = u$ is\n  \\begin{equation*}\n    u = a e^{x} + b e^{-x},\n  \\end{equation*}\n  and the general solution for the equation $v''=-2v$ is\n  \\begin{equation*}\n    v = c\\sin(\\sqrt{2}\\,x) + d\\cos(\\sqrt{2}\\,x).\n  \\end{equation*}\n  Here, $a$, $b$, $c$, and $d$ are parameters. Therefore, the general\n  solution for {\\eqref{eqn:system-differential2-2}} is\n  \\begin{equation*}\n    \\vect{w} = \\begin{mymatrix}{c} u \\\\ v \\end{mymatrix}\n    = \\begin{mymatrix}{c}\n      a e^{x} + b e^{-x} \\\\\n      c\\sin(\\sqrt{2}\\,x) + d\\cos(\\sqrt{2}\\,x) \\\\\n    \\end{mymatrix}\n    = a\\,\\begin{mymatrix}{c} e^{x} \\\\ 0 \\end{mymatrix}\n    + b\\,\\begin{mymatrix}{c} e^{-x} \\\\ 0 \\end{mymatrix}\n    + c\\,\\begin{mymatrix}{c} 0 \\\\ \\sin(\\sqrt{2}\\,x) \\end{mymatrix}\n    + d\\,\\begin{mymatrix}{c} 0 \\\\ \\cos(\\sqrt{2}\\,x) \\end{mymatrix}.\n  \\end{equation*}\n  We have therefore found the four basic solution of\n  {\\eqref{eqn:system-differential2-2}}.  But what about our original\n  equation {\\eqref{eqn:system-differential2-1}}? We can undo our\n  change of variables. Since $\\vect{w} = P^{-1}\\vect{v}$, we have\n  $\\vect{v}=P\\vect{w}$. Therefore, the general solution to our\n  original system of differential equations is\n  \\begin{eqnarray*}\n    \\vect{v} ~=~ P\\vect{w}\n    &=& a\\,P\\begin{mymatrix}{c} e^{x} \\\\ 0 \\end{mymatrix}\n    + b\\,P\\begin{mymatrix}{c} e^{-x} \\\\ 0 \\end{mymatrix}\n    + c\\,P\\begin{mymatrix}{c} 0 \\\\ \\sin(\\sqrt{2}\\,x) \\end{mymatrix}\n    + d\\,P\\begin{mymatrix}{c} 0 \\\\ \\cos(\\sqrt{2}\\,x) \\end{mymatrix} \\\\\n    &=& a\\,e^{x}\\begin{mymatrix}{c} 1 \\\\ 1 \\end{mymatrix}\n    + b\\,e^{-x}\\begin{mymatrix}{c} 1 \\\\ 1 \\end{mymatrix}\n    + c\\,\\sin(\\sqrt{2}\\,x)\\begin{mymatrix}{c} 1 \\\\ 2 \\end{mymatrix}\n    + d\\,\\cos(\\sqrt{2}\\,x)\\begin{mymatrix}{c} 1 \\\\ 2 \\end{mymatrix}.\n  \\end{eqnarray*}\n\\end{solution}\n\n% ----------------------------------------------------------------------\n\\subsection{Example: coupled train cars}\n\nOne of the reasons that differential equations are important is that\nthe \\textbf{laws of nature}%\n\\index{laws of nature} often take the form of differential equations.\nFor example, \\textbf{Newton's second law of motion} asserts that the\nacceleration of an object is equal to the total force on the object\ndivided by the mass of the object. In physics, it is common to use $t$\ninstead of $x$ for the independent variable, and $x$ instead of $y$\nfor the dependent variable, so that we write $x=f(t)$ instead of\n$y=f(x)$. If $x$ is the position of the object at time $t$, then the\nobject's acceleration is $x''$, and Newton's second law takes the form\n\\begin{equation*}\n  x'' = \\frac{F}{m}.\n\\end{equation*}\nThis is a differential equation. In the following example, we will\nneed another law of physics, namely \\textbf{Hooke's law}%\n\\index{spring (mechanics)!Hooke's law}%\n\\index{Hooke's law} about the force exerted by a spring. A\n\\textbf{spring}%\n\\index{spring (mechanics)} is an object made from an elastic material\n(often in the shape of a coil), which returns to its original shape\nafter being stretched or compressed. Hooke's law states that the force\nexerted by a spring to both of its ends is equal to\n\\begin{equation*}\n  F = k x.\n\\end{equation*}\nHere $x$ is the \\textbf{extension}%\n\\index{spring (mechanics)!extension} of the spring, i.e., the change\nin length of the spring, relative to its relaxed (natural)\nlength. Also, $k$ is a constant called the \\textbf{spring constant}%\n\\index{spring (mechanics)!spring constant}, measured in units of\n$\\frac{\\SI{N}}{\\m}$ (Newtons per meter). Of course the direction of\nthe force on one end of the spring is the opposite of the direction on\nthe other end. Hooke's law is not a differential equation, because it\ndoes not mention any derivatives. It is just an ordinary\nequation. Nevertheless, both the force $F$ and the extension $x$ can\nvary with time, i.e., they can both be functions of $t$.\n\n\\begin{example}{Coupled train cars}{coupled-train-cars}\n  Consider a train made up of three cars of mass $1\\kg$, $2\\kg$, and\n  $1\\kg$, which are aligned on a linear track and connected by\n  springs. Assume that each spring has the same spring constant\n  $k=2\\frac{\\SI{N}}{\\m}$.\n  \\begin{equation*}\n    \\begin{tikzpicture}\n      \\draw[thick] (0,0) -- (16.4,0);\n      \\begin{scope}\n        \\draw[fill=white] (2,0.5) rectangle node {$1\\kg$} (4,1.5);\n        \\draw[fill=white] (2.5,0.25) circle (0.25);\n        \\draw[fill=white] (3.5,0.25) circle (0.25);\n      \\end{scope}\n      \\begin{scope}[xshift=5.2cm]\n        \\draw[fill=white] (1.8,0.5) rectangle node {$2\\kg$} (4.2,1.9);\n        \\draw[fill=white] (2.5,0.25) circle (0.25);\n        \\draw[fill=white] (3.5,0.25) circle (0.25);\n      \\end{scope}\n      \\begin{scope}[xshift=10.4cm]\n        \\draw[fill=white] (2,0.5) rectangle node {$1\\kg$} (4,1.5);\n        \\draw[fill=white] (2.5,0.25) circle (0.25);\n        \\draw[fill=white] (3.5,0.25) circle (0.25);\n      \\end{scope}\n      \\begin{scope}[xshift=4cm]\n        \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.13,0.3)\n        -- ++(0.2,0);\n        \\draw (1.5,1.3) node[above] {$k$};\n      \\end{scope}\n      \\begin{scope}[xshift=9.4cm]\n        \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.13,0.3)\n        -- ++(0.2,0);\n        \\draw (1.5,1.3) node[above] {$k$};\n      \\end{scope}\n    \\end{tikzpicture}\n  \\end{equation*}\n  Find and solve the equations of motion of this system.\n\\end{example}\n\n\\begin{solution}\n  Let us start by defining appropriate coordinates.  Let $x$ be the\n  position of the first car, $y$ the position of the second car, and\n  $z$ the position of the third car, measured in meters from left to\n  right, relative to each car's natural resting position. The $x$-,\n  $y$-, and $z$-axes are shown in the following picture.  All three\n  axes are parallel to the train tracks, but they have their origins\n  in different places. The coordinates are chosen so that when $x=0$,\n  $y=0$, and $z=0$, then all three cars are at rest and both springs\n  are in their natural relaxed state.\n  \\begin{equation*}\n    \\begin{tikzpicture}[scale=0.8, color=blue!50!black]\n      \\draw[thick] (0,0) -- (16.4,0);\n      \\begin{scope}\n        \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n        \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n        \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n      \\end{scope}\n      \\begin{scope}[xshift=5.2cm]\n        \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n        \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n        \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n      \\end{scope}\n      \\begin{scope}[xshift=10.4cm]\n        \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n        \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n        \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n      \\end{scope}\n      \\begin{scope}[xshift=4cm]\n        \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.13,0.3)\n        -- ++(0.2,0);\n      \\end{scope}\n      \\begin{scope}[xshift=9.4cm]\n        \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.26,0.6)\n        -- ++(0.26,-0.6) -- ++(0.13,0.3)\n        -- ++(0.2,0);\n      \\end{scope}\n      \\begin{scope}[yshift=-1cm, xshift=0cm, color=black]\n        \\draw[->] (1,0) -- node[above] {$x$-axis} +(4,0);\n        \\draw (3,0) -- +(0,-0.2) node[below=-4pt] {$x=0$};\n      \\end{scope}\n      \\begin{scope}[yshift=-1cm, xshift=5.2cm, color=black]\n        \\draw[->] (1,0) -- node[above] {$y$-axis} +(4,0);\n        \\draw (3,0) -- +(0,-0.2) node[below=-4pt] {$y=0$};\n      \\end{scope}\n      \\begin{scope}[yshift=-1cm, xshift=10.4cm, color=black]\n        \\draw[->] (1,0) -- node[above] {$z$-axis} +(4,0);\n        \\draw (3,0) -- +(0,-0.2) node[below=-4pt] {$z=0$};\n      \\end{scope}\n    \\end{tikzpicture}\n  \\end{equation*}\n  Then the extension of the left spring is $y-x$, and therefore the\n  left spring's contracting force is\n  \\begin{equation*}\n    F_1 = k(y-x).\n  \\end{equation*}\n  Similarly, the extension of the right spring is $z-y$, and therefore\n  its contracting force is\n  \\begin{equation*}\n    F_2 = k(z-y).\n  \\end{equation*}\n  The total force acting on the left car is $F_1$, the total force\n  acting on the middle car is $F_2-F_1$, and the total force acting on\n  the right car is $-F_2$. By Newton's second law, the acceleration\n  of each car is given by $x'' = \\frac{F_1}{m_1}$,\n  $y'' = \\frac{F_2-F_1}{m_2}$, and $z''=\\frac{-F_2}{m_3}$. We\n  therefore have the following equations of motion:\n  \\begin{eqnarray*}\n    x'' &=& \\frac{k}{m_1}(y-x), \\\\\n    y'' &=& \\frac{k}{m_2}(x-2y+z), \\\\\n    z'' &=& \\frac{k}{m_3}(z-y).\n  \\end{eqnarray*}\n  Let us ignore the physical units and plug in the masses $m_1=1$,\n  $m_2=2$, and $m_3=1$ and the spring constant $k=2$. Then the equations\n  of motion are:\n  \\begin{eqnarray*}\n    x'' &=& 2(y-x), \\\\\n    y'' &=& x-2y+z, \\\\\n    z'' &=& 2(z-y),\n  \\end{eqnarray*}\n  or equivalently in matrix form:\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x'' \\\\ y'' \\\\ z'' \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rrr}\n      -2 & 2 & 0 \\\\\n      1 & -2 & 1 \\\\\n      0 & 2 & -2 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}.\n  \\end{equation*}\n  We can also write this as $\\vect{v}''=A\\vect{v}$, where\n  \\begin{equation*}\n    \\vect{v} = \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    A = \\begin{mymatrix}{rrr}\n      -2 & 2 & 0 \\\\\n      1 & -2 & 1 \\\\\n      0 & 2 & -2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  To solve the equation, we diagonalize the matrix $A$. Using the usual\n  method for diagonalization, we find that $A=PDP^{-1}$, where\n  \\begin{equation*}\n    P = \\begin{mymatrix}{rrr}\n      -1 &  1 & 1 \\\\\n      0  & -1 & 1 \\\\\n      1  &  1 & 1 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    D = \\begin{mymatrix}{rrr}\n      -2 &  0 & 0 \\\\\n      0  & -4 & 0 \\\\\n      0  &  0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The equation $\\vect{v}''=A\\vect{v}$ then becomes\n  $\\vect{v}''=PDP^{-1}\\vect{v}$, or equivalently\n  $P^{-1}\\vect{v}'' = DP^{-1}\\vect{v}$. We then diagonalize the\n  equation by performing the change of variables\n  $\\vect{w} = P^{-1}\\vect{v}$. The equation becomes\n  \\begin{equation*}\n    \\vect{w}'' = D\\vect{w}.\n  \\end{equation*}\n  If the components of $\\vect{w}$ are called $u$, $v$, and $w$, we can\n  write this as\n  \\begin{equation*}\n    \\begin{mymatrix}{c} u'' \\\\ v'' \\\\ w'' \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rrr}\n      -2 &  0 & 0 \\\\\n      0  & -4 & 0 \\\\\n      0  &  0 & 0 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} u \\\\ v \\\\ w \\end{mymatrix},\n  \\end{equation*}\n  or equivalently,\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}c}\n      u'' &=& -2u, \\\\\n      v'' &=& -4v, \\\\\n      w'' &=& 0.   \\\\\n    \\end{array}\n  \\end{equation*}\n  Since the variables are now decoupled, we can solve each\n  differential equation individually.\n  \\begin{itemize}\n  \\item \\textbf{Solutions for $\\eigenvar=-2$:}\n    By Theorem~\\ref{thm:differential-equation}, the basic solutions\n    for $u'' = -2u$ are\n    \\begin{equation*}\n      u=\\sin(\\sqrt{2}\\,t)\n      \\quad\\mbox{and}\\quad\n      u=\\cos(\\sqrt{2}\\,t).\n    \\end{equation*}\n    This translates into the following basic solutions for $\\vect{w}$:\n    \\begin{equation*}\n      \\vect{w}\n      = \\sin(\\sqrt{2}\\,t)\\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n      \\quad\\mbox{and}\\quad\n      \\vect{w}\n      = \\cos(\\sqrt{2}\\,t)\\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 0 \\end{mymatrix}.\n    \\end{equation*}\n    Using $\\vect{v} = P\\vect{w}$ to change to the original variables,\n    we get the basic solutions\n    \\begin{equation*}\n      \\vect{v}\n      = \\sin(\\sqrt{2}\\,t)\\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 1 \\end{mymatrix}\n      \\quad\\mbox{and}\\quad\n      \\vect{v}\n      = \\cos(\\sqrt{2}\\,t)\\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 1 \\end{mymatrix}.\n    \\end{equation*}\n    For example, the first of these basic solutions, written in the\n    coordinates $x$, $y$, and $z$, gives\n    \\begin{equation*}\n      \\begin{array}{c@{~~}c@{~}l}\n        x &=& -\\sin(\\sqrt{2}\\,t), \\\\\n        y &=& ~~~\\,0, \\\\\n        z &=& ~~~\\sin(\\sqrt{2}\\,t). \\\\\n      \\end{array}\n    \\end{equation*}\n    This corresponds to a periodic oscillation of the train where the\n    middle car is stationary, and the left car moves left when the\n    right car moves right. Each oscillation takes\n    $2\\pi/\\sqrt{2}\\approx 4.4$ seconds.  Here is a ``movie'' showing\n    one oscillation:\n    \\begin{equation*}\n      \\begin{tikzpicture}[scale=0.8, color=blue!50!black]\n        \\begin{scope}[yshift=0cm]\n          \\draw (-3,1) node[right] {$t=0\\s$};\n          \\draw[thick] (0,0) -- (16.4,0);\n          \\begin{scope}[xshift=0cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=5.2cm]\n            \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=10.4cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n          \\begin{scope}[xshift=9.4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n        \\end{scope}\n        \\begin{scope}[yshift=-2cm]\n          \\draw (-3,1) node[right] {$t=1.1\\s$};\n          \\draw[thick] (0,0) -- (16.4,0);\n          \\begin{scope}[xshift=-1cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=5.2cm]\n            \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=11.4cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=3cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.18,0.3)\n            -- ++(0.36,-0.6) -- ++(0.36,0.6)\n            -- ++(0.36,-0.6) -- ++(0.36,0.6)\n            -- ++(0.36,-0.6) -- ++(0.36,0.6)\n            -- ++(0.36,-0.6) -- ++(0.36,0.6)\n            -- ++(0.36,-0.6) -- ++(0.18,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n          \\begin{scope}[xshift=9.4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.18,0.3)\n            -- ++(0.36,-0.6) -- ++(0.36,0.6)\n            -- ++(0.36,-0.6) -- ++(0.36,0.6)\n            -- ++(0.36,-0.6) -- ++(0.36,0.6)\n            -- ++(0.36,-0.6) -- ++(0.36,0.6)\n            -- ++(0.36,-0.6) -- ++(0.18,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n        \\end{scope}\n        \\begin{scope}[yshift=-4cm]\n          \\draw (-3,1) node[right] {$t=2.2\\s$};\n          \\draw[thick] (0,0) -- (16.4,0);\n          \\begin{scope}[xshift=0cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=5.2cm]\n            \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=10.4cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n          \\begin{scope}[xshift=9.4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n        \\end{scope}\n        \\begin{scope}[yshift=-6cm]\n          \\draw (-3,1) node[right] {$t=3.3\\s$};\n          \\draw[thick] (0,0) -- (16.4,0);\n          \\begin{scope}[xshift=1cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=5.2cm]\n            \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=9.4cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=5cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.08,0.3)\n            -- ++(0.16,-0.6) -- ++(0.16,0.6)\n            -- ++(0.16,-0.6) -- ++(0.16,0.6)\n            -- ++(0.16,-0.6) -- ++(0.16,0.6)\n            -- ++(0.16,-0.6) -- ++(0.16,0.6)\n            -- ++(0.16,-0.6) -- ++(0.08,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n          \\begin{scope}[xshift=9.4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.08,0.3)\n            -- ++(0.16,-0.6) -- ++(0.16,0.6)\n            -- ++(0.16,-0.6) -- ++(0.16,0.6)\n            -- ++(0.16,-0.6) -- ++(0.16,0.6)\n            -- ++(0.16,-0.6) -- ++(0.16,0.6)\n            -- ++(0.16,-0.6) -- ++(0.08,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n        \\end{scope}\n        \\begin{scope}[yshift=-8cm]\n          \\draw (-3,1) node[right] {$t=4.4\\s$};\n          \\draw[thick] (0,0) -- (16.4,0);\n          \\begin{scope}[xshift=0cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=5.2cm]\n            \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=10.4cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n          \\begin{scope}[xshift=9.4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n        \\end{scope}\n        \\begin{scope}[xshift=3cm,yshift=1cm,rotate=-90]\n          \\draw[ultra thick,red] (0,0) sin (2,-1) cos (4,0) sin (6,1) cos (8,0);\n        \\end{scope}\n        \\begin{scope}[xshift=8.2cm,yshift=1cm,rotate=-90]\n          \\draw[ultra thick,red] (0,0) sin (2,0) cos (4,0) sin (6,0) cos (8,0);\n        \\end{scope}\n        \\begin{scope}[xshift=13.4cm,yshift=1cm,rotate=-90]\n          \\draw[ultra thick,red] (0,0) sin (2,1) cos (4,0) sin (6,-1) cos (8,0);\n        \\end{scope}\n      \\end{tikzpicture}\n    \\end{equation*}\n    The other basic solution, with $\\cos$ instead of $\\sin$, is the\n    same motion, just starting at a different offset in time. Note how\n    the eigenvector of $A$,\n    \\begin{equation*}\n      \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 1 \\end{mymatrix},\n    \\end{equation*}\n    describes the relative motion of the three cars, i.e., the first\n    and last cars are moving in opposite directions, whereas the\n    middle car is stationary. The corresponding eigenvalue\n    $\\eigenvar=-2$ determines the frequency. The frequency, which is\n    $\\sqrt{2}/2\\pi$ oscillations per second, is also called an\n    \\textbf{eigenfrequency}%\n    \\index{eigenfrequency}%\n    \\index{differential equation!eigenfrequency} or \\textbf{resonance\n      frequency}%\n    \\index{resonance!frequency}%\n    \\index{differential equation!resonance frequency}%\n    \\index{frequency!resonance} of the system.\n  \\item \\textbf{Solutions for $\\eigenvar=-4$:}\n    By Theorem~\\ref{thm:differential-equation}, the basic solutions\n    for $v'' = -4v$ are\n    \\begin{equation*}\n      v=\\sin(2t)\n      \\quad\\mbox{and}\\quad\n      v=\\cos(2t).\n    \\end{equation*}\n    This translates into the following basic solutions for $\\vect{w}$:\n    \\begin{equation*}\n      \\vect{w}\n      = \\sin(2t)\\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix}\n      \\quad\\mbox{and}\\quad\n      \\vect{w}\n      = \\cos(2t)\\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix}.\n    \\end{equation*}\n    We change this to the original variables using $\\vect{v} =\n    P\\vect{w}$, and get the basic solutions\n    \\begin{equation*}\n      \\vect{v}\n      = \\sin(2t)\\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 1 \\end{mymatrix}\n      \\quad\\mbox{and}\\quad\n      \\vect{v}\n      = \\cos(2t)\\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 1 \\end{mymatrix}.\n    \\end{equation*}\n    Writing the first of these basic solutions in the coordinates $x$,\n    $y$, and $z$, we get\n    \\begin{equation*}\n      \\begin{array}{c@{~~}c@{~}l}\n        x &=& ~~~\\sin(2t), \\\\\n        y &=& -\\sin(2t), \\\\\n        z &=& ~~~\\sin(2t). \\\\\n      \\end{array}\n    \\end{equation*}\n    This corresponds to a periodic oscillation of the train where the\n    outer cars move right at the same time that the middle car moves\n    left. Each oscillation takes\n    $2\\pi/2\\approx 3.14$ seconds. Here is a ``movie'' of the motion:\n    \\begin{equation*}\n      \\begin{tikzpicture}[scale=0.8, color=blue!50!black]\n        \\begin{scope}[yshift=0cm]\n          \\draw (-3,1) node[right] {$t=0\\s$};\n          \\draw[thick] (0,0) -- (16.4,0);\n          \\begin{scope}[xshift=0cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=5.2cm]\n            \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=10.4cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n          \\begin{scope}[xshift=9.4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n        \\end{scope}\n        \\begin{scope}[yshift=-2cm]\n          \\draw (-3,1) node[right] {$t=0.79\\s$};\n          \\draw[thick] (0,0) -- (16.4,0);\n          \\begin{scope}[xshift=-1cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=6.2cm]\n            \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=9.4cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=3cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.23,0.3)\n            -- ++(0.46,-0.6) -- ++(0.46,0.6)\n            -- ++(0.46,-0.6) -- ++(0.46,0.6)\n            -- ++(0.46,-0.6) -- ++(0.46,0.6)\n            -- ++(0.46,-0.6) -- ++(0.46,0.6)\n            -- ++(0.46,-0.6) -- ++(0.23,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n          \\begin{scope}[xshift=10.4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.03,0.3)\n            -- ++(0.06,-0.6) -- ++(0.06,0.6)\n            -- ++(0.06,-0.6) -- ++(0.06,0.6)\n            -- ++(0.06,-0.6) -- ++(0.06,0.6)\n            -- ++(0.06,-0.6) -- ++(0.06,0.6)\n            -- ++(0.06,-0.6) -- ++(0.03,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n        \\end{scope}\n        \\begin{scope}[yshift=-4cm]\n          \\draw (-3,1) node[right] {$t=1.57\\s$};\n          \\draw[thick] (0,0) -- (16.4,0);\n          \\begin{scope}[xshift=0cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=5.2cm]\n            \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=10.4cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n          \\begin{scope}[xshift=9.4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n        \\end{scope}\n        \\begin{scope}[yshift=-6cm]\n          \\draw (-3,1) node[right] {$t=2.36\\s$};\n          \\draw[thick] (0,0) -- (16.4,0);\n          \\begin{scope}[xshift=1cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=4.2cm]\n            \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=11.4cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=5cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.03,0.3)\n            -- ++(0.06,-0.6) -- ++(0.06,0.6)\n            -- ++(0.06,-0.6) -- ++(0.06,0.6)\n            -- ++(0.06,-0.6) -- ++(0.06,0.6)\n            -- ++(0.06,-0.6) -- ++(0.06,0.6)\n            -- ++(0.06,-0.6) -- ++(0.03,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n          \\begin{scope}[xshift=8.4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.23,0.3)\n            -- ++(0.46,-0.6) -- ++(0.46,0.6)\n            -- ++(0.46,-0.6) -- ++(0.46,0.6)\n            -- ++(0.46,-0.6) -- ++(0.46,0.6)\n            -- ++(0.46,-0.6) -- ++(0.46,0.6)\n            -- ++(0.46,-0.6) -- ++(0.23,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n        \\end{scope}\n        \\begin{scope}[yshift=-8cm]\n          \\draw (-3,1) node[right] {$t=3.14\\s$};\n          \\draw[thick] (0,0) -- (16.4,0);\n          \\begin{scope}[xshift=0cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=5.2cm]\n            \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=10.4cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n          \\begin{scope}[xshift=9.4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n        \\end{scope}\n        \\begin{scope}[xshift=3cm,yshift=1cm,rotate=-90]\n          \\draw[ultra thick,red] (0,0) sin (2,-1) cos (4,0) sin (6,1) cos (8,0);\n        \\end{scope}\n        \\begin{scope}[xshift=8.2cm,yshift=1cm,rotate=-90]\n          \\draw[ultra thick,red] (0,0) sin (2,1) cos (4,0) sin (6,-1) cos (8,0);\n        \\end{scope}\n        \\begin{scope}[xshift=13.4cm,yshift=1cm,rotate=-90]\n          \\draw[ultra thick,red] (0,0) sin (2,-1) cos (4,0) sin (6,1) cos (8,0);\n        \\end{scope}\n      \\end{tikzpicture}\n    \\end{equation*}\n    As before, the other basic solution, using $\\cos$ instead of\n    $\\sin$, is the same motion, but shifted in time. Also, the\n    eigenvector\n    \\begin{equation*}\n      \\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 1 \\end{mymatrix}\n    \\end{equation*}\n    describes the relative motion of the three cars; here the first\n    and last car move in the same direction while the middle car moves\n    in the opposite direction. The eigenfrequency of this oscillation,\n    at $2/2\\pi$ oscillations per second, is slightly higher than the\n    first one, due to the larger magnitude of the eigenvalue\n    $\\eigenvar=-4$.\n  \\item \\textbf{Solutions for $\\eigenvar=0$:} The last eigenvalue is\n    zero. By Theorem~\\ref{thm:differential-equation}, the general\n    solution of $w'' = 0$ is\n    \\begin{equation*}\n      w = a+bt,\n    \\end{equation*}\n    where $a$ and $b$ are arbitrary constants. This translates into\n    the following solution for $\\vect{w}$:\n    \\begin{equation*}\n      \\vect{w}\n      = (a+bt)\\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 1 \\end{mymatrix},\n    \\end{equation*}\n    and by the change of variables $\\vect{v} = P\\vect{w}$, we get\n    \\begin{equation*}\n      \\vect{v}\n      = (a+bt)\\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix}.\n    \\end{equation*}\n    Writing this in terms of the coordinates $x$, $y$, and $z$, we get\n    \\begin{equation*}\n      \\begin{array}{c@{~~}c@{~}l}\n        x &=& a+bt, \\\\\n        y &=& a+bt, \\\\\n        z &=& a+bt. \\\\\n      \\end{array}\n    \\end{equation*}\n    This simply describes a linear motion: the three cars are moving\n    down the track at constant speed $b$ from some initial starting\n    position $a$.\n    \\begin{equation*}\n      \\begin{tikzpicture}[scale=0.8, color=blue!50!black]\n        \\begin{scope}[yshift=0cm]\n          \\draw (-3,1) node[right] {$t=0\\s$};\n          \\draw[thick] (0,0) -- (16.4,0);\n          \\begin{scope}[xshift=-1cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=4.2cm]\n            \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=9.4cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=3cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n          \\begin{scope}[xshift=8.4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n        \\end{scope}\n        \\begin{scope}[yshift=-2cm]\n          \\draw (-3,1) node[right] {$t=1\\s$};\n          \\draw[thick] (0,0) -- (16.4,0);\n          \\begin{scope}[xshift=0cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=5.2cm]\n            \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=10.4cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n          \\begin{scope}[xshift=9.4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n        \\end{scope}\n        \\begin{scope}[yshift=-4cm]\n          \\draw (-3,1) node[right] {$t=2\\s$};\n          \\draw[thick] (0,0) -- (16.4,0);\n          \\begin{scope}[xshift=1cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=6.2cm]\n            \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=11.4cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=5cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n          \\begin{scope}[xshift=10.4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n        \\end{scope}\n        \\begin{scope}[yshift=-6cm]\n          \\draw (-3,1) node[right] {$t=3\\s$};\n          \\draw[thick] (0,0) -- (16.4,0);\n          \\begin{scope}[xshift=2cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=7.2cm]\n            \\draw[fill=blue!10] (1.8,0.5) rectangle (4.2,1.9);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=12.4cm]\n            \\draw[fill=blue!10] (2,0.5) rectangle (4,1.5);\n            \\draw[fill=blue!10] (2.5,0.25) circle (0.25);\n            \\draw[fill=blue!10] (3.5,0.25) circle (0.25);\n          \\end{scope}\n          \\begin{scope}[xshift=6cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n          \\begin{scope}[xshift=11.4cm]\n            \\draw (0,1) -- ++(0.2,0) -- ++(0.13,0.3)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.26,0.6)\n            -- ++(0.26,-0.6) -- ++(0.13,0.3)\n            -- ++(0.2,0);\n          \\end{scope}\n        \\end{scope}\n        \\begin{scope}[xshift=3cm,yshift=1cm,rotate=-90]\n          \\draw[ultra thick, red] (0,-1) -- (6,2);\n        \\end{scope}\n        \\begin{scope}[xshift=8.2cm,yshift=1cm,rotate=-90]\n          \\draw[ultra thick, red] (0,-1) -- (6,2);\n        \\end{scope}\n        \\begin{scope}[xshift=13.4cm,yshift=1cm,rotate=-90]\n          \\draw[ultra thick, red] (0,-1) -- (6,2);\n        \\end{scope}\n      \\end{tikzpicture}\n    \\end{equation*}\n    As before, the eigenvector\n    \\begin{equation*}\n      \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    \\end{equation*}\n    describes the relative motion of the three cars (in this case all\n    moving in the same direction). The eigenvalue $\\eigenvar=0$\n    indicates linear motion.\n  \\end{itemize}\n  What we have described here are the {\\em basic} solutions of the\n  system. The solutions corresponding to each of the eigenvalues are\n  also called \\textbf{modes}%\n  \\index{mode of resonance}%\n  \\index{resonance!mode}%\n  \\index{differential equation!mode} of the system. Thus, the train\n  has three modes, each corresponding to a particular eigenvalue of\n  the matrix $A$. In the first mode, the middle car is stationary and\n  the other two cars oscillate in opposite directions.  In the second\n  mode, the middle car oscillates in the opposite direction of the two\n  outer cars. The third mode is a linear movement along the track.\n\n  As always, the general solution is a linear combination of basic\n  solutions; for example, the cars might be oscillating in both the\n  first and second modes at their respective frequencies, while also\n  moving down the tracks.\n\\end{solution}\n", "meta": {"hexsha": "f55d42c5e49d73e716d79e6d61b989b458f24ebb", "size": 50276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Eigenvalues-Application-Differential.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Eigenvalues-Application-Differential.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Eigenvalues-Application-Differential.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 41.4476504534, "max_line_length": 80, "alphanum_fraction": 0.5067825603, "num_tokens": 19599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7441344626255928}}
{"text": "% !TEX root = Main.tex\n\\section{Neural Networks}\n\\textbf{Neurons}: $F_\\sigma(\\mathbf{x};\\mathbf{w}) = \\sigma(w_0 + \\sum_{i=1}^M{x_iw_i})$.\\\\\n\\textbf{Activation}: $s(x)=\\frac{1}{1+e^{-x}}$, $s'(x)=s(x)(1-s(x))$; $tanh(x) = \\tfrac{sinh(x)}{cosh(x)}$, $tanh'(x) = 1 - tanh^2(x)$;  $ReLU(x) = max(0, x)$, $ReLU'(x) = 0\\  or\\  1$\\\\\n\\textbf{Output}: Linear Regression: $\\hat{\\mathbf{y}} = \\mathbf{W}^L\\mathbf{x}^{L-1}$\\\\\nBinary Classification (Logistic):\\\\\n$\\hat{y_1} = \\text{P}[Y=1|\\mathbf{x}] = \\frac{1}{1 + \\exp[-\\langle \\mathbf{w}_1^L,\\mathbf{x}^{L-1}\\rangle]}$\\\\\nMulticlass (Softmax):\\\\\n$\\hat{y_k} = \\text{P}[Y=k|\\mathbf{x}]= \\frac{\\exp[\\langle \\mathbf{w}_k^L,\\mathbf{x}^{L-1}\\rangle]}{\\sum_{m=1}^{K}{\\exp[\\langle \\mathbf{w}_m^L, \\mathbf{x}^{L-1}\\rangle]}}$.\\\\\n(softmax: $\\sigma(z)_j = e^{z_j}/\\sum_{k=1}^K e^{z_k}$ for $j=1,\\dots,K$)\\\\\n\\textbf{Loss Function:} Squared Loss $\\frac{1}{2}(y - \\hat{y})^2$\\\\\nCross-Entropy Loss: $-y \\log \\hat{y} - (1-y)\\log(1-\\hat{y})$.\\\\\n\\textbf{Units \\& Layers}: FW Prop: $\\mathbf{x}^{l} = \\sigma^{l}\\left(\\mathbb{W}^{\\left(l\\right)}\\mathbf{x}^{\\left(l-1\\right)}\\right)$. L-layer network: $\\mathbf{y}=\\sigma^{\\left(L\\right)}\\left(\\mathbf{W}^{(L)}\\sigma^{(L-1)}\\left(\\cdots\\left(\\sigma^{(1)}\\left(\\mathbf{W}^{(1)}\\mathbf{x}\\right)\\cdots\\right)\\right)\\right)$\n\n\\subsection*{Backpropagation (L2L Jacobian)}\n$\\mathbf{x}$ = Prev Layer Act, $\\mathbf{x^+}$ = Curr Layer Act\\\\$\\mathbf{J}$ = $J_{ij}$ (Jacobian of mapping $\\mathbf{x}\\rightarrow\\mathbf{x^+}$)\\\\ $\\mathbf{x_i^+} = \\sigma(\\mathbf{w}_i^\\top\\mathbf{x})$, $J_{ij} = \\frac{\\partial \\mathbf{x_i^+}}{\\partial \\mathbf{x}_j} = w_{ij}\\cdot\\sigma'(\\mathbf{w}_i^\\top\\mathbf{x})$.\\\\\nMulti-Layer (First FW, then BW):\\\\\n$\\frac{\\partial\\mathbf{x}^{(l)}}{\\partial\\mathbf{x}^{(l-n)}} = \\mathbf{J}^{(l)}\\cdot\\frac{\\partial\\mathbf{x}^{(l-1)}}{\\partial\\mathbf{x}^{(l-n)}}=\\mathbf{J}^{(l)}\\cdot\\mathbf{J}^{(l-1)}\\cdots\\mathbf{J}^{(l-n+1)}$, then BP $ \\nabla_{x^{(l)}}^\\top\\ell=\\nabla_{y}^\\top\\ell\\cdot\\mathbf{J}^{(L)}\\cdots\\mathbf{J}^{(l+1)}$\n\n\\subsection*{Convolutional Neural Networks}\nTranslation invariance of images $\\rightarrow$ neurons compute same func, shift invariant filters; weights defined as filter masks, e.g. convolution: $F_{n,m}(\\mathbf{x};\\mathbf{w}) = \\sigma(b + \\sum_{k=-2}^2\\sum_{l=-2}^{2}{w_{k,l}x_{n+k,m+l}})$.\\\\\n$i',j'$ win. pos, $k$: win. size, $K$: weigths, $c$: chan.:\\\\\n $(I\\star K)_{i', j'} = \\sum_c \\sum_{-k\\leq i,j \\leq k} pad(X_c)_{i'+i,j'+j} \\cdot(K_c)_{i,j}$\\\\\nMax-Pooling (size 3): $\\max_{-1\\leq i', j' \\leq 1}(\\cdot)_{i+i', j+j'}$ % TODO: Make prettier, remove $\\cdot$ \n\n\\subsection*{ELBO}\n$\\lambda^* = argmax_\\lambda ELBO(\\lambda)$ where $ELBO=$\\\\\n$log p(y,\\theta) \\geq E_q[log p(x^{1:L},y; \\theta)-log q(x^{1:L}, y)]$\n\n\\subsection*{Autoregressive models}\n$p(x)=\\pi_{i=1}^{n^2} p(x_i|x_1,\\dots ,x_{i-1})$", "meta": {"hexsha": "7d65bcd6545892c65aa3e8f76d76abfaa41ab94f", "size": 2807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ConvolutionalNN.tex", "max_stars_repo_name": "Jakub-Golinowski/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "894b4545f873cd3cb85523dd79a37c1aa0ac26c7", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-02-23T14:58:12.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-23T14:58:12.000Z", "max_issues_repo_path": "ConvolutionalNN.tex", "max_issues_repo_name": "Jakub-Golinowski/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "894b4545f873cd3cb85523dd79a37c1aa0ac26c7", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ConvolutionalNN.tex", "max_forks_repo_name": "Jakub-Golinowski/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "894b4545f873cd3cb85523dd79a37c1aa0ac26c7", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-08-06T06:16:35.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-06T06:16:35.000Z", "avg_line_length": 90.5483870968, "max_line_length": 321, "alphanum_fraction": 0.5949412184, "num_tokens": 1256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778000158576, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7440918961194158}}
{"text": "%&LaTeX\n\n\\section{Discrete Fourier Transform}\n\n\\subsection{Lab Background}\nBy the end of this lab you should have a firm understanding of how the\nDiscrete Fourier Transform (DFT) can be implemented exactly using the\nFast Fourier Transform (FFT). In addition you should be able to\nidentify common problems using the DFT to analyze signals. You will\nalso be familiar with a new tool, the spectrogram, that uses the DFT\nas a function of time.\n\n\\subsection{Implementing the DFT}\n\n% TODO: have them work with this block for a good implementation of the J-DSP\nRecall that the DFT can be implemented directly from the analysis\nequation. For a length $N$ signal $x[n]$,\n\\begin{align}\nX[k]=\\sum_{n=0}^{N-1}x[n]e^{-j \\frac{2\\pi}{N} nk} && \\text{for $k = 0, 1, 2, \\cdots N-1$}\n\\label{eq:dft}\n\\end{align}\nThe order of the implementation is $O(N)=N^2$. The following java code\ncan be used to implement the DFT in J-DSP. It is implemented without\nany algorithmic speedup (i.e., it exactly mirrors equation\n\\ref{eq:dft}).  Example of raw DFT implementation:\n\t\\begin{lstlisting}\npublic class MyFunction1\n{\n public void myCode(double[]x1,double[]x2,double[]y1,double[]y2,\n \tdouble[]b1,double[]a1,double[]b2,double[]a2,\n \tdouble para1, double para2, double para3)\n  {\n  // x1, x2 - input at pin 0 and pin1\n  // y1, y2 - output at pin 4 and pin5\n  // raw DFT implementation\n  double[] yImag;\n  double[] yReal;\n  yImag = new double[256];\n  yReal = new double[256];\n  double twoPiOverN = 2*Math.PI/256;\n  for( int k = 0 ; k < 256 ; k++)\n  {\n    yReal[k] = 0;\n    yImag[k] = 0;\n    for( int n = 0 ; n < 256 ; n++)\n    {\n      yReal[k] += x1[n]*Math.cos(n*k*twoPiOverN);\n      yImag[k] += -x1[n]*Math.sin(n*k*twoPiOverN);\n    }\n    y1[k] = Math.sqrt(yReal[k]*yReal[k]+yImag[k]*yImag[k]);\n  }\n }\n}\n\t\\end{lstlisting}\nNote that there is not a native support in java for complex numbers so\nthis arithmetic is written out explicitly in the code above. For\nexample, the equation $y=x\\times e^{a}$ (where x is a real number)\nmust be explicitly written out using Euler's formula, and the real and\nimaginary portions saved in separate variables, $y_{real}=x\\times\n\\cos(a)$ and $y_{imag}=x\\times \\sin(a)$.\n\nThe FFT algorithm, on the other hand, can be used to reduce the\ncomputation time of the DFT to $O(N)=N\\log_2 N$ - a significant\nspeedup for even modest length signals.\n\n\\paragraph{Step 1.1}\nWrite some example code to multiply \\emph{two} complex numbers,\n$c=a\\times b$. Remember to represent the variables by their real and\nimaginary parts and save the real and imaginary parts in separate\nvariables.\n\n\n\\paragraph{Step 1.2} \nUse the \\block{UserDefinedFun} block to implement the FFT using loops\n(i.e., do not use recursion). The first part of this code performs a\nbit reversal on the input array. Use the following code to perform the\nbit reversal:\n% make more explict, bit rev vrbl\n\\begin{lstlisting}\n// bit reversal\nint  index;\nint  N = 256;\ndouble[] reversedX1 = new double[256];\n// need to shift 32 bit integer to make it an 8 bit reversal\nint shift = (32-(int)Math.round(Math.log(N)/Math.log(2))); \nfor( int n = 0 ; n < N ; n++){\n  index = (Integer.reverse(n))>>>shift; //reverse and then shift down to 8 bit\n  reversedX1[n] = x1[index]; \n}\n\\end{lstlisting}\nThen iterate over the array $\\log_2 N$ times! Remember to explicitly\ncarry out any complex arithmetic and take the magnitude of the output\narray once the FFT is computed. Include a copy of the java code in\nyour report.\n\n\\paragraph{Step 1.3} \nCheck your results in J-DSP using the \\block{FFT} block. Your results\nshould be identical. Take the FFT of a sinusoid with a frequency of\n$\\pi/4$ radians per second using your FFT implementation and the\n\\block{FFT} block provided in J-DSP. Include a screenshot of the\noutput plots.\n\n\n\n\\subsection{Using the DFT}\n% switch over to spectrogram example with DTMF - organize introduction\n% for ease of use over multiple steps\n\\paragraph{Step 2.1} \nCreate a sum of two sinusoids in J-DSP. Use the \\block{FFT} block to\ncompute the FFT of the sum and then plot the FFT magnitude. Use a\nfrequency of $0.13\\pi$ and $0.19\\pi$ for the two sinusoids. Make sure\nthat the \\option{pulsewidth} for each is set to 256. What does the\nresult look like? Does this make sense?\n\n\n\\paragraph{Step 2.2} At what index (or indices) does the FFT magnitude\nreach its peak value(s)? What frequency (or frequencies) does this\ncorrespond to?\n\n\n\\paragraph{Step 2.3} Change the frequencies of the sinusoids to\n$0.13\\pi$ and $0.14\\pi$. Repeat steps 2.1 and 2.2. Do the results\nstill make sense?\n\n\n\\paragraph{Step 2.4} Replace the sum of two sinusoids in J-DSP with\nthe \\block{DTMF} block under the \\menu{Audio Effects} function\nlist. Press some of the keys in the \\block{DTMF} block. Does the FFT\nblock show separate frequencies for each button?\n\n\n\n\\subsection{Spectrograms}\nComparing FFT graphs (as in the step 2.4) can be difficult to do. But\nwhat if we could analyze the frequency content of a signal as a\nfunction of time? That would make it easier to see differences in\nfrequency if a signal started changing (like a string of DTMF keys\npressed in turn). To do this we will need a new tool called the\n\\emph{Spectrogram}. The spectrogram is simply an algorithm for\ncomputing the FFT of a signal at different times and plotting them as\na function of time. The spectrogram is computed in the following way:\n\n\\begin{enumerate}\n\\item A given signal is ``windowed.'' This means that we only take a\n  certain number of points from the signal (for this example assume we\n  are using a window of length 128 points). To start out, we take the\n  first 128 points of the signal (points 0 through 127 of the input\n  array).\n\\item Take the FFT of the window and save the it in a separate array.\n\\item Advance the window in time by a certain number of points. For\n  instance we can advance the window by 64 points so that we now have\n  a window of indices 64 through 191 from the input signal array.\n\\item Repeat steps 1-3, saving the FFT of each window, until there are\n  no longer any points in the input array.\n\\item Form a 2-D matrix whose columns are the FFT magnitudes of each\n  window (placed in chronological order). In this way, each row\n  represents a certain frequency, each column represents a given\n  instant in time, and the value of the matrix represents the\n  magnitude of the FFT.\n\\end{enumerate}\n\nThe result is called a Spectrogram and is usually displayed as an RGB\nimage where blue represents small FFT magnitudes and red represents\nlarger FFT magnitudes (the \\emph{Jet} colormap if you are familiar\nwith color visualizations). There is an art to choosing the correct\nparameters of the spectrogram (i.e., window size, FFT size, how many\npoints to advance the FFT, etc.). Each parameter has tradeoffs for the\ntime and frequency resolution of the resulting spectrogram. For our\npurposes here, we will not be concerned with these tradeoffs. Instead\nwe will be more interested in getting familiar with analysis using\nspectrograms.\n\n\\paragraph{Step 3.1} Use the DTMF setup from step 2.4. Instead of\nusing the \\block{FFT} block, use the \\block{Spectrogram} block under\nthe \\menu{Statistical DSP} function stack. Keep all parameters in the\n\\block{Spectrogram} set to the default. Set the \\block{DTMF} block to\nplay five frames per key press. Press the number ``1.'' What does the\nspectrogram look like? Are both frequencies present?\n\n\n\\paragraph{Step 3.2} Now set the \\block{DTMF} block to\n\\option{Record}. Also set the \\option{Resolution} parameter inside the\n\\block{Spectrogram} block to 4 or 8 (otherwise you may notice a lag\nfor updating the spectrogram - it can be considerably CPU intensive\nfor large input signals). The \\option{Resolution} parameter controls\nhow many points the sliding window advances at each time step (larger\nsteps mean we take fewer FFTs). Press each key in the \\block{DTMF}\nblock in turn. Does the spectrogram make it easier to judge the\nfrequency content of the keys? Include a screenshot for your report.\n\n% LocalWords:  WebQ MATLAB DSP\n", "meta": {"hexsha": "850d4c7515b1d609cba537c54ceca3612c3b0532", "size": 8014, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "J-DSP Labs/lab8/lab8.tex", "max_stars_repo_name": "stiber/Signal-Computing", "max_stars_repo_head_hexsha": "cb5c7825e0cc80ca2ecd3e324fcf6231c320a721", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-09-10T16:54:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T15:48:26.000Z", "max_issues_repo_path": "J-DSP Labs/lab8/lab8.tex", "max_issues_repo_name": "stiber/Signal-Computing", "max_issues_repo_head_hexsha": "cb5c7825e0cc80ca2ecd3e324fcf6231c320a721", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2015-08-18T18:16:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-29T17:19:16.000Z", "max_forks_repo_path": "J-DSP Labs/lab8/lab8.tex", "max_forks_repo_name": "stiber/Signal-Computing", "max_forks_repo_head_hexsha": "cb5c7825e0cc80ca2ecd3e324fcf6231c320a721", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.7395833333, "max_line_length": 89, "alphanum_fraction": 0.74694285, "num_tokens": 2207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.847967769904032, "lm_q2_score": 0.877476793890012, "lm_q1q2_score": 0.7440720400574534}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Which of the following sets are subspaces of $\\R^3$? Explain.\n  \\begin{enumerate}\n  \\item $V_1=\\set{\\left.\\vect{u}=\\begin{mymatrix}{c}\n          u_1 \\\\ u_2 \\\\ u_3\n        \\end{mymatrix}~\\right\\vert~ \\abs{u_1} \\leq 4}$.\n  \\item $V_2=\\set{\\left.\\vect{u}=\\begin{mymatrix}{c}\n          u_1 \\\\ u_2 \\\\ u_3\n        \\end{mymatrix}~\\right\\vert~\\text{$u_i\\geq 0$ for each $i=1,2,3$}}$.\n  \\item $V_3=\\set{\\left.\\vect{u}=\\begin{mymatrix}{c}\n          u_1 \\\\ u_2 \\\\ u_3\n        \\end{mymatrix}~\\right\\vert~ u_3+u_1=2u_2}$.\n  \\item $V_4=\\set{\\left.\\vect{u}=\\begin{mymatrix}{c}\n          u_1 \\\\ u_2 \\\\ u_3\n        \\end{mymatrix}~\\right\\vert~ u_3\\geq u_1}$.\n  \\item $V_5=\\set{\\left.\\vect{u}=\\begin{mymatrix}{c}\n          u_1 \\\\ u_2 \\\\ u_3\n        \\end{mymatrix}~\\right\\vert~ u_3=u_1=0}$.\n  \\end{enumerate}\n\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item\n      No. We have $\\begin{mymatrix}{r}\n        1 \\\\ 0 \\\\ 0 \\\\ 0\n      \\end{mymatrix} \\in V_1$ but $10\\begin{mymatrix}{r}\n        1 \\\\ 0 \\\\ 0 \\\\ 0\n      \\end{mymatrix} \\notin V_1$.\n    \\item\n      This is not a subspace. The vector $\\begin{mymatrix}{r}\n        1 \\\\ 1 \\\\ 1 \\\\ 1\n      \\end{mymatrix}$\n      is in $V_2$. However, $(-1) \\begin{mymatrix}{r}\n        1 \\\\ 1 \\\\ 1 \\\\ 1\n      \\end{mymatrix}$ is not.\n    \\item This is a subspace. It contains the zero vector and is\n      closed with respect to vector addition and scalar\n      multiplication.\n    \\item\n      This\n      is not a subspace. The vector $\\begin{mymatrix}{r}\n        0 \\\\ 0 \\\\ 1 \\\\ 0\n      \\end{mymatrix}$ is in $V_4$. However $(-1) \\begin{mymatrix}{r}\n        0 \\\\ 0 \\\\ 1 \\\\ 0\n      \\end{mymatrix}  = \\begin{mymatrix}{r}\n        0 \\\\ 0 \\\\ -1 \\\\ 0\n      \\end{mymatrix}$ is not.\n    \\item This is a subspace. It contains the zero vector and is\n      closed with respect to vector addition and scalar\n      multiplication.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $\\vect{w}\\in \\R^4$ be a given fixed vector. Let\n  \\begin{equation*}\n    M=\\set{\\left.\\vect{u}\n        =\\begin{mymatrix}{c}\n          u_1 \\\\ u_2 \\\\ u_3 \\\\ u_4\n        \\end{mymatrix} \\in \\R^4~\\right\\vert~ \\vect{w}\\dotprod \\vect{u}\n      =0}.\n  \\end{equation*}\n  Is $M$ a subspace of $\\R^4$? Explain.\n  \\begin{sol}\n    Yes, this is a subspace because it contains the zero vector and is\n    closed with respect to vector addition and scalar\n    multiplication. For example, if $\\vect{u},\\vect{v}\\in M$, then\n    $\\vect{w}\\dotprod\\vect{u}=0$ and $\\vect{w}\\dotprod\\vect{v}=0$,\n    therefore $\\vect{w}\\dotprod(\\vect{u}+\\vect{v})=0$, therefore\n    $\\vect{u}+\\vect{v}\\in M$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $\\vect{w},\\vect{v}$ be given vectors in $\\R^4$ and define\n  \\begin{equation*}\n    M=\\set{\\left.\\vect{u}=\\begin{mymatrix}{c}\n        u_1 \\\\ u_2 \\\\ u_3 \\\\ u_4\n      \\end{mymatrix} \\in \\R^4\n      ~\\right\\vert~\n    \\text{$\\vect{w}\\dotprod \\vect{u}=0$ and $\\vect{v}\\dotprod \\vect{u}=0$}}.\n  \\end{equation*}\n  Is $M$ a subspace of $\\R^4$? Explain.\n  \\begin{sol}\n    Yes, this is a subspace.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  In this exercise, we use scalars from the field $\\Z_2$ of integers\n  modulo $2$ instead of real numbers (see Section~\\ref{sec:fields},\n  ``Fields''). Which of the following sets are subspaces of\n  $(\\Z_2)^3$?\n  \\begin{enumerate}\n  \\item $V_1 = \\set{\n      \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    }$.\n  \\item $V_2 = \\set{\n      \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    }$.\n  \\item $V_3 = \\set{\n      \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    }$.\n  \\item $V_3 = \\set{\n      \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    }$.\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item $V_1$ is a subspace.\n    \\item $V_2$ is not a subspace: not closed under addition. For example,\n      \\begin{equation*}\n        \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix} \\in V_2,\\quad\n        \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix} \\in V_2,\\quad\n        \\mbox{but}\\quad\n        \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n        + \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n        = \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 1 \\end{mymatrix} \\not\\in V_2.\n      \\end{equation*}\n    \\item $V_3$ is a subspace.\n    \\item $V_4$ is not a subspace. For example, it does not contain\n      the zero vector.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $V, W$ are subspaces of $\\R^n$. Let $V\\cap W$ be the set\n  of all vectors that are in both $V$ and $W$. Show that $V\\cap W$\n  is also a subspace.\n  \\begin{sol}\n    Because $\\vect{0}\\in V$ and $\\vect{0}\\in W$, we have\n    $\\vect{0}\\in V\\cap W$. To show that $V\\cap W$ is closed under\n    addition, assume $\\vect{u},\\vect{v}\\in V\\cap W$. Then\n    $\\vect{u},\\vect{v}\\in V$, and since $V$ is a subspace we have\n    $\\vect{u}+\\vect{v}\\in V$. Similarly $\\vect{u},\\vect{v}\\in W$, and\n    since $W$ is a subspace we have $\\vect{u}+\\vect{v}\\in W$. It\n    follows that $\\vect{u}+\\vect{v}$ is in both $V$ and $W$, and\n    therefore in $V\\cap W$. To show that $V\\cap W$ is closed under\n    scalar multiplication, assume $\\vect{u}\\in V\\cap W$ and\n    $k\\in\\R$. Then $\\vect{u}\\in V$, and therefore $k\\vect{u}\\in\n    V$. Similarly $k\\vect{u}\\in W$, and therefore also\n    $k\\vect{u}\\in V\\cap W$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $V$ be a subset of $\\R^n$. Show that $V$ is a subspace if and\n  only if it is non-empty and the following condition holds: for all\n  $\\vect{u},\\vect{v}\\in V$ and all scalars $a,b\\in\\R$,\n  \\begin{equation*}\n    a\\vect{u} + b\\vect{v} \\in V.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Let $\\vect{u}_1,\\ldots,\\vect{u}_k$ be vectors in $\\R^n$, and let\n  $S=\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$. Show that $S$ is the\n  {\\em smallest} subspace of $\\R^n$ that contains\n  $\\vect{u}_1,\\ldots,\\vect{u}_k$.  Specifically, this means you have\n  to show: if $V$ is any other subspace of $\\R^n$ such that\n  $\\vect{u}_1,\\ldots,\\vect{u}_k\\in V$, then $S\\subseteq V$.\n\\end{ex}\n\n", "meta": {"hexsha": "c51e43aca089a3cf3b51d326df00953c11e0e77f", "size": 6407, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/SpanIndependenceBasis-Subspaces.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/SpanIndependenceBasis-Subspaces.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/SpanIndependenceBasis-Subspaces.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 36.197740113, "max_line_length": 76, "alphanum_fraction": 0.5720305915, "num_tokens": 2589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.8479677506936879, "lm_q1q2_score": 0.7440720286347446}}
{"text": "\\chapter{Short-Time Speech Processing}\n\\newpage\n\n\\section{Segmentations/Frames}\nAn underlying assumption of speech signal processing is that the speech signal is slowly-time-varying, i.e. it changes slowly with time. Based on this assuption, we can perform short-time signal processing by splitting speech signals into isolated segmentations or frames.\n\n\\subsection{Mathematical Framework of Short-Time Processing}\nShort-time analysis is represented in a general form of\n\\[ Q_{\\hat{n}} = \\sum_{m=-\\infty}^{+\\infty}T(x[m]w[\\hat{n}-m]) = \\sum_{m=-\\infty}^{+\\infty}T(x[m])\\tilde{w}[\\hat{n}-m] \\]\nwhere $\\tilde{w}[\\hat{n}-m]$ is a sliding analysis window and $T()$ is the operation on input signal. $Q_{\\hat{n}}$ represents the short-time representation of signal $\\tilde{x}$ at time $\\hat{n}$.\n\\begin{remark}\n    It's actually a discrete-time convolution of $T(x[m])$ with $\\tilde{w}[n]$\n\\end{remark}\n\n\\subsection{Length of Segments}\nThe shorter the segement, the less likely a signal will vary significantly over the segment duration (due to its slowly-changing nature), and thus tracking abrupt waveform changes is best for shorter segements.\nHowever, parameters estimated from short may be highly variable because the data available for processing is small.\n\n\\subsection{Stepsize}\nTypically, the window is moved in jumps of $R>1$ samples, which corresponds to downsampling the output of the signal by a factor of $R$. If the window is of length $L$, then we should choose $R<L$ so that each sample is included in at least one segement. \n\nTypically, the analysis windows overlap by more than $50\\%$ of the window length.\n\n\\subsection{Commonly Used Windows}\n\\begin{itemize}\n    \\item Rectangular Window\n    \\[ w_R[n] = \n    \\begin{cases}\n        1 &(0 \\le n \\le L-1)\\\\\n        0 &(\\text{o.w.})\n    \\end{cases}\n    \\]\n    \\item Hamming Window\n    \\[ w_H[n] = \n    \\begin{cases}\n        0.54-0.46\\cos(2\\pi n/(L-1)) &(0 \\le n \\le L-1)\\\\\n        0 &(\\text{o.w.})\n    \\end{cases}\n    \\]\n\\end{itemize}\n\n\\section{Short-Time Energy and Short-Time Magnitude}\n\\subsection{Energy of Signal}\n\\begin{definition}[Energy]\n    The energy of a discrete-time signal is\n    \\[ E = \\sum_{m=-\\infty}^{+\\infty}(x[n])^2 \\]\n\\end{definition}\nUseless because it does not give any time-dependent properties of a speech signal.\n\n\\subsection{Short-Time Energy}\n\\begin{definition}[Short-Time Energy]\n    \\[ E_{\\hat{n}} = \\sum_{m=-\\infty}^{+\\infty} (x[m]w[\\hat{n}-m])^2 = \\sum_{m=-\\infty}^{+\\infty} (x[m])^2\\tilde{w}[\\hat{n}-m]\\]\n\\end{definition}\nwhere $w[n]$ is the window applied to $x[n]$ before squaring, and $\\tilde{w}[n]$ is the corresponding window that can be applied equivalently after squaring.\n\nFor an $L$-point window,\n\\[ E_{\\hat{n}} = \\sum_{m=\\hat{n}-L+1}^{\\hat{n}} (x[m]w[\\hat{n}-m])^2 \\]\n\n$E_{\\hat{n}}$ provides a basis for distinguishing voiced speech segments from unvoiced speech segments. Unvoiced segments have significantly smaller short-time energy compared with Voiced segments.\n\nFor high-quality speech signal (high signal-to-noise ratio), $E_{\\hat{n}}$ can also be used to distinguish speech from silence.\n\n\\subsection{Short-Time Magnitude}\nShort-time energy can be very sensitive to large signal levels. This can be addressed by taking square roots, or using the short-time magnitude.\n\\begin{definition}[Short-Time Magnitude]\n    \\[ M_{\\hat{n}} = \\sum_{m=-\\infty}^{+\\infty} |x[m]w[\\hat{n}-m]| = \\sum_{m=-\\infty}^{+\\infty} |x[m]|\\tilde{w}[\\hat{n}-m]\\]\n\\end{definition}\n\n\\section{Short-Time Zero-Crossing Rate}\nA \\textbf{zero-crossing} is said to occur if successive waveform samples have different algebraic signs.\n\\begin{definition}[Short-Time Zero-Crossing Rate]\n    \\[ Z_{\\hat{n}} = \\frac{1}{2L_{eff}}\\sum_{m=\\hat{n}-L+1}^{\\hat{n}} |\\sgn(x[m])| - \\sgn(x[m-1])| \\tilde{w}[\\hat{n}-m] \\]\n\\end{definition}\nTypically, the window used here is a rectangular window, so\n\\[ Z_{\\hat{n}} = \\frac{1}{2L}\\sum_{m=\\hat{n}-L+1}^{\\hat{n}} |\\sgn(x[m])| - \\sgn(x[m-1])| \\]\n\nVoiced speech will have relatively low zero-crossing rate, and Unvoiced speech will have relatively high zero-crossing rate.\n\n\\section{Short-Time AutoCorrelation}\n\\subsection{AutoCorrelation}\n\\begin{definition}[AutoCorrelation]\n    For determinisitc or aperiodic signals\n    \\[ \\phi[k] = \\sum_{m=-\\infty}^{+\\infty}x[m]x[m+k] \\]\n    For stationary random or periodic signals\n    \\[ \\phi[k] = \\lim_{N\\to\\infty}\\frac{1}{2N+1}\\sum_{m=-N}^{N}x[m]x[m+k] \\]\n\\end{definition}\n\\begin{remark}\n    AutoCorrelation highlights the period of signals because a local maximum is achieved at samples $0, \\pm N, \\pm 2N, \\dots$, regardless of the time origin of the periodic signal.\n\\end{remark}\n\\begin{proposition}\n    Properties of autocorrelation:\n    \\begin{itemize}\n        \\item For periodic signals: \n        \\[ \\phi[k] = \\phi[k+N] \\]\n        \\item $\\phi[k]$ = $\\phi[-k]$\n        \\item $\\phi[0] \\le |\\phi[k]|$ for all $k$\n        \\item $\\phi[0]$ equals to the total energy for determinisitc signals and average power of random signals.\n    \\end{itemize}\n\\end{proposition}\n\n\\subsection{Short-Time AutoCorrelation}\n\\begin{definition}[Short-Time AutoCorrelation]\n    \\[ R_{\\hat{n}}[k] = \\sum_{m=-\\infty}^{+\\infty}(x[m]w[\\hat{n}-m])(x[m+k]w[\\hat{n}-k-m]) \\]\n\\end{definition}\n\\begin{remark}\n    Short-Time AutoCorrelation preserves the properties of autocorrelation in the previous section, and $R_{\\hat{n}}[0]$ is equivalent to the short-time energy.\n\\end{remark}\n\n\\section{Short-Time Average Magnitude Difference Function}\nThe computation of autocorrelation involves considerable arithmetic.\n\nNote that for a truly periodic signal,\n\\[ d[k] = x[n] -x[n-k] \\]\nwould be $0$ whenever $k=0,\\pm N, \\pm 2N, \\dots$. So it is reasonable to expect that $d[n]$ will be small at multiples of period for short segements of voiced speech.\n\\begin{definition}[Short-Time AMDF]\n    \\[ \\gamma_{\\hat{n}}[k] = \\sum_{m=-\\infty}^{+\\infty} |x[\\hat{n}+m]w_1[m] - x[\\hat{n}+m-k]w_2[m-k] | \\]\n\\end{definition}\n\\begin{remark}\n    $\\gamma_{\\hat{n}}[k]$ would drop sharply near multiples of period.\n\\end{remark}\n\nAutoCorrelation and AMDF are used to find the \\textbf{pitch} (aka \\textbf{foundamental frequency}) of the speech.\n\n\\section{Short-Time Fourier Transform}\n\\begin{definition}[Continuous Time STFT]\n    \\[ X(\\hat{t}, \\Omega) = \\int_{-\\infty}^{+\\infty} w(\\hat{t}- t)x(t)e^{-j\\Omega t}\\mathrm{d}t \\]\n\\end{definition}\n\\begin{definition}[Discrete Time STFT]\n    \\[ X_{\\hat{n}}(e^{j\\omega}) = \\sum_{m=-\\infty}^{+\\infty}w[\\hat{n}-m]x[m]e^{-j\\omega m} \\]\n\\end{definition}\n\\begin{definition}[Spectrogram]\n    A spectrogram is a gray-scale image whose $x$-axis is time and $y$-axis is frequency, and its colormap indicates the log amplitude.\n\\end{definition}\n\\begin{remark}\n    If the band pass filter has wide bandwidth(300-900Hz), then the spectrogram has good temporal resolution but poor frequency resolution. On the other hand, if the band pass filter has narrow bandwidth(30-90Hz), then the spectrogram has poor temporal resolution but good frequency resolution.\n\\end{remark}", "meta": {"hexsha": "d06f6ce95c5ff57acb638f16df3ad932bdb0d6d4", "size": 6987, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Speech Recognition/ShortTimeProcessing.tex", "max_stars_repo_name": "YBRua/CourseNotes", "max_stars_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-20T10:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T08:15:15.000Z", "max_issues_repo_path": "Speech Recognition/ShortTimeProcessing.tex", "max_issues_repo_name": "YBRua/CourseNotes", "max_issues_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Speech Recognition/ShortTimeProcessing.tex", "max_forks_repo_name": "YBRua/CourseNotes", "max_forks_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T11:31:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T11:31:00.000Z", "avg_line_length": 51.375, "max_line_length": 294, "alphanum_fraction": 0.6947187634, "num_tokens": 2129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.8774767890838836, "lm_q1q2_score": 0.7440720191253802}}
{"text": "\\chapter{Geometry}\nGeometry (from the Ancient Greek: geo- \"earth\", -metron \"measurement\") is a branch of mathematics concerned with questions of shape, size, relative position of figures, and the properties of space.\n\n\n\\section{Plane Geometry}\n\\subsection{Point, Lines}\nDistance between two points $P=(x_1,y_1)$ and $Q=(x_2,y_2)$ in $\\mathbb{R}^2$ : \n\\[ \\overline{PQ} = \\sqrt{(x_1-x_2)^2+(y_1-y_2)^2} \\]\n\nMidpoint between P and Q: \n\\[ \\left(\\frac{x_1+x_2}{2},\\frac{y_1+y_2}{2}\\right) \\]\n\nLines equation given one point P: \n\\[ y-y_1 = m(x-x_1) \\]\n\nLine equation given two points P and Q: \n\\[ y-y_1 = \\frac{y_2-y_1}{x_2-x_1}(x-x_1) \\] \n\nDistance of one point P from the line r with equation $ax+by+c=0$ : \n\\[ d(U,r) = \\frac{\\left|ax_1+by_1+c\\right|}{\\sqrt{a^2+b^2}} \\]\n\n\n\\section{Trigonometry}\n\\textbf{Definition:} Trigonometry (from Greek trigonon, \"triangle\" and metron, \"measure\") is a branch of mathematics that studies relationships involving lengths and angles of triangles.\n\n\\subsection{Goniometric functions}\n\\textbf{Definition:} In mathematics, the goniometric functions (also called circular functions, angle functions or trigonometric functions) are functions of an angle. They relate the angles of a triangle to the lengths of its sides. \n\nFor the goniometric ratios for a point $p$ on the unit circle holds:\n\\begin{table}[ht!]\n\\centering\n\\begin{tabular}{ c | c | c }\n$ \\displaystyle \\sin(\\phi)=y_p $   & \n$ \\displaystyle \\cos(\\phi)=x_p $   & \n$ \\displaystyle \\tan(\\phi)=\\frac{\\sin(\\phi)}{\\cos(\\phi)} $\n\\end{tabular}\n\\end{table}\n\nThe reciprocal functions secant (sec), cosecant (csc), and cotangent (cot) are the reciprocals of the cosine, sine, and tangent:\n\n\\begin{table}[ht!]\n\t\\centering\n\t\\begin{tabular}{ c | c | c }\n\t$ \\displaystyle \\sec(\\phi)=\\frac{1}{\\sin{\\phi}} $  &\n\t$ \\displaystyle \\csc(\\phi)=\\frac{1}{\\cos{\\phi}} $  &\n\t$ \\displaystyle \\cot(\\phi)=\\frac{1}{\\tan(\\phi)}=\\frac{\\cos(\\phi)}{\\sin(\\phi)} $\n\t\\end{tabular}\n\\end{table}\n\n\\subsubsection{Inverse goniometric functions}\n\\begin{tabular}{  | c || c | c | c | c | c | c | }\n\t\\hline\n\tFunction   &  $\\sin$  &  $\\cos$  &  $\\tan$  &  $\\sec$ &  $\\csc$ &  $\\cot$ \\\\\n\t\\hline\n\tInverse   &  $\\arcsin$  &  $\\arccos$  &  $\\arctan$  &  arcsec  &  arccsc  &  arccot \\\\\n\t\\hline\t\n\\end{tabular}\n\n\n\\subsubsection{Pythagorean trigonometric identity}\n\\[\n\\sin^2(\\phi)+\\cos^2(\\phi)=1 \n\\]\n\n\n\\subsubsection{Identities in terms of their complements and supplements}\n\\[\n\\sin\\left(\\frac{\\pi}{2}-\\phi\\right)=\\cos(\\phi) \\ \\ , \\ \\ \\cos\\left(\\frac{\\pi}{2}-\\phi\\right)=\\sin(\\phi)\n\\]\n\\[\n\\sin\\left(\\frac{\\pi}{2}+\\phi\\right)=\\cos(\\phi) \\ \\ , \\ \\ \\cos\\left(\\frac{\\pi}{2}+\\phi\\right)=-\\sin(\\phi)\n\\]\n\n\\[\n\\sin(\\pi-\\phi)=\\sin(\\phi) \\ \\ , \\ \\ \\cos(\\pi-\\phi)=-\\cos(\\phi)\n\\]\n\\[\n\\sin(\\pi+\\phi)=-\\sin(\\phi) \\ \\ , \\ \\ \\cos(\\pi+\\phi)=-\\cos(\\phi)\n\\]\n\n\\[\n\\sin\\left(\\frac{3}{2}\\pi-\\phi\\right)=-\\cos(\\phi) \\ \\ , \\ \\ \\cos\\left(\\frac{3}{2}\\pi-\\phi\\right)=-\\sin(\\phi)\n\\]\n\\[\n\\sin\\left(\\frac{3}{2}\\pi+\\phi\\right)=-\\cos(\\phi) \\ \\ , \\ \\ \\cos\\left(\\frac{3}{2}\\pi+\\phi\\right)=\\sin(\\phi)\n\\]\n\n\n\\subsubsection{Identities for negative angles}\n\\[\n\\sin(-\\phi) = -\\sin(\\phi) \\ , \\ \\cos(-\\phi) = \\cos(\\phi)\n\\]\n\n\n\\subsubsection{Periodicity of trig functions}\n\\[\n\\sin(\\phi+2\\pi)=\\sin(\\phi) \\ , \\ \\cos(\\phi+2\\pi)=\\cos(\\phi) \\ , \\ \\tan(\\phi+\\pi)=\\tan(\\phi)\n\\]\n\n\n\\subsubsection{Ptolemy's identities}\n\\[\n\\sin(a+b)=\\sin(a)\\cos(b)+\\cos(a)\\sin(b)\n\\]\n\\[\n\\cos(a+b)=\\cos(a)\\cos(b)-\\sin(a)\\sin(b)\n\\]\n\\[\n\\sin(a-b)=\\sin(a)\\cos(b)-\\cos(a)\\sin(b)\n\\]\n\\[\n\\cos(a-b)=\\cos(a)\\cos(b)+\\sin(a)\\sin(b)\n\\]\n\n\\[\n\\tan(\\alpha+\\beta)=\\frac{\\tan(\\alpha) + \\tan(\\beta)}{1-\\tan(\\alpha)\\tan(\\beta)} \\text{ where } \\alpha, \\beta, \\alpha+\\beta \\ne \\frac{\\pi}{2} + k\\pi, \\ k \\in \\mathbb{Z}\n\\]\n\\[\n\\tan(\\alpha-\\beta)=\\frac{\\tan(\\alpha) - \\tan(\\beta)}{1+\\tan(\\alpha)\\tan(\\beta)} \\text{ where } \\alpha, \\beta, \\alpha-\\beta \\ne \\frac{\\pi}{2} + k\\pi, \\ k \\in \\mathbb{Z}\n\\]\n\n\\subsubsection{Double angle formulas}\n\\begin{align*}\n\\sin(2\\alpha) &= 2\\sin(\\alpha)\\cos(\\alpha) \\\\ \n\\cos(2\\alpha) &=\\cos^2(\\alpha)-\\sin^2(\\alpha) = 2\\cos^2(\\alpha)-1 = 1 - 2\\sin^2(\\alpha) \\\\\n\\tan(2\\alpha) &= \\frac{2\\tan(\\alpha)}{1-2\\tan^2(\\alpha)} \\text{ where } \\alpha \\ne \\frac{\\pi}{4}+k\\frac{\\pi}{2} \\ \\wedge \\ \\alpha \\ne \\frac{\\pi}{2}+k\\pi, \\ k \\in \\mathbb{Z}\n\\end{align*}\n\n\n\\subsubsection{Half angle formulas}\n\\begin{tabularx}{\\textwidth}{ X X X }\n$ \\displaystyle \\sin^2\\left(\\frac{\\alpha}{2}\\right) = \\frac{1-\\cos(\\alpha)}{2} $ & \n$ \\displaystyle \\cos^2\\left(\\frac{\\alpha}{2}\\right) = \\frac{1+\\cos(\\alpha)}{2} $ &\n$  \\displaystyle \\tan\\left(\\frac{\\alpha}{2}\\right) = \\frac{\\sin(\\alpha)}{1+\\cos(\\alpha)} $\n\\end{tabularx}\n\n\n\\subsubsection{Product-to-sum identities}\n\\[\n2\\sin(\\alpha)\\sin(\\beta) = \\cos(\\alpha-\\beta) - \\cos(\\alpha+\\beta)\n\\]\n\\[\n2\\cos(\\alpha)\\cos(\\beta) = \\cos(\\alpha-\\beta) + \\cos(\\alpha+\\beta)\n\\]\n\\[\n2\\sin(\\alpha)\\cos(\\beta) = \\sin(\\alpha-\\beta) + \\sin(\\alpha+\\beta)\n\\]\n\n\\subsubsection{Sum-to-product identities}\n\\[\n\\sin(\\alpha)+\\sin(\\beta) = 2\\sin\\left(\\frac{\\alpha+\\beta}{2}\\right)\\cos\\left(\\frac{\\alpha-\\beta}{2}\\right)\n\\]\n\\[\n\\sin(\\alpha)-\\sin(\\beta) = 2\\cos\\left(\\frac{\\alpha+\\beta}{2}\\right)\\sin\\left(\\frac{\\alpha-\\beta}{2}\\right)\n\\]\n\\[\n\\cos(\\alpha)+\\cos(\\beta) = 2\\cos\\left(\\frac{\\alpha+\\beta}{2}\\right)\\cos\\left(\\frac{\\alpha-\\beta}{2}\\right)\n\\]\n\\[\n\\cos(\\alpha)-\\cos(\\beta) = -2\\sin\\left(\\frac{\\alpha+\\beta}{2}\\right)\\sin\\left(\\frac{\\alpha-\\beta}{2}\\right)\n\\]\n\n\\subsubsection{Tangent half-angle substitution}\n$ \\displaystyle \\sin(\\alpha) = \\frac{2t}{1+t^2} \\text{ where } t=\\tan\\left(\\frac{\\alpha}{2}\\right) \\text{ and } \\alpha \\ne \\pi + 2k\\pi $\n\n$ \\displaystyle \\cos(\\alpha) = \\frac{1-t^2}{1+t^2} \\text{ where } t=\\tan\\left(\\frac{\\alpha}{2}\\right) \\text{ and } \\alpha \\ne \\pi + 2k\\pi $\n\n$ \\displaystyle \\tan(\\alpha) = \\frac{2t}{1-t^2} \\text{ where } t=\\tan\\left(\\frac{\\alpha}{2}\\right) \\text{ and } \\alpha \\ne \\frac{\\pi}{2} + k\\pi \\ \\wedge \\ \\alpha \\ne \\pi + 2k\\pi $\n\n\n\\subsection{Conversions of common angles}\n\n\\begin{tabular}{  | c | c || c | c | c | c | }\n\t\\hline\n\tDegrees          & Radians              & Sin                               & Cos                                               & Tan                                    & Cot               \\\\\n\t\\hline\n    $0^{\\circ}$      & 0                    & 0                                 &  1                                                & 0                                      & $\\pm\\infty$        \\\\\n    \\hline\t\n    $15^{\\circ}$     & $\\frac{\\pi}{12}$     & $\\frac{\\sqrt{6}-\\sqrt{2}}{4}$       &  $\\frac{\\sqrt{6}+\\sqrt{2}}{4}$                      & $2-\\sqrt{3}$                            & $2+\\sqrt{3}$       \\\\\n    \\hline\t\t\n    $30^{\\circ}$     & $\\frac{\\pi}{6}$     & $\\frac{1}{2}$      &   $\\frac{\\sqrt{3}}{2} $     &  $\\frac{\\sqrt{3}}{3}$    &  $\\sqrt{3}$  \\\\\n    \\hline\t\t\n    $45^{\\circ}$     & $\\frac{\\pi}{4}$     & $\\frac{\\sqrt{2}}{2}$   &   $\\frac{\\sqrt{2}}{2}$    &  1    &  1  \\\\\n    \\hline\t\t\n    $60^{\\circ}$     & $\\frac{\\pi}{3}$     & $\\frac{\\sqrt{3}}{2}$   &   $\\frac{1}{2}$    &  $\\sqrt{3}$    &  $\\frac{\\sqrt{3}}{3}$  \\\\\n    \\hline\t\t\n    $75^{\\circ}$     & $\\frac{5}{12}\\pi$     & $\\frac{\\sqrt{6}+\\sqrt{2}}{4}$   &   $\\frac{\\sqrt{6}-\\sqrt{2}}{4}$    &  $2+\\sqrt{3}$    &  $2-\\sqrt{3}$  \\\\\n    \\hline\n    $90^{\\circ}$     & $\\frac{\\pi}{2}$     & 1   &   0    &  $\\pm\\infty$   &  0  \\\\\n    \\hline\n   \t$105^{\\circ}$     & $\\frac{7}{12}\\pi$     & $\\frac{\\sqrt{6}+\\sqrt{2}}{4}$   &   $\\frac{\\sqrt{2}-\\sqrt{6}}{4}$    &  $-2-\\sqrt{3}$    &  $\\sqrt{3}-2$  \\\\\n    \\hline\n    $120^{\\circ}$     & $\\frac{2}{3}\\pi$     & $\\frac{\\sqrt{3}}{2}$      &   $-\\frac{1}{2} $     &  $-\\sqrt{3}$    &  $-\\frac{\\sqrt{3}}{3}$  \\\\\n    \\hline\t\n  \t$135^{\\circ}$     & $\\frac{3}{4}\\pi$     & $\\frac{\\sqrt{2}}{2}$   &   $-\\frac{\\sqrt{2}}{2}$    &  -1    &  -1  \\\\\n  \t\\hline\n  \t$150^{\\circ}$     & $\\frac{5}{6}\\pi$     & $\\frac{1}{2}$      &   $-\\frac{\\sqrt{3}}{2}$     &  $-\\frac{\\sqrt{3}}{3}$    &  $-\\sqrt{3}$  \\\\\n  \t\\hline\t\n    $165^{\\circ}$     & $\\frac{11}{12}\\pi$   & $\\frac{\\sqrt{6}-\\sqrt{2}}{4}$       &  -$\\frac{\\sqrt{6}+\\sqrt{2}}{4}$     & $\\sqrt{3}-2$   & $-\\sqrt{3}-2$       \\\\\n    \\hline\n    $180^{\\circ}$     & $\\pi$     & 0   &   -1   &  0    &  $\\pm\\infty$  \\\\\n    \\hline\n\t$195^{\\circ}$     & $\\frac{13}{12}\\pi$   & $\\frac{\\sqrt{2}-\\sqrt{6}}{4}$       &  -$\\frac{\\sqrt{6}+\\sqrt{2}}{4}$     & $2-\\sqrt{3}$   & $2+\\sqrt{3}$       \\\\\n\t\\hline\n\t$210^{\\circ}$     & $\\frac{7}{6}\\pi$     & $-\\frac{1}{2}$      &   $-\\frac{\\sqrt{3}}{2}$     &  $\\frac{\\sqrt{3}}{3}$    &  $\\sqrt{3}$  \\\\\n\t\\hline\n  \t$225^{\\circ}$     & $\\frac{5}{4}\\pi$     & $-\\frac{\\sqrt{2}}{2}$      &   $-\\frac{\\sqrt{2}}{2}$     &  1    &  1  \\\\\n  \t\\hline\t\n  \t$240^{\\circ}$     & $\\frac{4}{3}\\pi$     & $-\\frac{\\sqrt{3}}{2}$      &   $-\\frac{1}{2}$     &  $\\sqrt{3}$    &  $\\frac{\\sqrt{3}}{3}$  \\\\\n  \t\\hline\n     $255^{\\circ}$     & $\\frac{17}{12}\\pi$   & $-\\frac{\\sqrt{6}+\\sqrt{2}}{4}$       &  $\\frac{\\sqrt{2}-\\sqrt{6}}{4}$     & $2+\\sqrt{3}$   & $2-\\sqrt{3}$       \\\\\n     \\hline\n     $270^{\\circ}$     & $\\frac{3}{2}\\pi$     & -1      &   0    &  $\\pm\\infty$    &  0  \\\\\n     \\hline\t\n    $285^{\\circ}$     & $\\frac{19}{12}\\pi$   & $-\\frac{\\sqrt{6}+\\sqrt{2}}{4}$       &  $\\frac{\\sqrt{6}-\\sqrt{2}}{4}$     & $-2-\\sqrt{3}$   & $\\sqrt{3}-2$       \\\\\n    \\hline\n    $300^{\\circ}$     & $\\frac{5}{3}\\pi$     & $-\\frac{\\sqrt{3}}{2}$      &   $\\frac{1}{2}$     &  $-\\sqrt{3}$    &  $-\\frac{\\sqrt{3}}{3}$  \\\\\n    \\hline\t\n    $315^{\\circ}$     & $\\frac{7}{4}\\pi$     & $-\\frac{\\sqrt{2}}{2}$      &   $\\frac{\\sqrt{2}}{2}$     &  -1   &  -1  \\\\\n    \\hline\t\n    $330^{\\circ}$     & $\\frac{11}{6}\\pi$     & $-\\frac{1}{2}$      &   $\\frac{\\sqrt{3}}{2}$     &  -$\\frac{\\sqrt{3}}{3}$   &  $-\\sqrt{3}$  \\\\\n    \\hline\t\n     $345^{\\circ}$     & $\\frac{23}{12}\\pi$     & $\\frac{\\sqrt{2}-\\sqrt{6}}{4}$       &  $\\frac{\\sqrt{2}+\\sqrt{6}}{4}$    &  $\\sqrt{3}-2$    &  $-2-\\sqrt{3}$  \\\\\n     \\hline\t\n     $360^{\\circ}$     & $2\\pi$   & 0       &  1     & 0   & $\\pm\\infty$       \\\\\n     \\hline\n\\end{tabular}\n\n\n\\section{Polar, Cylindrical and Spherical Coordinates}\n\\subsection{Polar Coordinates}\nThe polar coordinate system is a two-dimensional coordinate system in which each point on a plane is determined by a distance from a reference point and an angle from a reference direction.\n\nThe polar coordinates $r$ and $\\varphi$ can be converted to the Cartesian coordinates $x$ and $y$ by:\n\\[\nx=r\\cos \\varphi  ~~~, ~~~ y=r\\sin \\varphi\n\\]\n\nThe Cartesian coordinates $x$ and $y$ can be converted to polar coordinates $r$ and $\\varphi$ with $r \\ge 0$ and $\\varphi$ in the interval $(-\\pi, \\pi]$ by:\n\n$ \\displaystyle r= \\sqrt{ x^2 + y^2 } $\n\n$ \\displaystyle \\varphi = atan2(y,x) = \n\\begin{cases}\n\\arctan(y/x) & \\text{ if } x>0 \\\\\n\\arctan(y/x) + \\pi & \\text{ if } x<0 \\text{ and } y\\ge0\\\\\n\\arctan(y/x) - \\pi & \\text{ if } x<0 \\text{ and } y<0\\\\\n\\pi/2 & \\text{ if } x=0 \\text{ and } y>0\\\\\n-\\pi/2 & \\text{ if } x=0 \\text{ and } y<0\\\\\n\\text{undefined} & \\text{ if } x=0 \\text{ and } y=0\\\\\n\\end{cases}\n$\n\n\n\n\\subsection{Cylindrical Coordinates}\nA cylindrical coordinate system is a three-dimensional coordinate system that specifies point positions by the distance from a chosen reference axis, the direction from the axis relative to a chosen reference direction, and the distance from a chosen reference plane perpendicular to the axis. The latter distance is given as a positive or negative number depending on which side of the reference plane faces the point.\n\n\\subsubsection{Convert From and To Cartesian coordinates}\nFor the conversion between cylindrical and Cartesian coordinates, it is convenient to assume that the reference plane of the former is the Cartesian $xy$-plane (with equation $z = 0$), and the cylindrical axis is the Cartesian $z$-axis. Then the $z$-coordinate is the same in both systems, and the correspondence between cylindrical (radius $\\rho$, azimuth $\\varphi$, elevation $z$) and Cartesian are the same as for polar coordinates, namely\n\\[\nx=\\rho \\cos \\varphi  ~~~, ~~~ y=\\rho \\sin \\varphi ~~~, ~~~ z=z\n\\]\n\n\\subsection{Spherical Coordinates}\nIn mathematics, a spherical coordinate system is a coordinate system for three-dimensional space where the position of a point is specified by three numbers: the radial distance of that point from a fixed origin, its polar angle measured from a fixed zenith direction, and the azimuth angle of its orthogonal projection on a reference plane that passes through the origin and is orthogonal to the zenith, measured from a fixed reference direction on that plane.\n\n\\subsubsection{Convert From and To Cartesian coordinates}\nThe spherical coordinates of a point in the ISO convention (i.e. for physics: radius $r$, inclination $\\theta$, azimuth $\\varphi$) can be obtained from its Cartesian coordinates $(x, y, z)$ by the formulae:\n\\[\nr=\\sqrt{x^2+y^2+z^2} ~~,~~ \\theta=\\arccos\\frac{z}{r} ~~,~~ \\varphi = \\arctan\\frac{y}{x}\n\\]\n\nConversely, the Cartesian coordinates may be retrieved from the spherical coordinates (where $r \\in [0, +\\infty), \\theta \\in [0, \\pi], \\varphi \\in [0, 2\\pi)$), by:\n\\[\nx=r\\sin\\theta\\cos\\varphi ~~,~~ y=r\\sin\\theta\\sin\\varphi ~~,~~ z=r\\cos\\theta\n\\]\n\n\\subsubsection{Convert From and To Cylindrical coordinates}\nCylindrical coordinates may be converted into spherical coordinates, by the formulas:\n\n\\[\nr=\\sqrt{\\rho^2 + z^2} ~~,~~ \\theta=\\arctan\\frac{\\rho}{z}=\\arccos\\frac{z}{r}   ~~,~~ \\varphi = \\varphi\n\\]\n\nConversely, the spherical coordinates may be converted into cylindrical coordinates by the formulae:\n\n\\[\n\\rho = r\\sin\\theta   ~~,~~  \\varphi=\\varphi  ~~,~~ z = r\\cos\\theta\n\\]", "meta": {"hexsha": "3d56554652b3916191a0c05b9103b6b4e0b3f50c", "size": 13431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematics_Formulary/sections/geometry.tex", "max_stars_repo_name": "ufoscout/Physics_notes", "max_stars_repo_head_hexsha": "68e705f1afc087af3161dd2eb5ff556cf3873533", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Mathematics_Formulary/sections/geometry.tex", "max_issues_repo_name": "ufoscout/Physics_notes", "max_issues_repo_head_hexsha": "68e705f1afc087af3161dd2eb5ff556cf3873533", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mathematics_Formulary/sections/geometry.tex", "max_forks_repo_name": "ufoscout/Physics_notes", "max_forks_repo_head_hexsha": "68e705f1afc087af3161dd2eb5ff556cf3873533", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-29T08:25:09.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-29T08:25:09.000Z", "avg_line_length": 46.3137931034, "max_line_length": 461, "alphanum_fraction": 0.5527510982, "num_tokens": 4998, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.8080672181749421, "lm_q1q2_score": 0.7440599571908261}}
{"text": "\\chapter{Quantum Mechanics: The Basics}\n\nThis chapter is a brief review of the fundamental quantum mechanics necessary for our treatment of quantum information theory. In here we discuss the basic mathematical objects and tools we shall deal with in the next chapter.\n\n\\section{Representing a Quantum Mechanical State}\n\\par The quantum mechanical state of a system is represented by a vector $\\Ket{\\psi}$ in the complex vector space known as the Hilbert space. In this section we see how such a state is constructed.\n\\par Let us consider a two-level quantum system such as a spin-half particle. Its state can be written in terms of two basis states which represent spin-up and spin-down. We can call these basis states $\\Ket{0}$ and $\\Ket{1}$ which are two orthogonal and normalized vectors in the Hilbert space.\n\\begin{align*}\n\\Ket{0} = \\left(\\! \\begin{array}{c} 1 \\\\ 0 \\end{array} \\!\\right) \\\\\n\\Ket{1} = \\left(\\! \\begin{array}{c} 0 \\\\ 1 \\end{array} \\!\\right)\n\\end{align*}\nIn such case the general state of the particle can be written as\n\\begin{align*}\n\\Ket{\\psi} = \\alpha \\Ket{0} + \\beta \\Ket{1}\n\\end{align*}\n\\par When the particle's spin along an axis is measured, it collapses to one of these two states $\\Ket{0}$ and $\\Ket{1}$ with probabilities $|\\alpha|^2$ and $|\\beta|^2$ respectively with the condition that\n\\begin{align*}\n|\\alpha|^2 + |\\beta|^2 = 1\n\\end{align*}\n\\par Instead of the basis states chosen above we could have chosen any other other as long as they are orthogonal and normalized so that they represent perfectly distinguishable outcomes in an experiment. One such example would be\n\\begin{center}\n$ \\frac{1}{\\sqrt{2}} \\left(\\! \\begin{array}{c} 1 \\\\ 1 \\end{array} \\!\\right) $ and $ \\frac{1}{\\sqrt{2}} \\left(\\! \\begin{array}{c} -1 \\\\ 1 \\end{array} \\!\\right) $\n\\end{center}\nThe important point is that the chosen basis has to be consistent across our calculations. That is, when we bring physical quantities together in a calculation they have to be represented in the same basis. If they are not then they will need to be rotated into one standard basis. This operation of rotation is called a unitary transformation and represented by a matrix $U$ such that $U U^\\dagger = U^\\dagger U = I$. Unitary transformations have the property that they do not change the physically observable outcomes. Under a unitary transformation the predictions for all those observables will remain the same.\n\\par After establishing the general idea let us now look at an example state we may represent in this way.\n\\begin{align*}\n  \\Ket{\\psi} &= \\frac{2}{\\sqrt{5}} \\Ket{0} + \\frac{1}{\\sqrt{5}} \\Ket{1} \\\\\n  &= \\frac{2}{\\sqrt{5}} \\left(\\! \\begin{array}{c} 1 \\\\ 0 \\end{array} \\!\\right) + \\frac{1}{\\sqrt{5}} \\left(\\! \\begin{array}{c} 0 \\\\ 1 \\end{array} \\!\\right) \\\\\n  &= \\frac{1}{\\sqrt{5}} \\left(\\! \\begin{array}{c} 2 \\\\ 1 \\end{array} \\!\\right)\n\\end{align*}\n\\par In this case we see that $\\alpha = \\frac{2}{\\sqrt{5}}$ and $\\beta = \\frac{1}{\\sqrt{5}}$.\n\\section{Pure States and Mixed States}\nIn terms of information that we have about the preparation of a quantum mechanical state, we identify it as either a pure state or as a mixed state.\n\\subsection{Pure State}\n\\par A pure state is a state for which we have complete knowledge about the preparation procedure. We already know in advance how the state was prepared, which, in principle is all that we can know about the system. The example of $\\Ket{\\psi}$ in the previous section is that of a pure state. We have a single state $\\Ket{\\psi}$ with 100\\% certainty and the predictions we can make about it can be no more accurate than they are with our current knowledge of it.\n\\par At this point it will be appropriate to introduce a more general representation of a quantum mechanical state than a simple ket vector. This representation we are going to introduce is called the \\textbf{density operator or density matrix}.\n\\subsection{The Density Operator}\n\\par The density operator for a state $\\Ket{\\psi}$ is simply a projection operator that projects all the vectors onto the state vector $\\Ket{\\psi}$.\n\\par If $\\Ket{\\psi}$ is represented by the column vector\n\\begin{align*}\n\\Ket{\\psi} = \\left(\\! \\begin{array}{c} a \\\\ b \\end{array} \\!\\right)\n\\end{align*}\nThen the density operator for the state would be\n\\begin{align*}\n  \\hat{\\rho} = \\Ket{\\psi} \\Bra{\\psi} &= \\begin{pmatrix} a \\\\ b \\end{pmatrix} \\begin{pmatrix} a^* & b^* \\end{pmatrix} \\\\\n  &= \\begin{pmatrix} |a|^2 & a b^* \\\\ a^* b & |b|^2 \\end{pmatrix}\n\\end{align*}\n\\par From this density operator we can determine outcomes of physical experiments. In quantum mechanics physical observable quantities are represented by Hermitian operators. Suppose we apply an observable $\\hat{O}$ to the density matrix which is the mathematical equivalent of performing the observation in an experiment. The state will collapse and the outcome of the experiment will have the expectation value of\n\\begin{align*}\n  \\braket{\\hat{O}} &= tr\\{\\hat{O} \\Ket{\\psi} \\Bra{\\psi}\\} \\\\\n  \\braket{\\hat{O}} &= tr\\{\\hat{O} \\hat{\\rho}\\}\n\\end{align*}\nHere $tr$ represents the trace operation, which is taking the sum of all entries on the main diagonal of the matrix.\n\n\\subsection{Mixed State}\n\\par In general when we deal with quantum systems in the real world, we will not have complete knowledge on how the state was prepared. This lack of knowledge can be due to several factors. It can be caused by errors in the apparatus that prepares the quantum state or it can be introduced later by environmental factors. In both cases we will not have a pure state with 100\\% certainty.\n\\par Let us take a look at a real world example. Suppose we want to prepare a number of atoms in state $\\ket{\\psi_0}$. We have an apparatus to do that for us. However due to some random error in the machinery some of the atoms are prepared in state $\\ket{\\psi_1}$ instead. Let's suppose the state we want, $\\ket{\\psi_0}$, is prepared with a 95\\% accuracy. Then the rest of the atoms we get from the machine - 5\\% of them - will be in state $\\ket{\\psi_1}$. In this case we have a mixed state.\n\\par Notice that the probabilities involving the states are no longer limited to the quantum domain. There are now classical probabilities involved as well. 0.95 is the classical probability of $\\ket{\\psi_0}$ occurring in the mix and 0.05 is the classical probability of $\\ket{\\psi_1}$ occurring.\n\\par In general, we will have a mixture of more than one states each occurring with its respective classical probability. $\\ket{\\psi_0}$ with probability $p_0$, $\\ket{\\psi_1}$ with probability $p_1$, $\\ket{\\psi_2}$ with probability $p_2$, and so on.\n\n\\subsection{Density Operator for Mixed States}\n\\par For a mixture of a number of quantum states where each state $\\ket{\\psi_i}$ occurs with classical probability $p_i$, the density operator is written as\n\\begin{align*}\n\\hat{\\rho} = \\sum_i \\ket{\\psi_i} \\bra{\\psi_i}\n\\end{align*}\n\\par As we saw in the case of pure states, expectation values for experimental outcomes are calculated in a similar fashion. If $\\hat{O}$ is the operator representing the observable quantity, then the expectation value for the operator will be given by\n\\begin{align*}\n\\braket{\\hat{O}} = tr\\{\\hat{O}\\hat{\\rho}\\}\n\\end{align*}\n\\par Similarly, we can calculate the probability of finding the system in a state $\\ket{\\sigma}$ by constructing the projection operator for that state $\\ket{\\sigma} \\bra{\\sigma}$ and applying it to the density operator $\\hat{\\rho}$ representing our system.\n\\begin{align*}\nProb_{\\ket{\\sigma}} = tr\\{ \\ket{\\sigma} \\bra{\\sigma} \\hat{\\rho} \\}\n\\end{align*}\n\n\\subsection{Basic properties of the density operator}\n\\par For a physically realizable state the density operator will always have the properties that\n\\begin{enumerate}\n  \\item It will be Hermitian\n  \\item It will have trace 1:\n  $ tr\\{\\hat{\\rho}\\} = 1 $\n\\end{enumerate}\n\\par There is another additional property that will help us differentiate between density matrices for pure states and mixed states.\n\\begin{itemize}\n  \\item For a pure state, $ tr\\{ \\hat{\\rho}^2 \\} = 1 $\n  \\item For a mixed state, $ tr\\{ \\hat{\\rho}^2 \\} < 1 $\n\\end{itemize}\n\n\\section{Joint State of two Systems}\n\\par So far we have dealt with quantum mechanical states of isolated particles. What will happen if we consider the joint state of more than one such particles? Classical intuition says that the joint state consisting of two subsystems A and B at any time can be completely specified simply by specifying the states of A and B individually. It turns out that this idea does not always work in the domain of quantum mechanics. In quantum mechanics, the joint state of two or more subsystems is specified by their \\textit{tensor product}. Let us take a look at a simple example to get some understanding of tensor products and joint states.\n\\par Suppose we have two atoms whose states are specified by $\\ket{\\psi_A}$ and $\\ket{\\psi_B}$.\n\\begin{align*}\n  \\ket{\\psi_A} = \\begin{pmatrix} a \\\\ b \\end{pmatrix} \\\\\n  \\ket{\\psi_B} = \\begin{pmatrix} c \\\\ d \\end{pmatrix}\n\\end{align*}\nThe joint state for $\\ket{\\psi_A}$ and $\\ket{\\psi_B}$ will be represented by the tensor product\n\\begin{align*}\n  \\ket{\\psi_{AB}} &= \\ket{\\psi_A} \\otimes \\ket{\\psi_B} \\\\\n                &= \\begin{pmatrix} a \\\\ b \\end{pmatrix} \\otimes \\begin{pmatrix} c \\\\ d \\end{pmatrix} \\\\\n                &= \\begin{pmatrix} ac \\\\ ad \\\\ bc \\\\ bd \\end{pmatrix}\n\\end{align*}\nTensor products for higher dimensional vectors are obtained by component-wise multiplication in a similar fashion.\n\\par Let us now take a look at a simple example for joint state of two atoms where atom A is in the ground state $\\ket{0}$ and atom B is in the excited sate $\\ket{1}$. The joint state of both particles will be\n\\begin{align*}\n  \\ket{\\psi_{AB}} &= \\ket{0}_A \\ket{1}_B \\\\\n                  &= \\begin{pmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{pmatrix}\n\\end{align*}\n\\par This suggests a more compact way of writing a joint state of two particles in our extended four-dimensional Hilbert space.\n\\begin{align*}\n  \\ket{\\psi_{AB}} &= ac \\ket{0}_A \\ket{0}_B + ad \\ket{0}_A \\ket{1}_B + bc \\ket{1}_A \\ket{0}_B + bd \\ket{1}_A \\ket{1}_B \n\\end{align*}\nwhere the four basis vectors represent possible combinations of ground and excited states of atoms A and B and the corresponding co-efficients squared are the probabilities of finding that particular combination. For example, $|ad|^2$ is the probability of the state collapsing to atom A in ground state and atom B in excited state. \n\n\\subsection{Operators for Joint States}\n\\par We have seen how joint states of two particles are given by tensor products which extend the systems to a higher dimensional Hilbert space. In our example two particles in their respective two-dimensional Hilbert spaces were extended to a four-dimensional Hilbert space. That means that the operators that work on those states will also be 4x4 matrices in the 4-D Hilbert space.\n\\par Suppose $\\hat{O}_A$ and $\\hat{O}_B$ are different observables acting respectively on the Hilbert space of particle A and particle B. The joint observable will be a tensor product of the two.\n\\begin{align*}\n  \\hat{O}_{AB} &= \\hat{O}_A \\otimes \\hat{O}_B \\\\\n               &= \\begin{pmatrix} a_1 & b_1 \\\\ c_1 & d_1 \\end{pmatrix} \\otimes \\begin{pmatrix} a_2 & b_2 \\\\ c_2 & d_2 \\end{pmatrix} \\\\\n               &= \\begin{pmatrix} \n                    a_1 a_2 & a_1 b_2 & b_1 a_2 & b_1 b_2 \\\\\n                    a_1 c_2 & a_1 d_2 & b_1 c_2 & b_1 d_2 \\\\\n                    c_1 a_2 & c_1 b_2 & d_1 a_2 & d_1 b_2 \\\\\n                    c_1 c_2 & c_1 d_2 & d_1 c_2 & d_1 d_2\n                  \\end{pmatrix}\n\\end{align*}\n\\par As a simple exercise let us construct a projection operator for projecting atom A on its ground state and atom B on its excited state. The isolated projector for A in this case is $\\ket{0} \\bra{0}$ and for B it is $\\ket{1} \\bra{1}$. The joint projector will be a tensor product of the two.\n\\begin{align*}\n  \\ket{0} \\bra{0} \\otimes \\ket{1} \\bra{1} &= \\begin{pmatrix} 1 & 0 \\\\ 0 & 0 \\end{pmatrix} \\otimes \\begin{pmatrix} 0 & 0 \\\\ 0 & 1 \\end{pmatrix} \\\\\n  &= \\begin{pmatrix} 0 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0 \\end{pmatrix}\n\\end{align*}\n\\par We can apply this joint projection operator to a density operator for a joint state in a 4-D Hilbert space and take the trace to find out the probability for the outcome where A is in $\\ket{0}$ and B is in $\\ket{1}$.\n\n\\subsection{Partial Trace and the Reduced Density Operator}\n\\par Just like the example of joining two operators to form a combined operator in the enlarged Hilbert space, we can also take the tensor product of two density operators (or density matrices) to form the combined density operator for two particles A and B.\n\\begin{align*}\n\\hat{\\rho}_{AB} = \\hat{\\rho}_A \\otimes \\hat{\\rho}_B\n\\end{align*}\n\\par But what if we needed to do the inverse? Sometimes we will have a situation where we need to find the density matrix $\\hat{\\rho}_A$ from a combined density matrix $\\hat{\\rho}_{AB}$. The mathematical operation for that is called a partial trace over B and is denoted by\n\\begin{align*}\n\\hat{\\rho}_A = tr_B\\{ \\hat{\\rho}_{AB} \\}\n\\end{align*}\nWe trace out system B and are left with only system A.\n\\par For a 4x4 density matrix, the partial trace over B to get the 2x2 density matrix for A looks like this.\n\\begin{align*}\n\\begin{pmatrix} a & b & c & d \\\\ e & f & g & h \\\\ i & j & k & l \\\\ m & n & o & p \\end{pmatrix}\n\\rightarrow\n\\begin{pmatrix} a+f & c+h \\\\ i+n & k+p \\end{pmatrix}\n\\end{align*}\n\n\\section{Entangled States}\n\\par In the previous section, we saw how we can write the product state of two particles as\n\\begin{align*}\n\\ket{\\psi_{AB}} = ac \\ket{0}_A \\ket{0}_B + ad \\ket{0}_A \\ket{1}_B + bc \\ket{1}_A \\ket{0}_B + bd \\ket{1}_A \\ket{1}_B\n\\end{align*}\nNow let us take a look at an interesting case.\n\\begin{align*}\n  \\ket{\\psi_{AB}} = \\frac{1}{\\sqrt{2}} \\ket{0}_A \\ket{0}_B + \\frac{1}{\\sqrt{2}} \\ket{1}_A \\ket{1}_B \n\\end{align*}\nWhat we have here is a state for which there is an equal probability of both particles being in their ground state or both being in their excited state. Now if we want to figure out the individual states of A and B separately, we hit a stop. We cannot determine the separate states of which this joint state is a product because we cannot determine a, b, c and d from these coefficients. Still this equation does represent a valid physical state because \\textit{any} vector in the Hilbert space is a valid physical state.\n\\par Let us now look at the physical consequences of this situation. One is the obvious consequence that if the atom A is measured and turns out to be in state $\\ket{0}$ then the atom B is also certainly in state $\\ket{0}$, and vice versa.\n\\par But there is another more interesting consequence. The fact that we cannot factorize this state means that we cannot specify a pure state of its constituent components. We cannot \\textit{in principle} know more than what we already have. Which means this certain state itself is a \\textit{pure state}. We cannot have full knowledge of the states of atoms A and B separately.\n\\par This phenomenon of entangled states brings up a very interesting research topic. Being unable to distinguish the subsystems A and B as individual states means that the whole composite system AB acts as a single system. It does not matter if the particles are far away from each other. The composite system still behaves as a single system extended in space. There is no analogue to this phenomenon in classical physics.\n\\subsection{Bell States}\n\\par The particular state discussed earlier in this section is a \\textit{maximally entangled} state of two subsystems - a state for which the amount of entanglement between the subsystems is maximum. This state is part of a set of four maximally entangled (or orthogonal entangled) states called Bell states. The four states are\n\\begin{align*}\n\\ket{\\Phi^+} &= \\frac{1}{\\sqrt{2}} \\left( \\ket{0}_A \\ket{0}_B + \\ket{1}_A \\ket{1}_B \\right) \\\\\n\\ket{\\Phi^-} &= \\frac{1}{\\sqrt{2}} \\left( \\ket{0}_A \\ket{0}_B - \\ket{1}_A \\ket{1}_B \\right) \\\\\n\\ket{\\Psi^+} &= \\frac{1}{\\sqrt{2}} \\left( \\ket{0}_A \\ket{1}_B + \\ket{1}_A \\ket{0}_B \\right) \\\\\n\\ket{\\Psi^-} &= \\frac{1}{\\sqrt{2}} \\left( \\ket{0}_A \\ket{1}_B - \\ket{1}_A \\ket{0}_B \\right)\n\\end{align*}\n\\par Before we study the phenomenon of entanglement in any further detail, we shall need to take a short detour to understand some basic concepts in quantum information theory. After that, we shall return to the topic of entanglement and how we quantify the amount of entanglement contained in a certain system (in other words, quantifying how entangled a particular system is).\n\n", "meta": {"hexsha": "5121c49dc24d80eb949138149d96675200f448ab", "size": 16609, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter-02.tex", "max_stars_repo_name": "saad440/undergrad-project", "max_stars_repo_head_hexsha": "6e4ddf112219c1e884ca2b2657852d54524c282c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-06-13T00:02:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-06-13T00:02:19.000Z", "max_issues_repo_path": "chapters/chapter-02.tex", "max_issues_repo_name": "saad440/undergrad-project", "max_issues_repo_head_hexsha": "6e4ddf112219c1e884ca2b2657852d54524c282c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter-02.tex", "max_forks_repo_name": "saad440/undergrad-project", "max_forks_repo_head_hexsha": "6e4ddf112219c1e884ca2b2657852d54524c282c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 96.0057803468, "max_line_length": 638, "alphanum_fraction": 0.7212956831, "num_tokens": 4655, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.920789673717312, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7440599437808789}}
{"text": "\\section{Introduction}\n\nIn this little write-up I want to calculate the cohomology ring of $G_2(\\mathbb{C}^4$), \ni.e. the Grassmannian manifold consisting of all 2-dimensional subspaces of $\\mathbb{C}^4$. \nTo do this we use the Serre spectral sequence we get from the fibration\n\\begin{center}\n\\begin{tikzcd}\nU(2) \\arrow[r] & V_2(\\mathbb{C}^4) \\arrow[r] & G_2(\\mathbb{C}^4)\n\\end{tikzcd}\n\\end{center}\n\nwhere $V_2(\\mathbb{C}^4)$ is the Stiefel manifold, \ni.e. the collection of 2-frames in $\\mathbb{C}^4$, and $U(2)$ is the unitary group. \nI won't do the calculation of the cohomology rings of $V_2(\\mathbb{C}^4)$ and $U(2)$, \nbut the latter we can easily get from the homeomorphism $U(n) \\simeq U(1)\\times SU(n-1)$, \ngiving in particular $U(2)\\simeq S^1\\times S^3$, and the former can be calculated by induction and the following fibration\n\\begin{center}\n\\begin{tikzcd}\nS^{2(n-k)+1} \\arrow[r] & V_k(\\mathbb{C}^n) \\arrow[r] & V_{k-1}(\\mathbb{C}^n).\n\\end{tikzcd}\n\\end{center}\n\nWe then have \n\\begin{equation*}\n    H^*(V_2(\\mathbb{C}^4)) = \\Lambda(a_5, a_7) \\text{ and } H^*(U(2)) = \\Lambda(a_1, a_3)\n\\end{equation*}\nwhere $a_i$ lies in degree $i$. \n\nFrom the fibration \n\\begin{center}\n    \\begin{tikzcd}\n    U(2) \\arrow[r] & V_2(\\mathbb{C}^4) \\arrow[r] & G_2(\\mathbb{C}^4)\n    \\end{tikzcd}\n\\end{center}\nwe get a spectral sequence $E_r$ which uses the cohomology of $G_2(\\mathbb{C}^4)$ with coefficients from the cohomology of $U(2)$ to calculate the cohomology of $V_2(\\mathbb{C}^4)$. \nSince we now already know the cohomology ring of $V_2(\\mathbb{C}^4)$ we can guess what the cohomology of $G_2(\\mathbb{C}^4)$ has to be in order for the spectral sequence to calculate the correct cohomology ring. \nThis is the approach of this write-up. ", "meta": {"hexsha": "73b04dd4abd74bddcd5720107a33db70cdfd8eaf", "size": 1733, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/introduction.tex", "max_stars_repo_name": "torgeiraamboe/cohomology_ring_of_grassmannian", "max_stars_repo_head_hexsha": "72268ac4af69ed167b52d8e7f1e6b69ed4632623", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/introduction.tex", "max_issues_repo_name": "torgeiraamboe/cohomology_ring_of_grassmannian", "max_issues_repo_head_hexsha": "72268ac4af69ed167b52d8e7f1e6b69ed4632623", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/introduction.tex", "max_forks_repo_name": "torgeiraamboe/cohomology_ring_of_grassmannian", "max_forks_repo_head_hexsha": "72268ac4af69ed167b52d8e7f1e6b69ed4632623", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.8378378378, "max_line_length": 212, "alphanum_fraction": 0.69186382, "num_tokens": 660, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7440599398963851}}
{"text": "\\subsection{Rules and Notation}\n\nDomain is the input space and codomain is the output space.\n\n\\begin{itemize}\n    \\item $T(\\tb{v}+\\tb{w})=T(\\tb{v})+T(\\tb{w})$\n    \\item $T(c\\tb{v})=cT(\\tb{v})$\n\\end{itemize}\n\nThus,\n\n\\[\\boxed{T(c\\tb{v}+d\\tb{w})=cT(\\tb{v})+dT(\\tb{w})}\\]\n\nwhere $c,d\\in \\R$ and $\\tb{v},\\tb{w}\\in \\R^n$.\\newline\n\nNotation given from $\\R^m$ to $\\R^n$:\n\n\\[T:\\; \\R^m\\rightarrow \\R^n.\\]\n\n\\subsection{Nonlinear examples}\n\n\\begin{itemize}\n    \\item $S:\\;R^2\\rightarrow\\R^2$ where $S\\begin{bmatrix}x\\\\y\\end{bmatrix}=\\begin{bmatrix}x^2\\\\y^2\\end{bmatrix}$\n    \\item $f:\\;\\R\\rightarrow\\R$ where $f(x)=mx+b$\n\\end{itemize}\n\nA transformation represented by the product of some matrix $A$ and the column vector input $\\tb{x}$ is always a linear transformation.", "meta": {"hexsha": "1e50dc7e0929601f6582fa425f5ed3f012c1c4ad", "size": 758, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/4_linear-transformations.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "linear-algebra/tex/4_linear-transformations.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "linear-algebra/tex/4_linear-transformations.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0740740741, "max_line_length": 134, "alphanum_fraction": 0.635883905, "num_tokens": 297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.7440317505906532}}
{"text": "%--------------------------------------------------------------------------\n% @file linear_systems.tex\n%\n% @date 09/26/16 09:33:12\n% @author Martin Noblia\n% @email martin.noblia@openmailbox.org\n%\n% @brief\n% Resumen de sistemas lineales.\n% @detail\n%\n% Licence:\n% This program is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or (at\n% your option) any later version.\n% \n% This program is distributed in the hope that it will be useful, but\n% WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n% General Public License for more details.\n% \n% You should have received a copy of the GNU General Public License\n%\n%---------------------------------------------------------------------------\n% begin\n%---------------------------------------------------------------------------\n% Resumen de sistemas lineales\n%---------------------------------------------------------------------------\n\\section{Sistemas Lineales}\n\n\\subsection{Matrices}\nUna matrix $A$ de tamanio $m \\times n$ es un arreglo rectangular de $m \\, n$ numeros\ndispuestos en $m$ filas y $n$ columnas. Por ejemplo:\n$\n\\begin{bmatrix}\n   1 & 0 & 1\\\\\n   0 & 1 & 0 \\\\\n   1 & 3 & 7\n \\end{bmatrix}\n$\nUna matriz generica de tamanio $m \\times n$ la anotamos: $A=(a_{ij})$ de tal manera que \nsu elemento en la fila $i$ columna $j$ es $a_{ij}$. La fila $i$ de $A$ es:\n$\n\\begin{bmatrix}\n   a_{i1} & a_{i2} & a_{i3} & \\cdots & a_{i\\,n}\n \\end{bmatrix}\n$\ny la columna $j$ de $A$ es:\n$\n\\begin{bmatrix}\n   a_{1j} \\\\ a_{2j} \\\\ a_{3j} \\\\ \\vdots \\\\a_{n \\, t}\n \\end{bmatrix}\n$\n\n\n\n\n", "meta": {"hexsha": "0a27c9578333f3675f8959b8771c9b97166440c8", "size": 1731, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algebra/Sections/linear_systems.tex", "max_stars_repo_name": "elsuizo/Cheatsheets", "max_stars_repo_head_hexsha": "73dd9562c8f67d94f6d070b8fb7636280e412866", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algebra/Sections/linear_systems.tex", "max_issues_repo_name": "elsuizo/Cheatsheets", "max_issues_repo_head_hexsha": "73dd9562c8f67d94f6d070b8fb7636280e412866", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algebra/Sections/linear_systems.tex", "max_forks_repo_name": "elsuizo/Cheatsheets", "max_forks_repo_head_hexsha": "73dd9562c8f67d94f6d070b8fb7636280e412866", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.3389830508, "max_line_length": 88, "alphanum_fraction": 0.5626805315, "num_tokens": 481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.7438992478794338}}
{"text": "\\section{The Benchmark: Computation of Shapley Effects} \\label{comp_shap}\n\nThis section introduces Shapley effects for sensitivity analysis. Shapley effects will serve as a benchmark for evaluating the performance of the sensitivity measures derived by the Morris method.\n\n\\subsection{Shapley Values in Economics}\n\nThe Shapley value is a concept from cooperative game theory, introduced by \\citet{S53}. It is a value that informs about how to fairly distribute the profit of a product that was created by a team effort. Fairly here means that any player receives as much of the gain as he or she contributed to the team effort. As individual contributions are not directly observed, \\citet{S53} proposes the following value. The Shapley value ensures that every individual receives at least as much as if he or she had if acted independently \\citep{IP19}.\n\nConsider a game with $k$ players, where $K$ denotes the set of all players, the grand coalition. A coalition is a subset $J \\subset K$. Let $- J$ denote the complement set of $J$, i.e. $- J = K \\setminus{J}$. The corresponding game is defined by a coalition value function that maps each coalition $J$ to the value attained by this coalition, i.e. $val: 2^K \\to \\mathbb{R}_{\\geq 0}$, where $2^K$ denotes the power set of $K$, i.e. the set of all subsets of $K$. It is generally assumed that $val(\\emptyset) = 0$. The following definition is strongly inspired by the one found in \\citet{PRB20}:\n\n\\begin{definition}\n\nGiven a coalition worth function $\\text{val}$, the marginal contribution of player $i$ joining coalition $J$ is $\\text{mar}(J, i)=\\text{val}(J \\cup \\{i\\}) - \\text{val}(J)$. The Shapley value is then defined as\n\\begin{equation*}\n\\begin{split}\n\\phi_{i} (\\text{val})& = \\sum_{J \\mid i \\notin J} \\frac{\\vert J \\vert ! (k - \\vert J \\vert - 1) ! }{ k !} (\\text{val}(J \\cup \\{i\\}) - \\text{val}(J)) \\\\\n& = \\frac{1}{k} \\sum_{J \\mid i \\notin J} \\binom{k-1}{\\vert J \\vert}^{-1} \\text{mar}(J, i).\n\\end{split}\n\\end{equation*}\n\n\\end{definition}\n\nIn other words, we consider every coalition of players and evaluates by how much the inclusion of player $i$ increases the overall profit of the coalition. This is achieved by subtracting the value generated by the members of coalition $J$ from the value created by the larger coalition that includes coalition $J$ and player $i$. In the context of a game, the marginal value for each coalition is divided among all members of this coalition, e.g. if the coalition has one member only, the entire marginal value is gained by this player. We can also interpret the Shapley value as the expected payoff from joining a coalition or from leaving the complementary coalition \\citep{PRB20}.\n\n\\citet{S53} shows that $\\phi_i$ is the only value satisfying all the following four axioms at the same time. Note that Shapley values normalised by total profit are considered.\n\n\\begin{itemize}\n    \\item Pareto efficiency: $\\sum_{i=1}^{k}\\phi_i=1$.\n\t\\item Symmetry: If $val(J \\cup {i})=val(J \\cup {j})\\ \\forall\\ J \\subseteq K \\setminus{\\{i, j\\}}$, then $\\phi_i = \\phi_j$.\n\t\\item Linearity: $\\phi_i(val_1 + val_2)=\\phi_i(val_1)+\\phi_i(val_2)$.\n\t\\item Null-player: If $\\forall J,\\ mar(J, i) = 0$ holds then $\\phi_i(val) = 0$.\n\\end{itemize}\n\nPareto efficiency ensures that nothing of the profit gained by the team is wasted. Normalised by the total profit, the Shapley value gives the share attained by each individual in the game. Symmetry implies that all players who contributed the same to the common product, receive the same payoff, reflecting the meritocratic principle. The null-player axiom ensures that players who do not contribute to the team effort at all do not receive any share of the profits. Especially axioms 1 and 4 are desirable in the context of the Shapley value as a variance-based sensitivity measure, as further discussed in the following subsection.\n\n\\subsection{Variance-based Sensitivity Analysis} \\label{var_based_sa}\n\nThere are several purposes for which we can apply sensitivity methods in general. Note, that in sensitivity analysis we refer to input variables by the term factors \\citep{R21}. In their textbook, \\citet{STC04} summarise the following four possible objectives of sensitivity analysis.\n\nFactors Prioritisation (FP): In the FP setting, we determine on which inputs applied, uncertainty reduction results into the largest reduction in output uncertainty. Sensitivity analysis determines the importance of an input variable. Applied to all inputs, we can derive a ranking of all inputs in order of importance. FP can guide research by prioritising inputs. Inputs are identified for which better experimental measurement can reduce output uncertainty the most, supposing that additional information costs the same for alle inputs.\n\nFactors Fixing (FF): The FF setting allows us to determine the least influential inputs. These can then be fixed at a specific value while losing only a minimum of information in the model output. FF can also be seen as input screening. We would want to fix the least influential inputs to reduce dimensionality of the model and thus the complexity and computational burden.\n\nVariance Cutting (VC): VC informs about which inputs to fix to arrive at a certain desired value of the output variance, under the condition that the smallest number of inputs are fixed. VC is most useful for risk assessment.\n\nFactors Mapping (FM): If we care about the input importance in certain regions of output values only, we can apply FM. First, we classify output values into groups and only then employs the importance exercise. So, the inputs are determined that contribute the most to producing output values in a target region, e.g. we could be interested in a certain percentile of the output range. The term mapping stems from mapping the importance of the inputs to the categories of $Y$.\n\nSensitivity analysis does address more fundamental objectives of mathematical modelling and the analysis of systems that can be achieved directly from the above settings and are summarised in \\citet{R21}. By sensitivity analysis, we can achieve or conduct scientific discovery, i.e. identification of causal relationships, dimensionality reduction, i.e. determination of the least important inputs, which is achieved by FF, data worth assessment, which relates to FP, and decision support \\citep{R21}.\n\nIn global sensitivity analysis, where inputs are probabilistic in nature, we distinguish six classes of sensitivity analysis methods \\citep{BP16}. The sensitivity indices discussed and applied in this work belong or are related to the area of variance-based sensitivity measures. Variance-based sensitivity measures are obtained by determining the expected reduction in output variance due to knowing input $i$ with certainty \\citep{BP16}. These methods are based on the classical formula for the law of total variance\n\\begin{equation*}\nV[Y]= V[E[Y \\mid X_J]] + E[V[Y \\mid X_J]]\n\\end{equation*}\n\n\\noindent assuming that $f(X) < \\infty$, where the $V$ operator stands for the unconditional variance of $Y, V[\\cdot \\mid \\cdot]$ for the conditional variance, and $E[\\cdot \\mid \\cdot]$ denotes the conditional expectation. The above expression decomposes total variance into the explained and the unexplained component \\citep{GM17}.\n\nA variance-based sensitivity measure determines how much output variance is attributable to each input $i$ \\citep{BP16}. Variance-based global sensitivity analysis is not applicable to decision variables, since global sensitivity analysis attaches a distribution to input variables, implying that inputs are uncertain \\citep{SNS16}. Recall that due to this uncertainty in the inputs $X_K$ the output $Y$ is uncertain as well. $V[Y]$ measures this uncertainty in the output, where $V[Y]$ is taken according to the joint distribution of $G_K$. In the variance of the model output, there are three parts of variances; the one caused by every input in isolation, the one that is caused by interaction effects among inputs, and one that is due to input dependence.\n\n\\citet{S93} introduced the popular Sobol' indices. In the case of input dependence, Shapley effects are superior to Sobol' indices \\citep{O14}. Sobol' indices are variance-based sensitivity measures that attribute the variance reduction to each subset $J \\subset K$ using an Analysis of Variance (ANOVA) decomposition. To ensure uniqueness of the ANOVA decomposition employed by \\citet{S53}, we need to assume independence of model inputs \\citep{GM17}. Sobol' indices were introduced as a subset importance measure \\citep{SNS16}. For the purposes of sensitivity analysis, we let the subsets be the single inputs, i.e. the subsets under considerations are singletons. The Sobol' indices are then defined as\n\\begin{align}\nS_i &= V[Y]^{-1} V[E[Y \\mid X_i]] \\label{first_order_sobol}\\\\\nS_i^T &= V[Y]^{-1}(V[Y] - V[E[Y \\mid {X_{- i}}]])\n\\label[equation]{total_sobol}\n\\end{align}\n\n\\noindent where $X_{- i}$ is the subset of input variables without input $i$. What follows does apply to models with independent inputs only. The sensitivity measure $S_i$ is called the first-order sensitivity index. $S_i$ represents the share of output variance reduced by the isolated effect of input $i$, excluding contributions in variance reduction by interactions between input $i$ and the remaining $(K-1)$ inputs. The subtrahend in the nominator of \\cref{total_sobol} can be seen as the expected variance reduction when $X_i$ is fixed at a certain value, i.e. if we know $X_i$ with certainty \\citep{SNS16}. $S_i^T$ is called the total sensitivity index. $S_i^T$ complements $S_i$ in the sense that it measures the total effect of $X_i$ in the output variance, including interaction effects \\citep{SNS16}. It can be considered the expected remaining output variance, when all values of the inputs are known, except for the value attached to $X_i$ \\citep{SNS16}. By normalising both measures by $V[Y]$, it is clear that the values of $S_i$ and $S_i^T$ are in the interval $[0, 1]$, since the numerators in \\cref{first_order_sobol,total_sobol} are always smaller than the total variance \\citep{GM17}. For the relationship between $S_i$ and $S_i^T$ the weak inequality $S_i\\ \\le\\ S_i^T$ holds true, while equality only holds when there are no interaction effects between $X_i$ and $X_{- i}$. Note that the terms indices and effects are used interchangeably.\n\nUnder input independence, the Sobol' indices have a clear interpretation. If $S_i$ is large, then the corresponding input $X_i$ is an influential input with respect to the output variance reduction \\citep{GM17}. In contrast, a small first-order effect $S_i$ does not imply that $X_i$ is an uninfluential input, if strong interaction effects are present \\citep{GM17}. As $S_i^T$ measures the total variance contribution by $X_i$, we can infer from a small $S_i^T$ that $X_i$ is indeed uninfluential \\citep{GM17}. If so, $X_i$ could be fixed at a certain value without causing changes in the model output variance \\citep{GM17}.\n\nEvaluating $S_i$ and $S_i^T$ we can also learn something about the structure of the model we are analysing, always assuming that inputs are independent. The model structure can be determined by the sums $\\sum_{i \\in K} S_i$ and $\\sum_{i \\in K} S_i^T$ \\citep{GM17}. If both sums are equal to one, interaction effects are negligible, since the model is additive in nature. The model is non-additive if $\\sum_{i \\in K} S_i < 1$ and $\\sum_{i \\in K} S_i^T > 1$ \\citep{GM17}. Thus, it can be inferred that interaction effects cannot be ignored and play a role in the system under consideration.\n\nRecall that the statements about the model structure and input importance do not hold if inputs are dependent. In the case of dependence, we cannot simply apply the ANOVA decomposition since it is no longer unique \\citep{O14}. In the Rust model, there are two input variables, $RC$ and $\\theta_{11}$. As one can see in \\cref{model_setup}, there exists significant dependence between the inputs. Thus, Sobol' indices should not be used. Another variance-based sensitivity measure are the now popular Shapley effects, which can be used also in the context of dependence. They are derived in the following section.\n\n\\subsection{Shapley Effects for Sensitivity Analysis}\n\nWhen applied as a sensitivity measure, the interpretation of the Shapley value changes. In the context of sensitivity analysis, \\citet{SNS16} coined the term Shapley effects, which were first suggested as a variance-based sensitivity measure by \\citet{O14}. $X_i$ is now interpreted as a model input instead of a player in a game. A coalition is now a subset of model inputs. \\citet{O14} defines the function $\\widetilde{val}$ as a function that assigns the explanatory power of this subset of inputs to this subset. That is, the function $\\widetilde{val}$ assigns the conditional variance to a subset of inputs, $\\widetilde{val}(J)=V[Y]^{-1}V[E[Y \\mid X_J]]$ and $\\widetilde{val}$ measures the reduction in $V[Y]$ due to the inputs in $J$ \\citep{SNS16}. \\citet{SNS16} show that the following alternative formulation of the value function leads to the same Shapley effect\n\\begin{equation*}\nval(J)=E[V[Y \\mid X_{- J}]].\n\\end{equation*}\n\n\\noindent $val(J)$ can be interpreted as the remaining variance of $Y$, given the values of the inputs in $- J$ are known. Both formulations satisfy the following two requirements\n\\begin{align*}\nval(\\emptyset)& = 0\\\\\nval(K)& = V[Y].\n\\end{align*}\n\n\\noindent In words, the value of the empty input subset should be zero and the value of the set of all inputs should equal the entire output variance. I normalise Shapley effects by $val(K)=V[Y] $ such that they fall inside the unit interval. The most appealing properties of Shapley effects are that they satisfy the following two conditions (compare to axioms 1 and 4).\n\\begin{align*}\n\\sum_{i=1}^{k}\\phi_i& = 1\\\\\n\\phi_i& \\geq 0,\\ \\forall \\ i=1, ..., k.\n\\end{align*}\n\n\\noindent So, the Shapley effects calculated for a model sum up to one and each Shapley effect is non-negative. Hence, the Shapley effects are input importance measures in terms of the expected output variance reduction induced by $X_i$. The non-negativity condition ensures that Shapley effects are always clearly interpretable. Note that due to the uncertainty in the computation process Shapley effects might be smaller than zero. Increasing the sample sizes mitigates this problem.\n\nShapley effects can be used to compare input importance, that is, inputs can be ranked according to their contribution to output variance reduction. Furthermore, the differences between values of Shapley effects can be interpreted.\n\nRecall the three parts of model output variance as discussed in \\cref{var_based_sa}: variance due to the isolated effect of an input (i.e. the main variance), due to interaction effects, and due to dependence among inputs. Shapley effects take all three into account. In this regard they differ from first-order and total Sobol' indices as defined in \\cref{var_based_sa} \\citep{O14}.\n\nIn comparison to Shapley effects we have to acknowledge that Sobol' indices can inform about the model structure as discussed in \\cref{var_based_sa}. In addition, Sobol' indices address more sensitivity analysis settings than Shapley effects, if inputs are independent. Shapley effects can be applied to FF only, since they distribute the effect of interactions between inputs equally across all inputs contained in the current subset \\citep{IP19}. FP cannot be precisely conducted by using Shapley effects, since we cannot distinguish between contributions of main variance and variance contributions due to interactions \\citep{IP19}.\n\nShapley effects yield a single value for each input that serves as the sensitivity measure, as opposed to Sobol' indices, which yield the first-order and total effects., i.e. two measures per input. Especially when computing sensitivity indices for studies that evaluate scientific phenomena, having a single value per input that informs about the variance contribution is very useful \\citep{SNS16}. Furthermore, when this measure considers main and interaction effects and can also handle input dependence, we have a very useful and versatile sensitivity measure.\n\nSobol' indices for dependent inputs have been proposed \\citep{MTA15}. This strategy is based on the estimation of four sensitivity indices, instead of the two measures in the case of input independence, elevating the practical usefulness of Shapley effects even more. In case of input dependence, Sobol' indices require a complicated ANOVA decomposition, whereas Shapley effects do not rely on such variance decompositions \\citep{IP19}. When applying Shapley effects, we would not even need to know whether input dependence or independence prevails.\n\n\\subsection{Algorithm for Shapley Effects} \\label{comp_alg}\n\n\\begin{figure}[t]\n\t\\caption{Uncertainty in Shapley Effects - $100$ Replicates}\n    \\label{boxplot_shapley}\n\t\\begin{centering}\n\t\\vspace*{-4mm}\n\t\\begin{centering}\n\t\\includegraphics[scale=0.9]{../figures/boxplot_shapley_effects_100.png}\n\n\t\\end{centering}\n\t\\end{centering}\n\n\t\\small\n\t\\textit{Notes:} Boxplots for 100 estimated Shapley effects for the inputs $RC$ and $\\theta_{11}$ using the same number of Monte Carlo samples: $N_V=100$, $N_O=10$, and $N_I=3$.\n\\end{figure}\n\nThe algorithm for the computation of Shapley effects needs to allow for conditional sampling of dependent inputs. Otherwise, some of the advantages of Shapley effects cannot be exploited. I use Algorithm 1 from \\citet{SNS16}.\\footnote{An alternative algorithm has been recently proposed by \\citet{PRB20} which uses mathematically more advanced concepts.}\n\nShapley effects consider all input subsets. To iterate over all subsets, \\citet{SNS16} restate the equation for Shapley effects to iterate over all permutations of model inputs. For instance, let $k=5$. Then, $K=\\{1,\\ 2,\\ 3,\\ 4,\\ 5\\}$. There exist $5!$ permutations, where one example is $\\pi'=(2,\\ 4,\\ 3,\\ 5,\\ 1)$. Let the set of all permutations of $K$ be denoted by $\\Pi(K)$. Further, let $P_i(\\pi)$ denote all inputs in permutation $\\pi$, that come before input $i$. In the above example, if $i=3$, then $P_3(\\pi')=\\{2,\\ 4\\}$. Using the permutation representation, \\citet{SNS16} state the marginal contribution due to input $i$ as $val(P_i(\\pi) \\cup\\{i\\}) - val(P_i(\\pi))$. By considering all permutations of $K$, we can restate the equation for the Shapley effects for input $i$ as\n\\begin{equation*}\n\\phi_i=\\sum_{\\pi \\in \\Pi(K)} (k!)^{-1} (val(P_i(\\pi) \\cup\\{i\\}) - val(P_i(\\pi))).\n\\end{equation*}\n\nThe algorithm of \\citet{SNS16} exploits the fact that their permutation-based algorithm evades redundant model evaluations by going through the permutations beginning with the smallest subset. The contribution of the preceding subset is subtracted from the contribution of the current subset. The marginal contribution is then computed by writing\n\\begin{equation*}\nval(P_{\\pi(j)}(\\pi) \\cup \\{\\pi(j)\\}) - val(P_{\\pi(j)}(\\pi)),\n\\end{equation*}\n\n\\begin{table}[t]\n\t\\centering\n\t\\caption{Descriptive Statistics Shapley Effects - $100$ Replicates}\n\t\\label{shapley_descriptives}\n\t\\begin{threeparttable}\n\t\\centering\n\t\\input{../figures/descriptives_shapley_replicates_100.tex}\n\t\\begin{tablenotes}\n\t\\small\n\t\\item \\textit{Notes:} Descriptive statistics for $100$ replicates of the Shapley effects. 95-percent confidence intervals are reported.\n\t\\end{tablenotes}\n\t\\end{threeparttable}\n\\end{table}\n\n\\noindent where $\\pi(j)$ denotes the input at position $j$ in permutation $\\pi$. In the above permutation $\\pi'$, at position 2 we have input 4, i.e. $\\pi'(2)=4$.\n\nTo see for which subsets the algorithm performs evaluations of $val$, consider the below example. For instance, following \\citet{SNS16}, if $k=3$ and $\\pi=(1, 3, 2)$, the algorithm computes\n\\begin{align*}\n\\Delta_1 &=val(\\{1\\})-val(\\emptyset),\\ set\\ prevC=0, \\\\\n\\Delta_2 &=val(\\{1,\\ 3\\})-prevC,\\ set\\ prevC=val(\\{1,\\ 3\\}), \\\\\n\\Delta_3 &=val(\\{1,\\ 3,\\ 2\\})-prevC,\\ set\\ prevC=val(\\{1,\\ 3,\\ 2\\}).\n\\end{align*}\n\nThe algorithm implements three Monte Carlo simulations. There are $N_V$ Monte Carlo samples of model inputs which are evaluated to get an estimate of $V[Y]$. Since the algorithm needs to handle dependent inputs, \\citet{SNS16} implement dependent sampling by an inner and an outer Monte Carlo simulation. To see why both Monte Carlo simulations are needed, fix a permutation $\\pi$. Then, sample $N_O$ outer samples, that are unconditionally drawn. Given this set of unconditionally drawn outer samples, draw $N_I$ inner samples conditionally on the outer samples. That is, for each outer sample, we have $N_I$ inner samples. Thus, the computational cost in terms of number of model evaluations is given by $N_V+m \\cdot N_I \\cdot N_O \\cdot (k-1)$, where $m$ is the number of permutations considered. In the exact setting of the algorithm, $m=\\vert \\Pi(K) \\vert=k!$. If only a random subset of permutations should be considered, we set $m<k!$, which can be useful to reduce the computational burden if the number of inputs is large.\n\n\\subsection{Shapley Effects for the Rust Model} \\label{shapley_rust_model}\n\nI apply three different computational setups. I do so to, firstly, evaluate the performance of Shapley effects and, secondly, get the correct input ranking according to the sensitivity for the Rust model. When working with the algorithm presented by \\citet{SNS16} in practice, it can be challenging to specify the sample sizes $N_O$ and $N_V$, since no guidance on how to allocate the computational budget to $N_V$ and $N_O$ is given.\n\nThe general computational setup applies to all three simulation studies. \\citet{SNS16} recommend setting $m=\\vert \\Pi(K) \\vert$, if computationally feasible. In order to reduce variance of the estimates of Shapley effects, they further recommend choosing $N_I=3$, while setting $N_O$ as large as possible, given the constraints on the computational budget. Since the Rust model has two inputs only, the number of permutations to be considered is two and thus very small. Hence, I set $m=2!=2$ and $N_I=3$. I run the estimation by using the implementation of the algorithm by the package \\textit{econsa}, a Python package for sensitivity analysis \\citep{OSE21}.\n\n% Shapley replicates.\n\n\\begin{figure}[t]\n\t\\caption{Convergence of Shapley Effects for the Rust Model}\n    \\label{shapley_convergence}\n\t\\begin{centering}\n\t\\vspace*{-4mm}\n\t\\begin{centering}\n\t\\includegraphics[scale=0.9]{../figures/convergence_shapley_effects_8.png}\n\t\\end{centering}\n\t\\end{centering}\n\n\t\\small\n\t\\textit{Notes:} Shapley effects estimated for different values of $N_O$, while setting $N_V=10\\,000$ and $N_I=3$.\n\\end{figure}\n\nFirstly, I estimate 100 Shapley effects for the inputs of the Rust model, $RC$ and $\\theta_{11}$ using the same general setup as described in the preceding paragraph. I further set $N_V=100$ and $N_O=10$. Thus, the computational cost of my choice of Monte Carlo runs imply that 160 model evaluations are needed to estimate the Shapley effects. On my machine (Windows 10, i5 processor), one estimation run takes approximately 40 seconds.\n\nThe distribution of the 100 replicates is visualised by the boxplots in \\cref{boxplot_shapley}. For further details on the estimated replicates, see \\cref{shapley_descriptives}. The mean of $\\phi_{RC}$ is $0.4163$ and for $\\phi_{\\theta_{11}}$ the mean value is $0.5837$. Shapley effects are estimated with a standard error of 0.0043.\nBoth, the boxplots, and the mean values show that $\\theta_{11}$ is the more important input in terms of contributions to output variance. The confidence intervals at the 95-percent level, are quite large, but they do not overlap, indicating that the implied input importance ranking is robust. The lower value of $\\phi_{RC}$ shows that $RC$ has less an impact on the output variance than $\\theta_{11}$.\n\n% True Shapley\n\nSecondly, I estimate one set of Shapley effects for a large sample size. I chose to consider $N_V=100\\,000$ and $N_O=10\\,000$, which amount to a computational cost of $160\\,000$ model evaluations. The resulting sensitivity measures are $\\phi_{RC} = 0.4176$ and $\\phi_{\\theta_{11}} = 0.5823$. I refer to this set of sensitivity measures as the \\textit{true} Shapley effects.\n\n% Shapley Convergence\n\nThirdly, I estimate eight Shapley effects for different sample sizes to illustrate their behaviour as $N_O$ increases. For all the estimations I fix $N_V$ at $12\\,500$, varying $N_O$ only. I consider $N_O \\in \\{200,\\ 500,\\ 800,\\ 1\\,000,\\ 2\\,000,\\ 3\\,000,\\ 4\\,000,\\ 6\\,000 \\}$. The total computational cost for one estimation is thus given by $10\\,000 + 6 \\cdot N_O$, e.g. for $N_O=200$, the total computational cost amounts to $11\\,200$ and for $N_O=6\\,000$, the total computational cost amounts to $46\\,000$ model evaluations. Results are visualised in \\cref{shapley_convergence}. For each chosen value of $N_O$ there is a clear input ranking, indicating that $\\theta_{11}$ is the more important input. Shapley effects are still relatively volatile, even for larger sample sizes. Details on the relative difference between estimates are shown in \\cref{rel_diff_shapley}. \\Cref{rel_diff_shapley} shows the percentage change in estimates given by $\\frac{\\phi_i^{n_o-1} - \\phi_i^{n_o}}{\\phi_i^{n_o}}$, for $i \\in \\{RC,\\ \\theta_{11}\\}$ and $n_o$ denoting the different values of $N_O$ considered. % Relative differences do not steadily decline.\n\n% Interpretation\n\nTo sum up, the input rankings are always the same: $\\theta_{11}$ is the more important input for the Rust model. This holds true for all the estimations of Shapley effects presented above. Since both $\\phi_i$ are far from zero, it is not recommended to fix any one of them, since both influence the output variance significantly. Otherwise we would assume an input to be deterministic which is subject to large uncertainty and has simultaneously a large influence on the model output.\n\n\\begin{table}[t]\n\t\\centering\n\t\\caption{Relative Difference Shapley Effects}\n\t\\label{rel_diff_shapley}\n\t\\begin{threeparttable}\n\t\\centering\n\t% \\hline\n\t\\input{../figures/shapley_convergence_relative_difference_8.tex}\n\t\\begin{tablenotes}\n\t\\small\n\t\\item \\textit{Notes:} The percentage difference between Shapley effects for different values of $N_O$ while keeping $N_V$ fixed at $12\\,500$ and $N_I$ at $3$. Percentage changes are calculated by $\\frac{\\phi_i^{n_o-1} - \\phi_i^{n_o}}{\\phi_i^{n_o}}$, for $i \\in \\{RC,\\ \\theta_{11}\\}$ and $n_o$ denoting the different values of $N_O$.\n\t\\end{tablenotes}\n\t\\end{threeparttable}\n\\end{table}", "meta": {"hexsha": "b63e1fd7e1659173a356ac46df944c50c528bf8b", "size": 26524, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/shapley_effects.tex", "max_stars_repo_name": "bhmueller/thesis", "max_stars_repo_head_hexsha": "3bb9a55b356eee4aee65d0e035731809db57acc6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/shapley_effects.tex", "max_issues_repo_name": "bhmueller/thesis", "max_issues_repo_head_hexsha": "3bb9a55b356eee4aee65d0e035731809db57acc6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/shapley_effects.tex", "max_forks_repo_name": "bhmueller/thesis", "max_forks_repo_head_hexsha": "3bb9a55b356eee4aee65d0e035731809db57acc6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 125.7061611374, "max_line_length": 1461, "alphanum_fraction": 0.7687000452, "num_tokens": 6782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.8633916134888614, "lm_q1q2_score": 0.7438448677924295}}
{"text": "\\documentclass{article}\n\n\\usepackage{mathrsfs,amssymb,amsmath}\n\n\\begin{document}\n\n\\section{If $\\mathscr{A}$ is a Banach algebra with identity and $a \\in \\mathscr{A}$ and is nilpotent (that is, $a^n=0$ for some $n$), then $\\sigma(a) = \\{0\\}$}\n\nFirstly, assume $a$ is invertible. Then \n\n\\begin{align*}\n    a^n &= 0 \\\\\n    (a^{-1})^n a^n &= (a^{-1})^n 0 \\\\\n    1 &= 0\n\\end{align*}\n\na contradiction, so $0 \\in \\sigma(a)$.\n\nNext, we need to show that $a-\\alpha$ for any $\\alpha \\in \\mathbb{C}$ is invertible.\n\nIf $1 + a + a^2 ...$ converges, it will converge to $1 / (1-a)$ by the geometric series. Since $a^n=0$, all terms $\\ge n$ vanish, hence the series converges, and $1/(1-a) \\in \\mathscr{A}$\n\nSince $\\mathscr{A}$ is closed under multiplication, it also contains $1/(a-1)$, hence $a-1$ is invertible, so $1 \\not \\in \\sigma(a)$. \n\nTODO: Extend to the other $\\alpha \\in \\mathbb{C} \\setminus 0 $ (maybe some simple algebra trick?)\n\n\n\\end{document}\n", "meta": {"hexsha": "daa338651ee10280ea8657eda305d25dd7d96ff1", "size": 945, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "analysis/7_Banach_Algebras/3_The_Spectrum.tex", "max_stars_repo_name": "lukemassa/math-exercises", "max_stars_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "analysis/7_Banach_Algebras/3_The_Spectrum.tex", "max_issues_repo_name": "lukemassa/math-exercises", "max_issues_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "analysis/7_Banach_Algebras/3_The_Spectrum.tex", "max_forks_repo_name": "lukemassa/math-exercises", "max_forks_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.5862068966, "max_line_length": 187, "alphanum_fraction": 0.6349206349, "num_tokens": 337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8633916134888613, "lm_q1q2_score": 0.7438448585840399}}
{"text": "\\chapter{Theory behind SVD}\n\\label{cha:svd-theory}\n\nLet us begin by giving the formal definition of the SVD factorization,\nwhich is in indeed a theorem (we will restrict ourselves to real\nmatrices, that is, to matrices whose entries belong to the field\n\\R{}). \\\\\n\n\\begin{theorem}[Singular Value Decomposition]\n\\label{thm:SVD}\nLet $A$ be a real matrix of $n \\times m$ \\imply $\\exists$ orthogonal matrices\n$V$ ($n \\times $n) and $U$  ($m \\times m$), and diagonal matrix\n$\\Sigma$ ($m \\times n$) \\suchthat:\n\n\\[\nA = U \\Sigma \\trans{V} \n\\]\n\\\\\nwhere $\\Sigma$ has the following properties: \n\\begin{align*}\n & \\Sigma =  diag(\\sigma_1,\\dots,\\sigma_p), & \\textds{for} p = min(n,m)  \\\\\n & \\sigma_1 \\ge \\sigma_2 \\ge \\dots \\ge \\sigma_r > 0, & \\textds{for} r = rank(A) \\\\\n & \\sigma_{r+1} = \\sigma_{r+2} = \\dots = \\sigma_p = 0 &\n\\end{align*}\n\\end{theorem}\n\\hfill\n\nNote that in the \\cref{thm:SVD}, we are considering diagonal\nmatrices on its more generic form that does not require them to be\nsquare; the definition of diagonal matrix $M$ can simply be that any\nelement other than $M_{ii}$ becomes zero. \\\\\n\nBefore presenting the proofs, is convenient to provide more context\nabout the theory behind this matrix factorization (and probably also,\npart of the motivation behind). \\\\\n\n\\input{svd-intuit.tex}\n\n\\section{The SVD proofs}\nThe rest of this chapter provides more theoretical background about\nthe SVD decomposition, in particular, it provides two different proofs of\n\\cref{thm:SVD}:\n\n\\begin{itemize}\n  \\item Algebraic proof using the Spectral Theorem.\n  \\item Geometric proof (implicitly using Compactness).\n\\end{itemize}\n\\hfill\n\nEach one of those proofs is intended to bring a\ndifferent perspective, about such an important result as SVD is. The\nlist is not exhaustive of course, there could be many more ways of \nproving it; but hopefully the short list presented here, will give the\nreader an idea about the rich theory behind this decomposition. \\\\\n\nAs with any mathematical theorem, proving is done based on previous\nresults; since this is not a text book, we can not afford the luxury\nof proving every auxiliary theorem we use. However, we made an effort\nfor at least mentioning explicitly the theorems; pointing to\nreferences, when possible, about their respective proofs. For some few\ncases (like the Spectral Theorem), we did include the proof of the\nauxiliary theorem as well.\n\n\\input{svd-proof-spec.tex}\n\\input{svd-proof-geo.tex}\n\n", "meta": {"hexsha": "070f86a2fdf599971242795cb153dc8e59cd24f7", "size": 2431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-theory.tex", "max_stars_repo_name": "rzavalet/svd-lsi-project-master", "max_stars_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "svd-theory.tex", "max_issues_repo_name": "rzavalet/svd-lsi-project-master", "max_issues_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "svd-theory.tex", "max_forks_repo_name": "rzavalet/svd-lsi-project-master", "max_forks_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.2835820896, "max_line_length": 82, "alphanum_fraction": 0.743315508, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.8354835289107309, "lm_q1q2_score": 0.7438261715370001}}
{"text": "\\section{Dimensional Analysis}\r\n\\subsection{Basic Dimensional Quantities and Units}\r\nFor most motions we will be considering, there are basically three dimensions of interests: length ($L$), mass ($M$) and time ($T$).\r\nIn general, the dimension of a physical quantity $X$ can be expressed using thsese three dimensions.\r\nFor example, the density can be expressed by $ML^{-3}$, and the force can be expressed by $MLT^{-2}$.\r\nWe are only going to consider the product of powers of the dimensional quantities.\r\nWe can then introduce units for the basic dimensional quantities.\r\nMost likely we will use the SI unit system ($L=$m, $M=$kg, $T=$s).\r\nFor other quantities, we can form units out of the basic units we defined for the basic quantities.\r\n\\begin{example}\r\n    To find the unit of the constant $G$ in Newton's Law of Gravitation, we can determine by writing each quantity in basic quantities, so we have $G=L^3T^{-2}M^{-1}$, therefore the unit for $G$ will be ${\\rm m^3s^{-2}kg^{-1}}$.\r\n\\end{example}\r\nThe general principle is that dynamical or physical equations must work for any chosen system of units.\r\n\\subsection{Scaling}\r\nSuppose I have a dimensional quantity $Y$ which depends on some other quantities $X_1,X_2,\\ldots,X_n$.\r\nLet the diensions of the quantity $Y$ be $L^aM^bT^c$, and $X_i$ has dimensions $L^{a_i}M^{b_i}T^{c_i}$.\r\nWe want to determine the dimensions of $Y$ from that of $X_i$.\r\nSo obviously we have $Y=C\\prod_i X_i^{p_i}$, so\r\n$$\\begin{cases}\r\n    a=\\sum_ip_ia_i\\\\\r\n    b=\\sum_ip_ib_i\\\\\r\n    c=\\sum_ip_ic_i\r\n\\end{cases}$$\r\nIf $n=3$, then there is an unique solution iff $X_1,X_2,X_3$ are independent, so\r\n$$\\begin{vmatrix}\r\n    a_1&a_2&a_3\\\\\r\n    b_1&b_2&b_3\\\\\r\n    c_1&c_2&c_3\r\n\\end{vmatrix}\\neq 0$$\r\nwhich happens most of the time.\r\nNote that for general $n$ there must be a solution (not necessarily unique) if we assume that $Y$ does indeed depend on a subset of $\\{X_i\\}$.\r\nSo for $n<3$, there is an unique solution as well.\\\\\r\nFor $n>3$, however, we can choose $n-3$ dimensionless constants\r\n$$\\lambda_i=X_i/(X_1^{p_{i1}}X_2^{p_{i2}}X_3^{p_{i3}})$$\r\nwhere $i=4,5,\\ldots$, assuming $X_1,X_2,X_3$ are independent.\r\nSo\r\n$$Y=C(\\lambda_4.\\lambda_5,\\ldots)X_1^{p_1}X_2^{p_2}X_3^{p_3}$$\r\nwhere $C$ is a dimensionless function.\r\nThis is sometimes known as Bridgemzn's Theorem.\r\n\\begin{example}\r\n    Consider a simple pendulum.\r\n    Let $d$ be the horizontal initial displacement, $m$ the mass, and $g$ the acceleration due to gravity, and $l$ the length of the string, and we want to find expression of the period $P$ in term of these.\r\n    Speaking of dimensions,\r\n    $$\\begin{cases}\r\n        [P]=T\\\\\r\n        [d,l]=L\\\\\r\n        [g]=LT^{-2}\\\\\r\n        [m]=M\r\n    \\end{cases}$$\r\n    Thus\r\n    $$T=M^{p_1}L^{p_2}(LT^{-2})^{p_3}$$\r\n    solve to get $p_1=0,p_2=1/2,p_3=-1/2$\r\n    Hence\r\n    $$P=C\\left( \\frac{d}{l} \\right)\\sqrt{\\frac{l}{g}}$$\r\n    For a dimensionless function $C$.\\\\\r\n    Hence, if we scale $d,l$ by $2$, the period will be scaled by $\\sqrt{2}$.\r\n    Also $P$ is independent of $m$.\r\n\\end{example}\r\n\\begin{example}\r\n    Taylor's estimate to the first atomic explosion.\\\\\r\n    We want to estimate the radius of the fireball $R$ which has dimension $L$.\r\n    $R$ depends on the time $t$ since the explosion which has dimension $T$.\r\n    The density of air $\\rho_0$ which has dimension $ML^{-3}$ is also involved.\r\n    Lastly the energy of explosion $E$ having dimension $ML^2T^{-2}$.\\\\\r\n    So by doing dimensional analysis, we immediately (since there are only $3$ depending dimensions) have $R\\propto \\sqrt[5]{Et^2/\\rho_0}$.\r\n    This has allowed Taylor to estimate the size of $E$.\r\n\\end{example}", "meta": {"hexsha": "d15b873533891d40c0695d08016cac25238d5aa0", "size": 3638, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/dim.tex", "max_stars_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_stars_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2/dim.tex", "max_issues_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_issues_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2/dim.tex", "max_forks_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_forks_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.2985074627, "max_line_length": 229, "alphanum_fraction": 0.6767454645, "num_tokens": 1143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.7438017860813557}}
{"text": "\\section{Probability distributions}\n\n\\subsection{Normal}\n\nBy contrast with substantial majority of books, the univariate normal distribution\ncan be derived form the multivariate normal distribution.\nIn this section we show how to obtain the univariate normal from the bivariate.\n\n\\begin{marginfigure}\n  \\includegraphics[width=\\linewidth]{figures/04_normal.pdf}\n  \\caption{Black dots represent the gas molecules.\n  The red dot stands for the one we catch.\n  Its speed along the horizontal axis is $v_1$, i.e., the first component of\n  the velocity vector, and its speed along the vertical axis is $v_2$.}\n\\end{marginfigure}\n\nThe original idea belongs to J.C. Maxwell who was wondering\nwhat distribution the velocity of gas molecules follow.\nThe similar question was also bothering J.H.W. Herschel who was an astronomer\nand was dealing with measurement errors in astronomical data.\nHere we provide a proof of the theorem known today as Herschel-Maxwell's.\n\nAssume there are gas molecules moving chaotically on a plane\nand we can measure the velocity vector of one of them.\nWe will denote this vector as $V = \\begin{pmatrix} X \\\\ Y \\end{pmatrix}$\nwhere $X$ and $Y$ stand for the horizontal and vertical components respectively.\nAssume additionally that\n\\begin{enumerate}\n  \\item The joint distribution finction $f(x,y)$ does not depend on\n  the vector $(X,Y)^T$ direction but depends on its length only;\n  \\item The orthogonal components of the velocity vector are independent;\n  \\item And we measure the velocity in such a way that $\\Var(X) = 1$.\n\\end{enumerate}\n\n\\marginnote{\nIt is more common to introduce a standard normal distribution in terms of its PDF\n\\begin{definition}\nA continuous random variable $\\xi$ has a standard normal distribution\nif its PMF is given by\n\\[\nf_{\\xi} (x) = \\frac{1}{\\sqrt{2\\pi}}\\exp\\left(-\\frac{x^2}{2}\\right).\n\\]\n\\end{definition}\nAfter that multivariate normal is defined.\n\n\\begin{definition}\nLet $\\xi_i \\stackrel{iid}{\\sim} \\mathcal{N}(0, 1)$ then $\\xi \\sim \\mathcal{N}(\\vec{0}, I)$\nwhere $\\xi = \\begin{pmatrix} \\xi_1 \\\\ \\vdots \\\\ \\xi_n \\end{pmatrix}$,\n$I$ is $n \\times n$ identity matrix, and its PMF is\n\\[\nf_{\\xi} (x_1, \\ldots, x_n) = \\frac{1}{(\\sqrt{2\\pi})^n}\\exp\\left(-\\frac{x_1^2+\\ldots+x_n^2}{2}\\right).\n\\]\n\\end{definition}\nAnd finally, location-scale transformations are applied.\n}\n\n\\begin{theorem}\nAssumptions (1), (2) and (3) are satisfied if and only if\n$X \\sim \\mathcal{N}(0, 1)$, $Y \\sim \\mathcal{N}(0, 1)$\nand $X$, $Y$ are independent.\n\\end{theorem}\n\n\\begin{proof}\nFirst of all, consider a vector $V' = \\begin{pmatrix} -Y \\\\ X \\end{pmatrix}$, i.e.,\nthe original vector $V$ rotated $90^{\\circ}$ counterclock-wise.\nBy the assumption (1), this operation did not change the distribution of $V$.\nHence, $V' \\sim V$ which implies $-Y \\sim X$ and $X \\sim Y$.\nIt follows that\n\\[\n\\begin{cases}\n\\E(-Y) = \\E(X) \\\\\n\\E(X) = \\E(Y)\n\\end{cases}\n\\]\nwhich holds for $\\E(X) = \\E(Y) = 0$ only.\nOne may notice that $\\E(X)$ may not exist at all,\nbut we derive later the exact distribution of $X$.\n\nLikewise, $\\Var(X) = \\Var(Y)$ and it follows from the assumption (3)\nthat $\\Var(X) = \\Var(Y) = 1$.\n\nNext, we introduce the angle between $V$ and the horizontal axis $U$ and\nthe length of the velocity vector $R = \\sqrt{X^2 + Y^2}$.\nObviously, $X = R \\cos U$ and $Y = R \\sin U$.\nNote that since the joint distribution of $X$ and $Y$ depends only on\nthe length of vector $V$ the distribution function of $U$ can only be constant,\nthus variable $U$ is uniform on the interval $(0, 2\\pi)$.\n\nApplying assumption (1) again, we conclude that the joint distribution function\ncan be written as a function of the length of the velocity vector, or equivalently\nof the length squared:\n\\[\nf(x,y) = h(x^2 + y^2).\n\\]\nBy the assumption (2), orthogonal components of $V$ are independent.\nHence, the joint PMF can be decomposed to the product of marginal ones:\n\\[\nf(x,y) = f(x)f(y) = g(x^2)g(y^2)\n\\]\nwhere the latter equality was written for convenience.\nPutting everything together, we obtain\n\\[\nh(x^2 + y^2) = g(x^2)g(y^2).\n\\]\nNext, we take the derivative of both sides with respect to $y^2$ and\nthen substitute $y^2 = 0$ to get a constant $k$:\n\\begin{align*}\nh'(x^2 + y^2) &= g(x^2)g'(y^2) \\\\\nh'(x^2) &= g(x^2)g'(0) \\\\\nh'(x^2) &= k \\cdot g(x^2)\n\\end{align*}\n\n\\marginnote{\nIn order to obtain $k$ we computed\n\\begin{align*}\n\\E(X^2) &= \\int_{-\\infty}^{\\infty} x^2 \\sqrt{c} e^{kx^2} dx \\\\\n&= \\left. x \\cdot \\sqrt{c} e^{kx^2} \\cdot \\frac{k}{2} \\right|_{-\\infty}^{\\infty} - \\int_{-\\infty}^{\\infty} \\sqrt{c} e^{kx^2} \\cdot \\frac{1}{2k} dx \\\\\n&= - \\frac{1}{2k} \\int_{-\\infty}^{\\infty} \\sqrt{c} e^{kx^2} \\\\\n&= - \\frac{1}{2k} \\cdot 1 \\\\\n&= 1.\n\\end{align*}\n}\n\nSolving the differential equation, we obtain\n\\[\nh(x^2) = c e^{kx^2}, \\quad c \\in \\mathbb{R}.\n\\]\nSo the joint PMF can be written as follows:\n\\[\nf(x,y) = h(x^2 + y^2) = c e^{k(x^2+y^2)}\n\\]\nand due to independece of $X$ and $Y$ the PMF of $X$ is\n\\[\nf(x) = \\sqrt{c} e^{kx^2}.\n\\]\n\n\\marginnote{\nIn order to obtain $c$ we computed:\n\\begin{align*}\n\\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} e^{-\\frac{x^2 + y^2}{2}} dx dy &= \\int_{0}^{2\\pi} \\int_{0}^{\\infty} e^{-\\frac{r^2}{2}}r dr d\\theta \\\\\n&= \\int_{0}^{2\\pi} \\left(\\int_{0}^{\\infty} e^{-u} du \\right) d\\theta \\\\\n&= \\int_{0}^{2\\pi} 1 d\\theta \\\\\n&= 2 \\pi.\n\\end{align*}\n}\n\nIn order to find the constant $k$, we need to solve $\\E(X^2) = 1$.\nComputing the integral we obtain $k=-\\frac{1}{2}$.\n\nFinally, we need to normalize $f(x, y) = c e^{-\\frac{x^2 + y^2}{2}}$ so as to\nobtain $c$. Again, computing another integral,\nwe conclude that $c=(2\\pi)^{-1}$ which finishes the proof.\n\nWithout assumption (3) variables $X$ and $Y$ are normal $\\mathcal{N}(0, \\sigma^2)$.\n\\end{proof}\n\nNotice, that any other $\\mathcal{N}(\\mu, \\sigma^2)$ can be obtained by applying\nlocation-scale transformations.\n\nThe theorem can be generalized to the $n$-dimensional case.\n\\begin{theorem}\\label{th:mvn}\nThe vector $z = \\begin{pmatrix} z_1 \\\\ \\vdots \\\\ z_n \\end{pmatrix}$\nfollows the standard multivariate normal distribution and its components\nare independent if and only if\n\\begin{enumerate}\n  \\item the function $f(z)$ depends on $\\lVert z \\rVert$ only,\n  \\item the projections of vector $z$ onto the orthogonal subspaces $A$ and $B$\n  in $\\mathbb{R}^n$ are independent.\n\\end{enumerate}\n\\end{theorem}\n\n\n\\subsection{Chi-squared}\n\n\\marginnote{\n\\begin{definition}\\label{def:chi_traditional}\nLet $z_i \\stackrel{iid}{\\sim} \\mathcal{N}(0,1)$.\nThen $Q$ follows the chi-squared distribution with $k$ degrees of freedom\nif it can be written as\n\\[\nQ = z_1^2 + z_2^2 + \\ldots + z_k^2.\n\\]\n\\end{definition}\n\nThis definition is a particular case of the geometric one.\nConsider projecting a vector $z = (z_1, z_2, \\ldots, z_n)$ form $\\mathbb{R}^n$\nonto the~$k$-dimensional subspace $S$ of vectors which first $k$ coordinates\nare arbitrary and all the rest are zeros. As a result we would get\n\\[\n\\hat z = (z_1, z_2, \\ldots, z_k, 0, \\ldots, 0).\n\\]\nSquaring the length of the projection, we obtain\n\\[\nQ = \\lVert \\hat z \\rVert = z_1^2 + z_2^2 + \\ldots + z_k^2.\n\\]\n}\n\n\\begin{definition}\\label{th:chi}\nConsider a random vector $z \\in \\mathbb{R}^n$ which components are independent\nand follow standard normal distribution, $z_i \\sim \\mathcal{N}(0,1)$.\nConsider also a $k$-dimensional subspace $L$ in $\\mathbb{R}^n$.\nLet the projection of vector $z$ onto the subspace $L$ be $\\hat z$ and\nits length squared $Q$\n\\[\nQ = \\lVert \\hat z \\rVert^2 = \\langle \\hat z, \\hat z \\rangle = \\hat z^T \\hat z\n\\]\nThen $Q$ follows the chi-squared distribution with $k$ degrees of freedom.\n\\end{definition}\n\n\\begin{theorem}\nThe definitions~\\ref{def:chi_traditional} and \\ref{th:chi} are equivalent.\n\\end{theorem}\n\n\\begin{proof}\nFirst, it can be shown that the~projected vector $\\hat z$ is the~original vector $z$\nmultiplied by the~projection matrix $H = X(X^T X)^{-1}X^T$ where the columns of $X$\nare fixed linearly independent vectors $x_1, \\ldots, x_k$ in $L$\nor equivalently $\\col X = \\Lin(x_1, \\ldots, x_k)$.\nThis matrix is  also often referred to as `hat-matrix'.\nThen the statement in~the~theorem can be rewritten as follows:\n\\[\n\\hat z^T \\hat z = (Hz)^T Hz = z^T H^T H z = z^T H^2 z = z^T H z,\n\\]\napplying the idempotence property in the last step.\n\nAnother nice property of~the~hat-mattix is symmetry.\nThus, it can be decomposed as\n\\[\nH = P D P^T,\n\\]\nwhere we choose the vectors of matrix $P$ to be unit and orthogonal,\nand $D = \\diag{(\\lambda_1, \\ldots, \\lambda_n)}$ where $\\lambda_i$ is an eigenvalue of $H$.\n\n\\begin{marginfigure}\n  \\includegraphics[width=\\linewidth]{figures/04_chi_squared_example.pdf}\n  \\caption{Consider a $3$-dimensional example, $\\col X = \\Lin(x_1, x_2)$ and $col^{\\perp}X = \\Lin(x_3)$.\n  $H x_1 = x_1$ and $H x_2 = x_2$ since they are in $\\col X$. However, $H x_3 = 0$ as $x_3 \\perp \\col X$.\n  Projecting an arbitrary vector onto $\\col X$ yileds $Hy = \\hat y \\in \\Lin(x_1, x_2)$\n  while projecting onto $\\col^{\\perp}X$ results in $(I-H)y = \\hat{\\hat y} \\in \\Lin(x_3)$.}\n\\end{marginfigure}\n\nSince $H^2 = H$ the eigenvalues are either $0$ or $1$.\nRecall that $H$ projects a vector onto $\\col X$.\nThen for any $x_i$, $i = 1, \\ldots, k$, $H x_i = x_i \\cdot 1$ since\nany $x_i$ is already in $\\col X$. This implies that $\\lambda_1 = \\ldots = \\lambda_k = 1$.\nThere are also $n-k$ vectors in the subspace orthogonal to $\\col X$.\nSo for any $x_i$, $i= k+1, \\ldots, n$, the orthogonal projection yields zero.\nWe conclude that $\\lambda_{k+1} = \\ldots = \\lambda_n = 0$.\n\nRewritting the theorem statement further, we obtain\n\\[\nz^T H z = z^T P D P^T z = (P^T z)^T D (P^T z) = \\tilde z^T D \\tilde z = \\tilde z_1^2 + \\ldots + \\tilde z_k^2.\n\\]\nNow we explore $\\tilde z$ given $z \\sim \\mathcal{N}(0, I)$:\n\\begin{align*}\n&\\tilde z = P^T z \\\\\n&\\E(\\tilde z) = \\E(P^T z) = P^T \\E(z) = 0 \\\\\n&\\Var(\\tilde z) = \\Var(P^T z) = P^T \\Var(z) (P^T)^T = P^T P = I\n\\end{align*}\nSo we conclude that $\\tilde z_1^2 + \\ldots + \\tilde z_k^2 \\sim \\chi^2_k$.\n\n\\end{proof}\n\n\n\\subsection{Student's}\n\n\\marginnote{\nA continuous random variable $T$ has Student's distribution with $k$ degrees\nof freedom if it can be expressed as\n\\[\nT = \\frac{Z}{\\gamma_k/\\sqrt{k}},\n\\]\nwhere $Z \\sim \\mathcal{N}(0,1)$, $\\gamma_k \\sim \\chi^2_{k}$ and\n$Z$, $\\gamma_k$ are independent.\n}\n\n\\begin{definition}\nLet  $z = \\begin{pmatrix} z_1 \\\\ \\vdots \\\\ z_n \\end{pmatrix}$\nwhere $z_i \\sim \\mathcal{N}(0, \\sigma^2), i=1, \\ldots, n$ and are independent.\nLet $L_1$ be 1-dimensional subspace in $\\mathbb{R}^{n}$,\ngenerated by unit-length vector $a$, $L_1 = \\Lin(a)$.\nLet $L_2$ be a subspace orthogonal to $L_1$.\nLet $T$ be a scaled ratio of lengths:\n\\[\nT = \\frac{\\langle a, z \\rangle}{\\lVert H_2 z \\rVert / \\sqrt{\\dim L_2}}\n\\]\nwhere $\\langle a, x \\rangle$ is the length of the projection of vector $z$ onto\n1-dimensional subspace $L_1$ multiplied by plus or minus one,\n$\\lVert H_2 z \\rVert$ — the length of the projection of vector $z$ onto $L_2$,\nThen $T$ follows Student's distribution with $\\dim L_2$ degrees of freedom.\n\\end{definition}\n\n% Let us choose two orthogonal subspaces: one-dimensional $L_1$ and $k$-dimensional $L_2$.\n\nPreviously we showed that, the squared length of projection follows\nthe chi-squared distribution with the degrees of freedom equal to the dimension\nonto which the vector was projected. Thus, $\\langle a, z \\rangle^2 = \\lVert H_1 z \\rVert^2 \\sim \\chi^2_1$\nand $\\lVert H_2 z \\rVert^2 \\sim \\chi^2_{k}$.\nNow we can express $T^2$ as a ratio of the per-dimension lengths squared:\n\\[\nT^2 = \\frac{\\lVert H_1 z \\rVert^2}{\\lVert H_2 z \\rVert^2 / \\dim L_2}\n\\]\nTaking the square root of both sides, we obtain:\n\\[\nT = \\frac{\\langle a, z \\rangle}{\\lVert H_2 z \\rVert / \\sqrt{\\dim L_2}} = \\tg \\varphi \\sqrt{\\dim L_2}\n\\]\nThe latter equality can be illustarted with a $3$-dimensional example (see Figure~\\ref{fig:f_dist}).\n\n\n\n\n\n\\subsection{t-test}\n\nIn a simple linear regression model\n\\[\ny = \\beta_1 \\mathbf{1} + \\beta_2 x + \\varepsilon\n\\]\nthe adjusted t-value $\\frac{t}{\\sqrt{n-2}}$ when $H_0: \\beta_2 = 0$ is tested\ncan be expressed in terms of the angle between $y$ and $\\hat y$ $\\varphi$ and\nis equal to $\\ctg \\varphi$.\n\nRecall that the t-statistic is defined in the following way:\n\\[\nt = \\frac{\\hat \\beta - \\beta}{se\\left(\\hat\\beta\\right)}\n\\]\nAdjusting this formula for the null hypothesis $H_0: \\beta_2 = 0$, we obtain\n\\begin{equation}\\label{eq:tstat}\nt = \\frac{\\hat \\beta_2}{se\\left(\\hat\\beta_2\\right)}\n\\end{equation}\nThen, we need to express $se\\left(\\hat\\beta_2\\right)$ in terms of vectors which can be\nplotted. From standard OLS procedure it follows that\n\\begin{equation}\\label{eq:varbeta2}\n\\Var(\\hat \\beta_2) = \\frac{\\sigma^2}{\\sum\\limits_{i=1}^n (x_i - \\bar x)^2}\n\\end{equation}\nSince actual $\\sigma$ is unknown the estimator will be used instead:\n\\begin{equation}\\label{eq:sigmaest}\n\\hat \\sigma^2 = \\frac{RSS}{n-2}\n\\end{equation}\nSubstituting \\eqref{eq:varbeta2} and \\eqref{eq:sigmaest} into \\eqref{eq:tstat}\ndivided by $\\sqrt{n-2}$, we obtain\n\\begin{align*}\n\\frac{t}{\\sqrt{n-2}} &=\n\\frac{\\hat \\beta_2}{\\sqrt{n-2}se\\left(\\hat\\beta_2\\right)} =\n\\frac{\\hat \\beta_2}{\\sqrt{n-2}\\frac{\\hat \\sigma}{\\sqrt{\\sum\\limits_{i=1}^n (x_i - \\bar x)^2}}} \\\\\n&= \\frac{\\hat \\beta_2 \\sqrt{\\sum\\limits_{i=1}^n (x_i - \\bar x)^2}}{\\sqrt{n-2}\\frac{\\sqrt{\\sum\\limits_{i=1}^n (y_i - \\hat y_i)^2}}{\\sqrt{n-2}}} =\n\\frac{\\hat \\beta_2 \\lVert x^c \\rVert}{\\sqrt{RSS}}\n\\end{align*}\nwhere $ \\lVert x^c \\rVert = \\sqrt{\\sum_{i=1}^n (x_i - \\bar x)^2}$ is the length of the\ncentred vector $x$.\n\nNow the result can be demonstrated visually.\nAgain we will project $x$ and $y$ vectors onto the $\\Lin^{\\perp}(\\mathbf{1})$ so as to\nget their centred versions $x^c$ and $y^c$.\nThen, we perform regression of $y$ onto $\\Lin(x, \\mathbf{1})$ which results in $\\hat y$.\nFollowing that, we project $\\hat y = \\hat \\beta_1 \\mathbf{1} + \\hat \\beta_2 x$ onto $\\Lin^{\\perp}(\\mathbf{1})$\nwhich yields $\\hat \\beta_2 x^c$.\nAfter all, we translate $\\sqrt{RSS}$ onto $\\Lin^{\\perp}(\\mathbf{1})$.\nThese steps are demonstrated in Figure~\\ref{fig:ttest_3d}.\n\nLooking at Figure~\\ref{fig:ttest_lin} which depicts the $\\Lin^{\\perp}(\\mathbf{1})$,\nwe derive\n\\[\n\\ctg \\varphi = \\frac{\\hat \\beta_2 \\lVert x^c \\rVert}{\\sqrt{RSS}} = \\frac{t}{\\sqrt{n-2}}\n\\]\n\n\\begin{figure}[ht!]\n\\begin{center}\n\\subfigure[]{\n\\includegraphics[width=0.45\\linewidth]{figures/04_ttest.pdf}\n\\label{fig:ttest_3d}}\n%\\hspace{4ex}\n\\subfigure[]{\n\\includegraphics[width=0.45\\linewidth]{figures/04_ttest_lin.pdf}\n\\label{fig:ttest_lin}}\n\\caption{\\subref{fig:pcorr_t_x}: Regression of $y$ onto $\\Lin(x, \\mathbf{1})$ and appropriate projections;\n\\subref{fig:pcorr_t_y}: $\\Lin^{\\perp}(\\mathbf{1})$.}\n\\end{center}\n\\end{figure}\n\n\n\\subsection{F-distribution}\n\n\\marginnote{\nGenerally, the following definition is given.\n\\begin{definition}\nLet $\\gamma_1 \\sim \\chi^2_{k_1}$, $\\gamma_2 \\sim \\chi^2_{k_2}$,\n$\\gamma_1$, $\\gamma_2$ independent.\nThen\n\\[\n\\frac{\\gamma_1/k_1}{\\gamma_2/k_2} \\sim F_{k_1, k_2}.\n\\]\n\\end{definition}\n}\n\n\\begin{definition}\\label{def:f}\nLet $z = \\begin{pmatrix} z_1 \\\\ \\vdots \\\\ z_n \\end{pmatrix}$\nwhere $z_i \\sim \\mathcal{N}(0, \\sigma^2)$ and are independent.\nLet $L_1$, $L_2$ be orthogonal subspaces in $\\mathbb{R}^n$.\nThen\n\\[\nF = \\frac{\\lVert H_1 z \\rVert^2 / \\dim L_1}{\\lVert H_2 z \\rVert^2 / \\dim L_2} \\sim F_{\\dim L_1, \\dim L_2},\n\\]\nwhere $\\lVert H_1 z \\rVert^2$, $\\lVert H_2 z \\rVert^2$ are the squared lengths\nof $z$ projected onto $L_1$ and $L_2$ respectively.\n\\end{definition}\n\nRecall that by Theorem~\\ref{th:mvn} the projections of a standard noraml vector\nonto orthogonal subspaces are independent.\nThus, in terms of the Definition~\\ref{def:f} $H_1 z$ and $H_2 z$ are independent.\nNext, from the Definition~\\ref{th:chi} where we defined the chi-squared distribution\nit follows that the squared lengths of these projections follow\nthe chi-squared distribution with the number of degrees of freedom\nequal to the dimension of the subspace onto which the vector was projected.\nIn other words, $\\lVert H_1 z \\rVert^2 \\sim \\chi^2_{\\dim L_1}$,\n$\\lVert H_2 z \\rVert^2 \\sim \\chi^2_{\\dim L_2}$.\n\n\\begin{marginfigure}\n\\includegraphics[scale=0.7]{figures/04_f_dist_example.pdf}\n\\caption{F-distribution as the ratio of the projection lengths squared\nadjusted to the dimensions of the subspaces.}\n\\label{fig:f_dist}\n\\end{marginfigure}\n\nTaking the ratio of these length squared, we get the interpretaion\nof the angle between the original vector $z$ and its projection onto $L_1$:\n\\[\n\\tg^2 \\varphi = \\frac{\\lVert H_1 z \\rVert^2}{\\lVert H_2 z \\rVert^2}.\n\\]\nAdjusting this ratio to the degrees of freedom, we get the desired definition.\n\n\n\\subsection{F-test}\n\nThe significance of several coefficients at once can be tested with the F-test.\nThe F-statistic has the following form\n\\[\nF = \\frac{(RSS_{R} - RSS_{UR})/q}{RSS_{UR}/(n-k_{UR})}\n\\]\nwhere indices $R$ and $UR$ stand for the restricted and unrestricted models\nrespectively, $n$ — number of observations, $k$ — number of regressors,\n$q$ — number of equtions used in the null hypothesis.\n\n\\begin{marginfigure}\n\\includegraphics[scale=0.55]{figures/04_ftest.pdf}\n\\caption{F-statistic is proportional to the cotangent squared of $\\varphi$,\nwhere $a$ stands for $\\sqrt{RSS_{UR}}$, $b$ — $\\sqrt{RSS_{R} -RSS_{UR}}$,\n$c$ — $\\sqrt{RSS_{R}}$.}\n\\label{fig:ftest}\n\\end{marginfigure}\n\nDue to plotting limitations, we consider the unrestricted model to be\n\\[\ny = \\beta_1 \\mathbf{1}+ \\beta_2 x + u\n\\]\nand the restricted model to be\n\\[\ny = \\alpha_1 \\mathbf{1} + v\n\\]\nNote that there was a choice in the restricted models.\n\n\nWe perform both regressions in order to get the ressiduals and plot them\nin Figure~\\ref{fig:ftest}.\nAdjusted to the degrees of freedom, the ratio can be expressed in terms of the\nangle between two vectors, $\\varphi$, as demonstrated in Figure~\\ref{fig:ftest}\n\\[\nF = \\frac{(RSS_{R} - RSS_{UR})/q}{RSS_{UR}/(n-k_{UR})} =\n\\ctg^2 \\varphi \\cdot \\frac{n - k_{UR}}{q}\n\\]\n", "meta": {"hexsha": "2965d896d4d8cebaba2f7540a03bad56f0025f03", "size": 17751, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/4_distributions.tex", "max_stars_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_stars_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-22T20:38:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:38:41.000Z", "max_issues_repo_path": "chapters/4_distributions.tex", "max_issues_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_issues_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-06-29T09:11:36.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-28T19:35:55.000Z", "max_forks_repo_path": "chapters/4_distributions.tex", "max_forks_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_forks_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-05-21T18:32:18.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-21T18:32:18.000Z", "avg_line_length": 37.6878980892, "max_line_length": 149, "alphanum_fraction": 0.6852008338, "num_tokens": 6182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282707, "lm_q2_score": 0.8652240791017536, "lm_q1q2_score": 0.7438017644287559}}
{"text": "\\section{Parameterized Surfaces}\r\n\\noindent\r\nParameterized surfaces are a natural of VVFs that map $\\mathbb{R}^n \\to \\mathbb{R}^m$ where usually $n<m$.\\\\\r\n\r\n\\noindent\r\nFor example, a cylinder of radius 1 can be parameterized as $\\vec{r}(u,v) = \\langle\\sin{u}, \\cos{u}, v\\rangle$. This particular surface maps $\\mathbb{R}^2 \\to \\mathbb{R}^3$.\\\\\r\nThe paraboloid $z = x^2 + y^2$ can be parameterized as $\\vec{r}(u,v)=\\langle u, v, u^2+v^2 \\rangle$.\\\\\r\n\r\n\\noindent\r\nA general trick when trying to parameterize a surface is to substitute $u$ and $v$ for two variables like $x$ and $y$ and find an expression for the third variable in terms of the $u$ and $v$. Although this doesn’t always lead to the most useful parameterization, it can be a good starting point.\\\\\r\n\r\n\\noindent\r\nFor example, if we wanted to parameterize the surface $y^2=x^2+z^2$ from $y=1$ to $y=9$, we could use the general trick and get $\\vec{r}(u,v) = \\langle u,\\sqrt{u^2+v^2},v\\rangle$ where $1\\leq u^2+v^2\\leq 9^2$. Although this parameterization is technically correct, it is difficult to work with because the bounds for $u$ and $v$ are not independent.\\\\\r\nInstead, we can recognize that the surface we are trying to parameterize has radial symmetry about the y-axis, and instead let $u$ be and angle and $v$ be a radius to get $\\vec{r}(u,v) = \\langle v\\cos{u}, v, v\\sin{u}\\rangle$ where $0\\leq u\\leq 2\\pi$ and $1\\leq v\\leq 9$. The parameterization now has independent bounds, which will make operations like integration much easier.\r\n", "meta": {"hexsha": "b9fa9ed245e7c6bcaca8dc46c6fb349ebd6e8d01", "size": 1506, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/parameterizedSurfaces.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/parameterizedSurfaces.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/parameterizedSurfaces.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 100.4, "max_line_length": 377, "alphanum_fraction": 0.7118193891, "num_tokens": 476, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7438017632431055}}
{"text": "\\chapter{The Energy Momentum Tensor}\nIn special relativity we have seen that the energy momentum tensor\n$\\tensor{T}{^\\mu^\\nu}$ is conserved or divergence free respectively, i.e.\n\\begin{equation}\n\\tensor{\\partial}{_\\mu}\\tensor{T}{^\\mu^\\nu}=0\\,.\\label{eq:EMcons}\n\\end{equation}\nThe problem we are faced in general relativity is the very definition of local\nenergy. Because gravity surely contributes to the energy, a problem arises\nas we can always transform to local flat space.\nWe start by revisiting the example of dust\n\\begin{example}[Dust]\n\\begin{equation}\n\\tensor{T}{^\\mu^\\nu}=\\rho_0\\tensor{u}{^\\mu}\\tensor{u}{^\\nu}\\,.\n\\end{equation}\nIn special relativity:\n${\\tensor{u}{^\\mu}=\\od{\\tensor{x}{^\\mu}}{\\tau}=\\gamma(1,\\vec{v})\\transpose}$,\n${\\tensor{T}{^0^0}=\\rho_0\\left(\\od{t}{\\tau}\\right)^2}=\\gamma^2\\rho_0:=\\rho$.\nWhere $\\rho$ is the density with respect to an observer at rest. For the Volume\nwe have $V=\\gamma^{-1}V_0$. For the Energy $E=\\gamma\\omega_0$. Then the density\nis given by $\\rho=\\frac{E}{V}=\\gamma^2\\rho_0$. The conservation of\n$\\tensor{T}{^0^\\nu}$ implies\n\\begin{equation}\n\\begin{split}\n0&=\\tensor{T}{^0^\\nu_{,\\nu}}\\\\\n&=\\tensor{T}{^0^0_{,0}}+\\tensor{T}{^0^i_{,i}}\\\\\n&=\\tensor{\\partial}{_t}\\left(\\rho_0\\gamma^2\\right)\n+\\tensor{\\partial}{_i}\\left(\\rho_0\\gamma^2\\tensor{v}{^i}\\right)\\\\\n&=\\tensor{\\partial}{_t}\\rho\n+\\tensor{\\partial}{_i}\\left(\\rho \\tensor{v}{^i}\\right)\\\\\n&=\\dot{\\rho}\n+\\boldsymbol{\\nabla}\\left(\\rho \\vec{v}\\right)\\,,\n\\end{split}\n\\end{equation}\nthe \\emph{continuity equation}. For the remaining spatial components we get\n\\begin{equation}\n\\begin{split}\n0&=\\tensor{T}{^i^\\nu_{,\\nu}}\\\\\n&=\\tensor{T}{^i^0_{,0}}+\\tensor{T}{^j^i_{,i}}\\\\\n&=\\dot{\\rho}\\tensor{v}{^i}\n+\\rho\\tensor{\\dot{v}}{^i}\n+\\tensor{v}{^i}\\tensor{\\partial}{_j}\\left(\\rho\\tensor{v}{^j}\\right)\n+\\tensor{\\dot{v}}{^j}\\rho\\tensor{\\partial}{_j}\\tensor{v}{^i}\\\\\n&=\\tensor{v}{^i}\\left[\\dot{\\rho}+\\tensor{\\partial}{_j}\\left(\\rho\\tensor{\\dot{v}}{^j}\\right)\\right]\n+\\rho\\left(\\tensor{\\dot{v}}{^i}+\\tensor{\\dot{v}}{^j}\\tensor{\\partial}{_j}\\tensor{v}{^i}\\right)\\\\\n&=\\rho\\left(\\tensor{\\dot{v}}{^i}+\\tensor{\\dot{v}}{^j}\\tensor{\\partial}{_j}\\tensor{v}{^i}\\right)\\,,\n\\end{split}\n\\end{equation}\nthe \\emph{Euler equation} for vanishing pressure (which was the key assumption\nfor dust). It is natural to generalize equation \\eqref{eq:EMcons} to curved\nspace\n\\begin{equation}\n\\tensor{T}{^\\mu^\\nu_{;\\nu}}=0\\,.\n\\end{equation}\nIn expanded form\n\\begin{equation}\n\\begin{split}\n0\n&=\\tensor{\\nabla}{_\\nu}\\left(\\rho_0\\tensor{u}{^\\mu}\\tensor{u}{^\\nu}\\right)\\\\\n&=\\tensor{{\\rho_0}}{_{;\\nu}}\\tensor{u}{^\\mu}\\tensor{u}{^\\nu}\n+\\rho_0\\tensor{u}{^\\mu_{;\\nu}}\\tensor{u}{^\\nu}\n+\\rho_0\\tensor{u}{^\\mu}\\tensor{u}{^\\nu_{;\\nu}}\\\\\n&=\\tensor{u}{^\\mu}\\left(\\rho_0\\tensor{u}{^\\nu_{;\\nu}}+\\tensor{{\\rho_0}}{_{;\\nu}}\\tensor{u}{^\\nu}\\right)\n+\\rho_0\\tensor{u}{^\\mu_{;\\nu}}\\tensor{u}{^\\nu} \\label{eq:DustEnCons}\n\\end{split}\n\\end{equation}\nWe multiply both sides with $\\tensor{u}{_\\mu}$\n\\begin{equation}\n\\begin{split}\n0\n&=-\\left(\\rho_0\\tensor{u}{^\\nu_{;\\nu}}+\\tensor{{\\rho_0}}{_{;\\nu}}\\tensor{u}{^\\nu}\\right)\n+\\rho_0\\tensor{u}{^\\nu}\\tensor{u}{_\\mu}\\tensor{u}{^\\mu_{;\\nu}}\\\\\n&=-\\left(\\rho_0\\tensor{u}{^\\nu_{;\\nu}}\n+\\tensor{{\\rho_0}}{_{;\\nu}}\\tensor{u}{^\\nu}\\right)\n\\end{split}\n\\end{equation}\nIf we plugg this back into equation \\eqref{eq:DustEnCons} we get\n\\begin{equation}\n\\begin{split}\n0&=\\tensor{u}{^\\nu}\\tensor{\\nabla}{_\\nu}\\tensor{u}{^\\mu}\\\\\n&=\\tensor{u}{^\\nu}\\tensor{\\partial}{_\\nu}\\tensor{u}{^\\mu}\n+\\tensor{u}{^\\nu}\\cSym{\\mu}{\\nu}{\\rho}\\tensor{u}{^\\rho}\\\\\n&=\\dod{\\tensor{x}{^\\nu}}{\\tau}\\dpd{\\tensor{u}{^\\mu}}{\\tensor{x}{^\\nu}}\n+\\cSym{\\mu}{\\nu}{\\rho}\\dod{\\tensor{x}{^\\nu}}{\\tau}\\dod{\\tensor{x}{^\\nu}}{\\tau}\\\\\n&=\\dpd[2]{\\tensor{x}{^\\mu}}{\\tau}\n+\\cSym{\\mu}{\\nu}{\\rho}\\dod{\\tensor{x}{^\\nu}}{\\nu}\\dod{\\tensor{x}{^\\nu}}{\\tau}\\\\\n\\end{split}\n\\end{equation}\nThe geodesic equation \\eqref{eq:geodeq}\n\\end{example}\n\\begin{remark}\nThis is a difference between electrodynamics and general relativity; dust moves\non geodesics, i.e.\\ the path is determined by the field equations alone. In contrast\nin electrodynamics an additional Force (Lorentz force) has to be\n\\emph{postulated} to describe the motion of test particles. The case is not\nsettled however e.g.\\ it is unclear whether the paths of spin particles is also\ndetermined by the field equations.\n\\end{remark}", "meta": {"hexsha": "5c758b25140db49a3a3325236a29794dc298e1dd", "size": 4292, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/06-energy-momentum-tensor.tex", "max_stars_repo_name": "Bigben37/GeneralRelativity", "max_stars_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-31T13:18:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-31T13:18:57.000Z", "max_issues_repo_path": "src/06-energy-momentum-tensor.tex", "max_issues_repo_name": "QuantumDancer/GeneralRelativity", "max_issues_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/06-energy-momentum-tensor.tex", "max_forks_repo_name": "QuantumDancer/GeneralRelativity", "max_forks_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.2474226804, "max_line_length": 103, "alphanum_fraction": 0.6568033551, "num_tokens": 1628, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7437938368808183}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Solve each of the following systems of equations with scalars in\n  $\\Z_2$. If there is more than one solution, write the\n  general solution in parametric form and also write down all of the\n  solutions individually. How many solutions are there?\n\n  \\begin{equation*}\n    (a)~\n    \\begin{mymatrix}{rrrr|r}\n      0 & 1 & 1 & 1 & 0 \\\\\n      1 & 0 & 0 & 1 & 1 \\\\\n      1 & 1 & 1 & 0 & 1\n    \\end{mymatrix}\n    \\quad\n    (b)~\n    \\begin{mymatrix}{rrr|r}\n      0 & 1 & 1 & 1 \\\\\n      1 & 0 & 1 & 1 \\\\\n      1 & 1 & 0 & 1\n    \\end{mymatrix}\n    \\quad\n    (c)~\n    \\begin{mymatrix}{rrrr|r}\n      0 & 1 & 1 & 0 & 1 \\\\\n      1 & 0 & 1 & 0 & 0 \\\\\n      1 & 1 & 0 & 1 & 0\n    \\end{mymatrix}\n    \\quad\n    (d)~\n    \\begin{mymatrix}{rrr|r}\n      0 & 1 & 1 & 1 \\\\\n      1 & 0 & 1 & 1 \\\\\n      1 & 1 & 1 & 0\n    \\end{mymatrix}\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Solve each of the following systems of equations with scalars in\n  $\\Z_3$. How many solutions does each system have?\n\n  \\begin{equation*}\n    (a)~\n    \\begin{mymatrix}{rrr|r}\n      0 & 1 & 1 & 1 \\\\\n      1 & 2 & 0 & 1 \\\\\n      2 & 0 & 2 & 1\n    \\end{mymatrix}\n    \\quad\n    (b)~\n    \\begin{mymatrix}{rrrr|r}\n      2 & 1 & 2 & 1 & 0 \\\\\n      0 & 2 & 1 & 1 & 2 \\\\\n      1 & 0 & 0 & 1 & 1\n    \\end{mymatrix}\n    \\quad\n    (c)~\n    \\begin{mymatrix}{rrr|r}\n      1 & 2 & 0 & 2 \\\\\n      1 & 0 & 1 & 1 \\\\\n      1 & 1 & 1 & 0\n    \\end{mymatrix}\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Solve each of the following systems of equations with scalars in\n  $\\Z_5$.\n\n  \\begin{equation*}\n    (a)~\n    \\begin{mymatrix}{rrrr|r}\n      0 & 2 & 1 & 4 & 0 \\\\\n      1 & 1 & 2 & 3 & 2 \\\\\n      2 & 4 & 0 & 0 & 4\n    \\end{mymatrix}\n    \\quad\n    (b)~\n    \\begin{mymatrix}{rrr|r}\n      1 & 2 & 4 & 1 \\\\\n      3 & 0 & 1 & 1 \\\\\n      2 & 4 & 3 & 2\n    \\end{mymatrix}\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  In $\\Z_7$, calculate $1^{-1}$, $2^{-1}$, $3^{-1}$, $4^{-1}$,\n  $5^{-1}$, and $6^{-1}$. Hint: write down the multiplication table.\n\\end{ex}\n\n\\begin{ex}\n  Consider a game similar to Example~\\ref{exa:button-game}, with 6\n  lights arranged in a rectangle:\n  \\begin{center}\n    \\begin{tabular}{|c|c|c|}\n      \\hline\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lighton} &\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lighton} &\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lightoff} \\\\\\hline\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lightoff} &\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lightoff} &\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lighton} \\\\\\hline\n    \\end{tabular}\n  \\end{center}\n  Again, each light doubles as a button. Pressing it toggles its own\n  light, as well as all of its neighbors. Which buttons do you have to\n  press to turn off all the light from the starting position shown\n  above? Is the answer unique? Is every pattern of lights reachable\n  from this starting position?\n\\end{ex}\n\n\\begin{ex}\n  Solve each of the following systems of equations with scalars in the\n  complex numbers.\n  \\begin{equation*}\n    (a)~\n    \\begin{mymatrix}{ccc|c}\n      1   & 1   & 1+i & 2    \\\\\n      1+i & 2+i & 3i  & 3+2i \\\\\n    \\end{mymatrix}\n    \\quad\n    (b)~\n    \\begin{mymatrix}{ccc|c}\n      1   & i    & 1+i & -1+2i \\\\\n      1+i & 2    & 1-i & 4+4i  \\\\\n      1   & -1+i & -i  & 0     \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item {\\Rref}: $\\begin{mymatrix}{ccc|c}\n      1 & 0 & 1 & 1 \\\\\n      0 & 1 & i & 1 \\\\\n    \\end{mymatrix}$. General solution: $x=1-t$, $y=1-it$, $z=t$.\n    \\item Solution: $x=1$, $y=1+i$, $z=i$.\n  \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "59e0cca20f5d8deef5bd9d759c310800487be6db", "size": 3668, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/SystemsofEquations-Fields.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/SystemsofEquations-Fields.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/SystemsofEquations-Fields.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 25.4722222222, "max_line_length": 77, "alphanum_fraction": 0.5329880044, "num_tokens": 1503, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.8670357649558006, "lm_q1q2_score": 0.7437156313697662}}
{"text": "\\chapter{Cross Correlations}\\label{chp:1}\n\nCross correlation is powerful statistical tool for computing the degree to which two signals are correlated (or similar), and also for computing lags. In this part, we first implement the cross correlation in 1 dimension and apply it to a signal processing task. Then we extend it to 2 dimensions and do some image processing with it. \n\n After implementing these basic models, we focus on the efficiency of calculating cross correlation. To be specific, large signals and images may result in time consumption. Then there is an alternative way to solve this problem, that is, finding spectral cross correlation with a Fourier transform and inverse Fourier transform. The result shows this new method achieve better performance in scale data.\n\n\\section{Normalized Spatial Cross Correlation in 1d}\n\nIn signal processing, cross-correlation is a measure of similarity of two series as a function of the displacement of one relative to the other. In this project, we only consider discrete signals rather than continue signals.\n\nFor any one dimension signal, we can represent it by a function. For discrete functions f and g, the cross-correlation is defined as\\cite{rabiner1975theory}\\cite{rabiner1978digital}:\n\n\\begin{equation*}\nr=\\frac{1}{N}\n\\sum_{i=1}^{i=N}(f(i)-\\bar{f})(g(i)-\\bar{g})\n\\end{equation*}\n\nWhich computes the correlation between two signals. However, the value of $r$ is somewhat arbitrary because of the variant amplitude of $f$ and $g$, which makes the position of maximum value of $r$ does not represents the offset that makes two signals get maximum similarity. One way around this is to normalize signal with the root-mean-quare. Normalized cross correlation is typically done by subtracting the mean and dividing by the standard deviation. As:\n\n\\begin{equation*}\nR=\\frac{1}{N}\n\\sum_{i=1}^{i=N}\n\\frac{(f(i)-\\bar{f})(g(i)-\\bar{g})}{\\sigma _{f}\\sigma _{g}}\n\\end{equation*}\n\nwhere\n\n\\begin{equation*}\n{\\sigma _{f}}=\n\\sqrt{\\frac{1}{N}\\sum_{i=1}^{i=N}(f(i)-\\bar{f})^{2}}\n\\hspace{4em}\n{\\sigma _{g}}=\n\\sqrt{\\frac{1}{N}\\sum_{i=1}^{i=N}(g(i)-\\bar{g})^{2}}\n\\end{equation*}\n\nSource code of one dimensional cross correlation and normalized one dimensional cross correlation are in Appendix \\ref{code:1.1_1} and\\ref{code:1.1_2} separately.\n\n\n\\section{Signal Offset}\n\nConsider two signals (denote by vector) come from the same source and they are just offset by some time since they are captured by two sensors with constant distance. Cross correlation can be used to find the offset time and distance between two sensors. First find the max value's position of the cross correlation vector computed from two signals. Then find corresponding positions of the two signals and compute the offset of the signal vector. Through the given sample rate and propagation speed, the offset time and distance can be calculated as follow:\n\n\\begin{equation*}\n\\text{offset time}=\\frac{\\text{offset}}{\\text{sample rate}} \n\\end{equation*}\n\n\\begin{equation*}\n\\text{distance}=\\text{(offset time)} * \\text{(propagation speed)}\n\\end{equation*}\n\nIn this task, we take two signal files and compute the cross correlation between them. Figure \\ref{fig:crr_vis0} shows the result of the cross correlation. \n\n\\begin{figure}[h!]\n\t\\centering\n\t\t\\includegraphics[width=0.45\\linewidth]{figures/part1/crr_vis0.eps}\n\t\t\\caption{Cross correlation of two signals.}\n\t\t\\label{fig:crr_vis0}\n\\end{figure} \n\nThe x coordinate of maximum correlation is 50081, the length of signal is 176401 and sample rate is 44100. Applying the function above can get the result of offset time equals 50081 and sensor distance equals 378.17 meters.\n\nSource code of signal offset computing is in Appendix \\ref{code:1.2}.\n\n\\section{Normalized Spatial Cross Correlation in 2d}\n\nTill now, the cross correlation we used can only computer one dimensional signal. But in later work, for comparing images and get the correlation of them smoothly, it is necessary to extend the cross correlation to two dimensions. Similar with signals can be represented by vector, images can represented by matrix. Consider two matrices, t (template) and A (search region), The matrix A will always larger than the matrix t. We can use two nested for-loops to ``lag'' t over A, compute for each ``lag'' the cross-correlation. Normalized cross correlation of two matrices defines as:\n\n\\begin{equation*}\nR(lag_{x},lag_{y})=\n\\frac{\\sum_{x,y}[A(x,y)-\\overline{A_{lag_{x},lag_{y}}})][t(x-lag_{x},y-lag_{y})-\\bar{t}]}\n{\\{\\sum_{x,y}[A(x,y)-\\overline{A_{lag_{x},lag_{y}}})]^2\n\t\\sum_{x,y}[t(x-lag_{x},y-lag_{y})-\\bar{t}]^2\n\t\\}^{0.5}}\n\\end{equation*}\n\nWhere $\\bar{t}$ is the mean of t, $\\overline{A_{lag_{x},lag_{y}}}$ is the mean of A in the region under t. \n\nThe source code of implementation of normalized 2d cross correlation is in Appendix \\ref{code:1.3}.\n\n\\section{Image Alignment}\n\nImages are just a matrix of pixel values in most image processing. It is naturally think of computing cross correlation between two images to get more relation informations of them. In this task, there are two images, one of them is a section of the other, so it is easy to find where the section of the image fits in the whole through cross correlation.\n\nHere, we have a section (rocket man) show in Figure \\ref{fig:rocketman} and a search region (maze) as Figure \\ref{fig:maze}.\n\n\\begin{figure}[h!]\n\t\\centering\n\t\t\\begin{subfigure}[t]{0.4\\linewidth}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.6\\linewidth]{figures/part1/wallypuzzle_rocketman.png}\n\t\t\t\\caption{Rocket Man (section). }\n\t\t\t\\label{fig:rocketman}\n\t\t\\end{subfigure}\n\t\t\\begin{subfigure}[t]{0.55\\linewidth}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=1\\linewidth]{figures/part1/wallypuzzle_result}\n\t\t\t\\caption{Maze (search region). }\n\t\t\t\\label{fig:maze}\n\t\t\\end{subfigure}\n\t\t\\caption{Source images for image alignment.}\n\\end{figure} \n\nThe visualization of cross correlation is shown in Figure \\ref{fig:crr_vis1} and Figure \\ref{fig:crr_vis2}. The maximum of the cross correlation corresponds to the estimated location of the section. Which means the most similar position of the section and search region. We mark it with a blue circle in Figure \\ref{fig:maze}.\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\begin{subfigure}[t]{0.45\\linewidth}\n\t\t\\includegraphics[width=1\\linewidth]{figures/part1/crr_vis1.eps}\n\t\t\\caption{2D visualization}\n\t\t\\label{fig:crr_vis1}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.45\\linewidth}\n\t\t\\centering\n\t\t\\includegraphics[width=1\\linewidth]{figures/part1/crr_vis2.eps}\n\t\t\\caption{3D visualization}\n\t\t\\label{fig:crr_vis2}\n\t\\end{subfigure}\n\t\\caption{Cross correlation result matrix visualization}\n\\end{figure} \n\nSource code for image alignment is in Appendix \\ref{code:1.4}.\n\n\\section{Spectral Cross Correlation}\n\nCross correlation can also be done in the spectral domain by completing a Fourier transform, multiplying signals, and doing an inverse Fourier transform.\n\nThe fast Fourier transform (FFT) algorithm can convert a signal from its original domain to a representation in the frequency domain and inverse fast Fourier transform (IFFT) vice versa. It is an advanced algorithm of the discrete Fourier transform (DFT), and it manages to reduce the complexity of computing the DFT from $O(n^2)$, which arises if one simply applies the definition of DFT, to $O(n\\log n)$ \\cite{heiderman84}.\n\nFast Fourier transform is a very useful and powerful algorithm in computing convolution and cross correlation. It can be shown that the discrete convolution of signal $u$ and $v$ as defined by,\n\n\\begin{equation*}\n(u*v)(\\tau)=\\sum_{m=1}^{N}u(m)v(\\tau-m)\n\\end{equation*}\n\ncan also be expressed in terms of Fourier transform\n\n\\begin{equation*}\n(u*v)(\\tau)=\\mathcal{F}^{-1}\\{\\mathcal{F}(u)\\cdot \\mathcal{F}(v)\\}\n\\end{equation*}\n\nwhere $\\mathcal{F}(u)$ is the Fourier transform of $u$, $\\mathcal{F}(v)$ is the Fourier transform of $v$, and $\\mathcal{F}^{-1}$ is the inverse Fourier transform.\n\nAs for cross correlation, it can be calculated through summation of a product.\n\n\\begin{equation*}\n(u*v)(\\tau)=\\sum_{m=1}^{N}u^*(m)v(\\tau+m)\n\\end{equation*}\n\nor using FFTs.\n\n\\begin{equation*}\n\t(u*v)(\\tau)=\\mathcal{F}^{-1}\\{(\\mathcal{F}(u))^{*}\\cdot \\mathcal{F}(v)\\}\n\\end{equation*}\n\nWhere the $*$ refers to the complex conjugate.\n\nTable \\ref{tab:run_time} compare the run time of two different method of task in section 2. From which we can find that spectral method using Fourier transform achieves better performance.\n\n\\begin{table}[h!]\n\t\\centering\n\t\\caption{Run time compare of spatial and spectral methods.}\n\t\\begin{tabular}{c|c|c}\n\t\t\\hline\n\t\tmethod & Spatial & Spectral \\\\\n\t\t\\hline\n\t\ttime(s) & 4.6741 & 0.1103 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\label{tab:run_time}\n\\end{table}\n\nSource code of spectral cross correlation is in Appendix \\ref{code:1.5}.\n\n\\section{Pattern Finder}\n\nIn this task, We pick a piece of music and cut a small piece of it (a drum) through listening. Figure \\ref{fig:drum} and Figure \\ref{fig:music} shows two pieces of waveforms separately. Figure \\ref{fig:crr_vis3} presents all occurrence of the element, as it is not a normalized correlation picture, all positions with the y-coordinates larger than 1000 is the appearance of the drum. In addition, other background noise have an effect on our calculation but not serious.\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\begin{subfigure}[t]{0.32\\linewidth}\n\t\t\\includegraphics[width=1\\linewidth]{figures/part1/drum.eps}\n\t\t\\caption{drum waveform}\n\t\t\\label{fig:drum}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.32\\linewidth}\n\t\t\\centering\n\t\t\\includegraphics[width=1\\linewidth]{figures/part1/music.eps}\n\t\t\\caption{music waveform}\n\t\t\\label{fig:music}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.32\\linewidth}\n\t\t\\centering\n\t\t\\includegraphics[width=1\\linewidth]{figures/part1/crr_vis3.eps}\n\t\t\\caption{cross correlation}\n\t\t\\label{fig:crr_vis3}\n\t\\end{subfigure}\n\t\\caption{Two oscillographs}\n\t\\label{fig:wave}\n\\end{figure} \n\nFrom the above plots, the signal length of one single drum is 7000, then cutting a 4.5 seconds music which length in Matlab is about $2*10^5$. There are 7 occurrences of the dum in this episode.\n\nSource code for pattern finder is in Appendix \\ref{code:1.6}.\n\n\\section{Cross correlation in three dimensions}\n\nThis part is just some thinking by myself. \n\nFrom the above research, we know that 1d cross correlation can be used to process acoustical signal and 2d cross correlation is very useful for image processing. Then, how about 3d cross correlation? If 3d cross correlation can be computed, we can easily know the space structure's similarity of two objects, theoretically. This task may have its value in microcosmos' research like molecular physics and microbiology. Consider there are one cell with a particular disease as specimen and no one know the reason of its pathogenicity. In the meanwhile, for several cells, some of them have the particular disease. If we can find spatial cross correlation between the specimen and other cell, base on the hypothesis that same diseased cell have the similar space structure, we can distinguish the healthy cell and diseased cell. \n\nComputer vision is one of the most popular research today. One important reason is people believe 2d object is easy to understand and image compared with 3d object. The 2d technology today have been more and more mature. However, we live in a 3d (even higher dimensions) world, research in 3d will become mainstream someday, I believe 3d cross correlation will become a basic concept and tool like today's 2d cross correlation in the future. \n\nWell, there are already some research about 3D cross correlation\\cite{Li2002Auto}\\cite{article2013}.", "meta": {"hexsha": "ff2e280c96858de0951d9343809e789a8b987d10", "size": 11587, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "The_Art_Of_Scientific_Computation/report/part1.tex", "max_stars_repo_name": "infinityglow/Unimelb-CS-Subjects", "max_stars_repo_head_hexsha": "07bdb49fd4c50035b7f2e80ca218ac2b620098e4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-14T16:31:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T16:31:07.000Z", "max_issues_repo_path": "The_Art_Of_Scientific_Computation/report/part1.tex", "max_issues_repo_name": "hidara2000/Unimelb-CS-Subjects", "max_issues_repo_head_hexsha": "07bdb49fd4c50035b7f2e80ca218ac2b620098e4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "The_Art_Of_Scientific_Computation/report/part1.tex", "max_forks_repo_name": "hidara2000/Unimelb-CS-Subjects", "max_forks_repo_head_hexsha": "07bdb49fd4c50035b7f2e80ca218ac2b620098e4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-14T11:59:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-14T11:59:13.000Z", "avg_line_length": 54.3990610329, "max_line_length": 827, "alphanum_fraction": 0.7592992146, "num_tokens": 3157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.7437156147500034}}
{"text": "\\begin{abox}\n\tLaplace Transforms\n\t\\end{abox}\n\nThe Laplace transform $f(s)$ of a function $F(t)$ is defined by \n\\begin{equation}\nf(s)=\\mathcal{L}\\{F(t)\\}=\\int_{0}^{\\infty} e^{-s t} F(t) d t .\n\\end{equation}\nA few comments on the existence of the integral are in order. The infinite integral of $F(t)$,\n\\begin{equation*}\n\\int_{0}^{\\infty} F(t) d t,\n\\end{equation*}\nneed not exist. For instance, $F(t)$ may diverge exponentially for large $t$. However, if there are some constants $s_{0}, M$, and $t_{0} \\geq 0$ such that for all $t>t_{0}$\n\\begin{equation}\n\\left|e^{-s_{0} t} F(t)\\right| \\leq M,\\label{LT-01}\n\\end{equation}\nthe Laplace transform will exist for $s>s_{0} $. $F(t)$ is then said to be of exponential order. As a counter example, $F(t)=e^{t^{2}}$ does not satisfy the condition given by Eq. (\\ref{LT-01}) and is not of exponential order. Thus, $\\mathcal{L}\\left\\{e^{t^{2}}\\right\\}$ does not exist.\nThe Laplace transform may also fail to exist because of a sufficiently strong singularity in the function $F(t)$ as $t \\rightarrow 0$. For example,\n\\begin{equation*}\n\\int_{0}^{\\infty} e^{-s t} t^{n} d t\n\\end{equation*}\ndiverges at the origin for $n \\leq-1$. The Laplace transform $\\mathcal{L}\\left\\{t^{n}\\right\\}$ does not exist for $n \\leq-1$. Since, for two functions $F(t)$ and $G(t)$ for which the integrals exist,\n\\begin{equation}\n\\mathcal{L}\\{a F(t)+b G(t)\\}=a \\mathcal{L}\\{F(t)\\}+b \\mathcal{L}\\{G(t)\\}\n\\end{equation}\nthe operation denoted by $\\mathcal{L}$ is linear.\\\\\n\\subsection{Important Laplace Transforms:}\n\\begin{enumerate}\n\t\\item $L(1)=\\frac{1}{s}$\n\t\\item $L\\left(x^{n}\\right)=\\frac{n !}{s^{n+1}}(n=0,1,2, \\ldots \\ldots . .)$\n\t\\item $L\\left(e^{a x}\\right)=\\frac{1}{s-a}(s>a)$\n\t\\item $L(\\cos a x)=\\frac{s}{s^{2}+a^{2}}$\n\t$(s>0)$\n\t\\item $L(\\sin a x)=\\frac{a}{s^{2}+a^{2}} \\quad(s>0)$\n\t\\item $L(\\cosh a x)=\\frac{s}{s^{2}-a^{2}}\\left(s^{2}>a^{2}\\right)$\n\t\\item $L(\\sinh a x)=\\frac{a}{s^{2}-a^{2}}\\left(s^{2}>a^{2}\\right)$\n\\end{enumerate}\n\n\\subsubsection{Important properties:}\n\\begin{enumerate}\n\t\\item Linear Property: $L\\left[a_{1} f_{1}(x)+a_{2} f_{2}(x)\\right]=a_{1} L\\left[f_{1}(x)\\right]+a_{2} L\\left[f_{2}(x)\\right]$\n\t\\item Shifting Property: $L\\left[e^{a x} f(x)\\right]=f(s-a)$\n\t\\item Scaling Property: $L[f(a x)]=\\frac{1}{a} f\\left(\\frac{s}{a}\\right)$\n\t\\item $L\\left[x^{n} f(x)\\right]=(-1)^{n} \\frac{d^{n}}{d s^{n}}(f(s))$\n\t\\item $L\\left[\\frac{f(x)}{x}\\right]=\\int_{-\\infty}^{\\infty} f(s) d s$\n\t\\item $L\\left[\\int_{0}^{t} f(x) d x\\right]=\\frac{1}{s} f(s)$\n\t\\item $L\\left[f^{\\prime}(x)\\right]=s L[f(x)]-f(0)$\n\t\\item  $L\\left[f^{\\prime \\prime}(x)\\right]=s^{2} L[f(x)]-f^{\\prime}(0)-s f(0)$\n\t\\item Laplace transform of a periodic function $f(x)$ having period ' $T$ ' is $$L[f({x})]=\\frac{1}{1-e^{-s T}} \\int_{0}^{T} e^{-s x} f({x}) d {x}$$\n\t\\item Laplace transform of the unit step function $u(x-a)=u_{a}(x)=\\left\\{\\begin{array}{lll}0 & \\text { for } & x<a \\\\ 1 & \\text { for } & x \\geq a\\end{array}\\right.$ is $\\frac{e^{-a s}}{s}$.\n\t\\item Laplace transform of the dirac delta function $\\delta(x-a)$ is $e^{-a s}$.\n\\end{enumerate}\n\\begin{exercise}\n\tFind the laplace transform of $f(x)=(1+\\cos 2 x)$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\begin{aligned}\n\tL[f(x)] &=\\int_{0}^{\\infty} e^{-s x}\\left(1+\\cos 2 x \\cdot d x=\\left(\\frac{e^{-s x}}{-s}\\right)_{0}^{\\infty}+\\int_{0}^{\\infty} e^{-s x} \\cos 2 x d x\\right.\\\\\n\t&=\\frac{1}{s}+\\frac{s}{4+s}=\\frac{2 s^{2}+4}{s\\left(s^{2}+4\\right)}\n\t\\end{aligned}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tFind the laplace transform of $f(x)=2 \\sin 2 x \\cos 4 x$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tL[f(x)]=L[2 \\sin 2 x \\cdot \\cos 4 x]=L[\\sin 6 x-\\sin 2 x]=\\left(\\frac{6}{s^{2}+36}-\\frac{2}{s^{2}+4}\\right)\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\nFind the laplace transform of $f(x)=e^{-x}(3 \\sinh 2 x-5 \\cosh 2 x)$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\begin{aligned}\n\tL[f(x)] &=L\\left(3 e^{-x} \\sinh 2 x\\right)-L\\left(5 e^{-x} \\cosh 2 x\\right) \\\\\n\t&=3 \\frac{2}{(s+1)^{2}-4}-5 \\cdot \\frac{(s+1)}{(s+1)^{2}-4}=\\frac{(1-5 \\mathrm{~s})}{\\left(\\mathrm{s}^{2}+2 \\mathrm{~s}-3\\right)} \\quad \\text { (Using 2nd property) }\n\t\\end{aligned}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tFind the laplace transform of the fuction\\\\\n\t$f(x)=1$ for $2 n \\leq x \\leq 2 n+1$\\\\\n\t$=0 \\quad$ for $2 n+1 \\leq x \\leq 2 n+2 \\quad(n=0,1,2, \\ldots . .)$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tL[f(x)] &=\\frac{1}{1-e^{-s T}} \\int_{0}^{T} e^{-s x} f(x) d x=\\frac{1}{1-e^{-2 s}} \\int_{0}^{2} e^{-s x} d x \\\\\n\t&=\\frac{1}{1-e^{-2 s}}\\left[\\int_{0}^{1} e^{-s x} d x\\right]=\\frac{1}{1-e^{-2 s}}\\left(\\frac{1-e^{-s}}{s}\\right)\\\\\n\t&=\\frac{\\left(1-e^{-s}\\right)}{s\\left(1+e^{-s}\\right)\\left(1-e^{-s}\\right)}=\\frac{1}{s\\left(1+e^{-s}\\right)}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tFind the laplace transform of $f(x)=\\left(1+x e^{-x}\\right)^{3}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tf(x)&=\\left(1+x e^{-x}\\right)^{3}=1+x^{3} e^{-3 x}+3 x e^{-x}+3 x^{2} e^{-2 x} \\\\\n\tL[f(x)]&=L(1)+L\\left(x^{3} e^{-3 x}\\right)+L\\left(3 x e^{-x}\\right)+L\\left(3 x^{2} e^{-2 x}\\right)\\\\\n\t&=\\frac{1}{s}+(-1)^{3} \\frac{d^{3}}{d s^{3}}\\left(\\frac{1}{s+3}\\right)+3(-1)^{1} \\frac{d}{d s}\\left(\\frac{1}{s+1}\\right)+3(-1)^{2} \\frac{d^{2}}{d s^{2}}\\left(\\frac{1}{s+2}\\right)\\text{ (Using 4th property)}\\\\\n\t&=\\frac{1}{s}+\\frac{6}{(s+3)^{4}}+\\frac{3}{(s+1)^{2}}+\\frac{6}{(s+2)^{3}} \\text {. }\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tFind the laplace transform of $f(x)=\\frac{1-e^{x}}{x}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tL\\left(\\frac{1-e^{x}}{x}\\right)&=\\int_{s}^{\\infty}\\left(\\frac{1}{s}-\\frac{1}{s-1}\\right) d s=[\\ln s-\\ln (s-1)]_{s}^{\\infty}=\\left[\\ln \\frac{s}{s-1}\\right]_{s}^{\\infty}:\\text{ (Using 5th property)}\\\\\n\t&=[\\ln s-\\ln (s-1)]_{s}^{\\infty}=\\left[\\ln \\frac{s}{s-1}\\right]_{s}^{\\infty}=\\ln \\left(\\frac{1}{\\left.1-\\frac{1}{s}\\right)_{s}}\\right)^{\\infty} \\\\\n\t&=0-\\ln \\frac{s}{s-1}=\\ln \\frac{(s-1)}{s}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tFind the inverse laplace transform of\n\t$$\\mathrm{f}(\\mathrm{s}) =\\frac{\\mathrm{s}-2}{(\\mathrm{~s}-2)^{2}+25}+\\frac{\\mathrm{s}+4}{(\\mathrm{~s}+4)^{2}+81}+\\frac{1}{(\\mathrm{~s}+2)^{2}+9} $$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\mathrm{~L}^{-1}[\\mathrm{f}(\\mathrm{s})] &=\\mathrm{L}^{-1}\\left[\\frac{\\mathrm{s}-2}{(\\mathrm{~s}-2)^{2}+25}\\right]+\\mathrm{L}^{-1}\\left[\\frac{\\mathrm{s}+4}{(\\mathrm{~s}+4)^{2}+81}\\right]+\\mathrm{L}^{-1}\\left[\\frac{1}{(\\mathrm{~s}+2)^{2}+9}\\right] \\\\\n\t&=\\mathrm{e}^{2 \\mathrm{x}} \\cos 5 \\mathrm{x}+\\mathrm{e}^{-4 \\mathrm{x}} \\cos 9 \\mathrm{x}+\\frac{\\mathrm{e}^{-2 \\mathrm{x}}}{3} \\sin 3 \\mathrm{x}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tThe graph of the function\n\t$$f(x)= \\begin{cases}1 & \\text { for } 2 n \\leq x \\leq 2 n+1 \\\\ 0 & \\text { for } 2 n+1 \\leq x \\leq 2 n+2\\end{cases}$$\n\t(Where $n=0,1,2,........$)is shown below.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=2.5cm,width=6cm]{LT-01}\n\t\\end{figure}\n\tIts Laplace transform $\\tilde{f}(\\mathrm{s})$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{1+e^{-s}}{s}$\n\t\t\\task[\\textbf{b.}]$\\frac{1-e^{-s}}{s}$\n\t\t\\task[\\textbf{c.}]$\\frac{1}{s\\left(1+e^{-s}\\right)}$\n\t\t\\task[\\textbf{d.}]  $\\frac{1}{s\\left(1-e^{-s}\\right)}$\n\t\\end{tasks}\n\\end{exercise}\n\\begin{answer}\n\tGiven function is a periodic function of period $T=2$\n\t\\begin{align*}\n\tL[f(x)] &=\\frac{1}{1-e^{-s T}} \\int_{0}^{T} e^{-s x} f(x) d x=\\frac{1}{1-e^{-2 s}} \\int_{0}^{2} e^{-s x} d x \\\\\n\t&=\\frac{1}{1-e^{-2 s}}\\left[\\int_{0}^{1} e^{-s x} d x\\right]=\\frac{1}{1-e^{-2 s}}\\left(\\frac{1-e^{-s}}{s}\\right) \\\\\n\t&=\\frac{\\left(1-e^{-s}\\right)}{s\\left(1+e^{-s}\\right)\\left(1-e^{-s}\\right)}=\\frac{1}{s\\left(1+e^{-s}\\right)}\n\t\\end{align*}\n\tSo the correct answer is \\textbf{option (c)}\n\\end{answer}\n\\begin{exercise}\n\tThe inverse transform of $\\frac{1}{s^2(s+1)}$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{1}{2} t^{2} e^{-t}$\n\t\t\\task[\\textbf{b.}]$\\frac{1}{2} t^{2}+1-e^{-t}$\n\t\t\\task[\\textbf{c.}]$t-1+e^{-t}$\n\t\t\\task[\\textbf{d.}] $\\frac{1}{2} t^{2}\\left(1-e^{-t}\\right)$ \n\t\\end{tasks}\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t&f(s)=\\frac{1}{s^{2}(s+1)}=\\frac{(s+1)-s(s+1)+s^{2}}{s^{2}(s+1)}=\\frac{1}{s^{2}}-\\frac{1}{s}+\\frac{1}{s+1} \\\\\n\t&\\Rightarrow L^{-1}[f(s)]=t-1+e^{-t}\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{option (c)}\n\\end{answer}\n", "meta": {"hexsha": "594866db5bdf564af0b30bf6fbd4837d1af66930", "size": 8239, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/Laplace Transforms.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CSIR- Mathematical Physics/chapter/Laplace Transforms.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CSIR- Mathematical Physics/chapter/Laplace Transforms.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.3353293413, "max_line_length": 286, "alphanum_fraction": 0.5783468868, "num_tokens": 3721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.7437156118029236}}
{"text": "\\chapter{Introduction}\n\\label{chap:introduction}\n\n\\section{Image Compression}\n\nImage compression is to decrease the size of the image file without dramatically downgarding the quality of the image.\n\nIn this courework, I set out to implement a simulation of the JPEG (Joint Photographic Experts Group) image compression process\\citep{wallace1992jpeg}. The implementation uses MATLAB as frontend interface and Python as backend.\n\n\\section{JPEG Standard}\n\nThe JPEG Still Picture Compression Standard is widely used on modern digital devices, ranging from computers, cameras to smartphones. For a grayscale image, a JPEG CODEC (Encoder and Decoder) typically involves 6 main steps as illustrated in Figure \\ref{fig:codec}.\n\n\\begin{figure}\n\\centering\n\\includegraphics{codec}\n\\caption{Six Main Steps of a JPEG CODEC.}\n\\label{fig:codec}\n\\end{figure}\n\nIn my application, I implement a simplified JPEG CODEC in Python programming language. The CODEC consists of both foward and inverse steps of Discrete Cosine Transform (DCT) and Quantization and gets rid of both forward and inverse steps of Entropy Coding. \n\nSince Entropy Codeing is reversible through Inverse Entropy Coding and does not affect the quality of the image, my implementation should be able to simulate the full effects of JPEG coding on any given still image despite its simplicity.\n\nAs shown in Figure \\ref{fig:app}, given an input grayscale image in uint8 matrix format, the application first crops the image array to multiply of $8$ in both column (width) and row (height). Then, a value of $128$ is subtracted from the image for each pixel value. After that, the matrix is divided into 8 by 8 blocks. Each block then goes through FDCT, Quantization, Inverse Quantization and IDCT individually.  All resulted blocks are placed in their previous position and a new matrix is thus formed. Finally, a value of $128$ is added back to the new matrix to get the compressed grayscale image. \n\n\\begin{figure}\n\\centering\n\\includegraphics{app}\n\\caption{Main Steps of the Application.}\n\\label{fig:app}\n\\end{figure}\n\nFor a color RGB image, the same process is carried out on each color channel respectively.\n\n\\subsection{Discrete Cosine Transform (DCT)}\n\nThe forward step of DCT is computed using the following equation.\n\n\\begin{equation}\nF(u, v) = \\frac{1}{4} C(u) C(v) [\\sum_{x=0}^7 \\sum_{y=0}^7 f(x,y) * cos\\frac{(2x+1)u\\pi}{16} cos\\frac{(2y+1)v\\pi}{16}]\n\\label{equ:fdct}\n\\end{equation}\n\nwhere $C(t) = 1/\\sqrt(2)$ for $t = 0$; $C(t) = 1$ otherwise. Both input $f$ and output $F$ is an 8 by 8 block.\n\nThe inverse step of DCT is computed using the following equation.\n\n\\begin{equation}\nf(x, y) = \\frac{1}{4} [\\sum_{u=0}^7 \\sum_{v=0}^7 C(u) C(v) F(u, v) * cos\\frac{(2x+1)u\\pi}{16} cos\\frac{(2y+1)v\\pi}{16}]\n\\label{equ:idct}\n\\end{equation}\n\nwhere $C(t) = 1/\\sqrt(2)$ for $t = 0$; $C(t) = 1$ otherwise. Both input $F$ and output $f$ is an 8 by 8 block.\n\n\\subsection{Quantization}\n\nThe forward step of Quantization is computed using the following equation.\n\n\\begin{equation}\nF^Q(u, v) = round(\\frac{F(u, v)}{Q(u, v)})\n\\label{equ:fq}\n\\end{equation}\n\nwhere $Q$ is the Quantization Table specified in the JPEG standard. Both input $F$ and ouput $F^Q$ is an 8 by 8 block.\n\nThe inverse step of Quantization is computed using the following equation.\n\n\\begin{equation}\nF(u, v) = F^Q(u, v) * Q(u, v))\n\\label{equ:iq}\n\\end{equation}\n\nwhere $Q$ should be the same as in the forward step. Both input $F^Q$ and ouput $F$ is an 8 by 8 block.\n\nBy default, the value of $Q$ is specfied as followed.\n\n\\begin{equation}\nQ = \n\\begin{bmatrix}\n  16& 11& 10& 16& 24& 40& 51& 61 \\\\\n  12& 12& 14& 19& 26& 58& 60& 55 \\\\\n  14& 13& 16& 24& 40& 57& 69& 56 \\\\\n  14& 17& 22& 29& 51& 87& 80& 62 \\\\\n  18& 22& 37& 56& 68& 109& 103& 77 \\\\\n  24& 35& 55& 64& 81& 104& 113& 92 \\\\\n  49& 64& 78& 87& 103& 121& 120& 101 \\\\\n  72& 92& 95& 98& 112& 100& 103& 99\n\\end{bmatrix}\n\\label{equ:q}\n\\end{equation}\n\n\n\n\n\n\n\n", "meta": {"hexsha": "3df1e9651bd05f59c51a3fd64004a21ff05108e4", "size": 3915, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/Chapter/Introduction.tex", "max_stars_repo_name": "daidahao/Loughborough-University-MSc-Advanced-Computer-Science-Report-Template", "max_stars_repo_head_hexsha": "3296c5cd19ba6ff72dff1e9aa68c3aa901c8fac2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/Chapter/Introduction.tex", "max_issues_repo_name": "daidahao/Loughborough-University-MSc-Advanced-Computer-Science-Report-Template", "max_issues_repo_head_hexsha": "3296c5cd19ba6ff72dff1e9aa68c3aa901c8fac2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/Chapter/Introduction.tex", "max_forks_repo_name": "daidahao/Loughborough-University-MSc-Advanced-Computer-Science-Report-Template", "max_forks_repo_head_hexsha": "3296c5cd19ba6ff72dff1e9aa68c3aa901c8fac2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.5454545455, "max_line_length": 603, "alphanum_fraction": 0.7213282248, "num_tokens": 1240, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.8577681013541611, "lm_q1q2_score": 0.7437156115975112}}
{"text": "\\section{Non-deterministic finite automata}\n\nA \\emph{non-deterministic finite automaton} (\\emph{NFA}) has the\nsame definition as a DFA except that \\(\\delta\\) returns a set of\nstates instead of one state. Let us consider\n\\begin{center}\n\\includegraphics[bb=48 711 188 758]{nfa_01_suffix}\n\\label{nfa_01_suffix}\n\\end{center}\nThere are two out-going edges from state~\\(q_0\\) which are\nlabelled~\\(0\\), hence two states can be reached when~\\(0\\) is input:\n\\(q_0\\) (loop) and~\\(q_1\\). This NFA recognises the language of words\non the binary alphabet whose suffix is~01.\n\nBefore describing formally what is a recognisable language by a NFA,\nlet us consider as an example the previous NFA and the input\n\\(00101\\). Let us represent each transition for this input by an edge\nin a tree where nodes are states of the NFA:\n\\begin{center}\n\\includegraphics[bb=71 651 395 732]{nfa_01_suffix_trace}\n\\end{center}\nA NFA is represented essentially like a DFA: \\(\\mathcal{N} = (Q_N,\n\\Sigma, \\delta_N, q_0, F_N)\\), where the names have the same\ninterpretation as for DFA, except~\\(\\delta_N\\), which returns a subset\nof~\\(Q\\) --~not an element of~\\(Q\\). For example, the NFA above can be\nspecified formally as\n\\begin{equation*}\n\\mathcal{N} = (\\{q_0, q_1, q_2\\}, \\{0, 1\\}, \\delta_N, q_0, \\{q_2\\})\n\\end{equation*}\nwhere the transition function~\\(\\delta_N\\) is given by the transition\ntable\n\\begin{equation*}\n\\begin{array}{r@{}l||c|c}\n\\multicolumn{2}{c||}{\\mathcal{N}} & 0 & 1\\\\\n\\hhline{==::==}\n\\rightarrow & q_0 & \\{q_0, q_1\\} & \\{q_0\\}\\\\\n            & q_1 & \\varnothing  & \\{q_2\\}\\\\\n\\#          & q_2 & \\varnothing  & \\varnothing\n\\end{array}\n\\end{equation*}\nNote that, in the transition table of a NFA, all the cells are filled:\nthere is no transition between two states if and only if the\ncorresponding cell contains~\\(\\varnothing\\). In case of a DFA, the\ncell would remain empty. It is common also to set that in case of the\nempty word input, \\(\\varepsilon\\), both for the DFA and NFA, the state\nremains the same:\n\\begin{itemize*}\n\n  \\item for DFA: \\(\\forall q \\in Q.\\delta_D (q, \\varepsilon) = q\\);\n\n  \\item for NFA: \\(\\forall q \\in Q.\\delta_N (q, \\varepsilon) = \\{q\\}\\).\n\n\\end{itemize*}\nAs we did for the DFAs, we can \\emph{extend the transition function}\n\\(\\delta_N\\) to accept words and not just letters (labels). The\nextended function is noted \\(\\hat{\\delta}_N\\) and defined as\n\\begin{itemize*}\n\n  \\item for all state \\(q \\in Q\\), let \\(\\hat{\\delta}_N (q,\n    \\varepsilon) = \\{q\\}\\);\n\n  \\item for all state \\(q\\ \\in Q\\), all words \\(w \\in \\Sigma^{*}\\),\n    all input \\(a \\in \\Sigma\\), let\n    \\begin{equation*}\n      \\hat{\\delta}_N (q, wa) =\n        \\bigcup_{q' \\in \\hat{\\delta}_N (q, w)}{\\delta_N  (q', a)}.\n    \\end{equation*}\n\n\\end{itemize*}\nThe language \\(L(\\mathcal{N})\\) recognised by a NFA~\\(\\mathcal{N}\\) is\ndefined as\n\\begin{equation*}\nL(\\mathcal{N}) = \\{w \\in \\Sigma^{*} \\; \\lvert \\; \\hat{\\delta}_N (q_0, w)\n\\cap F \\neq \\varnothing\\},\n\\end{equation*}\nwhich means that the processing of the input stops successfully as\nsoon as at least one current state belongs to~\\(F\\).\n\nFor example, let us use~\\(\\hat{\\delta}_N\\) to describe the processing\nof the input \\verb+00101+ by the NFA \\vpageref{nfa_01_suffix}:\n\\begin{enumerate*}\n\n  \\item \\(\\hat{\\delta}_N (q_0, \\varepsilon) = q_0\\),\n\n  \\item \\(\\hat{\\delta}_N (q_0, \\verb+0+) = \\delta_N (q_0, \\verb+0+) =\n    \\{q_0, q_1\\}\\),\n\n  \\item \\(\\hat{\\delta}_N (q_0, \\verb+00+) = \\delta_N (q_0, \\verb+0+)\n    \\cup \\delta_N (q_1, \\verb+0+) = \\{q_0, q_1\\} \\cup \\varnothing =\n    \\{q_0, q_1\\}\\),\n\n  \\item \\(\\hat{\\delta}_N (q_0, \\verb+001+) = \\delta_N (q_0, \\verb+1+)\n    \\cup \\delta_N (q_1, \\verb+1+) = \\{q_0\\} \\cup \\{q_2\\} = \\{q_0,\n    q_2\\}\\),\n\n  \\item \\(\\hat{\\delta}_N (q_0, \\verb+0010+) = \\delta_N (q_0, \\verb+0+)\n    \\cup \\delta_N (q_2, \\verb+0+) = \\{q_0, q_1\\} \\cup \\varnothing =\n    \\{q_0, q_1\\}\\),\n\n  \\item \\(\\hat{\\delta}_N (q_0, \\verb+00101+) = \\delta_N (q_0,\n    \\verb+1+) \\cup \\delta_N (q_1, \\verb+1+) = \\{q_0\\} \\cup \\{q_2\\} =\n    \\{q_0, q_2\\} \\ni q_2\\).\n\n\\end{enumerate*}\nSince~\\(q_2\\) is a final state, in fact \\(F = \\{q_2\\}\\), we get\n\\(\\hat{\\delta}_N (q_0, \\verb+00101+) \\cap F \\neq \\varnothing\\) thus\nthe string \\verb+00101+ is recognised by the NFA.\n", "meta": {"hexsha": "97024433934d20ca3be8bf5ae168bbacd64afab9", "size": 4188, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nfa.tex", "max_stars_repo_name": "rinderknecht/Book", "max_stars_repo_head_hexsha": "6f302ab1319c8ae9b3ea690c45fdb3d2b6fbca16", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "nfa.tex", "max_issues_repo_name": "rinderknecht/Book", "max_issues_repo_head_hexsha": "6f302ab1319c8ae9b3ea690c45fdb3d2b6fbca16", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "nfa.tex", "max_forks_repo_name": "rinderknecht/Book", "max_forks_repo_head_hexsha": "6f302ab1319c8ae9b3ea690c45fdb3d2b6fbca16", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.7777777778, "max_line_length": 72, "alphanum_fraction": 0.6446991404, "num_tokens": 1585, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.8577681013541611, "lm_q1q2_score": 0.7437156115975112}}
{"text": "\\chapter{Brownian Motion}\n\n\\newpage\n\n\\newcommand{\\cov}{\\mathrm{Cov}}\n\\newcommand{\\var}{\\mathrm{Var}}\n\n\n\\section{Definition of Brownian Motions}\n    \\subsection{Introduction}\n        We start from a random walk on real axis, but this time we move every $\\Delta t$ time. So in time interval $t$ we take $t/\\Delta t$ steps. Let $\\delta$ be the step size, then\n        \\[ X(t) = \\delta(X_1 + X_2 + \\cdots + X_{t/\\Delta t}) \\]\n        where $X_i \\in \\{0,1\\}$ with mean $0$ and variance $1$.\n\n        Then\n        \\[ \\mathbb{E}[X(t)] = 0 \\qquad Var[X(t)] = \\delta^2\\frac{t}{\\Delta t} \\]\n\n        What happens if $\\Delta t \\to 0$? Notice that if $\\Delta t$ exists in $Var[X(t)]$, then it either goes to 0 or goes to infinity and the problem is meaningless. So we set $\\delta = \\sigma \\sqrt{\\Delta t}$ and therefore\n        \\[ Var[X(t)] = \\sigma^2 t \\]\n\n        Recall the Central Limit Theorem in \\textsc{Probability and Statistics}\n        \\begin{theorem}[Central Limit Theorem]\\label{thm:CentralLimitTheorem}\n            Let $X_1,X_2,\\dots$ be a sequence of i.i.d. random variables, with mean $\\mu$ and variance $\\sigma^2$. Then\n            \\[ \\frac{\\sum_iX_i - n\\mu}{\\sigma\\sqrt{n}} \\sim \\mathcal{N}(0,1) \\]\n        \\end{theorem}\n\n        Let $Y_i = \\delta X_i$. $Var[Y_i] = \\sigma^2 \\Delta t$. Then\n        \\[ X(t) = \\sum_{k=0}^{t/\\Delta t} Y_k \\sim \\sigma \\sqrt{\\Delta t}\\cdot\\sqrt{\\frac{t}{\\Delta t}} \\mathcal{N}(0,1) = \\mathcal{N}(0, \\sigma^2 t) \\]\n        \n        \\begin{remark}\n            This result implies that the motion $X(t)$ in different time intervals are independent, i.e. $\\forall t_1 < t_2 < \\cdots < t_n$,\n            \\[ X(t_n)-X(t_{n-1}), \\dots, X(t_2)-X(t_1), X(t_1) \\]\n            are independent.\n\n            Further, $X(t+s)-X(t)$ depends only on $s$.\n\n            This is very similar to the property of a Poisson Process.\n        \\end{remark}\n\n    \\subsection{Formal Definition}\n        \\begin{definition}[Standard Brownian Motion]\\label{def:BrownianMotionStd}\n            $\\{W(t):t>0\\}$ is a \\textbf{Standard Brownian Motion} Process if\n            \\begin{enumerate}\n                \\item $W(0) = 0$.\n                \\item (Independent Increment) $\\forall t_1 < t_2 < \\cdots < t_n$, $W(t_n)-W(t_{n-1}), \\dots, W(t_2)-W(t_1)$, $W(t_1)$ are independent.\n                \\item (Stationary) $\\forall t,s \\ge 0$, $W(t+s) - W(t)$ only depends on $s$, and has a normal distribution $\\mathcal{N}(0, s)$\n                \\item Continuous Path\n            \\end{enumerate}\n        \\end{definition}\n\n    \\subsection{Another Characterizationo of SBM}\n        \\begin{definition}[Multivariate Gaussian Distribution]\n            A vector $(X_1, \\dots, X_n)$ has a Gaussian Distribution if (and only if)\n            \\[ \\forall a_1, \\dots, a_n \\qquad \\sum_{i=1}^n a_iX_i \\]\n            has a (Univariate) Gaussian Distribution.\n\n            Or equivalently\n            \\[ f(X) = (2\\pi)^{-n/2}|\\det\\Sigma|^{-1/2}\\exp\\left\\{(x-\\mu)^T\\Sigma^{-1}(x-\\mu)\\right\\} \\]\n        \\end{definition}\n        \\begin{remark}\n            The marginal probability given $X_i$ is also a Gaussian Distribution.\n        \\end{remark}\n\n        \\begin{definition}[Gaussian Process]\\label{def:GaussianProcess}\n            A stochastic process $\\{W(t)\\}_{t \\ge 0}$ is a \\textbf{Gaussian Process} if\n            \\[ \\forall n, \\forall t_1 \\le t_2 \\le \\cdots \\le t_n, \\qquad (W(t_1), W(t_2), \\dots, W(t_n))\\]\n            has a Guassian Distribution.\n        \\end{definition}\n\n        \\begin{definition}[Definition of SBM via Gaussian Process]\\label{def:BrownianMotionStdAlt}\n            A stochastic process $\\{W(t)\\}$ is a Standard Brownian Motion if\n            \\begin{enumerate}\n                \\item $W(t)$ is a Guassian Process.\n                \\item $W(t)$ has mean zero. $\\forall s$, $\\mathbb{E}[W(s)] = 0$.\n                \\item $\\forall s \\le t$, $Cov(W(s), W(t)) = s$. ($Cov(W(s), W(t))$ equals to $s$ if $s < t$ else $t$)\n            \\end{enumerate}\n        \\end{definition}\n        \\begin{remark}\n            This alternative definition is more often used to justify that a process is a Brownian motion. The only difficulty is to compute the covariance.\n\n            As a reminder, the covariance is given by\n            \\[ Cov(X,Y) = \\mathbb{E}[(X-\\mathbb{E}[X])(Y-\\mathbb{E}[Y])] \\]\n        \\end{remark}\n        \\begin{proof}\n            We now verify that Definition \\ref{def:BrownianMotionStdAlt} is equivalent to \\ref{def:BrownianMotionStd}.\n            \n            $\\Rightarrow$: A SBM satisfies definition \\ref{def:BrownianMotionStdAlt}. To see this, we show that any linear combination of $W(s)$ and $W(t)$ is a Gaussian. $\\forall a,b$,\n            \\begin{align*}\n                aW(s) + bW(t) &= aW(s) + b(W(t) - W(s) + W(s))\\\\\n                &= (a+b)W(s) + b(W(t)-W(s))\n            \\end{align*}\n            This is the sum of two independent Gaussians, so the sum is still a Gaussian, and we are done.\n\n            $W(t)$ has mean zero is straightforward by definition of SBM. So we only need to check condition 3.\n\n            \\begin{align*}\n                Cov(W(s), W(t)) &= Cov(W(s), W(t) - W(s) + W(s))\\\\\n                &= Var(W(s)) + Cov(W(s), W(t) - W(s))\\\\\n                &=s\n            \\end{align*}\n            Notice that the latter term is zero by the independent increment property.\n        \\end{proof}\n\n        \\subsubsection{A Simple Example}\n            If $W(t)$ is a SBM, then $X(t)=tW(1/t)$ is also a SBM.\n            \\begin{proof}\n                We only need to check definition \\ref{def:BrownianMotionStdAlt}. The first two conditions are easy to check. We consider the covariance.\n                \\begin{align*}\n                    Cov(X(s), X(t)) &= Cov(sW(1/s),tW(1/t))\\\\\n                    &= stCov(W(1/s), W(1/t))\\\\\n                    &= st\\cdot\\frac{1}{t} = s\n                \\end{align*}\n            \\end{proof}\n\n    \\subsection{Non-Standard Brownian Motions}\n        \\begin{definition}[General Brownian Motion]\n            $\\{X(t)\\}$ is a $(\\mu, \\sigma^2)$ Brownian Motion if\n            \\[ X(t) = X(0) + \\mu t + \\sigma W(t) \\]\n        \\end{definition}\n\n\n\\section{First Passage Time and Reflection Principle}\n    Let $W(t)$ be a Brownian Motion. Let $\\tau_b$ be the first time for the motion to pass some point $b$,\n    \\[ \\tau_b \\triangleq \\inf\\left\\{ t \\ge 0 : W(t) > b \\right\\} \\]\n\n    We are interested in $\\mathbb{P}[\\tau_b < t]$. $\\forall t$\n    \\begin{align*}\n        \\mathbb{P}[\\tau_b < t] &= \\mathbb{P}[\\tau_b < t, W(t) > b] + \\mathbb{P}[\\tau_b < t, W(t) \\le b] \\quad \\text{(Total Probability)}\\\\\n        &= \\mathbb{P}[W(t) > b] + \\mathbb{P}[W(t) < b | \\tau_b < t]\\cdot\\mathbb{P}[\\tau_b < t]\\\\\n    \\end{align*}\n\n    Notice that $W(t) > b$ implies $\\tau_b < t$, so\n    \\[ \\mathbb{P}[\\tau_b < t, W(t) > b] = \\mathbb{P}[W(t) > b] = 1 - \\Phi(\\frac{b}{\\sqrt{t}}) \\]\n\n    Further notice that $\\mathbb{P}[W(t) < b | \\tau_b < t]$ equals exactly to $1/2$, because the path is continuous, so that starting from $W(\\tau_b) = b$, the motion is \\emph{equally likely} to go beyond or below $b$. This property is referred to as the \\textbf{Reflection Principle}.\n\n    Plugging in all the results and solving for $\\mathbb{P}[\\tau_b < t]$ yields\n    \\[ \\mathbb{P}[\\tau_b < t] = 2 \\left( 1 - \\Phi\\left(\\frac{b}{\\sqrt{t}}\\right) \\right) \\]\n\n\n\\section{Brownian Bridge}\n    \\subsection{Conditional Distributions for Brownian Motion}\n        In this section, we fix $W(u) = x$, i.e. we add a restriction that at time $u$ the process must be at $x$. We are interested in the distribution of $W(t)$ in time interval $[0,u]$, conditioned on $W(u)=x$.\n\n        The resulting process still has a Gaussian distribution, so we only need to compute the mean and covariance.\n\n        Before we formally start, we first introduce a tool.\n        \\begin{proposition}\\label{prop:LemmaOfBrownianBridge}\n            \\[ W(t) - (t/u)W(u) \\]\n            is independent of $W(u)$\n        \\end{proposition}\n        \\begin{proof}\n            To see this, we only need to show that the covariance $\\cov[W(t)-(t/u)W(u), W(u)] = 0$.\n            \\begin{align*}\n                \\cov[W(t) - (t/u)W(u), W(u)] &= \\cov[W(t),W(u)] - \\frac{t}{u}\\cov[W(u), W(u)]\\\\\n                &= t - \\frac{t}{u} \\cdot u = 0\n            \\end{align*}\n            So we are done.\n        \\end{proof}\n\n        With Proposition \\ref{prop:LemmaOfBrownianBridge} we shall continue.\n\n        \\begin{align*}\n            0 &= \\mathbb{E}\\left[ W(t) - \\frac{t}{u}W(u) \\right]\\\\\n            &= \\mathbb{E}\\left[ W(t) - \\frac{t}{u} W(u) \\middle| W(u) \\right]\\\\\n            &= \\mathbb{E}\\left[ W(t) \\middle| W(u) \\right] - \\frac{t}{u}\\mathbb{E}[W(u) | W(u)]\\\\\n            &= \\mathbb{E}\\left(W(t) | W(u)\\right) - \\frac{t}{u}W(u)\n        \\end{align*}\n\n        Therefore\n        \\[ \\mu = \\mathbb{E}[W(t)|W(u)] = \\frac{t}{u}W(u) \\]\n\n        We then move on to compute the covariance, $\\forall t \\in [0, u]$,\n        \\begin{align*}\n            \\var[W(t) | W(u)] &= \\mathbb{E}[(W(t) - \\mathbb{E}[W(t)|W(u)])^2 | W(u)]\\\\\n            &= \\mathbb{E}[(W(t)- \\frac{t}{u}W(u))^2 | W(u)]\\\\\n            &= \\mathbb{E}[(W(t) - \\frac{t}{u}W(u))^2] \\quad \\text{(By Proposition \\ref{prop:LemmaOfBrownianBridge})}\\\\\n            &= \\mathbb{E}[W^2(t)] - \\frac{2t}{u}\\mathbb{E}[W(t)W(u)] + \\frac{t^2}{u^2}\\mathbb{E}[W^2(u)]\\\\\n            &= t - \\frac{2t}{u}t + \\frac{t^2}{u^2}u\\\\\n            &= \\frac{ut - t^2}{u} = \\frac{t(u-t)}{u}\n        \\end{align*}\n        \\begin{remark}\n            Since the process is constrained at $t=0$ and $t=u$, the result has a straightforward intuition that the process is more likely to have large variances in the middle of the process.\n        \\end{remark}\n\n        \\begin{align*}\n            \\cov[W(s), W(t) | W(u)] &= \\mathbb{E}[W(s) \\cdot W(t) | W(u)] - \\mathbb{E}[W(s) | W(u)] \\cdot \\mathbb{E}[W(t) | W(u)]\\\\\n        \\end{align*}\n        The last two terms are exactly the expectation (mean value) computed previously, so we only need to deal with the first term.\n\n        \\begin{align*}\n            \\mathbb{E}[W(s)W(t)|W(u)] &= \\int y \\mathbb{E}[W(s)|W(t)=y, W(u)]\\cdot p_{W(t)}(y|W(u)) \\mathrm{d}y\\\\\n            &= \\int y \\mathbb{E}[W(s) | W(t) = y] \\cdot p[y|W(u)]\\mathrm{d}y \\quad \\text{(By Independent Increment)}\\\\\n            &= \\int y \\cdot \\frac{s}{t}y p(y|W(u))\\mathrm{d}y\\\\\n            &= \\frac{s}{t}\\mathbb{E}[W^2(t)|W(u)]\n        \\end{align*}\n        \n        Plug this term back,\n        \\[\n            \\cov[W(s), W(t) | W(u)] = \\frac{s}{t}\\mathbb{E}[W^2(t)|W(u)] - \\frac{st}{u^2}W^2(u)\n        \\]\n\n        where\n        \\[ \\mathbb{E}[W^2(t)|W(u)] = \\mathbb{E}[W(t)|W(u)]^2 + \\var[W(t)|W(u)] = \\frac{t(u-t)}{u} + \\frac{t^2}{u^2}W^2(u) \\]\n\n        so the final result is\n        \\[ \\cov[W(s), W(u) | W(u)] = \\frac{s(u-t)}{u} \\]\n\n    \\subsection{Standard Brownian Bridge}\n        \\begin{definition}[Standard Brownian Bridge]\\label{def:BrownianBridgeStd}\n            A Gaussian Process is called a \\textbf{Standard Brownian Bridge} if\n            \\begin{enumerate}\n                \\item $X(0) = X(1) = 0$\n                \\item $\\cov[X(s), X(t)] = s(1-t)$\n            \\end{enumerate}\n        \\end{definition}\n        \\begin{remark}\n            The Brownian Bridge can be directly constructed from a Brownian Motion by\n            \\[ X(t) = W(t) - tW(1) \\]\n        \\end{remark}\n\n    \\subsection{First Passage Time of Brownian Bridge}\n        In this section we consider the first passage time of a Brownian Bridge.\n        \\[ \\tau_b \\triangleq \\inf\\left\\{ t \\ge 0 : W(t) > b \\right\\} \\]\n\n        We assume $x < b$, or otherwise $\\mathbb{P}[\\tau_b < t] = 1$. Consider $\\mathbb{P}[\\tau_b < t | W(t) = x]$, that is, the probability that we ever reached $b$ before we arrive at $x$ at time $t$.\n\n        By definition of conditional probability,\n        \\[ \\mathbb{P}[\\tau_b < t | W(t) =  x] = \\frac{\\mathbb{P}[\\tau_b < t, W(t) = x]}{\\mathbb{P}[W(t) = x]} \\]\n\n        We then get a $0/0$ because the probability that a continuous random variable gets a certain value is 0. Instead, we apply some informal notations. Let $\\mathrm{d}x$ be a small interval around $x$, we compute\n        \\[ \\frac{\\mathbb{P}[\\tau_b < t, W(t) \\in \\mathrm{d}x]}{\\mathbb{P}[W(t) \\in \\mathrm{d}x]} \\]\n\n        Denominator\n        \\begin{align*}\n            \\mathbb{P}[W(t) \\in \\mathrm{d}x] &= \\mathbb{P}[\\frac{1}{\\sqrt{u}}W(t) \\in \\frac{\\mathrm{d}x}{\\sqrt{u}}]\\\\\n            &= \\Phi(\\frac{\\mathrm{d}x}{\\sqrt{u}})\\\\\n            &= \\frac{1}{\\sqrt{u}}\\phi(\\frac{x}{\\sqrt{u}})\\mathrm{d}x\n        \\end{align*}\n\n        Numerator\n        \\begin{align*}\n            \\mathbb{P}[\\tau_b < t, W(t) \\in \\mathrm{d}x] &= \\mathbb{P}[\\tau_b < t] \\mathbb{P}[W(t) \\in \\mathrm{d}x | \\tau_b < t]\\\\\n            &= \\mathbb{P}[\\tau_b < t]\\mathbb{P}[W(t) \\in 2b - \\mathrm{d}x | \\tau_b < t]\\\\\n            &= \\mathbb{P}[W(t) \\in 2b-\\mathrm{d}x, \\tau_b < t]\n        \\end{align*}\n\n        Notice that $W(t) \\in 2b-\\mathrm{d}x$ implies $\\tau_b < t$.\n        \\begin{align*}\n            \\mathbb{P}[\\tau_b < t, W(t) \\in \\mathrm{d}x] &= \\mathbb{P}[W(t) \\in 2b-\\mathrm{d}x] = \\frac{1}{\\sqrt{u}}\\phi\\left( \\frac{2b-x}{\\sqrt{u}}\\mathrm{d}x \\right)\n        \\end{align*}\n\n        The result is\n        \\[ \\mathbb{P}[\\tau_b < u | W(u) = x] = \\exp\\left\\{ \\frac{-2b(b-x)}{u} \\right\\} \\]\n\n    \\subsection{Application to Test for Uniformity}\n        Suppose we have a series of i.i.d. random variables $U_1, \\dots, U_n$ having some distribution $F$ on $[0,1]$. We want to test if $F(t)=\\mathbb{P}[U < t]=t$, i.e. whether $F$ is a uniform distribution.\n\n        We define\n        \\[ F_n(t) = \\frac{1}{n} \\sum_{i=1}^n \\mathbb{I}[U_i < t] \\]\n\n        \\subsubsection{The Kolmogorov-Smirnov Test}\n        For some large enough $n$, reject if\n        \\[ F_n(t) - t \\ge b \\]\n        for some $t \\in [0,1]$ and accept otherwise.\n\n        \\subsubsection{Choice of Parameters}\n        We want to choose a proper $b$ so that the probability that we mistakenly reject a uniform distribution is small enough.\n\n        Assume $F(t)=t$, we hope the algorithm outputs accept. By Central Limit Theorem, $F_n(t)$ has a normal distribution. For a fixed $t$, we have\n        \\[ \\var[\\mathbb{I}[U_i < t]] = t(1-t) \\]\n\n        Let\n        \\[ X_n(t) = \\sqrt{n}(F_n(t)-t) \\]\n\n        Then by Central Limit Theorem,\n        \\[ X_n(t) \\longrightarrow \\mathcal{N}(0, t(1-t)) \\]\n\n        Using a Multivariate CLT, we actually have\n        \\[ (X_n(t_1), X_n(t_2)) \\longrightarrow \\mathcal{N}(0,t_1(1-t_2)) \\]\n        where $t_1(1-t_2)$ is a covariance matrix.\n\n        Therefore\n        \\[ \\cov[\\mathbb{I}[U < t_1], \\mathbb{I}[U < t_2]] = t_1(1-t_2) \\]\n\n        Which implies that $(X_n(t_1), X_n(t_2), \\dots, X_n(t_k))$ converges (in distribution) to a standard Brownian Bridge. Using the conclusion in previous section, we can conclude that\n        \\[ \\mathbb{P}[F_n(t)-t \\ge b] = e^{-2b^2} \\]\n", "meta": {"hexsha": "9d0f5d27ccb118a10a6141654076198095b339d7", "size": 14782, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Stochastic Processes/BrownianMotion.tex", "max_stars_repo_name": "YBRua/CourseNotes", "max_stars_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-20T10:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T08:15:15.000Z", "max_issues_repo_path": "Stochastic Processes/BrownianMotion.tex", "max_issues_repo_name": "YBRua/CourseNotes", "max_issues_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Stochastic Processes/BrownianMotion.tex", "max_forks_repo_name": "YBRua/CourseNotes", "max_forks_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T11:31:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T11:31:00.000Z", "avg_line_length": 51.3263888889, "max_line_length": 285, "alphanum_fraction": 0.5454606954, "num_tokens": 4947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7437156100212651}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{One-sample tests}\\label{sec:np_one_sample_tests}\n\n%-------------------------------------------------\n\\subsection{The sign test}\\label{sec:signtest}\n\nLet $X$ be a continuous random variable with an unknown median $\\eta$. The sign test is a non-parametric method for testing hypotheses about $\\eta$.\n\n%%-----------------------------\n%\\subsection{The median}\n%The non-parametric methods we consider are based on the \\emph{median} of an unknown distribution.\n%\n%\\begin{definition}\n%A \\emph{median} of a random variable $X$ is a real number $\\eta$ satisfying\n%\\[\n%\\prob(X\\leq\\eta)\\,\\geq\\frac{1}{2} \\quad\\text{and}\\quad \\prob(X\\geq\\eta)\\,\\geq\\frac{1}{2}.\n%\\]\n%If $X$ is a continuous random variable, its median is uniquely defined,\n%\\[\n%\\prob(X\\leq\\eta) = \\prob(X\\geq\\eta) = \\frac{1}{2}.\n%\\]\n%\\end{definition}\n%\n%\\begin{example}\n%Consider the random sample $\\{1, 2, 2, 2, 3, 14\\}$.\n%\\bit\n%\\it The sample median is $\\hat{\\eta} = 2$; the sample mean is $\\hat{\\mu}  = 4$.\n%\\eit\n%In this case, $\\hat{\\eta}$ provides a better indicator of centrality than $\\hat{\\mu}$.\n%\\end{example}\n\n%-----------------------------\n\\subsubsection{The test statistic}\n\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the distribution of $X$ and consider the null hypothesis $H_0:\\eta=\\eta_0$ against a suitable alternative. If $H_0$ is correct then approximately half of the observations should be smaller than $\\eta_0$ and approximately half should be larger than $\\eta_0$.\n\n\\begin{definition}\nThe sign test statistic $S^{+}_n$ is the number of observations larger than $\\eta_0$: \n\\[\nS^{+}_n = \\sum_{i=1}^n Z_i \\quad\\text{where}\\quad Z_i=I(X_i>\\eta_0).\n\\]\n\\end{definition}\n\nWe also define the complementary statistic $S^{-}_n = \\displaystyle\\sum_{i=1}^n (1-Z_i)$ which is the number of observations smaller than $\\eta_0$. Note that $S^{+}_n + S^{-}_n = n$.\n\n\\bigskip\nBecause the observations are independent, the distribution of our test statistic under $H_0$ is\n\\[\nS^{+}_n\\sim\\text{Binomial}(n,0.5).\n\\]\n\\bit\n\\it Small values of $S^{+}_n$ support the alternative $H_1:\\eta < \\eta_0$.\n\\it Large values of $S^{+}_n$ support the alternative $H_1:\\eta > \\eta_0$.\n\\eit\n\n% example: sign test (one sample)\n\\begin{example}\nThe following are measurements of the breaking strength of a certain kind of two-inch cotton ribbon.\n\\[\\begin{array}{cccccccccc}\n163 & 165 & 158 & 189 & 161 & 171 & 158 & 151 & 169 & 162 \\\\\n163 & 139 & 172 & 165 & 148 & 166 & 172 & 163 & 187 & 173 \\\\\n\\end{array}\\]\nConduct a sign test to decide between $H_0:\\eta=160$ and $H_1:\\eta>160$ at significance level $\\alpha=0.05$. \n\\end{example}\n\n\\begin{solution}\nFirst we must assume that the distribution of the breaking strength is continuous.\n\\small\n\\[\\begin{array}{cccccccccc} \\hline\n163 & 165 & 160 & 189 & 161 & 171 & 158 & 151 & 169 & 162 \\\\\n+ & + & - & + & + & + & - & - & + & + \\\\ \\hline\n163 & 139 & 172 & 165 & 148 & 166 & 172 & 163 & 187 & 173 \\\\\n+ & - & + & + & - & + & + & + & + & + \\\\ \\hline\n\\end{array}\\]\n\\normalsize\n\\bit\n\\it We have $n=20$ signs: under the null hypothesis, $S^{+}_n\\sim\\text{Binomial}(20,0.5)$.\n\\it The observed value of the test statistic $s^{+}_n=15$. \n\\it From tables we find that $\\prob_{H_0}(S^{+}_n\\geq 15) = 1 - 0.9793 = 0.0207$ approx. \n\\it Thus we reject $H_0$ at significance level $\\alpha=0.05$.\n\\eit\n\\end{solution}\n\n% example: sign test (paired samples)\n\\begin{example}[Sign test for paired samples]\nTo evaluate a new traffic-control system, the number of accidents that occurred at 12 dangerous junctions were recorded during the four weeks prior to the installation of the new system, and for the four weeks after its installation. The following data were obtained.\n\\small\n\\[\\begin{array}{|l|rrrrrrrrrrrr|} \\hline\n\\text{Junction}\t& \\phantom{1}1 & \\phantom{1}2 & \\phantom{1}3 & \\phantom{1}4 & \\phantom{1}5 & \\phantom{1}6 & \\phantom{1}7 & \\phantom{1}8 & \\phantom{1}9 & 10 & 11 & 12 \\\\ \\hline\n\\text{Before}\t& 3 & 5 & 2 & 3 & 3 & 3 & 0 & 4 & 1 &  6 &  4 &  1 \\\\\n\\text{After}\t& 1 & 2 & 2 & 2 & 2 & 0 & 2 & 3 & 3 &  4 &  1 &  0 \\\\ \\hline\n\\end{array}\\]\n\\normalsize\nUse a sign test to evaluate the claim that the new system is more effective than the old system.\n\\end{example}\n\n\\begin{solution}\nLet $\\eta_1$ and $\\eta_2$ denote the median number of accidents before and after the new system was installed, respectively. We test $H_0:\\eta_1=\\eta_2$ against $H_1:\\eta_1 > \\eta_2$.\n\\[\\begin{array}{|l|rrrrrrrrrrrr|} \\hline\n\\text{Junction}\t& \\phantom{1}1 & \\phantom{1}2 & \\phantom{1}3 & \\phantom{1}4 & \\phantom{1}5 & \\phantom{1}6 & \\phantom{1}7 & \\phantom{1}8 & \\phantom{1}9 & 10 & 11 & 12 \\\\ \\hline\n%\\text{Before}\t\t& 3 & 5 & 2 & 3 & 3 & 3 & 0 & 4 & 1 &  6 &  4 &  1 \\\\\n%\\text{After}\t\t& 1 & 2 & 2 & 2 & 2 & 0 & 2 & 3 & 3 &  4 &  1 &  0 \\\\ \\hline\n\\text{Difference}\t& + & + & 0 & + & + & + & - & + & - &  + &  + &  + \\\\ \\hline\n\\end{array}\\]\n\n\\bit\n\\it We have $n=11$ observations (one discarded) so $S^{+}_n\\sim\\text{Binomial}(11,\\theta)$ under $H_0$.\n\\it The value of the test statistic is $s^{+}_n = 9$.\n\\it Under $H_0:\\theta=0.5$, from tables we obtain $\\prob_{0.5}(S^{+}_n\\geq 9) = 1 - 0.9673 = 0.0327$.\n\\it At $\\alpha=0.05$ we reject $H_0$ and conclude that the system has indeed reduced the number of accidents.\n\\it At $\\alpha=0.01$ we retain $H_0$ and conclude that there is insufficient evidence to support the claim.\n\\eit\n\\end{solution}\n\n%-----------------------------\n\\subsubsection{Normal approximation}\n\nBy the central limit theorem, if $X\\sim\\text{Binomial}(n,\\theta)$ then for large $n$,\n\\[\nX\\sim N\\big(n\\theta,n\\theta(1-\\theta)\\big) \\text{\\quad approx.}\n\\]\nIf $H_0:\\theta=0.5$ is correct, the distribution of the test statistic is $S^{+}_n\\sim N(n/2,n/4)$ approx.\n\n% continuity correction\n\\begin{definition}[The continuity correction]\nLet $X$ be a discrete random variable, taking values in the set $\\{0,\\pm 1,\\pm 2,\\ldots\\}$. If the distribution of a continuous random variable $Y$ is taken as an approximation of the distribution of $X$, we set\n\\[\n\\prob(X=k) = \\prob\\left(k - \\frac{1}{2} < Y < k + \\frac{1}{2}\\right).\n\\] \n\\end{definition}\nThis means that \n\\bit\n\\it $\\prob(X < k) = \\prob(Y\\leq k-1/2)$ and $\\prob(X\\leq k) = \\prob(Y\\leq k+1/2)$,\n\\it $\\prob(X\\geq k) = \\prob(Y\\geq k-1/2)$ and $\\prob(X > k) = \\prob(Y\\geq k+1/2)$\n\\eit\n\n% example: sign test (large sample)\n\\begin{example}[Sign test for large samples]\nThe following data are the amounts of sulphur oxide (in tonnes) emitted by a large industrial plant over a period of 40 days.\n\\[\\begin{array}{cccccccccc}\n17 & 15 & 20 & 29 & 19 & 18 & 22 & 25 & 27 &  9 \\\\\n24 & 20 & 17 &  6 & 24 & 14 & 15 & 23 & 24 & 26 \\\\\n19 & 23 & 28 & 19 & 16 & 22 & 24 & 17 & 20 & 13 \\\\\n19 & 10 & 23 & 18 & 31 & 13 & 20 & 17 & 24 & 14\n\\end{array}\\]\nConstruct a sign test of size $\\alpha=0.01$ to evaluate $H_0:\\eta=21.5$ against $H_1:\\eta<21.5$.\n\\end{example}\n\n\\begin{solution}\nAssume that sulphur oxide emissions per day has a continuous distribution. The sign test statistic is\n\\[\nS^{+}_n = \\sum_{i=1}^n I(X_i>21.5).\n\\]\nand because the sample is relatively large, $S^{+}_n\\sim N(n/2,n/4)$ approx.\n\n\\bigskip\nUsing the continuity correction (for a lower-tailed test), we have the test statistic\n\\[\nZ = \\displaystyle\\frac{(S^{+}_n+1/2)-n/2}{\\sqrt{n/4}} \\sim N(0,1) \\text{ approx.}\n\\]\nHere, we have $n=40$ and $s^{+}_n=16$ (the number values exceeding $\\mu_0 = 21.5$), so the value of the test statistic is\n\\[\nz = \\frac{16.5 - 20}{\\sqrt{10}} = -1.1068.\n\\]\nFrom tables, the (lower-tail) critical value of $N(0,1)$ at $\\alpha=0.01$ is $z_c = \\Phi^{-1}(0.01) = -2.33$ approx. Thus we retain $H_0$ and conclude that the median amount of sulphur oxide emitted by the plant is not less than $21.5$ tons per day.\n\\end{solution}\n\n\\begin{exercise}\n\\begin{questions}\n\n\\question % flies\nThe biting rate of a particular species of fly was investigated. The biting rate is defined as the number of flies biting a volunteer during $15$ minutes of exposure. The species is known to have a median biting rate of $5$ bites per $15$ minutes. It is hypothesized that the median biting range is higher in bright, sunny weather. To test the hypothesis, a total of $122$ volunteers were exposed to flies on a sunny day, of which $95$ experienced biting rates greater than $5$.\nState the null and alternative hypotheses for the test, and state your conclusion for $\\alpha = 0.01$.\n\\begin{answer}\nLet $\\eta$ deonte the (true) median biting rate. \n\\par\nThe hypothesis test is $H_0:\\eta=5$ against, $H_1:\\eta>5$.\n\\par\nThe test statistic is $S_n^{+} = 95$ where $n=122$. \n\n\\bigskip\nUnder the null hypothesis, $\\prob(S_{122}^{+}\\geq 95) = \\prob\\big[\\text{Binomial}(122,0.5) \\geq 95\\big]$.\n\n\\bigskip\nSince $n$ is large, we use the normal approximation: under the null hypothesis,\n\\[\nZ = \\frac{(S_n^{+}-1/2) - n/2}{\\sqrt{n/4}} \\sim N (0,1) \\quad\\text{approx.}\n\\]\nIn this case, the test statistic is\n\\[\nz = \\frac{94.5 - 61}{\\sqrt{30.5}} = 6.0659.\n\\]\nAn approximate $p$-value is $\\prob(Z>6.6059) < 0.001$, so we reject $H_0$ at $\\alpha=0.01$.\n\\end{answer}\n\n\\question % sign-test v z-test\nLet $X\\sim N (\\mu,1)$ where $\\mu$ is unknown and suppose we wish to test the simple null hypothesis $H_0:\\mu=0$ against the simple alternative $H_1:\\mu=0.5$. A random sample of 9 observations is taken from the distribution of $X$ and the number $S^{+}$ of positive values is counted.\n\\ben\n\\it % << (i)\nA sign test rejects the null hypothesis if $S^{+}$ exceeds $6$. Find the size and power of the test.\n\\it % << (ii)\nConstruct a test based on the sample mean of the observations which has the same significance level as the sign test described above. Find the power of the test, and explain why this is higher than the power of the sign test.\n\\een\n\n\\begin{answer}\n\\ben\n\\it % << (i)\nUnder the null hypothesis, $S^{+}\\sim\\text{Binomial}(9, 0.5)$. The size of the test is\n\\[\n\\alpha = \\prob_{\\mu_0}(S^{+}>6) = \\prob\\big(\\text{Binomial}(9,0.5)>6\\big) \\approx 0.0898 \\text{ (from tables)}.\n\\]\nUnder $H_1:\\mu=0.5$ we have $X\\sim N(0.5,1)$, so the probability that an observataion takes a positive value under $H_1$ is\n\\[\n\\prob_{\\mu_1}(X > 0) \n\t= \\prob\\big(X > 0 \\text{ where } X\\sim N(0.5,1)\\big) \n\t= \\prob\\big(Z > -0.5 \\text{ where } Z\\sim N(0,1)\\big) \n\t\\approx 0.69146 \\quad\\text{(from tables).}\n\\]\nThe power of the test to detect the alternative $H_1:\\mu=0.5$ is therefore\n\\[\n\\gamma(0.5) = \\prob_{\\mu_1}(S^{+}>6) = \\prob\\big[\\text{Binomial}(9,0.6915) > 6\\big] = \\prob\\big[\\text{Binomial}(9,0.0.3085) < 3\\big] \n\\]\nwhere the second equality follows by the fact that \n\\[\n\\prob\\big[\\text{Binomial}(n,p) > k\\big] = \\prob\\big[\\text{Binomial}(n,1-p) < n-k\\big].\n\\]\nFrom tables, we find that \n\\[\n\\prob[\\text{Binomial}(9,0.30)\\leq 2\\big] \\approx 0.4628  \\quad\\text{and}\\quad \\prob[\\text{Binomial}(9,0.35)\\leq 2\\big] \\approx 0.3373.\n\\]\nTo find the required probability, we interpolate between these values:\n\\begin{align*}\n\\prob\\big[\\text{Binomial}(9,0.3085)\\leq 2\\big]\n\t& \\approx \\prob\\big[\\text{Binomial}(9,0.30)\\leq 2\\big] \\\\\n\t& \\qquad + \\left(\\frac{0.3085 - 0.30}{0.35 - 0.30}\\right)\\left(\\prob\\big[\\text{Bino}(9,0.35)\\leq 2\\big]-\\prob\\big[\\text{Bino}(9,0.30)\\leq 2\\big]\\right) \\\\\n\t& = 0.4628 - (0.1708\\times 0.1255) \\\\\n\t& = 0.4414.\n\\end{align*}\t\nAlternatively, we can use the normal approximation: if $Y\\sim \\text{Binomial}(9,0.6915)$ then $\\expe(Y) = 6.2231$ and $\\var(Y) = 1.9201$. Using the continuity correction,\n\\[\n\\prob\\big[\\text{Binomial}(9,0.6915) > 6\\big]\n\t\\approx \\prob\\left[ N (0,1) > \\frac{6.5-6.2231}{\\sqrt{1.9201}}\\right]\n\t= \\prob\\big(N(0,1)> 0.1998\\big) \n%\t= 1 - 0.5793 \n\t\\approx 0.4207.\n\\]\t\n\\item % (ii)\nLet $\\bar{X}$ denote the sample mean, and consider the $z$-test, where $H_0:\\mu=0$ is rejected in favour of $H_1:\\mu=0.5$ if $\\bar{X} > c$, with $c$ chosen to give the required significance level. Here we require $\\alpha = 0.0898$, so we need\n\\[\n\\prob_{\\mu_0}(\\bar{X} > c) = 0.0898.\n\\]\nUnder $H_0$ we have $X_i\\sim N (0,1)$, so $\\expe(\\bar{X})=0$ and $\\var(\\bar{X})=1/9$. Thus $\\bar{X}\\sim N (0,1/9)$, so the critical value $c$ satisfies\n\\[\n\\prob\\left( N (0,1) > \\frac{c}{\\sqrt{1/9}}\\right) = 0.0898,\n\\]\ni.e.\\ $1-\\Phi(3c) = 0.0898$, or $\\Phi(3c) = 0.9102$. From tables, $\\Phi(1.34076) = 0.91$ and $\\Phi(1.40507)= 0.92$. Interpolating linearly between these values gives\n\\[\n3c = 1.34076 + 0.02(1.40507 - 1.34076) = 1.342,\n\\]\nso $c\\approx 0.447$. The statistical power is \n\\begin{align*}\n\\gamma(0.5) = \\prob_{H_1}(\\bar{X} > 0.447) \n\t& = \\prob\\big(N(0.5,1/9) > 0.447\\big) \\\\\n\t& = \\prob\\big(N(0,1) > 3(0.447 - 0.5)\\big) \\\\\n\t& = \\prob\\big(N(0,1) > -0.159)\\big) \\\\\n\t& \\approx 0.564 \\quad\\text{(from tables).}\n\\end{align*}\nThis is higher than the power of the sign test (which is approximately $0.43$), because the $z$-test takes account of the magnitude of the observations, as well as their signs. If the data really do come from a normal distribution, the $z$-test is more powerful than the sign test for detecting $H_1:\\mu=0.5$ against $H_0:\\mu=0$.\n\\een\n\\end{answer}\n\\end{questions}\n\\end{exercise}\n\n\n%-------------------------------------------------\n\\subsection{The Wilcoxon signed-rank test}\\label{sec:wsr_test}\n\nThe Wilcoxon signed rank test is an extension of the sign test.\n\\bit\n\\it The sign test counts the \\emph{number} of observations which are larger than some fixed value.\n\\it The WSR test also considers the \\emph{relative size} of these observations.\n\\eit\n\n%-----------------------------\n%\\subsubsection{Ranks}\n\n\\begin{definition}\nFor a random sample $X_1,\\ldots,X_n$, the \\emph{rank} of observation $X_i$ is its position in the sequence of observations sorted in ascending order:\n\\[\nR(X_i) = \\sum_{j=1}^n I(X_j \\leq X_i)\n\\]\n\\end{definition}\n\nNote that the sum of the ranks is always equal to the sum of the first $n$ positive integers:\n\\[\n\\displaystyle \\sum_{i=1}^n R(X_i) = \\sum_{i=1}^n i = \\frac{1}{2}n(n+1).\n\\]\n\n\\begin{remark}[Ties]\nIf two or more observations have the same value, they are said to be \\emph{tied}. If the distribution is continuous, ties occur with probability zero. Ties often occur in practical applications however, due to the limited precision of measurements. To deal with ties, the usual approach is to assign an \\emph{average rank} to each of the tied observations. For example, if there are $m-1$ observations strictly smaller than $X_i=X_j$, we set\n\\[\nR(X_i) = R(X_j) = \\frac{m+(m+1)}{2} = m+\\frac{1}{2}.\n\\]\n\\end{remark}\n\n%-----------------------------\n\\subsubsection{The test statistic}\n\nLet $X$ be a continuous random variable whose distribution is \\emph{symmetric} and whose median $\\eta$ is unknown, and let $X_1,X_2,\\ldots,X_n$ be a random sample from the distribution of $X$. \nWithout loss of generality, we consider the null hypothesis $H_0:\\eta=0$:\n\\bit\n\\it for a single sample $X_1,X_2,\\ldots,X_n$, the null hypothesis $H_0:\\eta=\\eta_0$ reduces to $H_0:\\eta=0$ by looking at the differences $D_i = X_i - \\eta_0$;\n\\it For paired samples $X_1,X_2,\\ldots,X_n$ and $Y_1,Y_2,\\ldots,Y_n$, the null hypothesis $H_0:\\eta_1=\\eta_2$ reduces to $H_0:\\eta=0$ by looking at the differences $D_i = X_i - Y_i$.\n\\eit\n\n% definition: wsr statistic\n\\begin{definition}\nFor the null hypothesis $H_0:\\eta=0$, the \\emph{Wilcoxon signed rank} (WSR) statistic is \n\\[\nW^{+}_n = \\sum_{i=1}^n R_i Z_i \\quad\\text{where}\\quad R_i = \\sum_{j=1}^n I(|X_j|\\leq |X_i|) \\quad\\text{and}\\quad Z_i=I(X_i>0).\n\\]\n\\end{definition}\n\\bit\n\\it $R_i$ is the rank of $|X_i|$ in the sample of absolute values $|X_1|,|X_2|,\\ldots,|X_n|$;\n\\it $Z_i=1$ if $X_i>0$, otherwise $Z_i=0$.\n\\eit\n\nWe also define the complementary statistic $W^{-}_n = \\displaystyle\\sum_{i=1}^n R_i(1-Z_i)$. Note that\n\\[\nW^{+}_n + W^{-}_n = \\sum_{i=1}^n R_i = \\sum_{i=1}^n i = \\frac{1}{2}n(n+1).\n\\]\n\n%% test procedure\n%The WSR test procedure is as follows:\n%\\ben\n%\\it Compute the differences $D_i = X_i - \\eta_0$ (single sample) or $D_i=X_i-X'_i$ (matched pairs).\n%\\it Compute absolute differences $|D_i|$ and record the sign of $D_i$.\n%\\it Compute the ranks $R_i$ of the absolute differences $|D_i|$.\n%\\it Compute the the sum of the ranks of those $|D_i|$ having positive sign. \n%\\een\n%The final step yields the test statistic $W^{+}_n$.\n\n% example\n\\begin{example}\nA study of the effects of smoking by mothers on the birthweight of their children involved 12 pairs of mothers. The pairs of mothers were selected so that they were as similar as possible, except that one mother of each pair was a smoker and the other was not. The birthweights (in kilograms) of the babies were as follows.\n\\small\n\\[\\begin{array}{l|cccccccccccc} \\hline\n\\text{Pair}\t\t\t& 1      &  2     & 3      & 4      & 5      & 6      & 7      & 8      & 9      & 10     & 11     & 12 \t\t\\\\ \\hline\n\\text{Non-smoker}\t& 3.22   & 4.48   & 3.90   & 3.47   & 3.07   & 3.23   & 4.25   & 3.31   & 3.33   & 3.78   & 3.18   & 4.60  \t\\\\ \n\\text{Smoker}\t\t& 3.00   & 4.27   & 3.95   & 3.32   & 2.51   & 2.77   & 4.02   & 3.41   & 3.39   & 3.88   & 3.18   & 4.37 \t\\\\ \\hline\n\\end{array}\\]\n\\normalsize\nDo these data support the claim that mothers who smoke tend to have babies with smaller birthweights than those who do not? \n\\end{example}\n\n\\begin{solution}\nThe data are in matched pairs so we compute the differences $D_i=X_i-Y_i$, where $X_1,X_2,\\ldots,X_n$ are the birthweights for non-smokers and $Y_1,Y_2,\\ldots,Y_n$ are the corresponding birthweights for smokers. The test then becomes\n\\[\nH_0:\\eta = 0 \\quad\\text{against}\\quad H_1:\\eta > 0,\n\\]\nwhere $\\eta$ is the (true) median difference between birthweights for the non-smoking group and birthweights for the smoking group.\n\n\\small\n\\[\\begin{array}{|c|cccccccccccc|} \\hline\ni\t\t\t& 1      &  2     & 3      & 4      & 5      & 6      & 7      & 8      & 9      & 10     & 11     & 12   \t\\\\ \\hline\nX_i\t\t\t& 3.22   & 4.48   & 3.90   & 3.47   & 3.07   & 3.23   & 4.25   & 3.31   & 3.33   & 3.78   & 3.18   & 4.60 \t\\\\ \nX'_i\t\t& 3.00   & 4.27   & 3.95   & 3.32   & 2.51   & 2.77   & 4.02   & 3.41   & 3.39   & 3.88   & 3.18   & 4.37\t\\\\ \\hline\nD_i\t\t\t& 0.22   & 0.21   & -0.05  & 0.15   & 0.56   & 0.46   & 0.23   & -0.10  & -0.06  & -0.10  & 0.00  \t& 0.23\t\\\\\n|D_i|\t\t& 0.22   & 0.21   &  0.05  & 0.15   & 0.56   & 0.46   & 0.23   &  0.10  &  0.06  &  0.10  & 0.00  \t& 0.23\t\\\\ \\hline\n\\text{sgn}(D_i)\t& +      & +      & -      & +      & +      & +      & +      & -      & -      & -      &      \t& +  \t\\\\ \n%R(|D_i|)\t\t& 8      & 7      & 2      & 6      & 12     & 11     & 9.5    &  4.5   &  3     &  4.5   & 0     \t& 9.5  \t\\\\ \\hline\nR(|D_i|)\t\t& 7      & 6      & 1      & 5      & 11     & 10     & 8.5    &  3.5   &  2     &  3.5   &      \t& 8.5  \t\\\\ \\hline\n\\end{array}\\]\n\\vspace*{-2ex}\\normalsize\n\\bit\n\\it The zero difference is discarded, leaving $n=11$ non-zero differences.\n\\it Ties are replaced by the average of the corresponding ranks.\n\\eit\nFrom the data, $W^{+}_n = 56$ and $W^{-}_n = 10$. \\Big[Check: $W^{+}_n + W^{-}_n = 66 = \\frac{1}{2}n(n+1)$.\\Big]\n\\bit\n\\it Large values of $W^{+}_n$ support the alternative hypothesis, $H_1:\\eta > 0$. \n\\it From tables, the upper-tail critical value of $W^{+}_n$ for $n=11$ at $\\alpha=0.05$ is $w_c = 52$. \n\\eit\nSince $W^{+}_n > w_c$, we reject the null hypothesis and conclude that mothers who smoke tend to have babies with smaller birthweights than those who do not. \n\\end{solution}\n\n\n%-----------------------------\n\\subsubsection{Mean and variance of $W^{+}_n$}\n\n% theorem: mean and variance of W+\n\\begin{theorem}\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from a continuous distribution whose density function is symmetric about its mean. Under the null hypothesis $H_0:\\eta=0$, \n\\[\n\\expe(W^{+}_n) = \\frac{n(n+1)}{4} \\qquad\\text{and}\\qquad \\var(W^{+}_n)\t= \\frac{n(n+1)(2n+1)}{24}.\n\\]\n\\end{theorem}\n\n\\begin{proof}\nRecall that \n\\[\nW^{+}_n = \\sum_{i=1}^n R_i Z_i \\quad\\text{where}\\quad R_i = \\sum_{j=1}^n I(|X_j|\\leq |X_i|) \\quad\\text{and}\\quad Z_i=I(X_i>0).\n\\]\n%\n%$W^{+}_n = \\sum_{i=1}^n R_iZ_i$, where $R_i=R(|X_i|)$ and $Z_i = I(X_i > 0)$.\nUnder $H_0:\\eta=0$ we have $Z_i\\sim\\text{Bernoulli}(1/2)$ and hence $\\expe(Z_i)=1/2$ and $\\var(Z_i)=1/4$. \n\n\\begin{align*}\n\\expe(W^{+}_n) \n\t& = \\sum_{i=1}^n R_i\\expe(Z_i) \n\t= \\frac{1}{2}\\sum_{i=1}^n R_i\n\t= \\frac{1}{2}\\sum_{i=1}^n i\n\t= \\frac{1}{4}n(n+1). \\\\\n\\var(W^{+}_n)\n\t& = \\sum_{i=1}^n R_i^2 \\var(Z_i) \n\t= \\frac{1}{4}\\sum_{i=1}^n R_i^2\n\t= \\frac{1}{4}\\sum_{i=1}^n i^2\n\t= \\frac{1}{24}n(n+1)(2n+1).\n\\end{align*}\n\\end{proof}\n\n%\\begin{remark}\n%\\bit\n%\\it\n%In practice, the sum of the squares of the ranks is equal to the sum of the squares of the first $n$ natural numbers only if there are no ties and no zeros (i.e.\\ observations that are exactly equal to $\\eta_0$).\n%\\it A correction for ties is\n%\\[\n%\\var(W^{+}_n) = \\frac{1}{24}n(n+1)(2n+1) - \\frac{1}{48}\\sum t(t^2-1)\n%\\]\n%where $t$ is the number of tied observations (e.g.\\ $t=2$ if there are two identical observations) and the summation is over the number of sets of tied observations.\n%\\eit\n%\\end{remark}\n\n%-----------------------------\n\\subsubsection{Normal approximation}\n$W^{+}_n$ is the sum of random variables and (although the random variables are not independent) it satisfies the central limit theorem. Under $H_0:\\eta=0$, and provided $n$ is sufficiently large, the distribution of $W^{+}_n$ is \n\\[\nW^{+}_n \\sim N\\left(\\frac{1}{4}n(n+1), \\frac{1}{24}n(n+1)(2n+1)\\right) \\text{\\quad approx.}\n\\]\n\nThe continuity correction should be applied when defining the test statistic.\n\\bit\n\\it Lower-talied test:\n\\[\nZ = \\frac{(W^{+}_n +\\frac{1}{2})- \\frac{1}{4}n(n+1)}{\\sqrt{\\frac{1}{24}n(n+1)(2n+1)}}\\sim N(0,1) \\quad\\text{approx.}\n\\]\n\\it Upper-talied test:\n\\[\nZ = \\frac{(W^{+}_n -\\frac{1}{2})- \\frac{1}{4}n(n+1)}{\\sqrt{\\frac{1}{24}n(n+1)(2n+1)}}\\sim N(0,1) \\quad\\text{approx.}\n\\]\n\\eit\n\n%-----------------------------\n\\subsubsection{Exact distribution of $W^{+}_n$ under $H_0$}\n\nThe exact distribution of $W^{+}_n$ under $H_0$ can be obtained for small $n$ by a recurrence relation. The base case is $n=1$ (a single observation), for which $W^{+}_1\\in\\{0,1\\}$ and under $H_0:\\eta=0$,\n\\[\n\\prob(W^{+}_1 = 0) = \\frac{1}{2} \\quad\\text{and}\\quad \\prob(W^{+}_1 = 1) = \\frac{1}{2}.\n\\]\n%\n%\n%\\bit\n%\\it For $n = 2$, the set of ranks is $\\{1,2\\}$ so $W^{+}_2$ takes values in the set $\\{0,1,2,3\\}$. Under $H_0:\\eta=0$, \n%%\\small\n%\\[\\begin{array}{|c|cccc|}\\hline\n%\\text{Ranks}\t\t\t& \\{-1,-2\\}\t& \\{+1,-2\\}\t& \\{-1,+2\\}\t& \\{+1,+2\\}\t\\\\ \\hline\n%k\t\t\t\t\t& 0\t& 1\t& 2\t& 3 \\\\ \\hline\n%\\prob(W^{+}_2=k)\t\t& 0.25\t\t& 0.25\t\t&  0.25\t\t& 0.25 \t\t\\\\ \\hline\n%\\end{array}\\]\n%%\\normalsize\n%\n%\\it For $n=3$, the set of ranks is $\\{1,2,3\\}$, so $W^{+}_3$ takes values in the set $\\{0,1,2,3,4,5,6\\}$. Under $H_0:\\eta=0$,\n%%\\small\n%\\[\\begin{array}{|c|ccccccc|}\\hline\n%k\t\t\t\t& 0\t\t& 1\t\t& 2\t\t& 3 \t\t& 4 \t\t& 5 \t\t& 6\t\t\\\\ \\hline\n%\\prob(W^{+}_3=k)\t& 0.125\t& 0.125\t& 0.125\t& 0.25\t& 0.125\t& 0.125\t& 0.125\t\\\\ \\hline\n%\\end{array}\\]\n%%\\normalsize\n%\\eit\n\n% theorem\n\\begin{theorem}\nUnder $H_0:\\eta=0$,\n\\[\n\\prob\\big(W^{+}_{n+1}=k\\big) = \\frac{1}{2}\\prob\\big(W^{+}_n=k\\big) + \\frac{1}{2}\\prob\\big(W^{+}_n=k-(n+1)\\big).\n\\]\n%for $k=0,1,\\ldots,\\displaystyle\\frac{1}{2}n(n+1)$ (and zero otherwise).\nfor $k=0,1,\\ldots,\\frac{1}{2}n(n+1)$, and zero otherwise.\n\\end{theorem}\n\n\\begin{proof}\n\\bit\n\\it Let $X_1,X_2,\\ldots,X_n$ be a random sample from a continuous and symmetric distribution.\n\\it Let $R_i$ be the rank of $|X_i|$ among the absolute values $|X_1|,|X_2|,\\ldots,|X_n|$:\n\\eit\n\nThen $W^{+}_n$ can be written as\n\\[\nW^{+}_n = \\sum_{r=1}^n rU_r \\qquad\\text{where}\\qquad U_{R_i} = \\begin{cases} 1 & X_i > 0, \\\\ 0 & \\text{otherwise.}\\end{cases}\n\\]\n\n\\bit\n\\it $U_r$ indicates that the observation associated with rank $r$ has a positive sign.\n\\it Under the null hypothesis, $U_1,U_2,\\ldots,U_n$ is a random sample from the $\\text{Bernoulli}(1/2)$ distribution.\n\\eit\n\nLet $G_n(t)$ denote the probability generating function of $W^{+}_n$:\n\\begin{align*}\nG_n(t) \n\t= \\expe(t^{W^{+}_n})  \n\t= \\expe(t^{\\sum_{r=1}^n rU_r})\n\t& = \\expe(t^{U_1}t^{2U_2}\\cdots t^{nU_n}) \\\\\n\t& = \\prod_{r=1}^n \\expe(t^{rU_r}) \\qquad\\text{(by independence)} \\\\\n\t& = \\prod_{r=1}^n \\Big[t^0\\,\\prob(U_r=0) + t^r\\,\\prob(U_r=1)\\Big] \\\\\n\t& = \\prod_{r=1}^n \\frac{1}{2}(1 + t^r). \\\\\n\\intertext{Hence,}\nG_{n+1}(t) \n\t& = \\frac{1}{2}(1 + t^{n+1})G_n(t).\n\\end{align*}\n\nBy definition,\n\\begin{align*}\nG_n(t)\t\t= \\sum_{k=0}^{\\frac{1}{2}n(n+1)}\\,\\prob(W^{+}_n=k)t^k\n\\qquad\\text{and}\\qquad\nG_{n+1}(t)\t= \\sum_{k=0}^{\\frac{1}{2}(n+1)(n+2)}\\,\\prob(W^{+}_{n+1}=k)t^k.\n\\end{align*}\n\nThus,\n\\[\n\\sum_{k=0}^{\\frac{1}{2}(n+1)(n+2)}\\,\\prob(W^{+}_{n+1}=k)t^k \n\t= \\frac{1}{2}(1+t^{n+1})\\sum_{k=0}^{\\frac{1}{2}n(n+1)}\\,\\prob(W^{+}_n=k)t^k,\n\\]\n\nComparing the coefficients of $t^k$ yields the required recurrence relation:\n\\[\n\\prob\\big(W^{+}_{n+1}=k\\big) = \\frac{1}{2}\\prob\\big(W^{+}_n=k\\big) + \\frac{1}{2}\\prob\\big(W^{+}_n=k-(n+1)\\big).\n\\]\nThis recurrence relation is used to compute the quantiles of $W^{+}_n$ listed in statistical tables.\n\\end{proof}\n\n\n\\begin{exercise}\n\\begin{questions}\n\n\\question\nWe wish to test the hypothesis that two treatments $A$ and $B$ are equivalent, against the alternative hypothesis that the responses to treatment $A$ tend to be larger than the responses to treatment $B$. We perform a paired difference experiment, and analyse the resulting data using the Wilcoxon signed rank test. The data is shown in the following table.\n\\[\\begin{array}{|l|cccccccccc|}\\hline\n\\text{Pair}\t&  1 &  2 &  3 &  4 &  5 &  6 &  7 &  8 &  9 & 10 \\\\ \\hline\n$A$ \t\t\t& 54 & 60 & 98 & 43 & 82 & 77 & 74 & 29 & 63 & 80 \\\\\n$B$ \t\t\t& 45 & 45 & 87 & 31 & 71 & 75 & 63 & 30 & 59 & 82 \\\\ \\hline\n\\end{array}\\]\nState the null and alternative hypotheses for the test, and conduct the test at significance level $\\alpha=0.05$.\n\n\\begin{answer}\n\\ben\n\\it % << (i)\nLet $D_i=A_i-B_i$ denote the differences, and let $\\eta$ denote the (true) median difference. We test the null hypothesis $H_0:\\eta=0$ against the one-sided alternative $H_1:\\eta>0$.\n\\it % << (ii)\nThe signed ranks are computed as follows:\n\\[\\begin{array}{|l|cccccccccc|}\\hline\n\\text{Pair}\t\t\t&  1 &  2 &  3 &  4 &  5 &  6 &  7 &  8 &  9 & 10 \\\\ \\hline\n\\text{Difference}\t&  9 & 15 & 11 & 12 & 11 &  2 & 11 & -1 &  4 & -2 \\\\ \\hline\n\\text{Signed Rank}\t&  5 & 10 &  7 &  9 &  7 &2.5 &  7 & -1 &  4 & -2.5 \\\\ \\hline\n\\end{array}\\]\n\\bit\n\\it The Wilcoxon signed rank statistics are $W^{+} = 51.5$ and $W^{-}=3.5$. \n\\it Check: $\\frac{1}{2}n(n+1) = 55 = W^{+}+W^{-}$.\n\\it From tables, for a one-tailed test at $\\alpha=0.05$ and $n=10$, the critical value is $w^{+}_c = 44$.\n\\it Thus we reject $H_0:\\eta=0$ in favour of $H_1:\\eta>0$, and conclude that responses to treatment $A$ tend to be larger than responses to treatment $B$.\n\\eit\n\\een\n\\end{answer}\n\n\\question\nIn a comparison of two populations $A$ and $B$, a paired difference experiment with $n=30$ pairs yields the Wilcoxon signed-rank statistic $w^{+}=354$.\n\\ben\n\\it Construct a test to determine whether or not population $A$ is located to the right of population $B$.\n\\it Conduct the test at $\\alpha=0.05$.\n\\it Repeat part (2) using a normal approximation to the distribution of $W^{+}$.\n\\een\n\n\\begin{answer}\n\\ben\n\\it % << (i)\nLet $\\eta_A$ and $\\eta_B$ denote the (true) medians of populations $A$ and $B$ respectively. To determine whether population $A$ is located to the right of population $B$, we test the null hypothesis $H_0:\\eta_A=\\eta_B$ against the alternative $H_1:\\eta_A > \\eta_B$. We could also define $\\eta=\\eta_A-\\eta_B$ to be the difference between the two medians, in which case we would test $H_0:\\eta=0$ agaianst $H_1:\\eta>0$. \n\n\\it % << (ii)\nFrom tables, for a one-tailed test at $\\alpha=0.05$ and $n=30$, the critical value is $w^{+}_c = 313$, so we reject $H_0$ in favour of $H_1$.\n\nTo compute an approximate $p$-value for the test, from tables (for $n=30$) we see that $w^{+}_c = 345$ at $\\alpha=0.01$ and $w^{+}_c = 356$ at $\\alpha=0.005$. Interpolating between these values, \n\\[\n\\prob_{H_0}(W^{+}\\geq 354) \\approx 0.01 + \\left(\\frac{354-345}{356-345}\\right)(0.005 - 0.01) = 0.0059.\n\\]\n\n\\it % << (ii)\nThe normal approximation is $\\prob(W^{+}\\geq w^{+}_c) \\approx \\prob(Z\\geq z_c)$ where\n\\[\nZ = \\frac{(W^{+}-1/2) - \\expe(W^{+})}{\\sqrt{\\var(W^{+})}} \\sim N (0,1) \\quad\\text{approx.},\n\\]\nHere, $\\expe(W^{+})$ and $\\var(W^{+})$ are respectively the mean and variance of $W^{+}$ under $H_0$. \n\\par\nIn this case,\n\\[\n\\expe(W^{+}) = \\frac{1}{4}n(n+1) = 232\n\\quad\\text{and}\\quad\n\\var(W^{+})  = \\frac{1}{24}n(n+1)(2n+1) = 2363,\n\\]\nso the test statistic is \n\\[\nz = \\frac{353.5 - 232}{\\sqrt{2363}} = 2.4994.\n\\]\n\\bit\n\\it At $\\alpha=0.05$ we have $z_c = 1.645$, so we reject $H_0$. \n\\it From tables, an approximate $p$-value for the test is $1-0.99379 = 0.0062$.\n\\eit\n\\een\n\\end{answer}\n\n\\question\nTo test whether or not a new diet actually results in weight loss, a researcher recruited nine subjects, measured their weight (in kilograms) before starting the diet, and then again after two months on the diet. The results are shown in the following table.\n\\[\\begin{array}{|l|ccccccccc|} \\hline\n\\text{Case}\t\t\t&  1 &  2 &  3 &  4 &  5 &  6 &  7 &  8 &  9 \\\\ \\hline\n\\text{Weight before }\t& 55 & 50 & 54 & 43 & 62 & 61 & 56 & 48 & 53 \\\\\n\\text{Weight after }\t\t& 47 & 40 & 52 & 43 & 51 & 62 & 50 & 47 & 56 \\\\ \\hline\n\\end{array}\\]\n\n\\begin{parts}\n\\part\nUse a sign test with $\\alpha=0.05$ to decide whether or not the diet results in weight loss.\n\\begin{answer}\nLet $\\eta$ denote the (true) median weight loss. \n\\par\nWe evaluate $H_0:\\eta = 0$ against the alternative $H_0:\\eta > 0$.\n\\[\\begin{array}{|l|ccccccccc|} \\hline\n\\text{Case } (i)\t\t\t&  1 &  2 &  3 &  4 &  5 &  6 &  7 &  8 &  9 \\\\ \\hline\n\\text{Weight before }\t& 55 & 50 & 54 & 43 & 62 & 61 & 56 & 48 & 53 \\\\\n\\text{Weight after }\t\t& 47 & 40 & 52 & 43 & 51 & 62 & 50 & 47 & 56 \\\\ \\hline\n\\text{Difference } (D_i)\t&  8 & 10 &  2 &  0 & 11 & -1 &  6 &  1 & -3 \\\\ \\hline\n\\text{Sign }\t\t\t\t&  + &  + &  + &    &  + &  - &  + &  + &  - \\\\ \\hline\n%\\text{Rank } (R_i)\t\t&  6 &  7 &  3 &    &  8 &1.5 &  5 &1.5 &  4 \\\\ \\hline\n\\end{array}\\]\n\\bit\n\\it Exclude the zero difference, and take the sample size to be $n=8$.\n\\it $S_n^{+} = \\sum_i I(D_i>0) = 6$.\n\\it $S_n^{-} = \\sum_i I(D_i<0) = 2$. \n\\it Check: $S_n^{+} + S_n^{-} = n$.\n\\eit\nUnder $H_0$, $S_n^{+}\\sim\\text{Binomial}(n,0.5)$. From tables,\n\\[\n\\prob_{H_0}(S_n^{+}\\geq 6) = 1 - \\prob_{H_0}(S_n^{+}\\leq 5) = 1 - 0.8555 = 0.1445.\n\\]\nAt $\\alpha=0.05$, we would decide to retain the null hypothesis $H_0:\\eta=0$, and conclude that the diet results in no weight loss.\n\\end{answer}\n\n\\part\nRepeat the analysis using the Wilcoxon signed rank test.\n\\begin{answer}\n\\[\\begin{array}{|l|ccccccccc|} \\hline\n\\text{Difference } (D_i)\t&  8 & 10 &  2 &  0 & 11 & -1 &  6 &  1 & -3 \\\\ \\hline\n\\text{Sign }\t\t\t\t&  + &  + &  + &    &  + &  - &  + &  + &  - \\\\ \\hline\n\\text{Rank } (R_i)\t\t&  6 &  7 &  3 &    &  8 &1.5 &  5 &1.5 &  4 \\\\ \\hline\n\\end{array}\\]\n\\bit\n\\it $W^{+} = \\sum_i R_i I(D_i>0) = 6 + 7 + 3 + 8 + 5 + 1.5 = 30.5$.\n\\it $W^{-} = \\sum_i R_i I(D_i<0) = 1.5 + 4 = 5.5$.\n\\it Check: $W^{+} + W^{-} = \\frac{1}{2}n(n+1)$.\n\\eit\nFrom tables, critical values for an upper-tail test are\n\\bit\n\\it $w^{+}_c = 30$ at $\\alpha=0.05$, and \n\\it $w^{+}_c = 32$ at $\\alpha=0.025$.\n\\eit\nThus at $\\alpha=0.05$ we would reject the null hypothesis $H_0:\\eta = 0$ in favour of the alternative $H_0:\\eta > 0$, and conclude that the diet does indeed result in weight loss.\n\\end{answer}\n\n\\part\nBriefly discuss the reasons why the tests lead to different conclusions.\n\\begin{answer}\nThe sign test takes no account of the fact that the average amount of weight lost by those whose weight decreased over the study period, is significantly greater than the average amount of weight gained by those whose weight increased over the study period. \n\\end{answer}\n\\end{parts}\n\n\\end{questions}\n\\end{exercise}\n\n\n\n", "meta": {"hexsha": "b3792a64d1615c64329d15f80cef91a5e203990c", "size": 31516, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/10C_one_sample_tests.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/10C_one_sample_tests.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/10C_one_sample_tests.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 45.6753623188, "max_line_length": 478, "alphanum_fraction": 0.6212400051, "num_tokens": 12336, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8577681013541613, "lm_q1q2_score": 0.7437156086504315}}
{"text": "If you haven't downloaded and unzipped \\href{https://libaoj.in/courses/2021f/MATH3341/zip/Math.3341.zip}{\\texttt{Math.3341.zip}}. Download and unzip it under \\verb|H:| (H Drive if you are working on the Remote Lab). Change the current working directory by typing \\verb|cd H:\\Math.3341\\Math.3341.Lab.14| in the Command Window, and type \\verb|edit lab_14_script| in the Command Window to edit \\verb|lab_14_script.m|.\n\n%---------------------------------------------\n\\section{Direction Fields and Solution Curves}\n%---------------------------------------------\nGiven the following ODE and the initial condition,\n$$\n\\frac{dy}{dt} = -y - 5 e^{-t} \\sin(5t), \\quad y(0) = -2, \\quad t \\in [0, 3].\n$$\n\\begin{enumerate}[(a)]\n    \\item Define anoymous function \\verb`dydt` to be the right-hand side of the ODE.\n    \\item Define \\verb`a`, \\verb`b` to be the left and right endpoint of the interval $[0, 3]$, respectively.\n    \\item Define \\verb`t_step` to be the step size $\\Delta t = 0.01$.\n    \\item Define \\verb`t_span` to be a vector starting from \\verb`a` to \\verb`b` with step size \\verb`t_step` using colon notation.\n    \\item Use \\verb`ode23` to solve the ODE.\n    \\item Plot \\verb`y_sol(:, i)` versus \\verb`t_sol(:, i)` with line style specified in the cell array \\verb`LineStyle`.\n    \\item Run the script and see whether it works. If it does work, add more initial conditions to \\verb|y0|: $y(0) = 0$, $y(0) = 2$, $y(0) = 4$.\n\\end{enumerate}\n%---------------------------------------------\n\\section{System of ODEs}\n%---------------------------------------------\nNext, use the built-in ODE solver \\verb`ode45` to solve the following system of ODEs:\n$$\n\\begin{cases}\n    y'_1(t) = y_3, \\\\\n    y'_2(t) = y_4, \\\\\n    y'_3(t) = -2 y_1 + (3/2) y_2, \\\\\n    y'_4(t) = (4/3) y_1 - 3 y_2, \\\\\n\\end{cases}\n\\quad\n\\mathbf{y}(0) =\n\\begin{bmatrix}\n    -1 \\\\ 4 \\\\ 1 \\\\ 1\n\\end{bmatrix},\n\\quad\nt \\in [0, 15].\n$$\n\\begin{enumerate}[(a)]\n    \\item Define an anoymous function (you can refer to the example in reference page for \\verb`ode45`. To open the reference page, type \\verb`doc ode45` in the Command Window).\n    \\item Repeat the steps in Part 1 to define \\verb`a`, \\verb`b`, \\verb`t_step`, \\verb`t_span`, and \\verb`y0`.\n    \\item Use \\verb`ode45` to solve the system of ODEs.\n    \\item Plot \\verb`y(:, i)` versus \\verb`t` with line style specified in the cell array \\verb`LineStyle`.\n    \\item Plot \\verb`y(:, 3)` versus \\verb`y(:, 1)`.\n\\end{enumerate}\n%---------------------------------------------\nAt last, run the script \\verb|lab_14_script.m|. Upload the script file \\verb|lab_14_script.m|, and figure files \\verb|lab_14_figure_1.pdf|, \\verb|lab_14_figure_2.pdf|, \\verb|lab_14_figure_3.pdf| to Overleaf. Recompile, and submit the generated .pdf file on WyoCourses.\n\n\\begin{figure}[!hbtp]\n  \\centering\n  \\includegraphics[height=0.3\\textheight]{../Math.3341.Lab.14.ans/lab_14_figure_1.pdf}\n  \\caption{Expected result for Direction Fields and Solution Curves}\n  \\label{fig:}\n\\end{figure}\n\n\\begin{figure}[!hbtp]\n  \\centering\n  \\includegraphics[height=0.3\\textheight]{../Math.3341.Lab.14.ans/lab_14_figure_2.pdf}\n  \\includegraphics[height=0.3\\textheight]{../Math.3341.Lab.14.ans/lab_14_figure_3.pdf}\n  \\caption{Expected result for System of ODEs}\n  \\label{fig:}\n\\end{figure}\n\n\n", "meta": {"hexsha": "7e0ef6f52982ab962bfd0a2807e92dc3de04a31e", "size": 3259, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/Math.3341.Lab.14/exercise/body.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/Math.3341.Lab.14/exercise/body.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/Math.3341.Lab.14/exercise/body.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.921875, "max_line_length": 414, "alphanum_fraction": 0.6397667996, "num_tokens": 1052, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.8791467706759584, "lm_q1q2_score": 0.7437075687666589}}
{"text": "\\lab{Applications}{Image Segmentation}{Image Segmentation}\n\n\\objective{Understand some basic applications of Eigenvalues to graph theory}\n\\label{lab:ImgSeg_eigenvalues}\n\n\\section*{Graph Theory}\n\\begin{figure}[h]\n\\includegraphics[width=\\textwidth/2]{graphExample}\n\\caption{A simple graph}\n\\label{fig:example_graph}\n\\end{figure}\n\n\nGraphs are often used to represent relationships between objects.\nThey are represented by a set of nodes (or vertices) and a set of edges where each edge connects exactly two nodes.\nWe denote the number of vertices in a graph by $|V|$, and the number of edges by $|E|$.\nA graph is \\emph{directed} if connections are uni-directional, and \\emph{undirected} if they are bi-directional.\nOne way to encode all the information in this picture is to use what is called an adjacency matrix.\n\\begin{definition} An adjacency matrix $A$ is a $|V| \\times |V|$ matrix where the $(i,j)$-th entry $a_{ij}$ is\n\\begin{center}\n\t$a_{ij} = \\begin{cases} 1 & \\mbox{If an edge connects vertex i to vertex j} \\\\ 0 & \\mbox{otherwise} \\end{cases}$\n\\end{center}\n%technically, the definition does not apply to all graphs (according to Wikipedia)\n%however, this definition works if we are just considering simple graphs, i.e. at most one edge between any two vertices, no loops\n\\end{definition}\n\nEvery undirected edge can be represented as two directed edges.\nFigure \\ref{fig:example_graph} shows a simple undirected graph.\nWe can represent the connections of nodes as a matrix called an \\emph{adjacency matrix}.\nThe graph in Figure \\ref{fig:example_graph} can be represented as the following adjacency matrix.\n\\[\nA = \\begin{pmatrix}\n0 & 1 & 0 & 0 & 1 & 0\\\\\n1 & 0 & 1 & 0 & 1 & 0\\\\\n0 & 1 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 1 & 0 & 1 & 1\\\\\n1 & 1 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 0 & 1 & 0 & 0\n\\end{pmatrix}\n\\]\nWe order the nodes and each node represents one column and one row of the adjacency matrix.\nIf an edge exists between node $i$ and node $j$ then the $A_{ij}$ entry is 1.\nFor undirected graphs, the adjacency matrix will always be symmetric.\nThe diagonal represents self-edges, or edges that connect a node to itself.\nWhile adjacency matrices are useful, many graph algorithms depend on another representation of a graph called an \\emph{adjacency list}.\n\nRaising the adjacency matrix to a power yields some very interesting information.\nWe can discover the number of paths of length $n$ between two nodes by raising a graph's adjacency matrix to the $n$th power.\nFor example, by squaring $A$, we can find the number of paths of length 2 between every pair of nodes.\n\\begin{lstlisting}\n>>> np.linalg.matrix_power(A,2)\narray([[2, 1, 1, 1, 1, 0],\n       [1, 3, 0, 2, 1, 0],\n       [1, 0, 2, 0, 2, 1],\n       [1, 2, 0, 3, 0, 0],\n       [1, 1, 2, 0, 3, 1],\n       [0, 0, 1, 0, 1, 1]])\n\\end{lstlisting}\nWe can see that no paths of length 2 exist between node 0 and node 5 because $A^2_{0,5} = 0$.\nBy calculating $A^6$ we can find the number of paths length 6 from node 3 to itself.\n\\begin{lstlisting}\n>>> np.linalg.matrix_power(A, 6)\narray([[45, 54, 38, 45, 54, 16],\n       [54, 86, 29, 77, 51, 11],\n       [38, 29, 55, 15, 70, 27],\n       [45, 77, 15, 75, 31,  4],\n       [54, 51, 70, 31, 93, 34],\n       [16, 11, 27,  4, 34, 14]])\n\\end{lstlisting}\nWe see that there are 55 unique paths of length 6 from node 3 to itself.\nImagine trying to count all of those paths by hand!\nIt would be very easy to count incorrectly.\nHowever, this method makes it very simple to count paths without any mistakes.\n\nAdjacency matrices can also be composed of \\li{True} and \\li{False} values.\nIn this case, the $n$th power of such a matrix (using boolean arithmetic)\nis again a matrix of\nboolean values which simply indicate whether there exists a path of length $n$ between the given pair of nodes, rather than indicating the number of such\npaths.\n\n\\begin{problem}\nLet the following matrix represent a directed graph\n\\[\n\\begin{pmatrix}\n0 & 0 & 1 & 0 & 1 & 0 & 1 \\\\\n1 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n0 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n1 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\n0 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n0 & 0 & 1 & 0 & 0 & 0 & 1 \\\\\n0 & 1 & 0 & 0 & 0 & 0 & 0\n\\end{pmatrix}\n\\]\nBetween which pair of nodes does there exist the greatest number of paths\nof length five?\nFrom which node to which node is there no path of length seven?\n\\end{problem}\n\nAnother useful way of representing an undirected graph is a Laplacian matrix.\nThis special matrix can reveal a lot of information about a graph.\n\\begin{definition}\nFor a simple graph (an unweighted, undirected graph without self-edges), the Laplacian of a graph $G$ is\n\\[ L_G = D_G - A_G \\]\nwhere $D_G$ is the degree matrix of $G$ and $A_G$ is the adjacency matrix of $G$.\n\\end{definition}\nAn important question in working with graphs is the degree of its nodes.\nThe degree of a node is the number of edges that connect to the node.\nFor a directed graph, each node has an \\emph{out-degree} (the number of edges directed away from a node) and an \\emph{in-degree} (the number edges directed toward a node).\nThe degree matrix of a graph is a diagonal matrix that has the degree of each node as the diagonal entries (thus, for a directed graph there in an in-degree matrix and an out-degree matrix).\n\n\\begin{problem}\nCalculate the Laplacian matrix of the graph in Figure \\ref{fig:example_graph} by calculating $D$ and $A$.\nThink about how to find the number of neighboring nodes using an adjacency matrix.\n\nWrite a general solution that will calculate the Laplacian of any small graph.\nUse the adjacency matrix to check that the graph is unweighted, undirected, and contains no self-edges.\n\\label{prob:laplacian}\n\\end{problem}\n\n\nWe may also define weighted graphs so that each edge has a weight or cost attached to it.\nIn this case the adjacency matrix will have the cost in each entry, rather than just a 1 or 0.\nAn example of a weighted may be a collection of cities as vertices, roads connecting them as edges, and the distance of the connecting roads as the cost attached to each edge.\n\nIn this lab we will be investigating the sorts of things that we can discover about a graph by examining the spectrum of its adjacency matrix.\nWhile the formulation of the adjacency matrix seems to be very simple, its structure allows us to learn surprising things by examining its eigenvalues.\n\nFor a weighted graph the definition of the Laplacian of a graph is:\n\n\\begin{definition}  The \\emph{degree} of a vertex of a weighted graph is the sum of the weights of the edges connected to that vertex.\nIn undirected graphs, which is what we will be dealing with, this is the sum of all the weights moving into that vertex.\nThis definition varies slightly for directed graphs.\nLet $D$ be a diagonal matrix with\n\\[\nD_{ii} = \\mbox{ Degree of vertex $i$}\n\\]\nand let $A$ be the adjacency matrix of the graph.\nThe graph \\emph{Laplacian} $Q$ is given by\n\\[\nQ = D-A\n\\]\n\\end{definition}\n\nThe Laplacian matrix of a graph will typically be very sparse.\nWe will be examining the spectrum of the Laplacian matrix.\n\nA connected graph is a graph where every vertex is connected to every other vertex by at least one path.\nAn important question one might ask about a graph is whether or not it is connected.\nWhat is the best way to do this?\nA naive approach would be to exhaustively map every possible path from each vertex.\nWhile this would be feasible for very small graphs, most interesting graphs (for example, the internet) will have thousands of vertices and such an approach becomes essentially impossible to execute.\n\nIt turns out there is a better way.\nIf the second smallest eigenvalue of the Laplacian matrix associated with a graph is positive, then this graph is connected.\nThe mathematics behind this is quite involved, so we omit a proof for now.\nIn many applications the Laplacian matrix will be very sparse, and thus with optimizations made for sparsity, we can discover the connectivity of a graph relatively cheaply.\n\n\\begin{problem}Write a function \\li{laplacian} that accepts an adjacency matrix as an argument and returns the Laplacian matrix and its second smallest eigenvalue.\nUse the \\li{scipy.linalg} package to compute this eigenvalue.\nUsing {\\tt numpy.rand(n,n)}, generate several random matrices of various sizes.\nUse masking to change the sparsity of said matrices, i.e. {\\tt numpy.rand(n,n) > c} for {\\tt c = 0.25,0.5,0.75}.\nTry different distributions and $c$ values.\nWhat can we expect about the connectivity of random matrices?\n\\end{problem}\n\nA related problem is found in image processing.\nAn image is a collection of coordinates and light intensities.\nWe call each coordinate and associated brightness a pixel.\nWe let every pixel in an image be a vertex in a graph that is connected to its neighbors within a certain radius.\nFor an $N \\times N$ image, we define an adjacency matrix as follows:\n\n\\begin{equation}\n\\label{eq:adjacency}\nw_{ij} = e^{-\\frac{|I(i) - I(j)|}{\\sigma_I^2}} \\cdot \\begin{cases} e^{-\\frac{d(i,j)}{\\sigma_d^2}} & \\mbox{ for $d(i,j) < r$} \\\\ 0 & \\mbox{ otherwise} \\end{cases}\n\\end{equation}\nfor $i = 1 \\hdots N^2$ and $j = 1 \\hdots N^2$ (traveling through each pixel in the image), where\n\\begin{itemize}\n\t\\item$d(i,j)$ is the Euclidean distance between pixel $i$ and pixel $j$\n\t\\item $|I(i) - I(j)|$ is the difference in brightness of pixels $i$ and $j$\n\t\\item $\\sigma_I$ and $\\sigma_d$ are constants\n\\end{itemize}\nThus, given a $N\\times N$ image, we will produce an adjacency matrix of size $N^2\\times N^2$.\nEven for smaller images, this will become very large, but we have sparsity on our side.\nEven so, only do this for images smaller than 50 by 50.\nSince each pixel is only connected to the pixels within radius $r$ around it, relatively few entries will be non-zero.\n\n\\begin{problem}\nWrite a function \\li{adjacency} that takes an $N \\times N$ image array, radius $r$, and values for\n$\\sigma_I^2$ and $\\sigma_d^2$, and returns the adjacency matrix defined in \\eqref{eq:adjacency}.\nNotice that for each pixel you can save time by only checking the pixels $r$ rows and columns away.\n%For that you'll have to handle the pixels on the edges and corners of the image carefully.\n%I gave them new helper code, which abstracts away the edge cases.\nMake use of sparsity in order to feasibly store such a large matrix.\nWe have provided code to help out with this problem.\n\\end{problem}\n\nAn important problem in image processing is that of image segmentation.\nWhen humans observe an image, they can easily pick out portions of an image that ``belong together.''\nFor example, if we saw the picture of a person against a black background, the pixels making up the background would make up one segment of an image, and the person would make up the other part.\nWhile this seems simple for a human, how can we program a computer to do so?\n\nOnce again, we turn to the eigenvalues of the Laplacian matrix.\nWe examine the second smallest eigenvalue of $D^{-\\frac{1}{2}}QD^{-\\frac{1}{2}}$, where $D$ is the degree matrix and $Q$ is the Laplacian matrix of the adjacency matrix defined in \\eqref{eq:adjacency}.\nThe associated $N^2 \\times 1$ eigenvector will have positive and negative entries, splitting the image into two parts.\nThanks to some very fancy mathematics and the way we have defined the weights between nodes, this does a pretty good job of breaking an image into two segments.\nRecursively executing this function, we can find segments within segments.\n%Figure \\ref{segmentation:example} shows a simple example of an image and its segments.\n\n%\\begin{figure}\n%\\includegraphics[scale=0.2]{monument}\n%\\includegraphics[scale=0.2]{segment1}\n%\\includegraphics[scale=0.2]{segment2}\n%\\caption{An image and it's segments.}\n%\\label{segmentation:example}\n%\\end{figure}\n\n\\begin{problem}  Write a function \\li{segment} that solves the segmentation problem for small images.\nAccept an image array as an argument and return the two segments.\nUse $r = 5, \\sigma_I^2 = 0.02,$ and $\\sigma_d^2 = 3.0$.\nRemember that the Laplacian matrix will be very large but also very sparse.\nBecause of the way we defined $\\sigma_I^2$ the image matrix intensity values need to be between $0.0$ and $1.0$.\n\\end{problem}\n", "meta": {"hexsha": "c571b0a57093af6bcf641d1e33851ea675bc6eb2", "size": 12097, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/ImageSegment/ImageSegment.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/ImageSegment/ImageSegment.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/ImageSegment/ImageSegment.tex", "max_forks_repo_name": "lcbendall/numerical_computing", "max_forks_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.2466367713, "max_line_length": 201, "alphanum_fraction": 0.7398528561, "num_tokens": 3321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424450764199, "lm_q2_score": 0.8791467627598857, "lm_q1q2_score": 0.743707562070117}}
{"text": "\\section{Stochastic gradient descent method and convergence theory}\nThe next optimization problem is the most common case in machine learning.\n\\begin{problem}\n\t\\begin{equation}\\label{SGDproblem}\t\n \t\\min_{x \\in \\mathbb{R}^n} f(x)\\quad \\mbox{and}\\quad f(x) = \\frac{1}{N} \\sum_{i=1}^N f_i(x).\n\t\\end{equation}\n\\end{problem}\nOne version of stochastic gradient descent (SGD) algorithm is:\n\\begin{algorithm}\\caption{SGD}\n\\label{alg:SGD}\n{\\bf Input}: initialization $x_0$, learning rate $\\eta_t$.\n\n{\\bf For}: t = 0,1,2,$\\dots$ \n\nRandomly pick $i_t \\in \\{1, 2, \\cdots, N\\}$ independently with probability $\\frac{1}{N}$\n\\begin{equation}\\label{equ:sgd-iteration}\nx_{t+1} = x_{t} - \\eta_t \\nabla f_{i_t}(x_t).\n\\end{equation}\n\\end{algorithm}\n\n\n\\subsection{Convergence of SGD}\n\\begin{theorem}Assume that each $f_i(x)$ is $\\lambda$-strongly convex and $\\|\\nabla f_i(x)\\| \\le M$ for some $M >0$.\n\tIf we take $\\eta_t = \\frac{a}{\\lambda (t+1)}$ with sufficiently large $a$ such that \n\t\\begin{equation}\\label{key}\n\t\\|x_0 - x^*\\|^2 \\le \\frac{a^2M^2}{(a-1)\\lambda^2}\n\t\\end{equation}\nthen \n\\begin{equation}\n\\mathbb{E}e_{t}^2 \\le \\frac{a^2M^2}{(a-1)\\lambda^2 (t+1)}, \\quad  t\\ge 1,\n\\end{equation}\nwhere $e_t = \\|x_t - x^*\\|$.\n\\end{theorem}\n\n\\begin{proof}\nThe $L^2$ error of SGD can be written as\n\\begin{equation}\n      \\label{equ:L2SGD}\n      \\begin{split}\n            \\mathbb{E} \\|x_{t+1} - x^*\\|^2 &\\le \\mathbb{E}\\| x_{t} - \\eta_t \\nabla f_{i_t}(x_t) - x^* \\|^2 \\\\\n            &\\le \\mathbb{E} \\|x_t - x^*\\|^2 \n            - 2 \\eta_t \\mathbb{E} (\\nabla f_{i_t}(x_t) \\cdot (x_t - x^*)) \n            + \\eta_t^2 \\mathbb{E} \\|\\nabla f_{i_t}(x_t)\\|^2 \\\\\n            & \\le \\mathbb{E} \\|x_t - x^*\\|^2 - 2 \\eta_t \\mathbb{E} (\\nabla f (x_t) \\cdot (x_t - x^*))\n            + \\eta_t^2 M^2 \\\\\n            & \\le \\mathbb{E} \\|x_t - x^*\\|^2 -  \\eta_t \\lambda \\mathbb{E} \\|x_t - x^*\\|^2 + \\eta_t^2 M^2 \\\\\n            & = (1 - \\eta_t\\lambda) \\mathbb{E} \\|x_t - x^*\\|^2 + \\eta_t^2 M^2\n      \\end{split}\n\\end{equation}\nThe third line comes from the fact that\n\\begin{equation}\\label{key}\n\\begin{aligned}\n\\mathbb{E} (\\nabla f_{i_t}(x_t) \\cdot (x_t - x^*))  &= \\mathbb{E}_{i_1i_2\\cdots i_t} (\\nabla f_{i_t}(x_t) \\cdot (x_t - x^*)) \\\\\n&= \\mathbb{E}_{i_1i_2\\cdots i_{t-1}} \\frac{1}{N} \\sum_{i=1}^N \\nabla f_i(x_t)\\cdot (x_t - x^*) \\\\\n&= \\mathbb{E}_{i_1i_2\\cdots i_{t-1}}  \\nabla f(x_t)\\cdot (x_t - x^*) \\\\\n&= \\mathbb{E}\\nabla f(x_t)\\cdot (x_t - x^*),\n\\end{aligned}\n\\end{equation}\nand\n\\begin{equation}\n\\mathbb{E} \\|\\nabla f_{i_t}(x_t)\\|^2 \\le \\mathbb{E} M^2 = M^2.\n\\end{equation}\nNote when $t=0$, we have \n\\begin{equation}\\label{key}\n\\mathbb{E} e_0^2 = \\|x_0 - x^*\\|^2 \\le \\frac{a^2M^2}{(a-1)\\lambda},\n\\end{equation}\nbased on the assumption.\n\nIn the case of SDG, by the inductive hypothesis, \n\\begin{equation}\n      \\begin{split}\n            \\mathbb{E}e_{t+1}^2 & \\le (1 - \\eta_t\\lambda)\\mathbb{E}e_{t}^2  + \\eta_t^2 M^2\\\\\n            &\\le  (1 - \\frac{a}{t+1}) \\frac{a^2M^2}{(a-1)\\lambda^2 (t+1)} + \\frac{a^2M^2}{\\lambda^2 (t+1)^2} \\\\\n            & \\le \\frac{a^2M^2}{(a-1)\\lambda^2} \\frac{1}{(t+1)^2}(t+1 -a + a-1) \\\\\n            & = \\frac{a^2M^2}{(a-1)\\lambda^2} \\frac{t}{(t+1)^2} \\\\\n            & \\le \\frac{a^2M^2}{(a-1)\\lambda^2(t+2)}. \\quad \\left(\\frac{t}{(t+1)^2} \\le \\frac{1}{t+2}\\right),\n      \\end{split}\n\\end{equation}\nwhich completes the proof.\n\\end{proof}\n\n\n\\subsection{SGD with mini-batch}\nFirstly, we will introduce a natural extended version of the SGD discussed above with introducing mini-batch. \n\n\\begin{algorithm}[H]\\caption{SGD with mini-batch}\n\t\\label{alg:SGD}\n\t{\\bf Input}: initialization $x_0$, learning rate $\\eta_t$.\n\t\n\t{\\bf For}: t = 0,1,2,$\\dots$ \n\t\n\t\\begin{center}\n\tRandomly pick $B_t \\subset \\{1, 2, \\cdots, N\\}$ independently \n\twith probability $\\frac{m!(N-m)!}{N!}$ \\\\\n\tand $\\# B_t = m$.% with $\\frac{1}{\\tbinom{N}{m}} = $.\n\t\\end{center}\n\t\\begin{equation}\\label{equ:sgd-iteration}\n\tx_{t+1} = x_{t} - \\eta_t g_t(x_t).\n\t\\end{equation}\n\t\\quad where \n\t$$\n\tg_{t}(x_t) = \\frac{1}{m} \\sum_{i \\in B_{t}}  \\nabla f_i(x_t)\n\t$$\n\\end{algorithm}\n\nNow we introduce the SGD algorithm with mini-batch without replacement which is the most commonly used version of SGD in machine learning.\n\\begin{algorithm}[H]\n\t\\caption{Shuffle SGD with mini-batch}\n\t\\label{alg:mini-batch}\n\t{\\bf Input}: learning rate $\\eta_k$, mini-batch size $m$, parameter initialization $ x_{0}$ and denote $M = \\lceil \\frac{N}{m} \\rceil$. \n\t\n\t{\\bf For} Epoch $k = 1,2,\\dots$\n\t\n\t\\begin{center}\n\tRandomly pick $B_t \\subset \\{1, 2, \\cdots, N \\}$ without replacement \\\\\n\twith $\\# B_t = m$ for $t = 1,2,\\cdots,M$.\n\t\\end{center}\n\t\n\t\\quad{\\bf For} mini-batch $t = 1:M$\n\t\n\t\\quad Compute the gradient on $B_{t}$:\n\t$$\n\tg_{t}(x) = \\frac{1}{m} \\sum_{i \\in B_{t}}  \\nabla f_i(x)\n\t$$\n\t\\quad Update $x$:\n\t\\begin{equation*}\n\tx  \\leftarrow  x - \\eta_k g_t(x),\n\t\\end{equation*} \n\t\\quad {\\bf EndFor}\n\n\n\t{\\bf EndFor}\n\\end{algorithm}\n\nTo \"randomly pick $B_i \\subset \\{1, 2, \\cdots, N \\}$ without replacement\nwith $\\# B_i = m$ for $i = 1,2,\\cdots,t$'', we usually just randomly shuffle the index set first and\nthen consecutively pick every $m$ elements in the shuffled index set. That is the reason why we  \nwould like to call the algorithm as shuffled SGD while this is the mostly used version of SGD in machine learning.\n\n\\begin{remark}\t\nLet us recall a general machine learning loss function\n\\begin{equation}\\label{key}\nL(\\theta) = \\frac{1}{N}\\sum_{i=1}^N \\ell(h(X_i; \\theta), Y_i),\n\\end{equation}\nwhere $\\{(X_i, Y_i)\\}_{i=1}^N$ correspond to these data pairs. \nFor example, $\\ell(\\cdot, \\cdot)$ takes cross-entropy and $h(x; \\theta) = \\bm p(x;\\theta)$ as we discussed in Section \\ref{sec:LR}.  \nThus, we have the following corresponding relation\n\\begin{equation*} \nf(x) \\leftrightsquigarrow L(\\theta), \\quad\nf_i(x) \\leftrightsquigarrow \\ell(h(X_i; \\theta), Y_i). \n\\end{equation*}\n\\end{remark}\n\n\n\n\\endinput\nHere we can take the expectation of $i_t$ independently from $\\{x_i, i = 1,\\ldots,t\\}$\nto obtain the second line of (\\ref{equ:L2SGD}) since $i_t$ is independent from \n$\\{x_i, i = 1,\\ldots,t\\}$ which is completely determined by $\\{i_j, j = 1,\\ldots,t - 1\\}$.\nAnd the third line of (\\ref{equ:L2SGD}) is obtained from the boundness of the gradients.\n\nHere shuffle  index and get mini-batch $B_1, \\cdots, B_{\\frac{N}{m}}$ means that $\\# B_i = m$ and \n\\begin{equation}\\label{key}\n\\{1, 2, \\cdots, N\\} = \\cup_{i = 1}^{\\frac{N}{m}} B_i,  \\quad B_i \\cap B_j = \\emptyset\n\\end{equation}\nwhere $B_i$ is chosen from $\\{1, 2, \\cdots, N\\}$ randomly.\n\n", "meta": {"hexsha": "5725cc16b8b3fbeb70fa6f673a1b08fb732f5c85", "size": 6462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/4 Training Algorithms/4.3-ChSGD.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/4 Training Algorithms/4.3-ChSGD.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/4 Training Algorithms/4.3-ChSGD.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.4642857143, "max_line_length": 138, "alphanum_fraction": 0.6176106469, "num_tokens": 2586, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245618, "lm_q2_score": 0.8791467675095294, "lm_q1q2_score": 0.7437075558443488}}
{"text": "\\subsection{$LU$ factorization, multiplier method}\n\nRemember that for a matrix $A$ to be written in the form $A=LU$, you must be able to reduce it to its {\\ef} without interchanging rows. The following method gives a process for calculating the $LU$ factorization of such a matrix $A$.\n\n\\begin{example}{$LU$ factorization}{lu-factorization}\nFind an $LU$ factorization for\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n1 & 2 & 3 \\\\\n2 & 3 & 1 \\\\\n-2 & 3 & -2\n\\end{mymatrix}\n\\end{equation*}\n\\end{example}\n\n\\begin{solution}\n\nWrite the matrix as the following product.\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n1 & 2 & 3 \\\\\n2 & 3 & 1 \\\\\n-2 & 3 & -2\n\\end{mymatrix}\n\\end{equation*}\n\nIn the matrix on the right, begin with the left row and zero\nout the entries below the top using the row operation which involves adding\na multiple of a row to another row. You do this and also update the matrix\non the left so that the product will be unchanged. Here is the first step.\nTake $-2$ times the top row and add to the second. Then take $2$ times the\ntop row and add to the second in the matrix on the left.\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n2 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n1 & 2 & 3 \\\\\n0 & -1 & -5 \\\\\n-2 & 3 & -2\n\\end{mymatrix}\n\\end{equation*}\nThe next step is to take $2$ times the top row and add to the bottom in the\nmatrix on the right. To ensure that the product is unchanged, you place a $%\n-2 $ in the bottom left in the matrix on the left. Thus the next step yields\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n2 & 1 & 0 \\\\\n-2 & 0 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n1 & 2 & 3 \\\\\n0 & -1 & -5 \\\\\n0 & 7 & 4\n\\end{mymatrix}\n\\end{equation*}\nNext take $7$ times the middle row on right and add to bottom row. Updating\nthe matrix on the left in a similar manner to what was done earlier,\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n2 & 1 & 0 \\\\\n-2 & -7 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n1 & 2 & 3 \\\\\n0 & -1 & -5 \\\\\n0 & 0 & -31\n\\end{mymatrix}\n\\end{equation*}\nAt this point, stop. You are done.\n\\end{solution}\n\nThe method just described is called the\nmultiplier method.\n", "meta": {"hexsha": "586c4420a9a6b602b64c2caa8d745a90bbb0f362", "size": 2197, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/matricesLUFactorizationMultiplier.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/matricesLUFactorizationMultiplier.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/matricesLUFactorizationMultiplier.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 27.4625, "max_line_length": 233, "alphanum_fraction": 0.6722803823, "num_tokens": 775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234877, "lm_q2_score": 0.8947894597898776, "lm_q1q2_score": 0.7436980462863224}}
{"text": "\\subsection{Eigenvalues distribution}\n\\label{sec:dist}\n\nOne way to investigate if there is any significant difference between the regular and random SOMs is to compare their neural responses to the same random stimuli. Therefore, we measure the neural activity and build a covariance matrix out of it. Then, we compute the eigenvalues of the covariance matrix (or Gram matrix) and we estimate a probability distribution. Thus, we can compare the eigenvalues distributions of the two maps and compare them to each other. If the distributions are close enough in the sense of Wasserstein distance then the two SOMs are similar in terms of neural activation.  A Gram matrix is an $n \\times n$ matrix given by where $n$ is the number of neurons of the map and ${\\bf Y} \\in \\mathbb{R}^{n \\times m}$ is a matrix for which each column is the activation of all $n$ neurons to a random stimulus.\n\nFrom a computational point of view we construct the matrix ${\\bf Y}$ by applying a set of stimuli to the self-organized map and computing the activity of each neuron within the map. This implies that ${\\bf Y} \\in \\mathbb{R}^{m \\times n}$, where $m=1024$ (the number of neurons) and $n={2, 3}$ (two- or three-dimensional input samples). Then we compute the covariance or Gram matrix as ${\\bf M} = {\\bf Y}{\\bf Y}^T \\in \\mathbb{R}^{n \\times n}$, where $n$ is the number of neurons. Then we compute the eigenvalues and obtain their distribution by sampling the activity of neurons of each experiment for $200$ different initial conditions using $50$ input sample each time. At the end of sampling we get an \\emph{ensemble} of $200$ Gram matrices and finally we estimate the probability density of the eigenvalues on each \\emph{ensemble} by applying a Kernel Density Estimation method~\\citep{Parzen:1962} (KDE) with a Gaussian kernel and bandwidth $h=0.4$. This allows us to quantify any differences on the distributions of the regular and randomized SOMs by calculating the Earth-Mover or Wasserstein-1 distance over the two distributions (regular ($P$) and random SOM ($Q$)). The Wasserstein distance is computed as $W(P, Q) = \\inf_{\\gamma \\in \\Pi(P, Q)}\\{\\mathbb{E}_{(x, y) \\sim \\gamma}\\Big[||x - y||\\Big]\\}$, where $\\Pi(P, Q)$ denotes the set of all joint distributions $\\gamma (x, y)$, whose marginals are $P$ and $Q$, respectively. Intuitively, $\\gamma (x,y)$ indicates  how  much ``mass'' must be transported from $x$ to $y$ to transform the distribution $P$ into the distribution $Q$. \n\nThe distributions of the eigenvalues of the RSOM and the regular SOM are shown on figure~\\ref{fig:eigenvalues}. We can conclude that the two distributions are alike and do not suggest any significant difference between the two maps in terms of neural activity. This implies that the RSOM and the regular SOM have similar statistics of their neural activities. This means that the loss of information and the \\emph{stretch} to the input data from both RSOM and regular SOM are pretty close and the underlying  topology of the two maps do not really affect the neural activity. This is also confirmed\nby measuring the Wasserstein distance between the two distributions. The blue curve shows the regular SOM or distribution $P$ and the black curve the RSOM or distribution $Q$. The Wasserstein distance between the two distributions $P$ and $Q$ indicates that the two distributions are nearly identical on all datasets. The Wasserstein distances in Table~\\ref{table:distances}\nconfirm that the eigenvalues distributions of SOM and RSOM are almost identical indicating that both maps retain the\nsame amount of information after learning the representations of input spaces.\n\n\\begin{table}[!ht]\n  \\begin{center}\n    \\begin{tabular}{ll}\n        \\textbf{Experiment} & \\textbf{Wasserstein Distance} \\\\\n        \\hline\n        $2$D ring dataset               & $0.0000323$\\\\\n        $2$D uniform dataset with holes & $0.0000207$  \\\\\n        $3$D uniform dataset            & $0.0001583$ \\\\\n        MNIST dataset                   & $0.0015$ \\\\\n    \\end{tabular}\n      \\caption{\\textbf{Wasserstein distances of eigenvalues distributions.} We report here the Wasserstein \n      distances between eigenvalues distributions of SOM and RSOM for each of the four major experiments we\n      ran. The results indicate that the distributions are close pointing out that the SOM and RSOM capture\n      a similar level of information during training. For more information regarding how we computed the \n      eigenvalues distributions and the Wasserstein distance please see Section~\\ref{sec:dist}.}\n      \\label{table:distances}\n  \\end{center}\n\\end{table}\n\n\\begin{figure}\n  \\includegraphics[width=\\columnwidth]{eig-distributions-new.pdf}\n  %\n  \\caption{Eigenvalues distribution for \\textbf{A} 2D Ring dataset \\textbf{B} 2D uniform dataset with holes \\textbf{C} 3D uniform dataset and \\textbf{D} MNIST Dataset\n  }%\n  \\label{fig:eigenvalues}\n \\end{figure}", "meta": {"hexsha": "017cd8f29e0feb7955f5f325765c7283bde82087", "size": 4911, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "article-overleaf/05-appendix-F.tex", "max_stars_repo_name": "rougier/VSOM", "max_stars_repo_head_hexsha": "78e6eb924b5f89a0e6f42eb6bbe7971473a9abaa", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-20T06:27:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-11T22:20:28.000Z", "max_issues_repo_path": "article-overleaf/05-appendix-F.tex", "max_issues_repo_name": "rougier/VSOM", "max_issues_repo_head_hexsha": "78e6eb924b5f89a0e6f42eb6bbe7971473a9abaa", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "article-overleaf/05-appendix-F.tex", "max_forks_repo_name": "rougier/VSOM", "max_forks_repo_head_hexsha": "78e6eb924b5f89a0e6f42eb6bbe7971473a9abaa", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-03T04:41:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T04:41:57.000Z", "avg_line_length": 129.2368421053, "max_line_length": 1588, "alphanum_fraction": 0.7491345958, "num_tokens": 1199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025424, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7436980384341828}}
{"text": "\\section{Calculations}\n\\label{sec:calc}\n% CHANGE GB TO 1073741824 BYTES!!!\n\n%----------------------------------------------------------------------\n%           STORAGE\n%----------------------------------------------------------------------\n\\subsection{Storage}\n\nStorage requirements for 24 hours of 720p video data (.mp4):\n\\begin{equation*}\n\\begin{split}\nContinual & = \\left(\\frac{24 \\ hr}{1 \\ day}\\right)\\left(\\frac{60 \\ min}{1 \\ hr}\\right)\\left(\\frac{60 \\ sec}{ 1 \\ min}\\right)\\left(\\frac{17 \\ mbit}{1 \\ sec}\\right)\\left(\\frac{1 \\ byte}{8 \\ bit}\\right)\\left(\\frac{1 \\ GB}{1737441824 \\ byte}\\right) \\\\\n& = 170.99 \\ \\frac{GB}{day}\n\\end{split}\n\\end{equation*}\n\nBy limiting the active recording to moments where objects are detected, this storage requirement can be significantly lowered. Taking a theoretical family of 4 and a single dog, we can calculate for a minimum duration that the RPi2 is expected to record in 24 hours: \n\n\\begin{table}[H]\n\\centering\n\\caption{Known sighting during an average 24 hour day for a front door camera.}\n\\label{floor_table}\n\\begin{tabular}{@{}lcccc@{}}\n\\toprule\nType     & Qty & Duration (min) & Sighting/24 hr & Total  \\\\ \\midrule\nPerson   & 4   & 1              & 2               & 8      \\\\\nDog      & 1   & 1              & 2               & 2      \\\\\nDelivery & 2   & 1              & 1               & 2      \\\\ \\midrule\n         &     &                &                 & 12 min\n\\end{tabular}\n\\end{table}\n\nWith a minimum recording duration of 12 minutes based on the expected sightings (detected objects), the floor data requirements per 24 hours becomes:\n\n\\begin{equation*}\n\\begin{split}\nFloor \\ & = \\left(\\frac{12 \\ min}{1 \\ day}\\right)\\left(\\frac{60 \\ sec}{ 1 \\ min}\\right)\\left(\\frac{17 \\ Mbit}{1 \\ sec}\\right)\\left(\\frac{1 \\ byte}{8 \\ bit}\\right)\\left(\\frac{1 \\ GB}{1737441824 \\ byte}\\right) \\\\\n& = 0.000014254 \\ \\frac{GB}{day}\\Rightarrow 0.014254 \\ \\frac{MB}{day} \\Rightarrow 14.254 \\ \\frac{KB}{day}\n\\end{split}\n\\end{equation*}\n\n%----------------------------------------------------------------------\n%           NODS\n%----------------------------------------------------------------------\n\\subsection{Night Vision}\n\n\\subsubsection{Analog Light Sensor}\n\n\\begin{equation*}\n\\begin{split}\n    \\log\\left(I_{O}\\right) &= mx + b \\\\\n    I_{O} &= m\\log\\left(x\\right) + b \\\\\n    I_{O} &= 10\\log\\left(E_{v}\\right)\\left[l_{x}\\right]\n\\end{split}\n\\end{equation*}\n\nThe sensor has an output current range of $0\\mu A$--$50\\mu A$ between $1$ lux--$100000$ lux. The breakout board converts this current into a voltage using a $68K\\Omega$ resistor, giving a voltage output of $0V$--$3.4V$. Given the use-case of the light sensor, the $3.4V$ can be approximated to $3.3V$, which is a suitable voltage reference for the ATtiny85 microcontroller. With the output current range approximated to a voltage range of $0V$--$3.3V$ between $1$ lux--$100000$ lux,\n\n\\begin{equation*}\n\\begin{split}\n    log_{i} &= \\log\\left(l_{x \\ MAX} - l_{x \\ MIN}\\right) \\\\\n    &= \\log\\left(100000\\right) = 5 \\\\\n\\end{split}\n\\end{equation*}\n\nTo convert the analog value to a digital value, an 8-bit ADC is used:\n\\begin{equation*}\n    ADC = \\frac{log_{i}}{1024 \\ steps} = 0.00488\n\\end{equation*}\n\nFinally, the formula to obtain the final lux output, $l_{xo}$, on the RPi2:\n\n\\begin{equation*}\n%\\begin{split}\n    l_{xo} = 10^{raw_{i} \\times ADC} = 10^{raw_{i} \\times 0.00488}\n%\\end{split}\n\\end{equation*}\n\nwhere $raw_{i}$ is the raw value received by one of the analog pins on the ATtiny85.\\\\\n\n\\begin{figure}[H]\n    \\centering\n    \\makebox[\\textwidth][c]{\\includegraphics[width=0.2\\textwidth]{ChauSze_SeniorDesign_VDR.PNG}}\n    \\caption{Voltage divider for sensor voltage reference.}\n\\end{figure}\n\nSince 3.3V was chosen as the voltage reference value for the sensor, a voltage divider will be constructed in order to drop the 5V supply:\n\n\\begin{equation*}\n    V_{1} = V_{CC} \\frac{R_{2}}{R_{1} + R_{2}} = 5V \\frac{3.3K\\Omega}{1.7K\\Omega + 3.3K\\Omega} = 3.3V\n\\end{equation*}\n\n%----------------------------------------------------------------------\n%           LEDS\n%----------------------------------------------------------------------\n\\subsubsection{Driving the LEDs}\n\n\\paragraph{Single LED Iteration}\nThe 8mm IR LEDs have a forward voltage drop of 1.3V and a current recommendation of 100mA. A resistor is added in series to each IR LED with the values chosen by:\n\n\\begin{equation*}\n    R_{IR} = \\frac{V_{CC} - V_{D}}{I_{D}} = \\frac{5V - 1.3V}{100mA} = 37\\Omega\\approx 39\\Omega\n\\end{equation*}\n\n\\begin{equation*}\n    P_{D} = I_{D}^{2}R_{IR} = \\left(100mA\\right)^{2}\\left(39\\Omega\\right) = 0.39W\n\\end{equation*}\n\n\\begin{figure}[H]\n    \\centering\n    \\makebox[\\textwidth][c]{\\includegraphics[width=0.5\\textwidth]{ChauSze_SeniorDesign_IRLED.PNG}}\n    \\caption{Single LED circuit branch on the Night Vision block.}\n\\end{figure}\n\n\\paragraph{Series LED Iteration}\nAnother configuration that is being considered includes an additional IR LED onto each of the 3 ATtiny85 output pins. This changes the series resistor value to:\n\n\\begin{equation*}\n    R_{IR} = \\frac{V_{CC} - V_{D} - V_{D}}{I_{D}} = \\frac{5V - 1.3V - 1.3V}{100mA} = 24\\Omega\\approx 27\\Omega\n\\end{equation*}\n\n\\begin{equation*}\n    P_{D} = I_{D}^{2}R_{IR} = \\left(100mA\\right)^{2}\\left(27\\Omega\\right) = 0.27W\n\\end{equation*}\n\n\\begin{figure}[H]\n    \\centering\n    \\makebox[\\textwidth][c]{\\includegraphics[width=0.5\\textwidth]{ChauSze_SeniorDesign_IRLEDII.PNG}}\n    \\caption{Double LED circuit branch on the Night Vision block.}\n\\end{figure}\n\n%----------------------------------------------------------------------\n%           CV PRE-PROCESSING\n%----------------------------------------------------------------------\n\\subsection{Computer Vision: Pre-processing}\n\nBefore performing feature extraction, a given image--also known as a frame--is pre-processed in order to increase the accuracy of object-class detection. Some of these pre-processing steps also improve feature extraction during low-ambient light conditions. Some of these image processing techniques considers a given image in sections. This type of sectioning results in kernels, which is $m \\times n$ matrix ``windows'' of a given frame. Convolution is then performed on the matrix, which averages all of the pixels around the center-most pixel. \n\n\\begin{figure}[H]\n    \\centering\n    \\begin{subfigure}[b]{0.475\\textwidth}\n        \\includegraphics[width=\\textwidth]{ChauSze_SeniorDesign_CalcEx0.PNG}\n        \\caption{Original image.}\n        \\label{fig:CalcEx0}\n    \\end{subfigure}\n    ~ %add desired spacing between images, e. g. ~, \\quad, \\qquad, \\hfill etc. \n      %(or a blank line to force the subfigure onto a new line)\n    \\begin{subfigure}[b]{0.475\\textwidth}\n        \\includegraphics[width=\\textwidth]{ChauSze_SeniorDesign_CalcEx1.PNG}\n        \\caption{Converted to grayscale.}\n        \\label{fig:CalcEx1}\n    \\end{subfigure}\n    \\caption{An original image is converted to grayscale. A $3 \\times 3$ matrix is then sectioned off for further pre-processing. A grid is used in (b) to show individual pixel boundaries.}\\label{fig:CalcEx}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\makebox[\\textwidth][c]{\\includegraphics[width=0.875\\textwidth]{ChauSze_SeniorDesign_CalcEx2.PNG}}\n    \\caption{The values for each pixel within the $3 \\times 3$ matrix.}\n    \\label{fig:CalcEx2}\n\\end{figure}\n\nAs an arbitrary example, a $3 \\times 3$ matrix in Fig. \\ref{fig:CalcEx1}, bordered in red, will be considered for calculations.\n\n%\\begin{equation*}\n%    118 + 90 + 57 + 105 + 69 + 59 + 167 + 113 + 63 = 841\n%\\end{equation*}\n\n%----------------------------------------------------------------------\n%           GAUSSIAN\n%----------------------------------------------------------------------\n\\subsubsection{Gaussian Blurring}\n% http://www.pixelstech.net/article/1353768112-Gaussian-Blur-Algorithm\n% http://haishibai.blogspot.com/2009/09/image-processing-c-tutorial-4-gaussian.html\nBlurring--also known as smoothing--is an image processing technique where high frequency noise is removed from a given image at the cost of detail reduction. For the purposes of this system, blurring will improve edge detection \\cite[p.~28, 32]{mallat}.\n\nGaussian blurring was chosen due to its ability to utilize a weighted mean when averaging pixels in each frame. This specific blurring technique will allow for better performance when thresholding the frames. The name for this blurring technique comes from its use of a Gaussian function for calculations.\n\n\\begin{equation}\n    G(x, y) = \\frac{1}{\\sqrt{2\\pi\\delta}}e^{-\\frac{x^{2} + y^{2}}{2\\delta^{2}}}\n\\end{equation}\n\nUsing the example arbitrary window in the previous section, each pixel is assigned a coordinate:\n\n\\begin{equation*}\n    \\begin{bmatrix}\n        (-1, 1) & (0, 1) & (1, 1) \\\\\n        (-1, 0) & (0, 0) & (1, 0) \\\\\n        (-1, -1) & (0, -1) & (1, -1) \n    \\end{bmatrix}\n\\end{equation*}\n\nChoosing an arbitrary $\\delta$ value of 1.5 the center coordinate is calculated through the Gaussian function:\n\n\\begin{equation*}\n    G(0, 0) = \\frac{1}{\\sqrt{2\\pi 1.5}}e^{-\\frac{0^{2} + 0^{2}}{2 \\times 1.5^{2}}} = 0.0707\n\\end{equation*}\n\nCalculating the rest of the coordinates results in a weighted matrix:\n\n\\begin{equation*}\n    \\begin{bmatrix}\n        \\textcolor{rp}{0.0454} & \\textcolor{rb}{0.0566} & \\textcolor{rp}{0.0454} \\\\\n        \\textcolor{rb}{0.0566} & 0.0707 & \\textcolor{rb}{0.0566} \\\\\n        \\textcolor{rp}{0.0454} & \\textcolor{rb}{0.0566} & \\textcolor{rp}{0.0454}\n    \\end{bmatrix}\n\\end{equation*}\n\nThe sum of those values becomes:\n\n\\begin{equation*}\n        (0.0435 \\times 4) + (0.0566 \\times 4) + 0.0707 =  0.4787\n\\end{equation*}\n\nDividing by the summation will result in a weighted average matrix:\n\n\\begin{equation*}\n    \\frac{1}{0.479}\n    \\begin{bmatrix}\n        \\textcolor{rp}{0.0454} & \\textcolor{rb}{0.0566} & \\textcolor{rp}{0.0454} \\\\\n        \\textcolor{rb}{0.0566} & 0.0707 & \\textcolor{rb}{0.0566} \\\\\n        \\textcolor{rp}{0.0454} & \\textcolor{rb}{0.0566} & \\textcolor{rp}{0.0454}\n    \\end{bmatrix}\n    = \n    \\begin{bmatrix}\n        \\textcolor{rp}{0.0948} & \\textcolor{rb}{0.118} & \\textcolor{rp}{0.0948} \\\\\n        \\textcolor{rb}{0.118} & 0.148 & \\textcolor{rb}{0.118} \\\\\n        \\textcolor{rp}{0.0948} & \\textcolor{rb}{0.118} & \\textcolor{rp}{0.0948}\n    \\end{bmatrix}\n\\end{equation*}\n\nMultiplying each coordinate of the $3 \\times 3$ window will result in a Gaussian blur:\n\n\\begin{equation*}\n    \\begin{bmatrix}\n        (118 \\times 0.0948) & (90 \\times 0.118)& (57 \\times 0.0948) \\\\\n        (105 \\times 0.118) & (69 \\times 0.148) & (59 \\times 0.118)\\\\\n        (167 \\times 0.0948) & (113 \\times 0.118) & (63 \\times 0.0948) \n    \\end{bmatrix}\n    = \n    \\begin{bmatrix}\n        11.19 & 10.62 & 5.403 \\\\\n        12.39 & 10.21 & 6.962 \\\\\n        15.83 & 13.33 & 5.972 \n    \\end{bmatrix}\n\\end{equation*}\n\nFinally, summing up the values from the last matrix will result in the new value for the center-most pixel.\n\n\\begin{equation*}\n        11.19 + 10.62 + 5.403 + 12.39 + 10.21 + 6.962 + 15.83 + 13.33 + 5.972 = 91.907 \n\\end{equation*}\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{subfigure}[b]{0.475\\textwidth}\n        \\includegraphics[width=\\textwidth]{ChauSze_SeniorDesign_CalcEx2.PNG}\n        \\caption{Center pixel before Gaussian blur: 69.}\n        \\label{fig:CalcEx3}\n    \\end{subfigure}\n    ~ %add desired spacing between images, e. g. ~, \\quad, \\qquad, \\hfill etc. \n      %(or a blank line to force the subfigure onto a new line)\n    \\begin{subfigure}[b]{0.475\\textwidth}\n        \\includegraphics[width=\\textwidth]{ChauSze_SeniorDesign_CalcEx3.PNG}\n        \\caption{Center pixel after Gaussian blur: 93.}\n        \\label{fig:CalcEx4}\n    \\end{subfigure}\n    \\caption{Comparison of pixel values between the original $3 \\times 3$ window against one filtered with Gaussian blur.}\\label{fig:CalcEx5}\n\\end{figure}\n\nAs Fig. \\ref{fig:CalcEx4} shows, the resulting pixel value from a Gaussian blur performed in GNU Image Manipulation Program (GIMP) is within range of the calculated value.\n\n\\begin{equation*}\n    \\frac{\\mid GIMP - Calculated\\mid}{Calculated} \\times 100\\% = \\frac{\\mid93 - 91.907\\mid}{91.907} \\times 100\\% = 0.0119\\%\n\\end{equation*}\n\n%----------------------------------------------------------------------\n%           THRESH\n%----------------------------------------------------------------------\n%\\subsubsection{Thresholding}\n\n%----------------------------------------------------------------------\n%           CV DETECTION\n%----------------------------------------------------------------------\n\\subsection{Computer Vision: Detection}\n\nFacial detection is performed by searching a given image for features based on black and white rectangles \\cite{ViolaJones}. The calculation for the regions again uses matrix convolution.\n\nThe first step is a single pass through the entirety of a given image that computes the sum of all pixel values above and to the left ($+y, -x$) of the position being examined, inclusive. This is known as an integral table, that is:\n\n\\begin{equation}\n    I_{\\sum}\\left(x, y\\right) = \\sum_{\\substack{\n   x'\\leq x \\\\\n   y'\\leq y\n  }} i(x', y')\n\\end{equation}\n\nUsing the original window in Fig. \\ref{fig:CalcEx2}:\n\n\\begin{equation*}\n    \\begin{bmatrix}\n        (i_{(-1, 1)} = 118) & (i_{(0, 1)} = 208) & (i_{(1, 1)} = 265) \\\\\n        \n        (i_{(-1, 0)} = 223) & (\\ddots) & (\\vdots)\\\\\n        \n        (i_{(-1, -1)} = 390) & (\\cdots) & (i_{(1, -1)} = 841) \n    \\end{bmatrix}\n\\end{equation*}\n\nFeature identification is then performed using black and white rectangles over the integral table. The algorithm then passes feature types (various rectangles created by training the classifier using positive and negative results) over the integral table \\cite{haarTri}. Identifying features from this point on is based on a simple summation of the rectangle corners:\n\n\\begin{equation}\n    A_{M} = I(A) + I(C) - I(B) - I(D)\n\\end{equation}\n\n\n\\subsubsection{Haar}\n\nThe robustness of this method of object detection will be apparent with this final step. Consider Fig. \\ref{fig:CalcHaar2}. \n\n\\begin{figure}[H]\n    \\centering\n    \\begin{subfigure}[b]{0.475\\textwidth}\n        \\includegraphics[width=\\textwidth]{ChauSze_SeniorDesign_CalcHaar1.png}\n        \\caption{Haar line feature being applied to Fig. \\ref{fig:CalcEx1}. Points A to D corresponds to the white rectangle's corners.}\n        \\label{fig:CalcHaar1}\n    \\end{subfigure}\n    ~ %add desired spacing between images, e. g. ~, \\quad, \\qquad, \\hfill etc. \n      %(or a blank line to force the subfigure onto a new line)\n    \\begin{subfigure}[b]{0.475\\textwidth}\n        \\includegraphics[width=\\textwidth]{ChauSze_SeniorDesign_CalcHaar2.png}\n        \\caption{Computing the leftmost white rectangle of Fig. \\ref{fig:CalcEx1}'s integral image can be quickly achieved, allowing for real-time detection.}\n        \\label{fig:CalcHaar2}\n    \\end{subfigure}\n    \\caption{Facial detection through Haar-like features.}\n    \\label{fig:CalcHaar3}\n\\end{figure}\n\nBy analyzing the integral table of the original image, feature extraction becomes computationally inexpensive. If a $3 \\times 3$ rectangle is covering the integral table that was solved earlier, the resulting calculation is:\n\n\\begin{equation*}\n    A_{M} = I(A) + I(C) - I(B) - I(D) = 118 + 841 - 265 - 390 = 304\n\\end{equation*}\n  \n  This value is finally compared against the collection of rectangular Haar features collected during classifier training.\n  \n  Haar-like algorithm is grounded upon machine learning, a database of images containing positive and negative results for vehicles \\cite{vehicleFeatures}. Since the detection algorithm based on Haar features is scale invariant, a set of images can then be used to train a Haar classifier for vehicles \\cite{motionHaar}. This eliminates the use of blob analysis for vehicles.\n\n%----------------------------------------------------------------------\n%           ALGORITHMIC\n%----------------------------------------------------------------------\n%\\subsection{Algorithmic Helper Functions}\n\n%This section lists the calculations used in the software flowcharts.\n\n%\\subsubsection{Elapsed Time}\n\n%\\begin{equation*}\n    \n%\\end{equation*}\n\n%\\newpage\n%\\begin{multicols}{2}\n%\\begin{onehalfspacing}\n%\\printglossary\n%\\end{onehalfspacing}\n%\\end{multicols}", "meta": {"hexsha": "cb3f8efdf942d76fa13f6523fea8162805736798", "size": 16219, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/latex_calculations/calculations.tex", "max_stars_repo_name": "wodiesan/senior_design_spring", "max_stars_repo_head_hexsha": "a335d8e052fc71250d127ca24755e0e1dad81d30", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2016-03-26T03:46:09.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-30T17:29:43.000Z", "max_issues_repo_path": "documentation/latex_calculations/calculations.tex", "max_issues_repo_name": "wodiesan/senior_design_spring", "max_issues_repo_head_hexsha": "a335d8e052fc71250d127ca24755e0e1dad81d30", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "documentation/latex_calculations/calculations.tex", "max_forks_repo_name": "wodiesan/senior_design_spring", "max_forks_repo_head_hexsha": "a335d8e052fc71250d127ca24755e0e1dad81d30", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.0733695652, "max_line_length": 548, "alphanum_fraction": 0.6296935693, "num_tokens": 4849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.8311430541321951, "lm_q1q2_score": 0.7436980380023887}}
{"text": "%\n% Chapter 3.2\n%\n\n\\section*{3.2 The Mean Value Theorem}\n\n\\subsection*{Rolle's Theorem}\n\nLet \\(f\\) be a function that satisfies the following three hypotheses:\n\\begin{enumerate}\n    \\item \\(f\\) is continuous on the closed interval \\([a, b]\\).\n    \\item \\(f\\) is differentiable on the open interval \\((a, b)\\).\n    \\item \\(f(a)=f(b)\\)\n\\end{enumerate}\nThen there is a number \\(c\\) in \\((a, b)\\) such that \\(f'(c)=0\\).\n\n\\subsection*{Mean Value Theorem}\n\nLet \\(f\\) be a function that satisfies the following hypothesis:\n\\begin{enumerate}\n    \\item \\(f\\) is continuous on the closed interval \\([a, b]\\).\n    \\item \\(f\\) is differentiable on the open interval \\((a, b)\\).\n\\end{enumerate}\nThen there is \\(c\\) in \\((a, b)\\) such that\n$$f'(c)=\\frac{f(b)-f(a)}{b-a} \\Leftrightarrow f(b)-f(a)=f'(c)(b-a)$$\n\\\\\nIf \\(f'(x)=0\\) for all \\(x\\) in an interval \\((a, b)\\), then \\(f\\) is constant on \\((a, b)\\).\n", "meta": {"hexsha": "2636966d805e411d3169ec68638bdc091638fa61", "size": 892, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/3-2.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/3-2.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/3-2.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.8571428571, "max_line_length": 93, "alphanum_fraction": 0.6098654709, "num_tokens": 297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7436980356416919}}
{"text": "\\section{Calculus in Real Vector Spaces}\r\n\\subsection{Stationary Points}\r\nLet $C^2(\\mathbb R^2)$ denote the collection of twice differentiable functions $\\mathbb R^n\\to\\mathbb R$ with continuous second derivatives.\r\n\\begin{definition}\r\n    Let $f\\in C^2(\\mathbb R^n)$.\r\n    A point $\\underline{a}\\in\\mathbb R^n$ is stationary (or is a stationary point of $f$) if $\\nabla f(\\underline{a})=\\underline{0}$.\r\n\\end{definition}\r\nIf we expand $f$ near one of its stationary points $\\underline{x}=\\underline{a}$, then\r\n\\begin{align*}\r\n    f(\\underline{x})&=f(\\underline{a})+(\\underline{x}-\\underline{a})\\cdot\\nabla f+\\frac{1}{2}(x_i-a_i)(x_j-a_j)\\frac{\\partial^2f}{\\partial x_i\\partial x_j}(\\underline{a})+o(|\\underline{x}-\\underline{a}|^2)\\\\\r\n    &=f(\\underline{a})+\\frac{1}{2}(\\underline{x}-\\underline{a})^\\top H(\\underline{a})(\\underline{x}-\\underline{a})\r\n\\end{align*}\r\nWhere $H_{ij}(\\underline{a})=\\partial^2f/\\partial x_i\\partial x_j(\\underline{a})$ is the Hessian, which is a real symmetric matrix for every $\\underline{a}$.\\\\\r\nShift the origin to set $\\underline{a}=\\underline{0}$ and write $H=H(\\underline{0})$.\r\nAs $H$ is real symmetric, we know that in another orthonormal basis $H$ has the form $H=\\operatorname{diag}(\\lambda_1,\\ldots,\\lambda_n)$, hence in this new coordinate system,\r\n$$f(\\underline{x})-f(\\underline{0})=\\frac{1}{2}\\sum_{i=1}^n\\lambda_ix_i^2+o(|x|^2)$$\r\nTherefore,\r\n\\begin{theorem}\r\n    Let $\\lambda_i$ as before, then if $\\forall i,\\lambda_i>0$, then $\\underline{0}$ is a local minimum.\\\\\r\n    If instead $\\forall i,\\lambda_i<0$, then $\\underline{0}$ is a local maximum.\\\\\r\n    If some of the eigenvalues are positive and some are negative, then it is a saddle point.\\\\\r\n    If some $i$ has $\\lambda_i=0$, \r\n\\end{theorem}\r\nIf some $i$ has $\\lambda_i=0$, we have to look at higher order terms in the Taylor series.\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nIn the special case where $n=2$, we have $\\det H=\\lambda_1\\lambda_2$ and $\\operatorname{tr} H=\\lambda_1+\\lambda_2$, both of which are easier to calculate than the actual eigenvalues, so we can formulate a corollary to make things easier.\r\n\\begin{corollary}\r\n    If $\\det H>0,\\operatorname{tr}H>0$, then it is a local minimum.\\\\\r\n    If $\\det H>0,\\operatorname{tr}H<0$, it is a local maximum.\\\\\r\n    If $\\det H<0$, it is a saddle point.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\nDespite these results, one should note that the actual (global) maxima and minima might occur at boundaries where we may not have $\\nabla f=0$.\\\\\r\nAlso, there are plenty of examples of functions who only have saddle points.\r\nConsider a harmonic function $f$ on $D\\subset\\mathbb R^2$, i.e. $f_{xx}+f_{yy}=0$, then at a stationary point we necessarily have $\\operatorname{tr}H=0$, hence either $\\det H=0$ or it is a saddle point.\\\\\r\nBut of course, the theorem and corollary can help a lot in classifying stationary points.\r\n\\begin{example}\r\n    Let $f(x,y)=x^3+y^3-3xy$, then $\\nabla f=(3x^2-3y,3y^2-3x)^\\top$, so the only stationary points are $(x,y)=(0,0),(1,1)$.\r\n    $$H=\\begin{pmatrix}\r\n        6x&-3\\\\\r\n        -3&6y\r\n    \\end{pmatrix}$$\r\n    Hence, by the corollary, $(0,0)$ is a saddle point while $(1,1)$ is a minimum.\r\n    One can easily produce a phase diagram using these information.\r\n\\end{example}\r\n\\subsection{Constraints and Lagrange Multipliers}\r\nThe optimisation problems in $\\mathbb R^n$ are most likely coming with some sort of constraints.\r\nWe first illustrate this by way of an example\r\n\\begin{example}\r\n    We want to find a circle centered at $(0,0)$ with smallest radius which intersects the parabola $y=x^2-1$.\r\n    Naturally, there are many ways to do this.\r\n    One can solve the problem directly by simply substitution\r\n    $$x^2+y^2=x^2+(x^2-1)^2=x^4-x^2+1$$\r\n    which minimum is $3/4$ by either calculus or completing square.\r\n    So the smallest radius is $\\sqrt{3}/2$.\\\\\r\n    The second method to solve this probelm, which are are going to use, is called the Lagrange multipliers.\r\n    Define a new function\r\n    $$h(x,y,\\lambda)=f(x,y)-\\lambda g(x,y)$$\r\n    where $f(x,y)=x^2+y^2$ is the function we want to minimise and $g(x,y)=y-x^2+1$ which vanishes if $(x,y)$ is on the parabola.\r\n    $\\lambda$ here is called the Lagrange multiplier.\r\n    We now try to extremise $h$ over $x,y,\\lambda$.\r\n    Naturally, we take the particial derivatives\r\n    $$\\begin{cases}\r\n        \\partial h/\\partial x=2x+2\\lambda x\\\\\r\n        \\partial h/\\partial y=2y-\\lambda\\\\\r\n        \\partial h/\\partial\\lambda=y-x^2+1\r\n    \\end{cases}$$\r\n    Hence the stationary point of $h$ are at $(x,y)=(0,-1),(\\pm 1/\\sqrt{2},-1/2)$.\r\n    Plugging in yields the same solution.\r\n\\end{example}\r\nWhy does the method of Lagrange multiplier work?\r\nGeometrically, if we want to minimise a function $f$ subject to $g=0$.\r\nNow $\\nabla g$ is always perpendicular to $g=0$.\r\nThen, suppose the minimum of $f$ is $c$, then the graph of $f(x)=c$ would touch $g(x)=0$, therefore their gradients there are parallel, so $\\nabla f=\\lambda\\nabla g$ for some $\\lambda$, hence $\\nabla h=0$ (note that $\\partial h/\\partial\\lambda=0$ iff $g=0$), which is exactly the system we want to solve in the last part.\\\\\r\nIf there are many constraints $g_\\alpha(\\underline{x})=0$ of the minimisation problem of $f:\\mathbb R^k\\to\\mathbb R$ where $\\alpha$ ranges from $1$ to $k$, we can define an analogous\r\n$$h(x_1,\\ldots,x_k,\\lambda_1,\\ldots,\\lambda_k)=f(\\underline{x})-\\lambda_\\alpha g_\\alpha(\\underline{x})$$\r\nthen finding the stationary points of $h$ can help to determine the minimisation problem.", "meta": {"hexsha": "a0aa589265c85586ff67a963622f5b7ce40ab28f", "size": 5545, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/rn.tex", "max_stars_repo_name": "david-bai-notes/IB-Variational-Principles", "max_stars_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1/rn.tex", "max_issues_repo_name": "david-bai-notes/IB-Variational-Principles", "max_issues_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1/rn.tex", "max_forks_repo_name": "david-bai-notes/IB-Variational-Principles", "max_forks_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.4567901235, "max_line_length": 324, "alphanum_fraction": 0.6822362489, "num_tokens": 1723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8856314692902446, "lm_q1q2_score": 0.7436948276024921}}
{"text": "\\documentclass{article}\n\n\\usepackage{stmaryrd}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{relsize} \n\\usepackage{bm} \n\\usepackage{IEEEtrantools}\n\\usepackage{graphicx}\n\\usepackage[font={small,it}, width=\\textwidth]{caption}\n\\usepackage{subcaption}\n\\usepackage{hyperref}\n\\usepackage{cases}\n\\usepackage{xfrac}\n\\usepackage{comment}\n\\usepackage{framed}\n\\usepackage[ ddmmyyyy ]{datetime} \n\\usepackage{fancyhdr}\n\\usepackage{enumitem}\n\\usepackage{cite}\n\\usepackage{float}\n\\usepackage{multirow}\n\n\\newcommand{\\source}[1]{\\caption*{\\hfill Source: {#1}} }\n\n\\usepackage{mathtools}\n\\DeclareMathOperator{\\sign}{sign}\n\\DeclareMathOperator{\\sat}{sat}\n\n\\oddsidemargin = 20pt\n\\textwidth = 420pt\n\n\\hypersetup{\n     colorlinks   = true,\n     linkcolor    = blue\n}\n\n\\title{The Beagle Project}\n\\author{Marcus Greiff}\n\n\\begin{document}\n\\maketitle\n\n\\section{Introduction}\nThis project is still in it's early stages, and the following document simply defines the equations of the DC motor model which is used to simulate the currently implemented regulators. A more detailed derivation and definitions will be added as soon as possible.\n\\section{Motor model}\n\\subsubsection*{Governing equations}\nAssuming a simple DC motor model with constant magnetic field, Newton's and Kirchoff's laws can be used to derive the governing equations \n\\begin{flalign}\n\\frac{d^2\\theta(t)}{dt^2} &= \\frac{1}{J}\\Big(K_t i(t) - b\\frac{d\\theta (t)}{d t}\\Big)\\\\\n\\frac{di(t)}{dt} &= \\frac{1}{L}\\Big(-Ri(t) + V(t) - K_e\\frac{d\\theta(t)}{dt}\\Big)\n\\end{flalign}\n\\subsubsection*{Statespace form}\n\\begin{flalign}\n\\dot{\\mathbf{x}}(t) &= \\mathbf{A}\\mathbf{x}(t) + \\mathbf{B}\\mathbf{u}(t)\\\\\n\\mathbf{y}(t) &= \\mathbf{C}\\mathbf{x}(t)\n\\end{flalign}\nLet\n\\begin{equation}\n\\mathbf{x}(t) = \\begin{bmatrix}\\theta(t) & \\dot{\\theta}(t) & i(t) \\end{bmatrix}^T, \\qquad \\mathbf{u}(t) = V(t)\n\\end{equation}\nthen\n\\begin{equation}\n\\mathbf{A} =\\begin{bmatrix} 0 & 1 & 0 \\\\ 0 & -b/J & K_t/J  \\\\ 0 & -K_e/L & -R/L  \\end{bmatrix}, \\quad\n\\mathbf{B} =\\begin{bmatrix} 0  \\\\ 0  \\\\ 1/L  \\end{bmatrix}, \\quad\n\\mathbf{C} = \\mathbb{I}_{3\\times 3}\n\\end{equation}\n\\subsubsection*{Laplace domain equivalent}\nLet\n\\begin{equation}\n\\mathcal{L}\\begin{Bmatrix}\\Theta(t)\\end{Bmatrix}_s=\\Theta(s), \\quad\\mathcal{L}\\begin{Bmatrix}i(t)\\end{Bmatrix}_s=I(s), \\quad\\mathcal{L}\\begin{Bmatrix}V(t)\\end{Bmatrix}_s=V(s), \\quad\n\\end{equation}\nthen\n\\begin{flalign}\ns^2\\Theta(s) &= \\frac{1}{J}\\Big(K_t I(s) - b s\\Theta(s)\\Big)\\\\\nsI(s) &= \\frac{1}{L}\\Big(-R I(s) + V(s) - K_e s\\Theta(s)\\Big)\n\\end{flalign}\n\\subsubsection*{transfer function from $V(s)$ to $\\Theta(s)$}\n\\begin{flalign}\nG(s)_{U\\rightarrow\\Theta} &= \\frac{\\Theta(s)}{U(s)} =  \\frac{K_t}{s((sL+R)(J s +b) +K_tK_e)}U(s)\n\\end{flalign}\nUsing a partial fraction decomposition, this may be written\n\\begin{flalign}\nG(s)_{U\\rightarrow\\Theta} = \\frac{A}{s} - \\frac{B + Cs}{s^2 + D s + E} = \\frac{A}{s} + \\frac{B}{s^2 + D s + E}+\\frac{Cs}{s^2 + D s + E}\n\\end{flalign}\n\\begin{flalign}\n\\frac{Kt}{(s*(R*b + Ke*Kt))} - \\frac{(J*Kt*R + Kt*L*b)/(R*b + Ke*Kt) + (J*Kt*L*s)/(R*b + Ke*Kt)}{J*L*s^2 + (L*b + J*R)*s + R*b + Ke*Kt}\n\\end{flalign}\n\\subsubsection*{transfer function from $V(s)$ to $I(s)$}\n\n\\subsubsection*{LS-estimation}\nUsing a Bilinear z-transform, it is evident that\n\\begin{flalign}\n\\mathcal{Z}\\begin{Bmatrix}G(s)\\end{Bmatrix}_z = \\frac{a_2z^2 + a_1z^1 + a_0}{z^3 + b_2z^2 + b_1z^1 + b_0}\n\\end{flalign}\nLetting\n\\begin{equation}\n\\begin{cases}\n\\theta =  \\begin{bmatrix}a_2 & a_1 & a_0 & b_2 & b_1 & b_0 \\end{bmatrix}^T\\\\\n\\varphi(t-1) = \\begin{bmatrix}u(t-1)& u(t-2) & u(t-3) & -y(t-1)& -y(t-2) & -y(t-3) \\end{bmatrix}^T\n\\end{cases}\n\\end{equation}\nwe note that the discrete time difference equation can be written\n\\begin{equation}\ny(t) = \\varphi(t-1)^T\\theta\n\\end{equation}\n\n\\subsection{Controllers}\n\\begin{flalign}\n\\dot {x}_1 &= x_2\\\\\n\\dot {x}_2 &= (-bx_2 + K_tx_3)/J  \\\\\n\\dot {x}_3 &= (-K_ex_2 -Rx_3+ u)/L\n\\end{flalign}\nwith\n\\begin{equation}\nV(x_1, x_2, x_3) = \\frac{1}{2}(x_1^2 + x_2^2 + x_3^2)\n\\end{equation}\n\\begin{flalign}\n\\frac{\\partial V(x_1, x_2, x_3)}{\\partial t} &= {x}_1\\dot{x}_1 + {x}_2\\dot{x}_2 + {x}_3\\dot{x}_3\\\\\n&= {x}_1x_2 + {x}_2(-bx_2 + K_tx_3)/J+ {x}_3(-K_ex_2 -Rx_3+ u)/L\\\\\n&= {x}_1x_2 -bx_2^2/J + (K_t/J -K_e/L)x_2{x}_3 -Rx_3^2/L+ u/L\n\\end{flalign}\n\\newpage\\bibliography{Bibliography}{}\n\\bibliographystyle{IEEEtran}\n\\end{document}", "meta": {"hexsha": "175cd1e084110e50beee97b619f94b9091894b02", "size": 4328, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "beagle_project/report/report.tex", "max_stars_repo_name": "mgreiff/control_theory", "max_stars_repo_head_hexsha": "9188975d330a3cd712d042c599abd537e98d3296", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "beagle_project/report/report.tex", "max_issues_repo_name": "mgreiff/control_theory", "max_issues_repo_head_hexsha": "9188975d330a3cd712d042c599abd537e98d3296", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "beagle_project/report/report.tex", "max_forks_repo_name": "mgreiff/control_theory", "max_forks_repo_head_hexsha": "9188975d330a3cd712d042c599abd537e98d3296", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-06-22T10:03:14.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-22T10:03:14.000Z", "avg_line_length": 34.3492063492, "max_line_length": 263, "alphanum_fraction": 0.6684380776, "num_tokens": 1780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436728, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7436948177132698}}
{"text": "% chapter included in vclmanual.tex\n\\documentclass[vcl_manual.tex]{subfiles}\n\\begin{document}\n\n\n\\chapter{Examples}\\label{chap:Examples}\n\\flushleft\n\nThis example calculates the polynomial $x^3 + 2\\cdot x^2 - 5\\cdot x + 1$ on a floating point vector. The order of calculation is specified by parentheses in order to make shorter dependency chains.\n\n\\begin{example}\n\\label{examplePolynomial}\n\\end{example}\n\\begin{lstlisting}[frame=single]\nVec4f polynomial (Vec4f x) {\n    return (x + 2.0f) * (x * x) + ((-5.0f) * x + 1.0f);\n}\n\\end{lstlisting}\n\\vspacebig\n\nIn 64-bit Windows, you may add \\codei{\\_\\_vectorcall} and use a Clang or Microsoft compiler. This makes sure that vector parameters are transferred in registers rather than in memory. This is not needed when the function is inlined or when compiling for other platforms than Windows:\n\n\\begin{example}\n\\label{examplePolynomialVectorcall}\n\\end{example}\n\\begin{lstlisting}[frame=single]\nVec4f __vectorcall polynomial (Vec4f x) {\n    return (x + 2.0f) * (x * x) + ((-5.0f) * x + 1.0f);\n}\n\\end{lstlisting}\n\\vspacebig\n\n\nThe next example transposes a 4x4 matrix, using the AVX2 instruction set.\n\n\\begin{example}\n\\label{exampleTranspose4x4}\n\\end{example}\n\\begin{lstlisting}[frame=single]\nvoid transpose(float matrix[4][4]) {\n    Vec8f row01, row23, col01, col23;\n    // load first two rows\n    row01.load(&matrix[0][0]);\n    // load next two rows\n    row23.load(&matrix[2][0]);\n    // reorder into columns\n    col01 = blend8f<0,4, 8,12,1,5, 9,13>(row01, row23);\n    col23 = blend8f<2,6,10,14,3,7,11,15>(row01, row23);\n    // store columns into rows\n    col01.store(&matrix[0][0]);\n    col23.store(&matrix[2][0]);\n}\n\\end{lstlisting}\n\\vspacesmall\n\nSame example with AVX512:\n\n\\begin{example}\n\\label{exampleTranspose4x4avx512}\n\\end{example}\n\\begin{lstlisting}[frame=single]\nvoid transpose(float matrix[4][4]) {\n    Vec16f rows, columns;\n    // load entire matrix as rows\n    rows.load(&matrix[0][0]);\n    // reorder into columns\n    columns = permute16f<0,4,8,12,1,5,9,13,\n        2,6,10,14,3,7,11,15>(rows);\n    // store columns into rows\n    columns.store(&matrix[0][0]);\n}\n\\end{lstlisting}\n\\vspacebig\n\nThe next example makes a matrix multiplication of two 4x4 matrixes.\n\n\\begin{example}\n\\label{exampleMatrixMul4x4}\n\\end{example}\n\\begin{lstlisting}[frame=single]\nvoid matrixmul(float A[4][4], float B[4][4], float M[4][4]){\n    // calculates M = A*B\n    Vec4f Brow[4], Mrow[4];\n    int i, j;\n    // load B as rows\n    for (i = 0; i < 4; i++) {\n        Brow[i].load(&B[i][0]);\n    }\n    // loop for A and M rows\n    for (i = 0; i < 4; i++) {\n        Mrow[i] = Vec4f(0.0f);\n        // loop for A columns, B rows\n        for (j = 0; j < 4; j++) {\n            Mrow[i] += Brow[j] * A[i][j];\n        }\n    }\n    // store M\n    for (i = 0; i < 4; i++) {\n        Mrow[i].store(&M[i][0]);\n    }\n}\n\\end{lstlisting}\n\\vspacebig\n\n\nThe next example makes a table of the sin function and gets sin(x) and cos(x) by table lookup.\n\n\\begin{example}\n\\label{exampleSinTable}\n\\end{example}\n\\begin{lstlisting}[frame=single]\n\n#include <cmath>\n\nconst double pi = 3.14159265358979323846;\n\n// length of table. Must be a power of 2.\n#define sin_tablelen 1024\n// the accuracy of table lookup is +/- pi/sin_tablelen\n\nclass SinTable {\nprotected:\n    float table[sin_tablelen];\n    float resolution;\n    float rres;  // 1./resolution\npublic:\n    SinTable();  // constructor\n    Vec4f sin(Vec4f x);\n    Vec4f cos(Vec4f x);\n};\n\nSinTable::SinTable() {  // constructor\n    // compute resolution\n    resolution = float(2.0 * pi / sin_tablelen);\n    rres = 1.0f / resolution;\n    // Initialize table (No need to use vectors here because this \n    // is calculated only once:)\n    for (int i = 0; i < sin_tablelen; i++) {\n        table[i] = sinf((float)i * resolution);\n    }\n}\n\nVec4f SinTable::sin(Vec4f x) {\n    // calculate sin by table lookup\n    Vec4i index = roundi(x * rres);\n    // modulo tablelen equivalent to modulo 2*pi\n    index &= sin_tablelen - 1;\n    // look up in table\n    return lookup<sin_tablelen>(index, table);\n}\n\nVec4f SinTable::cos(Vec4f x) {\n    // calculate cos by table lookup\n    Vec4i index = roundi(x * rres) + sin_tablelen/4;\n    // modulo tablelen equivalent to modulo 2*pi\n    index &= sin_tablelen - 1;\n    // look up in table\n    return lookup<sin_tablelen>(index, table);\n}\n\nint main() {\n    SinTable sintab;\n    Vec4f a(0.0f, 0.5f, 1.0f, 1.5f);\n    Vec4f b = sintab.sin(a);\n    // b = (0.0000 0.4768 0.8416 0.9973)\n    // accuracy +/- 0.003\n    ...\n    return 0;\n}\n\\end{lstlisting}\n\\vspacesmall\n\n\n\\end{document}", "meta": {"hexsha": "2e06bf16fd0fccf8c9924a7ad9cdd36192ef649c", "size": 4552, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "vcl_examples.tex", "max_stars_repo_name": "haferburg/manual", "max_stars_repo_head_hexsha": "c7b365e7a7bbd3c155ff85edf9c6084311b0c10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2019-08-05T13:15:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T03:17:29.000Z", "max_issues_repo_path": "vcl_examples.tex", "max_issues_repo_name": "haferburg/manual", "max_issues_repo_head_hexsha": "c7b365e7a7bbd3c155ff85edf9c6084311b0c10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-08-03T05:13:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-03T05:13:02.000Z", "max_forks_repo_path": "vcl_examples.tex", "max_forks_repo_name": "haferburg/manual", "max_forks_repo_head_hexsha": "c7b365e7a7bbd3c155ff85edf9c6084311b0c10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-08-08T08:28:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-02T08:39:06.000Z", "avg_line_length": 26.1609195402, "max_line_length": 283, "alphanum_fraction": 0.6482864675, "num_tokens": 1488, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7435864045868261}}
{"text": "\n\\begin{tabular}{lcll}\\hline\nVariate    & $x$         & \\ccode{double} & $\\mu \\leq x < \\infty$ \\\\\nLocation   & $\\mu$       & \\ccode{double} & $-\\infty < \\mu < \\infty$\\\\\nScale      & $\\lambda$   & \\ccode{double} & $\\lambda > 0$ \\\\ \\hline\n\\end{tabular}\n\nThe probability density function (PDF) is:\n\n\\begin{equation}\nP(X=x) =  \\lambda e^{-\\lambda (x - \\mu)}\n\\end{equation}\n\nThe cumulative distribution function (CDF) is:\n\n\\begin{equation}\nP(X \\leq x) = 1 - e^{-\\lambda (x - \\mu)}\n\\end{equation}\n\n\n\\subsection{Sampling}\n\nAn exponentially distributed sample $x$ is generated by the\ntransformation method, using the fact that if $R$ is uniformly\ndistributed on $(0,1]$, $1-R$ is uniformly distributed on $[0,1)$:\n\n\\[\n   R = \\mbox{uniform positive sample in (0,1]}\\\\\n   x = \\mu - \\frac{1}{lambda} \\log(R)\n\\]\n\n\\subsection{Maximum likelihood fitting}\n\nThe maximum likelihood estimate $\\hat{\\lambda}$ is $\\frac{1}{\\sum_i\nx_i}$. The distribution of $\\frac{\\lambda}{\\hat{\\lambda}}$ is\napproximately normal with mean 1 and standard error $\\frac{1}{\\sqrt{N}}$\n\\citep{Lawless82}.\n\n% xref J1/p49 for derivation of standard error.\n\n\n", "meta": {"hexsha": "55cb448e45c2822de8dd75e4b96e36d698fede66", "size": 1115, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hmmer-3.3/easel/esl_exponential.tex", "max_stars_repo_name": "WooMichael/Project_Mendel", "max_stars_repo_head_hexsha": "ff572f7ce7f9beca148f7351cf34dbf11d670bc8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hmmer-3.3/easel/esl_exponential.tex", "max_issues_repo_name": "WooMichael/Project_Mendel", "max_issues_repo_head_hexsha": "ff572f7ce7f9beca148f7351cf34dbf11d670bc8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hmmer-3.3/easel/esl_exponential.tex", "max_forks_repo_name": "WooMichael/Project_Mendel", "max_forks_repo_head_hexsha": "ff572f7ce7f9beca148f7351cf34dbf11d670bc8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.5476190476, "max_line_length": 72, "alphanum_fraction": 0.6466367713, "num_tokens": 366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7435863897648912}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{dsfont}\n\\usepackage{amsthm}\n\\newtheorem*{theorem}{Theorem}\n\\begin{document}\n\\setlength{\\parskip}{10pt plus 1pt minus 1pt}\n\\title{Coarse Geometry and Groups}\n\\author{Pranav Garg}\n\\maketitle\n\\section{Quasi-Isometry}\n\\subsection*{Definitions}\nLet $(X, d_X)$ and $(Y, d_Y)$ be metric spaces.\n\n$f:X\\rightarrow Y$ is said to be K-Lipschitz if\\[\\forall x_1, x_2\\in X, d_Y(f(x_1),f(x_2))\\leq K\\cdot d_X(x_1, x_2)\\]\n\n$f:X\\rightarrow Y$ is said to be (K, L) Coarse Lipschitz if\\[\\forall x_1, x_2 \\in X, d_Y(f(x_1),f(x_2)) \\leq K\\cdot d_X(x_1, x_2) + L\\]\n\n$(X,d_X)$ and $(Y, d_Y)$ are said to be bilipschitz if $\\exists f:X\\rightarrow Y$ and $g:Y\\rightarrow X$, lipschitz such that $f\\circ g=\\mathds{1}_Y$ and $g\\circ f=\\mathds{1}_X$.\n\n$f, g : X\\rightarrow Y$ coarse lipschitz. We say $f\\sim g$ if $\\exists c>0$ such that $\\forall x\\in X, d_Y(f(x), g(x))<c$.\n\n$(X,d_X)$ and $(Y, d_Y)$ are said to be quasi-isometric if $\\exists f : X\\rightarrow Y$ and $g : Y\\rightarrow X$, coarse lipschitz such that $f\\circ g\\sim \\mathds{1}_Y$ and $g\\circ f\\sim \\mathds{1}_X$.\n\n\\subsection*{Examples}\n\\begin{itemize}\n\n\\item $\\mathbb{Z}$ is quasi-isometric to $\\mathbb{R}$.\n\\item A bounded metric space is quasi-isometric to a point.\n\\item If $\\Gamma$ is a metric space, then the space of vertices is quasi-isometric to the space consisting of vertices and edges with the metric as defined in the section on graph metric.\n\\end{itemize}\n\\section{Word Metric}\nLet $G$ be a finitely generated group and $S$ be a finite generator set for $G$.\nFor $g\\in G$, define norm of $g$, \\[\\|g\\| = min\\{n \\geq 0 : \\exists \\alpha_1, \\alpha_2,..., \\alpha_n \\in S\\cup S^{-1}, g=\\alpha_1 \\alpha_2 ...\\alpha_n\\} \\]\n\nThis satisfies the following properties:\n\\begin{itemize}\n\\item $\\|g\\| = 0\\Leftrightarrow g=e$ where $e$ is the identity of $G$.\n\\item $\\|g^{-1}\\|=\\|g\\|$\n\\item $\\|g_1g_2\\|\\leq \\|g_1\\|+\\|g_2\\|$\n\\end{itemize}\nDefine the word metric $d$ on $G$ by \\[\\forall g,h\\in G,\\; d(g,h)=\\|g^{-1}h\\|\\]\nThe properties of the norm listed above can be used to prove that this is a metric.\n\\begin{theorem}\nIf $S_1$ and $S_2$ are finite generating sets of $G$ and $d_1$ and $d_2$ are the corresponding word metrics, then $(G,d_1)$ is bilipschitz to $(G,d_2)$.\n\\end{theorem}\n\\begin{proof}\nConsider $f:(G,d_1)\\rightarrow(G,d_2)$ and $h:(G,d_2)\\rightarrow(G,d_1)$, both identity maps. Clearly $f\\circ h$ and $h\\circ f$ are also identity maps.\n\nLet $k_1=max\\{\\|\\alpha\\|_{S_2}:\\alpha\\in S_1\\}.$\nAs $S_1$ is finite, so is $k_1$.\nNow, if $\\|g\\|_{S_1}=n_1$, then $\\exists \\alpha_1, \\alpha_2,...,\\alpha_n \\in S_1\\cup S^{-1}_1$ such that $g=\\alpha_1 \\alpha_2 ...\\alpha_n$\n\\[\\Rightarrow \\|g\\|_{S_2} \\leq \\|\\alpha_1 \\|_{S_2} + |\\alpha_2\\|_{S_2}+...+|\\alpha_n\\|_{S_2}\\]\n\\[\\therefore\\|g\\|_{S_2}\\leq \\underbrace{k_1+k_1+...+k_1}_{\\text{n times}}=k_1\\cdot\\|g\\|_{S_1}\\]\n\nWe have shown $\\|g\\|_{S_2}\\leq k_1\\|g\\|_{S_1}.$ By replacing $g$ by $g_1 g^{-1}_2$, for $g_1,g_2\\in G$, we get that $f$ is $k_1 -$lipschitz.\n\nSimilarly, we can construct a $k_2$ so that $h$ is $k_2 -$lipschitz.\n\nThus $(G,d_1)$ is bilipschitz to $(G,d_2)$.\n\\end{proof}\n\\subsection*{Cayley Graph}\nThe Cayley Graph on a finitely generated group $G$ with respect to a finite generator set $S$ is a graph with vertices as the set $G$ and edges as $E = \\{(g, g\\alpha ), \\alpha \\in S\\cup S^{-1}\\}$. The maps $i$ and $\\tau$ are defined as: $i(g,g\\alpha )=g$ and $\\tau (g,g\\alpha )=g\\alpha$. The involution is $\\overline{(g,g\\alpha)}=(g\\alpha,g)$.\n\nThe word metric could alternatively and equivalently be defined as the graph metric on the Cayley graph.\n\\section{Growth Function}\nLet $G$ be a finitely generated group and $S$ be a finite generator set for $G$.\nThe growth function for $G$ and $S$, $\\rho_{G,S}:\\mathbb{N}\\rightarrow\\mathbb{N}$ is defined as:\n\\[\\rho_{G,S}(r)=|\\{g\\in G\\; \\vert\\; \\|g\\|\\leq r \\}|\\]\n\nTwo growth functions $\\rho_1$ and $\\rho_2$ are defined to be equivalent, $\\rho_1\\sim\\rho_2$, if $\\exists k,c>0$ such that \\[\\forall r>0,\\;\\; \\frac{1}{k}\\rho_1(\\frac{r}{c})\\leq \\rho_2(r)\\leq k\\rho_1(cr)\\]\n\\begin{theorem}\nIf $S_1$ and $S_2$ are finite generating sets for $G$, then $\\rho_{G,S_1}\\sim\\rho_{G,S_2}$\n\\end{theorem}\n\\begin{proof}\nConstruct $k_1$ and $k_2$ as in the proof of the previous theorem.\n\nLet $c=max\\{k_1,k_2\\}$.\n\\[\\|g\\|_{S_2}\\leq r\\;\\Rightarrow\\;\\frac{r}{c}\\leq\\|g\\|_{S_1}\\leq cr\\]\n\\[\\Rightarrow\\{g\\in G:\\|g\\|_{S_1}\\geq \\frac{r}{c}\\}\\subseteq\\{g\\in G:\\|g\\|_{S_2}\\leq r\\}\\subseteq\\{g\\in G:\\|g\\|_{S_1}\\leq cr\\}\\]\n\\[\\therefore\\rho_{G,S_1}(\\frac{r}{c})\\leq\\rho_{G,S_2}\\leq\\rho_{G,S_1}(cr)\\]\n\\end{proof}\n\\begin{theorem}\nLet $\\rho_n(r)=r^n$, $\\rho_m(r)=r^m$. Then, $\\rho_n\\sim\\rho_m\\;\\Rightarrow\\;n=m$\n\\end{theorem}\n\\end{document}\n", "meta": {"hexsha": "8323001b7cbaccdc452b05af88d733b897944bf7", "size": 4728, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/coarse_wordmetric.tex", "max_stars_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_stars_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-12-28T05:53:38.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-20T05:56:59.000Z", "max_issues_repo_path": "src/coarse_wordmetric.tex", "max_issues_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_issues_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/coarse_wordmetric.tex", "max_forks_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_forks_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.7272727273, "max_line_length": 343, "alphanum_fraction": 0.6611675127, "num_tokens": 1890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604134, "lm_q2_score": 0.868826769445233, "lm_q1q2_score": 0.7435863743678598}}
{"text": "\n% This LaTeX was auto-generated from an M-file by MATLAB.\n% To make changes, update the M-file and republish this document.\n\n\n\n    \n    \n\n\\subsection*{dynamics\\_cp.m} \n\n\\begin{par}\n\\textbf{Summary:} Implements ths ODE for simulating the cart-pole dynamics.\n\\end{par} \\vspace{1em}\n\n\\begin{verbatim}  function dz = dynamics_cp(t, z, f)\\end{verbatim}\n    \\begin{par}\n\\textbf{Input arguments:}\n\\end{par} \\vspace{1em}\n\n\\begin{lstlisting}\n%\t\tt     current time step (called from ODE solver)\n%   z     state                                                    [4 x 1]\n%   f     (optional): force f(t)\n%\n% *Output arguments:*\n%\n%   dz    if 3 input arguments:      state derivative wrt time\n%         if only 2 input arguments: total mechanical energy\n%\n%\n% Note: It is assumed that the state variables are of the following order:\n%       x:        [m]     position of cart\n%       dx:       [m/s]   velocity of cart\n%       dtheta:   [rad/s] angular velocity\n%       theta:    [rad]   angle\n%\n%\n% A detailed derivation of the dynamics can be found in:\n%\n% M.P. Deisenroth:\n% Efficient Reinforcement Learning Using Gaussian Processes, Appendix C,\n% KIT Scientific Publishing, 2010.\n%\n% Copyright (C) 2008-2013 by\n% Marc Deisenroth, Andrew McHutchon, Joe Hall, and Carl Edward Rasmussen.\n%\n% Last modified: 2013-03-08\n\nfunction dz = dynamics_cp(t,z,f)\n\\end{lstlisting}\n\n\n\\subsection*{Code} \n\n\n\\begin{lstlisting}\nl = 0.5;  % [m]      length of pendulum\nm = 0.5;  % [kg]     mass of pendulum\nM = 0.5;  % [kg]     mass of cart\nb = 0.1;  % [N/m/s]  coefficient of friction between cart and ground\ng = 9.82; % [m/s^2]  acceleration of gravity\n\nif nargin==3\n  dz = zeros(4,1);\n  dz(1) = z(2);\n  dz(2) = ( 2*m*l*z(3)^2*sin(z(4)) + 3*m*g*sin(z(4))*cos(z(4)) ...\n          + 4*f(t) - 4*b*z(2) )/( 4*(M+m)-3*m*cos(z(4))^2 );\n  dz(3) = (-3*m*l*z(3)^2*sin(z(4))*cos(z(4)) - 6*(M+m)*g*sin(z(4)) ...\n          - 6*(f(t)-b*z(2))*cos(z(4)) )/( 4*l*(m+M)-3*m*l*cos(z(4))^2 );\n  dz(4) = z(3);\nelse\n  dz = (M+m)*z(2)^2/2 + 1/6*m*l^2*z(3)^2 + m*l*(z(2)*z(3)-g)*cos(z(4))/2;\nend\n\\end{lstlisting}\n", "meta": {"hexsha": "f08f2695abf6ada4927768454b2000c3bfec37ea", "size": 2066, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tex/dynamics_cp.tex", "max_stars_repo_name": "SJTUGuofei/pilco-matlab", "max_stars_repo_head_hexsha": "a0b48b7831911837d060617903c76c22e4180d0b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 53, "max_stars_repo_stars_event_min_datetime": "2016-12-17T15:15:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T16:59:27.000Z", "max_issues_repo_path": "doc/tex/dynamics_cp.tex", "max_issues_repo_name": "sahandrez/quad_pilco", "max_issues_repo_head_hexsha": "2c99152e3a910d147cd0a52822da306063e6a834", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-04-24T11:02:23.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-24T11:09:45.000Z", "max_forks_repo_path": "doc/tex/dynamics_cp.tex", "max_forks_repo_name": "sahandrez/quad_pilco", "max_forks_repo_head_hexsha": "2c99152e3a910d147cd0a52822da306063e6a834", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 36, "max_forks_repo_forks_event_min_datetime": "2017-04-19T06:55:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-19T10:19:12.000Z", "avg_line_length": 27.1842105263, "max_line_length": 75, "alphanum_fraction": 0.5837366893, "num_tokens": 735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.931462514578343, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7434810586248636}}
{"text": "\\chapter{Convolutional Neural Networks}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\input{6DL/Convolution}\n\\input{6DL/ConvolutionalOperator}\n\\input{6DL/convolution-filter}\n\\input{6DL/ClassicCNNs}\n\\input{6DL/DenseNet}\n\\input{6DL/Detail_ResNet}\n\n\\input{6DL/CNN-Examples}\n\n\\chapter{MgNet: a Unified Framework for CNN and MG}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\input{6DL/mgnet}\n\\input{6DL/mgnet_datafeature}\n\\input{6DL/mgnet_iterativescheme}\n\\input{6DL/mgnet_densenet}\n\\input{6DL/mgnet_DPN}\n\\input{6DL/mgnet_relation}\n\\input{6DL/mgnet_numerica}\n\\input{6DL/mgnet_summary}\n\n\\input{6DL/ConstrainedLinearModel}\n\\input{6DL/Bottleneck-MgNet}\n\\input{6DL/DenseNet-MgNet}\n", "meta": {"hexsha": "0e1e209011fb83bc3dd27e839f74855d7b2763cf", "size": 659, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/DNN-MgNet-He.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/DNN-MgNet-He.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/DNN-MgNet-He.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3461538462, "max_line_length": 51, "alphanum_fraction": 0.7086494689, "num_tokens": 223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395168021653, "lm_q2_score": 0.795658104908603, "lm_q1q2_score": 0.7434590886238641}}
{"text": "\n\\subsection{Cesàro sum}\n\nThe Cesàro sum is the limit of the average of the first \\(n\\) partial sums.\n\nThat is:\n\n\\(\\lim_{n\\rightarrow \\infty }\\dfrac{1}{n}\\sum_{k=1}^ns_k\\)\n\nConsider the sequence \\(\\{1,-1,1,-1,...\\}\\)\n\nThe partial sum is:\n\n\\(s_k=\\sum_{i=1}^ka_i\\)\n\n\\(s_k=k\\mod(2)\\)\n\nThe Cesàro sum is:\n\\(\\lim_{n\\rightarrow \\infty }\\dfrac{1}{n}\\sum_{k=1}^ns_k\\)\n\n\\(\\lim_{n\\rightarrow \\infty }\\dfrac{1}{n}\\sum_{k=1}^nk\\mod(2)\\)\n\n\\(\\dfrac{1}{2}\\)\n\n", "meta": {"hexsha": "4439f90cbf753a4a12eb2f3ebcf4922e5ee7110d", "size": 444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/sequencesInfinite/02-02-cesaro.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/sequencesInfinite/02-02-cesaro.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/sequencesInfinite/02-02-cesaro.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.76, "max_line_length": 75, "alphanum_fraction": 0.6171171171, "num_tokens": 187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7434544550641039}}
{"text": "\\subsection{Test for a Conservative Vector Field}\r\n\\noindent\r\nSince we know that all conservative vector fields have potential function, we can create a test to see if a given vector field is conservative. $\\vec{F_{\\text{Conservative}}} = \\langle f_x, f_y \\rangle$, so $f_{xy} = f_{yx}$. That is, a vector field $\\vec{F}(x,y) = \\langle P(x,y), Q(x,y) \\rangle$ is conservative if $P_y = Q_x$.\\\\\r\nFor 3D vector field, the test is a little more complicated. A vector field $\\vec{F}\\langle P(x,y,z), Q(x,y,z), R(x,y,z)\\rangle$ is conservative if $P_y = Q_x$, $Q_z = R_y$, and $R_x = P_z$.\\\\\r\n\r\n\\noindent\r\nFor example, let see if $\\langle yz, xz, xy\\rangle$ is conservative.\r\n\\begin{equation*}\r\n\t\\frac{\\partial}{\\partial y}yz = z = \\frac{\\partial}{\\partial x}xz\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\frac{\\partial}{\\partial z}xz = x = \\frac{\\partial}{\\partial y}xy\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\frac{\\partial}{\\partial y}xy = y = \\frac{\\partial}{\\partial z}yz\r\n\\end{equation*}\r\nSo, the vector field is conservative.", "meta": {"hexsha": "9b652892ff2aa9ddf63c78389ece191d49507378", "size": 1020, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/lineSurfaceIntegrals/testconservativeVF.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/lineSurfaceIntegrals/testconservativeVF.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/lineSurfaceIntegrals/testconservativeVF.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.0, "max_line_length": 332, "alphanum_fraction": 0.6784313725, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819238, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7434544534990863}}
{"text": "\\subsection{Transaction Privacy}\nThe basis for transactions is that the amount paid must equal the product cost plus fees, plus change returned to purchaser\n$$ {paid} = {cost} + {fees} + {change}$$\nor rather, \n$$ {paid} - {change} = {cost} + {fees}$$\n\nSo using our pairing-based cryptography, we can encrypt the purchase offer as a triple \n$(T_{buy},R_{sell}, P_{buy})$\n$$ T_{buy} = \\frac{k_{rand} \\, s_{buy}}{paid - change} \\, U \\in G_1$$\n$$ R_{sell} = \\frac{1}{k_{rand}}\\,P_{sell} \\in G_2$$\nfor some random value $k_{rand}$ as a blinding factor, the buyer's secret key $s_{buy} \\in Z_q$, buyer's public key $P_{buy} = s_{buy} \\, V \\in G_2$,  seller's public key $P_{sell} \\in G_2$, and generators $U \\in G_1$, and $V \\in G_2$.\n\nBlinding factors ensure that repeated transactions for the same amount will appear different each time. Only the buyer needs to know the amount paid, and the change returned. The seller only needs assurance that their cost plus fees is covered.\n\nAt the seller's end, this transaction can be completed by computing $C_{sell}$ \n$$ C_{sell} = \\frac{cost+fees}{s_{sell}} \\, R_{sell} \\in G_2$$\nfor seller's private key $s_{sell} \\in Z_q$, \nand then verifying the pairing relation:\n$$ e(T_{buy},C_{sell}) = e(U,P_{buy}) \\in G_T$$\nfor buyer's public key $P_{buy}$. \n\nThis accomplishes three things. First, only the intended seller can verify the pairing relation, since it requires their private key, $s_{sell}$. Second, it proves to the seller that the buyer, identified by their public key, $P_{buy}$, originated the transaction. And third, it proves to the seller that the buyer paid the proper amount after receiving their change. \n\nAny mismatch between the two pairings indicates either that the seller was illegitimate and could not decrypt the $R_{sell}$ value properly, or that a presumed buyer did not originate the transaction, or else they didn't send a proper amount of currency. \n\nBuyer and seller are protected against forgery and fraud, and seller is protected against denial on the part of the buyer. The purchase offer is completely cloaked to third parties. And currency amounts, beyond what is already known to the seller, are hidden from  view.\n\nTo complete the transaction the seller must indicate acceptance and then the entire transaction must be published to the public blockchain with publicly verifiable proofs that the transaction was legitimate. \n\nTo accept the proposed purchase, the seller publishes the triple $(T_{buy}, C_{sell}, P_{buy})$ to the blockchain, where $T_{buy}$ was received from the buyer, and $C_{sell}$ was computed by the seller during verification. Together, these group elements form pairings that anyone can verify with the same pairing relation used by the seller:\n$$ e(T_{buy},C_{sell}) = e(U,P_{buy}) \\in G_T$$\nThis publication should be signed by the seller and posted to the blockchain. Doing so carries the signature weight of the seller as having accepted the purchase transaction. It would not have been published unless the seller accepted it. It proves that the buyer originated the transaction. And anyone can now verify that the transaction occurred. But all currency amounts remain hidden from view.\n\nBut more is needed. Nothing here prevents a buyer from claiming fraudulent values for amounts paid and change received. All we know is that their difference was matched by the seller's cost plus fees. Nor can we see if buyer and seller were colluding with fraudulent values on both sides of the transaction. \n\nSo accompanying the purchase transaction, we must provide cryptographic proofs that the individual currency values lie within legitimate ranges. In particular, the difference, $(paid - change)$, and $paid$,  $change$, $cost$, and $fees$, must all be nonnegative amounts within some range, like $[0..2^{64})$.   This is provided by Bulletproofs. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "3a0d2328fc184ddda29227ac2ce7979083e0112d", "size": 3895, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/Crypto-writeup/bilinear-cloaking.tex", "max_stars_repo_name": "easye/emotiq", "max_stars_repo_head_hexsha": "8f765e516704496011299eee4a2eba6f70170a34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 109, "max_stars_repo_stars_event_min_datetime": "2018-01-17T21:59:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T10:05:45.000Z", "max_issues_repo_path": "src/Crypto-writeup/bilinear-cloaking.tex", "max_issues_repo_name": "easye/emotiq", "max_issues_repo_head_hexsha": "8f765e516704496011299eee4a2eba6f70170a34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 227, "max_issues_repo_issues_event_min_datetime": "2018-02-13T10:15:07.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-17T11:54:39.000Z", "max_forks_repo_path": "src/Crypto-writeup/bilinear-cloaking.tex", "max_forks_repo_name": "easye/emotiq", "max_forks_repo_head_hexsha": "8f765e516704496011299eee4a2eba6f70170a34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2018-01-28T16:29:39.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-29T09:10:30.000Z", "avg_line_length": 99.8717948718, "max_line_length": 398, "alphanum_fraction": 0.7473684211, "num_tokens": 936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620614046438, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7434157405216905}}
{"text": "\\section{Solving Equations}\n\n\\begin{frame}[fragile]\n\\frametitle{Solution of linear equations}\nConsider,\n  \\begin{align*}\n    3x + 2y - z  & = 1 \\\\\n    2x - 2y + 4z  & = -2 \\\\\n    -x + \\frac{1}{2}y -z & = 0\n  \\end{align*}\nSolution:\n  \\begin{align*}\n    x & = 1 \\\\\n    y & = -2 \\\\\n    z & = -2\n  \\end{align*}\n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitle{Solving using Matrices}\nLet us now look at how to solve this using \\texttt{matrices}\n  \\begin{lstlisting}\nIn []: A = array([[3,2,-1],\n                  [2,-2,4],                   \n                  [-1, 0.5, -1]])\nIn []: b = array([1, -2, 0])\nIn []: x = solve(A, b)\n  \\end{lstlisting}\n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitle{Solution:}\n\\begin{lstlisting}\nIn []: x\nOut[]: array([ 1., -2., -2.])\n\\end{lstlisting}\n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitle{Let's check!}\n\\begin{small}\n\\begin{lstlisting}\nIn []: Ax = dot(A, x)\nIn []: Ax\nOut[]: array([ 1.00000000e+00,  -2.00000000e+00, \n              -1.11022302e-16])\n\\end{lstlisting}\n\\end{small}\n\\begin{block}{}\nThe last term in the matrix is actually \\alert{0}!\\\\\nWe can use \\texttt{allclose()} to check.\n\\end{block}\n\\begin{lstlisting}\nIn []: allclose(Ax, b)\nOut[]: True\n\\end{lstlisting}\n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitle{\\texttt{roots} of polynomials}\n\\begin{itemize}\n\\item \\texttt{roots} function can find roots of polynomials\n\\item To calculate the roots of $x^2-5x+6$ \n\\end{itemize}\n\\begin{lstlisting}\n  In []: coeffs = [1, -5, 6]\n  In []: roots(coeffs)\n  Out[]: array([3., 2.])\n\\end{lstlisting}\n\\vspace*{-.2in}\n\\begin{center}\n\\includegraphics[height=1.6in, interpolate=true]{images/roots}    \n\\end{center}\n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitle{SciPy: \\texttt{fsolve}}\n\\begin{small}\n\\begin{lstlisting}\n  In []: from scipy.optimize import fsolve\n\\end{lstlisting}\n\\end{small}\n\\begin{itemize}\n\\item Finds the roots of a system of non-linear equations\n\\item Input arguments - Function and initial estimate\n\\item Returns the solution\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitle{\\texttt{fsolve} \\ldots}\nFind the root of $sin(z)+cos^2(z)$ nearest to $0$\n\\begin{lstlisting}\nIn []: def g(z):\n ....:     return sin(z)+cos(z)*cos(z)\n\nIn []: fsolve(g, 0)\nOut[]: -0.66623943249251527\n\\end{lstlisting}\n\\begin{center}\n\\includegraphics[height=2in, interpolate=true]{images/fsolve}    \n\\end{center}\n\\end{frame}\n\n\\section{ODEs}\n\n\\begin{frame}[fragile]\n\\frametitle{Solving ODEs using SciPy}\n\\begin{itemize}\n\\item Consider the spread of an epidemic in a population\n\\item $\\frac{dy}{dt} = ky(L-y)$ gives the spread of the disease\n\\item $L$ is the total population.\n\\item Use $L = 2.5E5, k = 3E-5, y(0) = 250$\n\\item Define a function as below\n\\end{itemize}\n\\begin{lstlisting}\nIn []: from scipy.integrate import odeint\nIn []: def epid(y, t):\n  ....     k = 3.0e-5\n  ....     L = 2.5e5\n  ....     return k*y*(L-y)\n  ....\n\\end{lstlisting}\n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitle{Solving ODEs using SciPy \\ldots}\n\\begin{lstlisting}\nIn []: t = linspace(0, 12, 61)\n\nIn []: y = odeint(epid, 250, t)\n\nIn []: plot(t, y)\n\\end{lstlisting}\n%Insert Plot\n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitle{Result}\n\\begin{center}\n\\includegraphics[height=2in, interpolate=true]{images/epid}  \n\\end{center}\n\\end{frame}\n\n\n\\begin{frame}[fragile]\n\\frametitle{ODEs - Simple Pendulum}\nWe shall use the simple ODE of a simple pendulum. \n\\begin{equation*}\n\\ddot{\\theta} = -\\frac{g}{L}sin(\\theta)\n\\end{equation*}\n\\begin{itemize}\n\\item This equation can be written as a system of two first order ODEs\n\\end{itemize}\n\\begin{align}\n\\dot{\\theta} &= \\omega \\\\\n\\dot{\\omega} &= -\\frac{g}{L}sin(\\theta) \\\\\n \\text{At}\\ t &= 0 : \\nonumber \\\\\n \\theta = \\theta_0(10^o)\\quad & \\&\\quad  \\omega = 0\\ (Initial\\ values)\\nonumber \n\\end{align}\n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitle{ODEs - Simple Pendulum \\ldots}\n\\begin{itemize}\n\\item Use \\texttt{odeint} to do the integration\n\\end{itemize}\n\\begin{lstlisting}\nIn []: def pend_int(initial, t):\n  ....     theta = initial[0]\n  ....     omega = initial[1]\n  ....     g = 9.81\n  ....     L = 0.2\n  ....     F=[omega, -(g/L)*sin(theta)]\n  ....     return F\n  ....\n\\end{lstlisting}\n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitle{ODEs - Simple Pendulum \\ldots}\n\\begin{itemize}\n\\item \\texttt{t} is the time variable \\\\ \n\\item \\texttt{initial} has the initial values\n\\end{itemize}\n\\begin{lstlisting}\nIn []: t = linspace(0, 20, 101)\nIn []: initial = [10*2*pi/360, 0]\n\\end{lstlisting} \n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitle{ODEs - Simple Pendulum \\ldots}\n%%\\begin{small}\n\\texttt{}\n%%\\end{small}\n\\begin{lstlisting}\nIn []: from scipy.integrate import odeint\nIn []: pend_sol = odeint(pend_int, \n                         initial,t)\n\\end{lstlisting}\n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitle{Result}\n\\begin{center}\n\\includegraphics[height=2in, interpolate=true]{images/ode}  \n\\end{center}\n\\end{frame}\n\n%% \\section{FFTs}\n\n%% \\begin{frame}[fragile]\n%% \\frametitle{The FFT}\n%% \\begin{itemize}\n%%     \\item We have a simple signal $y(t)$\n%%     \\item Find the FFT and plot it\n%% \\end{itemize}\n%% \\begin{lstlisting}\n%% In []: t = linspace(0, 2*pi, 500)\n%% In []: y = sin(4*pi*t)\n\n%% In []: f = fft(y)\n%% In []: freq = fftfreq(500, t[1] - t[0])\n\n%% In []: plot(freq[:250], abs(f)[:250])\n%% In []: grid()\n%% \\end{lstlisting} \n%% \\end{frame}\n\n%% \\begin{frame}[fragile]\n%% \\frametitle{FFTs cont\\dots}\n%% \\begin{lstlisting}\n%% In []: y1 = ifft(f) # inverse FFT\n%% In []: allclose(y, y1)\n%% Out[]: True\n%% \\end{lstlisting} \n%% \\end{frame}\n\n%% \\begin{frame}[fragile]\n%% \\frametitle{FFTs cont\\dots}\n%% Let us add some noise to the signal\n%% \\begin{lstlisting}\n%% In []: yr = y + random(size=500)*0.2\n%% In []: yn = y + normal(size=500)*0.2\n\n%% In []: plot(t, yr)\n%% In []: figure()\n%% In []: plot(freq[:250],\n%%   ...:      abs(fft(yn))[:250])\n%% \\end{lstlisting}\n%% \\begin{itemize}\n%%     \\item \\texttt{random}: produces uniform deviates in $[0, 1)$\n%%     \\item \\texttt{normal}: draws random samples from a Gaussian\n%%         distribution\n%%     \\item Useful to create a random matrix of any shape\n%% \\end{itemize}\n%% \\end{frame}\n\n%% \\begin{frame}[fragile]\n%% \\frametitle{FFTs cont\\dots}\n%% Filter the noisy signal:\n%% \\begin{lstlisting}\n%% In []: from scipy import signal\n%% In []: yc = signal.wiener(yn, 5)\n%% In []: clf()\n%% In []: plot(t, yc)\n%% In []: figure()\n%% In []: plot(freq[:250], \n%%   ...:      abs(fft(yc))[:250])\n%% \\end{lstlisting}\n%% Only scratched the surface here \\dots\n%% \\end{frame}\n", "meta": {"hexsha": "1116c3da63548d047b114c2be893535727833a92", "size": 6458, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/advanced_python/slides/scipy.tex", "max_stars_repo_name": "FOSSEE/sees", "max_stars_repo_head_hexsha": "0e76356043e3ed28a74ecb5c8f64094bc18f2115", "max_stars_repo_licenses": ["OLDAP-2.5"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2015-01-21T13:52:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-12T08:54:48.000Z", "max_issues_repo_path": "slides/advanced_python/slides/scipy.tex", "max_issues_repo_name": "FOSSEE/sees", "max_issues_repo_head_hexsha": "0e76356043e3ed28a74ecb5c8f64094bc18f2115", "max_issues_repo_licenses": ["OLDAP-2.5"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2015-01-22T08:07:08.000Z", "max_issues_repo_issues_event_max_datetime": "2015-03-12T14:39:57.000Z", "max_forks_repo_path": "slides/advanced_python/slides/scipy.tex", "max_forks_repo_name": "FOSSEE/sees", "max_forks_repo_head_hexsha": "0e76356043e3ed28a74ecb5c8f64094bc18f2115", "max_forks_repo_licenses": ["OLDAP-2.5"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2015-01-20T23:03:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-12T08:54:57.000Z", "avg_line_length": 23.5693430657, "max_line_length": 80, "alphanum_fraction": 0.626664602, "num_tokens": 2307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048443, "lm_q2_score": 0.8705972650509008, "lm_q1q2_score": 0.7434141170217325}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[margin=1.25in]{geometry}\n\\usepackage[fleqn]{amsmath}\n\\usepackage{textcomp}\n\\usepackage{gensymb}\n\\usepackage{amsfonts}\n\\usepackage{enumitem}\n%\\usepackage{tikz}  % Include for figures.\n%\\usepackage{subfiles}  % Include for subfiles.\n\n\\newcommand{\\HOMEWORKNUM}{8}\n\\newcommand{\\NAME}{D. Choi}\n\\newcommand{\\DATE}{2020-06-02}\n\n\\title{\\vspace{-2\\baselineskip}MATH 225 - Homework \\#\\HOMEWORKNUM}\n\\author{\\NAME}\n\\date{\\DATE}\n\n%\\pagenumbering{gobble}  % Include for single-page document.\n\n% Augmented matrix environment.\n% https://tex.stackexchange.com/a/2238\n\\newenvironment{amatrix}[1]{%\n  \\left(\\begin{array}{@{}*{#1}{c}|c@{}}\n}{%\n  \\end{array}\\right)\n}\n\n\\begin{document}\n\\maketitle\n\n\\section*{1.}\n\\textit{Solve.}\n\\begin{align*}\n\tx + 2y + 3z + 5w &= 8 \\\\\n\t2x + 4y + 6z + 10w &= 16 \\\\\n\tx + y + z + w &= 10\n\\end{align*}\nThis system can be rewritten in matrix form $A\\vec{v} = \\vec{b}$ as\n\\begin{equation*}\n\t\\begin{pmatrix}\n\t\t1 & 2 & 3 & 5 \\\\\n\t\t2 & 4 & 6 & 10 \\\\\n\t\t1 & 1 & 1 & 1\n\t\\end{pmatrix}\n\t\\begin{pmatrix} x \\\\ y \\\\ z \\\\ w \\end{pmatrix}\n\t=\n\t\\begin{pmatrix} 8 \\\\ 16 \\\\ 10 \\end{pmatrix}\n\\end{equation*}\nThe coefficient matrix $A$ and the target vector $\\vec{b}$ can be concatenated\ncolumn-wise to create the augmented matrix $(A|\\vec{b})$.\n\\begin{equation*}\n\t(A|\\vec{b}) =\n\t\\begin{amatrix}{4}\n\t\t1 & 2 & 3 & 5 & 8 \\\\\n\t\t2 & 4 & 6 & 10 & 16 \\\\\n\t\t1 & 1 & 1 & 1 & 10\n\t\\end{amatrix}\n\\end{equation*}\nThe augmented matrix $(A|\\vec{b})$ can be row-reduced into reduced row-echelon\nform.\n\\footnotesize\n\\begin{align*}\n\t\\begin{amatrix}{4}\n\t\t1 & 2 & 3 & 5 & 8 \\\\\n\t\t2 & 4 & 6 & 10 & 16 \\\\\n\t\t1 & 1 & 1 & 1 & 10\n\t\\end{amatrix}\n\t&\\xrightarrow{\\frac{1}{2}r_2 \\rightarrow r_2}\n\t\\begin{amatrix}{4}\n\t\t1 & 2 & 3 & 5 & 8 \\\\\n\t\t1 & 2 & 3 & 5 & 8 \\\\\n\t\t1 & 1 & 1 & 1 & 10\n\t\\end{amatrix}\n\t\\xrightarrow{r_2 - r_1 \\rightarrow r_2}\n\t\\begin{amatrix}{4}\n\t\t1 & 2 & 3 & 5 & 8 \\\\\n\t\t0 & 0 & 0 & 0 & 0 \\\\\n\t\t1 & 1 & 1 & 1 & 10\n\t\\end{amatrix}\n\t\\\\\n\t&\\xrightarrow{r_2 \\leftrightarrow r_3}\n\t\\begin{amatrix}{4}\n\t\t1 & 2 & 3 & 5 & 8 \\\\\n\t\t1 & 1 & 1 & 1 & 10 \\\\\n\t\t0 & 0 & 0 & 0 & 0\n\t\\end{amatrix}\n\t\\xrightarrow{r_2 - r_1 \\rightarrow r_2}\n\t\\begin{amatrix}{4}\n\t\t1 & 2 & 3 & 5 & 8 \\\\\n\t\t0 & -1 & -2 & -4 & 2 \\\\\n\t\t0 & 0 & 0 & 0 & 0\n\t\\end{amatrix}\n\t\\\\\n\t&\\xrightarrow{-r_2 \\rightarrow r_2}\n\t\\begin{amatrix}{4}\n\t\t1 & 2 & 3 & 5 & 8 \\\\\n\t\t0 & 1 & 2 & 4 & -2 \\\\\n\t\t0 & 0 & 0 & 0 & 0\n\t\\end{amatrix}\n\t\\xrightarrow{r_1 - 2r_2 \\rightarrow r_1}\n\t\\begin{amatrix}{4}\n\t\t1 & 0 & -1 & -3 & 12 \\\\\n\t\t0 & 1 & 2 & 4 & -2 \\\\\n\t\t0 & 0 & 0 & 0 & 0\n\t\\end{amatrix}\n\\end{align*}\n\\normalsize\n\\newpage\n\\noindent The reduced row echelon form of $(A|\\vec{b})$,\n\\begin{equation*}\n\t\\begin{amatrix}{4}\n\t\t1 & 0 & -1 & -3 & 12 \\\\\n\t\t0 & 1 & 2 & 4 & -2 \\\\\n\t\t0 & 0 & 0 & 0 & 0\n\t\\end{amatrix}\n\t,\n\\end{equation*}\nis analogous to the matrix equation\n\\begin{equation*}\n\t\\begin{pmatrix}\n\t\t1 & 0 & -1 & -3 \\\\\n\t\t0 & 1 & 2 & 4 \\\\\n\t\t0 & 0 & 0 & 0\n\t\\end{pmatrix}\n\t\\begin{pmatrix} x \\\\ y \\\\ z \\\\ w \\end{pmatrix}\n\t=\n\t\\begin{pmatrix} 12 \\\\ -2 \\\\ 0 \\end{pmatrix}\n\\end{equation*}\nand also to the system\n\\begin{align*}\n\tx -z - 3w &= 12 \\\\\n\ty + 2z + 4w &= -2\n\t.\n\\end{align*}\nIn this system, $z$ and $w$ are free variables. \\\\\nThus, the system has \\boxed{\\text{infinitely many solutions}}.\n\\\\[\\baselineskip]\nSolutions to the system are of the form\n\\begin{equation*}\n\t\\boxed{\n\t\t\\begin{pmatrix}\n\t\t\t12 + z + 3w \\\\\n\t\t\t-2 - 2z - 4w \\\\\n\t\t\tz \\\\\n\t\t\tw\n\t\t\\end{pmatrix}\n\t}\n\t,\n\\end{equation*}\nor, equivalently,\n\\begin{equation*}\n\t\\boxed{\n\t\t\\begin{pmatrix} 12 \\\\ -2 \\\\ 0 \\\\ 0 \\end{pmatrix}\n\t\t+\n\t\t\\begin{pmatrix} 1 \\\\ -2 \\\\ 1 \\\\ 0 \\end{pmatrix} z\n\t\t+\n\t\t\\begin{pmatrix} 3 \\\\ -4 \\\\ 0 \\\\ 1 \\end{pmatrix} w\n\t}\n\t.\n\\end{equation*}\n\\newpage\n\n\\section*{2.}\n\\textit{Include an example of appropriate matrix as you justify your responses\nto the following questions.}\n\\begin{enumerate}[label=(\\alph*)]\n\t\\item \\textit{Suppose a linear system having six equations and three\n\tunknowns is consistent.\n\tCan you guarantee that the solution is unique?\n\tCan you guarantee that there are infinitely-many solutions?}\n\t\\\\[\\baselineskip]\n\tConsider the row-reduced system:\n\t\\begin{equation*}\n\t\t\\begin{pmatrix}\n\t\t\t0 & 0 & 0 \\\\\n\t\t\t0 & 0 & 0 \\\\\n\t\t\t0 & 0 & 0 \\\\\n\t\t\t0 & 0 & 0 \\\\\n\t\t\t0 & 0 & 0 \\\\\n\t\t\t0 & 0 & 0\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix} x \\\\ y \\\\ z \\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\end{pmatrix}\n\t\t.\n\t\\end{equation*}\n\t\\boxed{\\text{A unique solution cannot be guaranteed.}}\n\t\\\\[\\baselineskip]\n\tConsider the row-reduced system:\n\t\\begin{equation*}\n\t\t\\begin{pmatrix}\n\t\t\t1 & 0 & 0 \\\\\n\t\t\t0 & 1 & 0 \\\\\n\t\t\t0 & 0 & 1 \\\\\n\t\t\t0 & 0 & 0 \\\\\n\t\t\t0 & 0 & 0 \\\\\n\t\t\t0 & 0 & 0\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix} x \\\\ y \\\\ z \\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\end{pmatrix}\n\t\t.\n\t\\end{equation*}\n\tThe only solution to such a system is\n\t\\begin{equation*}\n\t\t\\begin{pmatrix} x \\\\ y \\\\ z \\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix} 0 \\\\ 0 \\\\ 0 \\end{pmatrix}\n\t\\end{equation*}\n\tThus, \\boxed{\\text{infinitely-many solutions cannot be guaranteed}}.\n\t\\newpage\n\t\\item \\textit{Suppose that a linear system having three equations and six\n\tunknowns is consistent.\n\tCan you guarantee that the solution is unique?\n\tCan you guarantee that there are infinitely-many solutions?}\n\t\\\\[\\baselineskip]\n\tConsider the row-reduced system:\n\t\\begin{equation*}\n\t\t\\begin{pmatrix}\n\t\t\t0 & 0 & 0 & 0 & 0 & 0 \\\\\n\t\t\t0 & 0 & 0 & 0 & 0 & 0 \\\\\n\t\t\t0 & 0 & 0 & 0 & 0 & 0\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix} a \\\\ b \\\\ c \\\\ d \\\\ e \\\\ f \\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix} 0 \\\\ 0 \\\\ 0 \\end{pmatrix}\n\t\t.\n\t\\end{equation*}\n\t\\boxed{\\text{A unique solution cannot be guaranteed.}}\n\t\\\\[\\baselineskip]\n\tFor there to be a unique solution, there must be a pivot for each column\n\tof the coefficient matrix in the row-reduced augmented matrix. This is not\n\tpossible when there are more columns than rows in the coefficient matrix.\n\tThus, \\boxed{\\text{infinitely-many solutions are guaranteed}}.\n\t\\item \\textit{Suppose that a linear system is consistent and has a unique\n\tsolution.\n\tWhat can you guarantee about the pivot positions in the augmented matrix?}\n\t\\\\[\\baselineskip]\n\tFor a row-reduced augmented matrix of a consistent linear system with a\n\tunique solution, \\boxed{\\text{a pivot must exist for each column of the\n\tcoefficient matrix}}.\n\\end{enumerate}\n\n\\end{document}", "meta": {"hexsha": "30f7f43f5f73c37ef64e5ebdeee2d4b014d25d40", "size": 6232, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "usc-20202-math-225-39425/hw08/main.tex", "max_stars_repo_name": "Floozutter/coursework", "max_stars_repo_head_hexsha": "244548f415553f058098cae84ccdd4ce3f58c245", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "usc-20202-math-225-39425/hw08/main.tex", "max_issues_repo_name": "Floozutter/coursework", "max_issues_repo_head_hexsha": "244548f415553f058098cae84ccdd4ce3f58c245", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "usc-20202-math-225-39425/hw08/main.tex", "max_forks_repo_name": "Floozutter/coursework", "max_forks_repo_head_hexsha": "244548f415553f058098cae84ccdd4ce3f58c245", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.4367346939, "max_line_length": 78, "alphanum_fraction": 0.6081514763, "num_tokens": 2571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517044, "lm_q2_score": 0.8705972717658209, "lm_q1q2_score": 0.7434141130457953}}
{"text": "\n\\chapter[Partial Differential Equations]{Finite difference methods for Partial Differential Equations}\n\n\\section[Revision]{Revision of Partial Differential Equations}\n\nA {\\em partial differential equation} is a relation between the\npartial derivatives of an unknown function and the independent\nvariables.  The order of the highest derivative is called the {\\em\n  order} of the equation.\n\nJust as in the case of an ordinary differential equation, we say that\na partial differential equation is {\\em linear} if it is of the first\ndegree in the dependent variable (the unknown function) and its\npartial derivatives.  If each term of such equation contains either\nthe dependent variable or one of its derivatives, the equation is\ncalled {\\em homogeneous}; otherwise it is said to be {\\em non\n  homogeneous}.\n\n\\smallskip\n\n\\noindent\n{\\bf Example} - The equations\n%\n\\begin{align*}\n  (a) & & \\pdv{\\phi}{t} - \\pdv[2]{\\phi}{x} &= 0, \\\\\n  (b) & & \\phi(x,t) \\pdv[2]{\\phi}{t} + \\pdv{\\phi}{x} &= f(x,t), \\\\\n  (c) & & \\pdv[4]{\\phi}{x} + \\pdv[4]{\\phi}{y} &= g(x,y) ,\n\\end{align*}\n%\nare, respectively, (a) Linear, homogeneous, second order, (b)\nnonlinear, non-homogeneous, second order, (c) linear, non-homogeneous,\nfourth order.\n\n\\smallskip\n\nIn this unit we consider only second order linear partial differential\nequations with constant coefficients:\n%\n\\begin{equation*}\n  A \\pdv[2]{u}{x} + 2 B \\pdv{u}{x}{y} +\n  C \\pdv[2]{u}{y} + D \\pdv{u}{x} + E \\pdv{u}{y} = f(x,y) .\n\\end{equation*}\n%\nThese equations are classified in three groups\\footnote{Note that the\n  coefficients $A$, $B$, etc. need not be constant}:\n\n\\medskip\n\n\\begin{center}\n  \\begin{tabular}{|l|l|l|l|} \\hline\n    \\multicolumn{1}{|c|}{ Type} &\n    \\multicolumn{1}{c|}{Coefficients} &\n    \\multicolumn{1}{c|} {Typical form} &\n    \\multicolumn{1}{c|} {Name} \\\\ \\hline \\hline\n    Hyperbolic & $B^2 - 4 A C > 0 $ &\n    $u_{t t} - c^2 u_{x x} = 0 $ & Wave eq. \\\\ \\hline\n    Parabolic & $B^2 - 4 A C = 0 $ &\n    $u_{t} - c^2 u_{x x} = 0 $ & Heat eq. \\\\ \\hline\n    Elliptic & $B^2 - 4 A C < 0 $ &\n    $u_{x x} + u_{y y} = 0 $ & Laplace eq. \\\\ \\hline\n  \\end{tabular}\n\\end{center}\n\n\\medskip\n\n\\noindent\nThe names arise by analogy with the curve\n%\n\\begin{equation*}\n  a x^2 + 2 b x y + c y^2 = f,\n\\end{equation*}\n%\nwhich represents an hyperbola, parabola and ellipse according as $b^2\n- 4 a c$ is positive, zero or negative, respectively.\n\nThe classification of the equations is very important for the study of\ntheir solutions.  A {\\em solution} of a partial differential equation\nin some region $R$ of the space of the independent variables is a\nfunction that has all the partial derivatives that appear in the\nequation and that satisfies the equation everywhere in $R$.  Like\nordinary differential equations, Partial differential equation have\nmany solutions.  For example, the functions\n%\n\\begin{equation*}\n  u(x,y) = x^2 - y^2, \\quad u = e^x \\cos(y), \\quad u=\\ln(x^2+y^2),\n\\end{equation*}\n%\nare all solutions of the equation\n%\n\\begin{equation*}\n  \\pdv[2]{u}{x} + \\pdv[2]{u}{y} = 0 .\n\\end{equation*}\n%\nExactly like for ordinary differential equations we must specify\nsomething more if we wish to obtain a unique solution: for example we\nmust specify the value of the function on the boundary of the region\n$R$ ({\\em boundary conditions}), and/or we must specify the value of\nthe function at the start ({\\em initial conditions}).  What type of\nboundary or initial condition to use depends on the type of Partial\ndifferential equation.\n\n\\medskip\n\n\\centerline{\\bf Hyperbolic}\n\n\\noindent \\underline{Example}: $u_{t t} - c^2 u_{xx} = 0$.\n\n\\noindent \\underline{Physical meaning}: Wave motion\n\n\\noindent \\underline{Initial conditions}: The value of $u$ and its\ntime derivative at $t=0$: $u(x,0)=f(x)$ and $u_t(x,0)=g(x)$.\n\n\\noindent \\underline{Boundary conditions}: Either $u$ or its normal\nderivative at the boundary of the integration region: e.g.\\ $u(0,t) =\n\\phi_1(t)$ and $u(L,t)= \\phi_2(t)$.  The former type of boundary\ncondition is called a \\textit{Dirichlet} boundary condition; the\nlatter is called a \\textit{Neumann} boundary condition.  It is also\npossible to mix the two types of boundary conditions (\\textit{mixed\n  boundary conditions}).\n\n\\bigskip\n\n\\centerline{\\bf Parabolic}\n\n\\noindent \\underline{Example}: $u_{t} - c^2 u_{xx} = 0$.\n\n\\noindent \\underline{Physical meaning}: Heat diffusion\n\n\\noindent \\underline{Initial conditions}: The value of $u$ at $t=0$:\n$u(x,0)=f(x)$.\n\n\\noindent \\underline{Boundary conditions}: Either $u$ or its normal\nderivative at the boundary of the integration region: e.g.\\ $u(0,t) =\n\\phi_1(t)$ and $u(L,t)= \\phi_2(t)$.\n\n\\bigskip\n\n\\centerline{\\bf Elliptic}\n\n\\noindent \\underline{Example}: $u_{xx} + u_{y y} = 0$ (Laplace's\nequation).\n\n\\noindent \\underline{Physical meaning}: Stationary profile of a\nmembrane, stationary temperature profile of a metal plate,\nelectrostatic potential in the absence of charges.\n\n\\noindent \\underline{Initial conditions}: They do not apply to these\nequations.\n\n\\noindent \\underline{Boundary conditions}: Either $u$ or its normal\nderivative at the boundary of the integration region: e.g.\\ if the\nregion is the rectangle $0 \\le x \\le a$, $0 \\le y \\le b$: $u(0,y) =\n\\phi_1(y)$, $u(a,y)= \\phi_2(y)$, $u(x,0) = g_1(x)$ and, finally,\n$u(x,b)=g_2(x)$.\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=120mm]{figures/pde_summary}}\n  \\caption{\\label{fig:pde_summary} \\it Types of partial differential\n    equations and their boundary and initial conditions.}\n\\end{figure}\n\n\\section{Numerical methods for PDEs}\n\nThere are many classes of methods to solve numerically partial\ndifferential equations.  Three main groups are:\n\n\\begin{enumerate}\n  %\n\\item \\textit{Finite difference methods}\n\n  The differential operators are approximated using their finite\n  difference representation on a given grid.  In this way the Partial\n  Differential Equation is transformed to a (nonlinear) algebraic\n  equation for the values of the solution on the grid points.  These\n  are the only methods that we discuss at any length in this unit.\n  %\n\\item \\textit{Finite element methods}\n\n  The domain of the solution is divided into cells.  The solution is\n  represented as a simple function (e.g.\\ a linear function) on each\n  cell and the partial differential equation is transformed to an\n  algebraic problem for the matching conditions of the simple\n  solutions at the boundaries of the cells.\n  %\n\\item \\textit{Spectral methods}\n\n  The solution is represented by a superposition of known functions\n  (e.g.\\ trigonometric functions or special polynomials).  The partial\n  differential equation is transformed to a set of algebraic equations\n  or ordinary differential equations for the amplitudes of the\n  component functions.  A subclass of these methods are the\n  \\textit{collocation methods}: the solution is represented on a grid\n  and the decomposition of the solution in known functions is used to\n  estimate to a high degree of accuracy the partial derivatives of the\n  solution on the grid points.  These methods are highly accurate and\n  fast, but in general require the domain of the solution to be fairly\n  simple, e.g.\\ a rectangle.\n  %\n\\end{enumerate}\n\n\\section[Elliptic Equations]{Elliptic Equations}\n\n\\subsection{Introduction}\n\nA ``standard form'' of elliptic partial differential equation with\nDirichlet boundary conditions is\n%\n\\begin{equation}\n  \\left\\{\n    \\begin{aligned}\n      u_{xx} + u_{y y} & = f(x,y), & & {\\rm in}~~\\Omega,\\\\\n      u\\big |_{\\partial\\Omega} & = \\phi(x,y), & & {\\rm on}~~\\partial\\Omega.\n    \\end{aligned}\n  \\right.\\label{dp}\n\\end{equation}\n%\nThis problem has a unique solution if the domain $\\Omega$ has a smooth\nboundary and $f$ and $\\phi$ are continuous functions.\n\n\\subsection{A simple finite difference method}\n\nWe are going to solve equation~(\\ref{dp}) numerically using the method\nof finite differences.  At the heart of this method is the finite\ndifference approximation of the second derivative of a function\n$y(x)$:\n%\n\\begin{equation}\n  y''(x) = \\frac{1}{h^2}[y(x+h)+y(x-h)-2y(x)]-\n  \\frac{h^2}{12}y^{(4)}(\\xi), \\label{fd}\n\\end{equation}\n%\nwhere $h$ is a fixed step size.  We illustrate this method using a\nsimple case of equation~(\\ref{dp}), namely the case of a Dirichlet\nproblem on a rectangle $0<x<a$, $0<y<b$.  First, a network of grid\npoints is established on the rectangle:\n%\n\\begin{equation*}\n  (x_i,y_j)=(i h_x,j h_y), \\qquad 0\\le i\\le n+1, \\quad 0\\le j\\le m+1,\n\\end{equation*}\n%\nwhere the step sizes in the $x$ and $y$ directions are given by\n\\begin{equation*}\n  h_x=\\frac{a}{n+1}, \\qquad h_y=\\frac{b}{m+1}.\n\\end{equation*}\n%\nNext, the differential equation in (\\ref{dp}) at the mesh point\n$(x_i,y_j)$ is replaced by its finite-difference analogue at that\npoint, which for $1 \\le i \\le n$ and $1 \\le j \\le m$ is:\n%\n\\begin{align}\n  \\label{eq:ellfd}\n  & & \\frac{1}{h_x^2}[u_{i-1,j}+u_{i+1,j}-2u_{i,j}] +\n  \\frac{1}{h_y^2}[u_{i,j-1}+u_{i,j+1}-2u_{i,j}] & = f_{i j},\n  \\nonumber \\\\\n  \\implies & & u_{i-1,j}+u_{i+1,j}-2u_{i,j} + \\alpha\n  [u_{i,j-1}+u_{i,j+1}-2u_{i,j}] & = h^2f_{i,j},\n\\end{align}\n%\nwhere $u_{i,j} = u(x_i,x_j)$, $\\alpha=(h_x/h_y)^2$ and $h=h_x$.  The\nvalues of $u_{i,j}$ are known when $i=0$ or $n+1$ and when $j=0$ or\n$m+1$, since these are the prescribed boundary values in the problem:\n%\n\\begin{align*}\n  u_{0,j} & = \\phi(x_0,y_j)  = \\phi(0,y_j) , &\n  u_{i,0} & = \\phi(x_i,y_0)  = \\phi(x_i,0), \\\\\n  u_{n+1,j} & = \\phi(x_{n+1},y_j)  = \\phi(a,y_j), &\n  u_{i,m+1} & = \\phi(x_i,y_{m+1})  = \\phi(x_i,b).\n\\end{align*}\n%\nThis means that equation~(\\ref{dp}) has been transformed to a\nnon-homogeneous system of linear equations, given by~(\\ref{eq:ellfd}),\nwith unknowns $u_{i,j}$ and $1\\le i\\le n$, $1\\le j\\le m$.\n\nAs an example, consider the simple case $n=2$ and $m=3$.  The\napproximate solution of equation~(\\ref{dp}) at the grid points are the\nsolution of the $6\\times 6$ system\n%\n\\begin{align*}\n  [u_{01}-2u_{11}+u_{21}]+\\alpha[u_{10}-2u_{11}+u_{12}] &= h^2 f_{11},\\\\\n  [u_{02}-2u_{12}+u_{22}]+\\alpha[u_{11}-2u_{12}+u_{13}] &= h^2 f_{12},\\\\\n  [u_{03}-2u_{13}+u_{23}]+\\alpha[u_{12}-2u_{13}+u_{14}] &= h^2 f_{13},\\\\\n  [u_{11}-2u_{21}+u_{31}]+\\alpha[u_{20}-2u_{21}+u_{22}] &= h^2 f_{21},\\\\\n  [u_{12}-2u_{22}+u_{32}]+\\alpha[u_{21}-2u_{22}+u_{23}] &= h^2 f_{22},\\\\\n  [u_{13}-2u_{23}+u_{33}]+\\alpha[u_{22}-2u_{23}+u_{24}] &= h^2 f_{23}.\n\\end{align*}\n%\nThe unknown quantities in this problem can be ordered in many ways. We\nselect the one known as the natural ordering\n%\n\\begin{equation*}\n  u=[u_{11},u_{12},u_{13},u_{21},u_{22},u_{23}]^T.\n\\end{equation*}\n%\nThe system has the form $A \\bu = \\bF$ with\n%\n\\begin{equation}\n  A = \\begin{pmatrix}\n      -2 (1+\\alpha) & \\alpha & 0 & 1 & 0 & 0 \\\\\n      \\alpha & -2(1+\\alpha) & \\alpha & 0 & 1 & 0 \\\\\n      0 & \\alpha & -2(1+\\alpha) & 0 & 0 & 1 \\\\\n      1 & 0 & 0 & -2(1+\\alpha) & \\alpha & 0 \\\\\n      0 & 1 & 0 & \\alpha & -2(1+\\alpha) & \\alpha \\\\\n      0 & 0 & 1 & 0 & \\alpha & -2(1+\\alpha) \\\\\n    \\end{pmatrix} \\label{eq:PDE:A}\n\\end{equation}\n%\nand\n%\n\\begin{equation*}\n  \\bF =\n  \\begin{pmatrix}\n    h^2f_{11}- u_{01}-\\alpha u_{10} \\\\\n    h^2f_{12}- u_{02} \\\\\n    h^2f_{13}- u_{03}-\\alpha u_{14} \\\\\n    h^2f_{21}- u_{31}-\\alpha u_{20} \\\\\n    h^2f_{22}- u_{32} \\\\\n    h^2f_{23}- u_{33}-\\alpha u_{24}\n  \\end{pmatrix},\n\\end{equation*}\n%\nwhere in the expressions of the components of the vector $\\bF$ only\nthe boundary values of $u_{i,j}$ are present.\n\nIn general, the $n\\times m$ system is sparse because each equation\ncontains at most five unknowns.  Iterative procedures such as the\nGauss-Seidel iterative method can be quite effective in this\nsituation.  Moreover, in setting up such a procedure there is no need\nto store the matrix $A$ of the coefficients defined in\nequation~(\\ref{eq:PDE:A}).  In fact, we can rewrite\nequation~(\\ref{eq:ellfd}) as\n%\n\\begin{align}\n  u_{i,j} &= \\frac{1}{2(1+\\alpha)} \\left [ u_{i-1,j} +u_{i+1,j} +\n    \\alpha (u_{i,j-1}+u_{i,j+1}) - h^2 f_{i,j} \\right ],\n    \\label{PDE:eq:Ell:Updateuij} \\\\ & \\notag \\qquad\n  1 \\le i \\le n, \\, 1 \\le j \\le m .\n\\end{align}\n%\nThis equation is a Gauss-Seidel formula to update $u_{i,j}$. When this\nequation is used, the value obtained from the right-hand side replaces\nthe old value of $u_{i,j}$.  It can also be seen as an implementation\nof Jacobi's method, if we assume that the variable on the left-hand\nside are stored separately from those on the right hand side.  As\ninitial guess of the solution we can assume that $u_{i,j} \\equiv 0$\n(in general we should use a guess that satisfies the boundary\nconditions).  Of course an initial guess close to the solution will\nreduce the number of iterations needed for convergence.\n\n\\subsection{Error analysis}\n\nHow accurate is the solution obtained using~(\\ref{eq:ellfd}) or,\nequivalently~(\\ref{PDE:eq:Ell:Updateuij})? To answer this question\nwe introduce the error\n%\n\\begin{equation*}\n  e_{i,j}=u_{i,j}-\\hat u_{i,j},\n\\end{equation*}\n%\nwhere $\\hat u_{i,j}=u(x_i,y_j)$ are the values of the exact solution\nof equation~(\\ref{dp}). Substituting\n%\n\\begin{equation*}\n  u_{i,j}=e_{i,j}+\\hat u_{i,j}\n\\end{equation*}\n%\ninto the difference equation~(\\ref{eq:ellfd}), we obtain\n%\n\\begin{align*}\n \\frac{1}{h_x^2}[e_{i-1,j}+e_{i+1,j}-2e_{i,j}] +\n \\frac{1}{h_y^2}[e_{i,j-1}+e_{i,j+1}-2e_{i,j}] &= f_{i,j} - \\\\\n & \\qquad \\frac{1}{h_x^2}[\\hat u_{i-1,j}+\\hat u_{i+1,j}-2\\hat u_{i,j}] - \\\\\n & \\qquad \\frac{1}{h_y^2}[\\hat u_{i,j-1}+\\hat u_{i,j+1}-2\\hat u_{i,j}].\n\\end{align*}\n%\nUsing the finite-difference approximation formula~(\\ref{fd}) to\neliminate the finite differences we obtain\n%\n\\begin{align*}\n  \\frac{1}{h_x^2}[e_{i-1,j}+e_{i+1,j}-2e_{i,j}] +\n     \\frac{1}{h_y^2}[e_{i,j-1}+e_{i,j+1}-2e_{i,j}] & =\n     f_{i,j} - \\\\\n     & \\quad [u_{xx}(x_i,y_j) + \\frac{h_x^2}{12}u_{xxxx}(\\xi_i,y_i)] -\n     \\\\\n     & \\quad [u_{y y}(x_i,y_j)+\\frac{h_2^2}{12}u_{yyyy}(x_i,\\zeta_j)] \\\\\n     & = - \\frac{h_x^2}{12}u_{xxxx}(\\xi_i,y_i) -\n     \\frac{h_y^2}{12}u_{yyyy}(x_i,\\zeta_j)\n\\end{align*}\n%\nwhere we have used\n%\n\\begin{equation*}\n  u_{xx}(x_i,y_j)+u_{y y}(x_i,y_j)=f_{i.j}.\n\\end{equation*}\n%\nHence, the error satisfies the difference equation\n%\n\\begin{equation*}\n  e_{i-1,j}+e_{i+1,j}-2e_{i,j}+\\alpha[e_{i,j-1}+e_{i,j+1}-2e_{i,j}]=\n  -\\frac{h_x^4}{12}u_{xxxx}(\\xi_i,y_i)-\n  \\frac{h_x^2 h_y^2}{12}u_{yyyy}(x_i,\\zeta_j),\n\\end{equation*}\n%\nand zero boundary conditions. Analysing this equality, it is possible\nto prove that\n%\n\\begin{equation*}\n  ||e_{i,j}|| \\simeq \\order{h_x h_y}.\n\\end{equation*}\n%\nThis means that in the limit $n\\to +\\infty$ and $m\\to +\\infty$ the\nnorm of the error tends to zero.\n\n\\section{Parabolic Equations}\n\n\\subsection{Introduction}\n\nThroughout this section we assume that the parabolic equation to be\nsolved is\n%\n\\begin{equation}\n  \\pdv{u}{t} = \\pdv[2]{u}{x} , \\qquad 0 \\le x \\le 1, \\, 0 \\le t\n  \\label{PDE:eq:Para:template}\n\\end{equation}\n%\nwith boundary conditions\n%\n\\begin{equation*}\n  u(0,t) = 0, \\qquad u(1,t) = 0,\n\\end{equation*}\n%\nand initial condition $u(x,0) = g(x)$.  There are many finite\ndifference methods to solve equation~(\\ref{PDE:eq:Para:template}).\nHere we consider only a few that are typical examples of their\nrespective classes.  Moreover, it should be noted that\nequation~(\\ref{PDE:eq:Para:template}) is linear.  The methods that we\ndiscuss become much harder to implement in the case of nonlinear\nequations.\n\n\\subsection[Forward-Time, Centred-Space (FTCS)]{An explicit method - Forward-Time, Centred-Space (FTCS)}\n\n\\subsubsection{The method}\n\nWe fix a time discretisation step $\\delta$ and a space discretisation\nstep $h$ so that the solution of equation~(\\ref{PDE:eq:Para:template})\nis represented on the grid\n%\n\\begin{equation*}\n  (x_i,t^n) = (i h, n \\delta), \\qquad 0 \\le i \\le N + 1, \\, n \\ge 0\n\\end{equation*}\n%\nwhere the number of grid points between $x=0$ and $x=1$ is $N+2$.  We\nuse the notation $u_i^n$ to indicate $u(x_i,t^n)$.  We discretise the\ntime derivative in equation~(\\ref{PDE:eq:Para:template}) using a\nforward difference approximation\n%\n\\begin{equation}\n  \\pdv{u}{t} = \\frac{u_i^{n+1}-u_i^{n}}{\\delta} + \\order{\\delta}\n  \\label{PDE:eq:ut}\n\\end{equation}\n%\nand the spatial derivative using\n%\n\\begin{equation}\n  \\pdv[2]{u}{x} = \\frac{u_{i+1}^{n}+u_{i-1}^{n}-2u_{i}^{n}}{h^2} + \\order{h^2}\n  \\label{PDE:eq:uxx}\n\\end{equation}\n%\nso that equation~(\\ref{PDE:eq:Para:template}) is represented by the\nset of (linear) algebraic equations\n%\n\\begin{equation*}\n  u_{i}^{n+1} = u_{i}^{n} +\n  \\frac{\\delta}{h^2} (u_{i+1}^{n}+u_{i-1}^{n}-2u_{i}^{n})\n\\end{equation*}\n%\nor, equivalently,\n%\n\\begin{equation}\n  u_{i}^{n+1} = (1-2s) u_{i}^{n} + s (u_{i+1}^{n}+u_{i-1}^{n})\n  \\label{PDE:eq:Para:expl}\n\\end{equation}\n%\nwhere $s = \\delta/h^2$.  Equation~(\\ref{PDE:eq:Para:expl}) is a finite\ndifference representation of Equation~(\\ref{PDE:eq:Para:template}):\nsince this equation gives the new values of $u_{i}^{n+1}$ explicitly\nin terms of previous values of $u_{i+1}^{n}$, $u_{i}^{n}$ and\n$u_{i-1}^{n}$ the method based on this equation is called an\n\\textit{explicit method}.  As it involves a forward difference\napproximation of the time derivative and a centred approximation of\nthe spatial derivative it is called a \\textit{forward-time\n  centred-space} (FTCS) method.\n\nEquation~(\\ref{PDE:eq:Para:expl}) must be complemented by the\ndiscretized version of the initial and boundary conditions, namely\n%\n\\begin{equation*}\n  u_{0}^{n} = u_{N+1}^{n} = 0 \\qand u_{i}^{0} = g(x_i) .\n\\end{equation*}\n\n\\subsubsection{Consistency, Stability and Convergence}\n\nWe have claimed that equation~(\\ref{PDE:eq:Para:expl}) is a finite\ndifference representation of equation~(\\ref{PDE:eq:Para:template}) and\nthat, therefore, can be used to find an accurate numerical solution to\nthis equation.  Given any algorithm to solve numerically a partial\ndifferential equation we must clearly determine if it is ``good'', in\nthe sense that it can be used to obtain efficiently an accurate\nsolution of the problem we aim to solve.  In order to do this we must\ndefine clearly what we mean by a ``good method''.\n\n\\begin{enumerate}\n  %\n\\item A finite difference equation is \\textbf{consistent} with a\n  partial differential equation if the difference between the Finite\n  Difference Equation (FDE) and the PDE (i.e.\\ the truncation error)\n  vanishes as the sizes of the grid spacings go to zero independently.\n\n  When the truncation error of the finite difference approximations of\n  the individual exact partial derivatives are known, proof of\n  consistency is straightforward. When the truncation errors of the\n  individual finite difference approximations are not known, the\n  complete finite difference equation must be analysed for\n  consistency.  That is accomplished by expressing each term in the\n  finite difference equation by a Taylor series about a particular\n  grid point.  The resulting equation, which is called the modified\n  differential equation (MDE), can be simplified to yield the exact\n  form of the truncation error of the complete finite difference\n  equation.  We will not develop this concept further in this unit.\n  %\n\\item The \\textbf{order} of a finite difference approximation of a\n  partial differential equation is the rate at which the global error\n  of the finite difference solution approaches zero as the size of the\n  grid spacings approach zero.\n\n  The global error of a finite difference equation is the order of the\n  truncation error terms in the finite difference approximations of\n  the individual exact partial derivatives in the Partial Differential\n  Equation.\n  %\n\\item When applied to a partial differential equation that has a\n  bounded solution, a finite difference equation is \\textbf{stable} if\n  it produces a bounded solution and is unstable otherwise.\n\n  If the solution of the FDE is bounded for all values of the grid\n  spacings, then the FDE is \\textit{unconditionally stable}.  If the\n  solution of the FDE is bounded only for certain values of the grid\n  spacings, then the FDE is \\textit{conditionally stable}.  If the\n  solution of the FDE is unbounded for all values of the grid\n  spacings, then the FDE is \\textit{unconditionally unstable}.  The\n  most used method to prove the stability of a (linear) finite\n  difference scheme is the Von Neumann method (see below).\n  %\n\\item A finite difference method is \\textbf{convergent} if the\n  solution of the finite difference equation approaches the exact\n  solution of the partial differential equation as the sizes of the\n  grid spacings go to zero.\n\n  Convergence is the most desirable property of an integration scheme.\n  However it is quite hard to prove directly that a method is\n  convergent.\n%\n\\end{enumerate}\n\nConsistency, stability and convergence are not independent concepts.\nThey are related by the following theorem due to Lax (1954):\n\n\\begin{quote}\n  %\n  Given a properly posed linear initial-value problem and a finite\n  difference approximation to it that is consistent, stability is the\n  necessary and sufficient condition for convergence.\n  %\n\\end{quote}\n\nThus, the question of convergence of a finite difference method is\nanswered by a study of the consistency and stability of the finite\ndifference equation.  If the finite difference equation is consistent\nand stable, then the finite difference method is convergent.\n\nThe Lax equivalence theorem applies to well-posed linear initial-value\nproblems.  May problems in engineering and science are not linear and\nnearly all problems involve boundary conditions in addition to initial\nconditions.  There is no equivalence theorem for such problems.\nNonlinear PDEs must be linearised locally and the FDE that\napproximates the linearised PDE is analysed for stability.  Experience\nhas shown that the stability criteria obtained of the linearised FDE\nalso apply to the nonlinear FDE and that FDEs that are consistent and\nwhose linearised equivalent is stable generally converge even for\nnonlinear initial-boundary-value problems.\n\n\\subsubsection{Consistency, stability and convergence of a FTCS\nmethod}\n\nEquation~(\\ref{PDE:eq:Para:expl}) is first order in time and second\norder in space: in fact the error involved in the discretisation of\nthe time derivative, equation~(\\ref{PDE:eq:ut}), is $\\order{\\delta}$, while\nthe error in the discretisation of the space derivative,\nequation~(\\ref{PDE:eq:uxx}), is $\\order{h^2}$.\n\nEquation~(\\ref{PDE:eq:Para:expl}) is clearly consistent.  As $\\delta\n\\to 0$ and $h \\to 0$ the finite difference approximations of the time\nand space derivatives, equations~(\\ref{PDE:eq:ut},~\\ref{PDE:eq:uxx}),\nconverge to the respective derivatives.\n\nTo verify whether the method given by\nequation~(\\ref{PDE:eq:Para:expl}) is stable, we start by observing\nthat the solution of equation~(\\ref{PDE:eq:Para:template}) with\nboundary conditions $u(0,t)=u(1,t)=0$ tends to zero in the long time\nlimit whatever the initial condition $g(x)$.  Therefore, also the\nsolution of the finite difference approximation,\nequation~(\\ref{PDE:eq:Para:expl}), must tend to zero as the time\ndiscretisation index $n$ tends to infinity.  To verify whether this is\nthe case we use the \\textit{Von Neumann method}.  The solution of\nequation~(\\ref{PDE:eq:Para:expl}) is of the form\n%\n\\begin{equation}\n  u_{\\ell}^{k} = e^{\\tj \\alpha \\ell h} q^k\n  \\label{PDE:eq:uellk}\n\\end{equation}\n%\nwhere $\\tj = \\sqrt{-1}$ while $\\alpha$ and $q$ are real parameters\nthat have to be determined by requiring that~(\\ref{PDE:eq:uellk})\nsatisfies~(\\ref{PDE:eq:Para:expl}).  Substituting~(\\ref{PDE:eq:uellk})\ninto~(\\ref{PDE:eq:Para:expl}) we obtain that $q$ is given by\n%\n\\begin{equation*}\n  q = s \\left ( e^{\\tj \\alpha h} + e^{-\\tj \\alpha h} \\right ) + (1 - 2s) =\n  1 - 4 s \\sin^2 \\left ( \\frac{\\alpha h}{2} \\right ) .\n\\end{equation*}\n%\nIn order for $|u_{\\ell}^{k}|$ to decrease to zero as $k$ tends to\ninfinity we must have\n%\n\\begin{equation}\n  |q| < 1 \\implies s < \\frac{1}{2} \\implies\n  \\frac{\\delta}{h^2} < \\frac{1}{2} .\n  \\label{PDE:eq:FTCSConstr}\n\\end{equation}\n%\nIn other words, the FTCS method~(\\ref{PDE:eq:Para:expl}) is only\nconditionally stable and the time and space discretisation steps,\n$\\delta$ and $h$ respectively, must satisfy the\nconstraint~(\\ref{PDE:eq:FTCSConstr}).  Using the Lax theorem we can\ntherefore conclude that, under these conditions, the FTCS method is\nalso convergent.  However, equation~(\\ref{PDE:eq:FTCSConstr}) is a\nrather stringent constraint as the time step must be reduce by a\nfactor of four if the space step is halved.  Therefore, methods\nlike~(\\ref{PDE:eq:Para:expl}) tend to be rather slow.\n\n\\subsection[Backward-Time, Centred-Space (BTCS)]{An Implicit method - Backward-Time, Centred-Space (BTCS)}\n\n\\subsubsection{The method}\n\nIn the explicit finite difference approximation of the diffusion\nequation the right hand side of equation~(\\ref{PDE:eq:Para:template})\nis computed at the current time step and used to compute the value of\nthe solution at the next time step.  In the implicit finite difference\napproximation the right hand side is ``computed'' at the next time\nstep, so that the finite difference scheme is an implicit equation for\nthe new value of the solution.  In the case of\nequation~(\\ref{PDE:eq:Para:template}) this is accomplished by using a\nbackward difference approximation of the time derivative at\n$t^{n+1}=t+\\delta$ so that equation~(\\ref{PDE:eq:Para:template}) is\ndiscretised as\n%\n\\begin{align}\n && \\frac{u_{i}^{n+1} - u_{i}^{n}}{\\delta} & =\n       \\frac{u_{i+1}^{n+1}+u_{i-1}^{n+1}-2u_{i}^{n+1}}{h^2} \\nonumber \\\\\n \\implies && (1+2s) u_{i}^{n+1} & = u_{i}^{n} + s\n (u_{i+1}^{n+1}+u_{i-1}^{n+1})\n \\label{PDE:eq:Para:BTCS}\n\\end{align}\n%\nwhere $s = \\delta/h^2$ and the unknowns are all the $u_{i}^{n+1}$.\nEquation~(\\ref{PDE:eq:Para:BTCS}) constitutes of a tri-diagonal linear\nsystem for the unknowns $u_{i}^{n}$ with row\n%\n\\begin{equation*}\n  -s u_{i-1}^{n+1} + (1+2s) u_{i}^{n+1} - s u_{i+1}^{n+1} = u_{i}^{n},\n  \\qquad 1 \\le i \\le N .\n\\end{equation*}\n%\nThis system can be solved by Gaussian elimination.  Note, however,\nthat if the partial differential equation is nonlinear then\nequation~(\\ref{PDE:eq:Para:BTCS}) becomes a nonlinear algebraic\nequation for the unknowns $u_{i}^{n+1}$ and is, as a consequence, very\nhard to solve.\n\n\\subsubsection{Consistency, stability and convergence}\n\nLike the FTCS method, the BTCS is first order in time and second order\nin space.  Moreover, it is clearly consistent.\n\nThe stability analysis is very similar to that of the explicit method.\nWe look for a solution of equation~(\\ref{PDE:eq:Para:BTCS}) of the\nform (\\ref{PDE:eq:uellk}) and substitute it in\nequation~(\\ref{PDE:eq:Para:BTCS}).  We obtain that $q$ must satisfy\n%\n\\begin{equation*}\n  q = 1 + 2 s \\left ( e^{\\tj \\alpha h} + e^{-\\tj \\alpha h} - 2 \\right ) q \\implies\n  q = \\frac{1}{1 + 4 s \\sin^2 \\left ( \\frac{\\alpha h}{2} \\right )} \\, .\n\\end{equation*}\n%\nIn other words $|q| < 1$ for all values of $s$ and the backward-time,\ncentred space method is unconditionally stable and, hence,\nunconditionally convergent.\n\n\\section{Hyperbolic Equations}\n\n\\subsection{Introduction}\n\nThe theory of hyperbolic equations and their solutions is quite\ninvolved and is not studied in this unit.  However, it is essential to\nknow it and understand it if any serious work with hyperbolic partial\ndifferential equations is to be attempted.  Here we consider a very\nsimple case and use it to discuss a few methods to integrate\nhyperbolic partial differential equations.  The methods discussed\napply also to more complex cases, but care should be taken to ensure\nthat the solutions obtained are acceptable.\n\nAs an example of a hyperbolic equation we consider the advection\nequation\n%\n\\begin{equation}\n  \\pdv{u}{t} + v \\pdv{u}{x} = 0 , \\qquad a \\le x, \\quad v > 0 .\n  \\label{PDE:eq:advect}\n\\end{equation}\n%\nThis equation represents a function propagating in the positive\n$x$-direction with speed $v$.  In order for the equation to have a\nunique solution we must specify an initial condition, $u(x,0) = F(x)$\nand a boundary condition at $x=a$, $u(a,t) = G(t)$.  Note that the\ndomain is unbounded in the positive $x$-direction: numerically this\nimplies that the numerical solution of equation~(\\ref{PDE:eq:advect})\nis acceptable only if the effects of the right boundary are\nnegligible, i.e.\\ only for the time taken for the signal to propagate\nacross the integration region and reach the right boundary.\n\n\\subsection{The forward-time centred-space method}\n\nThe most straightforward finite difference method for solving\nhyperbolic partial differential equations would appear to be the\nforward-time centred-space (FTCS) method.  Applied to the diffusion\nequation this method is conditionally stable; however, when applied to\nthe convection equation this method is unconditionally unstable.  The\nalgorithm consists in replacing the time derivative in\nequation~(\\ref{PDE:eq:advect}) with its forward difference\napproximation and the space derivative with the centred-difference\napproximation.  We obtain:\n%\n\\begin{equation*}\n  \\frac{u_{i}^{n+1}-u_{i}^{n}}{\\delta} +\n  v \\frac{u_{i+1}^{n}-u_{i-1}^{n}}{2 h} = 0\n\\end{equation*}\n%\nwhere $\\delta$ is the time step, $h$ is the space step, the spatial\ngrid is $x_i = i h$, with $i=0,1,\\ldots,N+1$, the time grid is $t^n =\nn \\delta$ and $u_{i}^{n} = u(x_i,t^n)$.  Solving for $u_{i}^{n}$ we\nobtain\n%\n\\begin{equation}\n  u_{i}^{n+1} = u_{i}^{n} - \\frac{c}{2} (u_{i+1}^{n}-u_{i-1}^{n}) \\, ,\n  \\label{PDE:eq:hypFTCS}\n\\end{equation}\n%\nwhere $c = u \\delta/h$ is the \\textit{convection number}.  The\nstability analysis of this equation shows that the solution\nof~(\\ref{PDE:eq:hypFTCS}) is $u_{\\ell}^{k} = \\exp(\\tj \\alpha \\ell h)\nq^k$, with\n%\n\\begin{equation*}\n  q = 1 - \\tj c \\sin(\\alpha h) ,\n\\end{equation*}\n%\nwhere $\\tj = \\sqrt{-1}$.  From this we obtain that\n%\n\\begin{equation*}\n  |q| = \\sqrt{1 + c^2 \\sin^2(\\alpha h)} > 1 \\, \\, \\forall c \\in \\bR .\n\\end{equation*}\n%\nHence the FTCS method is unconditionally unstable.\n\n\\subsection{The Lax method}\n\nLax (1954) proposed a modification to the FTCS method for the\nconvection equation that yields a conditionally stable method.  In\nthat modification, the value $u_{i}^{n}$ in the finite difference\napproximation of the time derivative is replaced by the average of its\nvalues at the neighbouring points:\n%\n\\begin{equation}\n  u_{i}^{n+1} = \\frac{1}{2} (u_{i+1}^{n} + u_{i-1}^{n}) -\n  \\frac{c}{2} (u_{i+1}^{n}-u_{i-1}^{n}) \\, ,\n  \\label{PDE:eq:hypLax}\n\\end{equation}\n%\nThis method is not consistent in general.  It can be shown that the\npartial differential equation that is represented by\nequation~(\\ref{PDE:eq:hypLax}) is\n%\n\\begin{equation}\n  \\pdv{u}{t} + v \\pdv{u}{x} = \\frac{1}{2}\n  \\left ( \\frac{h^2}{\\delta} - v^2 \\delta \\right )\n  \\pdv[2]{u}{x} +\n  \\frac{1}{3} \\left ( v h^2 - v^3 \\delta^2 \\right ) \\pdv[3]{u}{x} +\n  \\ldots \\, ,\n  \\label{PDE:eq:LaxEquiv}\n\\end{equation}\n%\nwhere $h$ and $\\delta$ are the space and time discretisation steps.\nFrom this equation we can see that as $h$ and $\\delta$ tend to zero\nthe first term on the right hand side does not vanish: on the\ncontrary, it is undetermined.  However, if the two discretisation\nsteps tend to zero so that their ratio is constant, for example at the\nvalue $\\beta = h / \\delta$, then equation~(\\ref{PDE:eq:hypLax})\napproaches the equation\n%\n\\begin{equation}\n  \\pdv{u}{t} + v \\pdv{u}{x} = \\frac{1}{2}\n  \\left ( \\beta h - v^2 \\delta \\right )\n  \\pdv[2]{u}{x}\n  \\label{eq:PDE:LaxMDE}\n\\end{equation}\n%\nas $h$ and $\\delta$ tend to zero.  The equation~(\\ref{eq:PDE:LaxMDE})\nis a parabolic convection-diffusion equation.  Substituting the\nconvection number $c=v \\delta/h$ into equation~(\\ref{eq:PDE:LaxMDE})\nwe obtain\n%\n\\begin{equation}\n  \\pdv{u}{t} + v \\pdv{u}{x} = \\frac{1}{2} v h\n  \\left ( \\frac{1}{c} - c \\right ) \\pdv[2]{u}{x}\n  \\label{eq:PDE:LaxMDE1}\n\\end{equation}\n%\nIn other words if $c \\neq 1$ the Lax approximation introduces some\nnumerical diffusion in the model that is to be integrated.  This\neffect is common to most finite difference schemes: it is normally not\nimportant if the original equation includes a diffusive term.  It may,\nhowever, give completely false results if no diffusion terms are\npresent in the original equation.  In the case of the advection\nequation the effect of the numerical diffusion is to smooth the\nsignals as they propagate and decrease their amplitude.\n\n\nAnother effect of the numerical diffusion of the Lax algorithm is to\nmake it conditionally stable.  The Von Neumann stability analysis\nshows that the method is stable if\n%\n\\begin{equation}\n  c = \\frac{v \\delta}{h} \\le 1 .\n  \\label{eq:PDE:hyp:CFL}\n\\end{equation}\n%\nComparing this result with equation~(\\ref{eq:PDE:LaxMDE1}) we see that\nthe scheme is stable if numerical diffusion is present.\nEquation~(\\ref{eq:PDE:hyp:CFL}) is called the Courant-Friedrichs-Lewy\nstability criterion.  It states that the numerical speed of\npropagation $v_{num} = h/ \\delta$ must be greater than or equal to the\nphysical speed of propagation $v$.\n\n\\subsubsection{Derivation of Equation~(\\ref{PDE:eq:LaxEquiv})}\n\nTo obtain equation~(\\ref{PDE:eq:LaxEquiv}) we Taylor expand\n$u_{i}^{n+1}$ and $u_{i\\pm 1}^{n}$ around $u_{i}^{n}$ (indicated with\n$u$ in what follows):\n%\n\\begin{align*}\n u_{i}^{n+1} &= u + \\delta \\partial_t u +\n                 \\frac{\\delta^2}{2}\\partial_{t t} u +\n                 \\frac{\\delta^3}{3!} \\partial_{t t t} u + \\order{\\delta^4}, \\\\\n u_{i\\pm 1}^{n} &= u + h \\partial_x u \\pm\n                 \\frac{h^2}{2}\\partial_{x x} u \\pm\n                 \\frac{h^3}{3!} \\partial_{x x x} u + \\order{h^4} .\n\\end{align*}\n%\nSubstituting into equation~(\\ref{PDE:eq:hypLax}) and dividing through\nby $\\delta$ we obtain\n%\n\\begin{equation}\n  \\partial_t u + v \\partial_x u =\n  -\\frac{\\delta}{2} \\partial_{t t} u\n  -\\frac{\\delta^2}{6} \\partial_{t t t} u\n  + \\frac{h^2}{2 \\delta} \\partial_{x x} u\n  - \\frac{v h^2}{6} \\partial_{x x x}u + \\order{\\delta^3} + \\order{h^3}\n  \\label{eq:PDE:14}\n\\end{equation}\n%\nWe now wish to replace the derivatives with respect to time with\nderivatives respect to space using this relation.  At first order in\n$\\delta$ we have that [we indicate with $\\order{\\delta^n}$ terms that are\nof the order of $n$ in either $\\delta$ or $h$]:\n%\n\\begin{equation}\n  \\partial_t u = - v \\partial_x u + \\order{\\delta}  \\label{PDE:eq:16}\n\\end{equation}\n%\nso that\n%\n\\begin{equation}\n  \\partial_{t t} u = - v \\partial_x \\partial_t u + \\order{\\delta} =\n  v^2 \\partial_{x x} u + \\order{\\delta}\n  \\label{PDE:eq:15}\n\\end{equation}\n%\nThis is not accurate enough to be replaced into\nequation~(\\ref{eq:PDE:14}): we need to obtain an expression correct up\nto second order in the space and time steps.  Starting once again from\nequation~(\\ref{eq:PDE:14}) we have\n%\n\\begin{equation*}\n  \\partial_t u = -v \\partial_x u\n  - \\frac{\\delta}{2} \\partial_{t t} u + \\order{\\delta^2} .\n\\end{equation*}\n%\nDifferentiating with respect to time on both sides and making use\nof~(\\ref{PDE:eq:16}) and~(\\ref{PDE:eq:15}) we obtain:\n%\n\\begin{align*}\n \\partial_{t t} u &=  -v \\partial_x \\partial_t u\n   - \\frac{\\delta}{2} \\partial_t \\partial_{t t} u + \\order{\\delta^2} \\\\\n  &=  -v \\partial_x \\left ( -v \\partial_x u\n   - \\frac{\\delta}{2} \\partial_{t t} u \\right )\n   - \\frac{\\delta}{2} \\partial_t v^2 \\partial_{x x} u + \\order{\\delta^2} \\\\\n  &=  v^2 \\partial_{x x} u + v \\partial_x\n        \\left ( \\frac{\\delta}{2} v^2 \\partial_{x x} u \\right ) +\n      v^3 \\frac{\\delta}{2} \\partial_{x x x} u + \\order{\\delta^2} \\\\\n  &=  v^2 \\partial_{x x} u + \\delta v^3 \\partial_{x x x} u +\n      \\order{\\delta^2}.\n\\end{align*}\n%\nDifferentiating equation~(\\ref{PDE:eq:15}) with respect to time we\nobtain\n%\n\\begin{equation*}\n  \\partial_{t t t} u = -v^3 \\partial_{x x x} u + \\order{\\delta} ,\n\\end{equation*}\n%\nand substituing both these expression into equation~(\\ref{eq:PDE:14})\nwe (finally) obtain equation~(\\ref{PDE:eq:LaxEquiv}).\n\n\\subsection{Upwind methods}\n\nA salient feature of hyperbolic equations is that they describe the\npropagation of information.  In the case of the advection\nequation~(\\ref{PDE:eq:advect}) the information propagates from\nnegative to positive $x$ with speed $v$.  This type of information\npropagation is referred to as \\textit{upwind} propagation, since the\ninformation comes from the direction from which the convection\nvelocity comes, that is, the upwind direction.  Finite difference\nmethods that account for the upwind influence are called\n\\textit{upwind} methods.\n\nThe simplest procedure for developing an upwind finite difference\nequation is to replace the time derivative by the first-order\nforward-difference approximation and the space derivative by the\nfirst-order one-sided-difference approximation in the upwind\ndirection.  For $v > 0$ the finite difference upwind approximation of\nequation~(\\ref{PDE:eq:advect}) is\n%\n\\begin{align}\n  && \\frac{u_{i}^{n+1}-u_{i}^{n}}{\\delta} + v\n  \\frac{u_{i}^{n} - u_{i-1}^{n}}{h} &= 0 \\\\ \\implies &&\n  u_{i}^{n+1} &= u_{i}^{n} - c ( u_{i}^{n} - u_{i-1}^{n} ) ,\n  \\label{eq:PDE:Upw}\n\\end{align}\n%\nwhere $c=v \\delta/h$ is the convection number.  The upwind method is\nconsistent, first order in time and space and stable if $c \\le 1$,\ni.e.\\ if the convection number satisfies the Courant-Friedrichs-Lewy\ncondition.  As in the case of the Lax scheme numerical diffusion (and\ndispersion) is present unless $c=1$.\n\n\\section*{Further reading}\n\nTopics covered here are also covered in\n\\begin{itemize}\n\\item Chapters 12 and 13 of Linz \\& Wang, \\textit{Exploring Numerical\n    Methods} (QA297 LIN),\n\\item Chapter 9 of Kincaid \\& Cheney, \\textit{Numerical Analysis}\n  (QA297 KIN),\n\\item Parts II and III (especially chapters 13 and 14) of Iserles,\n  \\textit{A First Course in the Numerical Analysis of Differential\n    Equations} (QA297 ISE).\n\\end{itemize}\n", "meta": {"hexsha": "3fcf3af76b91fdab73928cd79378c7202400aaf8", "size": 37473, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/tex/PDE.tex", "max_stars_repo_name": "josh-gree/NumericalMethods", "max_stars_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 76, "max_stars_repo_stars_event_min_datetime": "2015-02-12T19:51:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T15:34:11.000Z", "max_issues_repo_path": "Notes/tex/PDE.tex", "max_issues_repo_name": "josh-gree/NumericalMethods", "max_issues_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-05-24T19:49:52.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-23T21:40:42.000Z", "max_forks_repo_path": "Notes/tex/PDE.tex", "max_forks_repo_name": "josh-gree/NumericalMethods", "max_forks_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2015-01-05T13:30:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-15T09:59:39.000Z", "avg_line_length": 38.0050709939, "max_line_length": 106, "alphanum_fraction": 0.6998372161, "num_tokens": 12184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.870597265050901, "lm_q2_score": 0.8539127455162772, "lm_q1q2_score": 0.7434141008385768}}
{"text": "%!TEX root = main.tex\n\n\\appendix\n\\onecolumn\n\\section*{Overview}\n\\begin{table}[H]\n    \\centering\n    \\hspace*{-1cm}\\begin{tabular}{lllll}\n    \\toprule\n    Name                     & Function $\\varphi(x)$ & Range of Values & $\\varphi'(x)$ & Used by \\\\\\midrule % \n    Sign function$^\\dagger$  & $\\begin{cases}+1 &\\text{if } x \\geq 0\\\\-1 &\\text{if } x < 0\\end{cases}$ & $\\Set{-1,1}$                              & $0$                    & \\cite{971754} \\\\\n    \\parbox[t]{2.6cm}{Heaviside\\\\step function$^\\dagger$} & $\\begin{cases}+1 &\\text{if } x > 0\\\\0 &\\text{if } x < 0\\end{cases}$ & $\\Set{0, 1}$  & $0$                       & \\cite{mcculloch1943logical}\\\\\n    Logistic function        & $\\frac{1}{1+e^{-x}}$                           & $[0, 1]$                                                        & $\\frac{e^x}{(e^x +1)^2}$  & \\cite{duch1999survey} \\\\\n    Tanh                     & $\\frac{e^x - e^{-x}}{e^x + e^{-x}} = \\tanh(x)$ & $[-1, 1]$                                                       & $\\sech^2(x)$              & \\cite{LeNet-5,Thoma:2014}\\\\\n    \\gls{ReLU}$^\\dagger$           & $\\max(0, x)$                                   & $[0, +\\infty)$                                                  & $\\begin{cases}1 &\\text{if } x > 0\\\\0 &\\text{if } x < 0\\end{cases}$      & \\cite{AlexNet-2012}\\\\\n    \\parbox[t]{2.6cm}{\\gls{LReLU}$^\\dagger$\\footnotemark\\\\(\\gls{PReLU})} & $\\varphi(x) = \\max(\\alpha x, x)$                        & $(-\\infty, +\\infty)$                                             & $\\begin{cases}1 &\\text{if } x > 0\\\\\\alpha &\\text{if } x < 0\\end{cases}$ & \\cite{maas2013rectifier,he2015delving} \\\\\n    Softplus                 & $\\log(e^x + 1)$                                & $(0, +\\infty)$                                       & $\\frac{e^x}{e^x + 1}$    & \\cite{dugas2001incorporating,glorot2011deep} \\\\\n    \\gls{ELU}                & $\\begin{cases}x &\\text{if } x > 0\\\\\\alpha (e^x - 1) &\\text{if } x \\leq 0\\end{cases}$ & $(-\\infty, +\\infty)$ & $\\begin{cases}1 &\\text{if } x > 0\\\\\\alpha e^x &\\text{otherwise}\\end{cases}$ & \\cite{clevert2015fast} \\\\\n    Softmax$^\\ddagger$       & $o(\\mathbf{x})_j = \\frac{e^{x_j}}{\\sum_{k=1}^K e^{x_k}}$    & $[0, 1]^K$                                           & $o(\\mathbf{x})_j \\cdot \\frac{\\sum_{k=1}^K e^{x_k} - e^{x_j}}{\\sum_{k=1}^K e^{x_k}}$         & \\cite{AlexNet-2012,Thoma:2014}\\\\\n    Maxout$^\\ddagger$        & $o(\\mathbf{x}) = \\max_{x \\in \\mathbf{x}} x$                 & $(-\\infty, +\\infty)$                                 & $\\begin{cases}1 &\\text{if } x_i = \\max \\mathbf{x}\\\\0 &\\text{otherwise}\\end{cases}$          & \\cite{goodfellow2013maxout}       \\\\\n    \\bottomrule\n    \\end{tabular}\n    \\caption[Activation functions]{Overview of activation functions. Functions\n             marked with $\\dagger$ are not differentiable at 0 and functions\n             marked with $\\ddagger$ operate on all elements of a layer\n             simultaneously. The hyperparameters $\\alpha \\in (0, 1)$ of Leaky\n             ReLU and ELU are typically $\\alpha = 0.01$. Other activation\n             function like randomized leaky ReLUs exist~\\cite{xu2015empirical},\n             but are far less commonly used.\\\\\n             Some functions are smoothed versions of others, like the logistic\n             function for the Heaviside step function, tanh for the sign\n             function, softplus for ReLU.\\\\\n             Softmax is the standard activation function for the last layer of\n             a classification network as it produces a probability\n             distribution. See \\Cref{fig:activation-functions-plot} for a plot\n             of some of them.}\n    \\label{table:activation-functions-overview}\n\\end{table}\n\\footnotetext{$\\alpha$ is a hyperparameter in leaky ReLU, but a learnable parameter in the parametric ReLU function.}\n\n\\section*{Evaluation Results}\n\\glsunset{LReLU}\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{@{\\extracolsep{4pt}}lcccccc@{}}\n    \\toprule\n    \\multirow{2}{*}{Function} & \\multicolumn{4}{c}{Single model}                                                    & \\multicolumn{2}{c}{Ensemble of 10} \\\\\\cline{2-3}\\cline{4-5}\\cline{6-7}\n                   & \\multicolumn{2}{c}{Training set}     &\\multicolumn{2}{c}{Test set}                  & Training set         & Test set \\\\\\midrule\n    Identity       & \\SI{66.25}{\\percent} & $\\boldsymbol{\\sigma=0.77}$ &\\SI{56.74}{\\percent} & \\textbf{$\\sigma=0.51$} & \\SI{68.77}{\\percent} & \\SI{58.78}{\\percent}\\\\\n    Logistic       & \\SI{51.87}{\\percent} & $\\sigma=3.64$ &\\SI{46.54}{\\percent} & $\\sigma=3.22$          & \\SI{61.19}{\\percent} & \\SI{54.58}{\\percent}\\\\\n    Logistic$^-$   & \\SI{66.49}{\\percent} & $\\sigma=1.99$ &\\SI{57.84}{\\percent} & $\\sigma=1.15$          & \\SI{69.04}{\\percent} & \\SI{60.10}{\\percent}\\\\\n    Softmax        & \\SI{75.22}{\\percent} & $\\sigma=2.41$ &\\SI{59.49}{\\percent} & $\\sigma=1.25$          & \\SI{78.87}{\\percent} & \\SI{63.06}{\\percent}\\\\\n    Tanh           & \\SI{67.27}{\\percent} & $\\sigma=2.38$ &\\SI{55.70}{\\percent} & $\\sigma=1.44$          & \\SI{70.21}{\\percent} & \\SI{58.10}{\\percent}\\\\\n    Softsign       & \\SI{66.43}{\\percent} & $\\sigma=1.74$ &\\SI{55.75}{\\percent} & $\\sigma=0.93$          & \\SI{69.78}{\\percent} & \\SI{58.40}{\\percent}\\\\\n    \\gls{ReLU}     & \\SI{78.62}{\\percent} & $\\sigma=2.15$ &\\SI{62.18}{\\percent} & $\\sigma=0.99$          & \\SI{81.81}{\\percent} & \\SI{64.57}{\\percent}\\\\\n    \\gls{ReLU}$^-$ & \\SI{76.01}{\\percent} & $\\sigma=2.31$ &\\SI{62.87}{\\percent} & $\\sigma=1.08$          & \\SI{78.18}{\\percent} & \\SI{64.81}{\\percent}\\\\\n    Softplus       & \\SI{66.75}{\\percent} & $\\sigma=2.45$ &\\SI{56.68}{\\percent} & $\\sigma=1.32$          & \\SI{71.27}{\\percent} & \\SI{60.26}{\\percent}\\\\\n    S2ReLU         & \\SI{63.32}{\\percent} & $\\sigma=1.69$ &\\SI{56.99}{\\percent} & $\\sigma=1.14$          & \\SI{65.80}{\\percent} & \\SI{59.20}{\\percent}\\\\\n    \\gls{LReLU}    & \\SI{74.92}{\\percent} & $\\sigma=2.49$ &\\SI{61.86}{\\percent} & $\\sigma=1.23$          & \\SI{77.67}{\\percent} & \\SI{64.01}{\\percent}\\\\\n    \\gls{PReLU}    & \\textbf{\\SI{80.01}{\\percent}} & $\\sigma=2.03$ &\\SI{62.16}{\\percent} & $\\sigma=0.73$ & \\textbf{\\SI{83.50}{\\percent}} & \\textbf{\\SI{64.79}{\\percent}}\\\\\n    \\gls{ELU}      & \\SI{76.64}{\\percent} & $\\sigma=1.48$ &\\textbf{\\SI{63.38}{\\percent}} & $\\sigma=0.55$ & \\SI{78.30}{\\percent} & \\SI{64.70}{\\percent}\\\\\n    \\bottomrule\n    \\end{tabular}\n    \\caption[Activation function evaluation results on CIFAR-100]{Training and\n             test accuracy of adjusted baseline models trained with different\n             activation functions on CIFAR-100. For \\gls{LReLU}, $\\alpha = 0.3$ was\n             chosen.}\n    \\label{table:CIFAR-100-accuracies-activation-functions}\n\\end{table}\n\n\\begin{table}[H]\n    \\centering\n    \\setlength\\tabcolsep{1.5pt}\n    \\begin{tabular}{@{\\extracolsep{4pt}}lcccccccr@{}}\n    \\toprule\n    \\multirow{2}{*}{Function} & \\multicolumn{4}{c}{Single model}              & \\multicolumn{2}{c}{Ensemble of 10} & \\multicolumn{2}{c}{Epochs}\\\\\\cline{2-5}\\cline{6-7}\\cline{8-9}\n                              & \\multicolumn{2}{c}{Training set}     &\\multicolumn{2}{c}{Test set}                  & Train                & Test                 & Range     & \\multicolumn{1}{c}{Mean} \\\\\\midrule\n    Identity                  & \\SI{87.92}{\\percent} & $\\sigma=0.40$ & \\SI{84.69}{\\percent} & $\\sigma=0.08$         & \\SI{88.59}{\\percent} & \\SI{85.43}{\\percent} & \\hphantom{0}92 -- 140 & 114.5\\\\%TODO: Really?\n    Logistic                  & \\SI{81.46}{\\percent} & $\\sigma=5.08$ & \\SI{79.67}{\\percent} & $\\sigma=4.85$         & \\SI{86.38}{\\percent} & \\SI{84.60}{\\percent} & \\hphantom{0}\\textbf{58} -- \\hphantom{0}\\textbf{91}  & \\textbf{77.3}\\\\\n    Softmax                   & \\SI{88.19}{\\percent} & $\\sigma=0.31$ & \\SI{84.70}{\\percent} & $\\sigma=0.15$         & \\SI{88.69}{\\percent} & \\SI{85.43}{\\percent} & 124 -- 171& 145.8\\\\\n    Tanh                      & \\SI{88.41}{\\percent} & $\\sigma=0.36$ & \\SI{84.46}{\\percent} & $\\sigma=0.27$         & \\SI{89.24}{\\percent} & \\SI{85.45}{\\percent} & \\hphantom{0}89 -- 123 & 108.7\\\\\n    Softsign                  & \\SI{88.00}{\\percent} & $\\sigma=0.47$ & \\SI{84.46}{\\percent} & $\\sigma=0.23$         & \\SI{88.77}{\\percent} & \\SI{85.33}{\\percent} & \\hphantom{0}77 -- 119 & 104.1\\\\\n    \\gls{ReLU}                & \\SI{88.93}{\\percent} & $\\sigma=0.46$ & \\textbf{\\SI{85.35}{\\percent}} & $\\sigma=0.21$         & \\SI{89.35}{\\percent} & \\SI{85.95}{\\percent} & \\hphantom{0}96 -- 132 & 102.8\\\\\n    Softplus                  & \\SI{88.42}{\\percent} & $\\boldsymbol{\\sigma=0.29}$ & \\SI{85.16}{\\percent} & $\\sigma=0.15$         & \\SI{88.90}{\\percent} & \\SI{85.73}{\\percent} &            108 -- 143 & 121.0\\\\\n    \\gls{LReLU}               & \\SI{88.61}{\\percent} & $\\sigma=0.41$ & \\SI{85.21}{\\percent} & $\\boldsymbol{\\sigma=0.05}$         & \\SI{89.07}{\\percent} & \\SI{85.83}{\\percent} & \\hphantom{0}87 -- 117 & 104.5\\\\\n    \\gls{PReLU}               & \\textbf{\\SI{89.62}{\\percent}} & $\\sigma=0.41$ & \\textbf{\\SI{85.35}{\\percent}} & $\\sigma=0.17$& \\textbf{\\SI{90.10}{\\percent}} & \\SI{86.01}{\\percent} & \\hphantom{0}85 -- 111 & 100.5\\\\\n    \\gls{ELU}                 & \\SI{89.49}{\\percent} & $\\sigma=0.42$ & \\textbf{\\SI{85.35}{\\percent}} & $\\sigma=0.10$         & \\SI{89.94}{\\percent} & \\textbf{\\SI{86.03}{\\percent}} & \\hphantom{0}73 -- 113 &  92.4\\\\\n    \\bottomrule\n    \\end{tabular}\n    \\caption[Activation function evaluation results on HASYv2]{Test accuracy of\n             adjusted baseline models trained with different activation\n             functions on HASYv2. For \\gls{LReLU}, $\\alpha = 0.3$ was chosen.}\n    \\label{table:HASYv2-accuracies-activation-functions}\n\\end{table}\n\n\\begin{table}[H]\n    \\centering\n    \\setlength\\tabcolsep{1.5pt}\n    \\begin{tabular}{@{\\extracolsep{4pt}}lcccccccr@{}}\n    \\toprule\n    \\multirow{2}{*}{Function} & \\multicolumn{4}{c}{Single model}              & \\multicolumn{2}{c}{Ensemble of 10} & \\multicolumn{2}{c}{Epochs}\\\\\\cline{2-5}\\cline{6-7}\\cline{8-9}\n                              & \\multicolumn{2}{c}{Training set}     &\\multicolumn{2}{c}{Test set}                  & Train                & Test                 & Range     & \\multicolumn{1}{c}{Mean} \\\\\\midrule\n    Identity                  & \\SI{87.49}{\\percent} & $\\sigma=2.50$ & \\SI{69.86}{\\percent} & $\\sigma=1.41$         & \\SI{89.78}{\\percent} & \\SI{71.90}{\\percent} & \\hphantom{0}51 -- \\hphantom{0}65  &  53.4\\\\\n    Logistic                  & \\SI{45.32}{\\percent} & $\\sigma=14.88$& \\SI{40.85}{\\percent} & $\\sigma=12.56$        & \\SI{51.06}{\\percent} & \\SI{45.49}{\\percent} & \\hphantom{0}38 -- \\hphantom{0}93  &  74.6\\\\\n    Softmax                   & \\SI{87.90}{\\percent} & $\\sigma=3.58$ & \\SI{67.91}{\\percent} & $\\sigma=2.32$         & \\SI{91.51}{\\percent} & \\SI{70.96}{\\percent} & 108 -- 150           & 127.5\\\\\n    Tanh                      & \\SI{85.38}{\\percent} & $\\sigma=4.04$ & \\SI{67.65}{\\percent} & $\\sigma=2.01$         & \\SI{90.47}{\\percent} & \\SI{71.29}{\\percent} & 48 -- \\hphantom{0}92 & 65.2\\\\\n    Softsign                  & \\SI{88.57}{\\percent} & $\\sigma=4.00$ & \\SI{69.32}{\\percent} & $\\sigma=1.68$         & \\SI{93.04}{\\percent} & \\SI{72.40}{\\percent} & 55 -- 117            & 83.2\\\\\n    \\gls{ReLU}                & \\SI{94.35}{\\percent} & $\\sigma=3.38$ & \\SI{71.01}{\\percent} & $\\sigma=1.63$         & \\SI{98.20}{\\percent} & \\SI{74.85}{\\percent} & 52 -- \\hphantom{0}98 & 75.5\\\\\n    Softplus                  & \\SI{83.03}{\\percent} & $\\sigma=2.07$ & \\SI{68.28}{\\percent} & $\\sigma=1.74$         & \\SI{93.04}{\\percent} & \\SI{75.99}{\\percent} & 56 -- \\hphantom{0}89 & 68.9\\\\\n    \\gls{LReLU}               & \\SI{93.83}{\\percent} & $\\sigma=3.89$ & \\SI{74.66}{\\percent} & $\\sigma=2.11$         & \\SI{97.56}{\\percent} & \\SI{78.08}{\\percent} & 52 -- 120 & 80.1\\\\\n    \\gls{PReLU}               & \\SI{95.53}{\\percent} & $\\sigma=1.92$ & \\SI{71.69}{\\percent} & $\\sigma=1.37$         & \\SI{98.17}{\\percent} & \\SI{74.69}{\\percent} & 59 -- 101 & 78.8\\\\\n    \\gls{ELU}                 & \\SI{95.42}{\\percent} & $\\sigma=3.57$ & \\SI{75.09}{\\percent} & $\\sigma=2.39$         & \\SI{98.54}{\\percent} & \\SI{78.66}{\\percent} & 66 -- \\hphantom{0}72 & 67.2\\\\\n    \\bottomrule\n    \\end{tabular}\n    \\caption[Activation function evaluation results on STL-10]{Test accuracy of\n             adjusted baseline models trained with different activation\n             functions on STL-10. For \\gls{LReLU}, $\\alpha = 0.3$ was chosen.}\n    \\label{table:STL-10-accuracies-activation-functions}\n\\end{table}\n\n\\begin{table}[H]\n    \\centering\n    \\hspace*{-1cm}\\begin{tabular}{lllll}\n    \\toprule\n    Name                     & Function $\\varphi(x)$ & Range of Values & $\\varphi'(x)$ \\\\\\midrule % & Used by \n    Sign function$^\\dagger$  & $\\begin{cases}+1 &\\text{if } x \\geq 0\\\\-1 &\\text{if } x < 0\\end{cases}$ & $\\Set{-1,1}$                              & $0$                    \\\\%& \\cite{971754} \\\\\n    \\parbox[t]{2.6cm}{Heaviside\\\\step function$^\\dagger$} & $\\begin{cases}+1 &\\text{if } x > 0\\\\0 &\\text{if } x < 0\\end{cases}$ & $\\Set{0, 1}$  & $0$                       \\\\%& \\cite{mcculloch1943logical}\\\\\n    Logistic function        & $\\frac{1}{1+e^{-x}}$                           & $[0, 1]$                                                        & $\\frac{e^x}{(e^x +1)^2}$  \\\\%& \\cite{duch1999survey} \\\\\n    Tanh                     & $\\frac{e^x - e^{-x}}{e^x + e^{-x}} = \\tanh(x)$ & $[-1, 1]$                                                       & $\\sech^2(x)$              \\\\%& \\cite{LeNet-5,Thoma:2014}\\\\\n    \\gls{ReLU}$^\\dagger$           & $\\max(0, x)$                                   & $[0, +\\infty)$                                                  & $\\begin{cases}1 &\\text{if } x > 0\\\\0 &\\text{if } x < 0\\end{cases}$      \\\\%& \\cite{AlexNet-2012}\\\\\n    \\parbox[t]{2.6cm}{\\gls{LReLU}$^\\dagger$\\footnotemark\\\\(\\gls{PReLU})} & $\\varphi(x) = \\max(\\alpha x, x)$                        & $(-\\infty, +\\infty)$                                             & $\\begin{cases}1 &\\text{if } x > 0\\\\\\alpha &\\text{if } x < 0\\end{cases}$ \\\\%& \\cite{maas2013rectifier,he2015delving} \\\\\n    Softplus                 & $\\log(e^x + 1)$                                & $(0, +\\infty)$                                       & $\\frac{e^x}{e^x + 1}$    \\\\%& \\cite{dugas2001incorporating,glorot2011deep} \\\\\n    \\gls{ELU}                & $\\begin{cases}x &\\text{if } x > 0\\\\\\alpha (e^x - 1) &\\text{if } x \\leq 0\\end{cases}$ & $(-\\infty, +\\infty)$ & $\\begin{cases}1 &\\text{if } x > 0\\\\\\alpha e^x &\\text{otherwise}\\end{cases}$ \\\\%& \\cite{clevert2015fast} \\\\\n    Softmax$^\\ddagger$       & $o(\\mathbf{x})_j = \\frac{e^{x_j}}{\\sum_{k=1}^K e^{x_k}}$    & $[0, 1]^K$                                           & $o(\\mathbf{x})_j \\cdot \\frac{\\sum_{k=1}^K e^{x_k} - e^{x_j}}{\\sum_{k=1}^K e^{x_k}}$          \\\\%& \\cite{AlexNet-2012,Thoma:2014}\\\\\n    Maxout$^\\ddagger$        & $o(\\mathbf{x}) = \\max_{x \\in \\mathbf{x}} x$                 & $(-\\infty, +\\infty)$                                 & $\\begin{cases}1 &\\text{if } x_i = \\max \\mathbf{x}\\\\0 &\\text{otherwise}\\end{cases}$          \\\\%& \\cite{goodfellow2013maxout}       \\\\\n    \\bottomrule\n    \\end{tabular}\n    \\caption[Activation functions]{Overview of activation functions. Functions\n             marked with $\\dagger$ are not differentiable at 0 and functions\n             marked with $\\ddagger$ operate on all elements of a layer\n             simultaneously. The hyperparameters $\\alpha \\in (0, 1)$ of Leaky\n             ReLU and ELU are typically $\\alpha = 0.01$. Other activation\n             function like randomized leaky ReLUs exist~\\cite{xu2015empirical},\n             but are far less commonly used.\\\\\n             Some functions are smoothed versions of others, like the logistic\n             function for the Heaviside step function, tanh for the sign\n             function, softplus for ReLU.\\\\\n             Softmax is the standard activation function for the last layer of\n             a classification network as it produces a probability\n             distribution. See \\Cref{fig:activation-functions-plot} for a plot\n             of some of them.}\n    \\label{table:activation-functions-overview}\n\\end{table}\n\\footnotetext{$\\alpha$ is a hyperparameter in leaky ReLU, but a learnable parameter in the parametric ReLU function.}\n\n\\begin{figure}[ht]\n    \\centering\n    \\begin{tikzpicture}\n        \\definecolor{color1}{HTML}{E66101}\n        \\definecolor{color2}{HTML}{FDB863}\n        \\definecolor{color3}{HTML}{B2ABD2}\n        \\definecolor{color4}{HTML}{5E3C99}\n        \\begin{axis}[\n            legend pos=north west,\n            legend cell align={left},\n            axis x line=middle,\n            axis y line=middle,\n            x tick label style={/pgf/number format/fixed,\n                                /pgf/number format/fixed zerofill,\n                                /pgf/number format/precision=1},\n            y tick label style={/pgf/number format/fixed,\n                                /pgf/number format/fixed zerofill,\n                                /pgf/number format/precision=1},\n            grid = major,\n            width=16cm,\n            height=8cm,\n            grid style={dashed, gray!30},\n            xmin=-2,     % start the diagram at this x-coordinate\n            xmax= 2,     % end   the diagram at this x-coordinate\n            ymin=-1,     % start the diagram at this y-coordinate\n            ymax= 2,     % end   the diagram at this y-coordinate\n            xlabel=x,\n            ylabel=y,\n            tick align=outside,\n            enlargelimits=false]\n          \\addplot[domain=-2:2, color1, ultra thick,samples=500] {1/(1+exp(-x))};\n          \\addplot[domain=-2:2, color2, ultra thick,samples=500] {tanh(x)};\n          \\addplot[domain=-2:2, color4, ultra thick,samples=500] {max(0, x)};\n          \\addplot[domain=-2:2, color4, ultra thick,samples=500, dashed] {ln(exp(x) + 1)};\n          \\addplot[domain=-2:2, color3, ultra thick,samples=500, dotted] {max(x, exp(x) - 1)};\n          \\addlegendentry{$\\varphi_1(x)=\\frac{1}{1+e^{-x}}$}\n          \\addlegendentry{$\\varphi_2(x)=\\tanh(x)$}\n          \\addlegendentry{$\\varphi_3(x)=\\max(0, x)$}\n          \\addlegendentry{$\\varphi_4(x)=\\log(e^x + 1)$}\n          \\addlegendentry{$\\varphi_5(x)=\\max(x, e^x - 1)$}\n        \\end{axis}\n    \\end{tikzpicture}\n    \\caption[Activation functions]{Activation functions plotted in $[-2, +2]$.\n             $\\tanh$ and ELU are able to produce negative numbers. The image of\n             ELU, ReLU and Softplus is not bound on the positive side, whereas\n             $\\tanh$ and the logistic function are always below~1.}\n    \\label{fig:activation-functions-plot}\n\\end{figure}\n\n\\glsreset{LReLU}\n\\twocolumn", "meta": {"hexsha": "f51a02425b5f7fc8b7e5c99ccc84e274f4dcad52", "size": 18564, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "publications/activation-functions/appendix.tex", "max_stars_repo_name": "RalfGuder/LaTeX-examples", "max_stars_repo_head_hexsha": "a1bf9fe422969be1ca4674394ebd2170c07f7693", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1231, "max_stars_repo_stars_event_min_datetime": "2015-01-07T04:04:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T17:43:29.000Z", "max_issues_repo_path": "publications/activation-functions/appendix.tex", "max_issues_repo_name": "DoubleL61/LaTeX-examples", "max_issues_repo_head_hexsha": "cd0d97f85fadb59b7c6e9062b37a8bf7d725ba0c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2015-05-10T13:10:47.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-02T21:28:49.000Z", "max_forks_repo_path": "publications/activation-functions/appendix.tex", "max_forks_repo_name": "DoubleL61/LaTeX-examples", "max_forks_repo_head_hexsha": "cd0d97f85fadb59b7c6e9062b37a8bf7d725ba0c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 400, "max_forks_repo_forks_event_min_datetime": "2015-01-05T06:22:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-19T04:07:59.000Z", "avg_line_length": 90.1165048544, "max_line_length": 318, "alphanum_fraction": 0.5087804353, "num_tokens": 6531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7434141003292206}}
{"text": "\n\\subsection{Tangent space and tangent vectors}\n\nTake a topological space: can all subsets in the toplogy be mapped to \\(n\\) dimensional space? if so, manifold\n\nFor this we need openness: a graph for example isn't open and so isn't a manifold\n\nWe also need the same number of dimensions at each point\n\nIsn't always the case. eg two circles conneceted by a line is not a manifold. it's 2d in circles, 1d on line (and 3d at connections)\n\nWe have a homeomorphism from each point in the toplogy to an n dimensional coordinate system\n\nWe also have homeomorphisms of transformation maps, between different points on the topology\n\nThe vector space from the homeomorphism is tangent to the manifold at that point. the set of all tangents forms a tangent space\n\nInterior: \\(M\\); boundry \\(\\delta M\\)\nTangent on a manifold:\n\nThe tangent space of manifold \\(M\\) at point \\(p\\) is denoted \\(TM_p\\).\n\nIf we have a normal field\n\n\\(v=v^ie_i\\)\n\nThen we can differentiate wrt a direction \\(x\\).\n\n\\(\\dfrac{\\delta }{\\delta x}v=\\dfrac{\\delta }{\\delta x}v^ie_i\\)\n\n\\(\\dfrac{\\delta }{\\delta x}v=e_i\\dfrac{\\delta v^i}{\\delta x}\\)\n\nBecause the basis does not change.\n\nIf the basis does change we instead have:\n\n\\(\\dfrac{\\delta }{\\delta x}v=\\dfrac{\\delta }{\\delta x}v^ie_i\\)\n\n\\(\\dfrac{\\delta }{\\delta x}v=e_i\\dfrac{\\delta v^i}{\\delta x}+v^i\\dfrac{\\delta e_i }{\\delta x}\\)\n\nGeneral point. basis can vary across manifold\n\nAfter this basis diff\n\n\\subsubsection{Tangent space as vector bundle}\n\n\\subsubsection{Christoffel symbols (page)}\n\nChristoffel symbols are connections.\n\n\\subsubsection{The torsion tensor (own page)}\n\nTorsion tensor is\n\n\\(T_{jk}^i=\\Gamma^i_{jk}-\\Gamma^i_{kj}\\)\n\n\nIf torsion is \\(0\\), then the connection is symmetric.\n\n\\subsubsection{Basis of tangent space}\n\nWe can use as the basis for tangent space:\n\n\\(\\{\\dfrac{(\\delta }{\\delta x^1})_p,(\\dfrac{\\delta }{\\delta x^2})_p,...\\}\\)\n\n\nThis means we can write a tangent vector as:\n\n\\(u=u^i(\\dfrac{\\delta }{\\delta x^i})_p\\)\n\n\\subsubsection{Basis of contant space}\n\nWe can use as the basis for the contangent space:\n\n\\(\\{dx^1,dx^2,...\\}\\)\n\n\\subsubsection{Metric on the tangent space (to Riemann)}\n\n\\subsubsection{Basis of metric (to Riemann)}\n\nThe metric depends on the basis too:\n\n\\(g_{ij}(p)=g((\\dfrac{\\delta }{\\delta x^i})_p,(\\dfrac{\\delta }{\\delta x^j})_p)\\)\n\nThe metric on two tangent vectors is defined on the components.\n\n\\(g=g_{ij}(p)u^iv^j\\)\n\n", "meta": {"hexsha": "f3ad1f4f587c909090202f1a568ca925a6a6ab4c", "size": 2388, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/manifoldsDifferentiable/02-01-tangent.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/manifoldsDifferentiable/02-01-tangent.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/manifoldsDifferentiable/02-01-tangent.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.8314606742, "max_line_length": 132, "alphanum_fraction": 0.7135678392, "num_tokens": 709, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359806, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7434140999595678}}
{"text": "\\section{Calculer (2 points)}\n\n\n\\begin{questions}\n\t\\question[1] $\\dfrac{1}{4} + \\dfrac{5}{2} - \\dfrac{3}{4} + 2$\n\t\\begin{solution}\n\t\t\\begin{eqnarray*}\n\t\t\t\\dfrac{1}{4} + \\dfrac{5}{2} - \\dfrac{3}{4} + 2 &=& \\dfrac{1}{4} + \\dfrac{5\\times 2}{2 \\times 2} - \\dfrac{3}{4} + \\dfrac{2 \\times 4}{1 \\times 4} \\\\\n\t\t\t\\dfrac{1}{4} + \\dfrac{5}{2} - \\dfrac{3}{4} + 2 &=& \\dfrac{1}{4} + \\dfrac{10}{4} - \\dfrac{3}{4} + \\dfrac{8}{4} \\\\\n\t\t\t\\dfrac{1}{4} + \\dfrac{5}{2} - \\dfrac{3}{4} + 2 &=& \\dfrac{1 + 10 - 3 + 8}{4} \\\\\n\t\t\t\\dfrac{1}{4} + \\dfrac{5}{2} - \\dfrac{3}{4} + 2 &=& \\dfrac{16}{4} \\\\\n\t\t\t\\dfrac{1}{4} + \\dfrac{5}{2} - \\dfrac{3}{4} + 2 &=& 4 \\\\\n\t\t\\end{eqnarray*}\n\t\\end{solution}\n\t\n\t\\question[1] $4 - \\dfrac{7}{3} - \\dfrac{3}{4} + \\dfrac{7}{12}$\n\t\\begin{solution}\n\t\t\\begin{eqnarray*}\n\t\t\t4 - \\dfrac{7}{3} - \\dfrac{3}{4} + \\dfrac{7}{12} &=& \\dfrac{4 \\times 12}{1 \\times 12} - \\dfrac{7\\times 4}{3 \\times 4} - \\dfrac{3 \\times 3}{4 \\times 3} + \\dfrac{7}{12} \\\\\n\t\t\t4 - \\dfrac{7}{3} - \\dfrac{3}{4} + \\dfrac{7}{12} &=& \\dfrac{48}{12} - \\dfrac{28}{12} - \\dfrac{9}{12} + \\dfrac{7}{12} \\\\\n\t\t\t4 - \\dfrac{7}{3} - \\dfrac{3}{4} + \\dfrac{7}{12} &=& \\dfrac{48 - 28 - 9 + 7}{12} \\\\\n\t\t\t4 - \\dfrac{7}{3} - \\dfrac{3}{4} + \\dfrac{7}{12} &=& \\dfrac{18}{12} \\\\\n\t\t\t4 - \\dfrac{7}{3} - \\dfrac{3}{4} + \\dfrac{7}{12} &=& \\dfrac{3}{2} \\\\\n\t\t\\end{eqnarray*}\n\t\\end{solution}\n\\end{questions}\n", "meta": {"hexsha": "b66ed435011c83c4425a06b5df5e2fa942c7d030", "size": 1342, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "college/5e/3_fractions/exam/footing.tex", "max_stars_repo_name": "malhys/maths_projects", "max_stars_repo_head_hexsha": "540337598037f7925fbf2f0e7232c4e18813c25b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "college/5e/3_fractions/exam/footing.tex", "max_issues_repo_name": "malhys/maths_projects", "max_issues_repo_head_hexsha": "540337598037f7925fbf2f0e7232c4e18813c25b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "college/5e/3_fractions/exam/footing.tex", "max_forks_repo_name": "malhys/maths_projects", "max_forks_repo_head_hexsha": "540337598037f7925fbf2f0e7232c4e18813c25b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.7037037037, "max_line_length": 171, "alphanum_fraction": 0.4940387481, "num_tokens": 727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567177, "lm_q2_score": 0.7931059414036511, "lm_q1q2_score": 0.7433074484002211}}
{"text": "\\chapter{Additional Proofs}\n\nIn this appendix we provide proofs of incidental statements made throughout this thesis.\nThese proofs are provided in the interest of completeness.\n\nIn the introduction, it was stated that the word problem for any finitely presented group is recursively enumerable.\nThis is a well-known fact which we prove as follows.\n\n\\begin{proposition}\\label{prop:appendix/wp-fp}\n\tFinitely presented groups have recursively enumerable word problems.\n\\end{proposition}\n\n\\begin{proof}\n\tLet $G$ be a group with presentation $\\left\\langle X \\mid R \\right\\rangle$ where $X$ and $R$ are both finite.\n\tWe then see that a word $w \\in X^*$ is in the word problem if and only if we have\n\t\\[\n\t\tw\n\t\t=_{F_X}\n\t\t\\prod_{i=0}^n  u_i r_i^{\\delta_i} u_i^{-1}\n\t\\]\n\tfor some $n \\in \\mathbb{N}$ where each $u_i \\in X^*$, $\\delta_j \\in \\{-1,1\\}$ and $r_i \\in R$.\n\tNotice here that `$=_{F_X}$' denotes that the left and right-hand sides are the same word after free-reduction is performed, that is, they are equivalent if viewed as elements of the free group.\n\t\n\tWe may then construct a Turing machine $M$ which takes a word $w \\in X^*$ as input, then iterates through the set of all finite products $\\prod_{i=0}^n  u_i r_i^{\\delta_i} u_i^{-1}$.\n\tAt each iteration, the machine should compare the word $w$ and the result of the product.\n\tThe machine then terminate and accepts only if the two words are equal.\n\t\n\tWe see that the machine $M$ accepts a word $w \\in X^*$ if and only if it lies within the word problem $\\WP_X$, that is, membership to the word problem $\\WP_X$ is \\emph{semi-decidable}.\n\t\n\tIt is well known that a problem is semi-decidable if and only if the set of all accepted words (in this case the word problem) is recursively enumerable.\n\tThis can be proven by constructing a machine which checks all words in parallel using a technique known as \\emph{dovetailing} (see Theorem 20.8 on p.~441 of \\cite{rich2007} for a proof of this fact).\n\\end{proof}\n\nIn \\cref{sec:linear-constraints} we gave an example of a linearly constrained language, and provided its generating function.\nIn the following we show that this generating function is holonomic by explicitly constructing a system of linear differential equations which it satisfies.\n\n\\begin{proposition}\\label{prop:appendix/holonomic-function}\n\tThe multivariate power series\n\t\\[\n\t\tf(x,y,z) =\n\t\t\\sum_{n \\in \\mathbb{N}}\n\t\t\\frac{(3n)!}{(n!)^3}\n\t\tx^n y^n z^n\n\t\\]\n\tsatisfies the differential equations\n\t\\begin{equation}\\label{eq:appendix/holonomic-differential-eq}\n\t\\left.\n\t\\begin{aligned}\n\t\t(x^2 - 27 x^3 y z) \\partial_x^2 f(x,y,z)\n\t\t+ (x - 54 x^2 y z) \\partial_x f(x,y,z)\n\t\t- 6 x y z \\, f(x,y,z)\n\t\t&= 0\n\t\t\\\\\n\t\t(y^2 - 27 x y^3 z) \\partial_y^2 f(x,y,z)\n\t\t+ (y - 54 x y^2 z) \\partial_y f(x,y,z)\n\t\t- 6 x y z \\, f(x,y,z)\n\t\t&= 0\n\t\t\\\\\n\t\t(z^2 - 27 x y z^3) \\partial_z^2 f(x,y,z)\n\t\t+ (z - 54 x y z^2) \\partial_z f(x,y,z)\n\t\t- 6 x y z \\, f(x,y,z)\n\t\t&= 0.\n\t\\end{aligned}\n\t\\right\\}\n\t\\end{equation}\n\tThus, $f(x,y,z)$ is holonomic.\n\\end{proposition}\n\n\\begin{proof}\n\tNotice that the system of differential equations in \\eqref{eq:appendix/holonomic-differential-eq} is equivalent to\n\t\\begin{equation}\\label{eq:appendix/holonomic-differential-eq2}\n\t\\left.\n\t\\begin{aligned}\n\t\tx^2 \\partial_x^2 f(x,y,z)\n\t\t+ x \\partial_x f(x,y,z)\n\t\t-27 x^2 \\partial_x^2 (x y z \\, f(x,y,z))\n\t\t- 6 x y z \\, f(x,y,z)\n\t\t&= 0\n\t\t\\\\\n\t\ty^2 \\partial_y^2 f(x,y,z)\n\t\t+ y \\partial_y f(x,y,z)\n\t\t-27 y^2 \\partial_y^2 (x y z \\, f(x,y,z))\n\t\t- 6 x y z \\, f(x,y,z)\n\t\t&= 0\n\t\t\\\\\n\t\tz^2 \\partial_z^2 f(x,y,z)\n\t\t+ z \\partial_z f(x,y,z)\n\t\t-27 z^2 \\partial_z^2 (x y z \\, f(x,y,z))\n\t\t- 6 x y z \\, f(x,y,z)\n\t\t&= 0.\n\t\\end{aligned}\n\t\\right\\}\n\t\\end{equation}\n\tThis can be shown using the \\emph{product rule} of differentiation.\n\t\n\tLet\n\t\\[\n\t\tf(x,y,z) =\n\t\t\\sum_{n \\in \\mathbb{N}}\n\t\t\\frac{(3n)!}{(n!)^3}\n\t\tx^n y^n z^n,\n\t\\]\n\tthen\n\t\\begin{align*}\n\t\t\tx \\partial_x f(x,y,z)\n\t\t\t&=\n\t\t\t\\sum_{n=1}^\\infty\n\t\t\t\\frac{(3n)!}{(n!)^3}\n\t\t\t\\,n\\,\n\t\t\tx^n y^n z^n,\n\t\t\\\\\n\t\t\tx^2 \\partial_x^2 f(x,y,z)\n\t\t\t&=\n\t\t\t\\sum_{n=1}^\\infty\n\t\t\t\\frac{(3n)!}{(n!)^3}\n\t\t\t\\,n(n-1)\\,\n\t\t\tx^n y^n z^n,\n\t\t\\\\\n\t\t\txyz \\, f(x,y,z)\n\t\t\t&=\n\t\t\t\\sum_{n=1}^\\infty\n\t\t\t\\frac{(3(n-1))!}{((n-1)!)^3}\n\t\t\t\\,\n\t\t\tx^n y^n z^n,\\text{ and}\n\t\t\\\\\n\t\t\tx^2 \\partial_x^2 (xyz \\, f(x,y,z))\n\t\t\t&=\n\t\t\t\\sum_{n=1}^\\infty\n\t\t\t\\frac{(3(n-1))!}{((n-1)!)^3}\n\t\t\t\\,n(n-1)\\,\n\t\t\tx^n y^n z^n.\n\t\\end{align*}\n\t\n\tWe then see that\n\t\\[\n\t\tx^2 \\partial_x^2 f(x,y,z)\n\t\t+ x \\partial_x f(x,y,z)\n\t\t-27 x^2 \\partial_x^2 (x y z \\, f(x,y,z))\n\t\t- 6 x y z \\, f(x,y,z)\n\t\t=\n\t\t\\sum_{n=1}^\\infty c_n x^n y^n z^n\n\t\\]\n\twhere each\n\t\\begin{align*}\n\t\tc_n\n\t\t&=\n\t\tn^2\n\t\t\\frac{(3n)!}{(n!)^3}\n\t\t-\n\t\t(27n^2 - 27n + 6)\n\t\t\\frac{(3(n-1))!}{((n-1)!)^3}\n\t\t\\\\\n\t\t&=\n\t\t\\frac{1}{n}\n\t\t\\left[\n\t\t\tn^3\n\t\t\t\\frac{(3n)!}{(n!)^3}\n\t\t\t-\n\t\t\t3n(3n-1)(3n-2)\n\t\t\t\\frac{(3(n-1))!}{((n-1)!)^3}\n\t\t\\right].\n\t\\end{align*}\n\tMoreover, we see that each $c_n = 0$ as\n\t\\[\n\t\t\\frac{(3n)!}{(n!)^3}\n\t\t=\n\t\t\\frac{3n(3n-1)(3n-2)}{n^3}\n\t\t\\cdot\n\t\t\\frac{(3(n-1))!}{((n-1)!)^3}.\n\t\\]\n\tThus, we have\n\t\\[\n\t\tx^2 \\partial_x^2 f(x,y,z)\n\t\t+ x \\partial_x f(x,y,z)\n\t\t-27 x^2 \\partial_x^2 (x y z \\, f(x,y,z))\n\t\t- 6 x y z \\, f(x,y,z)\n\t\t=\n\t\t0.\n\t\\]\n\tThe proofs of the other two differential equations in \\eqref{eq:appendix/holonomic-differential-eq2} are the same.\n\\end{proof}\n", "meta": {"hexsha": "07d74216770ed71b5a636cf09277a531e332dcbe", "size": 5192, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/A_Additional_Proofs.tex", "max_stars_repo_name": "alexbishop/phd-thesis", "max_stars_repo_head_hexsha": "06f7d5f3f5fa8e6bdb9aa48796223acd9ba4ae3d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter/A_Additional_Proofs.tex", "max_issues_repo_name": "alexbishop/phd-thesis", "max_issues_repo_head_hexsha": "06f7d5f3f5fa8e6bdb9aa48796223acd9ba4ae3d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter/A_Additional_Proofs.tex", "max_forks_repo_name": "alexbishop/phd-thesis", "max_forks_repo_head_hexsha": "06f7d5f3f5fa8e6bdb9aa48796223acd9ba4ae3d", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.5274725275, "max_line_length": 200, "alphanum_fraction": 0.6153697997, "num_tokens": 2095, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7433003326222228}}
{"text": "\n\\subsection{Power law}\n\n\\(P(X)=\\dfrac{\\alpha -1}{a}(\\dfrac{x}{a})^{-\\alpha }\\)\n\nWhere \\(a\\) is the lower bound.\n\n\\(P(X)=0\\) for \\(X<a\\).\n\n\\subsubsection{Moments of the power law}\n\n\\(E[X^m]=\\dfrac{\\alpha - 1}{\\alpha -1 -m }a\\)\n\nIf \\(m\\ge \\alpha -1 \\) then this is not well defined.\n\nHigher order moments, such that the variance, cannot be identified.\n\n", "meta": {"hexsha": "5b4f9def815e851f6f2e69503cd23ca26a63fddc", "size": 352, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/distributionsContinous/01-03-power.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/distributionsContinous/01-03-power.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/distributionsContinous/01-03-power.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.5555555556, "max_line_length": 67, "alphanum_fraction": 0.6193181818, "num_tokens": 121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475699138558, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7432929833667614}}
{"text": "\\section{First Order Unification}\n\n Unification is widely used in automated reasoning, logic programming\n and programming language type system implementation.\n\n\n\\subsection{First-order terms}\n\nGiven a set of \\textit{variable symbols} $X = \\{x,y,z,\\cdots \\}$ , a\nset of distinct \\textit{constant symbols} $ C = \\{ a,b,c,\\cdots \\}$ a\nset of distinct \\textit{function symbols} $F = \\{f,g,h, \\cdots\n\\}$. Term is defined as any expression that can be generated by a\nfinite number of applications of the following rules:\n\n\n\\begin{enumerate}\n\\item Basis: any variable , and also any constant  is a term\n\\item Induction: if $t_1, \\cdots, t_k$ are terms then $f(t_1,\\cdots,\n  t_k)$ is term for finite $k, 0 < k$.\n\\end{enumerate}\n\n\nFor brevity, the constant symbols are regarded as function symbols\ntaking zero arguments, the induction rule is relaxed to allow terms\nwith zero arguments , and $a()$ is regarded as syntactically equal to\n$a$ . Mathematicians fix the arity of a function symbol while\ntypically in syntactic unification problems, a function symbol may\nhave any number of arguments, and possibly may have different number\nof arguments in different arguments.\n\nFirst order unification is the syntactic unification of first-order\nterms, while higher order unification is the unification of\nhigher-order terms. First-order unification is especially widely used\nin logic programming, programming language type system design,\nespecially in type inferencing algorithms based on the Hindley-Milner\ntype system, and automated reasoning. Higher-order unification is also\nwidely used in proof assistants, for example Isabelle and Twelf, and\nrestricted forms of higher-order unification (higher-order pattern\nunification) are used in some programming language implementations,\nsuch as lambdaProlog, as higher-order patterns are expressive, yet\ntheir associated unification procedure retains theoretical properties\ncloser to first-order unification. Semantic unification is widely used\nin SMT solvers and term rewriting algorithms.\n\nIt is well known that if two terms have a unfier, they also have a\n\\textit{most general unifier}\n\\subsection{Substitution}\n\nA substitution is defined as a finite set of mappings from variables\nto terms where each mapping must be \\textit{unique}, because mapping\nthe same variable to two different terms would be ambiguous. A\nsubstitution may be applied to a term u and is written $u\\{ x_0\n\\rightarrow t_0, \\cdots, x_k \\rightarrow t_k \\}$, which means\n\\textit{simultaneously} replace every occurrence of each variable\n$x_i$ in the term $u$ with the term $t_i$ for $0 \\le i \\le k $. E.g.\n$f(x,a,g(z),y)\\{x \\rightarrow h(a,y), z \\rightarrow b \\} = f(h(a,y), a\n, g(b),y)$. A unifier U is called a \\textit{most general unifer} for\n$L$, if $\\forall$ $U'$ of $L$, $\\exists$ substitution $s$, $subst(U',L) =\nsubst(s, subst(U,L))$ .\n\n\\subsection{Unification in Various areas}\n\nUnification in Prolog\n\\begin{itemize}\n\\item A variable which is uninstantiated-i.e. no previous unifications\n  were performed on it-can be unified with an atom, a term, or another\n  uninstantiated variable, thus effectively becoming its alias. In\n  many modern Prolog dialects and in first-order logic, a variable\n  cannot be unified with a term that contains it; this is the so\n  called occurs check.\n\n\\item Two atoms can only be unified if they are identical.\n\n\n\\item Similarly, a term can be unified with another term if the top\n  function symbols and arities of the terms are identical and if the\n  parameters can be unified simultaneously. Note that this is a\n  recursive behavior.\n\n\\end{itemize}\nUnification in HM type inference \n\n\\begin{itemize}\n\\item Any type variable unifies with any type expression, and is\n  instantiated to that expression. A specific theory might restrict\n  this rule with an occurs check.\n\\item Two type constants unify only if they are the same type\n\\item Two type constructions unify only if they are applications of\n  the same type constructor and all of their component types\n  recursively unify.\n\\end{itemize}\n\nDue to its declarative nature, the order in a sequence of unifications\nis (usually) unimportant.\n\n\n\\subsection{Occurs check}\n\nIf there is ever an attempt to unify a variable $x$ with a term with a\nfunction symbol containing $x$ as a strict subterm $x=f(\\cdots,\nx,\\cdots)$, $x$ would have to be an infinite term, which contradicts\nthe strict definition of terms that requires a \\textit{finite} number\nof applications of the induction rule. e.g $x=f(x)$ does not represent\na strictly valid term.\n\n\\subsection{Unification Examples}\n\n\\begin{tabular}{|c|c|c|}\n\\hline\nProlog Notation & Unify Substitution & Explaination \\\\\n\\hline \n\nf(X)=f(Y) & X $\\rightarrow$ Y & X and Y are aliased \\\\\nf(g(X),X) = f(Y,a) & X $\\rightarrow$ a, Y $\\rightarrow$ g(a) & \\\\\nX = f(X) & should fail & enforced by \\textit{occurs check} \\\\\nX=Y,Y=a & X $\\rightarrow$ a , Y $\\rightarrow$ a & \\\\\n\\hline \n\\end{tabular}\n\n\\subsection{Algorithm}\nUnification algorithms can either perform occurs checks as soon as a\nvariable has to be unified with a non-variable term or postpone all\noccurs checks to the end. The first kind check is \\textit{inline} and\nthe second is called \\textit{post} occurs checks. The second performs well.\n\\begin{eqnarray}\nG \\cup  \\{t  \\sim t\\}  \\Rightarrow G \\\\\nG \\cup \\{ f(s_0, \\cdots ,s_k )  \\sim f(t_0, \\cdots, t_k)\\}  \\Rightarrow\nG \\cup \\{s_0 \\sim t_0, \\cdots, s_k \\sim t_k \\}\\\\\nG \\cup \\{f(s_0, \\cdots, s_k) \\sim g(t_0,\\cdots, t_m ) \\} \\Rightarrow\n\\perp if f \\neq g \\vee  k \\neq m\\\\\nG \\cup \\{ x \\sim t \\} \\Rightarrow\nG{x\\rightarrow t} \\cup {x \\sim t} if x \\in Vars(G) \\wedge x \\notin Vars(t) \\\\\nG \\cup \\{ x \\sim f(s_0, \\cdots, s_k) \\} \\Rightarrow \\perp if x \\in\nVars(f(s_0, \\cdots, s_k ) )\n\\end{eqnarray}\nThe set of variables in a term $t$ is written as $Vars(t)$, and the et\nof variables in all terms on \\verb|LHS| or \\verb|RHS| of potential\nequations in a problem \\verb|G| is written as \\verb|Vars(G)|. For\nbrevity, constant symbols are regarded as function symbols having zero\narguments.\n\nRobinson Algorithm\n\\begin{verbatim}\nFunction robOccursCheck(x,t,delta)\nINPUT:\n  Variable x, term t, substitution delta\nOUTPUT:\n  false or true\nBEGIN\n  let S be a stack, initially containing t\n  while (S is non-empty) do\n    t := pop(S);\n    foreach variable y in t do\n      if x = y then\n        return false\n      if y is bound in delta  then\n        push y <* delta onto S\n    od \n  od\n  return true\nEND\n\nFUNCTION ROB(s,t)\nINPUT:\n  Term s and t\nOUTPUT:\n  substitution or failure\nBEGIN\n  let S be an empty stack of pairs of terms, initially containing\n(s,t)\n  let delta be the empty substitution\n  while (S is non-empty) do\n     (s,t) := pop (S);\n     while (s is a variable bound by delta) s := s <* delta\n     while (t is a variable bound by detal) t := t <* delta\n     if s <> t then\n       case(s,t) of\n         (x,y) => add x -> y to delta\n         (x,u) =>\n               if robOccursCheck(x,u,delta)\n               then\n                 add x -> u to delta\n                 apply x -> u to each term in delta \n               else failure\n         (u,x) =>\n               if robOccursCheck(x,u,delta)\n               then\n                 add x -> u to delta\n                 apply x -> u to each term in data\n               else failure\n\n         (f(s1,..,sn),f(t1,...,tn)) =>\n               push (s1,t1), ... , (sn,tn) onto S\n      end     \n  od\n  return delta\nEND\n\\end{verbatim}\n  ", "meta": {"hexsha": "92d650720fb1d6493acf6c920b8b94e995bb877a", "size": 7411, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "example/unification.tex", "max_stars_repo_name": "mgttlinger/ocaml-book", "max_stars_repo_head_hexsha": "09a575b0d1fedfce565ecb9a0ae9cf0df37fdc75", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 142, "max_stars_repo_stars_event_min_datetime": "2015-01-12T16:45:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-15T00:47:37.000Z", "max_issues_repo_path": "example/unification.tex", "max_issues_repo_name": "mgttlinger/ocaml-book", "max_issues_repo_head_hexsha": "09a575b0d1fedfce565ecb9a0ae9cf0df37fdc75", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-10-09T13:53:43.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-03T04:15:48.000Z", "max_forks_repo_path": "example/unification.tex", "max_forks_repo_name": "mgttlinger/ocaml-book", "max_forks_repo_head_hexsha": "09a575b0d1fedfce565ecb9a0ae9cf0df37fdc75", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2015-02-10T18:12:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-21T06:57:32.000Z", "avg_line_length": 37.2412060302, "max_line_length": 77, "alphanum_fraction": 0.7069221428, "num_tokens": 2029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.7431988002685054}}
{"text": "\\chapter{Naive Set Theory}\nThe concept of \\href{https://en.wikipedia.org/wiki/set_theory}{set theory} has arisen towards the end of the 19th century\nfrom an effort to put mathematics on a solid foundation.  The creation of a solid foundation was considered necessary as\nthe concept of infinity increasingly worried mathematicians. \n\nThe essential parts of set theory have been defined by \\href{https://de.wikipedia.org/wiki/Georg_Cantor}{Georg\n  Cantor} (1845 -- 1918). The first definition of the concept of a set was approximately as follows\n\\cite{cantor:1895}: \n\n\\begin{center}\n\\colorbox{red}{\\framebox{\\colorbox{yellow}{\n\\begin{minipage}{0.85\\linewidth}\n  A ``set'' is a \\blue{well-defined} collection $M$ of certain objects $x$ of our perception or our thinking.\n\\end{minipage}}}}\n\\end{center}\n\\vspace*{0.2cm}\n\n\\noindent\nHere, the attribute ``\\blue{well-defined}'' expresses the fact that for a given quantity $M$ and an object $x$ we have\nto be able to decide whether the object $x$ belongs to the set $M$.  If $x$ belongs to $M$, then $x$ is called an\n\\blue{element} of the set $M$ and we write this as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$x \\in M$. \n\\\\[0.2cm]\nThe symbol ``$\\in$'' is therefore used in set theory as a binary predicate symbol.  We use infix notation when\nusing this symbol, that is we write $x \\in M$ instead of ${\\in}(x, M)$.  \nSlightly abbreviated we can define the notion of a set as follows: \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\textsl{A set is a \\blue{well-defined} collection of elements}.\n\\\\[0.2cm]\nTo mathematically understand the concept of a \\blue{well-defined collection of elements},\nCantor introduced the so-called \\blue{axiom of comprehension}.\nWe can formalize this axiom as follows:  If $p(x)$ a \\blue{property} that\nan object $x$ can have, we can define the set $M$ of all objects that have this\nproperty.  Therefore, the set $M$ can be defined as \n\\\\[0.2cm]\n\\hspace*{1.3cm} \n$M := \\{ x \\;|\\; p(x) \\}$ \n\\\\[0.2cm]\nand we read this definition as ``$M$ is the set of all $x$ such that $p(x)$ holds''.\nHere, a property $p(x)$ is just a formula in which the variable $x$ happens to appear.\nWe illustrate the axiom of comprehension by an example: If $\\mathbb{N}$ is\nthe set of natural numbers, then we can define the set of all even numbers\nvia the property \\\\[0.2cm]\n\\hspace*{1.3cm} $p(x) \\;:=\\; (\\exists y\\in \\mathbb{N}: x = 2 \\cdot y)$. \\\\[0.2cm]\nUsing this property, the set of even numbers can be defined as \\\\[0.2cm]\n\\hspace*{1.3cm} $\\{ x \\;|\\; \\exists y\\in \\mathbb{N}: x = 2 \\cdot y \\}$. \n\nUnfortunately, the unrestricted use of the axiom of comprehension leads to serious problems.  To give an\nexample, let us consider the property of a set to \\underline{not} contain itself.  Therefore, we define  \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n $p(x) := \\neg(x \\in x)$ \n\\\\[0.2cm]\nand further define the set $R$ as follows: \n\\\\[0.2cm]\n\\hspace*{1.3cm} \n$R := \\{ x \\;|\\; \\neg (x \\in x) \\}$.  \n\\\\[0.2cm]\nIntuitively, we might expect that no set can contain itself.  However, things turn out to be more complicated.\nLet us try to check whether the set $R$ contains itself.  We have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\n\\begin{array}{cl}\n                  & R \\in R \\\\[0.2cm] \n  \\Leftrightarrow & R \\in \\bigl\\{ x \\;|\\; \\neg (x \\in x) \\bigr\\} \\\\[0.2cm] \n  \\Leftrightarrow & \\neg (R \\in R).\n\\end{array}\n$\n\\\\[0.2cm]\nSo we have shown that\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$R \\in R \\;\\Leftrightarrow\\; \\neg(R \\in R)$\n\\\\[0.2cm]\nholds.  Obviously, this is a contradiction.  As a way out, we can only conclude that the expression \\\\[0.2cm]\n\\hspace*{1.3cm} $\\{ x \\mid \\neg (x \\in x) \\}$ \\\\[0.2cm]\ndoes not define a set.  This shows that the axiom of comprehension is too general:  Not every expression of the form \n\\\\[0.2cm] \n\\hspace*{1.3cm}\n$M := \\{ x \\mid p(x) \\}$ \n\\\\[0.2cm]\ndefines a set.  The expression\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\bigl\\{x \\mid \\neg(x \\in x)\\bigr\\}$\n\\\\[0.2cm]\nhas been found by the British logician and philosopher \n\\href{http://de.wikipedia.org/wiki/Bertrand_Russell}{Bertrand Russell} (1872 -- 1970).  It is known as\n\\href{http://de.wikipedia.org/wiki/Russellsche_Antinomy}{Russell's Antinomy}. \n\nIn order to avoid paradoxes such as Russell's antinomy, it is necessary to be more careful when sets are\nconstructed.  In the following, we will present methods to construct sets that are weaker than the \naxiom of comprehension, but, nevertheless, these methods will be sufficient for our purposes.  We will use the\nnotation underlying the comprehension axiom and write set definitions in the form\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$M = \\{ x \\mid p(x) \\}$.  \n\\\\[0.2cm]\nHowever, we won't be allowed to use arbitrary formulas $p(x)$ here.  Instead, the formulas we are going to use\nfor $p(x)$ have to satisfy some restrictions.  These restrictions will prevent the construction of\nself-contradictory sets.\n\n\\section{Defining Sets by Listing their Elements}\nThe simplest way to define a set is to list of all of its elements. These elements are enclosed in the\ncurly braces  ``\\texttt{\\{}'' and ``\\texttt{\\}}'' and are separated by commas.\nFor example, when we define \\\\[0.2cm]\n\\hspace*{1.3cm} $M := \\{ 1, 2, 3 \\}$, \\\\[0.2cm]\nthen the set $M$ contains the elements $1$, $2$ and $3$.\nUsing  the notation of the axiom of comprehension we could write this set as \\\\[0.2cm]\n\\hspace*{1.3cm} \n$M = \\{ x \\mid x = 1 \\vee x = 2 \\vee x = 3 \\}$.\n\\\\[0.2cm]\nAnother example of a set that can be created by explicitly enumerating its elements\nis the set of all lower case Latin letters.  This set is given as\ndefine: \\\\[0.2cm]\n\\hspace*{1.3cm} \n$\\{\\mathtt{a}, \\mathtt{b}, \\mathtt{c}, \\mathtt{d}, \\mathtt{e},\n \\mathtt{f}, \\mathtt{g}, \\mathtt{h}, \\mathtt{i}, \\mathtt{j}, \\mathtt{k}, \\mathtt{l},\n \\mathtt{m}, \\mathtt{n}, \\mathtt{o}, \\mathtt{p}, \\mathtt{q}, \\mathtt{r}, \\mathtt{s},\n \\mathtt{t}, \\mathtt{u}, \\mathtt{v}, \\mathtt{w}, \\mathtt{x}, \\mathtt{y}, \\mathtt{z}\\}$.\n \\\\[0.2cm]\nOccasionally, we will use \\blue{dot notation} to define a set.  Using dot notation, the set of all lower case\nelements is written as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\{ \\mathtt{a}, \\mathtt{b}, \\mathtt{c}, \\cdots, \\mathtt{x}, \\mathtt{y}, \\mathtt{z}\\} $.\n\\\\[0.2cm]\nOf course, if we use dot notation the interpretation of the dots ``$\\cdots$'' must always be obvious from the\ncontext of the definition. \n\nAs a last example, we consider the \\blue{empty set} $\\emptyset$, which is defined as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\emptyset := \\{\\}$.\n\\\\[0.2cm]\nTherefore, the empty set does not contain any element at all.  This set plays an important role in set theory.  This\nrole is similar to the role played by the number $0$ in algebra.\n\nIf a set is defined by listing all of its elements, the order in which the\nelements are listed is not important.  For example, we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\{1,2,3\\} = \\{3,1,2\\}$,\n\\\\[0.2cm]\nsince both sets contain the same elements.\n\n\n\\section{Predefined Infinite Sets of Numbers}\nAll sets that are defined by explicitly listing their elements can only have finitely many elements.  \nIn mathematics there are a number of sets that have an \\blue{infinite} number of\nelements.  One example is the \n\\href{http://en.wikipedia.org/wiki/Natural_number}{set of natural numbers}, which is usually denoted by the symbol $\\mathbb{N}$.\nUnlike some other authors, I regard the number zero as a natural number.  This is consistent with the\n\\href{https://en.wikipedia.org/wiki/ISO_31-11}{\\textsc{Iso}-standard 31-11}.\\footnote{\n  The \\textsc{Iso} standard 31-11 has been replaced by the\n  \\href{https://en.wikipedia.org/wiki/ISO_80000-2}{\\textsc{Iso}-standard 80000-2},\n  but the definition of the set $\\mathbb{N}$ has not changed.  In the text, I did not cite \\textsc{Iso} 80000-2 because \n  the content of this standard is not freely available, at least not legally.\n}\nGiven the concepts discussed so far, the quantity $\\mathbb{N}$ cannot be defined.\nWe must therefore demand the existence of this set as an \\blue{axiom}.  More precisely, we postulate that there is a\nset $\\mathbb{N}$ which has the following three properties:\n\\begin{enumerate}\n\\item $0 \\in \\mathbb{N}$.\n\\item If we have a number $n$ such that $n \\in \\mathbb{N}$, then we also have $n+1 \\in \\mathbb{N}$.\n\\item The set $\\mathbb{N}$ is the smallest set satisfying the first two conditions.\n\\end{enumerate}\nWe write \\\\[0.2cm]\n\\hspace*{1.3cm} $\\mathbb{N} := \\{ 0, 1, 2, 3, \\cdots \\}$. \\\\[0.2cm]\nAlong with the set $\\mathbb{N}$ of natural numbers we will use the following sets of numbers: \n\\begin{enumerate}\n\\item $\\mathbb{N}^*$ is the set of \\blue{positive natural numbers}, so we have\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $\\mathbb{N}^* := \\{ n \\mid n \\in \\mathbb{N} \\wedge n > 0 \\}$.\n\\item $\\mathbb{Z}$ is the set of \\blue{integers}, we have\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $\\mathbb{Z} \\ = \\{ 0, 1, -1, 2, -2, 3, -3, \\cdots \\}$ \n\n\\item $\\mathbb{Q}$ is the set of \\blue{rational numbers}, we have\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $\\Bigl\\{ \\ds\\frac{p}{q} \\Bigm| p \\in \\mathbb{Z} \\wedge q \\in \\mathbb{N}^* \\Bigr\\}$.\n\\item $\\mathbb{R}$ is the set of \\blue{real numbers}.\n\n      A clean  mathematically definition of the notion of a \\href{https://de.wikipedia.org/wiki/Reelle_number}{real number}\n      requires a lot of effort and is out of the scope of this lecture.  If you are interested, a detailed\n      description of the construction of real numbers is given in my lecture notes on \n      \\href{https://github.com/karlstroetmann/Analysis/blob/master/Skript/analysis.pdf}{Analysis}.\n\\end{enumerate}\n\n\\section{The Axiom of Specification}\nThe \\blue{axiom of specification}, also known as the \n\\href{https://en.wikipedia.org/wiki/Axiom_schema_of_specification}{axiom of restricted comprehension},\nis a weakening of the comprehension axiom.  The idea behind the axiom of specification\nis to use a property $p$ \\blue{to select from an existing set $M$ a subset $N$ of those elements\nthat have the property $p(x)$}: \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$N := \\{ x\\in M \\;|\\; p(x) \\}$ \n\\\\[0.2cm]\nIn the notation of the axiom of comprehension this set is written as \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$N := \\{ x \\mid x \\in M \\wedge p(x) \\}$. \n\\\\[0.2cm]\nThis is a \\blue{restricted} form of the axiom of comprehension, because the condition ``$p(x)$'' that was used in the\naxiom of comprehension is now strengthened to the condition ``$x \\in M \\wedge p(x)$''.\n\n\n\\exampleEng\nUsing the axiom of restricted comprehension, the set of even numbers can be defined as \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n $\\{ x \\in \\mathbb{N} \\;|\\; \\exists y\\in \\mathbb{N}: x = 2 \\cdot y \\}$. \n\n\n\\section{Power Sets}\nIn order to introduce the notion of a \\blue{power set} we first have to define the notion of a \\blue{subset}.\nIf $M$ and $N$ are sets, then $M$ is a \\blue{subset} of $N$ if and only if each element of the\nset $M$ is also an element of the set $N$.  In that case, we write $M \\subseteq N$.  Formally, we define\n \\\\[0.2cm]\n\\hspace*{1.3cm}\n$M \\subseteq N \\;\\stackrel{\\mathrm{def}}{\\Longleftrightarrow}\\; \\forall x: (x \\in M \\rightarrow x \\in N)$.\n\n\\exampleEng\nWe have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\{ 1, 3, 5\\} \\subseteq \\{ 1, 2, 3, 4, 5 \\}$.\n\\\\[0.2cm]\nFurthermore, for any set $M$ we have that\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\emptyset \\subseteq M$. \\eox\n\\vspace*{0.2cm}\n\nThe  \\blue{power set} of a set $M$ is now defined as the set of all subsets\nof $M$.  We write $2^M$ for the power set of $M$.  Therefore we have\n\\\\[0.2cm] \n\\hspace*{1.3cm}\n$2^M := \\{ x \\;|\\; x \\subseteq M \\}$.\n\n\\exampleEng\nLet us compute the power set of the set $\\{1,2,3\\}$.  We have \\\\[0.2cm]\n\\hspace*{1.3cm}\n $2^{\\{1,2,3\\}} = \\bigl\\{ \\{\\},\\, \\{1\\}, \\, \\{2\\},\\, \\{3\\},\\, \\{1,2\\}, \\, \\{1,3\\}, \\{2,3\\},\\, \\, \\{2,3\\},\\,\\{1,2,3\\}\\bigr\\}$. \n\\\\[0.2cm]\nThis set has $8 = 2^3$ elements.  \n\\eox\n\nIn general, if the set $M$ has $m$ different elements, then it can be shown\nthat the power set $2^M$ has $2^m$ different elements.\nMore formally, let us designate the number of elements of a finite set $M$ as \n$\\textsl{card}(M)$.  Then we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\textsl{card}\\left(2^M\\right) = 2^{\\textsl{\\scriptsize card}(M)}$.\n\\\\[0.2cm]\nThis explains the notation $2^M$ to denote the power set of $M$.  \n\n\\section{The Union of Sets}\nIf two sets $M$ and $N$ are given, the union\nof $M$ and $N$ is the set of all elements that are either in the set $M$ or in the set $N$ or in both $M$ and\nin $N$.  This set is written as $M \\cup N$.\nFormally, this set is defined as \n\\\\[0.2cm]\n\\hspace*{1.3cm} $M \\cup N := \\{ x \\;|\\; x \\in M \\vee x \\in N \\}$. \n\n\\exampleEng\nIf $M = \\{1,2,3\\}$ and $N = \\{2,5\\}$, we have \n\\\\[0.2cm]\n\\hspace*{1.3cm} \n$\\{1,2,3\\} \\cup \\{2,5\\} = \\{1,2,3,5\\}$.  \\eox\n\\vspace*{0.2cm}\n\nThe concept of the union of two sets can be generalized.  Consider\na set $X$ such that the elements of $X$ are sets themselves. For example, the\n\\blue{power set} of a set $M$ is a set whose elements are sets themselves.  We can form the union of all the \nsets that are elements of the set $X$.  We write this set as $\\bigcup X$.  Formally,\nwe have\n\\\\[0.2cm]\n\\hspace*{1.3cm} $\\bigcup X := \\{ y \\;|\\; \\exists x \\in X: y \\in x \\}$.\n\n\\exampleEng\nIf we have \\\\[0.2cm]\n\\hspace*{1.3cm}\n $X = \\big\\{\\, \\{\\},\\, \\{1,2\\}, \\, \\{1,3,5\\}, \\, \\{7,4\\}\\,\\big\\}$, \\\\[0.2cm]\nthen \\\\[0.2cm] \n\\hspace*{1.3cm}\n $\\bigcup X = \\{ 1, 2, 3, 4, 5, 7 \\}$. \\eox\n\\vspace*{0.2cm}\n\n\\exerciseEng\nAssume that $M$ is a subset of $\\mathbb{N}$.  Compute the set $\\bigcup 2^M$.\n\\eox\n\n\\section{The Intersection of Sets}\nIf two sets $M$ and $N$ are given, we define the \\blue{intersection} of $M$ and $N$ as a set of all objects that are\nelements of both $M$ and  $N$.  We write that set as the average $M \\cap N$.\nFormally, we define \n\\\\[0.2cm]\n\\hspace*{1.3cm} $M \\cap N := \\{ x \\mid x \\in M \\wedge x \\in N \\}$.\n\n\\exampleEng\nWe calculate the intersection of the sets $M = \\{ 1, 3, 5 \\}$ and $N = \\{ 2, 3, 5, 6 \\}$.  We have\n\\\\[0.2cm]\n\\hspace*{1.3cm} $M \\cap N = \\{ 3, 5 \\}$.\n\\eox\n\\vspace*{0.2cm}\n\nThe concept of the intersection of two sets can be generalized.  Consider\na set $X$ such that the elements of $X$ are sets themselves. \nWe can form the intersection of all the \nsets that are elements of the set $X$.  We write this set as $\\bigcap X$.  Formally,\nwe have\n\\\\[0.2cm]\n\\hspace*{1.3cm} \n$\\bigcap X := \\{ y \\;|\\; \\forall x \\in X: y \\in x \\}$.\n\\vspace*{0.2cm}\n\n\\exerciseEng\nAssume that $M$ is a subset of $\\mathbb{N}$.  Compute the set $\\bigcap 2^M$.\n\\eox\n\n\\section{The Difference of Sets}\nIf $M$ and $N$ are sets, we define the \\blue{difference}\nof $M$ and $N$ as the set of all objects from $M$ that are not elements of $N$.  The difference of the sets $M$\nand $N$ is written as $M\\backslash N$ and is formally defined as\n \\\\[0.2cm]\n\\hspace*{1.3cm} $M \\backslash N := \\{ x \\mid x \\in M \\wedge x \\not\\in N \\}$.\n\n\\exampleEng\nWe compute the difference of the sets $M = \\{ 1, 3, 5, 7 \\}$ and $N = \\{ 2, 3, 5, 6 \\}$.  We have\n\\\\[0.2cm]\n\\hspace*{1.3cm} $M \\backslash N = \\{ 1, 7 \\}$. \\eox\n\n\\section{Image Sets}\nIf $M$ is a set and $f$ is a function defined for all $x$ of $M$, then the \\blue{image of $M$ under $f$}\nis defined as follows:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$f(M) := \\{ y \\;|\\; \\exists x \\in M: y = f(x) \\}$. \n\\\\[0.2cm]\nThis set is also written as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$f(M) := \\bigl\\{ f(x) \\;|\\; x \\in M \\}$. \n\n\\exampleEng\nThe set $Q$ of all square numbers can be defined as \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$Q := \\{ y \\mid \\exists x \\in \\mathbb{N}: y = x^2\\}$.\n\\\\[0.2cm]\nAlternatively, we can define this set as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$Q := \\bigl\\{ x^2 \\mid x \\in \\mathbb{N} \\bigr\\}$.\n\\eox\n\n\\section{Cartesian Products}\nIn order to be able to present the notion of a \\href{https://en.wikipedia.org/wiki/Cartesian_product}{Cartesian product},\nwe first have to introduce the notion of an \\href{https://en.wikipedia.org/wiki/Ordered_pair}{ordered pair} of two objects\n$x$ and $y$.  The \\blue{ordered pair} of $x$ and $y$ is written as\n\\\\[0.2cm] \n\\hspace*{1.3cm}\n$\\langle x, y \\rangle$.\n\\\\[0.2cm]\nIn the literature, the ordered pair of $x$ and $y$ is sometimes written as $(x,y)$, but I prefer the notation\nwith angle brackets.  The  \\blue{first component} of the pair $\\langle x, y \\rangle$ is $x$, while $y$ is\n\\blue{the second component}.  Two  ordered pairs $\\langle x_1, y_1 \\rangle$ and $\\langle x_2, y_2 \\rangle$ are\nequal if and only if they have the same first and second component, i.e.~we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\langle x_1, y_1 \\rangle \\,=\\,\\langle x_2, y_2 \\rangle  \\;\\Leftrightarrow\\; x_1 = x_2 \\wedge y_1 = y_2$. \n\\\\[0.2cm]\nThe \\blue{Cartesian product} of two sets $M$ and $N$ is now defined as the set of all ordered pairs such\nthat the first component is an element of  $M$ and the second component is an element of $N$.\nFormally, we define the cartesian product $M \\times N$ of the sets $M$ and $N$ as follows:  \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$M \\times N := \\big\\{ z \\mid \\exists x\\colon \\exists y\\colon\\bigl(z = \\langle x,y\\rangle \\wedge x\\in M \\wedge y \\in N\\bigr) \\bigr\\}$. \n\\\\[0.2cm]\nTo be more concise we usually write this as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$M \\times N := \\big\\{ \\langle x,y\\rangle \\mid  x\\in M \\wedge y \\in N \\}$.\n\n\\exampleEng\nIf $M = \\{ 1, 2, 3 \\}$ and $N = \\{ 5, 7 \\}$ we have\n\\\\[0.2cm]\n\\hspace*{1.3cm} \n$M \\times N = \\bigl\\{ \\pair(1,5),\\pair(2,5),\\pair(3,5),\\pair(1,7),\\pair(2,7),\\pair(3,7)\\bigr\\}$.\n\\eox\n\\vspace*{0.2cm}\n\n\\noindent\nThe notion of an ordered pair can be generalized to the notion of an\n\\blue{$n$-tuple} where $n$ is a natural number: An $n$-tuple has the form\n\\\\[0.2cm]\n\\hspace*{1.3cm} $\\langle x_1, x_2, \\cdots, x_n \\rangle$. \n\\\\[0.2cm]\nIn a similar way, we can generalize the notion of a Cartesian product of two sets to the Cartesian product of\n$n$ sets.  The \\blue{general Cartesian product} of $n$ sets  $M_1$, $\\cdots$, $M_n$ is defined as follows: \\\\[0.2cm]\n\\hspace*{1.3cm}\n$M_1 \\times \\cdots \\times M_n =\n  \\big\\{ \\langle x_1,x_2,\\cdots,x_n \\rangle \\bigm| x_1\\in M_1 \\wedge \\cdots \\wedge x_n \\in M_n \\big\\}\n$. \n\\\\[0.2cm]\nSometimes,  $n$-tuples are called lists.  In this case they are written with the square brackets ``\\texttt{[}''\nand ``\\texttt{]}'' instead of the angle brackets ``$\\langle$'' and ``$\\rangle$'' that we are using.  \n\n\\exerciseEng\nAssume that $M$ and $N$ are finite sets.  How can the expression $\\textsl{card}(M \\times N)$ be reduced to an\nexpression containing the expressions $\\textsl{card}(M)$ and $\\textsl{card}(N)$?\n\\eox\n\n\\section{Equality of Sets}\nWe have now presented all the methods that we will use in this lecture in order to construct sets.\nNext, we discuss the notion of \\blue{equality} of two sets.  As a set is solely defined by its members,\nthe question of the equality of two sets is governed by the \n\\href{https://en.wikipedia.org/wiki/Axiom_of_extensionality}{axiom of extensionality}:\n\\vspace*{0.2cm}\n\n\\begin{center}     \n\\colorbox{red}{\\framebox{\\colorbox{yellow}{ \n\\begin{minipage}{0.57\\linewidth}\n{\\sl Two sets are equal if and only if they have the same elements. }  \n\\end{minipage}}}}\n\\end{center}\n\\vspace{0.2cm}\n\n\\noindent\nMathematically, we can capture the axiom of extensionality through the formula\n\\\\[0.2cm]\n\\hspace*{1.3cm} $M = N \\;\\leftrightarrow\\; \\forall x: (x \\in M \\leftrightarrow x \\in N)$ \n\\\\[0.2cm]\nAn important consequence of this axiom is the fact that the order in which the\nelements are listed in a set does not matter.  For example, we have \n\\\\[0.2cm] \n\\hspace*{1.3cm} $\\{1,2,3\\} = \\{3,2,1\\}$, \n\\\\[0.2cm]\nbecause both sets contain the same elements.  Similarly, we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\{1,2,2,3\\} = \\{1,1,2,3,3\\}$,\n\\\\[0.2cm]\nbecause both these sets contain the elements $1$, $2$, and $3$.  It does not matter how often we list these\nelements when defining a set:  An object $x$ either is or is not an element of a given set $M$.  It does not\nmake sense to say something like ``$M$ contains the object $x$ $n$ times''.\\footnote{In the literature, you will find\nthe concept of a \\href{https://en.wikipedia.org/wiki/Multiset}{multiset}.  A \\blue{multiset} does not abstract\nfrom the number of occurrences of its elements.  In this lecture, we will not use multisets.}\n\nIf two sets are defined by explicitly enumerating their elements, the question whether\nthese sets are equal is trivial to decide.  However, if a set is defined using the axiom of specification, then\nit can be very difficult to decide whether this set is equal to another set.  For \nexample, it has been shown that \\\\[0.2cm]\n\\hspace*{1.3cm} \n$\\{ n \\in \\mathbb{N}^* \\mid \\exists x, y, z\\in\\mathbb{N}^*: x^n + y^n = z^n \\} = \\{1, 2\\}$. \n\\\\[0.2cm]\nHowever, the proof of this equation is very difficult because this equation\nis equivalent to \\href{https://en.wikipedia.org/wiki/Fermat%27s_Last_Theorem}{Fermat's conjecture}. \nThis conjecture was formulated in 1637 by \\href{https://de.wikipedia.org/wiki/Pierre_de_Fermat}{Pierre de Fermat}.  \nIt took mathematicians more than three centuries to come up with a rigorous proof that validates this conjecture:\nIn 1994 \\href{https://de.wikipedia.org/wiki/Andrew_Wiles}{Andrew Wiles}\nand \\href{https://de.wikipedia.org/wiki/Richard_Taylor_(Mathematician)}{Richard Taylor} were able to do this.\nThere are some similar conjectures concerning the equality of sets that are still open mathematical problems. \n\n\n\\section{Chapter Review}\n\\begin{enumerate}\n\\item What is a set?\n\\item How is the axiom of comprehension defined?  Why can't we use this axiom to define sets?\n\\item What is the axiom of restricted comprehension?\n\\item Lists all the methods that have been introduced to define sets.\n\\item What is the axiom of extensionality?\n\\end{enumerate}\nIf you want to develop a deeper understand of set theory, I can highly recommend the book\n\\emph{Set Theory and Related Topics} by Seymour Lipschutz \\cite{lipschutz:1998}.\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"logic\"\n%%% End: \n", "meta": {"hexsha": "625184044e4b240948b9ea087ffae3ccd8b920b3", "size": 21677, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-Notes-Python/sets.tex", "max_stars_repo_name": "AbdalrohmanGitHub/Logik", "max_stars_repo_head_hexsha": "62270c224061f38b637cb6920a0fbe5a56495bb9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture-Notes-Python/sets.tex", "max_issues_repo_name": "AbdalrohmanGitHub/Logik", "max_issues_repo_head_hexsha": "62270c224061f38b637cb6920a0fbe5a56495bb9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture-Notes-Python/sets.tex", "max_forks_repo_name": "AbdalrohmanGitHub/Logik", "max_forks_repo_head_hexsha": "62270c224061f38b637cb6920a0fbe5a56495bb9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.1486761711, "max_line_length": 134, "alphanum_fraction": 0.6740323846, "num_tokens": 7557, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.8723473680407889, "lm_q1q2_score": 0.7431987812129264}}
{"text": "% Written by Anders Sjoqvist and Ulf Lundstrom, 2009\n% The main sources are: tinyKACTL, Beta and Wikipedia\n\n\\chapter{Mathematics}\n\n\\section{Equations}\n\n\\[\\begin{aligned}ax+by=e\\\\cx+dy=f\\end{aligned}\n\\Rightarrow\n\\begin{aligned}x=\\dfrac{ed-bf}{ad-bc}\\\\y=\\dfrac{af-ec}{ad-bc}\\end{aligned}\\]\n\nIn general, given an equation $Ax = b$, the solution to a variable $x_i$ is given by\n\\[x_i = \\frac{\\det A_i'}{\\det A} \\]\nwhere $A_i'$ is $A$ with the $i$'th column replaced by $b$.\n\n% \\section{Recurrences}\n% If $a_n = c_1 a_{n-1} + \\dots + c_k a_{n-k}$, and $r_1, \\dots, r_k$ are distinct roots of $x^k + c_1 x^{k-1} + \\dots + c_k$, there are $d_1, \\dots, d_k$ s.t.\n% \\[a_n = d_1r_1^n + \\dots + d_kr_k^n. \\]\n% Non-distinct roots $r$ become polynomial factors, e.g. $a_n = (d_1n + d_2)r^n$.\n\n\\section{Trigonometry}\n\\begin{align*}\n\\sin(v+w)&{}=\\sin v\\cos w+\\cos v\\sin w\\\\\n\\cos(v+w)&{}=\\cos v\\cos w-\\sin v\\sin w\\\\\n\\tan(v+w)&{}=\\dfrac{\\tan v+\\tan w}{1-\\tan v\\tan w}\\\\\n\\sin v+\\sin w&{}=2\\sin\\dfrac{v+w}{2}\\cos\\dfrac{v-w}{2}\\\\\n\\cos v+\\cos w&{}=2\\cos\\dfrac{v+w}{2}\\cos\\dfrac{v-w}{2}\n\\end{align*}\n\\begin{align*}\n\ta\\cos x+b\\sin x&=r\\cos(x-\\phi)\\\\\n\ta\\sin x+b\\cos x&=r\\sin(x+\\phi)\n\\end{align*}\nwhere $r=\\sqrt{a^2+b^2}, \\phi=\\operatorname{atan2}(b,a)$.\n\n\\section{Geometry}\n\n\\subsection{Triangles}\nSide lengths: $a,b,c$\\\\\nSemiperimeter: $s=\\dfrac{a+b+c}{2}$\\\\\nArea: $A=\\sqrt{s(s-a)(s-b)(s-c)}$\\\\\nCircumradius: $R=\\dfrac{abc}{4A}$\\\\\nInradius: $r=\\dfrac{A}{p}$\\\\\nLength of median (divides triangle into two equal-area triangles): $m_a=\\tfrac{1}{2}\\sqrt{2b^2+2c^2-a^2}$\\\\\nLength of bisector (divides angles in two): $s_a=\\sqrt{bc\\left[1-\\left(\\dfrac{a}{b+c}\\right)^2\\right]}$\\\\\nLaw of sines: $\\dfrac{\\sin\\alpha}{a}=\\dfrac{\\sin\\beta}{b}=\\dfrac{\\sin\\gamma}{c}=\\dfrac{1}{2R}$\\\\\nLaw of cosines: $a^2=b^2+c^2-2bc\\cos\\alpha$\\\\\nLaw of tangents: $\\dfrac{a+b}{a-b}=\\dfrac{\\tan\\dfrac{\\alpha+\\beta}{2}}{\\tan\\dfrac{\\alpha-\\beta}{2}}$\\\\\n\n\\subsection{Quadrilaterals}\nWith side lengths $a,b,c,d$, diagonals $e, f$, diagonals angle $\\theta$, area $A$ and\nmagic flux $F=b^2+d^2-a^2-c^2$:\n\n\\[ 4A = 2ef \\cdot \\sin\\theta = F\\tan\\theta = \\sqrt{4e^2f^2-F^2} \\]\n\n For cyclic quadrilaterals the sum of opposite angles is $180^\\circ$,\n$ef = ac + bd$, and $A = \\sqrt{(s-a)(s-b)(s-c)(s-d)}$.\n\n\\subsection{Spherical coordinates}\n\\centerline{\\includegraphics[width=25mm]{content/math/sphericalCoordinates}}\n\\[\\begin{array}{cc}\nx = r\\sin\\theta\\cos\\phi & r = \\sqrt{x^2+y^2+z^2}\\\\\ny = r\\sin\\theta\\sin\\phi & \\theta = \\textrm{acos}(z/\\sqrt{x^2+y^2+z^2})\\\\\nz = r\\cos\\theta & \\phi = \\textrm{atan2}(y,x)\n\\end{array}\\]\n\n\\section{Derivatives/Integrals}\n\\begin{align*}\n\t\\dfrac{d}{dx}\\arcsin x = \\dfrac{1}{\\sqrt{1-x^2}} &&& \\dfrac{d}{dx}\\arccos x = -\\dfrac{1}{\\sqrt{1-x^2}} \\\\\n\t\\dfrac{d}{dx}\\tan x = 1+\\tan^2 x &&& \\dfrac{d}{dx}\\arctan x = \\dfrac{1}{1+x^2} \\\\\n\t\\int\\tan ax = -\\dfrac{\\ln|\\cos ax|}{a} &&& \\int x\\sin ax = \\dfrac{\\sin ax-ax \\cos ax}{a^2} \\\\\n\t\\int e^{-x^2} = \\frac{\\sqrt \\pi}{2} \\text{erf}(x) &&& \\int xe^{ax}dx = \\frac{e^{ax}}{a^2}(ax-1)\n\\end{align*}\n\nIntegration by parts:\n\\[\\int_a^bf(x)g(x)dx = [F(x)g(x)]_a^b-\\int_a^bF(x)g'(x)dx\\]\n\n\\section{Sums/Series}\n\n\\begin{comment}\n\\[ c^a + c^{a+1} + \\dots + c^{b} = \\frac{c^{b+1} - c^a}{c-1}, c \\neq 1 \\]\n\\begin{align*}\n\t1 + 2 + 3 + \\dots + n &= \\frac{n(n+1)}{2} \\\\\n\t1^2 + 2^2 + 3^2 + \\dots + n^2 &= \\frac{n(n+1)(2n+1)}{6} \\\\\n\t1^3 + 2^3 + 3^3 + \\dots + n^3 &= \\frac{n^2(n+1)^2}{4} \\\\\n\t1^4 + 2^4 + 3^4 + \\dots + n^4 &= \\frac{n(n+1)(2n+1)(3n^2+3n - 1)}{30} \n\\end{align*}\n\\end{comment}\n\n% $$1^4 + 2^4 + 3^4 + \\dots + n^4= \\frac{n(n+1)(2n+1)(3n^2+3n - 1)}{30}$$\n% $$e^x = 1+x+\\frac{x^2}{2!}+\\frac{x^3}{3!}+\\dots,\\,(-\\infty<x<\\infty)$$\n$$\\ln(1+x) = x-\\frac{x^2}{2}+\\frac{x^3}{3}-\\frac{x^4}{4}+\\dots,\\,(-1<x\\leq1)$$\n$$\\sqrt{1+x} = 1+\\frac{x}{2}-\\frac{x^2}{8}+\\frac{2x^3}{32}-\\frac{5x^4}{128}+\\dots,\\,(-1\\leq x\\leq1)$$\n$$\\sin x = x-\\frac{x^3}{3!}+\\frac{x^5}{5!}-\\frac{x^7}{7!}+\\dots,\\,(-\\infty<x<\\infty)$$\n$$\\cos x = 1-\\frac{x^2}{2!}+\\frac{x^4}{4!}-\\frac{x^6}{6!}+\\dots,\\,(-\\infty<x<\\infty)$$\n% $$e^{ix}=\\cos x+i\\sin x$$\n\n\\section{Probability theory}\nLet $X$ be a discrete random variable with probability $p_X(x)$ of assuming the value $x$. It will then have an expected value (mean) $\\mu=\\mathbb{E}(X)=\\sum_xxp_X(x)$ and variance $\\sigma^2=V(X)=\\mathbb{E}(X^2)-(\\mathbb{E}(X))^2=\\sum_x(x-\\mathbb{E}(X))^2p_X(x)$ where $\\sigma$ is the standard deviation. \n\\[\\mathbb{E}(aX+bY) = a\\mathbb{E}(X)+b\\mathbb{E}(Y)\\]\nIf $X,Y$ are independent, \\[V(aX+bY) = a^2V(X)+b^2V(Y).\\]\n% Expectation is linear\n% If $X$ is instead continuous it will have a probability density function $f_X(x)$ and the sums above will instead be integrals with $p_X(x)$ replaced by $f_X(x)$.\n\n\n\\subsection{Discrete distributions}\n\n% \\subsubsection{Binomial distribution}\n% \\# of successes in $n$ independent yes/no experiments, each which yields success with probability $p$ is $\\textrm{Bin}(n,p),\\,n=1,2,\\dots,\\, 0\\leq p\\leq1$.\n% \\[p(k)=\\binom{n}{k}p^k(1-p)^{n-k}\\]\n% \\[\\mu = np,\\,\\sigma^2=np(1-p)\\]\n% $\\textrm{Bin}(n,p)\\approx \\textrm{Po}(np)$ for small $p$.\n\n\\subsubsection{First success distribution}\nThe number of trials needed to get the first success in independent yes/no experiments, each wich yields success with probability $p$ is $\\textrm{Fs}(p),\\,0\\leq p\\leq1$.\n\\[p(k)=p(1-p)^{k-1},\\,k=1,2,\\dots\\]\n\\[\\mu = \\frac1p,\\,\\sigma^2=\\frac{1-p}{p^2}\\]\n\n\\subsubsection{Poisson distribution}\nThe number of events occurring in a fixed period of time $t$ if these events occur with a known average rate $\\kappa$ and independently of the time since the last event is $\\textrm{Po}(\\lambda),\\,\\lambda=t\\kappa$.\n\\[p(k)=e^{-\\lambda}\\frac{\\lambda^k}{k!}, k=0,1,2,\\dots\\]\n\\[\\mu=\\lambda,\\,\\sigma^2=\\lambda\\]\n$\\textrm{Bin}(n,p)\\approx \\textrm{Po}(np)$ for small $p$ (binomial distribution with $n$ coin flips, each of which is heads with probability $p$).\n\n\\subsection{Continuous distributions}\n\n% \\subsubsection{Uniform distribution}\n% If the probability density function is constant between $a$ and $b$ and 0 elsewhere it is $\\textrm{U}(a,b),\\,a<b$.\n% \\[f(x) = \\left\\{\n% \\begin{array}{cl}\n% \\frac{1}{b-a} & a<x<b\\\\\n% 0 & \\textrm{otherwise}\n% \\end{array}\\right.\\]\n% \\[\\mu=\\frac{a+b}{2},\\,\\sigma^2=\\frac{(b-a)^2}{12}\\]\n\n\\subsubsection{Exponential distribution}\nThe time between events in a Poisson process is $\\textrm{Exp}(\\lambda),\\,\\lambda>0$.\n\\[f(x) = \\left\\{\n\\begin{array}{cl}\n\\lambda e^{-\\lambda x} & x\\geq0\\\\\n0 & x<0\n\\end{array}\\right.\\]\n\\[\\mu=\\frac{1}{\\lambda},\\,\\sigma^2=\\frac{1}{\\lambda^2}\\]\n\n\\subsubsection{Normal distribution}\nMost real random values with mean $\\mu$ and variance $\\sigma^2$ are well described by $\\mathcal{N}(\\mu,\\sigma^2),\\,\\sigma>0$.\n\\[ f(x) = \\frac{1}{\\sqrt{2\\pi\\sigma^2}}e^{-\\frac{(x-\\mu)^2}{2\\sigma^2}} \\]\n% If $X_1 \\sim \\mathcal{N}(\\mu_1,\\sigma_1^2)$ and $X_2 \\sim \\mathcal{N}(\\mu_2,\\sigma_2^2)$ then\n% \\[ aX_1 + bX_2 + c \\sim \\mathcal{N}(\\mu_1+\\mu_2+c,a^2\\sigma_1^2+b^2\\sigma_2^2) \\]\n\n\\section{Markov chains}\nA \\emph{Markov chain} is a discrete random process with the property that the next state depends only on the current state.\nLet $X_1,X_2,\\ldots$ be a sequence of random variables generated by the Markov process.\nThen there is a transition matrix $\\mathbf{P} = (p_{ij})$, with $p_{ij} = \\Pr(X_n = i | X_{n-1} = j)$,\nand $\\mathbf{p}^{(n)} = \\mathbf P^n \\mathbf p^{(0)}$ is the probability distribution for $X_n$ (i.e., $p^{(n)}_i = \\Pr(X_n = i)$),\nwhere $\\mathbf{p}^{(0)}$ is the initial distribution.\n\n% \\subsubsection{Stationary distribution}\n$\\mathbf{\\pi}$ is a stationary distribution if $\\mathbf{\\pi} = \\mathbf{\\pi P}$.\nIf the Markov chain is \\emph{irreducible} (it is possible to get to any state from any state),\nthen $\\pi_i = \\frac{1}{\\mathbb{E}(T_i)}$ where $\\mathbb{E}(T_i)$  is the expected time between two visits in state $i$.\n$\\pi_j/\\pi_i$ is the expected number of visits in state $j$ between two visits in state $i$.\n\nFor a connected, undirected and non-bipartite graph, where the transition probability is uniform among all neighbors, $\\pi_i$ is proportional to node $i$'s degree. \\textbf{(IMPORTANT)} % https://codeforces.com/gym/101081/problem/B\n\n% \\subsubsection{Ergodicity}\nA Markov chain is \\emph{ergodic} if the asymptotic distribution is independent of the initial distribution.\nA finite Markov chain is ergodic iff it is irreducible and \\emph{aperiodic} (i.e., the gcd of cycle lengths is 1).\n$\\lim_{k\\rightarrow\\infty}\\mathbf{P}^k = \\mathbf{1}\\pi$.\n\n\\begin{comment}\n% \\subsubsection{Absorption}\nA Markov chain is an A-chain if the states can be partitioned into two sets $\\mathbf{A}$ and $\\mathbf{G}$, such that all states in $\\mathbf{A}$ are absorbing ($p_{ii}=1$), and all states in $\\mathbf{G}$ lead to an absorbing state in $\\mathbf{A}$.\nThe probability for absorption in state $i\\in\\mathbf{A}$, when the initial state is $j$, is $a_{ij} = p_{ij}+\\sum_{k\\in\\mathbf{G}} a_{ik}p_{kj}$.\nThe expected time until absorption, when the initial state is $i$, is $t_i = 1+\\sum_{k\\in\\mathbf{G}}p_{ki}t_k$.\n\\end{comment}", "meta": {"hexsha": "b1d357d9257ae25721b8094c75f102259b6efc6d", "size": 8920, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Implementations/content/math/chapter.tex", "max_stars_repo_name": "nocrizwang/USACO", "max_stars_repo_head_hexsha": "8a922f8d4b3bc905da97f53f9a447debe97d5e81", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-30T21:50:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-21T17:03:41.000Z", "max_issues_repo_path": "Implementations/content/math/chapter.tex", "max_issues_repo_name": "nocrizwang/USACO", "max_issues_repo_head_hexsha": "8a922f8d4b3bc905da97f53f9a447debe97d5e81", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Implementations/content/math/chapter.tex", "max_forks_repo_name": "nocrizwang/USACO", "max_forks_repo_head_hexsha": "8a922f8d4b3bc905da97f53f9a447debe97d5e81", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-04T02:36:09.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-04T02:36:09.000Z", "avg_line_length": 50.9714285714, "max_line_length": 305, "alphanum_fraction": 0.6365470852, "num_tokens": 3598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7431680870182714}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Let $z=2+7i$ and let $w=3-8i$. Compute $z + w$, $z - 2w$, $zw$, and $\\frac{w}{z}$.\n  \\begin{sol}\n    $z + w = 5-i$, $z - 2w = -4 + 23i$, $zw = 62+5i$, and\n    $\\displaystyle\\frac{w}{z} = -\\frac{50}{53}-\\frac{37}{53}i$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $z = 1 - 4i$. Compute $\\conjugate{z}$, $z^{-1}$, and $\\abs{z}$.\n\\end{ex}\n\n\\begin{ex}\n  Let $z = 3+5i$ and $w = 2-i$. Compute $\\conjugate{zw}$, $\\abs{zw}$,\n  and $z^{-1}w$.\n\\end{ex}\n\n\\begin{ex}\n  Use the properties of complex numbers to prove that if $z$ is a\n  complex number, then there exists a complex number $w$ with\n  $\\abs{w}=1$ and $wz=\\abs{z}$.\n  \\begin{sol}\n    If $z=0$, let $w=1$. If $z\\neq 0$, let\n    $w =\\displaystyle\\frac{\\abs{z}}{z}$. Note that\n    $\\displaystyle wz = \\frac{\\abs{z}}{z}z = \\abs{z}$ and\n    $\\displaystyle \\abs{w} = \\frac{\\abs{z}}{\\abs{z}} = 1$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  I claim that $1=-1$. Here is why.\n  \\begin{equation*}\n    -1=i\\,^2=\\sqrt{-1}\\sqrt{-1}=\\sqrt{(-1)^2}=\\sqrt{1}=1.\n  \\end{equation*}\n  What is wrong with this argument?\n  \\begin{sol}\n    The problem is that there is no single $\\sqrt{-1}$. In the complex\n    numbers, $-1$ has two square roots, namely $i$ and $-i$. Since\n    each complex number has two square roots, and generally neither of\n    them is positive or even real, the notation $\\sqrt{z}$ does not\n    have a fixed meaning in the complex numbers. Therefore, the\n    equation $\\sqrt{z}\\sqrt{w} = \\sqrt{zw}$ cannot be used. At best,\n    we could maybe say $\\sqrt{z}\\sqrt{w} = \\pm\\sqrt{zw}$.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "8e719ea28e25e49d84fe488ceb7689ab42041f5c", "size": 1576, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/ComplexNumbers-ComplexNumbers.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/ComplexNumbers-ComplexNumbers.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/ComplexNumbers-ComplexNumbers.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 32.1632653061, "max_line_length": 84, "alphanum_fraction": 0.5824873096, "num_tokens": 632, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7431680761381716}}
{"text": "\\lab{One-dimensional Optimization}{One-dimensional Optimization}\n\\objective{Most mathematical optimization problems involve estimating the minimizer(s) of a scalar-valued function.\nMany algorithms for optimizing functions with a high-dimensional domain depend on routines for optimizing functions of a single variable.\nThere are many techniques for optimization in one dimension, each with varying degrees of precision and speed.\nIn this lab, we implement the golden section search method, Newton's method, and the secant method, then apply them to the backtracking problem.\n% Some of these techniques also generalize to optimization in higher dimensions.\n}\n\n\\section*{Golden Section Search} % --------------------------------------------\n\nA function $f:[a,b]\\rightarrow\\mathbb{R}$ satisfies the \\emph{unimodal property} if it has exactly one local minimum and is monotonic on either side of the minimizer.\nIn other words, $f$ decreases from $a$ to its minimizer $x^*$, then increases up to $b$ (see Figure \\ref{fig:1dopt-golden-unimodal}).\n% Unimodal functions are the ``easiest'' kinds of functions to optimize, but there are several strategies for doing so.\nThe \\emph{golden section search} method optimizes a unimodal function $f$ by iteratively defining smaller and smaller intervals containing the unique minimizer $x^*$.\nThis approach is especially useful if the function's derivative does not exist, is unknown, or is very costly to compute.\n\nBy definition, the minimizer $x^*$ of $f$ must lie in the interval $[a,b]$.\nTo shrink the interval around $x^*$, we test the following strategically chosen points.\n\\begin{equation*}\n\\tilde{a} = b - \\frac{b - a}{\\varphi}\\qquad\\qquad\n\\tilde{b} = a + \\frac{b - a}{\\varphi}\n% \\label{eq:1dopt-golden-testpts}\n\\end{equation*}\nHere $\\varphi = \\frac{1 + \\sqrt{5}}{2}$ is the \\emph{golden ratio}.\nAt each step of the search, $[a,b]$ is refined to either $[a,\\tilde{b}]$ or $[\\tilde{a}, b]$, called the \\emph{golden sections}, depending on the following criteria.\n % \\footnote{Note that this is the same as $\\tilde{a} = a + \\rho(b-a)$ and $\\tilde{b} = a + (1-\\rho)(b-a)$ where $\\rho = \\frac{3-\\sqrt{5}}{2}$.}\n% These points define evenly sized intervals $[\\tilde{a}, b]$ and $[a, \\tilde{b}]$, called \\emph{golden sections} since the ratio of the lengths of $[a,\\tilde{a}]$ to $[\\tilde{a},b]$ is the same as the ratio of the lengths of $[\\tilde{a}, b]$ and $[a, b]$.\n% Additionally, the property of the golden ratio that  $\\frac{1}{\\varphi^2} = 1 - \\frac{1}{\\varphi}$ leads to a smaller amount of computations needed.\n\nIf $f(\\tilde{a}) < f(\\tilde{b})$, then since $f$ is unimodal, it must be increasing in a neighborhood of $\\tilde{b}$.\nThe unimodal property also guarantees that $f$ must be increasing on $[\\tilde{b}, b]$ as well, so $x^* \\in [a, \\tilde{b}]$ and we set $b = \\tilde{b}$.\nBy similar reasoning, if $f(\\tilde{a}) > f(\\tilde{b})$, then $x^* \\in [\\tilde{a}, b]$ and we set $a = \\tilde{a}$.\nIf, however, $f(\\tilde{a}) = f(\\tilde{b})$, then the unimodality of $f$ does not guarantee anything about where the minimizer lies.\nAssuming either $x^*\\in [a, \\tilde{b}]$ or $x^* \\in [\\tilde{a}, b]$ allows the iteration to continue, but the method is no longer guaranteed to converge to the local minimum.\n\nAt each iteration, the length of the search interval is divided by $\\varphi$.\nThe method therefore converges linearly, which is somewhat slow.\nHowever, the idea is simple and each step is computationally inexpensive.\n\n\\begin{figure}[H] % Golden section search for unimodal optimization.\n    \\centering\n    \\includegraphics[width=.7\\textwidth]{figures/golden_section.pdf}\n    \\caption{The unimodal $f:[a,b]\\rightarrow\\mathbb{R}$ can be minimized with a golden section search.\n    For the first iteration, $f(\\tilde{a}) < f(\\tilde{b})$, so $x^* \\in [a, \\tilde{b}]$.\n    New values of $\\tilde{a}$ and $\\tilde{b}$ are then calculated from this new, smaller interval.}\n    \\label{fig:1dopt-golden-unimodal}\n\\end{figure}\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{golden\\_section}{$f$,\\ $a$,\\ $b$,\\ \\li{tol},\\ \\li{maxiter}}\n   \\State $x_0 \\gets (a + b)/2$\n        \\Comment{Set the initial minimizer approximation as the interval midpoint.}\n   \\State $\\varphi = (1+\\sqrt{5})/2$\n        % \\Comment{Set $\\varphi$.}\n   \\For{$i=1,2,\\dots,$\\ \\li{maxiter}}\n        \\Comment Iterate only \\li{maxiter} times at most.\n        \\State $c \\gets (b - a)/\\varphi$\n        \\State $\\tilde{a} \\gets b - c$\n            % \\Comment{Set $\\tilde{a}$.}\n        \\State $\\tilde{b} \\gets a + c$\n            % \\Comment{Set $\\tilde{b}$. }\n        \\If{$f(\\tilde{a}) \\leq f(\\tilde{b})$}\n            \\Comment{Get new boundaries for the search interval.}\n            \\State $b \\gets \\tilde{b}$\n         \\Else{}\n            \\State $a \\gets \\tilde{a}$\n                \\EndIf\n        \\State $x_1 \\gets (a + b)/2$\n            \\Comment{Set the minimizer approximation as the interval midpoint.}\n        \\If{$|x_0-x_1| <$ \\li{tol}}\n              \\State \\texttt{break}\n                \\Comment{Stop iterating if the approximation stops changing enough.}\n       \\EndIf\n        \\State $x_0 \\gets x_1$\n   \\EndFor\n   \\State \\pseudoli{return} $x_1$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The Golden Section Search}\n\\label{Alg:Golden-Section-Search}\n\\end{algorithm}\n\n\\begin{problem} % Implement golden search.\nWrite a function that accepts a function $f:\\mathbb{R}\\rightarrow\\mathbb{R}$, interval limits $a$ and $b$, a stopping tolerance \\li{tol}, and a maximum number of iterations \\li{maxiter}.\nUse Algorithm \\ref{Alg:Golden-Section-Search} to implement the golden section search.\nReturn the approximate minimizer $x^*$, whether or not the algorithm converged (\\li{true} or \\li{false}), and the number of iterations computed.\n\nTest your function by minimizing $f(x) = e^x - 4x$ on the interval $[0, 3]$, then plotting the function and the computed minimizer together.\nAlso compare your results to SciPy's golden section search, \\li{scipy.optimize.golden()}.\n\n\\begin{lstlisting}\n>>> from scipy import optimize as opt\n>>> import numpy as np\n\n>>> f = lambda x : np.exp(x) - 4*x\n>>> opt.golden(f, brack=(0,3), tol=.001)\n1.3862578679031485              # ln(4) is the minimizer.\n\\end{lstlisting}\n\\label{prob:golden-section-search}\n\\end{problem}\n\n\\section*{Newton's Method} % ==================================================\n\n\\emph{Newton's method} is an important root-finding algorithm that can also be used for optimization.\nGiven $f:\\mathbb{R}\\rightarrow\\mathbb{R}$ and a good initial guess $x_0$, the sequence $(x_k)_{k=1}^\\infty$ generated by the recursive rule\n\\[\nx_{k+1} = x_k - \\frac{f(x_k)}{f'(x_k)}\n\\]\nconverges to a point $\\bar{x}$ satisfying $f(\\bar{x}) = 0$.\nThe first-order necessary conditions from elementary calculus state that if $f$ is differentiable, then its derivative evaluates to zero at each of its local minima and maxima.\nTherefore using Newton's method to find the zeros of $f'$ is a way to identify potential minima or maxima of $f$.\nSpecifically, starting with an initial guess $x_0$, set\n\\begin{equation}\nx_{k+1} = x_k - \\frac{f'(x_k)}{f''(x_k)}\n\\label{eq:1dopt-newton}\n\\end{equation}\nand iterate until $|x_k - x_{k-1}|$ is satisfactorily small.\nNote that this procedure does not use the actual function $f$ at all, but it requires many evaluations of its first and second derivatives.\nAs a result, Newton's method converges in few iterations, but it can be computationally expensive.\n\nEach step of \\eqref{eq:1dopt-newton} can be thought of approximating the objective function $f$ by a quadratic function $q$ and finding its unique extrema.\nThat is, we first approximate $f$ with its second-degree Taylor polynomial centered at $x_k$.\n\\[\nq(x) = f(x_k) + f'(x_k) (x - x_k) + \\frac{1}{2} f''(x_k) (x - x_k)^2\n\\]\nThis quadratic function satisfies $q(x_k) = f(x_k)$ and matches $f$ fairly well close to $x_k$.\nThus the optimizer of $q$ is a reasonable guess for an optimizer of $f$.\nTo compute that optimizer, solve $q'(x) = 0$.\n\\[\n0 = q'(x) = f'(x_k) + f''(x_k)(x - x_k)\n\\qquad\\Longrightarrow\\qquad\nx = x_k - \\frac{f'(x_k)}{f''(x_k)}\n\\]\nThis agrees with \\eqref{eq:1dopt-newton} using $x_{k+1}$ for $x$.\nSee Figure \\ref{fig:1dopt-quadratic-newton}.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = .7 \\textwidth]{figures/quad_approx.pdf}\n\\caption{A quadratic approximation of $f$ at $x_k$.\nThe minimizer $x_{k+1}$ of $q$ is close to the minimizer of $f$.\n}\n\\label{fig:1dopt-quadratic-newton}\n\\end{figure}\n\nNewton's method for optimization works well to locate minima when $f''(x) > 0$ on the entire domain.\nHowever, it may fail to converge to a minimizer if $f''(x) \\le 0$ for some portion of the domain.\nIf $f$ is not unimodal, the initial guess $x_0$ must be sufficiently close to a local minimizer $x^*$ in order to converge.\n\n\\begin{problem} % Newton's method for optimization\nLet $f:\\mathbb{R}\\rightarrow\\mathbb{R}$.\nWrite a function that accepts $f'$, $f''$, a starting point $x_0$, a stopping tolerance \\li{tol}, and a maximum number of iterations \\li{maxiter}.\nImplement Newton's method using \\eqref{eq:1dopt-newton} to locate a local optimizer.\nReturn the approximate optimizer, whether or not the algorithm converged, and the number of iterations computed.\n\nTest your function by minimizing $f(x) = x^2 + \\sin(5x)$ with an initial guess of $x_0 = 0$.\nCompare your results to \\li{scipy.optimize.newton()}, which implements the root-finding version of Newton's method.\n\\begin{lstlisting}\n>>> df = lambda x : 2*x + 5*np.cos(5*x)\n>>> d2f = lambda x : 2 - 25*np.sin(5*x)\n>>> opt.newton(df, x0=0, fprime=d2f, tol=1e-10, maxiter=500)\n-1.4473142236328096\n\\end{lstlisting}\nNote that other initial guesses can yield different minima for this function.\n\\end{problem}\n\n\\subsection*{The Secant Method} % ---------------------------------------------\n\nThe second derivative of an objective function is not always known or may be prohibitively expensive to evaluate.\nThe \\emph{secant method} solves this problem by numerically approximating the second derivative with a difference quotient.\n\\[\nf''(x) \\approx \\frac{f'(x + h) - f'(x)}{h}\n\\]\nSelecting $x = x_k$ and $h = x_{k-1} - x_k$ gives the following approximation.\n\\begin{equation}\nf''(x_k) \\approx \\frac{f'(x_k + x_{k-1} - x_k) - f'(x_k)}{x_{k-1} - x_k}\n= \\frac{f(x_k) - f'(x_{k-1})}{x_k - x_{k-1}}\n\\label{eq:1dopt-secant-approx}\n\\end{equation}\n% The \\emph{Secant method} approximates it using secant lines, or in other words, the rate of change between points.\nInserting \\eqref{eq:1dopt-secant-approx} into \\eqref{eq:1dopt-newton} results in the complete secant method formula.\n\\begin{equation}\nx_{k+1}\n= x_k - \\frac{x_k - x_{k-1}}{f'(x_k) - f'(x_{k-1})}f'(x_k)\n= \\frac{x_{k-1}f'(x_k) - x_{k}f'(x_{k-1})}{f'(x_k) - f'(x_{k-1})}\n\\label{eq:1dopt-secant-method}\n\\end{equation}\nNotice that this recurrence relation requires two previous points (both $x_{k}$ and $x_{k-1}$) to calculate the next estimate.\nThis method converges superlinearly---slower than Newton's method, but faster than the golden section search---with convergence criteria similar to Newton's method.\n\n\\begin{problem} % Implement secant method.\nWrite a function that accepts a first derivative $f'$, starting points $x_0$ and $x_1$, a stopping tolerance \\li{tol}, and a maximum of iterations \\li{maxiter}.\nUse \\eqref{eq:1dopt-secant-method} to implement the Secant method.\nTry to make as few computations as possible by only computing $f'(x_k)$ once for each $k$.\nReturn the minimizer approximation, whether or not the algorithm converged, and the number of iterations computed.\n\nTest your code with the function $f(x) = x^2 + \\sin(x) + \\sin(10x)$ and with initial guesses of $x_0 = 0$ and $x_1 = -1$.\nPlot your answer with the graph of the function.\nAlso compare your results to \\li{scipy.optimize.newton()}; without providing the \\li{fprime} argument, this function uses the secant method.\n% Note that this function is highly sensitive to the starting point, which is why it is not as helpful to compare your function with SciPy's method.\nHowever, it still only takes in one initial condition, so it may converge to a different local minimum than your function.\n\n\\begin{lstlisting}\n>>> df = lambda x: 2*x + np.cos(x) + 10*np.cos(10*x)\n>>> opt.newton(df, x0=0, tol=1e-10, maxiter=500)\n-3.2149595174761636\n\\end{lstlisting}\n\\end{problem}\n\n\\section*{Descent Methods} % ==================================================\n\nConsider now a function $f:\\mathbb{R}^n\\rightarrow\\mathbb{R}$.\n% Minimizing $f$ is a \\emph{high-dimensional optimization problem} because the domain of $f$ is $\\mathbb{R}^n$ instead of $\\mathbb{R}$.\n\\emph{Descent methods}, also called \\emph{line search methods}, are optimization algorithms that create a convergent sequence $(x_k)_{k=1}^\\infty$ by the following rule.\n\\begin{equation}\n\\x_{k+1} = \\x_k + \\alpha_k \\textbf{p}_k\n\\end{equation}\nHere $\\alpha_k \\in \\mathbb{R}$ is called the \\emph{step size} and $\\textbf{p}_k \\in \\mathbb{R}^n$ is called the \\emph{search direction}.\nThe choice of $\\textbf{p}_k$ is usually what distinguishes an algorithm;\nin the one-dimensional case ($n = 1$), $p_k = f'(x_k)/f''(x_k)$ results in Newton's method, and using the approximation in \\eqref{eq:1dopt-secant-approx} results in the secant method.\n\nTo be effective, a descent method must also use a good step size $\\alpha_k$.\nIf $\\alpha_k$  is too large, the method may repeatedly overstep the minimum; if $\\alpha_k$ is too small, the method may converge extremely slowly.\nSee Figure \\ref{fig:1dopt-overstep}.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.7\\textwidth]{figures/large_alpha.pdf}\n    \\caption{If the step size $\\alpha_k$ is too large, a descent method may repeatedly overstep the minimizer.}\n    \\label{fig:1dopt-overstep}\n\\end{figure}\n\nGiven a search direction $\\textbf{p}_k$, the best step size $\\alpha_k$ minimizes the function $\\phi_k(\\alpha) = f(\\x_k + \\alpha\\textbf{p}_k)$.\nSince $f$ is scalar-valued, $\\phi_k:\\mathbb{R}\\rightarrow\\mathbb{R}$, so any of the optimization methods discussed previously can be used to minimize $\\phi_k$.\nHowever, computing the best $\\alpha_k$ at every iteration is not always practical.\n % especially since computing a good $\\mathbf{p}_k$ is generally more critical.\nInstead, some methods use a cheap routine to compute a step size that may not be optimal, but which is good enough.\n% These methods do not seek to minimize $\\phi_k(\\alpha)$, but instead seek to sufficiently decrease it.\nThe most common approach is to find an $\\alpha_k$ that satisfies the \\emph{Wolfe conditions}:\n\\begin{align}\n&f(\\textbf{x}_k + \\alpha_k \\textbf{p}_k) \\leq f(\\textbf{x}_k) + c_1\\alpha_k Df(\\textbf{x}_k)\\trp \\textbf{p}_k\n\\label{eq:1dopt-wolfe-armijo}\n\\\\\n& - Df(\\textbf{x}_k + \\alpha_k \\textbf{p}_k)\\trp \\textbf{p}_k \\leq -c_2 Df(\\textbf{x}_k)\\trp \\textbf{p}_k\n\\label{eq:1dopt-wolfe-curvature}\n\\end{align}\nwhere $0 < c1 < c2 < 1$ (for the  best results, choose $c1 << c2$).\nThe condition \\eqref{eq:1dopt-wolfe-armijo} is also called the \\emph{Armijo rule} and ensures that the step decreases $f$.\nHowever, this condition is not enough on its own.\nBy Taylor's theorem,\n\\[\nf(\\textbf{x}_k + \\alpha_k \\textbf{p}_k) = f(\\textbf{x}_k) + \\alpha_k Df(\\textbf{x}_k)\\trp \\textbf{p}_k + \\mathcal{O}(\\alpha_k^2).\n\\]\nThus, a very small $\\alpha_k$ will always satisfy \\eqref{eq:1dopt-wolfe-armijo} since $Df(\\textbf{x}_k)\\trp\\textbf{p}_k < 0$ (as $\\textbf{p}_k$ is a descent direction).\nThe condition \\eqref{eq:1dopt-wolfe-curvature}, called the \\emph{curvature condition}, ensures that the $\\alpha_k$ is large enough for the algorithm to make significant progress.\n\nIt is possible to find an $\\alpha_k$ that satisfies the Wolfe conditions, but that is far from the minimizer of $\\phi_k(\\alpha)$.\nThe \\emph{strong Wolfe conditions} modify \\eqref{eq:1dopt-wolfe-curvature} to ensure that $\\alpha_k$ is near the minimizer.\n\\[\n| Df(\\textbf{x}_k + \\alpha_k \\textbf{p}_k)\\trp \\textbf{p}_k| \\leq c_2| Df(\\textbf{x}_k)\\trp \\textbf{p}_k|\n\\]\nThe \\emph{Armijo--Goldstein conditions} provide another alternative to \\eqref{eq:1dopt-wolfe-curvature}:\n\\[\nf(\\textbf{x}_k) + (1 - c)\\alpha_k Df(\\textbf{x}_k)\\trp \\textbf{p}_k \\leq f(\\textbf{x}_k + \\alpha_k\\textbf{p}_k) \\leq f(\\textbf{x}_k) + c\\alpha_k Df(\\textbf{x}_k)\\trp\\textbf{p}_k,\n\\]\nwhere $0 < c < 1$.\nThese conditions are very similar to the Wolfe conditions (the right inequality is \\eqref{eq:1dopt-wolfe-armijo}), but they do not require the calculation of the directional derivative $ Df(\\textbf{x}_k + \\alpha_k \\textbf{p}_k)\\trp\\textbf{p}_k$.\n% They perform as well as the Wolfe conditions in most situations, but are not well-matched for quasi-Newton methods with positive definite Hessians. % ?\n\n\\subsubsection*{Backtracking}\n\nA \\emph{backtracking line search} is a simple strategy for choosing an acceptable step size $\\alpha_k$: start with an fairly large initial step size $\\alpha$, then repeatedly scale it down by a factor $\\rho$ until the desired conditions are satisfied.\nThe following algorithm only requires $\\alpha$ to satisfy \\eqref{eq:1dopt-wolfe-armijo}.\nThis is usually sufficient, but if it finds $\\alpha$'s that are too small, the algorithm can be modified to satisfy \\eqref{eq:1dopt-wolfe-curvature} or one of its variants.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{backtracking}{$f$,\\ $Df$,\\ $\\x_k$,\\ $\\mathbf{p}_k$,\\ $\\alpha$,\\ $\\rho$,\\ $c$}\n    \\State \\texttt{Dfp} $\\gets Df(\\x_k)\\trp\\mathbf{p}_k$\n        \\Comment{Compute these values only once.}\n    \\State \\texttt{fx} $\\gets f(\\x_k)$\n    \\While{$\\big(f(\\x_k + \\alpha\\mathbf{p}_k) >$ \\texttt{fx} $+\\ c\\alpha$\\texttt{Dfp}$\\big)$}\n        \\State $\\alpha \\gets \\rho\\alpha$\n    \\EndWhile\n    \\Return $\\alpha$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Backtracking using the Armijo Rule}\n\\label{Alg:opt1d-backtracking}\n\\end{algorithm}\n\n\\begin{problem}\nWrite a function that accepts a function $f:\\mathbb{R}^n\\rightarrow\\mathbb{R}$, its derivative $Df:\\mathbb{R}^n\\rightarrow\\mathbb{R}^n$, an approximate minimizer $\\x_k$, a search direction $\\textbf{p}_k$, an initial step length $\\alpha$, and parameters $\\rho$ and $c$.\nImplement the backtracking method of Algorithm \\ref{Alg:opt1d-backtracking}.\nReturn the computed step size.\n\nThe functions $f$ and $Df$ should both accept 1-D NumPy arrays of length $n$.\nFor example, if $f(x,y,z) = x^2 + y^2 + z^2$, then $f$ and $Df$ could be defined as follows.\n\\begin{lstlisting}\n>>> f = lambda x: x[0]**2 + x[1]**2 + x[2]**2\n>>> Df = lambda x: np.array([2*x[0], 2*x[1], 2*x[2]])\n\\end{lstlisting}\n\nSciPy's \\li{scipy.optimize.linesearch.scalar_search_armijo()} finds an acceptable step size using the Armijo rule.\nIt may not give the exact answer as your implementation since it decreases $\\alpha$ differently, but the answers should be similar.\n\\begin{lstlisting}\n>>> from scipy.optimize import linesearch\n>>> from autograd import numpy as anp\n>>> from autograd import grad\n\n# Get a step size for f(x,y,z) = x^2 + y^2 + z^2.\n>>> f = lambda x: x[0]**2 + x[1]**2 + x[2]**2\n>>> x = anp.array([150., .03, 40.])         # Current minimizer guesss.\n>>> p = anp.array([-.5, -100., -4.5])       # Current search direction.\n>>> phi = lambda alpha: f(x + alpha*p)      # Define phi(alpha).\n>>> dphi = grad(phi)\n>>> alpha, _ = linesearch.scalar_search_armijo(phi, phi(0.), dphi(0.))\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{comment} % This is a little too confusing and needs revision if it's going to be in print.\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Golden Search Derivations} % -------------------------------------\n\nThe ratio of the lengths of $[a, \\tilde{a}]$ and $[\\tilde{a}, b]$ is the same as the ratio between the lengths of $[\\tilde{a}, b]$ and $[a, b]$ as follows:\n\\begin{align*}\n\\frac{\\tilde{a}-a}{b-\\tilde{a}} &= \\frac{(b-a)(1-\\frac{1}{\\varphi})}{b-b+\\frac{b-a}{\\varphi}} \\\\\n&= \\varphi(1-\\frac{1}{\\varphi}) \\\\\n\\frac{b-\\tilde{a}}{b-a} &= \\frac{1}{\\varphi}\n\\end{align*}\nAs one of the properties of the golden ratio states that $\\frac{1}{\\varphi^2} = 1 - \\frac{1}{\\varphi}$, they are equal.\n\nChosing the test points according to the golden ratio saves on computations.\nFor example, consider the case where $f(\\tilde{a}) > f(\\tilde{b})$ and label $a_0 = a$ and $a_1 = \\tilde{a}$.\nThus, $x^* \\in [\\tilde{a}, b]$ and for the next iteration\n\\begin{align*}\n\\tilde{a_1} &= b - \\frac{b - a_1}{\\varphi} \\\\\n&= b - \\frac{b - b + \\frac{b - a_0}{\\varphi}}{\\varphi}\\\\\n&= b - \\frac{b - a_0}{\\varphi^2}\\\\\n&= a_0 + \\frac{b - a_0}{\\varphi}\\\\\n&= \\tilde{b}\n\\end{align*}\nTherefore, the next $\\tilde{a}$ is the previous $\\tilde{b}$.\nSimilarly, if $f(\\tilde{a}) < f(\\tilde{b})$, then the next $\\tilde{b}$ will be the previous $\\tilde{a}$.\n\\end{comment}\n", "meta": {"hexsha": "3effea45cd23d7597792985ad16111f9defedb3d", "size": 20666, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume2/OneD_Optimization/OneD_Optimization.tex", "max_stars_repo_name": "chrismmuir/Labs-1", "max_stars_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 190, "max_stars_repo_stars_event_min_datetime": "2015-07-17T01:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T19:16:19.000Z", "max_issues_repo_path": "Volume2/OneD_Optimization/OneD_Optimization.tex", "max_issues_repo_name": "chrismmuir/Labs-1", "max_issues_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 184, "max_issues_repo_issues_event_min_datetime": "2015-07-16T17:56:06.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T23:47:14.000Z", "max_forks_repo_path": "Volume2/OneD_Optimization/OneD_Optimization.tex", "max_forks_repo_name": "chrismmuir/Labs-1", "max_forks_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 76, "max_forks_repo_forks_event_min_datetime": "2015-08-06T02:53:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T11:08:57.000Z", "avg_line_length": 58.8774928775, "max_line_length": 268, "alphanum_fraction": 0.6919578051, "num_tokens": 6460, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245828938678, "lm_q2_score": 0.8918110555020056, "lm_q1q2_score": 0.7431680758463488}}
{"text": "\n\\subsection{G{\\\"o}del’s completeness theorem}\n\n\\subsubsection{Completeness of first-order logic}\n\nWe previously showed that zero-order logic was complete. What about first-order logic?\n\nG{\\\"o}del’s’ completeness theorem says that for first order logic, a theory can include all tautologies, the first category.\n\nIf the completeness theorem is true and a formula is not in the theory, then the formula is either refutable or satisfiable under some, but not all interpretations.\n\nThat is, either the theory will contain \\(\\theta \\), \\(\\neg \\theta \\), or \\(\\theta \\) will be satisfiable in some but not all interpretations, and neither will be in the in theory.\n\nTo prove this we look for a proof that every formula is either refutable or true under some structure. So for an arbitrary formula \\(\\theta \\) we want to show it is either refutable or satisfiable under some interpretation.\n\n\\subsubsection{Part 1: Converting the form of the formula}\n\nRemove free variables, functions\n\nNote that if this is true, all valid formulae of the form below are provable:\n\n\\(\\neg \\theta \\)\n\nThis means that there is no interpretation where the following is true:\n\n\\(\\theta \\)\n\nConversely if \\(\\neg \\theta \\) is not in the theory, then \\(\\theta \\) must be true under some interpretation.\n\nThat is, if all valid formulae are provable, then all\n\nReformulating the question:\n\nThis is the most basic form of the completeness theorem. We immediately restate it in a form more convenient for our purposes:\n\nTheorem 2. Every formula \\(\\theta \\) is either refutable or satisfiable in some structure.\n\n\"\\(\\theta \\)is refutable\" means by definition \"\\(\\neg \\theta \\) is provable\".\n\n\\subsubsection{Decidability}\n\nGiven a formula, can we find out if can be derived from the axioms? We can follow a process for doing so which would inform us if the formula was or was not a theorem. Alternative, the process could carry on forever.\n\nIf the process never carries on forever the system is decidable: there is a finite process to determine whether the formula is in or out. If the process halts for true formulas, but can carry on forever for false formulas, the system is semi-decidable. If the process takes a long time, we do not know if it is looping infinitely, or approaching its halt point.\n\nIntuitively, use of axioms can make an existing formula shorter or longer, so finding all short formulas can require going forwards and backwards an infinite number of times.\n\n", "meta": {"hexsha": "9f8569117981cd35ebc73c74f8db26b18c96a991", "size": 2444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/godelCompleteness/01-01-firstCompleteness.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/godelCompleteness/01-01-firstCompleteness.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/godelCompleteness/01-01-firstCompleteness.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.9166666667, "max_line_length": 361, "alphanum_fraction": 0.772913257, "num_tokens": 551, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171067, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.7431402864510092}}
{"text": "\\section{Gaussian Mixture Model}%\n\\label{sec:l2hmc_gmm}\n%\nThe Gaussian Mixture Model (GMM) is a notoriously difficult example for\ntraditional HMC to sample accurately due to the existence of multiple modes.\n%\nIn particular, HMC cannot mix between modes that are reasonably separated\nwithout recourse to additional tricks.\n%\nThis is due, in part, to the fact that HMC cannot easily traverse the\nlow-density zones which exist between modes.\n\nIn the most general case, we consider a target distribution described by a\nmixture of $M > 1$ components in\n$\\mathbb{R}^{D}$ for $D \\geq 1$:\n%\n\\begin{equation}\n    p(\\mathbf{x}) \\equiv \\sum_{m=1}^{M} p(m) p(\\mathbf{x}|m) \\equiv\n        \\sum_{m=1}^{M} \\pi_m p(\\mathbf{x}|m) \\quad \\forall \\,\\,\\mathbf{x} \\in\n        \\mathbb{R}^{D}\n    \\label{eq:gmm_model}\n\\end{equation}\n%\nwhere $\\sum_{m=1}^{M} \\pi_m = 1$, $\\pi_M \\in (0, 1)$ $\\forall m = 1, \\ldots, M$\nand each component distribution is a normal probability distribution in\n$\\mathbb{R}^{D}$.\n%\nSo $\\mathbf{x}|m \\sim \\mathcal{N}(\\bm{\\mu}_m, \\bm{\\Sigma}_m)$, where\n$\\bm{\\mu}_m \\equiv \\mathbb{E}_{p{(\\mathbf{x}|m)}}\\left\\{\\mathbf{x}\\right\\}$ and\n$\\mathbf{\\Sigma}_m \\equiv \\mathbb{E}_{p{(\\mathbf{x}|m)}}{\\left\\{{(\\mathbf{x} -\n\\bm{\\mu}_m)}{(\\mathbf{x} - \\bm{\\mu}_m)}^{T}\\right\\}} > 0$ are the mean vector\nand covariance matrix, respectively, of component $m$.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Example}\n%\nConsider a simple 2D case consisting of two Gaussians \n%\n\\begin{equation}\n    \\mathbf{x} \\sim \\pi_1 \\,\\mathcal{N}(\\bm{\\mu}_1, \\bm{\\Sigma}_1) +\n        \\pi_2\\, \\mathcal{N}(\\bm{\\mu}_2, \\bm{\\Sigma}_2)\n    \\label{eq:log_likelihood_example}\n\\end{equation}\n%\nwith $\\pi_1 = \\pi_2 = 0.5$, $\\bm{\\mu}_1 = (-2, 0)$, $\\bm{\\mu}_2 = (2, 0)$ and\n%\n\\begin{equation}\n    \\bm{\\Sigma}_1 = \\bm{\\Sigma}_2 = \n        \\begin{bmatrix}\n            0.1    & 0 \\\\\n            0       & 0.1 \n        \\end{bmatrix}\n    \\label{eq:covariance_matrix}\n\\end{equation}\n%\nThe results of trajectories generated using both traditional HMC and the L2HMC\nalgorithm can be seen in Fig.~\\ref{fig:gmm_trajectories}.\na\nNote that traditional HMC performs poorly and is unable to mix between the two\nmodes, whereas L2HMC is able to correctly sample from the target distribution\nwithout getting stuck in either of the individual modes.\n\n%\nThe L2HMC sampler was trained using simulated annealing using the schedule\nshown in Eq~\\ref{eq:gmm_annealing} with a starting temperature of $T = 10$, for\n$5,000$ training steps.\n%\nBy starting with a high temperature, the chain is able to move between both\nmodes (`tunnel') successfully.\n%\nOnce it has learned this, we can lower the temperature back to $T = 1$ and\nrecover the initial distribution while preserving information about tunneling\nin the networks ``memory''.\n%\n\\begin{equation}\n  T(n) = {\\left(T_{i} - T_{f}\\right)} \\cdot {\\left(1 -\n  \\frac{n}{N_{\\mathrm{train}}}\\right)} + T_{f} \n\\label{eq:gmm_annealing}\n\\end{equation}\n%\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=\\textwidth]{gmm_figures/iso_gmm_chains1}\n    \\caption{Comparison of trajectories generated using L2HMC (top), and\n        traditional HMC with $\\eps = 0.25$ (middle) and $\\eps = 0.5$ (bottom).\n        Note that L2HMC is able to successfully mix between modes, whereas HMC\n        is not.}%\n\\label{fig:gmm_trajectories}\n\\end{figure}\n%\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=0.98\\textwidth]{gmm_figures/gmm_acl}\n    \\caption{Autocorrelation vs.\\ gradient evaluations (i.e.\\ MD steps). Note\n    that L2HMC (blue) has a significantly reduced autocorrelation after the\n  same number of gradient evaluations when compared to either of the two HMC\ntrajectories}% \n\\label{fig:gmm_autocorrelation} \n\\end{figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n", "meta": {"hexsha": "7ef63e68a579c1adfbf914601642a9df8aa7d018", "size": 3928, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/gmm/gmm.tex", "max_stars_repo_name": "saforem2/l2hmc-qcd", "max_stars_repo_head_hexsha": "b5fe06243fae663607b6c88e71373b68b19558fc", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2019-04-18T18:50:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T18:30:48.000Z", "max_issues_repo_path": "doc/gmm/gmm.tex", "max_issues_repo_name": "saforem2/l2hmc-qcd", "max_issues_repo_head_hexsha": "b5fe06243fae663607b6c88e71373b68b19558fc", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 21, "max_issues_repo_issues_event_min_datetime": "2019-09-09T21:10:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T17:43:51.000Z", "max_forks_repo_path": "doc/gmm/gmm.tex", "max_forks_repo_name": "saforem2/l2hmc-qcd", "max_forks_repo_head_hexsha": "b5fe06243fae663607b6c88e71373b68b19558fc", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-10-31T02:25:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-25T00:49:14.000Z", "avg_line_length": 38.1359223301, "max_line_length": 79, "alphanum_fraction": 0.6461303462, "num_tokens": 1200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7431402781602826}}
{"text": "\\chapter{Completions}\n\t\\setlist[enumerate,1,2]{leftmargin=1.8cm}\n\tIn this chapter we are intended to do \\textit{elementary calculus} with a heavy taste of algebra instead of analysis. A lot of concepts in analysis are stolen by algebraists with different generalisations.\n\t\\section{Absolute value}\n\t\tLet $K$ be a field. An \\textbf{absolute value} on $K$ is a function $K \\to \\mathbb{R}$, $x \\mapsto |x|_v$ satisfying the following three properties:\n\t\t\\begin{enumerate}[start=1,label={\\bfseries AV \\arabic*}]\n\t\t\t\\item We have $|x|_v \\ge 0$ and $=0$ if and only if $x = 0$.\n\t\t\t\\item For all $x,y \\in K$ we have $|xy|_v = |x|_v|y|_v$.\n\t\t\t\\item $|x+y|_v \\le |x|_v + |y|_v$. \\label{av3}\n\t\t\\end{enumerate}\n\t\n\t\tIf instead of \\ref{av3} the absolute value satisfies the stronger condition\n\t\t\\begin{enumerate}[start=4,label={\\bfseries AV \\arabic*}]\n\t\t\t\\item $|x+y|_v \\le \\max(|x|_v,|y|_v)$\n\t\t\\end{enumerate}\n\t\tthen we shall say that it is a \\textbf{valuation} or that it is non-archimedean. in particular, if the absolute value $|\\cdot|$ satisfy $|x|=1$ for all $x \\ne 0$, then we say $|\\cdot|$ is \\textbf{trivial}. We will exclude this case from now on. ", "meta": {"hexsha": "f03aee88b00bbf99f925369b9c337a2a399bdb44", "size": 1145, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/Ch02.tex", "max_stars_repo_name": "a234/algebraic-number-theory-note", "max_stars_repo_head_hexsha": "4d46963bdb030bd8d7181822314c7c0231b29716", "max_stars_repo_licenses": ["ECL-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/Ch02.tex", "max_issues_repo_name": "a234/algebraic-number-theory-note", "max_issues_repo_head_hexsha": "4d46963bdb030bd8d7181822314c7c0231b29716", "max_issues_repo_licenses": ["ECL-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapters/Ch02.tex", "max_forks_repo_name": "a234/algebraic-number-theory-note", "max_forks_repo_head_hexsha": "4d46963bdb030bd8d7181822314c7c0231b29716", "max_forks_repo_licenses": ["ECL-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 71.5625, "max_line_length": 247, "alphanum_fraction": 0.6908296943, "num_tokens": 406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299488452012, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7431204439785211}}
{"text": "\n\\subsection{Describing events}\n\n\nIn vector space \\(\\mathbb{R}^n\\).\n\n\\(\\mathbf{q} \\in \\mathbb{R}^n\\)\n\n\n\\subsection{Describing the path of a particle}\n\nAlso known as a worldline.\n\nIndex to \\(t\\)\n\n\\(\\mathbf{q} (t)\\)\n\n\\subsection{Describing the velocity of a particle}\n\n\\(v=\\dfrac{\\delta \\mathbf{q}}{\\delta t}\\)\n\n\\subsection{Describing the acceleration of a particle}\n\n\n\\(a=\\dfrac{\\delta v}{\\delta t}\\)\n\n\\(a=\\dfrac{\\delta^2 \\mathbf{q}}{\\delta t^2}\\)\n\n", "meta": {"hexsha": "cc316bcefacd61a3a3b6dbb5f4b54195fb5c1165", "size": 448, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/physics/worldlines/01-01-describing.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/physics/worldlines/01-01-describing.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/physics/worldlines/01-01-describing.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.4482758621, "max_line_length": 54, "alphanum_fraction": 0.6584821429, "num_tokens": 152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813513911654, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7430841717219465}}
{"text": "\n\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\n\\author{a1trl9}\n\\title{Machine Learning Review}\n\\date{}\n\n\\setlength\\parindent{0pt}\n\\counterwithin*{equation}{section}\n\n\\newcommand{\\V}[1]{\\boldsymbol{#1}}\n\\newcommand{\\TM}{\\bigtriangledown}\n\n\\begin{document}\n\\maketitle\n\\section{Regression}\n\\subsection{Linear Regression}\n\\subsection{Logistic Regression}\n\\subsubsection{Why Logistic Regression is a Linear Classifier}\n\nNoting:\n\\begin{equation}\nP(y_i=1)=\\frac{1}{exp(-\\V{w'}\\V{x_i})+1}\n\\end{equation}\n\nIf we set \\(p=0.5\\) as the threshold, then:\n\\begin{equation}\n\\left\\{\n\\begin{aligned}\n&\\hat{y}=1 \\quad if \\quad \\V{w'}\\V{x}>0\\\\\n&\\hat{y}=0 \\quad if \\quad \\V{w'}\\V{x}\\leq0\n\\end{aligned}\n\\right.\n\\end{equation}\n\nIt yields that if all training data are linearly separable, logistic regression\nmay lead to over-fitting. Intuitively, when \\(\\V{w}\\) subjects to all data are\nclassified correctly, scaling \\(\\V{w}\\) up can always increase likelihood and when\n\\(\\V{w} \\to \\infty\\), \\(p(y_i)=1\\) for all data points.\n\n\\subsubsection{The convexity of Negative Log-likelihood Function}\n\nSince:\n\\begin{equation}\n\\left\\{\n\\begin{aligned}\n&P(y_i=1)=\\frac{1}{exp(-\\V{w'}\\V{x_i})+1}\\\\\n&P(y_i=0)=\\frac{1}{exp(\\V{w'}\\V{x_i})+1}\n\\end{aligned}\n\\right.\n\\end{equation}\nWhere \\(\\V{w}\\) is the coefficient vector while \\(\\V{x_i}\\) is the feature vector.\nAssuming the dimension is \\(m\\).\n\nIf we transform the label set from \\(\\{1, 0\\}\\) to \\(\\{1, -1\\}\\), then\n\\begin{equation}\np(y_i)=\\frac{1}{exp(-y_i\\V{w'}\\V{x_i})+1}\n\\end{equation}\n\nLet \\(z=-y_i\\V{w'}\\V{x_i}\\), then the negative log-likelihood function is:\n\\begin{equation}\n-L=-\\sum_{i}^{N}log[\\frac{1}{exp(z)+1}]\n\\end{equation}\n\nHere we assume \\(L\\) is \\textbf{twice continuously differentiable}.\n\nLet \\(g(z)=\\frac{1}{exp(z)+1}\\), then:\n\\begin{equation}\ng'(z)=-\\frac{exp(z)}{[exp(z)+1]^2}=-g(z)[1-g(z)]\n\\end{equation}\n\nTherefore:\n\\begin{equation}\n\\begin{aligned}\n\\frac{d(-L)}{dw_j}&=-\\sum_{i}^N\\frac{1}{g(z)}g(z)[1-g(z)]y_ix_{ij}\\\\\n&=-\\sum_{i}^Ny_ix_{ij}[1-g(z)]\n\\end{aligned}\n\\end{equation}\n\nAnd:\n\\begin{equation}\n\\begin{aligned}\n\\frac{d(-L)}{dw_jdw_k}&=\\sum_{i}^Ny_i^2x_{ij}x_{ik}g(z)[1-g(z)]\\\\\n&=\\sum_{i}^Nx_{ij}x_{ik}g(z)[1-g(z)]\n\\end{aligned}\n\\end{equation}\n\nLet \\(\\V{a}\\) be any m-dimension vector. And \\(\\TM^2\\) is the Hessian matrix\nof \\(-L\\). Then:\n\n\\begin{equation}\n\\begin{aligned}\n\\V{a'}\\TM^2\\V{a}&=\\sum_{i}^N\\sum_{j}^m\\sum_{k}^ma_ja_kx_{ij}x_{ik}g(z)[1-g(z)]\\\\\n&=\\sum_{i}^N{\\{\\sqrt{g(z)[1-g(z)]}\\V{a'}\\V{x_i}\\}^2}\\\\\n&\\geq 0\n\\end{aligned}\n\\end{equation}\n\nSo \\(\\TM^2\\) is a positive semi-definite matrix, and \\(-L\\) is Therefore\na convex function.\n\n\\vspace{2mm}\n\\textbf{Further}\n\\begin{itemize}\n\\item It can be proved, that for any identifiable model from exponential family,\nthe negative log-likelihood function is strictly convex and therefore\nthe maximum likelihood estimate is unique \\textbf{if it exists}. When model\nis not identifiable (happens when variables are not independent), only\nconvex holds.\n\\item When \\(x_1, x_2, \\cdots, x_N\\) are not linearly independent, it is possible\nthat \\(\\V{a'}\\TM\\V{a}=0\\), in which case, \\(-L\\) is not strictly convex and\nthe minimum might not be unique.\n\\item If we add L2 regularizer, then \\(-L\\) will be strictly convex.\n\\end{itemize}\n\n\\subsubsection{*Convexity \\& Concavity and Hessian Matrix}\n\nSuppose \\(f: V \\rightarrow \\mathbb{R} \\) is a twice differentiable function. \\(V\\) is\na convex set on \\(\\mathbb{R}^n\\). If \\(f\\) is not convex, then \\(\\exists (\\V{x_1}, \n\\V{x_2}) \\in V, \\exists t \\in (0, 1) \\), \\(f((1-t)\\V{x_1} + t\\V{x_2}) > (1-t)f(\\V{x_1})+tf(\\V{x_2})\\).\nLet \\(\\theta: (0, 1) \\rightarrow R: \\theta(k)=f((1-k)\\V{x_1}+k\\V{x_2})\\). Then\n\\begin{equation}\n\\theta(t)=f((1-t)\\V{x_1}+t\\V{x_2}) > (1-t)f(\\V{x_1})+tf(\\V{x_2})=(1-t)\\theta(0)+t\\theta(1)\\\n\\end{equation}\n\nTherefore:\n\\begin{equation}\n\\left\\{\n\\begin{aligned}\n&\\theta(t)-\\theta(0)>t(\\theta(1)-\\theta(0))\\\\\n&\\theta(1)-\\theta(t)<(1-t)(\\theta(1)-\\theta(0))\n\\end{aligned}\n\\right.\n\\end{equation}\n\nAccording to Mean Value Theorem, \\(\\exists t_1 \\in (0, t), t_2 \\in (t, 1)\\),\nsubject to \\(\\frac{\\theta}{dt}(t_1)t=\\theta(t)-\\theta(0),\n\\frac{\\theta}{dt}(t_2)(1-t)=\\theta(1)-\\theta(t)\\). So:\n\n\\begin{equation}\n\\left\\{\n\\begin{aligned}\n&\\frac{\\theta}{dt}(t_1)>\\theta(1)-\\theta(0)\\\\\n&\\frac{\\theta}{dt}(t_2)<\\theta(1)-\\theta(0)\n\\end{aligned}\n\\right.\n\\end{equation}\n\nIt further yields:\n\n\\begin{equation}\n\\frac{\\theta}{dt}(t_1)>\\frac{\\theta}{dt}(t_2)\n\\end{equation}\n\nApply Mean Value Theorem again:\n\\begin{equation}\n\\frac{\\theta}{dt}(t_2)-\\frac{\\theta}{dt}(t_1)=(t_2-t_1)\\frac{d^2\\theta}{dt^2}(t_3)\n\\end{equation}\n\nWhere \\(t_3 \\in (t_1, t_2)\\). And obviously \\(\\frac{d^2\\theta}{dt^2}(t_3)<0\\).\n\nAs we know \\(\\frac{d^2\\theta}{dt^2}=(\\V{x_2}-\\V{x_1})'d^2f(\\V{x_2}-\\V{x_1})\\),\nwhere \\(d^f\\) is the Hessian matrix of \\(f\\). When it is positive semi-definite,\n\\(\\V{x_2}-\\V{x_1})'d^2f(\\V{x_2}-\\V{x_1})\\geq 0\\), which is contradict to\n\\(\\frac{d^2\\theta}{dt^2}(t_3)<0\\).\n\nTherefore, when the Hessian matrix of \\(f\\) is positive semi-definite, \\(f\\) is\nconvex. Similarly, if the Hessian matrix of \\(f\\) is negative semi-definite,\n\\(f\\) is concave.\n\n\\section{Regularisation}\n\\subsection{Transformation for Linear Regression}\nWithout regularisation:\n\\begin{equation}\nL=||\\mathbf{X}\\V{w}-\\V{y}||^2\n\\end{equation}\n\nWith regularisation:\n\\begin{equation}\nL=||\\mathbf{X}\\V{w}-\\V{y}||^2+\\lambda||\\V{w}||^2\n\\end{equation}\n\nWhere \\(\\lambda\\) controls the strength of regularisation. Now we try to solve:\n\\begin{equation}\n\\begin{aligned}\n&2\\mathbf{X}'(\\mathbf{X}\\V{w}-\\V{y})+2\\lambda \\V{w}=\\V{0}\\\\\n&\\implies (\\mathbf{X}'\\mathbf{X}+\\lambda \\mathbf{I})\\V{w}=\\mathbf{X}'\\V{y}\\\\\n&\\implies \\V{w}=(\\mathbf{X}'\\mathbf{X}+\\lambda \\mathbf{I})'\\mathbf{X}'\\V{y}\n\\end{aligned}\n\\end{equation}\n\nAs we know \\(\\mathbf{A}=\\mathbf{X}'\\mathbf{X}\\) is a symmetric matrix and for any non-zero vector \\(V{v}\\)\n(same dimension as \\(\\mathbf{A}\\)):\n\\begin{equation}\n\\V{v'}\\mathbf{A}\\V{v}=\\V{v'}\\mathbf{X}'\\mathbf{X}\\V{v}=(\\mathbf{X}\\V{v})'\\mathbf{X}\\V{v}\\geq 0\n\\end{equation}\n\nThen \\(\\mathbf{A}\\) is a positive semi-definite matrix. Besides, consider\nany eigenvector / eigenvalue pair \\(\\V{p}, t\\) for \\(\\mathbf{A}\\):\n\\begin{equation}\n\\begin{split}\n(\\mathbf{A}+\\lambda\\mathbf{I})\\V{p}=\\mathbf{A}\\V{p}+\\lambda\\V{P}\n=t\\V{p}+\\lambda\\V{p}=(t+\\lambda)\\V{p}\n\\end{split}\n\\end{equation}\n\nTherefore, for all eigenvalues \\(t_1, t_2, \\cdots, t_n\\) for \\(\\mathbf{A}\\),\n\\(t_1+\\lambda, t_2+\\lambda, \\cdots, t_n+\\lambda\\) is eigenvalues for\n\\(\\mathbf{A}+\\lambda\\mathbf{I}\\). Since \\(t_1, t_2, \\cdots, t_n\\) have all been\nnon-negative as \\(\\mathbf{A}\\) is positive semi-definite, and \\(\\lambda>0\\), \\(t_1+\\lambda, t_2+\\lambda, \\cdots, t_n+\\lambda\\)\nare all positive. As the multiple of \\(n\\) eigenvalues is equal to the\ndeterminant of \\(\\mathbf{A}\\), \\(det(\\mathbf{A})\\neq 0\\) and \\(rank(\\mathbf{A})=n\\),\n\\(\\mathbf{X}'\\mathbf{X}+\\lambda\\mathbf{I}\\) must be invertable.\n\n\\subsection{Transformation for Logistic Regression}\n\nWithout regularisation (ignoring intercept):\n\\begin{equation}\n\\begin{aligned}\n&L=-\\sum_{i}^my_ilog(\\sigma(\\V{x}_i\\V{w}))+(1-y_i)log(1-\\sigma(\\V{x}_i\\V{w}))\\\\\n&\\implies\n\\frac{dL}{\\V{w}}=-\\sum_{i}^m(y_i(1-\\sigma(\\V{x}_i))-(1-y_i)\\sigma(\\V{x}_i\\V{w})))\\V{x}'_i\\\\\n&=\\sum_{i}^m(\\sigma(\\V{x}_i\\V{w})-y_i)\\V{x}_i'\\\\\n\\end{aligned}\n\\end{equation}\n\nWith regularisation:\n\\begin{equation}\n\\begin{aligned}\n&\\frac{dL}{\\V{w}}=-\\sum_{i}^m(y_i(1-\\sigma(\\V{x}_i))-(1-y_i)\\sigma(\\V{x}_i\\V{w})))\\V{x}'_i+\\lambda\\V{w}\\\\\n&=\\sum_{i}^m(\\sigma(\\V{x}_i\\V{w})-y_i)\\V{x}_i'+\\lambda\\V{w}\\\\\n\\end{aligned}\n\\end{equation}\n\n\\section{Perceptron}\n\\subsection{Perceptron Convergence}\nAssuming the training data (\\(N\\) points) are linearly separable, in which case, \n\\(\\exists \\V{v}: ||\\V{v}||=1\\), subjects to \\(y_i\\V{v'}\\V{x_i}>\\gamma\\), for\n\\(i=1, 2, \\cdots N\\).\nNoting at each gradient step, the update is in the form of:\n\n\\begin{equation}\n\\V{w}^{t+1}=\\V{w}^t+\\eta y_j\\V{x_j}\n\\end{equation}\n\nWhere \\(<y_j, \\V{x_j}>\\) is the pair of predicted class \\& selected misclassified point.\n\nAs we know:\n\\begin{equation}\n||y_k\\eta\\V{x_k} +\\V{w}^{k-1}||^2=||y_k\\eta\\V{x_k}||^2+||\\V{w}^{k-1}||^2+y_k\\eta\\V{x_k}\\cdot \\V{w}^{k-1}\n\\end{equation}\n\nMoreover, \\(y_k\\V{x}\\V{w}^{k-1}\\) is always negative since \\(\\V{x_k}\\) is a\nmisclassified point. Therefore:\n\n\\begin{equation}\n\\begin{aligned}\n||\\V{w}^k||^2&=||y_k\\eta\\V{x_k} +\\V{w}^{k-1}||^2<||y_k\\eta \\V{x_k}||^2+||\\V{w}^{k-1}||^2\\\\\n&\\leq (\\eta R)^2 + ||\\V{w}^{k-1}||^2\n\\end{aligned}\n\\end{equation}\n\nIteratively, we get:\n\n\\begin{equation}\n||\\V{w}^k||^2<||\\V{w}^0||^2+k(\\eta R)^2\n\\end{equation}\n\nMeanwhile:\n\\begin{equation}\n\\begin{aligned}\n\\sum_{i=1}^k|\\V{v'}\\cdot (\\V{w}^i-\\V{w}^{i-1})|&=\\V{v'}\\cdot\\sum_{i=1}^k(\\V{w}^i-\\V{w}^{i-1})\\\\\n&=\\V{v'}\\cdot (\\V{w}^k-\\V{w}^0)\\\\\n&\\leq ||\\V{v'}||||\\V{w}^k-\\V{w}^0||\\\\\n&=||\\V{w}^k-\\V{w}^0||\\\\\n&= \\sqrt{||\\V{w}^k||^2 + ||\\V{w}^0||^2 - \\V{w}^k \\cdot \\V{w}^0}\\\\\n&\\leq \\sqrt{||\\V{w}^k||^2+||\\V{w}^0||^2+||\\V{w}^k||||\\V{w}^0||}\n\\end{aligned}\n\\end{equation}\n\nIn addition, since:\n\\begin{equation}\n\\begin{aligned}\n\\sum_{i=1}^k|\\V{v'}\\cdot (\\V{w}^i-\\V{w}^{i-1})|&=\\sum_{i=1}^k|\\V{v'}\\cdot (y_i\\eta\\V{x_i}')|\\\\\n&\\geq ky\n\\end{aligned}\n\\end{equation}\n\nWe finally get:\n\\begin{equation}\n\\begin{aligned}\nk\\gamma &\\leq \\sum_{i=1}^k|\\V{v'}\\cdot (\\V{w}^i-\\V{w}^{i-1})|\\\\\n&\\leq \\sqrt{||\\V{w}^k||^2+||\\V{w}^0||^2+||\\V{w}^k||||\\V{w}^0||}\\\\\n&\\leq\\sqrt{||\\V{w}^0||^2+k(\\eta R)^2+||\\V{w}^0||^2+||\\V{w}^0||\\sqrt{||\\V{w}^0||^2+k(\\eta R)^2}}\n\\end{aligned}\n\\end{equation}\n\nHere, we treat \\(\\V{w}^0\\) as constant and therefore:\n\n\\begin{equation}\nk\\gamma < \\sqrt{c_1}\\sqrt{k(\\eta R)^2}\n\\end{equation}\n\nSo \\(k<O((\\frac{\\eta R}{\\gamma})^2)\\)\n\n\\section{Neural Network}\n\\subsection{Local Quadratic Approximation}\nConsider the Taylor expansion of the error function \\(E(\\V{w})\\) around\na point \\(\\hat{\\V{w}}\\) in the weight space:\n\\begin{equation}\nE(\\V{w})=E(\\hat{\\V{w}})+(\\V{w}-\\hat{\\V{w}})'\\V{b}\n+\\frac{1}{2}\\hat{\\V{w}}'\\V{H}\\hat{\\V{w}}\n\\end{equation}\n\nWhere \\(\\V{H}\\) is the Hessian matrix at \\(\\hat{\\V{w}}\\).\n\nFirst, let \\(V\\) be the n-dimension linear space for the linear\ntransformation \\(H\\). As \\(\\V{H}\\) is symmetric, we can construct \\(n\\) orthonormal eigenvectors.\n\n\\vspace{2mm}\n\\textbf{Proof}\n\nLet \\(\\lambda_1, \\lambda_2\\) be two eigenvalues of \\(\\V{H}\\), so we have:\n\\begin{equation}\n\\begin{split}\n&\\V{H}\\V{p_1}=\\lambda_1\\V{p_1}\\\\\n&\\V{H}\\V{p_2}=\\lambda_1\\V{p_2}\\\\\n\\end{split}\n\\end{equation}\n\nSo:\n\\begin{equation}\n\\begin{split}\n(\\lambda_1\\V{p_1})'\\V{p_2}=(\\V{H}\\V{p_1})'\\V{p_2}\n=\\V{p_1}'\\V{H}'\\V{p_2}\n\\end{split}\n\\end{equation}\n\nAs \\(\\V{H}\\) is symmetric, \\(\\V{H}'=\\V{H}\\):\n\\begin{equation}\n\\lambda_1\\V{p_1}\\V{p_2}=\n\\V{p_1}'\\V{H}'\\V{p_2}=\\V{p_1}'\\V{H}\\V{p_2}=\\V{p_1}'\\lambda_2\\V{p_2}\n=\\lambda_2\\V{p_1}\\V{p_2}\n\\end{equation}\n\nNow consider two cases:\n\nFirst,  \n\\(\\lambda_1, \\lambda_2\\) are distinct eigenvalues, in this case\n\\(\\V{p_1}, \\V{p_2}\\) are orthogonal.\n\n\\vspace{2mm}\nSecond, if \\(\\lambda_1, \\lambda_2\\) are the same eigenvectors. Then\nbuild a pair of orthogonal eigenvectors \\(\\alpha_1\\V{p_1} + \\beta_1\\V{p_1}\\)\nand \\(\\alpha_2\\V{p_1}+\\beta_2\\V{p_2}\\) in the eigenvector space\n\\(\\{\\V{a}|\\V{H}\\V{a}=\\lambda_1\\V{a}\\}\\). Since \\(\\V{H}\\) is diagonalizable,\ndirect sum of eigenvector spaces equals to \\(V\\), the linear representation of \\(\\alpha_1\\V{p_1} + \\beta_1\\V{p_1}\\)\nand \\(\\alpha_2\\V{p_1}+\\beta_2\\V{p_2}\\) are unique and therefore they are \nlinearly independent\nwith eigenvectors paired with eigenvalues \\(\\lambda\\neq \\lambda_1\\). Combining\nall these eigenvectors could finally construct an \\(n\\times n\\) orthogonal eigenvector matrix \n\n\\vspace{2mm}\nFor both cases, we could then normalize the eigenvector matrix.\n\nWe can use these \\(n\\) orthonormal eigenvectors as a basis in the\nlinear space \\(V\\). And present \\(\\hat{\\V{w}}\\) as\n\\(\\sum_{i=1}^n\\alpha_i\\V{p}_i\\) where \\(\\V{p}_i\\) is the eigenvector.\nNow:\n\\begin{equation}\n\\begin{split}\n\\hat{\\V{w}}'\\V{H}\\hat{\\V{w}}\n&=(\\sum_{i=1}^n\\alpha_i\\V{p}_i)'\\V{H}(\\sum_{i=1}^n\\alpha_i\\V{p}_i)\\\\\n&=(\\sum_{i=1}^n\\alpha_i\\V{p}_i)'\\sum_{i=1}^n\n\\alpha_i\\V{H}\\V{p_i}\\\\\n&=(\\sum_{i=1}^n\\alpha_i\\V{p}_i)'\\sum_{i=1}^n\\alpha_i\\lambda_i\\V{p_i}\\\\\n&=\\sum_{i=1}^n\\sum_{j=1}^n\\alpha_i\\alpha_j\\lambda_j\\V{p}_i'\\V{p}_j\\\\\n&=\\sum_{i=1}^n\\alpha_i^2\\lambda_i\\V||{p}_i||^2\\\\\n&=\\sum_{i=1}^n\\lambda_i\\alpha_i^2\n\\end{split}\n\\end{equation}\n\n\\subsection{Numerical Solution -- Finite Difference}\n\\subsubsection{Why central difference is more precise?}\nFor one-side difference, with Taylor expansion:\n\\begin{equation}\nf(x+\\epsilon)=f(x)+\\epsilon f'(x)+o(\\epsilon)\n\\end{equation}\nSo:\n\\begin{equation}\n\\frac{f(x+\\epsilon)-f(x)}{\\epsilon}=f'(x)+o(\\epsilon)\n\\end{equation}\n\nFor central difference, with Taylor expansion:\n\\begin{equation}\n\\begin{split}\n&f(x+\\epsilon)=f(x)+\\epsilon f'(x)+\\epsilon^2\\frac{f''(x)}{2!}\n+o(\\epsilon^2)\\\\\n&f(x-\\epsilon)=f(x)-\\epsilon f'(x)+\\epsilon^2\\frac{f''(x)}{2!}\n+o(\\epsilon^2)\n\\end{split}\n\\end{equation}\nTherefore:\n\\begin{equation}\n\\begin{split}\n&f(x+\\epsilon)-f(x-\\epsilon)=2\\epsilon f'(x)+o(\\epsilon^2)\\\\\n&\\implies \\frac{f(x+\\epsilon)-f(x-\\epsilon)}{2\\epsilon}=f'(x)+o(\\epsilon^2)\n\\end{split}\n\\end{equation}\n\n\\end{document}\n", "meta": {"hexsha": "9f99878b08f917675896bcffccac7e4cbf78b06c", "size": 13000, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ml.tex", "max_stars_repo_name": "a1trl9/stle", "max_stars_repo_head_hexsha": "f6d58624bb9d7dabed13cf6e2ed01de598ef7426", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ml.tex", "max_issues_repo_name": "a1trl9/stle", "max_issues_repo_head_hexsha": "f6d58624bb9d7dabed13cf6e2ed01de598ef7426", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ml.tex", "max_forks_repo_name": "a1trl9/stle", "max_forks_repo_head_hexsha": "f6d58624bb9d7dabed13cf6e2ed01de598ef7426", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.4009661836, "max_line_length": 126, "alphanum_fraction": 0.6377692308, "num_tokens": 5536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587667, "lm_q2_score": 0.8740772318846386, "lm_q1q2_score": 0.7429404623660272}}
{"text": "% !TeX spellcheck = en_US\n\\subsection{Direct encoding}\nAs the name suggests, the direct encoding assign for each CSP variable $x$ and for each possible value from its domain $i$ a new propositional variable $x_i$ on the SAT side. The boolean variable is then True if and only if the original variable is assigned the value $i$.  To ensure consistent logical assignment for each propositional variable, we need to extend the SAT problem to include clauses that avoid inconsistent results such as assigning a CSP variable two values at the same time or no value at all (at-least-once and at-most-once clauses) \\cite{petke2011order}.\n\n\\subsubsection{Example}\nConsider the following instance of the map coloring problem:\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.5\\linewidth]{assets/map_coloring_unsolved}\n\t\\captionsetup{justification=centering,margin=2cm}\n\t\\caption{Unsolved instance of the map coloring problem}\n\t\\label{fig:map_coloring_unsolved}\n\\end{figure}  \nThe map consists of four regions $A,B,C,D$ sharing boarder as shown in the figure \\ref{fig:map_coloring_unsolved}. The purpose of this problem is to color each region of the map so that no two adjacent regions have the same color. The variables in this case are the regions themselves $\\{A,B,C,D\\}$ and each of them has the domain $\\{r,g,b\\}$ which stands for the colors red, green and blue respectively. To fully define the CSP we also need to define the constraints' set which comprise two types of constraints: \n\\begin{itemize}\n\t\\item unary constraints such as $A\\neq r$ since $A$ is already adjacent to a red colored region \n\t\\item binary constraints such as $A\\neq B, A\\neq C,\\dots$ i.e. no two adjacent regions share the same color\n\\end{itemize}\nHereafter, the unary constraints are avoided by restricting the domain of $A$ and $D$ to not include red; on the other hand, it should be noted that usually all the variables are given the same domain to simplify the problem.\n\nEncoding this problem directly will result in the following SAT instance:\na new propositional variable is associated with each value that can be assigned to a CSP variable. So we get the variables: $\\{ A_g, A_b, B_r, B_g,\\\\ B_b, \\dots\\}$. To ensure that each CSP variable will be assigned at least one color, we have to include the following at-least-once (ALO) clauses: $\\{ A_g \\vee A_b, B_g \\vee B_r \\vee B_b, \\dots \\}$. Similarly, we must ensure that no CSP variable is assigned multiple colors at the same time, which can be expressed as these at-most-once (AMO) clauses: $\\{ A_g \\oplus A_b, B_g \\oplus B_r, B_g \\oplus B_b, B_r \\oplus B_b, \\dots \\} $, where $\\oplus$ stands for the logical exclusive or operation $a \\oplus b \\equiv (a \\wedge \\neg b) \\vee (\\neg a \\wedge b) \\equiv (a \\vee b) \\wedge \\neg (a \\wedge b)$.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.75\\linewidth]{assets/alo_amo}\n\t\\captionsetup{justification=centering,margin=2cm}\n\t\\caption{Both types of clauses in direct encoded SAT}\n\t\\label{fig:alo_amo}\n\\end{figure}  \nALO and AMO clauses will enforce each CSP variable to be true only for one value from its domain, hence the name exactly-once (EO) clauses.\n\nWe still need to encode the binary constraints from CSP into some sort of clauses in SAT. This can be done easily by ensuring that no two CSP variables such as $C$ and $B$ share the same color, which can be translated into the following clauses:\n$$\n\t\\neg (C_r \\wedge B_r) \\quad, \\neg (C_g \\wedge B_g) \\quad, \\neg (C_b \\wedge B_b)\n$$\nThe same principle applies for the reset.\n%\\textcolor{red}{TODO: add a word about the similar support encoding (since both are sparse encodings)}\n\nThe direct encoding can be categorized under a general type called the sparse encoding. Notice that the direct encoding encodes conflict points (so called conflict or no-good) assignments such as $A$ and $B$ can't share the same color at the same time $\\neg (A_c \\wedge B_c) \\equiv \\neg A_c \\vee \\neg B_c$. It is also possible to encode the allowed (so called supports) assignments, e.g. $\\neg A_c \\vee B_c \\vee C_c \\vee D_c$. This type of clauses is the basis for the other type of sparse encoding called accordingly the support encoding \\cite{petke2011order}.\n\n\\subsubsection{Proposition}\nSolving the CSP problem directly with FC compared to the direct encoded SAT instance of the same CSP problem solved with DPLL will always result in similar search tree structure. i.e. FC on the original CSP problem and DPLL on the direct encoded SAT will explore the same number of branches. This proposition assumes equivalent branching heuristics for DPLL and FC.\n\n\\subsubsection{Proof idea}\\label{subsec:direct_encoding_proof}\nConsidering the generated search tree, our version of DPLL comprise only two rules: the one literal and the branching rule. This means at each node in the tree we either have to branch or the given variable must be assigned a truth value of either False or True. \n\nOn the FC side branching is equivalent to its counterpart in DPLL. The second case in DPLL (unit propagation by the one literal rule) is also equivalent to applying forward checking by enforcing arc consistency and reducing the domain of each CSP variable to one value only.\n\nSimilarly, we can trace the whole structure of both trees and process with the same logic on each propositional variable. By induction, we can prove that each algorithm explore the same number of branches \\cite{walsh2000sat}. \n\n\\subsubsection{Example}\nCompare the following search trees of FC applied to the previous map coloring problem and DPLL applied to direct encoded instance of the same previous map-coloring problem:\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=1\\linewidth]{assets/direct_fc_vs_dpll}\n\t\\captionsetup{justification=centering,margin=2cm}\n\t\\caption{Search trees of FC and DPLL}\n\t\\label{fig:direct_fc_vs_dpll}\n\\end{figure} \nThe arrows in node level on the FC side indicates enforcing arc consistency and the results are show directly underneath on the next line.\n\n\n\n", "meta": {"hexsha": "b715789d122dfe6c89b1cdff161e47b90f06b896", "size": 5983, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "direct_encoding.tex", "max_stars_repo_name": "mazenbesher/csp_and_sat", "max_stars_repo_head_hexsha": "ba73dda02acc2ecfc66a66530e54e3940b82384d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "direct_encoding.tex", "max_issues_repo_name": "mazenbesher/csp_and_sat", "max_issues_repo_head_hexsha": "ba73dda02acc2ecfc66a66530e54e3940b82384d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "direct_encoding.tex", "max_forks_repo_name": "mazenbesher/csp_and_sat", "max_forks_repo_head_hexsha": "ba73dda02acc2ecfc66a66530e54e3940b82384d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 93.484375, "max_line_length": 747, "alphanum_fraction": 0.7773692128, "num_tokens": 1507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7429404540614254}}
{"text": "%!TEX root =  ../main.tex\n\n\\objective{Compose and cecompose sums of power functions}\n\n\\subsection{Curvilinear Asymptotes}\nWe said last section that a rational function where the degree of the numerator is greater than\nthe degree of the denominator will have an asymptote defined by the quotient of the two,\nignoring the remainder.  Let us see an example.\n\n$$\nf(x)=\\frac{(x+1)(x-2)(x-5)(x+5)}{(x-1)(x+2)}\n$$\n\nWe can see that the first and last terms of the top will be $x^4 \\dots +50$.  The bottom \nmultiplies out to$x^2+x-2$.  The first two and the last two pairs in the numerator are easy \nto multiply: $(x^2-x-2)(x^2-25)$.  While a bit tortuous, multiply two trinomials is certainly\nthe easiest way to find the numerator, and it is $x^4-x^3-27x^2+25x+50$.  We can now find\nthe curvilinear asymptote.\n\n\\polylongdiv{x^4-x^3-27x^2+25x+50}{x^2+x-2}\n\nThe asymptote is a parabola!  It opens upward, has a $y$-intercept of -23 and a centerline \nat $x=1$.\n\n\\begin{figure}\n\\begin{centering}\n\\includegraphics[width=\\textwidth]{\\chapdir/pics/curvilinear}\n\\caption{A function with a parabolic asymptote}\n\\end{centering}\n\\end{figure}\n\n\\subsection{Partial Fraction Decomposition}\nCalculus is not concerned what the function does everywhere: we have the function itself\nfor that.  Calculus is satisfied local behavior, what a function does nearer and near to\ncertain places.  The curved asymptote we just found is more and more right, the larger \n(positive or negative) a number we plug into it.  We know how to find lines that behave\nlive the function almost any other point on the graph: tangent lines with a slope from\nthe derivative.  For example, at (5,0), the behavior can be modeled with \n$y-0 = \\frac{47}{5}(x-5)$.  But what about around the asymptotes, at 1 and -2?  That is\nwhere we bring back the ``remainder'' from the polynomial long division.\n\n$\\frac{44x+4}{x^2+x-2}$ is the non-asymptote part of the quotient, which we know is \ncomposed of $(x-1)(x+2)$ in the denominator.  Is there some way to rip it apart, into\ntwo fractions, one with a denominator of (x-1) and another with (x+2)?  Let us suppose\nthere is, and that each fraction has a simple constant in the numerator.  That would\nmean we are hypothesizing\n\n$$\n\\frac{A}{x-1} + \\frac{B}{x+2} = \\frac{44x+4}{x^2+x-2}\n$$\n\nwhere $A$ and $B$ are plain numbers.  We can begin to figure out what they are by\n``clearing the fraction'', multiplying by $x^2+x-2$ on both sides.  By factoring and canceling,\nwe get\n\n$$\nA(x+2) + B(x-1) = 44x + 4\n$$\n\nIf we distribute and group for like terms, we get\n\n$$\n(A+B)x + (2A-B) = 44x + 4\n$$\n\nNow we already said $A$ and $B$ are numbers, so if we have $A+B x$'s on the left,\nthen $A+B$ must equal 44, and $2A-B$ must equal 4.  We can either add these two \nequations, or use a matrix and find that $A=16$ and $B=28$.  This means $\\frac{16}{x-1}\n+ \\frac{28}{x+2} = \\frac{44x+4}{x^2+x-2}$.\n\nAdditionally, we have decomposed the fraction into its partial fraction components,\na fancy way of saying we made it easy to integrate.  This assume that you know that\n$\\int \\frac{1}{x} = \\ln{|x|}$, which we will not prove until chapter 8.\n\nIn the vicinity of $x=1$, $\\frac{16}{x-1}$ is a good model, and in the vicinity of $x=-2$,\n$\\frac{28}{x-2}$ is a good model of $f(x)$.\n\n\n\\subsection{Sums of Power Functions}\nFinally, everything we have learned up until this point is also good for sums of \npower function that do not obey the definition of polynomials and rational functions.\nFor example, suppose you wanted to make a doorway modeled by the equation\n$h(x) = \\sqrt[3]{(x+4)^2}+\\sqrt[3]{(x-4)^2}$ from -4 to 4.  If you had to program a \nmachine lathe to make the curved top, what would its slope be at every point\non the interval?\n\nWe will need both the integral and the derivative of the function, but fortunately\nit is the Power Rule all around.  $h'(x) = \\frac{2}{3\\sqrt[3]{x+4}}+\\frac{2}{3\\sqrt[3]{x-4}}$\nand $H(x) = \\frac{3}{5}\\sqrt[3]{(x+4)^5}+\\frac{3}{5}\\sqrt[3]{(x-4)^5}+C$\n", "meta": {"hexsha": "b27cd10564f03f8ac44e6927defcd92a7730937f", "size": 3961, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch06/0605.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch06/0605.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch06/0605.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.0111111111, "max_line_length": 95, "alphanum_fraction": 0.7101741984, "num_tokens": 1262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7429404529939438}}
{"text": "\\section{Use of List comprehensions}\n\n\\begin{lstlisting}[language=Haskell]\ntoBeImplemented = undefined\n\n-- the type for values\ntype Value = Double\n-- the type for matrices\ntype Matrix = [[Value]]\n\n-- We represent matrices as lists of lists, where each inner list represents a row\n-- (rather than a column) of the matrix.\n-- Example:\n-- [[a11, a12, a13],\n--  [a21, a22, a23]]\n-- Indexing, as often done in matrix computations, starts with 1 rather than 0 (beg Dijkstra's forgiveness).\n\n-- We assume as precondition for most of the following functions that all inner lists\n-- have the same length (if there are any). Here is a function that might be used to check this condition.\n\nexaIsMat =\n  isMat [[1, 2], [3, 4]] &&\n  isMat [[1, 2]] &&\n  isMat [] &&\n  isMat [[], []] &&\n  not (isMat [[1, 2], []])\n\nisMat :: Matrix -> Bool\nisMat [] = True\nisMat (row1 : rows) =\n  and [length row == lengthRow1 | row <- rows]\n  where lengthRow1 = length row1\n\n-- Sometimes we use square matrices. Here is a function that might be used to check whether a list of lists represents a square matrix.\nexaIsSquareMat =\n  isSquareMat [[1, 2], [3, 4]] &&\n  isSquareMat [[1]] &&\n  isSquareMat [] &&\n  not (isSquareMat [[]]) &&\n  not (isSquareMat [[1, 2, 3], [4, 5, 6]])\n\nisSquareMat = isSquareMatV2\n\nisSquareMatV1 :: Matrix -> Bool\nisSquareMatV1 [] = True\nisSquareMatV1 mat@(row1 : _) = -- example of an as-pattern\n  isMat mat && length mat == length row1\n\nisSquareMatV2 :: Matrix -> Bool\nisSquareMatV2 [] = True\nisSquareMatV2 mat =\n  isMat mat && length mat == length (head mat)\n\n-- zeroMat generates an m * n zero matrix, that is, a matrix with all entries 0.\nexaZeroMat =\n  zeroMat 2 3 == [[0, 0, 0], [0, 0, 0]]\n\nzeroMat :: Int -> Int -> Matrix\nzeroMat a b = [[0 | _ <- [1..b]] | _ <- [1..a]]\n\n-- Check whether a list of lists represents a zero matrix or not.\nisZeroMatV1 :: Matrix -> Bool\nisZeroMatV1 mat =\n  isMat mat && and [a == 0 | row <- mat, a <- row]\n\nisZeroMatV2 :: Matrix -> Bool\nisZeroMatV2 mat =\n  isMat mat && and [a == 0 | a <- concat mat]\n\n-- unitMat generates an n * n unit matrix, that is, a square matrix in which all entries are zero, except of the elements on the main diagonal, which are 1.\nexaUnitMat =\n  unitMatV1 3 == [[1, 0, 0], [0, 1, 0], [0, 0, 1]] &&\n  unitMatV2 3 == [[1, 0, 0], [0, 1, 0], [0, 0, 1]]\n\nunitMat = unitMatV1\n\nunitMatV1 :: Int -> Matrix\nunitMatV1 n = [unitRow n x | x <- [1..n]]\n  where unitRow a b = [if y == b then 1 else 0 | y <- [1..a]]\n\nunitMatV2 :: Int -> Matrix\nunitMatV2 n = [unitRow i | i <- [1 .. n]]\n  where\n    unitRow i = [0 | _ <- [1 .. i-1]] ++ 1 : [0 | _ <- [i+1 .. n]]\n\n-- Check whether two matrices are equal of not.\nequalMat :: Matrix -> Matrix -> Bool\nequalMat = (==)\n\n-- Check whether a list of lists represents a unit matrix or not.\nisUnitMat :: Matrix -> Bool\nisUnitMat mat = mat == unitMat (length mat)\n\n-- neg negates a matrix, that is,\n-- negates all corresponding components of it.\nexaNeg =\n  neg [[1, -2], [0, 4]] == [[-1, 2], [0, -4]]\n\nneg :: Matrix -> Matrix\nneg mat = [[-a | a <- row] | row <- mat]\n\n-- plusMat adds two matrices, that is, adds all corresponding components of them. precondition: mat1 and mat2 have the same size\nexaPlusMat =\n  unit3 `plusMat` (neg unit3) == zeroMat 3 3\n    where unit3 = unitMat 3\n\nplusMat = plusMatV1\n\nplusMatV1 :: Matrix -> Matrix -> Matrix\nmat1 `plusMatV1` mat2 = \n    [row1 `plusRow` row2 | (row1, row2) <- zip mat1 mat2]\n  where\n    row1 `plusRow` row2 = [a1 + a2 | (a1, a2) <- zip row1 row2]\n\nplusMatV2 :: Matrix -> Matrix -> Matrix\nmat1 `plusMatV2` mat2 = [zipWith (+) row1 row2 | (row1, row2) <- zip mat1 mat2]\n\n-- Reads the element in row i and column j of matrix mat.\n-- precondition: i and j are in range of mat\nreadMat :: Matrix -> Int -> Int -> Value\nreadMat mat i j = (mat !! i) !! j\n\n-- updateMat 'updates' matrix mat.\n-- The updated matrix is the same as mat, except of\n-- position row i column j, where the new value is val.\n-- Note: there is no imperative update; the function returns a new matrix.\n-- precondition: i and j are in range of mat\nexaUpdateMat =\n  updateMat (unitMat 3) 3 1 5 == [[1,0,0],[0,1,0],[5,0,1]]\n\nupdateMat :: Matrix -> Int -> Int -> Value -> Matrix\nupdateMat mat i j val =\n  [if i' == i then updateRow row j else row | (i', row) <- zip [1 ..] mat]\n    where\n      updateRow row j =\n        [if j' == j then val else val' | (j', val') <- zip [1 ..] row]\n\n\\end{lstlisting}\n\n\\clearpage", "meta": {"hexsha": "315344fc65fc88f508461dd5783b02d9cac1fdb8", "size": 4407, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TSM_AdvPrPa/Excercises/Haskell/05_MatrixManipulations.tex", "max_stars_repo_name": "nortismo/mse-documentations", "max_stars_repo_head_hexsha": "cc67637785237d630f077a863edcd5f49aa52b59", "max_stars_repo_licenses": ["Beerware"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "TSM_AdvPrPa/Excercises/Haskell/05_MatrixManipulations.tex", "max_issues_repo_name": "nortismo/mse-documentations", "max_issues_repo_head_hexsha": "cc67637785237d630f077a863edcd5f49aa52b59", "max_issues_repo_licenses": ["Beerware"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TSM_AdvPrPa/Excercises/Haskell/05_MatrixManipulations.tex", "max_forks_repo_name": "nortismo/mse-documentations", "max_forks_repo_head_hexsha": "cc67637785237d630f077a863edcd5f49aa52b59", "max_forks_repo_licenses": ["Beerware"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-15T07:10:24.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-15T07:10:24.000Z", "avg_line_length": 31.4785714286, "max_line_length": 156, "alphanum_fraction": 0.6346721125, "num_tokens": 1456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8962513786759491, "lm_q1q2_score": 0.7429375497960671}}
{"text": "\\documentclass{article}\n\\usepackage{latexsym}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage{amsthm}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem*{problem}{Problem}\n\n\\begin{document}\n\n\\title{Some functional equations}\n\\author{Dave Neary}\n\n\\maketitle\n\n\\section{2001 Dutch IMO qualification}\n\nSuppose for all $x,y \\in \\mathbb{R}$ that we have:\n\\[ f(x + y) = f(x) + f(y) + xy \\]\nand $f(4) = 10$. Find $f(2001)$.\n\nSetting $x=y=2$:\n\\[ f(4) = 10 = 2f(2) + 4 \\implies f(2) = 3\\]\n\nSetting $x=y=1$:\n\\[ f(2) = 3 = 2f(r12) + 1 \\implies f(1) = 1\\]\n\nSetting $y=0$:\n\\[ f(x) = f(x) + f(0) \\implies f(0) = 0 \\]\n\nFinally, setting $y=1$:\n\\[ f(x+1) = f(x) + f(1) + x \\]\n\nThis is already enough for us to calculate $f(n)$ for all positive integers:\n\\begin{align}\n\tf(n) - f(n-1) & = n \\\\\n\t& \\vdots \\\\\n\tf(1)-f(0) &= 1\n\\end{align}\nAdding LHS and RHS we get:\n\\[ f(n) = \\sum_{i=1}^{n} i = \\frac{1}{2}(n)(n+1) \\]\n\nand $f(2001) = 2003001$.\n\nWe can easily extend to show that the formula applies to negative integers:\n\\[f(n + (-n)) f(0) = 0 = f(n) + f(-n) - n^2 \\]\n\\[ \\implies f(-n) = n^2 - \\frac{1}{2}(n)(n+1) = n^2 - \\frac{n^2}{2} - \\frac{n}{2} \\]\n\\[ \\implies f(-n) = \\frac{1}{2}(-n)(-n+1) \\]\n\n\nThe question remains, however: what class of functions satisfies the functional relationship in\ngeneral, outside of integers?\n\nSince $f(nx) = f((n-1)x) + f(x) + (n-1)x^2$, we can show by simple iteration that:\n\\[ f(nx) = nf(x) + x^2((n-1)+(n-2)+\\cdots + 1) = nf(x) + \\frac{(n)(n-1)}{2} x^2 \\]\n\nFrom above, we know that $f(n) = \\frac{1}{2}(n)(n+1)$ for $n\\in \\mathbb{Z}$, so\nfor $x=\\frac{1}{m}, n=m, m \\in \\mathbb{Z}/{0}$:\n\\begin{align}\n\tf(1) &= f(m\\times\\frac{1}{m}) \\\\\n\t     &= mf(\\frac{1}{m}) + \\frac{m^2-m}{2m^2} \\\\\n\t     &= 1 \\\\\n\tf(\\frac{1}{m}) &= \\frac{1}{m}(1- \\frac{1}{2}(1-\\frac{1}{m})) \\\\\n\t               &= \\frac{1}{2}(\\frac{1}{m})(\\frac{1}{m} + 1)\n\\end{align}\n\nWe can now generalize to all rational numbers:\n\\begin{align}\n\tf(\\frac{n}{m}) &= nf(\\frac{1}{m}) + \\frac{n^2-n}{2m^2} \\\\\n\t& = \\frac{n}{2}(\\frac{1}{m})(\\frac{1}{m} + 1) + \\frac{1}{2}((\\frac{n}{m})^2-\\frac{n}{m^2}) \\\\\n\t& = \\frac{1}{2}(\\frac{n}{m})(\\frac{n}{m} + 1)\n\\end{align}\n\nBut does this mean that $f(x) = \\frac{1}{2}(x)(x+1)$ for all $x\\in \\mathbb{R}$? Bizarrely enough,\nthe answer is no. However, if $f(x)$ is defined to be continuous, then this is true. To see this,\nlet's consider an arbitrary irrational number $x$. We can define a sequence of rational numbers \n$\\{a_n\\}$ with $10^nx > 10^n a_n > 10^n x - 1$ for all $n$ by defining \n$a_n = \\frac{1}{10^n}\\lfloor 10^nx \\rfloor$. This set of rational numbers will converge to $x$, and the\nset $\\{f(a_n)\\} = \\{\\frac{1}{2}(a_n)(a_n+1)\\}$ also converges to $f(x) = \\frac{1}{2}(a_n)(a_n+1)$\nif $f$ is continuous.\n\nHowever, if $f$ is not continuous, we can construct infinitely many $f(x)$ which satisfy the\nconditions. For any irrational number, we can arbitrarily define $f(x) = c$, and then\n\\[ f(qx) &= qc + \\frac{1}{2}(q)(q-1)(x^2) \\]\n\nAnd since $qx$ will never be a rational number, this is linearly independent to the rational\nnumbers we already have above.\n\n\\end{document}\n", "meta": {"hexsha": "065e7fce40887beee23e46aea6aee08cd85510c2", "size": 3107, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "functional_equations.tex", "max_stars_repo_name": "dneary/math", "max_stars_repo_head_hexsha": "129b2093c01b12ddc2e61abd331c95da2177803c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "functional_equations.tex", "max_issues_repo_name": "dneary/math", "max_issues_repo_head_hexsha": "129b2093c01b12ddc2e61abd331c95da2177803c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "functional_equations.tex", "max_forks_repo_name": "dneary/math", "max_forks_repo_head_hexsha": "129b2093c01b12ddc2e61abd331c95da2177803c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7717391304, "max_line_length": 103, "alphanum_fraction": 0.5889925974, "num_tokens": 1249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732856, "lm_q2_score": 0.9086178938396674, "lm_q1q2_score": 0.7428628147710387}}
{"text": "\\section*{Sparse Coding}\n\\subsection*{Orthogonal Basis}\nTransform: For $\\mathbf{x}$ and orthog. mat. $\\mathbf{U}$ compute $\\mathbf{z} = \\mathbf{U}^\\top \\mathbf{x} $. For compression, can drop small values: $ \\mathbf{\\hat{x}} = \\mathbf{U\\hat{z}}$, $\\hat{z}_i = z_i$ if $ \\lvert z_i \\rvert > \\epsilon$ else 0.\nPros: fast inverse; preserves energy. \nor $\\mathbf{x}$ and orthog. mat. $\\mathbf{U}$ compute $\\mathbf{z} = \\mathbf{U}^\\top \\mathbf{x} $ else 0.\nReconstr. Error $\\|\\mathbf{x}-\\mathbf{\\hat{x}}\\|^2 = \\sum_{d\\notin\\sigma}\\langle\\mathbf{x},\\mathbf{u}_d\\rangle ^2$ for a subset of basis $\\sigma$.\\\\\n\\textbf{Haar Wavelets:} scaling function $\\phi(x)=[1,1,1,1]$, mother $W(x)=[1,1,-1,-1]$, dilated $W(2x)=[1,-1,0,0]$, translated $W(2x-1)=[0,0,1,-1]$. Do not forget to normalize.\\\\\n\\textbf{Comparison to Fourier basis:} local (not global) support, good for localized (not $\\sin$ like, repeating) signals.\n\\textbf{PCA basis:} data-dependent, but optimal for given $\\Sigma$. $\\mathbf{\\hat x} = \\mathbf{U}_K \\mathbf{z}_{[1:K]} $\n\\subsection*{Overcomplete Dictionaries}\nUse more atoms than dimensions, then choose the best representation. (e.g.Gabor wavelets use Fourier like features in a localized Gaussian window). \\\\ Linear dependency measure:  \\textbf{Coherence}\\\\\n\\begin{inparaitem}[\\color{gray}\\textbullet]\n\t\\item $m(\\mathbf{U}) = \\max_{i,j:\\, i \\neq j} | \\mathbf{u}_i^\\top \\mathbf{u}_j |$\n\t\\item $m(\\mathbf{B}) = 0$ if $\\mathbf{B}$ orth. mat.\n\t\\item $m([\\mathbf{B}, \\mathbf{u}]) \\geq \\frac{1}{\\sqrt{D}}$ if atom $\\mathbf{u}$ is added to $\\mathbf{B}$\n\\end{inparaitem}\\\\\n\\textbf{Signal Reconstruction:} orthonormal: $\\mathbf{x} = \\mathbf{Uz}$, spanning basis (linearly independent): $\\mathbf{x} = (\\mathbf{U}^T)^{-1}\\mathbf{z}$ (can be ill-conditioned), overcomplete: solve $\\mathbf{z}^* \\in \\argmin_\\mathbf{z} ||\\mathbf{z}||_0$ s.t. $\\mathbf{x}=\\mathbf{Uz}$. (NP hard). Can convexify with $L_1$ norm or greedy approx.: \\\\\n\\textbf{Matching Pursuit (MP)}\n\\begin{inparaenum}[\\color{gray}1.]\n\t\\item init: $\\hat z \\leftarrow 0, r \\leftarrow x$\n\t\\item while $\\|\\mathbf{z}\\|_0 < K$ do\n\t\\item select atom with smallest angle $j^* = \\argmax_j |\\langle \\mathbf{u}_j, \\mathbf{r} \\rangle|$\n\t\\item update coefficients: $\\hat z\\leftarrow \\hat z + \\langle \\mathbf{u}_{i^\\star}, \\mathbf{r} \\rangle \\mathbf{u_{j^*}}$\n\t\\item update residual: $\\mathbf{r} \\leftarrow \\mathbf{r} - \\langle \\mathbf{u}_{i^\\star}, \\mathbf{r} \\rangle \\mathbf{u}_{i^\\star}$.\n\\end{inparaenum}\n\\textbf{Exact recovery} when: $K<1/2( 1+1/m(\\mathbf{U}))$ \\\\\n\\textbf{Instance when MP never exactly match x}: Idea: if we always just half residual and start with a pos. number, we will never arrive at $0$. Start with (0,1). u1 = (1,0) u2 = ($\\sqrt 2$/2, $\\sqrt 2$/2), u3 = ($\\sqrt 3$/2, 1/2). \\\\\n\\textbf{Instance where MP does not have best solution:} u1 = (1,0), u2 = (0,1), u3 = (sqrt(2)/2, sqrt(2)/2). x = (2,1), will have largest correlation with u3, but residual then cannot be expressed with only u1 or u2, so we will use all 3 vectors instead of only u1 \\& u2.\n\\subsection*{Compressive Sensing}\nAquire set $\\mathbf{y}$ of $M$ linear combinations of signal, then reconstruct from it. $y_k = \\langle \\mathbf{w}_k, \\mathbf{x} \\rangle, k=1,...,M $\n$\\mathbf{y}=\\mathbf{Wx}=\\mathbf{WUz} =: \\Theta\\mathbf{z}$ with $\\Theta = \\mathbf{WU} \\in \\mathbb{R}^{M\\times D}$.\nAny orthonormal basis $\\mathbf{U}$ can obtain a stable reconstr. for any $K$-sparse compressible signal if: \\begin{inparaitem}[\\color{gray}\\textbullet]\n\\item $\\mathbf{W}$ is Gaussian random projection, i.e. $w_{ij}\\sim \\mathcal{N}(0,\\frac{1}{D})$\n\\item $M\\geq cK \\log \\frac{D}{K}$(some constant $c$).\n\\end{inparaitem}\nReconstruct as before: $\\mathbf{z}^\\star \\in \\argmin_{\\mathbf{z}}\\|\\mathbf{z}\\|_0$, s.t. $\\mathbf{y} = \\Theta\\mathbf{z}$ ", "meta": {"hexsha": "62de421edc78a2f37450146d3e2549cbf88afced", "size": 3756, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SparseCoding.tex", "max_stars_repo_name": "anklinv/Computational-Intelligence-Lab-ETH-FS19", "max_stars_repo_head_hexsha": "2ef62f626fa83d1410fbb1b2f8a0501937c0dabe", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-20T20:58:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-20T20:58:16.000Z", "max_issues_repo_path": "SparseCoding.tex", "max_issues_repo_name": "anklinv/Computational-Intelligence-Lab-ETH-FS19", "max_issues_repo_head_hexsha": "2ef62f626fa83d1410fbb1b2f8a0501937c0dabe", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SparseCoding.tex", "max_forks_repo_name": "anklinv/Computational-Intelligence-Lab-ETH-FS19", "max_forks_repo_head_hexsha": "2ef62f626fa83d1410fbb1b2f8a0501937c0dabe", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-06T16:55:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-21T01:02:09.000Z", "avg_line_length": 104.3333333333, "max_line_length": 351, "alphanum_fraction": 0.6645367412, "num_tokens": 1418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7428504159355322}}
{"text": "\\section{Improper Integrals}\r\nNow that we've developed the tools to deal with limits as they approach infinity and the possible indeterminate forms that may arise, we can apply these ideas to integrals, allowing us to have $-\\infty$ and $\\infty$ as limits of integration.\r\nWe call these integrals with $\\pm\\infty$ as limits of integration, and functions that become $\\pm\\infty$ somewhere within the interval we're integrating on improper integrals.\r\n\r\n\\subsection{Infinite Integration Limits}\r\n\\begin{definition}\r\n\tIf $f$ is continuous on $[a,\\infty)$, then\r\n\t\\begin{equation*}\r\n\t\t\\int_{a}^{\\infty}{f(x)\\d{x}} = \\lim_{b\\to\\infty}{\\int_{a}^{b}{f(x)\\d{x}}}.\r\n\t\\end{equation*}\r\n\tIf $f$ is continuous on $(-\\infty,b]$, then\r\n\t\\begin{equation*}\r\n\t\t\\int_{\\infty}^{b}{f(x)\\d{x}} = \\lim_{a\\to-\\infty}{\\int_{a}^{b}{f(x)\\d{x}}}.\r\n\t\\end{equation*}\r\n\tIf $f$ is continuous on $(-\\infty,\\infty)$, then\r\n\t\\begin{equation*}\r\n\t\t\\int_{-\\infty}^{\\infty}{f(x)\\d{x}} = \\int_{-\\infty}^{c}{f(x)\\d{x}} + \\int_{c}^{\\infty}{f(x)\\d{x}}\r\n\t\\end{equation*}\r\n\tfor any real constant $c$.\r\n\tIf these limits exist, then the integral converges and has a value.\r\n\tOtherwise, the integral diverges and does not have a value.\r\n\\end{definition}\r\n\r\n\\begin{example}\r\n\tEvaluate the following integral or state that it diverges.\r\n\t\\begin{equation*}\r\n\t\t\\int_{2}^{\\infty}{\\frac{3}{x^2-x}\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tApplying the definition,\r\n\t\\begin{align*}\r\n\t\t\\int_{2}^{\\infty}{\\frac{3}{x^2-x}\\d{x}} &= \\lim_{b\\to\\infty}{\\int_{2}^{b}{\\frac{3}{x^2-x}\\d{x}}} \\\\\r\n\t\t&= \\lim_{b\\to\\infty}{3\\int_{2}^{b}{\\left(\\frac{1}{x-1}-\\frac{1}{x}\\right)\\d{x}}} \\\\\r\n\t\t&= \\lim_{b\\to\\infty}{3\\ln{\\bigg\\lvert\\frac{x-1}{x}\\bigg\\rvert}\\Biggr\\rvert_{2}^{b}} \\\\\r\n\t\t&= \\lim_{b\\to\\infty}{3\\ln{\\bigg\\lvert\\frac{b-1}{b}\\bigg\\rvert}} - 3\\ln{\\bigg\\lvert\\frac{1}{2}\\bigg\\rvert} \\\\\r\n\t\t&= 0 + 3\\ln{2} \\\\\r\n\t\t&= 3\\ln{2}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tEvaluate the following integral or state that it diverges.\r\n\t\\begin{equation*}\r\n\t\t\\int_{1}^{\\infty}{\\frac{\\d{x}}{\\sqrt[4]{x}}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tApplying the definition,\r\n\t\\begin{align*}\r\n\t\t\\int_{1}^{\\infty}{\\frac{\\d{x}}{\\sqrt[4]{x}}} &= \\lim_{b\\to\\infty}{\\int_{1}^{b}{\\frac{\\d{x}}{\\sqrt[4]{x}}}} \\\\\r\n\t\t&= \\lim_{b\\to\\infty}{\\frac{4}{3}\\sqrt[4]{x^3}\\biggr\\rvert_{1}^{b}} \\\\\r\n\t\t&= \\lim_{b\\to\\infty}{\\frac{4}{3}\\sqrt[4]{b^3}} - \\frac{4}{3}\\sqrt[4]{1^3} \\\\\r\n\t\t&= \\infty - \\frac{4}{3} \\\\\r\n\t\t&= \\text{diverges}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsection{Infinite Discontinuities}\r\nAn infinite discontinuity occurs when a function takes on a value of $\\pm\\infty$ on the interval we're integrating on.\r\nIn this case, we'll need to split the integral into pieces, evaluating the limit as we approach this infinite discontinuity from both sides.\r\n\\begin{definition}\r\n\tIf $f$ is continuous on $(a,b]$, then\r\n\t\\begin{equation*}\r\n\t\t\\int_{a}^{b}{f(x)\\d{x}} = \\lim_{c\\to a^+}{\\int_{c}^{b}{f(x)\\d{x}}}.\r\n\t\\end{equation*}\r\n\tIf $f$ is continuous on $[a,b)$, then\r\n\t\\begin{equation*}\r\n\t\t\\int_{a}^{b}{f(x)\\d{x}} = \\lim_{c\\to b^-}{\\int_{a}^{c}{f(x)\\d{x}}}.\r\n\t\\end{equation*}\r\n\tIf $f$ is continuous on $[a,c) \\cup (c,b]$, then\r\n\t\\begin{equation*}\r\n\t\t\\int_{a}^{b}{f(x)\\d{x}} = \\int_{a}^{c}{f(x)\\d{x}} + \\int_{c}^{b}{f(x)\\d{x}}.\r\n\t\\end{equation*}\r\n\tIf these limits exist, then the integral converges and has a value.\r\n\tOtherwise, the integral diverges and does not have a value.\r\n\\end{definition}\r\n\r\n\\begin{example}\r\n\tEvaluate the following integral or state that it diverges.\r\n\t\\begin{equation*}\r\n\t\t\\int_{0}^{1}{\\frac{\\d{x}}{x^2}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe see that we have an infinite discontinuity at $x=0$.\r\n\tApplying the definition,\r\n\t\\begin{align*}\r\n\t\t\\int_{0}^{1}{\\frac{\\d{x}}{x^2}} &= \\lim_{c\\to 0^+}{\\int_{c}^{1}{\\frac{\\d{x}}{x^2}}} \\\\\r\n\t\t&= \\lim_{c\\to 0^+}{\\frac{-1}{x}\\biggr\\rvert_{c}^{1}} \\\\\r\n\t\t&= \\frac{-1}{1} + \\lim_{c\\to 0^+}{\\frac{1}{c}} \\\\\r\n\t\t&= -1 + \\infty \\\\\r\n\t\t&= \\text{diverges}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tEvaluate the following integral or state that it diverges.\r\n\t\\begin{equation*}\r\n\t\t\\int_{0}^{1}{\\frac{\\d{x}}{x^{1/2}}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe see that we have an infinite discontinuity at $x=0$.\r\n\tApplying the definition,\r\n\t\\begin{align*}\r\n\t\t\\int_{0}^{1}{\\frac{\\d{x}}{x^{1/2}}} &= \\lim_{c\\to 0^+}{\\int_{c}^{1}{\\frac{\\d{x}}{x^{1/2}}}} \\\\\r\n\t\t&= \\lim_{c\\to 0^+}{2x^{1/2}\\biggr\\rvert_{c}^{1}} \\\\\r\n\t\t&= 2 - \\lim_{c\\to 0^+}{2c^{1/2}} \\\\\r\n\t\t&= 2 - 0 \\\\\r\n\t\t&= 2.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsection{Convergence Tests}\r\n\\subsubsection{P-Test}\r\n\\begin{lemma}\r\n\tThe following integral will converge when $p > 1$ and diverge if $0 < p \\leq 1$.\r\n\t\\begin{equation*}\r\n\t\t\\int_{1}^{\\infty}{\\frac{\\d{x}}{x^p}}.\r\n\t\\end{equation*}\r\n\\end{lemma}\r\n\r\n\\begin{example}\r\n\tEvaluate the following integral or state that it diverges.\r\n\t\\begin{equation*}\r\n\t\t\\int_{1}^{\\infty}{\\frac{\\d{x}}{x}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe have an integral where $p=1$.\r\n\tSo, by the P-Test, the integral diverges.\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tEvaluate the following integral or state that it diverges.\r\n\t\\begin{equation*}\r\n\t\t\\int_{1}^{\\infty}{\\frac{\\d{x}}{x^{1.001}}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe have an integral where $p=1.001$.\r\n\tSo, by the P-Test, the integral converges.\r\n\t\\begin{align*}\r\n\t\t\\int_{1}^{\\infty}{\\frac{\\d{x}}{x^{1.001}}} &= \\lim_{b\\to\\infty}{\\int_{1}^{b}{\\frac{\\d{x}}{x^{1.001}}}} \\\\\r\n\t\t&= \\lim_{b\\to\\infty}{-1000x^{-0.001}\\biggr\\rvert_{1}^{b}} \\\\\r\n\t\t&= \\lim_{b\\to\\infty}{-1000b^{-0.001}} + 1000(1)^{-0.001} \\\\\r\n\t\t&= 0 + 1000 \\\\\r\n\t\t&= 1000.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{Direct Comparison Test}\r\n\\begin{lemma}\r\n\tLet $f$ and $g$ be continuous on $[a,\\infty)$ with $0 \\leq f(x) \\leq g(x)$ for all $x \\geq a$.\r\n\t\\begin{align*}\r\n\t\t\\int_{a}^{\\infty}{f(x)\\d{x}} &\\text{ converges if } \\int_{a}^{\\infty}{g(x)\\d{x}} \\text{ converges.} \\\\\r\n\t\t\\int_{a}^{\\infty}{g(x)\\d{x}} &\\text{ diverges if } \\int_{a}^{\\infty}{f(x)\\d{x}} \\text{ diverges.}\r\n\t\\end{align*}\r\n\\end{lemma}\r\n\r\nThat is, if a larger function converges, then so will a smaller funtion; if a smaller function diverges, then so will a larger function. \\\\\r\n\r\n\r\nThe hardest part of the Direct Comparison Test is deciding what function you should compare to.\r\nA general rule is to pick a function that is similar to, but simpler than then given function.\r\n\r\n\\begin{example}\r\n\tEvaluate the following integral or state that it diverges.\r\n\t\\begin{equation*}\r\n\t\t\\int_{1}^{\\infty}{\\frac{\\d{x}}{x^2-0.1}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tIf the 0.1 wasn't inside the square root, the function would simplify to $1/x$.\r\n\tSince the 0.1 is subtracted, the denominator is smaller than $1/x$.\r\n\tSo, $1/x$ is a function that is smaller on $[1,\\infty)$, meaning if it diverges, then so will the original function.\r\n\tWe know by the P-Test that the integral of $1/x$ from 1 to $\\infty$ will diverge, so the original function also diverges.\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tEvaluate the following integral or state that it diverges.\r\n\t\\begin{equation*}\r\n\t\t\\int_{1}^{\\infty}{e^{-x^2}\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tSince the exponent is negative, a smaller exponent would mean a larger value.\r\n\tSo, $e^{-x}$ is a larger function on $[1,\\infty)$.\r\n\t\\begin{equation*}\r\n\t\t\\int_{1}^{\\infty}{e^{-x}\\d{x}} = \\frac{1}{e},\r\n\t\\end{equation*}\r\n\tmeaning it converges, so the original function also converges.\r\n\\end{answer}\r\n\r\n\\subsubsection{Limit Comparison Test}\r\n\\begin{lemma}\r\n\tIf positive functions $f$ and $g$ are continuous on $[a,\\infty)$ and\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to\\infty}{\\frac{f(x)}{g(x)}}\r\n\t\\end{equation*}\r\n\tconverges to a positive real number, then\r\n\t\\begin{equation*}\r\n\t\t\\int_{a}^{\\infty}{f(x)\\d{x}} \\text { and } \\int_{a}^{\\infty}{g(x)\\d{x}}\r\n\t\\end{equation*}\r\n\tboth converge or both diverge.\r\n\\end{lemma}\r\n\r\n\r\nMany functions to which you can apply the Limit Comparison Test you can also apply the Direct Comparison Test.\r\nThe practical use of the limit comparison test is to take an uglier function, that may be tedious to integrate and compare it to a function that is easy to determine whether it diverges using something like the P-Test.\r\nA common strategy, especially for rational functions, is to look at their end behavior model.\r\n\r\n\\begin{example}\r\n\tEvaluate the following integral or state that it diverges.\r\n\t\\begin{equation*}\r\n\t\t\\int_{1}^{\\infty}{\\frac{\\d{x}}{1+x^2}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tAlthough you might recognize this as the derivative of $\\arctan$, let's continue with the Direct Comparison Test.\r\n\tThis function looks very similar to $1/x^2$, which we know by the P-Test will converge on $[1,\\infty)$.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to\\infty}{\\frac{\\frac{1}{x^2}}{\\frac{1}{1+x^2}}} = \\lim_{x\\to\\infty}{\\frac{1+x^2}{x^2}} = 1.\r\n\t\\end{equation*}\r\n\tSince 1 is a positive real constant and the integral of $1/x^2$ converges, then the original integral also converges by the Limit Comparison Test.\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tEvaluate the following integral or state that it diverges.\r\n\t\\begin{equation*}\r\n\t\t\\int_{1}^{\\infty}{\\frac{3x+6}{1-5x+7x^2}\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tLooking at this rational function, we see a degree 1 polynomial in the numerator and a degree 2 polynomial in the denominator.\r\n\tSo, we'd expect this rational function to have the same end behavior model as $1/x$, which we know by the P-Test diverges.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to\\infty}{\\frac{\\frac{3x+6}{1-5x+7x^2}}{\\frac{1}{x}}} = \\lim_{x\\to\\infty}{\\frac{3x^2+6x}{7x^2-5x+1}} = \\frac{3}{7}.\r\n\t\\end{equation*}\r\n\tSince 3/7 is a positive real constant and the integral of $1/x$ diverges, the the original integral also diverges by the Limit Comparison Test.\r\n\\end{answer}", "meta": {"hexsha": "ecc3e8ec38732d0a18a4e4af1655e79aec660682", "size": 9819, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/sequences_lhopital_improper/improper_integrals.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/sequences_lhopital_improper/improper_integrals.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/sequences_lhopital_improper/improper_integrals.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 40.5743801653, "max_line_length": 242, "alphanum_fraction": 0.6409002953, "num_tokens": 3637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7428504037262128}}
{"text": "\\subsection{Circles}\r\n\\noindent\r\nA circle of radius $R$ centered at the origin can be represented as $r = R$.\\\\\r\nCircles not centered at the origin require using the transformation equations.\r\n\\begin{equation*}\r\n\t(x-a)^2 + (y-b)^2 = R^2 \\implies (r\\cos{\\theta}-a)^2 + (r\\sin{\\theta}-b)^2 = R^2\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\tr^2\\cos^{2}{\\theta} + r^2\\sin^{2}{\\theta} - 2ra\\cos{\\theta} - 2rb\\sin{\\theta} + a^2 + b^2 = R^2\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\tr^2 - 2r(a\\cos{\\theta} + b\\sin{\\theta}) - R^2 + a^2 + b^2 = 0\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\tr = (a\\cos{\\theta} + b\\sin{\\theta}) \\pm \\sqrt{R^2 - a^2 - b^2 + (a\\cos{\\theta} + b\\sin{\\theta})^2}\r\n\\end{equation*}", "meta": {"hexsha": "0511cc6283ad5c3974084ef63c46194ea62b117d", "size": 681, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/curvilinearCoordinates/circles_polar.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/curvilinearCoordinates/circles_polar.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/curvilinearCoordinates/circles_polar.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 42.5625, "max_line_length": 100, "alphanum_fraction": 0.6035242291, "num_tokens": 285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898305367524, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7428150284496488}}
{"text": "\\chapter{Gaussian Models}\n\\label{chap:MVN}\n\nIn this chapter, we discuss the \\textbf{multivariate Gaussian} or \\textbf{multivariate normal(MVN)}, which is the most widely used joint probability density function for continuous variables. It will form the basis for many of the models we will encounter in later chapters.\n\n\n\\section{Basics}\nRecall from Section \\ref{sec:MVN} that the pdf for an MVN in $D$ dimensions is defined by the following:\n\\begin{equation}\n\\mathcal{N}(\\vec{x}|\\vec{\\mu},\\Sigma) \\triangleq \\dfrac{1}{(2\\pi)^{\\frac{D}{2}}|\\Sigma|^{\\frac{1}{2}}}\\exp\\left[-\\dfrac{1}{2}(\\vec{x}-\\vec{\\mu})^T\\Sigma^{-1}(\\vec{x}-\\vec{\\mu})\\right]\n\\end{equation}\n\nThe expression inside the exponent is the Mahalanobis distance between a data vector $\\vec{x}$ and the mean vector $\\vec{\\mu}$, We can gain a better understanding of this quantity by performing an \\textbf{eigendecomposition} of $\\vec{\\Sigma}$. That is, we write $\\vec{\\Sigma}=\\vec{U}\\vec{\\Lambda}\\vec{U}^T$, where $\\vec{U}$ is an orthonormal matrix of eigenvectors satsifying $\\vec{U}^T\\vec{U}=\\vec{I}$, and $\\vec{\\Lambda}$ is a diagonal matrix of eigenvalues. Using the eigendecomposition, we have that\n\\begin{equation}\n\\vec{\\Sigma}^{-1}=\\vec{U}^{-T}\\vec{\\Lambda}^{-1}\\vec{U}^{-1}=\\vec{U}\\vec{\\Lambda}^{-1}\\vec{U}^T=\\sum\\limits_{i=1}^D \\dfrac{1}{\\lambda_i}\\vec{u}_i\\vec{u}_i^T\n\\end{equation}\nwhere $\\vec{u}_i$ is the $i$'th column of $\\vec{U}$, containing the $i$'th eigenvector. Hence we can rewrite the Mahalanobis distance as follows:\n\\begin{align}\n(\\vec{x}-\\vec{\\mu})^T\\Sigma^{-1}(\\vec{x}-\\vec{\\mu}) & =(\\vec{x}-\\vec{\\mu})^T\\left(\\sum\\limits_{i=1}^D \\dfrac{1}{\\lambda_i}\\vec{u}_i\\vec{u}_i^T\\right)(\\vec{x}-\\vec{\\mu}) \\\\\n    & =\\sum\\limits_{i=1}^D \\dfrac{1}{\\lambda_i}(\\vec{x}-\\vec{\\mu})^T\\vec{u}_i\\vec{u}_i^T(\\vec{x}-\\vec{\\mu}) \\\\\n\t& =\\sum\\limits_{i=1}^D \\dfrac{y_i^2}{\\lambda_i}\n\\end{align}\nwhere $y_i \\triangleq \\vec{u}_i^T(\\vec{x}-\\vec{\\mu})$. Recall that the equation for an ellipse in 2d is\n\\begin{equation}\n\\dfrac{y_1^2}{\\lambda_1}+\\dfrac{y_2^2}{\\lambda_2}=1\n\\end{equation}\n\nHence we see that the contours of equal probability density of a Gaussian lie along ellipses. This is illustrated in Figure \\ref{fig:2d-MVN}. The eigenvectors determine the orientation of the ellipse, and the eigenvalues determine how elogonated it is.\n\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.70]{2d-MVN.png}\n\\caption{Visualization of a 2 dimensional Gaussian density. The major and minor axes of the ellipse are defined by the first two eigenvectors of the covariance matrix, namely $\\vec{u}_1$ and $\\vec{u}_2$. Based on Figure 2.7 of (Bishop 2006a)}\n\\label{fig:2d-MVN} \n\\end{figure}\n\nIn general, we see that the Mahalanobis distance corresponds to Euclidean distance in a transformed coordinate system, where we shift by $\\vec{\\mu}$ and rotate by $\\vec{U}$.\n\n\n\\subsection{MLE for a MVN}\n\\begin{theorem}(\\textbf{MLE for a MVN})\nIf we have $N$ iid samples $\\vec{x}_i \\sim \\mathcal{N}(\\vec{\\mu},\\vec{\\Sigma})$, then the MLE for the parameters is given by\n\\begin{align}\n\\bar{\\vec{\\mu}}    & =\\dfrac{1}{N}\\sum\\limits_{i=1}^N \\vec{x}_i \\triangleq \\bar{\\vec{x}} \\\\\n\\bar{\\vec{\\Sigma}} & =\\dfrac{1}{N}\\sum\\limits_{i=1}^N (\\vec{x}_i-\\bar{\\vec{x}})(\\vec{x}_i-\\bar{\\vec{x}})^T \\\\\n                     & =\\dfrac{1}{N}\\left(\\sum\\limits_{i=1}^N \\vec{x}_i\\vec{x}_i^T\\right)-\\bar{\\vec{x}}\\bar{\\vec{x}}^T\n\\end{align}\n\\end{theorem}\n\n\n\\subsection{Maximum entropy derivation of the Gaussian *}\nIn this section, we show that the multivariate Gaussian is the distribution with maximum entropy subject to having a specified mean and covariance (see also Section TODO). This is one reason the Gaussian is so widely used: the first two moments are usually all that we can reliably estimate from data, so we want a distribution that captures these properties, but otherwise makes as few addtional assumptions as possible.\n\nTo simplify notation, we will assume the mean is zero. The pdf has the form\n\\begin{equation}\nf(\\vec{x})=\\dfrac{1}{Z}\\exp\\left(-\\dfrac{1}{2}\\vec{x}^T\\vec{\\Sigma}^{-1}\\vec{x}\\right)\n\\end{equation}\n\n\n\\section{Gaussian discriminant analysis}\nOne important application of MVNs is to define the the class conditional densities in a generative classifier, i.e.,\n\\begin{equation}\np(\\vec{x}|y=c,\\vec{\\theta})=\\mathcal{N}(\\vec{x}|\\vec{\\mu}_c,\\vec{\\Sigma}_c)\n\\end{equation}\n\nThe resulting technique is called (Gaussian) \\textbf{discriminant analysis} or \\textbf{GDA} (even though it is a generative, not discriminative, classifier — see Section TODO for more on this distinction). If $\\vec{\\Sigma}_c$ is diagonal, this is equivalent to naive Bayes.\n\nWe can classify a feature vector using the following decision rule, derived from Equation \\ref{eqn:Generative-classifier}:\n\\begin{equation}\ny=\\arg\\max_{c} \\left[\\log p(y=c|\\vec{\\pi})+\\log p(\\vec{x}|\\vec{\\theta})\\right]\n\\end{equation}\n\nWhen we compute the probability of $\\vec{x}$ under each class conditional density, we are measuring the distance from $\\vec{x}$ to the center of each class, $\\vec{\\mu}_c$, using Mahalanobis distance. This can be thought of as a \\textbf{nearest centroids classifier}.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.70]{2d-Gaussians-Visualization-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.70]{2d-Gaussians-Visualization-b.png}}\n\\caption{(a) Height/weight data. (b) Visualization of 2d Gaussians fit to each class. 95\\% of the probability mass is inside the ellipse.}\n\\label{fig:2d-Gaussians-Visualization} \n\\end{figure}\n\nAs an example, Figure \\ref{fig:2d-Gaussians-Visualization} shows two Gaussian class-conditional densities in 2d, representing the height and weight of men and women. We can see that the features are correlated, as is to be expected (tall people tend to weigh more). The ellipses for each class contain 95\\% of the probability mass. If we have a uniform prior over classes, we can classify a new test vector as follows:\n\\begin{equation}\ny=\\arg\\max_{c} (\\vec{x}-\\vec{\\mu}_c)^T\\vec{\\Sigma}_c^{-1}(\\vec{x}-\\vec{\\mu}_c)\n\\end{equation}\n\n\n\\subsection{Quadratic discriminant analysis (QDA)}\nBy plugging in the definition of the Gaussian density to Equation \\ref{eqn:Generative-classifier}, we can get\n\\begin{equation}\\label{eqn:QDA}\np(y|\\vec{x},\\vec{\\theta})=\\dfrac{\\pi_c|2\\pi\\vec{\\Sigma}_c|^{-\\frac{1}{2}}\\exp\\left[-\\frac{1}{2}(\\vec{x}-\\vec{\\mu})^T\\vec{\\Sigma}^{-1}(\\vec{x}-\\vec{\\mu})\\right]}{\\sum_{c'}\\pi_{c'}|2\\pi\\vec{\\Sigma}_{c'}|^{-\\frac{1}{2}}\\exp\\left[-\\frac{1}{2}(\\vec{x}-\\vec{\\mu})^T\\vec{\\Sigma}^{-1}(\\vec{x}-\\vec{\\mu})\\right]}\n\\end{equation}\n\nThresholding this results in a quadratic function of $\\vec{x}$. The result is known as quadratic discriminant analysis(QDA). Figure \\ref{fig:QDA} gives some examples of what the decision boundaries look like in 2D.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.50]{QDA-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.50]{QDA-b.png}}\n\\caption{Quadratic decision boundaries in 2D for the 2 and 3 class case.}\n\\label{fig:QDA} \n\\end{figure}\n\n\n\\subsection{Linear discriminant analysis (LDA)}\n\\label{sec:Linear-discriminant-analysis}\nWe now consider a special case in which the covariance matrices are \\textbf{tied} or \\textbf{shared} across classes,$\\vec{\\Sigma}_c=\\vec{\\Sigma}$. In this case, we can simplify Equation \\ref{eqn:QDA} as follows:\n\\begin{align}\np(y|\\vec{x},\\vec{\\theta})& \\propto \\pi_c\\exp\\left(\\vec{\\mu}_c\\vec{\\Sigma}^{-1}\\vec{x}-\\dfrac{1}{2}\\vec{x}^T\\vec{\\Sigma}^{-1}\\vec{x}-\\dfrac{1}{2}\\vec{\\mu}_c^T\\vec{\\Sigma}^{-1}\\vec{\\mu}_c\\right) \\nonumber \\\\\n & =\\exp\\left(\\vec{\\mu}_c\\vec{\\Sigma}^{-1}\\vec{x}-\\dfrac{1}{2}\\vec{\\mu}_c^T\\vec{\\Sigma}^{-1}\\vec{\\mu}_c+\\log \\pi_c\\right) \\nonumber \\\\\n & \\quad \\exp\\left(-\\dfrac{1}{2}\\vec{x}^T\\vec{\\Sigma}^{-1}\\vec{x}\\right) \\nonumber \\\\\n & \\propto \\exp\\left(\\vec{\\mu}_c\\vec{\\Sigma}^{-1}\\vec{x}-\\dfrac{1}{2}\\vec{\\mu}_c^T\\vec{\\Sigma}^{-1}\\vec{\\mu}_c+\\log \\pi_c\\right)\n\\end{align}\n\nSince the quadratic term $\\vec{x}^T\\vec{\\Sigma}^{-1}\\vec{x}$ is independent of $c$, it will cancel out in the numerator and denominator. If we define\n\\begin{align}\n\\gamma_c& \\triangleq -\\dfrac{1}{2}\\vec{\\mu}_c^T\\vec{\\Sigma}^{-1}\\vec{\\mu}_c+\\log \\pi_c \\\\\n\\vec{\\beta}_c& \\triangleq \\vec{\\Sigma}^{-1}\\vec{\\mu}_c\n\\end{align}\nthen we can write\n\\begin{equation}\\label{eqn:LDA}\np(y|\\vec{x},\\vec{\\theta})=\\dfrac{e^{\\vec{\\beta}_c^T\\vec{x}+\\gamma_c}}{\\sum_{c'}e^{\\vec{\\beta}_{c'}^T\\vec{x}+\\gamma_{c'}}} \\triangleq \\sigma(\\vec{\\eta}, c)\n\\end{equation}\nwhere $\\vec{\\eta} \\triangleq (e^{\\vec{\\beta}_1^T\\vec{x}}+\\gamma_1,\\cdots, e^{\\vec{\\beta}_C^T\\vec{x}}+\\gamma_C)$, $\\sigma()$ is the \\textbf{softmax activation function}\\footnote{\\url{http://en.wikipedia.org/wiki/Softmax_activation_function}}, defined as follows:\n\\begin{equation}\n\\sigma(\\vec{q},i) \\triangleq \\dfrac{\\exp(q_i)}{\\sum_{j=1}^n \\exp(q_j)}\n\\end{equation}\n\nWhen parameterized by some constant, $\\alpha > 0$, the following formulation becomes a smooth, differentiable approximation of the maximum function:\n\\begin{equation}\n\\mathcal{S}_{\\alpha}(\\vec{x}) = \\dfrac{\\sum_{j=1}^D x_je^{\\alpha x_j}}{\\sum_{j=1}^D e^{\\alpha x_j}}\n\\end{equation}\n\n$\\mathcal{S}_{\\alpha}$ has the following properties:\n\\begin{enumerate}\n\\item $\\mathcal{S}_{\\alpha} \\rightarrow \\max$ as $\\alpha \\rightarrow \\infty$\n\\item $\\mathcal{S}_0$ is the average of its inputs\n\\item $\\mathcal{S}_{\\alpha} \\rightarrow \\min$ as $\\alpha \\rightarrow -\\infty$\n\\end{enumerate}\n\nNote that the softmax activation function comes from the area of statistical physics, where it is common to use the \\textbf{Boltzmann distribution}, which has the same form as the softmax activation function.\n\nAn interesting property of Equation \\ref{eqn:LDA} is that, if we take logs, we end up with a linear function of $\\vec{x}$. (The reason it is linear is because the $\\vec{x}^T\\vec{\\Sigma}^{-1}\\vec{x}$ cancels from the numerator and denominator.) Thus the decision boundary between any two classes, says $c$ and $c'$, will be a straight line. Hence this technique is called \\textbf{linear discriminant analysis} or \\textbf{LDA}.\n\nAn alternative to fitting an LDA model and then deriving the class posterior is to directly fit $p(y|\\vec{x},\\vec{W})=\\text{Cat}(y|\\vec{W}\\vec{x})$ for some $C \\times D$ weight matrix $\\vec{W}$. This is called \\textbf{multi-class logistic regression}, or \\textbf{multinomial logistic regression}. We will discuss this model in detail in Section TODO. The difference between the two approaches is explained in Section TODO.\n\n\n\\subsection{Two-class LDA}\nTo gain further insight into the meaning of these equations, let us consider the binary case. In this case, the posterior is given by\n\\begin{align}\np(y=1|\\vec{x},\\vec{\\theta})& =\\dfrac{e^{\\vec{\\beta}_1^T\\vec{x}+\\gamma_1}}{e^{\\vec{\\beta}_0^T\\vec{x}+\\gamma_0}+e^{\\vec{\\beta}_1^T\\vec{x}+\\gamma_1}}) \\\\\n  & =\\dfrac{1}{1+e^(\\vec{\\beta}_0-\\vec{\\beta}_1)^T\\vec{x}+(\\gamma_0-\\gamma_1)} \\\\\n  & =\\text{sigm}((\\vec{\\beta}_1-\\vec{\\beta}_0)^T\\vec{x}+(\\gamma_0-\\gamma_1))\n\\end{align}\nwhere sigm$(x)$ refers to the sigmoid function\\footnote{\\url{http://en.wikipedia.org/wiki/Sigmoid_function}}.\n\nNow\n\\begin{align}\n\\gamma_1-\\gamma_0& = -\\dfrac{1}{2}\\vec{\\mu}_1^T\\vec{\\Sigma}^{-1}\\vec{\\mu}_1+\\dfrac{1}{2}\\vec{\\mu}_0^T\\vec{\\Sigma}^{-1}\\vec{\\mu}_0 + \\log(\\pi_1/\\pi_0) \\\\\n & =-\\dfrac{1}{2}(\\vec{\\mu}_1-\\vec{\\mu}_0)^T\\vec{\\Sigma}^{-1}(\\vec{\\mu}_1+\\vec{\\mu}_0)+ \\log(\\pi_1/\\pi_0)\n\\end{align}\n\nSo if we define\n\\begin{align}\n\\vec{w}& =\\vec{\\beta}_1-\\vec{\\beta}_0=\\vec{\\Sigma}^{-1}(\\vec{\\mu}_1-\\vec{\\mu}_0) \\\\\n\\vec{x}_0& =\\dfrac{1}{2}(\\vec{\\mu}_1+\\vec{\\mu}_0)-(\\vec{\\mu}_1-\\vec{\\mu}_0)\\dfrac{\\log(\\pi_1/\\pi_0)}{(\\vec{\\mu}_1-\\vec{\\mu}_0)^T\\vec{\\Sigma}^{-1}(\\vec{\\mu}_1-\\vec{\\mu}_0)}\n\\end{align}\nthen we have $\\vec{w}^T\\vec{x}_0=-(\\gamma_1-\\gamma_0)$, and hence\n\\begin{equation}\np(y=1|\\vec{x},\\vec{\\theta})=\\text{sigm}(\\vec{w}^T(\\vec{x}-\\vec{x}_0))\n\\end{equation}\n\n(This is closely related to logistic regression, which we will discuss in Section TODO.) So the final decision rule is as follows: shift $\\vec{x}$ by $\\vec{x}_0$, project onto the line \\vec{w}, and see if the result is positive or negative.\n\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.50]{2d-LDA.png}\n\\caption{Geometry of LDA in the 2 class case where $\\vec{\\Sigma}_1=\\vec{\\Sigma}_2=\\vec{I}$.}\n\\label{fig:2d-LDA} \n\\end{figure}\n\nIf $\\vec{\\Sigma}=\\sigma^2\\vec{I}$, then $\\vec{w}$ is in the direction of $\\vec{\\mu}_1-\\vec{\\mu}_0$. So we classify the point based on whether its projection is closer to $\\vec{\\mu}_0$ or $\\vec{\\mu}_1$ . This is illustrated in Figure \\ref{fig:2d-LDA}. Furthemore, if $\\vec{\\pi}_1=\\vec{\\pi}_0$, then $\\vec{x}_0=\\frac{1}{2}(\\vec{\\mu}_1+\\vec{\\mu}_0)$, which is half way between the means. If we make $\\vec{\\pi}_1>\\vec{\\pi}_0$, then $\\vec{x}_0$ gets closer to $\\vec{\\mu}_0$, so more of the line belongs to class 1 a \\emph{priori}. Conversely if $\\vec{\\pi}_1<\\vec{\\pi}_0$, the boundary shifts right. Thus we see that the class prior, πc, just changes the decision threshold, and not the overall geometry, as we claimed above. (A similar argument applies in the multi-class case.)\n\nThe magnitude of $\\vec{w}$ determines the steepness of the logistic function, and depends on how well-separated the means are, relative to the variance. In psychology and signal detection theory, it is common to define the \\textbf{discriminability} of a signal from the background noise using a quantity called \\textbf{d-prime}:\n\\begin{equation}\nd' \\triangleq \\dfrac{\\mu_1-\\mu_0}{\\sigma}\n\\end{equation}\nwhere $\\mu_1$ is the mean of the signal and $\\mu_0$ is the mean of the noise, and $\\sigma$ is the standard deviation of the noise. If $d'$ is large, the signal will be easier to discriminate from the noise.\n\n\n\\subsection{MLE for discriminant analysis}\n\\label{sec:MLE-for-discriminant-analysis}\nThe log-likelihood function is as follows:\n\\begin{equation}\np(\\mathcal{D}|\\vec{\\theta})=\\sum\\limits_{c=1}^C{\\sum\\limits_{i:y_i=c}{\\log\\pi_c}}+\\sum\\limits_{c=1}^C{\\sum\\limits_{i:y_i=c}{\\log\\mathcal{N}(\\vec{x}_i|\\vec{\\mu}_c,\\vec{\\Sigma}_c)}}\n\\end{equation}\n\nThe MLE for each parameter is as follows:\n\\begin{align}\n\\bar{\\vec{\\mu}}_c& = \\dfrac{N_c}{N} \\\\\n\\bar{\\vec{\\mu}}_c& = \\dfrac{1}{N_c}\\sum\\limits_{i:y_i=c}\\vec{x}_i \\\\\n\\bar{\\vec{\\Sigma}}_c& = \\dfrac{1}{N_c}\\sum\\limits_{i:y_i=c}(\\vec{x}_i-\\bar{\\vec{\\mu}}_c)(\\vec{x}_i-\\bar{\\vec{\\mu}}_c)^T\n\\end{align}\n\n\n\\subsection{Strategies for preventing overfitting}\nThe speed and simplicity of the MLE method is one of its greatest appeals. However, the MLE can badly overfit in high dimensions. In particular, the MLE for a full covariance matrix is singular if $N_c <D$. And even when $N_c >D$, the MLE can be ill-conditioned, meaning it is close to singular. There are several possible solutions to this problem:\n\\begin{itemize}\n\\item{Use a diagonal covariance matrix for each class, which assumes the features are conditionally independent; this is equivalent to using a naive Bayes classifier (Section \\ref{sec:NBC})}.\n\\item{Use a full covariance matrix, but force it to be the same for all classes,$\\vec{\\Sigma}_c=\\vec{\\Sigma}$. This is an example of \\textbf{parameter tying} or \\textbf{parameter sharing}, and is equivalent to LDA (Section \\ref{sec:Linear-discriminant-analysis}).}\n\\item{Use a diagonal covariance matrix and forced it to be shared. This is called diagonal covariance LDA, and is discussed in Section TODO.}\n\\item{Use a full covariance matrix, but impose a prior and then integrate it out. If we use a conjugate prior, this can be done in closed form, using the results from Section TODO; this is analogous to the “Bayesian naive Bayes” method in Section \\ref{sec:Bayesian-naive-Bayes}. See (Minka 2000f) for details.}\n\\item{Fit a full or diagonal covariance matrix by MAP estimation. We discuss two different kindsof prior below.}\n\\item{Project the data into a low dimensional subspace and fit the Gaussians there. See Section TODO for a way to find the best (most discriminative) linear projection.}\n\\end{itemize}\n\nWe discuss some of these options below.\n\n\n\\subsection{Regularized LDA *}\n\n\n\\subsection{Diagonal LDA}\n\n\n\\subsection{Nearest shrunken centroids classifier *}\nOne drawback of diagonal LDA is that it depends on all of the features. In high dimensional problems, we might prefer a method that only depends on a subset of the features, for reasons of accuracy and interpretability. One approach is to use a screening method, perhaps based on mutual information, as in Section 3.5.4. We now discuss another approach to this problem known as the \\textbf{nearest shrunken centroids} classifier (Hastie et al. 2009, p652).\n\n\n\\section{Inference in jointly Gaussian distributions}\n\\label{sec:Inference-in-jointly-Gaussian-distributions}\nGiven a joint distribution, $p(\\vec{x}_1,\\vec{x}_2)$, it is useful to be able to compute marginals $p(\\vec{x}_1)$ and conditionals $p(\\vec{x}_1|\\vec{x}_2)$. We discuss how to do this below, and then give some applications. These operations take $O(D^3)$ time in the worst case. See Section TODO for faster methods.\n\n\n\\subsection{Statement of the result}\n\n\\begin{theorem}(\\textbf{Marginals and conditionals of an MVN}). Suppose $X=(\\vec{x}_1,\\vec{x}_2)$is jointly Gaussian with parameters\n\\begin{equation}\n\\vec{\\mu}=\\left(\\begin{array}{c}\\vec{\\mu}_1 \\\\\n                                \\vec{\\mu}_2\\end{array}\\right),\n\\vec{\\Sigma}=\\left(\\begin{array}{cc}\n                   \\vec{\\Sigma}_{11} & \\vec{\\Sigma}_{12} \\\\\n \t\t\t\t   \\vec{\\Sigma}_{21} & \\vec{\\Sigma}_{22} \\end{array}\\right),\n\\vec{\\Lambda}=\\vec{\\Sigma}^{-1}=\\left(\\begin{array}{cc}\n                   \\vec{\\Lambda}_{11} & \\vec{\\Lambda}_{12} \\\\\n \t\t\t\t   \\vec{\\Lambda}_{21} & \\vec{\\Lambda}_{22} \\end{array}\\right),\n\\end{equation}\n\nThen the marginals are given by\n\\begin{equation}\n\\begin{split}\np(\\vec{x}_1)= \\mathcal{N}(\\vec{x}_1|\\vec{\\mu}_1,\\vec{\\Sigma}_{11})\\\\\np(\\vec{x}_2)= \\mathcal{N}(\\vec{x}_2|\\vec{\\mu}_2,\\vec{\\Sigma}_{22})\n\\end{split}\n\\end{equation}\nand the posterior conditional is given by\n\\begin{equation}\\label{eqn:Marginals-and-conditionals-of-an-MVN}\n  \\boxed{\\begin{split}\n    p(\\vec{x}_1|\\vec{x}_2)& =\\mathcal{N}(\\vec{x}_1|\\vec{\\mu}_{1|2},\\vec{\\Sigma}_{1|2}) \\\\\n    \\vec{\\mu}_{1|2}& = \\vec{\\mu}_1+\\vec{\\Sigma}_{12}\\vec{\\Sigma}_{22}^{-1}(\\vec{x}_2-\\vec{\\mu}_2) \\\\\n\t               & = \\vec{\\mu}_1-\\vec{\\Lambda}_{11}^{-1}\\vec{\\Lambda}_{12}(\\vec{x}_2-\\vec{\\mu}_2) \\\\\n\t\t\t\t   & = \\vec{\\Sigma}_{1|2}(\\vec{\\Lambda}_{11}\\vec{\\mu}_1-\\vec{\\Lambda}_{12}(\\vec{x}_2-\\vec{\\mu}_2)) \\\\\n\t\\vec{\\Sigma}_{1|2}& = \\vec{\\Sigma}_{11}-\\vec{\\Sigma}_{12}\\vec{\\Sigma}_{22}^{-1}\\vec{\\Sigma}_{21}=\\vec{\\Lambda}_{11}^{-1}\n  \\end{split}}\n\\end{equation}\n\\end{theorem}\n\nEquation \\ref{eqn:Marginals-and-conditionals-of-an-MVN} is of such crucial importance in this book that we have put a box around it, so you can easily find it. For the proof, see Section TODO.\n\nWe see that both the marginal and conditional distributions are themselves Gaussian. For the marginals, we just extract the rows and columns corresponding to $\\vec{x}_1$ or $\\vec{x}_2$. For the conditional, we have to do a bit more work. However, it is not that complicated: the conditional mean is just a linear function of $\\vec{x}_2$, and the conditional covariance is just a constant matrix that is independent of $\\vec{x}_2$. We give three different (but equivalent) expressions for the posterior mean, and two different (but equivalent) expressions for the posterior covariance; each one is useful in different circumstances.\n\n\n\\subsection{Examples}\nBelow we give some examples of these equations in action, which will make them seem more intuitive.\n\n\n\\subsubsection{Marginals and conditionals of a 2d Gaussian}\n\n\n\\section{Linear Gaussian systems}\nSuppose we have two variables, $\\vec{x}$ and $\\vec{y}$.Let $\\vec{x} \\in \\mathbb{R}^{D_x}$ be a hidden variable, and $\\vec{y} \\in \\mathbb{R}^{D_y}$ be a noisy observation of $\\vec{x}$. Let us assume we have the following prior and likelihood:\n\\begin{equation}\\label{eqn:Linear-Gaussian-system}\n  \\boxed{\\begin{split}\n    p(\\vec{x})&=\\mathcal{N}(\\vec{x}|\\vec{\\mu}_x,\\vec{\\Sigma}_x) \\\\\n\tp(\\vec{y}|\\vec{x})&=\\mathcal{N}(\\vec{y}|\\vec{W}\\vec{x}+\\vec{\\mu}_y,\\vec{\\Sigma}_y)\n  \\end{split}}\n\\end{equation}\nwhere $\\vec{W}$ is a matrix of size $D_y \\times D_x$. This is an example of a \\textbf{linear Gaussian system}. We can represent this schematically as $\\vec{x} \\rightarrow \\vec{y}$, meaning $\\vec{x}$ generates $\\vec{y}$. In this section, we show how to “invert the arrow”, that is, how to infer $\\vec{x}$ from $\\vec{y}$. We state the result below, then give several examples, and finally we derive the result. We will see many more applications of these results in later chapters.\n\n\n\\subsection{Statement of the result}\n\\begin{theorem}(\\textbf{Bayes rule for linear Gaussian systems}). \nGiven a linear Gaussian system, as in Equation \\ref{eqn:Linear-Gaussian-system}, the posterior $p(\\vec{x}|\\vec{y})$ is given by the following:\n\\begin{equation}\\label{eqn:Linear-Gaussian-system-posterior}\n  \\boxed{\\begin{split}\n    p(\\vec{x}|\\vec{y})&=\\mathcal{N}(\\vec{x}|\\vec{\\mu}_{x|y},\\vec{\\Sigma}_{x|y}) \\\\\n\t\\vec{\\Sigma}_{x|y}&=\\vec{\\Sigma}_x^{-1}+\\vec{W}^T\\vec{\\Sigma}_y^{-1}\\vec{W} \\\\\n\t\\vec{\\mu}_{x|y}&=\\vec{\\Sigma}_{x|y}\\left[\\vec{W}^T\\vec{\\Sigma}_y^{-1}(\\vec{y}-\\vec{\\mu}_y)+\\vec{\\Sigma}_x^{-1}\\vec{\\mu}_x\\right]\n  \\end{split}}\n\\end{equation}\nIn addition, the normalization constant $p(\\vec{y})$ is given by\n\\begin{equation}\\label{eqn:Linear-Gaussian-system-normalizer}\n  \\boxed{\n    p(\\vec{y})=\\mathcal{N}(\\vec{y}|\\vec{W}\\vec{\\mu}_x+\\vec{\\mu}_y,\\vec{\\Sigma}_y+\\vec{W}\\vec{\\Sigma}_x\\vec{W}^T)\n  }\n\\end{equation}\n\\end{theorem}\n\nFor the proof, see Section 4.4.3 TODO.\n\n\n\\section{Digression: The Wishart distribution *}\n\n\n\\section{Inferring the parameters of an MVN}\n\n\n\\subsection{Posterior distribution of $\\mu$}\n\n\n\n\\subsection{Posterior distribution of $\\Sigma$ *}\n\n\n\n\\subsection{Posterior distribution of $\\mu$ and $\\Sigma$ *}\n\\label{sec:Posterior-distribution-of-mu-and-Sigma}\n\n\n\\subsection{Sensor fusion with unknown precisions *}\n\n", "meta": {"hexsha": "9135f6f9073293c364d79b78038efba98226bddf", "size": 21878, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mlapp/chapterMVN.tex", "max_stars_repo_name": "Alexoner/Statistical-formula", "max_stars_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-02-15T17:00:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-24T13:46:00.000Z", "max_issues_repo_path": "mlapp/chapterMVN.tex", "max_issues_repo_name": "Alexoner/Statistical-formula", "max_issues_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mlapp/chapterMVN.tex", "max_forks_repo_name": "Alexoner/Statistical-formula", "max_forks_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-02-25T15:40:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-25T04:26:03.000Z", "avg_line_length": 65.6996996997, "max_line_length": 773, "alphanum_fraction": 0.7036749246, "num_tokens": 7053, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.905989829267587, "lm_q1q2_score": 0.7428150234219368}}
{"text": "\\section{Grammar $\\rarr$ Automaton}\n\nGiven a \\textbf{Right-Linear Grammar}, the automaton has as states the \\emph{nonterminals}, the initial state is the axiom.\n\\begin{align*}\n    A \\rarr aB &\\quad\\Rightarrow\\quad A \\xrightarrow{a} B \\\\\n    A \\rarr B & \\quad\\Rightarrow\\quad A \\xrightarrow{\\epsilon}B \\\\\n    A \\rarr \\epsilon &\\quad\\Rightarrow\\quad A \\rarr \\text{ (final)}\n\\end{align*}\n\nGiven a \\textbf{Left-Linear Grammar}\n\nLL $\\xrightarrow[\\text{grammar}]{\\text{reverse}}$ RL $\\xrightarrow[\\text{autom}]{\\text{make}}$ automaton $\\xrightarrow[\\text{automaton}]{\\text{reverse}}$ result.\n", "meta": {"hexsha": "6e2b5bebff6fb066e1a1c71d36b82e863d0111ff", "size": 586, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "automata/grammar-to-automaton.tex", "max_stars_repo_name": "TiberioG/FLC-cheatsheet", "max_stars_repo_head_hexsha": "d86e8ba9c80fece75ffccf47c273334b677f4934", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-01-13T14:36:20.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-18T16:22:18.000Z", "max_issues_repo_path": "automata/grammar-to-automaton.tex", "max_issues_repo_name": "TiberioG/FLC-cheatsheet", "max_issues_repo_head_hexsha": "d86e8ba9c80fece75ffccf47c273334b677f4934", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "automata/grammar-to-automaton.tex", "max_forks_repo_name": "TiberioG/FLC-cheatsheet", "max_forks_repo_head_hexsha": "d86e8ba9c80fece75ffccf47c273334b677f4934", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-05-21T11:05:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-17T14:59:50.000Z", "avg_line_length": 45.0769230769, "max_line_length": 161, "alphanum_fraction": 0.704778157, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137296, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7426977891004942}}
{"text": "\\section{Small imprecisions can become big imprecisions}\nIn this section we explore two ways in which very small starting imprecisions can become very large imprecisions in the final output of a program.\n\n\\subsection{When doing numerically unstable computations}\\label{ss:numerically-unstable}\nThere are some types of computations which can transform small imprecisions into catastrophically large ones, and line intersection is one of them. Imagine you have four points $A,B,C,D$ which were obtained through an previous imprecise process (for example, their position can vary by a distance of at most $r = 10^{-6}$), and you have to compute the intersection of lines $AB$ and $CD$.\n\nFor illustration, we represent the imprecisions on the points with small disk of radius $r$: the exact position is the black dot, while the small gray disk contains the positions it could take because of imprecisions. The dashed circle gives an idea of where point $I$ might lie.\n\nIn the best case, when $A,B$ and $C,D$ aren't too close together, and not too far from the intersection point $I$, then the imprecision on $I$ isn't too big.\n\n\\centerFig{small-big0}\n\nBut if those conditions are not respected, the intersection $I$ might vary in a very wide range or even fail to exist, if given the imprecision lines $AB$ and $CD$ end up being parallel, or if $A$ and $B$ (or $C$ and $D$) end up coinciding.\n\n\\centerFig{small-big1}\n    \nThis shows that finding the intersection of two lines defined by imprecise points is a task that is inherently problematic for floating-point arithmetic, as it can produce wildly incorrect results even if the starting imprecision is quite small.\n\n\\subsection{With large values and accumulation}\\label{ss:accumulation}\n\nAnother way in which small imprecisions can become big is by accumulation. Problem ``Keeping the Dogs Apart'', which we treat in more detail in a case study in section~\\ref{ss:dogs}, is a very good example of this. In this problem, two dogs run along two polylines at equal speed and you have to find out the minimum distance between them at any point in time.\n\nEven though the problem seems quite easy and the computations do not have anything dangerous for precision (mostly just additions, subtractions and distance computations), it turns out to be a huge precision trap, at least in the most direct implementation.\n\nLet's say we maintain the current distance from the start for both dogs. There are $10^5$ polyline segments of length up to $\\sqrt{2}\\times 10^4$, so this distance can reach $\\sqrt{2}\\times 10^9$. Besides, to compute the sum, we perform $10^5$ sum operations which can all bring a $2^{-53} \\approx 1.11 \\times 10^{-16}$ relative error if we're using \\lstinline|double|. So in fact the error might reach\n\\[\\left(\\sqrt{2}\\times 10^9\\right) \\times 10^5 \\times 2^{-53} \\approx 0.016\\]\n\nAlthough this is a theoretical computation, the error does actually get quite close to this in practice, and since the tolerance on the answer is $10^{-4}$ this method actually gives a WA verdict.\n\nThis shows that even when only very small precision mistakes are made ($\\approx 1.11 \\times 10^{-16}$), the overal loss of precision can get very big, and carefully checking the maximal imprecision of your program is very important.\n", "meta": {"hexsha": "97652ccbdbfde10f8c832dbeaf482fab1bd75db9", "size": 3271, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/precision/small-big.tex", "max_stars_repo_name": "cbarnson/UVa", "max_stars_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_stars_repo_licenses": ["Unlicense", "MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-07T17:00:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-05T02:08:35.000Z", "max_issues_repo_path": "archives/codelibraries/cp-geo-master/precision/small-big.tex", "max_issues_repo_name": "cbarnson/UVa", "max_issues_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_issues_repo_licenses": ["Unlicense", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "archives/codelibraries/cp-geo-master/precision/small-big.tex", "max_forks_repo_name": "cbarnson/UVa", "max_forks_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_forks_repo_licenses": ["Unlicense", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 105.5161290323, "max_line_length": 402, "alphanum_fraction": 0.7743809233, "num_tokens": 774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673223709251, "lm_q2_score": 0.9136765145991261, "lm_q1q2_score": 0.742697781935391}}
{"text": "\\subsubsection{Some sanity checks}\n\nLet's take an example, to see what we get for a typical case.  We can write the beta-model as a radially symmetric pressure model:\n\n\\begin{equation}\np(x) = {1\\over{(1 + x^2)^{3\\beta/2}}}\n\\end{equation}\n\nIn the particular case $\\beta = 2/3$, the integrals become analytic.  In particular, we have\n\n\\begin{equation}\n\\integral{}{}{p(x)}{x} = \\integral{}{}{{1\\over{(1 + x^2)}}}{x} = \\arctan{x}\n\\end{equation}\n\nand \n\n\\begin{equation}\n\\integral{}{}{p(x)x^2}{x} = \\integral{}{}{{x^2\\over{(1 + x^2)}}}{x} = {x - \\arctan{x}}\n\\end{equation}\n\nwhence\n\n\\begin{equation}\nI(0) = \\integral{\\infty}{-\\infty}{p(x)}{x} = \\integral{\\infty}{-\\infty}{{1\\over{(1 + x^2)}}}{x} = \\pi\n\\end{equation}\n\n(which I confirmed numerically)\n\nand \n\n\\begin{equation}\n\\integral{x_R}{0}{p(x)4\\pi x^2}{x} = 4\\pi\\integral{x_R}{0}{{x^2\\over{(1 + x^2)}}}{x} = 4\\pi ({x_R - \\arctan{x_R}})\n\\end{equation}\n\n(which I also confirm numerically, for $x_R = 1$).\n\nFrom Equation~\\ref{eq:mgas} then, we have:\n\n\\begin{eqnarray}\n\\Mgas(R) &=& m_p\\mu_e {{y(0)}\\over{I(0)}} \\left({{m_e c^2}\\over{k_B T_e(0)}}\\right)\\left({{D^2_A\\theta^2_c}\\over{\\sigma_T}}\\right)\\integral{x_R}{0}{p(x)4\\pi x^2}{x}\\\\\\nonumber\n     &=& y(0)\\left({{T_e}\\over{1~{\\rm keV}}}\\right)^{-1} \\left({{D_A}\\over{1~{\\rm Gpc}}}\\right)^2 \\left({{\\theta_c}\\over{1~{\\rm arcsec}}}\\right)^2 ({x_R - \\arctan{x_R}})\\\\\\nonumber\n&& \\times 6.8\\times 10^{14}\\Msolar\n\\end{eqnarray}\n\nA \\betamodel\\ fit to A1914 with $\\beta = 2/3$ gives $\\theta_c = 20$ arcsec and $\\Delta T(0) = -2$~mK, or $y(0) \\sim 3.7\\times 10^{-4}$.  \n\nFor A1914 we also have $T_e \\sim 10~{\\rm keV}$, $D_A \\sim 0.6~$Gpc,\nyielding\n\n\\begin{eqnarray}\n\\Mgas(R) &=& y(0) ({x_R - \\arctan{x_R}}) \\times 9.8\\times 10^{15}\\Msolar\n\\end{eqnarray}\n\nIn Tony's paper, he estimates an \\mathR500\\ of $R \\sim 1.3$~Mpc, or $x_R = R/(D_A\\theta_c) \\sim 22$, yielding\n\n\\begin{eqnarray}\n\\Mgas(R) &=& 7.7\\times 10^{13}\\Msolar.\n\\end{eqnarray}\n\nNote that this is not what Tony reports for A1914, but is within 30\\% of his value ($11\\times 10^{13}\\Msolar$).\n", "meta": {"hexsha": "e1ebc37f2384e817da1245dbb22674b9a8d6a9fa", "size": 2037, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "help/sanityChecks.tex", "max_stars_repo_name": "erikleitch/climax", "max_stars_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-01T05:15:31.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-01T05:15:31.000Z", "max_issues_repo_path": "docs/sanityChecks.tex", "max_issues_repo_name": "erikleitch/climax", "max_issues_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/sanityChecks.tex", "max_forks_repo_name": "erikleitch/climax", "max_forks_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-02T19:35:55.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-07T00:54:51.000Z", "avg_line_length": 33.393442623, "max_line_length": 180, "alphanum_fraction": 0.6224840452, "num_tokens": 860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7426977750843778}}
{"text": "\\chapter{Geometria solida}\n\\section{Cono}\n\\begin{tcolorbox}[sidebyside,righthand width=9cm,colback=white,colframe=white,fonttitle=\\bfseries\t]\n\t\\includestandalone[width=2.2cm]{geometria/cono}\n\t\\tcblower\n\t\\begin{align}\nV=&\\dfrac{\\pi r^2h}{3}&r=&\\sqrt{\\dfrac{3V}{\\pi h}}&h=&\\dfrac{3V}{\\pi r^2}\\\\\na=&\\sqrt{r^2+h^2}&S_{lat}=&\\pi r a&S_{tot}=&S_{lat}+S_{ba}\n\t\\end{align}\n\\end{tcolorbox}\\index{Cono!volume}\\index{Cono!raggio}\n\\section{Cilindro}\n\\begin{tcolorbox}[sidebyside,righthand width=9cm,colback=white,colframe=white,fonttitle=\\bfseries\t]\n\t\\includestandalone[width=2.2cm]{geometria/cilindro}\n\t\\tcblower\n\t\\begin{align}\n\tV=&\\pi r^2h&r=&\\sqrt{\\dfrac{V}{\\pi h}}&h=&\\dfrac{V}{\\pi r^2}\\\\\n\tS_{lat}=&\\pi r h&S_{tot}=&S_{lat}+S_{ba}\n\t\\end{align}\n\\end{tcolorbox}\n\\section{Parallelepipedo rettangolo}\n\\begin{tcolorbox}[sidebyside,righthand width=9cm,colback=white,colframe=white,fonttitle=\\bfseries\t]\n\t\\includestandalone[width=4cm]{geometria/parallepipedoret}\n\t\\tcblower\n\t\\begin{align}\n\tV=&abh&V=&S_{ba}h\n\t\\end{align}\n\\end{tcolorbox}", "meta": {"hexsha": "489320f96225d311985f39b3eadcff0843830a38", "size": 1021, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "geometriasolida.tex", "max_stars_repo_name": "trim1962/formulario", "max_stars_repo_head_hexsha": "d7b0c7ce6a2064bfe39f1e3c96c4f01f3579e98e", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "geometriasolida.tex", "max_issues_repo_name": "trim1962/formulario", "max_issues_repo_head_hexsha": "d7b0c7ce6a2064bfe39f1e3c96c4f01f3579e98e", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "geometriasolida.tex", "max_forks_repo_name": "trim1962/formulario", "max_forks_repo_head_hexsha": "d7b0c7ce6a2064bfe39f1e3c96c4f01f3579e98e", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.8148148148, "max_line_length": 99, "alphanum_fraction": 0.7247796278, "num_tokens": 442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.7426917946899223}}
{"text": "% !TEX root = ../main.tex\n%---------------------------------------------------------------------------------------------------\n%---------------------------------------------------------------------------------------------------\n\\section{Mathematical formulation}\n%---------------------------------------------------------------------------------------------------\n%---------------------------------------------------------------------------------------------------\n\\begin{frame}{Dynamic programming}\\vspace{0.25cm}\n\\heading{Policy evaluation}\n\\begin{align*}\n  v^\\pi_t(s_t) = \\E_{s_t}^\\pi\\left[ \\sum^{T - t}_{j = 0}  \\delta^j\\, u_{t + j}(s_{t + j}, a^\\pi_{t + j}(s_{t + j})) \\right]\n\\end{align*}\n\\heading{Optimality equations}\n\\begin{align*}\n  v^{\\pi^*}_t(s_t)  & = \\max_{a_t \\in A} \\left\\{ u_t(s_t, a_t) + \\delta \\E^{\\pi^*}_{s_t}\\! \\left[ v^{\\pi^*}_{t + 1}(s_{t + 1})\\,\\right] \\right\\}\n\\end{align*}\n\n\\end{frame}\n%---------------------------------------------------------------------------------------------------\n%---------------------------------------------------------------------------------------------------\n\\begin{frame}{Backward induction algorithm}\\vspace{0.25cm}\n\\begin{algorithmic}\n\\For{$t = T, \\hdots, 1$}\n    \\If{t = T}\n        \\State $v^{\\pi^*}_T(s_T) =  \\underset{a_T\\in A}{\\max} \\bigg\\{ u_T(s_T, a_T) \\bigg\\}\\qquad \\forall\\, s_T\\in S$\n    \\Else\n        \\State Compute $v^{\\pi^*}_t(s_t)$ for each $s_t\\in S$ by\n        \\State $\\qquad v^{\\pi^*}_t(s_t) = \\underset{a_t\\in A}{\\max} \\bigg\\{ u_t(s_t, a_t) + \\delta \\E^\\pi_{s_t}\\! \\left[ v^{\\pi^*}_{t + 1}(s_{t + 1}) \\,\\right] \\bigg\\}$\n        \\State and set\n        \\State $\\qquad a^{\\pi^*}_t(s_t) = \\underset{a_t\\in A}{\\argmax} \\bigg\\{ u_t(s_t, a_t) + \\delta \\E^\\pi_{s_t}\\! \\left[ v^{\\pi^*}_{t + 1}(s_{t + 1})\\,\\right] \\bigg\\}$\n    \\EndIf\n\\EndFor\n\\vspace{0.3cm}\\end{algorithmic}\n\\end{frame}\n%---------------------------------------------------------------------------------------------------\n%---------------------------------------------------------------------------------------------------\n", "meta": {"hexsha": "2d9baed6d2c3d1dcf42c2cf97e7fab621174a802", "size": 2054, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/files/s-setup-mathematics.tex", "max_stars_repo_name": "OpenSourceEconomics/handout-eckstein-keane-wolpin-models", "max_stars_repo_head_hexsha": "68cc55540c8b8772a3b204b7ba063fb324b08fdb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slides/files/s-setup-mathematics.tex", "max_issues_repo_name": "OpenSourceEconomics/handout-eckstein-keane-wolpin-models", "max_issues_repo_head_hexsha": "68cc55540c8b8772a3b204b7ba063fb324b08fdb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-03-05T07:53:32.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-30T11:59:58.000Z", "max_forks_repo_path": "slides/files/s-setup-mathematics.tex", "max_forks_repo_name": "OpenSourceEconomics/handout-eckstein-keane-wolpin-models", "max_forks_repo_head_hexsha": "68cc55540c8b8772a3b204b7ba063fb324b08fdb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-09-17T17:09:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T19:27:05.000Z", "avg_line_length": 57.0555555556, "max_line_length": 170, "alphanum_fraction": 0.3422590068, "num_tokens": 597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582535657921, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7426794685346433}}
{"text": "\\subsection{Fuzzy Logic} \\label{fuzzy_logic}\nFuzzy Logic (FL) aims at modeling the human reasoning system. It finds its roots in multi-valued logic, which extends the classical two-valued logic by adding new truth values. Differently from other multi-valued logics which have a finite number of truth values, in FL a variable can assume the value of any real number in [0,~1], where 0 means completely false and 1 means completely true.\n% This characteristic is also found in Probabilistic Logic, where the truth value of a formula is computed by probabilistic expressions.\nIf we think about the definition of logic, it \\emph{``is the science of the formal principle of reasoning\"}. From this perspective, FL is concerned with the formal principles of \\textit{approximate reasoning}, since we deal with imprecise premises from which we derive imprecise conclusions~\\cite{pal1991fuzzy}. This aspect reflects the fact that in human reasoning we have to deal with vagueness when classifying concepts such as a \\textit{tall person} or a \\textit{small number}~\\cite{hajek1998basic, novak2012mathematical}. In this work, we will focus on the fuzzy extension of the First Order Logic (FOL).\n\nSeveral FL implementations have been proposed over the years to approximate the logical operators and quantifiers in different ways. We now proceed with the description of some popular variants of the FL by assuming familiarity with the basic notions of the FOL. The definitions we will use in this section are taken from~\\cite{analyzingDiffFuzzyLogic}. First of all, the semantics of the main fuzzy operators relies on the following functions:\n\\begin{itemize}\n    \\item \\textbf{Fuzzy Negation:} function to compute the \\textit{negation} of a truth value of a formula. A \\textit{fuzzy negation} is a decreasing function $ N:[0,1]\\rightarrow [0,1] $ \\\\\n    such that $ N(1)=0 $ and $ \\forall (x)\\in [0,1], N(N(x)) \\geq x $. $N$ is called \\textit{strict} if it is strictly decreasing and continuous, and \\textit{strong} if \\\\$\\forall x \\in [0,1], N(N(x))=x$. %In general, we will consider the classical negation $N(x) = 1 - x$.\n    \n    \\item \\textbf{Triangular Norms (t-norms):} function to compute the \\textit{conjunction} of two truth values of a formula. A \\textit{t-norm} is a function $ T:[0,1]^{2}\\rightarrow [0,1] $ that is \\textit{commutative} and \\textit{associative}, where $\\forall x \\in [0,1], T(x,\\cdot)$ is increasing (\\textit{monotonicity}) and $\\forall x \\in [0,1], T(1,x)=x$ (\\textit{neutrality}).\n    \n    \\item \\textbf{Triangular Conorms (t-conorm):} function to compute the \\textit{disjunction} of two truth values of a formula. A \\textit{t-conorm} (also known as s-norm) is a function $S:[0,1]^{2} \\rightarrow [0,1] $ that is \\textit{commutative} and \\textit{associative}, where $\\forall x \\in [0,1], S(x,\\cdot)$ is increasing (\\textit{monotonicity}) and $\\forall x \\in [0,1], S(0,x)=x$ (\\textit{neutrality}). Since t-conorms are obtained from t-norms by applying De Morgran's law from classical logic, it is possible to write the following equivalence\n    \\begin{gather*}\n        S(a, b) = 1 - T(1 - a, 1 - b)\n    \\end{gather*}\n    \n    \\item \\textbf{Aggregation Operators:} function to compute $\\forall$ and $\\exists$ quantifiers. \n    \\begin{itemize}\n        \\item the $\\forall$ quantifier can be interpreted as a function $A:[0,1]^{n} \\rightarrow [0,1] $ computed as a conjunction over all arguments $x$, using a t-norm adapted to $n$-dimensional input:\n        \\begin{gather*}\n            A_{T}()=0 \\\\\n            A_{T}(x_{1},x_{2},...,x_{n}) = T(x_{1},A_{T}(x_{2},...,x_{n}))\n        \\end{gather*}\n        \n        \\item the $\\exists$ quantifier can be interpreted as a function $E:[0,1]^{n} \\rightarrow [0,1] $ computed as a disjunction over all arguments $x$, using a t-conorm adapted to $n$-dimensional input:\n        \\begin{gather*}\n            E_{S}()=0 \\\\\n            E_{S}(x_{1},x_{2},...,x_{n}) = S(x_{1},E_{S}(x_{2},...,x_{n}))\n        \\end{gather*}\n    \\end{itemize}\n\\end{itemize}\n\nStarting from these definitions, we can find a variety of implementations of fuzzy operators. In Table~\\ref{tab:fuzzy_norm} are reported the operators of some popular fuzzy logics. The variants proposed by Łukasiewicz and Gödel can be considered among the most popular, but there are many other interpretations (e.g., Weber, Yager, Fodor). Table~\\ref{tab:fuzzy_aggregation} reports some aggregation operators based on the presented t-norm and t-conorm operators. \n\n\n\\begin{table}\n\\centering\n\\caption{Some common t-norm and t-conorm in fuzzy logic}\n\\label{tab:fuzzy_norm}\n\\begin{tabular}{|c|cc|}\n\\hline\n\\textbf{Name} & \\multicolumn{1}{c|}{\\textbf{T-norm}} & \\textbf{T-conorm}              \\\\ \\hline\nGödel         & $T_{G}(a,b)=min(a,b)$                & $S_{G}(a,b)=max(a,b)$          \\\\ \\hline\nProduct       & $T_{P}(a,b)=a \\cdot b$               & $S_{P}(a,b)=a + b - a \\cdot b$ \\\\ \\hline\nŁukasiewicz   & $T_{L}(a,b)=max(a+b-1,0)$            & $S_{L}(a,b)=min(a+b,1)$        \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\n\\begin{table}\n\\centering\n\\caption{Some common aggregation operators in fuzzy logic}\n\\label{tab:fuzzy_aggregation}\n\\resizebox{\\columnwidth}{!}{\\begin{tabular}{|c|cc|}\n\\hline\n\\textbf{Name}     & \\multicolumn{1}{c|}{\\textbf{Generalizes}} & \\textbf{Aggregation operator}                                     \\\\ \\hline\nMinimum           & $T_{G}$                                   & $A_{T_{G}}(x_{1},...,x_{n}) = min(x_{1},...,x_{n})$               \\\\\nProduct           & $T_{P}$                                   & $A_{T_{P}}(x_{1},...,x_{n}) = \\prod_{i=1}^{n} x_{i}$              \\\\\nŁukasiewicz       & $T_{L}$                                   & $A_{T_{L}}(x_{1},...,x_{n}) = max(\\sum_{i=1}^{n} x_{i}-(n-1), 0)$ \\\\ \\hline\nMaximum           & $S_{G}$                                   & $E_{S_{G}}(x_{1},...,x_{n}) = max(x_{1},...,x_{n})$               \\\\\nProbabilistic Sum & $S_{P}$                                   & $E_{S_{P}}(x_{1},...,x_{n}) = 1 - \\prod_{i=1}^{n} (1 - x_{i}) $   \\\\\nBounded Sum       & $S_{L}$                                   & $E_{S_{L}}(x_{1},...,x_{n}) = min(\\sum_{i=1}^{n} x_{i}, 1)$       \\\\ \\hline\n\\end{tabular}}\n\\end{table}", "meta": {"hexsha": "1618fd1efa101882c8eaa397a82eb9af16668f35", "size": 6167, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "project/sota/fuzzy_logic.tex", "max_stars_repo_name": "christianbernasconi96/MasterThesis", "max_stars_repo_head_hexsha": "6211ff86af247aace530912c4eca9019365d606e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "project/sota/fuzzy_logic.tex", "max_issues_repo_name": "christianbernasconi96/MasterThesis", "max_issues_repo_head_hexsha": "6211ff86af247aace530912c4eca9019365d606e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "project/sota/fuzzy_logic.tex", "max_forks_repo_name": "christianbernasconi96/MasterThesis", "max_forks_repo_head_hexsha": "6211ff86af247aace530912c4eca9019365d606e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 96.359375, "max_line_length": 609, "alphanum_fraction": 0.6343440895, "num_tokens": 1892, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.7981867681382279, "lm_q1q2_score": 0.742679464762012}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  For each of the following symmetric matrices, find the eigenvalues,\n  an orthonormal basis for each eigenspace, and then orthogonally\n  diagonalize the matrix.\n  \\begin{equation*}\n    (a)\\quad\n    A = \\begin{mymatrix}{rr}\n      -1 & 2 \\\\\n      2  & 2 \\\\\n    \\end{mymatrix},\\quad\n    (b)\\quad\n    A = \\begin{mymatrix}{rr}\n      3 & 1 \\\\\n      1 & 3 \\\\\n    \\end{mymatrix},\\quad\n    (c)\\quad\n    A = \\begin{mymatrix}{rrr}\n      1 & 1 & 0 \\\\\n      1 & 2 & 1 \\\\\n      0 & 1 & 1 \\\\\n    \\end{mymatrix},\\quad\n    (d)\\quad\n    A = \\begin{mymatrix}{rrr}\n      2 & 1 & 2 \\\\\n      1 & 2 & 2 \\\\\n      2 & 2 & 5 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item $A=PDP^{-1}$ where $D=\\begin{mymatrix}{rr}\n        -2 & 0 \\\\\n        0  & 3 \\\\\n      \\end{mymatrix}$,\n      $P=\\frac{1}{\\sqrt{5}}\\begin{mymatrix}{rr}\n        2  & 1 \\\\\n        -1 & 2 \\\\\n      \\end{mymatrix}$.\n    \\item $A=PDP^{-1}$ where $D=\\begin{mymatrix}{rr}\n        2 & 0 \\\\\n        0 & 4 \\\\\n      \\end{mymatrix}$,\n      $P=\\frac{1}{\\sqrt{2}}\\begin{mymatrix}{rr}\n        1  & 1 \\\\\n        -1 & 1 \\\\\n      \\end{mymatrix}$.\n    \\item $A=PDP^{-1}$ where\n      $D=\\begin{mymatrix}{rrr}\n        0 & 0 & 0 \\\\\n        0 & 1 & 0 \\\\\n        0 & 0 & 3 \\\\\n      \\end{mymatrix}$,\n      $\\def\\arraystretch{1.3}\n      P=\\begin{mymatrix}{rrr}\n        \\frac{1}{\\sqrt{3}} & \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{6}} \\\\\n        -\\frac{1}{\\sqrt{3}} & 0 & \\frac{2}{\\sqrt{6}} \\\\\n        \\frac{1}{\\sqrt{3}} & -\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{6}} \\\\\n      \\end{mymatrix}$.\n    \\item $A=PDP^{-1}$ where\n      $D=\\begin{mymatrix}{rrr}\n        1 & 0 & 0 \\\\\n        0 & 1 & 0 \\\\\n        0 & 0 & 7 \\\\\n      \\end{mymatrix}$,\n      $\\def\\arraystretch{1.3}\n      P=\\begin{mymatrix}{rrr}\n        \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{3}} & \\frac{1}{\\sqrt{6}} \\\\\n        -\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{3}} & \\frac{1}{\\sqrt{6}} \\\\\n        0 & -\\frac{1}{\\sqrt{3}} & \\frac{2}{\\sqrt{6}} \\\\\n      \\end{mymatrix}$.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Prove the converse of Theorem~\\ref{thm:diagonalization-symmetric}:\n  if a matrix $A$ is orthogonally diagonalizable, then $A$ is\n  symmetric.\n  \\begin{sol}\n    Suppose $A$ is orthogonally diagonalizable. Then $A=PDP^{-1}$,\n    where $D$ is diagonal and $P$ is orthogonal. Since $P$ is\n    orthogonal, we have $P^{-1}=P^T$, and therefore\n    $A=PDP^T$. Moreover, since $D$ is diagonal, we have $D=D^T$. It\n    follows that $A^T = (PDP^T)^T = (P^T)^T D^T P^T = PDP^T = A$, so\n    $A$ is symmetric.\n  \\end{sol}\n\\end{ex}\n", "meta": {"hexsha": "846afa669f604a29170d1c6fd6cd215dc389cd1f", "size": 2578, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/InnerProductSpaces-Diagonalization.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/InnerProductSpaces-Diagonalization.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/InnerProductSpaces-Diagonalization.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 28.6444444444, "max_line_length": 72, "alphanum_fraction": 0.485647789, "num_tokens": 1066, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.7426391232610782}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\n\\section{Matrix formulation}\nThe generic compartment model described in the previous sections can be written in matrix form. For simplicity and because we will restrict ourselves to such systems in the next, we consider the case of an isolated system, i.e. $\\phi_{i,e} = 0$. Let\n\\begin{equation} \\label{eq:def_compartment_vars}\n\t\\b c = \\begin{pmatrix} C_1 \\\\ C_2 \\\\ \\vdots \\\\ C_N \\end{pmatrix}, \\quad \\b q = \\begin{pmatrix} q_1 \\\\ q_2 \\\\ \\vdots \\\\ q_N \\end{pmatrix}, \\quad \\bs \\omega = \\begin{pmatrix} |\\Omega_1| \\\\ |\\Omega_2| \\\\ \\vdots \\\\ |\\Omega_N| \\end{pmatrix}, \\quad \\mbox{and} \\quad \\bs \\Omega = \\diag(\\bs \\omega).\n\\end{equation}\nThe evolution of the concentrations in the compartments is given by\n\\begin{equation} \\label{eq:compartmentmatrix}\n\t\\bs \\Omega \\b{\\dot{c}} = \\bs \\Omega \\b q + \\b A \\b c,\n\\end{equation}\nwhere $\\b A$ is the \\textit{interaction matrix}, which describes the advective and diffusive fluxes between the subdomains. Using the parameters introduced previously, $\\b A$ can be expressed as\n\\begin{equation} \\label{eq:generalA}\n\t\\b A = \t\\begin{pmatrix}\n\t\t\t\t-\\sum_{j=1}^N \\frac{1}{2}U_{1,j}+V_{1,j} & -\\frac{1}{2}U_{1,2}+V_{1,2} & \\cdots & -\\frac{1}{2}U_{1,N}+V_{1,N}\\\\[.1cm]\n\t\t\t\t-\\frac{1}{2}U_{2,1}+V_{2,1} & -\\sum_{j=1}^N \\frac{1}{2}U_{2,j}+V_{2,j} & \\cdots & -\\frac{1}{2}U_{2,N}+V_{2,N}\\\\\n\t\t\t\t\\vdots & \\vdots & \\ddots & \\vdots\\\\\n\t\t\t\t-\\frac{1}{2}U_{N,1}+V_{N,1} & -\\frac{1}{2}U_{N,2}+V_{N,2} & \\cdots & -\\sum_{j=1}^N \\frac{1}{2}U_{N,j}+V_{N,j}\n\t\t\t\\end{pmatrix}.\n\\end{equation}\nIn matrix formulation, the mean concentration is expressed as\n\\begin{equation} \\label{eq:Cmeanmatrix}\n\t\\bar C = \\frac{1}{|\\Omega|} \\b 1^\\t \\bs \\Omega \\b c,\n\\end{equation}\nwhere $\\b 1$ is the N-dimensional unit column vector. Notice that $|\\Omega| = \\b 1^\\t \\bs \\Omega \\b 1$. In the next of this section, we show how properties~\\ref{prop1_comp}, \\ref{prop2_comp} and~\\ref{prop3_comp} from section~\\ref{sec:prop_comp} are expressed in matrix formulation.\n\\begin{property} \\label{prop1bis_comp}\nEach column of the interaction matrix sums to zero:\n\\begin{equation}\n\t\\b 1^\\t \\b A = 0.\n\\end{equation}\n\\end{property} \n\\begin{proof}\n\tFrom equations~\\eqref{eq:compartmentmatrix} and~\\eqref{eq:Cmeanmatrix},\n\t\\begin{equation}\n\t\t|\\Omega| \\dot{\\bar{C}} = \\b 1^\\t \\bs \\Omega \\dot{\\b{c}} = \\b 1^\\t \\bs \\Omega \\b q + \\b 1^\\t\\b A \\b c.\n\t\\end{equation}\n\tThis equation is valid for an isolated system. If furthermore the tracer is passive ($\\b q=0$), we know by corollary \\ref{cor:Cmeanconstant} that $\\bar C$ must be constant. Hence\n\t\\begin{equation} \\label{eq:souris}\n\t\t|\\Omega| \\dot{\\bar{C}} = \\b 1^\\t\\b A \\b c = 0.\n\t\\end{equation}\n\tEquation~\\eqref{eq:souris} must be valid for any concentration vector $\\b c$, thus $\\b 1^\\t \\b A = 0$.\n\\end{proof}\n\n\\begin{property} \\label{prop2bis_comp}\n\tEach row of the interaction matrix sums to zero:\n\t\\begin{equation}\n\t\t\\b A \\b 1 = 0.\t\t\n\t\\end{equation}\t\n\\end{property}\n\\begin{proof}\n\tLet $C_0>0$ be a constant and $\\b c = C_0 \\b 1$. Introducing the latter in~\\eqref{eq:compartmentmatrix} with $\\b q = \\b 0$ yields\n\t\\begin{equation}\n\t\t0 = C_0 \\b A \\b 1.\n\t\\end{equation}\n\\end{proof}\n\n\\begin{property} \\label{prop3bis_comp}\n\tThe interaction matrix is negative definite.\n\\end{property}\n\\begin{proof}\n\tLet $\\b q = 0$. Since we consider an isolated domain, $\\bar C$ is a constant.\n\tConsider $\\hat{\\b c} = \\b c - \\bar C \\b 1$, the deviation of the concentration with respect to $\\bar C$. Since under those conditions,~\\eqref{eq:compartmentmatrix} is linear and homogeneous in $\\b c$, it applies to any perturbation of $\\b c$ by a constant, and thus to $\\hat{\\b c}$:\n\t\\begin{equation} \\label{eq:prp3matrix}\n\t\t\\bs \\Omega \\dot{\\hat{\\b c}} = \\b A \\hat{\\b c}.\n\t\\end{equation}\n\tThe box variance is expressed as\n\t\\begin{equation}\\label{eq:sigmamatrix}\n\t\t\\sigma^2_{box} = \\frac{1}{|\\Omega|} \\hat{\\b c}^\\t \\bs \\Omega \\hat{\\b c}.\n\t\\end{equation}\n\tA time-differentiation of~\\eqref{eq:sigmamatrix} yields\n\t\\begin{equation}\n\t\t\\frac{d \\sigma^2_{box}}{dt} = \\frac{2}{|\\Omega|} \\hat{\\b c}^\\t \\bs \\Omega \\dot{\\hat{\\b c}},\n\t\\end{equation}\n\tand finally by~\\eqref{eq:prp3matrix}\n\t\\begin{equation}\n\t\t\\frac{|\\Omega|}{2} \\frac{d \\sigma^2_{box}}{dt} = \\hat{\\b c}^\\t \\b A \\hat{\\b c}.\n\t\\end{equation}\n\tBy property~\\ref{prop3_comp}, the latter must be negative (or zero if $\\hat{\\b c} = \\b 0$), which shows that $\\b A$ is negative definite.\n\\end{proof}", "meta": {"hexsha": "69f57b1431ed7667d709050174b8baf2737ecab9", "size": 4401, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/compartments/matrixformulation.tex", "max_stars_repo_name": "dufaysr/tfe", "max_stars_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inputs/compartments/matrixformulation.tex", "max_issues_repo_name": "dufaysr/tfe", "max_issues_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inputs/compartments/matrixformulation.tex", "max_forks_repo_name": "dufaysr/tfe", "max_forks_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.4230769231, "max_line_length": 292, "alphanum_fraction": 0.667575551, "num_tokens": 1666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.742467909510828}}
{"text": "\\section{Axioms for Quantum Mechanics}\r\nNow we start to try and make the theory more mathematical.\r\n\\subsection{Vector Space and Inner Product}\r\nAs we have seen, we can collect $0$ and the set of possible wavefunctions (for fixed time $t$) as a vector space $\\mathcal H$ which is a subspace of $L^2(\\mathbb R^3,\\mathbb C)$.\r\nLinear maps involved are operators and the inner product is what we have seen earlier:\r\n\\begin{definition}\r\n    The inner product of two wavefunctions $\\psi,\\phi$ is defined by\r\n    $$(\\psi,\\phi)=\\int_{\\mathbb R^3}\\psi^*\\phi\\,\\mathrm dV$$\r\n\\end{definition}\r\n\\begin{lemma}\r\n    If $\\psi,\\phi\\in L^2(\\mathbb R^3,\\mathbb C)$, then $(\\psi,\\phi)$ exists.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Cauchy-Schwartz.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    1. $(\\psi,\\phi)=(\\phi,\\psi)^*$\\\\\r\n    2. $(\\psi,\\lambda_1\\phi_1+\\lambda_2\\phi_2)=\\lambda_1(\\psi,\\phi_1)+\\lambda_2(\\psi,\\phi_2)$ and $(\\mu_1\\psi_1+\\mu_2\\psi_2,\\phi)=\\mu_1^*(\\psi_1,\\phi)+\\mu_2^*(\\psi_2,\\phi)$.\\\\\r\n    3. $( \\psi,\\psi)\\ge 0$ and equals $0$ iff $\\psi=0$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A wavefunction $\\psi$ is normalised if $(\\psi,\\psi)=1$.\r\n    If $(\\psi,\\phi)=0$ then we say $\\psi,\\phi$ are orthogonal.\r\n    A set of wavefunctions $\\{\\psi_n\\}$ is orthogonal if $(\\psi_m,\\psi_n)=\\delta_{mn}$.\r\n    It is complete if an other wavefunction $\\phi$ can be written as\r\n    $$\\phi=\\sum_{n=0}^\\infty c_n\\psi_n$$\r\n    for some $c_n\\in\\mathbb C$.\r\n\\end{definition}\r\nIt then follows that\r\n\\begin{proposition}\r\n    If we have a complete and orthogonal set of wavefunctions $\\{\\psi_n\\}$ and $\\phi=\\sum_n c_n\\psi_n$, then $c_n=(\\psi_n,\\phi)$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Straight from definition.\r\n\\end{proof}\r\nThe probabilistic interpretation of inner product is that if we take $\\phi$ to be the desired outcome of a measurement and $\\psi$ is the actual state of the particle at the time of measurement, then $|( \\psi,\\phi)|^2$ can be taken as the probability of measuring $\\phi$ as an outcome, that is the overlap between the two states at time $t$.\r\n\\subsection{Hermitian Operators}\r\nAn operator on $\\mathcal H$, the vector space of possible wavefunctions and $0$, is a linear map from $\\mathcal H$ to itself (or a vector space containing it).\r\n\\begin{example}\r\n    Linear differential and translation are operators.\r\n    We can also have the parity operator $\\phi(x)\\mapsto\\psi(-x)$.\r\n\\end{example}\r\n\\begin{definition}\r\n    The Hemitian conjugate $\\hat{A}^\\dagger$ of an operator $\\hat{A}$ is an operator such that $(\\hat{A}^\\dagger\\psi_1,\\psi_2)=(\\psi_1,\\hat{A}\\psi_2)$ for any $\\psi_1,\\psi_2\\in\\mathcal H$.\r\n\\end{definition}\r\nConsequently, $(a_1\\hat{A}_1+a_2\\hat{A}_2)^\\dagger=a_1^*\\hat{A}^\\dagger+a_2^*\\hat{A}_2^\\dagger$ and $(\\hat{A}\\hat{B})^\\dagger=\\hat{B}^\\dagger\\hat{A}^\\dagger$.\r\n\\footnote{Yes, we haven't proved the existence and uniqueness of a conjugate. And yes, the lecturer still hasn't proved it.}\r\n\\begin{definition}\r\n    A Hermitian operator is an operator $\\hat{A}$ such that $(\\hat{A}\\psi_1,\\psi_2)=(\\psi_1,\\hat{A}\\psi_2)$.\r\n\\end{definition}\r\nEquivalently $\\hat{A}=\\hat{A}^\\dagger$.\r\n\\begin{example}\r\n    Physical quantities (observables) like $\\hat{x},\\hat{p},\\hat{H}$ are Hermitian operators.\r\n\\end{example}\r\n\\begin{theorem}\r\n    The eigenvalues of Hermitian operators are real.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $\\hat{A}$ be Hermitian and $\\psi$ a normalised eigenfunction of it with eigenvalue $a$, that is $\\hat{A}\\psi=a\\psi$.\r\n    Now\r\n    \\begin{align*}\r\n        a&=a(\\psi,\\psi)=( \\psi,a\\psi)=(\\psi,\\hat{A}\\psi)=( \\hat{A}^\\dagger\\psi,\\psi)=(\\hat{A}\\psi,\\psi)\\\\\r\n        &=( a\\psi,\\psi)=a^*(\\psi,\\psi)\\\\\r\n        &=a^*\r\n    \\end{align*}\r\n    So $a$ has to be real.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    Let $\\hat{A}$ be a Hermitian operator and $\\psi_1,\\psi_2$ normalised eigenfunctions with different eigenvalues $a_1\\neq a_2$, then $\\psi_1,\\psi_2$ are orthogonal.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    We have\r\n    \\begin{align*}\r\n        a_1(\\psi_1,\\psi_2 )&=a_1^*(\\psi_1,\\psi_2)=( a_1\\psi_1,\\psi_2)=( \\hat{A}\\psi_1,\\psi_2)\\\\\r\n        &=( \\hat{A}^\\dagger\\psi_1,\\psi_2)=(\\psi_1,\\hat{A}\\psi_2)=(\\psi_1,a_2\\psi_2)\\\\\r\n        &=a_2(\\psi_1,\\psi_2)\r\n    \\end{align*}\r\n    But $a_1\\neq a_2$, so it has to be the case that $(\\psi_1,\\psi_2)=0$.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    The set of eigenfunctions, discrete or continous, of any Hermitian operator forms a complete orthogonal set.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Haha.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Every solution of TDSE can be written as a superposition of the stationary states.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    The stationary states are eigenfunctions of the Hamiltonian.\r\n\\end{proof}\r\n\\subsection{Quantum Measurements}\r\nWe have a few postulates for quantum mechanics.\r\n\\begin{postulate}\r\n    1. Any quantum observable $O$ is represented by a Hermitian operator $\\hat{O}$.\\\\\r\n    2. The possible outcomes of measurement of $O$ are eigenvalues of $\\hat{O}$.\\\\\r\n    3. if $\\hat{O}$ has a discrete set $\\{\\psi_i\\}$ of normalised eigenfunctions with distinct eigenvalues $\\{\\lambda_i\\}$, then the measurement of $O$ on a particle in state $\\psi=\\sum_ia_i\\phi_i$, then the probability of outcome $\\lambda$ is $p(\\lambda_i)=|a_i|^2$.\r\n    In particular, if $\\psi=\\psi_i$, then the measurement is $\\lambda_i$ with probability $1$.\\\\\r\n    4. If $\\{\\psi_i\\}_{i\\in I}$ is a subset of the eigenfunctions with common eigenvalue $\\lambda$, then $p(\\lambda)=\\sum_{i\\in I}|a_i|^2$.\\\\\r\n    5. (consequence of 3 and 4) $\\sum_i|a_i|^2=1$.\\\\\r\n    6. (projection postulate, collapse of wavefunction) If $O$ is measured on $\\psi$ at time $t$ and outcome of the measure is $\\lambda_i$, then the wavefunction instaneously becomes $\\psi_1$ at time $t$.\\\\\r\n    7. If $\\hat{O}$ has an eigenvalue $\\lambda$ with eigenfunctions $\\{\\psi_i\\}_{i\\in I}$, then if $O$ is measured with outcome $\\lambda$ the wavefunction instaneously becomes a superposition of $\\{\\psi_i\\}_{i\\in I}$.\r\n\\end{postulate}\r\n\\begin{definition}\r\n    The projection operator $\\hat{p}_i$ sends $\\psi=\\sum_ja_j\\psi_j$ to $a_i\\psi_i$.\r\n\\end{definition}\r\n\\subsection{Expected Values}\r\nConsider the measurement of observable $O$ on state $\\psi$ and the corresponding Hermitian operator $\\hat{O}$ has a discrete set of eigenfunctions $\\{\\psi_i\\}$ with eigenvalues $\\lambda_i$, then $\\{\\lambda_i\\}$ gives us all possible outcomes of measures of $O$ with $p(\\lambda_i)=|\\langle\\psi,\\psi_i\\rangle|^2$.\r\nSo we can defined\\begin{definition}\r\n    The expected value of $O$ is\r\n    $$\\langle\\hat{O}\\rangle_\\psi=\\sum_ip_i\\lambda_i=\\sum_i|(\\psi,\\psi_i)|^2\\lambda_i=(\\psi,\\hat{O}\\psi)=\\int_{\\mathbb R^3}\\psi^*\\hat{O}\\psi\\,\\mathrm dV$$\r\n\\end{definition}\r\nThen easily $\\langle\\cdot\\rangle_\\psi$ is a linear form on the (real) vector space of Hermitian operators on $\\mathcal H$.\r\n\\subsection{Commutators}\r\n\\begin{definition}\r\n    The commutator of two operators $\\hat{A},\\hat{B}$ is the operator $[\\hat{A},\\hat{B}]=\\hat{A}\\hat{B}-\\hat{B}\\hat{A}$.\r\n    Correspondingly, the anti-commutator is $\\{\\hat{A},\\hat{B}\\}=\\hat{A}\\hat{B}+\\hat{B}\\hat{A}$\r\n\\end{definition}\r\nEasly $[\\cdot,\\cdot]$ is a antisymmetric and\r\n$$[\\hat{A},\\hat{B}\\hat{C}]=[\\hat{A},\\hat{B}]\\hat{C}+\\hat{B}[\\hat{A},\\hat{C}],[\\hat{A}\\hat{B},\\hat{C}]=\\hat{A}[\\hat{B},\\hat{C}]+[\\hat{A},\\hat{C}]\\hat{B}$$\r\n\\begin{example}\r\n    We have $[\\hat{x},\\hat{p}]=i\\hbar\\hat{I}$ where $\\hat{I}$ is the identity operator.\r\n\\end{example}\r\n\\begin{definition}\r\n    Two Hemitian operators $\\hat{A},\\hat{B}$ are simultaneously diagonalisable in $\\mathcal H$ if there is a complete basis of joint eigenfunctions $\\{\\psi_i\\}$ with $\\hat{A}\\psi_i=a_i\\psi_i$ and $\\hat{B}\\psi_i=b_i\\psi_i$ for all $i$ where $a_i,b_i$ are the respective eigenvalues.\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Two Hemitian operators $\\hat{A}$ and $\\hat{B}$ are simultaneously diagonalisable iff $[\\hat{A},\\hat{B}]=0$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    The ``only if'' direction is trivial.\r\n    Conversely, if $[\\hat{A},\\hat{B}]=0$, then $\\hat{A}\\hat{B}=\\hat{B}\\hat{A}$, so $A(B\\psi_i)=a_i(\\hat{B}\\psi_i)$ for all $i$.\r\n    This means that $\\hat{B}$ maps any eigenspace $E$ of $\\hat{A}$ to itself.\r\n    But $\\hat{B}$ is also Hermitian on $E$, so we can have an eigenspace $E$ in which $\\hat{B}$ acts diagonally.\r\n    Collect them together gives the desired complete set of basis.\r\n\\end{proof}\r\n\\subsection{Heisenberg's Uncertainty Principle}\r\n\\begin{definition}\r\n    The uncertainty in mass of $A$ on a state $\\psi$ is defined as\r\n    $$(\\Delta_\\psi A)^2=\\langle (\\hat{A}-\\langle\\hat{A}\\rangle_\\psi\\hat{I})^2\\rangle_\\psi=\\langle\\hat{A}^2\\rangle_\\psi-(\\langle\\hat{A}\\rangle_\\psi)^2$$\r\n    where $\\hat{I}$ is the identity operator.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    $(\\Delta_\\psi A)^2\\ge 0$ and $\\Delta_\\psi A=0$ iff $\\psi$ is an eigenfunction of $\\hat{A}$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Write $\\phi=(\\hat{A}-\\langle\\hat{A}\\rangle_\\psi\\hat{I})\\psi$, then\r\n    \\begin{align*}\r\n        (\\Delta_\\psi A)^2&=\\langle (\\hat{A}-\\langle\\hat{A}\\rangle_\\psi\\hat{I})^2\\rangle_\\psi\\\\\r\n        &=((\\hat{A}-\\langle\\hat{A}\\rangle_\\psi\\hat{I})\\psi,(\\hat{A}-\\langle\\hat{A}\\rangle_\\psi\\hat{I})\\psi)\\\\\r\n        &=(\\phi,\\phi)\\ge 0\r\n    \\end{align*}\r\n    and equality holds iff $\\phi=0$ which happens iff $\\phi=0$, but this is just another way of saying $\\phi$ is an eigenfunction of $\\hat{A}$.\r\n\\end{proof}\r\n\\begin{theorem}[Schwartz Inequality]\r\n    If $\\phi,\\psi$ are any two normalisable wavefunctions, then $|(\\phi,\\psi)|^2\\le(\\phi,\\phi)(\\psi,\\psi)$ with equality iff $\\phi,\\psi$ are linearly dependent.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Just copy the proof of the usual Cauchy-Schwartz Inequality.\r\n\\end{proof}\r\nSo we can safely write $\\Delta_\\psi A=\\sqrt{(\\Delta_\\psi A)^2}$.\r\n\\begin{theorem}[Generalised Uncertainty Theorem]\r\n    If $A,B$ are observables and $\\phi\\in\\mathcal H$, then\r\n    $$(\\Delta_\\psi A)(\\Delta_\\psi B)\\ge\\frac{1}{2}|(\\psi,[\\hat{A},\\hat{B}]\\psi)|$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Write $\\hat{A}'=\\hat{A}-\\langle\\hat{A}\\rangle_\\psi\\hat{I}$ which is also Hermitian, then we have $(\\Delta_\\psi A)^2=(\\hat{A}'\\psi,\\hat{A}'\\psi)$.\r\n    Similarly $\\hat{B}'=\\hat{B}-\\langle\\hat{B}\\rangle_\\psi\\hat{I}$ gives $(\\Delta_\\psi B)^2=(\\hat{B}'\\psi,\\hat{B}'\\psi)$.\r\n    Note that we have $[\\hat{A}',\\hat{B}']=[\\hat{A},\\hat{B}]$.\r\n    So Schwartz Inequality gives\r\n    $$(\\Delta_\\psi A)^2(\\Delta_\\psi B)^2=(\\hat{A}'\\psi,\\hat{A}'\\psi)(\\hat{B}'\\psi,\\hat{B}'\\psi)\\ge|(\\hat{A}'\\psi,\\hat{B}'\\psi)|^2=|(\\psi,\\hat{A}'\\hat{B}'\\psi)|^2$$\r\n    But we can write $\\hat{A}'\\hat{B}'=([\\hat{A}',\\hat{B}']+\\{\\hat{A}',\\hat{B}'\\})/2$.\r\n    Consequently,\r\n    $$(\\Delta_\\psi A)^2(\\Delta_\\psi B)^2\\ge \\frac{1}{4}|(\\psi,[\\hat{A}',\\hat{B}']\\psi)+(\\psi,\\{\\hat{A}',\\hat{B}'\\}\\psi) |^2$$\r\n    But\r\n    $$(\\psi,\\{\\hat{A}',\\hat{B}'\\}\\psi)=(\\{\\hat{A}',\\hat{B}'\\}^\\dagger\\psi,\\psi)=(\\{\\hat{A}',\\hat{B}'\\}\\psi,\\psi)=(\\psi,\\{\\hat{A}',\\hat{B}'\\}\\psi)^*$$\r\n    so $(\\psi,\\{\\hat{A}',\\hat{B}'\\}\\psi)$ has to be real.\r\n    Similarly $(\\psi,[\\hat{A}',\\hat{B}']\\psi)$ has to be purely imaginary.\r\n    Therefore\r\n    \\begin{align*}\r\n        (\\Delta_\\psi A)^2(\\Delta_\\psi B)^2&\\ge \\frac{1}{4}|(\\psi,[\\hat{A}',\\hat{B}']\\psi)+(\\psi,\\{\\hat{A}',\\hat{B}'\\}\\psi) |^2\\\\\r\n        &=\\frac{1}{4}|(\\psi,[\\hat{A}',\\hat{B}']\\psi)|^2+|(\\psi,\\{\\hat{A}',\\hat{B}'\\}\\psi) |^2\\\\\r\n        &\\ge\\frac{1}{4}|(\\psi,[\\hat{A}',\\hat{B}']\\psi)|^2\\\\\r\n        &=\\frac{1}{4}|(\\psi,[\\hat{A},\\hat{B}]\\psi)|^2\r\n    \\end{align*}\r\n    Taking square root on both sides shows the theorem.\r\n\\end{proof}\r\nIf $[\\hat{A},\\hat{B}]=0$, then the bound is just zero.\r\nThis is interpreted as we can measure $A,B$ simultaneously.\r\n\\begin{corollary}[Heisenberg's Uncertainty Principle]\r\n    $$(\\Delta_\\psi x)(\\Delta_\\psi p)\\ge\\frac{\\hbar}{2}$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Just take $\\hat{A}=\\hat{x},\\hat{B}=\\hat{p}$ and be reminded that $[\\hat{x},\\hat{p}]=i\\hbar\\hat{I}$.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. We can see a particle with light of wavelength $\\lambda\\sim\\Delta x$ around its de Broglie wavelength $h/p$, so $\\Delta p\\sim p\\sim\\hbar/(\\Delta x)$ which means $\\Delta x\\Delta p\\sim h=2\\pi\\hbar>\\hbar/2$.\\\\\r\n    2. Consider the unnormalisable plane wave solution $\\psi_p=e^{ipx/\\hbar}$ for a free particle, then $\\Delta_{\\psi_p}p=0,\\Delta_{\\psi_p}x=\\infty$.\r\n    Recall that we need to make a certain superposition of it normalisable by introducing the Gaussian wavepackage\r\n    $$\\psi_{\\rm GP}(x,t)=\\sqrt[4]{\\frac{\\sigma}{\\pi(\\sigma^2+\\hbar^2t^2/m^2)}}\\exp\\left( -\\frac{\\sigma(x-\\hbar k_0t/m)^2}{2(\\sigma^2+\\hbar^2t^2/m^2)} \\right)$$\r\n    where we actually have $(\\Delta_{\\psi_{\\rm GP}}x)(\\Delta_{\\psi_{\\rm GP}}p)=\\hbar/2$.\r\n\\end{example}\r\nWe can obtain the equality in the second example by calculation of course, but the gist is actually the following:\r\n\\begin{lemma}\r\n    If $\\hat{x}\\psi=ia\\hat{p}\\psi$ for some $a\\in\\mathbb R$, then $(\\Delta_\\psi x)(\\Delta_\\psi p)=\\hbar/2$.\r\n\\end{lemma}\r\nThis condition is easily seen to be necessary.\r\n\\begin{proof}\r\n    The condition shows that we have the equality case in Schwartz inequality in the proof of the preceding theorem.\r\n    Furthermore,\r\n    \\begin{align*}\r\n        (\\psi,\\{\\hat{x},\\hat{p}\\}\\psi)&=(\\psi,\\hat{x}\\hat{p}\\psi)+(\\psi,\\hat{p}\\hat{x}\\psi)\\\\\r\n        &=(\\hat{x}\\psi,\\hat{p}\\psi)+(\\hat{p}\\psi,\\hat{x}\\psi)\\\\\r\n        &=(ia\\hat{p}\\psi,\\hat{p}\\psi)+(\\hat{p}\\psi,ia\\hat{p}\\psi)\\\\\r\n        &=(-ia+ia)(\\hat{p}\\psi,\\hat{p}\\psi)\\\\\r\n        &=0\r\n    \\end{align*}\r\n    which implies the lemma.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    $\\hat{x}\\psi=ia\\hat{p}\\psi$ iff $\\psi(x)\\propto e^{-bx^2}$ for some $b>0$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\n\\subsection{Ehrenfest's Theorem}\r\n\\begin{theorem}[Ehrenfest's Theorem]\r\n    Let $\\hat{A}$ be an operator, then\r\n    $$\\frac{\\mathrm d}{\\mathrm dt}\\langle\\hat{A}\\rangle_\\psi=\\frac{i}{\\hbar}\\langle [\\hat{H},\\hat{A}]\\rangle_\\psi+\\langle\\partial\\hat{A}/\\partial t\\rangle_\\psi$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Just expand.\r\n    \\begin{align*}\r\n        \\frac{\\mathrm d}{\\mathrm dt}\\langle\\hat{A}\\rangle_\\psi&=\\frac{\\mathrm d}{\\mathrm dt}\\int_{-\\infty}^\\infty\\psi^*\\hat{A}\\psi\\,\\mathrm dx\\\\\r\n        &=\\int_{-\\infty}^\\infty\\frac{\\mathrm d}{\\mathrm dt}(\\psi^*\\hat{A}\\psi)\\,\\mathrm dx\\\\\r\n        &=\\int_{-\\infty}^\\infty \\left( \\frac{\\partial\\psi^*}{\\partial t}\\hat{A}\\psi+\\psi^*\\hat{A}\\frac{\\partial\\psi}{\\partial t} \\right)\\,\\mathrm dx+\\langle\\partial\\hat{A}/\\partial t\\rangle_\\psi\\\\\r\n        &=\\frac{i}{\\hbar}\\int_{-\\infty}^\\infty (\\psi^*\\hat{H}\\hat{A}\\psi-\\psi^*\\hat{A}\\hat{H}\\psi)\\,\\mathrm dx+\\langle\\partial\\hat{A}/\\partial t\\rangle_\\psi\\\\\r\n        &=\\frac{i}{\\hbar}\\langle[\\hat{H},\\hat{A}]\\rangle_\\psi+\\langle\\partial\\hat{A}/\\partial t\\rangle_\\psi\r\n    \\end{align*}\r\n    which is what we wanted.\r\n\\end{proof}\r\n\\begin{example}\r\n    Take $\\hat{A}=\\hat{H}$, then $[\\hat{H},\\hat{H}]=0$, so $\\mathrm d\\langle\\hat{H}\\rangle_\\psi/\\mathrm dt=0$ which is equivalent to the conservation of total energy in quantum mechanics.\\\\\r\n    Take $\\hat{A}=\\hat{p}$, then $[\\hat{H},\\hat{p}]=i\\hbar\\partial U/\\partial x$, therefore,\r\n    $$\\frac{\\mathrm d\\langle\\hat{p}\\rangle_\\psi}{\\mathrm dt}=-\\left\\langle\\frac{\\mathrm dU}{\\mathrm dx}\\right\\rangle_\\psi$$\r\n    which is analogous to the classical case.\\\\\r\n    Take $\\hat{A}=\\hat{x}$, ten we obtain $[\\hat{H},\\hat{x}]=-i\\hbar\\hat{p}/m$,\r\n    $$\\frac{\\mathrm d\\langle\\hat{x}\\rangle_\\psi}{\\mathrm dt}=\\frac{\\langle\\hat{p}\\rangle_\\psi}{m}$$\r\n    which is again analogous to classical mechanics.\r\n\\end{example}\r\n\\subsection{The Harmonic Oscillator Revisited}\r\nFor a harmonic oscillator, the Hamiltonian is\r\n\\begin{align*}\r\n    \\hat{H}&=\\frac{\\hat{p}^2}{2m}+\\frac{1}{2}m\\omega^2\\hat{x}^2\\\\\r\n    &=\\frac{1}{2m}(\\hat{p}+im\\omega\\hat{x})(\\hat{p}-im\\omega\\hat{x})+\\frac{i\\omega}{2}[\\hat{p},\\hat{x}]\\\\\r\n    &=\\frac{1}{2m}(\\hat{p}+im\\omega\\hat{x})(\\hat{p}-im\\omega\\hat{x})+\\frac{\\hbar\\omega}{2}\r\n\\end{align*}\r\nWrite $\\hat{a}=(\\hat{p}-im\\omega\\hat{x})/\\sqrt{2m}$ (called the ladder operator), then $\\hat{a}^\\dagger=(\\hat{p}+im\\omega\\hat{x})/\\sqrt{2m}$ and $\\hat{H}=\\hat{a}^\\top\\hat{a}+\\hbar\\omega/2$.\r\nAlso $[\\hat{a},\\hat{a}^\\dagger]=\\hbar\\omega\\hat{I}$, therefore $\\hat{a}$ is Hermitian.\r\nIn addition $[\\hat{H},\\hat{a}]=-\\hbar\\omega\\hat{a}$ and $[\\hat{H},\\hat{a}^\\dagger]=\\hbar\\omega\\hat{a}^\\dagger$.\r\nSuppose $X$ is an eigenfunction of $\\hat{H}$ with eigenvalue $E$, that is $\\hat{H}X=EX$, then $\\hat{H}\\hat{a}X=[\\hat{H},\\hat{a}]X+\\hat{a}\\hat{H}X=(-\\hbar\\omega+E)\\hat{a}X$.\r\nSimilarly $\\hat{a}^\\dagger =(E+\\hbar\\omega)\\hat{a}^\\dagger X$.\r\nThen by induction $\\hat{a}^nX$ is an eigenfunction of $\\hat{H}$ with eigenvalue $E-n\\hbar\\omega$ and $\\hat{a}^\\dagger X$ an eigenfunction with eigenvalue $E+n\\hbar\\omega$.\r\nFor $U\\ge 0$, we have $\\langle H\\rangle_\\psi\\ge 0$, so we can choose the lowest positive eigenfunction $X_0$ and we must then have $\\hat{a}X_0=0$.\r\nThis is just a first order differential equation, which can be easily solved to give $X_0(x)\\propto\\exp(-m\\omega x^2/(2\\hbar))$.\r\nSo $X_0$ has eigenvalue $\\hbar\\omega/2$.\r\nTo find the excited states, we simply need to compute\r\n$$X_n=(\\hat{a}^\\dagger)^nX_0\\propto\\frac{1}{\\sqrt{2m}}(\\hat{p}+im\\omega\\hat{x})^n\\exp(-m\\omega x^2/(2\\hbar))$$\r\nwhich involves Hermite polynomials.\r\nThey then have eigenvalue $E_n=(n+1/2)\\hbar\\omega$.", "meta": {"hexsha": "a4f85749765a54d900ae6064e65a8d8f3952268c", "size": 17216, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/axiom.tex", "max_stars_repo_name": "david-bai-notes/IB-Quantum-Mechanics", "max_stars_repo_head_hexsha": "8689057b154bdd3fbc6c9270e023b87583904427", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4/axiom.tex", "max_issues_repo_name": "david-bai-notes/IB-Quantum-Mechanics", "max_issues_repo_head_hexsha": "8689057b154bdd3fbc6c9270e023b87583904427", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4/axiom.tex", "max_forks_repo_name": "david-bai-notes/IB-Quantum-Mechanics", "max_forks_repo_head_hexsha": "8689057b154bdd3fbc6c9270e023b87583904427", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.0622710623, "max_line_length": 341, "alphanum_fraction": 0.6389986059, "num_tokens": 6212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7424678986921712}}
{"text": "\\lab{Trust-Region Methods}{Trust-Region Methods}\n\\label{lab:trust_region}\n\n\\objective{Explore Trust-Region methods for optimization.}\n\nWhen it comes to optimizing high-dimensional functions, a common strategy is to break\nthe problem up into a series of smaller, easier tasks, leading to a sequence of\nsuccessive approximations to the optimizer. This is the approach taken by Line-Search\nalgorithms such as Newton's method, as discussed in Lab \\ref{lab:line_search}.\nThe class of algorithms known as Trust-Region methods are also based on this\nstrategy, although they differ from Line-Search methods in some important ways.\n\n\\section*{Overview of the Trust-Region Approach}\nSuppose we have a function $f$ that we wish to minimize over its entire domain.\nGive that we have some particular point $x_k$ in the domain of $f$, how do we\nselect a new point $x_{k+1}$ that better minimizes the function? A Line-Search\nalgorithm solves this sub-problem by first choosing a search direction $d_k$ \n(often related to the gradient of $f$), and then a step length $\\alpha_k$ so\nas to minimize $f$ along the direction $d_k$. The next point, then, is simply\n\\[\nx_{k+1} := x_k + \\alpha_k d_k.\n\\]\n\nA Trust-Region algorithm, on the other hand, does away with a search direction and \nstep length, and instead approximates the function $f$ with some simpler function\n$m_k$ (called the \\emph{model function}). The model $m_k$ will likely not be close to $f$ over the entire\ndomain, and so we must restrict our attention to a ball of radius $r_k$ centered at\nthe point $x_k$, inside of which $m_k$ is reasonably close to $f$. We then minimize\n$m_k$ over this ball, and set $x_{k+1}$ equal to this minimizer. That is, solve the sub-problem\n\\[\nx_{k+1} := \\underset{x \\in B(x_k, r_k)}{\\text{argmin}} m_k(x).\n\\]\nThe ball $B(x_k, r_k)$ is called the \\emph{trust region} because we trust that the\nmodel function $m_k$ gives a reasonably accurate approximation of $f$ on this region.\nNote that it is also possible to use other types of trust regions, such as \nellipsoidal or box-like regions. \n\n\\subsection*{The Model Function}\nThe model function $m_k$ is commonly taken to be a linear or quadratic approximation of\n$f$ based on its Taylor Series expansion about the point $x_k$. In the linear case,\nour model function has the form\n\\[\nm_k(y) = f(x_k) + (y-x_k)^T \\nabla f(x_k).\n\\] \nIn the quadratic case, we simply add on a quadratic term to obtain\n\\[\nm_k(y) = f(x_k) + (y-x_k)^T \\nabla f(x_k) + \\frac{1}{2}(y - x_k)^T B_k (y-x_k),\n\\]\nwhere $B_k$ is the Hessian matrix of $f$ at $x_k$, or some approximation thereof.\nGiven a trust region with radius $r_k$, note that our sub-problem can be \nwritten in the following way:\n\\begin{align*}\nx_{k+1} &= \\underset{x \\in B(x_k, r_k)}{\\text{argmin}} m_k(x)\\\\\n&= x_k + \\underset{\\|p\\| < r_k}{\\text{argmin}}\\, \\{f(x_k) + p^T \\nabla f(x_k) + \\frac{1}{2}p^T B_k p\\}.\n\\end{align*}\n\n\\subsection*{The Trust-Region}\nDiscuss how choice of the radius $r_k$ can have large impact on performance of the algorithm. Balance between\ntoo small and too large of a trust region. How to determine whether the radius should change in the next iteration.\n\n\\section*{The Dogleg Method}\nThis is a method to approximately solve the sub-problem, appropriate when the model Hessian is positive definite.\nSciPy has an implementation of this algorithm in the optimization package.\n\n\n\\section*{Newton-CG Trust-Region Method}\nThis is a trust-region approach to the Newton-CG algorithm for large unconstrained optimization.\nSciPy has an implementation of this algorithm in the optimization package.\n\n\\section*{Levenberg-Marquardt Algorithm}\nThis is a trust-region approach to the Gauss-Newton method for nonlinear least squares.\n", "meta": {"hexsha": "411f4c5c1b184463ace1a174a237e7a793fcbe16", "size": 3710, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/TrustRegion/TrustRegion.tex", "max_stars_repo_name": "m4webb/numerical_computing", "max_stars_repo_head_hexsha": "d26e5ace9dbb91cd87440d84f0bd05d4a46e6781", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/TrustRegion/TrustRegion.tex", "max_issues_repo_name": "m4webb/numerical_computing", "max_issues_repo_head_hexsha": "d26e5ace9dbb91cd87440d84f0bd05d4a46e6781", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/TrustRegion/TrustRegion.tex", "max_forks_repo_name": "m4webb/numerical_computing", "max_forks_repo_head_hexsha": "d26e5ace9dbb91cd87440d84f0bd05d4a46e6781", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-12-08T01:19:23.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T01:19:23.000Z", "avg_line_length": 51.5277777778, "max_line_length": 115, "alphanum_fraction": 0.7504043127, "num_tokens": 1013, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.8840392725805822, "lm_q1q2_score": 0.7423577917592777}}
{"text": "\\section{Features}\n\nFeatures are sources of information that hopefully allow conclusions towards some kind of quantity of interest. Some people like to call them independent variables.\n\n\\subsection{Dense Features, Sparse Features}\nSparsity and density refer to the fraction of a matrix that is zeros. In the context of features, sparse features typically refer to feature vectors that have many zeros in them. I.e., $[1,2,5,2,6,3,0]$ would be a dense feature vector and $[2,0,0,0,0,3,0,0,1]$ would be a sparse feature vector. Typically, sparsity is touted as an advantage because it allows for lossless compressed representations of high-dimensional data, which has computational advantages. Another advantage, though, is that sparse representations can be more interpretable by containing information in an inherently more condensed fashion. They are also thought to prevent overfitting: many regularization techniques aim to minimize the number of parameters or features used in a predictive model, which amounts to biasing an algorithm towards learning sparse coefficients. An example is ridge regression. \n\n\\section{Multicollinearity}\nSo far this section is based on \\citeasnoun{ncssridgeregression}.\n\nMulticollinearity, or collinearity, occurs when features are linearly correlated with each other. The effects are horrible. They include inaccurate estimates of the regression coefficients, higher standard errors of the regression coefficients, lower partial t-tests for the regression coefficients, falsely insignificant p-values and decreased predictive power of the model. And other things.\n\n\\subsubsection{Detection}\n\n\\subparagraph{Scatter Plots}\nScatterplots provide a visual test for collinearity by hopefully exposing relationships between independent variables. This is subjective and unreliable, but people love plots.\n\n\\subparagraph{Variance Inflation Factors (VIF)}\nA VIF over 10 it said to indicate collinear variables.\n\n\\subparagraph{Eigenvalues of the Correlation Matrix}\nLinear relationships between two or more variables cause the corresponding rows of the correlation matrix to be identical or very similar. Correspondingly, the matrix will be singular or near-singular, which will manifest itself through zero or near-zero eigenvalues. The conditioning number, given by the largest eigenvalue divided by the smallest eigenvalue, are a quick way to test for this. A large conditioning number indicates collinearity.\n\n\\subparagraph{Regression Coefficients}\nCollinearity increases the standard error of the regression coefficients because it allows for the variation of the dependent variable to be explained in terms of a greater variety of different weights assigned to the collinear variables. Counterintuitive results for the regression coefficients may be the result of collinearity. \n\n\\subsection{Sources}\n\n\\subparagraph{Data Collection}\n\\subparagraph{Physical Constraints}\n\\subparagraph{Over-defined Model}\n\\subparagraph{Model Choice or Specification}\n\\subparagraph{Outliers}\n\n\\subsubsection{Remedies}\n\n\\subparagraph{Dimensionality Reduction}\nSVD, PCA, NNMF and other dimensionality reduction techniques allow for the feature space to be shrunk in a way that aims to optimally preserve information. Any technique worth its salt will either collapse or filter collinear variables into a reduced-rank representation of the information in the dataset.\n\n\\subparagraph{Regularization}\nCertain forms of regularization are similar in spirit to dimensionality reduction, except that, rather than addressing the dataset, they reduce the parameters used by a model to fit to the data. The canonical example is ridge regression. Ridge regression penalizes the use of a larger number of parameters and, if two variables are collinear, will tend to push the weight of one of them towards zero. It is important to standardize the variables before fitting the model, so that the regression weights for different variables are on the same scale. Ridge regression remains controversial \\cite{ncssridgeregression}. \n", "meta": {"hexsha": "0980153758ffa3c2ebfc7489f853229d4249695b", "size": 4026, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/stats_features.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/stats_features.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/stats_features.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 95.8571428571, "max_line_length": 878, "alphanum_fraction": 0.826626925, "num_tokens": 800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7422948505799946}}
{"text": "\\problemname{Study Pair}\n%\\illustration{.5}{filename}{Image by \\href{url}{Author}}\n\nThere are two classes, class $A$ and class $B$.\nEach class has $N$ students.\nThe teacher wants to make study pairs between the two classes.\nEach study pair consists of one student from class $A$ and the other from class $B$.\nEvery student's knowledge level on the course topic can be described as an integer.\nNamely, the $i$-th student from class $A$ has knowledge level $A_i$, and the $i$-th student from class $B$ has knowledge level $B_i$.\nTo achieve best study results, the knowledge levels of the two students in a study pair shall not differ too much.\nBesides, the sum of the knowledge levels of the two students in a pair shall not be too large (Let strong students help the others!).\nMore formally, given two constants $X, Y$, for every study pair $(A_i, B_j)$, it must satisfy $|A_i - B_j| \\leq X$ and $A_i + B_j \\leq Y$.\n\n\nThe teacher wonders what is the maximum number of study pairs she can make?\n\n\n\\section*{Input}\n\nThe first line of the input has an integer $T$, the number of test cases.\\\\\nEach case has three lines.\nThe first line has three integers $N, X, Y$.\nThe second line has $N$ integers, $A_1, A_2, ... A_N$.\nThe third line has $N$ integers, $B_1, B_2, ... B_N$.\n\n\\section*{Output}\n\nFor each case, output the maximum number of study pairs that can be made.\n\n\\section*{Constraints}\n\\begin{itemize}\n\\item $1 \\leq T\\leq 15$\n\\item $1 \\leq N \\leq 10^5$\n\\item $0 \\leq X, Y \\leq 10^9$\n\\item $0 \\leq A_i, B_i \\leq 10^9$ for $1\\leq i \\leq N$\n\\end{itemize}\n\n\\section*{Subtasks}\n\\begin{itemize}\n\\item $N \\leq 50$\n\\item Original constraints\n\\end{itemize}\n", "meta": {"hexsha": "a8c1436e2fb49a46a9904b2cdcb72a3b2ff256ec", "size": 1650, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "server/test_root/problem/studypair/problem_statement/problem.en.tex", "max_stars_repo_name": "yubowenok/coda", "max_stars_repo_head_hexsha": "29f2fd090c644b9dc1f4fa506da2dee1bd4f4102", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-09-27T04:45:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-12T01:31:40.000Z", "max_issues_repo_path": "server/test_root/problem/studypair/problem_statement/problem.en.tex", "max_issues_repo_name": "yubowenok/coda", "max_issues_repo_head_hexsha": "29f2fd090c644b9dc1f4fa506da2dee1bd4f4102", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-07-18T09:28:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-10T16:03:33.000Z", "max_forks_repo_path": "server/test_root/problem/studypair/problem_statement/problem.en.tex", "max_forks_repo_name": "yubowenok/coda", "max_forks_repo_head_hexsha": "29f2fd090c644b9dc1f4fa506da2dee1bd4f4102", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-29T20:59:27.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-29T20:59:27.000Z", "avg_line_length": 38.3720930233, "max_line_length": 138, "alphanum_fraction": 0.7175757576, "num_tokens": 505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8459424411924674, "lm_q1q2_score": 0.7422948502711681}}
{"text": "\n\\section{The \\maxelement algorithm}\n\\Label{sec:maxelement}\n\nThe \\maxelement algorithm in the \\cxx Standard Library \\cite[\\S 28.7.8]{cxx-17-draft}\nsearches the maximum of a general sequence. \nThe signature of our version of \\maxelement reads:\n\n\\begin{lstlisting}[style = acsl-block]\n\n  size_type max_element(const value_type* a, size_type n);\n\\end{lstlisting}\n\nThe function finds the largest element in the range\n\\inl{a[0..n-1]}.\nMore precisely, it returns the unique valid index \\inl{i} such that:\n\\begin{enumerate}\n\\item for each index \\inl{k} with \\inl{0 <= k < n} the condition\n\\inl{a[k] <= a[i]} holds and\n\\item for each index \\inl{k} with \\inl{0 <= k < i} the condition\n\\inl{a[k] < a[i]} holds.\n\\end{enumerate}\nThe return value of \\maxelement is \\inl{n} if and only if there is no\nmaximum, which can only occur if \\inl{n == 0}.\n\n\\subsection{Formal specification of \\maxelement}\n\nThe following listings shows the formal specification of \\specref{maxelement}.\nNote that we have subdivided the specification of \\maxelement into the two\nbehaviors~\\inl{empty} and \\inl{not_empty}.\nThe behavior \\inl{empty} contains the specification for the case that the\nrange contains no elements.\nThe behavior \\inl{not_empty} applies if the range has a positive length.\n\nThe ensures clause \\inl{max} of behavior \\inl{not_empty} indicates that\nthe returned valid index \\inl{k} refers to a maximum value of the array.\nThe postcondition \\inl{first} expresses that \\inl{k} is indeed the\n\\emph{first} occurrence of a maximum value in the array.\n\n\\input{Listings/max_element.h.tex}\n\n\\subsection{Implementation of \\maxelement}\n\nIn our description, we concentrate on the \\emph{loop annotations}\nof the implementation of \\implref{maxelement}.\n\n\\input{Listings/max_element.c.tex}\n\nThe loop invariant \\inl{max} is needed to prove the  postcondition\n\\inl{result} of the behavior \\inl{not_empty} of \\specref{maxelement}.\nUsing loop invariant \\inl{upper} we prove the postcondition \\inl{upper}\nof the behavior \\inl{not_empty} of \\specref{maxelement}.\nFinally, the postcondition \\inl{first} of this behavior can be\nverified with the loop invariant \\inl{first}.\n\n\\clearpage\n\n", "meta": {"hexsha": "bd9dd9b8537489f0bdc7705db8909ad918caf6e7", "size": 2146, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/maxmin/max_element.tex", "max_stars_repo_name": "fraunhoferfokus/acsl-by-example", "max_stars_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2017-06-14T04:17:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T06:07:36.000Z", "max_issues_repo_path": "Informal/maxmin/max_element.tex", "max_issues_repo_name": "fraunhoferfokus/acsl-by-example", "max_issues_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-10-18T13:30:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T07:10:16.000Z", "max_forks_repo_path": "Informal/maxmin/max_element.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 37.0, "max_line_length": 85, "alphanum_fraction": 0.7618825722, "num_tokens": 606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.8774767890838836, "lm_q1q2_score": 0.7422948468231129}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS622: Theory of Formal Languages\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 2}\n\nLet $A$ be an alphabet and let $b$ be a symbol such that $b \\notin A$.\n\n\\begin{enumerate}[label=(\\alph*)]\n\t\\item construct a transition system that accepts the language $ L = b A^* b $.\n\t\\item construct an equivalent deterministic finite automaton that accepts $L$.\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}[label=(\\alph*)]\n\n\t\\item\n\tA transition system that accepts the language $b A^* b$ is shown in Figure \\ref{fig:DR2}.\n\tStarting from initial state $q_0$, a word is accepted by this transition system only if it starts with $b$, follows a possible number of symbols in alphabet $A$ and end with $b$.\n\n\t\\begin{figure}[H]\\centering\n\t\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,semithick]\n\t\t\t\\tikzstyle{final}=[circle,thick,draw=black,fill=gray!40,text=black]\n\t\t\t\\node[state,initial] (0) {$q_0$};\n\t\t\t\\node[state] (1) [right of=0] {$q_1$};\n\t\t\t\\node[state, final] (2) [right of=1] {$q_2$};\n\t\t\t\\path\n\t\t\t\t(0) edge [bend left=0] node {b} (1)\n\t\t\t\t(1) edge [loop above] node {$A$} (1)\n\t\t\t\t\tedge [bend left=0] node {b} (2);\n\t\t\\end{tikzpicture}\n\t\t\\caption{Graph of a transition system that accepts the language $bA^*b$}\n\t\t\\label{fig:DR2}\n\t\\end{figure}\n\n\t\\item\n\tTo achieve an equivalent \\textit{dfa} with minimal number of states, we take advantage of the fact that the transition system given in Figure \\ref{fig:DR2} has no $\\lambda$-transition.\n\tTherefore, it is also a non-deterministic finite automaton.\n\tTo construct an equivalent \\textit{dfa} from the transition system/\\textit{ndfa} given in Figure \\ref{fig:DR2}, Table \\ref{tab:TB1} is constructed where $\\mathcal{K}\\left(S\\right)$ is set of all accessible states.\n\n\t\\begin{table}[H]\\centering\n\t\t\\begin{tabular}{|c|c||c|c|}\n\t\t\t\\hline\n\t\t\tS & $\\mathcal{K}\\left(S\\right)$ & S & $\\mathcal{K}\\left(S\\right)$ \\\\\n\t\t\t\\hline\n\t\t\t$\\emptyset$ & $\\emptyset$ & $\\{q_0,q_1\\}$ & $Q$ \\\\\n\t\t\t$\\{q_0\\}$ & $Q$ & $\\{q_1,q_2\\}$ & $\\{q_1,q_2\\}$ \\\\\n\t\t\t$\\{q_1\\}$ & $\\{q_1,q_2\\}$ & $\\{q_0,q_2\\}$ & $Q$ \\\\\n\t\t\t$\\{q_2\\}$ & $\\{q_2\\}$ & $\\{q_0,q_1,q_2\\}$ & $Q$\\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\t\\caption{Accessible States From All Possible Sets of States}\n\t\t\\label{tab:TB1}\n\t\\end{table}\n\n\tBased on Table \\ref{tab:TB1}, set of states in an equivalent \\textit{dfa} will be extracted as $\\{Q,\\{q1,q2\\}, \\{q2\\}, \\emptyset\\}$ \\ref{tab:TB1}.\n\tThe equivalent \\textit{dfa} can now be constructed by assigning $Q$ as initial state and $q_2$ as final state.\n\tThe graph of such equivalent \\textit{dfa} has been given in Figure \\ref{fig:DR3}.\n\n\t\\begin{figure}[H]\\centering\n\t\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,semithick]\n\t\t\t\\tikzstyle{final}=[circle,thick,draw=black,fill=gray!40,text=black]\n\t\t\t\\node[state,initial] (0) {$Q$};\n\t\t\t\\node[state] (1) [right of=0] {$\\{q_1,q_2\\}$};\n\t\t\t\\node[state, final] (2) [right of=1] {$\\{q_2\\}$};\n\t\t\t\\node[state] (3) [right of=2] {$\\emptyset$};\n\t\t\t\\path\n\t\t\t\t(0) edge [bend right=0] node {b} (1)\n\t\t\t\t\tedge [bend left=40] node {A} (3)\n\t\t\t\t(1) edge [loop above] node {$A$} (1)\n\t\t\t\t\tedge [bend right=0] node {b} (2)\n\t\t\t\t(2) edge [bend right=0] node {$\\{b\\} \\cup A$} (3)\n\t\t\t\t(3) edge [loop right] node {$\\{b\\} \\cup A$} (3);\n\t\t\\end{tikzpicture}\n\t\t\\caption{Graph of an equivalent \\textit{dfa} that accepts te language $bA^*b$}\n\t\t\\label{fig:DR3}\n\t\\end{figure}\n\n\\end{enumerate}\n", "meta": {"hexsha": "75bb1955e8b720b41560b09200bbddc24bf4cfc6", "size": 3665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs622-2015f/src/tex/hw02/hw02q02.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs622-2015f/src/tex/hw02/hw02q02.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs622-2015f/src/tex/hw02/hw02q02.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 43.630952381, "max_line_length": 214, "alphanum_fraction": 0.62946794, "num_tokens": 1329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310355, "lm_q2_score": 0.8615382165412809, "lm_q1q2_score": 0.7422480924353829}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% UMB-CS240-2016S: Programming in C\n% Copyright 2016 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/UMB-CS240-2016S\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 1}\n\nWrite a program \\texttt{bmi.c} that takes your weight in pounds and height in inches and calculates your Body Mass Index (BMI) according to Equation \\ref{eq1}.\nTo evaluate your BMI, program should as well indicate under which group you are classified according to Table \\ref{tab1} obtained from the Department of Health and Human Services/National Institution of Health.\n\n\\begin{equation}\nBMI = \\frac{weightInPounds \\times 703}{heightInInches^2}\n\\label{eq1}\n\\end{equation}\n\n\\begin{table}[H]\\centering\n\\begin{tabular}{|r|l|}\n\\hline\nGroup & BMI index \\\\\n\\hline\nUnderweight & less than 18.5 \\\\\nNormal & between 18.5 and 24.9 \\\\\nOverweight & between 25 and 29.9 \\\\\nObese & greater than or equal to 30 \\\\\n\\hline\n\\end{tabular}\n\\caption{BMI classification}\\label{tab1}\n\\end{table}\n\nFollowing is the expected output of a sample run of your program.\n\n\\begin{terminal}\n$ gcc bmi.c -o bmi\n$ ./bmi\nYour height (in): 72\nYour weight (lb): 145\nYour BMI is 19.66.\nYou are classified as normal.\n\\end{terminal}\n", "meta": {"hexsha": "a0e3c86e538096c0927b2f5c93078e63259629a2", "size": 1384, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/main/hw03/hw03q01.tex", "max_stars_repo_name": "ghorbanzade/UMB-CS240-2016S", "max_stars_repo_head_hexsha": "c32c866cbe5f7d7044f51f2bcd689b33bda61980", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-03T18:41:24.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-03T18:41:24.000Z", "max_issues_repo_path": "src/tex/main/hw03/hw03q01.tex", "max_issues_repo_name": "ghorbanzade/UMB-CS240-2016S", "max_issues_repo_head_hexsha": "c32c866cbe5f7d7044f51f2bcd689b33bda61980", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-05-16T23:55:39.000Z", "max_issues_repo_issues_event_max_datetime": "2016-06-20T03:04:35.000Z", "max_forks_repo_path": "src/tex/main/hw03/hw03q01.tex", "max_forks_repo_name": "ghorbanzade/UMB-CS240-2016S", "max_forks_repo_head_hexsha": "c32c866cbe5f7d7044f51f2bcd689b33bda61980", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.9523809524, "max_line_length": 210, "alphanum_fraction": 0.6777456647, "num_tokens": 382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.8596637577007393, "lm_q1q2_score": 0.7422264757973513}}
{"text": "$C[a, b]$ - set of all continuous functions\n\n\\section{Metric spaces}\n\n\\begin{definition}[Metric space]\n    $X$ set. Function $d: x\\times X \\to [0, \\infty)$ is called a metric if the following condition are met:\n    \\begin{enumerate}\n        \\item $d(x, y) = 0 \\iff x = y$\n        \\item $d(x, y) = d(y, x)$\n        \\item $d(x,z) \\leq d(x,y) + d(y, z)$ - the inequality of the triangle\n    \\end{enumerate}\n\\end{definition}\n\\begin{definition}\n    $(X, d)$ - metric space.\n\\end{definition}\n\\begin{example}[Discrete space]\n    $X$ - arbitrary.\n    \\[\n    d(x, y) = \\begin{cases}\n            1 & x \\not= y \\\\\n            0 & x = y\n        \\end{cases}\n    .\\] \n\\end{example}\n\\begin{example}[Real line]\n    $X = \\mathbb{R}, \\;\\; d(x, y) = \\left| x - y \\right| $\n\\end{example}\n\\begin{example}[n-dimentional space]\n    $X = \\mathbb{R}^{n} = \\{x = \\left( x_1, \\ldots, x_n \\right) \\mid x_i \\in \\mathbb{R}, 1 \\leq i \\leq n \\} $\n    \\[\n    d(x, y) = \\sqrt{\\sum_{i=1}^{n} \\left( x_i - y_i \\right)^2 } \n    .\\] \n\\end{example}\n\n\\begin{example}\n    $d_1(x, y) = \\sum_{i=1}^{n} \\left| x_i - y_i \\right|$ - metric on $\\mathbb{R}^{n}$\n\n    \\begin{proof}\n    \\[\n    d_1(x, z) = \\sum_{i=1}^{n} \\left| x_i - z_i \\right| \\leq \\sum_{i=1}^{n} \\left( \\left| x_i - _i \\right| + \\left| y_i - z_i \\right|  \\right) =\n    d_1(x, y) + d_(y, z)\n    .\\] \n    \\end{proof}\n\n    $d_{\\infty} (x, y) = \\underset{1\\leq i \\leq n}{\\max} \\left| x_i - y_i \\right|$ - metric on $\\mathbb{R}^{n}$\n    \n    \\begin{proof}\n        \\begin{align*}\n        d_{\\infty}(x, y) = 0 \\iff \\forall i : x_i = y_i \\iff x = y \\\\ \n        d_{\\infty}(x, z) = \\underset{1\\leq i \\leq n}{\\max} \\left| x_i - z_i \\right|  \\leq d_{\\infty}(x, y) + d_{\\infty}(y, z) \\\\\n        \\left| x_i - z_i \\right| \\leq \\left| x_i - y_i \\right| + \\left| y_i - z_i \\right|        \n        .\\end{align*}\n    \\end{proof}\n    \\[\n    1 \\leq p < \\infty : d_{p} (x, y) = \\left( \\sum_{i=1}^{n} \\left| x_i - y_i \\right| ^{p} \\right) ^{\\frac{1}{p}}\n    .\\] \n    \\[\n    0 < p < 1 : d_{p}(x, y) = \\sum_{i=1}^{n} \\left| x_i - y_i \\right| ^{p}\n    .\\] \n\n\\end{example}\n\n\\begin{example}\n$C[a, b]$ set of all continuous functions.\n$f: [a, b] \\to \\mathbb{R}$\n\\[\nd(f, g) = \\underset{a \\leq t \\leq b}{\\sup} \\left| f(t) - g(t) \\right| \n.\\] \n$d(f, g)$ is a metric on $C[a, b]$.\n\\end{example}\n\n\\begin{example}\n    $C_b[\\mathbb{R}]$ - a set of all continuous and limited functions $f: \\mathbb{R} \\to \\mathbb{R}$.\n    \\[\n    d(f, g) = \\underset{t \\in \\mathbb{R}}{\\sup} \\left| f(t) - g(t) \\right| \n    .\\] \n\\end{example}\n\\begin{example}\n    $(X, d)$ - metric space, $Y \\subset X$\n    \\[\n    d(y_1, y_2), y_1, y_2 \\in Y\n    .\\] \n    $(Y, d)$ - subspace $X$.\n\\end{example}\n\n\\begin{definition}\n    $\\left( X, d \\right) $ - metric space, $\\left\\{ x_n : n\\geq 1 \\right\\} $\n    series of $X$ elements. $\\left\\{ x_n : n\\geq 1 \\right\\} $ converges to $x \\in X$ if $\\underset{n\\to\\infty}{\\lim} d(x_n, x) = 0$.\n    \\[\n        \\left( \\forall \\varepsilon > 0 \\quad \\exists N \\quad \\forall n \\geq N \\quad d(x_n, x) < \\varepsilon \\right) \n    .\\] \n    \\[\n    x = \\lim_{n \\to \\infty} x_n\n    .\\] \n\\end{definition}\n\n\\begin{theorem}\n    In metric space convergent sequence has only one boundary.\n\\end{theorem}\n\\begin{proof}\n    Let $\\lim_{n \\to \\infty} x_n = x, \\; \\lim_{n \\to \\infty} x_n = y $.\n    \\[\n    0 \\leq d(x, y) \\leq d(x, x_n) + d(x_n, y) \\to 0\n    .\\] \n    \\[\n    \\Rightarrow d(x, y) = 0 \\Rightarrow x = y\n    .\\] \n\\end{proof}\n\n$\\left( X, d_x \\right), \\left( Y, d_y \\right) $ - metric spaces. $f : X \\to Y$.\n\n\\begin{definition}\n    \\begin{enumerate}\n        \\item $f$ continuous in point $x_0 \\in X$ if \n            \\[\n            x_n \\to x_0 \\text{ in $X$ } \\Rightarrow f(x_n) \\to f\\left( x_0 \\right) \\text{ in $Y$ }\n            .\\] \n        \\item $f$ continuous on $X$ if $f$ continuous in every point $x_0 \\in X$.\n    \\end{enumerate}\n\\end{definition}\n\n\\begin{remark}\n    $f$ continuous in $x_0 \\in X$ then and only then if\n    \\[\\forall \\varepsilon > 0 \\quad \\exists \\delta > 0 : d_x(x, x_0) < \\delta \\Rightarrow d_x(f(x), f(x_0)) < \\varepsilon \\]\n\\end{remark}\n\n\\begin{definition}\n    \\begin{enumerate}\n        \\item $f: X \\to Y$ is called homeomorphism if $f$ is bijective, continuous and $f^{-1}$ is continuous.\n        \\item $f: X \\to Y$ isometric if \n            \\[\n            d_y (f(x), f(x')) = d_x(x, x')\n            .\\] \n            Isometrie is always continuous.\n    \\end{enumerate}\n\\end{definition}\n\n$x \\in X, \\;\\; r > 0$\n\\begin{definition}\n    Open ball \\[\n    \\mathbb{B}(x, y) = \\{ y \\in X : d(y, x) < r \\} \n    .\\] \n\\end{definition}\n\\begin{definition}\n    Closed ball \\[\n    \\overline{\\mathbb{B}} = \\{ y \\in X : d(y, x) \\leq r \\} \n    .\\] \n\\end{definition}\n\nConvergence can be rewritten using the last two definitions:\n\\[\nx_n \\to x \\iff \\forall \\varepsilon > 0 \\quad \\exists N \\quad\n\\forall n \\geq N \\quad x_n \\in \\mathbb{B}(x, \\varepsilon)\n.\\] \n\n\\begin{figure}[ht]\n    \\centering\n    \\incfig{convergence-in-terms-of-open-and-closed-ball-definitions}\n    \\caption{Convergence in terms of open and closed ball definitions}\n    \\label{fig:convergence-in-terms-of-open-and-closed-ball-definitions}\n\\end{figure}\n\n\\begin{definition}\n    $A \\subset X$. Point $x$ is tangent to set $A$ if \\[\n    \\forall \\varepsilon > 0 \\quad \\mathbb{B}(x, \\varepsilon) \\cap A \\not= \\varnothing\n    .\\] \n\\end{definition}\n\n\\begin{example}\n    $X = \\mathbb{R}$, $A = (a, b)$. $a$ and $b$ are tangent to $A$. \\\\\n    All elements from set $A$ are tangent to $A$. \\\\\n    If there's some $\\exists c > b$ then we can pick some ball around $c$\n    of radius $r$. In that ball there would be no elements from A.\n\\end{example}\n\\begin{figure}[ht]\n    \\centering\n    \\incfig{tangent-point-example}\n    \\caption{Tangent point example}\n    \\label{fig:tangent-point-example}\n\\end{figure}\n\n\\begin{definition}\n    $\\overline{A} = \\{ x \\in X : x \\text{ tangent to } A \\} $ closure of set $A$.\n\\end{definition}\n\n\\begin{theorem}[Properties of closure]\n    Set $A$ with closure $\\overline{A}$ has the following properties:\n    \\begin{enumerate}\n        \\item $A \\subset \\overline{A}$\n        \\item $\\overline{\\overline{A}} = \\overline{A}$ --- idempotence\n        \\item $A \\subset B \\Rightarrow \\overline{A} \\subset \\overline{B}$\n        \\item $\\overline{A \\cup B} = \\overline{A} \\cup \\overline{B}$\n    \\end{enumerate}\n\\end{theorem}\n\\begin{proof}\n    \\begin{itemize}\n        \\item[1] \\begin{align*}\n        x \\in A \\Rightarrow \\mathbb{B}(x, \\varepsilon) \\cap A \\not= \\varnothing \\text{ since it contains $x$ }\n        .\\end{align*}\n    \\item[3] \\begin{align*}\n        x \\in \\overline{A} \\Rightarrow \\mathbb{B}(x, \\varepsilon) \\cap A \\not= \\varnothing \\Rightarrow \\\\\n        \\Rightarrow \\mathbb{B}(x, \\varepsilon) \\cap B \\not= \\varnothing \\Rightarrow \n        x \\in \\overline{B}\n        .\\end{align*}\n        \\item[2] \\begin{align*}\n            \\overline{A} \\subset \\overline{\\overline{A}} \\\\\n            \\text{ need to show that } \\overline{\\overline{A}} \\subset \\overline{A} \\\\\n            x \\in \\overline{\\overline{A}}, \\varepsilon > 0. \\quad\n            \\mathbb{B}(x, \\varepsilon) \\cap \\overline{A} \\not= \\varnothing \\\\\n            \\text{ exists point } y \\in \\mathbb{B}(x, \\varepsilon) \\cap \\overline{A}.\n        .\\end{align*}\n        \\begin{figure}[ht]\n            \\centering\n            \\incfig{eps-ball-y-in-eps-ball-x-with-point-from-a}\n            \\caption{Eps-Ball Y in eps-Ball x with point from A}\n            \\label{fig:eps-ball-y-in-eps-ball-x-with-point-from-a}\n        \\end{figure}\n\n        Lets show that $\\mathbb{B}(y, \\varepsilon - d(x, y)) \\subset \\mathbb{B}(x, \\varepsilon)$.\n        \\begin{gather*}\n            z \\in \\mathbb{B}(y, \\varepsilon - d(x, y)) \\\\\n            \\text{ for $z$ the following is met } d(z, y) < \\varepsilon - d(x, y) \\\\\n            \\varepsilon > d(z, y) + d(y, x) \\geq d(z, x) \\Rightarrow\n            z \\in \\mathbb{B}(x, \\varepsilon) \\\\ \n            \\mathbb{B}(y, \\varepsilon - d(x, y)) \\cap A \\not= \\varnothing \\Rightarrow \n            \\mathbb{B}(x, \\varepsilon) \\cap A \\not= \\varnothing \\\\\n            \\Rightarrow x \\in \\overline{A}.\n        \\end{gather*}\n\n    \\item[4] \\[\n    A \\subset A \\cup B \\Rightarrow \\overline{A} \\subset \\overline{A \\cup B}; \\; \\overline{B} \\subset \\overline{A \\cup B}\n    \\] \n    \\[\n    \\Rightarrow \\overline{A} \\cup \\overline{B} \\subset \\overline{A \\cup B}\n    .\\] \n\\begin{figure}[ht]\n    \\centering\n    \\incfig{for-stupid-idiots}\n    \\caption{For stupid idiots}\n    \\label{fig:for-stupid-idiots}\n\\end{figure}\n\n    Need to prove $\\overline{A \\cup B} \\subset \\overline{A} \\cup \\overline{B}$\n\n    (by contradiction) \\\\\n    Let $x \\in \\overline{A \\cup B}$ and $x \\not\\in \\overline{A}$, $x \\not\\in \\overline{B}$.\n    \\[\n    \\exists \\varepsilon_1 > 0 : \\mathbb{B}\\left( x, \\varepsilon_1 \\right) \\cap A = \\varnothing\n    .\\] \n    \\[\n    \\exists \\varepsilon_2 > 0 : \\mathbb{B}\\left( x, \\varepsilon_2 \\right) \\cap B = \\varnothing\n    .\\] \n    \\[\n    \\varepsilon = \\min(\\varepsilon_1, \\varepsilon_2). \\quad\n    \\mathbb{B}(x, \\varepsilon) \\cap \\left( A \\cup B \\right) = \\varnothing\n    .\\] \n    \\[\n    \\Rightarrow \\overline{A \\cup B} = \\overline{A} \\cup \\overline{B}\n    .\\] \n    \\end{itemize}\n\\end{proof}\n\n\n\\begin{theorem}\n    $x \\in \\overline{A} \\iff$ in set A exists series $\\left( x_n : n \\geq 1 \\right) $ that converges to $x$.\n\\end{theorem}\n\\begin{proof}\n    \\begin{itemize}\n        \\item[($\\Rightarrow$)] Let $x\\in \\overline{A}$\n            \\[\n            \\forall \\varepsilon > 0 \\quad \\mathbb{B}(x, \\varepsilon) \\cap A \\not= \\varnothing\n            .\\] \n            let $\\varepsilon_n = \\frac{1}{n} \\quad$ \\\\\n            $\\forall n \\geq 1$ exists point $x_n \\in A \\cap \\mathbb{B}(x, \\frac{1}{n}$ \\\\\n            \\[\n            0 \\leq d(x, x_n) < \\frac{1}{n} \\to 0. \\quad \\lim_{n \\to \\infty} x_n = x\n            .\\] \n        \\item[($\\Leftarrow$)] Let $\\lim_{n \\to \\infty} x_n = x$ and $x_n \\in A$. \\\\\n            \\[\n            \\forall \\varepsilon > 0 \\quad \\exists N \\quad \\forall n \\geq N \\quad d(x_n ,x) < \\varepsilon\n            .\\] \n            \\[\n            x_n \\in \\mathbb{B}(x, \\varepsilon) \\cap A \\not= \\varnothing\n            .\\] \n            \\[\n            \\Rightarrow x \\in \\overline{A}\n            .\\] \n    \\end{itemize}\n\\end{proof}\n\n\\begin{definition}\n    A is dense in set B if $B \\subset \\overline{A}$ (any B element can be approached to elements of A)\n\\end{definition}\n\\begin{definition}\n    A dense everywhere if $\\overline{A} = X$.\n\\end{definition}\n\\begin{definition}\n    Metric space $\\left( X, d \\right) $ is separable if exists dense everywhere countable set.\n\\end{definition}\n\n\\begin{example}\n    \\begin{enumerate}\n        \\item $\\mathbb{R}$ - separable space. $\\overline{\\mathbb{Q}} = \\mathbb{R}$\n        \\item $\\mathbb{R}^{n} $ - separable space related to any metric $d_{p}, \\; 0 < p \\leq \\infty$. $\\overline{\\mathbb{Q}^{n}} = \\mathbb{R}^{n}$\n        \\item $X, d$ - discrete. $\\mathbb{B}(x, \\varepsilon) = \\{ y : d(x, y) < \\varepsilon \\} $. But if $0 < \\varepsilon < 1$ then\n            \\[\n            \\mathbb{B}(x, \\varepsilon) \\cap A \\not= \\varnothing \\iff x \\in A.\n            .\\] \n            \\[\n             \\Rightarrow \\overline{A} = A\n            .\\] \n        The only dense everywhere set is X.\n    \\item $C[a, b]$; $d(f, g) = \\underset{t \\in [a, b]}{\\sup} \\left| f(t) - g(t) \\right| $ \\\\\n        By Weierstrasse theorem $\\forall f \\in C[a, b] \\quad \\forall \\varepsilon > 0$ exists polynomial\n    \\[ P(t) = a_0 + a_1 t + \\ldots + a_d t^{d} : \\underset{t \\in [a, b]}{\\sup}\n    \\left| f(t) - P(t) \\right| < \\varepsilon \\]\n    Dense everywhere set is set of polymonials with rational coefficients.\n\n    \\item $C_{b}(\\mathbb{R}), d(f, g) = \\underset{t \\in \\mathbb{R}}{\\sup} \\left| f(t) - g(t) \\right| $ - is not separable metric space.\n\n\\begin{figure}[ht]\n    \\centering\n    \\incfig{line-for-example-of-not-separable-metric-space}\n    \\caption{Line for example of not separable metric space}\n    \\label{fig:line-for-example-of-not-separable-metric-space}\n\\end{figure}\n\n\\[ A \\subset \\mathbb{Z} \\quad f_{A}(n) =\n \\begin{cases}\n     1 & n \\in A \\\\\n     0 & n \\in \\mathbb{Z} \\backslash A\n \\end{cases}\n.\\] \n\\[\nA \\not= A' \\quad n \\in A \\backslash A' \\text{ or } n \\in A' \\backslash A\n.\\] \n\\[\nd(f_{A}, f_{A'}) = 1\n.\\] \n\\[\n\\mathbb{B}(f_{A}, \\frac{1}{2}) \\cap \\mathbb{B}(f_{A'}, \\frac{1}{2}) = \\varnothing\n.\\] \nIn space $C_b(\\mathbb{R})$ exists a continuum family of open balls that do not intersect.\n\nIf dense everywhere set exists than in every open ball must be an element of the one.\n\\begin{figure}[ht]\n    \\centering\n    \\incfig{family-of-open-balls-each-containing-an-element}\n    \\caption{Family of open balls each containing an element}\n    \\label{fig:family-of-open-balls-each-containing-an-element}\n\\end{figure}\n    \\end{enumerate}\n\\end{example}\n", "meta": {"hexsha": "ad3b4e479a42cb4dd2e9197d8aa5f1e513ac2191", "size": 12699, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cources/functional-analysis/lec_01.tex", "max_stars_repo_name": "aipyth/notes", "max_stars_repo_head_hexsha": "59066a1110ea467b2aa43518da9295f23da89a32", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cources/functional-analysis/lec_01.tex", "max_issues_repo_name": "aipyth/notes", "max_issues_repo_head_hexsha": "59066a1110ea467b2aa43518da9295f23da89a32", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cources/functional-analysis/lec_01.tex", "max_forks_repo_name": "aipyth/notes", "max_forks_repo_head_hexsha": "59066a1110ea467b2aa43518da9295f23da89a32", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.8728813559, "max_line_length": 147, "alphanum_fraction": 0.5551618238, "num_tokens": 4736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.7422264666495284}}
{"text": "\\section{Measurement Uncertainty Analysis}\n\n\\subsection{Uncertainty for natural angular frequency}\n\nTo estimate type-A uncertainty of $(10T)$,\nthe standard deviation of the average value can be calculated as\n\n\\[\n\\begin{split}\n&t_{0.95}=3.18,\\quad n=4,\\\\\n&s_{\\overline{10T}}=\\sqrt{\\frac{1}{n(n-1)}\\sum_{i=1}^n((10T)_i-\\overline{10T})^2}.\\\\ \n&\\Delta_{10T,A}=\\frac{3.18}{\\sqrt{4}}\\times0.0076811\\approx 0.017s.\n\\end{split}\n\\]\n\nThe type-B uncertainty of $(10T)$ is 0.001s. Hence, the uncertainty of $(10T)$ is\n\n$$ u_{10T}=\\sqrt{\\Delta_A^2+\\Delta_B^2}=\\sqrt{0.017^2+0.001^2}\\approx 0.017s $$  \n\nFor the uncertainty of $\\omega_0$,\n\n$$\\omega_0=\\frac{20\\pi}{10T},\\quad \\frac{\\partial \\omega_0}{\\partial\n  (10T)}=-\\frac{20\\pi}{(10T)^2}$$ \n\n\\[\n\\begin{split}\n&u_{\\omega_0}=\\sqrt{\\frac{\\partial \\omega_0}{\\partial\n    (10T)}^2(u_{10T})^2}=\\frac{20\\pi}{(10T)^2}u_{(10T)}\\\\\n&=\\frac{20\\times3.1416}{15.485^2} \\times 0.017 = 0.004rad/s,\\\\  \n\\end{split}\n\\]\n\n$$ u_{\\omega_0,r}=\\frac{u_{\\omega_0}}{\\omega_0}\\times100\\%\n=\\frac{0.004}{4.058}=0.10\\% $$ \n\n\\subsection{Uncertainty of damping coefficient}\n\nThe type-A uncertainty of $\\ln(\\theta_i/\\theta_{i+5})$ can be determined by\ncalculating $s\\times t_{0.95}/\\sqrt{n}$.\n\nLet $k = s \\times t_{0.95}/\\sqrt{n}$.\n\n\n$$ t_{0.95}=2.78,\\quad n=5$$ \n\n$$ \\Delta_{A,k}=t_{0.95}/\\sqrt{5}\\times\n\\sqrt{\\frac{1}{5-1}\\sum_{i=1}^5(k_i-\\bar{k})^2}=2.78/\\sqrt{5}\\times\n0.00444 = 0.005 $$ \n\nThen, for the type-B uncertainty, \n\n$$ \\frac{\\partial k}{\\partial \\theta_{i}}=\\frac{1}{\\theta_i} $$\n$$ \\frac{\\partial k}{\\partial \\theta_{i+5}}=-\\frac{1}{\\theta_{i+5}} $$ \n$$ \\Delta_{B,k}=\\sqrt{\\frac{\\partial k}{\\partial\n    \\theta_{i}}^2(u_{\\theta_i})^2+\\frac{\\partial k}{\\partial\n    \\theta_{i+5}}^2(u_{\\theta_{i+5}})^2}\n=\\sqrt{(\\frac{u_{\\theta_i}}{\\theta_i})^2+(\\frac{u_{\\theta_{i+5}}}{\\theta_{i+5}})^2}  $$ \n\n\nWhen $i=0$, $\\theta_0=89\\degree$, $u_{\\theta_2}=1\\degree$,\n$\\theta_5=54\\degree$, $u_{\\theta_5}=1\\degree$. \n\n\\[\n\\Delta_{B,k}=\\sqrt{(\\frac{1}{89})^2+(\\frac{1}{54})^2}=0.022 \n\\]\n\nConsidering the type-B uncertainty of $\\ln(\\theta_i/\\theta_{i+5})$, the combined\nuncertainty is \n\n\\[\n\\begin{split}\nu_{k}&=\\sqrt{(0.005)^2+(0.022)^2}= 0.022,\\\\\nu_{k,r}&=\\frac{u_k}{\\bar{k}}\\times100\\%=\\frac{0.022}{0.511}\\times100\\%=4\\%\n\\end{split}\n\\]\n\nHence\n\n$$ \\ln(\\theta_i/\\theta_{i+5})=0.456\\pm0.005, \\quad u_r=1.09\\% $$ \n\nFor $10T=15.792 \\pm 0.001s$, we know that\n\\[\nT=1.5792\\pm0.0001s, \\quad u_{r,T}=0.006\\%.\n\\]\n\nThen calculate the uncertainty of $\\beta=\\ln(\\theta_i/\\theta_{i+5})/(5T)$.\n\n$$ \\frac{\\partial \\beta}{\\partial T}=-\\frac{k}{5T^2}$$ \n\n$$ \\frac{\\partial \\beta}{\\partial k}=\\frac{1}{5T} $$\n\n\\[\n\\begin{split}\nu_{\\beta}&=\\sqrt{(\\frac{\\partial \\beta}{\\partial T})^2(u_T)^2+(\\frac{\\partial\n    \\beta}{\\partial k})^2(u_k)^2}  \n=\\sqrt{(\\frac{k^2}{25T^4})(u_T)^2+(\\frac{1}{25T^2})(u_k)^2}\\\\\n&=\\sqrt{(\\frac{0.511^2}{25\\times1.5792^4})(0.0001^2)+(\\frac{0.022^2}{25\\times1.579\n    2^2})}  \\\\ \n&= 0.003s^{-1} \n\\end{split}\n\\]\n\nwhere $k=\\ln(\\theta_i/\\theta_{i+5})$.\n\nThus, \n\n\\[\n\\beta=0.0648\\pm 0.003s^{-1}, \\quad u_{\\beta,r}=5\\%\n\\]\n\n\n% TODO:\n\n\\subsection{Uncertainty of $\\theta_{st}$ vs. $\\omega$ and $\\varphi$ vs. $\\omega$}\n\nWe denote that $r=\\omega/\\omega_0$.\nTo determine the uncertainty of ratio, we know that\n\n$$ r=\\frac{20\\pi}{10T\\omega_0} $$ \n$$ \\frac{\\partial r}{\\partial (10T)}=-\\frac{20\\pi}{(10T)^2\\omega_0} $$ \n$$ \\frac{\\partial r}{\\partial \\omega_0}=-\\frac{20\\pi}{(10T)\\omega_0^2} $$\n\n\\[\n\\begin{split}\nu_{r}&=\\sqrt{(\\frac{\\partial r}{\\partial\n    (10T)})^2(u_{10T})^2+(\\frac{\\partial r}{\\partial\n    \\omega_0})^2(u_{\\omega_0})^2}\\\\ \n&=\\sqrt{\\frac{400\\pi^2}{(10T)^4\\omega_0^2}(u_{10T})^2+\\frac{400\\pi^2}{(10T)^2\\omega_0^4}(u_{\\omega_0})^2}.\n\\end{split}\n\\]\n\nAs is calculated before, $\\omega_0=3.9787 \\pm 0.006 \\ rad/s$.\n\nFor instance, when $10T= 15.79225  \\pm 0.001s$, the uncertainty of $r$ is\n\\[\nu_{r}=\\sqrt{\\frac{400\\times3.1416^2}{15.79225 ^4\\times 3.9787^2}(0.001)^2\n  +\\frac{400\\times3.1416^2}{15.79225^2\\times3.9787^4}(0.004)^2}=0.0009\n\\] \n\nFor the uncertainty of $\\varphi$ and $\\theta$, these two data only obtain type-B\nuncertainty, so the combined uncertainty of them are both equal to\n$\\Delta_B=1\\degree$, thus \n\n$$ u_{\\varphi}=1\\degree $$\n$$ u_{\\theta}=1\\degree. $$\n", "meta": {"hexsha": "7a5752e7bb9f75a1613cd9a36f7bbc572c217906", "size": 4177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "E5/part/6mua.tex", "max_stars_repo_name": "iamwrm/VP141", "max_stars_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-24T11:28:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T11:28:04.000Z", "max_issues_repo_path": "E5/part/6mua.tex", "max_issues_repo_name": "iamwrm/VP141", "max_issues_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "E5/part/6mua.tex", "max_forks_repo_name": "iamwrm/VP141", "max_forks_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6095890411, "max_line_length": 106, "alphanum_fraction": 0.6145559014, "num_tokens": 1807, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7422264604410324}}
{"text": "\\subsection{K-Means}\n\\label{sec:ctm-km}\n\nThe first clustering algorithm we tried was K-Means \\cite{macqueen1967some}. It iteratively tries to group unlabeled data points with similar features together by minimizing the mean distance between each point in each group. Figure~\\ref{fig:ctm-km} visualizes the groups labeled by the K-Means algorithm on the 2017 class for the Non-Blocking IO assignment.\n\nThe K-Means algorithm constructs each group to minimize the average distance from the group's centroid to every point in its corresponding group. Since the majority of students in our data set received full marks, we assumed the majority of the data points in each group should also represent full-mark solutions. As a result, the volume of full-mark solution points should draw the centroid of each group towards \\textquote{regions} representing higher marks. Based on this idea, we calculated a student's score based on their distance to their corresponding group's centroid; the closer a student was to their group's centroid, the higher their probability of receiving a high score.\n\nLet $P_i$ denote the point representing student $i$ and $C_i$ denote the centroid of the student's group. The distance from centroid $d_i$ is defined as:\n\\begin{equation*}\nd_i = \\norm{P_i - C_i}\n\\end{equation*}\n\nAs mentioned in Figure~\\ref{fig:ctm-km}, the scales in the axes have no tangible interpretations. Therefore, the distances from centroid $d_i$ we calculated for each point also had no meaningful interpretation. As a result, we tried to evaluate each point's centroid distance relative to all other points. In other words, we calculated each student's score based on their performance relative to the rest of their class.\n\nLet $\\mu$ denote the mean and $\\sigma$ denote the standard deviation of centroid distances of every student. We calculated student $i$'s score as follows:\n\\begin{equation*}\n\\text{Score}_i = 100 - 20 \\cdot \\frac{\\abs{d_i - \\mu}}{\\sigma}\n\\end{equation*}\n\nThis equation deducted up to 20 points for each standard deviation of centroid distance a student was from their corresponding group's centroid. We chose to deduct 20 points per standard deviation arbitrarily after experimenting with different values. The main idea was to deduct marks based on how far the solution was from the centroid, where we assumed majority of the full mark solutions were located.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{conversion-to-mark/marking_paster_nbio_ece459-a1-w2017_km}\n\\caption[K-Means Clustering]{Each data point represents a student solution to the Non-Blocking IO assignment from the 2017 class. It is important to note that this is a 2D projection of a multidimensional data set. Since we preprocessed the data with PCA, the first two dimensions presented here already capture the majority of the data variance. The scales in the axes are omitted because they have no tangible interpretations; they are meant for interpreting relative distances. The K-Means algorithm assigned each point a group, represented by their corresponding colour. Each set of concentric circles represent an arbitrary distance from the centroid of each group.}\n\\label{fig:ctm-km}\n\\end{figure}\n", "meta": {"hexsha": "a2155b65323e7b4021c5443e323478b180960347", "size": 3195, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/thesis/body/conversion-to-mark/k-means.tex", "max_stars_repo_name": "Trinovantes/Masters", "max_stars_repo_head_hexsha": "a7f036a08cda7e508b0c51fefa6ac150555ec2ee", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "thesis/thesis/body/conversion-to-mark/k-means.tex", "max_issues_repo_name": "Trinovantes/Masters", "max_issues_repo_head_hexsha": "a7f036a08cda7e508b0c51fefa6ac150555ec2ee", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thesis/thesis/body/conversion-to-mark/k-means.tex", "max_forks_repo_name": "Trinovantes/Masters", "max_forks_repo_head_hexsha": "a7f036a08cda7e508b0c51fefa6ac150555ec2ee", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 118.3333333333, "max_line_length": 685, "alphanum_fraction": 0.8015649452, "num_tokens": 712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7421937765826543}}
{"text": "\\chapter{Applications of the Fast-Fourier-Transform}\n\\label{AppendixFFT}\n\nThe Fast-Fourier-Transform~\\cite{BrighamFFTBook} is a versatile numerical\n\\index{Fourier transform!fast}\ntool. It is an efficient implementation of the discrete\nFourier transform that maps between a function in a canonical variable and\na function in the conjugate variable, e.g.\\\nspace ($x$) and wavenumber ($k$, equal to momentum with $\\hbar=1$),\nor time ($t$) and angular frequency ($\\omega$). For these two examples, the\ndiscrete Fourier transform $F$ of a function $f$ reads as\n\\begin{align}\n  F(\\omega_j)\n  &= \\sum_{n=0}^{N-1} f(t_n) \\ee^{-\\ii \\frac{2\\pi j n}{N}}\n  \\approx \\sum_{n=0}^{N-1} f(t_n) \\ee^{-\\ii \\omega_j t_n}\\,,\n  \\\\\n  F(k_j)\n  &= \\sum_{n=0}^{N-1} f(x_n) \\ee^{-\\ii \\frac{2\\pi j n}{N}}\n  \\approx \\sum_{n=0}^{N-1} f(x_n) \\ee^{-\\ii k_j x_n}\\,,\n\\end{align}\nwhere $N$ is the sampling size, and using the correspondence\n\\begin{equation}\n  w_j t_n \\approx \\frac{2 \\pi j n}{N}\\,,\n  \\qquad\n  k_j x_n \\approx \\frac{2 \\pi j n}{N}\\,.\n  \\label{eq:discrete_to_cont_FTT}\n\\end{equation}\n\nThis transformation is widely implemented in numerical libraries as\n$F(\\omega_j) \\equiv \\FFT f(t_n)$ with the inverse transform defined by\n\\begin{equation}\n  f(t_n) = \\frac{1}{N} \\FFT^{-1} F(\\omega_j)\n         = \\frac{1}{N} \\FFT^{-1} \\FFT f(t_n)\\,.\n\\end{equation}\nThe FFT scales as $N \\log N$ with the sampling size~\\cite{DuhamelSP1990}.\n\n\\section{The Frequency Grid}\n\nWhen using the output of the FFT routine, e.g.\\ as the spectrum of\na time-dependent signal $f(t_n)$, it is important to understand exactly which\nangular frequency values $\\omega_j$ the resulting amplitudes $F(\\omega_j)$\ncorrespond to. This differs between odd and even $N$, a detail that is often\nneglected and can lead to subtle errors in numerical calculations.\n\nIf the original signal is of duration $T = t_{N-1} - t_0$, and has a sampling\nrate $dt = \\frac{T}{N-1}$, the result of a call to the FFT routine is\nan array of $N$ complex numbers, containing the amplitudes for angular\nfrequencies between $-\\omega_{\\max}$ and $+\\omega_{\\max}$, with\n\\begin{equation}\n  \\omega_{\\max} = \\begin{cases}\n     \\frac{\\pi}{dt} = \\frac{(N-1)\\pi}{T}\n                      & \\text{if $N$ even} \\\\\n     \\frac{N-1}{N} \\frac{\\pi}{dt} = \\frac{N-1}{N} \\frac{(N-1)\\pi}{T}\n                      & \\text{if $N$ odd}\n                  \\end{cases}\n\\end{equation}\n\nThe layout of the frequency array also depends on whether $N$ is odd or even. In\nany case, the frequency array consists of two parts: the first sub-array of\nlength $l$ contains the amplitudes of the positive frequencies, the remaining sub-array\nof length $N-l$ (running from $l+1$ to $N$) contains the amplitudes for the\nnegative frequencies.\n\\begin{itemize}[noitemsep,nolistsep]\n\n  \\item $N$ even.\n\n  For even $N$, there are $l=N/2$ positive frequencies, and the values\n  correspond to $$0, d\\omega, \\dots, \\omega_{\\max}-d\\omega,$$\n  followed by $$-\\omega_{\\max}, -\\omega_{\\max}+d\\omega, \\dots, -d\\omega.$$\n\n  \\item $N$ odd.\n\n  For odd $N$, there are $l=N/2 + 1$ positive frequencies, and the values\n  correspond to $$0, d\\omega, \\dots, \\omega_{\\max},$$ followed by\n  $$-\\omega_{\\max}, -\\omega_{\\max}+d\\omega, \\dots, -d\\omega.$$\n\\end{itemize}\n\nThe spectral resolution is\n\\begin{equation}\n  d\\omega = \\begin{cases}\n      \\frac{2 \\omega_{\\max}}{N} = \\frac{2\\pi}{T} - \\frac{2\\pi}{N T}\n            & \\text{if $N$ even} \\\\\n      \\frac{2 \\omega_{\\max}}{N-1} = \\frac{2\\pi}{T}\n            & \\text{if $N$ odd}\n        \\end{cases}\\,.\n\\end{equation}\nWith $t_n  = n \\frac{T}{N}$ and $\\omega_j = j \\, d\\omega$,\nEq.~\\eqref{eq:discrete_to_cont_FTT} is recovered.  If $f(t) \\in \\Real$, then $F(\\omega) = F(-\\omega)^{*}$. For complex signals, on the other hand, the positive and the negative part of the spectrum are \\emph{not} equivalent.\n\\section{Derivatives and the Kinetic Operator}\n\nThe FFT can be used to calculate the derivative of a signal\n$f(x)$ evenly sampled at $N$ points.\n\\begin{equation}\n  \\partdifquo{x} \\equiv \\frac{1}{N} \\FFT^{-1} \\left( \\ii k \\right) \\FFT\n\\end{equation}\nThe kinetic operator in one Cartesian dimension is\n\\begin{equation}\n  \\Op{T} = \\frac{\\Op{p}^2}{2m}\n         = -\\frac{\\hbar}{2m} \\frac{\\partial^2}{\\partial x^2}\\,.\n\\end{equation}\nUsing the FFT, this becomes\n\\begin{equation}\n\\begin{split}\n  \\Op{T}&= -\\frac{\\hbar^2}{2m} \\frac{1}{N} \\FFT^{-1} \\ii k\n             \\FFT \\frac{1}{N} \\FFT^{-1} \\ii k \\FFT \\\\\n        &= \\frac{\\hbar^2}{2m} \\frac{1}{N}\\FFT^{-1} k^2 \\FFT\\,.\n\\end{split}\n\\end{equation}\n\n\\section{Cosine-Transform and Chebychev Coefficients}\n\nFor $f(x) = e^{x}$, the Chebychev coefficients can be derived analytically\nto be proportional to the Bessel functions, see\nsection~\\ref{subsec:chebychev} in chapter~\\ref{chap:numerics}. For a general\nfunction, however, the coefficients are calculated via a cosine\ntransform~\\cite{NdongJCP09}. Since the Chebychev polynomials $P_n$ are defined\nonly in the interval $[-1, 1]$, the function $f(x)$ must be rescaled as $f(x)\n= \\tilde{f}(\\xi)$ with $\\xi \\in [-1,1]$. The coefficients are then calculated as\n\\begin{equation}\n  a_n = \\frac{2 - \\delta_{n,0}}{\\pi}\n        \\int_{-1}^{+1} \\frac{\\tilde{f}(\\xi) P_n(\\xi)}{\\sqrt{1-\\xi^2}} \\dd \\xi\n      \\approx \\frac{2 - \\delta_{n,0}}{\\pi}\n        \\sum_{k=0}^{N-1} w_k f_k \\cos\\left( n \\theta_k \\right)\\,,\n\\end{equation}\nwith $f_k \\equiv f(x_k) = \\tilde{f}(\\xi_k)$, $\\theta_k \\equiv \\arccos(\\xi_k)$,\nand weights $w_k$ that depend on the choice of the sampling points $x_k$.\nThe approximation becomes exact for $N \\rightarrow \\infty$.\nThere are two possible choices of sampling points:\n\\begin{itemize}\n\n  \\item Gauss-Lobatto-Chebychev grid\n        (``closed interpolation'': $\\xi_k \\in [1, -1]$)\n  \\begin{equation}\n    \\xi_k = \\cos\\left( \\frac{k \\pi}{N-1}\n                \\right), \\qquad\n    w_k = \\left(\\frac{1}{2}\\right)^{\\delta_{n,0}}\n          \\left(\\frac{1}{2}\\right)^{\\delta_{n,N-1}}\n          \\frac{\\pi}{N-1}\\,.\n    \\label{eq:gauss_lobatto}\n  \\end{equation}\n  The $\\xi_k$ are the extrema of the Chebychev polynomials, plus\n  endpoints. The resulting formula for the coefficients $a_n$ is defined as\n  a discrete cosine transform of type I (DCT I) and may be implemented via the\n  FFT~\\cite{RaoDCTBook1990}. The complete calculation of the coefficients is\n  shown in Algorithm~\\ref{al:ChebyCoeffs}.\n\n  \\item Gauss-Chebychev (``open interpolation'': $\\xi_k \\in (1, -1)$)\n  \\begin{equation}\n    \\xi_k = \\cos\\left( \\frac{\\left(k + \\frac{1}{2}\\right) \\pi}{N}\n                \\right), \\qquad\n    w_k = \\frac{\\pi}{N}\\,.\n    \\label{eq:gauss_cheby}\n  \\end{equation}\n  The $\\xi_k$ are the roots of the Chebychev polynomials. The resulting\n  formula for the $a_n$ is defined as a discrete cosine transform of type II\n  (DCT II). There is no direct mapping to the FFT in this case.\n\\end{itemize}\n\n\\begin{algorithm}\n  \\caption{{\\sc ChebychevCoefficients}\n  for expansion of $f(x)$.\n  \\label{al:ChebyCoeffs}\n  }\n  \\begin{algorithmic}[1]\n    \\Statex\n    \\Require{$f(x)$ with $x \\in [x_{\\min}, x_{\\max}]$;\n             maximum number $n_{\\max}$  of coefficients\n    }\n    \\Ensure{Array of Chebychev coefficients $[a_0\\dots a_n]$, $n < n_{\\max}$\n    allowing to approximate $f(x)$ to predefined precision.}\n    \\Statex\n    \\Procedure{ChebyCoeffs}{$f(x)$}\n     \\State $\\Delta = x_{\\max} - x_{\\min}$\n     \\State $\\alpha = \\frac{1}{2} \\Delta$;\n            $\\beta = \\alpha + x_{\\min}$\n     \\State $F_{0:2 n_{\\max}-3} = 0$\n            \\Comment{allocation to size $2(n_{\\max}-1)$}\n     \\For{$k = 0:n_{\\max}-1$}\n        \\State $\\xi_{k} = \\cos\\left( \\frac{k \\pi}{n_{\\max} - 1} \\right)$\n        \\Comment{$\\xi_k = +1, \\dots, -1$}\n        \\State $F_k = f(\\alpha \\xi_{k} + \\beta)$\n     \\EndFor\n     \\For{$k = 1:n_{\\max}-2$} \\Comment{mirror, without endpoints}\n        \\State $F_{n_{\\max}-1+k} = F_{n_{\\max}-1-k}$\n     \\EndFor\n     \\State $F$ = \\Call{FFT}{$F$}\n     \\State $F = F / (n_{max}-1)$\n     \\State $F_0 = \\frac{1}{2} F_0$\n     \\State $F_{n_{\\max}-1} = \\frac{1}{2} F_{n_{\\max}-1}$\n     \\For{$i=0: n_{\\max}-1$}\n       \\State $a_i = F_i$\n       \\IIf{$\\Abs{a_i} < $~limit} exit loop with $n=i$\n     \\EndFor\n     \\State \\Return $[a_0, \\dots a_n]$\n   \\EndProcedure\n  \\end{algorithmic}\n\\end{algorithm}\n\n", "meta": {"hexsha": "ee1e05a36cb6a0a00d9c2ed3a53c27eaaed90e92", "size": 8161, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/appendixFFT.tex", "max_stars_repo_name": "goerz/dissertation", "max_stars_repo_head_hexsha": "ee8ae29b5da1bc6033260224ae6444fd7f4c4a2f", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-05-09T03:22:23.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-11T13:33:43.000Z", "max_issues_repo_path": "chapters/appendixFFT.tex", "max_issues_repo_name": "goerz/dissertation", "max_issues_repo_head_hexsha": "ee8ae29b5da1bc6033260224ae6444fd7f4c4a2f", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/appendixFFT.tex", "max_forks_repo_name": "goerz/dissertation", "max_forks_repo_head_hexsha": "ee8ae29b5da1bc6033260224ae6444fd7f4c4a2f", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.0100502513, "max_line_length": 224, "alphanum_fraction": 0.6323979904, "num_tokens": 2884, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523327, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7421616278308087}}
{"text": "\\lab{Diffie-Hellman Key Exchange}{Diffie-Hellman Key Exchange}\n\\label{lab:DiffieHellman}\n\\objective{Understand a method of creating a shared secure key with insecure communications.}\n\n\nIn cryptography, a \\emph{key} is a piece of secret information that is required to either encrypt or decrypt a message.\nA cipher (or code) is \\emph{symmetric} if it uses the same key for both encryption and decryption.\nPeople have used symmetric ciphers since ancient history.\nFor example, the ancient Greeks used substitution ciphers, the Nazis used Enigma, and people today use AES and Twofish.\n\nFor Alice and Bob to use a symmetric cipher, they must first agree on a key.\nA \\emph{key exchange algorithm} is a way to do this so that even if an enemy Eve intercepts all the information passed between Alice and Bob, she will not be able to deduce the key.\nThe Diffie-Hellman key exchange was the first such algorithm, and it is frequently used today.\n\n\\section*{One-Time Pad (Optional)}\nIn this section we introduce a basic symmetric cipher with modern uses: the one-time pad.\nThis cipher is outlined below.\n\\begin{itemize}\n\\item The key is a number.\n\\item Encrypt a message by \n\\begin{enumerate}\n\\item converting it to a number\n\\item then adding the key \\emph{bitwise}. This means that binary digits are added with no carrying; for example, $1010+11=1001$.\n\\end{enumerate}\n\\item Decrypt the ciphertext by \n\\begin{enumerate}\n\\item adding the key to it bitwise\n\\item then converting the resulting number back into text.\n\\end{enumerate}\n\\end{itemize}\nThe security of a one-time pad is compromised when the key is reused to encrypt another message.\n\nFor example, suppose we wish to encrypt the message SECRET.\nOne way to convert this message to a number is to use the substitution cipher $A=10, B=11, \\ldots, Z=35$.\nWith this rule, SECRET=281412271429.\nTo encrypt this message, we must choose a key that is larger than 281412271429.\nWe choose 987654321000. \nWe perform the bitwise addition in Python with the caret operator \\li{^}.\n\\begin{lstlisting}\n>>> message = 281412271429\n>>> key = 987654321000\n>>>\n>>> ciphertext = message^key    # Encode the message\n>>> ciphertext\n706282163757\n>>>\n>>> message == ciphertext^key    # Decode the message\nTrue\n\\end{lstlisting}\n\n\\begin{problem}\nFor this problem, use the substitution cipher $A=11, \\ldots$ described above, with the additional rule \\texttt{' '}=36.\n\\begin{enumerate}\n\\item Encrypt the message `PRIVATE INFO' with the key 987654321098765432109876.\n\\item Decrypt the message 153931672663401143 with the key 12345678901234567890.\n\\end{enumerate}\n\\end{problem}\n\n\n\n\\section*{Diffie-Hellman key exchange algorithm}\nThe Diffie-Hellman key exchange uses \\emph{primitive roots} modulo a prime.\n\n\\subsection*{Primitive roots}\nLet $p$ be a prime number. \nA positive number $a$ is a \\emph{primitive root modulo p} if the positive powers $a^1, a^2, \\ldots, a^{p-1}$ generate all nonzero congruence classes modulo $p$.\nFor example, let $p=7$.\nThen $a=2$ is not a primitive root, since\n\\[\n2^1=2, \\quad 2^2=4, \\quad 2^3 \\equiv 1, \\quad 2^4 \\equiv 2, \\quad 2^5 \\equiv 4, \\quad 2^6 \\equiv 1 \\pmod{7}.\n\\]\nThe powers of $2$ never hit the classes $3, 5,$ or $6$ modulo 7. \nHowever, $3$ is a primitive root since\n\\[\n3^1=3, \\quad 3^2\\equiv2, \\quad 3^3 \\equiv 6, \\quad 3^4 \\equiv 4, \\quad 3^5 \\equiv 5, \\quad 3^6 \\equiv 1 \\pmod{7}.\n\\]\nThat is, each congruence class $\\pmod{7}$ appears as a power of 3.\n\n\\subsection*{Diffie-Hellman algorithm}\n\nHere is an outline of how Alice and Bob can perform a Diffie-Hellman key exchange:\n\n\\begin{itemize}[$\\bullet$]\n\n\\item Alice and Bob (publicly) agree on a prime $p$ and a primitive root $g$.\n\n\\item Alice and Bob each secretly choose an integer, $x$ and $y$ respectively.\n\n\\item Alice computes $A = g^x \\pmod{p}$ while Bob computes $B = g^y \\pmod{p}$.\n\n\\item Alice and Bob exchange $A$ and $B$ (still keeping $x$ and $y$ secret).\n\n\\item Alice computes $B^x \\pmod{p}$ and Bob computes $A^y \\pmod{p}$. They get the same answer, \n\\[k \\equiv B^x \\equiv (g^y)^x \\equiv (g^x)^y \\equiv A^y \\pmod{p}.\\] \n\n\\end{itemize}\nNow Alice and Bob can use $k$ as a secure key for a symmetric cipher. \nOne advantage of this algorithm is that Alice and Bob can use the same prime $p$ and root $g$ to generate a new secure key, simply by picking new integers $x$ and $y$.\n\nThe key idea of the Diffie-Hellman algorithm is that $(g^x)^y\\equiv (g^y)^x \\pmod{p}$. \nWe do an example of this in Python with $p=41$, $g=6$, $x=10$, and $y=13$.\nThe function \\li{pow(a, b, n)} computes $a^b \\pmod{n}$.\n\\begin{lstlisting}\n>>> A = pow(6, 10, 41)\n>>> B = pow(6, 13, 41)\n>>> pow(A, 13, 41)\n32\n>>> pow(B, 10, 41)\n32\n\\end{lstlisting}\n\n\\begin{problem}\nWith a partner, perform a Diffie-Hellman key exchange with $p = 21929$ and $g=3$.\n\\end{problem}\n\nThe Diffie-Hellman can also be used to create a secure key shared by $n>2$ people. \nIf $n$ people choose private exponents $x_1, \\ldots, x_n$, then the secure key will be $g^{x_1 \\ldots x_n}$.\n\n\\begin{problem}\nWork out a method by which $n$ people can use Diffie-Hellman to create a secure key.\nRemember that only the $i^{th}$ person knows the $i^{th}$ exponent $x_i$.\nWith a group of at least 3 people, perform such an exchange with $p = 21929$ and $g=3$.\n\\end{problem}\n\n\\subsection*{Security of Diffie-Hellman}\nWhy is the Diffie-Hellman algorithm secure? \nSuppose a third party, Eve, intercepts $p$, $g$, $A$, and $B$\nIf she can compute $x$ and $y$, she easily compute $k$ just as Alice and Bob did. \nThen Eve must compute $x$ satisfying $A\\equiv g^x \\pmod{p}$.\nThis computation is known as taking a \\emph{discrete logarithm} of $A$ and there are no fast algorithms for doing it.\nWhen $p$ is large, say 100s of digits, calculating a discrete logarithm is effectively impossible.\n\n\\section*{Practical Considerations}\nFor Diffie-Hellman to be a practical key exchange algorithm, we need an efficient way to find primitive roots and perform modular exponentiation.\n\n\\subsection*{Finding primitive roots}\nThe only way to find the primitive roots of $p$ is to test numbers $a<p$ until a primitive root is found.\nOne test to see if $a$ is a primitive root is as follows.\n\nFirst, factor $p-1$ as a product of primes, say $p=p_1^{k_1}\\ldots p_n^{k_n}$.\nThen, for each prime $p_i$ in the factorization, compute $a^{(p-1)/p_i} \\pmod{p}$.\nIf for any $i$ we find $a^{(p-1)/p_i}\\equiv 1 \\pmod{p}$, then $a$ is NOT a primitive root.\nOtherwise, $a$ is a primitive root.\n\nAs an example we look for a primitive root of $p=41$.\nWe factor $p-1=40$ using the function \\li{factorint()} from SymPy.\n\\begin{lstlisting}\n>>> from sympy import factorint\n>>> factorint(40)\n{2: 3, 5: 1}\n\\end{lstlisting}\nThis output means that $40=2^3\\cdot5^1$.\nThen the powers to check are $40/2=20$ and $40/5=8$.\nThe following code shows that $2$ is not a primitive root modulo 41, since $2^{20}\\equiv 1 \\pmod{41}$.\n\\begin{lstlisting}\n>>> pow(2, 20, 41)\n1\n\\end{lstlisting}\nHowever, 6 is a primitive root modulo 41, as the following code shows.\n\\begin{lstlisting}\n>>> pow(6, 8, 41)\n10\n>>> pow(6, 20, 41)\n40\n\\end{lstlisting}\n\nThe idea behind this algorithm is that if $a^n \\equiv 1 \\pmod{p}$ for some $n<p-1$, then $a$ will not be a primitive root.\nInstead, powers of $a$ will repeat and miss some congruence classes, as they did in the example of $2 \\pmod{7}$.\nFor ``group-theoretic'' reasons, if $a^n \\equiv 1 \\pmod{p}$ for some $n<p-1$ (i.e., $a$ is not a primitive root), then there must be some $p_i$ such that $a^{(p-1)/p_i} \\equiv 1 \\pmod{p}$.\nSo, instead of checking all powers of $a$ modulo $p$, we only need to check the powers $(p-1)/p_i$ for all $i$.\n\n\\begin{problem}\nWrite the following function to test if $a$ is a primitive root modulo $p$.\n\\begin{lstlisting}\ndef is_primitive(root, mod):\n    '''Determine whether `root' is a primitive root modulo `mod'.\n    \n    INPUTS:\n    root - A positive integer.\n    mod  - A prime integer.\n    \n    Return a Boolean value.\n    '''\n\\end{lstlisting}\n\\end{problem}\n\n\n\\subsection*{Fast modular exponentiation}\nThe na\\\"ive way to compute $123^{361} \\pmod{19673}$ is to multilply 123 by itself 361 times, producing an enormous number, and then mod this number by 19673.\nA slightly better way is to take the modulus after each multiplication by 123, since this way we do not store such a large number.\n\n\\begin{problem}\\label{prob:power1}\nWrite the following function to implement the algorithm for modular exponentiation outlined above.\n\\begin{lstlisting}\ndef power1(base, exp, mod):\n    ''' Return base^exp modulo `mod'.\n    \n    Multiply `base' by itself `exp' times, taking the modulus after each \n    multiplication.\n    \n    Example:\n    >>> power1(5064, 361, 19673)\n    994\n    '''\n\\end{lstlisting}\n\nTime your function against Python's built in \\li{pow()} function.\nWhat is the difference in speed?\n\\end{problem}\n\nIf you did Problem \\ref{prob:power1}, you know that Python's exponentiation method is orders of magnitude faster than the na\\\"ive method outlined above.\nThis increase in performance is acheived with \\emph{binary exponentiation} (or exponentiation by squaring).\n\nThis idea of this method is as follows. \nTo compute $a^{361} \\pmod{19673}$, we first write 361 in binary as 101101001. Thus,\n\\begin{equation}\\label{equ:pow}\na^{361} = a^{2^0+2^3+2^5+2^6+2^8} = a^{2^0}a^{2^3}a^{2^5}a^{2^6}a^{2^8} \\pmod{19673}.\n\\end{equation}\nWe can quickly compute the integers\n\\[\na=a^{2^0},\\; a^2=a^{2^1}, \\;a^{2^2}, \\;\\ldots, \\;a^{2^8} \\pmod{19673}\n\\]\nby squaring each term to get the next. \nThen, to compute \\eqref{equ:pow}, we simply multiply the appropriate terms from this series.\n\n\\begin{problem}\nImplement binary exponentiation with the following function.\n\\begin{lstlisting}\ndef power2(base, exp, mod):\n    ''' Return base^exp modulo `mod'.\n    \n    Compute the result using the right-to-left binary method.\n    \n    Example:\n    >>> power2(5064, 361, 19673)\n    994\n    '''\n\\end{lstlisting}\nDo not at any point use Python's built-in exponentiation methods.\nCompare the speed of this function to that of the function in Problem \\ref{prob:power1} and Python's \\li{pow()} function.\nEven with a na\\\"ive implementation of binary exponentiation, you should see enormous improvement over the \\li{power1()} function.\n\\end{problem}\n\n\n\n", "meta": {"hexsha": "1a149173e9a1b88b140ee70e57ba1ec695f79b2f", "size": 10204, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/DiffieHellman/diffiehellman.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Labs/DiffieHellman/diffiehellman.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/DiffieHellman/diffiehellman.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 41.4796747967, "max_line_length": 188, "alphanum_fraction": 0.718247746, "num_tokens": 3109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.7421616260929439}}
{"text": "\\section{Linearization \\& Newton's Method}\r\n\r\n\\subsection{Linearization}\r\nAs we've seen, tangent lines intersect their function at most once: at the point of tangency.\r\nHowever, we know that differentiable functions are locally linear, so we'd expect the tangent line to be a decent approximation of the function near the point of tangency.\r\n\r\n\\begin{definition}\r\n\tIf $f$ is differentiable at $a$, then the approximating function\r\n\t\\begin{equation*}\r\n\t\tL(x) = f^\\prime(a)(x-a) + f(a)\r\n\t\\end{equation*}\r\n\tis the linearization of $f$ at $a$.\r\n\\end{definition}\r\n\r\n\\begin{example}\r\n\tFind the linearization of $f(x) = \\ln{(x+1)}$ at $x=0$.\r\n\tHow accurate is this approximation at $x=0.1$?\r\n\\end{example}\r\n\\begin{answer}\r\n\tFollowing the definition,\r\n\t\\begin{align*}\r\n\t\tf(0) = \\ln{(0+1)} = 0 \\\\\r\n\t\tf^\\prime(x) &= \\frac{1}{x+1} \\\\\r\n\t\tf^\\prime(0) &= \\frac{1}{0+1} = 1 \\\\\r\n\t\tL(x) &= 1(x-0) + 0 = x.\r\n\t\\end{align*}\r\n\t\r\n\tCalculating the error at $x=0.1$,\r\n\t\\begin{align*} \r\n\t\tL(0.1) &= 0.1 \\\\\r\n\t\tf(0.1) &\\approx .0953 \\\\\r\n\t\t\\text{\\% error} &= \\frac{\\abs{L(0.1)-f(0.1)}}{L(0.1)}100\\text{\\%} \\approx 4.7\\text{\\%}.\r\n\t\\end{align*}\r\n\t\r\n\tSo, we can see the linear approximation is pretty good.\r\n\\end{answer}\r\n\r\n\r\nWe call the difference in $x$ between the point of tangency and the point we're trying to approximate the differential.\r\n\\begin{definition}\r\n\tLet $y=f(x)$ be a differentiable function.\r\n\tThe differential $\\d{x}$ is an independent variable.\r\n\tThe differential $\\d{y}$ is $\\d{y} = f^\\prime(x)\\d{x}$.\r\n\\end{definition}\r\n\r\n$\\mathrm{d}y$ is the approximated change in $y$ expected by the linearization for some given change in $x$, $\\d{x}$.\r\n\r\n\\begin{example}\r\n\tFind $\\d{y}$ for $y=\\frac{2x}{1+x^2}$, $x=-2$, and $\\d{x} = 0.1$.\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n\t\ty^\\prime &= \\frac{-4x^2}{\\left(1+x^2\\right)^2} + \\frac{2}{1+x^2} \\\\\r\n\t\ty^\\prime(-2) &= -6/25 \\\\\r\n\t\t\\d{y} &= (-6/25)(0.1) = -0.024.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsection{Newton's Method}\r\nWe can use the fact that the tangent line approximates the function to find the zeroes of functions.\r\nStarting with an initial guess $x_0$ for the $x$ value of the zero, we look at the the tangent line at $x_0$ and find where it intersects the $x-axis$.\r\n\\begin{align*}\r\n\tL_0(x) &= f^\\prime(x_0)(x - x_0) + f(x_0) \\\\\r\n\t0 &= f^\\prime(x_0)(x - x_0) + f(x_0) \\\\\r\n\t-f^\\prime(x_0)(x - x_0) &= f(x_0) \\\\\r\n\tx - x_0 &= -\\frac{f(x_0)}{f^\\prime(x_0)} \\\\\r\n\tx &= x_0 - \\frac{f(x_0)}{f^\\prime(x_0)}.\r\n\\end{align*}\r\nThis $x$ value serves as our next guess for the zero.\r\nWe repeat this process, until we find the zero or are satisfied with our error\\footnote{For most well-behaved functions, Newton's Method can get within a small margin of error or a zero relatively quickly. There is also a generalized, sometimes faster version of Newton's Method that approximates the function with higher-order polynomials than just lines.}.\r\nThis yields a recursive formula\r\n\\begin{equation*}\r\n\tx_{n+1} = x_n - \\frac{f(x_n)}{f^\\prime(x_n)}.\r\n\\end{equation*}", "meta": {"hexsha": "3efc9ea8e9706c243e34adb95ab08ddaf6f393f0", "size": 2994, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/applications_derivative/linearization_newtons_method.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/applications_derivative/linearization_newtons_method.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/applications_derivative/linearization_newtons_method.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.4594594595, "max_line_length": 359, "alphanum_fraction": 0.6479625919, "num_tokens": 1025, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851154320682, "lm_q2_score": 0.8670357546485407, "lm_q1q2_score": 0.7420535514532571}}
{"text": "\\chapter{The Basics of Regression \\label{chapter:regression}}\n\nClassification is a form of supervised learning in which the outcome is a category. \\textbf{Regression}\\index{regression} is another form of supervised learning in which the outcome is a numeric value. For example, it may be a lab value, physical characteristic (height, weight, etc.), or numeric measurement (e.g. oxygen saturation).\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Visualizing the Regression Problem \\label{section:visualizingreg}}\n\nLet's consider the same setup from Section~\\ref{section:visualizingclass} but this time with a quantitative outcome: a ``recurrence biomarker'' that indicates the likelihood of recurrence of disease.\n\nAgain, we have data on two predictors: a disease severity score ($x_1$), which characterizes the severity of the illness for which the patient was originally treated, and a social determinants score ($x_2$), which characterizes a patient's socioeconomic status. We have measurements of $x_1$ and $x_2$ on the same $200$ patients as in Section~\\ref{section:visualizingclass}.\n\\begin{center}\n\\includegraphics[width=0.65\\textwidth]{img/esl-reg-just-data.png}\n\\end{center}\n\nThis is a plot of the data in a single plane. The color represents the value of the recurrence biomarker -- the height of the point above the plane. We want to design a model that will predict the value of the biomarker ($y$) based on the values of the two predictors, $x_1$ and $x_2$. These plots show the \\textbf{univariate} relationship of each predictor with the outcome.\n\\begin{center}\n\\includegraphics[width=0.45\\textwidth]{img/esl-reg-x1.png}\n\\includegraphics[width=0.45\\textwidth]{img/esl-reg-x2.png}\n\\end{center}\n\n\\begin{question}{question:influence}\nWhich of the two predictors, $x_1$ or $x_2$, appears to more strongly influence the value of the recurrence biomarker? Explain your reasoning using evidence from the preceding three plots. \n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Three Regression Algorithms}\n\n\\subsection{Linear Regression \\label{ssect:linreg}}\n\nThe regression analogue of logistic regression is \\textbf{linear regression}\\footnote{The terminology here is confusing. When we learn about generalized linear models in Chapter~\\ref{chapter:glms}, you'll see why logistic regression has the word ``regression'' in its name even though it's a classification algorithm.}. Linear regression creates a hyperplane that slices through the cloud of training datapoints such that it passes as close as possible, on average, to the data. This is, of course, easiest to see when the feature space is two-dimensional, as it is here:\n\n\\begin{center}\n\\includegraphics[width=0.65\\textwidth]{img/esl-reg-linear.png}\n\\end{center}\nThe three lines shown here sit on the hyperplane learned by the linear regression model. They are located at heights corresponding to the 25th, 50th, and 75th percentiles of the outcome, $y$ (the biomarker value). The plane tilts downward toward the upper left corner of the $x_1 \\times x_2$ grid and upward toward the bottom right corner. It may be helpful to visualize grabbing the $x_1 \\times x_2$ plane and rotating/translating it so that it passes through the middle of the training data. Here is a summary of the trained linear regression model:\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/linear-regression-model-output.png}\n\\end{center} \n\nAt each point $(x_1, x_2)$ in the feature space, the model's predicted value of the recurrence biomarker, $\\hat{y}$, is\n$$ \\hat{y} = 49.8600 + 10.4372 x_1 - 1.8824 x_2 $$\n\n\\begin{question}{}\nCompare and contrast the output from the linear regression model with the output from the logistic regression model in Chapter~\\ref{chapter:classification}. What looks the same? What looks different? What is being predicted in each case? \n\\end{question}\n\n\\subsection{K Nearest Neighbors (KNN)}\n\nRegression using KNN works very similarly to KNN for classification. In classification, we allow the nearest $K$ points to vote on the label of a new test point. In regression, we \\textbf{interpolate} between the values of the surrounding points to come up with the value of $y$ for a test point. Typically this is done just by averaging the $y$ values of the nearest $K$ points, but you can also do something more sophisticated, like weight their contributions by distance to the test point. Here is a contour plot of the regression surface produced by KNN ($K=15$) for our example:\n\n\\begin{center}\n\\includegraphics[width=0.65\\textwidth]{img/esl-reg-knn-15.png}\n\\end{center}\n\n\\noindent The contours are again drawn at the 25th, 50th, and 75th percentiles of the outcome, $y$. This looks like a bit of a mess compared to the linear regression plot, but at the same time, the KNN algorithm is able to capture arbitrarily complex relationships between $x_1$, $x_2$, and $y$ that can be missed by other regression algorithms.  \n\n\\subsection{Decision Tree}\n\nDecision tree regression is similar to decision tree classification except that the output at each leaf is not a class label or the probability of membership in the positive training class (both of which are shown on the tree in Section~\\ref{ssect:class_decision_tree}), but a numeric value. That value corresponds to the mean outcome value for the points in that leaf. \n\\vspace{-7mm}\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{img/esl-decision-tree-just-tree-reg.png}\n\\end{center}\n\\vspace{-7mm}\nThe predicted biomarker values for a decision tree trained on this dataset (created using the \\texttt{rpart} package in R with default parameters) are shown here:\n\\begin{center}\n\\includegraphics[width=0.65\\textwidth]{img/esl-reg-decision-tree.png}\n\\end{center}\nYou can see that the decision tree always chooses to split on $x_1$, the disease severity score, rather than $x_2$. Revisit Question~\\ref{question:influence} to remind yourself of why this is. The regression surface produced by the decision tree looks like a set of stairs climbing higher and higher as one moves from left to right across the $x_1 \\times x_2$ plane. The predicted value of $y$, the recurrence biomarker, is constant within each stair. \n\\vspace{5mm}\n\n\\begin{question}{}\nCompare this decision tree with the decision tree for the classification problem in Chapter~\\ref{chapter:classification}. What is the same? What is different?\n\\end{question}\n\n\\begin{question}{}\nThis \\textbf{regression tree} has eight leaves. What region of the feature space does each leaf correspond to?\n\\end{question}\n\n\\begin{question}{}\nWhat are the advantages and disadvantages of each of these three regression algorithms (linear regression, KNN, regression tree)?\n\\end{question}\n\n", "meta": {"hexsha": "952a4ed2d489b444848b6077b43be05012d7420a", "size": 6785, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-regression.tex", "max_stars_repo_name": "blpercha/mcds-notes", "max_stars_repo_head_hexsha": "33531a443afb154b5c415299276a2ad215463896", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-12-10T16:51:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T01:31:23.000Z", "max_issues_repo_path": "tex/mcds-regression.tex", "max_issues_repo_name": "blpercha/mcds-notes", "max_issues_repo_head_hexsha": "33531a443afb154b5c415299276a2ad215463896", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/mcds-regression.tex", "max_forks_repo_name": "blpercha/mcds-notes", "max_forks_repo_head_hexsha": "33531a443afb154b5c415299276a2ad215463896", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T17:16:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T17:16:44.000Z", "avg_line_length": 77.9885057471, "max_line_length": 583, "alphanum_fraction": 0.7649226234, "num_tokens": 1615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.8670357546485407, "lm_q1q2_score": 0.7420535387018963}}
{"text": "\n\\subsection{Z-test for variable significance}\n\n\\subsubsection{The standard score}\n\nWe may want to see how different a mean statistic is from a specific value.\n\nThe standard score allows us to measure this, by taking this distance and standardising by the standard deviation.\n\n\\(z=\\dfrac{\\bar x-x_0}{\\sigma }\\)\n\nThis requires us to know the standard deviation, which is in general not known.\n\nIf the sample size is large, we know this converges to the normal distribution through the central limit theorem.\n\n\\subsubsection{The Z-test}\n\nWe can see how likely our statistic was to be produced if it was drawn from a normal distribution with mean \\(x_0\\) and standard deviation \\(s_0\\).\n\n\\subsubsection{P-values}\n\nThis is the chance of the statistic being produced by chance.\n\n", "meta": {"hexsha": "5470349ded24f26fa0457cf24feca1e8413de8eb", "size": 774, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/hypothesisZT/01-01-zStatistic.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/hypothesisZT/01-01-zStatistic.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/hypothesisZT/01-01-zStatistic.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.25, "max_line_length": 147, "alphanum_fraction": 0.7764857881, "num_tokens": 171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.7419140288533841}}
{"text": "% !TeX root = ../main.tex\n\n\\chapter{Theory}\n\\label{ch:theory}\n\n\\section{SVM}\nA \\acrfull{svm} is a machine learning algorithm which tries to separate binary-class training data. The \\gls{svm} achieves this by searching for a hyperplane or a set of hyperplanes to separate the points of training data in a multidimensional space. There might be several possible hyperplanes that sufficiently separate the data but a \\gls{svm} searches for the hyperplane with the biggest perpendicular distance between the hyperplane and the borders of both classes that should be separated. The space between the hyperplane and the closest of the training data points is defined as the margin. If the algorithm finds the maximal margin it has also found the optimal hyperplane. See figure \\ref{fig:svmHyperplaneSeparation} for an example of possible hyperplane separations.\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.5]{figures/theorySVM_hyperplanes}\n\t\\caption{Separation of two classes by hyperplanes in 2 dimensional space. $H_1$ does not separate, $H_2$ and $H_4$ separate but the margin is very slim, $H_3$ separates with a much better margin.}\n\t\\label{fig:svmHyperplaneSeparation}\n\\end{figure}\n\n\\subsection*{Formal Definition}\nSince a \\Gls{svm} is a binary classifier a data point $x$ has to either belong into class A or class B. Let the training dataset of $n$ points be represented as $x_0,\\dots,x_n$ and the target values be $y_0,\\dots,y_n \\in {-1,+1}$. The values of $y_n$ should be \n\\begin{equation}\n\ty_i=\n\t\t\\begin{cases}\n\t\t+1 & \\text{if } x_i \\in \\text{class } {\\color{red}A} \\\\\n\t\t-1 & \\text{if } x_i \\in \\text{class } {\\color{blue}B}\n\t\t\\end{cases}.\t\n\\end{equation}\nThe optimal hyperplane should separate all vectors $x_i$ with a value of $y_i=1$ {(class ${\\color{red}A}$)} and those with a value of $y_i=-1$ {(class ${\\color{blue}B}$)} so that the distance between those two groups is maximal \\cite{Thome2012}. Let the hyperplane be\n\\begin{equation}\n\tD(x)=W \\bullet x+b\n\\end{equation}\n\nwhere $W$ is a vector normal to the hyperplane (see figure \\ref{fig:svmHyperplaneDistance}) and $b$ is a bias term \\cite{Boser1992}. $D(x)$ has to be calculated so that\n\\begin{equation}\n\tx \\in \n\t\\begin{cases}\n\t\\text{class } {\\color{red}A} & \\text{if } D(x) > 0 \\\\\n\t\\text{class } {\\color{blue}B} & \\text{if } D(x) < 0\n\t\\end{cases}\t\n\\end{equation}\nis true. The distance between a point $X$ and the hyperplane $D(x)$ is given as\n\\begin{equation}\n\\frac{D(X)}{\\|W\\|}\n\\end{equation}\nwhich is illustrated in figure \\ref{fig:svmHyperplaneDistance} \\cite{Thome2012}. Assuming that the data is linear separable {(as in figure \\ref{fig:svmHyperplaneSeparation})} we can then select two hyperplanes ${\\color{red}D(x)>0}$ and ${\\color{blue}D(x)<0}$ so that there are no points in between them and try to maximize the distance between those two hyperplanes {(in figure \\ref{fig:svmHyperplaneSeparation} $H_2$ and $H_4$)} which is then given as \n\\begin{equation}\n\\frac{2}{\\|W\\|}.\n\\end{equation}\nTo maximize the distance we must therefore minimize $\\|W\\|$ but with the constraint {(\\ref{eq:svmHyperplaneCondition})} that no data gets between the two hyperplanes {(hard-margin classification)}. Both constraints\n\\begin{equation}\n\t\\begin{split}\n\tx_i \\bullet w+b \\geq +1 \\quad \\text{if } {\\color{red}y_i=+1}\\\\\n\tx_i \\bullet w+b \\leq -1 \\quad \\text{ if } {\\color{blue}y_i=-1}\n\t\\end{split}\n\\label{eq:svmHyperplaneCondition}\n\\end{equation}\ncan be combined to $y_i(x_i\\bullet w + b)\\geq 1\\quad \\forall i, i=1\\dots n$. The solution for a maximum margin can therefore be found by solving\n\\begin{equation}\n\\begin{split}\n\\operatorname*{arg\\,min}_{w, b}\t\\left\\{\\frac{1}{2}\\|W\\|^2\\right\\} \\text{subject to} \\\\\ny_i(x_i\\bullet w + b)-1\\geq 0 \\quad \\forall i, i=1\\dots n\t\n\\end{split}\n\\end{equation}\nwith the Lagrangian multiplier method \\cite{Thome2012}. \n\nIf the data is not linear separable we have to relax the constraints from \\ref{eq:svmHyperplaneCondition} and allow some points in the margin {(soft-margin-classification)}. \n\nClassification of unknown data is now simply done through a calculation of the decision function $D(x)$\n\\begin{equation}\n\\text{prediction}\n\t\\begin{cases}\n\tx \\in \\text{class } {\\color{red}A} & \\text{if } D(x) > 0 \\\\\n\tx \\in \\text{class } {\\color{blue}B} & \\text{if } \\text{otherwise}\n\t\\end{cases}\t\n\\end{equation}\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.4]{figures/theorySVM_distanceToW}\n\t\\caption{Visualization of optimal margin and hyperplane in 2 dimensional space. The distance of Point $X$ to $D(x)$ is $\\frac{D(X)}{\\|W\\|}$. Source Bosner et al. \\cite{Boser1992}.}\n\t\\label{fig:svmHyperplaneDistance}\n\\end{figure}\n\\subsection*{Kernel Trick}\nHowever, there are still cases where the data can not be separated by a linear function as shown in figure \\ref{fig:svmKernelTrick}. In this case the data is mapped into another higher dimensional feature space {(Kernel trick)} so that it becomes linear separable again. The function that maps the data is called kernel. For evaluation in chapter \\ref{ch:discussion} the following four kernels from OpenCV \\cite{bradski2000opencv} and sklearn \\cite{Pedregosa2011} were used:\n\\begin{itemize}\n\t\\item Linear kernel: $k(x,y)=x*y$\n\t\\item Polynomial kernel: $k(x,y)=(\\gamma \\left\\langle x, y \\right\\rangle + coef_0)^\\text{degree}$\n\t\\item Radial basis function kernel: $k(x,y)=\\exp(-\\gamma ||x-y||^2)$\n\t\\item Additive $\\chi^2$ kernel: $ k(x,y)=-\\sum \\left[ (x-y)^2 / (x+y)\\right] $\n\\end{itemize}\n\\begin{figure}\n\t\\centering\n\t\\subfloat[Data not separable]{\\includegraphics[width=55mm]{figures/theorySVM_kernelTrick1}}\n\t\\subfloat[Data separable]{\\includegraphics[width=55mm]{figures/theorySVM_kernelTrick2}}\n\t\\subfloat[Data separable with hyperplane]{\\includegraphics[width=55mm]{figures/theorySVM_kernelTrick3}}\t\n\t\\caption{Illustration of Kernel trick. Data in {(a)} is not separable but if the data gets mapped into a higher dimensional space {(b)} a linear hyperplane can be fitted {(c)}. Figures plotted with code adapted from \\texttt{http://www.eric-kim.net/eric-kim-net/posts/1/kernel\\_trick.html}}\n\t\\label{fig:svmKernelTrick}\n\\end{figure}\n\n\\subsection*{Multiclass SVMs}\n\\label{subsec:svmMulticlass}\nIn case of a multiclass \\gls{svm} problem the most popular approach is to use several different binary class \\glspl{svm} instead of only one multiclass \\gls{svm} \\cite{Hsu2002, Duan2005, Thome2012}. There are two common solutions for the multiclass problem: One-VS-Rest and One-VS-One.\n\nAn One-VS-Rest multiclassifier with $n$ classes consists of $n$ distinct \\glspl{svm}. Each \\gls{svm} is trained on one of the classes as class A {(positive features)} and all other samples as class B {(negative features)}. Classification is done in a \"winner-takes-it-all\" fashion meaning that the \\gls{svm} with the highest output function assigns the class label.\n\nIn the One-VS-One approach $n\\frac{n-1}{2}$ \\glspl{svm} are constructed. Each class is paired in a \\gls{svm} with each other class. Classification is done in a \"majority-vote\" fashion so each \\gls{svm} votes for its class and the class with the most votes is assigned as the class label.\n\\newpage\n\\section{K-Nearest Neighbors}\nThe \\gls{knn} algorithm is a lazy classification algorithm which stores the complete training data in the learning phase \\cite{Keller1985}. In the classification phase it searches for the $k$ points in the training data that are nearest to the point that should be classified. The label that gets the majority of votes from the $k$ closest points {(neighbors)} is the result of the classification. See figure \\ref{fig:knn3} for a three class example and $k=3$. \n\nThe most popular metric to get the distance between the neighbors is the Euclidean distance, however, the accuracy can greatly be improved by using a learned distance metric such as the Mahanalobis distance which tries to maximize the margin between classes \\cite{Weinberger2005}. \n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/theoryKNN_3}\n\t\\caption{Example for a knn classification with $k=3$. The three nearest elements to the purple pentagon {(point that should be classified)} are marked with a square. Since two of the three neighbors are triangles the new point should also be a triangle.}\n\t\\label{fig:knn3}\n\\end{figure}\n\n\\section{Convolutional Neural Networks}\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.35]{figures/theoryCNN_model}\n\t\\caption{Sample architecture of a \\gls{cnn}. Source: Christodoulidis and Anthimopoulos \\cite{Christodoulidis2015}}\n\t\\label{fig:cnnModel}\n\\end{figure}\nA \\acrfull{cnn} is a multi-layer-feed-forward neural network that emulates the processes in the visual cortex by employing feature detection with small convolutional filters. \\glspl{cnn} generally outperform other gradient based learning techniques \\cite{LeCun1998} and are currently state-of-the-art \\cite{Russakovsky2015} for image recognition.\n\n\\glspl{cnn} usually consist of a succession of trainable convolutional, dense and pooling layers. Normally, the first layers comprise of several convolutional and pooling layers for feature extraction. For the classifications of features extracted in the previous layers, the network has at least one dense layer of neurons before the last layer. The last layer is usually the output layer and for the standard classification task the number of neurons is equal to the number of classes to classify so that the output of a neuron is the probability of a specific class at the same time. Figure \\ref{fig:cnnModel} shows an example of a \\gls{cnn} architecture with two convolutional and pooling layers and a dense, fully connected layer before the output layer. \n\n\\subsection*{Convolutional Layers}\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/theoryCNN_filter}\n\t\\caption{96 convolutional filters of size $3\\times 11\\times 11$ in the first layer. Filters trained on \\gls{ilsvrc}-2010. Source: Krizhevsky et al. \\cite{Krizhevsky2012}}\n\t\\label{fig:cnnFilter}\n\\end{figure}\nConvolutional layers contain multiple convolutional filters or kernels. They convolve the image to extract image features. Each filter convolves the output of the previous layer. In case of the first layer the filters operate directly on the input image. In later layers they collect more complex features from previous layers. Convolution happens by calculating the dot-product of the input matrix with the convolutional filter. Filters in \\glspl{cnn} usually overlap which helps to get a better translation invariance since each pixel is convolved multiple times by the same filter. The main goal of convolution in \\glspl{cnn} is to get distinctive image features. These convolutional filters are not handcrafted like filters in typical feature detectors. They learn the best filters by learning large quantities of data and change over the time and are ultimately able to extract features that are characteristic for the problem. Often, these kernels extract simple features like horizontal, vertical or diagonal edges {(figure \\ref{fig:cnnFilter})}. For food, prominent first layer kernels typically include many color kernels that specialize in extracting a range of similar colors \\cite{Christodoulidis2015}. The basic idea behind convolutional filters is that many features like edges or corners appear in multiple locations in images. By using the filters as a sliding window, one filter is able to detect the feature in any position.  \n\nTherefore, the main befit of using convolutional filters is the reduction of learnable weights. Filters are very small {(7x7 as the maximum size for a current \\gls{cnn} \\cite{Szegedy2014})} but are applied on the whole image in a sliding window approach. This means that a single convolutional filter shares weights for the image which significantly improves learning because it reduces the number of parameters to learn \\cite{LeCun1998}. GoogLeNet, a 22-layer \\gls{cnn}, uses \\gls{rgb} input images with a size of 224x224 \\cite{Szegedy2014}. A normal Neural Net without convolutions would not be able to handle this input size.\n\n\\subsection*{Pooling Layers}\nOnce a feature is detected the exact position becomes less important. Only the spatial relation to other features remains valuable. Knowing the exact position of a feature may even be harmful for generalization because the model becomes less invariant to position \\cite{LeCun1998}. One way to solve this problem and reduce the number of weights to learn is subsampling. In \\glspl{cnn} this normally occurs in pooling layers. Currently, the most common pooling layer type is max-pooling. This filter basically divides the input into $z\\times z$ blocks and extracts the maximum value of each block. A popular max-pooling layer instance is a $z=2$, stride $s=2$ layer. This layer downsamples the input by two. Recently, overlapping max-pooling layers have become popular \\cite{Szegedy2014}. They do not downsample as much as non-overlapping pooling layers {(in fact $z=3$ and $s=2$ outputs the same dimensions as the input)} but they seem to slightly decrease the error \\cite{Krizhevsky2012}.\n\n\\subsection*{Overfitting and Dropout}\n\\label{subsec:overfittingDropout}\nAlthough \\glspl{cnn} need fewer parameters to train high dimensional inputs than conventional neural nets, they also have the tendency to overfitt like conventional nets do. Overfitting is a common problem in machine learning that occurs if models are very complex. An overfitted model is optimized across the training data and describes or \"fits\" this data so well that it can not explain unseen data \\cite{Falkenauer1998}. Figure \\ref{fig:overfittingNet}a shows an overifitting neural network. After epoch 80 the error on the training set continues to decrease but the error on the validation set stops to decrease which means that although the net gets better at predicting the training data it gets worse for predicting unseen data.\n\nDropout is a novel way for neural nets to reduce the problem of overfitting by randomly dropping out nodes from the model. This forces the net to generalize better \\cite{Srivastava2014}.\n\n\\subsection*{Learning Rate and Momentum}\n\\label{subsec:learningMomentum}\nNeural networks try to find the global minimum of their cost function by adjusting the network weights. If there is only one minimum this is fairly easy as the network only has to adjust the weights towards the downward gradient. Real world scenarios, however, are much more complex and include many local minima as well. \n\nLearning rate and momentum are measurements of how weights are adjusted in backpropagation in search of the global minima. The learning rate denotes the magnitude of the weight change. That means that networks with a high learning rate advance faster along the gradient. Momentum is a term that multiplies a fraction of the previous weight update to the weight adjustment. By applying momentum, the steps the network takes on the gradient towards the minimum get bigger with each iteration. This helps to increase the speed of learning and may also prevent the network from getting stuck on local minima and saddle points because of the \"momentum\" the network simply \"steps over\" these points.\n\n\\section{Feature detectors and descriptors}\nA common approach in image classification is the use of feature detectors and feature descriptors. A feature detector detects interest points or keypoints in images. Ideally those keypoints are invariant to image transformations like rotation, scale or illumination changes so that the points can be found even if the image is rotated or taken from another perspective. In most cases, keypoints are corners, as corners can be localized quite easily. Knowing that a corner exists, however, does not help much with recognition. An algorithm also needs to describe the characteristics of an interest point so that it is possible to compare different interest points. The part of describing a keypoint is done by keypoint descriptors.\n\n\\subsection[HOG]{Histograms of Oriented Gradients (HOG)}\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[scale=0.45]{data/images/theory/theoryHOG_VisualizationGradients}\n\t\\caption{Visualization of HOG descriptor.}\n\t\\label{fig:hogVisualization}\n\\end{figure}\n\n\\acrfull{hog} is a popular image descriptor for human detection, developed by Dalal and Triggs in 2005 \\cite{Dalal2005}. The algorithm makes use of small contrast changes by describing the distribution of local gradients. This approach is believed to be based on biological processes of neurons in the primary visual cortex \\cite{Lowe2004}.\n\nThe first step is to divide the image into small blocks with a size of 16x16 pixels and a 50\\% overlap for better results. Each block is then subdivided by four 8x8 pixel cells. For each of these cells, gradient intensities are computed by applying the 1-D centered point derivative convolution mask horizontally and vertically:\n\\begin{equation}\n\tD_x=\n\t\\begin{bmatrix}\n\t-1 & 0 & 1\n\t\\end{bmatrix} \n\t\\quad\n\tD_y=\n\t\\begin{bmatrix}\n\t-1 \\\\ 0 \\\\ 1\n\t\\end{bmatrix} \n\\end{equation}   \nThe magnitude of the gradients is\n\\begin{equation}\n\tm=\\sqrt{(I\\ast D_x)^2+(I\\ast D_y)^2}\n\\end{equation}\nwhere $I$ is the image cell and the gradient orientation is given as\n\\begin{equation}\n\t\\theta = \\arctan \\left[\\ \\frac{(I\\ast D_y)}{(I\\ast D_x)}\\right]\\text{.}\n\\end{equation}\nTo achieve a better illumination invariance against shadowing, it is useful to contrast-normalize each cell. \n\nTo get a feature vector for each cell, a 9-bin histogram of the gradient orientations {(0\\degree - 180\\degree)} is calculated. The gradient orientations $\\theta$ are then scaled by the corresponding magnitude $m$. Figure \\ref{fig:hogVisualization} shows a visualization of gradient histograms. The gradient histogram in the center row on the right, is a single horizontal line meaning that the gradients in this cell are all horizontal which is logical because the original image in this cell is a horizontal edge.\n\nTo get the feature vector for the whole image all histograms are concatenated to form a large gradient histogram.\n\n\\gls{hog} is not rotation invariant which does not matter for human detection as humans tend to always have the same upright orientation. However, for food, rotation invariance is quite important.\n\n\\subsection[LBP]{Local Binary Pattern (LBP)}\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{figures/theoryLBP_coding}\n\t\\caption{Example for a LBP coding of the center pixel with value 6 (a). The neighboring pixels are thresholded against the center value (b) and multiplied by values in (c) with the result in (d). Source: Ojala et al. \\cite{Ojala1999}}\n\t\\label{fig:lbpCoding}\n\\end{figure}\n\\acrfull{lbp} is a simple texture descriptor which was originally proposed by Ojala et al. in 1994 \\cite{Ojala1994}. For the calculation of the \\gls{lbp} descriptor the 8 neighbors in a 3x3 block for each pixel are taken into account {(fig \\ref{fig:lbpCoding}a)}. The neighbors of the center pixel are then thresholded by comparing the value {(grayscale intensity)} of the pixel in the center to the intensities of the neighboring pixels. Pixels with a higher or equal value are getting labeled as \"1\" and \"0\" otherwise {(fig \\ref{fig:lbpCoding}b)}. Each position in the 3x3 block is then assigned a weight of $2^n$ {(fig \\ref{fig:lbpCoding}c)} where $n$ is ascending from left-to-right, top-to-bottom. In recent publications these weights are labeled clockwise ascending. The binary values are than multiplied by the corresponding weights {(fig \\ref{fig:lbpCoding}d)}. The values are then summed up and assigned as the new value for this \"texture unit\". The values can then be inserted into a histogram to form a 256-dim feature vector since there are 256 possible LBP values {($2^8=256$)}. Local binary patterns are invariant to grayscale changes because \\gls{lbp} describes spatial texture structure but not contrast intensities \\cite{Ojala1999}.  \n\nIn the following years \\gls{lbp} has been adapted and extended with additional contrast information \\cite{Ojala1999} or different neighborhood sizes to achieve rotation invariance with uniform \\glspl{lbp} \\cite{Ojala2002}.\n\n\n\\subsection[SIFT]{Scale invariant feature transform (SIFT)}\n\\label{subsec:sift}\n\\acrfull{sift} is a very popular local image feature detector, descriptor and matcher by Lowe from 1999 \\cite{Lowe1999}. It is invariant to uniform image scaling, translation and rotation and partially invariant to affine distortions, 3D viewpoint and illumination changes. It is also invariant to noise, partial occlusion and clutter \\cite{Lowe1999}. \n\n\\subsubsection*{Keypoint detection}\n%\\begin{figure}\n%\t\\centering\n%\t\\begin{minipage}{.5\\textwidth}\n%\t\t\\centering\n%\t\t\\includegraphics[width=0.45\\linewidth]{data/images/theory/theorySIFT_gaussianScales}\n%\t\t\\captionof{figure}{Image with different Gaussian scales.}\n%\t\t\\label{fig:gaussianScales}\n%\t\\end{minipage}%\n%\t\\begin{minipage}{.5\\textwidth}\n%\t\t\\centering\n%\t\t\\includegraphics[width=0.45\\linewidth]{data/images/theory/theorySift_dog}\n%\t\t\\captionof{figure}{Example of a Difference of Gaussians with $\\sigma=1$ and $\\sigma=3$.}\n%\t\t\\label{fig:dog}\n%\t\\end{minipage}\n%\\end{figure}\n\n\\begin{figure}\n\t\\centering\n\t\\begin{minipage}{.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=0.45\\linewidth]{figures/theorySIFT_scaleSpaceFiltering}\n\t\t\\captionof{figure}{Sequence of Gaussian smoothings of a 1D graph with $\\sigma$ increasing from bottom to top. Source Witkins \\cite{Witkin1983}}\n\t\t\\label{fig:scaleSpaceFiltering}\n\t\\end{minipage}%\n\t\\begin{minipage}{.5\\textwidth}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.45\\linewidth]{figures/theorySIFT_interestPointDetection}\n\t\t\t\\captionof{figure}{Interest points are detected by searching for minima and maxima. The value of the center pixel {(marked with X)} is compared to its 26 neighbors {(marked with circles)} on the current and adjacent scales. Source: Lowe \\cite{Lowe2004}}\n\t\t\t\\label{fig:interestPointDetection}\n\t\\end{minipage}\t\n\\end{figure}\n\n\nThe basic idea of \\gls{sift}'s keypoint extraction follows Witkins scale-space filtering \\cite{Witkin1983}. Witkins found out that by applying Gaussian smoothings at different scales of $\\sigma$ on a 1D-graph he could find robust edges depending on the scale of $\\sigma$ {(figure \\ref{fig:interestPointDetection}a)}. Since this process can also be applied to 2D images scale-space filtering is a good way to find scale invariant interest points {(also called \\gls{log})}. \\gls{sift}, however, uses a much more computation efficient approximation of \\gls{log} called \\acrfull{dog} \\cite{Lowe2004}. \\gls{dog} can be computed by subtracting two adjacent scales from each other. Figure \\ref{fig:dogScaleFiltering} shows the process of creating \\glspl{dog} at different scales. \\gls{sift} samples 3 scales per octave. After each octave the image size is halved and \\gls{dog} is applied again on the smaller image {(figure \\ref{fig:dogScaleFiltering})}.\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.3]{figures/theorySIFT_dogScaleFiltering}\n\t\\caption{For each octaves the image is blurred with Gaussian smoothings at rising scales. A \\gls{dog} is formed by subtracting two adjacent scales. After each octave the image size is halved and the process repeated. Source: Lowe \\cite{Lowe2004}}\n\t\\label{fig:dogScaleFiltering}\n\\end{figure}\n\nTo check if a pixel qualifies as an interest point at a certain scale, \\gls{sift} compares the values of the 3x3 neighboring pixels. If the pixel has the maximum or minimum value \\gls{sift} then compares the neighbors on the scales above and below. If the pixel has indeed the lowest or highest value across all 27 points it is taken as a potential interest point {(figure \\ref{fig:interestPointDetection})}. The cost of this operation is reasonably low because most of the pixels will be eliminated after the first few comparisons \\cite{Lowe2004}. To filter weak interest points, \\gls{sift} tries to eliminate low contrast points and points on edges since edges are not very robust features. After the elimination of weak points, \\gls{sift} computes a 32-bin gradient orientation histogram in the interest point neighborhood. Orientations are weighted by the magnitude of the gradient. Each bin represents 10\\degree of the 360 possible orientations. The bin with the highest peak is then selected as the dominant orientation for this keypoint. Bins with at least 80\\% of the highest bin value are selected to form an additional new keypoint.\n\n\\subsubsection*{Keypoint Description}\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.2]{figures/theorySIFT_descriptor}\n\t\\caption{Creation of the \\gls{sift} descriptor. Around the keypoint a 16x16 region {(this image is only half the size)} is taken and gradient orientations are calculated. The region forms 16 4x4 blocks with 8-bin gradient histograms. Source Lowe \\cite{Lowe2004}}\n\t\\label{fig:siftDescriptor}\n\\end{figure}\nThe \\gls{sift} keypoint descriptor relies on gradient orientation histograms. They are more stable features than just raw intensity values and less sensitive to 3D rotation. To calculate a descriptor for a keypoint, a neighborhood region of 16x16 pixels is selected oriented along the dominant orientation of the keypoint. The 16x16 region is then divided into 4x4 blocks and for each of these blocks a 8-bin gradient orientation histogram is calculated {(similar to the keypoint extraction)}. This results in a 128 dimensional feature vector for each keypoint {($16\\text{ blocks}*8\\text{ bins per histogram}=128$)} \\cite{Lowe2004}. Figure \\ref{fig:siftDescriptor} shows the process of the descriptor creation.\n\n\\subsection[SURF]{Speeded up Robust Features (SURF)}\n\\label{subsec:surf}\n\\gls{surf} is a feature detector and descriptor which was proposed in 2006 \\cite{Bay2006} and later revised in 2008 by Bay et al. \\cite{Bay2008}. It was developed with the goal to provide a faster alternative for the popular \\gls{sift} algorithm without trade offs in recognition performance.\n\n\\subsubsection*{Keypoint detection}\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.2]{figures/theorySURF_boxFilters}\n\t\\caption{Left half: discretized and cropped Gaussian second order partial derivates in $y$-direction and $xy$-direction. Right half: corresponding box filter approximations. Gray ares are equal to zero. Source Bay et al. \\cite{Bay2008}}\n\t\\label{fig:surfBoxFilters}\n\\end{figure}\nLike \\gls{sift}, \\gls{surf} also uses scale spaces to detect interest points. \\gls{surf}, however, relies on an approximation of the Hessian matrix\n\nThe first step is to compute the integral image. In integral images, pixel values are the sum of all pixels within a square between the pixel and the origin. These representations are efficient to compute and allow to find the sum of pixel values for any sized box within the image with only four arithmetic operations. Throughout the algorithm this benefit is leveraged to speed up detection and description.\n\nBay et al. approximate the Hessian matrix using box filters {(in the right of figure \\ref{fig:surfBoxFilters})}. By using integral images in combination with box filters the process of scale space creation can be sped up significantly. The benefit of box filters contrary to Gaussians which have to be applied iteratively is, that box filters can be applied directly on the original image which makes parallelization possible. In addition, \\gls{surf} does not downscale after each octave. It scales the image up which has the advantage of not causing aliasing. To localize interest points across scales, \\gls{surf} applies non-maximal suppression on a 3x3x3 neighborhood. \n\n\\subsubsection*{Keypoint Description}\nTo achieve rotation invariance, \\gls{surf} computes a dominant orientation for each interest point from a circular 6$s$ neighborhood by calculating Haar-wavelet responses in $x$ {(horizontal wavelet response)} and $y$ {(vertical wavelet response)} directions with $s$ being the scale of the interest point. Again, the combination of integral images and wavelets helps to calculate Haar-wavelets efficiently. The dominant orientation is calculated by the use of a sliding rotating window with an angle of $\\frac{\\pi}{3}$. The wavelet responses are then represented as vectors weighted with a Gaussian of $\\sigma=2.5s$. Horizontal and vertical vectors are added and the highest sum is the dominant interest point orientation.\n\nTo describe a keypoint, \\gls{surf} forms a square neighborhood region oriented along the dominant orientation with a size of 20$s$ {(so keypoints at higher scales include a bigger neighborhood)}. The region is then divided into 4x4 smaller sub-regions. In each of these sub-regions \\gls{surf} computes features at 5x5 evenly spaced sample points. Contrary to \\gls{sift}, \\gls{surf} does not utilize orientation histograms but again Haar-wavelet responses in horizontal $d_x$ and vertical $d_y$ direction relative to the dominant keypoint orientation. $d_x$ and $d_y$ are then summed up over each subregion. Those two and the sum of absolute response values $|d_x|$ and $|d_y|$ form the four dimensional feature vector for each subregion. Therefore, each keypoint has a 64 dimensional feature vector taking into account that there are 16 subregions each with a four dimensional vector. To achieve additional invariance to contrast and illumination changes the feature vector is turned into a unit vector.    \n\n\\subsection[ORB]{Oriented FAST and Rotated BRIEF (ORB)}\n\\gls{orb} is a combination of the corner detection algorithm \\gls{fast} \\cite{Rosten} and the binary descriptor \\gls{brief} \\cite{Calonder2010}. \\gls{orb} was introduced by Rublee and Bradski in 2011 \\cite{Rublee2011} as a replacement for \\gls{sift} for low-power devices and real time performance.\n\n\\subsubsection*{FAST Keypoint Detection}\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.3]{figures/theoryFAST_corners}\n\t\\caption{FAST corner detection. Interest points are selected if at least 12 adjoining pixel values that are either above or below the center pixels intensity {(dashed line)}. Source: Rosten and Drummond \\cite{Rosten}.}\n\t\\label{fig:fastCorners}\n\\end{figure}\n\\gls{fast} is a corner detection algorithm by Rosten and Drummond from 2006 that does not rely on Gaussians or scale spaces. \\gls{fast} compares 16 pixel intensities arranged on a circle with radius 9 around a possible corner point in the center. It is an interest point if it has at least 12 adjoining pixel values that are either above or below the center pixels intensity {(figure \\ref{fig:fastCorners})}. \\gls{fast}, however, is prone to have many responses along edges which are weaker features so \\gls{brief} tries to filter these edge responses by using a Harris corner measure. To achieve scale invariance \\gls{brief} applies \\gls{fast} on different image pyramid scale spaces. To also make the keypoints rotation invariant, \\gls{brief} calculates the intensity centroid which assumes that a corner's maximum intesity is offset from the actual center of the corner. This makes it possible to calculate the orientation by creating the vector from the intensity centroid to the actual corner point.\n\n\\subsubsection*{BRIEF Keypoint Description}\n\\gls{brief} is a binary descriptor from 2010 by Calonder et al. \\cite{Calonder2010}. Unlike \\gls{sift} or \\gls{surf}, a binary descriptor creates the descriptor values by comparing intensity values of pixels in the neighborhood of the keypoint. If the intensity of pixel $a$ is lower than the intensity of pixel $b$ than the test yields \"1\" and \"0\" otherwise. To create the feature vector \\gls{brief}  performs 256 binary tests and concatenates the results. The pixels that are compared are chosen by a Gaussian distribution around the center of the keypoint. Prior to these tests the image is smoothed. Additional in-plane rotation invariance is achieved by the proposed \"steered\" \\gls{brief}. Steered \\gls{brief} rotates the matrix of binary tests by a rotation matrix along the keypoint orientation. A lookup table with precomputed \\gls{orb} features is computed with a 12\\degree  interval. However, due to the very rotation by steered \\gls{brief}, the binary tests loose most of their variance so the expressiveness of the descriptor suffers. To prevent this, Rublee and Bradski proposed an algorithm to \"learn\" the optimal location of the pixel-pairs that are compared for the binary tests.\n\n\\subsection[CenSurE]{Center Surround Extremas (CenSurE)}\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[scale=0.2]{figures/theoryCenSurE_filters}\n\t\\caption{Center surround filters. From left to right: decreasing accuracy and computational cost.  Source Agrawal et al. \\cite{Agrawal2008}}\n\t\\label{fig:censureFilters}\n\\end{figure}\nThe \\gls{censure} feature detector was proposed by Agrawal et al. in 2008 as a framework of several bi-level filters for interest point detection \\cite{Agrawal2008}. \\gls{censure} is scale and rotation invariant and similar to the way \\gls{sift} and \\gls{surf} perform interest point detection. Contrary to the aforementioned keypoint detectors, \\gls{censure} does not up- or downscale the image in scale space and therefore does not inherit the disadvantages of up- and downscaling like inaccurate keypoint locations.\n\nTo detect corners \\gls{censure} employs approximations of \\gls{log} with center-surround discrete bi-level filters. The closest approximation of \\gls{log} is a circular bi-level filter as shown in figure \\ref{fig:censureFilters}a. Bi-level means that the filter only contains two values namely $1$ or $-1$. The circular filter is rotation invariant due to its symmetry but it is also expensive to compute. Therefore, \\gls{censure} uses octagons and boxes as approximations of the circular filter. Like \\gls{surf}, \\gls{censure} also leverages integral images for box filters and applies them on five scales. Since a major shortcoming of box filters is the lack of rotation invariance Agrawal et al. also proposed an octagon shaped filter which resembles the circle filter much more closely. Integral images, however, do not work with diagonal edges and thus do not work with octagons. To make computation still possible Agrawal et al. introduced \"slanted\" integral images which are able to construct any trapezoidal area in the same amount of time as rectangular integral images. \n\nTo detect interest points, \\gls{censure} performs non-maximal suppression over scale space across a 3x3x3 neighborhood. Weak interest points are filtered by threshold and edges are filtered the Harris corner measure.\n\n\\section{Bag of Words}\n\\acrfull{bow}, bag of features, bag of visual words or bag of keypoints is a simple, yet powerful image feature quantization method. The original idea of a \\gls{bow} approach for images came from texture classification \\cite{Leung2001}. Leung and Malik found out that by quantification of small texture patches {(textons)} in histograms they were able to accurately classify different textures. In 2004 Csurka et al. refined this approach and applied it to general image classification \\cite{Csurka2004}.\n\nThe idea behind a \\gls{bow} is very simple: During learning the \\gls{bow} clusters image descriptors using $k$-means clustering. The clustered representation of the image descriptors is called vocabulary. The vocabulary size is $k$, so using $k=1000$ for the k-means clustering results in a vocabulary of 1000 image features. Choosing $k$ is a trade-off between speed and accuracy and has to be determined during experiments. In an ideal world, a \\gls{bow} clusters image features together that are unique and expressive so that we would have a vocabulary of bread, salad, meat and noodle features.\n\nDuring classification the \\gls{bow} gets a set of image descriptors and matches these features with the previously learned vocabulary. The output of this process is a histogram of vocabulary occurrences. Referring to the ideal world example, the \\gls{bow} would get a set of features including many that look like bread, some that look like meat and a few that are similar to the salad texton. The output would be a histogram with a large value for the bread bin and some smaller values for the salad and meat bins. Giving this occurrence vector to a trained SVM would reveal that the image might be a Hamburger.\n\n\n\\section{Methodology}\n\\subsection{Performance Measurements}\n\n\\subsubsection*{Precession - Recall}\nThe most used measure for the precision of food classifiers is the average accuracy which is calculated by dividing the number of correct matches and the total number of samples. Accuracy, however, gives no information about the underlying conditions. It is a measure of overall performance. To have a higher chance of suggesting the correct items, future systems may present a list of options that the user can chose from. Intuitively, the accuracy is much higher if a classifier can present a list of items with high confidences instead of only one item because the problem is much easier. Accuracy, however, does not measures how easy a problem is. If a classifier were able to suggest all classes as options the accuracy would always be 100\\% although the results are not useful at all.\n\nThe combination of precision and recall objectively measures the actual relevance and performance of a classifier for a class of images because it includes the amount of considered items and the correct predictions. In this case the amount of considered items changes based on how many items the classifier can suggest. Precision and recall is defined as:\n\n\\begin{equation}\nPrecision = \\frac{T_p}{T_p+F_p} \\quad Recall = \\frac{T_p}{T_p+F_n}.\n\\end{equation}\n\n\\begin{itemize}\n\t\\item True positives $T_P$ is the number of correctly classified images of a class.\n\t\\item False positives $F_P$ are all images that the classifier predicted to be positive but are in reality negative. {(Type I Error)}\n\t\\item False negatives $F_N$ are all images that are positive {(belong to the class)} but are labeled as negative {(do not belong to class)} {(Type II Error)}\n\\end{itemize}\n\nA high recall means that many images were matched correctly and a high precision denotes a low number of incorrectly classified images. The bigger the area under the Precision-Recall curve the better the classifier.\n\n\\subsubsection*{Null Error Rate}\nThe null error rate is a baseline for any classification task that calculates the accuracy if a classifier would just predict the class with the most images.\n\n\\subsubsection*{Confusion Matrix}\nConfusion matrices are one of the most important metrics to understand why a classifier struggles with certain classes while getting a high precision with others. As the name suggests, a confusion matrix tells if the classifier \"confuses\" two classes.\n\nA confusion matrix for $n$ classes is always a $n \\times n$ matrix where columns represent the actual images classes and rows represent the predicted image classes so if the diagonal of the matrix has high values this means that the classifier makes correct predictions.\n\n\\subsubsection*{Categorical Cross-Entropy}\nThe categorical cross-entropy $L_i$ is an error function that is used for the training of neural networks in classification tasks as the objective function. It is more versatile than the accuracy or the \\gls{mse} because it takes the deviations of the predicted label $p_{i,j}$ and the actual label $t_{i,j}$ into account and weights the \"closeness\" of the prediction with the logarithm. For classification, cross entropy is more useful than \\gls{mse} because \\gls{mse} gives too much emphasis on incorrect predictions. The categorical cross entropy function is defined as:\n\n\\begin{equation}\nL_i = - \\sum_{j} t_{i,j}\\log(p_{i,j})\n\\end{equation} \n\nThe loss values that are used for the discussion of results for neural networks are the average values of the categorical cross-entropy {(\\gls{ace})}.\n\n\\subsection{Cross Validation}\nCross validation is one of the most essential techniques to evaluate real-world classification performance. Classifiers like \\glspl{svm} or neural networks are always better on data they have already seen. This is called overfitting {(see section \\ref{subsec:overfittingDropout})}. By training and testing on the same data the classification performance would be much better than the actual real world performance. To test if a classifier can actually work with samples it has not seen cross validation divides the dataset into different partitions. \n\nFor most tasks it is sufficient to divide the dataset into a training and a test set. The data in the training set is used to train the classifier and the test data is used to evaluate it with data is has not seen before.\n\n\\subsubsection*{k-fold Cross Validation}\nTo make the classification evaluation even more robust, $k$-fold cross validation is used. By applying $k$-fold cross validation the dataset is randomly partitioned into $k$ different parts. $k-2$ parts are used for training and two parts are used for the evaluation. This process is repeated $k$-times and after each iteration the parts are exchanged so that at the end, each sample was used for training and for validation. Calculating the mean of the $k$ evaluations gives a much more robust measurement because the evaluation does not depend on the difficulty of the test partitions.\n", "meta": {"hexsha": "5b3d3763f7ee8e052140212084ee51e61a04c9c8", "size": 41216, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapters/03_theory.tex", "max_stars_repo_name": "felixSchober/Deep-Food", "max_stars_repo_head_hexsha": "1cac55e945949cb5a04d742b35c023379a162c34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:46.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-13T19:38:17.000Z", "max_issues_repo_path": "Thesis/chapters/03_theory.tex", "max_issues_repo_name": "Jorba123/Deep-Food", "max_issues_repo_head_hexsha": "1cac55e945949cb5a04d742b35c023379a162c34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Thesis/chapters/03_theory.tex", "max_forks_repo_name": "Jorba123/Deep-Food", "max_forks_repo_head_hexsha": "1cac55e945949cb5a04d742b35c023379a162c34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-03-25T07:53:09.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-13T14:17:35.000Z", "avg_line_length": 112.3051771117, "max_line_length": 1444, "alphanum_fraction": 0.7881647904, "num_tokens": 10168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.8438951104066295, "lm_q1q2_score": 0.7419076504146833}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\n\\title{Messy Integral (@Vibingmath)}\n\\author{Shreenabh Agrawal}\n\\date{\\today}\n\\usepackage{amsmath}\n\\usepackage{geometry}\n\\geometry{a4paper, portrait, margin=1in}\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\\usepackage{amssymb}\n\\usepackage{relsize}\n\\usepackage[makeroom]{cancel}\n\\begin{document}\n\n\\maketitle\n\n\\section{Question}\n$$\\LARGE{{\\int\\limits_{1}^{e}}\\frac{x-x\\ln x+1}{x\\left(x+1\\right)^{2}+x\\ln^{2}x}\\: dx}$$\n\\section{Solution}\n\nLet us take substitution $\\ln x = t$ so that $dx = e^{t}dt$, thus our integral becomes\n\n$$\\LARGE{\\int\\limits_{0}^{1}}\\ \\frac{\\left(e^{t}\\ -\\ te^{t}\\ +\\ 1\\right)}{\\cancel{e^{t}}\\left[\\left(e^{t}+1\\right)^{2}\\ +\\ t^{2}\\right]}\\: {\\cancel{e^{t}}}\\:dt$$\nNow dividing both numerator and denominator by $t^2$ we get, \n$$\\mathlarger{\\LARGE{\\int\\limits_{0}^{1}}\\ \\frac{\\frac{e^{t}}{t^{2}}+\\ \\frac{1}{t^{2}}-\\frac{e^{t}}{t}}{\\left(\\frac{e^{t}}{t}+\\frac{1}{t}\\right)^{2}+\\ 1}\\ dt}$$\nNow taking a final substitution $$\\frac{e^{t}}{t}+\\frac{1}{t} = u$$ so that $$\\left(\\frac{e^{t}}{t}-\\frac{e^{t}}{t^{2}}-\\frac{1}{t^{2}}\\right)dt\\ =\\ du$$\nThe integral simplifies as:\n$$\\LARGE{\\int\\limits_{e+1}^{\\infty}\\frac{1}{1+u^{2}}\\ du}$$\nPlugging in the limits, the answer is $$\\boxed{=\\tan^{-1}\\left(\\frac{1}{1+e}\\right)}$$\n\\end{document}\n", "meta": {"hexsha": "a5f3bebb4e87d261d3fe82d2862200479d1a47bc", "size": 1304, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/vibing_math's questions/Messy Integral.tex", "max_stars_repo_name": "Nanu00/LaTeX", "max_stars_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-05-29T17:22:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T18:47:05.000Z", "max_issues_repo_path": "Calculus/vibing_math's questions/Messy Integral.tex", "max_issues_repo_name": "Nanu00/LaTeX", "max_issues_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-06-26T07:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-11T12:14:49.000Z", "max_forks_repo_path": "Calculus/vibing_math's questions/Messy Integral.tex", "max_forks_repo_name": "Shreenabh664/LaTeX", "max_forks_repo_head_hexsha": "675e03f3ec555456b9a2cc714825ec75317848c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-06-22T07:50:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-08T05:11:14.000Z", "avg_line_length": 39.5151515152, "max_line_length": 161, "alphanum_fraction": 0.6326687117, "num_tokens": 537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.741904086070968}}
{"text": "\\chapter{Sets}\n\\label{chapter:sets}\n\\marginurl{%\n  Sets:\\\\\\noindent\n  Introduction to Mathematical Reasoning \\#6\n}{youtu.be/bshBV2H4Sqo}\n\\section{The Intuitive Definition of a Set}\nA set is one of the two most important concepts in mathematics. Many mathematical\nstatements involve ``an integer $n$'' or ``a real number $a$''. Set theory\nnotation provides a simple way to express that $a$ is a real number or that $a$\nis a natural number. However, this language is much more expressible and it is\nimpossible to imagine modern mathematics without this notation.\n\nAs in the previous chapter it is difficult to define a set formally so we give\na less formal definition which should be enough to use the notation.\nA \\emph{set} is a well-defined collection of objects. Important examples of\nsets are:\n\\begin{enumerate}\n  \\item $\\R$ a set of reals,\n    \\nomenclature[S]{$\\R$}{denotes the set of all real numbers}\n  \\item $\\Z$ the set of integers\\footnote{``Z'' stands for the German word\n    Zahlen (``numbers'').},\n    \\nomenclature[S]{$\\Z$}{denotes the set of all integers}\n  \\item $\\N$ the set of natural numbers\\footnote{%\n      Note that in the literature\n      there are two different traditions: in one $0$ is a natural number, in\n      another it is not; in this book we are going to assume that $0$ is not a\n      natural number.\n    },\n    \\nomenclature[S]{$\\N$}{denotes the set of all integers greater than $0$}\n  \\item $\\Q$ a set of rational numbers,\n    \\nomenclature[S]{$\\Q$}{denotes the set of all rational numbers}\n  \\item $\\mathbb{C}$ a set of complex numbers.\n    \\nomenclature[S]{$\\C$}{denotes the set of all complex numbers}\n\\end{enumerate}\nUsually, sets are denoted by a single letter.\n\nObjects in a set are called \\emph{elements} of the set and we denote the\nstatement ``x is in the set $E$''\\footnote{%\n  The symbol $\\in$ was first used by Giuseppe Peano 1889 in his work\n  ``Arithmetices principia, nova methodo exposita''. Here he wrote on page X:\n  ``The symbol $\\in$ means is. So $a \\in b$ is read as a \\emph{is} a b;\n  \\dots''\n  The symbol itself is a stylized lowercase Greek letter epsilon\n  (``$\\epsilon$''), the first letter of the word  \\textgreek{esti}, which means\n  ``is''.\n} \nby the formula $x \\in E$ and the negation of this statement by $x \\not\\in E$.\nFor example, we proved that $\\sqrt{2} \\not\\in \\Q$.\n\\nomenclature[S]{$x \\in X$}{says that $x$ is an element of $X$} \n\\nomenclature[S]{$x \\not\\in Y$}{says that $x$ is not an element of $Y$} \n\n\\section{Basic Relations Between Sets}\nMany problems in mathematics are problems of determining whether two descriptions\nof sets are describing the same set or not. For example, when we learn how to\nsolve quadratic equations of the form $ax^2 + bx + c = 0$ ($a, b, c \\in \\R$) we\nlearn how to list the elements of the set $\\set[ax^2 + bx + c = 0]{x \\in \\R}$.\n\nWe say that two sets $A$ and $B$ are equal if they contain the\nsame elements (we denote it by $A = B$). If all the elements of $A$ belong to\n$B$ we say that $A$ is a subset of $B$ and denote it by\n$A \\subseteq B$\\footnote{%\n  In the literature there are three symbols for ``subset'': $\\subseteq$,\n  $\\subsetneq$, and $\\subset$. $A \\subseteq B$ means that $A$ is a subset of\n  $B$ and we allow $A = B$ and $A \\subsetneq B$ means that $A$ is a subset of\n  $B$ and we forbid $A = B$. However, there is a problem with the third symbol,\n  some people use it as a synonym of $\\subseteq$ and some use it as a synonym of\n  $\\subsetneq$. Due to this ambiguity we are going to avoid using it in this\n  book.\n}.\n\nFor example, $\\Q \\subseteq \\R$ since any rational number is\nalso a real number. A special set is an empty set i.e. the set that does not\nhave elements, we denote it $\\emptyset$.\n\n\\nomenclature[S]{$A \\subseteq B$}{says that $A$ is a subset of $B$}\n\n\\nomenclature[S]{$\\emptyset$}{denotes the set that does not have elements}\n\n\\begin{exercise}\n  \\label{exercise:inclusion}\n\n  Which of the following sets are included in which? Recall that a number is\n  prime iff it is an integer greater than $1$ and divisible only by $1$ and\n  itself.\n  \\begin{enumerate}\n    \\item The set of all positive integers less than $10$.\n    \\item The set of all prime numbers less than $11$.\n    \\item The set of all odd numbers greater than $1$ and less than $6$.\n    \\item The set of all positive integers less than $10$.\n    \\item The set whose only elements are $1$ and $2$.\n    \\item The set whose only element is $1$.\n    \\item The set of all prime numbers less than $11$.\n  \\end{enumerate}\n\\end{exercise}\n\n\\subsection{Diagrams}\nIf we think of a set $A$ as represented by all the points within a circle or\nany other closed figure, then it is easy to represent the notion of $A$ being a\nsubset of another set $B$ also represented by all the points within a circle.\nWe just put a circle labeled by $A$ inside of the circle labeled by $B$. We can\nalso diagram an equality by drawing a circle labeled by both $A$ and $B$. (see\nfig.~\\ref{figure:euler-diagram}). Such diagrams are called Euler diagrams and\nit is clear that one may draw Euler diagrams for more than two sets.\n\n\\begin{figure}\n    \\centering\n    \\subfloat[$B \\subseteq A$]{\n      \\begin{tikzpicture}[scale=0.6]\n        \\draw (20:2cm) circle (3cm) node [yshift=8ex] {$A$};\n        \\draw (0:2cm) circle (1.5cm) node {$B$};\n      \\end{tikzpicture}\n    }\n    \\qquad\\qquad\n    \\subfloat[$A = B$] {\n      \\begin{tikzpicture}[scale=0.6]\n        \\draw (20:2cm) circle (3cm) node [yshift=8ex] {$A, B$};\n      \\end{tikzpicture}\n    }\n    \\caption{Euler diagrams for subset and equality relations}\n    \\label{figure:euler-diagram}\n\\end{figure}\n\n\n\\subsection{Descriptions of Sets}\nIn this section we describe how to define new sets, this notation is also\nknown as \\emph{set-builder notation}.\n\n\\paragraph{Listing elements.} The simplest way to define a set is just to list\nthe elements. For example\n\\begin{enumerate}\n  \\item $\\set{1, 2, \\pi}$ is the set consisting of three elements 1, 2, and\n    $\\pi$, and\n  \\item $\\set{1, 2, 3, \\dots}$ is the set of all positive integers i.e. it is\n    the set $\\N$.\n\\end{enumerate}\n\n\\paragraph{Conditional definitions.}\nWe may also describe a set using some constraint e.g we may list all the even\nnumbers using the following formula $\\set[n \\text{ is even}]{n \\in \\Z}$\n(we read it as ``the set of all integers $n$ such that $n$ is even'').\n\nUsing this we may also define the set of all integers from $1$ to $m$, we\ndenote it $[m]$; i.e. $[m] = \\set[0 < n \\le m]{n \\in \\N}$.\n\\nomenclature[S]{$[n]$}{denotes the set of all the integers from $1$ to n}\n\n\n\\paragraph{Constructive definitions.} Another way to construct a set of all\neven numbers is to use the constructive definition of a set:\n$\\set[k \\in \\Z]{2k}$.\n\nWe may also describe a set of rational numbers using this description:\n$\\Q = \\set[a \\in \\Z, b \\in \\N]{a / b}$ (note that we may also use a mix of\na conditional and constructive definitions,\n$\\Q = \\set[a, b \\in \\Z, b \\neq 0]{a / b}$).\n\n\\begin{exercise}\n  Describe a set of perfect squares using constructive type of definition.\n\\end{exercise}\n\n\\subsection{Disjoint Sets}\nTwo sets are \\emph{disjoint} iff they do not have common elements. We also\nsay that two sets are \\emph{overlapping} iff they are not disjoint i.e. they\nshare at least one element.\n\nMore generally, $A_1$, \\dots, $A_\\ell$ are pairwise disjoint iff $A_i$ is\ndisjoint with $A_j$ for all $i \\neq j \\in [\\ell]$\n\n\\begin{exercise}\n  Of the sets in Exercise~\\ref{exercise:inclusion}, which are disjoint from\n  which?\n\\end{exercise}\n\n\n\\section{Operations over Sets.}\nAnother way to describe a set is to apply operation to other sets. Let $A$ and\n$B$ be sets.\n\\begin{figure}\n  \\centering\n  \\subfloat[$A \\cup B$]{\n    \\begin{tikzpicture}[scale=0.8]\n        \\fill[yellow] (45:2cm) circle (1.5cm);\n        \\fill[yellow] (0:2cm) circle (1.5cm);\n\n        \\draw (45:2cm) circle (1.5cm) node [above] {$A$};\n        \\draw (0:2cm) circle (1.5cm) node [below] {$B$};\n    \\end{tikzpicture}\n  }\n  \\qquad\\qquad\n  \\subfloat[$A \\cap B$]{\n    \\begin{tikzpicture}[scale=0.8]\n      \\begin{scope}\n          \\clip (45:2cm) circle (1.5cm);\n          \\fill[yellow] (0:2cm) circle (1.5cm);\n      \\end{scope}\n      \\draw (45:2cm) circle (1.5cm) node [above] {$A$};\n      \\draw (0:2cm) circle (1.5cm) node [below] {$B$};\n    \\end{tikzpicture}\n  }\n  \\vskip 0.25cm\n  \\subfloat[$A \\setminus B$]{\n    \\begin{tikzpicture}[scale=0.8]\n      \\begin{scope}[even odd rule]\n        \\clip (0:2cm) circle (1.5cm) (-0.25,-0.25) rectangle (3,3);\n        \\fill[yellow] (45:2cm) circle (1.5cm);\n      \\end{scope}\n      \\draw (45:2cm) circle (1.5cm) node [above] {$A$};\n      \\draw (0:2cm) circle (1.5cm) node [below] {$B$};\n    \\end{tikzpicture}\n  }\n  \\qquad\\qquad\n  \\subfloat[$A \\Delta B$]{\n    \\begin{tikzpicture}[scale=0.8]\n      \\begin{scope}[even odd rule]\n        \\clip (0:2cm) circle (1.5cm) (45:2cm) circle (1.5cm);\n        \\fill[yellow] (45:2cm) circle (1.5cm);\n        \\fill[yellow] (0:2cm) circle (1.5cm);\n      \\end{scope}\n\n      \\draw (45:2cm) circle (1.5cm) node [above] {$A$};\n      \\draw (0:2cm) circle (1.5cm) node [below] {$B$};\n    \\end{tikzpicture}\n  }\n  \\caption{Euler diagrams for set operations}\n\\end{figure}\n\n\nThe first example of the operations on sets is the \\emph{union} operation.\nThe union of $A$ and $B$ is the set containing all the elements of $A$ and all\nthe elements of $B$ i.e.\n$A \\cup B = \\set[x \\in A \\text{ or } x \\in B]{x}$\\footnote{%\n  Note that this definition is not correct since in the conditional definitions\n  we have to specify the set $x$ belongs to and we cannot do this here.\n}.\n\\nomenclature[S]{$A \\cup B$}{denotes the union of two sets $A$ and $B$}\n\nAnother example of such an operation is \\emph{intersection}. The\nintersection of $A$ and $B$ is the set of all the elements belonging to both\n$A$ and $B$ i.e $A \\cap B = \\set[x \\in A \\text{ and } x \\in B]{x}$\\footnote{%\n  You may notice that in the definition of the union we use disjunction and\n  in the definition of intersection we use conjunction. Actually this is the\n  reason the symbol of the conjunction is similar to the symbol of intersection\n  and the symbol of the disjunction is similar to the symbol of union.\n}.\n\\nomenclature[S]{$A \\cap B$}{denotes the intersection of two sets $A$ and $B$}\n\nThe third operation we are going to discuss this lecture is\n\\emph{set difference}. If $A$ and $B$ are some sets, then\n$A \\setminus B = \\set[x \\in A \\text{ and } x \\not\\in B]{x}$.\n\\nomenclature[S]{$A \\setminus B$}{denotes the difference of two sets $A$ and $B$}\n\nThe last operation is \\emph{symmetric difference}. If $A$ and $B$ are some\nsets, then $A \\Delta B = (A \\setminus B) \\cup (B \\setminus A)$. Note that\nalternatively $A \\Delta B = (A \\cup B) \\setminus (A \\cap B)$\n\n\\begin{exercise}\n  Describe the set\n  $\\set[n \\text{ is even}]{n \\in \\N} \\cap \\set[n \\in \\N]{3n}$.\n\\end{exercise}\n\n\\begin{theorem}\n\\label{theorem:set-equalities}\n  Let $A$, $B$, and $C$ be some sets. Then we have the following identities.\n  \\begin{description}\n    \\item[(associativity)] $A \\cup (B \\cup C) = (A \\cup B) \\cup C$ and\n      $A \\cap (B \\cap C) = (A \\cap B) \\cap C$.\n    \\item[(commutativity)] $A \\cup B = B \\cup A$ and $A \\cap B = B \\cap A$.\n    \\item[(distributivity)] $A \\cup (B \\cap C) = (A \\cup B) \\cap (A \\cup C)$\n      and $A \\cap (B \\cup C) = (A \\cap B) \\cup (A \\cap C)$.\n  \\end{description}\n\\end{theorem}\n\\begin{proof}\n  One may prove these properties using the Euler diagrams. Alternatively they\n  can be proven by definitions. Let us prove only the first part of the\n  distributivity, the rest is Exercise~\\ref{exercise:set-equalities}.\n\n  Our proof consists of two parts in the first part we prove that\n  $A \\cup (B \\cap C) \\subseteq (A \\cup B) \\cap (A \\cup C)$.\n  Suppose that $x \\in A \\cup (B \\cap C)$. Then $x \\in A$ or $x \\in (B \\cap C)$.\n  \\begin{itemize}\n    \\item If $x \\in A$, then $x \\in (A \\cup B)$ and $x \\in (A \\cup C)$ i.e.\n      $x \\in ((A \\cup B) \\cap (A \\cup C))$.\n    \\item If $x \\in (B \\cap C)$, then $x \\in B$ and $x \\in C$. Which implies\n      that $x \\in (A \\cup B)$ and $x \\in (A \\cup C)$. As a result,\n      $x \\in ((A \\cup B) \\cap (A \\cup C))$.\n  \\end{itemize}\n\\end{proof}\n\n\\begin{exercise}\n\\label{exercise:set-equalities}\n  Prove the rest of the equalities in Theorem~\\ref{theorem:set-equalities}.\n\\end{exercise}\n\nProbably the most difficult concept connected to sets is\nthe concept of a power set. Let $A$ be some set, then the set of\nall possible subsets of $A$ is denoted by $2^A$ (sometimes this set is denoted\nby $\\mathcal{P}(A)$) and called the power set of $A$. In other words $2^A =\n\\set[B \\subseteq A]{B}$.\n\n\\nomenclature[S]{$2^A$}{denotes the set of all the subsets of the set $A$}\n\n\\begin{warning}\n  Please do not forget about two extremal elements of the power set $2^A$: the\n  empty set and $A$ itself.\n\\end{warning}\n\n\\noindent For example if $A = \\set{1, 2, 3}$, then\n\\[\n  2^A = \\set{\\emptyset, \\set{1}, \\set{2}, \\set{3}, \\set{1, 2},\n  \\set{1, 3}, \\set{2, 3}, \\set{1, 2, 3}}.\n\\]\n\n\\section{The Well-ordering Principle}\nUsing the set notation we may finally justify the proof of the statement\nthat $2^n > n$ for all positive integers $n$ from the video about mathematical\ninduction. In order to do this let us first formulate the following theorem.\n\\begin{theorem}\n\\label{theorem:well-ordering}\n  Let $A \\subseteq \\Z$ be a non-empty set. We say that $b \\in \\Z$ is a lower\n  bound for the set $A$ iff $b \\le a$ for all $a \\in A$. Additionally, we say\n  that the set $A$ is bounded if there is a lower bound for $A$.\n\n  Given this, if $A$ is bounded, then there is a lower bound $a \\in A$ for the set $A$\n  (we say that $a$ is the minimum of the set $A$).\n\\end{theorem}\nNote that this theorem also states that any subset of natural numbers have a\nminimum.\n\nRecall that we wish to prove that $2^n > n$ for all positive $n$.\nAssume that it is not true, in this case the set\n$A = \\set[2^n < n]{n \\in \\N}$ is non-empty. Denote by $n_0$ the minimum of the\nset $A$, $n_0$ exists by Theorem~\\ref{theorem:well-ordering}. We may consider\nthe following two cases.\n\\begin{itemize}\n  \\item If $n_0 = 1$, then it leads to a contradiction since $2 = 2^1 > 1$.\n  \\item Otherwise, note that $1 \\le n_0 - 1 < n_0$, hence,\n    $2^{n_0 - 1} > n_0 - 1$. So $2^{n_0} > 2n_0 - 2 \\ge n_0$. Which is a\n    contradiction with the definition of $n_0$.\n\\end{itemize}\n\nFinally, we prove Theorem~\\ref{theorem:well-ordering}.\n\\begin{proof}[Proof of Theorem~\\ref{theorem:well-ordering}]\n  Let $b$ be a lower bound for the set $A$. Assume that there is no minimum of\n  the set $A$. Let $P(n)$ be the statement that\n  $n \\notin A$.\n\n  First, we are going to prove that $P(n)$ is true for all\n  $n \\ge b$. The base case is true since if $b \\in A$, then $b$ is the minimum\n  of $A$ which contradicts to the assumption that there is no minimum of $A$.\n  The induction step is also clear, by the induction hypothesis we know that\n  $P(b)$, \\dots, $P(k)$ are true, hence, $(k + 1) \\in A$ implies that $k + 1$\n  is the minimum of $A$.\n\n  Now we prove that $A$ is empty. Assume the opposite i.e. assume that there is\n  $x \\in A$. Note that $x \\ge b$ since $b$ is a lower bound of $A$. However,\n  $P(x)$ is true which implies that $x \\notin A$. Therefore the assumption was\n  false and $A$ is empty, but this contradicts to the fact that $A$ is non-\n  empty.\n\\end{proof}\n\n\n\\begin{chapterendexercises}\n  \\exercise Find the power sets of $\\emptyset$, $\\set{1}$, $\\set{1, 2}$,\n    $\\set{1, 2, 3, 4}$. How many elements in each of this sets?\n  \\exercise[recommended] Prove that\n    \\begin{itemize}\n      \\item $A \\subseteq B \\iff A \\cup B = B$,\n      \\item $A \\subseteq B \\iff A \\cap B = A$.\n    \\end{itemize}\n  \\exercise Let $A$ be a subset of a set $U$ we call this set a universe.\n    We say that the set $\\overline{A} = U \\setminus A$ is a complement of $A$\n    in $U$. Show the following equalities\n    \\begin{itemize}\n      \\item $\\overline{\\overline{A}} = A$.\n      \\item $\\overline{A \\cup B} = \\overline{A} \\cap \\overline{B}$.\n      \\item $\\overline{A \\cap B} = \\overline{A} \\cup \\overline{B}$.\n    \\end{itemize}\n  \\exercise[recommended] Let us define an intersection of more than two sets as follows.\n    Let $A_1$, \\dots, $A_n$ be some sets. Then\n    \\begin{itemize}\n      \\item $\\bigcap_{i = 1}^1 A_i = A_1$ and\n      \\item $\\bigcap_{i = 1}^{k + 1} A_i = \\left( \\bigcap_{i = 1}^k A_i \\right)\n        \\cap A_{k + 1}$.\n    \\end{itemize}\n    \\nomenclature[S]{$\\bigcap_{i = 1}^k A_i$}{denotes $A_1 \\cap \\dots \\cap\n    A_k$}\n\n    Show that $\\bigcap_{i = 1}^n \\set[i \\le x \\le n]{x \\in \\N} =\n    \\set{n}$ for all integers $n > 0$.\n    \\begin{solution}\n      There are two solutions for this problem which provide two important\n      points of view.\n\n      \\begin{enumerate}\n        \\item We may prove the statement using induction by $k$. Note that the\n          statement does not involve $k$ so we need to prove a bit different\n          statement, we prove \n          $\\bigcap_{i = 1}^k \\set[i \\le x \\le n]{x \\in \\N} =\n            \\set{k, k + 1, \\dots, n}$.\n          The base case for $k = 1$ is clear since \n          $\\bigcap_{i = 1}^1 \\set[i \\le x \\le n]{x \\in \\N} =\n            \\set[1 \\le x \\le n]{x \\in \\N} = \\set{1, 2, \\dots, n}$.\n\n          The induction step is also easy to see. By the induction hypothesis\n          $\\bigcap_{i = 1}^k \\set[i \\le x \\le n]{x \\in \\N} = \n            \\set{k, k + 1, \\dots, n}$.\n          Note that\n          \\begin{multline*}\n            \\bigcap_{i = 1}^{k + 1} \\set[i \\le x \\le n]{x \\in \\N} = \\\\\n            \\left(\n              \\bigcap_{i = 1}^k \\set[i \\le x \\le n]{x \\in \\N} \n            \\right) \\cap\n            \\set[k + 1 \\le x \\le n]{x \\in \\N} =  \\\\\n            \\set{k, k + 1, \\dots, n} \\cap \\set{k + 1, \\dots, n} =\n            \\set{k + 1, \\dots, n}.\n          \\end{multline*}\n          Thus for $k = n$,\n          $\\bigcap_{i = 1}^n \\set[i \\le x \\le n]{x \\in \\N} = \\set{n}$.\n        \\item Another approach is to prove the statement using induction by $n$.\n          The base case is also clear,\n          $\\bigcap_{i = 1}^1 \\set[i \\le x \\le n]{x \\in \\N} = \\set{1}$.\n\n          Let us now prove the induction step. By the induction hypothesis\n          $\\bigcap_{i = 1}^k \\set[i \\le x \\le k]{x \\in \\N} = \\set{k}$.\n          Hence,\n          \\begin{multline*}\n            \\bigcap_{i = 1}^k \\set[i \\le x \\le k + 1]{x \\in \\N} = \\\\\n            \\bigcap_{i = 1}^k \n              \\left(\n                \\set[i \\le x \\le k]{x \\in \\N} \\cup \\set{k + 1}\n              \\right)\n            \\stackrel{*}{=} \\\\\n            \\left(\\bigcap_{i = 1}^k \\set[i \\le x \\le k]{x \\in \\N} \\right) \\cup\n            \\set{k + 1} =\n            \\set{k, k + 1};\n          \\end{multline*}\n          note that all these equalities are clear except the equiality marked\n          by $*$, we prove it later.\n\n          Thus by the definition of the union\n          \\begin{multline*}\n            \\bigcap_{i = 1}^{k + 1} \\set[i \\le x \\le k + 1]{x \\in \\N} = \\\\\n            \\left(\n              \\bigcap_{i = 1}^k \\set[i \\le x \\le k + 1]{x \\in \\N}\n            \\right) \\cap \\\\\n            \\set[k + 1 \\le x \\le k + 1]{x \\in \\N}= \\\\\n            \\left(\n              \\bigcap_{i = 1}^k \\set[i \\le x \\le k + 1]{x \\in \\N}\n            \\right) \\cap\n            \\set{k + 1} = \\\\\n            \\set{k, k + 1} \\cap \\set{k + 1} =\n            \\set{k + 1}.\n          \\end{multline*}\n\n          Now we need to prove that if $A_1, \\dots, A_\\ell$, and $B$ are some sets,\n          then $\\bigcap_{i = 1}^\\ell (A_i \\cup B) =\n          \\left(\\bigcap_{i = 1}^\\ell A_i\\right) \\cup B$.\n          We prove it also using induction by $\\ell$. For $\\ell = 1$, the\n          statement is clear since $\\bigcap_{i = 1}^1 (A_i \\cup B) = A_1 \\cup B\n          = \\left(\\bigcap_{i = 1}^\\ell A_i\\right) \\cup B$.\n          Now we need to check the induction step. By the induction hypothesis\n          $\\bigcap_{i = 1}^k (A_i \\cup B) =\n            \\left(\\bigcap_{i = 1}^k A_i\\right) \\cup B$. Note that\n          \\begin{multline*}\n            \\bigcap_{i = 1}^{k + 1} (A_i \\cup B) =\n            \\bigcap_{i = 1}^k (A_i \\cup B) \\cap (A_{k + 1} \\cup B) = \\\\\n            \\left(\\left(\\bigcap_{i = 1}^k A_i\\right) \\cup B\\right) \\cap\n              (A_{k + 1} \\cup B) =  \\\\\n            \\left(\n              \\left(\n                \\bigcap_{i = 1}^k A_i\n              \\right) \\cap A_{k + 1} \n            \\right) \\cup B =\n            \\left(\\bigcap_{i = 1}^{k + 1} A_i\\right) \\cup B.\n          \\end{multline*}\n      \\end{enumerate}\n    \\end{solution}\n  \\exercise Let us define a union of more than two sets as follows.\n      Let $A_1$, \\dots, $A_n$ be some sets. Then\n      \\begin{itemize}\n        \\item $\\bigcup_{i = 1}^1 A_i = A_1$ and\n        \\item $\\bigcup_{i = 1}^{k + 1} A_i =\n          \\left( \\bigcup_{i = 1}^k A_i \\right) \\cup A_{k + 1}$.\n      \\end{itemize}\n      \\nomenclature[S]{$\\bigcup_{i = 1}^k A_i$}{denotes $A_1 \\cup \\dots \\cup\n      A_k$}\n\n      Show that $\\bigcup_{i = 1}^n \\range{i} = \\range{n}$ for all integers \n      $n > 0$.\n      \\begin{solution}\n        First, note that $\\range{k - 1} \\cup \\range{k} = \\range{k}$ for any \n        $k > 1$.\n\n        Now we are ready to prove the statement, we prove it using induction by\n        $n$. The base case is true since $\\bigcup_{i = 1}^1 \\range{i} =\n        \\range{1}$ by the definition. The induction step is also true since by\n        the induction hypothesis $\\bigcup_{i = 1}^{k - 1} \\range{i} = \n        \\range{k - 1}$ and by the definition of the union \n        $\\bigcup_{i = 1}^k \\range{i} = \n        \\left(\\bigcup_{i = 1}^{k - 1} \\range{i}\\right) \\cup \\range{k}$.\n        Hence, $\\bigcup_{i = 1}^k \\range{i} = \n          \\left( \\bigcup_{i = 1}^{k - 1} \\range{i} \\right) \\cup \\range{k} = \n          \\range{k - 1} \\cup \\range{k} = \\range{k}$.\n      \\end{solution}\n  \\exercise[recommended] Let $\\Omega$ be some set and $A_1, \\dots, A_n \\subseteq \\Omega$.\n    Show that $\\bigcup_{i = 1}^n A_i =\n      \\set[{\\exists i \\in \\range{n}\\ x \\in A_i}]{x \\in \\Omega}$.\n  \\exercise Let $A_1$, \\dots, $A_n$ be some sets.\n    Show that $\\bigcup_{i = 1}^n (A_i \\cap B) =\n    \\left(\\bigcup_{i = 1}^n A_i\\right) \\cap B$.\n  \\exercise Show that $A \\Delta (B \\Delta C) = (A \\Delta B) \\Delta C$.\n  \\exercise[recommended]\n    Let $\\mathbb{R}^{m \\times n}$ be the set of all matrices $m \\times n$ and\n    $\\mathbb{R}^n$ be the set of $n$ dimensional vectors.\n    Show that for any matrix $A \\in \\mathbb{R}^{m \\times n}$\n    ($n > m$) there is a nonzero vector $x \\in \\mathbb{R}^n$ such that $Ax = 0$.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "20f52d9f8dd551bcada9fad3eda363bcc91f8858", "size": 22463, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_1/chapter_6_sets.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_1/chapter_6_sets.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_1/chapter_6_sets.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 43.3648648649, "max_line_length": 89, "alphanum_fraction": 0.6165694698, "num_tokens": 7553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245911726381, "lm_q2_score": 0.8902942326713409, "lm_q1q2_score": 0.7419040774642027}}
{"text": "\\documentclass{standalone}\n\\begin{document}\n\\chapter{Applications of Calculus}\n\\section{Integrals}\n\\subsection{Volume of Revolution}\n\nIf part\tof a curve and the area underneath is rotated about a straight line, the solid formed is called a solid of revolution.\\\\\n\nConsider the graph $y=f(x)$ and suppose we  rotate the part of the curve from $x=a$ to $x=b$ about the x-axis. If the shaded area of $f(x)$ is notated about the $x$-axis the following shape is formed:\n\n\\begin{multicols}{2}\n\t\\begin{center}\n\t\t\\includegraphics[scale=0.5]{app_of_calc_integ_1}\n\t\\end{center}\n\t\\begin{center}\n\t\t~\\\\\n\t\t\\includegraphics[scale=0.5]{app_of_calc_integ_2}\n\t\\end{center}\n\\end{multicols}\n\n\nSuppose that the solid formed is cut into sections as shown. Let $PQRS$ be a typical section. If the cuts are reasonably close to each other, $PQRS$ approximates a cylinder with height $\\delta x$ and radius $y$ as shown below:\n\\begin{center}\n\t\\qquad \\qquad \\includegraphics[scale=1]{app_of_calc_integ_3}\n\\end{center}\nThe volume, $\\delta v$, of $PQRS$ is given by:\n$$\\delta V \\simeq \\pi y^2 \\delta x$$\nThus, the volume $V$ of solid $PQRS$ is given by:\n$$V\\simeq \\sum_{x=a}^{b} \\pi y^2 \\delta x$$\nThis summation approaches $V$ as $\\delta x \\to 0$\n$$V = \\lim\\limits_{\\delta x \\to 0}   \\sum_{x=a}^{b} \\pi y^2 \\delta x$$\n$$\\quad\\boxed{V = \\int_{a}^{b} \\pi y^2 \\, dx}$$\n\\hrulefill\n\\begin{example}\n\tFind the volume generated when the area  between $y=e^x$, the x-axis\n\\end{example}\n\n\\begin{alignat*}{2}\n\t&   & V & =\\int_{0}^{1} \\pi y \\, dx \\\\\n\\end{alignat*}\n\n\\begin{example}\n\tFind the volume generated when the area defined by the inequalities $y\\leq x^2$ and $y\\geq x$ is rotated about the $x$-axis.\n\\end{example}\n\\begin{multicols}{2}\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\twidth=8cm,\n\t\t\theight=6cm,\n\t\t\taxis line style={-},\n\t\t\txmin=0,\n\t\t\txmax=2.5,\n\t\t\tymin=0,\n\t\t\tymax=2.5,\n\t\t\txtick={}, % remove all ticks from x-axis\n\t\t\tytick={}, % ditto for y-axis\n\t\t\txlabel=$x$, \n\t\t\tylabel=$y$,\n\t\t\taxis lines=center, % default is to make a box around the axis\n\t\t\tsamples=100]\n\t\t\t\\addplot [name path=A,samples=501, domain=0:2, black] {sqrt(x)};\n\t\t\t\\addplot [name path=B,samples=501, domain=0:2, green]  {x};\n\t\t\t\\draw[pattern=north east lines,\n\t\t\tintersection segments={\n\t\t\t\tof=A and B,\n\t\t\t\tsequence={L2--R2[reverse]}\n\t\t\t}];\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\t\\begin{center}\n\t\t\n\t\\end{center}\n\t\n\\end{multicols}\n\\begin{alignat*}{2}\n\t&   & V_{e-c} & = V_e - V_c                                                      \\\\\n\t&   &         & = \\pi \\int_{0}^{1} \\sqrt{x}^2 \\, dx - \\pi \\int_{0}^{1} x^2 \\, dx \\\\\n\\end{alignat*}\n\\begin{example}\n\tFind the volume generated when the area in the first quadrant bounded by the circle $x=4\\cos\\theta, y=4\\sin\\theta$ rotates completely about the $x$-axis.\n\\end{example}\n\\begin{example}\n\t\n\tFind the volume when the region defined by  $y\\geq x^2+1,\\quad x\\geq0$ and $y\\leq2$ is rotated about the $y$-axis.\n\\end{example}\n\\begin{tikzpicture}\n\t\\begin{axis}[\n\t\twidth=8cm,\n\t\theight=6cm,\n\t\taxis line style={-},\n\t\txmin=0,\n\t\txmax=2.5,\n\t\tymin=0,\n\t\tymax=2.5,\n\t\txtick={}, % remove all ticks from x-axis\n\t\tytick={}, % ditto for y-axis\n\t\txlabel=$x$, \n\t\tylabel=$y$,\n\t\taxis lines=center, % default is to make a box around the axis\n\t\tsamples=100]\n\t\t\\path[name path=axis] (axis cs:0,0) -- (axis cs:0,2);\n\t\t\\addplot [name path=A, domain=0:2, black] {2};\t\n\t\t\\addplot [name path=B, domain=0:2, black]  {x^2 + 1};\n\t\t\\draw[pattern=north east lines,\n\t\t%TODO fix this\n\t\tintersection segments={\n\t\t\tof=B and A,\n\t\t\tof=axis and B,\n\t\t\tof=A and axis,\n\t\t\tsequence={L2--R\t2[reverse]}\n\t\t}];\n\t\t%\t\\draw[pattern=north east lines,\n\t\t%\tintersection segments={\n\t\t%\t\tof=axis and B,\n\t\t%\t}];\n\t\\end{axis}\n\\end{tikzpicture}\n\\subsection{Length of an arc of a curve}\nTo find the length of an arc of a curve we use the method of summing small elements of one length.\\\\\nSuppose that arc $PQ$, of length $\\delta s$, is such an element. Then, the length $S$ of the curve $AB$ is given by:\n\\begin{multicols}{2}\n\t\\begin{center}\n\t\t$\\sum_{x=x_1}^{x_2} \\delta S$\n\t\\end{center}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.7\\linewidth]{app_of_integ_4}\n\t\\end{center}\n\\end{multicols}\n\n\nAs $\\delta s$ is very small, it can be approximated to the hypothenuse of the $\\triangle PQR$. Thus:\n\\begin{alignat*}{2}\n\t&            & (\\delta x)^2 + (\\delta y)^2                    & \\simeq (\\delta s)^2                                                                 \\\\\n\t& \\implies   & 1 + \\left( \\frac{\\delta y}{\\delta x}\\right) ^2 & \\simeq \\left( \\frac{\\delta S}{\\delta x}\\right) ^2                                   \\\\\n\t& \\implies   & \\delta S                                       & \\simeq \\sqrt{1+\\left( \\frac{\\delta y}{\\delta x}\\right)^2 } \\delta x                 \\\\\n\t& \\therefore & S                                              & \\simeq \\sum_{x=x_1}^{x_2} \\sqrt{1 + \\left(\\frac{\\delta y}{\\delta x}\\right)}\\delta x \n\\end{alignat*}\n~\\\\\n~\\\\\nAs $\\delta x \\leftarrow 0, (\\frac{\\delta y}{\\delta x}) \\leftarrow \\frac{dy}{dx} \\quad $and$ \\quad s = \\lim_{\\delta x \\to 0} \\sum_{x=x_1}^{x_2} \\sqrt{1+\\left( \\frac{\\delta y}{\\delta x}\\right)^2}  \\delta x$\n~\\\\\n~\\\\\n~\\\\\n\n\\begin{center}\n\t\\begin{tcolorbox}[center title,hbox,    \n\t\tlifted shadow={1mm}{-2mm}{3mm}{0.1mm}%\n\t\t{black!50!white}]\n\t\t\\begin{varwidth}{\\textwidth}\n\t\t\t\\begin{center}\n\t\t\t\t$\\therefore \\quad S = \\int_{x_1}^{x_2} \\sqrt{1 + \\left(\\frac{dy}{dx}\\right)^2}\\, dx$\n\t\t\t\\end{center}\n\t\t\\end{varwidth}\n\t\\end{tcolorbox} \n\\end{center}\n\n\nKnowing the Cartesian equation of the curve, the necessary integration can be carried out.\\\\\n\nLet us now consider a curve $S$ parametrically in terms of $t$.\n\nWe can use again :\n\\begin{alignat*}{2}\n\t&          & (\\delta s )^2                            & \\simeq (\\delta x)^2 + (\\delta y)^2                                                                         \\\\\n\t& \\implies & \\left(\\frac{\\delta s}{\\delta t}\\right)^2 & \\simeq \\left(\\frac{\\delta x}{\\delta t}\\right)^2 + \\left(\\frac{\\delta y}{\\delta t}\\right)^2                 \\\\\n\t& \\implies & \\delta s                                 & \\simeq \\sqrt{\\left(\\frac{\\delta x}{\\delta t}\\right)^2 + \\left(\\frac{\\delta y}{\\delta t}\\right)^2} \\delta t \n\\end{alignat*}\n\n~\\\\\nas $\\delta t \\to 0\\quad ; \\quad \\frac{\\delta x}{\\delta t} \\to \\frac{dx}{dt} \\quad \\text{and} \\quad \\left(\\frac{\\delta y}{\\delta t}\\right) \\to \\frac{dy}{dt}$\\\\\n~\\\\\n\n$$\\therefore S = \\lim_{\\delta t \\to 0} \\sum_{t=t_1}^{t_2} \\sqrt{\\left(\\frac{\\delta x}{\\delta t}\\right)^2 + \\left(\\frac{\\delta y}{\\delta t}\\right)^2} \\delta t$$\n\n\\begin{center}\n\t\\begin{tcolorbox}[center title,hbox,    %%<<---- here\n\t\tlifted shadow={1mm}{-2mm}{3mm}{0.1mm}%\n\t\t{black!50!white}]\n\t\t\\begin{varwidth}{\\textwidth}\n\t\t\t\\begin{center}\n\t\t\t\t$S = \\int_{t_1}^{t_2} \\sqrt{\\left(\\frac{dx}{dt}\\right)^2 + \\left(\\frac{dy}{dt}\\right)^2}\\, dt$\n\t\t\t\\end{center}\n\t\t\\end{varwidth}\n\t\\end{tcolorbox} \n\\end{center}\n\\section{Rates of change}\nThe notation $\\dfrac{dy}{dx}$ denotes the rate of change of $y$ w.r.t.x. Suppose that $x$ and $y$ are quantities a such as length and volume respectively. Then $\\dfrac{dy}{dx}$ denotes the rate of change of volume w.r.t some length. In this section we use differentiation to deal with practical problems involving rates of change. \n\n\\begin{example}\n\tA spherical balloon is blown up so that its volume increases at a constant rate of $2\\text{cm}^3/s$. Find the rate of increase of the radius when the volume of the balloon is $50\\text{cm}^3$\n\\end{example}\n\n\\begin{multicols}{2}\n\t$\\od{V}{t} = 2$\n\t\n\\end{multicols}\n\\begin{example}\n\tA container with water is in the form of an inverted hollow cone with a iaerrentical angle of $30\\degree$. Water drips out from the vertex at the rate $3\\text{cm}^2/s$. Find the rate at which the surface area in contact with the water is changing when there are $8\\pi\\text{cm}^3$ of water remaining in the cone.\n\t\n\t\\begin{figure}\n\t\t\\includegraphics[scale=0.5]{app_of_calc_der_1}\n\t\\end{figure}\n\t\\begin{multicols}{2}\n\t\t\\begin{align*}\n\t\t\t\\od{V}{t} & = -3                            \\\\\n\t\t\tV         & = \\frac{1}{3} \\pi r^2 h         \\\\\n\t\t\tV         & = \\frac{1}{3} \\pi r^2 \\sqrt{3}r \\\\\n\t\t\tV         & = \\frac{\\sqrt{3}}{3}\\pi r^3     \\\\\n\t\t\t\\od{V}{t} & = \\sqrt{3}\\pi  r^2              \n\t\t\\end{align*}\n\t\t\\begin{align*}\n\t\t\t\\text{Required derivative: } \\od{A}{t} &          \\\\\n\t\t\tA                                      & = \\pi rl \n\t\t\\end{align*}\n\t\t\n\t\\end{multicols}\n\\end{example}\n\\end{document}\n\t", "meta": {"hexsha": "c54783c93243ad023f71abde01dfe456526bc246", "size": 8319, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Pure Mathematics/App_of_Calc.tex", "max_stars_repo_name": "Girogio/My-LaTeX", "max_stars_repo_head_hexsha": "706ec7cb4d62af1b5a9ad7547589889240c755bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-01-12T11:45:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-30T21:47:25.000Z", "max_issues_repo_path": "Pure Mathematics/App_of_Calc.tex", "max_issues_repo_name": "Girogio/My-LaTeX", "max_issues_repo_head_hexsha": "706ec7cb4d62af1b5a9ad7547589889240c755bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Pure Mathematics/App_of_Calc.tex", "max_forks_repo_name": "Girogio/My-LaTeX", "max_forks_repo_head_hexsha": "706ec7cb4d62af1b5a9ad7547589889240c755bb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.9863013699, "max_line_length": 331, "alphanum_fraction": 0.60355812, "num_tokens": 2919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694178, "lm_q2_score": 0.8688267881258485, "lm_q1q2_score": 0.7419022777167794}}
{"text": "\\lab{Correlation and Covariance}{Correlation and Covariance}\n\\label{lab:Stats1}\n\n\\objective{Explore applications of inner product spaces to topics in statistics.}\n\n% Source of the datasets: http://people.sc.fsu.edu/~jburkardt/datasets/regression/regression.html\n% under the GNU LGPL liscence\n\n\\section*{Shifting Data by the Mean}\nWhen analyzing numerical data, it is often useful to transform the data to have an average value of 0.\nThis process, which we call shifting by the mean, \nis easily accomplished by simply subtracting the mean of the data from each value. \nThe resulting shifted data now shows how each data point deviates from the mean.\nThis form makes it easier to spot outliers, judge the spread of the data, and compare with other data sets.\n\nConsider Table \\ref{tab:data} representing students scores in a class.\\\\\n\n\\begin{figure}\n\\begin{center}\n\\begin{tabular}{|c|r|r|r|r|}\n\t\\hline\nStudent & Homework & Exam 1  & Exam 2 & Final \\\\\n\\hline\nS1  & 89 & 91 & 77 & 75 \\\\\nS2  & 67 & 72 & 76 & 66 \\\\\nS3  & 72 & 77 & 69 & 70 \\\\\nS4  & 56 & 60 & 55 & 61 \\\\\nS5  & 92 & 98 & 89 & 86 \\\\\nS6  & 83 & 88 & 90 & 84 \\\\\nS7  & 45 & 60 & 55 & 48 \\\\\n\\hline\nAverage  & 72 & 78 & 73 & 70\\\\\n\\hline\n\\end{tabular}\\\\\n\\end{center}\n\\caption{Homework and exam scores for 7 students in a class.}\n\\label{tab:data}\n\\end{figure}\n\nWe can shift our data set by subtracting each column by its average value.  \nThis makes it so that the average of each column is zero.  \nIf $W$ represents the matrix of scores, the following Python command will shift each column by the mean.\n\\begin{lstlisting}\n>>> W = np.array([[89, 91, 77, 75],\n                  [67, 72, 76, 66],\n                  [72, 77, 69, 70],\n                  [56, 60, 55, 61],\n                  [92, 98, 89, 86],\n                  [83, 88, 90, 84],\n                  [45, 60, 55, 48]])\n>>> column_means = W.mean(axis=0)\n>>> X = W - column_means\n>>> X\narray([[ 17.,  13.,   4.,   5.],\n       [ -5.,  -6.,   3.,  -4.],\n       [  0.,  -1.,  -4.,   0.],\n       [-16., -18., -18.,  -9.],\n       [ 20.,  20.,  16.,  16.],\n       [ 11.,  10.,  17.,  14.],\n       [-27., -18., -18., -22.]])\n\\end{lstlisting}\n\nOnce we have subtracted out the mean from a vector, it is a simple task to compute its variance and standard deviation.\nThe \\emph{variance} of an $n$-dimensional vector $v$, often denoted $\\sigma^2$, is defined by the formula\n\\[\n\\sigma^2 = \\frac{1}{n}\\displaystyle\\sum_{i=1}^n (v_i - \\mu)^2,\n\\]\nwhere $\\mu$ is the mean of $v$. The \\emph{standard deviation} of $v$ is simply $\\sigma$, i.e. the square\nroot of the variance. These quantities measure the spread of the entries of the vector. When all of the entries are clustered\nclosely around the mean, the variance is small. See Figure \\ref{fig:variance} for an illustration of variance and mean-shifted data.\n\n(Note: \\emph{unbiased variance} is a quantity closely related to variance, but defined slightly differently. It comes into play\nin particular for small datasets or vectors. Further discussion is beyond the scope of this lab, but be aware that there is\nmore than one type of variance.)\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{variance}\n\\caption{On the left, the red values come from a vector with relatively high variance,\n         and the blue values come from a vector with relatively low variance.\n         On the right, the green values have been shifted by the mean from the blue values.}\n\\label{fig:variance}\n\\end{figure}\n\nCalculating the variance and the standard deviation in Python is straight forward.\nGiven the shifted data $X$, we simply square each entry, sum along the columns, and divide by the number of rows\nto obtain the variance. Take the square root of the result to get the standard deviation.\n\\begin{lstlisting}\n>>> var = (X**2).sum(axis=0)/X.shape[0]\n>>> var\narray([ 260.     ,  193.42857,  176.28571,  151.14285])\n>>> std = np.sqrt(var)\n>>> std\narray([ 16.124515,  13.907860,  13.277263,  12.294017])\n\\end{lstlisting}\nObserve that the scores for the homework exhibited the largest amount of spread.\n\nAs with many things in Python, there is an even shorter, more convenient way to calculate these quantities.\nWe may calculate the variance and standard deviation of the columns directly from $W$, without having to shift\nby the mean.\n\\begin{lstlisting}\n>>> W.var(axis = 0)\narray([ 260.     ,  193.42857,  176.28571,  151.14285])\n>>> W.std(axis = 0)\narray([ 16.124515,  13.907860,  13.277263,  12.294017])\n\\end{lstlisting}\n\n\\begin{problem}\n\\label{prob:shiftdata}\nImport the dataset contained in the \\li{weight_age_fat.txt} file. The first row is a header, and contains the names\nof each column, but no actual data. There are five columns, but the first two do not contain any data of interest.\nThe last three columns contain data on the weight (in kilograms), age (in years), and blood fat content of 25\nindividuals. Distinct data entries are separated by whitespace.\n\nWrite a function \\li{shiftByMean} that shifts the columns of an input array by their respective means, and returns the result.\nNext, write a function \\li{computeVariance} that calculates and returns the variance of each column of an input array.\nFinally, write a function \\li{reportStDev} that accepts no parameters and returns nothing, and simply contains a print\nstatement that prints out the name of the column with the smallest standard deviation as well as the numerical value of\nits standard deviation.\n\n\\end{problem}\n\n\\section*{The Inner Product and Angles Formula}\n\nInner products give information about lengths of vectors and angles between vectors.\nRecall that the standard inner product on $\\mathbb{R}^n$ between vectors $v$ and $u$ is given by\n\\[\n\\ipt{v}{u} = v^T u = \\displaystyle\\sum_{i=1}^n v_iu_i.\n\\]\nWe can take advantage of convenient syntax in NumPy to quickly calculate the inner product between two vectors:\n\\begin{lstlisting}\n>>> v = np.array([1., -2., 4.])\n>>> u = np.array([2., 3., -1.])\n>>> v.dot(u)\n-8.0\n\\end{lstlisting}\nThe 2-norm of a vector can be easily recovered from the inner product:\n\\begin{lstlisting}\n>>> v_norm = np.sqrt(v.dot(v))\n>>> v_norm\n4.5825756949558398\n\\end{lstlisting}\nAnother option to calculate the norm of an array is to use the \\li{numpy.linalg.norm} function, which has the\ncapability of computing a variety of different types of norms. \nIt is also convenient for computing norms of columns or rows of matrices, as follows:\n\\begin{lstlisting}\n>>> from numpy.linalg import norm\n>>> # calculate norms of the columns of X\n>>> norm(X, axis=0)\narray([42.661, 36.797, 35.128, 32.527])\n\\end{lstlisting}\n\nRecall that the angle $\\theta$ between two nonzero\nvectors $v$ and $u$ is given by\n\\[\n\\cos{\\theta} = \\frac{\\ipt{v}{u}}{\\norm{v}\\norm{u}}\n\\]\nwhere $\\norm{v} = \\sqrt{\\ipt{v}{v}}$ denotes the 2-norm of $x$.\nBy bringing the constants into the inner product, we see that the angle satisfies\n\\[\n\\cos{\\theta} = \\left\\langle\\frac{v}{\\norm{v}},\\frac{u}{\\norm{u}}\\right\\rangle.\n\\]\nHence, if we view the columns of $X$ as vectors in $\\mathbb{R}^7$, we can find the cosine of the angles between these columns by dividing each\nby its length, and then computing pairwise inner products. \nTo divide the columns by their respective lengths, we may execute the following code.\n\\begin{lstlisting}\n>>> Y = X/norm(X, axis=0)\n>>> Y\narray([[ 0.39848615,  0.35329218,  0.11386819,  0.15371887],\n       [-0.11720181, -0.16305793,  0.08540114, -0.12297509],\n       [ 0.        , -0.02717632, -0.11386819,  0.        ],\n       [-0.37504578, -0.48917378, -0.51240685, -0.27669396],\n       [ 0.46880723,  0.54352643,  0.45547275,  0.49190037],\n       [ 0.25784398,  0.27176321,  0.4839398 ,  0.43041282],\n       [-0.63288976, -0.48917378, -0.51240685, -0.67636301]])\n\\end{lstlisting}\n\nFinally, we get the cosines of the angles between columns by computing $Y^T Y$. To justify this calculation, consider\nthe $(i,j)^{th}$ entry of $Y^T Y$:\n\\begin{align*}\n(Y^T Y)_{i,j} &= \\sum_{k=1}^n (Y_{i,k})(Y^T)_{k,j} \\\\\n&= \\sum_{k=1}^n Y_{i,k}Y_{j,k} \\\\\n&= \\left\\langle Y_{:,i}, Y_{:,j} \\right\\rangle,\n\\end{align*}\nwhere $Y_{:,i}$ denotes the $i^{th}$ column of $Y$, and $Y_{:,j}$ the $j^{th}$ column.\nThus, we may obtain the cosine of the angle between each pair of columns of $X$ by computing $Y^T Y$,\nwhich can be easily done in Python as follows:\n\\begin{lstlisting}\n>>> np.dot(Y.T,Y)\narray([[ 1.        ,  0.97782999,  0.89014869,  0.94908967],\n       [ 0.97782999,  1.        ,  0.90978843,  0.92490144],\n       [ 0.89014869,  0.90978843,  1.        ,  0.9276955 ],\n       [ 0.94908967,  0.92490144,  0.9276955 ,  1.        ]])\n\\end{lstlisting}\n\nWe remark that the diagonals are always equal to one because the angle between a vector and itself is zero, and the cosine of zero is one.\n\n%It is also worth noting that the matrix resulting from the operation $A \\cdot A^T$ is symmetric and positive definite, so it compliant\n%with the Cholesky decomposition that was discussed at the end of Lab \\ref{lab:LUdecomp}.\n% ^^ I'm not totally sure what is going on with this last statement. What exactly is A \\cdot A^T? I'm assuming we mean A^T A, in which case\n% the matrix is in fact only guaranteed to be positive semi-definite. It still has a Cholesky decomposition in theory, although I think it can only be\n% computed for positive definite matrices. Anyway, I don't think the comment is relevant, so I have it removed for now.\n\n\\section*{Correlation}\nIn statistics, \\emph{correlation} is a broad term that refers to various types of statistical relationships and dependence between\nvariables of interest.\nIn this setting, the \\emph{Pearson correlation coefficient} of two vectors $u$ and $v$ is defined to be the cosine of the angle between the\nvectors $\\overline{u}$ and $\\overline{v}$, where $\\overline{u}$ is the vector obtained by subtracting the mean of $u$ from each of its entries,\nand similarly for $\\overline{v}$.\nTwo vectors are said to be\n\\begin{itemize}\n\\item Perfectly correlated if their correlation coefficient is equal to 1.\n\\item Positively correlated if their correlation coefficient is between 0 and 1.\n\\item Uncorrelated if their correlation coefficient is equal to 0.\n\\item Negatively correlated if their correlation coefficient is between -1 and 0.\n\\item Perfectly anticorrelated if their correlation coefficient is equal to -1.\n\\end{itemize}\n\nIf we have an array whose columns are the vectors of interest, we may calculate a correlation matrix\nby first shifting the columns by their mean, and then computing the matrix of angles as described in the\nprevious section. The $(i,j)$ entry of the resulting correlation matrix gives the correlation coefficient\nof columns $i$ and $j$.\n\n\\begin{problem}\nWrite a function \\li{corrMatrix} that calculates and returns the correlation matrix of the columns of the input array.\n\\end{problem}\nAgain, NumPy provides a method for computing the correlation matrix of the columns or rows of an array via the function \\li{np.corrcoef}.\nBe aware of the keyword argument \\li{rowvar}.\nNonzero integer values for \\li{rowvar} will yield the correlation matrix of the rows, whereas a value of 0 for \\li{rowvar} will produce the correlation matrix of the columns.\n\\begin{lstlisting}\n>>> np.corrcoef(W, rowvar=0)\narray([[ 1.        ,  0.97782999,  0.89014869,  0.94908967],\n       [ 0.97782999,  1.        ,  0.90978843,  0.92490144],\n       [ 0.89014869,  0.90978843,  1.        ,  0.9276955 ],\n       [ 0.94908967,  0.92490144,  0.9276955 ,  1.        ]])\n\\end{lstlisting}\nTime both your implementation as well as that of NumPy. Which is faster?\n\nThe notion of correlation is important in establishing linear relationships between measurements.\nParallel vectors pointing in the same direction are perfectly correlated, since they lie in the same line.\nOrthogonal vectors, on the other hand, are uncorrelated.\nGiven two vectors of the same length, one can visually check for correlation by viewing a scatter plot.\nThis can be done in Python as follows:\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n>>> x = np.random.rand(100)\n>>> y = np.random.rand(100)\n>>> plt.scatter(x,y)\n>>> plt.show()\n>>> plt.clf()\n\\end{lstlisting}\nYou will observe that the scatter plot does not indicate any obvious linear relationship between the two\nvectors. You can calculate the correlation coefficient and confirm that it is close to zero.\nSee Figure \\ref{fig:correlation} for examples of correlated and uncorrelated data.\n\n\\begin{figure}[h]\n\\includegraphics[width=\\textwidth]{correlation}\n\\caption{Left: scatter plot of two slightly positively correlated vectors.\n         Middle: scatter plot of two uncorrelated vectors.\n         Right: scatter plot of two highly negatively correlated vectors.}\n\\label{fig:correlation}\n\\end{figure}\n\n\\begin{problem}\nImport the data contained in the \\li{mortality.txt} file. The first 17 rows are headers, providing the names of the\n17 columns, and do not contain data. The first column is simply an index column, and may also be omitted.\nThe following 16 columns provide various demographic and environmental data for 60 countries, with the\nfinal column giving the mortality rate for that country.\nDistinct data entries are separated by whitespace.\n\nWrite a function that prints the answers to the following three questions, and generates plots as\ndescribed below.\nBetween which pair of distinct columns is the highest correlation?\nWhich column (apart from the last column) has the most negative correlation coefficient with mortality rate?\nWhich column is most nearly uncorrelated with mortality rate (i.e. the correlation coefficient is closest to 0)?\nMake scatter plots of all three of these pairs of columns, and include them on the same subplot panel.\nIn all relevant cases, the mortality rate column should be the second argument passed to \\li{plt.scatter}.\n\\end{problem}\n\nIt's important to understand that the high correlation between quantities does not necessarily imply\na causal relationship. For example, high correlation between violent crime rates and ice cream sales has\nbeen observed. This does not mean that ice cream causes crime or that increases in crime makes people want\nto eat more ice cream. Rather, both rates happen to increase during the summer and decrease during the winter.\n\nAnother import consideration is that the correlation coefficient does not provide information about\nnon-linear relationships and dependencies between data (see Figure \\ref{fig:non_linear}). Any thorough analysis will go well beyond a simple\ncalculation of the correlation matrix.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{nonlinear_dependence}\n\\caption{There is a clear nonlinear relationship present in this data, but the Pearson correlation\n         coefficient, which has a value of -0.00056, fails to capture it.}\n\\label{fig:non_linear}\n\\end{figure}\n\n\\section*{Covariance}\nRelated to the notion of correlation is that of covariance. \nThe covariance of two vectors measures how they jointly vary together. \nIn mathematical terms, given two vectors $u$ and $v$ in $\\mathbb{R}^n$, with $\\bar{u}$ and $\\bar{v}$ denoting the mean-shifted \nversions of these vectors (as before), we define the \\emph{covariance} of $u$ and $v$ to be\n\\[\n\\text{cov}(u,v) = \\frac{\\ipt{\\bar{u}}{\\bar{v}}}{n-1}.\n\\]\nIf $u$ and $v$ are close to parallel and both have high variance, then their covariance will be large in magnitude. \nOn the other hand, if $u$ and $v$ are nearly orthogonal (that is, nearly uncorrelated), or one has very small variance,\nthen their covariance will be small in magnitude. \n\nJust as with correlation, we can generate a covariance matrix for a collection of vectors that contains the covariance for each set of vectors.\nSpecifically, given a collection of vectors $x_1,\\ldots, x_m$, we define the covariance matrix $C$ for this collection to be the $m \\times m$ matrix satisfying\n\\[\nC_{i,j} = \\text{cov}(u,v).\n\\]\nIf we let $X$ be the matrix whose columns are the mean-shifted vectors $\\bar{x_1}, \\ldots, \\bar{x_m}$, note that\n\\begin{equation}\nC = \\frac{1}{n-1}X^TX.\n\\label{eq:cov}\n\\end{equation}\nThis gives us a very straight-forward way to compute the covariance matrix in Python:\n\\begin{lstlisting}\n>>> # we will calculate the covariance matrix of W\n>>> # subtract out the mean from the columns\n>>> X = W-W.mean(axis=0)\n>>> C = X.T.dot(X)/(X.shape[0]-1)\narray([[ 303.33333333,  255.83333333,  222.33333333,  219.5       ],\n       [ 255.83333333,  225.66666667,  196.        ,  184.5       ],\n       [ 222.33333333,  196.        ,  205.66666667,  176.66666667],\n       [ 219.5       ,  184.5       ,  176.66666667,  176.33333333]])\n\\end{lstlisting}\nAs usual, there is a nice way to compute the covariance matrix in NumPy, using the function \\li{np.cov}. This function\nalso has the keyword argument \\li{rowvar} which determines whether the covariance of the rows or of the columns is computed.\n\\begin{lstlisting}\n>>> np.cov(W, rowvar=0)\narray([[ 303.33333333,  255.83333333,  222.33333333,  219.5       ],\n       [ 255.83333333,  225.66666667,  196.        ,  184.5       ],\n       [ 222.33333333,  196.        ,  205.66666667,  176.66666667],\n       [ 219.5       ,  184.5       ,  176.66666667,  176.33333333]])\n\\end{lstlisting}\n\n\\begin{problem}\nCompute and report the covariance matrix of the \\li{mortality.txt} data set. \n\\end{problem}\n\nNote that the covariance matrix is symmetric. \nIndeed, from equation \\ref{eq:cov}, we can see that it is positive semi-definite and has nice spectral properties.\nObserve from that same equation that the spectral decomposition of the covariance matrix is closely related to the singular value decomposition of $X$.\nIt turns out that the covariance matrix and its spectral properties contain much information about relationships, patterns, and structure in the data. \nSeveral statistical techniques in data compression, dimensionality reduction, and information retrieval rely on discovering and exploiting this structure,\nand hence the covariance matrix and the singular value decomposition play an important role in data analysis. \n\n\\section*{Latent Semantic Indexing}\nWe now have the tools to build a simple, yet effective, system for indexing and retrieving documents according to their semantic content.\nThe method that we will implement is called \\emph{Latent Semantic Indexing}, or LSI.\n\nSuppose we have a collection of documents, which we call a \\emph{corpus}, and we wish to find the particular documents\nthat are most closely related to a given sequence of search terms. \nThis problem arises when searching a database of newspaper articles, an email inbox, a scientific journal, and in many more settings. \nWhen our corpus consists of many documents, it becomes infeasible to read, or even skim, each document on our own. \nWe need to utilize our mathematical and computational skills to facilitate the process.\nTo begin, we create a numerical representation of our corpus. \nA common approach, known as the \\emph{vector space model}, is as follows. \nFirst, specify a list $v$ of words of interest (this could just be all the unique words found in the corpus).\nLet $m$ be the length of the list $v$. Then we can represent a given document by a $m$-dimensional vector \n\\[\nd = \\begin{bmatrix}\nd_1 & d_2 & \\cdots & d_m\n\\end{bmatrix}^T,\n\\]\nwhere $d_i \\in \\mathbb{R}$ gives the contribution of the $i$-th term in the list $v$ to the document. \nFor our purposes in this lab, we define $d_i$ to be the number of times term $i$ occurs in the document.\nThe following code snippet shows how to compute the vector representation of a document given a list of words.\nWe use a particular data structure \\li{Counter}, which counts the number of occurrences of each unique element in a list.\n\\begin{lstlisting}\n>>> from collections import Counter\n>>> # initialize the word list and the document\n>>> v = [\"the\", \"great\", \"live\", \"math\", \"things\", \"do\", \"me\", \"you\"]\n>>> doc = \"If you cannot do great things do small things in a great way\"\n>>> # split the document into a list of words, make counter\n>>> count = Counter(doc.split())\n>>> # create the vector representation\n>>> d = np.array([count[w] for w in v])\n>>> print d\n[0 2 0 0 2 2 0 1]\n\\end{lstlisting}\nIf our corpus consists of $n$ documents, then we can represent the entire corpus by a $m \\times n$ matrix\n$D$ whose columns are just the vector representations of the documents. \nIn most real-world applications, $m$ and $n$ are very large (in the several thousands, or more). \nThankfully, the matrix $D$ will often be very sparse, since each particular document contains only a small subset\nof the entire list of words.\nThus, we can use the sparse libraries in SciPy to efficiently store and compute with this matrix.\n\nWe now use the singular value decomposition to reduce the dimensionality of the matrix representation of our\ncorpus in a way that optimally decouples the semantic content of the documents. \nMore precisely, we specify the number $t$ of greatest singular values we wish to retain, and calculate the truncated SVD of the matrix $D$,\nyielding a rank-$t$ approximation\n\\[\nD_t = U_t\\Sigma_tV_t^T,\n\\]\nwhere $U_t$ and $V_t$ are orthogonal matrices of size $m \\times t$ and $n \\times t$, respectively, and $\\Sigma_t$\nis a $t \\times t$ diagonal matrix containing the $t$ largest singular values of $D$. \nA typical value for $t$ is in the low hundreds.\nWe can compute this in Python as follows:\n\\begin{lstlisting}\n>>> from scipy.sparse import linalg as la\n>>> # assume D is a sparse matrix\n>>> t = 100\n>>> U, Sig, VT = la.svds(D, k=t)\n\\end{lstlisting}\nAlthough $U_t$ and $V_t$ are not sparse, they are much more feasible to compute with given that $t \\ll m$. \nObserve that the $i$-th column of $V_t^T$ is $\\Sigma_t^{-1}U_t^Td_i$, a transformed version of the $i$-th document vector.\nIt turns out that the matrix $\\Sigma_t^{-1}U_t^T$ defines a projection from $\\mathbb{R}^m$ onto a $t$-dimensional subspace\nin such a way that the projections of semantically similar documents have high correlation in the subspace, and\nsemantically differing documents will have low correlation. \nThus, if $q$ is the vector representation of a query, we can find the document in the corpus with the closest semantical\ncontent to $q$ by projecting $q$ down to the $t$-dimensional subspace, calculating its correlation with each of the \nprojected document vectors in the corpus, and then selecting the document with the highest such correlation.\n\\begin{comment}\nThe discussion above is still lacking, and doesn't quite hit the nail on the head. \nBut I don't want it to become to wordy and bloated, so I'll leave it as is for now.\n\\end{comment}\n\\begin{lstlisting}\n>>> # assume that docs is a list of the original documents\n>>> # assume that q is the vector representation of a query\n>>> # first, project q to the subspace\n>>> q = (1/S)*(U.T.dot(q))\n>>> # now calculate correlation of q with each column of VT\n>>> q -= q.mean()           # shift by mean\n>>> VT -= VT.mean(axis=0)\n>>> q /= norm(q)            # normalize\n>>> VT /= norm(VT, axis=0)\n>>> coefs = VT.T.dot(q)\n>>> # select the index of the highest correlation\n>>> ind = np.argmax(coefs)\n>>> print docs[ind]\n\\end{lstlisting}\n\\begin{problem}\nDo LSI and stuff.\n\\end{problem}\n\nAs a final note, the concepts of variance, standard deviation, correlation, and covariance apply to a much broader class of objects\nknown as \\emph{random variables}, which are central to statistics and probability theory. These topics will be\ncovered in detail later on.\n", "meta": {"hexsha": "b866cef37e477c2d73e041c1c26e2196670fe9f9", "size": 23382, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/CorrelationCovariance/CorrCovariance.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Labs/CorrelationCovariance/CorrCovariance.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/CorrelationCovariance/CorrCovariance.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 53.0204081633, "max_line_length": 174, "alphanum_fraction": 0.7250021384, "num_tokens": 6426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339909, "lm_q2_score": 0.8688267643505193, "lm_q1q2_score": 0.7419022509546247}}
{"text": "\\subsection{System}\n$$\n\\ddot{x}(t) = -x(t) - 0.1\\dot{x}(t) + u\n$$\n$$\n\\begin{bmatrix}\n\t\\dot{x}_1\\\\\n\t\\dot{x}_2\n\\end{bmatrix} = \\begin{bmatrix}\n\t-1 & 0\\\\\n\t0 & -0.1\n\\end{bmatrix}\\begin{bmatrix}\n\t{x}_1\\\\\n\t{x}_2\n\\end{bmatrix} +\\begin{bmatrix}\n\t0\\\\1\n\\end{bmatrix}u\n$$\n$$\nA = \\begin{bmatrix}\n\t-1 & 0\\\\\n\t0 & -0.1\n\\end{bmatrix}, \\quad B = \\begin{bmatrix}\n\t0\\\\1\n\\end{bmatrix}, \\qquad Q = \\begin{bmatrix}\n\t1 & 0\\\\\n\t0 & 1\n\\end{bmatrix}, \\qquad R = 1, \\qquad H = \\begin{bmatrix}\n\t1 & 0\\\\\n\t0 & 1\n\\end{bmatrix},\n$$\n\\subsection{part a}\nGradient tolerance is: $10^{-4}$\n\n\\subsubsection{figures}\n\\newpage\n\\begin{itemize}\n\t\\item Steepest Descent\n\t\\begin{itemize}\n\t\t\\item Quadratic Interpolation\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{Steepest Descent and Quadratic Interpolation}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q2/part a Steepest Descent + Quadratic Interpolation.png}\n\t\t\\end{figure}\n\t\t\\item Golden Section\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{Steepest Descent and Golden Section}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q2/part a Steepest Descent + Golden Section.png}\n\t\t\\end{figure}\n\t\\end{itemize}\n\t\\item BFGS\n\t\\begin{itemize}\n\t\t\\item Quadratic Interpolation\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{BFGS and Quadratic Interpolation}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q2/part a BFGS + Quadratic Interpolation.png}\n\t\t\\end{figure}\n\t\t\\item Golden Section\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{BFGS and Golden Section}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q2/part a BFGS + Golden Section.png}\n\t\t\\end{figure}\n\t\\end{itemize}\n\\end{itemize}\n\\subsubsection{result}\n\\begin{itemize}\n\t\\item Time\n\t\\begin{table}[h]\n\t\t\\caption {Time compare between four methods} \n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{ |c|c|c|c| }\n\t\t\t\t\\hline\n\t\t\t\t\\multicolumn{2}{|c|}{Steepest Descent} &\n\t\t\t\t\\multicolumn{2}{|c|}{BFGS} \\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\tQuadratic Interpolation & Golden Section & Quadratic Interpolation &\n\t\t\t\tGolden Section \\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\t$17.000\\sec$ & $24.353\\sec$ & $3.905\\sec$ & $4.985\\sec$\\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\t\\end{table}\n\t\\item Number of Cost calculation\n\t\\begin{table}[h]\n\t\t\\caption {Number of Cost calculation compare between four methods} \n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{ |c|c|c|c| }\n\t\t\t\t\\hline\n\t\t\t\t\\multicolumn{2}{|c|}{Steepest Descent} &\n\t\t\t\t\\multicolumn{2}{|c|}{BFGS} \\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\tQuadratic Interpolation & Golden Section & Quadratic Interpolation &\n\t\t\t\tGolden Section \\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\t$1285$ & $1922$ & $273$ & $373$\\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\t\\end{table}\n\t\\item Number of Gradient calculation\n\t\\begin{table}[h]\n\t\t\\caption {Number of Gradient calculation compare between four methods} \n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{ |c|c|c|c| }\n\t\t\t\t\\hline\n\t\t\t\t\\multicolumn{2}{|c|}{Steepest Descent} &\n\t\t\t\t\\multicolumn{2}{|c|}{BFGS} \\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\tQuadratic Interpolation & Golden Section & Quadratic Interpolation &\n\t\t\t\tGolden Section \\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\t$51$ & $51$ & $11$ & $11$\\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\t\\end{table}\n\\end{itemize}\n\\subsubsection{Four iteration for BFGS and Quadratic interpolation}\n\t\t\\begin{figure}[H]\n\t\\caption{BFGS and Quadratic Interpolation with four iteration}\n\t\\centering\n\t\\includegraphics[width=11.5cm]{../Figure/Q2/part a_2 BFGS + Quadratic Interpolation.png}\n\\end{figure}\n\t\\begin{table}[H]\n\t\\caption {four iteration and gradient tolerance compare} \n\t\\begin{center}\n\t\t\\begin{tabular}{ c|c|c|c| }\n\t\t\t\\cline{2 - 4}\n\t\t\t &Time & Number of Cost calculation & Number of Gradient calculation\\Tstrut\\\\\n\t\t\t \\hline\n\t\t\t \\multicolumn{1}{ |c|  } {Four iteration} & $3.905_{\\sec}$ & $273$ & $11$ \\Tstrut\\\\\n\t\t\t\\hline\n\t\t\t\\multicolumn{1}{ |c|  }{Gradient tolerance} & $1.586_{\\sec}$ & $100$ & $4$ \\Tstrut\\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\nBetween BFGS and Steepest Descent, BFGS if more faster but Steepest Descent is more easy to use. Quadratic interpolation can be faster when cost function use so much process but when we are so close to answer the function doesn't work well so we must increase gradient tolerance. ", "meta": {"hexsha": "eb5143abd14659ae3e73dd6fc7c26852e81a34a7", "size": 4108, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW3/Report/Q2/Q2_a.tex", "max_stars_repo_name": "alibaniasad1999/Optimal-Control", "max_stars_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-09T13:16:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-09T13:16:54.000Z", "max_issues_repo_path": "HW/HW3/Report/Q2/Q2_a.tex", "max_issues_repo_name": "alibaniasad1999/Optimal-Control", "max_issues_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW/HW3/Report/Q2/Q2_a.tex", "max_forks_repo_name": "alibaniasad1999/Optimal-Control", "max_forks_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.5277777778, "max_line_length": 280, "alphanum_fraction": 0.6682083739, "num_tokens": 1573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7418226058883721}}
{"text": "\\subsection{Image and Kernel}\n\nIf $T:\\;\\R^m\\rightarrow \\R^n$ then $\\mathrm{Im}(T)\\subset \\R^n$ and\n$\\mathrm{ker}(T)\\subset \\R^m$ because the associated matrix $A$ is $n\\times m$ in dimension.\\newline\n\n\\noindent\nBoth are closed under linear combinations:\n\\begin{itemize}\n    \\item If $\\tb y_1 ,\\tb y_2 \\in \\mathrm{Im}(T)$ then $a \\tb{y}_{1}+b \\tb{y}_{2} \\in \\mathrm{Im}(T)$ as well\n    \\item If $\\tb x_1 ,\\tb x_2 \\in \\mathrm{Ker}(T)$ then $a\\tb x_1 +b\\tb x_2 \\in \\mathrm{Ker}(T)$ as well\n\\end{itemize}\n\n\\subsection{Subspaces}\n\nCollection of vectors in $\\R^n$ is called a subspace in $\\R^n$ if collection is nonempty and closed under linear combinations.\nExamples (and counterexamples):\n\n\\begin{itemize}\n    \\item $W=\\left\\{\\left(\\begin{array}{c}\n        3 s \\\\\n        2+5 s\n        \\end{array}\\right) \\mid s \\in \\mathbb{R}\\right\\} \\subset \\mathbb{R}^{2}$\n        is not a subspace because $\\tb{0}$ is not contained within the set, so not closed under linear combinations\n    \\item $W=\\left\\{\\left(\\begin{array}{l}\n        x_{1} \\\\\n        x_{2} \\\\\n        x_{2}\n        \\end{array}\\right) \\mid 2 x_{1}+x_{2}-x_{3}=0\\right\\}$ is a subspace due to matrix representation and \n        the image of this matrix containing $\\tb{0}$ due to $T(\\tb{0}=\\tb{0})$\n\\end{itemize}\n\n\\noindent\n$\\R^2$ is not a subspace of $\\R^3$ because though a plane can be drawn in $\\R^3$, its components will be of the form\n$\\begin{bmatrix}x\\\\ y\\\\k\\end{bmatrix}$, where $k$ is fixed. Since $\\R^3$ vectors always have 3 coordinates, they can't represent $\\R^2$.\n$\\R^2$ can only be represented by $\\R^2$ vectors. Thus, $R^n$ is not a subspace of $\\R^{n+1}$.\\\\\n\n\\noindent\n\\textbf{\\textit{Claim:}} Span of a set of vectors in $\\R^n$ is a subspace of $\\R^n$.\\\\\n\\textbf{\\textit{Proof:}}\\\\\nLet $S=\\{\\tb v_1 ,\\tb v_2 ,\\cdots\\tb v_m \\}$. Let $\\tb w ,\\tb{y}\\in \\mathrm{span}(S)$.\nThus, $\\tb w =\\sum c_i\\tb v_i$ and $\\tb{y}=\\sum d_i\\tb v_i $ where $d_i,c_i\\in \\R$.\n\n\\begin{align*}\n    a\\tb w +b\\tb{y}&=a\\sum c_i\\tb v_i+b\\sum d_i\\tb v_i\\\\\n    &=\\sum a c_{i} \\tb v_{i}+\\sum b d_{i} \\tb v_i\\\\\n    &=\\sum (a c_i+b d_i) \\tb v_i \\in \\operatorname{span}(S)\n\\end{align*}\n\n\\noindent\nList of subspaces in $\\R^2$ would be $\\R^2$, $\\{t\\tb{v}\\mid t\\in\\R\\}$, $\\{\\tb{0}\\}$.\n\n\\subsection{Intersection and Union}\n\nIf $V$ and $W$ are collections of vectors in $\\R^n$:\n\\begin{itemize}\n    \\item $V \\cap W=\\{\\tb{x} \\mid \\tb{x} \\in V \\text { and } \\tb{x} \\in W\\}$ is the intersection\n    \\item $V \\cup W=\\{\\tb{x} \\mid \\tb{x} \\in V \\text { or } \\tb{x} \\in W\\}$ is the union\n\\end{itemize}\n\n\\subsection{Redundant Vectors}\n\nIf for some transformation $T$ there exists the following:\n\n\\[\\operatorname{im}(T)=\\operatorname{span}\\left\\{\\left(\\begin{array}{l}\n    1 \\\\\n    1 \\\\\n    1\n    \\end{array}\\right),\\left(\\begin{array}{l}\n    2 \\\\\n    2 \\\\\n    2\n    \\end{array}\\right),\\left(\\begin{array}{l}\n    1 \\\\\n    2 \\\\\n    3\n    \\end{array}\\right),\\left(\\begin{array}{l}\n    2 \\\\\n    3 \\\\\n    4\n    \\end{array}\\right)\\right\\}\\]\n\nThere are redundant vectors in this case. The minimum number of vectors in the span is 2, \nfor $\\tb{0}$ cannot be produced then. With 3 vectors in $\\R^3$, any one can be the result of linear combinations of the other 2.\nSo, it would be appropriate to say that:\n\n\\[\\operatorname{im}(T)=\\left\\{\\left(\\begin{array}{l}\n    1 \\\\\n    1 \\\\\n    1\n    \\end{array}\\right),\\left(\\begin{array}{l}\n    1 \\\\\n    2 \\\\\n    3\n    \\end{array}\\right)\\right\\}\\]\n\nThese are then \\textbf{linearly independent}. This set forms a \\textbf{basis} for that set of vectors.\nThus, the basis can be found for any matrix. The basis of $I_n$ is then $\\{\\tb{e}_1,\\tb{e}_2\\cdots \\tb{e}_n\\}$.\n\n\\subsection{Intersection and Union}\n\n\\begin{framed}\n    \\noindent If $V$ and $W$ are subspaces of $\\R^n$, then $V\\cap W$ \n    is a subspace of $\\R^n$ and $V\\cup W$ is \\textbf{not} a subspace of $\\R^n$.\n\\end{framed}\n\n\\noindent\nAn intersection is the items contained in both sets, so $\\tb{0}\\in V\\cap W$.\nIf $\\tb{v},\\tb{w}\\in V\\cap W$, then $\\tb{v},\\tb{w}\\in V$ and $\\tb{v},\\tb{w}\\in W$. This means that\n$\\tb{v}+\\tb{w}\\in V$ and $\\tb{v}+\\tb{w}\\in W$ so $\\tb{v}+\\tb{w}\\in V\\cap W$.\nSimilarly, if some $k\\tb{v}\\in V\\cap W$ where $k\\in \\R$ then $k\\tb{v}\\in V$ and $k\\tb{v}\\in V$. \nThus, $V\\cap W$ is a subspace of $\\R^n$.\\\\\n\n\\noindent\nThe union is the items contained in either set.\nIf $V=\\mathrm{span}(\\tb{e}_2)$ and $W=\\mathrm{span}(\\tb{e}_1)$, then let $\\tb{y}=\\begin{bmatrix}0\\\\ y\\end{bmatrix}\\in V$\nand $\\tb{x}=\\begin{bmatrix}x\\\\ 0\\end{bmatrix}\\in W$. Thus, $\\tb{y},\\tb{x}\\in V\\cup W$. However,\n$a\\tb{x}+b\\tb{y}\\notin V\\cup W$ where $a,b\\in \\R$.", "meta": {"hexsha": "fc8ae42afcc0856017a806368e8b0fbf8859a688", "size": 4562, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/12_subspaces.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "linear-algebra/tex/12_subspaces.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "linear-algebra/tex/12_subspaces.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9914529915, "max_line_length": 136, "alphanum_fraction": 0.6128890837, "num_tokens": 1745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.885631470799559, "lm_q1q2_score": 0.7418226000979335}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%\n% Expectation Integrals %\n%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Expectation Integrals}\n\n\\begin{proposition}{(Unknown)}{}\n\n    Let $A,B \\subseteq \\Omega$. Then the following equalities hold:\n\n        \\begin{itemize}\n            \\setlength{\\parskip}{0em}\n            \\item $\\Indicator{A^C} = 1 - \\Indicator{A}$,\n            \\item $\\Indicator{A \\cap B} = \\Indicator{A}\\Indicator{B}$.\n            \\item $\\Indicator{A \\cup B} = \\Indicator{A} + \\Indicator{B} - \\Indicator{A \\cap B}$.\n        \\end{itemize}\n\n\\end{proposition}\n\n\\begin{lemma}{3.3}{}\n\n    Let $X$ be a \\emph{non-negative} random variable. Then there exists a sequence of \\emph{non-negative, simple} random variables $X_n$ converging to $X$ for every $\\omega \\in \\Omega$.\n\n    \\Hint $h_n(x)=\\min\\{\\floor{2^nx}/2^n, n\\}$ is non-negative, simple and increasing, approaching $x$. Consider $X_n \\coloneqq h(X) \\to X$.\n\n\\end{lemma}\n\n\\begin{lemma}{}{Simple Function Integral Properties}\n\n    Let $f,g: \\Omega \\to \\overline{\\mathbb{R}}$ be a \\emph{non-negative}, simple functions and $a,b \\geq 0$. Then the following holds:\n\n    \\begin{itemize}\n        \\setlength{\\parskip}{0em}\n        \\item $\\int_{\\Omega} f \\, d\\mu \\geq 0$,\n        \\item $\\int_{\\Omega} (af + bg) \\, d\\mu = a\\int_{\\Omega} f + b\\int_{\\Omega}g \\, d\\mu$.\n    \\end{itemize}\n\n\\end{lemma}\n\n\\begin{corollary}{}{Positive Integral over Set}\n\n    Let $A \\subseteq \\Omega$ and $f: \\Omega \\to \\overline{\\mathbb{R}}$ a \\emph{non-negative} measurable function. Then $\\int_A f \\, d\\mu \\geq 0$.\n\n\\end{corollary}\n\n\\begin{lemma}{3.3}{General}\n\n    Let $f: \\Omega \\to \\overline{\\mathbb{R}}$ be a \\emph{non-negative}, measurable function. The there exists a sequence $f_n$ of \\emph{non-negative}, simple functions such that:\n\n    \\begin{align*}\n        \\lim_{n \\to \\infty} f_n = f\n    \\end{align*}\n\n    \\Hint Use $h_n$ from Lemma 3.3's hint.\n\n\\end{lemma}\n\n\\begin{exercise}{3.5}{}\n\n    Let $A \\in \\CalF$ s.t. $\\mu(A) = 0$. Then for \\emph{any} measurable function $f: \\Omega \\to \\overline{\\mathbb{R}}$:\n    \n        \\begin{align*}\n            \\int_A f \\,d\\mu = 0.\n        \\end{align*}\n\n\\end{exercise}\n\n\\begin{exercise}{3.6}{}\n\n    Let $f: \\Omega \\to \\mathbb{R}$ be a measurable function, then:\n\n        \\begin{enumerate}[(i)]\n            \\setlength{\\parskip}{0em}\n            \\item For any $c \\in \\mathbb{R}$ and $A \\in \\CalF$:\n\n                \\begin{align*}\n                    \\int_A cf \\, d\\mu = c \\int_A f \\, d\\mu,\n                \\end{align*}\n            \n            provided the integral exists.\n            \\item For any $A, B \\in \\CalF$, such that $A \\cap B = \\emptyset$:\n\n                \\begin{align*}\n                    \\int_{A \\cup B} f \\,d\\mu = \\int_{A} f \\,d\\mu + \\int_{B} f \\,d\\mu,\n                \\end{align*}\n\n            provided the left-hand or right-hand side is well-defined.\n        \\end{enumerate}\n\n\\end{exercise}\n\n\\begin{theorem}{3.8}{Monotone Convergence}\n\n    Let $(f_n)_{n=1}^{\\infty}$ be increasing sequence of non-negative, measurable functions $f_n: \\Omega \\to \\overline{\\mathbb{R}}$, converging to some $f$. Then:\n\n        \\begin{align*}\n            \\int_{\\Omega} \\lim_{n \\to \\infty} f_n \\,d\\mu = \\lim_{n \\to \\infty} \\int_{\\Omega} f_n \\,d\\mu\n        \\end{align*}\n\n\\end{theorem}\n\n\\begin{theorem}{3.14}{Lebesgue Integral as Riemann Integral}\n\n    Let $f: \\mathbb{R} \\to \\mathbb{R}$ be a Borel-function such that:\n\n        \\begin{enumerate}[(i)]\n            \\setlength{\\parskip}{0em}\n            \\item the Riemann integral $\\int_{-\\infty}^{\\infty} f(x) \\, dx$ exists and\n            \\item the Riemann integral $\\int_{-\\infty}^{\\infty} |f(x)| \\, dx < \\infty$, i.e. is finite,\n        \\end{enumerate}\n\n    then the Lebesgue integral $\\int_{\\mathbb{R}} f(x) \\lambda(dx)$ \\emph{exists} and\n\n        \\begin{align*}\n            \\int_{\\mathbb{R}} f(x) \\lambda(dx) = \\int_{-\\infty}^{\\infty} f(x) \\, dx,\n        \\end{align*}\n\n    i.e. the Lebesgue integral is equal to the Riemann integral.\n\n\\end{theorem}\n\n\\begin{exercise}{3.15}{}\n\n    Let $\\nu$ be a measure that is absolutely continuous with respect to measure $\\mu$ and density $g$, then $\\mu(g < 0) = 0$. Moreover, $\\nu$ is a probability measure $\\Leftrightarrow$ $g \\geq 0$ $\\mu$-a.e. and $\\int_{\\Omega} g \\, d\\mu = 1$.\n\n\\end{exercise}\n\n\\begin{proposition}{3.16}{}\n\n    Let $\\nu$ and $\\mu$ be measures on \\SigmaAlgebra\\ $\\CalF$ such that $\\nu$ is absolutely continuous with respect to $\\mu$ and density $g$. Then for every $\\CalF$-measurable function $f$ the following holds:\n\n        \\begin{align*}\n            \\int_{\\Omega} f \\, d\\nu = \\int_{\\Omega} fg \\, d\\mu,\n        \\end{align*}\n\n    whenever one of the integrals exists.\n\n\\end{proposition}\n\n\\begin{remark}{3.3}{}\n\n    Let $(\\Omega, \\mathcal{F}, \\mu)$ be measure space, $f: \\Omega \\to \\overline{\\mathbb{R}}$ \\emph{non-negative} $\\mathcal{F}$-measurable, then\n\n        \\begin{align*}\n            \\mu(f \\geq \\lambda) \\leq \\lambda^{-\\alpha} \\int_{\\Omega} f^{\\alpha} \\,d\\mu \\quad \\forall \\lambda > 0, \\alpha > 0.\n        \\end{align*}\n\n\\end{remark}\n\n\\begin{lemma}{3.10}{Fatou's Lemma}\n\n    Let $(f_n)_{n=1}^{\\infty}$ be a sequence of \\emph{non-negative}, measurable functions $f: \\Omega \\to \\overline{\\mathbb{R}}$, then\n\n        \\begin{align*}\n            \\int_{\\Omega} \\liminf_{n \\to \\infty} f_n \\, d\\mu \\leq \\liminf_{n \\to \\infty} \\int_{\\Omega} f_n \\, d\\mu.\n        \\end{align*}\n\n\\end{lemma}\n\n\\begin{corollary}{3.11}{Fatou's Lemma Extension}\n\n    Let $(f_n)_{n=1}^{\\infty}$ be a sequence of measurable functions $f: \\Omega \\to \\overline{\\mathbb{R}}$. Then\n\n        \\begin{enumerate}[(i)]\n            \\setlength{\\parskip}{0em}\n            \\item if there exists a $g \\in L_1(\\Omega, \\CalF, \\mu)$, i.e. $\\int_{\\Omega} |g| \\, d\\mu < \\infty$ such that $g \\leq f_n$ for all $n$, then:\n\n            \\begin{align*}\n                \\int_{\\Omega} \\liminf_{n \\to \\infty} f_n \\, d\\mu \\leq \\liminf_{n \\to \\infty} \\int_{\\Omega} f_n \\, d\\mu.\n            \\end{align*}\n            \\item if there exists a $g \\in L_1(\\Omega, \\CalF, \\mu)$, i.e. $\\int_{\\Omega} |g| \\, d\\mu < \\infty$ such that $g \\geq f_n$, then:\n\n            \\begin{align*}\n                \\int_{\\Omega} \\limsup_{n \\to \\infty} f_n \\, d\\mu \\geq \\limsup_{n \\to \\infty} \\int_{\\Omega} f_n \\, d\\mu.\n            \\end{align*}\n        \\end{enumerate}\n\n\\end{corollary}\n\n\\begin{theorem}{3.12}{Lebegue's Theorem on Dominated Convergence}\n\n    Let $(f_n)_{n=1}^{\\infty}$ be a sequence of Borel functions $f_n: \\Omega \\to \\overline{\\mathbb{R}}$ converging to some $f: \\Omega \\to \\overline{\\mathbb{R}}$. Assume there exists a (non-negative) Borel functions $g$ such that $|f_n| \\leq g$ for any $n \\geq 1$ and $\\int_{\\Omega} g \\, d\\mu < \\infty$. Then the following two statements hold:\n\n        \\begin{enumerate}[(i)]\n            \\setlength{\\parskip}{0em}\n            \\item\n                \\begin{align*}\n                    \\int_{\\Omega} |f| \\, d\\mu < \\infty,\n                \\end{align*}\n            \\item\n                \\begin{align*}\n                    \\int_{\\Omega} f \\, d\\mu = \\lim_{n \\to \\infty} \\int_{\\Omega} f \\, d\\mu.\n                \\end{align*}\n        \\end{enumerate}\n\n\\end{theorem}\n\n\\begin{proposition}{}{Restricted Expectation}\n\n    Let $X$ be a random variable and $A \\in \\CalF$, then:\n\n        \\begin{align*}\n            E(X \\Indicator{A}) = \\int_A X \\,dP.\n        \\end{align*}\n\n\\end{proposition}\n\n\\begin{theorem}{3.17}{Integration Over The Sample Space}\n\n    Let $f: \\mathbb{R} \\to \\mathbb{R}$ be a Borel function and $X$ a \\emph{finite} random variable, then:\n\n        \\begin{align*}\n            Ef(X) = \\int_{\\mathbb{R}} f Q_X(dx).\n        \\end{align*}\n\n\\end{theorem}\n\n\\begin{proposition}{3.18}{Markov-Chebyshev's Inequality}\n\n    Let $X$ be a \\emph{non-negative} R.V., then\n\n        \\begin{align*}\n            P(X \\geq \\lambda) \\leq \\lambda^{-\\alpha} E(X^{\\alpha}) \\quad \\forall \\lambda > 0, \\alpha > 0.\n        \\end{align*}\n\n    \\Hint $E(X^{\\alpha}) \\geq E(\\Indicator{X \\geq \\lambda} X^{\\alpha}) \\geq E(\\Indicator{X \\geq \\lambda} \\lambda^{\\alpha}) = \\lambda^{\\alpha} E(\\Indicator{X \\geq \\lambda}) = \\lambda^{\\alpha} P(X \\geq \\lambda)$.\n\n\\end{proposition}\n\n\\begin{proposition}{3.18}{Markov-Chebyshev's Inequality (General)}\n\n    Let $f: \\Omega \\to \\overline{\\mathbb{R}}$ be a \\emph{non-negative}, measurable function, then\n\n        \\begin{align*}\n            \\mu(f \\geq \\lambda) \\leq \\lambda^{-\\alpha} \\int_{\\Omega} f^{\\alpha} \\, d\\mu \\quad \\forall \\lambda > 0, \\alpha > 0.\n        \\end{align*}\n\n\\end{proposition}\n", "meta": {"hexsha": "8abf4dcf386bb4dba46ada85c24cfb7c48ed9883", "size": 8421, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/expectation-integrals.tex", "max_stars_repo_name": "smueksch/measure-theory-overview", "max_stars_repo_head_hexsha": "28d9c630ecac819b6aa1374e38caf218cf610b1c", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/expectation-integrals.tex", "max_issues_repo_name": "smueksch/measure-theory-overview", "max_issues_repo_head_hexsha": "28d9c630ecac819b6aa1374e38caf218cf610b1c", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/expectation-integrals.tex", "max_forks_repo_name": "smueksch/measure-theory-overview", "max_forks_repo_head_hexsha": "28d9c630ecac819b6aa1374e38caf218cf610b1c", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-02T15:34:51.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-02T15:34:51.000Z", "avg_line_length": 35.2343096234, "max_line_length": 342, "alphanum_fraction": 0.5695285596, "num_tokens": 2905, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7418225965080297}}
{"text": "\\newpage\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%        VECTOR ANALYSIS APPENDIX       %\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\chapter{Vector Analysis}\n\\index{Vector Analysis}\n\\label{app:vec-analysis}\nHere we review various techniques within vector calculus and analysis. \n\n% Vector Algebra\n\\section{Vector Algebra}\nVectors, by definition, are members of a vector space. It is therefore prudent to summarize the properties of vector fields. A vector space over a field $K$ is a set $V$ equipped with vector addition $+: V\\times V \\to V$ and scalar multiplication $*: K\\times V \\to V$, where $+$ is an additive group and $\\cdot$ is distributive over $+$ and the underlying field addition $+_K$. There are two additional structures of note. First, a bilinear form $(\\cdot,\\cdot): V\\times V\\to K$ that, when positive definite and nondegenerate, forms the familiar inner product $v\\cdot w \\to k\\in K$. Second, a bilinear operator $\\times : V\\times V \\to V$, called the \\textit{cross product}, which gives the vector space an algebra structure.\n\n\\subsection{Inner Product}\nThe vector inner product $\\cdot$ takes two vectors and produces a scalar. It can be used to measure the angle between two vectors.\n\\eqn{\\vec{A}\\cdot\\vec{B}=AB\\cos\\theta=A_x B_x + A_y B_y + A_z B_z}\nThe inner product is also used to compute magnitudes or the \\textit{norm} of a vector.\n\\eqn{\\norm{\\vec{A}}=\\sqrt{\\vec{A}\\cdot\\vec{A}}=\\sqrt{A_x^2 + A_y^2 + A_z^2}}\n\n\\subsection{Outer (Cross) Product}\nThe cross product takes two vectors and produces a vector whose direction corresponds to the right-hand rule.\n\\eqn{\\vec{A}\\times\\vec{B} = \n\t\\wrap{A_y B_z - A_z B_y}\\vec{\\hat{x}} \n\t+ \\wrap{A_z B_x - A_x B_z}\\vec{\\hat{y}}\n\t+ \\wrap{A_z B_x - A_x B_z}\\vec{\\hat{z}}}\n\\eqn{\\vec{A}\\times\\vec{B} = \n\t\\begin{vmatrix}\n\t\t\\hat{i} & \\hat{j} & \\hat{k}\\\\\n\t\tA_x & A_y & A_z \\\\\n\t\tB_x & B_y & B_z \n\t\\end{vmatrix}}\n\n\\subsection{Triple Product}\nThe scalar triple product represents the volume of the parallelepiped generated by $\\vec{A}$, $\\vec{B}$, and $\\vec{C}$.\n\\eqn{\\vec{A}\\cdot\\wrap{\\vec{B}\\times\\vec{C}} = \\begin{vmatrix}\n\tA_x & A_y & A_z \\\\\n\tB_x & B_y & B_z \\\\\n\tC_x & C_y & C_z \n\\end{vmatrix}}\nThe vector triple product can be simplified \n\\eqn{\\vec{A} \\times \\wrap{\\vec{B} \\times \\vec{C}} = \\vec{B}\\wrap{\\vec{A}\\cdot\\vec{C}} - \\vec{C}\\wrap{\\vec{A}\\cdot\\vec{B}}}\n\n% Differential Calculus\n\\section{Differential Calculus}\n\\subsection{Gradient}\nThe gradient of a function $f$, denoted $\\vec{\\del}f$, is a vector that represents the direction in which $f$ changes the greatest.\n\\eqn{\\vec{\\del} = \\pd{}{x}\\vec{\\hat{x}} + \\pd{}{y}\\vec{\\hat{y}} + \\pd{}{z}\\vec{\\hat{z}}}\n\n\\subsection{Divergence}\nThe divergence of a vector field measures how much the vector spreads out (or diverges) from the point in question.\n\\eqn{\\vec{\\del}\\cdot \\vec{v} = \\pd{v_x}{x} + \\pd{v_y}{y} + \\pd{v_z}{z}}\n\n\\subsection{Curl}\nThe curl of a vector field measures how much the vector swirls around the point in question.\n\\eqn{\\vec{\\del}\\times\\vec{v} = \\begin{vmatrix}\n\t\\hat{i} & \\hat{j} & \\hat{k} \\\\\n\t\\p/\\p x & \\p / \\p y & \\p/\\p z \\\\\n\tv_x & v_y & v_z\n\\end{vmatrix}}\n\n\\subsection{Second Derivatives}\nThe Laplacian $\\del^2$ represents a second-order change in a vector. There are also a few useful identities related to closed and exact differential forms.\n\\eqn{\\del^2\\vec{v} = \\pd[2]{v_x}{x} + \\pd[2]{v_y}{y} + \\pd[2]{v_z}{z}}\n\\eqn{\\vec{\\del} \\times \\wrap{\\vec{\\del}f}=0}\n\\eqn{\\vec{\\del}\\cdot\\wrap{\\vec{\\del}\\times \\vec{v}}=0}\n\n% Integral Calculus\n\\section{Integral Calculus}\n\\subsection{Fundamental Theorem of Calculus}\n\\eqn{\\int_a^b \\wrap{\\frac{df}{dx}}dx=f(b) - f(a)}\n\n\\subsection{Stokes-Cartan Theorem}\nThe Stokes-Cartan theorem related the integral of a form over a the boundary of a manifold to the integral of the exterior derivative of the form over the whole manifold. The Divergence theorem and Green's theorem are both instances of the more general stokes theorem.\n\\eqn{\\int_{\\p\\Omega}\\omega=\\int_\\Omega d\\omega}\n\\eqn{\\oint_{\\Gamma} \\vec{v} \\cdot d \\vec{\\Gamma} = \\iint_S\\vec{v}\\cdot d\\vec{S} \\where \\Gamma = \\p S}\n\\eqn{\\oiint_S \\vec{v}\\cdot d\\vec{S}  = \\iiint_V \\wrap{\\vec{\\del}\\cdot v} dV \\where S = \\p V}\n\n\\subsection{Integration by Parts}\nAnother useful identity is integration by parts, which can help solve integrals that produce iterative expressions, like integrals of the form $\\int x^p e^{-x} dx$.\n\\eqn{\\int_a^b f\\wrap{\\frac{dg}{dx}}dx = fg \\Big\\rvert_a^b - \\int_a^b g \\wrap{\\frac{df}{dx}}dx}\n\n% Curvilinear Coordinates\n\\section{Curvilinear Coordinates}\n\\subsection{Spherical Coordinates}\nWe adopt the mathematical convention for spherical coordinates $(r, \\theta, \\phi)$ whereby $\\theta$ is the \\textit{azimuthal} angle in the $x$-$y$ plane and $\\phi$ is the \\textit{polar} angle between the radial vector and the $z$-axis. This has the enormous advantage of sharing $\\theta$ with polar coordinates in the $x$-$y$ plane. This can be problematic because Griffiths uses the opposite convention \\cite{griffithsIntroductionElectrodynamics2018}.\n\\eqn{x = r\\sin\\phi\\cos\\theta \\quad\\quad y = r\\sin\\phi\\sin\\theta \\quad\\quad z = r \\cos\\phi}\n\\begin{align}\n\t\\vec{\\hat{r}} &= \\sin\\phi\\cos\\theta\\ \\vec{\\hat{x}} + \\sin\\phi\\sin\\theta\\ \\vec{\\hat{y}} + \\cos\\phi\\ \\vec{\\hat{z}} \\\\\n\t\\vec{\\hat{\\theta}} &= \\cos\\phi\\cos\\theta\\ \\vec{\\hat{x}} + \\cos\\phi\\sin\\theta\\ \\vec{\\hat{y}} - \\sin\\theta\\ \\vec{\\hat{z}} \\\\\n\t\\vec{\\hat{\\phi}} &= - \\sin\\theta\\ \\vec{\\hat{x}} + \\cos\\theta\\ \\vec{\\hat{y}}\n\\end{align}\nThe Gradient and Laplacian can also be written in spherical coordinates, which are often useful:\n\\eqn{\\del = \\pd{}{r}\\vec{\\hat{r}} + \\frac{1}{r \\sin \\phi}\\pd{}{\\theta} \\vec{\\hat{\\theta}} + \\frac{1}{r}\\pd{}{\\phi}\\vec{\\hat{\\phi}}}\n\\eqn{\\del^2 = \\frac{1}{r^2}\\pd{}{r}\\wrap{r^2 \\pd{}{r}} + \\frac{1}{r^2 \\sin^2\\phi}\\pd{{}^2}{\\theta^2} + \\frac{1}{r \\sin \\phi}\\pd{}{\\phi}\\wrap{\\sin\\phi \\pd{}{\\phi}}}\n\n% Dirac Delta\n\\section{Dirac Delta}\nThe \\textit{Dirac delta} is the first example of a \\textit{functional}, or \\textit{distribution}, encountered in a traditional physics undergraduate sequence, and is central to the entire theory of electrodynamics. A common example is given by the divergence of $\\vec{v} = \\frac{1}{r^2} \\vec{\\hat{r}}$. A naive computation yields $\\del \\cdot \\vec{v} = 0$, which seems counterintuitive. However, $\\vec{v}$ attains an infinite value at $0$, and any integral over a spherical region centered at $0$, we obtain a constant $4\\pi$. As we will see, this is a Dirac delta function.\n% One-Dimensional Dirac Delta\n\\subsection{One-Dimensional Dirac Delta}\nThe one-dimensional Dirac delta function is a function that is infinite at one point, and zero elsewhere, that is integrable to a constant value:\n\\eqn{\\delta(x) = \n\t\\begin{cases}\n\t\t0, & x \\neq 0 \\\\\n\t\t\\infty, & x = 0\n\t\\end{cases} \n\\quad\\quad \\text{such that}\\quad\\quad \\int_{-\\infty}^{\\infty}\\delta(x)\\ dx = 1}\nBy far the most important fact about the delta function, is that, when paired with a general function $f(x)$, the delta function \"selects\" the value of $f$ at $x=0$, such that $f(x)\\delta(x) = f(0)\\delta(x)$. This is useful for simplifying integrals. \n\\eqn{\\int_{-\\infty}^{\\infty}f(x)\\delta(x)dx = f(0)\\int_{-\\infty}^{\\infty}\\delta(x)dx = f(0) \\quad \\implies \\quad \\int_{-\\infty}^{\\infty}f(x)\\delta(x - a)dx = f(a)}\n% Three-Dimensional Dirac Delta\n\\subsection{Three-Dimensional Dirac Delta}\nWe can generalize the delta function to three-dimensional space: $\\delta^3(\\vec{r})=\\delta(x)\\delta(y)\\delta(z)$. Integrating this function over all space exhibits the same \"selection\" behavior as in the one-dimensional case:\n\\eqn{\\int_{\\infty^3}f(\\vec{r})\\delta^3(\\vec{r} - \\vec{a})dx^3 = f(\\vec{a})}\nWe can now restate the divergence of the function $f(\\vec{r})=\\frac{1}{r^2}\\vec{\\hat{r}}$ in terms of the delta function. \n\\eqn{\\boxed{\\vec{\\del} \\cdot \\wrap{\\frac{\\vec{\\hat{r}}}{r^2}} = 4\\pi \\delta^3(\\vec{r})}}\nThis can be used to simplify many integrals appearing in electrodynamics and other three-dimensional cases, such as spherical harmonics. For example:\n\\eqn{\\int_{\\mathcal{V}}\\wrap{r^2 + 2} \\vec{\\del}\\cdot\\wrap{\\frac{\\vec{\\hat{r}}}{r^2}} dV = \\int_{\\mathcal{V}}\\wrap{r^2 + 2} 4\\pi \\delta^3(\\vec{r}) dV = 4\\pi \\wrap{0 + 2} = 8\\pi}\n\n\n% Vector Fields\n\\newpage\n\\section{Vector Fields}\n\\label{app:vector-analysis:potentials}\n\\subsection{Potentials (Closed and Exact Forms)}\nGiven a differential form $a\\in \\Omega^p$, it is said to be \\textit{closed} if it's exterior derivative is zero, $da=0$, and is said to be \\textit{exact} if it is the exterior derivative of another form $b \\in \\Omega^{p-1}$, $a = db$. In the latter case, $b$ would be called the \\textit{potential function} of $a$. Since $d^2=0$, all exact forms are closed. Whether or not closed forms are exact depends on the topology, which is out of scope here. \n\nIn the case of a vector field $\\vec{F}$ on $\\RThree$, the property of having no curl $\\vec{\\del} \\times \\vec{F} = 0$ is equivalent to saying $\\vec{F}$ is closed. Consequently, there must exist a scalar potential $V$ such that $\\vec{F} = -\\del V$. To state it more formally:\n\\eqn{\\vec{\\del}\\times\\vec{F} = 0 \\implies \\vec{F} = -\\del V}\n\n\\subsection{The Helmholtz Theorem}\nThe Helmholtz Theorem states that a vector field $\\vec{F}$ is uniquely specified by its divergence $\\vec{\\del}\\cdot \\vec{F}$ and its curl $\\vec{\\del}\\times \\vec{F}$, assuming the boundary condition $\\lim_{r\\to \\infty} \\vec{F}(\\vec{r})=0$ is strong enough. If this is the case, then $F$ can be constructed from the divergence and curl:\n\\eqn{\\vec{F} = -\\del U + \\vec{\\del}\\times \\vec{W} \\quad\\quad \\text{where} \\quad\\quad\n\\begin{aligned}\n\tU(\\vec{r}) &= \\frac{1}{4\\pi}\\int \\frac{\\vec{\\del}\\cdot \\vec{F}}{\\norm{\\vec{r} - \\vec{r}'}} dr'^3 \\\\\n\t\\ & \\ \\\\\n\t\\vec{W}(\\vec{r}) &= \\frac{1}{4\\pi} \\int\\frac{\\vec{\\del}\\times \\vec{F}}{\\norm{\\vec{r} - \\vec{r}'}}dr'^3 \\\\\n\\end{aligned}}\n\n\n% Substitutions\n\\section{Substitutions}\n%Various integrals can be simplified via substitution techniques. This section details two such substitution methods, both of which have been useful in undergraduate physics.\n\\subsection{Trigonometric Substitution}\nSubstituting trigonometric functions for more complicated expressions can simplify an integral. The below cases highlight the most common trig substitutions:\n\\eqn{\\begin{array}{ccc}\n\t\\textbf{Case} & \\textbf{Integrand Contains} & \\textbf{Substitution} \\\\\n\t\\text{I}   & a^2 - x^2 & x = a\\sin\\theta \\\\\n\t\\text{II}  & a^2 + x^2 & x = a\\tan\\theta \\\\\n\t\\text{III} & x^2 - a^2 & x = a\\sec\\theta \\\\\n\\end{array}}\n\n\\subsection{Weierstrass Substitution}\nThe Weierstrass substitution transforms a function that depends on basic trigonometric functions of an angle into a function that depends on algebraic variables. Specifically, the substitution is:\n\\eqn{t = \\tan\\wrap{\\frac{\\theta}{2}} \\implies \\left\\{\n\\begin{aligned}\n\t\\sin(\\theta) &= \\frac{2t}{1 + t^2} \\\\\n\t\\cos(\\theta) &= \\frac{1 - t^2}{1 + t^2} \\\\\n\\end{aligned}\\right.}\n\\eqn{f\\wrap{\\sin \\theta, \\cos \\theta} \\to f\\wrap{\\frac{2t}{1 + t^2}, \\frac{1 - t^2}{1 + t^2}}}\n\n", "meta": {"hexsha": "a78c5c0db77987ef7af85104e6214ebeeebda573", "size": 10939, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/app-3-vec-analysis.tex", "max_stars_repo_name": "JWKennington/QualPrepNotes", "max_stars_repo_head_hexsha": "d080bc57a2bf1c243962e153f5baefd839974445", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sections/app-3-vec-analysis.tex", "max_issues_repo_name": "JWKennington/QualPrepNotes", "max_issues_repo_head_hexsha": "d080bc57a2bf1c243962e153f5baefd839974445", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/app-3-vec-analysis.tex", "max_forks_repo_name": "JWKennington/QualPrepNotes", "max_forks_repo_head_hexsha": "d080bc57a2bf1c243962e153f5baefd839974445", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.9440993789, "max_line_length": 723, "alphanum_fraction": 0.6850717616, "num_tokens": 3611, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355092, "lm_q2_score": 0.8175744806385542, "lm_q1q2_score": 0.741795309959647}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{booktabs}\n\\usepackage{xfrac}\n\\usepackage{todonotes}\n\n\\title{Neural Network Implementation Draft}\n\\date{October 2019}\n\n\\begin{document}\n\\maketitle\n\n\\section{Matrix Calculus}\n\n\\begin{table}\n    \\centering\n    \\begin{tabular}{cc}\n        \\toprule\n            $y$ & $\\frac{\\partial}{\\partial x} y$ \\\\\n        \\midrule\n            $Ax$     & $A^T$ \\\\\n            $x^T A$  & $A$   \\\\\n            $x^T x$  & $2x$  \\\\  \n            $x^T Ax$ & $Ax + A^Tx$  \\\\          \n        \\bottomrule\n    \\end{tabular}\n    \\caption{Useful derivatives equations}\n\\end{table}\n\n\\subsection{Chain Rule for Matrix Calculus}\n\nThe chain rule for a vectors is similar to the chain rule for scalars. Except the order is important. For $\\mathbf{z} = f(\\mathbf{y})$ and $\\mathbf{y} = g(\\mathbf{x}) $ the chain rule is:\n\\begin{equation}\n    \\frac{\\partial \\mathbf{z}}{\\partial \\mathbf{x}} = \\frac{\\partial \\mathbf{y}}{\\partial \\mathbf{x}}     \\frac{\\partial \\mathbf{z}}{\\partial \\mathbf{y}}\n\\end{equation}\n\n\\section{Example: 3 Layer Fully Connected Neural Network}\n\nFor the input $x$ the neural network which is described by its weights $W$, its biases $b$ and the activation functions $g(t)$. The network has $L_1$ neurons in the first layer, $L_2$ neurons in the second layer and $L_3$ neurons in the final layer.\n\n\\begin{table}\n    \\centering\n    \\begin{tabular}{lcc}\n        \\toprule\n            Layer & Weights & Bias \\\\\n        \\midrule\n            1     & [L1 nx] & [L1 1] \\\\\n            2     & [L2 L1] & [L2 1] \\\\\n            3     & [ny L2] & [ny 1] \\\\\n        \\bottomrule\n    \\end{tabular}\n    \\caption{Dimensions of the weight and bias matrices}\n\\end{table}\n\n\\begin{align*}\n    z_1 &= W_1 x + b_1 \\\\\n    a_1 &= f(z_1)      \\\\\n    z_2 &= W_2 a_1 + b_2 \\\\\n    a_2 &= f(z_2)      \\\\\n    z_3 &= W_3 a_2 + b_3 \\\\\n    h   &= z_3         \\\\\n\\end{align*}\n\n\\begin{equation}\n    J = \\frac{1}{N} \\sum_i^N (h(x_i;W,b)-y_i)^2\n\\end{equation}\n\n\\subsection{Backpropagation}\n\nThe update rule for gradient descent is\n\\begin{equation}\n    p_{i+1} = p_i + \\mu \\frac{\\partial J}{\\partial p_i}  \\quad \\forall p \\in \\{ W, b \\} \n\\end{equation}\n\nThe main difficulty here is to calculate the gradient for each parameter in the network, which can easily be several thousands or even million parameters. Here back-propagation is used to efficiently calculate those derivatives. The first step is to differentiate the cost function with respect to an parameter $p$ which can describe an weight or a bias\n\n\\begin{equation}\n    \\frac{\\partial J}{\\partial p_i}  = \\frac{2}{N} \\sum_i^N (h(x_i;W,b)-y_i) \\frac{\\partial h}{\\partial p_i} \n\\end{equation}\n\nThe total list of needed derivatives are: \\todo{The order is not correct yet}\n\n\\begin{align*}\n    \\frac{\\partial h}{\\partial W_3} &=  \\frac{\\partial h}{\\partial z_3} \\frac{\\partial z_3}{\\partial W_3} = a_2 \\\\ \n    \\frac{\\partial h}{\\partial W_2} &= \\frac{\\partial h}{\\partial a_2}     \\frac{\\partial a_2}{\\partial z_2}     \\frac{\\partial z_2}{\\partial W_2} = W_3^T f'(z_2) a_2 \\\\\n    \\frac{\\partial h}{\\partial W_1} &= \\frac{\\partial h}{\\partial a_2} \\frac{\\partial a_2}{\\partial z_2} \\frac{\\partial z_2}{\\partial a_1} \\frac{\\partial a_1}{\\partial z_1} \\frac{\\partial z_1}{\\partial W_1} = W_2^T W_3^T f'(z_2) f'(z_1)   x  \\\\\n    %\n    \\frac{\\partial h}{\\partial b_3} &=  \\frac{\\partial h}{\\partial z_3} \\frac{\\partial z_3}{\\partial b_3}  = 1 \\\\ \n    \\frac{\\partial h}{\\partial b_2} &= \\frac{\\partial h}{\\partial a_2}     \\frac{\\partial a_2}{\\partial z_2}     \\frac{\\partial z_2}{\\partial b_2} = W_3 f'(z_2)   \\\\\n    \\frac{\\partial h}{\\partial b_1} &= \\frac{\\partial h}{\\partial a_2} \\frac{\\partial a_2}{\\partial z_2} \\frac{\\partial z_2}{\\partial a_1} \\frac{\\partial a_1}{\\partial z_1} \\frac{\\partial a_1}{\\partial b_1} =  W_2^T W_3^T  f'(z_2) f'(z_1)  \\\\\n\\end{align*}\n\nNote: Here the equations are used as scalars. Because those are vectors all equations need to be transposed.\n\n\nCalculations of the delta terms is as follows\n\\begin{equation}\n    \\delta^{(4)} = h - y \n\\end{equation}\nthen the next delta value is computed using the update equation\n\\begin{equation}\n    \\delta^{(l-1)} = W_i^T \\delta^{(l)} .* f'(z) \n\\end{equation}\nand then the total update term is calculated:\n\\begin{equation}\n    \\Delta^{(l)} = \\delta^{(l)} a^{(l)}    \n\\end{equation}\n\nIt can be seen that the same derivatives are used more often\n\n\\begin{table}\n    \\centering\n    \\begin{tabular}{lc}\n        \\toprule\n            Derivative & Result  \\\\\n        \\midrule\n            $\\sfrac{\\partial z_1}{\\partial W_1}$     & $ x $ \\\\\n            $\\sfrac{\\partial z_1}{\\partial b_1}$     & $ 1 $ \\\\\n            $\\sfrac{\\partial a_1}{\\partial z_1}$     & $ f'(z_1) $ \\\\\n        \\midrule\n            $\\sfrac{\\partial z_2}{\\partial a_1}$     & $ W_2 $ \\\\\n            $\\sfrac{\\partial z_2}{\\partial W_2}$     & $ a_1 $ \\\\\n            $\\sfrac{\\partial z_2}{\\partial b_2}$     & $ 1 $ \\\\\n            $\\sfrac{\\partial a_2}{\\partial z_2}$     & $ f'(z_2) $ \\\\\n        \\midrule\n            $\\sfrac{\\partial z_3}{\\partial a_2}$     & $ W_3 $ \\\\\n            $\\sfrac{\\partial z_3}{\\partial W_3}$     & $ a_2 $ \\\\\n            $\\sfrac{\\partial z_3}{\\partial b_3}$     & $ 1 $ \\\\\n        \\bottomrule\n    \\end{tabular}\n    \\caption{Calculations of all derivatives of the network}\n\\end{table}\n\nHere something to note here: $f'(z_i)$ is the derivative of the activation function with respect to $z_i$. As an example, the equation of the ReLU activation function is:\n\\begin{equation}\n    f(t) = \\begin{cases}\n        t   \\quad \\text{if} \\quad t > 0 \\\\\n        0   \\quad \\text{else}\n    \\end{cases}\n\\end{equation}\nThe derivative $f'(t)$ is\n\\begin{equation}\n    f'(t) = \\begin{cases}\n        1   \\quad \\text{if} \\quad t > 0 \\\\\n        0   \\quad \\text{else}\n    \\end{cases}\n\\end{equation}\n\n\n\\section{Example: Convolutional Neural Network}\n\nThe two dimensional convolution is defined as:\n\n\\begin{equation}\n   z(i,j) = (f*g)(i,j) = \\sum_{m=-\\infty}^{\\infty} \\sum_{n=-\\infty}^{\\infty} f(m,n) g(m-i,n-j)\n\\end{equation}\n\nCompared to the previous example the input data is now not one dimensional but two-dimensional.\n\nAlso because the problem tackled here is a classification one, the loss function used is the cross-entropy function:\n\\begin{equation}\n    J = - y .* \\log(h) + (1-y) .* \\log(1-h)\n\\end{equation}\nwhere $.*$ is used as the element-wise multiplication. This can be interpreted as:\n\\begin{equation}\n    J = \\begin{cases}\n        - y_i * \\log(h_i)       \\quad &\\text{if} \\quad y_i = 1 \\\\\n        (1 - y_i) * \\log(h_i)   \\quad &\\text{if} \\quad y_i = 0\n    \\end{cases}\n\\end{equation}\n    \nBecause each image is exclusively in one class, the vector \n\\begin{equation}\ny = \\begin{bmatrix}\n    y_1 & y_2 & \\cdots & y_n\n\\end{bmatrix}^T\n\\end{equation}\nconsists of all zeros except for a single $1$.\n\n \n\n\\end{document}\n", "meta": {"hexsha": "bcc7a9e4b5382bda35d983adc0629d2c2dd59943", "size": 6824, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/nn/NNMath.tex", "max_stars_repo_name": "marbleton/FPGA_MNIST", "max_stars_repo_head_hexsha": "4b4a30e0adca35de9adcad7b3fec08c516260790", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-11-13T12:24:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-31T02:39:35.000Z", "max_issues_repo_path": "tex/nn/NNMath.tex", "max_issues_repo_name": "marbleton/FPGA_MNIST", "max_issues_repo_head_hexsha": "4b4a30e0adca35de9adcad7b3fec08c516260790", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2019-12-17T22:06:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T00:20:45.000Z", "max_forks_repo_path": "tex/nn/NNMath.tex", "max_forks_repo_name": "marbleton/FPGA_MNIST", "max_forks_repo_head_hexsha": "4b4a30e0adca35de9adcad7b3fec08c516260790", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-10-20T15:12:52.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-13T13:36:37.000Z", "avg_line_length": 37.0869565217, "max_line_length": 353, "alphanum_fraction": 0.608880422, "num_tokens": 2325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7417953059919428}}
{"text": "\\section{Algebraic Geometry}\r\n\\subsection{Basics}\r\n{\\bf Theorem:}\r\nEvery conic in the affine space over $R$ is equivalent under an affine transformation to\r\none of the following:\r\n(1) $X^2 + Y^2 + P = 0$ (ellipse, point, empty set),\r\n(2) $X^2 - Y^2 + P = 0$ (hyperbola, intersecting lines),\r\n(3) $X^2 + Y + P = 0$ (parabola),\r\n(4) $X^2 + P = 0$ (parallel lines, point empty).  In projective space (1), (2), (3) are\r\nequivalent. In the projective space over ${\\mathbb C}$, they are all projectively equivalent.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\nLet $R=k[x_1, \\ldots, x_n]$, $W= k^n= {\\mathbb A}^n$ for the \\emph{affine} setup and\r\n$R=k[x_0, x_1, \\ldots, x_n]$ (where $f \\in R$ is a \\emph{homogeneous} polynomial),\r\n$W= k^{n+1} \\setminus \\{ {\\vec 0}\\}= {\\mathbb P}^n$ under the usual equivalence \r\nfor the \\emph{projective} setup.\r\nIf $S \\subseteq R$, $V(S)= \\{ x \\in W: f(x)=0, \\forall f \\in S \\}$.  $V(S)$ is an\r\n\\emph{affine} (resp \\emph{projective}) \\emph{algebraic set}.  An algebraic set\r\nis \\emph{irreducible} if is cannot be expressed as the union of two non-trivial\r\nalgebraic sets.  An affine irreducible algebraic set is an \\emph{algebraic variety}.\r\nIf $S= \\{f\\}$, $V(S)$ is called a \\emph{hypersurface}.\r\nIf $V \\subseteq W$, $I(V)= \\{ f \\in R: f(x)=0, \\forall x \\in V \\}$.\r\nIf $\\langle S \\rangle= I$ as an ideal in R, $V(S)=V(I)$.\r\n$rad(I)={\\sqrt I}= \\{a: a^n \\in I\\}$.  $I$ is a \\emph{radical} ideal if $I={\\sqrt I}$.\r\nRoughly, radical ideals $\\leftrightarrow$ varieties,\r\nprime ideals $\\leftrightarrow$ subvarieties,\r\nmaximal ideals $\\leftrightarrow$ points.  \r\nIf $V$ is an algebraic variety, $I(V)$ is a prime ideal (proof below)\r\nand $\\Gamma[V]= R/I(V)$ is\r\ncalled a \\emph{coordinate ring}.\r\n${\\overline R}= k(x_1, \\ldots, x_n)$ is the quotient field of $R$; members of ${\\overline R}$\r\ninduce \\emph{rational} maps.\r\n${\\mathcal O}_P(V)$ denotes the rational functions on $V$ defined on $P$.\r\nThe \\emph{Zariski} topology on $W$ is defined by identifying the $V(S)$ with\r\n\\emph{closed sets}.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nLet $k$ be algebraically closed. \r\nThere is a one to one correspondence between polynomial maps $\\varphi: V \\rightarrow W$\r\nand the homomorphisms ${\\tilde {\\varphi}}: \\Gamma[W] \\rightarrow \\Gamma[V]$.\r\nLet ${\\mathcal T}(V,k)= \\{f: f:V \\rightarrow W \\}$.  If $\\varphi: V \\rightarrow W$,\r\n$\\tilde {\\varphi}: {\\mathcal T}(W,k) \\rightarrow {\\mathcal T}(V,k)$.  \r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:}\r\n$k \\subseteq \\Gamma[V)] \\subseteq {\\mathcal O}_P(V) \\subseteq k(V)$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Definitions:}\r\nTwo affine varieties\r\n$V, W$ are \\emph{isomorphic} if $\\exists \\phi, \\psi: \r\n\\phi \\circ \\psi= id_W$. Suppose $F_i$ is a collection of functions. \r\nThe \\emph{multiplicity of a root} at a point ${\\vec a}$ is\r\n$f(t)= gcd(F_{1}({\\vec a} + L(t)), \\ldots , F_{m}({\\vec a} + L(t)))$ where $L(t)$ is a line\r\nthrough $O={\\vec 0}$.\r\nBy transferring $P$ to ${\\vec 0}$ and express $F= F_m + \\ldots + F_n$, $F_m$ is\r\na form of degree $m$.\r\n$L$ touches $X$ at $O$ if its\r\nintersection multiplicity is greater than 1.\r\nLocus of points touching $X$ at $x$ is the \\emph{tangent space}, $\\Theta_{x,X}$.\r\nTwo varieties $V, W$ are \\emph{birationally equivalent} if there are \\emph{rational} maps\r\n$\\varphi_1: V \\rightarrow W$ and $\\varphi_2: W \\rightarrow V$ between them.\r\n$f(x,y)$ is \\emph{rational} if $\\exists \\phi, \\psi$: $f(\\phi(t), \\psi(t))=0$.\r\nAny conic (2nd order equation) in two variables has either infinitely many\r\nrational solutions or none.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nTwo curves are birationally equivalent iff their fields of functions are isomorphic.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nEvery irreducible curve of degree 2 is rational.\r\n$x^{n}+y^{n}=1$ is not rational for $n>2$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Definition:} Suppose $\\phi: A^n(k) \\rightarrow A^m(k)$, $f \\in k[y_1, \\ldots, y_m]$; \r\nthe \\emph{pullback} is $\\phi^*: \\phi^* \\circ f= f \\circ \\phi$.\r\nA \\emph{discrete valuation ring (``DVR'')} is a Noetherian,\r\nlocal domain whose maximal ideal is principal.\r\nIf a form, F, does not vanish on an irreducible projective variety\r\nX then $dim(X_{F})= dim(X)-1$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nThe following are equivalent: (1) The set of non-units in $R$\r\nform an ideal; (2) $R$ has a unique maximal ideal.  \r\nThe following are equivalent and define a DVR: \r\n(1) $R$ is Noetherian and its maximal ideal is principal; (2) \r\n$\\exists t \\in R:\r\n\\forall  0 \\ne z \\in R: z=ut^n$, where $u$ is a unit.  \r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe show $1 \\rightarrow 2$.  First uniqueness.  If $ut^m=vt^n$ for units $u,v$,\r\n$ut^{m-n}=v$ but then $t^{m-n}$ is a unit.  For existance, since ${\\mathfrak m}= (t)$,\r\nfor a non-unit, $z \\in {\\mathfrak m}$, \r\n$z= z_1t$ and if $z_i$ is a non-unit, $z_{i+1}= z_i t$ so\r\n$(z_1) \\subset (z_2) \\subset \\ldots$ and since $R$ is Noetherian eventually\r\n$(z_n)=(z_{n+1})$.  $z_{n+1}= vz_{n}, v \\in R$ $z_n= t vz_n$ so $vt=1$ but $t$ is not a unit.\r\n\\end{quote}\r\n{\\bf Theorem:} The pole set is an algebraic variety.  \r\n$\\Gamma[V]= \\bigcap_{P \\in V} {\\mathcal O}_P(V)$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $S_1 \\subseteq S_2$ then $I(S_1) \\supseteq I(S_2)$.  Every algebraic set\r\nis the intersection of hypersurfaces.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nBy the Hilbert basis theorem, $I(V)= (f_1, f_2, \\ldots, f_r)$ and so\r\n$V= V(f_1) \\cup \\ldots \\cup V(f_r)$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nEvery closed set is the union of finitely many irreducible ones.\r\nEvery irreducible closed set is birationally isomorphic to a hypersurface in $A^{n}$.  \r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:}\r\n(1) An algebraic set, $V$, is irreducible iff $I(V)$ is prime.\r\n(2) If $k$ is algebraically closed, $I(V(f))= (f)$.\r\n(3) If $I$ is radical, $I(V(I))= I$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n(3) follows from Nullstellensatz.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nLet $R=k[x,y]$. If $f, g \\in R$ have no common factor, $V(f) \\cap V(g)$ is finite.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$k(x)[y]$ is a PID, $Af+Bg=1$ over $k(x)$; now clear denominators.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $I$ is prime, $V(I)$ is irreducible.  There is a $1-1$ correspondence between\r\nprime ideals and irreducible algebraic sets; there is a $1-1$ correspondence between\r\nmaximal ideals and points.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nLet $V$ be an algebraic set then $V= V_1 \\cup \\ldots V_r$, $V_i$, irreducible,\r\n$V_i \\nsubseteq V_j, i \\ne j$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe use the following (follows from axiom of choice).  Let \r\n${\\mathcal S}$ be a non-empty collection of ideals in a Noetherian ring, $R$,\r\nthen \r\n${\\mathcal S}$ has a maximal element.  From this we conclude and collection of\r\nalgebraic sets has a minimal element. \\\\\r\nNow let\r\n${\\mathcal S}= \\{ V:\r\n\\textnormal{algebraic, } V\r\n\\textnormal{ is not a finite union} \r\n\\textnormal{ of irreducible}\r\n\\textnormal{ algebraic sets} \\}$ .\r\nLet $V$ be a minimal element of\r\n${\\mathcal S}$.  $V= V_1 \\cup V_2$ and this is a contradiction.  For the second condition,\r\nthrow out the $V_i$ violating it.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\n${\\mathcal O}_P(V)$ is a Noetherian local domain.  Further, the maximal ideal\r\n${\\mathfrak M}_P(V)$ is generated elements of $f \\in \\Gamma[V]$ for which $f(P)= 0$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nSTS $I \\subseteq\r\n{\\mathcal O}(V)$ is finitely generated.\r\nSince $\\Gamma[V]$ is Noetherian, $(f_1, \\ldots, f_r)= I \\cap \\Gamma[V]$.  Claim\r\n$(f_1, \\ldots, f_r)= I$ and an\r\n${\\mathcal O}(V)$ ideal, for if $f \\in I$, $\\exists b \\in \\Gamma[V]: b \\ne 0$ and\r\n$bf \\in \\Gamma[V]$ so $bf= \\Gamma[V] \\cap I$, $bf= \\sum_i a_i f_i, a_i \\in \\Gamma[V]$ and\r\n$f= \\sum_i {\\frac {a_i} {b_i}} f_i$.\r\n\\end{quote}\r\n{\\bf Definition:}\r\n$I(P, F \\cap G)= dim_k({\\mathcal O}_P({\\mathbb A}^2)/(F, G)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\n$|V(I)| < \\infty$ iff $R/I$ is finite dimensional over $k$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIf $P_1, \\ldots, P_r \\in V$, we can fine $f_i \\in R: f_i(p_j)= \\delta_{ij}$ so\r\n$r \\le dim_k(R/I)$.\r\nOn the other hand,\r\nif $V(I)= \\{ P_1 , P_2 , \\ldots , P_r \\}, P_i= (a_{i1}, a_{i2}, \\ldots, a_{in})$,\r\ndefine $f_j= \\prod_i (x_i - a_{ij}), F_j \\in I(V(I))$ so $F_j^N \\in I, {\\overline F}_j= 0$\r\nand ${\\overline X}_j^{rN}$ is a $k$-linear combination of\r\n$ {\\overline 1}, {\\overline x}_j^{1}, \\ldots, {\\overline x}_j^{rN-1} $ and\r\n$ {\\overline x}_1^{m_1}, \\ldots, {\\overline x}_n^{m_n}; m_i < rN $ is a set of generators.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nLet $I$ be an ideal of $R$ ($k$, algebraically closed), $V(I)= \\{P_1 , \\ldots , P_N\r\n\\}$ and $\r\n{\\mathcal O}_i= {\\mathcal O}_{P_i}({\\mathbb A}^n) $,\r\n$\\exists \\varphi: R/I \\rightarrow \\prod_i \r\n{\\mathcal O}_i/(I{\\mathcal O}_i)$ induced\r\nfrom the natural homomorphisms $\\varphi_i: R \\rightarrow {\\mathcal O}_i/(I{\\mathcal O}_i)$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} $P$ is a simple point of $f$ iff ${\\mathcal O}_P(V(f))$ is a DVR.\r\nIf $L$ is a non-tangent line $l + {\\mathcal O}_P(V)$ is a uniformizing parameter.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWLOG, $P=(0,0), L= ax$ and $y=0$ is the tangent.\r\n${\\mathfrak M}_P(V(f))= (x,y)$ whether $P$ is simple or not.\r\nSuppose $f= y(1+g(x,y)) - x^2 h(x)$ and $yg= x^2h \\in \\Gamma(f)$ so\r\n$y= x^2 h g^{-1}$ since $g(P) \\ne 0$ and \r\n${\\mathfrak M}_P(V(f))= (x)$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nSuppose ${\\mathfrak M}= {\\mathfrak M}_P(F)$ denotes the maximal ideal of \r\n${\\mathcal O}= {\\mathcal O}_P(F)$.\r\n$ 0 \\rightarrow {\\mathfrak M}^n/{\\mathfrak M}^{n+1}\r\n\\rightarrow {\\mathcal O}/{\\mathfrak M}^{n+1}\r\n\\rightarrow {\\mathcal O}/{\\mathfrak M}^{n} \\rightarrow 0$.\r\n$\\chi(n)= dim({\\mathcal O}/{\\mathfrak M}^n)=$ Hilbert polynomial.  \r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  Let $P$ be a point on an irreducible curve, $f$, for all sufficiently\r\nlarge $n$, $m_P(f)= dim_k({\\mathfrak M}_P(f)^n/{\\mathfrak M}_P(f)^{n+1})$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Divisors:}\r\nSuppose $E: y^2= x^3-x$ and $f(x,y)= {\\frac x y}$.  On $E: {\\frac x y}= {\\frac y {x^2-1}}$.\r\nIf $u_P$ is a \\emph{uniformizer}, $f= u_P^r g, r \\in {\\mathbb Z}, g(P) \\ne 0, \\infty$ and\r\nwe define $ord_P(f)=r$.  In this example, $u_{(0,0)}= y$ is a uniformizer at $(0,0)$ of\r\n$E: y^2= x^3-x$.  Since $x= y^2({\\frac 1 {x^2-1}})= y {\\frac y {x^2-1}}= {\\frac x y}y=x$,\r\n$ord_{(0,0)}(x)= 2$.  In general, for $P=(x_0, y_0) \\in E$, $u_P$ can be taken as any line\r\nthrough $P$ not tangent to $E$, thus we can take $u_P= x-x_0$ when $y_0 \\ne 0$ and\r\n$u_p= y$ when $y_0=0$.  For example, if $E: y^2= x^3 + 72$ then $(-2, 8) \\in E$.\r\nSince $f(x,y)= x+y-6$ vanishes at $(-2,8)$ and\r\n$f(x,y)= (x+2) + (y-6) = (x+2)( 1 + {\\frac {(x+2)^2 - 6(x+2) + 12)} {y-8}})$,\r\n$ord_P(f)=1$, $u_{\\infty}= {\\frac x y}$.\r\n\\\\\r\n\\\\\r\n{\\bf Weak Bezout:} If two curves of dimension $m$ and $n$ meet at more than $mn$\r\npoints (counting multiplicity) then they have a common component.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nStrategy of Proof: (S-1) $\\#(C_1 \\cap C_2 \\cap {\\cal A}^2) \\le\r\ndim({\\frac R {(f_1 , f_2)}}) \\le n_1 n_2$, (S-2) first inequality is an equality,\r\n(S-3) first inequality can be strengthened to\r\n$I(C_1 \\cap C_2,P) \\le dim({\\frac R {(f_1 , f_2)}})$, \r\n(S-4) inequality in 4 is an equality,\r\n(S-5) $I$ is invariant under projective transformations --- transform so the line at\r\ninfinity does not intersect $C_1 \\cap C_2$.\r\nNotation: Let $f_1 (x, y)$, and $f_2 (x, y)$, defining curves\r\n$C_1$ and $C_2$, have dimension $m, n$ respectively.\r\n$R= k[x, y]$, $(f_1 (x, y), f_2 (x, y))= R f_1 + R f_2$.\r\n\\\\\r\n\\\\\r\n\\emph{S-1:}\r\n$C_1 \\cap C_2 \\leq dim_k ({\\frac {R} {(f_1 , f_2 )}}) \\leq mn$. [Argument:\r\nIf $P_1, P_2, \\ldots P_r$ are distinct, $\\exists h_i (x,y)$ with\r\n$h_i (P_j ) = \\delta_{ij}$, so if there are $r$ common roots of $f_1$ and\r\n$f_2$,\r\n$\\sum_{i=1}^r c_i h_i (x,y) = r_1 f_1 (x,y) + r_2 f_2 (x,y)$ implies $c_i=\r\n0$.] \\\\\r\nLet $R_d$ be polynomials of degree $\\leq d$ then\r\n$dim_k (R_d )= \\phi (d) = {\\frac {(d+1)(d+2)} {2}}$.\r\nLet $W_d = R_{d-m }f_1 + R_{d-n}f_2$, for $d \\geq (m+n)$.\r\n$R_{d-m}f_1 \\cap R_{d-n} f_2 = R_{d-m-n} f_1 f_2$.\r\n$dim_k ( R_d ) - dim_k (W_d )= mn$.\r\n$g= \\sum_i^l c_j g_j$ has a non-trivial dependency for $l>mn$ with\r\n$g \\in W_d$.\r\n\\\\\r\n\\emph{S-2:}\r\nSecond inequality is equality if $C_1 \\cap C_2$ don't meet at infinity. \r\nLet $f^*$ be the homogeneous polynomial consisting of the highest degree terms\r\nin $f$.  If $\\infty \\notin C_1 \\cap C_2$ then $f_1^*$, $f_2^*$ have no common factor.\r\nIf $f_1^*$ and $f_2^*$ have no common factor then $(f_1 , f_2) \\cap R_d= W_d$.\r\nUnder the conclusion of the previous sentence, if $d \\ge n_1 + n_2$ then\r\n$dim({\\frac R {(f_1 , f_2)}}) \\ge n_1 n_2$ which proves the result.\r\n\\\\\r\nDefine ${\\mathcal O}_P= \\{ F \\in K(x, y): F(P)$ exists $\\}$, \r\n${\\mathfrak M}_P= \\{ f \\in {\\mathcal O}_P: f(P)= 0 \\}$.\r\n${\\mathfrak M}_P$ is a unique maximal ideal of $O_P$.  $(f_1, f_2)_P= f_1 O_P + f_2 O_P$.\r\nNow define $I(C_1 \\cap C_2; P)= dim( {\\frac {{\\mathcal O}_P} {(f_1 , f_2)_P}})$.\r\n\\\\\r\n\\emph{S-3:} \r\n${\\frac {{\\mathcal O}_P} {(f_1 , f_2)_P}} \\le {\\frac {R} {(f_1, f_2)}} < \\infty$.\r\n${\\mathcal O}_P = (f_1 , f_2)_P +R$.\r\nIf $P \\notin C_1 \\cap C_2$ then $I(C_1 \\cap C_2, P)=0$;\r\nIf $P \\in C_1 \\cap C_2$ then $(f_1 , f_2)_P \\subset {\\mathfrak M}_P$;\r\n$I(C_1 \\cap C_2; P) = 1 + dim({\\frac R {(f_1 , f_2)_P}})$ iff\r\n$(f_1 , f_2) = {\\mathfrak M}_P$.\r\nIf $P \\in C_1 \\cap C_2$ and $r \\ge dim({\\frac {{\\mathcal O}_P} {(f_1 , f_2)_P}})$ then\r\n${\\mathfrak M}_P^r \\subset (f_1, f_2)_P$.  If \r\n$P, Q \\in C_1 \\cap C_2 \\cap {\\cal A}^2, \\psi \\in {\\mathcal O}_P$\r\nthen $\\exists g \\in R$: \r\n$g= \\psi \\jmod{(f_1 , f_2)_P}$ and \r\n$g= 0 \\jmod{(f_1 , f_2)_Q}$ if $P \\ne Q$.\r\n\\\\\r\n\\emph{S-4:} Kernel of natural map $R \\rightarrow \\prod_{P \\in (C_1 \\cap C_2 \\cap {\\cal A}^2)}\r\n{\\frac {{\\mathcal O}_P} {(f_1 , f_2)_P}}$ is just $(f_1 , f_2)$ where the natural map is:\r\n$f \\mapsto (\\ldots, f \\jmod{(f_1, f_2)}, \\ldots)$.  \r\n$dim({\\frac R J})\r\n= \\sum_P dim( {\\frac  {{\\mathcal O}_P} {(f_1 , f_2)}})\r\n= \\sum_P I(C_1 \\cap C_2, P)$.  The last equality holds iff $J \\subset (f_1 , f_2)$.\r\nDefine $L= \\{ g \\in R : gf \\in (f_1 , f_2) \\}$ and $1 \\in L$.  $L$ is an ideal\r\n$(f_1 , f_2) \\subset L \\subset R$.  \r\n$P \\in {\\cal A}^2$, $\\exists g \\in L: g(P) =0, P \\in L$.  \r\n$\\exists a \\in k: 1 \\notin L +R(x-a)$ and\r\n$\\exists b \\in k: 1 \\notin L +R(x-a) + R(y-b)$.\r\n\\\\\r\n\\emph{S-5:}\r\nProperties of intersection multiplicity.  $I((y-x^m), y; 0)= m$.  Show the definitions\r\nmake sense and that there is a line $L$ which does not contain any of the intersection\r\npoints.  The proof requires knowing there are only a finite number of points in the\r\nintersection.\r\n\\end{quote}\r\n{\\bf Genus} for non-singular curve: $g_f = {\\frac {(n-1)(n-2)} {2}} - d$.\r\n$L(D)= \\{ f: K(C)^*: div(f) \\ge -D \\}$.  $l(D)= dim (L(D))$.\r\n\\\\\r\n\\\\\r\n{\\bf Reimann Roch Theorem:} Let\r\n$X$ be a non-singular projective plane curve.  $\\exists g \\ge 0: \\forall D,\r\ndim_k(L(D)) \\ge deg(D)+1-g$.  The minimum such $g$ is called the genus.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Resultants:} \r\nThe $r$ forms $f_1,f_2,...,f_r$ with indeterminate coefficients possess a resultant\r\nsystem of integral polynomials $b_k$ such that for special values of the \r\ncoefficients in $K$ (algebraically closed).  \r\nThe vanishing of all resultants is a necessary and \r\nsufficient condition for\r\n$f_1= f_2= ... =f_r= 0$ to have a solution $\\ne 0$.  The $b_k$ are homogeneous\r\nin the coefficients of every form $f_i$ and \r\nsatisfy $x_k^{s_r}b_k=0 \\jmod {(f_1, f_2,...,f_r)}$.  \r\n\\\\\r\n\\\\\r\n{\\bf Bezout's Theorem.}  If $f, g$ are two curves of degree $n,m$ respectively that\r\nhave no common component then they intersect in $mn$ points counting multiplicity.\r\nNotes: A homogeneous system \r\n$f_1= f_2= ... =f_r= 0$ has solutions\r\n$(\\xi_1^{(a)}, \\xi_2^{(a)},...  \\xi_n^{(a)}), a= 1,2,3,...,q$.  \r\nSet $l_x=u_1x_1+u_2x_2+...+u_nx_n$.\r\nForm resultant system $b_1(u), ..., b_t(u)$.  The common zeros of $b_1, ...$ are\r\n$\\prod l_a$.  By Nullstellensatz, \r\n$(\\prod_a l_a)^{\\tau}=0 (b_1(u),b_2(u),...,b_t(u))$\r\n$\\rightarrow D(u)= \\prod {l_a}^{\\rho_a}$ and\r\n$(b_i(u))^{r_i}=0 (\\prod l_a)$\r\n$\\rightarrow D(u)= (f_1,...,f_r,l)$.  $R(u)$ is the same as the u-resultant so\r\n$\\sum \\rho_a$ is the degree of $R(u)= \\prod deg(f_i)$.\r\n\\\\\r\n\\\\\r\n\\emph{Example:} $F_1(x,y,z)=x^2+y^2-10z^2=0$,\r\n$F_2(x,y,z)=x^2+xy+2y^2-16z^2=0$, add $F_3(x,y,z)= u_0z+u_1x+u_2y$.\r\n$Res_{1,2,2}(F_0,F_1,F_2)=(u_0+u_1-3u_2)(u_0+2{\\sqrt 2}u_1+{\\sqrt 2}u_2)\r\n(u_0-2{\\sqrt 2}u_1-{\\sqrt 2}u_2)$.  \r\nSolutions are $(1,-3,1)$, $(-1,3,1)$, \r\n$(2{\\sqrt 2}, 2{\\sqrt 2}, 1)$,  \r\n$(-2{\\sqrt 2}, -2{\\sqrt 2}, 1)$.\r\n\\\\\r\n\\\\\r\n\\emph{Example proof with generics:} $F_1(X,Y,Z)=X-Y^2$, $F_2(X,Y,Z)=XY-Z$,\r\n$(X,Y,Z) \\rightarrow (t^2,t,t^3)$ is generic because it is a solution for any\r\nspecialization of $t$ and any solution is obtainable this way.\r\n\\\\\r\n\\\\\r\nLet $D$ be a domain and $\\Omega=\\Omega_D= {\\overline {D(t_1,t_2,...)}}$ is called a universal\r\nfield.  Note that $\\Omega \\leftrightarrow$ {prime ideals over} $D[X_1,...]$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} $x_1, ... x_n \\in \\Omega$.  $I= \\{ f: f(x_1,...,x_n)=0 \\}$ is a prime ideal.\r\nIf $I$ is a prime ideal and $1 \\notin I$ then $I$ has a generic 0.  Any extension\r\n$K(\\alpha_1 , ..., \\alpha_m)$ can be embedded in $\\Omega$.\r\n\\\\\r\nHints: look at $E=D[X]/I$.  Under this homomorphism the image of $(X_1,...X_n)$ is generic.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} If $\\xi_1 ,..., \\xi_n$ are elements of an arbitrary extension of $K$ then\r\nIf $\\Re =K[X_1,...,X_n]$ and $\\wp= \\{ f: f(\\xi_1,...,\\xi_n)=0 \\}$.  \r\n$1 \\notin \\Re$ and $\\wp$ is a prime ideal.  Every prime ideal has a generic element.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:}  Any ideal $g=(f_1, ..., f_n)$ which has no zeros in $\\Omega$ is the unit ideal.\r\n\\emph{Proof:} Otherwise a maximal ideal would correspond to a non-zero generic point.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Extension of Nullstellensatz}:  If $p_1, ..., p_s$ all vanish at the common zeros of\r\n$(f_1,...,f_n)$, then $\\exists q$ such that powers of the $p_i$'s of degree $q$\r\nare in $(f_1,...,f_n)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  For $s=1$, this is the simple Nullstellensatz.  Let the exponent for each $i$ be\r\n$q_i$.  Set $q= q_1 + q_2 + ...+ q_n -n +1$.\r\nNullstellensatz bound: $\\rho \\leq 13 d^n$ where $d$ is the degree and $n$ is the number of\r\nvariables.\r\n\\end{quote}\r\n{\\bf Theorem:}  \r\nLet $N_q$ be the number of products $X_j$ of degree $q$.\r\nSuppose $F_1, F_2,..., F_r$ are forms.  $(0,...,0)$ is the only common zero\r\niff all products $X_j$ can be expressed as linear combinations of the $X_{ki}F_i$ \r\nwith coefficients in $K$.\r\nNote:  This means they are linearly independent.  So there are other common zeros is\r\nthere are fewer than $N_q$.  Note that $X_1, ..., X_n$ satisfy the extension conditions.  \r\nIf the $X_{ki}F_i= \\sum a_{kij}X_j$\r\nare not linearly independent, the determinant families, $R_i(a)$, form a resultant set.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Multivariate resultants:}  If we fix degrees \r\n$d_0,d_1, \\ldots d_n$ \r\nthen there is a unique\r\npolynomial $Res \\in {\\mathbb Z}[u_i , \\alpha]$ such that (a) if $F_0, F_1, \\ldots , F_n$\r\nare homogeneous polynomials of degrees\r\n$d_0,d_1, \\ldots d_n$ then $F_0= \\ldots = F_n=0$ has a nontrivial solution over\r\n${\\mathbb C}$ iff \r\n$Res(F_0, \\ldots , F_n)=0$, (b) \r\n$Res(x_0^{d_0}, \\ldots , x_n^{d_n})=1$, (b) \r\n, (c) $Res$ is irreducible\r\nin ${\\mathbb C}[u_i, \\alpha]$.  If $PP=PP(x_1, x_2, \\ldots, x_n)$ is a set of\r\npower products in the $x_i$, there are $N_m= {{m+n-1} \\choose {n-1}}$  $PP$'s of degree\r\n$m$.  \\emph{Example:} \r\n$A_3=a_3x^2b_3y^2+c_3z^2$,\r\n$A_2=a_2x+b_2y+c_2z$,\r\n$A_1=a_1x+b_1y+c_1z$.  $S_i= {\\frac {PP_i^d} {x_i^d}}$,\r\n$S_1= \\langle x^2, xy, xz \\rangle, S_2=\\langle y^2, yz \\rangle, S_3= \\langle z^2 \\rangle$.\r\n\\\\\r\n\\\\\r\n$\\left(\r\n\\begin{array}{c|cccccc}\r\n & x^2 & xy & xz & y^2 & yz & z^2 \\\\\r\n\\hline\r\nxA_1 & a_1 & b_1 & c_1 & 0 & 0 & 0 \\\\\r\nyA_1 & 0 & a_1 & 0 & b_1 & c_1 & 0 \\\\\r\nzA_1 & 0 & 0 & a_1&  0 & b_1 & c_1 \\\\\r\nyA_2 & 0 & a_2 & 0 & b_2 & 0 & 0 \\\\\r\nzA_2 & 0 & 0 & a_2 & 0 & b_2 & c_2 \\\\\r\nA_3 & a_3 & 0 & 0 & b_3 & 0 & c_3 \\\\\r\n\\end{array}\r\n\\right)\r\n$.\r\n\\subsection{Elliptic Curves}\r\n{\\bf Basic Definitions:}  An \\emph{elliptic curve} is a smooth projective curve of\r\ngenus $1$ with a distinguished point $O$.  In the plane, (affine)\r\nelliptic curves are described by an equation of the form\r\n$E(F): y^2 +a_1 xy + a_3 = x^3 +a_2 x^2 + a_4 x + a_6$, $a_i \\in F$ \r\ncalled the \\emph{general affine Weierstrauss form (GWF)}.\r\nAn equation of the form\r\n$E(F): y^2 = x^3 + a x + b$, $a, b \\in F$, is said to be in\r\n\\emph{special affine Weierstrauss form (SWF)} and\r\nsometimes we denote this curve by $E_{a,b}(F)$.  \r\nIf $P=(x_P, y_P)$ is a solution of\r\nthe SWF, $P$ is said to be on the elliptic curve $E_{a,b}(F)$.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\n\\emph{Projective coordinates:}\r\n$(X_1 , Y_1, Z_1) \\sim (X_2 , Y_2, Z_2)$, \r\n$X_1 = \\lambda^c X_2$, $Y_1 = \\lambda^d Y_2$, $Z_1 = \\lambda Z_2$, \r\n$c,d \\in {\\mathbb Z}^{>0}$ and usually $c=d=1$.\r\n\\emph{Jacobian projective coordinates:} $\\infty= (1:1:0)$ and $-(X:Y:Z)=(X:-Y:Z)$.\r\n\\emph{Standard projective coordinates:} $\\infty= (0:1:0)$ and $-(X:Y:Z)=(X:-Y:Z)$.\r\n\\\\\r\n\\\\\r\n{\\bf Addition Formula for SWF:}\r\n$Y^{2}Z= X^{3}+aXZ+bZ^{3}$, $P_{i}= (x_{i},y_{i})$, $O=(0:1:0)$.\r\nWe want to calculate $R=P_1+P_2$.  If $P_1$ or $P_2$ is $O$, result is obvious.\r\nIf $x_1=x_2$ and $y_1= - y_2$, $R=O$.\r\nIf $x_1 \\ne x_2$, set\r\n$\\lambda ={\\frac {y_{2}-y_{1}} {x_{2}-x_{1}}}$.  If $x_1 = x_2$ and\r\n$y_1 \\ne - y_2$, set $\\lambda= (3{x_1}^2+a)(y_1+y_2)^{-1}$.\r\nIn either case, $x_3= \\lambda^2 - x_1 -x_2$,\r\n$y_3= \\lambda(x_1-x_3)-y_1$ and $R= (x_3 : y_3 : 1)$.\r\n$|\\epsilon_{p}| \\leq 2{\\sqrt p}$.  $E_{a,b}(F)$\r\ndefined by $f(x,y)= y^2-(x^3+ax+b)$ is \\emph{non-singular}\r\nif there is no point $(x,y)\\in E_{a,b}(F)$ such that\r\n${\\frac {\\partial f} {\\partial x}} (x,y)=0$ and\r\n${\\frac {\\partial f} {\\partial y}} (x,y)=0$ or equivalently\r\nprovided\r\n$x^3_ax+b$ does not multiple roots.\r\n$f(x,y)$ has multiple roots iff $-(4a^3 + 27 b^2)=0$.  \r\nUsually we pick $Z$ axis tangent to\r\n$O$ and then $(0,1,0)$ as the point at $\\infty$. \r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  \r\nIf $C_1$ and $C_2$ are two non cubic curves that meet\r\nat eight points, they meet at nine points (counting multiplicity).\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$C_1: a_1x^x+a_2y^3+ \\ldots + a_{10}xyz$.\r\n$C_2: b_1x^x+b_2y^3+ \\ldots + b_{10}xyz$.  The set of cubics passing through eight\r\npoints form a two parameter family: $C= \\alpha C_1 + \\beta C_2$.\r\n$C_1(P_i)=0=C_2(P_i), i \\le 8 \\rightarrow C(P_9)=0$.\r\n\\end{quote}\r\n{\\bf Observation:}  The ``eight point theorem'' gives a quick proof of associativity by\r\nlooking at the intersection of six lines (read down and across) in the following:\r\n$$\r\n\\left(\r\n\\begin{array}{l | c c c}\r\n & l: & m: & n:\\\\\r\n\\hline\r\nr: & P & X & Q+R\\\\\r\ns: & Q & R & {\\overline {QR}}\\\\\r\nt: & {\\overline {PQ}} & P+Q & O\\\\\r\n\\end{array}\r\n\\right)$$\r\nHere, $X= {\\overline {P(Q+R)}}= {\\overline {R(P+Q)}}$ and the eight point theorem\r\nis applied to \r\n$C_1: l(X,Y,Z) m(X,Y,Z) n(X,Y,Z)= 0$ and $C_2: r(X,Y,Z) s(X,Y,Z) t(X,Y,Z)= 0$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}  $Z=0$ is tangent to PSWF at $[0,1,0]$ but the tangent line intersects\r\nthe curve three times. This is called a \\emph{flex point}.\r\n\\\\\r\n\\\\\r\n{\\bf Mordell's Theorem:}  If a non-singular cubic curve over $k$ has a rational point then\r\nthe rational points are finitely generated as a $k$-module.\r\nUse $H({\\frac m n})= max(|m|, |n|)$. Let $P=(x,y)$.  Define $H(P)= H(x)$ and\r\n$h(P)= log(H(P))$.  From now on assume $C$ is given by\r\n$y^2= x^3 + ax^2 + bx +c$.\r\n\\begin{quote}\r\n\\emph{Proof:} To prove it, need four lemmas:\r\n\\\\\r\n\\\\\r\n\\emph{Lemma 1:} There are a finite number of points $P$: $h(P) < M$.\r\n\\\\\r\n\\\\\r\n\\emph{Lemma 2:} Fix $P_0$ on $C$, $\\exists K_0(P_0 , a, b, c):  h(P+P_0) \\leq\r\n2h(P)+ k_0$.\r\n\\\\\r\n\\jt Show that if $P$ is on $C(Q)$, $P=({\\frac m {e^2}}, {\\frac n {e^3}})$.  Then\r\nshow $n \\leq KH(P)^{\\frac 3 2}$.  Use this to get\r\n$k_0$.\r\n\\\\\r\n\\\\\r\n\\emph{Lemma 3:} Fix  $\\exists K(a, b, c):  h(2P) \\geq\r\n4h(P) - K$.\r\n\\\\\r\n\\\\\r\n\\emph{Lemma 4:} $|\\{C(Q):2C(Q)\\}| < \\infty$.\r\n\\\\\r\n\\\\\r\nFor lemma 4, assume $y^2= x^3+ax^2+bx$ (so the curve\r\nalways has a rational point), and use $\\Gamma= C(Q)$ and\r\n$\\Delta=2\\Gamma$.  Define the map\r\n$\\phi(x,y)= (x+a+{\\frac b x}, y{\\frac {x^2 - b} {x^2}})$.\r\nDefine $\\psi$ similarly.  Note that $\\psi ( \\phi (P))= 2P$ and\r\n$ker(\\phi) = \\{0, (0,0)\\}$. ${Q^*}^2$ $\\alpha(x,y)= x \\jmod\r\n{{Q^*}^2}$.  $im(\\phi) \\subseteq ker(\\alpha)$.\r\nLet $p_i | b$, $i= 1,2, \\ldots t$ then $|\\Gamma: \\phi(\\Gamma)| \\leq\r\n2^{t+1}$.\r\n$|\\Gamma:\\phi(\\Gamma)| \\leq 2^{t+1}$.  Use the following lemma: If $A$ and\r\n$B$\r\nare abelian $A \\rightarrow B \\rightarrow A$ and\r\n$|B:\\phi(A)| < \\infty$,\r\n$|A:\\phi(B)| < \\infty$, then $|A:2A| \\leq\r\n|B:\\phi(A)| |A:\\phi(B)|$.\r\n\\\\\r\n\\\\\r\n\\emph{Proof given lemmas:} Let $Q_0 , \\ldots, Q_{m-1}$ be the coset\r\nrepresentatives.  $P-Q_{i_1}= 2P_1$ is in the subgroup, $P_1-Q_{i_2}= 2P_2$,\r\nrepeatedly doing this yields:\r\n$P= Q_{i_1} + 2 Q{i_2} + \\ldots + 2^{m-1}Q_{i_m} +\r\n2^m P_m$, $h(P_j) \\leq {\\frac 3 4} h(P_{j-1})$.\r\nSince there are a finite\r\nnumber of $Q_i$ there's a $k'$ so that $h(P-Q_i) \\leq 2 h(P) + k'$ for all\r\n$P$.  Using the inequalities $h(P_j) \\leq {\\frac {h(P_{j-1})} 2} +\r\n{\\frac {k+k'} 4}$.\r\nSo the group is generated by the $Q_i$ and the (finite number\r\nof) points of $ht \\leq {\\frac {k+k'} 4}$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nLet $C$ be a non-singular cubic curve $C: y^2= x^3 + ax^2 + bx +c$.  Set\r\n$D= -4a^3 c + a^2 b^2 + 18 abc -4b^3 -27c^2$.  Let $\\Phi$ be the set of\r\npoints of finite order.  Let $\\phi$ be the reduction map mod $p$.  If\r\n$(p, 2D)= 1$ then $\\phi$ is an injection into $C(F_p )$.\r\n\\\\\r\n\\\\\r\n{\\bf Nagel-Lutz Theorem:} Same as above with $P(x,y)$ as a rational point of finite order\r\n$y=0$ or $y|d^2$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Functions on Elliptic Curves:}\r\n$f_1(x,y) = {\\frac {s(x,y)} {t(x,y)}}$ and\r\n$f_2(x,y) = {\\frac {u(x,y)} {v(x,y)}}$ are said to be \\emph{equivalent} on the\r\nelliptic curve $E$, denoted by $f_1 \\sim_E f_2$ iff $(sv-ut)= 0 \\jmod {E}$.\r\nPolynomials can be uniquely $x$ or $y$ reduced but not rational functions.\r\n\\emph{Examples:}  Let $E: y^2-(x^3+x^2+x)$ then\r\n$ {\\frac {x}{y-x}} \\sim_E {\\frac {y+x}{x^2+1}}$.  \r\nPut\r\n$F(X,Y,Z)= \\{ {\\frac x y} \\}= [X, Y]$ then $F[0,1,0] =[0,1] \\sim_E 0$ (a zero) while\r\nif $G(X,Y,Z)= \\{ {\\frac y x} \\}= [Y, X]$ then $G[0,1,0] =[0,1] \\sim_E \\infty$.\r\nFor $E: y^2= x^3-x$, $\\{ {\\frac y {x^2-1}} \\} \\sim_E \\{ {\\frac x y} \\}$ and\r\n$[YZ, X^2-Z^2] \\sim_E [X,Y]$.  \r\nFor $E: y^2= x^3-x$, \r\n$\\{x \\}$ has a $0$ at $(0,0)$,\r\n$\\{y \\}$ has a $0$ at $(-1,0), (0,0), (1,0)$,\r\n$\\{ {\\frac x y} \\}$ has a $0$ at $(-1,0), (1,0)$.\r\nIf $E(a,b)$ is non-singular, $E$ is irreducible and\r\nwe can embed $k[x,y]/(E)$ in the field of fractions $K(E)$ \r\nand we can define a map from $K(R) \\rightarrow\r\n{\\overline K} \\cup \\{\\infty\\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nA \\emph{morphism} between two elliptic curves $C_1$ and $C_2$ is a rational map\r\n$\\varphi: (C_1, I_1) \\rightarrow (C_2 , I_2)$, \r\n$\\varphi(x,y)= (f(x,y), g(x,y)), g, g \\in K(C_1 )$, such that\r\n$\\varphi(P+Q)= \\varphi(P)+\\varphi(Q)$.  $\\varphi(P)= [n]P$ is a morphism.  A\r\nmorphism is an \\emph{isomorphism} if $\\exists \\psi$, a morphism: $\\psi \\circ \\varphi= [1]$.\r\nAn \\emph{isogony} is a surjective morphism with finite kernel preserving the base point.\r\nIf $\\psi: E_1 \\rightarrow E_2$ induces a $\\psi^*: K(E_2) \\rightarrow K(E_1)$.\r\n$\\psi^*(f)= f \\circ \\psi$.  $deg(\\psi)= ker(\\psi)$.\r\n\\\\\r\n\\\\\r\n\\emph{Example of dual isogony:} \r\n$E: y^2= x^3 + x^2 +x$,\r\n$E': (y')^2= (x')^3 -2 (x')^2 -3 (x')$.  \r\n$\\psi(x,y)=\r\n( {\\frac {y^2} {x^2}}, {\\frac {y(1-x^2)} {x^2}})$,\r\n$\\varphi(x',y')= ( {\\frac {(y')^2} {4(x')^2}}, {\\frac {(y')(-3-(x')^2)} {8(x')^2}},)$ \r\nand $\\varphi \\circ \\psi= [2]$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nSuppose $E= E_{a,b}(K), char(K) \\ne 2,3$.  Let $x_1= \\mu^2x$ and $y_1= \\mu^3 y$ then\r\n$(x_1 , y_1) \\in E_{a', b'}(K)$ with $a'= \\mu^4 a$ and $b'= \\mu^6b$.  Two \r\nelliptic curves related in this way are said to be \\emph{isomorphic}.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nIf $K= F_{p^m}, p \\ne 2, 3$ and \r\n$E_K^{(1)}(a, b) \\cong E_K^{(2)}({\\overline a}, {\\overline b})$ iff \r\n$\\exists u \\in K^*$ such that $u^4 {\\overline a}=a$ and\r\n$u^6 {\\overline b}=b$ under the map $(x,y) \\mapsto (u^2 x, u^3 y)$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Definition:}\r\n$j(E)= 1728 {\\frac {4a^3} {4a^3+27b^2}}$ is called the\r\n\\emph{$j$-invariant}. \r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\n$j(E)$ is invariant under \r\nthe transformation above (i.e. - two isomorphic curves have the same\r\n$j$-invariant) and, conversely, two curves with the same $j$ value are related in \r\nthis way (and are\r\nthus isomorphic in the elliptic curve defined over the algebraic closure).\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $j(E_1)=j(E_2)$ then\r\n$\\exists \\mu \\in {\\overline K}, \\mu \\ne 0: a_2= \\mu^4 a_1, b_2= \\mu^6 b_2$.  \r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Homogeneous forms:}\r\nLet $G(u,v)$ be a homogeneous polynomial and $(u_0, v_0) \\in {\\mathbb P}^1_K$,\r\n$\\exists k \\ge 0$ and $H(u, v)$ with $H(u_0, v_0) \\ne 0: G(u,v)= (v_0 u -u_0 v)^k H(u,v)$.\r\nAny line in ${\\mathbb P}^2_k$ can be parameterized by \r\n$(x,y,z)= (a_0 u + b_0 v, a_1 u + b_1 v, a_2 u + b_2 v)$.\r\n$L$ intersects $C$ to order $n$ at $P=(x_0 : y_0 : z_0)$ if ${\\overline C}(u,v) =\r\n(v_0 u - u_0 v)^n H(u,v)$ in the foregoing theorem; denote this as $ord_{L, P}(C)=n$,\r\n$ord_{L, P}(C)= \\infty$ if ${\\overline C}$ is identically 0.  \r\nIf $L_1, L_2$ are lines, $ord_{L_1, P}(P)= 1$\r\nor $\\infty$.  If $C$ is a curve defined by $C(x,y,z)=0$, $C$ is non singular at $P$ if\r\n$(C_x, C_y, C_z) \\ne 0$ in which case the tangent line is $C_x X + C_y Y + C_z Z =0$.  If\r\n$C$ is non-singular at $P$ there is a line in ${\\mathbb P}^2_K$ that intersect $C$ to order at\r\nleast $2$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nThe number of equivalence classes of elliptic curves over $K$ is\r\n$2q+6$, $2q+2$, $2q+4$, $2q$ according to $q = 1, 5, 7, 11 \\jmod{12}$.\r\nIf $K= F_{2^m}$ and $E_K(a, b): y^2 + xy = x^3 + a x^2 +b$ then\r\n$E_K^{(1)}(a, b) \\cong E_K^{(2)}({\\overline a}, {\\overline b})$ iff \r\n$b= {\\overline b}, Tr(a)=Tr({\\overline a})$ and if so $\\exists s: {\\overline a}= s^2+s+a$ \r\nunder the map $(x,y) \\mapsto (x, y+sx)$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Division Polynomials:}\r\nLet $E(K): y^2+a_1xy+a_3y= x^3 +a_2 x^2 + a_4 x + a_6$ be an elliptic curve \r\n$m \\in {\\mathbb Z}, P = (x,y)$, \r\n$b_2 = a_1^2 + 4a_2$,\r\n$b_4 = a_1 a_3 + 2a_4$,\r\n$b_6 = a_3^2 + 4a_6$,\r\n$b_8 =  a_1^2 a_6 + 2 a_4 a_6 - a_1 a_3 a_4 + a_2 a_3^2 -a_4^2$ then\r\n$\\exists \\psi_m(x,y), \\omega_m(x,y), \\theta_m(x,y) \\in K[x,y]$ such that\r\n$[m]P=({\\frac {\\theta_m(x,y)} {(\\psi_m(x,y))^2}}, {\\frac {\\omega_m(x,y)} {(\\psi_m(x,y))^3}})$.\r\n$\\psi_1 = 0$, $\\psi_1 = 2$,\r\n$\\psi_2 = 2y+a_1x+a_3$, \r\n$\\psi_3 = 3x^4+b_2x^2+3b_4x^2+3b_6+b_8$,\r\n$\\psi_4 = (2x^6+b_2x^5+5 b_4 x^4 + 10 b_8 x^2 +(b_2 b_8-b_4 b_6)x+ b_4 b_8 - b_6^2) \r\n\\psi_2$,\r\n$\\psi_{2m+1} = \\psi_{m+2} \\psi_m^3 - \\psi_{m-1}\\psi_{m+1}^3, m \\ge 2$,\r\n$\\psi_{2m} = \r\n{\\frac {\\psi_m} {\\psi_2}}\r\n(\\psi_{m+2} \\psi_{m-1}^2 - \\psi_{m-2} \\psi_{m+1}^2)$,\r\n$\\theta_m = x \\psi_m^2- \\psi_{m+1} \\psi_{m-1}$,\r\n$\\omega_m = \r\n{\\frac {1} {4 y}} \r\n(\\psi_{m+2} \\psi_{m-1}^2- \\psi_{m-2} \\psi_{m+1}^2), m>2$.\r\nNote that $deg(\\psi_m)= O(m^2)$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nAn \\emph{endomorphism} is a homomorphic map between and an elliptic \r\ncurve and itself that is expressible as a \\emph{rational function}.\r\nIf $\\alpha$ is an endomorphism and $P=(x,y),\r\n\\alpha(X+Y) = \\alpha(X) + \\alpha(Y), \\alpha(x,y)= (r_1(x,y), r_2(x,y))$.  Because\r\n$y^2= x^3+ax+b$, we may assume \r\n$\\alpha(x,y)= (r_1(x), y r_2(x))$; if $r_1(x)= {\\frac {p(x)} {q(x)}}$, the degree of\r\nendomorphism is $max(deg(p(x)), deg(q(x)))$.  This endomorphism\r\n$\\alpha$ is a \\emph{separable endomorphism} if $r_1'(x) \\ne 0$.\r\nThe \\emph{Frobenius endomorphism} is\r\n$\\varphi(x,y)= (x^q , y^q)$. \r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\n$E[n]= \\{P \\in E({\\overline K}): nP= \\infty \\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} (1) If $char(K) \\ne 2$ $E[2]= {\\mathbb Z}_2 \\oplus {\\mathbb Z}_2$; \r\nif $char(K) = 2$ $E[2]= {\\mathbb Z}_2$ or $0$.\r\n(2) If $char(K) \\nmid n$ or is $0$, $E[n]= {\\mathbb Z}_n \\oplus {\\mathbb Z}_n$.  (3)\r\nIf $char(K)=p \\mid n, n=p^r n'$ then\r\n$E[n]= {\\mathbb Z}_n \\oplus {\\mathbb Z}_{n'}$ or\r\n$E[n]= {\\mathbb Z}_{n'} \\oplus {\\mathbb Z}_{n'}$.  Proof\r\nuses division polynomials.  Let\r\n$E$ be an elliptic curve over $F_q$.  Then \r\n$E(F_q)= {\\mathbb Z}_n$ or\r\n${\\mathbb Z}_{n_1} \\oplus {\\mathbb Z}_{n_2}$ with $n_1 \\mid n_2$.  \r\n\\begin{quote}\r\n\\emph{Proof:}\r\nApply the above theorem.\r\n$\\phi_n$ induces a linear transformation on $E[n]$.\r\n$E[n]= Z_{n_1} \\oplus \\ldots \\oplus Z_{n_k}$ by ther FTOAG.  Let $l \\mid n_1$ so\r\n$l \\mid n_j$. $E[l] \\subseteq E[n]$, so it has order $l^k$.  But the \r\nendomorphism induced by multiplication by $n$ has order $n^2$, so $k=2$.  Since\r\nthis map, annihilates $Z_{n_1} \\oplus Z_{n_2}$, $n_1, n_2 \\mid n$, and since\r\n$n^2= \\#E[n]$, $n_1=n_2=n$.\r\n\\end{quote}\r\n{\\bf Theorem:} If $\\alpha$ be a separable endomorphism of $E_{A,B}(\\overline{F_q})$, \r\n$deg((\\alpha)= |ker(\\alpha)|$, otherwise $deg((\\alpha)> |ker(\\alpha)|$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$\\alpha(x,y)= (r_1(x), yr_2(x))$, $r_1(x)= {\\frac {p(x)}{q(x)}}$; since $\\alpha$\r\nis separable, $p'q-q'p \\neq 0$.  Let $S= \\{x \\in \\overline{K}: (pq'-qp')q=0\\}$.\r\nThere are $(a,b)$ on the curve: $a \\neq 0 \\neq b$, $(a,b) \\neq O$.\r\n$deg(p-aq)= deg(\\alpha)$, and $a \\notin r_1(S)$.  There are exactly $deg(\\alpha)$\r\npoints: $\\alpha(x,y)= (a,b)$.  STS there are no nultiple roots.  If $x_0$ is a multiple\r\nroot, $pq'-qp'(x_0) =0$.  If $\\alpha$ is not separable, the same argument holds but\r\nthe equation has at least one solution with multiple roots so it has fewer roots than\r\n$deg( \\alpha )$.\r\n\\end{quote}\r\n{\\bf Theorem:} $\\alpha: E_{A,B}(\\overline{K}) \\rightarrow E_{A,B}(\\overline{K})$ is surjective.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIf $p-aq$ is not constant and $x_0$ is a root, $q(x_0) \\neq 0$.  Choose $y_0^2= x_0^3+Ax_0+B$.\r\n$\\alpha(x_0,y_0)= (a, b')$, $b'= \\pm b$.  If $b'=b$, we're done.  If \r\n$\\alpha(x_0 , y_0 )= (a, -b')= (a, b)$.  Since $E(\\overline{K})$ is infinite and\r\n$ker( \\alpha )$ is finite, only a finite number of points map onto a points\r\nwith a single $x$ coordinate.  Therefore either $p$ or $q$ is not constant.\r\nThere is a unique $a$ such that $p-aq$ is constant.  So there are at most two\r\npoints, namely, $(a, \\pm b )$ not in the image.  Pick another\r\n$P_1$: $\\alpha(P_1 )=(a_1 , b_1 )$.  $(a_1, b_1 ) + (a,b) \\neq (a, \\pm b )$.\r\nThere is a unique $P_2$: $\\alpha (P_2 ) =  ( a_1 , b_1 ) + (a, b)$ so\r\n$\\alpha (P_2 - P_1 )= (a,b)$ and\r\n$\\alpha (P_1 - P_2 )= (a,-b)$.\r\n\\end{quote}\r\n{\\bf Theorem:} $\\phi_q^n-1$ is separable and $|ker(\\phi_q^n-1)|= |\\#E(F_q)|$.  \r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$\\phi$ is a homomorphism.  It has degree $q$ and $(x^q)'=0$.\r\n\\end{quote}\r\n{\\bf Theorem:}  Let $E_{A, B}$ be an elliptic curve.  Fix $(u,v) \\in E$.  Define\r\n$f(x,y), g(x,y)) = (x,y) + (u,v)$. Then ${\\frac {\\frac {df(x,y)} {dx}} {g(x,y)}}= {\\frac 1 y}$.\r\n\\begin{quote}\r\nUse the addition formula and the fact that $2y y'= 3x^2+A$ to get\r\n$(x-u)^3u({\\frac {df(x,y)}{dx}}-g(x,y))=\r\nv(Au+u^3+v^3-Ax-x^3-y^2) + y(-Au-u^3-v^3+Ax+x^3-y^2)$.  Now use $B=y^2-x^3-Ax$ to get the result.\r\n\\end{quote}\r\n{\\bf Theorem:}  Let $\\alpha_i, i= 1,2,3$ be endomorphisms.  \r\nWrite $\\alpha_i(x,y)= (R_{\\alpha_i}, S_{\\alpha_i}y)$.  Suppose $\\exists c_{\\alpha_1}, c_{\\alpha_2}:\r\n{\\frac {R_{\\alpha_i}'} {S_{\\alpha_i}}}= c_{\\alpha_i}, i=1,2$.  Then\r\n${\\frac {R_{\\alpha_3}'} {S_{\\alpha_3}}}= c_{\\alpha_1} + c_{\\alpha_2}$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n${\\frac {\\partial x_3} {\\partial x_1}} = {\\frac {y_3} {y_1}}$ and\r\n${\\frac {\\partial x_3} {\\partial x_2}} = {\\frac {y_3} {y_2}}$.\r\n${\\frac {\\partial x_j} {\\partial x}} = c_{\\alpha_j}{\\frac {y_j} {y}}$.  Now apply the\r\nchain rule.\r\n\\end{quote}\r\n{\\bf Theorem:} Let $E_{A,B}$ be an elliptic curve, $n \\in {\\mathbb Z}$ and\r\n$n(x,y)= (R_n(x), yS_n(x))$.  Then\r\n${\\frac {R_{n}'} {S_{n}'}}= n$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nFrom the inverse formula if it holds for $n>0$, it holds for $n<0$.  It holds for $n=1$ and the\r\nresult above shows if it holds for $n$, it holds for $n+1$.\r\n\\end{quote}\r\n{\\bf Theorem:} $r, s \\in \\mathbb{Z}$, $r \\neq 0 \\neq s$ then $r\\phi_n+s$ is separable iff $p \\nmid s$.\r\n$(x,y) \\in E(F_q)$ iff $\\phi_p(x,y)= (x,y)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$r(x,y)= (R_r(x), y S_r(x))$. \r\n$(R_{r \\phi_q(x)}(x), y_{r\\phi_q}(x))= (R_r^q, y(x^3+Ax+B)^{\\frac {q-1} 2} S_r^q(x))$.\r\nThus $c_{r \\phi_q}= R_{r \\phi_q}'/S_{r \\phi_q}=0$.\r\n$R_{r \\phi_q +s} /S_{r \\phi_1 +s} = c_{r \\phi_q} + c_s = s \\neq 0 \\jmod{p}$.\r\n\\end{quote}\r\n{\\bf Theorem:} $deg(a \\alpha + b \\beta)= a^2 deg( \\alpha ) + b^2 deg( \\beta ) + ab (deg (\\alpha + \\beta )\r\n- deg( \\alpha ) -deg( \\beta )$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nConsider $\\alpha_n$ and $\\beta_n$ given by the matricies when viewed as maps in $E[n]$.  The matrix calculation\r\nis straigntforward.\r\n\\end{quote}\r\n{\\bf Theorem:} Let $E$ be an elliptic curve over $K$ and $n$ a positive integer, $char(K) \\nmid n$.  There\r\nis a pairing $e_n : E[n] \\times E[n] \\rightarrow \\mu_n$ (the Weil pairing) with \r\n(1) $e_n$ bilinear in each variable, (2) $e_n$, non-degenerate, (3) $e_n(T,T)=1$,\r\n(4) $e_n(T,S)= e(S, T)^{-1}$, $e_n( \\sigma T , \\sigma S)$ for $\\sigma \\in Aut ( \\overline{K} )$, and\r\n(6) $e_n( \\alpha (S) , \\alpha (T))= e_n(s, T)^{deg( \\alpha )}$, for all seperable automorphisms of $E$.\r\nIf the coefficients are in $F_q$, the statement holds for $\\phi_p$.\r\n\\begin{quote}\r\n\\emph{Proof:}  The proof uses divisor theory.\r\n\\end{quote}\r\n{\\bf Theorem:} Let $\\{T_1 , T_2 \\}$ be a basis in $E[n]$.  Then $e_n(T_1 , T_2 )$ is a primitive $n$-th\r\nroot of unity.\r\n\\begin{quote}\r\n\\emph{Proof:}  Suppose $e_n(T_1 , T_2 )= \\zeta$, $zeta^d=1$.  $e_n(T_1, d T_2)=1$ and\r\n$e_n(T_2, dT_2)= e_n(T_2 , T_2 )^d= 1$.  Let $S= a T_1 +b T_2$.  \r\n$e_n(T_1, dT_2)= e_n(T_1 , dT_2)^a e_n(T_t, dT_2)^b=1$.  This is true for all $S$ so $dT_2= \\infty$.  But\r\nthis can hold iff $n \\mid d$, so $\\zeta$ is  a primitive root.\r\n\\end{quote}\r\n{\\bf Theorem:} Let $\\alpha$ be and endomorphism of $E$ over $K$ and $n$, a positive integer\r\nnot divisible by $char(K)$.  Then $deg( \\alpha_n )= deg( \\alpha ) \\jmod{n}$.\r\n\\begin{quote}\r\n\\emph{Proof:} By the previous result, $\\zeta= e_n(T_1 , T_2 ) $ is primitive. So\r\n$\\zeta^{deg( \\alpha )}= e_n(T_1 , T_2 )= e_n(aT_1 + c T_2, bT_1 + d T_2)= \\zeta^{ad-bc}$.\r\n\\end{quote}\r\n{\\bf Theorem:} $r, s \\in \\mathbb{Z}$, $(r,q) \\neq 1$ then $deg(r\\phi_n-s)= r^2q+s^2- r s a$, where\r\n$a= q+1-\\#E(F_q)$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$deg(r \\phi_q - s)= r^2 deg( \\phi_q ) + s^2 deg(-1) + r( deg( \\phi_q - 1) -\r\ndeg( \\phi_q ) - deg(-1))$.\r\n\\end{quote}\r\n{\\bf Theorem:} $a= q+1-\\#E(F_q)$.  $\\phi_q^2-a\\phi_q +q=0$ and $a=Tr((\\phi)_q)_m \\jmod{m}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nConsider $\\alpha= \\phi_q^2 -a \\phi_q +q$ as an endomophism in $E[m]$.\r\n$|ker(\\phi_q-1)|= deg(\\phi_q-1)=det((\\phi_q)_m-I)$.  By Cayley Hamilton,\r\n$(\\phi_q^2)_m -a \\phi_q +q = 0 \\jmod{m}$.  This is true for infinitely many\r\n$m$ so $\\alpha=0$.\r\n\\end{quote}\r\n{\\bf Hasse's Theorem:} Let $E_q$ be an elliptic curve then \r\n$ q+1- 2 {\\sqrt q} \\le \\#E_q \\le q+1+ 2 {\\sqrt q}$,\r\n$\\#E_q=q+2-t$, $t$ is the Frobenius trace. \r\n\\begin{quote}\r\n\\emph{Proof of Hasse:}\r\nLet $\\psi$ be the Frobenius map.  \r\n$\\#E_p = |ker([1]-\\psi)|$.  First note that $deg([1])=1$ (in fact, $deg([n]) =n^2$).\r\n$deg(\\psi)= p$.  Also note that $deg(a+b)-deg(a)-deg(b)=B(a,b)$ is bilinear.\r\n$0 \\le deg([t] + [2] \\psi)=t^2 -4p -2tB[1, -\\psi]= 4p-t^2$; so\r\n$(deg([1]-\\psi) - deg([1]) -deg(\\psi))^2 \\le 4p$ but the first term is $\\#E(F_p)$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $\\alpha \\ne 0$ is a separable endomorphism of $E$, \r\n$deg(\\alpha)= \\#ker(\\alpha)$, otherwise\r\n$deg(\\alpha)> \\#ker(\\alpha)$.  \r\nThe endomorphism $[n]P \\mapsto Q$ has degree $n^2$; most endomorphisms are of this form.\r\nIf $char(K) \\nmid n$ then $E[n]= {\\mathbb Z}_n \\oplus {\\mathbb Z}_n$. \r\nIf $E[n] \\subseteq E({\\mathbb K})$ then $\\mu_n \\in K$.  Given $E_q(a,b), n \\ge 1$, (1)\r\n$ker(\\phi_q^n -1)= \\#E_{q^n}(a,b)$ and \r\n$\\phi_q^n -1$ is separable\r\n$\\#E_{q^n}(a,b)= deg(\\phi_q^n -1)$.\r\nIf $\\alpha$ is separable, then $deg(\\alpha)= \\#ker(\\alpha)$.  \r\n$|E({\\overline {F_p}})[m]|= m^2$ if $(m,p)=1$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nLet $E(F_q)$ be an elliptic curve $E(F_q) \\approx {\\mathbb Z}_n$ or\r\n${\\mathbb Z}_{n_1} \\times {\\mathbb Z}_{n_2}, n_1 \\mid n_2 $.  \r\nThe Frobenius endomorphism has degree $q$ and is not separable.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Definitions:}\r\nIf $E_q$ is an elliptic curve over\r\na finite field of characteristic $p$, $E_q$ is said to be \\emph{supersingular} if\r\n$E_q[p]= \\{ \\infty \\}$.\r\n(1) $char(F) \\ne 2,3$, $(x,y) \\mapsto ({\\frac {x-3a_1^2-12 a_2} {36}}, \r\n{\\frac {y - 3 a_1 x} {216}} - {\\frac {a_1^3 + 4 a_a a_2 -12 a_3} {24}})$, \r\nsends the general equation to \r\n$E_q(a,b): y^2= x^3 + ax +b, \\Delta = -16(4 a^3 + 27 b^2)$.\r\n(2) $char(F) = 2, a_1 \\ne 0$, $(x,y) \\mapsto \r\n(a_1^2x+{\\frac {a_3} {a_1}}, y+{\\frac {a_1^2 a_4 - a_3^2} {a_1^2}})$,\r\nsends the general equation to \r\n$E_q(a,b): y^2 + xy = x^3 + ax +b, \\Delta = b$.  This is \\emph{non-supersingular}.\r\n(3) $char(F) = 2, a_1 = 0$, $(x,y) \\mapsto \r\n(x+a_2, y)$, sends the general equation to \r\n$E_q(a,b): y^2 + cy = x^3 + ax +b, \\Delta = c^4$.  This is supersingular.\r\n(4) $char(F) = 3, a_1^2 \\ne - a_2$, $(x,y) \\mapsto \r\n(x+{\\frac {d_4} {d_2}}, y+ a_1 x + a_1 {\\frac {d_4} {d_2}} +a_3)$, \r\n$d_2= a_1^2+a_2, d_4= a_4-a_1 a_3$,\r\nsends the general equation to \r\n$E_q(a,b): y^2= x^3 + ax +b, \\Delta = - a^3 b$.  This is non-supersingular.\r\n(5) $char(F) = 3, a_1^2 = - a_2$, $(x,y) \\mapsto \r\n(x, y+ a_1 x + a_3)$, sends the general equation to \r\n$E_q(a,b): y^2= x^3 + ax +b, \\Delta = - a^3 $.  This is supersingular.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  $q=p^m$, $\\exists E_q: \\#E_q= q+1-t$ iff\r\n(i) $t \\ne 0 (p), t^2 \\le 4q$; or, (ii) $m= 1(2)$ and either (a) $t=0$ or (b)\r\n$t^2=2q, p=2$, or (c) $t^2=3q, p=3$; or, (iii) $m=0 (2)$ and either (a)\r\n$t^2=4q$ or (b) $t^2=q, p \\ne 1 (3)$ or (c) $t=0, p \\ne 1 (4)$. $E_{p^m}$ is supersingular\r\niff $p \\mid t$.  $E_q = {\\mathbb Z}_{n_1} \\oplus {\\mathbb Z}_{n_2}$ and \r\n$ n_2 \\mid n_1 \\mid (q-1)$.  \r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Divisors:}\r\nGiven $E(K)$, $P \\in E({\\overline K})$, define $D= \\sum_j a_j [P_j], a_j \\in {\\mathbb Z}$ and\r\n$deg(D)= \\sum_j a_j$.  $Div^0(E)$ are the \\emph{divisors} of degree 0.  \r\nIf $f$ is a function on $E$,\r\n$div(f) = \\sum_P ord_P(f) [P] \\in div(E)$.  Two divisors $D_1, D_2$ are said to be\r\n\\emph{equivalent} if $D_1-D_2 = (D)_E$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} If $P-Q$ is a divisor on an elliptic curve $E$, $P-Q= c$.\r\nThe theorem can be applied as follows.  Suppose\r\n$div(\\{ f \\})= P_1 + P_2 + \\ldots + P_n Q_1 - Q_2 - \\ldots - Q_n$.  Let\r\n$l_1$ be the line through $P_1, P_2$ and hence $-(P_1+P_2)$ while\r\n$m_1$ is the line through $-(P_1+P_2)$ and $O$ and hence $P_1+P_2$ then\r\n$div( \\{f\\} {\\frac {m_1}{l_1}})= (P_1+P_2) + \\ldots + P_n +O - Q_1 - \\ldots - Q_n$ continuing\r\nand doing the same for the $Q_i$, we get\r\n$div( \\{f\\} \\cdot\r\n{\\frac {m_1}{l_1}} \\cdot\r\n{\\frac {m_2}{l_2}} \\cdot \\ldots\r\n{\\frac {m_{2n-2}}{l_{2n-2}}})=\r\n(P_1+P_2 + \\ldots + P_n) + (n-1) O - (Q_1 + \\ldots + Q_n)\r\n-(n-1)O =\r\n(P_1+P_2 + \\ldots + P_n) - (Q_1 + \\ldots + Q_n)$ so \r\n$f=c ( {\\frac {l_1}{m_1}} \\cdot {\\frac {l_2}{m_2}} \\cdot \\ldots\r\n{\\frac {l_{2n-2}}{m_{2n-2}}})$ by the theorem.\r\n\\begin{quote}\r\n\\end{quote}\r\n\\emph{Example of divisor calculations:}\r\n$div(\\{x \\})= 2(0,0)-2 \\infty$, \r\n$div(\\{y \\})= (-1,0)+(0,0)+(1,0) -3 \\infty$, \r\n$div(\\{ {\\frac x y} \\})= (0,0)+ \\infty -(-1,0)-(1,0)$. \r\nLet $E: y^2= x^3 -2x -5$ and $D= (2,3)+(2,-3)+O-2(-2,1) -(29,156)$.  We\r\ncan confirm $(2,3) + (2, -3) +O= O$ and $2(-2,1)+(29, 156)= O$ are elliptic\r\ncurve divisors.  The line containing $(2,3), (2,-3),O$ is $x-2=0$.  The\r\nline containing $2(-2,1)$ and $(25,156)$ is $y-5x-11=0$, so\r\n$div({\\frac {x-2} {y-5x-11}})= D$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\n$D= \\sum_P n_P P$ is a divisor of an elliptic curve $E$ iff\r\n$\\sum_P n_P =0$ and $\\sum_P [n_P]P =0$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Definition:}\r\n$f \\circ n (P)= f(nP)$.  If $T \\in E[n], \\exists T' \\in E[n^2]: nT'=T$ and\r\n$g=f \\circ n, div(g)= \\sum_{R \\in E[n]} [T'+R] -[R]$.  $g(P+S)^n= g(P)^n$ so\r\n$({\\frac {g(P+S)} {g(P)}})^n=1$.  \r\nDefine the \\emph{Weil pairing} as\r\n$e_n(S,T)= {\\frac {g(P+S)} {g(P)}}$.  If $\\sigma$ is an automorphism, \r\n$e_n( \\sigma S, \\sigma T)= \\sigma e_n(S,T)$.  If $\\alpha$ is separable,\r\n$e_n( \\alpha S, \\alpha T)= e_n(S,T)^{deg(\\alpha)}$.  \r\n\\\\\r\n\\\\\r\n{\\bf Theorem (Siegal):}  An elliptic curve over ${\\mathbb Q}$ has only finitely many\r\ninteger points.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem (Mazur):}  The set of torsion points $T_E({\\mathbb Q})$ of\r\n$E/{\\mathbb Q}$ is one of \r\n${\\mathbb Z}/n{\\mathbb Z}, n= 1,2,\\ldots,10,12$ or\r\n${\\mathbb Z}/n{\\mathbb Z} \\times\r\n{\\mathbb Z}/2n{\\mathbb Z}$, $n= 1,2,3,4$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nFor every isogony $\\psi:E \\rightarrow E'$ there is a \\emph{dual} $\\hat{\\psi}:\r\n\\hat{\\psi} \\psi= [2]_E$.  $Frob_n: \r\n{\\overline {F_p}} \\rightarrow\r\n{\\overline {F_p}}$ and $F_{p^n}= \\{ \\alpha \\in {\\overline {F_p}}: Frob_n( \\alpha )= \\alpha \\}$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:}\r\n$\\#E(F_p)= p+1 + \\sum_{x=0}^{p-1} ({\\frac {x^3+ax+b} {p}})$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Point Counting:} \r\nCounting points by\r\nbaby-step giant-step is ($O(q^{{\\frac 1 4} + \\epsilon})$). Set\r\n$N= \\#E_q$ then \r\n$q+1 - 2 {\\sqrt q} \\le N \\le q+1 + 2 {\\sqrt q}$; if $[m]P= \\infty$ then $N=m$, probably.\r\nPut $m=q+1- 2{\\sqrt q} +k, l= \\lceil {\\sqrt 4 {\\sqrt q}} \\rceil, k= al+b$, then\r\n$[m]P= [c]P + [a]S + [b] P, c= q+1-2{\\sqrt q}, S= [l]P$ or $[c]P+ [a]S = - [b] P$.  Baby\r\nstep computes LHS and stores it.  Giant step computes RHS and does a lookup.\r\n\\\\\r\n\\\\\r\n{\\bf Schoof point counting:}\r\nLet $\\varphi$ be the Frobenius automorphism $\\varphi(x,y)= (x^q , y^q )$.  \r\nSchoof calculates\r\n$t \\jmod{l}$ for a set of primes $l \\in {\\cal P}$ with \r\n$\\prod_{l \\in {\\cal P}} l > {4 {\\sqrt q}}$ and then \r\nconstruct $t$ using CRT finally returning $q+1-t$.\r\nHere's how:\\\\\r\n\\jt (1) For $l=2$, $t= 0 \\jmod{l}$ iff \r\n$(x^3+ax+b,x^q-x) \\ne 1$.  \\\\\r\n\\jt (2) if $l$ is odd, set $q_l = q \\jmod{l}, |q_l| < {\\frac l 2}$;\r\nfind $(x', y')= \\varphi(x,y)^2 + q_l (x,y) \\jmod{\\psi_l (x,y))}$;\r\nfor $j= 1,2, \\ldots {\\frac {l-1} 2}$:\\\\\r\n\\jt \\jt\r\n(i) Compute $(x_j , y_j)=j(x,y)$; \\\\\r\n\\jt \\jt\r\n(ii) if\r\n$x'-x_j^q = 0 \\jmod{\\psi_l}$, go to iii, if not, try next $j$, if all such\r\n$j$'s have been tried, go to (iv); \\\\\r\n\\jt \\jt\r\n(iii) Compute $y', y_j$, if ${\\frac {y'-y_j} y} = 0 \\jmod{\\psi_l}$ then \r\n$t= j \\jmod{l}$ otherwise $t= -j \\jmod{l}$; \\\\\r\n\\jt \\jt\r\n(iv) Let $w^2=q \\jmod{l}$, if no such $w$ exists, \r\n$t=0 \\jmod{l}$;\\\\\r\n\\jt \\jt\r\n(v) if $(x^q - x_w, \\psi_l )=1$ then \r\n$t=0 \\jmod{l}$, otherwise, set $g= numerator({\\frac {y^q - y_w} y}, \\psi_l)$, if\r\n$g \\ne 1$, $t= 2w \\jmod{l}$ otherwise \r\n$t= -2w \\jmod{l}$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition of Complex Multiplication:}\r\n$E: y^2= x^3 - x$, $\\mu: E \\rightarrow E$, $\\mu(x,y)= (-x, iy)$, \r\n$\\mu^2= [-1]$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} \r\nIf $D= \\sum_{P \\in E} n_P [P]$, $deg(D)= \\sum_P n_P$ and $sum(D)= \\sum_P n_P P$.\r\n$div(f)= \\sum_{P \\in E({\\overline K})} ord_P(f) [P] \\in Div(E)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  Let $E$ be an elliptic curve and $f$ be a function on $E$ not $0$ then \r\n(1) $f$ has finitely many poles and zeros, (2) $deg(div(f))=0$ and (3) if there are no\r\npoles or zeros, $f$ is a constant.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:}  Let $E$ be an elliptic curve and $D$ a divisor on $E$ with\r\n$deg(D)=0$ then $\\exists f$ on $E$ with $div(f)=D, sum(D)= \\infty$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Pairing:} $e_n: E[n] \\times E[n] \\rightarrow \\mu_n$.  $\\mu_n$ is the $n$th roots of\r\nunity.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nFor simplified case of elliptic curves in Weierstrauss form ($E: y^2=x^3+Ax+B$),\r\nall polynomials, $f(x,y)$, on $E$, denoted $f \\in K[E]$, \r\ncan reduced to normal form, \r\n$f(x,y)= v(x)+yw(x)$.  If\r\n$f(x,y)= v(x)+yw(x)$, ${\\overline f}= v(x)-y w(x)$ and $N(f)= f {\\overline f}$.\r\n$deg(f)= \\textnormal{max}(2 deg_x(v), 3+2deg_x(w))$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\nIf $f \\in K[E]$ then $deg(f)= deg_x(N(f))$ and $deg(f)$ has the usual properties.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nIf $r \\in K(E)$ and $P \\in E$, $\\exists u \\in K(E)$ such that (1) $u(P)=0$ and\r\n(2) if $r \\in K(E)$, $\\exists s \\in K(E): r=u^ds$.  Further, $d$ does not\r\ndepend on the choice of $u$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nFor the SWF curve, we can specify $u$ as follows: \r\n(1) For $P=(a,b) \\in E, b \\ne 0$, $u(x,y)= (x-a)$;\r\n(2) For $P=(w,0) \\in E$, $u(x,y)= y$; and\r\n(3) For $P= \\infty$, $u(x,y)= {\\frac x y}$.\r\n\\end{quote}\r\n{\\bf Definition:}\r\nFor the notation of the previous theorem, define $ord_P(r)= d$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\nLet $r \\in K(E)$, $\\sum_P ord_P(r) = 0$.  If $f \\in K[E]$ then the sum of the\r\nmultiplicities of the zeros of $f$ equals the degree of $f$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Definition:}\r\n$\\Delta \\in Div(E)$ is principal if $\\Delta= div(r)$ for some $r \\in K(E)$.  The\r\nprincipal divisors are denoted $Prin(E)$ and $Pic(E)= Div(E)/Prin(E)$.  \r\n$|\\Delta|= \\sum_{P \\in P- \\infty} |m(P)|$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\nLet $\\Delta \\in Div(E), \\exists \\tilde{\\Delta} \\in Div(E)$ with\r\n$\\Delta \\sim \\tilde{\\Delta}$ with\r\n$deg(\\Delta)=deg(\\tilde{\\Delta})$ and\r\n$|\\tilde{\\Delta}| \\le 1$.  \\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} \r\n$\\forall \\Delta \\in Div^0(E), \\exists ! P \\in E$: \r\n$\\Delta \\sim \\langle P \\rangle -\\langle \\infty \\rangle$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nLet $[n]: E \\rightarrow E$ be represented by the rational function \r\n$[n](P)=(g_n(P), h_n(P))$ then if $(n,p)=1$, \r\n${\\frac {g_n} x} (O) \\sim {\\frac 1 {n^2}}$ and\r\n${\\frac {h_n} y} (O) \\sim {\\frac 1 {n^3}}$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nLet $P, Q \\in E$ and suppose $u$ is a uniformizing parameter at $P$,\r\ndefine $T_Q(u)](R)=u(R+Q)$ then $T_Q(u)$ is the uniformizing\r\nparameter at $P-Q$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nLet $E$ be an elliptic curve with $deg(D)=0$.  $\\exists f \\in K(E): D= div(f)$ iff\r\n$sum(D)= \\infty$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nSuppose $m>n>0$ and $m, n, m-n, m+n$ are all prime to $p$, then\r\n$div(g_m-g_n)= \r\n\\langle E[m+n] \\rangle+\r\n\\langle E[m-n] \\rangle-\r\n\\langle E[m] \\rangle-\r\n\\langle E[n] \\rangle$.  \r\nIf $(n,p)=1$, $|E[n]|= n^2$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nIf $(n,p)=1$, $div(\\phi_n)= \\langle E[n] \\rangle - n^2 \\langle \\infty \\rangle$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nSuppose $r \\in K(E)$ is a non-constant function, then $r$ takes on all values\r\nincluding $\\infty$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nSuppose $f: E \\rightarrow E, K(E)$ is a non-constant then $f$ is onto.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Definition:} The \\emph{ramification index} of $F$ at $P$ is defined by\r\n$e_F(P)= ord_P(u \\circ F)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\n$ord_P(u \\circ F) = ord_{F(P)}(r) \\cdot e_F(P)$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Definition:} \r\n$F^*: Div(E) \\rightarrow Div(E)$ is \r\n$F^*( \\langle Q \\rangle)= \\sum_{F(P)=Q} e_F(P) \\langle P \\rangle$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\n$F^*$ is 1-1, $div(r \\circ F)= F^*(div(r))$ and\r\n$ e_{F_1 \\circ F_2}(P)= e_{F_1}(F_2(P)) \\cdot e_{F_2}(P)$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nSuppose $\\alpha: E \\rightarrow E$ is a non-zero endomorphism then\r\n$e_{\\alpha}(P)$ is independent of $P$.\r\n\\begin{quote}\r\n\\end{quote}\r\nFor $m \\in {\\mathbb Z}, r \\in K(E)$ with $D$ the derivative then\r\n$D(r \\circ [m])= (m \\circ D(r)) \\circ [m]$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nIf $\\varphi$ is the Frobenius homomorphism over $GF(q)$ then $e_{\\varphi}= q$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Definition:} \r\n$e_{\\alpha}=1$ means $\\alpha$ is separable.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\nIf $(m,p)=1$ then $[m]$ is separable.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nIf $(m,p)=1$ and $(n,p)=1$ then $[m]+[n] \\varphi$ is separable.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nIf $P \\in E[m]$ then $[m]^*( \\langle T \\rangle - \\langle \\infty \\rangle)$\r\nis principal.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Definition:} \r\nA rational map $F: E \\rightarrow E'$ that is a group homomorphism from\r\n$E$ into $E'$ is a \\emph{morphism}.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\nLet $T_1$ and $T_2$ be a basis for $E[m]$ then $e+m(T_1 , T_2 )$ is a primitive\r\n$m$-th root of unity.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Definition:} \r\nIf $\\alpha$ is an endomorphism then $\\alpha(E[m]) \\subseteq E[m]$\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} \r\nLet $M$ be an algebraic extension of $L$ and $A_r$ is the linear map from $M$\r\nto $M$ represented by multiplication by $r$ with respect to the basis\r\n$r_1 , \\ldots , r_n$ and $f_r(x)= det(xI-A_r)$ with constant term \r\n$c_n = (-1)^n det(A_r)$.  Define $N(r)= det(A_r)$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} \r\nSuppose $\\alpha: E \\rightarrow E'$ be an isogony $K'= \\alpha^*(K(E')) \\subseteq K(E)$.\r\nDefine $N= N_{K(E)/K'}$ then $N(r)](P)= \\prod_{\\alpha(Q)= \\alpha(P)} r(Q)^{e_{\\alpha}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} \r\nLet $r \\in K(E)$ and $D \\in Div(E)$.  Suppose $div(r)$ and $D$ have disjoint support\r\ndefine $r(D)= \\prod_{P \\in E} f(P)^{n_p}$.  For $f, g \\in K(E)$ further\r\ndefine\r\n$\\langle f, g \\rangle_P= (-1)^{mn} [{\\frac {f^n}{g^m}}](P)$ where \r\n$m= ord_P(f)$ and\r\n$n= ord_P(g)$.  $\\langle f, g \\rangle_P$ is called the local symbol of $f$ and $g$.\r\n\\\\\r\n\\\\\r\n{\\bf Weil Reciprocity Theorem:} $\\prod_{P \\in E} \\langle f, g \\rangle_P =1$.\r\n\\\\\r\n\\\\\r\n{\\bf Construction of the Weil Pairing:}\r\nFor $T \\in E[n]$,\r\n$\\exists f: div(f)= n[T]- n[\\infty]$.  Choose $T' \\in E[n^2]: nT'=T$ then \r\n$\\exists g: div(g) = \\sum_{R \\in E[n]} ([T'+R]-[R])$.  Put $f \\circ n (P)= f(nP)$.\r\nThis gives $f \\circ n(P)= g^n(P)$.  Put\r\n$e_n(S,T)= {\\frac {g(P+S)} {g(P)}} \\in \\mu_n,  S \\in E[n], P \\in E({\\overline K})$ and\r\n$e_n$ satisfies the pairing properties.\r\n\\\\\r\n\\\\\r\n{\\bf Example:}\r\nIf $E(F_7): y^2= x^3+2$ then $E(F_7)[3]= {\\mathbb Z}_3 \\oplus {\\mathbb Z}_3$.  To\r\ncompute $e_3((0,3),(5,1))$, $D_{(0,3)}= [(0,3)]-[\\infty]$ and\r\n$D_{(5,1)}= [(3,6)]-[(6,1)]$, $div(y-3)= 3 D_{(0,3)}$ and \r\n$div({\\frac {4x-y+1} {5x-y-1}})= 3 D_{(5,1)}$.\r\n$f_{(0,3)}(D_{(5,1)})= {\\frac {f_{(0,3)}(3,6)} {f_{(0,3)}(6,1)}}= \r\n{\\frac {6-3} {1-3}}= 2 \\jmod{7}$.\r\n$f_{(5,1)}(D_{(0,3)})= 4$, $e_3((0,3),(5,1))= {\\frac 4 2}= 2 \\jmod{7}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\nIf $F= {\\mathbb Q}, {\\mathbb R}, {\\mathbb C}$\r\n$E(F)= {\\mathbb Z}/m{\\mathbb Z} \\times {\\mathbb Z}/m{\\mathbb Z}$;\r\nif $F= {\\mathbb F_p}, p \\nmid m, \\exists k:$\r\n$E(F_{p^{jk}})= {\\mathbb Z}/m{\\mathbb Z} \\times {\\mathbb Z}/m{\\mathbb Z}$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Note:} \r\nIf $m[P]=O$, $m[P]-m[O]$ is a divisor of $E(F)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  Let $P, Q \\in E[m]$, \r\n$div(f_P)= m[P]=m[O]$,\r\n$div(f_Q)= m[Q]=m[O]$ then $e_m(P,Q)= \r\n{\\frac {f_P(Q+S)}{f_P(S)}}/\r\n{\\frac {f_Q(P-S)}{f_Q(-S)}}$ for $S \\in E(F)$ is bilinear.\r\n$E[m]= \\langle aP_1+bP_2 \\rangle$ and suppose.\r\n$P= a_P P_1+b_P P_2 \\rangle$, $e_m(P,Q)= \\zeta^{det\r\n\\left(\r\n\\begin{array}{cc}\r\na_P &  a_Q \\\\\r\nb_P &  b_Q \\\\\r\n\\end{array}\r\n\\right)\r\n}$ where\r\n$\\zeta= e_m(P_1,P_2)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem (for Miller's Algorithm):}  Let $E$ be an elliptic curve and\r\n$P= (x_P, y_P)$ and\r\n$Q= (x_Q, y_Q)$ are non-zero points on $E$.  Let $\\lambda$ the the slope of\r\nthe line betwween $P$ and $Q$ and define \r\n$g_{P, Q}= x-x_P$ if $\\lambda= \\infty$ and\r\n$g_{P, Q}= \r\n{\\frac {y-y_p - \\lambda(x-x_P)} {x+x_P+x_Q+\\lambda^2}} $, otherwise.  Then (a)\r\n$div(g_{P,Q})= [P]+[Q] -[P+Q]-[O]$ and\r\n(b) For $m \\ge 1$ with binary representation $[m_{n-1}, \\ldots, m_0]$ satisfies\r\n$div(f_P)= m[P]-[mP]-(m-1)[O]$ where \r\n$g_{T,T}$ and\r\n$g_{T,P}$ are defined by Miller's algorithm.\\\\\r\n{\\bf Miller's Algorithm:}\\\\\r\n\\jt 1. Set $T=P$ and $f=1$;\\\\\r\n\\jt 2. $\\textnormal{for}(i=(n-2); i \\ge 0; i--)$\\\\\r\n\\jt \\jt 3. $f= f^2 \\cdot g_{T,T}$;\\\\\r\n\\jt \\jt 4. $T= 2T$;\\\\\r\n\\jt \\jt 5. if($m_i=1$)\\\\\r\n\\jt \\jt \\jt 6. $f= f \\cdot g_{T,P}$;\\\\\r\n\\jt \\jt \\jt 7. $T= T+P$;\\\\\r\n\\jt 8. $return(f)$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}  Let \r\n$P, Q \\in E(F_q)[l]$, choose $f_P: div(f_P)= l[P]-l[Q]$ than the \\emph{Tate pairing}\r\nis $\\tau(P,Q)= {\\frac {f_P(Q+S)}{f_P(S)}}$ and the \\emph{modified Tate pairing} is\r\n$\\hat{\\tau}(P,Q)= \\tau(P, Q)^{\\frac {q-1}{l}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nLet $E$ be an elliptic curve over $F_p, m \\ge 1, p \\nmid m$, the \\emph{embedding degree}\r\nof $E$ with respect to $m$ is the smallest positive $k$ such that\r\n$E(F_{p^k})[m]= {\\mathbb Z}/m{\\mathbb Z} \\times {\\mathbb Z}/m{\\mathbb Z}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nLet $E$ be an elliptic curve over $F_p, p \\nmid m$ and suppose $E$ has an element of\r\nprime order $l \\ne p$.  The embedding degree, $k$ is one of the following:\r\n(1) $k=1$ ($l \\le {\\sqrt p}+1$);\r\n(2) $k=l$ if $p=1 \\jmod{l}$;\r\n(3) if $p \\ne 1 \\jmod{l}$, $k$ is the smallest positive integer such that\r\n$E(F_{p^k})= {\\mathbb Z}/m{\\mathbb Z} \\times {\\mathbb Z}/m{\\mathbb Z}$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf MOV Algorithm:}  Under the same conditions as the theorem:\\\\\r\n\\jt 1. Compute $N= \\#E(F_{p^k})$, $l \\mid N$;\\\\\r\n\\jt 2. Choose, at random, $T: T \\in E(F_{p^k}), T \\notin E(F_{p})$;\\\\\r\n\\jt 3. Compute $T'= (N/l)T$.  If $T'=O$, repeat step 2.\\\\\r\n\\jt 4. $lT'= O$, compute $\\alpha= e_m(P, T')$ and $\\beta= e_m(Q, T')$;\\\\\r\n\\jt 5. Solve $\\beta= \\alpha^n$ in $E(F_{p^k})$;\\\\\r\n\\jt 6. $Q=nP$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nLet $l \\ge 3$, $P \\in E[l]$, $lP=O$, $\\psi: E \\rightarrow E$.  $\\psi$ is a\r\n\\emph{distortion map} for $P$ if (a) $\\psi(nP)= n \\psi(P)$ and (b)\r\n$e_l(P, \\psi(P))$ is a primitive $l$-th root of unity.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  If $E[l]=\r\n{\\mathbb Z}/l{\\mathbb Z} \\times {\\mathbb Z}/l{\\mathbb Z}$, TFAE:\r\n(a) $P, Q$ is a basis for $E[l]$;\r\n(b) $p \\ne O$ and there is no $\\alpha: Q= \\alpha P$;\r\n(c) $e_l(P,Q)$ is a primitive $l$-th root of unity.\r\n\\\\\r\n\\\\\r\nNote: the \\emph{decision ECDLP problem} is in $NP \\cap co-NP$.  \r\nAttacks (1) Exhaustive Search - \r\nto avoid, make sure $\\#E_q=nh$, $n$ a large prime $>2^{160}$,\r\n$h$, small; (2) Pohlig-Hellman/Pollard-$\\rho$ \r\nuse Pohlig to reduce from $n= p_1^{e_1} ... p_t^{e_t}$ to\r\n$p$, since this step is easy, want $p$ large, Pollard costs $O({\\sqrt p})$\r\n[For Pollard, ``random'' function is $f(X)= X+ a_j P +b_j Q \\jmod{p}$.];\r\n(3) Isomorphism attack;\r\n(4) MOV for anomalous curves - to avoid make sure $q=p^m$ and $p \\nmid \\#E_q$; \r\n(5) Weil-Tate pairing - to avoid make sure $n \\nmid (q^k-1), k \\le C$ and that the\r\nDLP problem for $F_{q^C}$ is intractable;\r\n(6) Weil descent - to avoid, if $q=2^m$, make sure $m$ is prime.  Index calculus attack\r\nis unlikely because the lifting required from $E_q(a,b)$ to \r\n$E_{\\mathbb Q} ({\\overline a}, {\\overline b})$ is unknown and the number of points of\r\nsmall height in elliptic curves over ${\\mathbb Q}$ is small.\r\n\\\\\r\n\\\\\r\n{\\bf Lenstra Elliptic Curve Factoring Method:}\r\n\\begin{enumerate}\r\n\\item $(n,6)= 1, n \\ne m^r$.\r\n\\item Choose random $b, x_1, y_1$ between $1$ and $n$.\r\n\\item $c= {y_1}^2+{x_1}^3-bx_1 \\jmod{n}$.\r\n\\item $(n, 4b^3+27c^2)= 1$.\r\n\\item $k= lcm(1,2, \\ldots, K)$.\r\n\\item Compute $KP= ({\\frac {a_k} {{d_k}^2}}, {\\frac {b_k} {{{d_k}^3}}})$\r\n\\item $D= (d_k , n)$ If $D=1$, go to 5 and bump $K$ or go to 2 and select new curve.\r\n\\end{enumerate}\r\n\\subsection {Elliptic, Weierstrauss and Fermat} \r\n{\\bf Definition:} \r\nTwo curves $C, D$ are projectively equivalent if there is a projective\r\ntransformation $\\phi$ with $\\phi(C)=D$.\r\nEvery nonsingular cubic is equivalent to a curve which in affine coordinates is\r\n$y^2= 4 x^3-g_2x-g_3= 0$.  This is the \\emph{Weierstauss normal form.}\r\nNote: To prove show that every non-singular curve has an inflexion point (triple tangent).\r\nMap flex to $(0,0,1)$.\r\n\\\\\r\n\\\\\r\n{\\bf Elliptic Functions from Trigonometry:}\r\n$S(x)= \\int {\\frac {dx} {\\sqrt {1- x^2}}}$.\r\nLet ${\\frac {dx} {du}}= c(u)$,\r\n$s(u)^2 + c(u)^2= 1$.  $s'(u)= c(u)$, $c'(u)=-S(u)$, $s(-u)=-s(u)$ and $c(-u)=c(u)$.\r\n$s(x+y)= s(x)c(y)+s(y)c(x)$ and\r\n$c(x+y)= c(x)c(y)-s(y)s(x)$. $\\Omega: R \\rightarrow S^1$ ($S^1$ is the 1-sphere - circle) by\r\n$u \\mapsto (c(u),s(u))$ is a morphism: $\\Omega(x+y)= \\Omega (x) \\oplus \\Omega (y)$.\r\n$\\Omega$ has a non-trivial kernel $K$ since $S^1$ is compact but $R$ isn't.  \r\n$K= 2 \\pi {\\mathbb Z}$.\r\nThese functions are periodic, satisfy the given derivatives, parameterize $S^1$ under the\r\nindicated morphism and provide the integration property.\r\nBy analogy, set $F(k,v)= \\int {\\frac {dz} {\\sqrt {(1-z^2 ) (1- k^2 z^2 )}}}$ and define\r\n$sn$ by $F(k,sn(u))=u$.  \r\n$cn(u)= {\\sqrt {1 - sn^2 (u)}}$,\r\n$dn(u)= {\\sqrt {1 - k^2 sn^2 (u)}}$.  $sn, cn, dn$ are doubly periodic with\r\nperiods $\\omega_1 , \\omega_2$.  \r\n\\\\\r\n\\\\\r\n{\\bf Weierstrauss Parameterization:} $y(t)^2= x(t)^3+a x(t) + b$.\r\nLet $\\omega_1 , \\omega_2 \\in {\\mathbb C}$ and \r\n$\\Lambda= \\{ a \\omega_1 + b \\omega_2: a,b \\in {\\mathbb Z} \\}$ which\r\nis preserved under unimodular transformations,\r\n$\\Lambda'= \\lambda - \\{ {\\vec 0} \\}$.\r\n${\\mathbb C}/\\Lambda$ is an equivalence class of complex numbers equivalent\r\nto a torus.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nAny two basis of the same discrete group of an elliptic (doubly periodic)\r\nfunction are related by \\emph{unimodular} transformations.\r\nThe period module of a doubly periodic function is one of the following: (1) $0$;\r\n(2) $n \\omega, n \\in {\\mathbb Z}$;\r\n(3) $n \\omega_1+ m \\omega_2, n,m \\in {\\mathbb Z}$.  In the latter case, there is a \r\ncanonical basis $(\\omega_1 , \\omega_2 )$ with $\\tau= {\\frac {\\omega_2} {\\omega_1}}$ such that\r\n(i) $Im(\\tau) >0$, (ii) $-{\\frac 1 2} \\leq Re(\\tau) \\leq {\\frac 1 2}$, (iii) $|\\tau| \\geq 1$ and\r\n$Re(\\tau)>0$ if $|\\tau|=1$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nSuppose neither (1) or (2) hold.  Let $\\omega_1$ be the element of $M$ with smallest non zero modulus and\r\nlet $\\omega_2$ be the element of $M \\notin \\{ m \\omega_1 \\}$ with the smallest non-zero modulus.  First,\r\nif ${\\frac {\\omega_2} {\\omega_1}} \\in {\\mathbb R}, \\exists n:  n < {\\frac {\\omega_2}{\\omega_1}} < n+1$ which\r\nmeans $|n \\omega_2 - \\omega_1| < | \\omega_1|$ which is a contradiction.  We may put\r\n$\\omega= \\lambda_1 \\omega_1 + \\lambda_2 \\omega_2, \\lambda_1, \\lambda_2 \\in {\\mathbb R} $ \r\nso $\\exists m_1, m_2 \\in {\\mathbb Z}: | \\lambda_1 - m_1 | \\leq {\\frac 1 2}, | \\lambda_2 - m_2 | \\leq {\\frac 1 2}$.\r\nBut then $\\omega'= \\omega - m_1 \\omega_1 - m_2 \\omega_2 \\in M$ and\r\n$ |\\omega'| \\leq {\\frac 1 2} |\\omega_1|+ {\\frac 1 2} |\\omega_2| \\leq |\\omega_2| $.  To show (i, (ii), (iii) and\r\n(iv), pick \r\n$\\omega_1$ and\r\n$\\omega_2$ as above.  We already have, \r\n$ |\\omega_1| \\leq |\\omega_2| $,\r\n$ |\\omega_2| \\leq |\\omega_1+\\omega_2| $,\r\n$ |\\omega_2| \\leq |\\omega_1-\\omega_2| $.  \r\nIf $Im(\\tau) <0$ replace $(\\omega_1 , \\omega_2)$ with $(-\\omega_1 , \\omega_2)$.\r\nIf $Re(\\tau) = - {\\frac 1 2}$ replace $(\\omega_1 , \\omega_2)$ with $(\\omega_1 , \\omega_1+\\omega_2)$.\r\nIf $|\\tau|=1$ and $Re(\\tau) < 0$ replace $(\\omega_1 , \\omega_2)$ with $(-\\omega_2 , \\omega_1)$.\r\n\\end{quote}\r\n{\\bf Theorem:}  An elliptic function without poles is constant.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:}  If $f$ is elliptic, $\\sum_{a \\in {\\cal P}} Res(f,a) = 0$, ${\\cal P}$ is the set of \\emph{poles}.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:}  If $f$ is elliptic,  $M$ is the module of periods,\r\n$\\langle a_1 , \\ldots, a_n \\rangle$ are the zeros,\r\n$\\langle b_1 , \\ldots, b_n \\rangle$ are the poles then\r\n$\\sum_i a_i= \\sum_i b_i \\jmod{M}$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Elliptic functions of order $2$:} $\\wp(z)= z^{-2}+ a_2x^2+a_4 z^4 + \\ldots $.\r\n$\\wp(z)= {\\frac 1 {z^2}} + \\sum_{\\omega \\ne 0} {\\frac 1 {(z- \\omega)^2)}}- {\\frac 1 {\\omega)^2}}$.  If\r\n$|\\omega| \\geq 2|z|$, \r\n$|{\\frac 1 {(z- \\omega)^2)}}- {\\frac 1 {\\omega)^2}}| \\leq {\\frac {10 |z|} {|\\omega|^3}}$.\r\n$\\wp'(z)^2= 4 \\wp(z)^3 - g_2 \\wp - g_3= 4 (\\wp(z)-e_1) (\\wp(z)-e_2) (\\wp(z)-e_3) $,\r\n$e_1, e_2, e_3$ are distinct.  The equation can be solved by $z= \\int^w {\\frac {dw}\r\n{\\sqrt{4w^3 -  g_2 w - g_3}}}$.  Since $\\wp(\\omega_1 -z)= \\wp(z)$, \r\n$ \\wp'({\\frac {\\omega_1} {2}})= 0 $; similarly,\r\n$ \\wp'({\\frac {\\omega_2} {2}})= 0 $ and\r\n$ \\wp'({\\frac {\\omega_1+\\omega_2} {2}})= 0 $. So\r\n$e_1=  {\\frac {\\omega_1} {2}}$,\r\n$e_2= {\\frac {\\omega_2} {2}}$, and\r\n$e_3= {\\frac {\\omega_1+\\omega_2} {2}}$.  Put $\\lambda( \\tau )= {\\frac {e_3 - e_2} {e_1- e_2}}$.\r\n$\\lambda$ is the quotient of two analytic functions in the upper half-plane.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\nIf $\\lambda({\\frac {a \\tau + b} {c \\tau + d}})= \\lambda(\\tau)$, the linear transformation is\r\nan \\emph{automorphism} of $\\wp$.  The automorphisms\r\n$\\lambda({\\frac {a \\tau + b} {c \\tau + d}})= \\lambda(\\tau)$ for\r\n$\r\n\\left(\r\n\\begin{array}{cc}\r\na & b\\\\\r\nc & d\\\\\r\n\\end{array}\r\n\\right)=\r\n\\left(\r\n\\begin{array}{cc}\r\n1 & 0\\\\\r\n0 & 1\\\\\r\n\\end{array}\r\n\\right) \\jmod{2}\r\n$ form the \\emph{modular group}.\r\n$\\lambda(\\tau + 1) = {\\frac {\\lambda(\\tau)} {\\lambda(\\tau) -1}}$,\r\n$\\lambda({\\frac 1 \\tau}) = 1- \\lambda(\\tau)$.\r\n$\\wp(z, \\Lambda)= {\\frac 1 {z^2}}+ \\sum_{\\omega \\in \\Lambda'} ({\\frac 1 {(z-\\omega)^2}} - \r\n{\\frac 1 {\\omega^2}})$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  \r\n$\\wp(z, \\Lambda)$ converges uniformly for ${\\mathbb C}/\\Lambda$, $\\wp(z)= \\wp(-z)$ and\r\n$\\wp$ is doubly periodic.  As $z$ ranges over a fundamental region, $\\wp$ takes on every\r\ncomplex value twice.\r\n$\\wp(z, \\Lambda)- {\\frac 1 {z^2}}= \r\n\\sum_{\\omega \\in \\Lambda'} ({\\frac 1 {(z-\\omega)^2}} - {\\frac 1 {\\omega^2}})=\r\n\\sum_{n=1}^{\\infty} (n+1) z^n\r\n(\\sum_{\\omega \\in \\Lambda'} \r\n|{\\frac 1 {\\omega^{n+2}}}|)$. The final summation is an Eisenstein series of weight\r\n$n+2$, denoted $G_{n+2}$.\r\n$\\wp(z)= {\\frac 1 {z^2}} +3G_4 z^2+ 5G_6z^4 + \\ldots$.\r\n$P(z)= (\\wp'(z), \\wp(z))$ is a point on $y^2=4x^3-60 G_4 x -140 G_6$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Reimann surfaces:}\r\nGlue two copies of $C$ to get ${\\sqrt z}$.  For $N \\in {\\mathbb Z}, N>0$ define\r\n$\\Gamma_0 (N) \\subseteq SL_2$ with $N|c$.\r\n$\\Gamma_0 (N)$ acts on $H$ and $H/\r\n\\Gamma_0 (N) \\equiv X_0 (N) \\backslash K$ where $K$ are the cusps.  \r\n$X_0 (N)$ is compact and\r\nthe members are the modular functions of level $N$.\r\n\\\\\r\n\\\\\r\n{\\bf Semi-Stable:} For all primes $l>3$, $l|Disc$ and only two of the roots are equal \r\n$\\jmod{l}$.\r\nFrey curve: $C^F_{a,b} \r\n{\\buildrel\\rm def\\over =} \\; \r\ny^2= x (x-a^p) (x-b^p)$.  \r\nIf $b$ is even and $a = -1 \\jmod{4}$.  Frey curve is semi-stable.\r\n\\\\\r\n\\\\ \r\n{\\bf Definitions:}\r\nDenote $E_{A,B,C,D}({\\mathbb Q}) {\\buildrel\\rm def\\over =} \\; \r\ny^2= Ax^3 + B x^2 + CX +D, A, B, C, D \\in {\\mathbb Q}$.\r\nDefine $b_p$ to be the number of solutions to $E_{A,B,C,D}({\\mathbb Q})= 0$. $E$ \r\nis \\emph{modular} if\r\n$\\exists$ eigenfunction, $f(z)= \\sum_n a_n e^{2 \\pi i n z}$. $E/{\\mathbb Q}$\r\nis modular if $\\exists f$ and eigenfunction with $a_p=p+1-b_p$ for all but finitely many\r\n$p$.\r\n\\\\\r\n\\\\\r\n{\\bf Taniyama-Shimura Conjecture:}  Every elliptic curve is modular.\r\nAlternate T-S: $E(A,B,C,D)$.  $\\exists$ modular functions $f(z), g(z)$ such that\r\n$g(z)^2= Af(z)^3+Bf(z)^2+C f(z) +D$.\r\n\\begin{quote}\r\n\\end{quote}\r\nDefine the \\emph{conductor}\r\n$Cond_{a,b,c}= \\prod_{p|abc} p$.  Two elliptic curves are isomorphic\r\niff their \\emph{$j$-invariants} are equal. The $j$-invariant of $C^F_{a,b} =\r\n2^8 {\\frac {(a^{2p} +b^{2p} +a^p b^p)^3} {a^{2p} b^{2p} c^{2p}}}$.\r\nIf $F({\\frac {az+b} {cz+d}})= (cz+d)^2 F(z)$, $F$ is a modular form of weight $2$.\r\n\\\\\r\n\\\\\r\n{\\bf Proof of Fermat's Last Theorem:}  Suppose it's false and that $a^p + b^p= c^p$ is\r\na counterexample.  Let \r\n$C^F_{a,b}$ be the Frey curve.  $Disc(C^F_{a,b})= a^{2p} b^{2p}c^{2p}$ so\r\n$C^F_{a,b}$ is semi-stable.\r\nWiles proved every semi-stable elliptic curve is modular so\r\n$C^F_{a,b}$ is modular and has a cusp form of weight $2$ and level $N$ where $N$\r\nis the conductor.\r\nIf $l$ is an odd prime and $l|N$,\r\nby Serre, we can obtain a new $F$ of\r\nweight 2 of level $N/l$.  By induction, keep doing this until $N=2$.  The dimension\r\nof the space of cusps is equal to the genus of compact Reimann surface $X_0(N)$.  \r\nBut $Genus(X_0(2))= 0$, so there is no such cusp forms of weight $2$, level $2$.\r\nThis contradiction establishes the theorem.  Incidentially, the restriction of semi-stability\r\nin Wiles Theorem has been removed.\r\n", "meta": {"hexsha": "ef1edcbfb8fc24dc37989504c861527c7d1412d7", "size": 67568, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "science/math6.tex", "max_stars_repo_name": "jlmucb/class_notes", "max_stars_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "science/math6.tex", "max_issues_repo_name": "jlmucb/class_notes", "max_issues_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "science/math6.tex", "max_forks_repo_name": "jlmucb/class_notes", "max_forks_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.5922580645, "max_line_length": 115, "alphanum_fraction": 0.5826426711, "num_tokens": 28491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7417857616285858}}
{"text": "\\lab{Applications}{Leontief Input-Output Models}{Leontieff Input-Output Models}\n\\label{Leontief}\n\n\\objective{Explain the basics of input-output models, and apply them to analyze a state economy.}\n\nOne of the primary applications of linear algebra is modeling interactions between a large number of variables in a concise way.\nWe can use it to simplify the analysis of very complicated interactions in a variety of settings.\n\nFor example, in economics, one might be interested in how one the inputs of one sector of an economy are reliant upon the outputs of another economy.\nTo build a car, you need refined steel, plastic, and glass (among other materials).\nThese are all outputs of other sectors of the economy.\nIf there is an increase in car production there will necessarily be increases in production in other sectors of the economy like steel, plastic, and glass.\nThis type of interaction can be described using what is called a \\emph{Leontief Input-Output model}, or just an Input-Output model.\n\nConsider a simple economy divided up into sectors representing agriculture, textiles, and construction.\nGiven sufficient data, we can estimate how much of the output from one economy is used as an input to another.\nAn array representing the required inputs in this simple economy is shown in \\ref{IOCoefTable}.\nThis is called a consumption matrix.\nIt can be especially useful when determining the short term impacts of a given change in the economy.\nDirectly, its columns represent the inputs required to produce one additional unit of output.\nFor example, to produce one extra unit of agriculture output we need to input about .4 units of agriculture, .04 units of textiles and .08 units of construction.\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|c|c|c|c|}\n\\hline\n& Agriculture & Textiles & Construction \\\\ \\hline\nAgriculture & .4167 & .5357 & .25 \\\\ \\hline\nTextiles & .0417 & .0893 & .1667 \\\\ \\hline\nConstruction & .0833 & .0714 & .0417 \\\\ \\hline\n\\end{tabular}\n\\caption{Input Output Coefficients.\nThe columns represent the amount of each product needed to produce one additional unit of output.}\n\\label{IOCoefTable}\n\\end{center}\n\\end{table}\n\nThis sort of matrix can easily be computed from a table of inputs and outputs like the one shown in Table \\ref{IORawTable}.\nA matrix of input and output values like the one shown in Table \\ref{IORawTable} is called an exchange matrix.\nIf we divide each column by the output of the corresponding industry we can obtain the coefficient matrix (consumption matrix).\nWe can do this in Python as follows, and we obtain the coefficients in Table \\ref{IOCoefTable}.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> IO = np.array([[250., 150., 30., 600.], [25., 25., 20., 280.], [50., 20., 5., 120.]])\n>>> IOCoeff = IO[:,:3] / IO[:,3]\n\\end{lstlisting}\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|c|c|c|c|c|}\n\\hline\n& Agriculture & Textiles & Construction & Total Output \\\\ \\hline\nAgriculture & 250 & 150 & 30 & 600 \\\\ \\hline\nTextiles & 25 & 25 & 20 & 280 \\\\ \\hline\nConstruction & 50 & 20 & 5 & 120 \\\\ \\hline\nTotal Input & 325 & 195 & 55 & \\\\ \\hline\n\\end{tabular}\n\\caption{Raw Input Output Data.\nColumns represent inputs to an industry, and rows represent outputs.\nNotice that not all the total output is used as input for the economy itself.}\n\\label{IORawTable}\n\\end{center}\n\\end{table}\n\nWe will now consider the sorts of things these matrices tell us.\nBy way of example, we will consider the total output needed to produce one extra unit of agriculture.\nThis certainly costs one unit of agriculture without accounting for the inputs required, but in order to produce one unit of agriculture, we also need inputs of .4167 units of agriculture, .0417 units of textiles, and .0833 units of construction.\nWe also need the inputs necessary to produce those inputs, and the inputs necessary to produce the inputs to the inputs for the inputs, etc.\nLetting $d$ be the $3\\times 1$ array of needed goods and $C$ be the coefficient matrix, the total cost of producing the outputs in $d$ will be\n\n\\[ d + C d + C^2 d + C^3 d + \\dots = \\left( \\sum_{n=0}^{\\infty} C^n \\right) d = \\left( I - C \\right)^{-1} d\\]\n\nThis is just a geometric series in $C$ (recall that $C^0$ is just the identity matrix).\nThe last formula for evaluating the geometric series can be derived in the same way as the formula for a geometric series of complex numbers.\nIt can be shown that such a geometric matrix series converges if and only if the absolute value of each of the eigenvalues of the matrix is strictly less than one.\nThis is a constraint that will be built into any real system, and the non-convergence of such a series would indicate a problem with the data.\n\nSince the overall effect of the increase in demand from inputs to inputs to inputs, etc. may not happen immediately, it may often be helpful to just evaluate the first two terms in this summation.\n\n\\begin{problem}\nWhat is the cost of producing an additional 50\\% more units of construction?\nCalculate the answer in two different ways.\nFor the first way, you will approximate the answer by using the geometric series.\nWrite a function named \\li{geomSeries} that takes an $n \\times n$ array $C$ and an $n$-dimensional\nvector $d$ as inputs, as well as an integer $m$, and returns $(\\sum_{i=0}^m C^i)d$.\nYou can then use this function to approximate the solution for $m=5$.\nAlso calculate the exact answer by evaluating $(I-C)^{-1}d$.\nNotice how a distortion in the market for construction can drastically affect the need for other goods as well.\n\\end{problem}\n\nIf $X$ represents the total output of the economy, we can represent the ``net'' output to consumers $D$ (demand) by the following equation:\n\\[ D = X - C X \\]\nIn other words, the amount of output used for consumption is the total output minus the portion that is reused as input for the economy itself.\n\nThis agrees with our geometric series since the total output of the economy must be the total output required to produce everything that isn't reused, i.e.\n\\[ X = \\left( \\sum_{n=0}^{\\infty} C^n \\right) D = \\left( I - C \\right)^{-1} D \\]\nWhich is equivalent to $ D = X - C X $.\n\n\\begin{problem}\nWhat are the demand levels for the three product economy?\n\\end{problem}\n\n\\begin{problem}\nA city is trying to determine how to allocate funds for the celebration of the centennial anniversary of its founding.\nIt is expecting to take in \\$100000 in space (lodging, etc.) \\$100000 in consumable goods (food, and other retail items), and \\$40000 in services.\nGiven that the coefficient matrix for space, consumable goods, and services is\n\\[ \\begin{bmatrix}\n.2 & .3 & .3 \\\\\n.1 & .2 & .3 \\\\\n.2 & .2 & .2 \\\\\n\\end{bmatrix} \\]\nEstimate the amount the city should be prepared to produce of each good.\n\\end{problem}\n\n\\section*{Importing CSV Data with Missing Values}\nBefore we get to the next problem, we review some important skills concerning reading and writing data with CSV files.\nRecall that a CSV file, or a `Comma Separated Values' file, contains tabular data with the rows on separate lines\nof the file, and the columns separated by some delimiter character, such as a comma or a white space. This is a\nubiquitous format for storing and transferring data, and Python has good support for it. We will use the \\li{csv}\nmodule to examine the contents of the file \\li{missing_data.txt}.\n\n\\begin{lstlisting}\n>>> import csv\n>>> with open(\"missing_data.txt\", \"r\") as csvfile:\n>>>     myReader = csv.reader(csvfile, delimiter=';')\n>>>     for row in myReader:\n>>>         print row\n['1.0', '2.2', '-3.0', '???']\n['0.0', '2.1', '???', '5.1']\n['0.4', '2.3', '-2.8', '4.8']\n['0.3', '???', '-3.1', '5.0']\n\\end{lstlisting}\n\nNotice the \\li{with ... as ...} block. This is the preferred way to open and read from files, as it takes care of\nclosing the file once you exit the code block. We next created a \\li{csv.reader} object around\nthe file, and specified the delimiter character to be a semi-colon. Then we iterated through the rows of our reader\nand printed the contents.\n\nNotice the entries that consist of three question marks. This indicates missing data. Such situations arise frequently\nin real life, and we need to know ways to cope with imperfect or incomplete datasets. NumPy provides a very convenient\nway to import homogeneous data from CSV files, even with missing data. We will use the \\li{np.genfromtxt} function to\nextract the data and fill in the missing values. In this example, we will set the missing value in the second column to\n2.2, the missing value in the third column to -3.0, and the missing value in the fourth column to 4.9.\n\n\\begin{lstlisting}\n>>> data = np.genfromtxt(\"missing_data.txt\", delimiter=';',\n                         missing_values = ['???'],\n                         filling_values = {1:2.2, 2:-3.0, 3:4.9})\n>>> data\narray([[ 1. ,  2.2, -3. ,  4.9],\n       [ 0. ,  2.1, -3. ,  5.1],\n       [ 0.4,  2.3, -2.8,  4.8],\n       [ 0.3,  2.2, -3.1,  5. ]])\n\\end{lstlisting}\n\nWe now have a NumPy array containing our filled-in data, and we can continue with whatever computations we desire. Notice\nthat we still needed to specify the delimiter character. The \\li{missing_values} argument is a list of strings that\ndesignate missing values, and the \\li{filling_values} argument is a dictionary that maps the index of a column to the\nvalue used to replace all the missing values in that column.\n% The value of a \\li{None} key in this dictionary will be used as a default fill value, except where you specify.\n% Except the above statement doesn't seem to be true!!!\nIf you want to replace all missing values with the same\nfilling value, the \\li{filling_values} argument can be set to this single filling value (if the desired filling value\nhappens to be 0, you must enclose it in quotes, i.e. \\li{filling_values = '0'}).\n\nIf for some reason we want to omit certain rows from the beginning or end of the CSV file, we can use the \\li{skip_header} or \\li{skip_footer}\narguments, which are integers representing the number of lines at the beginning or end of the file to skip, respectively.\nIf we want to extract only certain columns from the CSV file, we can use the \\li{usecols} argument, which is a list of\nthe column indices that we want to extract. In this next example, we omit the first row and the first column.\n\n\\begin{lstlisting}\n>>> data = np.genfromtxt(\"missing_data.txt\", delimiter=';',\n                         missing_values = ['???'],\n                         filling_values = {1:2.2, 2:-3.0, 3:4.9},\n                         skip_header = 1,\n                         usecols = (1,2,3))\n>>> data\narray([[ 2.1, -3. ,  5.1],\n       [ 2.3, -2.8,  4.8],\n       [ 2.2, -3.1,  5. ]])\n\n\\end{lstlisting}\n\n\\begin{problem}\nThe file \\li{io2002table.txt} contains the raw input output data for the state of Washington in the year 2002.\nThe last column is the output vector. This is a CSV file with a tab delimiter, so you will set to set your\ndelimiter to \\li{'\\\\t'}. The top row contains the names of each of the columns, and thus should be omitted when\nyou import the data. Similarly, the first column contains labels for the rows, and should be omitted. Finally,\nthere are some missing values in this file, and we assume that they are missing because there is not interaction\nbetween the two corresponding sectors of the economy. Thus, set all missing values to 0. Import the data\nto a NumPy array, and calculate the IO coefficient matrix and the demand vector.\n\nNext, find the output vector if the demand for construction increases by ten percent.\nNote that column 8 of the original CSV file corresponds to construction.\nThis will require increasing the correct entry of the initial\ndemand vector by ten percent and using \\li{linalg.solve()} to find the new output vector.\n\\end{problem}\n\nThis method can be used to model economies of almost any scale.\nOne of the primary limitations is that this model assumes that production varies linearly in its inputs, which may not be realistic.\n", "meta": {"hexsha": "961a6f5e0a12cf5e3a78b8b6076f343ea703e636", "size": 11943, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/Leontief/Leontief.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Labs/Leontief/Leontief.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/Leontief/Leontief.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 59.1237623762, "max_line_length": 246, "alphanum_fraction": 0.7333165871, "num_tokens": 3062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7417857516195431}}
{"text": "%\n% OK\n%\n% setting up at Aug. third, 2009\n% finished at Aug 5th, 2009\n% seems to be OK\n%\n%\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\chapter{Introduction to delta function}\n\\label{sec:delta_function}\n\nAs what we can see, in the discussion of quantum mechanics or even the\nquantum chemistry, we always meet the situation that the delta\nfunction has to be used (for example, the normalization of free\nparticle wave function, the discussion of position and momentum\noperator in \\ref{sec:PRAMR_in_position_representation} etc. For the\ncase of the continuous basis functions, the delta function is\nfrequently used). Hence in this part, we are going to give some\nmathematical introduction for the delta function.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Definition of delta function}\n\\label{sec:definition_delta_function}\n%\n%\n%\n%\nThe delta function can be considered as some ``peculiar'' function\nwhich has two features below:\n\\begin{equation}\n\\label{DELTAeq:1}\n\\delta (x) = \\begin{cases}\n    \\infty & x = 0 \\\\\n    0 & x \\neq 0\n  \\end{cases}\n\\end{equation}\n\n\\begin{equation}\n\\label{DELTAeq:2}\n \\int_{-\\infty}^{+\\infty}\\delta (x)dx =\n\\int_{-\\epsilon}^{+\\epsilon}\\delta (x)dx = 1\n\\end{equation}\nHere $(-\\epsilon, \\epsilon)$ is some ``small enough'' open interval\naround the $0$. The (\\ref{DELTAeq:1}) and (\\ref{DELTAeq:2}) are also\nthe definition for the delta function, which indicates that the\ndelta function is infinity at $0$, but quickly tends to $0$ as is\napart from the $0$ point.\n\nNow let's give some examples. Firstly, consider the function below:\n\\begin{equation}\\label{}\n\\Psi_{n}(x) = \\frac{\\sin nx}{\\pi x} \\quad \\text{$n$ is some natural\nnumber }\n\\end{equation}\nFirstly, we can prove that:\n\\begin{align}\\label{}\n\\lim_{x \\rightarrow 0}\\Psi_{n}(x) = \\lim_{x \\rightarrow 0}\\frac{\\sin\nnx}{\\pi x} = \\lim_{x \\rightarrow 0}\\frac{\\sin nx}{n x}\\frac{n}{\\pi}\n= \\frac{n}{\\pi}\n\\end{align}\nSo we can think that $\\Psi_{n}(0) = \\frac{n}{\\pi}$. Here as $n\n\\rightarrow +\\infty$, $\\Psi_{\\infty}(0) \\rightarrow +\\infty$. Hence\nthe (\\ref{DELTAeq:1}) is satisfied.\n\nSecondly, from the improper integral theory, we can know that:\n\\begin{equation}\\label{}\n\\int_{0}^{+\\infty}\\frac{\\sin nx}{x}dx = \\frac{\\pi}{2}\n\\end{equation}\nHence we have the integral as:\n\\begin{align}\\label{}\n\\int_{-\\infty}^{+\\infty}\\frac{\\sin nx}{\\pi x}dx &=\n2\\frac{1}{\\pi}\\int_{0}^{+\\infty}\\frac{\\sin nx}{x}dx \\quad\n \\text{here the $\\Psi_{n}(x)$ is even function}\\nonumber \\\\\n&=2\\frac{1}{\\pi}\\times\\frac{\\pi}{2} \\nonumber \\\\\n&=1\n\\end{align}\nSo the (\\ref{DELTAeq:2}) is satisfied. Thus we can have\n$\\Psi_{\\infty}(x) = \\delta(x)$.\n\nFrom the definition of $\\Psi_{n}(x)$, we can even prove that the\nfunction below is also the delta function:\n\\begin{equation}\\label{}\n\\Phi(x) = \\frac{1}{2\\pi}\\int_{-\\infty}^{+\\infty} e^{ikx}dk\n\\end{equation}\n\nThis function is very important in discussing the property related\nto plane wave functions. Firstly, as $x = 0$, it's easy to see tat\nthe $\\Phi(0) = \\frac{1}{2\\pi}\\int_{-\\infty}^{+\\infty} dk \\Rightarrow\n\\infty$, so the (\\ref{DELTAeq:1}) is satisfied.\n\nAs for the (\\ref{DELTAeq:2}) since we have (suggest that $a$ is some\nnatural number):\n\\begin{align}\\label{}\n\\Phi_{a}(x) = \\frac{1}{2\\pi}\\int_{-a}^{+a} e^{ikx}dk &=\n\\frac{1}{i2x\\pi}e^{ikx}\\Big|^{a}_{-a} \\nonumber \\\\\n&=\\frac{1}{i2x\\pi}2i\\sin ax \\quad \\cos(a) = \\cos(-a)\\nonumber \\\\\n&=\\frac{\\sin ax}{x\\pi}\n\\end{align}\nHence the integral for the $\\Phi(x)$ in the whole real space has\nbeen resorted to the $\\Psi_{a\\rightarrow \\infty}(x)$; so we have:\n\\begin{equation}\\label{}\n\\Phi(x) = \\delta(x)\n\\end{equation}\n\nFinally, let's consider the Gauss distribution function:\n\\begin{equation}\\label{}\n\\Omega_{\\sigma}(x) =\n\\frac{1}{\\sqrt{2\\pi\\sigma}}e^{-\\frac{x^{2}}{2\\sigma}}\n\\end{equation}\n\nFirstly, we can see that:\n\\begin{align}\\label{}\n\\Omega_{\\sigma}(0) &= \\frac{1}{\\sqrt{2\\pi\\sigma}}\\times 1 \\quad\n\\underrightarrow{\\sigma \\rightarrow 0} \\nonumber\n\\\\\n\\Omega_{\\sigma \\rightarrow 0 }(0) &= \\infty\n\\end{align}\n\nOn the other hand, since from the improper integral theory, we have:\n\\begin{equation}\\label{DELTAeq:20}\n\\int_{0}^{+\\infty}e^{-x^{2}}dx = \\frac{\\sqrt{\\pi}}{2}\n\\end{equation}\nThen we have the integral for the $\\Omega_{\\sigma}(x)$ as:\n\\begin{align}\\label{}\n\\int_{-\\infty}^{+\\infty}\n\\frac{1}{\\sqrt{2\\pi\\sigma}}e^{-\\frac{x^{2}}{2\\sigma}} dx &=\n\\frac{1}{\\sqrt{2\\pi\\sigma}}\\int_{-\\infty}^{+\\infty}\ne^{-\\frac{x^{2}}{2\\sigma}} dx \\nonumber \\\\\n&= \\frac{2}{\\sqrt{2\\pi\\sigma}}\\int_{0}^{+\\infty}\\sqrt{2\\sigma}\ne^{-(\\frac{x}{\\sqrt{2\\sigma}})^{2}} d\\frac{x}{\\sqrt{2\\sigma}} \\quad\n\\text{$\\Omega_{\\sigma}(x)$ is even} \\nonumber \\\\\n&=\\frac{2}{\\sqrt{\\pi}}\\times\\frac{\\sqrt{\\pi}}{2} \\quad\n\\text{From the \\ref{DELTAeq:20}}\\nonumber \\\\\n&= 1\n\\end{align}\nHence we have $\\Omega_{0}(x) = \\delta(x)$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Characters of delta function}\n\\label{sec:character_delta_function}\n%\n%\n%\n%\nIn this section let's state some characters of delta function.\n\n\\begin{theorem}\n$\\delta(x)$ is some even function: $\\delta(x) = \\delta(-x)$\n\\end{theorem}\n\n\\begin{proof}\nthe proof is straightforward. For (\\ref{DELTAeq:1}), the\n$\\delta(-x)$ is naturally satisfied, and for the integral in the\n(\\ref{DELTAeq:2}) we have:\n\\begin{equation}\\label{}\n\\int_{-\\infty}^{+\\infty}\\delta(-x)dx =\n-\\int_{-\\infty}^{+\\infty}\\delta(-x)d(-x) =\n\\int_{-\\infty}^{+\\infty}\\delta(t)dt = 1\n\\end{equation}\nHence  $\\delta(x) = \\delta(-x)$. \\qedhere\n\\end{proof}\n\n\\begin{theorem}\n$\\delta(ax) = \\frac{1}{|a|}\\delta(x)$\n\\end{theorem}\n\n\\begin{proof}\nFirstly suggest that $a>0$, then:\n\\begin{equation}\\label{DELTAeq:3}\n\\begin{split}\n  \\int_{-\\infty}^{+\\infty}\\delta(ax)dx &=\n  \\frac{1}{a}\\int_{-\\infty}^{+\\infty}\\delta(ax)d(ax) \\\\\n    &= \\frac{1}{a}\\delta(x)\n\\end{split}\n\\end{equation}\n\nFor the $a < 0$ (in this case, if we simply repeat the progress in\n\\ref{DELTAeq:3}; the upper limit and the lower limit in integral\nshould change), since we have $\\delta(ax) = \\delta(-ax)$; then we\ncan replace the $a$ with $|a|$ to repeat the demonstration in\n(\\ref{DELTAeq:3}). So finally we can get the conclusion. \\qedhere\n\\end{proof}\n\n\\begin{theorem}\n\\label{DELTA:4}\n$\\int_{-\\infty}^{+\\infty}f(x)\\delta(x)dx = f(0)$.\n\\end{theorem}\n\n\\begin{proof}\n\\begin{equation}\\label{}\n\\begin{split}\n  \\int_{-\\infty}^{+\\infty}f(x)\\delta(x)dx &=\n  \\int_{-\\epsilon}^{+\\epsilon}f(x)\\delta(x)dx \\\\\n    &= f(0)\\int_{-\\epsilon}^{+\\epsilon}\\delta(x)dx \\\\\n    &= f(0)\n\\end{split}\n\\end{equation} \\qedhere\n\\end{proof}\n\nThe theorem (\\ref{DELTA:4}) is some important expression for delta\nfunction. Now consider the delta function $\\delta (x - x^{'})$,\nwhere $x^{'}$ is some arbitrary number; it can be easily understood\nthat the (\\ref{DELTAeq:1}) and (\\ref{DELTAeq:2}) are converted as:\n\\begin{equation}\n\\label{DELTAeq:5} \\delta (x - x^{'}) = \\begin{cases}\n    \\infty & x = x^{'} \\\\\n    0 & x \\neq x^{'}\n  \\end{cases}\n\\end{equation}\n\n\\begin{equation}\n\\label{DELTAeq:6}\n \\int_{-\\infty}^{+\\infty}\\delta (x - x^{'})dx =\n\\int_{-\\epsilon}^{+\\epsilon}\\delta (x - x^{'})dx = 1\n\\end{equation}\nThe (\\ref{DELTAeq:1}) and (\\ref{DELTAeq:2}) can be considered as the\nspecial case while $x^{'} = 0$. Through this expansion, by using the\ntheorem (\\ref{DELTA:4}) we can prove that the relation below is\ntrue:\n\\begin{theorem}\n\\begin{equation}\\label{DELTAeq:7}\n\\int_{-\\infty}^{+\\infty}f(x)\\delta(x - x^{'})dx =\n\\int_{-\\infty}^{+\\infty}f(x^{'})\\delta(x - x^{'})dx^{'} =f(x)\n\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\nFor the first equation in the (\\ref{DELTAeq:7}), we can directly use\nthe even function character to prove it. For the second equation in\n(\\ref{DELTAeq:7}), we have:\n\\begin{equation}\\label{}\n\\begin{split}\n  \\int_{-\\infty}^{+\\infty}f(x)\\delta(x - x^{'})dx &=\n   \\int_{-\\infty}^{+\\infty}f(t+x^{'})\\delta(t)dt\n   \\quad t = x - x^{'}\\\\\n    &= f(t+x^{'})\\Big|_{t=0} \\quad \\text{From theorem \\ref{DELTA:4}}\\\\\n    &= f(x^{'})\n\\end{split}\n\\end{equation}\n \\qedhere\n\\end{proof}\n\n\\begin{theorem}\n$\\delta(x) = \\delta^{*}(x)$\n\\end{theorem}\n\n\\begin{proof}\nSuggest that we have some arbitrary real function of $f(x)$,\n\\begin{equation}\\label{}\n\\begin{split}\n  \\left[\\int_{-\\infty}^{+\\infty}f(x)\\delta(x)dx\\right]^{*} &=\n   \\int_{-\\infty}^{+\\infty}f(x)\\delta^{*}(x)dx \\\\\n    &=f^{*}(0) = f(0) \\\\\n    &= \\int_{-\\infty}^{+\\infty}f(x)\\delta(x)dx \\Rightarrow \\\\\n    &= \\int_{-\\infty}^{+\\infty}f(x)\n    \\Big(\\delta(x)-\\delta^{*}(x)\\Big)dx = 0\n\\end{split}\n\\end{equation}\nHence we have $\\delta(x) = \\delta^{*}(x)$. \\qedhere\n\\end{proof}\n\n\\begin{theorem}\n$\\int_{-\\infty}^{+\\infty}\\delta(x - x^{'}) \\delta(x - x^{''})dx =\n\\delta(x^{'} - x^{''})$. Here $x^{'}$ and $x^{''}$ are both of\narbitrary real number.\n\\end{theorem}\n\n\\begin{proof}\nFrom  (\\ref{DELTAeq:7}), we set the $f(x) = \\delta(x)$ so according\nto the (\\ref{DELTAeq:7}):\n\\begin{equation}\\label{}\n\\begin{split}\n  \\int_{-\\infty}^{+\\infty}f(x- x^{''})\\delta(x - x^{'})dx\n  &= f(x- x^{''})\\Big|_{x =x^{'}} \\\\\n    &= f(x^{'}- x^{''})\n\\end{split}\n\\end{equation}\n\\qedhere\n\\end{proof}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Example to use delta function:\nthe normalization of plane wave functions}\n\\label{sec:normalization_delta_function}\n%\n%\n%\n%\nNow by using the delta function let's solve some important problem\nin quantum mechanics: how to normalize the plane wave function?\n\nAccording to the (\\ref{BASICeq:14}), the plane wave function can be\nexpressed as:\n\\begin{equation}\\label{}\n\\Psi_{p}(x) = e^{\\frac{ipx}{\\hbar}}\n\\end{equation}\nActually it's the eigen state for the $\\hat{p}$:\n\\begin{equation}\\label{}\n\\hat{p}\\Psi_{p}(x) = p\\Psi_{p}(x)\n\\end{equation}\n\nNow let's go to see how to normalize this function:\n\\begin{equation}\\label{}\n\\begin{split}\n  \\langle \\Psi_{p}(x^{'})|\\Psi_{p}(x)\\rangle\n  =\\int_{-\\infty}^{+\\infty}\\Psi^{*}(x')\\Psi(x)dp\n  &= \\int_{-\\infty}^{+\\infty} e^{\\frac{ip(x-x^{'})}{\\hbar}}dp \\\\\n  &= \\hbar\\int_{-\\infty}^{+\\infty} e^{\\frac{ip(x-x^{'})}{\\hbar}}\n  d\\left(\\frac{p}{\\hbar}\\right) \\\\\n  &= 2\\pi\\hbar\\delta(x-x^{'})\n\\end{split}\n\\end{equation}\n\nHence if we integrate over all the $x$:\n\\begin{equation}\\label{}\n\\begin{split}\n  \\int_{-\\infty}^{+\\infty}\n  \\langle \\Psi_{p}(x^{'})|\\Psi_{p}(x)\\rangle dx\n  &= \\int_{-\\infty}^{+\\infty} 2\\pi\\hbar\\delta(x-x^{'}) dx \\\\\n    &= 2\\pi\\hbar\n\\end{split}\n\\end{equation}\n\nThus finally we can express the plane wave function as:\n\\begin{equation}\\label{}\n\\Psi_{p}(x) = \\frac{1}{\\sqrt{2\\pi\\hbar}}e^{\\frac{ipx}{\\hbar}}\n\\end{equation}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../main\"\n%%% End:\n", "meta": {"hexsha": "f59a2efb728503812352457f1a677c81fa0b94d5", "size": 10626, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "algorithm/math/delta.tex", "max_stars_repo_name": "murfreesboro/fenglai-note", "max_stars_repo_head_hexsha": "7bdf943f681e54948cd68775a31e4c93a53a13f8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-16T07:23:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-16T07:23:48.000Z", "max_issues_repo_path": "algorithm/math/delta.tex", "max_issues_repo_name": "murfreesboro/fenglai-note", "max_issues_repo_head_hexsha": "7bdf943f681e54948cd68775a31e4c93a53a13f8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "algorithm/math/delta.tex", "max_forks_repo_name": "murfreesboro/fenglai-note", "max_forks_repo_head_hexsha": "7bdf943f681e54948cd68775a31e4c93a53a13f8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.8895348837, "max_line_length": 79, "alphanum_fraction": 0.6207415773, "num_tokens": 3777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.8705972818382005, "lm_q1q2_score": 0.7417077969205761}}
{"text": "\\chapter{Eigenfunctions of CT systems}\nTo summarize the course so far given an input signal $x(t)$ and a LTI system described (equivalently) by a linear, constant coefficient differential equation, impulse response, or a block diagram, we can determine the output using convolution. This is referred to as \\emph{time-domain} analysis.\n\nThe advantages of this approach are that the analysis is straightforward (if cumbersome) and it applies to all LTI systems, stable or otherwise. Time-domain representations of signals are also intuitive given their direct application in physical systems.\n\nThere are also some disadvantages. First, time-domain analysis does not scale well to larger systems since analysis with block diagram decompositions requires convolution, and in the case of the feedback motif dealing with inverse systems or de-convolution. Second, it is difficult to design an impulse responses for a given purpose. Finally implementing a system directly from an impulse response is not intuitive.\n\nWe can borrow a technique from mathematics to overcome these disadvantages by transforming the \\emph{domain} of the representations to one in which the operation of convolution becomes one of multiplication. This approach, called generally \\emph{frequency domain} analysis has a number of advantages and will be our focus for the remainder of the course.\n\n\\section{The Response of LTI Systems to Complex Exponentials}\n\nRecall convolution can be viewed as a decomposition of a signal into an infinite sum of $\\delta$ functions plus the linearity property.\n\\[\nx(t) = \\int\\limits_{-\\infty}^{\\infty} x(\\tau)\\delta(t-\\tau) \\; d\\tau \\;\\longrightarrow\\; y(t) = \\int\\limits_{-\\infty}^{\\infty} x(\\tau)h(t-\\tau) \\; d\\tau\n\\]\n  \nWe now consider a different decomposition based on the complex exponential, $e^{st}$ for $s \\in \\mathbb{C}$, rather than $\\delta$ functions. As we will see this decomposition simplifies convolution, turning it into multiplication.\n\n\\subsection{Eigenfunction $e^{st}$ and Transfer Function $H(s)$}\n\nLet $x(t) = e^{st}$ for $s\\in \\mathbb{C}$, then $y(t) = h(t) * x(t) = x(t) * h(t)$ and by the definition of convolution\n\\begin{align*}\n  y(t) & = \\int\\limits_{-\\infty}^{\\infty}h(\\tau)x(t-\\tau)\\; d\\tau\\\\\n  &= \\int\\limits_{-\\infty}^{\\infty}h(\\tau)e^{s(t-\\tau)}\\; d\\tau = \\int\\limits_{-\\infty}^{\\infty}h(\\tau)e^{st}e^{-s\\tau}\\; d\\tau\\\\\n  &= e^{st} \\int\\limits_{-\\infty}^{\\infty}h(\\tau)e^{-s\\tau}\\; d\\tau\\\\\n  &= e^{st}H(s)\n\\end{align*}\nwhere $H(s) = \\int\\limits_{-\\infty}^{\\infty}h(\\tau)e^{-s\\tau}\\; d\\tau$ is the \\emph{Laplace Transform} of the impulse response, $h(t)$. $H(s)$ is called the \\emph{transfer function} or \\emph{Eigenvalue} of the system and $e^{st}$ is the \\emph{Eigenfunction} for CT LTI systems.\n\nSimilar to the impulse function, the complex exponential is a special signal because it's response is easy to determine. It is just the same signal scaled by a multiplicative factor as illustrated below:\n\n\\begin{center}\n  \\includegraphics[scale=0.6]{graphics/lti-ct-complex-exp.pdf}\n\\end{center}\n\n\\begin{example}\nSuppose $H(s) = \\frac{1}{s+1}$ and $x(t) = e^{(-4+j2\\pi)t}$. Then the output is\n\\begin{align*}\n  y(t) &= H(-4+j2\\pi)e^{(-4+j2\\pi)t}\\\\\n  &= \\frac{1}{-4+j2\\pi+1}e^{(-4+j2\\pi)t}\\\\\n  &= \\frac{1}{-3+j2\\pi}e^{(-4+j2\\pi)t} \\; ,\n\\end{align*}\nanother complex exponential.\\\\\n$\\blacksquare$\n\\end{example}\n\nGiven $H(s)$ and inputs that are sums of complex exponentials, the output is easy to determine.\n\n\\begin{center}\n  \\includegraphics[scale=0.6]{graphics/ct-linear-response-complex-exp.pdf}\n\\end{center}\nIn some cases the sums are countably infinite while in others the uncountably infinite so that the sums become integrals.\n\n\\begin{example} Consider the CT system with impulse response response\n  \\[\n  h(t) = e^{-5t}u(t)\n  \\]\n  Determine the Eigenvalues that corresponds to the input $x(t) = \\cos(t)$ and the output $y(t)$.\\\\\n\n  Solution: We note the cosine can be decomposed into two complex exponentials as\n  \\[\n  \\cos(t) = \\frac{1}{2}e^{jt} + \\frac{1}{2}e^{-jt}\n  \\]\n  Thus in terms of the general decomposition there are two terms with complex constants $s_1 = 0+j$ and $s_2 = 0-j$ and real constants $a_1 = a_2 = \\frac{1}{2}$.\n  \\[\n   x(t) = \\sum_i a_i e^{s_it} = a_1 e^{s_1t} + a_2 e^{s_2t} = \\frac{1}{2}e^{jt} + \\frac{1}{2}e^{-jt} = \\cos(t)\n   \\]\n   Then the output is given by\n   \\[\n   y(t) = \\sum_i H(s_i) a_i e^{s_it} = H(s_1) a_1 e^{s_1t} + H(s_2) a_2 e^{s_2t} = H(j) \\frac{1}{2}e^{jt} + H(-j)\\frac{1}{2}e^{-jt}\n   \\]\n   which requires we find the Eigenvalues $H(j)$ and $H(-j)$. To do so we use the Laplace integral\n   \\[\n   H(j) = \\int\\limits_{-\\infty}^{\\infty}h(\\tau)e^{-j\\tau}\\; d\\tau = \\int\\limits_{0}^{\\infty} e^{-5\\tau} \\, e^{-j\\tau}\\; d\\tau = \\int\\limits_{0}^{\\infty} e^{-(j+5)\\tau}\\; d\\tau = \\frac{-1}{j+5} e^{-(j+5)\\tau} \\Big|_{0}^{\\infty} = \\frac{1}{j+5}  \n   \\]\n   Similarly\n   \\[\n   H(-j) = \\int\\limits_{-\\infty}^{\\infty}h(\\tau)e^{j\\tau}\\; d\\tau = \\int\\limits_{0}^{\\infty} e^{-5\\tau} \\, e^{j\\tau}\\; d\\tau = \\int\\limits_{0}^{\\infty} e^{-(-j+5)\\tau}\\; d\\tau = \\frac{-1}{-j+5} e^{-(j+5)\\tau} \\Big|_{0}^{\\infty} = \\frac{1}{-j+5}  \n   \\]\n   Substituting back into the output equation gives\n   \\begin{align*}\n     y(t) &= H(j) \\frac{1}{2}e^{jt} + H(-j)\\frac{1}{2}e^{-jt}\\\\\n     &=  \\frac{1}{j+5} \\frac{1}{2}e^{jt} + \\frac{1}{-j+5} \\frac{1}{2}e^{-jt}\n   \\end{align*}\n   We can simplify this expression using the polar form of the Eigenvalues\n   \\begin{align*}\n     y(t) &= \\frac{1}{j+5} \\frac{1}{2}e^{jt} + \\frac{1}{-j+5} \\frac{1}{2}e^{-jt}\\\\\n     &= Re^{j\\theta} \\frac{1}{2}e^{jt} + Re^{-j\\theta} \\frac{1}{2}e^{-jt}\\\\\n     &= R \\frac{1}{2}e^{jt + j\\theta} + R \\frac{1}{2}e^{-jt -j\\theta}\\\\\n     &= R\\cos(t + \\theta)\n   \\end{align*}\n   where\n   \\[\n   R = \\left|\\frac{1}{j+5}\\right| = \\frac{1}{\\sqrt{26}} \\mbox{ and } \\theta = \\angle{\\frac{1}{j+5}} = -\\arctan \\frac{1}{5}\n   \\]\n   Note for this system, given a sinusoidal input, the output is a scaled and phase shifted sinusoid at the same frequency, where the scaling factor and phase shift is system dependent. It is illustrative to compare this analysis to the time-domain analysis of the same impulse response and input using convolution.\n   $\\blacksquare$\n\\end{example}\n\n\\section{Decomposition of signals using complex exponentials}\n\nIn this course we consider the cases of stable CT systems. Recall a stable system is one in which a bounded input leads to a bounded output, or equivalently the impulse response is absolutely integrable. We will consider two decompositions of the input:\n\n  \\begin{itemize}\n  \\item \\emph{Fourier Series}: When $x(t)$ is periodic with fundamental frequency $\\omega_0$, $\\Re{(s)} = 0$ so that $s = jk\\omega_0$, and the decomposition is a countably infinite sum. This gives the input-output relationship\n    \\[\n    x(t) = \\sum\\limits_{k = -\\infty}^{\\infty} a_k \\, e^{j k\\omega_0 t} \\; \\longrightarrow\\; y(t) = \\sum\\limits_{k = -\\infty}^{\\infty} H(j k\\omega_0)\\, a_k \\, e^{j k\\omega_0 t}\n    \\]\n    where $H(j k\\omega_0)$ are the Eigenvalues, also called the \\emph{frequency response}.\n  \\item \\emph{Inverse Fourier Transform}: When $x(t)$ is a-periodic, $\\Re{(s)} = 0$ so that $s = j\\omega$, and the decomposition is an uncountably infinite sum (real integral over $\\omega$). This gives the input-output relationship\n    \\[\n    x(t) = \\frac{1}{2\\pi}\\int\\limits_{-\\infty}^{\\infty} X(\\omega) \\, e^{j \\omega t}\\; d\\omega \\;\\longrightarrow\\; y(t) = \\frac{1}{2\\pi}\\int\\limits_{-\\infty}^{\\infty} H(\\omega) X(\\omega) \\, e^{j \\omega t}\\; d\\omega\n    \\]\n    where $H(j \\omega)$ are the Eigenvalues, again called the \\emph{frequency response}.  \n  \\end{itemize}\n\n  Other courses (e.g. ECE 3704) look at the general case of unstable systems and $s \\in \\mathbb{C}$ with decompositions:\n\n  \\begin{itemize}\n  \\item \\emph{One-Sided Laplace Transform}: $x(t)$ is causal and the decomposition is an uncountably infinite sum (complex integral)\n  \\item \\emph{Two-Sided (Bilateral) Laplace Transform}: $x(t)$ is non-causal and the decomposition is an uncountably infinite sum (complex integral). This is the most general case for CT LTI systems.\n  \\end{itemize}\n\n  While the Laplace decompositions require complex integration, they can be understood and computed using algebra and a table of forward transforms, which only require integration of a complex function of a real variable $t$ (this is the general approach taken in upper level courses). However, this is outside the scope of this course because of time limitations.\n\nInstead, we will be spending the next few weeks going through the CT Fourier decompositions in some detail. You will also learn how to find the CT frequency response for a stable system, and see how to use both for analysis.\n\n", "meta": {"hexsha": "df38536884b1b37d38aec8b62f2205792cbe2acd", "size": 8678, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "12-ct-tf.tex", "max_stars_repo_name": "clwyatt/notes-2714", "max_stars_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "12-ct-tf.tex", "max_issues_repo_name": "clwyatt/notes-2714", "max_issues_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "12-ct-tf.tex", "max_forks_repo_name": "clwyatt/notes-2714", "max_forks_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.796875, "max_line_length": 415, "alphanum_fraction": 0.6821848352, "num_tokens": 2795, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.8705972751232809, "lm_q1q2_score": 0.7417077813822026}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage{graphicx,subcaption}\n\\usepackage{amsmath,amsfonts}\n\\title{Notes on Optimisation}\n\\author{G.A. Jarrad}\n\\begin{document}\n\\maketitle\n\\numberwithin{equation}{section}\n\\numberwithin{figure}{section}\n\\numberwithin{table}{section}\n\\section{Introduction}\\label{sec:intro}\nblah, blah, blah\n\n\\section{Recursive Least Square Error Estimation}\nConsider using least square error optimisation to approximately fit the linear coefficient model\n\\begin{eqnarray}\n   y & = & \\vec{a}\\cdot\\vec{x}+\\varepsilon\n\\label{eq:y_ax}\n\\end{eqnarray}\nto the data $\\left\\{(\\vec{x}_t,y_t)\\;|\\;t=1,2,\\ldots,n\\right\\}$.\nThe square error is given by\n\\begin{eqnarray}\n   S_n & = & \\sum_{t=1}^n(y_t-\\vec{a}\\cdot\\vec{x}_t)^2\n\\end{eqnarray}\nand hence\n\\begin{eqnarray}\n   \\frac{\\partial S_n}{\\partial\\vec{a}} & = & -2\\sum_{t=1}^n(y_t-\\vec{a}\\cdot\\vec{x}_t)\\vec{x}_t\\,.\n\\end{eqnarray}\nThe turning point $\\hat{\\vec{a}}_n$ then occurs when\n\\begin{eqnarray}\n   \\sum_{t=1}^n y_t\\vec{x}_t = \\sum_{t=1}^n\\vec{x}_t\\vec{x}_t^{T}\\hat{\\vec{a}}_n\\,,\n\\label{eq:yx_xxa_n}\n\\end{eqnarray}\nand thus $S_n$ is maximised when\n\\begin{eqnarray}\n   \\hat{\\vec{a}}_n = \\left(\\sum_{t=1}^n\\vec{x}_t\\vec{x}_t^{T}\\right)^{-1}\\sum_{t=1}^n y_t\\vec{x}_t\\,.\n\\end{eqnarray}\n\nSuppose now that another data point $(y_{n+1},\\vec{x}_{n+1})$ is given. Then the new least square error estimate\nis given by\n\\begin{eqnarray}\n   \\hat{\\vec{a}}_{n+1} = \\left(\\sum_{t=1}^{n+1}\\vec{x}_t\\vec{x}_t^{T}\\right)^{-1}\\sum_{t=1}^{n+1} y_t\\vec{x}_t\\,,\n\\label{eq:yx_xxa_np1}\n\\end{eqnarray}\nwhich appears to require yet another matrix inverse. However, this secondary inverse can avoided by using recursive estimation\nof the form\n\\begin{eqnarray}\n   P_{n+1} & = & \\left(\\sum_{t=1}^{n+1}\\vec{x}_t\\vec{x}_t^{T}\\right)^{-1}\n\\nonumber\\\\\n  & = & \\left(\\sum_{t=1}^{n}\\vec{x}_t\\vec{x}_t^{T}+\\vec{x}_{n+1}\\vec{x}_{n+1}^{T}\\right)^{-1}\n\\nonumber\\\\\n  & = & \\left(P_n^{-1}+\\vec{x}_{n+1}\\vec{x}_{n+1}^{T}\\right)^{-1}\n\\nonumber\\\\\n  & = & P_n-\\frac{P_n\\vec{x}_{n+1}\\vec{x}_{n+1}^{T}P_n}{1+\\vec{x}_{n+1}^{T}P_n\\vec{x}_{n+1}}\\,,\n\\end{eqnarray}\nfrom the Woodbury matrix identity \n\\begin{eqnarray}\n    \\left(A+UCV \\right)^{-1} = A^{-1} - A^{-1}U \\left(C^{-1}+VA^{-1}U \\right)^{-1} VA^{-1}\\,.\n\\end{eqnarray}\nConsequently, observe that\n\\begin{eqnarray}\n   \\sum_{t=1}^{n+1} y_t\\vec{x}_t & = & \\sum_{t=1}^{n} y_t\\vec{x}_t+y_{n+1}\\vec{x}_{n+1}\n\\nonumber\\\\\n& = & \\sum_{t=1}^n\\vec{x}_t\\vec{x}_t^{T}\\hat{\\vec{a}}_n+y_{n+1}\\vec{x}_{n+1}\n\\nonumber\\\\\n& = & \\sum_{t=1}^{n+1}\\vec{x}_t\\vec{x}_t^{T}\\hat{\\vec{a}}_n-\\vec{x}_{n+1}\\vec{x}_{n+1}^{T}\\hat{\\vec{a}}_n\n         +y_{n+1}\\vec{x}_{n+1}\n\\nonumber\\\\\n& = & P_{n+1}^{-1}\\hat{\\vec{a}}_n+\\vec{x}_{n+1}(y_{n+1}-\\hat{\\vec{a}}_n\\cdot\\vec{x}_{n+1})\n\\end{eqnarray}\nfrom equation~\\eqref{eq:yx_xxa_n}, and hence the estimate $\\hat{\\vec{a}}_{n+1}$ is given recursively by\n\\begin{eqnarray}\n   \\hat{\\vec{a}}_{n+1} = \\hat{\\vec{a}}_{n} + P_{n+1} \\vec{x}_{n+1}(y_{n+1}-\\hat{\\vec{a}}_n\\cdot\\vec{x}_{n+1})\n\\end{eqnarray}\nfrom equation~\\eqref{eq:yx_xxa_np1}. Observe that this recursive estimate takes the form of a predictor--corrector\nupdate, since $\\hat{\\vec{a}}_n\\cdot\\vec{x}_{n+1}$ is the expected value of\n$y_{n+1}$ given $\\hat{\\vec{a}}_n$, from model~\\eqref{eq:y_ax}.\n\nAs a slight alternative to the above approach to re-estimation,\n suppose now instead that we are using a sliding data window of fixed width $n$, e.g.\\ for time series analysis.\nThen the $k$-th parameter estimate $\\hat{\\vec{a}}_{n}^{(k)}$ is given by\n\\begin{eqnarray}\n   \\hat{\\vec{a}}_{n}^{(k)} = \\left(\\sum_{t=k}^{n+k-1}\\vec{x}_t\\vec{x}_t^{T}\\right)^{-1}\\sum_{t=k}^{n+k-1} y_t\\vec{x}_t\\,.\n\\label{eq:yx_xxa_nk_alt}\n\\end{eqnarray}\nHence, observe that\n\\begin{eqnarray}\n   P_{n}^{(k+1)} & = & \\left(\\sum_{t=k+1}^{n+k}\\vec{x}_t\\vec{x}_t^{T}\\right)^{-1}\n\\nonumber\\\\\n  & = & \\left(\\sum_{t=k}^{n+k-1}\\vec{x}_t\\vec{x}_t^{T}-\\vec{x}_k\\vec{x}_k^T+\\vec{x}_{n+k}\\vec{x}_{n+k}^{T}\\right)^{-1}\n\\nonumber\\\\\n  & = & \\left({Q_n^{(k)}}^{-1}+\\vec{x}_{n+k}\\vec{x}_{n+k}^{T}\\right)^{-1}\n\\nonumber\\\\\n  & = & Q_n^{(k)}-\\frac{Q_n^{(k)}\\vec{x}_{n+k}\\vec{x}_{n+k}^{T}Q_n^{(k)}}{1+\\vec{x}_{n+k}^{T}Q_n^{(k)}\\vec{x}_{n+k}}\\,,\n\\end{eqnarray}\nwhere\n\\begin{eqnarray}\n   Q_{n}^{(k)} & = & \\left(\\sum_{t=k}^{n+k-1}\\vec{x}_t\\vec{x}_t^{T}-\\vec{x}_k\\vec{x}_k^T\\right)^{-1}\n\\nonumber\\\\\n  & = & \\left({P_n^{(k)}}^{-1}-\\vec{x}_{k}\\vec{x}_{k}^{T}\\right)^{-1}\n\\nonumber\\\\\n  & = & P_n^{(k)}+\\frac{P_n^{(k)}\\vec{x}_{k}\\vec{x}_{k}^{T}P_n^{(k)}}{1-\\vec{x}_{k}^{T}P_n^{(k)}\\vec{x}_{k}}\\,.\n\\end{eqnarray}\nConsequently, \n\\begin{eqnarray}\n   \\sum_{t=k+1}^{n+k} y_t\\vec{x}_t & = & \\sum_{t=k}^{n+k-1} y_t\\vec{x}_t-y_k\\vec{x}_k+y_{n+k}\\vec{x}_{n+k}\n\\nonumber\\\\\n& = & \\sum_{t=k}^{n+k-1}\\vec{x}_t\\vec{x}_t^{T}\\hat{\\vec{a}}_n^{(k)}-y_k\\vec{x}_k+y_{n+k}\\vec{x}_{n+k}\n\\nonumber\\\\\n& = & \\sum_{t=k+1}^{n+k}\\vec{x}_t\\vec{x}_t^{T}\\hat{\\vec{a}}_n^{(k)}\n+\\vec{x}_k\\vec{x}_k^{T}\\hat{\\vec{a}}_n^{(k)}-\\vec{x}_{n+k}\\vec{x}_{n+k}^{T}\\hat{\\vec{a}}_n^{(k)}\n\\nonumber\\\\\n&&        \\hspace*{10mm}{}-y_k\\vec{x}_k+y_{n+k}\\vec{x}_{n+k}\n\\nonumber\\\\\n& = & {P_{n}^{(k+1)}}^{-1}\\hat{\\vec{a}}_n^{(k)}\n-\\vec{x}_{k}(y_{k}-\\hat{\\vec{a}}_n^{(k)}\\cdot\\vec{x}_{k})\n\\nonumber\\\\\n&& \\hspace*{10mm}{}+\\vec{x}_{n+k}(y_{n+k}-\\hat{\\vec{a}}_n^{(k)}\\cdot\\vec{x}_{n+k})\\,,\n\\end{eqnarray}\nand hence\n\\begin{eqnarray}\n   \\hat{\\vec{a}}_{n}^{(k+1)} & = & \\hat{\\vec{a}}_{n}^{(k)}\n-P_n^{(k+1)}\\vec{x}_{k}(y_{k}-\\hat{\\vec{a}}_n^{(k)}\\cdot\\vec{x}_{k})\n\\nonumber\\\\\n&&\\hspace*{6mm}{}+P_n^{(k+1)}\\vec{x}_{n+k}(y_{n+k}-\\hat{\\vec{a}}_n^{(k)}\\cdot\\vec{x}_{n+k})\n\\,,\n\\label{eq:yx_xxa_nkp1_alt}\n\\end{eqnarray}\nfrom equation~\\eqref{eq:yx_xxa_nk_alt}.\n\n\\end{document}\n", "meta": {"hexsha": "af05cb637ad3bd91ed5148c6ac031ff8cacfcaad", "size": 5576, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "random_thoughts/notes/recursive-LS-notes.tex", "max_stars_repo_name": "gaj67/gaj-data-science", "max_stars_repo_head_hexsha": "aadcf6ee2cd00606563f213167c2eeeb42430c59", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "random_thoughts/notes/recursive-LS-notes.tex", "max_issues_repo_name": "gaj67/gaj-data-science", "max_issues_repo_head_hexsha": "aadcf6ee2cd00606563f213167c2eeeb42430c59", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "random_thoughts/notes/recursive-LS-notes.tex", "max_forks_repo_name": "gaj67/gaj-data-science", "max_forks_repo_head_hexsha": "aadcf6ee2cd00606563f213167c2eeeb42430c59", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.2424242424, "max_line_length": 126, "alphanum_fraction": 0.6020444763, "num_tokens": 2561, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.7416895422069739}}
{"text": "\\lab{The QR Decomposition}{The QR Decomposition}\n\\label{lab:QRdecomp}\n\\objective{The QR decomposition is a fundamentally important matrix factorization.\nIt is straightforward to implement, is numerically stable, and provides the basis of several important algorithms.\nIn this lab we explore several ways to produce the QR decomposition and implement a few immediate applications.\n% \\\\ \\indent We restrict our discussion to real matrices.\n% However, the results and algorithms presented here can be extended to complex matrices by replacing ``transpose'' with ``hermitian conjugate'' and ``symmetric matrix'' with ``hermitian matrix.''\n}\n\nThe QR decomposition of a matrix $A$ is a factorization $A=QR$, where $Q$ is  has orthonormal columns and $R$ is upper triangular.\nEvery $m \\times n$ matrix $A$ of rank $n \\le m$ has a QR decomposition, with two main forms.\n%\n\\begin{itemize}\n    \\item \\textbf{Reduced QR}: $Q$ is $m \\times n$, $R$ is $n \\times n$, and the columns $\\{\\q_j\\}_{j=1}^n$ of $Q$ form an orthonormal basis for the column space of $A$.\n    \\item \\textbf{Full QR}: $Q$ is $m \\times m$ and $R$ is $m \\times n$.\n    In this case, the columns $\\{\\q_j\\}_{j=1}^m$ of $Q$ form an orthonormal basis for all of $\\mathbb{F}^m$, and the last $m - n$ rows of $R$ only contain zeros.\n    If $m = n$, this is the same as the reduced factorization.\n\\end{itemize}\nWe distinguish between these two forms by writing $\\widehat{Q}$ and $\\widehat{R}$ for the reduced decomposition and $Q$ and $R$ for the full decomposition.\n%\n\\begin{align*} % Reduced and full QR decompositions.\n\\begin{array}{ccc}\n\\textcolor{red}{\\widehat{Q}\\ (m \\times n)} & \\textcolor{blue}{\\widehat{R}\\ (n \\times n)} & \\\\\n\\left[\\begin{array}{cccccccc}\n\\arrayrulecolor{red}\n\\cline{2-4}\n& \\lvl{}     &        & \\rvl{}     &          &        &      & \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      & \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      & \\\\\n& \\lvl{\\q_1} & \\cdots & \\rvl{\\q_n} & \\q_{n+1} & \\cdots & \\q_m & \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      & \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      & \\\\\n& \\lvl{}     &        & \\rvl{}     &          &        &      & \\\\\n\\cline{2-4}\n\\end{array}\\right]\n&\n\\left[\\begin{array}{ccccc}\n\\arrayrulecolor{blue}\n\\cline{2-4}\n& \\lvl{r_{11}} & \\cdots & \\rvl{r_{1n}} & \\\\\n& \\lvl{}       & \\ddots & \\rvl{\\vdots} & \\\\\n& \\lvl{}       &        & \\rvl{r_{nn}} & \\\\\n\\cline{2-4}\n& 0            & \\cdots & 0            & \\\\\n& \\vdots       &        & \\vdots       & \\\\\n& 0            & \\cdots & 0            & \\\\\n\\end{array}\\right]\n& =\\ A\\ (m \\times n)\n\\\\\nQ\\ (m \\times m) & R\\ (m \\times n) & \\\\\n\\end{array}\n\\end{align*}\n\n\\section*{QR via Gram-Schmidt} % ==============================================\n\nThe \\emph{classical Gram-Schmidt algorithm} takes a linearly independent set of vectors and constructs an orthonormal set of vectors with the same span.\nApplying Gram-Schmidt to the columns of $A$, which are linearly independent since $A$ has rank $n$, results in the columns of $Q$.\n\nLet $\\{\\x_j\\}_{j=1}^n$ be the columns of $A$.\nDefine\n%\n\\begin{align*}\n\\q_1 = \\frac{\\x_1}{\\|\\x_1\\|},\n&&\n\\q_{k} = \\frac{\\x_k - \\p_{k-1}}{\\|\\x_k - \\p_{k-1}\\|},\\quad k=2,\\ \\ldots,\\ n,\n\\\\ \\\\\n\\p_0 = \\0,\n&&\n\\p_{k-1} = \\sum_{j=1}^{k-1} \\langle \\q_j, \\x_k\\rangle \\q_j,\\quad k=2,\\ \\ldots,\\ n.\n\\end{align*}\n\nEach $\\p_{k-1}$ is the projection of $\\x_k$ onto the span of $\\{\\q_j\\}_{j=1}^{k-1}$, so $\\q_k' = \\x_k - \\p_{k-1}$ is the residual vector of the projection.\nThus $\\q_k'$ is orthogonal to each of the vectors in $\\{\\q_j\\}_{j=1}^{k-1}$.\nTherefore, normalizing each $\\q_k'$ produces an orthonormal set $\\{\\q_j\\}_{j=1}^n$.\n\nTo construct the reduced QR decomposition, let $\\widehat{Q}$ be the matrix with columns $\\{\\q_j\\}_{j=1}^n$, and let $\\widehat{R}$ be the upper triangular matrix with entries\n%\n\\begin{align*}\nr_{kk} = \\|\\x_k-\\p_{k-1}\\|,\n&&\nr_{jk} = \\langle \\q_j, \\x_k\\rangle = \\q_j\\trp\\x_k,\\ j < k.\n\\end{align*}\n%\nThis clever choice of entries for $\\widehat{R}$ reverses the Gram-Schmidt process and ensures that $\\widehat{Q}\\widehat{R} = A$.\n\n\\begin{comment}\nTo construct the full QR decomposition, choose $m - n$ vectors $\\{\\x_j\\}_{j=n+1}^m$ such that the entire set of original vectors $\\{\\x_j\\}_{j=1}^m$ is linearly independent, then continue the Gram-Schmidt process to produce the additional columns of $Q$.\nAppending $m - n$ rows of zeros to $\\widehat{R}$ results in $R$.\n\\end{comment}\n\n\\subsection*{Modified Gram-Schmidt} % -----------------------------------------\n\nIf the columns of $A$ are close to being linearly dependent, the classical Gram-Schmidt algorithm often produces a set of vectors $\\{\\q_j\\}_{j=1}^n$ that are not even close to orthonormal due to rounding errors.\nThe \\emph{modified Gram-Schmidt algorithm} is a slight variant of the classical algorithm which more consistently produces a set of vectors that are ``very close'' to orthonormal.\n\nLet $\\q_1$ be the normalization of $\\x_1$ as before.\nInstead of making just $\\x_2$ orthogonal to $\\q_1$, make \\textbf{each} of the vectors $\\{\\x_j\\}_{j=2}^n$ orthogonal to $\\q_1$:\n\\[\\x_k = \\x_k - \\langle \\q_1,\\x_{k} \\rangle \\q_1,\\quad k=2,\\ \\ldots,\\ n.\\]\nNext, define $\\q_2 = \\frac{\\x_2}{\\|\\x_2\\|}$.\nProceed by making each of $\\{\\x_j\\}_{j=3}^n$ orthogonal to $\\q_2$:\n\\[\\x_k = \\x_k - \\langle \\q_2,\\x_{k} \\rangle \\q_2,\\quad k=3,\\ldots,n.\\]\nSince each of these new vectors is a linear combination of vectors orthogonal to $\\q_1$, they are orthogonal to $\\q_1$ as well.\nContinuing this process results in the desired orthonormal set $\\{\\q_j\\}_{j=1}^n$.\nThe entire modified Gram-Schmidt algorithm is described below. % in Algorithm \\ref{Alg:modified-Gram-Schmidt}.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{Modified Gram-Schmidt}{$A$}\n    \\State $m, n \\gets \\shape{A}$\n        \\Comment{Store the dimensions of $A$.}\n    \\State $Q \\gets \\makecopy{A}$\n        \\Comment{Make a copy of $A$ with \\li{np.copy()}.}\n    \\State $R \\gets \\zeros{n}{n}$\n        \\Comment{An $n\\times n$ array of all zeros.}\n    \\For{$i=0\\ldots n-1$}\n        \\State $R_{i,i} \\gets \\|Q_{:,i}\\|$\\label{step:mgs-normalize}\n            % \\Comment{(Hint: use \\li{scipy.linalg.norm()}).}\n        \\State $Q_{:,i} \\gets Q_{:,i}/R_{i,i}$\\label{step:mgs-mult1}\n            \\Comment{Normalize the $i$th column of $Q$.}\n        \\For{$j=i+1\\ldots n-1$}\n            \\State $R_{i,j} \\gets Q_{:,j}\\trp  Q_{:,i}$\\label{step:mgs-mult2}\n            \\State $Q_{:,j} \\gets Q_{:,j}-R_{i,j}Q_{:,i}$\\label{step:mgs-mult3}\n                \\Comment{Orthogonalize the $j$th column of $Q$.}\n        \\EndFor\n    \\EndFor\n    \\State \\pseudoli{return} $Q, R$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\label{Alg:modified-Gram-Schmidt}\n\\end{algorithm}\n\n\\begin{problem} % QR via Modified Gram Schmidt.\nWrite a function that accepts an $m \\times n$ matrix $A$ of rank $n$.\nUse Algorithm \\ref{Alg:modified-Gram-Schmidt} to compute the reduced QR decomposition of $A$.\n\nConsider the following tips for implementing the algorithm.\n\\begin{itemize}\n\n% \\item In Python, the operation \\li{a = a + b} can also be written as \\li{a += b}.\n\n\\item Use \\li{scipy.linalg.norm()} to compute the norm of the vector in step \\ref{step:mgs-normalize}.\n\n\\item Note that steps \\ref{step:mgs-mult1} and \\ref{step:mgs-mult3} employ scalar multiplication or division, while step \\ref{step:mgs-mult2} uses vector multiplication.\n\n\\end{itemize}\n\nTo test your function, generate test cases with NumPy's \\li{np.random} module.\nVerify that $R$ is upper triangular, $Q$ is orthonormal, and $QR = A$.\nYou may also want to compare your results to SciPy's QR factorization routine, \\li{scpiy.linalg.qr()}.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import linalg as la\n\n# Generate a random matrix and get its reduced QR decomposition via SciPy.\n>>> A = np.random.random((6,4))\n>>> Q,R = la.qr(A, mode=\"economic\") # Use mode=\"economic\" for reduced QR.\n>>> print(A.shape, Q.shape, R.shape)\n(6,4) (6,4) (4,4)\n\n# Verify that R is upper triangular, Q is orthonormal, and QR = A.\n>>> np.allclose(np.triu(R), R)\n<<True>>\n>>> np.allclose(Q.T @ Q, np.identity(4))\n<<True>>\n>>> np.allclose(Q @ R, A)\n<<True>>\n\\end{lstlisting}\n\\label{prob:qr-via-mgs}\n\\end{problem}\n\n\\section*{Consequences of the QR Decomposition} % =============================\n\nThe special structures of $Q$ and $R$ immediately provide some simple applications.\n\n\\subsection*{Determinants} % --------------------------------------------------\n\nLet $A$ be $n \\times n$.\nThen $Q$ and $R$ are both $n \\times n$ as well.%\n\\footnote{An $n \\times n$ orthonormal matrix is sometimes called \\emph{unitary} in other texts.}\nSince $Q$ is orthonormal and $R$ is upper-triangular,\n\\[\\det(Q) = \\pm 1 \\qquad\\text{and}\\qquad \\det(R) = \\prod_{i=1}^n r_{i,i}.\\]\nThen since $\\det(AB) = \\det(A)\\det(B)$,\n\\begin{equation}\n\\label{eq:qr-determinant}\n\\abs{\\det(A)} = \\abs{\\det(QR)} = \\abs{\\det(Q)\\det(R)} = \\abs{\\det(Q)}\\abs{\\det(R)} = \\abs{\\prod_{i=1}^n r_{i,i}}.\n\\end{equation}\n\n\\begin{problem} % Use the QR decomposition to calculate |det(A)|.\nWrite a function that accepts an invertible matrix $A$.\nUse the QR decomposition of $A$ and (\\ref{eq:qr-determinant}) to calculate $\\abs{\\det(A)}$.\nYou may use your QR decomposition algorithm from Problem \\ref{prob:qr-via-mgs} or SciPy's QR routine.\nCan you implement this function in a single line?\n\\\\(Hint: \\li{np.diag()} and \\li{np.prod()} may be useful.)\n\nCheck your answer against \\li{la.det()}, which calculates the determinant.\n\\end{problem}\n\n\\subsection*{Linear Systems} % ------------------------------------------------\n\nThe LU decomposition is usually the matrix factorization of choice to solve the linear system $A\\x = \\b$ because the triangular structures of $L$ and $U$ facilitate forward and backward substitution.\nHowever, the QR decomposition avoids the potential numerical issues that come with Gaussian elimination.\n\nSince $Q$ is orthonormal, $Q^{-1}= Q\\trp$.\nTherefore, solving $A\\x = \\b$ is equivalent to solving the system $R\\x = Q\\trp\\b$.\nSince $R$ is upper-triangular, $R\\x = Q\\trp\\b$ can be solved quickly with back substitution.%\n\\footnote{See the Linear Systems lab for details on back substitution.}\n\n\\begin{problem} % Use the QR decomposition to solve Ax = b quickly.\nWrite a function that accepts an invertible $n \\times n$ matrix $A$ and a vector $\\b$ of length $n$.\nUse the QR decomposition to solve $A\\x = \\b$ in the following steps:\n\\begin{enumerate}\n    \\item Compute $Q$ and $R$.\n    \\item Calculate $\\y = Q\\trp\\b$.\n    \\item Use back substitution to solve $R\\x = \\y$ for $\\x$.\n\\end{enumerate}\n\\end{problem}\n\n\\section*{QR via Householder} % ===============================================\n\nThe Gram-Schmidt algorithm orthonormalizes $A$ using a series of transformations that are stored in an upper triangular matrix.\nAnother way to compute the QR decomposition is to take the opposite approach: triangularize $A$ through a series of orthonormal transformations.\nOrthonormal transformations are numerically stable, meaning that they are less susceptible to rounding errors.\nIn fact, this approach is usually faster and more accurate than Gram-Schmidt methods.\n\nThe idea is for the $k$th orthonormal transformation $Q_k$ to map the $k$th column of $A$ to the span of $\\{\\e_j\\}_{j=1}^k$, where the $\\e_j$ are the standard basis vectors in $\\mathbb{R}^m$.\nIn addition, to preserve the work of the previous transformations, $Q_k$ should not modify any entries of $A$ that are above or to the left of the $k$th diagonal term of $A$.\nFor a $4 \\times 3$ matrix $A$, the process can be visualized as follows.\n%\n\\begin{align*}\nQ_3 Q_2 Q_1\n\\left[\\begin{array}{ccccc}\n\\cline{2-4}\n& \\lvl{*} & * & \\rvl{*} & \\\\\n& \\lvl{*} & * & \\rvl{*}& \\\\\n& \\lvl{*} & * & \\rvl{*} & \\\\\n& \\lvl{*} & * & \\rvl{*} & \\\\ \\cline{2-4}\n\\end{array}\\right]\n= Q_3 Q_2\n\\left[\\begin{array}{ccc}\n     *  & * &      * \\\\\n\\cline{2-3}\n\\rvl{0} & * & \\rvl{*} \\\\\n\\rvl{0} & * & \\rvl{*} \\\\\n\\rvl{0} & * & \\rvl{*} \\\\\n\\cline{2-3}\n\\end{array}\\right]\n= Q_3\n\\left[\\begin{array}{ccc}\n* & * & * \\\\\n0 & * & * \\\\\n\\cline{3-3}\n0 & \\rvl{0} & \\rvl{*} \\\\\n0 & \\rvl{0} & \\rvl{*} \\\\\n\\cline{3-3}\n\\end{array}\\right]\n=\n\\left[\\begin{array}{ccc}\n* & * & * \\\\\n0 & * & * \\\\\n0 & 0 & * \\\\\n0 & 0 & 0 \\\\\n\\end{array}\\right]\n\\end{align*}\n\nThus $Q_3 Q_2 Q_1 A = R$, so that $A = Q_1\\trp Q_2\\trp Q_3\\trp R$ since each $Q_k$ is orthonormal.\nFurthermore, the product of square orthonormal matrices is orthonormal, so setting $Q = Q_1\\trp Q_2\\trp Q_3\\trp$ yields the full QR decomposition.\n\nHow to correctly construct each $Q_k$ isn't immediately obvious.\nThe ingenious solution lies in one of the basic types of linear transformations: reflections.\n\n\\subsection*{Householder Transformations} % -----------------------------------\n\nThe \\emph{orthogonal complement} of a nonzero vector $\\v \\in \\mathbb{R}^n$ is the set of all vectors $\\x \\in \\mathbb{R}^n$ that are orthogonal to $\\v$, denoted $\\v^\\perp = \\{ \\x \\in \\mathbb{R}^n \\mid \\langle \\x, \\v \\rangle = 0 \\}$.\nA \\emph{Householder transformation} is a linear transformation that reflects a vector $\\x$ across the orthogonal complement $\\v^\\perp$ for some specified $\\v$.\n\nThe matrix representation of the Householder transformation corresponding to $\\v$ is given by $H_{\\v} = I - 2\\frac{\\v\\v\\trp}{\\v\\trp\\v}$.\nSince $H_{\\v}\\trp H_{\\v} = I$, Householder transformations are orthonormal.\n\n\\begin{figure}[H]\n\\centering\n\\begin{tikzpicture}\n    \\draw[-,dashed, gray](-2,-1.333)--(3, 2);               % hyperplane\n    \\draw[->, gray, >=stealth,ultra thick](0,0)--(.8,-1.2); % v\n    \\draw[->, >=stealth, thick](0,0)--(2.815, .777);        % H x\n    \\draw[->, >=stealth, thick](0,0)--(1.8,2.3);            % x\n    \\node[draw=none](v)at(.65,-.6){$\\v$};\n    \\node[draw=none](x)at(.75,1.5){$\\x$};\n    \\node[draw=none](Hx)at(3, .5){$H_{\\v}\\x$};\n    \\node[draw=none](H)at(-1.5,-.6){$\\v^\\perp$};\n    % \\node[draw=none](bullet)at(2.31, 1.53){\\textbullet};\n    % \\node[draw=none](vandx)at(4.0,1.5){$\\x -\n    % \\left \\langle \\dfrac{\\v}{\\|\\v\\|}, \\x \\right \\rangle \\dfrac{\\v}{\\|\\v\\|}$};\n\\end{tikzpicture}\n\\caption{The vector $\\v$ defines the orthogonal complement $\\v^\\perp$, which in this case is a line.\nApplying the Householder transformation $H_{\\mathbf{v}}$ to $\\x$ reflects $\\x$ across $\\v^\\perp$.}\n\\label{fig:Householder_reflector}\n\\end{figure}\n\n\\subsection*{Householder Triangularization} % ---------------------------------\n\nThe \\emph{Householder algorithm} uses Householder transformations for the orthonormal transformations in the QR decomposition process described on the previous page.\nThe goal in choosing $Q_k$ is to send $\\x_k$, the $k$th column of $A$, to the span of $\\{\\e_j\\}_{j=1}^k$.\nIn other words, if $Q_k\\x_k = \\y_k$, the last $m - k$ entries of $\\y_k$ should be $0$, i.e.,\n\\begin{align*}\nQ_k\\x_k = Q_k\n\\left[\\begin{array}{c}\nz_1 \\\\ \\vdots \\\\ z_k \\\\ z_{k+1} \\\\ \\vdots \\\\ z_m\n\\end{array}\\right]\n=\n\\left[\\begin{array}{c}\ny_1 \\\\ \\vdots \\\\ y_k \\\\ 0 \\\\ \\vdots \\\\ 0\n\\end{array}\\right]\n= \\y_k.\n\\end{align*}\n\nTo begin, decompose $\\x_k$ into $\\x_k = \\x_k' + \\x_k''$, where $\\x_k'$ and $\\x_k''$ are of the form\n\\[\n\\x_k' = \\left[z_1\\quad \\cdots\\quad z_{k-1}\\quad 0\\quad \\cdots\\quad 0\\right]\\trp,\n\\qquad\\qquad\n\\x_k'' = \\left[0\\quad \\cdots\\quad 0\\quad z_k\\quad \\cdots\\quad z_m\\right]\\trp.\n\\]\nBecause $\\x_k'$ represents elements of $A$ that lie above the diagonal, only $\\x_k''$ needs to be altered by the reflection.\n\nThe two vectors $\\x_k''\\ \\pm\\ \\|\\x_k''\\|\\e_k$ both yield Householder transformations that send $\\x_k''$ to the span of $\\e_k$ (see Figure \\ref{fig:householder-two-possible-reflectors}).\nBetween the two, the one that reflects $\\x_k''$ further is more numerically stable.\nThis reflection corresponds to \\[\\v_k = \\x_k'' + \\sign(z_k)\\|\\x_k''\\| \\e_k,\\] where $z_k$ is the first nonzero component of $\\x_k''$ (the $k$th component of $\\x_k$).\n\n\\begin{figure}[H] % Two possible reflections into the span of e_1.\n\\begin{tikzpicture}\n\n\\draw[-, dashed, gray](-3,-1)--(3,1);\n\\draw[-, dashed, gray](-.8,2.4)--(.6,-1.8);\n\\draw[-, gray, thick](-4,0)--(4,0);\n\\draw[->, thick, >=stealth'](0,0)--(2,1.6);\n\\draw[<->, thick, >=stealth'](-2.6,0)--(2.6,0);\n\\draw[->, gray,  ultra thick, >=stealth](0,0)--(1.5,.5);\n\\draw[->, gray, ultra thick, >=stealth](0,0)--(-.5,1.5);\n\n\\node[draw=none, node distance=3.5cm]\n    (dummy)at(2.5,.2){};\n\\node[draw=none, node distance=.5cm](Hvx)\n    [below of=dummy]{$H_{\\v_1}\\x$};\n\\node[draw=none, node distance=2cm](x)\n    [above left of=Hvx]{$\\x$};\n\\node[draw=none](v1)[left of=x]{$\\v_1$};\n\\node[draw=none, node distance=.55cm](v2)[below of=x]{$\\v_2$};\n\\node[draw=none, node distance=4cm](hvx2)[left of=dummy]{$H_{\\v_2}\\x$};\n\n\\end{tikzpicture}\n\\caption{There are two reflections that map $\\x$ into the span of $\\e_1$, defined by the vectors $\\v_1$ and $\\v_2$.\nIn this illustration, $H_{\\v_2}$ is the more stable transformation since it reflects $\\x$ further than $H_{\\v_1}$.}\n\\label{fig:householder-two-possible-reflectors}\n\\end{figure}\n\nAfter choosing $\\v_k$, set $\\u_k = \\frac{\\v_k}{\\|\\v_k\\|}$.\nThen $H_{\\v_k} = I - 2\\frac{\\v_k\\v_k\\trp}{\\|\\v_k\\|^2} = I - 2\\u_k\\u_k\\trp$, and hence $Q_k$ is given by the block matrix\n\\begin{equation*}\nQ_k =\n\\left[\\begin{array}{cc}\nI_{k-1} & \\0 \\\\\n\\0      & H_{\\v_k} \\\\\n\\end{array}\\right] =\n\\left[\\begin{array}{cc}\nI_{k-1} & \\0 \\\\\n\\0      & I_{m-k+1} - 2 \\u_k\\u_k\\trp \\\\\n\\end{array}\\right].\n\\end{equation*}\n\nHere $I_{p}$ denotes the $p \\times p$ identity matrix, and thus each $Q_k$ is $m \\times m$.\n\nIt is apparent from its form that $Q_k$ does not affect the first $k-1$ rows and columns of any matrix that it acts on.\nThen by starting with $R = A$ and $Q = I$, at each step of the algorithm we need only multiply the entries in the lower right $(m-k+1) \\times (m-k+1)$ submatrices of $R$ and $Q$ by $I-2\\u_k\\u_k\\trp$.\nThis completes the Householder algorithm, detailed below.\n\n\\begin{algorithm}[H] % QR Decomposition via Householder Reflections.\n\\begin{algorithmic}[1]\n\\Procedure{Householder}{$A$}\n    \\State $m, n \\gets \\shape{A}$\n    \\State $R \\gets \\makecopy{A}$\n    \\State $Q \\gets I_{m}$\n        \\Comment{The $m\\times m$ identity matrix.}\n    \\For{$k=0\\ldots n-1$}\n        \\State $\\u \\gets \\makecopy{R_{k:,k}}$\n        \\State $u_0 \\gets u_0 + \\sign(u_0)\\|\\u\\|$\n            \\Comment{$u_0$ is the first entry of $\\u$.}\\label{step:HH-sign}\n        \\State $\\u \\gets \\u/\\|\\u\\|$\n            \\Comment{Normalize $\\u$.}\n        \\State $R_{k:,k:} \\gets R_{k:,k:} - 2\\u\\left(\\u\\trp R_{k:,k:}\\right)$\n            \\Comment{Apply the reflection to $R$.}\\label{step:HH-outer1}\n        \\State $Q_{k:,:} \\gets Q_{k:,:} - 2\\u\\left(\\u\\trp Q_{k:,:}\\right)$\n            \\Comment{Apply the reflection to $Q$.}\\label{step:HH-outer2}\n    \\EndFor\n    \\State \\pseudoli{return} $Q\\trp, R$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\label{Alg:QR-via-Householder}\n\\end{algorithm}\n\n\\begin{problem} % QR Decomposition via Householder Triangularization\nWrite a function that accepts as input a $m \\times n$ matrix $A$ of rank $n$.\nUse Algorithm \\ref{Alg:QR-via-Householder} to compute the full QR decomposition of $A$.\n\nConsider the following implementation details.\n\\begin{itemize}\n\n\\item NumPy's \\li{np.sign()} is an easy way to implement the $\\sign()$ operation in step \\ref{step:HH-sign}.\nHowever, \\li{np.sign(0)} returns $0$, which will cause a problem in the rare case that $u_0 = 0$ (which is possible if the top left entry of $A$ is $0$ to begin with).\nThe following code defines a function that returns the sign of a single number, counting $0$ as positive.\n\n\\begin{lstlisting}\nsign = lambda x: 1 if x >= 0 else -1\n\\end{lstlisting}\n\n\\item In steps \\ref{step:HH-outer1} and \\ref{step:HH-outer2}, the multiplication of $\\u$ and $(\\u\\trp X)$ is an \\emph{outer product} ($\\x\\y\\trp$ instead of the usual $\\x\\trp\\y$).\nUse \\li{np.outer()} instead of \\li{np.dot()} to handle this correctly.\n\n\\end{itemize}\n\nUse NumPy and SciPy to generate test cases and validate your function.\n\n\\begin{lstlisting}\n>>> A = np.random.random((5, 3))\n>>> Q,R = la.qr(A)                  # Get the full QR decomposition.\n>>> print(A.shape, Q.shape, R.shape)\n(5,3) (5,5) (5,3)\n>>> np.allclose(Q @ R, A)\n<<True>>\n\\end{lstlisting}\n\\label{prob:qr-via-hessenberg}\n\\end{problem}\n\n\\begin{comment}\n\\begin{info}\nHouseholder QR factorization is more numerically stable than modified Gram-Schmidt.\nHowever, modified Gram-Schmidt is still useful for some types of iterative methods because it finds the orthonormal basis one vector at a time instead of all at once.\n\\end{info}\n\\end{comment}\n\n\\section*{Upper Hessenberg Form} % ============================================\n\nAn \\emph{upper Hessenberg matrix} is a square matrix that is nearly upper triangular, with zeros below the first subdiagonal.\nEvery $n \\times n$ matrix $A$ can be written $A = QHQ\\trp$ where $Q$ is orthonormal and $H$, called the \\emph{Hessenberg form} of $A$, is an upper Hessenberg matrix.\nPutting a matrix in upper Hessenberg form is an important first step to computing its eigenvalues numerically.\n\nThis algorithm also uses Householder transformations.\nTo find orthogonal $Q$ and upper Hessenberg $H$ such that $A = QHQ\\trp$, it suffices to find such matrices that satisfy $Q\\trp A Q = H$.\nThus, the strategy is to multiply $A$ on the left and right by a series of orthonormal matrices until it is in Hessenberg form.\n\nUsing the same $Q_k$ as in the $k$th step of the Householder algorithm introduces $n - k$ zeros in the $k$th column of $A$, but multiplying $Q_k A$ on the right by $Q_k\\trp$ destroys all of those zeros.\nInstead, choose a $Q_1$ that fixes $\\e_1$ and reflects the first column of $A$ into the span of $\\e_1$ and $\\e_2$.\nThe product $Q_1A$ then leaves the first row of $A$ alone, and the product $(Q_1A)Q_1\\trp$ leaves the first column of $(Q_1A)$ alone.\n\\[\n\\begin{array}{ccccc}\n\\left[\\begin{array}{ccccc}\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n* & * & * & * & *\n\\end{array}\\right]\n&\\underrightarrow{Q_1}&\n\\left[\\begin{array}{ccccc}\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n0 & * & * & * & * \\\\\n0 & * & * & * & * \\\\\n0 & * & * & * & *\n\\end{array}\\right]\n&\\underrightarrow{Q_1\\trp }&\n\\left[\\begin{array}{ccccc}\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n0 & * & * & * & * \\\\\n0 & * & * & * & * \\\\\n0 & * & * & * & *\n\\end{array}\\right]\n\\\\\nA & & Q_1A & & (Q_1 A) Q_1\\trp\n\\end{array}\n\\]\nContinuing the process results in the upper Hessenberg form of $A$.\n%\n\\begin{equation*}\nQ_3 Q_2 Q_1 A Q_1\\trp Q_2 \\trp Q_3\\trp =\n\\left[\\begin{array}{ccccc}\n* & * & * & * & * \\\\\n* & * & * & * & * \\\\\n0 & * & * & * & * \\\\\n0 & 0 & * & * & * \\\\\n0 & 0 & 0 & * & *\n\\end{array}\\right]\n\\end{equation*}\n\nThis implies that $A = Q_1\\trp Q_2\\trp Q_3\\trp H Q_3 Q_2 Q_1$, so setting $Q = Q_1\\trp Q_2\\trp Q_3\\trp$ results in the desired factorization $A = QHQ\\trp$.\n\n\\subsection*{Constructing the Reflections} % ----------------------------------\n\nConstructing the $Q_k$ uses the same approach as in the Householder algorithm, but shifted down one element.\nLet $\\x_k = \\y_k' + \\y_k''$ where $\\y_k'$ and $\\y_k''$ are of the form\n\\[\n\\y_k' = \\left[z_1\\quad \\cdots\\quad z_k\\quad 0\\quad \\cdots\\quad 0\\right]\\trp,\n\\qquad\\qquad\n\\y_k'' = \\left[0\\quad\\cdots\\quad 0\\quad z_{k+1}\\quad\\cdots\\quad z_m\\right]\\trp.\n\\]\nBecause $\\y_k'$ represents elements of $A$ that lie above the first subdiagonal, only $\\y_k''$ needs to be altered.\nThis suggests using the reflection\n\\begin{gather*}\nQ_k =\n\\left[\\begin{array}{cc}\nI_k & \\0 \\\\\n\\0      & H_{\\v_k} \\\\\n\\end{array}\\right] =\n\\left[\\begin{array}{cc}\nI_k & \\0 \\\\\n\\0      & I_{m-k} - 2 \\u_k\\u_k\\trp \\\\\n\\end{array}\\right],\\textrm{ where}\n\\\\\n\\v_k = \\y_k'' + \\sign(z_k)\\|\\y_k''\\| \\e_k,\n\\qquad\\qquad\n\\u_k = \\frac{\\v_k}{\\|\\v_k\\|}.\n\\end{gather*}\n\nThe complete algorithm is given below.\nNote how similar it is to Algorithm \\ref{Alg:QR-via-Householder}.\n% Although the Hessenberg form exists for any square matrix, this algorithm only works for full-rank square matrices.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{Hessenberg}{$A$}\n    \\State $m, n \\gets \\shape{A}$\n    \\State $H \\gets \\makecopy{A}$\n    \\State $Q \\gets I_{m}$\n    \\For{$k=0 \\ldots n-3$}\n        \\State $\\u \\gets \\makecopy{H_{k+1:,k}}$\n        \\State $u_0 \\gets u_0 + \\sign(u_0)\\|\\u\\|$\n        \\State $\\u \\gets \\u/\\|\\u\\|$\n        \\State $H_{k+1:,k:} \\gets H_{k+1:,k:} - 2\\u(\\u\\trp H_{k+1:,k:})$\n            \\Comment{Apply $Q_k$ to $H$.}\n        \\State $H_{:,k+1:} \\gets H_{:,k+1:} - 2(H_{:,k+1:} \\u) \\u\\trp$\n            \\Comment{Apply $Q_k\\trp$ to $H$.}\n        \\State $Q_{k+1:,:} \\gets Q_{k+1:,:} - 2\\u(\\u\\trp Q_{k+1:,:})$\n            \\Comment{Apply $Q_k$ to $Q$.}\n    \\EndFor\n    \\State \\pseudoli{return} $H, Q\\trp$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\label{Alg:Upper-Hessenberg-Form}\n\\end{algorithm}\n\n\\begin{problem} % Reduce a matrix to upper Hessenberg form.\nWrite a function that accepts a nonsingular $n \\times n$ matrix $A$.\nUse Algorithm \\ref{Alg:Upper-Hessenberg-Form} to compute the upper Hessenberg $H$ and orthogonal $Q$ satisfying $A = QHQ\\trp$.\n\nCompare your results to \\li{scipy.linalg.hessenberg()}.\n\n\\begin{lstlisting}\n# Generate a random matrix and get its upper Hessenberg form via SciPy.\n>>> A = np.random.random((8,8))\n>>> H, Q = la.hessenberg(A, calc_q=True)\n\n# Verify that H has all zeros below the first subdiagonal and QHQ^T = A.\n>>> np.allclose(np.triu(H, -1), H)\n<<True>>\n>>> np.allclose(Q @ H @ Q.T, A)\n<<True>>\n\\end{lstlisting}\n\\label{prob:hessenberg-via-householder}\n\\end{problem}\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Complex QR Decomposition} % --------------------------------------\n\nThe QR decomposition also exists for matrices with complex entries.\nThe standard inner product in $\\mathbb{R}^m$ is $\\langle \\x,\\y \\rangle = \\x\\trp \\y$, but the (more general) standard inner product in $\\mathbb{C}^m$ is $\\langle \\x,\\y \\rangle = \\x\\hrm \\y$.\nThe $\\hrm$ stands for the \\emph{Hermitian conjugate}, the conjugate of the transpose.\nMaking a few small adjustments in the implementations of Algorithms \\ref{Alg:modified-Gram-Schmidt} and \\ref{Alg:QR-via-Householder} accounts for using the complex inner product.\n\n\\begin{enumerate}\n\n\\item Replace any transpose operations with the conjugate of the transpose.\n\n\\begin{lstlisting}\n>>> A = np.reshape(np.arange(4) + 1j*np.arange(4), (2,2))\n>>> print(A)\n[[ 0.+0.j  1.+1.j]\n [ 2.+2.j  3.+3.j]]\n\n>>> print(A.T)                      # Regular transpose.\n[[ 0.+0.j  2.+2.j]\n [ 1.+1.j  3.+3.j]]\n\n>>> print(A.conj().T)               # Hermitian conjugate.\n[[ 0.-0.j  2.-2.j]\n [ 1.-1.j  3.-3.j]]\n\\end{lstlisting}\n\n\\item Conjugate the first entry of vector or matrix multiplication before multiplying with \\li{np.dot()}.\n\n\\begin{lstlisting}\n>>> x = np.arange(2) + 1j*np.arange(2)\n>>> print(x)\n[ 0.+0.j  1.+1.j]\n\n>>> np.dot(x, x)                    # Standard real inner product.\n2j\n\n>>> np.dot(x.conj(), y)             # Standard complex inner product.\n(2 + 0j)\n\\end{lstlisting}\n\n\\item In the complex plane, there are infinitely many reflections that map a vector $\\x$ into the span of $\\e_k$, not just the two displayed in Figure \\ref{fig:householder-two-possible-reflectors}.\nUsing $\\sign(z_k)$ to choose one is still a valid method, but it requires updating the \\li{sign()} function so that it can handle complex numbers.\n\n\\begin{lstlisting}\nsign = lambda x: 1 if np.real(x) >= 0 else -1\n\\end{lstlisting}\n\n\\end{enumerate}\n\n\\subsection*{QR with Pivoting} % ----------------------------------------------\n\nThe LU decomposition can be improved by employing Gaussian elimination with partial pivoting, where the rows of $A$ are strategically permuted at each iteration.\nThe QR factorization can be similarly improved by permuting the columns of $A$ at each iteration.\nThe result is the factorization $AP = QR$, where $P$ is a permutation matrix that encodes the column swaps.\nTo compute the pivoted QR decomposition with \\li{scipy.linalg.qr()}, set the keyword \\li{pivoting} to \\li{True}.\n\n\\begin{lstlisting}\n# Get the decomposition AP = QR for a random matrix A.\n>>> A = np.random.random((8,10))\n>>> Q,R,P = la.qr(A, pivoting=True)\n\n# P is returned as a 1-D array that encodes column ordering,\n# so A can be reconstructed with fancy indexing.\n>>> np.allclose(Q @ R, A[:,P])\n<<True>>\n\\end{lstlisting}\n\n\\begin{comment}\n\\subsection*{Stability of the QR Decomposition in SciPy} % --------------------\n\nSciPy's QR factorization routine uses Householder reflections.\nThough this routine is numerically stable, there are still potential numerical problems.\nConsider the following example.\n\n\\begin{lstlisting}\n# Generate a random orthonormal matrix and a random upper-triangular matrix.\n>>> Q, _ = la.qr(np.random.normal(size=(500,500)))\n>>> R  = np.triu(np.random.normal(size=(500,500)))\n\n# Calculate A = QR, noting that Q and R are the EXACT QR decomposition of A.\n>>> A = Q @ R\n\n# Use SciPy to rediscover the QR decomposition of A.\n>>> Q1, R1 = la.qr(A)\n\n# Compare the true Q and R to the computed Q1 and R1.\n>>> print(la.norm(Q1-Q, <<ord>>=np.inf) / la.norm(Q, <<ord>>=np.inf))\n1.21169651649\n\n>>> print(la.norm(R1-R, <<ord>>=np.inf) / la.norm(R, <<ord>>=np.inf))\n1.72312747194\n\\end{lstlisting}\n\nThis is terrible!\nThis algorithm works in $16$ decimal points of precision, but $Q_1$ and $R_1$ are accurate to $0$ decimal points.\nThese errors in $Q_1$ and $R_1$ are called \\emph{forward errors}.\nEven so, miraculously, the product $Q_1 R_1$ is very close $A$.\n\n\\begin{lstlisting}\n>>> A1 = Q1 @ R1\n>>> la.norm(A1 - A, <<ord>>=np.inf) / la.norm(A, <<ord>>=np.inf)\n3.353843164496928e-15\n\\end{lstlisting}\n\nThe error in $A_1$, called the \\emph{backward error}, is very small.\nThis shows that the errors in $Q_1$ and $R_1$ are somehow ``correlated,'' so that they cancel out in the product.\nIn fact, the large errors in $Q_1$ and $R_1$ are not because the algorithm is bad, but rather because $A$ was \\emph{poorly conditioned} to begin with.\nConditioning and stability will be discussed more in depth later in the curriculum.\n\\end{comment}\n\n\\subsection*{QR via Givens} % -------------------------------------------------\n\nThe Householder algorithm uses reflections to triangularize $A$.\nHowever, $A$ can also be made upper triangular using rotations.\nTo illustrate the idea, recall that the matrix for a counterclockwise rotation of $\\theta$ radians is given by\n\\[\nR_\\theta =\n\\left[\\begin{array}{cc}\n\\cos\\theta & -\\sin\\theta \\\\\n\\sin\\theta &  \\cos\\theta\n\\end{array}\\right].\n\\]\n\nThis transformation is orthonormal.\nGiven $\\x = \\left[a, b\\right]\\trp$, if $\\theta$ is the angle between $\\x$ and $\\e_1$, then $R_{-\\theta}$ maps $\\x$ to the span of $\\e_1$.\n\n\\begin{figure}[H]\n\\centering\n\\begin{tikzpicture}\n    \\draw[-, thick](-.5,0)--(3,0);\n    \\draw[-, thick](0,-.5)--(0,1.5);\n    \\draw[->, thick, >=stealth'](0,0)--(2.5,1);\n    \\draw[-,thick](2.5,-.2)--(2.5,.2);\n    \\draw[-, thick](-.2,1)--(.2,1);\n    \\node[draw=none](point_b)at(2.5,-.4){$a$};\n    \\node[draw=none](point_a)at(-.4,1){$b$};\n    \\draw[-, thick] (.5,.2)arc [start angle=60, end angle=-20, radius=4.5pt];\n    \\node[draw=none](theta)at(.85, .18){$\\theta$};\n\\end{tikzpicture}\n\\caption{Rotating clockwise by $\\theta$ sends the vector $\\left[a,b\\right]\\trp$ to the span of $\\e_1$.}\n\\label{fig:Givens-rotation}\n\\end{figure}\n\nIn terms of $a$ and $b$, $\\cos \\theta =  \\frac{a}{\\sqrt{a^2+b^2}}$ and $\\sin\\theta = \\frac{b}{\\sqrt{a^2+b^2}}$.\nTherefore,\n\\[\nR_{-\\theta}\\x\n=\n\\left[\\begin{array}{cc}\n\\cos\\theta  & \\sin\\theta \\\\\n-\\sin\\theta & \\cos\\theta \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{c} a \\\\ b \\end{array}\\right]\n=\n\\left[\\begin{array}{cc}\n \\frac{a}{\\sqrt{a^2+b^2}} & \\frac{b}{\\sqrt{a^2+b^2}} \\\\ \\\\\n-\\frac{b}{\\sqrt{a^2+b^2}} & \\frac{a}{\\sqrt{a^2+b^2}} \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{c} a \\\\ b \\end{array}\\right]\n=\n\\left[\\begin{array}{c} \\sqrt{a^2+b^2} \\\\ 0 \\end{array}\\right].\n\\]\n\nThe matrix $R_{\\theta}$ above is an example of a $2 \\times 2$ \\emph{Givens rotation matrix}.\nIn general, the Givens matrix $G(i,j,\\theta)$ represents the orthonormal transformation that rotates the 2-dimensional span of $\\e_i$ and $\\e_j$ by $\\theta$ radians.\nThe matrix representation of this transformation is a generalization of $R_\\theta$.\n\\[\nG(i,j,\\theta) =\n\\left[\\begin{array}{ccccc}\nI & 0 & 0 & 0 & 0 \\\\\n0 & c & 0 & -s & 0 \\\\\n0 & 0 & I & 0 & 0 \\\\\n0 & s & 0 & c & 0 \\\\\n0 & 0 & 0 & 0 & I\n\\end{array}\\right]\n\\]\n\nHere $I$ represents the identity matrix, $c=\\cos \\theta$, and $s=\\sin \\theta$.\nThe $c$'s appear on the $i$th and $j$th diagonal entries.\n\n\\subsubsection*{Givens Triangularization} % - - - - - - - - - - - - - - - - - -\n\nAs demonstrated, $\\theta$ can be chosen such that $G(i,j,\\theta)$ rotates a vector so that its $j$th-component is 0.\nSuch a transformation will only affect the $i$th and $j$th entries of any vector it acts on (and thus the $i$th and $j$th rows of any matrix it acts on).\n\nTo compute the QR decomposition of $A$, iterate through the subdiagonal entries of $A$ in the order depicted by Figure \\ref{fig:Givens-iteration-order}.\nZero out the $ij$th entry with a rotation in the plane spanned by $\\e_{i-1}$ and $\\e_i$, represented by the Givens matrix $G(i-1,i,\\theta)$.\n\n\\begin{figure}[H]\n\\centering\n\\begin{tikzpicture}[xscale=.7, yscale=.7]\n    \\draw[->, gray, thick](0,0)--(0,5.5);\n    \\draw[->, gray, thick](1,0)--(1,4.5);\n    \\draw[->, gray, thick](2,0)--(2,3.5);\n    \\draw[->, gray, thick](3,0)--(3,2.5);\n    \\draw[->, gray, thick](4,0)--(4,1.5);\n    \\node[draw=none] at(0,-1){\\large 1};\n    \\node[draw=none] at(1,-1){\\large 2};\n    \\node[draw=none] at(2,-1){\\large 3};\n    \\node[draw=none] at(3,-1){\\large 4};\n    \\node[draw=none] at(4,-1){\\large 5};\n\n    \\draw[-, ultra thick] (0,6)--(4,2);\n\n    \\draw[-, thick](-1,-.5)--(-1,6.5);\n    \\draw[-, thick](-1, -.5)--(-.5,-.5);\n    \\draw[-, thick](-1,6.5)--(-.5,6.5);\n\n    \\draw[-, thick](5,-.5)--(5,6.5);\n    \\draw[-, thick](5,-.5)--(4.5,-.5);\n    \\draw[-, thick](5,6.5)--(4.5,6.5);\n\\end{tikzpicture}\n\\caption{The order in which to zero out subdiagonal entries in the Givens triangularization algorithm.\nThe heavy black line is the main diagonal of the matrix.\nEntries should be zeroed out from bottom to top in each column, beginning with the leftmost column.}\n\\label{fig:Givens-iteration-order}\n\\end{figure}\n\nOn a $2 \\times 3$ matrix, the process can be visualized as follows.\n\\[\n\\left[\\begin{array}{cc}\n* & * \\\\\n* & * \\\\\n* & * \\\\\n\\end{array}\\right]\n\\underrightarrow{G(2,3,\\theta_1)}\n\\left[\\begin{array}{cccc}\n&      *  &      *  & \\\\\n\\cline{2-3}\n& \\lvl{*} & \\rvl{*} & \\\\\n& \\lvl{0} & \\rvl{*} & \\\\\n\\cline{2-3}\n\\end{array}\\right]\n\\underrightarrow{G(1,2,\\theta_2)}\n\\left[\\begin{array}{cccc}\n\\cline{2-3}\n& \\lvl{*} & \\rvl{*} & \\\\\n& \\lvl{0} & \\rvl{*} & \\\\\n\\cline{2-3}\n&      0  &      *  & \\\\\n\\end{array}\\right]\n\\underrightarrow{G(2,3,\\theta_3)}\n\\left[\\begin{array}{ccc}\n     * &       *  & \\\\\n\\cline{2-2}\n\\rvl{0} & \\rvl{*} & \\\\\n\\rvl{0} & \\rvl{0} & \\\\\n\\cline{2-2}\n\\end{array}\\right]\n\\]\nAt each stage, the boxed entries are those modified by the previous transformation.\nThe final transformation $G(2,3,\\theta_3)$ operates on the bottom two rows, but since the first two entries are zero, they are unaffected.\n\nAssuming that at the $ij$th stage of the algorithm $a_{ij}$ is nonzero, Algorithm \\ref{Alg:QR-via-Givens} computes the Givens triangularization of a matrix.\nNotice that the algorithm does not actually form the entire matrices $G(i,j,\\theta)$; instead, it modifies only those entries of the matrix that are affected by the transformation.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{Givens Triangularization}{$A$}\n\\State $m, n \\gets \\shape{A}$\n\\State $R \\gets \\makecopy{A}$\n\\State $Q \\gets I_{m}$\n\\For{$j=0\\ldots n-1$}\n    \\For{$i=m-1\\ldots j+1$}\n      \\State $a, b \\gets R_{i-1,j}, R_{i,j}$\n      \\State $G \\gets [[a, b],[-b,a]]/\\sqrt{a^2+b^2}$\n      \\State $R_{i-1:i+1,j:} \\gets GR_{i-1:i+1, j:}$\n      \\State $Q_{i-1:i+1,:} \\gets GQ_{i-1:i+1,:}$\n    \\EndFor\n\\EndFor\n\\State \\pseudoli{return} $Q\\trp , R$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\label{Alg:QR-via-Givens}\n\\end{algorithm}\n\n\\begin{comment}\n\\begin{info} % Advantages and disadvantages of Givens\nLike Householder transformations, Givens rotations are orthonormal, and therefore numerically stable.\nIn addition, they affect only a small part of the array at each iteration, making them ideal for some problems.\n\nIn general, however, Algorithm \\ref{Alg:QR-via-Givens} requires more floating point operations than Algorithm \\ref{Alg:QR-via-Householder}.\nOn the other hand, the Givens algorithm can be \\emph{parallelized}, meaning that multiple processors can be used to simultaneously carry out different iterations of the algorithm.\n\\end{info}\n\\end{comment}\n\n\\subsubsection*{QR of a Hessenberg Matrix via Givens} % - - - - - - - - - - - -\n\nThe Givens algorithm is particularly efficient for computing the QR decomposition of a matrix that is already in upper Hessenberg form, since only the first subdiagonal needs to be zeroed out.\nAlgorithm \\ref{Alg:QR-of-Hessenberg-via-Givens} details this process.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{Givens Triangularization of Hessenberg}{$H$}\n\\State $m, n \\gets \\shape{H}$\n\\State $R \\gets \\makecopy{H}$\n\\State $Q \\gets I_{m}$\n\\For{$j=0\\ldots \\min\\{n-1, m-1\\}$}\n    \\State $i = j+1$\n    \\State $a, b \\gets R_{i-1,j}, R_{i,j}$\n    \\State $G \\gets [[a, b],[-b,a]]/\\sqrt{a^2+b^2}$\n    \\State $R_{i-1:i+1,j:} \\gets GR_{i-1:i+1, j:}$\n    \\State $Q_{i-1:i+1,:i+1} \\gets GQ_{i-1:i+1,:i+1}$\n\\EndFor\n\\State \\pseudoli{return} $Q\\trp , R$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\label{Alg:QR-of-Hessenberg-via-Givens}\n\\end{algorithm}\n\n\\begin{info} % Hessenberg of Symmetric -> Tridiagonal.\nWhen $A$ is symmetric, its upper Hessenberg form is a \\emph{tridiagonal} matrix, meaning its only nonzero entries are on the main diagonal, the first subdiagonal, and the first superdiagonal.\nThis is because the $Q_k$'s zero out everything below the first subdiagonal of $A$ and the $Q_k\\trp$'s zero out everything to the right of the first superdiagonal.\nTridiagonal matrices make computations fast, so computing the Hessenberg form of a symmetric matrix is very useful.\n\\end{info}\n", "meta": {"hexsha": "c80a4fe421a226d6fb209b05f5a09c8000bd01bb", "size": 38005, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume1/QR_Decomposition/QR_Decomposition.tex", "max_stars_repo_name": "chrismmuir/Labs-1", "max_stars_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 190, "max_stars_repo_stars_event_min_datetime": "2015-07-17T01:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T19:16:19.000Z", "max_issues_repo_path": "Volume1/QR_Decomposition/QR_Decomposition.tex", "max_issues_repo_name": "chrismmuir/Labs-1", "max_issues_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 184, "max_issues_repo_issues_event_min_datetime": "2015-07-16T17:56:06.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T23:47:14.000Z", "max_forks_repo_path": "Volume1/QR_Decomposition/QR_Decomposition.tex", "max_forks_repo_name": "chrismmuir/Labs-1", "max_forks_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 76, "max_forks_repo_forks_event_min_datetime": "2015-08-06T02:53:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T11:08:57.000Z", "avg_line_length": 42.4636871508, "max_line_length": 253, "alphanum_fraction": 0.6374424418, "num_tokens": 12856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8128673133042217, "lm_q2_score": 0.9124361539289199, "lm_q1q2_score": 0.7416895250058383}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage[colorlinks]{hyperref}\n\n\\newcommand{\\vx}[0]{\\mathbf{x}}\n\n\\author{Mika Illouz}\n\\title{EigenDog's \\texttt{dawg}}\n\n\\begin{document}\n\n\\maketitle\n\nEigenDog's implementation of {\\bf Gradient Boosting Trees}, called\n\\texttt{dawg} follows the mathematical description in Friedman's 1999\npaper \\cite{GBM}.\n\nFollowing Friedman's notation, our training set is represented by\n$(y_i, \\vx_i)$ where $i = 1 \\ldots n$: We have $n$ records, each\nrecord $i$ consists of an outcome (aka response) $y_i$ and feature\nvector $\\vx_i$.  In the general \\texttt{dawg} formulation the objective is to\nminimize the loss function $Q$:\n%\n\\begin{equation}\n\\label{objective}\nQ = \\sum_{i=1}^{n} L(y_i, F(\\vx_i))\n\\end{equation}\n%\nIn this context context, $y \\in \\{ -1, 1 \\}$ and\n%\n\\[\nL(y,F) = \\log ( 1 + \\exp( -2 y F ) )\n\\]\n$L$ is know as the {\\bf deviance} or {\\bf cross-entropy.}  $F$ is the\nobject we want to construct.  The probability of classifications are:\n\\begin{equation}\n\\begin{split}\np(y =1|\\vx) &= \\frac{1}{1 + \\exp(-2 F(\\vx) )} \\\\\np(y =-1|\\vx) &= 1 - p(y=1|\\vx) = \\frac{1}{1 + \\exp(2 F(\\vx) )} \\\\\n\\end{split}\n\\end{equation}\n\nSome intuition about function $L(y,F)$:\nfirst, $\\log( 1 + \\exp (\\bullet) )$ is always positive, since\n$\\exp(\\bullet) \\ge 0$.  When $y=1$ and $F \\rightarrow \\infty$, the\nquantity $\\exp ( -2 y F ) \\rightarrow 0$ and $L(y, F) \\rightarrow 0$.\nSo, to drive $L(y, F)$ closer to zero (which is its floor) when\n$y_i=1$, we want to increase $F$.  Similarly, when $y=-1$, decreasing\n$F \\rightarrow -\\infty$ drives $L(y, F)$ closer to zero.  In either\ncase, increasing the magnitude of $F$ in the same direction as $y$\nreduces $L(y,F)$.  Similarly, when $y$ and $F$ have opposite signs and\n$| F | \\rightarrow \\infty$ then $L(y,F) \\rightarrow \\infty$.\n\nIn \\texttt{dawg}, the function $F(\\vx)$ is a sum of $K+1$ decision trees:\n\\[\nF(\\vx) = \\sum_{k=0}^K F_k(\\vx)\n\\]\nMore precisely, each $F_k(\\vx)$ is a binary decision trees, so that\neach of its non-leaf nodes has two child trees, called the {\\bf left}\nand {\\bf right} sub-trees.  A decision tree is a piecewise constant\nfunction, where a leaf node represents one of the constant pieces, and\na non-leaf node represent a decision over the value of a single\nfeature $\\vx^j$.  (Notation: whereas $\\vx_i$ is the $i$-th row of the\ntraining set, $\\vx^j$ is the $j$-th feature/column).\n\nThe ``boosting'' in \\texttt{dawg} refers to the fact that in each iteration $k$,\na new decision tree is constructed that improves upon the previously\nconstructed function defined by the sequence of trees $F_0, \\ldots,\nF_{k-1}$.  The essential (and inductive) question in \\texttt{dawg} is: having\nconstructed these trees, what ought the {\\em next} tree be?\n\n\\paragraph{Feature Splitting}\n\nTo build the next tree, we must partition the population of records\ninto two subsets.  To build deeper trees, we must recursively\npartition each subset.  With each recursion, we must answer the\nquestion: were we to stop recursion here -- and therefore build a pair\nof leaf nodes -- what would be their constant values?  We denote the\nleaf's constant value as $\\gamma$, with $\\gamma_L$ being the left\nvalue, and $\\gamma_R$ being the right one.  Over a subset of records\n$S$, we want to choose a value for $\\gamma$ so that the loss function\nin equation [\\ref{objective}] is minimized.  For each record $i$ in\n$S$, $\\gamma$ would be added to sum of the all previously constructed\ntrees $F_k(\\vx_i)$.  So our goal is to find a $\\gamma^*$:\n%\n\\[\n\\gamma^* = \\arg \\min_\\gamma \\sum_{i \\in S} L\n  \\bigg[\n    y_i, \\bigg\\{ \\sum_{k=0}^K F_k(\\vx_i) \\bigg\\} + \\gamma\n  \\bigg]\n\\]\nTo simplify the presentation, we'll define $F_i^K \\equiv \\sum_{k=0}^K\nF_k(\\vx_i)$, which is the value of the record $i$ evaluated over the\nsum of all the decision trees constructed thus far:\n%\n\\[\n\\gamma^* = \\arg \\min_\\gamma \\sum_{i \\in S} L\n  \\bigg[ y_i, F_i^K + \\gamma \\bigg]\n\\]\n%\nFinding the best $\\gamma$, $\\gamma^*$, is univariate minimization\nproblem because $y_i$ and $F_i^K$ are all fixed.  Furthermore, it\nturns out that we don't need the optimal $\\gamma^*$, just a decent\napproximation $\\hat \\gamma \\approx \\gamma^*$.  In his paper, Friedman\ndeclares (without giving proof) that this approximation is:\n\\[\n\\hat \\gamma =\n  \\frac { \\sum_{i \\in S} z_i } { \\sum_{i \\in S} | z_i | ( 2 - | z_i | ) }\n\\]\nwhere\n\\[\nz_i \\equiv \\frac{ 2 y_i } { 1 + \\exp [ 2 y_i F_i^K ] }\n\\]\nare called the {\\em pseudo-response}.\n\n\\paragraph{Proof}\n\nThe proof is as follows: we model $Q(\\gamma)$ using a local quadratic\napproximation defined by the Taylor series expansion.  The textbook\ndefinition of a Taylor series expansion centered at zero (actually\nknown as the Maclaurin series) is:\n\\[\nf(x) = f(0) + f'(0)x + f''(0)x^2/2! + \\cdots\n\\]\nApplying this to $Q(\\gamma)$, we have:\n\\begin{equation*}\nQ(\\gamma) = Q(0) + Q'(0)\\gamma + Q''(0)\\gamma^2/2! + \\cdots \\\\\n\\end{equation*}\nThen dropping the higher-order terms, we have the quadratic\napproximation:\n\\begin{equation}\nQ(\\gamma) \\approx Q(0) + Q'(0)\\gamma + Q''(0)\\gamma^2/2! \\\\\n\\label{Q-quad}\n\\end{equation}\n\nSince we are no longer minimizing $Q(\\gamma)$ exactly, but rather an\napproximation of that function, the resulting $\\hat \\gamma$ will be\nalso be an approximation of the true minimizer $\\gamma^*$.  The\nminimizer of $Q(\\gamma)$ must satisfy $Q'(\\hat \\gamma)=0$, and, taking\nthis first derivative results in the condition $Q'(0) + Q''(0)\\hat\n\\gamma = 0$ or\n\\[\n\\hat \\gamma = -\\frac{ Q'(0) }{ Q''(0) }\n\\]\nThis approximation might initially seem crude. However, one must view\nthis in the context of the broader \\texttt{dawg} algorithm, in which each new\ndecision tree addresses the shortcomings of the previous ones.\nTherefore, a crude selection of $\\gamma$ in one branch of one tree is\ncorrected in the tree-building iterations that follow it.  In fact,\nsince the \\texttt{dawg} model improves with each new tree, we expect the leaf\nvalues necessary to make further improvements to shrink in magnitude.\nIn other words, as $k \\rightarrow \\infty$, $\\gamma \\rightarrow 0$.\n\nWe now derive expressions for $Q'(0)$ and $Q''(0)$:\n\n\\begin{equation*}\n\\begin{split}\nQ'(\\gamma) &= \\frac {\\partial Q}{\\partial \\gamma} \\\\\n&= \\frac{\\partial}{\\partial \\gamma} \\sum_{i \\in S} L \\bigg[ y_i, F_i^K + \\gamma \\bigg] \\\\\n&= \\frac{\\partial}{\\partial \\gamma} \\sum_{i \\in S} \\log \\big( 1 + \\exp [ -2 y_i (F_i^K + \\gamma) ] \\big) \\\\\n&= \\sum_{i \\in S} \\frac{\\partial}{\\partial \\gamma} \\log \\big( 1 + \\exp [ -2 y_i (F_i^K + \\gamma) ] \\big) \\\\\n&= \\sum_{i \\in S} \\big( 1 + \\exp [ -2 y_i (F_i^K + \\gamma) ] \\big)^{-1} \\frac{\\partial}{\\partial \\gamma} \\big( 1 + \\exp [ -2 y_i (F_i^K + \\gamma) ] \\big) \\\\\n&= \\sum_{i \\in S} \\big( 1 + \\exp [ -2 y_i (F_i^K + \\gamma) ] \\big)^{-1}  \\exp [ -2 y_i (F_i^K + \\gamma) ] \\big( -2 y_i \\big) \\\\\n&= \\sum_{i \\in S} \\frac{  \\big( -2 y_i \\big) \\exp [ -2 y_i (F_i^K + \\gamma) ] } { 1 + \\exp [ -2 y_i (F_i^K + \\gamma) ] } \\\\\n&= \\sum_{i \\in S} \\frac{  -2 y_i \\exp [ -2 y_i (F_i^K + \\gamma) ] } { 1 + \\exp [ -2 y_i (F_i^K + \\gamma) ] } \\times\n   \\frac { \\exp [ 2 y_i (F_i^K + \\gamma) ] } { \\exp [ 2 y_i (F_i^K + \\gamma) ] } \\\\\n&= \\sum_{i \\in S} \\frac{ -2 y_i } { \\exp [ 2 y_i (F_i^K + \\gamma) ] + 1 } \\\\\n\\end{split}\n\\end{equation*}\n\nNow the second derivative:\n\n\\begin{equation*}\n\\begin{split}\nQ''(\\gamma) &= \\frac {\\partial Q'}{\\partial \\gamma} \\\\\n&= \\frac {\\partial}{\\partial \\gamma} \\sum_{i \\in S} \\frac{ -2 y_i } { \\exp [ 2 y_i (F_i^K + \\gamma) ] + 1 } \\\\\n&= \\sum_{i \\in S} (-2 y_i ) \\frac {\\partial}{\\partial \\gamma} \\bigg( \\exp [ 2 y_i (F_i^K + \\gamma) ] + 1 \\bigg)^{-1} \\\\\n&= \\sum_{i \\in S} (-2 y_i ) (-1) \\bigg( \\exp [ 2 y_i (F_i^K + \\gamma) ] + 1 \\bigg)^{-2} \\frac {\\partial}{\\partial \\gamma} \\bigg( \\exp [ 2 y_i (F_i^K + \\gamma) ] + 1 \\bigg) \\\\\n&= \\sum_{i \\in S} (-2 y_i ) (-1) \\bigg( \\exp [ 2 y_i (F_i^K + \\gamma) ] + 1 \\bigg)^{-2} \\exp [ 2 y_i (F_i^K + \\gamma) ] ( 2 y_i ) \\\\\n&= \\sum_{i \\in S} \\frac{ (2 y_i)^2 } { \\bigg( \\exp [ 2 y_i (F_i^K + \\gamma) ] + 1 \\bigg)^2 } \\times \\exp [ 2 y_i (F_i^K + \\gamma) ] \\\\\n\\end{split}\n\\end{equation*}\n\nSince we are interested in $Q'(0)$, $Q''(0)$, we now simplify with\n$\\gamma=0$:\n\\begin{equation*}\n\\begin{split}\nQ'(0) &= \\sum_{i \\in S} \\frac{ -2 y_i } { \\exp [ 2 y_i F_i^K ] + 1 } = - \\sum_{i \\in S} \\frac{ 2 y_i } { \\exp [ 2 y_i F_i^K ] + 1 } \\\\\nQ''(0) &= \\sum_{i \\in S} \\frac{ (2 y_i)^2 } { \\bigg( \\exp [ 2 y_i F_i^K ] + 1 \\bigg)^2 } \\times \\exp [ 2 y_i F_i^K ] \\\\\n\\end{split}\n\\end{equation*}\nThen, conveniently defining\n\\begin{equation*}\nz_i \\equiv \\frac{ 2 y_i } { 1 + \\exp [ 2 y_i F_i^K ] }\n\\end{equation*}\nwe get\n\\begin{equation*}\n\\begin{split}\nQ'(0) &= - \\sum_{i \\in S} z_i \\\\\nQ''(0) &= \\sum_{i \\in S} z_i^2 \\exp [ 2 y_i F_i^K ] \\\\\n\\end{split}\n\\end{equation*}\nNote from the definition of $z_i$ that $2 y_i = z_i ( 1 + \\exp [ 2 y_i\n  F_i^K ] )$ and therefore $\\exp [ 2 y_i F_i^K ] = 2y_i/z_i - 1 =\n(2y_i - z_i)/z_i$.  So,\n\\begin{equation*}\nQ''(0) = \\sum_{i \\in S} z_i^2 \\frac{ 2 y_i - z_i }{ z_i } = \\sum_{i \\in S} z_i ( 2 y_i - z_i ) = \\sum_{i \\in S} ( 2 y_i z_i - z_i^2 )\n\\end{equation*}\nAlso note that\n\\begin{equation*}\ny_i z_i = y_i \\frac{ 2 y_i } { 1 + \\exp [ 2 y_i F_i^K ] } = \\frac{ 2 y_i^2 } { 1 + \\exp [ 2 y_i F_i^K ] }\n\\end{equation*}\nHowever, since $y_i$ is always either $1$ or $-1$, $y_i^2 = 1$, and so\n$y_i z_i = | z_i |$.  Substituting this into $Q''(0)$, we have\n\\begin{equation*}\nQ''(0) = \\sum_{i \\in S} ( 2 | z_i | - z_i^2 ) = \\sum_{i \\in S} ( 2 | z_i | - | z_i | ^2 ) = \\sum_{i \\in S} | z_i | ( 2 - | z_i | )\n\\end{equation*}\nFinally, we can confirm Friedman's approximation for the optimal $\\gamma$:\n\\begin{equation*}\n\\hat \\gamma\n  = - \\frac{ Q'(0) }{ Q''(0) }\n  = - \\frac{ - \\sum_{i \\in S} z_i }{ \\sum_{i \\in S} | z_i | ( 2 - | z_i | ) }\n  = \\frac{ \\sum_{i \\in S} z_i }{ \\sum_{i \\in S} | z_i | ( 2 - | z_i | ) }\n\\end{equation*}\n\n\\paragraph{Optimal Loss}\n\nI'll define $N$ and $D$ denoting numerator and denominator:\n\\begin{equation*}\n\\begin{split}\nN(S) &= \\sum_{i \\in S} z_i \\\\\nD(S) &= \\sum_{i \\in S} | z_i | ( 2 - | z_i | ) \\\\\n\\end{split}\n\\end{equation*}\nand then $\\hat \\gamma = N(S)/D(S)$.\n\nThe non-leaf nodes in the tree we are constructing are labeled with\nthe identity of a feature $x^j$ and a rule for deciding whether\nevaluation should proceed to the left or right sub-tree.  For features\nthat are ordered, this decision takes the form of $x^j \\le \\alpha$\n(where $\\alpha =$ is also known as the {\\bf split}.  A split\npartitions a population of records into two subsets $S_L$ and its\ncomplement $S_R$.  For each subset, we can compute $\\gamma_L$ and\n$gamma_R$ resp., which would reveal the leaf values for a branch of\nthe decision tree.  we could also determine what the loss of\npopulation of records would be under the split:\n\\[\nQ(\\hat \\gamma) = Q_L( \\hat \\gamma_L) + Q_R( \\hat \\gamma_R ) =\n\\sum_{i \\in S_L} L [ y_i, F_i^K + \\gamma_L ] +\n\\sum_{i \\in S_R} L [ y_i, F_i^K + \\gamma_R ]\n\\]\nA feature with $M$ distinct values has $M-1$ candidate splits.  By\nevaluating $Q(\\hat \\gamma)$ for each the candidate splits (and\ncorrespondingly, the partition $S_L$ and $S_R$ that would result from\nthe split), we can identify a split associated with the minimum loss\n$Q$.  Similarly, determining the optimum split and corresponding loss\nof each feature in the training set, we can identify the feature\nassociated with the minimum loss.  Exhaustively determining $\\gamma$\nand the resulting loss for each candidate split and for each feature\nis the key computation in \\texttt{dawg}.\n\nComputing $Q(\\hat \\gamma)$ exactly is expensive; fortunately our local\nquadratic approximation \\ref{Q-quad} is already available:\n\\begin{equation*}\n\\begin{split}\nQ(\\hat \\gamma) &\\approx\n  Q(0) +\n  \\hat \\gamma ( - N ) +\n  \\frac{1}{2} \\hat \\gamma^2 ( D ) \\\\\n&= Q(0) + \\frac{N}{D} (-N) +   \\frac{1}{2} \\big( \\frac{N}{D} \\big)^2 ( D ) \\\\\n&= Q(0) - \\frac{N^2}{D} + \\frac{1}{2} \\frac{N^2}{D} \\\\\n&= Q(0) - \\frac{1}{2} \\frac{N^2}{D}\n\\end{split}\n\\end{equation*}\n\n\n\\paragraph{Ordinal Features}\n\nFor an ordered feature, we can efficiently compute $\\hat \\gamma$ and\nloss $Q(\\hat \\gamma)$ for all possible splits.  For example, the 11-th\nfeature $\\vx^{11}$ of a training set consisting of 7 records is\n$\\vx^{11} = [5,1000,21,5,1000,5,5]^T$.  $\\vx^{11}$ has three distinct\nvalues $\\{5,21,1000\\}$, and correspondingly, two possible splits:\n$x^{11} \\le 5$ and $x^{11} \\le 21$.  We want to determine which of\nthese splits would result in lower loss.  Assuming $Q(0)$ is evaluated\nidentically for all features, We now need to compute $N_{\\{i| x^{11}\n  \\le 5\\}}$, $N_{\\{i| x^{11} \\le 21\\}}$, $D_{\\{i| x^{11} \\le 5\\}}$,\n$D_{\\{i| x^{11} \\le 21\\}}$.\n\n\\paragraph{Deep Trees}\n\nA decision tree consisting of one root node and two leaves is called a\n{\\bf stump}.  Typically, we want to grow deeper decision trees, as\nthis will better capture interaction-effects among features.  To build\nsub-trees, we simply capture the splitting feature and value and apply\nthe same tree-building logic on the partition of records defined by\nthe split.  When only terminate the tree with leaves once the depth of\nthe tree has reached a user-specified limit.\n\nWe must maintain the partition (of partition of ...) over which a best\nsplit is to be searched.  For trees whose depth is greater than one\n(non-stumps), the ancestor split along with its feature data is\nnecessary in order to assign a record to a descendant partition.\n\n\\paragraph{Categorical Features}\n\nCategorical features are defined by some finite number of labels.  For\nexample, the feature {\\em nationality} might have three categories\n(aka class labels) \\texttt{French}, \\texttt{American}, and\n\\texttt{Panamanian}.  The categories of such a feature have no natural\nordering.  A decision rule for a categorical feature $x^j$ takes the\nform $x^j \\in C_L$ where $C_L$ is a subset of the categories of that\nfeature.  For example, \\texttt{if $x \\in$ \\{French, American\\} go left\n  else if $x \\in$ \\{Panamanian\\} go right else raise NoSuchCategory}.\nIn this example, $C_L =$ \\texttt{\\{French, American\\}} and $C_R =$\n\\texttt{\\{Panamanian\\}}.  For a categorical feature with $B$\ncategories, there are $2^B - 2$ ways to partition these into two sets.\nA naive approach would be to evaluate every partition, and pick the\none associated with the smallest loss.  However, for even a modest\n$B$, this can be quite expensive.  Fortunately, a heuristic which\nimposes an order on the categories exists; with this ordering,\ncomputing $\\hat \\gamma$'s and associated loss is nearly identical to\nthat of an ordinal features.\n\nIn the context of non-boosted trees, the idea is use the response $y$\ndetermine the order -- after all, we want to use the feature to\ndiscriminate between $y=1$ and $y=-1$.  Stated differently, in an\nideal partition, the response on one side will be uniformly $1$ and on\nthe other uniformly $-1$.\n\nIn the context boosted trees, we do not care about the response $y_i\n\\in {-1,1}$ but rather the pseudo-response $z_i \\in \\Re$, because the\nlatter reflects that which has not yet been explained by previous\ntrees.  Why does Friedman call\n\\[\nz_i \\equiv \\frac{ 2 y_i } { 1 + \\exp [ 2 y_i F_i^K ] }\n\\]\nthe pseudo-response?  First note that $z_i$ is some $y_i$ scaled by\nthe positive quantity $2/( 1 + \\exp [ 2 y_i F_i^K ] )$.  we stated\nearlier that when $y_i$ and $F_i^K$ have the same sign, then the\ncomponent of the loss $L(y_i,F_i^K)$ due to record $i$ is low (by\ndesign) and that record is considered to be well explained.  In that\ncase, as $|F_i^K| \\rightarrow \\infty$, $\\exp [ 2 y_i F_i^K ]\n\\rightarrow \\infty$, and $z_i \\rightarrow 0$.  Conversely for poorly\nexplained records, $y_i$ and $F_i^K$ have opposite signs, $\\exp [ 2\n  y_i F_i^K ] \\rightarrow 0$ and $z_i \\rightarrow 2 y_i$.\n\nBy ordering the categories according to the average of $z_i$ in each\ncategory, that is\n\\[\n\\frac{1}{\\text{card}(S)} N \\equiv \\frac{1}{\\text{card}(S)} \\sum_{i \\in S} z_i\n\\]\nWe can find the split among the categories which clusters the\nunexplained responses of each type ${-1,1}$.\n\n\\paragraph{Shrinkage and Stochastic Boosting}\n\nIn his follow-on paper \\cite{SGB}, Friedman improved tree-boosting in\ntwo ways.  The first idea is to train each tree (produced in a single\niteration) on a different, random subset of the training set ({\\bf\nstochastic}).  The second idea is to shrink the leaf values by some\nscalar $\\alpha < 1$.\n\nThe stochastic idea is inspired by the common practice in statistics\nof setting aside data for model validation.  Predictive modeling\nalgorithms can easily {\\bf overfit}, by which we mean that they pay\ntoo much attention to the records in the training set, and in the\nprocess degrade their ability to perform well on data that they have\nnot seen.  So, using the same set of records for both model assessment\nand development often leads to a very optimistic view of a model's\nperformance.  A validation set consisting of records that are hidden\nduring model development can provide a more realistic view of the\nmodel's performance.  In tree boosting, training on a different random\nsubset of records is intended to mitigate overfitting.  Experience\nshows that it has the intended effect.\n\nThe second idea is to shrink in magnitude the value of each tree (that\nis, replace the $\\hat \\gamma$'s that are at the leaf of every tree\nwith a scaled version, $\\alpha \\hat \\gamma$ where $0 < \\alpha < 1$.\nThis is inspired by common practice in optimization algorithms, where\na {\\bf step}, intended to bring the algorithm closer to the solution,\nis scaled back.  In \\texttt{dawg}, a step is a tree.  The impact of\nscaling each tree with the shrinkage factor $\\alpha$ (also known as\nthe {\\bf learning rate}) is to (a) slow down the algorithm (b) give\nopportunities for a wider set of features to be included in the model,\nresulting in a superior model (c) promote convergence.\n\nIt has been shown, both in academic papers, and by applying\n\\texttt{dawg} to various data sets, that shrinkage and stochastic\nboosting used in combination leads to higher quality models.  These\nruntime costs are significant, and the code necessary to implement\nthese features is more complex.\n\nThe point about convergence deserves some elaboration.  It is possible\nthat for some learning rate $\\alpha \\le 1$ the loss $Q \\rightarrow\n\\infty$.  This happens typically because $L(y_i, F_i^K) \\rightarrow\n\\infty$ for some record $i$ which was held out during the last\niteration $K$.  \\texttt{dawg} detects to this situation by restarting\nlearning with a rate half the original one.\n\n\\paragraph{Algorithm Termination}\n\nAlthough shrinkage and stochastic boosting reduce the tendency for\n\\texttt{dawg} to overfit, they do not eliminate that tendency.  In an\nideal world without overfitting, \\texttt{dawg}'s loss function would\nsimply stop decreasing with each iteration $k$, defining a convenient\ntermination point.  However, with enough diverse features, it seems\npossible to drive the loss arbitrarily close to zero.  This raises the\nquestion: for a given learning rate, what is the optimal number of\ntrees (iterations) ?  To answer this question, \\texttt{dawg} performs\nk-fold cross-validation: it trains internally on $(k-1)$ folds, and\nmonitors the loss on the remaining ``validation'' fold.  Once the loss\non this fold starts increasing, \\texttt{dawg} stops learning.\n\\texttt{dawg} constructs $k$ such sub-models, and averages them in a\nfinal model.\n\nDuring the validation phase, we can speak of several sets of records.\nThe training set is the union of the validation set and the working\nset.  In each iteration of the validation phase, the working set is\nrandomly partitioned in two.  One partition is used for building a\ntree, and the other partition is unused.  The partition of records\nwhich are used are further portioned as splits are discovered.\n\n\\begin{thebibliography}{5}\n\\bibitem{GBM}Friedman, Jerome H.  Greedy Function Approximation: A\n  Gradient Boosting machine, 1999;\n  \\url{//http://www-stat.stanford.edu/~jhf/ftp/trebst.pdf}\n\\bibitem{SGB}Friedman, Jerome H.  Stochastic Gradient Boosting, 1999;\n  \\url{http://www-stat.stanford.edu/~jhf/ftp/stobst.pdf}\n\\bibitem{ARFF} \\url{http://www.cs.waikato.ac.nz/~ml/weka/arff.html}\n\\end{thebibliography}\n\n\\end{document}\n", "meta": {"hexsha": "9474d53f944885985c2743001805a6d3c4cf3df9", "size": 20114, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/dawg.tex", "max_stars_repo_name": "alexbaretta/dawg", "max_stars_repo_head_hexsha": "3d98d41ae72884e99938e41149cfb08203dec792", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-03-02T19:09:01.000Z", "max_stars_repo_stars_event_max_datetime": "2017-03-03T08:57:43.000Z", "max_issues_repo_path": "doc/dawg.tex", "max_issues_repo_name": "alexbaretta/dawg", "max_issues_repo_head_hexsha": "3d98d41ae72884e99938e41149cfb08203dec792", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/dawg.tex", "max_forks_repo_name": "alexbaretta/dawg", "max_forks_repo_head_hexsha": "3d98d41ae72884e99938e41149cfb08203dec792", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.1330275229, "max_line_length": 174, "alphanum_fraction": 0.6852441086, "num_tokens": 6580, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164657, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7416154709075788}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Find $-7\\begin{mymatrix}{r}\n    6 \\\\\n    0 \\\\\n    4 \\\\\n    -1\n  \\end{mymatrix}\n  + 6\\begin{mymatrix}{r}\n    -13 \\\\\n    -1 \\\\\n    1 \\\\\n    6\n  \\end{mymatrix}$.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Decide whether\n  \\begin{equation*}\n    \\vect{v}= \\begin{mymatrix}{r}\n      4 \\\\\n      4 \\\\\n      -3\n    \\end{mymatrix}\n  \\end{equation*}\n  is a linear combination of the vectors\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r}\n      3 \\\\\n      1 \\\\\n      -1\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{u}_2 =\n    \\begin{mymatrix}{r}\n      2 \\\\\n      -2 \\\\\n      1\n    \\end{mymatrix}.\n  \\end{equation*}\n  If yes, find the coefficients.\n\n  \\begin{sol}\n    \\begin{equation*}\n      \\begin{mymatrix}{r}\n        4 \\\\\n        4 \\\\\n        -3\n      \\end{mymatrix}\n      =\n      2\n      \\begin{mymatrix}{r}\n        3 \\\\\n        1 \\\\\n        -1\n      \\end{mymatrix}\n      -\n      \\begin{mymatrix}{r}\n        2 \\\\\n        -2 \\\\\n        1\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Decide whether\n  \\begin{equation*}\n    \\vect{v}= \\begin{mymatrix}{r}\n      4 \\\\\n      4 \\\\\n      4\n    \\end{mymatrix}\n  \\end{equation*}\n  is a linear combination of the vectors\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r}\n      3 \\\\\n      1 \\\\\n      -1\n    \\end{mymatrix},\n    \\quad\n    \\vect{u}_2 =\n    \\begin{mymatrix}{r}\n      8 \\\\\n      0 \\\\\n      -1\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{u}_3 =\n    \\begin{mymatrix}{r}\n      2 \\\\\n      -2 \\\\\n      1\n    \\end{mymatrix}.\n  \\end{equation*}\n  If yes, find the coefficients.\n\n  \\begin{sol}\n    The system\n    \\begin{equation*}\n      \\begin{mymatrix}{r}\n        4 \\\\\n        4 \\\\\n        4\n      \\end{mymatrix}\n      =\n      a_1\n      \\begin{mymatrix}{r}\n        3 \\\\\n        1 \\\\\n        -1\n      \\end{mymatrix}\n      + a_2 \\begin{mymatrix}{r}\n        8 \\\\\n        0 \\\\\n        -1\n      \\end{mymatrix}\n      + a_3\n      \\begin{mymatrix}{r}\n        2 \\\\\n        -2 \\\\\n        1\n      \\end{mymatrix}\n    \\end{equation*}\n    has no solution.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "aae47c4483f2c8e3d72c5d0da6fdde3c3650289e", "size": 2109, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Vectors-LinearCombinations.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Vectors-LinearCombinations.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Vectors-LinearCombinations.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 15.7388059701, "max_line_length": 40, "alphanum_fraction": 0.4476055002, "num_tokens": 817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.74154938530302}}
{"text": "%!TEX root = ../notes.tex\n\\section{February 25, 2022}\n\\recall Midterm discrete log problem where\n\\[x\\to x^e\\mod p\\]\nand a solution we gave was take $(x^e)^p\\equiv x$ where $de\\equiv 1\\mod (p-1)$.\n\nWhat if we didn't take this mod $p$, but instead took it mod $pq$.\n\nWe can take the analog of Fermat's Little Theorem mod $pq$, where\n\\[a^{(p-1)(q-1)}\\equiv 1\\mod pq\\]\n\nWhat if we did the same thing, instead of taking inverse mod $p-1$, we took it mod $(p-1)(q-1)$ to extract $e^\\mathrm{th}$ roots if we know $(p-1)(q-1)$.\n\nWe know $p$ and $q$, we can easily figure out $(p-1)(q-1)$. Also, if we know $(p-1)(q-1)$, we also know\n\\[pq-p-q+1\\]\nWe know that $pq = x$ and $p+q = y$, then $pq$ are roots of $t^2-yt+x=0$.\n\n\\subsection{RSA Public-Key Cryptography}\nAlice generates\n\\begin{align*}\n    p, q                  & \\to \\text{Two large prime numbers} \\\\\n    e                     & \\to \\text{``Public exponent''}     \\\\\n    N = pq                & \\to \\text{``Public modulo''}       \\\\\n    \\boxed{(e, N)}        & \\to \\text{Public key}              \\\\\n    (d, N)                & \\to \\text{Private key}             \\\\\n    \\text{where }d\\cdot e & \\equiv 1\\mod(p-1)(q-1)\n\\end{align*}\n\nBob has some message $m$ he wishes to send to Alice. Bob sends $m^e\\mod N$ and sends it to Alice.\n\nAfter receiving this message, Alice can recover $(m^e)^d\\equiv m\\mod N$.\n\n$p, q$ are private, but $pq$ is private. The security of RSA rests on multiplication being easy, but factorization being hard ($pq$ is hard to factorize into $p$ and $q$).\n\nWe might implement such an algorithm like so:\n\\begin{lstlisting}[language=Python]\nfrom crypto import gcd, ext_gcd, pow_mod\nN = p * q\nd = ext_gcd(e, (p-1) * (q-1))[0] % ((p-1) * (q-1))\nm = 1234567891234786951234010239847123748\n# 0 < m < N is True\nc = pow_mod(m, e, N)\npow_mod(c, d, N) # => m\n\\end{lstlisting}\n\nIf we were Alice and Bob, we \\emph{still} have one step to go! We need to find ourselves big prime numbers $p, q$ (finding $e$ is easy, we can just use our \\textsf{gcd} algorithm). How do we do that?\n\n\\subsection{Primality Testing}\n\\textsf{Prime hunting!}\n\nPrime numbers are reasonably common. So generating a large prime number amounts to generating a number, checking if it's prime, and repeating until we get a prime.\n\nThis reduces to the problem of checking if a number is prime. Given an $n$, is it a prime?\n\n\\begin{lstlisting}\nfrom crypto import pow_mod\nn = 123874610239487102893741890237023\npow_mod(2, n-1, n)\n\\end{lstlisting}\ngives us a basic primality check. Fermat's Little Theorem says that if $n$ is prime, then $2^{p-1}\\equiv 1\\mod n$.\n\n\\begin{definition}[Witnesses]\n    We say that $a$ is a \\ul{witness} for the compositeness of $n$ if\n    \\[a^{n-1}\\not\\equiv 1\\mod n\\]\n    and $gcd(a, n) = 1$.\n\\end{definition}\n\nWe have a problem! Fermat's Little Theorem is not an if-and-only-if. We can have numbers that pass this test for almost every base. Take $n = 3\\cdot 11\\cdot 17 = 561$.\n\n\\begin{lstlisting}[language=Python]\nfrom crypto import pow_mod, gcd\nfor a in range(n):\n    if gcd(a, n) == 1:\n        print(pow_mod(a, n-1, n))\n\\end{lstlisting}\ngives $1$ for \\emph{everything}\\footnote{oh no!}\n\n\\begin{definition}[Carmichael Number]\n    A \\ul{Carmichael number} is a composite number with \\emph{no} witness of compositeness.\n\\end{definition}\n\\begin{example}\n    $561$ is a Carmichael Number.\n\\end{example}\n\nWe now \\emph{almost} have a way of checking for primality, but it doesn't always quite work.\n\nSince taking to the power of $n-1$ is a group homomorphism, then Lagrange's Theorem states that if there is a witness, then there are \\emph{a lot} of witnesses.\n\n\\begin{proposition}\\label{prop:aq-1-mod-p}\n    Let $p$ be an odd prime. Write\n    \\[p-1 = 2^k\\cdot q\\quad\\text{with $q$-odd}\\]\n    Then either\n    \\[a^{q}\\equiv 1\\mod p\\]\n    or one of $a^q, a^{2q}, a^{4q},\\dots, a^{2^{k-1}q}$ is $\\equiv -1\\mod p$.\n\\end{proposition}\n\\begin{proof}\n    We look at this sequence\n    \\[a^q, a^{2q}, a^{4q},\\dots, \\underbrace{a^{2^iq}}_{\\not\\equiv 1\\pmod p}, \\underbrace{a^{2^{i+1}q}}_{\\equiv 1\\pmod p}, \\dots, a^{2^{k-1}q}, a^{2^kq}\\]\n    We have that $a^{2^kq}\\equiv 1\\mod p$ by Fermat's Little Theorem. There's some point where we `become' congruent to $1\\mod p$. If the first one is one, then we have the first case. Otherwise we have $a^q\\not\\equiv 1$ mod $p$, then we repeatedly square until we get to $1\\mod p$. Then \\emph{right before} we turned to $1\\mod p$, we would have had $-1\\mod p$. In our example above, this is $a^{2^iq}$. \n\\end{proof}", "meta": {"hexsha": "b420d03f8f23da5de0b793653e88c1513b6769d3", "size": 4491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-02-25.tex", "max_stars_repo_name": "jchen/math1580-notes", "max_stars_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-14T15:03:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T15:03:38.000Z", "max_issues_repo_path": "lectures/2022-02-25.tex", "max_issues_repo_name": "jchen/math1580-notes", "max_issues_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_issues_repo_licenses": ["BSL-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures/2022-02-25.tex", "max_forks_repo_name": "jchen/math1580-notes", "max_forks_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_forks_repo_licenses": ["BSL-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.91, "max_line_length": 404, "alphanum_fraction": 0.654419951, "num_tokens": 1532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7415079258770775}}
{"text": "\\chapter{Introduction}\n\n\\section{Motivation}\nAn example of computing a result over a data type is computing the \\textbf{maximum path sum} over a binary tree. Given a \\inlinehaskell{BinTree}, starting at the root node, find a path from the root node to the leaves that leads to the maximum total.\n\nThe implementation of the computation is done in \\texttt{Haskell}. And the definition of the binary tree and example tree is:\n\\begin{haskell}\ndata BinTree = Leaf Int\n             | Node BinTree Int BinTree \n\\end{haskell}\n\n\\begin{haskell}\nexampleTree :: BinTree    \nexampleTree = Node (Node (Leaf 8) 7 (Leaf 9)) 3 (Node (Leaf 5) 4 (Leaf 2))\n\\end{haskell}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.4\\textwidth]{introduction/Tree.pdf}\n    \\caption{Graphic visualization of the \\inlinehaskell{exampleTree}}\n\\end{figure}\n\nAn implementation of computing the max path sum over data type \\inlinehaskell{BinTree} can be seen below and has a complexity of $\\mathcal{O}(N)$, where $N$ is the number of nodes in the tree.\n\\begin{haskell}\nmaxPathSum :: BinTree -> Int\nmaxPathSum (Leaf x)     = x\nmaxPathSum (Node l x r) = x + max (maxPathSum l, maxPathSum r)\n\\end{haskell}\n\nAnd computing the max path sum over the \\inlinehaskell{exampleTree} results in 19.\n\n\\begin{figure}[H]\n\\begin{minipage}[c]{0.35\\textwidth}\n\\begin{haskell}\nmaxPathSum exampleTree !$\\equiv$! 19\n\\end{haskell}\n\\end{minipage}\n\\hspace{0.1\\textwidth}\n\\begin{minipage}[c]{0.55\\textwidth}\n\\includegraphics[width=0.7\\textwidth]{introduction/SolvedTree.pdf}\n\\end{minipage}\n\\end{figure}\n\nTo reduce the number of recomputations, first, we need to compare the structure of the data type for equality. When comparing the data type structure for equality, if they are equal, the previously computed result can be reused. Otherwise, the result needs to be recomputed. To compare the structure of the data type efficiently, we introduce the use of hash functions. Generating a hash every time a comparison takes place would be inefficient because part of the structure does not change, which leads to the same hash. Thus, every substructure in the data type stores the hash of its structure. Using hash functions and storing them to compare the structures of the data type for equality is performed in constant time ($\\mathcal{O}(1)$).\n\nIn the example, a new data type is introduced: the \\inlinehaskell{MerkleTree}. This data type is the same as the \\inlinehaskell{BinTree}, but the constructors also contain a \\inlinehaskell{Hash}. To create a \\inlinehaskell{MerkleTree}, we traverse through a \\inlinehaskell{BinTree} and hash the structure and store it. Creating a \\inlinehaskell{MerkleTree} has a time complexity of $\\mathcal{O}(N)$.\n\n\\begin{haskell}\ndata MerkleTree = LeafH Hash Int\n                | NodeH Hash MerkleTree Int MerkleTree\n\nmerkle :: BinTree -> MerkleTree\nmerkle (Leaf x)     = LeafH (hash [\"Leaf\", x]) x\nmerkle (Node l x r) = NodeH (hash [\"Node\", x, hl, hr]) l' x r'\n  where\n    hl = getHash l'\n    hr = getHash r'\n    l' = merkle l\n    r' = merkle r\n\\end{haskell}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.4\\textwidth]{introduction/MerkleTree.pdf}\n    \\caption{The \\inlinehaskell{MerkleTree} of \\inlinehaskell{exampleTree}}\n\\end{figure}\n\nTo compute the max path sum and its intermediate results, we can use the precomputed hashes of the \\inlinehaskell{MerkleTree} to efficiently generate a \\inlinehaskell{Map Hash Int}. The complexity of computing the max path sum and the intermediate results is $\\mathcal{O}(N)$.   \n\nThe example implementation of computing the max path sum and its intermediate results can be seen below. However, this implementation uses a \\texttt{union} (\\inlinehaskell{<>}) to combine the \\inlinehaskell{Map}'s which has a complexity of $\\mathcal{O}(m*log(n/m + 1)), m <= n$\\cite{HaskellDataUnion}. This can be implemented more efficiently by giving the \\inlinehaskell{Map} to the left side and then to the right side of the Tree, which makes it a constant operation. Except, this would make the code more complex. So, for clarity, the example is implemented with a union.\n\n\\begin{haskell}\nmaxPathSumInc :: MerkleTree -> (Int, Map Hash Int)    \nmaxPathSumInc (LeafH h x)     = (x, insert h x empty)\nmaxPathSumInc (NodeH h l x r) = (y, insert h y (ml <> mr))  \n  where\n    y = x + max (xl, xr)\n    (xl, ml) = maxPathSumInc l\n    (xr, mr) = maxPathSumInc r\n\\end{haskell}\n\\vspace{15pt}\n\\begin{figure}[H]\n    \\begin{minipage}[c]{0.55\\textwidth}\n        \\centering\n        \\includegraphics[width=.7\\textwidth]{introduction/MerkleTree.pdf}\n    \\end{minipage}\n    \\hspace{0.1\\textwidth}\n    \\begin{minipage}[c]{0.35\\textwidth}\n        \\centering\n        \\begin{tabular}{|l|r|}\n            \\hline\n            \\textbf{Hash Nodes} & \\textbf{Max Sum} \\\\\n            \\hline\n            \\# 6dd & 19 \\\\\n            \\hline\n            \\# 5df & 16 \\\\\n            \\hline\n            \\# fa0 & 8 \\\\\n            \\hline\n            \\# 8d0 & 9 \\\\\n            \\hline\n            \\# f3b & 9 \\\\\n            \\hline\n            \\# 84b & 5 \\\\\n            \\hline\n            \\# 1ad & 2 \\\\\n            \\hline\n        \\end{tabular}\n    \\end{minipage}\n    \\caption{The \\inlinehaskell{MerkleTree} with intermediate results}    \n\\end{figure}\n\nWhen there is a change in the \\inlinehaskell{BinTree}, only the hashes of the change itself and its parents need to be recomputed. The recomputation of the hash has a time complexity with an upper bound of $\\mathcal{O}(N)$ and an average of $\\Theta(M \\log{N})$ where $M$ is the number of changed nodes. The upper bound is $\\mathcal{O}(N)$, because if $N = M \\Rightarrow \\mathcal{O}(N \\log{N}) > \\mathcal{O}(N)$, but when every node in the tree is changed, then the original function can be used. Meaning that this implementation only works efficiently with small changes to the data type.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.4\\textwidth]{introduction/ChangedMerkleTree.pdf}\n    \\caption{Changed Merkle Tree}\n\\end{figure}\n\nThen to compute the max path sum over the Changed Tree, the previously computed \\inlinehaskell{Map} can be used to reduce the amount of recomputation. This function also has the same complexity as the change Merkle tree, with an upper bound of $\\mathcal{O}(N)$ and an average of $\\Theta(M \\log{N})$. \n\n\\begin{haskell}\nmaxPathSumMap :: Map Hash Int -> MerkleTree -> (Int, Map Hash Int)\nmaxPathSumMap m (LeafH h x) = case lookup m h of\n  Just y  -> (y, m)\n  Nothing -> (x, insert h x m)\nmaxPathSumMap m (NodeH h l x r) = case lookup m h of\n  Just y  -> (y, m)\n  Nothing -> (y, insert h y (ml <> mr))\n    where\n      y = x + max (xl, xr)\n      (xl, ml) = maxPathSumMap m l\n      (xr, mr) = maxPathSumMap m r  \n\\end{haskell}\n\nIn Table \\ref{table:function-compl-inc} and \\ref{table:function-compl} the function complexities can be seen of the functions used to compute incrementally and complete. As can be seen, the upper bound complexities of the functions for incremental computation are the same as for the complete computation. However, when there are small changes to the data type the incremental update of the result has lower complexity ($\\Theta(M \\log{N})$) than the complete recomputation complexity ($\\Theta(N)$), which makes it more efficient.\n\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{|l|r|r|}\n        \\hline\n        \\textbf{Function} & \\textbf{Average} & \\textbf{Upper bound} \\\\\n        \\hline\n        \\inlinehaskell{merkle} & $\\Theta(N)$ & $\\mathcal{O}(N)$ \\\\\n        \\hline\n        \\inlinehaskell{maxPathSumInc} & $\\Theta(N)$ & $\\mathcal{O}(N)$ \\\\\n        \\hline\n        Change Merkle Tree & $\\Theta(M \\log{N})$  & $\\mathcal{O}(N)$ \\\\\n        \\hline\n        \\inlinehaskell{maxPathSumMap} & $\\Theta(M \\log{N})$  & $\\mathcal{O}(N)$ \\\\\n        \\hline\n    \\end{tabular}\n    \\caption{Functions used for incremental computation}\n    \\label{table:function-compl-inc}\n\\end{table}\n\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{|l|r|r|}\n        \\hline\n        \\textbf{Function} & \\textbf{Average} & \\textbf{Upper bound} \\\\\n        \\hline\n        \\inlinehaskell{maxPathSum} & $\\mathcal{O}(N)$ & $\\mathcal{O}(N)$ \\\\\n        \\hline\n    \\end{tabular}\n    \\caption{Functions used for complete computation}\n    \\label{table:function-compl}\n\\end{table}\n\nThe problem with this implementation is that it only works for the \\inlinehaskell{BinTree} datatype. The goal would be to create a generic function, where only the \\inlinehaskell{maxPathSum} would be defined and the result would automatically contain the intermediate results. A generic definition could look like this:\n\n\\begin{haskell}\ncataMerkle :: (f a -> a) -> Map Hash a -> Fix (f :*: K Hash) -> (a, Map Hash a)\n\\end{haskell}\n\nUsing the \\inlinehaskell{cataMerkle} function would lead to only needing to implement the \\inlinehaskell{maxPathSum} function and the intermediate results are then automatically stored.\n\n\\section{Research Questions}\n\\todo[inline]{Write the research questions}\n\n\\section{Contributions}\n\\todo[inline]{Write the contributions}", "meta": {"hexsha": "f64966b97c77020ec41fbc22a11d5b88c4531508", "size": 9001, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/introduction.tex", "max_stars_repo_name": "jortvangorkum/thesis-paper", "max_stars_repo_head_hexsha": "897946211f14901b656a89b2f56c624c84b4e810", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sections/introduction.tex", "max_issues_repo_name": "jortvangorkum/thesis-paper", "max_issues_repo_head_hexsha": "897946211f14901b656a89b2f56c624c84b4e810", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/introduction.tex", "max_forks_repo_name": "jortvangorkum/thesis-paper", "max_forks_repo_head_hexsha": "897946211f14901b656a89b2f56c624c84b4e810", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.1857923497, "max_line_length": 741, "alphanum_fraction": 0.6932563049, "num_tokens": 2575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726544, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7415079235694904}}
{"text": "\\sec{Laplace Transforms}\n\\subsection{The Laplace Transform}\n\\begin{defn}[The Laplace Transform]\n\tLet $f:(0, \\infty)\\to\\mathbb{R}$ be a good enough function.\\\\\n\tThe Laplace transform of $f$ is another function denoted as $\\mathcal{L}(f)$ or $\\mathcal{L}f$ or simply, $F.$ It is defined as follows:\n\t\\begin{equation} \\label{eq:lap}\n\t\t(\\mathcal{L}f)(s) := \\int_{0}^{\\infty} e^{-st}f(t) dt.\n\t\\end{equation}\n\\end{defn}\n\n\\begin{mdframed}[style=boxstyle, frametitle={Remarks}]\n\t\\begin{enumerate}[leftmargin=*]\n\t\t\\item It is customary to use uppercase letters for the Laplace transform and use the variable $s$ as the argument of the transform. Thus, we write $F(s), X(s), Y(s),$ et cetera for the Laplace transforms of $f(t), x(t), y(t),$ et cetera.\n\t\t\\item We have not stated what ``good enough'' means. Also we have not stated the domain of $\\mathcal{L}f.$ It is precisely whenever the integral in (\\ref{eq:lap}) exists. More details about sufficient conditions can be found in the notes linked.\n\t\t\\item Notations will be abused a lot and we'll write things like $\\mathcal{L}(f) = F(s)$ or $\\mathcal{L}(f(t)) = F(s).$ (If you don't realise why this is abuse of notation, then ignorance is bliss and continue.)\n\t\\end{enumerate}\n\\end{mdframed}\n\n\\begin{mdframed}[style=boxstyle2, frametitle={A remark}]\n\tNote that in general, the function $F(s)$ need not exist on the whole real line. Often, there exists some $a \\in \\mathbb{R}$ such that $F(s)$ exists for $s > a.$\n\\end{mdframed}\n\n\\newpage\n\n\\subsection{Properties}\nThe advantage of studying Laplace transforms will be seen when we see its many different properties.\\\\\nWe have the following property that's easy to verify:\n\\begin{mdframed}[style=boxstyle, frametitle={Linearity of Laplace Transforms}]\n\t\\begin{equation*} \n\t\t\\mathcal{L}(af + bg) = a\\mathcal{L}(f) + b\\mathcal{L}(g).\n\t\\end{equation*}\n\tOf course, $a$ and $b$ are real numbers.\n\\end{mdframed}\n\nRecall from calculus that changing the value of a function at finitely many points has no effect on the integral. Thus, it is possible for two different functions to have the same Laplace transform. However, we do have the following theorem if we demand continuity.\n\\newpage\n\\begin{thm}[Equality of Laplace transforms] \n\tLet $f, g:[0, \\infty) \\to \\mathbb{R}$ be continuous functions such that\n\t\\[\\mathcal{L}f = \\mathcal{L}g.\\]\n\tIn this case, we have\n\t\\[f = g.\\]\n\\end{thm}\n\n\\begin{mdframed}[style=boxstyle, frametitle={A trick}]\n\tOne useful trick is differentiate with respect to the parameter. For example, consider:\n\t\\begin{align*} \n\t\t& \\mathcal{L}(e^{at})(s) = \\dfrac{1}{s - a}\\\\\n\t\t& \\text{Differentiating with respect to }a:\\\\\n\t\t& \\mathcal{L}(te^{at})(s) = \\dfrac{1}{(s - a)^2}.\n\t\\end{align*}\n\tNote that the interchanging of $\\dfrac{\\partial}{\\partial a}$ and $\\mathcal{L}$ needs justification. (Which we do not provide.)\n\\end{mdframed}\n\n\\begin{thm}[Derivatives of Laplace]\n\t\\begin{equation*} \n\t\t\\mathcal{L}(tf(t)) = -\\dfrac{d}{ds}F(s).\n\t\\end{equation*}\n\tIn general,\n\t\\begin{equation*} \n\t\t\\mathcal{L}(t^nf(t)) = (-1)^n\\dfrac{d^n}{ds^n}F(s).\n\t\\end{equation*}\n\\end{thm}\n\n\\begin{thm}[Laplace of derivatives]\n\t\\begin{align*} \n\t\t\\mathcal{L}(f'(t)) &= sF(s) - f(0),\\\\\n\t\t\\mathcal{L}(f''(t)) &= s^2F(s) - sf(0) - f'(0),\\\\\n\t\t\\mathcal{L}(f^{(n)}(t)) &= s^nF(s) - \\sum_{k=0}^{n-1} s^{n-1-k}f^{(k)}(0).\n\t\\end{align*}\n\\end{thm}\n\n\\begin{thm}[First Shift Theorem]\n\tIf\n\t\\begin{equation*} \n\t\t\\mathcal{L}(f(t)) = F(s),\n\t\\end{equation*}\n\tthen\n\t\\begin{equation*} \n\t\t\\mathcal{L}(e^{at}f(t)) = F(s - a).\n\t\\end{equation*}\n\\end{thm}\n\n\\begin{defn}[Heaviside step function]\n\tThe \\defin{Heaviside unit step function} $u:\\mathbb{R}\\to\\{0, 1\\}$ is defined as\n\t\\begin{align*} \n\t\tu(t) := \\begin{cases}\n\t\t\t0 & \\text{if } t < 0\\\\\n\t\t\t1 & \\text{if } t \\ge 0\n\t\t\\end{cases}\n\t\\end{align*}\n\tFor $c \\in \\mathbb{R},$ the function $u_c(t)$ is defined as $u(t - c).$\n\\end{defn}\n\n\\begin{thm}[Second Shift Theorem]\n\tSuppose $\\mathcal{L}f = F(s)$ for $s > a \\ge 0.$ \\\\\n\tIf $c > 0,$ then we have\n\t\\begin{equation*} \n\t\t\\mathcal{L}(u_c(t)f(t - c)) = e^{-cs}F(s),\n\t\\end{equation*}\n\tfor $s > a.$\n\\end{thm}\n\n\\begin{thm}[Laplace transform of periodic functions]\n\tLet $p > 0$ be such that $f(t + p) = f(t).$\n\t\\begin{equation*} \n\t\t\\mathcal{L}f = \\dfrac{1}{1 - e^{-ps}}\\int_{0}^{p} e^{-st}f(t) dt.\n\t\\end{equation*}\n\\end{thm}\n\n\\subsection{Laplace table}\n\\begin{center}\n\t\\bgroup\n\t\\def\\arraystretch{2}\n\t\\begin{tabular}{|c|c||c|c|} \n\t\\hline\n\t$f(t)$ & $F(s)$ & $f(t)$ & $F(s)$ \\\\\n\t\\hline\n\t\\hline\n\t$t$ & $1/s^2$ & $t^a$ & $\\dfrac{\\Gamma(a + 1)}{s^{a + 1}}$\\\\\n\t$u_c(t)$ & $e^{-cs}/s$ & $e^{at}$ & $\\dfrac{1}{s - a}$\\\\\n\t$\\sin(\\omega t)$ & $\\dfrac{\\omega}{s^2 + \\omega^2}$ & $\\cos(\\omega t)$ & $\\dfrac{s}{s^2 + \\omega^2}$\\\\\n\t$t\\sin(\\omega t)$ & $\\dfrac{2\\omega s}{(s^2 + \\omega^2)^2}$ & $t\\cos(\\omega t)$ & $\\dfrac{s^2 - \\omega^2}{(s^2 + \\omega^2)^2}$\\\\\n\t$e^{at}\\sin(\\omega t)$ & $\\dfrac{\\omega}{(s - a)^2 + \\omega^2}$ & $e^{at}\\cos(\\omega t)$ & $\\dfrac{s - a}{(s - a)^2 + \\omega^2}$\\\\\n\t$\\sinh(\\omega t)$ & $\\dfrac{\\omega}{s^2 - \\omega^2}$ & $\\cosh(\\omega t)$ & $\\dfrac{s}{s^2 - \\omega^2}$\\\\\n\t$e^{at}\\sinh(\\omega t)$ & $\\dfrac{\\omega}{(s - a)^2 - \\omega^2}$ & $e^{at}\\cosh(\\omega t)$ & $\\dfrac{s - a}{(s - a)^2 - \\omega^2}$\\\\\n\t\\hline\n\t\\end{tabular}\n\t\\egroup\n\\end{center}\n\n\\subsection{The convolution}\n\\begin{defn}[Convolution]\n\tThe \\defin{convolution} of functions $f$ and $g$ is another function $f*g$ defined as\n\t\\begin{equation*} \n\t\t(f*g)(t) = \\int_{0}^{t} f(t - \\tau)g(\\tau) d\\tau.\n\t\\end{equation*}\n\\end{defn}\n\n\\begin{mdframed}[style=boxstyle, frametitle={Properties}]\n\t\\begin{enumerate}[leftmargin=*]\n\t\t\\item $f*g = g*f.$\n\t\t\\item $f*(g_1 + g_2) = f*g_1 + f*g_2.$\n\t\t\\item $(f * g) * h = f * (g * h).$\n\t\t\\item $f * 0 = 0 * f = 0.$ (Here, $0$ denotes the zero \\emph{function}.)\n\t\\end{enumerate}\n\\end{mdframed}\n\n\\begin{mdframed}[style=boxstyle, frametitle={Caution}]\n\t$f*1 = f$ is \\textbf{not} true in general.\\\\\n\tFor instance, $\\sin t * 1 = 1 - \\cos t.$\n\\end{mdframed}\n\n\\begin{thm}[Convolution of Laplace]\n\tSuppose $\\mathcal{L}f$ and $\\mathcal{L}g$ exist for all $s > a \\ge 0.$ Then,\n\t\\begin{align*} \n\t\t\\mathcal{L}(f * g) = \\mathcal{L}(f)\\mathcal{L}(g) \\qquad \\text{for } s > a.\n\t\\end{align*}\n\\end{thm}", "meta": {"hexsha": "c3eda7cd27ca53ac4bbbad6959da4f2235272d28", "size": 6141, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tuts/ma-108/summary/laplace.tex", "max_stars_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_stars_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-12-17T20:34:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T09:58:57.000Z", "max_issues_repo_path": "tuts/ma-108/summary/laplace.tex", "max_issues_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_issues_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-03-04T10:23:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-28T10:29:01.000Z", "max_forks_repo_path": "tuts/ma-108/summary/laplace.tex", "max_forks_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_forks_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-08-30T18:19:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-17T12:09:09.000Z", "avg_line_length": 38.8670886076, "max_line_length": 265, "alphanum_fraction": 0.6257938447, "num_tokens": 2447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256591565729, "lm_q2_score": 0.8807970889295664, "lm_q1q2_score": 0.7414775899713228}}
{"text": "\\section{Data normalization in DNNs and CNNs}\nThe goal of data normalization is twofold:\n\\begin{enumerate}\n\\item Data normalization is the organization of data to appear similar across all records and fields.\n\\item It increases the cohesion of entry types leading to cleansing, lead generation, segmentation, and higher quality data.\n\\end{enumerate}\nData normalization includes eliminating unstructured data and redundancy (duplicates) in order to ensure logical data storage. When data normalization is done correctly, you will end up with standardized information entry.\n\nIn this chapter, we use superscript $i$, $j$, $l$ and $\\nu$ to represent the $i$-th data, the $j$-th channel, the $l$-th depth and the $\\nu$-th iteration step, respectively.\n\n\\subsection{Data normalization in DNNs}\nConsider that we have the all training data as\n\\begin{equation}\\label{eq:trainingdata}\n(X,Y) := \\{(x^i, y^i)\\}_{i=1}^N,\n\\end{equation}\nfor $x^i \\in \\mathbb{R}^d$ and $y^i \\in \\mathbb{R}^k$. Here superscripte $i$ represents the $i$-th data.\n\nBefore we input every data into a DNN model, we will apply the following normalization\nfor all data $x_i$ for each component. The notation $x \\sim X$ means that $x$ is a discrete random variable on $X$\nwith probability\n\\begin{equation}\\label{key}\n\\mathbb P( x = x^i ) = \\frac{1}{N},\n\\end{equation}\nfor any $x^i \\in X$. The expectation and the variance are \n\\begin{equation}\\label{key}\n\\mu_X =\\mathbb{E}_{x \\sim X}[x] = \\frac{1}{N}\\sum_{i=1}^N x^i, \n\\quad  \\sigma_X= \\mathbb{V}_{x\\sim X}[x] = \\frac{1}{N} \\sum_{i=1}^N ( x^i - \\mu_X)^T( x^i - \\mu_X).\n\\end{equation}\nDefine new data\n\\begin{equation}\\label{eq:normlizationData}\n\\tilde x^i = \\frac{x^i - \\mu_X }{\\sqrt{\\sigma_X}},\n\\end{equation}\nwhere \n$\nx^i , \\tilde x^i , \\mu_X, \\sigma_X \\in \\mathbb{R}^d.\n$\nFinally, we will have a ``new'' data set \n\\begin{equation}\\label{key}\n\\tilde X = \\{\\tilde x^1, \\tilde x^2, \\cdots, \\tilde x^N \\},\n\\end{equation}\nwith unchanged label set $Y$. \nTo be specific, we rewrite the equation \\eqref{eq:normlizationData} into an elementwise form. \nLet denote\n\\begin{equation}\\label{key}\nx^{i,j} \\longleftrightarrow \\text{ the j-th component of data } x^i.\n\\end{equation}\nThen we have following formula of for all $j = 1, 2, \\cdots, d$\n\\begin{equation}\\label{key}\n\\tilde x^{i,j}  = \\frac{x^{i,j} - \\mu_X^j }{\\sqrt{\\sigma_X^j}},\n\\end{equation}\nwhere $\\mu_X=(\\mu_X^1,\\mu_X^2,\\cdots, \\mu_X^d)\\in \\mathbb{R}^d$, $\\sigma_X=(\\sigma_X^1,\\sigma_X^2,\\cdots, \\sigma_X^d)\\in \\mathbb{R}^d$ and\n\\begin{equation}\\label{key}\n\\mu_X^j =\\mathbb{E}_{x \\sim X}[x^j] = \\frac{1}{N}\\sum_{i=1}^N x^{i,j}, \n\\quad  \\sigma_X^j = \\mathbb{V}_{x\\sim X}[x^j] = \\frac{1}{N} \\sum_{i=1}^N ( x^{i,j} - \\mu_X^j)^2.\n\\end{equation}\nHere we note that, by normalizing the data set, we have the next properties \nfor new data $\\tilde x=(\\tilde x^1, \\tilde x^2, \\cdots, \\tilde x^N) \\in \\tilde X$ with component $j = 1,2,\\cdots,d$,\n\\begin{equation}\\label{key}\n\\mathbb{E}_{\\tilde X}[\\tilde x] = \\frac{1}{N} \\sum_{i=1}^N \\tilde x^i = 0, \n\\end{equation}\nand \n\\begin{equation}\\label{key}\n\\mathbb{V}_{\\tilde X}[\\tilde x] = \\frac{1}{N} \\sum_{i=1}^N (\\tilde x^i - \\mathbb{E}_{\\tilde X}[\\tilde x] )^T (\\tilde x^i - \\mathbb{E}_{\\tilde X}[\\tilde x] )= 1.\n%\\begin{pmatrix}\n%1\\\\1\\\\\\vdots\\\\1 \n%\\end{pmatrix} \\in \\mathbb{R}^d.\n\\end{equation}\n%\\begin{equation}\\label{key}\n%\\mathbb{E}_{\\tilde X}[[\\tilde x]_j] = \\frac{1}{N} \\sum_{i=1}^N [\\tilde x_i]_j = 0,\n%%\\begin{pmatrix}\n%%0\\\\0\\\\\\vdots\\\\0 \n%%\\end{pmatrix} \\in \\mathbb{R}^d,\n%\\end{equation}\n%and \n%\\begin{equation}\\label{key}\n%\\mathbb{V}_{\\tilde X}[[\\tilde x]_j] = \\frac{1}{N} \\sum_{i=1}^N ([\\tilde x_i]_j - \\mathbb{E}_{\\tilde X}[[\\tilde x]_j] )^2 = 1.\n%%\\begin{pmatrix}\n%%1\\\\1\\\\\\vdots\\\\1 \n%%\\end{pmatrix} \\in \\mathbb{R}^d.\n%\\end{equation}\n\nFor the next sections in this chapter, without special notices, we use $X$ data set\nas the normalized one as default. \n\n\n\\subsection{Data normalization for images in CNNs}\nFor images, we have a color image data set $(X,Y) := \\{(x^i, y^i)\\}_{i=1}^N$.\n%where\n%\\begin{equation}\\label{key}\n%x^i \\in \\mathbb{R}^{3 \\times m\\times n}.\n%\\end{equation}\nWe further denote these the $(s,t)$ pixel value for data $x_i$ at channel $j$ as:\n\\begin{equation}\\label{key}\nx^{i,j}_{s,t} \\longleftrightarrow (s,t) \\text{ pixel value for } x^i \\text{ at channel } j,\n\\end{equation}\nwhere $1\\le i \\le N, 1\\le j\\le 3, 1\\le s \\le m$, and  $1\\le t\\le n$.\n\nThen, the normalization for $x^i$ is defined by\n\\begin{equation}\\label{key}\n\\tilde x^{i,j}_{s,t} = \\frac{x^{i,j}_{s,t} - \\mu_X^j }{\\sqrt{\\sigma_X^j}},\n\\end{equation}\nwhere %$\\bm 1 \\in \\mathbb{R}^{m\\times n}$ with all elements equal to $1$ and\n$\nx^{i,j}_{s,t}, \\tilde x^{i,j}_{s,t}, \\mu_X^j, \\sigma_X^j \\in \\mathbb{R}.\n$\nThis means that we need to normalize the data for each channel. Here\n\\begin{equation}\\label{key}\n\\mu_X^j = \\frac{1}{m\\times n\\times N} \\sum_{ 1 \\le i \\le N} \\sum_{1\\le s \\le m, 1 \\le t \\le n} x^{i,j}_{s,t}.\n\\end{equation}\nThere are two common choices of $\\sigma_X^j$:\n\\begin{enumerate}\n\\item Batch normalization also uses the \nformula below to compute the variance in CNN for each channel.\n\\begin{equation}\\label{key}\n\\sigma_X^j = \\frac{1}{ N \\times m\\times n} \\sum_{ 1 \\le i \\le N} \\sum_{1\\le s \\le m, 1 \\le t \\le n} (x^{i,j}_{s,t} -\\mu_X^j )^2.\n\\end{equation}\n% we confirmed with Lian by both numerical test and code checking that BN also use the above \n%formula to compute the variance in CNN for each channel.\n\\item\nAnother way to compute the variance over each channel is to compute the standard deviation on each channel for every data,\nand then average them in the data direction.\n\\begin{equation}\\label{key}\n\\sqrt{\\tilde \\sigma_X^j} = \\frac{1}{ N} \\sum_{ 1 \\le i \\le N}  \\left( \\frac{1}{m\\times n}\\sum_{1\\le s \\le m, 1 \\le t \\le n} (x^{i,j}_{s,t} - \\mu_i^j )^2 \\right)^{\\frac{1}{2}},\n\\end{equation}\nwhere\n$\\displaystyle \n\\mu_i^j  = \\frac{1}{m\\times n} \\sum_{1\\le s \\le m, 1 \\le t \\le n} x^{i,j}_{s,t}.\n$\n\\end{enumerate}\n\n\\begin{example}[Comparison of $\\sqrt{[\\sigma_X]_j}$ and  $\\sqrt{[\\tilde \\sigma_X]_j}$ on CIFAR10.]\n\n\nOn CIFAR10, both ways share the same $\\mu_X$ as\n\\begin{equation}\\label{key}\n\\mu_X = \\begin{pmatrix}\n0.49140105 & 0.48215663 & 0.44653168\n\\end{pmatrix}.\n\\end{equation}\nBut they had different standard deviation estimates:\n\\begin{equation}\n\\begin{aligned}\n\\sqrt{\\sigma_X^j} &= \\begin{pmatrix}\n0.24703284 & 0.24348499 & 0.26158834\n\\end{pmatrix} \\\\\n%\\sqrt{[\\bar \\sigma_X]_j} &= \\begin{pmatrix}\n%0.12835675 & 0.12578563 & 0.1533168\n%\\end{pmatrix} \\\\\n\\sqrt{\\tilde \\sigma_X^j} &= \\begin{pmatrix}\n0.20220193 & 0.19931635 & 0.20086373\n\\end{pmatrix} \n\\end{aligned}\n\\end{equation}\nThis numerical shows that the two normalization are different.\n\\end{example}\n\n\\endinput\n\n\n\\subsubsection{Data normalization for images}\nFor images, consider we have a color image data set $(X,Y) := \\{(x_i, y_i)\\}_{i=1}^N$ where\n\\begin{equation}\\label{key}\nx_i \\in \\mathbb{R}^{3 \\times m\\times n}.\n\\end{equation}\nWe further denote these the $(s,t)$ pixel value for data $x_i$ at channel $j$ as:\n\\begin{equation}\\label{key}\n[x_i]_{j;st} \\longleftrightarrow (s,t) \\text{ pixel value for } x_i \\text{ at channel } j,\n\\end{equation}\nwhere $1\\le i \\le N, 1\\le j\\le 3, 1\\le s \\le m$, and  $1\\le j\\le n$.\n\nThen, the normalization for $x_i$ is defined by\n\\begin{equation}\\label{key}\n[\\tilde x_i]_{{j;st}} = \\frac{[x_i]_{{j;st}} - [\\mu_X]_j }{\\sqrt{[\\sigma_X]_j}},\n\\end{equation}\nwhere %$\\bm 1 \\in \\mathbb{R}^{m\\times n}$ with all elements equal to $1$ and\n\\begin{equation}\\label{key}\n[x_i]_{{j;st}}, [\\tilde x_i]_{{j;st}}, [\\mu_X]_j, [\\sigma_X]_j \\in \\mathbb{R}.\n\\end{equation}\nHere \n\\begin{equation}\\label{key}\n[\\mu_X]_j = \\frac{1}{m\\times n\\times N} \\sum_{ 1 \\le i \\le N} \\sum_{1\\le s \\le m, 1 \\le t \\le n} [x_i]_{j;st}.\n\\end{equation}\nand \n\\begin{equation}\\label{key}\n[\\sigma_X]_j = \\frac{1}{ N \\times m\\times n} \\sum_{ 1 \\le i \\le N} \\sum_{1\\le s \\le m, 1 \\le t \\le n} ([x_i]_{j;st} -[\\mu_X]_j )^2.\n\\end{equation}\nIn batch normalization, they also adopt this form.\n\n\n\\subsection{Batch normalization for CNN}\nFor simplicity, then have the following BN scheme for CNN\n\\begin{equation}\\label{def:BNeq-traningCNN}\n\\begin{aligned}\n[\\mu^\\ell_{\\mathcal B_t}]_{j} & \\leftarrow \\frac{1}{m \\times m_\\ell \\times n_\\ell }\\sum_{i=1}^m \\sum_{1\\le s\\le m_\\ell, 1\\le t \\le n_\\ell} [f^\\ell(x_i)]_{j;st}  &&\\text{ mean on channel }j \\\\\n[\\sigma^\\ell_{\\mathcal B_t}]_{j}^2 & \\leftarrow \\frac{1}{m \\times m_\\ell \\times n_\\ell }\\sum_{i=1}^m \\sum_{1\\le s\\le m_\\ell, 1\\le t \\le n_\\ell} ([f^\\ell(x_i)]_{j;st}-[\\mu_{\\mathcal B_t}]_j)^2   &&\\text{ variance on channel }j\\\\\n[\\hat f^\\ell (x)]_{j;st} & \\leftarrow \\frac{[f^\\ell(x)]_{j,st}-[\\mu^\\ell_{\\mathcal B_t}]_j}{\\sqrt{[\\sigma^\\ell_{\\mathcal B_t}]_j^2+\\epsilon}}   &&\\text{ normalize }\\\\\n[{\\rm BN}_{\\mathcal B_t}(\\tilde f^{\\ell})]_{j;st} &:= [\\tilde f^\\ell(x)]_{j;st}  \\leftarrow [\\gamma^\\ell]_j [\\hat f^\\ell (x)]_{j;st} + [\\beta^\\ell]_{j} \n&&\\text{ scale and shift on channel}\n\\end{aligned}\n\\end{equation}\n\n\n\\subsection{Different methods in computing ``standard deviation'' in one channel}\nNow basically, we have the following three different ways to \ncompute the $\\sqrt{[\\sigma_X]_j}$, different ways correspond to different\nassumption for data distribution in one channel.\n\n\\subsubsection{1: Whiting via covariance matrix}\nFor simplicity, we assume data set $ X = \\{ x_i~:~ i = 1:N\\} \\subset \\mathbb{R}^d$ \nsampled from a random vector $x$, then the whiting processing for these data set is\n\\begin{equation}\\label{key}\n\\tilde x_i = {\\rm Cov}^{-\\frac{1}{2}}(X)(x_i - \\mu),\n\\end{equation}\nwhere\n\\begin{equation}\\label{key}\n\\mu = \\frac{1}{N} \\sum_{i} x_i \\approx \\mathbb{E}[x] \\in \\mathbb{R}^d,\n\\end{equation}\nand\n\\begin{equation}\\label{key}\n{\\rm Cov}(X) = \\frac{1}{N} \\sum_{i} (x_i - \\mu) (x_i - \\mu)^T \\approx \\mathbb{E}[(x-\\mathbb{E}[x])(x-\\mathbb{E}[x])^T]\\in \\mathbb{R}^{d\\times d}.\n\\end{equation}\nThis processing makes\n\\begin{equation}\\label{key}\n\\tilde \\mu = \\frac{1}{N} \\sum_{i} \\tilde x_i = 0 \\in \\mathbb{R}^d,\n\\end{equation}\nand \n\\begin{equation}\\label{key}\n{\\rm Cov}(\\tilde X) = \\frac{1}{N} \\sum_{i} (\\tilde x_i - \\tilde \\mu) (\\tilde x_i - \\tilde \\mu)^T = I \\in \\mathbb{R}^{d\\times d}.\n\\end{equation}\n\n\\subsection{2: Normalizing via diagonal matrix}\n%If we make the assumption that all components of the random vector $x$ are independent. \n%Then, this means that \n%\\begin{equation}\\label{key}\n% \\mathbb{E}[(x-\\mathbb{E}[x])(x-\\mathbb{E}[x])^T] \\text{ is a diagonal matrix. } \n%\\end{equation}\\\\\nHere we just want the result that each marginal distribution for $x$ share the same variance, that\nis \n\\begin{equation}\\label{key}\n\\mathbb{V}[[x]_i] = \\mathbb{V}[[x]_j].\n\\end{equation}\n\nThis leads us the following element-wise version of normalization:\n\\begin{equation}\\label{norm-D}\n\\tilde x_i = D^{-\\frac{1}{2}}{(x_i - \\mu)},\n\\end{equation}\nwhere\n\\begin{equation}\\label{key}\n\\mu = \\frac{1}{N} \\sum_{i} x_i \\approx \\mathbb{E}[x] \\in \\mathbb{R}^d,\n\\end{equation}\nand\n\\begin{equation}\\label{key}\nD = \\frac{1}{N} {\\rm Diag}(\\sum_{i} (x_i - \\mu) \\odot (x_i - \\mu) ).\n\\end{equation}\n\nThis leads to\n\\begin{equation}\\label{key}\n\\tilde \\mu = \\frac{1}{N} \\sum_{i} \\tilde x_i = 0 \\in \\mathbb{R}^d,\n\\end{equation}\nand \n\\begin{equation}\\label{key}\n \\frac{1}{N} \\sum_{i} (\\tilde x_i - \\tilde \\mu) \\odot (\\tilde x_i - \\tilde \\mu) = (1,1,\\cdots,1)^T,\n\\end{equation}\nwhich means that $[\\tilde x]_i$ and $[\\tilde x]_j$ share the same variance as two random variable.\n\n\\blue{This normalization is already OK for the assumption of weight initialization in Xaviar's analysis.}\n\nThus, we may understand all other method as an approximated or modified version for the \\eqref{norm-D}.\n\n\\subsection{Version 1:  keep $\\mu \\in \\mathbb{R}^d$ but $D$ as a scaler by scaler variance.}\n\\begin{equation}\\label{norm-D}\n\\tilde x_i = D^{-\\frac{1}{2}}{(x_i - \\mu)},\n\\end{equation}\nhere \n\\begin{equation}\\label{key}\n\\mu = \\frac{1}{N} \\sum_{i} x_i \\approx \\mathbb{E}[x] \\in \\mathbb{R}^d,\n\\end{equation}\nand\n\\begin{equation}\\label{key}\nD = \\frac{1}{N}  \\sum_{i} \\|x_i - \\mu\\| = \\frac{1}{N} \\sum_{i} ( \\sum_{j} \\frac{1}{d}([x_i]_j - [\\mu]_j) )^{\\frac{1}{2}}.\n\\end{equation}\n\n\\subsubsection{Version 2: let $\\mu$  and $D$ both scaler by averaging over all components of $x$.}\nIn continuous, for mean\n\\begin{equation}\\label{key}\n\\mu = \\frac{1}{d} \\sum_t \\mathbb{E}[[x]_t],\n\\end{equation}\nthis leads to the statistics \n\\begin{equation}\\label{key}\n\\frac{1}{N \\times d} \\sum_{i} \\sum_{t} [x_i]_t.\n\\end{equation}\nFor ``variance'',\n\\begin{equation}\\label{key}\n\\sigma =  \\frac{1}{d} \\sum_t \\mathbb{E}[([x]_t - \\mathbb{E}[[x]_t])^2],\n\\end{equation}\nthen this leads to\n\\begin{equation}\\label{key}\n\\frac{1}{N \\times d} \\sum_{i} \\sum_{t} ([x_i]_t - \\mathbb{E}[[x_i]_t])^2.\n\\end{equation}\nThis is different from what we did in BN.\n\nHowever, if we further take $\\mathbb{E}[[x_i]_t] = $ some scaler, then it is natural to take  \n\\begin{equation}\\label{key}\n\\mathbb{E}[[x_i]_t] = \\mathbb{E}[[x_i]_s] = \\frac{1}{N \\times d} \\sum_{i} \\sum_{t} [x_i]_t.\n\\end{equation}\nThen for multi-channel image data, we have:\n\\begin{equation}\\label{key}\n[\\sigma_X]_j = \\frac{1}{ N \\times m\\times n} \\sum_{ 1 \\le i \\le N} \\sum_{1\\le s \\le m, 1 \\le t \\le n} ([x_i]_{j;st} -[\\mu_X]_j )^2.\n\\end{equation}\nThis scheme is adopted in BN.\n\n\\subsubsection{Version 3:   let $\\mu$  scale but compute $D^{\\frac{1}{2}}$ directly}\nIn continuous, for mean\n\\begin{equation}\\label{key}\n\\mu = \\frac{1}{d} \\sum_t \\mathbb{E}[[x]_t],\n\\end{equation}\nthis leads to the statistics \n\\begin{equation}\\label{key}\n\\frac{1}{N \\times d} \\sum_{i} \\sum_{t} [x_i]_t.\n\\end{equation}\nThis is the same with before.\n\nFor standard deviation,\n\\begin{equation}\\label{key}\n\\sigma^{\\frac{1}{2}} =  \\mathbb{E} (\\frac{1}{d} \\sum_t [([x]_t - \\mathbb{E}[[x]_t])^2])^{\\frac{1}{2}},\n\\end{equation}\nthen this leads to\n\\begin{equation}\\label{key}\n\\frac{1}{N \\times d} \\sum_{i} \\sum_{t} ([x_i]_t - \\mathbb{E}[[x_i]_t])^2.\n\\end{equation}\nThen for CNN, we got\n\\begin{equation}\\label{key}\n\\sqrt{[\\tilde \\sigma_X]_j} = \\frac{1}{ N} \\sum_{ 1 \\le i \\le N} \\sqrt{[\\tilde \\sigma_{X_i}]_j}  =\\frac{1}{ N} \\sum_{ 1 \\le i \\le N}  \\left( \\frac{1}{m\\times n}\\sum_{1\\le s \\le m, 1 \\le t \\le n} ([x_i]_{j;st} -[\\mu_{X_i}]_j )^2 \\right)^{\\frac{1}{2}}.\n\\end{equation}\nThe most commonly used standard deviation for CIFAR10 in Pytorch adopts this way.\n\n\n\n\\subsection{Let $ [\\bar x_i]_j  = \\frac{1}{m\\times n} \\sum_{s,t} [x_i]_{j;st} \\sim \\bar D$ on $\\mathbb{R}$ for all $i$ index.}\nThen, this leads to the following scheme for $\\sqrt{[\\sigma_X]_j}$ \n\\begin{equation}\n[\\bar \\sigma_X]_j = \\frac{1}{ N } \\sum_{ 1 \\le i \\le N} ([\\bar x_i]_{j} -[\\mu_X]_j )^2,\n\\end{equation}\nwhere $[\\bar x_i]_j  = \\frac{1}{m\\times n} \\sum_{s,t} [x_i]_{j;st}$.\n\nThis formula seems better in mathematics.\n\nHowever, how to understand this from the normalization viewpoint? \n\n\n\n\n\n\\subsection{Comparison of $\\sqrt{[\\sigma_X]_j}, \\sqrt{[\\bar \\sigma_X]_j}$ and  $\\sqrt{[\\tilde \\sigma_X]_j}$ on CIFAR10.}\n\nThey share the same $\\mu_X$ as\n\\begin{equation}\\label{key}\n\\mu_X = \\begin{pmatrix}\n0.49140105 & 0.48215663 & 0.44653168\n\\end{pmatrix}.\n\\end{equation}\nBut they had different standard deviation estimates:\n\\begin{equation}\n\\begin{aligned}\n\\sqrt{[\\sigma_X]_j} &= \\begin{pmatrix}\n0.24703284 & 0.24348499 & 0.26158834\n\\end{pmatrix} \\\\\n\\sqrt{[\\bar \\sigma_X]_j} &= \\begin{pmatrix}\n0.12835675 & 0.12578563 & 0.1533168\n\\end{pmatrix} \\\\\n\\sqrt{[\\tilde \\sigma_X]_j} &= \\begin{pmatrix}\n0.20220193 & 0.19931635 & 0.20086373\n\\end{pmatrix} \n\\end{aligned}\n\\end{equation}\n\nI am very strange about this, because we could also do like the following:\n\\begin{equation}\\label{key}\n\\sqrt{[\\sigma_X]_j} = \\frac{1}{ m\\times n} \\sum_{1\\le s \\le m, 1 \\le t \\le n} \\left( \\frac{1}{m} \\sum_{ 1 \\le i \\le N}  ([x_i]_{j;st} -[\\mu_X]_j )^2 \\right)^{\\frac{1}{2}}.\n\\end{equation}\n\n\n", "meta": {"hexsha": "9ba44f64b598d9eacc8c3d917ac9c1d9f8e09dc4", "size": 15696, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ImageNormalization.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/ImageNormalization.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/ImageNormalization.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.9817232376, "max_line_length": 249, "alphanum_fraction": 0.6614424057, "num_tokens": 6213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.8807970904940925, "lm_q1q2_score": 0.7414775877930833}}
{"text": "\\section{Spectrum of Autoregressive Processes}\n\\subsection{Shortcomings of unbiased ACF}\nBased on the Yule-Walker equations, the autoregressive parameters can be obtained by the inversion of autocorrelation matrix, as expressed in Eq.\\ref{proof:ar}.\n\\begin{equation}\n\\mathbf{r}_{xx}=\\mathbf R_{xx}\\mathbf a \\quad \\Rightarrow \\quad \\mathbf a=\\mathbf R^{-1}_{xx}\\mathbf {r}_{xx}\n\\label{proof:ar}\n\\end{equation}\nTherefore, the ACF matrix $\\mathbf {R}_{xx}$ is positive semi-definite for biased estimator which is invertible. As to unbiased ACF shown in previous section, the autocorrelation matrix may be singular which can not be inverted.\n\\subsection{AR Modelling with few samples}\nGiven the autoregressive parameters $\\mathbf a$ =[2.76 -3.81 2.65 -0.92] and the white noise power $\\sigma^2=1$, the estimation of AR modelling process with the order $p$ from 2 to 14 is shown in Fig.\\ref{fig:1_4_b}. The AR model has a frustrated performance with low order which only detects one peak. With the order increasing, the estimation is approaching to the actual frequency response. However, the AR(4) model perform poorly although it consists with the true order of filter. This is probably caused by the small number of available samples with $N=500$. Therefore, in order to obtain desirable response, either the order of AR model or the number of sample should increase. \n\\begin{figure}[htbp]\n     \\centering\n     \\begin{subfigure}[b]{0.35\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/14/14b1.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.35\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/14/14b2.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.35\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/14/14b3.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.35\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/14/14b4.eps}\n     \\end{subfigure}\n        \\caption{AR Model with varying order}\n        \\label{fig:1_4_b}\n\\end{figure}\n\\subsection{AR modelling with increasing samples}\nRepeat the process in previous section except applying $10k$ samples to model. When the AR order $p < p_{actrual =4}$, the autoregressive parameters can not be estimated. As shown in Fig.\\ref{fig:1_4_c}, the AR(2) model only captures one peak frequency, which is an under-modelling estimation. However, the AR model matches the actual response with two peaks when the order $p$ is larger than 4. Moreover, increasing order ($p>5$) brought less improvement between actual response and estimation. Therefore, the optimal order for the large number of sample is $4^{th}$.\n\\begin{figure}[htbp]\n     \\centering\n     \\begin{subfigure}[b]{0.35\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/14/14c1.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.35\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/14/14c2.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.35\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/14/14c3.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.35\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/14/14c4.eps}\n     \\end{subfigure}\n        \\caption{AR Modelling with $10k$ samples}\n        \\label{fig:1_4_c}\n\\end{figure}\n", "meta": {"hexsha": "31a0cb0d5d61375eeeb78747fd50f86a57c1e843", "size": 3428, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/sections/Part1/14.tex", "max_stars_repo_name": "zdhank/Adaptive-Signal-Processing", "max_stars_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-05T10:27:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-19T08:55:10.000Z", "max_issues_repo_path": "Report/sections/Part1/14.tex", "max_issues_repo_name": "zdhank/Adaptive-Signal-Processing", "max_issues_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/sections/Part1/14.tex", "max_forks_repo_name": "zdhank/Adaptive-Signal-Processing", "max_forks_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.1967213115, "max_line_length": 685, "alphanum_fraction": 0.7053675613, "num_tokens": 968, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.8418256492357359, "lm_q1q2_score": 0.7414775799160201}}
{"text": "\\section{Useful Mathematical Information}\nHere are some helpful mathematical notes.\nI also put more mathematical information throughout this document in various section that is not contained here, so be sure to study that information as well.\n\n\\subsection{Numerical Data}\n\\subsubsection{Mathematical Data}\n\\(\\pi\\approx3.1\\)\\\\*\n\\(e\\approx2.7\\)\\\\*\n\\(\\mathrm{ln}2\\approx.7\\)\\\\*\n\\(\\sqrt{2}\\approx1.4\\)\\\\*\n\\(\\sqrt{3}\\approx1.7\\)\\\\*\n\\(\\sqrt{10}\\approx\\pi\\)\\\\\\\\*\n\\(\\sin(30^{\\circ})=\\cos(60^{\\circ})=\\frac{1}{2}=.5\\)\\\\*\n\\(\\sin(45^{\\circ})=\\cos(45^{\\circ})=\\frac{1}{\\sqrt{2}}\\approx.71\\)\\\\*\n\\(\\sin(60^{\\circ})=\\cos(30^{\\circ})=\\frac{\\sqrt{3}}{2}\\approx.87\\)\n\\subsubsection{Physical Data}\nGravitational Constant: \\(G\\approx6.67\\times10^{-11}(Nm^2/kg^2)\\)\\\\*\nProton Mass:  \\(m_p\\approx1.7\\times10^{-27}(kg)\\)\\\\*\nElectron Mass: \\(m_e\\approx9.1\\times10^{-31}(kg)\\)\\\\*\nElectron Charge: \\(e\\approx1.6\\times10^{-19}(C)\\)\\\\*\nVacuum Permittivity: \\(\\epsilon_0\\approx9\\times10^{-12}(C^2/Nm^2)\\)\\\\*\nCoulomb's Constant: \\(k_e=\\frac{1}{4\\pi\\epsilon_0} \\approx 9\\times10^8(Nm^2/C^2)\\)\\\\*\nVacuum Permeability: \\(\\mu_0=4\\pi\\times10^{-7}(N/A^2)\\)\\\\*\nPlank's Constant: \\(h\\approx6.6\\times10^{-34}(Js)\\)\\\\*\nModified Plank's Constant: \\(\\hbar =\\frac{h}{2\\pi}\\approx10^{-34}(Js)\\)\\\\*\nStefan-Boltzman constant: \\(\\sigma=5.7\\times10^{-8}(W/m^2K^4)\\)\\\\*\nSpeed of Light: \\(c=\\frac{1}{\\sqrt{\\epsilon_0\\mu_0}}\\approx3\\times10^{8}(m/s)\\)\\\\*\n\\\\*\nEarth Data:\\\\*\n Acceleration Due to Gravity: \\(g \\approx 10(m/s^2)\\)\\\\*\n Year: \\(T_{year}\\approx\\pi\\times10^{7}(s)\\)\\\\*\nAverage Radius: \\(R_E\\approx6\\times10^6 (m)\\)\\\\*\nMass: \\(M_E\\approx6\\times10^{24}(kg)\\)\\\\*\nAverage distance from the Sun to Earth: \\(1(A.U.)\\approx1.5\\times10^{11}(m)\\)\\\\*\nAverage distance from the Moon to Earth: \\(\\sim4\\times10^{8}(m)\\)\\\\*\nIntensity at Earth's surface: \\(\\sim1.3\\times10^3(W/m^2)\\)\\\\*\nAtmospheric Pressure: \\(1(atm)\\approx10^5(Pa)\\)\\\\*\nMass of Atmosphere: \\(\\sim5\\times10^{18}(kg)\\)\\\\*\nDensity of Atmosphere at Sea Level: \\(\\sim1.2(kg/m^3)\\)\\\\*\nNumber Density of Atmosphere at Sea Level: \\(\\sim2.5\\times10^{25}(molecules/m^3)\\)\\\\*\n\\(90\\%\\) of atmosphere is below \\(16(km)\\)\n\n\\subsection{Areas and Volumes}\n\n\\subsubsection{Areas}\nCircle: \\(\\pi r^2\\)\\\\*\nTriangle: \\(\\frac{1}{2}bh\\)\\\\*\nFunction in \\(x\\)-\\(y\\) Plane: \\(\\int_{x_1}^{x_2}f(x)\\,\\mathrm{d}x\\)\\\\*\nSphere: \\(4\\pi r^2\\)\\\\*\nCylinder: \\(2\\pi r^2+2\\pi rl\\)\n\n\\subsubsection{Volumes}\nSphere: \\(\\frac{4}{3}\\pi r^3\\)\\\\*\nCylinder: \\(\\pi r^2l\\)\n\n\\subsection{Trigonometric Identities}\n\n\\subsubsection{Pythagorean Identity}\n\\(\\sin^2(\\theta)+\\cos^2(\\theta)=1\\)\n\n\\subsubsection{Double Angle}\n\\(\\sin(2\\theta)=2\\sin(\\theta)\\cos(\\theta)\\)\\\\*\n\\(\\cos(2\\theta)=\\cos^2(\\theta)-\\sin^2(\\theta)\\)\n\n\\subsubsection{Half Angle}\n\\(\\sin^2\\left(\\frac{\\theta}{2}\\right)=\\frac{1}{2}\\left(1-\\cos(\\theta)\\right)\\)\\\\*\n\\(\\cos^2\\left(\\frac{\\theta}{2}\\right)=\\frac{1}{2}\\left(1+\\cos(\\theta)\\right)\\)\n\n\\subsubsection{Euler's Identity}\n\\(e^{i\\theta}=\\cos{\\theta}+i\\sin{\\theta}\\)\n\n\\subsection{Vector Identities}\n\n\\subsubsection{Triple Scalar Product}\n\\(\\mathbf{A}\\cdot(\\mathbf{B}\\times\\mathbf{C})=\\mathbf{B}\\cdot(\\mathbf{C}\\times\\mathbf{A})=\\mathbf{C}\\cdot(\\mathbf{A}\\times\\mathbf{B})\\)\n\n\\subsubsection{Triple Vector Product}\n\\(\\mathbf{A}\\times(\\mathbf{B}\\times\\mathbf{C})=\\mathbf{B}(\\mathbf{A}\\cdot\\mathbf{C})-\\mathbf{C}(\\mathbf{A}\\cdot\\mathbf{B})\\)\n\n\\subsection{Fundamental Theorem of Caculus}\n\\(\\displaystyle \\int_{x_1}^{x_2}{\\frac{\\mathrm{d}f(x)}{\\mathrm{d}x}\\mathrm{d}x}=f(x_2)-f(x_1)\\)\\\\\\\\*\n\\(\\displaystyle \\int_{\\mathbf{a}}^{\\mathbf{b}}{(\\nabla f)\\cdot\\mathrm{d}\\mathbf{l}}=f(\\mathbf{b})-f(\\mathbf{a})\\)\\\\\\\\*\n\\(\\displaystyle \\int_{A}{(\\nabla\\times\\mathbf{F})\\cdot\\mathrm{d}\\mathbf{a}}=\\oint_{\\delta A}{\\mathbf{F}\\cdot\\mathrm{d}\\mathbf{l}}\\)\\\\\\\\*\n\\(\\displaystyle \\int_{V}{(\\nabla\\cdot\\mathbf{F})\\mathrm{d}V}=\\oint_{\\delta V}{\\mathbf{F}\\cdot\\mathrm{d}\\mathbf{a}}\\)\\\\\\\\*\nIn general: \\(\\displaystyle\\int_{\\Omega}{\\mathrm{d}\\omega}=\\oint_{\\delta\\Omega}{\\omega}\\)\\\\*\nHere \\(\\omega\\) is a (\\(n-1\\))-form, \\(\\Omega\\) is a manifold of dimension \\(n\\), and \\(\\mathrm{d}\\) is the exterior derivative\n\n\\subsection{Fourier Series}\nFor function with \\(2L\\) periodicity:\\\\*\n\\(\\displaystyle f(x)=\\frac{1}{2}a_0+\\sum_{n=1}^\\infty a_n\\cos(nx)+\\sum_{n=1}^\\infty b_n\\sin(nx)\\)\\\\*\n\\(\\displaystyle a_0=\\frac{1}{L}\\int_{-L}^{L}f(x)\\,\\mathrm{d}x\\)\\\\*\n\\(\\displaystyle a_n=\\frac{1}{L}\\int_{-L}^{L}f(x)\\cos(nx)\\,\\mathrm{d}x\\)\\\\*\n\\(\\displaystyle b_n=\\frac{1}{L}\\int_{-L}^{L}f(x)\\sin(nx)\\,\\mathrm{d}x\\)\\\\\\\\*\nIf the function has half- or quarter-wave symmetry, then \\(n\\) takes on only odd values.\n\n\\subsection{Delta Function}\n\\[\\displaystyle\\int_{a}^{b}f(x)\\delta(x-x_0)\\,\\mathrm{d}x = \\left\\{\n\\begin{array}{l l}\n  f(x_0) & \\quad \\mbox{\\(a\\leq x_0\\leq b\\)}\\\\\n  0 & \\quad \\mbox{otherwise}\\\\ \\end{array} \\right. \\]\n\\(\\delta(cx)=\\frac{1}{|c|}\\delta(x)\\)\n\n\\subsection{Step Function}\n\\[\\theta(x) = \\left\\{\n\\begin{array}{l l}\n  1 & \\quad \\mbox{\\(x>0\\)}\\\\\n  1/2 & \\quad \\mbox{x=0}\\\\\n  0 & \\quad \\mbox{\\(x<0\\)}\\\\ \\end{array} \\right. \\]\n\\(\\displaystyle\\frac{\\mathrm{d}\\theta}{\\mathrm{d}x}=\\delta(x)\\)\n\n\\subsection{Legendre Polynomials}\n\\(\\displaystyle P_l(x)=\\frac{1}{2^ll!}\\left(\\frac{\\mathrm{d}}{\\mathrm{d}x}\\right)^l\\left(x^2-1\\right)^l\\)\\\\\\\\*\n\\(P_l(1)=1\\)\\\\*\n\\(P_0(x)=1\\)\\\\*\n\\(P_1(x)=x\\)\\\\*\n\\(P_2(x)=(3x^2-1)/2\\)\\\\\\\\*\n\\(\\displaystyle \\int_{-1}^{1}P_l(x)P_{l'}(x)\\mathrm{d}x=\\frac{2}{2l+1}\\delta_{ll'}\\)\n\n\\subsection{Spherical Harmonics}\n\\(\\displaystyle Y^{m}_{l}\\left(\\theta,\\phi\\right)=\\sqrt{\\frac{(2l+1)(l-m)!}{4\\pi(l+m)!}}P_{l}^{m}(\\cos{\\theta})e^{im\\phi}\\)\\\\*\nwhere \\(P_{l}^{m}\\) is the associated Legendre polynomial\\\\\\\\*\n\\(\\displaystyle\\int_{0}^{\\pi}{\\int_{0}^{2\\pi}{Y_{l}^{m}Y_{l'}^{*m'}\\sin{\\theta}\\mathrm{d}\\phi\\mathrm{d}\\theta}}=\\delta_{ll'}\\delta_{mm'}\\)\\\\\\\\*\nThe concept of an orthonormal set of basis vectors is very important for this test.\n\n\\subsection{Common Approximations}\nFor physical units:\\\\*\n\\(1(mi)\\approx1.6(km)\\)\\\\*\n\\(1(rpm)=\\frac{\\pi}{30}(rad/s)\\approx.1(rad/s)\\)\\\\\\\\*\nFor small \\(\\beta\\) (special relativity):\\\\*\n\\(\\gamma\\approx1+\\frac{1}{2}\\beta^2\\)\\\\*\n\\(\\frac{1}{\\gamma}\\approx1-\\frac{1}{2}\\beta^2\\)\\\\\\\\*\nFor small \\(x\\):\\\\*\n\\(\\cos{x}\\approx1\\)\\\\*\n\\(\\tan{x}\\approx\\sin{x}\\approx x\\)\\\\*\n\\(\\sqrt{1+x}\\approx1+\\frac{1}{2}x\\)\\\\*\n\\(e^x\\approx1+x\\)\\\\*\n\\((1+x)^n\\approx1+nx\\)\n", "meta": {"hexsha": "855ed84585961c5d9b10f82ebc89335db87fcf73", "size": 6233, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/math.tex", "max_stars_repo_name": "jhetherly/Physics_GRE_Review", "max_stars_repo_head_hexsha": "3edbd342c1d1bf39502b4c6838828501e145e408", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-07-11T13:33:29.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-11T13:33:29.000Z", "max_issues_repo_path": "src/math.tex", "max_issues_repo_name": "jhetherly/Physics_GRE_Review", "max_issues_repo_head_hexsha": "3edbd342c1d1bf39502b4c6838828501e145e408", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/math.tex", "max_forks_repo_name": "jhetherly/Physics_GRE_Review", "max_forks_repo_head_hexsha": "3edbd342c1d1bf39502b4c6838828501e145e408", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.1666666667, "max_line_length": 158, "alphanum_fraction": 0.6253810364, "num_tokens": 2542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7414775737866055}}
{"text": "\\chapter{Mathematical background}\n\\label{chpr:math}\nThe present study starts with an introduction to the mathematical foundations required for its understanding. The reader that is familiar with abstract algebra and elliptic curve cryptography may skip the first two chapters to deal directly with the digital signature schemes presented in Chapter \\ref{chpr:dss}.\n\\\\\nWe start with a brief presentation of the group and field's structures, deferring the introduction to elliptic curves mathematics to the second section. For details and proofs see \\cite{RefWork:20} and \\cite{RefWork:1}.\n\n\\bigskip\n\n\\section{Groups and fields}\n\\label{groupsfields}\n\n\\begin{mydef} {\\bf (Group)}: A group is a set $G \\neq \\emptyset$ together with a binary operation $\\bullet: G \\times G \\to G$ (called the \tgroup law of $G$) that satisfies:\n\t\\begin{itemize}\n\t\t\\item Closure: $\\forall a, b \\in G  \\Longrightarrow a \\bullet b \\in G$;\n\t\t\\item Associativity: $\\forall a, b, c \\in G  \\Longrightarrow (a \\bullet b) \\bullet c = a \\bullet (b \\bullet c)$;\n\t\t\\item Identity: $\\exists e \\in G \\ | \\ \\forall a \\in G, \\ e \\bullet a = a \\bullet e = a$. Such an element $e$ is unique; \n\t\t\\item Invertibility: $\\forall a \\in G, \\ \\exists b \\in G \\ | \\ a \\bullet b = b \\bullet a = e$. This element is unique and it is commonly denoted either as $a^{-1}$ or $-a$, depending on the notation (multiplicative or additive).\n\t\\end{itemize}\n\\end{mydef}\n\\label{def1}\n\\noindent\nAs a careful reader may have noticed, it is not required the property of commutativity. This means that, in general, the result of the operation may depend on the order of the operands. If this is not the case, meaning that the group operation is also commutative, the group is called abelian.\n\\\\\nConsider now a group $(G, +)$: hereinafter we will stick with the additive notation, unless otherwise specified.\nIf $G$ is finite, i.e. it has a finite number of elements, we define the order of $G$ as the number of elements in $G$. We can also define the order of an element $g \\in G$ to be the smallest integer $k > 0$ such that $kg = 0$, where with 0 we denote the additive identity\\footnote{In an additive group it is natural to define the scalar multiplication: given $g \\in G$ and $k \\in \\mathbb{N}, \\ k \\neq 0$, we have that $kg = g + g + ... + g$, where the summation is repeated $k - 1$ times. In a similar fashion, it is natural to define exponentiation in the multiplicative case.}. If $k$ is the order of $g$, then:\n$$ig = jg \\Longleftrightarrow i \\equiv j \\ (\\text{mod} \\ k).$$\nIndeed:\n$$ig = jg \\ \\Longleftrightarrow \\ (i - j)g = 0 \\ \\Longleftrightarrow \\ i - j = nk, \\ n \\in \\mathbb{Z},$$\nfrom which the thesis.\n\\\\\nNext we state a basic result from group theory, that will turn out to be very useful in the following:\n\\begin{thm} {\\bf (Lagrange's theorem)}:\n\tLet $G$ be a finite group.\n\t\\begin{enumerate}\n\t\t\\item Let $H$ be a subgroup\\footnote{Given a group $(G, +)$, a subset $H$ is a subgroup of $G$ if $H$ endowed with the restriction of the group operation to $H \\times H$ is a group.} of $G$. Then the order of $H$ divides the order of $G$;\n\t\t\\item Let $g \\in G$. Then the order of $g$ divides the order of $G$.\n\t\\end{enumerate}\n\\end{thm}\n\n\\bigskip\n\n\\noindent\nFor the cryptographic applications that we will study, a particular family of groups turns out to be very important: cyclic groups. A cyclic group is a group that is generated by a single element: this means that it contains (at least) an element $g$ such that every other element of the group can be obtained by repeatedly applying the group operation to $g$, i.e. $\\forall h \\in G, \\ \\exists n \\in \\{1, ..., k\\} \\ | \\ h = ng$, where $k$ as before denotes the order of $g$. All the group's elements satisfying this property are called generator of the group.\n\\\\\nTwo interesting properties of cyclic groups are the following:\n\\begin{enumerate}\n\t\\item Every cyclic group is abelian;\n\t\\item Every finite group has at least a cyclic subgroup.\n\\end{enumerate}\n\n\\bigskip\n\\noindent\nNow let's get to the mathematical concept of field. A field is a non empty set on which are defined two binary operations, usually called addition and multiplication. It has to be an abelian group under addition (with 0 denoting the additive identity) and the non-zero elements have to form an abelian group under multiplication. Finally, the multiplication has to be distributive over the addition. \n\\\\\nMore precisely we can give the following definition.\n\\begin{mydef} {\\bf (Field)}: A field is a set $K \\neq \\emptyset$ endowed with two binary operations $+$ and $*: K \\times K \\to K$, such that:\n\\begin{itemize}\n\t\\item $(K, +)$ is an abelian group, whose identity element is denoted by 0. This group is called the additive group of the field;\n\t\\item $(K \\text{\\textbackslash}\\{0\\}, *)$ is an abelian group. It is called the multiplicative group of the field, sometimes denoted by $K^{\\times}$ or by $K^*$;\n\t\\item $\\forall a, b, c \\in K: \\ a * (b + c) = a * b + a * c$. \n\\end{itemize}\n\\end{mydef}\n\n\\bigskip\n\\noindent\nAnother key role in the following will be played by finite fields: a finite field is simply a field with a finite number of elements. A finite field of order $q$, denoted as $\\mathbb{F}_q$, exists if and only if $q = p^k$, where $p$ is a prime number and $k$ is a positive integer. The field of a given order is unique, up to an isomorphism (this means that there are different representations of a unique mathematical object). In a field of order $p^k$, the characteristic of the field (as defined below) is $p$: thus adding $p$ copies of any element results in the additive identity. \n\\\\\nIn particular we will deal with prime finite fields, i.e. the finite fields whose order is a prime number. Finite fields of order a prime $p$ may be represented by the set $\\mathbb{Z}_p = \\{0, 1, ..., p-1\\}$ with addition and multiplication defined through modular arithmetic, that is: given $a, b \\in \\mathbb{F}_p$ then $r = a + b$ and $s = a * b$ are integers in $[0, p - 1]$, defined as the remainder of the divisions $(a + b)/p$ and $a*b/p$, respectively. This is usually written as: $a + b \\equiv r \\ (\\text{mod} \\ p)$ and $a * b \\equiv s \\ (\\text{mod} \\ p)$ or as $a + b \\equiv r \\ \\text{in} \\ \\mathbb{F}_p$ and $a * b \\equiv s \\ \\text{in} \\ \\mathbb{F}_p$ . It is easy to see that in this case the additive identity is the integer 0, while the multiplicative identity is the integer 1.\n\\\\\nSubtraction and division are defined via the additive and multiplicative inverses:\n\\begin{itemize}\n\t\\item Subtraction: given $a \\in \\mathbb{F}_p$, we know by definition that there is a unique element $-a \\in \\mathbb{F}_p$ such that $a + (-a) = 0 \\ (\\text{mod} \\ p)$. Then we define subtraction as: $a - b = a + (-b) \\ (\\text{mod} \\ p), \\ \\forall a, b \\in \\mathbb{F}_p$;\n\t\\item Division: $\\forall a \\in \\mathbb{F}_p \\text{\\textbackslash} \\{0\\}, \\ \\exists a^{-1} \\ | \\ a * a^{-1} = 1 \\ (\\text{mod} \\ p)$, again by definition. Thus we can define division as: $a / b = a * (b)^{-1}, \\ \\forall a, b \\in \\mathbb{F}_p, \\ b \\neq 0$.\n\\end{itemize}\nNotice that not all the finite fields $\\mathbb{F}_q$ are isomorphic to $\\mathbb{Z}_q$: consider for example the case $q = 2^2 = 4$. Here $p = 2$ and $k = 2$. Since two is a prime number, we have that there exists a field with four elements. But since four is not a prime number, we cannot represent this field through the set $\\mathbb{Z}_4 = \\{0, 1, 2, 3\\}$. Consider the element 2: 2 * 0 = 0 (mod 4), 2 * 1 = 2 (mod 4), 2 * 2 = 0 (mod 4), 2 * 3 = 2 (mod 4). As we can see it does not admit a multiplicative inverse in $\\mathbb{Z}_4$: for this reason $\\mathbb{Z}_4$ is not a field and cannot be used as representation of $\\mathbb{F}_4$.\n\n\\bigskip\n\\noindent\nWe end this section giving the definition of field characteristic, that will be useful when defining the equation of an elliptic curve. \n\\begin{mydef} {\\bf (Field characteristic)}: Given a field $(K, \\ +, \\ *)$, we denote by 0 and 1 the additive and multiplicative identities, respectively.\n\\\\\nThe characteristic of $K$, denoted as  $\\text{char}(K)$, is defined to be the smallest $n \\in \\mathbb{Z} \\text{\\textbackslash} \\{0\\}$ for which the following relation holds: \n$$\\underbrace{1 + ... + 1}_\\text{$n$ times} = 0$$ \nIn case this relation never holds, the field is said to have characteristic zero.\n\\end{mydef}\n\n\\bigskip\n\n\\bigskip\n\n\\section{Elliptic curves}\n\\label{ec}\nIn the most general case, an elliptic curve over a field $K$ is defined through the equation: $$y^2 + a_1xy + a_2y = x^3 + a_3x^2 + a_4x + a_5,$$ where $a_1, ..., a_5 \\in K$. This form is called generalized Weierstrass equation, and can be simplified according to the characteristic of the field. In particular, if it is different from two and three we can write:\n$$y^2 = x^3 + ax + b, \\ a, b \\in K.$$\nThis latter equation is called Weierstrass equation, and it is the most widely used.\n\\\\\nWe will denote an elliptic curve over a field $K$ through the notation $E(K)$, that represents the set of points satisfying the defining equation. By construction, this set also contains a special point, called the point at infinity (its role will be clarified in the next section): \n$$E(K) = \\{\\infty\\}\\cup\\{(x, y) \\in K \\times K \\ | \\ y^2 = x^3 + ax + b\\}.$$\n\\\\\nTo start familiarizing with elliptic curves, it could be useful to consider the case in which $K = \\mathbb{R}$, the set of real numbers. In Figure \\ref{fig:figure1} we can look at a couple of elliptic curves' real graph.\n\\begin{figure}\n\t\\noindent\n\t\\makebox[\\textwidth]{\\includegraphics[width=15cm, height=7cm]{Images/EC.eps}}\n\t\\captionof{figure}{Two examples of elliptic curves over the real numbers.}\n\t\\label{fig:figure1}\n\t\\source{\\url{https://en.wikipedia.org/wiki/Elliptic_curve\\#Elliptic_curves_over_the_real_numbers}.}\n\\end{figure}\n\\noindent\nAs we can see, the elliptic curves are symmetric with respect to the $x$-axis, so that for every feasible $x$ there are two $y$ values satisfying the Weierstrass equation.\n\\\\\nTypically the Weierstrass equation is coupled with the constraint that the discriminant of the cubic $x^3 + ax + b$ is different from zero. This is equivalent to ask that:\n$$4a^3 + 27b^2 \\neq 0,$$ \nin order to avoid multiple roots. Geometrically, this requirement means that there are no cusps, self intersections or isolated points\\footnote{This requirement has also other implications: it can be shown that, without it, the elliptic curve $E_{ns}(K)$ defined over the non-singular points has an isomorphism with simpler algebraic structures, such as $K$ itself or $K^{\\times}$. This problem typically arises when dealing with elliptic curves modulo composites.}. \nWe can also link the sign of the discriminant to the number of components of the curve: the real graph of a curve has two components if its discriminant is positive, and one component if it is negative, as exemplified in Figure \\ref{fig:figure1} (the discriminant is $\\Delta = -16(4a^3 + 27b^2)$).\n\n\\bigskip\n\\noindent\nWe get back for a moment to the generalized Weierstrass equation, and show how to go from there to the more appealing Weierstrass form:\n$$y^2 + a_1xy + a_2y = x^3 + a_3x^2 + a_4x + a_5,$$ \nwith $a_1,...,a_5$ constants in $K$. We have said that this is the most generic form for an elliptic curve, but what does it exactly mean? It means that it is always possible to reduce to the Weierstrass equation, unless the characteristic of the field over which the curve is defined is two or three. In these two cases, we need to resort to the general formula.\n\\\\\nHowever, if the characteristic of the field is not two we can divide by two\\footnote{Remember that in a field of characteristic two the number two acts as zero, the additive element that has not a multiplicative inverse.} and complete the square: $$\\left(y + \\frac{a_1x}{2} + \\frac{a_2}{2}\\right)^2 = x^3 + \\left(a_3 + \\frac{a_1^2}{4}\\right)x^2 + \\left(a_4 + \\frac{a_1a_2}{2}\\right)x + \\left(\\frac{a_2^2}{4} + a_5\\right),$$ which can be written as $$y_1^2 = x^3 + a_1{'}x^2 + a_2{'}x + a_3{'},$$ with $y_1 = y + \\frac{a_1x}{2} + \\frac{a_2}{2}$ and new constants $a_1{'}, a_2{'}, a_3{'} \\in K$. Moreover, if the characteristic is neither three, then we can consider $x_1 = x + \\frac{a_1{'}}{3}$:\n$$y_1^2 = x^3 + a_1{'}x^2 + a_2{'}x + a_3{'} = \\left(x_1 - \\frac{a_1{'}}{3}\\right)^3 + a_1{'}\\left(x_1 - \\frac{a_1{'}}{3}\\right)^2 + a_2{'}\\left(x_1 - \\frac{a_1{'}}{3}\\right) + a_3{'} = $$ $$= \\left(x_1 - \\frac{a_1{'}}{3}\\right)\\left(x_1^2 + \\frac{a_1{'}^2}{9} -\\frac{2}{3}a_1{'}x_1 + a_1{'}x_1 - \\frac{a_1{'}^2}{3} + a_2{'}\\right) + a_3{'} = $$ $$=\\left(x_1 - \\frac{a_1{'}}{3}\\right) \\left(x_1^2 + \\frac{1}{3}a_1{'}x_1 - \t\\frac{2}{9}a_1{'}^2 + a_2{'}\\right) + a_3{'} = $$ $$= x_1^3 + \\cancel{\\frac{1}{3}a_1{'}x_1^2} - \\frac{2}{9}a_1{'}^2x_1 + a_2{'}x_1 - \\cancel{\\frac{1}{3}a_1{'}x_1^2} - \\frac{1}{9}a_1{'}^2x_1 + \\frac{2}{27}a_1{'}^3 - \\frac{1}{3}a_1{'}a_2{'} + a_3{'} = $$ $$=x_1^3 + \\left(a_2{'} - \\frac{1}{3}a_1{'}^2\\right)x_1 + \\left(\\frac{2}{27}a_1{'}^3 - \\frac{1}{3}a_1{'}a_2{'} + a_3{'}\\right).$$ \nThrough a proper renaming of the constants we get finally to the well known Weierstrass form: $y_1^2 = x_1^3 + ax_1 + b$ for some constants $a$ and $b$ in $K$. \n\\\\\nFinally, for the sake of completion, we present the case of the equation $cy^2 = dx^3 + ax + b$ and how to transform it in Weierstrass form. We can multiply both sides by $c^3d^2$ and write $(c^2dy)^2 = (cdx)^3 + (ac^2d)(cdx) + bc^3d^2$. The change of variables $y_1 = c^2dy$ and $x_1 = cdx$ yields to the desired formulation of the equation.\n\n\\bigskip\n\n\\bigskip\n\n\\subsection{The group law}\n\\label{grouplaw}\nThis section is devoted to the definition of the addition operation between elements in $E(K)$: this operation turns out to be fundamental since it induces the structure of abelian group on the elliptic curve's point. Moreover, we will see why, in the definition of the curve, we had to consider the point at infinity.\n\\\\\nIn particular we will consider $K$ to be the set of real numbers, in order to give an easy graphical representation of the operation. This can be done without loss of generality, since the formulas that we will derive can be shown to be valid for every $K$ with $\\text{char}(K) \\neq 2, 3$. \n\n\\bigskip\n\\noindent\nLoosely speaking we can say that:\n\\begin{itemize}\n\t\\item The points of the elliptic curve are the group's elements;\n\t\\item The identity element is the point at infinity, denoted by $\\infty$;\n\t\\item The inverse of a point $Q$ is the one symmetric about the $x$-axis: $Q = (x, y) \\Longrightarrow -Q = (x, -y)$;\n\t\\item Addition is given by the following rule: given three aligned points on the curve $Q_1$, $Q_2$ and $Q_3$ their sum is $Q_1 + Q_2 + Q_3 = \\infty$.  \n\\end{itemize}\n\n\\begin{center}\n\t\\noindent\n\t\\makebox[\\textwidth]{\\includegraphics[width=20cm, height=5cm]{Images/chord.eps}}\n\t\\captionof{figure}{Geometric interpretation of the addition of EC points.}\n\t\\label{fig:figure2}\n\t\\source{\\url{https://en.wikipedia.org/wiki/Elliptic_curve\\#The_group_law}.}\n\\end{center}\n\\noindent\nIn order to define properly the addition of EC points we need to consider five different cases. We start taking an elliptic curve $E$ defined by the usual equation in Weierstrass form $y^2 = x^3 + ax + b, \\ a,b \\in \\mathbb{R}$ and two points $Q_1 = (x_1, y_1), \\ Q_2 = (x_2, y_2) \\in E(\\mathbb{R})$. Unless otherwise specified, we assume also that $Q_1, Q_2 \\neq \\infty$.\n\\begin{enumerate}\n\t\\item $x_1 \\neq x_2$: consider the line passing through $Q_1$ and $Q_2$. In most of the cases (i.e. when neither the points are tangent points) this line will intersect the curve in a third point, that we denote as $-Q_3$. Then take the reflection with respect to the $x$-axis (i.e. change the sign of the $y$ coordinate): denote this final point as $Q_3$.\n\t\\\\\n\tThe algorithm specified allows us to give meaning to the formula: \n\t$$Q_1 + Q_2 = Q_3.$$\n\tThe one outlined above is the geometrical intuition, but we can obtain algebraic formulas for the operation. The line passing through $Q_1$ and $Q_2$ has equation $y = m(x - x_1) + y_1$, where $m = \\frac{y_2 - y_1}{x_2 - x_1}$ is its slope. Notice that if $x_1 = x_2$ the line is vertical, but we will treat this case later on. We can find the intersections between the line and the curve through a substitution: $(m(x - x_1) + y_1)^2 = x^3 + ax + b$. We have $m^2(x^2 - 2x_1x + x_1^2) + 2my_1(x - x_1) + y_1^2 = x^3 + ax + b$; this formula can be rearranged in the form: $$x^3 - m^2x^2 + (a + 2m^2x_1 - 2my_1)x + (b + 2my_1x_1 - m^2x_1^2 -y_1^2) = 0.$$\n\t\\\\\n\tIn general solving a cubic equation is non trivial, but we have already two roots, namely $x_1$ and $x_2$ since $Q_1$ and $Q_2$ are points on both the line and the curve. To find the third root we notice that, given a cubic polynomial $x^3 + ax^2 + bx + c$ with roots $r, s$ and $t$, we can write: $$x^3 + ax^2 + bx + c = (x - r)(x - s)(x - t) =$$ \n\t$$= x^3 - (r + s + t)x^2 + (rs + rt + st)x - rst.$$\n\tTherefore $r + s + t = - a$, so that, if we know two roots $r$ and $s$, we can find the third as $t = - a - r - s$.\n\t\\\\\n\tIn our case we have $x_1 + x_2 + x_3 = m^2 \\ \\Longrightarrow \\ x_3 = m^2 - x_1 - x_2$. Remembering to change the $y$ coordinate of the intersection point due to the reflection, we get $Q_3$ as: $x_3 = m^2 - x_1 - x_2$ and $y_3 = m(x_1 - x_3) - y_1$.\n\t\\begin{figure}\n\t\t\\noindent\n\t\t\\makebox[\\textwidth]{\\includegraphics[width=15cm, height=7cm]{Images/sum.eps}}\n\t\t\\captionof{figure}{Graphical representation of the point addition.}\n\t\t\\label{fig:figure3}\n\t\\end{figure}\n\t\n\t\\item $x_1 = x_2 \\wedge y_1 \\neq y_2$: the line through $Q_1$ and $Q_2$ is vertical, therefore it intersects $E$ at $\\infty$. Reflecting the point at infinity across the $x$-axis yields to the same point. Therefore, in this case $Q_1 + Q_2 = \\infty$. \n\t\\\\\n\tThis is in agreement with what we stated before: if  $x_1 = x_2 \\wedge y_1 \\neq y_2$ it means that $Q_2 = -Q_1$, and since the point at infinity acts as the identity element we have exactly that $Q_1 + Q_2 = \\infty$.\n\t\n\t\\item $Q_1 = Q_2 = (x_1, y_1) \\wedge y_1 \\neq 0$: when two points on a curve are very close one another, the line through them approximates a tangent line. Therefore, when the two points coincide, we take the line through them to be the tangent line. Implicit differentiation allows us to find its slope $m$:\n\t$$y^2 = x^3 + ax + b \\ \\Longrightarrow \\ \\frac{d(y(x)^2)}{dx} = \\frac{d}{dx}(x^3 + ax + b) \\ \\Longrightarrow$$\n\t$$ \\Longrightarrow \\ \\frac{d(y^2)}{dy}\\frac{dy}{dx}=2y\\frac{dy}{dx}= 3x^2 + a \\ \\Longrightarrow $$ \n\t$$\\Longrightarrow \\ m = \\left(\\frac{dy}{dx}\\right)_{x_1} = \\frac{3x_1^2 + a}{2y_1}.$$\n\tAgain, the equation of the line is $y = m(x - x_1) + y_1$. At this point we can proceed as before: the line intersects the curve in a second point. Substituting the equation of the straight line would result in a cubic equation. But we already know two roots, so that we get: $x_3 = m^2 - 2x_1$ and $y_3 = m(x_1 - x_3) - y_1$.\n\t\\\\\n\t\\item $Q_1 = Q_2 = (x_1, y_1) \\wedge y_1 = 0$: as we can see from the previous point in this case the tangent line is vertical and we set $Q_1 + Q_2 = \\infty$.\n\t\\item The last case we have to deal with is when one of the two points is $\\infty$. Suppose, without loss of generality, that $Q_2 = \\infty$; the line through $Q_1$ and $\\infty$ is a vertical line that intersects $E$ in the point $-Q_1$, which is the reflection of $Q_1$ across the $x$-axis. When we reflect $-Q_1$ to get $Q_3 = Q_1 + Q_2$, we get back to $Q_1$. Therefore:\n\t $$Q_1 + \\infty = Q_1$$\n\tfor all points $Q_1$ on $E$. Of course, we extend this to include $\\infty + \\infty = \\infty$.\n\\end{enumerate}\nThanks to these algebraic formulas we can notice that when $Q_1$ and $Q_2$ have coordinates in a field $K$ that contains $a$ and $b$, then $Q_1 + Q_2$ also has coordinates in $K$. This means that $E(K)$ is closed under the defined addition operation.\n\n\\bigskip\n\\noindent\nNow we state a theorem showing formally that the couple $(E, +)$ is indeed an abelian group. The theorem with the proof can be found in \\cite{RefWork:1}.\n\\begin{thm} The operation $+$ as defined above on an elliptic curve $E$ satisfies the following properties:\n\t\\begin{enumerate}\n\t\t\\item Commutativity: $Q_1 + Q_2 = Q_2 + Q_1, \\ \\forall Q_1, Q_2 \\in E$;\n\t\t\\item Identity: $Q + \\infty = Q, \\ \\forall Q \\in E$;\n\t\t\\item Invertibility: $\\forall Q \\in E, \\ \\exists Q' \\in E \\ | \\ Q + Q' = \\infty$. This point will be denoted by $-Q$;\n\t\t\\item Associativity: $(Q_1 + Q_2) + Q_3 = Q_1 + (Q_2 + Q_3), \\ \\forall Q_1, \\ Q_2, Q_3 \\in E$.\n\t\\end{enumerate}\n\\end{thm}\n\n\\bigskip\n\\noindent\nAlthough we won't prove the theorem, it can be useful to give a sketch of its proof. The commutativity is obvious, either from the formulas or from the fact that the line passing through $Q_1$ and $Q_2$ is the same as the line passing through $Q_2$ and $Q_1$. The identity property of the point at infinity holds by definition, as the existence of the inverse element.\n\\\\\nThe tricky part of the proof is related with associativity: either it can be proved working out the annoying computations or through a much more elegant and complex method based on projective coordinates, for which we again refer to the bibliography.\n\n\\bigskip\n\\noindent\nNow that we have clear in mind what does addition between EC points mean, we can define subtraction and scalar multiplication:\n\\begin{itemize}\n\t\\item Subtraction: given $Q, R \\in E$, we set $Q - R = Q + (-R)$. We can do this since everything is perfectly defined in the right hand side of the equation;\n\t\\item Scalar multiplication: $\\forall k \\in \\mathbb{N}$\\textbackslash$\\{0\\}, \\ kQ = Q + Q + ... + Q$, where the addition is repeated $k - 1$ times.\n\\end{itemize}\nNotice that to compute the scalar multiplication for a large $k$ it is inefficient to add $Q$ to itself repeatedly. There are several faster approaches, the simplest called the {\\bf Double and Add Algorithm}. \nWe stress this fact since, as we will see later on, scalar multiplication and its computational asymmetry are the key ingredients for elliptic curve cryptography: the fact is that it is easily computable\\footnote{The double and add algorithm requires polynomial time in the number of bits $n$ representing the numbers involved, compared to the exponential time required by the naive approach; that is, assuming that the point doubling and the point addition require a constant time, we need $O(n^{\\alpha}), \\ \\alpha > 1$ elementary operations, compared to $O(2^n)$. In particular on average it requires $n$ doublings and $0.5 * n$  additions, since the binary expansion of a random integer has an equal number of 1's and 0's.}\nbut its inversion, the so called discrete logarithm (DL), although not provable to be hard, is believed to be so: this means that in general we have no efficient algorithm to compute it.\n\\\\\n\\\\\n{\\bf Double and Add Algorithm}: To compute $kQ$, start with the binary representation of $k$: $k = k_0 + 2k_1 + 2^2k_2 + ... + 2^nk_n$, where $k_0,...,k_n \\in \\{0, 1\\}$. \n\n\\begin{algorithm}\n\t\\caption{Double and Add algorithm}\n\t\\label{alg:double_add}\n\t\\begin{algorithmic}[1]\n\t\t\\Procedure{double\\_and\\_add}{$k, \\ Q$}\n\t\t\\State $R \\gets \\infty$\n\t\t\\For {$i\\gets 1,n$}\n\t\t\\If{$k_i = 1$}\n\t\t\\State $R \\gets Q + R$\n\t\t\\EndIf\n\t\t\\State $Q \\gets Q + Q$\n\t\t\\EndFor\n\t\t\\State \\textbf{return} $R$\n\t\t\\EndProcedure\n\t\\end{algorithmic}\n\\end{algorithm}\n\\noindent\nThe algorithm can be further sped up through the pre-computation of a vector of multiples of $Q$: this approach is not always feasible, since the point $Q$ is not always fixed\\footnote{The point $Q$ is fixed, for example, when computing the public key from a private key. For a thorough exposition of these concepts we refer to Chapter \\ref{chpr:ecc}.}.", "meta": {"hexsha": "aa3249a97d2fa6a889d437691deb3302fb3acc99", "size": 23624, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/Math_intro.tex", "max_stars_repo_name": "gionasoldati/thesis", "max_stars_repo_head_hexsha": "e8b3b3828f4ccb0a35e26381b361425e09a51b11", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/Math_intro.tex", "max_issues_repo_name": "gionasoldati/thesis", "max_issues_repo_head_hexsha": "e8b3b3828f4ccb0a35e26381b361425e09a51b11", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapters/Math_intro.tex", "max_forks_repo_name": "gionasoldati/thesis", "max_forks_repo_head_hexsha": "e8b3b3828f4ccb0a35e26381b361425e09a51b11", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-06T23:47:52.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-06T23:47:52.000Z", "avg_line_length": 97.6198347107, "max_line_length": 806, "alphanum_fraction": 0.7017016593, "num_tokens": 7552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7413608722329673}}
{"text": "\\section{2-Dimensional Diffusion}\n\n\nThe two dimensional diffusion equation is given as:\n\\begin{equation}\n  \\frac{\\partial u}{\\partial t} = v\\frac{\\partial^2 u}{\\partial x^2} + v\\frac{\\partial^2 u}{\\partial y^2}  \n\\end{equation}\n\nWe approximate this using a forward difference in time and a central difference in space:\n\\begin{equation}\n  \\frac{u^{n+1}_{i, j} - u^{n}_{i, j}}{\\Delta t} = \\nu\\frac{ u^{n}_{i, j-1} - 2  u^{n}_{i, j} +  u^{n}_{i, j+1}}{\\Delta x^2} + \\nu\\frac{ u^{n}_{i-1, j} - 2  u^{n}_{i, j} +  u^{n}_{i+1, j}}{\\Delta y^2}\n\\end{equation}\n\nRearranging to solve for $u^{n+1}_{i, j}$ yields:\n\\begin{equation}\nu^{n+1}_{i, j} = u^{n}_{i, j} + \\frac{\\nu\\Delta t}{\\Delta x^2}(u^{n}_{i, j-1} - 2  u^{n}_{i, j} +  u^{n}_{i, j+1}) + \\frac{\\nu\\Delta t}{\\Delta y^2}(u^{n}_{i-1, j} - 2  u^{n}_{i, j} +  u^{n}_{i+1, j})\n\\end{equation}\n", "meta": {"hexsha": "f3881831772b1263cce53bef089495ec9babf326", "size": 835, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tex/part2/diffusion_2d.tex", "max_stars_repo_name": "csrhau/cfd-primer", "max_stars_repo_head_hexsha": "4888e08579a2c43f519dd9b2c7fb905da1768b7c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/tex/part2/diffusion_2d.tex", "max_issues_repo_name": "csrhau/cfd-primer", "max_issues_repo_head_hexsha": "4888e08579a2c43f519dd9b2c7fb905da1768b7c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/tex/part2/diffusion_2d.tex", "max_forks_repo_name": "csrhau/cfd-primer", "max_forks_repo_head_hexsha": "4888e08579a2c43f519dd9b2c7fb905da1768b7c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.3888888889, "max_line_length": 200, "alphanum_fraction": 0.5796407186, "num_tokens": 370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109784205502, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7413138106309993}}
{"text": "\\section{$LU$ factorization}\n\nAn $LU$ factorization of a matrix involves writing the given matrix as the\nproduct of a lower triangular matrix $L$ which has the main diagonal consisting\nentirely of ones, and an upper triangular matrix $U$ in the indicated\norder. This is the version discussed here but it is sometimes the case that\nthe $L$ has numbers other than 1 down the main diagonal. It is still a\nuseful concept. The $L$ goes with ``lower'' and the $U$ with ``upper''.\n\nIt turns out many matrices can be written in this way and when this is\npossible, people get excited about slick ways of solving the system of\nequations, $AX=B$. It is for this reason that you want to study the\n$LU$ factorization. It allows you to work only with triangular\nmatrices. It turns out that it takes about half as many operations to\nobtain an $LU$ factorization as it does to find the {\\rref}.\n\nFirst it should be noted not all matrices have an $LU$ factorization and so\nwe will emphasize the techniques for achieving it rather than formal proofs.\n\\index{LU decomposition!non-existence}\n\\index{LU factorization}\n\n\\begin{example}{A matrix with NO $LU$ factorization}{}\nCan you write $\\begin{mymatrix}{rr}\n0 & 1 \\\\\n1 & 0\n\\end{mymatrix} $ in the form $LU$ as just described?\n\\end{example}\n\n\\begin{solution}\nTo do so you would need\n\\begin{equation*}\n\\begin{mymatrix}{rr}\n1 & 0 \\\\\nx & 1\n\\end{mymatrix} \\begin{mymatrix}{rr}\na & b \\\\\n0 & c\n\\end{mymatrix} =\\allowbreak \\begin{mymatrix}{cc}\na & b \\\\\nxa & xb+c\n\\end{mymatrix} =\\begin{mymatrix}{rr}\n0 & 1 \\\\\n1 & 0\n\\end{mymatrix} .\n\\end{equation*}\n\nTherefore, $b=1$ and $a=0$. Also, from the bottom rows, $xa=1$ which can't\nhappen and have $a=0$. Therefore, you can't write this matrix in the form $%\nLU$. It has no $LU$ factorization. This is what we mean above by saying the\nmethod lacks generality.\n\nNevertheless the method is often extremely useful, and we will describe\nbelow one the many methods used to produce an $LU$ factorization when\npossible.\n\\end{solution}\n", "meta": {"hexsha": "50490f14af6c1e6f82075763f479c32b0f2c7344", "size": 1993, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/matricesLUFactorization.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/matricesLUFactorization.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/matricesLUFactorization.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 35.5892857143, "max_line_length": 79, "alphanum_fraction": 0.7390868038, "num_tokens": 572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.8872045966995027, "lm_q1q2_score": 0.7412448418535348}}
{"text": "\\section{Task C}\n\\label{sec:task-c}\n\nThe equivalent internal forces are given as\n\\begin{equation} \\tag{9.15b}\n  \\label{eq:int-force}\n  \\ubar{\\bm{T}}_{a}^{(e)} = \\int_{v^{(e)}} \\utilde{\\sigma} \\cdot \\ubar{\\nabla} N_{a}\\, dv\n\\end{equation}\nFor a CST element of thickness \\(t\\) the same expression in local coordinates reads \n\\begin{equation}\n  \\label{eq:int-force-local}\n  \\ubar{\\bm{T}}_{a}^{(e)} = \\int \\int \\utilde{\\sigma} \\cdot \\ubar{\\nabla} N_{a} \\, t \n  \\, dx \\, dy =\n  \\int_{-1}^{1} \\int_{-1}^{1} \\utilde{\\sigma} \\cdot \\ubar{\\nabla} N_{a} \\, t \n  \\det \\left( \\frac{\\partial \\ubar{\\bm{x}}}{\\partial \\ubar{\\bm{\\xi}}} \\right) \\,\n  d\\xi \\, d\\eta\n\\end{equation}\nApply Gaussian quadrature rule to compute the integral numerically:\n\\begin{equation}\n  \\label{eq:int-force-numer}\n  \\ubar{\\bm{T}}_{a}^{(e)} \\approx\n  \\sum_{i=1}^{\\text{nip}} W_{i} \\utilde{\\sigma} \\cdot \\ubar{\\nabla} N_{a} \\, t \n  \\det \\left( \\frac{\\partial \\ubar{\\bm{x}}}{\\partial \\ubar{\\bm{\\xi}}} \\right),\n\\end{equation}\nwhere \\(W_{i}\\) is a weight for each of the integration points.\nFor a CST element, the number of integration points is 1 with coordinates\n\\(\\xi = 1/3\\), \\(\\eta = 1/3\\) and the weight \\(W = 0.5\\).\n\nThe Matlab implementation of this task can be found in \n\\texttt{get\\_intern\\_eq\\_forces.m} (see section \\ref{app:matlab-code}).\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../main\"\n%%% End:\n", "meta": {"hexsha": "78b01b8409cd47c81cf50337835cad04e421e7d1", "size": 1381, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/sec/task_c.tex", "max_stars_repo_name": "iamrosk/hyperelasticity", "max_stars_repo_head_hexsha": "b4f33e0c4f79473df47f29cce398b61e264f204b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-14T00:14:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-14T00:14:05.000Z", "max_issues_repo_path": "doc/sec/task_c.tex", "max_issues_repo_name": "iamrosk/hyperelasticity", "max_issues_repo_head_hexsha": "b4f33e0c4f79473df47f29cce398b61e264f204b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/sec/task_c.tex", "max_forks_repo_name": "iamrosk/hyperelasticity", "max_forks_repo_head_hexsha": "b4f33e0c4f79473df47f29cce398b61e264f204b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-14T03:19:55.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-14T03:19:55.000Z", "avg_line_length": 38.3611111111, "max_line_length": 89, "alphanum_fraction": 0.6350470673, "num_tokens": 508, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.741242192568653}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath, amssymb, bm}\n\\title{Sweet \\texttt{Cython} code for planet search finding}\n\\author{@\\texttt{dfm} \\& @\\texttt{mirca}}\n\n\\begin{document}\n\\maketitle\n\\section{Why period search algorithms are important?}\n\\subsection{Statistical assumptions}\nWe assume that $y_i \\sim \\mathcal{N}(m(t_i), \\sigma_i)$, $i=1, 2, ..., n$, where\n\\begin{equation}\nm(t_i) =\n\\left\\{\n    \\begin{array}{ll}\n        l, & \\text{if}~t_0 \\leq t_i \\leq t_0 + w ,\\\\\n        h, & \\text{otherwise}.\n    \\end{array}\n\\right.\n\\end{equation}\nsuch that $h>l$, in which $t_0$ is the transit time, $w$ is the transit duration,\n$h$ is the mean (not quite) flux level out-of-transit, $l$ is the mean (not quite)\nflux level in-transit.\n\nThen the log-likelihood function of $\\bm{y} \\triangleq (y_1, y_2, ..., y_n)$,\nassuming $y_i$'s are pair-wise idependent, can be written as\n\\begin{align}\n    \\log p(\\bm{y}| h, l) = -\\dfrac{1}{2}\\sum_{i=1}^{n}\\left(\\dfrac{y_i - m(t_i)}{\\sigma_i}\\right)^2,\n\\end{align}\nup to an additive constant.\n\nNote further that, the log-likelihood function can be expressed as\n\\begin{align}\n    \\log p(\\bm{y}| h, l) = -\\dfrac{1}{2}\\left[\\sum_{i \\in I}\\left(\\dfrac{y_i - l}{\\sigma_i}\\right)^2\n                              + \\sum_{i \\in I^{c}}\\left(\\dfrac{y_i - h}{\\sigma_i}\\right)^2\\right],\n\\end{align}\nin which $I\\triangleq\\left\\{i | t_0 \\leq t_i \\leq t_0 + w \\right\\}$ and $I^{c}$ denotes the complement of $I$.\n\nAnd the maximum likelihood estimator for $h$ and $l$, denoted as $h^{\\star}$ and $l^{\\star}$,\nrespectively, can be written as\n\\begin{equation}\n    l^{\\star}(\\bm{y}) = \\dfrac{\\displaystyle\\sum_{i \\in I}\\dfrac{y_i}{\\sigma^2_i}}{\\displaystyle\\sum_{i\\in I}\\dfrac{1}{\\sigma^2_i}},\n    ~~h^{\\star}(\\bm{y}) = \\dfrac{\\displaystyle\\sum_{i \\in I^{c}}\\dfrac{y_i}{\\sigma^2_i}}{\\displaystyle\\sum_{i\\in I^{c}}\\dfrac{1}{\\sigma^2_i}}.\n\\end{equation}\n\nNote that\n\\begin{align}\n    \\mathrm{var}\\left(l^{\\star}(\\bm{y})\\right) = \\dfrac{\\displaystyle\\sum_{i \\in I}\\dfrac{\\mathrm{var}(y_i)}{\\sigma^4_i}}\n    {\\displaystyle\\left(\\sum_{i\\in I}\\dfrac{1}{\\sigma^2_i}\\right)^{2}}\n    = \\displaystyle\\left(\\sum_{i\\in I}\\dfrac{1}{\\sigma^2_i}\\right)^{-1}\\\\\n    \\mathrm{var}\\left(h^{\\star}(\\bm{y})\\right) = \\dfrac{\\displaystyle\\sum_{i \\in I^c}\\dfrac{\\mathrm{var}(y_i)}{\\sigma^4_i}}\n    {\\displaystyle\\left(\\sum_{i\\in I^c}\\dfrac{1}{\\sigma^2_i}\\right)^{2}}\n    = \\displaystyle\\left(\\sum_{i\\in I^c}\\dfrac{1}{\\sigma^2_i}\\right)^{-1}\n\\end{align}\n\nThe maximum likelihood for the transit depth, denoted as $d^{\\star}$, can then be written as\n\\begin{equation}\n    d^{\\star}(\\bm{y}) = h^{\\star}(\\bm{y}) - l^{\\star}(\\bm{y}).\n\\end{equation}\n\nThen the variance on $d^{\\star}$ can be expressed as\n\\begin{align}\n    \\mathrm{var}\\left(d^{\\star}\\right) &= \\mathrm{var}\\left(h^{\\star}\\right) + \\mathrm{var}\\left(l^{\\star}\\right)\\\\\n    &= \\displaystyle\\left(\\sum_{i\\in I}\\dfrac{1}{\\sigma^2_i}\\right)^{-1}\n    + \\displaystyle\\left(\\sum_{i\\in I^c}\\dfrac{1}{\\sigma^2_i}\\right)^{-1}.\n\\end{align}\n\nThen the signal to noise ratio of the transit depth can be computed as\n\\begin{equation}\n    \\mathrm{SNR}_{d^{\\star}}= \\dfrac{d^{\\star}}{\\sqrt{\\displaystyle\\left(\\sum_{i\\in I}\\dfrac{1}{\\sigma^2_i}\\right)^{-1}\n                                            + \\displaystyle\\left(\\sum_{i\\in I^c}\\dfrac{1}{\\sigma^2_i}\\right)^{-1}}}.\n\\end{equation}\n\n\\end{document}\n\n", "meta": {"hexsha": "4c56ef47abe41411cc887b54a4e006d5c6d34faf", "size": 3330, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "blog-post/post.tex", "max_stars_repo_name": "mirca/transit-periodogram", "max_stars_repo_head_hexsha": "cd2d8c7ee3ba7ce857948c049ba951189e5af31b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-02-15T07:18:54.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-05T05:06:54.000Z", "max_issues_repo_path": "blog-post/post.tex", "max_issues_repo_name": "mirca/transit-periodogram", "max_issues_repo_head_hexsha": "cd2d8c7ee3ba7ce857948c049ba951189e5af31b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2018-02-13T15:19:49.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-23T14:12:32.000Z", "max_forks_repo_path": "blog-post/post.tex", "max_forks_repo_name": "mirca/transit-periodogram", "max_forks_repo_head_hexsha": "cd2d8c7ee3ba7ce857948c049ba951189e5af31b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.4, "max_line_length": 142, "alphanum_fraction": 0.6297297297, "num_tokens": 1270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7412225551988139}}
{"text": "% s,mask\n\n\\subsection{Masking}\n\nOne subtle point is that we usually display images\nas a rectangular grid of $\\ty{nx} \\times \\ty{ny}$ pixels,\nbut usually the iterative algorithms\nwork on column vectors.\nOften only a subset of the pixels are updated,\nas illustrated in\n\\fref{fig,reg,mask}.\nA logical array called the \\ty{mask}\nspecifies which pixels are to be updated.\nThe function call\n\\ty{x_col = x_array(mask(:))}\nextracts the relevant pixel elements\n``within the mask''\ninto a column vector.\nConversely, the call\n\\ty{x_array = embed(x_col, mask)}\nputs the elements of the column vector\nback into the appropriate places\nin the array.\n\n\\newcommand{\\fdir}{book/c-reg/fig}\n%\\infig{fig,reg,mask}{0.4}\n\n\\begin{figure}\n\\cent{\n\\input{\\fdir/fig,reg,mask,pic,6,5}\n}\n\\caption{\nA $6 \\times 5$\nimage lattice with approximately circular FOV. \nOnly the $\\np = 8$ pixels with indices shown are estimated.\n}\n\\label{fig,reg,mask}\n\\end{figure}\n\nThe following code illustrates these ideas.\n\n\\begin{verbatim}\nmask = false(6,5); mask([9 10 14:17 21 22]) = true;\nxc = [10:5:45]';\nxa = embed(xc, mask)\n\\end{verbatim}\n\n\\noindent\nHere is the resulting output.\n\n\\begin{verbatim}\n0     0     0     0     0\n0     0    20     0     0\n0    10    25    40     0\n0    15    30    45     0\n0     0    35     0     0\n0     0     0     0     0\n\\end{verbatim}\n\n\\noindent\nConversely,\ntyping the following\nproduces a vector that is the same as the original \\ty{xc} vector.\n\\begin{verbatim}\nxa(mask)\n\\end{verbatim}\n\nWhen first working on image reconstruction problems,\nit is quite tempting to disregard\nusing any such mask\nand try to reconstruct\nthe ``full'' image\nbecause it seems simpler.\nHowever,\nestimating more parameters than are needed\nto describe the object\nusually requires more computation time\nand often degrades the conditioning\nof the problem\nleading to slower convergence.\n", "meta": {"hexsha": "8c19ba562d5bae3745090dae48f287d66334f0e4", "size": 1849, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/s,mask.tex", "max_stars_repo_name": "tianrluo/mirt", "max_stars_repo_head_hexsha": "d2cd8d980a4a7a8ba7523850ed1c31d016f633df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 72, "max_stars_repo_stars_event_min_datetime": "2019-06-04T08:11:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-08T04:10:47.000Z", "max_issues_repo_path": "doc/s,mask.tex", "max_issues_repo_name": "tianrluo/mirt", "max_issues_repo_head_hexsha": "d2cd8d980a4a7a8ba7523850ed1c31d016f633df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-06-15T22:02:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-27T03:29:20.000Z", "max_forks_repo_path": "doc/s,mask.tex", "max_forks_repo_name": "tianrluo/mirt", "max_forks_repo_head_hexsha": "d2cd8d980a4a7a8ba7523850ed1c31d016f633df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2019-06-12T09:20:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T09:19:27.000Z", "avg_line_length": 22.8271604938, "max_line_length": 66, "alphanum_fraction": 0.7138994051, "num_tokens": 543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.8479677660619634, "lm_q1q2_score": 0.7411893176868418}}
{"text": "The grammar used in this section is the following:\n\n\\begin{align*} \n    &S \\to AB\\\\\n    &A \\to a\\\\\n    &B \\to BB|a|b\\\\\n\\end{align*}\n\nThis grammar matches every string that begins with an `a', no matter what comes next.\n\n\\subsubsection{Number of iterations/recusive calls for each parser}\n\nIt is very interesting because with this grammar the top-down algorithm never uses the stored values in its table, no matter the pattern used.\nAt first one could think that this is a very bad thing, indeed since the top-down without the table is exactly the same as the naive parser it means that using this grammar they will both have the same behaviour.\nBut what is interesting is that the naive parser with this grammar and a string of size $n$ reacts like so:\n$$\nrecursive \\text{ } calls = \n\\begin{cases}\n    2n - 1 &\\text{if string matches the grammar}\\\\\n    n &\\text{otherwise}\n\\end{cases}\n$$\n\nIt is very easy to demonstrate those two results:\n\\begin{enumerate}\n    \\item In every pattern that does start with an `a' the number of recursive calls is $2n - 1$ because:\n        \\begin{itemize}\n            \\item[$-$] The initial call is $parse(S, 0, n)$.\n            \\item[$-$] The function will the recursively call $parse(A, 0, 1)$, which will return true since the \\textit{terminal} `a' is equal to the character 0 of the string which is also `a'.\n            \\item[$-$] Then the function will call a second time $parse(B, 1, n)$.\n            \\item[$-$] That function will call $parse(B, 1, 2)$. That will return true no matter the character since `B' possesses both \\textit{terminals} `a' and `b'.\n            \\item[$-$] Then it will call $parse(B, 2, n)$. This will repeat itself until $parse(B, n - 1, n)$ is called. At that moment it will return true.\n            \\item[$-$] At that moment the number of recursive calls is $(n - 1) * 2$ plus the initial call $1$, for a total of $2n - 1$ recursive calls. Note that every 2 steps this algorithm goes 1 step deeper into the recursive stack, this is an important fact for the experimentations.\n        \\end{itemize}\n    \\item In every pattern that does not start with an `a' the number of recursive calls is the size of the string $n$ because:\n        \\begin{itemize}\n            \\item[$-$] The initial call is $parse(S, 0, n)$. That function will enter in a loop for k going from $1$ to $n - 1$.\n            \\item[$-$] The function will then recursively call $parse(A, 0, 1)$, which returns false since the \\textit{terminal} `a' is not equal to the character 0 of the string, which is `b'.\n            \\item[$-$] Then the function will call $parse(A, 0, k)$ until the end of the for loop. The calls will return false each time since `A' does not possess any \\textit{non-terminals} rules.\n            \\item[$-$] So there is $1$ call plus $n - 1$ calls made by the first called function, for a total of $n$ recursive calls. Note that all the sub calls are made by the first called function, which limits the maximum reached recursive depth to only 2, it will be interesting to see in the experimentations how that has a very important impact.\n        \\end{itemize}\n\\end{enumerate}\n\nWith a behaviour like this one the naive parser is very efficient with that grammar.\nAlso in this section only the naive parser and both bottom-up parsers will be considered, since the naive and top-down one are the same.\n\nWith this grammar the best and worst case scenarios for the `string' bottom-up parser are:\n\\begin{itemize}\n    \\item[$-$] The worst case is a string following this pattern: `$b\\string^ n$'.\n    \\item[$-$] The best case is a string following this pattern: `$a\\string^ n$'.\n    \\item[$-$] Every case that is a mix between `a's and `b's will have a running time situated between the best and worst case.\n        The more `b's there is in the string the closer the running time will be from the worst case and conversely with `a's.\n\\end{itemize}\n\nIt is now poosible to compare the anticipated behaviours of the `boolean' bottom-up and the naive parser, in both cases, using the function \\ref{eq:bottom-up_iterations} and the two expressions from above.\n\n\\FloatBarrier\n\\begin{figure}[h]\n\\begin{tikzpicture}\n\\begin{groupplot}[group style={group size=2 by 1},height=0.5\\textwidth,width=0.5\\textwidth, domain=0:1000]\n\\nextgroupplot[title=`Boolean' bottom-up, xlabel=string size, ylabel=iterations]\n\\addplot[red]{3 * x + ((2 / 6) * ((3 * (x^2) * (x + 1)) - (x * (x + 1) * ((2 * x) + 1))))};\n\\nextgroupplot[title=Naive, legend pos=north west,xlabel=string size, ylabel=recusive calls]\n\\addplot[green]{2 * x - 1};\n\\addlegendentry{Case 1}\n\\addplot[blue]{x};\n\\addlegendentry{Case 2}\n\\end{groupplot}\n\\end{tikzpicture}\n\\caption{Anticipation of the behaviours of the parsers, grammar 2}\n\\end{figure}\n\\FloatBarrier\n\nSince the number of recursive calls of the naive parser with that grammar is linear it should be very effective compared to the `boolean' bottom-up one.\nThe naive parser should also be more effective than the `string' bottom-up parser since this one also follows a power function.\n\n\\subsubsection{Comparing the efficiency}\n\nWith that grammar there is only two cases to compare, the case in which the string matches the grammar and the case when it doesn't, except for the `string' bottom-up which has a behaviour depending on the pattern but for which those two patterns are the extrem cases.\n\nThe first used pattern is a case in which the strings match the grammar: `$a\\string^ n$'.\n\n\\FloatBarrier\n\\begin{figure}[h]\n\\begin{tikzpicture}\n    \\begin{groupplot}[group style={group size=2 by 2},height=0.5\\textwidth,width=0.5\\textwidth] \n    \\nextgroupplot[title=Both bottom-up counters, ylabel=iterations, legend pos = north west]\n    \\addplot coordinates {\n        (50, 187575)\n        (100, 1500150)\n        (200, 12000300)\n        (400, 96000600)\n        (600, 324000900)\n        (800, 768001200)\n        (1000, 1500001500)};\n    \\addlegendentry{String}\n    \\addplot coordinates {\n        (50, 41800)\n        (100, 333600)\n        (200, 2667200)\n        (400, 21334400)\n        (600, 72001600)\n        (800, 170668800)\n        (1000, 333336000)};\n    \\addlegendentry{Boolean}\n    \\nextgroupplot[title=Both bottom-up running time, legend pos = north west, ylabel=seconds]\n    \\addplot coordinates {\n        (50, 0.011391)\n        (100, 0.08719)\n        (200, 0.668587)\n        (400, 5.41536)\n        (600, 17.6169)\n        (800, 41.9493)\n        (1000, 82.579)};\n    \\addlegendentry{String}\n    \\addplot coordinates {\n        (50, 0.001673)\n        (100, 0.011914)\n        (200, 0.101755)\n        (400, 0.816538)\n        (600, 3.0517)\n        (800, 8.58051)\n        (1000, 18.6903)};\n    \\addlegendentry{Boolean}\n    \\nextgroupplot[title=Naive counter, xlabel=string size, ylabel=recursive calls]\n    \\addplot coordinates {\n        (50000, 99999)\n        (100000, 199999)\n        (200000, 399999)\n        (300000, 599999)\n        (400000, 799999)};\n    \\nextgroupplot[title=Naive running time, xlabel=string size, ylabel=seconds]\n    \\addplot coordinates {\n        (50000, 0.001854)\n        (100000, 0.002961)\n        (200000, 0.005776)\n        (300000, 0.007833)\n        (400000, 0.010237)};\n    \\end{groupplot}\n\\end{tikzpicture}\n\\caption{Both bottom-up and naive parsers behaviours, grammar 2, case 1}\n\\end{figure}\n\\FloatBarrier\n\nThe running time of the naive parser compared to the two bottom-up ones with this grammar is so small that it is needed to use different string sizes in order to get relevant results.\n\nWith this grammar and that case the `boolean' bottom-up parser is faster than the `string' version.\n\nA limitation of the top-down parser is that it needs to allocate memory for its table, but with strings of the size that are used in this experimentation it is not possible to allocate the memory.\nSo even if the behaviour is theoricaly exactly the same as with the naive parser in practice with a classic computer it is not possible to parse strings that long with the top-down parser.\n\nThe running time of the naive parser is linear, which makes sense since its number of recursive calls is linear too.\n\nAn interesting thing is that even if the running time of the naive parser remains very small with big string sizes the maximum size of the recursive stack was reached for strings bigger than 410000 characters.\nThis can be explained by the fact that when the string size $n$ increases the algorithm goes deeper and deeper in the stack: 1 more level of depth every 2 recursive calls.\nThis is not an issue that we will be able to see with a pattern that does not starts with a `b', indeed in that case as explained in section 3.2.2.1, case 2, the maximum recursive depth accessed is 2, which will allow the parser to parse longer strings.\n\nThe second used pattern is a case in which the strings do not match the grammar: `$b\\string^ n$'.\n\n\\FloatBarrier\n\\begin{figure}[h]\n\\begin{tikzpicture}\n    \\begin{groupplot}[group style={group size=2 by 2},height=0.5\\textwidth,width=0.5\\textwidth] \n    \\nextgroupplot[title=Both bottom-up counters, ylabel=iterations, legend pos = north west]\n    \\addplot coordinates {\n        (50, 62625)\n        (100, 500250)\n        (200, 4000500)\n        (400, 32001000)\n        (600, 108001500)\n        (800, 256002000)\n        (1000, 500002500)};\n    \\addlegendentry{String}\n    \\addplot coordinates {\n        (50, 41800)\n        (100, 333600)\n        (200, 2667200)\n        (400, 21334400)\n        (600, 72001600)\n        (800, 170668800)\n        (1000, 333336000)};\n    \\addlegendentry{Boolean}\n    \\nextgroupplot[title=Both bottom-up running times, legend pos = north west, ylabel=seconds]\n    \\addplot coordinates {\n        (50, 0.005147)\n        (100, 0.043097)\n        (200, 0.329631)\n        (400, 2.56894)\n        (600, 8.39397)\n        (800, 20.0372)\n        (1000, 39.8311)};\n    \\addlegendentry{String}\n    \\addplot coordinates {\n        (50, 0.001673)\n        (100, 0.011914)\n        (200, 0.101755)\n        (400, 0.816538)\n        (600, 3.0517)\n        (800, 8.58051)\n        (1000, 18.6903)};\n    \\addlegendentry{Boolean}\n    \\nextgroupplot[title=Naive counter, xlabel=string size, ylabel=recursive calls]\n    \\addplot coordinates {\n        (50000000, 50000000)\n        (100000000, 100000000)\n        (200000000, 200000000)\n        (300000000, 300000000)\n        (400000000, 400000000)\n        (500000000, 500000000)\n        (600000000, 600000000)};\n    \\nextgroupplot[title=Naive running time, xlabel=string size, ylabel=seconds]\n    \\addplot coordinates {\n        (50000000, 0.262654)\n        (100000000, 0.524298)\n        (200000000, 1.05584)\n        (300000000, 1.56371)\n        (400000000, 2.08152)\n        (500000000, 2.61476)\n        (600000000, 3.13239)};\n    \\end{groupplot}\n\\end{tikzpicture}\n\\caption{Both bottom-up and naive parsers behaviour, grammar 2, case 2}\n\\end{figure}\n\\FloatBarrier\n\nThe curves of the `boolean' are the same as with the last case since no matter the pattern used that parser will always have the same behaviour with that grammar.\nThis case is the best case for the `string' bottom-up parser and the running time is indeed lower than with the first case, however it still takes more time than the `boolean' version.\n\nWith that case it was possible to parse a word of 600 millions character in about 3 seconds with the naive parser, which is very impressive.\nThe parser was maybe able to parse the word in some seconds but the longest part was in fact the time to generate the string and also the time to pass such string in parameter to some functions.\nThe running time is once again linear as expected.\n\\\\\n\\\\\nWith both the best and the worst case scenarios for the `string' bottom-up parser it is possible to display the area between the two curves.\nThe running time of that parser will always be contained in the blue area and the more `$b$'s there is in the given string the more the running time will follow a close curve from the worst case and conversely.\n\n\\FloatBarrier\n\\begin{figure}[h]\n    \\centering\n    \\begin{tikzpicture}\n        \\begin{axis}[title=`String' bottom-up running times, ylabel=seconds, xlabel=string size, legend pos = north west]\n        \\addplot[mark=*, green, name path=plot1] coordinates {\n        (50, 0.005147)\n        (100, 0.043097)\n        (200, 0.329631)\n        (400, 2.56894)\n        (600, 8.39397)\n        (800, 20.0372)\n        (1000, 39.8311)};\n        \\addlegendentry{Best case}\n        \\addplot[mark=*, red, name path=plot2] coordinates {\n        (50, 0.011391)\n        (100, 0.08719)\n        (200, 0.668587)\n        (400, 5.41536)\n        (600, 17.6169)\n        (800, 41.9493)\n        (1000, 82.579)};\n        \\addlegendentry{Worst case}\n        \\addplot[blue!30] fill between[of=plot1 and plot2];\n        \\addlegendentry{All cases}\n        \\end{axis}\n    \\end{tikzpicture}\n    \\caption{Running time of the `string' bottom-up parser, grammar 3}\n\\end{figure}\n\\FloatBarrier\n", "meta": {"hexsha": "648733bb1aded3b931d8c6039e7a055108a4c57a", "size": 12861, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/grammar_2.tex", "max_stars_repo_name": "ThomasRanvier/cyk_algorithm_analysis", "max_stars_repo_head_hexsha": "f6d7fbf95533461b58b0a9937530f1e4d8bc2e29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/sections/grammar_2.tex", "max_issues_repo_name": "ThomasRanvier/cyk_algorithm_analysis", "max_issues_repo_head_hexsha": "f6d7fbf95533461b58b0a9937530f1e4d8bc2e29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/sections/grammar_2.tex", "max_forks_repo_name": "ThomasRanvier/cyk_algorithm_analysis", "max_forks_repo_head_hexsha": "f6d7fbf95533461b58b0a9937530f1e4d8bc2e29", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-13T17:38:35.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-13T17:38:35.000Z", "avg_line_length": 48.1685393258, "max_line_length": 352, "alphanum_fraction": 0.6796516601, "num_tokens": 3630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8824278556326344, "lm_q1q2_score": 0.741004644394898}}
{"text": "\\paragraph{Range} is very prone to outliers.\n$ R = \\max(X) - \\min(X) $\n\n\\paragraph{Interquantile range}\n$ IQR = Q_3 - Q_1 $\n\n\\paragraph{Variance} \\hspace{0pt}\n\n\\vspace{-30pt}\n\\begin{gather*}\n\\var X = s^2 = \\frac{1}{n-1}\\sum_{i=1}^n \\left( X_i - \\mean \\right)^2\n\\end{gather*}\n\n\\paragraph{Standard deviation}\n$s = \\sqrt{s^2} = \\sqrt{Var}$\n\n\\paragraph{Coefficient of variation} \\hspace{0pt}\n\n\\vspace{-20pt}\n\\begin{gather*}\ncv = \\frac{s}{\\mean}\n\\end{gather*}\n\n\\paragraph{Median absolute deviation} \\hspace{0pt}\n\n\\vspace{-20pt}\n\\begin{gather*}\n\\mad = \\med \\left( |X_1 - \\med_X|, \\ldots, |X_n - \\med_X| \\right)\n\\end{gather*}\n\n\\vspace{-10pt} %\\noindent\nwhere $\\med_X$ is the sample median.\n", "meta": {"hexsha": "0c628c2b3ea78245c36684123b12528aaef6466e", "size": 683, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_2d_measures_dispersion.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_stars_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs_2d_measures_dispersion.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_issues_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs_2d_measures_dispersion.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_forks_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.696969697, "max_line_length": 69, "alphanum_fraction": 0.6530014641, "num_tokens": 261, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750453562491, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7409805653345839}}
{"text": "\\section{Exercises in Discrete Random Variables}\\label{S:xsDiscreteRVs}\n\\begin{ExerciseList}\n\\Exercise[label={xRV1}]\nOne number in the following table for the probability function of a random variable $X$ is incorrect.  \nWhich is it, and what should the correct value be?\n$$\n\\begin{array}{c|ccccc}\nx&1&2&3&4&5\\\\\\hline\n\\P(X=x)&0.07&0.10&1.10&0.32&0.40\n\\end{array}\n$$\n\\Answer\n$\\P(X=3)$ does not satisfy the condition that $0\\leq \\P(A)\\leq1$ for any event $A$.  \nIf $\\Omega$ is the sample space, then $\\P(\\Omega)=1$ and so  the correct probability is \n\\[\n\\P(X=3)\\;=\\;1-0.07-0.10-0.32-0.40\\;=\\;0.11 \\enspace .\n\\]\n\n\\Exercise\nLet $X$ be the number of years before a particular type of machine will need replacement.  \nAssume that $X$ has the probability function $f(1)=0.1$, $f(2)=0.2$, $f(3)=0.2$, $f(4)=0.2$, $f(5)=0.3$.\n\\be\n\\item Find the distribution\n  function, $F$,  for $X$, and graph both $f$ and $F$.\n\n\\item  Find the probability that the machine needs to be\n  replaced during the first 3 years.\n\n\\item  Find the probability that the machine needs no\n  replacement during the first 3 years.\n\\ee\n\\Answer\n\\be\n\\item  Tabulate the values for the probability mass function  as follows: $$\n\\begin{array}{c|ccccc}\nx&1&2&3&4&5\\\\\\hline\n\\P(X=x)&0.1&0.2&0.2&0.2&0.3\n\\end{array}\n$$so the  distribution function is:\n\\[F(x)\\; = \\;\\P(X \\leq x) \\;=\\;\n\\begin{cases}\n 0 & \\text{ if }  0 \\leq   x < 1\\\\\n 0.1 & \\text{ if } 1 \\leq  x < 2\\\\\n0.3 & \\text{ if } 2 \\leq x < 3\\\\\n 0.5 & \\text{ if } 3 \\leq x < 4\\\\\n0.7 & \\text{ if }  4 \\leq x < 5\\\\\n 1& \\text{ if }    x \\geq 5\n\\end{cases}\n\\]\n\n%The graphs of $f(x)$ and $F(x)$ for random variable $X$ are shown below:\n\n%TODO\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/fandFfor5YearMachine.png}}\n\n\n\n\\item The probability that the machine needs to be replaced during the\n  first 3 years is:\n$$\\P(X \\leq  3)\\;=\\;\\P(X=1)+\\P(X=2)+\\P(X=3)\\;=\\;0.1+0.2+0.2\\;=\\;0.5\\,.$$\n(This answer is easily seen  from the distribution function of $X$.)\n\\item The probability that the machine needs no replacement during the\nfirst three years is\n\\[ \\P(X >  3)\\;=\\;\\, 1-\\P(X \\leq  3)\\,=\\, 0.5 \\,.\\]\n\\ee\n\n\\Exercise\nOf 200 adults, 176 own one TV set, 22 own two TV sets, and 2 own three TV sets.  \nA person is chosen at random. What is the probability mass function of $X$,  the number of TV sets owned by that person?\n\\Answer\nAssuming that the probability model is being built from the observed relative frequencies, the probability mass function is:\n$$\nf(x)\\;=\\;\\begin{cases}\\frac{176}{200}&x=1\\\\\\frac{22}{200}&x=2\\\\\\frac{2}{200}&x=3\\end{cases}$$\n\n\\Exercise\nSuppose a discrete random variable $X$ has probability function give by\n$$\\begin{array}{c|cccccccccccc}\nx&3&4&5&6&7&8&9&10&11&12&13\\\\\\hline\n \\P(X=x)&0.07&0.01&0.09&0.01&0.16&0.25&0.20&0.03&0.02&0.11&0.05\n\\end{array}\n$$\n\\be\n\\item[(a)] Construct a row of cumulative probabilities for this table, that\n  is, find the distribution function of $X$.\n\\item[(b)] Find  the following  probabilities.\n\\bcols{3}\n\\be\n\\item[(i)]$\\P(X\\leq 5)$\n\\item[(ii)] $\\P(X<12)$\n\\item[(iii)] $\\P(X>9)$\n\\item[(iv)] $\\P(X\\geq 9)$\n\\item[(v)] $\\P(4 <  X\\leq 9)$\n\\item[(vi)] $\\P(4<X<11)$\n\\ee\n\\ecols\n\\ee\n\n\\Answer\n\\begin{itemize}\n\\item[(a)]  $$\\begin{array}{c|cccccccccccc}\nx&3&4&5&6&7&8&9&10&11&12&13\\\\\\hline\nF(x) =\\P(X\\leq x)&0.07&0.08&0.17&0.18&0.34&0.59&0.79&0.82&0.84&0.95&1.00\n\\end{array}\n$$\n\n\\medskip\n\\item[(b)]\n\\be\n\\item[(i)]$\\P(X\\leq 5)= F(5) = 0.17$ \\\\[3pt]\n\\item[(ii)]$\\P(X<12)=\\P(X\\leq11) = F(11) =0.84$\\\\[3pt]\n\\item[(iii)] $\\P(X>9)= 1 - \\P(X\\leq 9) = 1- F(9) =1-0.79=0.21$ \\\\[3pt]\n\\item[(iv)] $\\P(X\\geq 9)=1-\\P(X <  9)=1-\\P(X\\leq 8)=1-0.59=0.41$ \\\\[3pt]\n\\item[(v)] $\\P(4 <  X\\leq 9)= F(9) - F(4) =0.79-0.08=0.71$ \\\\[3pt]\n\\item[(vi)] $\\P(4<X<11)=\\P(4 <  X\\leq 10)= F(10) -F(4) =0.82- 0.08=0.74$ \\\\[3pt]\n\\ee\n\\end{itemize}\n\n\n\\Exercise\nA box contains 4 right-handed and 6 left-handed screws.  \nTwo screws are drawn at random without replacement. Let $X$ be the number of left-handed screws drawn.  \nFind the probability mass function for $X$, and then calculate  the following probabilities:\n\\be\n\\item $\\P(X\\leq 1)$\n\\item $\\P(X\\geq 1)$\n\\item $\\P(X>1)$\n\\ee\n\\Answer\nSince  we are sampling without replacement,\n\\begin{eqnarray*}\n\\P(X=0) &=& \\frac{4}{10}\\cdot\\frac{3}{9} = \\frac{2}{15}\\quad (\\text{one way of drawing two right screws}), \\\\\n\\P(X=1) &=& \\frac{6}{10}\\cdot\\frac{4}{9}+\\frac{4}{10}\\cdot\\frac{6}{9} = \\frac{8}{15}\\quad(\\text{two ways of drawing one left and one  right screw}),\\\\\n\\P(X=2) &=& \\frac{6}{10}\\cdot\\frac{5}{9} = \\frac{1}{3}\\quad(\\text{one way of drawing two left screws}).\n\\end{eqnarray*}\nSo the probability mass function of $X$ is:\n\\[f(x)\\;=\\;\\P(X=x)\\;=\\;\n\\begin{cases}\n\\frac{2}{15}  & \\text{if } x=0\\\\[3pt]\n\\frac{8}{15} & \\text{if } x=1\\\\[3pt]\n\\frac{1}{3}  & \\text{if } x=2\n\\end{cases}\\]\n\nThe required probabilities are:\n\\be\n\\item\n$$\\P(X\\leq1)\\;=\\;\\P(X=0)+\\P(X=1)\\;=\\;\\frac{2}{15}+\\frac{8}{15}\\;=\\;\\frac{2}{3}$$\n\\item\n$$\\P(X\\geq 1)\\;=\\;\\P(X=1)+\\P(X=2)\\;=\\;\\frac{8}{15}+\\frac{1}{3}\\;=\\;\\frac{13}{15}$$\n\\item\n$$\\P(X>1)\\;=\\;\\P(X=2)\\;=\\;\\frac{1}{3}$$\n\\ee\n\n\n\\Exercise\nSuppose that  a random variable $X$ has geometric  probability mass function,\n  \\[f(x)\\;=\\;\\frac{k}{2^x}\\quad (x=0,1,2,\\dots)\\,.\\]\n\\be\n\\item Find the value of  $k$.\n\\item  What is  $\\P(X\\geq 4)$?\n\\ee\n\\Answer\n\\be\n\\item\nSince $f$ is a probability mass function,  $$\\sum_{x=0}^\\infty\\frac{k}{2^x}\\;=\\;1\\,, \n\\qquad \\text{that is,}\\qquad k\\,\\sum_{x=0}^\\infty\\frac{1}{2^x}\\;=\\;1\\ \\enspace.$$\nNow $\\displaystyle \\sum_{x=0}^\\infty\\frac{1}{2^x}$ is a geometric series with common ratio $r= \\frac{1}{2}$ and first term $a=1$,\nand so has  sum\n\\[ S\\;=\\; \\frac{a}{1-r} \\;=\\;\\frac{1}{1-\\frac{1}{2} } \\;=\\; 2\\]\nTherefore, \\[  2 k\\;=\\; 1 \\,, \\quad \\text{that\n  is,}\\quad k\\;=\\; \\frac{1}{2}\\,.\\]\n\n\\item From (a), the probability mass function of $f$ is\n  $$f(x)\\;=\\;\\frac{\\frac{1}{2}}{2^{x}}\\;=\\;\\frac{1}{2^{x+1}}\\,.\\quad\n  (x=0,1,2,\\dots)$$ Now\n\\[\\P(X\\geq 4)\\;=\\;1-\\P(X<4)\\;=\\;1-\\P(X\\leq3)\\] where\n\\ba{\\P(X\\leq3)&=\\;\\sum^3_{x=0}\\frac{1}{2^{x+1}}\\\\[3pt]\n&=\\;\\frac{1}{2}+\\frac{1}{4}+\\frac{1}{8}+\\frac{1}{16}\\\\[3pt]\n&=\\;\\frac{8}{16}+\\frac{4}{16}+\\frac{2}{16}+\\frac{1}{16}\\\\[3pt]\n&=\\;\\frac{15}{16}\\enspace.\n}\nThat is,  $\\P(X\\geq4)\\,=\\,\\displaystyle \\frac{1}{16}$.\n\\ee\n\n\\Exercise\nFour fair coins are tossed simultaneously.  \nIf we count the number of heads that appear then we have a  binomial random variable,  $X=$ {\\it the number of heads}.\n\\be\n\\item Find the probability mass\n  function of  $X$.\n\\item  Compute the probabilities of obtaining no heads, precisely 1\n  head, at least 1 head, not more than 3 heads.\n\\ee\n\\Answer\nNote that  $\\theta=\\frac{1}{2}$ here.\n\\be\n\\item $X$ has probability mass function\n\\[f(x)\\;=\\;\\begin{cases}\n\\displaystyle\\displaystyle \\binom{4}{0}\\frac{1}{2}^0\\frac{1}{2}^4=\\frac{1}{16}&x=0\\\\[16pt]\n\\displaystyle\\displaystyle\\binom{4}{1}\\frac{1}{2}^1\\frac{1}{2}^3=\\frac{4}{16}&x=1\\\\[16pt]\n\\displaystyle\\displaystyle\\binom{4}{2}\\frac{1}{2}^2\\frac{1}{2}^2=\\frac{6}{16}&x=2\\\\[16pt]\n\\displaystyle\\binom{4}{3}\\frac{1}{2}^3\\frac{1}{2}^1=\\frac{4}{16}&x=3\\\\[16pt]\n\\displaystyle\\binom{4}{4}\\frac{1}{2}^4\\frac{1}{2}^0=\\frac{1}{16}&x=4\n\\displaystyle\\end{cases}\n\\]\n\n\\item The required probabilities are:\n\n$\\displaystyle \\P(X=0)=f(0)=\\frac{1}{16}$\\\\[3pt]\n$\\displaystyle \\P(X=1)=f(1)=\\frac{4}{16}$\\\\[3pt]\n$\\displaystyle \\P(X\\geq1)=1-\\P(X=0)=1-f(0)=\\frac{15}{16}$\\\\[3pt]\n$\\displaystyle \\P(X\\leq3)=f(0)+f(1)+f(2)+f(3)=\\frac{15}{16}$\n\\ee\n\n\\Exercise\nThe distribution of blood types in a certain  population is as follows:\n$$\n\\begin{array}{c|cccc}\n\\text{Blood type}&\\text{Type } O&\\text{Type } A&\\text{Type } B& \\text{Type }AB\\\\\\hline\n\\text{Proportion}&0.45&0.40&0.10&0.05\n\\end{array}\n$$\nA random sample of 15 blood donors is observed from this\npopulation. Find the probabilities of the following events.\n\n\\be\n\\item Only one type $AB$ donor is included.\n\\item At least three of the donors are type $B$.\n\\item More than ten of the donors are \\emph{either} type $O$ \\emph{or} type $A$.\n\\item Fewer that five of the donors are \\emph{not} type $A$.\n\\ee\n\\Answer\n\\be\n\\item  If the random variable $X$ denotes the number of type $AB$ blood donors\n  in the sample of 15, then $X$ has a binomial distribution with $n=15$\n  and $\\theta=0.05$.  Therefore\n\\[\\P(X=1) \\;=\\;\\binom{15}{1} (0.05)^1  (0.95)^{14}\\;=\\;0.366 \\quad (\\text{3 sig. fig.}) \\,.\\]\n\n\\medskip\n\\item  If the random variable $X$ denotes the number of type $B$  blood donors\n  in the sample of 15, then $X$ has a binomial distribution with $n=15$\n  and $\\theta=0.10$.  Therefore\n\\ba{\\P(X\\geq 3) &\\;=\\;  1\\, - \\,\\P(X=0)\\, -\\, \\P(X=1)\\, -\\, \\P(X=2) \\\\[3pt]\n &\\;=\\;  1\\; - \\; \\binom{15}{0} (0.1)^0  (0.9)^{15}\\;-\\; \\binom{15}{1}\n (0.1)^1  (0.9)^{14}\\;-\\; \\binom{15}{2} (0.1)^2  (0.9)^{13}\\\\[3pt]\n&\\;=\\;  1\\,-\\, 0.2059 \\,-\\, 0.3432 \\,-\\, 0.2669\\\\[3pt]\n&\\;=  \\;0.184 \\quad (\\text{to 3 sig. fig.})\n}\n\n\\medskip\n\\item If the random variable $X$ denotes the number of type  $O$ or type $A$ blood donors\n  in the sample of 15, then $X$ has a binomial distribution with $n=15$\n  and $\\theta=0.85$.  Therefore\n\\ba{\\P(X > 10 ) &\\;=\\;  \\P(X=11)\\, + \\, \\P(X=12)\\, +\\,  \\P(X=13) \\, + \\, \\P(X=14)\\, + \\, \\P(X=15)  \\\\[3pt]\n &\\;=\\;   \\binom{15}{11} (0.85)^{11}  (0.15)^{4}\\;+\\; \\binom{15}{12}\n (0.85)^{12}  (0.15)^{3}\\\\[3pt]\n&\\;+\\; \\binom{15}{13} (0.85)^{13}  (0.15)^{2}\\;+\\; \\binom{15}{14} (0.85)^{14}  (0.15)^{1}\\;+\\; \\binom{15}{15} (0.85)^{15}  (0.15)^{0}\\\\[3pt]\n&\\;=\\;  0.1156 \\,+\\,0.2184 \\,+\\,0.2856 \\,+\\, 0.2312\\,+\\,0.0874\\\\[3pt]\n&\\;=\\;0.938 \\quad (\\text{to 3 sig. fig.})\n}\n\n\\medskip\n\\item If the random variable $X$ denotes the number of blood donors that\n  are \\emph{not} of type $A$ blood donors\n  in the sample of 15, then $X$ has a binomial distribution with $n=15$\n  and $\\theta=0.6$.  Therefore\n\\ba{\\P(X <  5) &\\;=\\;  \\P(X=0)\\, +\\, \\P(X=1)\\, + \\, \\P(X=2)\\, + \\, \\P(X=3)\\, + \\, \\P(X=4) \\\\[3pt]\n &\\;=\\;   \\binom{15}{0} (0.6)^0  (0.4)^{15}\\;+\\; \\binom{15}{1}\n (0.6)^1  (0.4)^{14}\\;+\\; \\binom{15}{2} (0.6)^2  (0.4)^{13}\\\\[3pt]\n&\\;+\\; \\binom{15}{3} (0.6)^3  (0.4)^{12}\\;+\\; \\binom{15}{4} (0.6)^4  (0.4)^{11}\\\\[3pt]\n&\\;=\\;  0.0000 \\,+\\,  0.0000\\,+\\, 0.0003\\,+\\, 0.0016\\,+\\,0.0074\\\\[3pt]\n&\\;=\\;0.009 \\quad (\\text{to 3 DP.})\n}\n\\ee\n\n\n\n\\Exercise\nIf the probability of hitting a target in a single shot is $10\\%$ and 10 shots are fired independently, what is the probability that the target will be hit at least once?\n\\Answer\nThis is a Binomial experiment with parameters $\\theta=0.1$ and $n=10$, and so \n\\[\\P(X\\geq 1) = 1-\\P(X<1) = 1-\\P(X=0) \\enspace ,\\] \nwhere\n\\[\\P(X=0) = \\binom{10}{0}0.1^0 0.9^{10} \\approxeq 0.3487 \\enspace .\\]\n\n Therefore, the probability that the target will be hit at least once is\n \\[1- 0.3487 \\approxeq 0.6513 \\enspace .\\]\n\n%question  (poisson)\n\\Exercise \nSuppose that a certain type of magnetic tape contains, on the average, 2 defects per 100 meters.  \nWhat is the probability that a roll of tape 300 meters long will contain  no defects?\n\\Answer\nSince 2 defects exist on every 100 meters, we would expect 6 defects on a 300 meter tape.  \nIf $X$ is the number of defects on a 300 meter tape, then $X$ is Poisson with $\\lambda = 6$ and so the probability of zero defects is\n$$\\P(X=0;6)\\;=\\;\\frac{6^0}{0!}e^{-6}\\;=\\;0.0025\\enspace.$$\n\n%question  (poisson)\n\\Exercise\nIn 1910, E.~Rutherford and H.~Geiger showed experimentally that the number of alpha particles emitted per second in a radioactive process is a random variable $X$ having a Poisson distribution. If the average number of particles emitted per second is  0.5, what is the probability of observing two or more particles during any given second?\n\\Answer\nSince $X$ is $\\poisson(\\lambda)$ random variable with $\\lambda=0.5$, $\\P(X\\geq2)$ \nis the probability of observing two or more particles during any\ngiven second. $$\\P(X\\geq 2)\\;=\\;1-\\P(X<2)\\;=\\;1-\\P(X=1)-\\P(X=0)\\enspace,$$\nwhere $\\P(X=1)$ and $\\P(X=0)$ can be carried out by the Poisson\nprobability mass function $$\\P(X=x)\\;=\\; f(x)\\;=\\;\\frac{\\lambda^x}{x!}e^{-\\lambda}\\enspace.$$\nNow \\[\\P(X=0)\\;=\\;\\frac{0.5^0}{0!}\\,\\times \\,e^{-0.5} \\;=\\; 0.6065\\] and\n\\[ \\P(X=1)\\;=\\;\\frac{0.5^1}{1!}\\,\\times \\, e^{-0.5}\\;=\\; 0.3033\\] and so\n$$\\P(X\\geq 2)\\;=\\; 1- 0.9098\\;= \\;0.0902\\enspace.$$\n\n%question  (poisson)\n\\Exercise \nThe number of lacunae (surface pits) on specimens of steel, polished and examined in a metallurgical laboratory, is thought to have a Poisson distribution.\n\\be\n\\item Write down the formula for the probability that a specimen has $x$\n  defects, explaining the meanings of the symbols you use.\n\\item Simplify the formula in the case $x=0$.\n\\item In a large homogeneous collection of specimens, 10\\% have one or more lacunae. Find (approximately) the percentage having exactly two.\n\\item Why might the Poisson distribution not apply in this situation?\\\\[4pt]\n[{\\scriptsize HINT: Recall the {\\em emphasised sentence} in THINKING POISSON and what the continuum on which the number of events occur is for the problem, and what could possibly go wrong in your imagination of the manufacturing process of the steel specimens (normally you need to melt and manipulate iron with other elements and cast them in moulds and this needs energy and raw materials of possibly varying quality and the machines used in the process could break down, etc.) to violate the Poisson assumption about the occurrence of pits on the surface of the specimens.}]\n\\ee\n\\Answer\n\\be\n\\item The Probability mass function for $\\poisson(\\lambda)$ random variable $X$ is \n\\[\\P(X=x)\\;=\\;f(x;\\lambda)\\;=\\; \\frac{e^{-\\lambda}\\lambda^x}{x!}\\]\nwhere $\\lambda$ is the mean number of lacunae per specimen and $X$ is\nthe random variable ``number of lacunae on a specimen''.\n\n\\item If $x=0$ then $x!=0!=1$ and $\\lambda^x=\\lambda^0=1$, and the formula becomes  \n$\\displaystyle \\P(X=0) \\,=\\, e^{-\\lambda}$.\n\n\\item Since $\\P(X \\geq 1) = 0.1$, \\[\\P( X=0)\\;=\\; 1 -  \\P(X \\geq 1)\\;=\\; 0.9\\,.\\]\n\nUsing (b) and solving for $\\lambda$ gives:\n\\[ e^{-\\lambda}\\;=\\; 0.9 \\quad \\text{that is,}\\quad \\lambda \\;=\\; -\\ln(0.9) \\;=\\; 0.1\\;\n(\\text{approximately}\\,.)\\]\n\nHence \\[\\P( X=2 )\\;=\\;   \\frac{e^{-0.1} (0.1)^2}{2!}  \\;=\\;0.45\\% \\;\n(\\text{approximately}\\,.) \\]\n\n\\item Occurrence of lacunae may not always be independent. For example, a machine malfunction may cause them to be clumped.\n\\ee\n\n\n\\end{ExerciseList}\n", "meta": {"hexsha": "fe0a02936b96b3f4994b58303666e5eaca98c683", "size": 14158, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/ExsInDiscreteRVs.tex", "max_stars_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_stars_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-19T07:54:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T13:55:18.000Z", "max_issues_repo_path": "matlab/csebook/ExsInDiscreteRVs.tex", "max_issues_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_issues_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "matlab/csebook/ExsInDiscreteRVs.tex", "max_forks_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_forks_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-07-18T07:47:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T11:28:24.000Z", "avg_line_length": 41.1569767442, "max_line_length": 578, "alphanum_fraction": 0.6226161887, "num_tokens": 5802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.8962513835254865, "lm_q1q2_score": 0.740941596865702}}
{"text": "\\section{Standing wave in 3D}\r\n\r\nYou are singing in a 1\\,m $\\times$ 2\\,m $\\times$ 3\\,m shower room.\\\\\r\n\\begin{enumerate}[label=\\alph*)] % a), b), c), ...\r\n\r\n\\item (3 pts) The sound waves generated are pressure waves propagating in air with some speed $c_s$. What is the wave equation for the displacement $\\xi$ from equilibrium position in 3D?\r\n\r\n\r\n\\item (2 pts) Assuming the walls are immovable, what are the boundary conditions of the wave equation? Justify your answer.\r\n\\\\\r\n\r\n\r\nFunctions of the form $\\xi(x,y,z,t)=A\\sin(k_x x)\\sin(k_y y)\\sin(k_z z)\\cos(\\omega t)$ solve the wave equation.\r\n\r\n\r\n\\item (3 pts) Determine $\\omega$ as a function of $k_x, k_y, k_z$.\r\n\r\n\\item (2 pts) What are the 3 lowest normal mode frequencies?\r\n\r\n\\end{enumerate}\r\n\r\n% \\newpage\r\n% \\section{Solutions}\r\n%\r\n% \\begin{enumerate}[a)]\r\n% \t\\item The wave equation is\r\n% \t\\begin{equation}\r\n% \tc_s^2 \\nabla^2 \\xi =\\partial_t^2 \\xi\r\n% \t\\end{equation}\r\n%\r\n%\r\n% \t\\item Dirichlet BC, $\\xi|_{\\partial}=0$. No displacement at the boundary.\r\n%\r\n%\r\n% \t\\item The dispersion relation can be written as\r\n% \t\\begin{equation}\r\n% \t\\omega^2 = c_s^2 (k_x^2+k_y^2+k_z^2)\r\n% \t\\end{equation}\r\n%\r\n%\r\n% \t\\item The normal mode frequencies are determined by\r\n%\r\n% \t\\begin{equation}\r\n% \t\\omega^2 = c_s^2 ((\\frac{n_x\\pi}{1})^2+(\\frac{n_y\\pi}{2})^2+(\\frac{n_z\\pi}{3})^2)\r\n% \t\\end{equation}\r\n%\r\n% \tHence by a simple counting, we have the 3 lowest 3-tuple: $(1,1,1), (1,1,2), (1,2,1)$, ordered as $(n_x,n_y,n_z)$.\r\n%\r\n%\r\n% \\end{enumerate}\r\n", "meta": {"hexsha": "3d8f93355ebf99362ba37c9ad42c74ff69a02fa6", "size": 1487, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Quizzes/quiz3_shower.tex", "max_stars_repo_name": "rxa254/VibrationsAndWaves", "max_stars_repo_head_hexsha": "347a25413921e3a8ffde9ece48dc357bd417239c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-20T05:11:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-20T05:11:53.000Z", "max_issues_repo_path": "Quizzes/quiz3_shower.tex", "max_issues_repo_name": "rxa254/VibrationsAndWaves", "max_issues_repo_head_hexsha": "347a25413921e3a8ffde9ece48dc357bd417239c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Quizzes/quiz3_shower.tex", "max_forks_repo_name": "rxa254/VibrationsAndWaves", "max_forks_repo_head_hexsha": "347a25413921e3a8ffde9ece48dc357bd417239c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.1568627451, "max_line_length": 187, "alphanum_fraction": 0.6388702085, "num_tokens": 521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.7409415894077186}}
{"text": "\\subsection{Trigonometric Identities}\nThere are numerous trigonometric identities, including those relating to shift/periodicity, Pythagoras type identities, double-angle formulas, half-angle formulas and addition formulas.\nWe list these below.\n\n\\begin{enumerate}\n\\item[1.] \\dfont{Shifts and periodicity}\n$$\\begin{array}{|rcl|rcl|rcl|}\n\\hline\n~&~&~&~&~&~&~&~&~\\\\\n\\ds{\\sin (\\theta + 2\\pi)} & = & \\ds{\\sin \\theta} &\n\\ds{\\cos (\\theta + 2\\pi)} &= & \\ds{\\cos \\theta} &\n\\ds{\\tan (\\theta + 2\\pi)} &= & \\ds{\\tan \\theta} \\\\\n~&~&~&~&~&~&~&~&~\\\\\n\\hline\n~&~&~&~&~&~&~&~&~\\\\\n\\ds{\\sin (\\theta + \\pi)} &= & \\ds{-\\sin \\theta} &\n\\ds{\\cos (\\theta + \\pi)} &= & \\ds{-\\cos \\theta} &\n\\ds{\\tan (\\theta + \\pi)} &= & \\ds{\\tan \\theta} \\\\\n~&~&~&~&~&~&~&~&~\\\\\n\\hline\n~&~&~&~&~&~&~&~&~\\\\\n\\ds{\\sin (-\\theta)} &= & \\ds{-\\sin \\theta} & \n\\ds{\\cos (-\\theta)} &= & \\ds{\\cos \\theta} & \n\\ds{\\tan (-\\theta)} &= & \\ds{-\\tan \\theta}  \\\\\n~&~&~&~&~&~&~&~&~\\\\\n\\hline\n~&~&~&~&~&~&~&~&~\\\\\n\\ds{\\sin \\left(\\theta +\\frac{\\pi}{2}\\right) } &= &  \\ds{\\cos \\theta} &\n\\ds{\\cos \\left(\\theta -\\frac{\\pi}{2}\\right)} &= &  \\ds{\\sin \\theta} &\n\\ds{\\tan \\left(\\frac{\\pi}{2}-\\theta\\right)} &= & \\ds{\\cot \\theta}  \\\\\n~&~&~&~&~&~&~&~&~\\\\\n\\hline\n\\end{array}$$\n\\end{enumerate}\n\n\\begin{multicols}{2}\n\\begin{enumerate}\n\\item[2.] \\dfont{Pythagoras type formulas}\n\n$ \\begin{array}{|rcl|} \\hline\t\n&& \\\\\n\\ds{\\sin ^2 \\theta + \\cos ^2 \\theta} & = & \\ds{1}\\\\\n&& \\\\\n\\ds{\\tan^2 \\theta + 1} & = & \\ds{\\sec^2 \\theta} \\\\\n&& \\\\\n\\ds{1 + \\cot ^2 \\theta}  & = & \\ds{\\csc^2 \\theta} \\\\\n&& \\\\ \\hline\n\\end{array} $\n\n\\vspace{5mm} \n\\item[3.] \\dfont{Addition and subtraction formulas}\n\n$\\begin{array}{|rcl|} \\hline\n&& \\\\\t\n\\ds{\\sin(\\theta+\\phi)} & = & \\ds{\\sin\\theta\\cos\\phi + \\cos\\theta\\sin\\phi} \\\\\n&& \\\\\n\\ds{\\cos(\\theta+\\phi)} & = & \\ds{\\cos\\theta\\cos\\phi - \\sin\\theta\\sin\\phi} \\\\\n&& \\\\\n\\ds{\\tan(\\theta+\\phi)} & = & \\ds{\\frac{\\tan\\theta + \\tan\\phi}{1 - \\tan\\theta\\tan\\phi}}\\\\\n&& \\\\\n\\ds{\\sin(\\theta-\\phi)} & = & \\ds{\\sin\\theta\\cos\\phi - \\cos\\theta\\sin\\phi} \\\\\n&& \\\\\n\\ds{\\cos(\\theta-\\phi)} & = & \\ds{\\cos\\theta\\cos\\phi + \\sin\\theta\\sin\\phi} \\\\\n&& \\\\ \\hline \n\\end{array} $\n\n\n\\item[4.] \\dfont{Double-angle formulas}\n\n$\\begin{array}{|rcl|} \\hline\n&& \\\\\t\n\\ds{\\sin(2\\theta)} & =  & \\ds{2\\sin\\theta\\cos\\theta} \\\\\n&& \\\\\n\\ds{\\cos(2\\theta)} & = & \\ds{\\cos^2\\theta - \\sin^2\\theta}\\\\\n& =  & \\ds{2\\cos^2\\theta - 1} \\\\\n& = & \\ds{1-2\\sin^2\\theta}\\\\\n&& \\\\ \\hline \n\\end{array}$\n\n\\vspace{4mm} \n\\item[5.] \\dfont{Half-angle formulas}\n\n$ \\begin{array}{|rcl|} \\hline \n&& \\\\\n\\ds{\\cos^2\\theta} & = & \\ds{\\frac{1+\\cos(2\\theta)}{2}} \\\\\n&& \\\\\n\\ds{\\sin^2\\theta} & = & \\ds{\\frac{1-\\cos(2\\theta)}{2}} \\\\\n&& \\\\ \\hline \n\\end{array} $\n\n\\end{enumerate}\n\\end{multicols}\n\n\\begin{example}{Double Angle}{DoubleAngle}\nFind all values of $x$ with $0\\leq x\\leq \\pi$ such that $\\sin 2x=\\sin x$.\n\\end{example}\n\n\\begin{solution} \nUsing the double-angle formula $\\sin 2x = 2\\sin x \\cos x$ we have:\n\n\\hspace{3cm} $$\\begin{array}{rcl}\n\\ds{2\\sin x\\cos x} & = & \\ds{\\sin x} \\\\\n\\ds{2\\sin x\\cos x- \\sin x} & = & \\ds{0} \\\\\n\\ds{\\sin x \\, (2\\cos x - 1)} & = & \\ds{0} \\\\\n\\end{array}$$\n\nThus, either \\hspace{1cm} $\\,\\, \\sin x=0 \\,\\, $ or $\\,\\, \\cos x = 1/2\\,\\, $. \\\\\n\nFor the first case when $\\,\\, \\sin x = 0 \\,\\, $, we get $\\, x=0 \\, $ or $\\, x=\\pi \\,$.\nFor the second case when $\\,\\,\\cos x = 1/2 \\,\\,$, we get $\\, x=\\pi/3 \\,$ (use the special triangles and CAST rule to get this).\nThus, we have three solutions: $x=0, \\, \\pi/3, \\, \\pi$.\n\\end{solution}", "meta": {"hexsha": "be79b7e2c63268e3c67e18b7f18c7c169d7a1a6b", "size": 3407, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1-review/1-3-5-trig-identities.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1-review/1-3-5-trig-identities.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1-review/1-3-5-trig-identities.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.4196428571, "max_line_length": 185, "alphanum_fraction": 0.5253889052, "num_tokens": 1489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7409415779529469}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS630: Database Management Systems\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 1}\n\nWrite \\textbf{relational algebra} expressions for the following queries:\n\n\\begin{enumerate}[label=(\\alph*)]\n\n\\item Find the ages of employees who work in a department named 'Catering'.\n\n\\textbf{Solution:}\n$$ \\pi_{E.age}(\\pi_{W.eid}(\\pi_{D.did}(\\sigma_{D.dname = 'Catering'}D)\\Join W)\\Join E) $$\n\\item Find salaries of employees that work at least 30\\% of their time in departments that have budget at least \\$50000.\n\n\\textbf{Solution:}\n$$ \\pi_{E.salary}(\\pi_{W.eid}(\\sigma_{W.pct\\_time \\geq 30}(\\pi_{D.did}(\\sigma_{D.budget \\geq 50000}D)\\Join W))\\Join E) $$\n\n\\item Find the salaries of department managers.\n\n\\textbf{Solution:}\n$$ \\pi_{E.salary}(\\sigma_{E.eid = D.managerid}((D \\Join_{W.did = D.did} W)\\Join_{W.eid = E.eid} E)) $$\n\n\\item Find the names of employees who work in the \\textit{Marketing} department or who spend more than half of their time in a single department.\n\n\\textbf{Solution:}\n$$\\rho(E1,\\pi_{W.eid}(\\pi_{D.did}(\\sigma_{D.dname ='Marketing'}D)\\Join W))$$\n$$\\rho(E2,\\pi_{E.eid}(\\sigma_{W.pct\\_time \\geq 50}(E \\Join W)))$$\n$$\\pi_{E.ename}((E1 \\cup E2)\\Join E) $$\n\n\\item Find the \\texttt{eid} of managers who manage exactly one department.\n\n\\textbf{Solution:}\n\\begin{enumerate}\n\\item M is defined as \\texttt{eid} of managers who manage more than two department.\n$$\\rho(D1(1\\rightarrow did2, 2\\rightarrow dname2, 3\\rightarrow budget2, 4\\rightarrow managerid2),Department) $$\n$$\\rho(M,\\pi_{managerid}(Department \\Join_{(managerid = managerid2 \\wedge did \\neq did2)} D1 )) $$\n\\item desired list $M^\\prime$ is obtained by subtracting M from the list of all managers.\n$$\\rho(M^\\prime,\\pi_{E.eid}(\\pi_{W.eid}((\\pi_{managerid}Department - M)\\Join_{managerid = eid} Works)\\Join Employee))$$\n\\end{enumerate}\n\\end{enumerate}\n", "meta": {"hexsha": "5d66f45a5dcdcbc02beae0a7538375c6d2ae0ab1", "size": 2114, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs630-2014f/src/tex/m01/m01q01.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs630-2014f/src/tex/m01/m01q01.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs630-2014f/src/tex/m01/m01q01.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 45.9565217391, "max_line_length": 145, "alphanum_fraction": 0.6674550615, "num_tokens": 657, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7408936329418455}}
{"text": "\\section{Action of $\\pi_1$, simple spaces, and the Hurewicz theorem}\nIn the previous section, we constructed a long exact sequence of homotopy groups:\n\\begin{equation*}\n    \\xymatrix{\n\t& \\cdots\\ar[r] & \\pi_2 (X,A)\\ar[dll]\\\\\n\t\\pi_1 A\\ar[r] & \\pi_1 X\\ar[r] & \\pi_1 (X,A)\\ar[dll]\\\\\n\t\\pi_0 A\\ar[r] & \\pi_0 X, & \n    }\n\\end{equation*}\nwhich looks suspiciously similar to the long exact sequence in homology.\nThe goal of this section is to describe a relationship between homotopy groups and homology groups.\n\nBefore we proceed, we will need the following lemma.\n\\begin{lemma}[Excision]\n    If $A\\subseteq X$ is a cofibration, there is an isomorphism\n    $$H_\\ast(X,A)\\xrightarrow{\\simeq}\\widetilde{H}_\\ast(X/A).$$\n    Under this hypothesis,\n    $$X/A\\simeq\\text{Mapping cone of }i:A\\to X;$$\n    here, the mapping cone is the homotopy pushout in the following diagram:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    A\\ar[r]^i\\ar[d]^{in_1} & X\\ar[d]\\\\\n\t    CA\\ar[r] & X\\cup_A CA,\n\t    }\n    \\end{equation*}\n    where $CA$ is the cone on $A$, defined by\n    $$CA = A\\times I/A\\times 0.$$\n\\end{lemma}\nThis lemma is dual to the statement that the homotopy fiber is homotopy equivalent to the strict fiber for fibrations.\n\nUnfortunately, $\\pi_\\ast(X,A)$ is definitely not $\\pi_\\ast(X/A)$!\nFor instance, there is a cofibration sequence\n$$S^1\\to D^2\\to S^2.$$\nWe know that $\\pi_\\ast S^1$ is just $\\Z$ in dimension $1$, and is zero in other dimensions.\nOn the other hand, we do not, and probably will never, know the homotopy groups of $S^2$.\n(A theorem of Edgar Brown in \\cite{brown-computability} says that these groups are computable, but this is super-exponential.)\n%\\begin{theorem}[Now]\n%    If $X$ is a simply connected finite complex, and $X\\not\\simeq \\ast$, then we do not know $\\pi_\\ast(X)$. And we'll probably never be able to know them.\n%\\end{theorem}\n%These groups \\emph{are} computable (a theorem by Edgar Brown), but it's super-exponential. This is discouraging. We'll never know what, eg., $\\pi_{10000}(S^2)$ is.\n\n%Anyway, I said there was $\\partial:\\pi_n(X,A,\\ast)\\to \\pi_{n-1}(A,\\ast)$. How does this look? Well you just look at the restriction of $I^n\\to X$ to $1\\times I^{n-1}\\to A$. And the composite $\\pi_n(X,A,\\ast)\\xrightarrow{\\partial}\\pi_{n-1}(A,\\ast)\\to \\pi_{n-1}(X,\\ast)$ is trivial by definition!\n\\subsection{$\\pi_1$-action}\nThere is more structure in the long exact sequence in homotopy groups that we constructed last time, coming from an action\nof $\\pi_1(X)$.\nThere is an action of $\\pi_1(X)$ on $\\pi_n(X)$: if $x,y$ are points in $X$, and $\\omega:I\\to X$ is a path with $\\omega(0) = x$ and $\\omega(1) = y$, we have a map $f_\\omega:\\pi_n(X,x)\\to \\pi_n(X,y)$;\nthis, in particular, implies that $\\pi_1(X,\\ast)$ acts on $\\pi_n(X,\\ast)$.\nWhen $n=1$, the action $\\pi_1(X)$ on itself is by conjugation.\n\nIn fact, one can also see that $\\pi_1(A)$ acts on $\\pi_n(X,A,\\ast)$.\nIt follows (by construction) that all maps in the long exact sequence of Equation \\eqref{lexseqhomotopy} are equivariant for\nthis action of $\\pi_1(A)$.\nMoreover:\n\\begin{prop}[Peiffer identity]\n    Let $\\alpha,\\beta\\in \\pi_2(X,A)$. Then $(\\partial \\alpha)\\cdot\\beta = \\alpha\\beta\\alpha^{-1}$.\n\\end{prop}\n%For example, if $j:\\pi_2(X)\\to \\pi_2(X,A)$, and $\\alpha = j(\\gamma)$, $\\partial\\alpha = 1$: $\\img(k)\\subseteq\\coker \\pi_2(X,A)$. (I did not follow this)\n\n\\begin{definition}\n    A topological space $X$ is said to be \\emph{simply connected} if it is path connected, and $\\pi_1(X,\\ast) = 1$.\n\\end{definition}\nLet $p:E\\to B$ be a covering space with $E$ and $B$ connected.\nThen, the fibers are discrete, hence do not have any higher homotopy.\nUsing the long exact sequence in homotopy groups, we learn that $\\pi_n(E)\\to \\pi_n(B)$ is an isomorphism for $n>1$,\nand that $\\pi_1(E)$ is a subgroup of $\\pi_1(B)$ that classifies the covering space.\nIn general, we know from Exercise \\ref{simplequotient} that $\\Omega B$ acts on the homotopy fiber $Fp$.\nSince $Ff$ is discrete, this action factors through $\\pi_0(\\Omega B)\\simeq \\pi_1(B)$.\n\n%In particular, $\\pi_q(S^n)\\simeq \\pi_q(\\RP^n)$ for $q>1$. Of course, $\\pi_1(\\RP^n)\\simeq \\Z/2\\Z$. This creates a ton of homology in $\\RP^n$ that's not present in the homology of $S^n$. Here's a piece of language.\n\\begin{definition}\n    A space $X$ is said to be \\emph{$n$-connected} if $\\pi_i(X) = 0$ for $i\\leq n$.\n\\end{definition}\nNote that this is a well-defined condition, although we did not specify the basepoint: $0$-connected implies path connected.\nSuppose $E\\to B$ is a covering space, with the total space $E$ being $n$-connected.\nThen, Hopf showed that the group $\\pi_1(B)$ determines the homology $H_i(B)$ in dimensions $i<n$.\n%in particular, $H_i(B) = H_i(\\pi_1(B))$, which is the group homology. This is due to Heinz Hopf.\n\nSometimes, there are interesting spaces which are not simply connected, for which the $\\pi_1$-action is nontrivial.\n\\begin{example}\n    Consider the space $S^1\\vee S^2$.\n    The universal cover is just $\\RR$, with a $2$-sphere $S^2$ stuck on at every integer point.\n    This space is simply connected, so the Hurewicz theorem says that $\\pi_2(E)\\simeq H_2(E)$.\n    Since the real line is contractible, we can collapse it to a point: this gives a countable bouquet of $2$-spheres.\n    As a consequence, $\\pi_2(E)\\simeq H_2(E) = \\bigoplus_{i=0}^\\infty \\Z$.\n\n    There is an action of $\\pi_1(S^1\\vee S^2)$ on $E$: the action does is shift the $2$-spheres on the integer points of $\\RR$ (on $E$) to the right by $1$ (note that $\\pi_1(S^1\\vee S^2) = \\Z$).\n    This tells us that $\\pi_2(E) \\simeq \\Z[\\pi_1(B)]$ as a $\\Z[\\pi_1(B)]$-module; this is the same action of $\\pi_1(E)$ on\n    $\\pi_2(E)$.\n    We should be horrified: $S^1\\vee S^2$ is a very simple $3$-complex, but its homotopy is huge!\n\\end{example}\nSimply-connectedness can sometimes be a restrictive condition; instead, to simplify the long exact sequence, we define:\n\\begin{definition}\n    A topological space $X$ is said to be \\emph{simple} if it is path-connected, and\n    $\\pi_1(X)$ acts trivially on $\\pi_n(X)$ for $n\\geq 1$.\n\\end{definition}\nNote, in particular, that $\\pi_1(X)$ is abelian for a simple space.\n\nBeing simple is independent of the choice of basepoint. If $\\omega:x\\mapsto x^\\prime$ is a path in $X$,\nthen $\\omega_\\sharp:\\pi_n(X,x)\\to \\pi_n(X,x^\\prime)$ is a group isomorphism.\nThere is a (trivial) action of $\\pi_1(X,x)$ on $\\pi_n(X,x)$, and another (potentially nontrivial)\naction of $\\pi_1(X,x^\\prime)$ on $\\pi_n(X,x^\\prime)$.\nBoth actions are compatible: hence, if $\\pi_1(X,x)$ acts trivially, so does $\\pi_1(X,x^\\prime)$.\n\nIf $X$ is path-connected, there is a map $\\pi_n(X,\\ast)\\to [S^n,X]$.\nIt is clear that this map is surjective,\n%because I can always choose a basepoint in $X$ as the image of a basepoint in $S^n$.\nso one might expect a factorization:\n\\begin{equation*}\n    \\xymatrix{\n\t\\pi_n(X,\\ast)\\ar@{->>}[r]\\ar[dr] & [S^n,X]\\\\\n\t& \\pi_1(X,\\ast)\\backslash \\pi_n(X,\\ast)\\ar[u]\n\t}\n\\end{equation*}\n\\begin{exercise}\\label{simplequotient}\n    %Exercises 7 and 9 of pset 2\n    Prove that $\\pi_1(X,\\ast)\\backslash \\pi_n(X,\\ast) \\simeq [S^n, X]$.\n    To do this, work through the following exercises.\n    \n    Let $f:X\\to Y$ be a map of spaces, and let $\\ast\\in Y$ be a fixed basepoint of $Y$.\n    Denote by $Ff$ the homotopy fiber of $f$; this admits a natural fibration $p:Ff \\to X$, given by $(x,\\sigma)\\mapsto x$.\n    If $\\Omega Y$ denotes the (based) loop space of $Y$, we get an action $\\Omega Y \\times Ff \\to Ff$, given by\n    $$(\\omega,(x,\\sigma)) \\mapsto (x,\\sigma\\cdot\\omega),$$\n    where $\\sigma\\cdot\\omega$ is the concatenation of $\\sigma$ and $\\omega$, defined, as usual, by\n    $$\n    \\sigma\\cdot\\omega(t) = \\begin{cases}\n\t\\omega(2t) & 0\\leq t\\leq 1/2\\\\\n\t\\sigma(2t-1) & 1/2\\leq t\\leq 1.\n    \\end{cases}\n    $$\n    (Note that when $X$ is the point, this defines a ``multiplication'' $\\Omega Y \\times \\Omega Y \\to \\Omega Y$; this is \n    associative and unital up to homotopy.)\n    On connected components, we therefore get an action of $\\pi_0\\Omega Y \\simeq \\pi_1 Y$ on $\\pi_0 Ff$.\n\n    There is a canonical map\n    $$Ff \\times \\Omega Y \\to Ff\\times_X Ff,$$\n    given by $((x,\\sigma),\\omega) \\mapsto ((x,\\sigma),(x,\\sigma)\\cdot\\omega)$.\n    Prove that this map is a homotopy equivalence (so that the action of $\\Omega Y$ on $Ff$ is ``free''), and conclude that\n    two elements in $\\pi_0 Ff$ map to the same element of $\\pi_0 X$ if and only if they are in the same orbit under the action\n    of $\\pi_1 Y$.\n\n    Let $X$ be path connected, with basepoint $\\ast\\in X$.\n    Conclude that $\\pi_1(X,\\ast)\\backslash \\pi_n(X,\\ast) \\simeq [S^n,X]$ by proving that the surjection\n    $\\pi_n(X,\\ast) \\to [S^n,X]$ can be identified with the orbit projection for the action of $\\pi_1(X,\\ast)$ on $\\pi_n(X,\\ast)$.\n\\end{exercise}\nIf $X$ is simple, then the quotient $\\pi_1(X,\\ast)\\backslash \\pi_n(X,\\ast)$ is simply $\\pi_n(X, \\ast)$, so\nExercise \\ref{simplequotient} implies that $\\pi_n(X,\\ast)\\cong [S^n,X]$ --- independently of the basepoint;\nin other words, these groups are canonically the same, i.e., two paths $\\omega,\\omega^\\prime:x\\to y$ give the\nsame map $\\omega_\\sharp = \\omega^\\prime_\\sharp:\\pi_n(X,x)\\to \\pi_n(X,y)$.\n\n\\begin{exercise}\n    A \\emph{$H$-space} is a pointed space $X$, along with a pointed map $\\mu:X\\times X \\to X$, such that the maps\n    $x\\mapsto \\mu(x,\\ast)$ and $x\\mapsto \\mu(\\ast,x)$ are both pointed homotopic to the identity.\n    In this exercise, you will prove that path connected $H$-spaces are simple.\n    \n    Denote by $\\cc$ the category of pairs $(G,H)$, where $G$ is a group that acts on the group $H$ (on the left); the morphisms\n    in $\\cc$ are pairs of homomorphisms which are compatible with the group actions.\n    This category has finite products.\n    Explain what it means for an object of $\\cc$ to have a ``unital multiplication'', and prove that any object $(G,H)$ of $\\cc$\n    with a unital multiplication has $G$ and $H$ abelian, and that the $G$-action on $H$ is trivial.\n    Conclude from this that path connected $H$-spaces are simple.\n\\end{exercise}\n\\subsection{Hurewicz theorem}\n\\begin{definition}\n    Let $X$ be a path-connected space.\n    The Hurewicz map $h:\\pi_n(X,\\ast)\\to H_n(X)$is defined as follows:\n    an element in $\\pi_n(X,\\ast)$ is represented by $\\alpha:S^n\\to X$; pick a generator $\\sigma\\in H_n(S^n)$, and send\n    $$\\alpha\\mapsto\\alpha_\\ast(\\sigma)\\in H_n(X).$$\n\\end{definition}\nWe will see below that $h$ is in fact a homomorphism.\n\nThis is easy in dimension $0$: a point is a $0$-cycle!\nIn fact, we have an isomorphism $H_0(X)\\simeq \\Z[\\pi_0(X)]$.\n(This isomorphism is an example of the Hurewicz theorem.)\n\nWhen $n=1$, we have $h:\\pi_1(X,\\ast)\\to H_1(X)$. Since $H_1(X)$ is abelian, this factors as\n$\\pi_1(X,\\ast)\\to \\pi_1(X,\\ast)^{ab}\\to H_1(X)$.\nThe Hurewicz theorem says that the map $\\pi_1(X,\\ast)^{ab}\\to H_1(X)$ is an isomorphism.\nWe will not prove this here; see \\cite[Theorem 2A.1]{hatcher} for a proof.\n\nThe Hurewicz theorem generalizes these results to higher dimensions:\n\\begin{theorem}[Hurewicz]\n    Suppose $X$ is a space for which $\\pi_i(X) = 0$ for $i<n$, where $n\\geq 2$.\n    Then the Hurewicz map $h:\\pi_n(X)\\to H_n(X)$ is an isomorphism.\n\\end{theorem}\n\nBefore the word ``isomorphism'' can make sense, we need to prove that $h$ is a homomorphism.\nLet $\\alpha,\\beta:S^n\\to X$ be pointed maps. The product $\\alpha\\beta\\in \\pi_n(X)$ is the composite:\n$$\\alpha\\beta:S^n\\xrightarrow{\\delta\\text{, pinching along the equator}} S^n\\vee S^n\\xrightarrow{\\beta\\vee\\alpha}X\\vee X\\xrightarrow{\\nabla}X,$$\nwhere $\\nabla:X\\vee X\\to X$ is the fold map, defined by:\n\\begin{equation*}\n    \\xymatrix{\n\tX\\ar[dr]^1\\ar[d] & \\\\\n\tX\\vee X\\ar[r]|\\nabla & X\\\\\n\tX\\ar[u]\\ar[ur]_1 & \n    }\n\\end{equation*}\n%We have two inclusions $\\mathrm{in}_1,\\mathrm{in}_2$ of $S^n$ to $S^n\\vee S^n$.\n%If $\\sigma\\in H_n(S^n)$ is a generator, the composite\n%$$\\sigma\\mapsto {in_1}_\\ast\\sigma + {in_2}_\\ast\\sigma\\mapsto {in_1}_\\ast h(\\alpha) + {in_2}_\\ast h(\\beta)\\mapsto h(\\alpha) + h(\\beta)$$\n%\\todo{edit from here}\n%As desired.\nTo show that $h$ is a homomorphism, it suffices to prove that for two maps $\\alpha,\\beta:S^n \\to X$, the induced maps on homology\nsatisfy $(\\alpha+\\beta)_\\ast = \\alpha_\\ast + \\beta_\\ast$ --- then,\n$$h(\\alpha+\\beta) = (\\alpha+\\beta)_\\ast(\\sigma) = \\alpha_\\ast(\\sigma) + \\beta_\\ast(\\sigma) = h(\\alpha) + h(\\beta).$$\nTo prove this, we will use the pinch map $\\delta:S^n \\to S^n \\vee S^n$, and the quotient maps $q_1,q_2:S^n\\vee S^n \\to S^n$;\nthe induced map $H_n(S^n) \\to H_n(S^n) \\oplus H_n(S^n)$ is given by the diagonal map $a\\mapsto (a,a)$.\nIt follows from the equalities\n$$(f\\vee g)\\iota_1 = f, \\ (f\\vee g)\\iota_2 = g,$$\nwhere $\\iota_1,\\iota_2:S^n\\hookrightarrow S^n \\vee S^n$ are the inclusions of the two wedge summands, that the map $(f\\vee g)_\\ast((\\iota_1)_\\ast + (\\iota_2)_\\ast)$\nsends $(x,0)$ to $f_\\ast(x)$, and $(0,x)$ to $g_\\ast(x)$.\nIn particular,\n$$(x,x)\\mapsto f_\\ast(x) + g_\\ast(x),$$\nso the composite $H_n(S^n) \\to H_n(X)$ sends $x\\mapsto (x,x) \\mapsto f_\\ast(x) + g_\\ast(x)$.\nThis composite is just $(f+g)_\\ast(x)$, since the composite $(f\\vee g)\\delta$ induces the map $(f+g)_\\ast$ on homology.\n\nIt is possible to give an elementary proof of the Hurewicz theorem, but we won't do that here: instead,\nwe will prove this as a consequence of the Serre spectral sequence.\n\n\\begin{example}\n    Since $\\pi_i(S^n) = 0$ for $i<n$, the Hurewicz theorem tells us that $\\pi_n(S^n) \\simeq H_n(S^n) \\simeq \\Z$.\n\\end{example}\n\n\\begin{example}\n    Recall the Hopf fibration $S^1\\to S^3\\xar{\\eta} S^2$.\n    The long exact sequence on homotopy groups tells us that\n    $\\pi_i(S^3)\\xrightarrow{\\simeq}\\pi_i(S^2)$ for $i>2$, where the map is given by\n    $\\alpha\\mapsto\\eta\\alpha$.\n    As we saw above, $\\pi_3(S^3) = \\Z$, so $\\pi_3(S^2)\\simeq \\Z$, generated by $\\eta$.\n    \n    One can show that $\\pi_{4n-1}(S^{2n})\\otimes\\QQ\\simeq \\QQ$.\n    A theorem of Serre's says that, other than $\\pi_n(S^n)$, these are the only non-torsion homotopy groups of spheres.\n\\end{example}\n%One more thing to say is that $\\pi_i(S^n) = 0$ if $i<n$. I won't prove this, but it's also kind of obvious, isn't it? By Hurewicz, it follows that $\\pi_n(S^n)\\simeq H_n(S^n)\\simeq \\Z$. We actually have one more example: $\\pi_3(S^2)\\simeq \\Z$ generated by the Hopf fibration $S^3\\to S^2$. It's not obvious that this isn't nullhomotopic, but it's true. But now, for example, I can suspend $\\eta$ (the Hopf fibration) and get $\\eta\\circ\\Sigma\\eta$. We thought for a long time that there were the only things we could compute in $\\pi_\\ast S^n$; but this is not true! It's a lot more chaotic.\n", "meta": {"hexsha": "7f3a6dcf4785609e9493cbd85fdf69c1416ec607", "size": 14566, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-47-pi_1-action-hurewicz.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "906/lec-47-pi_1-action-hurewicz.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "906/lec-47-pi_1-action-hurewicz.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 62.2478632479, "max_line_length": 588, "alphanum_fraction": 0.6755457916, "num_tokens": 4975, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.8757869981319862, "lm_q1q2_score": 0.7408653945659105}}
{"text": "\\subsection{Free Undamped Vibrations ($b = 0$)}\r\n\\noindent\r\nIn this case, our equation simplifies to\r\n\\begin{equation*}\r\n\tmy'' + ky = 0.\r\n\\end{equation*}\r\nThe two roots of ou auxiliary equation are\r\n\\begin{equation*}\r\n\tr = \\pm i \\sqrt{\\frac{k}{m}} = \\pm i\\omega.\r\n\\end{equation*}\r\nSo, our solution becomes\r\n\\begin{equation*}\r\n\ty = C_1\\cos{(\\omega t)} + C_2\\sin{(\\omega t)}.\r\n\\end{equation*}\r\nThis is the same $\\omega$ from physics that means angular frequency, so the same physics formulas apply, like $T = \\frac{2\\pi}{\\omega}$ for the period of the oscillation.\\\\\r\n\r\n\\noindent\r\nWe can simplify this a bit further. If we think of the $\\cos$ and $\\sin$ components as being sides of a right triangle like so,\r\n\\begin{center}\r\n\t\\includegraphics[width=0.5\\textwidth]{./higherOrder/freeVibrs/triangle.png}\r\n\\end{center}\r\nthen we rewrite our equation as\r\n\\begin{equation*}\r\n\ty = A\\left( \\frac{C_1}{\\sqrt{C_1^2 + C_2^2}}\\cos{(\\omega t)} + \\frac{C_2}{\\sqrt{C_1^2 + C_2^2}}\\sin{(\\omega t)} \\right).\r\n\\end{equation*}\r\nNote that since $\\left(\\frac{C_1}{A}\\right)^2 + \\left(\\frac{C_2}{A}\\right)^2 = 1$, we can rewrite these coefficients as $\\cos{\\phi}$ and $\\sin{\\phi}$ respectively where\r\n\\begin{equation*}\r\n\t\\phi = \\begin{cases}\r\n\t\t\\arctan{(\\frac{C_2}{C_1})} & C_1 > 0 \\\\\r\n\t\t\\arctan{(\\frac{C_2}{C_1})} + \\pi & C_1 \\leq 0\r\n\t\\end{cases}.\r\n\\end{equation*} \r\nSo, our equation becomes\r\n\\begin{equation*}\r\n\ty = A\\left(\\cos{(\\omega t)}\\cos{\\phi} + \\sin{(\\omega t)}\\sin{\\phi}\\right).\r\n\\end{equation*}\r\nUsing the $\\cos$ angle addition formula,\r\n\\begin{equation*}\r\n\ty = A\\cos{(\\omega t - \\phi)}.\r\n\\end{equation*}\r\n\\begin{center}\r\n\t\\includegraphics[width=0.5\\textwidth]{./higherOrder/freeVibrs/undampedfree.png}\r\n\\end{center}\r\nAs we can see, an undamped free vibration will simply oscillate back and forth without decay.\r\n\r\n\\begin{example}\r\n\tA 2kg mass in an undamped system is attached to a spring with $k = 50 \\text{N/m}$. The initial position of the masss is $y_0 = -0.25\\text{m}$. The initial velocity is $v_0 = -1\\text{m/s}$. Find an expression for $y(t)$, the position of the mass at time $t$. Write your answer in terms of a $\\cos$ and a phase shift. Find the period and frequency in proper units.\r\n\\end{example}\r\n\\noindent\r\nThe IVP describing this problem is\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\t2y'' + 50y = 0 \\\\\r\n\t\ty'(0) = -1 \\\\\r\n\t\ty(0) = -0.25\r\n\t\\end{cases}.\r\n\\end{equation*}\r\nExtracting the auxiliary equation and finding the roots,\r\n\\begin{equation*}\r\n\t2r^2 + 50 = 0 \\implies r = \\pm 5i.\r\n\\end{equation*}\r\nSo, our general solution is\r\n\\begin{equation*}\r\n\ty = C_1\\cos{(5t)} + C_2\\sin{(5t)}.\r\n\\end{equation*}\r\nSolving for $C_1$ and $C_2$,\r\n\\begin{align*}\r\n\ty(0) &= -0.25 = C_1 \\implies C_1 = -0.25 \\\\\r\n\ty' &= -5C_1\\sin{(5t)} + 5C_2\\cos{(5t)} \\\\\r\n\ty'(0) &= -1 = 5C_2 \\implies C_2 = -0.2.\r\n\\end{align*}\r\nSolving for $\\phi$, keeping in mind that $C_1 < 0$,\r\n\\begin{equation*}\r\n\t\\phi = \\arctan{\\frac{C_2}{C_1}} + \\pi = \\arctan{\\frac{4}{5}} + \\pi.\r\n\\end{equation*}\r\nSo, our answer is (in units of meters)\r\n\\begin{equation*}\r\n\ty = \\sqrt{(-0.25)^2 + (-0.2)^2}\\cos{\\left(5t - \\arctan{\\left(\\frac{4}{5}\\right)} - \\pi\\right)} \\approx 0.32\\cos{\\left(5t - 3.82\\right)}.\r\n\\end{equation*}\r\nSolving for the period,\r\n\\begin{equation*}\r\n\tT = \\frac{2\\pi}{\\omega} = \\frac{2\\pi}{5} \\text{s}.\r\n\\end{equation*}\r\nSolving for the frequency,\r\n\\begin{equation*}\r\n\tf = \\frac{1}{T} = \\frac{5}{2\\pi} \\text{Hz}.\r\n\\end{equation*}", "meta": {"hexsha": "b7c55fe5d53f158c51af03228597b654d6c1cc7f", "size": 3389, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/freeVibrs/freeUndamped.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/higherOrder/freeVibrs/freeUndamped.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/higherOrder/freeVibrs/freeUndamped.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 38.9540229885, "max_line_length": 364, "alphanum_fraction": 0.6432575981, "num_tokens": 1283, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.8757869884059266, "lm_q1q2_score": 0.7408653863382239}}
{"text": "\n\\subsection{Farkas' lemma}\n\nWe have matrix \\(A\\) and vector \\(b\\).\n\nEither:\n\\begin{itemize}\n\\item \\(Ax=b\\); \\(x\\ge 0\\)\n\\item \\(A^Ty\\ge 0\\); \\(b^Ty<0\\)\n\\end{itemize}\n\n\n", "meta": {"hexsha": "4f0cb51afd545341a424a56812af7f6c5b7fd14b", "size": 168, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/optimisationMulti/03-04-farkas.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/optimisationMulti/03-04-farkas.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/optimisationMulti/03-04-farkas.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 12.9230769231, "max_line_length": 38, "alphanum_fraction": 0.5773809524, "num_tokens": 71, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299488452012, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7408242245403798}}
{"text": "%%% lecture 8a\n\n\\begin{beispiel}\n\tAssume $k(x,y)$ continuous on $[0,1] \\times [0,1]$ and $h(y,z)$ continuous on $[0,1]\\times \\mathbb{R}$ and \n\t\\[\n\t\t\\sup\\limits_{(y,z) \\in [0,1] \\times \\mathbb{R}} \\abs{h(y,z)} \\equiv B < \\infty.\n\t\\]\n\tThen there exists a solution $f \\in C([0,1])$ to \n\t\\[\n\t\tf(x) = \\int_{0}^{1} k(x,y)h(y,f(y)) \\,\\mathrm{d}y, \\qquad x \\in [0,1].\n\t\\]\n\tMethod: Set $f \\in C([0,1])$ and\n\t\\[\n\t\tT(f)(x) = \\int_{0}^{1}k(x,y)h(y,f(y)) \\,\\mathrm{d}y, \\qquad x \\in [0,1] \\qquad (*).\n\t\\]\n\tWe want to apply (a generalized version of) Schauder's fixed point theorem. Assume $(E, \\norm{.})$ is a Banach space and $F$ closed convex subset of $E$. Moreover assume $T: E \\to E$ continuos and $T(F)$ relatively compact in $(E,\\norm{.})$. Then $T$ has a fixed point in $F$. \\\\\n\t\\begin{description}\n\t\t\\item[Step 1:] $T$ as in $(*)$. \\\\\n\t\t\\textbf{Claim:} \\text{    }     $T(C([0,1])) \\subseteq C([0,1])$. \\\\\n\t\tTo proof this we note that $k$ is continuous on $[0,1] \\times [0,1]$ whicht is compact in $\\mathbb{R}^2$. This implies that $k$\n is uniformly continuous on $[0,1]\\times [0,1]$. Fix now $\\varepsilon >0$. \\\\\n Then there exists $\\delta = \\delta (\\varepsilon) >0$ such that\n \\[\n \t\\abs{k(x_1,y_1)- k(x_2,y_2)} < \\frac{\\varepsilon}{B}\n \\]\n for $\\abs{(x_1,y_1)- (x_2,y_2)}< \\delta $. \\\\\n Fix $f \\in C([0,1])$\n \t\\begin{align*}\n \t\t\\abs{T(f)(x_1)-T(f)(x_2)} & = \\abs{ \\int_{0}^{1}(k(x_1,y)-k(x_2,y))h(y,f(y)) \\,\\mathrm{d}y} \\\\\n\t\t&\\leq \\int_{0}^{1}\\underset{< \\frac{\\varepsilon}{B} \\text{ if } \\abs{x_1-x_2}< \\delta }{\\underbrace{\\abs{k(x_1,y)-k(x_2,y)}}}\\underset{\\leq B}{\\underbrace{\\abs{h(y,f(y))}}} \\,\\mathrm{d}y < \\varepsilon, \\qquad \\text{provided }\\abs{x_1-x_2}< \\delta\n \t\\end{align*}\n\tConclusion: $T(f) \\in C([0,1])$ for $f \\in C([0,1])$\n\t\\item[Step 2:] Choose $F$. \\\\\n\t$k$ is a continuous function on a compact set $[0,1] \\times [0,1]$ implies\n\t\\[\n\t\t\\sup\\limits_{(x,y) \\in [0,1] \\times [0,1]} \\abs{k(x,y)} \\equiv A < \\infty.\n\t\\]\n\tHence \n\t\\[\n\t\t\\abs{T(f)(x)} \\leq  AB \\qquad \\text{ for all }f \\in C([0,1]).\n\t\\]\n\tSet \n\t\\[\n\t\tF:= \\set[f \\in C([0,1])]{\\norm{f} = \\max_{x \\in [0,1]}\\abs{f(x)} \\leq AB}.\n\t\\]\n\tClearly $F$ is closed convex in $(C([0,1]),\\norm{.})$ which is a Banach space.\n\t\\item[Step 3:] \\textbf{Claim:} \\text{    }     $T(F)$ is relatively compact. \\\\\n\tTo prove this we use the Arzela-Ascoli Theorem. \\\\\n\t$\\phantom{...}$ \\\\\n\tLet $K$ be a compact set in $\\mathbb{R}^n$. Let $\\mathcal{S} \\subset C(K)$ (realvalued continuous functions on $K$). \\\\\n\tThen $\\mathcal{S}$ is relatively compact in $(C(K),\\norm{.}_{\\infty})$ if \n\t\\begin{enumerate}[(1)]\n\t\t\\item $\\mathcal{S}$ uniformly bounded, i.e.\n\t\t\\[\n\t\t\t\\sup_{f \\in \\mathcal{S}} \\norm{f} < \\infty.\n\t\t\\]\n\t\t\\item Equicontinuity of $f \\in \\mathcal{S}$, i.e.\n\t\t\\begin{align*}\n\t\t\t\\forall\\, \\varepsilon>0 \\,\\exists\\, \\delta = \\delta (\\varepsilon) >0: \\,\\forall\\,  f \\in \\mathcal{S}: & \\\\\n\t\t\t\\abs{x_1-x_2} < \\delta, \\, x_1,x_2 \\in K \\qquad \\Rightarrow & \\qquad \\abs{f(x_2)-f(x_1)}< \\varepsilon.\n\t\t\\end{align*}\n\t\\end{enumerate}\n\tIn our example it is $\\mathcal{S} = F$, $K = [0,1]$ in $\\mathbb{R}$. Check that (1) and (2) in AA-Theorem are satisfied. \\\\\n\t\\begin{enumerate}[(1)]\n\t\t\\item $F$ is uniformly bounded since\n\t\\[\n\t\t\\sup_{f \\in F}\\norm{f} \\leq AB < \\infty.\n\t\\]\n\t\\item Equicontinuity follows from calculations in Step 1. \\\\\n\t\\end{enumerate}\t\n\tConclusion: $T(F)$ is relatively compact.\n\t\\item[Step 4:] \\textbf{Claim:} \\text{    }     $T: F \\to F$ continuous \\\\\n\tIn step 1 we had $f \\in F$ and $x_n \\to x$ in $[0,1]$. We have shown that $T(f)(x_n) \\to T(f)(x)$ in $\\mathbb{R}$. So $T(f)$ is a continuous function. \\\\\n\tNow we want to show that for $f_n \\to f$ in $F$ we've got $T(f_n) \\to T(f)$ in $C([0,1])$. \\\\\n\tNote that $h: [0,1] \\times [-AB,AB] \\to \\mathbb{R}$ is continuous and $[0,1] \\times [-AB,AB]$ is compact set in $\\mathbb{R}^2$. So $h: [0,1] \\times [-AB,AB] \\to \\mathbb{R}$ is uniformly continuous. \\\\\n\tFix $\\varepsilon >0$. Then there exists a $\\delta = \\delta (\\varepsilon) >0$ such that\n\t\\[\n\t\t\\abs{h(y_1,z_1)-h(y_2,z_2)} < \\frac{\\varepsilon}{A}\n\t\\] \n\tfor $\\abs{(y_1,z_1)-(y_2,z_2)} < \\delta $. For $f_1,f_2 \\in F$ with\n\t\\[\n\t\t\\norm{f_1-f_2} < \\delta.\n\t\\]\n\tWe have \n\t\\begin{align*}\n\t\t\\abs{T(f_1)(x)-T(f_2)(x)} &= \\abs{\\int_{0}^{1}k(x,y)(h(y,f_1(y))-h(y,f_2(y))) \\,\\mathrm{d}y} \\\\\n\t\t&\\leq  \\int_{0}^{1}\\underset{\\leq A}{\\underbrace{\\abs{k(x,y)}}}\\underset{< \\frac{\\varepsilon}{A}}{\\underbrace{\\abs{h(y,f_1(y))-h(y,f_2(y))}}} \\,\\mathrm{d}y < \\varepsilon.\n\t\\end{align*}\n\tConclusion: $T: F \\to F$ is continuous. \n\t\\item[Step 5:] Apply Schauder's fixed point theorem.\n\t\\end{description}\n\\end{beispiel}\n\\subsection{Completion of normed spaces} \n\\label{sub:completion_of_normed_spaces}\n$(E,\\norm{.})$ normed spaces. We say that $(\\tilde E, \\norm{.}_*)$ is a completion of $(E,\\norm{.})$ if $(\\tilde E, \\norm{.}_*)$ is a normed space such that\n\\begin{enumerate}[(1)]\n\t\\item $\\exists\\, \\Phi: E \\to \\tilde E$ injective and linear.\n\t\\item $\\norm{x} = \\norm{\\Phi(x)}_*$ for all $x \\in E$.\n\t\\item $\\Phi(E)$ is dense in $\\tilde E$.\n\t\\item $(\\tilde E, \\norm{.}_*)$ is a Banach space.\n\\end{enumerate}\n\\minisec{Construction:}\nLet $(x_n)_{n=1}^{\\infty}$ and $(y_n)_{n=1}^{\\infty}$ be Cauchy sequences in $(E,\\norm{.})$. We say that $(x_n)_{n=1}^{\\infty}$ and $(y_n)_{n=1}^{\\infty}$ are equivalent, denoted by $(x_n) \\sim (y_n)$, if \n\\[\n\t\\norm{x_n-y_n} \\to 0, \\qquad n \\to \\infty.\n\\]\nSet \\[\n\t\\tilde E= \\set[ \\left((x_n) \\right)_N]{(x_n)_{n=1}^{\\infty} \\text{ Cauchy sequence in } (E,\\norm{.})}.\n\\]\nVector space structure:\n\\[\n\t\\begin{cases}\n\t\t[(x_n)]_N + [(\\tilde x_n)]_N &= [(x_n + \\tilde x_n)]_N \\\\\n\t\t\\lambda [(x_n)]_N &= [(\\lambda x)_n]_N.\n\t\\end{cases}\n\\]\nShow that these definitions are well-defined, i.e. independent of the choice of representative norm\n\\[\n\t\\norm{ [(x_n)]_N}_* = \\lim_{n \\to \\infty} \\norm{x_n}.\n\\]\nNote \\[\n\t(x_n) \\sim (y_n)\n\\]\nimplies\n\\[\n\t\\lim_{n \\to \\infty}\\norm{x_n} = \\lim_{n \\to \\infty} \\norm{y_n}.\n\\]\nSince\n\\[\n\t\\abs{\\norm{x_n}- \\norm{y_n}} \\leq \\norm{x_n-y_n} \\to 0, \\qquad n \\to \\infty\n\\]\nCheck that the axioms for being a norm are satisfied. \\\\\nNow we have $(\\tilde E,\\norm{.}_*)$ is a normed space. \\\\\nDefine $\\Phi$: For $x \\in E$ set $\\Phi(x) = \\left[ (x)_{n=1}^{\\infty} \\right]_N$ where \n\\[\n\t(x)_{n=1}^{\\infty} = (x,x,x, \\dots).\n\\]\n\\begin{description}\n\\item[Claim 1 \\& 2:] easy to prove. \n\\item[Claim 3:] $\\Phi(E)$ dense in $(\\tilde E,\\norm{.}_*)$. Fix $\\left[ (x_n) \\right]_N \\in \\tilde E$. Consider $\\Phi(x_k)$ where $x_k$ is the element in the $k$-th position in the sequence $(x_1,x_2, \\dots,x_n, \\dots)$.\n\\begin{align*}\n\t\\norm{\\left[ (x_n) \\right]_N - \\Phi(x_k)}_* = \\lim_{n \\to \\infty}\\norm{x_n - x_k} \\to 0 \\qquad k \\to \\infty.\n\\end{align*}\nSince $(x_n)_{n=1}^{\\infty}$ is a Cauchy sequence. \\\\\n\\item[Claim 4:] $(\\tilde E, \\norm{.}_*)$ is a Banach space.\\\\\nConsider a Cauchy sequence $z_n \\in \\tilde E$ such that $\\norm{z_n - z} \\to 0$ as $n \\to \\infty$. \\\\\nTo show: There exists $z \\in \\tilde E$ such that \n\\[\n\t\\norm{z_n - z} \\to 0, \\qquad n \\to \\infty.\n\\]\nBy 3 we have that $\\Phi(E)$ is dense in $ \\tilde E$ so for $n=1,2,\\dots$ there exists $x_n \\in E$, $n=1,2,\\dots$ such that\n\\[\n\t\\norm{z_n - \\Phi(z_n)} < \\frac{1}{n}, \\qquad  n=1,2,\\dots.\n\\]\nSet $z=: \\left[ (x_n) \\right]_N$. \\\\\nNeed to show that $(x_n)_{n=1}^{\\infty}$ is a Cauchy sequence\n\\begin{align*}\n\t\\norm{x_n - x_m} &= \\norm{\\Phi(x_n)-\\Phi(x_m)}_* \\\\\n\t& \\leq  \\norm{\\Phi(x_n)- z_n}_* + \\norm{z_n-z_m}_* + \\norm{z_m - \\Phi(x_m)}_* \\\\\n\t&< \\frac{1}{n} + \\norm{z_n-z_m} + \\frac{1}{m} \\to 0, \\qquad n,m \\to \\infty.\n\\end{align*}\nConclusion: $(x_n)_{n=1}^{\\infty}$ is a Cauchy sequence in $(E, \\norm{.})$. Remains to show:\n\\[\n\t\\norm{z_n-z}_* \\to 0, \\qquad n \\to \\infty\n\\]\n\\[\n\t\\norm{z_n - z}_* \\leq \\underset{< \\frac{1}{n}}{\\underbrace{\\norm{z_n - \\Phi(x_n)}_*}} + \\underset{= \\lim_{n \\to \\infty}\\norm{x_n-x_m}}{\\underbrace{\\norm{\\Phi(x_n)-z}_*}} \\to 0, \\qquad n \\to \\infty.\n\\]\n\\end{description}\n\nConsider $ f \\in C([0,1])$\n\\begin{itemize}\n\t\\item max-norm: $\\norm{f} = \\max_{x \\in [0,1]}\\abs{f(x)}$. Then $(C([0,1]),\\norm{.})$ is a Banach space.\n\t\\item $p \\geq 1:$\n\t\\[\n\t\t\\norm{f}_{L^p} = \\left( \\int_{0}^{1}\\abs{f(x)}^p \\,\\mathrm{d}x \\right)^{\\frac{1}{p}} \n\t\\]\n\tdefines a norm for $C([0,1])$.\n\\end{itemize}\n\\begin{bemerkung}\n\t\\begin{itemize}\n\t\t\\item Consider piecewise linear $f_n \\in C([0,1])$ for $n =1,2, \\dots$\n\t\t\\[\n\t\t\tf_n(x) = \\begin{cases}\n\t\t\t\t1, &\\text{ if } \\frac{1}{2} \\leq x \\leq 1 \\\\\n\t\t\t\t0, &\\text{ if } x \\leq \\frac{1}{2} - \\frac{1}{2n}\n\t\t\t\\end{cases}\n\t\t\\]\n\t\twith\n\t\t\\[\n\t\t\t\\norm{f_n-f_m}_{L^1} \\leq \\frac{1}{2} \\frac{1}{\\min(m,n)} \\to 0, \\qquad n,m \\to \\infty.\n\t\t\\]\n\t\tSo $(f_n)_{n=1}^{\\infty}$ is a Cauchy sequence in $(C([0,1]),\\norm{.}_{L^1})$ but $(f_n)_{n=1}^{\\infty}$ does not converge in $(C([0,1]),\\norm{.}_{L^1})$ since\n\t\tif $\\norm{f_n - f}_{L^1} \\to 0$ as $n \\to \\infty$ and $f \\in C([0,1])$ then\n\t\t\\[\n\t\t\tf(x) = \\begin{cases}\n\t\t\t\t0, &\\text{ if }x \\in [0,\\frac{1}{2})\\\\\n\t\t\t\t1, &\\text{ if }x \\in [\\frac{1}{2},1]\n\t\t\t\\end{cases}.\n\t\t\\]\n\t\tConclusion: $(C([0,1]), \\norm{.}_{L^1})$ is not a Banach space.\n\t\t\\item Consider:\n\t\t\\[\n\t\t\tf(x) = \\begin{cases}\n\t\t\t\t1, &\\text{ if }x = \\frac{1}{2}\\\\\n\t\t\t\t0, &\\text{ if }x \\in [0,1] \\setminus \\set{\\frac{1}{2}}\n\t\t\t\\end{cases}.\n\t\t\\]\n\t\tThen\n\t\t\\[\n\t\t\t\\norm{f}_{L^1} = 0 = \\norm{0}_{L^1}.\n\t\t\\]\n\t\tCompare this with the first axiom for a norm function.\n\t\t\\item Replace $[0,1]$ with $\\mathbb{R}$. For $f : \\mathbb{R} \\to \\mathbb{R}$ set \\[\n\t\t\t\\supp(f) = \\set[x \\in \\mathbb{R}]{f(x) \\neq 0}.\n\t\t\\]\n\t\tSet \n\t\t\\[\n\t\t\tC_0(\\mathbb{R}) = \\set[f \\in C(\\mathbb{R})]{ \\supp(f) \\text{ is compact in }\\mathbb{R}}.\n\t\t\\]\n\t\t\\textbf{Claim:} \\text{    }      $C_0(\\mathbb{R})$ forms a vector space and for every $p \\geq 1$ and $f \\in C_0(\\mathbb{R})$\n\t\t\\[\n\t\t\t\\norm{f}_{L^p} = \\left( \\int_{\\mathbb{R}}^{} \\abs{f(x)}^p \\,\\mathrm{d}x \\right)^{\\frac{1}{p}}\n\t\t\\] defines a norm on $C_0(\\mathbb{R})$. \\\\\n\t\tProblem: $(C_0(\\mathbb{R}), \\norm{.}_{L^p})$ for $p \\geq 1$ are not Banach spaces. \\\\\n\t\t$(L^1(\\mathbb{R}),\\norm{.}_{L^1})$ is a completion of $(C_0(\\mathbb{R}),\\norm{.}_{L^1})$. \\\\\n\t\tNote $A \\subset \\mathbb{R}$ and $A$ bounded. Define\n\t\t\\[\n\t\t\tf_A(x) \\begin{cases}\n\t\t\t\t1, & x \\in A\\\\\n\t\t\t\t0, &\\text{elsewhere}\n\t\t\t\\end{cases}.\n\t\t\\]\n\t\tLebesguesmeasure of $A = \\norm{f_A}_{L^1} = \\mu(f_A)$. $A \\subset \\mathbb{R}$ and $A$ unbounded\n\t\t\\[\n\t\t\t\\mu(A) = \\lim_{n \\to \\infty} \\mu ( A \\cap [-n,n]).\n\t\t\\]\n\t\tWe say that $A \\subset \\mathbb{R}$ is a $0$- set if for all $\\varepsilon >0$ there exist open intervals $I_n$, $n=1,2, \\dots$ such that\n\t\t\\begin{enumerate}[(1)]\n\t\t\t\\item $ A \\subseteq \\bigcup_{n=1}^{\\infty}I_n$,\n\t\t\t\\item $\\sum_{n=1}^{\\infty}$ lenghts of $I_m < \\varepsilon$.\n\t\t\\end{enumerate} \n\t\tIn particular\n\t\t\\[\n\t\t\tA = \\mathbb{Q} = \\set[r_n]{n=1,2,\\dots}\\qquad \\text{is a $0$-set}.\t\n\t\t\\]\n\t\\end{itemize}\n\\end{bemerkung}", "meta": {"hexsha": "98b3bd77f524316abcb81436c282890f44309786", "size": 10674, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "AF/splits/lecture8a.tex", "max_stars_repo_name": "TiKeil/LatexGU", "max_stars_repo_head_hexsha": "556ad083ea9478a99ea17e2c9b4bb22a964045ae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-01T03:52:33.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-01T03:52:33.000Z", "max_issues_repo_path": "AF/splits/lecture8a.tex", "max_issues_repo_name": "TiKeil/LatexGU", "max_issues_repo_head_hexsha": "556ad083ea9478a99ea17e2c9b4bb22a964045ae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "AF/splits/lecture8a.tex", "max_forks_repo_name": "TiKeil/LatexGU", "max_forks_repo_head_hexsha": "556ad083ea9478a99ea17e2c9b4bb22a964045ae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.0403225806, "max_line_length": 280, "alphanum_fraction": 0.5677346824, "num_tokens": 4767, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7407141527750012}}
{"text": "\\subsection{Projection methods}\n\n\\begin{Definition}{galerkin-method}\n  Let $\\mata\\in\\Rnn$ and $\\vb\\vx\\in\\R^n$ with $\\mata\\vx=\\vb$. Then,\n  the vector $\\tilde\\vx\\in\\R^n$ is called the \\define{Galerkin\n    approximation} of $\\vx$ in a subspace $K$ orthogonal to a subspace\n  $L$, if there holds\n  \\begin{align}\n    \\tilde\\vx &\\in K,\\\\\n    \\vb-\\mata\\tilde\\vx &\\perp L.\n                         \\label{eq:krylov:1}\n  \\end{align}\n  This type of approximation is called \\define{Galerkin method}, more\n  specifically \\define{Ritz-Galerkin method} in the case $K=L$ and\n  \\define{Petrov-Galerkin method} in the case $K\\neq L$.\n\\end{Definition}\n\n\\begin{remark}\n  For the case $K=L$ we deduce from the optimization property of\n  orthogonal projections that $\\mata\\tilde x$ in~\\eqref{eq:krylov:1}\n  is the vector in the subspace $\\mata K$ closest to $\\vb$. Thus,\n  $\\tilde\\vx$ minimizes the \\putindex{residual} $\\vb-\\mata\\vy$ over\n  all choices $\\vy\\in K$.\n\n Note that this does not hold for $K\\neq L$.\n\\end{remark}\n\n\\begin{Definition}{projection-step}\n  Given a vector $\\vx^{(k)}\\in\\R^n$ and its residual\n  $\\vb-\\mata\\vx^{(k)}$. Then, we say that the vector\n  $\\vx^{(k+1)}\\in\\R^n$ is obtained by a \\define{projection step}, if\n  \\begin{gather}\n    \\vx^{(k+1)} = \\vx^{(k)} + \\vy,\n  \\end{gather}\n  where after the choice of subspaces $K$ and $L$ the update $\\vy$ is\n  determined by the condition\n  \\begin{align}\n    \\vy&\\in K\\\\\n    \\vr^{(k)} - \\mata\\vy &\\perp L.\n  \\end{align}\n\\end{Definition}\n\n\\begin{Example}{projection-gauss-seidel}\n  The Gauss-Seidel substep is a projection step with the choice\n  \\begin{gather}\n    K=L=\\spann{\\ve_i}.\n  \\end{gather}\n\\end{Example}\n\n\\begin{notation}\n  We will mostly only consider a single step of the method in\n  \\slideref{Definition}{projection-step}. Therefore, we will consider\n  the step from an initial guess $\\vx^{(0)}$ to an approximate solution\n  $\\tilde \\vx$ to simplify the notation.\n\\end{notation}\n\n\\begin{Definition}{projection-method-matrix}\n  Let $\\matv=(\\vv_1,\\dots,\\vv_m)$ and $\\matw=(\\vw_1,\\dots,\\vw_m)$ be bases for\n  the subspaces $K$ and $L$, respectively. Then, the solution\n  $\\tilde \\vx$ to the projection step is determined by $\\vy\\in\\R^m$ and\n  \\begin{align}\n    \\tilde\\vx &= \\vx^{(0)} + \\matv\\vy\\\\\n    \\matw^*\\mata\\matv \\vy &= \\matv^* \\vr^{(0)}.\n  \\end{align}\n  It is thus obtained by solving an $m$-by-$m$ linear system, called\n  the projected system or the \\define{Galerkin\n    equations}. $\\matw^*\\mata\\matv\\in\\R^{m\\times m}$ is the\n  \\define{projected matrix}.\n\\end{Definition}\n\n\\begin{proof}\n  See \\cite[Section 5.1.2]{Saad00}.\n\\end{proof}\n\n\\begin{Theorem}{projected-invertible}\n  Let one of the following conditions hold:\n  \\begin{enumerate}\n  \\item $\\mata$ is symmetric, positive definite and $L=K$.\n  \\item $\\mata$ is invertible and $L = \\mata K$.\n  \\end{enumerate}\n  Then, the projected matrix $\\matw^*\\mata\\matv$ is invertible for any\n  bases $\\matv$ and $\\matw$ of $K$ and $L$, respectively.\n\\end{Theorem}\n\n\\begin{Theorem}{projection-orthogonal-optimal}\n  Let $\\mata\\in\\Rnn$ be symmetric, positive definite. Then,\n  $\\tilde \\vx$ is the result of the orthogonal ($L=K$) projection\n  method with initial vector $\\vx^{(0)}$ if and only if it minimizes\n  the \\putindex{A-norm} of the error over the space $\\vx^{(0)}+K$. Namely, for the\n  solution $\\vx$ of $\\mata\\vx=\\vb$ there holds\n  \\begin{gather}\n    \\norm{\\tilde\\vx-\\vx}_A = \\min_{\\vy\\in\\vx^{(0)}+K} \\norm{\\vy-\\vx}_A.\n  \\end{gather}\n  Here, $\\norm\\vy_A = \\sqrt{\\vy^*\\mata\\vy}$.\n\\end{Theorem}\n\n\\begin{Theorem}{projection-oblique-optimal}\n  Let $\\mata\\in\\Rnn$ and $L=\\mata K$. Then, $\\tilde \\vx$ is the result\n  of the (oblique) projection method with initial vector $\\vx^{(0)}$\n  if and only if it minimizes the Euclidean norm of the residual\n  $\\vb-\\mata\\tilde\\vx$ over the space $\\vx^{(0)}+K$. Namely, there\n  holds\n  \\begin{gather}\n    \\norm{\\vb-\\mata\\tilde\\vx}_2\n    = \\min_{\\vy\\in\\vx^{(0)}+K} \\norm{\\vb-\\mata\\vy}_2\n  \\end{gather}\n\\end{Theorem}\n\n\\begin{Example}{projection-1d}\n  A one-dimensional projection method can be characterized by two\n  vectors $\\vv$ and $\\vw$. Then,\n  \\begin{gather}\n    K = \\spann\\vv,\n    \\qquad L = \\spann\\vw.\n  \\end{gather}\n  The new solution is\n  \\begin{gather}\n    \\tilde\\vx = \\vx^{(0)}+\\alpha \\vv,\n  \\end{gather}\n  where\n  \\begin{gather}\n    \\alpha = \\frac{\\scal(\\vr^{(0)},\\vw)}{\\scal(\\mata\\vv,\\vw)}\n  \\end{gather}\n  is determined from the Galerkin condition $\\vr^{(0)}-\\mata\\vy \\perp \\vw$\n\\end{Example}\n\n\\begin{Algorithm*}{steepest-descent-algol}{The steepest descent method}\n  \\begin{algorithmic}[1]\n    \\Require $\\mata\\in\\Rnn$ s.p.d.; $\\quad\\vx,\\vb\\in\\R^n$\n    \\State $\\vr\\gets \\vb-\\mata\\vx$\n    \\Repeat\n    \\State $\\alpha\\gets\\frac{\\scal(\\vr,\\vr)}{\\scal(\\mata\\vr,\\vr)}$\n    \\State $\\vx \\gets \\vx + \\alpha\\vr$\n    \\State $\\vr \\gets \\vr-\\alpha\\mata\\vr$\n    \\Until convergence\n  \\end{algorithmic}\n\\end{Algorithm*}\n\n\\begin{Lemma}{steepest-descent}\n  Each step of the steepest descent method computes the minimum of\n  $F(\\vy) = \\norm{\\vy-\\vx}_A^2$ along the line from the current\n  iterate $\\vx^{(k)}$ in direction $-\\nabla F(\\vx^{(k)})$.\n\\end{Lemma}\n\n\\begin{remark}\n  In this algorithm, the operation $\\mata\\vr$ is applied twice. Since\n  in most implementations this will be the part with the most\n  computational operations, we introduce an auxiliary vector\n  $\\vp = \\mata\\vr$, which can be used in lines 3 and 5. At the cost of\n  one additional vector, the numerical effort per step is almost\n  cut in half.\n\\end{remark}\n\n\\begin{Remark}{convergence-residual}\n  The residual $\\vr = \\vb - \\mata\\tilde\\vx$ of the current iterate\n  $\\tilde\\vx$ measures the misfit of $\\tilde\\vx$ in the equation\n  $\\mata\\vx = \\vb$. Since the error $\\tilde\\vx-\\vx$ is unknown, we can\n  use it as criterion for the accuracy of the current\n  solution. Indeed, there holds\n  \\begin{gather}\n    \\norm{\\vx-\\tilde\\vx}\n    = \\norm*{\\mata^{-1}\\bigl(\\mata\\vx - \\mata\\tilde\\vx\\bigr)}\n    = \\norm*{\\mata^{-1}\\bigl(\\vb - \\mata\\tilde\\vx\\bigr)}\n    \\le \\norm{\\mata^{-1}}\\norm{\\vr}.\n  \\end{gather}\n  Therefore, the criterion for convergence of the algorithm is typically\n  \\begin{gather}\n    \\norm{\\vr} \\le \\text{TOL},\n  \\end{gather}\n  where TOL is a tolerance chosen by the user.\n\n  Note, that the computation of $\\vr$ is subject to roundoff\n  errors. Thus, the tolerance should always be chosen\n  \\begin{gather}\n    \\text{TOL} > c\\norm{\\vb}\\eps,\n  \\end{gather}\n  where $\\eps$ is the machine accuracy and $c$ should account for\n  error accumulation in the matrix-vector product.\n\\end{Remark}\n\n\\begin{Algorithm*}{steepest-descent-python1}{Steepest descent in Python}\n  \\lstinputlisting{python/steepest-descent.py}\n\\end{Algorithm*}\n\n\\begin{remark}\n  Depending on the quality of the compiler/interpreter, the code line\n  \\begin{lstlisting}[language=Python,numbers=none]\n    x += alpha*r\n  \\end{lstlisting}\n  may involve creating an auxiliary vector $\\vp = \\alpha \\vr$ and\n  adding this vector to $\\vx$.  Obviously, this could be avoided by\n  directly implementing\n  \\begin{lstlisting}[language=Python,numbers=none]\n    for i in range(0,n):\n      x[i] += alpha*r[i]\n  \\end{lstlisting}\n  Since operations like this are ubuquitous in scientific computing,\n  they were standardized early on in the BLAS (basic linear algebra\n  subroutines) library. It contains the FORTRAN function\n  \\begin{lstlisting}[language=Fortran,numbers=none]\n    SUBROUTINE DAXPY( n, alpha, x, incx, y, incy)\n  \\end{lstlisting}\n  which computes $\\vy\\gets\\vy+\\alpha\\vx$ for double precision vectors\n  of length $n$ (the increment arguments allow to skip elements). For\n  usage in Python, there is a wrapper\n  \\begin{lstlisting}[language=Python,numbers=none]\n    scipy.linalg.blas.daxpy(x, y[, n, a, offx, incx, offy, incy])\n  \\end{lstlisting}\n\\end{remark}\n\n\\begin{Algorithm*}{steepest-descent-python2}{Steepest descent with daxpy}\n  \\lstinputlisting{python/steepest-descent-axpy.py}\n\\end{Algorithm*}\n\n\\begin{Algorithm*}{minimal-residual-algol}{The minimal residual method}\n  \\begin{algorithmic}[1]\n    \\Require $\\mata\\in\\Rnn$; $\\quad\\vx,\\vb\\in\\R^n$\n    \\State $\\vr\\gets \\vb-\\mata\\vx$\n    \\Repeat\n    \\State $\\alpha\\gets\\frac{\\scal(\\mata\\vr,\\vr)}{\\scal(\\mata\\vr,\\mata\\vr)}$\n    \\State $\\vx \\gets \\vx + \\alpha\\vr$\n    \\State $\\vr \\gets \\vr-\\alpha\\mata\\vr$\n    \\Until convergence\n  \\end{algorithmic}\n\\end{Algorithm*}\n\n\\begin{Lemma}{minimal-residual}\n  Each step of the minimal method computes the minimum of\n  $F(\\vy) = \\norm{\\vb-\\mata\\vy}_2^2$ along the line from the current\n  iterate $\\vx^{(k)}$ in direction $\\vr$.\n\\end{Lemma}\n\n\\begin{Lemma}{lucky-breakdown}\n  The iteration sequences $\\{\\vx^{(k)}\\}$ of the steppest descent and\nminimal residual methods, respectively, are well defined except for\nthe case where $\\vx^{(k)}$ is the exact solution $\\vx$ and thus\n$\\vr^{(k)} = 0$.\n\nWe refer to this phenomenon as \\define{lucky breakdown}, since the\nmethod only fails after the exact solution has been found.\n\\end{Lemma}\n\n\\begin{Lemma*}{kantorovich-inequality}{Kantorovich inequality}\n  Let $\\mata\\in\\Rnn$ be symmetric, positive definite with minnimal and\n  maximal eigenvalues $\\lambda_{\\min}$ and $\\lambda_{\\max}$. Then, for\n  $\\vx\\in\\R^n$ there holds\n  \\begin{gather}\n    \\frac{\\scal(\\mata\\vx,\\vx)\\scal(\\mata^{-1}\\vx,\\vx)}{\\scal(\\vx,\\vx)^2}\n    \\le \\frac{(\\lambda_{\\min}+\\lambda_{\\max})^2}{4\\lambda_{\\min}\\lambda_{\\max}}\n  \\end{gather}\n\\end{Lemma*}\n\n\\begin{Theorem}{steepest-descent-convergence}\n  Let $\\mata\\in\\R^nn$ be symmetric, positive definite with extremal\n  eigenvalues $\\lambda_{\\min}$ and $\\lambda_{\\max}$. Then, the error\n  $\\ve^{(k)} = \\vx-\\vx^{(k)}$ of the steepest descent method admits\n  the estimate\n  \\begin{gather}\n    \\norm{\\ve^{(k+1)}}_A \\le \\rho \\norm{\\ve^{(k)}}_A,\n  \\end{gather}\n  where the contraction number is\n  \\begin{gather}\n    \\rho\n    = \\frac{\\lambda_{\\max}-\\lambda_{\\min}}{\\lambda_{\\max}+\\lambda_{\\min}}\n    = \\frac{\\cond_2\\mata - 1}{\\cond_2\\mata+1}\n    = 1-\\frac2{\\cond_2\\mata+1}\n  \\end{gather}\n\\end{Theorem}\n\n\\begin{Theorem}{minimal-residual-convergence}\n  Let $\\mata\\in\\Rnn$ such that its symmetric part $(\\mata+\\mata^T)/2$\n  is positive definite. Then, the residuals $\\vr^{(k)}$ of the minimal\n  residual method admit the estimate\n  \\begin{gather}\n    \\norm{\\vr^{(k+1)}}_2 \\le \\rho \\norm{\\vr^{(k)}}_2,\n  \\end{gather}\n  where the contraction number is\n  \\begin{gather}\n    \\rho = \\left(1-\\frac{\\norm{\\mata}^2}{\\sigma^2}\\right)^{\\nicefrac12}\n  \\end{gather}\n  and $\\sigma$ is the smallest eigenvalue of $(\\mata+\\mata^T)/2$.\n\\end{Theorem}\n\n\\begin{remark}\n  Let $e_k$ be some measure of the error of a fixed-point iteration\n  with contraction number $\\rho$ after $k$ steps. Then, there holds\n  \\begin{gather}\n    e_k \\le \\rho^k e_0.\n  \\end{gather}\n  Thus, the number of steps needed to obtain a (relative) reduction of\n  the error by a prescribed relative tolerance $\\epsilon$, that is, to\n  achieve $e_k/e_0\\le\\epsilon$, is\n  \\begin{gather}\n    \\label{eq:krylov:steps-convergence}\n    k \\ge \\frac{\\log\\epsilon}{\\log\\rho}.\n  \\end{gather}\n  From this formula, we realize that the number of steps of such a\n  method grows linearly with the logarithm of the tolerance. Further,\n  it is inverse proportional to the logarithm of the contraction\n  number $\\rho$.\n\n  Note that logarithms with respect to any base can be used\n  in~\\eqref{eq:krylov:steps-convergence}, since the quotient is\n  independent of the base.\n\\end{remark}\n\n\\begin{Definition}{convergence-rate-logarithmic}\n  The (logarithmic) \\define{convergence rate} of a contraction with\n  \\putindex{contraction number} $\\rho$ is\n  \\begin{gather}\n    r_c = -\\log_{10} \\rho.\n  \\end{gather}\n\n  The average \\define{observed convergence rate} of $k$ steps of a\n  method with error measure $e_k$ is\n  \\begin{gather}\n    \\overline{r_c} = \\frac1k \\log_{10}\\frac{e_0}{e_k}.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{remark}\n  The logarithmic convergence rate allows us to directly compare two\n  iterative methods. Let's say, there are two iterations $M_1$ and\n  $M_2$ and the convergence rate of $M_2$ ist twice the rate of\n  $M_1$. Then, given an initial vector, $M_1$ will need twice as many\n  steps compared to $M_2$ to reach the same accuracy.\n\n  This implies that $M_2$ is favorable, if the effort for each step is\n  less than twice the effort for $M_1$. If it is more than twice, then\n  $M_1$ is the faster method in spite of the slower convergence.\n\\end{remark}\n\n\\subsection{Krylov spaces}\n\n\\begin{Definition}{krylov-space}\n  For a matrix $\\mata\\in\\Rnn$ and a vector $\\vv\\in\\R^n$, we define the\n  \\define{Krylov space}\n  \\begin{gather}\n    \\krylov_m = \\krylov_m(\\mata,\\vv)\n    = \\spann{\\vv,\\mata\\vv,\\dots,\\mata^{m-1}\\vv}.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Definition}{grade-of-v}\n  For a matrix $\\mata\\in\\Rnn$ and a vector $\\vv\\in\\R^n$ we define the\n  \\define{grade} of $\\vv$, more precise the grade of $\\vv$ with\n  respect to $\\mata$ as the minimal grade of a polynomial $p$ such\n  that\n  \\begin{gather}\n    p(\\mata)\\vv = 0\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Lemma}{krylov-invariant}\n\\end{Lemma}\n\\begin{Lemma}{krylov-polynomial}\n  The Krylov space $\\krylov_m(\\mata,\\vv)$ is isomorphic to $\\P_{m-1}$\n  if and only if the grade of $\\vv$ with respect to $\\mata$ is at\n  least $m$. In particular, for any $\\vw\\in\\krylov_m(\\mata,\\vv)$ there\n  is a unique polynomial $p\\in\\P_{m-1}$ such that\n  \\begin{gather}\n    \\vw = p(\\mata)\\vv.\n  \\end{gather}\n\n  It is invariant under the action of $\\mata$ if and only if the grade\n  of $\\vv$ does not exceed $m$.\n\\end{Lemma}\n\n\\begin{proof}\n  See \\cite[Propositions 6.1 \\& 6.2]{Saad00}.\n\\end{proof}\n\n\\begin{Lemma}{krylov-projector}\n  Let $\\matq_m$ be a projector onto $\\krylov_m$ and define\n  \\begin{align}\n    \\mata_m\\colon \\krylov_m &\\to \\krylov_m\\\\\n    \\vv&\\mapsto \\matq_m \\mata.\n  \\end{align}\n  Then, for any polynomial $q\\in\\P_{m-1}$ there holds\n  \\begin{gather}\n    q(\\mata)\\vv = q(\\mata_m)\\vv.\n  \\end{gather}\n  For any polynomial $p\\in\\P_m$, there holds\n  \\begin{gather}\n    \\matq_m p(\\mata)\\vv = p(\\mata_m)\\vv\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  See \\cite[Proposition 6.3]{Saad00}.\n\\end{proof}\n\n\\subsection{The Arnoldi procedure}\n\n\\begin{Algorithm*}{arnoldi-1}{Arnoldi I}\n  \\algtext*{EndIf}\n  \\begin{algorithmic}[1]\n    \\Require $\\mata\\in\\Rnn$; $\\quad\\vv_1\\in\\R^n, \\norm{\\vv_1}_2 = 1$\n    \\For{$j=1,\\dots,m$}\n    \\For{$i=1,\\dots,j$}\n    \\State $h_{ij} \\gets \\scal(\\mata\\vv_j,\\vv_i)$\n    \\EndFor\n    \\State $\\vw_j \\gets \\mata \\vv_j-\\sum_{i=1}^j h_{ij}\\vv_i$\n    \\State $h_{j+1,j} \\gets \\norm{\\vw_j}_2$\n    \\If{$h_{j+1,j}=0$} \\textbf{stop}\\EndIf\n    \\State $\\vv_{j+1} = \\nicefrac{\\vw_j}{h_{j+1,j}}$\n    \\EndFor\n  \\end{algorithmic}\n\\end{Algorithm*}\n\n\\begin{Lemma}{arnoldi-krylov}\n  Assume that the Arnoldi algorithm does not stop before step\n  $m$. Then, the vectors $\\vv_1,\\dots,\\vv_m$ form an orthonormal basis\n  of $\\krylov_m(\\mata,\\vv_1)$.\n\\end{Lemma}\n\n\\begin{proof}\n  See \\cite[Proposition 6.4]{Saad00}.\n\\end{proof}\n\n\\begin{Theorem}{arnoldi-projection}\n  Let $\\matv_m = (\\vv_1,\\dots,\\vv_m)$ be the matrix of basis vectors\n  generated by the Arnoldi method and let\n  $\\overline{\\matH}_m\\in\\R^{m+1\\times m}$ be the Hessenberg matrix of\n  entries $h_{ij}$ computed in the algorithm. Let further\n  $\\mathH_m\\in\\R^{m\\times m}$ be the same matrix without the last\n  row. Then, there holds\n  \\begin{align}\n    \\mata\\matv_m &= \\matv_m\\matH_m+\\vw_m\\ve_m^T\\\\\n                 &= \\matv_{m+1}\\overline{\\matH}_m\\\\\n  \\end{align}\n  and\n  \\begin{gather}\n    \\matH_m = \\matv_m^T\\mata\\matv.\n  \\end{gather}\n\\end{Theorem}\n\n\\begin{proof}\n  See \\cite[Proposition 6.5]{Saad00}.\n\\end{proof}\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "64bd290c9d900d0e1026a37a721554323a7a29ca", "size": 15558, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nla/krylov.tex", "max_stars_repo_name": "guidokanschat/notes", "max_stars_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "nla/krylov.tex", "max_issues_repo_name": "guidokanschat/notes", "max_issues_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-05-24T07:31:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-31T12:58:14.000Z", "max_forks_repo_path": "nla/krylov.tex", "max_forks_repo_name": "guidokanschat/notes", "max_forks_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-05-15T19:28:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-05T19:07:29.000Z", "avg_line_length": 34.9617977528, "max_line_length": 82, "alphanum_fraction": 0.6742511891, "num_tokens": 5315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152498, "lm_q2_score": 0.9032942112597332, "lm_q1q2_score": 0.7406049121316661}}
{"text": "\\section{Electricity}\n  \\subsection{Electrostatics}\n  Electric charge is a property of some objects that allow such objects to feel an electric force. The units for charge are coulombs (C). The smallest amount of charge an object can have is the elementary charge: $e=1.602*10^{-19}C$. For an electron, this is -e, while for a proton it is +e. As everyone knows, like charges repel, and opposite charges attract each other.\\par \n  Any material we use is made of atoms, which themselves are made of charge. There are two different types of materials, insulators and conductors. For insulators, atomic/molecular electrons are stuck in place with their parent atom/molecule and their electrons are immobile. For conductors, the atomic/molecular electrons are shared among the material (these are also known as mobile electrons). Our typical insulators are wood, plastic, and printer paper, while typical conductors are metal, water, and humans.\\par\n  \\begin{align*}\n    \\text{The force that charge } q_1 \\text{ exerts on charge} q_2 \\text{ is: (Coulombs law)}\\\\\n    \\vec{F_{1\\to2}}(r_{1\\to2})=\\frac{1}{4\\pi \\epsilon_0}\\frac{q_1q_2}{r_{1\\to2}^2}\\hat{r_{1\\to2}}\\\\\n    \\text{Where } \\epsilon_0=8.85*10^{-12}\\frac{C^2}{Nm^2}\n  \\end{align*}\n  \\subsubsection{Example}\n  Find the net force on $q_c$ due to $q_a$ and $q_b$ where $q_a+q_b$ are fixed in space. Remeber that forces are vectors.\n  \\begin{align*}\n    \\vec{F_{net_c}}&=\\vec{F_{bc}}+\\vec{F_{ac}}\\\\\n    &=\\frac{1}{4\\pi\\epsilon_0}\\frac{q_bq_c}{r_{bc}^2}\\hat{r_{bc}}+\\frac{1}{4\\pi\\epsilon_0}\\frac{q_bq_c}{r_{ac}^2}\\hat{r_{ac}}\\\\\n    &=\\frac{1}{4\\pi\\epsilon_0}\\frac{q_bq_c}{X_0^2}(\\hat{+i})+\\frac{1}{4\\pi\\epsilon_0}\\frac{q_aq_c}{Y_0^2}(\\hat{+j})\\\\\n    &=\\frac{1}{4\\pi\\epsilon_0}\\left(\\frac{q_bq_c}{x_0^2}\\hat{i}+\\frac{q_bq_c}{y_0^2}\\hat{j}\\right)\\\\\n    \\text{if } q_b=q_a \\text{ and } x_0=y_0 \\text{, then }\\\\\n    \\vec{F_{net_c}}&=\\frac{q_aq_c}{4\\pi\\epsilon_0x_0^2}(\\hat{i}+\\hat{j})\\\\\n  \\end{align*}\\\n  Coulombs law works with super position:\n  \\begin{equation*}\n    \\vec{F_{1\\to2}}=\\frac{1}{4\\pi\\epsilon_0}\\frac{q_1q_2}{r_{1\\to2}^2}\\hat{r_{1\\to2}}\n  \\end{equation*}\n  Find the force on charge $Q_A$ due to other stationary charges:\n  \\begin{align*}\n    \\vec{F_{ba}}&=\\frac{1}{4\\pi\\epsilon_0}\\frac{q_aq_b}{r_{ba}}\\hat{r_{ba}}\\\\\n    &=\\frac{1}{4\\pi\\epsilon_0}\\frac{q_aq_b}{y_0^2}\\hat{j}\\\\\n    \\vec{F_{ca}}&=\\frac{1}{4\\pi\\epsilon_0}\\frac{q_aq_c}{r_{ca}^2}\\hat{r_{ca}}\\\\\n    &=\\frac{q_cq_a}{4\\pi\\epsilon_0}\\left[\\frac{1}{r_{ca}^2}sin(\\theta)(\\hat{i})+\\frac{1}{r_{ca}^2}cos(\\theta)(-\\hat{j})\\right]\\\\\n    &=\\frac{q_cq_a}{r\\pi\\epsilon_0}\\left[\\frac{1}{x_0^2+y_0^2}\\frac{x_0}{\\sqrt{x_0^2+y_0^2}}\\hat{i}-\\frac{1}{\\sqrt{x_0^2+y_0^2}}\\frac{y_0}{\\sqrt{x_0^2+y_0^2}}\\hat{j}\\right]\\\\\n    &=\\frac{q_cq_a}{4\\pi\\epsilon_0}\\frac{1}{(x_0^2+y_0^2)^{\\frac{3}{2}}}(x_0\\hat{i}-y_0\\hat{j})\\\\\n    \\text{Now find }f_{net_a}&=F_{ca}+F_{ba}\\\\\n    &=(F_{ba_x}+F_{ca_x})\\hat{i}+(F_{ba_y}+F_{ca_y})\\hat{j}\\\\\n    F_{net_a}&=\\frac{1}{4\\pi\\epsilon_0}\\left[\\frac{q_cq_a}{(x_0^2+y_0^2)^{\\frac{3}{2}}}x_0\\hat{i}+\\left(\\frac{q_bq_a}{y_0}-\\frac{q_cq_a}{(x_0^2+y_0^2)^{\\frac{3}{2}}}y_o\\right)\\hat{j}\\right]\\\\\n  \\end{align*} \n  \\subsection{Electric Fields}\n  A field is a function that has different values throughout space that can be changed in time. Temperature is a scalar field when looking at the temperature around a room. Wind patterns are a vector field on a weather map. We will study the electric field $\\vec{E}$. This field helps us find the force exerted on any charge Q.\n  \\begin{equation*}\n    \\vec{F}=Q\\vec{E}\n  \\end{equation*}\n  The field $\\vec{E}$ created by a charge q is:\n  \\begin{equation*}\n    \\vec{E}=\\frac{1}{4\\pi\\epsilon_0}\\frac{q}{r^2}\\hat{r}\\\\\n  \\end{equation*}\n  This field acts on another charge Q such that:\n  \\begin{align*}\n    \\vec{F}&=Q\\vec{E}\\\\\n    &=Q\\frac{1}{4\\pi\\epsilon_0}\\frac{q}{r^2}\\hat{r}\\\\\n    \\vec{F}&=\\frac{1}{4\\pi\\epsilon_0}\\frac{qQ}{r^2}\\hat{r} \\text{ (Coulombs Law)}\\\\\n  \\end{align*}\n  $\\vec{E}$ Fields point away from positive cherges and towards negative ones. Since $\\vec{E}$ is a vector, if two or more static charges each create a field, the net field is their vector sum (superposition).\n  \\begin{equation*}\n    \\vec{E_{net}}=\\sum_{i=1}^n\\vec{E_i}\n  \\end{equation*}\n  \\subsubsection{Example 1}\n  Two identical charges $q_1=q_2=q$ are equidistant from the origin on the x-axis. Find $\\vec{E}$ anywhere on the x-axis.\n  \\begin{align*}\n    \\vec{E}&=2\\left(\\frac{1}{4\\pi\\epsilon_0}\\frac{q_2}{r_2^2}cos\\theta\\right)\\hat{k}\\\\\n    &=2\\frac{1}{4\\pi\\epsilon_0}\\frac{2qz}{\\left(z^2+\\left(\\frac{L}{2}\\right)^2\\right)^{\\frac{3}{2}}}\\hat{k}\\\\\n    \\vec{E}(z)&=\\frac{1}{4\\pi\\epsilon_0}\\frac{2qz}{\\left(z^2+\\left(\\frac{L}{2}\\right)^{\\frac{3}{2}}\\right)}\\hat{K}\n  \\end{align*}\n  What if the charges that make a field are grouped together closely? Then we will describe those charges as a continuous distribution. Linear charge density is $\\lambda=\\frac{dq}{dl}\\to dq=\\lambda dl$. Recall,\n  \\begin{align*}\n    \\vec{E}&=\\frac{1}{4\\pi\\epsilon_0}\\frac{q}{r^2}\\hat{r}\\\\\n    &=\\sum_{i=1}^N\\frac{1}{4\\pi\\epsilon_0}\\frac{q_i}{r_i^2}\\hat{r_i}\\to \\vec{E}=\\frac{1}{4\\pi\\epsilon_0}\\int\\frac{dq}{r^2}\\hat{r}\\\\\n    \\text{For this problem: }\\\\\n    E&=\\frac{1}{r\\pi\\epsilon_0}\\int_{\\frac{-L}{2}}^{\\frac{L}{2}}\\frac{\\lambda dx}{z^2+x^2}\\frac{z}{\\sqrt{z^2+x^2}}\\hat{k}\\\\\n    &=\\frac{1}{r\\pi\\epsilon_0}\\lambda z \\int_{\\frac{-L}{2}}^{\\frac{L}{2}}\\frac{dx}{(z^2+x^2)^{\\frac{3}{2}}}\\hat{k}\\\\\n    &=\\frac{1}{4\\pi\\epsilon_0}\\lambda z \\left(\\frac{x}{z^2\\sqrt{x^2+z^2}}\\right)\\Big|_{\\frac{-L}{2}}^{\\frac{L}{2}}\\hat{k}\\\\\n    &=\\frac{1}{4\\pi\\epsilon_0}\\lambda z \\left[\\frac{\\frac{L}{2}-\\frac{-L}{2}}{z^2\\sqrt{\\frac{L}{2}^2+z^2}}\\right]\\hat{k}\\\\\n    &=\\frac{1}{4\\pi\\epsilon_0}2\\lambda z\\frac{\\frac{L}{2}}{z^2\\sqrt{\\frac{L}{2}^2+z^2}}\\hat{k}\n  \\end{align*}\n  If the line of charge is $\\inf$ in length, then the only change would be the bounds of the integral.\n  \\subsubsection{Example 2}\n  Find $\\vec{E}$ where the midpoint of a uniform line of charge as shown. The X components cancel.\n  \\begin{align*}\n    d\\vec{E}&=\\frac{1}{4\\pi\\epsilon_0}\\frac{dq}{r^2}\\hat{r}\\\\\n    \\lambda&=\\frac{dq}{dl}=\\frac{dq}{dx}\\\\\n    dq&=\\lambda dx\\\\\n    \\text{We see that } E_x=0 \\text{ while } E_z\\neq 0 \\text{ then, }\\\\\n    d\\vec{E}&=\\frac{1}{4\\pi\\epsilon_0}\\frac{\\lambda dx}{x^2+z^2}\\frac{z}{\\sqrt{x^2+z^2}}\\hat{k}\\\\\n    &=\\frac{1}{4\\pi\\epsilon_0}\\frac{\\lambda dxz}{(x^2+z^2)^{\\frac{3}{2}}}\\hat{k}\\\\\n    E&=\\int_{\\frac{-L}{2}}^{\\frac{L}{2}}\\frac{1}{4\\pi\\epsilon_0}\\frac{\\lambda dxz}{(x^2+z^2)^{\\frac{3}{2}}}\\\\\n    &=\\frac{\\lambda z}{4\\pi\\epsilon_0}\\int_{\\frac{-L}{2}}^{\\frac{L}{2}}(x^2+z^2)^{\\frac{-3}{2}}dx\\\\\n    \\vec{E}(z)&=\\frac{2\\lambda z}{4\\pi\\epsilon_0}\\frac{\\frac{L}{2}}{z^2\\sqrt{\\frac{L}{2}^2+z^2}}\\hat{k}\n  \\end{align*}\n  \\subsubsection{Example 3}\n  Find $\\vec{E}$ for the sitution shown:\n  \\begin{align*}\n    d\\vec{E}&=\\frac{1}{4\\pi\\epsilon_0}\\frac{dq}{r^2}\\hat{r}\\\\\n    &=\\frac{1}{4\\pi\\epsilon_0}\\frac{\\lambda dx}{r^2}\\left(cos\\theta\\hat{i}+sin\\theta\\hat{k}\\right)\\\\\n    &=\\frac{\\lambda}{4\\pi\\epsilon_0}\\left[\\int_{0}^{L}\\frac{dx(x-L)}{(z^2+(x-L))^{\\frac{3}{2}}}\\hat{i}+\\int_0^L\\frac{dxz}{(z^2+(x-L))^{\\frac{3}{2}}}  \\right]\\\\\n    \\shortintertext{We will let x'=x-l } x=0\\to x'=0-L=-L\\\\\n    x=L\\to x'=0\\\\\n    dx'=dx-dL \\text{ because } L=const\\\\\n    &=\\frac{\\lambda}{4\\pi\\epsilon_0}\\left[\\int_{-L}^0\\frac{dx'x'}{(z^2+x'^2)^{\\frac{3}{2}}}\\hat{i}+\\int_{-L}^0\\frac{dx'z}{(z^2+x'^2)^{\\frac{3}{2}}}\\hat{k}\\right]\\\\\n    \\vec{E}&=\\frac{\\lambda}{4\\pi\\epsilon_0}\\left[\\frac{x'}{x'^2\\sqrt{x^2+z^2}}\\Big|_{x'=L}^{x'=0}\\hat{i}+\\frac{-1}{\\sqrt{x^2+z^2}}\\Big|_{x'=-L}^{x'=0}\\hat{k}\\right]\n  \\end{align*}\n  \\subsection{Electric Field Lines}\n  We can draw field lines to represent how an electric field looks in space. Recall that for a point charge, $\\vec{E}=\\frac{1}{4\\pi\\epsilon_0}\\frac{q}{r^2}\\hat{r}$\n  \\newline\n  Let's find $\\vec{E}$ above the midpoint of two opposite charges +q and -q which are a distance d apart.\n  \\begin{align*}\n    r^2&=z^2+\\left(\\frac{d}{2}\\right)^2\\\\\n    \\vec{E}&=\\vec{E}_-\\vec{E}_+\\\\\n    &=\\frac{1}{4\\pi\\epsilon_0}\\frac{q}{z^2+\\frac{d}{2}}\\left(-\\frac{\\frac{d}{2}}{\\sqrt{z^2+\\frac{d}{2}^2}}\\hat{i}-\\frac{z}{\\sqrt{z^2+\\frac{d}{2}^2}}\\hat{k}\\right)+\\frac{1}{4\\pi\\epsilon_0}\\frac{q}{z^2+\\frac{d}{2}}\\left(-\\frac{\\frac{d}{2}}{z^2}\\hat{i}+\\frac{z}{\\sqrt{z^2+\\frac{d}{2}^2}}\\hat{k}\\right)\\\\\n    \\vec{E}&=-\\frac{1}{4\\pi\\epsilon_0}\\frac{qd}{\\left(z^2+\\frac{d}{2}^2\\right)^{\\frac{3}{2}}}\\hat{i}\\\\\n    \\shortintertext{Consider $\\vec{p}=q\\vec{d}$. This is an electric dipole moment.}\\\\\n    \\vec{E}&=-\\frac{1}{r\\pi\\epsilon_0}\\frac{\\vec{p}}{\\left(z^2+\\frac{d}{2}^2\\right)^{\\frac{3}{2}}}\\\\ \n    \\shortintertext{As you get further from the dipole, z$>>$d:}\\\\ \n    \\vec{E}&\\cong-\\frac{1}{4\\pi\\epsilon_0}\\frac{\\vec{p}}{(z^2)^{\\frac{3}{2}}}\\\\\n    \\shortintertext{If you get very far away: $z\\to\\infty$ or $\\frac{d}{2}\\to\\infty$}\\\\\n    \\vec{E}&=\\frac{-1}{4\\pi\\epsilon_0}\\frac{qd}{\\left(z^2+\\frac{d}{2}\\right)^{\\frac{3}{2}}}\\hat{i} =\\frac{-1}{4\\pi\\epsilon_0}\\frac{q\\left(\\frac{d}{z}\\right)}{\\left(1+\\frac{d}{2}\\right)^{\\frac{3}{2}}}\\hat{i}\\\\\n  \\end{align*}\n  For dipoles in an external field, $\\vec{p}=q\\vec{d}$. The net displacement force on $\\vec{p}$ is 0, but it will have torque.\n  \\begin{align*}\n    \\tau=\\vec{r}\\times\\vec{F}=\\left(\\vec{\\frac{d}{2}}\\times\\vec{F_+}\\right)+\\left(\\vec{\\frac{d}{2}}\\times\\vec{F_-}\\right)&=\\left(\\vec{\\frac{d}{2}}\\times q\\vec{E_{ext}}\\right)+\\left(-\\vec{\\frac{d}{2}}\\times q\\vec{E_{ext}}\\right)\\\\\n    &=2\\left(\\vec{\\frac{d}{2}}\\times q\\vec{E_{ext}}\\right)\\\\\n    \\vec{\\tau}&=(\\vec{q}d\\times \\vec{E_{ext}})\\\\\n    \\alignedbox{\\vec{\\tau}}{=\\vec{P}\\times\\vec{E_{ext}}}\\\\\n  \\end{align*}\n  \\subsubsection{Example 1.}\n  The field $\\vec{E}$ is above the center of a uniformly charged ring is $\\vec{E}=\\frac{1}{r\\pi\\epsilon_0}\\frac{Qz}{(z^2+k^2)^{\\frac{3}{2}}}\\hat{k}$. Now let the ring isntead, be a disk with toal charge Q that is uniformly distributed.\n  \\begin{align*}\n    \\shortintertext{Total charge Q over a total area of $\\pi R^2$}\\\\\n    \\frac{Q}{\\pi R^2}&=\\sigma\\\\\n    dQ&=\\sigma2\\pi rdr\\\\\n    dE&=\\frac{1}{4\\pi\\epsilon_0}\\frac{dQ}{r^2}\\hat{r}\\\\\n    dQ&=\\sigma 2\\pi r'dr'\\\\\n    \\shortintertext{All of the x and y components vanish, which leaves us with:}\\\\\n    \\int dE&=\\int\\frac{1}{4\\pi\\epsilon_0}\\frac{\\sigma 2\\pi r'dr'}{r'^2+z^2}\\frac{z}{\\sqrt{r'^2+z^2}}\\hat{k}\\\\\n    \\vec{E}&=\\frac{1}{4\\pi\\epsilon_0}2\\pi\\sigma z \\int_0^R\\frac{r'dr'}{(r'^2+z^2)^{\\frac{3}{2}}}\\hat{k}\\\\\n    &=\\frac{1}{4\\pi\\epsilon_0}2\\pi\\sigma z \\left(-\\frac{1}{\\sqrt{r'^2+z^2}}\\right)\\Big|_{r'=0}^{r'=R}\\\\\n    &=\\frac{1}{4\\pi\\epsilon_0}2\\pi\\sigma z \\left[-\\frac{1}{R^2+z^2}-\\frac{1}{z}\\right]\\hat{k}\\\\\n    \\alignedbox{\\vec{E}}{=\\frac{1}{4\\pi\\epsilon_0}\\frac{2Q}{R^2}z\\left(\\frac{1}{z}-\\frac{1}{\\sqrt{R^2+z^2}}\\right)\\hat{k}}\n  \\end{align*}\n  \\subsection{Flux and Gauss's Law}\n  Flux is the amount of flow of a material or substance through some region. Area vectors point out of the plane of the area itself. Flux is denoted by $\\Phi$, and the equation for flux is:\n  \\begin{equation*}\n    \\Phi=\\int\\vec{f}\\cdot d\\vec{a}\n  \\end{equation*}\n  \\subsubsection{Example 1}\n  Find the flux $\\Phi$ of $\\vec{E}=\\epsilon_0\\frac{z}{z_0}\\vec{i}$ through an are $y_0+z_0$ in the y-z plane.\n  \\begin{align*}\n    \\Phi&=\\int\\vec{E}\\cdot d\\vec{a}\\\\\n    &=\\int Eda\\\\ \n    &=\\int_0^{z_0}\\int_0^{y_0}Eda\\\\\n    &=\\int_0^{z_0}\\int_0^{y_0}\\epsilon_0\\frac{z}{z_0}dydz\\\\\n    &=\\epsilon_0\\frac{y_0}{z_0}\\int_0^{z_0}dz\\\\\n    &=\\epsilon_0\\frac{y_0}{z_0}\\left(\\frac{1}{2}z_0^2-\\frac{1}{2}0^2\\right)\\\\\n    \\alignedbox{\\Phi}{=\\frac{1}{2}\\epsilon_0y_0z_0}\\\\\n    \\shortintertext{First, a single charge Q. We must apply a Gaussian surface to the point charge:}\\\\\n    \\Phi&=\\int\\vec{E}\\cdot d\\vec{a}=\\int(E\\hat{r})\\cdot(da\\hat{r})\\\\\n    &=\\int\\vec{E}\\cdot d\\vec{a}\\\\\n    &=\\int\\frac{1}{4\\pi\\epsilon_0}\\frac{1}{R^2}da\\\\\n    &=\\frac{1}{4\\pi\\epsilon_0}\\int da\\\\ \n    &=\\frac{q}{\\epsilon_0}\\\\\n    \\intertext{More generally, we write:}\\\\\n    \\alignedbox{\\Phi_E}{=\\oint\\vec{E}\\cdot d\\vec{a}=\\frac{q}{\\epsilon_0}}\n  \\end{align*}\n  This brings us to Gauss's law. This law is always true but it is only useful in certain situations. 1) When $\\vec{E}\\cdot d\\vec{a}$ is an easy dot product (they are parallel vectors). 2) When E is constant in magnatude across the surface. Then we can pull E through the integral. 3) When the total surface area is known. For example, we want the equations to be able to do the following:\n  \\begin{align*}\n    &\\oint\\vec{E}\\cdot d\\vec{a}\\\\\n    &\\oint Eda\\\\\n    &E\\oint da /to E_a=\\frac{q_{inside}}{E_0}\n  \\end{align*}\n  \\subsubsection{Example 2}\n  A sphere has a uniform charge Q throughout its volume and radius, R. Find E everywhere.\n  \\begin{align*}\n    \\shortintertext{Outside:}\\\\\n    \\oint\\vec{E}\\cdot d\\vec{a}&=\\frac{q_{enc}}{\\epsilon_0}\\\\\n    \\oint Eda &= \\frac{Q}{\\epsilon_0}\\\\\n    E\\oint da &= \\frac{Q}{\\epsilon_0}\\\\\n    E4\\pi r^2 &=\\frac{Q}{\\epsilon_0}\\\\\n    \\alignedbox{\\vec{E}}{=\\frac{1}{4\\pi\\epsilon_0}\\frac{Q}{r^2}\\hat{r}\\text{ for }r>R}\n    \\shortintertext{Now for the inside:}\\\\\n    \\int dq_{enc}&=\\int\\rho dv\\\\\n    q_{enc}&=\\rho\\int dv_{gauss}\\\\\n    &=\\rho\\frac{4}{3}\\pi r^3\\\\\n    \\text{Also } \\rho&=\\frac{Q}{\\frac{4}{3}\\pi R^3}\\\\\n    E4\\pi r^2&=\\frac{q_{enc}}{\\epsilon_0}\\\\\n    E&=\\frac{1}{4\\pi r^2}\\frac{1}{\\epsilon_0}Q\\frac{r^3}{R^3}\\\\\n    \\alignedbox{E}{=\\frac{1}{4\\pi\\epsilon_0}\\frac{Qr}{R^3}\\hat{r} \\text{ for }r<R}\n  \\end{align*}\n  \\subsubsection{Example 3}\n  Find $\\vec{E}$ everywhere for a very long line of charge with a charge density $\\lambda$ (constant and uniform charge).\n  \\begin{align*}\n    \\oint\\vec{E}\\cdot d\\vec{a}&=\\frac{q_{enc}}{\\epsilon_0}\\\\\n    \\int\\vec{E}\\cdot d\\vec{a}_{curve}+\\int\\vec{E}\\cdot d\\vec{a}_{left} +\\int\\vec{E}\\cdot d\\vec{a}_{right}&=\\int\\vec{E}\\cdot d\\vec{a}_{curve}=\\frac{\\lambda l}{\\epsilon_0}\\\\\n    \\int\\vec{E}\\cdot d\\vec{a}_{curve}&=\\frac{\\lambda l}{\\epsilon_0}\\\\\n    E\\int d\\vec{a}_{curve}&=\\frac{\\lambda L}{\\epsilon_0}\\\\\n    E(2\\pi rl)&=\\frac{\\lambda l}{\\epsilon_0}\\\\\n    \\alignedbox{\\vec{E}}{=\\frac{\\lambda}{2\\pi\\epsilon_0r}\\hat{r}}\\\\\n  \\end{align*}\n  \\subsubsection{Example 4}\n  A sphere has a non-uniform charge density of $\\rho=\\rho_0\\frac{r}{R}$ for a sphere with a radius, R. Find $\\vec{E}$ everywhere.\n  \\begin{align*}\n    \\int\\int\\int dxdydz \\to \\int\\int\\int r^2sin\\theta d\\theta dr d\\phi\\\\\n    \\shortintertext{First, the outside: } r>R\\\\\n    \\oint\\vec{E}\\cdot d\\vec{a}&=\\frac{q_{enc}}{\\epsilon_0}\\\\\n    \\oint Eda&=\\frac{q_{enc}}{\\epsilon_0}\\\\\n    E\\oint da&=\\frac{q_{enc}}{\\epsilon_0}\\\\\n    E(4\\pi r^2)=\\frac{q_{enc}}{\\epsilon_0}\\\\\n    \\int dq_{enc} &= \\int\\rho dV_{enc}\\\\\n    q_{enc}&=\\int \\rho_0\\frac{r}{R}dV\\\\\n    &=\\frac{\\rho_0}{R}\\int_0^{2\\pi}\\int_0^\\pi\\int_0^Rrr^2sin\\theta dr d\\theta d\\phi\\\\\n    &=\\frac{\\rho_0}{R}4\\pi\\int_0^Rr^3dr\\\\\n    &=\\rho_0\\frac{1}{R}4\\pi\\frac{1}{4}R^4\\\\\n    q_{enc}&=\\pi\\rho_0R^3\\\\\n    E(4\\pi r^2)=\\frac{1}{\\epsilon_0}\\pi\\rho_0R^3\\\\\n    \\alignedbox{\\vec{E}}{=\\frac{1}{4\\epsilon_0}\\frac{\\rho_0R^3}{r^2}\\hat{r}\\text{ for }r>R}\\\\\n    \\shortintertext{What about for $r<R$? Becuase of the boundary, we will have to seperately find $\\vec{E}$ for $r<R$:}\\\\\n    \\oint\\vec{E}\\cdot d\\vec{a}&=\\frac{q_{enc}}{\\epsilon_0}\\\\\n    \\oint Eda &=\\frac{q_enc}{\\epsilon_0}\\\\\n    E\\oint da&=\\frac{q_{enc}}{\\epsilon_0}\\\\\n    E(4\\pi r^2)&=\\frac{q_{enc}}{\\epsilon_0}\\\\\n    \\int dq_{enc}&=\\int \\rho dV_{gauss}\\\\\n    q_{enc}&=\\int\\rho_0\\frac{r}{R}dV_{gauss}=\\frac{\\rho_0}{R}\\int_0^{2\\pi}\\int_0^\\pi\\int_0^rrr^2sin\\theta dr d\\theta d\\phi\\\\\n    &=4\\pi\\frac{\\rho_0}{R}\\int_0^rr^3dr\\\\\n    q_{enc}&=\\pi\\frac{\\rho}{R}r^4\\\\\n    \\to \\text{Gauss's law } E(4\\pi r^2)&=\\frac{1}{\\epsilon_0}\\pi\\rho_0\\frac{r^4}{R}\\\\\n    E&=\\frac{1}{4\\epsilon_0R}\\rho_0r^2\\\\\n    \\alignedbox{E}{=\\frac{1}{4\\epsilon_0}\\rho_0\\frac{r^2}{R}}\\\\\n  \\end{align*}\n  The equations agree at $r=R$, therefore when greather than or equal to and less than and equal to, the answer also works as $r\\to0$ or $r\\to\\infty$.\n  \\subsubsection{Example 4 (Gauss's Law with Conductors)}:\n  Let's consider 2 large conductivity plates that are side by side. Lets put $\\pm Q$ on both of the conductivity plates.\n  \\begin{align*}\n    \\oint\\vec{E}\\cdot d\\vec{a}&=\\frac{q_{enc}}{\\epsilon_0}\\\\\n    \\int\\vec{E}d\\vec{a}_{right}+\\int\\vec{E}d\\vec{a}_{left}+\\int\\vec{E}d\\vec{a}_{top}&+\\int\\vec{E}d\\vec{a}_{bottom}+\\int\\vec{E}d\\vec{a}_{top}+\\int\\vec{E}d\\vec{a}_front\\\\\n    \\int\\vec{E}d\\vec{a}_{right}+\\int\\vec{E}d\\vec{a}_{left}&=\\frac{q_{enc}}{\\epsilon_0}\\\\\n    E_a+E_a&=\\frac{q_{enc}}{\\epsilon_0} \\text{ Surface charge density}\\\\\n    2E_a&=\\frac{\\sigma a}{\\epsilon_0}\\hat{i} \\text{ Between plates}\\\\\n    \\vec{E}&=\\frac{\\sigma}{2\\epsilon_0}\\hat{i} \\text{ left of the plates}\\\\\n    \\shortintertext{Now for the right plate:}\\\\\n  \\end{align*}\n\n\n\n  % Notes from 10.05.2020\n  \\newpage\n  \\subsection{Electric Potential}\n  \\subsubsection{Example 1}\n  Find $\\vec{E}$ above a disk of charge distribution that is uniform. the disk has radius (R) and total charge (Q). Let's find V then $\\vec{E}$\n  \\begin{align*}\n    dV&=\\frac{1}{4\\pi\\epsilon_0}\\frac{dq}{r}\\\\\n    \\shortintertext{The charge distribution is $\\sigma=\\frac{Q}{\\pi R^2}$}\\\\\n    dq&=\\sigma dA\\\\\n    &=\\sigma 2\\pi rdr\\\\\n    \\shortintertext{This r is not the same r as before, so we will call them r'}\\\\\n    &=\\sigma 2\\pi r'dr'\\\\\n    dV&=\\frac{1}{4\\pi\\epsilon_0}\\frac{\\sigma 2\\pi r'dr'}{\\sqrt{z^2+r'^2}}\\\\\n    V&=\\frac{1}{4\\pi\\epsilon_0}2\\pi\\sigma\\int_0^R\\frac{r'dr'}{\\sqrt{z^2+r'^2}}\\\\\n    V&=\\frac{1}{4\\pi\\epsilon_0}2\\pi\\sigma\\sqrt{z^2+r'^2}\\Big|_{r'=0}^{r'=R}\\\\\n    \\alignedbox{V}{=\\frac{1}{4\\pi\\epsilon_0}2\\pi\\sigma\\left[\\sqrt{z^2+R^2}-z\\right]}\n    \\shortintertext{Now let's find $\\vec{E}$}\\\\\n    E_x&=-\\frac{\\partial}{\\partial x}V=0\\\\\n    E_y&=\\frac{-\\partial}{\\partial y}V=0\\\\\n    E_z&=\\frac{-\\partial}{\\partial z}V = -\\frac{1}{4\\pi\\epsilon_0}2\\pi\\sigma\\left[\\frac{1}{2}(z^2+R^2)^{\\frac{-1}{2}}2z-1\\right]\\\\\n    \\alignedbox{\\vec{E}}{=\\frac{1}{4\\pi\\epsilon_0}2\\pi\\sigma\\left[1-\\frac{z}{\\sqrt{z^2+R^2}}\\hat{K}\\right]}\\\\\n  \\end{align*}\n  What does it mean to have potential charge? Potential doesn't have a proper value. Defining a reference point for V. $E_s = -\\frac{\\partial}{\\partial s}V$. Consider V and $V+V_0$ where $V_0$ is a constant. We get the same $\\vec{E}$ value. $E_s=-\\frac{\\partial}{\\partial s}V=\\frac{-\\partial}{\\partial s}(V+v_0)$. This is analogous to choosing an origin. For example, if you are going to calculate the velocity of a marker hitting the ground, you have to keep track of position so you must choose an origin. This is the same way that V is chosen when doing these equations. We need to choose where $V=0$. We choose $V=0$ at infinity. Recall that $V=\\frac{1}{4\\pi\\epsilon_0}\\frac{q}{r}$.\n  \\subsection{Electrostatic Potential Energy}\n   Electric forces are conservative. This doesn't mean not progressive, it means that they conserve energy. We can do these calculations using energy alone, similar to gravity or $MgH=\\frac{1}{2}mv^2$. The law of energy conservation is $\\Delta K+\\Delta U=0$. Energy is not always conserved though. One physics 103 example is friction (drag). Disipative forces are also a good example of ways energy is not fully conserved. Energy is not lost, it is just converted from translational energy to heat energy. Macroscopically, the energy is not conserved, but at a microscopic level, the energy is fully conserved. We will not consider disipative forces in this course. This means that we can use the law of energy conservation ($\\Delta K+\\Delta U=0$). We've said previously that the $U=QV$. Very similar to $\\vec{F}=Q\\vec{E}$.\n  \\subsubsection{Example 1}\n  Charge $Q_1=6\\mu C$ and $Q_2=4\\mu C$ are released from rest at a distance apart of $l=10cm$. Find their final speeds $v_1$ and $v_2$. The forces of point $Q_1$ and $Q_2$ are going to exert forces away from each other. It is possible to take a force approach to this problem, but as they move apart, their acceleration changes. This makes the problem much more difficult, but you can do an energy approach because the stages in between do not matter within this approach. We will solve this using energy.\n  \\begin{align*}\n    \\Delta K+\\Delta U &=0\\\\\n    K_1-K_0+U_1-U_2&=0\\\\\n    \\shortintertext{We have to change either $Q_1$ and $Q_2$ or change $K_0$ and $K_1$ because they don't mean the same thing. We are going to change Q to be $Q_A$ and $Q_B$. Initially, their kinetic energy is zero:}\n    K_1+U_1-U_0&=0\\\\\n    \\left(\\frac{1}{2}m_Av_a^2+\\frac{1}{2}m_bv_b^2\\right)+\\frac{1}{4\\pi\\epsilon_0}\\frac{Q_AQ_B}{r_{AB}}-\\frac{1}{4\\pi\\epsilon_0}\\frac{Q_A}{l}&=0\\\\\n    \\shortintertext{Interaction energy is a better term than potential energy. Potential energy goes in pairs. It is how two charges interact, not how a single charge exists. No matter how far apart they are, they will exert a force on each other. $\\frac{Q_A}{Q_B}\\to0$ because $r_{AB}\\to 0$}\\\\\n    \\frac{1}{2}m_Av_A^2+\\frac{1}{2}m_Bv_B^2&=\\frac{1}{4\\pi\\epsilon_0}\\frac{Q_AQ_B}{l}\\\\\n    \\shortintertext{Let $M_A=M_B=15g$}\\\\\n    \\shortintertext{In this system, $\\vec{F_{AB}}=-\\vec{F_{AB}}$ Also there are no external forces acting so,}\\\\\n    \\vec{F}_{net}&=\\vec{F}_{AB}+\\vec{F}_{BA}=0=\\frac{d}{dt}\\vec{P}\\\\\n    \\Delta P_{01}&=0=P_1-P_0\\\\\n    0&=m_Av_A+m_Bv_B\\\\\n    \\to v_A^2&=V_B^2\\frac{m_B^2}{m_A^2}\\\\\n    \\to \\frac{1}{2}m_A\\left[v_B^2\\frac{m_B^2}{m_A^2}\\right]+\\frac{1}{2}m_Bv_B^2&=\\frac{1}{4\\pi\\epsilon_0}\\frac{Q_AQ_B}{l}\\\\\n    \\frac{1}{2}v_B^2\\left[\\frac{m_B^2}{m_A}+m_B\\right]&=\\frac{1}{4\\pi\\epsilon_0}\\frac{Q_AQ_B}{l}\\\\\n    m_bv_B^2&=\\frac{1}{4\\pi\\epsilon_0}\\frac{Q_AQ_B}{l}\\\\\n    \\alignedbox{v_b}{=\\sqrt{\\frac{1}{m_b}\\frac{1}{4\\pi\\epsilon_0}\\frac{Q_AQ_B}{l}}}\\\\\n    v_a&=-v_B\\frac{m_B}{m_A}\\\\\n    \\alignedbox{v_A}{=-v_B}\\\\\n  \\end{align*}\n  \\newpage", "meta": {"hexsha": "f074a70734c2e0d61732fd7d51e73927f9a7d8e2", "size": 21590, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "physics204/Sections/4Electricity.tex", "max_stars_repo_name": "CameronSWilliamson/GU-MATH", "max_stars_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-18T00:49:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T00:49:14.000Z", "max_issues_repo_path": "physics204/Sections/4Electricity.tex", "max_issues_repo_name": "therealkeyisme/Math-Notes", "max_issues_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "physics204/Sections/4Electricity.tex", "max_forks_repo_name": "therealkeyisme/Math-Notes", "max_forks_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 74.9652777778, "max_line_length": 823, "alphanum_fraction": 0.6356183418, "num_tokens": 8900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7406049027271111}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{numprint}\n\n\\author{Daniel Fernandes Martins (danielfmt)}\n\\title{Question \\#3 Solution}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Conditional Probability}\n\n\\subsection{Calculating $P(B)$}\n\nFirst we need to calculate the probability of picking a black ball on the\nfirst try:\n\n\\begin{equation*}\nP(B) = \\frac{1}{2} \\cdot 1 + \\left( \\frac{1}{2} \\right)^2 = \\frac{3}{4}\n\\end{equation*}\n\n\\subsection{Calculating $P(A|B)$}\n\nFor the second ball to be also black, then we must have picked the first bag\n(bag $A$):\n\n\\begin{equation*}\nP(A|B) = P(A \\cap B) \\div P(B) = \\left( \\frac{1}{2} \\cdot 1 \\right) \\div \\frac{3}{4} = \\frac{2}{3}\n\\end{equation*}\n\n\\end{document}\n", "meta": {"hexsha": "96c5f214e1820eb8b290f42412bc949226b03097", "size": 710, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week-01/math/q03.tex", "max_stars_repo_name": "danielfm/edx-learning-from-data", "max_stars_repo_head_hexsha": "1675e14c20fc1b7ad54d2704b9c8a941e043cbcb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 98, "max_stars_repo_stars_event_min_datetime": "2015-04-27T06:55:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:09:19.000Z", "max_issues_repo_path": "week-01/math/q03.tex", "max_issues_repo_name": "danielfm/edx-learning-from-data", "max_issues_repo_head_hexsha": "1675e14c20fc1b7ad54d2704b9c8a941e043cbcb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-05-14T19:33:33.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-12T13:07:41.000Z", "max_forks_repo_path": "week-01/math/q03.tex", "max_forks_repo_name": "danielfm/edx-learning-from-data", "max_forks_repo_head_hexsha": "1675e14c20fc1b7ad54d2704b9c8a941e043cbcb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 56, "max_forks_repo_forks_event_min_datetime": "2015-01-10T08:18:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-28T08:46:22.000Z", "avg_line_length": 20.8823529412, "max_line_length": 98, "alphanum_fraction": 0.685915493, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916240341031, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.7405897956424395}}
{"text": "\\documentclass[11pt,twoside]{article}\n\n\\usepackage[headings]{fullpage}\n\\usepackage[utopia]{mathdesign}\n\n\\pagestyle{myheadings}\n\\markboth{Be rational}{Be rational}\n\n\\input{../../fncextra}\n\n\\begin{document}\n   \n\\begin{center}\n    \\bf Let's be rational about this\n\\end{center}\n\nOur go-to form of interpolating function is the polynomial,\n\\begin{equation}\n p(x) = c_0 + c_1 x + c_2 x^2 + \\cdots + c_{n-1} x^{n-1}.\n\\end{equation}\nWhen the monomials are evaluated at $m$ nodes, we get the Vandermonde matrix\n\\begin{equation}\n\\mV = \n \\begin{bmatrix}\n      1 & t_0 & t_0^{2} & \\cdots & t_0^{m-1} \\\\[1mm]\n      1 & t_1 & t_1^{2} & \\cdots & t_1^{m-1}   \\\\[1mm]\n      1 & t_2 & t_2^{2} & \\cdots & t_2^{m-1} \\\\[1mm]\n      \\vdots & \\vdots & \\vdots  &  & \\vdots \\\\\n      1 & t_{m-1} & t_{m-1}^{2} & \\cdots & t_{m-1}^{m-1} \n \\end{bmatrix} .         \n\\end{equation}\nGiven a function $f$, setting $y_i=f(t_i)$ and solving $\\mV \\bfc = \\bfy$ produces the coefficients of the interpolating polynomial.\n\nPolynomials can, in principle, converge pointwise to any continuous function. However, they are not equally efficient at doing so for all functions. One way to obtain faster convergence in some cases is to turn to a different category of functions. An interesting choice are the \\textbf{rational functions},\n\\begin{equation}\n\\label{ratdef}\n r(x) = \\frac{a_0 + a_1 x + \\cdots + a_{n-1} x^{n-1}}{b_0 + b_1 x + \\cdots + b_{n-1} x^{n-1}+ b_nx^n}.\n\\end{equation}\nBecause they can have zeros in the denominator, rational functions are often superior for approximating functions that blow up or have steep gradients. \n\nObserve that in~\\eqref{ratdef}, multiplying all of the coefficients by the same constant leaves $r$ unchanged. Thus we make a normalization, $b_n=1$. This leaves a total of $n+n=2n$ coefficients to be determined in $r$, so we require $2n$ interpolation nodes. From~\\eqref{ratdef}, setting $r(t_i)=f(t_i)=y_i$, for $i=0,\\ldots,2n-1$ and clearing the denominator, we eventually obtain\n\\begin{equation}\n\\label{eq:sys1}\n\\m{W} \\bfa - \\m{Y} \\m{W} \\bfb = \\m{Y} \n\\begin{bmatrix}\n t_0^n \\\\ t_1^n \\\\ \\vdots \\\\ t_{2n-1}^n\n\\end{bmatrix},\n\\end{equation}\nwhere $\\m{W}$ is a $2n\\times n$ Vandermonde-style matrix, \n$\\m{Y}=\\diag(y_0,\\ldots,y_{2n-1})$, and $\\bfa$ and $\\bfb$ collect the polynomial coefficients in the numerator and denominator respectively. This equation is actually a square linear system,\n\\begin{equation}\n  \\label{eq:sys2}\n\\begin{bmatrix}\n  \\m{W} & - \\m{Y} \\m{W} \n\\end{bmatrix}\n\\begin{bmatrix}\n\\bfa \\\\ \\bfb\n\\end{bmatrix}\n= \\m{Y} \n\\begin{bmatrix}\nt_0^n \\\\ t_1^n \\\\ \\vdots \\\\ t_{2n-1}^n\n\\end{bmatrix},\n\\end{equation}\neasily solved for the vector $\\bfc = \\bigl[ \\bfa\\,; \\, \\bfb \\bigr]$. \n\n\\subsection*{Goals}\n\nYou will compute a rational interpolant and compare it to a polynomial interpolant for the same points. \n\n\\subsection*{Preparation}\n\nRead section 9.1 and answer the following questions.\n\n\\begin{enumerate}\n    \\item Derive~\\eqref{eq:sys1}.\n    \\item Write out the linear system~\\eqref{eq:sys2} for the rational interpolant to the four points $(-1,0)$, $(0,-1)$, $(1,1)$, $(2,1)$. \n\\end{enumerate}\n\n\\subsection*{Procedure}\n\nDownload templates for the script and for the function \\texttt{ratinterp.m}.\n\n\\begin{enumerate}\n    \\item Complete the function \\texttt{ratinterp} that computes a rational interpolant to given data using the algorithm outlined above. \n    \\item Define the function $g(x) = \\tanh(10x) + 2x^2$ and plot it over the interval $[-1,1]$.\n    \\item To your plot add the polynomial interpolant using $m=18$ equally spaced nodes in $[1,1]$. (It will not be a good result.)\n    \\item Find the rational interpolant with $n=9$ and the same nodes. Start a new plot and plot the error $g(x)-r(x)$ over $[-1,1]$. It should be fairly small over the whole interval.\n\\end{enumerate}\n\n\\subsection*{Discussion}\n\nReturning to the $n=9$ rational interpolant of $g$, find the poles of $r$ (i.e., the roots of the denominator). Several of them are conjugate pairs that lie essentially on the imaginary axis of the complex plane. Referring to a property of $g$, explain the two poles closest to the origin. You may want to prove and then use the identity $\\cosh(x)=\\cos(ix)$. \n\n\n\n\n\\end{document}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: t\n%%% End: \n", "meta": {"hexsha": "ef2bbc6b562aab19e143f0f36e635a9015fe3e3d", "size": 4265, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter09/BeRational/BeRational.tex", "max_stars_repo_name": "snowdj/fnc-extras", "max_stars_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 109, "max_stars_repo_stars_event_min_datetime": "2018-04-21T09:02:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T19:03:54.000Z", "max_issues_repo_path": "labs/chapter09/BeRational/BeRational.tex", "max_issues_repo_name": "snowdj/fnc-extras", "max_issues_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-12-04T22:17:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T21:04:47.000Z", "max_forks_repo_path": "labs/chapter09/BeRational/BeRational.tex", "max_forks_repo_name": "snowdj/fnc-extras", "max_forks_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 49, "max_forks_repo_forks_event_min_datetime": "2017-04-02T17:21:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T17:19:57.000Z", "avg_line_length": 41.4077669903, "max_line_length": 382, "alphanum_fraction": 0.69003517, "num_tokens": 1410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7405897744124527}}
{"text": "\\chapter{Frames}\n\n(Wikipedia says frame (ordered basis) for what we say basis. Should we follow?)\n\n\\section{A frame is an origin point and a basis}\n\nWith a basis, we can describe every vector with tuples.\n\nWith a frame, we can describe every point with tuples.\n\nA frame \\(S\\) is an origin point \\( O \\) and a basis \\( E \\).\n\nWe can describe a point \\( P \\) as \\( O + OP \\).\nWe then state \\(OP\\) as a linear combination of the vectors in \\(E\\).\nSuppose that the linear combination is \\(OP = x_1 e_1 + \\ldots + x_n e_n\\).\nWe call the tuple \\( (x_1,\\ldots,x_n) \\) the \\emph{\\(S\\)-coordinates} of \\(P\\).\n\n\\emph{Coordinate system} is another name for \\emph{frame}.\n\n\\footnote{\\url{https://en.wikipedia.org/wiki/Frame\\#Mathematics}}\n\n\\section{Some coordinate systems}\n\nA \\emph{coordinate system} maps a coordinate tuple to a vector.\n\n\\subsection{The rectangular coordinate system}\n\nOrthonormal basis.\n\n\\(R(x,y) = x e_1 + y e_2\\).\n\n\\(R(x) = x_1 e_1 + x_2 e_2\\).\n\nIn this system, the coordinates are the scalar coefficients in the linear combination of basis vectors.\nThe coordinates describe how the basis vectors should be linearly combined to form the described vector.\n\nLet \\(T : V^2 \\to V^2\\) be a linear transformation.\nThen \\(T(R(x)) = T(x_1 e_1 + x_2 e_2) = x_1 \\cdot T(e_1) + x_2 \\cdot T(e_2) = x_1 e_1' + x_2 e_2' = R'(x) \\).\n\n\\subsection{The polar coordinate system}\n\n\\(P(r,t) = r e_1 \\text{ rotated } t \\text{ radians counterclockwise}\\).\n\n\\section{Coordinate system transformations}\n\n\\subsection{Converting polar coordinate tuples to rectangular coordinate tuples}\n\nBoth the rectangular coordinate $(r\\cos\\theta, r\\sin\\theta)$ and the polar coordinate $(r,\\theta)$\ndescribe the same point in two-dimensional Euclidean space.\n\\[\nR(r\\cos\\theta, r\\sin\\theta) = P(r,\\theta)\n\\]\n\nA point in a space can have different coordinates in different coordinate systems.\n\n\\section{Using coordinate systems to apply analysis to geometry}\n\nCoordinate systems bridge synthetic geometry and analytic geometry.\n\nA coordinate system transformation is a function taking a coordinate system and giving another coordinate system.\n\n\\section{Describing vectors with numbers without drawing}\n\nEarlier in \\ChapterRef{chp:vector},\nwe defined a vector as something telling us\nhow to go from an origin point to a destination point.\n\nWe can define three directions: right, forward, and up.\nWe can describe \\emph{any} point in space by saying that the point is\n\\(x\\) meters right, \\(y\\) meters forward, and \\(z\\) meters up from where we are standing.\nWe have just described a \\emph{coordinate system}:\na mapping between a \\emph{coordinate tuple} and a point in space.\n\nA tuple and a coordinate system can represent a vector.\n\n\\( v = x_1 e_1 + x_2 e_2 \\).\n\nDescribing a vector using bases:\n\n\\[\nv = \\sum_k x_k e_k\n\\]\nwhere each \\(x_k:\\Real\\) and each \\(e_k:\\Real^n\\).\n\nFor example:\n\nLet \\( e_1 \\) be a unit vector pointing right.\n\nLet \\( e_2 \\) be a unit vector pointing up.\n\nThen, \\( 1 e_1 + 2 e_2 \\) is a vector.\n\n\"The numbers in the list depend on the choice of coordinate system.\"%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Covariance_and_contravariance_of_vectors}}\n\n\\subsection{Basis vectors and coordinate axes}\n\nAn orthonormal basis makes good coordinate axes.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Orthonormal_basis}}\n\nThe same point has different coordinates in different frames.\n\n\\section{Coordinate systems}\n\nWe can describe a point by a \\emph{coordinate system} and a \\emph{coordinate tuple}.\n\n\\index{definitions!coordinate}%\nA \\emph{coordinate} is a number.\n\n\\index{definitions!coordinate tuple}%\nA \\emph{coordinate tuple} is a tuple of \\emph{coordinates}.\nExample: \\((1,2)\\).\n\n\\index{definitions!coordinate system}%\nA \\emph{coordinate system} maps a coordinate tuple to a point in a space.\n\n\\index{definitions!\\(n\\)-dimensional real coordinate space}%\nThe \\emph{n-dimensional real coordinate space} \\( \\Real^n \\)\nis the set of all \\(n\\)-tuples where every component is a real number.\nIt can \\emph{represent} the \\(n\\)-dimensional Euclidean space.\n\nThe \\(n\\)-dimensional Cartesian coordinate system uses \\(n\\) basis vectors\nto map \\( \\Real^n \\) to \\(n\\)-dimensional Euclidean space.\n\n\\subsection{Drawing the standard two-dimensional Cartesian coordinate axes}\n\n\\subsection{Transforming the vector}\n\nAlso known as \\emph{active transformation}.\nThis changes the vector.\n\nWe write \\(v = E(x)\\) to mean that \\emph{the vector \\(v\\) is described by the coordinate tuple \\(x\\) under coordinate system \\(E\\)}.\n\nLet \\(v = E(x)\\).\nThe vector \\(v\\) is described by the tuple \\(x\\) under coordinate system \\(E\\).\n\nIf we transform the vector to \\(T(v)\\),\nthen we will also transform the coordinate tuple to \\(T(E(x))\\),\nwhich we can also write as \\((T \\circ E)(x)\\) using function composition notation.\n\nThus, if \\(v = E(x)\\), then \\( T(v) = (T \\circ E)(x) \\).\n\nTherefore, transforming the vector by \\(T\\) has the same effect as\ntransforming the coordinate system (not the coordinate tuple) by \\(T\\).\n\n\\subsection{Transforming the basis}\n\n\\emph{Passive transformation}.\nChanging the basis while still referring to the same point.\nThis does not change the vector.\n\nEvery vector can be stated as a linear combination of the basis vectors.\n\n\\index{definitions!coordinate transformation}%\nA \\emph{coordinate transformation} is a map from a coordinate system to a coordinate system.\n\nThere are many points in an Euclidean space, but none is special.\nHowever, we can pick a point in Euclidean space, and call it \\( O \\), short for \\emph{origin}.\n\nWe can describe the same vector using different coordinate tuples in different coordinate systems.\nFor example, the same vector \\(v\\) has coordinate tuples \\(x\\) in coordinate system \\(E\\)\nand has coordinate tuples \\(x'\\) in coordinate system \\(E'\\).\n\\[\n    v = E(x) = E'(x')\n\\]\n\n\\footnote{\\url{https://en.wikipedia.org/wiki/Active_and_passive_transformation}}\n\nLet \\(T\\) be a linear transformation.\n\nIf \\(E'\\) happens to be \\(T \\circ E\\), then\n\n\\begin{align*}\n    E(x) &= (T \\circ E)(x') & \\text{assumed}\n    \\\\ E(x) &= T(E(x')) & \\text{by definition of composition}\n    \\\\ T^{-1}(E(x)) &= T^{-1}(T(E(x'))) & \\text{applying \\(T^{-1}\\) to both sides}\n    \\\\ (T^{-1}\\circ E)(x) &= E(x')\n\\end{align*}\n\n\\subsection{Changing basis}\n\nA basis transformation is a coordinate system transformation.\nSuch transformation has the type\n$(\\mathbb{R}^n \\to \\mathbb{R}^n) \\to (\\mathbb{R}^n \\to \\mathbb{R}^n)$.\nSuch basis transformation $E' = T~E$ can be written out\nas $\\vec{e}'_k = T_k~(\\vec{e}_1, \\ldots, \\vec{e}_n)$,\nwhich can be written out even more in the greatest detail as\n\\[\n(\\vec{e}'_k)_i = (T_k)_i~(\\vec{e}_1, \\ldots, \\vec{e}_n)\n\\]\nwhich are actually $n^2$ equations,\nand each $(T_k)_i$ is a function that takes $n^2$ real numbers.\nIf the transformation is linear,\nwe can write the transformation as matrix multiplication:\n\\[\nE' = ET\n\\]\nwhich expands into $n$ equations each:\n\\[\n\\vec{e}_i' = \\sum_{k=1}^n T_{ik} \\vec{e}_k\n\\]\nwhich, in turn, expands into $n$ equations again each:\n\\[\ne_{ij}' = \\sum_{k=1}^n T_{ik} \\cdot e_{kj}\n\\]\n\nSometimes we want to use another basis to locate the same point.\nThat is, if we have a vector $x$ in basis $E$, and a vector $y$ in basis $TE$,\nwe want $Ex = TEy$.\nWe want to change the basis from $E$ to $TE$,\nso old coordinate $x$ become $y$,\nbut we want $y$ in $TE$ such that $TEy$ is still $Ex$,\nwhich we can state mathematically:\n\\begin{align*}\nTEy &= Ex\n\\\\ T^{-1}TEy &= T^{-1}Ex\n\\\\ Ey &= T^{-1}Ex\n\\end{align*}\nwhich says that the change of coordinate goes against the change of basis,\nso we say that the vector $x$ is *contravariant* to the basis transformation $T$.\nThis means that if we move the origin of the coordinate system 3 units to the right,\nthen we will have to move the coordinates 3 units to the left\nif we want the new coordinate to locate the same point.\n\nWhat about covectors?\nCovector $f$.\n\\[\nf(TEy) = f(Ex)\n\\]\nDue to the linearity of covectors:\n\\begin{align*}\nf(Ex) &= f\\left(\\sum_i x_i \\vec{e}_i\\right) = \\sum_i f(x_i \\vec{e}_i)\n\\\\ f(TEy) &= f\\left(\\sum_i y_i T\\vec{e}_i \\right) = \\sum_i f(y_i T\\vec{e}_i)\n\\\\ \\vec{e}'_k = \\sum_i T_{ki} \\vec{e}_i\n\\end{align*}\n\n(todo show that covector is covariant)\n\n\\section{Coordinate transformation}\n\nLet's say we have one space $S$,\nand two coordinate systems $J : M \\to S$ and $K : N \\to S$.\nA coordinate transformation from $J$ to $K$ (we name this transformation $T : M \\to N$)\ntransforms a $J$-coordinate\nto an $K$-coordinate describing the same point.\nThis transformation relates both coordinate systems as\n$J~x = K~(T~x)$, which means that if $x$ is a coordinate in $J$, then $T~x$ is a coordinate in $K$ locating the same point.\nWe can also write the equation as $J = K \\circ T$.\n\nTo consider each component of the coordinate separately,\nwe write\n$T~(x_1,\\ldots,x_m) = (y_1,\\ldots,y_n)$\nwhere\n\\begin{align*}\ny_1 &= t_1~(x_1,\\ldots,x_m)\n\\\\ &\\vdots\n\\\\ y_n &= t_n~(x_1,\\ldots,x_m).\n\\end{align*}\nThus we can think of $T$ as an $n$-tuple $(t_1,\\ldots,t_n)$\nwhose each component $t_k$ takes an $m$-tuple.\nWe can extend the definition of function application so that it works on tuples:\n\\[\n(t_1,\\ldots,t_n)~\\vec{x} = (t_1~\\vec{x}, \\ldots, t_n~\\vec{x})\n\\]\nbut why would we?\n\nIf we define that, we can see how a change in a tuple component translates\nto a change in the other tuple component.\n\\[\n\\frac{\\partial y_i}{\\partial x_j} = pd~j~t_i\n\\]\n\nA space mapping maps the underlying space $M : R \\to S$.\n\nThe transformation $T~x = 2\\cdot x$ can be viewed as two things:\nas a space transformation, it makes everything bigger;\nas a coordinate transformation, it makes everything smaller.\nCoordinate transformation works in reverse.\nYou can move the point, or you can change the coordinate.\n\nCovariance.\n\nDistance-preserving transformation.\n$d~(T~x)~(T~y) = d~x~y$.\n\n$T$-symmetry.\n$f~(T~x) = T~(f~x)$?\n\nInverse transformation.\nComposition of transformations.\n\nWe can use several coordinate systems on the same space.\nSome coordinate systems are more convenient to work with.\nTo specify a place on Earth, we can use the\ngeographic coordinate system (latitudes and longitudes).\n% https://en.wikipedia.org/wiki/Geographic_coordinate_system\nA coordinate transformation does not move the point.\n\nIf a coordinate system is a bijection,\nthen it describes an isomorphism between\nits coordinate space and the space it describes.\nThis means we can pick any of them we find most convenient,\nand whatever works with it will work with the other.\n\nLet's say we have two spaces $R$ and $S$.\n$T : R \\to S$.\n\nEmbedding and projection are mappings between spaces.\nEmbedding maps a lower-dimensional space to a higher-dimensional space;\nprojection maps a higher-dimensional space to a lower-dimensional space.\n\n\\subsection{Picking a frame: The standard basis vectors}\n\nThe standard basis vectors of $\\mathbb{R}^3$\nis $\\{e_1,e_2,e_3\\}$\nwhere $e_1 = (1,0,0)$, $e_2 = (0,1,0)$, and $e_3 = (0,0,1)$,\nwhich can also be written as the matrix\n\\[\n    \\Matrix{ e_1 & e_2 & e_3 }\n    = \\Matrix{ 1&0&0\\\\0&1&0\\\\0&0&1 }\n\\]\nwhere each basis vector becomes a column in the matrix.\n\nA coordinate system transformation multiplies the basis with the transformation matrix.\n\n\\subsection{Curvilinear coordinate system: polar coordinate system}\n\n\\section{Understanding a covector as a linear function}\n\nEvery linear endofunction of an $n$-dimensional vector space\ncan be written as a vector of $n$ of inner products.\n\n\\section{Understanding how cobasis is to covector as basis is to vector}\n\nWe can derive a basis for $V^*$ from a basis for $V$.\nLet us write the basis for $V$ as \\(E = \\{ e_1, \\ldots, e_n\\}\\).\nWe then define $G = \\{ g_1, \\ldots, g_n \\}$ where \\(g_k(x) = x \\cdot e_k\\).\nIf such $G$ also spans the entire $V^*$,\nthen $G$ is a basis for $V^*$,\nand we call such $G$ the dual basis of $E$.\n\n\\section{Multiplying a covector and a vector}\n\nThe product between a covector $f : V^*$ and vector $\\vec{x} : V$\nis simply $f~\\vec{x}$ (function application)?\n\n\\section{Eigenvalues, eigenvectors, and fixpoints of transformations? Why are we talking about this?}\n\nWe say that a point is a fixpoint (invariant)\nof a transformation iff the transformation maps it to itself.\n$f(x) = x$.\nWe can also say that $f$ is a fixtransform of $x$.\n\nWe can embed a plane on a sphere.\n\nTo describe an embedding,\nwe can use words, or we can use algebra:\nwe pick a coordinate system for each space,\nand describe the embedding of the coordinates.\nAn embedding $E : R \\to S$ is a mapping from a space $R$ to (a subset of) another space $S$.\nLet $J : M \\to R$ and $K : N \\to S$ be coordinate systems for those spaces, respectively.\nLet $T : M \\to N$ be the coordinate transformation that corresponds to that embedding.\nLet $x$ be a $J$-coordinate.\nThen we have:\n\\[\nK~(T~x) = E~(J~x)\n\\]\nwhich can also be written\n\\[\nK \\circ T = E \\circ J.\n\\]\nSpherical coordinate system\nuse three: radius,: $(r,\\theta,\\phi)$. Here the radius is fixed so we can use $(\\theta,\\phi)$.\n\n\\section{Moving points around}\n\n\\subsection{Translating a point}\n\nWe can translate a point \\(P\\) by a vector \\(v\\).\nThe result is the point \\(P + v\\).\n\n\\subsection{Rotating a vector}\n\nRotation is always done with respect to the origin.\nIf you need otherwise, then translate, rotate, and inverse-translate.\n\nTwo-dimensional rotation is simple because the axis of rotation is a point.\nThree-dimensional rotation is more complex because the axis of rotation is a line.\n\nLet \\(x\\) be the vector that we want to rotate.\n\nLet \\(a\\) be the axis of rotation.\n\nLet \\(n\\) be orthogonal to \\(a\\).\nLet \\(a + n = x\\).\nThus, \\(a\\), \\(x\\), and \\(n\\) form a right triangle, with \\(x\\) as the hypothenuse.\n\nLet \\(\\theta\\) be the angle of rotation.\n\nLet \\(A(x,y)\\) be the angle from \\(x\\) to \\(y\\).\n\nThe result of rotating a vector \\(x\\) about the axis \\(a\\) by angle \\(\\theta\\) is the vector \\(y\\).\n\n\\(\\norm{x} = \\norm{y}\\)\n\n\\(A(a,x) = A(a,y)\\).\n\n\\(A(n,x) + \\theta \\equiv A(n,y)\\).\n\n\\subsection{Applying a rotation matrix to a vector}\n\nThis matrix%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Rotation_matrix}}\ndescribes\ntwo-dimensional rotation by a counterclockwise angle of \\(\\theta\\):\n\\Formula{\n    \\Matrix{\n        \\cos\\theta & -\\sin\\theta\n        \\\\ \\sin\\theta & \\cos\\theta\n    }.\n}\nLet that matrix be \\(R\\).\nLet \\(v\\) be a vector.\nThen \\(Rv\\) is \\(v\\) rotated by \\(\\theta\\).\n\n\\section{Moving frames around without moving points}\n\n\\subsection{Locating the same point with different coordinate systems}\n\nExample of coordinate transformation:\nThe same point in the same two-dimensional Euclidean space\nis described by\nboth the polar coordinates \\( (r,\\theta) \\)\nand the rectangular coordinates \\( (r \\cos \\theta, r \\sin \\theta) \\).\nThe transformation is \\( (r,\\theta) \\to (r \\cos \\theta, r \\sin \\theta) \\).\n\n% https://en.wikipedia.org/wiki/Real_coordinate_space\n\nA \\emph{coordinate system} $M : C \\to S$ is a surjective mapping from\n\\emph{coordinate space} $C$ to \\emph{target space} $S$.\n\nA \\emph{coordinate} is a point in \\(C\\).\nThe coordinate system tells us how to get to a point.\n\nThe \\(n\\)-dimensional real coordinate space is $\\mathbb{R}^n$.\n% https://en.wikipedia.org/wiki/Real_coordinate_space\nIt is also called the real $n$-space.\nA point in the real $n$-space is an $n$-tuple of real numbers $(x_1,\\ldots,x_n)$.\n\n$(x,y)$ is the tuple of coordinates,\n$x$ is the x-coordinate, and $y$ is the y-coordinate.\n\nCoordinate systems unify geometry and\n% https://en.wikipedia.org/wiki/Mathematical_analysis\nmathematical analysis.\nWith coordinates,\nwe can solve geometric problems by\nnumbers, calculus, and algebra,\nso that computers can\nfind the intersection of geometric objects\nby solving the corresponding system of equations,\nand find the size of a geometric object by solving the corresponding integral.\n\n\\section{Fields}\n\nA field is a function that assigns something to each point in space.\n\nA vector field is a function \\( f : P \\to V \\).\n\nWe need two bases to coordinatefully describe a vector field.\nOne basis to turn \\( P \\) to \\(\\Real^m\\).\nAnother basis to turn \\(V\\) to \\(\\Real^n\\).\n\nThe coordinateful description of a field \\(f\\) under basis \\(?,?\\) is \\(f_? : \\Real^m \\to \\Real^n\\).\n\nA force field assigns a force vector to each point in space.\n\nA scalar field assigns a scalar to each point in space.\nAn example of a scalar field is a temperature field.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Temperature_gradient}}\n\nLet \\(T(P)\\) be the temperature at point \\(P\\).\nBecause \\(P = O + \\sum_k x_k e_k\\), we have \\(T(O + \\sum_k x_k e_k)\\).\n\nMathematics and physics use the same term \\enquote{field} to mean different things.\n\n\\footnote{\\url{https://en.wikipedia.org/wiki/Field_(physics)}}\n", "meta": {"hexsha": "00ea071954f8e2a24f15e978f00e18e5f8089c39", "size": 16608, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/frame.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/physics/frame.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/physics/frame.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 34.0327868852, "max_line_length": 132, "alphanum_fraction": 0.7113439306, "num_tokens": 4726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391599428538, "lm_q2_score": 0.8577681013541611, "lm_q1q2_score": 0.7405897729669495}}
{"text": "%================================\n\\section{Separation Axioms. From $T_0$ to Hausdorff}\n%================================\n\n% links\n\n% https://en.wikipedia.org/wiki/Separation_axiom\n\n% https://en.wikipedia.org/wiki/Separated_sets\n\n% https://proofwiki.org/wiki/Definition:Tychonoff_Separation_Axioms\n\n\n%--------------------------------\n\\begin{definition}\n\t[saperated]\n\t\\label{def: seperated}\n\tIn a topological space, two sets are said to be \\textit{separated} iff each is disjoint from other's closure.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[separated by neighbourhoods]\n\t\\label{def: separated by neighbourhoods}\n\tIn a topological space $(X, \\mathcal T)$, two sets $A$ and $B$ are said to be \\textit{separated by neighbourhood} iff there are neighbourhoods $N_A$ of $A$ and $N_B$ of $B$ such that $N_A$ and $N_B$ are disjoint.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[topologically indistinguishable]\n\t\\label{def: topologically indistinguishable}\n\tLet $(X, \\mathcal T)$ be a topological space. Two points $x,y \\in X$ are said to be \\textit{topologically indistinguishable} iff they share all their neighbourhoods. That is, let $\\mathcal N_x$ be the family of all neighbourhoods of $x$ and let $\\mathcal N_y$ be the family of all neighbourhoods of $y$, we have\n\t$$\n\t\\mathcal N_x = \\mathcal N_y.\n\t$$\n\n\tRespectively, $x,y$ are said to be \\textit{topologically distinguishable} iff they are not topologically distinguishable; i.e.,\n\t$$\n\t\\mathcal N_x \\ne \\mathcal N_y.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tIn an indiscrete topological space, all distinct points are topologically indistinguishable.\n\\end{example}\n%--------------------------------\n\n\n\\centering{\n\t\\subsection*{$T_0$ Spaces}\n}\n\n%--------------------------------\n\\begin{definition}\n\t[$T_0$ spaces]\n\t\\label{def: T_1 spaces}\n\tA topological space $(X, \\mathcal T)$ is said to be $T_0$ or \\textit{Kolmogorov}, iff all distinct points $x,y \\in X$ are topologically distinguishable.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tLet $X$ be any set and let $\\mathcal T$ be the indiscrete topology on $X$. $(X, \\mathcal T)$ is $T_0$ iff $|X| \\in \\{0, 1\\}$.\n\\end{example}\n%--------------------------------\n\n\n\\centering{\n\t\\subsection*{$T_1$ Spaces}\n}\n\n\n%--------------------------------\n\\begin{definition}\n\t[$R_0$ spaces]\n\t\\label{def: R_0 spaces}\n\tA topological space $(X, \\mathcal T)$ is said to be $R_0$ iff any two topologically distinguishable points in $X$ are separated.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[$T_1$ Spaces]\n\t\\label{def: T_1 spaces}\n\tA topological space $(X, \\mathcal T)$ is said to be $T_1$ or \\textit{Fr\\'echet} iff it is $T_0$ and $R_0$; i.e., all distinct pionts $x,y \\in X$ are separated.\n\\end{definition}\n%-------------------------------\n\n%--------------------------------\n\\begin{example}\n\t[$R_0$ but not $T_0$]\n\tLet $\\mathcal T$ be a countable family of disjoint proper intervals on $\\mathbb R^n$, and $\\bigcup \\mathcal T = \\mathbb R^n$. $(X, \\mathcal T)$ is $R_0$, but not $T_0$.\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\t[$T_0$ but not $R_0$]\n\t\\label{eg: T_0 but not T_1}\n\tLet $(\\mathbb R_{\\ge 0}, \\mathcal T)$ be a topological space with\n\t$$\n\t\\mathcal T = \\left\\{ U \\subseteq \\mathbb R : \\forall i \\in \\mathbb R_{\\ge 0}, \\ U_i = [0, i)  \\right\\},\n\t$$\n\tThen for all $x,y \\in (\\mathbb R_{\\ge 0}, \\mathcal T)$, if $x \\ne y$, then there are $|y - x|$ neighbourhoods $N_x$ of $x$ do not contain $y$. Thus, it is $T_0$.\n\n\tOn the other hand, it is not $R_0$, because for all $x, y \\in (\\mathbb R_{\\ge 0}, \\mathcal T)$ with $x < y$, $x \\in \\overline{\\{y\\}} = [0, y]$.\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\t[$R_0$ but not $T_1$]\n\t\\label{eg: R_0 but not T_1}\n\n\tLet $X$ be any set with $|X| \\ge 3$, let $U \\subsetneq X$ with $|U| \\ge 2$, let $\\mathcal T_{X \\setminus U}$ be a $T_1$ topology on $X \\setminus U$, and let $\\mathcal T$\n\t$$\n\t\\mathcal T = \\mathcal T_{X \\setminus U} \\cup \\{X, U\\}.\n\t$$\n\n\tFor all $x,y \\in X$, if $x \\ne y$, then they are separated. Thus, the space is $R_0$.\n\n\tBut $(X, \\mathcal T)$ is not $T_1$, because all $\\{u\\} \\in U$ share the same closure which is $U$ itself.\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{corollary}\n\t[alternative definitions of $R_0$ spaces]\n\t\\label{prop: alternative definitions of R_0 spaces}\n\tLet $(X, \\mathcal T)$ be $R_0$, then the following conditions are equivalent.\n\t\\begin{enumerate}[(i)]\n\t\t\\item\n\t\tThe closure of all singletons in $X$ are not $T_0$ subspace.\n\n\t\t\\item\n\t\tFor any two points $x,y \\in X$, $x \\in \\overline{ \\{y\\} }$ iff $y \\in \\overline{ \\{x\\} }$.\n\n\t\t\\item\n\t\tEvery open set is the union of closed sets.\n\t\\end{enumerate}\n\n\t\\begin{proof}\n\t\t\\\n\t\t\\begin{enumerate}[(i)]\n\t\t\t\\item\n\t\t\tBy Definition \\ref{def: R_0 spaces}, if $y$ and $x$ are topologically distinguishable, by Definition \\ref{def: R_0 spaces}, $x$ and $y$ are separated; i.e., $x \\notin \\overline {\\{y\\}}$ and $y \\notin \\overline{\\{x\\}}$.\n\n\t\t\t\\item\n\t\t\tBy Definition \\ref{def: R_0 spaces}, for all $x,y \\in X$, $x,y$ are not separated only if they are topologically indistinguishable. By Definition \\ref{def: topologically indistinguishable}, they share all their neighbourhoods, thus they have the same closure; i.e., $\\overline{\\{x\\}} = \\overline{\\{y\\}}$.\n\n\t\t\t\\item\n\t\t\tFor any $U \\in \\mathcal T$,\n\t\t\t$$\n\t\t\tU = \\bigcup_{x \\in U} \\{x\\}.\n\t\t\t$$\n\t\t\tIf $(X, \\mathcal T)$ is $T_1$, then we are done. Suppose $(X, \\mathcal T)$ is not $T_1$, then there exists $A \\in \\mathcal T$ with $|A| > 1$, and for all $B \\subsetneq A$, $B \\notin \\mathcal T$ (proof omitted). For such $A$, $X \\setminus A$ is open, for $X \\setminus A = \\bigcup (\\mathcal T \\setminus \\{A\\})$, thus $A$ is also closed.\n\n\t\t\tSuppose for any such $A$ with $A \\cap U \\ne \\emptyset$, $A \\subseteq U$. Suppose it fails, i.e., $A \\cap U \\ne A$, then we have $A \\cap U \\subsetneq A$ and $A \\cap U \\in \\mathcal T$, which is contradicted to the condition of $A$. Now we have\n\t\t\t$$\n\t\t\tU = \\bigcup \\mathcal A \\cup \\bigcup_{x \\in I} \\{x\\}\n\t\t\t$$\n\t\t\twhere $\\mathcal A$ is the family of such $A$, and $I$ is the union of all closed singletons in $U$. Thus $U$ is open.\n\t\t\\end{enumerate}\n\t\\end{proof}\n\\end{corollary}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{corollary}\n\t[alternative definitions of $T_1$ spaces]\n\t\\label{prop: alternative definitions of T_1 spaces}\n\tLet $(X, \\mathcal T)$ be $T_1$, then the following conditions are equivalent.\n\t\\begin{enumerate}[(i)]\n\t\t\\item All singletons in $X$ are closed.\n\t\t\\item Every subset of $X$ is the intersection of all open sets containing it.\n\t\t\\item Every cofinite subset of $X$ is open.\n\t\\end{enumerate}\n\n\n\t\\begin{proof} \\\n\t\t\\begin{enumerate}[(i)]\n\t\t\t\\item\n\t\t\tSuppose there exists $\\{x\\} \\subseteq X$ with $\\overline{\\{x\\}} \\ne \\{x\\}$, then there exists $y \\in \\overline{\\{x\\}}$ with $x \\ne y$. By Definition \\ref{def: T_1 spaces}, this is impossible.\n\n\t\t\t\\item\n\t\t\tFor any $A \\subseteq X$,\n\t\t\t$$\n\t\t\tA = \\bigcup_{x \\in A} \\{x\\}.\n\t\t\t$$\n\t\t\tLet $B = X \\setminus A$. By De Morgan's law,\n\t\t\t$$\n\t\t\tB = \\bigcap_{x \\in A} X \\setminus \\{x\\}.\n\t\t\t$$\n\t\t\t$(X, \\mathcal T)$ is $T_1$ iff all $\\{x\\}$ are closed, in which case, $B$ is the intersection of all open sets $X \\setminus \\{x\\} \\supseteq B$.\n\n\t\t\t\\item\n\t\t\tLet $A$ be a cofinite subset of $X$. $X \\setminus A$ is a finite union of singletons. As $(X, \\mathcal T)$ is $T_1$, any singletons in $X$ is closed. By Proposition \\ref{prop: dark side of topology}, $X \\setminus A$ is closed. By Definition \\ref{def: closed sets}, $A$ is open.�\n\t\t\\end{enumerate}\n\t\\end{proof}\n\\end{corollary}\n%--------------------------------\n\n\n\\centering{\n\t\\subsection*{Hausdorff Spaces}\n}\n\n\n%--------------------------------\n\\begin{definition}\n\t[$R_1$ spaces]\n\t\\label{def: R_1 spaces}\n\tA topological space $(X, \\mathcal T)$ is said to be $R_1$ iff any two topological distinguishable points in $X$ are separated by neighbourhoods.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[Hausdorff Spaces]\n\t\\label{def: Hausdorff spaces}\n\tA topological space $(X, \\mathcal T)$ is said to be \\textit{Hausdorff} or $T_2$ iff it is $T_0$ and $R_1$; i.e., all distinct points $x, y \\in X$ are separated by neighbourhoods.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{theorem}\n\tAll metrizable spaces are Hausdorff\n\n\t\\begin{proof}\n\t\tLet $(X, \\mathcal T)$ be a metrizable space. There exists a metric $\\rho$ on $X$ that induces $\\mathcal T$. Given distinct points $x,y \\in X$, suppose for all $\\varepsilon \\in \\mathbb R_{> 0}$, there exists $z \\in B(x, \\varepsilon) \\cap B(y, \\varepsilon)$. Then $\\rho(x, z) < \\varepsilon$ and $\\rho(y, z) < \\varepsilon$. Now we have\n\t\t$$\n\t\t\\rho(x, z) + \\rho(y, z) < 2\\varepsilon.\n\t\t$$\n\n\t\tPut $\\rho(x,y) > 2\\varepsilon$ as $x$ and $y$ are arbitrarily given. Then we have\n\t\t$$\n\t\t\\rho(x, z) + \\rho(y,z) < \\rho(x,y),\n\t\t$$\n\t\twhich implies that $\\rho$ is not a metric on $X$. Hence, $(X, \\mathcal T)$ is not metrizable which is contradicted to the condition.\n\t\\end{proof}\n\\end{theorem}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{theorem}\n\t\\label{prop: T2 implies T1}\n\tAll singletons in a Hausdorff space are closed.\n\n\t\\begin{proof}\n\t\tLet $(X, \\mathcal T)$ be a Hausdorff space, and let $x \\in X$. For all $y \\in X$ with $x \\ne y$, there is a open neighbourhood $U_y$ of $y$ such that $x \\notin U_y$. Then, for all such $U_y$, we have\n\t\t$$\n\t\t\\forall y \\in X, \\; x \\in X \\setminus U_y = \\{x\\} \\iff x \\in \\bigcap_{y \\in X \\setminus \\{x\\}} X \\setminus U_y  = \\{x\\}.\n\t\t$$\n\t\tAs all $X \\setminus U_y$ are closed, their intersection $\\{x\\}$ is closed.\n\t\\end{proof}\n\\end{theorem}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\t[$T_1$ but not Hausdorff]\n\t\\label{eg: T_1 but not T_2}\n\tLet $X$ be a nonempty set, let $p \\in X$, let $\\mathcal T'$ be a Hausdorff topology on $X \\setminus \\{p\\}$, and let\n\t$$\n\t\\mathcal T = \\{X\\} \\cup \\mathcal T'.\n\t$$\n\tThen, all $x \\in (X, \\mathcal T)$ are closed, thus $(X, \\mathcal T)$ is Fr\\'echet. But the only neighbourhood of $p$ is $X$, so its closure is $X$. Then, for any $x \\in X \\setminus \\{p\\}$, $x$ and $p$ are not separated, in which case $(X, \\mathcal T)$ is not $R_0$. Thus, $(X, \\mathcal T)$ is not Hausdorff.\n\\end{example}\n%--------------------------------\n", "meta": {"hexsha": "ebf02198af09937ea28f6482a01909b79ed7f63f", "size": 10730, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-v0/separation-axioms-1.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-v0/separation-axioms-1.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-v0/separation-axioms-1.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.3867595819, "max_line_length": 337, "alphanum_fraction": 0.5779123952, "num_tokens": 3531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851135937125, "lm_q2_score": 0.8652240947405564, "lm_q1q2_score": 0.7405030243238758}}
{"text": "\\section{Relations and Functions}\\label{sec:relations_and_functions}\n\\subsection{Basics}\nThe Cartesian product of two sets can be viewed as describing all possible connections between the elements of the first set to the elements of the second set, and thus any subset of a Cartesian product forms a specific \\emph{relation} between the sets.\n\n\\begin{example}{Relations as subsets of Cartesian products}{relation}\n\tGiven the following two sets:\n\t\\[\n\t\tA=\\{1,2,3,4\\},\\ B=\\{\\alpha,\\beta,\\gamma\\},\n\t\\]\n\tthen\n\t\\begin{align*}\n\t\tA\\times B = \\left\\{ (1,\\alpha),\\ (1,\\beta),\\ (1,\\gamma), \\right.\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t(2,\\alpha),\\ (2,\\beta),\\ (2,\\gamma),\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t(3,\\alpha),\\ (3,\\beta),\\ (3,\\gamma),\\\\\n\t\t\t\t\t\t\t  \\left.\t(4,\\alpha),\\ (4,\\beta),\\ (4,\\gamma) \\right\\}.\n\t\\end{align*}\n\n\tWe can choose the following pairs to form a subset of $A\\times B$:\n\t\\[\n\t\tR = \\left\\{ (1,\\beta),\\ (2,\\alpha),\\ (3,\\alpha),\\ (3,\\beta), (4,\\gamma)  \\right\\}.\n\t\\]\n\t$R$ is thus a relation between $A$ and $B$. We can graphically illustrate $R$ as follows:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\Large\n\t\t\t\n\t\t\t\\draw[thick, xred, fill=xred!20] (0,0) ellipse (0.5cm and 2cm) node[above, yshift=2cm] (Albl) {$A$};\n\t\t\t\\node (1) at (0,1.5cm) {$1$};\n\t\t\t\\node (2) at (0,0.5cm) {$2$};\n\t\t\t\\node (3) at (0,-0.5cm) {$3$};\n\t\t\t\\node (4) at (0,-1.5cm) {$4$};\n\t\t\t\n\t\t\t\\draw[thick, xgreen, fill=xgreen!20] (2.5cm,0) ellipse (0.5cm and 1.5cm) node[above, yshift=2cm] (Blbl) {$B$};\n\t\t\t\\node (alpha) at (2.5cm,1cm) {$\\alpha$};\n\t\t\t\\node (beta) at (2.5cm,0cm) {$\\beta$};\n\t\t\t\\node (gamma) at (2.5cm,-1cm) {$\\gamma$};\n\n\t\t\t\\draw[arrow] (1) -- (beta);\n\t\t\t\\draw[arrow] (2) -- (alpha);\n\t\t\t\\draw[arrow] (3) -- (alpha);\n\t\t\t\\draw[arrow] (3) -- (gamma);\n\t\t\t\\draw[arrow] (4) -- (beta);\n\n\t\t\t\\draw[arrow] (Albl) -- (Blbl) node[midway, above] {$R$};\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\\end{example}\n\nRelations can be inverted by reversing the order of each of its pairs.\n\n\\begin{example}{Inverse relation}{inv_relation}\n\tThe inverse relation to the relation in \\autoref{example:relation} is\n\t\\[\n\t\tR^{-1} = \\left\\{ (\\beta,1),\\ (\\alpha,2),\\ (\\alpha,3),\\ (\\beta,3), (\\gamma,4)  \\right\\}.\n\t\\]\n\tGraphically:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\Large\n\t\t\t\n\t\t\t\\draw[thick, xred, fill=xred!20] (0,0) ellipse (0.5cm and 2cm) node[above, yshift=2cm] (Albl) {$A$};\n\t\t\t\\node (1) at (0,1.5cm) {$1$};\n\t\t\t\\node (2) at (0,0.5cm) {$2$};\n\t\t\t\\node (3) at (0,-0.5cm) {$3$};\n\t\t\t\\node (4) at (0,-1.5cm) {$4$};\n\t\t\t\n\t\t\t\\draw[thick, xgreen, fill=xgreen!20] (2.5cm,0) ellipse (0.5cm and 1.5cm) node[above, yshift=2cm] (Blbl) {$B$};\n\t\t\t\\node (alpha) at (2.5cm,1cm) {$\\alpha$};\n\t\t\t\\node (beta) at (2.5cm,0cm) {$\\beta$};\n\t\t\t\\node (gamma) at (2.5cm,-1cm) {$\\gamma$};\n\n\t\t\t\\draw[arrow] (beta) -- (1);\n\t\t\t\\draw[arrow] (alpha) -- (2);\n\t\t\t\\draw[arrow] (alpha) -- (3);\n\t\t\t\\draw[arrow] (gamma) -- (3);\n\t\t\t\\draw[arrow] (beta) -- (4);\n\n\t\t\t\\draw[arrow] (Blbl) -- (Albl) node[midway, above] {$R^{-1}$};\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\\end{example}\n\nA \\emph{function} $f$ from a set $A$ to a set $B$ is a relation for which any element in $A$ is connected to a single element in $B$.\n\n\\begin{example}{Functions}{functions}\n\tThe following are two functions from the set $A$ to the set $B$ defined in \\autoref{example:relation}:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\Large\n\t\t\t% f\n\t\t\t\\draw[thick, xred, fill=xred!20] (0,0) ellipse (0.5 and 2) node[above, yshift=2cm] (Albl) {$A$};\n\t\t\t\\node (1f) at (0,1.5) {$1$};\n\t\t\t\\node (2f) at (0,0.5) {$2$};\n\t\t\t\\node (3f) at (0,-0.5) {$3$};\n\t\t\t\\node (4f) at (0,-1.5) {$4$};\n\t\t\t\n\t\t\t\\draw[thick, xgreen, fill=xgreen!20] (2.5,0) ellipse (0.5 and 1.5) node[above, yshift=2cm] (Blbl) {$B$};\n\t\t\t\\node (alpha_f) at (2.5,1) {$\\alpha$};\n\t\t\t\\node (beta_f) at (2.5,0) {$\\beta$};\n\t\t\t\\node (gamma_f) at (2.5,-1) {$\\gamma$};\n\n\t\t\t\\draw[arrow] (1f) -- (alpha_f);\n\t\t\t\\draw[arrow] (2f) -- (beta_f);\n\t\t\t\\draw[arrow] (3f) -- (gamma_f);\n\t\t\t\\draw[arrow] (4f) -- (gamma_f);\n\n\t\t\t\\draw[arrow] (Albl) -- (Blbl) node[midway, above] {$f$};\n\t\t\t\n\t\t\t% g\n\t\t\t\\draw[thick, xred, fill=xred!20] (6,0) ellipse (0.5 and 2) node[above, yshift=2cm] (Albl) {$A$};\n\t\t\t\\node (1g) at (6,1.5)  {$1$};\n\t\t\t\\node (2g) at (6,0.5)  {$2$};\n\t\t\t\\node (3g) at (6,-0.5) {$3$};\n\t\t\t\\node (4g) at (6,-1.5) {$4$};\n\t\t\t\n\t\t\t\\draw[thick, xgreen, fill=xgreen!20] (8.5,0) ellipse (0.5 and 1.5) node[above, yshift=2cm] (Blbl) {$B$};\n\t\t\t\\node (alpha_g) at (8.5,1) {$\\alpha$};\n\t\t\t\\node (beta_g) at  (8.5,0) {$\\beta$};\n\t\t\t\\node (gamma_g) at (8.5,-1) {$\\gamma$};\n\n\t\t\t\\draw[arrow] (1g) -- (alpha_g);\n\t\t\t\\draw[arrow] (2g) -- (gamma_g);\n\t\t\t\\draw[arrow] (3g) -- (beta_g);\n\t\t\t\\draw[arrow] (4g) -- (alpha_g);\n\n\t\t\t\\draw[arrow] (Albl) -- (Blbl) node[midway, above] {$g$};\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\t\t\n\tThe pairs making up $f$ are $(1,\\alpha),\\ (2,\\beta),\\ (3,\\gamma)$ and $(4,\\gamma)$, and the pairs making up $g$ are $(1,\\alpha),\\ (2,\\gamma),\\ (3,\\beta)$ and $(4,\\alpha)$.\n\\end{example}\n\n\\begin{note}{Relations which are not functions}{}\n\tNote that the relation in \\autoref{example:relation} is \\textbf{not} a function, since the element $3\\in A$ is connected to more than one element in $B$, namely $\\alpha$ and $\\gamma$.\n\\end{note}\n\nDifferent names are used in some branches of mathematics to describe functions, such as \\emph{maps} and \\emph{transformations}. Barring context, they all mean the same thing.\n\nA common way to denote that a function $f$ is connecting elements in $A$ to elements in $B$ is\n\\begin{equation}\n\tf: A\\to B.\n\t\\label{eq:function_basics}\n\\end{equation}\n$A$ is called the \\emph{domain} of $f$, and $B$ its \\emph{image}. In this book and many other sources, the following notation is used: $f(x)=y$, which means that when we apply the function $f$ to an element $x\\in A$, the result is the element it is connected to, i.e. $y\\in B$. We write this as $x\\mapsto y$ (the special symbol $\\mapsto$ is called a \\emph{mapping notation}).\n\n\\begin{example}{Value $\\mapsto$ value notation for functions}{}\n\tFor the functions $f,g$ as defined in \\autoref{example:functions}:\n\t\\begin{align*}\n\t\t&f(1)=\\alpha,\\ f(2)=\\beta,\\ f(3)=f(4)=\\gamma.\\\\\n\t\t&g(1)=g(4)=\\alpha,\\ g(2)=\\gamma,\\ g(3)=\\beta.\n\t\\end{align*}\n\\end{example}\n\n\\subsection{Injective, surjective and bijective functions}\nA function is \\emph{injective} if each of the elements in its \\textbf{image} is connected to by at most a single element in its \\textbf{domain}. An injective function is also known as an \\emph{injection}.\n\n\\begin{example}{Injective function}{injective}\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.9]\n% Injective function\n\t\t\\fill[xred!20, draw=xred, thick] (0,0) circle (0.75cm and 2cm) node[above, yshift=2cm, text=xred] (A) {$A$};\n\t\t\\node (A1) at (0,1.5) {$1$};\n\t\t\\node (A2) at (0,0.5) {$2$};\n\t\t\\node (A3) at (0,-0.5) {$3$};\n\t\t\\node (A4) at (0,-1.5) {$4$};\n\n\t\t\\fill[xgreen!20, draw=xgreen, thick] (2,0) circle (0.75cm and 1.75cm) node[above, yshift=2cm, text=xgreen] (B) {$B$};\n\t\t\\node (B1) at (2,1.2) {$\\alpha$};\n\t\t\\node (B2) at (2,0.4) {$\\beta$};\n\t\t\\node (B3) at (2,-0.4) {$\\gamma$};\n\t\t\\node (B4) at (2,-1.2) {$\\delta$};\n\n\t\t\\draw[arrow] (A1) -- (B2);\n\t\t\\draw[arrow] (A2) -- (B3);\n\t\t\\draw[arrow] (A3) -- (B1);\n\t\t\\draw[arrow] (A4) -- (B4);\n\n\t\t\\draw[arrow] (A) to node[midway, above, yshift=2mm] {Injective} (B);\n\n% Non injective function\n\t\t\\fill[xred!20, draw=xred, thick] (6,0) circle (0.75cm and 2cm) node[above, yshift=2cm, text=xred] (A) {$A$};\n\t\t\\node (A1b) at (6,1.5) {$1$};\n\t\t\\node (A2b) at (6,0.75) {$2$};\n\t\t\\node (A3b) at (6,0) {$3$};\n\t\t\\node (A4b) at (6,-0.75) {$4$};\n\t\t\\node (A5b) at (6,-1.5) {$5$};\n\n\t\t\\fill[xgreen!20, draw=xgreen, thick] (8,0) circle (0.75cm and 1.75cm) node[above, yshift=2cm, text=xgreen] (B) {$B$};\n\t\t\\node (B1b) at (8,1.2) {$\\alpha$};\n\t\t\\node (B2b) at (8,0.4) {$\\beta$};\n\t\t\\node (B3b) at (8,-0.4) {$\\gamma$};\n\t\t\\node (B4b) at (8,-1.2) {$\\delta$};\n\n\t\t\\draw[arrow] (A1b) -- (B1b);\n\t\t\\draw[arrow, red] (A2b) -- (B2b);\n\t\t\\draw[arrow, red] (A3b) -- (B2b);\n\t\t\\draw[arrow] (A4b) -- (B3b);\n\t\t\\draw[arrow] (A5b) -- (B4b);\n\n\t\t\\draw[arrow] (A) to node[midway, above, yshift=2mm] {Non-injective} (B);\n\t\\end{tikzpicture}\n\n\t\\flushleft\n\tThe function on the right in non-injective because the element $\\beta\\in B$ is connected to by two elements in $A$ ($2$ and $3$, red arrows).\n\\end{example}\n\nA function is \\emph{surjective} if every element in its image is connected to by at least a single element in its domain (see \\autoref{example:surjective}). As with injective functions, a surjective function is also known as a \\emph{surjection}. A non surjective function can be made into surjective function by excluding from its image any element that is not connected to by any element from its domain (see \\autoref{example:surjectification}).\n\nA function $f:A\\to B$ that is both surjective and bijective is called a \\emph{bijective function} (also a \\emph{bijection}). All elements in the image of a bijection are connected to by exactly a single element in its domain. This means that the direction of the connections can be flipped, yielding the \\emph{inverse} of the original function (denoted $f^{-1}$).\n\nThe reason only bijective functions have inverses is as follows: Given a function $f:A\\to B$,\n\\begin{itemize}\n\t\\item if $f$ is non-injective, then there is at least one element $y_{1}\\in B$ which is connected to by at least two elements from $A$. We can name these elements $x_{1}$ and $x_{2}$. When inverted, $f^{-1}:B\\to A$ has an element $y_{1}\\in B$ (note that for $f^{-1}$, $B$ is its domain), which is connected to two or more elements in $A$, the image of $f^{-1}$. These are of course $x_{1},x_{2}$. This fact disqualifies $f^{-1}$ from being a function.\n\t\\item If $f$ is non-surjective, then there exists at least one element $y_{2}\\in B$ that is not connected to by any element from $A$. When inverted, $y_{2}$ in the domain $B$ of $f^{-1}$ is not connected to any element in its image $A$. This fact disqualifies $f^{-1}$ from being a function.\n\\end{itemize}\n\n \\blindtext\n\n\n\n\\begin{example}{Surjective function}{surjective}\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.9]\n\t\t% Surjection\n\t\t\\fill[xred!20, draw=xred, thick] (0,0) circle (0.75cm and 2cm) node[above, yshift=2cm, text=xred] (A) {$A$};\n\t\t\\node (A1) at (0,1.5) {$1$};\n\t\t\\node (A2) at (0,0.5) {$2$};\n\t\t\\node (A3) at (0,-0.5) {$3$};\n\t\t\\node (A4) at (0,-1.5) {$4$};\n\n\t\t\\fill[xgreen!20, draw=xgreen, thick] (2,0) circle (0.75cm and 1.75cm) node[above, yshift=2cm, text=xgreen] (B) {$B$};\n\t\t\\node (B1) at (2,1.2) {$\\alpha$};\n\t\t\\node (B2) at (2,0.4) {$\\beta$};\n\t\t\\node (B3) at (2,-0.4) {$\\gamma$};\n\t\t\\node (B4) at (2,-1.2) {$\\delta$};\n\n\t\t\\draw[arrow] (A1) -- (B2);\n\t\t\\draw[arrow] (A2) -- (B3);\n\t\t\\draw[arrow] (A3) -- (B1);\n\t\t\\draw[arrow] (A4) -- (B4);\n\n\t\t\\draw[arrow] (A) to node[midway, above, yshift=2mm] {Surjective} (B);\n\n\t\t% Non surjection\n\t\t\\fill[xred!20, draw=xred, thick] (6,0) circle (0.75cm and 2cm) node[above, yshift=2cm, text=xred] (A) {$A$};\n\t\t\\node (A1b) at (6,1.5) {$1$};\n\t\t\\node (A2b) at (6,0.75) {$2$};\n\t\t\\node (A3b) at (6,0) {$3$};\n\t\t\\node (A4b) at (6,-0.75) {$4$};\n\t\t\\node (A5b) at (6,-1.5) {$5$};\n\n\t\t\\fill[xgreen!20, draw=xgreen, thick] (8,0) circle (0.75cm and 1.75cm) node[above, yshift=2cm, text=xgreen] (B) {$B$};\n\t\t\\node (B1b) at (8,1.2) {$\\alpha$};\n\t\t\\node (B2b) at (8,0.4) {$\\beta$};\n\t\t\\node (B3b) at (8,-0.4) {$\\gamma$};\n\t\t\\node (B4b) at (8,-1.2) {$\\delta$};\n\n\t\t\\draw[arrow] (A1b) -- (B1b);\n\t\t\\draw[arrow, red] (A2b) -- (B2b);\n\t\t\\draw[arrow, red] (A3b) -- (B2b);\n\t\t\\draw[arrow] (A4b) -- (B3b);\n\t\t\\draw[arrow] (A5b) -- (B4b);\n\n\t\t\\draw[arrow] (A) to node[midway, above, yshift=2mm] {Non-surjective} (B);\n\t\\end{tikzpicture}\n\\end{example}\n\n\\begin{example}{Making a non-surjective function into a surjection}{surjectification}\n\tGiven the two sets $A=\\{1,2,3,4\\}$ and $B=\\{\\alpha,\\beta,\\gamma,\\delta\\}$, the following non-surjective function $f:A\\to B$ is defined:\n\t\\[\n\t\tf = \\left\\{ (1,\\alpha),\\ (2,\\beta),\\ (3,\\gamma),\\ (4,\\gamma) \\right\\}.\n\t\\]\n\n\tBy removing $\\delta$ from $B$, the function $f$ becomes surjective (though it remains non-injective).\n\\end{example}\n\n\\begin{example}{Cross examples}{}\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.9]\n\t\t% Injection not surjection\n\t\t\\fill[xred!20, draw=xred, thick] (0,0) circle (0.75cm and 2cm) node[above, yshift=2cm, text=xred] (A) {$A$};\n\t\t\\node (A1) at (0,1) {$1$};\n\t\t\\node (A2) at (0,0)\t{$2$};\n\t\t\\node (A3) at (0,-1) {$3$};\n\n\t\t\\fill[xgreen!20, draw=xgreen, thick] (2,0) circle (0.75cm and 1.75cm) node[above, yshift=2cm, text=xgreen] (B) {$B$};\n\t\t\\node (B1) at (2,1.05) {$\\alpha$};\n\t\t\\node (B2) at (2,0.35) {$\\beta$};\n\t\t\\node (B3) at (2,-0.35) {$\\gamma$};\n\t\t\\node (B3) at (2,-1.05) {$\\delta$};\n\n\t\t\\draw[arrow] (A1) -- (B1);\n\t\t\\draw[arrow] (A2) -- (B2);\n\t\t\\draw[arrow] (A3) -- (B3);\n\n\t\t\\draw[arrow] (A) to node[midway, above, yshift=2mm] {Injective, non surjective} (B);\n\t\t\n\t\t% Surjection not injection\n\t\t\\fill[xred!20, draw=xred, thick] (6,0) circle (0.75cm and 2cm) node[above, yshift=2cm, text=xred] (A) {$A$};\n\t\t\\node (A1) at (6,1.5) {$1$};\n\t\t\\node (A2) at (6,0.5)\t{$2$};\n\t\t\\node (A3) at (6,-0.5) {$3$};\n\t\t\\node (A4) at (6,-1.5) {$4$};\n\n\t\t\\fill[xgreen!20, draw=xgreen, thick] (8,0) circle (0.75cm and 1.75cm) node[above, yshift=2cm, text=xgreen] (B) {$B$};\n\t\t\\node (B1) at (8,1.05) {$\\alpha$};\n\t\t\\node (B2) at (8,0.35) {$\\beta$};\n\t\t\\node (B3) at (8,-0.35) {$\\gamma$};\n\t\t\\node (B4) at (8,-1.05) {$\\delta$};\n\n\t\t\\draw[arrow] (A1) -- (B1);\n\t\t\\draw[arrow] (A2) -- (B2);\n\t\t\\draw[arrow] (A3) -- (B3);\n\t\t\\draw[arrow] (A4) -- (B3);\n\n\t\t\\draw[arrow] (A) to node[midway, above, yshift=2mm] {Injective, non surjective} (B);\n\t\\end{tikzpicture}\n\n\t\\vspace{1em}\n\t\\begin{tikzpicture}[scale=0.9]\n\t\t% Injection and surjection\n\t\t\\fill[xred!20, draw=xred, thick] (0,0) circle (0.75cm and 2cm) node[above, yshift=2cm, text=xred] (A) {$A$};\n\t\t\\node (A1) at (0,1.5) {$1$};\n\t\t\\node (A2) at (0,0.5)\t{$2$};\n\t\t\\node (A3) at (0,-0.5) {$3$};\n\t\t\\node (A4) at (0,-1.5) {$4$};\n\n\t\t\\fill[xgreen!20, draw=xgreen, thick] (2,0) circle (0.75cm and 1.75cm) node[above, yshift=2cm, text=xgreen] (B) {$B$};\n\t\t\\node (B1) at (2,1.05) {$\\alpha$};\n\t\t\\node (B2) at (2,0.35) {$\\beta$};\n\t\t\\node (B3) at (2,-0.35) {$\\gamma$};\n\t\t\\node (B4) at (2,-1.05) {$\\delta$};\n\n\t\t\\draw[arrow] (A1) -- (B1);\n\t\t\\draw[arrow] (A2) -- (B3);\n\t\t\\draw[arrow] (A3) -- (B2);\n\t\t\\draw[arrow] (A4) -- (B4);\n\n\t\t\\draw[arrow] (A) to node[midway, above, yshift=2mm] {Injective and surjective} (B);\n\t\t\n\t\t% Surjection not injection\n\t\t\\fill[xred!20, draw=xred, thick] (6,0) circle (0.75cm and 2cm) node[above, yshift=2cm, text=xred] (A) {$A$};\n\t\t\\node (A1) at (6,1.5) {$1$};\n\t\t\\node (A2) at (6,0.5)\t{$2$};\n\t\t\\node (A3) at (6,-0.5) {$3$};\n\t\t\\node (A4) at (6,-1.5) {$4$};\n\n\t\t\\fill[xgreen!20, draw=xgreen, thick] (8,0) circle (0.75cm and 1.75cm) node[above, yshift=2cm, text=xgreen] (B) {$B$};\n\t\t\\node (B1) at (8,1.05) {$\\alpha$};\n\t\t\\node (B2) at (8,0.35) {$\\beta$};\n\t\t\\node (B3) at (8,-0.35) {$\\gamma$};\n\t\t\\node (B4) at (8,-1.05) {$\\delta$};\n\n\t\t\\draw[arrow] (A1) -- (B1);\n\t\t\\draw[arrow] (A2) -- (B1);\n\t\t\\draw[arrow] (A3) -- (B2);\n\t\t\\draw[arrow] (A4) -- (B3);\n\n\t\t\\draw[arrow] (A) to node[midway, above, yshift=2mm] {Neither injective nor surjective} (B);\n\t\\end{tikzpicture}\n\\end{example}\n\n\\vspace{2em}\n\\begin{note}{Other names for bijections}{bijections}\n\tBijections are also called \\emph{one-to-one correspondences} and \\emph{invertible functions}.\n\\end{note}\n\n\\subsection{Real functions}\nIn suitable cases, a function is defined via a general mapping rule. This should be very familiar to anyone who learned mathematics in high school, where many times functions are defined this way, e.g.\n\\begin{equation}\n\tf(x) = x^{2}+3x-4.\n\t\\label{eq:function_by_formula}\n\\end{equation}\n\nIn mapping notation we can write \\autoref{eq:function_by_formula} as $f:x\\mapsto x^{2}+3x-4$. In high school mathematics, both the domain and image of such functions is $\\mathbb{R}$, although it is almost never specified explicitly. Such functions are commonly referred to as \\emph{real functions}, a convention used in this book as well.\n\n\\begin{example}{Functions defined using a mapping rule}{}\n\tThe following are real functions:\n\t\\[\n\t\tf_{1}(x) = 2x^{2}-5,\\quad f_{2}(x)=\\sin\\left( \\frac{x}{3} \\right),\\quad f_{3}(x)=\\frac{1}{\\sqrt{2\\pi}}\\eu^{-\\frac{(x-\\mu)^{2}}{\\sigma^{2}}}.\n\t\\]\n\n\tNote that these functions can also be defined using different sets, for example $f_{1}:\\mathbb{N}\\to\\mathbb{Z},\\quad f_{2}:\\mathbb{N}\\to[-1,1],\\quad$ etc.\n\\end{example}\n\nReal functions can be easily plotted in a \\emph{Cartesian coordinate system} by drawing all the points $\\left( x,f(x) \\right)$ (i.e. all the points $\\left( x,y \\right)$, where $x,y\\in\\mathbb{R}$ and $x\\mapsto y$). We call these points the \\emph{graph} of $f$ over $\\mathbb{R}$.\n\n\\begin{example}{Graphs of real functions}{graph_of_functions}\n\tThe following two functions are plotted on the domain $\\left[ -9,9 \\right]$:\n\n\t\\begin{minipage}{0.35\\textwidth}\n\t\t\\begin{itemize}\n\t\t\t\\item \\textcolor{xred}{$\\bm{f(x)=x^{2}-2x-3}$},\n\t\t\t\\item \\textcolor{xgreen}{$\\bm{g(x)=4\\eu^{x}/\\left( \\eu^{x}+1 \\right)}$}.\n\t\t\\end{itemize}\n\t\\end{minipage}%\n\t\\begin{minipage}[c]{0.65\\textwidth}\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\tgraph2d,\n\t\t\t\t\twidth=9cm, height=6cm,\n\t\t\t\t\txmin=-9, xmax=9,\n\t\t\t\t\tymin=-5, ymax=5,\n\t\t\t\t\tdomain=-9:9,\n\t\t\t\t\trestrict y to domain=-5:5,\n\t\t\t\t\tdeclare function={f(\\x)=\\x^2-2*\\x-3;},\n\t\t\t\t\tdeclare function={g(\\x)=4*exp(\\x)/(1+exp(\\x));},\n\t\t\t\t]\n\t\t\t\t\\addplot[function, color=xred] {f(x)};\n\t\t\t\t\\addplot[function, color=xgreen] {g(x)};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\\end{minipage}\n\\end{example}\n\nIn \\autoref{example:graph_of_functions}, the function $g(x)$ always increases in value from left to right. Let's give this notion a more formal tone: a function $f$ is said to be \\emph{increasing} on an interval $I$ if for any $x_{1},x_{2}\\in I$, if $x_{2}>x_{1}$ then $f\\left( x_{2} \\right) > f\\left( x_{1} \\right)$. We can similarily define the idea of \\emph{decreasing} on an interval.\n\nA property of some functions which is visually easy to depict is symmetry. A real function $f$ is said to be \\emph{symmetric} if for any $x\\in\\mathbb{R},\\ f(-x)=f(x)$. This essentially means that the $y$-axis mirrors the function's plot. If for any $x\\in\\mathbb{R},\\ f(-x)=-f(x)$, we say that the function is \\emph{anti-symmetric}. A function can be neither, but there's only a single function which is both: the zero function, i.e. $f(x)=0$.\n\n\\begin{example}{Symmetric and anti-symmetric functions}{function_symmetry}\n\tIn the following graphs, the function on the top is symmetric, while the function on the bottom is anti-symmetric:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\tgraph2d,\n\t\t\t\t\twidth=13cm, height=8cm,\n\t\t\t\t\txmin=-5, xmax=5,\n\t\t\t\t\tymin=-1.5, ymax=1.5,\n\t\t\t\t\tdomain=-6:6,\n\t\t\t\t\trestrict y to domain=-1.5:1.5,\n\t\t\t\t]\n\t\t\t\t\\addplot[function, xred] {(2*\\x^2-2)*exp(-1/\\x^2)/\\x^4};\n\t\t\t\t%\\addplot[function, xblue] {(2*\\x^2-2)*exp(-1/\\x^2)/\\x^5};\n\n\t\t\t\t\t%\\left(2x^{2}-2\\right)\\cdot\\frac{\\exp\\left(-\\frac{1}{x^{2}}\\right)}{x^{4}}\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\tgraph2d,\n\t\t\t\t\twidth=13cm, height=8cm,\n\t\t\t\t\txmin=-4, xmax=4,\n\t\t\t\t\tymin=-2, ymax=2,\n\t\t\t\t\tdomain=-4:4,\n\t\t\t\t\trestrict y to domain=-2:2,\n\t\t\t\t]\n\t\t\t\t\\addplot[function, xblue] {(2*\\x^2-2)*exp(-1/\\x^2)/\\x^5};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\\end{example}\n\n(injections/surjections of real functions?)\n \nA real function is said to be \\emph{periodic} if it repeats its values exactly over and over with increasing $x$. In more precise terms we define a real function $f$ to be periodic if for any integer value $k$,\n\\begin{equation}\n\tf(x+kT) = f(x).\n\t\\label{eq:periodic function}\n\\end{equation}\nwhere $T=[a,b]$ is a finite interval of $\\mathbb{R}$ which we call the \\emph{period} of the function.\n\n\\begin{example}{A periodic function}{periodic function}\n\tThe following graph depicts a periodic function $f$, with its period $T$ shown. Notice that for any $x\\ f(x+T)=f(x)$, i.e. you can move the period measure left and right along the $x$-axis and the values of $f(x)$ in both its edges would always be the equal.\n\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\t\tgraph2d,\n\t\t\t\twidth=14cm, height=6cm,\n\t\t\t\txmin=-15, xmax=15,\n\t\t\t\tymin=-5, ymax=5,\n\t\t\t\txticklabels={},\n\t\t\t\tyticklabels={},\n\t\t\t\tdomain=-15:15,\n\t\t\t\trestrict y to domain=-6:6,\n\t\t\t\tsamples=350,\n\t\t\t]\n\t\t\t\\addplot[function, xgreen] {0.8*sin(deg(2*\\x))+1.5*sin(deg(\\x))};\n\t\t\t\\draw[|-|, thick] (1,4) -- node[midway, below] {$T$} ({2*pi+1},4);\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\\end{example}\n\nTwo additional measures that arise from a period $T$ are the \\emph{frequency} $f=\\frac{1}{T}$, and the \\emph{angular frequency} $\\omega=2\\pi f=\\frac{2\\pi}{T}$. We will use these measures later in the book.\n\n\\vspace{2em}\n\\begin{note}{Units of period and frequency}{}\n\tIn a periodic function such as the one in the above example, the units for the period are the same one used for the horizontal axis, while the units of both frequency and angular frequency are both 1 over the unit used for the horizontal axis/period. For example, if the unit of the horizontal axis is that of seconds, then the frequency units are 1/seconds, i.e. Hertz (SI symbol: \\si{Hz}).\n\\end{note}\n\n\\subsection{Composition of functions}\nFunctions can be \\emph{composed} together, generating new functions. Given two functions $f:A\\to B$ and $g:B\\to C$, their composition is denoted as $f\\circ g$. For the composition to be well defined, the \\textbf{image} of $f$ must be the same as the \\textbf{domain} of $g$, and the resulting composition would have $A$ as its domain and $C$ as its image, i.e. $f\\circ g:A\\to C$.\n\n\\begin{example}{Composition of functions}{composition}\n\tConsider the functions\n\t\\[\n\t\tf(x)=x^{2},\\quad g(x)=\\sin(x).\n\t\\]\n\tUsing these functions, the two possible compositions are\n\t\\begin{itemize}\n\t\t\\item $f\\circ g = f\\left( g(x) \\right) = \\left[ \\sin(x) \\right]^{2}$, and\n\t\t\\item $g\\circ f = g\\left( f(x) \\right) = \\sin\\left( x^{2} \\right)$.\n\t\\end{itemize}\n\\end{example}\n\n\\begin{example}{Graphical representation of function composition}{}\n\tA graphical representation of composing two functions:\n\t\\[\n\t\tf:\\{1,2,3,4\\}\\to\\{\\alpha,\\beta,\\gamma,\\delta\\},\\quad g:\\{\\alpha,\\beta,\\gamma,\\delta\\}\\to\\{a,b,c\\}.\n\t\\]\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}[scale=0.9]\n\t\t\t\\fill[xred!20, draw=xred, thick] (0,0) circle (0.75cm and 2cm);\n\t\t\t\\node (A1) at (0,1.5) {$1$};\n\t\t\t\\node (A2) at (0,0.5) {$2$};\n\t\t\t\\node (A3) at (0,-0.5) {$3$};\n\t\t\t\\node (A4) at (0,-1.5) {$4$};\n\n\t\t\t\\fill[xpurple!20, draw=xpurple, thick] (3,0) circle (0.75cm and 2cm);\n\t\t\t\\node (B1) at (3,1.2) {$\\alpha$};\n\t\t\t\\node (B2) at (3,0.4) {$\\beta$};\n\t\t\t\\node (B3) at (3,-0.4) {$\\gamma$};\n\t\t\t\\node (B4) at (3,-1.2) {$\\delta$};\n\n\t\t\t\\draw[arrow, thick] (1,2) -- node [midway, above] {$f$} ++(1,0);\n\t\t\t\\draw[arrow, thick] (4,2) -- node [midway, above] {$g$} ++(1,0);\n\n\t\t\t\\fill[xgreen!20, draw=xgreen, thick] (6,0) circle (0.75cm and 1.75cm);\n\t\t\t\\node (C1) at (6,1) {$a$};\n\t\t\t\\node (C2) at (6,0) {$b$};\n\t\t\t\\node (C3) at (6,-1) {$c$};\n\n\t\t\t\\draw[arrow] (A1) -- (B2);\n\t\t\t\\draw[arrow] (A2) -- (B4);\n\t\t\t\\draw[arrow] (A3) -- (B1);\n\t\t\t\\draw[arrow] (A4) -- (B3);\n\t\t\t\\draw[arrow] (B1) -- (C2);\n\t\t\t\\draw[arrow] (B2) -- (C3);\n\t\t\t\\draw[arrow] (B3) -- (C1);\n\t\t\t\\draw[arrow] (B4) -- (C3);\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\t\n\tThe composition results in the following function\n\t\\[\n\t\tf\\circ g:\\{1,2,3,4\\}\\to\\{a,b,c,\\}.\n\t\\]\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}[scale=0.9]\n\t\t\t\\fill[xred!20, draw=xred, thick] (0,0) circle (0.75cm and 2cm);\n\t\t\t\\node (A1) at (0,1.5) {$1$};\n\t\t\t\\node (A2) at (0,0.5) {$2$};\n\t\t\t\\node (A3) at (0,-0.5) {$3$};\n\t\t\t\\node (A4) at (0,-1.5) {$4$};\n\n\t\t\t\\draw[arrow, thick] (1,2) -- node [midway, above] {$f\\circ g$} ++(1,0);\n\n\t\t\t\\fill[xgreen!20, draw=xgreen, thick] (3,0) circle (0.75cm and 1.75cm);\n\t\t\t\\node (C1) at (3,1) {$a$};\n\t\t\t\\node (C2) at (3,0) {$b$};\n\t\t\t\\node (C3) at (3,-1) {$c$};\n\n\t\t\t\\draw[arrow] (A1) -- (C3);\n\t\t\t\\draw[arrow] (A2) -- (C3);\n\t\t\t\\draw[arrow] (A3) -- (C2);\n\t\t\t\\draw[arrow] (A4) -- (C1);\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\\end{example}\n", "meta": {"hexsha": "ce508f4bbe59e79181e7f28d9b67d34bf20bf7c9", "size": 23928, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/intro/relations_functions.tex", "max_stars_repo_name": "barak/maths_book", "max_stars_repo_head_hexsha": "da47454d85ed7c5167d7951bb5c29c28d987b107", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2021-12-25T20:02:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T17:57:59.000Z", "max_issues_repo_path": "chapters/intro/relations_functions.tex", "max_issues_repo_name": "barak/maths_book", "max_issues_repo_head_hexsha": "da47454d85ed7c5167d7951bb5c29c28d987b107", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2022-01-17T05:01:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-20T06:18:24.000Z", "max_forks_repo_path": "chapters/intro/relations_functions.tex", "max_forks_repo_name": "barak/maths_book", "max_forks_repo_head_hexsha": "da47454d85ed7c5167d7951bb5c29c28d987b107", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2022-01-17T10:15:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-02T10:45:13.000Z", "avg_line_length": 41.3979238754, "max_line_length": 452, "alphanum_fraction": 0.6128803076, "num_tokens": 9777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017535, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7405030204829265}}
{"text": "\\part{Solutions}\n\\setcounter{chapter}{0}\n\n\\ifthenelse{\\boolean{createspace} }{\n}\n{\n\\renewcommand{\\chaptermark}[1]{\n\\ifthenelse{\\boolean{kindle1}}{\\makeoddhead{kindle1page}{\\scriptsize{Ch.~\\arabic{chapter}}}{\\scriptsize \\em Solutions}{\\scriptsize #1} }{}\n}\n}\n\n\n\\chapter{ Searching}\\normalsize\n\n\n\\ans{sqrt}\nOne of the fastest ways to invert a fast-growing monotone function (such as the square function) \nis to do a binary search in a precomputed table of the function. \nSince the square root for the largest 32-bit unsigned integer can be represented in 16 bits, we build an array of\nlength $2^{16}$ such that $i$-th element in the array is $i^2$. When\nwe want to compute square root for a given number $n$, we look for the\nlargest number in the array that is still smaller than $n$.  Because\nthe square root is relatively small, it is faster to compute it on the fly\nthan to precompute it.\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nunsigned int sqrt_search(unsigned int input) {\n  int begin = 0;\n  int end = 65536;\n  while(begin + 1 < end){\n    int mid = begin + (end - begin) / 2;\n      unsigned int mid_sqr = mid * mid;\n    if (mid_sqr == input) {\n      return mid;\n    } else if (mid_sqr > input) {\n      end = mid;\n    } else {\n      begin = mid;\n    }\n  }\n  return begin;\n}\n\\end{lstlisting}\n\n\\ans{bin-search}\n% We implemented binary search through an array in Problem~\\ref{sqrt}.\n% from file BinSearch.java\n% run as javac BinSearch.java ; java -ea -cp . BinSearch\n\\lstinputlisting[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Java]{BinSearch.java}\n\n\\ans{bin-search-next}\nA straightforward way to find an element larger than \na given value $k$ is to look for $k$ via a \nbinary search and then, if $k$ is found, walk the array \nforward (linearly) until either the first element \nlarger than $k$ is encountered or the end of the array is reached. \nIf $k$ is not found, a binary search will end up pointing to \neither the next largest value after $K$ in the array, in which case no further action is required or the \nnext smallest value in which case the next element is the next largest value.\n\n\\begin{comment}\nHere is an implementation in Python:\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Python]\nimport math\n \n# Find first element larger than k in sorted array\ndef firstElementLargerThanK(arr, k):\n    # use binary search to find position of k or neighbor if not found\n    top = len(arr) - 1\n    bot = 0\n    foundK = False\n    while (bot <= top and foundK == False):\n        mid = bot + ((top - bot + 1) / 2)\n        if arr[mid] < k:\n            bot = mid + 1\n        if arr[mid] > k:\n            top = mid - 1\n        if arr[mid] == k:\n            foundK = True\n \n    # if neighbor is greater, we are done\n    if arr[mid] > k:\n        return mid, arr[mid]\n    else:\n        for i in range(mid + 1, len(arr)):\n            if arr[i] > k:\n                return i, arr[i]\n        return 0, 0\n\\end{lstlisting}\n\nHere are the test runs:\n\n{\\footnotesize\n\\begin{verbatim} \na1 = [6, 23, 22, 81, 4, 2, 5, 5, 10, 9, 47]\na1.sort()\nfirstElementLargerThanK(a1, 21) = (7, 22)\n\na2 = [6, 23, 22, 81, 21, 2, 5, 5, 10, 9, 47]\na2.sort()\nfirstElementLargerThanK(a2, 21) = (7, 22)\n\na3 = [6, 23, 22, 81, 4, 2, 5, 5, 36, 9, 47]\na3.sort()\nfirstElementLargerThanK(a3, 21) = (6, 22)\n\na4 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6]\na4.sort()\nfirstElementLargerThanK(a4, 5) = (12, 6)\n\\end{verbatim} \n}\n\\end{comment}\n\nThe worst-case runtime of this algorithm is $\\Theta(n)$---the \ninput of all values matching $K$, except for \nthe last one (which is greater than $K$), is the worst-case.\n%Imagine if it were one million values of 5 instead of 20---then \n%our original algorithm would inspect approximately 500,000 elements\n%instead of $\\log_2(500000) \\approx 19$ elements. \n\nThe solution to this problem is to replace the linear scan with a binary search \nin the second part of the algorithm, which  \nleads to the desired element to be found in $O(\\log n)$ time.\n\n\\begin{comment}\nThe problem with this, of course, is that the worst-case input may not be \nthe ``typical'' input. If we expect a uniform random distribution of values from a large range, \nthe expected time to reach the next larger element after having found the position for $K$ \nwould be constant, i.e., we would expect to find the next biggest element in a\nsmall number of steps, regardless of $n$. In the case of a million unique randomly distributed sorted values, our original \nalgorithm would solve the first part of the problem in $\\log_2(1,000,000) = 20$ steps and then \nexactly one step for the second part, compared to another 19 steps for the ``improved'' \nalgorithm that used a second binary search.\n\\end{comment}\n\n\\begin{comment}\nOn the other hand, if there are many expected duplicates, there is a crossover point after \nwhich the binary search does become faster. Specifically, that number is $\\log_2\\frac{n}{2})$; so, in \nthe case of $1,000,000$, if we expect any more than 19 copies of each element in the sorted \narray, we are still better off using a second binary search to find the next highest \nnumber rather than a linear walk through 19 elements. Of course, the constant factors in \nthe algorithm will have an impact as well, but which algorithm is better still depends on the amount of duplication relative to $n$.\n\\end{comment}\n\n\\ans{bin-search-equal}\nSince the array contains\ndistinct integers and is sorted, for any $i >0$, $A[i] \\ge A[i-1] +1$.\nTherefore $B[i] = A[i] -i$ is also nondecreasing. It follows that\nwe can do a binary search for 0 in $B$ to find an\nindex such that $A[i] = i$. \n(We do not need to actually create $B$, we can simply use $A[i] -i$ wherever $B[i]$ is referenced.)\n\n\\ans{bin-search-unknown-length}\nThe key idea here is to simultaneously do a binary search for the end\nof the array as well as the key.\nWe try to look for $A[2^k]$ in the $k$-th step and \ncatch exceptions for successive values of $k$ till either we hit an\nexception or we hit a number greater than or equal to $b$. Then we do a\nbinary search for $b$ between indices $2^{k-1}$ and $2^k$.\nThe runtime of the search algorithm is $O(\\log n)$. \nIn code:\n%tested\n \\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nint BinarySearchInUnboundedArray(int * A, int b) {\n  int k = 0;\n  while(true) {\n    int c;\n    try {\n      c = A[(1 << k) -1];\n      if (c == b) {\n        return (1 << k) -1;\n      } else if (c >= b) {\n        break;\n      }\n    }\n    catch (exception e) {\n      break;\n    }\n    k++;\n  }\n  // Now do a binary search between indices 2^(k-1) and (2^k)-1.\n  int begin = 1 << (k -1);\n  int end = (1 << k) - 1;\n  while(begin + 1 > end) {\n    int mid = begin + (end - begin) / 2;\n    try {\n      if (A[mid] == b) {\n        return mid;\n      } else if (A[mid] < b){\n        begin = mid;\n      } else {\n        end = mid;\n      }\n    }\n    catch (exception e) {\n      end = mid;\n    }\n  }\n  // Nothing matched b\n  return -1;\n}\n \\end{lstlisting}\n\n\n\\ans{missing-small-ram}\nIn the first step, we build an array of\n$2^{16}$ integers that is initialized to $0$ and for every number in the file,\nwe take its $16$ most significant bit to index into this array and\nincrement that number. Since there are less than $2^{32}$ numbers in the\nfile, there is bound to be one number in the array that is less\nthan $2^{16}$. This tells us that there is at least one number missing\namong the possible numbers with those upper bits. In the second pass,\nwe can focus only on the numbers that match this criterion and use a bit-vector of size $2^{16}$ to identify one of the missing\nnumbers.\n\n\n\\begin{comment}\n\nIan's solution\n\nWhen the two arrays are of comparable size, the intersection can be\ncomputed by walking both the arrays simultaneously like merge sort and\nonly write out the entries that are found in both the arrays. This can\nbe done in $O(n + m)$ time.\n\nWhen $m$ is much smaller than $n$, it can be more efficient to do a\nbinary search for each of the elements of $B$ in $A$ and write out the\nelements that were found. This can be done in $O(m \\log n)$ time.\n\n\nGiven sorted arrays $A$ and $B$ of length $n$ and $m$ respectively, return an array $C$ \ncontaining elements common to $A$ and $B$. The array $C$ should be free of duplicates. How would you \nperform this intersection if $n$ and $m$ were roughly equal? How about\nif $n$ is much less than $m$?\n\\end{comment}\n\n\\ans{intersection}\n% This problem is quite commonly solved by databases while performing join operations. \n% However the task of databases is more difficult since  it has to deal with the difference in access time for secondary storage. \nThe simplest algorithm is a ``loop join'', i.e., walking through \nall the elements of one array and comparing them to the elements of the other array. This has  \n$O(m \\cdot n)$ time complexity, regardless of whether the arrays are sorted or unsorted: \n\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Python]\nfor each unique element in A\n    for each unique element in B\n        if A = B\n            include A in output\n\\end{lstlisting} \n\nHowever since both the arrays are sorted, we can \nmake some optimizations. First, in the right array, we can \nuse binary search to find whether the element \nexists rather than scanning the entire array:\n\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Python]\nfor each unique element in A\n    use binary search to find A in B\n    if found, include A in output\n\\end{lstlisting} \n\nNow our algorithm should be $O(n \\cdot \\log_2 m )$. We should\nchoose the larger set for the inner \nloop (i.e., binary search) since if $n \\ll m$ then $m\\log(n) \\gg n\\log(m)$.\n\n\\begin{comment}\nFor example:\n\nIf $n = 1000$ and $m = 100$, we have $1000 \\cdot \\log_2(100) \\approx 6643$ \nIf $n = 100$ and $m = 1000$, we have $100 \\cdot \\log_2(1000) \\approx 997$\n\nIf $n = 600$ and $m = 500$, we have $600 \\cdot \\log_2(500) \\approx 5379$\nIf $n = 500$ and $m = 600$, we have $500 \\cdot \\log_2(600) \\approx 4614$\n\nIf $n = 1000$ and $m = 999$, we have $1000 \\cdot \\log_2(999) \\approx 9964$\nIf $n = 500$ and $m = 600$, we have $500 \\cdot \\log_2(600) \\approx 9955$\n\\end{comment}\n\nThis is the best solution if one set is much smaller than \nthe other. However it is not optimal for cases where the set sizes are similar because \nwe are not using the fact that both arrays are sorted to our advantage. \nIn that case, a linear scan through both the arrays in tandem will work \nbest as shown in this Python code:\n\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Python]\ndef TryLinearIntersect(n, m, a, b):\n    # construct sorted sets of random numbers of size n and m\n    A = []\n    for i in range(n):\n        A.append(random.randint(a, b))\n    A.sort()\n \n    B = []\n    for j in range(m):\n        B.append(random.randint(a, b))\n    B.sort()\n \n    return LinearIntersect(A, B)\n \ndef LinearIntersect(A, B):\n    output = []\n    ACounter = 0\n    BCounter = 0\n    lastMatch = None\n    while ACounter < len(A) and BCounter < len(B):\n        if A[ACounter] == B[BCounter] and A[ACounter] != lastMatch:\n            lastMatch = A[ACounter]\n            output.append(lastMatch)\n            ACounter = ACounter + 1\n            BCounter = BCounter + 1\n        elif A[ACounter] < B[BCounter]:\n            ACounter = ACounter + 1\n        else:\n            BCounter = BCounter + 1\n    return output\n\\end{lstlisting}\n\n\n\\begin{comment}\nSome example runs:\n\n\\begin{verbatim} \n>> TryLinearIntersect(100, 100, 1, 100)\n\nA: [1, 3, 4, 4, 7, 8, 10, 12, 12, 12, 14, 14, 14, 16, 16, \n\t17, 21, 21, 22, 22, 23, 23, 23, 24, 24, 26, 27, 28, \n\t28, 29, 31, 31, 32, 32, 33, 33, 33, 35, 37, 37, 38, \n\t38, 38, 40, 40, 41, 44, 44, 44, 45, 45, 46, 46, 47, \n\t49, 49, 52, 52, 53, 53, 54, 54, 54, 55, 57, 58, 60, \n\t61, 61, 63, 63, 65, 66, 71, 72, 73, 75, 76, 78, 79, \n\t79, 81, 81, 82, 85, 87, 87, 88, 88, 88, 88, 89, 90, \n\t92, 93, 93, 94, 95, 96, 98]\n\nB: [2, 2, 2, 3, 4, 4, 4, 5, 9, 9, 10, 10, 13, 13, 14, 16, \n\t17, 17, 19, 21, 22, 26, 26, 26, 27, 28, 30, 30, 30, \n\t30, 31, 32, 33, 34, 34, 37, 37, 39, 40, 45, 46, 46, \n\t46, 48, 49, 50, 53, 55, 56, 58, 59, 59, 59, 60, 62, \n\t62, 62, 63, 66, 67, 69, 69, 74, 74, 74, 75, 77, 78, \n\t79, 79, 79, 79, 79, 81, 81, 81, 81, 81, 82, 83, 84, \n\t84, 86, 87, 88, 90, 90, 91, 92, 96, 97, 97, 97, 98, \n\t98, 98, 98, 99, 100, 100]\n\nOutput: [3, 4, 10, 14, 16, 17, 21, 22, 26, 27, 28, 31, 32, \n\t\t33, 37, 40, 45, 46, 49, 53, 55, 58, 60, 63, \n\t\t66, 75, 78, 79, 81, 82, 87, 88, 90, 92, 96, 98]\n\\end{verbatim} \n\\end{comment}\n\nThe runtime for this algorithm is $O(m + n)$.\n\n\\begin{comment}\nThere is one additional case where we can improve on this; if there are expected to be long \nruns of nonmatching values in between matches, then we can improve our time by using \nbinary search on either set, compared to the most recent value in the other set. This will \nbe advantageous if the log of the number of remaining values is smaller than the \nnonmatching value run-length.\n\\end{comment}\n\\begin{comment}\n\\begin{verbatim} \ndef TryLinearIntersectWithBSLookahead(n, m, a, b):\n    # construct sorted sets of random numbers of size n and m\n    A = []\n    for i in range(n):\n        A.append(random.randint(a, b))\n    A.sort()\n \n    B = []\n    for j in range(m):\n        B.append(random.randint(a, b))\n    B.sort()\n \n    return LinearIntersectWithBSLookahead(A, B)\n \n \ndef LinearIntersectWithBSLookahead(A, B):\n    #editor.AddText(\"\\nOriginal: A: \" + str(A) + \"; B: \" + str(B) + \"\\n\")\n    output = []\n    ACounter = 0\n    BCounter = 0\n    lastMatch = None\n    jumpout = 0\n    while ACounter < len(A) and BCounter < len(B): #and jumpout < 1000:\n        if A[ACounter] == B[BCounter] and A[ACounter] != lastMatch:\n            #editor.AddText(\"A[ACounter] = \" + str(A[ACounter]) + \", B[BCounter] = \" + str(B[BCounter]) + \", lastMatch = \" + str(lastMatch) + \"\\n\")\n            lastMatch = A[ACounter]\n            output.append(lastMatch)\n            ACounter = ACounter + 1\n            BCounter = BCounter + 1\n        elif A[ACounter] < B[BCounter]:\n            ACounter = BS(A, ACounter + 1, B[BCounter])\n        else:\n            BCounter = BS(B, BCounter + 1, A[ACounter])\n        #jumpout = jumpout + 1\n        #editor.AddText(\"\\output \" + str(jumpout) + \": \" + str(output) + \"\\n\")\n    return output\n \n# return the position of the array where the value is or would be\ndef BS(ar, val, low):\n    high = len(ar)\n    while low < high:\n        mid = (low + high) // 2\n        midval = ar[mid]\n        if midval < val:\n            low = mid+1\n        elif midval > val: \n            high = mid\n        else:\n            return mid\n    return low\n\\end{verbatim} \n\nWe should  be able to tell the timing difference in large arrays with \nsparse overlap---say, 10000 items in each array drawn from a set \nof 1000000 integers. \n\n\\begin{verbatim} \n>> TryLinearIntersect(10000, 10000, 1, 1000000)\nTryLinearIntersect took 187.00003624 ms\n\n>> TryLinearIntersectWithBSLookahead(10000, 10000, 1, 1000000)\nTryLinearIntersectWithBSLookahead took 92.9999351501 ms\n\\end{verbatim} \n\\end{comment}\n\n\n\\ans{anagrams}\nA simple way to approach this problem is to hash each word based on its sorted \nrepresentation (i.e., ``logarithm'' and ``algorithm'' would both be hashed as ``aghilmort'').\nThis ensures that all the anagrams of a given word map to the same hash value.\n\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Python]\ndef anagrams(dictionary):\n    output = []\n    map = {}\n    # for each word\n    for word in dictionary:\n        # sort the letters\n        sorted_word = sortchars(word)\n        # add the word to the list held in a dictionary \n        # under its sorted key\n        if sorted_word not in map:\n            map[sorted_word] = [word]\n        else:\n            map[sorted_word].append(word)\n    # for each dictionary key\n    for k in map.keys():\n        # return the list if it has more than one item\n        if len(map[k]) > 1:\n            output.append(map[k])\n    return output\n \ndef sortchars(word):\n    l = list(word)\n    l.sort()\n    return ''.join(l)\n\\end{lstlisting} \n\nA sample run:\n{\\footnotesize\n\\begin{verbatim} \n>> anagrams((\"algorithm\", \"god\", \"logarithm\", \"dog\", \"snute\"))\n    [['algorithm', 'logarithm'], ['god', 'dog']]\n\\end{verbatim} \n}\n\n\\ans{search-sum}\nThis could be easily done in $O(n^2)$ time by searching for all possible values of $i$ and $j$ such that $A[i] + A[j] = K$.\n\nWe could do significantly better by storing the values from the array in \na hash table. Then for each new value, we check to see if its \ncomplement (i.e., $K$ minus the value) has already \nbeen seen and if so, what is the index?\nHere is a Python implementation of this \nconcept using Python's built-in dictionary object as the hash table:\n\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Python]\ndef PairSum(arr, K):\n    h = {}\n    for i in range(len(arr)):\n        complement = K - arr[i]\n        h[arr[i]] = i\n        if complement in h:\n            return h[complement], i\n\\end{lstlisting} \n\nThis gives the following results, where the return values of the function are the two \nindices of elements that add up to $K$:\n{\\footnotesize\n\\begin{verbatim} \nar1 = [2, 3, 4, 5, 6, 7, 8, 7]\n\nPairSum(ar1, 4) = (0, 0)\nPairSum(ar1, 5) = (0, 1)\nPairSum(ar1, 10) = (3, 3)\nPairSum(ar1, 13) = (4, 5)\nPairSum(ar1, 15) = (5, 6)\nPairSum(ar1, 17) = None\n\\end{verbatim} \n}\n\nThis algorithm runs in $O(n)$ time since it makes only a single pass through the list \nand the work done inside the loop is constant (assuming we have \na nice hash function that gives us a constant time hash insert and lookup).\n\n\n\\ans{anonymous-letter}\nHere essentially we need to efficiently represent two multisets (one\nfor characters in the anonymous letter and one for characters in the\nmagazine) and see if one is a subset of the other.\n\nThe most direct way of doing this would be to build a hash table $M$, where\nthe key is a character and its value is the number of times it appears\nin the magazine.  Once this is built, we can scan the anonymous letter \ncharacter by character and decrement the corresponding count in $M$.\nIf the count goes to zero, we delete the character from $M$.\nWe can write the anonymous letter with characters in the magazine\niff we can go over the entire anonymous letter and find every\ncharacter in $M$ with a positive count. \n\nIf the characters are coded in ASCII, we could do away with $M$ and use a 256 entry \ninteger array $A$, with $A[i]$ being set to the number of times the character $i$ appears\nin the magazine.\n\nOne way to improve performance of the approach outlined above\nwhen the magazine is very long is to process the magazine in segments;\nin this way, if the letter can be written with a relatively\nsmall initial prefix of the magazine, the whole magazine does not have\nto be processed. \nThe segments may be of fixed size or a doubling strategy may be employed.\nThis does not help the worst-case complexity (since\nit may not be possible to write the letter with the characters in the magazine\nand this cannot be determined without inspecting the entire magazine) but\nspeeds up the best-case and possibly the average-case.\n\n\\ans{pair-users}\nHere essentially each user is associated with a set of attributes and\nwe need to find users associated with a given set of attributes\nquickly. A hash table would be a perfect solution here but we need\na hash function over the set of attributes.  There are a couple of\ngood ways of doing this. If the number of attributes is small, then we\ncan represent the set as a bit-vector, where each bit represents a\nspecific attribute. Once we have this canonical representation of set,\nthen it is easy to use any hash function that transforms this bit-vector into a desired hash space. \n\nHowever if the space of possible attributes is large, then the best way\nto represent a set canonically would be to sort the attributes. For this sorting, \nany arbitrary ordering of attributes will work. We can represent the sorted \nlist of attributes in a string concatenating all the attributes.\n\nIncidentally, if we want to group users based on similar rather than identical attributes, the\nproblem becomes significantly more difficult. A common approach is\nmin-hashing. Essentially, we construct a set of $k$ independent hash functions\n($k$ is chosen based on how similar we want the sets to be). Then for\neach set $s$ we define \n\\[M_k(s) = \\min_{a_i \\in s} h_k(a_i) . \\]\nIf two sets $s_1$ and $s_2$ have similar set of attributes then with\nhigh probability $M_k(s_1) = M_k(s_2)$. Based on this, we map each set\nof attributes $s$ to a sequence of hashes $M_1(s)\\ldots M_k(s)$.  Now\nthe problem has been reduced to pairing users that have the same hash\nsequence, which is similar to the original problem. Here $k$ can be varied appropriately to increase or decrease the probability of match for a pair of \nslightly different attribute sets.\n\n\n\\ans{missing}\nThe idea here is very similar to hashing. Consider a very simple hash\nfunction $F(x) = x \\bmod{(n+1)}$. We can build a bit-vector of length\n$n+1$ that is initialized to $0$ and for every element in $A$, we set\nbit $F\\big(A[i]\\big)$ to 1.  Since there are only $n$ elements in the array,\nthere has to be at least one bit in the vector that is not set. That\nwould give us the number that is not there in the array.\n\nAn even simpler approach is to find the max (or min) element in the array \nand return one more (less) than that element. This approach will not work if the \nextremal elements are the largest (smallest) values in the set\nthat the entries are drawn from.\n\n\n\\begin{comment}\n\nSuppose you have a scheme for finding patterns in stock trends. You may want to see how \ngood it is with respect to the best possible scheme. One way to formalize this is to \nconsider an array $A$ of $n$ integers representing the price of a share of a company's stock \nover $n$ days. Given $A$, how would you efficiently determine the maximum amount of money \nyou could make by buying and selling a share over those $n$ days?\n\nThe brute force algorithm is quite simple: Buy the share at or before the beginning of any \nrise, and sell at or before the beginning of any drop. Assuming you have to start by \nbuying a share the first day, you would have an outer loop that ranges from day $0$ \nto $n - 1$ and for each day, determine if the price is \nrising (in which case you buy or hold) or \nfalling (in which case you sell or avoid buying). The way to determine this is simply to \nlook at the next day. Here is a sample Python implementation:\n\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Python]\ndef MaxDiff(arr):\n    holding = False\n    account = 0\n    for i in range(len(arr) - 1):\n        if arr[i + 1] > arr[i] and holding == False:\n            # buy!\n            holding = True\n            account = account - arr[i]\n        elif arr[i + 1] < arr[i] and holding == True:\n            # sell!\n            holding = False\n            account = account + arr[i]\n \n    # if we end up holding the stock, sell it at the end for the final profit\n    if holding == True:\n        account = account + arr[i + 1]\n        holding = False\n \n    return account\n\\end{lstlisting} \n\nThis yields:\n\n{\\footnotesize\n\\begin{verbatim}\nar1 = [5, 7, 9, 2, 2, 1, 3, 7, 12, 15, 12, 16, 8, 8, 2, 19] # max profit should be 39\nMaxDiff(ar1) = 39\n\nar2 = [8, 7, 6, 5, 4, 3, 2, 1] # max profit should be 0\nMaxDiff(ar2) = 0\n\nar3 = [1, 2, 3, 4, 5, 6, 7, 8] # max profit should be 7\nMaxDiff(ar3) = 7\n\\end{verbatim}\n}\n\nIs there any better way to do this? Already we are using an $O(n)$ algorithm as each step \ncompares only the current and following days which is constant work. With it not being a \nsorted (or sortable) list, I can't see a way to avoid hitting every element once; there \nmay be ways to do less work on each step, but I don't see a way to do it asymptotically \nfaster.\n\\end{comment}\n\n\n\n\n\\ans{max-difference}\nSince the energy is only related to the height of the robot, we can\nignore $x$ and $y$ co-ordinates. Let's say that the points where the\nrobot goes in successive order have heights $h_1,\\ldots,h_n$.\nLet's assume that the battery capacity is such that with full battery, the robot can climb up $B$ meters. Then the robot will  run\nout of battery iff there exist integers $i$ and $j$ such that $i <\nj$ and $h_j - h_i > B$. In other words, in order to go from point $i$\nto point $j$, the robot needs to climb more than $B$ points.  So, we\nwould like to pick $B$ such that for any $i < j$, we have $B \\ge h_j - h_i$.\n\nIf we did not have the constraint that $i < j$, then we could just\ncompute $B$ as $\\max(h) - \\min(h)$ but this may be an overestimate:\nconsider the case when the robot is just going downwards.  \n\nWe can compute the minimum $B$ in $O(n)$ time \nif we keep the running min as we do a sweep. In code:\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\ndouble BatteryCapacity(vector<double> h) {\n  if (h.size() < 2) {\n    return 0;\n  }\n  double min = h[0];\n  double result = 0;\n  for (int i = 1; i < h.size(); ++i) {\n    if (h[i] - min > result) {\n      result = h[i] - min;\n    }\n    if (min > h[i]) {\n      min = h[i];\n    }\n  }\n  return result;\n}\n\\end{lstlisting}\n\n\\ans{majority}\nLet's first consider just the strict majority case.\nThis problem has an elegant solution when you make the following\nobservation: if you take any two distinct elements from the stream\nand throw them away, the majority element remains the majority of the remaining\nelements (we assumed there was a majority element to begin with). The reasoning goes\nas follows: let's say the majority element occurred $m$ times out\nof $n$ elements in the stream such that $m/n > 1/2$.  The two distinct\nelements that we choose to throw can have at most one of the majority\nelements. Hence after discarding them, the ratio of the previously\nmajority element could be either $m/(n-2)$ or $(m -1) /(n-2)$.  It\nis easy to verify that if $m/n > 1/2$, then $m/(n-2) > (m -1) /(n-2)  > 1/2$. \n\nNow, as we read the stream from beginning to the end, as soon as we\nencounter more than one distinct element, we can discard one instance\nof each element and what we are left with in the end must be the\nmajority element. \n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nstring FindMajority(stream* s) {\n  string candidate, next_word;\n  int count = 0;\n  while (s->GetNext(&next_word)) {\n    if (count == 0) {\n      candidate = next_word;\n      count = 1;\n    } else if (candidate == next_word) {\n      count++;\n    } else {\n      count--;\n    }\n  }\n  return candidate;\n}\n\\end{lstlisting}\n\nThe code above assumes there is a majority word in the\nstream; if no word has a strict majority, it still returns\na string but there are no meaningful guarantees on what that string would be.\n\n\\ans{majority2}\nThis is essentially a generalization of Problem~\\ref{majority}. Here\ninstead of discarding two distinct words, we discard $k$ distinct words\nat any given time and we are guaranteed that all the words that occurred\nmore than $1/k$ times the length of the stream before discarding continue\nto have more than $1/k$ fraction of copies.  For implementing this\nstrategy, we need to keep a hash table of current $k$ candidates. Here\nis an example code:\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nvoid FindFrequentItems(stream* s, hash_map<string, int>* word_set, int k) {\n  word_set->clear();\n  string word;\n  while(s->GetNextWord(&word)) {\n    hash_map<string, int>::iterator i = word_set->find(word);\n    if (i == word_set->end()) {\n      if (word_set->size() == k) {\n        // Hash table is full, decrement all counts, which \n        // is equivalent to discarding k distinct words.\n        for (hash_map<string, int>::iterator j = word_set->begin();\n             j !=  word_set->end();\n             ++j) {\n          --(j->second);\n          if (j->second ==0){\n            word_set->erase(j);\n          }\n        }\n      } else {\n        (*word_set)[word] = 1;\n      }\n    } else {\n      i->second++;\n    }\n  }\n}\n\\end{lstlisting}\nIt may seem the above code is taking $O(n.k)$ time since\nthe inner loop may take $k$ steps (decrementing count for all $k$\nentries) and the loop goes on for $n$ times. However if you note that\neach word in the stream can only be erased once, then the total time spent erasing everything is $O(n)$ and the rest of the steps inside the loop run in constant time.\n\nThe above code provides us with a $k -1$ size set of words\nthat is a superset of the words that occur more than $n/k$ times. \nIn order to get the exact set, we need to make another pass over the\nstream and count the number of times each word in the hash table\nactually occurs so that we  keep only the words which occur more than $n/k$ times.\n\n\n\\ans{bst}\nA recursive solution is natural:\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nNode* SearchBST(Node* root, int key) {\n  if (root == NULL) {\n    return NULL;\n  } else if (root->key == key) {\n    return root;\n  } else if (root->key < key) {\n    return SearchBST(root->left, key);\n  } else {\n    return SearchBST(root->right, key);\n  }\n}\n\\end{lstlisting}\n\nRecursion adds the overhead of function calls. \nThe code above is not literally tail recursive, which means\nthat an optimizing compiler is unlikely to remove the recursive calls;\nhowever there still is a straightforward iterative solution:\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nNode* SearchBST(Node* root, int key) {\n while(root != NULL) {\n   if (root->key == key) {\n     return root;\n   } else if (root->key < key) {\n     root = root->left;\n   } else {\n     root = root->right;\n   }\n return NULL;\n}\n\\end{lstlisting}\n\n\n\\ans{bst-next}\nThis is similar to Problem~\\ref{bst} but you just have to\ncontinue your binary search till the end even if you find the element\nthat you were looking for and also keep track of the last element\nthat met the criteria.\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nNode* SearchBST(Node* root, int key) {\n  Node* result = NULL;\n  while(root != NULL) {\n    if (root->key > key) {\n      result = root;\n      root = root->left;\n    } else {\n      root = root->right;\n    }\n  }\n  return result;\n}\n\\end{lstlisting}\n\n\\ans{k-smallest-int-2-array}\nThis problem requires some creative use of the binary search\nidea. Let's say that the two arrays are $A1$ and $A2$ and say that $l$ of the $k$ smallest elements of the union\ncome from the first array and $l-k$ elements come from the second array.\nIf this were indeed true, then we would see that $A1[l-1] \\le A2[k-l]$\nand $A2[l-k]-1 \\le A1[l]$ (barring some corner cases where we reach\nthe end of the array).\n\nThe other interesting observation we can make is that if $A1[l-1] >\nA2[k-l]$, then we should use at least one more element from the second\narray in the $k$ smallest elements. Similarly, if $A2[l-k-1] > A1[l]$,\nthen we should use at least one more element from the first\narray. Using these two inequalities, we can essentially do a binary\nsearch on $l$.  Note that this problem gives you plenty of corner\ncases to worry about. In code:\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nint FindOrderStat(const vector<int>& a1,\n\t\t  const vector<int>& a2,\n\t\t  unsigned int k) {\n  // Check the validity of input.\n  assert(a1.size() + a2.size() >= k);\n  assert(k > 0);\n  // Find an index begin <= l < end such that a1[0]..a1[l-1]\n  // and a2[0]..a2[k-l-1] are the smallest k numbers.\n  unsigned int begin = max(0, k - a2.size());\n  unsigned int end = min(a1.size(), k); \n  while(begin  < end) {\n    unsigned l = begin + (end - begin)/2;\n    // Can we include a1[l] in the k smallest numbers?\n    if((l < a1.size()) && (k-l > 0) && (a1[l] < a2[k-l-1])) {\n      begin = l + 1;\n    } else if ((l > 0) && (k-l < a2.size()) && (a1[l-1] > a2[k-l])) {\n      // This is the case where we can discard a[l-1]\n      // from the set of k smallest numbers.\n      end = l;\n    } else {\n      // We found our answer since both the inequalities were false.\n      begin = l;\n      break;\n    } \n  }\n  if (begin == 0) {\n    return a2[k - 1];\n  } else if (begin == k) {\n    return a1[k-1];\n  } else { \n    return max(a1[begin -1], a2[k - begin -1]);\n  }\n}\n\\end{lstlisting}\n\n\n\\ans{intersecting-lines}\nConsider two lines  $y = a_i + b_ix$ and\n$y = a_j + b_j x$  such that $a_i > a_j$.\nThe $i$-th line intersects the line $x = 0$ at $(0, a_i)$ and the\n$j$-th line intersects the line $x = 0$ at $(0,a_j)$. Similarly,\nthese lines intersect $x = 1$ at $(1, a_i + b_i)$ and $(1,\na_j + b_j)$. Lines $i$ and $j$ intersect iff \n\\ifthenelse{\\boolean{createspace}}{\n\\[\n\\big((a_i >\na_j) \\& (a_i + b_i < a_j + b_j)\\big) | \\big((a_i < a_j) \\& (a_i + b_i > a_j +\nb_j)\\big) .  \\] \n} {\n\\begin{eqnarray*}\n\\lefteqn{\\big((a_i > a_j) \\& (a_i + b_i < a_j + b_j)\\big)}  &  &  \\\\\n& & | \\; \\big((a_i < a_j) \\& (a_i + b_i > a_j + b_j)\\big) . \n\\end{eqnarray*}\n}\nIn other words, for the lines to intersect, if $a_i < a_j$,\nthen it must be the case that  $(a_i + b_i < a_j + b_j)$ or vice versa\n(ignoring the trivial\ncase where they intersect on one of the boundaries). \n\nHence if we sort the pairs $(a_i, b_i)$ by $a_i$ and test that for\nsuccessive pairs $(a_i, b_i)$ and $(a_j, b_j)$ if $a_i + b_i < a_j +\nb_j$, we know that they do not intersect. If we do find a\nviolation of this inequality, then we have found one of the\nintersecting pairs.\n\nSorting takes $O(n \\log n)$ time and comparing successive pairs\ntakes $O(n)$ time. Hence this can be done in $O(n \\log n)$ time.\n\n\\ans{overlapping-lines}\nOne way to solve this is to sort the intervals by their lower boundary\nand see if their upper boundary is also sorted in the same order. If\nnot, we are sure to find some pair of indices $l,m$ where $a_l \\le\na_m$ and $b_l \\ge b_m$. This would be the pair we are looking for. If\nthe upper boundaries are also sorted, then we are guaranteed that no\ninterval is completely contained in another interval. Since this\ninvolves sorting followed by a linear scan, we can get this done in\n$O(n \\log n)$ time.\n\n\n\n\\ans{2d-render}\nThe key idea here is to sort the endpoints of the lines and do a\nsweep from left to right. As we do the sweep, we maintain a list of\nlines that intersect the current position as well as the highest line\nand its color.  In order to quickly lookup the highest line among\nthe set of intersecting lines, we can keep an ordered binary tree data-structure and to lookup the lines by the endpoint quickly, we can\nmaintain a hash table.\n\n\\ans{completion-search} \nDefine $F(\\sigma)$ to be $\\sum_{i=1}^{n}\n\\min(s_i,\\sigma)$.  We are looking for a value of $\\sigma$ such that $F(\\sigma) =\nS'$. Clearly, $F$ monotonically increases with $\\sigma$. Also, since \n$0 \\le S' \\le S$, the value of $\\sigma$ is going to be between $0$ and\n$\\max(s_i)$. Hence we can perform a binary search like operation for\nfinding the correct value of $\\sigma$ between 0 and $\\max(s_i)$. \n\nAssume that the $s_1,\\cdots,s_n$ are already sorted, i.e., for all $i$, $s_i\n\\le s_{i+1}$.  Compute the running sum $z_k = \\sum_{i=1}^{k}{s_i}$. \n\nNow, suppose $s_k \\le \\sigma \\le s_{k+1}$. Consequently, \\[F(\\sigma) = (n - k) \\cdot \\sigma + z_k .\\]\n\nUsing the above expression, we can search for the value of $k$ such that\n$F(s_k) \\le S' \\le F(s_{k+1})$ by performing binary search for $k$\n(since the runtime of this solution is already $\\Theta(n \\log n)$, we\ncan do a linear search as well for simplicity). Once we have found\nthe right value of $k$, we can compute the value of $y$ by simply\nsolving the equation for $F(\\sigma)$ above.\n\nThe most expensive operation for this entire solution is sorting the $s_i$s,\nhence the runtime is $O(n \\log n)$. However if we are given the $s_i$s  in\nadvance and we are allowed preprocessing, then for each value of $S'$,\nthe search would just take $O(\\log n)$ time.\n\n\\ans{matrix-search}\nA solution to this problem is discussed in the context of finding Hardy-Ramanujan numbers (Problem~\\ref{Hardy-Ramanujan}).\n\n\\ans{simple-polygon}\nGiven two line segments in a two-dimensional plane, we can test for\nintersection easily in constant time. Given $n$ line segments of a\npolygon, we can find if any of the segments intersect in $O(n^2)$ time\nby simply testing each pair. However doing this in $O(n \\log n)$ time\nrequires a fairly complex algorithm.\n\nConsider two line segments and the two farthest vertical lines that each intersect\nwith both the line segments (one vertical line is the leftmost\nvertical line that still intersects with both lines and the other one\nis the rightmost). The two line segments would intersect iff their vertical ordering changes between the two vertical lines.\n\nThe key idea is to use a sweep line, a vertical line that moves from\nleft to right through each endpoint.  We order the polygon vertices\n(endpoints of line segments) from left to right first by increasing the\n$x$ co-ordinate, then by increasing the $y$ co-ordinate. Now, imagine a\nvertical line moving from left to right through these $2n$ endpoints.\n\nFor each position of this vertical line, we keep an ordered list of\nintersecting line segments. The list is sorted by the $y$ co-ordinate of\nthe first endpoint of the line segment.  As we reach the starting points\nof the new line segments, we insert them by doing a binary search for\nthem. As we reach the end of a line segment, we remove it from the\nlist. The sorted list can be maintained using a balanced BST.\n\nWhen any line segment ends, we test if its vertical ordering changed\ncompared to the other lines in the list (which can be done in constant\ntime by just comparing the nearest two lines). The lines intersect iff the ordering changed for some line segment.\n\n\\chapter{ Sorting}\n\n\\ans{good-sort}\nIn general, Quicksort is considered one of the most efficient sorting\nalgorithms since it has a runtime of $\\Theta(n\\log_2 n)$ and it sorts\nin-place (sorted data is not copied to some other buffer). \nSo, for a large set of random integers, Quicksort would be our choice.\n\nQuicksort has to be implemented carefully---for example, in a na\\\"{i}ve\nimplementation, an array with many duplicate\nelements leads to quadratic runtimes (and a high likelihood of stack space\nbeing exhausted because of the number of recursive calls)---this can\nbe managed by putting all keys equal to the pivot in the correct place. \nSimilarly, it is important to call the smaller subproblem first---this, \nin conjunction with tail recursion ensures that the stack depth is $O(\\log_2 n)$.\n\nHowever there are cases where other solutions are more preferable:\n\\begin{itemize}\n\\itemsep 1pt\n\\item {Small set}---for a very small set (for example, 3-4 integers),\n  a simple implementation such as insertion sort is easier to code, and runs faster.\n\\item {Almost sorted array}---if every element is known to be at most $k$ places from its \nfinal location, a min-heap can be used to get an $O(n\\log_2 k)$ algorithm (Problem~\\ref{app-sort}); alternatives\nare bubble sort and insertion sort.\n\\item {Numbers from a small range, small number of distinct keys}---counting sort, which records for\neach element, the number of elements less than it. This count can be kept\nin an array (if the largest number is comparable in value to the size of the set being sorted) or a BST, where the keys are the numbers and the values are their\nfrequencies.\n\\item {Many duplicates}---we can add the keys to a BST, with linked lists for elements \nwhich have the same key; the sorted result can be derived from an in-order walk of the BST\n\\item {Stability is required}---most useful sorting algorithms are not stable.\nMergesort, carefully implemented, can be made stable; another solution is to add\nthe index as an integer rank to the keys to break ties.\n\\end{itemize}\n\n\\ans{big-sort}\nWhen sorting data that cannot fit into the RAM of a single machine, we have to partition the data into\nsmaller blocks that would fit in the memory, sort each block individually, and then combine the blocks. If a cluster of machines is available, \nthe blocks can be sorted in parallel or they can be read in sequence\non a single machine and then stored on the disk.\n\nThere are two popular approaches for doing this. If we know the rough\ndistribution of the data in advance (e.g., it is distributed uniformly),\nit can be partitioned into contiguous subranges of approximately equal size\n in the first pass. This has the advantage that\nonce the individual blocks are sorted, we can combine them\njust by concatenation.\n\nAnother slightly more expensive approach that does not require any\nknowledge of distribution is to read the input data in sequence till the memory is full, sort it, write it, and then read the next block till we are done with the file. This requires us to merge the sorted blocks in the end like Mergesort. Here, since we could be potentially merging a large number of sorted files, using a min-heap is\nhelpful. Essentially, we keep the smallest unread entry from each file\nin the heap, then we extract the min element from the heap, replace\nit with the next entry from the same file, and write out the min value\nto the output file.\n\nThe Unix \\texttt{sort} program is \nvery robust; it makes use of the disk when needed and can combine\na set of files into a single sorted file.\n\n\\ans{max12}\nFirst, we consider the problem of finding the best player.\nEach game eliminates one player and there are 128 players; so, 127 matches are necessary and also sufficient.\n\nTo find the second best, we note that the only candidates are\nthe players who are beaten by the player who is eventually determined\nto be the best---everyone else lost to someone who is not the best.\n\nTo find the best player, the order in which we organize the matches\nis inconsequential---we just pick pairs from the set of \ncandidates and whoever loses is removed from the pool of candidates.\nHowever if we proceed in an arbitrary order, we might start with the\nbest player, who defeats 127 other players and  then the players who\nlost need to\nplay 126 matches amongst themselves to find the second best.\n\nWe can do much better by organizing the matches as a binary tree---we pair\noff players arbitrarily who play 64 matches. After these matches, we are\nleft with 64 candidates; we pair them off again arbitrarily and they play 32 matches.\nProceeding in this fashion, we organize the 127 matches needed to find the \nbest player and the winner would have played only 7 matches. Therefore we can find the second\nbest player by organizing 6 matches between the 7 players who lost to the best player,\nfor a total of 134 matches.\n\n\\ans{min-max}\nSplit the numbers into pairs of two and then group the higher values of\nthe pairs into one set and the lower values into another set.\n Find the min of the lower group and the max of\nthe higher group. \n\n\\ans{top3}\nLet's start with five time-trials with no cyclist being in more than one\nof these five initial time-trials. Let the rankings be \n$A1,A2,A3,A4,A5$, $B1,B2,B3,B4,B5$,\n$C1,C2,C3,C4,C5$, $D1,D2,D3,D4,D5$, and \n$E1,E2,E3,E4,E5$, where the first cyclist is the fastest.\nNote that we can eliminate $A4,A5,B4,B5,C4,C5,D4,D5,E4,E5$ at this stage.\n\nNow, we race the winners from each of\nthe initial time-trials. Without loss of generality, assume the outcome is $A1,B1,C1,D1,E1$.\nAt this point, we can eliminate $D1$ and $E1$ as well as $D2,D3$ and $E2,E3$.\nFurthermore, since $C1$ was third, $C2$ and $C3$ cannot be in the top three;\nSimilarly, $B3$ cannot be a contender.\n\nWe need to find the best and the second best from $A2,A3,B1,B2,C1$, which we can determine with\none more time-trial, for a total of seven time-trials.\n\n% A lower bound of 6 races is easy to prove: if the first 5 races are not disjoint, \n% someone has not raced yet, and he may be the top cyclist. Conversely, if\n% the first 5 races are disjoint, we need one more races to compare the winners.\n% We can tighten the lower bound to 7 by supposing that say $A1$ is not picked\n\nNote that we need time-trials to determine the overall winner, and the sequence of time-trials\nto determine the winner is essentially unique---if some cyclist did not participate in the first\nfive time-trials, he would have to participate in the sixth one. But then one of the winners\nof the first five time-trials would not participate in the sixth time-trial and he might \nbe the overall winner.  The first six time-trials do not determine the second and the third fastest\ncyclists, hence a seventh race is needed.\n\n\n\\ans{distance-sort}\nWhenever the swap operation for the objects being sorted is expensive, one of the best things to\ndo is indirect sort, i.e., sort references to the objects first and\nthen apply the permutation that was applied to the references in the\nend. \n\nIn the case of statues, we can assign increasing indices to the\nstatues from left to right and then sort the pairs of statue height\nand index. The indices in the sorted pairs would give us the\npermutation to apply.  While applying permutation, we would want to\nperform it in a way that we move each statue the minimum possible\ndistance. We can achieve this if each statue is moved exactly to its\ncorrect destination exactly once (no intermediate swaps). \n\n\\ans{privacy}\nThe simplest way of doing this would be to define a lexicographic\nordering over the rows (where we ignore the contents of deleted\ncolumns) and sort the rows.  Once the rows are sorted, we can count\nthe number of duplicate rows for each unique row easily in a linear\npass. In case it is expensive to swap the rows (since each row contains\nlarge amounts of data), it might be more efficient to hash the contents\nof the row and sort the hash values instead.\n\n\\ans{var-sort}\nAlmost all sorting algorithms rely on swapping records. However this\nbecomes complicated when the record size varies. One way of\ndealing with this problem is to allocate for the maximum possible\nsize for each record---this can be very wasteful if there is a large\nvariation in the sizes. \n\nHere also indirect sort can be helpful---keep the records in a compact form in\nthe memory and build another array of pointers to the records. \nThen we just sort the pointers using \nthe compare function on the de-referenced pointers \nand finally write the data by de-referencing the sorted pointers.\n\n\n\\ans{dup-sort}\nAn efficient way of eliminating duplicates from any set of records,\nwhere a ``less-than'' operation can be defined, is to sort the records\nand then eliminate the duplicates in a single pass over the data.\n\nSorting can be done in $O(n\\log n)$ time;  the subsequent elimination of\nduplicates takes $O(n)$ time. If the elimination of duplicates is\ndone in-place, it would be more efficient than writing the unique set\nin a separate array since we would achieve better cache performance.\nHere is the code that does in-place duplicate removal:\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nsize_t EliminateDuplicates(int* array, size_t length) {\n  size_t j = 1;\n  for (size_t i = 1; i < length; i++) {\n    if (array[i] != array[j-1]) {\n      array[j] = array[i];\n      j++;\n    }\n  }\n  return j;\n}\n\\end{lstlisting}\n\nAnother efficient way is to use hash tables where we\nstore each record into a hash table as the key with no value and\nthen write out all the keys in the hash table. Since hash table\ninserts can be done in $O(1)$ time and iterating over all the keys also takes\nonly $(n)$ time, this solution scales much better than the sorting\napproach. However, in practice, for small size of inputs, the sorting\napproach might work faster since it can be done in-place.\n\n\\ans{merge-sorted-arrays}\nWhile merging $k$ sorted arrays, we need to repeatedly pick the smallest\nelement amongst the smallest remaining records from each array. A \nmin-heap is ideal for maintaining a set of records when we  \nrepeatedly insert and query for the smallest record (both extract-min and insert\nwould take $O(\\log k)$ time). Hence we can do the merge in $O(n\\log k)$ time,\nwhere $n$ is the total number of records in the input. Here is the\ncode for this:\n\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nbool Greater(const pair<int, int>& a,\n\t     const pair<int, int>& b) {\n  if (a.first > b.first) {\n    return true;\n  } else if (a.first == b.first && a.second > b.second) {\n    return true;\n  } else {\n    return false;\n  }\n} \n\nvoid MergeSortedVectors(\n    const vector<vector<int> >& sorted_input, \n    vector<int>* output) {\n  // The first number is the smallest number remaining and\n  // the second number represents array from which it was taken.\n  vector<pair<int, int> > min_heap;\n  // We keep an index of the numbers read from each array.\n  vector<int> current_read_index(sorted_input.size());\n  for (int i = 0; i < sorted_input.size(); i++) {\n    if (sorted_input[i].size() > 0) {\n      min_heap.push_back(make_pair(sorted_input[i][0], i));\n      current_read_index[i] = 1;\n    }\n  }\n\n  make_heap(min_heap.begin(), min_heap.end(), Greater);\n\n  while (min_heap.size() > 0) {\n    pair<int, int> min = min_heap[0];\n    pop_heap(min_heap.begin(), min_heap.end(), Greater);\n    min_heap.pop_back();\n    output->push_back(min.first);\n    if (current_read_index[min.second] <\n        sorted_input[min.second].size()) {\n      // There are more inputs to be read. Read the next number\n      // and insert it in the heap.\n      min.first = sorted_input[min.second][current_read_index[min.second]];\n      current_read_index[min.second]++;\n      min_heap.push_back(min);\n      push_heap(min_heap.begin(), min_heap.end(), Greater);\n    }\n  } \n}\n\\end{lstlisting}\n\n% \\ans{merge-sorted-arrays}\n\n\\begin{comment}\nIan's solution\n\nMerge sorted arrays\n\nGiven $k$ sorted arrays of integers, return a sorted array containing the elements of the \nsorted arrays, including any duplicates.\n\nWhen combining multiple lists into an output, the ``merge'' step of merge sort comes \n to mind immediately---take items off the top of $k$ sorted sublists and combine them into a \nsingle output. This requires $k$ comparisons for each item in $n$, so  overall we require $O(k \\cdot n)$ \noperations. If $k$ is small, this is essentially linear in $n$. \nCode for that process in Python:\n\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Python++]\ndef TryMerge(k, n, a, b):\n \n    # construct a list of k arrays of n random elements \n    # in the range of a to b\n    lists = GetListOfSortedArrays(k, n, a, b)\n \n    # pass them in to Merge and report the output\n    return Merge(lists)\n \ndef GetListOfSortedArrays(k, n, a, b):\n    lists = list()\n    for i in range(k):\n        l = []\n        for j in range(n):\n            l.append(random.randint(a, b))\n        l.sort()\n        lists.append(l)\n    return lists\n \ndef Merge(lists):\n \n    # maintain dictionary of k pointers to the next item in each array\n    pointers = {}\n    for k in range (len(lists)):\n        pointers[k] = 0 # init all pointers to the start of their list\n \n    output = []\n    while len(pointers) > 0:\n        # look at the top item in each list\n        min = None\n        p = None\n        for k in pointers.keys():\n            val = lists[k][pointers[k]]\n            if min == None or val < min:\n                min = val\n                p = k\n \n        # add the item to the output and increment the pointer\n        output.append(min)\n        pointers[p] = pointers[p] + 1\n \n        # if the pointer is past the last item the list, remove \n\t# the pointer\n        if pointers[p] >= len(lists[p]):\n            del(pointers[p])\n \n    return output\n\\end{lstlisting}\n\nAnd some output:\n\n\\begin{verbatim} \nTryMerge(5, 5, 1, 100)\n\nOriginal: [[13, 63, 69, 72, 96], [2, 5, 7, 51, 92], [1, 12, 12, 33, 69], \n\t   [10, 12, 29, 44, 99], [8, 19, 19, 25, 80]]\n\nResult:   [1, 2, 5, 7, 8, 10, 12, 12, 12, 13, 19, 19, 25, 29, 33, 44, 51, \n\t\t63, 69, 69, 72, 80, 92, 96, 99]\n\\end{verbatim} \n\nIf, on the other hand, $k$ is large (for example, approaching the size of $n$) then the operation \ntends to $O(n^2)$ or greater, which is bad.\n\nInstead, assuming there is enough space to store an additional copy of each element, it is \npossible that inserting all the items into a heap and then pulling them off one at a time \ncould be quicker. Each heap insert requires $O(\\log n)$ time, so building the entire heap \nshould require $O(n lg n)$ time. However there is a method called ``bubble down'' that will \nactually create a heap from an array in roughly linear-time. Doing that would then allow \nus to get the list in $O(n)$ time even for large $k$. \n\nHere is the Python code approximating that solution:\n\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\ndef TryHeap(k, n, a, b):\n \n    # construct a list of k arrays of n random elements \n    # in the range of a to b\n    lists = GetListOfSortedArrays(k, n, a, b)\n \n    # return sorted version using a heap\n    return HeapSort(lists)\n \ndef HeapSort(lists):\n \n    # put the items into contiguous storage\n    input = []\n    for l in lists:\n        input.extend(l)\n    count = len(input)\n \n    # heapify (using python's built in library, which does bubble down \n    # heapification in near linear-time)\n    heapq.heapify(input)\n \n    # pull min value into output until heap is empty\n    output = []\n    for i in range(count):\n        output.append(heapq.heappop(input))\n    return output\n\\end{lstlisting} \n\nThis also correctly sorts the input lists.\n\nOf these two approaches, which one performs better on the same input? \nWe can add timing decorators to the function like so:\n\n\\begin{verbatim} \nimport time\ndef print_timing(func):\n    def wrapper(*arg):\n        t1 = time.time()\n        res = func(*arg)\n        t2 = time.time()\n        editor.AddText(\"\\n\" + func.func_name \n\t\t+ \" took \" + str((t2-t1)*1000.0) + \" ms\\n\")\n        return res\n    return wrapper\n\\end{verbatim} \n\nWe then add a decorator to each function:\n\n\\begin{verbatim} \n@print_timing\ndef TryHeap(k, n, a, b):\n    ...\n\\end{verbatim} \n\nThe timings thus obtained tell us about the function's performance in \ndifferent situations. As we might expect, with a small $k$, \nthe merge version beats the heap version: \n\n\\begin{verbatim} \n>> TryMerge(2, 1000000, 1, 10000)\nTryMerge took 12014.9998665 ms\n\n>> TryHeap(2, 1000000, 1, 10000)\nTryHeap took 13969.0001011 ms\nHowever, with a larger k, the heap version is faster (about five times as fast in one implementation):\n\n>> TryMerge(100, 3000, 1, 10000)\nTryMerge took 10780.9998989 ms\n\n>> TryHeap(100, 3000, 1, 10000)\nTryHeap took 2062.99996376 ms\n\\end{verbatim}\n\nDoubling $k$ roughly quadruples the time (which is consistent with \nthe assertion that the performance is $O(n^2)$ as $k$ approaches $n$). By \ncomparison, doubling $k$ in the heap version is (expectedly) a linear doubling:\n\n\\begin{verbatim} \n>> TryMerge(200, 3000, 1, 10000)\nTryMerge took 38062.0000362 ms\n\n>> TryHeap(200, 3000, 1, 10000)\nTryHeap took 4266.00003242 ms\n\\end{verbatim}\n\n\\end{comment}\n\n\\ans{app-sort}\nThe easiest way of looking at this problem is that we need to store\nthe numbers in memory till all the numbers smaller than this number have\narrived. Once those numbers have arrived and have been written to the\noutput file, we can go ahead and write this number. Since we do not\nknow how the numbers are shuffled, it is hard to tell when all the numbers\nsmaller than a given number have arrived and have been written to\nthe output. However since we are told that no number is off by more\nthan one thousand positions from its correctly sorted position, if more than\na thousand numbers greater than a given number have arrived and all the numbers\nsmaller than the given number that arrived have been written, we can\nbe sure that there are no more other smaller numbers that are going to\narrive. Hence it is safe to write the given numbers. \n\nThis essentially gives us the strategy to always keep 1001 numbers in\na min-heap. As soon as we read a new number, we insert the new\nnumber and then extract the min\nfrom the heap and write the output.\n\n\\begin{comment}\nIan's solution\n\nThere is a stream of numbers arriving as an input such that each number is at most 1000 \npositions away from its correctly sorted position. Write an algorithm that outputs \ncorrectly sorted numbers but uses only $O(1)$ storage.\n\nThe problem is essentially that of buffering a constant number of input items, $m$ (in this \ncase, $m = 1000$). A good data-structure to use for this (assuming ascending order) would be \na min-heap. If we use a heap, each insert would take $\\log m$ time. Since $m$ is a constant, this is really a constant time operation.\n\nInitially we would need to buffer $(m \\log m)$ records. For each additional item that comes in \nvia the stream, we first insert it into the heap ($O(lg m)$.\nThen we pop the min item off the heap. All the heap operations would be constant time with respect to $n$ since we are treating $m$ as a constant.\n\nHere is a Python implementation. First, we have to simulate an ``almost sorted'' stream which we can do with this Python function:\n\n\\begin{verbatim}\nimport random\nimport heapq\nimport math\n \n# Create an almost-sorted array of numbers\ndef GetInputStream(n, m):\n    ordered = range(0, n)\n    for i in range(0, n):\n        ordered[i] = random.randint(0, n)\n    list.sort(ordered)\n    permuted = range(0, n)\n    for i in range(0, n):\n        permuted[i] = None\n \n    # for each element, put it into a spot that's +/- m away \n    # from its original spot, checking first to see that \n    # that spot is available\n    for x in range(n):\n        moved = False\n        # first, see if I am forced into a slot by there being \n\t# an opening that is m lower than me\n        if x >= m and permuted[(x - m)] == None:\n            permuted[(x - m)] = ordered[x]\n            moved = True\n        else:\n            while moved == False:\n                newpos = random.randint(max(x - m, 0), min(x + m, n - 1))\n                if permuted[newpos] == None:\n                    permuted[newpos] = ordered[x]\n                    moved = True\n \n    return permuted\n\\end{verbatim} \n\nThis produces an input stream where every element is at most $m$ positions away from its \neventual sorted order. The original source material is a random list of numbers that has \nbeen put in ascending order. Each element is then moved to a randomly determined \nunoccupied position that is +/- $m$ slots away (taking care no gaps are left).\n\nThen, to sort the items, each is inserted into a min-heap, and when the heap size is \ngreater than m, one item is popped off (i.e., the min item is returned and removed from the \nheap and the heap is re-heapified) for every item that is pushed on.\n\n\\begin{verbatim}  \ndef AlmostSorted(n, m):\n    # simulate a stream of random numbers by creating an almost-sorted \n    # array of n numbers, and iterating over them\n    input = GetInputStream(n, m)\n \n    # prepare an output array to store the output in; if we \n    # were really streaming, this would not exist\n    output = range(0, n)\n    for i in range(0, n):\n        output[i] = None\n    counter = 0\n \n    # put each item into the heap, and if the size of the \n    # heap is over m, output the smallest item\n    heap = []\n    heapq.heapify(heap)\n    heapsize = 0\n    for i in range(n):\n        heapq.heappush(heap, input[i])\n        heapsize = heapsize + 1\n        if heapsize > m:\n            output[counter] = heapq.heappop(heap)\n            counter = counter + 1\n \n    # at the end of the stream, output the remaining items from the heap\n    while counter < len(output):\n            output[counter] = heapq.heappop(heap)\n            counter = counter + 1\n \n    return output\n\\end{verbatim}\n\n\nThis produces an output in sorted order, in constant time for each item regardless of the \nsize of $n$. (Of course, for this Python implementation, the entire program must execute, \nmaking the operation time linear in $n$).\n\n\\end{comment}\n\n\\ans{running-average}\nWhile it takes $O(k)$ time to compute the average of a window of size\n$k$, the successive averages for the sliding window can be computed\ninexpensively\nby maintaining the sum over the sliding window. When the window is\nslid by one position, the new sum can be computed like this: \n$sum_{i+1} = sum_i + x[i+k+1] - x[i]$.  Hence the entire running\naverage can be computed in $O(n)$ time.\n\nComputing the running median is a bit more involved but the same idea is applicable there as well. \nWhen we slide the window by one position, we delete the first element\nfrom the list and insert the next element. \nTherefore we need to maintain a set \nin a way that allows us to find the median easily in the presence of\ninserts and deletes.\nThis can be achieved with a balanced BST (an AVL tree or a red-black tree could do the job). \nBoth insert and delete are $O(\\log k)$ operations.\nFinding the median after an update amounts to looking for the successor or\npredecessor\nof the existing median depending on whether the update involved an element\nthat was larger or smaller than the current median.\nTherefore we can compute the running median in $(n\\log k)$ time for the entire series.\n\nAlternately, we could just use an order-statistic tree which is simply a balanced BST with\nsome additional information stored at each node.  Specifically, in an order-statistic\ntree, each node records the number of nodes in the subtree stored at that node.\nInserts and deletes can be done in $O(\\log n)$ time and retrieving\nan element with a given rank (which covers the median case)\ncan also be implemented in $O(\\log n)$ time.\n\n\n\n\\ans{event-simulation}\nEvent driven simulation is a classic problem and is used in a number\nof simulation applications including digital circuits. The main idea\nhere is that at any given point, we know all the future events that are\ngoing to happen as a direct result of events that have happened so\nfar. Until the first event in these set of events happens, nothing\nelse is going to happen. Hence we can advance time to this event\nwithout doing any new work. \n\nIn practice, this essentially amounts to maintaining a queue of events\nthat are going to happen as a direct result of past events, find the\nevent with the smallest time in this set, delete it from the set,\ncompute the events that this event would trigger, and then insert them\nin the event queue. For this application again, a min-heap works\nmost efficiently. \n\n\n\\chapter{ Meta-algorithms}\\normalsize\n\n\\ans{longest-nondecreasing}\nLet $s_i$ be the length of the longest nondecreasing subsequence of $A$ that ends\nat $A[i]$ (specifically, $A[i]$ is included in this subsequence). Then \nwe can write the recurrence\n\\[ \ns_i = \\max\\Big( \\max_{j: A[j] \\leq A[i], j < i} (s_j +1) , 1 \\Big) .\n\\]\n\nUsing this strategy, fill up a table for $s_i$. If we want the sequence as well, for\neach $i$, in addition to storing the length of the sequence, we can\nstore the index of the last element of sequence that we extend to get\nthis sequence. Here is an implementation of the idea:\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nvoid longestNondecreasingSequence(\n    const vector<int>& input, vector<int>* output) {\n  assert(output != NULL);\n  output->clear();\n  if (input.size() == 0) {\n    return;\n  }\n  vector<int> longestSequenceLength(input.size(), 1);\n  vector<int> previous_index(input.size(), -1);\n  longestSequenceLength[0] = 1;\n  int max_length = 1;\n  int longest_sequence_end = 0;\n  for (int i = 1; i < input.size(); i++) {\n    int length = 1;\n    int prev_index = -1;\n    for (int j = 0; j < i; j++) {\n      if (input[j] <= input[i] &&\n          longestSequenceLength[j] + 1 > length) {\n\tlength = longestSequenceLength[j] + 1;\n\tprev_index = j;\n      }\n    }\n    longestSequenceLength[i] = length;\n    previous_index[i] = prev_index;\n    if (max_length < length) {\n      max_length = length;\n      longest_sequence_end = i;\n    }\n  }\n  assert(output != NULL);\n  output->clear();\n  // Build the reverse of the longest sequence by going backwards from the end.\n  while(longest_sequence_end >= 0) {\n    output->push_back(input[longest_sequence_end]);\n    longest_sequence_end = previous_index[longest_sequence_end];\n  }\n  std::reverse(output->begin(), output->end());\n}\n\\end{lstlisting}\n\n\\ans{frog-crossing}\nLet $P[x]$ be true iff there is a stone in the river at $x$ meters.\n\nLet's define $F[x][y]$ to be a Boolean variable that is true iff it is\npossible for the frog to reach $x$ meters from the shore with the last\njump being $y$ meters. We can say that $F[0][y]$ is true iff $y=0$. Also,\n$F[x][y]$ can be true iff $P[x]$ is true (there is a stone there) and \nthat either $F[x-y][y]$,  $F[x-y][y+1]$, or $F[x-y][y-1]$ is true.\nUsing DP, we can compute the values of $F[n][y]$ for\nall possible values of $y$. One interesting thing to note here is that\nwhile jumping the first $n$ meters, the largest jump size could be at most\n$\\sqrt{2n}$. Hence we just need to worry about values of $y \\le\n\\lceil \\sqrt{2n} \\rceil $.  This gives us a runtime of $O(n^{1.5})$. Here is a\npossible implementation:\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nbool isReachable(const vector<bool>& p) {\n  if (p.size() == 0) {\n    return true;\n  }\n  // Max attainable jump size.\n  int m = sqrt(2 * p.size());\n  vector<vector<bool> > f(p.size() + 1);\n  // The first block can only be reached with jump of\n  // size 1 and no block can be reached with jump of\n  // size 0.\n  for (int j = 0; j <= m; j++) {\n    f[0].push_back(false);\n  }\n  for (int i = 1; i < p.size(); i++) {\n    f[i].push_back(false);\n  }\n  if (p[0]) {\n    f[0][1] = true;\n  }\n  for (int i = 1; i < p.size(); i++) {\n    for (int j = 1; j <= m; j++) {\n      f[i].push_back(false);\n      if (p[i] && i - j >= 0) {\n\tif (f[i-j][j]) {\n\t  f[i][j] = true;\n\t} else if (j > 0 && f[i-j][j-1]) {\n\t  f[i][j] = true;\n\t} else if (j + 1 < m && f[i-j][j+1]) {\n\t  f[i][j] = true;\n\t} \n      }\n      if (f[i][j] == true && i + j + 1 > p.size() ) {\n\t//From this point the frog can cross the river in\n\t// a single jump.\n\treturn true;\n      }\n    }\n  }\n  return false;\n}\n\n\\end{lstlisting}\n\n% \\ans{max-submatrix}\n% This is a fairly straightforward application of dynamic programming.\n% Let $A_{m,n}$ be the input matrix. Let $A(a,b,c,d)$ represent the\n% submatrix of $A$ that just contains rows $a$ through $c$, and columns\n% $b$ through $d$. Let $Sum(X)$ be the sum of all the elements in matix\n% $X$. Hence we want to find $\\argmax_{a,b,c,d} Sum(A(x,b,c,d))$.\n\n% Let's define $T(x,y)$ to be $max_{a,b}(Sum(A(a,b,x,y))$, i.e., the sum\n% of the largest submatrix that ends in $A[x,y]$. We define $T[x,0]$ and\n% $T[0,y]$ to be 0 for all values of $x$ and $y$. Then we \n\n\\ans{cutting-paper}\nSince the machine we have can only cut a piece of paper into two\npieces either vertically or horizontally and all the final pieces have integer\nlength and width, this significantly limits the space we\nhave to explore. Let $V(x,y)$ be the maximum value we\ncan extract out of a paper of width $x$ and height $y$.\nLet $U(x,y)$ be the price of a paper of dimension $x,y$ without\ncutting (if we cannot sell it as is, the value is set to 0).\n\nWe assert that\n\\begin{eqnarray*}\n\\lefteqn{V(x,y)  =  \\max} \\\\\n & & \\Big(\\max_{a \\in [0,x]} \\big(V(a,y) + V(x-a, y)\\big),  \\\\\n & & \\max_{b \\in [0,y]} \\big(V(x,b) + V(x, y-b)\\big),  \\\\ \n & & U(x,y)\\Big).\n\\end{eqnarray*}\n\nIn other words, the value of the paper is the max of the cost of the two\nvertically cut pieces or the two horizontally cut pieces or the paper\nas is. Using this recurrence relationship, we can use DP to compute the values of $V$ of interest in $O(a\\cdot b + n)$\ntime.\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nfloat computeMaxCost(int width, int length, vector<PaperPrice> prices) {\n  vector<vector<float> > V;\n  for (int i = 0; i <= width; i++) {\n    V.push_back(vector<float>(length + 1, 0));\n  }\n  for (int i = 0; i < prices.size(); i++) {\n    if (prices[i].length <= length && prices[i].width <= width) {\n      if (V[prices[i].width][prices[i].length] < prices[i].price) {\n\tV[prices[i].width][prices[i].length] = prices[i].price;\n      }\n    }\n  }\n\n  for (int i = 1; i <= width; i++) {\n    for (int j = 1; j <= length; j++) {\n      for (int k = 1; k < i; k++) {\n\tif (V[i][j] < V[i-k][j] + V[k][j]) {\n\t  V[i][j] = V[i-k][j] + V[k][j];\n\t}\n      }\n      for (int k = 1; k < j; k++) {\n\tif (V[i][j] < V[i][k] + V[i][j-k]) {\n\t  V[i][j] = V[i][k] + V[i][j-k];\n\t}\n      }\n    }\n  }\n\n  float result = V[width][length];\n  return result;\n}\n\\end{lstlisting}\n\n\\ans{word-breaking}\nThis is a straightforward DP problem. If the input\nstring $S$ has length $n$, we build a table $T$ of length $n$ such that $T[k]$ is a\nBoolean that tells\nus if the substring $S(0,k)$ can be broken into a set of valid words.\n\nWe can build a hash table of all the valid words such that we can\ndetermine if a string is a valid word or not in constant time.\nThen $T[k] $ is true iff there exists a $j \\in [0,k-1] $ such that\n$T[j]$ is true and $S(j,k)$ is a valid word.\n\nThis will just tell us if we can break a given string into valid words\nbut would not give us the words themselves. With a little more\nbook-keeping, we can achieve that. Essentially, in table $T$ along with\nthe Boolean value, we can also store the beginning index of the last word\nin the string.\n\nIf we want all possible decompositions, we can store all possible\nvalues of $j$ that gives us a correct break with each\nposition. However the number of possible decompositions can be exponential\nhere. For example, consider the string ``itsitsitsits...''.\n\n\n\\ans{elec-college}\nWe need to determine if there is a subset of states whose Electoral College votes add up to $\\frac{538}{2} = 269$. This is a version of the 0-1 knapsack problem described in Problem~\\ref{01knapsack} and the  DP solution to that problem can be used.\n\n\n\\ans{red-blue-house}\nNumber the individual elections from $1$ to $446$.\nLet $T(a,b)$ be the probability that exactly $b$ Republicans win out of elections $\\{1,2,\\ldots,a\\}$.\n\nLet $X_i$ be the event that a Republican wins the $i$-th race.\nThen $T(a,b) = Pr(\\sum_{i\\leq a} X_i = b)$.  \nThere are two ways in which the first $a$ random variables sum up to $b$: \nthe $a$-th random variable is 1 and the first $a-1$ variables sum up to $b-1$ \nor the $a$-th random variable is 0 and the first $a-1$ random variables sum up to $b$.\nSince these events are exclusive, the probability $T(a,b)$ is the sum\nof the probabilities of these two events.\nTo be precise, \\[ T(a,b) = T(a-1,b-1) \\cdot p_a + T(a-1,b) \\cdot (1-p_a) . \\]\nThe base cases for the recursion are $T(0,0) = 1$ and $T(0,b) = 0$, for $b > 0$.\nTherefore $T$ can be computed using DP. Since both $a$ and $b$ take \nvalues from $0$ to the number of races and computing $T(a,b)$ from\nearlier values takes constant time, the complexity is quadratic in the number of races.\n \n\\ans{load-balancing}\n% Let's say that you have $n$ users, with unique hashes  $h_1$ through $h_n$ and $m$ machines. Each user with hash  $h_i$ has  $B_i$  bytes to store. \n%  You need to find numbers $K_1$ through $K_m$  such that all users with hashes between\n% $k_j$ and $k_{j+1}$ get assigned to machine $j$.  How would find the numbers $K_1$ through $K_m$, such \n% that the load on the most heavily loaded machine is minimized?\nLet $L(a,b)$ be the maximum load on a server when users with hash $h_1$\nthrough $h_a$ are assigned to servers $S_1$ through $S_b$ in an\noptimal way so that the max load is minimized. We observe the following recurrence:\n\\[ L(a,b) = \\min_{x\\in\\{1,\\ldots,a\\}}\\Big(\\max\\big(L(x,b-1), \\sum_{i =\n  x+1}^a(B_i)\\big)\\Big) . \\]\n\nIn other words, we find the right value of $x$ such that if we pack\nthe first $x$ users in $b-1$ servers and the remaining in the last\nserver, the max load on a given server is minimized.\n\nUsing this relationship, we can tabulate the values of $L$ till we get\n $L(n,m)$.  While computing $L(a,b)$ when the values of $L$ is\ntabulated for all lower values of $a$ and $b$, we need to find the\nright value of $x$ to minimize the load. As we increase $x$, $L(x, b-1)$ in\nthe above expression increases and the term $ \\sum_{i =\n  x+1}^a(B_i))$ decreases. Hence in order to find $x$ that\nminimizes their max, we can do a binary search for $x$ which can be\ndone in $O(\\log a)$ time. Therefore we can compute the load in\n$O\\big(m n\\log(n)\\big)$ time.\n\n\\ans{voltage-selection}\nLet $V(g)$ be the voltage level assigned\nto gate $g$. Let $I(g)$ be the\nset of all gates that are inputs to $g$. Let $P(g)$  be the minimum possible power that can be achieved by\na legal assignment of voltages, wherein we choose a low voltage for gate  $g$.\nLet $Q(g)$ be the  minimum possible power that can be achieved  when\n$g$ is assigned a high voltage.\nWe can write the following recurrence relationship for $P$ and $Q$: \n\\begin{eqnarray*}\nP(g) & = & 1 + \\sum_{r \\in I(g)}Q(r) \\\\\nQ(g) & = & 2 + \\sum_{r \\in I(g)} \\min \\big( P(r), Q(r)\\big).\n\\end{eqnarray*}\n\nUsing these equations, we can tabulate the values of $P$ and $Q$\nfor all gates and our answer is going to come from the maximum of the values of  $P$ and  $Q$ for the gate at the root of the tree.\nSince we perform constant operations per gate, \nthe overall complexity is $O(G)$, where $G$ is the number of gates.\n\n\\ans{buffer-insertion}\nWe can formulate this DP in a manner similar to Solution~\\ref{voltage-selection}.\nFor each node, we tabulate $k$ values. Let $N(u, l)$\nbe the minimum number of buffers needed for the subtree rooted at \nnode $u$, if the first buffer above this node appears $l$ or more hops away. The\nrecurrence relationship can be defined by\n\\ifthenelse{\\boolean{createspace}}{\n\\[N(n, l) = \\sum_{c \\in I(n)}\\min\\Big( 1 + N(c, k), N\\big(c, \\min(l+1, k)\\big)\\Big) . \\]\n}\n{\n\\begin{eqnarray*}\n\\lefteqn{[N(n, l) =} \\\\\n& & \\sum_{c \\in I(n)}\\min\\Big( 1 + N(c, k), N\\big(c, \\min(l+1, k)\\big)\\Big) .\n\\end{eqnarray*}\n}\n\nWe can tabulate the value of $N$ for all nodes from the leaf to the root for\nall values of $l \\le k$. Then $N(r,k)$, where $r$ is the root,\nis the minimum number of buffers needed.\nSince we perform $O(k)$ operations per gate, \nthe overall complexity is $O(G\\cdot k)$, where $G$ is the number of gates.\n\n\n\\ans{triangulation}\nLet's label the vertices of the polygon $1,\\ldots,n$, starting from\nan arbitrary vertex and walking clockwise.  Let $C(p_1,\\ldots, p_k)$ be the cost\nof triangulating the polygon formed by vertices $p_1$ through $p_k$. Let $L(a\\cdot b)$ be the length of the straight line drawn from vertex\n$a$ to vertex $b$. \n\n Now, we know that if the number of vertices in the polygon is three or\n less, the cost is zero.  Consider an edge $\\langle p_i, p_{i+1}\\rangle$. One of the\n triangles must contain this edge. The third vertex of the triangle is\n going to be another vertex, say $p_j$. Then the cost of triangulation\n is going to be the cost of triangle $\\langle p_i, p_{i+1}, p_j\\rangle$ and the\n cost of triangulation of the smaller polygons formed by removing this\n triangle (which may be 1 or 2 polygons depending upon whether $j = i\n + 2$ or not). For any pair of points $a$ and $b$, let $L(a,b)$ be the\n length of the line segment joining $a$ and $b$. Then we can write the\n following recurrence relationship: \n\\begin{eqnarray*}\n\\lefteqn{A(p_1, \\ldots, p_k) = \\min_{x: 3 \\le x \\le  k} \\Big(} \\\\\n& & A(p_3, \\ldots, p_x)  \\\\\n& & + A(p_x, \\ldots,p_k,p_1) + L(p_1, p_2) + L(p_1,p_x) + L(p_2,p_x)\\Big).\n\\end{eqnarray*}\nIf we tabulate the cost of triangulation of each polygon that is a\nresult of picking subsequent points on the original polygon, we\nwould need to do this for roughly $n^2$ polygons. If we have\nalready tabulated the value for all smaller polygons, it will take\nus $O(n)$ time for doing so. Hence we can compute the minimum cost in\n$O(n^3)$ time.\n\n\\begin{comment}\n\\ans{climbing}\nLet $F(n)$ be the number of ways of climbing $n$ stairs through a\ncombination of 1 or 2 steps.  We can note that $F(1) = 1$ and $F(0) =\n1$.\nNow, all paths that lead us to cross $n$ steps either start with a\nsingle step or a double step. In case of a single step, there are\n$F(n-1)$ ways of completing the path. In case of a double step, there\nare $F(n-2)$ ways of completing the path. Hence \n\\[ F(n) = F(n-1) + F(n-2) , \\] \nwhich leads to a simple dynamic programming algorithm that can compute\n$F(n) $ in $O(n)$ time. An interesting thing to note \nhere is that $F(n)$ has the same recurrence relationship as Fibonacci numbers and $F(n)$ is actually $(n +1)$-th Fibonacci number.\n\n\\end{comment}\n\n\\ans{arith-expr}\nWe focus on the case where all the operands are nonnegative integers\nand the only operations are $\\cdot$ and $+$. \n\nRepresent the expression $v_0 \\circ_0 v_1 \\circ_1 \\cdots \\circ_{n-2} v_{n-1}$ \nby arrays $V = [v_0,\\ldots,v_{n-1}]$ and $\\circ_0,\\ldots,\\circ_{n-2}$.\n\nLet $\\mbox{Max}[i,j]$ denote\nthe maximum value achievable by some parenthesization for\nthe subexpression $v_i \\circ_i v_i \\circ_i \\cdots \\circ_{j} v_{j}$,\nwhere $\\mbox{Max}[i,j]$ is just $V[i]$.\n\nThe key to solving this problem is to recognize that if operation \n$\\circ_i$ is performed last, the subexpressions\n$v_0 \\circ_0 v_1 \\circ_1 \\cdots \\circ_{i-2} v_{i-1}$ and\n$v_{i+1} \\circ_{i+1}  \\cdots \\circ_{n-2} v_{n-1}$ must be parenthesized\nto be maximized individually.  \n\nIn particular, the maximum value must be achieved\nfor some value of $i$ in $[0,n-2]$, so \n\\[\n\\mbox{Max}[0,n-1] = \\max_{i \\in [0,n-2]} \\mbox{Max}[0,i] \\circ_i \\mbox{Max}[i+1,n-1] .\n\\]\nThe total number of recursive calls is $O(\\binom{n}{2})$ and each\ncall requires $O(n)$ additional computation to combine the results,\nleading to an $O(n^3)$ algorithm.\n\nEfficiently computing this recurrence requires that intermediate\nresults be cached. In code:\n\\lstinputlisting[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Java]{Parens.java}\n\nFor the more general cases, we need to keep track of the minimum and maximum values\nas well as the positive and negative values closest to zero.\nThis makes the code more complicated but does not change the \ncharacter and the complexity of the algorithm.\n\n\\ans{point-covering}\nWe schedule tutors greedily: as soon as there is a request that cannot be handled by the previously assigned tutors, we choose a new tutor. \n\nWhile it is simple to implement this scheme, it is not completely\ntrivial to prove that it is\noptimum, i.e., we cannot cover all the requests with fewer\ntutors.\n\nIn order to prove the optimality we will define the notion of slack.\nConsider a set of requests $j_1,\\ldots,j_n$ such that the requests are ordered by the time\nthey need to be done. Let $S(j)$ and $E(j)$ be the starting and ending\ntime for request $j$.  Let $t_i,\\ldots,t_m$ be the times when we assign a\ntutor, ordered by time. \n% It may be possible for the last tutor to be\n% able to return after doing the last job and return in less than an\n% hour.  \n\nDefine the time the last tutor assigned has available after his last request\nis fulfilled as the slack in the schedule.\n\nWe claim that greedy scheduling is the optimum scheduling. \nWe can prove this using induction over the number of requests; \nfor our induction hypothesis, in addition to the claim that\nthe number of tutors is minimized, we claim that the schedule maximizes the slack.\nFor $n=1$, the greedy algorithm will send exactly one tutor\nat the start time of the request; clearly this is the strategy that uses the minimum number of tutors and no more slack is possible.\n\nLet's assume that this statement is true for all values of $n \\le k$. \n Now we can prove this for $n = k +1$ as follows: consider the requests\n $j_1,\\ldots,j_k$ sorted by their start time. Consider that\n $t_1,\\ldots,t_m$ are the times when we scheduled the tutors to cover\n these requests based on the greedy strategy. Now, when we add the next\n request $j_{k+1}$ to the list, either it can be covered by slack or\n it may require a new tutor.\n\nIn the case the new request can be\n covered by the slack, clearly this is the optimum solution (if we\n needed at least $m$ tutors to cover the first $k$ requests, we\n cannot cover the $k+1$ requests with fewer tutors). Also, in this case,\n since the schedule for the first $k$ requests\n maximized the slack, we cannot have a\n better schedule with $m$ tutors that cover all $k+1$ requests\n and have a bigger slack.\n\nIn case we need to pick an additional tutor for the $k+1$-th request,\nit must be that the $m$-th\ntutor did not have the slack to cover the last request. If there is\nanother way to cover the requests with $m$ or less tutors, then we can use\nthe same set of tutors to cover the first $k$ requests and get a bigger slack,\nwhich contradicts our assumptions. Also, since the $(m+1)$-th tutor\nwill start exactly when the last request starts, this schedule must maximize the slack.\n\n\\ans{minimize-waiting-time}\nLet's say that the time for the $i$-th customer to be serviced is $c_i$. Then the\nwaiting time for the customer $c_i$ would be $\\sum_{j=1}^i t_{c_j}$.\nHence sum of all the wait times would be\n\\[\\sum_{i=0}^n \\sum_{j=1}^i t_{c_j} = \\sum_{i=0}^n t_{c_i}\\cdot i . \\]\n\nSince we want to minimize the total wait time for all the customers\nand $c_i$s must take values from 1 through $n$, it follows that the\ncustomers who take the smallest time must get served first. Hence we\nmust sort the customers by their service time and then serve them in\nthe order of increasing service time.\n\n\\ans{huffman-coding}\nHuffman coding is an optimum solution to this problem (there could be\nother optimum codes as well).  Huffman coding proceeds in three steps:\n\\begin{enumerate}\n\\itemsep 1pt\n\\item Sort symbols in increasing order of probability and create a\n  binary tree node for each symbol.\n\\item Create a new node by combining the smallest probability\n  nodes as children and assigning it the probability of the sum of its\n  children.\n\\item Remove the children from consideration and add the new node into\n  the sorted list of nodes to be combined and repeat the entire\n  process till we have a single rooted binary tree.\n\\end{enumerate}\n\nOnce we have the rooted tree, we can assign all the left edges as 0\nand the right edges as 1. All the original symbols would be the leaf nodes\nin this tree and the path from root to the leaf node would give us the\nbit sequence for that symbol.\n\nNow, we need to prove (1.)~this encoding is optimum and (2.)~find\na fast implementation of this algorithm.\n\nFor implementing this idea, we can maintain a min-heap of candidate nodes\nthat can be combined in any given step. Since each combination step\nrequires two {\\em extract-min} and one {\\em insert} operation that can be\ndone in $O(\\log n)$ time, we can find the Huffman codes in $O(n \\log n)$\ntime.\n\nWe can prove the optimality of Huffman codes inductively. For a\nsingle code, obviously Huffman codes are optimum. Let's say that for\nany probability distribution among $n$ symbols, Huffman codes are\noptimum. Given this assumption, we will prove it is true for\n$n+1$.  Suppose there is another encoding that has a smaller expected\nlength of code  for some probability distribution for $n +1$\nsymbols.\n\n For any encoding, we can map the codes to a binary tree by\ncreating the null string to root and adding a left edge for each 0 and\na right edge for each 1. We can make several observations about this binary tree:\n\\begin{itemize}\n\\itemsep 1pt\n\\item Each symbol must map to a leaf node; otherwise, our prefix\n  assumption will be violated.\n\\item There cannot be a nonleaf node that has less than two children\n  (otherwise, we can delete the node and bring its child one level up\n  and hence reduce the expected code length).\n\\item If we sort the binary tree leaves in order of their path lengths,\n  the two longest paths must have the same length (since the\n  parent of the leaf with the longest path must have another child).\n\\item The two nodes with the longest paths in the tree must be assigned to\n  the two symbols with the smallest probability (otherwise, we can swap\n  symbols and achieve smaller expected code length).\n\\item If we remove the two smallest probability symbols and replace them\n  with one symbol that has its probability equal to the sum of the probabilities of the replaced symbols, the optimum prefix\n  coding must have the same expected code length as this tree when we\n  delete the two lowest probability nodes (otherwise, we can use this\n  new optimum tree and replace it with the old tree).\n\\end{itemize}\n\n\nNow consider that the symbols have probabilities $p_1 \\le p_2 \\le\n\\ldots \\le p_{n+1}$.  \nLet $O(p_1,\\ldots, p_{n+1})$ be the optimum\nexpected code length for this probability distribution and\n$H(p_1,\\ldots, p_{n+1})$ be the expected code length for Huffman coding. So, we can\neasily see that\n\\ifthenelse{\\boolean{createspace}}{\n\\[ O(p_1,\\ldots, p_{n+1}) = O(p_1,\\ldots, p_{n-1}, p_n + p_{n+1}) +\np_n + p_{n+1} . \\]\n}\n{\n\\begin{eqnarray*}\n\\lefteqn{O(p_1,\\ldots, p_{n+1}) =} \\\\\n& & O(p_1,\\ldots, p_{n-1}, p_n + p_{n+1}) + p_n + p_{n+1} .\n\\end{eqnarray*}\n}\nThe way we construct Huffman codes we know that \n\\ifthenelse{\\boolean{createspace}}{\n\\[ H(p_1,\\ldots, p_{n+1}) = H(p_1,\\ldots, p_{n-1}, p_n + p_{n+1}) +\np_n + p_{n+1} . \\]\n}\n{\n\\begin{eqnarray*}\n\\lefteqn{ H(p_1,\\ldots, p_{n+1}) = } \\\\\n& & H(p_1,\\ldots, p_{n-1}, p_n + p_{n+1}) +\np_n + p_{n+1} . \n\\end{eqnarray*}\n}\n\nBy our inductive assumption, \n\\ifthenelse{\\boolean{createspace}}{\n$H(p_1,\\ldots, p_{n-1}, p_n + p_{n+1}) =\nO(p_1,\\ldots, p_{n-1}, p_n + p_{n+1})$. \n}\n{\n\\begin{eqnarray*}\n\\lefteqn{ H(p_1,\\ldots, p_{n-1}, p_n + p_{n+1}) = } \\\\\n & & O(p_1,\\ldots, p_{n-1}, p_n + p_{n+1}).\n\\end{eqnarray*}\n}\nHence $H(p_1,\\ldots,\np_{n+1}) = O(p_1,\\ldots, p_{n+1})$. In other words, Huffman coding\nis optimum for $n+1$ symbols.\n\n\\ans{efficient-ui}\nThis problem is very similar in structure to the Huffman coding\nproblem above, if $c =1$. If we represent each click on the sub-menu\noperation as a $1$ and each scan down operation as a $0$, then the path\nto reach a menu item can be represented as a string of $0$s and $1$s.\nThe time it would take to reach each menu item is proportional to the\nlength of this string. And finally, we cannot have two actions mapped\nto two strings such that one is a prefix of the other. Hence if we\nuse Huffman coding algorithm to come up with the bit-strings for each\naction and then build the menu system based on these strings, we would\nachieve the minimum expected time to interact with the menu.\n\nWhen $c > 1$, it is similar to the case where there is an asymmetric cost\nfor a $0$ and a $1$ in the code (for example, it requires more power\nto transmit a $1$ than a $0$). There is no known polynomial time\nsolution for this case. Below we describe an algorithm that will take $O(2^n \\cdot n \\cdot \\log n)$ time:\n\\begin{enumerate} \n\\itemsep 1pt\n\\item Sort each operation by the probability of its occurrence.\n\\item Iterate over all possible binary tree structures with\n  $n$ leaves. Map each left edge in the binary tree as a scan down\n  operation and each right edge as a clock to open sub-menu operation.\n\\begin{enumerate}\n\\item For each leaf, compute the time it takes to reach the node\n  (number of left edges + $c$ times the number of right edges in the path to the node).\n\\item Sort the nodes in the order of time it takes to reach it.\n\\item Map the actions to the nodes such that the highest probability\n  action is mapped to the lowest visit time. Compute the expected visit\n  time to the nodes.\n\\end{enumerate}\n\\item Find the tree structure that has the lowest expected time to\n  visit.\n\\end{enumerate}\nThe number of unique binary trees with $n$ leaves is roughly $O(2^n)$.\n \n\\ans{first-fit}\nThis can be trivially done in $O(n^2)$ time if we do a linear scan for\nthe boxes for each new object to find the first box where it would fit.\n\nIn order to speed things up, we can maintain a list of boxes where a\ncertain capacity is available for the first time.  For each box, we\nkeep a record which contains the remaining box capacity and the box\nnumber. We will maintain a sorted list of boxes, first by box capacity,\nthen by box number. When we receive a new item, we look for the first\nrecord with capacity greater than or equal to the item's weight. We put it\nin the corresponding box, update its capacity, and reinsert it at the\ncorrect position. In order to maintain a sorted list, we can use a\nbalanced binary tree such that find, delete, and insert are all\n$O(\\log n)$ operations.\n\n\\ans{point-covering-1}\nA covering set $S$ must contain at least one point $x$\nsuch that $x \\leq b_{min} = \\min\\{b_i\\}$. Any such point covers the subset \nof intervals $[a_i,b_i], a_i \\leq b_{min}$. Of course, $b_{min}$ itself covers\nall such intervals and so there exists a minimum cardinality covering\nthat contains $b_{min}$ and no other points to its left. Consequently,\nthe following procedure computes a minimum covering set $S$:\n\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nI = {1,2,...,n};\nS = {};\nwhile (I != {}) {\n  bmin = min{b[i] | i in I}\n  S = S + {bmin};\n  I = I - {i|a[i] <= bmin};\n}\n\\end{lstlisting}\n\nUsing a balanced BST, we can implement the search for minimum, insertion, and deletion in $O(\\log n)$ time, yielding an $O(n\\log n)$ algorithm.\n\n\\ans{point-covering-2}\nIf there is some point on the circle that is not contained in at least one\nof the $n$ arcs, then the problem is identical to Problem~\\ref{point-covering-1}.\nSo, suppose this is not so.  Without loss of generality, we may assume that a minimum\ncardinality covering set $S$ contains only right endpoints of arcs, i.e., ``clockwise''\nright endpoints. There are $n$ such endpoints.  If we choose a given right endpoint\nand eliminate all the arcs that are covered by it, the remaining problem\nis identical to that in Problem~\\ref{point-covering-1}. This means we\ncan solve the arc-covering problem by $n$ calls to the algorithm \nin Solution~\\ref{point-covering-1}, yielding an $O(n^2 \\log n)$\nalgorithm.\n\n\\ans{magazines}\nSuppose our algorithm computes\nthe clustering $C = \\{O_1,O_2,\\ldots,O_k\\}$.  Suppose $C$ is not optimum,\ni.e., there is another clustering $P  = \\{P_1,P_2,\\ldots,P_k\\}$ which lowers the separation.\nSince $C$ and $P$ are distinct, there must be some pair of objects $a,b$\nthat are assigned to the same cluster in $C$ but different clusters in $P$---otherwise, either $C$ and $P$ would be identical or some $P_i$ would be empty, which was\nexplicitly disallowed.\n\nLet $u,v$ be the last pair of objects that we merged in our algorithm.\nSuppose $x,y$ were the next pair our algorithm would have merged if\nwe had performed one more iteration, i.e., computed a $k+1$-clustering.\nObserve that $d(x,y)$ is the separation of $C$ since $x$ and $y$\nare a pair of closest objects not in the same cluster.\n\nNow, our algorithm has put $a$ and $b$ in the same cluster,\nthere is some set of pairs of the form $\\{(a,\\delta_1),\n(\\delta_1,\\delta_2),\\ldots,(\\delta_{l-1},\\delta_l), (\\delta_l,b)\\}$ that our algorithm selected.\n(It may be that the set is simply $\\{(a,b)\\}$ if we directly selected $d(a,b)$.)\nSince $a$ and $b$ are in different clusters in $P$, one of these pairs, call it $e$, must be\nin distinct $P_i$ and $P_j$. Therefore the separation of $P$ is at most $d(e)$, which is\nno more than $d(u,v)$. Now $d(u,v)$ is no more than $d(x,y)$, which is the\nseparation of $C$. Therefore the separation of $P$ is no more than that of $C$, contradicting the choice of $P$.\nTherefore $C$ has the maximum separation of all $k$-clusterings. \n\n\\ans{party-planning}\nWe compute the optimum invitation list by iteratively removing \npeople who cannot meet Leona's constraints until there\nis no one left to remove---the remaining set\nis the unique maximum set of people that Leona can invite.\n\nSpecifically, we iteratively remove anyone who has fewer than six friends in the current set or anyone \nwho has fewer than six people they do not know in the current set.\nThe process must converge since we start with a finite number of\npeople and remove at least one person in each iteration.\nThe remaining set satisfies Leona's constraints by construction.\n\nIt remains to show that the remaining set is maximum. \nIn fact, we show something stronger, namely that it is the unique \nmaximum set that satisfies Leona's constraints.\n\nWe do this by proving that people who are removed could never be \nin a set that satisfies the constraints.  We do this \nby induction on the order in which the people were removed.\n\nThe first person $P_1$ removed was removed because either $P_1$ had fewer\nthan six friends in the entire set or the number of people \n$P_1$ did not know was fewer than six---clearly $P_1$ cannot belong to any set that satisfies\nthe constraints, let alone the maximum set.  \n\nInductively, assume the first $i-1$ persons removed could not belong to any set that satisfies\nthe constraints.  \n\nConsider $P_i$, the $i$-th person we remove. It must be that \neither fewer than six people know $P_i$ \nin the current set or $P_i$  does not know fewer than six people in the current set.  \nBut by induction, the current set includes any maximum set, so \nthe $i$-th person removed cannot belong to a maximum set and induction goes through.\n\n\\chapter{ Algorithms on Graphs}\n\n\n\n\\ans{maze}\nModel the maze as an undirected graph.  Each vertex corresponds to a white pixel.\nWe will index the vertices based on the co-ordinates of the corresponding pixel; so, vertex $v_{i,j}$ corresponds to the matrix entry $(i,j)$.\nEdges model adjacent pixels; so, $v_{i,j}$ is connected\nto vertices $v_{i+1,j}$, $v_{i,j+1}$, $v_{i-1,j}$, and $v_{i,j-1}$, assuming these\nvertices exist---vertex $v_{a,b}$ does not exist if the corresponding pixel is black\nor the co-ordinates $(a,b)$ lie outside the image.\n\n\nNow, run a DFS starting from the vertex corresponding to the entrance. If at some point, we discover the exit vertex in the DFS, then there exists a path from the entrance to the exit .\nIf we implement recursive DFS then the path would consist of all the vertices in the call stack corresponding to previous recursive calls to the DFS routine.\n\nThis problem can also be solved using BFS from the entrance vertex\non the same graph model.  The BFS tree has the property that the\ncomputed path will be a shortest path from the entrance.  However\nBFS is more difficult to implement than DFS since in DFS, the compiler implicitly\nhandles the DFS stack, whereas in BFS, the queue has to be explicitly\ncoded up.  Since the problem did not call for a shortest path,\nit is better to use DFS.\n\n\\begin{comment}\nIan's solution\n\nIt is natural to apply graph models and algorithms to spatial problems. Consider a black \nand white image of a maze: white pixels represent open areas and black spaces are walls. \nThere are two special pixels, one is designated the entrance and the other is the exit.\n\nGiven a two-dimensional matrix of black and white entries representing a maze, with \ndesignated entrance and exit points, find a path from the entrance to the exit, if one \nexists.\n\nFirst, we need a routine to construct such mazes. In Python, we will deal with this input \nmaze as a two-dimensional array of characters (if we needed to preserve space, we could do \nit with a two-dimensional bit matrix but this is fine for our purposes and will produce \nclearer codes). When printed, such an array might use asterisks to show walls and spaces to \nshow paths. Of course, if we create an array with random gaps, it is very unlikely that \nthere will ever be a path through the maze, so we can do a little better: we can \ninitialize the maze to all walls, then ``carve'' paths in it that are runs of several \nspaces, either vertically or horizontally.\n\n\\begin{verbatim} \nimport random\ndef CreateMaze(width, height):\n    NUMPATHS = (width * height) / 2\n    MAXPATHLENGTH = min(width, height) / 3\n    maze = []\n    for i in range(width):\n        row = []\n        for j in range (height):\n            row.append(\"*\")\n        maze.append(row)\n    # now randomly carve some paths\n    for p in range (NUMPATHS):\n        x = random.randint(0, width - 1)\n        y = random.randint(0, height - 1)\n        direction = random.randint(0,1)\n        length = random.randint(0, MAXPATHLENGTH)\n        CarvePath(maze, x, y, length, direction)\n    return maze\n \ndef CarvePath(maze, x, y, length, direction):\n    #editor.AddText(\"Carving path \" + str(x) + \", \" + str(y) + \", \" + str(length) + \", \" + str(direction) + \"\\n\")\n    if direction == 0:\n        for xpos in range(x, min(x+length, len(maze))):\n            maze[xpos][y] = \" \"\n    else:\n        for ypos in range(y, min(y+length, len(maze[x]))):\n            maze[x][ypos] = \" \"\n \ndef PrintMaze(m):\n    for row in m:\n        for char in row:\n            editor.AddText(char)\n        editor.AddText(\"\\n\")\nAn example maze, of size 32 x 64, is shown here:\n\n>> PrintMaze(CreateMaze(32, 64))\n\n** **     *  **  **      ************* *******************    **\n** ** **                  **   ******** **  **     ***       * *\n** **  *  * **** ****    *** ***     ** *******               **\n*      **** ****  **           * ******  *** ** ********** *  **\n *       ****      *      **      ** **  *** ** ** *  **** *  **\n      * ***** **       * *** *    ** **  **  ** *    ***** ** **\n        * *****    *     ***   *   * ***           ******* **  *\n * **      **        * *  **** *  ** ***      * *  ** ***  **   \n        * *** * *          *** *  * ** *  **        * ***    *  \n              ***  *         **** *             * ** ***   *    \n    *     *** *     *   *  *         * ****     * ******   * ** \n    *  *** ** *    ***       ***  * ** * * *     *         * ** \n **        *       ***  *    **** * * ** ***   * * *****  ******\n  **** * * *  **** **        **** * *    *** **  * *****  ***** \n   *****        ** **         *** *    ** **       * ***     * *\n* * ****       ***    *****         * * * ** ** ** * ***  **    \n* *      **        ** *****  *     ** *** ****     * *    **   *\n      * ***                         **     * **  * * **** *     \n* * ***             * * **          ****   *  *  *******     ** \n******        * *     * *      * *  ****      *          *      \n******       *      *   ***    * *  *  **         *    *     ** \n**              *   *   *** *       **    *   * ***    * ** *** \n**  **          * *  *  ***                     ***  * *     ** \n**  **  **      *    *  *** *        **** * *   *** **** **     \n**  *             * **   ** ** *      **  * *    *  ****  ** ** \n *        **  **  ** *  **         **                 **     ** \n *  ** **         **         *** **       * **  ** *   *      * \n *  ******* * *  *      * *  ****  *           *   ** **  ***** \n  ****      * *   * *   * *        * *  * *******  ****   * **  \n    ******  * *  *  *     *               ** *****        *  ** \n     ** **               ******   *  *          ***  **       * \n  ***** **  *** * **     **    *     **   **  * * *  *          \n\\end{verbatim} \n\nThe constants for the number of paths and the maximum path length were determined empirically .\n%(I \n%just tried different numbers until I found some that seemed to make %mazes with long, \n%winding paths through them at this size).\nA more sophisticated approach would be to have \neach path branch off the previous one with some probability but this will work for now.\n\nNext, we have to create a graph representation of the open spaces that shows for every \nopen space what other spaces it connects to in the four cardinal directions. A good Python \ndata-structure for a graph is a dictionary (i.e., hash table) where the keys are locations \n(in our case, $x/y$ co-ordinates) and the adjacency list is a list contained in the \ndictionary's value. For example, in the maze above, the short ``hallway'' starting at \nposition (2, 0) and extending down might be represented as:\n\n\\begin{verbatim} \nmazegraph = {\n    (2, 0): [(2, 1)],\n    (2, 1): [(2, 0), (2, 2)],\n    (2, 2): [(2, 1), (2, 3)],\n    etc.\n}\n\\end{verbatim} \n\nWe can build a graph of the maze in this way pretty simply---go one location at a time, \nfrom top left to bottom right, and build the adjacency dictionary.\n\n\\begin{verbatim} \ndef BuildMazeGraph(maze):\n    mazegraph = {}\n    for r in range(len(maze)):\n        for c in range (len(maze[r])):\n            # if it's open\n            if maze[r][c] == \" \":\n                # add each of the four cardinal directions if empty and within maze\n                if r < (len(maze) - 1):              #down\n                    if maze[r+1][c] == \" \":\n                        addMazeNode(mazegraph, (r, c), ((r+1), c))\n                if c < (len(maze[r]) - 1):           #right\n                    if maze[r][c+1] == \" \":\n                        addMazeNode(mazegraph, (r, c), (r, (c+1)))\n                if r > 0:                            #up\n                    if maze[r-1][c] == \" \":\n                        addMazeNode(mazegraph, (r, c), ((r-1), c))\n                if c > 0:                            #left\n                    if maze[r][c-1] == \" \":\n                        addMazeNode(mazegraph, (r, c), (r, (c-1)))\n    return mazegraph\n \ndef addMazeNode(mazegraph, k, v):\n    if k not in mazegraph:\n        mazegraph[k] = []\n    mazegraph[k].append(v)\nThis builds a (nonconnected) graph data-structure from the maze:\n\n>> len(BuildMazeGraph(CreateMaze(32, 64)).keys())\n\n  = 1261\n\\end{verbatim} \n\nFinding a path from any square to any other, if one exists, is as simple as doing a search \nfrom the start to the end node using the graph-based version of the maze. In our case, we \nhave not yet designated a start and end square, and since we are generating the maze \nrandomly, we have to do that first. An easy choice is to take the first empty square \nstarting from the top left and make it the start, and likewise the last empty square from \nthe bottom right, and make it the end (this may make our mazes more difficult, i.e., less \nlikely to have a solution, but hopefully we have tweaked the creation algorithm to the point \nwhere such paths happen occasionally, as they do in the generated example above). \nEnd-point calculation is done like so:\n\n\\begin{verbatim} \ndef CalculateEntries(maze):\n    # beginning and end are defined as the first and the last blank space\n    start = end = \"\"\n    for r in range(len(maze)):\n        for c in range(len(maze[r])):\n            if start == \"\" and maze[r][c] == \" \":\n                start = (r, c)\n            if maze[r][c] == \" \":\n                end = (r, c)\n    return start, end\n\\end{verbatim} \n\nFrom there, we solve the maze by doing a search (a depth-first search in this case) for a \npath from the start to the end:\n\n\\begin{verbatim} \ndef FindPath(mazegraph, start, end, path=[]):\n    mypath = path[:] # make a copy of the incoming path, do not change it by reference\n    mypath.append(start)\n    if start == end:\n        return mypath\n    if not mazegraph.has_key(start):\n        return None\n    for node in mazegraph[start]:\n        if node not in mypath:\n            newpath = FindPath(mazegraph, node, end, mypath)\n            if newpath: return newpath\n    return None\n\\end{verbatim} \n\nWe can now use a function that marks the maze with each item on the found path. Rather \nthan using a single character, using a counter that ranges from 0 to 9 can give us a \nbetter feel for what path was actually taken. Together:\n\n\\begin{verbatim}  \ndef MarkPath(maze, path):\n    if path != None:\n        counter = 0\n        for node in path:\n            maze[node[0]][node[1]] = str(counter % 10)\n            counter = counter + 1\n    return maze\n \ndef SolveMaze(maze):\n    start, end = CalculateEntries(maze)\n    mazegraph = BuildMazeGraph(maze)\n    return MarkPath(maze, FindPath(mazegraph, start, end))\n\\end{verbatim} \n\nThis seems to work, and returns solved mazes some of the time:\n\n\\begin{verbatim} \n>> PrintMaze(SolveMaze(CreateMaze(10, 20)))\n\n*0  ******** *******\n 1 * *******     *  \n 290123**** * ****  \n 38***4     *  **** \n*47***5**** ** **   \n 56** 6789  *  *    \n* *** ***012  * ****\n  *** *** *3    *   \n* **   ** *45**  *  \n*** *  *****67890123\n\\end{verbatim} \n\nHowever the time to do this is quite variable depending on the exact layout of \nthe maze---some larger mazes (say, $15\\times 15$) with many paths and no \nsolutions can take several minutes \nto return a solution. This could be fixed by better use of memory, tighter algorithms, \netc.\n\nNote also that it is not the shortest path (in the example above, it goes all the way down \nto step five (position $(1, 5)$) before turning up again).\n\\end{comment}\n\n\\ans{link-binary-tree-nodes}\nIf you traverse the binary tree in BFS order,\nthen you are guaranteed to hit all the nodes at the same depth\nconsecutively. So, you can build the linked list of all the nodes as you\ndiscover them in BFS order. While traversing the tree, we also need to know when we move from\nnodes of depth $k$ to nodes of depth $k + 1$. This can be easily\nachieved by keeping track of the depth when inserting nodes in\nthe queue.\n\n\\ans{conn}\n%Let's say $G$ has Property~$C0$ iff there exists an edge $e$ such\n%that $G' = (V, E-\\{e\\})$ is connected.\nFirst, we consider the problem of checking if \n$G$ is $2\\exists$-connected.\nIf $G' = (V, E- \\{(u,v)\\})$ is connected, it must be that a path exists between $u$ and $v$.\nThis is possible iff $u$ and $v$ lie on a cycle in $G$.  Thus $G$ is $2\\exists$-connected\niff there exists a cycle in $G$.\n\nWe can check for the existence of a cycle in $G$ by running DFS on $G$.  As soon as\nwe discover an  edge from a gray vertex back to a gray vertex which is not its immediate\npredecessor in the search, a cycle exists in $G$ and we can stop.\n\nThe complexity of DFS is $(|V| + |E|)$; however in the case described above,\nthe algorithm runs in $O(|V|)$ time. This is because an undirected\ngraph with no cycles can have at most $|V|-1$ edges.\n\n%Let's say $G$ has Property~$C1$ iff for all edges $e$\n% $G' = (V, E-\\{e\\})$ is connected.\n\nNow, we consider the problem of checking if $G$ is $2\\forall$-connected.\n Clearly, $G$ is not $2\\forall$-connected iff there exists an edge $e$\n such that $G' = (V, E-\\{e\\})$ is disconnected.\n The latter condition holds iff there is no cycle including edge $e$.\n\n We can find an edge $(u,v)$ that is not on a cycle with DFS. \n Without loss of generality, assume $u$ is discovered first.\n Observe that the removal of $(u,v)$ disconnects $G$ iff there are no back-edges\n between $v$ or $v$'s descendants to $u$ or $u$'s ancestors.\n\n Define $l(v)$ to be the minimum of the discovery time $d(v)$ of $v$ and\n $d(w)$ for $w$ such that $(t,w)$ is a back-edge from $t$, where $t$ is a\n descendant of $v$.\n\n We claim $l(v) < d(v)$ iff there is a back-edge between $v$ or one of $v$'s descendants \n to $u$ or one of $u$'s ancestors.\n If $l(v) < d(v)$, then there is a path from $v$ through one of its descendants \n to an ancestor of $v$, i.e., $v$ lies on a cycle. \n If $l(v) = d(v)$, there is no way to get from $v$ back to $u$; hence\n removal of $(u,v)$ disconnects $u$ and $v$.\n\n Now, we show how to compute $l(v)$ efficiently: once we have processed all of $v$'s children,\n then $l(v) = \\min\\big(d(v), \\min_{x \\, \\mbox{\\scriptsize child of } \\,v} l(x) \\big)$.  This computation\n does not add to the asymptotic complexity of DFS since it is just a constant\n additional work per edge, so we can check $2\\forall$-connectedness in linear-time.\n\n\\ans{wiring}\nAssuming the pins are numbered from $0$ to $p-1$,\ncreate an undirected graph $G$ on $p$ vertices $v_0,\\ldots,v_{p-1}$.\nAdd an edge between $v_i$ to $v_j$ if pins~$i$~and~$j$ are connected by a wire.\n\nAssume for simplicity, $G$ is connected; if not, the connected components can\nbe analyzed independently.\n\nRun BFS on $G$ starting with $v_0$. Assign $v_0$ arbitrarily to lie on the left\nhalf.  All vertices at an odd distance from $v_0$ are assigned to the right half.\n\n\nWhen performing BFS on an undirected graph, all newly discovered edges will\neither be from vertices which are at a distance $d$ from $v_0$ to undiscovered vertices (which will\nthen be at a distance $d+1$ from $v_0$) or from vertices which are at a\ndistance $d$ to vertices which are also at a distance $d$. First, assume we never encounter an edge from\na distance $k$ vertex to a distance $k$ vertex. In this case,\neach wire is from a distance $k$ vertex to a distance $k+1$ vertex, so all wires are between\nthe left and right halves.\n\nIf any edge is from a distance $k$ vertex to a distance $k$ vertex,\nwe stop---the pins cannot be partitioned into left and right halves as desired.\nThe reason is as follows:  let $u$ and $v$ be\nsuch vertices. Consider the first common ancestor $a$ in the BFS search of $u$ and $v$ (such an\nancestor must exist since the search started at $v_0$).  The paths $p_{a,u}$ and $p_{a,v}$ in the BFS tree from $a$ to $u$ and $v$ are\nof equal length; therefore the cycle formed by going from $a$ to $u$, then through the edge $(u,v)$, and then back to $a$ from $u$ via\n$p_{a,v}$ has an odd length.  The vertices in an odd length cycle cannot be partitioned into two sets such that all edges\nare between the sets.\n\n\n\n\\ans{tc}\nIt is natural to model the network as a graph: vertices correspond\nto individuals and an edge exists from $A$ to $B$ if $B$ is a contact of $A$.\n\nFor an individual $x$, we can compute the set of $x$'s contacts by running graph search \n(DFS or BFS) from $x$.  Running graph search for each individual leads\nto a $O\\big(| V |\\cdot ( |V| +|E|)\\big)$ algorithm for transitive closure.\n\nAnother approach which has complexity $O(|V|^3)$ but which may be\nmore efficient for dense graphs is to run an all-pairs shortest path algorithm\nwith edge weights of 1.  If there is a path from $u$ to $v$, the \nshortest path distance from $u$ to $v$ will be finite; otherwise, it\nwill be $\\infty$.  We can further improve the shortest path calculation\nby simply recording whether there is a path from $u$ to $v$ or not; in this\nway, we need a Boolean matrix rather than an integer matrix encoding the\ndistances between the vertices.\n\n\\ans{euler}\nLet $v$ be any vertex in $G$.\nConsider an Euler tour $T$ of $G$.\nEach time the tour enters $v$, it must exit $v$ by a different edge.  Furthermore,\neach edge must be entered exactly once and exited exactly once.  Hence\nwe can put incoming edges and outgoing edges in a 1-1 correspondence, so\nthe in-degree and out-degree of $v$ must be equal.\n\nConversely, let the in-degree and out-degree of every vertex $v$ in $G$ be equal.\nConstruct an Euler tour as follows:\nstart with an arbitrary vertex.  Use DFS to explore from this vertex until a simple cycle is found.\nSuch a cycle must exist since we can never get trapped in a vertex---if we entered a newly discovered vertex, we can\nalways exit it because of the constraint that in-degree equals out-degree.\n\nContinue doing this till all the edges have been partitioned into disjoint simple cycles.  Now, merge these cycles as follows: start with any cycle.  For any vertex on the\ncurrent cycle, find a cycle that it is in, which is not the current cycle, and add a detour to this new cycle.\nIteratively add cycles to the current cycle.\n\nWe claim that all disjoint cycles must be merged by this process.\nIf not, there must be an edge $(p,q)$ on a simple cycle $S$ that is not in\n the cycle $C$ our process has converged to, where   $p$ appears in $C$ (such\nan edge exists because the graph is connected).  We can merge the edges of $S$ to our cycle\nabout $p$, thereby contradicting the maximality of $C$.\n\nThe algorithm for constructing the cycles is just DFS and the merge process is also linear-time, so the algorithm is linear-time.\n\n\\ans{eph}\nModel the FSM as a graph---each state $s$ corresponds to a distinct vertex $v_s$.\nThe edge set consists of precisely those edges\nwhich correspond to potential\ntransitions between states;\nspecifically, $(v_s,v_t) \\in E$ iff $\\exists i \\, T(s,i) = t$.  We will refer to states\nand vertices interchangeably.\n\nNow, consider the directed acyclic graph (DAG) of strongly connected components (SCCs) for this graph.  Any state not in an SCC (which is the sink of this DAG)\nmay transition out of the SCC which it is in and once it is out, it will not return.\nConversely, all states within the sink SCCs can return to themselves, so the states in the\nsink SCCs are precisely the nonephemeral states; the complement  of this set is the desired set of ephemeral states.\n\nThe SCC DAG of a graph can be computed in linear-time from the\ngraph model and the graph itself can be constructed in linear-time from the FSM, so the whole computation is linear.\n\n\\ans{tree-diam}\nWe can compute the diameter by running BFS from each vertex and recording the largest shortest path distance. This has\n$O\\big(|V|\\cdot(|V|+|E|)\\big) = O(|V|^2)$ complexity since $|E| = |V|-1$\nin a tree.\n\nWe can achieve better time complexity by using divide-and-conquer.\nLet $r$ be any vertex. We take $r$ to be the root of the tree $T$.\nSuppose $r$ has degree $m$ and\nthe subtrees rooted at $r$'s children are $T_1,T_2,\\ldots,T_m$. Let \n$d_1,d_2,\\ldots,d_m$ be their diameters and $h_1,h_2,\\ldots,h_n$ their heights.\n\nLet $\\lambda$ be a longest path in $T$. Either it\npasses through $r$ or it does not. \nIf it does not pass through $r$, it must be entirely within one of the $m$ subtrees and hence the longest path length in $T$ is the maximum of $d_1,d_2,\\ldots,d_m$.\nIf it does pass through $r$, it must be between a pair of vertices in distinct subtrees\nthat are farthest from $r$. The distance from $r$ to the vertex in $T_i$ that is farthest\nfrom it is simply $f_i = h_i + 1$.\nThe longest length path in $T$ is the larger of the maximum of $d_1,d_2,\\ldots,d_m$ and the two largest $f_i$s.\n\nIf we process the subtrees one at a time,\nupdate $\\max_i\\{d_1,d_2,\\ldots,d_i\\}$, and the largest and second\nlargest of the $f_is$, the time complexity is proportional to the\nsize of the tree, i.e., $O(|V|)$.\n\n\n\\ans{timing-analysis}\nAssume the inputs to the network stabilize at time $0$.\nWe are trying to bound when the primary outputs stabilize.  \n\nSuppose gate $g$ has a delay $D(g)$.  It will stabilize at\nno more  than $D(g)$ time after all its inputs have stabilized.\nTherefore we can compute when each gate has stabilized by processing gates\nin topological order, starting from the primary inputs---for each gate,\nwe can bound when it stabilizes since we have already bounded when its\ninputs have stabilized.  Topological ordering for a graph\ncan be computed in $O(n+m)$\ntime, where $n$ and $m$ are the number of vertices and edges in the graph.\n\nThe value we compute is an upper bound and may not be tight because of\nlogical relationships between signals---for example, if one of the inputs to an\nAND gate is 0, then the output of the AND gate will be independent of the changes at its other inputs.\n\n\\ans{team-photo-1}\nLet $A$ and $B$ be $n$-dimension real vectors;\nwrite $A < B$ if $A[i] < B[i]$ for each $i$. \nThe $<$ relation is transitive.\n\nLet $\\langle x_1,x_2,\\ldots,x_{20}\\rangle$ be the heights of\nthe players in Team~X and $\\langle y_1,y_2,\\ldots,y_{20}\\rangle$\nbe the heights of the players in Team~Y.\nThe key observation\nis that Team~X can be placed in front of Team~Y\niff $\\mbox{\\textsc{sort}}\\langle x_1,\\ldots,x_{20}\\rangle < \\mbox{\\textsc{sort}}\\langle y_1,\\ldots,y_{20}\\rangle$.\n\nNow, we define a DAG $G$ with vertices corresponding\nto the teams as follows: there is an edge from vertex $X$ to $Y$ iff\n$\\mbox{\\textsc{sort}}(X) < \\mbox{\\textsc{sort}}(Y)$.\n\nEvery sequence of teams where the successive teams can \nbe placed in front of each other corresponds to a path in $G$. \nTo find the longest such sequence, we simply need to find the longest\npath in the DAG $G$. We can do this, for example, by topologically\nordering the vertices in $G$; the longest path terminating at vertex \n$v$ is the maximum of the longest paths terminating at $v$'s fanins\nconcatenated with $v$ itself.  \n\nThe topological ordering computation is $O(|V| + |E|)$\nand dominates the computation time.\n\n% Use Dilworth's theorem decomposition into chains\n\n\\ans{radio-freq}\nThe most obvious approach is to start with an arbitrary two-coloring.  \nIf it is diverse, we are done.  \n\nAt this point, a natural approach  would be to look  for a nondiverse vertex $v$\nand flipping $v$'s color but this can result in some of $v$'s \nneighbors becoming nondiverse.\n\nTo prove that this approach works, we look at {\\em diverse} edges---edges between \nvertices of different colors.\nWe claim that a coloring that maximizes the number of diverse edges is also\ndiverse.\n\nIf not, suppose $x$ is not diverse.  Without loss of \ngenerality, suppose $x$ is white. Then by changing $x$'s color to black,\nthe number of diverse edges strictly\nincreases (since $x$ had more white  neighbors than black neighbors).\n\nTherefore a coloring which maximizes the number of diverse edges\nyields a diverse graph. Such a coloring must exist: because the\ngraph is finite, there are only a finite number of colorings.\nWe can construct a coloring by starting with an arbitrary coloring \nand applying the argument above, i.e., finding nondiverse vertices\nand flipping their color.\n\n\n\\ans{sp-min-edge}\nUsually Dijkstra's shortest path algorithm uses scalar values for edge\nlength. However it can easily be modified  to the case\nwhere edge weight is a vector if {\\em addition} and {\\em comparison} can be defined over\nthe vectors. In this case, if the edge cost  is $c$, we\nsay the length of the edge is given by the vector  $\\langle c, 1\\rangle$. We define addition to be\njust component-wise addition. Hence if we sum up the edge lengths over a\npath, we essentially get the total cost and the number of edges in the\npath. The compare function can be just the lexicographic (first by the total cost, then by the number of edges). With this, we can run Dijkstra's shortest path algorithm and find the shortest path that\nrequires the least number of edges.\n\n\\begin{comment}\nA key step in Dijkstra's algorithm for single-source shortest paths\ninvolves updating the shortest path estimates as the vertices are discovered.\n\nInstead of storing shortest path length estimates, we can store\na shortest path estimate and the fewest number of edges\nfor this estimate.  We will record these in two arrays $d[x]$ and $w[x]$.\n\nThe process of relaxing the edge $(r,s)$\nthen updates the shortest path estimate as follows: if $d[r] + d(r,s) < d[s]$, then\n$d[s] = d[r] + d(r,s)$ and $w[s] = w[r] + 1$; if  $d[r] + d(r,s) < d[s]$,\nnothing  is updated;  and if  $d[r] + d(r,s) = d[s]$ and\n$w[s] > w[r] + 1$, $w[s] = w[r] + 1$.\n\nThis has the same complexity as Dijkstra's algorithm but keeps track of\nthe fewest edges on a shortest path.\n\\end{comment}\n\n\\ans{number-sp}\nWe can compute the number of shortest paths by \nperforming a BFS-type computation starting at $u$.\n\nConsider the set of vertices $S_{k-1}$ such that for any vertex $a \\in S_{k-1}$, the shortest\n distance between $u$ and $a$ is $k-1$. Now, consider a vertex $v$ such that the shortest distance\n between $u$ and $v$ is $k$. If we know the number of shortest paths between $u$ and any vertex in\n $S_{k-1}$, we can easily infer the number of shortest paths between $u$ and $v$ by summing up this\n number for all vertices $a \\in S_{k-1}$ that also have an edge to $v$.  This is because each \n distinct path from $u$ to $a$ also gives us a distinct path from $u$ to $v$ by simply adding the\n edge from $a$ to $y$ to the path. \n\nBFS runs in linear-time and, assuming we store the number of shortest paths\nfrom intermediate vertices, the computation for a distance $k$ node\nis proportional to the number of its outgoing edges. Hence the complete\nalgorithm runs in linear-time.\n\n\\begin{comment}\n\nIan's solution---\n \nMost of the problem we've considered involve finding a single optimum solution. Sometimes \nwe may want to know the number of optimum solutions. For example, there may be multiple \nshortest paths between two vertices of a graph.\n\nDevelop a linear-time algorithm that computes the number of shortest paths from a vertex u \nto a vertex v in an undirected graph, where each edge weight is one.\n\nThe brute force algorithm for finding shortest paths (i.e. compute all possible paths) \nwould give us an easy way to determine the number of optimal solutions but it is clearly \nnot linear-time.\n\nWhen we use a breadth-first search to compute shortest path, it is linear but we typically \nonly get one shortest path - the algorithm explicitly ignores other possible paths, \nleaving a tree with only one path from the root to any node. However, if we store depths \n(aka path lengths) as well as found count as we traverse the graph, any time we \nencounter a node, we can see if the depth we're encountering it at now is the same as the \nshortest depth, and if so, increment the number of optimal paths counter. Then we simply \nlook at this number for the target:\n\nWe can start by making a simple undirected graph G(v,e) as:\n\\begin{verbatim}\ndef MakeUndirectedGraph(v, e):\n    # create an undirected graph of v nodes with e edges\n    graph = {}\n    for i in range(v):\n        graph[i] = []\n    while e > 0:\n        v1, v2 = random.randint(0, (v - 1)), random.randint(0, (v - 1))\n        if (v1 != v2) and v2 not in graph[v1]:\n            graph[v1].append(v2)\n            graph[v2].append(v1)\n        e = e - 1\n    return graph\n\\end{verbatim}\n\n\nWe can then use our variant of the standard iterative BFS algorithm, keeping a data \nstructure with the best depth and found count as we go:\n\n\\begin{verbatim}\ndef NumShortestPaths(graph, source, target):\n    nodes = {} # a hash table for storing the depth and found count, for each node\n    queue = [] # a queue for BFS processing, which also stores the depth\n    current_depth = 0\n    queue.append((source, current_depth))\n    nodes[source] = (current_depth, 1) # tuple of depth & found count\n \n    while queue != []:\n        current, current_depth = queue.pop(0) # get the next node to process in BFS        \n        for neighbor in graph[current]:\n            if neighbor not in nodes:\n                queue.append((neighbor, current_depth + 1))\n                nodes[neighbor] = (current_depth + 1, 1)\n            else:\n                node_depth, node_found_count = nodes[neighbor]\n                if current_depth + 1 == node_depth: # in BFS, can never find a shorter, but can find same\n                    nodes[neighbor] = (node_depth, node_found_count + 1)\n \n    return nodes[target][1]\n\\end{verbatim} \n\nA run shows:\n\n\\begin{verbatim} \n>> NumShortestPaths(MakeUndirectedGraph(20, 40), 0, 19)\n\n = 2\nThe debug output for this run shows that for this graph:\n\n{\n    0: [16, 7, 18, 2, 17], \n    1: [15], \n    2: [6, 0, 12], \n    3: [8, 17, 18, 19], \n    4: [16, 15, 12], \n    5: [17, 11, 12, 15], \n    6: [2, 14], \n    7: [0, 17], \n    8: [9, 19, 3, 11, 14], \n    9: [8], \n    10: [15], \n    11: [12, 15, 8, 5, 18], \n    12: [18, 2, 13, 11, 17, 5, 4], \n    13: [15, 12], \n    14: [6, 8], \n    15: [13, 10, 16, 11, 18, 1, 4, 19, 5], \n    16: [0, 15, 4], \n    17: [7, 5, 0, 3, 12], \n    18: [12, 0, 3, 15, 11], \n    19: [8, 15, 3]\n}\n\\end{verbatim} \nThe two shortest paths to 19 are:\n\n\\begin{verbatim} \n0 -> 16 -> 15 -> 19\n0 -> 17 -> 3  -> 19\n\\end{verbatim} \n\nThe processing tree looked like this (indented by depth):\n\\begin{verbatim} \nPopped off queue: node 0, depth 0\n    Added to queue: node 16, depth 1, found count 1 \n    Added to queue: node 7, depth 1, found count 1 \n    Added to queue: node 18, depth 1, found count 1 \n    Added to queue: node 2, depth 1, found count 1 \n    Added to queue: node 17, depth 1, found count 1 \n    Popped off queue: node 16, depth 1\n        Added to queue: node 15, depth 2, found count 1 \n        Added to queue: node 4, depth 2, found count 1 \n    Popped off queue: node 7, depth 1\n    Popped off queue: node 18, depth 1\n        Added to queue: node 12, depth 2, found count 1 \n        Added to queue: node 3, depth 2, found count 1 \n        Incremented in queue: node 15, depth 2, new count 2\n        Added to queue: node 11, depth 2, found count 1 \n    Popped off queue: node 2, depth 1\n        Added to queue: node 6, depth 2, found count 1 \n        Incremented in queue: node 12, depth 2, new count 2\n    Popped off queue: node 17, depth 1\n        Added to queue: node 5, depth 2, found count 1 \n        Incremented in queue: node 3, depth 2, new count 2\n        Incremented in queue: node 12, depth 2, new count 3\n        Popped off queue: node 15, depth 2\n            Added to queue: node 13, depth 3, found count 1 \n            Added to queue: node 10, depth 3, found count 1 \n            Added to queue: node 1, depth 3, found count 1 \n            Added to queue: node 19, depth 3, found count 1 \n        Popped off queue: node 4, depth 2\n        Popped off queue: node 12, depth 2\n            Incremented in queue: node 13, depth 3, new count 2\n        Popped off queue: node 3, depth 2\n            Added to queue: node 8, depth 3, found count 1 \n            Incremented in queue: node 19, depth 3, new count 2\n        Popped off queue: node 11, depth 2\n            Incremented in queue: node 8, depth 3, new count 2\n        Popped off queue: node 6, depth 2\n            Added to queue: node 14, depth 3, found count 1 \n        Popped off queue: node 5, depth 2\n            Popped off queue: node 13, depth 3\n            Popped off queue: node 10, depth 3\n            Popped off queue: node 1, depth 3\n            Popped off queue: node 19, depth 3\n            Popped off queue: node 8, depth 3\n                Added to queue: node 9, depth 4, found count 1 \n            Popped off queue: node 14, depth 3\n                Popped off queue: node 9, depth 4\n\\end{verbatim} \n\n\\end{comment}\n\n\n\n\n\\ans{rand-dag-path}\n% The proof of NP-completeness was given by\n% http://www.google.com/url?sa=t&source=web&ct=res&cd=2&ved=0CB8QFjAB&url=http%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fdownload%3Fdoi%3D10.1.1.78.3513%26rep%3Drep1%26type%3Dpdf&ei=rgz-S97KD4T78Aar78zQDQ&usg=AFQjCNHXvyetloBHkO7iOZLz0tb0BbLuhQ&sig2=Gu3sEXprs9xPLiYLybbc2A\n%\n% Bicriteria Shortest Path Problems in the Plane\nThis is an NP-complete problem and hence there is no efficient algorithm known\nfor it. However if the probabilities assigned to each edge come from  a small set of numbers or if we\nare willing to approximate the probabilities, then this can be solved efficiently.\n\nIt is natural to solve this problem using dynamic programming---we iteratively compute\nthe matrix $M^{k}_p(s,t)$ which is the shortest path distance between vertices $s$ and $t$ \nsuch that the probability of a path existing with that distance is at least $p$ and the\nnumber of edges in the path is exactly $k$.\n\nGiven $M^k_p(s,t)$, we can compute $M^{k+1}_p(s,t)$ using the recurrence\n\\ifthenelse{\\boolean{createspace}}{\n\\[\nM^{k+1}_p(s,t) = \\min{p'}\\min_{u \\, \\in\\,  \\mbox{\\scriptsize fanin}(t)}\\big(M^{k}_{p'}(s,u) \\cdot M^{1}_{p/p'}(u,t)\\big) .\n\\]\n}\n{\n\\begin{eqnarray*}\n\\lefteqn{M^{k+1}_p(s,t) = } \\\\\n & & \\min{p'}\\min_{u \\, \\in\\,  \\mbox{\\scriptsize fanin}(t)}\\big(M^{k}_{p'}(s,u) \\cdot M^{1}_{p/p'}(u,t)\\big) .\n\\end{eqnarray*}\n}\nThere are an infinite number of values for $p$: any real number in $[0,1]$. \nIn reality, there are only a finite number of paths, so we only need to   consider\nthose probabilities. However the number of paths in a graph can be exponential\nand each path can have a distinct probability, so it is not realistic to\nconsider the possible set of values for $p$. Instead, we can take the approach \nof binning: we compute $M^{k}_{p}$  for a range of values for $p$, e.g.,\n$p = \\frac{n}{100}, \\; n = 0\\, \\mbox{to} \\, 100$.\n\n\\ans{rand-dag}\nLet's model the map  as a graph $G=(V,E)$ such that each room $i$ is\nrepresented by vertex $v_i\\in V$ and an edge $(v_,v_j)\\in E$ exists\niff there is a way to go from room $i$ to room $j$. Let\n$l(e)$ be the length of the corridor represented by the edge $e$.\n\nThe key idea here is to assign each room an expected time to the\ntreasure room\nwhen we follow the optimal strategy. Let's say for room $i$, the\nexpected time to the treasure room is $t(i)$. Then for a nonspecial room $i$, we\nwould always pick the next room to be the one that gives us the\nsmallest expected time to the treasure room. Hence for nonspecial room $i$\n\\[ t(i) = \\min_{j:(i,j) \\in E} \\Big(l\\big((i,j)\\big) + t(j)\\Big) . \\] \nOn the other hand, for the special rooms, the expected time is going to\nbe the average of the expected times through all the outgoing edges. Hence for special room $i$\n\\[ t(i) = \\mbox{avg}_{j:(i,j) \\in E} \\Big(l\\big((i,j)\\big) + t(j)\\Big) . \\] \nAlso, if the treasure room is vertex $s$, then $t(s)=0$. Using these\nrelationships, we can compute $t(i)$ for each vertex $i$ by\ninitializing $t(i) = \\infty$ for all nodes $i\\not=s$ and $t(s)= 0$.\nThen we apply the relaxation for each node based on one of the two\nabove equations. Since this graph is a DAG, after $|V|$ steps of\nrelaxation, we would reach a fixed point. This algorithm would have a\nruntime of $O(|E|\\cdot|V|)$ since each relaxation phase takes $|E|$\ntime. This can be further improved by inverting the graph, doing a\ntopological sort of the graph by starting at node $s$, and then\ncomputing $t(i)$ for node $i$ in topological order. \n\n\nOnce we have all the values of $t$ computed, if we are in any room where\nwe have to make a choice, we choose the corridor that minimizes the\nexpected time to the treasure room. \n\n\n\\begin{comment}\nFrom Ian Varley\n\nBase case: trivial.  1 hop---either go to treasure room in one hop or go to a special room,\nknow the prob that the special room will work.  2 hop---go deterministically, get 1-hop answer,\nor go to a special room, get 1-hop answer.\n\nThe difference between this and our maze in the previous problem is that this graph is now \ndirected - you can only pass from one room to another in one direction. We also no longer \nhave the expectation of a square matrix - rooms can have any number of passages and can \nalready connect to any other rooms anywhere in the maze. Per clarification via email, this \ngraph is also acyclic, so there are no back links or two way corridors.\n\nThis can be simulated simply by creating a set of N random  nodes, then walking through the \nnodes a single time and making one or more randomized forward connections from each node \n(starting at a random node and proceeding through every node, modulo the number of nodes). \nThe result is a directed acyclic graph. Each room is labeled with a random number between \n0 and (n-1).\n\n\\begin{verbatim} \n# create a graph with n nodes and up to c directed connections per node\ndef CreateRandMaze(n, c):\n    # create graph\n    mazegraph = {}\n    for i in range(n):\n        mazegraph[i] = []\n \n    # add edges between nodes: start at any node, cycle through \n    # remaining nodes, adding forward connections only\n    #offset = random.randint(0, (n-1))\n    offset = 0\n    for j in range(n):\n        m = (offset + j) % n\n        # insert a random number of random forward links\n        for k in range(random.randint(0, c)):\n            dest = (offset + random.randint(j, (n-1))) % n\n            if dest != m and dest not in mazegraph[m] and dest in mazegraph:\n                mazegraph[m].append(dest)\n \n    return mazegraph\n\\end{verbatim} \n\nThis creates simple directed acyclic graphs as in the following case (where ``offset'' was \nrandomly chosen to be zero):\n\n\\begin{verbatim} \n>> CreateRandMaze(10,20)\n\n{\n    0: [1, 6, 2], \n    1: [7, 4], \n    2: [7, 8, 5], \n    3: [5, 8, 9], \n    4: [8, 9, 7, 5], \n    5: [6, 9, 7, 8], \n    6: [8, 7], \n    7: [9, 8], \n    8: [], \n    9: []\n}\n\\end{verbatim} \n\nNote that there are actually two nodes with no incoming links: 0 and 3. We will pick those \nnodes to be our starting rooms and then randomly pick one node with no outgoing links as \nour treasure room. Our first pass at the algorithm should return the shortest path from \nthe start rooms to the treasure; later, we will modify that to deal with special rooms.\n\nWe can easily find the shortest path using a recursive BFS or DFS that returns the path \nlength and node list. This is an unweighted graph, so each edge costs 1. Note that this \nsimple version of ShortestPath only works in acyclic graphs - for graphs with possible \ncycles, a more robust algorithm like Dijkstra's algorithm should be used. Since there can \nbe multiple entrances, our return has the following structure:\n\n\\begin{verbatim} \n    { # maze graph:\n        room: [exits ...], \n        room: [exits ...], \n        ...\n    },\n    { # solution: for each entrance \n        entrance: (length, [path ...]), \n        entrance: (length, [path ...]), \n        ...\n    }\ndef SolveDirectedMaze(mazegraph):\n    # solve the shortest path in the maze between a chosen start and end node\n    paths = {}\n    treasure = len(mazegraph) - 1\n    for entrance in GetEntrances(mazegraph):\n        paths[entrance] = ShortestPath(mazegraph, entrance, treasure)\n    return mazegraph, paths\n \ndef ShortestPath(graph, start, end):    \n    if start == end: return 0, [end]\n    sl, sp = len(graph) + 1, None\n    for dest in graph[start]:\n        l, p = ShortestPath(graph, dest, end)\n        if l < sl:\n            sl = l\n            sp = p\n    if sp != None:\n        sp.insert(0, start)\n    return sl + 1, sp\n \ndef GetEntrances(mazegraph):\n    possibles = {}\n    for room in mazegraph.keys():\n        possibles[room] = True\n    for room in mazegraph:\n       for dest in mazegraph[room]:\n            possibles[dest] = False\n    entrances = []\n    for room in possibles.keys():\n        if possibles[room] == True and len(mazegraph[room]) > 0: \n\t    # entrances must have at least one exit\n            entrances.append(room)\n    return entrances\n\n>> SolveDirectedMaze(CreateRandMaze(14, 5))\n\n = (\n    {\n        0: [9, 13, 2], \n        1: [4, 7, 9], \n        2: [12], \n        3: [7, 11], \n        4: [10, 12, 8, 9], \n        5: [], \n        6: [12], \n        7: [8, 9], \n        8: [9], \n        9: [11, 13, 10], \n        10: [11], \n        11: [13, 12], \n        12: [13], \n        13: []\n    },\n    {\n        0: (1, [0, 13]), \n        1: (2, [1, 9, 13]), \n        3: (2, [3, 11, 13]), \n        5: (16, None), \n        6: (2, [6, 12, 13])\n    } \n)\n\\end{verbatim} \n\nHow should we alter this strategy in the face of special rooms? We are still solving a \nshortest path problem; however we need to deal with the cost of hitting a special node \ndifferently than a regular node. When asked for the cost of a path from a special room to \nthe treasure, instead of returning the min path, it should return an average of its paths.\n\nIf the treasure is not reachable from all nodes, the length of the shortest path  from that node may be infinity. While writing programs, this may present a problem and usually substituting infinity with a very large number works well.\n\nWe can make the maze ``special'' by passing it through a function that simply adds a special \ntoken to the edge list of f randomly selected nodes:\n\n\\begin{verbatim} \n# add a marker to the edge list of a random set of f nodes\ndef Randomize(mazegraph, f):\n    SPECIAL = -1\n \n    # choose a set of f nodes\n    rooms = mazegraph.keys()[:]\n    specialnodes = []\n    popout = 1000 # there may be cases where we get unlucky, and the # of branching rooms is < f\n    while f > 0 and popout > 0:\n        specialnode = random.randint(0, len(rooms) - 1)\n        if len(mazegraph[rooms[specialnode]]) > 1: # only make branching rooms special\n            specialnodes.append(rooms[specialnode])\n            del(rooms[specialnode])\n            f = f - 1\n        popout = popout - 1\n    specialnodes.sort()\n \n    # add marker to chosen rooms\n    for m in specialnodes:\n        mazegraph[m].append(SPECIAL)\n    return mazegraph\n\\end{verbatim} \n\nOur solution then changes only in that we return an average instead of the min:\n\n\\begin{verbatim} \ndef SolveDirectedRandomMaze(randommazegraph):\n    # solve the shortest path in the maze between a chosen start and end node\n    paths = {}\n    treasure = len(randommazegraph) - 1\n    for entrance in GetEntrances(randommazegraph):\n        paths[entrance] = RandomShortestPath(randommazegraph, entrance, treasure)\n    return randommazegraph, paths\n \ndef RandomShortestPath(graph, start, end):\n \n    MAX = len(graph) * 2 # some slightly large number, can be tweaked\n    SPECIAL = -1\n \n    if start == end: \n        return 0, [end]\n    if len(graph[start]) == 0: \n        return 0, None\n    if SPECIAL in graph[start]:\n        # calculate average\n        totallength, numpaths, possiblepaths = 0, 0, []\n        for dest in graph[start]:\n            if dest != SPECIAL:\n                l, p = RandomShortestPath(graph, dest, end)\n                numpaths += 1\n                if p == None:\n                    totallength += MAX\n                else:\n                    totallength += l\n                possiblepaths.append(p)\n        if numpaths > 0:\n            averagelength = float(totallength) / float(numpaths)\n            if possiblepaths != None:\n                possiblepaths.insert(0, start)\n                possiblepaths.insert(0, 'Random (' + str(averagelength + 1) + '):')\n            return averagelength + 1, (possiblepaths)\n        else:\n            return 0, None\n    else:\n        # calculate min\n        sl, sp = MAX, None\n        for dest in graph[start]:\n            if dest != SPECIAL:\n                l, p = RandomShortestPath(graph, dest, end)\n                if p != None and l < sl:\n                    sl = l\n                    sp = p\n        if sp != None:\n            sp.insert(0, start)\n        if sp == [] or sp == None:\n            return 0, None\n        else:\n            return sl + 1, sp\n \ndef Pretty(list):\n    mazegraph = list[0]\n    editor.AddText(\"\\n{\\n\")\n    for key in mazegraph:\n        editor.AddText(\"    \" + str(key) + \": \" + str(mazegraph[key]) + \"\\n\")\n    editor.AddText(\"}\\n\")\n    solutions = list[1]\n    editor.AddText(\"{\\n\")\n    for entrance in solutions:\n        editor.AddText(\"    Entrance \" + str(entrance) + \": Length \" \n\t\t+ str(solutions[entrance][0]) + \"; \" \n\t\t+ str(solutions[entrance][1]) + \"\\n\")\n    editor.AddText(\"}\\n\")\n\\end{verbatim} \n\nHere is an example run:\n\n\\begin{verbatim} \n>> Pretty(SolveDirectedRandomMaze(Randomize(CreateRandMaze(20, 7), 5)))\n\n{\n    0: []\n    1: [8, 2, 11, 5, 7]\n    2: [6, 12, 19]\n    3: [9, 18, 13, 10, -1]\n    4: [19, 18, 15, -1]\n    5: [12]\n    6: [8, 10]\n    7: [15, 12, 14, -1]\n    8: [12, 14, 15, -1]\n    9: [16, 15]\n    10: [13, 14, 15]\n    11: []\n    12: [16, 13, 17]\n    13: [16, 19]\n    14: [15]\n    15: []\n    16: [19]\n    17: [19, 18, -1]\n    18: [19]\n    19: []\n}\n{\n    Entrance 1: Length 2; [1, 2, 19]\n    Entrance 3: Length 2.5; ['Random (1.5):', 3, [9, 16, 19], [18, 19], [13, 19], [10, 13, 19]]\n    Entrance 4: Length 14.6666666667; ['Random (13.6666666667):', 4, [19], [18, 19], None]\n}\n\\end{verbatim} \nIf we take entrance 1, the shortest path is nonspecial - just:\n\n\\begin{verbatim}\n1 -> 2 -> 19.\n\\end{verbatim}\n\nIf we take entrance 3, it is a little harder; there are four path choices right from the first node:\n\\begin{verbatim}\n\n    3 -> 9 -> 16 -> 19\n    3 -> 18 -> 19\n    3 -> 13 -> 19\n    3 -> 10 -> 13 -> 19\n\\end{verbatim} \n\nThe lengths of these four choices (in hops) are 3, 2, 2, and 3, with an average length of \n2.5.\n\nIf we take entrance 4, things are a little more complicated because we might get sent to \nto the dead end of node 15; possible paths are:\n\\begin{verbatim}\n    4 -> 19\n    4 -> 18 -> 19\n    4 -> 15 -> dead end\n\\end{verbatim}\nOur lengths are 1, 2, and MAX (which we have arbitrarily set to be two times the total maze \nsize which here equals 40). $(1 + 2 + 40) / 3 = 14.3333333333$\n\nWe could adjust our sensitivity to possible dead ends by making MAX bigger or smaller.\n\\end{comment}\n\n\n\\begin{comment}\n\\ans{connecting-cities}\nThe minimum spanning tree (MST) problem is as follows: given a \nconnected undirected graph on vertices $V$  and edges $E$ with \neach edge having a weight, compute a minimum-weight subset of edges $E'$ such that $(V,E')$ \nis connected.  There are $O(|V| + |E|)$ algorithms for solving the MST problem.\n\nThe problem of connecting cities can be mapped into an MST problem\nas follows:  we draw horizontal and vertical lines through\neach city and identify the intersection points; add these as new \nvertices. The edge set consists of line segments corresponding to \nintersections. We now look for the MST in this graph.\n\nClaim: The MST yields an optimum set of roads.\n\nnontrivial argument of correctness? (is it correct?)\n% Hai's notes:  http://www.google.com/url?sa=t&source=web&ct=res&cd=9&ved=0CD4QFjAI&url=http%3A%2F%2Fwww.eecs.northwestern.edu%2F~haizhou%2F357%2Flec5.pdf&\\end{itemize}=AEmZS_LsGouVtgfmnOm2CQ&usg=AFQjCNHiSWJf2Fg_k66oCLXeRZHJaKZRhA&sig2=eCLA9CV0ydwGEz6fS1WwPg\n\\end{comment}\n\n\n\\ans{tsp-choice}\nConsider a directed graph $G=(V,E)$, where the vertices correspond to the cities.\nEach pair of cities is connected by an edge.\n\nEvery plan corresponds to a cycle in the graph and vice versa.  So, we \nneed to find a cycle which maximizes the ratio of profit for\nall jobs on the cycle to the cost of performing the jobs on the cycle.\n\nLet $\\rho_{\\mbox{\\scriptsize max}}$ be the maximum ratio \nachievable. We can find $\\rho_{\\mbox{\\scriptsize max}}$ by guessing\na ratio $\\rho$ and seeing whether it is too large or too small.\n\nLet $\\rho$ be any positive real number.  Give each edge $e = (i,j)$ a\nweight of $\\rho \\cdot c(e) - p(j)$,\nwhere $c(e)$ is the cost of taking edge $e$ and $p(j)$ is the profit\nof visiting node $j$.\n\nIf the graph has a negative cycle with this weight function, we claim that \n$\\rho < \\rho_{\\mbox{\\scriptsize max}}$. \n\nLet $C$ be such a cycle.  Then we know that $\\rho c(C) - p(C) < 0$, where we\nhave extended $c$ and $p$ to sequences of edges in the natural way.\nTherefore for cycle $C$, we have $p(C)/c(C) > \\rho$, i.e., $\\rho < \\rho_{\\mbox{\\scriptsize max}}$.\n\nConversely, if all the cycles in the graph have a positive weight, it must be\nthat $\\rho > \\rho_{\\mbox{\\scriptsize max}}$. Since if $\\rho_{\\mbox{\\scriptsize max}} \\leq \\rho$, let $C$ be a cycle\nwhose profit-to-cost ratio is $\\rho_{\\mbox{\\scriptsize max}}$. Then $p(C)/c(C) = \\rho_{\\mbox{\\scriptsize max}} \\leq \\rho$\nwhich implies $p(C) -\\rho c(C) \\leq 0$, contradicting the absence of \nnonpositive weight cycles.\n\nThere is a straightforward algorithm for computing the presence of \nnegative weight cycles which runs in $O(|V|\\cdot |E|)$ time. We can perform\nbinary search to find $\\rho_{\\mbox{\\scriptsize max}}$ with $0$ as a lower bound and $\\max_{e\\in E} p(e)/c(e)$.\nThe search can be terminated when we have determined $\\rho_{\\mbox{\\scriptsize max}}$ to a specified\ntolerance of $\\epsilon$.\n\nClearly, it is not advantageous to make any move unless the profit-to-cost\nratio is greater than one. We can bound the maximum possible profit-to-cost ratio by finding the edge that maximizes the ratio of profit of\nvisiting its destination  to the\ncost of traversing the edge. Suppose this cost is $R$, then we need to perform the search\nbetween $1.0$ and $R$ for the optimum ratio. In order to narrow down\nthe search to an interval of size $\\epsilon$, we would need $(\\log (R-1)\n- \\log(\\epsilon))/\\log 2$ steps. Since each step involves finding a\nnegative cycle, it can be done in $O(|V|\\cdot|E|)$ time using the \nBellman-Ford algorithm.\n\n\\ans{road-network}\nThe straightforward solution would be to compute the shortest path \nfrom $A$ to $B$ for each proposal.\n\nNote that we cannot add all the proposals at once; otherwise, we may end up with a shortest path which  uses\nmultiple proposals.\n\nInstead we use an all-pairs shortest path algorithm on the original graph\nto get a matrix $S(u,v)$ of shortest path distances for each\npair of vertices.  Each proposal $p$ is a pair of cities\n$x,y$.  The best we can do by using proposal $p$ is $\\min\\big(S(A,B), S(A,x) + A(y,B)\\big)$.\nThis computation is constant time, so we can \nevaluate all the proposals in time proportional to the number of \nproposals after we have computed the shortest path for each pair. \nAll-pairs shortest path can be computed in  $O(|V|\\cdot|E|\\log |V|)$ time\n by multiple calls to Dijkstra's algorithm or in $O(|V|^3)$ time using the Floyd-Warshall algorithm.\n\n\n\\ans{stable-assignment}\nThis is a classical problem and is solved using a ``proposal algorithm''.\n\nEach student who does not have an adviser ``proposes'' to the most-preferred \nprofessor to whom he has not yet proposed. \n\nEach professor then considers all the students who have proposed to him and tells the \none he most prefers, ``I accept you\" and \"no\" to the rest. \nThe professor is then provisionally matched to a student. \n\nIn each subsequent round, each student who does not have an adviser proposes to one professor\nto whom he has not yet proposed (regardless of whether the professor has already accepted \na student or not)  \nand the professor once again replies with one ``accept'' and rejects the rest. \n\nThis may mean that professors who have already accepted a student can ``trade-up'' and students who have already been accepted by a professor can be ``jilted''.\n\nThis algorithm has two key properties:\n\\begin{itemize}\n\\itemsep 1pt\n\\item It converges to a state where everyone is paired. Everyone gets accepted at some point. Once a professor accepts a student, he always has a student.  There cannot be a professor and a student both unpaired since the student must have proposed to that professor at some point (since a student will eventually propose to everyone, if necessary) and being unpaired, the professor would have accepted.\n\\item The pairings are stable. Let Riemann be a student and Gauss be a professor. Suppose they are each paired but not to each other. \nUpon completion of the algorithm, it is not possible for both Riemann and Gauss \nto prefer each other over their current pairings. If Riemann prefers Gauss to his current professor, he must have asked Gauss before he asked his current professor. If Gauss accepted Riemann's proposal, yet is not paired to Riemann at the end, he must have dumped him for someone he preferred more and therefore does not like Riemann more than his current student. If Gauss rejected his proposal, he was already paired with someone he preferred to Riemann.\n\\end{itemize}\n\n\n\\ans{arbitrage}\nWe define a weighted directed graph $G = (V,V \\times V)$, where $V$ corresponds to \nthe set of commodities. The weight $w(e)$ of edge $ e = (u,v)$ is  the amount\nof commodity $v$ we can buy with one unit of commodity $u$.\n\nObserve that an arbitrage exists iff there is a cycle in $G$ \nwhose edge weights multiply out to more than 1. \n\nCreate a new graph $G' = (V,E)$ with weight function $w'(e) = -\\log w(e)$. \nSince $\\log ab = \\log a + \\log b$, there is a cycle in $G$ whose edge weights\nmultiply out to more than 1 iff there is a cycle in $G'$ whose edge weights\nsum up to less than $\\log 1 = 0$.  \n\nWe know how to efficiently find negative weight cycles in weighted directed graphs,\ne.g., using the Bellman-Ford algorithm which takes $O(|V| \\cdot |E|)$\ntime and\ncan use this to compute the existence of an arbitrage.\n\n\n\n\\ans{bvn}\nFirst, note that the number of packets at input $i$ is the sum\nof the elements in row $i$ and the number of packets destined\nthrough output $j$ is the sum of all the elements in column $j$.\n\nLet the maximum row sum be $R$---then it will take at least $R$ cycles\nto transfer the packets from an input corresponding to $R$.\nSimilarly, if $C$ is the maximum column sum, it will take \nat least $C$ cycles to transfer the packets to an output corresponding to $C$,\ni.e., $\\beta = \\max(R,C)$ is a lower bound on the number of cycles.\n\nWe claim $\\beta$ is actually a tight bound. To do this, we first prove that\nwe can create a matrix $A^\\ast \\geq A$ such that every row and column of\n$A^\\ast$ sums up to $\\beta$.\n\nThe proof is by construction---starting with $A$, find a row and a column \nwhose sums are less than $\\beta$ and increment that element by $1$.\nEach successive matrix is larger than its predecessor and the process\nmust converge to a matrix whose rows and columns all sum up to $\\beta$.\n\nNow, consider a bipartite hypergraph on vertices $\\{(L,0),\\ldots,(L,n-1),\n(R,0),\\ldots,(R,n-1)\\}$, where we have $A^\\ast[i,j]$ edges \nbetween vertex $(L,i)$ and $(R,j)$. Since the row\nand column sums are all $\\beta$, it follows that the degrees of all vertices\nis $\\beta$.\n\nThis graph has a perfect matching---this follows from the theorem\nthat a $\\beta$-regular bipartite graph has a perfect matching which in\nturn follows from Birkhoff's characterization of bipartite graphs, namely a perfect matching exists iff \nevery subset of size $k$ has at least $k$ neighbors.\n\nA perfect matching is a permutation from inputs to outputs---by choosing these\nassignments and performing the corresponding transfer, we can \nreduce the number of packets to transfer from $A^\\ast$ by $n$ and the\nresulting matrix has rows and columns summing to exactly $\\beta-1$.  In\nthis way, we can construct a schedule which transfers all the packets in $A\\ast$\nin $\\beta$ cycles.   Since $A^\\ast \\geq A$, this schedule will\nalso transfer all the packets in $A$ in $\\beta$ cycles.\n\n\n\\ans{shannon-capacity}\nIf the transmitter and receiver decide on a restricted\nset of pairs of symbols rather than just symbols, they can do better than \n$1$ bit per symbol transmitted.\n\nThe insight is that a pair like $(A,C)$ and $(B,E)$ cannot be mistaken\nfor each other since $C$ and $E$ cannot conflict.\n\nA formal way of finding the largest set of pairs of symbols\nwhich cannot be mistaken for each other is to create\na conflict graph on the 25 pairs $\\{(A,A),\\ldots,(E,E)\\}$---put\nan edge between $(u_1,u_2)$ and $(v_1,v_2)$ iff \n$(u_1,v_1) \\in \\mathbf{\\Pi}$ and $(u_2,v_2) \\in  \\mathbf{\\Pi}$.\n\nNow, we want to find a maximum independent set in this graph---i.e.,\nthe largest subset of vertices, not two of which are connected by an edge.\n\nThere are a number of such sets of cardinality $5$---e.g.,  \n\\[\nS = \\{(A,A),(B,C),(C,E),(D,B),(E,D)\\} .\n\\]\nTherefore\nwe can send $\\log_2 5$ bits with every two symbols which \namounts to roughly 1.16 bits per symbol transmitted.\n\n\\ans{team-photo-2}\nIn Solution~\\ref{team-photo-1}, we showed how to model the\nproblem using a DAG, with each vertex corresponding to a player.\nProblem~\\ref{team-photo-2} is asking for \na minimum cardinality set of vertex disjoint paths in this DAG such\nthat each vertex appears on some path.\n\nThis problem can be reduced to a flow problem: let $G = (V,E)$ be a DAG.\nConstruct a flow problem $F$ as follows: define\n$G = (V',E')$ from $G = (V,E)$ by creating\na left vertex $v_l$ and a right vertex $v_r$ for each vertex $v \\in V$.\n\nAdd a new source vertex $s$, add edges from\n$s$ to each left vertex, and add a sink vertex $t$ with edges from each right\nvertex to $t$. \n\nAdd edges $(v_l,v_r)$ for each $v\\in V$.\nFor each edge $(u,v)\\in E$, add an edge $(v_r, u_l)$.\n\nAssign a lower bound and upper bound of $1$ for each edge of the form $(v_l, v_r)$;\nall other edges have  a lower bound of $0$ and upper bound of $\\infty$. \n\nBy construction, the minimum feasible flow for $F$ defines\na minimum cardinality set of vertex disjoint paths.\n\n\\ans{dancing-with-the-stars}\nThe problem can directly be mapped into the weighted bipartite\nmatching problem: bidders and celebrities constitute the left and right\nvertices; an edge exists from $b$ to $c$ iff $b$ has offered money to dance with\n$c$ and the weight of an edge is the amount offered for the dance.\nIt can be solved using specialized algorithms, network flows, or linear programming.\n\nIf the requirement that bidders and celebrities be distinct is dropped, \nthe problem becomes a weighted matching problem in a general graph which is still\nsolvable in polynomial time.\n\n\n\\ans{2-cnf}\nLet $\\phi$ be a CNF expression of $n$ variables $x_0,\\ldots,x_{n-1}$ and\n$m$ clauses in which each clause contains no more than two variables.\n\nAssume without loss of generality that each clause in $\\phi$ contains\nexactly two distinct variables since singleton clauses\nforce the value of the corresponding variable for a satisfying assignment.\n\nConstruct the directed graph $G_\\phi$ on $2n$ vertices indexed by $x_0,\\ldots,x_{n-1},{x_0}',\\ldots,{x_{n-1}}'$.\nFor each clause $l_i + l_j$, add an edge from ${l_i}'$ to ${l_j}$ and\n${l_j}'$ to ${l_i}$, where ${{x_i}'}'$ is interpreted as $x_i$.\n\n{\\em Claim}: $\\phi$ is satisfiable iff for each $i$, there does not exist a path from\n$v_{x_i}$ to $v_{x_i}'$ and a path  from $v_{x_i}'$ to $v_{x_i}$.\n\n{\\em Proof}: If an edge exists from $v_{x_i}$ to $v_{x_j}$, it means that whenever $x_i$ is true,\nthen $x_j$ must be true in a satisfying assignment for $\\phi$. Similar results\nhold for vertices corresponding to complemented\nvariables. By the transitivity of\nlogical implication, a path in $G_\\phi$ from $v_{l_i}$ to $v_{l_j}$ implies that\nif $l_i$ is true in a satisfying assignment for $\\phi$, then so must $l_j$.\n\nNow, consider the SCCs of $G_\\phi$.  If for some $i$, $v_{x_i}$ and $v_{x_i}'$ are both\nin the same SCC, there cannot exist a satisfying assignment for $\\phi$.\nConversely, if for no $i$, $v_{x_i}$ and $v_{x_i}'$ are both\nin the same SCC, we will prove that a satisfying\nassignment for $\\phi$ exists by constructing it as follows:\nobserve that if some $v_{x_i}$ or $v_{x_i}'$ is set to true\nin an SCC, then all the corresponding variables in that SCC are set to\ntrue, as are all variables in the descendants of the SCC.\n\nStart with any source SCC in the SCC DAG which contains\n$v_{l_i}$ and does not have a path to $v_{{l_i}'}$ (such a vertex must exist; otherwise, $v_{l_i}$ and $v_{{l_i}'}$ would\nbe in the same SCC).\nSet $l_i$ to true and update all implied assignments, including setting ${l_i}'$ to false. \nIteratively perform this computation until all the literals have been assigned.  We can always\npick a literal to assign before the assignment is complete since no $v_{l_i}$ and $v_{{l_i}'}$\nare in the same SCC and we are only reducing the SCC DAG.\n\nEach clause will be satisfied after this is completed since each clause is of the form $l_i + l_j$.\nAssume WLOG that we assign $l_i$ first.  If it is assigned to true, the clause is satisfied; otherwise, when $l_i$ is assigned to false, we will set ${l_j}$ to true.\n\n\n\\ans{toe}\nLet $\\phi$ be a set of equality and inequality constraints on variables\n$x_0,\\ldots,x_{n-1}$.  Create an undirected graph $G_\\phi$ on vertices $x_0,\\ldots,x_{n-1}$;\nfor each equality $x_i = x_j$, add the edge $(x_i,x_j)$.\n\nNow examine the connected components of $G_\\phi$.\nBy the transitivity of equality, we can infer that $x_i = x_j$ for all\nvertices $x_i$ and $x_j$ in a common SCC.\n\nTherefore if for some inequality $x_p \\neq x_q$, vertices\n$x_p$ and $x_q$ lie in the same SCC, the set of constraints $\\phi$ is not satisfied.\n\nConversely, let there be $k$ connected components $C_0,\\ldots,C_{k-1}$.  Assign\nthe variables in $C_i$ to the value $i$. This satisfies all the equality constraints and since all the inequality constraints involve variables\nfrom different SCCs, all inequality constraints are satisfied too.\n\n\n\\chapter{ Algorithms on Strings}\n\n\\ans{string-search}\nThere are several interesting algorithms for substring search that run\nin linear-time  such as Knuth-Morris-Pratt, Boyer-Moore, and\nRabin-Karp algorithm.  However in practice, for most applications, substring\nsearch runs faster than that. We have found Boyer-Moore algorithm to\nbe the fastest in our experience. \n\nThe Boyer-Moore algorithm works by trying to match characters of $S$\nin $T$ at a certain offset in the reverse order (last character of\n$S$ matched first). If we can match all the characters in $S$, then we\nhave found a match; otherwise, we stop at the first mismatch.  The key idea behind the Boyer-Moore algorithm is to be able to skip as\nmany offsets as possible when we are done matching characters at a\ngiven offset. We do this by building two tables---good suffix shift table and a bad character shift table.\n\nFor a given character, the bad character shift table gives us the distance of the last\noccurrence of that character in $S$ to the rightmost\nstring.  If the character does not occur in $S$, then the entry in the\ntable is of length  $S$.  Hence when we find a character in $T$ that\ndoes not match for the current offset, we know how much we must move\nforward so that this character can match for the first time.\n\nThe good suffix shift table is a little more complex. Conceptually, for a given\nsuffix $X$ of $S$, it tells us what is the shortest suffix $Y$ of $S$\nthat is longer than $X$ and has $X$ as suffix. In practice, what we\nstore is how far can we move safely, given that we have matched up to $length(X)$ characters but\ndid not match the next character. \n\n\n\n\n\n\\ans{unique-char-string-search}\nThe most na\\\"{i}ve way of finding whether a string $S$ is a substring of\nanother string $T$  would be to test character by character at every\noffset in $T$, if we find a match for $A$. However this would take\n$O(m \\cdot n)$ time, where $m$ is the length of $A$ and $n$ is the length of $T$.\nWe can do better than that. If at a certain offset we match a\nset  of characters in $A$ to that of $T$ but they do not match all\nthe characters in $A$  since $A$ has all unique characters,  the\ncharacters in $T$ that matched $A$ will not match $A$ at any other\noffset. Hence we can skip a few offsets. \nThis essentially means that for every character in $T$, we\ncompare it with a character in $A$ at most once.  This will lead to a\nlinear-time matching algorithm that runs in $O(n +m)$ time.\n\n\\ans{rotate-string}\nThis is a special case of applying a permutation with constant\nadditional storage (cf.~Problem~\\ref{perm}) except that the permutation is a rotation. In the \ncase of rotations, we get cycles of the form $(c,i+c,2i+c,\\ldots, (m \\cdot i\n + c)\\bmod n)$ for different values of $c$ from $1$ through  a number of cycles. So, essentially all other\ncycles are a shifted version of the first cycle. For example, consider\nthe case where $n = 6$ and $i = 2$, we get $(1,3,5)$ and $(2,4,6)$.\nOnce we have identified the difference between the lowest and the second lowest element in any cycle, we know the number of cycles there are\nand their starting points.\n\n\\ans{test-rotation}\nThe key idea here is that if string $A$ is a rotation of another\nstring $B$, then $A$ must be a substring of $B \\cdot B$. For example, since\n$arc$ is a rotation of $car$, it is a substring of $carcar$. Since\nsubstring test can be done in linear-time using the Knuth-Morris-Pratt\nalgorithm, we can test for rotation in linear-time.\n\n\\ans{normalize}\nWe are not providing explicit solution to this problem here since\nthere are no algorithmic ideas involved. Most times when this\nkind of a\nquestion is asked, you need to keep a few things in mind:\n\\begin{itemize}\n\\item A single pass over the string is likely going to be faster.\n\\item You can build prefix tables to match \\texttt{index.html} and \\texttt{default.html}\n  in advance to speed up the process.\n\\item You may not know if you need to add the protocol part or not\n  until you have reached the end of the host part. Hence it may be a good idea to leave some \n  space for adding \\texttt{http://} at the beginning of the buffer.\n\\end{itemize}\n\n\\ans{longest-palindrome}\nThis problem can be reduced to finding the longest common subsequence\nbetween the input string and its reverse. We have already shown how\nthis can be done efficiently in Problem~\\ref{longest-nondecreasing}.\n\n\\ans{pretty-printing}\nThis can be efficiently solved by dynamic programming. Let $C(a)$ be\nthe minimum wasted space for arranging the last $a$ words.  If we have\nall the values for $C(i)$ tabulated for $i < a$, we can compute $C(a)$ \nby finding the number of words we can fit in the first line that\nminimizes $C(a)$.   \n\n\\ans{min-edit-distance}\nThis is another interesting application of dynamic programming.\n\nLet $S(i,j)$ represent the substring of string $S$ that contains all\nthe characters of $S$ from index $i$ to $j-1$ (inclusive).  Let the edit\ndistance between the two strings $A$ and $B$ be represented by\n$E(A,B)$. Let's say that $a$ and $b$ are, respectively,\nthe length of strings $A$ and $B$. We now make two claims:\n\\begin{itemize}\n\\itemsep 1pt\n\\item If $A[a-1]  = B[b-1]$ (i.e., the last two characters of the\n  strings match), then $E(A,B) = E(A(0,a-1), B(0,b-1))$. This is\n  obviously true since any set of transformation that turns $A$ into\n  $B$  can turn $A(0,a-1)$ into $B(0,b-1)$ and vice versa.\n\\item If $A[a-1]  \\not= B[b-1]$ (i.e., the last two characters of the\n  strings do not match), then \n\\ifthenelse{\\boolean{createspace}}{\n\\[ E(A,B) = \\min\\Big(E\\big(A(0,a-1), B\\big), E\\big(A,\n  B(0,b-1)\\big)\\Big) + 1 .\\]\n}{\n  \\begin{eqnarray*}\n  \\lefteqn{E(A,B) =} \\\\\n  & & \\min\\Big(E\\big(A(0,a-1), B\\big), \\\\\n  & &  \\; \\; E\\big(A, B(0,b-1)\\big)\\Big) + 1 .\n  \\end{eqnarray*}\n}\n  We can see this to be true by observing that if\n  there is a smaller sequence of events that leads to the transformation of\n  $A$ into $B$, there must be a step where the last character of the\n  string becomes the same as the last character of $B$.  This\n  could happen either by inserting a new character at the end or\n  deleting the last character. We can reorder the sequence such that\n  this operation happens at the end. The length of the sequence would remain the same and we would still end up with $B$ in the end. In case this operation was ``delete'',\n  then by deleting this operation, we get a sequence of operations\n  that turn $A(0,a-1)$ into $B$. If this operation was an ``insert'', then\n  by dropping this operation, we would have a set of transformations\n  that turn $A$ into $B(0,b-1)$.  In either case, it would be a\n  contradiction if there was a sequence of operations that turned $A$\n  into $B$ which is smaller than $\\min\\Big(E\\big(A(0,a-1), B\\big), E\\big(A,\n  B(0,b-1)\\big)\\Big) + 1$.\n\\end{itemize}\n\nWe can use the above results to tabulate the values of $E\\big(A(0,k),\nB(0,l)\\big)$ for all values of $k < a$ and $l < b$ in $O(a\\cdot b)$ time till\nwe get the value of $E(A,B)$.\n\n\\ans{grep}\nThe key to solving this problem is using recursion effectively.\n\nIf the regular expression \\texttt{r} starts with \\texttt{\\^}, \nthen \\texttt{s} must  match the remainder of \\texttt{r};\notherwise, \\texttt{s} must match \\texttt{r} at some position.\n\nCall the function that  checks whether a string \\texttt{S} matches\n\\texttt{r} from the beginning \\texttt{matchHere}.\nThis function has to check several cases---(1.)~length-0\nregular expressions which match everything, (2.)~a regular\nexpression starting with a \\texttt{*} match, (3.)~the regular expression\n\\texttt{\\$}, and (4.)~a regular\nexpression starting with an alphanumeric character or dot.\n\nOf these, (1.)~and (3.)~are base cases, (4.)~is a check followed\nby a call to \\texttt{matchHere}, and (3.)~requires\na new \\texttt{matchStar} function.\n \nThe \\texttt{matchStar} function does a walk down the string,\nchecking that the prefix thus far matches the alphanumeric character or dot until some suffix matches the remainder of the regular expression.\n\n\\lstinputlisting[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Java]{RegExp.java}\n\n\n\n\n\n\n\\chapter{ Intractability}\n\n\\ans{01knapsack}\nThe 0-1 knapsack problem is an NP-complete problem. However\nthe dynamic programming solution to the problem runs in\npseudopolynomial time (to be precise, its time complexity is $O(n\\cdot W)$).\n\nLet $A(w)$ be the maximum value that can be packed with weight less than or equal to $w$.\nWe can use the recurrence \n\\[ A(w) = \\max\\big(A(w-1), \\max_i(A(w-w_i) + v_i)\\big) .\\]\nFor $w \\leq 0$, we set $A[w] =0$.\nComputing $A[w]$ given $A[i]$, for all $i < w$, takes $O(n)$ time; therefore this DP procedure computes $A[W]$ in $O(n\\cdot W)$ time.\n\n\\ans{tsp}\nA good way to approach this problem is to think of a related problem\nthat can be solved exactly efficiently. The minimum spanning tree (MST) problem\nhas an efficient algorithm and it yields a way of visiting each city exactly \ntwice---start at any city $c$ and perform an in-order walk\nin the MST with $c$ as the root.  This traversal leads to a path in \nwhich each edge is visited exactly twice.\n\nNow consider any tour for a salesman---if we drop the final edge back \nto the starting city, the remaining set of edges constitute a tree.\nTherefore the cost of any traveling salesman problem is at least as great as the cost of the MST.\n\nNow we make use of the fact that the distances between cities satisfies\nthe triangle inequality to build a tour from the MST whose\ncost is no greater than the MST. When we perform our in-order walk, \nwe simply skip over cities we have already visited---the direct distance from\n$u$ to $v$ cannot be more than the sum of distances on a path from $u$ to $v$.\n\nHence we have a tour costing at most twice the cost of the MST which itself\nwas an upper bound on the cost of the traveling salesman problem.\n\n\\ans{facility-location}\nA natural approach to this problem is to build the assignment \none warehouse at a time. We can pick the first warehouse to be the city\nfor which the cost is minimized---this takes $\\Theta(n^2)$ time since we\ntry each city one at a time and check its distance to every other city.\n\nLet's say we have selected the first $i-1$ warehouses $\\{c_1,c_2,\\ldots,c_{i-1}\\}$\nand are trying to\nchoose the $i$-th warehouse. A reasonable choice for $c_i$\nis the one that is the farthest from the $i-1$ warehouses already chosen.\nThis can also be computed in $O(n^2$) time. \n\nLet the maximum distance from any remaining cities to a warehouse be $d_{m}$.\nThen the cost of this assignment is $d_{m}$. Let $e$ be\na city that has this distance to the warehouses.\nIn addition, the $m$ warehouse cities are all at least $d_{m}$ apart; otherwise, we would have chosen $e$ and not $c_m$ at the $m$-th selection.\n\nAt least two of these $m+1$ cities have \nto have the same closest warehouse in an optimum assignment.\nLet $p,q$ be two such cities and $w$ be the warehouse they are\nclosest to. Since $d(p,q) \\leq d(w,p) + d(w,q)$, it follows\nthat one of $d(w,p)$ or $d(w,q)$ is not less than $d_m/2$.\nHence the cost of this optimum assignment is at least $d_m/2$, so\nour greedy heuristic produced an assignment that is within a factor of \ntwo of the optimum cost assignment.\n% We selected $c_{m-1}$ to be the point that was farthest from the first $m-1$\n% warehouses.\n\nNote that the initial selection of a warehouse is immaterial for the \nargument to work but heuristically, it is better to choose \na central city as a starting point.\n\n\\ans{computing-exponents}\nIt is natural to try and solve this problem by divide-and-conquer, e.g., \ndetermine the minimum number of multiplications for each of $x^{k}$ and $x^{30/k}$,\nfor different values of $k$.  The problem is that the subproblems are not\nindependent---we cannot just add the minimum number of multiplications for computing\n$x^{5}$ and $x^{6}$ since both may use $x^{3}$.\n\nInstead we resort to branch-and-bound: we maintain a set of partial solutions\nwhich we try to extend to the final solution. The key to efficiency is\npruning out partial solutions efficiently.\n\nIn our context, a partial solution is a list of exponents that we have\nalready computed. Note that in a minimum solution, we will never have\nan element repeated in the list. In addition, it suffices to consider\npartial solutions in which the exponents occur in increasing order\nsince if $k > j$ and $x^k$ occurs before $x^j$ in the chain, then\n$x^k$ could not be used in the derivation of $x^j$. Hence we lose nothing by advancing the\nposition of $x^k$. \n\nHere is code that solves the problem:\n\n\\lstinputlisting[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Java]{MinExp.java}\n\nThe code runs in a fraction of a second.\nIt reports  $\\langle x^{1}, x^{2}, x^{3}, x^{5}, x^{10}, x^{15}, x^{30}\\rangle$.\nIn all, 7387 partial solutions are examined.\n\nThere are other potential bounding techniques: for example, from the binary\nrepresentation of 30 ($11110$), we know that $7$ multiplications suffice (computing\n$x^2, x^4,x^8,x^{16}$ and then multiplying these together).  \nIn addition, we could keep out duplicate partial solutions.\nThe code could avoid considering all pairs $i,j$ and focus on pairs that just involve\nthe last element since other pairs will have been considered previously.\nMore sophisticated bounding can be applied:\na chain like $\\langle x, x^2, x^3,x^6,x^7\\rangle$ will require at least three\nmore multiplications (since $\\lceil \\frac{30}{7}\\rceil = 3$) and so this chain\ncan be safely pruned. \nWhen selecting a partial solution to continue searching from, we could\nchoose one that is promising, e.g., the shortest solution---this might lead to\nbetter solutions faster and therefore more bounding on other search paths.\n\nFor hand calculations, these techniques are important but\nthey are trickier to code and our original code solves the\ngiven problem reasonably quickly.\n\n\n\\ans{cnf-sat}\nA reasonable way to proceed is to use branch-and-bound: we choose a variable\n$v$, see if there is a satisfying assignment when $v=0$ and if not,\nwe try $v=1$. If there is no satisfying assignment for $v=0$ and\nfor $v=1$, the expression in not satisfiable.\n\nOnce we choose a variable and set its value, the expression simplifies---we\nneed to remove clauses where $v$ appears\nif we set $v=1$ and remove clauses where $v'$ appears when we set $v=0$.\nIn addition, if we get to a unit clause---one where a single literal appears,\nwe know that in any satisfying assignment for \nthe current expression, that literal must be set to true; this rule\nleads to additional simplification.  Conversely, if all the clauses are true,\nwe do not need to proceed further---every assignment to the remaining variables\nmakes the expression true.\n\nThere are various choices for selecting variables. One natural choice\nis to pick the variable which appears the most times in clauses with\ntwo literals since it leads to the most unit clauses on simplification.\nAnother choice is to pick the variable which is the most binate---i.e., it appears\nthe most times in negated and nonnegated forms.\n\n\n\n\\ans{scheduling-classes}\nWe are given a set of $N$ unit duration lectures and $M$ classrooms. The lectures can be held simultaneously as long as no two lectures need to happen in the same classroom at the same time and all the \nprecedence constraints are met. \n\nThe problem of scheduling \nthese lectures  so as to minimize the time taken to completion is known\nto be NP-complete.\n\nThis problem is naturally modeled using graphs.  We model\nlectures as vertices, with an edge from vertex $u$ to vertex $v$ if\n$u$ is a prerequisite for $v$.  Clearly, the graph must be acyclic for\nthe precedence constraints to be satisfied.\n\nIf there is just one lecture room, we can simply hold the lectures\nin topological order and complete the $N$ lectures in $N$ time (assuming\neach lecture is of unit duration).\n\nWe can develop heuristics by observing the following: at any time, there\nis a set of lectures whose precedence constraints have been satisfied.\nIf this set is smaller than $M$, we can schedule all of them;\notherwise, we need to select a subset to schedule.\n\nThe subset selection can be based on several metrics:\n\\begin{itemize}\n\\itemsep 1pt\n\\item Rank order lectures based on the length of the longest \ndependency chain that they are at the start of.\n\\item Rank order lectures based on the number of lectures\nthat they are immediate prerequisites for.\n\\item Rank order lectures based on the total number of lectures\nthat they are direct or indirect prerequisites for.\n\\end{itemize} \nWe can also use combinations of these criteria to order the lectures\nthat are currently schedulable.\n\nFor example, for each vertex, we define its criticality to be the length of a longest path\nfrom it to a sink.  We schedule lectures by processing vertices\nin topological order.  At any point in our algorithm, we have a set of candidate\nlectures---these are the lectures whose prerequisites have already been scheduled.\n\nIf the candidate set is less than size $M$, we schedule all the lectures; otherwise, we choose the $M$ most critical lectures and schedule those---the\nidea is that they should be scheduled sooner since they are at the start of\nlonger dependency chains.\n\nThe criterion is heuristic and may not lead \nto optimum schedules---this is to be expected since the problem is NP-complete.\nOther heuristics may be employed, e.g., we may use the number of lectures that depend\non lecture $L$ as the criticality of lecture $L$ or some combination of the criterion.\n\n\\ans{Hardy-Ramanujan}\nThis problem is very similar to another very popular problem that \nis asked in interviews. You \nare given an $n \\times n$ matrix in which both rows and columns are sorted in ascending order and you are supposed to find a given\nnumber in the matrix. \n\nIn this case, we are essentially looking for an\nimplicit matrix $A$ such that $A(i,j) = i^3 + j^3$.  In our case, the\nmatrix will have $n^{1/3}$ rows and columns. There are several\nalgorithms for searching  for a number in such a matrix that are linear\nin the number of rows. \n\nOne approach is to start by comparing $x$ to $A_{n,1}$. If $x = A_{n,1}$,\nstop. Otherwise, there are two cases:\n\\begin{itemize}\n\\itemsep 1pt\n\\item $x > A_{n,1}$, in which case $x$  is greater than all elements in Column~1.\n\\item $x < A_{n,1}$, in which case $x $ is less than all elements in Row~$n$.\n\\end{itemize} \nIn either case, we have a matrix with $n$ fewer elements to search.\nIn each iteration, we remove a row or a column, which means we inspect $2n-1$ elements.\n\n%TODO: hacked for better break\n\\newpage\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nbool IsSumOfcubes(int n) {\n  int m = ceil(pow(n, 1/3));\n  int i = m; int j = 0;\n  while( j < m && i >= 0) {\n    int k = i*i*i +j*j*j;\n    if (k == n) {\n      return true;\n    } else if (k < n) {\n      ++j;\n    } else {\n      --i;\n    }\n  }\n}\n\\end{lstlisting}\n\nFor a tight lower bound, let $x$ be any input. Define $A$ to be:\n\\[\n\\left[\n\\begin{array}{lllll}\n & & & & x-1 \\\\\n & & & & x+1 \\\\\n & & & \\cdots &     \\\\\n & &x-1 & &     \\\\\n & &x+1 & &     \\\\\n &x-1 & & &     \\\\\n &x+1 & & &     \\\\\nx -1 & & & &    \n\\end{array}\n\\right] \n\\] where all entries not shown are 0.\nWe claim that any algorithm that solves the matrix search problem will have to compare\n$x$ with each of the $2n-1$ elements\nshown (i.e., the diagonal elements and the elements immediately below them).\nCall these elements the $\\Delta$ elements.\n\nComparing $x$ with other elements does not eliminate any of the $\\Delta$ elements.\nSuppose an algorithm did not compare $x$ with one of the $\\Delta$ elements.\nThen we could make that element $x$ (instead of $x-1$ or $x+1$) and the algorithm\nwould behave exactly as before and hence return the wrong result. Therefore\nat least $2n-1$ compares are necessary which means that the algorithm we designed is optimum.\n\nNote that for this problem, if the input number is $n$, the size of\nthe input is $\\log n$ bits. Since the runtime is $O(n^{1/3})$, it is\nstill an exponential algorithm in the size of the input.\n\n\\ans{collatz}\nOften interview questions are open-ended\nwith no definite good solution---all you can do is provide some good\nheuristics and code it well. For the Collatz hypothesis,\nthe general idea is to start with each number and iterate\ntill you reach one. Here are some of the ideas that you can try to accelerate\nthe check:\n\\begin{enumerate}\n\\itemsep 1pt\n\n\\item Reuse computation by storing all the numbers you have already\n  proven to converge  to 1; that way, as soon as you reach such a number, you can\n  assume it would reach 1.\n\\item In order to save hash table space, you can keep only odd numbers\n  in the hash table.\n\\item   If you have tested every number up to $k$, you can stop\n  the chain as soon as you reach a number that is less than or equal to\n  $k$. Also, you do not need to store the numbers below $k$ in the\n  hash table, so you can keep deleting these numbers from the hash table as\n  you progress.\n\\item If multiplication and division are expensive, use bit shifting\n  and addition.\n\\item Since the numbers in a sequence may grow beyond 32 bits, you should\n  use 64 bit longs and keep testing for overflow.\n  % (probability of this happening should be fairly low).\n\\end{enumerate}\n\n\\ans{closest-pair-2}\nThe brute-force solution is to consider all pairs of points: this yields\nan $O(n^2)$ algorithm.\n\nA reasonable approach is to split the points into two equal-sized sets using a line $x = P$ parallel to the Y-axis.  Such a line\ncan be found by computing the median of the values for the\n$x$ co-ordinates---this calculation can be performed\nusing randomization in a manner analogous to Quicksort.\n\nWe can then compute the closest pair of points recursively\non the two sets; let the closest pair of points on the left of\n$P$ be $d_l$ apart and the closest pair of points\nto the right of $P$ be $d_r$ apart.  Let $d = \\min(d_l,d_r)$.\n\nNow, all we need to look at is points which are in the band $[P-d, P+d]$.\nIn degenerate situations, all points may be within this band. So, if we\ncompare all the pairs, the complexity becomes quadratic again.\nHowever we can sort the points in the band on their $y$ co-ordinates\nand scan the sorted list, looking for points $d$ or less distance\nfrom the point being processed.  \n\nIntuitively, there cannot be a large \nnumber of such points since otherwise, the closest pair\nin the left and right partitions would have to be less than $d$ apart. This intuition\ncan be analytically justified---Shamos and Hoey's famous\n1975 paper ``Closest-point problems'' shows that no more than 6 points\ncan be within $d$ distance of any point which leads to an $O(n \\log n)$ algorithm---the time \nis dominated by the need to sort.\n\nThe recursion can be sped up by switching to brute-force when\na small number of points remain.\n%---the quadratic\n%complexity of the brute-force approach is offset by the reduced overhead of recursion.\n\n\\ans{prime} Here are a couple of simple heuristics that you can use to\nspeed up primality tests:\n\\begin{enumerate}\n\\item It is sufficient to test for factorization up to $\\lceil \\sqrt n \\, \\rceil$.\n\\item You can limit yourself to prime numbers only. You may not know\n  all the prime numbers between $2$ and $\\sqrt n$, however you can use\n  the fact that all prime numbers other than 2 and 3 are of the\n  form $6k +1$ or $6k -1$. This would speed up your computation by a\n  factor of $3$.\n\\end{enumerate}\n\n \n\\chapter{ Parallel Computing}\n\n\\ans{servlet-with-caching}\nThe na\\\"{i}ve solution would be: \n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Java]\npublic class S1 implements Servlet {\n  String wLast = null;\n  String [] closestToLastWord = null;\n\n  public void service(ServletRequest req, ServletResponse resp) {\n    String w = extractWordToCheckFromRequest(req);\n    if (checkWord.equals(wLast)) {\n      encodeIntoResponse(resp, closestToLastWord);\n    } else {\n      wLast = w;\n      closestToLastWord = closestInDictionary(w);\n    }\n  }\n}\n\\end{lstlisting}\n\nThis solution has a race condition---Thread~A might have \nwritten \\texttt{wLast} and then Thread~B reads \\texttt{wLast} and \\texttt{closestToLastWord} \nbefore Thread~A has a chance to update \\texttt{closestToLastWord}. \nThe call to \\texttt{closestToLastWord} could take quite long or be very fast, depending \non the length of \\texttt{checkWord}.  Hence it is quite possible that\nbetween the two write operations of Thread~A, Thread~B reads both \\texttt{wLast} and \\texttt{closestToLastWord}.\n\nA thread-safe solution would be to declare \\texttt{service} to be synchronized;\nin this case, only one thread could be executing the method\nand there is no race between write to \\texttt{wLast} and \\texttt{closestToLastWord}.\nThis leads to poor performance---only one servlet thread can be executing at a time.\n\nThe solution is to lock just the part of the code that operates\non the cached values---specifically, the check on the cached value \nand the updates to the cached values: \n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Java]\npublic class S2 implements Servlet {\n  String wLast = null;\n  String [] closestToLastWord = null;\n\n  public void service(ServletRequest req, ServletResponse resp) {\n    String w = extractFromRequest(req);\n    String result  = null;\n    synchronized (this) {\n      if (w.equals(wLast)) {\n        result = closestToLastWord.clone();\n      }\n    }\n    if (closestToLastWord == null) {\n      result = closestInDictionary(i);\n      synchronized (this) {\n        closestInDictionary = result;\n        wLast = w;\n      }\n    }\n    encodeIntoResponse(resp, result);\n  }\n}\n\\end{lstlisting}\n\nIn the above code, multiple servlets can be in their call to \\texttt{closestInDictionary}\nwhich is good because the call may take a  long time.\nBecause we lock on \\texttt{this}, the read-assignment on a hit\nand write-write assignment on completion are atomic. Note that\nwe have to \\texttt{clone} \\texttt{closestToLastWord} when assigning\nto \\texttt{result} since otherwise, \\texttt{closestToLastWord} might change before we encode\nit into the response.\n\n\\ans{thread-pools}\nThe first attempt to solve this problem might be to have \\texttt{main}\nlaunch a new thread per request rather than process the request\nitself:\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Java]\nclass ThreadPerTaskWebServer {\n  public static void main(String [] args) throws IOException {\n   final ServerSocket socket = new ServerSocket(80);\n    while ( true ) {\n      final Socket connection = socket.accept();\n      Runnable task = new Runnable() {\n        public void run() {\n          handleRequest(connection);\n        }\n      }\n      new Thread(task).start();\n    }\n  }\n}\n\\end{lstlisting}\n\nThe problem with this approach is that we do not control the\nnumber of threads launched. A thread consumes a nontrivial\namount of resources by itself---there is the overhead of\nstarting and ending down the thread and the resources\nused by the thread. For a lightly-loaded server,\nthis may not be an issue but under load, it can result in \nexceptions that are challenging, if not impossible, to handle.\n\nThe right trade-off is to use a {\\em thread pool}. As the \nname implies, this is a collection of threads, the size of which\nis bounded. Java provides thread pools through the \\texttt{Executor}\nframework. \n\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Java]\nclass TaskExecutionWebServer {\n  private static final int NTHREADS = 100;\n  private static final Executor exec \n      = Executors.newFixedThreadPool(NTHREADS);\n\n  public static void main(String[] args) throws IOException {\n    ServerSocket socket = new ServerSocket(80);\n    while (true) {\n      final Socket connection = socket.accept();\n      Runnable task = new Runnable() {\n        public void run() {\n          handleRequest(connection);\n        }\n      };\n      exec.execute(task);\n    }\n  }\n}\n\\end{lstlisting}\n       \n\\ans{async-replies}\nOur strategy is to launch a thread $T$ per \\texttt{Requestor} object. \nThread $T$ in turn launches another thread, $S$, which calls \n\\texttt{execute} and \\texttt{ProcessResponse}. \nThe call to \\texttt{execute} in $S$\nis wrapped in a try-catch \\texttt{InterruptedException} loop;\nif \\texttt{execute} completes successfully,\n\\texttt{ProcessResponse} is called on the result.\n\nAfter launching $S$, $T$ sleeps for the timeout interval---when\nit wakes up, it interrupts $S$. If $S$ has completed, nothing happens; otherwise, the try-catch \\texttt{InterruptedException} calls \\texttt{error}.\n\nCode for this is given below:\n\\lstinputlisting[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Java]{AsyncThread.java}\n\n\\begin{comment}\nSend requests, register call-backs.  Responses are asynchronous.\nNeed to demultiplex messages---unique identifier.\nCan have fault-tolerance in the form of time-outs, does not appreciably add\nto the overhead.\nNeed a single thread to manage the demuxing.\n\\end{comment}\n\n\\ans{timer}\nThere are two aspects to the design---first, the data-structures and second, the locking mechanism.\n\nOne solution is to use two data-structures.\nThe first is a heap in which we insert key-value pairs: the keys are runtimes and the values are the thread to run at that time.\nA dispatch thread runs these threads; it sleeps from call\nto call and may be woken up if a thread is added to or deleted\nfrom the pool.  If woken up, it advances or retards its remaining\nsleep time based on the top of the heap. \nOn waking up, it looks for the thread at the top of the\nheap---if its launch time is the current time, the dispatch thread\ndeletes it from the heap and executes it. It then sleeps till \nthe launch time for the next thread in the heap. (Because of\ndeletions, it may happen that the dispatch thread wakes up and finds\nnothing to do.)\n\nThe second data-structure is a hash table with thread ids as keys\nand entries in the heap as values. If we need to cancel a thread,\nwe go to the heap and delete it.  Each time a thread is added,\nwe insert it into the heap; if the insertion\nis to the top of the heap, we interrupt the dispatch thread\nso that it can adjust its wake up time.\n\nSince the heap is shared by the update methods and the dispatch thread,\nwe need to lock it. The simplest solution is to have a single lock\nthat is used for all read and writes into the heap and the hash table.\n\n\\begin{comment}\n\\ans{synchronization}\nWe can solve this by using two locks, $L$ and $M$.\nWe use $L$ to guard access to the number $n$ of outstanding tasks;\nwhen a new task is launched it increments $n$ and \nwhen it completes, it decrements $n$ and waits on $M$ before\nexiting.\n\nWhen a thread decrements $n$ to $0$, it calls \\texttt{notifyAll} \non $M$---this wakes up all the threads waiting on $M$\nwho can now exit.\n\n\\end{comment}\n\n\n\\ans{rw-1}\nWe want to be able to indicate whether the string is being read \nas well as whether the string is being written to.  We achieve this\nwith a pair of locks---LR and LW and a read counter locked by LR. \n\nA reader proceeds as follows: it locks LR, increments the counter, and\nreleases LR.  After it performs its reads, it locks LR, decrements the counter, and releases LR.  \nA writer locks LW, then iteratively performs the following: it locks LR, checks to see if the read counter is 0;\nif so, it performs its write, releases LW, and then releases LR.\nIn code:\n\\lstinputlisting[basicstyle=\\footnotesize,numbers=left,breaklines=true]{RW.java}\n\n\\ans{rw-2}\nWe want to give writers the preference.  We achieve this by\nmodifying the solution above to have a reader start by locking LW and\nthen immediately releasing LW.  In this way, a writer who acquires the \nLW lock is guaranteed to be ahead of the subsequent readers.  \n\n\\ans{rw-3}\nWe can achieve fairness between readers and writers by having\na bit which indicates whether a read or a write was the\nlast operation performed.  If the last operation performed was a read,\na reader on acquiring a lock must release the lock and retry---this gives\nwriters priority in acquiring the lock; a similar operation is performed\nby writers.\n\n\\ans{producer-consumer}\nThis problem can be solved for a single producer and a single consumer with\na pair of semaphores---{\\em fillCount} is incremented and {\\em emptyCount} is \ndecremented whenever an item is added to the buffer.  If the producer\nwants to decrement {\\em emptyCount} when its count is 0, the producer\nsleeps.  The next time an item is consumed, {\\em emptyCount} is incremented\nand the producer is woken up.  The consumer operates analogously.\nThe Java methods, \\texttt{wait} and \\texttt{notify}, can\nbe used to implement the desired functionality.\n\nIf there are multiple producers and consumers, the solution above has two\nraces---two producers\ncan try writing to the same slot and two consumers can read from\nthe same slot.  These races can be removed by adding mutexes around the\n{\\em putItemIntoBuffer} and {\\em removeItemFromBuffer} calls.\n\n\\ans{barber}\nA casual implementation is susceptible to races. For example, \na new customer sees the barber cutting hair and goes to the waiting room;\nbefore he gets to the chair, the barber completes the haircut,\nchecks the waiting room, and goes back to his chair to sleep.\nThis is a form of livelock---the barber and the customer are both idle,\nwaiting for each other.\nAs another example, in the absence of appropriate locking,\ntwo customers may arrive simultaneously, see the barber\ncutting hair, and a single vacant seat in the waiting room, and \ngo to the waiting room to occupy the single chair.\n\nOne way to achieve correct operation\nis to have a single mutex which allows only\none person to change state at a time.\nThe barber must acquire the mutex before checking \nfor customers; he must release it when he either begins to \nsleep or begins to cut hair. A customer must acquire \nthe mutex before entering the shop; he must release it when he sits in either \na waiting room chair or the barber chair. \n\nFor a complete solution, in addition to the mutex, we need event semaphores\nto record the number of customers in \nthe waiting room and the number of people getting their hair cut.\nThe event semaphore recording the number of customers in the waiting room\nis used to wake up the barber when a customer enters; the event\nsemaphore recording the number of customers getting a haircut\nis used to wake up waiting customers.\n\n\\ans{dining-philosophers}\nThe natural solution is for each resource to have a lock.\nThe problem arises when each thread $i$ requests lock $i$ and\nthen $i+1 \\bmod{n}$.  Since all locks have already been acquired, \nthe thread deadlocks.\n\nOne approach is to have a central controller, which \nknows exactly which resources are in use and arbitrates conflicting requests.\nIf resources are not available for a thread,\nthe controller can reject his request.\n\nAnother solution is to order the resources and require that resources be\nacquired in increasing order and released in decreasing order.\nFor example, if all threads request simultaneously, resource $n-1$\nwill be left unrequested (since Thread $n-1$ will request\n$0$ first, and then $n-1$).  Thread $n-2$ will then succeed at \nacquiring resource $n-1$ since Thread $n-1$ will block on Resource $0$.\n\n\\begin{comment}\nThe example below shows a solution where the chopsticks are not represented explicitly. \nPhilosophers can eat if none of their neighbors are eating. \nThis is comparable to a system where philosophers that cannot get the second chopstick must put down the first chopstick before they try again.\n\nIn the absence of locks associated with the resources, threads must ensure\nthat the decision to enter $m$ is not based on stale information about the\nstate of its neighbors. If Thread 2 sees that Thread 1 does not\nhold resource 1, then Thread 2 looks at Thread 3, Thread 1 could take resource 1\nwhile Thread 2 looks at Thread 3. This problem can be avoided\nby using a single mutual exclusion lock not associated with the resources but\nwith the decision procedures that can change the states of the philosophers.\nThis is ensured by the monitor. The procedures test, pickup, and putdown are\nlocal to the monitor and share a mutual exclusion lock. Notice that threads\ncalling \\texttt{WAITC(x)} release the lock and wait on the variable \\texttt{x} \nuntil another thread calls \\texttt{SIGNALC(x)} on the same variable. \nWhen the process that called \\texttt{WAITC} resumes, it will have reacquired the lock.\n\\end{comment}\n\nThis solution is not starvation-free, e.g., \nT2 can wait forever while T1 and T3 alternate.\nTo guarantee that no thread starves, one could keep track of the\nnumber of times a thread cannot execute when his neighbors release their locks.\nIf this number exceeds some limit, the state of the thread\ncould change to \\texttt{starving} and the decision procedure to enter the critical\nsection could be supplemented to require that none of the neighbors are starving.  \nA philosopher that cannot pick up locks because a neighbor is starving \nis effectively waiting for the neighbor's neighbor to finish eating. \nThis additional dependency reduces concurrency---raising the threshold for \ntransition to the \\texttt{starving} state reduces this effect.\n\n\n\\chapter{ Design Problems}\n% \\dp{A note about solutions}\nMany of the problems in this chapter can be the basis for PhD-level research.\nA comprehensive discussion on the solutions available for such problems is \noutside the scope of this book.  In an interview setting when someone asks such\na question, you should have a discussion in which\nyou demonstrate an ability to think creatively, understand design\ntradeoffs, and attack unfamiliar problems. The\nanswers in this chapter are presented in this context---they\nare meant to be examples of good responses in an\ninterview and are not definitive state-of-the-art solutions.\n\n\\ans{mosaic} \nAs mentioned in the prologue to this book, one approach\nis to do a coarse pixelization of the tiles and for each\npotential tile position, find the tile in the image that is closest to\nit in terms of a norm defined over each pixel color. If the image\ncollection is limited, you would often end up with significant\nerrors. Since the human eye perceives the average color of a region, it\nhas been observed that if you adjust the average target color of a\ntile based on errors made by its neighboring tiles, it improves the\noverall quality.\n\nOften the target image may have very similar color for a large number\nof tiles in the background. If we pick the same image over and over\nfor a contiguous region, it stands out in the mosaic and does not create\nvery good aesthetics. Hence the mosaic tools would usually allow the\nusers to specify constraints on how often a tile can be repeated or\na minimum separation between the two copies of an image.\n\nGiven a rectangle in the target image, finding the best image that\ncan approximate it essentially boils down to searching for the nearest\nneighbor in some $k$-dimensional space (where $k$ is the number of\ncolor pixels used to approximate the image). Since we can do some preprocessing on the library of images, it makes sense to do some\nspatial indexing.  A very simple indexing scheme for relatively low\nvalue of $k$ would be to just form a $k$-dimensional grid and place\nthe images to the closest point on the grid. A more sophisticated\napproach would be to use $R$-trees for indexing.\n%TODO: senthil suggested mentioned the rectangle packing problem here.\n%Amit: Not sure if I Can do this here. Rectangle packing would mean different %sizes of tiles. Not sure how to do packing and closest point in k-dimensional %space optimization simultaneously.\n\nFinding the overall best fit under the constraints of how often an\nimage can be repeated is NP-hard. However greedy approaches work\nreasonably well.\n\n\\ans{search-engine}\nThe predominant way of doing this is to build inverted indices. In an inverted index, for each word, we store a list of locations where the word\noccurs. Here location is defined to be the pair of document id and the\noffset in the document.  The list is stored in sorted order of\nlocations (first ordered by document id, then by offset). When we are\nlooking for the documents that contain a set of words, what we need to\ndo is find the intersection of lists for each word. Since the lists\nare already sorted, the intersection can be done in linear-time (linear in \nthe total size of the lists). There are various optimizations that\ncan be done to this basic infrastructure. We list a few thoughts below.\n\\begin {itemize}\n\\itemsep 1pt\n\\item \\textrm{Compression}---compressing the inverted index\n  helps both with the ability to index more documents as well as memory\n  locality (fewer cache misses). Since we are storing sorted lists,\n  one way of compressing is to use delta compression where we only\n  store the difference between the successive entries. The deltas can be\n  represented in fewer bits.  \n\\item \\textrm{Caching}---the distribution queries is often fairly skewed\n  and it helps a great deal to cache the results of some of the most\n  frequent queries.\n\\item \\textrm{Frequency-based optimization}---since search results often\n  do not need to return every document that matches (only top ten or\n  so), only a fraction of highest quality documents can be used to\n  answer most of the queries. This means that we can make two\n  inverted indices, one with the high quality documents that stays in the\n  memory and one with the remaining documents that stays on the disk. This\n  way if we can keep the number of queries that require the secondary\n   index to a small enough number, then we can still maintain a reasonable throughput\n  and latency.\n\\item \\textrm{Intersection order}---since the total intersection time\n  depends on the total size of lists, it would make sense to intersect the words with smaller sets first. For example, if we are looking for\n  ``USA GDP 2009'', it would make sense to intersect the lists for GDP and 2009\n  before trying to intersect the list for USA.\n\\end{itemize}\nWe could also build a multilevel index \nto improve accuracy on documents. For high priority web pages, we can\nrecursively from ``document'' abstraction introduce a notion of ``paragraph'' \nand then ``sentence'' to index further down. That way \nthe intersections for the words might be within the \nsame context. We can pick results with closer\nindex values from these lists.\n\n\n\\ans{ip-lookup}\nThis is a well studied problem because of its implications for\nbuilding a high speed Internet backbone. There are a number of \napproaches that have been proposed and used in IP routers. \nOne simple approach is to build a trie data-structure such\nthat we can traverse the trie for an IP address till we hit a node that has a\nlabel. This essentially requires one pointer indirection per bit of input. The lookup speed\ncan be improved a little at the cost of memory by making fatter nodes\nin the trie that consume multiple bits at a time.\n\nThere are a number of approaches that have been tried in software and\nhardware to speed the lookup process:\n\\begin{itemize}\n%TODO:(amit) feedback from senthil below:\n%One way of reducing this is to do a binary... In order for binary search \n% to work... terminate early. The paragraph\n%needs more elaboration.\n\\itemsep 1pt\n\n\\item Binary search on hash tables---we can have one hash table\n  for each possible length of prefix and then do a search for the\n  longest matching prefix by looking through all the hash tables. However this could take 32 hash table lookups. One way of\n  reducing this is to do a binary search for the longest matching\n  prefix. In order for binary search to work, we would have to insert\n  additional prefixes in the hash tables to ensure that if a longer prefix exists,\n  binary search does not terminate early. This can be done by performing a binary search for each prefix and insert additional dummy entries wherever the binary search terminates early. This could inflate the size\n  of hash tables by at most $\\log_2 32$ (in practice, it is much\n  smaller).\n\n\\item Ternary Content Addressable Memory (TCAM)---a TCAM is a special\n  piece of hardware, where instead of storing 0s and 1s, a single unit\n  of memory can also store a third state called the ``don't care''\n  state. Also, the contents of memory can be addressed by partial\n  contents of the memory. TCAMs with 32 address bits are used to store\n  prefixes. Each prefix is padded with ``don't care'' bits to make it 32\n  bits. This way, when we use an IP address to address the TCAM, we\n  get all the matching prefixes. A priority logic gate then selects the\n  longest matching prefix.\n\\end{itemize}\n\n\n\\ans{spell-check}\nThe basic idea behind most spelling correction systems is that the misspelled word's edit distance from the intended word tends to be very small \n(one or two edits). Hence if we keep a hash table for all the words in the dictionary and\nlook for all the words that are within two edit distances of the text, most\nlikely, the intended word will be found in this set.  If the alphabet\nhas $m$ characters and the search text\nhas $n$ characters, we would need to perform roughly $n\\cdot m^2$ hash table lookups. When we intersect all the strings within two edit\ndistance with the dictionary words, sometimes we can land up with a\nfairly large set of words and it is important to provide a ranked list\nof suggestions to the users such that the most likely candidates are at\nthe top. This is often done by various probabilistic\nmodels. There are various interesting ideas that can be used to\nimprove the spelling correction system:\n\\begin{itemize}\n\\itemsep 1pt\n\\item \\textrm{Typing errors model}---often spelling mistakes are a result\n  of typing errors. Typing errors are easy to model based on keyboard\n  layouts.\n\\item\\textrm{Phonetic modeling}---a big class of spelling errors happen\n  when the person spelling it knows how the words sounds but does not\n  know the exact spelling. In such cases, it helps to map the text to\n   phonemes and then find all the words that map to the same phonetic\n  sequence.\n\\item\\textrm{History of refinements}---often users themselves provide a\n  great amount of data about the most likely misspellings by first\n  entering a misspelled word and then correcting it. \n  This kind of historic data is often immensely valuable for spelling\n  correction.\n\\item\\textrm{Stemming}---often the size of dictionary can be reduced by only\nkeeping the stemmed version of the words in it and stemming the query\ntext as well.\n\\end{itemize}\n\n\\ans{stemming}\n%TODO(amit): feedback from senthil\n% Solution 9.5: This thought occurred to me: \n% for words beginning with a letter of the alphabet, build a trie of a smaller\n% depth, coalesce anything beyond this depth into a single node. \n% Compute edit distances for all pairs of words at this\n% node. The ones that have deletions in the end can be used together, \n% this is again quite approximate. We can play with\n% depths for each letter of the alphabet to distribute them better.\nStemming is a fairly large topic and different systems have adopted\ndifferent approaches. Porter stemmer developed by Martin Porter is\nconsidered one of the most authoritative algorithms for stemming in\nthe English language. Here we mention some basic ideas related to\nstemming, however this is in no way a comprehensive discussion on\nstemming approaches.\n \nThe basic idea in most stemming systems works based on some simple rewrite rules, such as, if the word ends with ``es'' or ``s'' or ``ation'', then we remove\nthem.  Sometimes, a simple termination may not work, for example,\n$\\mbox{wolves} \\mapsto \\mbox{wolf}$. In order to cover this case, we may have a\nrule to replace a suffix ``ves'' to ``f''.  In the end, most rules amount to matching a set of\nsuffixes and depending upon which one we end up with, we may apply a\ncertain transformation to the string. One way of efficiently doing this\ncould be to build a finite state machine based on all the rules.\n\nA more sophisticated system might have several exceptions to the broad\nrule based on the stem matching some patterns. For example, the Porter\nstemmer defines several rules based on a pattern of vowels and\nconsonants.\n\nOther approaches include use of stochastic method to learn rewrite\nrules and N-gram based approaches where we look at the surrounding\nwords to determine the correct stemming for a word.\n\n\\ans{throttle}\nThis problem as posed, has some ambiguity:\n\\begin{itemize}\n\\itemsep 1pt\n\\item Since we usually download one file in one request, if a file is\n  greater than $b$ bytes, there is no way we can meet the constraint\n  of serving fewer than $b$ bytes every minute, unless we  can work with\n  the lower layers of networking stack such as the transport layer or the\n  network layer. Often the system\n  designer could look at the distribution of file sizes and conclude\n  that this problem happens so infrequently that we do not care.\n  Alternately, we may choose to serve no more than the first $b$ bytes of any file.\n\n\\item Given that the host's bandwidth is a resource for which there could be\ncontention, one important design choice to be made is how to resolve a contention. Do we let requests get served in first-come first-served order or is there a notion of priority? Often\ncrawlers have a built-in notion of priority based on how important the\ndocument is to the users or how fresh the current copy is.\n\\end{itemize}\n\nOne way of doing this could be to maintain a server with which each\ncrawler checks to see if it is okay to hit a particular host. The server\ncan keep an account of how many bytes have been downloaded from the\nserver in the last minute and not permit any crawler to hit the server if\nwe are already close to the quota. If we do not care about priority,\nthen we can keep the interface synchronous where a server requests for\npermission to download a file and it immediately gets approved\nor denied. If we care about priorities, then the server may enqueue the\nrequest and inform the crawler when it is alright to download the\nfile. The queues at the permission server may be based on priorities.\n\nIn case the single permission server becomes a bottleneck for the\nsystem, we can use multiple servers such that the responsibility of a\ngiven host is decided by hashing the host name and assigning it to a\nparticular server based on the hash range.\n\n\\ans{page-rank}\nSince the web graph can have billions of nodes and it is mostly a\nsparse graph, it is best to represent the graph as an adjacency list.\nBuilding the adjacency list representation of the graph itself may\nrequire significant amount of computation, depending upon how the\ninformation is collected. Usually, the graph is constructed by\ndownloading the pages on the web and extracting the hyperlink\ninformation from the pages. Since the URL of a page can be arbitrarily\nlong and varies a lot in size, it is often a good idea to represent\nthe URL by a hash value.\n\nThe most expensive part of PageRank algorithm is the repeated matrix\nmultiplication. Usually, it is not possible to keep the entire graph\ninformation in a single machine's RAM. There are usually two\napproaches to solving this problem:\n\\begin{itemize}\n\\itemsep 1pt\n\\item Disk-based sorting---in this approach, we keep the column\n  vector $X$ in memory and load each row at a time.  For a given row\n  $A_i$, we write out pairs of numbers $\\langle j, A_{ij}\\cdot\n  X_j\\rangle$ to disk. Then we sort the pairs by their first component\n  on disk and then add up the second component to get the result\n  vector.  The advantage of this approach is that as long as we can\n  hold the column vector in the RAM, we can do the entire computation\n  on a single machine. However this approach can be fairly slow\n  because disk-based sorting is usually slow.\n\n\\item Partitioned graph---in this approach, we use $n$ machines\n  and partition the vertices (web pages) into $n$ sets. Usually, the\n  partitioning is done by partitioning the hash space such that it is\n  easy to determine which vertex maps to which machine. Given this\n  partitioning, each machine loads its vertices and their outgoing\n  edges into RAM. Each machine also loads the parts of the PageRank\n  vector that corresponds to its vertices. Then each machine does a\n  local matrix multiplication. Since some of the edges on each machine\n  would correspond to the nodes that are owned by other machines, the\n  result vector is going to contain nonzero entries for vertices that\n  are not owned by the local machine. So, at the end of local\n  multiplication, we need to send updates to other hosts so that\n  these values can be correctly added up. The advantage of this\n  approach is that we can process arbitrarily large graphs as long as\n  we have sufficient number of machines. \n\\end{itemize}\n\n\\ans{priority-system}\nIf we have sufficient RAM on a single machine, the most simple\nsolution would be to maintain a min-heap where we maintain\nall the events by their priority.  Since we are interested in a\nscalable solution to this problem, we need to partition the problem\nacross multiple machines. \n\nOne way of doing this could be to hash the\nevents and partition them into ranges so that one hash range\ncorresponds to one machine. This way, the insert and delete operations can\nbe done by just communicating with one of the servers. However in\norder to do the extract-min operation, we need to send a find-min\nmessage to all the machines, infer the min from all their\nresponses, and then try to delete it. \n\nSince at a given time, all the clients would be interested in the same\nevent (the highest priority event), it is hard to distribute this\nproblem well.\nIf a large number of clients are\ntrying to do this operation at the same time, we may run into a\nsituation where most clients will find that the absolute min event they were\ntrying to extract has already been deleted. If the throughput of this\nservice can be handled by a single machine, we can keep one server\nthat is responsible for responding to all the machines. This\nserver can prefetch top hundred or so events from each of the machines\nand keep them in a heap.\n\nIn many applications, we do not need strong consistency guarantees. What we need is that overall, we spend most of our resources taking care of the highest priority jobs. In such cases, a client can pick one of the hash ranges randomly\nand just request the highest priority job from the corresponding\nmachine. This would work great for distributed crawler application but\nit would be a bad idea for event driven simulation.\n\n\n\\ans{min-latency}\nOften clients of a service care more about the $99$-th or the $95$-th\npercentile latency for the server rather than the mean latency since they want\nmost of the requests to be serviced in a reasonable amount of time even if an\noccasional request takes very long. If our architecture is such that\nat a time only a fixed number of requests can get served and other\npending requests must wait for a slot to open up before getting\nserved, it is important to design our queuing system in such a way\nthat the requests that take a very long time to serve do not block many small\njobs behind them.\n\nConsider the case where the time it takes for the server to process a\nrequest is a function of the request. Given the\ndistribution of requests, the service time follows a Pareto distribution. In\nsuch cases, it greatly helps to have two queues and pick a good\nthreshold such that the requests that take longer than the threshold\ntime, go to one queue and the requests that take less than or equal to\nthe threshold time, go to the other queue. We pick the threshold such that\nthe majority of jobs go to the faster queue and the jobs in this queue\nare never blocked behind a big job.  The larger jobs do have to wait\nmore behind the larger jobs but overall this strategy can greatly\nreduce the $99$-th percentile latency.\n\nOften the system designer does not know how long a given request is\ngoing to take in advance in order to make the right queuing decision. It has\nbeen shown that even in such cases, it is advantageous to keep two\nqueues. When a request comes in, it is put in the fast queue, however\nwhen it takes longer than a certain threshold time, we cancel the\nrequest and put it at the back of the slow queue.\n\n\n\\ans{adwords}\nReasonable goals for such a system could include:\n\\itemsep 1pt\n\\begin{itemize}\n\\item providing users with the most relevant ads\n\\item provide advertisers with the best possible return on their investment\n\\item minimizing the cost of running such an operation\n\\end{itemize}\n\nThere are two key components to building such a system: \n(1.)~the front-facing component, by which advertisers can add\ntheir advertisements, control when their ads get displayed, how much\nand how they want to spend their advertising money, and review\nthe performance of their ads and (2.)~the ad-serving system\nwhich selects which ads to show on the searches.\n\nThe front-facing system can be a fairly conventional website design.\nUsers interact with the system using a browser and opening a \nconnection to the website. You will need to build a number of features:\n\\begin{itemize}\n\\itemsep 1pt\n\\item \\textrm{User authentication}---a way for users to create accounts and\n  authenticate themselves.\n\\item\\textrm{User state}---a set of forms to let advertisers specify things\n  like their advertising materials, their advertising budget etc. Also\n  a way to store this information persistently.\n\\item\\textrm{Performance reports}---a way to generate reports on how and\n  where the advertiser's money is being spent.\n\\item\\textrm{Human interactions}---even the best of automated systems require\n  occasional human interaction and a way to interfere with the\n  algorithms. This may require an interface for advertisers to be able\n  to contact customer service representatives and an interface for\n  those representatives to interact with the system.\n\\end{itemize}\n\\begin{comment}\nThere are standard techniques \nfor maintaining a list of users, and authenticating them.\n\n\nUsers can enter their ads using text-boxes or file uploads (if\nads can be in image or flash format). They can also enter what\nkeywords, locales, times-of-day, etc. they want the ads to be shown\nin.  The entry can be made more efficient using AJAX, e.g., \nauto-completing keywords, and suggesting synonyms. \n\nUsers also need to specify how much they want to spend in a day,\nhow much they are willing to pay for an ad to be displayed,\nand how much they will pay for an ad that is clicked on.\n\\end{comment}\n\nThe whole front-end system can be built using, for example, HTML and\nJavaScript, with a LAMP stack (Linux as the operating system, Apache as the HTTP\nserver, MySQL as the database software, and PHP for the application logic) \nresponding to the user input.\n\n\\begin{comment}\nIn addition to the frontend seen by the users, it would\nalso be necessary to have a customer service frontend, by which\ncustomer service representatives (CSRs) can over-ride default limits \non the number of ads or keywords, compute detailed comparisons\nof ads, bill customers, etc.\n\nThe system also needs to be able to look for \nads that potentially violate policies on copyright violation or use abusive language.  CSRs can be alerted on ads \nbeing posted that refer to known copyrights or use words from a dictionary\nof potentially unacceptable words.\n\\end{comment}\n\nThe ad-serving system would probably be a less conventional web service.\nIt needs to choose\nads based on their ``relevance'' to the search, \nperhaps some knowledge of the user's search history, and how much the advertiser is\nwilling to pay. A number of strategies could be envisioned here for\nestimating relevance, such\nas, using information retrieval or  machine learning techniques that learn from past user interactions.\n\n%TODO(amit): added from senthil's mail, pls check\n%amit: either I am not understanding  or this seems like a complex way of solving a simpler matching problem.\n% there is another class of ad serving problems where different ads define %different constraints about what can get served and what cannot and the concern % is to meet ad reservations. There flow makes a lot of sense. I Can write about % this at some point.\n%One approach to the ad-serving problem could be to use network flow. There are %$m$ ads on the source side and $n$ web pages on the sink side. An ad has an %edge to a page if it is relevant to it. The costs of the ads are \n%the capacities of edges from the source. Page frequency ratio times the total %sum of ad costs will be the capacities on the edges to the sink. A max flow \n%might give us an optimal pairing. Relevance can be found with textual \n%analysis with ad tags and data mining of the web page.  \n\nThe ads can be added to the search results\nby embedding JavaScript in the results that pulls in the ads from the\nad-serving system directly. This helps isolate the latency of serving search results from the latency of serving ad results.\n\n\\ans{rec-system}\n% It is natural to provide snippets from ``similar'' pages, with each snippet being\n% a hyperlink.  \nThe key technical challenge in this problem is to come up with the list of\narticles---the HTML code for adding these to a sidebar is trivial.\n\nOne suggestion might be to add articles that have proven to be popular recently.\nAnother is to have links to recent news articles.  A human reader at Jingle \ncould tag articles which he believes to be significant. He could \nalso add tags such as finance, politics, etc. to the articles.\n% and an article to a finance article could be linked only to those which have tags.\nThese tags could also come from the HTML meta-tags or the page title.\n\nWe could also sometimes provide articles at random and see how popular\nthey prove to be; the popular articles can then be shown more\nfrequently.\n\nOn a more sophisticated level, Jingle could use automatic textual analysis,\nwhere a similarity is defined between pairs of articles---this similarity is\na real number and measures how many words are common to the two. Several \nissues come up, such as the fact that frequently occurring words such\nas ``for'' and ``the'' should be ignored and that having\nrare words such as ``arbitrage'' and ``induction'' in common is more important\nthan having say, ``America'' and ``international''.\n\nTextual analysis has problems, such as the fact that two words may\nhave the same spelling but completely different meanings (anti-virus\nmeans different things in the context of articles on AIDS and computer security).\n\nOne way to augment textual analysis is to use collaborative filtering---using\ninformation gleaned from many users. For example, by examining cookies and\ntime-stamps in the web server's log files, we can tell what articles individual users have read.\nIf we see many users have read both $A$ and $B$ in a single session, we might\nwant to recommend $B$ to anyone reading $A$. For collaborative filtering to work,\nwe need to have a substantial number of users.\n\n% Textual analysis, currentness, clustering based on log file analysis, rules, breaking articles,\n% user knowledge, tags; collaborative filtering\n\n\n\n\\ans{poker}\nAn online poker playing service would have a front-end system\nwhich users interact with and a back-end system which runs\nthe games, manages money, looks for fraud, etc.\n\nThe front-end system would entail a UI for account management---this would cover\nfirst-time registration, logging-in, managing online persona, and \nsending or receiving money.\nIn addition, there would be the game playing UI---this could be\nas simple as some HTML rendering of the state of the game (cards in\nhand, cards on the table, bets) and a form to enter a bet.\nA more sophisticated UI might use JavaScript to animate cards being\ndealt, change the expression on player's images, status messages or smileys from\nplayers, etc.\n\nThe back-end needs to be able to form tables of players,\nshuffle in a truly random manner,\ndeal correctly, check if the player's moves are legal, and update \nplayer's finances.  It can be implemented using, for example, a Java servlet\nengine which receives HTTP requests, sends appropriate responses, and updates\nthe database appropriately.\n\nOne of the big challenges in such a system is fault-tolerance.\nOn the server side, there are standard techniques for this, such\nas replication. \n\n% http://www.onlinepokerfaq.com/guide/cheating.html\nOn the client side, there is the possibility that\na player may realize he is in a poor situation and claim that his Internet\nconnection went down. This can be resolved by having a rule that \nthe server will bid on the player's behalf if the player does not respond\nquickly enough. Another possibility is having the server treat the\nplayer who is disconnected as being in the game but not requiring any\nmore betting of him.  This clearly can be abused by the player, so \nthe server needs to record how often a player's connection hangs\nin a way that is favorable to him.\n\nCollusion between players is another serious problem.  Again, the server logs\ncan be mined for examples of players working together to share knowledge\nof their cards or squeeze other players out. In addition, players\ncan themselves flag suspicious play and customer service representatives can investigate further.\n\nRandom number generation is an intensely studied problem but is\nstill easy to get wrong. A fairly frequent problem is using process id\nas a seed for a random number generator, which means that\nthere are only roughly 20,000 possible sequences of random numbers.\nThis means that, on an average, knowing the first 4 cards is enough\nto predict the order of the rest of the cards \nsince $ \\log_2 \\binom{52}{4} \\approx 18.04 > \\log_2 20000 = \\approx 14.28$.\n\n\n\\ans{driving-directions}\nAt its core, a driving directions service needs to store the map as a\nGraph, where each intersection and street address is a vertex and the\nroads connecting them are edges. When a user enters a starting\naddress and an ending address, it finds the corresponding vertices and\nfinds the shortest path connecting the two vertices (for some definition of shortest). There are several issues that come up:\n\\begin{itemize}\n\\itemsep 1pt\n\n\\item Address normalization---a given address may be expressed by\n  the user in different ways, for example, ``street'' may be shortened\n  to ``st'', there may not be a city and state, just zip code or vice\n  versa. We need a way to normalize the addresses to a standard\n  format. Sometimes an underspecified address may need to be mapped to\n  some concrete address, for example, a city name to the city center.\n\\item Definition of shortest---different users may have different\n  preferences for routing, for example, shortest distance or fastest\n  path (considering average speed on the road), avoiding use of freeways,\n  etc. Each of these preferences can be captured by some notion of\n  edge length.\n\\item Approximate shortest distance---given the enormity of a\n  graph representing all the roads in a large country, it would be\n  fairly difficult for a single server to compute the shortest path\n  using standard shortest path algorithms and return in a reasonable\n  amount of time. However using the knowledge that most long paths go\n  through a standard system of highways and the fact that the nodes\n  and edges in the graph represent points in euclidean space, we can\n  devise some clever approximation algorithms that run much\n  faster. \n\\end{itemize}\n\n\\ans{isbn-lru}\nTo quickly lookup an ISBN number, we would want a hash table\ndata-structure. However it would take $O(n)$ time to find the least-recently-used item in a hash table to discard. One way to improve the\nperformance would be to be lazy about garbage collection such that the\ncost of removal of least-recently-used ISBNs can be amortized over\nseveral lookups. To be concrete, let's say we want the cache to be of\nsize $n$, then we do not delete any entries from the hash table till it\ngrows to the size of $2n$. At this point, we go over the entire\nhash table, looking at the number of times this item was used,\nfind the median number of times a value in the hash table was used, and then\ndiscard everything below the median. This way, the cost of delete\noperations is $O(n)$ but it will happen at least at the interval of $n$\nlookups, hence the amortized cost of deletion is $O(1)$ at the cost of\ndoubling the memory consumption.\n\n\\ans{file-copy}\nAssume that the bandwidth from the lab machine is a limiting factor.\nIt is reasonable to first perform trivial optimizations, such as\ncombining the articles into a single file and compressing this file.\n\nOpening 1000 connections each five minutes from the lab server to \nthe 1000 machines in the datacenter and transferring the\nlatest news articles is not feasible since the total data transferred\nwill be approximately 5~terabytes (without compression) every five minutes. \n\nSince the bandwidth between machines in a datacenter is very high,\nwe can copy the file from the lab machine to a single machine\nin the datacenter and have the machines in the datacenter \ncomplete the copy.  Instead of having just one machine serve\nthe file to the remaining 999 machines, we can have each machine \nthat has received the file initiate copies to the machines that\nhave not yet received the file.  In theory, this leads to an exponential\nreduction in the time taken to perform the copy.\n\nThere are several issues which have to be dealt with: should a machine initiate\nfurther copies before it has received the entire file? (This is tricky\nbecause of link or server failures.) How should the knowledge of machines\nwhich do not yet have copies of the file be shared? (There can be a\ncentral repository or servers can simply check others by random\nselection.)  If the bandwidth between machines in a datacenter is not a\nconstant, how should the selections be made? (Servers close to each other, e.g., in the\nsame rack, should prefer communicating with each other.)  \n\nFinally, it should be mentioned that there are open source \nsolutions to this problem, e.g., Unison, which would be a good place to start.\n\n\\ans{leader-election}\nThink of the hosts as being vertices in a directed graph with an\nedge from $A$ to $B$, if $A$ initially know $B$'s IP address.\n\nWe will study variants of this problem---synchronized or unsynchronized\nhosts and known or unknown bounds on the network; compare\nthem with respect to convergence time, message size, and the number\nof messages. We assume the graph is strongly connected (otherwise, the problem is unsolvable).\n\nFirst, assume that the hosts are all synchronized to a common\nclock (there are standard protocols which can allow computers\nto synchronize within a few tens of milliseconds; alternately,\nGPS signals can be used to achieve even tighter synchronization).\n\nWe will consider the case where the number of hosts $N$ and\nthe diameter $D$ of the network is known to all the hosts. \nOur algorithm will elect the host with the highest IP address as the\nleader.\nThe simplest algorithm for leader election is flooding---each\nhost keeps track of the highest IP address it\nknows about; the highest IP address is initialized to\nits own IP address.\n\nSince hosts are synchronized, we can proceed in rounds.\nIn each round, host propagates the highest IP address\nit knows of to each of its (initial) neighbors. After \n$D$ rounds, if the highest IP address a host knows of is\nits own, it declares itself the leader.\n\nThere is a small improvement to this algorithm which reduces\nthe number of messages sent---a host sends out an update\nonly when the highest IP address it knows about changes.\n\nIt takes $D$ rounds to converge and $|E|\\cdot D$ messages are\ncommunicated.\nThe number of iterations to convergence can be reduced\nto $\\log_2 D$ by having each host send the set\nof hosts it has discovered in each iteration to each\nhost it knows about. This leads to faster convergence\nsince the distance to the frontier of undiscovered hosts\ndoubles in each iteration. However it requires much\nmore communication---the final round involves $N$\nhosts sending $N$ messages and each message\nhas the ids of $N$ hosts. Furthermore, unlike the\noriginal algorithm, this variant requires messages\nto potentially traverse longer routes (in the original\nalgorithm, a host communicated only with the hosts it knew about initially).\nThe algorithm works correctly even if $D$ is just an upper bound on the true diameter.\n\nWhen $N$ and $D$ are completely unknown, leader election can be performed through a distributed BFS.\nEach host starts by sending out a search message to all\nof its outgoing neighbors. In any round, if a host\nreceives a search message, it chooses one of the \nhosts from which it received a search as its parent and\ninforms its parent about its selection.\n(Since we are assuming an IP network, a child\ncan directly communicate its selection back\nto its parent.)\n\nThis procedure constructs a BFS tree for each host. \nCompletion can be detected by having hosts respond \nto search messages with both a parent or nonparent message\nas well as a notification of completion from its children.\nWhen BFS completes, each host has complete knowledge\nof the graph and can determine the leader.\n\nNow, we consider the asynchronous case. The flooding\nalgorithms we considered earlier cannot be directly\ngeneralized to asynchronous hosts because there\nis no notion of a round.  However we can simulate\nrounds by having hosts tag their messages with\nthe round number. A host waits to receive\nall round $r$ messages from all its neighbors before\nperforming its round $r$ update. \n\nNote that this algorithm cannot avoid sending messages if\nthe highest IP it knows about does not change in round $r$\nsince the neighbors depend on receiving all their round $r$\nmessages before they can advance.  \n\n\\ans{discovery}\nDiscovery and leader election are identical, so the solution to \nProblem~\\ref{leader-election} works here too.\n\n\\chapter{ Discrete Mathematics}\n\n\\ans{binom}\nIt is tempting to try and pair up terms in the numerator and denominator for the\nexpression for  $\\binom{n}{k}$ that have common factors and try to somehow  cancel them out.\nThis approach is unsatisfactory because of the need to have factorizations.\n\nThe binomial coefficients satisfy several identities, the most basic of which is the {\\em addition\nformula:}\n\\[\n \\binom{n}{k} =  \\binom{n-1}{k} +  \\binom{n-1}{k-1} .\n\\]\nThere are various proofs of this identity, ranging from the combinatorial interpretation\nto induction and finally, direct manipulation of the expressions.\n\nThis identity yields a straightforward recursion for $\\binom{n}{k}$. \nThe base cases are  $\\binom{r}{r}$ and  $\\binom{r}{0}$, both of which are 1.\nThe individual results from\nthe subcalls are integers and if  $\\binom{n}{k}$ can be represented by an \\texttt{int}, they can too; so, overflow is not a concern.\n\nThe recursion can lead to repeated subcalls and consequently exponential runtimes. There is\nan easy fix---cache intermediate results as in dynamic programming. There are\n$O(n^2)$ subproblems and the results can be combined in $O(1)$ time, yielding an $O(n^2)$ complexity bound.\n\n\\ans{climbing-stairs}\n\\begin{comment}\n% AA's solution:\nLet $S(k)$ denote the number of ways of climbing a\nstaircase with $k$ steps.\nNote that $S(0) = 1$ and $S(1) = 1$.\nThere are two choices for the final step---either take two steps or one step; both\nyield different jump sequences.\nTherefore $S$ satisfies the following recurrence:\n\\begin{eqnarray*}\nS(k) & = & S(k-1) + S(k-2), \\;\\;\\mbox{if} \\; k > 1.\n\\end{eqnarray*}\nThe solution to this is the Fibonacci sequence.\n\\end{comment}\n% AP's solution:\nLet $F(n)$ be the number of ways of climbing $n$ stairs through a\ncombination of one or two steps.  We note that $F(1) = 1$ and $F(0) =\n1$.\nNow, all paths that lead us to cross $n$ steps either start with a\nsingle step or a double step. In case of a single step, there are\n$F(n-1)$ ways of completing the path. In case of a double step, there\nare $F(n-2)$ ways of completing the path. Hence\n\\[ F(n) = F(n-1) + F(n-2) . \\]\nThis leads to a simple dynamic programming algorithm that can compute\n$F(n)$ in $O(n)$ time. An interesting thing to note \nhere is that $F(n)$ has the same recurrence relationship as the Fibonacci\nnumbers and $F(n)$ is actually the $(n +1)$-th Fibonacci number.\n\n\\ans{ramsey}\nThis problem can be modeled using undirected graphs where vertices correspond to guests.\nThere is a pair of edges between every pair of guests.  Color an edge between a pair of guest ``blue''\nif they are friends, otherwise, color it ``red''.\n\nThen the theorem is equivalent to the claim\nthat in any clique on six vertices, where the edges are either blue or red, there is a subset of\nthree vertices, all connected by edges of the same color.\n\n\nChoose any vertex $v$.  Examine the five edges with an endpoint\nin $V_0$.  There must be at least three edges which are of the same color $c$\n(this follows from the pigeon-hole principle).  Let $(v,\\alpha), (v,\\beta), (v,\\gamma)$ be three such edges. Now, either there is an edge colored $c$\nbetween one of $\\alpha,\\beta$ and $\\gamma$, in which case $v$ and the vertices in $\\alpha,\\beta$ and $\\gamma$\nare connected by edges colored $c$ or there is no such edge, in which case $\\alpha,\\beta$ and $\\gamma$ are\nthemselves connected by edges that are of the same color.\n\n\n\\begin{comment}\n\\ans{red-black}\nFor any search tree, the worst-case lookup time is dictated by its height.  We need to know the maximum\nheight a tree storing $n$ keys can have.  It is an elementary fact that there must be $n-1$\ninternal nodes in a search tree with $n$ keys.\n\nWe will now compute a bound on the height $h$\nas a function of the number of internal nodes.\nLet $H(n)$ be this quantity.\nWe claim that $H(n)$ is at most $2 \\log(n+1)$.\n\nWe prove this by induction on $n$: it trivially holds for $n=0$ since the tree must consist of a single leaf and therefore have height $0$.\n\nFor the inductive step, consider a tree with $n+1$ internal nodes.  The root must be an internal node with\ntwo children.\n\nNote---seems to require the use of the Red-Black property, CLRS has a proof (page 274, Ed.~2).\nUnless we stick to just proving an $O(\\log n)$ bound.\n\\end{comment}\n\n\\ans{500-doors}\nNumber the doors from 1 to 500.\nLet's start with some examples---door 12 is toggled on days 1, 2, 3, 4, 6, 12; door 3 is toggled\non days 1 and 3; door 1 is toggled on day 1; door 500 is toggled on days 1, 2, 4, 5, 10, 20, 25, 50, 100, 125, 250, 500.\n\nThe pattern that emerges is the following: a door is toggled as many times as its id has divisors.\nDivisors come in pairs: $12 = 1\\times 12 = 2\\times 6 = 3\\times 4$. So, the total number of divisors is even, except when the number is a perfect square.\nFor the perfect square case, the total number of divisors is odd.\nTherefore the doors that are open at the end of the process are those with ids\n1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324,\n361, 400, 441, 484---these are 22 doors altogether. In the general case, it\nwould be $\\lfloor\\sqrt{n}\\rfloor$, where $n$ is the number of doors. \n\n%Source: AA---maybe Zeitz?\n\n\\ans{height-determination}\nLet $F(k,l)$ be the maximum number of floors that can be tested by\n$k$ identical balls and at most $l$ drops. We know that $F(1,l) =\nl$. If we are given an additional ball to drop, we can drop the first\nball at $F(k,l-1) $ floor. If it breaks, then we can use the\nremaining balls and $l-1$ drops to determine the floor exactly; if it\ndoes not break, then we could drop the first ball at $F(k,l-1)  +\nF(k, l-2)$ floor. If it breaks, we can use the remaining $k$ balls\nand $l-2$ drops to narrow down the exact floor between $F(k,l-1)  +\n1$ and $F(k,l-1)  +\nF(k-1, l-2)$.  Continuing this argument till $k-1$ drops of the first\nball, we can test up to $\\sum_{i=1}^{l-1} F(k, l-i)$  floors. Hence\n\n\\[F(k+1,l) = \\sum_{i=0}^{l-1} F(k, l-i) . \\]\n\nGiven the above recurrence relationship it is straightforward to\nobserve that $F(k+1,l)   = \\binom{ k + l  -1}{k}$ since it follows\nexactly the same recurrence relationship. (One easy way to notice this is to\ntabulate some concrete values for $F(k,l)$.)  Now, since $F(k,l)$ monotonically\nincreases in $k$ and $l$, we can easily invert it to determine the number of\ndrops needed, given the number of balls and the number of drops.\n\n\\ans{card-color-bet}\nA good way to begin this problem is to come up with some strategy\nthat guarantees a positive return. It is possible to guarantee a $2\\times$\nreturn by \nwaiting till the last card and betting the entire amount\non the last card whose color is uniquely determined by the \nthe 51 cards that have already been seen.\n\nTo do better than a $2\\times$ return, consider the case of a deck of\n$4$ cards with $2$ red cards and $2$ black cards.  If we do not bet\non the first card, there will be three remaining cards. Assume, without loss of generality, that two cards are black and one is red. If we bet \\$$\\frac{1}{3}$ on the next card being black and are successful,\nthen we have \\$$\\frac{4}{3}$ which we can double on the last card for\na $\\frac{8}{3} > 2$ return. If we lose, then the two remaining cards are black, \nin which case we can double our remaining money twice, i.e., achieve\na $\\frac{2}{3} \\times 2 \\times 2 = \\frac{8}{3} > 2$ return.\nNote that this analysis assumes we can bet arbitrary fractions of the money \nwe possess.\n\nNow, we consider the case where we can only bet in penny increments.\nLet $Q(c,r,t)$ be the most we can guarantee, when we have $c$ cents to\ngamble with and there are $r$ red cards remaining out of a total of $t$ cards.\nWe can bet $b$ cents, $0 \\leq b \\leq c$ on the next card.\nSince we have to design a strategy that maximizes the worst-case\npayoff, the maximum amount we can make on betting on red cards is given by\n\\ifthenelse{\\boolean{createspace}}{\n\\begin{eqnarray*}\nQ_R(c,r,t) & = & \\max_{b\\in \\{0,1,2,\\ldots,c\\}} \\min\\big( Q(c+b, r-1, t-1), Q(c-b,r,t)\\big).\n\\end{eqnarray*}\n} {\n\\begin{eqnarray*}\n\\lefteqn{Q_R(c,r,t)  = } \\\\\n& & \\max_{0 \\leq b \\leq c } \\min\\big( Q(c+b, r-1, t-1), Q(c-b,r,t)\\big).\n\\end{eqnarray*}\n}\nThe maximum we can make by betting on black cards is\n\\ifthenelse{\\boolean{createspace}}{\n\\begin{eqnarray*}\nQ_B(c,r,t) & = & \\max_{b\\in \\{0,1,2,\\ldots,c\\}} \\min\\big( Q(c+b, r, t-1), Q(c-b,r-1,t)\\big).\n\\end{eqnarray*}\n}\n{\n\\begin{eqnarray*}\n\\lefteqn{Q_B(c,r,t) =} \\\\\n& & \\max_{0 \\leq b \\leq c} \\min\\big( Q(c+b, r, t-1), Q(c-b,r-1,t)\\big).\n\\end{eqnarray*}\n}\nHence $Q(c,r,t) = \\max\\big(Q_R(c,r.t), Q_B(c,r,t)\\big)$ which yields a dynamic programming\nalgorithm for computing the maximum payoff---base cases are of the form $Q(c,0,t)$\nand $Q(c,t,t)$, both of which are $c\\times 2^t$.\n\nHowever if we directly try and compute $Q(100,26,52)$, the algorithm runs for an\nunacceptably long time. This is because we will be exploring paths for which $c$ grows\nvery large. Since we are given the maximum payoff on a dollar\nwhen fractional amounts can be bet is less than $9.09$, we can prune computations for $Q(c,r,t)$\nwhen $c \\geq 909$. The following code implements the dynamic programming algorithm\nwith this pruning; it computes the maximum payoff, $808$, in two minutes.\n\n\\lstinputlisting[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Java]{CardSelect.java}\n\n\\ans{odd-even}\nThe process will converge since at each step, we reduce the number of integers in $A$ by one.\nThe number of odd integers removed in \neach step is even since we either remove two odd integers or none.  \nTherefore if there were an even number of odd integers to begin with,\nthe last integer must be even; if there were an odd number of odd numbers to begin with, it must be odd.\n\n\\ans{gassing-up}\nConsider the thought experiment of starting at an arbitrary city with sufficiently large amount\nof gas so that we can complete the loop. In this experiment, we note the amount\nof gas in the tank as the vehicle goes through the loop at each\ncity before loading the gas kept in that city for the vehicle. If\nwe start at a different city with a different amount of gas, the amount\nof gas in the tank at each city should still vary in the same fashion\nwith a constant offset. If we pick the city where the amount of gas in\nthe tank is minimum as the starting point, clearly we will never run out\nof gas. This computation can be easily done in linear-time with a\nsingle pass over all the cities.\n\n\n\\begin{comment}\nLet the cities be numbered $0,1,\\ldots,n-1$, and let it take $d_i$\ngas to drive from city $i$ to $i+1 \\bmod{n}$. Suppose there is $g_i$\ngas available at city $i$.  \n\nWe are given that $G = \\sum_{i=0}^{n-1} g_i = D = \\sum_{i=0}^{n-1}  d_i$.\n\nSuppose for the sake of contradiction---there is no city from \nwhich we can start with an empty tank and drive a complete\ncycle.\n\nSuppose we start at $0$, and the furthest we can get to without running\nout of gas is $F_0$ ($F_0$ may be $0$ itself). \nThis means that the sum of the $g_i$'s from $0$ to $F_0$ (inclusive)\nis strictly less than the sum of the $d_i$'s from $0$ to $F_0$.\n\nNow consider starting at $F_0 + 1$, say the furthest we can get\nto is $F_1$.  In this way, we get a series of paths\n$\\langle 0,\\ldots, F_0\\rangle$, $\\langle F_0 + 1,\\ldots, F_1\\rangle$,\netc. \n\nFor a path $\\langle A,\\ldots, B\\rangle$, we will refer to $A$ as \nbeing the start, and $B$ as being the end.\n\nSince the number of cities is finite, at some point we must have\nthe end $e$ of one path being the start $s$ of another path.  If we sum\nup the $g_i$'s for all the cities occurring on the paths starting at $s$\nuntil we get to $e$, we will get $k \\cdot G$, where $k > 0$ (since we may loop\naround multiple times).  Similarly, the sum of the $d_i$'s will be $k \\cdot D$.\n\nBut, by construction, for each path, the sum of the $g_i$'s is less than the\nsum of the $g_i$'s, which leads to a contradiction.\n\nHere's a much simpler solution: there must be some city $i$ with enough gas $g_i$ to drive to\nthe next city. Logically, the gas from city $i+1 \\bmod{n}$ can be added to the gas at\ncity $i$, and city $i+1 \\bmod{n}$ can be removed from consideration. The remaining\ncities, together with $i$ (which now has gas $g_i + g_{i+1 \\bmod{n}}$) satisfy\nthe conditions of the problem, so we can inductively continue till we've got just one city with\nenough gas to complete the circuit.\n\\end{comment}\n\n\\ans{suicidal}\nConsider the case where exactly one person has green eyes. The\nstatement from the explorer would make it clear to the\nperson with green eyes that he  has green eyes since nobody else\nthat he sees has green eyes. \n\nNow, suppose there are two inhabitants with green eyes. \nThe first day, each of these two inhabitants would see exactly one other person with\ngreen eyes. Each would see the other person on the second day too, from which\nthey could infer that there must be two\ninhabitants with green eyes, the second one being themselves. \nHence both of them would leave the second day.\n\nUsing induction, we can demonstrate that if there are $k$ inhabitants\nwith green eyes, all the green-eyed inhabitants would leave after the \n$k$-th assembly. We already saw the base case, $k=1$. Suppose the\ninduction hypothesis  holds \nfor $k-1$.  If there are $k$ inhabitants with green\neyes, each inhabitant with green eyes would see $k-1$ other\ninhabitants with green eyes.\nIf at the $k$-th assembly, they see that nobody has departed, \nit would indicate that they themselves have green eyes and hence\nall the green-eyed inhabitants would leave on the $k$-th day.\n\nAs for the second part of the question, for $k=1$, it is\nfairly obvious that the explorer gave new knowledge to the person with\ngreen eyes. For other cases, the new information is a bit subtle. For $k=2$, the green-eyed inhabitants would be able to infer\nthe color of their eyes on the second day based on the information that\neveryone on the island knows that there are green-eyed inhabitants\nand yet no one left. For $k=3$, they are able to infer\nbecause everyone knows that everyone knows that there are green-eyed\ninhabitants and yet on the second day no one left. \n\nSuppose $x$ is some fact and $E(x)$ represents the fact that everyone knows $x$ to be true. In this case, let $g$ represent the fact\nthat there are some green-eyed inhabitants on the island. Then on the $k$-th day, all the green-eyed\ninhabitants would use the fact $E^K(g)$ to infer that they have green-eyes.\nEssentially, what the explorer did by announcing the fact in the assembly is that it became ``common knowledge'', i.e., $E^{\\infty}(g)$ became true. \n\n\\begin{comment}\nIt is easiest to consider this problem when there are only two\ninhabitants---then each of the two inhabitants knows there are two eye colors, and knows\nthe other inhabitant's eye color, and can can therefore immediately infer his own.\n\nNow consider the case where there are three inhabitants. Two must have one\ncolor, say brown, and the other must have blue eyes. The blue-eyed inhabitant realizes\nthat his eyes must be blue since he knows the others have brown eyes.\nHe will kill himself at midnight, and therefore, not appear the next day. The two brown-eyed\ninhabitants can infer that their own eye color must be brown for the\nblue-eyed inhabitant to have inferred his own color, and they will kill themselves.\n\nFor the case of four inhabitants, if there are three  with one color, and one with the other,\nthe latter will infer his color, and then the first three will know that they all had\nthe same color.  If there are two of each color, then all will be alive the \nnext day, and therefore each knows that his color cannot be the same as the two\nwho have a common color.  Proceeding inductively, if there are $2N$ inhabitants, \nthey will all kill themselves on the $N$-th day.\n\nFor the second part of the question, the new knowledge injected by\nthe explorer is subtle. For the case $N=3$ with one blue-eyed and two \nbrown-eyed inhabitants, the explorer is telling the inhabitants with blue-eyes\nsomething new. For the case $N=4$,  with two inhabitants of each color, the explorer is telling\nthe inhabitants that the others know that there are two colors (which would\nnot be the case if 3 had one color since the remaining inhabitant could have\nthe same color).\n\\end{comment} \n\n\\ans{hershey}\nIf the assumption is that once you have broken the bar into two pieces, they become separate \nproblems, then it does not matter what order you do it---you will require 15 total breaks in \nany scenario.\n\nIf, on the other hand, the assumption is that the whole bar stays together (as it would if \nyou were breaking it inside its wrapper, for instance), then you can do a little better. \nYou could simply break it along all axes (say, first the vertical and then the horizontal) \nfor a total of 6 breaks.\n\n\n\\ans{chomp-1}\n\\begin{comment}\nPlayer~1 can always win. Here is a winning strategy for him: start by eating the square\nat $(1,1)$.  Now, it is Player~2's turn and the remaining pieces are a\nset of the form $\\{ (x,y) | x = 0 \\mbox{ or } y = 0, 0 \\leq x, y \\leq n \\}$.\nEither Player~2 eats the poisoned square or he eats a square at $(0,k)$ or\n$(k,0)$, where $n \\geq k >0$.  If Player~2 chooses $(0,k)$, Player~1 can eat the\nsquare at $(k,0)$; if Player~2 chooses $(k,0)$, Player~1 can eat the square at\n$(0,k)$. In either case, it is now Player~2's turn and the remaining pieces are\na set of the form $\\{ (x,y) | x = 0 \\mbox{ or } y = 0, 0 \\leq x, y \\leq k-1 \\}$.\nEventually, this set will become $\\{(0,0)\\}$ and Player~2 will be forced to eat\nthe poisoned piece.\n\nGiven a $n \\times n$ rectangle, in the upper right quadrant in the Cartesian\nplane, with the lower leftmost point at $(0, 0)$. Two players take turns at taking a bite out of the \nrectangle. A bite removes a square and all squares above and to the right. The first \nplayer to eat the square at $(0, 0)$ loses. Construct a winning strategy for Player 1.\n\\end{comment}\nPlayer~1 can always win. The key observation in this game is that we want to\nforce the play to be symmetrical around the diagonal, i.e.,\n$(0,0), (1,1), \\ldots, (n,n)$ with our opponent forced to move first in terms of breaking the symmetry. If that is \nthe case, we can follow each of his moves by a matching move reflected in this \ndiagonal which will eventually force him \nto select the $(0,0)$ space. \n\nThe way to force this type of play is to be the first person to \nselect $(1,1)$---this causes the play area to be just the column $(0, [0-n])$\nand the row $([0-n], 0)$ (i.e., an ``L'' shape). At that point, we can\nsuccessfully mirror any move that Player~2 makes, forcing him to eventually\nchoose (0,0).\n\n% In pseudocode:\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true]\nWinChomp():\n    Choose (1,1)\n    Until you win:\n        Wait for Player 2 to choose square (i,j)\n        Choose square (j,i)\n\\end{lstlisting}\n\n\\ans{chomp-2}\nSuppose the set of remaining squares are of the form of a rectangle and one\nadditional square (which must be on the lower row) and Player~2 is to move.  The remaining set of squares will be of the form of a rectangle (if Player~2\nplays the lower row) or a rectangle with a set of additional squares on the\nlower row.  In either case, Player~1 can recreate the state to be a rectangle and one additional square, i.e., Player~1 can force a win.\nBy playing $(1,n-1)$ as his initial move, Player~1 can create this situation and therefore force a move.\n\n\n\\ans{chomp-3}\nSuppose Player~2 has a winning strategy. Suppose Player~1 chose $(n-1,m-1)$ as\nhis initial choice and Player~2 countered with position $(i,j)$, leaving the set $S$ of squares.\nNow, it is Player~1's turn and from this set, by hypothesis, Player~2 can force a win.  However Player~1 could have chosen $(i,j)$ as his initial\nmove and the set of remaining squares would be $S$ (since the square $(n-1,m-1)$ is above and to the right of all\nother squares) with Player~2's turn.\n\nThis contradicts the hypothesis that Player~2 has a winning strategy; therefore Player~1 must have a winning strategy.\n\nNote that this does not give an explicit strategy as we did for\nProblem~\\ref{chomp-1} and Problem~\\ref{chomp-2}.\n\n\\ans{coins-1}\nNumber the coins from 1--50.\nPlayer $F$ can choose all the even-numbered coins by first picking Coin~50 and then always picking the odd number coin at one of the two ends. For example, if Player $G$ chooses Coin~1, then in the next turn, Player $F$ chooses Coin~2. If Player $G$ chooses Coin~49, then $F$ chooses Coin~48 in the next turn. In this fashion, $F$ can always leave an arrangement where $G$ can only choose from odd-numbered coins.\n\nIf the value of the coins at even indices is larger that of the coins at odd indices,\n$F$ can win by selecting the even indices and vice versa.  If the values\nare the same, he can simply choose either and in each case, he cannot lose.\n\n\n\n\\ans{coins-2}\nThe problem can be solved using dynamic programming.\n\n% When Player 1 is to move, the board consists of coins in the range \n% $[2k+1,2l]$ and when Player 2 is to move, the coins are in the range\n% $[2m,2n+1]$.\n\nLet $P(m,n)$ be the largest margin of victory that\na player can achieve when the coins remaining are indexed by $m$ to $n$, inclusive.\n\nThe function $P$ satisfies the following:\n\\ifthenelse{\\boolean{createspace}}{\n\\begin{eqnarray*}\nP(m,n) & = & \\max\\Big(C[n] - P(n+1,m),C[m] - P(n,m -1)\\Big) \\; \\mbox{if} \\; n > m \\\\\nP(m,m) & = & C[m] \\; \\mbox{if} \\; n = m.\n\\end{eqnarray*}\n}\n{\n\\begin{eqnarray*}\n\\lefteqn{P(m,n)  = } \\\\\n& & \\max\\Big(C[n] - P(n+1,m), \\\\\n& & C[m] - P(n,m -1)\\Big), \\; \\mbox{if} \\; n > m \\\\\n\\lefteqn{P(m,m)  =  } \\\\\n& & C[m], \\; \\mbox{if} \\; n = m.\n\\end{eqnarray*}\n}\n\nIn the general case, we can compute $P$ for $n$ coins by\ndynamic programming---there are $n(n+1)/2$ possible arguments for $P$\nand the work required to compute $P$ from previously computed values is constant. Hence $P$ can be computed in $O(n^2)$ time.\n\n\\ans{hiker}\nThe easiest way to prove this is to imagine another man (call him Bob) \ndescending the mountain on Saturday, in exactly the same fashion\nas Adam did on Sunday.  When ascending on Saturday,\nAdam will pass Bob at some time and place---this is the time and place which Adam\nwill be at on Sunday.\n\n\n\n\\chapter{ Probability}\n\n\\ans{sampling-1}\nIt is easy to solve this problem when $k=1$---we simply make one call to the random number\ngenerator, take the returned $r$ value mod~$n$. We can swap $A[n-1]$ with $A[r]$.\n\nFor $k>1$, we start by choosing one element at random as above and we now\nrepeat the same process with the $n-1$ element subarray $A[0:n-2]$. Eventually, the random subset\noccupies the slots $A[n-1-k:n-1]$ and the remaining elements are in \nthe first $n-k$ slots. \n\nThe algorithm clearly is in-place. \nTo show that all the subsets are equally likely, we prove something stronger, namely that all permutations of size $k$ are equally likely.\n\nFormally, an $m$-permutation of a set $S$ of cardinality $n$ is a sequence of $m$\nelements of $S$  with no repetitions.\nNote that there are $\\frac{n!}{(n-m)!}$ $k$-permutations. \n\nThe induction hypothesis now is that after iteration $m$, \nthe subarray $A[n-m-k:n-1]$ contains each possible $m$-permutation with probability\n$\\frac{(n-m)!}{n!}$. \n\nFor $m=1$, any element is equally likely to be selected, so the base case holds.\n\nSuppose the inductive hypothesis holds for $m=l$.  Consider $m=l+1$. \nConsider a particular $(l+1)$-permutation, say $\\langle\n\\alpha_1,\\ldots,\\alpha_{l+1}\\rangle$. This consists of a single element\n$\\alpha_1$ followed by the $l$-permutation\n$\\langle\\alpha_2,\\ldots,\\alpha_{l+1}\\rangle$. Let $E_1$ be the event that\n$\\alpha_1$ is selected in iteration $l+1$ and $E_2$ be the event that the first $l$ iterations produced $\\langle \\alpha_2,\\ldots,\\alpha_{l+1}\\rangle$.\nThe probability of $\\langle\\alpha_1,\\ldots,\\alpha_{l+1}\\rangle$ resulting after\niteration $l+1$ is simply $Pr( E_1 \\cap E_2) = Pr( E_1 | E_2) \\cdot Pr( E_2)$.\nBy the inductive hypothesis, the probability of permutation\n$\\langle\\alpha_2,\\ldots,\\alpha_{l+1}\\rangle$ is $\\frac{(n-m)!}{n!}$. The\nprobability $Pr(E_1|E_2) =  \\frac{1}{n-l}$ since the algorithm selects from elements in $0:n-l-1$ with equal probability. Therefore:\n\n\\ifthenelse{\\boolean{createspace}}\n{\n\\[\nPr( E_1 \\cap E_2)  =   Pr( E_2 | E_1) \\cdot Pr( E_1)\n                     =  \\frac{1}{n-l} \\cdot \\frac{( n - l)!}{n!}\n                        = \\frac{1}{\\frac {(n-l-1)!}{n!}} .\n\\]\n}\n{\n\\begin{eqnarray*}\n\\lefteqn{Pr( E_1 \\cap E_2)  } \\\\\n & = & Pr( E_2 | E_1) \\cdot Pr( E_1) \\\\\n & = & \\frac{1}{n-l} \\cdot \\frac{( n - l)!}{n!} \\\\\n & = & \\frac{1}{\\frac {(n-l-1)!}{n!}} .\n\\end{eqnarray*}\n}\n\nThe algorithm generates all random $k$-permutations with equal probability,\nfrom which it follows that all subsets of size $k$ are equally likely.\n\nWe make $k$ calls to the random number generator.  When $k$ is bigger than $\\frac{n}{2}$, \nwe can optimize by computing a subset of $n-k$ elements to remove from the set.\nWhen $k = n-1$, this replaces $n-2$ calls to the random number generator with a single call.\n\n\n\\ans{sampling-2}\nWe store the first $k$ packets. Consequently, we select the $n$-th packet\nto add to our subset with probability $\\frac{k}{n}$. If we do choose it,\nwe select an element uniformly at random to eject from the \nsubset.\n\nTo prove correctness, we use induction on\nthe number of packets that have been read. Specifically,\nthe inductive hypothesis is that all $k$-sized subsets are equally likely after\n$n \\geq k$. \n\nThe number of $k$-size subset is $\\binom{n}{k}$,\nso the probability of  any $k$-size subset is $\\frac{1}{\\binom{n}{k}}$.\n\nFor the base case $n=k$, there is exactly one subset of size $k$\nwhich is what the algorithm has computed.\n\nAssume the inductive hypothesis holds for $n > k$.  Suppose we have\nprocessed the $n+1$-th packet.  The probability\nof a $k$-size subset that does not include the $n+1$-th packet\nis the probability that we had selected that subset after reading\nthe $n$-th iteration and did not select the $n+1$-th packet which is\n\\ifthenelse{\\boolean{createspace}}{\n\\[\n\\frac{1}{\\binom{n}{k}} \\cdot \\left( 1 - \\frac{k}{n+1}\\right) = \n\\frac{k! (n-k)!}{n!} \\cdot \\left( \\frac{n-k+1}{n+1}\\right) = \\frac{k!\\cdot (n-k)!\\cdot (n-k+1)}{n!\\cdot (n+1)} .\n\\]\n}{\n\\begin{eqnarray*}\n\\lefteqn{\\frac{1}{\\binom{n}{k}} \\cdot \\left( 1 - \\frac{k}{n+1}\\right) } \\\\\n & = & \\frac{k! (n-k)!}{n!} \\cdot \\left( \\frac{n-k+1}{n+1}\\right) \\\\\n & = & \\frac{k!\\cdot (n-k)!\\cdot (n-k+1)}{n!\\cdot (n+1)} .\n\\end{eqnarray*}\n}\nThis equals $\\frac{1}{\\binom{n+1}{k}}$.\nSo, the inductive hypothesis holds for subsets excluding the $n+1$ element.\n\nThe probability\nof a $k$-size subset $H$ that includes the $n+1$-th packet $p_{n+1}$\ncan be computed as follows: let $G$ be a $k$-size\nsubset of  the first $n$ packets. The only way we can\nget from $G$ to $H$ is if $G$ contains $H - \\{p_{n+1}\\}$.\nLet $G^\\ast$ be such a subset; let $\\{q\\} = H - \\{p_{n+1}\\}$. \n\nThe probability of going from $G$ to $H$ is the probability\nof selecting $p_{n+1}$ and dropping $q$ that is equal\nto $\\frac{k}{n+1}\\cdot\\frac{1}{k}$. There are $n+1-k$ candidate\nsubsets for $G^\\ast$, each with probability $\\frac{1}{\\binom{n}{k}}$ (by the inductive hypothesis)\nwhich means that the probability of $H$ is given by\n\\ifthenelse{\\boolean{createspace}}{\n\\[\n\\frac{k}{n+1}\\cdot\\frac{1}{k}\\cdot (n+1-k) \\cdot \\frac{1}{\\binom{n}{k}} = \n\\frac{(n+1-k)(n-k)! k!}{(n+1)n!} = \\binom{n+1}{k} ,\n\\]\n}\n{\n\\begin{eqnarray*}\n\\lefteqn{\\frac{k}{n+1}\\cdot\\frac{1}{k}\\cdot (n+1-k) \\cdot \\frac{1}{\\binom{n}{k}} = } \\\\\n & & \\frac{(n+1-k)(n-k)! k!}{(n+1)n!} = \\binom{n+1}{k} ,\n \\end{eqnarray*}\n}\nso induction goes through for subsets including the $n+1$-th element.\n\n\\begin{comment}\nThe algorithm is clearly correct for sequences of length $k$ or less.\nTo prove the algorithm is correct we use induction, starting from\nsequences of length greater than or equal to $k+1$. \n\nFor the base case, namely $n=k+1$, the probability of element $k+1$ being in\nthe set is $\\frac{k}{k+1}$, which is clearly correct. The probability of\none of the first $k$ elements remaining in the set is $1-\\frac{1}{k+1} = \\frac{k}{k+1}$,\nso the base case holds.\n\nSuppose the sampling is correct for $n=l$. We now compute the probability that\nan element is in the sampled set after element $l+1$ is considered.\nThe probability that element $l+1$ is added is exactly $\\frac{k}{l+1}$, which \nis the desired probability.  The probability that element $k\\leq l$ is in the\nset after considering the element $l+1$ is the probability that\nit was in the sampled set at iteration $l$ (which by induction is $\\frac{k}{l+1}$), \nand that it was not ejected at iteration $l+1$. \nThe probability of any element $i$ in the sampled\nset being ejected at iteration $l+1$ is the probability of element $l+1$ being\nselected times the probability that $i$ was chosen from the $k$ elements in\nthe sampled set to eject.\nThis is simply $\\frac{k}{l+1}\\cdot \\frac{1}{k} =  \\frac{1}{l+1}$.\nHence the probability of an element being present after step $l+1$ is\n$\\frac{k}{l}\\cdot(1-\\frac{1}{l+1}) = \\frac{k}{l}\\cdot\\frac{l}{l+1}= \\frac{k}{l+1}$ \nso induction goes through.\n\\end{comment}\n\n\\ans{sampling-3}\nWe can make use of the algorithm for \nproblem~\\ref{sampling-1} with the array $A$ initialized by $A[i] = i$.\nWe do not actually need to store the elements in $A$, all we need to do is store\nthe elements as we select them, so the storage requirement is met.\n\n\\ans{perm-1}\nThe process does not yield all permutations with equal probability. One way to \nsee this is to consider the case $n=3$.  There are $3! = 6$ permutations possible. \nThere are a total of $3^3 = 27$ ways in \nwhich we can choose the elements to swap and they are all\nequally likely. Since 27 is not divisible by 6, some\npermutations correspond to more ways than others, ergo not all permutations\nare equally likely.\n\nThe process can be fixed by selecting elements at random and \nmoving them to the end, similar to how we proceeded in Problems~\\ref{sampling-1}\nand~\\ref{sampling-3}.\n\n\\ans{perm-2}\nOur solution to Problem~\\ref{sampling-1} can be used with \n$k=n$.  Although the subset that is returned is unique (it will be $\\{0,1,\\ldots,n-1\\}$),\nall $n!$ possible orderings of the elements in the set occur with equal\nprobability. (Note that we cannot use the trick to reduce the number of calls\nto the random number generator at the end of Solution~\\ref{sampling-1}.)\n\n\\ans{triangle}\nThe first thing to note is that three segments can make a triangle iff\nno one segment is longer than the sum of the other two:\nthe ``only if'' follows from the triangle inequality and the ``if''\nfollows from a construction---take a segment and draw circles at the\nendpoints\n with radius equal to the lengths of the other circles.\n\nSince the three segment lengths add up to 1, \nthere is a segment that is longer than the sum of the other two iff\nthere is a segment that is longer than $\\frac{1}{2}$. \n\nLet $l = \\min{(u1,u2)}$, \n$m = \\max{(u1,u2)} - \\min{(u1,u2)}$, and $ u = 1 - \\max{(u1,u2)}$;\nthese are the lengths of the first, second, and third segments,\nfrom left to right.\nIf one segment is longer than 0.5, then none of the others\ncan be longer than 0.5; so, the events $l > 0.5$,\n$m > 0.5$, and $u > 0.5$ are disjoint.\n\nObserve that $l > 0.5$ iff both $u1$ and $u2$ are greater than 0.5;\nthe probability of this event is $\\frac{1}{2} \\times \\frac{1}{2}$ because $u1$ and $u2$ are chosen independently.\nSimilarly $m > 0.5$ iff both $u1$ and $u2$ are less than 0.5, which is $\\frac{1}{2} \\times \\frac{1}{2}$.\n\nTo compute the probability of $m > 0.5$, first we consider the case\nthat $u1 < u2$. For $m > 0.5$, we need $u1$ to be between 0 and $1$ and $u2$ to be between $0.5 + u1$ and $1$. This probability can\nbe expressed by the integral\n\\[\n\\int_{u1=0}^{0.5} \\int_{u2=u1+0.5}^{1} 1 \\cdot du1 \\cdot du2  \n\\]\nwhich evaluates to $\\frac{1}{8}$.\n\nBy symmetry, the probability of $m > 0.5$ when $u1 > u2$ is also $\\frac{1}{8}$.\nHence the probability of a segment being longer than $\\frac{1}{2}$ \nis $\\frac{1}{4} + \\frac{1}{4} + \\frac{1}{4} = \\frac{3}{4}$.\nSo, the probability of being able to make a triangle out of the segments\nis $1 - \\frac{3}{4} = \\frac{1}{4}$.\n\nFor the second case, we fail to be able to make a triangle\nin case $u1 > 0.5$, $u2 - u1 > 0.5$, or $1-u2 > 0.5$. The first\nprobability is simply $\\frac{1}{2}$.\n\nThe second probability is given by the integral\n\\[\n\\int _{u1=0}^{0.5} \\int_{u2=u1+0.5}^{1} \\frac{1}{(1-u1)} \\cdot du2 \\cdot du1 .\n\\]\nNote that the probability density function for $u2$ is different from the previous\ncase since $u2$ is uniform in $[u1,1]$, not $[0,1]$.\nThis integral evaluates to $\\frac{1 + \\log_e{\\frac{1}{2}}}{2}$.\nThe third probability can also be computed using an integral but by symmetry,\nit must be the same as the second probability.\nHence the final probability is $\\frac{1}{2} + 2 \\cdot \\frac{1 + \\log_e{\\frac{1}{2}}}{2} \\approx 0.807$.\n\nIntuitively, the second formulation leads to a higher probability of a long line segment\nbecause there is less diversity in the points. For the first case, the points are spread\nrandomly; for the second, there is a 0.5 chance that the first point itself precludes\nus from building the triangle.  Another way to think of it is that if we put down a lot of points, the first method will lead to short segments with little variation in lengths but the second method will give us a skewed distribution and the first few segments will be considerably longer.\n\nThese computations can be verified by a numerical simulation. Here is an example code to perform this:\n\\lstinputlisting[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Java]{triangle.java}\n\n\\ans{balls-bins}\nThe probability that a given ball does not land up in a given bin is\n$(n-1)/n$. The probability that none of the balls land up in the bin\nis $\\left(\\frac{n-1}{n}\\right)^m$.  Hence the expected number of empty\nbins can be given as $n\\left(\\frac{n-1}{n}\\right)^m$. Note that this\ncan be closely approximated by $n\\cdot e^{m/n}$. Hence as long as on\nan average, each server is handling significantly more than one\nclient, there should be very few idle servers.\n\n\\ans{random-permutation}\nLet $X_i$ be the random variable, which is $1$ if $\\sigma(i) = i$\nand $0$ otherwise. (Such a random variable is often referred to as an ``indicator random variable''.) The number of fixed points is equal to $X_1 + X_2 + \\cdots + X_n$. Expectation is linear, i.e., the expected value \nof a sum of random variables is equal to the sum\nof the expected values of the individual random variables. The\nexpected value of $X_i$ is $0 \\cdot \\frac{n-1}{n} + 1 \\cdot \\frac{1}{n}$ (since\nan element is equally likely to be mapped to any other element).\nTherefore the expected number of fixed points is $n \\cdot \\frac{1}{n} = 1$.\n\nWe can compute the expected length of $\\mu$ by defining\nindicator random variables $Y_1,\\ldots Y_n$, where $Y_i = 1$ iff\n$\\forall j < i \\; \\big(\\sigma(j) < \\sigma(i)\\big)$.\nObserve that the length of $\\mu$ is simply the sum of the $Y_i$s.\nThe expected value of $Y_i$ is $\\frac{1}{i}$, since $\\forall j < i \\; \\big(\\sigma(j) < \\sigma(i)\\big)$\niff the largest of the first $i$ elements is at position $i$, which\nhas probability $\\frac{1}{i}$ since all the permutations are equally likely.\nTherefore the expected value for the length of $\\mu$ is $1 + \\frac{1}{2} + \\frac{1}{3} + \\cdots + \\frac{1}{n}$, which tends to $\\log_e n$.\n\nNote that for both parts of the problem, we used the linearity\nof expectation which does not require the individual random variables\nto be independent.  This is crucial since the $X_i$s and $Y_j$s\nare not independent---for example, if the first $n-1$ elements get mapped\nto themselves, then the $n$-th element must also map to itself.\n\n\\begin{comment}\n\nIan's solution (INCORRECT)\n\nDoes the following process yield a uniformly random permutation of $A$? \n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true]\nFor i = 1::n swap A[i] with a randomly chosen element of A. \n  (The randomly chosen element could be i itself.)\n\\end{lstlisting}\n\n\nMy first guess would be that it would (assuming it's a 1-based array); at each turn, the \nprobability that any given value $j$ will be selected as the right-hand side of the swap is \n1/n; earlier values in the array have the same chance of being permuted at each stage as \nlater values do. Each array slot is visited once in order, so every element will be \npermuted an average of 2 times, and in both cases the previous swaps have no impact on \nwhere it will be swapped to.\n\nHere's a Python implementation of randomly permuting an array:\n\n\\begin{verbatim}\nimport random\n \ndef Permute(A):\n    for i in range(len(A)):\n        j = random.randint(0, len(A) - 1)\n        temp = A[i]\n        A[i] = A[j]\n        A[j] = temp\n    return A\n\\end{verbatim}\n\nTo test whether there appears to be any skew in the resulting values, \nthis routine uses repeated random permutations and computes an \naverage of the resulting values:\n\n\\begin{verbatim}\ndef TestSkew(trials, size):\n    # loop over permuting the same array; sum and then get average at the end\n    A = range(size)\n    random.shuffle(A)\n    B = A[:]\n    for i in range(trials):\n        A = Permute(A)\n        # update the summed values in B\n        for j in range(len(B)):\n            B[j] = B[j] + A[j]\n    for k in range(len(B)):\n        B[k] = B[k] / trials\n    return B\n\\end{verbatim}\n\nThe result of permuting a 100 item array 5000 times is:\n\n\\begin{verbatim}\nTestSkew(5000, 100) = \n[49, 49, 48, 49, 49, 49, 50, 49, 49, 49, 48, 49, 50, 49, 49, 49, 48, 49, 49, 49, 48, \n 49, 49, 49, 49, 49, 49, 49, 49, 50, 49, 49, 48, 49, 49, 49, 49, 49, 49, 49, 49, 50, \n 48, 49, 49, 49, 49, 49, 48, 49, 50, 49, 49, 49, 49, 49, 48, 49, 49, 49, 49, 49, 49, \n 50, 49, 49, 48, 50, 49, 49, 49, 50, 49, 51, 49, 50, 49, 50, 48, 49, 49, 48, 49, 49, \n 49, 49, 50, 49, 49, 49, 49, 49, 49, 49, 49, 50, 49, 49, 49, 48]\n\\end{verbatim}\n\nThere does not appear to be much skew - the median \nvalue of 49 (the range is 0 to 99) is in almost every slot, and \nthere doesn't appear to be a pattern that I can discern in the numbers, \nother than it being a uniform distribution.\n\\end{comment}\n\n\n\\ans{rand-1}\nBasically, we want to produce a random number between $0$ and $b-a$, inclusive.\n\nWe can produce a random number from $0$ to $l-1$ as follows: let $j$ be the least\ninteger such that $l\\leq 2^j$. \n\nIf $l$ is a power of 2, say $l=2^j$, then all we need are $j$ calls to the 0-1 valued\nrandom number generator---the $j$ bits from the calls encode a $j$ bit integer\nfrom $0$ to $l-1$, inclusive and all such numbers are equally likely;\nso, we can use this integer.\n\nIf $l$ is not a power of 2, the $j$ calls may or may not encode an integer in the range\n$0$ to $l-1$. If the number is in the range, we return it; since all the numbers\nare equally likely, the result is correct. \n\nIf the number is not in the range, we try again. The probability of having to try again\nis less than $\\frac{1}{2}$ since $l > 2^{j-1}$. \nThe probability that we take exactly $k$ steps before succeeding\nis at least $(1 - \\frac{1}{2})^{k-1}\\cdot \\frac{1}{2} = \\frac{1}{2}^k$.\nThe expected number of trials\nbefore we converge to a solution is bounded by $1\\cdot\\frac{1}{2} + 2\\cdot(\\frac{1}{2})^2 + \n(\\frac{1}{2})^3 + \\cdots $ whose limit is 2.\n\n\\ans{hist-1}\nLet $F_X(x)$ be the cumulative distribution function for $X$, \ni.e., $F_X(x) = \\mbox{probability that } X \\leq x$.  \n\nTo generate $X$, we perform the following operation: we select a number $r$ uniformly\nat random in the unit interval. We then project back from $F_X$ to obtain a value\nfor $X$, i.e., we return $s = F_X^{-1}(r)$. \n\nBy construction, the probability that the value we return is less than or equal to $\\alpha$ is\n$F_X(\\alpha)$, so the cumulative distribution function of the random variable we\ncreated is exactly that of $X$. \n\n\\ans{dice-completion}\nFirst we prove that if $\\langle X_1, X_2,\\ldots \\rangle$ is a sequence of Bernoulli IID random variables, with $p(X_i = 1) = p$,\nthen the expected time to see the first $1$ is $\\frac{1}{p}$. The reasoning is as follows: define $F_i$ to\nbe the event that the first $1$ comes on the $i$-th trial. Then $Pr(F_i) = (1-p)^{i-1} \\cdot p$.\nHence the expected time is $S = \\sum_{i=1} i \\cdot  (1-p)^{i-1} \\cdot p$. This sum simplifies to $\\frac{1}{p}$ (multiply\nboth sides by $p$, subtract, and sum the infinite geometric series on the right).\n\nNow, we consider the problem of dice rolls. The key is to determine the expected time to see the\n$k$-th new value. Clearly, the expected time to see the first new value is just $1$. The time to see\nthe second new value from the first new value is $\\frac{1}{5/6}$ since the probability of\nseeing a new value, given that one value has already been seen, is $5/6$. In this way, the time\ntaken to see the third new value, given that two values have already been seen, is $\\frac{1}{4/6}$.\nGeneralizing this idea, the time taken to see the $k$-th new value, given that $k-1$ values have already been seen, is $\\frac{1}{(6- (k-1)) /6}$.\n\nHence the expected time to see the sixth new value is $\\frac{6}{6} + \\frac{6}{5} + \\frac{6}{4} + \\frac{6}{3} + \\frac{6}{2} + \\frac{6}{1}\n\\approx 14.7$.\n\n\n\\ans{option-pricing-2}\nLet $f$ be the price for the option.\nA fair price is determined by the no-arbitrage requirement. \nSuppose we start with a portfolio of $x$ shares  \nand $y$ options in $S$---$x$ and $y$ may be \nnegative (which indicates that we sell stocks or sell options).\n\nThe initial value of our portfolio is $x\\cdot 100 +y\\cdot f$. \nOn Day 100, two things may have happened:\n\\begin{itemize} \n\\item The stock went up and the portfolio is worth $x\\cdot 120 + y\\cdot 20$.\n\\item The stock went down and the portfolio is worth  $x\\cdot 70$.\n\\end{itemize} \nIf we could choose $x$ and $y$ in such a way that our initial portfolio\nhas a negative value---which means that we are paid to take it on---and\nregardless of the movement in the stock, our portfolio takes a \nnonnegative value, then we will have created an arbitrage.\n\nTherefore the conditions for an arbitrage to exist are:\n\\begin{eqnarray*}\nx\\cdot 120 + y\\cdot 20 & \\geq & 0 \\\\\nx\\cdot 70 & \\geq & 0 \\\\\nx\\cdot 100 + y \\cdot f  & < & 0 \n\\end{eqnarray*}\nA fair price for the option is one in which no arbitrage exists.\n% The second equation implies that $x\\geq 0$\n\nIf $f$ is less than $0$, an arbitrage exists---we are paid to buy options,\nlose nothing if the price goes down, and make \\$20 per option\nif the price goes up. Therefore $f \\geq 0$, so we can write the third\ninequality as $y \\leq -\\frac{100}{f} x$.\nThe first equation can be rewritten as $y \\geq -6\\cdot x$.\n\nCombining these two inequalities, we see that an arbitrage does not exist\nif $-\\frac{100}{f} \\geq -6$, i.e., $f \\leq \\frac{100}{6}$. Outside of the\ninterval $[0,\\frac{100}{6}]$, we do have an arbitrage.\n\nFor example, if $f=19 > \\frac{100}{6}$, then the option is overpriced and \nwe should sell (``write'') options.  If we write $b$ options and buy one share,\nwe will start with a portfolio that is worth  $100 + 19\\cdot b$.\nIf the stock goes down, the options are worthless; so, our portfolio\nis worth $\\$70$. If the stock goes up, we lose $\\$20$ on \neach option we wrote but see a gain on the stock we bought. We want\nthe net gain to be nonnegative and the initial\nportfolio to have a negative value, i.e., \n\\begin{eqnarray*}\n120 + 20 \\cdot b & \\geq & 0 \\\\\n100 + 19 \\cdot b  & < & 0\n\\end{eqnarray*}\nCombining the two inequalities, we see that any value of $b$ in $[-6,-\\frac{100}{19})$\nleads to an arbitrage.\n\n\\ans{option-pricing-3}\nSuppose our initial portfolio consists of $x_0$ stocks, $x_1$ options, and $x_2$\nbonds.\n\nProceeding as above, we see the condition for an arbitrage to exist\nis:\n\\begin{eqnarray*}\n100 \\cdot x_0 + f \\cdot x_1 + x_2 & < & 0 \\\\\n120 \\cdot x_0 + 20 \\cdot x_1 + 1.02 \\cdot x_2 \\geq 0 \\\\\n70 \\cdot x_0 + 1.02 \\cdot x_2 \\geq 0 \n\\end{eqnarray*}\nWriting the linear terms as $Ax$, we see that \nif $det(A) \\neq 0$, then we can always find an arbitrage since we\ncan solve $Ax = b$. We will denote row~$i$ of $A$ by $A_i$.\n\nThe determinant of $A$ equals $70(1.02f - 20) + 1.02(100\\cdot20 - 120f)$.\nThis equals $0$ when $f = 640/51 \\approx 12.549 = f^\\ast$, so an arbitrage\ndefinitely exists if the option price is not equal to $f^\\ast$.\n\nConversely, if the option is priced at $f^\\ast$, $det(A) = 0$ and\nin particular $A_0 = 0.6275 \\cdot A_1 + 0.3583 \\cdot A_2$.\nSince $A_0$ is a linear combination of \n$A_1$ and $A_2$ with positive weights, then\nif $A_1 x\\geq 0$ and $A_2 x \\geq 0$, $A_0x$ must also be $\\geq 0$, so\nno arbitrage can exist.\n\n\\ans{option-pricing-1}\nLet $x$ be the price of the stock on day 100. The option is worthless if $x < 300$.  \nIf the price is $x \\geq 300$, the option is worth $x -300$ dollars.\nThe expected value of $x$ is given by the integral\n\\[\n\\int_{300}^{\\infty} (x-300) \\cdot \\frac{e^{-\\frac{(x-300)^2}{2\\cdot (20)^2}}}{\\sqrt{2 \\pi (20)^2}} dx .\n\\]\n\n% expectation of half normal is \\sigma \\sqrt{2/\\pi} ->  for just the positive side it is half\n% of this i.e., \\sigma \\sqrt{1/(2 \\pi)}\n\nThe integral can be evaluated in closed form---let $y = x -300$ and\nlet's write $\\sigma$ instead of $20$.\nThe expression above simplifies to\n\\[\n\\int_{0}^{\\infty} y \\cdot \\frac{e^{-\\frac{y^2}{2\\cdot \\sigma^2}}}{\\sqrt{2 \\pi \\sigma^2}} dy .\n\\]\nThe indefinite integral $\\int w\\cdot e^{-w^2} dw$ has the closed form solution $-\\frac{e^{-w^2}}{2}$, so the \ndefinite integral equals $\\sigma \\sqrt{\\frac{1}{2 \\pi}} \\approx 0.39 \\sigma$.\nTherefore the expected payoff on the option on day 100 is $0.39 \\cdot 20 =\n\\$7.8$.\n\n\\ans{optimum-bidding}\nThe first thing to ask is what are you trying to optimize? There\nare various objectives, all of which are reasonable---maximize expected\nprofit, minimize loss, maximize ratio of expected profit to variance, etc.\n\nLet's say we want to maximize profit. The expected profit is\n$\\int_{X = B }^{X=400} ( 1.8 X - B)\\cdot \\frac{1}{400} dB$.\nThis simplifies to $\\frac{0.9 \\cdot 400^2 - 400 B + 0.1 B^2}{400}$.\nThe derivative is $0.2B - 400$. \n\nThe expected profit has a negative derivative in the range of interest---$B \\in [0,400]$.\nThis means that as we increase $B$, we get less and less profit, so we should keep $B=0$.\n\nIn retrospect, this result makes sense since if we win the auction, we are\npaying twice of $X$ in expectation and getting only $1.8X$ in return.\n\n\n\\ans{once-or-twice}\nIf the probability of winning is $p$, then the expected gain is $-1\n+ p\\cdot w$. Hence for a fair game, $w = 1/p$. \n\nThe face value of the card can be any number between $1$ and $13$. For the dealer, all values are equally likely. Hence if the\nplayer's card has a face value $i$, then the probability of winning for\nthe player is $(i-1)/13$. If the player always takes only one random card,\nhis probability of winning is $(1/13)\\sum_{i=1}^{13}{(i-1)/13} =\n6/13$. Hence it makes sense to ask for the next card only if the first\ncard yields a probability less than $6/13$, i.e., the face value of the first\ncard is $7$. If we are given that the face value of the first card is $7$ or \nmore, then the chances of winning are $(1/7)\\sum_{i=7}^{13}{(i-1)/13} = 9/13$; otherwise, it is $6/13$. Hence the \noverall probability of winning is  \n$\\frac{7}{13}\\cdot\\frac{9}{13} + \\frac{6}{13}\\cdot\\frac{6}{13} = 99/169$.\nThus the fair value would be $169/99 \\approx 1.707$.\n\n\\begin{comment}\n\nClearly, the optimum strategy of each player is independent of each other\nsince they do not learn any thing new about the other player's\nmoves. By symmetry, we can argue that the best chances of winning is\ngoing to be $1/2$. We can prove this by contradiction---if there\nexists a strategy that results in your chances of winning against a\nrational adversary being greater than $1/2$ then the rational\nadversary can also use the same strategy and hence the chances of\nwinning cannot be greater than $1/2$.\n\nSuppose  the adversary uses a certain strategy $A$ which results in a\ncertain probability distribution for the adversary.  Suppose that the\nfirst number you get as a player is $c$.  If choose to keep $c$ as the\nfinal number, the probability of winning will monotonically increase\nwith $c$. If you choose to get the second random number, given the\nprobability distribution of the adversarie's number, the probability\nof winning would be certain fixed number. Clearly, there exists a\nnumber $\\hat{c}$ such that if $c < \\hat{c}$ it is better to go for the\nsecond number otherwise it is better to keep the first number.\n\nNow that we have established that the best strategy is to find a\nnumber $\\hat{c}$ such that we choose the second number if and only if\nthe first number is less than $\\hat{c}$, we will try to find the\noptimum value of $\\hat{c}$.  Suppose the probability distribution for the adversary's\nnumber strategy is $A(x)$ then if you use \n\n\n\nLet's say that the random numbers you\nget are $x_1$ and $y_1$ and the numbers that the adversary gets are\n$x_2$ and $y_2$. Suppose you pick the number to be $c_1$\nand the adversary picks the number to be $c_2$. Then the chances of\nwinning is going to be \n\\begin{eqnarray*}\nPr[(x_1 \\ge c_1) \\wedge (x_2 \\ge c_2) \\wedge (x_1 > x_2) ]  &+&\\\\ \n Pr[(x_1 \\ge c_1) \\wedge (x_2 < c_1) \\wedge (x_1 > y_2)]  &+&\\\\\nPr[(x_1 < c_1) \\wedge (x_2 \\ge  c_1) \\wedge (y_1 > x_2)]\n &+&\\\\\nPr[(x_1 < c_1) \\wedge (x_2 <  c_1) \\wedge (y_1 > y_2)]. &&\n\\end{eqnarray*}\n\n\nLet's say  we choose a second number if the first\nnumber we are given is below a threshold, $\\alpha$. \nLet the final number we get be $M$.\nThen the CDF for our choice $M_1$ is given by:\n\\begin{eqnarray*}\nP(M_1 \\leq t ) & = & \\alpha \\cdot t, 0 \\leq t < \\alpha \\\\\nP( M_1 \\leq t ) & = & \\alpha^2 + (t-\\alpha) + \\alpha\\cdot(t -\\alpha) \n\\end{eqnarray*}\nThe first probability comes from the recognition that\nwe need the first number selected to be  less than $\\alpha$ and \nthe second to be less than $t$.\n\nThe second probability comes from writing $P(M_1 \\leq t) = \nP(M_1 \\in [0,\\alpha) \\cup M_1 \\in [\\alpha,t]$ with the\ntwo subevents being disjoint.\n\nDifferentiating the CDF, we see the Probability Distribution Function    (PDF) for $M_1$ is given by \n\\begin{eqnarray*}\np_{M_1}(t) & = & \\alpha, t < \\alpha \\\\\np_{M_1}(t) & = & 1-\\alpha, t \\geq \\alpha\n\\end{eqnarray*}\n\nSuppose we choose $\\alpha_1$ as our threshold and our opponent\nchooses $\\alpha_2$ as his threshold.  Let his final\nnumber be $M_2$. Then the probability that $M_1 > M_2$ can\nbe computed as follows:\n\n\\end{comment}\n\n\n\\ans{red-card}\nWe can trivially achieve a probability of success of $\\frac{1}{2}$ by always choosing the first card.\n\nA natural way to proceed is to consider the probability\n$p_k(f)$ of winning for the optimum strategy after $k$ cards\nremain, of which $f$ are red cards.\nThen $p_k(f) = \\max\\big(\\frac{f}{k}, \n\\frac{f}{k}\\cdot p_{k-1}(f-1) + (1-\\frac{f}{k})\\cdot p_{k-1}(f)\\big)$.  \n\nThe base cases for the recurrence are $p_1(1) = 1$ and $p_1(0) = 0$.\nApplying the recurrence, we obtain $p_2(2) = 1, p_2(1) = \\frac{1}{2},\np_2(0) = 0$, and $p_3(3) = 1, p_3(2) = \\frac{2}{3}, p_3(1) = \\frac{1}{3},\np_3(0) = 0$.  This suggests that $p_k(f) = \\frac{f}{k}$, which\ncan directly be verified from the recurrence. Therefore the best\nwe can do, $p_{52}(26) = \\frac{26}{52} = \\frac{1}{2}$, is no better than simply selecting\nthe first card.\n\nAn alternate view of this is that since the cards in the deck are\nrandomly ordered, the odds of the top card we select being red is the same\nas the card at the bottom of the deck being red, which has a $\\frac{f}{k}$ chance of\nbeing red when there are $f$ red cards and $k$ cards in total.\n\n\n\\ans{secy-problem}\nIf we always select the first secretary, we have a $\\frac{1}{n}$ chance of\nselecting the best secretary.\n\nOne way to do better is to skip the first $\\frac{n}{2}$ secretaries\nand then choose the first one in the remaining set that is superior to\nthe best secretary interviewed in the first $\\frac{n}{2}$ secretaries. This \nhas a probability of succeeding of at least $\\frac{1}{4}$ since \nthe probability that the second best secretary lies in the first half\nand the best secretary is in the second half is at least $\\frac{1}{4}$. Note that the probability of this is actually more than $\\frac{1}{4}$\nsince the second best secretary is in the first half, there is a higher than\n$0.5$ probability that the best secretary is in the second half.\n\nIt is known that if we follow a strategy of skipping the first\n$s$ secretaries and selecting the first secretary who is superior to all others so\nfar, the probability is maximized for $s$ closest to $n/e$ and the maximum probability\ntends to  $1/e$.\n\n\\ans{which-coin}\nLet $L$ be the event that the selected coin is tail-biased, $U$ be the\nevent that the selected coin is head-biased, and $3H5$ be the event\nthat a coin chosen at random from the bag comes up heads $3$ times out of $5$ tosses.\n\nWe want to compute $Pr( L | 3H5)$. By Bayes' rule, this is $\\frac{Pr( L \\cap 3H5) }{Pr(3H5)}$.\nApplying Bayes' rule again, this probability equals\n\\begin{eqnarray*}\n\\lefteqn{\\frac{Pr(3H5|L)\\cdot Pr(L)}{Pr\\big(3H5\\cap(L \\cup U)\\big)}} \\\\\n& = & \\frac{Pr(3H5|L)\\cdot Pr(L)}{Pr(3H5 \\cap L) + Pr(3H5 \\cap U)} \\\\\n& = &  \\frac{Pr(3H5|L)\\cdot Pr(L)}{Pr(3H5|L)\\cdot Pr(L) + Pr(3H5|H)\\cdot Pr(H)} \\\\\n& = & \\frac{\\binom{5}{3}\\cdot0.4^3\\cdot 0.6^2\\cdot 0.5}{\\binom{5}{3}\\cdot0.4^3\\cdot 0.6^2\\cdot 0.5 + \\binom{5}{3}\\cdot0.4^2\\cdot 0.6^3\\cdot 0.5} \\\\\n& = & 0.4\n\\end{eqnarray*}\n\nFor the second part, we can use the Chebyshev inequality to compute the number of trials we need for \na majority of $n$ tosses of the tail-biased coin to be heads with probability $\\frac{1}{100}$.\nLet $L_i$ be the event that the $i$-th toss of the tail-biased coin comes up heads.\nIt will be convenient to use a Bernoulli random variable $X_i$ to encode\nthis event, with a $1$ indicating heads and $0$ indicating tails.\n\nThe mean $\\mu$ of the sum $X$ of \n$n$ Bernoulli random variables which are IID with probability $p$ is\n$n\\cdot p$; the standard deviation $\\sigma$ is $\\sqrt{np(1-p)}$. In our context,\n$\\mu = 0.4n$ and $\\sigma = \\sqrt{6n/25}$.\n\nThe Chebyshev inequality gives us a bound on the probability of a random variable\nbeing far from its mean. Specifically, $Pr\\big( |X - \\mu| \\geq k \\sigma \\big) \\leq \\frac{1}{k^2}$.\n\nFor the majority of $n$ tosses to not be tails, it is necessary that \nthe sum of the $n$ coin tosses is greater than or equal to $0.5n$.\nWe want to bound this probability by $\\frac{1}{100}$, so we take $k=10$. \nWe want to solve for $n$ such that $0.5n -  0.4n \\geq 10 \\cdot \\sqrt{6n/25}$, i.e.,\n$0.1n \\geq 4.9 \\sqrt n$ which is satisfied for $n \\geq 2400$.\nNote that the analysis is not tight---the Chebyshev inequality refers to the probability of $|X - \\mu| \\geq k \\sigma$ but we are only looking at $X - \\mu \\geq \\sigma$.\n\nThe Chebyshev inequality holds for all random variables if they have a variance. We can obtain\na tighter bound by applying a Chernoff bound, which is specific to the sums of Bernoulli random variables.\nSpecifically, Chernoff bounds tell us that $Pr\\big(X \\geq (1+\\delta)\\mu \\big) \\leq e^{\\frac{-\\mu\\delta^2}{3}}$.\nWe want to bound $Pr\\big(X \\geq 0.5n = (1+0.25)(0.4n)\\big)$, so\n$\\delta = 0.25$. Thus we want\n$e^{\\frac{-0.4n (0.25)^2}{3}} < 0.01$; taking natural logs we obtain $-\\frac{0.4n (0.25)^2}{3} < \\ln{100} = -4.6$, which holds for $n > 552$.\n\nThe Chernoff bound is also pessimistic---through simulation code attached below,\nwe determined that when $n=553$, only $17$ times in $10^7$ trials did we\nsee a majority of tails; when $n=148$, tails was not a majority in $0.88$\\% \nof the trials. \n\\lstinputlisting[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=Java]{TailCoin.java}\n\n\n\\ans{rand-complexity}\nFirst, we show that any deterministic algorithm must examine all\nBoolean variables. \nThe idea is that an adversary can force the value of any subexpression\nto be unknown till all the variables in the subexpression have been read.\nFor example, suppose variable $X$ is ANDed with variable $Y$.\nIf the algorithm reads the value of $X$ before $Y$,\nwe return true; when $Y$ is queried, we return false.\nIn this way, the value of $X\\wedge Y$ is determined\nonly after both the variables are read. \n\nThis generalizes with induction: the inductive hypothesis is that\nan $L_k$ expression requires all the variables to have been read\nbefore its value is determined and its final value is the \nvalue of the last variable read.\nFor a subexpression of the form $\\phi \\wedge \\psi$, where $\\phi$ and\n$\\psi$ are $L_k$ expressions, if all the variables from $\\phi$\nare read before all the variables from $\\psi$ are read, the adversary\nchooses the last variable read from $\\phi$ to be true, forcing\nthe algorithm to evaluate $\\psi$. A similar argument can be used\nfor subexpressions of the form $\\phi \\vee \\psi$.\n\nSuppose we evaluate an expression by choosing \none of its two subexpressions at random to evaluate first;\nwe evaluate the other subexpression only if the expression's value\nis not forced by the subexpression that we evaluated first.\n\nFor example, if we are to evaluate an $L_{k+1}$ expression of the form\n$\\big((\\phi_0 \\wedge \\phi_1) \\vee (\\psi_0 \\wedge \\psi_1)\\big)$,\nwhere the subexpressions $\\phi_0,\\phi_1,\\psi_0,\\psi_1$ are $L_k$ expressions, we\nrandomly choose one of $(\\phi_0\\wedge\\phi_1)$ and $(\\psi_0 \\wedge \\psi_1)$ \nto evaluate first.  If the first expression evaluated is true, we can ignore the\nsecond; otherwise, we evaluate the second. \nIf the first expression is true, we reduced the number of variables queried\nby at least half. If the first expression is false, at least\none of the two subexpressions is false and we have a probability of $0.5$\nof selecting that subexpression and avoiding evaluating the other subexpression.\nSo, in the worst-case, we can expect to avoid one of the four\nsubexpressions $\\phi_0,\\phi_1,\\psi_0,\\psi_1$. Therefore the expected \nnumber of variables queried to evaluate an $L_{k+1}$ expression, $Q(k+1)$ satisfies \n\\[\nQ(k+1) \\leq 3 \\cdot Q(k) .\n\\]\nFrom this, $Q(k) = 3^k$. It is straightforward to use induction\nto show that there are a total of $n = 4^k$ variables in an $L_k$ expression, so \n$Q(k) = n^{\\log_4 3} = n^{0.793}$.\n\n\n\n\\chapter{ Programming}\n\\lstset{language=C++}\n\n\\ans{parity}\nThe fastest algorithm for manipulating bits can vary based on the underlying hardware. \n\nThe time taken to directly compute the parity of a single number is proportional\nto the number of bits:\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nshort parity(long a) {\n  short result = 0;\n  for (; a != 0; a = a / 2) {\n    result = result ^ (a & 1);\n  }\n  return result;\n}\n\\end{lstlisting}\n\nA neat trick that erases the least significant bit of a number\nin a single operation can be used to improve performance in the\nbest and average cases:\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nshort parity2(long a) {\n  short result = 0;\n  while (a) {\n    result ^= 1;\n    a = a & (a - 1);\n  }\n  return result;\n}\n\\end{lstlisting}\n\nBut when you have to perform a large number of parity operations and more generally,\nany kind of bit fiddling operation, the best way to do this is to precompute the\nanswer and store it in an array.\nDepending upon how much memory is at your disposal (and how much fits \nefficiently in cache), you can vary the size of the lookup table. Below is an example\nimplementation where you build a lookup table ``precomputed\\_parity''\nthat stores the parity of any $16$-bit number $i$ as\n$precomputed\\_parity[i]$. This array can either be constructed during\nstatic initialization or dynamically---a flag bit can be used\nto indicate if the entry at a location is uninitialized.\nOnce you have this array, you can implement the parity function as follows:\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nshort parity3(long a) {\n  short result = precomputed_parity[a >>16];\n  result ^= precomputed_parity[a & 0xFFFF];\n  return result;\n}\n\\end{lstlisting}\n\n\n\\ans{rev-bits}\nSimilar to computing parity (cf.~Problem~\\ref{parity}), the fastest way \nto reverse bits would be to build a precomputed array \\texttt{precomputed\\_reverse}\nsuch that for every $16$-bit number $i$,  \\texttt{precomputed\\_reverse[i]} holds the bit-reversed~$i$.\nThen you can do something like this:\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nlong reverse_bits(long l) {\n  return (precomputed_reverse[l & 0xFFFF] << 16) |\n    precomputed_reverse[l >> 16] ;\n}\n\\end{lstlisting}\n \n\\ans{run-length-encoding}\nAgain, here precomputed arrays can speed things significantly.\nFor all possible 256 values of a byte, we can store the corresponding\nrun-length encoded values.  One tricky thing here is that a particular\nsequence of identical consecutive bits may cross the byte boundary  and you may need to combine the results\nacross the byte boundaries. This just requires some additional logic\nto see if the last bit of the previous byte matches the first bit of the\ncurrent byte or not and accordingly either simply concatenate the\nencoded sequence or add the first number for the current byte to the last\nnumber for the previous byte.\n\n\\ans{perm}\nWe can use the fact that every permutation\ncan be expressed as a composition of disjoint cycles, with\nthe decomposition being unique up to ordering. \n\nFor example, the permutation $(3,1,2,4)$ can be represented as $(1,3,2)(4)$, i.e., we\ncan achieve the permutation $(3,1,2,4)$ by these two moves: $1\\mapsto 3, 3\\mapsto 2, 2\\mapsto 1$ and $4\\mapsto 4$. \n\nIf the permutation was given to us as a set of disjoint cycles, we could easily apply the\npermutation in constant amount of additional storage since we just\nneed to perform rotation by one element. So, what remains is a way\nto identify the disjoint cycles that constitute the permutation. \n\nAgain, it is fairly easy to identify the set of cycles if you have\nan additional $N$ bits: you start from any position and keep going\nforward (from $i$ to $A[i]$)\ntill you hit the initial index, at which point you have found one of the\ncycles.  Then you can go to another position that is not already a part\nof any cycle.  Finding a position that is not already a part of a cycle\nis easy if you have a bit-vector that could indicate whether we\nhave already included a given position in a cycle or not.  \n\nOne way to do this without using additional $O(N)$ storage could be to use\nthe sign bit in the integers that constitute the permutation:\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nvoid ApplyPermutation(int * permutation, int* A, int n) {\n  for (int i = 0; i < n; ++i) {\n    if (permutation[i] > 0) {\n      // Start searching for a cycle from i.\n      int j = i;\n      int tmp = A[i];\n      do {\n        int k = permutation[j];\n        int swap_var = A[k];\n        A[k] = tmp;\n        tmp = swap_var;\n        // Mark j as visited.\n        permutation[j] *= -1; // sets the sign bit\n        j = k;\n      } while(j != i);\n    }\n  }\n  // Restore the sign for permutation.\n  for (int i = 0; i < n; ++i) {\n    permutation[i] *= -1;\n  }\n}\n\\end{lstlisting}\n\nThe above code will apply the permutation in $O(N)$ time but implicitly\nwe are using additional $O(N)$ storage (even if we are borrowing it\nfrom the sign bit of permutation matrix). \nWe need $O(N)$ storage to remember all the visited cycles. \n\nWe can avoid this by just going from\nleft to right and applying the cycle only if the current position is the leftmost position in \nthe cycle. In order to test whether the current\nposition is the leftmost position or not, you will have to traverse the\ncycle once more. This boosts the runtime to $\\Theta(N^2)$.\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nvoid ApplyPermutation2(int * permutation, int* A, int n) {\n  for (int i = 0; i < n; ++i) {\n    // Traverse the cycle to see if i is the min element\n    bool min_element = true;\n    int j = permutation[i];\n    while( j != i) {\n      if (j < i) {\n        min_element = false;\n        break;\n      }\n      j = permutation[j];\n    }\n    if (min_element) {\n      int j = i;\n      int tmp = A[i];\n      do {\n        int k = permutation[j];\n        int swap_var = A[k];\n        A[k] = tmp;\n        tmp = swap_var;\n        j = k;\n      } while(j != i);\n    }\n  }\n}\n\\end{lstlisting}\n\n\\ans{inv-perm}\nThe solution is very similar to the previous problem. All you need to\ndo is decompose the permutation into a set of cycles and invert each\ncycle one step back. For example, the permutation  $3,1,2,4$ can be\nrepresented as $(1,3,2)(4)$.\nHence the inverse can be represented as $(2,3,1)(4)$ which amounts to\n$2,3,1,4$.\n\nIn order to save additional space, we can use exactly the same set of\ntricks as in the above problem.\n\n\\ans{reverse-words}\nIf you try to figure out the position for each character in a single\npass, it becomes fairly complex. If you do this in two stages, it\nbecomes fairly easy. In the first step, invert the entire string and in\nthe second step, invert each word. For example, $ram\\; is\\; costly \\mapsto\nyltsoc\\; si\\; mar \\mapsto costly\\; is\\; ram$. Here is an example code that achieves\nthis:\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nvoid InvertString(char* input, size_t length) {\n  for (int i = 0; i < length /2; ++i) {\n    swap(input + i, input + length - i - 1);\n  }\n}\n\nvoid ReverseWords(char* input) {\n  size_t length = strlen(input);\n  InvertString(input, length);\n  int start = 0;\n  while(start < length) {\n    int end = start;\n    while(end < length && input[end] != ' ') {\n      end++;\n    }\n    InvertString(input+start, end-start);\n    start = end + 1;\n  }\n}\n \\end{lstlisting}\n\n\n\\begin{comment}\nSolution from Ian Varley\n\nInvert all the words in a sentence: ``it was the best of times''\n$\\mapsto$ ``ti saw eht tseb fo semit''\n\nThe solution to this problem differs if we need to do it in-place or not. Assuming we do \nnot, a Python solution is simple:\n\n\\begin{verbatim} \ndef invert(sentence):\n    words = sentence.split()\n    output = []\n    for word in words:\n        output.append(reverse(word))\n    return ' '.join(output)\n \ndef reverse(word):\n    l = list(word)\n    l.reverse()\n    return ''.join(l)\n\\end{verbatim} \n\nSample run:\n\\begin{verbatim} \n>> invert(\"it was the best of times\")\n\nti saw eht tseb fo semit\n\\end{verbatim} \n\nThis algorithm should run in $O(n+m)$ time where $n$ is the number of words and $m$ is the \nnumber of characters. The outer loop does a constant number of operations for each word, \nand the inner loop does a constant number of operations for each letter (assuming \n``reverse'' is implemented in $O(n)$ time).\n\\end{comment}\n\n\\ans{rev-list}\nHere is an example code that reverses a linked list and returns the\nhead pointer for the reversed list. The only\nimportant thing here is that you save the pointer to the next node\nbefore overwriting it.\n%tested\n\\begin{lstlisting}[basicstyle=\\footnotesize,numbers=left,breaklines=true,language=C++]\nNode* ReverseLinkedList(Node* head) {\n  Node* prev = NULL;\n  Node* current = head;\n  while(current != NULL) {\n    Node* tmp = current->next;\n    current->next = prev;\n    prev = current;\n    current = tmp;\n  }\n  return prev;\n}\n\\end{lstlisting}\n\n\\ans{cycle} There are two elegant solutions to this problem. One \nsolution is that you try to reverse the linked list and one of the two things can happen:\n\\begin{enumerate}\n\\itemsep 1pt\n\n\\item You reach the null pointer at the end of the \nlist---this indicates that this was a correctly constructed linked list. \n\\item You reach the head pointer of the list which indicates that the linked list has a loop.\n\\end{enumerate}\n\nOf course this operation is destructive,\ni.e., you modify your input but you can restore the input by\nreversing it again.\n\nAnother interesting approach is to have two pointers traverse the linked\nlist and in every step, you advance the pointers. The first pointer is\nadvanced by one position and the second one is advanced by two\npositions. If you have a correctly constructed linked list, then both\nthe pointers will end up at the tail of the list. However if you have\na circular linked list then you would be in an infinite loop.\nSince the second pointer is traversing the loop twice as fast as the\nfirst, it will often intersect with the first pointer in the loop. If\nyou find the two pointers intersect, this would indicate the list is circular.\n\n\\ans{delete-list}\nThis is more of a trick question than a conceptual one. Given the pointer to a node, it is\nimpossible to delete it from the list without modifying its predecessor's\nnext pointer and the only way to get to the predecessor is to\ntraverse the list from head. However it is easy to delete the\nnext node since it just requires modifying the next pointer of the current\nnode. Now if we copy the value part of the next node to the current node,\nthis would be equivalent to deleting the current node. \n\n(This question used to be commonly asked but it would be poor practice\nto use this solution in real life---for example, a reference \nto the successor of the node that was just deleted is now corrupted.)\n\n\n\\ans{bad-bin-search}\nAt first glance, it would appear that the search function\ndoes a constant amount of work and then recurses on a subarray\nthat is less than half as big as the array passed in---a\nclassic  $O(\\log n)$ algorithm.\n\nHowever the array slicing---the construction of the subarray---is potentially\nexpensive, depending on how it is implemented. \nDifferent languages implement array slicing in different ways: the elements may\nbe aliased to elements in the original array or they may be copied.\nIf a copy is being made, this copy takes $\\Theta(l)$\ntime to compute, where $l$ is the length of the array slide. \nTherefore the recurrence is $T(n) = \\Theta(n) + T(\\frac{n}{2})$,\nwhich solves to $T(n) = \\Theta(n)$.  \n\nThe right way to perform binary search,\nwhich avoids the copy, passes integer indexes denoting the range\nto perform search on (alternately, a while loop can be used to avoid\nrecursion).  See Problem~\\ref{bin-search} for more details.\n", "meta": {"hexsha": "5bfbe2d2ded393eb0e4ceb15a199666775f3d180", "size": 299325, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cpp/solutions.tex", "max_stars_repo_name": "powernit/epicode", "max_stars_repo_head_hexsha": "e81d4387d2ae442d21631dfc958690d424e1d84d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 258, "max_stars_repo_stars_event_min_datetime": "2016-07-18T03:28:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-05T09:08:44.000Z", "max_issues_repo_path": "cpp/solutions.tex", "max_issues_repo_name": "powernit/epicode", "max_issues_repo_head_hexsha": "e81d4387d2ae442d21631dfc958690d424e1d84d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-08-13T22:12:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-25T17:50:11.000Z", "max_forks_repo_path": "cpp/solutions.tex", "max_forks_repo_name": "powernit/epicode", "max_forks_repo_head_hexsha": "e81d4387d2ae442d21631dfc958690d424e1d84d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 154, "max_forks_repo_forks_event_min_datetime": "2016-07-18T06:29:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T18:33:05.000Z", "avg_line_length": 45.1879528986, "max_line_length": 456, "alphanum_fraction": 0.712883989, "num_tokens": 82790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388125473628, "lm_q2_score": 0.8933094124452287, "lm_q1q2_score": 0.7404988435897302}}
{"text": "% Copyright 2018 Melvin Eloy Irizarry-Gelpí\n\\chapter{Reals}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe real numbers are the set of familiar numbers. There are integers, rationals, and irrationals.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Arithmetic Operations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nFor future reference, here you can find the familiar arithmetic operations on real numbers.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Addition}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe addition operation is familiar. If $a$ and $b$ are two real numbers, then the result $c$ of the addition of $a$ and $b$ is also a real number:\n\\begin{equation}\n    c = a + b\n\\end{equation}\nThere is an element $0$ in the reals called zero that does not contribute to the addition:\n\\begin{equation}\n    a = a + 0 = 0 + a\n\\end{equation}\nNote that zero does not have a sign.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Multiplication}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe multiplication operation is also familiar. If $a$ and $b$ are two real numbers, then the result $c$ of the multiplication of $a$ and $b$ is also a real number:\n\\begin{equation}\n    c = a \\wedge b\n\\end{equation}\nThere is an element $1$ in the reals called one that does not contribute to the multiplication:\n\\begin{equation}\n    a = a \\wedge 1 = 1 \\wedge a\n\\end{equation}\nNote that one is positive.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Negation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThere is an element $-1$ in the reals that when multiplied with a real number $a$ gives the negative of $a$:\n\\begin{equation}\n    {-a} = a \\wedge {-1} = {-1} \\wedge a\n\\end{equation}\nNote that one is negative. This operation is a 2-involution.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Conjugation Operations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe conjugation operations on real numbers are trivial, but are needed for Cayley-Dickson construct where they lead to non-trivial conjugations.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Asterisk Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe asterisk conjugate operation on a real number $a$ is itself:\n\\begin{equation}\n    a^{\\ast} = a\n\\end{equation}\nThat is, all real numbers are asterisk-self-conjugate. This operation is trivially a 2-involution.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Quadrance}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe quadrance of a real number $a$ is defined as the product of $a$ and the asterisk conjugate of $a$:\n\\begin{equation}\n    \\Vert a \\Vert^{2} = a^{2} = a \\wedge a^{\\ast} = a^{\\ast} \\wedge a\n\\end{equation}\nNote that the quadrance of any non-zero real number is positive, and that zero is the only real number with zero quadrance.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Cloak Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe cloak conjugate operation on a real number $a$ is equivalent to the negation operation:\n\\begin{equation}\n    a^{\\diamond} = {-a}\n\\end{equation}\nThis operation is a 2-involution.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Dagger Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe dagger conjugate operation on a real number $a$ is itself:\n\\begin{equation}\n    a^{\\dagger} = a\n\\end{equation}\nThat is, all real numbers are dagger-self-conjugate. This operation is trivially a 2-involution.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Hodge Star}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe Hodge star operation on a real number $a$ is itself:\n\\begin{equation}\n    a^{\\star} = a\n\\end{equation}\nThat is, all real numbers are star-self-conjugate. This operation is trivially a 2-involution.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Differential Operators}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nYou can define a real variable $z$ and a \\textbf{Wirtinger} differential operator $\\nabla$ such that\n\\begin{equation}\n    \\nabla \\wedge z = 1\n\\end{equation}\nThat is,\n\\begin{equation}\n    \\nabla = \\frac{\\partial}{\\partial z}\n\\end{equation}\nSince real numbers are asterisk-self-conjugate, the asterisk Wirtinger differential operator $\\nabla^{\\ast}$ is equivalent to $\\nabla$:\n\\begin{equation}\n    \\nabla^{\\ast} = \\nabla\n\\end{equation}\nThe quadrance of the Wirtinger differential operator is the \\textbf{Laplace} differential operator:\n\\begin{equation}\n    \\Vert \\nabla \\Vert^{2} = \\frac{\\partial^{2}}{\\partial z^{2}} = \\nabla \\wedge \\nabla^{\\ast} = \\nabla^{\\ast} \\wedge \\nabla\n\\end{equation}", "meta": {"hexsha": "f254d44edd23a0e15c1c5b6230e5de537e0f952d", "size": 5420, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/A.tex", "max_stars_repo_name": "meirizarrygelpi/pcdc", "max_stars_repo_head_hexsha": "d9f64322a3bc130024c3c8662cc297ba1a16f154", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter/A.tex", "max_issues_repo_name": "meirizarrygelpi/pcdc", "max_issues_repo_head_hexsha": "d9f64322a3bc130024c3c8662cc297ba1a16f154", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter/A.tex", "max_forks_repo_name": "meirizarrygelpi/pcdc", "max_forks_repo_head_hexsha": "d9f64322a3bc130024c3c8662cc297ba1a16f154", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.6213592233, "max_line_length": 163, "alphanum_fraction": 0.4846863469, "num_tokens": 1134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7404983724140548}}
{"text": "\\lab{Algorithms}{Functions and Logic}{Functions and Logic}\n\n\\objective{This section will teach how to build functions. It will also introduce logical statements used in programming.}\n\nUp to this point we have only run scripts. We now introduce a much more powerful and versatile method of problem solving: writing functions.\n\nA function, in the programming sense, is a block of code that accepts input (arguments) and returns output.  When you need a function, you simply define one.  Python functions begin with the keyword \\li{def}, followed by the function name.  Input arguments are listed inside parentheses separated by commas.  Finally the function definition ends with a colon.  In Python, every function returns a value. This value can be explicitly returned using a \\li{return} statement.  If no \\li{return} is defined, the function will always return \\li{None}.  Below is a simple function that returns what it receives\n\\begin{lstlisting}[style=python]\n: def returnInput(x):\n....: return x\n\\end{lstlisting}\n\nNote that all code inside the function is indented.  This is very important in Python.  Any code not indented under the function definition is not part of the function.  To execute a function, you call the function by name and pass input parameters.  Try calling the function and passing different arguments.\n\\begin{lstlisting}[style=python]\n: returnInput(\"This is a string\")\n'This is a string'\n: returnInput(37)\n37\n: returnInput(3**2)\n9\n\\end{lstlisting}\n\nThis function is defined for as long as we have IPython running.  If we happen to close IPython, our function definition will be lost.  To avoid losing our function definitions, we can place them in a Python script file (a *.py file).\n\n\\begin{problem}\nIn a file, functions.py, define functions that will do the following:\n\\begin{itemize}\n\\item Accept anything, but always return the number 42\n\\item Accept two numbers and return their product\n\\item Accepts no arguments and prints ``You called!\"\n\\end{itemize}\n\\end{problem}\n\nRestart IPython.  Now, how do we use our functions defined in functions.py without having to redefine each function inside IPython.  Fortunately, Python allows us to import functions.  Each *.py is really a Python module which can be imported in the same fashion as the SciPy library.\n\\begin{lstlisting}[style=python]\n: import functions\n\\end{lstlisting}\n\nNow our function are accessible as \\li{functions.<function_name>}.  Using the \\li{as} keyword, we can assign an alias to our module.  Let us define a function in \\li{functions.py} that will compute the roots of a quadratic equation.  This function will return a tuple containing multiple values.  Note that before using the \\li{sqrt} function, we have to define it, which we do by importing \\li{sqrt} from Python's \\li{math} library.\n\\begin{lstlisting}[style=python]\nfrom math import sqrt\ndef quadrForm(a,b,c):\n    descr = sqrt(b**2-4*a*c)\n    x1 = (-b+descr)/2.0*a\n    x2 = (-b-descr)/2.0*a\n    return (x1, x2)\n\\end{lstlisting}\n\nThis function takes as inputs the coefficients of a quadratic function and returns the output of the quadratic formula.\n\\begin{lstlisting}[style=python]\n: functions.quadrForm(1,-2,1)\n(1.0, 1.0)\n\\end{lstlisting}\n\nWe note that this function is susceptible to floating point error. For example, try to find the roots of the polynomial $x^2 - (10^7 + 10^-7)x + 1$ using our function:\n\n\\begin{lstlisting}[style=python]\n>> [x1 x2] = quadrForm(1,-(1e7 + 1e-7),1)\n(10000000.0, 9.96515154838562e-08)\n\\end{lstlisting}\n\nClearly the first root is correct, but the second root is clearly in error (admittedly the error is small, but in this case it is easily fixed). The second root shows the error because it is calculated by subtracting two numbers that are very close together.\n\nWe can solve this problem by using slightly different approach. We first calculate the root that is farther from zero using the formula.  Note that we will have to write our own \\li{sign()} function in Python.  The \\li{sign()} function should return $-1.0$ if the input is negative, $0.0$ if the input is zero, or $1.0$ if the input is positive.\n\\[\nx_1 = \\frac{-b - \\text{sign}(b)*\\text{descr}}{2a}\n\\]\nWe can then use a formula known as Viete's formula to calculate the other root (solving for x2).\n\\[\nx_1 x_2 = c/a\n\\]\n\n\\begin{problem}\nWrite a function that implements this second approach to finding the roots. Call it \\li{quadrForm2}.  Note the improved accuracy.\n\\end{problem}\n\n\\section*{Logic, Conditionals and Loops}\nThree basic operators in logic are \\li{and} (\\&), \\li{or} (\\textbar), and \\li{not} (!). We can use relational operators from the~\\ref{tbl:relops} to build logical statements.\n\n\\begin{table}[h!]\n\\begin{center}\n\\begin{tabular}{|c|c|}\n\t\\hline\n\t\\li{==} & equal to\\\\\n        \\li{<} & less than\\\\\n\t\\li{<=} & less than or equal to\\\\\n\t\\li{\\!=} & not equal to\\\\\n\t\\li{>} & greater than\\\\\n\t\\li{>=} & greater than or equal to\\\\\n\t\\hline\n\\end{tabular}\n\\caption{Some relational operators}\n\\label{tbl:relops}\n\\end{center}\n\\end{table}\n\nUsing these building blocks we can build complicated statements. For example, consider a vector $x$ and the statement \\li{(x>1) & (x<10)}.  The statement will evaluate \\li{True} if $x_i$ is between one and ten, and \\li{False} otherwise.  This technique is called \\emph{masking} and is useful for operating only on parts of a vector or an array that meet certain conditions.  Applying the mask to our vector $x$ will yield a boolean vector (a vector with only \\li{True} or \\li{False} values).  We can assign an operation for when we encounter a \\li{True} value.  For example, suppose we want to add $5.5$ to any number that is less than $0.6$ in our vector $x$.  We can do this simply with the following statement:\n\\begin{lstlisting}[style=python]\n: a = sp.rand(10); a\narray([ 0.90492936,  0.42251211,  0.80463372,  0.45087988,  0.94395439,\n        0.11372628,  0.17177908,  0.42053736,  0.94759312,  0.59030686])\n: b = (a<.6); b\narray([False,  True, False,  True, False,  True,  True,  True, False,  True], dtype=bool)\n: a[b]  #the values that correspond to the True values of our mask\narray([ 0.42251211,  0.45087988,  0.11372628,  0.17177908,  0.42053736,\n        0.59030686])\n: a[b] += 5.5; a   # a += 1 is equivalent to a = a + 1. a[b] makes it so that the operation is only applied to values which correspond to a 'True' value in b.\narray([ 0.90492936,  5.92251211,  0.80463372,  5.95087988,  0.94395439,\n        5.61372628,  5.67177908,  5.92053736,  0.94759312,  6.09030686])\n\\end{lstlisting}\n\n\\begin{problem}\nCreate logical statements for the following:\n\\begin{itemize}\n%\\item True if x is prime and less than one-thousand, false otherwise (use the function \\li{isprime}).\n\\item True if $x^2$ is greater than 10 or x is positive and smaller than 2.\n\\item True if the Bessel function of the second kind evaluated at x, with nu = 1, has magnitude greater than 1 (you will need to import \\li{special.yn()}).\n\\end{itemize}\n\\end{problem}\n\n\\begin{problem}\nCreate a function that takes an input vector x and shuffles it like a deck of cards. You may assume that x has even length. The key is to create a mask using some random vector and then assign specific cards to even or odd slots of an output vector using that mask. Then see how many shuffles it takes to make the output $y$ ``random.\" (you can do this by looking at the offdiagonal entry of corrcoef(x,y), which should be close to zero if the output is random).\n\\end{problem}\n\n", "meta": {"hexsha": "78214014e2ee7ab26d3e4b24a2dcc777fbeb8583", "size": 7431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/Functions/Functions.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/Functions/Functions.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/Functions/Functions.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.448, "max_line_length": 713, "alphanum_fraction": 0.7369129323, "num_tokens": 2113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8774767922879693, "lm_q1q2_score": 0.7404983676170869}}
{"text": "% !TeX root = thoughts.tex\n\\section{Recap of probabilistic inversion and Hamiltonian Mechanics}\n\n\\paragraph{Probabilistic inversion and classical sampling}\nIn probabilistic inversion one does not require regularization, in contrast to deterministic inversion. Instead, one explores the model space by quantifying uncertainties and calculating probabilities for any model. In a sense, this can be considered as the `complete' solution. It is defined using Bayes' Theorem as follows;\n\n\\begin{gather}\n\tp(\\mathbf{q}|\\mathbf{d}) = \\frac{p(\\mathbf{d}|\\mathbf{q})\\;p(\\mathbf{q})}{ p(\\mathbf{d})}\n\\end{gather}\nGenerally, we ignore the data evidence ($p(\\mathbf{d})$) as it only provides scaling of the posterior.\n\nIf the prior is normally distributed in model space, we can define it by\n\n\\begin{gather}\n\tp(\\mathbf{q}) = k \\cdot \\exp{\\left( -\\frac{1}{2} \\left[ \\mathbf{q} -\\mathbf{q_0}\\right]^T \\MatrixVariable{C}_M ^{-1}\\left[ \\mathbf{q} -  \\mathbf{q_0}\\right]\\right)}\n\\end{gather}\nwhere $k$ is a scaling constant (i.e. for normalization), $\\mathbf{q_0}$ the mean of the prior distribution and $\\MatrixVariable{C}_M ^{-1}$ the inverse parameter covariance matrix. This inverse parameter covariance matrix is given by\n\\begin{gather}\n\t\\left[ \\MatrixVariable{C}_M^{-1} \\right]_{ij} = r_{ij} \\sigma_i \\sigma_j\n\\end{gather}\nwith $r_{ij}$ the correlation between parameters $q_i$ and $q_j$ and $\\sigma_i$ the standard deviation of parameter $q_i$.\n\nThe prior in data space, $p(\\mathbf{d}|\\mathbf{q}) $, can be seen as the likelihood to see data based on a selected model. This generally incorporates a forward model, measurement uncertainties and forward modeling uncertainties. Because the quantification of forward modeling uncertainties is generally very hard to estimate usually the actual implementation of this is ignored. With only the forward model and measurement uncertainties (normally distributed) the prior in data space is as follows:\n\\begin{gather}\n\tp(\\mathbf{d}|\\mathbf{q}) =  k \\cdot \\exp{\\left( -\\frac{1}{2} \\left[ G\\left(\\mathbf{q}\\right) -\\mathbf{d_0}\\right]^T \\MatrixVariable{C}_D ^{-1}\\left[G\\left(\\mathbf{q}\\right) -  \\mathbf{d_0}\\right]\\right)}\n\\end{gather}\nwith $k$ again a scaling constant, $\\MatrixVariable{C}_D$ the data covariance matrix, $d_0$ the observed data and $G\\left(\\mathbf{q}\\right)$ the forward modeled data based on parameters $q$ and forward model $G$. This forward model $G$ can be any non-linear model, but \\gls{HMC} inversion algorithms are greatly simplified if they are actually linear systems, as will be illustrated later.\n\nWhen these prior data functions are combined one obtains the (improperly scaled) posterior. The negative exponent of the posterior is generally called the misfit and has a special role in many inversions. In deterministic inversion, the aim is usually to find the global minimum of this function. In probabilistic inversion,one tries to map the entire misfit by (pseudo) random sampling. The misfit is given by\n\n\\begin{gather}\n\t\\chi(\\mathbf{q}) = \\frac{1}{2} \\left[ \\mathbf{q} -\\mathbf{q_0}\\right]^T \\MatrixVariable{C}_M ^{-1}\\left[ \\mathbf{q} -  \\mathbf{q_0}\\right] + \\frac{1}{2} \\left[ G\\left(\\mathbf{q}\\right) -\\mathbf{d_0}\\right]^T \\MatrixVariable{C}_D ^{-1}\\left[G\\left(\\mathbf{q}\\right) -  \\mathbf{d_0}\\right].\n\\end{gather}\n\nExploring this misfit is typically done based on prior information. The Metropolis-Hastings algorithm draws new models entirely from the prior in model space, and accepts either by having a lower misfit or randomly based on the exponential increase in misfit if the proposed model has a larger misfit.\n\nIf the prior model is far off or has large uncertainties, classical samplers might have a hard time finding proper acceptable models. An example which will be expanded on in the first section is a linear model where prior data is off by double the forward modeled value, which on 10,000 samples lead to less than 100 accepted models. These acceptance rates are very wasteful of computing power. On the other side, drawing new models is computationally cheap relative to the more intensive \\gls{HMC} sampling.\n\nA rather helpful way to write the misfit for a linear forward model with Gaussian uncertainties allows for easy computation of derivatives, as well as keeping notations clean. I start by rewriting the misfit functional as;\n\n\\begin{align}\n\t\\chi(\\mathbf{q}) =& \\frac{1}{2} \\left[ \\mathbf{q} -\\mathbf{q_0}\\right]^T \\MatrixVariable{C}_M ^{-1}\\left[ \\mathbf{q} -  \\mathbf{q_0}\\right] \n\t+ \\frac{1}{2} \\left[ \\MatrixVariable{G}\\mathbf{q} -\\mathbf{d_0}\\right]^T \\MatrixVariable{C}_D ^{-1}\\left[\\MatrixVariable{G}\\mathbf{q} -  \\mathbf{d_0}\\right]\\nonumber\\\\\n\t=&\\frac{1}{2} \\mathbf{q}^T \\MatrixVariable{C}_M ^{-1}\\mathbf{q} \n\t- \\frac{1}{2} \\mathbf{q_0}^T \\MatrixVariable{C}_M ^{-1}\\mathbf{q} \n\t- \\frac{1}{2} \\mathbf{q}^T \\MatrixVariable{C}_M ^{-1}\\mathbf{q_0} \n\t+ \\frac{1}{2} \\mathbf{q_0}^T \\MatrixVariable{C}_M ^{-1}\\mathbf{q_0}\\nonumber\\\\\n\t&+ \\frac{1}{2}\\left( \\MatrixVariable{G} \\mathbf{q} \\right)^T \\MatrixVariable{C}_D ^{-1}\\left( \\MatrixVariable{G} \\mathbf{q} \\right)\n\t-\\frac{1}{2} \\mathbf{d_0} ^T \\MatrixVariable{C}_D ^{-1}\\left( \\MatrixVariable{G} \\mathbf{q} \\right)\\nonumber\\\\\n\t&-\\frac{1}{2}\\left( \\MatrixVariable{G} \\mathbf{q} \\right)^T \\MatrixVariable{C}_D ^{-1}\\mathbf{d_0}\n\t+\\frac{1}{2}\\mathbf{d_0}^T \\MatrixVariable{C}_D ^{-1}\\mathbf{d_0}\\nonumber\\\\\n\t=&\\frac{1}{2} \\mathbf{q}^T \\MatrixVariable{C}_M ^{-1}\\mathbf{q} \n\t- \\frac{1}{2} \\mathbf{q_0}^T \\MatrixVariable{C}_M ^{-1}\\mathbf{q} \n\t- \\frac{1}{2} \\mathbf{q}^T \\MatrixVariable{C}_M ^{-1}\\mathbf{q_0} \n\t+ \\frac{1}{2} \\mathbf{q_0}^T \\MatrixVariable{C}_M ^{-1}\\mathbf{q_0\\nonumber}\\\\\n\t&+ \\frac{1}{2}\\mathbf{q}^T \\MatrixVariable{G}^T  \\MatrixVariable{C}_D ^{-1} \\MatrixVariable{G} \\mathbf{q} \n\t-\\frac{1}{2} \\mathbf{d_0} ^T \\MatrixVariable{C}_D ^{-1} \\MatrixVariable{G} \\mathbf{q} %\\nonumber\\\\\n\t-\\frac{1}{2} \\mathbf{q}^T  \\MatrixVariable{G}^T \\MatrixVariable{C}_D ^{-1}\\mathbf{d_0}\n\t+\\frac{1}{2}\\mathbf{d_0}^T \\MatrixVariable{C}_D ^{-1}\\mathbf{d_0}.\n\\end{align}\nNow the trick is to realize that all the components can be individually transposed without altering the equation. The fact that $ \\mathbf{a}^T \\mathbf{b} = \\mathbf{a} \\cdot \\mathbf{b} = \\mathbf{b} \\cdot \\mathbf{a} = \\mathbf{b}^T \\mathbf{a}$ should be enough proof. Also realizing that  covariance matrices are always symmetric, we rearrange the equation in second, first and zeroth order terms of $\\mathbf{q}$:\n\\begin{align}\n\t\\chi(\\mathbf{q}) =\n\t&\\frac{1}{2} \\mathbf{q}^T \\left[\\MatrixVariable{C}_M^{-1} +  \\MatrixVariable{G}^T  \\MatrixVariable{C}_D ^{-1} \\MatrixVariable{G} \\right]\\mathbf{q} -\\left(\\mathbf{q_0}^T \\MatrixVariable{C}_M ^{-1} + \\mathbf{d_0} ^T \\MatrixVariable{C}_D ^{-1} \\MatrixVariable{G}\\right) \\mathbf{q}\n\t \\nonumber\\\\\n\t& \n\t+ \\frac{1}{2} \\mathbf{q_0}^T \\MatrixVariable{C}_M ^{-1}\\mathbf{q_0}\n\t+\\frac{1}{2}\\mathbf{d_0}^T \\MatrixVariable{C}_D ^{-1}\\mathbf{d_0}.\n\\end{align}\nOr, substituting the different components;\n\\begin{align}\n\t\\chi(\\mathbf{q}) =\n\t&\\frac{1}{2}\\mathbf{q}^T \\MatrixVariable{A} \\; \\mathbf{q} -\\mathbf{b}  \\mathbf{q} + c,\n\\end{align}\nwhere\n\\begin{align}\n\t\\MatrixVariable{A} &= \\MatrixVariable{C}_M^{-1} +  \\MatrixVariable{G}^T  \\MatrixVariable{C}_D ^{-1} \\MatrixVariable{G} \\label{eq:linear_system.misfit_A}\\\\\n\t\\mathbf{b} &= \\mathbf{q_0}^T \\MatrixVariable{C}_M ^{-1} + \\mathbf{d_0} ^T \\MatrixVariable{C}_D ^{-1} \\MatrixVariable{G} \\label{eq:linear_system.misfit_b}\\\\\n\tc &=  \\frac{1}{2} \\mathbf{q_0}^T \\MatrixVariable{C}_M ^{-1}\\mathbf{q_0}\n\t+\\frac{1}{2}\\mathbf{d_0}^T \\MatrixVariable{C}_D ^{-1}\\mathbf{d_0}.\n\\end{align}\nNote that $\\mathbf{b}$ is a row vector, so $\\mathbf{b}\\mathbf{q}$ is actually the dot product between $\\mathbf{b}^T$ and $\\mathbf{q}$.\n\nNow using this notation, one can easily compute the gradient of the misfit as\n\\begin{gather}\n\t\\frac{\\partial \\chi}{\\partial q_i} = A_{ij} q_j - b_i.\n\\end{gather}\n\\index{Algorithm performance}Note that repeated indices are summed. Note that using these quantities (which are precomputed every inversion) sped up propagation by 10 times.\n\n\\paragraph{Hamiltonian Mechanics and sampling} One way to propose more acceptable models is to use \\gls{HMC} sampling. In this algorithm, the model is considered as a particle in $n$-dimensional space, where n denotes the number of inversion parameters. By not assigning new parameters but momenta in each dimension and propagating the model for a certain amount of time one proposes new models.\n\nThe propagation is based on Hamilton's Equations. These two equations interrelate energy of a system to it's position and momentum.\\index{Hamilton's equations} Hamilton's equations for a trajectory of a particle are given in this $n$-dimensional space as;\n\n\\begin{gather}\n\t\\frac{d q_i}{dt} = \\frac{\\partial H}{\\partial p_i},\\label{eq:ham1}\\\\\n\t\\frac{d p_i}{dt} = - \\frac{\\partial H}{\\partial q_i}\\label{eq:ham2}.\n\\end{gather}\nIn these equations, $q_i$ is the position in dimension $i$, $p_i$ is the momentum in dimension $i$ (given by $p_i = \\mu_i \\frac{d q_i}{dt}$). $H$ stands for the Hamiltonian, which in physical Hamiltonian Mechanics is the sum of potential en kinetic energy.\n\nThe trick to \\gls{HMC} sampling is to consider the misfit functional $\\chi$ as a gravitational potential. This allows us to propagate our model over model space as if it were a particle moving under the influence of gravity defined by the posterior distribution. The actual definitions for potential and kinetic energy then become:\n\n\\begin{gather}\n\tK(\\mathbf{p}) = \\frac{1}{2} \\sum_{i=1}^{n} \\frac{p_i^2}{\\mu_i},\\label{eq:kineticsimple}\\\\\n\tU(\\mathbf{q}) = \\chi(\\mathbf{q}).\n\\end{gather}\n\nThere are already many interesting options, remarks and conclusions to draw from this framework, but as it is usually nicely illustrated using a few examples, we will come to that later. Noteworthy however that a simplification is done on the calculation of momenta. In a later analysis, I extend this definition. See also the note about equation \\eqref{eq:hamsimple1}.\n\nOne thing which is useful to note now is that the derivatives on the right hand sides of equations \\eqref{eq:ham1} and \\eqref{eq:ham2} now simplify, for the Hamiltonian derivative with respect to momenta only depends on kinetic energy, while the derivative with respect to position only depends on potential energy. The simplified representation is:\n\n\\begin{gather}\n\\frac{d q_i}{dt} = \\frac{p_i}{\\mu_i},\\label{eq:hamsimple1}\\\\\n\\frac{d p_i}{dt} = - \\left[\\nabla_{q} \\chi \\right]_i\\label{eq:hamsimple2}.\n\\end{gather}\nAn extension on this with a \\index{Mass matrix}non-diagonal mass matrix will allows us to `link' parameters together in the propagation. This will be analyzed later on. Typically, however, for simple cases one chooses a diagonal positive definite mass matrix, which leads to equation \\eqref{eq:hamsimple1}.\n\n\\index{Model propagation}The propagation of models is done using a leapfrog scheme, in which one splits up each time step in three separate calculations. First the momentum is propagated half an original time step, then the model parameters are propagated a full step, after which the momentum catches up again. Since I will not alter much on this side of the algorithm, for specifics I refer to section~5.2.3.3 of \\cite{neal2011mcmc}.\n\n\\index{Acceptance rate}Acceptance of a new proposition works almost equal with \\gls{HMC} as it does with the Metropolis-Hastings algorithm. The difference is that one does not compare misfit magnitudes, but the actual Hamiltonian, or energy of the system. Mathematically, this can be expressed as\n\\begin{gather}\n\t\\min\\left( 1, \\frac{\\exp\\left[-H(\\mathbf{q_\\tau},\\mathbf{p_\\tau}) \\right]}{\\exp\\left[-H(\\mathbf{q},\\mathbf{p}) \\right]} \\right).\n\\end{gather}\nI like this better in words. As we explore model space, we assign new momenta in each iteration. This will result in a different energy of the system. If the Hamiltonian (the system's energy) has decreased from the previous sample, than it is accepted unconditionally (because $\\exp (H - H_\\tau)>1$). If, however, energy has increased, it has a chance of $\\exp \\left(H - H_\\tau\\right)$ to be accepted. This can be expressed as exploration of energy levels.\n\n\\index{Measure of exploration}What is noteworthy is that through the conservation of energy the Hamiltonian will not change over the course of the trajectory. This allows two things; a quality control to ensure that propagation of the model is performed correctly. Moreover, the chance of accepting a model is completely defined as soon as the momentum is assigned. This is very important, as it now also follows that propagation time doesn't influence the acceptance rate \\textit{at all}. As one will see, trajectory length is more a tuning parameter which determines the algorithm's measure of exploration.\n\n\\index{Mass matrix}Mass matrices can be chosen in two ways. A standard, non-optimized option would be to choose the unit matrix. A simple analysis given in Andreas Fichtner's reader also reveal that parameters with different forward model derivatives oscillate non-equally during a trajectory. A mitigation is to assign the mass matrix according to the forward model. The mass matrix that would result in equal oscillations would be \n\\begin{gather}\\label{eq:massMatrixForward}\n\\MatrixVariable{M} = \\MatrixVariable{G}^T \\MatrixVariable{G}\n\\end{gather}\nwhere just taking the trace of this matrix would `unlink' the parameters again and make oscillations roughly equal. We'll see later that this assumption is not fully correct.\n\n\\index{Momenta!Drawing} Momenta are drawn from the mass matrix diagonal (correlation is assumed to be non-existent). By using the square root of the mass as standard deviation and zero mean, $n$ momenta are drawn corresponding to $n$ parameters.\n\n", "meta": {"hexsha": "0962419164b30490458d55570d490168de236d29", "size": 13738, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thoughts/recap.tex", "max_stars_repo_name": "larsgeb/hmc-documentation", "max_stars_repo_head_hexsha": "e302375a870359174254cc4e6c0515ef255dea3e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "thoughts/recap.tex", "max_issues_repo_name": "larsgeb/hmc-documentation", "max_issues_repo_head_hexsha": "e302375a870359174254cc4e6c0515ef255dea3e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thoughts/recap.tex", "max_forks_repo_name": "larsgeb/hmc-documentation", "max_forks_repo_head_hexsha": "e302375a870359174254cc4e6c0515ef255dea3e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 101.762962963, "max_line_length": 608, "alphanum_fraction": 0.7438491775, "num_tokens": 4127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7404983652837247}}
{"text": "\\chapter{Rewriting math equations into basic UREs}\n\nBased on the work of Gusev and Evans~\\cite{broadcastElim,broadcastElimQR},  we can translate math equations into UREs, following the simple steps below. Going through an example, we would find that this process is pretty much mechanical and intuitive, and only middle-school level of math knowledge is needed. So do not be scared by the math symbols. In fact, you want to work out the UREs through the simple math process, since the correctness can be proved and that would save you time in debugging.\n\nWe strongly recommend a beginner tries one example so as to quickly master the skills. These skills are generally applicable to real world problems.\n\nUse auto-regressive filter~\\cite{autoRegressiveModel} for example:\n\\begin{equation}\n X_t=c+\\sum\\limits^I_{i=1}\\varphi_i X_{t-i}+\\varepsilon_t\n\\end{equation}\nwhere $c$ is a constant, $\\varphi_1, ... \\varphi_I$ are the parameters, $\\varepsilon _t$ is white noise, and $X_t$ is the output at the current time $t$ and is dependent on the previous $I$ outputs $ X_{t-1}, ..., X_{t-I}$. \n\nTable~\\ref{tab:deriving-ures-for-auto-regressive-filter} shows a complete process how UREs are derived for the problem, and the steps are explained in more detail below:\n\n\\begin{table*}[!ht]\n\\begin{tabular}{|l|ll|ll|}\n\\hline\n    \\multicolumn{1}{|c|}{\\textbf{Step}} & \\multicolumn{2}{|c|}{\\textbf{Equations}} & \\multicolumn{2}{|c|}{\\textbf{Initial values}} \\\\\\hline\\hline\n     \\multirow{1}{*}{1: Iterative form}\n        & $X_t=c+\\sum\\limits^I_{i=1}\\varphi_i X_{t-i}+\\varepsilon_t$    & $t=1, ..., T$   & $X_{t-i}=0$ &if $t-i \\le 0$          \\\\\\hline\n     \\multirow{2}{*}{2: Recursive form}\n        & $X_t=X_t+\\varphi_i X_{t-i}$                   & $t=1,...,T$ & $X_t=c+\\varepsilon_t$ &  \\\\\n        &                                         &   $i=1,..,I$      &  $X_{t-i}=0$ &if $t-i \\le 0$ \\\\\\hline        \n     \\multirow{2}{*}{3: DSA}\n        & $X_t^i=X_t^{i-1}+\\varphi_i X_{t-i}^I$         & $t=1,...,T$  & $X_t^{0}=c+\\varepsilon_t$ & \\\\\n        &                                         &  $i=1,..,I$& $X_{t-i}^I=0$ &if $t-i \\le 0$\\\\\\hline        \n     \\multirow{2}{*}{4: Full index form}\n         & $X_t^i=X_t^{i-1}+\\varphi_i^0 X_{t-i}^I$      & $t=1,...,T$ & $X_t^{0}=c+\\varepsilon_t^0$  & \\\\\n         & &$i=1,..,I$ & $X_{t-i}^I=0$ &if $t-i \\le 0$\\\\\\hline         \n     \\multirow{4}{*}{5: UREs}\n         & \\multicolumn{2}{|l|}{$\\Phi_t^i=(t-1=0) ? \\varphi_i^0 : \\Phi_{t-1}^i $}             &    & \\\\\n         & \\multicolumn{2}{|l|}{$\\chi_t^i=(t-1=0) ? 0 : (i-1=0 ? X_{t-1}^{i-(1-I)} : \\chi_{t-1}^{i-1})$}&&\\\\\n         & $X_t^i=(i-1=0 ? c+\\varepsilon_t^0 :  X_t^{i-1})+\\Phi_t^i\\chi_t^i$ &$t=1,...,T$ & &\\\\\n         & & $i=1,..,I$& & \\\\\\hline         \n\\end{tabular}\n\\caption{Deriving UREs for auto-regressive filter. Here $c? a : b$ is an expression returning $a$ when condition $c$ is true, and $b$ otherwise.}\n\\label{tab:deriving-ures-for-auto-regressive-filter}\n\\end{table*}\n\n\n\\section{Step 1: Iterative form}\n\nFirst, write down the math equation(s) of the original problem. Usually, in an  equation, a domain  is iterated (like $i=1,...,I$ and $t=1,...,T$),  and some variable (like $X$) is computed. A variable might have some initial values (like $X_{t-i}=0$ for $t-i \\le 0$).\n\n\\section{Step 2: Recursive form}\n\nTranslating the iterative form to a recursive form is straightforward: according to the iterative form, initialize a variable (e.g. $X_t=c+\\varepsilon_t$), and update the variable every iteration with a new value based on its previous value (in the form of $X_t=X_t+...$).\n\n\\section{Step 3: DSA (Dynamic Single Assignment)}\n\nWhen updating a variable every iteration, save it to a distinct memory location. Every reference to a variable thus exposes the iteration in which the variable is defined. For example, $X_t=X_t + ... X_{t-i}$ is changed into  $X_t^i=X_t^{i-1} + ... X_{t-i}^I$. After this renaming, it is clear that the 3 references to $X$ are referring to the $X$ values defined in the current iteration $\\begin{psmallmatrix}i\\\\t\\end{psmallmatrix}$ and previous iterations $\\begin{psmallmatrix}i-1\\\\t\\end{psmallmatrix}$ and $\\begin{psmallmatrix}I\\\\t-i\\end{psmallmatrix}$, respectively. \nConsequently, dataflow/dependences between these iterations are made explicit.  \n\nFor another example, the initialization $X_t=c+\\varepsilon_t$ is changed into  $X_t^0=c+\\varepsilon_t$ by adding one 0 for the missing index $i$. $X_t^0$ refers to the $X$ value defined in iteration $\\begin{psmallmatrix}0\\\\t\\end{psmallmatrix}$, which is outside the domain, because index $i$ starts from 1 with a step of 1. In general, if index $i$ starts from $s$ with a step $h$, the initial value should be $X_t^{s-h}$.\n\n\\section{Step 4: Full index form}\n\nNow variables are referenced with full indices, but constants are not: $\\varphi_i$ and $\\varepsilon_t$ are inputs never modified when computing $X_t$ (The other constant $c$ is just a number and we do not care). Similar to the handling of initialization in step 3, we give these constants full indices by adding 0's for the missing index $i$:  change $\\varphi_i$ and $\\varepsilon_t$  into $\\varphi_i^0$ and $\\varepsilon_t^0$. They refer to the $\\varphi$ and $\\varepsilon$ values defined in iteration $\\begin{psmallmatrix}0\\\\i\\end{psmallmatrix}$ and $\\begin{psmallmatrix}0\\\\t\\end{psmallmatrix}$, respectively,  which are outside the domain. In general, if iteration index $i$ starts from $s$ with a step $h$, we should rename $\\varphi_i$ and $\\varepsilon_t$ into $\\varphi_i^{s-h}$ and $\\varepsilon_t^{s-h}$.\n\nAfter being full indexed, variables and constants will be processed in the same way.\n\nAt this point, the equations we get are AREs (Affine Recurrence Equations), that is, the current iteration $\\begin{psmallmatrix}i\\\\t\\end{psmallmatrix}$ reads a value defined in a previous iteration with a distance $d$ that is in the form of  $d=A\\begin{psmallmatrix}i\\\\t\\end{psmallmatrix}+d_0$, where $A$ is a matrix and $d_0$ a constant vector. In other words, there is a read-after-write affine dependence between the two iterations. The dependence distance can be calculated as the current iteration  - the previous iteration  = the write's index - the read's index: Remember that every write/read is fully indexed with the iteration that defines its value; thus the write is indexed with the current iteration, the read is indexed with the previous iteration.  See Table~\\ref{tab:deps-full-index-form-auto-regressive-filter} for all the dependences:\n\n\\begin{table*}[!ht]\n\\begin{tabular}{|c|c|c|l|}\n\\hline\n    \\multicolumn{1}{|c|}{\\textbf{Dependence No.}} & \\multicolumn{1}{|c|}{\\textbf{Write}} & \\multicolumn{1}{|c|}{\\textbf{Read}} & \\multicolumn{1}{|c|}{\\textbf{Dependence distance}}\\\\\\hline\\hline\n     \\multirow{1}{*}{1} & $X_t^i$ & $X_t^{i-1}$ &  $\\begin{pmatrix} i\\\\t\\end{pmatrix} -  \\begin{pmatrix} i-1 \\\\ t\\end{pmatrix} =  \\begin{pmatrix} 1 \\\\ 0\\end{pmatrix}$ \\\\\\hline\n     \\multirow{1}{*}{2} & $X_t^i$ & $\\varphi_i^{0}$ &  $\\begin{pmatrix} i\\\\t\\end{pmatrix} -  \\begin{pmatrix} 0 \\\\ i \\end{pmatrix} =  \\begin{pmatrix} i \\\\ t-i\\end{pmatrix} =  \\begin{pmatrix} 1 & 0 \\\\ -1 & 1\\end{pmatrix}  \\begin{pmatrix} i \\\\ t\\end{pmatrix}$ \\\\\\hline\n     \\multirow{1}{*}{3} & $X_t^i$ & $X_{t-i}^{I}$ &  $\\begin{pmatrix} i\\\\t\\end{pmatrix} -  \\begin{pmatrix} I \\\\ t-i \\end{pmatrix} =  \\begin{pmatrix} i-I \\\\ i\\end{pmatrix} =  \\begin{pmatrix} 1 & 0 \\\\ 1 & 0\\end{pmatrix}  \\begin{pmatrix} i \\\\ t\\end{pmatrix} + \\begin{pmatrix} -I \\\\ 0 \\end{pmatrix}$  \\\\\\hline\n\\end{tabular}\n\\caption{Dependences of the full index form in  step 4 of  Table~\\ref{tab:deriving-ures-for-auto-regressive-filter}}.\n\\label{tab:deps-full-index-form-auto-regressive-filter}\n\\end{table*}\n\n\\section{Step 5: UREs}\n\nWe translate AREs into UREs by converting a broadcast into a pipeline. After that, every dependence has a constant distance uniformly in the entire domain.\n\nThere are two ways to convert a broadcast into a pipeline, either graphically or mathematically. \n\n\\subsection{First way to translate AREs into UREs: drawing a dataflow graph}\n\\label{sec:are-to-ures-with-dfg}\n\nWe can draw the dataflow and intuitively figure out how to change a broadcast into a pipeline, as exemplified in Fig.~\\ref{fig:broadcast-to-pipeline-arf}. According to the 2nd dependence in Table~\\ref{tab:deps-full-index-form-auto-regressive-filter}, originally, a datum $\\varphi_i^0$ is broadcast to iterations $X_t^i$ for all $t$, as shown in the left of the figure. \n\nEquivalently, the same datum can be loaded in an iteration at a boundary of the domain, and from that iteration, propagated in a pipeline fashion to all the other iterations, as shown in the right of the figure. As we can see, $\\varphi_i^0$ is  loaded at a bounary iteration $(i, 1)$, and then is propagated to iteration $(i, 2)$, and from there to iteration $(i, 3)$, etc. \n\n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[width=\\textwidth]{./img/broadcast-to-pipeline-arf.png}\n    \\caption{For the 2nd dependence of auto-regressive filter in Tabel~\\ref{tab:deps-full-index-form-auto-regressive-filter}, the broadcasts due to this dependence are changed to pipelines. Here we assume $T=3$, and every point is an iteration annotated with its indices $\\begin{psmallmatrix} i\\\\ t\\end{psmallmatrix}$.}\n    \\label{fig:broadcast-to-pipeline-arf}\n\\end{figure}\n\n\\subsubsection{Expressing a pipeline} \n\\label{sec:express-pipeline}\n\nNow we can modify the full index form\n\n\\begin{equation}\nX_t^i=...\\varphi_i^0...\n\\end{equation}\n\ninto\n\n\\begin{equation}\nX_t^i=...\\Phi_t^i...\n\\end{equation}\n\nwhere $\\Phi$ values are propagated along the $t$ dimension until out of the domain:\n\n\\begin{equation}\n\\Phi_t^i=(t-1=0) ? \\varphi_i^0 : \\Phi_{t-1}^i\n\\end{equation}\n\nAs you can see, the keys to change a broadcast into a pipeline are: (1) the direction of the pipeline, along which data would be propagated from one iteration to the next, and (2) the boundary conditions when the pipeline is fed with some initial values.  \n\nIn the same way, we can convert a broadcast due to the third dependence into a pipeline (Could you do it?). After that, we get the UREs shown in step 5 of  Table~\\ref{tab:deriving-ures-for-auto-regressive-filter}.\n\n\\subsection{Second way to translate AREs into UREs: Calculating a propagation direction}\n\\label{sec:are-to-ures-with-math}\n\nWe can generalize the example in Fig.~\\ref{fig:broadcast-to-pipeline-arf}, and directly find out a propagation direction vector in simple math: \n\n\\begin{quotation}\n\\noindent If a read-after-write dependence is affine, i.e. the distance $d$ is in the form of $Az+d_0$, where $A$ is a matrix, $z$ is the current iteration, and $d_0$ is a constant vector, then the dependence incurs broadcasts of values, and such a broadcast can be changed into a pipeline by propagating a value along a direction $r$ that is a solution of $(E-A)r=\\mathbf{0}$, where $E$ is the identity matrix.\n\\end{quotation}\n\n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[width=\\textwidth]{./img/broadcast-to-pipeline.png}\n    \\caption{Changing a broadcast into a pipeline}\n    \\label{fig:broadcast-to-pipeline}\n\\end{figure}\n\nThe left part of Fig.~\\ref{fig:broadcast-to-pipeline} shows that due to an affine dependence, some data are broadcast to multiple consumers, including an iteration $b$ at the boundary of the domain, and two other iterations $c_1$ and $c_2$, etc. Remember that data are fully indexed, i.e. they can be considered having been defined in an iteration $y$, even though that iteration is actually out of the domain. \n\nLet the dependence distance be $d=Az+d_0$.  Because both iteration $c1$ and $c_2$ get data from the same iteration $y$, using the  dependence distance, we have\n\\begin{equation}\ny = c_2 - (Ac_2+d_0) = c_1 - (Ac_1+d_0)\n\\end{equation}\n\nSo\n\\begin{equation}\n(E-A)c_2 = (E-A)c_1    \n\\end{equation}\n\nLet $r=c_2-c1$, we have\n\\begin{equation}\n(E-A)r = 0.\n\\end{equation}\n\nTherefore, we can imagine that a datum that is defined outside the domain is first sent to a boundary iteration $b$, and then following a propagation direction $r$ to the next iteration $b+r$, and so on, and eventually the data reach iteration $c_1$, and then $c_2$, etc. This constructs a pipeline as shown in the right part of Fig.~\\ref{fig:broadcast-to-pipeline}.\n\nFor example, the second dependence for the auto-regressive filter is $\\begin{psmallmatrix} 1 & 0 \\\\ -1 & 1\\end{psmallmatrix}  \\begin{psmallmatrix} i \\\\ t\\end{psmallmatrix}$ (Table~\\ref{tab:deps-full-index-form-auto-regressive-filter}), and thus $A=\\begin{psmallmatrix} 1 & 0 \\\\ -1 & 1\\end{psmallmatrix}$. Solve the equation $(E-A)r=\\begin{psmallmatrix} 0 & 0 \\\\ 1 & 0\\end{psmallmatrix}r=\\mathbf{0}$. We get a solution $r=\\begin{psmallmatrix} 0 &\\\\ *\\end{psmallmatrix}$, where the second element (the $t$ dimension)  can be arbitrary. Take a non-zero solution $r=\\begin{psmallmatrix} 0 &\\\\ 1\\end{psmallmatrix}$, and we see exactly from the right part of Fig.~\\ref{fig:broadcast-to-pipeline-arf} that a  pipeline can be constructed along the $t$ dimension for a datum. \n\nWith this propagation direction, we convert a broadcast due to the second dependence into a pipeline in the same way as shown in Section~\\ref{sec:express-pipeline}. Following the same approach, for the third dependence, we can find a propagation direction $r=\\begin{psmallmatrix} 1 &\\\\ 1\\end{psmallmatrix}$, and convert the broadcasts due to this dependence into pipelines as well (Could you do it?). After that, we get the UREs shown in step 5 of  Table~\\ref{tab:deriving-ures-for-auto-regressive-filter}.\n\n\\subsection{Testing correctness of UREs in standard C}\n\\label{sec:test-correctness-ures}\n\nWe can express the UREs in Table~\\ref{tab:deriving-ures-for-auto-regressive-filter} in standard C, adding necessary helping code for testing, and see if the UREs can produce correct results. See Listing~\\ref{lst:test-correctness-ures-auto-regressive-filter-in-c}.  \n\n\\lstinputlisting[language=c, caption={Testing the correctness of the UREs in Table~\\ref{tab:deriving-ures-for-auto-regressive-filter} in standard C code.}, label={lst:test-correctness-ures-auto-regressive-filter-in-c}]{code/auto-regressive-filter-testing-ures-in-c.c}\n\n\nNow test it: \n\\begin{verbatim}\n    $gcc auto-regressive-filter-testing-ures.c\n    $./a.out\n    Success!\n\\end{verbatim}\n\n\\subsection{Expressing the UREs in T2S}\n\\label{sec:express-ures-in-t2s}\n\nIt is straightforward to express the UREs in T2S. See Listing~\\ref{lst:test-correctness-ures-auto-regressive-filter-in-t2s}. The code is similar to the C code before. The major difference is that the T2S code builds a symbolic dataflow graph where inputs are symbolic parameters and computation is symbolic expressions (Line 13-27), then instantiates the graph to compute with concrete inputs (Line 29-37), and after that compares with a golden baseline for correctness.  \n\n\\lstinputlisting[language=c, caption={Testing the correctness of the UREs in Table~\\ref{tab:deriving-ures-for-auto-regressive-filter} in T2S.}, label={lst:test-correctness-ures-auto-regressive-filter-in-t2s}]{code/auto-regressive-filter-testing-ures-in-t2s.cpp}\n\nNow test it: \n\\begin{verbatim}\n    $ export T2S_PATH=path_to_your_t2s_installation\n    $ export PATH=$T2S_PATH/Halide/bin:$T2S_PATH/install/gcc-7.5.0/bin:$PATH\n    $ export LD_LIBRARY_PATH=$T2S_PATH/Halide/bin:$LD_LIBRARY_PATH\n    $ g++ -I$T2S_PATH/Halide/include -L$T2S_PATH/Halide/bin -lHalide  -std=c++11 \\   \n          auto-regressive-filter-testing-ures-in-t2s.cpp\n    $ ./a.out \n    Success!\n\\end{verbatim}\n\n\n", "meta": {"hexsha": "81d781f4f930791041c2bc43bdc55d17cea986e0", "size": 15498, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "t2s/doc/programming-guide/rewriting-math-equations-into-basic-ures.tex", "max_stars_repo_name": "z24tao/t2sp", "max_stars_repo_head_hexsha": "ceb8ce114a897a1e2060d844ca56610ebb1bca22", "max_stars_repo_licenses": ["BSD-2-Clause-Patent"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "t2s/doc/programming-guide/rewriting-math-equations-into-basic-ures.tex", "max_issues_repo_name": "z24tao/t2sp", "max_issues_repo_head_hexsha": "ceb8ce114a897a1e2060d844ca56610ebb1bca22", "max_issues_repo_licenses": ["BSD-2-Clause-Patent"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-27T06:55:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T06:55:35.000Z", "max_forks_repo_path": "t2s/doc/programming-guide/rewriting-math-equations-into-basic-ures.tex", "max_forks_repo_name": "ronghongbo/t2sp", "max_forks_repo_head_hexsha": "7b9e4e3075ee2bebd755a5755c5f7dda1cd78783", "max_forks_repo_licenses": ["BSD-2-Clause-Patent"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 79.8865979381, "max_line_length": 853, "alphanum_fraction": 0.7095754291, "num_tokens": 4772, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7404983606169996}}
{"text": "\\section{Bonus Lecture: Simple Groups of Order 60}\r\nConsider $\\operatorname{GL}_2(\\mathbb Z_5)$.\r\nWe first want to find the size of this group.\r\nIt is easy to see that\r\n$$\\begin{pmatrix}\r\n    a&b\\\\\r\n    c&d\r\n\\end{pmatrix}\\in\\operatorname{GL}_2(\\mathbb Z_5)$$\r\nis invertible if annd only if $ad-bc$ has a multiplicative inverse, that is, is nonzero.\r\nTake $U_5\\subset \\mathbb Z_5$ to be the set of elements in $\\mathbb Z_5$ having multiplicative inverse, that is, $U_5=\\mathbb Z_5^\\times=\\mathbb Z_5\\setminus\\{0\\}$.\r\nThere are $5^4=625$ $2\\times 2$ matrices in total.\r\nAmongst them, the number of non-invertible ones satisfies $ad\\equiv bc\\pmod{5}$.\\\\\r\nCase 1: $a=0$, then $bc=0$, so either $b=0$ (which gives $25$ choices) or $c=0$ (which gives, again, $25$ choices).\r\nThere are double-counted cases where $b=c=0$ and there are $5$ cases, so there is a total of $45$ choices.\\\\\r\nCase 2: $a\\neq 0$, then we can solve for $d$ given $b,c$.\r\nIndeed, for any $b,c$, we can have an unique corresponding $d$, hence there are $4\\times 5^2=100$ choices.\\\\\r\nSo there are a total of $145$ non-invertible matrices and thus $480$ invertible matrices.\r\nThere are still a lot of elements, so we want to think about $\\operatorname{SL}_2(\\mathbb Z_5)$.\r\nBut since $\\det:\\operatorname{GL}_2(\\mathbb Z_5)\\to\\mathbb Z_5^\\times$ is a surjective homomorphism with kernel $\\operatorname{SL}_2(\\mathbb Z_5)$, so $|\\operatorname{SL}_2(\\mathbb Z_5)|=120$.\r\nAlso note that $\\operatorname{PSL}_2(\\mathbb Z_5)\\cong\\operatorname{SL}_2(\\mathbb Z_5)/\\{\\pm I\\}$, then $|\\operatorname{PSL}_2(\\mathbb Z_5)|=60$.\r\nWe can analyze the conjugacy classes in $\\operatorname{PSL}_2(\\mathbb Z_5)$ to find out that they look exactly like that in $A_5$.\r\nIn fact they are isomorphic.\r\n\\begin{theorem}\r\n    $\\operatorname{PSL}_2(\\mathbb Z_5)\\cong A_5$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $G=\\operatorname{PSL}_2(\\mathbb Z_5)$.\r\n    Take the subgroup\r\n    $$H=\\left\\{ \\begin{pmatrix}\r\n        1&0\\\\\r\n        0&1\r\n    \\end{pmatrix},\r\n    \\begin{pmatrix}\r\n        2&0\\\\\r\n        0&3\r\n    \\end{pmatrix},\r\n    \\begin{pmatrix}\r\n        0&2\\\\\r\n        2&0\r\n    \\end{pmatrix},\r\n    \\begin{pmatrix}\r\n        0&1\\\\\r\n        4&0\r\n    \\end{pmatrix}\\right\\}\\le G$$\r\n    so the three non-identity elements in $H$ has order $2$ and since there is only one conjugation class of element of order $2$, so the conjugates of $H$ contains all element of order $2$.\r\n    Since there are $15$ elements of order $2$ and $H$ contains $3$ elements of order $2$, there must be at least $5$ conjugates of $H$.\r\n    We want to show there are precisely $5$ of them.\r\n    Consider the action $G$ on the set $X$ of the subgroups of $G$ by conjugation, then the stabiliser $G_H$ (the normalizer) satisfies $|G_H|\\times |G\\star H|=|G|=60$.\r\n    Note that $H\\le G_H$, hence $4||G_H|$, therefore $|G\\star H||15$.\r\n    If $|G\\star H|=15$, we know that there are only $15$ elements of order $2$, some pair of conjugates have $3$ elements in common (counting identity), but then they must be the same, contradiction.\r\n    So $|G\\star H|=5$ as claimed.\r\n    The action of $G$ on $G\\star H$ then gives a homomorphism $\\rho:G\\to S_5$.\\\\\r\n    Now $G$ is simple by the same argument we used to show the simplicity of $A_5$ since they have the same table of sizes of conjugacy classes.\r\n    Hence $\\rho$ is injective (since $\\rho$ is obviously not constant), so $G\\cong\\operatorname{Im}\\rho$ which has index $2$ in $S_5$, hence is normal in $S_5$.\\\\\r\n    Suppose $\\operatorname{Im}\\rho\\neq A_5$, then $\\operatorname{Im}\\rho\\cap A_5\\le A_5$ has index $2$, so $\\{e\\}\\neq\\operatorname{Im}\\rho\\cap A_5\\lhd A_5$, contradiction.\r\n    Therefore $G\\cong\\operatorname{Im}\\rho\\cong A_5$.\r\n\\end{proof}\r\nIn fact, there is only one simple group of order $60$ up to isomorphism.\\\\\r\nNow we turn to the symmetry of platonic solids.\r\nNote that dual solids have isomorphic symmetries.\r\nLet $G$ be the group of all isometries of a platonic solid and and $SG$ the group of all rotational isometries of it.\r\nIt is fact that $\\operatorname{O}(3)\\cong \\operatorname{SO}(3)\\times C_2$.\r\nNote $S_4\\not\\cong A_4\\times C_2$, since $x\\mapsto -x$ is no longer a symmetry of the tetrahedron.\r\nOtherwise, we have $G\\cong SG\\times C_2$.\\\\\r\nFor cube, we have seen that $SG$ has $24$ elements.\r\nIn fact, $SG\\cong S_4$ since it permutes the set of long diagonals (pairs of opposite vertices).\\\\\r\nNow symmetries of a regular isocahedron.\r\nLet $SG$ act (transitively) on its $12$ vertices.\r\nThe stabiliser of the vertex are the rotations though the axis through the vertex, so it is isomorphic to $C_5$.\r\nSo $|SG|=5\\times 12=60$.\r\nIn fact, again we have $SG\\cong A_5$.\r\n\\begin{proposition}\r\n    $SG$ is simple.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    $SG$ contains rotations of order $5$ through a vertex and of order $3$ through the centre of a face or order $2$ through the centre of an edge.\r\n    So if $H\\unlhd SG$ contains a rotation of order $5$ around some vertex, then by conjugating we can contain all rotations of order $5$ around any vertex.\r\n    But then $H$ acts transitively on the vertices, and on any pair of vertices, but then one must get all rotations, so $H=SG$.\r\n    Similar arguments hold if $H$ contains an element of order $2$ or $3$, hence $SG$ is simple.\r\n\\end{proof}\r\nIn fact, there are five inscribed tetrahedra in an isocahedra that are permuted by the action of $SG$, so by the same argument used in showing $\\operatorname{PSL}_2(\\mathbb Z_5)\\cong A_5$, we have $SG\\cong A_5$.", "meta": {"hexsha": "caafe65e6eb79526682d0c0d41a26d4bf5a6679c", "size": 5481, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11/bonus.tex", "max_stars_repo_name": "david-bai-notes/IA-Groups", "max_stars_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "11/bonus.tex", "max_issues_repo_name": "david-bai-notes/IA-Groups", "max_issues_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "11/bonus.tex", "max_forks_repo_name": "david-bai-notes/IA-Groups", "max_forks_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.6666666667, "max_line_length": 211, "alphanum_fraction": 0.6880131363, "num_tokens": 1796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545425, "lm_q2_score": 0.8774767826757122, "lm_q1q2_score": 0.7404983595053501}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{physics}\n\\usepackage{amsmath}\n\\usepackage{showlabels}\n\\usepackage{amssymb}\n\\title{Statistical Computing for Scientists and Engineers\\\\[1em] Homework 5}\n\\author{Jiale Shi}\n\\date{Nov/12/2018}\n\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\\usepackage{array}\n\\begin{document}\n\\maketitle\n\n\\newpage\n\n\\section{Importance Sampling}\nUse importance sampling to approximate expectation $\\mathbb{E}_{p}[f(x)]$ where\n\\begin{equation}\n    f(x) = 2\\sin(\\frac{\\pi}{1.5}x) , x\\geq 0\n\\end{equation}\nand target distribution is defined as \n\\begin{equation}\n    p(x) = x^{1.65-1}\\exp(-x^2/2), x\\geq 0\n\\end{equation}\n\nwrite down your choice of sampling distribution. Plot sampling distribution and target distribution on a plot. Write down the algorithm of your implementation.\n\nSolution:\nThe target distribution \n\\begin{equation}\n    p(x) = x^{1.65-1}\\exp(-x^2/2) =x^{0.65}\\exp(-x^2/2) , x\\geq 0\n\\end{equation}\n\nThe shape of the target distribution is similar to the Gamma distribution Gamma(3,2.5) to some extent. Therefore, we choose Gamma distribution Gamma(3,2.5) as our proposed distribution.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.6]{HW5P1_1.png}\n\\caption{sampling distribution Gamma(3,2.5), target distribution}\n%\\label{fig:universe}\n\\end{figure}\n\nWe samples for $N = 10^6$ times, collect samples(x), calculate weight$W$.\n\\begin{equation}\n    W(samples) = \\frac{p(samples)}{Gamma(3,2.5)}\n\\end{equation}\n\n\\begin{equation}\n    E(f(x)) \\approx \\frac{1}{N}\\sum_{i=1}^{N}W(samples)f(samples) \\approx 0.7758554717760647\n\\end{equation}\n\n\n\n\\newpage\n\\section{Sequential Monte Carlo Sampler}\nImplement a sequential Monte Carlo sampler to draw samples from target distribution $\\pi$, which is an equal mixture of 5 normal distributions in $\\mathbb{R}^2$ with unit covariance and centers that are equally distributed on the circumference of a circle with diameter 40.\n\nInitialize 3000 particles with points located at the center of the circle.\n\nUsing 100 bridging densities $\\pi_{0}$,... ,$\\pi_{100}$ where\n\\begin{equation}\n    \\pi_{k}(x) \\propto \\pi(x)^{\\alpha_{k}}\n\\end{equation}\nand $0 \\leq \\alpha_{1} \\leq ... \\leq \\alpha_{n} = 1$.\n\nUse a normal random walk proposal with step size $\\sqrt{6}$ to evolve particles\n\nMeasure degeneracy using effective sample size with a threshold of $N/2$ and resample accordingly.\n\nTo show the evolution of the points, including distribution of points for $\\pi_{0}$, $\\pi_{50}$, $\\pi_{100}$. Additionally, generate an animation showing the points evolving from $\\pi_{0}$ to $\\pi_{n}$. Write down algorithm of your implementation.\n\nSolution:\nTarget distribution $\\pi$, is an equal mixture of 5 normal distributions in $\\mathbb{R}^2$ with unit covariance and centers that are equally distributed on the circumference of a circle with diameter 40.\n\nThe five center points should be\n\n$(x_1,y_1) = (20\\cos(0),20 \\sin(0))$ ; \n\n$(x_2,y_2) = (20\\cos(\\frac{2\\pi}{5}),20 \\sin(\\frac{2\\pi}{5}))$; \n\n$(x_3,y_3) = (20\\cos(\\frac{4\\pi}{5}),20 \\sin(\\frac{4\\pi}{5}))$; \n\n$(x_4,y_4) = (20\\cos(\\frac{6\\pi}{5}),20 \\sin(\\frac{6\\pi}{5}))$; \n\n$(x_5,y_5) = (20\\cos(\\frac{8\\pi}{5}),20 \\sin(\\frac{8\\pi}{5}))$\n\nThe final target distribution $\\pi(x,y)$ should  be\n\\begin{equation}\n\\begin{aligned}\n    \\pi(x,y) =   & \\exp\\{ -[(\\frac{(x-x_1)^2}{2})+(\\frac{(y-y_1)^2}{2})] \\} \\\\\n     + & \\exp\\{-[(\\frac{(x-x_2)^2}{2})+(\\frac{(y-y_2)^2}{2})] \\} \\\\\n     + & \\exp\\{-[(\\frac{(x-x_3)^2}{2})+(\\frac{(y-y_3)^2}{2})] \\} \\\\\n     + & \\exp\\{-[(\\frac{(x-x_4)^2}{2})+(\\frac{(y-y_4)^2}{2})] \\}   \\\\\n     + & \\exp\\{-[(\\frac{(x-x_5)^2}{2})+(\\frac{(y-y_5)^2}{2})] \\}\n\\end{aligned}\n\\end{equation}\n\nAll the 3000 particles start from the original point $(0,0)$.\nFor $K = [1,2,3,...,100]$, $a_{K} = [0.01,0.02,0.03,..,1]$ the target distribution $\\pi(x,y)_{K} = \\pi(x,y)^{a_K}$. The proposal distribution is a 2D normal distribution with step size is $\\sqrt{6}$. The update follows the MH algorithm. The detail is in the following figure.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.46]{SMCalgorithm.png}\n\\caption{SMC Algorithm}\n%\\label{fig:universe}\n\\end{figure}\n\nThe distribution of points for $\\pi_{0}$, $\\pi_{50}$,$\\pi_{100}$.\n\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.3]{f0.png}\n\\caption{$\\pi_{0}$ start from the center of the circle}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.3]{f50.png}\n\\caption{$\\pi_{50}$}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.3]{f100.png}\n\\caption{$\\pi_{100}$}\n%\\label{fig:universe}\n\\end{figure}\n\n\n\n\n\\newpage\n\\section{Hamiltonian Monte Carlo (HMC)}\nHMC introduces an momentum variable $q$, and uses Hamiltonian dynamics to generate samples.\n\n\nThe potential energy $U(x) = -\\log p(x)$, the kinetic energy $K(q) = -\\log p(q)$.\n$p(x)$ is the target density and $p(q)$ is the proposal density for $q$.\nThe summation $H(x,q) = U(x) + K(q)$. If we can generate samples $\\propto \\exp(-H(x,q)) = p(x)p(q)$, the resulting x samples will be distributed according to the target one.\n\nTo generate new candidate samples based on the Hamilton's equation of motion:\n\n\\begin{equation}\n\\begin{aligned}\n& \\frac{\\partial x_i}{\\partial t} = & \\frac{\\partial H}{\\partial q_i} = & \\frac{\\partial K}{\\partial q_{i}} \\\\\n& \\frac{\\partial q_i}{\\partial t} = & -\\frac{\\partial H}{\\partial x_i} = & -\\frac{\\partial U}{\\partial x_{i}}\n\\end{aligned}\n\\end{equation}\n\nFor numerical implementation, Hamilton's equations must be approximated by non-continual time, using small step $\\epsilon$. \nIt starts with half step update for the momentum variable, and then do a full step for $x$ using the update momentum, and then do the other half step for momentum.\n\\begin{equation}\n\\begin{aligned}\n& q_{i}(t+\\epsilon/2) = q_i(t) -(\\epsilon/2)\\frac{\\partial U}{\\partial x_{i}(t)} \\\\\n& x_{i}(t+\\epsilon) = x_{i}(t)+ \\epsilon   \\frac{\\partial H}{\\partial q_i}  & \\mbox{where}  &  \\frac{\\partial H}{\\partial q_i}=q_i(t+\\epsilon/2) \\\\ %\\frac{\\partial K}{\\partial q_{i}}\n& q_{i}(t+\\epsilon) = q_i(t+\\epsilon/2) -(\\epsilon/2)\\frac{\\partial U}{\\partial x_{i}(t+\\epsilon)} \n\\end{aligned}\n\\end{equation}\n\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.6]{HW5P3_1.png}\n\\caption{target distribution, sampled distribution}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.50]{HW5P3_2.png}\n\\caption{$p(x_1 | x_2)$}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.55]{HW5P3_3.png}\n\\caption{$p(x_2 | x_1)$}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.55]{HW5P3_4.png}\n\\caption{The first 50 steps}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.5]{HW5P3_5.png}\n\\caption{Convergence of $<x_{1}>, <x_{2}>$}\n%\\label{fig:universe}\n\\end{figure}\n\n\n\n\n\\newpage\n\\section{Sequential Importance Sampling for Solving Integral Equations}\nDevise and implement a (sequential) importance sampling Monte Carlo scheme to solve the following integral equation for $f(x)$ (defined in [-1,1]) at $x=0$:\n\n\\begin{equation}\n    f(x) = x+\\frac{1}{2}\\int^{1}_{-1}(t-x)f(t)dt\n\\end{equation}\n\nand compare results with the actual solution:\n\n\\begin{equation}\n    f(x) = \\frac{3}{4}x+\\frac{1}{4}\n\\end{equation}\n\nConsider uniform distribution $U[-1-\\alpha,1+\\alpha]$ as the transition kernel and with the appropriate stopping rule (similarly to the example considered in class in solving $Ax=b$). Comment on the performance for $[\\alpha=0.001,0.1,1,1.5,2]$\n\n\\textbf{Solution:}\n\nAccording to the actual solution, $f(x) = \\frac{3}{4}x+\\frac{1}{4}$. \nThe true value $f(0) = 0.25$. \n\nThe integral equation can be transformed into solving\n\\begin{equation}\n    f(x) = x + \\sum_{n=1}^{\\infty} \\int_{-1}^{1} (\\prod_{k=1}^{n}(t_{k}-t_{k-1}))t_k dt_{1:n}\n\\end{equation}\nIt involves an infinite sum of integrals of increasing dimension, which can be solved by SIS.\nConsider uniform distribution $U[-1-\\alpha,1+\\alpha]$ as the transition kernel.\n\n\\begin{math}\n\\begin{aligned}\n& P_{d} = \\alpha \\\\\n& M = \\frac{1}{(2+2\\cdot\\alpha)} \\\\\n\\end{aligned}\n\\end{math}\n\nsimulate a path using Markov chain. Start from $x^{(i)}=0$, then generate sample $t_{1}^{(i)} \\sim M(t_{1}^{(i)},t)$, $t_{2}^{(i)} \\sim M(t_{2}^{(i)},t)$, until $t_{k+1}^{(i)}$ reaches $s$, the cemetery state.\n\nCalculate the associated weight\n\n\\begin{math}\n\\begin{aligned}\nW^{(i)} (x,t_{1},..,t_{k}) =     \\left\\{ \\begin{array}{rcl}\n     \\frac{0.5((t_{1}-x))}{M} (\\prod^{n}_{k=1} \\frac{0.5(t_{k}-t_{k-1})}{M})\\frac{t_{k}}{P_{d}} & \\mbox{for}\n   & k>0 \\\\ \n   \\frac{0.5((t_{1}-x))}{M} \\frac{t_{k}}{P_{d}} & \\mbox{for} & k=0\n \\end{array}\\right.\n\\end{aligned}\n\\end{math}\n\n\n\\begin{math}\n\\begin{aligned}\nf(x) = y^{(N)}  = \\frac{y_{0} + \\sum_{i}^{N}W^{(i)}}{N} & \\mbox{where} & y_{0}=0\n\\end{aligned}\n\\end{math}\n\nFor $[\\alpha=0.001,0.1,1,1.5,2]$, the performance is: \n\\begin{equation}\n\\begin{aligned}\n& \\alpha = 0.001, & f(0) = 0.2764 & \\mbox{slow}\\\\\n& \\alpha = 0.01, & f(0) = 0.2527 \\\\\n& \\alpha = 0.015, & f(0) = 0.2501 \\\\\n& \\alpha = 0.02, & f(0) = 0.2410 \\\\\n& \\alpha = 0.04, & f(0) = 0.2368 \\\\\n& \\alpha = 0.1, & f(0) = 0.2305 \\\\\n& \\alpha = 1, & f(0) = 0.1205 \\\\\n& \\alpha = 1.5, & f(0) = 0.0982 \\\\\n& \\alpha = 2, & f(0) = 0.0820 & \\mbox{fast} \n\\end{aligned}\n\\end{equation}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.5]{HW5P4.png}\n\\caption{Convergence of $<x_{1}>, <x_{2}>$}\n%\\label{fig:universe}\n\\end{figure}\n\nWhen $\\alpha$ becomes larger and larger, the speed becomes faster and faster.\nFrom $\\alpha = [0.001,0.01,0.015,0.02, 0.04, 0.1,1,1.5,2]$, when $\\alpha$ becomes larger and larger, $f(0)$ initially a little bigger than 0.25, and then $f(0)$ decreases. At $\\alpha = 0.015$, $f(0)$ is closest to the true value 0.25.\n\n\n%\\bibliographystyle{plain}\n%\\bibliography{references}\n\\end{document}\n", "meta": {"hexsha": "a294ed3a2300e7bb2a754a407969570dcda393fc", "size": 9832, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/HW5/HW5_SHI_JIALE_LatexSourceCode/main.tex", "max_stars_repo_name": "shijiale0609/Statistical-Computing-Methods", "max_stars_repo_head_hexsha": "e780746d5f1e4b475bf38eb15d9d825daf45ffa6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Homework/HW5/HW5_SHI_JIALE_LatexSourceCode/main.tex", "max_issues_repo_name": "shijiale0609/Statistical-Computing-Methods", "max_issues_repo_head_hexsha": "e780746d5f1e4b475bf38eb15d9d825daf45ffa6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework/HW5/HW5_SHI_JIALE_LatexSourceCode/main.tex", "max_forks_repo_name": "shijiale0609/Statistical-Computing-Methods", "max_forks_repo_head_hexsha": "e780746d5f1e4b475bf38eb15d9d825daf45ffa6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.9034482759, "max_line_length": 275, "alphanum_fraction": 0.6677176566, "num_tokens": 3522, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199673867851, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.7404889620219135}}
{"text": "\\clearpage\n\\subsection{Comparison between 1D and 2D finite element discretization}\n\\begin{table}[]\n\\centerline{\\bf 1D and 2D Comparison for Finite Element and Multigrid }\\medskip\n\\centering\n\\begin{tabular}{ p{7cm}<{\\centering}|p{7cm}<{\\centering}}\n\\hline\n%\\smallskip \n   $1D: \\Omega=(0, 1)$      \\smallskip &    $2D: \\Omega=(0, 1)\\times (0, 1)$     \n%\\smallskip \n  \\\\\\hline\n $\\begin{cases}\n -u''=f&x\\in \\Omega\\\\\n u(0)=u(1)=0&\n \\end{cases}$        &     \n $\\begin{cases}\n -\\triangle u=f&x\\in \\Omega\\\\\n u=0&x\\in \\partial \\Omega\n \\end{cases}$       \n \\\\\\hline\n  \\multicolumn{2}{c}{$\\displaystyle u=\\argmin_{v\\in V}   J(v)$}   \n \\\\\\hline\n  $\\displaystyle J(v)={1\\over 2}\\int_0^1  |v'|^2dx - \\int_0^1  fv dx $\n  &     $\\displaystyle J(v)={1\\over 2}\\int_\\Omega  |\\nabla v|^2dx - \\int_\\Omega fv\n  dx $      \n \\\\\\hline\n \\multicolumn{2}{c}{$V=\\{v: \\Omega\\rightarrow \\mathbb{R} \\mbox{ is continuous and piecewise smooth, } v|_{\\partial \\Omega}=0\\}$}\n \\\\\\hline \n  \\multicolumn{2}{c}{FE space: $V_h=\\{v_h\\in V, v_h \\mbox{ is piecewise linear w.r.t. } \\mathcal{T}_h\\}$}  \n\\\\\\hline\n\\begin{minipage}{0.5\\textwidth}\\centering\n      \t\\includegraphics[width=4cm]{figures/grid1d.png}\n   \t \\end{minipage}  \n    \t&  \n\t\\begin{minipage}{0.2\\textwidth}\\centering\n      \t\\includegraphics[width=2cm]{figures/grid1.png}\n   \t \\end{minipage} \n\\\\\\hline\n $\\phi_i(x)$   & $\\phi_{ij}(x, y)$ \n \\\\\\hline\n \\begin{minipage}{0.4\\textwidth}\\centering\n      \t\\includegraphics[height=2cm]{figures/basisfunction.pdf}\n   \t \\end{minipage}\n    & \\begin{minipage}{0.5\\textwidth}\\centering\n      \t\\includegraphics[height=2cm]{figures/nodalbasis.pdf}\n   \t \\end{minipage} \n\\\\\\hline\n \\multicolumn{2}{c}{Find $u_h\\in V_h$ s.t. $\\displaystyle J(u_h)=\\min_{v_h\\in V_h} J(v_h)$}    \n \\\\\\hline\n $\\displaystyle u_h=\\sum_{i=1}^n \\mu_i\\phi_i(x)$         &    $\\displaystyle u_h=\\sum_{i, j=1}^n \\mu_{ij}\\phi_{ij}(x, y)$      \n  \\\\\\hline\n Find $\\mu\\in \\mathbb{R}^n$ s.t. $\\displaystyle  I(\\mu)=\\min_{\\nu\\in \\mathbb{R}^n} I(\\nu)$\n &   Find $\\mu\\in \\mathbb{R}^{n\\times n}$ s.t. $\\displaystyle  I(\\mu)=\\min_{\\nu\\in \\mathbb{R}^{n\\times n}} I(\\nu)$  \n \\\\\\hline\n \\multicolumn{2}{c}{$I(\\nu)={1\\over 2}(A\\ast \\nu, \\nu)_{l^2} - (b, v)_{l^2} $}  \n \\\\\\hline\n $A={1\\over h}(-1, 2, -1)$        &   \n$\\scriptsize\n A=\\begin{pmatrix}\n 0&-1&0\\\\\n -1&4&-1\\\\\n 0&-1&0\n \\end{pmatrix}\n$     \n \\\\\\hline\n  \\multicolumn{2}{c}{$\\mu=\\argmin I(\\nu) \\Longleftrightarrow \\nabla J(\\mu)=A\\ast \\mu -b=0$}    \\\\\\hline\n\\multicolumn{2}{c}{ GD Method:   $ \\mu^{(m+1)}=\\mu^{(m)} -\\eta(A\\ast \\mu^{(m)}-b)$}       \n \\\\\\hline\n$\\eta={h\\over 4}$       &    $\\eta={1\\over 8}$      \\\\\\hline\n\\end{tabular}\n\\end{table}\n\n\\renewcommand\\arraystretch{2}\n\\begin{table}[]\n\\centerline{\\bf Basic multigrid components}\n\\medskip \n\\centering\n\\begin{tabular}{ p{7cm}<{\\centering}|p{7cm}<{\\centering}}\n\\hline \n \\begin{minipage}{0.5\\textwidth}\n      \t\\includegraphics[width=7cm,height=3.5cm]{figures/two-grids1.png}\n   \t \\end{minipage}\n    & \\begin{minipage}{0.5\\textwidth}\n      \t\\includegraphics[width=7cm,height=7cm]{figures/two-grids2.png}\n   \t \\end{minipage} \n\\\\\\hline\n  $\\phi_{i}^{2h}={1\\over 2} \\phi_{2i-1}^{h} + \\phi_{2i}^{h} + {1\\over 2} \\phi_{2i+1}^{h}$        &     { \\small$ \\phi_{i,j}^{2h} =\\phi_{2i,2j}^{h} \n+\\frac{1}{2}\\left(\\phi_{2i-1,2j-1}^{h} +\\phi_{2i+1,2j+1}^{h} \\right)\n+\\frac{1}{2}\\left(\\phi_{2i-1,2j}^{h} +\\phi_{2i,2j-1}^{h} \n+\\phi_{2i+1,2j}^{h} +\\phi_{2i,2j+1}^{2h} \\right)$}\n      \\\\\\hline\n  \\multicolumn{2}{c}{ $\\Phi^{2h}=R\\ast_2 \\Phi^h$  }    \\\\\\hline\n $R=({1\\over 2}, 1, {1\\over 2})$      &   $R=\\begin{pmatrix}\n0&{1\\over 2}&{1\\over 2}\\\\\n{1\\over 2}&1&{1\\over 2}\\\\\n{1\\over 2}&{1\\over 2}&0\n\\end{pmatrix}$       \\\\\\hline\n\\end{tabular}\n\\end{table}\n\n\\clearpage\n\n\n\n", "meta": {"hexsha": "f4d9807a2288b6b1767b890d9ed216ed83c50da4", "size": 3665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.5-1D2DFE_MgNet.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.5-1D2DFE_MgNet.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.5-1D2DFE_MgNet.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.9047619048, "max_line_length": 147, "alphanum_fraction": 0.5828103683, "num_tokens": 1629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7403729013617447}}
{"text": "\n\\subsection{Predictions}\n\nOur data \\((\\mathbf y, \\mathbf X)\\) is divided into \\((y_i, \\mathbf x_i)\\).\n\nWe create a function \\(\\hat y_i = f(\\mathbf x_i)\\).\n\nThe best predictor of \\(y\\) given \\(x\\) is:\n\n\\(g(X)=E[Y|X]\\)\n\nThe goal of regression is to find an approximation of this function.\n\n\\subsection{Residuals}\n\n\\(\\epsilon_i = y_i- \\hat y_i\\)\n\n\\subsection{Residual sum of squares (RSS)}\n\n\\(RSS=\\sum_i \\epsilon_i^2\\)\n\n\\(RSS=\\sum_i (y_i-\\hat y_i)^2\\)\n\n\\subsection{Explained sum of squares (ESS)}\n\n\\(ESS=\\sum_i (\\bar y-\\hat y_i)^2\\)\n\n\\subsection{Total sum of squares (TSS)}\n\n\\(TSS=\\sum_i (y_i-\\bar y)^2\\)\n\n\\subsection{Relationship between prediction and probability distribution}\n\n\\(P(y|X, \\theta )\\)\n\n\\(\\hat y =f(\\mathbf x)\\)\n\nThrough integration?\n\n\\(E[y] = \\int P(y|X, \\theta ) dy\\)\n\n", "meta": {"hexsha": "47aa868bd2c0229e6727adc8200907dc1ab664b5", "size": 784, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/parametric/01-01-prediction.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/parametric/01-01-prediction.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/parametric/01-01-prediction.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.6666666667, "max_line_length": 75, "alphanum_fraction": 0.6517857143, "num_tokens": 259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.793105953629227, "lm_q1q2_score": 0.7403095349971652}}
{"text": "\\chapter{Discrete Markov Chains}\n\\emph{“和女朋友在商场走散了，是在原地等碰到的概率大还是随机走碰到的概率大？急，在线等。”}\n\\newpage\n\n\n\\section{Finite Space Markov Chain}\n\n    \\subsection{Basic definitions}\n    % State Space\n    \\begin{definition}[State Space]\n        A \\textbf{state space} $\\mathcal{S}$ is a finite or countable set of states, i.e. the values that random variables $X_i$ may take on.\n    \\end{definition}\n    % Initial Distribution\n    \\begin{definition}[Initial Distribution]\n        The \\textbf{initial distribution} $\\pi_0$ is the probability distribution of the Markov Chain at time $0$. Denote $\\mathbb{P}[X_0 = i]$ by $\\pi_0(i)$.\n    \\end{definition}\n    \\begin{remark}\n        Formally, $\\pi_0$ is a function from $\\mathcal{S}$ to $[0,1]$ s.t.\n        \\[ \\pi_0(i) \\ge 0 \\text{ for all $i\\in\\mathcal{S}$} \\]\n        \\[ \\sum_{i\\in\\mathcal{S}} \\pi_0(i) = 1\\]\n    \\end{remark}\n    % Probability Transition Matrix\n    \\begin{definition}[Probability Transition Matrix]\n        The \\textbf{Transition Matrix} is a matrix $P = (p_{ij})$, where\n        \\[ p_{ij} = \\mathbb{P}[X_{n+1} = j | X_n = i] \\]\n        i.e. the probability given that the chain is at state $i$ at $T=n$ that jumps to $j$ at $T=n+1$\n    \\end{definition}\n    \\begin{remark}\n        ~{}\n        \\begin{itemize}\n            \\item The \\emph{rows} of $P$ sum up to $1$.\n            \\item The entries in $P$ are all non-negative.\n        \\end{itemize}\n    \\end{remark}\n\n    %%%%%%%% Markov Property\n    \\subsection{The Markov Property}\n    % Markov Property\n    \\begin{definition}[Markov Property]\n        We say a stochastic process $X_1, X_2, \\dots $ satisfies the \\textbf{Markov property} if \n        \\[ \\mathbb{P}[X_{n+1} = i_{n+1} | X_n = i_n, \\dots, X_0 = i_0] = \\mathbb{P}[X_{n+1} = i_{n+1} | X_n = i_n] \\]\n    \\end{definition}\n    That is, the \\emph{next} state $X_{n+1}$ depends only on the \\emph{current} state $X_n$.\n    % Time-homogeneity\n    \\begin{definition}[Time-homogeneous Markov Chain]\n        A Markov Chain is said to be \\textbf{time homogeneous} if\n        \\[ \\forall t \\quad \\mathbb{P}[X_{t+1} = j | X_t = i] = P(i,j) \\]\n    \\end{definition}\n    For now, we only consider \\emph{time homogeneous} Markov Chains.\n\n    %%%%%%%% Multistep Transition by Matrix Algebra\n    \\subsection{Matrix Interpretation of Markov Chains}\n    We now computes the probability distribution at $T=n+1$, denoted by $\\pi_{n+1}$.\n    \\[ \\pi_{n+1}(j) = \\mathbb{P}[X_{n+1} = j] = \\sum_{i=1}^N \\mathbb{P}[X_n=i]\\mathbb{P}[X_{n+1} = j | X_n = i] = \\sum_{i=i}^N \\pi_n(i)P(i,j)\\]\n    Therefore\n    \\[ \\pi_{n+1}^T = \\pi_n^T P \\]\n    \\[ \\pi_n^T = \\pi_0^T P^n \\]\n    We use $P(i,j)$ to denote the element $(i,j)$ of $P$, we use $P^n$ to denote the $n$-th power of $P$, and we assume that $\\pi_i$'s are column vectors.\n    % Chapman-Kolmogorov\n    \\begin{theorem}[Chapman-Kolmogorov Equality]\\label{thm:ChapmanKolmogorovEquality}\n        \\[ P^{m+n}(i,j) = \\sum_k P^m(i,k)P^n(k,j) \\]\n    \\end{theorem}\n\n\n\\section{Stationary Distribution}\n\n    % Stationary Distribution\n    \\begin{definition}[Stationary Distribution]\n        $\\pi$ is called a \\textbf{stationary distribution} of a Markov Chain if\n        \\[ \\pi^TP = \\pi \\]\n    \\end{definition}\n    \\begin{remark}\n        A Markov Chain may have 0, 1 or infinitely many stationary distribution.\n    \\end{remark}\n\n    \\emph{Here comes the question: When does a stationary distribution exist? If it exists, is it unique? If it is unique, does the chain converges to it?}\n\n\n\\section{Irreducibility, Aperiodicity and Recurrence}\nFor convenience, we will use $\\mathbb{P}_i[A]$ to denote $\\mathbb{P}[A | X_0 = i]$, and use $\\mathbb{E}_i$ to denote expectation in an analogous way.\n\n    %%%%%%%% Irreducibility\n    \\subsection{Irreducibility}\n    % Accessible\n    \\begin{definition}[Accessibility]\n        Let $i$, $j$ be two states, we say $j$ is \\textbf{accessible from} $i$ if it is possible (with positive probability) for the chain to ever visit $j$ if the chain starts from $i$.\n        \\[ \\mathbb{P}_i[\\bigcup_{n=0}^\\infty\\{X_n = j\\}] > 0 \\]\n        or equivalently\n        \\[ \\sum_{n=0}^\\infty P^n(i,j) = \\sum_{n=0}^\\infty \\mathbb{P}_i[X_n = j] > 0 \\]\n    \\end{definition}\n    % Communicate\n    \\begin{definition}[Communication]\n        We say $i$ \\textbf{communicates with} $j$ if $j$ is accessible from $i$ and $i$ is accessible from $j$.\n    \\end{definition}\n    % Irreducible\n    \\begin{definition}[Irreducibility]\n        We say a Markov Chain is \\textbf{irreducible} if all pairs of states communicate. And it is reducible otherwise.\n    \\end{definition}\n    The relation \\emph{communicate with} is an equivalent relation, and irreducible simply means the number of equivalent classes is 1.\n\n    %%%%%%%% Aperiodicity\n    \\subsection{Aperiodicity}\n    % Period\n    \\begin{definition}[Period]\n        Given a Markov Chain, its \\textbf{period} of state $i$ is defined to be the greatest common divisor $d_i$ of the lengths of loops starting from $i$.\n        \\[ d_i = \\gcd\\{n|P^n(i,i) > 0\\} \\]\n    \\end{definition}\n    % Period is a class property\n    \\begin{theorem}\n        If states $i$ and $j$ communicate, then $d_i = d_j$\n    \\end{theorem}\n    \\begin{sketchproof}\n        ~{}\n        \\begin{itemize}\n            \\item $P^{n_1}(i,j) > 0$ and $P^{n_2}(j,i) > 0$.\n            \\item $P^{n_1+n_2}(i,i)>0 \\Rightarrow d_i | n_1 + n_2$.\n            \\item Suppose $P^n{j,j} > 0$, then $P^{n+n_1+n_2}(i,i) > 0 \\Rightarrow d_i | n + n_1 + n_2$.\n            \\item $d_i | n \\Rightarrow d_j \\ge d_i$.\n            \\item Similarly $d_i \\ge d_j$. We are done.\n        \\end{itemize}\n    \\end{sketchproof}\n    \\begin{remark}\n        Therefore all states in a communicating class have the same period, and all states in an irreducible Markov chain have the same period.\n    \\end{remark}\n    % Aperiodic\n    \\begin{definition}[Aperiodicity]\n        An irreducible Markov chain is said to be \\textbf{aperiodic} if its period is 1, and periodic otherwise.\n    \\end{definition}\n    \\begin{proposition}\n        \\normalfont\n        If $P(i,i) > 0$, then the Markov Chain is aperiodic.\n    \\end{proposition}\n    \\begin{remark}\n        This is a sufficient but not necessary condition.\n    \\end{remark}\n\n    %%%%%%%% Recurrence\n    \\subsection{Recurrence}\n    We define the \\textbf{First Hitting Time} $T_i$ of the state $i$ by\n    \\[ T_i = \\inf\\{n>0 | X_n = i\\} \\]\n    and we can define recurrence as follows\n    % Recurrent\n    \\begin{definition}[Recurrence]\n        The state $i$ is \\textbf{recurrent} if $\\mathbb{P}_i[T_i<\\infty] = 1$, and is transient if it is not recurrent.\n    \\end{definition}\n    \\begin{remark}\n        Recurrence means that starting from state $i$ at $T=0$, the chain \\emph{is sure to} return to $i$ eventually.\n    \\end{remark}\n    % Recurrence is a class property\n    \\begin{theorem}\n        \\normalfont\n        Let $i$ be a recurrent state, and let $j$ be accessible from $i$, then all of the following hold:\n        \\begin{enumerate}\n            \\item $\\mathbb{P}_i[T_j < \\infty] = 1$.\n            \\item $\\mathbb{P}_j[T_i < \\infty] = 1$.\n            \\item The state $j$ is recurrent.\n        \\end{enumerate}\n    \\end{theorem}\n    \\begin{sketchproof}\n        ~{}\n        \\begin{itemize}\n            \\item The paths starting from $i$ can be seen as infinitely many \\emph{cycles}.\n            \\item Whether the chain visits $p$ in the cycles can be seen as a Bernoulli distribution with probability $p>0$.\n            \\item The probability of not visiting $j$ in the first $n$ cycles is $(i-p)^n$, which goes to $0$ as $n\\to\\infty$. So (1)hold.\n            \\item (2) can be proved by contradiction. $\\mathbb{P}_j[T_i < \\infty] < 1$ will lead to contradiction against the fact that $i$ is recurrent.\n            \\item (1)(2) implies (3).\n        \\end{itemize}\n    \\end{sketchproof}\n    \\begin{corollary}\n        If $\\mathbb{P}_i[T_j < \\infty] > 0$ but $\\mathbb{P}_j[T_i < \\infty] < 1$, then $i$ is transient.\n    \\end{corollary}\n    % Equivalent Statement of Recurrence\n    \\begin{theorem}[Equivalent Statement of Recurrence]\n        \\normalfont\n        The state $i$ is recurrent if and only if $\\mathbb{E}_i[N_i] = \\infty$, where $N_i = \\sum_{i=0}^\\infty\\mathbb{I}\\{X_n = i\\}$.\n    \\end{theorem}\n    \\begin{sketchproof}\n        ~{}\n        \\begin{itemize}\n            \\item Recurrence $\\Rightarrow \\mathbb{P}_i[N_i = \\infty] = 1 \\Rightarrow \\mathbb{E}_i[N_i] = \\infty$.\n            \\item The converse is proved by contradiction.\n            \\item If $i$ is transient, there is a chance of $p$ that the chain never return to $i$.\n            \\item So $N_i$ is distributed geometrically, and $\\mathbb{E}_i[N_i]$ will be finite. Contradiction.\n        \\end{itemize}\n    \\end{sketchproof}\n    \\begin{remark}\n        By taking expectation on $N_i$, we have:\n        \\[ \\mathbb{E}_i[N_j] = \\sum_{i=0}^\\infty P^n(i,j) \\]\n    \\end{remark}\n\n    \\begin{corollary}\\label{TransientStateGoesToZero}\n        If $j$ is transient, then $\\lim_{n\\to\\infty}P^n(i,j) = 0$ for all states $i$.\n    \\end{corollary}\n    \\begin{sketchproof}\n        ~{}\n        \\begin{itemize}\n            \\item $\\mathbb{E}_j[N_j] < \\infty$.\n            \\item $\\mathbb{E}_i[N_j] = \\mathbb{P}_i[T_j < \\infty]\\mathbb{E}_i[N_j | T_j < \\infty]$.\n            \\item $\\mathbb{E}_i[N_j] \\le \\mathbb{E}_i[N_j | T_j] = \\mathbb{E}_j[N_j] < \\infty$ since the probability \\emph{restarts} once the chain visits $j$ again.\n            \\item $\\mathbb{E}_i[N_j] = \\sum_{i=0}^\\infty P^n(i,j) < \\infty$ and this implies our conclusion.\n        \\end{itemize}\n    \\end{sketchproof}\n\n    \\begin{corollary}\n        If $i$ is recurrent, then $\\sum_{n=1}^{\\infty}p^n(i,i) = \\infty$;\n\n        If $i$ is transient, then $\\sum_{n=1}^{\\infty}p^n(i,i) < \\infty$.\n    \\end{corollary}\n\n    \\begin{proposition}\n        Suppose a Markov Chain has a stationary distribution $\\pi$, if the state $j$ is transient, then $\\pi(j) = 0$.\n    \\end{proposition}\n    The last proposition follows from Corollary \\ref{TransientStateGoesToZero}.\n\n    \\begin{corollary}\n        If an irreducible Markov Chain has a stationary distribution, then the chain is recurrent.\n    \\end{corollary}\n    \\begin{sketchproof}\n        The chain cannot be transient, or otherwise all $\\pi(j)$ would be 0 and the sum of $\\pi$ does not equal to 1.\n    \\end{sketchproof}\n    \\begin{remark}\n        The converse is not true!\n    \\end{remark}\n\n    \\begin{proposition}\n        A drunk man will find his way home, but a drunk bird may get lost forever.\n    \\end{proposition}\n    This is because the random walk on $\\mathbb{Z}$ and $\\mathbb{Z}^2$ is recurrent, while the walks on higher dimensions are transient.\n\n    %%%%%%%% More on Recurrence\n    \\subsection{More on Recurrence}\n    % Null Recurrence\n    \\begin{definition}[Null Recurrence]\n        The state $i$ is \\textbf{null recurrent} if it is recurrent and $\\mathbb{E}_i[T_i] = \\infty$.\n    \\end{definition}\n    % Positive Recurrence\n    \\begin{definition}[Positive Recurrence]\n        The state $i$ is \\textbf{positive reccurent} it is recurrent and $\\mathbb{E}_i[T_i] < \\infty$.\n    \\end{definition}\n\n    \\begin{proposition}\n        Given an irreducible Markov Chain, it is either transient, null recurrent or positive recurrent.\n    \\end{proposition}\n\n\n\n\\section{Strong Law of Large Numbers of Markov Chains}\n% SLLN of Markov Chains\n\\begin{theorem}[SLLN of Markov Chains]\\label{SLLN}\n    Let $X_0, X_1, \\dots$ be a Markov Chain starting in the state $X_0=i$. Suppose state $i$ communicates with state $j$. The limiting fraction of time that the chain spends in $j$ is $\\frac{1}{\\mathbb{E}_j[T_j]}$.\n    \\[ \\mathbb{P}_i[\\lim_{n\\to\\infty}\\frac{1}{n}\\sum_{t=1}^n\\mathbb{I}\\{X_t=j\\} = \\frac{1}{\\mathbb{E}_j[T_j]}] = 1 \\]\n\\end{theorem}\n\\begin{sketchproof}\n    Read the book. I'm not going to write this because I am lazy.\n\\end{sketchproof}\n\n\n\\section{Basic Limit Theorem}\\label{BasicLimitTheorem}\naka. Foundamental Theorem of Markov Chains\n\n    %%%%%%%% Finite Case\n    \\subsection{Finite State Space}\n    % Spectral Radius\n    \\begin{definition}[Spectral Radius]\n        Given a non-negative matrix $A$, the spectral radius $\\rho(A)$ is the maximum norm of its eigenvalues\n        \\[ \\rho(A) = \\max\\{ \\lambda(A) \\} \\]\n    \\end{definition}\n    \\begin{proposition}\n        Let $A$ be a non-negative matrix, then\n        \\[ \\min_{1\\le i \\le n} \\sum_{j=1}^N a_{i,j} \\le \\rho(A) \\le \\max_{1\\le i \\le n} \\sum_{j=1}^N a_{i,j} \\]\n    \\end{proposition}\n    % Perron-Frobenius Theorem\n    \\begin{lemma}[Perron-Frobenius Theorem]\\label{PFT}\n        Let $A$ be a non-negative matrix with spectral radius $\\rho(A) = \\alpha$, then $\\alpha$ is an eigenvalue of $A$, and has both left and right non-negative eigenvectors.\n    \\end{lemma}\n    \\begin{remark}\n        Lemma \\ref{PFT} implies that for a finite probability transition matrix $P$, it always has at least one stationary distribution, because it always has eigenvalue $1$ ($P\\mathbf{1} = \\mathbf{1}$) and a corresponding eigenvector $\\pi$ s.t. $\\pi^TP = \\pi$.\n    \\end{remark}\n\n    \\begin{lemma}\n        Suppose a $k \\times k$ matrix $P$ is irreducible. Then there exists a unique solution to $\\pi P = \\pi$.\n    \\end{lemma}\n    % Foundamental Theorem, Finite Case\n    \\begin{theorem}[Foundamental Theorem, Finite Case] If a finite Markov Chain is \\emph{irreducible} and \\emph{aperiodic}, then it has a \\emph{unique stationary distribution} $\\pi$ any initial distribution \\emph{converges} to it:\n        \\[ \\forall \\pi_0,\\quad \\lim_{t\\to\\infty}\\pi_0^T P^t = \\pi^T \\]\n    \\end{theorem}\n\n    %%%%%%%% Countable Case\n    \\subsection{Countable Case}\n    % Basic Limit Theorem\n    \\begin{theorem}[Basic Limit Theorem]\n        Let $X_1, X_2, \\dots$ be an \\emph{irreducible aperiodic} Markov Chain that has a \\emph{stationary distribution} $\\pi$. Then\n        \\[ \\lim_{n\\to\\infty}\\pi_n(i) = \\pi(i) \\]\n        for any state $i$ and for any initial distribution $\\pi_0$.\n    \\end{theorem}\n    % Bounded Convergence Theorem\n    \\begin{lemma}[Bounded Convergence Theorem]\\label{BCT}\n        If $X_n \\to X$ with probability $1$ and there is a finite number $b$ such that $|X_n| < b$ for all $n$, then\n        \\[ \\mathbb{E}[X_n] \\to \\mathbb{E}[X] \\]\n    \\end{lemma}\n    % Corollary of SLLN\n    Recall SLLN \\ref{SLLN}, and the following is a corollary.\n    \\begin{corollary}\\label{SLLNCoro}\n        For an \\emph{irreducible} Markov Chain, we have\n        \\[ \\lim_{n\\to\\infty} \\frac{1}{n}\\sum_{t=1}^n P^t(i,j) = \\frac{1}{\\mathbb{E}_j[T_j]} \\]\n    \\end{corollary}\n    \\begin{sketchproof}\n        Take expectations on both sides of Theorem \\ref{SLLN} yields the conclusion.\n    \\end{sketchproof}\n    % Cesaro Average\n    \\begin{proposition}[Cesaro Average]\n        If a sequence of numbers $a_n$ converges to a value $a$, then the \\textbf{Cesaro Average} $(1/n)\\sum_{t=1}^na_t$ also converges to it.\n    \\end{proposition}\n    Corollary \\ref{CesaroCoro} follows immediately from the proposition,\n    \\begin{corollary}\\label{CesaroCoro}\n        For an \\emph{irreducible aperiodic} Markov Chain with a \\emph{stationary distribution},\n        \\[ \\lim_{n\\to\\infty}\\frac{1}{n}\\sum_{t=1}^nP^t(i,j) \\to \\pi(j) \\]\n    \\end{corollary}\n    \\begin{theorem}\n        An \\emph{irreducible, aperiodic} Markov Chain with a \\emph{stationary distribution} has a stationary distribution given by\n        \\[ \\pi(j) = \\frac{1}{\\mathbb{E}_j[T_j]} \\]\n    \\end{theorem}\n    \\begin{sketchproof}\n        The proof of the theorem is trivial: compare Corollary \\ref{SLLNCoro} and \\ref{CesaroCoro}.\n    \\end{sketchproof}\n    % Foundamental Theorem, Countable Case\n    \\begin{theorem}[Foundamental Theorem, Countable Case]\\label{theorem:FTMC-Countable}\n        An \\emph{irreducible} Markov Chain has a \\emph{unique stationary distribution} given by\n        \\[ \\pi(j) = \\frac{1}{\\mathbb{E}_j[T_j]} \\]\n        if and only if it is \\emph{positive recurrent}.\n    \\end{theorem}\n\n    %%%%%%%% Other Conclusions\n    \\subsection{Other Conclusions}\n    \\emph{Since they are not covered in class, no proof will be provided. I'm lazy you know.}\n    \\begin{definition}[Doubly Stochastic Chains]\n        A transition matrix $P$ is said to be \\textbf{doubly stochastic} if all of its columns sum up to 1.\n    \\end{definition}\n    \\begin{optTheorem}\n        For a doubly stochastic Markov Chain with $N$ states, the uniform distribution $\\pi(i) = 1/N$ is a stationary distribution.\n    \\end{optTheorem}\n    \\begin{optTheorem}\n        For a Markov Chain with symmetric $P$ and $N$ states, the uniform distribution $\\pi(i) = 1/N$ is a stationary distribution.\n    \\end{optTheorem}\n    \\begin{optTheorem}\n        Let $T_j^k = \\min\\{ n > T_y^{k-1} | X_n = y \\}$ be the time of the $k$-th visit to $j$, then by the Markov property,\n        \\[ \\mathbb{T}_x[T_y^k < \\infty] = \\mathbb{P}_x[T_y < \\infty]\\cdot\\mathbb{P}_y[T_y<\\infty] \\]\n        Notice that\n        \\[ \\mathbb{E}[X] = \\sum_{k=0}^{\\infty}\\mathbb{P}[X \\le k] \\]\n        Using the two equations, we have\n        \\[ \\mathbb{E}_x[N_y] = \\frac{\\mathbb{P}_x[T_y < \\infty]}{1-\\mathbb{P}_y[T_y < \\infty]} \\]\n    \\end{optTheorem}\n    \\begin{remark}\n        This theorem gives us more insights into the results in Section \\ref{BasicLimitTheorem}.\n    \\end{remark}\n\n\n\n\\section{Examples}\n\n    %%%%%%%% Galton-Watson Process\n    \\subsection{Galton-Watson Process}\\label{sub:BranchingProcess}\n    \\emph{aka. Branching Process}\n    \\paragraph*{Problem.} What is the probability that a family name eventually extincts?\n    \\paragraph*{Notations.}\n    \\begin{itemize}\n        \\item $G_t$ denotes the number of males in generation $t$.\n        \\item $X_{tk}$ denotes the number of sons fathered by the $k$-th father in the $t$-th generation. Assume $X_{tk}$ are \\emph{iid} with $\\mathbb{P}[X_{tk}=i]=p(i)$.\n        \\item $\\rho = \\mathbb{P}[extinction] = \\mathbb{P}[\\cup_{k\\ge 1}\\{ G_k=0 \\}]$ denotes the probability that the family name eventually goes extinct.\n        \\item $q_t = \\mathbb{P}[G_t = 0]$ denotes the probability that the family name goes extinct at the $t$-th generation.\n    \\end{itemize}\n    The problem is trivial when $p(0) = 0$ or $p(0) + p(1) = 1$. Either the family name never goes extinct or it goes extinct almost surely. We consider $p(0) > 0$ and $p(0) + p(1) < 1$.\n\n    By conditioning on what happens at the first step, we can calculate $\\rho$ by\n    \\[ G_{t+1} = \\sum_{i=1}^{G_t} X_{ti} \\]\n    \\begin{align}\n    \\rho &= \\sum_{k=0}^{\\infty}\\mathbb{P}[extinction \\wedge  G_1 = k] \\notag \\\\\n    &= \\sum_{k=0}^{\\infty}\\mathbb{P}[extinction | G_1 = k]\\cdot\\mathbb{P}[G_1 = k | G_0 = 1] \\quad \\text{(by 全概率公式)} \\notag \\\\\n    &= \\sum_{k=0}^{\\infty}p(k)\\rho^k \\triangleq \\psi(\\rho) \\notag\n    \\end{align}\n    The last step used the fact that all males have sons independently. $\\psi(\\rho)$ is called the \\textbf{Probability Generating Function} of $p(\\cdot)$.\n\n    \\begin{definition}[Probability Generating Function]\n        The probability generating function of $X$ is given by\n        \\[ G_X(z) \\triangleq \\mathbb{E}[z^X] = \\sum_{k=0}^{\\infty}\\mathbb{P}[X=k]z^k \\]\n    \\end{definition}\n\n    The probability of eventual extinction satisfies $\\psi(\\rho) = \\rho$.\n    \\[ \\psi'(z) = \\sum_{k=1}^{\\infty}kp(k)z^{k-1} > 0\\]\n    \\[ \\psi''(z) = \\sum_{k=2}^{\\infty}k(k-1)p(k)z^{k-2} > 0 \\]\n    So $\\psi(z)$ is a strictly increasing convex function with the following properties.\n    \\begin{itemize}\n        \\item $\\psi(1) = 1$. So $\\rho = 1$ is always a solution.\n        \\item $\\psi'(1) = \\sum_{k=1}^{\\infty}kp(k) = \\mathbb{E}[X] \\triangleq \\mu$\n    \\end{itemize}\n    \\begin{enumerate}[(i)]\n        \\item If $\\mu \\le 1$, $\\rho = 1$ is the only solution. Therefore the family name will go extinct.\\footnote{This can be better understood by plotting a sketch of $\\psi$.}\n        \\item If $\\mu > 1$, there exists another solution $r<1$.\n        \n        Observe that $\\{ G_t = 0 \\} \\subseteq \\{ G_{t+1} = 0 \\}$ and $q_t \\le q_{t+1}$. Since $q_t$ has a upper bound $\\rho$, it will always converge.\n        \\[ q_t \\uparrow \\rho \\]\n        So we only need to prove $\\forall t \\quad q_t < r$. By induction,\n        \\begin{itemize}\n            \\item[base.] $q_0 = 0 < r$.\n            \\item[hypo.] $q_t < r$.\n            \\item[step.] $q_{t+1} = \\sum_{i=0}^{\\infty}\\mathbb{P}[G_1 = i]\\mathbb{P}[G_{t+1} = 0| G_1 = i] = \\sum_{i=0}^{\\infty}p(i)(q_t)^i$. The last step used the iid assuption of $X$. \n            Therefore $q_{t+1} = \\psi(q_t) \\le \\psi(r) = r$. Done.\n        \\end{itemize} \n    \\end{enumerate}\n\n    %%%%%%%% Gambler's Ruin\n    \\subsection{Gambler's Ruin}\\label{GamblerRuin}\n    \\paragraph*{Problem.} Consider a gambler in a casino, who has probability $p$ to win \\$$1$ and $1-p$ to lose \\$$1$. The process stops when the gambler gets \\$$N$ or loses all his money. Assume the gambler starts the game with \\$$i$.\n    \\paragraph*{Notations.}\n    \\begin{itemize}\n        \\item $P_i$ denotes the probability of the gambler gets \\$$N$ and wins, starting with \\$$i$.\n        \\item $Z_i \\in \\{1, -1\\}$ denotes whether the gambler wins or loses in round $i$.\n        \\[ X_t = X_0 + \\sum_{i=0}^{t-1}Z_i \\]\n    \\end{itemize}\n    Obviously,\n    \\[ P_N = 1 \\quad P_0 = 0 \\]\n    When $1 \\le i \\le N-1$, $P_i$ can be calculated by\n    \\begin{align*}\n        P_i &= \\mathbb{P}[win | X_0 = i] \\\\\n        &= \\mathbb{P}[win \\wedge Z_0 = 1 | X_0 = i] + \\mathbb{P}[win \\wedge Z_0 = -1 | X_0 = i] \\quad \\text{(Again by 全概率公式 on $Z_i$)} \\\\\n        &= \\mathbb{P}[win | X_0=i, Z_0 = 1]\\cdot\\mathbb{P}[Z_0=1|X_0=i] + \\mathbb{P}[win|X_0=1, Z_0=-1]\\cdot\\mathbb{P}[Z_0=-1|X_0=i] \\\\\n        &= p\\cdot P_{i+1} + (1-p)\\cdot P_{i-1}\n    \\end{align*}\n    Rearranging,\n    \\[ p(P_{i+1} - P_i) = (1-p)(P_i - P_{i-1}) \\]\n    \\[ P_{i+1} -P_i = \\frac{1-p}{p}(P_i - P_{i-1}) \\]\n    Let $\\theta = \\frac{1-p}{p}$, by high school mafs\n    \\[ P_{i+1} - P_i = \\theta^i(P_1 - P_{0}) \\]\n    \\begin{enumerate}[(i)]\n        \\item Assume for now that $p \\neq \\frac{1}{2}$ so $\\theta \\neq 1$, then summing over $i$ yields\n        \\[ P_N - P_0 = 1 = \\frac{1-\\theta^N}{1-\\theta} P_1 \\]\n        Therefore\n        \\[ P_1 = \\frac{1-\\theta}{1-\\theta^N} \\]\n        Summing from $0$ to $i$ yields\n        \\[ P_i = \\frac{1-\\theta^i}{1-\\theta^N} \\]\n        \\item If $p=\\frac{1}{2}$,\n        \\[ P_{i+1} - P_i = P_i - P_{i-1} \\]\n        This is a arithmetic progress, and again by high school mafs\n        \\[ P_i = \\frac{i}{N} \\]\n    \\end{enumerate}\n    To sum up\n    \\[ \n        P_i = \n        \\begin{cases}\n            \\frac{i}{N} &(i = \\frac{1}{2})\\\\\n            \\frac{1-\\theta^i}{1-\\theta^N} &(\\text{o.w.})\n        \\end{cases}    \n    \\]\n\n    \\subsection{Drug Test}\\label{DrugTest}\n    This example is based on results from the previous subsection \\ref{GamblerRuin}.\n    \\paragraph*{Problem.} We want to test the cure rate $p_1$ of a drug \\textrm{Drug}1. We already have a \\textrm{Drug}2 with known cure rate $p_2$. We want to know whether $p_1 > p_2$ or not. To do this, we find $t$ pairs of patients $(X_i, Y_i)$ and conduct tests using the two drugs on $X$ and $Y$ respectively. Once the number of patients who are cured by \\textrm{Drug}1 but not \\textrm{Drug}2 exceeds a certain threshold $M$, we can claim that $p_1 \\ge p_2$.\n    \\paragraph*{Notations.}\n    \\begin{itemize}\n        \\item $X_i,Y_i \\in \\{0,1\\}$ is a boolean denoting whether the first or the second drug cured patient $i$.\n        \\item $Z_i = X_i - Y_i$.\n        \\item $p_1, p_2$ denotes the probability that the two drugs cure a patient, respectively.\n    \\end{itemize}\n\n    The value of $Z_i$ falls into 3 cases:\n    \\[ Z_i = \n        \\begin{cases}\n            1 &p_1(1-p_2)\\\\\n            -1 &p_2(1-p_1)\\\\\n            0 &(\\text{o.w.})\n        \\end{cases}\n    \\]\n    If we ignore the cases where $Z_i = 0$, then we can model this problem as a gambler's ruin, with $p = \\frac{p_1(1-p_2)}{p_1(1-p_2)+p_2(1-p_1)}$.\n\n    And\n    \\[ \\mathbb{P}[TestWrong] = 1 - \\frac{1-\\theta^M}{1-\\theta^{2M}} = \\frac{1}{\\theta^{-M} + 1} \\]\n    The probability above drops exponentially with $M$, so the threshold does not need to be very large to achieve accurate results.\n\n    %%%%%%%% Another random walk on N\n    \\subsection{Another Random Walk}\\label{AnotherRandWalk}\n    \\paragraph*{Problem.} Consider a random walk on $\\mathbb{N}$ where\n    \\[ P(0,1) = 1 \\quad P(N,N) = 1 \\]\n    We want to compute how many steps we need to reach $N$ starting from $i$.\n    \\paragraph*{Notations.}\n    \\begin{itemize}\n        \\item $h_i$ denotes the expectation of steps to reach $N$ starting from $X_0=i$.\n        \\item $Y_i$ denotes the number of steps from $i$ to $i+1$ for the first time.\n        \\item $g_j \\triangleq \\mathbb{E}[Y_j]$.\n    \\end{itemize}\n    Obviously\n    \\[ \\mathbb{E}[h_0] = 1 + \\mathbb{E}[h_1] \\quad \\mathbb{E}[h_N] = 0 \\]\n    Similar to subsection \\ref{DrugTest},\n    \\[ h_i = 1+ (1-p)h_{i-1} + ph_{i+1} \\]\n    This can be calculated using \\emph{the linearity of expectation}. \n\n    Notice that\n    \\[ h_i = \\sum_{j=i}^{N-1}Y_j \\]\n    Taking expectations on both sides\n    \\[ \\mathbb{E}[h_i] = \\sum_{j=i}^{N-1}\\mathbb{E}[Y_j] \\]\n    So we only need to caculate $\\mathbb{E}[Y_j]$.\n    \\begin{itemize}\n        \\item $g_0 = 1$.\n        \\item $g_i = 1 + 0 \\cdot p + (1-p)(g_{i-1}+g_i)$.\n    \\end{itemize}\n    \\begin{enumerate}\n        \\item Again assume $p \\neq \\frac{1}{2}$. \n        Rearranging yields\n        \\[ g_i = \\frac{1}{p} + \\theta g_{i-1} \\]\n        and after a few steps of arithmetics\n        \\[ g_i = \\sum_{i=0}^{t-1}\\frac{1}{p}\\theta^i + \\theta^t \\]\n        Summing over $g_i$ is a sum of geometric progress, easy.\n        \\item If $p = \\frac{1}{2}$, then\n        \\[ g_{i} - g_{i-1} = \\frac{1}{p} = 2 \\]\n        so\n        \\[ g_t = 2t + 1 \\]\n        and\n        \\[ \\mathbb{E}[h_0] = \\sum_{t=0}^{N-1}(2t+1) = N^2 \\]\n    \\end{enumerate}\n    \\begin{remark}\n        As the converse of the conclusion, if we take $N$ steps, the farthest distance we can go is $\\sqrt{N}$.\n    \\end{remark}\n\n    \\subsection{Yet Another Random Walk}\n    Consider a random walk on $\\mathbb{N}$ with\n    \\begin{align*}\n        p(i,i+1) &= p\\\\\n        p(i,i-1) &= 1-p\\\\\n        p(0,0) &= 1-p\n    \\end{align*}\n    We are going to prove that if $p > 1/2$, the chain is transient, and if $p \\le 1/2$, the chain is recurrent.\n    Let $V_i = \\min\\{ n\\le0 | X_n = i \\}$ denote the time of the first visit to state $i$. \n    Let $h(x) = \\mathbb{P}_x(V_N<V_0) (N > 0)$ denote the probability of a Markov chain starting from the state $x$ to \\emph{reach state $N$ before it reaches state $0$}.\n\n    By definition of the random walk, for all $1 \\le x \\le N-1$:\n    \\begin{equation}\n        \\notag\n        h(x) = ph(x+1) + (1-p)h(x-1)\n    \\end{equation}\n    and\n    \\[ h(0) = 0 \\quad h(N) = 1 \\]\n\n    Rearranging gives us:\n    \\begin{equation}\n        \\label{eq3.1}\n        p[h(x+1) - h(x)] = (1-p)[h(x) - h(x-1)]\n    \\end{equation}\n    \\[ h(x+1) - h(x) = \\frac{1-p}{p}[h(x) - h(x-1)] \\]\n\n    So $a(x) = h(x) - h(x-1)$ is a geometric series with $a(1) = h(1) - h(0) = h(1)$.\n    \\[ a(x) = h(x+1) - h(x) = a(1) \\cdot (\\frac{1-p}{p})^{x-1} \\]\n\n    Summing over $x = 1$ to $N$ yields: \n    \\[ h(N) - h(0) = a(1) \\cdot \\sum_{i = 1}^{N}(\\frac{1-p}{p})^i \\]\n\n    Notice that $h(N) - h(0) = 1$, we can solve for $a(1)$:\n    \\[ a(1) = \\frac{1-\\theta}{1-\\theta^N} \\]\n    where $\\theta = \\frac{1-p}{p}$.\n\n    Therefore:\n    \\begin{equation}\n        \\notag\n        h(x) = a(1)\\sum_{i=1}^{x}(\\theta^i) = \\frac{1-\\theta}{1-\\theta^N} \\cdot \\frac{1-\\theta^x}{1-\\theta} = \\frac{1-\\theta^x}{1-\\theta^N}\n    \\end{equation}\n\n    To briefly sum up:\n    \\begin{equation}\n        \\label{eq3.2}\n        \\mathbb{P}_x[V_N < V_0] = \\frac{1-\\theta^x}{1-\\theta^N}\n    \\end{equation}\n    where $\\theta = \\frac{1-p}{p}$.\n\n    We now consider different cases of $p$.\n    \\begin{enumerate}\n        \\item $p > \\frac{1}{2}$.\\\\\n        The case where $p=1$ is trivial because the chain simply keeps going right and never returns, so any state in the chain is transient.\n\n        When $\\frac{1}{2} < p < 1$, the chain is irreducible. If we can prove that one state in the chain is transient, then all states in the chain must also be transient. WLOG, we will prove that the state $0$ is transient.\n\n        Suppose the chain starts from $0$, it cannot stay in state $0$ forever, because $(1-p)^n \\to 0$ as $n\\to\\infty$, so it will leave $0$ and visit $1$. We are going to prove that once the chain reaches $1$ from $0$, there is a probability that it will never return to $0$ again, and $0$ is therefore transient.\n\n        Plug in $x=1$ into (\\ref{eq3.2}) and let $N \\to \\infty$. Since $p > \\frac{1}{2}$, $\\theta < 1$, $\\theta^N \\to 0$.\n        \\[ \\mathbb{P}_1[V_0 = \\infty] = 1-\\theta \\]\n        That is, there is a probability of $1-\\theta$ that the chain reaches infinity before it returns to $0$, i.e. the chain is never returning to $0$ again. Therefore it is transient.\n\n        \\item $p \\le \\frac{1}{2}$.\\\\\n        We first consider the case where $p < \\frac{1}{2}$.\n\n        Similarly, we only need to prove that $0$ is recurrent, since the chain is irreducible. Again, the chain cannot stay in $0$ forever, and once it reaches $1$ from $0$, we can compute $\\mathbb{P}_1[V_0 = \\infty]$ by letting $N$ go to infinity. This time, since $p < \\frac{1}{2}$, $\\theta > 1$ and $\\theta^N \\to \\infty$, therefore,\n        \\[ \\mathbb{P}_1[V_0 = \\infty] = 0 \\]\n        That is, the chain will return to $0$ with probability $1$, and it is therefore recurrent.\n\n        When $p = \\frac{1}{2}$, $\\theta = 1$, (\\ref{eq3.2}) has a division by zero and cannot be used. We now consider (\\ref{eq3.1}). Since $p=\\frac{1}{2}$, $p = (1-p)$, they cancelled each other,\n        \\[ h(x+1) - h(x) = h(x) - h(x-1) \\]\n        So $h(x)$ is an arithmetic progression. Since $h(0)=0$ and $h(N)=1$, it must has the form of\n        \\[ h(x) = \\frac{x}{N} \\]\n        \n        Again plugging in $x=1$ and letting $N \\to \\infty$,\n        \\[ \\mathbb{P}_1[\\infty < V_0] = 0 \\]\n        Therefore it is still recurrent when $p = \\frac{1}{2}$.\n\n        \\item $p = \\frac{1}{2}$.\\\\\n        Let $\\tau$ be the \\emph{exit time} defined as $\\tau = \\min\\{ n | X_n \\notin (0,N) \\}$, i.e. the minimum time for the chain to be either in state $0$ or state $N$. EOSP claimed that\n        \\begin{equation}\n            \\label{claim}\n            \\mathbb{E}_x[\\tau] = x(N-x)\n        \\end{equation}\n\n        Let $g(x) = \\mathbb{E}_x[\\tau]$, since $p = \\frac{1}{2}$:\n        \\begin{equation}\n            \\label{gx}\n            g(x) = 1 + \\frac{1}{2}g(x+1) + \\frac{1}{2}g(x-1)\n        \\end{equation}\n        \n        We can verify (\\ref{claim}) by plugging $g(x) = x(N-x)$ into (\\ref{gx}).\n        \\begin{align}\n            RHS &= 1 + 0.5(x+1)(N-x-1) + 0.5(x-1)(N-x+1) \\notag \\\\\n            &= 1 + Nx - x^2 -1 \\notag \\\\\n            &= Nx - x^2 = LHS \\notag\n        \\end{align}\n\n        Therefore $\\mathbb{E}_x[\\tau] = x(N-x)$. Then we can again follow our previous proofs: plug in $x=1$ and let $N\\to\\infty$, which yields\n        \\[ \\mathbb{E}_1[\\tau] \\to \\infty \\quad n \\to \\infty \\]\n        That is, $\\mathbb{E}_1[V_0] = \\infty$.\n\n        Then we can calculate $\\mathbb{E}_0[T_0]$:\n        \\[ \\mathbb{E}_0[T_0] = \\frac{1}{2}\\times 1 + \\frac{1}{2}\\mathbb{E}_1[V_0] = \\infty \\]\n        Therefore the chain is null recurrent when $p=\\frac{1}{2}$.\n\n        \\item $p<\\frac{1}{2}$.\\\\\n        EOSP claimed that\n        \\[ \\mathbb{E}_x[\\tau] = \\frac{x}{1-2p}-\\frac{N}{1-2p}\\cdot\\frac{1-\\theta^x}{1-\\theta^N} \\]\n        This claim can be verified by plugging it into and checking that the two sides of the equation are equal.\n        \\[ g(x) = 1 + pg(x+1) + (1-p)g(x-1) \\]\n\n        Plug in $x=1$ and let $N\\to\\infty$.\n        \\[ \\frac{N}{1-\\theta^N} \\to 0\\]\n        \\[ \\mathbb{E}_1[\\tau] \\to \\frac{1}{1-2p} \\quad n \\to \\infty \\]\n\n        Similarly,\n        \\[ \\mathbb{E}_0[T_0] = (1-p) \\times 1 + p \\cdot \\frac{1}{1-2p} < \\infty \\]\n        $\\mathbb{E}_0[T_0] < \\infty$. Therefore the chain is positive recurrent when $p < \\frac{1}{2}$.\n    \\end{enumerate}\n\n\n\n\\section{Coupling and Stochastical Dominance}\nIn this section we assume the sample space $\\Omega$ is at most countable, but the results in this section can be generalized to continuous case.\n\n    %%%%%%%% Motivating Example: 2-SAT\n    \\subsection{Motivating Example: 2-SAT}\n        Recall the SAT problem in \\textsc{AI2615 Design and Analysis of Algorithms}. A 2-SAT is a special case of SAT where each \\verb|or| expression has at most 2 terms\n        \\[ \\varphi = (x_1 \\vee y_1) \\wedge (x_2 \\vee y_2) \\cdots \\]\n        The problem is RP and can be solved using the following algorithm.\n\n        \\verb|Expected Algorithm, but not found.| It's here: Algorithm \\ref{algo:2SATAlgo}.\n\n        \\begin{algorithm}\n            \\caption{2-SAT Solver}\n            \\KwIn{CNF with $n$ terms}\n            Random intialize a solution $\\sigma$.\\\\\n            \\For{$i = 1:100n^2$}\n            {\n                \\If{$\\sigma$ satisfies CNF}\n                {\n                    \\KwRet{$\\sigma$}\n                }\n                \\Else\n                {\n                    Randomly choose one term $(X_i \\vee Y_i)$ that is false.\\\\\n                    Randomly flip $X_i$ or $Y_i$.\n                }\n            }\n            \\KwRet{Not satisfiable}\n            \\label{algo:2SATAlgo}\n        \\end{algorithm}\n\n        To prove its correctness, we only need to consider the cases where the CNF is indeed satisfiable with solution $\\sigma$. We denote the sequence of attempts produced by the algorithm by\n        \\[ \\sigma_0 \\to \\sigma_1 \\to \\cdots \\to \\sigma_{100n^2} \\]\n        Let $X_i$ denotes the number of terms in $\\sigma$ and $\\sigma_i$ that are exactly the same.\n\n        You should convince yourself that $X_0, X_1, \\dots$ is not a Markov Chain. \\sout{So we get stuck}. However we can still informally show the correctness.\n\n        Notice that if the CNF is not satisfiable, the algorithm will always give the correct answer. So we only consider the case where the CNF is indeed satisfiable, but the algorithm fails to find the solution.\n\n        We first introduce some basic concepts.\n\n    %%%%%%%% Stochastic Dominance\n    \\subsection{Stochastic Dominance}\n        \\begin{definition}[Stochastic Dominance]\n            A distribution $\\mu$ is said to \\textbf{stochasitcally dominate} $\\nu$ if\n            \\[ \\forall x\\quad \\mathbb{P}_{X\\sim\\mu}[X \\ge x] \\ge \\mathbb{P}_{Y\\sim\\nu}[Y \\ge x] \\]\n        \\end{definition}\n        \\begin{remark}\n            Let $F$ and $G$ be the cumulative distribution function of $X$ and $Y$, we have $F(x) \\le G(x)$, i.e. the probability of $X$ concentrates on larger values.\n        \\end{remark}\n        \\paragraph{Some Examples.}\n        \\begin{itemize}\n            \\item 2-SAT.\n            \\item Binomial distribution. $B(n,p)$ and $B(n,q)$.\n            \\item Erd$\\mathrm{\\ddot{o}}$s-R$\\mathrm{\\acute{e}}$nyi Random Graph $\\mathcal{G}(n,p)$ is a graph with $n$ nodes and the edges have a probability of $p$ to exist. We sample $G$ randomly from $\\mathcal{G}$ and test if $G$ is connected. If $p>q$ then $G_p$ stocahstically dominates $G_q$.\n        \\end{itemize}\n\n    %%%%%%%% Coupling\n    \\subsection{Coupling}\n        \\begin{definition}[Coupling]\n            $(X',Y')$ is the coupling of random variables $(X,Y)$ if $X'$ has the same distribution of $X$ and $Y'$ has the same distribution as that of $Y$. i.e. A coupling $C$ of $X$ and $Y$ is a joint distribution of $X$ and $Y$.\n        \\end{definition}\n        \\begin{remark}~{}\n            \\begin{itemize}\n                \\item The coupling of $X$ and $Y$ is not unique.\n                \\item If $X$ has distribution $\\mu$ and $Y$ has distribution $\\nu$, then any joint distribution $(X,Y)$ having marginal distribution $X\\sim\\mu$ and $Y\\sim\\nu$ is a coupling of $X$ and $Y$.\n                \\[ \\forall x, \\quad \\mathbb{P}_{(X,Y) \\sim C}[X=x] = \\mu(x) \\]\n                \\[ \\forall y, \\quad \\mathbb{P}_{(X,Y) \\sim C}[Y=y] = \\nu(y) \\]\n                \\item Constructing a coupling can be intuitively seen as a process of filling a table of the joint distribution of $X$ and $Y$.\n            \\end{itemize}\n        \\end{remark}\n        \\begin{definition}[Monotone Coupling]\n            Let $C$ be a coupling of $X$ and $Y$. $C$ is a \\textbf{monotone coupling} if\n            \\[ \\mathbb{P}_{(X,Y)\\sim C}[X\\ge Y] = 1\\footnote{“它总是大”——Prof.Zhang} \\]\n        \\end{definition}\n        \\begin{theorem}\\label{MonoCouplingAndDominance}\n            There is a monotone coupling of $X$ and $Y$ \\emph{if and only if} $X$ stochastically doniminates $Y$.\n        \\end{theorem}\n        \\begin{proof}\n            ~{}\\\\\n            $\\Rightarrow$.\n            By definition of coupling\n            \\[ \\mathbb{P}_{Y\\sim\\nu}[Y \\ge a] = \\mathbb{P}_{(X,Y)\\sim C}[Y\\ge a] \\]\n            By the Law of Total Probability\n            \\[ \\mathbb{P}_{Y\\sim\\nu}[Y \\ge a] = \\mathbb{P}_{(X,Y)\\sim C}[Y \\ge a \\wedge X \\ge Y]\\mathbb{P}[X \\ge Y] + \\mathbb{P}_{(X,Y)\\sim C}[Y \\ge a \\wedge X < Y]\\mathbb{P}[X < Y] \\]\n            The latter term is $0$ by definition of monotone coupling, so\n            \\[ \\mathbb{P}_{Y\\sim\\nu}[Y \\ge a] = \\mathbb{P}_{(X,Y)\\sim C}[X \\ge Y \\ge a] \\le \\mathbb{P}_{(X,Y)\\sim C}[X \\ge a] = \\mathbb{P}_{X\\sim\\mu}[X \\ge a] \\]\n\n            $\\Leftarrow$. Suppose $X$, $Y$ are two random variables having  distribution $F(x)$ and $G(x)$ respectively. By stochastic dominance we have $F(x) \\le G(x)$ for any $x$. Let $U$ be a random variable having a uniform distribution over $(0,1)$, since $F(x)$ is increasing\n            \\[ F^{-1}(U) \\le x \\Leftrightarrow F(F^{-1}(U)) \\le F(x) \\]\n            Therefore\n            \\[ \\mathbb{P}[F^{-1}(U) \\le x] = \\mathbb{P}[F(F^{-1}(U)) \\le F(x)] = \\mathbb{P}[U \\le F(x)] = F(x) \\]\n            Similarly\n            \\[ \\mathbb{P}[G^{-1}(U) \\le x] = G(x) \\]\n            Since $F(x) \\le G(x)$, we have $F^{-1}(x) \\ge G^{-1}(x)$ and therefore we obtained a coupling $C = (X' = F^{-1}(U), Y' = G^{-1}(U))$ for which $X' \\ge Y'$.\n\n            \\paragraph{Alternative proof.} $\\Leftarrow$. As is mentioned in class, let us think of constructing a coupling of $\\mu$ and $\\nu$ as the process of filling out a joint distribution table of $\\mu$ and $\\nu$. In order for the coupling to be a monotone coupling, all positive values in the table should only be in the bottom left part. Following the hint in the lecture note, we will show that we can always construct such a table in a ``greedy'' manner, as long as $\\mu$ stochastically dominates $\\nu$.\n    \n            Suppose we are going to fill a $N$ by $N$ table $C$ whose rows are $\\mu(i)$ and columns are $\\nu(i)$.\n            For the $i$-th row, our goal is to fill out the row, in a way that the values in this row sum up to $\\mu(i)$, and that all the values in and after the $(i+1)$-th column are $0$, i.e.\n            \\begin{equation}\\label{Eq:constr1}\n                \\forall i \\quad \\sum_{j=1}^N C(i, j) = \\mu(i)\n            \\end{equation}\n            \\begin{equation}\\label{Eq:constr2}\n                \\forall i \\forall j > i \\quad C(i, j) = 0\n            \\end{equation}\n            Meanwhile, we are also subjected to the constraint that the $j$-th column sums up to $\\nu(j)$.\n            \\begin{equation}\\label{Eq:constr3}\n                \\forall j \\quad \\sum_{i=1}^N C(i,j) = \\nu(j)\n            \\end{equation}\n            \n            Let $F$ and $G$ denote the cumulative distribution function of $\\mu$ and $\\nu$.\n            \\[ F(x) = \\sum_{i=1}^x\\mu(i) \\quad G(x) = \\sum_{i=1}^x\\nu(i) \\]\n            Notice that since $\\mu$ stochastically dominates $\\nu$, we have\n            \\[ \\forall x \\quad F(x) \\le G(x) \\]\n        \n            \\textbf{We first briefly explains the main idea.}\n        \n            When $i=1$, constrained by (\\ref{Eq:constr2}), we can only put positive values in the first column, i.e. only $C(1,1)$ in the first row can be positive. Therefore, $\\nu(1)$ cannot be smaller than $\\mu(1)$, or otherwise we can only put at most $\\nu(1)$ in $C(1,1)$, and we ``run out of budget'' for the positive remainder $\\mu(1)-\\nu(1)$. Fortunately, $\\mu$ stochastically dominates $\\nu$, so we have $\\mu(1) = F(1) \\le G(1) = \\nu(1)$. Therefore we can set $C(1,1) = \\mu(1)$, and set other elements in the first row to $0$.\n        \n            Similarly, when $i=2$, we have a total ``budget'' of $(\\nu(1) - \\mu(1)) + \\nu(2)$. The first term comes from the extra ``budget'' that remains when filling the first row, and the second term comes from the new column $\\nu(2)$. We have to ``divide and assign'' $\\mu(2)$ into the first two columns. Again $\\mu(2)$ cannot be larger than our ``budget'', or we will have a positive remainder $\\mu(2) - \\left(\\nu(1) - \\mu(1) + \\nu(2)\\right)$ that has no place to assign. Fortunately, since $\\mu(1) + \\mu(2) = F(2) \\le G(2) = \\nu(1) + \\nu(2)$, we have\n            \\[ \\mu(2) \\le \\nu(1) + \\nu(2) - \\mu(1) \\]\n            so we have enough ``budget'', and can assign $\\mu(2)$ in the following way\n            \\begin{enumerate}\n                \\item $C(2,1) = \\min\\{\\mu(2), \\nu(1) - \\mu(1)\\}$\n                \\item $C(2,2) = \\mu(2) - C(2,1)$\n            \\end{enumerate}\n        \n            \\textbf{Based on this idea, we can then fill out the table $C$ inductively.}\n        \n            \\textbf{Induction Base.} As is argued above, when $i=1$, we can always successfully fill out the first row, as long as $\\mu$ stochastically dominates $\\nu$.\n        \n            \\textbf{Induction Hypothesis.} Now suppose we have successfully filled out the first $k$ rows of $C$.\n        \n            \\textbf{Induction Step.} When filling out the $(k+1)$-th row, the ``total budget'' for this row will be\n            \\[ \\sum_{i=1}^{k}(\\nu(i) - \\mu(i)) + \\nu(i+1) \\]\n            again the former term is the remaining budget and the latter is from the new column $\\nu(k+1)$. The budget is always enough because\n            \\[ F(k+1) = \\sum_{i=1}^{k+1}\\mu(i) \\le G(k+1) = \\sum_{i=1}^{k=1} \\nu(i) \\]\n            so\n            \\[ \\mu(k+1) \\le \\sum_{i=1}^{k}(\\nu(i) - \\mu(i)) + \\nu(i+1) \\]\n            Therefore we can assign values on the $k+1$-th row in the following way\n            \\begin{itemize}\n                \\item $C(k+1, 1) = \\min\\{ \\mu(k+1), \\nu(1) - \\sum_{i=1}^k C(i,1) \\}$\n                \\item $C(k+1, 2) = \\min\\{ \\mu(k+1) - C(k+1,1), \\nu(2)-\\sum{i=1}^k C(i,2) \\}$\n                \\item \\dots\n                \\item $C(k+1, k+1) = \\mu(k+1) - \\sum_{i=1}^k C(k+1, i)$\n            \\end{itemize}\n            In this way we can fill $C$ such that all the positive values only lie in the lower left part of $C$, and therefore the coupling $C$ is a monotone coupling.\n        \\end{proof}\n\n    %%%%%%%% 2-SAT Revisited\n    \\subsection{2-SAT: Proof of Correctness}\n        \\begin{theorem}[Markov's Inequality]\\label{MarkovIneq}\n            Let $X$ be a nonnegative random varialbe and let $a > 0$, then\n            \\[ \\mathbb{P}[X \\ge a] \\le \\frac{\\mathbb{E}[X]}{a} \\]\n        \\end{theorem}\n        We can now prove the correctness of Algorithm \\ref{algo:2SATAlgo}.\n        \\begin{sketchproof}\n            Note that $X_{i+1}$ differs from $X_i$ in at most 1 operand, and that\n            \\[ \\mathbb{P}[X_{i+1} = X_i + 1] \\ge \\frac{1}{2} \\]\n            \\[ \\mathbb{P}[X_{i+1} = X_i - 1] \\le \\frac{1}{2} \\]\n            We can introduce a random walk described in subsection \\ref{AnotherRandWalk} $Y_1, Y_2, \\dots$ with $p = \\frac{1}{2}$.\n\n            $X_i$ stochatically dominates $Y_i$. This is intuitive, and can be proved using Theorem \\ref{MonoCouplingAndDominance} and constructing a monotone coupling:\n\n            We introduce a random variable $U$ that has a uniform distribution $U \\sim U(0,1)$. Let $q$ be the probability of $X_{i+1} = X_i + 1$, from the arguments above we already have $p < q$. Then we construct a coupling of $X$ and $Y$ by letting $X_{t+1} = X_t + 1$ if $U \\ge q$ and $X_{t+1} = X_t - 1$ otherwise; and by letting $Y_{t+1} = Y_t + 1$ if $U \\ge p$ and $Y_t - 1$ otherwise. Then it follows that $X_t \\ge Y_t$, and therefore $X_t$ stochastically dominiates $Y_t$.\n            \n            Since $Y_i$ has an expectation of $n^2$ to get to state $n$ (starting from $0$), it follows intuitively that $X_i$ has a smaller expectation of steps to get to $n$.\n\n            Actually,\n            \\[ \\mathbb{E}[\\text{First Hitting Time of $n$}|Y_0] = n^2 - Y_0^2 \\]\n\n            We have chosen the max iteration to be $100n^2$, by Markov's Inequality \\ref{MarkovIneq}, the probability that we take $100n^2$ iterations without finding a feasible solution is at most $1/100$.\n        \\end{sketchproof}\n        \\begin{remark}~{}\n            \\begin{itemize}\n                \\item \\sout{A formal proof of correctness will be given in the next lecture.}\n                \\item The rigorous proof has been updated.\n                \\item The idea of coupling can be used to prove other examples of stochastic dominance.\n            \\end{itemize}\n        \\end{remark}\n\n    %%%%%%%% Maximum Couplings\n    \\subsection{Maximum Couplings}\n        \\begin{definition}[Maximum Coupling]\n            Suppose $X$ has distribution function $\\mu$, $Y$ has distribution function $\\nu$. Let $C$ denote the set of all couplings of $(X,Y)$. $(\\hat{X},\\hat{Y})$ is a \\textbf{maximum $\\mu$,$\\nu$ couple} if\n            \\[ \\mathbb{P}[\\hat{X}=\\hat{Y}] = \\max_{(X,Y)\\in C}\\mathbb{P}[X=Y] \\]\n            i.e. among all such couples its components are most likely to be equal.\n        \\end{definition}\n        \\begin{proposition}\n            A maximum coupling always exists.\n            \\[ \\mathbb{P}[\\hat{X} = \\hat{Y}] = \\sum_{z\\in\\Omega}m(z) \\]\n            where $m(z) = \\min\\{ \\mu(z), \\nu(z) \\}$.\n        \\end{proposition}\n        \\begin{remark}\n            For continuous cases, the sum becomes integral.\n        \\end{remark}\n\n    %%%%%%%% Total Variance Distance\n    \\subsection{Total Variance Distance}\n        \\begin{definition}[Total Variation Distance]\n            Given two distributions $\\mu$ and $\\nu$ defined on a sample space $\\Omega$, the \\textbf{total variance distance} of $\\mu$ and $\\nu$ is defined as\n            \\[ \\|\\mu - \\nu \\|_{TV} \\triangleq \\frac{1}{2}\\sum_{x\\in\\Omega}|\\mu(x)-\\nu(x)| = \\max_{A\\subseteq\\Omega} \\mu(A)-\\nu(A) = 1-\\min_{z\\in\\Omega}\\{ \\mu(z), \\nu(z) \\} \\]\n            Geometrically, this is the half of size of the area between the pdf of $\\mu$ and $\\nu$.\n        \\end{definition}\n        \\begin{lemma}[The Coupling Lemma]\\label{CouplingLemma}\n            For any coupling $C$ of $\\mu$ and $\\nu$,\n            \\[ \\mathbb{P}_{(X,Y)\\sim C}[X \\neq Y] \\ge \\|\\mu - \\nu \\|_{TV} \\]\n            and there exists a coupling $C^{*}$ that achieves the equality.\n        \\end{lemma}\n        \\begin{proof}\n            If we view the coupling as a way to fill the table, then $\\mathbb{P}_{(X,Y) \\sim C}[X=Y]$ is the sum of all values on the diagonal of the table. Intuitively, the value on $i$-th row and $j$-th column is upper bounded by $\\mu(i)$ and $\\nu(j)$, so the sum is upper bounded by $\\sum_{z\\in\\Omega}\\min\\{\\mu(z), \\nu(z)\\}$.\n            \\begin{align*}\n                \\mathbb{P}[X \\neq Y] &= 1 - \\mathbb{P}_{(X,Y) \\sim C}[X = Y] \\\\\n                &= 1 - \\sum_{z \\in \\Omega}\\mathbb{P}[X=Y=z] \\\\\n                &\\ge 1 - \\sum_{z \\in \\Omega}\\min \\{\\mu(z), \\nu(z)\\}\\\\\n                &= \\sum_{z \\in \\Omega}\\left( \\mu(z) - \\min\\{\\mu(z),\\nu(z)\\} \\right)\\\\\n                &= \\| \\mu - \\nu \\|_{TV}\n            \\end{align*}\n            The previous part showed that $\\mathbb{P}_{(X,Y)\\sim C}[X \\neq Y]$ is always lower bounded by $\\|\\mu - \\nu\\|_{TV}$.\n\n            We then complete the proof by showing that there exists a coupling $\\mathcal{C}^*$ that achieves the equality.\n\n            Intuitively, if a coupling achieves the upper bound $\\mathbb{P}[X = Y = z] = \\min\\{ \\mu(z), \\nu(z) \\}$, it will also achieve the equality in the Coupling Lemma.\n\n            Let $U$ be a random variable with uniform distribution $U \\sim Uniform(0,1)$.\n\n            Let $m(z) = \\min\\{\\mu(z), \\nu(z)\\}$, and $p = \\sum_{z\\in\\Omega}m(z)$.\n\n            Let $V_1$, $V_2$, $V_3$ be three random variables with distributions\n            \\begin{enumerate}\n                \\item $V_1$: $f_{V_1}(x) = \\frac{m(z)}{p}$\n                \\item $V_2$: $f_{V_2}(x) = \\frac{\\mu(x) - m(x)}{1-p}$\n                \\item $V_3$: $f_{v_3}(X) = \\frac{\\nu(x) - m(x)}{1-p}$\n            \\end{enumerate}\n            Then we can construct the coupling as follows\n            \\begin{itemize}\n                \\item $X=Y=V_1$ if $U \\le p$\n                \\item $X=V_2 \\quad Y=V_3$ if $U > p$\n            \\end{itemize}\n            Since $\\mathbb{P}[V_2 = V_3] = 0$, we have that $\\mathbb{P}[X = Y] = p = \\sum_{z\\in\\Omega}\\min\\{\\mu(z), \\nu(z)\\}$. Now we only need to show that the distribution we created is a coupling of $X$ and $Y$.\n            \\[ p_X(x) = pf_{V_1}(x) + (1-p)f_{V_2}(x) = m(z) + \\mu(z) - m(z) = \\mu(z) \\]\n            \\[ p_Y(x) = pf_{V_1}(x) + (1-p)f_{V_3}(x) = m(z) + \\nu(z) - m(z) = \\nu(z) \\]\n            Therefore it is indeed a coupling of $X$ and $Y$, and it achieves the upper bound of $\\mathbb{P}[X=Y] = \\sum_z\\min\\{\\mu(z),\\nu(z)\\}$, therefore it also achieves the equality in the Coupling Lemma.\n        \\end{proof}\n        \\begin{remark}\n            The $C^*$ here is the maximal coupling.\n        \\end{remark}\n\n\n\\section{Proof of the Foundamental Theorem}\n    We are going to prove that:\n    \\paragraph{}\n        \\emph{An irreducible, aperiodic, positive recurrent Markov Chain has a unique stationary distribution, and it converges to the distribution.}\n\n    \\begin{proof}\n        We only consider the finite case. The proof of Theorem \\ref{theorem:FTMC-Countable} (which does not exist in this note) has already shown that an Irreducible Positive Recurrent Markov chain has a Unique Stationary Distribution, so we only prove the convergence part here. Suppose there are two Markov Chains $X$ and $Y$\n        \\[ X_0 \\to X_1 \\to \\dots \\to X_t \\to \\dots \\]\n        \\[ Y_0 \\to Y_1 \\to \\dots \\to Y_t \\to \\dots \\]\n        Let the initial distribution of $Y$ be the stationary distribution $\\pi$, so each $Y_i$ has distribution $\\pi$. Let the initial distribution of $X$ be $\\mu_0$, and $X_i$ has the distribution given by $\\mu_{i} = P^T\\mu_{i-1}$.\n\n        We define \\textbf{convergence} by $\\lim_{i\\to\\infty}\\|\\mu_{i} - \\pi\\|_{TV} = 0$.\n\n        For each $(X_t, Y_t)$, we construct a coupling $C_t$ such that each chain is runned independently, and once $X_t = Y_t$ for some $t$, then $X_{t'} = Y_{t'}$ for all $t' \\ge t$.\n\n        Irreducibility guarantees that \n        \\[ \\forall i,j \\quad \\exists n \\quad P^n(i,j) > 0 \\]\n        And we first claim a fact: Aperiodicity further guarantees that\n        \\begin{equation}\\label{FTMCEq1}\n            \\exists n \\quad \\forall i,j \\quad P^n(i,j) > 0\n        \\end{equation}\n        To prove (\\ref{FTMCEq1}), we are going to show that\n        \\begin{equation}\\label{FTMCEq2}\n            \\forall i,j \\quad \\exists t_{ij} \\quad \\forall t>t_{ij} \\quad P^t(i,j) > 0\n        \\end{equation}\n        Then (\\ref{FTMCEq1}) can be proved by setting $n = \\max_{i,j}\\{t_{ij}\\}$. Note that this result only holds in finite case.\n\n        We visualize the Markov Chain from $i$ to $j$ as many cycles starting from and ending at $i$, of length $c_1,c_2,\\dots$, plus a path from $i$ to $j$ (this path must exist, guaranteed by irreducibility). Since the chain is Aperiodic,\n        \\[ \\gcd(c_1, c_2,\\dots,c_s) = 1 \\]\n        And by Lemma \\ref{theorem:Bezout}, there exist integers $x_1,x_2,\\dots,x_s$ such that\n        \\[ c_1x_1 + c_2x_2 + \\dots + c_sx_s = 1 \\]\n        And it follows immediately that there exist $y_1,y_2,\\dots,y_s$ such that\n        \\[ c_1y_1 + c_2y_2 + \\dots + c_sy_x = b \\]\n        for all sufficiently large $b$. Additionally we also need to add the finite length of path from $i$ to $j$.\n\n        \\begin{lemma}[B$\\mathrm{\\acute{e}}$zout's Theorem]\\label{theorem:Bezout}\n            Let $a,b$ be two integers, then there exist integer $\\mu, \\nu$ such that\n            \\[ a\\mu + b\\nu = \\gcd(a,b) \\]\n        \\end{lemma}\n\n        Now consider the coupling.\n        \\[ \\mathbb{P}[X_n = Y_n] \\ge \\mathbb{P}[X_n=Y_n=x] \\ge SomeConstant~{} \\alpha > 0 \\]\n        This is guaranteed by the irreducibility of the chain.\n        So\n        \\[ \\mathbb{P}[X_n \\neq Y_n] \\le 1 - \\alpha \\]\n        Now condider the $2n$-th step, by the Law of Total Probability,\n        \\[ \\mathbb{P}[X_{2n} \\neq Y_{2n}] = \\mathbb{P}[X_{2n} \\neq Y_{2n} \\wedge X_n \\neq Y_n] + \\mathbb{P}[X_{2n} \\neq Y_{2n} \\wedge X_n = Y_n] \\]\n        The latter is $0$ because it is impossible by our construction of coupling.\n        \n        By conditional probability and the Markov Property\n        \\[ \\mathbb{P}[X_{2n} \\neq Y_{2n} \\wedge X_n \\neq Y_n] \\le \\mathbb{P}[X_{2n} \\neq Y_{2n} | X_n \\neq Y_n](1-\\alpha) \\le (1-\\alpha)^2 \\]\n\n        It follows immediately that $\\mathbb{P}[X_t \\neq Y_t] \\to 0$ as $t \\to \\infty$. So $\\lim_{t\\to\\infty}\\|\\mu_t - \\pi\\|_{TV} = 0$, and we are done.\n    \\end{proof}\n\n\n\\section{Applications of Markov Chain}\n    We assume the state space $\\mathcal{S}$ is finite, but in most cases the applications can be generalized to countably infinite cases. And we assume that the Markov chains are Aperiodic and Irreducible.\n\n    \\subsection{Time Reversibility}\n        \\begin{definition}[Time Reversibility]\n            A Markov chain is said to be time reversible if there exists a distribution $\\pi$ such that\n            \\begin{equation}\\label{def:DetailedBalanceCondition}\n                \\forall x,y \\in \\mathcal{S} \\quad \\pi(x)P(x,y) = \\pi(y)P(y,x)\n            \\end{equation}\n        \\end{definition}\n        \\begin{remark} ~{}\n            \\begin{itemize}\n                \\item The $\\pi$ here is actually the stationay distribution. because\n                \\[ (\\pi^TP)(y) = \\sum_{x\\in\\mathcal{S}}\\pi(x)P(x,y) = \\sum_{x\\in\\mathcal{S}}\\pi(y)P(y,x) = \\pi(y)\\sum_{x\\in\\mathcal{S}}P(y,x) = \\pi(y) \\]\n                \\item (\\ref{def:DetailedBalanceCondition}) is also called the \\textbf{detailed balance condition}.\n                \\item The detailed balance condition implies that $(X_0,X_1,\\dots,X_n)$ and $X_n,X_{n-1},\\dots,X_0$ have \\emph{the same distribution}, and this is the reason why such chains are called time-reversible.\n            \\end{itemize}\n        \\end{remark}\n\n    \\subsection{Metropolis Algorithm}\n        If we want to sample from some distribution $\\mu$, one way of doing this is to design a random walk (Markov Chain) with stationary distribution $\\mu$ and run the random walk for a sufficiently long period of time. We now discuss how to design such random walks. Recall the following proposition:\n        \\begin{proposition}\n            A random walk on graph $\\mathcal{G}$ with probability transition matrix\n            \\[P(i,j) = \n            \\begin{cases}\n                \\frac{1}{d_i} \\quad &j \\in \\mathcal{N}(i)\\\\\n                0 \\quad &j otherwise\n            \\end{cases}\n            \\]\n            has stationary distribution\n            \\[ \\pi(i) = \\frac{d_i}{\\sum_{j\\in\\mathcal{S}}d_j} \\]\n        \\end{proposition}\n        Consider a random walk on graph $\\mathcal{G} = (V, E)$. Given a distribution $\\mu$, we want to design a random walk such that the stationay distribution is $\\mu$. Let $d_i$ denote the degree of the $i$-th node in $\\mathcal{G}$.\\\\\n        Let\n        \\[ \\Delta = \\max_{i \\in V} d_i \\]\n        For any node $i$, for all $j \\in \\mathcal{N}(i)$, we ``propose'' to move to $j$ with probability $1/\\Delta$. And $j$ ``accepts'' $i$ with probability $\\min \\{\\frac{\\mu(j)}{\\mu(i)}, 1\\}$. If the move is rejected, we stay in $i$. We define the probability transition matrix as follows\n        \\begin{equation}\\notag\n            P(i, j) = \n            \\begin{cases}\n                0 \\quad & j \\notin \\mathcal{N}(i)\\\\\n                \\frac{1}{\\Delta}\\min\\{1, \\frac{\\mu(j)}{\\mu(i)}\\} \\quad &j \\in \\mathcal{N}(i)\\\\\n                1 - \\sum_{k\\in\\mathcal{N}(i)} P(i,k) \\quad & i = j\n            \\end{cases}\n        \\end{equation}\n        \\begin{proposition}\n            The $P$ defined above satisfies\n            \\[ \\mu P = \\mu \\]\n            i.e. it is a Markov chain with stationay distribution $\\pi$.\n        \\end{proposition}\n        \\begin{sketchproof}~{}\n            \\begin{itemize}\n                \\item Trivial if $j \\notin \\mathcal{N}(i)$.\n                \\item If $j \\in \\mathcal{N}(i)$. WLOG assume $\\mu(j) \\ge \\mu(i)$.\n                \\[ \\mu(i)P(i,j) = \\mu(i)\\frac{1}{\\Delta}\\min\\{1,\\frac{\\mu(j)}{\\mu(i)}\\} = \\frac{\\mu(i)}{\\Delta} \\]\n                and\n                \\[ \\mu(j)P(j,i) = \\mu(j)\\frac{1}{\\Delta}\\min\\{1,\\frac{\\mu(i)}{\\mu(j)}\\} = \\frac{\\mu(i)}{\\Delta} \\]\n                So we are done.\n            \\end{itemize}\n        \\end{sketchproof}\n        \\begin{remark}\n            If we run the algorithm sufficiently long, the sequence we get will have a distribution that is approximately the same as $\\mu$. What's more, in this algorithm, we only need to know $\\frac{\\mu(j)}{\\mu(i)}$, instead of knowing $\\mu$. And this is useful in practice.\n        \\end{remark}\n\n        In Chang's note, if we assume the desired distribution is proportional to\n        \\[ \\pi(i) \\propto d(i)f(i) \\]\n        where $f(i)$ is some additional weight on the degree of node $i$, then we can define the matrix by\n        \\begin{equation}\\notag\n            P(i, j) = \n            \\begin{cases}\n                0 \\quad & j \\notin \\mathcal{N}(i)\\\\\n                \\frac{1}{d(i)}\\min\\{1, \\frac{f(j)}{f(i)}\\} \\quad &j \\in \\mathcal{N}(i)\\\\\n                1 - \\sum_{k\\in\\mathcal{N}(i)} P(i,k) \\quad & i = j\n            \\end{cases}\n        \\end{equation}\n\n        \\begin{remark}\n            The Metropolis method simulates a random walk on a \\emph{graph}, whose nodes are different states. However, the choice of edges depends on us, and different choices of edges will lead to different choices of $P$.\n        \\end{remark}\n\n    \\subsection{Simulated Annealing}\n        \\par Simulated Annealing is a stochastic optimization algorithm. Given a set $\\mathcal{S}$, and a function $w(x)$. We want to minimize (or maximize) $w(x)$.\n        \\paragraph{Notations.}\n        \\begin{itemize}\n            \\item $\\mathcal{S}^* = \\{x\\in\\mathcal{S}|w(x) = \\min_{y\\in\\mathcal{S}} w(y)\\}$: the set of global minimizers of $w(x)$.\n            \\item $\\mu^*$: a uniform distribution on $\\mathcal{S}^*$.\n            \\item $T$: The ``Temperature'' parameter.\n        \\end{itemize}\n        \\par We define a distribution on $\\mathcal{S}$, and we want to make the probability concentrate on $x$ where $w(x)$ is small. However sampling from $\\mathcal{S}$ is usually infeasible because $\\mathcal{S}$ is too large.\n        \\par Instead, we introduce a parameter $T$, and let\n        \\[ \\mu_T(x) \\sim e^{-\\frac{w(x)}{T}} \\]\n        \\begin{proposition}\n            As $T \\to 0$, $\\mu_T(x) \\to \\mu^*(x)$.\n        \\end{proposition}\n        \\par However, if we start with a very small $T$, we may get stuck in a local extremum. So we start with a large $T_1$ and gradually decrease $T$.\n        \\begin{theorem}\n            If $T_1,T_2,\\dots$ satisify\n            \\begin{enumerate}\n                \\item $\\{T_i\\} \\to 0$.\n                \\item $T_i$ decreases slow enough. (``Slow'' means that the sum of a certain series defined by $\\mathcal{S}$ diverges, but it is so complicated that it is beyond the scope.)\n            \\end{enumerate}\n            Then let $P^{(n)} \\triangleq \\prod_{k=1}^n P_{T_k}$.\n            \\[ \\forall \\mu \\quad \\mu^TP^{(n)} \\to \\mu^* \\]\n        \\end{theorem}\n        That is, as long as $T$ decreases slowly enough, we only need to run each temperature $T_i$ \\emph{for one step with the Metropolis algorithm}.\n\n\n\\section{Mixing Times}\n    By designing a proper coupling $C$, we can upper bound the convergence speed of a Markov Chain.\n\n    \\subsection{Mixing Time}\n        \\begin{definition}[Mixing Time]\\label{def:MixingTime}\n            The \\textbf{mixing time} $\\tau_{mix}(\\varepsilon)$ is defined as\n            \\[ \\tau_{mix}(\\varepsilon) = \\max_{a} \\min_{t} \\| \\mu_t^a - \\pi \\|_{TV} \\le \\varepsilon \\]\n            It represents the minimal time for $\\mu$ to converge to $\\pi$ starting from the worst initial distribution $\\mu^a$.\n        \\end{definition}\n\n    \\subsection{Some Examples}\n\n        \\subsubsection{Random Walk on Hypercube.}\n            A \\textbf{hypercube} is a $\\{0,1\\}$ string $\\{0,1\\}^n$, and there exists an edge between $x$ and $y$ if and only if $\\sum_{i=1}^n|x(i)-y(i)| = 1$, i.e. $x$ and $y$ differs in only one bit.\n            Let\n            \\[\n                X_{t+1} = \n                \\begin{cases}\n                    X_t \\quad & w.p.\\frac{1}{2}\\\\\n                    \\textit{Move into one of the neighbours} & w.p.\\frac{1}{2}\n                \\end{cases}\n            \\]\n            i.e. we have probability $1/2$ to stay still and probability $1/2$ to move into a neighbour.\n\n            If we start from the worst case, then $\\mathbb{P}[X_t \\neq Y_t]$ can give an upper bound of $\\tau_{mix}$.\n\n            We construct the coupling as follows. Suppose we are at $X_t$,\n            \\begin{enumerate}\n                \\item Uniformly pick $i \\in n$.\n                \\item Uniformly pick $c \\in \\{0, 1\\}$.\n                \\item Set the $i$-th bit of $X_t$ to $c$ and yield $X_{t+1}$.\n            \\end{enumerate}\n            We choose \\emph{the same} $i$ and $c$ for both $X_t$ and $Y_t$.\n\n            It can be proved that if we run $n\\log n + cn$ iterations, the probability that $X_t \\neq Y_t$ is at most $e^{-c}$. i.e.\n            If\n            \\[ t \\ge n\\log n + cn \\]\n            Then\n            \\[ \\mathbb{P}[X_t \\ne Y_t] \\le e^{-c} = \\varepsilon \\]\n            Therefore \n            \\[ \\tau_{mix} \\le n\\log n + n\\log \\frac{1}{\\varepsilon} \\le \\varepsilon\\]\n            So we need approximately at most $n\\log n$ steps.\n\n        \\subsubsection{Coupon Collection}\n            Given a set of $n$ coupons, we pick $X$ times. And we want to know the total time we need to collect all $n$ coupons.\n\n            Let $X_i$ denotes the number of gachas needed to get an $i$-th new coupon.\n            \\[ \\mathbb{E}[X] = \\mathbb{E}[\\sum_{i=1}^n X_i] = \\sum_{i=i}^n \\mathbb{E}[X_i] \\]\n            Notice that $X_i$ has a geometric distribution with parameter $\\frac{n-i+1}{n}$. Therefore\n            \\[ \\mathbb{E}[X] = \\sum_{i=1}^n \\frac{n}{n-i+1} = n\\sum_{i=1}^n \\frac{1}{i} \\approx n(\\log n + \\gamma) \\]\n\n        \\subsubsection{Card Shuffling}\n            Suppose we shuffle a deck of 52 cards using a ``top-in-at-random'' method: we pick the card on the top and insert it into one of 52 positions (including the top) at random. This Markov chain has the stationary distribution $\\pi = Uniform(\\mathcal{S}_{52})$. By FTMC, $\\|\\pi_n - pi\\|_{TV} \\to 0$ as $n \\to \\infty$.\n\n            It is possible to find a random variable $T$ which denotes the time at which the deck becomes exactly uniformly distributed. We first introduce some notations.\n\n            \\begin{itemize}\n                \\item $U_i$ is uniformly distributed on $1,2,\\dots,52$ representing that the $i$-th shuffle moves the card on the top to position $U_i$.\n                \\item $T_1 = \\inf\\{ n: U_n = 52 \\}$ denotes the first time a card is moved below card 52.\n                \\item $T_2 = \\inf\\{ n>T_1: U_n \\ge 51 \\}$ denotes the second time a card is moved below card 52.\n                \\item $T_{51} = \\inf\\{ n>T_50: U_n \\ge 2 \\}$ denotes the 51st time a card is moved below card 52.\n            \\end{itemize}\n\n            Then $T = T_{52} = T_{51} + 1$.\n\n            Clearly we have\n            \\begin{itemize}\n                \\item $T_1 \\sim Geometry(1/51)$\n                \\item $T_2 - T_1 \\sim Geometry(2/52)$\n                \\item \\dots\n                \\item $T_{52} - T_{51} \\sim Geometry(52/52) = 1$\n            \\end{itemize}\n\n            We can calculate $\\mathbb{E}[T]$. By linearity of Expectation,\n            \\[ \\mathbb{E}[T] = \\mathbb{E}[T_1] + \\mathbb{E}[T_2-T_1] + \\dots + \\mathbb{E}[T_52 - T_51] \\approx 52\\log 52 \\]\n            Similarly, if we are shuffling $d$ cards, we have\n            \\[ \\mathbb{E}[T] = d\\log{d} \\]\n\n    \\subsection{Strong Stationary Times}\n        \\begin{definition}[Stopping Time]\n            The time $T$ is called the \\textbf{stopping time} if for each $n$, one can tell whether $T=n$ by just looking at $X_0, X_1, \\dots, X_n$, i.e. it is not necessary to know any other future values of $X_{n+1}, X_{n+2}, \\dots$.\n        \\end{definition}\n        \\begin{remark}\n            In the card-shuffling example, $T$ is a stopping time.\n        \\end{remark}\n        \\begin{definition}[Strong Stationary Time]\n            A random variable $T$ is called a \\textbf{strong stationary time} if it satisfies\n            \\begin{enumerate}\n                \\item $T$ is a stopping time\n                \\item $X_T$ is distributed as $\\pi$\n                \\item $X_T$ is independent of $T$\n            \\end{enumerate}\n        \\end{definition}\n        \\begin{lemma}\\label{Lemma:StrongStationaryTime}\n            If $T$ is a strong stationary time for the Markov Chain $\\{X_n\\}$, then $\\|\\pi_n - \\pi\\| \\le \\mathbb{P}[T > n]$ for all $n$.\n        \\end{lemma}\n\n    \\subsection{Threshold Pheonomenon}\n        In card shuffling and many other Markov Chains, $\\|\\pi_n - \\pi\\|$ stays close to $1$ for a while, and suddenly drop to nearly $0$ at approximately $n = d\\log{d}$\n\n        \\begin{theorem}\n            For $T$ defined in the card shuffling, let $\\Delta(n) = \\|\\pi_n - \\pi\\|$, we have\n            \\[ \\Delta(d\\log{d} + cd) \\le \\mathbb{P}[T > d\\log{d} + cd] \\le e^{-c} \\]\n            for all $c \\ge 0$\n        \\end{theorem}\n        \\begin{sketchproof} ~{}\n            \\begin{enumerate}\n                \\item The first inequality follows from Lemma \\ref{Lemma:StrongStationaryTime}.\n                \\item To prove the second inequality, we introduce the coupon collector's problem.\n                \\item Suppose we want to collect $d$ uniforly distributed coupons, the \\sout{gachas} boxes we need to open to collect all $d$ coupons have the distribution\n                \\[ 1 + Geometry((d-1)/d) + \\dots + Geometry(1/d) \\]\n                \\item Let $B_i = \\{ \\text{coupon $i$ does not appear in the first $n$ cereal boxes} \\}$\n                \\item Then $T_i > n$ is the union $\\bigcup_{i=1}^dB_i$\n                \\item $\\mathbb{P}[T>n] \\le \\sum_{i=1}^d\\mathbb{P}[B_i] = d\\left(1 - \\frac{1}{d}\\right)^n \\le de^{-n/d}$\n                \\item Take $n = d\\log{d} + cd$ yield the result\n            \\end{enumerate}\n        \\end{sketchproof}\n", "meta": {"hexsha": "e62ab00d5f9eb4896852a5a5f67805d01c91eee3", "size": 66229, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Stochastic Processes/DiscreteMarkovChain.tex", "max_stars_repo_name": "YBRua/CourseNotes", "max_stars_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-20T10:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T08:15:15.000Z", "max_issues_repo_path": "Stochastic Processes/DiscreteMarkovChain.tex", "max_issues_repo_name": "YBRua/CourseNotes", "max_issues_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Stochastic Processes/DiscreteMarkovChain.tex", "max_forks_repo_name": "YBRua/CourseNotes", "max_forks_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T11:31:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T11:31:00.000Z", "avg_line_length": 56.365106383, "max_line_length": 556, "alphanum_fraction": 0.5859819716, "num_tokens": 21833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.8688267898240861, "lm_q1q2_score": 0.7401994212816336}}
{"text": "Binary search trees suffer from a problem which is known as ``degeneration''. A binary tree is said to be \\textit{degenerate} if for each node there is only one non-empty child. This phenomenon happens when the elements inserted do not have a substantially random distribution, that is they are partially ordered. The limit case is the insertion of a sorted sequence such as the numbers from 1 to 10, which results in the following tree:\n\n\\begin{lstlisting}\n1\n \\\n  2\n / \\\n    3\n   / \\\n      5\n     / \\\n        6\n       / \\\n          7\n         / \\\n            8\n           / \\\n              9\n             / \\\n               10\n              /  \\\n\\end{lstlisting}\n\nSearch and removal operations in this sort of tree will have $O(N)$ complexity, which is significantly worse than the $O(\\log N)$ that we expect from a balanced tree.\n\nIn the rest of this section, we will present a new sort of binary trees, 2-3-4 trees, which always remain balanced by only adding elements to the root node and therefore increasing the height of the tree uniformly by one.\n\n\nThere are multiple possible implementations of balanced binary trees. We present here 2-3-4 trees as they are very widely used in many common implementation, and are also slightly simpler to describe and relatively simple to implement in our language. A widely used alternative to 2-3-4 trees is \\textit{red-black} trees, which are \\textit{isomorph} to 2-3-4. In other words, any 2-3-4 tree can be translated to an equivalent red-black tree without loss of structure or information, and vice-versa.\n\n\\paragraph{Structure of 2-3-4 trees}\nA 2-3-4 tree does not only have nodes with one value\\footnote{\\textit{values} are often also called \\textit{keys}.} and two children. In a 2-3-4 tree we distinguish three kinds of nodes: \n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item 2-nodes have one value $k$ and two children $l$ and $r$ such that $\\forall k' \\in l . k' < k$ and $\\forall k' \\in r . k' > k$;\n\\item 3-nodes have two value $k_1$ and $k_2$ and three children $l$, $m$, and $r$ such that $\\forall k' \\in l . k' < k_1$, $\\forall k' \\in r . k' > k_2$, and $\\forall k' \\in m . k_1 < k' < k_2$;\n\\item 4-nodes have three values $k_1$, $k_2$, and $k_3$ and four children $l$, $m_1$, $m_2$, and $r$ such that $\\forall k' \\in l . k' < k_1$, $\\forall k' \\in r . k' > k_3$, $\\forall k' \\in m_1 . k_1 < k' < k_2$, and $\\forall k' \\in m_2 . k_2 < k' < k_3$.\n\\end{inparaenum}\n\nAn example of such a tree with a depth of only two could be:\n\n\\begin{lstlisting}\n    10 20 \n /   |    \\\n5   17   22 24 29\n\\end{lstlisting}\n\nHere the root \\texttt{10 20} is a 3-node with two elements, \\texttt{10} and \\texttt{20}, and three children:\n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item 2-node \\texttt{5};\n\\item 2-node \\texttt{17};\n\\item 4-node \\texttt{22 24 29}.\n\\end{inparaenum}\n\nOur goal is to insert elements in such a manner that the tree maintains its balance, independent of the order of insertion of the elements.\n\nOur implementation of 2-3-4 trees is based on lists of elements. Lists are defined as usual, either a list is empty (\\texttt{nil}) or it is the append of an element to a list (\\texttt{;}):\n\n\\begin{lstlisting}\nData [] \"nil\" [] Priority 0 Type List\nData [ListElem] \";\" [List] Priority 100 Type List\n\\end{lstlisting}\n\nThe elements of the list can either be values (in our case just integers) or children, thus:\n\n\\begin{lstlisting}\n<<int>> is ListElem\nBTree is ListElem\n\\end{lstlisting}\n\nThe tree is defined as either an \\texttt{empty} node without values and children, or a proper \\texttt{node} that contains a list of values and children:\n\n\\begin{lstlisting}\nData [] \"empty\" [] Priority 0 Type BTree\nData [] \"node\" [List] Priority 0 Type BTree\n\\end{lstlisting}\n\nThe above definition means that a 2-node with value \\texttt{k} and children \\texttt{l} and \\texttt{r} will be represented as:\n\n\\begin{lstlisting}\nnode l;k;r;nil\n\\end{lstlisting}\n\na 3-node with values \\texttt{k1} and \\texttt{k2} and children \\texttt{l}, \\texttt{m}, and \\texttt{r} will be represented as:\n\n\\begin{lstlisting}\nnode l;k1;m;k2;r;nil\n\\end{lstlisting}\n\nand similarly for 4-nodes.\n\n\\paragraph{Insertion}\nThe main idea behind insertion into a \\texttt{2-3-4} tree is that for each node, we:\n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item find the appropriate child where we wish to insert by checking the values inside the node;\n\\item insert into that child;\n\\item if the child becomes too big (a 5-node, which is not allowed) then we split the node into two smaller nodes and insert the excess value into the current node.\n\\end{inparaenum}\n\nInsertion is thus a function that given a tree and an element to add returns the transformed tree:\n\n\\begin{lstlisting}\nFunc [BTree] \"insert\" [<<int>>] Priority 0 Class Expr => BTree\n\\end{lstlisting}\n\nInsertion into an empty tree is quite simple, in that we add the element between two empty nodes, therefore creating a trivial 2-node. This will only happen during the first insertion, that is when the tree is empty:\n\n\\begin{lstlisting}\n----------------------------------------------\nempty insert kv => node (empty;(kv;(empty;nil)))\n\\end{lstlisting}\n\nFor non-empty trees we will always stop right before the empty children, and we will always insert into leaf nodes. If the node is not a leaf, then we find the appropriate position and insert the new value there with function \\texttt{insertInto}. This yields a new tree which needs to be \\texttt{split} if its root is too big (a 5-node):\n\n\\begin{lstlisting}\nisLeaf l => no\nkv insertInto l => l'\nsplit l' => res\n----------------------------------------\n(node l) insert kv => res\n\\end{lstlisting}\n\nIf the node is indeed a leaf, then we find the appropriate position within its list of content and add the element plus a new \\texttt{empty} child with the \\texttt{insertSorted} function. The node, just like in the previous case, might become too big (a 5-node) as a result of insertion, and may thus need to be \\texttt{split}:\n\n\\begin{lstlisting}\nisLeaf l => yes\nl insertSorted kv empty => l1\nsplit l1 => res\n-------------------------------\n(node l) insert kv => res\n\\end{lstlisting}\n\nThe function that checks whether or not a tree is a leaf takes as input its list of values and children and returns a boolean value:\n\n\\begin{lstlisting}\nFunc [] \"isLeaf\" [List] Priority 0 Type Expr => YesNo\n\\end{lstlisting}\n\n\\texttt{isLeaf} returns \\texttt{yes} when the children of the node are all \\texttt{empty}. Since we know that this is a balanced tree, then we know that if one child (for example the first) is \\texttt{empty}, then all other children will be as well:\n\n\\begin{lstlisting}\n---------------------------------\nisLeaf (empty;rest) => yes\n\\end{lstlisting}\n\nIf the first child of the tre is not \\texttt{empty}, then we can be sure that all other children are not empty as well and thus we are not in presence of a leaf:\n\n\\begin{lstlisting}\nl != empty\n---------------------------------\nisLeaf (l;rest) => no\n\\end{lstlisting}\n\nIn case of leaves, we simply\\footnote{For a large enough value of ``simply''.} need to find the proper position within the list where to insert our element. The \\texttt{insertSorted} will therefore take a list of values and trees plus a value to insert as input, and return another such list:\n\n\\begin{lstlisting}\nFunc [List] \"insertSorted\" [<<int>>] Priority 0 Type Expr => List\n\\end{lstlisting}\n\nIf we reach the end of the list, then we simply add the value followed by the \\texttt{empty} tree. The function \\texttt{insertSorted} is only called on leaves, thus all children are already \\texttt{empty}:\n\n\\begin{lstlisting}\n--------------------------------------\nl;nil insertSorted k => l;k;empty;nil\n\\end{lstlisting}\n\nIf we find the element already in the tree, then we do nothing and return the original tree untouched:\n\n\\begin{lstlisting}\nx == k\n--------------------------------\nl;x;xs insertSorted k => l;x;xs\n\\end{lstlisting}\n\nIf the element to insert is bigger than the current value in the list, then we have found the point of insertion. We put the new element right before the bigger element and between them we put an \\texttt{empty} child:\n\n\\begin{lstlisting}\nx > k\n----------------------------------------\nl;x;xs insertSorted k => l;k;empty;x;xs\n\\end{lstlisting}\n\nIf the element to insert is smaller than the current value in the list, then we will have to go on looking in the rest of the list. We perform the insertion in the rest of the list, which then becomes the updated tail\\footnote{\\textit{Tail} is a common name given to ``the rest of a recursively defined list''.}:\n\n\\begin{lstlisting}\nx < k\nxs insertSorted k => xs'\n--------------------------------\nl;x;xs insertSorted k => l;x;xs'\n\\end{lstlisting}\n\n\nInsertion into non-leaf elements is very similar to \\texttt{insertSorted}. The first aspect of \\texttt{insertInto} is that it looks for the right position in the list of values and children where the insertion needs to happen. Whereas \\texttt{insertSorted} at that point simply adds two elements to the list, \\texttt{insertInto} recursively calls \\texttt{insert} into the appropriate child. We know that the child where we perform the recursive insertion is not \\texttt{empty} because otherwise \\texttt{insertSorted} would have been called instead of \\texttt{insertInto}.\n\n\\texttt{insertInto} takes as input the value to insert and the list where the insertion needs to take place, and returns the list with the value added:\n\n\\begin{lstlisting}\nFunc [<<int>>] \"insertInto\" [List] Priority 0 Type Expr => List\n\\end{lstlisting}\n\nThe base case of \\texttt{insertInto} happens when we reach the last child of the input list. In this case we cannot proceed forward, and therefore we will have to perform the insertion into the last child itself. After the recursive insertion step is performed, the child is updated and we need to \\texttt{merge} it back into the original list:\n\n\\begin{lstlisting}\nl insert k => l'\nmerge l' nil => l''\n---------------------------\nk insertInto l;nil => l''\n\\end{lstlisting}\n\nIf the value we are trying to insert is smaller than the current value, then we have found the position of insertion and perform the \\texttt{insert} and the \\texttt{merge} steps precisely like we did for the previous case:\n\n\\begin{lstlisting}\nx > k\nl insert k => l'\nmerge l' x;xs => l''\n---------------------------\nk insertInto l;x;xs => l''\n\\end{lstlisting}\n\nIf we find the value we are trying to insert, then we simply return the original list unchanged:\n\n\\begin{lstlisting}\nx == k\n------------------------------\nk insertInto l;x;xs => l;k;xs\n\\end{lstlisting}\n\nIf the value we are trying to insert is bigger than the current value, then we try to insert it at a later position with a recursive call to \\texttt{insertInto} the tail of the list \\texttt{xs}:\n\n\\begin{lstlisting}\nx < k\nk insertInto xs => xs'\n-------------------------------\nk insertInto l;x;xs => l;x;xs'\n\\end{lstlisting}\n\nThe role of \\texttt{split} is extremely important. After insertion, we may get a 5-node, which is not allowed. Split therefore takes as input a list of values and nodes, and returns a 2-3-4 tree where the eventual 5-nodes have been split:\n\n\\begin{lstlisting}\nFunc [] \"split\" [List] Priority 0 Class Expr => BTree\n\\end{lstlisting}\n\nIf \\texttt{split} encounters a 2-node (list of three elements), 3-node (list of five elements), or 4-node (list of seven elements), then it simply ``wraps'' the list into a single node and returns the node as the resulting tree:\n\n\\begin{lstlisting}\n------------------------------------------\nsplit l;(k;(r;nil)) => node l;(k;(r;nil))\n\n-------------------------------------------------------------\nsplit l;(k1;(m;(k2;(r;nil)))) => node l;(k1;(m;(k2;(r;nil))))\n\n------------------------------------------------------------------------\nsplit l;(k1;(l_m;(k2;(r_m;(k3;(r;nil)))))) => node l;(k1;(l_m;(k2;(r_m;(k3;(r;nil))))))\n\\end{lstlisting}\n\nIf the list is a 5-node, then it contains nine elements. We take the middle value as a \\textit{pivot}, and use the first three elements of the list as a 2-node and the remaining five elements of the list as a 3-node. We then return a 2-node where the newly created elements are the left and right child and the \\textit{pivot} is the value:\n\n\\begin{lstlisting}\nl' := node l;(k1;(l_m;nil))\nr' := node m;(k3;(r_m;(k4;(r;nil))))\n----------------------------------------------------------------------------\nsplit l;(k1;(l_m;(k2;(m;(k3;(r_m;(k4;(r;nil)))))))) => node l';(k2;(r';nil))\n\\end{lstlisting}\n\n\nAfter insertion we always perform a \\texttt{split}. The fact that we just performed an insertion means that the sub-tree is now bigger by one element. The fact that we just \\texttt{split} means that if we find a 2-node then this node was just split and therefore its single element should be added to the current list of elements, thereby promoting it by one level and therefore potentially propagating the excess size to the parent node. This way, if we need to create a new node, we keep sending new elements to parent nodes until we reach the root. When we split the root, then \\textit{the whole tree} has grown by one level. This will always keep the tree perfectly balanced.\n\n\\texttt{merge} takes as input a tree (where the insertion just took place) and the list of elements where the node needs to be merged, and returns a new list of elements where the input tree has been added:\n\n\\begin{lstlisting}\nFunc [] \"merge\" [BTree List] Priority 0 Type Expr => List\n\\end{lstlisting}\n\nIf we find a 2-node, then we know that it has just been split. This means that we effectively promote its value to the current level:\n\n\\begin{lstlisting}\n---------------------------------------\nmerge (node l;(k;(r;nil))) xs => l;(k;(r;xs))\n\\end{lstlisting}\n\nIf we find a 3-node or a 4-node (in general a node where the input list is longer than four elements) then we simply add this node as a single child of the list to return:\n\n\\begin{lstlisting}\n--------------------------------------------------\nmerge (node l;(k1;(m;(k2;rs)))) xs => (node l;(k1;(m;(k2;rs))));xs\n\\end{lstlisting}\n\n\nLet us now try to visualize\\footnote{``Try'' is the keyword here.} this process. We will consider the most interesting path of insertion, that is insertion into a tree which needs to grow in height by one.\n\nThe initial tree, where we shall insert the value 9, is:\n\n\\begin{lstlisting}\n   1  3  5\n /  |   |  \\\n0   2   4  6 7 8\n\\end{lstlisting}\n\nThe initial call to \\texttt{insert} processes the root of the tree. Since the root is not a leaf (all its children are non-empty), then it will perform an \\texttt{insertInto} followed by a \\texttt{split}.\n\n\\texttt{insertInto} finds that 9 is bigger than all elements of the root, thus insertion needs to happen in the right-most child: \\texttt{6 7 8}. This leads us to another call to \\texttt{insert} of value 9 into tree, which will then be followed by a call to \\texttt{merge}.\n\n\\begin{lstlisting}\n  6 7 8\n /  |  \\\n\\end{lstlisting}\n\nSince the node is a leaf, then \\texttt{insert} calls \\texttt{insertSorted}, followed by a \\texttt{split}. \\texttt{insertSorted} simply places the new value into the right position in the tree:\n\n\\begin{lstlisting}\n  6 7 8 9\n / | | | \\\n\\end{lstlisting}\n\nThe first \\texttt{split} creates a new 2-node:\n\n\\begin{lstlisting}\n     7\n   /   \\\n  6    8 9\n / \\  / | \\\n\\end{lstlisting}\n\nThis tree is sent back to as the result of \\texttt{insertInto}, which merges it with the list of values which was the original root of the tree (that is \\texttt{|2|4|5|}). \\texttt{merge} adds the value of the 2-node as a sibling of the elements of the root, since it recognizes the result of a succesful split. The resulting tree (not yet valid) is thus:\n\n\\begin{lstlisting}\n   1  3  5  7\n /  |   |  |  \\\n0   2   4  6  8 9\n\\end{lstlisting}\n\nThis is returned as the result of \\texttt{insertInto}, which is then processed by the last call to \\texttt{split}. Since \\texttt{split} finds a 5-node, it proceeds with its splitting and returns the result as the final tree:\n\n\\begin{lstlisting}\n         3\n      /     \\\n     /       \\\n   1        5  7\n /   \\     /  |  \\\n0     2   4   6  8 9\n\\end{lstlisting}\n\nThis elegant algorithm has thus managed to push the excess elements back up until the root was reached, therefore performing the final split at the root instead of one of the leaves and thus all nodes increase by one level of height instead of just a few, which would progressively unbalance the tree. Notice that the nodes of the resulting tree are all 2-nodes or 3-nodes, therefore it will take a few more insertions (at least three) before we can increase the height of the tree yet again.\n\n\n\\paragraph{A coward's approach to search}\nWe now quickly conclude the section by showing a ``lazy'' (in the sense that we use very simple predicates and some code duplication) approach to lookup. We define function \\texttt{contains} which determines whether or not a value is present within the tree:\n\n\\begin{lstlisting}\nFunc [] \"contains\" [BTree <<int>>] Priority 0 Type Expr => Bool\n\\end{lstlisting}\n\nThe trivial case is that the search has ended up in an empty tree. In this case we simply return a negative result:\n\n\\begin{lstlisting}\n-----------------------\ncontains empty k => no\n\\end{lstlisting}\n\nIf we have found a two-node, then we check whether the value of the node is the one we are looking for. If this is the case, then we can return a positive result:\n\n\\begin{lstlisting}\nx == k\n-----------------------------------\ncontains (node l;x;r;nil) k => yes\n\\end{lstlisting}\n\nIf the value of the node is bigger (smaller) than the searched value, then we proceed with a recursive search in the left (right) child:\n\n\\begin{lstlisting}\nk < x\ncontains l key => res\n----------------------------------\ncontains node(l;x;r;nil) k => res\n\nk > x\ncontains r key => res\n----------------------------------\ncontains node(l;x;r;nil) k => res\n\\end{lstlisting}\n\nSimilarly, for 3-nodes we need to find the proper interval where search must recursively continue:\n\n\\begin{lstlisting}\nkey > x1\nkey < x2\ncontains m k => res\n------------------------------------------\ncontains node(l;x1;m;x2;r;nil) k => res\n\\end{lstlisting}\n\nThe rest would need to be written by hand.\n\n\\paragraph{A courageous approach to search}\nThe above is perhaps useful for illustration purposes. As an alternative, we could write a recursive search functions similar to \\texttt{insertSorted} or \\texttt{insertInto}.\n\nContainment fails immediately on an \\texttt{empty} sub-tree:\n\n\\begin{lstlisting}\n-----------------------\ncontains empty k => no\n\\end{lstlisting}\n\nOn a non-empty \\texttt{node} we invoke auxiliary function \\texttt{containsIterate}, which simply takes a list of elements instead of a tree as a parameter:\n\n\\begin{lstlisting}\nFunc [] \"containsIterate\" [List <<int>>] Priority 0 Type Expr => Bool\n\\end{lstlisting}\n\n\\begin{lstlisting}\ncontainsIterate l k => res\n---------------------------\ncontains node l k => res\n\\end{lstlisting}\n\n\\texttt{containsIterate} defaults to searching in the right-most child if no other suitable children have been found so far:\n\n\\begin{lstlisting}\ncontains r k => res\n-------------------------\ncontainsIterate r;nil k => res\n\\end{lstlisting}\n\nIf the current value of the list is equal to the value we are searching, then search has been concluded positively:\n\n\\begin{lstlisting}\nk = x\n--------------------------------\ncontainsIterate l;x;xs k => yes\n\\end{lstlisting}\n\nIf the current value of the list is bigger than the value we are searching, then we have found the child where search needs to continue recursively:\n\n\\begin{lstlisting}\nk < x\ncontains l k => res\n--------------------------------\ncontainsIterate l;x;xs k => res\n\\end{lstlisting}\n\nIf the current value of the list is smaller than the value we are searching, then we have not yet found the child where search needs to recurse, and we must continue iterating the elements of the list:\n\n\\begin{lstlisting}\nk > x\ncontainsIterate xs k => res\n--------------------------------\ncontainsIterate l;x;xs k => res\n\\end{lstlisting}\n\n\nThis second formulation of search is quite shorter than the previous, and illustrates nicely how a well-though out recursive procedure is often much shorter to write and read \\footnote{but perhaps not invent} than lots of repeated, boilerplate code.\n", "meta": {"hexsha": "c94e0fb80d6461b560125d924a56d348a107983e", "size": 20172, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Course materials/Dictaat/tex/Examples/balanced_binary_search_trees.tex", "max_stars_repo_name": "vs-team/metacompiler", "max_stars_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-12-13T09:22:28.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-03T21:48:11.000Z", "max_issues_repo_path": "Course materials/Dictaat/tex/Examples/balanced_binary_search_trees.tex", "max_issues_repo_name": "cult-of-giuseppe/metacompiler", "max_issues_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2015-08-14T06:48:43.000Z", "max_issues_repo_issues_event_max_datetime": "2015-08-16T09:37:03.000Z", "max_forks_repo_path": "Course materials/Dictaat/tex/Examples/balanced_binary_search_trees.tex", "max_forks_repo_name": "cult-of-giuseppe/metacompiler", "max_forks_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-10-11T17:13:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-10T19:12:15.000Z", "avg_line_length": 44.7272727273, "max_line_length": 679, "alphanum_fraction": 0.6895697006, "num_tokens": 5341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.7401994080741511}}
{"text": "\\subsection{Shooting method}\nFinal time is free so:\n$$\n\\vec{F} = \\begin{bmatrix}\n\tx_1(t_f) - x_{1_f}\\\\\n\tx_2(t_f) - x_{2_f}\\\\\n\t\\left.(\\mathcal{H} - h_t)\\right\\vert_{t_f}\n\\end{bmatrix}\n$$\n$$\n\\vec{y}_{k+1} = \\vec{y}_k - \\left.\\dfrac{\\partial \\vec{F}}{\\partial \\vec{y}}\n\\right\\vert_{\\vec{y}_k}\n\\vec{F}(\\vec{y}_k)\n$$\n\\begin{figure}[H]\n\t\\caption{Shooting method}\n\t\\centering\n\t\\includegraphics[width=11.5cm]{../Figure/Q3/Shooting.png}\n\\end{figure}", "meta": {"hexsha": "e248d22e81eb050d967fbb60f15eb9a4bcfa06e7", "size": 440, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW3/Report/Q3/Q3_b.tex", "max_stars_repo_name": "alibaniasad1999/Optimal-Control", "max_stars_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-09T13:16:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-09T13:16:54.000Z", "max_issues_repo_path": "HW/HW3/Report/Q3/Q3_b.tex", "max_issues_repo_name": "alibaniasad1999/Optimal-Control", "max_issues_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW/HW3/Report/Q3/Q3_b.tex", "max_forks_repo_name": "alibaniasad1999/Optimal-Control", "max_forks_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.1578947368, "max_line_length": 76, "alphanum_fraction": 0.6409090909, "num_tokens": 191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037732, "lm_q2_score": 0.79053032607222, "lm_q1q2_score": 0.7401616937014434}}
{"text": "\\subsection{Density of the rationals}\n\n\\subsubsection{Rationals are dense in rationals}\n\nFor any pair of rationals, there is another rational between them:\n\n\\(a=\\dfrac{p}{q}\\)\n\n\\(b=\\dfrac{m}{n}\\)\n\nWhere \\(b>a\\).\n\nWe define a new rational:\n\n\\(c=\\dfrac{a+b}{2}\\)\n\n\\(c=\\dfrac{pn+qm}{2qn}\\)\n\nThis is a rational number.\n\nWe can write:\n\n\\(a=\\dfrac{2pn}{2qn}\\)\n\n\\(b=\\dfrac{2qm}{2qn}\\)\n\nAs \\(b>a\\) we know \\(2qm>2pn\\)\n\nSo: \\(a < c < b\\)\n\n", "meta": {"hexsha": "facbb5fa496ad721f12a18e92d1414883e9b5e69", "size": 430, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/rational/01-07-rationalsDensity.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/rational/01-07-rationalsDensity.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/rational/01-07-rationalsDensity.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.8709677419, "max_line_length": 66, "alphanum_fraction": 0.6209302326, "num_tokens": 157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480346, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7401616862699294}}
{"text": "\n\\subsection{Space shuttle and Corvette}\nThe space shuttle accelerates from zero to 17{,}000 miles per hour\nin 8 minutes.\nA Corvette accelerates from zero to 60 miles per hour in 4.5 seconds.\nThe following script compares the two.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nvs = 17000*\"mile\"/\"hr\"\nts = 8*\"min\"/(60*\"min\"/\"hr\")\nas = vs/ts\nas\nvc = 60*\"mile\"/\"hr\"\ntc = 4.5*\"sec\"/(3600*\"sec\"/\"hr\")\nac = vc/tc\nac\n\"Time for Corvette to reach orbital velocity:\"\nvs/ac\nvs/ac*60*\"min\"/\"hr\"\n\\end{Verbatim}\n\nHere is the result when the script runs.\nIt turns out that the space shuttle accelerates more than twice as fast as a\nCorvette.\n\n$\\displaystyle a_s={\\hbox{127500 mile}\\over(\\hbox{hr})^2}$\n\n$\\displaystyle a_c={\\hbox{48000 mile}\\over(\\hbox{hr})^2}$\n\n\\verb$Time for Corvette to reach orbital velocity:$\n\n$\\displaystyle 0.354167\\;\\rm hr$\n\n$\\displaystyle 21.25\\;\\rm min$\n", "meta": {"hexsha": "af0c7c3e72040fe8935d9979378d28c3e7a1c0e4", "size": 875, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/space-shuttle-and-corvette.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/space-shuttle-and-corvette.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/space-shuttle-and-corvette.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0, "max_line_length": 76, "alphanum_fraction": 0.712, "num_tokens": 288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.7401616784341994}}
{"text": "\n\\subsection{Angles}\n\n\\subsubsection{Recap: Cauchy-Schwarz inequality}\n\nThis states that:\n\n\\(|\\langle u,v\\rangle |^2 \\le \\langle u, u\\rangle \\dot \\langle v, v\\rangle \\)\n\nOr:\n\n\\(\\langle v,u\\rangle\\langle u,v\\rangle \\le \\langle u, u\\rangle \\dot \\langle v, v\\rangle \\)\n\n\\subsubsection{Introduction}\n\n\\(\\langle v,u\\rangle\\langle u,v\\rangle \\le \\langle u, u\\rangle \\dot \\langle v, v\\rangle \\)\n\n\\(\\dfrac{\\langle v,u\\rangle\\langle u,v\\rangle}{||u||.||v||} \\le ||u||.||v||\\)\n\n\\(\\dfrac{||u||.||v||}{\\langle v,u\\rangle} \\ge \\dfrac{\\langle u,v\\rangle}{||u||.||v||}\\)\n\n\\(\\cos (\\theta )=\\dfrac{\\langle u,v\\rangle }{||u||.||v||}\\)\n\n", "meta": {"hexsha": "584fe15213184a00f7be5e980d70eb5b4ee7e2e4", "size": 618, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/affineEuclid/04-02-angles.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/affineEuclid/04-02-angles.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/affineEuclid/04-02-angles.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.75, "max_line_length": 90, "alphanum_fraction": 0.6148867314, "num_tokens": 233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067260443809, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.7401586195070798}}
{"text": "\\section{Covariance and Uncertainty}\n\nCovariance is the relationship that every variable has with every other variable, and it is very important in multidimensional systems. We have our main covariance $\\boldsymbol{P}$, also called the estimate uncertainty, which is modified both in the \\textit{Predict} and in the \\textit{Update} phases. \n\nIn the \\textit{Predict} step, we extrapolate the estimate uncertainty to create a prediction for $\\boldsymbol{P}$ at the next timestep. This is done by using our state transition matrix previously obtained from the motion model. \n\\begin{equation}\n    \\boldsymbol{P}_{k+1} = \\boldsymbol{F} \\cdot \\boldsymbol{P} \\cdot \\boldsymbol{F}^T + \\boldsymbol{Q}\n\\end{equation}\nwhere $\\boldsymbol{Q}$ is a matrix representing the process noise. This is hard to nail down and understand physically, but think of it as the uncertainty in the process of the EKF itself. There are formulas and ways to find more complicated versions of all entries, but it suffices in our case to simply use the 8x8 identity matrix multiplied by a constant that we can tune. This constant tends to remain in the range (1.1, 1.3) in our application.\n\nIn addition to these uncertainties in the estimations and in the process, we of course have uncertainties in our measurements. If sensors give direct values for their variance, those should be used. We define the measurement uncertainty as a 6x6 matrix, $\\boldsymbol{R}$, with the variance of each measurement as the entry on the diagonal corresponding to that measurement's position in $\\boldsymbol{z}$. We know that our approximations for the positions using GPS coordinates are fairly scuffed and have a standard deviation around 5 meters, whereas our IMU and encoders can easily be more accurate than a tenth of a unit. As such, we used the following matrix as a starting point. We frequently modify these values on the fly based on which sensors are performing well and which ones are having more interference than expected. Check the competition build of the code to see what we finalized at the venue.\n\n\\begin{equation}\n    \\boldsymbol{R} = \n    \\begin{pmatrix}\n    35 & 0 & 0 & 0 & 0 & 0 \\\\\n    0 & 25 & 0 & 0 & 0 & 0 \\\\\n    0 & 0 & 0.1 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 0.1 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 0.01 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 & 0.01\n    \\end{pmatrix}\n\\end{equation}\n\nNote that if a sensor is being absolutely horrible or breaks it can be essentially disabled by setting its uncertainty value in this matrix to something huge like 100,000. Even if the filter never receives data from a sensor (i.e., it is unplugged or not functioning), it will use the starting value, 0, weighted with a massive uncertainty; this means the filter will still work if a sensor is disconnected, albeit not as well as with all the expected data.", "meta": {"hexsha": "94dc3148c9a9a56b753f5bff4cfe3784cc06e09c", "size": 2801, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/IGVC EKF Derivation/sections/covariance.tex", "max_stars_repo_name": "SoonerRobotics/igvc_software_2022", "max_stars_repo_head_hexsha": "906e6a4fca22d2b0c06ef1b8a4a3a9df7f1d17dd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-07T14:56:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-13T23:31:07.000Z", "max_issues_repo_path": "docs/IGVC EKF Derivation/sections/covariance.tex", "max_issues_repo_name": "SoonerRobotics/igvc_software_2022", "max_issues_repo_head_hexsha": "906e6a4fca22d2b0c06ef1b8a4a3a9df7f1d17dd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-09-22T01:53:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-17T01:02:31.000Z", "max_forks_repo_path": "docs/IGVC EKF Derivation/sections/covariance.tex", "max_forks_repo_name": "SoonerRobotics/igvc_software_2022", "max_forks_repo_head_hexsha": "906e6a4fca22d2b0c06ef1b8a4a3a9df7f1d17dd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-06-29T05:21:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-23T05:03:27.000Z", "avg_line_length": 112.04, "max_line_length": 908, "alphanum_fraction": 0.7518743306, "num_tokens": 718, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.8244619242200081, "lm_q1q2_score": 0.7401155901506171}}
{"text": "\\abbreviations\n\n\\section*{Symbols}\n\n\\begin{symbollist}\n  \\item[$P\\left(X \\mid Y\\right)$] (Conditional) Probability of $X$ Given $Y$\n  \\item[$\\expval{X}$ or $\\expvalE{X}$] Expectation Value of $X$\n  \\item[$\\sigma_{X}^{2}$ or $\\variance{X}$] Variance of $X$\n  \\item[$\\sigma_{u,v}^{2}$ or $\\cov{u}{v}$] Covariance of $u$ and $v$\n  \\item[$\\vb*{\\beta}$] Model Parameters, $n \\times 1$ Column Vector\n  \\item[$\\mathbf{X}$] Input Features, $m \\times n$ Matrix\n  \\item[$y$] Dependent Feature\n  \\item[$m$] Number of Data Points or Rows\n  \\item[$n$] Number of Input Features or Columns\\footnote{$n$ is also sometimes used for the number of rows, if it is the standard terminology for a method.}\n  \\item[$\\nu$] Number of Degrees of Freedom\n  \\item[$S\\left(\\vb*{\\beta}\\right)$] Objective Function\n  \\item[$L\\left(\\vb*{\\beta}\\right)$] Loss Function\n  \\item[$\\Omega\\left(\\vb*{\\beta}\\right)$] Regularization Function\n  \\item[$L$] Likelihood Function\n  \\item[$\\yhat$] Estimated Dependent Feature or Classification Score, Prediction % Leave as $\\yhat$ to get the proper spacing\n  \\item[$Z$] Significance\n  \\item[$S\\left(t\\right)$] Survival Function\n  \\item[$\\lambda\\left(t\\right)$] Hazard Function\n  % \\item[\\ZB] Significance, Incomplete Beta Function Approximation\n  % \\item[\\CLs] Signal Confidence Level\n\\end{symbollist}\n\n\\clearpage\n\\section*{Abbreviations}\n% TODo keep updated\n\n\\begin{symbollist}\n  \\item[\\iid] Independent and Identically Distributed\n  \\item[\\kNN] $k$-Nearest Neighbors\n  \\item[\\tSNE] $t$-Distributed Stochastic Neighbor Embedding\n  \\item[ABC] Approximate Bayesian Computation\n  \\item[ACF] Auto-Correlation Function\n  \\item[ADF] Augmented Dickey--Fuller Test for Stationarity\n  \\item[AIC] Akaike Information Criterion\n  \\item[AICc] Akaike Information Criterion with corrections\n  \\item[ANCOVA] Analysis of Covariance\n  \\item[ANOVA] Analysis of Variance\n  \\item[AR] Autoregressive (Models)\n  \\item[AUC] Area Under Curve\n  \\item[BDT] Boosted Decision Tree\n  \\item[BFS] Breadth First Search\n  \\item[BIC] Bayesian Information Criterion\n  \\item[BLUE] Best Linear Unbiased Estimator\n  \\item[CART] Classification and Regression Tree\n  \\item[CDF] Cumulative Distribution Function\n  \\item[CLT] Central Limit Theorem\n  \\item[CNN] Convolutional Neural Network\n  \\item[DFS] Depth First Search\n  \\item[DID] Difference in Differences\n  \\item[EM] Expectation Maximization\n  \\item[FWHM] Full Width at Half Maximum\n  \\item[GLM] Generalized Linear Model\n  \\item[GLS] Generalized Least Squares\n  \\item[GMM] Gaussian Mixture Model\n  \\item[GNB] Gaussian N{a\\\"i}ve Bayes (Classification)\n  \\item[GP] Gaussian Process\n  \\item[HR] Hazard Ratio\n  \\item[IQR] Interquartile Range\n  \\item[KDE] Kernel Density Estimation\n  \\item[LDA] Linear Discriminant Analysis\n  \\item[LSTM] Long Short Term Memory\n  \\item[LVQ] Learning Vector Quantization\n  \\item[MA] Moving Average (Models)\n  \\item[MANOVA] Multivariate Analysis of Variance\n  \\item[MAP] Maximum \\aposteriori (Estimation)\n  \\item[MAPE] Mean Absolute Percent Error\n  \\item[MC] Monte Carlo\n  \\item[MCMC] Markov Chain Monte Carlo\n  \\item[MI] Mutual Information\n  \\item[ML] Machine Learning\n  \\item[MLE] Maximum Likelihood Estimation (or Estimator)\n  \\item[MMSE] Minimum Mean Square Error (Estimator)\n  \\item[MSE] Mean Squared Error\n  \\item[NLP] Natural Language Processing\n  \\item[NMI] Normalized Mutual Information\n  \\item[NN] Neural Network\n  \\item[OLS] Ordinary Least Squares\n  \\item[PACF] Partial Auto-Correlation Function\n  \\item[PCA] Principle Component Analysis\n  \\item[PCR] Principal Component Regression\n  \\item[PDF] Probability Density Function\n  \\item[PR] Prevalence Ratio\n  \\item[QDA] Quadratic Discriminant Analysis\n  \\item[RDBMS] Relational Database Management System\n  \\item[RMSD] Root Mean Squared Deviation\n  \\item[RMSE] Root Mean Squared Error\n  \\item[RNN] Recurrent Neural Network\n  \\item[ROC] Receiver Operating Characteristic\n  \\item[RSF] Random Survival Forest\n  \\item[SGD] Stochastic Gradient Descent\n  \\item[SMBO] Sequential Model-Based Optimization\n  \\item[SQL] Structured Query Language\n  \\item[SVD] Singular Value Decomposition\n  \\item[SVM] Support Vector Machine\n  \\item[TF-IDF] Term Frequency-Inverse Document Frequency\n  \\item[TPE] Tree-Structured Parzen Estimator\n  \\item[VIF] Variance Inflation Factor\n%  \\item[] \n\\end{symbollist}\n%  \\item[GAN] Generational Adversarial Network\n", "meta": {"hexsha": "68037d61cfbd4141260d2cd6c6bbb40c54d6f9e9", "size": 4333, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/listofabbr.tex", "max_stars_repo_name": "mepland/data_science_notes", "max_stars_repo_head_hexsha": "f529a86490110fc6a30d1af6d37c0add2517244f", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-05-30T15:15:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-23T01:01:08.000Z", "max_issues_repo_path": "sections/listofabbr.tex", "max_issues_repo_name": "mepland/data_science_notes", "max_issues_repo_head_hexsha": "f529a86490110fc6a30d1af6d37c0add2517244f", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/listofabbr.tex", "max_forks_repo_name": "mepland/data_science_notes", "max_forks_repo_head_hexsha": "f529a86490110fc6a30d1af6d37c0add2517244f", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.8773584906, "max_line_length": 157, "alphanum_fraction": 0.7399030695, "num_tokens": 1332, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7401155840221935}}
{"text": "\\subsection{Fourier-Galerkin}\n    \\label{Galerkin}\n\t\\vspace{0.3cm} \n\t\n\t\n\tIn chapter \\ref{Chapter_2} we saw that for a function $\\varphi \\in H^2_p [0, 2 \\pi]$ it can be written as\n\t\\begin{align}\n\t\\label{Expansion_phi}\t\n\t\t\\varphi (x, t) = \\displaystyle \\sum_{|n| \\leq \\infty} \\hat{\\varphi}_n (t) \\phi_n (x), \\hspace{2mm} \\hat{\\varphi}_n (t) = \\frac{1}{2 \\pi} \\left\\langle \\varphi (x, t), \\phi_n (x) \\right\\rangle  \n\t\\end{align}\n\twhere $\\phi_n (x) = e^{inx}$, and let's assume that this function is the solution of the problem (\\ref{Bugers_Lineal}).\\\\\n\t\n\tThe Fourier-Galerkin method will be constructed using the project operator described in (\\ref{proyection_operator}) to project and force the function $\\varphi$ to satisfy the problem (\\ref{Bugers_Lineal}) on a space that will be defined a continuation. \\\\\n\t\n\tLet $V_N$ the space of trigonometric polynomials of degree $2N + 1$ given by $V_N = B_N \\cap H^2_p [0, 2 \\pi]$, where $B_N = span\\{\\phi_n (x) : |n| \\leq N\\}$. Then for $\\varphi \\in V_N$ we can obtain its expansion as  \n\t\\begin{align}\n\t\\label{Expansion_phi_N}\t\n\t\t\\varphi_N (x, t) = \\displaystyle \\sum_{|n| \\leq N} \\hat{\\varphi}_n (t) \\phi_n (x), \\hspace{2mm} \\hat{\\varphi}_n (t) = \\frac{1}{2 \\pi} \\left\\langle \\varphi (x, t), \\phi_n (x) \\right\\rangle  \n\t\\end{align} \n\t\n\tSubstituting (\\ref{Expansion_phi}), and (\\ref{Expansion_phi_N}) into the equation (\\ref{Bugers_Lineal}) to taking the difference as follows\n\t\\begin{align*}\n\t\t\\left[ \\frac{\\partial}{\\partial t} \\varphi_N - \\alpha \\frac{\\partial^2}{\\partial x} \\varphi_N \\right] - \\left[ \\frac{\\partial \\varphi}{\\partial t} - \\alpha \\frac{\\partial^2 \\varphi}{\\partial x} \\right] = R_N (x, t)   \n\t\\end{align*}\n\twhere $R_N (x, t)$ is a residual function, and since the second term is exactly zero because $\\varphi$ is the exact solution we have to\n\t\\begin{align*}\n\t\t\\frac{\\partial}{\\partial t} \\varphi_N -  \\alpha \\frac{\\partial^2}{\\partial x} \\varphi_N = R_N (x, t)\n\t\\end{align*}\n\t\n\tIn the Fourier-Galerkin method, it is desired that the remainder $R_N$ belong to the orthogonal space of $ V_N $, that is, for every $\\varphi, \\phi \\in V_N $ such that $\\langle \\varphi - \\mathcal{P}_N \\varphi, \\phi \\rangle = 0$. This is achieved by forcing for each $|n| \\leq N$ the following condition\n\t\\begin{align}\n\t\t\\left\\langle R_N, \\phi_n \\right\\rangle = \\left\\langle \\frac{\\partial \\varphi_N}{\\partial t} - \\alpha \\frac{\\partial^2 \\varphi_N}{\\partial x^2}, \\phi_n \\right\\rangle = 0, \\hspace{2mm}  \\hspace{2mm} \\phi_n \\in V_N, \\hspace{2mm} \\forall t > 0\n\t\\end{align}\n\tor equivalently\n\t\\begin{align*}\n\t\t\\displaystyle \\int_{\\mathcal{D}} \\frac{\\partial}{\\partial t} \\varphi_N (x, t) \\overline{\\phi_n (x)} dx = \\alpha \\int_{\\mathcal{D}} \\frac{\\partial^2}{\\partial x^2} \\varphi_N (x, t) \\overline{\\phi_n (x)} dx , \\hspace{2mm}  \\hspace{2mm} \\phi_n \\in V_N, \\hspace{2mm} \\forall t > 0\n\t\\end{align*}\n\t\n\t\\noindent Using the orthogonality $\\langle \\phi_k, \\phi_n \\rangle = 2 \\pi \\delta_{kn}$, for each $n$ fixed we have to\n\t\\begin{align*}\n\t\t\\left\\langle \\frac{\\partial \\varphi_N}{\\partial t}, \\phi_n  \\right\\rangle = \\left\\langle \\displaystyle \\sum_{ |k| \\leq N} \\frac{d \\hat{\\varphi}_k (t)}{dt} \\phi_k, \\phi_n  \\right\\rangle = 2 \\pi \\frac{d \\hat{\\varphi}_n (t)}{dt}\n\t\\end{align*}\n\t\n\tNote that the spatial interval is not the desired one, for this we are going to define the following linear transformation from $\\mathcal{D}_p = [0, 2 \\pi]$ to $\\mathcal{D} = [x_L, x_R]$ given by $x = P z + x_L$ to escalate the problem, where $P = \\frac{x_R - x_L}{2 \\pi}$ and $z \\in \\mathcal{D}_p$. Then, using the chain rule we can rewritten the derivatives as\n\t\\begin{align*}\n\t\t\\frac{\\partial^2 \\varphi_N}{\\partial x^2} = P^2 \\frac{\\partial^2 \\varphi_N}{\\partial x^2} \n\t\\end{align*}\n\tand using $\\frac{\\partial^2}{\\partial x^2} \\phi_n (x) = -P^2 n^2 \\phi_n (x)$ we have to  \n\t\\begin{align*}\n\t\t\\alpha \\left\\langle \\frac{\\partial^2 \\varphi_N}{\\partial x^2}, \\phi_n \\right\\rangle = -2 \\pi \\alpha P^2 n^2 \\hat{\\varphi}_n (t), \\hspace{2mm} |n| \\leq N\n\t\\end{align*}\n\t\n\t\\noindent Therefore, we have the next ODE\n\t\\begin{align*}\n\t\t\\frac{d \\hat{\\varphi}_n (t)}{dt} = - \\alpha P^2 n^2 \\hat{\\varphi}_n (t), \\hspace{2mm} |n| \\leq N \n\t\\end{align*}\n\twhich is solved using the projection of the initial condition given by\n\t\\begin{align}\n\t\\label{Galerkin_Linear}\t\n\t\t\\varphi_N (x, 0) = \\displaystyle \\sum_{|n| \\leq N} \\hat{\\varphi}_n (0) \\phi_n (x), \\hspace{2mm} \\hat{\\varphi}_n (0) = \\frac{1}{2 \\pi} \\langle \\varphi_0 (x), \\phi_n (x) \\rangle   \n\t\\end{align}\n\t\n\tWe will denote $\\lambda_n = \\alpha P^2 n^2$, so the exact solution for the above system is given as follows\n\t\\begin{align*}\n\t\t\\hat{\\varphi}_n (t) = \\hat{\\varphi}_n (0) e^{-\\lambda_n t}, \\hspace{2mm} |n| \\leq N\n\t\\end{align*} \n\t\n\tTherefore, using (\\ref{Expansion_phi_N}) the solution can be expressed as\n\t\\begin{align*}\n\t\t\\varphi_N (x, t) = \\displaystyle \\sum_{ |n| \\leq N} \\hat{\\varphi}_n (0) e^{-\\lambda_n t} \\phi (x) \n\t\\end{align*}\n\t\n\tWe can notice that $\\lambda_n$ is actually an eigenvalue of the problem (\\ref{Bugers_Lineal}), which is associated with the eigenvector $\\varphi_n (0)$. Therefore, we should note that what we are actually solving is an eigenvalues ​​problem to obtain a representation of the solution in terms of its eigenvectors. \\\\\n\t\n\tTo see this more clearly, we will represent the solution by configuring the following vectors\n\t\\begin{align*}\n\t\t\\hat{\\varphi}_N (t) = \\left[ \\hat{\\varphi}_{-N} , \\hat{\\varphi}_{-N + 1} (t), \\dots, \\hat{\\varphi}_N (t)  \\right]^T, \\hspace{2mm} \\hat{\\varphi}_N (0) = \\left[ \\hat{\\varphi}_{-N} (0) , \\hat{\\varphi}_{-N + 1} (0), \\dots, \\hat{\\varphi}_N (0)  \\right]^T\n\t\\end{align*}\n\t\n\t\\noindent and the matrix \n\t\\begin{align*}\n\t\t\\displaystyle \\mathcal{L}_N = {\\begin{bmatrix}\n\t\t\t\t\\lambda_{-N} & 0 & \\ldots & 0 & 0\\\\\n\t\t\t\t0 & \\lambda_{-N + 1} & \\ldots & 0 & 0\\\\\n\t\t\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\t\t\t0 & 0 & \\ldots & \\lambda_{N - 1} & 0\\\\\n\t\t\t\t0 & 0 & \\ldots & 0 & \\lambda_{N}\n\t\t\\end{bmatrix}},\n\t\\end{align*}\n\t\n\t\\noindent then we can express the solution system as \n\t\\begin{align*}\n\t\t\\hat{\\varphi}_N (t) =  e^{- \\mathcal{L}_N t} \\hat{\\varphi}_N (0), \n\t\\end{align*}\n\twhere $e^{- \\mathcal{L}_N}$ is the inverse of the exponential matrix of $\\mathcal{L}_N$ given by \n\t\\begin{align*}\n\t\t\\displaystyle e^{\\mathcal{L}_N} = {\\begin{bmatrix}\n\t\t\t\te^{\\lambda_{-N}} & 0 & \\ldots & 0 & 0\\\\\n\t\t\t\t0 & e^{\\lambda_{-N + 1}} & \\ldots & 0 & 0\\\\\n\t\t\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\t\t\t0 & 0 & \\ldots & e^{ \\lambda_{N - 1}} & 0\\\\\n\t\t\t\t0 & 0 & \\ldots & 0 & e^{\\lambda_{N}}\n\t\t\\end{bmatrix}}.\n\t\\end{align*}\n\t\n\tFrom the above, we can notice that the solution approaches very fast to zero when $ t $ tends to infinity. To show this, we can see that the solution is bounded as follows\n\t\\begin{align*}\n\t\t\\| \\varphi_N (x, t) \\|^2 &= \\displaystyle \\sum_{ |n| \\leq N} | \\hat{\\varphi}_n (t) |^2 = \\sum_{ |n| \\leq N} | \\hat{\\varphi}_n (0) |^2 e^{-2 \\lambda_n t} \\\\\n\t\t&\\leq e^{- 2 t} \\sum_{ |n| \\leq N} | \\hat{\\varphi}_n (0) |^2 = e^{- 2t} \\| \\varphi (0) \\|^2 \n\t\\end{align*}\n\tshowing us that the coefficients vanishing with exponential speed, which tells us that the convergence must have the same behavior. We can verify this with the following estimate\n\t\\begin{align*}\n\t\t\\| \\varphi(x, t) - \\varphi_N (x, t) \\|^2 &= \\displaystyle \\sum_{ |n| > N} | \\hat{\\varphi}_n (0) |^2 e^{-\\lambda_n t} \\leq e^{-\\lambda_N t} \\sum_{ |n| > N} | \\hat{\\varphi}_n (0) |^2 \\\\\n\t\t&\\leq e^{-\\lambda_N t} \\sum_{ |n| \\leq N} | \\hat{\\varphi}_n (0) |^2 = e^{-\\lambda_N t} \\|\\varphi_N (0) \\|^2 \n\t\\end{align*}\n\t\n\tTherefore, the rate of convergence is exponential, which verifies the theory studied in chapter \\ref{Chapter_2}, ensuring an excellent approximation of the solution of the problem (\\ref{IVP_Burgers}), which is obtained using (\\ref{Hopf_tranform}) to obtain\n\t\\begin{align}\n\t\\label{Exact_Solution_Approximation}\t\n\t\tu_N (x, t)  = - 2 \\alpha \\frac{\\partial_x \\varphi_N (x, t)}{ \\varphi_N (x, t)} = - 2 \\alpha \\frac{\\displaystyle \\sum_{ |n| \\leq N} in \\hat{\\varphi}_n (0) e^{- \\lambda_n t}  \\phi_n (x) }{\\displaystyle \\sum_{|n| \\leq N} \\hat{\\varphi}_n (0) e^{- \\lambda_n t}  \\phi_n (x)}\n\t\\end{align}\n\n\tThe previous expression is much more practical to calculate solutions to the problem (\\ref{IVP_Burgers}), we only have to handle the arithmetic operations correctly, and with low approximation orders we will have excellent results.", "meta": {"hexsha": "89da1243898927f4a770e85c3537c3e946ad924a", "size": 8308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/burgers_equation/deterministic/methods/Galerkin.tex", "max_stars_repo_name": "alanmatzumiya/Maestria", "max_stars_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-12-29T10:44:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T11:18:45.000Z", "max_issues_repo_path": "docs/burgers_equation/deterministic/methods/Galerkin.tex", "max_issues_repo_name": "alanmatzumiya/spectral-methods", "max_issues_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/burgers_equation/deterministic/methods/Galerkin.tex", "max_forks_repo_name": "alanmatzumiya/spectral-methods", "max_forks_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T13:29:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T13:29:56.000Z", "avg_line_length": 67.5447154472, "max_line_length": 363, "alphanum_fraction": 0.649735195, "num_tokens": 3162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7400883080733257}}
{"text": "\\section{Math}\n\n\\subsection{Geometric Sum}\nGeometric Sum for $q \\neq 1$:\n\\[\n\\sum\\limits_{k=1}^n q^k = \\frac{1-q^{n+1}}{1-q}\n\\]\nFor $\\lvert q \\rvert < 1$ the corresponding infinite sum converges:\n\n\\[\n\\sum_{i = 1}^{\\infty} q^k = \\frac{1}{1 - q}\n\\]\n\n\\subsection{Picks Theorem}\nFor every polygon with integer-only coordinates with following holds\nfor the area $A$, amount of interior integer points $i$ and amount of\nboundary points $b$:\n\\[\nA = i + \\frac{b}{2} - 1\n\\]\n\n\\lst{Calculation of border points:  }{$\\mathcal{O}(b\\cdot \\log(\\text{maxVal}))$}{geometry/picksTheorem.cc}\nFor polygon area see the geometry section.\n\n\\subsection{Eulers formular for planar graphs}\nFor every planar graph $G$ the following holds: $V - E + F = 2$\n\n\\subsection{Combinatorics}\n\n\\subsubsection{Binomial coefficient}\nNumber of possible sets with $k$ elements selected from $n$ elements. \n\\begin{equation*}\n  \\binom{n}{k} = \\binom{n}{n - k} = \\frac{n!}{k!(n - k)!} =\n  \\frac{n}{k}\\binom{n - 1}{k - 1} = \\binom{n - 1}{k} + \\binom{n - 1}{k\n  - 1}\n\\end{equation*}\n\\begin{center}\n\t\\begin{tabular}{ |l||l|l|l|l|l|l|l|l|l|l| } \n\t\t\\hline\n\t\t\\diagbox{$n$}{$k$} & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\\\\n\t\t\\hline\\hline\n\t\t0 &  1 &   &    &    &     &     &    &    &  &  \\\\\n\t\t1 &  1 & 1 &    &    &     &     &    &    &  &  \\\\\n\t\t2 &  1 & 2 & 1  &    &     &     &    &    &  &  \\\\\n\t\t3 &  1 & 3 & 3  & 1  &     &     &    &    &  &  \\\\\n\t\t4 &  1 & 4 & 6  & 4  & 1   &     &    &    &  &  \\\\\n\t\t5 &  1 & 5 & 10 & 10 & 5   & 1   &    &    &  &  \\\\\n\t\t6 &  1 & 6 & 15 & 20 & 15  & 6   & 1  &    &  &  \\\\\n\t\t7 &  1 & 7 & 21 & 35 & 35  & 21  & 7  & 1  &  &  \\\\\n\t\t8 &  1 & 8 & 28 & 56 & 70  & 56  & 28 & 8  & 1&  \\\\\n\t\t9 &  1 & 9 & 36 & 84 & 136 & 136 & 84 & 36 & 9& 1\\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{center}\n\\subsubsection{Catalan numbers}\nUse cases:\n\\begin{itemize}\n\\item The number of valid groupings of $n$ pairs of parentheses\n\\item The number of diagonal-avoiding paths on $n\\times n$ grid\n\\item The number of ways to triangulate a regular polygon with $n + 2$\n  sides\n\\item The number of rooted full binary trees with $n$ internal nodes\n\\item The number of rooted trees with $n$ edges\n\\item The number of ways to correctly parenthesize an ordered expression of $n\n  + 1$ items with a binary operation\n\\end{itemize}\n\\begin{equation*}\n  C_n = \\frac{1}{n + 1}\\binom{2n}{n} =\n  \\begin{cases}\n    1 & n = 0 \\lor n = 1\\\\\n    \\sum\\limits_{k = 0}^{n - 1}C_kC_{n - 1 - k} & \\text{otherwise}\n  \\end{cases}\n\\end{equation*}\nValues $C_0$ to $C_{10}$: $1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796$\n\n\\subsubsection{Euler numbers}\n\nThe number of permutations $1,\\ldots, n$ with exactly $k$\nnon-decreasing segments.\n\\begin{equation*}\n  \\left\\langle\n    \\begin{matrix}\n      n\\\\k\n    \\end{matrix}\n\\right\\rangle = \\sum\\limits_{l = 0}^k(-1)^l \\binom{n + 1}{l}(k + 1 - l)^n\n  =\n  \\begin{cases}\n    1 & k = 0 \\lor k = n\\\\\n    k \\left\\langle\n      \\begin{smallmatrix}\n        n - 1\\\\k\n      \\end{smallmatrix}\n\\right\\rangle + (n - k + 1) \\left\\langle\n  \\begin{smallmatrix}\n    n - 1\\\\k - 1\n  \\end{smallmatrix}\n\\right\\rangle & \\text{otherwise}\n  \\end{cases}\n\\end{equation*}\n\n\\begin{center}\n\t\\begin{tabular}{ |l||l|l|l|l|l|l|l|l| } \n\t\t\\hline\n\t\t\\diagbox{$n$}{$k$} & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7  \\\\\n\t\t\\hline\\hline\n\t\t0 &  1 &     &      &       &        &       &      &    \\\\\n\t\t1 &  1 & 1   &      &       &        &       &      &    \\\\\n\t\t2 &  1 & 4   & 1    &       &        &       &      &    \\\\\n\t\t3 &  1 & 11  & 11   & 1     &        &       &      &    \\\\\n\t\t4 &  1 & 26  & 66   & 26    & 1      &       &      &    \\\\\n\t\t5 &  1 & 57  & 302  & 302   & 57     & 1     &      &    \\\\\n\t\t6 &  1 & 120 & 1191 & 2416  & 1191   & 120   & 1    &    \\\\\n\t\t7 &  1 & 247 & 4293 & 15619 & 15619  & 4293  & 247  & 1  \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{center}\n\n\\subsubsection{Stirling Numbers of the first kind}\nNumber of permutations $1, \\dots, n$ with exactly $k$ cycles.\n\\begin{equation*}\n  \\begin{bmatrix}\n    n\\\\k\n  \\end{bmatrix} =\n  \\begin{cases}\n  \t1 & k = n \\\\\n    0 & k = 0 \\land n > 0\\\\\n    \\left[\n      \\begin{smallmatrix}\n        n - 1\\\\k - 1\n      \\end{smallmatrix}\n\\right] + (n - 1) \\left[\n  \\begin{smallmatrix}\n    n-1\\\\k\n  \\end{smallmatrix}\n\\right] & \\text{otherwise}\n  \\end{cases}\n\\end{equation*}\n\n\\begin{center}\n\t\\begin{tabular}{ |l||l|l|l|l|l|l|l|l|l |} \n\t\t\\hline\n\t\t\\diagbox{$n$}{$k$} & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8  \\\\\n\t\t\\hline\\hline\n\t\t0 & 1 &        &       &      &        &     &    &     & \\\\\n\t\t1 & 0 &  1    &       &       &      &      &     &     &  \\\\\n\t\t2 & 0 &  1    & 1     &       &      &      &     &     &  \\\\\n\t\t3 & 0 &  2    & 3     & 1     &      &      &     &     &  \\\\\n\t\t4 & 0 &  6    & 11    & 6     & 1    &      &     &     &  \\\\\n\t\t5 &  0 & 24   & 50    & 35    & 10   & 1    &     &     &  \\\\\n\t\t6 & 0 &  120  & 274   & 225   & 85   & 15   & 1   &     &  \\\\\n\t\t7 & 0 &  720  & 1764  & 1624  & 735  & 175  & 21  & 1   &  \\\\\n\t\t8 & 0 &  5040 & 13068 & 13132 & 6769 & 1960 & 322 & 28 & 1 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{center}\n\n\\subsubsection{Stirling Numbers of the second kind}\n\nNumber of partitions of $n$ elements into $k$ sets.\n\\begin{equation*}\n  \\begin{Bmatrix}\n    n\\\\k\n  \\end{Bmatrix} =\n  \\begin{cases}\n    1 & k = n\\\\\n    0 & k = 0 \\land n > 0 \\\\\n    \\left\\{\n      \\begin{smallmatrix}\n        n - 1\\\\k - 1\n      \\end{smallmatrix}\n\\right\\} + k \\left\\{\n  \\begin{smallmatrix}\n    n - 1\\\\k\n  \\end{smallmatrix}\n\\right\\} & \\text{otherwise}\n  \\end{cases}\n\\end{equation*}\n\\begin{center}\n\t\\begin{tabular}{ |l||l|l|l|l|l|l|l|l|l| } \n\t\t\\hline\n\t\t\\diagbox{$n$}{$k$} & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7  & 8 \\\\\n\t\t\\hline\\hline\n\t\t0 & 1 &      & & & & & & & \\\\\n\t\t1 & 0 &  1 &     &     &      &      &     &     &  \\\\\n\t\t2 & 0 &  1 & 1   &     &      &      &     &     &  \\\\\n\t\t3 & 0 & 1 & 3   & 1   &      &      &     &     &  \\\\\n\t\t4 & 0 &  1 & 7   & 6   & 1    &      &     &     &  \\\\\n\t\t5 & 0 &  1 & 15  & 25  & 10   & 1    &     &     &  \\\\\n\t\t6 & 0 &  1 & 31  & 90  & 65   & 15   & 1   &     &  \\\\\n\t\t7 & 0 &  1 & 63  & 301 & 350  & 140  & 21  & 1   &  \\\\\n\t\t8 & 0 &  1 & 127 & 966 & 1701 & 1050 & 266 & 28 & 1 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{center}\n\n\\subsubsection{Derangements}\nAmount of permutations of a set with $n$ elements such that no element\nis at its starting position.\n\\begin{equation*}\n  \\text{der}(n)\n  \\begin{cases}\n    1 & n = 0\\\\\n    0 & n = 1\\\\\n    (n - 1)(\\text{der}(n - 1) + \\text{der}(n - 2)) & \\text{otherwise}\n  \\end{cases}\n\\end{equation*}\nFirst values: $1, 0, 1, 2, 9, 44, 265, 1854, 14833, 133496, 1334961, 14684570$\n\n\\subsection{Primes}\n\\begin{center}\n\t$\\begin{tabu}{ |lllllllllllll| } \n\t\t\\hline\n\t\t2        & 3   & 5   & 7        & 11  & 13  & 17      & 19  & 23  & 29_{10} & 31       & 37  & 41  \\\\\n\t\t43       & 47  & 53  & 59       & 61  & 67  & 71_{20} & 73  & 79  & 83      & 89       & 97  & 101 \\\\\n\t\t103      & 107 & 109 & 113_{30} & 127 & 131 & 137     & 139 & 149 & 151     & 157      & 163 & 167 \\\\\n\t\t173_{40} & 179 & 181 & 191      & 193 & 197 & 199     & 211 & 223 & 227     & 229_{50} & 233 & 227 \\\\\n\t\t\\hline\n\t\\end{tabu}$\n\t\n\t\n\t$\\begin{tabu}{|llllllllll|}\n\t\t\\hline\n\t\t10^i & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\\\\n\t\t\\hline\n\t\t\\text{cnt} & 4 & 25 & 168 & 1229 & 9592 & 78498 & 664579 & 5761455 & 50847534 \\\\\n\t\t\\hline\n\t\\end{tabu}$\n\\end{center}\n\n\\subsection{Number of Divisors}\n\\begin{center}\n  $\\begin{tabu}{|llllllllll|}\n    \\hline\n    \\leq 10^i   & 1 &  2 &  3 &  4 &   5 &   6 &   7 &   8 & 9 \\\\\\hline\n    \\text{cnt}  & 4 & 12 & 32 & 64 & 128 & 240 & 448 & 768 & 1344\\\\\n    \\hline\n  \\end{tabu}$\n\\end{center}\n\n\\subsubsection{Hypergeometric distribution}\nSet with $N$ elements of which $K$ have a wanted property. The\nprobability of $k$ elements having property $K$ when choosing $n$ is\n\\[\nH = \\frac{\n\t\\left(\\begin{array}{c}K\\\\k\\end{array}\\right)\n\t\\cdot \n\t\\left(\\begin{array}{c}N-K\\\\n-k\\end{array}\\right)\n}\n{\n\t\\left(\\begin{array}{c}N\\\\n\\end{array}\\right)\n}\n\\]\n\\subsection{Newton Method}\n%TODO(Alex): More information when to use.\nThe intersections of a function $f$ with the x-axis can be\napproximated iteratively:\n\\[\nx_{n + 1} = x_n - \\frac{f(x_n)}{f'(x_n)} \n\\]\nThe method converges towards the solution quadratically therefore\ndoubleing the amount of correct decimal places every iteration.\n", "meta": {"hexsha": "5f45c3f963894750053bccbf3a10486d826c3736", "size": 8184, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "document/math.tex", "max_stars_repo_name": "Zeldacrafter/CompProg", "max_stars_repo_head_hexsha": "5367583f45b6fe30c4c84f3ae81accf14f8f7fd3", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-02-06T15:44:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-21T03:51:21.000Z", "max_issues_repo_path": "document/math.tex", "max_issues_repo_name": "Zeldacrafter/CompProg", "max_issues_repo_head_hexsha": "5367583f45b6fe30c4c84f3ae81accf14f8f7fd3", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "document/math.tex", "max_forks_repo_name": "Zeldacrafter/CompProg", "max_forks_repo_head_hexsha": "5367583f45b6fe30c4c84f3ae81accf14f8f7fd3", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.2366412214, "max_line_length": 106, "alphanum_fraction": 0.4861925709, "num_tokens": 3648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.870597271765821, "lm_q1q2_score": 0.7399825932243032}}
{"text": "\\chapter{  Single Variable Calculus}\r\n\\section{Limits and Continuity}\r\n\\subsection{Limits}\r\n\\begin{definition}\r\n\tLet $f(x)$ be defined on an open interval about $x_{0}$, except possibly at $x_{0}$ itself. If $f(x)$ gets arbitrarily close to $l$ for all $x$ sufficiently close to $x_{0}$,  We say that $f(x)$ approaches  the limit $l$   as $x$ approaches $x_{0}$ , and write,\r\n\t$$\r\n\t\\lim _{x \\rightarrow x_{0}} f(x)=l\r\n\t$$\r\n\tIf, for every number $\\epsilon>0$, there exists a corresponding number $\\delta>0$ such that for all $x$\r\n\t$$\r\n\t0<\\left|x-x_{0}\\right|<\\delta \\quad \\Rightarrow \\quad|f(x)-l|<\\epsilon\r\n\t$$\r\n\\end{definition}\r\n\r\n\r\n\\subsubsection{Left-Hand and Right-Hand Limits}\r\n\\subsubsection{Left-Hand Limits}\r\nIf the values of a function $f(x)$ at $x=c$ can be made as close as desired to the number $l_{1}$ at points close to and on the left of $c$, then $l_{1}$ is called left-hand limit. It is denoted by\r\n$$\r\n\\lim _{x \\rightarrow c^{-}} f(x)=l_{1}\r\n$$\r\n\\subsubsection{Right-Hand Limits}\r\nIf the values of a function $f(x)$, at $x=c$ can be made as close as desired to the number $l_{2}$ at points close to and on the right of   $c$, then $l_{2}$ is called right-hand limit.  It is denoted by,\r\n$$\r\n\\lim _{x \\rightarrow c^{+}} f(x)=l_{2}\r\n$$\r\n\\subsubsection{Properties of Limits}Suppose we have $\\lim _{x \\rightarrow c} f(x)=a, \\lim _{x \\rightarrow c} g(x)=b$ \\begin{itemize}\r\n\t\\item  $\\lim _{x \\rightarrow c}(f(x) \\pm g(x))=\\lim _{x \\rightarrow c} f(x) \\pm \\lim _{x \\rightarrow c} g(x)=a \\pm b$\r\n\t\\item  $\\lim _{x \\rightarrow c}(f(x) \\cdot g(x))=\\lim _{x \\rightarrow c} f(x) \\cdot \\lim _{x \\rightarrow c} g(x)=a \\cdot b$\r\n\t\\item $\\lim _{x \\rightarrow c}\\left(\\frac{f(x)}{g(x)}\\right)=\\frac{\\lim _{x \\rightarrow c} f(x)}{\\lim _{x \\rightarrow c} g(x)}=\\frac{a}{b},$ where $b \\neq 0$\r\n\t\\item  $\\lim _{x \\rightarrow c} k f(x)=k \\lim _{x \\rightarrow c} f(x),$ where $k$ is a constant.\r\n\t\\item  $\\lim _{x \\rightarrow c}|f(x)|=\\left|\\lim _{x \\rightarrow c} f(x)\\right|=|a|$\r\n\t\\item   $\\lim _{x \\rightarrow c}\\left[ f(x)\\right] ^{g(x)}$ =$\\lim _{x \\rightarrow c}\\left[ f(x)\\right] ^{\\lim _{x \\rightarrow c}\\left[ g(x)\\right] }$=\\ $ a^{b}$\r\n\t\\item  If $\\lim _{x \\rightarrow c} f(x)=\\pm \\infty,$ then $\\lim _{x \\rightarrow c} \\frac{1}{f(x)}=0$\r\n\\end{itemize}\r\n\\subsubsection{Important Limits}\r\n\\begin{itemize}\r\n\t\\item $\\lim _{x \\rightarrow 0} \\frac{\\sin x}{x}=1$\r\n\t\\item $\\lim _{x \\rightarrow 0} \\frac{\\tan x}{x}=1$\r\n\t\\item  $\\lim _{x \\rightarrow 0} \\cos x=1$\r\n\t\\item $\\lim _{x \\rightarrow 0}(1+x)^{1 / x}=\\lim _{x \\rightarrow \\infty}\\left(1+\\frac{1}{x}\\right)^{x}=e$\r\n\t\\item $\\lim _{x \\rightarrow 0} \\frac{\\log (1+x)}{x}=1$\r\n\t\\item $\\lim _{x \\rightarrow 0} \\frac{\\left(a^{x}-1\\right)}{x}=\\log a,$ if $(a>0)$\r\n\t\\item $\\lim _{x \\rightarrow 0} \\frac{x^{n}-a^{n}}{x-a}=n a^{n-1}$\r\n\t\\item  $\\lim _{x \\rightarrow \\infty} \\frac{\\log x}{x^{m}}=0,$ if $(m>0)$\r\n\\end{itemize}\r\n\\subsubsection{ L'Hôpital's rule}\r\nL'Hôpital's rule is a method finding the limits of indeterminant forms. \r\n\\begin{align*}\r\nx \\ln x &\\quad  \\text { as } x  \\rightarrow 0^{+}, \\\\\r\nx e^{-x} & \\quad  \\text { as } x \\rightarrow \\infty \\\\\r\n\\frac{\\ln x}{x} & \\quad   \\text { as } x \\rightarrow \\infty\r\n\\end{align*}\r\n\r\n\\begin{definition}\r\n\tIf $\\lim _{x \\rightarrow c} f(x)=\\lim _{x \\rightarrow c} g(x)=0$ or $\\pm \\infty, \\lim _{x \\rightarrow c} \\frac{f^{\\prime}(x)}{g^{\\prime}(x)}$ exists and\r\n\t$g^{\\prime}(x) \\neq 0$ for all $x$, then,\r\n\t$$\r\n\t\\lim _{x \\rightarrow c} \\frac{f(x)}{g(x)}=\\lim _{x \\rightarrow c} \\frac{f^{\\prime}(x)}{g^{\\prime}(x)}\r\n\t$$\r\n\t\r\n\\end{definition}\r\n\\begin{exercise}\r\n\tEvaluate $\\lim _{x \\rightarrow 0} \\frac{\\sin 5 x}{\\sin 2 x}$\r\n\\end{exercise}\r\n\\begin{answer}\r\n\tHere $f(x)=\\sin 5 x$, $g(x)=\\sin 2 x$, and $a=0 .$ Since $f(a)=g(a)=\\sin 0=0$, we can apply L'Hôpital's rule and find this limit:\r\n\t\r\n\t\\begin{align*}\r\n\t\\lim _{x \\rightarrow 0} \\frac{\\sin 5 x}{\\sin 2 x} &=\\lim _{x \\rightarrow 0} \\frac{5 \\cos 5 x}{2 \\cos 2 x} \\quad \\text { (l'Hop) } \\\\\r\n\t&=\\lim _{x \\rightarrow 0} \\frac{5 \\cos (5 \\cdot 0)}{2 \\cos (2 \\cdot 0)} \\\\\r\n\t&=\\frac{5}{2}\r\n\t\\end{align*}\r\n\t\r\n\\end{answer}\r\n\\section{Continuous Functions}\r\n\\begin{definition}\r\n\tThe function $f(x)$ is continuous at $x=c$ if\r\n\t$$\r\n\t\\lim _{\\mathrm{x}_{\\rightarrow} c^{-}} f(x)=\\lim _{\\mathrm{x}_{\\rightarrow} c^+} f(x) \\text { i.e. } \\lim _{\\mathrm{x} \\rightarrow c} f(x) \\text { exists and equals } f(c)\r\n\t$$\r\n\tThe function $f$ is said to be continuous on its domain, if it is continuous at each point in it's domain. If $f$ is not continuous at a particular value  $c$, we say that $f$ is discontinuous at $c$ or that $f$ has a discontinuity at $c$.\r\n\\end{definition}\r\n\\textbf{\\large Continuity test:}\\\\\r\nA function $f(x)$ is continuous at $x=c$ if and only if it meets the following three conditions.\r\n\\begin{enumerate}\r\n\t\\item $f(c)$ exists\r\n\t( $c$ lies in the domain of $f$ )\r\n\t\\item $\\lim _{x \\rightarrow c} f(x)$ exists $\\quad(f$ has a limit as $x \\rightarrow c)$\r\n\t\\item $\\lim _{x \\rightarrow c} f(x)=f(c) \\quad$ (The limit equals the function value)\r\n\\end{enumerate}\r\n\\section{Differentiability}\r\n\\begin{definition}\r\n\tA real-valued function $f(x)$ defined on an open interval $(a, b) .$ The function is said to be differentiable for $x=c$, if\r\n\t$$\\lim _{h \\rightarrow 0} \\frac{f(c+h)-f(c)}{h}\\quad\\text{exists for every}\\quad c \\in(a, b)$$\r\n\tA function is always continuous at a point if the function is differentiable at the same point. However, the converse is not always true.\r\n\\end{definition}\r\n\\section{Tangents and Normals}\r\n\\subsection{Tangents}\r\n\\begin{wrapfigure}{r}{0.25\\textwidth}\r\n\t\\begin{center}\r\n\t\t\\includegraphics[width=0.25\\textwidth]{tangents}\r\n\t\\end{center}\r\n\t\\caption{tangent to a curve.}\r\n\\end{wrapfigure}\r\nThe tangent line to a curve at a given point is the straight line  that touches the curve at that point. The point is called pont of tangency.\\\\\\\\\r\nLet $y=f(x)$ be a given curve and $P(x, y)$ and $Q(x+\\delta x, y+\\delta y)$ be two\r\nneighbouring points on it. Equation of the line $P Q$ is,\r\n\\begin{align}\r\nY-y&=\\frac{y+\\delta y-y}{x+\\delta x-x}(X-x)\r\n\\Longrightarrow Y-y=\\frac{\\delta y}{\\delta x}(X-x)\r\n\\end{align}\r\nThis line will be tangent to the given curve at $P$, if $Q \\rightarrow P$ which in turn means that $\\delta x \\rightarrow 0$ and we know that \r\n\r\n\\begin{align}\r\n\\lim _{\\delta x \\rightarrow 0} \\frac{\\delta y}{\\delta x}&=\\frac{d y}{d x}\\\\\\text{Therefore the equation of the tangent is,}\\notag\\\\\r\nY-y&=\\frac{d y}{d x}(X-x)\r\n\\end{align} \r\n\\subsection{Normals}\r\nThe normal at a point $(x, y)$  is the line perpendicular (at right angles) to the tangent at that point. It's slope is given by,\r\n\\begin{align}\r\n\\text{Slope  }&=\\frac{-1}{{d y}/{d x}}\\\\\r\n\\text{And hence equation of the normal is ,}\\notag\\\\\r\nY-y&=\\frac{-1}{d y / d x}(X-x)\r\n\\end{align} \r\n\r\n\\subsubsection{Geometrical meaning }\r\n$d y / d x$ represents the slope of the tangent to the given curve $y=f(x)$ at any point $(x, y).$\r\n$$ \\frac{d y}{d x}=\\tan \\theta$$($\\theta$={The angle which the tangent to the curve makes with +ve direction of $x$ -axis.} )\r\n\\section{Monotonic Functions}\r\n  A monotonic function is a function which is either entirely nonincreasing or nondecreasing on an interval $\\left( a,b\\right) $. A function is monotonic if its first derivative (which need not be continuous) does not change sign.\r\n  \\begin{enumerate}\r\n  \t\\item A function  $f(x)$ is called monotonically increasing (also increasing or non-decreasing) on an interval $\\left( a,b\\right) $, if,\r\n  \t$$ x_{1}\\leq x_{2} \\Rightarrow  f\\left( x_{1}\\right) \\leq f\\left( x_{2}\\right) \\ \\text{For all values of }  x_{1}, x_{2} \\in \\left( a,b\\right)    $$\r\n  \tAnd if,\r\n  \t $$ x_{1} < x_{2} \\Rightarrow  f\\left( x_{1}\\right) < f\\left( x_{2}\\right) \\ \\text{For all values of }  x_{1}, x_{2} \\in \\left( a,b\\right)    $$\r\n  \t\\item \r\n  \tA function $f(x)$ is said to be  decreasing on an interval $\\left( a,b\\right) $  if, \r\n  \t$$ x_{1}\\leq x_{2} \\Rightarrow  f\\left( x_{1}\\right) \\geq f\\left( x_{2}\\right) \\ \\text{For all values of }  x_{1}, x_{2} \\in \\left( a,b\\right)    $$\r\n  \t A function $f(x)$ is said to be strictly decreasing on an interval $\\left( a,b\\right) $  if,\r\n  \t \t$$ x_{1}< x_{2} \\Rightarrow  f\\left( x_{1}\\right) > f\\left( x_{2}\\right) \\ \\text{For all values of }  x_{1}, x_{2} \\in \\left( a,b\\right)    $$\r\n  \\end{enumerate}\r\n\r\n \\subsubsection{Conditions for Increasing and Decreasing Functions}\r\n Consider $f(x)$ to be continous on  $ \\left[  a, b\\right]$ and differentiable on $\\left(a,b \\right) $ then,\r\n \\begin{itemize}\r\n \\item  If $f^{\\prime}(x)>0$ for each $x$ in $(a, b)$ then $f$ is (strictly) increasing on $(a, b)$.\r\n \\item  If $f^{\\prime}(x)<0$ for each $x$ in $(a, b)$ then $f$ is (strictly) decreasing on $(a, b)$.\r\n \\item  If $f^{\\prime}(x)=0$ for each $x$ in $(a, b)$ then $f$ is a constant function on $(a, b)$.\r\n \\begin{itemize}\r\n \t\\item  If $f^{\\prime}\\left(x^{+}\\right)>0$ and $f^{\\prime}\\left(x^{-}\\right)>0$, then increasing at $x$ for all $ x \\in (a, b) $.\r\n \t\\item If $f^{\\prime}\\left(x^{+}\\right)<0$ and $f^{\\prime}\\left(x^{-}\\right)<0$, then decreasing at $x$ for all $ x \\in (a, b) $.\r\n \t\\item Otherwise neither increasing nor decreasing.\r\n \\end{itemize}\r\n \\item  If $f^{\\prime}(x)=g^{\\prime}(x)$ for each $x$ in $(a, b)$ then there exists a constant $c$ such that $f(x)=g(x)+c$ for each $x$ in $(a, b)$.\t\r\n \\end{itemize}\r\n\\begin{minipage}{0.45\\textwidth}\r\n\t\\begin{figure}[H]\r\n\t\t\\centering\r\n\t\t\\includegraphics[height=5cm,width=6cm]{increasing}\r\n\t\t\\caption{Increasing Function}\r\n\t\t\\label{Increasing Function}\r\n\t\\end{figure}\r\n\\end{minipage}\r\n \\begin{minipage}{0.45\\textwidth}\r\n \t\\begin{figure}[H]\r\n \t\t\\centering\r\n \t\t\\includegraphics[height=5cm,width=6cm]{decreasing}\r\n \t\t\\caption{Decreasing Function}\r\n \t\t\\label{Decreasing Function}\r\n \t\\end{figure}\r\n \\end{minipage}\r\n\\begin{exercise}\r\n\tLet $f(x)=x^{3}-3 x^{2}+3 x+y .$ Examine the nature of function at $x=0$ and 1 .\r\n\\end{exercise}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n\tf(x)&=x^{3}-3 x^{2}+3 x+4 \\\\ f^{\\prime}(x)&=3 x^{2}-6 x+3\\\\\r\n\t\\text{At} \\quad x&=0,\\ f^{\\prime}(0)=3>0. \\intertext{Hence $f(x)$ is increasing at $x=0$}\r\n\t\\text{\tAt } \\quad x&=1, f^{\\prime}(1)=3-6+3=0 . \\intertext{Hence, let's check $f^{\\prime}\\left(1^{+}\\right)$ and $f\\left(1^{-}\\right)$}\r\n\t\\text{Clearly,} \\quad  f^{\\prime}\\left(1^{+}\\right)&=f(x=1.001)>0\\\\ \\text{And,}\\ \\left.f^{\\prime}(1^{-}\\right)&=f(x=0.999)>0\r\n\t\\intertext{Hence $f(x)$ is increasing at $x=1$.}\r\n\\end{align*}\r\n\\end{answer}\r\n\\section{Maxima and Minima of Functions}\r\nFor a continuous and differentiable function $f(x)$ a stationary point $x^{*}$ is a point at which the slope of the function vanishes, i.e. $f^{\\prime}(x)=0$ at $x=x^{*}$, where $x^{*}$ belongs to its domain of\r\ndefinition. A stationary point may be a minimum, maximum or a saddle point(inflection point). \r\n\\subsection{maximum value}\r\nA function $f(x, y)$ is said to have a maximum value at $x=a, y=b$, if there exists a small neighbourhood of $(a, b)$ such that,\r\n$$\r\nf(a, b)>f(a+h, b+k)\\ \\text{for all values of}\\ \\left(h,k \\right)\r\n$$\r\n\\subsection{Minimum value }\r\nA function $f(x, y)$ is said to have a minimum value for $x=a, y=b$, if there exists a small neighbourhood of\r\n $(a, b)$ such that $$f(a, b)<f(a+h, b+k) \\text{for all values of}\\ \\left(h,k \\right)$$.\r\n \\\\The maximum and minimum values of a function are also called extreme or extremum values of the function.\r\n\r\n \\begin{note}\r\n \t \\leavevmode\r\n \t\\\\\\\\\r\n \t\\textbf{Saddle point:} It is a point where function is neither maximum nor minimum.\r\n \\end{note}\r\nIf $f(a+h, b+k)-f(a, b)$ remains of the same sign for all values (positive or negative) of $(h, k)$, then $f(a, b)$ is said to be extremum value of $f(x, y)$ at $(a, b).$\r\n\\begin{itemize}\r\n\t\\item If $f(a+h, b+k)-f(a, b)<0$, Then $f(a, b)$ is maximum.\r\n\t\\item If $f(a+h, b+k)-f(a, b)>0$, Then $f(a, b)$ is minimum.\r\n\\end{itemize}\r\n\\subsubsection{Rules to find Extremum values}\r\n\\begin{enumerate}\r\n\t\\item Differentiate $y=f(x)$ and find out\r\n$\\frac{dy}{dx}$\r\n\t\\item Put $\\frac{d y}{d x}=0$ and solve these equations for $x$  . Let one root of $\\frac{d y}{d x}=0$ is at $x=a$.\r\n\t\\item If $\\frac{d^{2} y}{d^{2} x}=-v e$ for $x=a$, then maxima is at $x=a$.\r\n\t\\item If $\\frac{d^{2} y}{d^{2} x}=+v e$ for $x=a$, then minima is at $x=a$.\r\n\t\\item If $\\frac{d^{2} y}{d^{2} x}=0$ at $x=a$, then find $\\frac{d^{3} y}{d^{3} x}$.\r\n\t\\\\\\\\If $\\frac{d^{3} y}{d^{3} x} \\neq 0$ at $x=a$, neither maximum nor minimum at $x=a$.\r\n\t\\\\\\\\If $\\frac{d^{3} y}{d^{3} x}=0$ at $x=a$, then find $\\frac{d^{4} y}{d^{4} x}$ and investigate further.\r\n\t\r\n\\end{enumerate}\r\n\\begin{figure}[H]\r\n\t\\begin{center}\r\n\t\t\\includegraphics[width=0.75\\textwidth]{minima}\r\n\t\\end{center}\r\n\\caption{Minima and Maxima of functions}\r\n\\end{figure}\r\n\\begin{exercise}\r\n\tFind the equilibrium points and  find it's nature.\r\n\t\\\\1.$ f(x)=x^{3}-3x+9$\r\n\t\\\\2.$f(x)=2 x^{3}-21 x^{2}+36 x $\r\n\\end{exercise}\r\n\\begin{answer}1.\r\n\t\\begin{align*}\r\n\tf^{\\prime}(x)&=\\frac{df}{dx}=3x^{2}-3\\\\\r\n\t\\text{Equating }\\quad\\frac{df}{dx} &=0\\\\\r\n\t\\text{we get,}x&=1,-1\\\\\r\n\t\\frac{d^{2}f}{dx^{2}}&=6x\\\\\r\n\t\\frac{d^{2}f}{dx^{2}}\\bigg\\rvert_{x=1}&=6>0\\quad(\\text{Local minima})\\\\\r\n\t\\frac{d^{2}f}{dx^{2}}\\bigg\\rvert_{x=1}&=-6<0\\quad(\\text{Local maxima})\\\\\r\n\t\\end{align*}\r\n\t2.\r\n\t\\begin{align*}\r\n\t f^{\\prime}(x)&=6 x^{2}-42 x+36\\\\\r\n\t \\text{Equating }\\quad\\frac{df}{dx} &=0\\\\\r\n\t  6 x^{2}-42 x+36&= 0\\\\\r\n\t  (x-1)(x-6)&=0 \\rightarrow x=1,6 \\\\\r\n\t  \\frac{d^{2}f}{dx^{2}}&=12 x-42\\\\\r\n\t  \\frac{d^{2}f}{dx^{2}}\\bigg\\rvert_{x=1}&=-30<0\\quad(\\text{Local maxima.})\\\\\r\n\t  \\frac{d^{2}f}{dx^{2}}\\bigg\\rvert_{x=1}&=30>0\\quad(\\text{Local minima.})\r\n\t  \\end{align*}\r\n\t\r\n\\end{answer}\r\n\r\n\\section{Differentiation}\r\nLet $y=f(x)$ be a differentiable function. The differential $d x$ is an independent variable.Then the differential $d y$ is given by,\r\n\\begin{align*}\r\nd y&=f^{\\prime}(x) d x\\\\\r\n\\frac{d y}{d x}&=f^{\\prime}(x)\r\n\\end{align*}\r\n\\subsection{Important Properties of Differentiation} \r\n\\begin{enumerate}\r\n\t\\item $\\frac{d}{d x}(f(x)+g(x))=\\frac{d}{d x} f(x)+\\frac{d}{d x} g(x)$\r\n\t\\item $\\frac{d}{d x}(f(x)-g(x))=\\frac{d}{d x} f(x)-\\frac{d}{d x} g(x)$\r\n\t\\item $\\frac{d}{d x}(f(x) \\cdot g(x))=f(x) \\cdot \\frac{d}{d x}(g(x))+\\frac{d}{d x}(f(x)) \\cdot g(x)$\r\n\t\\item $\\frac{d}{d x}\\left(\\frac{f(x)}{g(x)}\\right)=\\frac{\\frac{d}{d x} f(x) \\cdot g(x)-f(x) \\frac{d}{d x} g(x)}{(g(x))^{2}}$\r\n\\end{enumerate}\r\n\\textcolor{ocre}{(\\large * The section \\ref{partial diferentiation} can be omitted without losing continuity.)}\r\n\\subsection{Partial Differentiation}\\label{partial diferentiation}\r\n\\begin{definition}\r\n\tThe partial derivative of $\\boldsymbol{f}(\\boldsymbol{x}, \\boldsymbol{y})$ with respect to $\\boldsymbol{y}$ at the point $\\left(x_{0}, y_{0}\\right)$ is\r\n\t$$\r\n\t\\left.\\frac{\\partial f}{\\partial y}\\right|_{\\left(x_{0}, y_{0}\\right)}=\\left.\\frac{d}{d y} f\\left(x_{0}, y\\right)\\right|_{y=y_{0}}=\\lim _{h \\rightarrow 0} \\frac{f\\left(x_{0}, y_{0}+h\\right)-f\\left(x_{0}, y_{0}\\right)}{h},\r\n\t$$\r\n\tprovided the limit exists.\r\n\\end{definition}\r\nIf a derivative of function of several independent variable, $f(x,y,z..)$ be found with respect to any one of them, keeping the others as constants, it is said to be partial derivative .And the operation of finding is called partial differentiation.\r\n\\\\\\\\The partial derivative of $f(x, y)$ with respect to $x$ and $y$ are generally denoted by,\r\n\\begin{align*}f_{x}=\\frac{\\partial f}{\\partial x}\\quad &;\\quad f_{y}=\\frac{\\partial f}{\\partial y}\\\\\r\n \\frac{\\partial}{\\partial x}\\left(\\frac{\\partial f}{\\partial x}\\right) \\equiv \\frac{\\partial^{2} f}{\\partial x^{2}} \\equiv f_{x x}\\quad &;\\quad \\frac{\\partial}{\\partial y}\\left(\\frac{\\partial f}{\\partial y}\\right) \\equiv \\frac{\\partial^{2} f}{\\partial y^{2}} \\equiv f_{y y} \\\\\r\n\t\\frac{\\partial}{\\partial x}\\left(\\frac{\\partial f}{\\partial y}\\right) \\equiv \\frac{\\partial^{2} f}{\\partial x \\partial y} \\equiv f_{x y} \\quad &;\\quad \\frac{\\partial}{\\partial y}\\left(\\frac{\\partial f}{\\partial x}\\right) \\equiv \\frac{\\partial^{2} f}{\\partial y \\partial x} \\equiv f_{y x}\\quad \\text { it is given that } f_{x y}=f_{y x}\r\n\\end{align*}\r\n\\begin{exercise}\r\n\tFind $\\partial f / \\partial y$ if $f(x, y)=y \\sin x y$.\r\n\t\r\n\\end{exercise}\r\n\\begin{answer}\r\nWe treat $x$ as a constant and $f$ as a product of $y$ and $\\sin x y$ :\r\n\\begin{align*}\r\n\\frac{\\partial f}{\\partial y} &=\\frac{\\partial}{\\partial y}(y \\sin x y)=y \\frac{\\partial}{\\partial y} \\sin x y+(\\sin x y) \\frac{\\partial}{\\partial y}(y) \\\\\r\n&=(y \\cos x y) \\frac{\\partial}{\\partial y}(x y)+\\sin x y\\\\&=x y \\cos x y+\\sin x y .\r\n\\end{align*}\r\n\\end{answer}\r\n\\begin{exercise}\r\n\tFind the values of $\\partial f / \\partial x$ and $\\partial f / \\partial y$ at the point $(4,-5)$ if\r\n\t$f(x, y)=x^{2}+3 x y+y-1$\r\n\\end{exercise}\r\n\\begin{answer}\r\n\t To find $\\partial f / \\partial x$, we treat $y$ as a constant and differentiate with respect to $x$\r\n\t \\begin{align*}\r\n\t \\frac{\\partial f}{\\partial x}&=\\frac{\\partial}{\\partial x}\\left(x^{2}+3 x y+y-1\\right)\\\\&=2 x+3 \\cdot 1 \\cdot y+0-0=2 x+3 y\\\\\r\n\t \\partial f / \\partial x|_{(4,5)} &=\r\n\t \t(4)+3(-5)=-7\r\n\t \\end{align*}\r\nTo find $\\partial f / \\partial y$, we treat $x$ as a constant and differentiate with respect to $y$ :\r\n\t\\begin{align*}\r\n\\frac{\\partial f}{\\partial y}&=\\frac{\\partial}{\\partial y}\\left(x^{2}+3 x y+y-1\\right)=0+3 \\cdot x \\cdot 1+1-0=3 x+1\\\\\r\n\\partial f / \\partial y|_{(4,5)}&= 3(4)+1=13\r\n\t\\end{align*}\r\n\t\r\n\\end{answer}\r\n\\begin{theorem}\r\n\t\\textbf{Euler's theorem:} \\\\If $u$ is a homogenous function of degree ' $n$ ' in $x$ and $y$ then\r\n\t$$\r\n\tx \\frac{\\partial u}{\\partial x}+y \\frac{\\partial u}{\\partial y}=n u\r\n\t$$\r\n\tFor any number of variables,\r\n\t$$\r\n\tx \\frac{\\partial u}{\\partial x}+y \\frac{\\partial u}{\\partial y}+z \\frac{\\partial u}{\\partial z}+\\ldots \\ldots \\ldots+w \\frac{\\partial u}{\\partial w}=n u\r\n\t$$\r\n\\end{theorem}\r\n\\begin{note}\r\n\t\\begin{align*}\r\n\t\t&\\text{If, }u=f(x, y) \\text{but, } \\quad x=\\phi(s, t); \\quad y=\\phi(s, t);\\\\\r\n\t\t\\text{Then, }&\\frac{\\partial u}{\\partial s}=\\frac{\\partial u}{\\partial x} \\cdot \\frac{\\partial x}{\\partial s}+\\frac{\\partial u}{\\partial y} \\cdot \\frac{\\partial y}{\\partial s}\\quad \\text { and }\\quad \\frac{\\partial u}{\\partial t}=\\frac{\\partial u}{\\partial x} \\cdot \\frac{\\partial x}{\\partial t}+\\frac{\\partial u}{\\partial y} \\cdot \\frac{\\partial y}{\\partial t}\r\n\t\\end{align*}\r\n\\end{note}\r\n\\begin{exercise}\r\n\tFind $\\partial z / \\partial x$ if the equation\r\n\t$$\r\n\ty z-\\ln z=x+y\r\n\t$$\r\n\tdefines $z$ as a function of the two independent variables $x$ and $y$ and the partial derivative exists.\r\n\\end{exercise}\r\n\\begin{answer}\r\n\tWe differentiate both sides of the equation with respect to $x$, holding $y$ constant and treating $z$ as a differentiable function of $x$ :\r\n\t\\begin{align*}\r\n\t\t\\frac{\\partial}{\\partial x}(y z)-\\frac{\\partial}{\\partial x} \\ln z &=\\frac{\\partial x}{\\partial x}+\\frac{\\partial y}{\\partial x} \\\\\r\n\t\ty \\frac{\\partial z}{\\partial x}-\\frac{1}{z} \\frac{\\partial z}{\\partial x} &=1+0 \\hspace{4cm}\r\n\t\t \\begin{array}{l}\r\n\t\t\t\\text { With } y \\text { constant, } \\\\\r\n\t\t\t\\frac{\\partial}{\\partial x}(y z)=y \\frac{\\partial z}{\\partial x}\r\n\t\t\\end{array} \\\\\r\n\t\t\\left(y-\\frac{1}{z}\\right) \\frac{\\partial z}{\\partial x}&=1 \\\\\r\n\t\t\\frac{\\partial z}{\\partial x}&=\\frac{z}{y z-1}\r\n\t\\end{align*}\r\n\\end{answer}\r\n\\section{Integration}\r\n\\subsection{Definite and Indefinite Integrals}\r\n\\subsection{Definite Integrals}\r\nIf a function $f(x)$ is defined in the interval $[a, b]$, then the definite integral of the function is given by\r\n$$\r\n\\int_{a}^{b} f(x) \\cdot d x=[F(x)]_{a}^{b}=F(b)-F(a)\r\n$$\r\nWhere $F(x)$ is an integral of $f(x), a$ is called the lower limit and $b$ is the upper limit of the integral.\r\nGeometrically, a definite integral represents the area bounded by a curve, $y=f(x), x$ -axis and the lines $x=a$ and $x=b$.\r\n\\subsubsection{Properties}\r\n\\begin{enumerate}\r\n\t\\item $ \\int_{a}^{b} f(x) \\cdot d x=\\int_{a}^{b} f(y) \\cdot d y$\r\n\t\\item  $\\int_{a}^{b} f(x) \\cdot d x=-\\int_{b}^{a} f(x) \\cdot d x$\r\n\t\\item  $\\int_{a}^{b} f(x) \\cdot d x=\\int_{a}^{c} f(x) \\cdot d x+\\int_{c}^{b} f(x) \\cdot d x \\quad$ if $a<c<b$\r\n\t\\item $\\int_{0}^{2 a} f(x) \\cdot d x=\\int_{0}^{a} f(x) \\cdot d x+\\int_{0}^{a} f(2 a-x) \\cdot d x$\r\n\t\\item $\\int_{0}^{a} f(x) \\cdot d x=\\int_{0}^{a} f(a-x) \\cdot d x$\r\n\t\\item $\\int_{-a}^{a} f(x) \\cdot d x=2 \\int_{0}^{a} f(x) \\cdot d x$, If the function is even. $\\int_{-a}^{a} f(x) \\cdot d x=0$, if the function is odd.\r\n\t\\item $\\int_{0}^{n a} f(x) \\cdot d x=n \\int_{0}^{a} f(x) \\cdot d x$ if $f(x)=f(x+a)$\r\n\\end{enumerate}\r\n\\subsection{Indefinite Integrals}\r\nThe set of all antiderivatives of the function $ f$ is called the\r\nindefinite integral of $ f$ with respect to $ x$, and is symbolized by,\r\n$$\r\n\\int f(x) d x\r\n$$\r\nAn indefinite integral $\\int f(x) d x$ is a function plus an arbitrary constant $C$.\r\n\\subsection{Methods of Integration}\r\n\r\n\\subsection{Integration by Substitution}\r\nIf $u=g(x)$ is a differentiable function whose range is an interval $I$ and $f$ is continuous on $I$, then\r\n$$\r\n\\int f(g(x)) g^{\\prime}(x) d x=\\int f(u) d u\r\n$$\r\n\\textbf{ Method of solving}\r\n\\begin{enumerate}\r\n\t\\item Substitute $u=g(x)$ and $d u=g^{\\prime}(x) d x$ to obtain the integral\r\n\t$$\r\n\t\\int f(u) d u\r\n\t$$\r\n\t\\item Integrate with respect to $u$.\r\n\t\\item Replace $u$ by $g(x)$ in the result.\r\n\\end{enumerate}\r\n\r\n\\begin{exercise}\r\n\tIntegrate \r\n\t\\begin{enumerate}\r\n\t\t\\item $\\int x^{2} \\sin \\left(x^{3}\\right) d x$\r\n\t\t\\item $ \\int \\frac{1}{\\cos ^{2} 2 x} d x$\r\n\t\t\\item $ \\int \\sin ^{2} x d x$\r\n\t\\end{enumerate}\r\n\\end{exercise}\r\n\\begin{answer}1.\\hspace{0.5cm}\r\n\t\r\n\\begin{minipage}{0.45\\textwidth}\r\n\t\\begin{align*}\r\n\t\\int x^{2} \\sin \\left(x^{3}\\right) d x &=\\int \\sin \\left(x^{3}\\right) \\cdot x^{2} d x \\\\\r\n\t&=\\int \\sin u \\cdot \\frac{1}{3} d u \\\\\r\n\t&=\\frac{1}{3} \\int \\sin u d u \\\\\r\n\t&=\\frac{1}{3}(-\\cos u)+C \\\\\r\n\t&=-\\frac{1}{3} \\cos \\left(x^{3}\\right)+C\r\n\t\\end{align*}\r\n\\end{minipage}\\hspace{2.5cm}\r\n\\begin{minipage}{0.35\\textwidth}\\hfill\r\n\t\t\r\n\t\\begin{align*}\r\n\t&\\text{Let,}u=x^{3}\\\\\r\n\t&d u=3 x^{2} d x \\\\\r\n\t&(1 / 3) d u=x^{2} d x\\\\\r\n\t&\\text{Integrate}\\text{ with respect to $u$}\\\\\\\\\\\\\r\n\t&\\text{Replace $u$ by $x^{3}$.}\r\n\t\\end{align*}\r\n\\end{minipage}\r\n\t\r\n\r\n\t\\begin{minipage}{0.45\\textwidth}\r\n\t\t2.\\vspace{0.2cm}\r\n\t\t\\begin{align*}\r\n\t\t\\int \\frac{1}{\\cos ^{2} 2 x} d x &=\\int \\sec ^{2} 2 x d x \\\\\r\n\t\t&=\\int \\sec ^{2} u \\cdot \\frac{1}{2} d u \\\\\r\n\t\t&=\\frac{1}{2} \\int \\sec ^{2} u d u \\\\\r\n\t\t&=\\frac{1}{2} \\tan u+C \\\\\r\n\t\t&=\\frac{1}{2} \\tan 2 x+C\r\n\t\t\\end{align*}\r\n\t\\end{minipage}\\hspace{2.5cm}\r\n\\begin{minipage}{0.35\\textwidth}\\hfill\r\n\t\r\n\t\\begin{align*}\r\n\t&\\frac{1}{\\cos 2 x}=\\sec 2 x \\\\\r\n\t&u=2 x \\\\\r\n\t&d u=2 d x \\\\\r\n\t&d x=(1 / 2) d u \\\\\r\n\t\\\\\r\n\t&\\frac{d}{d u} \\tan u=\\sec ^{2} u \\\\\r\n\t&u=2 x\r\n\\end{align*}\r\n\\end{minipage}\\\\\\\\\r\n3.\\vspace{0.2cm}\\begin{align*}\r\n\\int \\sin ^{2} x d x &=\\int \\frac{1-\\cos 2 x}{2} d x \\quad \\sin ^{2} x=\\frac{1-\\cos 2 x}{2}\\hspace{2cm} \\because\\sin ^{2} x=\\frac{1-\\cos 2 x}{2}\\\\\r\n&=\\frac{1}{2} \\int(1-\\cos 2 x) d x=\\frac{1}{2} \\int d x-\\frac{1}{2} \\int \\cos 2 x d x \\\\\r\n&=\\frac{1}{2} x-\\frac{1}{2} \\frac{\\sin 2 x}{2}+C=\\frac{x}{2}-\\frac{\\sin 2 x}{4}+C\r\n\\end{align*}\r\n\\end{answer}\r\n\\subsection{Integration by Parts}\r\nIntegration by parts is a technique for performing integration (definite and indefinite) by expanding the differential of a product of function $d(u v)$ and expressing the original integral in terms of a known integral.\r\n$$ \\int f(x) g^{\\prime}(x) d x=f(x) g(x)-\\int f^{\\prime}(x) g(x) d x$$\r\n Let $u=f(x)$ and $v=g(x)$. Then $d u=f^{\\prime}(x) d x$ and $d v=g^{\\prime}(x) d x$.\r\nThen,\r\n\\begin{center}\r\n\t\\framebox{\r\n\t\t\r\n\t\t\\parbox[t][1cm]{4cm}{\r\n\t\t\t\r\n\t\t\t\\addvspace{0.3cm} \\centering \r\n\t\t\t$\\int u d v=u v-\\int v d u$\t} \t}\r\n\\end{center}\r\n\\begin{note}\\leavevmode \\newline\r\nFor definite integral, $\\left.\\int_{a}^{b} f(x) g^{\\prime}(x) d x=f(x) g(x)\\right]_{a}^{b}-\\int_{a}^{b} f^{\\prime}(x) g(x) d x$\r\n\\end{note}\r\n\\subsubsection{Tabular Integration}\r\n\\begin{minipage}{0.5\\textwidth}\r\nTabular integration is a special technique for integration by parts. It can be applied to certain functions in the form $f(x)g(x)$, where one of $f(x)$ or $g(x)$  can be differentiated multiple times with ease, while the other function can be integrated multiple times with ease.\r\n\\end{minipage}\r\n\\begin{minipage}{0.5\\textwidth}\r\n\r\n\\begin{figure}[H]\r\n\t\t\\centering\r\n\t\\includegraphics[width=5cm, height=5cm]{tabular integration}\r\n\t\\caption{Tabular integration}\r\n\\end{figure}\r\n\\end{minipage}\r\n\r\n\\textbf{Method of solving}\r\n\\begin{enumerate}\r\n\t\\item In the product comprising the function , identify the polynomial and denote it $f(x)$. Denote the other function in the product by $g(x)$.\r\n\t\\item Create a table of $f(x)$ and $g(x)$, and successively differentiate $f(x)$ until you reach 0 . Successively integrate $g(x)$ the same amount of times.\r\n\t\\item Construct the integral by taking the product of $f(x)$ and the first integral of $g(x)$, then add the product of $f^{\\prime}(x)$ times the second integral of $g(x)$, then add the product of $f^{\\prime \\prime}(x)$ times the third integral of $g(x)$, etc...\r\n\\end{enumerate}\r\n\r\n{\\begin{exercise}\r\n\t\tIntegrate $\\int x^{2} e^{x} d x$\r\n\t\\end{exercise}\r\n\t\r\n\t\\begin{answer}.\\\\\r\n\t\t\\begin{minipage}{0.45\\textwidth}\r\n\t\t\t\\begin{align*}\r\n\t\t\t\\text { With } f(x)=x^{2} \\text { and } g(x)&=e^{x} \\text { , we list: }\\\\\r\n\t\t\t\\end{align*}\r\n\t\t\tWe combine the products of the functions connected by the arrows according to the operation signs above the arrows to obtain\t\r\n\t\t\t\\begin{align*}\r\n\t\t\t\\int x^{2} e^{x} d x&=x^{2} e^{x}-2 x e^{x}+2 e^{x}+C\r\n\t\t\t\\end{align*}\r\n\t\t\t\r\n\t\t\t\r\n\t\t\\end{minipage}\\hspace{2.5cm}\r\n\t\t\\begin{minipage}{0.35\\textwidth}\\hfill\r\n\t\t\t\r\n\t\t\t\\includegraphics[width=0.65\\textwidth]{tabularex}\r\n\t\t\\end{minipage}\r\n\\end{answer}}\r\n\r\n\r\n\\subsection{Integration by Partial fraction}\r\nThe method of integrating rational functions (of the form\\quad$\\frac{P(x)}{Q(x)}$)\\quad as a sum of simpler fractions is called the method of partial fraction.This method  works by algebraically splitting $P(x) / Q(x)$ into pieces that are easier to integrate.\r\n\\subsubsection{Method of solving}\r\n\\begin{enumerate}\r\n\t\\item Let $x-r$ be a linear factor of $Q(x)$. Suppose that $(x-r)^{m}$ is the highest power of $x-r$ that divides $Q(x)$. Then, to this factor, assign the sum of the $m$ partial fractions:\r\n\t$$\r\n\t\\frac{A_{1}}{x-r}+\\frac{A_{2}}{(x-r)^{2}}+\\cdots+\\frac{A_{m}}{(x-r)^{m}}\r\n\t$$\r\n\tDo this for each distinct linear factor of $Q(x)$\r\n\t\\item Let $x^{2}+p x+q$ be a quadratic factor of $Q(x)$. Suppose that $\\left(x^{2}+p x+q\\right)^{n}$ is the highest power of this factor that divides $Q(x)$. Then, to this factor, assign the sum of the $n$ partial fractions:\r\n\t$$\r\n\t\\frac{B_{1} x+C_{1}}{x^{2}+p x+q}+\\frac{B_{2} x+C_{2}}{\\left(x^{2}+p x+q\\right)^{2}}+\\cdots+\\frac{B_{n} x+C_{n}}{\\left(x^{2}+p x+q\\right)^{n}}\r\n\t$$\r\n\tDo this for each distinct quadratic factor of $Q(x)$ that cannot be factored into linear factors with real coefficients.\r\n\t\\item Set the original fraction $P(x) / Q(x)$ equal to the sum of all these partial fractions. Clear the resulting equation of fractions and arrange the terms in decreasing powers of $x$.\r\n\t\\item Equate the coefficients of corresponding powers of $x$ and solve the resulting equations for the undetermined coefficients.\r\n\\end{enumerate}\r\n\\begin{exercise}\r\n\tIntegrate $\r\n\t\\int \\frac{6 x+7}{(x+2)^{2}} d x\r\n\t$\r\n\\end{exercise}\r\n\\begin{answer}\r\n\tExpress the integrand as a sum of partial fractions with undetermined coefficients.\r\n\t\\begin{align*}\r\n\t\\frac{6 x+7}{(x+2)^{2}}&=\\frac{A}{x+2}+\\frac{B}{(x+2)^{2}}\\qquad(\\rightarrow\\text{Multiply both sides by} (x+2)^{2})\\\\\r\n\t6 x+7 &=A(x+2)+B \\\\\r\n\t&=A x+(2 A+B)\r\n\t\\end{align*}\r\n\t{Equating coefficients of corresponding powers of $x$ gives}\r\n\t\\begin{align*}\r\n\tA=6 \\quad \\text{and} \\quad 2 A+B=12+B=7, &\\quad \\text{or} \\quad A=6 \\quad \\text{and} \\quad B=-5.\\\\\r\n\t\\therefore \\int \\frac{6 x+7}{(x+2)^{2}} d x &=\\int\\left(\\frac{6}{x+2}-\\frac{5}{(x+2)^{2}}\\right) d x \\\\\r\n\t&=6 \\int \\frac{d x}{x+2}-5 \\int(x+2)^{-2} d x \\\\\r\n\t&=6 \\ln |x+2|+5(x+2)^{-1}+C\r\n\t\\end{align*}\r\n\\end{answer}\r\n\\begin{exercise}\r\n\tIntegrate $\\int \\frac{2 x^{3}-4 x^{2}-x-3}{x^{2}-2 x-3} d x$\r\n\\end{exercise}\r\n\\newcommand{\\longdiv}{\\smash{\\mkern-0.43mu\\vstretch{1.31}{\\hstretch{.7}{)}}\\mkern-5.2mu\\vstretch{1.31}{\\hstretch{.7}{)}}}}\r\n\\begin{answer}The given function is an improper fraction.First we need to divide the denominator into the numerator to get a polynomial plus a proper fraction.\r\n\t\r\n\t\\[\r\n\t\\arraycolsep=0.5pt\r\n\t\\renewcommand\\arraystretch{0.6}\r\n\t\\begin{array}{*1r @{\\hskip\\arraycolsep}c@{\\hskip\\arraycolsep} *{11}r}\r\n\t&          & 2x &  &  & &  &  &  &  &  &  &   \\\\\r\n\t\\cline{2-13}\r\n\tx ^ { 2 } - 2 x - 3  &\\longdiv &  2 x ^ { 3 } & -  & 4 x ^ { 2 }   & -  &  x     & -  & 3     &   &      &   &        \\\\\r\n\t&          & 2 x ^ { 3 } & - & 4 x ^ { 2 } & - &  6x &   &      &   &      &   &        \\\\\r\n\t\\cline{3-7}\r\n\t&          &   &   &  &  &   & 5x  & -     & 3  &      &   &        \r\n\t\\end{array}\r\n\t\\]\r\n\tThen we write the improper fraction as a polynomial plus a proper fraction.\r\n\t\\begin{align*}\r\n\t\\frac{2 x^{3}-4 x^{2}-x-3}{x^{2}-2 x-3}&=2 x+\\frac{5 x-3}{x^{2}-2 x-3}\\\\\r\n\t\\text{and then,}\\\\\r\n\t\\int \\frac{2 x^{3}-4 x^{2}-x-3}{x^{2}-2 x-3} d x &=\\int 2 x d x+\\int \\frac{5 x-3}{x^{2}-2 x-3} d x \\\\\r\n\t&=\\int 2 x d x+\\int \\frac{2}{x+1} d x+\\int \\frac{3}{x-3} d x \\\\\r\n\t&=x^{2}+2 \\ln |x+1|+3 \\ln |x-3|+C\r\n\t\\end{align*}\r\n\t\r\n\t\r\n\\end{answer}\r\n\\subsection{Trigonometrtic Integrals}\r\nTrigonometric integrals involve algebraic combinations of the six basic trigonometric\r\nfunctions.\r\n\\subsubsection{Trigonmetric Substitution}\r\nTrigonometric substitution is used to simplify certain integrals containing radical expressions. Depending on the function we need to integrate, we substitute one of the following expressions:\r\n\\begin{itemize}\r\n\t\\item For $\\sqrt{a^{2}-x^{2}}$, use $x=a \\sin \\theta$.\r\n\t\\item For $\\sqrt{a^{2}+x^{2}}$, use $x=a \\tan \\theta$.\r\n\t\\item For $\\sqrt{x^{2}-a^{2}}$, use $x=a \\sec \\theta$.\r\n\\end{itemize}\r\n\\subsubsection{Powers of sines and cosines}\r\nFor the integrals of the form $$\\int \\sin ^{m} x \\cos ^{n} x d x$$\r\n\\begin{itemize}\r\n\t\\item If , \\textbf{m=n=odd}\\\\\r\n\tWrite $m$ as $2 k+1$ and use the identity $\\sin ^{2} x=1-\\cos ^{2} x$ to obtain\r\n\t$$\r\n\t\\sin ^{m} x=\\sin ^{2 k+1} x=\\left(\\sin ^{2} x\\right)^{k} \\sin x=\\left(1-\\cos ^{2} x\\right)^{k} \\sin x\r\n\t$$\r\n\tThen combine the single $\\sin x$ with $d x$ in the integral and set $\\sin x d x$ equal to $-d(\\cos x)$.\r\n\t\\item If , \\textbf{m=even and n=odd}\\\\\r\n\t Write $n$ as $2 k+1$ and use the identity $\\cos ^{2} x=1-\\sin ^{2} x$ to obtain\r\n\t$$\r\n\t\\cos ^{n} x=\\cos ^{2 k+1} x=\\left(\\cos ^{2} x\\right)^{k} \\cos x=\\left(1-\\sin ^{2} x\\right)^{k} \\cos x .\r\n\t$$\r\n\tThen combine the single $\\cos x$ with $d x$ and set $\\cos x d x$ equal to $d(\\sin x)$.\r\n\t\\item If , \\textbf{m=n=even}\\\\\r\n\tSubstitute\r\n\t$$\r\n\t\\sin ^{2} x=\\frac{1-\\cos 2 x}{2}, \\quad \\cos ^{2} x=\\frac{1+\\cos 2 x}{2}\r\n\t$$\r\n\tTo reduce the integrand to one in lower powers of $\\cos 2 x$.\r\n\\end{itemize}\r\n\r\n\\begin{note}\\newline\r\n\t$\\begin{array}{l}\r\n\t\t\\sin m x \\sin n x=\\frac{1}{2}[\\cos (m-n) x-\\cos (m+n) x] \\\\\\\\\r\n\t\t\\sin m x \\cos n x=\\frac{1}{2}[\\sin (m-n) x+\\sin (m+n) x] \\\\\\\\\r\n\t\t\\cos m x \\cos n x=\\frac{1}{2}[\\cos (m-n) x+\\cos (m+n) x]\r\n\t\\end{array}$\r\n\\end{note}\r\n\\begin{exercise}\r\n\tEvaluate $\\int \\cos ^{5} x d x$\r\n\\end{exercise}\r\n\\begin{answer}\r\n\t\\begin{align*} \r\n\t\\int \\cos ^{5} x d x &=\\int \\cos ^{4} x \\cos x d x=\\int\\left(1-\\sin ^{2} x\\right)^{2} d(\\sin x) \\\\ &=\\int\\left(1-u^{2}\\right)^{2} d u \\\\ &=\\int\\left(1-2 u^{2}+u^{4}\\right) d u \\\\ &=u-\\frac{2}{3} u^{3}+\\frac{1}{5} u^{5}+C=\\sin x-\\frac{2}{3} \\sin ^{3} x+\\frac{1}{5} \\sin ^{5} x+C \r\n\t\\end{align*}\r\n\\end{answer}\r\n\\begin{exercise}\r\n\tEvaluate $\\int_{0}^{\\pi / 4} \\sqrt{1+\\cos 4 x} d x$\r\n\\end{exercise}\r\n\\begin{answer}\r\n $\\quad$ To eliminate the square root we use the identity\r\n\t$$\r\n\t\\cos ^{2} \\theta=\\frac{1+\\cos 2 \\theta}{2}, \\quad \\text { or } \\quad 1+\\cos 2 \\theta=2 \\cos ^{2} \\theta\r\n\t$$\r\n\\begin{align*}\r\n\t\t\\intertext{With $\\theta=2 x$, this becomes}\r\n\t1+\\cos 4 x&=2 \\cos ^{2} 2 x\\\\\r\n\t\\int_{0}^{\\pi / 4} \\sqrt{1+\\cos 4 x} d x &=\\int_{0}^{\\pi / 4} \\sqrt{2 \\cos ^{2} 2 x} d x=\\int_{0}^{\\pi / 4} \\sqrt{2} \\sqrt{\\cos ^{2} 2 x} d x \\\\\r\n\t\t&=\\sqrt{2} \\int_{0}^{\\pi / 4}|\\cos 2 x| d x=\\sqrt{2} \\int_{0}^{\\pi / 4} \\cos 2 x d x \\quad \\begin{array}{l}\r\n\t\t\t\\cos 2 x \\geq 0 \\\\\r\n\t\t\t\\text { on }[0, \\pi / 4]\r\n\t\t\\end{array} \\\\\r\n\t\t&=\\sqrt{2}\\left[\\frac{\\sin 2 x}{2}\\right]_{0}^{\\pi / 4}=\\frac{\\sqrt{2}}{2}[1-0]=\\frac{\\sqrt{2}}{2}\r\n\t\\end{align*}\r\n\\end{answer}\r\n\\begin{exercise}\r\n Evaluate,\t$\\int \\frac{x^{2} d x}{\\sqrt{9-x^{2}}}$\r\n\\end{exercise}\r\n\\begin{answer}\r\n\t\t\\begin{alignat*}{2}\r\n\t\t\\text{Let, }&x=3 \\sin \\theta, \\quad d x=3 \\cos \\theta d \\theta, &&\\quad-\\frac{\\pi}{2}<\\theta<\\frac{\\pi}{2} \\\\\r\n\t\t&9-x^{2}=9-9 \\sin ^{2} \\theta=9\\left(1-\\sin ^{2} \\theta\\right)&&=9 \\cos ^{2} \\theta\\\\\r\n\t\\end{alignat*}\r\n\tThen\r\n\t\\begin{align*}\r\n\t\\int \\frac{x^{2} d x}{\\sqrt{9-x^{2}}} &=\\int \\frac{9 \\sin ^{2} \\theta \\cdot 3 \\cos \\theta d \\theta}{|3 \\cos \\theta|} \\\\\r\n\t&=9 \\int \\sin ^{2} \\theta d \\theta \\quad \\cos \\theta>0 \\text { for }-\\frac{\\pi}{2}<\\theta<\\frac{\\pi}{2} \\\\\r\n\t&=9 \\int \\frac{1-\\cos 2 \\theta}{2} d \\theta \\\\\r\n\t&=\\frac{9}{2}\\left(\\theta-\\frac{\\sin 2 \\theta}{2}\\right)+C \\qquad |\\sin 2 \\theta=2 \\sin \\theta \\cos \\theta \\\\\r\n\t&=\\frac{9}{2}(\\theta-\\sin \\theta \\cos \\theta)+C \\quad \\\\\r\n\t&=\\frac{9}{2}\\left(\\sin ^{-1} \\frac{x}{3}-\\frac{x}{3} \\cdot \\frac{\\sqrt{9-x^{2}}}{3}\\right)+C  \\\\\r\n\t&=\\frac{9}{2} \\sin ^{-1} \\frac{x}{3}-\\frac{x}{2} \\sqrt{9-x^{2}}+C\r\n\t\\end{align*}\r\n\t\r\n\\end{answer}\r\n\\begin{exercise}\r\n\tEvaluate\r\n\t$\\int \\sin 3 x \\cos 5 x d x$\r\n\\end{exercise}\r\n\\begin{answer}\r\n\tWe know that ,\\quad $\\sin m x \\cos n x=\\frac{1}{2}[\\sin (m-n) x+\\sin (m+n) x]$\\\\\r\n\t\\begin{align*}\r\n\t\\text{m = 3 and n = 5 we get}\\\\\r\n\t\t\\int \\sin 3 x \\cos 5 x d x &=\\frac{1}{2} \\int[\\sin (-2 x)+\\sin 8 x] d x \\\\\r\n\t\t&=\\frac{1}{2} \\int(\\sin 8 x-\\sin 2 x) d x \\\\\r\n\t\t&=-\\frac{\\cos 8 x}{16}+\\frac{\\cos 2 x}{4}+C\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\section{Summation and Serises}\r\n\\begin{minipage}{0.45\\textwidth}\r\n\t\\begin{center}\r\n\t\t\\framebox{\r\n\t\t\t\\parbox[t][5cm]{3cm}{\r\n\t\t\t\t\r\n\t\t\t\t\\addvspace{0.2cm} \\centering \r\n\t\t\t\t\r\n\t\t\t\t\\begin{align*}\r\n\t\t\t&\\text{\\textbf{Sum of Arithmatic series}}\\\\\r\n\t\t\tS&=\\sum_{n=0}^{+N} [a+(n-1)d]\\\\\r\n\t\t\tS_{N}&=\\frac{N}{2}[a+l] \\rightarrow (l= \\text{Last term})\\\\\r\n\t\t\tS_{N}&=\\frac{N}{2}[2a+(n-1)d]\r\n\t\t\t\\end{align*}} }\r\n\t\\end{center}\r\n\\end{minipage}\r\n\\begin{minipage}{0.45\\textwidth}\r\n\t\\begin{center}\r\n\t\t\\framebox{\r\n\t\t\t\\parbox[t][5cm]{3cm}{\r\n\t\t\t\t\r\n\t\t\t\t\\addvspace{0.2cm} \\centering \r\n\t\t\t\t\r\n\t\t\t\t\\begin{align*}\r\n\t\t\t\t&\\text{\\textbf{Sum of Geometric series}}\\\\\r\n\t\t\t\t&S_{n}=\\frac{a(1-r^{n})}{1-r}\\qquad (r<1)\\\\\r\n\t\t\t\t&S_{n}=\\frac{a(r^{n}-1)}{r-1}\\qquad (r>1)\\\\\r\n\t\t\t\t&\\text{\\textbf{\\large Sum of Infinite series}}\\\\\r\n\t\t\t\t&S_{n}=\\frac{a}{r-1}\r\n\t\t\t\t\\end{align*}} }\r\n\t\\end{center}\r\n\\end{minipage}\r\n\\section{Binomial Theorem}\r\n\\begin{theorem}\r\n\tFor any positive integer $ n $, the $ n ^{\\text{th }}$power of the sum of two numbers $ a $ and $ b $ may be expressed as the sum of $ n + 1 $ terms of the form,\r\n\\begin{equation}\r\n\t\t$$(a+b)^{n}= \\sum_{n=o}^{r} {^{n}C_{r} a^{n-r}b^{r}}$$\r\n\\end{equation}\r\n\r\n\\end{theorem}\r\n\\section{Taylor and Maclaurin series}\r\n\\begin{definition}\r\n\tLet $f$ be a function with derivatives of all orders throughout some interval containing $a$ as an interior point. Then the Taylor series generated by $f$ at $x=a$ is\r\n\t$$\r\n\t\\begin{aligned}\r\n\t\\sum_{k=0}^{\\infty} \\frac{f^{(k)}(a)}{k !}(x-a)^{k}=f(a)+f^{\\prime} &(a)(x-a)+\\frac{f^{\\prime \\prime}(a)}{2 !}(x-a)^{2} +\\cdots+\\frac{f^{(n)}(a)}{n !}(x-a)^{n}+\\cdots\r\n\t\\end{aligned}\r\n\t$$\r\n\tThe Maclaurin series generated by $f$ is\r\n\t$$\r\n\t\\sum_{k=0}^{\\infty} \\frac{f^{(k)}(0)}{k !} x^{k}=f(0)+f^{\\prime}(0) x+\\frac{f^{\\prime \\prime}(0)}{2 !} x^{2}+\\cdots+\\frac{f^{(n)}(0)}{n !} x^{n}+\\cdots,\r\n\t$$\r\n\tThe Taylor series generated by $f$ at $x=0$.\r\n\\end{definition}\r\n\\subsubsection{Taylor polynomial}\r\nLet $f$ be a function with derivatives of order $k$ for $k=1,2, \\ldots, N$ in some interval containing $a$ as an interior point. Then for any integer $n$ from 0 through $N$, the Taylor polynomial of order $n$ generated by $f$ at $x=a$ is the polynomial,\r\n$$\r\n\\begin{aligned}\r\nP_{n}(x)=f(a)+f^{\\prime}(a)(x-a) &+\\frac{f^{\\prime \\prime}(a)}{2 !}(x-a)^{2}+\\cdots \\\\\r\n&+\\frac{f^{(k)}(a)}{k !}(x-a)^{k}+\\cdots+\\frac{f^{(n)}(a)}{n !}(x-a)^{n} .\r\n\\end{aligned}\r\n$$\r\n\\begin{exercise}\r\n\tFind the Taylor series and the Taylor polynomials generated by $f(x)=e^{x}$ at $x=0$.\r\n\\end{exercise}\r\n\\begin{answer}\r\n\t$$\r\n\tf(x)=e^{x}, \\quad f^{\\prime}(x)=e^{x}, \\quad \\ldots, \\quad f^{(n)}(x)=e^{x}, \\quad \\ldots\r\n\t$$\r\n\twe have\r\n\t$$\r\n\tf(0)=e^{0}=1, \\quad f^{\\prime}(0)=1, \\quad \\ldots, \\quad f^{(n)}(0)=1, \\quad \\ldots\r\n\t$$\r\n\tThe Taylor series generated by $f$ at $x=0$ is\r\n\t\\begin{align*}\r\n\tf(0)+f^{\\prime}(0) x+\\frac{f^{\\prime \\prime}(0)}{2 !} x^{2}+\\cdots &+\\frac{f^{(n)}(0)}{n !} x^{n}+\\cdots \\\\\r\n\t&=1+x+\\frac{x^{2}}{2}+\\cdots+\\frac{x^{n}}{n !}+\\cdots \\\\\r\n\t&=\\sum_{k=0}^{\\infty} \\frac{x^{k}}{k !}\r\n\t\\end{align*}\r\n\t\r\n\\end{answer}\r\n\\begin{exercise}\r\n\tIn the Taylor's series expansion of $e^{x}$ about $x=2$, the coefficient of $(x-2)^{4}$ is\r\n\\end{exercise}\r\n\\begin{answer}\r\n\t$f(x)$ in the neighborhood of $a$ is given by\r\n\t\\begin{align*}\r\nf(x)=\\sum_{n=0}^{\\infty} b_{n}(x-a)^{n}\\\\\r\n\\text{where} b_{n}&=\\frac{f^{n}(a)}{n !}\\\\\r\nf^{4}(x)&=e^{x} \\cdot f^{4}(2)=e^{2}\\\\\r\n\\text{Therefore, coefficient of}(x-2)^{4}&=b_{4}=\\frac{f^{4}(2)}{4 !}=\\frac{e^{2}}{4 !}\r\n\\end{align*}\r\n\\end{answer}\r\n\\newpage\r\n\\colorlet{ocre1}{ocre!70!}\r\n\\colorlet{ocrel}{ocre!30!}\r\n\\begin{table}[H]\r\n\t\\centering\r\n\t\\arrayrulecolor{ocre}\r\n\t\\renewcommand{\\arraystretch}{1.7}\r\n\t\\begin{tabularx}{0.8\\textwidth} { \r\n\t\t\t| >{\\centering\\arraybackslash}X \r\n\t\t\t| >{\\centering\\arraybackslash}X |  }\r\n\t\t\\hline\r\n\t\t\\rowcolor{ocrel}\\large \\textbf{Derivatives} & \\large \\textbf{Integrals} \\\\\r\n\t\t\\hline\r\n\t\t$\\frac{d}{d x}\\left(\\frac{x^{n +1}}{n+1}\\right)=x^{n} $ & $\\int x^{n} d x=\\frac{x^{n+1}}{n+1}+C$   \\\\\r\n\t\t\\hline\r\n\t\t$ \\frac{d}{d x}(x)=1 $& $ \\int d x=x+C $\\\\ \\hline\r\n\t\t$ \\frac{d}{d x}(\\sin x)=\\cos x$& $\\int \\cos x d x=\\sin x+C $\\\\ \\hline\r\n\t\t$\\frac{d}{d x}(-\\cos x)=\\sin x $& $ \\int \\sin x d x=-\\cos x+C$\\\\ \\hline\r\n\t\t$\\frac{d}{d x}(\\tan x)=\\sec ^{2} x  $& $ \\int \\sec ^{2} x d x=\\tan x+C $\\\\ \\hline\r\n\t\t$ \\frac{d}{d x}(-\\cot x)=\\operatorname{cosec}^{2} x$& $ \\int \\operatorname{cosec}^{2} x d x=-\\cot x+C $\\\\ \\hline\r\n\t\t$ \\frac{d}{d x}(\\sec x)=\\sec x \\tan x $& $ \\int \\sec x \\tan x d x=\\sec x+C $\\\\ \\hline\r\n\t\t$\\frac{d}{d x}(-\\operatorname{cosec} x)=\\operatorname{cosec} x \\cot x $& $\\int \\operatorname{cosec} x \\cot x d x=-\\operatorname{cosec} x+C $\\\\ \\hline\r\n\t\t$ \\frac{d}{d x}\\left(\\sin ^{-1} x\\right)=\\frac{1}{\\sqrt{1-x^{2}}} $& $\\int \\frac{\\mathrm{d} x}{\\sqrt{1-x^{2}}}=\\sin ^{-1} x+C $\\\\ \\hline\r\n\t\t$\\frac{d}{d x}\\left(\\cos ^{-1} x\\right)=-\\frac{1}{\\sqrt{1-x^{2}}}  $& $\\int-\\frac{d x}{\\sqrt{1-x^{2}}}=\\cos ^{-1} x+C  $\\\\ \\hline\r\n\t\t$ \\frac{d}{d x}\\left(\\tan ^{-1} x\\right)=\\frac{1}{1+x^{2}} $& $\\int \\frac{d x}{1+x^{2}}=\\tan ^{-1} x+C $\\\\ \\hline\r\n\t\t$ \\frac{d}{d x}\\left(\\cot ^{-1} x\\right)=-\\frac{1}{1+x^{2}} $& $\\int-\\frac{d x}{1+x^{2}}=\\cot ^{-1} x+C $\\\\ \\hline\r\n\t\t$\\frac{d}{d x}\\left(\\sec ^{-1} x\\right)=\\frac{1}{|x| \\sqrt{x^{2}-1}}  $& $\\int \\frac{d x}{|x| \\sqrt{x^{2}-1}}=\\sec ^{-1} x+C $\\\\ \\hline\r\n\t\t$ \\frac{d}{d x}\\left(\\operatorname{cosec}^{-1} x\\right)=-\\frac{1}{|x| \\sqrt{x^{2}-1}}$& $\\int \\frac{d x}{-|x| \\sqrt{x^{2}-1}}=\\operatorname{cosec}^{-1} x+C  $\\\\ \\hline\r\n\t\t$ \\frac{d}{d x}\\left(e^{x}\\right)=e^{x} $& $ \\int e^{x} d x=e^{x}+C $\\\\ \\hline\r\n\t\t$\\frac{d}{d x}(\\log |x|)=\\frac{1}{x} $& $\\int \\frac{d x}{x}=\\log |x|+C $\\\\ \\hline\r\n\t\t$ \\frac{d}{d x}\\left(\\frac{a^{x}}{\\log a}\\right)=a^{x}$& $ \\int a^{x} d x=\\frac{a^{x}}{\\log a}+C$\\\\ \\hline\r\n\t\t$ $& $\\int_{-\\infty}^{\\infty} x^{2 n} e^{-\\alpha x^{2}} d x=\\sqrt{\\frac{\\pi}{\\alpha}} \\frac{(2 n-1) ! }{(2 \\alpha)^{n}} $\\\\ \\hline\r\n\t\t$ $& $ \\int_{-\\infty}^{\\infty}  e^{-\\alpha x^{2}} d x=\\sqrt{\\frac{\\pi}{\\alpha}}  $\\\\ \\hline\r\n\t\t$  $& $\\int \\frac{d x}{x^{2}-a^{2}}=\\frac{1}{2 a} \\ln \\left|\\frac{x-a}{x+a}\\right|+C $\\\\ \\hline\r\n\t\t$ $& $\\int \\frac{d x}{\\sqrt{x^{2} \\pm a^{2}}} = \\ln \\left|x+\\sqrt{x^{2} \\pm a^{2}}\\right|+C  $\\\\ \\hline\r\n\t\t$ $& $\\int x \\sin n x d x =\\frac{1}{n^{2}}(\\sin n x-n x \\cos n x)+C  $\\\\ \\hline\r\n\t\t$ $& $ \\int e^{a x} \\sin b x d x = \\frac{e^{a x}(a \\sin b x-b \\cos b x)}{a^{2}+b^{2}}+C$\\\\ \\hline\r\n\t\t$ $& $ \\int e^{a x} \\cos b x d x = \\frac{e^{a x}(a \\cos b x+b \\sin b x)}{a^{2}+b^{2}}+C $\\\\ \\hline\r\n\t\t\r\n\t\\end{tabularx}\r\n\\caption{List of important Derivatives and Integrals}\r\n\\end{table}\r\n\\newpage\r\n\\begin{center}\r\n\t\\textbf{\\large Basic Trigonometric identities}\r\n\\end{center}\r\n\\begin{minipage}{0.45\\textwidth}\r\n\t\\colorlet{ocre1}{ocre!70!}\r\n\t\\colorlet{ocrel}{ocre!30!}\r\n\t\\begin{table}[H]\r\n\t\t\\centering\r\n\t\t\\arrayrulecolor{ocre}\r\n\t\t\\renewcommand{\\arraystretch}{2.5}\r\n\t\t\\begin{tabularx}{0.9\\textwidth} { \r\n\t\t\t\t| >{\\centering\\arraybackslash}X \r\n\t\t\t\t|   }\r\n\t\t\t\\hline\r\n\t\t\t\\rowcolor{ocrel} \\large \\textbf{Pythogorean identity} \\\\\r\n\t\t\t\\hline\r\n\t\t\t\\hline\r\n\t\t\t$\\begin{array}{l}\r\n\t\t\t\\sin ^{2} \\theta+\\cos ^{2} \\theta=1 \\\\\r\n\t\t\t1+\\tan ^{2} \\theta=\\sec ^{2} \\theta \\\\\r\n\t\t\t1+\\cot ^{2} \\theta=\\csc ^{2}\\theta\r\n\t\t\t\\end{array} $\\\\ \\hline\r\n\t\t\t\r\n\t\t\t\r\n\t\t\\end{tabularx}\r\n\t\t\r\n\t\\end{table}\r\n\\end{minipage}\r\n\\begin{minipage}{0.45\\textwidth}\r\n\t\\colorlet{ocre1}{ocre!70!}\r\n\t\\colorlet{ocrel}{ocre!30!}\r\n\t\\begin{table}[H]\r\n\t\t\\centering\r\n\t\t\\arrayrulecolor{ocre}\r\n\t\t\\renewcommand{\\arraystretch}{2.5}\r\n\t\t\\begin{tabularx}{0.9\\textwidth} { \r\n\t\t\t\t| >{\\centering\\arraybackslash}X \r\n\t\t\t\t|   }\r\n\t\t\t\\hline\r\n\t\t\t\\rowcolor{ocrel} \\large \\textbf{Angle Sum and Differences} \\\\\r\n\t\t\t\\hline\r\n\t\t\t\\hline\r\n\t\t\t$\\begin{array}{l}\r\n\t\t\t\\sin (\\alpha \\pm \\beta)=\\sin \\alpha \\cos \\beta \\pm \\cos \\alpha \\sin \\beta \\\\\r\n\t\t\t\\cos (\\alpha \\pm \\beta)=\\cos \\alpha \\cos \\beta \\mp \\sin \\alpha \\sin \\beta \\\\\r\n\t\t\t\\tan (\\alpha \\pm \\beta)=\\frac{\\tan \\alpha \\pm \\tan \\beta}{1 \\mp \\tan \\alpha \\tan \\beta}\r\n\t\t\t\\end{array}$\\\\ \\hline\r\n\t\t\t\r\n\t\t\t\r\n\t\t\\end{tabularx}\r\n\t\t\r\n\t\\end{table}\r\n\t\r\n\\end{minipage}\\\\\r\n\\begin{minipage}{0.45\\textwidth}\r\n\t\\colorlet{ocre1}{ocre!70!}\r\n\t\\colorlet{ocrel}{ocre!30!}\r\n\t\\begin{table}[H]\r\n\t\t\\centering\r\n\t\t\\arrayrulecolor{ocre}\r\n\t\t\\renewcommand{\\arraystretch}{2.5}\r\n\t\t\\begin{tabularx}{0.9\\textwidth} { \r\n\t\t\t\t| >{\\centering\\arraybackslash}X \r\n\t\t\t\t|   }\r\n\t\t\t\\hline\r\n\t\t\t\\rowcolor{ocrel} \\large \\textbf{Double Angle} \\\\\r\n\t\t\t\\hline\r\n\t\t\t\\hline\r\n\t\t\t$\\begin{aligned} \\sin 2 \\theta &=2 \\sin \\theta \\cos \\theta \\\\ &=\\frac{2 \\tan \\theta}{1+\\tan ^{2} \\theta} \\\\\\\\ \\cos 2 \\theta &=\\cos ^{2} \\theta-\\sin ^{2} \\theta \\\\ &=2 \\cos ^{2} \\theta-1 \\\\ &=1-2 \\sin ^{2} \\theta \\\\ &=\\frac{1-\\tan ^{2} \\theta}{1+\\tan ^{2} \\theta} \\\\\\\\ \\tan 2 \\theta &=\\frac{2 \\tan \\theta}{1-\\tan ^{2} \\theta} \\end{aligned}$\\\\\\\\ \\hline\r\n\t\t\t\r\n\t\t\t\r\n\t\t\\end{tabularx}\r\n\t\t\r\n\t\\end{table}\r\n\t\r\n\\end{minipage}\r\n\\begin{minipage}{0.45\\textwidth}\r\n\t\\colorlet{ocre1}{ocre!70!}\r\n\t\\colorlet{ocrel}{ocre!30!}\r\n\t\\begin{table}[H]\r\n\t\t\\centering\r\n\t\t\\arrayrulecolor{ocre}\r\n\t\t\\renewcommand{\\arraystretch}{2.5}\r\n\t\t\\begin{tabularx}{0.9\\textwidth} { \r\n\t\t\t\t| >{\\centering\\arraybackslash}X \r\n\t\t\t\t|   }\r\n\t\t\t\\hline\r\n\t\t\t\\rowcolor{ocrel} \\large \\textbf{Half Angle} \\\\\r\n\t\t\t\\hline\r\n\t\t\t\\hline\r\n\t\t\t$\\begin{array}{l}\r\n\t\t\t\\sin \\frac{\\theta}{2}=\\pm \\sqrt{\\frac{1-\\cos \\theta}{2}} \\\\\r\n\t\t\t\\cos \\frac{\\theta}{2}=\\pm \\sqrt{\\frac{1+\\cos \\theta}{2}}\r\n\t\t\t\\end{array} $\\\\\\\\ \r\n\t\t\t$\\begin{aligned} \\tan \\frac{\\theta}{2} &=\\csc \\theta-\\cot \\theta \\\\ &=\\pm \\sqrt{\\frac{1-\\cos \\theta}{1+\\cos \\theta}} \\\\ &=\\frac{\\sin \\theta}{1+\\cos \\theta} \\\\ &=\\frac{1-\\cos \\theta}{\\sin \\theta} \\end{aligned}$\\\\ \\hline\r\n\t\t\t\r\n\t\t\t\r\n\t\t\\end{tabularx}\r\n\t\t\r\n\t\\end{table}\r\n\t\r\n\\end{minipage}\\\\\r\n\\begin{minipage}{0.45\\textwidth}\r\n\t\\colorlet{ocre1}{ocre!70!}\r\n\t\\colorlet{ocrel}{ocre!30!}\r\n\t\\begin{table}[H]\r\n\t\t\\centering\r\n\t\t\\arrayrulecolor{ocre}\r\n\t\t\\renewcommand{\\arraystretch}{2.5}\r\n\t\t\\begin{tabularx}{0.9\\textwidth} { \r\n\t\t\t\t| >{\\centering\\arraybackslash}X \r\n\t\t\t\t|   }\r\n\t\t\t\\hline\r\n\t\t\t\\rowcolor{ocrel} \\large \\textbf{Product to Sum} \\\\\r\n\t\t\t\\hline\r\n\t\t\t\\hline\r\n\t\t\t$\\begin{array}{l}\r\n\t\t\t\\sin \\theta \\sin \\varphi=\\frac{\\cos (\\theta-\\varphi)-\\cos (\\theta+\\varphi)}{2} \\\\\r\n\t\t\t\\sin \\theta \\cos \\varphi=\\frac{\\sin (\\theta+\\varphi)+\\sin (\\theta-\\varphi)}{2} \\\\\r\n\t\t\t\\cos \\theta \\sin \\varphi=\\frac{\\sin (\\theta+\\varphi)-\\sin (\\theta-\\varphi)}{2} \\\\\r\n\t\t\t\\cos \\theta \\cos \\varphi=\\frac{\\cos (\\theta-\\varphi)+\\cos (\\theta+\\varphi)}{2}\r\n\t\t\t\\end{array}$\\\\ \\hline\r\n\t\t\t\r\n\t\t\t\r\n\t\t\\end{tabularx}\r\n\t\t\r\n\t\\end{table}\r\n\t\r\n\\end{minipage}\r\n\\begin{minipage}{0.45\\textwidth}\r\n\t\\colorlet{ocre1}{ocre!70!}\r\n\t\\colorlet{ocrel}{ocre!30!}\r\n\t\\begin{table}[H]\r\n\t\t\\centering\r\n\t\t\\arrayrulecolor{ocre}\r\n\t\t\\renewcommand{\\arraystretch}{2.5}\r\n\t\t\\begin{tabularx}{1\\textwidth} { \r\n\t\t\t\t| >{\\centering\\arraybackslash}X \r\n\t\t\t\t|   }\r\n\t\t\t\\hline\r\n\t\t\t\\rowcolor{ocrel} \\large \\textbf{Sum to Product} \\\\\r\n\t\t\t\\hline\r\n\t\t\t\\hline\r\n\t\t\t$\\begin{array}{l}\r\n\t\t\t\\sin \\theta \\pm \\sin \\varphi=2 \\sin \\left(\\frac{\\theta \\pm \\varphi}{2}\\right) \\cos \\left(\\frac{\\theta \\mp \\varphi}{2}\\right) \\\\\r\n\t\t\t\\cos \\theta+\\cos \\varphi=2 \\cos \\left(\\frac{\\theta+\\varphi}{2}\\right) \\cos \\left(\\frac{\\theta-\\varphi}{2}\\right) \\\\\r\n\t\t\t\\cos \\theta-\\cos \\varphi=-2 \\sin \\left(\\frac{\\theta+\\varphi}{2}\\right) \\sin \\left(\\frac{\\theta-\\varphi}{2}\\right)\r\n\t\t\t\\end{array}$\\\\ \\hline\r\n\t\t\t\r\n\t\t\t\r\n\t\t\\end{tabularx}\r\n\t\t\r\n\t\\end{table}\r\n\t\r\n\\end{minipage}\r\n\r\n\r\n\\newpage\r\n\\begin{abox}\r\n\tPractise Set-1\r\n\\end{abox}\r\n\\begin{enumerate}\r\n\t\\item Given that $f(1)=1, f^{\\prime}(1)=1$, and $f^{\\prime \\prime}(1)=1$, the value of $f(1 / 2)$ is $\\ldots \\ldots \\ldots \\ldots \\ldots$ (NAT){\\exyear{IIT JAM 2013}}\r\n\t\r\n\t\\item  The tangent line to the curve $x^{2}+x y+5=0$ at (1,1) is represented by \r\n\t{\\exyear{IIT JAM 2016}}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{a.}] $y=3 x-2$\r\n\t\t\\task[\\textbf{b.}]$y=-3 x+4$\r\n\t\t\\task[\\textbf{c.}] $x=3 y-2$\r\n\t\t\\task[\\textbf{d.}] $x=-3 y+4$\r\n\t\\end{tasks}\r\n\t\r\n\t\\item The coefficient of $x^{3}$ in the Taylor expansion of $\\sin (\\sin x)$ around $x=0$ is\r\n\t((NAT)Specify your answer upto two digits after the decimal point){\\exyear{IIT JAM 2018}}\r\n\t\\item The function $f(x)=\\frac{8 x}{x^{2}+9}$ is continuous everywhere except at\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{a.}]  $x=0$ \r\n\t\t\\task[\\textbf{b.}] $x=\\pm 9$\r\n\t\t\\task[\\textbf{c.}] $x=\\pm 9 i$\r\n\t\t\\task[\\textbf{d.}] $x=\\pm 3 i$ \r\n\t\\end{tasks}\r\n\t\\item Which one of the following functions has a discontinuity in the second derivative at $x=0$,where $x$ is a real variable?{\\exyear{IIT JAM 2020}}\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{a.}] $f(x)=|x|^{3}$  \r\n\t\t\\task[\\textbf{b.}] $f(x)=x|x|$\r\n\t\t\\task[\\textbf{c.}] $f(x)=\\cos (|x|)$\r\n\t\t\\task[\\textbf{d.}] $f(x)=|x|^{2}$\r\n\t\\end{tasks}\r\n\\end{enumerate}\r\n\\newpage\r\n\\begin{abox}\r\n\tPractise Set-2\r\n\\end{abox}\r\n\\begin{enumerate}\r\n\t\\item For what value of $\\lambda$ is the function $f(x)$ continuous at $x=3 ?$\r\n\t$\r\n\tf(x)=\\left\\{\\begin{aligned}\r\n\t\\frac{x^{2}-9}{x-3}, & x \\neq 3 \\\\\r\n\t\\lambda, & x=3\r\n\t\\end{aligned}\\right.\r\n\t$\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{a.}]$\\lambda=6$  \r\n\t\t\\task[\\textbf{b.}]$\\lambda=3$  \r\n\t\t\\task[\\textbf{c.}]$\\lambda=2$   \r\n\t\t\\task[\\textbf{d.}]$\\lambda=9$   \r\n\t\\end{tasks}\r\n\t\\item $f(x)=(1+3 x)^{1 / 3}$ when $\\neq 0 f(0)=e^{3}$ is continuous for $x=0$\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{a.}]0  \r\n\t\t\\task[\\textbf{b.}]1\r\n\t\t\\task[\\textbf{c.}]$e^{3}$ \r\n\t\t\\task[\\textbf{d.}]$e^{-3}$\r\n\t\\end{tasks}\r\n\t\\item Let $f(x)=(x-2)^{17}(x+5)^{24}$. Then\r\n\t\\begin{tasks}(1)\r\n\t\t\\task[\\textbf{a.}] $f$ does not have a critical point at 2  \r\n\t\t\\task[\\textbf{b.}]$f$ has a minimum at 2\r\n\t\t\\task[\\textbf{c.}] $f$ has a maximum at 2\r\n\t\t\\task[\\textbf{d.}] $f$ has neither a minimum nor a maximum at 2\r\n\t\\end{tasks}\r\n\t\\item Find the intervals in which the function $f(x)=$ $x^{4}-\\frac{x^{3}}{3}$ is decreasing.\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{a.}]$\\left(-\\infty, \\frac{1}{4}\\right)$.  \r\n\t\t\\task[\\textbf{b.}]$\\left(+\\infty, \\frac{1}{4}\\right)$. \r\n\t\t\\task[\\textbf{c.}]$\\left(-\\frac{1}{4}, +\\frac{1}{4}\\right)$.  \r\n\t\t\\task[\\textbf{d.}]$\\left(-\\infty, \\frac{1}{2}\\right)$.   \r\n\t\\end{tasks}\r\n\t\\item Find the intervals in which the function $f(x)=2 x^{3}+9 x^{2}+12 x+24$ is increasing.\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{a.}] $(-\\infty,-2) \\cup(-1, \\infty)$ \r\n\t\t\\task[\\textbf{b.}]$(-2,-1)$\r\n\t\t\\task[\\textbf{c.}]$(-\\infty,-1) \\cup(2, \\infty)$ \r\n\t\t\\task[\\textbf{d.}]$(-1, \\infty)$ \r\n\t\\end{tasks}\r\n\t\\item In the Taylor series expansion of $e^{x}$ about $x=2$ the coefficient of $(x-2)^{4}$\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{a.}]$\\frac{1}{4!}$  \r\n\t\t\\task[\\textbf{b.}]$\\frac{2^{4}}{4!}$\r\n\t\t\\task[\\textbf{c.}]$\\frac{e^{2}}{4!}$ \r\n\t\t\\task[\\textbf{d.}]$\\frac{e^{4}}{4!}$\r\n\t\\end{tasks}\r\n\t\\item For the function $e^{-x}$, the linear approximation around $x=2$ is\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{a.}] $(3-x) e^{-2}$ \r\n\t\t\\task[\\textbf{b.}]$1-x$\r\n\t\t\\task[\\textbf{c.}] $[3+2 \\sqrt{2}-(1+\\sqrt{2}) x] e^{-2}$ \r\n\t\t\\task[\\textbf{d.}] $e^{-2}$ \r\n\t\\end{tasks}\r\n\t\\item What is the value of $\\lim _{x \\rightarrow 0} \\frac{e^{x}-\\left(1+x+\\frac{x^{2}}{2}\\right)}{x^{3}} ?$\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{a.}] 0 \r\n\t\t\\task[\\textbf{b.}]$1 / 6$\r\n\t\t\\task[\\textbf{c.}] $1 / 3$\r\n\t\t\\task[\\textbf{d.}]1 \r\n\t\\end{tasks}\r\n\t\\item The infinite series $1+x+\\frac{x^{2}}{2 !}+\\frac{x^{3}}{3 !}+\\frac{x^{4}}{4 !}+\\cdots$\r\n\tcorresponds to\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{a.}]$\\sec x$  \r\n\t\t\\task[\\textbf{b.}]$e^{x}$\r\n\t\t\\task[\\textbf{c.}]$\\cos x$ \r\n\t\t\\task[\\textbf{d.}]$1+\\sin ^{2} x$ \r\n\t\\end{tasks}\r\n\t\\item  The volume of solid of revolution when rotated about $x$ -axis is given as\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{a.}]$\\int_{a}^{b} \\pi y^{2} d y$\r\n\t\t\\task[\\textbf{b.}]$\\int_{a}^{b} \\pi x^{2} d x$\r\n\t\t\\task[\\textbf{c.}]$\\int_{a}^{b} \\pi y^{2} d x$\r\n\t\t\\task[\\textbf{d.}]$\\int_{a}^{b} \\pi x^{2} d y$\r\n\t\\end{tasks}\r\n\t\r\n\t\\item The expansion of $\\mathrm{e}^{\\sin (x)}$ is? \r\n\t\\begin{tasks}(1)\r\n\t\t\\task[\\textbf{a.}]$1+x+x^{2} / 2+x^{4} / 8+\\ldots$ \r\n\t\t\\task[\\textbf{b.}]$1+x-x^{2} / 2+x^{4} / 8+\\ldots .$\r\n\t\t\\task[\\textbf{c.}]$1+x+x^{2} / 2-x^{4} / 8+\\ldots$\r\n\t\t\\task[\\textbf{d.}]$1+x+x^{3} / 6-x^{5} / 10+\\ldots$\r\n\t\\end{tasks}\r\n\t\\item The necessary condition for the maclaurin expansion to be true for function $\\mathrm{f}(\\mathrm{x})$ is\r\n\t\\begin{tasks}(1)\r\n\t\t\\task[\\textbf{a.}]$\\mathrm{f}(\\mathrm{x})$ should be continuous.\r\n\t\t\\task[\\textbf{b.}]$\\mathrm{f}(\\mathrm{x})$ should be differentiable.\r\n\t\t\\task[\\textbf{c.}]$\\mathrm{f}(\\mathrm{x})$ should exists at every point.\r\n\t\t\\task[\\textbf{d.}]$\\mathrm{f}(\\mathrm{x})$ should be continuous and differentiable.\r\n\t\\end{tasks}\r\n\t\r\n\t\r\n\t\r\n\t\\item  Let $F(x)=\\int_{0}^{x}\\left(t^{2}-3 t+2\\right) d t$, then $F$ has\r\n\t\\begin{tasks}(1)\r\n\t\t\\task[\\textbf{a.}] A local maximum at $x=1$ and a local minimum at $x=2$ \r\n\t\t\\task[\\textbf{b.}]A local minimum at $x=1$ and a local maximum at $x=2$\r\n\t\t\\task[\\textbf{c.}] Local maxima at $x=1$ and $x=2$\r\n\t\t\\task[\\textbf{d.}] Local minima at $x=1$ and $x=2$\r\n\t\\end{tasks}\r\n\t\\item Find the Taylor series generated by $f(x)=1 / x$ at $a=2$.\r\n\t\\begin{tasks}(1)\r\n\t\t\\task[\\textbf{a.}]$\\frac{1}{2}+\\frac{(x-2)}{2^{2}}+\\frac{(x-2)^{2}}{2^{3}}+\\cdots+(-1)^{n+1} \\frac{(x-2)^{n}}{2^{n+1}}+\\cdots$  \r\n\t\t\\task[\\textbf{b.}]$\\frac{1}{2}-\\frac{(x-2)}{2^{2}}+\\frac{(x-2)^{2}}{2^{3}}-\\cdots+(-1)^{n} \\frac{(x-2)^{n}}{2^{n+1}}+\\cdots$\r\n\t\t\\task[\\textbf{c.}] $\\frac{(x-2)}{2^{2}}-\\frac{(x-2)^{2}}{2^{3}}-\\cdots+(-1)^{n} \\frac{(x-2)^{n}}{2^{n+1}}-\\cdots$\r\n\t\t\\task[\\textbf{d.}] $1-\\frac{(x)}{2^{2}}+\\frac{(x)^{2}}{2^{3}}-\\cdots+(-1)^{n} \\frac{(x-)^{n}}{2^{n+1}}+\\cdots$\r\n\t\\end{tasks}\r\n\t\\item Let $A(t)$ denote the area bounded by the curve $y=e^{-|x|}$, the $x$ -axis and the straight lines $x=-t$\r\n\tand $x=t$. Then $\\lim _{t \\rightarrow \\infty} A(t)$ is equal to\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{a.}]$2$  \r\n\t\t\\task[\\textbf{b.}]$-2$\r\n\t\t\\task[\\textbf{c.}]$1$ \r\n\t\t\\task[\\textbf{d.}]$-1$ \r\n\t\\end{tasks}\r\n\\end{enumerate}\r\n\\colorlet{ocre1}{ocre!70!}\r\n\\colorlet{ocrel}{ocre!30!}\r\n\\setlength\\arrayrulewidth{1pt}\r\n\\begin{table}[H]\r\n\t\\centering\r\n\t\\arrayrulecolor{ocre}\r\n\t\r\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\r\n\t\t\\hline\r\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\r\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\r\n\t\t1&\\textbf{a}&2&\\textbf{c}\\\\\\hline \r\n\t\t3&\\textbf{d}&4&\\textbf{a}\\\\\\hline\r\n\t\t5&\\textbf{a}&6&\\textbf{c}\\\\\\hline\r\n\t\t7&\\textbf{a}&8&\\textbf{b}\\\\\\hline\r\n\t\t9&\\textbf{b}&10&\\textbf{c}\\\\\\hline\r\n\t\t11&\\textbf{c}&12&\\textbf{d}\\\\\\hline\r\n\t\t13&\\textbf{a}&14&\\textbf{b}\\\\\\hline\r\n\t\t15&\\textbf{a}&&\\\\\\hline\r\n\t\\end{tabular}\r\n\\end{table}\r\n\\newpage\\begin{abox}\r\n\tPractise Set-3\r\n\\end{abox}\r\n\\begin{enumerate}\r\n\t\\item If a function is given by\r\n\t$$\r\n\tf(x)=\\left\\{\\begin{array}{cl}\r\n\t\\frac{\\sin x}{x}+\\cos x, & x \\neq 0 \\\\\r\n\t2, & x=0\r\n\t\\end{array}\\right.\r\n\t$$\r\n\tFind out whether or $\\operatorname{not} f(x)$ is continuous at $x=0$.\r\n\t\\begin{answer}\r\n\t\tWe have\r\n\t\tL.H.L. at $x=0$\r\n\t\t\r\n\t\t\\begin{align*}\r\n\t\t\\text{L.H.L.}&=\\lim _{x \\rightarrow 0} f(x)=\\lim _{h \\rightarrow 0} f(0-h)=\\lim _{h \\rightarrow 0} f(-h) \\\\\r\n\t\t&=\\lim _{h \\rightarrow 0}\\left[\\frac{\\sin (-h)}{-h}+\\cos (-h)\\right]=1+1=2\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\tR.H.L. at $x=0$\r\n\t\t\r\n\t\t\\begin{align*}\r\n\t\t\\text{R.H.L.}&=\\lim _{x \\rightarrow 0} f(x)=\\lim _{h \\rightarrow 0} f(0+h)=\\lim _{h \\rightarrow 0} f(h) \\\\\r\n\t\t&=\\lim _{h \\rightarrow 0}\\left[\\frac{\\sin h}{h}+\\cos h\\right]=1+1=2\r\n\t\t\\end{align*}\r\n\t\tAlso, we know that $f(0)=2 .$ Thus, $\\lim _{x \\rightarrow 0^{-}} f(x)=$ $\\lim _{x \\rightarrow 0^{+}} f(x)=f(0)$\r\n\t\t\\\\Hence, $f(x)$ is continuous at $x=0$.\r\n\t\t\r\n\t\\end{answer}\r\n\t\\item Discuss the continuity of $f(x)=2 x-|x|$ at $x=0$.\r\n\t\\begin{answer}\r\n\t\tWe have\r\n\t\t$$\r\n\t\t\\begin{array}{c}\r\n\t\tf(x)=2 x-|x|=\\left\\{\\begin{aligned}\r\n\t\t2 x-x, & \\text { if } x \\geq 0 \\\\\r\n\t\t2 x-(-x), & \\text { if } \\quad x<0\r\n\t\t\\end{aligned}\\right. \\\\\r\n\t\t\\Rightarrow f(x)=\\left\\{\\begin{aligned}\r\n\t\tx, & \\text { if } x \\geq 0 \\\\\r\n\t\t3 x, & \\text { if } \\quad x<0\r\n\t\t\\end{aligned}\\right.\r\n\t\t\\end{array}\r\n\t\t$$\r\n\t\t\\begin{align*}\r\n\t\t\\text{L.H.L. at x=0}\\\\\r\n\t\t&=\\lim _{x \\rightarrow 0^{-}} f(x)=\\lim _{x \\rightarrow 0^{-}} 3 x=3 \\times 0=0\\\\\r\n\t\t\\text{R.H.L. at }x=0\\\\\r\n\t\t&=\\lim _{x \\rightarrow 0^{+}} f(x)=\\lim _{x \\rightarrow 0^{+}}x=0\\\\\r\n\t\t\\text{and}\\ f(0)=0\\\\\r\n\t\t&=\\lim _{x \\rightarrow 0^{-}} f(x)=\\lim _{x \\rightarrow 0^{+}} f(x)=f(0)\\\\\r\n\t\t\\text{\tSo, $f(x)$ is continuous at $x=0$.}\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\\end{answer}\r\n\t\\item  Find all local maxima and minima for $f(x, y)=x^{2}-y^{2}$.\r\n\t\\begin{answer}\r\n\t\tHere, $f_{x}=2 x, f_{y}=-2 y, f_{x x}=2, f_{y y}=-2, f_{x y}=0$\\\\\\\\\r\n\t\tApplying $f_{x}=0, f_{y}=0$, we get $x=0$ and $y=0 .$ \\\\\\\\So, the critical point of the functions are $(0,0)$\\\\\\\\\r\n\t\tHere, ${Df(x,y)}(0,0)=f_{x x}(0,0) f_{y y}(0,0)-f_{x y}(0,0)^{2}=(2 \\times-2)-0=-4<0$\\\\\\\\\r\n\t\tSo, there is neither a maximum nor minimum at $(0,0)$, and so there are no local maxima or minima of the function.\r\n\t\t\\begin{note}\r\n\t\t\t\\textbf{Classifying stationary points of a function of two variables}\\\\\\\\\r\n\t\t\tConsider a function of two variables, $f(x y)$. Let $(a, b)$ be a stationary point, so that $f_{x}=0$ and $f_{y}=0$ at $(a, b)$. Then:\r\n\t\t\t\\begin{itemize}\r\n\t\t\t\t\\item  If $f_{x x} f_{y y}-f_{x y}^{2}<0$ at $(a, b)$ then $(a, b)$ is a saddle point.\\\\\r\n\t\t\t\t\\item  If $f_{x x} f_{y y}-f_{x y}^{2}>0$ at $(a, b)$ then $(a, b)$ is either a maximum or a minimum. Distinguish between these as follows:\\\\\r\n\t\t\t\t\r\n\t\t\t\t\\begin{itemize}\r\n\t\t\t\t\t\\item  If $f_{x x}<0$ and $f_{y y}<0$ at $(a, b)$ then $(a, b)$ is a maximum point.\\\\\r\n\t\t\t\t\t\\item If $f_{x x}>0$ and $f_{y y}>0$ at $(a, b)$ then $(a, b)$ is a minimum point.\\\\\r\n\t\t\t\t\\end{itemize}\r\n\t\t\t\t\r\n\t\t\t\t\\item  If $f_{x x} f_{y y}-f_{x y}^{2}=0$ then anything is possible. More advanced methods are required to classify the stationary point properly.\r\n\t\t\t\\end{itemize}\r\n\t\t\\end{note}\r\n\t\\end{answer}\r\n\t\\item Find the absolute maximum and minimum values of $f(x)=\\sin x+\\frac{1}{2} \\cos 2 x$ in $\\left[0, \\frac{\\pi}{2}\\right]$\r\n\t\\begin{answer}\r\n\t\tWe have\r\n\t\t$$\r\n\t\tf(x)=\\sin x+\\frac{1}{2} \\cos 2 x \\quad \\text { in }\\left[0, \\frac{\\pi}{2}\\right]\r\n\t\t$$\r\n\t\tDifferentiating with respect to $x$, we get\r\n\t\t$$\r\n\t\tf^{\\prime}(x)=\\cos x-\\sin 2 x\r\n\t\t$$\r\n\t\tFor absolute maximum and absolute minimum,\r\n\t\t$$\r\n\t\t\\begin{aligned}\r\n\t\t& f^{\\prime}(x)=0 \\\\\r\n\t\t\\Rightarrow & \\cos x-2 \\sin x \\cos x=0 \\\\\r\n\t\t\\Rightarrow & \\cos x(1-2 \\sin x)=0 \\\\\r\n\t\t\\Rightarrow & \\cos x=0 \\quad \\text { or } \\quad \\sin x=\\frac{1}{2} \\\\\r\n\t\tx &=\\frac{\\pi}{2} \\text { or } \\frac{\\pi}{6}\r\n\t\t\\end{aligned}\r\n\t\t$$\r\n\t\tNow, $\\begin{aligned} f\\left(\\frac{\\pi}{6}\\right) &=\\sin \\frac{\\pi}{6}+\\frac{1}{2} \\cos \\frac{\\pi}{3}=\\frac{1}{2}+\\frac{1}{4}=\\frac{3}{4} \\\\ f\\left(\\frac{\\pi}{2}\\right) &=\\sin \\frac{\\pi}{2}+\\frac{1}{2} \\cos \\pi=1-\\frac{1}{2}=\\frac{1}{2} \\\\ f(0) &=\\sin 0+\\frac{1}{2} \\cos 0=0+\\frac{1}{2}=\\frac{1}{2} \\end{aligned}$\r\n\t\t\\\\The absolute maximum value $=3 / 4$\r\n\t\t\\\\The absolute minimum value $=1 / 2$.\r\n\t\\end{answer}\r\n\t\\item Expand $e^{\\sin x}$ by Maclaurin's series up to the term containing $x^{4}$.\r\n\t\\begin{answer}\r\n\t\t\r\n\t\t\\begin{align*}\r\n\t\tf(x)&= e^{\\sin x} \\\\\r\n\t\tf^{\\prime}(x)&= e^{\\sin x} \\cos x \\cdot f(x) \\cdot \\cos x \\\\\r\n\t\tf^{\\prime \\prime}(x)&= f^{\\prime}(x) \\cos x-f(x) \\sin x \\\\ f^{\\prime \\prime}(0)&=1 \\\\\r\n\t\tf^{\\prime \\prime \\prime}(x)&= f^{\\prime \\prime}(x) \\cos x-2 f^{\\prime}(x) \\sin x \r\n\t\t-f(x) \\cos x\\\\ f^{\\prime \\prime \\prime}(0)&=0 \\\\\r\n\t\tf^{\\prime \\prime \\prime \\prime}(x)&= f^{\\prime \\prime \\prime}(x) \\cos x-3 f^{\\prime}(x) \\sin x \r\n\t\t-3 f^{\\prime}(x) \\cos x \\cdot f(x) \\sin x  \\\\\r\n\t\tf^{\\prime \\prime \\prime \\prime}(0)&=-3\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\tand so on.\r\n\t\tSubstituting the values of $f(0), f^{\\prime}(0)$, etc. in the Maclaurin's series, we get\r\n\t\t\\begin{align*}\r\n\t\te^{(\\sin x)} &=1+x \\cdot 1+\\frac{x^{2} \\cdot 1}{2 !}+\\frac{x^{3} \\cdot 0}{3 !}+\\frac{x^{4} \\cdot(-3)}{4 !}+\\cdots \\\\\r\n\t\t&=1+x+\\frac{x^{2}}{2}-\\frac{x^{4}}{8}+\\cdots\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\\end{answer}\r\n\t\\item For what interval is $f(x)=\\frac{x}{2}+\\frac{2}{x}, x \\neq 0$ increasing?\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{a.}] $(-\\infty,-2) \\cup(2, \\infty)$ \r\n\t\t\\task[\\textbf{b.}]$(-\\infty,-1) \\cup(1, \\infty)$\r\n\t\t\\task[\\textbf{c.}]$(-2,2)$ \r\n\t\t\\task[\\textbf{d.}] $(0, \\infty)$\r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\tWe have\r\n\t\t\\begin{align*}\r\n\t\tf(x) &=\\frac{x}{2}+\\frac{2}{x} \\\\\r\n\t\t\\Rightarrow \\quad f^{\\prime}(x) &=\\frac{1}{2}-\\frac{2}{x^{2}}=\\frac{x^{2}-4}{2 x^{2}}\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\tFor $f(x)$ to be increasing,\r\n\t\t\\begin{figure}[H]\r\n\t\t\t\\includegraphics[width=0.55\\textwidth]{pset-2 single}\r\n\t\t\\end{figure}\r\n\t\t\\begin{align*}\r\n\t\t& f^{\\prime}(x)>0 \\\\\r\n\t\t\\Rightarrow & \\frac{x^{2}-4}{2 x^{2}}>0 \\\\\r\n\t\t\\Rightarrow & x^{2}-4>0 \\Rightarrow(x-2)(x+2)>0 \\\\\r\n\t\t\\Rightarrow & x<-2 \\quad \\text { or } \\quad x>2\r\n\t\t\\end{align*}\r\n\t\tSo, $f(x)$ is increasing on $(-\\infty,-2) \\cup(2, \\infty)$.\r\n\t\\end{answer}\r\n\t\\item As $x$ increased from $-\\infty$ to $\\infty$, the function $f(x)=\\frac{e^{x}}{1+e^{x}}$\r\n\t(a) monotonically increases\r\n\t(b) monotonically decreases\r\n\t(c) increases to a maximum value and then decreases\r\n\t\\begin{tasks}(1)\r\n\t\t\\task[\\textbf{a.}]Monotonically increases \r\n\t\t\\task[\\textbf{b.}]Monotonically decreases\r\n\t\t\\task[\\textbf{c.}]Increases to a maximum value and then decreases\r\n\t\t\\task[\\textbf{d.}]Decreases to a minimum value and then increases\r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t\\text{We have,}\\\\\r\n\t\tf(x)&=\\frac{e^{x}}{1+e^{x}}\\\\\r\n\t\t\\text{\tDifferentiating $f(x)$, we get}\\\\\r\n\t\tf^{\\prime}(x)&=\\frac{e^{x}\\left(1+e^{x}\\right)-e^{2 x}}{\\left(1+e^{x}\\right)^{2}}\\\\&=\\frac{e^{x}}{\\left(1+e^{x}\\right)^{2}}\r\n\t\t\\end{align*}\r\n\t\tSince $e^{x}$ is positive for all values of $x, f^{\\prime}(x)$ is positive for all values of $x$ and hence $f(x)$ monotonically increases. \r\n\t\t\r\n\t\t\r\n\t\\end{answer}\r\n\t\r\n\t\\item The Taylor's series expansion of $\\frac{\\sin x}{x-\\pi}$ at $x=\\pi$ is given by\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{a.}] $1+\\frac{(x-\\pi)^{2}}{3 !}+\\cdots$ \r\n\t\t\\task[\\textbf{b.}]$-1-\\frac{(x-\\pi)^{2}}{3 !}+\\cdots$\r\n\t\t\\task[\\textbf{c.}]$1-\\frac{(x-\\pi)^{2}}{3 !}+\\cdots$ \r\n\t\t\\task[\\textbf{d.}]  $-1+\\frac{(x-\\pi)^{2}}{3 !}+\\cdots$\r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\tTaylor's series expansion of $f(x)$ around $x=\\pi$ is\r\n\t\t\\begin{align*}\r\n\t\tf(x)&=f(\\pi)+\\frac{x-\\pi}{1 !} f^{\\prime}(\\pi)+\\frac{(x-\\pi)^{2}}{2 !} f^{\\prime \\prime}(\\pi)+\\cdots \\\\\r\n\t\t\\text { Now, } f(\\pi)&=\\lim _{x \\rightarrow \\pi} \\frac{\\sin x}{x-\\pi}\\\\&=\\lim _{x \\rightarrow \\infty} \\frac{\\cos x}{1}=-1\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\tSimilarly, by using L'Hospital's rule, we can show that\r\n\t\t\\begin{align*}\r\n\t\tf^{\\prime}(\\pi)&=0\\\\\\text{and} \\quad f^{\\prime \\prime}(\\pi)&=-\\frac{1}{3}\\\\\r\n\t\t\\text{\tSo, the expansion is}\\quad f(x)&=-1+(-1 / 6)(x-\\pi)^{2}+\\cdots\\\\\r\n\t\tf(x)&=-1-\\frac{\\left(x^{\\prime}-\\pi\\right)^{2}}{3 !}+\\cdots\r\n\t\t\\end{align*}\r\n\t\tSo the correct answer is {\\textbf{b}}\r\n\t\\end{answer}\r\n\t\r\n\t\\item Find $\\frac{d z}{d t}$ when $z=x y^{2}+x^{2} y, x=a t^{2}, y=2 a t$\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t&\\text { We have, } z=x y^{2}+x^{2} y \\Rightarrow \\frac{\\partial z}{\\partial x}-y^{2}+2 x y \\text { and } \\frac{\\partial z}{\\partial y}=2 x y+x^{2}\\\\\r\n\t\t&\\begin{aligned}\r\n\t\t\\text { Also, } x &=a t^{2}, y=2 a t \\Rightarrow \\frac{d x}{d t}=2 a t, \\frac{d y}{d t}=2 a \\\\\r\n\t\t\\text { Hence, }, & \\frac{d z}{d t}=\\frac{\\partial z}{\\partial x} \\cdot \\frac{d x}{d t}+\\frac{\\partial z}{\\partial y} \\frac{d y}{d t}=\\left(y^{2}+2 x y\\right)(2 a t)+\\left(2 x y+x^{2}\\right) 2 a \\\\\r\n\t\t&=\\left(4 a^{2} t^{2}+2 a t^{2} \\cdot 2 a t\\right) 2 a t+\\left(2 a t^{2} 2 a t+a^{2} t^{4}\\right) 2 a \\\\\r\n\t\t&=8 a^{3} t^{3}+8 a^{3} t^{4}+8 a^{3} t^{3}+2 a^{4} t^{3}\\\\&=16 a^{3} t^{3}+8 a^{3} t^{4}+2 a^{4} t^{3}\\\\&=16 a^{3} t^{3}+10 a^{3} t^{4}\r\n\t\t\\end{aligned}\r\n\t\t\\end{align*}\r\n\t\\end{answer}\r\n\t\\item \r\n\tIf  $x^{y}+y^{x}=c$,  find the value of $ \\frac{d y}{d x}$\r\n\t\r\n\t\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t\\text { Let } f(x, y)&=x^{y}+y^{x}\\\\\r\n\t\t\\text { Then, } \\frac{\\partial f}{\\partial x}&=y x^{y-1}+y^{x} \\log _{e} y ; \\text { Similarly }, \\frac{\\partial f}{\\partial y}=x^{y} \\log _{e} x+x y^{x-1}\\\\\r\n\t\t\\therefore \\quad \\frac{d y}{d x}&=-\\frac{\\partial f / \\partial x}{\\partial f / \\partial y}=-\\frac{y^{x} \\log _{e} y+y^{y-1}}{x^{y} \\log _{e} x+x y^{x-1}}\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\\end{answer}\r\n\t\r\n\\end{enumerate}\r\n\r\n\\newpage\r\n\\begin{abox}\r\n\tBHU Previous Year Questions\r\n\\end{abox}\r\n\\section*{\\centering{\\color{futuringtheme} \\underline{Single Variable Calculus}}}\r\n\r\n\\begin{questions}\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question In the limit $x \\rightarrow \\infty, \\ln (x)-x$\r\n\t\t\\exyear{BHU 2012}\r\n\t\\end{minipage}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] equals zero\r\n\t\t\\task[\\textbf{B.}]equals 2\r\n\t\t\\task[\\textbf{C.}]equals $-\\infty$\r\n\t\t\\task[\\textbf{D.}] equals$+\\infty$\r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t\\lim _{x \\rightarrow \\infty} \\ln(x)-x&=-\\lim _{x \\rightarrow \\infty}  (x-\\ln (x))\\\\\\\r\n\t\tx-\\ln (x) \r\n\t\t&=\\ln \\left(e^{x}\\right)+\\ln \\left(x^{-1}\\right) \\\\\r\n\t\t&=\\ln \\left(\\frac{e^{x}}{x}\\right)\\\\\\text{But }\\lim _{x \\rightarrow \\infty} \\frac{e^{x}}{x}&=\\frac{\\infty}{\\infty}\\\\\r\n\t\t\\intertext{Since the form is indeterminate using L'Hopital's rule we get,}\r\n\t\t\\lim _{x \\rightarrow \\infty} \\frac{e^{x}}{x}&=\\lim _{x \\rightarrow \\infty} \\frac{e^{x}}{1} \\rightarrow \\infty\\\\\r\n\t\t\\text{Then,}\\ \\lim _{x \\rightarrow \\infty} \\ln(x)-x&=-(\\lim _{x \\rightarrow \\infty} \\ln(\\infty))\\\\&=-\\infty\r\n\t\t\\end{align*}\r\n\t\tCorrect option is (C)\r\n\t\\end{answer}\r\n\t\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question The mutual potential energy $V$ of two particles depends on their spatial separation as follows $$V=\\frac{a}{r^{2}}-\\frac{b}{r} ; a>0 ; b>0$$For what separation are the particles in static equilibrium?\r\n\t\t\\exyear{BHU 2012}\r\n\t\\end{minipage}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $\\frac{a}{b}$\r\n\t\t\\task[\\textbf{B.}]$\\frac{a}{2 b}$\r\n\t\t\\task[\\textbf{C.}] $\\frac{a^{2}}{b}$\r\n\t\t\\task[\\textbf{D.}] $\\frac{2 a}{b}$ \r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\tAt static equilibrium,\\begin{align*}\r\n\t\t\\frac{\\partial v}{\\partial r}&=0\\\\\r\n\t\t\\frac{\\partial v}{\\partial r}&=\\frac{\\partial( ar^{-2}-br^{-1})}{\\partial r }\\\\\r\n\t\t&=-\\frac{2a}{r^{3}}+\\frac{b}{r^{2}}\\\\\r\n\t\t\\Rightarrow -\\frac{2a}{r^{3}}+\\frac{b}{r^{2}}&=0\\\\\r\n\t\t\\frac{2a}{r^{3}}&=\\frac{b}{r^{2}}\\\\\r\n\t\tr&=\\frac{2a}{b}\r\n\t\t\\end{align*}\r\n\t\tCorrect option is (D)\r\n\t\\end{answer}\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question $\\operatorname{Lt}_{x \\rightarrow \\infty} \\sqrt{x}(\\sqrt{x+4}-\\sqrt{x})$\r\n\t\t\\exyear{BHU 2012}\r\n\t\\end{minipage}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] 0\r\n\t\t\\task[\\textbf{B.}]2\r\n\t\t\\task[\\textbf{C.}] $\\frac{1}{2}$\r\n\t\t\\task[\\textbf{D.}] does not exist\r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t\\lim _{x \\rightarrow \\infty} \\sqrt{x}(\\sqrt{x+4}-\\sqrt{x})&=\\lim _{x \\rightarrow \\infty} (\\sqrt{x^{2}+4x}-{x})\\\\\r\n\t\t\\intertext{Multiply numerator and denominator by the conjugate}\r\n\t\t&=\\lim _{x \\rightarrow \\infty} (\\sqrt{x^{2}+4x}-{x})\\cdot \\frac{(\\sqrt{x^{2}+4x}+{x})}{(\\sqrt{x^{2}+4x}+{x})}\\\\\r\n\t\t&=\\lim _{x \\rightarrow \\infty} \\frac{x^{2}+4x-x^{2}}{(\\sqrt{x^{2}+4x}+{x})}\\\\\r\n\t\t&=\\lim _{x \\rightarrow \\infty} \\frac{4x}{(\\sqrt{x^{2}+4x}+{x})}\\\\\r\n\t\t&=\\lim _{x \\rightarrow \\infty} \\frac{4x}{x(\\sqrt{1+\\frac{4}{x}}+{1})}\\\\\r\n\t\t&=\\lim _{x \\rightarrow \\infty} \\frac{4}{(\\sqrt{1+\\frac{4}{x}}+{1})} \\hspace{2cm} \\because \\lim _{x \\rightarrow \\infty}\\frac{4}{x}=\\frac{4}{\\infty}=0 \\\\\r\n\t\t&=\\frac{4}{(\\sqrt{1}+{1})}\\\\\r\n\t\t&=\\frac{4}{2}=2\r\n\t\t\\end{align*}\r\n\t\tCorrect option is(B)\r\n\t\\end{answer}\r\n\t\r\n\t\\section*{\\centering{\\color{futuringtheme} \\underline{Integral Calculus}}}\r\n\t\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question If $[x]$ stands for largest integer not exceeding $x$, then the integral $\\int_{-1}^{+2}[x] d x$ equals\r\n\t\t\\exyear{BHU 2012}\r\n\t\\end{minipage}\r\n\t\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] 3\r\n\t\t\\task[\\textbf{B.}]0\r\n\t\t\\task[\\textbf{C.}]1\r\n\t\t\\task[\\textbf{D.}] 2\r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t\\int_{-1}^{+2}[x] d x&=\\int_{x=-1}^{0}[x] d x+\\int_{x=0}^{1}[x] d x+\\int_{x=1}^{2}[x] d x \\\\\r\n\t\t&=\\int_{-1}^{0} -1 d x+\\int_{0}^{1} 0 d x+\\int_{1}^{2} 1 d x\\\\\r\n\t\t&=\\left[-x \\right]_{-1} ^{0}+\\left[0 \\right]_{0} ^{1}+\\left[x \\right]_{1} ^{2}\\\\\r\n\t\t&=-1+0+1=0\r\n\t\t\\end{align*}\r\n\t\tCorrect option is (B)\r\n\t\\end{answer}\r\n\t\r\n\t\r\n\t\\begin{abox}\r\n\t\tHCU Previous Year Questions\r\n\t\\end{abox}\r\n\t\\section*{\\centering{\\color{futuringtheme} \\underline{ Serieses}}}\r\n\t\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question  The first three terms in the Taylor series expansion of $\\sin x$ around $x=\\frac{\\pi}{2}$ are \r\n\t\t{\\exyear{HCU 2015}}\r\n\t\\end{minipage}\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{A.}]$\\left(x-\\frac{\\pi}{2}\\right)-\\frac{\\left(x-\\frac{\\pi}{2}\\right)^{3}}{3 !}+\\frac{\\left(x-\\frac{\\pi}{2}\\right)^{5}}{5 !}$ \r\n\t\t\\task[\\textbf{B.}]$\\left(x-\\frac{\\pi}{2}\\right)+\\frac{\\left(x-\\frac{\\pi}{2}\\right)^{3}}{3 !}+\\frac{\\left(x-\\frac{\\pi}{4}\\right)^{5}}{5 !}$ \r\n\t\t\\task[\\textbf{C.}] (c) $1-\\frac{\\left(x-\\frac{\\pi}{2}\\right)^{2}}{2 !}+\\frac{\\left(x-\\frac{\\pi}{2}\\right)^{4}}{4 !}$\r\n\t\t\r\n\t\t\\task[\\textbf{D.}]$1+\\left(x-\\frac{\\pi}{2}\\right)+\\frac{1}{2 !}\\left(x-\\frac{\\pi}{2}\\right)^{2}$ \r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\tf(x)&=\\sin x \\quad f(\\pi / 2)=1\\\\\r\n\t\tf^{\\prime}(x)&=\\cos x \\quad f^{\\prime}(\\pi / 2)=0\\\\\r\n\t\tf^{\\prime \\prime}(x)&=-\\sin x \\quad f^{\\prime \\prime}(\\pi / 2)=-1\\\\\r\n\t\tf^{\\prime \\prime \\prime}(x)&=-\\cos x \\quad f^{\\prime \\prime \\prime}(\\pi / 2)=0 \\quad\r\n\t\t\\intertext{\tThen,  Taylor expansion of $ f(x) $ about $x=\\frac{\\pi}{2}$}\r\n\t\tf(x)&=f\\left(\\frac{\\pi}{2}\\right)+\\left(x-\\frac{\\pi}{2}\\right) f^{\\prime}\\left(\\frac{\\pi}{2}\\right)+\\left(x-\\frac{\\pi}{2}\\right)^{2} \\frac{f^{\\prime \\prime}(\\pi / 2)}{2 !}+\\left(x-\\frac{\\pi}{2}\\right)^{3} \\frac{f^{\\prime \\prime \\prime}(\\pi / 2)}{3 !}+\\cdots\\\\\r\n\t\t&=1-\\left(\\frac{x-\\frac{\\pi}{2}}{2 !}\\right)^{2}+\\left(\\frac{x-\\frac{\\pi}{4}}{4 !}\\right)^{4}-\\cdots\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\tCorrect option is (C)\r\n\t\\end{answer}\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question The sum of the series\r\n\t\t$$\r\n\t\t1-\\frac{1}{3}+\\frac{1}{5}-\\frac{1}{7}+\\frac{1}{9}-\\frac{1}{11}+\\cdots \\cdots\r\n\t\t$$\r\n\t\tis equal to\r\n\t\t{\\exyear{HCU 2018}}\r\n\t\\end{minipage}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}]$\\frac{\\pi}{2}$. \r\n\t\t\\task[\\textbf{B.}]$\\frac{\\pi}{4}$. \r\n\t\t\\task[\\textbf{C.}]$\\pi$ \r\n\t\t\\task[\\textbf{D.}]$\\frac{100}{101}$. \r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t\\intertext{We know that,}\r\n\t\t\\tan ^{-1} x&=x-\\frac{x^{3}}{3}+\\frac{x^{5}}{5}-\\frac{x^{7}}{7}+\\ldots \\ldots\\\\ \r\n\t\t\\text{When $x=1$,}\\ \\tan ^{-1} 1&=1-\\frac{1}{3}+\\frac{1}{5}-\\frac{1}{7}+\\frac{1}{9}-\\frac{1}{11}+\\cdots \\cdots\\\\&=\\frac{\\pi}{4}\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\tCorrect option is(B)\r\n\t\\end{answer}\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question  The product of the two given series\r\n\t\t$$\r\n\t\t\\left(x-\\frac{1}{3 !} x^{3}+\\frac{1}{5 !} x^{5}+\\cdots\\right)\\left(1-\\frac{1}{2 !} x^{2}+\\frac{1}{4 !} x^{4}+\\cdots\\right)\r\n\t\t$$\r\n\t\t{\\exyear{HCU 2019}}\r\n\t\\end{minipage}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $e^{2 x}$\r\n\t\t\\task[\\textbf{B.}] $\\frac{1}{2}(\\cos 2 x)$\r\n\t\t\\task[\\textbf{C.}] $e^{-2 x}$\r\n\t\t\\task[\\textbf{D.}] $\\frac{1}{2}(\\sin 2 x)$\r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\tWe know that,\r\n\t\t\\begin{align*}\r\n\t\t\\sin x&=\\left(x-\\frac{1}{3 !} x^{3}+\\frac{1}{5 !} x^{5}+\\cdots\\right)\\\\\r\n\t\t\\cos x&=\\left(1-\\frac{1}{2 !} x^{2}+\\frac{1}{4 !} x^{4}+\\cdots\\right)\\\\\r\n\t\t\\text{Then,}\\\\\r\n\t\t\\sin x \\cos x&=\\left(x-\\frac{1}{3 !} x^{3}+\\frac{1}{5 !} x^{5}+\\cdots\\right)\\left(1-\\frac{1}{2 !} x^{2}+\\frac{1}{4 !} x^{4}+\\cdots\\right)\\\\\r\n\t\t\\text{But,}\\ \\sin 2x&=2\\sin x \\cos x\\\\\\\\\r\n\t\t\\text{Then,}\\\\\r\n\t\t\\sin x \\cos x&=\\left(x-\\frac{1}{3 !} x^{3}+\\frac{1}{5 !} x^{5}+\\cdots\\right)\\left(1-\\frac{1}{2 !} x^{2}+\\frac{1}{4 !} x^{4}+\\cdots\\right)=\\frac{1}{2}\\sin 2x\r\n\t\t\\end{align*}\r\n\t\tCorrect option is (D)\r\n\t\\end{answer}\r\n\t\r\n\t\\section*{\\centering{\\color{futuringtheme} \\underline{Trigonometry}}}\r\n\t\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question If $\\cot \\theta=\\sin 2 \\theta$, the possible values of $\\tan \\theta$ are\r\n\t\t{\\exyear{HCU 2020}}\r\n\t\\end{minipage}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}]0,1 . \r\n\t\t\\task[\\textbf{B.}]$-1,0$. \r\n\t\t\\task[\\textbf{C.}]$-1,1$. \r\n\t\t\\task[\\textbf{D.}]$-1 / 2,1 / 2$. \r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t\\cot \\theta&=\\sin 2 \\theta\\\\\r\n\t\t&=2\\sin \\theta \\cos \\theta\\\\\r\n\t\t\\tan \\theta &=\\frac{1}{\\cot \\theta}=\\frac{1}{2\\sin \\theta \\cos \\theta}\\\\\r\n\t\t\\text{Then tan exists only when}\\ \\sin \\theta &= \\cos \\theta \\neq 0\\\\\r\n\t\t\\Rightarrow \\theta&= \\pm 45^{\\circ}\r\n\t\t\\text{Then,} \\tan \\theta &=-1,1\r\n\t\t\\end{align*}\r\n\t\tCorrect option is(C)\r\n\t\\end{answer}\r\n\t\\begin{abox}\r\n\t\tJEST Previous Year Questions\r\n\t\\end{abox}\r\n\t\\section*{\\centering{\\color{futuringtheme} \\underline{ Serieses}}}\r\n\t\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question As $x \\rightarrow 1$, the infinite series $x-\\frac{1}{3} x^{3}+\\frac{1}{5} x^{5}-\\frac{1}{7} x^{7}+\\ldots \\ldots .$\r\n\t\t\\exyear{JEST 2012}\r\n\t\\end{minipage}\r\n\t\\begin{tasks}(2)\r\n\t\t\\task[\\textbf{A.}] diverges\r\n\t\t\\task[\\textbf{B.}] converges to unity\r\n\t\t\\task[\\textbf{C.}]converges to $\\frac{\\pi}{4}$\r\n\t\t\\task[\\textbf{D.}]none of the above\r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t\\tan ^{-1} x&=x-\\frac{x^{3}}{3}+\\frac{x^{5}}{5}-\\frac{x^{7}}{7}+\\ldots \\ldots \\\\ \\tan ^{-1} 1&=\\frac{\\pi}{4}\r\n\t\t\\end{align*}\r\n\t\tCorrect option is (C)\r\n\t\\end{answer}\r\n\t\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question What is the value of the following series?\\\\\r\n\t\t$\\left(1+\\frac{1}{2 !}+\\frac{1}{4 !}+\\ldots .\\right)^{2}-\\left(1+\\frac{1}{3 !}+\\frac{1}{5 !}+\\ldots . .\\right)^{2}$\r\n\t\t\\exyear{JEST 2012}\r\n\t\\end{minipage}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] 0\r\n\t\t\\task[\\textbf{B.}]$e$\r\n\t\t\\task[\\textbf{C.}]$e^{2}$\r\n\t\t\\task[\\textbf{D.}]1\r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\te^{1}&=1+1+\\frac{1^{2}}{2 !}+\\frac{1^{3}}{3 !}+-; \\hspace{0.2cm} e^{-1}=1-1+\\frac{1^{2}}{2 !}-\\frac{1^{3}}{3 !} \\ldots . .\\\\\r\n\t\t\\cosh 1&=\\frac{e^{1}+e^{-1}}{2}\\\\&=1+\\frac{1}{2 !}+\\frac{1}{4 !}+\\ldots\\\\\r\n\t\t\\sinh 1&=\\frac{\\left(e^{1}-e^{-1}\\right)}{2}\\\\&=1+\\frac{1}{3 !}+\\frac{1}{5 !}+\\ldots\\\\\r\n\t\t\\text{i.e.,}\\ \\cosh ^{2} 1-\\sinh ^{2} 1&=1\r\n\t\t\\end{align*}\r\n\t\tCorrect option is (D)\r\n\t\\end{answer}\r\n\t\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question What is the value of the following series?\r\n\t\t$$\\left(1-\\frac{1}{2 !}+\\frac{1}{4 !}-\\ldots .\\right)^{2}+\\left(1-\\frac{1}{3 !}+\\frac{1}{5 !}-\\ldots\\right)^{2}$$\r\n\t\t\\exyear{JEST 2013}\r\n\t\\end{minipage}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] 0\r\n\t\t\\task[\\textbf{B.}]e\r\n\t\t\\task[\\textbf{C.}]$e^{2}$\r\n\t\t\\task[\\textbf{D.}]1\r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t\\cos \\theta&=1-\\frac{\\theta^{2}}{2 !}+\\frac{\\theta^{4}}{4 !} \\ldots . \\\\ \\sin \\theta&=\\theta-\\frac{\\theta^{3}}{3 !}+\\frac{\\theta^{5}}{5 !} \\ldots . .\\\\\r\n\t\t\\left(1-\\frac{1}{2 !}+\\frac{1}{4 !} \\ldots\\right)^{2}+\\left(1-\\frac{1}{3 !}+\\frac{1}{5 !}\\right)^{2}&=\\cos ^{2} 1+\\sin ^{2} 1\\\\&=1 \\hspace{2.5cm}\\left[\\because \\sin ^{2} \\theta+\\cos ^{2} \\theta=1\\right]\r\n\t\t\\end{align*}\r\n\t\tCorrect option is (D)\r\n\t\\end{answer}\r\n\t\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question The sum $\\sum_{m=1}^{99} \\frac{1}{\\sqrt{m+1}+\\sqrt{m}}$ is equal to\\\\\r\n\t\t\\exyear{JEST 2015}\r\n\t\\end{minipage}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] 9\r\n\t\t\\task[\\textbf{B.}]$\\sqrt{99}-1$\r\n\t\t\\task[\\textbf{C.}]$\\frac{1}{(\\sqrt{99}-1)}$\r\n\t\t\\task[\\textbf{D.}]11\r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t\\sum_{m=1}^{99} \\frac{1}{\\sqrt{m+1}+\\sqrt{m}}&=\\sum_{m=1}^{99} \\frac{\\sqrt{m+1}-\\sqrt{m}}{(m+1)-m}\\\\&=\\sum_{m=1}^{99} \\sqrt{m+1}-\\sqrt{m}\\\\\r\n\t\t&=\\sqrt{2}-\\sqrt{1}+\\sqrt{3}-\\sqrt{2} \\ldots . .+\\sqrt{100}-\\sqrt{99}\\\\&=\\sqrt{100}-\\sqrt{1}\\\\&=10-1=9\r\n\t\t\\end{align*}\r\n\t\tCorrect option is (A)\r\n\t\\end{answer}\r\n\t\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question The sum of the infinite series $1-\\frac{1}{3}+\\frac{1}{5}-\\frac{1}{7}+\\ldots$ is\r\n\t\t\\exyear{JEST 2016}\r\n\t\\end{minipage}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $2 \\pi$\r\n\t\t\\task[\\textbf{B.}]$\\pi$\r\n\t\t\\task[\\textbf{C.}]$\\frac{\\pi}{2}$\r\n\t\t\\task[\\textbf{D.}]$\\frac{\\pi}{4}$\r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t\\intertext{The series expansion of  $ \\tan ^{-1} x  $  in interval $ -1<x \\leq 1 $ is,}\r\n\t\t\\tan ^{-1} x&=x-\\frac{1}{3} x^{3}+\\frac{1}{5} x^{5}-\\frac{1}{7} x^{7}+\\cdots\r\n\t\t\\intertext{Putting $ x=1, $ we get,}\r\n\t\t\\tan ^{-1} 1&=1-\\frac{1}{3}+\\frac{1}{5}-\\frac{1}{7}+\\cdots \\cdot \\\\&=1-\\frac{1}{3}+\\frac{1}{5}-\\frac{1}{7} \\cdots \\cdot\\\\&=\\frac{\\pi}{4}\r\n\t\t\\end{align*}\r\n\t\tCorrect option is (D)\r\n\t\\end{answer}\r\n\t\\section*{\\centering{\\color{futuringtheme} \\underline{Integral Calculus}}}\r\n\t\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question If $[\\mathrm{x}]$ denotes the greatest integer not exceeding $\\mathrm{x}$, then $\\int_{0}^{\\infty}[x] e^{-x} d x$\r\n\t\t\\exyear{JEST 2012}\r\n\t\\end{minipage}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $\\frac{1}{e-1}$\r\n\t\t\\task[\\textbf{B.}]1\r\n\t\t\\task[\\textbf{C.}]$\\frac{e-1}{e}$\r\n\t\t\\task[\\textbf{D.}]$\\frac{e}{e^{2}-1}$\r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\t\\begin{align*}\r\n\t\t[x]=0 \\rightarrow 0 \\leq x<1&;\\hspace{0.2cm} [x]=1\\rightarrow 1 \\leq x<2; \\hspace{0.2cm} [x]=2 \\rightarrow 2 \\leq x<3\\\\\r\n\t\t\\intertext{Then,}\\int_{0}^{\\infty}[x] e^{-x} d x&=\\int_{0}^{1}[x] e^{-x} d x+\\int_{1}^{2}[x] e^{-x} d x+\\int_{2}^{3}[x] e^{-x} d x+\\int_{3}^{4}[x] e^{-x} d x\\\\\r\n\t\t&\\Rightarrow 0+\\int_{1}^{2} 1 . e^{-x} d x+\\int_{2}^{3} 2 . e^{-x} d x+\\int_{3}^{4} 3 \\cdot e^{-x} d x\\\\&=\\left[-e^{-x}\\right]_{1}^{2}+2\\left(-e^{-x}\\right)_{2}^{3}+3\\left(-e^{-x}\\right)_{3}^{4}+\\ldots\\\\\r\n\t\t&=e^{-1}-e^{-2}+2 e^{-2}-2 e^{-3}+3 e^{-3}-3 e^{-4}+4 e^{-4}-4 e^{-5}+\\\\\r\n\t\t&=e^{-1}+e^{-2}+e^{-3}+e^{-4}+\\ldots \\ldots \\infty\\\\\r\n\t\t&=\\frac{e^{-1}}{1-e^{-1}}=\\frac{1}{e-1}\\hspace{2cm}\\left(\\because r=\\frac{e^{-2}}{e^{-1}}=e^{-2+1}=e^{-1}\\right)\r\n\t\t\\end{align*}\r\n\t\tCorrect option is (A)\r\n\t\\end{answer}\r\n\t\\section*{\\centering{\\color{futuringtheme} \\underline{Trigonometry}}}\r\n\t\r\n\t\r\n\t\\begin{minipage}{\\textwidth}\r\n\t\t\\question A semicircular piece of paper is folded to make a cone with the centre of the semicircle as the apex. The half-angle of the resulting cone would be:\r\n\t\t\\exyear{JEST 2016}\r\n\t\\end{minipage}\r\n\t\\begin{tasks}(4)\r\n\t\t\\task[\\textbf{A.}] $90^{\\circ}$\r\n\t\t\\task[\\textbf{B.}]$60^{\\circ}$\r\n\t\t\\task[\\textbf{C.}]$45^{\\circ}$\r\n\t\t\\task[\\textbf{D.}]$30^{\\circ}$\r\n\t\\end{tasks}\r\n\t\\begin{answer}\r\n\t\tWhen the semicircular piece of paper is folded to make a cone, the circumference ofbase is equal to the circumference of the original semicircle. Let $r$ be the radius of the base of the cone and $R$ be the radius of the semicircle.\r\n\t\t\\begin{align*}\r\n\t\t\\text{Hence,}\\ 2 \\pi r&=\\pi R \\Rightarrow r=\\frac{R}{2}\r\n\t\t\\intertext{The stay height of the come will also be R.}\r\n\t\t\\text{Hence,}\\ \\sin \\alpha&=\\frac{R / 2}{R}=\\frac{1}{2}\\\\\r\n\t\t\\text{Thus, }\\ \\alpha&=30^{\\circ}\r\n\t\t\\end{align*}\r\n\t\t\\begin{figure}[H]\r\n\t\t\t\\begin{center}\r\n\t\t\t\t\\includegraphics[width=4.5cm,height=2.5cm]{32-S-crop}\r\n\t\t\t\\end{center}\r\n\t\t\\end{figure}\r\n\t\tCorrect option is (D)\r\n\t\\end{answer}\r\n\t\r\n\\end{questions}\r\n\r\n\r\n\r\n\r\n", "meta": {"hexsha": "1fdd439083c28f3e47750f537697d42b83feb889", "size": 75850, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/limits.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CSIR- Mathematical Physics/chapter/limits.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CSIR- Mathematical Physics/chapter/limits.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.9710144928, "max_line_length": 364, "alphanum_fraction": 0.5767040211, "num_tokens": 31994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.7399825723383503}}
{"text": "\\section*{Bayesian point estimation}\n\\begin{frame}{The maximum~\\textit{a posteriori} (MAP) estimator}\n\\begin{defn}[Maximum~\\textit{a posteriori}]\nThe posterior mode or maximum~\\textit{a posteriori} (MAP) estimator of a parameter $\\theta$ is given by\n\\begin{equation}\n \\label{eq:MAP}\n \\delta_{\\pi}^{\\text{MAP}}(x) := \\argmax_{\\theta \\in \\boldsymbol{\\Theta}} p(\\theta \\mid x).\n\\end{equation}\n\\end{defn}\n\\begin{example}[MAP for the binomial case]\n Suppose $x \\sim \\operatorname{Binomial}(n, p)$.\n Now consider the following three priors for $p$: \n \\begin{itemize}\n  \\item $\\pi_0(p) = \\frac{\\sqrt{p(1-p)}}{B(1/2, 1/2)} $ [Jeffreys];\n  \\item $\\pi_1(p) = 1$ [Beta(1,1)/Uniform];\n  \\item $\\pi_2(p) = \\left(p(1-p)\\right)^{-1}$ [\\cite{Haldane1932}].  \n \\end{itemize}\nThese lead to \n\\begin{itemize}\n \\item $\\delta_0^{\\text{MAP}}(x) = \\max \\{(x-1/2)/(n-1), 0 \\}$;\n \\item $\\delta_1^{\\text{MAP}}(x) = x/n$;\n \\item $\\delta_2^{\\text{MAP}}(x) = \\max \\{ (x-1)/(n-2), 0 \\}$.\n\\end{itemize}\n\\end{example}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A word of caution}\n We end this discussion with the following warning:\n\\begin{idea}[Marginalise, not maximise]\n\\label{idea:always_marginalise}~\n Bayesian approaches to estimation and prediction \\underline{usually} focus on \\textit{marginalisation} rather than \\textit{optmisation}.\n This is because, following the Likelihood Principle, all of the information available about the unknowns is contained in the posterior distribution, and thus all inferences must be made using this probability measure, usually by finding suitable expectations of functionals of interest.\n\\end{idea}\nIn particular, for higher dimensions, \\textbf{concentration of measure}\\footnote{See these excellent notes by Terence Tao:\\url{https://terrytao.wordpress.com/2010/01/03/254a-notes-1-concentration-of-measure/} .} ensures that the posterior mode has less and less relevance as a summary, at least so far as the barycentre of the distribution is concerned.\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Precision of Bayes estimators}\n A central quantity in the evaluation of Bayesian estimators is\n \\begin{equation}\n  \\label{eq:bayes_risk}\n  E_p\\left[\\left(\\delta_\\pi - h(\\theta)\\right)^2\\right] = E_{\\pi}\\left[\\left(\\delta_\\pi - h(\\theta)\\right)^2 \\mid x \\right]\n \\end{equation}\nfor measurable $h$.\n\\begin{example}[Bayes versus frequentist risk]\n Take $x \\sim \\operatorname{Binomial}(n, \\theta)$ with $n$ known and place a Jeffreys's prior on $\\theta$.\n Consider the MLE: $\\delta_1(x) = x/n$.\n It can be shown that:\n $$ E_\\pi\\left[\\left(\\delta_1 - \\theta \\right)^2 \\mid x \\right] = \\left(\\frac{x - n/2}{n(n+1)}\\right)^2 +  \\frac{(x + 1/2)(n - x + 1/2)}{(n + 1)^2(n+2)}.$$\n Moreover,\n $$\\max_{\\theta \\in (0, 1)}  E_\\pi\\left[\\left(\\delta_1 - \\theta\\right)^2 \\mid x \\right] = [4(n+2)]^{-1},$$\n and\n $$ \\max_{\\theta \\in (0, 1)} E_\\theta \\left[\\left(\\delta_1 - \\theta\\right)^2\\right] = [4n]^{-1}.$$ \n\\end{example}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A brief aside about prediction}\n Prediction is an important inferential task and is somewhat related to the previous discussion on precision.\n Consider predicting a quantity $z$ \\textbf{conditional} on data $x$.\n For that  we need $g(z \\mid x, \\theta)$, $f(x\\mid \\theta)$ and $\\pi(\\theta)$.\n Then,\n \\begin{equation}\n  \\label{eq:general_predictive}\n  g_\\pi(z\\mid x) = \\int_{\\boldsymbol{\\Theta}} g(z\\mid x, t) p(t \\mid x)\\,dt\n \\end{equation}\nencodes all of the information brought by the posterior about $z$.\nA special case  is i.i.d prediction:\n\\begin{equation}\n \\label{eq:posterior_predictive_data}\n g(\\tilde{x} \\mid x) = \\int_{\\boldsymbol{\\Theta}} f(\\tilde{x} \\mid t) p(t \\mid x)\\,dt\n\\end{equation}\nis the posterior predictive of the new data $\\tilde{x}$.\n\\begin{idea}[Calibrated priors for prediction]\n\\label{idea:prediction_calibrated_priors}\nThe prior, $\\pi$, can be constructed so as to minimise error in a prediction task. \n\\end{idea}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A neat trick}\nComputing expectations all the time means we have to become familiar with a few tricks to facilitate obtaining approximate answers.\n\\begin{example}[Mixture representation of the Student-t]\nTake $x \\sim \\operatorname{Normal}_p(\\theta, \\boldsymbol{I}_p)$ and put $\\theta \\sim \\operatorname{Student-t}_p(\\alpha, 0, \\tau^2\\boldsymbol{I}_p)$.\nThen $p(\\theta \\mid x)$ does not have a closed-form normalising constant and computing the Bayes estimator under quadratic loss is a chore.\nHowever, we can use the representation\n\\begin{align*}\n \\theta \\mid z &\\sim \\operatorname{Normal}_p(0, \\tau^2z\\boldsymbol{I}_p),\\\\\n z & \\sim \\operatorname{InverseGamma}(\\alpha/2, \\alpha/2),\n\\end{align*}\nto get \n$$ \\theta \\mid x, z \\sim  \\operatorname{Normal}_p\\left(\\frac{x}{ 1+ \\tau^2z}, \\frac{\\tau^2z}{ 1+ \\tau^2z}\\boldsymbol{I}_p\\right) $$ \nThus, the Bayes estimator $\\delta_\\pi(x) = \\int_0^\\infty E_\\pi[\\theta \\mid x, z]p(z \\mid x)\\,dz$ can be computed with a single integral for any dimension $p$. \n\\end{example} \n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Conjugacy is handy!\\footnote{Taken from~\\cite{Robert2007}.}}\n\\begin{center}\n \\includegraphics[scale=0.5]{figures/conjugate_table_expectations.pdf}\n\\end{center}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A worked example}\nWe will stretch our Bayesian muscles with the next problem. \n\\begin{exercise}[Inference for the rate of a Gamma]\n\\label{exercise:rate_gamma_different_losses}\n Let $x \\sim \\operatorname{Gamma}(\\nu, \\theta)$ with $\\nu >0$ known.\n A natural choice of prior is $\\theta \\sim \\operatorname{Gamma}(\\alpha, \\beta)$.\n Find the Bayes estimator under \n $$ L_1(\\delta, \\theta) = \\left(\\delta - \\frac{1}{\\theta}\\right)^2, $$\n and the scale-invariant loss\n $$ L_2(\\delta, \\theta) = \\theta^2 \\left(\\delta - \\frac{1}{\\theta}\\right)^2$$\n \\textit{Hint:} If $X \\sim \\operatorname{Gamma}(\\alpha, \\beta)$, $Y = 1/X \\sim \\operatorname{InverseGamma}(\\alpha, \\beta)$ and $E[Y^k] = \\frac{\\beta^k}{(\\alpha-1)\\cdots(\\alpha-k)}$\n\\end{exercise}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A quick note on quadratic loss}\n Exercise~\\ref{exercise:rate_gamma_different_losses} is a special case of the general situation where \n $$ L(\\delta, \\theta) = w(\\theta) ||\\delta-\\theta||_{\\boldsymbol{G}}^2, $$\n for $\\boldsymbol{G}$ a $p \\times p$ non-negative symmetric matrix.\n In this case, we get\n $$ \\delta_\\pi = \\frac{E_p[w(\\theta)\\theta]}{E_p[w(\\theta)]}. $$\n Please \\textbf{note} that there is no universal justification for quadratic loss other than (sometimes leading to increased) mathematical tractability\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Loss estimation}\n Since the loss function, $L(\\delta(x), \\theta)$ is usually measurable w.r.t the posterior, it can be estimated much the same way as other functionals.\n In particular, if you are feeling particularly eclectic, you can always constructed $\\pi$ such that\n $$ E\\left[E_p[L(\\delta_\\pi(x), \\theta]\\right] \\geq R(\\delta_\\pi(x), \\theta),  \\theta \\in \\boldsymbol{\\Theta}, $$\n i.e. that the estimated loss never underestimates the error resulting from the use of $\\delta_\\pi$, at least in the long run.\n This is called \\textbf{frequentist validity}.\n \\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A nice little problem by Neyman}\nThe following problem is described by Jeffreys as originating with Jerzy Neyman\\footnote{Jerzy Neyman (1894-1981) was a Polish-American statistician, known for with work with Egon Pearson (1895-1980) on the foundations of the null hypothesis significance testing (NHST) framework.}.\n\\begin{exercise}[The tramcar problem]\n \\label{exercise:tramcar}\n A person travelling in a a foreign country has to change trains at a junction, and goes into the town, the existence of which they have only just heard.\n They have no idea of its size.\n The first thing they see is a tramcar numbered $100$.\n Assuming tramcars are numbered consecutively from $1$ onwards, what could one \\textit{infer} about the number $N$ of tramcars in this town?\n\\end{exercise}\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Recommended reading}\n\\begin{itemize}\n  \\item[\\faBook] \\cite{Robert2007}, Ch4.\n%  \\item \n \\item[\\faForward] Next lecture: \\cite{Robert2007} Ch. 5.\n \\end{itemize} \n\\end{frame}\n", "meta": {"hexsha": "9be95614482bd4f36d4bb59ae3c0bc984f9bfda7", "size": 8320, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/lecture_5.tex", "max_stars_repo_name": "lucasmoschen/BayesianStatisticsCourse", "max_stars_repo_head_hexsha": "79fe17dd71fa9638ae4865c8e75eeb0f814d2ccb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-03-17T17:39:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T23:40:56.000Z", "max_issues_repo_path": "slides/lecture_5.tex", "max_issues_repo_name": "anhnguyendepocen/BayesianStatisticsCourse", "max_issues_repo_head_hexsha": "79fe17dd71fa9638ae4865c8e75eeb0f814d2ccb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-24T01:28:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T20:49:10.000Z", "max_forks_repo_path": "slides/lecture_5.tex", "max_forks_repo_name": "anhnguyendepocen/BayesianStatisticsCourse", "max_forks_repo_head_hexsha": "79fe17dd71fa9638ae4865c8e75eeb0f814d2ccb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-05-26T16:28:02.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T12:33:26.000Z", "avg_line_length": 55.4666666667, "max_line_length": 353, "alphanum_fraction": 0.6838942308, "num_tokens": 2526, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.8705972583359806, "lm_q1q2_score": 0.739982561957632}}
{"text": "% !Mode:: \"TeX:UTF-8\"\n% !TEX program = xelatex\n\\section{Question 1}\n\\begin{equation*}\n    \\begin{aligned}\n        \\EE\\中括号{\\log\\小括号{\\frac{S(n\\delta t)}{S_0}}} &= \\EE\\中括号{n\\log d+\\log\\小括号{\\frac{u}{d}}\\sum_{i=1}^nR_i} \\\\\n        &= n\\log d + \\log\\小括号{\\frac{u}{d}}\\sum_{i=1}^n\\EE\\中括号{R_i} \\\\\n        &= n\\log d + \\log\\小括号{\\frac{u}{d}}\\sum_{i=1}^np \\\\\n        &= n\\log d + \\log\\小括号{\\frac{u}{d}}np\n    \\end{aligned}\n\\end{equation*}\n\n\\begin{equation*}\n    \\begin{aligned}\n        \\var\\中括号{\\log\\小括号{\\frac{S(n\\delta t)}{S_0}}} &= \\var\\中括号{n\\log d+\\log\\小括号{\\frac{u}{d}}\\sum_{i=1}^nR_i} \\\\\n        &= \\var\\中括号{\\log\\小括号{\\frac{u}{d}}\\sum_{i=1}^nR_i} \\\\\n        &= \\小括号{\\log\\小括号{\\frac{u}{d}}}^2\\sum_{i=1}^n\\var\\小括号{R_i} \\\\\n        &= \\小括号{\\log\\小括号{\\frac{u}{d}}}^2\\sum_{i=1}^nnp(1-p)\n    \\end{aligned}\n\\end{equation*}\n\n\n\n\\section{Question 2}\n\\subsection{Review}\nThe three papers discussed the method of estimating option prices by simulations. Boyle's paper first introduced the how to use Monte Carlo method to solve option valuation problems, he suggested that we can first generate the returns of the stock and then calculate the option value based on the risk neutrality assumption. 19 years later, Broadie and Glasserman presented two direct method for estimating option prices by simulation, including pathwise method and likelihood ration method. The two methods raise the computational speed and return unbiased estimates. In 2001, F.A.Longstaff and E.S.Schwartz extended the method to American options. The key is to use least squares to estimate the conditional expected payoff, which satisfy the situation where FDM can not be used, such as valuation of American options.\n\n\n\\subsection{From Binomial to Trinomial Method}\nIt's possible if the process allow the stock price at a time point equal to the price at previous time point for a given probability.\n\nThen the trinomial tree is like the form according to Figure~\\ref{F:trinomial-tree}, and it has parameters $u$, $d$, $p_1$, $p_2$, $M$.\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=.5\\textwidth]{figures/2019-12-25-trinomial-tree.png}\n    \\caption{Trinomial Tree}\\label{F:trinomial-tree}\n\\end{figure}\n\n\n\\subsection{Appendix}\n\\paragraph{Paper I:} Phelim P. Boyle, \\emph{Options: A Monte Carlo approach}\\footnote{Journal of Financial Economics, Volume 4, Issue 3, 1977.}.\n\nAbstract: This paper develops a Monte Carlo simulation method for solving option valuation problems. The method simulates the process generating the returns on the underlying asset and invokes the risk neutrality assumption to derive the value of the option. Techniques for improving the efficiency of the method are introduced. Some numerical examples are given to illustrate the procedure and additional applications are suggested.\n\n\\paragraph{Paper II:} Mark Broadie, Paul Glasserman, \\emph{Estimating Security Price Derivatives Using Simulation}\\footnote{Management Science, Volume 42, No. 2 1996.}.\n\nAbstract: Simulation has proved to be a valuable tool for estimating security prices for which simple closed form solutions do not exist. In this paper we present two direct methods, a pathwise method and a likelihood ratio method, for estimating derivatives of security prices using simulation. With the direct methods, the information from a single simulation can be used to estimate multiple derivatives along with a security's price. The main advantage of the direct methods over resimulation is increased computational speed. Another advantage is that the direct methods give unbiased estimates of derivatives, whereas the estimates obtained by resimulation are biased. Computational results are given for both direct methods, and comparisons are made to the standard method of resimulation to estimate derivatives. The methods are illustrated for a path independent model (European options), a path dependent model (Asian options), and a model with multiple state variables (options with stochastic volatility).\n\n\\paragraph{Paper III:} Francis A. Longstaff, Eduardo S. Schwartz, \\emph{Valuing American Options by Simulation: A Simple Least­Squares Approach}\\footnote{The Review of Financial Studies, Volume 14, Issue 1, 2001.}.\n\nAbstract: This article presents a simple yet powerful new approach for approximating the value of American options by simulation. The key to this approach is the use of least squares to estimate the conditional expected payoff to the optionholder from continuation. This makes this approach readily applicable in path­dependent and multifactor situations where traditional finite difference techniques cannot be used. We illustrate this technique with several realistic examples including valuing an option when the underlying asset follows a jump­diffusion process and valuing an American swaption in a 20­factor string model of the term structure.\n", "meta": {"hexsha": "352df0fda5737baf7849b332178bdfac5e16ef49", "size": 4824, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MA216/sections/11.tex", "max_stars_repo_name": "iydon/homework", "max_stars_repo_head_hexsha": "253d4746528ef62d33eba1de0b90dcb17ec587ed", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-10-20T08:18:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-11T12:14:56.000Z", "max_issues_repo_path": "MA216/sections/11.tex", "max_issues_repo_name": "iydon/homework", "max_issues_repo_head_hexsha": "253d4746528ef62d33eba1de0b90dcb17ec587ed", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2022-01-13T03:04:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T00:49:10.000Z", "max_forks_repo_path": "MA216/sections/11.tex", "max_forks_repo_name": "iydon/homework", "max_forks_repo_head_hexsha": "253d4746528ef62d33eba1de0b90dcb17ec587ed", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-11-02T05:46:01.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-12T23:11:28.000Z", "avg_line_length": 92.7692307692, "max_line_length": 1017, "alphanum_fraction": 0.7638888889, "num_tokens": 1256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7399618582620135}}
{"text": "\n\\section{Gridworld [15 pts]}\n\nConsider the following grid environment. Starting from any unshaded square, you can move up, down, left, or right. Actions are deterministic and always succeed (e.g. going left from state 16 goes to state 15) unless they will cause the agent to run into a wall. The thicker edges indicate walls, and attempting to move in the direction of a wall results in staying in the same square (e.g. going in any direction other than left from state 16 stays in 16). Taking any action from the green target square (no. 12) earns a reward of $r_g$ (so $r(12, a)$ = $r_g$ $\\forall a$) and ends the episode . Taking any action from the red square of death (no. 5) earns a reward of $r_r$ (so $r(5, a)$ = $r_r$ $\\forall a$) and ends the episode. Otherwise, from every other square, taking any action is associated with a reward $r_s \\in \\{-1, 0, +1\\}$ (even if the action results in the agent staying in the same square). Assume the discount factor $\\gamma = 1$, $r_g = +5$, and $r_r = -5$ unless otherwise specified.\n\n\\begin{figure}[h]\n  \\centering\n    \\includegraphics[width=0.3\\textwidth]{tex/grid.png}\n  \t\\label{fig:grid}\n\\end{figure}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item (3pts) Define the value of $r_s$ that would cause the optimal policy to return the shortest path to the green target square (no. 12). Using this $r_s$, find the optimal value for each square.\n\n\\textbf{Answer:}\n\n\\begin{equation}\nr_s = -1\n\\end{equation}\n\n\\begin{equation}\n\\begin{bmatrix}\n0 & 1 & 2 & 3 \\\\\n-5& 2 & 3 & 4 \\\\\n2 & 3 & 4 & 5 \\\\\n1 & 0& -1& -2\n\\end{bmatrix}\n\\end{equation}\n\n\\item (3pts) Lets refer to the value function derived in (a) as $V^{\\pi_g}_{old}$ and the policy as $\\pi_g$. Suppose we are now in a new gridworld where all the rewards ($r_s$, $r_g$, and $r_r$) have $+2$ added to them. Consider still following $\\pi_g$ of the original gridworld, what will the new values $V^{\\pi_g}_{new}$ be in this second gridworld?\n\n\\textbf{Answer:}\n\n\\begin{equation}\n\\begin{bmatrix}\n12 & 11 & 10 & 9 \\\\\n-3 & 10 & 9  & 8 \\\\\n10 & 9  & 8  & 7 \\\\\n11 & 12 & 13 & 14\n\\end{bmatrix}\n\\end{equation}\n\n\\item (3pts) Consider a general MDP with rewards, and transitions. Consider a discount factor of $\\gamma$. For this case assume that the horizon is infinite (so there is no termination). A policy $\\pi$ in this MDP induces a value function $V^\\pi$ (lets refer to this as $V^\\pi_{old}$). Now suppose we have a new MDP where the only difference is that all rewards have a constant $c$ added to them. Can you come up with an expression for the new value function $V^\\pi_{new}$ induced by $\\pi$ in this second MDP in terms of $V^\\pi_{old}$, $c$, and $\\gamma$?\n\n\\textbf{Answer:}\n\n\\begin{equation}\n\\begin{split}\nV^\\pi_{old}(s) & = \\Ex_{\\pi}[\\sum_{t=0}^{\\infty} \\gamma^{t}r_t|s_0=s] \\\\\nV^\\pi_{new}(s) & = \\Ex_{\\pi}[\\sum_{t=0}^{\\infty}\\gamma^{t}(r_t + c)|s_0=s] \\\\\n               & = \\Ex_{\\pi}[\\sum_{t=0}^{\\infty}\\gamma^{t}r_t|s_0=s] + c\\sum_{t=0}^{\\infty}\\gamma^{t} \\\\\n               & = V^\\pi_{old}(s) + \\frac{c}{1-\\gamma}\n\\end{split}\n\\end{equation}\n\n\n\n\\item (2pts) Lets go back to our gridworld from (a) with the default values for $r_g$, $r_r$, $\\gamma$ and with the value you specified for $r_s$. Suppose we now derived a second gridworld by adding a constant $c$ to all rewards ($r_s$, $r_g$, and $r_r$) such that $r_s = +2$. How does the optimal policy change (Just give a one or two sentence description)? What do the values of the unshaded squares become?\n\n\\textbf{Answer:}\n\nIt will become looping at states other than the terminate states, because each step will gain positive reward value.\n\nUnshaded squares will become value $+\\infty$.\n\n\\item (2pts) Now take the second gridworld from part (d) and change $\\gamma$ such that $0 < \\gamma < 1$. Can the optimal policy change and does it depend on your choice of gamma? (A brief description is sufficient, no formal proof or mathematical analysis required).\n\n\\textbf{Answer:}\n\nIf $\\gamma$ is close to $1$, the result is same, all unshaded squares will have value $+\\infty$ and optimal policy is keep looping.\n\nif $\\gamma$ is equal to some value closing to $0$, at some point optimal policy will be able to find a shortest path to green square.\n\n\\item (2pts) Lets go back to our gridworld from (a) with the default values for $r_g$, $r_r$, $\\gamma$ and with the value you specified for $r_s$. In this gridworld, our optimal policy from any unshaded square never terminates in the red square. Now suppose $r_s$ can take on any real, non-infinite value and is not restricted to $\\{+1, 0, -1\\}$ anymore. Give a value of $r_s$ such that there are unshaded squares starting from which following the optimal policy results in termination in the red square.\n\n\\textbf{Answer:}\n\n\\begin{equation}\nr_s \\leq -5\n\\end{equation}\n\n\n\\end{enumerate}\n", "meta": {"hexsha": "218675f4cf6571d297c61045b0c59daf5985cda5", "size": 4770, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment1_written/tex/Q_Grid.tex", "max_stars_repo_name": "ksang/cs234-assignments", "max_stars_repo_head_hexsha": "dc9a2238c7e28db7ae5eaebde6d776a2e5a59ebc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-12-25T12:29:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T12:53:13.000Z", "max_issues_repo_path": "assignment1_written/tex/Q_Grid.tex", "max_issues_repo_name": "ksang/cs234-assignments", "max_issues_repo_head_hexsha": "dc9a2238c7e28db7ae5eaebde6d776a2e5a59ebc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-11-13T17:43:49.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T02:04:12.000Z", "max_forks_repo_path": "assignment1_written/tex/Q_Grid.tex", "max_forks_repo_name": "ksang/cs234-assignments", "max_forks_repo_head_hexsha": "dc9a2238c7e28db7ae5eaebde6d776a2e5a59ebc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-02T01:34:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-02T01:34:47.000Z", "avg_line_length": 56.7857142857, "max_line_length": 1003, "alphanum_fraction": 0.6997903564, "num_tokens": 1452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.890294223211224, "lm_q1q2_score": 0.7399618541704294}}
{"text": "\n\\subsection{Projections}\n\nA projection is a linear map which if applied again returns the original result.\n\nA projection can drop a dimension for example.\n\t\n", "meta": {"hexsha": "b2e42031eda296b494fafc4d63eea43e7d62c677", "size": 158, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/endomorphisms/01-03-projection.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/endomorphisms/01-03-projection.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/endomorphisms/01-03-projection.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.75, "max_line_length": 80, "alphanum_fraction": 0.7911392405, "num_tokens": 32, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7399529640593895}}
{"text": "\\lab{GMRES}{GMRES}\n\\label{lab:GMRES}\n\\objective{In this lab we will learn how to use the GMRES algorithm.}\n\nThe GMRES (``Generalized Minimal Residuals\") algorithm is an effecient way to solve large linear systems.\nIt is an iterative method that uses Krylov subspaces to reduce a high-dimensional problem to a sequence of smaller dimensional\nproblems.\n\n\\begin{comment}\n\\section*{The Arnoldi Iteration and Approximate Solutions}\nThe basic idea of GMRES is as follows.\nLet $A$ be an $m\\times m$ matrix (real or complex), where $m$ is very large,\nand let $b \\in \\mathbb{F}^m$ ($\\mathbb{F}$ may either be the real or complex numbers).\nLet $\\mathcal{K}_n$ denote the order-$n$ Krylov subspace generated by $A$ and $b$.\nIn each iteration, we consider the least squares problem\n\\begin{equation}\n\\underset{x \\in \\mathcal{K}_n}{\\text{minimize}}\\qquad \\|b-Ax\\|_2.\n\\label{eq:GMRES_lstsq1}\n\\end{equation}\nNow if $x \\in K_n$, then $x$ can be expressed as a linear combination of basis vectors $b, Ab, \\ldots, A^{n-1}b$, i.e.\n\\[\nx = y_1b + y_2Ab + \\cdots + y_nA^{n-1}b.\n\\]\nIf we let $K_n$ be the matrix whose columns are $b, Ab, A^{2}b, \\cdots, A^{n-1}b$, then we can write this simply as\n$x = K_n y$.\nThen the solution of the least squares problem is the vector $K_{n}y$ such that $\\|b-A K_{n}y\\|_2$ is minimized.\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{LeastSquares}\n\\caption{GMRES involves solving the least squares problem repeatedly.}\n\\end{figure}\n\nThe major drawback of this approach is that it relies on the matrix $K_n$, which tends to be ill-conditioned due to its columns\nbeing far from orthogonal (as discussed in Lab \\ref{lab:kry_arnoldi}).\n%To see this, suppose there is an eigenbasis for $A$ with associated eigenvalues, and suppose $\\lambda$ is the largest eigenvalue.\n%Then $\\lambda^n$ is an eigenvalue of $A^n$.\n%Since $\\lambda$ is bigger than the other eigenvalues of $A$, $\\lambda^n$ may be much, much bigger than the other eigenvalues of $A^n$,\n%which are simply the eigenvalues of $A$ raised to the $n$th power.\n%Thus the eigenvector associated with $\\lambda$ often begins to dominate as we progress, with the end result being that the columns of\n%$K_n$ become nearly linearly dependent.\nThe easiest fix in this situation is to use the Arnoldi iteration so that we have an orthonormal basis for $\\mathcal{K}_n$ to work with.\nNot only does this alleviate the problem of ill-conditioning, it also allows us to optimize in other ways, due to the special\nstructure of the matrices produced.\n\nLet $q_1,\\ldots, q_n$ be the orthonormal basis for $\\mathcal{K}_n$ obtained by the Arnoldi iteration, and let $Q_n$ be the matrix\nhaving these vectors as its columns.\nRecall that $q_1 = b/\\|b\\|_2$.\nFinally, let $H_n$ be the $(n+1)\\times n$ upper Hessenberg matrix generated by the Arnoldi iteration, and let $e_1=(1,0,\\cdots,0)$.\n\nIn this orthonormal basis, $x \\in \\mathcal{K}_n$ implies that there is some vector $y$ such that $x = Q_n y$.\nFurther, it is not hard to check that the matrices generated by the Arnoldi iteration satisfy the equation\n\\[\nAQ_n = Q_{n+1}H_n.\n\\]\nWe also have the identity\n\\[\nb = \\|b\\|_2q_1 = \\|b\\|_2Q_{n+1}e_1.\n\\]\nPutting all of this together, we can rewrite the objective function of our least squares problem as follows:\n\\begin{align*}\n\\|b - Ax\\|_2 &= \\|Ax - b\\|_2\\\\\n&= \\|AQ_ny - b\\|_2\\\\\n&= \\|Q_{n+1}H_ny - \\left(\\|b\\|_2Q_{n+1}e_1\\right)\\|_2\\\\\n&= \\|Q_{n+1}\\left(H_n y - \\|b\\|_2e_1\\right)\\|_2.\n\\end{align*}\n\nThe matrix $Q_{n+1}$ has orthonormal columns, but it does not have enough columns to be a unitary matrix.\nLet us extend the set $q_1,\\ldots, q_{n+1}$ to an orthonormal basis $q_1,\\ldots,q_{n+1},q_{n+2},\\ldots,q_m$\nof our space, and let $Q'$ be the matrix whose columns are equal to these vectors.\nThen $Q'$ is now a unitary matrix, and hence preserves the norm, i.e. $\\|Q'z\\|_2 = \\|z\\|_2$ for all $z \\in \\mathbb{F}^m$.\nGiven $x \\in \\mathbb{F}^{n+1}$, if we define $x' \\in \\mathbb{F}^m$ to be\n\\[\nx' =\n\\begin{bmatrix}\n  x\\\\\n  0\\\\\n  \\vdots\\\\\n  0\n\\end{bmatrix},\n\\]\nthen you can easily check that\n\\[\nQ'x' = Q_{n+1}x.\n\\]\nFrom this, we deduce that\n\\begin{align*}\n\\|Q_{n+1}x\\|_2 &= \\|Q'x'\\|_2\\\\\n& = \\|x'\\|_2\\\\\n&= \\|x\\|_2.\n\\end{align*}\nHence, we conclude that\n\\[\n\\|Q_{n+1}\\left(H_n y - \\|b\\|_2e_1\\right)\\|_2 = \\|H_n y - \\|b\\|_2e_1\\|_2.\n\\]\nThus, the least squares problem given by \\ref{eq:GMRES_lstsq1} is equivalent to the problem\n\\begin{equation}\n\\underset{y \\in \\mathbb{F}^n}{\\text{minimize}}\\qquad \\|H_n y - \\|b\\|_2e_1\\|_2.\n\\label{eq:GMRES_lstsq2}\n\\end{equation}\nIf $y$ is the solution to this problem, then the solution to \\ref{eq:GMRES_lstsq1}, and hence an approximate\nsolution to $Ax = b$ is given by $x=Q_n y$.\n\nWe can measure how good our approximate solution is by considering the residual, which we define to be\n\\[\n\\frac{\\|Ax-b\\|_2}{\\|b\\|_2}.\n\\]\nWe can express this residual in terms of $y$ as follows:\n\\begin{equation}\n\\frac{\\|H_n y - \\|b\\|_2e_1\\|_2}{\\|b\\|_2}.\n\\label{eq:GMRES_residual}\n\\end{equation}\n\\end{comment}\n\n\\section*{The GMRES Algorithm}\nLet $A$ be an invertible $m \\times m$ matrix and let $\\b$ be an $m$-vector.\nLet $\\mathcal{K}_n(A, \\b)$ be the order-$n$ Krylov subspace generated by $A$ and $\\b$.\nThe idea of the GMRES algorithm is that instead of solving $A\\x = \\b$ directly, we solve the least squares problem\n\\begin{equation}\n\\underset{\\x \\in \\mathcal{K}_n}{\\text{minimize}}\\qquad \\|\\b-A\\x\\|_2\n\\label{eq:GMRES_lstsq1}\n\\end{equation}\nfor increasing values of $n$.\nAt each iteration, we compute the \\emph{residual}, or error between the least squares solution and a true solution of $A\\x = \\b$.\nThe algorithm returns when this residual is sufficiently small.\nIn good circumstances, this will happen when $n$ is still much less than $m$.\n\nThe GMRES algorithm is integrated with the Arnoldi iteration for numerical stabiility, so that instead of solving \\eqref{eq:GMRES_lstsq1}, at the $n^{th}$ iteration we solve\n\\begin{equation}\n\\underset{\\y \\in \\mathbb{F}^n}{\\text{minimize}}\\qquad \\|H_n \\y - \\|\\b\\|_2\\e_1\\|_2.\n\\label{eq:GMRES_lstsq2}\n\\end{equation}\nHere, $H_n$ is the $(n+1)\\times n$ upper Hessenberg matrix generated by the Arnoldi iteration and $\\e_1$ is the vector $(1, 0, \\ldots, 0)$ of length $n+1$.\nIf $\\y$ is the minimizer for the $n^{th}$ iteration of \\eqref{eq:GMRES_lstsq2}, then the residual is\n\\begin{equation}\n\\frac{\\|H_n \\y - \\|\\b\\|_2\\e_1\\|_2}{\\|\\b\\|_2},\n\\label{eq:GMRES_residual}\n\\end{equation}\nand the corresponding minimizer for \\eqref{eq:GMRES_lstsq1} is $Q_n\\y$, where $Q_n$ is the matrix whose columns are $\\q_1, \\ldots, \\q_n$ as defined by the Arnoldi iteration.\nThis algorithm is outlined in Algorithm \\ref{alg:gmres}.\nFor a complete derivation see [TODO: ref textbook].\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{GMRES}{$A, \\b, k, tol$}\n\t\\State $Q \\gets \\empty{\\size{\\b}}{k+1}$\t\t\t\\Comment{Initialize}\n\t\\State $H \\gets \\zeros{k+1}{ k}$\n\t\\State $Q[:,0] = \\b/\\norm{\\b}_2$\n    \\For{$n=1\\ldots k$}\n        \\State Set entries of $Q$ and $H$ as in Arnoldi iteration\n        \\State Calculate least squares solution $\\y$ of \\ref{eq:GMRES_lstsq2}.\n        \\State Calculate the residual $res$ given by Equation \\ref{eq:GMRES_residual}.\n        \\If{$res < tol$}\n            \\State \\pseudoli{return} $Q[:,n+1]\\y, \\,\\, res$\n        \\EndIf\n    \\EndFor\n    \\State \\pseudoli{return} $Q[:,n+1]\\y, \\,\\, res$\t\t\t\t\t\t\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The GMRES algorithm. This algorithm operates on a vector $\\b$ and matrix $A$. \nIt iterates $k$ times or until the residual is less than $tol$, returning an approximate solution to $A\\x=\\b$ and the error in this approximation.}\n\\label{alg:gmres}\n\\end{algorithm}\n\n%\\begin{warn}\n%The Python function \\li{linalg.lstsq} solves a least squares problem, returning not only the vector, $y$, but also the residual,\n%the rank of the matrix, and the singular values.\n%Be careful when you write your code that you access the correct results and don't just assume that \\li{linalg.lstsq} returns the\n%vector that you want.\n%The least squares solver also returns a residual, but it's not the number we reference in this book, so be sure to take the square\n%root of the residual reported by the solver and divide by $\\norm{b}$ to get $res=\\norm{Ax-b}/\\norm{b}$.\n%\\end{warn}\n\n% Hint: explain how to find lstsq to find the residual?\n\\begin{problem}\nUse Algorithm \\ref{alg:gmres} to complete the following Python function implementing the GMRES algorithm.\n\\begin{lstlisting}\ndef gmres(b, Amul, k=100, tol=1E-8):\n    '''Use the GMRES algorithm to approximate the solution to Ax=b, where A is the linear operator defined by `Amul'.\n    \n    INPUTS:\n    b    - A NumPy array.\n    Amul - A function handle. Should describe a linear operator.\n    k    - Maximum number of iterations of the GMRES algorithm. Defaults \n           to 100.\n    tol  - Stop iterating if the residual is less than `tol'. Defaults to \n           1E-8.\n    \n    RETURN:\n    Return (y, res) where `y' is an approximate solution to Ax=b and `res' \n    is the residual.\n    \n    Examples:\n    >>> A = np.array([[1,0,0],[0,2,0],[0,0,3]])\n    >>> Amul = lambda x: A.dot(x)\n    >>> b = np.array([1, 4, 6])\n    >>> gmres(Amul, b)\n    (array([ 1.,  2.,  2.]), 1.5083413465299765e-17)\n    '''\n\\end{lstlisting}\nYou make make the following assumptions:\n\\begin{enumerate}\n\\item The input \\li{b} is a real array and the function \\li{Amul()} always outputs real arrays.\n\\item The vectors found by the Arnoldi iteration will never be zero. In other words, $\\b$ will never be in a proper invariant subspace of $A$.\n\\end{enumerate}\n\nHint: Use \\li{scipy.linalg.lstsq()} to solve the least squares problem.\n\\label{prob:MyGMRES}\n\\end{problem}\n\n\n\n\\subsection*{Convergence of GMRES}\nAt the $n$-th iteration, GMRES computes the best approximate solution $\\x \\in \\mathcal{K}_n$ to $A\\x = \\b$.\nIf $A$ is full rank, then $\\mathcal{K}_m = \\mathbb{F}^m$, so the $m^{th}$ iteration will always return an exact answer.\nHowever, we say the algorithm converges after $n$ steps if the $n^{th}$ residual is sufficiently small.\n\nThe rate of convergence of GMRES depends on the eigenvalues of $A$.\n\n\\begin{problem}\\label{prob:plot_gmres}\nFinish the following Python function by modifying your solution to Problem \\ref{prob:MyGMRES}.\n\n\\begin{lstlisting}\ndef plot_gmres(b, A, tol=1E-8):\n    '''Use the GMRES algorithm to approximate the solution to Ax=b.\n    \n    INPUTS:\n    b   - A 1-D NumPy array of length m.\n    A   - A 2-D NumPy array of shape mxm.\n    tol - Stop iterating and create the desired plots if the residual is\n          less than `tol'. Defaults to 1E-8.\n    \n    OUTPUT:\n    Follow the GMRES algorithm until the residual is less than tol, for a \n    maximum of m iterations. Then create the two following plots (subplots\n    of a single figure):\n     \n    1. Plot the eigenvalues of A in the complex plane\n    \n    2. Plot the convergence of the GMRES algorithm by plotting the\n    iteration number on the x-axis and the residual on the y-axis.\n    Use a log scale on the y-axis.\n    '''\n\\end{lstlisting}\n\nUse this function to investigate the convergence of GMRES as follows. \nDefine an $m\\times m$ matrix\n\\[A_n = nI+P,\\]\n where $I$ is the $m \\times m$ identity matrix and $P$ is a $m \\times m$ matrix of numbers from a random normal distribution with mean 0 and standard deviation $1/(2\\sqrt{m})$. \n Call \\li{plot_gmres} on $A_n$ for $n=-4,-2,0,2,4$. Use $m=200$ and let \\li{b} be an array of ones. What do you conjecture about the convergence of the GMRES algorithm?\n \n Hints:\n \\begin{enumerate}\n \\item Create a plot with a log scale on the y-axis with the function \\li{plt.semilogy()}.\n \\item Create a matrix with entries from a random normal distribution with \\li{np.random.rand()}.\n \\item Output for $n=2$, $m=200$ is in Figure \\ref{fig:plot_gmres} below.\n \\end{enumerate}\nIdeas for this problem were taken from Example 35.1 on p.271 of \\cite{Trefethen1997}.\n\n\\begin{figure}[H]\n\\includegraphics[width=.7\\textwidth]{plot_gmres.pdf}\n\\caption{The left plot is the eigenvalues of the matrix $A_2$, which is defined in Problem \\ref{prob:plot_gmres}.\nThe right plot is the convergence of the GMRES algorithm on $A_2$ with starting vector $\\b = (1, 1, \\ldots, 1)$.\nThis figure is one possible output of the function \\li{plot_gmres()}.}\n\\label{fig:plot_gmres}\n\\end{figure}\n\\end{problem}\n\n\n\\section*{Improving GMRES}\nThere are many ways to make the GMRES algorithm more robust and efficient.\n\n\n\\subsection*{Breakdowns in GMRES}\nOne of the selling points of GMRES is that it can't break down unless it has reached an exact solution.\n\nThe only way GMRES could break down is if a vector found by the Arnoldi iteration is 0.\nThat is, suppose, we have already computed \n\\[\\mathcal{K}_n(A, \\b) = \\text{span}\\{\\b, A\\b, \\ldots, A^{n-1}\\b\\} = \\text{span}\\{\\q_1, \\ldots, \\q_n\\}.\\]\nWe next compute $A^n\\b$ and orthogonalize it against $\\mathcal{K}_n(A, \\b)$, yielding $\\q_{n+1}$.\nBut if $A^n\\b \\in \\mathcal{K}_n(A,\\b)$ then $\\q_{n+1}$ will be 0, and our algorithm will break when we try to normalize $\\q_{n+1}$.\n\nIn this situation, the least squares solution to \\eqref{eq:GMRES_lstsq2} is an \\emph{exact} solution to $A\\x=\\b$. \nIn other words, $\\b$ is in the $\\text{span}\\{\\q_1, \\ldots, \\q_n\\}$.\n\n\\begin{problem}\nUpdate your solution to Problem \\ref{prob:MyGMRES} to deal with the scenario described above.\nHint: Use something similar to lines 11-12 of the Arnoldi algorithm in Lab \\ref{lab:kry_arnoldi}.\n\\label{prob:GMRES3}\n\\end{problem}\n\n% This section is poorly written. It is vague, not mathematically precise.\n% If we ever want to include it, then it needs a lot of work.\n\\begin{comment}\n\\subsection*{Optimizing Least-Squares for GMRES (Optional)}\nThe Hessenberg structure and the Krylov subspace relations enable us to save time on the least-squares part of the problem if we use QR factorization.\nObserve that if $H_n$ can be factored as $Q_n R_n$, where $Q_n$ is not the same matrix as above and $R_n$ is invertible upper triangular, we may solve the least squares problem by simply solving $R_n x_n=\\norm{b} Q_{n}^{H}e_1$ via back substitution.\nThere are two ways in which we can speed up this process.\nFirst, we take advantage of the Hessenberg structure by using the techniques from Problem \\ref{prob:givens_hessenberg} in Lab \\ref{lab:givens}.\nRecall that the technique in this situation was to use Givens rotations to eliminate the subdiagonal elements one at a time.\nThis process, which was part of a previous lab, reduces the operation count from $O(n^3)$ to $O(n^2)$.\nThe second speedup comes from the fact that we already know the QR factorization for $H_{n-1}$ from the previous step of the algorithm.\nThis means that we can simply update the QR factorization from the previous step rather than computing it all over again.\nSince $H_{n}$ has only one more column and row than $H_{n-1},$ all we need to do is update the last column by performing all previous Givens rotations on just the last column of $H_n$, which requires only $O(n)$ work.\nThen we perform one final Givens rotation on $H_n$ to eliminate the new subdiagonal entry which was not present in $H_{n-1}$.\nThus, the QR factorization of $H_n$ can be reduced from an $O(n^3)$ process to only $O(n)$ using these special techniques.\n\nThe back substitution necessary to solve the least squares problem can also be reduced to an operation of $O(n)$.\n\nThe speedup from $O(n^3)$ to $O(n)$ is very good, but it can only partially alleviate the problems that come with a problem that is ill-suited for GMRES.\nIt may still be useful because it allows us to perform more iterations in a reasonable amount of time.\nIn many situations, the simple technique of the next section will keep $n$ low enough that the optimizations from this section are not critical.\n\n \\begin{problem}\n \\label{prob:GMRES2}\n (Optional) Modify MyGMRES to incorporate these optimizations, and call this program MyGMRES1.\n Run both programs on a series of five random $100\\times 100$ matrices and compare the time each requires.\n Are the gains substantial?\n Try it again matrices of size $1000\\times 1000$ or larger, and see how substantial the difference becomes.\n Try the same thing using the techniqes of the next section.\n Explain why the difference in performance is less dramatic this time.\n \\end{problem}\n\\end{comment}\n\n\\subsection*{GMRES with restarts}\nThe first few iterations of GMRES have low spatial and temporal complexity. \nHowever, as $k$ increases, the $k^{th}$ iteration of GMRES becomes more expensive in both time and memory.\nIn fact, computing the $k^{th}$ iteration of GMRES for very large $k$ can be prohibitively complex.\n\nThis issue is addressed by using GMRES(k), or GMRES with restarts.\nWhen $k$ becomes large, this algorithm restarts GMRES but with an improved initial guess.\nGMRES with restarts is outlined in Algorithm \\ref{alg:gmres_k}.\n\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{GMRES(k)}{$A, \\b, k, tol, restarts$}\n  \\State $r \\gets 0$ \\Comment{Restart counter}\n  \\State $Q \\gets \\empty{\\size{b}}{k+1}$\t\t\t\\Comment{Initialize}\n\\State $H \\gets \\zeros{k+1}{ k}$\n   \\While{$r \\leq restarts$}\n\t\\State{ Perform the GMRES algorithm, obtaining a least squares solution $\\y$}\n\t\\State{ If the desired tolerance was reached, return. Otherwise, continue.}\n    \\State $b \\gets Q[:,k+1]\\y$\n    \\State $r \\gets r+1$\n    \\EndWhile\n    \\State \\pseudoli{return} $Q[:,k+1]\\y, \\,\\, res$\t\t\\Comment{Return the approximate solution and the residual}\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The GMRES(k) algorithm. This algorithm performs GMRES on a vector $\\b$ and matrix $A$. It iterates $k$ times before restarting. \nIt terminates after $restarts$ restarts or when the residual is less than $tol$, returning an approximate solution to $A\\x=\\b$ and the error in this approximation. }\n\\label{alg:gmres_k}\n\\end{algorithm}\n\n\n\n\n\nThe algorithm GMRES(k) will always have manageable spatial and temporal complexity, but it is less reliable than GMRES.\nIf the true solution $\\x$ to $A\\x=\\b$ is nearly orthogonal to the Krylov subspaces $\\mathcal{K}_n(A, \\b)$ for $n\\leq k$, then GMRES(k) could converge very slowly or not at all.\n\n\\begin{problem}\nImplement Algorithm \\ref{alg:gmres_k} with the following function.\n\\begin{lstlisting}\ndef gmres_k(b, Amul, k=100, tol=1E-8, restarts=50):\n    '''Use the GMRES(k) algorithm to approximate the solution to Ax=b, where A is the linear operator defined by `Amul'.\n    \n    INPUTS:\n    b        - A NumPy array.\n    Amul     - A function handle. Should describe a linear operator.\n    k        - Maximum number of iterations of the GMRES algorithm before \n              restarting. Defaults to 100.\n    tol      - Stop iterating if the residual is less than `tol'. Defaults \n              to 1E-8.\n    restarts - Maximum number of restarts. Defaults to 50.\n    \n    RETURN:\n    Return (y, res) where `y' is an approximate solution to Ax=b and `res' \n    is the residual.\n    '''\n\\end{lstlisting}\n\nCompare the speed of \\li{gmres()} from Problem \\ref{prob:MyGMRES} and \\li{gmres_k()} on the matrices in Problem \\ref{prob:plot_gmres}.\n\\label{prob:GMRES3}\n\\end{problem}\n\n\\section*{GMRES in SciPy}\nThe GMRES algorithm is implemented in SciPy as the function \\li{scipy.sparse.linalg.gmres()}.\nHere we use this function to solve $A\\x=\\b$ where $A$ is a random $300 \\times 300$ matrix and $\\b$ is a random vector.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import sparse as spar\n>>> from scipy import linalg as la\n>>>\n>>> A = np.random.rand(300, 300)\n>>> b = np.random(300)\n>>> x, info = spar.linalg.gmres(A, b)\n>>> info\n3000\n\\end{lstlisting}\n\nThe function outputs two objects: the approximate solution \\li{x} and a constant \\li{info} telling if the function converged.\nIf \\li{info=0} then convergence occured; if \\li{info} is positive then it equals the number of iterations performed.\nIn this case, the function performed 3000 iterations of GMRES before returning the approximate solution \\li{x}.\nWe can check how close the solution is.\n\\begin{lstlisting}\n>>> la.norm(A.dot(x)-b)\n4.744196381683801\n\\end{lstlisting}\n\nWe can get a better approximation using GMRES with restarts. \n\\begin{lstlisting}\n>>> # Restart after 1000 iterations\n>>> x, info = spar.linalg.gmres(A, b, restart=1000)\n>>> info\n0\n>>> la.norm(A.dot(x)-b)\n1.0280404494143551e-12\n\\end{lstlisting}\nThis time, the returned approximation \\li{x} is about as close to a true solution as we could hope for.\n\n\n", "meta": {"hexsha": "732326a86b1c2dbd2ee1e41d08bd804451cbf943", "size": 20315, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/GMRES/GMRES.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Labs/GMRES/GMRES.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/GMRES/GMRES.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 48.1398104265, "max_line_length": 249, "alphanum_fraction": 0.7136598572, "num_tokens": 6166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.8354835432479663, "lm_q1q2_score": 0.7399305192355232}}
{"text": "\\lab{Numerical Methods for Initial Value Problems; Harmonic Oscillators}{Numerical Methods for Initial Value Problems; Harmonic Oscillators}\n\\label{lab:ivp}\n\n\\objective{Implement several basic numerical methods for initial value problems (IVPs), and use them to study harmonic oscillators.}\n\n\\section*{Methods for Initial Value Problems}\nConsider the initial value problem\n\\begin{align}\n\t\\begin{split}\ny' &= f(x,y),\\quad a \\leq x \\leq b, \\\\\ny(a) &= y_0, \n\t\\end{split}\\label{ivp:generic}\n\\end{align}\nwhere $f$ is a continuous function. \nA solution of \\eqref{ivp:generic} is a continuously differentiable function $y(x)$ that satisfies the equation $y' = f(x,y)$ on the interval $[a,b]$ and for which $y(a) = y_0$. \nIn this lab we will focus on numerical methods for approximating $y(x)$, and sidestep the important mathematical problem of verifying that \\eqref{ivp:generic} has a unique solution.\n\nFor many IVPs it is impossible to find a closed-form, analytic expression for the solution.\nWhen there is a closed-form expression for the solution, it may not be very useful.\nIn both cases, numerical methods must be relied on to understand the solutions of \\eqref{ivp:generic}. \n\nAs an example, consider the initial value problem\n\\begin{align}\n\t\\begin{split}\ny'(x) &= \\sin y(x), \\\\\ny(0) &= y_0.\n\t\\end{split}\\label{ivp:example}\n\\end{align}\nThe solution $y(x)$ is defined implicitly by\n\\[x = \\ln \\left|\\frac{\\cos y_0 + \\cot y_0}{\\csc y + \\cot y} \\right|.\\]\nThis analytic expression does not provide much intuition, so we turn to a combination of qualitative and numerical methods. \nSince $\\sin (n \\pi) = 0$, this differential equation has constant solutions $y_n(x) = n \\pi,$ $n \\in \\mathbb{N}$. \nWe can also use an IVP solver to numerically approximate solutions for several other initial values. \nAfter plotting these solutions (see Figure \\ref{ivp:int_curves}), it becomes obvious how solutions of \\eqref{ivp:example} behave in general.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{example.pdf}\n\\caption{Several solutions of \\eqref{ivp:example}, using Numpy's IVP solver \\li{dopri5}. }\n\\label{ivp:int_curves}\n\\end{figure}\n\n\n\\section*{Numerical Methods}\nNumerical methods for solving initial value problems require us to approximate the solution on a set of grid points $a = x_0< x_1<\\hdots< x_n = b$ in our interval.  \nFor simplicity we will assume that each of the $n$ subintervals $[x_{i-1},x_i]$ has equal length $h = (b-a)/n$. $h$ is called the \\textit{step size}. \nWe then look for values $y_0, y_1, \\hdots, y_n$ that approximate the solution at the grid points.\nFor each $i$, Taylor's theorem says that\n\\begin{align*}\ny(x_{i+1}) &= y(x_{i}) + h y'(x_i) + \\frac{h^2}{2} y''(\\xi_i)\\text{ for some }\\xi_i \\in [x_i,x_{i+1}].\n\\end{align*}\nThe quantity $\\frac{h^2}{2} y''(\\xi_i)$ is negligible for small $h$, and thus\n\\begin{align*}\ny(x_{i+1}) &\\approx y(x_{i}) + h y'(x_i)  ,\\\\\n&\\approx y(x_{i}) + h f(x_i,y(x_i)).\n\\end{align*}\nThis approximation leads to a method called Euler's method: Letting $y_0 = y(a)$, $y_{i+1}$ is given by $y_{i+1} = y_i +hf(x_i,y_i)$ for $i = 0, 1, \\hdots, n-1$.\nEuler's method is a first order method, with error $\\mathcal{O}(h^1)$.\n% \\begin{enumerate}\n% \\item Let $y_0 = y(a)$.\n% \\item For $i = 0, 1, \\hdots, n-1$, let $y_{i+1} = y_i +hf(x_i,y_i)$.\n% \\end{enumerate}\n\nA similar application of Taylor's theorem shows that\n\\begin{align*}\ny(x_{i}) &= y(x_{i+1}) - h y'(x_{i+1}) + \\frac{h^2}{2} y''(\\xi_i) \\text{ for some } \\xi_i \\in [x_i,x_{i+1}]; \\\\\n\\end{align*}\nthus for small $h$\n\\begin{align*}\ny(x_{i+1}) &\\approx  y(x_{i}) + h f(x_{i+1},y(x_{i+1})).\n\\end{align*}\nThis approximation leads to another first order method called the backwards Euler method: Letting $y_0 = y(a)$, for $i = 0, \\hdots, n-1$ we  solve  $y_{i} = y_{i+1}-hf(x_{i+1},y_{i+1})$ for $y_{i+1}$.\n\nNote that for both the Euler and backwards Euler methods, only $y_i, f,$ and other points in the interval $[x_i, x_{i+1}]$ are needed to find $y_{i+1}$. \nBecause of this, they are called \\textit{one-step methods}.\n\nEuler's method is an \\textit{explicit method}. \nThe backwards Euler method is an \\textit{implicit method} since an equation must be solved at each step to find $y_{i+1}$. \nExplicit and implicit methods each have advantages and disadvantages. \nWhile implicit methods require an equation to be solved at each time step, they often have better stability properties than explicit methods.\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{prob1.pdf}\n\\caption{The solution of \\eqref{ivp:prob1}, alongside several approximations using Euler's method.}\n\\label{ivp:euler}\n\\end{figure}\n\n\n\\begin{problem} The solution of\n\\begin{align}\n\t\\begin{split}\n\t\ty' &= y - 2x + 4,\\quad 0 \\leq x \\leq 2, \\\\\n\t\ty(0) &= 0,\n\t\\end{split}\\label{ivp:prob1}\n\\end{align}\nis given by $y(x) = -2+2x + 2e^x.$\nUse Euler's method to numerically approximate the solution with step sizes $h = 0.4, 0.2$, and $0.1.$ \nCheck that your results match Figure \\ref{ivp:euler}.\n\\end{problem}\n\nSo how do we come up with numerical methods with higher order accuracy? \nUsing Taylor's theorem (as we did for Euler's method) to create higher-order one-step methods would lead to numerically approximating derivatives of $f(t,y)$ - not very desirable.\n\nLet us look for a second order method of the form $y_{i+1} = y_i + a f(x_i+b, y_i+c)$. \nBy expanding $a f(x+b, y+c)$ with Taylor's theorem and matching constants in the equation\n\\begin{align*}\nf(x,y) + \\frac{h}{2}f'(x,y) &= f(x,y) + \\frac{h}{2}\\frac{\\partial f}{\\partial x}(x,y) + \\frac{h}{2}\\frac{\\partial f}{\\partial y}(x,y) \\cdot f(x,y),\n\\end{align*}\nwe find that $a = h, b = h/2,$ and $c = h/2$. \nThis method is called the Midpoint method. \nIVP solvers with this general form are called \\textit{Runge-Kutta methods}. \n% Another second order Runge-Kutta method is the modified Euler method:\n% $y_{i+1} = y_i + \\frac{h}{2}[ f(x_i, y_i) + f(x_{i+1}, y_i+ hf(x_i, y_i))]$\n\nThere are many Runge-Kutta methods with varying orders of accuracy. \nMethods of order four or higher are most commonly used. A fourth order Runge-Kutta method iterates as follows: \n\\begin{align*}\n\t\\begin{split}\nK_1 &= f(x_i,y_i), \\\\\nK_2 &= f(x_i + \\frac{h}{2}, y_i + \\frac{h}{2} K_1),\\\\\nK_3 &= f(x_i + \\frac{h}{2} , y_i + \\frac{h}{2} K_2),\\\\\nK_4 &= f(x_{i+1} , y_i + h K_3),\\\\\ny_{i+1} &= y_i + \\frac{h}{6}(K_1 + 2K_2 + 2K_3 + K_4).\n\t\\end{split}\n\\end{align*}\n\nNotice that these methods are doing a type of quadrature where we are sampling the function at different points and then performing computation using the samples and some inherent weights. \nFor example, consider a differential equation \n\\[ y' = f(t).\\]\nSince the function $f$ has no $y$ dependence, this is a simple integration problem, and these IVP methods become well known quadrature methods. In this case, Euler's method corresponds to the left hand sum, and backward Euler's method corresponds to the right hand sum. \nThe modified Euler and midpoint methods are second order IVP methods that correspond to the trapezoidal and midpoint rules for integration, respectively. RK4 corresponds to Simpson's rule for integration.\n\n\n\\begin{comment}\n\\begin{problem}\nSuppose a differential equation is given by\n\\[ y' = f(t).\\]\nSince the function $f$ has no $y$ dependence, this a simple integration problem. \nWhich integration approximation methods correspond to Euler's method, backward Euler's method, modified Euler's method, the Midpoint method, and the fourth order Runge-Kutta method (RK4)?\n\\end{problem}\n\\end{comment}\n\n\n\n\\section*{Advantages of Higher-Order Methods} \n\nHigher-order methods are usually much more efficient. One way to measure this efficiency is to determine how many times the right hand side of the initial value problem must be evaluated to provide a desired accuracy.  As an example, consider the initial value problem \n\\begin{align}\n\t\\begin{split}\n\t\ty' &= y \\cos(x), x \\in [0,8],\\\\\n\t\ty(0) &= 1. \n\t\\end{split}\n\t\\label{ivp:efficiency_problem}\n\\end{align}\nFigure \\ref{ivp:efficiency_figure} illustrates the comparative efficiency of the Euler, Midpoint, and RK4 methods.  The figure also demonstrates another point: since the lower order methods require more floating point operations, floating point error limits the highest possible accuracy that can be achieved with lower order methods. \n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{Efficiency.pdf}\n\\caption{Here we graph the relative error in computing the solution of \\eqref{ivp:efficiency_problem} at $x = 8$, versus the number of times the right side of \\eqref{ivp:efficiency_problem} must be evaluated.  }\n\\label{ivp:efficiency_figure}\n\\end{figure}\n\n\n\n\nLet $t^*$ be an approximation of some value $t$. The relative error of the approximation is \n\\[ \\frac{|t^*-t|}{|t|}.\n\\]\nNote that the relative error is simply the absolute error $|t^*-t|$ normalized by the size of $t$.  A method with order $p$ has error of the form \n\\[E(h) = C h^p. \\]\nThis means that the graph of $\\log (E)$ versus $\\log(h)$ has slope $p$.  \nThe relative error of a numerical method can be approximated and graphed to verify that $p$th order convergence is occurring. For example, consider the IVP\n \\begin{align}\n \t\\begin{split}\n y' &= y - 2x + 4,\\quad 0 \\leq x \\leq 2, \\\\\n y(0) &= 0.\n \t\\end{split} \\label{ivp:prob2}\n \\end{align}\nThe following code solves the initial value problem on several grids using the Euler method, approximates the relative error in computing $y(2)$ and creates a plot (see Figure \\ref{ivp:relative_error}).\n\n\\begin{lstlisting}\nimport matplotlib.pyplot as plt\n\na, b, ya = 0., 2., 0.\n\ndef ode_f(x,y):\n\treturn np.array([y -2*x + 4.])\n\t\nbest_grid = 320\t\t\t\t\t#  number of subintervals in most refined grid\n# Requires an implementation of the euler method\nbest_val = euler(ode_f,ya,a,b,best_grid)[-1]  \n\nsmaller_grids = [10,20,40,80]  # number of subintervals in smaller grids\nh = [2./N for N in smaller_grids]\nEuler_sol = [euler(ode_f,ya,a,b,N)[-1] for N in smaller_grids]\nEuler_error = [abs(( val - best_val)/best_val ) for val in Euler_sol]\n\t\nplt.loglog(h, Euler_error, '-b', label=\"Euler method\"\t  , linewidth=2.)\nplt.show()\n\n\\end{lstlisting}\n\n\n\\begin{problem} Consider the IVP \\eqref{ivp:prob2}.\nUse the Midpoint method and the fourth order Runge-Kutta method (RK4) to approximate the value of the solution at $x = 2$, with a step size of $h = 0.2,$ $ 0.1,$ $0.05 $, $0.025,$ and $0.0125.$ \nCreate a log-log plot of the relative error of each approximation using the \\li{loglog} function in \\li{matplotlib} (see Figure \\ref{ivp:relative_error}).\n\\end{problem}\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{relative_error.pdf}\n\\caption{The solution of $y' -y= -2x+4,$ $y(0) = 0$, is $y(x) = -2+2x + 2e^x.$ This loglog plot shows the relative error in numerically approximating $y(2)$, using step sizes $h = 0.2,$ $0.1,$ $0.05,$ $0.025,$ and $0.0125$. The slope of each line demonstrates the first, second, and fourth order convergence of the Euler, Midpoint, and RK4 methods, respectively.}\n\\label{ivp:relative_error}\n\\end{figure}\n\n\n\\section*{Harmonic Oscillators and Resonance} \nHarmonic oscillators show up often in classical mechanics.\nA few examples include the pendulum (with small\n displacement), spring-mass systems, and the flow of electric current through various types of circuits.\nA harmonic oscillator can be described by an initial value problem of the form\n\\begin{align*}\n\t&{}my'' + \\gamma y' + ky = f(t) ,\\\\\n\t&{}y(0) = y_0,\\quad\n\ty'(0) = y'_0.\n\\end{align*}\nWe will describe the construction of this mathematical model in the context of a spring-mass system.\n\nSuppose an object with mass $m$ is placed at the end of a horizontal spring.\nThe natural position of the object is called the \\textit{equilibrium position} for the system.\nIf the object is displaced from its equilibrium position and given an initial velocity,\nit will act like a harmonic oscillator.\nThe principal property of a harmonic oscillator $y(t)$ is that once $y$ leaves its equilibrium value $y = 0$, it experiences a restoring force $F_r = -ky.$\nThis force pushes $y$ back towards its equilibrium.\nHooke's law says that this holds true for a\nspring-mass system if the displacement $y$ is small.\n\nOften there is an additional damping force $F_d$, often due to some type of friction. \nThis force is usually proportional to the $y'$ (the \\emph{velocity}), is always in the opposite direction of $y'$, and represents energy leaving the system. (You can think of it as drag.)\nThus we have $F_d = -\\gamma y', $ where $ \\gamma \\geq 0$ is constant.\nWe may also need to consider an additional external force $f(t)$, or a driving force, that is interacting with our spring-mass system.\n\nBy using Newton's law we obtain\n\\begin{align*}\nma &= F = F_r + F_d + f(t),\\\\\nmy'' &= -ky -\\gamma y' + f(t).\n\\end{align*}\n\n\\section*{Simple harmonic oscillators}\nA simple harmonic oscillator is a harmonic oscillator that is not damped ($\\gamma =0$), and is free ($f = 0$) rather than forced ($f \\not = 0$). \nA simple harmonic oscillator can described by the IVP\n\\begin{align*}\n&{}my'' + ky = 0,\\\\\n&{}y(0) = y_0,\\quad\ny'(0) = y_0'.\n\\end{align*}\nThe solution of this IVP is $y = c_1\\cos (\\omega_0 t) + c_2 \\sin (\\omega_0 t)$ where $\\omega_0 = \\sqrt{k/m}$ is the natural frequency of the oscillator and $c_1$ and $c_2$ are determined by applying the initial conditions. This in turn can be written in the form\n\\[y = A\\sin (\\omega_0 t + \\delta) .\\]\n\nTo solve this IVP using the fourth order Runge Kutta method (RK4), we need to write this system in the form\n\\[z'(t) = f(t,z(t)) \\]\nWe can do this by letting $z_1 = y, z_2 = y'$. Then we have \\[     z'=\n \\left[\\begin{array}{c}z_1 \\\\z_2\\end{array}\\right]'  =  \\left[\\begin{array}{c}z_2 \\\\\\frac{-k}{m}z_1\\end{array}\\right]= f(z).\\]\n\n\n\\begin{problem} Use the RK4 method to solve for the simple harmonic oscillator satisfying \n\\begin{align}\n\t\\begin{split}\n&{}my'' + ky = 0,\\quad 0 \\leq t \\leq 20, \\\\\n&{}y(0) = 2, \\quad\ny'(0) = -1,\n\t\\end{split}\n\t\\label{ivp:simple_oscillator}\n\\end{align}\nfor $m = 1$ and $k =1$. Note that in your implementation of RK4, the constants $K_1, K_2, K_3,$ and $K_4$ become vectors with $n$ entries, where $n$ is the number of equations in the first-order system.\n\nPlot your numerical approximation of $y(t)$.  \nCompare this with its numerical approximation when $m = 3$ and $k =1$. Consider: Why does the difference in solutions make sense physically?\n\\end{problem}\n\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{simple_oscillator.pdf}\n\\caption{Solutions of \\eqref{ivp:simple_oscillator} for several values of $m$.}\n\\label{ivp:simple_oscillator_figure}\n\\end{figure}\n\n\n\\section*{Damped free harmonic oscillators} \nWe now consider damped free harmonic oscillators. \nThese systems are described by the differential equation\n\\[my''(t) +\\gamma y'(t) + ky(t) = 0.\\]\nFor fixed values of $m$ and $k$, it is interesting to study the effect of the damping coefficient $\\gamma$.\n\nThe roots of the characteristic equation are \\[r_1,r_2 = \\frac{-\\gamma \\pm \\sqrt{\\gamma^2 -4km}}{2m} .\\]\nNote that the real parts of $r_1$ and $r_2$ are always negative, and so any solution $y(t)$ will decay over time due to a dissipation of the system energy. \nThere are several cases to consider for the general solution of this equation:\n\\begin{enumerate}\n\\item If $\\gamma^2 > 4km$, then the general solution is $y(t) = c_1 e^{r_1t} + c_2e^{r_2t}$. Here the system is said to be $\\textit{overdamped}$. \nNotice from the general solution that there is no oscillation in this case.\n\\item If $\\gamma^2 = 4km$, then the general solution is $y(t) = c_1 e^{\\gamma t/2m} + c_2 te^{\\gamma t/2m}$. Here the system is said to be $\\textit{critically damped}$.\n\\item If $\\gamma^2 < 4km$, then the general solution is\n\\begin{align*}\ny(t) &= e^{-\\gamma t/2m} \\left[c_1\\cos(\\mu t) + c_2 \\sin (\\mu t)\\right],\\\\\n&= R e^{-\\gamma t/2m}  \\sin (\\mu t + \\delta),\n\\end{align*}\nwhere $R$ and $\\delta$ are fixed, and $\\mu = \\sqrt{4km-\\gamma^2}/2m.$ This system does oscillate.\n\\end{enumerate}\n\n\\begin{problem}\nUse the RK4 method to solve for the damped free harmonic oscillator satisfying \n\\begin{align*}\n&{}y'' +\\gamma y'+ y = 0, \\quad 0 \\leq t \\leq 20,\\\\\n&{}y(0) = 1, \\quad\ny'(0) = -1.\n\\end{align*}\nFor $\\gamma = 1/2,$ and $\\gamma = 1$, simultaneously plot your numerical approximations of $y$.  \nFind $y(20)$ accurate to four significant digits, by checking that the relative error is less than $5\\times 10^{-5}$.  \nHow many subintervals do you need?\n\\end{problem}\n\n\\section*{Forced harmonic oscillators without damping}\nLet's look at the systems described by the differential equation\n\\begin{align}\nmy''(t)  + ky(t) &= F(t). \\label{Forced_harm_osc}\n\\end{align}\nIn many instances the external force $F(t)$ is periodic, so let us assume that $F(t) = F_0 \\cos(\\omega t)$. \nIf $\\omega_0 = \\sqrt{k/m} \\not = \\omega,$ then the  general solution of \\ref{Forced_harm_osc} is given by\n\\[y(t) = c_1 \\cos (\\omega_0 t) + c_2\\sin (\\omega_0 t) + \\frac{F_0}{m(\\omega_0^2 - \\omega^2)} \\cos (\\omega t).\\]\nIf $\\omega_0 = \\omega$, then the general solution is\n\\[y(t) = c_1 \\cos (\\omega_0 t) + c_2\\sin (\\omega_0 t) + \\frac{F_0}{2m\\omega_0} t \\sin (\\omega_0 t).\\]\n\nIn the case that $\\omega_0 = \\omega$, the solution contains a term that grows arbitrarily large as $t \\to \\infty$.\nIf we included damping then the solution would be bounded, but would still be large for small $\\gamma$ and $\\omega$ close to $\\omega_0$.\n\nConsider a physical spring-mass system.\nEquation \\ref{Forced_harm_osc} holds only for small oscillations (this is where Hooke's law is applicable).\nFor larger oscillations, this equation will not hold.\nHowever, the fact that the equation predicts large oscillations suggests the spring-mass system could fall apart as a result of the external force. \nMechanical resonance has been known to cause failure of bridges, buildings, and airplanes.\n\n\\begin{problem}\nUse the RK4 method to solve for the damped and forced harmonic oscillator satisfying \n\\begin{align}\n\t\\begin{split}\n&{}2y'' + \\gamma y' + 2y = 2 \\cos (\\omega t), \\quad 0 \\leq t \\leq 40,\\\\\n&{}y(0) = 2, \\quad\ny'(0) = -1. \n\t\\end{split}\n\t\\label{ivp:damped_forced_oscillator}\n\\end{align}\nFor the following values of $\\gamma$ and $\\omega,$ plot your numerical approximations of $y$ and find $y(40)$ accurate to four significant digits: $(\\gamma, \\omega) = (0.5, 1.5),$ $(0.1, 1.1),$ and $(0, 1).$\n\\end{problem}\n\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{damped_forced_oscillator.pdf}\n\\caption{Solutions of \\eqref{ivp:damped_forced_oscillator} for several values of $\\omega$ and $\\gamma$.}\n\\label{ivp:damped_forced_oscillator_figure}\n\\end{figure}\n", "meta": {"hexsha": "32ac327d2811b5fba559e0a377aca20cb165326d", "size": 18608, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol4A/IVP/IVP.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol4A/IVP/IVP.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol4A/IVP/IVP.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 50.9808219178, "max_line_length": 363, "alphanum_fraction": 0.7112532244, "num_tokens": 5776, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8267117898012104, "lm_q2_score": 0.8947894654011352, "lm_q1q2_score": 0.7397330004370407}}
{"text": "\\section{Derivative Rules}\\label{sec:DerivativeRules}\r\nUsing the definition of the derivative of a function is quite tedious.\r\nIn this section we introduce a number of different shortcuts that can be used to compute the derivative.\r\nRecall that the \\ifont{definition of derivative} is:\r\n\r\nGiven any number $x$ for which the limit \r\n$$f'(x)=\\lim_{h\\to 0}\\frac{f(x+h)-f(x)}{h}$$\r\nexists, we assign to $x$ the number $f'(x)$.\r\n\r\nNext, we give some basic \\ifont{derivative rules} for finding derivatives without having to use the limit definition directly.\r\n\r\n\\begin{theorem}{Derivative of a Constant Function}{Derivative of a Constant Function}\r\nLet $c$ be a constant, then $\\ds{\\frac{d}{dx}(c)=0}$.\r\n\\end{theorem}\r\n\r\n\\begin{proof}\r\nLet $f(x)=c$ be a constant function. By the definition of derivative:\r\n$$f'(x)=\\lim_{h\\to 0}\\frac{f(x+h)-f(x)}{h}=\\lim_{h\\to 0}\\frac{c-c}{h}=\\lim_{h\\to 0}0=0.$$\r\n\\end{proof}\r\n\r\n\\begin{example}{Derivative of a Constant Function}{DerivativeConstantFunction}\r\n The derivative of $f(x)=17$ is $f'(x)=0$ since the derivative of a constant is $0$.\r\n\\end{example}\r\n\r\n\\begin{theorem}{The Power Rule}{The Power Rule}\r\nIf $n$ is a positive integer, then $\\ds{\\frac{d}{dx}(x^n)=nx^{n-1}}$.\r\n\\end{theorem}\r\n\r\n\\begin{proof}\r\nWe use the formula:\r\n$$x^n-a^n=(x-a)(x^{n-1}+x^{n-2}a+\\cdots+xa^{n-2}+a^{n-1})$$\r\nwhich can be verified by mulitplying out the right side.\r\nLet $f(x)=x^n$ be a power function for some positive integer $n$.\r\nThen at any number $a$ we have:\r\n$$f'(a)=\\lim_{x\\to a}\\frac{f(x)-f(a)}{x-a}=\\lim_{x\\to a}\\frac{x^n-a^n}{x-a}=\\lim_{x\\to a}(x^{n-1}+x^{n-2}a+\\cdots+xa^{n-2}+a^{n-1})=na^{n-1}.$$\r\n\\end{proof}\r\n\r\nIt turns out that the Power Rule holds for any real number $n$ (though it is a bit more difficult to prove).\r\n\r\n\\begin{theorem}{The Power Rule (General)}{The Power Rule (General)}\r\nIf $n$ is any real number, then $\\ds{\\frac{d}{dx}(x^n)=nx^{n-1}}$.\r\n\\end{theorem}\r\n\r\n\\begin{example}{Derivative of a Power Function}{DerivativePowerFunction}\r\nBy the power rule, the derivative of $g(x)=x^4$ is $g'(x)=4x^3$.\r\n\\end{example}\r\n\r\n\\begin{theorem}{The Constant Multiple Rule}{The Constant Multiple Rule}\r\nIf $c$ is a constant and $f$ is a differentiable function, then $$\\ds{\\frac{d}{dx}[cf(x)]=c\\frac{d}{dx}f(x)}.$$\r\n\\end{theorem}\r\n\r\n\\begin{proof}\r\nFor convenience let $g(x)=cf(x)$.\r\nThen:\r\n$$g'(x)=\\lim_{h\\to 0}\\frac{g(x+h)-g(x)}{h}=\\lim_{h\\to 0}\\frac{cf(x+h)-cf(x)}{h}$$\r\n$$=\\lim_{h\\to 0}c\\left[\\frac{f(x+h)-f(x)}{h}\\right]=c\\lim_{h\\to 0}\\frac{f(x+h)-f(x)}{h}=cf'(x),$$\r\nwhere $c$ can be moved in front of the limit by the Limit Rules.\r\n\\end{proof}\r\n\r\n\\begin{example}{Derivative of a Multiple of a  Function}{DerivativeMultipleFunction}\r\nBy the constant multiple rule and the previous example, the derivative of $F(x)=2\\cdot(17+x^4)$ is\r\n$$F'(x)=2(4x^3)=8x^3.$$\r\n\\end{example}\r\n\r\n\\begin{theorem}{The Sum/Difference Rule}{The Sum/Difference Rule}\r\nIf $f$ and $g$ are both differentiable functions, then\r\n$$\\ds{\\frac{d}{dx}[f(x)\\pm g(x)]=\\frac{d}{dx}f(x)\\pm\\frac{d}{dx}g(x)}.$$\r\n\\end{theorem}\r\n\r\n\\begin{proof}\r\nFor convenience let $r(x)=f(x)\\pm g(x)$.\r\nThen:\r\n$$\\begin{array}{ccl}\r\nr'(x)&=&\\ds{\\lim_{h\\to 0}\\frac{r(x+h)-r(x)}{h}}\\\\\r\n\\\\\r\n&=&\\ds{\\lim_{h\\to 0}\\frac{[f(x+h)\\pm g(x+h)]-[f(x)\\pm g(x)]}{h}}\\\\\r\n\\\\\r\n~&=&\\ds{\\lim_{h\\to 0}\\left[\\frac{f(x+h)-f(x)}{h}\\pm\\frac{g(x+h)-g(x)}{h}\\right]}\\\\\r\n\\\\\r\n&=&\\ds{\\lim_{h\\to 0}\\frac{f(x+h)-f(x)}{h}\\pm\\lim_{h\\to 0}\\frac{g(x+h)-g(x)}{h}}\\\\\r\n\\\\\r\n~&=&f'(x)+g'(x)\\\\\\end{array}$$\r\n\\end{proof}\r\n\r\n\\begin{example}{Derivative of a Sum/Difference of Functions}{DerivativeSumDifferenceFunction}\r\nBy the sum/difference rule, the derivative of $h(x)=17+x^4$ is \r\n$$h'(x)=f'(x)+g'(x)=0+4x^3=4x^3.$$\r\n\\end{example}\r\n\r\n\\begin{theorem}{The Product Rule}{The Product Rule}\r\nIf $f$ and $g$ are both differentiable functions, then\r\n$$\\ds{\\frac{d}{dx}[f(x)\\cdot g(x)]=f(x)\\frac{d}{dx}[g(x)]+g(x)\\frac{d}{dx}[f(x)]}.$$\r\n\\end{theorem}\r\n\r\n\\begin{proof}\r\nFor convenience let $r(x)=f(x)\\cdot g(x)$.\r\nAs in the previous proof, we want to separate the functions $f$ and $g$.\r\nThe trick is to add and subtract $f(x+h)g(x)$ in the numerator.\r\nThen:\r\n$$\\begin{array}{ccl}\r\nr'(x)&=&\\ds{\\lim_{h\\to 0}\\frac{f(x+h)g(x+h)-f(x+h)g(x)+f(x+h)g(x)-f(x)g(x)}{h}}\\\\\r\n\\\\\r\n~&=&\\ds{\\lim_{h\\to 0}\\left[f(x+h)\\frac{g(x+h)-g(x)}{h}+g(x)\\frac{f(x+h)-f(x)}{h}\\right]}\\\\\r\n\\\\\r\n~&=&\\ds{\\lim_{h\\to 0}f(x+h)\\cdot\\lim_{h\\to 0}\\frac{g(x+h)-g(x)}{h}+\\lim_{h\\to 0}g(x)\\cdot\\lim_{h\\to 0}\\frac{f(x+h)-f(x)}{h}}\\\\\r\n\\\\\r\n~&=&f(x)g'(x)+g(x)f'(x)\\\\\\end{array}$$\r\n\\end{proof}\r\n\r\n\\begin{example}{Derivative of a Product of Functions}{DerivativeProductFunction}\r\nFind the derivative of $\\ds h(x)=(3x-1)(2x+3)$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nOne way to do this question is to expand the expression.\r\nAlternatively, we use the product rule with $f(x)=3x-1$ and $g(x)=2x+3$.\r\nNote that $f'(x)=3$ and $g'(x)=2$, so,\r\n$$h'(x)=(3)\\cdot(2x+3)+(3x-1)\\cdot(2)=6x+9+6x-2=12x+7.$$\r\n\\end{solution}\r\n\r\n\\begin{theorem}{The Quotient Rule}{The Quotient Rule}\r\nIf $f$ and $g$ are both differentiable functions, then $$\\ds{\\frac{d}{dx}\\left[\\frac{f(x)}{g(x)}\\right]\r\n=\\frac{g(x)\\frac{d}{dx}[f(x)]-f(x)\\frac{d}{dx}[g(x)]}{[g(x)]^2}}.$$\r\n\\end{theorem}\r\n\r\n\\begin{proof}\r\nThe proof is similar to the previous proof but the trick is to add and subtract the term $f(x)g(x)$ in the numerator.\r\nWe omit the details.\r\n\\end{proof}\r\n\r\n\\begin{example}{Derivative of a Quotient of Functions}{DerivativeQuotientFunction}\r\nFind the derivative of $\\ds h(x)=\\frac{3x-1}{2x+3}$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nBy the quotient rule (using $f(x)=3x-1$ and $g(x)=2x+3$) we have:\r\n$$h'(x)=\\frac{\\frac{d}{dx}(3x-1)\\cdot (2x+3)-(3x-1)\\cdot\\frac{d}{dx}(2x+3)}{(2x+3)^2}$$\r\n$$=\\frac{3(2x+3)-(3x-1)(2)}{(2x+3)^2}=\\frac{11}{(2x+3)^2}.$$\r\n\\end{solution}\r\n\r\n\\begin{example}{Second Derivative}{}\r\nFind the second derivative of $f(x)=5x^3+3x^2$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe must differentiate $f(x)$ twice:\r\n$$f'(x)=15x^2+6x,$$\r\n$$f''(x)=30x+6.$$\r\n\\end{solution}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:DerivativeRules}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind the derivatives of the following functions.\r\n\\begin{multicols}{3}\r\n\\begin{enumerate}\r\n\t\\item\t$\\ds x^{100}$\r\n\t\\item\t$\\ds x^{-100}$\r\n\t\\item\t$\\ds {1\\over x^5}$\r\n\t\\item\t$\\ds x^\\pi$\r\n\t\\item\t$\\ds x^{3/4}$\r\n\t\\item\t$\\ds x^{-9/7}$\r\n\t\\item\t$\\ds 5x^3+12x^2-15$\r\n\t\\item\t$\\ds -4x^5 + 3x^2 - 5/x^2$\r\n\t\\item\t$\\ds 5(-3x^2 + 5x + 1)$\r\n\t\\item\t$\\ds (x+1)(x^2+2x-3)$\r\n\t\\item\t$\\ds (x+1)(x^2+2x-3)^{-1}$\r\n\t\\item\t$\\ds x^3(x^3-5x+10)$\r\n\t\\item\t$\\ds (x^2+5x-3)(x^5)$\r\n\t\\item\t$\\ds (x^2+5x-3)(x^{-5})$\r\n\t\\item\t$\\ds (5x^3+12x^2-15)^{-1}$\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\begin{sol}\r\n\\begin{multicols}{3}\r\n\\begin{enumerate}\r\n\t\\item\t$\\ds 100x^{99}$\r\n\t\\item\t$\\ds -100x^{-101}$\r\n\t\\item\t$\\ds -5x^{-6}$\r\n\t\\item\t$\\ds \\pi x^{\\pi-1}$\r\n\t\\item\t$\\ds (3/4)x^{-1/4}$\r\n\t\\item\t$\\ds -(9/7)x^{-16/7}$\r\n\t\\item\t$\\ds 15x^2+24x$\r\n\t\\item\t$\\ds -20x^4+6x+10/x^3$\r\n\t\\item\t$\\ds -30x+25$\r\n\t\\item\t$\\ds 3x^2+6x-1$\r\n\t\\item\t$\\ds -\\frac{x^2+2x+5}{(x^2+2x-3)^2}$\r\n\t\\item\t$\\ds 3x^2(x^3-5x+10)+x^3(3x^2-5)$ \r\n\t\\item\t$\\ds x^4(7x^2+30x-15)$\r\n\t\\item\t$\\ds\\frac{-3x^2-20x+15}{x^6}$\r\n\t\\item\t$\\ds -\\frac{3x(5x+8)}{(5x^3+12x^2-15)^2}$ \r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\end{sol} \r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n Find an equation for the tangent line to $\\ds f(x) = x^3/4 - 1/x$ at $x=-2$.\r\n\\begin{sol}\r\n$y=13x/4+5$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind an equation for \r\nthe tangent line to $\\ds f(x)= 3x^2 - \\pi ^3$ at $x= 4$.\r\n\\begin{sol}\r\n$\\ds y=24x-48-\\pi^3$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nSuppose the position of an object at time $t$ is  given by\r\n$\\ds f(t)=-49 t^2/10+5t+10$. Find a function giving the speed of the object\r\nat time $t$. The acceleration of an object is the rate at which its\r\nspeed is changing, which means it is given by the derivative of the\r\nspeed function. Find the acceleration of the object at time $t$.\r\n\\begin{sol}\r\n$-49t/5+5$, $-49/5$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nLet $\\ds f(x) =x^3$ and $c= 3$. Sketch the graphs of $f$,\r\n$cf$, $f'$, and $(cf)'$ on the same diagram.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nThe general polynomial $P$ of degree $n$ in the variable $x$\r\nhas the form $\\ds P(x)= \\sum _{k=0 } ^n a_k x^k = a_0 + a_1 x + \\ldots\r\n+ a_n x^n$. What is the derivative (with respect to $x$)\r\nof $P$?\r\n\\begin{sol}\r\n$\\ds\\sum_{k=1}^n ka_kx^{k-1}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind a cubic polynomial whose graph has horizontal tangents at\r\n$(-2 , 5)$ and $(2, 3)$.\r\n\\begin{sol}\r\n$\\ds x^3/16-3x/4+4$\r\n\\end{sol}\r\n\\end{ex}\r\n \r\n%%%%%%%%%%\r\n\\begin{ex} \r\nProve that $\\ds{d\\over dx}(cf(x))= cf'(x)$ using the\r\ndefinition of the derivative.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nSuppose that $f$ and $g$ are differentiable at $x$. Show\r\nthat $f-g$ is differentiable at $x$ using the two linearity\r\nproperties from this section.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nUse the product rule to compute the derivative of $\\ds f(x)=(2x-3)^2$.\r\n Sketch the function.  Find an equation of the tangent line to the curve at\r\n $x=2$.  Sketch the tangent line at $x=2$.\r\n\\begin{sol}\r\n$f'=4(2x-3)$, $y=4x-7$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nSuppose that $f$, $g$, and $h$ are differentiable functions.\r\nShow that $(fgh)'(x) = f'(x) g(x)h(x) + f(x)g'(x) h(x) + f(x) g(x)\r\nh'(x)$.\r\n\\end{ex}\r\n\r\n%\\exercise\r\n%State and prove a rule to compute $(fghi)'(x)$, \r\n%similar to the rule in the previous problem.\r\n%\r\n%\\remark{Product notation}\r\n%Suppose $\\ds f_1 , f_2 , \\ldots f_n$ are functions.\r\n%The product of all these functions can be written\r\n%$$ \\prod _{k=1 } ^n f_k.$$\r\n%This is similar to the use of $\\ds \\sum$ to denote a \r\n%sum.\r\n%For example,\r\n%$$\\prod _{k=1 } ^5 f_k =f_1 f_2 f_3 f_4 f_5$$\r\n%and\r\n%$$\r\n%\\prod _ {k=1 } ^n k = 1\\cdot 2 \\cdot \\ldots \\cdot n = n!.$$\r\n%We sometimes use somewhat more complicated conditions; for example\r\n%$$\\prod _{k=1 , k\\neq j } ^n f_k$$\r\n%denotes the product of $\\ds f_1$ through $\\ds f_n$ except for $\\ds f_j$.\r\n%For example, \r\n%$$\\prod _{k=1 , k\\neq 4} ^5 x^k = x\\cdot x^2 \\cdot x^3 \\cdot x^5 =\r\n%x^{11}.$$\r\n%\\endremark\r\n%\r\n%\\exercise\r\n%  The \\dfont{generalized product rule} \r\n%says that if $\\ds f_1 , f_2 ,\\ldots ,f_n$ are differentiable functions at\r\n%  $x$ then\r\n%$${d\\over dx}\\prod _{k=1 } ^n f_k(x) = \r\n%\\sum _{j=1 } ^n \\left(f'_j (x) \\prod _{k=1 , k\\neq j} ^n\r\n%   f_k (x)\\right).$$\r\n%Verify that this is the same as your answer to the previous problem\r\n%when $n=4$,\r\n%and write out what this says when $n=5$.\r\n\r\n\r\n%%%%%%%%%%%\r\n%\\begin{ex} \r\n%Find all points on the graph of\r\n%$\\ds f(x)=\\sin^2(x)$ at which the tangent line is horizontal.\r\n%\\begin{sol} \r\n%$n\\pi/2$, any integer $n$\r\n%\\end{sol}\r\n%\\end{ex}\r\n%\r\n%%%%%%%%%%%\r\n%\\begin{ex} \r\n%Find all points on the graph of $\\ds f(x) = 2\\sin(x) -\r\n%\\sin^2(x)$ at which the tangent line is horizontal.\r\n%\\begin{sol} \r\n%$\\pi/2+n\\pi$, any integer $n$\r\n%\\end{sol}\r\n%\\end{ex}\r\n%\r\n%%%%%%%%%%%\r\n%\\begin{ex} \r\n%Find an\r\n %equation for the tangent line to $\\ds \\sin^2(x)$ at \r\n%$x=\\pi/3$.\r\n%\\begin{sol} \r\n%$\\sqrt3x/2+3/4-\\sqrt3\\pi/6$\r\n%\\end{sol}\r\n%\\end{ex}\r\n%\r\n%%%%%%%%%%%\r\n%\\begin{ex} \r\n%Find an equation for the tangent line to $\\ds \\sec ^2 x$\r\n%at $x=\\pi/3$.\r\n%\\begin{sol} \r\n%$\\ds 8\\sqrt3x+4-8\\sqrt3\\pi/3$\r\n%\\end{sol}\r\n%\\end{ex}\r\n%\r\n%%%%%%%%%%%\r\n%\\begin{ex} \r\n%Find an equation for the tangent line to $\\ds \\cos ^2 x -\r\n%\\sin ^2 (4x)$ at $x=\\pi/6$.\r\n%\\begin{sol} \r\n%$\\ds 3\\sqrt3x/2-\\sqrt3\\pi/4$\r\n%\\end{sol}\r\n%\\end{ex}\r\n%\r\n%%%%%%%%%%%\r\n%\\begin{ex} \r\n%Find the points on the curve $\\ds y= x+ 2\\cos x$ that have a\r\n%horizontal tangent line.\r\n%\\begin{sol} \r\n%$\\ds \\pi/6+2n\\pi$, $5\\pi/6+2n\\pi$, any integer $n$\r\n%\\end{sol}\r\n%\\end{ex}\r\n%\r\n%%%%%%%%%%%\r\n%\\begin{ex} \r\n%Let $C$ be a circle of radius $r$. Let $A$ be an arc on $C$\r\n%subtending a central angle $\\theta$. Let $B$ be the chord of\r\n%$C$ whose endpoints are the endpoints of $A$. (Hence, $B$ also\r\n%subtends $\\theta$.) Let $s$ be the length of $A$\r\n%and let $d$ be the length of $B$. Sketch a diagram of the situation\r\n%and compute $\\ds \\lim_{\\theta \\to 0^+ } s/d$.\r\n%\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nCompute the derivative of $\\ds {x^3\\over x^3-5x+10}$.\r\n\\begin{sol} \r\n$\\ds {3x^2\\over x^3-5x+10}-{x^3(3x^2-5)\\over (x^3-5x+10)^2}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nCompute the derivative of $\\ds {x^2+5x-3\\over x^5-6x^3+3x^2-7x+1}$.\r\n\\begin{sol} \r\n$\\ds {2x+5\\over x^5-6x^3+3x^2-7x+1}-{(x^2+5x-3)(5x^4-18x^2+6x-7)\\over(x^5-6x^3+3x^2-7x+1)^2}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nCompute the derivative of $\\ds {x\\over\\sqrt{x-625}}$.\r\n\\begin{sol} \r\n$\\ds \\frac{x-1250}{2(x-625)^{3/2}}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nCompute the derivative of $\\ds {\\sqrt{x-5}\\over x^{20}}$.\r\n\\begin{sol} \r\n$\\ds \\frac{200-39x}{2x^{21}\\sqrt{x-5}}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind an equation for the tangent line to $\\ds f(x) = (x^2 -\r\n4)/(5-x)$ at $x= 3$.  \r\n\\begin{sol} \r\n$\\ds y=17x/4-41/4$ \r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind an equation for the tangent line to \r\n$\\ds f(x) = (x-2)/(x^3 + 4x - 1)$ at $x=1$.\r\n\\begin{sol} \r\n$y=11x/16-15/16$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%\\exercise Let $P$ be a polynomial of degree $n$ and let $Q$ be a\r\n%polynomial of degree $m$ (with $Q$ not the zero polynomial). \r\n%Using sigma notation we can write\r\n%$$P=\\sum _{k=0 } ^n a_k x^k,\\qquad\r\n%Q=\\sum_{k=0}^m b_k x^k.\r\n%$$\r\n%Use sigma notation to write the derivative of the \r\n%{\\dfont rational function\\index{rational function}\\/}\r\n%$P/Q$.\r\n%% \\begin{sol} $\\left(\\sum_{k=0}^m b_k x^k\\sum _{k=1}^n ka_k x^{k-1}-\r\n%% \\sum _{k=0 } ^n a_k x^k\\sum_{k=1}^m kb_k x^k\\right)/\r\n%% \\left(\\sum_{k=0}^m b_k x^k\\right)^2$\r\n%% \\end{sol}\\end{ex}\r\n\r\n%\\exercise The curve $\\ds y=1/(1+x^2)$ is an example of a class of\r\n%curves each of which is called a {\\dfont witch of\r\n%Agnesi\\index{witch of Agnesi}}. \r\n%Sketch the curve and find the tangent line to the curve at\r\n%$x= 5$. (The word {\\em witch\\/} here is a mistranslation of the\r\n%original Italian, as described at\r\n%$$\\hbox{\\url{http://mathworld.wolfram.com/WitchofAgnesi.html} \r\n%\\vb|http://mathworld.wolfram.com/WitchofAgnesi.html|\\endurl}$$\r\n%and \r\n%$$\\eqalign{\r\n%\\hbox{\\url{http://instructional1.calstatela.edu/sgray/Agnesi/WitchHistory/Historynamewitch.html} \r\n%\\vb|http://|\\endurl}%\r\n%&\\!\\!\\hbox{\\url{http://instructional1.calstatela.edu/sgray/Agnesi/WitchHistory/Historynamewitch.html} \r\n%\\vb|instructional1.calstatela.edu/sgray/Agnesi/|\\endurl}\\cr\r\n%&\\hbox{\\url{http://instructional1.calstatela.edu/sgray/Agnesi/WitchHistory/Historynamewitch.html} \r\n%\\vb|WitchHistory/Historynamewitch.html|\\endurl.)}\\cr\r\n%}$$\r\n%\\begin{sol} $y=19/169-5x/338$\r\n%\\end{sol}\\end{ex}\r\n%%% \\footnote{Due to a mistranslation of the Italian word\r\n%%%   \\emph{versiera} which actually refers to a rope that turns the\r\n%%%   sail.}.  \r\n \r\n%%%%%%%%%%\r\n\\begin{ex} \r\nIf $f'(4) = 5$, $g'(4) = 12$, $(fg)(4)= f(4)g(4)=2$, and $g(4) = 6$,\r\ncompute $f(4)$ and $\\ds{d\\over dx}{f\\over g}$ at 4.\r\n\\begin{sol} \r\n$13/18$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "8515f94787faaae5002ea2f565aac9123546e9da", "size": 15063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-derivatives/4-4-der-rules.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4-derivatives/4-4-der-rules.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4-derivatives/4-4-der-rules.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.1219008264, "max_line_length": 144, "alphanum_fraction": 0.5976233154, "num_tokens": 6017, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.880797081106935, "lm_q1q2_score": 0.7396352346974929}}
{"text": "The previous results can help improving the performance of any task involving comparisons performed homomorphically such as private database queries, $k$-nearest neighbour search, top-$k$ selection or step function evaluation in neural nets. In this section we choose to demonstrate the gain brought by our approach for sorting and min/max search which are subroutines needed for the aforementioned tasks.\n\n\\subsection{Sorting}\n\\label{subsec:sorting}\n\n    To demonstrate the efficiency of our comparison algorithms, we applied them to a popular computational task that demands multiple comparisons, sorting.\n\tThe best homomorphic sorting algorithm in terms of running time is the direct sorting algorithm due to {\\c C}etin et al.~\\cite{CDSS15}.\n\tFor a given array $A = [a_0,\\dots,a_{N-1}]$, this algorithm computes a \\emph{comparison matrix} $\\mL$ defined by\n\t\\begin{align*}\n\t\t\\mL_{ij} =\n\t\t\\begin{cases}\n\t\t\t\\LT(a_i, a_j) & \\text{ if } i < j, \\\\\n\t\t\t0 & \\text{ if } i = j, \\\\\n\t\t\t1 - \\LT(a_j, a_i) & \\text{ if } i > j.\n\t\t\\end{cases}\n\t\\end{align*}\n\n        \\emph{Example} : for $A = [5,1,7,2,3]$, the matrix $L\\in\\{0,1\\}^{5\\times 5}$ is given by:\n\n        $$ \\mL = \\left(\n          \\begin{array}{ccccc}\n            0 & 0 & 1 & 0 & 0 \\\\\n            1 & 0 & 1 & 1 & 1 \\\\\n            0 & 0 & 0 & 0 & 0 \\\\\n            1 & 0 & 1 & 0 & 1 \\\\\n            1 & 0 & 1 & 0 & 0\n          \\end{array}\n\\right)$$\n        \n        It is easy to see that the Hamming weight of the $i$th row of $\\mL$ is unique and equal to the array index of $a_i$ after sorting the array $A$ in the descending order.\n\tFor example, the zero weight indicates that there are no elements of $A$ bigger than $a_i$. \n\tThus, $a_i$ has a zero index in $A$ after sorting; in other words, $a_i$ is the maximum element of $A$.\n\n\tLet $A'$ be a sorted version of $A$ in the descending order.\n\tTo compute $A'[i]$ for any $i \\in [0,N-1]$, we homomorphically select an element $a_j$ such that $\\wt(\\mL[j]) = i$.\n\tThis can be done with the following sum  \n\t\\begin{align}\\label{eq:sorting_extraction}\n\t\tA'[i] = \\sum_{j=0}^{N-1} \\EQ_{[0,N-1]}(i,\\wt\\left(\\mL[j]\\right)) \\cdot a_j\\,.\n\t\\end{align}\n\tNote that the equality function should be defined on the set $[0,N-1]$, which implies that $N$ must be smaller than the plaintext modulus $p$.\n\n\t\\begin{remark}\n\t\tSince the matrix $\\mL$ is defined by $N(N-1)/2$ elements, it can be costly to keep it in memory for large~$N$.\n\t\tInstead, we can compute the Hamming weights of its rows by iteratively computing one comparison $\\LT(a_i, a_j)$ with $i < j$ at a time.\n\t\tTo achieve this, we create an array of size $N$ initialized with zeros that eventually will store the Hamming weights.\n\t\tThen, we add the outcome of $\\LT(a_i, a_j)$ to the $i$th element of this array and the result of $1-\\LT(a_i, a_j)$ to the $j$th element.\n\t\tIn this approach, only $N$ elements of the Hamming weight array are being kept in RAM.\n\t\\end{remark}\n\n\tThe direct sorting algorithm requires $N(N-1)/2$ less-than operations to compute the matrix $\\mL$ and $N^2$ equality operations to compute sorted elements of $A'$.\n\tWhile computing equalities, we can reduce the total number of non-scalar multiplications if $N$ is large enough.\n\tRecall $\\EQ_\\S$ needs $M = \\log_2(p-1) + \\wt(p-1) - 1$ non-scalar multiplications for any $\\S \\subseteq [0,p-1]$.\n\tHence, to compute $\\EQ_{[0,N-1]}(i,\\wt\\left(\\mL[j]\\right))$ for all $i \\in [0,N-1]$, we should perform $N M$ multiplications.\n\t%$\\EQ(i,\\wt\\left(\\mL[j]\\right)) = 1 - (i-\\wt\\left(\\mL[j]\\right))^{p-1}$\n\tUsing Lemma~\\ref{lem:difference_to_p-1} (see Appendix~\\ref{app:proof_thm_less_than_total_degree}), we can rewrite: \n\t\\begin{align*}\n\t\t\\EQ_{[0,N-1]}\\left(i,\\wt\\left(\\mL[j]\\right)\\right) = 1 - \\sum_{k=0}^{p-1} i^k \\cdot \\wt\\left(\\mL[j]\\right)^{p-1-k}\\,.\n\t\\end{align*}\n\tIf we precompute the powers $\\wt\\left(\\mL[j]\\right)^{p-1-k}$, then we need only $p-2$ non-scalar multiplications to compute all the equalities $\\EQ(i,\\wt\\left(\\mL[j]\\right))$ as the index $i$ is not encrypted.\n\tHence, if $N > (p-2)/M$, this approach results in a smaller number of non-scalar multiplications.\n\tYet, this method introduces $p-1$ scalar multiplications (by powers $i^k$) and $p-2$ additions. \n\tHowever, these operations are much faster in HE schemes than non-scalar multiplication such that the gain from reducing non-scalar multiplications becomes dominant. \n\t\n\tThe main advantage of direct sorting is that its multiplicative depth is independent of the array length, namely $d = d\\left(\\LT\\right) + \\ceil{\\log_2 (p-1)} + 1$ with $d\\left(\\LT\\right)$ given in Equation (\\ref{eq:circuit-depth}).\n        \n\tThis allows to avoid large encryption parameters and costly bootstrapping operations.\n\t%We can further reduce this depth by computing the Hamming weight modulo a plaintext modulus $p$ that is equal or larger than the length of an array $n$.\n\n\\subsection{Minimum and maximum of an array}\n\\label{sec:min/max}\n\n\tAnother application of our comparison algorithms is concerned with finding a minimum (or maximum) element of an array.\n\tTo find the minimum of an array with $N$ elements, at least $N-1$ calls of the pairwise minimum function are required~\\cite[Chapter 9]{CLR09}, which can be achieved, for instance, by the \\emph{tournament method}.\n\t\n\tThe tournament method consists of $\\ceil{\\log N}$ iterations.\n\tIn each iteration, the input array is divided into pairs. \n\tIf the array length is odd, one element is stashed for the next iteration. \n\tThen, the maximum of each pair is removed from the array.\n\tThe algorithm stops when only one element is left; this is the minimum of the input array, see Figure~\\ref{fig:minimum_tournament}. \n\t\\begin{figure}\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t% first stage\n\t\t\t\\draw[black, thin] (0,0) rectangle (1,1);\n\t\t\t\\draw[black, thin] (0,1.5) rectangle (1,2.5);\n\t\t\t\\draw[black, thin] (0,3.0) rectangle (1,4);\n\t\t\t\\draw[black, thin] (0,4.5) rectangle (1,5.5);\n\n\t\t\t\\node at (0.5, 5.0) {$a_0$};\n\t\t\t\\node at (0.5, 3.5) {$a_1$};\n\t\t\t\\node at (0.5, 2.0) {$a_2$};\n\t\t\t\\node at (0.5, 0.5) {$a_3$};\n\n\t\t\t% second stage\n\t\t\t\\draw[black, thin] (1.5,0.75) rectangle (2.5,1.75);\n\t\t\t\\draw[black, thin] (1.5,3.75) rectangle (2.5,4.75);\n\n\t\t\t\\node at (2.0, 1.25) {$\\min$};\n\t\t\t\\node at (2.0, 4.25) {$\\min$};\n\n\t\t\t\\draw[black, thin, ->] (1,0.5) -- (2,0.5) -- (2,0.75);\n\t\t\t\\draw[black, thin, ->] (1,2) -- (2,2) -- (2,1.75);\n\n\t\t\t\\draw[black, thin, ->] (1,3.5) -- (2,3.5) -- (2,3.75);\n\t\t\t\\draw[black, thin, ->] (1,5) -- (2,5) -- (2,4.75);\n\n\t\t\t% third stage\n\t\t\t\\draw[black, thin] (3.0,2.25) rectangle (4.0,3.25);\n\n\t\t\t\\node at (3.5, 2.75) {$\\min$};\n\n\t\t\t\\draw[black, thin, ->] (2.5,1.25) -- (3.5,1.25) -- (3.5,2.25);\n\t\t\t\\draw[black, thin, ->] (2.5,4.25) -- (3.5,4.25) -- (3.5,3.25);\n\n\t\t\t% final outcome\n\t\t\t\\draw[black, thin, ->] (4.0,2.75) -- (5.0,2.75);\n\t\t\t\\node at (6.5, 2.75) {$\\min(a_0,a_1,a_2,a_3)$};\n\n\t\t\\end{tikzpicture}\n\t\t\\caption{The tournament method of finding the minimum of an array. In each stage, the array elements are divided into pairs. Only minimum of a pair go to the next stage.}\n\t\t\\label{fig:minimum_tournament}\n\t\\end{figure}\n\tUnfortunately, the tournament method has a big multiplicative complexity, namely $\\ceil{\\log N} \\cdot d(\\min(x,y))$.\n\tIn the HE world, this enforces us to use either impractical encryption parameters~\\cite{TMP15} or a slow bootstrapping function.\n\n\tTo reduce the depth of the array minimum algorithm, we can combine the tournament method and direct sorting.\n\tLet $A = [a_0,\\dots,a_{N-1}]$ be an input array.\n\tFirst, we perform $T$ iterations of the tournament algorithm, which leaves us with an array $A' = [a'_0, \\dots, a'_{N'-1}]$ of length $N' = \\ceil{N/2^T}$ containing minimal elements of $A$.\n\tThen, we can find the minimum by computing the comparison table $\\mL$ as in direct sorting and extracting one of the minimal elements.\n\tIf $M(f)$ is the non-scalar multiplicative complexity of a function $f$, then the total number of non-scalar multiplications to find the minimum of an array is approximately equal to\n\t\\begin{align*}\n\t\t(N - N') \\cdot M\\left(\\min(x,y)\\right) + \\frac{N'(N'-1)}{2} \\cdot M\\left(\\LT\\right) \\\\\n\t\t+ M(\\mathtt{Extraction}).\n\t\\end{align*}\n\t\n\tThe extraction of a minimum element can be done with two methods.\n\tIn the first approach, we use the fact that the Hamming weight of the comparison table row corresponding to the minimum is equal to $N'-1$.\n\tHence, we can retrieve the minimum as in~(\\ref{eq:sorting_extraction})\n\t\\begin{align}\\label{eq:our_minimum}\n\t\t\\min(A') = \\sum_{i=0}^{N'-1} \\EQ_{[0,N'-1]}(N'-1,\\wt\\left(\\mL[i]\\right)) \\cdot a'_i.\n\t\\end{align}\n\tHere, the multiplicative depth is equal to \n\t\\begin{align*}\n\t\tT \\cdot d(\\min(x,y)) + d(\\LT) + \\ceil{\\log_2 (p-1)} + 1\n\t\\end{align*}\n\twhich is independent of the input array length $N$.\n\tSince $\\EQ_{[0,N'-1]}$ need $\\log_2(p-1) + \\wt(p-1) - 1$ non-scalar multiplications, then the number of non-scalar multiplications needed to extract the array minimum is equal to \n\t\\begin{align*}\n\t\tM(\\mathtt{Extraction}) = N' (\\log_2(p-1) + \\wt(p-1) - 1).\n\t\\end{align*}\n\tShaul et al.~\\cite{PoPETS:SFR20} proposed another circuit to extract the array minimum that exploits the fact that the comparison table row related to the minimum contains only $1$ except for the main diagonal entry.\n\tIn other words, the product of $\\prod_{j=1, j \\ne i}^{N'} \\mL_{ij} = 1$ if and only if $a'_i = \\min(A')$.\n\tHence, the minimal element is equal to\n\t\\begin{align}\\label{eq:shaul_minimum}\n\t\t\\min(A') = \\sum_{i=0}^{N'-1} a'_i \\cdot \\prod_{j=1, j \\ne i}^{N'} \\mL_{ij}.\n\t\\end{align}\n\tThe resulting depth of this circuit amounts to\n\t\\begin{align*}\n\t\tT \\cdot d\\left(\\min(x,y)\\right) + d(\\LT) + \\ceil{\\log (N'-1)} + 1.\n\t\\end{align*}\n\tThis extraction circuit requires the following number of multiplications \n\t\\begin{align*}\n\t\tM(\\mathtt{Extraction}) = N' (N'-2).\n\t\\end{align*}\n\tThis implies that for small enough $N'$, Shaul's circuit~(\\ref{eq:shaul_minimum}) has a smaller depth or/and a smaller multiplication complexity than the circuit in~(\\ref{eq:our_minimum}).\n\tFurthermore, Shaul's circuit supports any length $N' > p$, whereas (\\ref{eq:our_minimum}) requires $N' \\le p$ such that $\\wt(\\mL[i])$ do not overflow modulo $p$.\n\n\tIn the experiments conducted in Section~\\ref{sec:impl-results}, we use the best of these approaches for given $N$, $T$ and $p$.\n        \n\t%%%%%%%%%%\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main_pets\"\n%%% End:\n", "meta": {"hexsha": "3ea99a57e50af3c9917fcf4b1103626a795245bb", "size": 10354, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/applications.tex", "max_stars_repo_name": "iliailia/comparison-circuit-over-fq", "max_stars_repo_head_hexsha": "bc48a9101278997f0847b6ace59c8f3b83884dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-03-24T07:58:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T00:41:08.000Z", "max_issues_repo_path": "paper/applications.tex", "max_issues_repo_name": "iliailia/comparison-circuit-over-fq", "max_issues_repo_head_hexsha": "bc48a9101278997f0847b6ace59c8f3b83884dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-03-24T03:03:11.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-01T09:23:59.000Z", "max_forks_repo_path": "paper/applications.tex", "max_forks_repo_name": "iliailia/comparison-circuit-over-fq", "max_forks_repo_head_hexsha": "bc48a9101278997f0847b6ace59c8f3b83884dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-19T16:28:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T16:28:37.000Z", "avg_line_length": 59.1657142857, "max_line_length": 405, "alphanum_fraction": 0.6709484257, "num_tokens": 3442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.8128673246376008, "lm_q1q2_score": 0.7396336756530595}}
{"text": "\\lab{Pseudospectra}{Pseudospectra}\n\\label{lab:pseudospectra}\n\\objective{The Pseudospectrum of a matrix is related to its eigenvalues.  The Pesudospectra of normal and non-normal matrices will be investigated.  We will plot pseudospectra and examine the characteristics of different types of matrices.}\n\n\n\n\\section*{Pseudospectra Definition}\nEigenvalues of matrices are extremely important, as there are a myriad of practical applications in which they are used.  In Quantum Mechanical systems, particularly, many operators can be represented by matrices, and the eigenvalues are the physical observables of the system.  Though we can make extremely precise measurements, there is often an $\\epsilon$-small error in measurements.  In this case, we are interested not just in the eigenvalues, but in the ``almost\" eigenvalues, the $\\epsilon$ region surrounding the actual eigenvalue.  The $\\epsilon$ region around the eigenvalues of a square matrix $A$ represents the $\\epsilon$-pseudospectrum (plural \\emph{pseudospectra}) of $A$, which can be denoted $\\sigma_{\\epsilon}(A)$.\n\nTo be more precise, the \\emph{point spectrum} of $A$ is defined as\n\\begin{align*}\n\t\\sigma(A)&=\\{z \\in \\mathbb{C}: det(zI-A)=0\\}\\\\\n\t&=\\{z \\in \\mathbb{C}: (zI-A)^{-1} \\text{ is undefined}\\}.\n\\end{align*}\nThe point spectrum of $A$ contains all the eigenvalues of $A$.  By convention, if $z$ is an eigenvalue of $A$, then $\\|(zI-A)^{-1}\\|=\\infty$.\nThe $\\epsilon$-pseudospectrum of a matrix is a generalization of its point spectrum, and for a matrix $A$ is defined as\n\\begin{equation}\n\t\\sigma_{\\epsilon}(A)=\\{z \\in \\mathbb{C}:\\|(zI-A)^{-1}\\| > \\epsilon^{-1}\\}.\n\\end{equation}\nNote that this definition requires the use of a matrix norm. Any matrix norm can be used, but in this lab we will use the norm induced by the 2-norm.\n\nIn the case of the 2-norm, the pseudospectrum has an equivalent definition:\n\\begin{equation}\n\t\\label{equ:spec}\n\t\\sigma_{\\epsilon}(A)=\\{z \\in \\mathbb{C}: z \\in \\sigma(A+E) \\text{ for some $E$ with } \\|E\\|<\\epsilon\\}.\n\\end{equation}\nWhen the entries of a matrix are slightly altered, changes in the point spectrum also occur.  The pseudospectrum can then be thought of as the set of eigenvalues that can result from small changes in the entries of a matrix.  If $A$ is an $n \\times n$ matrix, then we can use Equation \\ref{equ:spec} with some $n \\times n$ matrix $E$ satisfying $\\lVert E \\rVert < \\epsilon$ to find the $\\epsilon$-pseudospectrum of $A$, which will be a set of all complex numbers $z$ which are in the point spectrum of $A+E$.\n\nOne means of plotting the $\\epsilon$-pseudospectrum of $A$ is by generating several random matrices $E$ with norm $\\epsilon$, and then plotting the eigenvalues $z$ of all of them together.  The horizontal axis is the real part of $z$, with the vertical axis being the imaginary part of $z$.\n\n\\begin{figure}\n\\begin{center}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{ps_scatter1}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{ps_scatter2}\n\\end{subfigure}\n\\caption{Scatter plots representing the $\\epsilon$-pseudospectrum of the matrix given in Problem 1. The plot on the left uses $\\epsilon=10^{-6}$. The plot on the right uses $\\epsilon=10^{-3}$. In both plots, the eigenvalues of twenty matrices $A+E$ were plotted.}\n\\label{fig:ps_scatter}\n\\end{center}\n\\end{figure}\n\n\\begin{problem}\nComplete the function below for plotting the pseudospectrum of a matrix $A$ by plotting the point spectra of several matrices $A+E$, where $\\lVert E \\rVert = \\epsilon$. \n\n\\begin{lstlisting}\ndef ps_scatter_plot(A, epsilon=.001, num_pts=20):\n    '''Plots the 'poorman's pseudospectrum' of a matrix A\n    \n    Parameters:\n    A : ndarray of size (n,n)\n        The matrix whose pseudospectrum is to be plotted.\n    epsilon : float\n        The norm of the random matrices that are generated.\n        Defaults to 10**-3\n    num_pts : int\n        The number of matrices, E, that will be used in the\n        algorithm. Defaults to 20.       \n    '''\n\\end{lstlisting}\n\nTo get random matrices of the right norm, generate random matrices, divide them by their respective 2-norms, and then multiply by epsilon.\nHave your code plot the eigenvalues (point spectrum) of $A$ in one color, and the point spectrum of each $A+E$ in a different color.  The $\\epsilon$-pseudospectrum of $A$ can be though of as the region enclosed by your points.  Test your code on the 120x120 matrix:\n\\begin{equation}\n\t\\begin{pmatrix}\n\t\t0  &  i  &  -1  &  0  & \\cdots  &  0  \\\\\n\t\t-i &  0  &   i  & -1 & \\ddots  &  \\vdots  \\\\\n\t\t1  & -i  &   0  &  i &\\ddots&  0  \\\\\n\t\t0   & 1 & -i & 0 &\\ddots& -1\\\\\n\t\t\\vdots   & \\ddots    & \\ddots & \\ddots &\\ddots & i\\\\\n\t\t 0  &  \\cdots     &   0     &    1  &   -i  & 0\n\t\t\\end{pmatrix}\n\\label{prob:pseudoplot}\n\\end{equation}\n\nYour plot should resemble those in Figure \\ref{fig:ps_scatter}.\n\\end{problem}\n\nThis method of plotting, often called the ``poorman's pseudospectrum\", can only show the $\\epsilon$-pseudospectrum of $A$ for one value of $\\epsilon$ at a time, and even then it just provides a bound for the pseudospectrum. In many cases it does not give sufficient information, so we will now explain how to plot the $\\epsilon$-pseudospectrum using a more precise algorithm.\n\n\\section*{An Equivalent Pseudospectral Definition}\n\nRecall the following definition:\n\n\\begin{equation}\n\\sigma _{\\epsilon}(A) = \\{ z \\in \\mathbb{C} \\, : \\, \\lVert (zI_n-A)^{-1} \\rVert > \\epsilon ^{-1}\\}\t.\n\\end{equation}\n\nWhen we are using the induced 2-norm, we get that $\\lVert (zI_n-A)^{-1} \\rVert$ is the largest singular value of $(zI_n-A)^{-1}$.  This is also defined for a matrix $B$ as the square root of the largest eigenvalue of $B^{H} B$ \n This is equal to $1/s_{min}(zI_n-A)$, where $s_{min}(zI_n-A)$ is the smallest singular of $(zI_n-A)$. Hence, we can write\n\n\\begin{equation}\n\\sigma _{\\epsilon}(A) = \\{ z \\in \\mathbb{C} \\, | \\, s_{min}(A-zI_n) < \\epsilon \\}.\t\n\\end{equation}\n\n\n\\section*{The Lanczos Method}\n\nUsing this new definition for $\\sigma _{\\epsilon}(A)$, we can now plot pseudospectra using Lanczos iterations. Lanczos iterations make use of the Arnoldi method described in Lab \\ref{lab:kry_arnoldi} in order to more efficiently compute the smallest eigenvalue of $(zI_n-A)$. This method allows us to plot the pseudospectrum as a contour plot, where each contour corresponds to a fixed value of $\\epsilon$. The algorithm is provided below.\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Pseudospectrum}{$A, m, epsilon$}\n\t\\State $T \\gets schur(A)$\t\t\t\\Comment{Compute the Schur decomposition of A}\n\t\\State $eigsA \\gets diagonal(T)$\n\t\\State $xvals,yvals \\gets psgrid(eigsA,m)$\n\t\\State $sigmin \\gets \\zeros{m}{m}$\t\t\t\t\t\n\t\\For{$k=0\\ldots m-1$}\n\t    \\For{$j=0\\ldots m-1$}\t\t\n\t\t    \\State $T_1 \\gets (xvals[k]+i*yvals[j])I_n-T$  \n\t\t    \\State \\Comment{$I_n$ is the $n\\times n$ identity matrix.}\n\t\t    \\State $T_2 \\gets T1^*$        \\Comment{Compute the conjugate transpose.}\t\t\n\t\t    \\State $sigold \\gets 0$    \\Comment{Initialize variables.}\n\t\t    \\State $qold \\gets \\zeros{n}{1}$\n\t\t    \\State $beta \\gets 0$\n\t\t    \\State $H \\gets \\zeros{n}{n}$\n\t\t    \\State $q \\gets$ random, complex-valued $n \\times 1$ array of norm 1 \n\t\t    \\State \\Comment{Assume both real and imaginary parts are normally distributed}\n\t\t    \\For{$p=0 \\ldots N-2$}\n\t\t\t    \\State $b_1 \\gets$ solution to $T_2x = q$\t\n\t\t\t    \\State $b_2 \\gets$ solution to $T_1x = b_1$\n\t\t\t    \\State $v \\gets b_2 - beta*qold$\n\t\t\t    \\State $alpha \\gets real(q^**v)$\n\t\t\t    \\State $v \\gets v - alpha*q$\n\t\t\t    \\State $beta \\gets \\norm{v}$\n\t\t\t    \\State $qold \\gets q$\n\t\t\t    \\State $q \\gets v/beta$\n\t\t\t    \\State $H[p+1,p] \\gets beta$\n\t\t\t    \\State $H[p,p+1] \\gets beta$\n\t\t\t    \\State $H[p,p] \\gets alpha$\n\t\t\t    %\\State $eigsH \\gets$ eigenvalues of $H[:p+1,:p+1]$\n\t\t\t    \\State $sig \\gets$ absolute value of largest eigenvalue of $H[:p+1,:p+1]$\n\t\t\t    \\If{$|sigold/sig-1|<0.001$}\n\t\t\t        \\State Break    \\Comment{End loop if $sig$ is close to $sigold$}\n\t\t\t    \\EndIf\n\t\t\t    \\State $sigold \\gets sig$\n\t\t\t\\EndFor\n\t\t\t\\State $sigmin[j,k] \\gets \\sqrt{sig}$\n\t    \\EndFor\n\t\\EndFor\n\t\\State Plot the log of the values in $sigmin$ as a contour plot on the grid determined by $xvals$ and $yvals$.\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The Lanczos Method. This algorithm accepts a $n \\times n$ square matrix, $A$; a list of values for $\\epsilon$; and an accuracy measure of $m$. It computes the $10^{-\\epsilon}$-pseudospectrum of $A$ for each value of $\\epsilon$ and produces the contour plot on the grid determined by $xvals$ and $yvals$ as returned by psgrid().}\n\\label{alg:lanczos_method}\n\\end{algorithm}\n\nNote that while this algorithm gives better results than our previous method of plotting pseudospectra, it is much slower.\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=\\textwidth]{ps_contour}\n\\caption{Contour plot of the $\\epsilon$-pseudospectrum of the matrix given in Problem 1, with $\\epsilon=10^{-2},10^{-3},\\cdots,10^{-7}$. }\n\\label{fig:ps_contour}\n\\end{center}\n\\end{figure}\n\n\n\n\\begin{problem}\nFinish the function below for implementing Algorithm \\ref{alg:lanczos_method} in Python. Make the function also plot the eigenvalues of the matrix on the same plot.\n\n\\begin{lstlisting}\ndef ps_contour_plot(A, m = 20, epsilon_vals=None):\n    '''Plots the pseudospectrum of the matrix A as a contour plot.  Also,\n    plots the eigenvalues.\n    \n    Parameters:\n        A : square, 2D ndarray\n            The matrix whose pseudospectrum is to be plotted\n        m : int\n            accuracy\n        epsilon_vals : list of floats\n            If k is in epsilon_vals, then the epsilon-pseudospectrum\n            is plotted for epsilon=10**-k\n            If epsilon_vals=None, the defaults of plt.contour() are used\n            instead of any specified values.\n     '''\n    \n\\end{lstlisting}\n\nTest your code on the matrix from Problem 1. Your plot should look like Figure \\ref{fig:ps_contour}. You will need to choose a grid on which to plot the values computed in this algorithm. Use a grid that is roughly twice as large as one needed to plot the eigenvalues. To make your code run faster, make sure to use functions designed for Hermitian or triangular matrices whenever possible.\n\\begin{enumerate}\n\\item Plot the eigenvalues and contour lines on a complex plane.\n\\item $m$ defaults to 20 but if you want the plot to look like Figure \\ref{fig:ps_contour}, you will need m to be close to 150.  Note that this will take a while longer.\n\\item In order to plot the contour lines.  Use the following code.\n\\begin{lstlisting}\nplt.contour(xvals,yvals,np.log10(sigmin), levels=epsilon_vals)\n\\end{lstlisting}\n\\end{enumerate}\n\n\\end{problem}\n\n\\section*{Hermitian, Normal, and Nonnormal Matrices}\nRecall that a matrix $A$ is Hermitian if it is equal to its conjuage transpose, i.e. $A^{H} = A$.  All the eigenvalues of Hermitian matrices are real.  However, if the elements change slightly (adding $E$), these matrices quickly fall out of the class of Hermitian matrices, and the $\\epsilon$-pseudospectra may gain an imaginary component.\n\nA broader class of matrices that includes all Hermitian matrices is the class of \\emph{normal matrices}.  A normal matrix commutes with its conjugate transpose, i.e. $A A^{H} = A^{H} A$. In the case that $A$ is normal, it can be shown that the $\\epsilon$-pseudospectrum consists of the union of circular sets about each of the eigenvalues of $A$. When $A$ is not a normal matrix, the pseudospectrum can have more varied shapes. Because of this, plotting the pseudospectrum of a nonnormal matrix can provide more information about its behavior.\n\nFigure \\ref{fig:ps_normal} provides an example of this. The plots show the pseudospectra of the matrices:\n\n\\begin{equation}\n\tB = \\begin{pmatrix}\n\t\t-1 & 0 & 0\\\\\n\t\t0 & 1 & 0\\\\\n\t\t0 & 0 & i\n\t\\end{pmatrix}, \\qquad \tB' = \\begin{pmatrix}\n\t\t-1 & -1 & -1\\\\\n\t\t0 & 1 & 1\\\\\n\t\t0 & 0 & i\n\t\\end{pmatrix}.\n\\end{equation}\n\nNote that these matrices have the same set of eigenvalues, but that while $B$ is normal, $B'$ is not. The plot of the pseudospectrum of $B$ shows the expected circular regions, but the plot for $B'$ lacks such symmetry. Another example of this can be seen in Figure \\ref{fig:ps_scatter}. The pseudospectrum does not expand out from all of the eigenvalues evenly. Most of the region contained in the pseudospectrum lies on the sides of the plot, and not close to the center.\\\\\n\nBecause the pseudospectra of normal matrices behave so consistently, the study of pseudospectra focuses on nonnormal matrices. Pseudospectra can also be used to study infinite-dimensional linear operators, but different methods are required for plotting their pseudospectra.\n\n\\begin{figure}\n\\begin{center}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{ps_normal}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{ps_nonnormal}\n\\end{subfigure}\n\\caption{Plots of the Pseudospectrum of two matrices with the same eigenvalues. The plot on the left is for a normal matrix, and the one on the right is for a nonnormal matrix. The contours correspond to $\\epsilon=10^{-0.4},10^{-0.8},10^{-1.2}$}\n\\label{fig:ps_normal}\n\\end{center}\n\\end{figure}\n\n\\begin{problem}\nUsing your function from problem \\ref{prob:pseudoplot}, investigate how the pseudospectra of Nonnormal, Hermitian, and Normal matrices differ.  To do so, use the matrix given in problem \\ref{prob:pseudoplot} as the Nonnormal matrix.  \n\nFor the Hermitian matrix, change the subdiagonal of $1$s to be $-1$.  \n\nFor the Normal matrix, reset all of the subdiagonal entries to be zero (change the $1$ diagonal and $-i$ diagonal to zeros).  Set all of the diagonal entries to be random complex values (so as to get different eigenvalues).\n\nPlot your results.\n\\end{problem} \n\n\n% ~\\cite{Tufte2005}\n", "meta": {"hexsha": "5d836410d5ba3d73e14dcf0b38d810490af3f5b4", "size": 13849, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Orphans/Pseudospectra/Pseudospectra.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Orphans/Pseudospectra/Pseudospectra.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Orphans/Pseudospectra/Pseudospectra.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 56.0688259109, "max_line_length": 733, "alphanum_fraction": 0.7094375045, "num_tokens": 4082, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.9046505370289059, "lm_q1q2_score": 0.7396191969918876}}
{"text": "\\subsection{Strain Homogenization}\n\nThe derivation for the homogenized strain tensor, $\\left< \\boldsymbol{\\epsilon}\\right>$, begins in a similar manner to the homogenized stress tensor derivation with the familiar definition of the spatial average:\n\n\\begin{equation}\n\\langle\\boldsymbol{\\epsilon}\\rangle=\\frac{1}{A^{h}}\\int_{\\Omega^{h}}\\boldsymbol{\\epsilon}^m dA\\label{eqn:strain2}\n\\end{equation}\n\nAt this point, it becomes convenient to assume a small displacement formulation of strain. This displacement assumption limits the applicability of the strain homogenization, but in the context of large scale geomechanics, this assumption remains reasonable. As such, the linear infinitesimal strain tensor can be written in terms of the displacement vector, $\\mathbf{u}^m$:\n\n\\begin{equation}\n\\boldsymbol{\\epsilon}^m=\\frac{1}{2}\\left[\\nabla\\mathbf{u}^m+\\left(\\nabla^\\top \\mathbf{u}^m\\right)\\right]\\label{eqn:strain1}\n\\end{equation}\n\nThe above integral can be converted to the following boundary integral using the divergence theorem:\n\n\\begin{equation}\n\\langle\\boldsymbol{\\epsilon}\\rangle=\\frac{1}{2A^{h}}\\oint_{\\Gamma^{h}}\\left[\\mathbf{u}^m\\otimes\\mathbf{n}+\\mathbf{n}\\otimes\\mathbf{u}^m\\right]d\\Gamma\\label{eqn:strain5-1}\n\\end{equation}\n\nwhere $\\mathbf{n}$ is the outward pointing normal to $\\Gamma_h$.\n\nWhen $\\Gamma_h$ is defined by a set of line segments over which the displacement is also linear, the boundary integral can be rewritten as a summation over each of the $N$ boundary segments. Let $\\bar{\\mathbf{u}}^m_{I}$ denote the average displacement along the $I^{th}$ boundary segment of the homogenization boundary, which is calculated as the average of the two nodal displacements defining the boundary of each segment. Let $\\mathbf{n}_{I}$ represent the outward pointing normal to the $I^{th}$ boundary segment on the homogenization boundary.  Let the length of boundary segment $I$ be denoted by $L_{I}$. The homogenized strain can be rewritten as\n\n\\begin{equation}\n\\langle\\boldsymbol{\\epsilon}\\rangle=\\frac{1}{2A^{h}}\\sum_{I=1}^{N}\\left[\\bar{\\mathbf{u}}^m_{I}\\otimes\\mathbf{n}_{I}+\\mathbf{n}_{I}\\otimes\\bar{\\mathbf{u}}^m_{I}\\right]L_{I}\\label{eqn:strain7}\n\\end{equation}\n", "meta": {"hexsha": "4077e779c9a2444fdf61cd89a8002e20060db4c2", "size": 2181, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "subsection_strainHomogenization.tex", "max_stars_repo_name": "yetisir/up-scaling-dem-simulations", "max_stars_repo_head_hexsha": "9c9043effdb72a608ffec11726af97154751722e", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "subsection_strainHomogenization.tex", "max_issues_repo_name": "yetisir/up-scaling-dem-simulations", "max_issues_repo_head_hexsha": "9c9043effdb72a608ffec11726af97154751722e", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "subsection_strainHomogenization.tex", "max_forks_repo_name": "yetisir/up-scaling-dem-simulations", "max_forks_repo_head_hexsha": "9c9043effdb72a608ffec11726af97154751722e", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-29T23:14:09.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-29T23:14:09.000Z", "avg_line_length": 77.8928571429, "max_line_length": 654, "alphanum_fraction": 0.7624942687, "num_tokens": 631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7395167782058224}}
{"text": "A wide variety of physical phenomena are modeled in the space-time domain by partial differential equations. The purpose of this section is to review generalities about PDEs and suited strategies depending on the nature of the equations so that solutions can be derived.\n\\subsection{General concepts}\nA system of partial differential equations can be written by means of a vector operator $\\vect{\\Gc}$ of independent and dependent variables $(x_1,...,x_N)$ and $(u_1,...,u_I)$:\n\\begin{equation}\n  \\label{eq:diff_operator}\n  \\vect{\\Gc}\\(x_1,...,x_N,u_1,...,u_I,\\drond{u_1}{x_1},..., \\drond{^Mu_I}{x_N^M}\\) = \\vect{0}\n\\end{equation}\nThe dimension of the system is given by the size $I$ of the array $\\vect{\\Uc}^T=[u_1,...,u_I] \\in \\Rbb^I$, referred to as the \\textit{unknown vector}. The highest derivative of the unknown vector in the system defines the \\textit{order of the system} $M$. In equation \\eqref{eq:diff_operator} and in what follows, sans-serif symbols refer to matrices while calligraphic symbols stand for column arrays. Furthermore, the partial derivatives of a quantity $u$ with respect to a variable $x$ may be written $u_x$ when there is no ambiguity. Making use of index notation and the convention of implicit summation over repeated indices, a system of partial differential equations reads:\n\\begin{equation*}\n   \\sum_{k=1}^{N} \\sum_{p=1}^{M}\\Asf_{ij}^p \\drond{^p\\Uc_j}{x_k^p} + \\Sc_i = 0\n\\end{equation*}\nor equivalently, in matrix form:\n\\begin{equation}\n  \\label{eq:diff_system_matrix}\n  \\sum_{k=1}^{N}\\sum_{p=1}^{M}\\tens{\\Asf}^p \\drond{^p\\vect{\\Uc}}{x_k^p} + \\vect{\\Sc} =  \\vect{0}\n\\end{equation}\nCoefficients matrices $\\tens{\\Asf}^p$ and the vector $\\vect{\\Sc}$ may depend on independent variables and the unknown vector ($x_1,...,x_N,\\vect{\\Uc}$) leading to different types of partial differential systems. Namely, whether those terms are functions of the $x_k$ or not leads respectively to \\textit{linear systems with variable coefficients} or to \\textit{linear systems with constant coefficients}. The system remains \\textit{linear} if $\\vect{\\Sc}$ depends linearly on $\\vect{\\Uc}$, and is \\textit{semi-linear} if the relation is non-linear. Finally, if $\\tens{\\Asf}^p$ depends on the vector $\\vect{\\Uc}$ and its derivatives up to order $M-1$, the system is called \\textit{quasi-linear}.\n\n\nThe \\textit{Cauchy problem} consists in finding a solution $\\vect{\\Uc}$ of system \\eqref{eq:diff_system_matrix} that satisfies a set of given prescribed values. Geometrically speaking, the solution of such a problem can be seen as the building of a hyper-surface of $\\Rbb^{I+N}$, hence the term of \\textit{integral surface} for $\\vect{\\Uc}$. Such a problem can be reduced to that of solving a first-order Cauchy problem by using suitable changes of variables \\cite[p.54]{PDEs}, we will therefore focus on first-order PDEs.\n\n\\subsection{Notion of characteristics -- Hyperbolic problems}\nThe theorem of \\textit{Cauchy--Kowalewski} locally ensures the existence of solutions of a Cauchy problem for partial differential systems and is based on the restrictive requirement of analytic coefficient matrices and initial data (see \\cite[p.46]{PDEs}). The case of first-order systems however, only requires continuity and differentiability conditions and is based on the concept of \\textit{characteristics}, which makes the development of a solution more flexible.\n\n\\subsubsection*{First-order quasi-linear equations}\nTo illustrate the aforementioned notions, we consider the first-order quasi-linear PDE with independent variables $x$ and $t$:\n\\begin{equation}\n  \\label{eq:1st_order_pde}\n   a u_x + b u_t  = c\n\\end{equation}\nwhere coefficients $a$ and $b$ are such that $a^2 + b^2 \\neq 0$. Given values of $u$ are prescribed along a curve defined by means of a parameter $\\eta$ in the $(x,t)$ plane as $\\Cscr_0:(x(\\eta),t(\\eta))$, so that $u(x(\\eta),t(\\eta))$ draws a curve $\\Cscr$ in the space $(x,t,u)$. \n%In what follows, $\\Cscr$ is referred to as the \\textit{initial curve}.\nWe assume that $\\Cscr_0$ is regular, namely $\\ddroit{x}{\\eta}^2 + \\ddroit{t}{\\eta}^2 \\neq 0$, and that one of the derivatives, say $\\ddroit{t}{\\eta}$, does not vanish. Figure \\ref{fig:initial_curve} shows an example of such an \\textit{initial curve} $\\Cscr$ prescribing values of $u$ along a parametrized curve of the $(x,t)$ plane.\n%The value of $u$ on $\\Cscr$ being used as a starting point for the solution of the Cauchy problem, $\\Cscr$ is referred to as the \\textit{initial curve}. \n\\begin{figure}[h]\n  \\centering\n  \\input{chapter2/pgfFigures/initialCurve}\n  \\caption{Example of initial curve $\\Cscr$ in the $(x,t,u)$ space and its projection $\\Cscr_0$ in the $(x,t)$ plane.}\n  \\label{fig:initial_curve}\n\\end{figure}\nWith data given along $\\Cscr$, the Cauchy problem is equivalent to that of finding a surface $u(x,t)$ that contains the initial curve and satisfies \\eqref{eq:1st_order_pde}.\nThus, one seeks the partial derivatives $u_x$ and $u_t$ of $u$ on $\\Cscr$ in order to extend the given data into a strip in the neighborhood of the initial curve.\nThe total derivative of $u$ along $\\Cscr$ being:\n\\begin{equation}\n  \\label{eq:dtot_u}\n  \\ddroit{u}{\\eta}=u_x\\ddroit{x}{\\eta}+u_t\\ddroit{t}{\\eta}\n\\end{equation}\none gets, after multiplying the previous equation by $d\\eta$, the following relation between the partial derivatives of $u$ on the initial curve:\n\\begin{equation*}\n  u_t= \\ddroit{u}{t} - u_x\\ddroit{x}{t}\n\\end{equation*}\nThen, equation \\eqref{eq:1st_order_pde} can be rewritten as:\n\\begin{equation}\n  \\label{eq:normal_form_pde}\n  (a - b\\ddroit{x}{t})u_x = c - b\\left.\\ddroit{u}{t}\\right|_{t\\in\\Cscr_0}\n\\end{equation}\nThe right-hand side of equation \\eqref{eq:normal_form_pde} is known along $\\Cscr$ so that the Cauchy problem admits a unique solution $u_x$ if and only if:\n\\begin{equation}\n  \\label{eq:non-characteristics}\n  \\ddroit{x}{t}\\neq \\frac{a}{b}\n\\end{equation}\nAn initial curve satisfying the condition \\eqref{eq:non-characteristics} is a \\textit{non-characteristic curve} and enables to uniquely determine a solution of the Cauchy problem. On the other hand, an initial curve defined such that $\\ddroit{x}{t} = \\frac{a}{b}$ is a \\textit{characteristic curve} and yields infinitely many solutions \\cite[p.65]{Courant}. \n\n%A \\textit{non-characteristic curve} is an initial curve satisfying the condition \\eqref{eq:non-characteristics}, otherwise it is a \\textit{characteristic curve}. \n\n\n\\subsubsection*{Geometrical representation of characteristic curves}\nConsider a partial differential equation of the form \\eqref{eq:1st_order_pde}, and prescribed values of $u$ along a characteristic curve $\\Cscr$. Since one cannot find a unique solution of the Cauchy problem in this case, infinitely many integral surfaces $u^{(i)}(x,t)$ with normal vectors $\\vect{n}^{(i)}=[u^{(i)}_x,u^{(i)}_t,-1]$ can intersect $\\Cscr$. Those integral surfaces satisfy equation \\eqref{eq:1st_order_pde} and hence, $\\vect{n}^{(i)}\\cdot \\vect{w}=0$ where $\\vect{w}=[a,b,c]$, so that the set of tangent planes to solutions $u^{(i)}(x,t)$ forms a fan whose axis is $\\vect{w}$.\nThis situation is depicted in figure \\ref{fig:plan_fan} for which an initial characteristic straight line $\\Cscr$ is contained by integral surfaces satisfying a PDE of the form \\eqref{eq:1st_order_pde}.\n%Let $u(x,t)$ be a surface in the $(x,t,u)$ space which normal vector is $\\vect{n}=[u_x,u_t,-1]$. This surface is an integral surface if it is a solution of equation \\eqref{eq:1st_order_pde} and hence, if $\\vect{n}\\cdot \\vect{w}=0$ with $\\vect{w}=[a,b,c]$.\n%This situation is depicted in figure \\ref{fig:plan_fan} for which an initial characteristic straight line $\\Cscr$ is contained by integral surfaces satisfying some pde of the form \\eqref{eq:1st_order_pde}.\n% Figure \\ref{fig:plan_fan} shows a collection of integral surfaces for some partial differential equation \\eqref{eq:1st_order_pde} with prescribed $u$ along a straight line $\\Cscr$.\n% Then, the set of tangent planes to those solutions $u^{(i)}(x,t)$ forms a fan of planes which axis is $\\vect{w}$.\n\\begin{figure}[h!]\n  \\centering\n  \\input{chapter2/pgfFigures/plan_fan}\n  \\caption{Examples of integral surfaces passing through the same curve $\\Cscr$ defined such that $t=\\mathrm{constant}$ and $u=\\mathrm{constant}$ along $\\Cscr$.}\n  \\label{fig:plan_fan}\n\\end{figure}\n\n$\\newline$\n\\textit{Characteristic line elements}, tangent to all integral surfaces $u^{(i)}(x,t)$ are then defined as:\n\\begin{equation}\n  \\label{eq:monge_axis}\n  \\matrice{dx \\\\ dt \\\\ du} = \\matrice{a \\\\ b \\\\c}\n\\end{equation}\nIntroduction of a parameter $\\eta$ and integration of equation \\eqref{eq:monge_axis} yield a one-parameter family of characteristic curves of the PDE:\n\\begin{equation*}\n  x=x(\\eta) \\quad ; \\quad t=t(\\eta) \\quad ; \\quad u=u(\\eta)\n\\end{equation*}\nHence, a characteristic curve is tangent at every point to all the integral surfaces, and an infinity of integral surfaces cross one characteristic curve. As a consequence, if the initial curve is a characteristic curve, infinitely many integral surfaces contain it so that the Cauchy problem cannot be solved.\nHowever, the following statement holds \\cite[p.63]{Courant}:\n\\begin{theorem}[Courant]\n  \\label{th:integral_surface_generated}\n  Every surface $u(x,t)$ generated by a one-parameter family of characteristic curves is an integral surface.\n\n  Conversely, every integral surface is generated by a one-parameter family of characteristic curves.\n\\end{theorem}\nThis theorem will be used in what follows to solve the Cauchy problem.\n\n%\\subsection{The method of characteristic}\n\\subsubsection*{First-order quasi-linear systems}\nThe concept of characteristic curves is now extended to first-order quasi-linear systems of dimension $I$.\nConsider the following system written in matrix form:\n\\begin{equation}\n  \\label{eq:1st_order_quasi-linear_syst}\n  \\Absf^t\\(x,t,\\vect{\\Uc}\\) \\: \\vect{\\Uc}_t + \\Absf^x\\(x,t,\\vect{\\Uc}\\)\\: \\vect{\\Uc}_x + \\vect{\\Sc} = \\vect{0}\n\\end{equation}\nSimilarly to quasi-linear PDEs, given values of $\\Ucb$ are prescribed along a regular curve $\\Cscr_0:(x(\\eta),t(\\eta))$ defining an initial curve $\\Ucb(x(\\eta),t(\\eta))$ of the $(x,t,\\Ucb)$ space. The Cauchy problem consists in finding all the derivatives of $\\Ucb(x,t)$ such that equation \\eqref{eq:1st_order_quasi-linear_syst} is satisfied in the vicinity of $\\Cscr$.\nMaking use of the total derivative of $\\Ucb$ along the initial curve:\n\\begin{equation}\n  \\label{eq:dtot_Uvect}\n  \\ddroit{\\Ucb}{\\eta}=\\Ucb_x\\ddroit{x}{\\eta}+\\Ucb_t\\ddroit{t}{\\eta} \\quad \\rightarrow \\quad \\Ucb_t = \\left.\\ddroit{\\Ucb}{t}\\right|_{t\\in\\Cscr_0} - \\Ucb_x  \\ddroit{x}{t}\n\\end{equation}\nsystem \\eqref{eq:1st_order_quasi-linear_syst} can be rewritten:\n\\begin{equation}\n  \\label{eq:normal_form}\n  \\( \\Absf^x - \\lambda \\Absf^t \\) \\vect{\\Uc}_x + \\Scb + \\Absf^t\\left.\\ddroit{\\Ucb}{t}\\right|_{t\\in\\Cscr_0} = \\vect{0}\n\\end{equation}\nwhere:\n\\begin{equation}\n  \\label{eq:lambda_slope}\n  \\lambda=\\ddroit{x}{t}\n\\end{equation}\nWith $\\Scb$ and $\\Absf^t\\left.\\ddroit{\\Ucb}{t}\\right|_{t\\in\\Cscr_0}$ known along $\\Cscr_0$, the Cauchy problem admits a unique solution $\\vect{\\Uc}_x$ along $\\Cscr$ if the determinant of the system does not vanish, that is:\n\\begin{equation}\n  \\label{eq:characteristic_determinant}\n  D=\\abs{\\Absf^x - \\lambda \\Absf^t} \\ne 0\n\\end{equation}\nwhere D is called the \\textit{characteristic determinant} of system \\eqref{eq:1st_order_quasi-linear_syst}. If D does not have real roots along $\\Cscr_0$, the problem is said \\textit{elliptic} and the Cauchy problem can be solved. Indeed, in that case the knowledge of $\\Ucb$ along the initial curve allows the computation of derivatives and hence, the building of an integral strip defined by $\\Ucb,\\Ucb_x,\\Ucb_t$. If the characteristic determinant admits $I$ real roots on the other hand, system \\eqref{eq:normal_form} can no longer be solved. Those eigenvalues come along with left and right eigenvectors respectively defined as:\n\\begin{equation}\n  \\label{eq:eigenvectors}\n  \\Lc^k_i  \\Asf^x_{ij} = \\lambda_k \\Lc^k_i \\Asf^t_{ij} \\quad ; \\quad \\Asf^x_{ij}\\Rc^k_j = \\lambda_k \\Asf^t_{ij}\\Rc^k_j \\qquad k=1,...,I\n\\end{equation}\n\\begin{remark}\n  Note that eigenvectors can be stored as matrices $\\Rbsf$ and $\\Lbsf$ where $\\Rsf_{ij}=\\Rc^j_i$ and $\\Lsf_{ij}=\\Lc_j^i$.\n\\end{remark}\n\n\\begin{definition}\n  \\label{def:hyperbolic_system}\n  A first-order system of $I$ partial differential equations is said \\textbf{hyperbolic} if it admits real eigenvalues and $I$ independent eigenvectors \\cite{Courant}.\nFor those problems, one can draw a set of one-parameter families of characteristic curves $\\varphi^k$ in the $(x,t)$ plane by integrating the relations $\\lambda_k=dx/dt$ ($1 \\leq k \\leq I$).\n\\end{definition}\n\n\\begin{example}\n  \\label{ex:charac1}\n  Consider the first-order system with variable coefficients\n\\begin{equation*}\n \\matrice{x &0 \\\\0 &-x} \\drond{}{t} \\matrice{\\Uc_1 \\\\ \\Uc_2} + \\drond{}{x}\\matrice{\\Uc_1 \\\\ \\Uc_2} = \\matrice{0 \\\\0}\n\\end{equation*}\nwhose characteristic determinant \\eqref{eq:characteristic_determinant} is:\n\\begin{equation*}\n  (1-\\lambda x)(1+\\lambda x)=0\n\\end{equation*}\nWe thus have two solutions $\\lambda_{1,2}=\\pm 1/x$ leading, by integration of \\eqref{eq:lambda_slope}, to two one-parameter families of characteristic curves:\n\\begin{equation*}\n  t_1(x)=\\frac{1}{2}x^2+c_1  \\quad \\text{and} \\quad t_2(x)=-\\frac{1}{2}x^2+c_2 \n\\end{equation*}\nThose curves are drawn in figure \\ref{fig:exampleCharac}\\subref{subfig:curve_lines} for several values of integration constants $c_1$ and $c_2$.\n\\end{example}\n\\begin{example}\n  \\label{ex:charac2}\n  Consider now the first-order system with constant coefficients\n\\begin{equation*}\n \\matrice{1 &0 \\\\0 &2} \\drond{}{t} \\matrice{\\Uc_1 \\\\ \\Uc_2} + \\drond{}{x}\\matrice{\\Uc_1 \\\\ \\Uc_2} = \\matrice{0 \\\\0}\n\\end{equation*}\nwhose eigenvalues, according to equation \\eqref{eq:characteristic_determinant} satisfy\n\\begin{equation*}\n  (1 - \\lambda )(1- 2\\lambda)=0\n\\end{equation*}\nTwo real roots exist $\\lambda_1=1 \\: ; \\: \\lambda_2=1/2$, leading by integration of \\eqref{eq:lambda_slope} to two one-parameter families of straight lines:\n\\begin{equation*}\n  t_1(x)=x+c_1  \\quad \\text{and} \\quad t_2(x)=2x+c_2 \n\\end{equation*}\nUnlike example \\ref{ex:charac1}, coefficient matrices do not depend on independent variables, thus yielding characteristic straight lines in the $(x,t)$ plane (see \\ref{fig:exampleCharac}\\subref{subfig:straight_lines}).\n\\end{example}\n\\begin{figure}[h]\n  \\centering\n  \\subcaptionbox{Example \\ref{ex:charac1}: $\\lambda_{1,2}=\\pm 1/x$\\label{subfig:curve_lines}}{\\input{chapter2/pgfFigures/exampleCharac}}\n  \\subcaptionbox{Example \\ref{ex:charac2}: $\\lambda_{1}=1 \\:\\text{and} \\: \\lambda_2=1/2$\\label{subfig:straight_lines}}{\\input{chapter2/pgfFigures/exampleCharac_const}}\n  \\caption{Family of characteristic curves corresponding to the eigenvalues of the first-order systems given in examples \\ref{ex:charac1} and \\ref{ex:charac2}.}\n  \\label{fig:exampleCharac}\n\\end{figure}\n\n\\subsection{The method of characteristics}\nAs theorem \\ref{th:integral_surface_generated} states, an integral surface is generated by a one-parameter family of characteristic curves. Therefore the knowledge of those curves enables the building of the solution of the Cauchy problem. Indeed, the projection of the quasi-linear system \\eqref{eq:1st_order_quasi-linear_syst} onto the \\textit{left eigenbasis} or \\textit{left characteristic basis} leads to:\n\\begin{equation*}\n  \\vect{\\Lc}^k \\( \\Absf^t \\vect{\\Uc}_t + \\Absf^x\\vect{\\Uc}_x \\) + \\vect{\\Lc}^k \\vect{\\Sc}= \\vect{0}\n\\end{equation*}\n%Introduction of the definition of left eigenvectors \\eqref{eq:eigenvectors} then yields:\nwhere $\\Lcb^k$ satisfies \\eqref{eq:eigenvectors}, and hence:\n\\begin{equation*}\n  \\vect{\\Lc}^k  \\Absf^t \\( \\vect{\\Uc}_t +\\lambda_k \\vect{\\Uc}_x   \\) + \\vect{\\Lc}^k \\vect{\\Sc}=\\vect{0}\n\\end{equation*}\nIn this equation, the \\textit{directional derivative} of $\\vect{\\Uc}$ along the $k$th characteristic curve $\\varphi^k$ arises, namely:\n\\begin{equation*}\n \\left.\\ddroit{\\Ucb}{t}\\right|_{t\\in\\varphi^k} = \\Ucb_t + \\lambda_k \\Ucb_x   \n\\end{equation*}\nThus, along a characteristic curve a system of partial differential equations reduces to a system of \\textit{Ordinary Differential Equations} (ODEs) composed of the following \\textit{characteristic equations}:\n\\begin{equation}\n  \\label{eq:PDEs_ODEs}\n  \\vect{\\Lc}^k  \\(\\Absf^t \\ddroit{\\Ucb}{t} + \\Scb \\)=\\vect{0}\n\\end{equation}\nIntegration of equations \\eqref{eq:PDEs_ODEs} yields a set of \\textit{integral curves} from which the Cauchy problem can be solved.\n%It then comes out that the Cauchy problem can be solved as the system \\eqref{eq:PDEs_ODEs}.\nIndeed, the solution at a point of the $(x,t)$ plane can be determined by tracing backward the characteristic curves to the initial curve and integrating ODEs \\eqref{eq:PDEs_ODEs} along those paths according to the \\textit{method of characteristics}.\nNote that if $\\Scb$ is zero, then $\\Ucb$ is constant along characteristic curves. \n\nTo illustrate the method, let us consider again the quasi-linear system of example \\ref{ex:charac1} for which the Cauchy problem is built by prescribing initial conditions along the $x$-axis. Note that \"initial conditions\" have now a physical meaning since they are defined at $t=0$, the Cauchy problem is then an \\textit{Initial Value Problem (IVP)}. Through a point $(x^*,t^*)$ pass two characteristic curves, each belonging to a different one-parameter family. The solution at this point can be determined by integrating the ODE corresponding to the first (\\textit{resp. second}) eigenvalue of the system between $(x^1,0)$ (\\textit{resp. $(x^2,0)$}) and $(x^*,t^*)$. The singularity of hyperbolic problems can hence be circumvented by using the characteristic structure in order to determine a unique solution. \n\\begin{figure}[h]\n  \\centering\n  \\input{chapter2/pgfFigures/characMethod2x2}\n  \\caption{Domain of dependence of the solution at $(x^*,t^*)$ for the system of example \\ref{ex:charac1}.}\n  \\label{fig:charac_method2x2}\n\\end{figure}\nWe see that only a segment of the initial curve has an influence on the solution at a given point. Namely, the intersections of the initial curve and characteristic curves with the highest and the lowest slopes define the \\textit{domain of dependence} of the solution at this point (see figure \\ref{fig:charac_method2x2}). This property of hyperbolic problems implies the existence of waves that propagate information at finite speeds corresponding to the eigenvalues of a quasi-linear form. The theory presented so far will be applied in what follows to solid mechanics.\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% ispell-local-dictionary: \"american\"\n%%% TeX-master: \"../mainManuscript\"\n%%% End:\n", "meta": {"hexsha": "c0931d18297599ab23c756f918ea6928979b1192", "size": 18676, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/chapter2/PDEs.tex", "max_stars_repo_name": "adRenaud/research", "max_stars_repo_head_hexsha": "2f0062a1800d7a17577bbfc2393b084253d567f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-18T14:52:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-18T14:52:03.000Z", "max_issues_repo_path": "manuscript/chapter2/PDEs.tex", "max_issues_repo_name": "adRenaud/research", "max_issues_repo_head_hexsha": "2f0062a1800d7a17577bbfc2393b084253d567f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-01-07T13:11:11.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-07T13:11:11.000Z", "max_forks_repo_path": "manuscript/chapter2/PDEs.tex", "max_forks_repo_name": "adRenaud/research", "max_forks_repo_head_hexsha": "2f0062a1800d7a17577bbfc2393b084253d567f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 83.0044444444, "max_line_length": 814, "alphanum_fraction": 0.7422895695, "num_tokens": 5614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.739478754370688}}
{"text": "\\section{Sparse Coding}\n\n\\subsection*{Orthogonal Basis}\nFor $x$ and orthogonal $U = (u_1|..|u_{D}) \\in \\mathbb{R}^{DxD}$. \nEncoding $\\mathbf{z = U^\\top x}$. \nDecoding $\\mathbf{x = U z = UU^\\top x  = x }$.\nTresholding $ \\mathbf{\\hat{x}} = \\mathbf{U\\hat{z}}$, $\\hat{z}_i = z_i$ if $ \\lvert z_i \\rvert > \\epsilon$ else 0. \nReconstr. Error $\\|\\mathbf{x}-\\mathbf{\\hat{x}}\\|^2 = \\|\\sum_{d\\notin\\sigma}\\langle\\mathbf{x},\\mathbf{u}_d\\rangle \\mathbf{u_d} \\|^2 =  \\sum_{d\\notin\\sigma}\\langle\\mathbf{x},\\mathbf{u}_d\\rangle ^2$. Proof: $\\|\\sum x_i \\|^2 = \\sum \\|x_i \\|^2$ if $x_i$ orthogonal. Advantages: efficient inverse, energy/length preservation. \\\\\n\\textbf{Haar wavelets:} \\\\\nscaling: $[1,1,1,1]$, mother wavelet: $[1,1,-1,-1]$, dilated: $[1,-1,0,0]$, translated: $[0,0,1,-1]$.\n\n\\textbf{Fourier vs Wavelets:}\\\\\n\\textbullet Fourier: good for periodic signals, global support, no time info/only frequencies themselves. \\\\\n\\textbullet Wavelets: good for localized signals like abrupt changes/irregularities, represents a signal in time and frequency domain. \n\n\\subsection*{Overcomplete Basis}\n$\\mathbf{U} \\in \\mathbb{R}^{D \\times  L}$ for \\# atoms $ = L > D = \\mathsf{dim}\\text{(data)}$. $x \\in \\mathbb{R}^D, z \\in \\mathbb{R}^L$ because $Uz=x$.\nEncoding ill-posed problem $\\rightarrow$ add constraint $\\mathbf{z}^\\star \\in \\argmin_\\mathbf{z} \\lVert \\mathbf{z} \\rVert_0$ s.t. $\\mathbf{x} = \\mathbf{Uz}$. NP-hard and non-convex \\\\ $\\rightarrow$ approx with Basis pursuit i.e relax to 1-norm (convex) or with Matching Pursuit.\n\n\\textbf{Coherence} \\\\\n$m(\\mathbf{U}) = \\max_{i,j:\\, i \\neq j} | \\mathbf{u}_i^\\top \\mathbf{u}_j |$ \\\\\n\\textbf{Matching Pursuit (MP)}\na greedy approximation algorithm.\nObjective: $\\mathbf{z}^\\star \\in \\argmin_{\\mathbf{z}} \\|\\mathbf{x} - \\mathbf{Uz} \\|_2$, s.t. $\\|\\mathbf{z}\\|_0 \\leq K$\n\\begin{inparaenum}[\\color{red}1.]\n\t\\item init: $z \\leftarrow 0, r \\leftarrow x$\n\t\\item while $\\|\\mathbf{z}\\|_0 < K$ do\n\t\\item select atom with max correlation $d^\\star = \\argmax_d |\\langle \\mathbf{u}_d, \\mathbf{r} \\rangle|$\n\t\\item update coefficients: $z_{d^\\star} \\leftarrow z_{d^\\star} + \\langle \\mathbf{u}_{d^\\star}, \\mathbf{r} \\rangle$\n\t\\item update residual: $\\mathbf{r} \\leftarrow \\mathbf{r} - \\langle \\mathbf{u}_{d^\\star}, \\mathbf{r} \\rangle \\mathbf{u}_{d^\\star}$.\n\\end{inparaenum}\n\n\\textbf{Compressive Sensing}: Compress data while gathering:\n\\begin{inparaitem}[\\color{red}\\textbullet]\n  \\item $\\mathbf{x} \\in \\mathbb{R}^D$, $K$-sparse in o.n.b. $\\mathbf{U}$. $\\mathbf{y} \\in \\mathbb{R}^M$ corresponds to $M$ lin. combinations/measurements of signal; $\\mathbf{y} = \\mathbf{Wx} = \\mathbf{WUz} = \\mathbf{\\theta z}$, $\\theta \\in \\mathbb{R}^{M \\times D}$\n  \\item Reconstruct $\\mathbf{x} \\in \\mathbb{R}^D$ from $\\mathbf{y}$; find $\\mathbf{z}^\\star \\in \\argmin_{\\mathbf{z}}\\|\\mathbf{z}\\|_0$, s.t. $\\mathbf{y} = \\mathbf{\\theta z}$ (e.g. with MP). Given $\\mathbf{z}$, reconstruct $\\mathbf{x}$ via $\\mathbf{x} = \\mathbf{Uz}$\n\\end{inparaitem}\n\\\\Sufficient conditions:\n\\begin{inparaitem}[\\color{red}\\textbullet]\n  \\item $\\mathbf{W} = $ Gaussian random projection, i.e. $w_{ij}\\sim\\mathcal{N}(0, \\frac{1}{D})$\n  \\item M $\\geq cK log(\\frac{D}{K})$, where $c$ is some constant\n\\end{inparaitem}\n\n\\subsection*{Dictionary Learning}\nAdapt the dictionary to signal characteristics. Objective: $(\\mathbf{U}^\\star, \\mathbf{Z}^\\star) \\in \\argmin_\\mathbf{U,Z} \\| \\mathbf{X} - \\mathbf{U} \\cdot \\mathbf{Z} \\|_F^2$ \\\\\n\\textbf{K-SVD (Iter Greedy Minimization):}\n\\begin{inparaenum}[\\color{red} 1.]\n  \\item Coding step: $\\mathbf{Z}^{t+1} \\in \\argmin_\\mathbf{Z} \\| \\mathbf{X} - \\mathbf{U}^t \\mathbf{Z} \\|_F^2 = \\sum_{i=1}^N \\|x_i-U^tz_i \\|^2$ s.t $\\|z_i\\|_0 \\leq K$. Use any pursuit algorithm.\n  \\item Dict update step: $\\mathbf{U}^{t+1} \\in \\argmin_\\mathbf{U} \\| \\mathbf{X} - \\mathbf{UZ}^{t+1} \\|_F^2$, s.t $\\forall l\\in [L]:\\|\\mathbf{u}_l\\|_2 = 1$. \n   idea: update one atom $u_l$ at a time. $\\min_{u_l}\\|\\mathbf{X} - \\mathbf{U}\\mathbf{Z}\\|_F^2 = \\min_{u_l}\\|X-(\\sum_{e \\neq l}u_ez_e^\\top + u_lz_l^\\top)\\|_F^2= \\min_{u_l}\\|\\mathbf{R}_l - \\mathbf{u}_l(\\mathbf{z}_l)^\\top\\|_F^2$ where $z_l$ is the $l$-th row of matrix $Z$ and $R_l$ is the residual due to atom $u_l$. Use SVD $\\mathbf{R}_l = \\sum_i \\sigma_i \\tilde{u}_i \\tilde{v}_i^\\top$ then $\\mathbf{u}^*_l=\\tilde{\\mathbf{u}}_1$ and $\\mathbf{z}^*_l=\\tilde{\\mathbf{v}}_1$ (use power iteration for efficiency).\n\\end{inparaenum}\n", "meta": {"hexsha": "e18a7c1b6b25c534cae4946c0aeb8ed85440e772", "size": 4357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SparseCoding.tex", "max_stars_repo_name": "florianmorath/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-19T15:10:37.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-19T15:10:37.000Z", "max_issues_repo_path": "SparseCoding.tex", "max_issues_repo_name": "florianmorath/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SparseCoding.tex", "max_forks_repo_name": "florianmorath/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 83.7884615385, "max_line_length": 508, "alphanum_fraction": 0.6488409456, "num_tokens": 1773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7394190284086932}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% UMB-CS240-2016S: Programming in C\n% Copyright 2016 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/UMB-CS240-2016S\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 1}\n\nTo check whether a given non-negative integer $n$ is a prime, it suffices to check if it is divisible by at least one of the elements in $\\mathbb{S}_n =  \\{ k_i \\in \\mathbb{P} | k_i < \\sqrt{n} \\}$.\nIf $\\mathbb{S}_n$ is known, it takes $|\\mathbb{S}_n|$ operations to check for primality of $n$.\nThis is much better than when $\\mathbb{S}_n$ is not known in which case it takes $\\mathbb{O}(n \\log \\log n)$ operations to construct it.\n\nSuppose we can store $\\mathbb{P} = \\mathbb{S}_n$, as set of all \\textit{known} prime numbers, in a file and access it when testing primality of another non-negative integer $m$.\nThis way, if $1 << m < n$, primality testing of $m$ would be trivial.\nOn the other hand, if $1 << n < m$, $\\mathbb{S}_n$ would still be very useful in constructing $\\mathbb{S}_m$ and required operations for prime-checking $m$ will be reduced by $c_1 n \\log \\log n + c_2$ operations where $c_1$ and $c_2$ are positive integers.\nIn this case, once $m$ is prime-checked, we can update the list of \\textit{known} prime numbers to $\\mathbb{S}_m$ for later use.\n\nYou are asked to write a program \\texttt{fast-prime.c} that accepts a set of non-negative integer numbers as command line arguments and, using the above-mentioned algorithm, checks for their primality.\n\nYou may not include any header file other than \\texttt{fast-prime.h}.\nIn addition, your \\texttt{fast-prime.c} file should accompany a \\texttt{Makefile} to facilitate building process and artifact removal.\n\nFollowing illustrates the expected functionality of your program.\n\n\\newpage\n\n\\begin{terminal}\n$ ls\nfast-prime.c fast-prime.h Makefile\n$ make\ngcc -c -o fast-prime.o fast-prime.c\ngcc -o fast-prime fast-prime.o -Werror -Wall -std=gnu99 -I.\n$ ./fast-prime\nerror: missing command line argument\n$ ./fast-prime 6\n6     : not prime\n$ ls\nfast-prime fast-prime.c fast-prime.h fast-prime.o\nMakefile primes.log\n$ cat primes.log\n2\n3\n5\n$ ./fast-prime 25 37 39 29\n25    : not prime\n37    : prime\n39    : not prime\n29    : prime\n$ ls\nfast-prime fast-prime.c fast-prime.h fast-prime.o Makefile primes.log\n$ cat primes.log\n2\n3\n5\n7\n11\n13\n17\n19\n23\n29\n31\n37\n$ make clean\nrm -rf fast-prime\nrm -rf primes.log\nfind . -name '*.o' -delete\n\\end{terminal}\n", "meta": {"hexsha": "11e57be3d7d09346c84983f7bd26ef7c8183c292", "size": 2595, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/main/hw06/hw06q01.tex", "max_stars_repo_name": "ghorbanzade/UMB-CS240-2016S", "max_stars_repo_head_hexsha": "c32c866cbe5f7d7044f51f2bcd689b33bda61980", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-03T18:41:24.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-03T18:41:24.000Z", "max_issues_repo_path": "src/tex/main/hw06/hw06q01.tex", "max_issues_repo_name": "ghorbanzade/UMB-CS240-2016S", "max_issues_repo_head_hexsha": "c32c866cbe5f7d7044f51f2bcd689b33bda61980", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-05-16T23:55:39.000Z", "max_issues_repo_issues_event_max_datetime": "2016-06-20T03:04:35.000Z", "max_forks_repo_path": "src/tex/main/hw06/hw06q01.tex", "max_forks_repo_name": "ghorbanzade/UMB-CS240-2016S", "max_forks_repo_head_hexsha": "c32c866cbe5f7d7044f51f2bcd689b33bda61980", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.0714285714, "max_line_length": 256, "alphanum_fraction": 0.6894026975, "num_tokens": 773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907932, "lm_q2_score": 0.8872045952083047, "lm_q1q2_score": 0.7393294176058907}}
{"text": "\\section{Statistics for Bernoulli Trials (Inference for Proportions)}\\label{S:InfForProps}\n\n\\subsection{ Testing biasedness of a coin}\n\n\\textbf{\\ }Suppose we have a coin where $\\theta$ is the probability of coming up\nwith Heads and $1-\\theta$ is is the probability of coming up with Tails. Here $\\theta$\nis a number between $0$ and $1.$ The coin is fair (unbiased) if $\\theta=1/2$;\notherwise it is a biased coin. Throwing a coin constitutes a\\textbf{\\\nBernoulli trial} if we identify Heads with the number $1$ and Tails with $0$%\n. The random variable $X$ symbolizing the outcome of this experiment is a \n\\textbf{Bernoulli random variable.} Thus we have \n\\begin{equation*}\n\\P \\left( X=0\\right) =1-\\theta\\text{, }\\P \\left( X=1\\right) =\\theta\\text{, }0<\\theta<1%\n\\text{. }\n\\end{equation*}%\nGenerally we abbreviate ``random variable\" by RV.\n\nRecall that the distribution of a discrete RV is the entirety of its\npossible values $x_{1},x_{2},\\ldots $ along with the associated\nprobabilities $\\theta_{i}=\\P \\left( X=x_{i}\\right) $. The \\textbf{Bernoulli\ndistribution} $\\bernoulli(\\theta)$ is by definition the distribution of $X,$\ni.e. the possible values are $0$ and $1$ and the associated probabilities\nare $1-\\theta$ and $\\theta$.\n\nHow can we test whether a given coin is biased or not ? Obviously we should\nthrow the coin repeatedly and compare the number of Heads with the number of\nTails. If we throw the coin $n$ times, this provides us with \\ $n$ \\textit{%\nindependent Bernoulli trials}, symbolized by independent Bernoulli random\nvariables $X_{1},\\ldots ,X_{n}$. \\bigskip \\bigskip\n\n\\textbf{First example of a hypothesis test.} To phrase the biasedness\nquestion in statistical terms, introduce two hypotheses: \n\\begin{eqnarray*}\nH_{0} &:&\\theta=1/2\\text{ null hypothesis} \\\\\nH_{1} &:&\\theta\\neq 1/2\\text{ alternative hypothesis}\n\\end{eqnarray*}%\nTo test if the null hypothesis \n\\index{null hypothesis} is true, we throw the coin $n$ times and let $%\nX_{i}=1 $ if Heads comes up on the $i$th trial and $0$ otherwise, so that $%\n\\overline{X}_{n}$ is the fraction of times Heads comes up in the first $n$\ntrials. The test is specified by giving a critical region \\textbf{%\n\\index{critical region} }$\\mathcal{C}_{n}$ so that we reject $H_{0}$ (that\nis, decide $H_{0}$ is incorrect) when $%\n\\overline{X}_{n}\\in \\mathcal{C}_{n}$. One possible choice in this case is \n\\begin{equation*}\n\\mathcal{C}_{n}=\\left\\{ x:\\left\\vert x-\\frac{1}{2}\\right\\vert >1/\\sqrt{n}%\n\\right\\} .\n\\end{equation*}%\nThis choice is motivated by the fact that if $H_{0}$ is true then using the\ncentral limit theorem ($Z$ is a standard normal variable), with $\\theta=1/2$ \n\\begin{equation}\n\\P \\left( \\overline{X}_{n}\\in \\mathcal{C}_{n}\\right) =\\P \\left( \\left\\vert \n\\frac{\\overline{X}_{n}-\\theta}{\\sqrt{\\theta(1-\\theta)}/\\sqrt{n}}\\right\\vert \\geq 2\\right)\n\\approx P\\left( \\left\\vert Z\\right\\vert \\geq 2\\right) =0.05.\n\\end{equation}%\nand $2\\sqrt{\\frac{1}{2}\\cdot \\frac{1}{2}}=1$. Rejecting $H_{0}$ when it is\ntrue is called a \\textbf{type I error. \n\\index{type I error}}In this test we have set the type I error to be 5\\%.\n\n\\bigskip \\bigskip\n\n\\subsection{Review of underlying probability concepts}\\label{S:ReviewOfProb}\n\nAlthough Probability Theory I is a pre-requisite for Inference Theory I, we will review the concepts again as everyone may not have met the pre-requisites at the level needed for the sequel. \nIn the process we will use slightly different notational conventions as these are more common in mathematical statistics.\n\n\\textbf{\\ }Recall the notion of independence of RV`s: suppose $%\nX_{1},X_{2}$ are RV`s which can be jointly observed, i.e. they have a\njoint distribution. Suppose also that both $X_{1},X_{2}$ have the same\nfinite range of possible values: $\\Xz=\\left\\{ \\xi _{1},\\ldots ,\\xi _{m}\\right\\} $. Then independence means \n\\begin{equation*}\n\\P \\left( X_{1}=x_{1},X_{2}=x_{2}\\right) =\\P \\left( X_{1}=x_{1}\\right) \\P\n\\left( X_{2}=x_{2}\\right) \n\\text{, }x_{1},x_{2}\\in \\Xz.\n\\end{equation*}%\nIndependence of $n$ RV`s $X_{1},\\ldots ,X_{n}$ is defined analogously,\nwhere for any set of values $x_{1},\\ldots ,x_{n}$ (all from $\\Xz$)\nwe require \n\\begin{equation*}\n\\P \\left( X_{1}=x_{1},\\ldots ,X_{n}=x_{n}\\right)\n=\\dprod\\limits_{i=1}^{n}\\P \\left( X_{i}=x_{i}\\right) .\n\\end{equation*}%\nThrowing a coin $n$ times, our Bernoulli RV`s $X_{1},\\ldots ,X_{n}$ are\nnot only independent but also \\textit{identically distributed}. This means\nthat all $X_{i}$ considered ``alone\" (i.e. in their marginal distribution)\nhave the same distribution $\\bernoulli(\\theta)$. Such an array of RV`s is\noften called \\textbf{independent and identically distributed}\\textit{, }%\nabbreviated\\textit{\\ }IID The case of observed IID RV`s is the\nmost frequently assumed and encountered one in statistics. Specialized to\nBernoulli RV`s $X_{1},\\ldots ,X_{n}$ the \\textit{\\ }IID assumption\nmeans: if $x_{1},\\ldots ,x_{n}$ \\ is any sequence of $0$'s and $1$'s then \n\\begin{equation*}\n\\P \\left( X_{1}=x_{1},\\ldots ,X_{n}=x_{n}\\right)\n=\\dprod\\limits_{i=1}^{n}\\P \\left( X_{i}=x_{i}\\right) =\\theta^{k}\\left(\n1-\\theta\\right) ^{n-k}\n\\end{equation*}%\nwhere $k$ is the number of $1$'s in the $n$-tuple $x_{1},\\ldots ,x_{n}$.\nNote that we may write \n\\begin{equation*}\nk=\\sum_{i=1}^{n}x_{i}\n\\end{equation*}%\nhence \n\\begin{equation*}\n\\P \\left( X_{1}=x_{1},\\ldots ,X_{n}=x_{n}\\right) =\\theta^{\\left(\n\\sum_{i=1}^{n}x_{i}\\right) }\\left( 1-\\theta\\right) ^{n-\\left(\n\\sum_{i=1}^{n}x_{i}\\right) }.\n\\end{equation*}\n\n\\begin{Exercise}[title={Subsets of independent RVs},label={IndepOfSubSeqOfRVs}]\nSuppose that $X_{1},\\ldots ,X_{n}$ is a set of RV's\nall having the same finite range of possible values: $\\Xz=\\left\\{\n\\xi _{1},\\ldots ,\\xi _{m}\\right\\} $, i.e we have $X_{i}\\in \\Xz$, $%\ni=1,\\ldots ,n$. Define independence of $X_{1},\\ldots ,X_{n}$ by the\nproperty: for all $n$-tuples $\\left( x_{1},\\ldots ,x_{n}\\right) \\in \\Xz^{n}$ we have \n\\begin{equation*}\n\\P \\left( X_{1}=x_{1},\\ldots ,X_{n}=x_{n}\\right)\n=\\dprod\\limits_{i=1}^{n}\\P \\left( X_{i}=x_{i}\\right) \\text{.}\n\\end{equation*}%\nShow that independence of $X_{1},\\ldots ,X_{n}$ implies independence of any\nsubset $X_{i_{1}},\\ldots ,X_{i_{k}}$ where $\\left\\{ i_{1},\\ldots\n,i_{k}\\right\\} $ is an arbitrary subset of size $k$ of the indices $\\left\\{\n1,\\ldots ,n\\right\\} $, and $2\\leq k<n$.\\bigskip\n\\end{Exercise}\n\n\\begin{Exercise}[title={Convergence in distribution and probability to $\\pointmass$ RV},label={ConvInDistToPointMassImpliesConvInProb}] \nLet $X_{1},X_{2}\\ldots $ be a sequence of RV's and $%\n\\mu $ be a real number. Let $Y$ be a RV taking value $\\mu $ with\nprobability one ($\\P \\left( Y=\\mu \\right) =1$). The law, or probability\ndistribution, of $Y$ is called the \\textit{degenerate law concentrated at }$%\n\\mu $ or the $\\pointmass(\\mu)$ RV; it has distribution function \n\\begin{equation*}\nG_{\\mu }(x)=\\P \\left( Y\\leq x\\right) =\\left\\{ \n\\begin{tabular}{l}\n$0$, $x<\\mu $ \\\\ \n$1$, $x\\geq \\mu .$%\n\\end{tabular}%\n\\right.\n\\end{equation*}%\nShow that as $n\\rightarrow \\infty $ \n\\begin{equation*}\nX_{n}\\rightsquigarrow Y\\text{ if and only if }X_{n}\\longrightarrow_{\\P}\\mu ,\n\\end{equation*}%\ni.e. convergence in distribution to the degenerate law means convergence in\nprobability to $\\mu $. For these convergence notions, see Definition (\\ref%\n{def-converg-in-law}) ( regarding $\\rightsquigarrow $) , and the well known\nconvergence in probability: $X_{n}\\longrightarrow_{\\P}\\mu $ if $\\P \\left(\n\\left\\vert X_{n}-\\mu \\right\\vert \\geq \\varepsilon \\right) \\rightarrow 0$ for\nevery $\\varepsilon >0$).\n\\end{Exercise}\n\n\\textbf{Moments of the Bernoulli distribution}. Suppose that $X$ has the\nBernoulli law $\\bernoulli(\\theta)$. A notation we will frequently use is \n\\begin{equation*}\n\\mathcal{L}(X)=\\bernoulli(\\theta)\\text{. }\n\\end{equation*}%\nHere ``$\\mathcal{L}(X)$\" means ``the law of the RV $X$\", where the law is\na short word for the distribution (derived from ``probability law\", an older\nterm for ``distribution\"). Now it is easy to see, with the shorter notation for expectations without the $(\\cdot)$ for convenience, that \n\\begin{eqnarray*}\n\\E (X) = \\E X &=&0\\cdot \\left( 1-\\theta\\right) +1\\cdot \\theta=\\theta, \\\\\n\\E (X^2) = \\E X^{2} &=&0^{2}\\cdot \\left( 1-\\theta\\right) +1^{2}\\cdot \\theta=\\theta\n\\end{eqnarray*}%\nand hence \n\\begin{equation*}\n\\V(X)=\\E X^{2}-\\left( \\E X\\right) ^{2}=\\theta-\\theta^{2}=\\theta\\left( 1-\\theta\\right) .\n\\end{equation*}%\n\\textbf{The law of large numbers. }Specialized to our case of IID\nBernoulli's it gives \n\\begin{equation*}\n\\overline{X}_{n}=n^{-1}\\sum_{i=1}^{n}X_{i}\\longrightarrow _{\\theta}\\E X=\\theta\n\\end{equation*}%\nwhere $\\longrightarrow_{\\P}$ (or equivalently $\\overset{\\P}{\\longrightarrow}$) denotes convergence in probability. Here $\\overline{X%\n}_{n}$ is the arithmetic mean of $X_{1},\\ldots ,X_{n}$, also called the \n\\textbf{sample mean.} Recall that convergence in probability $\\overline{X}%\n_{n}\\longrightarrow_{\\P} \\theta$ means: for every $\\varepsilon >0$ \n\\begin{equation*}\n\\P \\left( \\left\\vert \\overline{X}_{n}-\\theta\\right\\vert >\\varepsilon \\right)\n\\longrightarrow 0\\text{ as }n\\rightarrow \\infty \\text{. }\n\\end{equation*}%\nHere $\\theta=\\E X$ may be also be called ``\\textbf{population mean}\". This derives\nfrom the fact that in many examples other than coin throw, a Bernoulli RV $X$ \nis obtained from randomly selecting an individual from a large\npopulation. Fore instance, we might select a random individual from the U.S.\npopulation and observe whether it is a smoker or nonsmoker. Provided our\nselection is ``truly random\", we obtain a Bernoulli distribution $\\bernoulli(\\theta)$ \nwhere $\\theta$ is the proportion of smokers in the population at large. By\nthis reasoning, we often identify a random variable $X$ with a ``population\"\nand its expectation and variance $\\E X,$ $\\V(X)$ with the population\nmean and variance. Thus there is a correspondence between sample mean $\\overline{X%\n}_{n}$ and population mean $\\E X$ etc. Of course there are many random\nvariables occurring in practice which do not arise from ``selecting from a\npopulation\", for example a coin throw, hitting a target when shooting,\ngetting rain on a hike etc., \\bigskip \\bigskip\n\n\\textbf{Population proportion and sample proportion.} For Bernoulli RV's $%\nX_{1},\\ldots ,X_{n}$, the sample mean $\\overline{X}_{n}$ may be identified with\nthe \\textit{sample proportion of }$1$\\textit{'s}. Indeed \n\\begin{equation*}\n\\overline{X}_{n}=n^{-1}\\sum_{i=1}^{n}X_{i}=\\frac{\\#\\text{ of }1^{^{\\prime }}s%\n\\text{ in the sample }X_{1},\\ldots ,X_{n}}{n}\n\\end{equation*}%\nthus $\\overline{X}_{n}$ is the number of $1$'s in the sample relative to sample\nsize $n$, briefly called \\textbf{sample proportion} $\\widehat{\\theta}_{n}$. Thus for\nBernoulli RV's $X_{1},\\ldots ,X_{n}$ we have \n\\begin{equation*}\n\\overline{X}_{n}=\\widehat{\\theta}_{n}.\n\\end{equation*}%\nThe same correspondence exists on the population level: $\\E X=\\theta$ where $\\theta$ may\nbe called the \\textbf{population proportion}. To repeat it, $X$ may not\nactually be the result of selecting from some population; $X$ may be the\noutcome of a random experiment like a coin throw. Still the terminology\n``sample proportion/ population proportion\" is widely used in\nstatistics.\n\n\n\n\\subsubsection{Chebyshev's inequality and the Law of Large Numbers (LLN)}\n\nThe law of large numbers (LLN) \\index{Law of Large Numbers} holds under a general assumption that $%\n\\E\\left\\vert X_{i}\\right\\vert <\\infty $, see [D]\\footnote{%\nThroughout we will use [D] for the reference: Durrett, R., \\emph{The\nEssentials of Probability, }Duxbury Press, 1994.} p. 223. or Proof via CFs in Probability Theory I earlier. \nBut we recall here from scratch for reinforcement of your learning.}\n\n\\begin{prop}[Weak Law of Large Numbers] \nSuppose $X_{1},X_{2},\\ldots $ are IID\\ RV\\\n's and have $\\E\\left\\vert X_{i}\\right\\vert <\\infty $. Let $\\mu =\\E X_{i}$. Then\nas $n\\rightarrow \\infty $%\n\\begin{equation*}\n\\overline{X}_{n}\\longrightarrow_{\\P}\\mu\n\\end{equation*}%\nin other words: for every $\\varepsilon >0$ \n\\begin{equation*}\n\\P \\left( \\left\\vert \\overline{X}_{n}-\\mu \\right\\vert \\geq \\varepsilon \\right)\n\\longrightarrow 0\\text{. }\n\\end{equation*}\n\\end{prop}\n\nThe general proof is not given in [D], but is argued under an additional\nassumption that the IID $X_{i}$ have a finite variance. In this case the\nLLN follows from \\textit{Chebyshev's inequality }([D] p. 222)\\textit{: }if $%\nY $ is an RV with finite variance $\\sigma ^{2}$ then for any $t>0$ \\textit{%\n\\ }%\n\\begin{equation}\n\\P \\left( \\left\\vert Y-\\E Y\\right\\vert \\geq t\\right) \\leq \\frac{\\V%\n(Y)}{t^{2}}.  \\label{Chebyshev}\n\\end{equation}%\nThis easily yields a proof of the weak LLN under an additional assumption $%\n\\V(X_{i})=\\sigma ^{2}<\\infty $: note that $\\V(\\overline{X}%\n_{n})=\\sigma ^{2}/n$ so that \n\\begin{equation*}\n\\P \\left( \\left\\vert \\overline{X}_{n}-\\mu \\right\\vert \\geq \\varepsilon \\right)\n\\leq \\frac{\\V(\\overline{X}_{n})}{\\varepsilon ^{2}}=\\frac{\\sigma ^{2}}{%\nn\\varepsilon ^{2}}\\longrightarrow 0.\n\\end{equation*}\n\n\\begin{proof}[Proof of Chebyshev's inequality (\\protect\\ref{Chebyshev})]\nLet $X$ be a nonnegative RV ($X\\geq 0$ ) with finite expectation: $%\n\\E X<\\infty $. Let $\\mathbf{1}_{A}$ be the indicator function of an event $A$.\nThen for $u>0$ \n\\begin{equation*}\n\\E X=\\E X\\mathbf{1}_{\\left\\{ X<u\\right\\} }+\\E X\\mathbf{1}_{\\left\\{ X\\geq u\\right\\}\n}\\geq \\E X\\mathbf{1}_{\\left\\{ X\\geq u\\right\\} }\\geq u \\E \\mathbf{1}_{\\left\\{\nX\\geq u\\right\\} }=u\\P \\left( X\\geq u\\right) .\n\\end{equation*}%\nThus we obtain \\textit{Markov's inequality} \n\\begin{equation*}\n\\P \\left( X\\geq u\\right) \\leq \\frac{\\E X}{u}.\n\\end{equation*}%\nSetting $X=\\left\\vert Y-\\E Y\\right\\vert ^{2}$ we obtain \n\\begin{equation*}\n\\P \\left( \\left\\vert Y-\\E Y\\right\\vert \\geq t\\right) =\\P \\left( \\left\\vert\nY-\\E Y\\right\\vert ^{2}\\geq t^{2}\\right) \\leq \\frac{\\E\\left\\vert Y-\\E Y\\right\\vert\n^{2}}{t^{2}}=\\frac{\\V(Y)}{t^{2}}.\n\\end{equation*}\n\\end{proof}\n\n\\bigskip \\bigskip To understand what the assumption of a finite variance\nmeans, it is instructive to find an example of a RV having $\\E\\left\\vert\nX\\right\\vert <\\infty $ but with infinite variance.\n\n\\subsubsection{Normal approximation and the Central Limit Theorem (CLT)}\n\nLet us state the Central Limit Theorem, following [D], p. 228.\n\n\\begin{prop}\nSuppose $X_{1},X_{2},\\ldots $ are IID\\ RV\\ 's and have $\\E X_{i}=\\mu $\nand $\\V(X_{i})=\\sigma ^{2}$ with $0<\\sigma ^{2}<\\infty $. Then as $%\nn\\rightarrow \\infty $%\n\\begin{equation*}\n\\P \\left( \\frac{\\overline{X}_{n}-\\mu }{\\sigma /\\sqrt{n}}\\leq x\\right)\n\\longrightarrow \\P \\left( Z\\leq x\\right) \\text{ for all }x\n\\end{equation*}%\nwhere $Z$ denotes a random variable with the standard normal distribution.\n\\end{prop}\n\nSpecialized to IID Bernoulli RV's $X_{1},\\ldots ,X_{n}$ with law $%\n\\bernoulli(\\theta)$, this says \n\\begin{equation}\n\\sqrt{n}\\frac{\\left( \\widehat{\\theta}_{n}-\\theta\\right) }{\\sqrt{\\theta(1-\\theta)}}\\rightsquigarrow\n\\normal(0,1)\\text{ as }n\\rightarrow \\infty .  \\label{specialize-Bern}\n\\end{equation}%\nHere $\\normal(0,1)$ is the \\textit{standard normal distribution} (or standard\nGaussian distribution) and $\\rightsquigarrow $ denotes\\textit{\\ convergence\nin distribution} (or in law) of a RV A random variable $Z$ has the\nstandard normal distribution if \n\\begin{equation*}\n\\P \\left( Z\\leq z\\right) =\\Phi (z)=\\int_{-\\infty }^{z}\\varphi (t)dt\n\\end{equation*}%\nwhere $\\Phi $ is the \\textit{standard normal distribution function, }defined\nin terms of the \\textit{standard} \\textit{normal density }%\n\\begin{equation*}\n\\varphi (t)=\\frac{1}{\\sqrt{2\\pi }}\\exp \\left( -t^{2}/2\\right) .\n\\end{equation*}%\nThus we have a number of symbols associated with the standard normal\ndistribution: $\\normal(0,1)$ is the distribution itself, $Z$ is a common symbol\nfor a RV having that law, i.e. $\\mathcal{L}(Z)=\\normal(0,1)$; $\\Phi $ is the\ndistribution function $\\Phi (t)=\\P \\left( Z\\leq t\\right) $ and $\\varphi $\nis the density. The \\textit{general normal} (or Gaussian) distribution with\nmean $\\mu $ and variance $\\sigma ^{2}$ is denoted by $\\normal(\\mu ,\\sigma ^{2})$;\nit is defined as \n\\begin{equation*}\n\\normal(\\mu ,\\sigma ^{2}):=\\mathcal{L}(\\mu +\\sigma Z).\n\\end{equation*}\n\nThe convergence stated in the CLT is a special case of \\textit{convergence\nin distribution}$.$\n\n\\begin{definition}\n\\label{def-converg-in-law} A sequence of RV's $Y_{n}$ converges in\ndistribution (or in law) to a RV $Y$, written \n\\begin{equation*}\nY_{n}\\rightsquigarrow Y\\text{ as }n\\rightarrow \\infty\n\\end{equation*}%\nif \n\\begin{equation}\n\\P \\left( Y_{n}\\leq z\\right) \\longrightarrow \\P \\left( Y\\leq z\\right) \n\\text{ as }n\\rightarrow \\infty  \\label{clt-x}\n\\end{equation}%\nfor every point of continuity $z$ of the distribution function of $Y$.\n\\end{definition}\n\nSince for a standard normal $Z$ the distribution function is $\\Phi $ which\nis continuous everywhere, in the case of the CLT we simply have (\\ref{clt-x}%\n) for every $z$, and the CLT as stated above indeed gives a convergence in\ndistribution. Other ways of writing a convergence in law (in distribution)\nare \n\\begin{equation*}\n\\mathcal{L}\\left( Y_{n}\\right) \\rightsquigarrow \\mathcal{L}\\left( Y\\right) \n\\text{ or }Y_{n}\\rightsquigarrow \\mathcal{L}\\left( Y\\right)\n\\end{equation*}%\nwhich is justified since convergence in distribution is a statement about\nthe laws (or distribution functions) of $Y_{n}$ and $Y$. Thus in the case of\nthe CLT we may write \n\\begin{equation*}\n\\frac{\\overline{X}_{n}-\\mu }{\\sigma /\\sqrt{n}}\\rightsquigarrow \\normal(0,1)\\text{ as }%\nn\\rightarrow \\infty\n\\end{equation*}%\nsince $\\normal(0,1)=\\mathcal{L}\\left( Z\\right) $, and for Bernoulli's this\nspecializes to (\\ref{specialize-Bern}).\n\nIn [D] the CLT is proved under the assumption that $\\E\\exp (tX)<\\infty $ for $%\nt\\in \\left( -t_{0},t_{0}\\right) $ and some $t_{0}>0$. For a Bernoulli $X$\nthis is trivially fulfilled since $X\\leq 1$ and hence $\\E\\exp (tX)\\leq \\exp\n(t)$. \\bigskip\n\n\\begin{Exercise}[title={CLT implies LLN},label={CLTImpliesLLN}]\nShow that the CLT implies the LLN. More precisely, assume\nthat a sequence of RV's $Y_{n}$ satisfies \n\\begin{equation*}\n\\frac{Y_{n}-\\mu }{\\sigma /\\sqrt{n}}\\rightsquigarrow \\normal(0,1)\\text{ as }%\nn\\rightarrow \\infty\n\\end{equation*}%\nfor certain $\\mu ,\\sigma $ where $\\sigma >0$. Show that $Y_{n}%\n\\longrightarrow_{\\P}\\mu $. \\bigskip \\bigskip\n\\end{Exercise}\n\n\\subsubsection{Normal approximation for the binomial distribution}\n\nRecall the definition of the binomial distribution: if $X_{1},\\ldots ,X_{n}$\nare IID\\ Bernoulli $\\bernoulli(\\theta)$ then the distribution of the sum $%\nS_{n}=\\sum_{i=1}^{n}X_{i}$ is the \\textit{binomial distribution} $\\binomial(n,\\theta)$.\nThe probability function of $\\binomial(n,\\theta)$ is \n\\begin{equation}\n\\P \\left( S_{n}=k\\right) =\\left( \\binom{n}{k}\\right) \\theta^{k}\\left( 1-\\theta\\right)\n^{n-k}\\text{, }k=0,\\ldots ,n.  \\label{binom-law}\n\\end{equation}%\nThe binomial law has two parameters- $n,$ the number of trials, and $\\theta$, the\nprobability of ``success\", i.e. of $1$. Thus the binomial law is the\ndistribution of the number of successes in $n$ independent Bernoulli trials\n(with the same probability of success).\n\n\\bigskip\n\n\\begin{proof}[Proof of (\\protect\\ref{binom-law})]\nLet $x_{1},\\ldots ,x_{n}$ be an arbitrary collection of $0^{\\prime }$s and $%\n1^{\\prime }$s$.$ We have seen above that \n\\begin{equation*}\n\\P \\left( X_{1}=x_{1},\\ldots ,X_{n}=x_{n}\\right) =\\theta^{\\left(\n\\sum_{i=1}^{n}x_{i}\\right) }\\left( 1-\\theta\\right) ^{n-\\left(\n\\sum_{i=1}^{n}x_{i}\\right) }\n\\end{equation*}%\nwhere $\\sum_{i=1}^{n}x_{i}$ is the number of $1^{\\prime }$s among $%\nx_{1},\\ldots ,x_{n}$, i.e. the number of successes. Thus \n\\begin{eqnarray*}\n\\P \\left( \\sum_{i=1}^{n}X_{i}=k\\right) &=&\\sum_{\\left( x_{1},\\ldots\n,x_{n}\\right) :\\sum_{i=1}^{n}x_{i}=k}\\theta^{k}\\left( 1-\\theta\\right) ^{n-k} \\\\\n&=&\\theta^{k}\\left( 1-\\theta\\right) ^{n-k}\\cdot \\#\\left\\{ \\left( x_{1},\\ldots\n,x_{n}\\right) :\\sum_{i=1}^{n}x_{i}=k\\right\\} \\\\\n&=&\\theta^{k}\\left( 1-\\theta\\right) ^{n-k}\\left( \\binom{n}{k}\\right)\n\\end{eqnarray*}%\n(indeed the number of $n$-tuples of $\\left( x_{1},\\ldots ,x_{n}\\right) $ of $%\n0^{\\prime }$s and $1^{\\prime }$s having exactly $k$ $1^{\\prime }$s is $%\n\\left( \\binom{n}{k}\\right) $- choose the $k$ positions among positions $%\n1,\\ldots ,n$ where you place $1^{\\prime }$s).\n\\end{proof}\n\n\\bigskip\n\nThus the CLT, specialized to IID\\ Bernoullis in (\\ref{specialize-Bern}),\nis a statement about the normal approximation of the binomial law. Indeed\nlet $S_{n}=\\sum_{i=1}^{n}X_{i}$; we may write \n\\begin{eqnarray}\n\\widehat{\\Theta}_{n} &=&\\overline{X}_{n}=n^{-1}\\sum_{i=1}^{n}X_{i}=n^{-1}S_{n},  \\notag \\\\\n\\sqrt{n}\\frac{\\left( \\widehat{\\Theta}_{n}-\\theta\\right) }{\\sqrt{\\theta(1-\\theta)}} &=&  \\notag \\\\\n&=&\\frac{S_{n}-n\\theta}{\\sqrt{n\\theta(1-\\theta)}}\\rightsquigarrow \\normal(0,1)\\text{ as }%\nn\\rightarrow \\infty .  \\label{demoivre-laplace}\n\\end{eqnarray}%\nHere $S_{n}$ has the binomial law $\\binomial(n,\\theta)$. The form (\\ref{demoivre-laplace}%\n) of the CLT is also called the \\textbf{De Moivre- Laplace theorem};\nhistorically it was the first version of the CLT (De Moivre (1733) for $%\n\\theta=1/2 $, Laplace (1812) for $0<\\theta<1$). We see that the left side of (\\ref%\n{demoivre-laplace}) is just the standardized sum $S_{n}$, by calculating its\nfirst two moments: \n\\begin{eqnarray*}\n\\E S_{n} &=&\\sum_{i=1}^{n}\\E X_{i}=n\\theta\\text{, } \\\\\n\\V(S_{n}) &=&\\sum_{i=1}^{n}\\V(X_{i})=n\\theta(1-\\theta).\n\\end{eqnarray*}%\nRecall that standardizing a RV $Y$ means subtracting its expectation $\\E Y\\ $%\nand then dividing by the standard deviation $\\mathrm{SD}(Y)=\\sqrt{\\mathrm{Var%\n}(Y)}$ so that the standardized expression \n\\begin{equation*}\n\\frac{Y-\\E Y}{\\mathrm{SD}(Y)}\n\\end{equation*}%\nhas mean $0$ and variance $1$. Hence the verbal summary of the CLT: ``the\nstandardized sum of IID RV's is approximately standard normal\". Of\ncourse standardizing the sum $S_{n}=\\sum_{i=1}^{n}X_{i}$ yields the same\nresult as standardizing the sample mean $\\overline{X}_{n}$: \n\\begin{eqnarray*}\n\\E S_{n} &=&n\\E\\overline{X}_{n}\\text{ and }\\V(S_{n})=n^{2}\\V(%\n\\overline{X}_{n})\\text{, hence } \\\\\n\\frac{S_{n}-\\E S_{n}}{\\mathrm{SD}(S_{n})} &=&\\frac{\\overline{X}_{n}-\\E\\overline{X}_{n}}{%\n\\mathrm{SD}(\\overline{X}_{n})}\n\\end{eqnarray*}%\nso it is also true that ``the standardized (sample) mean of IID RV's is\n\\ldots \".\n\n\\subsubsection{A visualization of the De Moivre-Laplace central limit theorem%\n\\textbf{\\ }}\n\nLet $X_{1},\\ldots ,X_{n}$ be independent identically distributed random\nvariables having the Bernoulli law $\\binomial(1,\\theta)$ with probability of success $\\theta$.\nRecall that $S_{n}=\\sum_{i=1}^{n}X_{i}$ then has the binomial law $\\binomial(n,\\theta)$\nwith probabilities \n\\begin{equation*}\nP(Y=k)=\\frac{n!}{k!\\cdot (n-k)!}\\cdot \\theta^{k}(1-\\theta)^{n-k}.\n\\end{equation*}%\nTo plot these probabilities we use the Gamma-function $\\Gamma (x)$ which is\ndefined for all $x>0$. and which has the property that for integers $k$ \n\\begin{equation*}\n\\Gamma (k+1)=k!\n\\end{equation*}%\nThus we are able to plot a continuous function for all $x$ in a range, and\nwe obtain a visualization of the factorial and derived expressions. We let $%\nx $ be the continuous variable taking the place of $k=0,1,\\ldots ,n$.\n\nDefine a function \n\\begin{equation*}\nb_{n}(x)=\\frac{\\Gamma (n+1)}{\\Gamma (x+1)\\cdot \\Gamma (n-x+1)}\\cdot\n\\theta^{x}\\cdot (1-\\theta)^{n-x}\n\\end{equation*}\n\nHere $b_{n}(x)$ represents the binomial law $\\binomial(n,\\theta)$ in the following sense: \n\\begin{equation*}\nb_{n}(k)=\\frac{n!}{k!(n-k)!}\\theta^{k}(1-\\theta)^{n-k}\\text{, }k=0,1,\\ldots ,n.\n\\end{equation*}\n\nSet $\\theta=1/3$ and $n=600$. The plot of the function $b_{n}(x)$, which\ninterpolates the binomial probabilities, is:\n\n\\vspace{3cm} \n{\\scriptsize [done in Lecture 3 - get/read notes to draw by hand here.]}\\\\\n\nLet us look at this\npicture around the expected value $n\\theta=600/3=200$ in the range of three\nstandard deviations. The standard deviation is $\\sigma =\\sqrt{n}\\cdot \\sqrt{%\n\\theta \\cdot (1-\\theta)}=11.55$, thus $3\\sigma =34.65\\approx 35$ and we take a range\nvalues of $x$ from $165$ to $235$.\n\n\n{\\scriptsize [done in Lecture 3 - get/read notes to draw by hand here.]}\\\\\n\\vspace{3cm} \n~\\\\\n\n\nThe curve is\nvisually indistinguishable from a normal density. For a comparison we plot\nthe normal density with expectation $\\mu =200$ and standard deviation $%\n\\sigma =11.55$, i. e. the function \n\\begin{equation*}\nf(x)=\\frac{1}{\\sigma }\\varphi \\left( \\frac{x-\\mu }{\\sigma }\\right)\n\\end{equation*}%\nwhere \n\\begin{equation*}\n\\varphi \\left( t\\right) =\\frac{1}{\\sqrt{2\\pi }}\\exp \\left( -t^{2}/2\\right)\n\\end{equation*}%\nis the standard normal density $\\varphi \\left( t\\right) $. The density $f(x)$\nis plotted in (red) dots over the previous function $b_{n}(x)$.\n\n{\\scriptsize [done in Lecture 3 - get/read notes to draw by hand here.]}\\\\\n\\vspace{3cm} \n~\\\\\n\nIn this reasoning, we plotted the interpolated probability\nfunction of the sum $S_{n}$ against the density of the normal distribution $%\n\\normal(\\mu ,\\sigma ^{2})=\\normal\\left( n\\theta,n\\theta(1-\\theta)\\right) $. In fact since the CLT says\nthat the standardized sum $\\frac{S_{n}-n\\theta}{\\sqrt{n\\theta(1-\\theta)}}$ is approximately\nstandard normal:%\n\\begin{equation}\n\\frac{S_{n}-n\\theta}{\\sqrt{n\\theta(1-\\theta)}}\\rightsquigarrow Z  \\label{clt-correct}\n\\end{equation}%\nby multiplying by $\\sigma =\\sqrt{n\\theta(1-\\theta)}$ and then adding $\\mu =n\\theta$ we\nwould infer $S_{n}$ that should be approximately \n\\begin{equation}\nS_{n}\\approx \\sqrt{n\\theta(1-\\theta)}Z+n\\theta  \\label{cautious}\n\\end{equation}%\nwhere $\\mathcal{L}(\\sigma Z+\\mu )=$ $\\normal(\\mu ,\\sigma ^{2})$. But here we\nshould be cautious as to the meaning of the sign ``$\\approx $\": in (\\ref%\n{cautious}) both the left side and the right side depend on $n$, so we do\nnot have a limit relation. Nevertheless it is common in statistics to state\nthe normal approximation to the binomial as \n\\begin{equation*}\nS_{n}\\approx \\normal\\left( n\\theta,n\\theta(1-\\theta)\\right) .\n\\end{equation*}%\nThis is correct if we understand it to mean the CLT (\\ref{clt-correct}).\nWhen we plot the distributions $\\binomial(n,\\theta)$ and $\\normal\\left( n\\theta,n\\theta(1-\\theta)\\right) $, we\nmake certain scale transforms anyway, e.g. we look at the distributions\naround their expectation, on the scale of the standard deviation. This\namounts to standardization, and what we see is in fact the CLT (\\ref%\n{clt-correct}).\n\nMoreover (\\ref{cautious}) can be made rigorous by introducing a certain\ndistance for distributions and then claiming that the distance between $%\n\\mathcal{L}(S_{n})$ and $\\normal\\left( n\\theta,n\\theta(1-\\theta)\\right) $ tends to zero; we will\nnot elaborate this here.\n\n\\subsection{The success / failure rule}\\label{S:SuccessFailureRule}\n\n\\textbf{\\ }In applied statistics one finds a rule which limits the\napplicability of the normal approximation to the binomial $\\binomial(n,\\theta)$: it is\nrequired that both $n\\theta\\geq 10$ and $n(1-\\theta)\\geq 10$. This is called the\n``success / failure rule\" \\index{success / failure rule} since $n\\theta$ is the expected number of successes: $%\n\\E S_{n}=n\\theta$ and and $n(1-\\theta)$ is the expected number of ``failures\": $\\E\\left(\nn-S_{n}\\right) =n(1-\\theta)$. This rule is based on the fact that the CLT\\\n``breaks down\" for small values of $\\theta$. More precisely, when $\\theta$ is small, a\nlarger $n$ is needed to make the normal approximation good; for large enough \n$n$ a small $\\theta$ can always be compensated. For an illustration, select $%\n\\theta=1/200$ and again $n=600$; then $n\\theta=3$ and the success / failure rule is\nviolated. The plot of $b_{n}(k)$ is as follows:\n\n\n{\\scriptsize [done in Lecture 3 - get/read notes to draw by hand here.]}\\\\\n\\vspace{3cm} \n~\\\\\n\n\nNext we will look at this distribution around $\\mu =n\\theta$, i.e. $%\n\\mu =3$ in the range of three standard deviations, i. e. $3\\sigma $ where $%\n\\sigma =\\sqrt{n\\theta(1-\\theta)}$, thus $\\sigma =1.\\,73$. Thus $3\\cdot \\sigma\n=5.\\,2\\approx 5$ and we select a range of $x$ from $0$ to $3+5=10$. \n\n\n{\\scriptsize [done in Lecture 3 - get/read notes to draw by hand here.]}\\\\\n\\vspace{3cm} \n~\\\\\n\n\nClearly the normal\napproximation is not convincing; moreover on that scale, we should take into\naccount that the binomial probabilities $b_{n}(k)$ are only defined for\ninteger values $k$, whereas we plotted the interpolating continuous function \n$b_{n}(x)$ defined for all $x\\geq 0$.\n\n\\begin{labwork}\\label{LW:VisualiseSuccessFailureRule}\nWrite a \\Matlab script to visualise the above figures drawn in lectures and algorithmically as well as visually understand {\\em the success / failure rule}.\n\nYou need to use {\\tt gammaln} in \\Matlab for $\\log_e(\\Gamma)$ function and use laws of exponents and logarithms for the PDF of $\\binomial(n,\\theta)$ RVs with large $n$.\n\\end{labwork}\n\n\\begin{Exercise}[label={ExBlueEyedInSpringfield}]\nSuppose the probability of having blue eyes is $0.15$\nfor any given person in the U.S.. The town of Springfield, USA has $800$\npeople. Suppose the residents of Springfield are all unrelated as they are immigrants arriving from all over the U.S., \nand therefore have eye colors that are independent of each other.\n\n\\begin{description}\n\\item[\\textbf{a)}] Find the expected number of people with blue eyes in\nSpringfield, USA.\n\n\\item[b)] Find the variance and standard deviation of the number of\nblue-eyed people in Springfield, USA.\n\n\\item[c)] Use the Normal approximation to the Binomial to calculate the\nprobability that there are between $110$ and $125$ blue-eyed residents of\nSpringfield, USA. Be sure to verify the success/ failure condition for\nvalidity of the normal approximation.\n\\end{description}\n\\end{Exercise}\n\n\\subsubsection{The Poisson approximation to the binomial}\\label{S:PoissonApproxBinomialSuccessFailureRule}\n\nThe breakdown of the normal approximation for small $\\theta$ is related to the \n\\textbf{Poisson approximation} for $\\binomial(n,\\theta)$, according to which $%\n\\binomial(n,\\theta)\\approx \\poisson(n\\theta)$ if $\\theta$ is small and $n$ is large such that $%\nn\\theta\\rightarrow \\lambda $. Here $\\poisson(\\lambda )$ is the Poisson\ndistribution given by probabilities \n\\begin{equation*}\n\\P \\left( Y=k\\right) =\\frac{\\lambda ^{k}}{k!}\\exp \\left( -\\lambda \\right) ,%\n\\text{ }k=0,1,\\ldots\n\\end{equation*}\n\n\\begin{prop}\nSuppose $\\lambda >0$ and consider the binomial law $\\binomial(n,\\theta)$ for $\\theta=\\lambda\n/n $. Let $p_{n,k}$ be the probability function of $\\binomial(n,\\lambda /n)$ and let \n$q_{n,k}$ be the probability function of the Poisson law $\\poisson%\n(\\lambda )$. Then for $n\\rightarrow \\infty $ and fixed $\\lambda $,%\n\\begin{equation*}\np_{n,k}\\rightarrow q_{n,k}\\text{ as }n\\rightarrow \\infty \\text{, for every }%\nk=0,1,\\ldots \\text{.}\n\\end{equation*}\n\\end{prop}\n\n\\begin{proof}\nWe have \n\\begin{eqnarray}\np_{n,k} &=&\\frac{n!}{k!(n-k)!}\\theta^{k}(1-\\theta)^{n-k}  \\notag \\\\\n&=&\\frac{n!}{k!(n-k)!}\\left( \\frac{\\lambda }{n}\\right) ^{k}\\left( 1-\\frac{%\n\\lambda }{n}\\right) ^{n-k}  \\notag \\\\\n&=&\\frac{1}{k!}\\cdot \\frac{n!}{(n-k)!n^{k}}\\cdot \\lambda ^{k}\\cdot \\frac{1}{%\n\\left( 1-\\lambda /n\\right) ^{k}}\\cdot \\left( 1-\\frac{\\lambda }{n}\\right)\n^{n}.  \\label{factors}\n\\end{eqnarray}%\nFor the second factor we have \n\\begin{equation*}\n\\frac{n!}{(n-k)!n^{k}}=\\frac{\\left( n-k+1\\right) }{n}\\cdot \\frac{\\left(\nn-k+2\\right) }{n}\\cdot \\ldots \\frac{n}{n}\n\\end{equation*}%\ni.e. it is a product of $k$ factors each of which tends to $1,$ hence $\\frac{%\nn!}{(n-k)!n^{k}}\\rightarrow 1$. For the 4th factor in (\\ref{factors}) we\nobviously have \n\\begin{equation*}\n\\frac{1}{\\left( 1-\\lambda /n\\right) ^{k}}\\rightarrow 1\\text{. }\n\\end{equation*}%\nFor the 5th factor in (\\ref{factors}) we have \n\\begin{equation*}\n\\left( 1-\\frac{\\lambda }{n}\\right) ^{n}\\rightarrow \\exp (-\\lambda )\n\\end{equation*}%\nwhich proves that \n\\begin{equation*}\np_{n,k}\\rightarrow \\frac{1}{k!}\\cdot \\lambda ^{k}\\cdot \\exp (-\\lambda )\n\\end{equation*}%\nas $n\\rightarrow \\infty $, for a fixed $k.$\n\\end{proof}\n\nWe have established the Poisson approximation to $\\binomial(n,\\theta)$ if $n\\theta=\\lambda $\nexactly; a slight modification gives the result when $\\theta=\\theta_{n}$ depends on $n \n$ in such a way that $n\\theta_{n}\\rightarrow \\lambda $ as $n\\rightarrow \\infty $.\nThis result is sometimes called the \\textbf{law of small numbers }because it\nis the probability distribution of the number of occurrences of an event\nthat happens rarely but has very many opportunities to happen. Another name\nis {\\bf law of rare events}.\n\nAnalogously to what we did for the binomial distribution, for visualization\npurposes we will interpolate the probability function by a smooth function \n\\begin{equation*}\nh(x)=\\frac{1}{\\Gamma (x+1)}\\cdot \\lambda ^{x}\\cdot \\exp (-\\lambda ).\n\\end{equation*}%\nThen $h(x)$ represents the Poisson law $\\poisson(\\lambda )$ in the\nfollowing sense: \n\\begin{equation*}\nh(k)=\\frac{1}{k!}\\cdot \\lambda ^{k}\\cdot \\exp (-\\lambda )\\text{, }%\nk=0,1,\\ldots .\n\\end{equation*}%\nSet as before $n=600$, and consider the binomial $\\binomial(n,\\theta)$ for $\\theta=1/200$;\nthen our appropriate $\\lambda $ is $\\lambda =3$. The picture below \n%(Figure % \\ref{fig1}) \nis analogous to the last figure, where the dotted line now\nrepresents the Poisson law $\\poisson(3)$ instead of the normal law $\\normal(\\mu\n,\\sigma ^{2})$ with mean $\\mu =n\\theta$ and variance $n\\theta(1-\\theta)$.\n\n\n{\\scriptsize [done in Lecuture 5 - get/read notes to draw by hand here.]}\\\\\n\\vspace{3cm} \n~\\\\\n\n\nWe see a visually perfect approximation of the binomial law by\nthe Poisson law. Here both laws are discrete (concentrated on the integers $%\n0,1,\\ldots $) and the picture represents a continuous interpolation.\n\nThe success/failure rule thus can be explained by the Poisson approximation,\nin the sense that the \\textit{Poisson approximation contradicts the normal\nfor small }$\\lambda =n\\theta$. In the requirement $\\lambda \\geq 10$, the $10$ is\na limit chosen by convention; in the figures we saw that at least for $%\n\\lambda =3$, the Poisson and the normal curves are visually different. Can\nwe argue that for $\\lambda \\geq 10$, the Poisson and the normal\napproximation are not in contradiction? For that we have to observe that $%\n\\poisson(\\lambda )$ approximates a normal distribution as $\\lambda\n\\rightarrow \\infty $. \\bigskip\n\n\\begin{Exercise}[title={Sum of independent $\\poisson$ RVs is a $\\poisson$ RV},label={SumOfIndPoissons}]\nSuppose $X,Y$ are independent RV's with $\\mathcal{L}(X)=%\n\\poisson(t),\\mathcal{L}(Y)=\\poisson(u)$ where $t,u>0$. Then $\\mathcal{L%\n}(X+Y)=\\poisson(u+t)$.\n\\end{Exercise}\n\nAs a consequence, we can represent $\\poisson(n)$ as the law of a sum of\nIID RV`s, each with law $\\poisson(1)$:%\n\\begin{equation*}\n\\poisson(n)=\\mathcal{L}\\left( S_{n}\\right) \\text{, }S_{n}=%\n\\sum_{i=1}^{n}Y_{i}\\text{, }Y_{i}\\text{ indep., }\\mathcal{L}\\left(\nY_{i}\\right) =\\poisson(1).\n\\end{equation*}%\nTherefore a CLT holds for the normalized $S_{n}$; recall that expectation\nand variance of $\\poisson(\\lambda )$ are both $\\lambda $: if $\\mathcal{L}%\n(Y)=\\poisson(\\lambda )$ then $\\E Y=\\lambda $, $\\V(Y)=\\lambda $;\nhence \n\\begin{eqnarray}\n\\E (S_n) = \\E S_{n} &=&n\\text{, }\\V(S_{n})= \\V S_n = n \\\\\n\\frac{S_{n}-n}{\\sqrt{n}} &\\rightsquigarrow &\\normal(0,1)\\text{ by the CLT. }\n\\label{clt-for-poisson}\n\\end{eqnarray}%\nWe can express the latter relation also as \n\\begin{equation*}\n\\poisson(n)\\approx \\normal\\left( n,n\\right) \\text{ as }n\\rightarrow \\infty\n\\end{equation*}%\nwhere $\\approx $ means ``closeness in distribution\", with a rigorous meaning (%\n\\ref{clt-for-poisson}). \\bigskip \\bigskip\n\n\\begin{rem}\nIt can be verified that these limiting relations are also\ntrue for general $\\poisson(\\lambda )$:%\n\\begin{equation*}\n\\poisson(\\lambda )\\approx \\normal\\left( \\lambda ,\\lambda \\right) \\text{ as }%\n\\lambda \\rightarrow \\infty\n\\end{equation*}%\nwhich is plausible (the limits holds for all sequences of $\\lambda\n_{n}\\rightarrow \\infty $, not only for a limit along the integers $%\n1,2,\\ldots $). This can be verified using the characteristic function (or moment generating function) of $%\n\\poisson(\\lambda )$. an alternative argument is: represent $\\poisson%\n(\\lambda )$ as a sum $X+Y$ where $\\lfloor \\lambda \\rfloor$ is the floor of $\\lambda$, i.e., largest integer $n\\leq\n\\lambda $, $\\mathcal{L}\\left( X\\right) =\\poisson(\\lfloor \\lambda \\rfloor)$ and $%\n\\mathcal{L}\\left( Y\\right) =\\poisson(\\lambda - \\lfloor \\lambda \\rfloor)$, then show\nthat $X$ can be approximated by a normal and $Y$ has negligible influence.\nWe will acquire the tools for a rigorous argument later.\n\\end{rem}\n\nLet us try to illustrate the CLT for the Poisson law, using the tools we\nhave. First we choose a small $\\lambda $, e.g. $\\lambda =1.5$ and plot the\nPoisson $\\poisson(\\lambda )$ and the normal $\\normal(\\lambda ,\\lambda )$:\n\n\n{\\scriptsize [done in Lecuture 5 - get/read notes to draw by hand here.]}\\\\\n\\vspace{3cm} \n~\\\\\n\n\nConsider the value $\\lambda =10$ which is ``borderline\" according to the\nconvention of the success / failure rule: \n\n\n{\\scriptsize [done in Lecuture 5 - get/read notes to draw by hand here.]}\\\\\n\\vspace{3cm} \n~\\\\\n\n\nA value $\\lambda =50$ gives \n\n\n{\\scriptsize [done in Lecuture 5 - get/read notes to draw by hand here.]}\\\\\n\\vspace{3cm} \n~\\\\\n\n\nshowing a nearly perfect\nfit again, as an illustration of the CLT in action for sums of Poisson\nvariables.\n\n\\begin{labwork}\\label{LW:VisualiseSuccessFailureRulePoisson}\nWrite a \\Matlab script to visualise the above figures drawn in lectures and algorithmically as well as visually understand {\\em the success / failure rule} with {\\bf law of rare events} or Poisson approximation.\n\nYou need to use {\\tt gammaln} in \\Matlab for $\\log_e(\\Gamma)$ function and use laws of exponents and logarithms for the factorial term in the PDF of $\\binomial(n,\\theta)$ and $\\poisson(\\lambda)$ RVs with large $n$.\n\\end{labwork}\n\n\\subsubsection{An example for use of normal approximation of the binomial}\n\n\\begin{Exercise}[label={ExMultipleChoiceQuestions}]\nA multiple-choice examination has 100 questions, each\nwith five possible answers of which only one is correct. Suppose a student\njust guesses at all the answers.\n\n(a) What is the probability that he or she gets exactly 2 out of the first 5\nquestions correct?\n\n(b) What is approximately the probability that he or she gets between 20 and\n30 questions correct on the entire test?\n\n\\end{Exercise}\n\n\\begin{Answer}\n\n(a) The number of questions out of the first five that the student gets\ncorrect has a binomial distribution with parameters $n=5$ and $p=0.2.$\nTherefore, the probability that the student gets exactly two of the\nquestions correct is \n\\begin{equation*}\n\\left( \\binom{5}{2}\\right) \\left( 0.2\\right) ^{2}\\left( 0.8\\right) ^{5-2}=%\n\\frac{5!}{2!\\cdot 3!}\\left( 0.2\\right) ^{2}\\left( 0.8\\right) ^{5-2}=0.204\\,8.\n\\end{equation*}\n\n(b) Let $X$ be the number of questions that the student answers correctly on\nthe entire test. Then, $X$ has a binomial distribution with $n=100$ and $%\np=0.2$. Check the sucess/ failure condition :%\n\\begin{equation*}\nnp=100\\cdot 0.2=20>10,\\text{ }n(1-p)=80>10.\n\\end{equation*}%\nUsing the normal approximation to the binomial distribution, we can\napproximate the distribution of the standardized $X$ by a standard normal\ndistribution. We have $\\mu =EX=np=20$ and \n\\begin{equation*}\n\\sigma =SD(X)=\\sqrt{np(1-p)}=\\sqrt{100\\cdot \\left( 0.2\\right) \\cdot \\left(\n0.8\\right) }=4.\n\\end{equation*}%\nNow we have for $a=20$ and $b=30$ \n\\begin{eqnarray*}\n\\P \\left( a\\leq X\\leq b\\right) &=&\\P \\left( \\frac{a-\\mu }{\\sigma }\\leq \n\\frac{X-\\mu }{\\sigma }\\leq \\frac{b-\\mu }{\\sigma }\\right) \\\\\n&\\approx &\\P \\left( \\frac{a-\\mu }{\\sigma }\\leq Z\\leq \\frac{b-\\mu }{\\sigma }%\n\\right)\n\\end{eqnarray*}%\nwhere $Z$ is a standard normal random variable. We find \n\\begin{eqnarray*}\n\\frac{a-\\mu }{\\sigma } &=&\\frac{20-20}{\\sigma }=0, \\\\\n\\frac{b-\\mu }{\\sigma } &=&\\frac{30-20}{4}=10/4=2.5\n\\end{eqnarray*}%\nThe numbers $\\frac{a-\\mu }{\\sigma }$ and $\\frac{b-\\mu }{\\sigma }$ are called\nthe $Z$-scores of $a$ and $b$ respectively; thus from the table of $Z$ \n\\begin{eqnarray*}\n\\P \\left( \\frac{a-\\mu }{\\sigma }\\leq Z\\leq \\frac{b-\\mu }{\\sigma }\\right)\n&=&\\P \\left( 0\\leq Z\\leq 2.5\\right) \\\\\n&=&\\P \\left( Z\\leq 2.5\\right) -\\P \\left( Z\\leq 0\\right) \\\\\n&=&0.9938-0.5=0.4938.\n\\end{eqnarray*}\n\\end{Answer}\n\n\\begin{Exercise}[label={ExBlueEyedInNewSpringfield}]\nSuppose the probability of having blue eyes is $0.15$\nfor any given person in the U.S.. The town of Springfield, USA recently experienced economic downturn and most people lost their jobs.  There are only $60$ people now in Springfield. \nSuppose the residents of Springfield are all unrelated as they are immigrants arriving from all over the U.S., \nand therefore have eye colors that are independent of each other.\n\n\\begin{description}\n\\item[\\textbf{a)}] Find the expected number of people with blue eyes in\nSpringfield, USA.\n\n\\item[b)] Find the variance and standard deviation of the number of\nblue-eyed people in Springfield, USA.\n\n\\item[c)] Use either the Normal or Poisson approximation to the Binomial, whichever is most appropriate via the success / failure condition, to calculate the\nprobability that there are between $20$ and $25$ blue-eyed residents of\nSpringfield, USA. You may leave your answer as a simplified expression instead of a numerical value.\n\\end{description}\n\\end{Exercise}\n\n\\subsubsection{The correction for continuity}\\label{S:CorrectionForContinuity}\n\nSuppose that in the last example, we substitute question (b) ``between 20\nand 30 questions correct\" by ``between 21 and 30 questions correct\", that\nis, we are asking for the approximate probability%\n\\begin{equation*}\n\\P \\left( a+1\\leq X\\leq b\\right)\n\\end{equation*}%\nwith $a=20,$ $b=30$ or equivalently, for an approximation to \n\\begin{equation*}\n\\P \\left( a<X\\leq b\\right)\n\\end{equation*}%\n(since $X$ is a binomial RV, taking only integer values). By the reasoning\nabove, we find the Z-score of $a+1$:%\n\\begin{equation*}\n\\frac{a+1-\\mu }{\\sigma }=\\frac{21-20}{\\sigma }=\\frac{1}{4}=0.25.\n\\end{equation*}%\nThe approximate probability is then \n\\begin{equation*}\n\\P \\left( a+1\\leq X\\leq b\\right) \\approx \\P \\left( \\frac{a+1-\\mu }{\\sigma }%\n\\leq Z\\leq \\frac{b-\\mu }{\\sigma }\\right)\n\\end{equation*}\nThis will yield a different value from our previous approximation since the\nlower Z-score is now $\\frac{a+1-\\mu }{\\sigma }$ instead of $\\frac{a-\\mu }{%\n\\sigma }$; the difference can be described by \n\\begin{eqnarray*}\n&&\\P \\left( \\frac{a-\\mu }{\\sigma }\\leq Z\\leq \\frac{b-\\mu }{\\sigma }\\right)\n-\\P \\left( \\frac{a+1-\\mu }{\\sigma }\\leq Z\\leq \\frac{b-\\mu }{\\sigma }\\right)\n\\\\\n&=&\\P \\left( \\frac{a-\\mu }{\\sigma }\\leq Z\\leq \\frac{a-\\mu }{\\sigma }+\\frac{1%\n}{\\sigma }\\right) .\n\\end{eqnarray*}%\nRecall that $\\sigma =\\sqrt{np(1-p)}$ here, so that $1/\\sigma $ is small. At\nthe same time, this difference approximates the difference \n\\begin{equation*}\n\\P \\left( a<X\\leq b\\right) -\\P \\left( a+1\\leq X\\leq b\\right) =\\P \\left(\nX=a\\right)\n\\end{equation*}%\nfor $a=20$, so that it turns out that we approximate an individual\nprobability $\\P \\left( X=a\\right) $ for a binomial $X$ by (setting $z(a)=%\n\\frac{a-\\mu }{\\sigma }$) \n\\begin{equation}\n\\P \\left( X=a\\right) \\approx \\int_{z(a)}^{z(a)+1/\\sigma }\\varphi (t)dt.\n\\label{indiv-probab-approx}\n\\end{equation}%\nwhere $1/\\sigma $ is small. The right hand side is an integral of the\nstandard normal density over a small piece of size $1/\\sigma .$ Extending\nthis reasoning to all integers between $a=20$ and $b=30$, we obtain \n\\begin{equation*}\n\\P \\left( a\\leq X\\leq b\\right) =\\sum_{k=0}^{10}\\P \\left( X=a+k\\right)\n\\end{equation*}%\n\\textit{so we have }$11$\\textit{\\ individual probabilities to approximate.}\nOn the other hand, our original approximation was%\n\\begin{equation}\n\\P \\left( a\\leq X\\leq b\\right) \\approx \\int_{z(a)}^{z(b)}\\varphi (t)dt.\n\\label{uncorrected}\n\\end{equation}%\nand noting $z(a)+10/\\sigma =z(b),$ we note that the interval $\\left(\nz(a),z(b)\\right) $ \\textit{contains only }$10$\\textit{\\ of the small\nintervals of length }$1/\\sigma $\\textit{.} So there is a slight\ninconsistency in our method.\n\nThis can be corrected by replacing the approximation (\\ref%\n{indiv-probab-approx}), that is, integration over the interval $\\left(\nz(a),z(a)+1/\\sigma \\right) $, by integration over a symmetric interval\naround $z(a)$ having the same length: $\\left( z(a)-1/2\\sigma ,z(a)+1/2\\sigma\n\\right) $, so that we now use \n\\begin{equation}\n\\P \\left( X=a\\right) \\approx \\int_{z(a)-1/2\\sigma }^{z(a)+1/2\\sigma\n}\\varphi (t)dt.  \\label{indiv-probab-approx-corr-1}\n\\end{equation}%\nSince \n\\begin{eqnarray*}\nz(a)-1/2\\sigma &=&\\frac{a-\\mu }{\\sigma }-\\frac{1}{2\\sigma }=\\frac{a-1/2-\\mu \n}{\\sigma }=z(a-1/2) \\\\\nz(a)+1/2\\sigma &=&z(a+1/2),\n\\end{eqnarray*}%\nwe may write (\\ref{indiv-probab-approx-corr-1}) as \n\\begin{equation}\n\\P \\left( X=a\\right) \\approx \\int_{z(a-1/2)}^{z(a+1/2)}\\varphi (t)dt.\n\\label{indiv-probab-approx-corr-2}\n\\end{equation}%\nThe principle of using (\\ref{indiv-probab-approx-corr-2}) for individual\nbinomial probabilities is known as the \\textit{correction for continuity}.\nIt implies that, for $\\P \\left( a\\leq X\\leq b\\right) $, we now use an\napproximation \n\\begin{equation}\n\\P \\left( a\\leq X\\leq b\\right) \\approx \\int_{z(a-1/2)}^{z(b+1/2)}\\varphi\n(t)dt  \\label{uncorrected-corr}\n\\end{equation}%\nrather than (\\ref{uncorrected}). This corrected method is now consistent in\nitself, that is, the left side splits up into 11 individual probabilities $%\n\\P \\left( X=k\\right) $:%\n\\begin{equation*}\n\\P \\left( a\\leq X\\leq b\\right) =\\sum_{k=0}^{10}\\P \\left( X=a+k\\right) ,\n\\end{equation*}%\nand similarly the right side in (\\ref{uncorrected-corr}) splits into $11$\nintegrals over small pieces of length $1/\\sigma $.\n\nWhether we use the continuity correction or not, the individual binomial\nprobabilities will be small for large $n$: for some $t^{\\ast }$ \n\\begin{eqnarray*}\n\\P \\left( X=a\\right) &\\approx &\\int_{z(a)-1/2\\sigma }^{z(a)+1/2\\sigma\n}\\varphi (t)dt=\\frac{1}{\\sigma }\\varphi (t^{\\ast })=\\frac{1}{\\sqrt{np(1-p)}}%\n\\varphi (t^{\\ast }) \\\\\n&\\leq &\\frac{1}{\\sqrt{n}}\\cdot \\frac{1}{\\sqrt{2\\pi p(1-p)}},\n\\end{eqnarray*}\nfor some $t^{\\ast }$ with $z(a)-1/2\\sigma <t^{\\ast }<z(a)+1/2\\sigma $, and\nin view of \n\\begin{equation*}\n\\varphi (t^{\\ast })=\\frac{1}{\\sqrt{2\\pi }}\\exp (-t^{\\ast }/2)\\leq \\frac{1}{%\n\\sqrt{2\\pi }}.\n\\end{equation*}%\nThus the individual binomial probabilities will decrease like $1/\\sqrt{n}$\nas $n\\rightarrow \\infty $ at most (or will be even smaller).\n\n%\\begin{mycomments-env}\n%If possible, add a histogram picture, on the scale of $X$ and $\\normal(\\mu ,\\sigma\n%^{2})$, similar to standard argument (cf. DeGroot, Shervish, p. 293).\n%\n%A paragraph on a local limit theorem might be added. The proper reference\n%is: Borovkov (Russian, 1976), p. 107. Below we append an earlier paragraph\n%about ``behaviour of binomial probabilities\".\n%\n%How do the binomial probabilities%\n%\\begin{equation*}\n%p_{n,k}:=\\P \\left( S_{n}=k\\right) =p^{k}\\left( 1-p\\right) ^{n-k}\\left( \n%\\binom{n}{k}\\right)\n%\\end{equation*}%\n%behave in the context of the CLT ? Firstly, we should suppose they tend to $%\n%0,$ since (arguing nonrigorously) $\\sum_{k=0}^{n}p_{n,k}=1$ and there are $%\n%n+1$ of them. Moreover the CLT implies that for any $a,b$ $,$ $a<b$%\n%\\begin{equation*}\n%\\P \\left( a\\leq \\frac{S_{n}-np}{\\sqrt{np(1-p)}}\\leq b\\right) \\rightarrow\n%\\int_{a}^{b}\\varphi (t)dt\n%\\end{equation*}%\n%where $\\varphi $ is the standard normal density.\n%\n%Note that $S_{n}$ takes values in $\\left\\{ 0,1,2,\\ldots ,n\\right\\} $, i.e.\n%in ``grid points\" with step size $1$. Hence the standardized sum $\\frac{%\n%S_{n}-np}{\\sqrt{n}c}$ (where $c=\\sqrt{p(1-p)}$) takes values in ``grid\n%points\" $t_{k,n}=\\frac{k-np}{\\sqrt{n}c}$ which have step size $\\frac{1}{%\n%\\sqrt{n}c}$.\n%\n%How would we approximate the normal integral $\\int_{a}^{b}\\varphi (t)dt$ by\n%a Riemann sum, using the integrand function $\\varphi (t)$, on a grid of\n%points $\\left\\{ t_{k,n}\\right\\} $ ? Obviously we would use the approximation \n%\\begin{equation}\n%\\sum_{a\\leq t_{k,n}\\leq b}\\varphi (t_{k,n})\\frac{1}{\\sqrt{n}c}\\rightarrow\n%\\int_{a}^{b}\\varphi (t)dt\\text{ as }n\\rightarrow \\infty  \\label{compar-1}\n%\\end{equation}%\n%since $\\frac{1}{\\sqrt{n}c}$ is exactly the distance between the points $%\n%t_{k,n}$. On the other hand we have by the CLT, if $p_{n,k}=\\P \\left(\n%S_{n}=k\\right) $ are the binomial probabilities \n%\\begin{equation}\n%\\P \\left( a\\leq \\frac{S_{n}-\\text{ }np}{\\sqrt{np(1-p)}}\\leq b\\right)\n%=\\sum_{a\\leq t_{k,n}\\leq b}p_{n,k}\\rightarrow \\int_{a}^{b}\\varphi (t)dt\\text{\n%as }n\\rightarrow \\infty  \\label{compar-2}\n%\\end{equation}%\n%Comparing (\\ref{compar-1}) and (\\ref{compar-2}) we find that \n%\\begin{equation*}\n%\\sum_{a\\leq t_{k,n}\\leq b}\\varphi (t_{k,n})\\frac{1}{\\sqrt{n}c}-\\sum_{a\\leq\n%t_{k,n}\\leq b}p_{n,k}\\rightarrow 0\\text{ as }n\\rightarrow \\infty .\n%\\end{equation*}%\n%Comparing the individual terms in this sum we are led to believe that each\n%ndividual $p_{n,k}$ behaves like the associated $\\varphi (t_{k,n})/\\sqrt{n}%\n%c,$ more precisely that \n%\\begin{equation*}\n%\\varphi (t_{k,n})-p_{n,k}\\sqrt{n}c\\rightarrow 0\\text{ as }n\\rightarrow\n%\\infty .\n%\\end{equation*}%\n%Such a result can be obtained rigorously and is known as a \\textbf{local\n%limit theorem }(local CLT ).\n%\\end{mycomments-env}\n\n%TCIMACRO{\\TeXButton{end-mycomments}{\\end{mycomments}}}%\n%BeginExpansion\n%\\end{mycomments}%\n%EndExpansion\n\n\\subsubsection{The normal table and quantiles}\n\nThe so-called $Z$-table gives the areas under the standard normal curve%\n\\begin{equation*}\n\\P \\left( Z\\leq z\\right) =\\int_{-\\infty }^{z}\\varphi (t)dt.\n\\end{equation*}%\nIt is well known that the normal integral \n\\begin{equation*}\n\\int_{-\\infty }^{z}\\varphi (t)dt=\\frac{1}{\\sqrt{2\\pi }}\\int_{-\\infty\n}^{z}\\exp \\left( -t^{2}/2\\right) dt\n\\end{equation*}%\ndoes not have an explicit analytic solution. Hence the necessity to use a\nnumerically computed table; statistical software has these values stored (or\nsometimes computes them).\n\nAs an example, suppose $z=-1.26$. First, look up the value of $z$ without\nthe second decimal place, i.e. $-1.2$, in one of the two columns headed ``z\".\nTo the left of $-1.2$ you find all the probabilities $\\P \\left( Z\\leq\n-1.2-s\\right) $ for $s=0.00,\\ldots ,0.09$, i.e. for values of the second\ndecimal place. In our example we have $s=0.06$, so we go to the column\nheaded ``$0.06$\" and find $\\P \\left( Z\\leq -1.26\\right) =0.1038$.\n\nConsider a positive value of $z$, e.g. $z=2.73.$ First, look up the value of \n$z$ without the second decimal place, i.e. $2.7$, in one of the two columns\nheaded ``z\". To the right of $2.73$ you find all the probabilities $\\P\n\\left( Z\\leq 2.7+s\\right) $ for $x=0.00,\\ldots ,0.09$, i.e. for values of\nthe second decimal place. In our example we have $s=0.03$, so we go to the\ncolumn headed ``$0.03$\" and find $\\P \\left( Z\\leq 2.73\\right) =0.9968$.\n\nUseful rules to find other normal probabilities are \n\\begin{equation*}\n\\P \\left( Z<z\\right) =\\P \\left( Z\\leq z\\right)\n\\end{equation*}%\n(since for a continuous RV having a density, $\\P \\left( Z=z\\right) =0$), \n\\begin{eqnarray*}\n\\P \\left( Z\\geq z\\right) &=&1-\\P \\left( Z\\leq z\\right) \\\\\n&=&\\P \\left( Z\\leq -z\\right)\n\\end{eqnarray*}%\nThe last two equalities give two ways of looking up $\\P \\left( Z\\geq\nz\\right) $ in the table. The second equality derives from the symmetry of\nthe normal density: since $\\varphi (t)=\\varphi (-t)$, we have \n\\begin{eqnarray*}\n\\P \\left( Z\\geq z\\right) &=&\\int_{z}^{\\infty }\\varphi\n(t)dt=\\lim_{x\\rightarrow \\infty }\\int_{z}^{x}\\varphi\n(t)dt=\\lim_{x\\rightarrow \\infty }\\int_{-x}^{-z}\\varphi (t)dt \\\\\n&=&\\int_{-\\infty }^{-z}\\varphi (t)dt=\\P \\left( Z\\leq -z\\right) .\n\\end{eqnarray*}%\nIt also follows that $\\P \\left( Z\\leq 0\\right) =\\P \\left( Z\\geq 0\\right)\n=1/2$.\n\nThe table begins at $z=-3.9$ and ends at $z=3.9$, for which the\nprobabilities are given as $0.0000$ and $1$.$0000$ respectively, i.e. they\nare given up to $4$ decimal places. There is a famous rule for the\npractitioner giving the probability content of certain intervals around $0.$\n\n\\bigskip\n\n\\textbf{The 68-95-99.7 rule }(De Moivre, 1733).\\textbf{\\ }\\emph{In a normal\nmodel }$\\normal(\\mu ,\\sigma ^{2})$\\emph{, about }$68\\%$\\emph{\\ of the values fall\nwithin one standard deviation of the mean, about }$95\\%$\\emph{\\ of the\nvalues fall within two standard deviations of the mean, and about }$99.7\\%$%\n\\emph{\\ of the values fall within three standard deviations of the mean.}%\n\\bigskip\\ \n\nThe last part (99.7 part) is also called the $3\\sigma -$\\textbf{rule}. Let\nus verify these claims, using the $Z$-table. Suppose $\\mathcal{L}\\left(\nX\\right) =\\normal(\\mu ,\\sigma ^{2})$; then for $k=1,2,3$ \n\\begin{eqnarray*}\n\\P \\left( \\mu -k\\sigma \\leq X\\leq \\mu +k\\sigma \\right) &=&\\P \\left( -k\\leq \n\\frac{X-\\mu }{\\sigma }\\leq k\\right) =\\P \\left( -k\\leq Z\\leq k\\right) \\\\\n&=&\\P \\left( Z\\leq k\\right) -\\P \\left( Z\\leq -k\\right) .\n\\end{eqnarray*}%\nFor $k=1,2,3$ we find \n\\begin{eqnarray*}\n\\P \\left( Z\\leq 1\\right) -\\P \\left( Z\\leq -1\\right)\n&=&0.8413-0.1568=0.6845, \\\\\n\\P \\left( Z\\leq 2\\right) -\\P \\left( Z\\leq -2\\right)\n&=&0.9772-0.0228=0.954\\,4, \\\\\n\\P \\left( Z\\leq 3\\right) -\\P \\left( Z\\leq -3\\right)\n&=&0.9987-0.0013=0.9974.\n\\end{eqnarray*}%\nThe rule (as an approximation statement)\\ is confirmed. \\bigskip\n\n\\textbf{Reverse lookup and quantiles.} It is often of interest to find a\nvalue of $z$ which matches a certain probability, say $\\alpha $ ($0<a<1$),\nsuch that$,$ if $X$ is a RV \n\\begin{equation*}\n\\P \\left( X\\geq z\\right) =\\alpha .\n\\end{equation*}%\nIn this case we write $z=z_{\\alpha}$ and call this the \\textbf{%\nupper }$\\alpha $\\textbf{-quantile} of the distribution of $X$. Note that if $%\nX$ is $\\normal(\\mu ,\\sigma ^{2})$ then $z_{\\alpha}$ is uniquely defined:\nthe equation \n\\begin{equation*}\n\\int_{z}^{\\infty }\\varphi _{\\mu ,\\sigma ^{2}}(t)dt=\\alpha\n\\end{equation*}%\nhas a unique solution in $z$, since the left side is continuous, strictly\nmonotone decreasing in $z$ and ranges between $0$ and $1$. Here $\\varphi\n_{\\mu ,\\sigma ^{2}}(t)=\\varphi (\\left( t-\\mu \\right) /\\sigma )/\\sigma $ is\nthe density of $\\normal(\\mu ,\\sigma ^{2})$; since this density is strictly\npositive everywhere, we find \n\\begin{equation*}\n\\frac{d}{dz}\\int_{z}^{\\infty }\\varphi _{\\mu ,\\sigma ^{2}}(t)dt=-\\varphi\n_{\\mu ,\\sigma ^{2}}(z)<0\n\\end{equation*}%\nand indeed $\\P \\left( X\\geq z\\right) $ is strictly decreasing in $z$. For $%\n\\alpha =0.25$ the $z_{\\alpha}$ called \\textbf{the upper quartile}\nof the distribution; for $\\alpha =0.75$ the $z_{\\alpha}$ called \n\\textbf{the lower quartile}. For $\\alpha =0.5$ we obtain the \\textbf{median}\nof distribution of $X$; for $\\normal(\\mu ,\\sigma ^{2})$ it coincides with the mean \n$\\mu $. We can also define \\textbf{lower }$\\alpha $\\textbf{-quantiles} by\nsolving $\\P \\left( X\\leq z\\right) =\\alpha $ for $z$.\n\n\n\\begin{example}\nSuppose that Verbal SAT test scores $X$ are described by a\nnormal curve, for which the mean is 500 and the standard deviation is 100. A\nstudent's score is better than 75\\% of all the scores. What is the student's\nscore?\n\n\n\\medskip \\textbf{Solution. }We are asked the upper $25$\\%-quantile (or $0.25$%\n-quantile, or the upper quartile) of $\\normal(\\mu ,\\sigma ^{2})$ with $\\mu =500$\nand $\\sigma =100.$ Call this $s$ now, i.e. $s$ is the student's score. We\nmust have \n\\begin{equation*}\nP(X\\geq s)=0.25\n\\end{equation*}%\nhence \n\\begin{equation*}\nP(X\\leq s)=0.75=P\\left( \\frac{X-\\mu }{\\sigma }\\leq \\frac{s-\\mu }{\\sigma }%\n\\right) =P\\left( Z\\leq \\frac{s-\\mu }{\\sigma }\\right) .\n\\end{equation*}%\nLet $s^{\\ast }=(s-\\mu )/\\sigma ,$ then \n\\begin{equation*}\nP\\left( Z\\leq s^{\\ast }\\right) =0.75\n\\end{equation*}%\ni.e. $s^{\\ast }=z_{1/4}^{\\ast }$ is the upper quartile of $\\normal(0,1)$. By\n``reverse lookup\" in the $Z$-table, we find the two closest to $0.75$ entries\n(probabilities) to be $0.7486$ and $0.7517$, corresponding to $z$-values $%\n0.67$ and $0.68$ respectively (i.e. $\\P \\left( Z\\leq 0.67\\right) =0.7486$).\nA common method now is to interpolate between these two values of $z$, which\nwould give us $z_{1/4}^{\\ast }=s^{\\ast }=0.675$. This gives a value for $s$ \n\\begin{equation*}\ns=\\sigma s^{\\ast }+\\mu =67.5+500=567.5.\n\\end{equation*}%\nThe method can be summarized: if $z_{\\alpha}$ denotes the $\\alpha $%\n-quantile of $\\normal(0,1)$ and $x_{\\alpha }^{\\ast }$ denotes the $\\alpha $%\n-quantile of $\\normal(\\mu ,\\sigma ^{2})$ then $x_{\\alpha }^{\\ast }=\\sigma\nz_{\\alpha}+\\mu $\n\\end{example}\n\n\\subsubsection{Drawing the normal curve}\n\nBelow we are plotting the normal density with mean $\\mu =5$ and standard\ndeviation $\\sigma =5$.\n\n\\vspace{5cm}\n~\\\\\n\nWe see that at $x=0$\nthe curve changes curvature, i. e. left of $0 $ it is convex (downward bent)\nand right of $0$ it is concave (upward bent). Such a point is called an \n\\textbf{inflection point}. We see that at $x=10$ there is another inflection\npoint, and both inflection points are one standard deviation away from the\nmean. We will show that this a general feature of any normal distribution $%\n\\normal(\\mu ,\\sigma ^{2})$.\n\nTo see this, note that a smooth function $f$ (which has at least 2\nderivatives) is convex at $x$ if $f^{\\prime }$ is increasing at $x$\n(strictly increasing, say), which means $f^{\\prime \\prime }(x)>0$.\nSimilarly, $f$ is concave at $x$ if $f^{\\prime \\prime }(x)<0$. The density\nof $\\normal(\\mu ,\\sigma ^{2})$ is \n\\begin{equation*}\nf(x)=\\frac{1}{\\sigma }\\varphi \\left( \\frac{x-\\mu }{\\sigma }\\right)\n\\end{equation*}%\nwhere $\\varphi \\left( t\\right) =\\frac{1}{\\sqrt{2\\pi }}\\exp \\left(\n-t^{2}/2\\right) $ is the density of $\\normal(0,1)$. Now \n\\begin{eqnarray}\nf^{\\prime }(x) &=&\\frac{1}{\\sigma ^{2}}\\varphi ^{\\prime }\\left( \\frac{x-\\mu \n}{\\sigma }\\right) \\text{, }  \\notag \\\\\nf^{\\prime \\prime }(x) &=&\\frac{1}{\\sigma ^{3}}\\varphi ^{\\prime \\prime\n}\\left( \\frac{x-\\mu }{\\sigma }\\right)  \\label{inflec}\n\\end{eqnarray}%\nand \n\\begin{eqnarray*}\n\\varphi ^{\\prime }\\left( t\\right) &=&\\frac{d}{dt}\\frac{1}{\\sqrt{2\\pi }}\\exp\n\\left( -t^{2}/2\\right) =-\\frac{1}{\\sqrt{2\\pi }}\\exp \\left( -t^{2}/2\\right)\n\\cdot t, \\\\\n\\varphi ^{\\prime \\prime }\\left( t\\right) &=&\\frac{1}{\\sqrt{2\\pi }}\\left(\n\\exp \\left( -t^{2}/2\\right) \\cdot t^{2}-\\exp \\left( -t^{2}/2\\right) \\right)\n\\\\\n&=&\\varphi \\left( t\\right) \\cdot \\left( t^{2}-1\\right) .\n\\end{eqnarray*}%\nIt follows that $\\varphi ^{\\prime \\prime }\\left( t\\right) <0$ for $|t|<1$\nand $\\varphi ^{\\prime \\prime }\\left( t\\right) >0$ for $|t|>1$, hence the\ninflection points of $\\varphi $ are $-1$ and $1$. From (\\ref{inflec}) it\nfollows that $f^{\\prime \\prime }(x)<0$ if $\\left\\vert \\frac{x-\\mu }{\\sigma }%\n\\right\\vert <1$ etc, so that the inflection points of $f$ are at $x=\\mu \\pm\n\\sigma $.\n\n\\subsubsection{Chebyshev's inequality and the normal tail}\n\nA \\textit{tail estimate} for a RV $X$ is an estimate for the probability $%\n\\P \\left( \\left\\vert X\\right\\vert >t\\right) $. We may compare the tail\nestimates obtained from the standard normal $Z\\ $with those from the\nChebyshev inequality. The latter lells us that for any RV $X$ with $\\E X=0$\nand $\\V(X)=1$ and any $t>0$ \n\\begin{equation*}\n\\P \\left( \\left\\vert X\\right\\vert >t\\right) \\leq t^{-2}\n\\end{equation*}%\nwhich for $t=1$ gives $1$ (i.e. it is trivial), for $t=2$ it gives $0.25$\nand for $t=3$ it gives $1/9=0.11$. For the standard normal we obtain the\ncorresponding $\\P \\left( \\left\\vert Z\\right\\vert >t\\right) $ from the table\n(or approximately from the $3\\sigma $-rule) as $0.315\\,5$ for $t=1$, $%\n0.045\\,6$ for $t=2$ and $0.002\\,6$ for $t=3$. Thus the normal tail decreases\nmuch faster than $1/t^{2}$, the upper bound from the Chebyshev inequality.\nThis is not surprising in view of the form of the normal density: we have \n\\begin{equation*}\n\\P \\left( \\left\\vert Z\\right\\vert >t\\right) =2\\int_{t}^{\\infty }\\varphi\n(u)du=\\sqrt{\\frac{2}{\\pi }}\\int_{t}^{\\infty }\\exp \\left( -u^{2}/2\\right) du\n\\end{equation*}%\nand we would expect that the integral decreases with a similarly fast rate\nas the density $\\varphi $ itself, as the lower bound $t$ tends to infinity.\nThis is made precise by the following result.\n\n\\begin{prop}\n(\\textbf{Mill's inequality}) Let $\\mathcal{L}(Z)=\\normal(0,1)$. Then \n\\begin{equation}\nP\\left( \\left\\vert Z\\right\\vert >t\\right) \\leq \\sqrt{\\frac{2}{\\pi }}\\frac{1}{%\nt}\\exp \\left( -t^{2}/2\\right) .  \\label{mills-ineq}\n\\end{equation}\n\\end{prop}\n\n\\begin{proof}\nObserve that $u/t\\geq 1$ for $u\\geq t$, hence \n\\begin{eqnarray*}\n\\P \\left( \\left\\vert Z\\right\\vert >t\\right) &\\leq &\\sqrt{\\frac{2}{\\pi }}%\n\\frac{1}{t}\\int_{t}^{\\infty }u\\exp \\left( -u^{2}/2\\right) du \\\\\n&=&\\sqrt{\\frac{2}{\\pi }}\\frac{1}{t}\\lim_{x\\rightarrow \\infty\n}\\int_{t}^{x}u\\exp \\left( -u^{2}/2\\right) du \\\\\n&=&\\sqrt{\\frac{2}{\\pi }}\\frac{1}{t}\\lim_{x\\rightarrow \\infty }\\left[ -\\exp\n\\left( -u^{2}/2\\right) \\right] _{t}^{x} \\\\\n&=&\\sqrt{\\frac{2}{\\pi }}\\frac{1}{t}\\exp \\left( -t^{2}/2\\right) .\n\\end{eqnarray*}\n\\end{proof}\n\n\nSuppose again that $S_{n}=\\sum_{i=1}^{n}X_{i}$ where $X_{i}$ are IID\nBernoulli $\\bernoulli(p)$. The Chebyshev inequality gives for a tail\nprobability \n\\begin{equation*}\n\\P \\left( \\left\\vert \\frac{S_{n}-np}{\\sqrt{np(1-p)}}\\right\\vert >t\\right)\n\\leq 1/t^{2}\n\\end{equation*}%\nand it is \\textit{exact} (holds for every $n$). In contrast, the normal tail\nestimate holds only as a limiting result for large $n,$ i.e. $\\P \\left(\n\\left\\vert \\cdot \\right\\vert >t\\right) \\rightarrow \\P \\left( \\left\\vert\nZ\\right\\vert >t\\right) $). But then the upper bound on $\\P \\left(\n\\left\\vert \\cdot \\right\\vert >t\\right) $ suggested is much smaller than the\none of Chebyshev's inequality, as shown by Mill's inequality. Obviously, for\napplications a choice is to be made. Probability estimates which hold only\nas limits for $n\\rightarrow \\infty $ are called \\textit{asymptotic}. Much of\nthe basic statistical methods to be discussed (confidence intervals, tests)\\\nare asymptotic \\ in this sense, based on an assumption that $n$ is large\nenough. \\bigskip\n\n\\begin{Exercise}\nShow that Mill's inequality is sharp in the\nfollowing sense: as $t\\rightarrow \\infty$, the ratio of the left and\nright sides of (\\ref{mills-ineq}) tends to one. A common notation for this\nis: \n\\begin{equation*}\nP\\left( \\left\\vert Z\\right\\vert >t\\right) \\sim \\sqrt{\\frac{2}{\\pi }}\\frac{1}{%\nt}\\exp \\left( -t^{2}/2\\right) \\text{ as }t\\rightarrow \\infty\n\\end{equation*}%\n\\emph{where the symbol \"}$\\sim $\\emph{\" applied to two functions }$g(t)$%\n\\emph{, }$h(t)$\\emph{\\ means that }$g(t)/h(t)\\rightarrow 1$\\emph{\\ as }$t$%\n\\emph{\\ tends to a limit (}$t\\rightarrow \\infty $\\emph{\\ on our case). }\n\\end{Exercise}\n\n\\subsection{Confidence intervals for a proportion}\\label{S:ConfIntForProps}\n\n\\subsubsection{Basic reasoning for a normal mean}\n\nSuppose that a random variable $X$ has a distribution $\\normal(\\mu ,1)$, i.e. it\ncan be written $X=\\mu +Z$. Suppose further that we do not know $\\mu $, but\nwe observe $X$ (\\textit{one observation only}, i.e we obtain one realization\nof $X$). What statements can be made about the unknown $\\mu $ ?\n\nFrom the $3\\sigma $-rule we know that with probability $99.7\\%$, $Z$ falls\nwithin a distance $3$ from $0.$ Consequently, $X$ falls within a distance $3$\nfrom $\\mu $, with the same probability $99.7\\%$. Now we have observed $X$,\nand we know that \n\\begin{equation*}\n\\P \\left( \\left\\vert X-\\mu \\right\\vert \\leq 3\\right) =0.997\n\\end{equation*}%\nwhich can equivalently be expressed as: ``the interval $\\left[ X-3,X+3\\right] \n$ covers $\\mu $ with probability $99.7\\%$\" or formally \n\\begin{equation}\n\\P \\left( \\left[ X-3,X+3\\right] \\ni \\mu \\right) =0.997.\n\\label{confid-interv}\n\\end{equation}%\nHere ``$\\ni $\" is the inverted ``element of\" sign $\\in $ which should be read\n``the interval contains\" or ``the interval covers\". Of course we could have\nwritten $\\mu \\in \\left[ X-3,X+3\\right] $, but to stress the fact that \\emph{%\nthe interval is random, not }$\\mu $, we write $\\left[ X-3,X+3\\right] \\ni \\mu \n$.\n\nSuppose that $X$ has been observed and takes the value $x$. Then, based on (%\n\\ref{confid-interv}), the interval $\\left[ x-3,x+3\\right] $ is called a \n\\textit{confidence interval} and the probability $0.997$ is called the \n\\textit{confidence level}, usually denoted by $C$. As an example, assume $%\nx=2 $ was observed. Then $\\left[ -1,5\\right] $ is a confidence interval of\nlevel $C=99.7$ percent. Based on the probability estimate (\\ref%\n{confid-interv}), the statement usually associated to the interval is: ``we\nare $99.7$ \\% confident that $\\left[ -1,5\\right] $ covers the unknown mean $%\n\\mu $\".\n\nA confidence statement like this is not the same as a probability statement:\nit is not claimed that, after $x$ is already observed, that ``the probability\nthat the interval $\\left[ -1,5\\right] $ covers the true mean $\\mu $ is $%\n99.7\\%$\". Indeed after $X$ took the value $x=2$, there is no randomness\nleft, when we assume that $\\mu $ is merely unknown, but not random. What can\nbe said about the interval $\\left[ -1,5\\right] $ is a \\textit{confidence\nstatement}, not a probability statement. This is based on the probability\nstatement: in $99.7\\%$ of all cases, the interval obtained by this method\ncovers the true parameter - formally expressed as (\\ref{confid-interv})\nwhere $X$ is random. When $X=x$ is realized, i.e. no longer random, the\nconfidence statement about $\\left[ -1,5\\right] $ is derived ``in hindsight\"\nfrom (\\ref{confid-interv}).\n\nThe confidence level $C=99.7\\%$ is not a commonly used value; these are $%\n99\\% $ and $95\\%$. Let us find the corresponding confidence intervals for $%\n\\mu $, based on $X\\sim \\normal(\\mu ,1)\\footnote{%\nThe notation $X\\sim \\normal(\\mu ,1)$ is a commonly used equivalent for $\\mathcal{L}%\n(X)=\\normal(\\mu ,1)$. Similarly, $X\\sim Y$ will be used for $\\mathcal{L}(X)=%\n\\mathcal{L}(Y)$. This usage should not be confused with the one for\nnonrandom sequences $x_{n}$,$y_{n}$, where the symbol $x_{n}\\sim y_{n}$\nmeans $x_{n}$/$y_{n}\\rightarrow 1$.}$ We have to solve%\n\\begin{equation*}\n\\P \\left( \\left\\vert X-\\mu \\right\\vert \\leq z\\right) =C\n\\end{equation*}%\nfor $z>0$, upon which $\\left[ X-z,X+z\\right] $ will be a level $C$\nconfidence interval. Since $X-\\mu \\sim Z$, we have \n\\begin{eqnarray*}\n\\P \\left( \\left\\vert Z\\right\\vert \\leq z\\right) &=&1-2\\P \\left( Z>z\\right)\n=C, \\\\\n\\P \\left( Z>z\\right) &=&\\left( 1-C\\right) /2=:\\alpha .\n\\end{eqnarray*}%\nThus $z=z_{\\alpha}$, the upper $\\alpha $-quantile of $Z$ for $%\n\\alpha =\\left( 1-C\\right) /2$. The commonly used values are easily found\nfrom the table, using $\\P \\left( Z>z\\right) =\\P \\left( Z<-z\\right) $:%\n\\begin{eqnarray*}\nC &=&99\\%\\text{, }\\alpha =0.005\\text{, }z_{\\alpha}=2.578 \\\\\nC &=&95\\%\\text{, }\\alpha =0.025\\text{, }z_{\\alpha}=1.96.\n\\end{eqnarray*}%\nRecall the second part of the 68-95-99.7\\% rule: there it was claimed that $%\n\\P \\left( \\left\\vert Z\\right\\vert \\leq 2\\right) \\approx 95\\%$; we just\nfound the corresponding quantile more accurately: it is not $2$ but $1.96.$\n\nThe idea of the confidence interval for the unknown mean $\\mu $ can easily\nbe extended to the case where we observe (one) $X\\sim \\normal(\\mu ,\\sigma ^{2})$\nprovided $\\sigma ^{2}$ is known. Let $C$ be the confidence level and $\\alpha\n=(1-C)/2$; then $\\left( X-\\mu \\right) /\\sigma \\sim Z$ and \n\\begin{eqnarray*}\nC &=&\\P \\left( \\left\\vert Z\\right\\vert \\leq z_{\\alpha}\\right) =\\P\n\\left( \\left\\vert \\frac{X-\\mu }{\\sigma }\\right\\vert \\leq z_{\\alpha }\\right) \\\\\n&=&\\P \\left( \\left\\vert X-\\mu \\right\\vert \\leq \\sigma z_{\\alpha }\\right) =\\P \\left( \\left[ X-\\sigma z_{\\alpha},X+\\sigma z_{\\alpha\n}\\right] \\ni \\mu \\right) .\n\\end{eqnarray*}\n\n\\begin{prop}\n\\label{prop-normal-CI}Suppose a RV $X\\sim \\normal(\\mu ,\\sigma ^{2})$ is observed\nwhere $\\mu $ is unknown and $\\sigma >0$ is known. Let $z_{\\alpha}$\nbe the upper $\\alpha $-quantile of $Z$ for some $0<\\alpha <1/2$. Then for $%\nC=1-2\\alpha $.%\n\\begin{equation*}\n\\P \\left( \\left[ X-\\sigma z_{\\alpha},X+\\sigma z_{\\alpha}%\n\\right] \\ni \\mu \\right) =C,\n\\end{equation*}%\nwhich means that for any observed value $X=x$, the interval $\\left[ x-\\sigma\nz_{\\alpha},x+\\sigma z_{\\alpha}\\right] $ is a confidence\ninterval for $\\mu $ of level $C$.\n\\end{prop}\n\nIn what follows, we will generally abbreviate the statement: ``\\textit{for\nany observed value }$X=x$\\textit{, the interval }$\\left[ x-\\sigma z_{\\alpha},x+\\sigma z_{\\alpha}\\right] $\\textit{\\ is a confidence\ninterval for.. }\" by: ``\\textit{the interval }$\\left[ X-\\sigma z_{\\alpha},X+\\sigma z_{\\alpha}\\right] $\\textit{\\ is a confidence\ninterval for ...}.\"\\bigskip\n\n\\textbf{Parameters and statistical inference.} We assumed initially that we\nobserve $X\\sim \\normal(\\mu ,1)$ (or equivalently an $X$ with $\\mathcal{L}(X)=\\normal(\\mu\n,1)$) where the mean $\\mu $ is unknown. In that context $\\mu $ is called a%\n\\textit{\\ parameter} of the distribution of $X$. Constructing a confidence\ninterval for $\\mu $ is an example of \\textit{statistical inference }%\nregarding a parameter. Other examples of inference are hypothesis tests\n(about a parameter) and estimation of a parameter, also called \\textit{point\nestimation}. In point estimation one just gives a ``reasonable guess\" of a\nparameter. Note that if $X\\sim \\normal(\\mu ,1)$, then $X$ itself is a reasonable\nguess of $\\mu $, i.e. a point estimate. In contrast, a confidence interval\ngives a range and an attached probability statement; a confidence interval\nis also called an \\textit{interval estimate}. In the case $X\\sim \\normal(\\mu\n,\\sigma ^{2})$, both $\\mu $ and $\\sigma ^{2}$ may be parameters; above we\nassumed $\\sigma $ ``known\", i.e. we constructed a confidence interval which\nmade use of $\\sigma $ (namely $\\left[ X-\\sigma z_{\\alpha},X+\\sigma\nz_{\\alpha}\\right] $\\textit{\\ }). When $\\sigma $ is unknown, this\ninterval is not available. \\bigskip\n\n\\textbf{The case of }$n$\\textbf{\\ IID normal observations.} The model of \n\\textit{one }normal observation $X$ appears artificial; it may strike one as\na situation with very little data indeed. Consider instead the case of\nindependent observations $X_{1},\\ldots ,X_{n}$ all with law $\\normal(\\mu ,\\sigma\n^{2})$, and as above assume $\\mu $ is unknown while $\\sigma $ is known. To\nconstruct a confidence interval for $\\mu $, one may choose to take the\nsample mean $\\overline{X}_{n}$ first and then build an interval estimate using\ninformation about the law of $\\overline{X}_{n}$. Indeed we have from basic\nproperties of the normal law \n\\begin{equation*}\n\\overline{X}_{n}\\sim \\normal(\\mu ,n^{-1}\\sigma ^{2})\n\\end{equation*}%\n(this follows from the fact that the sum of independent normals is normal,\nand a mean and variance computation). As a reminder, let's compute the\nvariance: \n\\begin{eqnarray*}\n\\V(\\overline{X}_{n}) &=&\\V\\left(\nn^{-1}\\sum_{i=1}^{n}X_{i}\\right) =n^{-2}\\V\\left(\n\\sum_{i=1}^{n}X_{i}\\right) =_{\\text{(by independence)}}n^{-2}\\sum_{i=1}^{n}%\n\\V\\left( X_{i}\\right) \\\\\n&=&n^{-2}\\sum_{i=1}^{n}\\sigma ^{2}=n^{-1}\\sigma ^{2}.\n\\end{eqnarray*}%\nWe immediately obtain a confidence interval for $\\mu $, by treating $\\overline{X}%\n_{n}$ as ``one normal observation\" with mean $\\mu $ and variance $\\tau\n^{2}=n^{-1}\\sigma ^{2}$. We need only apply the previous Proposition \\ref%\n{prop-normal-CI} setting the standard deviation $\\tau =\\sigma /\\sqrt{n}$:\n\n\\begin{prop}\n\\label{prop-ci-normal-sample}Suppose independent observations $X_{1},\\ldots\n,X_{n}$ with $X_{i}\\sim \\normal(\\mu ,\\sigma ^{2})$ where $\\mu $ is unknown and $%\n\\sigma >0$ is known. Let $\\overline{X}_{n}$ be the sample mean and let $z_{\\alpha\n}^{\\ast }$ be the upper $\\alpha $-quantile of $Z$ for some $0<\\alpha <1/2$.\nThen $\\left[ \\overline{X}_{n}-\\sigma z_{\\alpha}/\\sqrt{n},\\overline{X}%\n_{n}+\\sigma z_{\\alpha}/\\sqrt{n}\\right] $ is a confidence interval\nfor $\\mu $ of level $C=1-2\\alpha $.\n\\end{prop}\n\n\\subsubsection{Asymptotics for the sample proportion}\n\nLet us return to the case of $n$ IID Bernoulli observations $X_{1},\\ldots ,X_{n}$\n$,$ $X_{i}\\sim \\bernoulli(\\theta^*)$ where $\\theta^* \\in (0,1)$ is unknown. Our goal is\nto construct a confidence interval of level $C$ for the unknown population\nproportion $\\theta^*$. The starting point is the normal approximation for the {\\em point estimator} $\\widehat{\\Theta}_n$ based on the sample proportion: \n\\begin{equation}\n\\widehat{\\Theta}_{n}=\\overline{X}_{n}=n^{-1}\\sum_{i=1}^{n}X_{i} \\quad \\text{ and } \\qquad\nT_{n}:=\\frac{\\widehat{\\Theta}_{n}-\\theta^*}{\\sqrt{\\theta^*(1-\\theta^*)}/\\sqrt{n}}\\rightsquigarrow Z\n\\label{sample-prop-limitlaw}\n\\end{equation}%\nwhere $Z\\sim \\normal(0,1)$.\n\n\\begin{lemma}\n\\label{lem-lawconv-interval}For $\\alpha =\\left( 1-C\\right) /2$ and $%\nz_{\\alpha}$ such that $\\P \\left( Z>z_{\\alpha}\\right)\n=\\alpha $ we have \n\\begin{equation*}\n\\P \\left( -z_{\\alpha}\\leq \\frac{\\widehat{\\Theta}_{n}-\\theta^*}{\\sqrt{\\theta^*(1-\\theta^*)}/\\sqrt{%\nn}}\\leq z_{\\alpha}\\right) \\rightarrow \\P \\left( -z_{\\alpha }^{\\ast\n}\\leq Z\\leq z_{\\alpha}\\right) =C\\text{ as }n\\rightarrow \\infty .\n\\end{equation*}\n\\end{lemma}\n\n\\begin{proof}\nIndeed we have \n\\begin{equation*}\n\\P \\left( -z_{\\alpha}\\leq T_{n}\\leq z_{\\alpha}\\right)\n=\\P \\left( T_{n}\\leq z_{\\alpha}\\right) -\\P \\left(\nT_{n}<-z_{\\alpha}\\right)\n\\end{equation*}%\nNow $\\P \\left( T_{n}\\leq t\\right) $ is the distribution function of $T_{n}$\nat $t$; by convergence in distribution $T_{n}\\rightsquigarrow Z$, $\\P \\left( T_{n}\\leq t\\right) $ tends to \n$\\P \\left( Z\\leq t\\right) =\\Phi (t)$ for every $t$ (since every $t$ is a\ncontinuity point of $\\Phi$). We also claim that for every $t$ \n\\begin{equation}\n\\P \\left( T_{n}<t\\right) \\rightarrow \\Phi (t).\n\\label{variant-of-lawconverg}\n\\end{equation}%\n(the distribution function of $T_{n}$ may have a jump at $t$, but its size\ntends to $0$ as $n \\to \\infty$). Indeed for every $\\varepsilon >0$ \n\\begin{equation*}\n\\P \\left( T_{n}\\leq t-\\varepsilon \\right) \\leq \\P \\left( T_{n}<t\\right)\n\\leq \\P \\left( T_{n}\\leq t+\\varepsilon \\right)\n\\end{equation*}%\nand $\\P \\left( T_{n}\\leq t-\\varepsilon \\right) \\rightarrow \\Phi\n(t-\\varepsilon )$, $\\P \\left( T_{n}\\leq t+\\varepsilon \\right) \\rightarrow\n\\Phi (t+\\varepsilon )$ and $\\left\\vert \\Phi (t+\\varepsilon )-\\Phi\n(t-\\varepsilon )\\right\\vert $ can be made arbitrarily small by a choice of $%\n\\varepsilon $. Hence (\\ref{variant-of-lawconverg}) is shown. Setting $%\nt=z_{\\alpha}$ and $t=-z_{\\alpha}$ we obtain \n\\begin{equation*}\n\\P \\left( T_{n}\\leq z_{\\alpha}\\right) -\\P \\left( T_{n}<-z_{\\alpha\n}^{\\ast }\\right) \\rightarrow \\P \\left( Z\\leq z_{\\alpha}\\right)\n-\\P \\left( Z\\leq -z_{\\alpha}\\right) =\\P \\left( -z_{\\alpha }^{\\ast\n}\\leq Z\\leq z_{\\alpha}\\right) .\n\\end{equation*}\n\\end{proof}\n\nWe may write the claim of the lemma as \n\\begin{eqnarray}\n&&\\P \\left( -z_{\\alpha}\\sqrt{\\theta^*(1-\\theta^*)}/\\sqrt{n}\\leq \\theta^*-\\widehat{\\Theta}%\n_{n}\\leq z_{\\alpha}\\sqrt{\\theta^*(1-\\theta^*)}/\\sqrt{n}\\right) \\\\\n&=&\\P \\left( \\widehat{\\Theta}_{n}-z_{\\alpha}\\sqrt{\\theta^*(1-\\theta^*)}/\\sqrt{n}\\leq\n\\theta^* \\leq \\widehat{\\Theta}_{n}+z_{\\alpha}\\sqrt{\\theta^*(1-\\theta^*)}/\\sqrt{n}\\right)\n\\rightarrow C  \\label{asympt-coverage}\n\\end{eqnarray}%\nand we are close to an approximate confidence interval for the unknown $\\theta^*$,\nexcept for the fact that $\\theta^*(1-\\theta^*)$ is unknown, hence the upper and lower\nbounds of the interval cannot be used. There are several methods to overcome\nthis difficulty as shown below.\n\n\n\\textbf{a). Standard Confidence Interval of asymptotic level $C$: } We can use $\\widehat{\\theta}_{n}$ as a point estimate for the unknown $\\theta^*$ in the\ninterval bounds, i.e. we set \n\\begin{equation*}\nm=z_{\\alpha}\\sqrt{\\frac{\\widehat{\\theta}_{n}(1-\\widehat{\\theta}_{n})}{n}}\n\\end{equation*}%\nuse the interval \n\\begin{equation}\n\\left[ \\widehat{\\theta}_{n}-m,\\widehat{\\theta}_{n}+m\\right]\n\\label{standard-one-proportion-interval}\n\\end{equation}%\nas an approximate confidence interval of level $C$. Indeed $\\widehat{\\theta}_{n}$ is\na reasonable estimate of $\\theta^*$ since $\\widehat{\\Theta}_{n}\\longrightarrow_{\\P } \\theta^*$ by the\nLLN and also $\\E\\widehat{\\Theta}_{n}=\\theta^*$ (i.e., $\\widehat{\\Theta}_{n}$ is an {\\em unbiased} estimator). But then we must\nestablish a convergence result as in (\\ref{asympt-coverage}), more precisely \n\\begin{eqnarray}\n&&\\P \\left( \\widehat{\\Theta}_{n}-m\\leq \\theta^* \\leq \\widehat{\\Theta}_{n}+m\\right)  \\notag \\\\\n&=&\\P \\left( -z_{\\alpha}\\leq \\frac{\\widehat{\\Theta}_{n}-\\theta^*}{\\sqrt{\\widehat{\\Theta}%\n_{n}(1-\\widehat{\\Theta}_{n})}/\\sqrt{n}}\\leq z_{\\alpha}\\right) \\rightarrow C.\n\\label{will-establish}\n\\end{eqnarray}%\nThat should be possible, given that \n\\begin{equation*}\n\\frac{\\widehat{\\Theta}_{n}-\\theta^*}{\\sqrt{\\widehat{\\Theta}_{n}(1-\\widehat{\\Theta}_{n})}/\\sqrt{n}}=T_{n}\\cdot \n\\sqrt{\\frac{\\theta^*(1-\\theta^*)}{\\widehat{\\Theta}_{n}(1-\\widehat{\\Theta}_{n})}}\n\\end{equation*}%\nand the fact that $\\widehat{\\Theta}_{n}\\longrightarrow_{\\P} \\theta^*,$ hence $\\theta^*/\\widehat{\\Theta}%\n_{n}\\longrightarrow_{\\P} 1$. Below we will establish (\\ref{will-establish}),\nshowing that the interval (\\ref{standard-one-proportion-interval}) is an\napproximate confidence interval of level $C$ for $\\theta^*$. A common synonym for\n``approximate as $n\\rightarrow \\infty $\" is ``asymptotic\"; the interval (\\ref%\n{standard-one-proportion-interval}) is in fact the \\textbf{standard\nconfidence interval of asymptotic level }$C$ for the population proportion.\nThe bound $m$ in the interval $\\left[ \\widehat{\\Theta}_{n}-m,\\widehat{\\Theta}_{n}+m\\right] $\nis called the \\textit{margin of error}; the width of the interval is $2m$.\n\n\\bigskip\n\n\\textbf{b) Conservative confidence interval of asymptotic level $C$: }. We use the inequality \n\\begin{equation*}\n\\theta^*(1-\\theta^*)\\leq \\frac{1}{4}\n\\end{equation*}%\n\\textbf{(Exercise !)} to replace $\\sqrt{\\theta^*(1-\\theta^*)}$ by $1/2$ in (\\ref%\n{asympt-coverage}) and thus we work with a wider interval around $\\widehat{\\theta}%\n_{n} $ which increases coverage probability of $\\theta^*$, and thus should also\nhave asymptotic coverage probability \\textit{at least} $C$. In more detail:\nset $m=z_{\\alpha}/2\\sqrt{n}$; since $\\sqrt{\\theta^*(1-\\theta^*)} \\leq 1/2,$ we\nhave $z_{\\alpha}\\sqrt{\\theta^*(1-\\theta^*)}/\\sqrt{n}\\leq m$ and hence \n\\begin{eqnarray*}\n&&\\P \\left( \\widehat{\\Theta}_{n}-m\\leq \\theta^* \\leq \\widehat{\\Theta}_{n}+m\\right) \\\\\n&\\geq &\\P \\left( \\widehat{\\Theta}_{n}-z_{\\alpha}\\sqrt{\\theta^*(1-\\theta^*)}/\\sqrt{n}\\leq\n\\theta^* \\leq \\widehat{\\Theta}_{n}+z_{\\alpha}\\sqrt{\\theta^*(1-\\theta^*)}/\\sqrt{n}\\right)\n\\rightarrow C.\n\\end{eqnarray*}%\nhence \n\\begin{equation}\n\\liminf_{n\\rightarrow \\infty }\\P \\left( \\widehat{\\Theta}_{n}-z_{\\alpha}%\n\\frac{1}{2\\sqrt{n}}\\leq \\theta^* \\leq \\widehat{\\Theta}_{n}+z_{\\alpha}\\frac{1}{2\\sqrt{%\nn}}\\right) \\geq C.  \\label{asy-level-conservat-CI}\n\\end{equation}%\nSo there is also an asymptotic coverage probability of at least $C$. This\nmethod is known as the \\textbf{conservative method} for an asymptotic\nconfidence interval of level $C$. The conservative margin of error is $%\nm=z_{\\alpha}/2\\sqrt{n}$.\n\n\\bigskip\n\n\\textbf{c) Exact Chebyshev's confidence interval with coverage probability at least $C$: } We use \\textit{Chebyshev's inequality} applied to the sample\nproportion (with $\\V(\\widehat{\\Theta}_{n})=\\theta^*(1-\\theta^*)/n$) \n\\begin{equation*}\n\\P \\left( \\left\\vert \\widehat{\\Theta}_{n}-\\theta^*\\right\\vert \\geq m\\right) \\leq \\frac{%\n\\theta^*(1-\\theta^*)}{nm^{2}}\\leq \\frac{1}{4nm^{2}}\\enspace ,\n\\end{equation*}%\nset $C=1-1/4nm^{2}$ and solve for $m$, which gives $m=\\sqrt{\\frac{1}{%\n4n(1-C)}}$ and for the interval $\\left[ \\widehat{\\theta}_{n}-m,\\widehat{\\theta}_{n}+m\\right] $\na confidence statement \n\\begin{equation*}\n\\P \\left( \\left[ \\widehat{\\Theta}_{n}-m,\\widehat{\\Theta}_{n}+m\\right] \\ni \\theta^* \\right) \\geq C.\n\\end{equation*}%\nThis interval has nonasymptotic (or \\textit{exact}) coverage probability at\nleast $C$, and in that sense it is preferable to an asymptotic confidence\ninterval. But the margin of error is larger: if we compare it with the\nconservative (asymptotic) margin of error $z_{\\alpha}\\frac{1}{2%\n\\sqrt{n}}$, we notice that both are of order $1/\\sqrt{n}$, but their ratio \n\\begin{equation}\n\\frac{\\sqrt{\\frac{1}{4n(1-C)}}}{z_{\\alpha}\\frac{1}{2\\sqrt{n}}}=%\n\\frac{1/\\sqrt{1-C}}{z_{\\alpha}}=\\frac{1/\\sqrt{2\\alpha }}{z_{\\alpha}}  \\label{ratio}\n\\end{equation}%\nis large. This is clear from the fact that the numerator is the solution of $%\n1/2x^{2}=\\alpha $ and the denominator is the solution of $\\P (Z>x)=\\alpha $%\n, and from what we discussed above about the normal tail. From the table it\ncan be seen that for $C=0.95$ we have $z_{\\alpha}=1.96$; then the\nabove ratio is $2.28$ and for $C=0.99$ the ratio $3.88.$\\bigskip\n\n\\begin{Exercise}\nUse Mill's inequality to formally show that (\\ref{ratio})\ntends to infinity as $\\alpha \\rightarrow 0$ (i.e. as $C\\rightarrow 1$) .\n\\end{Exercise}\n\n\\begin{Exercise}[label={ExmaxOfBernoulliVarianceIsQuarter}] \nShow that for any $\\theta$ with $0<\\theta<1$ \n\\begin{equation*}\n\\theta(1-\\theta)\\leq \\frac{1}{4}.\n\\end{equation*}%\n\\textit{Remark:} this inequality was used to derive the conservative method\nof building a confidence interval for the population proportion.\n\\end{Exercise}\n\\begin{Answer}\nHINT: Take the first derivative of $\\theta(1-\\theta)$ with respect to $\\theta$, set it equal to $0$ and solve for $\\theta$.\nThis solution will give the point at which $\\theta(1-\\theta)$ has zero slope. \nNow, find the second derivative of $\\theta(1-\\theta)$ with respect to $\\theta$, and evaluate it at the solution to see if the maximum is achieved with a negative second derivative.\n\\end{Answer}\n\n\\textbf{d) Exact Hoeffding's confidence interval with coverage probability at least $C$: } \nFor the sample proportion there is a much better inequality available than that of Chebyshev: Hoeffding's inequality of \\eqref{EqHoeffdingsInequality} in Proposition~\\ref{P:HoeffdingsInequality}, \napplied to the the sample proportion $\\widehat{\\Theta}_{n}$ gives for any $%\nm>0 $ \n\\begin{equation}\\label{EqExactHoeffdingsConfInterForProportion}\n\\P \\left( \\left\\vert \\widehat{\\Theta}_{n}-\\theta^*\\right\\vert \\geq m\\right) \\leq 2\\exp\n\\left( -2nm^{2}\\right)\n\\end{equation}%\nso that if we desire a confidence interval with level $C$, we set \n\\begin{equation*}\nC=1-2\\exp \\left( -2nm^{2}\\right)\n\\end{equation*}\nand solve for $m$, which gives \n\\begin{equation*}\nm=\\sqrt{\\frac{-\\log \\left( (1-C)/2 \\right)}{2n}}=\\sqrt{\\frac{\\log (1/\\alpha )}{%\n2n}}.\n\\end{equation*}%\nThis interval is also nonasymptotic (i.e. has exact coverage probability $C$\nfor any $n$) and is narrower than the one derived from the Chebyshev\ninequality. Nevertheless the interval derived from the normal tail, which is\nnot exact but asymptotic, is more commonly used.\n\nNext we prove Hoeffding's inequality using the following simple idea of Chernoff.\n\n\\begin{idea}[Chernoff's bounding method]\nBy Markov's inequality, if $s$ is an arbitrary positive real number, then for any RV $X$, and any $t>0$:\n\\[\n\\P(X \\geq t) = \\P (\\e^{sX} \\geq \\e^{st}) \\leq \\frac{\\E(\\e^{sX})}{\\e^{st}}\n\\]\nThe idea in Chernoff's bounding method is to find $s>0$ that minimises the upper-bound, i.e., the RHS of the above equation, to make it as small as possible. In the case of a sum of independent RVs $X_1,X_2,\\ldots,X_n$ given by $S_n = \\sum_{i=1}^n X_i$:\n\\begin{align}\n\\P(S_n - \\E(S_n) \\geq t) \n&\\leq \\e^{-st} \\E \\left( \\exp \\left( s \\sum_{i=1}^n (X_i - \\E(X_i)) \\right)\\right) \\notag \\\\\n&= \\e^{-st} \\prod_{i=1}^n \\E\\left( \\e^{s(X_i-\\E(X_i))}\\right), \\quad \\text{by independence.} \\label{EqChernoffsBoundingMethod}\n\\end{align}\nThus, the problem of finding better bounds than that given by Chebychev's inequality boils down to finding a good upper-bound for $\\E\\left( \\e^{s(X_i-\\E(X_i))}\\right)$, i.e., \nthe moment generating function of each of the random variables $X_i-\\E(X_i)$. There are many ways to do this and the most simple approach is due to Hoeffding in 1963 as shown next.\n\\end{idea}\n\n\\begin{prop}[Hoeffding's $\\neq$]\\label{P:HoeffdingsInequality}\nLet $X_1,X_2,\\ldots,X_n$ be independent bounded RVs such that $\\P(Z_i \\in [a_i,b_i])=1$ for each $i \\in \\{1,2,\\ldots,n\\}$. Let $S_n = \\sum_{i=1}^n X_i$. Then for any $t>0$, we have\n\\begin{equation}\\label{EqHoeffdingsInequality}\n\\P (\\vert S_n - \\E(S_n) \\vert \\geq t) \\leq 2 \\exp \\left(-\\frac{2t^2}{\\sum_{i=1}^n (b_i-a_i)^2}\\right)\n\\end{equation}\n\\end{prop}\n\n\\begin{proof}\nThe core of proving Hoeffding's inequality is the following upper bound: if $X$ is a RV with $\\E(X)=0$ and $a \\leq X \\leq b$, then\n\\[\n\\E \\left( \\e^{sX}\\right) \\leq \\e^{(s^2(b-a)^2/8)}\n\\] \nThe above upper-bound is derived from the convexity of the exponential function:\n\\[\n\\e^{sx} \\leq \\frac{x-a}{b-a}\\e^{sb} + \\frac{b-x}{b-a}\\e^{sa}, \\text{ for } a \\leq x \\leq b\n\\]\n\n{\\scriptsize Draw $\\e^{sx}$ on y-axis as a function of $x$ along x-axis and the line from $\\e^{sa}$ to $\\e^{sb}$ for the upper-bound as $x$ goes from $a$ to $b$.}\n\n\\vspace{4cm}\n\nThus, taking expectations on both sides of the above inequality\n\\begin{align*}\n\\E \\left( \\e^{sX}\\right) \n&\\leq\n\\E\\left( \\frac{X-a}{b-a}\\right) \\e^{sb} +   \\E \\left( \\frac{b-X}{b-a} \\e^{sa} \\right)\\\\\n&= \\frac{b}{b-a} \\e^{sa} - \\frac{a}{b-a} \\e^{sb}, \\quad \\text{ because } \\E(X)=0\\\\\n&= \\left( 1 - c + c \\e^{s(b-a)} \\right) \\e^{-c s(b-a)}, \\text{ where, } c=\\frac{-a}{b-a}\\enspace.\n\\end{align*}\nNow let\n\\[\nu=s(b-a) \\quad \\text{ and define } \\phi(u) := -c u + \\log(1-c+c\\e^u)\n\\]\nThen we have\n\\[\n\\E \\left( \\e^{sX} \\right) \\leq \\left( 1-c+c\\e^{s(b-a)}\\right) \\e^{- c s (b-a)} = \\e^{\\phi(u)}\n\\]\nTo minimise the upper-bound let's express $\\phi(u)$ in a Taylor's series with remainder term:\n\\[\n\\phi(u) = \\phi(0) + u \\phi'(0) + \\frac{u^2}{2} \\phi^{\\prime\\prime}(v) \\quad \\text{for some } v \\in [0,u]\n\\]\n\\begin{align*}\n\\phi(0)\n&= -c \\cdot 0 + \\log(1-c+c \\e^0) = 0 \\\\\n\\phi'(u)\n&= -c + \\frac{c \\e^u}{1-c+c\\e^u} \\quad \\implies \\quad \\phi'(u)=0 \\\\\n\\phi^{\\prime \\prime}\n&= \\frac{c \\e^u}{1-c+c\\e^u} - \\frac{c\\e^u}{(1-c+c\\e^u)^2}\\\\\n&= \\frac{c \\e^u}{1-c+c\\e^u} \\left(1 - \\frac{c\\e^u}{(1-c+c\\e^u)} \\right)\\\\\n&= \\rho(1-\\rho), \\quad \\text{ where, } \\rho := \\frac{c\\e^u}{(1-c+c\\e^u)}  \n\\end{align*}\nNow, $\\phi^{\\prime\\prime}=\\rho(1-\\rho)$, being the familiar quadratic, is maximised by setting\n\\[\n\\rho = \\frac{c\\e^u}{(1-c+c\\e^u)} = \\frac{1}{2} \\implies \\phi^{\\prime\\prime} \\leq \\frac{1}{4} \\enspace .\n\\]\nThus we get\n\\[\n\\phi(u) \\leq \\frac{u^2}{8} = \\frac{s^2(b-a)^2}{8} \\quad \\implies \\quad \\E(\\e^{sX}) \\leq \\e^{s^2(b-a)^2/8} \\enspace .\n\\]\nNow, we can just plug-in the above upper-bound $\\e^{s^2(b-a)^2/8}$, specialised to each $X_i$ that is bounded between $a_i$ and $b_i$, directly into \\eqref{EqChernoffsBoundingMethod} of Chernoff's bounding method \nto derive Hoeffding's inequality:\n\\begin{align*}\n\\P \\left( (S_n - \\E(S_n)) \\geq t \\right) \n&\\leq \\e^{-st} \\prod_{i=1}^n \\e^{s^2(b_i-a_i)^2/8} \\\\\n%=& \\e^{-st} \\e^{s^2 \\sum_{i=1}^n (b_i-a_i)^2/8} \\\\\n%=& \\e^{-2t^2/\\sum_{i=1}^n (b_i-a_i)^2}, \\qquad \\text{by choosing the optimal } s=4t/\\sum_{i=1}^n(b_i-a_i)^2\n\\end{align*}\nSimilarly, we can also show that\n\\[\n\\P \\left( (\\E(S_n) - S_n) \\geq t \\right) \\leq \\e^{-2t^2/\\sum_{i=1}^n (b_i-a_i)^2}\n\\]\nThus we have proved the inequality for the absolute value of $S_n - \\E(S_n)$ in \\eqref{EqHoeffdingsInequality} known as Hoeffding's inequality. \n\\end{proof}\n\nNext we prove \\eqref{EqExactHoeffdingsConfInterForProportion} by specialising \\eqref{EqHoeffdingsInequality} to the $\\binomial(n,\\theta^*)$ RV $S_n=\\sum_{i=1}^nX_i$, where $X_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} \\bernoulli(\\theta^*)$, in terms of the sample mean as the point estimator $\\widehat{\\Theta}_n = \\overline{X}_n = S_n/n$, as originally proved by Chernoff (1952) and Okamoto (1958):\n\\begin{align}\n\\P \\left( \\vert \\overline{\\Theta}_n - \\theta^* \\vert \\geq m \\right) \n&= \\P \\left( \\frac{1}{n} \\vert S_n - \\E(S_n) \\vert \\geq m \\right) %\\notag \\\\\n= \\P \\left( \\vert S_n - \\E(S_n) \\vert \\geq n m \\right) \\notag \\\\\n&\\leq 2 \\e^{-2(n m)^2/\\sum_{i=1}^n (b_i-a_i)^2} \\notag\\\\\n&= 2 \\e^{-2(n m)^2/\\sum_{i=1}^n (1-0)^2} \\quad \\text{since for each $\\bernoulli(\\theta)$ RV } b_i=1, a_i=0 \\notag\\\\\n&= 2 \\e^{-2(n m)^2/n} = 2 \\e^{-2 n m^2} \\notag \n\\end{align}\n\n\\begin{Exercise}[label={ExExactConfIntervalsFor25BernoulliTrials}]\nSuppose you toss a possibly biased coin 25 times and observe 18 heads. Assuming IID $\\bernoulli(\\theta^*)$ trials where $\\theta^*$ is the probability of coming up heads, obtain exact confidence intervals for the unknown $\\theta^*$ with confidence level $C$ of at least $95\\%$ using exact sample size via: (a) Chebyshev's inequality and (b) Hoeffding's inequality.\n\\end{Exercise}\n\n\\subsubsection{Some technical convergence results}\n\nIn order to establish the result for the asymptotic coverage probability of\nthe standard confidence interval for $\\theta^*$ (i. e. in order to show (\\ref%\n{will-establish})) some results about convergence in law and in probability\nare needed. Recall that a continuous random variable is one with a\ncontinuous distribution function $\\P \\left( X\\leq t\\right) $. The claim\nthat a RV $X$ has a continuous distribution (or law) means that $X$ has a\ncontinuous distribution function $\\P \\left( X\\leq t\\right) $.\n\n\\begin{lemma}\n\\label{lem-lawconv-1a}Suppose $X_{n}$ is a sequence of RV which converges\nin distribution to a continuous RV $X$: \n\\begin{equation*}\nX_{n}\\rightsquigarrow X\n\\end{equation*}%\nand let $Y_{n}$ be a sequence of RV which converges in probability to $0$: \n\\begin{equation*}\nY_{n}\\rightarrow _{\\P }0.\n\\end{equation*}%\nThen \n\\begin{equation*}\nX_{n}+Y_{n}\\rightsquigarrow X.\n\\end{equation*}\n\\end{lemma}\n\nNote that no independence assumptions were made.\n\n\\begin{proof}\nLet $F_{n}$ be the distribution function of $X_{n}$ and $F$ be the\nrespective d.f. of $X$. Convergence in distribution means that \n\\begin{equation*}\n\\P (X_{n}\\leq t)=F_{n}(t)\\rightarrow F(t)\n\\end{equation*}%\nfor every continuity point of the limit d.f. $F.$ We assumed that $F$ is\ncontinuous, so it means convergence for every $t$. Now for $\\varepsilon >0$%\n\\begin{equation*}\n\\P (X_{n}+Y_{n}\\leq t)=\n\\end{equation*}%\n\\begin{equation}\n=\\P (\\left\\{ X_{n}+Y_{n}\\leq t\\right\\} \\cap \\left\\{ \\left\\vert\nY_{n}\\right\\vert \\leq \\varepsilon \\right\\} )+\\P (\\left\\{ X_{n}+Y_{n}\\leq\nt\\right\\} \\cap \\left\\{ \\left\\vert Y_{n}\\right\\vert >\\varepsilon \\right\\} ).\n\\label{split-up}\n\\end{equation}%\nThe first term on the right is \n\\begin{eqnarray*}\n\\P (\\left\\{ X_{n}\\leq t-Y_{n}\\right\\} \\cap \\left\\{ \\left\\vert\nY_{n}\\right\\vert \\leq \\varepsilon \\right\\} ) &\\leq &\\P (\\left\\{ X_{n}\\leq\nt+\\varepsilon \\right\\} \\cap \\left\\{ \\left\\vert Y_{n}\\right\\vert \\leq\n\\varepsilon \\right\\} ) \\\\\n&\\leq &\\P (X_{n}\\leq t+\\varepsilon ).\n\\end{eqnarray*}%\nFor this upper bound we have%\n\\begin{equation*}\n\\P (X_{n}\\leq t+\\varepsilon )\\rightarrow F(t+\\varepsilon )\\text{ as }%\nn\\rightarrow \\infty .\n\\end{equation*}%\nThe second term in (\\ref{split-up}) is \n\\begin{equation*}\n\\P (\\left\\{ X_{n}+Y_{n}\\leq t\\right\\} \\cap \\left\\{ \\left\\vert\nY_{n}\\right\\vert >\\varepsilon \\right\\} )\\leq \\P (\\left\\vert\nY_{n}\\right\\vert >\\varepsilon )\\rightarrow 0\\text{ as }n\\rightarrow \\infty .\n\\end{equation*}%\nHence for every $\\delta >0$ we can find $m_{1}$ such that for all $n\\geq\nm_{1}$ \n\\begin{equation}\n\\P (X_{n}+Y_{n}\\leq t)\\leq F(t+\\varepsilon )+2\\delta .  \\label{bracket-1a}\n\\end{equation}%\nNow take the same $\\varepsilon >0$; we have \n\\begin{equation*}\nP(X_{n}\\leq t-\\varepsilon )=\n\\end{equation*}%\n\\begin{eqnarray*}\n&&\\P (\\left\\{ X_{n}\\leq t-\\varepsilon \\right\\} \\cap \\left\\{ \\left\\vert\nY_{n}\\right\\vert \\leq \\varepsilon \\right\\} )+\\P (\\left\\{ X_{n}\\leq\nt-\\varepsilon \\right\\} \\cap \\left\\{ \\left\\vert Y_{n}\\right\\vert >\\varepsilon\n\\right\\} ) \\\\\n&\\leq &\\P (\\left\\{ X_{n}+Y_{n}\\leq t\\right\\} \\cap \\left\\{ \\left\\vert\nY_{n}\\right\\vert \\leq \\varepsilon \\right\\} )+\\P (\\left\\vert\nY_{n}\\right\\vert >\\varepsilon ) \\\\\n&\\leq &\\P (X_{n}+Y_{n}\\leq t)+P(\\left\\vert Y_{n}\\right\\vert >\\varepsilon ).\n\\end{eqnarray*}%\nConsequently \n\\begin{equation*}\n\\P (X_{n}+Y_{n}\\leq t)\\geq \\P (X_{n}\\leq t-\\varepsilon )-\\P (\\left\\vert\nY_{n}\\right\\vert >\\varepsilon ).\n\\end{equation*}%\nUsing again the two limits for the probabilities on the right, for every $%\n\\delta >0$ we can find $m_{2}$ such that for all $n\\geq m_{2}$ \n\\begin{equation}\n\\P (X_{n}+Y_{n}\\leq t)\\geq F(t-\\varepsilon )-2\\delta .  \\label{bracket-2a}\n\\end{equation}%\nTaking $m=\\max (m_{1},m_{2})$ and collecting (\\ref{bracket-1a}), (\\ref%\n{bracket-2a}), we obtain for $n\\geq m$ \n\\begin{equation*}\nF(t-\\varepsilon )-2\\delta \\leq P(X_{n}+Y_{n}\\leq t)\\leq F(t+\\varepsilon\n)+2\\delta .\n\\end{equation*}%\nSince $F$ is continuous at $t$, and $\\varepsilon $ was arbitrary, we can\nselect $\\varepsilon $ such that \n\\begin{eqnarray*}\nF(t+\\varepsilon ) &\\leq &F(t)+\\delta , \\\\\nF(t-\\varepsilon ) &\\geq &F(t)-\\delta\n\\end{eqnarray*}%\nso that for $n$ large enough \n\\begin{equation*}\nF(t)-3\\delta \\leq \\P (X_{n}+Y_{n}\\leq t)\\leq F(t)+3\\delta\n\\end{equation*}%\nand since $\\delta $ was also arbitrary, the result follows.\n\\end{proof}\n\n\\begin{lemma}\n\\label{lem-lawconv-2a}Under the assumptions of Lemma \\ref{lem-lawconv-1a},\nwe have \n\\begin{equation*}\nX_{n}Y_{n}\\rightarrow _{\\P }0.\n\\end{equation*}\n\\end{lemma}\n\n\\begin{proof}\nLet $\\varepsilon >0$; and $\\delta >0$ be arbitrary and given. Suppose $%\n\\left\\vert X_{n}Y_{n}\\right\\vert \\geq \\varepsilon $. Then, for every $t>0$,\neither $\\left\\{ \\left\\vert X_{n}\\right\\vert >t\\right\\} $, or if that is not\nthe case, then$\\left\\vert X_{n}Y_{n}\\right\\vert \\leq t\\left\\vert\nY_{n}\\right\\vert $ and hence $\\left\\vert Y_{n}\\right\\vert \\geq \\varepsilon\n/t $. Hence . \n\\begin{equation}\n\\P \\left( \\left\\vert X_{n}Y_{n}\\right\\vert \\geq \\varepsilon \\right) \\leq\n\\P \\left( \\left\\vert X_{n}\\right\\vert >t\\right) +\\P \\left( \\left\\vert\nY_{n}\\right\\vert \\geq \\varepsilon /t\\right) .  \\label{first-decompos-a}\n\\end{equation}%\nLet again $F_{n}$ be the distribution function of $X_{n}$ and $F$ be the\nrespective d.f. of $X$. Now for every $t>0$ \n\\begin{eqnarray*}\n\\P \\left( \\left\\vert X_{n}\\right\\vert >t\\right) &=&1-\\P \\left( X_{n}\\leq\nt\\right) +\\P \\left( X_{n}<-t\\right) \\\\\n&\\leq &1-F_{n}\\left( t\\right) +F_{n}\\left( -t\\right) .\n\\end{eqnarray*}%\nSince $F_{n}$ converges to $F_{0}$ at both points $t$, $-t$, we find $%\nm_{1}=m_{1}(t)$ (depending on $t$) such that for all $n\\geq m_{1}$ \n\\begin{equation*}\n\\P \\left( \\left\\vert X_{n}\\right\\vert >t\\right) \\leq\n1-F_{0}(t)+F_{0}(-t)+\\delta\n\\end{equation*}%\nSelect now $t$ large enough such that \n\\begin{equation*}\n1-F_{0}(t)\\leq \\delta \\text{, }F_{0}(-t)\\leq \\delta .\n\\end{equation*}%\nThen for all $n\\geq m_{1}(t)$ \n\\begin{equation*}\n\\P \\left( \\left\\vert X_{n}\\right\\vert \\geq t\\right) \\leq 3\\delta .\n\\end{equation*}%\nOn the other hand, once $t$ is fixed, in view of convergence in probability\nto $0$ of $\\left\\vert Y_{n}\\right\\vert $, one can find $m_{2}$ such that for\nall $n\\geq m_{2}$ \n\\begin{equation*}\n\\P \\left( \\left\\vert Y_{n}\\right\\vert \\geq \\varepsilon /t\\right) \\leq\n\\delta .\n\\end{equation*}%\nIn view of (\\ref{first-decompos-a}) we have for all $n\\geq m=\\max\n(m_{1},m_{2})$%\n\\begin{equation*}\n\\P \\left( \\left\\vert X_{n}Y_{n}\\right\\vert \\geq \\varepsilon \\right) \\leq\n4\\delta .\n\\end{equation*}%\nSince $\\delta >0$ was arbitrary, the result is proved.\n\\end{proof}\n\nWe need an auxiliary result which despite its simplicity is still frequently\ncited as a ``Theorem\".\n\n\\begin{prop}\n\\label{theo-slutsky}(\\textbf{Slutsky's theorem}). Suppose a sequence of\nrandom variables $X_{n}$ converges in probability to a value $x$ ($%\nX_{n}\\rightarrow _{\\P }x$ as $n\\rightarrow \\infty $). Suppose $f$ is a real\nvalued function defined in a neighborhood of $x$ and continuous there. Then \n\\begin{equation*}\nf(X_{n})\\rightarrow _{\\P }f(x),\\;n\\rightarrow \\infty .\n\\end{equation*}\n\\end{prop}\n\n\\begin{proof}\nConsider an arbitrary $\\varepsilon >0$. Select $\\delta >0$ small enough such\nthat $(x-\\delta ,x+\\delta )$ is contained in the neighborhood of $x$ where $%\nf $ is defined and also fulfilling the condition that $\\left\\vert\nt-x\\right\\vert \\leq \\delta $ implies $\\left\\vert f(t)-f(x)\\right\\vert \\leq\n\\varepsilon $ (by continuity of $f$ such a $\\delta $ can be found). Then the\nevent $\\left\\vert f(X_{n})-f(x)\\right\\vert >\\varepsilon $ implies $%\n\\left\\vert X_{n}-x\\right\\vert >\\delta $ and hence \n\\begin{equation*}\nP\\left( \\left\\vert f(X_{n})-f(x)\\right\\vert >\\varepsilon \\right) \\leq\nP\\left( \\left\\vert X_{n}-x\\right\\vert >\\delta \\right) .\n\\end{equation*}%\nSince the latter probability tends to $0$ as $\\;n\\rightarrow \\infty $, we\nalso have \n\\begin{equation*}\nP\\left( \\left\\vert f(X_{n})-f(x_{0})\\right\\vert >\\varepsilon \\right)\n\\rightarrow 0\\text{ as }n\\rightarrow \\infty\n\\end{equation*}%\nand since $\\varepsilon $ was arbitrary, the result is proved.\\bigskip\n\\end{proof}\n\n\n\\subsubsection{Asymptotic confidence level}\\label{S:AsympConfLevel}\n\nWith these results we are now able to prove that the standard asymptotic confidence\ninterval for the unknown population proportion $\\theta^*$ has indeed asymptotic level $C$, i.e.\nprove relation (\\ref{will-establish}): \n\\begin{equation}\n\\P \\left( -z_{\\alpha}\\leq \\frac{\\widehat{\\Theta}_{n}-\\theta^*}{\\sqrt{\\widehat{\\Theta}_{n}(1-%\n\\widehat{\\Theta}_{n})}/\\sqrt{n}}\\leq z_{\\alpha}\\right) \\rightarrow C\n\\label{asy-level-a}\n\\end{equation}%\nfor $\\alpha =\\left( 1-C\\right) /2$. As already noted we have \n\\begin{equation}\n\\frac{\\widehat{\\Theta}_{n}-\\theta^*}{\\sqrt{\\widehat{\\Theta}_{n}(1-\\widehat{\\Theta}_{n})}/\\sqrt{n}}=T_{n}\\cdot \n\\sqrt{\\frac{\\theta^*(1-\\theta^*)}{\\widehat{\\Theta}_{n}(1-\\widehat{\\Theta}_{n})}}  \\label{factor-T-n}\n\\end{equation}%\nwhere $T_{n}\\rightsquigarrow Z$, and $T_{n}$ is the \"correctly standardized\"\nsample proportion $\\widehat{\\Theta}_{n}$ (as in (\\ref{sample-prop-limitlaw})). The\nfunction $f(\\theta^*):=\\theta^*(1-\\theta^*)$ is continuous in a neighborhood of every $\\theta^* \\in (0,1)$; by\nSlutsky's theorem we have $\\widehat{\\Theta}_{n}(1-\\widehat{\\Theta}_{n})\\rightarrow _{\\P\n}\\theta^*(1-\\theta^*)$. A repeated application of Slutsky's theorem now gives \n\\begin{equation*}\n\\frac{\\theta^*(1-\\theta^*)}{\\widehat{\\Theta}_{n}(1-\\widehat{\\Theta}_{n})}\\rightarrow _{\\P }1\\text{, }\\sqrt{%\n\\frac{\\theta^*(1-\\theta^*)}{\\widehat{\\Theta}_{n}(1-\\widehat{\\Theta}_{n})}}\\rightarrow _{\\P }1.\n\\end{equation*}%\nAn application of Lemma (\\ref{lem-lawconv-2a}) to (\\ref{factor-T-n}) gives \n\\begin{equation*}\n\\widehat{T}_{n}:=\\frac{\\widehat{\\Theta}_{n}-\\theta^*}{\\sqrt{\\widehat{\\Theta}_{n}(1-\\widehat{\\Theta}_{n})}/\\sqrt{n}}%\n\\rightsquigarrow Z.\n\\end{equation*}%\nAnalogously to Lemma (\\ref{lem-lawconv-interval}) (replace $T_{n}$ there by $%\n\\widehat{T}_{n}$) it now follows that \n\\begin{equation*}\n\\P \\left( -z_{\\alpha}\\leq \\widehat{T}_{n}\\leq z_{\\alpha }^{\\ast\n}\\right) \\rightarrow \\P \\left( -z_{\\alpha}\\leq Z\\leq z_{\\alpha\n}^{\\ast }\\right) =C\\text{ }\n\\end{equation*}%\ni.e. (\\ref{asy-level-a}) is established and thereby proving the following proposition.\n\n\\begin{prop}\n\\label{prop-asy-confid-level-two-sided}Suppose \n$X_{1},\\ldots ,X_{n}$ are independent Bernoulli observations with $X_{i}\\sim \\bernoulli(\\theta^*)$.  \nSuppose $\\theta^*\\in (0,1)$ is unknown and we want to find out its value. \nLet the point estimator $\\widehat{\\Theta}_{n}$ of $\\theta^*$ be the sample proportion and let $%\nz_{\\alpha}$ be the upper $\\alpha $-quantile of $Z$ for some $%\n0<\\alpha <1/2$. Then \n\\begin{equation*}\n \\left[ \\widehat{\\Theta}_{n}-m,\\widehat{\\Theta}_{n}+m\\right] \\quad \\text{where,} \\quad m=z_{\\alpha}\\sqrt{\\frac{\\widehat{\\Theta}_{n}(1-\\widehat{\\Theta}_{n})}{n}}\n\\end{equation*}%\nis a confidence interval for $\\theta^*$ of asymptotic level $C=1-2\\alpha $.\n\\end{prop}\n\n\\begin{Exercise}[label={ExAsymptoticConfIntervalsFor125BernoulliTrials}]\nSuppose you toss a possibly biased coin 125 times and observe 118 heads. Assuming IID $\\bernoulli(\\theta^*)$ trials where $\\theta^*$ is the probability of coming up heads, obtain a confidence interval based on the CLT with asymptotic level $95\\%$ for the unknown $\\theta^*$.\n\\end{Exercise}\n\n\n\\subsubsection{Sample size determination}\\label{S:SampleSizeDetermination}\n\nThe standard confidence interval has width $2m$, where the margin of error\nis \n\\begin{equation}\nm=z_{\\alpha}\\sqrt{\\frac{\\widehat{\\Theta}_{n}(1-\\widehat{\\Theta}_{n})}{n}}\n\\label{standard-margin-a}\n\\end{equation}\nThere are two conflicting aims:\n\n\\begin{itemize}\n\\item[{\\bf Aim of precision:}] The width should be as small as possible, in order to accurately ``pinpoint\" the unknown value $\\theta^*$.\n\n\\item[{\\bf Aim of certainty:}] The confidence level $C$ should be as high as possible, i.e., close to one, since it can be interpreted as the ``reliability\" of the interval.\n\\end{itemize}\n\nThe conflict clearly appears with the quantile $z_{\\alpha}$: if $%\nC\\rightarrow 1$ then $\\alpha =\\left( 1-C\\right) /2\\rightarrow 0$ and hence $%\nz_{\\alpha}\\rightarrow \\infty $, and as a consequence the margin of\nerror $m$ also tends to infinity. For small margin of error at fixed sample\nsize $n$ we would have to decrease $z_{\\alpha}$, thus increase $%\n\\alpha $ and decrease $C$. However the sample size $n$ also influences the\nmargin of error $m$; in fact $m$ is proportional to $1/\\sqrt{n}$. Thus both\nhigh $C$ and small $m$ \\textit{can easily be achieved if we let }$%\nn\\rightarrow \\infty $, but sample size usually is a cost factor.\n\nIf we use the conservative margin of error \n\\begin{equation}\nm=z_{\\alpha}\\sqrt{\\frac{1}{4n}}  \\label{conserv-margin}\n\\end{equation}%\nthen it is easy to determine a sample size that a given margin of error $%\nm^{\\ast }$ is guaranteed: \n\\begin{equation}\nn=\\left( \\frac{z_{\\alpha}}{2m^{\\ast }}\\right) ^{2}\n\\label{sample-size-determin-1}\n\\end{equation}%\nis obtained by solving (\\ref{conserv-margin}) for $n$.\n\nIf we prefer the standard interval, and try to determine $n$ for achieving a\ngiven margin of error, we are faced with the problem that $\\widehat{\\Theta}_{n}$ is\nnot available before we have obtained the sample of that size. Indeed\nsetting $m=m^{\\ast }$ in (\\ref{standard-margin-a}) and solving for $n$ gives \n\\begin{equation*}\nn=\\widehat{\\Theta}_{n}(1-\\widehat{\\Theta}_{n})\\left( \\frac{z_{\\alpha}}{m^{\\ast }}%\n\\right) ^{2}.\n\\end{equation*}\n\nAn obvious idea is to use an initial guess of $\\theta^*$, or conduct a pilot study\nwith sample size $n_{1}$ and obtain an initial estimate $\\widehat{\\Theta}_{(1)}$ from\nthere. Then determine the final sample size from \n\\begin{equation*}\n\\widehat{n}=\\widehat{\\Theta}_{(1)}(1-\\widehat{\\Theta}_{(1)})\\left( \\frac{z_{\\alpha}}{%\nm^{\\ast }}\\right) ^{2}\n\\end{equation*}\n\n\\begin{algorithm}[htbp]\n\\label{algo-2-stage}\\textbf{Two stage method }\\\\To achieve a given margin\nof error\\textit{\\ }$m^{\\ast }$ (for fixed confidence level C)\\textit{: }%\n\\bigskip \\newline\n\\textbf{(1)} Sample $n_{1}$ data $Y_{1},\\ldots ,Y_{n_{1}}$ (all IID\nBernoulli $\\bernoulli(\\theta^*)$), obtain the corresponding sample proportion $%\n\\widehat{\\Theta}_{(1)}$ and use it to determine an estimated sample size $\\widehat{n}$ by \n\\begin{equation*}\n\\widehat{n}=\\widehat{\\Theta}_{(1)}(1-\\widehat{\\Theta}_{(1)})\\left( \\frac{z_{\\alpha}}{%\nm^{\\ast }}\\right) ^{2}.\n\\end{equation*}%\n\\bigskip \\textbf{(2) }Take another sample $X_{1},\\ldots ,X_{\\widehat{n}}$ (all\nIID Bernoulli $\\bernoulli(\\theta^*)$), independent of the first one, of size $%\n\\widehat{n}$, obtain the sample proportion $\\widehat{\\Theta}_{\\widehat{n}}$ and use it for a\nconfidence interval $\\left[ \\widehat{\\Theta}_{\\widehat{n}}-m^{\\ast },\\widehat{\\Theta}_{\\widehat{n}%\n}+m^{\\ast }\\right] .$ \\bigskip\n\\end{algorithm}\n\nThe method is well founded heuristically. Can we show that it works, i.e.\nthat asymptotic confidence level $C$ is maintained ?\n\nConsider an \"ideal sample size\" $n_{0}$ which would guarantee the margin of\nerror $m^{\\ast }$ if $\\theta^*$ were known: \n\\begin{equation}\nm^{\\ast }=z_{\\alpha}\\sqrt{\\frac{\\theta^*(1-\\theta^*)}{n_{0}}}.\n\\label{m-star-equal}\n\\end{equation}%\ni.e. \n\\begin{equation}\nn_{0}=\\theta^*(1-\\theta^*)\\left( \\frac{z_{\\alpha}}{m^{\\ast }}\\right) ^{2}.\n\\label{n-null-determined}\n\\end{equation}%\nThis is a sample size we cannot use, but if we could use it, then the\ninterval $\\left[ \\widehat{\\Theta}_{n_{0}}-m^{\\ast },\\widehat{\\Theta}_{n_{0}}+m^{\\ast }\\right] $\nwould surely have asymptotic confidence level $C$. Of course if we know $\\theta^*$\nthen there is no need for a confidence interval anymore. But consideration\nof such \"unavailable\" methods is frequently useful\\footnote{%\nSuch unavailable choices are sometimes called \"of oracle type\" since they\nare only available if an oracle tells us the truth, i.e. gives the true $\\theta^*$\nhere.}.\n\nIn what follows we will assume firstly, that the sample size for the pilot\nstudy $n_{1}$ tends to infinity, so that we have a more and more accurate $%\n\\widehat{\\Theta}_{(1)}$. On the other hand, we want $n_{1}$ to be small compared to\nthe size $\\widehat{n}$ of our \"actual\" sample, i.e we want $n_{1}/\\widehat{n}%\n\\rightarrow _{\\P }0$ (here $\\widehat{n}$ is random). Since there is good reason\nto believe that $\\widehat{n}/n_{0}\\rightarrow _{\\P }1$, we should guarantee $%\nn_{1}/n_{0}\\rightarrow 0$. But $n_{0}$ is determined by $m^{\\ast }$ via (\\ref%\n{n-null-determined}), so we are led to consider small desired margins of\nerror: $m^{\\ast }\\rightarrow 0$. The requirement $n_{1}/n_{0}\\rightarrow 0$\nwill equivalently be expressed as $n_{1}\\left( m^{\\ast }\\right)\n^{2}\\rightarrow 0$ (in view of (\\ref{n-null-determined})).\n\n\\bigskip\n\n\\begin{rem}\nWhen $n_{1}$ is only a fraction of $n_{0}$ \nthen the following modification of the Algorithm does not change the\nessence: let $Y_{1},\\ldots ,Y_{n_{1}}$ be the first part of the\nlarger sample $X_{1},\\ldots ,X_{\\widehat{n}}$. This is how one might\nproceed in practice, but to show rigorously that this method also works is\nslightly more involved, though not different in principle from our proof\nbelow.\n\\end{rem}\n\nTo summarize: we will consider the Algorithm \\ref{algo-2-stage} in a setting\nwhere $m^{\\ast }\\rightarrow 0$, $n_{1}\\rightarrow \\infty $, and $n_{1}\\left(\nm^{\\ast }\\right) ^{2}\\rightarrow 0$ (the third requirement means that $n_{1}$\ntends to infinity slower than $\\left( m^{\\ast }\\right) ^{2}$ tends to zero).\n\n\\begin{prop}\nSuppose independent Bernoulli observations $Y_{1},\\ldots ,Y_{n_{1}}$ and $%\nX_{1},X_{2}\\ldots $with law $\\bernoulli(\\theta^*)$ where $\\theta^* \\in (0,1)$ is unknown.\nSuppose $n_{1}\\rightarrow \\infty $, $m^{\\ast }\\rightarrow 0$ and $%\nn_{1}\\left( m^{\\ast }\\right) ^{2}\\rightarrow 0$. Then the confidence\ninterval $\\left[ \\widehat{\\Theta}_{\\widehat{n}}-m^{\\ast },\\widehat{\\Theta}_{\\widehat{n}}+m^{\\ast }%\n\\right] $ given by Algorithm \\ref{algo-2-stage} maintains asymptotic level $%\nC $.\n\\end{prop}\n\n\\begin{proof}\nFor the proof, we may take $n_{0}$ as our basic index tending to infinity ($%\nn_{0}\\rightarrow 0$ is equivalent to $m^{\\ast }\\rightarrow 0$). First we\nshow that \n\\begin{equation}\n\\frac{\\widehat{n}}{n_{0}}\\rightarrow _{\\P }1\\text{ as }n_{0}\\rightarrow 0.\n\\label{firststep-n-0}\n\\end{equation}%\nIndeed, we have \n\\begin{eqnarray*}\n\\frac{\\widehat{n}}{n_{0}} &=&\\frac{\\widehat{\\Theta}_{(1)}(1-\\widehat{\\Theta}_{(1)})\\left( \\frac{%\nz_{\\alpha}}{m^{\\ast }}\\right) ^{2}}{\\theta^*(1-\\theta^*)\\left( \\frac{z_{\\alpha}}{m^{\\ast }}\\right) ^{2}} \\\\\n&=&\\frac{\\widehat{\\Theta}_{(1)}(1-\\widehat{\\Theta}_{(1)})}{\\theta^*(1-\\theta^*)}.\n\\end{eqnarray*}%\nBy Slutsky's theorem (Theorem \\ref{theo-slutsky}) it suffices to show that $%\n\\widehat{\\Theta}_{(1)}\\rightarrow _{\\P }\\theta^*$. By the LLN, this is implied by our\ncondition $n_{1}\\rightarrow \\infty $.\n\nConsider the coverage probability:%\n\\begin{eqnarray}\n&=&\\P \\left( \\widehat{\\Theta}_{\\widehat{n}}-m^{\\ast }\\leq \\theta^*\\leq \\widehat{\\Theta}_{\\widehat{n}%\n}+m^{\\ast }\\right)  \\notag \\\\\n&=&1-\\P \\left( \\widehat{\\Theta}_{\\widehat{n}}-\\theta^*\\leq -m^{\\ast }\\right) +\\P \\left( \\widehat{\\Theta}%\n_{\\widehat{n}}-\\theta^*\\geq m^{\\ast }\\right)  \\label{other-term}\n\\end{eqnarray}%\nNow \n\\begin{equation*}\n\\P \\left( \\widehat{\\Theta}_{\\widehat{n}}-\\theta^*\\geq m^{\\ast }\\right) =\n\\end{equation*}\n\\begin{equation}\n\\P \\left( \\frac{\\widehat{\\Theta}_{\\widehat{n}}-\\theta^*}{\\sqrt{\\theta^*(1-\\theta^*)}/\\sqrt{\\widehat{n}}}\\leq \n\\frac{\\sqrt{\\widehat{n}}m^{\\ast }}{\\sqrt{\\theta^*(1-\\theta^*)}}\\right) .  \\label{tail-inequ}\n\\end{equation}%\nNow $\\widehat{\\Theta}_{\\widehat{n}}$ is from a sample of random size $\\widehat{n}$ but the $%\n\\widehat{n}$ is independent of this sample since it is based on $Y:=\\left(\nY_{1},\\ldots ,Y_{n_{1}},\\ldots \\right) $. Now by $\\P_{\\ast }$ we will write\nprobabilities for fixed $Y$ (conditional on $Y$); then we have $\\P \\left(\n\\cdot \\right) =\\E\\P_{\\ast }\\left( \\cdot \\right) $ where the expected value\nrefers to $Y$. Select $\\varepsilon >0$; from (\\ref{firststep-n-0}) we have\non an event $A_{n_{0}}$ (concerning only $Y$) where $\\P \\left( Y\\notin\nA_{n_{0}}\\right) \\rightarrow 0$ \n\\begin{equation*}\n1-\\varepsilon \\leq \\widehat{n}/n_{0}\\leq 1+\\varepsilon\n\\end{equation*}%\nhence for $Y\\in A_{n_{0}}$ \n\\begin{equation*}\n\\widehat{n}\\geq n_{0}\\left( 1-\\varepsilon \\right) \\text{ and }\\widehat{n}\\leq\nn_{0}\\left( 1+\\varepsilon \\right) .\n\\end{equation*}%\nIn this case \n\\begin{equation*}\n\\frac{\\sqrt{\\widehat{n}}m^{\\ast }}{\\sqrt{\\theta^*(1-\\theta^*)}}\\leq \\frac{\\sqrt{n_{0}}m^{\\ast }%\n}{\\sqrt{\\theta^*(1-\\theta^*)}}\\sqrt{\\left( 1+\\varepsilon \\right) }=z_{\\alpha}%\n\\sqrt{\\left( 1+\\varepsilon \\right) }\n\\end{equation*}%\nby (\\ref{m-star-equal}). Let $B_{n_{0}}$be the event in (\\ref{tail-inequ}),\nthen, if $\\mathbf{1}_{\\left\\{ Y\\in A_{n_{0}}\\right\\} }$ denotes the\nindicator of the event $\\left\\{ Y\\in A_{n_{0}}\\right\\} $, \n\\begin{eqnarray*}\n\\P \\left( B_{n_{0}}\\right) &=&\\E\\P\\nolimits_{\\ast }\\left( B_{n_{0}}\\right)\n=\\E\\mathbf{1}_{\\left\\{ Y\\in A_{n_{0}}\\right\\} }\\P\\nolimits_{\\ast }\\left(\nB_{n_{0}}\\right) +\\E\\mathbf{1}_{\\left\\{ Y\\notin A_{n_{0}}\\right\\}\n}\\P\\nolimits_{\\ast }\\left( B_{n_{0}}\\right) \\\\\n&\\leq &\\E\\mathbf{1}_{\\left\\{ Y\\in A_{n_{0}}\\right\\} }\\P\\nolimits_{\\ast\n}\\left( B_{n_{0}}\\right) +\\E\\mathbf{1}_{\\left\\{ Y\\notin A_{n_{0}}\\right\\} } \\\\\n&=&\\E\\mathbf{1}_{\\left\\{ Y\\in A_{n_{0}}\\right\\} }\\P\\nolimits_{\\ast }\\left(\nB_{n_{0}}\\right) +\\P \\left( Y\\notin A_{n_{0}}\\right) \\\\\n&\\leq &\\E\\mathbf{1}_{\\left\\{ Y\\in A_{n_{0}}\\right\\} }\\P\\nolimits_{\\ast\n}\\left( \\frac{\\widehat{\\Theta}_{\\widehat{n}}-\\theta^*}{\\sqrt{\\theta^*(1-\\theta^*)}/\\sqrt{\\widehat{n}}}\\leq\nz_{\\alpha}\\sqrt{\\left( 1+\\varepsilon \\right) }\\right) +\\P \\left(\nY\\notin A_{n_{0}}\\right) .\n\\end{eqnarray*}\nIf $Y$ is fixed then $\\widehat{n}$ is also fixed and on the event $Y\\in\nA_{n_{0}} $ we have $\\widehat{n}\\geq n_{0}\\left( 1-\\varepsilon \\right) $. Thus $%\n\\widehat{n}$ is large and the CLT will hold, so for large $n_{0}$ we will have \n\\begin{equation*}\n\\P\\nolimits_{\\ast }\\left( \\frac{\\widehat{\\Theta}_{\\widehat{n}}-\\theta^*}{\\sqrt{\\theta^*(1-\\theta^*)}/\\sqrt{%\n\\widehat{n}}}\\leq z_{\\alpha}\\sqrt{\\left( 1+\\varepsilon \\right) }\\right)\n\\leq \\P \\left( Z\\leq z_{\\alpha}\\sqrt{\\left( 1+\\varepsilon \\right) }%\n\\right) +\\varepsilon .\n\\end{equation*}%\nHere the right side does not depend on $Y$. Collecting these results we\nobtain \n\\begin{eqnarray*}\n\\P \\left( B_{n_{0}}\\right) &\\leq &\\E\\mathbf{1}_{\\left\\{ Y\\in\nA_{n_{0}}\\right\\} }\\left( \\P \\left( Z\\leq z_{\\alpha}\\sqrt{\\left(\n1+\\varepsilon \\right) }\\right) +\\varepsilon \\right) +\\P \\left( Y\\notin\nA_{n_{0}}\\right) \\\\\n&\\leq &\\P \\left( Z\\leq z_{\\alpha}\\sqrt{\\left( 1+\\varepsilon\n\\right) }\\right) +\\varepsilon +\\P \\left( Y\\notin A_{n_{0}}\\right) \\\\\n&\\leq &\\P \\left( Z\\leq z_{\\alpha}\\sqrt{\\left( 1+\\varepsilon\n\\right) }\\right) +2\\varepsilon\n\\end{eqnarray*}%\nsince $\\P \\left( Y\\notin A_{n_{0}}\\right) \\leq \\varepsilon $ for\nsufficently large $n_{0}$. Since $\\varepsilon >0$ was arbitrary, we obtain \n\\begin{equation*}\n\\limsup \\P \\left( \\widehat{\\Theta}_{\\widehat{n}}-\\theta^*\\geq m^{\\ast }\\right) =\\limsup \\P\n\\left( B_{n_{0}}\\right) \\leq \\P \\left( Z\\leq z_{\\alpha}\\right)\n=\\alpha\n\\end{equation*}%\nFor the other term in (\\ref{other-term}) we obtain analogously \n\\begin{equation*}\n\\limsup \\P \\left( \\widehat{\\Theta}_{\\widehat{n}}-\\theta^*\\leq -m^{\\ast }\\right) \\leq \\alpha .\n\\end{equation*}%\nhence \n\\begin{equation*}\n\\liminf \\P \\left( \\widehat{\\Theta}_{\\widehat{n}}-m^{\\ast }\\leq \\theta^*\\leq \\widehat{\\Theta}_{\\widehat{n}%\n}+m^{\\ast }\\right) \\geq 1-2\\alpha =C.\n\\end{equation*}\n\\end{proof}\n\n\n\\begin{rem}\nIn the proof we did not use the condition that $n_{1}$ is\nonly a fraction of $n_{0}$ (i.e. $n_{1}\\left( m^{\\ast }\\right)\n^{2}\\rightarrow 0$) but this condition would play a role if $Y_{1},\\ldots\n,Y_{n_{1}}$\\emph{\\ }is the first part of the larger sample $X_{1},\\ldots ,X_{%\n\\widehat{n}}$.\n\\end{rem}\n\n\\begin{Exercise}[label={ExNameOfMayorPoll}]\nA simple random sample of 200 people aged 18 or over\nis taken in a large city to see how many of them know the name of the mayor.\nIt turns out that $118$ could correctly give her name.\n\n\\begin{description}\n\\item[\\textbf{a}] Find a $90\\%$ (asymptotic) confidence interval for the\nproportion of people 18 or over who know the mayor's name. In calculating\nthe interval, please also give the margin of error.\n\n%\\item[\\textbf{b}] What is the margin of error for this interval?\n\n\\item[\\textbf{b}] Suppose the staff said that budget constraints mean that\nthe largest sample they can obtain is $1200$ people. They make another\nsurvey with that sample size and find $\\widehat{p}=0.6$. In order to please the\nmayor they report a margin of error of $0.02$. What is the asymptotic\nconfidence level of this interval?\n\\end{description}\n\\end{Exercise}\n\n\\remove{\n}\n", "meta": {"hexsha": "6cfc7dbacc81ff866f89311e053a77c34931e5ae", "size": 112271, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/InferProportions.tex", "max_stars_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_stars_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-19T07:54:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T13:55:18.000Z", "max_issues_repo_path": "matlab/csebook/InferProportions.tex", "max_issues_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_issues_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "matlab/csebook/InferProportions.tex", "max_forks_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_forks_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-07-18T07:47:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T11:28:24.000Z", "avg_line_length": 47.5724576271, "max_line_length": 392, "alphanum_fraction": 0.6807456957, "num_tokens": 39478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245828938678, "lm_q2_score": 0.8872045952083047, "lm_q1q2_score": 0.7393293992434834}}
{"text": "\\subsection{Von Neumann's cumulative hierarchy}\\label{subsec:von_neumanns_cumulative_hierarchy}\n\nWe will now investigate how we can use set theory itself to build models of set theory. \\Fullref{thm:cumulative_hierarchy_model_of_zfc} contains the important results.\n\n\\begin{definition}\\label{def:cumulative_hierarchy}\\mcite[def. 61.1]{OpenLogicFull}\n  For every ordinal \\( \\alpha \\) we use \\fullref{rem:unbounded_transfinite_recursion} to define\n  \\begin{equation}\\label{eq:def:cumulative_hierarchy}\n    V_\\alpha \\coloneqq \\begin{cases}\n      \\varnothing,                                  &\\alpha = 0 \\\\\n      \\pow(V_\\beta),                                &\\alpha = \\beta + 1 \\\\\n      \\bigcup\\set{ V_\\beta \\given \\beta < \\alpha }, &\\alpha \\T{is a limit ordinal.}\n    \\end{cases}\n  \\end{equation}\n\n  Each \\( V_\\alpha \\) is called a \\term{stage} and the index \\( \\alpha \\) of a stage is called its \\term{rank}. The entire proper class of stages is called the \\term{cumulative hierarchy}.\n\n  If some set \\( A \\) is a subset of \\( V_\\alpha \\), but not of \\( V_\\beta \\) for any \\( \\beta < \\alpha \\), we say that \\( \\alpha \\) is the \\term{rank} of the set \\( A \\) and denote it by \\( \\rank(A) \\). We will see in \\fullref{thm:axiom_of_regularity} that every set has a rank.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:cumulative_hierarchy}\n  Without relying on the \\hyperref[def:zfc/foundation]{axiom of foundation} and by assuming that ordinals are well-founded by definition, we can prove the following basic properties for \\hyperref[def:cumulative_hierarchy]{Von Neumann's cumulative hierarchy}:\n  \\begin{thmenum}\n    \\thmitem{thm:def:cumulative_hierarchy/transitive} Each stage \\( V_\\alpha \\) is a transitive set.\n    \\thmitem{thm:def:cumulative_hierarchy/membership} For any two ordinals \\( \\alpha < \\beta \\) we have \\( V_\\alpha \\in V_\\beta \\).\n    \\thmitem{thm:def:cumulative_hierarchy/rank_inequality} If \\( A \\in B \\) and both sets have ranks, then \\( \\rank(A) \\in \\rank(B) \\).\n    \\thmitem{thm:def:cumulative_hierarchy/well_founded} Each stage \\( V_\\alpha \\) is well-founded by set membership.\n    \\thmitem{thm:def:cumulative_hierarchy/subsets} We have \\( \\alpha < \\beta \\) if and only if \\( V_\\alpha \\subsetneq V_\\beta \\).\n    \\thmitem{thm:def:cumulative_hierarchy/ordinals} For every ordinal \\( \\alpha \\) we have \\( \\rank(\\alpha) = \\alpha \\).\n    \\thmitem{thm:def:cumulative_hierarchy/stage_rank} For every stage \\( V_\\alpha \\) we have \\( \\rank(V_\\alpha) = \\alpha \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:cumulative_hierarchy/transitive} The statement is vacuous for \\( \\alpha = 0 \\). Suppose that \\( \\alpha > 0 \\), let \\( A \\in V_\\alpha \\) and \\( B \\in A \\). We will show that \\( B \\in V_\\alpha \\).\n  \\begin{itemize}\n    \\item Suppose that \\( \\alpha = \\beta + 1 \\) and that \\( V_\\beta \\) is a transitive set. Then \\( A \\in V_\\alpha \\) implies that \\( A \\subseteq V_\\beta \\). Thus, \\( B \\in V_\\beta \\) and, since \\( V_\\beta \\) is a transitive set, \\( B \\subseteq V_\\beta \\).\n\n    Therefore, \\( B \\in V_\\alpha = \\pow(V_\\beta) \\).\n\n    \\item Suppose that \\( \\alpha \\) is a limit ordinal and that \\( V_\\beta \\) are transitive sets for every \\( \\beta < \\alpha \\). Then \\( A \\in V_\\alpha \\) implies that \\( A \\) belongs to \\( V_{\\beta_0} \\) for some \\( \\beta_0 < \\alpha \\). The inductive hypothesis implies that \\( A \\subseteq V_{\\beta_0} \\). Therefore, \\( A \\subseteq V_\\alpha \\).\n  \\end{itemize}\n\n  \\SubProofOf{thm:def:cumulative_hierarchy/membership} Let \\( \\alpha < \\beta \\) be some ordinals. We will show that \\( V_\\alpha \\in V_\\beta \\) using induction on \\( \\beta \\).\n  \\begin{itemize}\n    \\item Suppose that \\( \\beta \\) is a successor ordinal, i.e. \\( \\beta = \\mu + 1 \\) for some \\( \\mu \\), and suppose that for every \\( \\alpha < \\mu \\) we have \\( V_\\alpha \\in V_\\mu \\). Clearly \\( V_\\mu \\in V_\\beta \\) because \\( V_\\mu \\) is a subset of itself.\n\n    If \\( \\alpha < \\mu \\), then \\( V_\\alpha \\in V_\\mu \\) by the inductive hypothesis and, since \\( V_\\beta \\) is a transitive set by \\fullref{thm:def:cumulative_hierarchy/transitive}, \\( V_\\alpha \\in V_\\beta \\).\n\n    \\item Suppose that \\( \\beta \\) is a limit ordinal. For some fixed \\( \\alpha_0 \\in \\beta \\) we have \\( V_{\\alpha_0} \\in V_{\\alpha_0 + 1} \\) by what we have already proved. We also have\n    \\begin{equation*}\n      V_\\beta\n      =\n      \\bigcup_{\\alpha < \\beta} V_\\alpha,\n    \\end{equation*}\n    hence \\( V_{\\alpha_0} \\in V_\\beta \\).\n  \\end{itemize}\n\n  \\SubProofOf{thm:def:cumulative_hierarchy/rank_inequality} Let \\( A \\in B \\) be arbitrary sets for which ranks are defined. Trichotomy holds for ordinals, so we have to show that \\( \\rank(A) \\geq \\rank(B) \\) leads to a contradiction. Denote the ranks by \\( \\alpha \\) and \\( \\beta \\) for brevity.\n\n  We have \\( A \\subseteq V_\\alpha \\) by definition and \\( A \\subseteq V_\\beta \\) since \\( V_\\alpha \\in V_\\beta \\) and \\( V_\\beta \\) is transitive. If we suppose that \\( \\rank(B) < \\rank(A) \\), this would mean that \\( A \\) belongs to a stage below \\( V_\\alpha \\), which contradicts the minimality of \\( \\alpha = \\rank(A) \\).\n\n  Now suppose that \\( \\beta = \\rank(B) = \\rank(A) = \\alpha \\).\n  \\begin{itemize}\n    \\item If \\( \\beta = 0 \\), then \\( A \\in B \\) is impossible.\n\n    \\item If \\( \\beta \\) is a successor ordinal of \\( \\alpha \\), then \\( V_\\beta = \\pow(V_\\alpha) \\). Since \\( B \\subseteq V_\\beta \\) is a set of subsets of \\( V_\\alpha \\), \\( A \\in B \\) is a subset of \\( V_\\alpha \\). Thus, we have \\( \\rank(A) \\leq \\alpha < \\rank(A) \\), which contradicts the well-foundedness of the ordinal ordering.\n\n    \\item If \\( \\beta \\) is a limit ordinal, then \\( V_\\beta = \\bigcup\\set{ V_\\alpha \\given \\alpha < \\beta } \\). As a member of \\( B \\), the set \\( A \\) belongs to some lower stage \\( V_{\\alpha_0} \\), which again leads to \\( \\rank(A) < \\rank(A) \\).\n  \\end{itemize}\n\n  Thus, it remains for \\( \\rank(A) < \\rank(B) \\).\n\n  \\SubProofOf{thm:def:cumulative_hierarchy/well_founded} We will use induction on \\( \\alpha \\). Suppose that \\( V_\\beta \\) is well-founded for every \\( \\beta < \\alpha \\). Aiming at a contradiction, suppose that there exists an infinitely descending sequence \\( \\seq{ x_k }_{k=1}^\\infty \\subseteq V_\\alpha \\). Then the sequence \\( \\seq{ \\rank(x_k) }_{k=0}^\\infty \\) of ranks is an infinitely descending set of ordinals. The \\hyperref[def:transitive_closure_of_a_set]{transitive closure} of the underlying set is then an ordinal by \\fullref{thm:transitive_set_of_transitive_sets}. But this contradicts the well-foundedness of ordinals.\n\n  Therefore, \\( V_\\alpha \\) must be well-founded.\n\n  \\SubProofOf{thm:def:cumulative_hierarchy/subsets} If \\( \\alpha < \\beta \\), then from \\fullref{thm:def:cumulative_hierarchy/membership} and \\fullref{thm:def:cumulative_hierarchy/transitive} it follows that \\( V_\\alpha \\subseteq V_\\beta \\). We will show that \\( V_\\alpha \\neq V_\\beta \\). Fix some \\( \\mu < \\beta \\) and suppose that \\( V_\\alpha \\subsetneq V_\\mu \\) holds for all \\( \\alpha < \\mu \\). If \\( V_\\alpha = V_\\beta \\), this would mean that \\( V_\\alpha \\subsetneq V_\\mu \\subseteq V_\\beta = V_\\alpha \\), which is a contradiction. Therefore, \\( V_\\alpha \\subsetneq V_\\beta \\).\n\n  Conversely, suppose that \\( V_\\alpha \\subsetneq V_\\beta \\). Since trichotomy holds for ordinals and since \\( V_\\alpha \\neq V_\\beta \\), it is sufficient to show that \\( \\alpha > \\beta \\) leads to a contradiction. If \\( \\alpha > \\beta \\), from \\fullref{thm:def:cumulative_hierarchy/membership} it follows that \\( V_\\beta \\in V_\\alpha \\), which implies that \\( V_\\beta \\subsetneq V_\\beta \\). The obtained contradiction shows that \\( \\alpha < \\beta \\).\n\n  \\SubProofOf{thm:def:cumulative_hierarchy/ordinals} We will use transfinite induction to show that \\( \\rank(\\alpha) = \\alpha \\) for every ordinal.\n  \\begin{itemize}\n    \\item The case \\( \\alpha = 0 \\) is trivial because \\( \\alpha = \\varnothing \\subseteq \\varnothing = V_0 \\).\n\n    \\item Suppose that \\( \\alpha = \\beta + 1 \\) is a successor ordinal and \\( \\rank(\\beta) = \\beta \\). Clearly \\( \\beta \\in \\pow(V_\\beta) = V_\\alpha \\) and \\( \\set{ \\beta } \\in V_\\alpha \\). Since \\( V_\\alpha \\) is a transitive set, we also have \\( \\beta \\subseteq V_\\alpha \\). Thus,\n    \\begin{equation*}\n      \\alpha = \\beta + 1 = \\beta \\cup \\set{ \\beta } \\subseteq V_\\alpha.\n    \\end{equation*}\n\n    \\item Suppose that \\( \\alpha \\) is a limit ordinal and that for \\( \\rank(\\beta) = \\beta \\) for all \\( \\beta < \\alpha \\). Since \\( \\beta \\in V_{\\beta + 1} \\) for any \\( \\beta < \\alpha \\), we have\n    \\begin{equation*}\n      \\alpha\n      =\n      \\set{ \\beta \\T{is an ordinal} \\given \\beta < \\alpha }\n      \\subseteq\n      \\bigcup\\set{ V_{\\beta + 1} \\given \\beta < \\alpha }\n      =\n      V_\\alpha.\n    \\end{equation*}\n  \\end{itemize}\n\n  \\SubProofOf{thm:def:cumulative_hierarchy/stage_rank} Clearly \\( V_\\alpha \\) is a subset of itself, hence \\( \\rank(V_\\alpha) \\leq \\alpha \\). In particular, the rank of \\( V_\\alpha \\) exists.\n\n  We will use induction on \\( \\alpha \\) to show that \\( \\rank(V_\\alpha) \\geq \\alpha \\).\n  \\begin{itemize}\n    \\item For \\( \\alpha = 0 \\) this is obvious.\n    \\item If \\( \\rank(V_\\alpha) = \\alpha \\), then\n    \\begin{equation*}\n      \\rank(V_{\\alpha + 1})\n      =\n      \\rank(\\pow(V_\\alpha))\n      \\reloset {\\ref{thm:def:cumulative_hierarchy/rank_inequality}} >\n      \\rank(V_\\alpha)\n      =\n      \\alpha.\n    \\end{equation*}\n\n    \\item Let \\( \\lambda \\) be a limit ordinal and suppose that \\( \\rank(V_\\alpha) = \\alpha \\) for any \\( \\alpha < \\lambda \\). Then\n    \\begin{equation*}\n      \\rank(V_\\lambda)\n      \\reloset {\\ref{thm:def:cumulative_hierarchy/rank_inequality}} \\geq\n      \\sup\\set{ \\rank(V_\\alpha) \\given \\alpha < \\lambda }\n      =\n      \\sup\\set{ \\alpha \\given \\alpha < \\lambda }\n      =\n      \\lambda.\n    \\end{equation*}\n  \\end{itemize}\n\n  Therefore, \\( \\rank(V_\\alpha) = \\alpha \\).\n\\end{proof}\n\n\\begin{theorem}[Axiom of regularity]\\label{thm:axiom_of_regularity}\\mcite[thm. 64.11]{OpenLogicFull}\n  Every set belongs to a stage in \\hyperref[def:cumulative_hierarchy]{von Neumann's cumulative hierarchy}.\n\n  This statement is called the \\term{axiom of regularity} and in the presence of the other axioms of \\logic{ZF}, it is equivalent to the \\hyperref[def:zfc/foundation]{axiom of foundation}. It is much more difficult to state in the language of set theory, however.\n\\end{theorem}\n\\begin{proof}\n  \\ImplicationSubProof[def:zfc/foundation]{axiom of foundation}[thm:axiom_of_regularity]{axiom of regularity} Let \\( A \\) be a set. By \\fullref{thm:transitive_closure_of_a_set}, its \\hyperref[def:transitive_closure_of_a_set]{transitive closure} \\( \\cl^T(A) \\) is a transitive set. Define\n  \\begin{equation*}\n    D \\coloneqq \\set{ B \\in \\cl^T(A) \\given B \\T{does not belong to the cumulative hierarchy} }.\n  \\end{equation*}\n\n  We will show that \\( D \\) is empty. Assume the contrary. Then by the \\hyperref[def:zfc/foundation]{axiom of foundation} there exists \\( B_0 \\in D \\) such that \\( B_0 \\cap D = \\varnothing \\). Since \\( \\cl^T(A) \\) is a transitive set, \\( B_0 \\subseteq \\cl^T(A) \\). Thus, \\( B_0 \\) consists of members \\( x \\) of \\( \\cl^T(A) \\) that themselves have ranks, i.e. a minimal ordinal \\( \\beta \\) such that \\( x \\subseteq V_\\beta \\). It follows from the \\hyperref[def:zfc/replacement]{axiom schema of replacement} that these ordinals form a set. Denote this set by \\( C \\).\n\n  If \\( x \\in B_0 \\), then \\( x \\subseteq V_\\beta \\) for some \\( \\beta \\in C \\) and \\( x \\in V_{\\beta + 1} \\). Thus,\n  \\begin{equation*}\n    B_0 \\subseteq \\bigcup\\set{ V_{\\beta + 1} \\given \\beta \\in C }.\n  \\end{equation*}\n\n  Denote the union on the right by \\( \\alpha \\). From \\fullref{thm:union_of_set_of_ordinals} it follows that \\( \\alpha \\) is an ordinal strictly larger than the ordinals in \\( C \\). By \\fullref{thm:def:cumulative_hierarchy/membership} we have that \\( V_{\\beta + 1} \\in V_\\alpha \\) for every \\( \\beta \\in C \\). Thus,\n  \\begin{equation*}\n    B_0 \\subseteq \\bigcup\\set{ V_{\\beta + 1} \\given \\beta \\in C } \\subseteq V_\\alpha.\n  \\end{equation*}\n\n  This contradicts our assumption that \\( B_0 \\) does not belong to the cumulative hierarchy. Therefore, \\( D = \\varnothing \\) and every member of \\( \\cl^T(A) \\) also belongs to the cumulative hierarchy. In particular, every member of \\( A \\) belongs to the cumulative hierarchy.\n\n  Define\n  \\begin{equation*}\n    \\mu \\coloneqq \\bigcup\\set{ \\rank(B) + 1 \\given B \\in A }.\n  \\end{equation*}\n\n  Since \\( B \\) is a member of the stage with rank \\( \\rank(B) + 1 \\) for every \\( B \\in A \\), with the same reasoning as above it follows that \\( A \\subseteq V_\\mu \\).\n\n  \\ImplicationSubProof[thm:axiom_of_regularity]{axiom of regularity}[def:zfc/foundation]{axiom of foundation} Let \\( A \\) be any nonempty set. We will show that there exists a subset of \\( A \\) that is disjoint from \\( A \\).\n\n  The \\hyperref[thm:axiom_of_regularity]{axiom of regularity} ensures that \\( A \\) belongs to the von Neumann cumulative hierarchy. Let \\( B \\in A \\) be a set with minimal rank.\n\n  Suppose that \\( B \\cap A \\) is not empty. Then there exists some set \\( C \\in A \\setminus B \\). From \\fullref{thm:def:cumulative_hierarchy/rank_inequality} it follows that \\( \\rank(C) < \\rank(B) < \\rank(A) \\). But \\( C \\) belongs to \\( A \\) and has a rank strictly smaller than \\( \\rank(B) \\), which contradicts the minimality of \\( \\rank(B) \\).\n\n  The obtained contradiction shows that \\( B \\cap A = \\varnothing \\).\n\\end{proof}\n\n\\begin{theorem}\\label{thm:cumulative_hierarchy_model_of_z}\\mcite{MathSE:cumulative_hierarchy_model_of_zfc}\n  The stage \\( V_{\\omega + \\omega} \\) of the \\hyperref[def:cumulative_hierarchy]{von Neumann's cumulative hierarchy} is a standard model of \\logic{Z}, i.e. \\logic{ZFC} without the \\hyperref[def:zfc/replacement]{axiom schema of replacement}.\n\n  More generally, a necessary and sufficient condition for \\( V_\\alpha \\) to be a model of \\logic{Z} is for \\( \\alpha \\) to be a limit ordinal larger than \\( \\omega \\).\n\\end{theorem}\n\\begin{proof}\n  The following axioms are automatically satisfied for any stage \\( V_\\alpha \\):\n  \\begin{itemize}\n    \\item The validity of the \\hyperref[def:zfc/extensionality]{axiom of extensionality} is inherited from the metatheory.\n\n    \\item The \\hyperref[def:zfc/specification]{axiom schema of specification} is satisfied because each axiom in the schema \\hyperref[def:first_order_definability]{defines} a subset of \\( V_\\alpha \\) and because \\( V_\\alpha \\) is a transitive set. This does not necessarily require the axiom schema of specification in the metatheory --- we only need the subsets of \\( V_\\alpha \\) defined in \\fullref{def:first_order_definability}.\n\n    \\item The \\hyperref[def:zfc/union]{axiom of unions} is satisfied because if \\( A \\in V_\\alpha \\) and \\( C \\in \\bigcup A \\), then there exists some \\( B \\in A \\) such that \\( C \\in B \\in A \\). Since \\( V_\\alpha \\) is a transitive set, it follows that \\( C \\in V_\\alpha \\).\n\n    \\item The \\hyperref[def:zfc/foundation]{axiom of foundation} is satisfied for any \\( V_\\alpha \\) due to \\fullref{thm:def:cumulative_hierarchy/well_founded}. Its validity is also inherited from the metatheory, but we do not actually need the \\hyperref[def:zfc/foundation]{axiom of foundation} in the metatheory.\n\n    \\item The validity of the \\hyperref[def:zfc/choice]{axiom of choice} is inherited from the metatheory.\n\n    Indeed, for any family of sets \\( \\mscrA \\in V_\\alpha \\) there exists a \\hyperref[def:choice_function]{choice function} \\( c: \\mscrA \\to \\bigcup \\mscrA \\). The set \\( \\set{ c(A) \\given A \\in \\mscrA } \\) then has a lower rank by \\fullref{thm:def:cumulative_hierarchy/rank_inequality} and thus by \\fullref{thm:def:cumulative_hierarchy/subsets} it belongs to \\( V_\\alpha \\).\n  \\end{itemize}\n\n  The rest of the axioms are satisfied whenever some easy restrictions are imposed on \\( \\alpha \\):\n  \\begin{itemize}\n    \\item The \\hyperref[def:zfc/power_set]{axiom of power sets} is satisfied by \\( V_\\lambda \\) for a limit ordinal \\( \\lambda \\) if the axiom of power sets holds in the metatheory.\n\n    Indeed, if \\( A \\in V_\\lambda \\) and \\( A \\) has rank \\( \\beta \\), then necessarily \\( \\beta < \\lambda \\). Since \\( A \\subseteq V_\\beta \\), it follows that \\( \\pow(A) \\subseteq \\pow(V_\\beta) = V_{\\beta + 1} \\). But \\( \\beta + 1 < \\lambda \\) since \\( \\lambda \\) is a limit ordinal. Therefore, \\( \\rank(\\pow(A)) = \\beta + 1 < \\lambda \\). From \\fullref{thm:def:cumulative_hierarchy/subsets} it follows that \\( V_{\\beta + 1} \\subsetneq V_\\lambda \\) and thus \\( \\pow(A) \\subsetneq V_\\lambda \\).\n\n    \\item The \\hyperref[def:zfc/pairing]{axiom of pairing} is also satisfied by \\( V_\\lambda \\) for a limit ordinal \\( \\lambda \\) if the axiom of pairing holds in the theory.\n\n    Let \\( A \\) and \\( B \\) be members of \\( V_\\lambda \\). Let \\( \\beta \\) be the larger of their ranks. Then \\( A \\) and \\( B \\) are subsets of \\( V_\\beta \\), hence members of \\( \\pow(V_\\beta) = V_{\\beta + 1} \\) and thus the set \\( \\set{ A, B } \\) has rank \\( \\beta + 2 \\).\n\n    Since \\( \\lambda \\) is a limit ordinal, we have \\( \\beta + 2 < \\lambda \\) and hence \\( \\set{ A, B } \\in V_\\lambda \\) by \\fullref{thm:def:cumulative_hierarchy/subsets}.\n\n    \\item The \\hyperref[def:zfc/infinity]{axiom of infinity} is satisfied by any ordinal \\( \\alpha > \\omega \\).\n\n    Indeed, by \\fullref{thm:def:cumulative_hierarchy/ordinals} we have \\( \\omega \\subseteq V_\\omega \\) and by \\fullref{thm:def:cumulative_hierarchy/subsets} we have \\( \\omega \\in V_\\alpha \\) for \\( \\alpha \\geq \\omega + 1 \\).\n  \\end{itemize}\n\n  As discussed in \\fullref{ex:countable_limit_ordinals}, \\( \\omega + \\omega \\) is the smallest ordinal that is both strictly larger than \\( \\omega \\) and is a limit ordinal. Therefore, \\( \\omega + \\omega \\) or any larger limit ordinal is a model of \\( \\logic{ZFC} \\) without the axiom of replacement.\n\\end{proof}\n\n\\begin{definition}\\label{def:cofinality}\n  The \\term{cofinality} of a \\hyperref[def:preordered_set]{preordered set} \\( (P, \\leq) \\) is defined as\n  \\begin{equation*}\n    \\op{cf}(P, \\leq) \\coloneqq \\min\\set{ \\card(A) \\given A \\T{is a cofinal subset of} P }.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:cardinal_cofinality}\n  The \\hyperref[def:cofinality]{cofinality} of an infinite cardinal \\( \\kappa \\) is\n  \\begin{equation*}\n    \\op{cf}(\\kappa) = \\min\\set{ \\card(A) \\given A \\T{is an unbounded subset of} \\kappa }.\n  \\end{equation*}\n\\end{proposition}\n\\begin{proof}\n  Well-foundedness of \\( \\kappa \\) ensures that it is bounded from below, hence a subset \\( A \\) of \\( \\kappa \\) is bounded from above if and only if it is bounded.\n\n  Since \\( \\kappa \\) itself as a limit ordinal by \\fullref{thm:cardinal_is_infinite_iff_limit_ordinal}, it has no maximum. Hence, it is unbounded.\n\n  The above reflections along with \\fullref{thm:totally_ordered_cofinal_equivalences} imply that a subset \\( A \\) of \\( \\kappa \\) is cofinal if and only if it is unbounded.\n\\end{proof}\n\n\\begin{definition}\\label{def:regular_cardinal}\n  We say that the infinite cardinal \\( \\kappa \\) is \\term{regular} if any of the following equivalent conditions hold:\n  \\begin{thmenum}\n    \\thmitem{def:regular_cardinal/cofinality} \\( \\kappa \\) it is equal to its own \\hyperref[def:cofinality]{cofinality}.\n    \\thmitem{def:regular_cardinal/unbounded_subsets} Every unbounded subset of \\( \\kappa \\) has cardinality \\( \\kappa \\).\n  \\end{thmenum}\n\n  Note that the term \\enquote{regular cardinal} is unrelated to \\fullref{thm:axiom_of_regularity}.\n\n  If \\( \\kappa \\) is not regular, we say that it is \\term{singular}. Finite ordinals are neither regular nor singular.\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:regular_cardinal/cofinality}{def:regular_cardinal/unbounded_subsets} Note that \\( \\card(A) \\leq \\kappa \\) for \\( A \\subseteq \\kappa \\). \\Fullref{thm:cardinal_cofinality} implies that if \\( A \\) is unbounded, we have \\( \\card(A) \\geq \\op{cf}(\\kappa) \\). But \\( \\op{cf}(\\kappa) = \\kappa \\), hence the result follows.\n\n  \\ImplicationSubProof{def:regular_cardinal/unbounded_subsets}{def:regular_cardinal/cofinality} If every unbounded subset of \\( \\kappa \\) has cardinality \\( \\kappa \\), the minimum of all such cardinalities is \\( \\kappa \\) and hence \\( \\op{cf}(\\kappa) = \\kappa \\).\n\\end{proof}\n\n\\begin{remark}\\label{rem:strongly_inaccessible_cardinal}\n  If \\( \\kappa \\) is an \\hi{uncountable} \\hyperref[def:regular_cardinal]{regular} (weak or strong) \\hyperref[def:successor_and_limit_cardinal]{limit cardinal}, it is commonly called a (weakly or strongly) \\term{inaccessible cardinal}.\n\n  The assumption of uncountability is sometimes dropped, however. We avoid this ambiguity by being explicit and using \\enquote{uncountable regular strong limit cardinal} rather than \\enquote{strongly inaccessible cardinal}.\n\n  Furthermore, we often do not need to restrict ourselves to uncountable regular strong limit cardinals. An added benefit to this is that we can utilize the universe of hereditary finite sets \\hyperref[def:universe_of_hereditary_finite_sets]{\\( V_\\omega \\)} as a \\hyperref[def:grothendieck_universe]{Grothendieck universe} in category theory.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:aleph_zero_is_regular}\n  The first infinite cardinal \\( \\aleph_0 \\) is a \\hyperref[def:regular_cardinal]{regular}.\n\\end{proposition}\n\\begin{proof}\n  The only strict subsets of \\( \\aleph_0 \\) are either countable or finite and the finite sets are bounded. The only unbounded subsets of \\( \\aleph_0 \\) have cardinality \\( \\aleph_0 \\). Hence, \\( \\aleph_0 \\) equals its own cofinality and is thus regular.\n\\end{proof}\n\n\\begin{lemma}\\label{thm:regular_cardinal_stage_supremum_lemma}\n  Let \\( \\kappa \\) be a \\hyperref[def:regular_cardinal]{regular cardinal} and let \\( R \\subseteq \\kappa \\). If \\( \\card(R) < \\kappa \\), then \\( \\sup R < \\kappa \\).\n\\end{lemma}\n\\begin{proof}\n  We shall prove that the set \\( R \\) is bounded from above with respect to the membership ordering of \\( \\kappa \\). Indeed, suppose that it is unbounded. Then \\( \\card(R) = \\kappa \\) since \\( \\kappa \\) is regular. But this contradicts our assumption that \\( \\card(R) < \\kappa \\).\n\n  The obtained contradiction shows that \\( R \\) is bounded from above (with respect to membership in \\( \\kappa \\)). Hence, there exists some ordinal \\( \\rho < \\kappa \\) that is an upper bound of \\( R \\). The supremum \\( \\sup R \\) then satisfies \\( \\sup R \\leq \\rho < \\kappa \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:regular_cardinal_stage_inverse_transitivity}\n  For any regular cardinal \\( \\kappa \\), we have\n  \\begin{equation*}\n    A \\subseteq V_\\kappa \\T{if and only if} (A \\in V_\\kappa \\T{and} \\card(A) < \\kappa).\n  \\end{equation*}\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Let \\( A \\subseteq V_\\kappa \\) and \\( \\card(A) < \\kappa \\). Define\n  \\begin{equation*}\n    R \\coloneqq \\set{ r(x) \\given x \\in A }.\n  \\end{equation*}\n\n  Then from \\fullref{thm:regular_cardinal_stage_supremum_lemma} it follows that \\( \\sup R < \\kappa \\). Denote \\( \\sup R \\) by \\( \\rho \\). Then\n  \\begin{equation*}\n    x \\subseteq V_\\rho \\T{for every} x \\in A.\n  \\end{equation*}\n\n  Therefore, \\( A \\in V_{\\rho + 2} \\). Since \\( \\kappa \\) is an infinite cardinal, from \\fullref{thm:cardinal_is_infinite_iff_limit_ordinal} it follows that it is a limit ordinal and \\( \\rho + 1 < \\kappa \\); then from \\fullref{thm:def:cumulative_hierarchy/subsets} it follows that \\( A \\in V_\\kappa \\).\n\n  \\NecessitySubProof Follows from \\fullref{thm:def:cumulative_hierarchy/transitive}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:strong_regular_cardinal_stages}\n  If \\( \\kappa \\) is a \\hyperref[rem:strongly_inaccessible_cardinal]{regular strong limit cardinal}, then \\( \\card(V_\\alpha) < \\kappa \\) for every \\( \\alpha < \\kappa \\).\n\\end{proposition}\n\\begin{proof}\n  We use \\fullref{thm:bounded_transfinite_induction} on \\( \\alpha \\).\n  \\begin{itemize}\n    \\item If \\( \\alpha = 0 \\), then \\( V_\\alpha = \\varnothing \\) and hence \\( \\card(V_\\alpha) = 0 < \\kappa \\).\n    \\item If \\( \\alpha < \\kappa \\) and \\( \\card(V_\\alpha) < \\kappa \\), then\n    \\begin{equation*}\n      \\card(V_{\\alpha + 1})\n      \\reloset {\\eqref{eq:def:cumulative_hierarchy}} =\n      \\card(\\pow(V_\\alpha))\n      \\reloset {\\ref{thm:cardinal_exponentiation_power_set}} =\n      2^{\\card(V_\\alpha)}.\n    \\end{equation*}\n\n    Since \\( \\kappa \\) is a strong limit, we have \\( \\card(V_{\\alpha + 1}) < \\kappa \\).\n\n    \\item Suppose that \\( \\lambda < \\kappa \\) is a limit ordinal and that \\( \\card(V_\\alpha) < \\kappa \\) for every \\( \\alpha < \\lambda \\).\n\n    From \\fullref{thm:def:cumulative_hierarchy/subsets} we have \\( V_\\alpha \\subsetneq V_{\\alpha + 1} \\) for any \\( \\alpha < \\lambda \\), hence\n    \\begin{equation}\\label{eq:thm:def:cumulative_hierarchy/subsets/limit_inclusion}\n      \\card(V_\\alpha) \\leq \\card(V_{\\alpha + 1}).\n    \\end{equation}\n\n    Define the set\n    \\begin{equation*}\n      C \\coloneqq \\set{ \\card(V_\\alpha) \\given \\alpha < \\lambda }.\n    \\end{equation*}\n\n    Then\n    \\begin{equation*}\n      \\card(V_\\lambda)\n      \\reloset {\\eqref{eq:def:cumulative_hierarchy}} =\n      \\card\\parens*{ \\bigcup \\set{ V_\\alpha \\given \\alpha < \\lambda } }\n      \\reloset {\\eqref{eq:thm:def:cumulative_hierarchy/subsets/limit_inclusion}} =\n      \\sup\\set{ \\card(V_\\alpha) \\given \\alpha < \\lambda }\n      =\n      \\sup C.\n    \\end{equation*}\n\n    From \\fullref{thm:regular_cardinal_stage_supremum_lemma} it follows that \\( \\sup C < \\kappa \\). Therefore, \\( \\card(V_\\lambda) = \\sup C < \\kappa \\).\n  \\end{itemize}\n\\end{proof}\n\n\\begin{corollary}\\label{thm:strong_regular_cardinal_stage_cardinality}\n  If \\( \\kappa \\) is a \\hyperref[rem:strongly_inaccessible_cardinal]{regular strong limit cardinal}, then \\( \\card(A) < \\kappa \\) for every \\( A \\in V_\\kappa \\).\n\\end{corollary}\n\\begin{proof}\n  Denote by \\( \\alpha \\) the rank of \\( A \\). Then\n  \\begin{equation*}\n    \\card(A) \\leq \\card(V_\\alpha) < \\kappa,\n  \\end{equation*}\n  where the last inequality follows from \\fullref{thm:strong_regular_cardinal_stages}.\n\\end{proof}\n\n\\begin{theorem}\\label{thm:cumulative_hierarchy_model_of_zfc}\n  The stage \\( V_\\kappa \\) of the \\hyperref[def:cumulative_hierarchy]{von Neumann's cumulative hierarchy} is a standard model of \\logic{ZFC} for every \\hyperref[rem:strongly_inaccessible_cardinal]{uncountable regular strong limit cardinal} \\( \\kappa \\).\n\n  This theorem is an extension of \\fullref{thm:cumulative_hierarchy_model_of_z}.\n\n  Thus, assuming that at least one strongly inaccessible cardinal exists, \\logic{ZFC} is consistent since it has a model.\n\\end{theorem}\n\\begin{proof}\n  First note that \\( \\kappa \\) is necessarily a limit ordinal by \\fullref{thm:cardinal_is_infinite_iff_limit_ordinal}. It is also larger than \\( \\omega \\) since it is uncountable. Hence, \\fullref{thm:cumulative_hierarchy_model_of_z} is satisfied. We must only show that the \\hyperref[def:zfc/replacement]{axiom schema of replacement} holds in \\( V_\\kappa \\).\n\n  Let \\( A \\in V_\\kappa \\). The \\hyperref[def:zfc/replacement]{axiom schema of replacement} requires the image of every definable function from \\( A \\) to \\( V_\\kappa \\) to be a member of \\( V_\\kappa \\).\n\n  Let \\( \\varphi \\) be a \\hyperref[def:first_order_syntax/formula]{formula} of \\hyperref[def:zfc]{\\logic{ZFC}} not containing \\( \\tau \\) nor \\( \\sigma \\) as free variables. Suppose additionally that for every \\( x \\in V_\\kappa \\) there exists a unique \\( y \\in V_\\kappa \\) such that \\( \\varphi\\Bracks{\\xi \\to x, \\eta \\to y} = T \\). These conditions ensure that \\( \\varphi \\) can be plugged into the \\hyperref[def:zfc/replacement]{axiom schema of replacement}. Define the relation\n  \\begin{equation*}\n    f \\coloneqq \\set{ (x, y) \\in V_\\kappa^2 \\given \\varphi\\Bracks{\\xi \\to x, \\eta \\to y} = T }.\n  \\end{equation*}\n\n  Then \\( f \\) is a function because of our earlier restrictions on \\( \\varphi \\). Since \\( V_\\kappa \\) is transitive and \\( A \\in V_\\kappa \\), it is sufficient to consider the restriction of \\( f\\restr_A \\) of \\( f \\). It will not be necessary to do even that since we will explicitly restrict ourselves to values of \\( f \\) on \\( A \\).\n\n  Clearly \\( f[A] \\) is a subset of \\( V_\\kappa \\) and hence \\( \\rank(f[A]) \\leq \\kappa \\). In order to show that the instance of the axiom schema of replacement with \\( \\varphi \\) holds, is sufficient to show that \\( \\rank(f[A]) < \\kappa \\).\n\n  It is clear that\n  \\begin{equation*}\n    \\card(f[A]) \\leq \\card(\\dom(f\\restr_A)) = \\card(A).\n  \\end{equation*}\n\n  From \\fullref{thm:strong_regular_cardinal_stage_cardinality} it follows that \\( \\card(A) < \\kappa \\) and since \\( \\card(f[A]) < \\kappa \\), from \\fullref{thm:regular_cardinal_stage_inverse_transitivity} it follows that \\( f[A] \\in V_\\kappa \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:universe_of_hereditary_finite_sets}\n  For this reason, \\( V_\\omega \\) is known as the \\term{universe of hereditary finite sets}.\n\n  From \\fullref{thm:aleph_zero_is_strong_limit} and \\fullref{thm:aleph_zero_is_regular} it follows that \\( \\omega = \\aleph_0 \\) is a regular strong limit cardinal. Then by \\fullref{thm:strong_regular_cardinal_stage_cardinality}, every member of \\( V_\\omega \\) is finite. Because \\( V_\\omega \\) is a transitive set, every member of every member of \\( V_\\omega \\) is also finite. So is every member of every member of every member.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:cumulative_hierarchy_model_of_zfc_without_infinity}\n  The universe of hereditary finite sets \\hyperref[def:universe_of_hereditary_finite_sets]{\\( V_\\omega \\)} is a standard model of \\logic{ZFC} without the \\hyperref[def:zfc/infinity]{axiom of infinity}.\n\\end{proposition}\n\\begin{proof}\n  From the proof of \\fullref{thm:cumulative_hierarchy_model_of_z} is follows that \\( V_\\omega \\) is a model of \\logic{ZFC} without the axiom of infinity and the axiom schema of replacement.\n\n  \\Fullref{thm:cumulative_hierarchy_model_of_zfc} shows that being a regular strong limit cardinal is sufficient for \\( V_\\omega \\) to satisfy the axiom of replacement.\n\\end{proof}\n", "meta": {"hexsha": "ba651cb955ad139668f187b822945ad145672f23", "size": 29848, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/von_neumanns_cumulative_hierarchy.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/von_neumanns_cumulative_hierarchy.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/von_neumanns_cumulative_hierarchy.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 75.1838790932, "max_line_length": 633, "alphanum_fraction": 0.6833958724, "num_tokens": 9243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866548, "lm_q2_score": 0.8376199613065411, "lm_q1q2_score": 0.7391391849958779}}
{"text": "%\\setcounter{page}{800}\n\\chapter{Advanced Integration Techniques\\label{AdvancedIntTechniques}}\nBefore introducing the more advanced techniques, we will look at\na shortcut for the easier of the substitution-type integrals.\nAdvanced integration techniques then follow:\nintegration by parts, trigonometric integrals, trigonometric\nsubstitution, and partial fraction decompositions.\n\n\\section{Substitution-Type Integration by Inspection}\nIn this section we will consider integr>als which we \nwould have done earlier by substitution, but which are\nsimple enough that we can guess the approximate form\nof the antiderivatives, and then insert any factors needed\nto correct for discrepancies detected by (mentally) computing\nthe derivative of the approximate form and comparing it to \nthe original integrand.  Some general forms will be mentioned\nas formulas, but the {\\it idea} is to be able to compute\nintegrals without resorting to writing the usual $u$-substitution\nsteps.\n\n\\bex Compute $\\ds{\\int\\cos5x\\,dx}$.\n\n\\underline{Solution}: We can anticipate that the \n{\\bf approximate form\\footnotemark} of the answer is\n$\\sin5x$, \nbut then\n$$\\frac{d}{dx}\\sin5x=\\cos5x\\cdot\\frac{d}{dx}(5x)=\\cos5x\\cdot5=5\\cos5x.$$\nSince we are looking for a function whose derivative is\n$\\cos5x$, and we found one whose derivative is $5\\cos5x$,\nwe see that our candidate antiderivative $\\sin5x$ gives\na derivative with an extra factor of $5$, compared with\nthe desired outcome.  Our candidate antiderivative's\nderivative is 5 times too large, so\nthis candidate $\\sin 5x$ must be 5 times too large.  To compensate\nand arrive at a function with the proper derivative, \nwe multiply our candidate  $\\sin5x$\nby $\\frac15$.  This give us a new candidate antiderivative $\\frac15\\sin5x$,\nwhose derivative is of course $\\frac15\\cos5x\\cdot5=\\cos5x$,\nas desired.  Thus we have\n$$\\int\\cos5x\\,dx=\\frac15\\sin5x+C.$$\n\\eex\n%%%%%  FOOTNOTE\n\\footnotetext{In this section, by {\\it approximate form} we mean\na form which is correct except for {\\bf multiplicative constants}.}\n%%%%%  END FOOTNOTE\n\nIt may seem that we wrote more in the example above than with \nthe usual $u$-substitution method, but what we\nwrote could be performed mentally without resorting to writing\nthe details.\n\nIn future sections, an integral such as the above may occur as a\nrelatively small step in the execution of a more advanced and\nmore complicated method\n(perhaps for computing a much more difficult integral).  \nThis section's purpose is to point out how such an integral can be \nquickly dispatched, to avoid it becoming a needless distraction\nin the more advanced methods.\n\nSome formulas which should be quickly verifiable by inspection\n(that is, by reading and mental computation rather than \nwith paper and pencil, for instance) follow:\n\\begin{align}\n\\int e^{kx}\\,dx&\\hphantom{-}=\\hphantom{-}\\frac1ke^{kx}+C,\\label{IntE^KX}\\\\\n\\int \\cos kx\\,dx&\\hphantom{-}=\\hphantom{-}\\frac1k \\sin kx+C,\\\\\n\\int\\sin kx\\,dx&\\hphantom{-}=-\\frac1k\\cos kx+C,\\\\\n\\int \\sec^2kx\\,dx&\\hphantom{-}=\\hphantom{-}\\frac1k\\tan kx+C,\\\\\n\\int\\csc^2kx\\,dx&\\hphantom{-}=-\\frac1k\\cot kx+C,\\\\\n\\int\\sec kx\\tan kx\\,dx&\\hphantom{-}=\\hphantom{-}\\frac1k\\sec kx+C,\\\\\n\\int\\csc kx\\cot kx\\,dx&\\hphantom{-}=-\\frac1k\\csc kx+C,\\\\\n\\int\\frac1{ax+b}\\,dx&\\hphantom{-}=\\hphantom{-}\\frac1a\\ln|ax+b|+C.\n            \\label{Int1/AX+B}\n\\end{align}\n\n\\bex The following integrals can be computed with $u$-substitution,\nbut also are computable by inspection:\n\\begin{align*}\n\\int\\frac1{5x-9}\\,dx&=\\frac15\\ln|5x-9|+C,\\\\\n\\int\\sin5x\\,dx&=-\\frac15\\cos5x+C,\\\\\n\\int\\cos\\frac{x}2\\,dx&=2\\sin\\frac{x}2+C,\\\\\n\\int\\sec^2\\pi x\\,dx&=\\frac1{\\pi}\\tan\\pi x+C,\\\\\n\\int\\csc6x\\cot6x\\,dx&=-\\frac16\\csc6x+C.\\end{align*}\n\\eex\n\nWhile it is true that we can call upon the formulas\n(\\ref{IntE^KX})--(\\ref{Int1/AX+B}), the more flexible\nstrategy is to anticipate the form of the antiderivative\nand adjust accordingly.  For instance, we have the following\nantiderivative form, written two ways:\n\\begin{align*}\n\\int \\frac{1}u\\,du&=\\ln|u|+C,\\\\\n\\int\\frac{f'(x)}{f(x)}\\,dx&=\\ln|f(x)|+C.\\end{align*}\n(As usual, the second form is the same as the first where \n$u=f(x)$.) So when we see an integrand which is a fraction,\nthe numerator being the derivative of the denominator\nexcept for multiplicative constants, we know the \nantiderivative will be, approximately, the natural \nlog of the absolute value of that denominator.\n\n\\bex Consider $\\ds{\\int\\frac{x}{x^2+1}\\,dx}$\n\nHere we see that the derivative of the denominator is also a factor\nin the integrand.\nOur candidate approximate form can then be $\\ln|x^2+1|=\\ln(x^2+1)$.\nNow we differentiate to see what we need to include to get the\ncorrect derivative:\n$$\\frac{d}{dx}\\ln(x^2+1)=\\frac1{x^2+1}\\cdot2x=2\\cdot\\frac{x}{x^2+1}.$$\nTo correct for the extra factor of 2 and thus get the correct derivative,\nwe insert the factor $\\frac12$:\n$$\\frac{d}{dx}\\left[\\frac12\\ln(x^2+1)\\right]\n =\\frac12\\cdot\\frac1{x^2+1}\\cdot2x=\\frac{x}{x^2+1},$$\nas desired.  Thus \n$$\\int\\frac{x}{x^2+1}\\,dx=\\frac12\\ln(x^2+1)+C.$$\nTo be sure, a quick (mental?) check by differentiation verifies the answer.\n\\eex\n\nOf course there are many other forms.\n\n\n\\bex Consider $\\ds{\\int\\frac1{\\sqrt{5x-9}}\\,dx}$.\n\nOf course this can be rewritten\n$\\int(5x-9)^{-1/2}\\,dx$.  Now it is crucial that a\ncomplete substitution, $u=5x-9\\implies du=5\\,dx$, etc., \nshows that $du$ and $dx$ agree except for a multiplicative\nconstant, so we know that the integral---up to multiplicative\nconstants---is of form $\\int u^{-1/2}\\,du$, which is a power rule.\n\nThe {\\it approximate} form of the antiderivative is thus\n$u^{1/2}=(5x-9)^{1/2}$,  which we write in $x$ and then differentiate,\n$$\\frac{d}{dx}(5x-9)^{1/2}=\\frac12(5x-9)^{-1/2}\\cdot5,$$\nwhich has {\\bf extra} factors (compared to our original integrand)\nof collectively  $\\frac52$. To cancel their effects we\ninclude a factor $\\frac25$ in our actual, reported  antiderivative.\nThus\n$$\\int\\frac1{\\sqrt{5x-9}}\\,dx=\\frac25(5x-9)^{1/2}+C=\\frac25\\sqrt{5x-9}+C.$$\n\\eex\n\nNote that a quick derivative computation, albeit involving a\n(simple) chain rule, gives us the correct function $1/\\sqrt{5x-9}$. \n\n\\bex Consider $\\ds{\\int 7x\\,\\sin^5x^2\\cos x^2\\,dx}$.\n\nFor such an antiderivative, our ability to guess the form \ndepends upon our exptertise with the original substitution\nmethods.  In all of these was a form $\\int f(u)\\,K\\,du$,\nwhere we could anticipate both $u$ and $f$, with $du$\naccounting for remaining terms, and $K\\in\\Re$\nwhich we can ignore by taking our shortcut path\ndescribed in this section.  Looking ahead, the student well-versed\nin substitution will expect $u=\\sin x^2$, and the integral\nbeing of the approximate form $\\int u^5\\,du$.  Thus we will\nhave an approximate antiderivative of $u^6$ (times a constant),\ni.e., the approximate form should be $\\sin^6x^2$.  Now we differentiate\nthis and see what compensating factors must be included\nto reconcile with the original integrand:\\footnotemark\n$$\\frac{d}{dx}(\\sin x^2)^6\n=6(\\sin x^2)^5\\cdot \\cos x^2\\cdot 2x\n=12x\\,\\sin^5x^2\\cos x^2.$$\nOf course we want $7$ in the place of the $12$ (or separately,\n$2\\cdot6$), so we multiply\nby $\\frac7{12}$ (or again, $7\\cdot\\frac1{6\\cdot2}$).  With this we have\n$$\\int7x\\,\\sin^5x^2\\cos x^2\\,dx=\\frac7{12}\\sin^6x^2+C.$$\n\\eex\n\\footnotetext{%%%\n%%% FOOTNOTE\nNotice that we are assuming fluency in the chain rule as we\ncompute the derivative of $\\sin^6x^2$, rather than writing out\nevery step as we did in Chapter~\\ref{DerivativeChapter}.\nEach student must gage personal ability to omit steps.\n%%% END FOOTNOTE\n}\n\n\nIt would be perfectly natural to forego this method of ``guess and\nadjust'' in favor of the old-fashioned substitution method.\nIndeed the full substitution method has some advantages (see the next\nsubsection).  For instance, it\nis more ``constructive,'' and thus\nless error-prone; one is less tempted to skip steps\nwhile employing substitution, while one might \nattempt a mental derivation of the answer here and\nthus easily be off by a factor.  \nIt is important that each student find the comfortable\nlevel of brevity for himself.\\footnote{%%\n%%% FOOTNOTE\nIt is the author's experience that students in engineering\nand physics programs are more interested in arriving at the\nanswer quickly, while mathematics and other science students prefer the\npresentation of the full substitution method.  The latter\nare somewhat less likely to be wrong by a multiplicative\nconstant, though the former tend to progress through the\ntopics faster.  There are, of course, spectacular exceptions,\nand each group benefits from camaraderie with the other.\n%%% END FOOTNOTE\n}\n\n\n\nThe method used in the above examples can be summarized as follows:\n\\begin{enumerate}\n\\item Anticipate the form of the antiderivative by an {\\it approximate form}\n      (correct up to a multiplicative constant).\n\\item Differentiate this approximate form and compare to the original\n      function (to be integrated);\n\\item If Step 1 is correct, and thus the approximate form's derivative \n      differs from the original (integrand) function by a multiplicative \n      constant, insert a compensating,\n      reciprocal multiplicative constant in the approximate form to arrive\n      at the actual antiderivative;\n\\item For verification, differentiate the answer to see if the\n      original function emerges.\n\\end{enumerate}\n\n\\bex Compute $\\ds{\\int x^3\\sin x^4\\,dx}$.\n\n\\underline{Solution}: This is of the approximate form\n$\\int\\sin u\\,du$, with $u=x^4$. The approximate form of the solution\nis thus $\\cos x^4+C$ (or $-\\cos x^4+C$, but these differ by \na multiplicative constant $-1$), which has derivative\n$-\\sin x^4\\cdot4x^3$.  We introduce a factor of $-\\frac14$\nto compensate for the extra factor of $-4$:\n$$\\int x^3\\sin x^4\\,dx=-\\frac14\\cos x^4+C,$$\nwhich can be quickly verified by differentiation.\n\\eex\n\n\\bex Compute $\\ds{\\int x\\sqrt{9-x^2}\\,dx}$.\n\n\\underline{Solution}: It is advantageous to read this\nintegral $\\int x(9-x^2)^{1/2}\\,dx$, which is of\napproximate form $\\int u^{1/2}\\,du$ (where $u=9-x^2$).  These observations,\nand the approximate form $(9-x^2)^{3/2}$ of the integral, can be \ngotten by mental observation (referred to earlier as\n``by inspection'').  Its derivative\nis $\\frac32(9-x^2)^{1/2}\\cdot(-2x)$, which\nhas an extra factor of $-3$ (after cancellation).\nThus\n$$\\int x\\sqrt{9-x^2}=-\\frac13\\left(9-x^2\\right)^{3/2}+C.$$\n\n\n\\eex\n\n\n\n\n\n\n\\subsection{Limitations of the Method}\nThere are two very important points to be made about the\nlimitiations of the method.  The first point is argued\nby making several related points, and the second is illustrated in\nan example.\n\n\\begin{enumerate}[{\\bf(I)}]\n\\item {\\bf This method can not totally replace the earlier substitution\n      method.} \n  \\begin{enumerate}[(a)]\n      \\item The skills used in the substitution method will be\n            needed for later methods.  In particular, the idea\n            that the entire integral in $x$ is replaced\n            by one in $u$ (for instance), including the $dx$\n            and, if a definite integral, the interval of integration.\n      \\item If an integral is difficult enough, the more constructive\n            substitution method is less error-prone than\n            this ``guess and adjust'' style here.\n      \\item The idea of the substitution method is the same as\n            this method; anticipating what to set equal to $u$ is\n            equivalent to guessing the approximate form of the\n            integral in $u$, and thus the approximate form of\n            the antiderivative.\n      \\item When using numerical and other methods with definite\n            integrals, a substitution can sometimes make for a\n            much simpler integral to be approximated or otherwise \n            analyzed, even if the antiderivative is never computed. \n            For instance, with $u=x^2$, giving then $du=2x\\,dx$, we can write\n            $$\\int_{-1}^2 xe^{x^4}\\,dx=\\frac12\\int_{1}^4e^{u^2}\\,du.$$\n       \\end{enumerate}\n\\item {\\bf It is imperative that the derivative of the approximate form\ndiffers from the original function to be integrated by at most a\n{multiplicative constant}.}  In particular, an extra\nvariable function cannot be compensated for.  \n\\end{enumerate}\nTo illustrate this point, and simultaneously warn against a \ncommon mistake, consider \n$$\\int\\frac1{x^2+1}\\,dx.$$\nThe mistake to avoid here is to take the approximate solution to be\n$\\ln(x^2+1)$, which we then notice has derivative\n$$\\frac{d}{dx}\\ln(x^2+1)=\\frac1{x^2+1}\\cdot2x.$$\nUnfortunately we cannot compensate by dividing by \nthe extra factor $2x$, because\\footnotemark\n$$\\frac{d}{dx}\\left[\\frac{\\ln(x^2+1)}{2x}\\right]=\n\\frac{2x\\cdot\\frac{d\\ln(x^2+1)}{dx}-\\ln(x^2+1)\\cdot\\frac{d(2x)}{dx}}{(2x)^2},$$\nwhich is guaranteed (by the presence of the logarithm in\nthe result) to be something other than our original \nfunction $\\frac1{x^2+1}$.  The method does not work because multiplicative\n{\\it functions} do not ``go along for the ride'' in derivative (or \nantiderivative) problems the way multiplicative constants do.\n%%% FOOTNOTE\n\\footnotetext{Alternatively, a product rule computation can be used:\n$$\\frac{d}{dx}\\left[\\frac1{2x}\\ln(x^2+1)\\right]\n=\\frac1{2x}\\cdot\\frac{d\\ln(x^2+1)}{dx}+\n  \\ln(x^2+1)\\cdot\\frac{d}{dx}\\left[\\frac1{2x}\\right],$$\nwhich eventually gives the original function for the first product, but \nthe second part of the product rule is a complication\nwe cannot rid ourselves of easily.\n\nIt should be pointed out that the method of the next section\ndoes utilize the fact that the first product above is\nthe desired original function, and an algorithm can be fashioned\nto compensate for the presence of the second product.  The application of \nthat method is not universally useful, and even \nwhen it is helpful \nit takes considerable work to develop the theory as well as\nfluency in its application.\n%%% END FOOTNOTE\n}\n\nOf course we knew from before that \n$$\\int\\frac1{x^2+1}\\,dx=\\tan^{-1}x+C,$$\nso this integral is not really suitable for a substitution argument, \nbut is rather a special case in and of itself.  \n\n\n\n\n\n\n\n\n\n\n\n\\newpage\n\\section{Integration By Parts\\label{IntByPartsSection}}\n\nWhile integration by substitution in its elementary form\ntakes advantage of the chain rule, by contrast integration by\nparts exploit the product rule. The application is a bit\nmore complicated than with substitution, and there are \nperhaps more variations on the theme than with substitution.\nFurthermore, to be truly fluent in this method requires one to be able\nto see more steps ahead than with substitution, as the method\nis arguably twice as long and complicated as most substitution\nproblems.  Still, it can be similarly mastered with practice.\n\n\\subsection{The Idea by an Example\\label{IntByPartsSubsec''TheIdea''}}\nSuppose that we need to find an antiderivative of the function\n$f(x)=x\\sec^2 x$.  It is not hard to see that normal substitution\nin not going to easily yield our desired antiderivative $F$:\n$$\\int x\\sec^2x\\,dx=F(x)+C.$$  \nHowever, a clever student might notice that $x\\sec^2 x$\ncontains terms that could have arisen from\na product rule derivative computation:\n\\begin{align*}\\frac{d}{dx}\\left[x\\tan x\\right]\n  &=x\\cdot\\frac{d\\tan x}{dx}+\\tan x\\cdot\\frac{dx}{dx}\\\\\n  &=x\\sec^2x+\\tan x.\\end{align*}\nIf we rearrange the terms above, we can summarize as follows:\n$$x\\sec^2x=\\frac{d}{dx}\\left[x\\tan x\\right]-\\tan x.$$\nIn fact the line immediately\nabove is perhaps where the spirit of the method is\nmost on display:  that the given function is indeed one {\\it part}\nof a product rule derivative.  If we are fortunate, the other\n{\\it part} of the product rule formula is easier to integrate,\nbecause the derivative term, namely $\\frac{d}{dx}\\left[x\\tan x\\right]$\nis trivial to integrate, since we are just asking for the antiderivative\nof the derivative of a (differentiable) function, which ultimately \nreturns the function itself, and an additive constant we can absorb\nin the second integral.\nIndeed, if we take antiderivatives of both sides, we then get\n\\begin{align*}\\int x\\sec^2x\\,dx&=\\int\\left[\\left(\\frac{d[x\\tan x]}{dx}\\right)\n               -\\tan x\\right]\\,dx\\\\\n             &=x\\tan x-\\int\\tan x\\,dx\\\\\n             &=x\\tan x-\\ln|\\sec x|+C.\\end{align*}\nFrom such as the above emerges a method whereby we identify\nour given function (here $x\\sec^2x$) as a {\\it part} of a product rule \ncomputation ($\\frac{d}{dx}[x\\tan x]$),\nand integrate our original function by instead (trivially) integrating the\nproduct rule derivative term (again $\\frac{d}{dx}[x\\tan x]$), \nand then integrating the other {\\it part} ($\\tan x$)\nof the product rule output.  Often the other, hidden part of the\nunderlying product rule is easier to integrate than the original\nfunction, and therein lies much of the success of the method.\n\n\n\\subsection{The Technique In Its Simpler Applications}\nRecall that when we completely developed the substitution method, \nthe underlying \nprinciple---the chain rule---was not written out in complete\nderivative form, but rather in {\\it differential} form.\nThat was partly because of the compactness of the differential\nnotation.  Having supposed that $F$ was an antiderivative of $f$,\nwe eventually settled on writing the argument below without\nthe first two integrals:\n$$\\int f(u(x))u'(x)\\,dx=\\int f(u(x))\\cdot\\frac{du(x)}{dx}\\,dx\n =\\int f(u)\\,du=F(u)+C=F(u(x))+C.$$\nAt first we did write the first steps because the proof was in the chain\nrule: $\\frac{d}{dx}F(u(x))=F'(u(x))u'(x)=f(u(x))u'(x).$\nHowever, we eventually opted for the differential form, though for\nmost it takes some practice.  We will adopt differential notation\nin integration by parts as well.  For instance, recall the \nproduct rule can be rewritten in differential form:\n\\begin{equation}\nd(uv)=u\\,dv+v\\,du.\\label{ProdRuleInDifferentialsForParts}\n\\end{equation}\nOf course this came from multiplying a derivative product rule\nby, say, $dx$, assuming $u$ and $v$ are in fact functions of $x$:\n$$\\frac{d(uv)}{dx}=u\\cdot\\frac{dv}{dx}+v\\cdot\\frac{du}{dx}.$$\nNow we rearrange (\\ref{ProdRuleInDifferentialsForParts}) as follows:\n\\begin{equation}\nu\\,dv=d(uv)-v\\,du.\\label{Rearr.ProdRuleInDifferentialsForParts}\n\\end{equation}\nEquation (\\ref{Rearr.ProdRuleInDifferentialsForParts}) is perhaps\nthe best equation to visualize the principle behind the eventual\nintegration formula, because it is an easy step from the product rule.\nThe actual formula quoted in most textbooks is still two steps away.\nFirst we integrate both sides:\n\\begin{equation}\\int u\\,dv=\\int d(uv)-\\int v\\,du.\n\\label{OneStepBeforeIntByParts}\\end{equation}\nNext we  notice that the first integral on the right hand side of \n(\\ref{OneStepBeforeIntByParts}) is simply $uv$, and so we arrive\nat our final working formula for our integration by parts technique:\n\\begin{equation}\n\\boxed{\\int u\\,dv=uv-\\int v\\,du.}\\label{IntByPartsFormula}\\end{equation}\nMost textbooks and instructors use the formula above in exactly that\nform.  It is best memorized, though its derivation---particuarly\nfrom (\\ref{Rearr.ProdRuleInDifferentialsForParts})---should\nnot be forgotten.  \n\nNext we look at an example of the actual application of\n(\\ref{IntByPartsFormula}).  In the example below, the arrangement of terms\nis as one would work the problem with pencil and paper, except for\nthe implication arrows and the underbraces (which we explain briefly below,\nand exclude from then on).\n\n\\bex Compute $\\ds{\\int xe^x\\,dx}$.\n\n\\underline{Solution}:\n\\begin{alignat*}{3}\nu&=x&&\\qquad\\qquad& dv&=e^x\\,dx\\\\\n&\\Downarrow&&&&\\Uparrow\\\\\ndu&=dx&&&v&=e^x\n\\end{alignat*}\n$$\\int\\underbrace{x}_{u}\\ \\underbrace{e^x\\,dx}_{dv}\n=uv-\\int v\\,du\n=(x)(e^x)-\\int(e^x)\\,dx\n=xe^x-e^x+C.$$\n\\eex\n It is interesting to note\nthat we {\\it choose} $u$ and $dv$, and then {\\it compute}\n$du$ and $v$, with one qualification.  That is that\n$v$ is not unique;  the computation from $dv$ to $v$ is\nof an antidifferentiation nature and so we really only know $v$\nup to an additive constant.  In fact {\\it any} $v$ so that $dv=e^x\\,dx$\n(we took $v=e^x\\implies dv=e^x\\,dx$)\nwill work in (\\ref{IntByPartsFormula}).  Any additive constant,\nwhile legitimate, will eventually cancel in the final computation.\nFor instance, if we had chosen $v=e^x+100$, we would have had\n\\begin{align*}\nuv-\\int v\\,du&=x(e^x+100)-\\int(e^x+100)\\,dx\\\\\n               &=xe^x+100x-e^x-100x+C\\\\\n              &=xe^x-e^x+C,\n\\end{align*}\nas before.  For most cases, we will just assume that the additive\nconstant is zero and we will use the simplest antiderivative for $v$.\n(We will not continue to write the implication arrows as they \nare technical and perhaps confusing.)\n\nNow we will revisit the example we gave in\nSubsection~\\ref{IntByPartsSubsec''TheIdea''}, using what will be our\nbasic style for this method.\n\n\\bex Compute $\\ds{\\int x\\sec^2x\\,dx}$.\n\n\\underline{Solution}:\n\\begin{alignat*}{3}\nu&=x&&\\qquad\\qquad&dv&=\\sec^2x\\,dx\\\\\ndu&=dx&&&v&=\\tan x\n\\end{alignat*}\n$$\n\\int x\\sec^2x\\,dx =\\int u\\,dv\n=uv-\\int v\\,du=x\\tan x-\\int\\tan x\\,dx=x\\tan x-\\ln|\\sec x|+C.$$\n\\eex\nSince this method is more complicated than substitution, there\nare more complicated considerations in how to\napply it. First of course, one should attempt an\nearlier, simpler method.  But if those fail, and integration\nby parts is to be attempted,\\footnote{%%%\n%%% FOOTNOTE\nOf course with practice one can see ahead whether or not integration by\nparts is likely to achieve an answer for a particular integral.}\n the following guidelines for choosing $u$ and $dv$\nshould be considered:\n\\begin{enumerate}\n\\item $u$ and $dv$ {\\bf must} account for exactly all factors of \n      the integral.\n  \\begin{enumerate}[1.5.]\n  \\item Of course, \n        $dv$ {\\bf must} contain the differential term (for example, $dx$)\n      as a factor,\n      but can contain more terms.\\end{enumerate}\n\\item $v=\\int dv$ should be computable with relative ease.\n\\item $du=u'(x)\\,dx$ (assuming the original integral was in $x$)\n      should not be overly complicated.\n\\item The integral $\\int v\\,du$ should be simpler than the original\n      integral $\\int u\\,dv$.\\footnote{%%%%\n%%% FOOTNOTE\nLater, in a twist on the method,\nwe will see that the we do not necessarily require\n$\\int v\\,du$ be easier than the original,  $\\int u\\,dv$.%\n%%% END FOOTNOTE\n}\n\\end{enumerate}\nThe next example illustrates the importance of the second consideration\n(numbered 2.) above.\n\n\\newpage\n\\bex Compute $\\ds{\\int x^3\\sin x^2\\,dx}$.\n\n\\underline{Solution}: \nWe  do not want to make $u=\\sin x^2$, because \nthen $dv=x^3\\,dx$, giving $du=2x\\cos x^2$ and $v=\\frac14x^4$,\nand our $\\int v\\,du$ will be $\\int\\frac12x^5\\cos x^2\\,dx$,\nwhich is worse than our original integral.\n\nWe will instead take $u$ to be some power of $x$,\nbut not all of $x^3$, else the terms remaining for $dv$\nwould be $dv=\\sin x^2\\,dx$, which we cannot integrate with ordinary\nmethods.\\footnote{%%% \n%%% FOOTNOTE\nIn fact, we cannot compute $\\int\\sin x^2\\,dx$ using any kind of\nsubstitution or parts, or any other method of this text for that\nmatter, and arrive at an antiderivative in simple terms of the\nfunctions we know so far such as powers, exponentials, logarithms,\ntrigonometric or hyperbolic functions or their inverses.  \nHowever, when we\nstudy series we will find other expressions with which we can\nfashion an antiderivative of $\\sin x^2$.%%\n%%% END FOOTNOTE\n}\n\n\n\nWhat we will settle on is $dv=x\\sin x^2\\,dx$, for its integral\nis an easy substitution.  We leave the remaining terms, $x^2$,\nfor $u$:\n\\begin{alignat*}{3}\nu&=x^2&&\\qquad\\qquad&dv&=x\\sin x^2\\,dx\\\\\ndu&=2x\\,dx&&&v&=-\\frac12\\cos x^2\\end{alignat*}\n\\begin{align*}\n\\int x^3\\sin x^2\\,dx&=\\int \\underbrace{x^2}_{u}\n                       \\cdot \\underbrace{x\\sin x^2\\,dx}_{dv}\\\\\n                    &=uv-\\int v\\,du\\\\\n                    &=(x^2)\\left(-\\frac12\\cos x^2\\right)\n                        -\\int\\left(-\\frac12\\cos x^2\\right)2x\\,dx\\\\\n                    &=-\\frac{x^2}{2}\\cos x^2+\\frac12\\int \\cos x^2\\cdot x\\,dx\\\\\n                    &=-\\frac{x^2}{2}\\cos x^2+\\frac12\\sin x^2+C.\n\\end{align*}\nWe omitted the details of computing $v$ from $dv$, and computing the\nlast integral, as most students at this point can anticipate the\napproximate forms of those antiderivatives, mentally compute\nthe derivatives of the approximate forms, and then insert constant factors\nrequired to make the antiderivatives correct.  (This was \nthe purpose of the last section.)\n\\eex\n\nThis last example shows how the requirement that $v=\\int dv$ (up\nto an additive constant) be computable helps to guide us to \nthe proper choice of $u$ and $dv$.  It was lucky that the second integral\nwas easily computable (which would not have been the case\nif the original integral were, say, $\\int x^2\\sin x^2\\,dx$\nor $\\int x^4\\sin x^2\\,dx$), but anyhow we cannot even get\nto the second integral if we cannot compute $v$.\n\n The next example shows a different lesson:\nthat it is sometimes appropriate to integrate by parts more than once\nin a given problem.\n\n\\bex Compute $\\ds{\\int x^2\\cos 3x\\,dx}$.\n\n\\underline{Solution}: For reasons that will be clear later, \nwe will call this integral $\\I$.  Now we proceed to the \nintegration by parts.\n\\begin{alignat*}{3}\nu&=x^2&&\\qquad\\qquad&dv&=\\cos3 x\\,dx\\\\\ndu&=2x\\,dx&&&v&=\\frac13\\sin3x\\end{alignat*}\n$$\\I=\\int \\underbrace{x^2}_{u}\\underbrace{\\cos 3x\\,dx}_{dv}\n=uv-\\int v\\,du\n=\\frac13x^2\\sin 3x-\\int\\frac23x\\sin3x\\,dx.\n$$\nWhile we still cannot compute this last integral directly with old methods,\nit is better than the original in the sense that\nour trigonometric function is multiplied by a first-degree polynomial,\nwhere in the original the polynomial was second degree.\nThe work which is left more closely resembles our earliest examples\nof integration by parts.  \n\nA strict use of the language would force us to introduce\ntwo new variables other than $u$ and $v$, but since they\nhave ``disappeared'' in the present form of our answer,\nnamely $\\frac13x^2\\sin3x-\\frac23\\int x\\sin3x\\,dx$, it is\nnot considered such bad form to ``reset'' (or ``recycle'') $u$ and $v$\nfor another integration by parts step, this time \ninvolving the integral $\\int x\\sin 3x\\,dx$:\n\\begin{alignat*}{3}\nu&=x&&\\qquad\\qquad&dv&=\\sin3x\\,dx\\\\\ndu&=dx&&&v&=-\\frac13\\cos3x\\end{alignat*}\n$$\\int \\underbrace{x}_{u}\\underbrace{\\sin3x\\,dx}_{dv}\n=uv-\\int v\\,du\n=-\\frac{x}3\\cos3x+\\frac13\\int\\cos3x\\,dx\n=-\\frac{x}3\\cos3x+\\frac13\\cdot\\frac13\\sin 3x+C_1.$$\nNow we insert this last result into our original computation:\n\\begin{align*}\n\\int x^2\\cos3x\\,dx&=\\frac{x^2}3\\sin3x-\\frac23\\left[-\\frac{x}3\\cos3x\n           +\\frac19\\sin3x+C_1\\right]\\\\\n  &=\\frac{x^2}3\\sin3x+\\frac{2}{9}x\\cos3x-\\frac2{27}\\sin3x+C.\\end{align*}\n\\eex\n\nSeveral lessons can be gleaned from the example above.  (1)\nit is very important for proper ``bookkeeping,'' as these\nproblems can beget several ``subproblems,'' and the proper\nplacement of resulting terms is crucial to getting the correct answer;\n(2) it is not unknown to use integration by parts more\nthan once in a problem; (3) if we can take as many \nantiderivatives of a function $f(x)$ as we like\n(i.e., the antiderivative, the antiderivative of the\nantiderivative, etc.), then for an integral\n$\\int x^nf(x)\\,dx$ we can let $u=x^n$, and integration\nby parts will yield a second integral with a reduction\nin the power of $x$, namely \n\\begin{equation}\n\\int x^nf(x)\\,dx=x^nF(x)-\\int nx^{n-1}F(x)\\,dx\\end{equation}\nwhere $F'=f$. \n\nOther cases concern choices of $u$ where we choose a \nfunction whose derivative we know, but whose antiderivative\nmight not be standard knowledge for the average student.\n\\bex Compute $\\ds{\\int(x^2+1)\\ln x\\,dx}$.\n\n\\underline{Solution}: We cannot let $dv=\\ln x\\,dx$, since\nas yet we do not know the antiderivative of $\\ln x$.\n(Even if we did, such a choice for $dv$ would not be advantageous,\nas Example~\\ref{ComputingIntLnXExample} helps to show.)\nSo we have little choice but to let $\\ln x$ be $u$.\n\\begin{alignat*}{3}\nu&=\\ln x&&\\qquad\\qquad&dv&=(x^2+1)\\,dx\\\\\ndu&=\\frac1x\\,dx&&&v&=\\frac{x^3}3+x\\end{alignat*}\n\\begin{align*}\n\\int(x^2+1)\\ln x\\,dx&=uv-\\int v\\,du\\\\\n                    &=(\\ln x)\\left(\\frac{x^3}3+x\\right)\n                     -\\int\\left(\\frac{x^3}3+x\\right)\\frac1x\\,dx\\\\\n               &=\\frac13(\\ln x)(x^3+3x)-\\int\\left(\\frac{x^2}3+1\\right)\\,dx\\\\\n            &=\\frac13(x^3+3x)\\ln x-\\frac19x^3-\\frac13x+C.\n                   \\end{align*}\n\\label{IntPoly*LnExample}\\eex\n\n\n\n\n\n\\subsection{A Simple Twist on the Method}\nHere we show how to find antiderivatives of interesting functions\nwhose derivatives we already know.  \n\\bex Compute $\\ds{\\int \\ln x\\,dx}$.\n\n\\underline{Solution}: Here we cannot let $dv=\\ln x\\,dx$, for\ncomputing $v=\\int dv$ would be the same as computing the whole,\noriginal integral.  As in Example~\\ref{IntPoly*LnExample},\nwe also note that placing $\\ln x$ in the $u$-term makes for\na simpler derivative.  Thus we write\n\\begin{alignat*}{3}\nu&=\\ln x&&\\qquad\\qquad&dv&=dx\\\\\ndu&=\\frac1x\\,dx&&&v&=x,\\end{alignat*}\nso that\n\\begin{align*}\n\\int \\ln x\\,dx&=uv-\\int v\\,du\\\\\n              &=(\\ln x)(x)-\\int(x)\\left(\\frac1x\\,dx\\right)\\\\\n              &=x\\ln x-\\int 1\\,dx\\\\\n              &=x\\ln x-x+C.\\end{align*}\n\\label{ComputingIntLnXExample}\\eex\nIn fact the same type of computation will be used for \nfinding antiderivatives of arctrigonometric functions.\n\n\\bex Compute $\\ds{\\int\\sin^{-1}x\\,dx}$.\n\n\\underline{Solution}: Again we have no choice but to let $u=\\sin^{-1}x$,\n$dv=dx$.\n\\begin{alignat*}{3}\nu&=\\sin^{-1}x&&\\qquad\\qquad&dv&=dx\\\\\ndu&=\\frac1{\\sqrt{1-x^2}}\\,dx&&&v&=x\\end{alignat*}\nFor brevity, we will begin to label the desired integral $\\I$,\nso here $\\I=\\int\\sin^{-1}x\\,dx$.\n(The second interval is computed ``by inspection.'')\n\\begin{align*}\n\\I=uv-\\int v\\,du&=x\\sin^{-1}x-\\int\\frac{x}{\\sqrt{1-x^2}}\\,dx\\\\\n                &=x\\sin^{-1}x+\\left(1-x^2\\right)^{1/2}+C.\\end{align*}\n\n\\eex\n\n\n\\newpage\n\\subsection{An Indirect Method}\nThe following method, which we describe in the end, is\nuseful in surprisingly many settings.\n\\bex Compute $\\ds{\\int e^{2x}\\cos3x\\,dx=\\I}$.\n\n\\underline{Solution}: Here we again name the desired integral\n$\\I$ for brevity in later steps.\n\nIt should be obvious (especially after a\nfew attempts) that simple substitution methods will not work.\nSo we attempt an integration by parts.\n\\begin{description}\n\\item[Step 1.]  We will let the trigonometric function be part of $dv$:\n\\begin{alignat*}{3}\nu&=e^{2x}&&\\qquad\\qquad&dv&=\\cos3x\\,dx\\\\\ndu&=2e^{2x}\\,dx&&&v&=\\frac13\\sin3x\n\\end{alignat*}\nSo far, after some rearrangement and simplifying, we have\n\\begin{align}\\I&=uv-\\int v\\,du\\notag\\\\\n&=\\frac13e^{2x}\\sin3x-\\frac23\n\\underbrace{\\int e^{2x}\\sin 3x\\,dx}_{\\II}.\\label{(I)Step1}\\end{align}\nThis does not seem any easier than the first integral, so \nperhaps we might continue, but this time let the trigonometric \nfunction\nbe $u$ and the exponential (along with $dx$) be contained in $dv$.\n\\item[Step 2.] Compute $\\II=\\int e^{2x}\\sin3x\\,dx$ \n in light of the comments at the end of the first step.\n\\begin{alignat*}{3}\nu&=\\sin3x&&\\qquad\\qquad&dv&=e^{2x}\\,dx\\\\\ndu&=3\\cos3x\\,dx&&&v&=\\frac12e^{2x}\\end{alignat*}\n$$\\II=uv-\\int v\\,du=\\frac12e^{2x}\\sin3x-\\frac32\\int e^{2x}\\cos3x\\,dx.$$\nCombining this with the conclusion (\\ref{(I)Step1}) of Step 1 gives us:\n\\begin{align*}\n\\I&=\\frac13e^{2x}\\sin3x-\\frac23\\left[\n        \\frac12e^{2x}\\sin3x-\\frac32\\int e^{2x}\\cos3x\\,dx\\right]\\\\\n  &=\\frac13e^{2x}\\sin3x-\\frac13e^{2x}\\sin3x+\\int e^{2x}\\cos3x\\,dx\\\\\n  &=\\int e^{2x}\\cos3x\\,dx.\n\\end{align*}\n\\end{description}\nUnfortunately that puts us right back where we started.\nHowever, a minor change in our effort above will eventually lead us to \nthe solution.  While keeping Step 1,\nour next step towards a solution is to replace Step 2\nby the same strategy as used in Step 1, namely that we \nuse the exponential function for $u$ and the trigonometric with  $dv$.\n\\begin{description}\n\\item[Step 2---Second Attempt] Again we compute $\\II=\\int e^{2x}\\sin3x\\,dx$:\n\\begin{alignat*}{3}\nu&=e^{2x}&&\\qquad\\qquad&dv&=\\sin3x\\,dx\\\\\ndu&=2e^{2x}\\,dx&&&v&=-\\frac13\\cos3x\\end{alignat*}\n\\begin{align}\n\\II&=uv-\\int v\\,du\\notag\\\\\n   &=-\\frac13e^{2x}\\cos3x+\\frac23\\int e^{2x}\\cos3x\\,dx.\n   \\label{(II)Step2'}\\end{align}\nIt may seem that (\\ref{(II)Step2'}) is also a dead end,\nsince it contains the original integral. But this\nattempt is different. In fact,\nwhen we combine (\\ref{(II)Step2'}) with (\\ref{(I)Step1}) we get\n\\begin{align*}\n\\I&=\\frac13e^{2x}\\sin3x-\\frac23\\II\\\\\n  &=\\frac13e^{2x}\\sin3x-\\frac23\\left[-\\frac13e^{2x}\\cos3x\n                                 +\\frac23\\int e^{2x}\\cos3x\\,dx\\right]\\\\\n  &=\\frac13e^{2x}\\sin3x+\\frac29e^{2x}\\cos3x-\\frac49\n\\underbrace{\\int e^{2x}\\cos3x\\,dx}_{\\I},\n\\end{align*}\nwhich we can summarize by the following equation:\n\\begin{equation}\n\\I=\\frac13e^{2x}\\sin3x+\\frac29e^{2x}\\cos3x-\\frac49\\I.\n\\label{EquationToBeSolvedToFindI}\n\\end{equation}\nNow we are ready to derive $\\I$, not by another calculus computation,\nbut in fact by simple algebra.\n\\item[Step 3.] Solve (\\ref{EquationToBeSolvedToFindI}) for $\\I$.\nFirst we add $\\frac49\\I$ to both sides.\n$$\\frac{13}{9}\\I=\\frac13e^{2x}\\sin3x+\\frac29e^{2x}\\cos3x+C_1.$$\nHere we add $C_1$ because in fact each $\\I$ in \n(\\ref{EquationToBeSolvedToFindI}) represents\nall antiderivatives which of course differ from eachother by\nadditive constants.  Now (\\ref{EquationToBeSolvedToFindI})\nmakes sense because of the fact that there are additive constants on both\nsides of that equation (though on the right side they are \nmulitplied by $-\\frac49$, but that still yields additive constants).\\footnote{%\n%%% FOOTNOTE\nIn fact, two simlutaneous appearances of $\\I$ do not have to have\nthe same additive constants, so $\\I-\\I=C_2$, not zero.%\n%%%% END FOOTNOTE\n}  \nSolving for $\\I$ we now have\n\\begin{align}\n\\I&=\\frac9{13}\\left[\\frac13e^{2x}\\sin3x+\\frac29e^{2x}\\cos3x+C_1\\right]\\notag\\\\\n&=\\frac3{13}e^{2x}\\sin3x+\\frac2{13}e^{2x}\\cos3x+C,\n\\end{align}\nwhere $C=\\frac9{13}C_1$.\n\\end{description}\n\\label{ExampleIntEx(2x)Sin3x;SolveFor(I)}\\eex\n\nWhat is important to understand about the example above is that sometimes,\nthough we cannot perhaps directly compute a particular integral, it may\nhappen that an indirect method gives us the answer.  Here we found an\nequation, namely (\\ref{EquationToBeSolvedToFindI}), which our desired\nintegral satisfies, and for which it could be solved algebraically.\nWe must be open to the possibility of finding a desired quantity\nby indirect methods, as well as direct computations.\n\nIt should be pointed out that we could have computed the integral\nin Example~\\ref{ExampleIntEx(2x)Sin3x;SolveFor(I)} by instead\nletting $u$ be the trigonometric function, and $dv=e^{2x}\\,dx$\nin {\\it both} steps.  In fact it is usually best to pick similar\nchoices for $u$ and $dv$ when an integration by parts will take\nmore than one step.  (Recall the discussion for $\\int x^nf(x)\\,dx$.)\n\nThe method of Example~\\ref{ExampleIntEx(2x)Sin3x;SolveFor(I)},\nnamely solving for $\\I$ after an integration by parts step, \nis available perhaps more often than one would think.\n\n\\bex Compute $\\ds{\\int \\sin^2x\\,dx=\\I}$.\n\n\\underline{Solution}:\n\\begin{alignat*}{3}\nu&=\\sin x&&\\qquad\\qquad&dv&=\\sin x\\,dx\\\\\ndu&=\\cos x\\,dx&&&v&=-\\cos x\n\\end{alignat*}\n$$\\I=\\int uv-\\int v\\,du=-\\sin x\\cos x+\\int\\cos^2x\\,dx.$$\nWe could perform the same integration by parts with the second\nintegral, but instead we will use the fact that $\\cos^2x=1-\\sin^2x$:\n\\begin{align*}\\I&=-\\sin x\\cos x+\\int(1-\\sin^2x)\\,dx\\\\\n                &=-\\sin x\\cos x+x-\\int\\sin^2x\\,dx\\\\\n                &=x-\\sin x\\cos x-\\I.\\end{align*}\nHere we see that we can add $\\I$ to both sides, divide by $2$ and get\n$$\\I=\\frac12(x-\\sin x\\cos x)+C.\\footnotemark$$\n\\footnotetext{%%\n%%%% FOOTNOTE\nThe intermediate step would be \n  $2\\I=x-\\sin x\\cos x+C_1$.  See the discussion\nfor Example~\\ref{ExampleIntEx(2x)Sin3x;SolveFor(I)},\npage~\\pageref{ExampleIntEx(2x)Sin3x;SolveFor(I)}.\n\nIn fact many textbooks do not bother writing the $C_1$ term, preferring\nto remind the student at the end that an indefinite integral problem \nnecessitates a ``$+C.$''%\n%%% END FOOTNOTE\n}\\label{FirstPartsIntegrationOfSinSquaredX}\n\\eex\n\nThe example above can be computed directly if we use the trigonometric fact\nthat $\\sin^2x=\\frac12(1-\\cos 2x)$, giving\n\\begin{align*}\\int\\sin^2x\\,dx&=\\int\\frac12(1-\\cos2x)\\,dx\\\\\n        &=\\frac12x-\\frac14\\sin2x+C\\\\\n        &=\\frac12x-\\frac14\\cdot2\\sin x\\cos x+C,\\end{align*}\nwhich is the same as before.  \nFor the last step we used the (double-angle)\ntrigonometric identity $\\sin2x=2\\sin x\\cos x$.\nIn Section~\\ref{TrigIntsSection} we will opt for\nthis alternative method, and indeed will make quite an\neffort to exploit the algebraic properties of the trignometric\nfunctions wherever possible, but some integrals there will\nalso {\\it require} integration by parts.\n\n\n\n\n\n\n\\subsection{Miscellaneous Considerations}\nFirst we look at a definite integral arising from integration by\nparts.  It should be pointed out that the general formula\nwill look like the following:\\footnotemark\n\\begin{equation}\n\\int_{x=a}^{x=b}u\\,dv=\\left.\\vphantom{\\frac11}uv\\right|_{x=a}^{x=b}\n-\\int_{x=a}^{x=b}v\\,du.\\label{PartsForDefIntsEq}\\end{equation}\n\\footnotetext{%\n%%% FOOTNOTE\nSome texts leave out the ``$x=$'' parts, assuming they are \nunderstood, but we will continue to use the convention that,\nunless otherwise stated, the ``limits of integration''\nshould match the differential's variable.  Another popular way\nto write (\\ref{PartsForDefIntsEq}) avoids the issue:\n$$\\int_a^b u(x)v'(x)\\,dx=\\left.\\vphantom{\\frac11}u(x)v(x)\\right|_a^b\n   -\\int_a^bv(x)u'(x)\\,dx.$$\n%%% END FOOTNOTE\n}\n\\bex Compute $\\ds{\\int_{-\\pi}^{\\pi}x\\sin x\\,dx}$.\n\n\\underline{Solution}:\n(Note how the negative signs cancel in the parts formula step.)\n\\begin{alignat*}{3}\nu&=x&&\\qquad\\qquad&dv&=\\sin x\\,dx\\\\\ndu&=dx&&&v&=-\\cos x\\end{alignat*}\n\\begin{align*}\n\\int_{-\\pi}^{\\pi}x\\sin x\\,dx\n  &=\\left.\\vphantom{X_X^X}(-x\\cos x)\\right|_{-\\pi}^{\\pi}\n    +\\int_{-\\pi}^{\\pi}\\cos x\\,dx\\\\\n  &=[-\\pi\\cos\\pi]-[-(-\\pi)\\cos(-\\pi)]+\\left.\n   \\vphantom{\\frac11}\\sin x\\right|_{-\\pi}^{\\pi}\\\\\n  &=(-\\pi)(-1)-(\\pi)(-1)+\\sin\\pi-\\sin(-\\pi)\\\\\n  &=\\pi+\\pi+0-0\\\\\n  &=2\\pi.\\end{align*}\n\\eex\n\nIn the example above,\nWe could also have  noticed that $\\int_{-\\pi}^{\\pi}\\cos x\\,dx$\nis zero because we are integrating over a whole period \n$[-\\pi,\\pi]$ of $\\cos x$, and both $\\sin x$ and $\\cos x$\nhave definite integral zero over any full period.\n\nIt is typical to compute that part $\\left.\\vphantom{\\frac22}\n  u(x)v(x)\\right|_{z}^b$ separately, but one could instead and\nseparately compute the entire antiderivative, and then \nevaluate at the two limits and take the difference:\n$$\\int_{-\\pi}^{\\pi} x\\sin x\\,dx\n=\\left.\\vphantom{\\frac11}\\left(-x\\cos x+\\sin x\\right)\\right|_{-\\pi}^{\\pi}.$$\nWhich method to use is a matter of bookkeeping preferences,\nand perhaps whether or not part of the \nright-hand side of (\\ref{PartsForDefIntsEq}) is particularly simple.\n\n\nThe next example gives us several options along the way, though\nin each the original choices of $u$ and $dv$ are the same.\n\\bex Compute $\\ds{\\int x\\tan^{-1}x\\,dx=\\I}$.\n\n\\underline{Solution}: Again we have little choice on our selection of\n$u$ and $dv$.\n\\begin{alignat*}{3}\nu&=\\tan^{-1}x&&\\qquad\\qquad&dv&=x\\,dx\\\\\ndu&=\\frac1{x^2+1}\\,dx&&&v&=\\frac12x^2\n\\end{alignat*}\n\\begin{align*}\n\\I&=uv-\\int v\\,du\\\\\n  &=\\frac12x^2\\tan^{-1}x-\\frac12\\int\\frac{x^2}{x^2+1}\\,dx.\\end{align*}\nNow this last integral can be found by rewriting\nthe integrand using either polynomial long division, or \nby a little cleverness:\n$$\\frac{x^2}{x^2+1}=\\frac{x^2+1-1}{x^2+1}=\\frac{x^2+1}{x^2+1}\n                       -\\frac1{x^2+1}=1-\\frac1{x^2+1}.$$\nThus\n\\begin{align*}\n\\I&=\\frac12x^2\\tan^{-1}x-\\frac12\\int\\left(1-\\frac1{x^2+1}\\right)\\,dx\\\\\n &=\\frac12x^2\\tan^{-1}x-\\frac12x+\\frac12\\tan^{-1}x+C.\\end{align*}\n\nThough our choice of $u$ and $dv$ was limited, \nour choice of $v$ was not as limited.  Recall that we could have\nchosen any $v=\\frac12x^2+C_1$.  In this particular integral, \nwe could have saved ourselves some effort if we had chosen\n$v$ more strategically:\n\\begin{alignat*}{3}\nu&=\\tan^{-1}x&&\\qquad\\qquad&dv&=x\\,dx\\\\\ndu&=\\frac1{x^2+1}\\,dx&&&v&=\\frac12\\left(x^2+1\\right)\\end{alignat*}\nThis gives\n\\begin{align*}\n\\I&=uv-\\int v\\,du\\\\\n  &=\\frac12\\left(x^2+1\\right)\\tan^{-1}x-\\int\\frac{\\frac12(x^2+1)}{x^2+1}\\,dx\\\\\n  &=\\frac12\\left(x^2+1\\right)\\tan^{-1}x-\\int\\frac12\\,dx\\\\\n  &=\\frac12\\left(x^2+1\\right)\\tan^{-1}x-\\frac12x+C,\n\\end{align*}\nas before (though rearranged).\n\\eex\nThough rare, and not crucial, strategically adding a particular constant\nto the natural choice for $v$ can on occasion make for easier computations.\n\n\n\n\n\\newpage\n\\begin{center}\n\\underline{\\Large{\\bf Exercises}}\\end{center}\n\n\\begin{multicols}{2}\n\nCompute the following integrals.\n\\begin{enumerate}\n\\item $\\ds{\\int x\\sin x\\,dx}$\n\\item $\\ds{\\int x\\cos x\\,dx}$\n\\item $\\ds{\\int x\\sec x\\tan x\\,dx}$\n\\item $\\ds{\\int x\\sec^2x\\,dx}$\n\\item $\\ds{\\int x\\ln x\\,dx}$\n\\item $\\ds{\\int x\\tan^{-1}x\\,dx}$\n\\item $\\ds{\\int x\\sec^{-1}x\\,dx}$, $x>1$.\n\\item $\\ds{\\int x\\sec^{-1}x\\,dx}$, $x<1$.\n\\item $\\ds{\\int x\\sqrt{1-x}\\,dx}$.\n\\item $\\ds{\\int\\frac{x}{\\sqrt{1-x}}\\,dx}$\n\\item $\\ds{\\int xe^x\\,dx}$\n\\item $\\ds{\\int x\\sin5x\\,dx}$\n\\item $\\ds{\\int x e^{x/2}\\,dx}$\n\\item $\\ds{\\int x^3e^{x^2}\\,dx}$\n\\item $\\ds{\\int x^5\\sin x^3\\,dx}$\n\\item $\\ds{\\int x^2e^{3x}\\,dx}$\n\\item $\\ds{\\int \\ln x\\,dx}$\n\\item $\\ds{\\int \\tan^{-1}x\\,dx}$\n\\item $\\ds{\\int\\sin^{-1}x\\,dx}$\n\\item $\\ds{\\int x\\sqrt{1-x^2}\\ \\sin^{-1}x\\,dx}$\n\\item $\\ds{\\int\\sin^2x\\,dx}$\n\\item $\\ds{\\int\\cos^25x\\,dx}$\n\\item $\\ds{\\int e^{5x}\\cos2x\\,dx}$\n\\end{enumerate}\n\\end{multicols}\n\\newpage\n\\section{Trigonometric Integrals\\label{TrigIntsSection}}\nWe have already looked at two basic types of trigonometric\nintegrals:  those arising from the derivatives of the\ntrigonometric functions (Subsection~\\ref{FirstTrigRulesSubsection}, \npage~\\pageref{FirstTrigRulesSubsection}), and those of the elementary\nsubstitution types in Section~\\ref{SecondTrigRules}.\nIn this section we are mainly interested in\ncomputing integrals\nwhere the integrands are combinations of powers of\ntrigonometric functions.  In such cases, the \nangles of each trigonometric function appearing are all the same.\nAnother important topic considered here is how to deal\nwith trigonometric combinations where the angles differ,\nand we will examine how to deal with several of those cases.\n\nIn the first examples where the angles agree, \nwe rearrange the terms in the integrand  and use \nthe three basic trigonometric identities to write the\nentire integral as function of one trigonometric function,\nand its differential as the final factor.  A substitution\nstep then leads to one or more power rules.  Unfortunately\nthis  only leads to a solution  if the combinations of powers \nare of a few simple forms.  Still, these combinations occur\noften enough to warrant study.\n\nAfter we look at those simplest forms, we look at \nother combinations of powers where the angles agree.  \nTechniques include other\nalgebraic manipulations, as well as integration by parts.\n\nIn the final forms, where the angles do not agree, we look\nat several trigonometric identities which help us to \nrewrite the integrals in simpler forms.\n\n\\subsection{Simplest Examples}\n\nThese first three examples illustrate an approach we\ndevelop in Subsections~\\ref{OddSineOrCosine},\n\\ref{EvenSecant/OddTangent} and \\ref{EvenCosecant/OddCotangent}.\n\n\n\\bex Compute $\\ds{\\int\\tan^2x\\,dx}$.\n\n\\underline{Solution}: \n$\\ds{\\int\\tan^2x\\,dx=\\int(\\sec^2x-1)\\,dx=\\tan x-x+C.}$\n\\eex\nThe example above used the facts that \n$\\tan^2x=\\sec^2x-1$, and that we know\nthe antiderivative of $\\sec^2x$ (where we\nmight not have known the antiderivative of \n$\\tan^2x$ immediately).  The integral above does\nnot in itself contain a general method.  Indeed there\nis no general method, but there are ways to \nrewrite many trigonometric integrals to make their\ncomputations more elementary.\n\\bex \nCompute  $\\ds{\\int\\sin^6x\\,\\cos^5x\\,dx}$.\n\n\\underline{Solution}: Here we will use the fact that \n$\\cos^2x=1-\\sin^2x$, and so $\\cos^{2k}x=\\left(1-\\sin^2x\\right)^k$.\nEventually  we will take $u=\\sin x$, implying $du=\\cos x\\,dx$:\n\\begin{align*}\n\\int\\sin^6x\\,\\cos^5x\\,dx&=\\int\\sin^6x\\,\\cos^4x\\,\\cos x\\,dx\\\\\n                     &=\\int\\sin^6x\\left(1-\\sin^2x\\right)^2\\cos x\\,dx\\\\\n                  &=\\int u^6\\left(1-u^2\\right)^2\\,du\n                     =\\int u^6\\left(1-2u^2+u^4\\right)\\,du\\\\\n                  &=\\int\\left[u^6-2u^8+u^{10}\\right]\\,du\\\\\n                  &=\\frac{u^7}7-\\frac{2u^9}9+\\frac{u^{11}}{11}+C\\\\\n                  &=\\frac17\\sin^7x-\\frac29\\sin^9x+\\frac1{11}\\sin^{11}x+C.\n\\end{align*}\n\\eex\n\n\\bex Compute $\\ds{\\int\\sec^5x\\,\\tan^3x\\,dx}$.\n\n\\underline{Solution}: Here we will borrow a factor of secant,\nand another of tangent, to form the functional part of $du$,\nwhere $u=\\sec x$:\n\n\\begin{align*}\n\\int\\sec^5x\\,\\tan^3x\\,dx&=\\int\\sec^4x\\,\\tan^2x\\,\\sec x\\tan x\\,dx\\\\\n&=\\int\\sec^4x\\left(\\sec^2x-1\\right)\\sec x\\tan x\\,dx\\\\\n&=\\int u^4\\left(u^2-1\\right)\\,du\\\\\n&=\\int\\left[u^6-u^4\\right]\\,du\\\\\n&=\\frac{u^7}7-\\frac{u^5}5+C\\\\\n&=\\frac17\\sec^7x-\\frac15\\sec^5x+C.\n\\end{align*}\n\\eex\n\nNow we look at these three specific techniques more closely\nand generalize them.\n\n\\subsection{Odd Powers of Sine or Cosine\\label{OddSineOrCosine}}\nHere we are interested in the cases of integrals\n\\begin{equation}\\int\\sin^m\\theta\\,\\cos^n\\theta\\,d\\theta.\\label{SineCosForm1}\n\\end{equation}\nwhere either $m$ or $n$ is odd.  Suppose, for example, that\n$m$ is odd, so that we can write $m=2k+1$ for some integer $k$.\nThen we rewrite the form (\\ref{SineCosForm1}) as \n$$\\int\\sin^m\\theta\\,\\cos^{2k+1}\\theta\\,d\\theta\n  =\\int\\sin^m\\theta\\,\\cos^{2k}\\theta\\,\\cos\\theta\\,d\\theta.$$\nThe $\\cos\\theta$ term which we ``peeled away'' becomes the functional\npart of the $du$, where $u=\\sin\\theta$ (so $du=\\cos\\theta\\,d\\theta$).\nWe then write the rest of the integral in terms of $u=\\sin\\theta$.\nTo do so we use\n\\begin{alignat*}{2}\n&&\\sin^2\\theta+\\cos^2\\theta&=0\\\\\n&\\iff&\\qquad\\cos^2\\theta&=1-\\sin^2\\theta\\\\\n&\\implies&\\cos^{2k}\\theta&=\\left(1-\\sin^2\\theta\\right)^k.\\end{alignat*}\nUsing this fact in the integral above, and setting $u=\\sin\\theta$, we get\n\\begin{align*}\n\\int\\sin^m\\theta\\,\\cos^{2k+1}\\theta\\,d\\theta\n & =\\int\\sin^m\\theta\\,\\cos^{2k}\\theta\\,\\cos\\theta\\,d\\theta\\\\\n &=\\int\\sin^m\\theta\\left(1-\\sin^2\\theta\\right)^k\\cos\\theta\\,d\\theta\\\\\n &=\\int u^m\\left(1-u^2\\right)^k\\,du.\\end{align*}\nThis yields a polynomial integrand, which\nwe may then wish to expand before computing (with a sequence of power\nrules).\n\nSimliarly, if there is an odd power of the sine, we can\nuse the fact that $\\sin^2\\theta=1-\\cos^2\\theta$,\nand eventually using $u=\\cos\\theta$, to \nrewrite such an integral\n\\begin{align*}\n\\int\\sin^{2k+1}\\theta\\,\\cos\\theta\\,d\\theta&=\\int\\sin^{2k}\\theta\\,\\cos\\theta\n                       \\sin\\theta\\,d\\theta\\\\\n  &=\\int\\left(1-\\cos^2\\theta\\right)^k\\cos^n\\theta\\,\\sin\\theta\\,d\\theta\\\\\n  &=\\int\\left(1-u^2\\right)u^n(-du)\\\\\n  &=-\\int\\left(1-u^2\\right)u^n\\,du.\n\\end{align*}\n\nIn both of these it was crucial that we had an odd number of\nfactors of either the sine or cosine, since ``peeling off''\none factor then leaves an even number, which can be\neasily written in terms of the other trigonometric function.\nThe peeled off factor is then the functional part of the differential\nafter substitution.\n\nNote that while\nany even power of a sine or cosine function can be written\nentirely in terms of  the other, this is not the\ncase with odd powers.\\footnote{%%\n%%% FOOTNOTE\nConsider the trigonometric identity $\\sin^2\\theta+\\cos^2\\theta=1$.\nWhen solved for either the sine or cosine function, we\nget one of the following:\n\\begin{align*}\n\\sin\\theta&=\\pm\\sqrt{1-\\cos^2\\theta},\\\\\n\\cos\\theta&=\\pm\\sqrt{1-\\sin^2\\theta}.\\end{align*}\nWe see the ambiguity in the $\\pm$, and the introduction of a radical\nwhich itself can very much complicate an integral.\nHowever, when we raise these to \neven powers the radicals {\\it and} the $\\pm$ both \ndisappear, and we are left with sums of nonnegative, integer powers.\n%%% END FOOTNOTE\n}\nThis technique works because\nremoving a factor from an odd power of sine or cosine,\nboth provides the functional part of $du$ and leaves an even power,\nwhich we write in terms of the other function which is then $u$\nin the substitution.\n\n\\bex Compute $\\ds{\\int\\sin^5x\\,\\cos^4x\\,dx}$.\n\n\\underline{Solution}: Here we see an odd number of sine factors,\nas so we peel one away to be part of the differential term,\nand write the entire integral in terms of the cosine:\n\\begin{align*}\n\\int\\sin^5x\\,\\cos^4x\\,dx&=\\int\\sin^4x\\,\\cos^4x\\,\\sin x\\,dx\\\\\n                      &=\\int\\left(\\sin^2x\\right)^2\\cos^4x\\,\\sin x\\,dx\\\\\n                      &=\\int\\left(1-\\cos^2x\\right)^2\\cos^4x\\,\\sin x\\,dx.\n\\end{align*}\n(In most future computations we will skip the second line above.)\nNow we take\n\\begin{alignat*}{2}\n&&u&=\\cos x\\\\\n&\\implies& du&=-\\sin x\\,dx\\\\\n&\\iff&    -du&=\\sin x\\,dx.\n\\end{alignat*}\nWith the substitution we will have a polynomial to integrate.\nTo summarize and finish the problem, we have:\n\\begin{align*}\n\\int\\sin^5x\\,\\cos^4x\\,dx&=\\int\\left(1-\\cos^2x\\right)^2\\cos^4x\\,\\sin x\\,dx\\\\\n      &=\\int\\left(1-u^2\\right)^2u^4(-du)\\\\\n      &=-\\int\\left(1-2u^2+u^4\\right)u^4\\,du\\\\\n      &=-\\int\\left(u^4-2u^6+u^8\\right)\\,du\\\\\n      &=-\\frac15\\,u^5+\\frac27\\,u^7-\\frac19\\,u^9+C\\\\\n      &=-\\frac15\\cos^5x+\\frac27\\cos^7x-\\frac19\\cos^9x+C.\n\\end{align*}\n\\eex\n\nIt should be clear that one cannot easily differentiate the final\nanswer and immediately recognize the original integrand.  This is because\nsome trigonometric identities were used to get an integrand form\nwhich was computable using these methods.  Indeed, it is best\nto check the validity of the steps from the beginning, rather\nthan to differentiate a tentative answer.  However, it is an\ninteresting exercise---left to the interested reader---in \ntrigonometric identities to \nperform the differentiation, and then validate that the\nanswer there is the original integrand.\n\n\nIt is not necessary that the angle is always $x$.\nHowever, for this technique we do require the angles inside\nthe trigonometric functions to always match, and for the\napproximate differential of the variable of substitution to be present.\n\n\\bex Compute $\\ds{\\int\\sin^45x\\,\\cos^35x\\,dx}$.\n\n\\underline{Solution}: Here there is an odd number of cosine terms, and\nwe act accordingly.\n\\begin{align*}\n\\int\\sin^45x\\,\\cos^35x\\,dx\n  &=\\int\\sin^45x\\,\\cos^25x\\,\\cos5x\\,dx\\\\\n  &=\\int\\sin^45x\\left(1-\\sin^25x\\right)\\cos5x\\,dx.\\end{align*}\nHere we have\n\\begin{alignat*}{2}\n&&u&=\\sin5x\\\\\n&\\implies& du&=5\\cos5x\\,dx\\\\\n&\\iff&    \\frac15\\,du&=\\cos5x\\,dx.\n\\end{alignat*}\nNow we begin again, incorporating this new information into \nour computation:\n\\begin{align*}\n\\int\\sin^45x\\,\\cos^35x\\,dx\n&=\\int\\sin^45x\\left(1-\\sin^25x\\right)\\cos5x\\,dx\\\\\n&=\\int u^4\\left(1-u^2\\right)\\cdot\\frac15\\,du\\\\\n&=\\frac15\\int\\left(u^4-u^6\\right)\\,du\\\\\n&=\\frac15\\cdot\\frac15\\,u^5-\\frac15\\cdot\\frac17\\,u^7+C\\\\\n&=\\frac1{25}\\sin^55x-\\frac1{35}\\sin^75x+C.\n\\end{align*}\n\\eex\n\nThe technique works even if only one of the trigonometric\nfunctions sine or cosine appears, as long as it is to an odd\npower.\n\n\\bex Compute $\\ds{\\int\\sin^37x\\,dx}$.\n\n\\underline{Solution}:  Here we can still peel off a sine factor\nto be the functional part of our differential, and then\nwrite the remaining factors in terms of the cosine.\n\n\\begin{align*}\n\\int\\sin^37x\\,dx&=\\int\\sin^27x\\,\\sin7x\\,dx\\\\\n                &=\\int\\left(1-\\cos^27x\\right)\\sin7x\\,dx.\n\\end{align*}\nUsing the substitution $u=\\cos7x$, so $du=-7\\sin7x\\,dx$,\nimplying $-\\frac17\\,du=\\sin7x\\,dx$, we get\n\\begin{align*}\n\\int\\sin^37x\\,dx&=\n\\int\\left(1-\\cos^27x\\right)\\sin7x\\,dx\\\\\n              &=\\int\\left(1-u^2\\right)\\cdot\\frac{-1}7\\,du\\\\\n              &=-\\frac17\\left[u-\\frac13\\,u^3\\right]+C\\\\\n              &=-\\frac17\\cos7x+\\frac1{21}\\cos^37x+C.\n\\end{align*}\n\\eex\n\nFurthermore, not all the powers need to be positive integer powers,\nas long as one is odd.\n\n\\bex Compute $\\ds{\\int\\frac{\\cos^7x}{\\sqrt{\\sin x}}\\,dx}$.\n\n\\underline{Solution}:  Here we have an odd number of cosine terms,\nso we will peel one off to be the functional part of our differential.\nThat is, we will have $u=\\sin x$, so $du=\\cos x\\,dx$. Thus\n\\begin{align*}\n\\int\\frac{\\cos^7x}{\\sqrt{\\sin x}}\\,dx\n&=\\int\\frac{\\cos^6x}{\\sqrt{\\sin x}}\\,\\cos x\\,dx\\\\\n&=\\int\\frac{\\left(1-\\sin^2x\\right)^3}{\\sqrt{\\sin x}}\\,\\cos x\\,dx\\\\\n&=\\int\\frac{\\left(1-u^2\\right)^3}{\\sqrt{u}}\\,du\\\\\n&=\\int\\frac{1-3u^2+3u^4-u^6}{u^{1/2}}\\,du\\\\\n&=\\int\\left[u^{-1/2}-3u^{3/2}+3u^{7/2}-u^{11/2}\\right]\\,du\\\\\n&=2u^{1/2}-3\\cdot\\frac25\\,u^{5/2}+3\\cdot\\frac29\\,u^{9/2}-\\frac2{13}\\,u^{13/2}\n          +C\\\\\n&=2u^{1/2}\\left[1-\\frac35u^2+\\frac13u^4-\\frac1{13}u^6\\right]+C\\\\\n&=2\\sqrt{\\sin x}\\left[1-\\frac35\\sin^2x+\\frac13\\sin^4x-\\frac1{13}\\sin^6x\\right]\n   +C.\n\\end{align*}\n\\eex\n\nIt is possible that both powers are odd, and either\nfunction can be peeled off, and the integral written in terms of the\nother.  However, if one of these odd powers is greater than the other,\nit is more efficient to peel off a factor from the lower power, as the\nnext example demonstrates.\n\n\\bex Compute $\\ds{\\int\\sin^3x\\,\\cos^7x\\,dx}$.\n\n\\underline{Solution}:  We will consider both methods for computing\nthis antiderivative.  First we peel off a sine to be part of\nthe differential, and let $u=\\cos x$.\n\\begin{align*}\n\\int\\sin^3x\\,\\cos^7x\\,dx&=\\int\\sin^2x\\,\\cos^7x\\,\\sin x\\,dx\\\\\n                      &=\\int\\left(1-\\cos^2x\\right)\\cos^7x\\,\\sin x\\,dx\\\\\n                      &=\\int\\left(1-u^2\\right)u^7(-\\,du)\\\\\n                      &=-\\int\\left(u^7-u^9\\right)\\,du\\\\\n                      &=-\\frac18\\,u^8+\\frac1{10}\\,u^{10}+C\\\\\n                      &=-\\frac18\\cos^8x+\\frac1{10}\\cos^{10}x+C.\n\\end{align*}\nNext we instead peel off a cosine factor, and let $w=\\sin x$.\n\\begin{align*}\n\\int\\sin^3x\\,\\cos^7x\\,dx&=\\int\\sin^3x\\,\\cos^6x\\,\\cos x\\,dx\\\\\n        &=\\int\\sin^3x\\left(1-\\sin^2x\\right)^3\\cos x\\,dx\\\\\n        &=\\int w^3\\left(1-w^2\\right)^3\\,dw\\\\\n        &=\\int w^3\\left(1-3w^2+3w^4-w^6\\right)\\,dw\\\\\n        &=\\int\\left(w^3-3w^5+3w^7-w^9\\right)\\,dw\\\\\n        &=\\frac14\\,w^4-\\frac36\\,w^6+\\frac38\\,w^8-\\frac1{10}\\,w^{10}+C\\\\\n        &=\\frac14\\sin^4x-\\frac12\\sin^6x+\\frac38\\sin^8x-\\frac1{10}\\sin^{10}x+C.\n\\end{align*}\n\\eex\n\nAs we see in the above example, there can be different valid choices for\nsome integrals.  The answers may look very different, but \nthat is a reflection of the wealth of trigonometric identities \navailable.  In fact, the antiderivatives, excluding the arbitrary\nconstants, need not be equal, but the difference should be \naccounted for in the constants.\\footnote{%%%\n%%% FOOTNOTE\nRecall the integral $\\int2\\sin x\\cos x\\,dx$, for which one\ncan let either $u=\\sin x$ or $u=\\cos x$, yielding\n\\begin{align*}\n\\int2\\sin x\\cos x\\,dx&=\\sin^2x+C_1,\\qquad\\text{or}\\\\\n\\int2\\sin x\\cos x\\,dx&=-\\cos^2x+C_2.\\end{align*}\nSince these differ by a constant, specifically\n$\\sin^2x=-\\cos^2x+1$, both are valid.  But clearly\n$\\sin^2x\\ne\\cos^2x$.\n%%% END FOOTNOTE\n}\n\n\n\n\n\\subsection{Even Powers of Secant or Odd Powers of Tangent\n\\label{EvenSecant/OddTangent}}\nThis technique of peeling off some factors of a trigonometric\nfunction to be part of the $du$ (after substitution) has\ntwo workable versions for integrals of the type\n\\begin{equation}\n\\int\\sec^m\\,\\theta\\tan^n\\theta\\,d\\theta.\\label{SecantTangentForm1}\n\\end{equation}\nThese rely upon the following facts from trigonometry and calculus:\n\\begin{alignat*}{3}\n\\tan^2\\theta+1&=\\sec^2\\theta,&\\qquad\\qquad\n            \\frac{d}{d\\theta}\\tan\\theta&=\\sec^2\\theta,\\\\\n\\sec^2\\theta-1&=\\tan^2\\theta,&\\qquad\\frac{d}{d\\theta}\n        \\sec\\theta&=\\sec\\theta\\tan\\theta.\\end{alignat*}\n\nThe techniques we will employ are as follow:\n\\begin{enumerate}\n\\item If an integral of the form (\\ref{SecantTangentForm1})\ncontains an odd power of tangent, we peel off a factor\n$\\sec\\theta\\tan\\theta$ to be the functional part of the differential.\nThis leaves an even power of tangent, which can be written as\na power of $\\left(\\sec^2\\theta-1\\right)$.\n\\item If an integral of the form (\\ref{SecantTangentForm1})\ncontains an even power of secant, we peel off a factor\n$\\sec^2\\theta$ to be the functional part of the differential.\nThe remaining even power of secant is then written as \na power of $\\left(\\tan^2\\theta+1\\right)$.\n\\end{enumerate}\n\n\\bex Compute $\\ds{\\int\\sec^6x\\,\\tan^8x\\,dx}$.\n\n\\underline{Solution}  Here we have an even number of secant factors,\nand so we can peel off two.  Eventually we will let $u=\\tan x$,\nimplying $du=\\sec^2x\\,dx$.\n\\begin{align*}\n\\int\\sec^6x\\,\\tan^8x\\,dx\n &=\\int\\sec^4x\\,\\tan^8x\\,\\sec^2x\\,dx\\\\\n &=\\int\\left(\\tan^2x+1\\right)^2\\tan^8x\\,\\sec^2x\\,dx\\\\\n &=\\int\\left(u^2+1\\right)^2u^8\\,du\\\\\n &=\\int\\left(u^4+2u^2+1\\right)u^8\\,du\\\\\n &=\\int\\left(u^{12}+2u^{10}+u^8\\right)\\,du\\\\\n &=\\frac1{13}\\,u^{13}+\\frac2{11}\\,u^{11}+\\frac19\\,u^9+C\\\\\n &=\\frac1{13}\\tan^{13}x+\\frac2{11}\\tan^{11}x+\\frac19\\tan^9x+C.\n\\end{align*}\n\\label{SecEvenTanEven1}\\eex\n\n\\bex Compute $\\ds{\\int\\sec^72x\\tan^52x\\,dx}$\n\n\\underline{Solution}:\nHere we have an odd number of tangent factors, so we peel off a \n$\\sec2x\\tan2x$ factor to be the functional part of the differential.\nEventually we then have $u=\\sec2x$, giving $du=2\\sec2x\\tan2x\\,dx$\nand thus $\\frac12\\,du=\\sec2x\\tan2x\\,dx$.\n\\begin{align*}\n\\int\\sec^72x\\,\\tan^52x\\,dx\n &=\\int\\sec^62x\\,\\tan^42x\\,\\sec2x\\tan2x\\,dx\\\\\n &=\\int\\sec^62x\\left(\\sec^22x-1\\right)^2\\sec2x\\tan2x\\,dx\\\\\n &=\\int u^6\\left(u^2-1\\right)^2\\cdot\\frac12\\,du\\\\\n &=\\frac12\\int u^6\\left(u^4-2u^2+1\\right)\\,du\\\\\n &=\\frac12\\int\\left(u^{10}-2u^8+u^6\\right)\\,du\\\\\n &=\\frac12\\left[\\frac1{11}\\,u^{11}-\\frac29\\,u^9+\\frac17\\,u^7\\right]+C\\\\\n &=\\frac1{22}\\sec^{11}2x-\\frac19\\sec^92x+\\frac1{14}\\sec^72x+C.\n\\end{align*}\n\\eex\nIn fact this last example could be computed by first rewriting\nthe integral in terms of cosines and sines:\n\\begin{align*}\n\\int\\frac{\\sin^52x}{\\cos^{12}2x}\\,dx\n&=\\int\\frac{\\sin^42x}{\\cos^{12}2x}\\sin2x\\,dx\n=\\int\\frac{\\left(1-\\cos^22x\\right)^2}{\\cos^{12}2x}\\sin2x\\,dx\\\\\n&=\\int\\frac{\\left(1-u^2\\right)^2}{u^{12}}\\cdot\\frac{-1}2\\,du\n=-\\frac12\\int u^{-12}\\left(1-2u^2+u^4\\right)\\,du,\\text{ etc.}\n\\end{align*}\nThus, the relationships involving the secant and tangent are\nnot required in this last example.  However, rewriting\nthe integral in the previous problem, Example~\\ref{SecEvenTanEven1},\nin terms of sines and cosines would not yield either to an odd\npower.  Thus  Example~\\ref{SecEvenTanEven1} illustrates\nan integral which does benefit from the extra structure\n(algebraic and calculus) of the secant-tangent relationship.\n\n\\bex Compute $\\ds{\\int\\tan^4x\\,dx}$.\n\n\\underline{Solution}:  Here we look at two solutions.\nIn the first, instead of exploiting the fact that there are an even\nnumber of factors of secant (namely zero) present here,\nwe will repeatedly use the fact that $\\tan^2\\theta+1=\\sec^2\\theta$.\n(In the second line, we let $u=\\tan x$.)\n\\begin{align*}\n\\int\\tan^4x\\,dx&=\\int\\tan^2x\\left(sec^2x-1\\right)\\,dx\\\\\n               &=\\int\\underbrace{\\tan^2x}_{u^2}\\underbrace{\\sec^2x}_{du}\n                 \\,dx -\\int\\tan^2x\\,dx\\\\\n               &=\\frac13\\tan^3x-\\int\\tan^2x\\,dx\\\\\n               &=\\frac13\\tan^3x-\\int\\left(\\sec^2x-1\\right)\\,dx\\\\\n               &=\\frac13\\tan^3x-\\tan x+x+C.\\end{align*}\nOf course the other method is to ``peel off'' a factor of $\\sec^2x$, which\nwe do even\nthough it does not really appear.  To have it appear, we will\nmultiply and divide the integrand by $\\sec^2x$.  Then\nwe will let $u=\\tan x$.\nA long division will give us the sum of powers in our final integral\nbelow.\n\\begin{align*}\n\\int\\tan^4x\\,dx&=\\int\\frac{\\tan^4x}{\\sec^2x}\\sec^2x\\,dx\\\\\n               &=\\int\\frac{\\tan^4x}{\\tan^2x+1}\\sec^2x\\,dx\\\\\n               &=\\int\\frac{u^4}{u^2+1}\\,du\\\\\n               &=\\int\\left(u^2-1+\\frac1{u^2+1}\\right)\\,du\\\\\n               &=\\frac13\\,u^3-u+\\tan^{-1}u+C_1\\\\\n               &=\\frac13\\tan^3x-\\tan x+\\tan^{-1}(\\tan x)+C_1\\\\\n               &=\\frac13\\tan^3x-\\tan x+x+C.\n\\end{align*}\nHere we did have the extra complication of long division.\nFurthermore, to see that the two answers were the same we\nhad to notice\n$\\tan^{-1}(\\tan x)=x+n\\pi$, where $n\\in\\mathbb{Z}$, i.e., $n$ is\nan integer.\\footnote{\n%%% FOOTNOTE\nRecall knowing $\\tan x$ does not mean we know\nthe angle $x$, but we do know it to an integer multiple of $\\pi$,\nwhich is the period of tangent.  Recall also that\ntangent is one-to-one in each such period. (Of course the\nintegral is only defined on each period individually,\nseparated by the discontinuities---in fact vertical \nasymptotes---of the integrand.)  Furthermore, the arctangent\nfunction only outputs angles in the period $-\\pi/2<\\theta<\\pi/2$,\nso $\\tan^{-1}(\\tan x)\\in(-\\pi/2,\\pi/2)$, where $x$ is not so restricted.\nEventually, this is all taken care of by the arbitrary nature\nof the constant $C$.%\n%%% END FOOTNOTE\n}  Thus the final constant $C$ takes into account $C_1-n\\pi$, still\na constant.\n\\eex\n\n\\subsection{Even Powers of Cosecant or Odd Powers of Cotangent\n\\label{EvenCosecant/OddCotangent}}\n\nHere we just point out that a similar relationship \nexists between the cosecant and cotangent, as exists\nbetween the secant and tangent.  We briefly look\nat two examples to illustrate this.   The integral type\nis \n\\begin{equation}\n\\int\\csc^m\\theta\\,\\cot^n\\theta\\,d\\theta.\\label{CosecantCotangentForm1}\n\\end{equation}\nWe begin with  the following facts from trigonometry and calculus:\n\\begin{alignat*}{3}\n\\cot^2\\theta+1&=\\csc^2\\theta,&\\qquad\\qquad\n            \\frac{d}{d\\theta}\\cot\\theta&=-\\csc^2\\theta,\\\\\n\\csc^2\\theta-1&=\\cot^2\\theta,&\\qquad\\frac{d}{d\\theta}\n        \\csc\\theta&=-\\csc\\theta\\cot\\theta.\\end{alignat*}\n\nThe techniques we will employ mirror those used for\nthe secant-tangent integrals:\n\\begin{enumerate}\n\\item If an integral of the form (\\ref{CosecantCotangentForm1})\ncontains an odd power of cotangent, we peel off a factor\n$\\csc\\theta\\cot\\theta$ to be the functional part of the differential.\nThis leaves an even power of cotangent, which can be written as\na power of $\\left(\\csc^2\\theta-1\\right)$.\n\\item If an integral of the form (\\ref{CosecantCotangentForm1})\ncontains an even power of cosecant, we peel off a factor\n$\\csc^2\\theta$ to be the functional part of the differential.\nThe remaining even power of cosecant is then written as \na power of $\\left(\\cot^2\\theta+1\\right)$.\n\\end{enumerate}\n\n\\bex Compute $\\ds{\\int\\csc^8x\\,\\cot^2x\\,dx}$.\n\n\\underline{Solution}: We see an even number of cosecants, so\nwe peel off two to be part of the differential.\n\\begin{align*}\n\\int\\csc^8x\\,\\cot^2x\\,dx&=\\int\\csc^6x\\,\\cot^2x\\,\\csc^2x\\,dx\\\\\n    &=\\int\\left(\\csc^2x\\right)^3\\cot^2x\\,\\csc^2x\\,dx\\\\\n    &=\\int\\left(\\cot^2x+1\\right)^3\\cot^2x\\,\\csc^2x\\,dx.\n\\end{align*} \nTaking $u=\\cot x$, giving $du=-\\csc^2x\\,dx$, so $-du=\\csc^2x\\,dx$,\nwe get\n\\begin{align*}\n\\int\\csc^8x\\,\\cot^2x\\,dx&\\int\\left(\\cot^2x+1\\right)^3\\cot^2x\\,\\csc^2x\\,dx\\\\\n         &=\\int\\left(u^2+1\\right)^3u^2(-du)\\\\\n         &=-\\int\\left(u^6+3u^4+3u^2+1\\right)u^2\\,du\\\\\n         &=-\\int\\left(u^8+3u^6+3u^4+u^2\\right)\\,du\\\\\n         &=-\\frac19\\,u^9-\\frac37\\,u^7-\\frac35\\,u^5-\\frac13\\,u^3+C\\\\\n         &=-\\frac19\\cot^9x-\\frac37\\cot^7x-\\frac35\\cot^5x-\\frac13\\cot^3x+C.\n\\end{align*}\n\\eex\n%\\newpage\n\\bex Compute $\\ds{\\int\\csc^3\\frac{x}2\\,\\cot^3\\frac{x}2\\,dx}$.\n\n\\underline{Solution}: Here the cotangent appears to an odd\npower, so we will peel of one cosecant and one cotangent.\n\\begin{align*}\n\\int\\csc^3\\frac{x}2\\,\\cot^3\\frac{x}2\\,dx\n  &=\\int\\csc^2\\frac{x}2\\,\\cot^2\\frac{x}2\\,\\csc\\frac{x}2\\,\\cot\\frac{x}2\\,dx\\\\\n  &=\\int\\csc^2\\frac{x}2\\left(\\csc^2\\frac{x}2-1\\right)\n          \\csc\\frac{x}2\\cot\\frac{x}2\\,dx.\n\\end{align*}\nNow we let $u=\\csc\\frac{x}2$, implying\n$du=-\\csc\\frac{x}2\\cot\\frac{x}2\\cdot\\frac12\\,dx$,\nwhence\n$-2\\,du=\\csc\\frac{x}2\\cot\\frac{x}2\\,dx$.\nOur integral then becomes\n\\begin{align*}\n\\int\\csc^3\\frac{x}2\\,\\cot^3\\frac{x}2\\,dx\n &=\\int\\csc^2\\frac{x}2\\left(\\csc^2\\frac{x}2-1\\right)\n          \\csc\\frac{x}2\\cot\\frac{x}2\\,dx\\\\\n &=\\int u^2\\left(u^2-1\\right)(-2)\\,du\\\\\n &=-2\\int\\left(u^4-u^2\\right)\\,du\\\\\n &=-\\frac25\\,u^5+\\frac23\\,u^3+C\\\\\n &=-\\frac25\\csc^5\\frac{x}2+\\frac23\\csc^3\\frac{x}2+C.\n\\end{align*}\n\\eex\n\n\\subsection{Even Powers of Sine and Cosine}\nNow we turn our attention to the question of integration\nwhen both powers of sine and cosine are even.  There\nare two standard methods for handling this:\nintegration by parts, and ``half-angle formulas.''\nThe former is more useful when the powers are small\nthan when they are large, and the latter is perhaps\nmore general.\\footnote{%\n%%% FOOTNOTE\nIn today's calculus texts, integration by parts is less\nprominently presented for such integrals, while half-angle\nmethods are more popular among authors.  We present\nboth here for the lower powers, as some of the phenomena \nfound in the integration by parts \nfor such integrals are found later in this section.%\n%%%% END FOOTNOTE\n}\n\n\\bex Compute $\\ds{\\int\\sin^2x\\,dx}$ using integration by parts.\n\n\\underline{Solution}: This exact computation was performed\nin\nExample~\\ref{FirstPartsIntegrationOfSinSquaredX},\npage~\\pageref{FirstPartsIntegrationOfSinSquaredX}.\nSo that it is in front of us here, we summarize that \ncomputation:\n\\begin{align*}\n\\I&=\\int\\underbrace{\\sin x}_{u}\\underbrace{\\sin x\\,dx}_{dv}\n   =\\underbrace{(\\sin x)}_v\\underbrace{(-\\cos x)}_{v}\n         -\\int\\underbrace{(-\\cos x)}_v\\underbrace{\\cos x\\,dx}_{du}\n   =-\\sin x\\cos x+\\int\\cos^2x\\,dx\\\\\n  &=-\\sin x\\cos x+\\int\\left(1-\\sin^2x\\right)\\,dx\n   =-\\sin x\\cos x+x-\\int\\sin^2x\\,dx\\\\\n  &=x-\\sin x\\cos x-\\I.\n\\end{align*}\nAt this point we add $\\I=\\int\\sin^2x\\,dx$ to both sides to get\n\\begin{align*}\n2\\int\\sin^2x\\,dx&=x-\\sin x\\cos x+C_1\\\\\n\\implies\n\\int\\sin^2x\\,dx&=\\frac12\\left(x-\\sin x\\cos x\\right)+C.\\end{align*}\n\\label{IntOfSineSquaredForTrigIntegrals}\\eex\n\nThe method above works well for integrating\n$\\sin^2x$ or $\\cos^2x$, but higher, even powers\nbecome more cumbersome.  For this reason it is \ncommon to opt for alternatives involving \nslightly more sophisticated trigonometric identities.\nThere is some redundancy in the list below, as \n(\\ref{SineIsOdd}), (\\ref{CosineIsEven}),\n(\\ref{Sine(A+B)}) and (\\ref{Cosine(A+B)}) together imply \nthe others.\n\\begin{align}\n\\sin(-\\theta)&=-\\sin\\theta,\\label{SineIsOdd}\\\\\n\\cos(-\\theta)&=\\cos\\theta,\\label{CosineIsEven}\\\\\n\\sin(A+B)&=\\sin A\\cos B+\\sin B\\cos A\\label{Sine(A+B)}\\\\\n\\sin(A-B)&=\\sin A\\cos B-\\sin B\\cos A\\label{Sine(A-B)}\\\\\n\\cos(A+B)&=\\cos A\\cos B-\\sin A\\sin B\\label{Cosine(A+B)}\\\\\n\\cos(A-B)&=\\cos A\\cos B+\\sin A\\sin B\\label{Cosine(A-B)}\\\\\n\\sin 2A&=2\\sin A\\cos A\\label{Sine2A}\\\\\n\\cos 2A&=\\cos^2A-\\sin^2A\\label{Cosine2A-Version1}\\\\\n\\cos 2A&=2\\cos^2A-1\\label{Cosine2A-Version2}\\\\\n\\cos 2A&=1-2\\sin^2A.\\label{Cosine2A-Version3}\n\\end{align}\nIt is left for the exercises to show that \n\\begin{enumerate}\n\\item (\\ref{Sine(A-B)})\nfollows from replacing $B$ with $-B$ in (\\ref{Sine(A+B)}),\n\\item Similarly, (\\ref{Cosine(A-B)})\nfollows from (\\ref{Cosine(A+B)}).\n\\item (\\ref{Sine2A}) follows from (\\ref{Sine(A+B)}), if we let $B=A$.\n\\item Similarly (\\ref{Cosine2A-Version1}) follows from (\\ref{Cosine(A+B)}).\n\\item (\\ref{Cosine2A-Version2}) and (\\ref{Cosine2A-Version3})\n      follow from (\\ref{Cosine2A-Version1}) and the identity\n      $\\sin^2A+\\cos^2A=1$.\n\\end{enumerate}\nNow (\\ref{Cosine2A-Version2}) and (\\ref{Cosine2A-Version3}) can \nbe rewritten as follow:\n\\begin{align*}\n\\cos2A+1&=2\\cos^2A,\\\\\n2\\sin^2A&=1-\\cos2A.\\end{align*}\nReplacing $A$ with $\\theta$, we can divide these by 2 to get\nso-called half-angle formulas:\\footnote{%\n%%% FOOTNOTE\nEquations (\\ref{Half-AngleForCosineSquared}) \nand (\\ref{Half-AngleForSineSquared})\nare called half-angle formulas because the \nangle $\\theta$ on the left is half of the angle $2\\theta$ on the\nright.  In fact, knowing the location of the terminal side of an\nangle does not tell us where its half is located.\nIndeed, $90^\\circ$ and $450^\\circ$ are coterminal, but \ntheir half angles, $45^\\circ$ and $225^\\circ$ are not.\nThis is reflected in what are given as ``half-angle'' formulas\nin most trigonometry texts (compare to\n(\\ref{Half-AngleForCosineSquared}) and (\\ref{Half-AngleForSineSquared})):\n\\begin{align*}\n\\cos\\frac{\\alpha}2&=\\pm\\sqrt{\\frac{1+\\cos\\alpha}2}\\\\\n\\sin\\frac{\\alpha}2&=\\pm\\sqrt{\\frac{1-\\cos\\alpha}2}.\\end{align*}\nHowever, knowing where an angle terminates does determine where\ntwice the angle terminates, as is reflected in \n(\\ref{Sine2A})--(\\ref{Cosine2A-Version3}).\n%%% END FOOTNOTE\n}\n\\begin{align}\n\\cos^2\\theta&=\\frac12\\left(1+\\cos2\\theta\\right),\n              \\label{Half-AngleForCosineSquared}\\\\\n\\sin^2\\theta&=\\frac12\\left(1-\\cos2\\theta\\right).\n             \\label{Half-AngleForSineSquared}\n\\end{align}\nUsing (\\ref{Half-AngleForSineSquared}), we see\n$$\\int\\sin^2x\\,dx=\\int\\frac12(1-\\cos2x)\\,dx\n=\\frac12\\left[x-\\frac12\\sin2x\\right]+C.$$\nFor reasons which will be clear in the next section, it is\noften desirable that the angle in the final answer agree\nwith the original angle, in this case $x$.\nFor that we use the double-angle formula (\\ref{Sine2A}),\nto get\n\\begin{align*}\\int\\sin^2x\\,dx&=\\frac12\\left[x-\\frac12\\sin2x\\right]+C\n =\\frac12\\left[x-\\frac12\\cdot2\\sin x\\cos x\\right]+C\\\\\n &=\\frac12x-\\frac12\\sin x\\cos x+C.\\end{align*}\nThis agrees with the answer we obtained through\nintegration by parts, in \nExample~\\ref{IntOfSineSquaredForTrigIntegrals},\npage~\\pageref{IntOfSineSquaredForTrigIntegrals}.\n\n\\newpage\n\\bex Compute $\\ds{\\int\\sin^4x\\,dx}$.\n\n\\underline{Solution}: Here we use the half-angle formulas \nrepeatedly, until our integral has no positive, even powers of sine or cosine:\n\\begin{align*}\n\\int\\sin^4x\\,dx&=\\int\\left(\\sin^2x\\right)^2\\,dx\n                =\\int\\left[\\frac12\\left(1-\\cos2x\\right)\\right]^2\\,dx\\\\\n               &=\\frac14\\int\\left(1-2\\cos2x+\\cos^22x\\right)\\,dx\\\\\n               &=\\frac14\\int\\left[1-2\\cos2x+\\frac12(1+\\cos4x)\\right]\\,dx\\\\\n               &=\\frac14\\int\\left[\\frac32-2\\cos2x+\\frac12\\cos4x\\right]\\,dx\\\\\n          &=\\frac14\\left[\\frac32\\,x-\\sin2x+\\frac12\\cdot\\frac14\\sin4x\\right]+C\\\\\n        &=\\frac38x-\\frac14\\sin2x+\\frac1{32}\\sin4x+C.\n\\end{align*}\nThis answer is correct, but if we want to match the angles to the\noriginal ($x$), we can use some double-angle formulas\n(\\ref{Sine2A}) and (\\ref{Cosine2A-Version1}):\n\\begin{align*}\n\\int\\sin^4x\\,dx&=\\frac38x-\\frac14\\sin2x+\\frac1{32}\\sin4x+C\\\\\n&=\\frac38\\,x-\\frac14\\cdot2\\sin x\\cos x+\\frac1{32}\\cdot2\\sin2x\\cos2x+C\\\\\n&=\\frac38\\,x-\\frac12\\sin x\\cos x+\\frac1{16}(2\\sin x\\cos x)(\\cos^2x-\\sin^2x)+C,\n\\end{align*}               \nwhich can again be simplified and rewritten in several ways.\n\\eex\n\n\\bex Compute $\\ds{\\int\\sin^23x\\,\\cos^23x\\,dx}$.\n\n\\underline{Solution}: \n\\begin{align*}\n\\int\\sin^23x\\,\\cos^23x\\,dx\n &=\\int\\frac12(1-\\cos6x)\\cdot\\frac12(1+\\cos6x)\\,dx\n  =\\frac14\\int\\left(1-\\cos^26x\\right)\\,dx\\\\\n &=\\frac14\\int\\left[1-\\frac12(1+\\cos12x)\\right]\\,dx\n  =\\frac14\\int\\left[\\frac12-\\frac12\\cos12x\\right]\\,dx\\\\\n &=\\frac14\\left[\\frac{x}2-\\frac12\\cdot\\frac1{12}\\sin12x\\right]+C\n  =\\frac{x}8-\\frac1{96}\\sin12x+C.\n\\end{align*}\n(We could have used $1-\\cos^26x=\\sin^26x$ after the first line.)\nAs before, if we would like to have our answer in terms of the\noriginal angle, we need to utilize the double angle formulas\n(\\ref{Sine2A}) and (\\ref{Cosine2A-Version1}):\n\\begin{align*}\n\\int\\sin^23x\\,\\cos^23x\\,dx\n  &=\\frac{x}8-\\frac1{96}\\sin12x+C\\\\\n  &=\\frac{x}8-\\frac1{96}\\cdot2\\sin6x\\cos6x+C\\\\\n  &=\\frac{x}8-\\frac1{48}(2\\sin3x\\cos3x)(\\cos^23x-\\sin^23x)+C\\\\\n  &=\\frac{x}8-\\frac1{24}\\sin3x\\cos3x(\\cos^23x-\\sin^23x)+C.\n\\end{align*}\n\\eex\n\n\\subsection{Miscellaneous Problems and Methods}\nThere are many trigonometric integrals that\neither do not fit one of the above categories, or\nfor which those methods are unwieldy.  We\nwill look at several such here.  The reader should \nrealize, however, that we cannot exhaust all\npossibilities here, and a particular problem may have\na particularly clever solution which does not generalize\nwell to other problems.\n\nThe methods of the earlier subsections are all standard and any\nsuccessful calculus student is expected to know them.\nThe first few examples here are of this class also, in\nthat the better students should be able to handle these\nwithout resorting to references.  We will, however, \neventually have methods in this subsection\nwhich such a student should be\naware of, but is understandably less likely to be able to \nrecite from memory.\nAll are derivable, but again, the latter are somewhat more \nobscure and even an excellent students might prefer to use \na reference.  It is important, however,  that all students\nbe aware of these latter classes of problems, \nand the available methods of solution,\nregardless of whether a reference is used ultimately.\n\n\\bex Compute $\\ds{\\int\\sec^3x\\,dx}$.\n\n\\underline{Solution}: Here we have an odd number of secants,\nand an even (zero) number of tangents.  Unfortunately our\nealier methods called for an even number of secants or\nan odd number of tangents.  We could notice that the integrand\nrepresents an odd number ($-3$) of cosines, and\nthen with $u=\\sin x$, we could write\n$$\\int\\sec^3x\\,dx=\\int\\frac1{\\cos^3x}\\,dx=\\int\\frac1{\\cos^4x}\\,\\cos x\\,dx\n                 =\\int\\frac1{\\left(1-\\sin^2x\\right)^2}\\cos x\\,dx\n                 =\\int\\frac1{\\left(1-u^2\\right)^2}\\,du,$$\nbut in fact we have yet to discuss how to integrate that final\nform. (We will in Section~\\ref{PartialFracSection},\nand while it will be somewhat long, it will be a straightforward computation\nthere).\nInstead we will next try integration by parts.  \nSince the integrand contains an easily integrated $\\sec^2x\\,dx$ factor, we will\nlet that be $dv$:\n\\begin{alignat*}{3}\nu&=\\sec x&&\\qquad\\qquad&dv&=\\sec^2x\\,dx\\\\\ndu&=\\sec x\\tan xdx&&&v&=\\tan x \n\\end{alignat*}\n$$\\int\\sec^3x\\,dx=uv-\\int v\\,du=\\sec x\\tan x-\\int \\sec x\\tan^2x\\,dx.$$\nNow it is tempting to do another parts step, with $dv=\\sec x\\tan x\\,dx$,\nbut---as happened in some previous examples---we would then have\nour original integral on the left, and the same on the right.\nWhat works here is to instead use one of the basic trigonometric \nidentities at this step:\n\\begin{align*}\n\\int\\sec^3x\\,dx&=\\sec x\\tan x-\\int\\sec x \\tan^2x\\,dx\\\\\n           &=\\sec x \\tan x-\\int\\sec x\\left(\\sec^2x-1\\right)+C\\\\\n       &=\\sec x\\tan x -\\int\\sec^3 x\\,dx +\\int\\sec x\\,dx\\\\\n       &=\\sec x\\tan x+\\ln|\\sec x+\\tan x|-\\int\\sec^3x\\,dx.\n\\end{align*}\nAdding $\\int\\sec^3x\\,dx$ to both sides gives\n\\begin{align*}\n2\\int\\sec^3x\\,dx&=\\sec x\\tan x+\\ln|\\sec x+\\tan x|+C_1\\\\\n\\implies\n\\int\\sec^3x\\,dx&=\\frac12(\\sec x\\tan x+\\ln|\\sec x+\\tan x|)+C.\n\\end{align*}\n\\eex\n\nWhen integrating arbitrary integer powers of the trigonometric\nfunctions, a common technique is to make use of so-called\n{\\it reduction formulas}.  These are derived using integration\nby parts, often incorporating the kind of computation \nabove.  For instance, let us consider the general problem of\nintegrating $\\sec^nx$, where $n\\ge3$.  Such an  integral contains\nwithin its integrand\nthe factor $\\sec^2x$, which we use in the $dv$ term.\nIntegration by parts can proceed as follows:\n\\begin{alignat*}{3}\nu&=\\sec^{n-2} x&&\\qquad\\qquad&dv&=\\sec^2x\\,dx\\\\\ndu&=(n-2)\\sec^{n-3}x\\,\\sec x \\cdot\\tan x\\,dx&&&v&=\\tan x\\\\\ndu&=(n-2)\\sec^{n-2}x\\,\\tan x\\,dx \n\\end{alignat*}\ngiving us\n\\begin{align*}\n\\int\\sec^nx\\,dx\n&=\\int\\underbrace{\\sec^{n-2}x}_{u}\\underbrace{\\sec^2x\\,dx}_{dv}\\\\\n&=\\sec^{n-2}x\\,\\tan x-\\int(n-2)\\sec^{n-2}x\\,\\tan^2x\\,dx\\\\\n&=\\sec^{n-2}x\\,\\tan x-\\int(n-2)\\sec^{n-2}x\\left(\\sec^2x-1\\right)\\,dx\\\\\n&=\\sec^{n-2}x\\,\\tan x-(n-2)\\int\\sec^nx\\,dx+(n-2)\\int\\sec^{n-2}x\\,dx\\\\\n\\implies\n(n-1)\\int\\sec^nx\\,dx&=\\sec^{n-2}x\\,\\tan x+(n-2)\\int\\sec^{n-2}x\\,dx.\n\\end{align*}\nNow we can divide by $(n-1)$ to get a general reduction formula\n\\begin{equation}\n\\int\\sec^nx\\,dx=\\frac1{n-1}\\,\\sec^{n-2}x\\,\\tan x+\\frac{n-2}{n-1}\\int\n\\sec^{n-2}x\\,dx.\\label{ReductionFormulaForSecant}\\end{equation}\nThis is called a reduction formula because the resulting integral\nis of a lower power of secant.  A quick inspection reveals that\nthis formula is valid for $n=2$ as well, so it is if fact valid\nfor $n\\ge2$.  \n\n\\bex Compute $\\ds{\\int\\sec^5x\\,dx}$.\n\n\\underline{Solution}: Here we will invoke the formula twice:\nonce for $n=5$, and then again for $n=3$ to deal with the\nresulting integral.  That will give an integral of secant\nto the first power, which is one which should be already\nmemorized.\n\\begin{alignat*}{2}\n\\int\\sec^5x\\,dx&=\\frac14\\sec^3x\\,\\tan x+\\frac{3}{4}\\int\\sec^3x\\,dx\n &\\qquad&\\text{($n$=5 in (\\ref{ReductionFormulaForSecant}))}\\\\\n &=\\frac14\\sec^3x\\,\\tan x+\\frac34\\left[\\frac12\\sec x\\tan x+\\frac12\n              \\int\\sec x\\,dx\\right]&\n        &\\text{($n$=3 in (\\ref{ReductionFormulaForSecant}))}\\\\\n &=\\frac14\\sec^3x\\,\\tan x+\\frac38\\sec x\\tan x+\\frac38\n         \\ln|\\sec x+\\tan x|+C.\\end{alignat*}\n\\eex\n\nOther reduction formulas which can be arrived at similarly\ninclude\n\\begin{align}\n\\int\\sin^nx\\,dx&=-\\frac{\\sin^{n-1}x\\,\\cos x}{n}\n       +\\frac{n-1}n\\int\\sin^{n-2}x\\,dx,\n        \\label{ReductionFormulaForSine}\\\\\n\\int\\cos^nx\\,dx&=\\frac{\\cos^{n-1}x\\,\\sin x}{n}\n       +\\frac{n-1}n\\int\\cos^{n-2}x\\,dx.\n        \\label{ReductionFormulaForCosine}\n\\end{align}\n\n\\bex Compute $\\ds{\\int\\cos^65x\\,dx}$.\n\n\\underline{Solution}: Here we cannot use the formula\n(\\ref{ReductionFormulaForCosine}) directly, because our angle does\nnot match our differential.  To compensate, we will\nperform a substitution step first.  Specifically, we will\nlet $u=5x$, so $du=5dx$ and thus $\\frac15\\,du=dx$, giving\n\\begin{alignat*}{2}\n\\int\\cos^65x\\,dx&=\\int\\cos^6u\\cdot\\frac15\\,du\\\\\n&=\\frac15\\int\\cos^6u\\,du\\\\\n&=\\frac15\\left[\\frac{\\cos^5u\\,\\sin u}6+\\frac56\\int\\cos^4u\\,du\\right]\n        &\\qquad&\\text{($n=6$ in (\\ref{ReductionFormulaForCosine}))}\\\\\n&=\\frac{\\cos^5u\\,\\sin u}{30}+\\frac16\\left[\\frac{\\cos^3u\\,\\sin u}{4}\n           +\\frac34\\int\\cos^2u\\,du\\right]\n          &&\\text{($n=4$ in (\\ref{ReductionFormulaForCosine}))}\\\\\n&=\\frac{\\cos^5u\\,\\sin u}{30}+\\frac{\\cos^3u\\,\\sin u}{24}\n           +\\frac18\\left[\\frac{\\cos u\\sin u}2+\\frac12\\int 1\\,du\\right]\n          &&\\text{($n=2$ in (\\ref{ReductionFormulaForCosine}))}\\\\\n&=\\frac{\\cos^5u\\,\\sin u}{30}+\\frac{\\cos^3u\\,\\sin u}{24}\n           +\\frac{\\cos u\\sin u}{16}+\\frac1{16}\\,u+C\\\\\n&=\\frac{\\cos^55x\\,\\sin5x}{30}+\\frac{\\cos^35x\\,\\sin 5x}{24}\n           +\\frac{\\cos 5x\\sin 5x}{16}+\\frac{5x}{16}+C.\n\\end{alignat*}\n\\eex\n\nClearly reduction formulas can be very useful.  Indeed they \nprovide an iterative method for reducing an integral computation,\nstep by step, until---hopefully---a manageable integral appears.\nIn fact in \nboth examples above, we used the reduction formula for one more step\nthan necessary, because it was easier than \nrecomputing $\\int\\sec^3x\\,dx$ or $\\int\\cos^2u\\,du$ as before.\nFurthermore, many of the technical details for finding these\nintegrals are built into the reduction formulas.\n\nAs useful as the reduction formulas are, they have a couple of\nminor drawbacks.  First, when the angle does not match the differential,\nsome substitution needs to be performed to compensate.\nSecond---and more serious---is that any attempt to memorize these is likely\nto result in error.  Thus the student of calculus needs to learn\nthe earlier methods and be able to perform such calculations\nunaided, and also know that these reduction formulas (and others)\nare available and know how to use them.\\footnote{%\n%%% FOOTNOTE\nSuch formulas can be found in most engineering/science calculus\ntexts, as well as books containing tables of integration formulas\nsuch as the {\\it CRC Standard Mathematical Tables and Formulae}.\n%%% END FOOTNOTE\n}\n\nNow we consider integrals of following three forms, where $m\\ne n$:\n$$\\int\\sin mx\\,\\sin nx\\,dx,\n\\qquad\\qquad\n\\int\\sin mx\\,\\cos nx\\,dx,\n\\qquad\\qquad\n\\int\\cos mx\\,\\cos nx\\,dx.$$\nWhat distinguishes these is that the angles of the trigonometric functions\ndo not agree.  There are two methods for computing these:\nintegration by parts, and utilizing the following trigonometric identities:\n\\begin{align}\n\\sin A\\cos B&=\\frac12\\left[\\sin(A-B)+\\sin(A+B)\\right],\\label{SinACosB}\\\\\n\\sin A\\sin B&=\\frac12\\left[\\cos(A-B)-\\cos(A+B)\\right],\\label{SinASinB}\\\\\n\\cos A\\cos B&=\\frac12\\left[\\cos(A-B)+\\cos(A+B)\\right].\\label{CosACosB}\n\\end{align}\nFor obvious reasons, these are called {\\it product-sum formulas}.\nThese follow from adding or subtracting\n(\\ref{Sine(A+B)}), (\\ref{Sine(A-B)}), (\\ref{Cosine(A+B)}),\nand (\\ref{Cosine(A-B)}), which we repeat here for reference:\n\\begin{align*}\n\\sin(A+B)&=\\sin A\\cos B+\\sin B\\cos A,\\\\\n\\sin(A-B)&=\\sin A\\cos B-\\sin B\\cos A,\\\\\n\\cos(A+B)&=\\cos A\\cos B-\\sin A\\sin B,\\\\\n\\cos(A-B)&=\\cos A\\cos B+\\sin A\\sin B.\\end{align*}\nFor instance, (\\ref{SinACosB}) follows from adding the\nfirst two of these and solving for $\\sin A\\cos B$.  All\nthree, (\\ref{SinACosB})--(\\ref{CosACosB}), are left \nto the exercises.\n\n\\bex Compute $\\ds{\\int\\sin2x\\cos5x\\,dx}$.\n\n\\underline{Solution}: Here we use (\\ref{SinACosB}),\nwith $A=2x$ and $B=5x$:\n\\begin{align*}\n\\int\\sin2x\\cos5x\\,dx&=\\int\\frac12[\\sin(2x-5x)+\\sin(2x+5x)]\\,dx\\\\\n                    &=\\int\\frac12[\\sin(-3x)+\\sin7x]\\,dx\\\\\n                    &=\\int\\frac12[-\\sin3x+\\sin7x]\\,dx\\\\\n                    &=\\frac13\\cos3x-\\frac17\\cos7x+C.\\end{align*}\n\\eex\n\nThe method above has the drawback that the solution does not\ncontain the same angles as the integrand. One can\nget back to the original angles using the formulas\n\\begin{align*}\n\\cos3x&=\\cos(5x-2x)=\\cos5x\\cos2x+\\sin5x\\sin2x,\\\\\n\\cos7x&=\\cos(5x+2x)=\\cos5x\\cos2x-\\sin5x\\sin2x.\\end{align*}\nAlternatively, an integration by parts argument leaves intact\nthe angles.  It requires two integration by parts steps,\nand we need to solve for the integral.  Furthermore, \nwe have to make the analogous substitution for $u$ both\ntimes, and for $dv$ both times.  By analogous, here\nwe mean using the same angle, $2x$ or $5x$, as the argument\nof the trigonometric function both times.\nIf we always let the $u$-term have angle $2x$,\nand the $dv$-term have angle $5x$, \neventually the solution there will be\n$$\\int\\sin2x\\cos5x\\,dx\n  =\\frac5{21}\\sin2x\\sin5x+\\frac2{21}\\cos2x\\cos5x+C.$$\n\\newpage\n\\begin{center}\n\\underline{\\Large{\\bf Exercises}}\\end{center}\n\n\\begin{multicols}{2}\nEvaluate the following integrals.\n\\begin{enumerate}\n\\item $\\ds{\\int\\sin x\\cos x\\,dx}$\n\\item $\\ds{\\int\\sin^2x\\cos x\\,dx}$\n\\item $\\ds{\\int\\sin x\\cos^2x\\,dx}$\n\\item $\\ds{\\int\\sin^3x\\cos^2x\\,dx}$\n\\item $\\ds{\\int\\sin^4x\\cos^5x\\,dx}$\n\\item $\\ds{\\int\\frac{\\sin^3x}{\\cos^2x}\\,dx}$\n\\item $\\ds{\\int\\frac{\\sin^3x}{\\cos^2x+1}\\,dx}$\n\\item $\\ds{\\int \\sin^4x\\cos^5x\\,dx}$\n\\item $\\ds{\\int\\sin^32x\\cos^{15}2x\\,dx}$\n\\item $\\ds{\\int\\frac{\\sin^2x}{\\cos x}\\,dx}$\n\n\n\n\n\\item $\\ds{\\int\\sin^3x\\ln|\\sin x|\\,dx}$\n\\item $\\ds{\\int\\cos^3x\\ln|\\sin x|\\,dx}$\n\\end{enumerate}\n\\end{multicols}\n\n\n\\newpage\n\\section{Trigonometric Substitution\\label{TrigSubSection}}\nIn this section we explore how integrals can sometimes be\nsolved by making some clever substitutions involving\ntrigonometric functions, even though the original integrals\nthemselves do not involve such functions.  \nBefore developing the general mechanics, the example below\nis offered for motivation:\n\n\\bex Compute $\\ds{\\int\\frac{\\sqrt{1-x^2}}x\\,dx}$.\n\n\\underline{Solution}:  Note first that this integral will not\nsimply yield to earlier techniques.  (The reader is welcome to \ntry, to see where those methods eventually fall short.)\n\nNote also that, due to the square root, \nwe require $-1\\le x\\le 1$.  In fact we also cannot have $x=0$, but\nthat constraint will be consistent with our new integral upon substitution.\nIn fact it is the radical which is giving us the most difficulty here.\n\nThe solution to that problem is to realize that $[-1,1]$ is exactly\nthe range of the function $\\sin\\theta$.  Moreover, if we\nallow $\\theta\\in[-\\pi/2,\\pi/2]$, then we have the mappings\nfrom $\\theta$ to $x$ and back as follows:\n\n\\begin{center}\n\\begin{pspicture}(-6,-.5)(6,.5)\n\\rput(-5,0){$\\ds{\\left[-\\frac{\\pi}2,\\frac{\\pi}2\\right]}$}\n\\psline{|->}(-4,0)(-1,0)\n\\rput(-2.5,.3){$\\sin\\theta$}\n\\rput(0,0){$[-1,1]$}\n\\psline{|->}(1,0)(4,0)\n\\rput(5,0){$\\ds{\\left[-\\frac{\\pi}2,\\frac{\\pi}2\\right]}$}\n\\rput(2.5,.3){$\\sin^{-1}x$}\n\\end{pspicture}\n\\end{center}\n\nWe will use the substitution $x=\\sin\\theta$ in the integral above,\nwith the understanding that $\\theta\\in[-\\pi/2,\\pi/2]$ (excluding zero\ndue to the denominator).  As usual, it is also crucial to write \nthe differential in terms of the new variable:\n\\begin{align*}\nx&=\\sin\\theta\\\\\n\\implies dx&=\\cos\\theta\\,d\\theta.\\end{align*}\nThus\n$$\\int\\frac{\\sqrt{1-x^2}}x\\,dx\n=\\int\\frac{\\sqrt{1-\\sin^2\\theta}}{\\sin\\theta}\\,\\cos\\theta\\,d\\theta.$$\nSince we have chosen the range $\\theta\\in[-\\pi/2,\\pi/2]$ to get\nour range for $x\\in[-1,1]$ (again excluding zero), we have\nangles in the first and fourth quadrants.  In those quadrants, in\nfact, the cosine is nonnegative.  Thus\n$$\\theta\\in\\left[-\\frac{\\pi}2,\\frac{\\pi}2\\right]\n\\implies\\sqrt{1-\\sin^2\\theta}=\\sqrt{\\underbrace{\\cos^2\\theta}_{\\ge0}}\n=\\cos\\theta.$$\nSummarizing our work so far, and then continuing, we get\n\\begin{align*}\n\\int\\frac{\\sqrt{1-x^2}}x\\,dx\n&=\\int\\frac{\\sqrt{1-\\sin^2\\theta}}{\\sin\\theta}\\,\\cos\\theta\\,d\\theta\n=\\int\\frac{\\cos\\theta}{\\sin\\theta}\\cos\\theta\\,d\\theta\\\\\n&=\\int\\frac{\\cos^2\\theta}{\\sin\\theta}\\,d\\theta\n=\\int\\frac{1-\\sin^2\\theta}{\\sin\\theta}\\,d\\theta\n=\\int\\left[\\csc\\theta-\\sin\\theta\\right]\\,d\\theta\\\\ \\vphantom{\\int}\n&=\\ln|\\csc\\theta-\\cot\\theta|+\\cos\\theta+C.\n\\end{align*}\nNow we have a trigonometric form of the antiderivative, but of course\nthe original integral was in $x$ and not $\\theta$.  While we will\ndevelop a more visual method in the subsections, here we will note that\n$\\sin\\theta=x$, and $\\cos\\theta=\\sqrt{1-\\sin^2\\theta}=\\sqrt{1-x^2}$.\nOf course once we have the sine and cosine functions, we have all\nthe trigonometric functions.  Summarizing again, but this time\nadding the final substitution in $x$, we have\n$$\\int\\frac{\\sqrt{1-x^2}}x\\,dx\n=\\ln|\\csc\\theta-\\cot\\theta|+\\cos\\theta+C\n=\\ln\\left|\\frac1x-\\frac{\\sqrt{1-x^2}}x\\right|+\\sqrt{1-x^2}+C.$$\n\\eex\n\nThe technique in this section---assuming the original\nvariable of integration is $x$---can be somewhat summarized, though\nthe details are rather sophisticated.  A summary could be\nwritten as\nfollows:\n\\begin{enumerate}\n\\item Use an appropriate {\\it trigonometric substitution}, i.e., \nlet $x$ be in terms of some trigonometric function of an\nangle $\\theta$.  Substitution for $dx$ follows.\n\\item Simplify the trigonometric expression in the resulting \nintegral.  In particular, if there were radicals\nin the original integral they should usually not be present in the \nsimplified trigonometric integral.\n\\item Solve the trigonometric integral.  The solution will be\nin terms of $\\theta$.\n\\item Substitute back in terms of $x$, as dictated by the \noriginal substitution where $x$-terms were replaced by $\\theta$-terms.\n\\end{enumerate}\n\nIt should be noted at the outset that the trigonometric integrals\nwhich arise here may require some re-writing before they succumb to \nour trigonometric integral methods of Section~\\ref{TrigIntsSection}.\nFurthermore, a problem which naturally gives rise to trigonometric\nsubstitution (as in the previous example) may or may not\nyield a simple trigonometric integral.  However, all trigonometric\nintegrals we will encounter here are of classes we considered\nin Section~\\ref{TrigIntsSection}, so ultimately those techniques\nequipped us for our work here.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\newpage\n\\section{Partial Fractions and Integration\\label{PartialFracSection}}\nIn this section we are interested in techniques for computing\nintegrals of the form\n\\begin{equation}\n\\int\\frac{P(x)}{Q(x)}\\,dx,\\label{GeneralRationalForPFD}\n\\end{equation}\nwhere $P(x)$ and $Q(x)$ are polynomials. \nThis is not in general a simple problem, unless \nthe integral in (\\ref{GeneralRationalForPFD}) is from\nvery particular classes.  However, with the techniques\nwe explore here, we can break $\\frac{P(x)}{Q(x)}$ into\nsimpler fractions whose integrals are relatively easy.\nTo see an advantage of such an approach, consider the following example.\n\\bex Compute $\\ds{\\int\\frac{5x-1}{x^2-x-2}\\,dx}$.\n\n\\underline{Solution}: Note that the numerator is not a \nsimple (constant number)\nmultiple of the derivative of the denominator, so \nsubstitution will not give a simple $\\int\\frac1u\\,du$-form.\n\nHowever, it  happens that\n\\begin{equation}\\frac{5x-1}{x^2-x-2}\n  =\\frac{5x-1}{(x-2)(x+1)}\n  =\\frac2{x+1}+\\frac3{x-2}.\\label{FirstPFDExamplePFD}\n\\end{equation}\nThus\n\\begin{align*}\n\\int\\frac{5x-1}{x^2-x-2}\\,dx\n & =\\int\\left(\\frac2{x+1}+\\frac3{x-2}\\right)\\,dx\\\\\n & =2\\ln|x+1|+3\\ln|x-2|+C\\\\\n & =\\ln\\left|(x+1)^2(x-2)^3\\right|+C.\\end{align*}\n\\eex\n\nIn this section we will develop the methods needed to \nfind expansions of fractions such as \nin (\\ref{FirstPFDExamplePFD}). The idea is to reverse\nthe high school\nalgebra exercises, which would have us {\\it combine} \nsums or differences of fractions into a single fraction.  For \npurposes of integral calculus, it is almost always\nbetter to instead deal with several, simpler fractions than\ntheir combination into a single, more complicated fraction.\n\nA significant amount of our work in this section will be\nalgebraic, specifically, developing the method of decomposing\na fraction $P(x)/Q(x)$ into simpler, ``partial fractions.''\nIn order for the method to work, we will require $P(x)$ to\nhave lower degree $Q(x)$. (If the degree of $P$ is at least\nthat of $Q$, we can use long division to write the function\nas a polynomial plus $r(x)/Q(x)$, where the degree of $r$ is\nless than that of $Q$.)\n\n\nThough not crucial for the calculus, we will spend the next subsection \nlooking roughly at the theory behind the general\nform of these partial\nfraction decompositions (PFD's), in hopes it will help\nreinforce the rules themselves.  \nIn Subsection~\\ref{RulesForPDFSubsection} we will \ndefinitively write the\nrules for PFD's without reference to integrals.\nFinally, we will see how to solve for the coefficients \nof a particular PFD, in the context of computing antiderivatives\nof these.\n\n\\subsection{Theory Behind the Forms of PFD's (Optional)}\nThe argument here is usually omitted from calculus texts,\nand instead left to linear algebra courses.  However, the basic intuition \nis not difficult so we include it here, though the real work\nis in later subsections.  In all of these we\nare looking at functions\n\\begin{equation}\n\\frac{P(x)}{Q(x)},\\qquad \\text{$P$ and $Q$ polynomials, degree $P$ $<$\n                                 degree $Q$}.\n\\label{DegP<DegQ}\\end{equation}\nBefore stating the general rules for PFD's, we look at several examples\nillustrating the underlying theory.\n\n\\bex For this example, we will argue in steps.\n\\begin{enumerate}\n\\item Consider all functions of the form \n\\begin{equation}\\frac{a x+b}{(x+1)(x-2)}.\\label{Ex1ForProofOfPFD-Together}\n\\end{equation}\n\\item Now there are two linearly independent\\footnotemark\nfunctions, specifically $\\frac{x}{(x+1)(x-2)}$\nand $\\frac1{(x+1)(x-2)}$ which---with linear combinations---can give us\nany such function (\\ref{Ex1ForProofOfPFD-Together}).  Indeed,\n$$\\frac{ax+b}{(x+1)(x-2)}=a\\cdot\\left[\\frac1{(x+1)(x-2)}\\right]\n                         +b\\cdot\\left[\\frac{x}{(x+1)(x-2)}\\right].$$\nIn a linear-algebraic sense, we would say the functions of the\nform (\\ref{Ex1ForProofOfPFD-Together}) form a 2-dimensional space\n(or 2-dimensional {\\it vector space}), because to specify such\na function requires two constants, $a$ and $b$.\n\n\\item Now instead consider another 2-dimensional space of functions\ngiven by linear combinations of the form\n\\begin{equation}\n\\frac{A}{x+1}+\\frac{B}{x-2}\n=A\\cdot\\left[\\frac1{x+1}\\right]+B\\cdot\\left[\\frac1{x-2}\\right].\n\\label{Ex1ForProofOfPFD-Apart}\n\\end{equation}\n\\item \nThe functions $\\frac1{x+1}$ and $\\frac{1}{x-2}$ are indeed also linearly\nindependent, so the set of all functions of the form\n(\\ref{Ex1ForProofOfPFD-Apart}) also forms a 2-dimensional\nvector space; to specify any such function requires\nspecifying two constants, $A$ and $B$.\n\n\\item Now notice that \n$$\\frac{A}{x+1}+\\frac{B}{x-2}\n=\\frac{A(x-2)+B(x+1)}{(x+1)(x-2)}\n=\\frac{(A+B)x+(-2A+B)}{(x+1)(x-2)},$$\nwhich is of form (\\ref{Ex1ForProofOfPFD-Together})\nwith $a=A+B$ and $b=-2A+B$.  In other words, any function of the\nform (\\ref{Ex1ForProofOfPFD-Apart}) can also be written in the \nfrom (\\ref{Ex1ForProofOfPFD-Together}).\n\\item This tells us that the two-dimensional space\nof functions $\\frac{A}{x+1}+\\frac{B}{x-2}$ is contained in the\ntwo-dimensional space of functions $\\frac{ax+b}{(x+1)(x-2)}$.\nIt is a fact of linear algebra that the only way for a\ntwo-dimensional space to be contained in another two-dimensional\nspace is for them to be the same spaces.  (Think about \na plane being contained in another plane, and realize that\nthey must then be the same plane.)\n\n\\item Finally, since (by 6 above) the space of all functions\nof the form $\\frac{ax+b}{(x+1)(x-2)}$ is the {\\bf same} as the \nspace of all functions of the form\n$\\frac{A}{x+1}+\\frac{B}{x-2}$, it follows that\nany function of the form $\\frac{ax+b}{(x+1)(x-2)}$\ncan also be written in the form $\\frac{A}{x+1}+\\frac{B}{x-2}$.\n\\end{enumerate}\n\\eex\n\\footnotetext{We call functions $f_1,f_2,\\cdots,f_n$ \n{\\it linearly independent} if and only if \nit is impossible to write any of these as linear combinations\nof the others. In other words, we {\\it exclude} cases where there\nexist {\\it constants} $a_1,\\cdots,a_{k-1},\\ a_{k+1},\\cdots,a_n\\in\\Re$\nsuch that\n\\begin{align*}\nf_k&=a_1f_1+a_2f_2+\\cdots+a_{k-1}f_{k-1}+a_{k+1}f_{k+1}+\\cdots+a_nf_n,\\qquad\ni.e.,\\\\\n(\\forall x)[\\qquad f_k(x)&=a_1f_1(x)+a_2f_2(x)+\\cdots+\n          a_{k-1}f_{k-1}(x)+\n          a_{k+1}f_{k+1}(x)+\\cdots+a_{n}f_{n}(x)\\qquad].\n\\end{align*}\n}\n\nNotice that functions of the form (\\ref{Ex1ForProofOfPFD-Together})\nare indeed also of the form $P(x)/Q(x)$ where $P$ is of degree\nless than $Q$, since the degree of $P$ is at most 1 (zero if $a=0$) and the\ndegree of $Q$ is 2.\n\nThe argument above guarantees that a PFD such as \n(\\ref{FirstPFDExamplePFD}) exists.  It is more desirable\nfor integration purposes to have form (\\ref{Ex1ForProofOfPFD-Apart})\nthan (\\ref{Ex1ForProofOfPFD-Together}).\n\n\\bex An argument similar to that of the previous example shows that\nthe following forms give exactly the same functions:\n\\begin{equation}\\frac{ax^2+bx+c}{(x+1)(x+2)(x+3)}=\\frac{A}{x+1}+\n\\frac{B}{x+2}+\\frac{C}{x+3}.\\label{Ex2ForProofOfPFD-Both}\n\\end{equation}\nOf course $a,b,c$ are likely to differ from $A,B,C$.  Here the\nunderlying sets of linearly independent functions are, respectively,\n\\begin{align*}U&=\\left\\{\\frac{x^2}{(x+1)(x+2)(x+3)}, \n           \\frac{x}{(x+1)(x+2)(x+3)},\n           \\frac{1}{(x+1)(x+2)(x+3)}\\right\\},\\\\\n              V&=\\left\\{\\frac1{x+1},\\frac1{x+2},\\frac1{x+3}\\right\\}.\n\\end{align*}\nBoth sets of vectors span\\footnote{%%%\n%%% FOOTNOTE\nThe noun form of {\\bf span} has a precise technical meaning.  The {\\it span}\nof ``vectors'' $v_1,v_2,\\cdots,v_n$ is the set of all possible\nlinear combinations of those vectors.  Thus for example\n$$\\text{Span}\\left\\{\\frac1{x+1},\\frac1{x+2},\\frac1{x+3}\\right\\}\n=\\left\\{\\left.a\\cdot\\left[\\frac1{x+1}\\right]+b\\cdot\\left[\\frac1{x+2}\\right]\n        +c\\cdot\\left[\\frac1{x+3}\\right]\\ \\right| \\ a,b,c\\in\\Re\\right\\}.$$\n\nWe would then say that the functions (vectors, in the linear algebra sense)\n$\\frac1{x+1},\\frac1{x+2},\\frac1{x+3}$, taken together, {\\it span} \nthe set described above.\n%%% END FOOTNOTE\n} 3-dimensional spaces.\nIt is not hard to see that functions on the right-hand side of\n(\\ref{Ex2ForProofOfPFD-Both}) can also be in the form on the left.\nIndeed, if we combine the fractions on the right, we get\n$$\\frac{A}{x+1}+\\frac{B}{x+2}+\\frac{C}{x+3}\n=\\frac{\\overbrace{A(x+2)(x+3)}^{\\text{degree }\\le2}+\n        \\overbrace{B(x+1)(x+3)}^{\\text{degree }\\le2}\n        +\\overbrace{C(x+1)(x+2)}^{\\text{degree }\\le2}}\n      {(x+1)(x+2)(x+3)},$$\nwhich gives us a polynomial in the numerator with degree\nat most 2, as on the left-hand side of (\\ref{Ex2ForProofOfPFD-Both}).\nHere we have the span of $V$ contained in the span of $U$,\nthough they are both 3-dimensional spaces.  Thus they must be\nthe same spaces (we have one 3-dimensional space inside of another,\nso they must be the same!), so in fact, anything written like\nthe left-hand side of (\\ref{Ex2ForProofOfPFD-Both})\ncan be written like the right-hand side.  (In a later subsection\nwe will show how to find $A,B,C$ given $a,b,c$.)\n\nIt should be clear that integrating a function written like the\nright-hand side of (\\ref{Ex2ForProofOfPFD-Both}) is likely much simpler \nthan integrating one in the form on the left.\n\\eex\n\n\\bex Next we argue that the following forms describe the same (space of)\nfunctions:\n\\begin{equation}\n\\frac{ax^2+bx+c}{(x+7)^3}\n  =\\frac{A}{x+7}+\\frac{B}{(x+7)^2}+\\frac{C}{(x+7)^3}.\n\\label{Ex3ForProofOfPFD-Both}\n\\end{equation}\nThe underlying sets of linearly independent functions are, \nrespectively,\n$\\left\\{\\frac{x^2}{(x+7)^3},\\frac{x}{(x+7)^3},\\frac1{(x+7)^3}\\right\\}$\nand\n$\\left\\{\\frac1{x+7},\\frac1{(x+7)^2},\\frac1{(x+7)^3}\\right\\}$,\nboth spanning 3-dimensional spaces.  To show they are the same\nspaces, we note that\n$$\\frac{A}{x+7}+\\frac{B}{(x+7)^2}+\\frac{C}{(x+7)^3}\n  =\\frac{A(x+7)^2+B(x+7)+C}{(x+7)^3},$$\nwhich eventually simplifies to the form on the left-hand side of \n(\\ref{Ex3ForProofOfPFD-Both}). Arguing as before, the underlying\nsets of linearly independent functions must span the same\n3-dimensional spaces, so anything of the form on the left-hand side\nof (\\ref{Ex3ForProofOfPFD-Both}) can be written also in the\nform on the right-hand side.\n\\eex\n\n\\bex For our last example, we claim the following\nforms give the same functions:\n\\begin{equation}\n\\frac{ax^4+bx^3+cx^2+dx+e}{x^3(x^2+1)}\n=\\frac{A}x+\\frac{B}{x^2}+\\frac{C}{x^3}+\\frac{Dx+E}{x^2+1}.\n\\label{Ex4ForProofOfPFD-Both}\n\\end{equation}\nHere the spanning sets of linearly independent functions are respectively\n\\begin{align*}\nU&=\\left\\{\\frac{x^4}{x^3(x^2+1)},\\ \\frac{x^3}{x^3(x^2+1)},\\ \n\\frac{x^2}{x^3(x^2+1)},\\ \\frac{x}{x^3(x^2+1)},\\ \\frac{1}{x^3(x^2+1)}\\right\\},\\\\\nV&=\\left\\{\\frac1x,\\ \\frac1{x^2},\\ \\frac1{x^3},\\ \\frac{x}{x^2+1},\\ \\frac1{x^2+1}\n   \\right\\}.\n\\end{align*}\nAgain, the form on the right of (\\ref{Ex4ForProofOfPFD-Both})\ncan be rewritten as below, simplifying into the form on the left-hand\nside of (\\ref{Ex4ForProofOfPFD-Both}) as\n$$\\frac{Ax^2(x^2+1)+Bx(x^2+1)+C(x^2+1)+(Dx+E)(x^2+1)}{x^3(x^2+1)}.$$\n(Note that this  has numerator of degree at most 4.)\nBecause both sides of \n(\\ref{Ex4ForProofOfPFD-Both}) must therefore\ndescribe exactly the same functions\nin a 5-dimensional vector space, it follows that anything\nwritten in the form on the left of (\\ref{Ex4ForProofOfPFD-Both})\ncan also be written in the form on the right.\n\\eex\n\nIn the next subsection we generalize the logic of\nthe examples above to write exact rules for the \nform of a PFD based upon the original fraction's denominator.  \nThen in Subsection~\\ref{SubsecForFindingIntsWPFD's}\nwe look at three methods of finding\nthe coefficients, $A$, $B$, $C$, etc., of the PFD expansion,\nand immediately apply the methods to problems of computing integrals of\nsuch functions.\n\\newpage\n\\subsection{Partial Fraction Decompositions: The Rules\n\\label{RulesForPDFSubsection}}\n\nIt is a fact of algebra (corollary to the Fundamental\nTheorem of Algebra) that any polynomial with real coefficients can be \nfactored uniquely---up to rearrangement of \nmultiplicative constants---into powers of linear terms $(ax+b)^n$\nand powers of irreducible quadratic\\footnote{%%%\n%%% FOOTNOTE\nIt is easy to see when a quadratic term is ``irreducible\nover the real numbers,'' meaning we cannot write\nit as $(ex+f)(gx+h)$, where $e,f,g,h\\in\\Re$, the latter being\nequivalent to there being real numbers $\\alpha,\\beta$\nsuch that the polynomial is zero there\n(i.e., at $\\alpha=-f/e$, $\\beta=-h/g$). Using the quadratic formula,\nit is plain that no such real solutions to the quadratic being\nzero occur if and only if $b^2-4ac<0$ (i.e., when the term under the\nradical in the quadratic formula is negative).}\n%%% END FOOTNOTE\nterms $(ax^2+bx+c)^m$ with real coefficients.  So for instance, \n$$x^3-x^2+x-1=(x-1)(x^2+1),$$\nand there is no other way to factor it, except for \ninstance $2(x-1)(\\frac12x^2+\\frac12)$, etc.\nWith that in mind, the rules for partial fraction decompositions\nfollow.\n\nFirst, we are given a rational function $\\frac{P(x)}{Q(x)}$,\nwhere $P$ and $Q$ are polynomials.\n\\begin{enumerate}\\setcounter{enumi}{-1}\n\\item In 1 and 2 below we assume deg $P <$ deg $Q$.\n      If the deg $P \\ge$ deg $Q$, then first we apply\n      poynomial long division to achieve\n      $$\\frac{P(x)}{Q(x)}=p(x)+\\frac{r(x)}{Q(x)},$$\n      where $p,r$ are polynomials and deg $r <$ deg $Q$.\n      Then the following rules apply to $\\frac{r(x)}{Q(x)}$.\n\\item If $(ax+b)^n$, where $a\\ne0$ occurs as a factor in $Q(x)$, then\n      the partial fraction decomposition (PFD) of $\\frac{P(x)}{Q(x)}$\n      will contain terms\n      $$\\frac{A_1}{ax+b}+\\frac{A_2}{(ax+b)^2}+\\cdots+\\frac{A_n}{(ax+b)^n}.$$\n\\item If $ax^2+bx+c$ is an irreducible quadratic, and\n      $(ax^2+bx+c)^m$ occurs as a factor in $Q(x)$, then\n      the PFD of  $\\frac{P(x)}{Q(x)}$ will contain terms\n      $$\\frac{A_1x+B_1}{ax^2+bx+c}\n          +\\frac{A_2x+B_2}{(ax^2+bx+c)^2}\n          +\\cdots+\\frac{A_mx+B_m}{(ax^2+bx+c)^m}.$$\n\\end{enumerate}\n\nThe application of these rules can be somewhat confusing at first,\nso we will look at several examples before proceeding to \nsolve for the coefficients $A_1, B_1$, etc.  \nFor the second case, we will mostly be interested in \nirreducible quadratics of the form $x^2+k^2$, where $k>0$.\nNote that\nwe will usually use letters without subscripts, such as\n$A,B,C$, and so on for our PFD coefficients (to be found later).\n\n\\bex Write the partial fraction decompositions for the given \nrational functions:\n\\begin{itemize}\n\\item $\\ds{\\frac{3x^5-11x^3+15x-2}{(x+1)^2(x-3)^4}\n  =\\frac{A}{x+1}+\\frac{B}{(x+1)^2}+\\frac{C}{x-3}\n    +\\frac{D}{(x-3)^2}+\\frac{E}{(x-3)^3}+\\frac{F}{(x-3)^4}}$.\n\\item $\\ds{\\frac1{(x+1)^2(x-3)^4}\n=\\frac{A}{x+1}+\\frac{B}{(x+1)^2}+\\frac{C}{x-3}\n    +\\frac{D}{(x-3)^2}+\\frac{E}{(x-3)^3}+\\frac{F}{(x-3)^4}}$.\n\\end{itemize}\nIn both cases, we had a polynomial of degree less than\n6 divided by a polynomial of degree 6, so ``Rule 0''\nis not invoked.  We also had two factors of $x+1$\nin the denominator, so we needed a constant over the\nfirst power, plus another constant over the second power,\nof $x+1$.  With $(x-3)$ appearing to the third power in \nthe denominator, we needed a constant over each of the\nfirst, second, and third powers of $x+3$. (Of course the\nchoice of constants  $A,B,C,D,E$ will be different for these\ntwo functions above, but the form of their PFD's is the same.) \n\\eex\n\nWe do not want to be redundant in our PFD's, so if $Q(x)$\ncontains the factor $(x-3)^4$ but does not contain $(x-3)^5$,\nfor instance, we require constants divided by\n$(x-3)$, $(x-3)^2$, $(x-3)^3$ and $(x-3)^4$ (but not $(x-3)^5$).\nNow one could say that\nsuch a $Q(x)$ also contains $(x-3)^2$, but we do not then\nrequire in our PFD constants divided by $(x-3)$ and $(x-3)^2$ {\\it again},\nsince these are already taken care of by those required by\nthe factor $(x-3)^4$ in $Q(x)$.\n\nTo rephrase the rules in light of the last paragraph,\nif exactly $n$ factors of $(ax+b)$ appear in $Q(x)$, then\nthe PFD  contains terms \n$\\frac{A_1}{ax+b}+\\cdots+\\frac{A_n}{(ax+b)^n}$.\nIf exactly  $m$ factors of $(ax^2+bx+c)$ appear, with $b^2-4ac<0$,\nthen the PFD contains terms\n$\\frac{A_1x+B_1}{ax^2+bx+c}+\\cdots+\\frac{A_mx+B_m}{(ax^2+bx+c)^m}$.\n\\bex Here are more PFD expansion forms.  (We do not solve for the \n     coefficients yet.)\n\\begin{itemize}\n\\item $\\ds{\\frac{x^4+x+1}{x^3(x^2+9)^2}\n     =\\frac{A}x+\\frac{B}{x^2}+\\frac{C}{x^3}\n      +\\frac{Dx+E}{x^2+9}+\\frac{Fx+G}{(x^2+9)^2}}$.\n\\item $\\ds{\\frac1{(x^2+1)(x^2+4)}=\\frac{Ax+B}{x^2+1}+\\frac{Cx+D}{x^2+4}}$.\n\\item $\\ds{\\frac{x^5-8}{x(2x+1)^2(9-x)^3}\n =\\frac{A}x+\\frac{B}{2x+1}+\\frac{C}{(2x+1)^2}\n   +\\frac{D}{9-x}+\\frac{E}{(9-x)^2}+\\frac{F}{(9-x)^3}}$.\n\\item $\\ds{\\frac2{x^2-5}=\\frac2{\\left(x-\\sqrt5\\right)\\left(x+\\sqrt5\\right)}\n     =\\frac{A}{x-\\sqrt5}+\\frac{B}{x+\\sqrt5}}$.\n\\item $\\ds{\\frac1{x^4-1}=\\frac1{(x^2-1)(x^2+1)}\n       =\\frac1{(x+1)(x-1)(x^2+1)}\n       =\\frac{A}{x+1}+\\frac{B}{x-1}+\\frac{Cx+D}{x^2+1}}$.\n\\end{itemize}\n\\eex\n\nThe last two PFD's above required us to factor the denominators before\nwe started to implement the rules.  Note that we must be careful\nto identify factors which are truly distinct.  Consider the following:\n$$\\frac1{x(x-3)(3x-9)}=\\frac1{3x(x-3)^2}\n=\\frac{A}x+\\frac{B}{x-3}+\\frac{C}{(x-3)^2}.$$\nThe factors $(x-3)$ and $(3x-9)$ were not really distinct factors,\nbut were constant multiples of eachother.  If we do not notice this\nwe will find ourselves attempting a PFD \nwith $\\frac{A}{x}+\\frac{B}{x-3}+\\frac{C}{3x-9}$, but\nthe ``$B$'' and ``$C$'' terms are not independent, so we will miss\none dimension of possibilities for our PFD.  \nNote also that the\nfactor $\\frac13$ can be included in the first PFD term\n(i.e., we could replace $\\frac{A}x$ with $\\frac{A}{3x}$, of course giving\na different ``$A$''), or its influence absorbed into the $A$, $B$ and $C$\nterms.  We will usually opt for the latter approach (as we did above).\n\n\\subsection{Finding the Coefficients for PFD's\n\\label{SubsecForFindingIntsWPFD's}}\nThere are two main methods, and one auxiliary method, for finding\nthe coefficients $A$, $B$, etc., for a PFD.  The most efficient\nmethod for a particular PFD is usually a mixture of the two \nmain methods; perhaps the first method can be used to find $A$\nand $C$, and the second to find $B$, for instance.\nEfficiently \ncomputing the coefficients is thus somewhat of an art.\\footnote{%%%\n%%% FOOTNOTE\nIn fact either method is---strictly \nspeaking---sufficient, and indeed there are textbooks which\nteach only one or the other method.  However, trying to fit a particularly\ncomplicated PFD into any single method will make for much more difficult\ncomputations than are necessary. That said, for computer programming one\nwould likely choose one method and let the computer calculate the coefficients\nby ``brute force.''} \n%%% END FOOTNOTE\n\nThe methods are based upon some properties of polynomials.  \nConsider two polynomials \n\\begin{align*}\n f(x)&=a_nx^n+a_{n-1}x^{n-1}+\\cdots+a_2x^2+a_1x+a_0,\\\\\n g(x)&=b_mx^m+b_{m-1}x^{m-1}+\\cdots+b_2x^2+b_1x+b_0.\\end{align*}\nThe statement that  $f(x)=g(x)$ is an ``equality of polynomials,'' i.e., \nthat $f(x)$ and $g(x)$ are the {\\it same} polynomial is\nequivalent to each of the following two conditions (separately):\\footnotemark\n%%% FOOTNOTE\n\\footnotetext{Some texts use the notation $f(x)\\equiv g(x)$, read\n``$f(x)$ is identically equal to $g(x)$.''  In other words, \n$f(x)$ and $g(x)$ are the same functions.\nThe word {\\it identically}\nis in the spirit of, for instance, trigonometric identities,\nso one could write for example $\\sin^2\\theta+\\cos^2\\theta\\equiv1$.\nOf course we have a different use of the symbol ``$\\equiv$,''\nand will thus refrain from using it in this context, but the\nreader should be aware of this common alternative use of the\nsymbol.} \n%%% END FOOTNOTE\n\\begin{enumerate}\n\\item $(\\forall x\\in\\Re)[f(x)=g(x)]$.  In other words, $f$ and $g$\n      are the same functions.\n\\item $(\\forall i\\in\\{1,2,\\cdots,\\max\\{m,n\\}\\})[a_i=b_i]$, that is, all the\n      coefficients are the same.  (Note that it is possible, for \n      instance, that $m<n$, in which case we just take \n      $b_{m+1},\\cdots,b_n=0$.)\n\n\\end{enumerate}\nFurthermore, if $f(x)$ and $g(x)$ are the same polynomials, then\n$f'(x)=g'(x)$, $f''(x)=g''(x)$, $f'''(x)=g'''(x)$ $\\cdots$, in the \nsense of being the same polynomials, and so 1 and 2 from above\napply to these derivatives as well.\n\nOur first method will exploit 1, the second 2, and the auxiliary\nmethod will make use of\nfinal observation about derivatives. The first method\nessentially ``probes'' the two polynomials at different points,\nusually chosen strategically, to get some quick information\nout of a polynomial equality, and is often called an\n``evaluation method.''  The  second method is often referred to\nas ``comparing coefficients,'' and can also be useful for finding\nquick information.  The auxiliary method exploits the fact that\nthe first methods can be applied to the derivatives (of any\norder) of $f$ and $g$ to get further information quickly.\n\n\\bex Compute the integral $\\ds{\\int\\frac1{x^2-5x+6}\\,dx}$.\n\n\\underline{Solution}:  Here we have a degree-0 polynomial\ndivided by a degree-2 polynomial,\nso the PFD rules apply.  Now one usually writes the PFD form of the \nintegrand, complete with the unknown coefficients, before\nproceeding to the methods of computing the coefficients.  In\nother words, our first step would be to write:\n$$\\int\\frac1{x^2-5x+6}\\,dx\n =\\int\\frac1{(x-2)(x-3)}\\,dx\n =\\int\\left[\\frac{A}{x-2}+\\frac{B}{x-3}\\right]\\,dx.$$\nThe next two lines can be skipped with practice, though\nthe first time one works this section they are worth writing\nso the mechanics of the method can be understood and reinforced.\nFirst we write the algebraic step (PFD) which was contained in the\nrewriting of the integrands above:\n$$\\frac1{(x-2)(x-3)}=\\frac{A}{x-2}+\\frac{B}{x-3}.$$\nThis came from the fact that we have $x-2$ as a factor in the\ndenominator, but only once, and the same for $x-3$.\nNext we multiply both sides by {\\bf the denominator on the left}:\n$$(x-2)(x-3)\\left[\\frac1{(x-2)(x-3)}\\right]\n  =(x-2)(x-3)\\left[\\frac{A}{x-2}+\\frac{B}{x-3}\\right].$$\nOn the left, the whole denominator cancels and we have the\nnumerator of the original fraction.  On the right we \nhave to distribute the $(x-2)(x-3)$ across the sum in the\nbrackets.  For the ``$A$'' term the $(x-2)$ cancels, while\nfor the ``$B$'' term the $(x-3)$ cancels, giving us an\nequality of polynomials:\n%\\newpage\n\\begin{equation}1=A(x-3)+B(x-2).\\label{PolyEqualityForPFD1}\n\\end{equation}\nBecause this is an equality of polynomials ($f(x)=g(x)$ where \n$f(x)=1$ and $g(x)=A(x-3)+B(x-2)$), it must be true for any \n$x\\in\\Re$.  Now we choose two values of $x$ strategically.\n\\begin{alignat*}{2}\n\\underline{x=3}:\\qquad&& 1&=A(3-3)+B(3-2)\\implies\\boxed{1=B}\\\\\n\\underline{x=2}:\\qquad&& 1&=A(2-3)+B(2-2)\\\\\n              &&\\implies 1&=-A\\implies\\boxed{A=-1}.\\end{alignat*}\nNow we summarize what we have so far, and compute the desired integral:\n\\begin{align*}\n\\int\\frac1{x^2-5x+6}&=\\int\\left[\\frac{-1}{x-2}+\\frac{1}{x-3}\\right]\\,dx\\\\\n                    &=-\\ln|x-2|+\\ln|x-3|+C\\\\\n                    &=\\ln\\left|\\frac{x-3}{x-2}\\right|+C.\n\\end{align*}\n(The last step is not necessary, but for reasons of style\nmany textbooks combine logarithmic terms into a single logarithm.)\n\\eex\n\nBecause (\\ref{PolyEqualityForPFD1}) was an equality of polynomials\n(meaning the polynomial on the left is {\\it the same polynomial}\nas that on the right\\footnotemark), we could substitute\nany number for $x$ in (\\ref{PolyEqualityForPFD1})\nand still have a true statement.\nFortunately, there were choices which could eliminate \nan unknown, leaving an equation in the other unknown\nwhich is easily solved.\n\n\n%%% FOOTNOTE\n\\footnotetext{It should be pointed out that when\nwe write a PFD, for instance\n$$\\frac1{(x-2)(x-3)}=\\frac{A}{x-2}+\\frac{B}{x-3},$$\nwe mean that these are the same functions as well, so once\nwe find $A$ and $B$, the right-hand side would simplify to become the\nleft-hand side. To find $A$ and $B$ we actually solve the\n{\\it polynomial} equality (\\ref{PolyEqualityForPFD1})\nfor $A$ and $B$.\n\nNote also the distinction between ``equations'' such as $2x-1=5$,\nwhich is true only for $x=3$, and ``equalities'' such as\n$(x+1)^2=x^2+2x+1$, true for all $x$, meaning the function\n$(x+1)^2$ is the same as the function $x^2+2x+1$.\n%%%\n%%% END FOOTNOTE\n}\n\nThe second method for finding $A$ and $B$ (not preferred here\nbut not terribly difficult here either) is to look at the\ncoefficients of the polynomials on the left-hand side and\nright-hand side of (\\ref{PolyEqualityForPFD1}),\nand realize that the coefficients of the\nvarious powers of $x$ must agree for these to be\nthe {\\it same} polynomials.  Though perhaps not necessary for\nthis simple case, one sometimes expands the right-hand side\nand collects like terms \n$$1=(A+B)x+(-3A-2B).$$\nFrom this or just reading from (\\ref{PolyEqualityForPFD1}),\nwe can in turn set equal the coefficients of the $x^1$ terms\nand the constant (some\nsay $x^0$) terms to get the following system of two\nequations in two unknowns:\n\\begin{equation}\\left\\{\\begin{array}{rcrcr}\n 0&=&A&+&B\\hphantom{.}\\\\\n 1&=&-3A&-&2B.\\end{array}\\right.\\label{PolyEqualityForCompCoeffForPFD1}\n\\end{equation}\nThe first equation came from the fact that there is no $x^1$-term\non the left-hand side of (\\ref{PolyEqualityForCompCoeffForPFD1}),\nor alternatively, the $x^1$-term is $0x^1$ on the left.\nTo solve such a system one might add three times the\nfirst equation to the second, to get $B=1$, and\nuse that information in the first to get $A=-1$, as before.\n\nWhenever the denominator of our function $P(x)/Q(x)$ has\na linear factor $(ax+b)$, evaluating the associated {\\it polynomial}\nequality---such as (\\ref{PolyEqualityForPFD1})---at that\n$x$-value which makes this linear factor zero (namely \n$x=-b/a$) will\nquickly yield one of the coefficients, since all but one\nterm in the polynomial equation will have $(ax+b)$ as a factor,\nand therefore vanish at $x=-b/a$.\nThus this first method should always be employed to find that\ncoefficient if the\ndenominator $Q$ has a linear factor.  If the denominator \nhas all linear terms to the first power, then this ``evaluation''\nmethod will quickly yield all coefficients.\n\n\\bex Compute $\\ds{\\int\\frac{2x^2-3x+2}{x(x+5)(2x+1)}\\,dx}$.\n\n\\underline{Solution} It is important to notice that the numerator\nis degree 2, and the denominator degree 3, so the PFD rules do apply.\n$$\\int\\frac{2x^2-3x+2}{x(x+5)(2x+1)}\\,dx\n =\\int\\left[\\frac{A}x+\\frac{B}{x+5}+\\frac{C}{2x+1}\\right]\\,dx.$$\nEventually we will cease writing the next two lines, but to be\nsure we will include them here so that the logic is clear:\n\\begin{alignat*}{2}\n&&\\frac{2x^2-3x+2}{x(x+5)(2x+1)}&=\\frac{A}x+\\frac{B}{x+5}+\\frac{C}{2x+1}\n   \\\\\n&\\implies\n  &x(x+5)(2x+1)\\left[\\frac{2x^2-3x+2}{x(x+5)(2x+1)}\\right]\n    &=x(x+5)(2x+1)\\left[\\frac{A}x+\\frac{B}{x+5}+\\frac{C}{2x+1}\\right]\\\\ \\\\\n&\\implies&2x^2-3x+2&=A(x+5)(2x+1)+Bx(2x+1)+Cx(x+5).\n\\end{alignat*}\nInto this last line we can now enter values for $x$ which will\nquickly yield the coefficients.\n\n\\begin{alignat*}{2}\n\\underline{x=0}:\\qquad&& 2&=A(5)(1)\\implies\\boxed{A=\\frac25}\\\\\n\\underline{x=-5}:\\qquad&& 20+15+2&=B(-5)(-9)\\\\\n              &&\\implies 37&=45B\\implies\\boxed{B=\\frac{37}{45}}.\\\\\n\\underline{x=-\\frac12}:\\qquad&&\n              2\\cdot\\frac14-3\\cdot\\left(-\\frac12\\right)+2\n                &=C\\left(-\\frac12\\right)\\left(-\\frac12+5\\right)\\\\\n              &&\\implies \\frac12+\\frac32+2&=C\\left(-\\frac12\\right)\n                    \\left(\\frac92\\right)\\\\\n              &&\\implies4&=-\\frac94C\\implies\n                       \\boxed{C=-\\frac{16}9}.\n              \\end{alignat*}\nPutting this together with our original integral, we get\n\\begin{align*}\n\\int\\frac{2x^2-3x+2}{x(x+5)(2x+1)}\\,dx\n&=\\int\\left[\\frac{2/5}x+\\frac{37/45}{x+5}+\\frac{-16/9}{2x+1}\\right]\\,dx\\\\\n&=\\frac25\\ln|x|+\\frac{37}{45}\\ln|x+5|-\\frac{16}9\\cdot\\frac12\\ln|2x+1|+C\\\\\n&=\\frac25\\ln|x|+\\frac{37}{45}\\ln|x+5|-\\frac89\\ln|2x+1|+C.\n\\end{align*}\n\\eex\nNext we look at an example where all factors of $Q(x)$ are linear, \nbut one of these linear factors appears to the second power.\n\n\\bex Compute $\\ds{\\int\\frac{x+1}{x^2(x-5)(x+4)}\\,dx}$.\n\n\\underline{Solution}: This time we will describe but\nomit the explicit multiplication\nstep in the PFD.\\footnote{%%%\n%%% FOOTNOTE\nThe pattern of cancellation, when we multiply the PFD by the original\ndenominator $Q(x)$, should become second nature with a small amount\nof practice. That said, it is important to remember what we are doing\n(multiplying by $Q(x)$) to get from the PFD to the polynomial equality,\nand how the various factors cancel (or do not cancel) in that multiplication.\n%%% END FOOTNOTE\n}\n$$\\int\\frac{x+1}{x^2(x-5)(x+4)}\\,dx\n  =\\int\\left[\\frac{A}x+\\frac{B}{x^2}+\\frac{C}{x-5}+\\frac{D}{x+4}\\right]\\,dx,$$\nwhere \n$$\\frac{x+1}{x^2(x-5)(x+4)}\n=\\frac{A}x+\\frac{B}{x^2}+\\frac{C}{x-5}+\\frac{D}{x+4}.$$\nMultiplying by $x^2(x-5)(x+4)$ then gives us\n\\begin{equation}x+1=Ax(x-5)(x+4)+B(x-5)(x+4)+Cx^2(x+4)+Dx^2(x-5).\n  \\label{PolyEqualityForPFD3}\\end{equation}\nWith this equation, choosing $x=0,5,-4$ will yield three of the\nfour coefficients.\n\\begin{alignat*}{2}\n\\underline{x=0}:&\\qquad&1&=B(-5)(4)\\implies\\boxed{B=-\\frac1{20}}\\\\\n\\underline{x=5}:&&6&=C(5^2)(9)\\\\\n          &&\\implies\\frac{2\\cdot3}{5^2\\cdot3\\cdot3}\n                   &=C\\implies\\boxed{C=\\frac2{75}}\\\\\n\\underline{x=-4}:&\\qquad&-3&=D((-4)^2)(-9)\\\\\n              &&\\implies-3&=D[-16\\cdot9]\\\\\n              &&\\implies 3&=D\\cdot16\\cdot3\\cdot3\\implies\n                     \\boxed{D=\\frac1{48}} \n\\end{alignat*}\nThis exhausts the evaluations which give equations in one coefficient.\nNext we have several methods for finding $A$.\n\\begin{description}\n\\item[Method 1.] Compare coefficients.  In particular, we look at the\nhighest-order $x$-terms which appear---at least initially---in \nthe polynomial equality,\nwhich for (\\ref{PolyEqualityForPFD3}) means the $x^3$-terms.\nHere we have no $x^3$-terms on the left, and on the right,\neven without a complete expansion, we can see that \nthe $x^3$-terms will be $A+C+D$.  (The middle-order terms are more\ndifficult to read from (\\ref{PolyEqualityForPFD3}).)  Fortunately\nwe already know the values of $C$ and $D$, so we have enough\ninformation to find $A$:\n\\begin{alignat*}{2}\n\\underline{x^3\\text{-term}}:&\\qquad&0&=A+C+D\\\\\n                      &&\\implies0&=A+\\frac2{75}+\\frac1{48}\n                                  =A+\\frac2{3\\cdot5^2}+\\frac1{2^4\\cdot3}\\\\\n                      &&\\iff0&=A+\\frac{2\\cdot2^4+1\\cdot5^2}{3\\cdot5^2\\cdot2^4}\n                              =A+\\frac{32+25}{3\\cdot5^2\\cdot2^4}\\\\\n                      &&\\iff-\\frac{57}{1200}&=A\\implies\n                                \\boxed{A=-\\frac{19}{400}}\n\\end{alignat*}\n\nFrom this we can complete the integration:\n\\begin{align*}\\int\\frac{x+1}{x^2(x-5)(x+4)}\\,dx\n&=\\int\\left[\\frac{-\\frac{19}{400}}{x}+\\frac{-\\frac1{20}}{x^2}\n     +\\frac{\\frac2{75}}{x-5}+\\frac{\\frac1{48}}{x+4}\\right]\\,dx\\\\\n&=-\\frac{19}{400}\\ln|x|-\\frac1{20}\\cdot\\frac{-1}{x}+\\frac2{75}\\ln|x-5|\n       +\\frac1{48}\\ln|x+4|+C.\n\\end{align*}\n\\item[Method 2.] One can instead evaluate the polynomial \nequality (\\ref{PolyEqualityForPFD3}) at still another $x$-value,\nthough no such value will produce $A$ alone:\n$$\\underline{x=1}:\\qquad 2=A(1)(-4)(5)\n                     +B(-4)(5)+C(1)^2(5)+D(1)^2(-4).$$\nSince we already know $B$, $C$ and $D$, we can insert that information\nand solve for $A$. \n\\item[Method 3.] This will be more useful later, but this method\n(referred to earlier as the {\\rm auxiliary} method) certainly applies.\nThe idea is that we apply $\\frac{d}{dx}$ to both sides\nof (\\ref{PolyEqualityForPFD3}), which is valid because the left-hand\nside and right-hand side of (\\ref{PolyEqualityForPFD3})\nare the same {\\rm functions}.\n\nIn order to use this method, it is useful to recall the generalized\nproduct rule.  For three functions $u(x)$, $v(x)$ and $w(x)$, for instance,\nwe have\n$$(uvw)'=u'vw+uv'w+uvw'.$$\nFor reference we recall (\\ref{PolyEqualityForPFD3}), from which we then\ncompute the derivatives. Equation (\\ref{PolyEqualityForPFD3}) reads:\n$$x+1=Ax(x-5)(x+4)+B(x-5)(x+4)+Cx^2(x+4)+Dx^2(x-5).$$\n\\begin{align*}\n\\underline{\\frac{d}{dx}}:\\qquad\\qquad1&=A[(1)(x-5)(x+4)+x(1)(x+4)+x(x-5)(1)]\\\\\n  &\\qquad+B[(1)(x+4)+(x-5)(1)]\\\\\n  &\\qquad\\qquad+C[(2x)(x+4)+x^2(1)]\\\\\n  &\\qquad\\qquad\\qquad+D[(2x)(x-5)+x^2(1)].\\end{align*}\nNow when we evaluate this at $x=0$, we see that we get\n$$1=A[(1)(-5)(4)]+B[(1)(4)+(-5)(1)]+0+0.$$\nThis gives us $1=-20A-B$, so then $A=(1+B)/(-20)=(19/20)/(-20)=-19/400$,\nas before.\n\\end{description}\n\\eex\n\nA simple principle buried in the third method is the following:\n\\begin{theorem}\nIf $(x-a)^m$, where $m>1$ is a factor of a polynomial $f(x)$,\n             then $(x-a)^{m-1}$ is a factor of $f'(x)$.\n\\label{DerivLowersPowerOf(X-A)Theorem} \n\\end{theorem}\nFor a proof, we note that $(x-a)^m$ being a factor of $f(x)$\nis equivalent to $f(x)=(x-a)^mg(x)$, where $g(x)$ is another \npolynomial.  Thus\n$$f'(x)=(x-a)^mg'(x)+m(x-a)^{m-1}(1)g(x)\n=(x-a)^{m-1}\\underbrace{\\left[(x-a)g'(x)+mg(x)\\right]}_{\\text{polynomial}},$$\nso indeed $(x-a)^{m-1}$ is a factor of $f'(x)$.\n\n\nNow evaluating both sides of (\\ref{PolyEqualityForPFD3}) at $x=0$\ncaused  those terms with $x$ and $x^2$ factors to vanish,\nleaving an equation with $B$ only.  When we differentiate \n(\\ref{PolyEqualityForPFD3}), those terms with $x^2$ factors\n{\\it still vanish}---because one power of $x$ remains---leaving \nonly the $B$-term (as before) \nand the $A$-term (which had a factor $x$ but not $x^2$).\nAlready knowing $B$, we could solve for $A$.\n\n\nA few guidelines for efficiently finding the PFD coefficients\nshould be made at this point.\n\n\\begin{enumerate}\n\\item When linear factors are present in $Q(x)$, it is best\n      to exhaust this method for finding some of the coefficients\n      easily. This means evaluating the relevant polynomial equality\n      at each value for which $Q(x)=0$.\n\\item When those values are exhausted, we should next \n      compare coefficients of the\n      powers of $x$, particuarly the highest power which occurs\n      on the right-hand side.\n\\item If $(ax+b)^m$ is a factor of $Q(x)$, where $m>1$, \n      and the first two methods fail to get all coefficients,\n      then differentiation of the polynomial equality may\n      yield more coefficients.\n\\item If there are still coefficients to be found, then further\n      evaluations, differentiations, or coefficient comparisons\n      should be implemented.\n\\end{enumerate}\n\\bex Compute $\\ds{\\int\\frac{5x^3-17x^2+19x-13}{(x+1)(x-2)^3}\\,dx}$.\n\n\\underline{Solution}: As usual we start with the PFD.\n$$\\frac{5x^3-17x^2+19x-13}{(x+1)(x-2)^3}\n=\\frac{A}{x+1}+\\frac{B}{x-2}+\\frac{C}{(x-2)^2}+\\frac{D}{(x-2)^3}$$\n\\begin{equation}\n5x^3-17x^2+19x-13\n =A(x-2)^3+B(x+1)(x-2)^2+C(x+1)(x-2)+D(x+1)\n\\label{PolyEqualityForPFD4}\\end{equation}\n\\begin{alignat*}{2}\n\\underline{x=-1}:&\\qquad&-5-17-19-13&=A(-27)\\\\\n                 &&\\implies-54&=-27A\\implies\\boxed{A=2}\\\\\n\\underline{x=2}:&\\qquad&5(8)-17(4)+19(2)-13&=D(3)\\\\\n                &&\\implies-3&=3D\\implies\\boxed{D=-1}\\\\\n\\underline{x^3\\text{-term}:}&&5&=A+B\\\\\n                &&\\implies 5&=2+B\\implies\\boxed{B=3}.\n\\end{alignat*}\nWhile we could perform another evaluation ($x=0$ comes to mind),\nor look at another coefficient (prone to error), instead we will\ndifferentiate (\\ref{PolyEqualityForPFD4}):\n\\begin{align*}\n15x^2-34x+19&=A[3(x-2)^2(1)]\\\\\n             &\\qquad+B[(1)(x-2)^2+(x+1)\\cdot2(x-2)(1)]\\\\\n             &\\qquad\\qquad+C[(1)(x-2)+(x+1)(1)]\\\\\n             &\\qquad\\qquad\\qquad+D(1).\\end{align*}\nNow we evaluated at $x=2$:\n\\begin{align*}\n15(4)-34(2)+19&=C(3)+D\\\\\\implies 11&=3C-1\\implies \\boxed{C=4}.\n\\end{align*}\nThus\n\\begin{align*}\n\\int\\frac{5x^3-17x^2+19x-13}{(x+1)(x-2)^3}\\,dx\n&=\n\\int\\left[\\frac2{x+1}+\\frac3{x-2}+\\frac4{(x-2)^2}-\\frac1{(x-2)^3}\\right]\\,dx\\\\\n&=2\\ln|x+1|+3\\ln|x-2|-\\frac4{x-2}-\\frac1{-2}\\cdot\\frac1{(x-2)^2}+C\\\\\n&=\\ln\\left|(x+1)^2(x-2)^3\\right|-\\frac4{x-2}+\\frac1{2(x-2)^2}+C.\n\\end{align*}\n\n\n\\eex\n\nA quick corollary to our Theorem~\\ref{DerivLowersPowerOf(X-A)Theorem} \nis that if\n$(x-a)^m$ is a factor of a polynomial $f(x)$, then for $k<m$ we have\n$(x-a)^{m-k}$ is a factor of $f^{(k)}(x)=\\frac{d^k}{dx^k}f(x)$.\nThis follows from repeated applications of the theorem, which \ncan be paraphrased as saying that we lose at most one factor of $(x-a)$\nfor each derivative we take, until we run out of factors of\n$(x-a)$.  If our latest example had $(x-2)^4$ in the denominator,\nwe could have taken a second derivative of the corresponding\npolynomial equation, and then those terms with \n$(x-2)^3$ or $(x-2)^4$ will stil be zero at $x=2$, but the \nother terms would likely be nonzero.\\footnote{%%%\n%%% FOOTNOTE\nNote that it is quite possible that $x-a$ is not a factor of \na polynomial $f(x)$, but {\\it is} a factor of $f'(x)$.  \nThat is the case when $x=a$ is a {\\it critical point} of\n$f(x)$. For example, $x-1$ is not a factor of $f(x)=x^2-2x+21$,\nbut is a factor of $f'(x)=2x-2=2(x-1)$.\n\nNote also that the theorem applies to any linear factor $ax+b$,\nwhere $a\\ne0$, since $ax+b=a\\left(x+\\frac{b}a\\right)$.\nThus if $x^m$ is a factor of a polynomial $f(x)$, \nthe $x^{m-1}$ is a factor of $f'(x)$, etc., as is the \ncase if we replace $x^m$ with $(ax+b)^m=a^m\\left(x+\\frac{b}a\\right)$.\n%%% END FOOTNOTE\n}\n\n\nNow we turn our attention to PFD's where the denominators contain\nirreducible quadratic factors.\\footnote{%%\n%%% FOOTNOTE\n Until the next section, we will\nnot be able to integrate the general case where we have an \nirreducible quadratic factor to a power greater than 1,\nwith some exceptional cases.  \n%%% END FOONTOTE\n}\nOne problem with such factors is that they are nonzero for \nany $x\\in\\Re$,\\footnote{%%%\n%%% FOOTNOTE\nRecall that if $f(x)$ is a polynomial of degree $\\ge1$,\nthen $f(a)=0\\iff (x-a)$ is a factor of $f(x)$.\n%%% END FOOTNOTE\n}\nso the evaluation method's usefulness is limited in these cases.\nFor such PFD's, we will need to rely more upon the coefficient\ncomparison method to find our coefficients.\n\n\\bex Compute $\\ds{\\int\\frac{4x^3-7x^2+31x-38}{x^4+13x^2+36}\\,dx}$.\n\n\\underline{Solution}:\nPFD rules apply since the degree of the numerator is less than that\nof the denominator.\nWe need to begin by factoring the denominator of the integrand,\nafter which we can write the general form of the PFD.\n$$\n\\int\\frac{4x^3-7x^2+31x-38}{x^4+13x^2+36}\\,dx\n=\\int\\frac{4x^3-7x^2+31x-38}{(x^2+4)(x^2+9)}\\,dx\n=\\int\\left[\\frac{Ax+B}{x^2+4}+\\frac{Cx+D}{x^2+9}\\right]\\,dx.$$\nNow taking the second equation, we underlying PFD becomes\nthe polynomial equality\n\\begin{equation}4x^3-7x^2+31x-38=(Ax+B)(x^2+9)+(Cx+D)(x^2+4).\n\\label{PolyEqualityForPFD5}\n\\end{equation}\nNow we look at the coefficients.\\footnote{%%%\n%%% FOOTNOTE\nNote that the constant (``$x^0$'') term equation is what we \nwould get if we evaluated (\\ref{PolyEqualityForPFD5}) at $x=0$.\nIt is easy to see that this is always the case.%%%\n%%% END FOOTNOTE\n}\n\\begin{alignat*}{2}\n\\underline{x^3\\text{-term}}:&&\\qquad 4&=A+C\\\\\n\\underline{x^2\\text{-term}}:&&-7&=B+D\\\\\n\\underline{x^1\\text{-term}}:&&31&=9A+4C\\\\\n\\underline{x^0\\text{-term}}:&&-38&=9B+4D.\n\\end{alignat*}\nThough this looks like (and is) four equations in four\nunknowns, in fact it ``decouples'' into two systems,\neach with two unknowns, since the first and third\nequations have only $A$ and $C$, and the second and fourth have\n$B$ and $D$ only.  We solve these in turn.\n$$\\begin{array}{rcrcr}\n4&=&A&+&C\\\\\n31&=&9A&+&4C\\end{array}\n\\qquad\\qquad\n\\begin{array}{rcrcr}\n-7&=&B&+&D\\\\\n-38&=&9B&+&4D\\end{array}$$\nFor the first system, we multiply the first equation by $-9$ and add\nto the second, to get $-5=0A-5C\\implies C=1$. From that we have\nthe original first equation giving $A=4-C=4-1=3$.\n\nFor the second system, we do the same, that is, mutliply the first\nequation by $-9$ and add to the second, giving $63-38=-5D\n\\implies25=-5D\\implies-5=D$.  From the original first equation\nin that system, we then get $B=-7-D=-7+5=-2$.\n\nNow we compute the integral, noting that it is easier if we\nbreak the PFD into four distinct terms:\n\\begin{align*}\n\\int\\frac{4x^3-7x^2+31x-38}{(x^2+4)(x^2+9)}\\,dx\n&=\\int\\left[\\frac{3x}{x^2+4}-\\frac{2}{x^2+4}\n              +\\frac{x}{x^2+9}-\\frac5{x^2+9}\\right]\\,dx\\\\\n&=\\frac32\\ln(x^2+4)-\\frac22\\tan^{-1}\\frac{x}2+\\frac12\\ln(x^2+9)\n        -\\frac53\\tan^{-1}\\frac{x}3+C\\\\\n&=\\ln\\sqrt{(x^2+4)^3(x^2+9)}-\\tan^{-1}\\frac{x}2\n         -\\frac53\\tan^{-1}\\frac{x}3+C.\n\\end{align*}\n\\eex\n\nIn the example above, we used the following common integration formula,\nwhich is particularly useful in problems encountered in this section.\nIt is derivable with the usual substitution methods, and not too difficult\nto verify by differentiation.  The formula is the following:\n\\begin{equation}\n\\int\\frac1{x^2+a^2}\\,dx=\\frac1a\\tan^{-1}\\frac{x}a+C.\n\\label{Int1/(x^2+a^2)}\\end{equation}\nWe also used \n$$\\int\\frac{x}{x^2+k^2}\\,dx=\\frac12\\ln(x^2+k^2)+C,$$\nassuming $k\\ne0$.  Note that we do not need absolute values\ninside the logarithm since $x^2+k^2\\ge k^2>0$.\n\nWhen we have irreducible quadratic factors in the denominator\n$Q(x)$, it is likely that we will need to compare coefficients.\\footnote{%%%\n%%% FOOTNOTE\nOr something equivalent to comparing coefficients.  For instance,\n$x=0$ gives $-38=9B+4D$, and one derivative of (\\ref{PolyEqualityForPFD5})\ngives \n$$12x^2-14x+31=(A)(x^2+9)+(Ax+B)(2x)+(C)(x^2+4)+(Cx+D)(2x),$$\nwhich, when we consider the datum $x=0$ gives\n$31=9A+4C$.  Both of these we had before.  More derivatives,\nevaluated at $x=0$,  give\nmultiples of the other two equations in our system (four equations in four\nunknowns).%%\n%%% END FOOTNOTE\n}\nAfterall, there are no real numbers which will make all but\none of those coefficients vanish.  (We can make two vanish with $x=0$,\nbut that still leaves two.)  If linear terms are also present, however,\nthe evaluation method will yield one or more of the coefficients quickly.\n\n\\bex Compute $\\ds{\\int\\frac{12x^4+190x^2+13x-6}{(2x-1)(x^2+16)}\\,dx}$.\n\n\\underline{Solution}: First we note that the numerator has degree\nwhich is not less than the denominator, so we must use long division.\nTo do so we need to expand the denominator:\n$(2x-1)(x^2+16)=2x^3-x^2+32x-16$.\n\nNow through polynomial long division we get\n\\begin{equation}\n\\frac{12x^4+190x^2+13x-6}{(2x-1)(x^2+16)}\n =\\frac{12x^4+190x^2+13x-6}{2x^3-x^2+32x-16}\n =6x+3+\\frac{x^2+13x+42}{2x^3-x^2+32x-16}.\\end{equation}\nRefactoring our denominator, our integral now becomes\n$$\\int\\left[6x+3+\\frac{x^2+13x+42}{(2x-1)(x^2+16)}\\right]\\,dx\n=\\int\\left[6x+3+\\frac{A}{2x-1}+\\frac{Bx+C}{x^2+16}\\right]\\,dx.$$\nThe first two terms are easy enough.  For our PFD, we need only\nconcern ourselves with the remaining fraction:\n$$\\frac{x^2+13x+42}{(2x-1)(x^2+16)}=\n\\frac{A}{2x-1}+\\frac{Bx+C}{x^2+16}.$$\nThe corresponding polynomial equation is then\n\\begin{equation}\nx^2+13x+42=A(x^2+16)+(Bx+C)(2x-1).\n\\label{PolyEqualityForPFD6}\\end{equation}\nWe begin with an evalutation, followed by a coefficient comparison.\n\\begin{alignat*}{2}\n\\underline{x=\\frac12}:&\\qquad&\\frac14+\\frac{13}2+42&=\n              A\\left(\\frac14+16\\right)\\\\\n       &&\\implies \\frac{1+26+168}{4}&=\\frac{65}4A\\\\\n       &&\\implies {195}&=65A\\implies\\boxed{A=3}\\\\\n\\underline{x^2\\text{-term}}:\n           &&1&=A+2B\\\\\n           &&\\implies1&=3+2B\\implies\\boxed{B=-1}.\n\\end{alignat*}\nPerhaps the simplest next step is to find $C$ by evaluation of\n(\\ref{PolyEqualityForPFD6}) at,\nsay, $x=0$:\n\\begin{align*}\n\\underline{x=0}:\\qquad 42&=16A-C\\\\\n                  \\implies42&=16(3)-C\\\\\n                  \\implies C&=16(3)-33=48-16\\implies \\boxed{C=6}.\n\\end{align*}\nThus our original integral, including the polynomial terms, becomes\n\\begin{align*}\n\\int\\frac{12x^4+190x^2+13x-6}{(2x-1)(x^2+16)}\\,dx\n&=\\int\\left[6x+3+\\frac{3}{2x-1}-\\frac{x}{x^2+16}+\\frac{6}{x^2+16}\n  \\right]\\,dx\\\\\n&=3x^2+3x+\\frac32\\ln|2x-1|-\\frac12\\ln(x^2+16)+\\frac64\\tan^{-1}\\frac{x}4\n+C\\\\&=3x(x+1)+3\\ln\\sqrt{|2x-1|}-\n\\ln\\sqrt{x^2+16}+\\frac32\\tan^{-1}\\frac{x}4\n+C.\\end{align*}\nThe second from the last line was complete; the last line just gives\nsome alternative styles for the particular terms.\n\\eex\n\nOf course with any new technique, we have to be sure that\nwe do not neglect the earlier methods.\n\n\n\\section{Miscellaneous Methods}\n\nIn this section we will use completing the square, and other\nmethods to rewrite several types of integrals into forms\nwhere we can more easily use either partial fractions\nor trigonometric substitution.  We will also look at examples\nwhere a substitution will bring us to such forms.  Finally, we\nwill consider the use of integration tables, which \ncan be found in numerous publications, but which require\nsome sophistication to be used properly.\n\n\n\n\n\n\n\n\\newpage\n\n\n", "meta": {"hexsha": "fec4413b367292be1ba5620fe22de6fc850fa41c", "size": 131004, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "michael.dougherty/chapter07.tex", "max_stars_repo_name": "UNDL-edu/Calculo-Infinitesimal", "max_stars_repo_head_hexsha": "2ad971127ae31b88de02b5e85fb8ba2249278e2e", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "michael.dougherty/chapter07.tex", "max_issues_repo_name": "UNDL-edu/Calculo-Infinitesimal", "max_issues_repo_head_hexsha": "2ad971127ae31b88de02b5e85fb8ba2249278e2e", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "michael.dougherty/chapter07.tex", "max_forks_repo_name": "UNDL-edu/Calculo-Infinitesimal", "max_forks_repo_head_hexsha": "2ad971127ae31b88de02b5e85fb8ba2249278e2e", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.0019236935, "max_line_length": 79, "alphanum_fraction": 0.6903300663, "num_tokens": 45136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262966, "lm_q2_score": 0.8824278571786139, "lm_q1q2_score": 0.7391391822203874}}
{"text": "\\section{Gaussian processes and the multivariate normal distribution}\n\nGaussian processes generalize the multivariate normal distribution from vectors to functions, like the multivariate normal distribution generalizes the univariate normal distribution from scalars to vectors. The progression is as follows:\n\\begin{equation}\n    \\begin{array}{ll}\n        y\\sim\\textup N(\\mu,V): & \\textup{$y$, $\\mu$, $V$ are scalars}\\\\\\\\\n        \\vec y\\sim\\textup N(\\vec \\mu,C): & \\textup{$\\vec y$ and $\\vec \\mu$ are vectors, $C$ is a matrix}\\\\\\\\\n        f\\sim\\textup{GP}(M, C): & \\textup{$f$ and $M$ are functions of one variable, $C$ is a function of two variables}\n    \\end{array}\n\\end{equation}\n\nOne of the nice things about all Gaussian distributions (parameterized by mean and covariance) is that they're easy to marginalize. For example, each element of a vector with a multivariate normal distribution has a univariate normal distribution:\n\\begin{eqnarray*}\n    \\vec y\\sim\\textup N(\\vec \\mu,C)\\\\\n    \\Rightarrow \\vec y_i\\sim\\textup N(\\vec \\mu_i,C_{i,i}),\n\\end{eqnarray*}\nand any subvector of a vector with a multivariate normal distribution has a multivariate normal distribution:\n\\begin{eqnarray*}\n    \\vec y\\sim\\textup N(\\vec \\mu,C)\\\\\n    \\Rightarrow \\vec y_{i_1\\ldots i_2}\\sim\\textup N(\\vec \\mu_{i_1\\ldots i_2},C_{i_1\\ldots i_2,i_1\\ldots i_2}).\n\\end{eqnarray*}\n\nThis marginalizability applies to GP's as well. If $\\vec x$ is a vector of values,\n\\begin{equation}\n    \\begin{array}{l}\n        f\\sim\\textup{GP}(M, C)\\\\\\\\\n        \\Rightarrow f(\\vec x) \\sim\\textup N(M(\\vec x), C(\\vec x,\\vec x)).\n    \\end{array}\n\\end{equation}\nIn other words, any evaluation of a Gaussian process realization has a multivariate normal distribution. Its mean is the corresponding evaluation of the associated mean function, and its covariance is the corresponding evaluation of the associated covariance function. You can probably start to see why this fact is important for working with GPs on a computer.\n\n\\subsection{Observations}\nAs mentioned earlier, if $f$ has a GP prior and normally-distributed observations of $f$ are made at a finite set of values, $f$'s posterior is a Gaussian process also:\n\\begin{eqnarray*}\n    \\left.\\begin{array}{l}\n        d_i \\stackrel{\\tiny{\\textup{ind}}}{\\sim} \\textup{N}(f(o_i), V_i)\\\\\n        f \\sim \\textup{GP}(M,C)\n    \\end{array}\\right\\}\\Rightarrow f|d \\sim \\texttt{GP}(M_o, C_o).\n\\end{eqnarray*}\nDenoting by $o$ the array of observation values $[o_0\\ldots o_{N-1}]$ and $V$ a matrix with observation variances $[V_0\\ldots V_{N-1}]$ on its diagonal, $M_o(x)$ and $C_o(x,y)$ are as follows for arbitrary input vectors $x$ and $y$:\n\\begin{eqnarray*}\n    M_o(x) = M(x) + C(x,o)[C(o,o) + V]^{-1}(f(o)-M(o))\\\\\n    C_o(x,y) = C(x,y) - C(x,o)[C(o,o) + V]^{-1}C(o,y).\n\\end{eqnarray*}\n\n\\subsection{Low-rank observations}\n\nIf $C(o,o)+V$ is singular, some elements of $f(o)$ can be computed from others with no uncertainty. In other words, there exists a partition $[o_*, o_{**}]$ of $o$ and corresponding partition of the data such that $C(o_*,o_*)+V$ is full-rank and\n\\begin{eqnarray*}\n    f(o_{**}) = M_{o_*}(o_{**}),\n\\end{eqnarray*}\nwhere $M_{o_*}$ can be computed from the formula above.\n\nIn such cases, this package's strategy is to observe $f$ at a subvector $o_*$ of $o$, such that $C(o_*,o_*)+V$ is full-rank but if any elements were added to $o_*$ it would pick up a very small eigenvalue. The function \\function{predictive_check} optionally checks the remaining data values $d_{**}$ against $M_{o_*}(o_{**})$, and raises an error if the two aren't equal up to a user-defined threshold.\n\nThis threshold is parameter \\code{relative_precision} from \\texttt{Covariance}'s init method, multiplied by the largest value on the diagonal of $C(o_*,o_*)+V$; intuitively, the maximal variance of $f(o_{**})$ given $f(o_*)$ is a multiple of the maximal variance of $f(o_*)$.\n\n\\section{Incomplete Cholesky factorizations}\\label{sec:ichol} % (fold)\n\nIn addition to numpy's linear algebra support, this package uses some Fortran subroutines wrapped using \\citetitle[http://cens.ioc.ee/projects/f2py2e/]{f2py}. They require \\citetitle[http://www.netlib.org/blas/]{BLAS} and \\citetitle[http://www.netlib.org/lapack/]{LAPACK} libraries (eg, \\citetitle[http://math-atlas.sourceforge.net/]{ATLAS}) on your system, and the \\file{setup.py} script will attempt to find these. If you don't have optimized BLAS and LAPACK installed, it's a good idea to install them; this package and numpy in general will be much faster. Some operating systems (such as Mac OS X) ship with optimized BLAS and LAPACK libraries included.\n\nThe following incomplete Cholesky factorization functions are found in the Fortran files \\file{linalg_utils.f} and \\file{incomplete_chol.f} :\n\\begin{description}\n\n    % \\item[\\function{dtrsm_wrap(a,b,uplo='U',transa='N',alpha=1.)}:] A wrapper for the BLAS routine \\citetitle[http://www.netlib.org/blas/dtrsmf.f]{DTRSM}, which solves triangular systems \\texttt{$\\alpha$a$^{op}$ x = b} in-place (that is, \\texttt{b} is overwritten by $x$).\n    % \\begin{itemize}\n    %     \\item If \\texttt{uplo='U'}, \\texttt{a} is assumed to be an upper triangle; if \\texttt{uplo='L'}, \\texttt{a} is assumed to be a lower triangle.\n    %     \\item If \\texttt{transa='T'}, \\texttt{$\\alpha$a.T*x = b} is solved. If \\texttt{transa='N'}, \\texttt{$\\alpha$a*x = b} is solved.\n    % \\end{itemize}\n    % \n    % \\item[\\function{dtrmm_wrap(a,b,uplo='U',transa='N',alpha=1.)}:] A wrapper for the BLAS routine \\citetitle[http://www.netlib.org/blas/dtrsmf.f]{DTRMM}, which does the triangular matrix multiplication \\texttt{$\\alpha$a$^{op}$x = b} in-place (that is, \\texttt{b} is overwritten by $x$).\n    % \\begin{itemize}\n    %     \\item If \\texttt{uplo='U'}, \\texttt{a} is assumed to be an upper triangle; if \\texttt{uplo='L'}, \\texttt{a} is assumed to be a lower triangle.\n    %     \\item If \\texttt{transa='T'}, \\texttt{$\\alpha$a.T*x} is computed. If \\texttt{transa='N'}, \\texttt{$\\alpha$a*x} is computed.\n    % \\end{itemize}\n    % \n    % \\item[\\function{info = dpotrf_wrap(a)}:] A wrapper for the LAPACK routine \\citetitle[http://www.netlib.org/lapack/double/dpotrf.f]{DPOTRF}, which tries to overwrite positive-definite matrix \\texttt{a} with an upper-triangular Cholesky factor in-place. If the return value \\texttt{info} is positive, \\texttt{a} is not positive definite and the algorithm has failed.\n\n    \\item[\\function{U, m, piv = ichol(diag, reltol, rowfun)}:] An implementation of the incomplete Cholesky decomposition, based on a port of one of the functions in the \\citetitle[http://www.kyb.tuebingen.mpg.de/bs/people/seeger/]{chol_incomplete} package by Matthias Seeger.\n\nThe arguments are:\n    \\begin{description}\n        \\item[\\texttt{diag}:] The diagonal of an \\texttt{n} by \\texttt{n} covariance matrix C.\n        \\item[\\texttt{reltol}:] If the ratio of the \\texttt{i}'th pivot to the maximum pivot is found to be less than \\texttt{reltol}, the \\texttt{i}'th pivot is assumed to be zero.\n        \\item[\\texttt{rowfun}:] A Python function. The call \\function{rowfun(i,p,rowvec)} should perform the update \\texttt{rowvec[i,i+1:]=C[i,p[i+1:]]} in-place.\n    \\end{description}\n\nThe outputs are:\n    \\begin{description}\n        \\item[M:] The rank of C. Note that M$\\le$\\texttt{n}.\n        \\item[\\texttt{piv}:] A length-\\texttt{n} vector of pivots.\n        \\item[\\texttt{U}:] An M-by-\\texttt{n} upper-triangular matrix that satisfies \\texttt{U[:,argsort(piv)].T * U[:,argsort(piv)] = C}.\n    \\end{description}\n\nBecause the full matrix $C$ does not need to be computed ahead of time, the algorithm is able to factor $C$ in $O(m^2 n)$ operations \\cite{incompchol}. The algorithm is implemented in Fortran, but a Python version would be as follows:\n\n\\begin{verbatim}\n\ndef swap(vec,i,j):\n    temp = vec[i]\n    vec[i] = vec[j]\n    vec[j] = temp\n\ndef ichol(diag, reltol, rowfun):\n\n    piv = arange(n)\n    U = zeros((n,n),dtype=float).view(matrix)\n    rowvec = zeros(n,dtype=float)\n\n    for i in range(n):\n        l = diag[i:].argmax()\n        maxdiag = diag[l]\n\n        if maxdiag < reltol:\n            m=i\n            return U[:m,:], m, piv\n\n        swap(diag,i,l)\n        swap(p,i,l)\n\n        temp = U[:i,i]\n        U[:i,i] = U[:i,l]\n        U[:i,l] = temp\n\n\n        U[i,i] = sqrt(diag[i])\n        rowvec[i:] = C[i,piv[i+1:]]\n\n        if i > 0:\n            rowvec -= U[:i,i].T * U[:i,i+1:]\n\n        U[i,i+1:] = rowvec[i+1:] / U[i,i]\n        diag[i+1:] -= U[i,i+1:].view(ndarray) ** 2\n\n    m=n\n    return U, m, piv\n\\end{verbatim}\n\nFunction \\function{ichol} is wrapped by the \\class{Covariance} method \\method{cholesky}.\n\n\\item[\\function{m, piv = ichol_continue(U, diag, reltol, rowfun, piv)}:]\nThis function computes the Cholesky factorization of an \\texttt{n} by \\texttt{n} covariance matrix C from the factor of its upper-left \\texttt{n}$_*$ by \\texttt{n}$_*$ submatrix C$_*$. Its input arguments are as follows:\n\\begin{description}\n    \\item[\\texttt{U}:] Unlike \\function{ichol}, this function overwrites a matrix in-place. Suppose the Cholesky factor of C$_*$, \\texttt{U}$_*$, is of rank M$_*$. On input, \\texttt{U} must be an \\texttt{[m + (n-n$_*$)]}-by-\\texttt{n} matrix arranged like this:\n    \\begin{eqnarray*}\n        \\left[\n        \\begin{array}{ccc}\n            \\texttt{U}_*\\texttt{[:,:m}_*\\texttt{]} & \\texttt{U}_*\\texttt{[:,:m}_*\\texttt{].T.I C[:m}_*\\texttt{,n}_*\\texttt{:]} & \\texttt{U}_*\\texttt{[:,m}_*\\texttt{:]}\\\\\n            \\texttt{0}&\\texttt{0}&\\texttt{0}\n        \\end{array}\n        \\right]\n    \\end{eqnarray*}\nOn exit, \\texttt{U} will be an M-by-\\texttt{n} upper-triangular matrix that satisfies \\texttt{U[:,argsort(piv)].T * U[:,argsort(piv)]=C}.\n    \\item[\\texttt{piv}:] Denote by \\texttt{piv}$_*$ the pivot vector associated with \\texttt{U}$_*$ On input, \\texttt{piv} must be a length-\\texttt{n} vector laid out like this:\n    \\begin{eqnarray*}\n        \\begin{array}{ccc}\n            [\\texttt{piv}_*\\texttt{[:m}_*\\texttt{]} & \\texttt{arange(n-n$_*$)} & \\texttt{piv}_*\\texttt{[m}_*\\texttt{:]}]\n        \\end{array}\n    \\end{eqnarray*}\n    \\item[\\texttt{diag}:] The length \\texttt{n-n}$_*$ diagonal of \\texttt{C[n$_*$:,n$_*$]}.\n    \\item[\\texttt{rowfun}:] The call \\function{rowfun(i,p,rowvec)} should perform the update \\texttt{rowvec[i,i+1:]} \\texttt{=} \\texttt{C[i,p[i+1:]]} in-place.\n\\end{description}\n\n    The input parameter \\texttt{reltol}, as well as the output parameters \\texttt{piv} and M and the updated matrix \\texttt{U}, should be interpreted just like their counterparts in \\function{ichol}.\n\n    The algorithm is just like the algorithm in ichol, but the index \\texttt{i} iterates over \\texttt{range(m$_*$,m$_*$+n-n$_*$)} (and the index of \\texttt{diag} is downshifted appropriately).\n\n    \\function{ichol_continue} is wrapped by the \\class{Covariance} method \\method{continue_cholesky}, so it should rarely be necessary to call it directly.\n\n    \\item[\\function{U, m, piv = ichol_full(c, reltol)}:] Just like \\texttt{ichol}, but instead of a diagonal and a `get-row' function a full covariance matrix C is required as an input.\n\n    \\item[\\function{U, m, piv = ichol_full(basis, nug, reltol)}:] Just like \\texttt{ichol}, but the following arguments are required:\n    \\begin{description}\n        \\item[\\texttt{basis}:] The evaluation of a basis function on the mesh, multiplied by the Cholesky factor of the coefficients' covariance matrix. This is itself a square root of the covariance matrix, but running it through \\texttt{ichol_basis} allows for observations with nonzero variance and essentially pivots for better accuracy even in the zero-variance case.\n        \\item[\\texttt{nug}:] A vector that will effectively be added to the diagonal of the covariance matrix.\n    \\end{description}\n\\end{description}\n\n%     \\item[\\function{x = trisolve(A,b,uplo='U',transa='N',inplace=False)}:] Solves the triangular system \\texttt{$\\alpha$a$^{op}$ x = b} using \\function{dtrsm_wrap} and returns $x$. If \\texttt{A} is found to be singular, an error is raised.\n%     \\begin{itemize}\n%         \\item \\texttt{A} is assumed upper-triangular if \\code{uplo='U'} and lower-triangular if \\code{uplo='L'}.\n%         \\item If \\texttt{transa='T'}, \\texttt{$\\alpha$a.T*x = b} is solved. If \\texttt{transa='N'}, \\texttt{$\\alpha$a*x = b} is solved.\n%         \\item If \\texttt{inplace=True}, \\texttt{b} is overwritten with $x$ in-place and returned. If \\texttt{inplace=False}, \\texttt{b} is not modified.\n%     \\end{itemize}\n% \n%     \\item[\\function{b = trimult(A,x,uplo='U',transa='N',inplace=False)}:] Does the triangular multiplication \\texttt{$\\alpha$a$^{op}$x = b} using \\function{dtrmm_wrap} and returns \\texttt{b}.\n%     \\begin{itemize}\n%         \\item \\texttt{A} is assumed upper-triangular if \\code{uplo='U'} and lower-triangular if \\code{uplo='L'}.\n%         \\item If \\texttt{transa='T'}, \\texttt{$\\alpha$a.T8x} is computed. If \\texttt{transa='N'}, \\texttt{$\\alpha$a*x} is computed.\n%         \\item If \\texttt{inplace=True}, $x$ is overwritten with \\texttt{b} in-place and returned. If \\texttt{inplace=False}, $x$ is not modified.\n%     \\end{itemize}\n% \\end{description}\n\n    % \\item[\\function{observe(M, C, obs_mesh, obs_vals, obs_V, lintrans, cross_validate = True)}:] This function calls \\texttt{C.observe}, calls \\texttt{M.observe} with the output, and then if \\texttt{cross_validate=True} calls \\texttt{predictive_check}.\n\n%     If the return of \\texttt{predictive_check} value is \\texttt{False}, the values of some observations can be predicted with negligible uncertainty from the values of others, but they don't match their predicted values; in other words, the data are extremely improbable. A \\texttt{ZeroProbability} exception is raised with some helpful suggestions if this is the case.\n%\n%     \\item[\\function{OK = predictive_check(obs_vals, obs_mesh, M, posdef_indices, tolerance)} :] Checks the value of M evaluated at \\texttt{obs_mesh} sliced at the complement of \\texttt{posdef_indices} against the corresponding \\texttt{obs_vals}. If any of the differences are greater than \\texttt{tolerance}, \\texttt{False} is returned. Otherwise \\texttt{True} is returned.\n% \\end{description}\n% \\section{Object internals}\\label{sec:internals}\n%\n% The methods of \\class{Mean}, \\class{Covariance} and \\class{Realization} will be described here.\n%\n% \\section{Covariance}\\label{sec:covarianceInt}\n% \\begin{description}\n%\n%     \\item[\\method{cholesky(x, apply_pivot = True, observed=True)}:] Returns an incomplete Cholesky factor of \\texttt{C(x,x)}. The other arguments' meanings are as follows:\n%     \\begin{description}\n%         \\item[\\texttt{apply_pivot}:] If \\texttt{True}, the return value is a matrix \\texttt{U} such that \\texttt{U.T*U = C(x,x)}. If \\texttt{False}, the return value is a dictionary. Element \\texttt{'pivots'} is a vector of pivots returned by function \\function{ichol}, and element \\texttt{'U'} is the matrix \\texttt{sig} returned by \\function{ichol}.\n%         \\item[\\texttt{observed}:] If \\texttt{True}, the matrix \\texttt{C(x,x)} is obtained conditional on observations that have been made involving C. If \\texttt{False}, the matrix is obtained without regard to those observations.\n%     \\end{description}\n%\n%         \\item[\\method{continue_cholesky(x, x_old, chol_dict_old[, apply_pivot, observed])}:] Returns an incomplete Cholesky factor of \\texttt{C(concatenate(x_old,x), concatenate(x_old,x))}. Arguments \\texttt{apply_pivot} and \\texttt{observed} are the same as for \\texttt{cholesky}. \\texttt{chol_dict_old} should be the incomplete Cholesky factorization of \\texttt{C(x_old, x_old)} in the form of a dictionary such as the one produced by \\texttt{C.cholesky}.\n%\n%         This method returns either a matrix or a dictionary depending on the value of \\texttt{apply_pivot}. See \\texttt{cholesky}.\n%\n%\n%         \\item[\\method{relevant_slice, obs_mesh_new, U_for_draw = observe(obs_mesh, obs_V=0.)}:] All subsequent calls will be made under the assumption that observations of the random field at inputs \\texttt{obs_mesh} have been made with variance \\texttt{obs_V}. This method updates the following attributes of C:\n%         \\begin{itemize}\n%             \\item \\texttt{observed}: This flag is set to \\texttt{True}.\n%             \\item \\texttt{obs_U} and \\texttt{obs_piv}: The output of \\texttt{self.cholesky(obs_mesh, apply_pivot=False, observed=False)}.\n%             \\item \\texttt{obs_mesh}: The mesh on which self has been observed, sliced by \\texttt{obs_piv[:m]}, where M is the rank of \\texttt{obs_U}.\n%             \\item \\texttt{obs_V}: The variances associated with the observations, sliced as \\texttt{obs_mesh} is.\n%             \\item \\texttt{obs_len}: The length of \\texttt{obs_V}.\n%         \\end{itemize}\n%\n%         The return values are:\n%         \\begin{itemize}\n%             \\item \\texttt{relevant_slice}: The indices included in the incomplete Cholesky factorization. These correspond to the values of \\texttt{obs_mesh} that determine the other values, but not one another.\n%             \\item \\texttt{obs_mesh_new}: \\texttt{obs_mesh} sliced according to \\texttt{relevant_slice}.\n%             \\item \\texttt{U_for_draw}: An upper-triangular Cholesky factor of \\texttt{self}'s evaluation on \\texttt{obs_mesh} conditional on all previous observations.\n%         \\end{itemize}\n%\n%\n%\n%     \\item[\\method{__call__(x[, y, observed])}:]\n%\n%     \\begin{itemize}\n%         \\item If only one argument $x$ is provided, \\texttt{C(x,x) = V(f(x))} will be returned conditional on any observations that have been made.\n%         \\begin{itemize}\n%             \\item If C is unobserved or \\texttt{observed = False}, its underlying function C is evaluated at each element of $x$. The \\texttt{i}'th element of the return value is \\texttt{c(x_i,x_i)}.\n%             \\item If C is observed and \\texttt{observed = True}, its underlying function C is evaluated at each element of $x$. The \\texttt{i}'th element of the return value is\n%             \\begin{eqnarray*}\n%                 \\texttt{c(x_i,x_i) - (U.T.I c(o,x_i)).T (U.T.I c(o,x_i))},\n%             \\end{eqnarray*}\n%             where \\texttt{o} is \\code{self.obs_mesh} and \\texttt{U} is \\texttt{self.obs_U}, both of which were provided by \\function{observe}.\n%             \\end{itemize}\n%\n%         \\item If two arguments \\texttt{(x,y)} are provided, \\texttt{C(x,y)} will be returned conditional on any observations that have been made.\n%         \\begin{itemize}\n%             \\item If C is unobserved, \\texttt{c(x,y)} will be returned where C is the underlying function. If $x$ and $y$ are references to the same array, only half the matrix will actually be computed; the other half will be filled in.\n%         \\item If C is observed, the return value will be\n%         \\begin{eqnarray*}\n%             \\texttt{c(x,y) - (U.T.I c(o,x)).T (U.T.I c(o,y))}\n%         \\end{eqnarray*}\n%         where again \\texttt{o} is \\code{self.obs_mesh} and \\texttt{U} is \\texttt{self.obs_U}.\n%         \\end{itemize}\n%\n%     \\end{itemize}\n%     \\end{description}\n%\n% \\section{BasisCovariance}\\label{sec:basisCovariance}\n% \\class{BasisCovariance} has methods and attributes that act just like those of \\texttt{Covariance}, but of course the internal computations are different and tend to be faster.\n%\n% \\section{Mean}\\label{sec:meanInt}\n% \\begin{description}\n%     \\item[\\method{observe(C, obs_mesh_new, obs_vals_new)}:] All subsequent calls will be made under the assumption that observations of the random field at inputs \\texttt{obs_mesh} have been made with variance \\texttt{obs_V}. Assumes that \\texttt{C(obs_mesh_new, obs_mesh_new)} is positive definite; the \\emph{function} \\function{observe} slices \\texttt{obs_vals} according to \\texttt{Covariance.observe}'s output value \\texttt{relevant_slice} before passing it to \\texttt{Mean.observe}. This method updates the following attributes of M:\n%     \\begin{itemize}\n%         \\item \\texttt{self.C}: The covariance of the random field (which has self as mean) that was observed. Several of $C$'s attributes are used by this method.\n%         \\item \\texttt{self.obs_U}: \\texttt{C.obs_U}.\n%         \\item \\texttt{self.obs_mesh}: \\texttt{C.obs_mesh}.\n%         \\item \\texttt{obs_V}: \\texttt{C.obs_V}.\n%         \\item \\texttt{obs_len}: \\texttt{C.obs_len}.\n%         \\item \\texttt{self.dev}: \\texttt{obs_mesh - self.__call__(obs_mesh, observed=False)}.\n%         \\item \\texttt{self.reg_vec}: \\texttt{self.obs_U[:,:m].T*self.dev}, where M is the rank of \\texttt{self.obs_U}.\n%     \\end{itemize}\n%\n%     Note that \\texttt{Mean.observe} will not cross-validate; if inconsistent observation values are used, it will simply ignore them. You'll need to call \\texttt{predictive_check} yourself if you want cross-validation.\n%\n%     \\item[\\method{__call__(x[, observed])}:]\n%     \\begin{itemize}\n%         \\item If M has not been observed or \\texttt{observed = False}, the return value of \\texttt{M(x)} will just be \\texttt{m(x)} where M is the underlying mean function.\n%         \\item If M has been observed and \\texttt{observed = True}, the return value will be\n%         \\begin{eqnarray*}\n%             \\texttt{c(x,o) U.I r},\n%         \\end{eqnarray*}\n%         where \\texttt{r} is \\code{self.reg_vec}, \\texttt{U} is \\code{self.obs_U} and C is \\code{self.cov_fun}, all of which were provided by \\function{observe}.\n%\n%     \\end{itemize}\n%\n% \\end{description}\n\n% \\section{Realization}\\label{sec:realInt}\n% A realization f maintains the following attributes:\n% \\begin{itemize}\n%     \\item \\texttt{x_sofar}: The values at which self has already been evaluated.\n%     \\item \\texttt{f_sofar}: Self's evaluation at \\texttt{x_sofar}.\n%     \\item \\texttt{M_internal}: An observed copy of self's mean.\n%     \\item \\texttt{C_internal}: An observed copy of self's covariance.\n% \\end{itemize}\n%\n% When the evaluation \\texttt{f(x)} is requested, the following happen:\n% \\begin{enumerate}\n%     \\item \\texttt{x_sofar} is searched for elements of $x$. If any are found, the corresponding values of f aren't recomputed. Call the remaining elements \\texttt{x_new}.\n%     \\item \\texttt{C_internal} is observed at \\texttt{x_new} with \\texttt{obs_V=0}.\n%     \\item The output value \\texttt{U_for_draw} is used to generate a normal random variable \\texttt{f_new} with mean \\texttt{M_internal(x_new)} and covariance \\texttt{C_internal(x_new, x_new)}.\n%     \\item \\texttt{M_internal} is observed with \\texttt{obs_mesh = x_new}, \\texttt{obs_vals = f_new}, \\texttt{obs_taus = Inf}.\n%     \\item \\texttt{f_new} is appropriately combined with f's evaluation at previously computed values of $x$ and the result is returned.\n% \\end{enumerate}\n%\n% If a realization's covariance is an instance of \\texttt{BasisCovariance}, the behavior is different. At instantiation, the realization will draw coefficients for the basis terms; calls to the realization will simply be handled by calling the basis.\n\n% chapter numerics (end)\n\n% \\chapter{Wishlist}\\label{cha:wishlist}\n% \\section{Features}\n% \\begin{itemize}\n%     \\item Linear transformations.\n%     \\begin{itemize}\n%         \\item Create new GP's from old GP's via linear transformations. Maybe try to make a \\class{LinearOperator} class.\n%         \\item Observe linear transformations of evaluations of GP.\n%     \\end{itemize}\n%     \\item Observations can be dependent (\\texttt{obs_V} can be square rather than a diagonal).\n%     \\item Specific support for anisotropy.\n%     \\item Specific support for spline covariances.\n%     \\item Specific support for vector-valued GPs (cokriging).\n% \\end{itemize}\n%\n% \\section{Optimizations}\n% \\begin{itemize}\n%     % \\item Markov random field covariances, which take advantage of the sparseness of the covariance for speed.\n%     \\item Speed up realization calls with just one value. All the array manipulation really bogs this case down, and this makes dynamical/autoregressive applications slow.\n%     \\begin{itemize}\n%         \\item There isn't a clear bottleneck, unfortunately. It might be necessary to write all the call methods in f2py or Pyrex.\n%     \\end{itemize}\n% \\item \\function{ichol} and friends:\n% \\begin{itemize}\n%     \\item Don't allocate full-rank memory up-front.\n%     \\item Use a symbolic Cholesky decomposition to save some work.\n%     \\item Increase granularity of BLAS calls to take better advantage of threaded libraries.\n%     \\item Distributed memory.\n% \\end{itemize}\n% \\end{itemize}\n%\n% \\section{Other}\n% \\begin{itemize}\n%     \\item Clean up the return values from \\class{Covariance.observe}.\n%     \\item Try to figure out relative performance of incomplete Cholesky w/low-rank covariances to basis covariances, and relative performance of sparse Cholesky to Markov Random Field covariances.\n% \\end{itemize}\n\n% section new_features (end)\n\n% \\chapter{Quick reference}\\label{cha:reference}\n", "meta": {"hexsha": "f1a6565f04aa42d42111e66489270ab5c6254084", "size": 24702, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pymc/gp/Docs/numerics.tex", "max_stars_repo_name": "kyleabeauchamp/pymc", "max_stars_repo_head_hexsha": "6ce0094584f1fa00eed0b2ecee533c2fb7f190d6", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-12-03T09:42:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-06T19:23:29.000Z", "max_issues_repo_path": "pymc/gp/Docs/numerics.tex", "max_issues_repo_name": "kyleabeauchamp/pymc", "max_issues_repo_head_hexsha": "6ce0094584f1fa00eed0b2ecee533c2fb7f190d6", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-09-27T02:00:41.000Z", "max_issues_repo_issues_event_max_datetime": "2016-09-27T02:15:32.000Z", "max_forks_repo_path": "pymc/gp/Docs/numerics.tex", "max_forks_repo_name": "kyleabeauchamp/pymc", "max_forks_repo_head_hexsha": "6ce0094584f1fa00eed0b2ecee533c2fb7f190d6", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-05-11T06:17:00.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-17T23:22:46.000Z", "avg_line_length": 69.7796610169, "max_line_length": 658, "alphanum_fraction": 0.6902275119, "num_tokens": 7328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7390723582902449}}
{"text": "\\subsection{Dot Products}\r\n\\noindent\r\nA dot product is a way of multiplying two vectors so that the result is a scalar.\r\n$\\vec{a}\\cdot\\vec{b} = \\norm{\\vec{a}}\\norm{\\vec{b}}\\cos{\\theta}$ where $\\theta$ is the angle between $\\vec{a}$ and $\\vec{b}$.\r\nOne way to think of the dot product is as a measure of how much two vectors point in the same direction.\r\nWe can also show using the law of cosines that $\\vec{a}\\cdot\\vec{b} = a_1b_1+a_2b_2+...+a_nb_n$.\r\nKnowing the lengths of two vectors and their dot product we can calculate the angle between them as\r\n\\begin{equation*}\r\n\t\\theta = \\arccos{\\left(\\frac{\\vec{a} \\cdot \\vec{b}}{\\norm{\\vec{a}} \\norm{\\vec{b}}}\\right)}.\r\n\\end{equation*}\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.25\\textwidth]{../common/vectorsMatrices/DotProduct.png}\r\n\t\\caption{Two vectors and the angle between them}\r\n\\end{figure}\r\n\r\n\\noindent\r\nAlthough similar to scalar multiplication, dot products have some properties that set them apart.\r\n\\begin{enumerate}[label=]\r\n\t\\item \\textbf{Commutative}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{a}\\cdot\\vec{b} = \\vec{b}\\cdot\\vec{a}\r\n\t\t\\end{equation*}\r\n\t\tthe same as scalar multiplication.\r\n\t\\item \\textbf{Distributive}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{a}\\cdot\\left(\\vec{b}+\\vec{c}\\right) = \\vec{a}\\cdot\\vec{b}+\\vec{a}\\cdot\\vec{c}\r\n\t\t\\end{equation*}\r\n\t\tthe same as scalar multiplication.\r\n\t\\item \\textbf{\\underline{NOT} Associative}\r\n\t\t$\\left(\\vec{a}\\cdot\\vec{b}\\right)\\cdot\\vec{c}$ is a nonsense expression.\r\n\t\tHowever, like scalar multiplication, dot products are scalar associative.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\left(c\\cdot\\vec{a}\\right)\\cdot\\vec{b} = \\vec{a}\\cdot\\left(c\\cdot\\vec{b}\\right)\r\n\t\t\\end{equation*}\r\n\\end{enumerate}", "meta": {"hexsha": "fb8a77f22196f976359c67f81e9fd679322067a9", "size": 1689, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/vectorsMatrices/dotProducts.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "common/vectorsMatrices/dotProducts.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "common/vectorsMatrices/dotProducts.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 45.6486486486, "max_line_length": 126, "alphanum_fraction": 0.6944937833, "num_tokens": 562, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7390723568853387}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Appendix}\\label{sec:}\n\n\\subsection{Proof of the Cauchy-Schwarz inequality for random variables}\n\nWe need to show that for any two random variables $X$ and $Y$,\n\\[\n\\expe(XY)^2 \\leq \\expe(X^2)\\expe(Y^2)\n\\]\nwith equality if and only if $\\prob(Y=aX)=1$ for some $a\\in\\R$.\n\nFirst we need the following technical result (which we shall not prove).\n% lemma\n\\begin{lemma}\\label{lem:pos_rv_expe_zero}\nIf $X\\geq 0$ and $\\expe(X)=0$ then $\\prob(X=0)=1$.\n\\end{lemma}\n\n\\begin{proof}[Cauchy-Schwarz]\n$X^2$ and $Y^2$ are non-negative random variables, so by Lemma~\\ref{lem:pos_rv_expe_zero} we can assume that $\\expe(X^2)>0$ and $\\expe(Y^2)>0$ (otherwise both sides of the inequality are identically zero).\n\nLet $a\\in\\R$ consider the random variable $Z=aX-Y$. By the properties of expectation,\n\\begin{align*}\nZ^2\\geq 0 \n\t& \\Rightarrow \\expe(Z^2)\\geq 0  \\qquad\\text{(positivity)}\\\\\n\t& \\Rightarrow \\expe(a^2X^2 - 2aXY + Y^2) \\geq 0  \\\\\n\t& \\Rightarrow a^2\\expe(X^2) - 2a\\expe(XY) + \\expe(Y^2) \\geq 0 \\qquad\\text{(linearity).}\n\\end{align*}\n\n\\bit\n\\it Let $q(a)=a^2\\expe(X^2) - 2a\\expe(XY) + \\expe(Y^2)$. This is a quadratic expression in $a$.\n\\eit\nSince $q(a)\\geq 0$ for all $a\\in\\R$, the roots of the quadratic equation $q(a)=0$, given by\n\\[\na = \\frac{\\expe(XY)\\pm\\sqrt{\\expe(XY)^2-\\expe(X^2)\\expe(Y^2)}}{\\expe(X^2)}\n\\]\nare either both complex (discriminant is negative) or co-incide (discriminant is zero). \n\\bit\n\\it Hence $\\expe(XY)^2-\\expe(X^2)\\expe(Y^2) \\leq 0$, or equivalently $\\expe(XY)^2\\leq \\expe(X^2)\\expe(Y^2)$.\n\\eit\n\nThe discriminant is zero if and only if the quadratic has one real root, which occurs if and only if $\\expe(Z^2)=0$ for some $a\\in\\R$, i.e.\n\\[\n\\expe\\left((aX-Y)^2\\right) = 0\\qquad\\text{for some $a\\in\\R$.}\n\\]\nBecause $(aX-Y)^2$ is a non-negative random variable, we have by Lemma~\\ref{lem:pos_rv_expe_zero} that\n\\[\n\\prob\\big[(aX-Y)^2 = 0\\big] = 1\n\\]\nor equivalently, $\\prob\\big(Y = aX) = 1$, as required. \n\\end{proof}\n", "meta": {"hexsha": "9537611a052034b8d8cdf0d3b20709ede1264ef7", "size": 2011, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/05F_proof_of_cauchy_schwarz.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/05F_proof_of_cauchy_schwarz.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/05F_proof_of_cauchy_schwarz.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 37.9433962264, "max_line_length": 205, "alphanum_fraction": 0.6489308802, "num_tokens": 776, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.739072354537584}}
{"text": "\\documentclass[12pt]{article}\n\\input{physics1}\n\\begin{document}\n\n\\section*{NYU Physics I---small variations}\n\n\\paragraph{\\theproblem}\\refstepcounter{problem}%\nYou have a cubic block of ice, $1.000\\,\\m$ on a side.  By what\nfractional amount does its mass decrease if you shave a millimeter off\nof it in each dimension (ie, so that it becomes a cubic block of ice,\n$0.999\\,\\m$ on a side)?\n\n\\paragraph{\\theproblem}\\refstepcounter{problem}%\nExplain why your answer to the above was so close to $3\\times\n10^{-3}$.  You have two explanations to give, \\textsl{(a)}~one from\nthe point of view of the three operations you did (shave one face,\nthen the next, then the next), and \\textsl{(b)}~one from the point of\nview of small variations (write the formula for the volume $V$ in\nterms of the side length $\\ell$ and differentiate with respect to\n$\\ell$).\n\n\\paragraph{\\theproblem}\\refstepcounter{problem}%\nGive a general argument---using calculus---that\n\\begin{equation}\n\\lim_{\\epsilon\\rightarrow 0}\\,(1+\\epsilon)^n=1+n\\,\\epsilon \\quad .\n\\end{equation}\n\n\\paragraph{\\theproblem}\\refstepcounter{problem}%\nWith a calculator, compute the sine of the angle $\\theta=0.1\\,\\rad$.\nNow compute the error you make if you use $\\sin\\theta=\\theta$.  Now\ncompare that error to the quantity $\\theta^2/2$ and $\\theta^3/6$.  Is\nit close to either?\n\n\\paragraph{\\theproblem}\\refstepcounter{problem}%\nNow compute the error you make if you use\n\\begin{equation}\n\\lim_{\\theta\\rightarrow 0}\\,\\sin\\theta=\\theta-\\frac{1}{6}\\,\\theta^3 \\quad .\n\\label{eq:third}\n\\end{equation}\nDo you think the \\emph{next} term in the Taylor series for sine will\nbe negative or positive on this basis?\n\n\\paragraph{\\theproblem}\\refstepcounter{problem}%\nInside of what angle is the approximation $\\sin\\theta=\\theta$ good to\none percent?  What is this angle in degrees?\n\n\\paragraph{\\theproblem}\\refstepcounter{problem}%\nNow square the expression in Equation~(\\ref{eq:third}) and compare it\nto the second-order expression for cosine:\n\\begin{equation}\n\\lim_{\\theta\\rightarrow 0}\\,\\cos\\theta=1-\\frac{1}{2}\\,\\theta^2 \\quad .\n\\end{equation}\nShow that this is consistent with the trigonometric identity\n\\begin{equation}\n\\sin^2\\theta = \\frac{1 - \\cos(2\\,\\theta)}{2} \\quad .\n\\end{equation}\n\n\\end{document}\n", "meta": {"hexsha": "7e3692db6bdef410e5d56c417556be2d4867f7dc", "size": 2237, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/worksheet_variations.tex", "max_stars_repo_name": "davidwhogg/Physics1", "max_stars_repo_head_hexsha": "6723ce2a5088f17b13d3cd6b64c24f67b70e3bda", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-11-13T03:48:56.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-13T03:48:56.000Z", "max_issues_repo_path": "tex/worksheet_variations.tex", "max_issues_repo_name": "davidwhogg/Physics1", "max_issues_repo_head_hexsha": "6723ce2a5088f17b13d3cd6b64c24f67b70e3bda", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2016-10-07T19:48:57.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-29T22:47:25.000Z", "max_forks_repo_path": "tex/worksheet_variations.tex", "max_forks_repo_name": "davidwhogg/Physics1", "max_forks_repo_head_hexsha": "6723ce2a5088f17b13d3cd6b64c24f67b70e3bda", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.9152542373, "max_line_length": 75, "alphanum_fraction": 0.7402771569, "num_tokens": 671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7390723503967536}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Use row operations to calculate the following determinants:\n  \\begin{equation*}\n    (a)~\n    \\begin{absmatrix}{rrr}\n      1 & 2 & 1 \\\\\n      2 & 3 & 2 \\\\\n      -4 & 1 & 2\n    \\end{absmatrix},\n    \\quad\n    (b)~\n    \\begin{absmatrix}{rrr}\n      2 & 1 & 3 \\\\\n      2 & 4 & 2 \\\\\n      1 & 4 & -5\n    \\end{absmatrix},\n    \\quad\n    (c)~\n    \\begin{absmatrix}{rrrr}\n      1 & 2 & 1 & 2 \\\\\n      3 & 1 & -2 & 3 \\\\\n      -1 & 0 & 3 & 1 \\\\\n      2 & 3 & 2 & -2\n    \\end{absmatrix},\n    \\quad\n    (d)~\n    \\begin{absmatrix}{rrrr}\n      1 & 4 & 1 & 2 \\\\\n      3 & 2 & -2 & 3 \\\\\n      -1 & 0 & 3 & 3 \\\\\n      2 & 1 & 2 & -2\n    \\end{absmatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item\n      \\begin{equation*}\n        \\begin{absmatrix}{rrr}\n          1 & 2 & 1 \\\\\n          2 & 3 & 2 \\\\\n          -4 & 1 & 2\n        \\end{absmatrix} = -6.\n      \\end{equation*}\n    \\item\n      \\begin{equation*}\n        \\begin{absmatrix}{rrr}\n          2 & 1 & 3 \\\\\n          2 & 4 & 2 \\\\\n          1 & 4 & -5\n        \\end{absmatrix} = -32.\n      \\end{equation*}\n    \\item One can row reduce this, using only row operations of the\n      third kind, to\n      \\begin{equation*}\n        \\def\\arraystretch{1.2}\n        \\begin{mymatrix}{rrrr}\n          1 & 2 & 1 & 2 \\\\\n          0 & -5 & -5 & -3 \\\\\n          0 & 0 & 2 & \\frac{9}{5} \\\\\n          0 & 0 & 0 & -\\frac{63}{10}\n        \\end{mymatrix}.\n      \\end{equation*}\n      Therefore, the determinant is $-63$.\n    \\item One can row reduce this, using only row operations of the\n      third kind, to\n      \\begin{equation*}\n        \\def\\arraystretch{1.2}\n        \\begin{mymatrix}{rrrr}\n          1 & 4 & 1 & 2 \\\\\n          0 & -10 & -5 & -3 \\\\\n          0 & 0 & 2 & \\frac{19}{5} \\\\\n          0 & 0 & 0 & -\\frac{211}{20}\n        \\end{mymatrix}.\n      \\end{equation*}\n      Thus the determinant is $211$.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "0e1bcab470dcf8ea10accc50303578c4f6cadaea", "size": 1921, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Determinants-RowOperations.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Determinants-RowOperations.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Determinants-RowOperations.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 23.4268292683, "max_line_length": 67, "alphanum_fraction": 0.4325871942, "num_tokens": 754, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479467, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.7390723479751115}}
{"text": "\\lab{Algorithms}{Elementary Matrices}{Elementary Matrices}\n\\label{lab:LUdecomp}\n\\objective{In this section we will use elementary matrices to find the RREF and to find the LU decomposition.}\n\nIn Linear algebra there are 3 elementary row operations: switching two rows, multiplying a row by a constant, and adding a multiple of one row to another row.  We carry out each of these operations with a corresponding elementary matrix.  These matrices are easy to construct. Suppose $A$ is an $m \\times n$ matrix and you want to perform one of the three elementary operations on $A$. You can do this be constructing the $m \\times m$ identity matrix, $I$, performing the elementary row operation on $I$ to obtain $E$ and then multiplying $EA$.  For example, consider the matrix\n\\[\nA = \\begin{pmatrix}\na_{11}&a_{12}&a_{13}&a_{14}\\\\\na_{21}&a_{22}&a_{23}&a_{24}\\\\\na_{31}&a_{32}&a_{33}&a_{34}\n\\end{pmatrix}\n\\]\nIf we want to swap the first two rows, we can left multiply the\nmatrix $A$ by:\n\\[\nE = \\begin{pmatrix}\n0&1&0\\\\\n1&0&0\\\\\n0&0&1\n\\end{pmatrix},\n\\]\nthen\n\\[\nE A =\n\\begin{pmatrix}\na_{21}&a_{22}&a_{23}&a_{24}\\\\\na_{11}&a_{12}&a_{13}&a_{14}\\\\\na_{31}&a_{32}&a_{33}&a_{34}\n\\end{pmatrix}.\n\\]\nE in this case is called a type I matrix.\n\nNow let's examine the next row operation.  If we want to multiply,\nsay, the second row of $A$ by the constant $b$, we can left multiply\nthe matrix $A$ by the following matrix:\n\\[\n\\tilde{E} = \\begin{pmatrix}\n1&0&0\\\\\n0&b&0\\\\\n0&0&1\n\\end{pmatrix}.\n\\]\nThen\n\\[\n\\tilde{E} A =\n\\begin{pmatrix}\na_{11}&a_{12}&a_{13}&a_{14}\\\\\nb a_{21}&b a_{22}&b a_{23}&b a_{24}\\\\\na_{31}&a_{32}&a_{33}&a_{34}\n\\end{pmatrix}.\n\\]\n$\\tilde{E}$ is called a type II matrix.  \n\nNow let's examine the last row operation.  If we want to multiply,\nsay, the first row of $A$ by a constant $c$ and add it to the second\nrow, we can left multiply the matrix $A$ by the following matrix:\n\\[\n\\widehat{E} = \\begin{pmatrix}\n1&0&0\\\\\nc&1&0\\\\\n0&0&1\n\\end{pmatrix}.\n\\]\nThen\n\\[\n\\widehat{E} A =\n\\begin{pmatrix}\na_{11}&a_{12}&a_{13}&a_{14}\\\\\nc a_{11} + a_{21}&c a_{12} + a_{22}&c a_{13} + a_{23}&c a_{14} + a_{24}\\\\\na_{31}&a_{32}&a_{33}&a_{34}\n\\end{pmatrix}.\n\\]\n$\\widehat{E}$ is called a type III matrix.\n\nBelow, the elementary matrices corresponding to each row operation is implemented in Python.\n\\lstinputlisting[style=python, style=fromfile, name=row_opers.py]{row_opers.py}\n\n\\section*{Programming Row Reduction}\n\nA fundamental problem in linear algebra is using matrix representations to solve systems of linear equations.  In this section, we do this by using elementary matrices to reduce a matrix into ``row echelon form'' (REF), as opposed to ``reduced row echelon form'' (RREF).  We remark that to solve a linear system, it is actually faster computationally to use REF and then finish with back-substitution, than it is to use RREF.  Consider the following matrix: \n\n\\[\n\\begin{pmatrix}\n4&5&6&3 \\\\\n2&4&6&4 \\\\\n7&8&0&5\n\\end{pmatrix}\n\\]\n\nBy iteratively left multiplying by elementary matrices, we can reduce as follows:\n\nRemember that our functions returns the elementary array corresponding to the desired row operation.  Also note that setting the type of our initial array is crucial.\n\\begin{lstlisting}[style=python]\n: import scipy as sp\n: import row_opers as op\n: A = sp.array([[4, 5, 6, 3],[2, 4, 6, 4],[7, 8, 0, 5]], dtype='float32')\narray([[ 4.,  5.,  6.,  3.],\n       [ 2.,  4.,  6.,  4.],\n       [ 7.,  8.,  0.,  5.]], dtype=float32)\n: A1 = sp.dot(op.cmultadd(3,1,0,-A[1,0]/A[0,0]), A); A1\narray([[ 4. ,  5. ,  6. ,  3. ],\n       [ 0. ,  1.5,  3. ,  2.5],\n       [ 7. ,  8. ,  0. ,  5. ]])\n: A2 = sp.dot(op.cmultadd(3,2,0,-A1[2,0]/A1[0,0]), A1); A2\narray([[  4.  ,   5.  ,   6.  ,   3.  ],\n       [  0.  ,   1.5 ,   3.  ,   2.5 ],\n       [  0.  ,  -0.75, -10.5 ,  -0.25]])\n: A3 = sp.dot(op.cmultadd(3,2,1,-A2[2,1]/A2[1,1]), A2); A3\narray([[ 4. ,  5. ,  6. ,  3. ],\n       [ 0. ,  1.5,  3. ,  2.5],\n       [ 0. ,  0. , -9. ,  1. ]])\n\\end{lstlisting}\n\nTo complete REF we would need to divide each row by its leading\ncoefficient.  We can do that using Type II matrices.  We leave it to\nyou to carry this out.\n\n\\begin{problem}\n\\label{prob:REF}\nWrite a Python function, which takes as input an\n$n\\times (n+1)$ matrix (in other words and \\emph{augmented} matrix) and performs the above naive row reduction to REF using elementary matrices.\n\\end{problem}\n\n\\section*{LU Decomposition}\n\nAgain, consider the matrix $A$. By iteratively left multiplying by\nelementary matrices, we reduce as follows:\n\n\\begin{lstlisting}[style=python]\n: E1 = op.cmultadd(3,1,0,-A[1,0]/A[0,0]); E1\narray([[ 1. ,  0. ,  0. ],\n       [-0.5,  1. ,  0. ],\n       [ 0. ,  0. ,  1. ]])\n: B1 = sp.dot(E1, A)\narray([[ 4. ,  5. ,  6. ,  3. ],\n       [ 0. ,  1.5,  3. ,  2.5],\n       [ 7. ,  8. ,  0. ,  5. ]])\n: E2 = op.cmultadd(3,2,0,-B1[2,0]/B1[0,0])\n: B2 = sp.dot(E2, B1)\n: E3 = op.cmultadd(3,2,1,-B2[2,1]/B2[1,1])\n: U = sp.dot(E3, B2); U\narray([[ 4. ,  5. ,  6. ,  3. ],\n       [ 0. ,  1.5,  3. ,  2.5],\n       [ 0. ,  0. , -9. ,  1. ]])\n\\end{lstlisting}\nNote that we have reduced the above matrix into upper-triangular\nform, denoted as $U$.  Hence, we have\n\\[\nU = E_3 E_2 E_1 A.\n\\]\nSince the elementary matrices are invertible, we also have\n\\[\n(E_3 E_2 E_1)^{-1} U =  A.\n\\]\nThis can be re-written as\n\\[\nE_1^{-1} E_2^{-1} E_3^{-1} U =  A.\n\\]\nThen we define $L$ to be\n\\[\nL = E_1^{-1} E_2^{-1} E_3^{-1},\n\\]\nwhich yields $L U = A$.  \n\\begin{lstlisting}[style=python]\n: from scipy import linalg as la\n: I = lambda x: la.inv(x)\n: L = sp.dot(sp.dot(I(E1), I(E2)), I(E3)); L\narray([[ 1.  ,  0.  ,  0.  ],\n       [ 0.5 ,  1.  ,  0.  ],\n       [ 1.75, -0.5 ,  1.  ]])\n: sp.dot(L, U)\narray([[ 4.,  5.,  6.,  3.],\n       [ 2.,  4.,  6.,  4.],\n       [ 7.,  8.,  0.,  5.]])\n\\end{lstlisting}\nWhat makes $LU$ decomposition so easy is that the inverses of\nelementary matrices are elementary matrices.  For example, the\ninverse of a Type 3 elementary matrix is the same matrix with the\nopposite sign in the $(j,k)$ entry.  In the above problem, we have:\nNote that the minus signs are gone.  Doing it this way, we don't\nhave to actually invert anything to compute $L$.  This makes the\ncomputation much faster.\n\n\\section*{Why Should I Care?}\n\nThe LU Decomposition isn't very useful when doing matrix computation\nby hand.  It is, however, very important in scientific computation\nfor the following reasons:\n\\begin{itemize}\n\\item If you want to solve the matrix equation $A x = b$, for several different $b's$, you can replace $A$ with $L$ and $U$, giving $L U x = b$.  Then solve the equations $L y = b$ and $U x = y$, using forward and backward substitution, respectively.  This is actually faster than solving them with row reduction.\n\\item The $LU$ decomposition allows quick computation of both inverses and determinants.\n\\item For very large matrices the $LU$ decomposition is crucial.  Indeed one can perform the $LU$ decomposition on a given matrix $A$ without needing additional space, that is, the program actually over-writes $A$ with $L$ and $U$.  Note that since the diagonal of $L$ are all ones, they don't need to be stored, and so the upper diagonal (including the diagonal) is $U$ and the lower diagonal (not including the diagonal) is $L$.\n\\end{itemize}\n\n\\begin{problem}\n\\label{prob:LU}\nWrite a Python function which takes as input\na random $n\\times n$ matrix, performs the LU decomposition and\nreturns $L$ and $U$.  To verify that it works, multiply $L$ and $U$ together\nand compare to $A$. Note: you should not use the \\li{inv} function when you do this. You should only use the elementary matrices that we just created.\nAdditionally, have your function count the number of operations needed to perform the LU decomposition.\n\\end{problem}\n\n\\begin{problem}\n\\label{prob:det}\nWrite a Python function which uses the solution to Problem \\ref{prob:LU} to find the determinant of $A$.\n\\end{problem}\n", "meta": {"hexsha": "93446eaa109da03e568a5f5e2ccf6e22588e2868", "size": 7838, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/ElemMatrices/ElemMatr_C.tex", "max_stars_repo_name": "jasongrout/numerical_computing", "max_stars_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/ElemMatrices/ElemMatr_C.tex", "max_issues_repo_name": "jasongrout/numerical_computing", "max_issues_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/ElemMatrices/ElemMatr_C.tex", "max_forks_repo_name": "jasongrout/numerical_computing", "max_forks_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-21T23:06:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-21T23:06:27.000Z", "avg_line_length": 37.6826923077, "max_line_length": 578, "alphanum_fraction": 0.6524623628, "num_tokens": 2773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.739072340784073}}
{"text": "\n\\chapter{Some Limit Theorems}\n\n\\section{Important/Useful Theorems}\n\n\\subsection{Weak Law of Large Numbers}\nLet $\\xi_1, \\xi_2, ..., \\xi_n$ be $n$ independent indentically distributed random variables with mean $a$ and variance $\\sigma^2$.  Then, given any $\\delta > 0$ and $\\epsilon >0$, however small, there is an integer, $n$ such that:\n\\begin{equation}\n\ta- \\epsilon \\leq \\frac{1}{n}(\\xi_1 +\\xi_2 + \\cdots + \\xi_n) \\leq a + \\epsilon\n\\end{equation}\nwith probability greater than $1- \\delta$.\n\n\n\\subsection{Generating Functions}\n\nFor the \\textbf{discrete} random variable $\\xi$ with probability distribution $P_{\\xi}(k)$, the generating function is defined as\n\n\\begin{equation}\n\tF_{\\xi}(z) = \\sum_{k=0}^{\\infty}P_{\\xi}(k)z^k\n\\end{equation}\nwhich yields some cool relations:\n\\begin{eqnarray}\n\tP_{\\xi}(k) = \\frac{1}{k!}F_{\\xi}^{(k)}(0) \\\\\n\t\\textbf{E}\\xi = F'(1) \\\\\n\t\\sigma^2 =F''(1) + F'(1) - [F'(1)]^2\n\\end{eqnarray}\n\nNote, also, that while you sum together random variables, you multiply generating functions.\n\n\\subsection{Thm. 6.2}\n\nThe sequence of probability distributions, $P_n(k)$ with generating functions $F_n(z)$ where $n=1, 2, 3, ....$ converges weakly to the distribution $P(k)$ with distribution function $F(z)$ iff  \n\n\\begin{equation}\n\t\\lim_{n\\rightarrow \\infty} F_n(z) = F(z)\n\\end{equation}\n\n\\subsection{Characteristic Functions}\n\nFor a real random variable $\\xi$, its generating function is defined as\n\n\\begin{equation}\n\tf_{\\xi}(t) = \\textbf{E}e^{i \\xi t} = F_{\\xi}(e^{i t}) = \\sum_{k=0}^{\\infty} P_{\\xi}(k)e^{i k t}\n\\end{equation}\nOr, if the variable is continuous:\n\\begin{equation}\n\tf_{\\xi}(t) = \\int_{-\\infty}^{\\infty} P_{\\xi}(x)e^{i x t} dx\n\\end{equation}\nWhere it is clear that is represents the discrete or continuous fourier transform of the probability distribution and as such, the inverse is true:\n\\begin{equation}\n\tP_{\\xi}(x) = \\frac{1}{2 \\pi}\\int_{-\\infty}^{\\infty} f_{\\xi}(t)e^{-i x t} dt\n\\end{equation}\nLike Generating functions, there are some cool properties that can be exploited:\n\\begin{eqnarray}\n\t\\textbf{E}\\xi = -if_{\\xi}'(0) \\\\\n\t\\textbf{D}\\xi = -f_{\\xi}''(0) + [f_{\\xi}'(0)]^2\n\\end{eqnarray}\nAnd just like generating functions, they multiply together for random variables that add together.\n\n\\subsection{The Central Limit Theorem}\n\nA sequence of random variables $\\xi_1, \\xi_2, \\xi_3, ...$ is said to satisfy the central limit theorem if\n\\begin{equation}\n\t\\lim_{n\\rightarrow \\infty} \\textbf{P}\\{ x' \\leq \\frac{S_n - \\textbf{E}S_n}{\\sqrt{\\textbf{D}S_n}} \\leq x''\\} = \\int_{x'}^{x''}e^{\\frac{-x^2}{2}}dx\n\\end{equation}\nWhere\n\\begin{equation}\n\tS_n = \\sum_{k=1}^n \\xi_k\n\\end{equation}\n\n\\subsection{Thm. 6.3}\n\nIf the same series of random variables as above each has mean $a_k$ and variance $\\sigma^2_k$ and satisfies the Lyapunov condition:\n\\begin{equation}\n\t\\lim_{n\\rightarrow \\infty} \\frac{1}{B_n^3} \\sum_{k=1}^n \\textbf{E}|\\xi_k - a_k|^3 = 0\n\\end{equation}\nWhere\n\\begin{equation}\n\tB_n^2 = \\textbf{D}S_n = \\sum_{k=1}^n \\sigma^2_k\n\\end{equation}\nthen the sequence will satisfy the central limit theorem.\n\n\n\\section{Answers to Problems}\n\\subsection{}\n%problem6.1\n\\begin{eqnarray}\n\ta- \\epsilon \\leq \\frac{1}{n}(\\xi_1 +\\xi_2 + \\cdots + \\xi_n) \\leq a + \\epsilon \\\\\n\ta- \\epsilon \\leq \\frac{1}{n}\\sum_{k=1}^n \\xi_i \\leq a + \\epsilon \\\\\n\t- \\epsilon \\leq \\frac{1}{n}\\sum_{k=1}^n \\xi_i -a \\leq \\epsilon \\\\\n\t\\left| \\frac{1}{n}\\sum_{k=1}^n \\xi_i -a  \\right| < \\epsilon\n\\end{eqnarray}\nAnd we know this happens with probability\n\\begin{equation}\n\tP_n = 1- \\delta\n\\end{equation}\n\\begin{equation}\n\t\\textbf{P} \\left[ \\left| \\frac{1}{n}\\sum_{k=1}^n \\xi_i -a  \\right| < \\epsilon  \\right] = 1 - \\delta\n\\end{equation}\n\\begin{equation}\n\t\\lim_{n\\rightarrow \\infty} \\textbf{P} \\left[ \\left| \\frac{1}{n}\\sum_{k=1}^n \\xi_i -a  \\right| < \\epsilon  \\right] = 1 \n\\end{equation}\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem6.2\n\nSince we know the mean, we most certainly can use the equation to estimate the variance: look what it's doing.  It's taking the sum of the square of the distances from the known mean and dividing by the number of trials: the classic standard deviation calculation.\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem6.3\nWe need to start with some calculations on the distribution:\n\\begin{eqnarray}\n\tE\\xi = \\int_0^{\\infty} x \\frac{x^m}{m!}e^{-x} dx = m+1 \\\\\n\tE\\xi^2 = \\int_0^{\\infty} x^2 \\frac{x^m}{m!}e^{-x} dx = (m+2)(m+1)\n\\end{eqnarray}\n\n\\begin{equation}\n\tP \\{  | \\xi - a | > \\epsilon  \\} \\leq \\frac{1}{\\epsilon^2}\\textbf{E}(\\xi - a)^2\n\\end{equation}\nclearly we can manipulate it in this manner:\n\\begin{equation}\n\t-P \\{  | \\xi - a | > \\epsilon  \\} \\geq  - \\frac{1}{\\epsilon^2}\\textbf{E}(\\xi - a)^2\n\\end{equation}\n\\begin{equation}\n\t1-P \\{  | \\xi - a | > \\epsilon  \\} \\geq 1 - \\frac{1}{\\epsilon^2}\\textbf{E}(\\xi - a)^2\n\\end{equation}\n\\begin{equation}\n\tP \\{  | \\xi - a | < \\epsilon  \\} \\geq 1 - \\frac{1}{\\epsilon^2}\\textbf{E}(\\xi - a)^2\n\\end{equation}\nlet $\\epsilon = a = m+1$\n\\begin{equation}\n\tP \\{ 0 \\leq \\xi  \\leq 2(m+1)  \\} \\leq 1 - \\frac{1}{(m+1)^2}[(m+2)(m+1) - (m+1)^2]\n\\end{equation}\n\\begin{equation}\n\tP \\{ 0 \\leq \\xi  \\leq 2(m+1)  \\} \\leq \\frac{m}{m+1}\n\\end{equation}\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem6.4\nUnder these circumstances, we expect 500 A and the standard deviation is $\\sqrt{250}= 5 \\sqrt{10} \\approx 15$ therefore the $\\pm 100$ from the mean is more than $\\pm 6 \\sigma$ meaning there is indeed far more that .97 probability of seeing the mean between these two values.\n\n\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem6.5\n\\begin{eqnarray}\n\tF_{\\xi}(z) = \\frac{z +z^2 + z^3 + z^4 + z^5 +z^6}{6}\n\\end{eqnarray}\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem6.6\n\\begin{eqnarray}\n\tF'_{\\xi}(z) = \\frac{1+ 2z + 3z^2 + 4z^3 + 5z^4 + 6z^5}{6}\n\\end{eqnarray}\n\\begin{eqnarray}\n\tF'_{\\xi}(1) = \\frac{21}{6} = \\frac{7}{2} = \\textbf{E}\\xi\n\\end{eqnarray}\n\\begin{eqnarray}\n\tF''_{\\xi}(z) = \\frac{2+ 6z + 12z^2 + 20z^3 + 30z^4 }{6}\n\\end{eqnarray}\n\\begin{eqnarray}\n\tF''_{\\xi}(1) = \\frac{70}{6} = \\frac{35}{3}  \n\\end{eqnarray}\n\\begin{eqnarray}\n\t\\sigma^2 = F''_{\\xi}(1) + F'_{\\xi}(1) + [F'_{\\xi}(1)]^2  = \\frac{35}{3} + \\frac{7}{2} - \\frac{49}{4}  = \\frac{35}{12}\n\\end{eqnarray}\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem6.7\nIn order to do this problem with 6.6, we need the generating function\n\\begin{eqnarray}\n\tF_{\\xi}(z) = \\sum_{k=0}^{\\infty} \\frac{ a^k }{k!}e^{-a} z^k = e^{a(z-1)}\n\\end{eqnarray}\n\\begin{eqnarray}\n\tF'_{\\xi}(z) = a e^{a (z-1)} \\\\\n\tF'_{\\xi}(1) = a e^{0}  = a = \\textbf{E}\\xi\\\\\n\\end{eqnarray}\n\\begin{eqnarray}\n\tF''_{\\xi}(z) = a^2 e^{a (z-1)} \\\\\n\tF''_{\\xi}(1) = a^2\n\\end{eqnarray}\n\\begin{eqnarray}\n\t\\sigma^2 = F''_{\\xi}(1) + F'_{\\xi}(1) - [F'_{\\xi}(1)]^2  = a^2 + a - a^2 = a\n\\end{eqnarray}\n\n\n\\subsection{}\n%problem6.8\nIn order to do this problem with 6.6, we need the generating function\n\\begin{eqnarray}\n\tF_{\\xi}(z) = \\sum_{k=0}^{\\infty} \\frac{ a^k }{(1+a)^{k+1}} z^k = \\frac{-a-1}{(a+1) (a z-a-1)}\n\\end{eqnarray}\n\\begin{eqnarray}\n\tF'_{\\xi}(z) = \\frac{(a+1) a}{(a+1) (a z-a-1)^2} = \\frac{a}{(a z-a-1)^2} \\\\\n\tF'_{\\xi}(1) = a =  \\textbf{E}\\xi\\\\\n\\end{eqnarray}\n\\begin{eqnarray}\n\tF''_{\\xi}(z) = \\frac{-2 a^2}{(a z-a-1)^3} \\\\\n\tF''_{\\xi}(1) = 2 a^2\n\\end{eqnarray}\n\\begin{eqnarray}\n\t\\sigma^2 = F''_{\\xi}(1) + F'_{\\xi}(1) - [F'_{\\xi}(1)]^2  = 2 a^2 + a - a^2 = a^2 - a = \\textbf{D}\\xi\n\\end{eqnarray}\n\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem6.9\nThese two distributions have generating functions:\n\\begin{eqnarray}\n\tF_{\\xi_1} = e^{a(z-1)} \\\\\n\tF_{\\xi_2} = e^{a'(z-1)}\n\\end{eqnarray}\nwhich means that $\\eta$ has this generating function:\n\\begin{eqnarray}\n\tF_{\\eta} =F_{\\xi_1}F_{\\xi_2} = e^{a(z-1)}e^{a'(z-1)} = e^{(a'+ a)(z-1)}  \\\\\n\\end{eqnarray}\nWhich, according to theorem 6.2 means there that $\\eta$ is a Poisson distribution with mean $a+a'$.\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem6.10\nFor any given experiment we can define an individual generating function: $F_i(z) = q_i + z p_i$ meaning that for the entire function\n\\begin{eqnarray}\n\tF(z) = \\prod_{i=1}^n F_i(z) = \\prod_{i=1}^n (q_i + z p_i)\n\\end{eqnarray}\nThe trick that Feller uses at this point is to take the log\n\\begin{eqnarray}\n\t\\log F(z) = \\sum_{i=1}^n \\log F_i(z) = \\sum_{i=1}^n \\log (q_i + z p_i) \\\\\n\t\\log F(z) = \\sum_{i=1}^n \\log (1 - p_i + z p_i) = \\sum_{i=1}^n \\log (1 - p_i( z -1))\n\\end{eqnarray}\nWe were, however, told that the largest probability goes to zero so we take the taylor series of each term, $\\log (1-x) \\approx - x$\n\\begin{eqnarray}\n\t\\lim_{n \\rightarrow \\infty} \\log F(z) =  \\sum_{i=1}^n \\log (1 - p_i( z -1)) = \\sum_{i=1}^n  p_i( 1 - z ) = - \\lambda (z - 1) \\\\\n\t\\lim_{n \\rightarrow \\infty} F(z) = e^{- \\lambda (z - 1)}\n\\end{eqnarray}\nAnd, according to theorem 6.2, the probability distribution is Poissonian.\n\\textbf{Answer verified}\n\n\n\\subsection{}\n%problem6.11\n\n\\begin{eqnarray}\n\tp_{\\xi}(x) = \\frac{1}{2} e^{-|x|} \\\\\n\tf_{\\xi}(t) = \\int_{-\\infty}^{\\infty} \\frac{1}{2} e^{ i x t } e^{-|x|} dx \\\\\n\tf_{\\xi}(t) = \\frac{1}{t^2+1}\n\\end{eqnarray}\n\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem6.12\n\\begin{eqnarray}\n\tf_{\\xi}(t) = \\frac{1}{t^2+1} \\\\\n\tf'_{\\xi}(t) =  -\\frac{2 t}{\\left(t^2+1\\right)^2} = i \\textbf{E}\\xi \\\\\n\tf'_{\\xi}(0) =  i \\textbf{E}\\xi = 0 \\\\\n\tf''_{\\xi}(t) = \\frac{8 t^2}{\\left(t^2+1\\right)^3}-\\frac{2}{\\left(t^2+1\\right)^2} \\\\\n\tf''_{\\xi}(0) = - \\sigma^2 = -2\n\\end{eqnarray}\n\n\\textbf{Answer verified}\n\n\n\\subsection{}\n%problem6.13\nFor a uniform distribution\n\\begin{eqnarray}\n\tp(x) = \\frac{1}{b-a}\n\\end{eqnarray}\nTherefore the characteristic is:\nFor a uniform distribution\n\\begin{eqnarray}\n\tf(t) = \\frac{1}{b-a} \\int_a^b e^{i x t} dx = \\frac{i \\left(e^{i a t}-e^{i b t}\\right)}{t(b-a)}\n\\end{eqnarray}\n\\textbf{Answer verified}\n\n\n\\subsection{}\n%problem6.14\n\\begin{eqnarray}\n\tf_{\\xi} (t) = e^{-a|t|} \\\\\n\tp(x) = \\frac{1}{2 \\pi} \\inf_{\\infty}^{\\infty} e^{-a|t|} e^{- i x t} \\\\\n\tp(x) = \\frac{a}{\\pi(a^2+x^2)}\n\\end{eqnarray} \n\\textbf{Answer verified}\n\n\\subsection{}\n%problem6.15\nLooking at the characteristic, there is clearly going to be a discontinuity in the deirvative at $t=0$, meaning that the derivative does not exist at that point.  This jibes well with what we've done before because we proved in problem 43 on page 24 that the probability distribution this characteristic produces does not have a mean or a standard deviation.\n\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem6.16\nFor the single die, $E\\xi = 3.5$ and $D\\xi = \\frac{35}{12}$.  The distribution for $n$ dice rolls is binomial but in the limit of large $n$, it approximates a normal distribution with $E\\xi = 3.5n$ and $D\\xi = n \\frac{35}{12}$\n\\begin{eqnarray}\n\tP\\{ 3450 \\leq x \\leq 3550  \\} = \\int_{3450}^{3550} \\sqrt{\\frac{1}{\\frac{70 \\pi \\cdot 10^3}{12}}}e^{-\\frac{(x-3500)^2}{\\frac{70 \\cdot 10^3}{12}}} dx \\\\\n\t= 0.645461  \\\\\n\\end{eqnarray} \n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem6.17\n\nWe want to prove here that the distribution satisfies the Lyapunov condition:\n\\begin{equation}\n\t\\lim_{n\\rightarrow \\infty} \\frac{1}{B_n^3} \\sum_{k=1}^n \\textbf{E}|\\xi_k - a_k|^3 = 0\n\\end{equation}\nWhere\n\\begin{equation}\n\tB_n^2 = \\textbf{D}S_n = \\sum_{k=1}^n \\sigma^2_k\n\\end{equation}\n\nThe machinations of which are left to the reader... sorry!\n\n\\textbf{Answer not verified}\n\n%%answer template\n%\\subsection{}\n%%problem n.n\n%\n%\n%\\begin{equation}\n%\t\n%\\label{answern.n}\n%\\end{equation}\n%\\textbf{Answer [not] verified}\n\n\n\n\n\n", "meta": {"hexsha": "0f291aea74b9347989937d7bedcbc8d65485274b", "size": 11301, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter6.tex", "max_stars_repo_name": "stefk/Rozanov_ptcc_solutions", "max_stars_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter6.tex", "max_issues_repo_name": "stefk/Rozanov_ptcc_solutions", "max_issues_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter6.tex", "max_forks_repo_name": "stefk/Rozanov_ptcc_solutions", "max_forks_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.661849711, "max_line_length": 358, "alphanum_fraction": 0.6404742943, "num_tokens": 4557, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190938, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7390217623953538}}
{"text": "\\section{Bonus lecture: Primitive Roots}\r\nWe work in the multiplicative group $\\mathbb Z_p^\\times$ or $\\mathbb Z_p^\\star$ consisting of $(\\mathbb Z_p\\setminus\\{0\\},\\times,1)$.\r\n\\begin{definition}\r\n    The order of $x\\in\\mathbb Z_p^\\star$ is the least $n\\in\\mathbb N$ with $x^n\\equiv 1\\pmod{p}$.\r\n\\end{definition}\r\nIt is trivial that an order indeed exists by F$\\ell$T.\r\n\\begin{example}\r\n    The order of $2$ in $\\mathbb Z_7^\\star$ is $3$, and the order of $3$ there is $6$.\r\n\\end{example}\r\n\\begin{definition}\r\n    A $x\\in \\mathbb Z_p^\\star$ is said to be a primitive root, or generator, if $x$ has order $p-1$.\r\n\\end{definition}\r\nIndeed, if such an $x$ exists, then every element in $\\mathbb Z_p^\\star$ can be written in the form $x^n$ for some $n\\in\\mathbb N$.\r\n\\begin{theorem}\\label{primitive}\r\n    For any $p$, there exists a generator.\r\n\\end{theorem}\r\nThat is, $\\mathbb Z_p^\\star\\cong C_{p-1}$.\r\n\\begin{proposition}\r\n    If $x$ has order $n$, then if $x^d\\equiv 1\\pmod{p}$, then $n|d$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial by minimality of order.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Let $x$ have order $a$ and $y$ have order $b$ where $a,b$ are coprime, then $xy$ has order $ab$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Obviously $(xy)^{ab}\\equiv 1\\pmod{p}$.\r\n    Conversely, if $(xy)^d\\equiv 1\\pmod{p}$, then $x^dy^d\\equiv 1\\pmod{p}$, so $x^{bd}\\equiv 1\\pmod{p}$ hence $a|bd$, but $a,b$ are coprime, so $a|d$.\r\n    Similarly $b|d$, thus $ab|d$ since again $a,b$ are coprime.\r\n\\end{proof}\r\nAlso the condition of $a,b$ being coprime is necessary.\r\nIndeed, by the same idea, we obtain\r\n\\begin{proposition}\r\n    Let $x$ have order $a$ and $y$ have order $b$, then there is some element have order $l$, the LCM of $a,b$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Let\r\n    $$a=p_1^{a_1}\\cdots p_k^{a_k}q_1^{c_1}\\cdots q_j^{c_j},b=p_1^{b_1}\\cdots p_k^{b_k}q_1^{d_1}\\cdots q_j^{d_j}$$\r\n    where $p_i,q_i$ are distinct primes where $a_i\\ge b_i,c_i\\le d_i$.\r\n    Then $x^{q_1^{c_1}\\cdots q_j^{c_j}}$ has order $p_1^{a_1}\\cdots p_k^{a_k}$, and $y^{p_1^{b_1}\\cdots p_k^{b_k}}$ has order $q_1^{d_1}\\cdots q_j^{d_j}$.\r\n    So $x^{q_1^{c_1}\\cdots q_j^{c_j}}y^{p_1^{b_1}\\cdots p_k^{b_k}}$ has order $p_1^{a_1}\\cdots p_k^{a_k}q_1^{d_1}\\cdots q_j^{d_j}=l$ by above.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $d$ is the biggest order in $\\mathbb Z_p^\\star$, then any order divides $d$.\r\n\\end{corollary}\r\nNote that all the above works in any finite abelian group.\r\nWe now bring in number theory.\r\n\\begin{proposition}\r\n    Let $f$ be a polynomial in $\\mathbb Z_p$ or degree $k>0$, the $f$ has at most $k$ roots in $\\mathbb Z_p$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Division and induction.\r\n\\end{proof}\r\n\\begin{remark}\r\n    This is NOT true in $\\mathbb Z_n$ in general since we used division (which requires it to be a field).\r\n    For example, $x^2\\equiv 1$ has $4$ roots modulo $8$.\r\n\\end{remark}\r\n\\begin{proof}[Proof of Theorem \\ref{primitive}]\r\n    Take $d$ to be the biggest order in $\\mathbb Z_p^\\star$.\r\n    We want $d=p-1$.\r\n    Note that for any $x\\in\\mathbb Z_p^\\star$, $x^d\\equiv 1\\pmod{p}$ by the preceding corollary.\r\n    But the polynomial $x^d-1$ can have at most $d$ roots.\r\n    Then we must have $d\\ge p-1$, but $d|p-1\\implies d\\le p-1$, hence $d=p-1$.\r\n\\end{proof}\r\nThere are some consequences by this theorem.\r\nWe let $g$ be the generator hereafter.\r\nFor example, we can prove Fermat by takeing $x\\equiv g^a\\pmod{p}$, then $x^{p-1}\\equiv g^{a(p-1)}\\equiv 1\\pmod{p}$.\\\\\r\nFrom now on we set $p$ odd.\r\nSo we have $\\mathbb Z_p^\\star$ contains exactly $(p-1)/2$ roots by again looking at the exponent.\r\nAlso, a non-square times a non-square gives a square.\r\nNow we look at $-1$.\r\nThen we must have $g^{(p-1)/2}\\equiv -1\\pmod{p}$, so $-1$ is a square if and only if $(p-1)/2$ is even, which happens if and only if $p\\equiv 1\\pmod{4}$.\\\\\r\nFor Wilson's Theorem, we can simply write $(p-1)!\\equiv g^{1+2+3+\\cdots +(p-1)}\\equiv g^{p(p-1)/2}\\equiv (-1)^p\\equiv -1\\pmod{p}$.\\\\\r\nFor $p=3k+1$, the cubes are exactly $g^3,g^6,\\ldots,g^{3k}$, so there are exactly $k=(p-1)/3$ cubes.\r\nOtherwise, everything is a cube (as shown in example sheets).\r\n\\begin{remark}\r\n    The proof does not tell us how we can find the generator as it only shows existence.\r\n    Even today, it is not well-understood which element would be a generator.\r\n    For example, when is $2$ a generator?\r\n    It is true for $\\mathbb Z_5$ but not $\\mathbb Z_7$.\r\n    Nobody knows for which primes $2$ is a primitive roots, it is not even known if $2$ is a primitive root modulo infinitely many primes $p$ (Artin's Conjecture).\r\n\\end{remark}", "meta": {"hexsha": "8e5a9dbe34deaf51d64dbc48c5a56d16056d2c83", "size": 4606, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8/prim.tex", "max_stars_repo_name": "david-bai-notes/Numbers-and-Sets", "max_stars_repo_head_hexsha": "2c8ca0c4983c1d575b5f55f2a91d34d6ef534845", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-15T21:17:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-15T21:17:29.000Z", "max_issues_repo_path": "8/prim.tex", "max_issues_repo_name": "david-bai-notes/Numbers-and-Sets", "max_issues_repo_head_hexsha": "2c8ca0c4983c1d575b5f55f2a91d34d6ef534845", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "8/prim.tex", "max_forks_repo_name": "david-bai-notes/Numbers-and-Sets", "max_forks_repo_head_hexsha": "2c8ca0c4983c1d575b5f55f2a91d34d6ef534845", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.4939759036, "max_line_length": 164, "alphanum_fraction": 0.6578376031, "num_tokens": 1668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236823, "lm_q2_score": 0.8596637505099167, "lm_q1q2_score": 0.7390217546682416}}
{"text": "%!TEX root = ../thesis.tex\n\\chapter{Supplementary Material}\n\\section{Matrix definitions}\\label{app:GellMann}\nThe standard form of the $2\\times 2$ Pauli matrices is\n%\n\\begin{equation}\n\\sigma_1 = \\begin{pmatrix}\n0 & 1\\\\\n1 & 0\n\\end{pmatrix},\n\\hspace{0.5cm}\n\\sigma_2 = \\begin{pmatrix}\n0 & -i\\\\\ni & 0\n\\end{pmatrix},\n\\hspace{0.5cm}\n\\sigma_3 = \\begin{pmatrix}\n1 & 0\\\\\n0 & -1\n\\end{pmatrix}\\\\, .\n\\end{equation}\n%\nThe $4\\times 4$ gamma matrices in the Dirac representation in Euclidean space are therefore given by\n%\n\\begin{equation}\n\\gamma_i = \\begin{pmatrix}\n0 & \\sigma_i\\\\\n-\\sigma_i & 0\n\\end{pmatrix},\n\\hspace{0.5cm}\n\\gamma_4 = \\begin{pmatrix}\nI & 0\\\\\n0 & -I\n\\end{pmatrix}\\, .\n\\end{equation} \n%\nThe gamma matrices in this representation are evidently Hermitian, and satisfy the anti-commutation relationship,\n%\n\\begin{equation}\n\\lbrace \\gamma_\\mu\\, ,\\, \\gamma_\\mu \\rbrace = 2\\,\\delta_{\\mu\\nu}\\, .\n\\end{equation}\n%\nThe Gell-Mann matrices $\\lambda_a$ are related to the generators of $SU(3)$, $t_a$, by~\\cite{peskin2018introduction}\n%\n\\begin{equation}\nt_a = \\frac{\\lambda_a}{2}\\, .\n\\end{equation}\n%\nThe matrices are given by\n%\n\\begin{align}\n\\lambda _ { 1 } &= \\left( \\begin{array} { c c c } { 0 } & { 1 } & { 0 } \\\\ { 1 } & { 0 } & { 0 } \\\\ { 0 } & { 0 } & { 0 } \\end{array} \\right) \\quad \\lambda _ { 2 } = \\left( \\begin{array} { c c c } { 0 } & { - i } & { 0 } \\\\ { i } & { 0 } & { 0 } \\\\ { 0 } & { 0 } & { 0 } \\end{array} \\right) \\quad \\lambda _ { 3 } = \\left( \\begin{array} { c c c } { 1 } & { 0 } & { 0 } \\\\ { 0 } & { - 1 } & { 0 } \\\\ { 0 } & { 0 } & { 0 } \\end{array} \\right)\\nonumber\\\\\n\\lambda _ { 4 } &= \\left( \\begin{array} { c c c } { 0 } & { 0 } & { 1 } \\\\ { 0 } & { 0 } & { 0 } \\\\ { 1 } & { 0 } & { 0 } \\end{array} \\right) \\quad \\lambda _ { 5 } = \\left( \\begin{array} { c c c } { 0 } & { 0 } & { - i } \\\\ { 0 } & { 0 } & { 0 } \\\\ { i } & { 0 } & { 0 } \\end{array} \\right)\\nonumber\\\\\n\\lambda _ { 6 } &= \\left( \\begin{array} { c c c } { 0 } & { 0 } & { 0 } \\\\ { 0 } & { 0 } & { 1 } \\\\ { 0 } & { 1 } & { 0 } \\end{array} \\right) \\quad \\lambda _ { 7 } = \\left( \\begin{array} { c c c } { 0 } & { 0 } & { 0 } \\\\ { 0 } & { 0 } & { - i } \\\\ { 0 } & { i } & { 0 } \\end{array} \\right) \\quad \\lambda _ { 8 } = \\frac { 1 } { \\sqrt { 3 } } \\left( \\begin{array} { c c c } { 1 } & { 0 } & { 0 } \\\\ { 0 } & { 1 } & { 0 } \\\\ { 0 } & { 0 } & { - 2 } \\end{array} \\right)\\, .\n\\end{align}\n\n\\section{Gauge transformation of $F_{\\mu\\nu}$}\\label{app:GTF}\nRecall from Eq.~\\eqref{eq:FieldStrengthTensor} that the field strength tensor is defined to be\n%\n\\begin{equation}\nF_{\\mu\\nu}=\\partial_\\mu A_\\nu - \\partial_\\nu A_\\mu + ig[A_\\mu,\\,A_\\nu]\\, .\n\\label{eq:FieldStrength(app)}\n\\end{equation}\n%\nTo calculate how $F_{\\mu\\nu}$ transforms under a gauge transformation, we will also make use of the gauge transformation property for $A_\\mu$,\n%\n\\begin{equation}\nA_\\mu \\rightarrow \\Omega\\,A_\\mu\\,\\Omega^\\dag + \\frac{i}{g}\\,(\\partial_\\mu\\,\\Omega)\\,\\Omega^\\dag\\, . \n\\label{eq:PotentialGT(app)}\n\\end{equation}\n%\nWe will also make repeated use of the unitarity of $\\Omega$, specifically the fact that\n%\n\\begin{align}\n\\partial_\\mu \\left(\\Omega\\, \\Omega^\\dagger\\right) &= \\left(\\partial_\\mu\\,\\Omega\\right)\\Omega^\\dagger + \\Omega\\left(\\partial_\\mu\\, \\Omega^\\dagger\\right)\\nonumber\\\\\n&=\\partial_\\mu \\, I\\nonumber\\\\\n&= 0\\nonumber\\\\\n\\implies & \\left(\\partial_\\mu\\,\\Omega\\right)\\Omega^\\dagger = -\\Omega\\left(\\partial_\\mu\\, \\Omega^\\dagger\\right)\\, .\n\\end{align}\n%\nSubstituting Eq.~\\eqref{eq:PotentialGT(app)} into Eq.~\\eqref{eq:FieldStrength(app)} we obtain\n%\n\\begin{align}\nF_{\\mu\\nu} \\rightarrow &\\left(\\partial_\\mu \\, \\Omega\\right)A_\\nu \\, \\Omega^\\dagger + \\Omega\\left(\\partial_\\mu\\,A_\\nu\\right)\\Omega^\\dagger + \\Omega \\, A_\\nu\\left(\\partial_\\mu \\, \\Omega^\\dagger\\right)\\nonumber\\\\\n& + \\frac{i}{g}\\left(\\partial_\\nu\\,\\partial_\\mu\\, \\Omega\\right)\\Omega^\\dagger + \\frac{i}{g}\\left(\\partial_\\nu\\,\\Omega\\right)\\left(\\partial_\\mu\\,\\Omega^\\dagger\\right)\\nonumber\\\\\n& - \\left(\\partial_\\nu \\, \\Omega\\right)A_\\mu \\, \\Omega^\\dagger - \\Omega\\left(\\partial_\\nu\\,A_\\mu\\right)\\Omega^\\dagger - \\Omega \\, A_\\mu\\left(\\partial_\\nu \\, \\Omega^\\dagger\\right)\\nonumber\\\\\n& - \\frac{i}{g}\\left(\\partial_\\nu\\,\\partial_\\mu\\, \\Omega\\right)\\Omega^\\dagger - \\frac{i}{g}\\left(\\partial_\\mu\\,\\Omega\\right)\\left(\\partial_\\nu\\,\\Omega^\\dagger\\right)\\nonumber\\\\\n& +ig \\, \\Omega \\, A_\\mu \\, A_\\nu \\, \\Omega^\\dagger - \\left(\\partial_\\mu \\, \\Omega\\right)A_\\nu \\, \\Omega^\\dagger + \\Omega\\,A_\\mu\\left(\\partial_\\nu \\, \\Omega^\\dagger\\right) + \\frac{i}{g}\\left(\\partial_\\mu\\,\\Omega\\right)\\left(\\partial_\\nu\\,\\Omega^\\dagger\\right)\\nonumber\\\\\n& -ig \\, \\Omega \\, A_\\nu \\, A_\\mu \\, \\Omega^\\dagger + \\left(\\partial_\\nu \\, \\Omega\\right)A_\\mu \\, \\Omega^\\dagger - \\Omega\\,A_\\nu\\left(\\partial_\\mu \\, \\Omega^\\dagger\\right) - \\frac{i}{g}\\left(\\partial_\\nu\\,\\Omega\\right)\\left(\\partial_\\mu\\,\\Omega^\\dagger\\right)\\, . \n\\end{align}\nCancelling off terms reduces the above expression to the desired result,\n%\n\\begin{align}\nF_{\\mu\\nu} \\rightarrow &\\, \\Omega\\left(\\partial_\\mu\\,A_\\nu\\right)\\Omega^\\dagger - \\Omega\\left(\\partial_\\nu\\,A_\\mu\\right)\\Omega^\\dagger +ig\\,\\Omega\\left[A_\\mu,\\,A_\\nu\\right]\\Omega^\\dagger\\nonumber\\\\\n&= \\Omega\\,F_{\\mu\\nu}\\,\\Omega^\\dagger\\, .\n\\end{align}\n\n\\section{Wilson line gauge transformation}\\label{app:WilsonLineGT}\n\nWe wish to show that the Wilson line obeys the gauge transformation property\n%\n\\begin{equation}\nU_\\mu(x) \\rightarrow \\Omega(x)\\,U_\\mu(x)\\,\\Omega^\\dagger(x)\n\\end{equation}\n%\nWe can apply a gauge transformation to $A_\\mu$ to obtain\n%\n\\begin{equation}\nU_\\mu(x)\\rightarrow\\mathcal{P}\\exp\\left(-iag\\int_0^1\\,dt\\, \\Omega(x(t))\\,A_\\mu(x(t))\\,\\Omega^\\dagger(x(t)) + \\frac{i}{g}\\,(\\partial_\\mu\\,\\Omega(x(t)))\\,\\Omega^\\dagger(x(t))\\right)\\, ,\n\\label{eq:WilsonLineGT(app)}\n\\end{equation}\n%\nwhere $x(t)=x+at\\hat{\\mu}$. To simplify this expression, we need to make use of an equivalent expression for the path-ordered exponential. For a generic path-ordered exponential of a function $a(t)$ we can write\n%\n\\begin{align}\n&\\mathcal{P}\\left(\\int_0^t dt^\\prime\\, a(t^\\prime)\\right) = \\lim_{N\\rightarrow\\infty} \\left( e^{a(t_N)\\Delta t}\\,e^{a(t_{N-1})\\Delta t}\\,\\cdots\\,e^{a(t_0)\\Delta t}\\right)\\nonumber\\\\\n\\implies &\\mathcal{P}\\left(-\\int_0^t dt^\\prime\\, a(t^\\prime)\\right) = \\lim_{N\\rightarrow\\infty} \\left( e^{a(t_0)\\Delta t}\\,e^{a(t_{1})\\Delta t}\\,\\cdots\\,e^{a(t_N)\\Delta t}\\right)\\, , \\label{eq:OrderedExponentialLimit}\n\\end{align}\n%\nwhere $\\lbrace t_0 = 0, \\, \\cdots\\, , \\, t_N = t\\rbrace$ is a partition of the integration range into equal slices of length $\\Delta t = \\frac{t}{N}$. We also wish to utilise the fact that\n%\n\\begin{equation}\ne^{ig\\,\\Omega(x)\\,A_\\mu(x)\\,\\Omega^\\dagger(x)} = \\Omega(x)\\,e^{ig\\,A_\\mu(x)}\\,\\Omega^\\dagger(x)\\, ,\n\\end{equation}\nas can be easily derived from writing the exponential as an infinite sum.\\\\\n\nWriting Eq.~\\eqref{eq:WilsonLineGT(app)} in the form of Eq.~\\eqref{eq:OrderedExponentialLimit} and employing the fact that path-ordering permits us to only retain the first order terms in the Baker-Campbell-Hausdorff identity (see Eq.~\\eqref{eq:BCH}), we find that\n%\n\\begin{align}\nU_\\mu(x)\\rightarrow \\lim_{N\\rightarrow\\infty} &\\left( \\Omega(x_0)\\,e^{ig\\,A_\\mu(x_0)\\,\\Delta x}\\,\\Omega^\\dagger(x_0) \\exp\\left((\\partial_\\mu\\,\\Omega(x_0))\\,\\Omega^\\dagger(x_0)\\right)\\right.\\nonumber\\\\\n&\\times \\Omega(x_1)\\,e^{ig\\,A_\\mu(x_1)\\,\\Delta x}\\,\\Omega^\\dagger(x_1) \\exp\\left((\\partial_\\mu\\,\\Omega(x_1))\\,\\Omega^\\dagger(x_1)\\Delta x\\right) \\times \\, \\cdots \\nonumber\\\\\n&\\left. \\times \\, \\Omega(x_{N-1})\\,e^{ig\\,A_\\mu(x_{N-1})\\,\\Delta x}\\,\\Omega^\\dagger(x_{N-1}) \\exp\\left((\\partial_\\mu\\,\\Omega(x_{N-1}))\\,\\Omega^\\dagger(x_{N-1})\\Delta x\\right) \\right)\\, , \\label{eq:WilsonLineExpansion(app)}\n\\end{align}\n%\nwhere $\\Delta x = \\frac{a}{N}$, $x_0=x$ and $x_N = x+a\\hat{\\mu}$. However, in the limit as $N\\rightarrow\\infty$, $\\exp\\left((\\partial_\\mu\\,\\Omega(x_i))\\,\\Omega^\\dagger(x_i)\\Delta x \\right)$ is precisely the parallel transport operator for $\\Omega$ over the distance $\\Delta x$, and hence satisfies \n%\n\\begin{equation}\n\\Omega^\\dagger(x_i)\\exp\\left((\\partial_\\mu\\,\\Omega(x_i))\\,\\Omega^\\dagger(x_i)\\Delta x \\right) = \\Omega^\\dagger(x_{i+1})\\, .\n\\label{eq:RotationTransport(app)}\n\\end{equation}\n%\nSubstituting Eq.~\\eqref{eq:RotationTransport(app)} into Eq.~\\eqref{eq:WilsonLineExpansion(app)} eliminates all the gauge transformation terms except for the first and last transformations. This then reduces to our desired result,\n%\n\\begin{equation}\nU_\\mu(x)\\rightarrow \\Omega(x)\\,U_\\mu(x)\\,\\Omega^\\dagger(x+a\\hat{\\mu})\\, .\n\\end{equation} \n\n\\section{Taylor expansion of $P_{\\mu\\nu}$}\\label{app:TEPlaquette}\nHere we sketch out how to construct the field strength tensor in terms of the plaquette. We will neglect a discussion of the $\\mathcal{O}(a^3)$ terms found in Eq.~\\eqref{eq:PlaquetteExponantial(app)} as a more careful treatment outside the scope of this work is required to show that these higher order terms do not render the expansion shown in Eq.~\\eqref{eq:PlaquetteExpansion} incorrect. However, this derivation highlights the key steps in arriving at the desired result. First, we recall the definitions of the gauge link in the continuum\n%\n\\begin{equation}\nU_\\mu(x) = \\mathcal{P}\\exp\\left(-iag\\int_0^1 \\,dt \\,A_\\mu(x + at\\hat{\\mu})\\right)  \\, ,\n\\label{eq:GaugeLink(app)}\n\\end{equation}\n%\nand the plaquette formed from the product of the gauge links around a $1\\times 1$ loop\n\\begin{equation}\nP_{\\mu\\nu} = U_\\mu(x)\\,U_\\nu(x+a\\hat{\\mu})\\,U^\\dagger_\\mu(x+a\\hat{\\nu})\\,U^\\dagger_\\nu(x)\\, .\n\\label{eq:Plaquette(app)}\n\\end{equation}\n%\nWe can approximate the integral in Eq.~\\eqref{eq:GaugeLink(app)} by Taylor expanding $A_\\mu$ around $a=0$ and explicitly evaluating the integral. Note that once we have Taylor expanded $A_\\mu$, the term within the integral commutes with itself for all values of $t$, allowing us to omit the path ordering from Eq.~\\eqref{eq:GaugeLink(app)}. Performing the expansion, we find that\n%\n\\begin{align}\nU_\\mu(x)&=\\exp\\left(-iag\\int_0^1 dt \\left(A_\\mu\\left(x\\right) + at\\partial_\\mu A_\\mu(x) + \\mathcal{O}(a^3)\\right)\\right)\\nonumber\\\\\n&=\\exp\\left(-iag A_\\mu\\left(x\\right) - \\frac{1}{2}ia^2 g\\, \\partial_\\mu A_\\mu\\left(x\\right)+ \\mathcal{O}(a^3)\\right)\\, . \\label{eq:UTaylor}\n\\end{align}\n%\nSimilarly, we evaluate\n%\n\\begin{align}\nU_\\nu(x+a\\hat{\\mu}) &= \\exp\\left(-iag\\int_0^1 dt \\left(A_\\nu(x) + a\\partial_\\mu A_\\nu + at\\partial_\\nu A_\\nu + \\mathcal{O}(a^3)\\right)\\right)\\nonumber\\\\\n&= \\exp\\left(-iag A_\\nu(x) - ia^2g\\,\\partial_\\mu A_\\nu(x) - \\frac{1}{2}ia^2 g\\,\\partial_\\nu A_\\nu(x)+ \\mathcal{O}(a^3)\\right)\\, . \\label{eq:UTaylor2}\n\\end{align}\n%\nWe will also require the Baker-Campbell-Hausdorff identity for non-Abelian matrix exponentials\n%\n\\begin{equation}\n\\exp(A)\\,\\exp(B) = \\exp\\left(A + B +\\frac{1}{2}[A,\\,B]\\right)\\, .\n\\label{eq:BCH}\n\\end{equation}\n%\nSubstituting Eq.~\\eqref{eq:UTaylor} and Eq.~\\eqref{eq:UTaylor2} into Eq.~\\eqref{eq:Plaquette(app)} and retaining only terms up to $\\mathcal{O}(a^2)$ we find that\n%\n\\begin{alignat}{2}\nP_{\\mu\\nu} &\\simeq &&\\exp\\left(-ig\\left(a\\,A_\\mu(x)+\\frac{1}{2}a^2\\,\\partial_\\mu A_\\mu(x) \\right)\\right)\\nonumber\\\\\n& &&\\times\\exp\\left(-ig\\left(aA_\\nu(x) + \\frac{1}{2}a^2\\,\\partial_\\nu A_\\nu(x) + a^2\\,\\partial_\\mu A_\\nu(x)\\right)\\right)\\nonumber\\\\\n& &&\\times\\exp\\left(ig\\left(aA_\\mu(x) + \\frac{1}{2}a^2\\,\\partial_\\mu A_\\mu(x) + a^2\\,\\partial_\\nu A_\\mu(x)\\right)\\right)\\nonumber\\\\\n& &&\\times\\exp\\left(ig\\left(a\\,A_\\nu(x)+\\frac{1}{2}a^2\\,\\partial_\\nu A_\\nu(x)\\right)\\right)\\nonumber\\\\\n&\\simeq &&\\exp\\left(-ia^2g\\,\\partial_\\mu A_\\nu(x) + ia^2g\\,\\partial_\\nu A_\\mu(x) +\\frac{a^2g^2}{2}[A_\\mu(x),\\,A_\\nu(x)] - \\frac{a^2g^2}{2}[A_\\nu(x),\\,A_\\mu(x)]\\right)\\nonumber\\\\\n&= &&\\exp\\left(-ia^2g F_{\\mu\\nu}(x) + \\mathcal{O}(a^3)\\right)\\, .\n\\label{eq:PlaquetteExponantial(app)}\n\\end{alignat}\n\\section{Properties of the adjoint representation}\n\\label{app:RepMapProof}\nConsider the mapping $H:SU(3)^\\text{fundamental}\\rightarrow SU(3)^\\text{adjoint}$ defined by\n%\n\\begin{equation}\n\\left[H(U)\\right]_{ij} = \\frac{1}{2}\\Tr\\left(\\lambda_i \\, U \\, \\lambda_j\\, U^\\dagger\\right)\\, .\n\\label{eq:FundMap(app)}\n\\end{equation}\n%\nWe want to show that for $U,V\\in SU(3)^F$\n%\n\\begin{equation}\n\\left[H(U)\\right]_{ij}\\left[H(V)\\right]^{jk} = \\left[H(U V)\\right]_i^{~k}\\, .\n\\label{eq:MapPreserve(app)}\n\\end{equation}\n%\nTo do this, we will need to make use of the following Fierz completeness relations for the $SU(3)$  generators\n%\n\\begin{equation}\n\\lambda _ { b } ^ { a } \\lambda _ { c } ^ { d } = 2\\, \\delta _ { c } ^ { a } \\delta _ { b } ^ { d } - \\frac { 2 } { 3 } \\delta _ { b } ^ { a } \\delta _ { c } ^ { d }\\, .\n\\end{equation}\n%\nSubstituting Eq.~\\eqref{eq:FundMap(app)} into Eq.~\\eqref{eq:MapPreserve(app)} and noting that repeated indicies are summed over, we have\n\\begin{align}\n\\left[H(U)\\right]_{\\alpha\\beta}\\left[H(V)\\right]^{\\beta\\gamma} &= \\frac{1}{2} \\lambda^\\alpha_{ab}\\, U_{bc}\\,\\lambda^\\beta_{cd}\\, U^\\dagger_{da} \\times \\frac{1}{2} \\lambda^\\beta_{ef}\\, V_{fg}\\,\\lambda^\\gamma_{gh}\\, V^\\dagger_{he}\\nonumber\\\\\n&=\\frac{1}{2} U_{bc}\\,U^\\dagger_{da}\\,V_{fg}\\,V^\\dagger_{he}\\,\\lambda^\\alpha_{ab}\\, \\lambda^\\gamma_{gh} \\left(\\delta_{cf}\\,\\delta_{de} - \\frac{1}{3}\\delta_{cd}\\delta_{ef}\\right)\\nonumber\\\\\n&=\\frac{1}{2}U_{bc} \\, V_{cg} \\, \\lambda^\\gamma_{gh} \\, V^\\dagger_{hd} \\, U^\\dagger_{da} \\, \\lambda^\\alpha_{ab} - \\frac{1}{6} U_{bc} \\, U^\\dagger_{ca} \\, V^\\dagger_{he} \\, V_{eg} \\lambda^\\alpha_{ab}\\, \\lambda^\\gamma_{gh}\\nonumber\\\\\n&= \\frac{1}{2}U_{bc} \\, V_{cg} \\, \\lambda^\\gamma_{gh} \\, V^\\dagger_{hd} \\, U^\\dagger_{da} \\, \\lambda^\\alpha_{ab} - \\frac{1}{6}\\delta_{ba}\\delta_{hg} \\lambda^\\alpha_{ab}\\, \\lambda^\\gamma_{gh}\\nonumber\\\\\n&=\\frac{1}{2}\\Tr\\left(U \\, V \\, \\lambda^\\gamma \\, (U \\, V)^\\dagger \\lambda^\\alpha\\right) - \\frac{1}{6}\\Tr\\left(\\lambda^\\alpha\\right) \\, \\Tr\\left(\\lambda^\\gamma\\right)\\, .\n\\end{align}\nMaking use of the cyclic property of the trace and the fact that the Gell-Mann matrices are traceless, we find the desired result,\n%\n\\begin{align}\n\\left[H(U)\\right]_{\\alpha\\beta}\\left[H(V)\\right]^{\\beta\\gamma} &= \\frac{1}{2}\\Tr\\left(\\lambda^\\alpha U \\, V \\, \\lambda^\\gamma \\, (U \\, V)^\\dagger \\right)\\nonumber\\\\\n&= \\left[H(UV)\\right]_{\\alpha\\gamma} \\, .\n\\end{align}\\\\\n\nWe also wish to show that for $U^A\\in SU(3)^A$ and $U\\in SU(3)^F$ that\n%\n\\begin{equation}\n\\Tr\\left(U^A\\right) = \\left|\\Tr(U)\\right|^2 -1\\, .\n\\end{equation}\n%\nMaking use of Eq.~\\eqref{eq:FundMap(app)}, we have\n\\begin{align}\n\\Tr\\left(U^A\\right) &= \\sum_{\\alpha=1}^8 \\frac{1}{2}\\Tr\\left(\\lambda^\\alpha \\, U_\\mu(x) \\, \\lambda^\\alpha \\, U_\\mu^\\dagger(x)\\right)\\nonumber\\\\\n&= \\frac{1}{2}U_{bc} \\, U^\\dagger_{da} \\, \\lambda_{ab}^\\alpha \\, \\lambda_{cd}^\\alpha\\nonumber\\\\\n&= U_{bc} \\, U^\\dagger_{da} \\left(\\delta_{ad}\\,\\delta_{bc} - \\frac{1}{3}\\delta_{ab}\\,\\delta_{cd}\\right)\\nonumber\\\\\n&= \\Tr\\left(U\\right) \\, \\Tr\\left( U^\\dagger \\right) - \\frac{1}{3}\\Tr\\left(U\\, U^\\dagger\\right)\\nonumber\\\\\n&= \\left|\\Tr(U)\\right|^2 -1\n\\end{align}\n\n\\section{Cooling algorithm derivation}\\label{app:Cooling}\nWe wish to find $a_i$ such that \n%\n\\begin{equation}\nU_\\mu^\\prime = a_3 \\, a_2 \\, a_1 \\, U_\\mu\\, ,\n\\label{eq:UPrime(app)}\n\\end{equation}\n%\nminimises the local Wilson action associated with the link $U_\\mu$. This minimisation is equivalent to maximising\n%\n\\begin{equation}\nR = \\operatorname{Re} \\Tr (U_\\mu^\\prime \\, \\bar{U})\\, .\n\\label{eq:CoolFunctional(app)}\n\\end{equation}\n%\nTo determine the optimal choice for the $a_i$, we define the following three functions, $F_i(V)$, such that $F_i : SU(3)\\rightarrow SU(2)$:\n%\n\\begin{align}\nF_1(V) &=\\frac{1}{k_1} \\begin{pmatrix}\n\\frac{1}{2}\\left(V_{11} + V_{22}^*\\right) & \\frac{1}{2}\\left(V_{12} - V_{21}^*\\right) & 0\\\\\n\\frac{1}{2}\\left(V_{21} - V_{12}^*\\right) & \\frac{1}{2}\\left(V_{11}^* + V_{22}\\right) & 0\\\\\n0 & 0 & k_1\n\\end{pmatrix}\\, ,\\\\\nF_2(V) &=\\frac{1}{k_2} \\begin{pmatrix}\n\\frac{1}{2}\\left(V_{11} + V_{33}^*\\right) & 0 &\\frac{1}{2}\\left(V_{13} - V_{31}^*\\right)\\\\\n0 & k_2 & 0\\\\\n\\frac{1}{2}\\left(V_{31} - V_{13}^*\\right) & 0 & \\frac{1}{2}\\left(V_{11}^* + V_{33}\\right)\n\\end{pmatrix}\\, ,\\\\\nF_3(V) &=\\frac{1}{k_3} \\begin{pmatrix}\nk_3 & 0 & 0\\\\\n0 & \\frac{1}{2}\\left(V_{22} + V_{33}^*\\right) & \\frac{1}{2}\\left(V_{23} - V_{32}^*\\right)\\\\\n0 & \\frac{1}{2}\\left(V_{32} - V_{23}^*\\right) & \\frac{1}{2}\\left(V_{22}^* + V_{33}\\right)\n\\end{pmatrix}\\, ,\n\\end{align}\n%\nwhere $k_i^2$ is the determinant of the $2\\times 2$ $SU(2)$ sub-block. The $\\frac{1}{k_i}$ factor therefore fixes the determinant such that $\\det(F_i(V))=1$. We now wish to find a suitable $V$ to define our $a_i$'s. Consider the first case, $U^{(1)}_\\mu = a_1\\,U_\\mu$, and let $a_1 = F_1(U_\\mu\\,\\bar{U})^\\dagger$. It is worth stating explicitly that it is this step where the fact that a sum of $SU(2)$ matrices is proportional to an $SU(2)$ matrix is utilised. Despite the fact that $U_\\mu\\,\\bar{U} \\notin SU(3)$, $U_\\mu \\, \\tilde{U}_\\alpha\\in SU(3)~\\forall\\, \\alpha$, which implies that $F_i(U_\\mu\\, \\tilde{U}_\\alpha)\\in SU(2)$. Then we have, for example,\n%\n\\begin{align}\nF_1(U_\\mu \\, \\bar{U}) &= \\frac{1}{k_1}\\sum_\\alpha\n\\begin{pmatrix}\n\\frac{1}{2}\\left((U_\\mu \\, \\tilde{U}_\\alpha)_{11} + (U_\\mu \\, \\tilde{U}_\\alpha)^*_{22}\\right) & \\frac{1}{2}\\left((U_\\mu \\, \\tilde{U}_\\alpha)_{12} - (U_\\mu \\, \\tilde{U}_\\alpha)^*_{21}\\right) & 0\\\\\n\\frac{1}{2}\\left((U_\\mu \\, \\tilde{U}_\\alpha)_{21} - (U_\\mu \\, \\tilde{U}_\\alpha)^*_{12}\\right) & \\frac{1}{2}\\left((U_\\mu \\, \\tilde{U}_\\alpha)^*_{11} + (U_\\mu \\, \\tilde{U}_\\alpha)_{22}\\right) & 0\\\\\n0 & 0 & k_1\n\\end{pmatrix}\\nonumber\\\\\n&=\\frac{1}{k_1}\\sum_\\alpha\n\\begin{pmatrix}\nk_{1,\\,\\alpha}\\,\\left(F_1(U_\\mu\\,\\tilde{U}_\\alpha)\\right)_{11} & k_{1,\\,\\alpha}\\,\\left(F_1(U_\\mu\\,\\tilde{U}_\\alpha)\\right)_{12} & 0\\\\\nk_{1,\\,\\alpha}\\,\\left(F_1(U_\\mu\\,\\tilde{U}_\\alpha)\\right)_{21} & k_{1,\\,\\alpha}\\,\\left(F_1(U_\\mu\\,\\tilde{U}_\\alpha)\\right)_{22} & 0\\\\\n0 & 0 & k_1\n\\end{pmatrix}\\nonumber\\\\\n&=\\frac{1}{k_1}\\sum_\\alpha\n\\left(\\begin{array}{@{}c|c@{}}\nk_{1,\\,\\alpha} \\,F_1(U_\\mu\\,\\tilde{U}_\\alpha)_{2\\times 2} & 0\\\\\n  \\hline \n0 & k_1\n\\end{array}\\right)\n\\label{eq:FExpansion}\n\\end{align}\n%\nThe $2\\times 2$ block in Eq.~\\eqref{eq:FExpansion} is a sum over terms proportional to $SU(2)$ matrices, and hence the result is proportional to an $SU(2)$ matrix. Thus with the appropriate normalisation from the $k_1$ factor, we see that $F_1(U_\\mu \\, \\bar{U})\\in SU(2)$. The same result holds true for $F_2$ and $F_3$.\\\\\n\nWith the definition $a_1 = F_1(U_\\mu\\,\\bar{U})^\\dagger$, the functional in Eq.~\\eqref{eq:CoolFunctional(app)} we are seeking to maximise can now be directly evaluated. Setting $U = U_\\mu\\,\\bar{U}$, we can write Eq.~\\eqref{eq:CoolFunctional(app)} as \n%\n\\begin{align}\n\\Re\\Tr(F_1(U)^\\dagger\\, U) &=\\Re \\left(\\frac{1}{k_1}\\left[ \\frac{1}{2}\\,U_{11} \\left(U_{22} + U_{11}^*\\right) - \\frac{1}{2}\\,U_{21} \\left(U_{12} - U_{21}^*\\right)\\right.\\right.\\nonumber\\\\\n&~~~~+ \\left. \\left.\\frac{1}{2}\\,U_{22} \\left(U_{11} + U_{22}^*\\right)\n- \\frac{1}{2}\\,U_{12} \\left(U_{21} - U_{12}^*\\right) +k_1\\,U_{33}\\right]\\right)\\nonumber\\\\\n&= \\frac{1}{k_1}\\Re\\left(\\frac{|U_{11}|^2}{2} + \\frac{|U_{22}|^2}{2} + \\frac{|U_{12}|^2}{2} + \\frac{|U_{21}|^2}{2} + U_{11}\\,U_{22} - U_{12}\\,U_{21} + k_1\\,U_{33}\\right)\\, .\\label{eq:FunctionalExpanded}\n\\end{align}\n%\nHere we have used the fact that by the construction of $F_1(U)$, $k_1$ is real and can therefore be brought to the front of Eq.~\\eqref{eq:FunctionalExpanded}. We now wish to make use of the known determinant of $F_1(U)$ to simplify this expression.\n%\n\\begin{align}\n\\det(F_1(U)) &= \\frac{1}{4\\,k_1^2} \\left(\\left(U_{11}+ U_{22}^*\\right)\\left(U_{11}^* + U_{22}\\right)-\\left(U_{12} - U_{21}^*\\right)\\left( U_{21} - U_{12}^*\\right)\\right)\\nonumber\\\\\n&=\\frac{1}{4\\,k_1^2}\\left( |U_{11}|^2 + |U_{22}|^2 + |U_{12}|^2 + |U_{21}|^2\\right.\\\\\n&~~~~+ U_{11}\\,U_{22} + U_{11}^*\\,U_{22}^* + U_{12}\\,U_{21} + U_{12}^*\\,U_{21}^*\\big)\\nonumber\\\\\n&= \\frac{1}{2\\,k_1^2}\\Re\\left(\\frac{|U_{11}|^2}{2} + \\frac{|U_{22}|^2}{2} + \\frac{|U_{12}|^2}{2} + \\frac{|U_{21}|^2}{2} + U_{11}\\,U_{22} - U_{12}\\,U_{21}\\right)\\nonumber\\\\\n&=1\\, .\n\\end{align}\n%\nSubstituting this determinant back into Eq.~\\eqref{eq:FunctionalExpanded}, we find that\n%\n\\begin{align}\n\\Re\\Tr(F_1(U)^\\dagger\\, U) &= \\Re\\left(\\frac{1}{k_1}(2k_1^2 + k_1\\,U_{33}))\\right)\\nonumber\\\\\n&=2\\,k_1 + \\Re\\left(U_{33}\\right)\\, .\n\\end{align}\n%\nFinally, substituting back $U = U_\\mu\\,\\bar{U}$ brings us to the desired result,\n%\n\\begin{equation}\n\\Re \\Tr (F_1(U_\\mu\\,\\bar{U})^\\dagger \\, U_\\mu \\, \\bar{U}) = 2k_1 + \\Re\\left( (U_\\mu\\, \\bar{U})_{33}\\right)\\, .\n\\label{eq:MaximisedCooling}\n\\end{equation}\n%\nBy the matrix structure of $F_1(V)$ it is apparent that $\\Re(U_\\mu\\, \\bar{U})_{33}$ is invariant under pre-multiplication by $a_1$, so it is clear that Eq.~\\eqref{eq:MaximisedCooling} represents the maximum attainable value for this form of $U^{(1)}_\\mu$. Similarly, we let $a_2=F_2(U_\\mu\\,\\bar{U})^\\dagger$ and $a_3=F_3(U_\\mu\\,\\bar{U})^\\dagger$ to obtain the final value of $U^\\prime_\\mu$ according to Eq.~\\eqref{eq:UPrime(app)}. This construction results in a choice of $U_\\mu^\\prime \\in SU(3)$ that minimises the local Wilson action.", "meta": {"hexsha": "95484304071e501288effead3a4d38cdf2d53517", "size": 20916, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendices/appendices.tex", "max_stars_repo_name": "jamesbiddle/Masters_Thesis", "max_stars_repo_head_hexsha": "275177c3167b490d678575f0078cc6c87614b7bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Appendices/appendices.tex", "max_issues_repo_name": "jamesbiddle/Masters_Thesis", "max_issues_repo_head_hexsha": "275177c3167b490d678575f0078cc6c87614b7bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Appendices/appendices.tex", "max_forks_repo_name": "jamesbiddle/Masters_Thesis", "max_forks_repo_head_hexsha": "275177c3167b490d678575f0078cc6c87614b7bb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.5176470588, "max_line_length": 657, "alphanum_fraction": 0.6362115127, "num_tokens": 8415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819238, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7390085426340637}}
{"text": "\\section{Modeling \\& Optimization}\r\nNow that we know some ways to find extreme values, we can apply them to answer optimization problems.\r\nThe general steps needed to solve an optimization problem are:\r\n\\begin{enumerate}\r\n\t\\item Write an equation that represents what you're trying to maximize/minimize. This is called your primary equation.\r\n\t\\item Use additional information to eliminate excess variables.\r\n\t\\item Find extreme values.\r\n\t\\item Select the extreme values that fit the problem's constraints. Make sure your answer is what the problem is asking for.\r\n\\end{enumerate}\r\n\r\n\\begin{example}\r\n\tA farmer has 1000 linear feet of fence and wants to create a rectangular pasture.\r\n\tThe pasture borders a river, which doesn't need a fence.\r\n\tWhat is the maximum area he can enclose?\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{enumerate}\r\n\t\t\\item Since the pasture is rectangular, we know the two lengths of fence perpendicular to the river will be the same length, which we'll call $x$.\r\n\t\t\tWe'll say the remaining side parallel to the river has length $y$.\r\n\t\t\tSo, the area enclosed is\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tA(x,y) = xy.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item There is no reason for the farmer not to use all 1000 linear feet of fence, so we'd expect the sum of the lengths of the 3 fenced sides to be equal to 1000 feet: $2x + y = 1000$, or $y = 1000 - 2x$.\r\n\t\t\tWe can then substitute back into our primary equation to get it in terms of just $x$.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tA(y) = x(1000-2x) = 1000x - 2x^2.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item We'll do a first derivative test to find extreme values.\r\n\t\t\\begin{align*}\r\n\t\t\tA^\\prime(y) &= 1000 - 4x \\\\\r\n\t\t\tA^\\prime(y) &= 0 \\text{ at } x = 250 \\\\\r\n\t\t\tA^\\prime(200) &= 200 > 0 \\\\\r\n\t\t\tA^\\prime(300) &= -200 < 0.\r\n\t\t\\end{align*}\r\n\t\t\\item So, $x=250 \\implies y = 500$ is a local maximum.\r\n\t\t\tThis corresponds to an area of $A = 250\\cdot 500 = 125000\\text{ft}^2$.\r\n\t\\end{enumerate}\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tWhat is the maximum area of a rectangle that has two vertices on the $x-axis$ and two vertices on the portion of the graph $y=8-x^2$ where $y > 0$?\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{enumerate}\r\n\t\t\\item We can define any such trapeziod (which include all such rectangles) by the $x$ values of the vertices on the $x$ axis.\r\n\t\t\tWe'll call these two values $x_1$ and $x_2$.\r\n\t\t\tWe'll say arbitrarily that $x_1 < x_2$.\r\n\t\t\tSo, the area enclosed is\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tA(x_1, x_2) = (x_2 - x_1)\\frac{f(x_1) + f(x_2)}{2}.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item However, the problem specifically restricts us to a rectangle, not a trapezoid.\r\n\t\t\tSo, the heights of each side must be equal.\r\n\t\t\t\\begin{align*}\r\n\t\t\t\tf(x_1) &= f(x_2) \\\\\r\n\t\t\t\t8 - x_1^2 &= 8 - x_2^2 \\\\\r\n\t\t\t\tx_1^2 &= x_2^2 \\\\\r\n\t\t\t\t\\pm x_1 &\\ \\pm x_2 \\\\\r\n\t\t\t\t-x_1 &= x_2 \\text{ because $x_1 \\neq x_2$}.\r\n\t\t\t\\end{align*}\r\n\t\t\tSubstituting back into our primary equation,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tA(x_2) = (x_2 - (-x_2))\\frac{f(x_2) + f(-x_2)}{2} = 2x_2f(x_2) = 16x_2 - 2x_2^3.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item We'll do a second derivative test for fin extreme values.\r\n\t\t\t\\begin{align*}\r\n\t\t\t\tA^\\prime(x_2) &= 16 - 6x_2^2 \\\\\r\n\t\t\t\tA^\\prime(x_2) &= 0 \\text{ at } x = \\pm\\frac{4}{\\sqrt{6}} \\\\\r\n\t\t\t\tA^{\\prime\\prime}(x_2) &= -12x_2 \\\\\r\n\t\t\t\tA^{\\prime\\prime}\\left(-\\frac{4}{\\sqrt{6}}\\right) &= 8\\sqrt{6} > 0 \\\\\r\n\t\t\t\tA^{\\prime\\prime}\\left(\\frac{4}{\\sqrt{6}}\\right) &= -8\\sqrt{6} < 0.\r\n\t\t\t\\end{align*}\r\n\t\t\\item So, $x_2 = 4/\\sqrt{6}$ is a local maximum, and $x_2 = -4/\\sqrt{6}$ is a local minimum.\r\n\t\t\tThe problem asks for a maximum, so we select $x_2 = 4/\\sqrt{6}$.\r\n\t\t\tThe problem asks for a maximum area, so\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tA_{max} = 16\\left(\\frac{4}{\\sqrt{6}}\\right) - 2\\left(\\frac{4}{\\sqrt{6}}\\right)^3 = \\frac{128}{3\\sqrt{6}} \\approx 17.419.\r\n\t\t\t\\end{equation*}\r\n\t\\end{enumerate}\r\n\\end{answer}", "meta": {"hexsha": "c8f00e3f20f816f4696955feed35a8246205a5ef", "size": 3804, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/applications_derivative/modeling_optimization.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/applications_derivative/modeling_optimization.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/applications_derivative/modeling_optimization.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.962962963, "max_line_length": 207, "alphanum_fraction": 0.6461619348, "num_tokens": 1336, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7389347072819613}}
{"text": "\\section{Exercises in Continuous Random Variables}\\label{S:xsContinuousRVs}\n\\begin{ExerciseList}\n\\Exercise\nConsider the probability density function\n$$f(x)\\;=\\;\\begin{cases} k &-4 \\leq x\\leq4\\\\0&\\textrm{otherwise}\\end{cases}\\,.$$\n\n\\be\n\\item Find  the value of $k$.\n\\item Find the distribution function, $F$.\n\\item   Graph $f$ and  $F$.\n\\ee\n\\Answer\n\\be\n\\item Since $f(x)$ is a (continuous) probability density function which integrates to one,\n$$\\int_{-4}^4kdx\\;=\\;1\\,.$$\nThat is, \n\\ba{k \\,x\\bigg]^4_{-4}&=\\;1\\\\[3pt]k(4-(-4))&=\\;1\\\\[3pt]8k&=\\;1\\\\[3pt]k&=\\;\\frac{1}{8}}\n\n\\item First note that if $x <  -4$, then  $$F(x)\\;=\\;\\int^x_{-\\infty}0\\,dv\\;=\\;0\\,.$$\nIf $-4 \\leq x \\leq 4$, then\n\\begin{align*}F(x)&=\\;\\int^{-4}_{-\\infty}0\\,dv\\;+\\;\\int^x_{-4} \\frac{1}{8}\\,dv\\\\[3pt]\n&=\\;0\\;+\\;\\left[ \\frac{1}{8}\\, v \\right]^x_{-4}\\\\[3pt]\n&=\\;  \\frac{1}{8} (x +4)\\end{align*}\nIf $x\\geq 4$, then\n\\begin{align*}F(x)&=\\int^{-4}_{-\\infty}0\\,dv\\;+\\;\\int^{4}_{-4}\n  \\frac{1}{8} \\,dv\\;+\\;\\int^x_{4} 0 \\,dv\\\\[3pt]\n&=0\\;+\\;\\left[\\frac{1}{8} v \\right]^4_{-4}\\;+\\;0\\\\[3pt]\n&=\\; 1\\end{align*}\nHence  $$F(x)\\;=\\;\\begin{cases}0&x <  -4\\\\ \\frac{1}{8} (x+4) &-4 \\leq\n  x\\leq 4\\\\1&x\\geq 4\\end{cases}$$\n\n\\item  The graphs of $f(x)$ and $F(x)$ for  random variable $X$ are as follows:\n%TODO\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/fandFforConstantDensity.png}}\n\n\\ee\n\n\\Exercise\nAssume that a new light bulb will burn out at time $t$ hours according to the probability density function given by \n$$\nf(t)\\;=\\;\n\\begin{cases}\n\\lambda e^{-\\lambda t} & \\text{ if } t >0 \\enspace,\\\\\n0 & \\text{ otherwise} \\enspace .\n\\end{cases}\n$$\nIn this context, $\\lambda$ is often called the failure rate of the bulb.\n\n\\be\n\\item[(a)]Assume that $\\lambda=0.01$, and find the probability that the\n  bulb will not burn out before $\\tau$ hours. This $\\tau$-specific probability is often\n  called the reliability of the bulb.\n\nHint: Use the distribution function for an $\\exponential(\\lambda)$ random variable (recall, $F(\\tau;\\lambda)=\\int_{-\\infty}^{\\tau} f(t) dt$)!\n\n\\item[(b)]For what  value of $\\tau$ is the reliability of the bulb exactly $\\frac{1}{2}$?\n\\ee\n\\Answer\n\\be\n\\item Since the distribution function is $F(t; \\lambda) \\,=\\,\n  1 - \\exp( - \\lambda t)$,\n \\[\\P(t>\\tau)\\;=\\;1-\\P(t<\\tau)\\;=\\; 1 - F(\\tau;\\lambda=0.01) \\;=\\;1-(1-e^{-0.01\\tau})\\;=\\;e^{-0.01\\tau}\\,.\\]\n\n\\item Set  \\[\\P(t>\\tau)\\;=\\;e^{-0.01\\tau}\\;=\\;\\frac{1}{2}\\]\nand solve for $\\tau$ to get  then $\\tau\\,=\\,-100\\times \\log(0.5)\\,=\\,69.3\\quad (\\text{3 sig. fig.})$\\,.\n\\ee\n\n\\Exercise \nLet the random variable $X$ be the time  after which certain ball bearings wear out, with density\n$$f(x)\\;=\\;\\begin{cases} ke^{-x}&0\\leq x\\leq 2\\\\0&\\textrm{otherwise}\\end{cases}\\enspace.$$\nNote: $X$ is measured in  years.\n\\be\n\\item Find $k$.\n\\item Find the probability that a bearing will last at least 1 year.\n\\ee\n\\Answer\n\\be\n\\item\n\n\\ba{\\int^2_0 k\\,e^{-x}\\,dx &=\\;1\\\\[3pt]\n\\left[ -k\\,e^{-x}\\right]^2_0&=\\;1\\\\[3pt]\nk\\,(-e^{-2}+1)&=\\;1\\\\[3pt]\nk&=\\;\\frac{1}{1-e^{-2}} \\quad (\\approx 1.1565)\n}\n\n\\item\n\\ba{\\P(X\\geq1)&=1\\,-\\,\\P(X<1)\\\\[3pt]\n&=\\;1\\;-\\;\\int^1_0 k e^{-x}\\,dx\\\\[3pt]\n&=\\;1\\;+\\;k\\left(e^{-x}\\right]^1_0\\\\[3pt]\n&=\\;1\\;+\\;\\frac{e^{-1}-1}{1-e^{-2}}\\\\[3pt]\n&\\approx\\;0.2689}\n\n\\ee\n\n\n\\end{ExerciseList}\n\n", "meta": {"hexsha": "d8a92122c7c16acc27cd0205f73fb842507801b2", "size": 3217, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/ExsInContinuousRVs.tex", "max_stars_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_stars_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-19T07:54:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T13:55:18.000Z", "max_issues_repo_path": "matlab/csebook/ExsInContinuousRVs.tex", "max_issues_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_issues_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "matlab/csebook/ExsInContinuousRVs.tex", "max_forks_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_forks_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-07-18T07:47:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T11:28:24.000Z", "avg_line_length": 33.1649484536, "max_line_length": 141, "alphanum_fraction": 0.5930991607, "num_tokens": 1371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8962513682840824, "lm_q1q2_score": 0.7389251296131318}}
{"text": "\\chapter{Arithmetical Hierarchy}\n\n\\Cref{theorem:enumerable-via-computable-funcitons} proves that any decidable set\nis the image of some total computable function from $\\N$; identifying sets and\npredicates we give the following reformulation.\n\\begin{theorem}\n  A predicate$A(x)$ of natural numbers is enumerable iff there is a decidable\n  predicate $B(x, y)$ such that the following formula is always true:\n  \\[\n    A(x) \\iff \\exists y \\  B(x, y).\n  \\]\n  (Here and in the sequel, we are going to write $\\exists x \\  P(x)$ denotes the\n  statement ``there is an $x$ from the domain of $P$ such that $P(x)$ is true.)\n\\end{theorem}\n\nA natural questions can be asked: ``What can be said about other combinations of\nquantifiers?''.\n\nIt is easy to see that if $A(x)$ is a predicate such that \n\\[\n  A(x) \\iff \\exists y \\  \\exists z \\  C(x, y, z),\n\\]\nwhere $C(x, y, z)$ is decidable, then $A(x)$ is enumerable.\nIndeed, let $B(x, \\pair{y}{z}) = C(x, y, z)$; then $B(x, w)$ is decidable and \n\\[\n  A(x) \\iff \\exists y \\  \\exists z \\  B(x, \\pair{y}{z}) \\iff \n    \\exists w \\  B(x, w).\n\\]\nIf $A(x)$ is a predicate such that \n\\[\n  A(x) \\iff \\forall y \\  B(x, y),\n\\]\nwhere $B(x, y)$ is decidable, then the negation of $A(x)$ is enumerable (we call\nsuch sets and predicates \\emph{coenumerable}). Indeed, \n\\[\n  \\lnot A(x) \\iff \\exists y \\  \\lnot B(x, y),\n\\]\nand $\\lnot B(x, y)$ is decidable since the compliment of a decidable set is\ndecidable.\n\nThis question gives rise to the following definition.\n\\begin{definition}\n  We say that a predicate $A$ on $\\N$ belongs to the class $\\Sigma_n$ iff there\n  is a deciable predicate $B$ on $\\N^{n + 1}$ such that \n  \\[\n    A(x) \\iff \n    \\exists y_1 \\  \\forall y_2 \\  \\exists y_3 \\  \\dots B(x, y_1, \\dots, y_n).\n  \\]\n  Similarly, a predicate $A$ on $\\N$ belongs to the class $\\Sigma_n$ iff there\n  is a deciable predicate $B$ on $\\N^{n + 1}$ such that \n  \\[\n    A(x) \\iff \n    \\forall y_1 \\  \\exists y_2 \\  \\forall y_3 \\  \\dots B(x, y_1, \\dots, y_n).\n  \\]\n\\end{definition}\n\nPrevious observations can be generalized as follows.\n\\begin{theorem}\n\\label{theorem:arythmetic-hierarchy-basics}\n  \\begin{enumerate}\n    \\item The set $\\Sigma_1$ consists of enumerable sets.\n    \\item If a predicate belongs to $\\Sigma_n$, then its negation belongs to\n      $\\Pi_n$.\n    \\item The set $\\Sigma_n$ does not change if we allow groups of quantifiers\n      of the same type instead of single quantifiers.\n  \\end{enumerate}\n\\end{theorem}\n\nLike enumerable and decidable sets, $\\Sigma_n$ and $\\Pi_n$ sets have several\ngood properties.\n\\begin{theorem}\n  Union and intersection of two $\\Sigma_n$ ($\\Pi_n$) sets are also $\\Sigma_n$\n  ($\\Pi_n$) sets.\n\\end{theorem}\n\\begin{proof}\n  We prove the statement for the union of two $\\Sigma_n$ sets, all other cases\n  have similar proofs. Let $A_1, A_2 \\in \\Sigma_n$. By the definition of\n  $\\Sigma_n$, there are decidable $B_1$ and $B_2$ such that \n  \\begin{gather*}\n    A_1(x) \\iff \\exists y_1 \\  \\forall y_2 \\  \\dots B_1(x, y_1, \\dots, y_n) \\\\\n    \\text{and} \\\\\n    A_2(x) \\iff \\exists z_1 \\  \\forall z_2 \\  \\dots B_2(x, z_1, \\dots, z_n).\n  \\end{gather*}\n  Therefore \n  \\begin{multline*}\n      A_1(x) \\land A_2(x) \\iff \\\\\n      \\exists y_1, z_1 \\  \\forall y_2, z_2 \\  \\dots \n        B_1(x, y_1, \\dots, y_n) \\land B_2(x, z_1, \\dots, z_n);\n  \\end{multline*}\n  which implies that $A_1 \\land A_2$ is a $\\Sigma_n$ predicate\n  (\\Cref{theorem:arythmetic-hierarchy-basics}).\n\\end{proof}\n\n\\begin{exercise}\n  Prove that $\\Sigma_n \\cup \\Pi_n \\subseteq \\Sigma_{n + 1} \\cup \\Pi_{n + 1}$ for\n  any $n \\in \\N_0$.\n\\end{exercise}\n\nWe can also prove an extension of\n\\Cref{theorem:m-reduction-complexity-preservation}.\n\\begin{theorem}\n  Let $n \\in \\N$, and let $A, B \\subseteq \\N$ such that $A \\le_m B$.\n  If $B \\in \\Sigma_n$, then $A \\in \\Sigma_n$.\n\\end{theorem}\n\\begin{proof}\n  Let $f$ be the reduction from $A$ to $B$. Let $C$ be a decidable predicate\n  such that\n  \\[\n    B(x) \\iff \\exists y_1 \\  \\forall y_2 \\  \\dots C(x, y_1, \\dots, y_n).\n  \\]\n  Note that, by the definition of the reduction, \n  \\[\n    A(x) \\iff \\exists y_1 \\  \\forall y_2 \\  \\dots C(f(x), y_1, \\dots, y_n);\n  \\]\n  hence, $A(x) \\in \\Sigma_n$ since $C(f(x), y_1, \\dots, y_n)$ is decidable.\n\\end{proof}\n\n\n\\begin{exercise}\n  Prove that if a set $A \\in \\Sigma_n$, then $A \\times A \\in \\Sigma_n$.\n\\end{exercise}\n\nWe defined infinitely many classes of sets; however, we have not shown that all\nthese sets are different (except $\\Sigma_0$ and $\\Pi_0$ which are equal to the\nclass of all decidable sets). Like in the case of enumebrable sets, to prove\nthis we need to use universal sets.\n\\begin{theorem}\n  For any $n \\in \\N$, there is a set $U \\in \\Sigma_n$ universal for $\\Sigma_n$\n  subsets of $\\N$.\n\\end{theorem}\n\\begin{proof}\n  We prove the statement using induction by $n$. The base case for $n = 1$ is\n  true by\n  \\Cref{theorem:arythmetic-hierarchy-basics,theorem:universal-set-enumerable}.\n\n  Let us prove the induction step. Assume $V \\in \\Sigma_n$ is a universal set\n  for $\\Sigma_n$ subsets of $\\N$. First we show that $(\\N \\setminus V) \\in \\Pi_n$\n  is a universal set for $\\Pi_n$ subsets of $\\N$. Let $A \\in \\Pi_n$. Then there\n  is $k \\in \\N$ such that $\\N \\setminus A = V_k$ since $(\\N \\setminus A) \\in\n  \\Sigma_n$. Therefore, $A = \\N \\setminus V_k$ which implies that \n  $\\N \\setminus V$ is universal for $\\Pi_n$ subsets of $\\N$.\n  \n  \n  Note that there is $W' \\in \\Pi_n$ that is universal for $\\Pi_n$ subsets\n  of $\\N^2$. Indeeed, let $W' = \\set[(n, \\pair{x}{y}) \\in W]{(n, x, y) \\in \\N^3}\n  \\in \\Sigma_n$.\n  Let $A' \\in \\Pi_n$ and $B'$ be decidable set such that\n  \\[\n    A'(x, y) \\iff \\exists z_1 \\  \\forall z_2 \\  \\dots B'(x, y, z_1, \\dots, z_n).\n  \\]\n  Consider $A \\subseteq \\N$ such that \n  \\[\n    A(\\pair{x}{y}) \\iff \\exists z_1 \\  \\forall z_2 \\  \\dots \n      B'(x, y, z_1, \\dots, z_n);\n  \\]\n  it is clear that $A \\in \\Pi_n$. Hence, there is $k \\in \\N$ such that \n  $W_k = A$, which implies that $W'_n = A'$. Therefore $W'$ is universal for\n  $\\Pi_n$ subsets of $\\N^2$.\n\n  Let us consider the set \n  $U = \\set[\\exists y \\  (k, x, y) \\in W']{(k, x) \\in \\N^2}$. We claim that it is\n  universal for $\\Sigma_{n + 1}$ subsets of $\\N$.\n  Let $A \\in \\Sigma_{n + 1}$. Then there is $B \\in \\Pi_n$ such that \n  \\[\n    A(x) \\iff \\exists y \\  B(x, y).\n  \\]\n  In addittion, there is $k \\in n$ such that $W'_k = B$. Therefore, \n  \\[\n    A(x) \\iff \\exists y \\  W'(k, x, y) \\iff U(k, x).\n  \\]\n  Hence, $U$ is universal for $\\Sigma_{n + 1}$ subsets of $\\N$.\n\\end{proof}\n\nWe proved that the compliment of an enumerable universal set for the class of\nenumerable sets is not enumerable. Similar result can be shown for $\\Sigma_n$.\n\\begin{theorem}\n  Let $n \\in \\N$ and let $W \\subseteq \\N^2$ be universal for $\\Sigma_n$ subsets\n  of $\\N$. Then $W \\not\\in \\Pi_n$.\n\\end{theorem}\n\\begin{proof}\n  Assume that $W \\in \\Pi_n$, this implies that that the set \n  $D = \\set[(n, n) \\not\\in W]{n \\in \\N}$ belongs to $\\Sigma_n$.\n  Note that there is $k \\in \\N$ such that $W_k = D$ since $W$ is universal for\n  $\\Sigma_n$ subsets if $\\N$. However, $W_k(k)$ is true only if $W_k(k)$ is\n  false, which is a contradiction. Therefore, $W \\not\\in \\Pi_n$.\n\\end{proof}\n\n\\begin{corollary}\n  For any $n \\in \\N$, $\\Pi_n \\not\\subseteq \\Sigma_{n + 1}$ and \n  $\\Sigma_n \\not\\subseteq \\Pi_{n + 1}$.\n\\end{corollary}\n\n\\begin{chapterendexercises}\n  \\exercise Prove that if $A, B \\in \\Sigma_n$, then \n    $A \\setminus B \\in \\Sigma_{n + 1} \\cap \\Pi_{n + 1}$.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "8578903d3a8dc212f749d01d0517b858f11057a4", "size": 7443, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_9/chapter_40_arithmetical_hierarchy.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_9/chapter_40_arithmetical_hierarchy.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_9/chapter_40_arithmetical_hierarchy.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 37.7817258883, "max_line_length": 81, "alphanum_fraction": 0.6379148193, "num_tokens": 2653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.865224070413529, "lm_q1q2_score": 0.738825874320206}}
{"text": "\\section{08/31}\n\\subsection{Verifying Matrix Multiplication}\n\\begin{problem}{Verifying Matrix Multiplication}{}\n    Let $A$, $B$, and $C$ be $n \\times n$ matrices. Verify whether\n    \\[A \\times B = C\\]\n\\end{problem}\nThe best known deterministic algorithm for this requires $\\bigO{n^{2.37286}}$\noperations, improving over the previous best of $\\bigO{n^{2.37287}}$\n\\cite{alman2020refined}. However, we can do substantially better using\nrandomization.\n\nA principle in randomized algorithms is to take advantage of an ``abundance of\nwitness,'' that is, when some property that is helpful towards your algorithm\noccurs often enough, to try and make use of that property.\n\nIn this case, the witness is that, if $AB = C$, then $AB\\vec{r} = C\\vec{r}$ for\nevery vector $\\vec{r}$. Thus, a single vector will prove if $AB \\neq C$, and\neach vector for which $AB\\vec{r} = C\\vec{r}$ increases our confidence that $AB =\nC$. This admits the following pseudocode\n\\begin{algorithm}\n    \\caption{Verify Matrix Multiplication}\n    \\begin{algorithmic}[1]\n        \\Function{Rand-Matrix-Mult-Verify}{A, B, C}\n            \\State $\\vec{r} \\gets \\Call{Sample}{\\set{0,1}^n}$\n            \\If{$A(B\\vec{r}) \\neq C\\vec{r}$}\n                \\State \\Return \\False\n            \\Else\n                \\State \\Return \\True\n            \\EndIf\n        \\EndFunction\n    \\end{algorithmic}\n\\end{algorithm}\nNotice that this algorithm only requires $\\bigO{n^2}$ operations. As stated\npreviously, it does not admit false negatives --- if $AB = C$, it will never\noutput \\False, because we must have $AB\\vec{r} = C\\vec{r}$ for all $\\vec{r}$.\n\nLet us determine the probability that this algorithm outputs \\True when $AB \\neq\nC$. Write $D = AB - C \\neq 0_{n,n}$, and observe that $D$ must have at least one\nnon-zero entry. Without loss of generality, say it is $d_{1,1}$. Now, if\n$AB\\vec{r} = C\\vec{r}$, then $D\\vec{r} = \\vec{0}$. In particular, writing\n$\\vec{r} = (r_1, r_2, \\dots, r_n)$, we must have\n\\begin{align*}\n    d_{1,1}r_1 + d_{1,2}r_2 + \\dots + d_{1,n}r_n = 0\\\\\n    r_1 = \\frac{-1}{d_{1,1}}\\sum_{i=2}^n d_{1,i}r_i\n\\end{align*}\n\nTo determine the probability that $r_1$ is equal to this value, we apply the\n\\emph{Principle of Deferred Decisions}\n\\begin{definition}{Principle of Deferred Decisions}{}\n    The \\emph{Principle of Deferred Decisions} states that, in the analysis of a\n    randomized algorithm, we can \\emph{defer} random choices until they are\n    revealed to the algorithm.  \n\\end{definition}\n\nIn this specific case, we can assume $r_2$, $r_3$, \\dots, $r_n$ have already\nbeen assigned their random values. Clearly, then, the probability that $r_1$ is\nequal to $\\frac{-1}{d_{1,1}}\\sum_{i=2}^n d_{1,i}r_i$ is \\emph{at most}\n$\\sfrac{1}{2}$. \n\nThis gives us an upper bound on the probability of a false positive. In\nparticular, after repeating the algorithm $k$ times, the probability of a false\npositive is at most $\\sfrac{1}{2^k}$. Setting $k = \\log{n}$ yields the desired\nupper bound of $\\sfrac{1}{n}$. In other words, the following pseudocode verifies\nmatrix multiplication with high probability\n\n\\begin{algorithm}\n    \\caption{Verify Matrix Multiplication with High probability}\n    \\begin{algorithmic}[1]\n        \\Function{Rand-Matrix-Mult-Verify-WHP}{A, B, C}\n            \\ForRange{$i$}{1}{$\\log{n}$}\n                \\State $\\texttt{result} \\gets \\Call{Rand-Matrix-Mult-Verify}{A, B, C}$\n                \\If{$\\texttt{result}$ is \\False}\n                    \\State \\Return \\False\n                \\EndIf\n            \\EndForRange\n            \\State \\Return \\True\n        \\EndFunction\n    \\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{Verifying Equality of Binary Strings}\n\\begin{problem}{Verifying Equality of Binary Strings}{}\n    Given strings\n    \\begin{align*}\n        \\texttt{X} &= \\texttt{x}_0 \\texttt{x}_1 \\dots \\texttt{x}_{n-1}\\\\\n        \\texttt{Y} &= \\texttt{y}_0 \\texttt{y}_1 \\dots \\texttt{y}_{n-1} \n    \\end{align*}\n    Determine if $X = Y$, i.e., if there exists an $i$ such that $\\texttt{x}_i\n    \\neq \\texttt{y}_i$.\n\\end{problem}\n\nHere, we are interested in \\emph{communication complexity}. Specifically suppose\nAlice has string $\\texttt{X}$ and Bob has string $\\texttt{Y}$, and they wish to\ndetermine if their strings are equal by transmitting a message of $k$ bits.\n\nClearly, there is a naive deterministic algorithm that requires $\\bigO{n}$ time\nby simplying comparing all $n$ bits. In fact, \\emph{every} deterministic\nalgorithm requires $\\bigOm{n}$ bits. However, we can construct a randomized\nalgorithm, via a technique called \\emph{fingerprinting}, that requires\n$\\bigO{\\log{n}}$ bits.\n\nFor a prime $p \\in \\set{1, 2, \\dots, k}$, let us define $F_p(x) = x \\bmod p$.\nAdditionally, we will identify the values $\\texttt{X}$ and $\\texttt{Y}$ by the\nnumerical value of their binary strings, that is,\n\\begin{align*}\n    \\texttt{X} &= \\sum_{i=0}^{n-1}\\texttt{x}_i 2^i\\\\\n    \\texttt{Y} &= \\sum_{i=0}^{n-1}\\texttt{y}_i 2^i \n\\end{align*}\nIf $F_p(\\texttt{X}) \\neq F_p(\\texttt{Y})$, then we output \\False, otherwise we\noutput \\True. Again, this admits no false negatives, since if $\\texttt{X} =\n\\texttt{Y}$, $F_p(\\texttt{X}) = F_p(\\texttt{Y})$ for any function $F_p$.\n\nObserve that, if $F_p(\\texttt{X}) = F_p(\\texttt{Y})$, then\n\\[\\sum_{i=0}^{n-1}\\left(\\texttt{x}_i - \\texttt{y}_i\\right) 2^i \\bmod p = 0\\]\nAdditionally, notice that\n\\[\\sum_{i=0}^{n-1}\\left(\\texttt{x}_i - \\texttt{y}_i\\right) 2^i \\leq 2^n\\]\nIn particular, there are at most $n$ prime factors of\n$\\sum_{i=0}^{n-1}\\left(\\texttt{x}_i - \\texttt{y}_i\\right) 2^i$. Letting $\\pi(k)$\ndenote the number of primes less than or equal to $k$, we have\n\\begin{align*}\\prob{F_p(\\texttt{X}) \\neq F_p(\\texttt{Y}) \\given \\texttt{X} \\neq \\texttt{Y}}\n    &\\leq \\frac{n}{\\pi(k)}\\\\\n    &\\approx \\frac{n\\ln{k}}{k}\n\\end{align*}\nTaking $k = n^2\\ln{n}$ yields\n\\[\\prob{F_p(\\texttt{X}) \\neq F_p(\\texttt{Y}) \\given \\texttt{X} \\neq \\texttt{Y}} \\leq \\frac{1}{n}\\]\n\n\\subsection{Binary Consensus}\n\\begin{problem}{Binary Consensus}{}\n    Given $n$ parties, of which at most $f$ are faulty (and can crash at any\n    time), and who each hold a 0 or 1, Consensus is reached when:\n    \\begin{enumerate}\n        \\item Agreement --- all non-faulty parties agree to the same bit\n        \\item Validity --- if all parties start with a value, all parties must\n              agree on that value\n        \\item Termination --- all parties terminate in finite time\n    \\end{enumerate}\n\\end{problem}\n\nLet us assume that communication is asynchronous and that all nodes can\ncommunicate with all other nodes (i.e., the network is a complete graph).\n%TODO drawing\n\nWith \\emph{no faults}, it is sufficient for each node to simply broadcast their\nvalue and take the majority, breaking ties with 1. However, with even a single\nfault, this problem \\emph{cannot} be solved deterministically. Additionally, no\nrandomized algorithm can solve this problem when there are at least\n$\\sfrac{n}{2}$ faults.\n\n%TODO prove the above for randomized.", "meta": {"hexsha": "bc1eadcf0008a3c40ff6393d75584219f8ef1e07", "size": 6928, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/0831.tex", "max_stars_repo_name": "khalid-salad/Randomized-Algorithms-Notes", "max_stars_repo_head_hexsha": "2556b9d8ede2f3c10960949680f077a8d7e37196", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-28T23:46:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-28T23:46:42.000Z", "max_issues_repo_path": "tex/0831.tex", "max_issues_repo_name": "khalid-salad/Randomized-Algorithms-Notes", "max_issues_repo_head_hexsha": "2556b9d8ede2f3c10960949680f077a8d7e37196", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/0831.tex", "max_forks_repo_name": "khalid-salad/Randomized-Algorithms-Notes", "max_forks_repo_head_hexsha": "2556b9d8ede2f3c10960949680f077a8d7e37196", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.4966442953, "max_line_length": 98, "alphanum_fraction": 0.6726327945, "num_tokens": 2218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7388258734484928}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Find the vector equation for the line through $(-7,6,0)$ and\n  $(-1,1,4)$. Then, find the parametric equations for this\n  line.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find parametric equations for the line through the point\n  $(7,7,1)$ with direction vector\n  $\\vect{d} = \\begin{mysmallmatrix}{r} 1 \\\\ 6 \\\\ 2 \\end{mysmallmatrix}$.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Parametric equations of the line are\n  \\begin{equation*}\n    \\begin{array}{c}\n      x = t+2, \\\\\n      y = 6-3t, \\\\\n      z = -t-6.\n    \\end{array}\n  \\end{equation*}\n  Find a direction vector for the line and a point on the line.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  The equation of a line in two dimensions is written as $y=x-5$. Find\n  a vector equation for this line.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find parametric equations for the line through $(6, 5, -2, 3)$\n  and $(5, 1, 2, 1)$.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the following vector equation for a line in $\\R^3$:\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x\\\\y\\\\z \\end{mymatrix}\n    = \\begin{mymatrix}{r} 1\\\\2\\\\0 \\end{mymatrix}\n    + t\\,\\begin{mymatrix}{r} 1\\\\0\\\\1 \\end{mymatrix}.\n  \\end{equation*}\n  Find a new vector equation for the same line by doing the change of\n  parameter $t=2-s$.\n  \\begin{sol}\n    We have\n    \\begin{equation*}\n      \\begin{mymatrix}{c} x\\\\y\\\\z \\end{mymatrix}\n      = \\begin{mymatrix}{r} 1\\\\2\\\\0 \\end{mymatrix}\n      + (2-s)\\,\\begin{mymatrix}{c} 1\\\\0\\\\1 \\end{mymatrix}\n      = \\begin{mymatrix}{r} 3\\\\2\\\\2 \\end{mymatrix}\n      + s\\,\\begin{mymatrix}{r} -1\\\\0\\\\-1 \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the line given by the following parametric equations:\n  \\begin{equation*}\n    \\begin{array}{c}\n      x = 2t+2, \\\\\n      y = 5-4t, \\\\\n      z= -t-3.\n    \\end{array}\n  \\end{equation*}\n  Find symmetric equations for the line.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the point on the line segment from $P = (-4, 7, 5)$ to\n  $Q = (2, -2, -3)$ which is $\\frac{1}{7}$ of the way from $P$\n  to $Q$.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose a triangle in $\\R^n$ has vertices at $P$, $Q$,\n  and $R$.  Consider the lines which are drawn from a vertex to the\n  mid point of the opposite side. Show these three lines intersect in\n  a point and find the coordinates of this point.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Determine whether the lines\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 2 \\end{mymatrix}\n    + t \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 2 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ -1 \\\\ -4 \\end{mymatrix}\n    + s \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ -1 \\end{mymatrix}\n  \\end{equation*}\n  intersect. If yes, find the point of intersection.\n\\end{ex}\n\n\\begin{ex}\n  Determine whether the lines\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c} 2 \\\\ -1 \\\\ 0 \\end{mymatrix}\n    + t \\begin{mymatrix}{c} 1 \\\\ 3 \\\\ 2 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 3 \\end{mymatrix}\n    + s \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 0 \\end{mymatrix}\n  \\end{equation*}\n  intersect. If yes, find the point of intersection.\n\\end{ex}\n\n\\begin{ex}\n  Find the angle between the two lines\n  \\begin{equation*}\n    \\begin{mymatrix}{r} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{r} 3 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    + t \\begin{mymatrix}{r} 3 \\\\ -3 \\\\ 0 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\begin{mymatrix}{r} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{r} 3 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    + s \\begin{mymatrix}{r} -1 \\\\ 2 \\\\ 2 \\end{mymatrix}.\n  \\end{equation*}\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex} Let $P = (1,2,3)$ be a point in $\\R^3$. Let $L$ be the line\n  through the point $P_0 = (1, 4, 5)$ with direction vector\n  $\\vect{d} = \\begin{mysmallmatrix}{r} 1 \\\\ -1 \\\\\n    1 \\end{mysmallmatrix}$. Find the shortest distance from $P$ to\n  $L$, and find the point $Q$ on $L$ that is closest to $P$.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex} Let $P = (0,2,1)$ be a point in $\\R^3$. Let $L$ be the line through the points $P_0 = (1, 1, 1)$ and $P_1 = (4, 1, 2)$. Find the shortest distance from $P$ to $L$, and find the point $Q$ on $L$ that is closest to $P$.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\\label{ex:angle-lines}\n  When we computed the angle between two lines in\n  Example~\\ref{exa:angle-between-two-lines}, we calculated two\n  different angles and took the smaller of the two. Show that one can\n  get the same answer by taking the absolute value of the dot product,\n  i.e., by solving\n  \\begin{equation*}\n    \\cos\\theta =\n    \\frac{\\abs{\\vect{u}\\dotprod\\vect{v}}}{\\norm{\\vect{u}}\\norm{\\vect{v}}}.\n  \\end{equation*}\n  \\begin{sol}\n    From trigonometry, we have the following properties of the cosine\n    function:\n    \\begin{itemize}\n    \\item $\\cos\\theta$ is positive for $0\\leq\\theta\\leq\\frac{\\pi}{2}$,\n      and negative for $\\frac{\\pi}{2}\\leq\\theta\\leq\\pi$.\n    \\item $\\cos(\\pi-\\theta) = -\\cos\\theta$.\n    \\end{itemize}\n    By the method in Example~\\ref{exa:angle-between-two-lines}, we\n    calculated $\\theta$ such that\n    \\begin{equation*}\n      \\cos\\theta =\n      \\frac{\\vect{u}\\dotprod\\vect{v}}{\\norm{\\vect{u}}\\norm{\\vect{v}}}.\n    \\end{equation*}\n    If $0\\leq\\theta\\leq\\frac{\\pi}{2}$, the answer is $\\theta$. If\n    $\\frac{\\pi}{2}\\leq\\theta\\leq\\pi$, the answer is $\\phi=\\pi-\\theta$.\n    But in the last case, the dot product is negative and we have\n    \\begin{equation*}\n      \\cos\\phi = \\cos(\\pi-\\theta) = -\\cos\\theta = \\frac{-\\vect{u}\\dotprod\\vect{v}~~}{\\norm{\\vect{u}}\\norm{\\vect{v}}}\n      =\n      \\frac{\\abs{\\vect{u}\\dotprod\\vect{v}}}{\\norm{\\vect{u}}\\norm{\\vect{v}}}.\n    \\end{equation*}\n    So in either case we get the correct answer by taking the absolute\n    value.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "6a5f81994d04ce3d26d686beaaf988e0d3da883e", "size": 6064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/LinesAndPlanes-Lines.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/LinesAndPlanes-Lines.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/LinesAndPlanes-Lines.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 31.5833333333, "max_line_length": 228, "alphanum_fraction": 0.6029023747, "num_tokens": 2337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7388258712280813}}
{"text": "\\section{LLN and CLT}\nLet $X_1, ..., X_n \\stackrel{iid}{\\sim} P_{\\mu}$, where $E(X_i)=\\mu$ and $Var(X_i)=\\sigma^2$ for all $i=1,2,...,n$ and $\\bar{X_n}= \\frac{1}{n} \\sum_{i=1}^{n} X_i$.\\\\\n\\textbf{Law of large numbers:}\n\\begin{align*}\n\\bar{X_n}& \\xrightarrow[n \\rightarrow \\infty]{P, a.s.} \\mu\\\\\n\\frac{1}{n} \\sum_{i=1}^{n} g(X_i)& \\xrightarrow[n \\rightarrow \\infty]{P, a.s.} \\mathbb{E}[g(X)]\n\\end{align*}\n\\textbf{Central Limit Theorem for Mean:}\n\\begin{align*}\n\\sqrt(n)\\frac{\\bar{X_n}-\\mu}{\\sqrt(\\sigma^2)}& \\xrightarrow[n \\rightarrow \\infty]{(d)} N(0,1)\\\\\n\\sqrt(n)(\\bar{X_n}-\\mu)& \\xrightarrow[n \\rightarrow \\infty]{(d)} N(0,\\sigma^2)\n\\end{align*}\n\n\\textbf{Central Limit Theorem for Sums:}\n\n\\begin{align*}\n\\sum{X}_{i=1}^{n} & \\xrightarrow[n \\rightarrow \\infty]{(d)} N(n \\mu, \\sqrt(n)\\sqrt(\\sigma^2))\\\\\n\\frac{\\sum{X}_{i=1}^{n} - n\\mu}{\\sqrt(n) \\sqrt(\\sigma^2)} & \\xrightarrow[n \\rightarrow \\infty]{(d)} N(0, 1)\\\\\n\\end{align*}\n\n\\textbf{Variance of the Mean:}\n\\begin{align*}\nVar(\\overline{X_n})&=(\\frac{\\sigma^2}{n})^2 Var(X_1 + X_2,...,X_n) =\\frac{\\sigma^2}{n}\n\\end{align*}\n\\textbf{Expectation of the mean:}\n\\begin{align*}\nE[\\bar{X_n}] & =\\frac{1}{n}E[X_1 + X_2,...,X_n] =\\mu.\n\\end{align*}", "meta": {"hexsha": "6602e2d17753ed65bd6cb99882f5053ce447ab75", "size": 1187, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/Law_large_Numbers.tex", "max_stars_repo_name": "kpsunkara/MITx_capstone_1", "max_stars_repo_head_hexsha": "ee5ef547e144011edd1bd4f03def0a24a31f69bf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "content/Law_large_Numbers.tex", "max_issues_repo_name": "kpsunkara/MITx_capstone_1", "max_issues_repo_head_hexsha": "ee5ef547e144011edd1bd4f03def0a24a31f69bf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "content/Law_large_Numbers.tex", "max_forks_repo_name": "kpsunkara/MITx_capstone_1", "max_forks_repo_head_hexsha": "ee5ef547e144011edd1bd4f03def0a24a31f69bf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-20T06:07:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-20T06:07:28.000Z", "avg_line_length": 42.3928571429, "max_line_length": 165, "alphanum_fraction": 0.6074136479, "num_tokens": 533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7387484666631176}}
{"text": "\\section{Masked attention\rimplementation}\n\nIn this section we will detail the prefix sum algorithm proposed by\r\\citet{choromanski2021rethinking} for\r masked kernelized attention, and give an implementation with usual\rfunctions of neural network frameworks.\r\n\n\\begin{equation}\nA^{masked} = \\mathrm{masked} \\left( \\phi(Q) \\times \\phi(K^T) \\right) \\times V\n\\end{equation}\n\nIn this expression, $\\mathrm{masked}$ being the operation that set all cells\r above the diagonal to 0 in a matrix. The naive implementation of this\r operation has complexity $O(L_QL_Kd)$.\n\nWe can change the complexity using the operation proposed by\r \\citet{choromanski2021rethinking}. We\r will derive its formulation here.\r To start with it, $A^{masked}$ is defined as\n\n\\begin{equation}\nA^{masked} = S^{masked} \\times V\n\\end{equation}\n\n\\noindent{}which\rin summation form is expressed as\n\n\\begin{equation}\nA^{masked}_{ij} = \\sum_k V_{kj} \\times S^{masked}_{ik}\n\\end{equation}\n\n\\noindent{}and the\relements of S are defined as:\n\n\\begin{equation}\nS^{masked}_{ik} =\r\n\\begin{cases}\nk \\leq i & \\sum_l \\left( \\phi(Q)_{il} \\times \\phi(K)_{kl} \\right) \\\\\r\n\\text{otherwise} &{}0 \n\\end{cases}\n\\end{equation}\n\nPutting these elements together leads to\n\n\\begin{equation}\nA^{masked}_{ij}= \\sum_{k=1}^i V_{kj} \\times \\sum_l \\left( \\phi(Q)_{il} \\times \\phi(K)_{kl} \\right)\n\\end{equation}\n\n\\noindent{}which can be reworked as\n\n\\begin{equation}\nA^{masked}_{ij}= \\sum_l \\phi(Q)_{il} \\times \\sum_{k=1}^i \\left(V_{kj} \\times \\phi(K)_{kl} \\right)\n\\end{equation}\n\nIn this work we make use of these ideas to implement the calculation of\r $A^{masked}$ with complexity $O(max(L_Q, L_K) \\times d^2)$ without\r custom GPU code as per the following algorithm:\r\n\n\\begin{enumerate}\r\n\\def\\labelenumi{\\arabic{enumi}.}\r\n\\item\r\n$\\phi(Q)$, $\\phi(K)$, $V$ tensors of shape $(L_Q, 1, d)$,\r\n$(L_K, d)$, $(L_K, d)$\r\n\\item\r\n$Unrolled_{kjl} = V_{kj} \\times \\phi(K)_{kl}$ tensor of shape\r\n$(L_K, d, d)$\r\n\\item\r\n$Right = cumsum(Unrolled,\\text{ dim=0})$ tensor of shape\r\n$(L_K, d, d)$\r\n\\item\r\n$Right = align(Right, L_Q)$ tensor of shape $(L_Q, d, d)$\r\n\\item\r\n$A^{masked} = \\phi(Q) \\otimes Right$ tensor of shape $(L_Q, 1, d)$\r\n\\end{enumerate}\r\n\n\\noindent{}with\n\n\\begin{itemize}\n\\item\r\n$\\otimes$ the batch matrix product along the last two dimensions\r\n\\item\r\n$cumsum(\\_, dim=0)$ the function that calculates the cumulated sum\r\nalong the first dimension\r\n\\item\r\n$align(\\_, L_Q)$ the function that extend the first dimensions to\r\nsize $L_Q$ by repeating the last element if $L_Q > L_K$, or\r\ntruncate to size $L_Q$ if $L_Q < L_K$. (Can be implemented with\r\nslicing and concatenation)\r\n\\end{itemize}\n\n\\endinput\n", "meta": {"hexsha": "8744b3d1c8b7ef18e083d2204ed9fae4ac1c0205", "size": 2629, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/03-masked-attention.tex", "max_stars_repo_name": "ScalableTransformer/Scaleformer", "max_stars_repo_head_hexsha": "57e65deb7ba5fdda88a21bdaf71092a0101cf8c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/sections/03-masked-attention.tex", "max_issues_repo_name": "ScalableTransformer/Scaleformer", "max_issues_repo_head_hexsha": "57e65deb7ba5fdda88a21bdaf71092a0101cf8c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/sections/03-masked-attention.tex", "max_forks_repo_name": "ScalableTransformer/Scaleformer", "max_forks_repo_head_hexsha": "57e65deb7ba5fdda88a21bdaf71092a0101cf8c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-01T06:24:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T06:24:31.000Z", "avg_line_length": 32.8625, "max_line_length": 214, "alphanum_fraction": 0.7010270065, "num_tokens": 855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7387484644138002}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\graphicspath{{plots/}}\n\\setlength{\\parindent}{0em}\n\\setlength{\\parskip}{0.5em}\n\n\\title{CTA200 Assignment 2}\n\\author{Emily Crawley}\n\\date{05/05/2021}\n\n\\begin{document}\n\n\\maketitle\n\n\\section*{Question 1}\n\nUsing the approximation given for evaluating a function $f(x)$ at $x_0$ for small finite $h$, we define \\texttt{deriv(f, x0, h)} which computes\n\n$$ \\frac{f(x_0 + h) - f(x_0 - h)}{2h} $$\n\nWe then define our function to be differentiated, \\texttt{f(x) = sin(x)} and its analytical derivative \\texttt{dfdx(x) = cos(x)}. Values of $h < 1$ were chosen ranging from 0.1 to 1e-8.\n\nWe compute the analytical derivative $cos(0.1)$, and the numerical derivatives at each value of $h$, plotting them each against the analytical solution. Since the $h$ values vary by orders of 10 we plot the error on logarithmic axes using \\texttt{pyplot.loglog}.\n\n\\includegraphics[scale=0.7]{plot1}\n\nFrom the plot we can see that the error in the numerical solution decreases linearly for smaller values of $h$, until around $h < 10^{-6}$ when the larger relative error presumably comes from the precision limitations of the \\texttt{float} type. The slope of the linear part of the graph represents how quickly the error decreases as $h$ decreases, so in some sense represents its effectiveness in terms of accuracy. That is, we want to be able to greatly decrease error with only one or two order-of-magnitude decrements of $h$, so a steeper slope is preferable.\n\n\\section*{Question 2}\n\nWe cover the complex plane in the square $|z|^2 = \\Re(z)^2 + \\Im(z)^2$ by taking $c = x + iy$ for numerous combinations of x- and y-values between -2 and 2.\n\nFor each point $c$ we iterate the expression $z_{i + 1} = z_i^2 + c$ starting from $z_0 = 0$ and test the absolute square of each $z_i$ to see if it diverges from the boundary. If so, we assign it a value of 0 in a 2D boolean array representing whether each point is bounded or not. We also record the iteration number in a separate 2D array. The iteration number array contains values of -1 for points that stay bounded. We then plot the results using \\texttt{pyplot.imshow}.\n\nWhen tested running for 1000 iterations, none of the points in the sample set take more than 32 iterations to diverge, so to save time we will only iterate for 32 steps.\n\nThe only obvious pattern from the resulting images is that there are no points that remain bounded from our iteration in an area centered around $c = -0.5i$. This same area on the iteration numbers plot also notably contains the brightest points, i.e. the points in these areas take a higher number of iterations to diverge. There is a single point near the center of this area that notably takes the single highest number of iterations to diverge. These results are taken from a finite number of points across the area and not every possible point, so there could be more \"interesting\" points that are missed by numerical analysis.\n\n\\includegraphics[scale=0.7]{plot2_1}\n\n\\includegraphics[scale=0.7]{plot2_2}\n\n\\section*{Question 3}\n\nOur initial value problem is given as:\n\n\\begin{align}\n    \\frac{dS}{dt} &= -\\frac{\\beta S I}{N},\\\\\n    \\frac{dI}{dt} &= \\frac{\\beta S I}{N} - \\gamma I,\\\\\n    \\frac{dR}{dt} &= \\gamma I\n\\end{align}\n\n$I(0) = 1, S(0)=999, R(0) = 0$\n\n$N=1000$, $0\\leq t \\leq 200$\n\nUsing \\texttt{scipy.integrate.solve\\_ivp} as the ODE integrator, which takes parameters \\texttt{(fun, tspan, y0)}, we set up the time derivative functions as a vector $[\\frac{dS}{dt},\\frac{dI}{dt},\\frac{dR}{dt}]$ for the \\texttt{fun} parameter, and the initial conditions vector $[S(0), I(0), R(0)]$ as \\texttt{y0}. We also specify the parameter \\texttt{vectorized=True} so that the integrator handles the vectors properly. We will use its default Runge-Kutta method, \\texttt{method='RK45'}.\n\n$\\beta$ represents an infection rate and $\\gamma$ represents a recovery rate, so we will select some meaningful variations on these parameters, i.e. a disease that spreads quickly but has a fast recovery rate, a disease that spreads quickly with a slower recovery rate, etc. The solutions show us the different progressions for each of these sets of parameters, for example with a high infection rate and low recovery rate there is a large spike in $I(t)$, whereas with the same infection rate but a higher recovery rate the $I(t)$ \"spike\" is much lower as the disease does not have the opportunity to progress. The first three scenarios plotted all have the recovered and susceptible populations become constant when the infected population reaches zero. With a zero recovery rate, the entire population eventually becomes infected.\n\n\\includegraphics[scale=0.7]{plot3}\n\n\\end{document}", "meta": {"hexsha": "55f79311f00a1a81d321bc3f6ec459afc73af61b", "size": 4772, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_2/Assignment 2.tex", "max_stars_repo_name": "emilychallice/CTA200", "max_stars_repo_head_hexsha": "7343229002a5a6df8a6280c721f908018d0ccbd8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_2/Assignment 2.tex", "max_issues_repo_name": "emilychallice/CTA200", "max_issues_repo_head_hexsha": "7343229002a5a6df8a6280c721f908018d0ccbd8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_2/Assignment 2.tex", "max_forks_repo_name": "emilychallice/CTA200", "max_forks_repo_head_hexsha": "7343229002a5a6df8a6280c721f908018d0ccbd8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 72.303030303, "max_line_length": 833, "alphanum_fraction": 0.7518860017, "num_tokens": 1283, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.8887588038050467, "lm_q1q2_score": 0.7386856935708188}}
{"text": "\\documentclass{article}\n\\title{Learning}\n\\author{Samuel Schlesinger}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Problems}\n\n\\subsection{Linear Regression}\n\nIn linear regression, we wish to relate two sets of data by a linear estimator. Specifically,\nwe have some set of vectors $\\{(x_i \\in \\mathbb{R}^D, y_i \\in \\mathbb{R})\\}_{i \\in [N]}$ and\nwe want to find some $\\beta \\in \\mathbb{R}^{D + 1}$ such that we minimize the sum of squared\nerrors. From now on, for notational parsimony, I'll assume that $x_i \\in \\mathbb{R}^{D+1}$ and\nsay, the last dimension, is reserved for a $1$, to multiplicatively interact with the extra\nplace in $\\beta$, which will perform the role of a \"bias\" in our estimate. We're learning an\naffine transformation rather than simply a linear one this way. We relate our variables in the\nfollowing way, where $\\epsilon \\in \\mathbb{R}$ is the error term.\n\n\\[ y = x\\beta + \\epsilon \\]\n\\[ SSE = \\epsilon^T\\epsilon \\]\n\nWe'll go through a quick derivation of the closed formula for $\\beta$ which minimizes $SSE$.\nFirst, we recognize:\n\n\\[ \\epsilon = y - x\\beta \\]\n\nThus, we can write $SSE$ as:\n\n\\[ SSE = (y - x\\beta)^T(y - x\\beta) \\]\n\nWe can distribute the transposition:\n\n\\[ SSE = (y^T - \\beta^Tx^T)(y - x\\beta) \\]\n\nFinally, we expand:\n\n\\[ SSE = y^Ty - y^Tx\\beta - \\beta^Tx^Ty + \\beta^Tx^Tx\\beta \\]\n\nAnd by transposing one of the inner terms (not changing its value, as this is the error which\nis a scalar):\n\n\\[ SSE = y^Ty - 2\\beta^Tx^Ty + \\beta^Tx^Tx\\beta \\]\n\nSo we have a nice formula for the error, but we have to minimize!\n\n\\[ \\frac{\\partial SSE}{\\partial \\beta} = -2x^Ty + 2x^Tx\\beta = 0 \\]\n\\[ \\beta = (x^Tx)^{-1}x^Ty \\]\n\nWe have found our $\\beta$ in closed form, so then my Haskell code initially reflected this.\nThat being said, once one observes a property of $\\beta$ its clear that something better\ncan be done computationally. Critically, $x^Tx$ is always going to be positive definite, so\nwe can use the Cholesky factorization and get a matrix $L^*L = x^Tx$ and write:\n\n\\[ \\beta = (L^*L)^{-1}x^Ty = (L^{-1})(L^{-1})^*x^Ty \\]\n\nThe property of $L$ which is important here is that it is triangular, making the inversion\nmuch more numerically stable than it otherwise could be. This becomes incredibly important\nand because of this implementation change I went from being able to deal with thousands of\ndata points of dimension $3$, now I can handle millions of dimension $100$.\n\n\\subsection{KMeans Clustering}\n\nWhen we kmeans-cluster data, we are given a set of data points and an integer:\n\n\\[X = \\{x_i \\in \\mathbb{R}^D\\}_{i \\in [N]}, k \\in \\mathbb{N}, k \\leq N \\]\n\nOur objective is to produce $S = \\{S_i \\subset X\\}_{i \\in [k]}$ a partition of $X$ with means\n$\\mu_i = \\frac{\\sum_{x \\in S_i} x}{|S_i|}$ such that it \nminimizes the kmeans error function:\n\n\\[ KME(S) = \\sum_{i = 1}^k \\sum_{x \\in S_i} ||x - \\mu_i||^2 \\]\n\nSolving this problem is not easy, in fact its NP-hard if you squint at it long enough, so\nwe'll use a simple greedy heuristic. Lets assume that we have some candidate set of $\\mu_i$,\nwe can use these to generate a clustering by taking \n$S_i = \\{ x \\in X \\mid argmin_j d(x, \\mu_j) = i\\}$. That being said, we must then check if\nthese $\\mu_i$ actually are the means for these clusters, and thus we must check that $\\mu_i$\ntruly is the average of $S_i$. Thus we compute the new mean of $S_i$, $\\mu'_i$, and we check\nif $\\mu'_i = \\mu_i$. If this is the case for all $i$, we are finished, but if it is not, we\nmust undergo the hassle of reconstructing $S$, as a different partition will result for the\nnew means we've found. This process repeats and repeats and repeats until it reaches a stable\npoint, which we say is the kmeans clustering of the dataset according to our heuristic. It\nturns out this process works well if you choose the points right, and there are a variety of\nways to do this, so I've left this choice up to the user of the algorithm. In the test, I use\na simple uniform choice selection, which works decently well in practice but lacks some perks\nfor theory. This algorithm performs much more poorly than linear regression simply because of\nthe nature of the problem, and because I also wasn't able to delegate enough of this work to \nthe fast processes in hmatrix. I really want to give this another whack sometime and make it\nmuch more efficient. \n\n\\end{document}\n", "meta": {"hexsha": "6f712ddf7c4b2ccf53ac12ac3a140656100cca8e", "size": 4366, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "learning.tex", "max_stars_repo_name": "SamuelSchlesinger/learning", "max_stars_repo_head_hexsha": "c3f2fd2ed6a3699b836338c35814ef9a6cd1e676", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "learning.tex", "max_issues_repo_name": "SamuelSchlesinger/learning", "max_issues_repo_head_hexsha": "c3f2fd2ed6a3699b836338c35814ef9a6cd1e676", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "learning.tex", "max_forks_repo_name": "SamuelSchlesinger/learning", "max_forks_repo_head_hexsha": "c3f2fd2ed6a3699b836338c35814ef9a6cd1e676", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.5510204082, "max_line_length": 94, "alphanum_fraction": 0.7148419606, "num_tokens": 1273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7386856917560863}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: General Slicing}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises computing volume by cross-sectional area.\n\\end{abstract}\n\\maketitle\n\n\\begin{exercise}\nThe base of a solid region is bounded by the curves $x = 0$, $y = x^2$ and $y = x$. The cross sections perpendicular to the $x$-axis are squares. Compute the volume of the region.\n\\begin{itemize}\n\\item A typical square cross section has side length $L = \\answer{x - x^2}$ and area $A = \\answer{(x-x^2)^2}$. \n\\item Possible numerical values of the $x$-coordinates of points in the base range from a minimum value of $x = \\answer{0}$ up to a maximum of $x = \\answer{1}$.\n\\item To compute volume, integrate:\n\\[ V = \\int_{\\answer{0}}^{\\answer{1}} \\answer{(x-x^2)^2} d\\answer{x} = \\answer{\\frac{1}{30}}. \\]\n\\end{itemize}\n\\end{exercise}\n\n\\begin{exercise}\nFind the volume of the region in three-dimensional space defined by the inequalities\n\\begin{align*}\n0 & \\leq x \\leq 1, \\\\\n0 & \\leq y \\leq z^2, \\\\\n0 & \\leq z \\leq 3.\n\\end{align*}\n\\begin{itemize}\n\\item Cross sections perpendicular to the $z$-axis are \\wordChoice{\\choice{square}\\choice[correct]{rectangular}\\choice{triangluar}} with length $\\answer{1}$ in the $x$-direction and width $\\answer{z^2}$ in the $y$-direction.\n\\item The area of a $z$ cross section is $A(z) = \\answer{z^2}$.\n\\item To compute volume, integrate:\n\\[ V = \\int_{\\answer{0}}^{\\answer{3}} \\answer{z^2} dz = \\answer{9}. \\]\n\\end{itemize}\n\\end{exercise}\n\n\\begin{exercise}\nA right circular cylinder of radius $1$ and height $3$ is twisted along its axis so that the disk at height $z$ is centered on the axis $ x = \\cos (2 \\pi z/3), y = \\sin (2 \\pi z/3))$, which corresponds to one full twist along the axis. Compute the volume of this twisted cylinder.\n\\[ V = \\answer{3 \\pi}. \\]\n\\end{exercise}\n\n\\begin{exercise}\nA certain three-dimensional region has a base in the $xy$-plane which is bounded above by the graph $y = 1-x^2$ and below by $y=0$. Slices perpendicular to the $y$-axis are equilateral triangles whose base lies in the $xy$-plane as well. Compute the volume of the region.\n\\[ V = \\answer{\\frac{\\sqrt{3}}{2}}. \\]\n\\end{exercise}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}(2018 Midterm 1)\nCompute the volume of the region in 3-dimensional space which satisfies the inequalities\n\\begin{align*} \n0 \\leq   x \\leq (1 - z^2) \\qquad \\mbox{ and } \\qquad\n0 \\leq  y \\leq (1 + z^2) \\qquad \\mbox{ and } \\qquad \n0 \\leq z \\leq 1.\n\\end{align*}\n\\vspace{-12pt}\n\\begin{multipleChoice}\n\\choice{$\\displaystyle \\frac{2}{3}$}\n\\choice{$\\displaystyle \\frac{3}{4}$}\n\\choice[correct]{$\\displaystyle \\frac{4}{5}$}\n\\choice{$\\displaystyle \\frac{5}{6}$}\n\\choice{$\\displaystyle \\frac{6}{7}$}\n\\choice{none of these}\n\\end{multipleChoice}\n\\end{question}\n\n\\begin{question}(2019 Midterm 1)\nThe inequality \n\\[ \\frac{x^2}{a^2} + \\frac{y^2}{b^2} \\leq 1 \\]\ndefines an ellipse in the $xy$-plane whose area is $\\pi a b$ for any positive values of the constants $a$ and $b$.  Compute the three dimensional volume of the region defined by\n\\[ 4 x^2 + z^2 y^2 \\leq z^2 \\mbox{ for } 0 \\leq z \\leq 1. \\]\n(Hints won't reveal until after you choose a response.)\n\\begin{multipleChoice}\n\\choice{$\\displaystyle 4 \\pi z^2$}\n\\choice{$4 \\pi$}\n\\choice{$\\displaystyle \\frac{\\pi}{4z}$}\n\\choice[correct]{$\\displaystyle \\frac{\\pi}{4}$}\n\\choice{$\\displaystyle {\\pi z}$}\n\\choice{$\\displaystyle {\\pi}$}\n\\end{multipleChoice}\n\\begin{feedback}\nDividing the first inequality by $z^2$ on both sides gives\n\\[ \\frac{x^2}{\\frac{z^2}{4}} + \\frac{y^2}{1} \\leq 1, \\]\n\\begin{hint}\nwhich means that slices in the $z$-direction are ellipses with area $\\pi \\frac{z}{2} \\cdot 1 = \\frac{\\pi z}{2}$. \n\\begin{hint}\nVolume is obtained by integration:\n\\[ V = \\int_0^1 \\frac{\\pi z}{2} dz = \\left. \\frac{\\pi z^2}{4} \\right|_{0}^1 = \\frac{\\pi}{4}. \\]\n\\end{hint}\\end{hint}\n\\end{feedback}\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "1f605df461950f808f71f7ffd4b313d526b918f3", "size": 3905, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "volumes/01genslicepractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "volumes/01genslicepractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "volumes/01genslicepractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.1052631579, "max_line_length": 280, "alphanum_fraction": 0.680921895, "num_tokens": 1328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256591565729, "lm_q2_score": 0.8774767986961403, "lm_q1q2_score": 0.7386824844569777}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{titletoc}\n\\usepackage{titlesec}\n\\usepackage{geometry} \n\\usepackage{fontspec, xunicode, xltxtra}\n\\usepackage{float}\n\\usepackage{cite}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{listings}\n\\usepackage{titletoc}\n\\usepackage{bm}\n\n\\geometry{left=3cm,right=3cm,top=3cm,bottom=3cm}\n\\DeclareMathOperator*{\\argmin}{argmin}\n\\DeclareMathOperator*{\\argmax}{argmax}\n\\DeclareMathOperator*{\\var}{var}\n\\DeclareMathOperator*{\\expec}{E}\n\n\\begin{document}\n\\title{\\textsf{Homework 7 for Pattern Recognition}}\n\\author{Fan JIN\\quad (2015011506)}\n\\maketitle\n\n\\section*{Question 1}\n{\n    \\subsection*{Notations}\n    {\n        The multidimensional scaling (MDS) seeks to find a centered configuration $X = [x_1, \\cdots, x_n]$, \n        where $x_1, \\cdots, x_n \\in \\mathbb{R}^2$, \n        such that its distance matrix $\\hat{D} = (\\hat{d}_{ij}) \\approx D$ where $$\\hat{d}_{ij}^2 = (x_i - x_j)^T (x_i - x_j)$$ for $1 \\leq i \\leq n$ and $1 \\leq j \\leq n$.\n\n        Define the Gram matrix $$B = (b_{ij}) = X^T X,$$ \n        and it follows that $$\\hat{d}_{ij}^2 = x_i^T x_i + x_j^T x_j - 2 x_i^T x_j = b_{ii} + b_{jj} - 2 b_{ij}.$$\n\n        By algebra manipulations\\footnote{https://en.wikipedia.org/wiki/Multidimensional\\_scaling}, \n        we can express $b_{ij}$ in terms of $d_{ij}$:\n        $$\\hat{B} = -\\frac{1}{2} J \\hat{D} J,$$\n        where $$J = I_n - \\frac{1}{n} 1 \\cdot 1^T.$$\n\n        Thus, we take $B$ as an estimate of $\\hat{B}$, by reducing the dimension using the PCA approach. \n        Apply eigen decomposition and we obtain\n        $$B = V * D * V^T,$$ where the eigenvalues are sorted in descending order.\n        Retain the first two eigenvalues:\n        $$\\hat{B} = \\hat{V} * \\hat{D} * \\hat{V}^T,$$\n        where $\\hat{V}$ is the first two columns of $V$, and $\\hat{D}$ is the first two eigenvalues of the diagonal matrix $D$. Then, we have\n        $$X = \\hat{D}^{1/2} \\hat{V}^T$$ which satisfies $$B = X^T X.$$\n    }\n\n    \\subsection*{Visualization}\n    {\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 1\\linewidth]{Q1/result.png}\n            \\caption{Raw result}\n        \\end{figure}\n\n        To compare it with the actual satellite maps, we rotate it such that Zhengzhou is located roughly on the north of Wuhan.\n\n        We see the cities in main lines (e.g. Beijing, Zhengzhou, Wuhan) preserve their relative location better, compared to those in branch lines. \n        This is mainly because the linearity between distance and traveling duration differs in the railway level. For main line railways, the traveling duration is usually linear with the distance on map, for they have\n        \\begin{itemize}\n            \\item routemaps much more straightforward,\n            \\item fewer stops,\n            \\item faster train speed.\n        \\end{itemize}\n\n        It is noticed that the city Hanzhong seems like an outlier. This city, located in the middle of Mount Qinling and Mount Daba, was connected to other cities by a very slow branch line railway, before the construction of highspeed railways. This is why it is far away from other cities in the MDS map, although it is actually not so on the fringe.\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 1\\linewidth]{Q1/rotated.png}\n            \\includegraphics[width = 1\\linewidth]{Q1/map.jpg}\n            \\caption{Comparison}\n        \\end{figure}\n    }\n}\n\n\\section*{Question 2a}\n{\n    \\subsection*{PCA}\n    {\n        The PCA (principal component analysis) applies eigen decomposition to the covariance matrix (unnormalized) or correlation matrix (normalized) to the original data in $P$ dimensions, and only retains the first $p$ largest eigenvalues and their corresponding eigenvectors, which reconstructs the compressed data in $p$ dimensions. \n    }\n\n    \\subsection*{t-SNE}\n    {\n        The basic idea of t-SNE (t-distribution stochastic neighbor embedding) is to map the data to a probability distribution by affine transformation. \n\n        Given $N$ high dimensional objects $x_1, \\cdots, x_N$, the t-SNE algorithm first computes a conditional probability, \n        which indicates the dissimilarity between two objects, \n        $$p_{j|i} = \\frac{ \\exp{(- \\lVert x_i - x_j \\rVert^2 / 2\\sigma_i^2)} }{ \\sum_{k\\neq i} \\exp{(- \\lVert x_i - x_k \\rVert^2 / 2\\sigma_i^2)} },$$\n        where the bandwidth of the Gaussian kernels $\\sigma_i$ is set such that the perplexity of the conditional distribution equals a predefined perplexity. \n        This can be done using the bisection method. \\footnote{https://en.wikipedia.org/wiki/T-distributed\\_stochastic\\_neighbor\\_embedding}\n\n        Given the conditional distributions, the joint distribution of two objects is computed as follows.\n        $$p_{ij} = \\frac{ p_{j|i} + p_{i|j} }{2N}.$$\n\n        Unlike the classical SNE algorithm, the joint probabilities in low dimension space are computed in t-SNE using the t-distribution (heavy-tailed).\n        $$q_{ij} = \\frac{ (1 + \\lVert y_i - y_j \\rVert^2 )^{-1} }{ \\sum_{k\\neq i} (1 + \\lVert y_i - y_j \\rVert^2 )^{-1} }.$$\n\n        The final step is to train the low dimensional objects $y_1, \\cdots, y_N$ such that the KL distance below between the two distributions is minimized:\n        $$\\mathrm{KL}(P\\Vert Q) = \\sum_{i\\neq j} p_{ij} \\log{\\frac{p_{ij}}{q_{ij}}}.$$\n\n    }\n\n    \\subsection*{LLE}\n    {\n        The basic idea of LLE (locally linear embedding) is to map the data to a lower dimensional space while retaining the nonlinear manifold.\n        \\footnote{https://cs.nyu.edu/~roweis/lle/algorithm.html} \n        It hypothesize that each data point is a weighted linear combination of its neighboring objects, \n        and that such weights are shared in both original space and lower dimensional space. It consists of 3 steps:\n\n        \\begin{itemize}\n            \\item Calculate the $k$ nearest neighbors using KNN algorithms.\n\n            \\item Minimize the reconstruction loss\n            $$\\epsilon(W) = \\sum_{i}{ \\lVert X_i - \\sum_{j}{W_{ij} X_j} \\rVert ^2}$$\n            subject to $$\\sum_{j} {\\frac{ \\sum_k C_{jk}^{-1} }{ \\sum_{lm} C_{lm}^{-1} }} = 1$$\n            where the local convariance matrix $$C_{jk} = (x - \\eta_j)^T (x - \\eta_k)$$ with $\\eta$ is the nearest neighbors of $x$.\n        \\end{itemize}\n\n    }\n}\n\n\\section*{Question 2b}\n{\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.8\\linewidth]{Q2/t-SNE.png}\n        \\caption{2D mapped data by t-SNE}\n    \\end{figure}\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.8\\linewidth]{Q2/LLE_2.png}\n        \\caption{2D mapped data by LLE with k=2}\n    \\end{figure}\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.8\\linewidth]{Q2/LLE_3.png}\n        \\caption{2D mapped data by LLE with k=3}\n    \\end{figure}\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.8\\linewidth]{Q2/LLE_4.png}\n        \\caption{2D mapped data by LLE with k=4}\n    \\end{figure}\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.8\\linewidth]{Q2/LLE_5.png}\n        \\caption{2D mapped data by LLE with k=5}\n    \\end{figure}\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.8\\linewidth]{Q2/LLE_6.png}\n        \\caption{2D mapped data by LLE with k=6}\n    \\end{figure}\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.8\\linewidth]{Q2/LLE_8.png}\n        \\caption{2D mapped data by LLE with k=8}\n    \\end{figure}\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.8\\linewidth]{Q2/LLE_10.png}\n        \\caption{2D mapped data by LLE with k=10}\n    \\end{figure}\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.8\\linewidth]{Q2/LLE_12.png}\n        \\caption{2D mapped data by LLE with k=12}\n    \\end{figure}\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.8\\linewidth]{Q2/LLE_15.png}\n        \\caption{2D mapped data by LLE with k=15}\n    \\end{figure}\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.8\\linewidth]{Q2/LLE_20.png}\n        \\caption{2D mapped data by LLE with k=20}\n    \\end{figure}\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.8\\linewidth]{Q2/LLE_25.png}\n        \\caption{2D mapped data by LLE with k=25}\n    \\end{figure}\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.8\\linewidth]{Q2/LLE_30.png}\n        \\caption{2D mapped data by LLE with k=30}\n    \\end{figure}\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.8\\linewidth]{Q2/LLE_50.png}\n        \\caption{2D mapped data by LLE with k=50}\n    \\end{figure}\n}\n\n\\section*{Question 2c}\n{\n    According to the author\n    \\footnote\n    {\n        Once I have a t-SNE map, how can I embed incoming test points in that map? \\\\\n        t-SNE learns a non-parametric mapping, which means that it does not learn an explicit function that maps data from the input space to the map. \n        Therefore, it is not possible to embed test points in an existing map (although you could re-run t-SNE on the full dataset). \n        A potential approach to deal with this would be to train a multivariate regressor to predict the map location from the input data. \n        Alternatively, you could also make such a regressor minimize the t-SNE loss directly, which is what I did in this paper.\n    },\n    the incoming test points cannot be embedded in the t-SNE map. There are two workarounds.\n    \\begin{itemize}\n        \\item Re-run t-SNE on the full dataset. But the classifier we trained on training set would not work, since the re-run t-SNE map would differ from the previous one.\n        \\item Train a multivariate regressor to predict the map location.\n    \\end{itemize}\n\n    In this project, we choose the latter workaround. We use the KNN classifier provided by the Classification Learner Toolbox in MATLAB. \n    And we achieve a testing accuracy of 0.983051 in the reduced model in 2 dimensional space, while it is 0.947034 in the full model in 784 dimensional space. \n}\n\n\\section*{Question 2d}\n{\n    In section 2b, we experimented the t-SNE algorithm, and the LLE algorithm with various hypermaramter $k$s. \n\n    \\begin{itemize}\n        \\item The LLE requires a hyperparamter $k$, and the performance is quite sensitive to $k$. This means hypertuning is necessary, and a proper $k$ is crucial to the success.\n        However, the output is separable within a range from $k=8$ to $k=20$. Many hypervalues are available for the algorithm.\n        \n        \\item The t-SNE has no hyperparamters. But it has some weakness in that it is impossible to embed incoming test points to a pretrained map. \n        When a test point comes in, we have to re-train the model with the training set combined with the testing point, which is time consuming.\n    \\end{itemize}\n}\n\n\\section*{Question 3}\n{\n    \\begin{itemize}\n        \\item Classifier: Medium KNN (Classification Toolbox in MATLAB)\n        \\item Feature Selection by: KL Divergence\n        \\item Features to select from: 1000\n        \\item Validation: 10-fold\n        \\item Features to select: 20. We experimented from $p=2$ to $p=30$, and $p=20$ has the best performance in terms of validation accuracy.\n    \\end{itemize}\n\n    The features selected are\n    \\begin{table}[!hbp]\n        \\centering\n        \\begin{tabular}{|c|c|c|c|c|}\n        \\hline\n        361 & 425 & 662 & 166 & 219 \\\\\n        \\hline\n        329 & 592 & 957 & 663 & 804 \\\\\n        \\hline\n        542 & 817 & 395 & 281 & 778 \\\\\n        \\hline\n        720 & 626 & 206 & 844 & 48 \\\\\n        \\hline\n        \\end{tabular}\n        \\caption{Features selected}\n    \\end{table}\n\n    \\begin{table}[!hbp]\n        \\centering\n        \\begin{tabular}{|c|c|c|}\n        \\hline\n        & Full features & 20 selected features \\\\\n        \\hline\n        Validation accuracy & 0.697500 & 0.797500 \\\\\n        \\hline\n        \\end{tabular}\n        \\caption{Comparison with 10-fold}\n    \\end{table}\n\n    By feature selection with KL divergence, the accuracy of Medium KNN increases from 69.75\\% to 79.75\\%. What an improvement!\n}\n\n\\section*{Source Code}\n{\n    Please download the souece code from http://39.106.23.58/files/PR7\\_2015011506.7z\n\n    For Question 2, please cd into ``Q1'' directory and run ``main.m''. \n\n    For Question 2, please cd into ``Q2'' directory run ``main.m''. It may take \\emph{less than a minute} to train the network, but the result is reproducible because of the random seed.\n\n    For Question 3, please cd into ``Q3'' directory run ``main.m''.\n\n    For each model, I clicked ``Generate code'' button to transcript my operations into MATLAB codes, and stored each of them in the corresponding ``.m'' file. These files include:\n    \\begin{itemize}\n        \\item trainClassifierFull.m\n        \\item trainClassifierReduced.m\n    \\end{itemize}\n    Thus, the steps above can be easily reproduced without using the GUI of the toolbox. \n\n}\n\n\\clearpage\n\\end{document}\n    ", "meta": {"hexsha": "9f3781b9bdf8bbff35b49d8e3979641a4e76dbb8", "size": 13061, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW7/Homework7.tex", "max_stars_repo_name": "kingium/PatternRecognitionForUndergrads", "max_stars_repo_head_hexsha": "5cd08f3a260fae4a7edaf71599433e93484863b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW7/Homework7.tex", "max_issues_repo_name": "kingium/PatternRecognitionForUndergrads", "max_issues_repo_head_hexsha": "5cd08f3a260fae4a7edaf71599433e93484863b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW7/Homework7.tex", "max_forks_repo_name": "kingium/PatternRecognitionForUndergrads", "max_forks_repo_head_hexsha": "5cd08f3a260fae4a7edaf71599433e93484863b0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.9967845659, "max_line_length": 353, "alphanum_fraction": 0.6513283822, "num_tokens": 3768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256631249077, "lm_q2_score": 0.8774767906859264, "lm_q1q2_score": 0.7386824811958959}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{exercises}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 3.1 Some symmetries of Riemann}\n\n\\begin{cadabra}\n   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w#}::Indices(position=independent).\n\n   ;::Symbol;\n\n   \\partial{#}::PartialDerivative.\n\n   \\Gamma^{a}_{b c}::TableauSymmetry(shape={2}, indices={1,2}).\n\n   Rabcd := R^{a}_{b c d} ->   \\partial_{c}{\\Gamma^{a}_{b d}}\n                             - \\partial_{d}{\\Gamma^{a}_{b c}}\n                             + \\Gamma^{e}_{b d} \\Gamma^{a}_{c e}\n                             - \\Gamma^{e}_{b c} \\Gamma^{a}_{d e}.       # cdb(Rabcd.000,Rabcd)\n\n   dRabcd := R^{a}_{b c d ; e} -> \\partial_{e}{R^{a}_{b c d}}\n                                + \\Gamma^{a}_{f e} R^{f}_{b c d}\n                                - \\Gamma^{f}_{b e} R^{a}_{f c d}\n                                - \\Gamma^{f}_{c e} R^{a}_{b f d}\n                                - \\Gamma^{f}_{d e} R^{a}_{b c f}.       # cdb(dRabcd.000,dRabcd)\n\n\\end{cadabra}\n\n\\clearpage\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 3.1 Antisymmetry on last pair of indices}\n\n\\begin{cadabra}\n   expr := R^{a}_{b c d} + R^{a}_{b d c}.                               # cdb(ex-0301.101,expr)\n\n   substitute (expr, Rabcd)                                             # cdb(ex-0301.102,expr)\n\\end{cadabra}\n\n\\begin{dgroup*}[spread={3pt}]\n   \\Dmath*{\\cdb{ex-0301.101} = \\Cdb*{ex-0301.102}}\n\\end{dgroup*}\n\n\\clearpage\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 3.1 First Bianchi identity}\n\n\\begin{cadabra}\n   expr := R^{a}_{b c d} + R^{a}_{d b c} + R^{a}_{c d b}.               # cdb(ex-0301.201,expr)\n\n   substitute   (expr, Rabcd)                                           # cdb(ex-0301.202,expr)\n   canonicalise (expr)                                                  # cdb(ex-0301.203,expr)\n\\end{cadabra}\n\n\\begin{dgroup*}[spread={3pt}]\n   \\Dmath*{\\cdb{ex-0301.201} = \\Cdb*[\\hskip2.5cm\\hfill]{ex-0301.202}\n                             = \\Cdb*{ex-0301.203}}\n\\end{dgroup*}\n\n\\clearpage\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 3.1 Second Bianchi identity}\n\n\\begin{cadabra}\n   expr := R^{a}_{b c d ; e} + R^{a}_{b e c ; d} + R^{a}_{b d e ; c}.   # cdb(ex-0301.301,expr)\n\n   substitute     (expr, dRabcd)                                        # cdb(ex-0301.302,expr)\n   substitute     (expr,  Rabcd)                                        # cdb(ex-0301.303,expr)\n   distribute     (expr)                                                # cdb(ex-0301.304,expr)\n   product_rule   (expr)                                                # cdb(ex-0301.305,expr)\n   sort_product   (expr)                                                # cdb(ex-0301.306,expr)\n   rename_dummies (expr)                                                # cdb(ex-0301.307,expr)\n   canonicalise   (expr)                                                # cdb(ex-0301.308,expr)\n\\end{cadabra}\n\n\\begin{dgroup*}[spread={3pt}]\n   \\Dmath*{\\cdb{ex-0301.301} = \\Cdb*[\\hskip2.0cm\\hfill]{ex-0301.302}\n                             = \\Cdb*{ex-0301.303}\n                             = \\Cdb*{ex-0301.304}}\n\\end{dgroup*}\n\n\\clearpage\n\n\\begin{dgroup*}[spread={3pt}]\n   \\Dmath*{\\cdb{ex-0301.301} = \\Cdb*[\\hskip4.5cm\\hfill]{ex-0301.305}\n                             = \\Cdb*[\\hskip4.5cm\\hfill]{ex-0301.306}}\n\\end{dgroup*}\n\n\\clearpage\n\n\\begin{dgroup*}[spread={3pt}]\n   \\Dmath*{\\cdb{ex-0301.301} = \\Cdb*[\\hskip3.5cm\\hfill]{ex-0301.307}\n                             = \\Cdb*{ex-0301.308}}\n\\end{dgroup*}\n\n\\end{document}\n", "meta": {"hexsha": "ad686d07eac68df1f81baffe70c46d94457ae46d", "size": 3822, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/exercises/ex-0301.tex", "max_stars_repo_name": "leo-brewin/cadabra-tutorial", "max_stars_repo_head_hexsha": "5b428ae158b5346315ab6c975dee9de933e5c3d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2019-12-20T07:49:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T22:55:47.000Z", "max_issues_repo_path": "source/cadabra/exercises/ex-0301.tex", "max_issues_repo_name": "leo-brewin/cadabra-tutorial", "max_issues_repo_head_hexsha": "5b428ae158b5346315ab6c975dee9de933e5c3d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/cadabra/exercises/ex-0301.tex", "max_forks_repo_name": "leo-brewin/cadabra-tutorial", "max_forks_repo_head_hexsha": "5b428ae158b5346315ab6c975dee9de933e5c3d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-22T13:52:19.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-22T13:52:19.000Z", "avg_line_length": 37.1067961165, "max_line_length": 96, "alphanum_fraction": 0.4147043433, "num_tokens": 1152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7386824717057513}}
{"text": "\\title{Probabilistic PCA}\n\n\\subsection{Probabilistic PCA}\n\nProbabilistic principal components analysis (PCA) is a\ndimensionality reduction technique that\nanalyzes data via a lower dimensional latent space\n\\citep{tipping1999probabilistic}. It is often\nused when there are missing values in the data or for multidimensional\nscaling.\n\nWe demonstrate with an example in Edward.\nAn interactive version with Jupyter notebook is available\n\\href{http://nbviewer.jupyter.org/github/blei-lab/edward/blob/master/notebooks/probabilistic_pca.ipynb}{here}.\n\n\\subsubsection{Data}\n\nWe use simulated data. We'll talk about the individual variables and\nwhat they stand for in the next section. For this example, each data\npoint is 2-dimensional, $\\mathbf{x}_n\\in\\mathbb{R}^2$.\n\n\\begin{lstlisting}[language=Python]\ndef build_toy_dataset(N, D, K, sigma=1):\n  x_train = np.zeros((D, N))\n  w = np.random.normal(0.0, 2.0, size=(D, K))\n  z = np.random.normal(0.0, 1.0, size=(K, N))\n  mean = np.dot(w, z)\n  for d in range(D):\n    for n in range(N):\n      x_train[d, n] = np.random.normal(mean[d, n], sigma)\n\n  print(\"True principal axes:\")\n  print(w)\n  return x_train\n\nN = 5000  # number of data points\nD = 2  # data dimensionality\nK = 1  # latent dimensionality\n\nx_train = build_toy_dataset(N, D, K)\n\\end{lstlisting}\n\n\\begin{lstlisting}\n## True principal axes:\n## [[ 0.25947927]\n##  [ 1.80472372]]\n\\end{lstlisting}\n\nWe visualize the data set.\n\n\\begin{lstlisting}[language=Python]\nplt.scatter(x_train[0, :], x_train[1, :], color='blue', alpha=0.1)\nplt.axis([-10, 10, -10, 10])\nplt.title(\"Simulated data set\")\nplt.show()\n\\end{lstlisting}\n\n\\includegraphics[width=450px]{/images/probabilistic-pca-fig0.png}\n\n\\subsubsection{Model}\n\nConsider a data set $\\mathbf{X} = \\{\\mathbf{x}_n\\}$ of $N$ data\npoints, where each data point is $D$-dimensional, $\\mathbf{x}_n \\in\n\\mathbb{R}^D$. We aim to represent each $\\mathbf{x}_n$ under a latent\nvariable $\\mathbf{z}_n \\in \\mathbb{R}^K$ with lower dimension, $K <\nD$. The set of principal axes $\\mathbf{W}$ relates the latent variables to\nthe data.\n\nSpecifically, we assume that each latent variable is normally distributed,\n\\begin{equation*}\n\\mathbf{z}_n \\sim N(\\mathbf{0}, \\mathbf{I}).\n\\end{equation*}\nThe corresponding data point is generated via a projection,\n\\begin{equation*}\n\\mathbf{x}_n \\mid \\mathbf{z}_n\n\\sim N(\\mathbf{W}\\mathbf{z}_n, \\sigma^2\\mathbf{I}),\n\\end{equation*}\nwhere the matrix $\\mathbf{W}\\in\\mathbb{R}^{D\\times K}$ are known as\nthe principal axes. In probabilistic PCA, we are typically interested in\nestimating the principal axes $\\mathbf{W}$ and the noise term\n$\\sigma^2$.\n\nProbabilistic PCA generalizes classical PCA. Marginalizing out the the\nlatent variable, the distribution of each data point is\n\\begin{equation*}\n\\mathbf{x}_n \\sim N(\\mathbf{0}, \\mathbf{W}\\mathbf{W}^Y + \\sigma^2\\mathbf{I}).\n\\end{equation*}\nClassical PCA is the specific case of probabilistic PCA when the\ncovariance of the noise becomes infinitesimally small, $\\sigma^2 \\to\n0$.\n\nWe set up our model below. In our analysis, we fix $\\sigma=2.0$, and\ninstead of point estimating $\\mathbf{W}$ as a model parameter, we\nplace a prior over it in order to infer a distribution over principal\naxes.\n\n\\begin{lstlisting}[language=Python]\nfrom edward.models import Normal\n\nw = Normal(loc=tf.zeros([D, K]), scale=2.0 * tf.ones([D, K]))\nz = Normal(loc=tf.zeros([N, K]), scale=tf.ones([N, K]))\nx = Normal(loc=tf.matmul(w, z, transpose_b=True), scale=tf.ones([D, N]))\n\n\\end{lstlisting}\n\n\\subsubsection{Inference}\n\nThe posterior distribution over the principal axes $\\mathbf{W}$ cannot\nbe analytically determined. Below, we set up our inference variables\nand then run a chosen algorithm to infer $\\mathbf{W}$. Below we use\nvariational inference to minimize the $\\text{KL}(q\\|p)$ divergence\nmeasure.\n\n\\begin{lstlisting}[language=Python]\nqw = Normal(loc=tf.get_variable(\"qw/loc\", [D, K]),\n            scale=tf.nn.softplus(tf.get_variable(\"qw/scale\", [D, K])))\nqz = Normal(loc=tf.get_variable(\"qz/loc\", [N, K]),\n            scale=tf.nn.softplus(tf.get_variable(\"qz/scale\", [N, K])))\n\ninference = ed.KLqp({w: qw, z: qz}, data={x: x_train})\ninference.run(n_iter=500, n_print=100, n_samples=10)\n\\end{lstlisting}\n\n\\subsubsection{Criticism}\n\nTo check our inferences, we first inspect the model's learned\nprincipal axes.\n\n\\begin{lstlisting}[language=Python]\nsess = ed.get_session()\nprint(\"Inferred principal axes:\")\nprint(sess.run(qw.mean()))\n\\end{lstlisting}\n\n\\begin{lstlisting}\n## Inferred principal axes:\n## [[-0.24093632]\n##  [-1.76468039]]\n\\end{lstlisting}\n\nThe model has recovered the true principal axes up to finite data and\nalso up to identifiability (there's a symmetry in the\nparameterization).\n\nAnother way to criticize the model is to visualize the observed data\nagainst data generated from our fitted model.\n\n\\begin{lstlisting}[language=Python]\nx_post = ed.copy(x, {w: qw, z: qz})\nx_gen = sess.run(x_post)\n\nplt.scatter(x_gen[0, :], x_gen[1, :], color='red', alpha=0.1)\nplt.axis([-10, 10, -10, 10])\nplt.title(\"Data generated from model\")\nplt.show()\n\\end{lstlisting}\n\n\\includegraphics[width=450px]{/images/probabilistic-pca-fig1.png}\n\nThe generated data looks close to the true data.\n\n\\subsubsection{Acknowledgments}\n\nWe thank Mayank Agrawal for writing the initial version of this\ntutorial.\n\n\\subsubsection{References}\\label{references}\n", "meta": {"hexsha": "58e5ab937c4ccedb3684a60ae9b41daf386d1d35", "size": 5329, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tutorials/probabilistic-pca.tex", "max_stars_repo_name": "zhangyewu/edward", "max_stars_repo_head_hexsha": "8ec452eb0a3801df8bda984796034a9e945faec7", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5200, "max_stars_repo_stars_event_min_datetime": "2016-05-03T04:59:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T03:32:26.000Z", "max_issues_repo_path": "docs/tex/tutorials/probabilistic-pca.tex", "max_issues_repo_name": "zhangyewu/edward", "max_issues_repo_head_hexsha": "8ec452eb0a3801df8bda984796034a9e945faec7", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 724, "max_issues_repo_issues_event_min_datetime": "2016-05-04T09:04:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T02:41:12.000Z", "max_forks_repo_path": "docs/tex/tutorials/probabilistic-pca.tex", "max_forks_repo_name": "zhangyewu/edward", "max_forks_repo_head_hexsha": "8ec452eb0a3801df8bda984796034a9e945faec7", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1004, "max_forks_repo_forks_event_min_datetime": "2016-05-03T22:45:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T00:08:08.000Z", "avg_line_length": 31.7202380952, "max_line_length": 110, "alphanum_fraction": 0.7280915744, "num_tokens": 1589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7386824682236295}}
{"text": "\\section{Trim and linearisation}\n\n\\subsection{Trimming}\nThe first step when designing the control system of an aircraft is to study the behavior of the aircraft due to control inputs or external disturbances from an equilibrium condition. If the aircraft we're not to be in equilibrium, deviation from the initial conditions would occur that are unrelated to the control inputs making the analysis more difficult.\n\nIn the case of an aircraft this equilibrium condition is known as a trimmed flight condition. In order to determine the trimmed flight condition the states and inputs much be chosen such that the linear- and angular-accelerations are zero. For this assignment this is done by minimizing the following cost function.\n\n\\begin{equation}\n    \\label{eq:trim_cost}\n    cost = 5\\dot{h}^2 + \n           W_{\\phi}\\dot{\\phi}^2 +\n           W_{\\theta}\\dot{\\theta}^2 + \n           W_{\\psi}\\dot{\\psi}^2 +\n           2\\dot{V_{tot}}^2 + \n           10\\dot{\\alpha}^2 + \n           10\\dot{\\beta}^2 + \n           10\\dot{P}^2 +\n           10\\dot{Q}^2 +\n           10\\dot{R}^2\n\\end{equation}\n\nAll the flight states in the cost function are squared, which is what allows the trim condition to be found by minimizing it. Once the cost function returns zero, the trimmed flight condition states and inputs have been found.\n\nPerforming the trimming procedure for 5 iterations in level flight for both flight conditions and both the high and low fidelity models yields the following final values for the cost function.\n\n\\begin{center}\n    \\begin{tabular}{ r | c | c }\n                               & high fidelity & low fidelity \\\\ \\hline \\hline\n     Assigned flight condition & $0.0506$ & $4.2997\\cdot10^{-29}$ \\\\  \n     APA flight condition      & $7.1856\\cdot10^{-6}$ & $5.1572\\cdot10^{-29}$    \n    \\end{tabular}\n\\end{center}\n\nThe results for the low fidelity models are smaller than the machine epsilon $2.2204\\cdot10^{-16}$ of the computer used to calculate these, so it's safe to assume the trimmed flight condition has been successfully found. \n\nThe final costs for the high fidelity model are higher. The results for the APA flight conditions are in the order of $10^{-6}$ and for the assigned flight conditions in the order of $10^{-2}$. This indicates that the resulting state and inputs values are not perfect, but since the cost is close to zero, it may be close enough for further analysis.\n\n\n\\subsection{Accelerometer Position Analysis}\nNo changes are seen in the $A$ and $B$ matrix after adding the new vertical accelerometer output to the Simulink model. This is expected since the addition of the accelerometer output didn't change the dynamics of the aircraft. However the C and D matrices now have an extra row which corresponds to the new output. Equation~\\ref{eq:anss} shows the linearized output equation of the normal acceleration at the center of gravity ($x_a=0$).\n\n\\begin{equation}\n    \\label{eq:anss}\n    y = \\begin{bmatrix}\n        0 \\\\ 0 \\\\ -3.24322220018077e-05 \\\\ 0 \\\\ -9.67969758700180e-06 \\\\ 0 \\\\ \n        0.00398736185031356 \\\\ 9.92978181907083 \\\\ 0 \\\\ 0 \\\\ 0.966415396225217 \\\\ \n        0 \\\\ 0 \\\\ 0.0208407616972783 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0\n        \\end{bmatrix}^T x + \n        \\begin{bmatrix}\n        0 & 0 & 0 & 0\n    \\end{bmatrix} u\n\\end{equation}\n\nThe accelerometer output primarily depends on the velocity, angle of attack, pitch rate and the normal load factor. The altitude and pitch angle also have a minor contribution, however since these are small it could be caused by errors in the model or linearizion process. Equation~\\ref{eq:tf_el_an} shows the transfer function from the elevator to normal acceleration.\n\n\\begin{equation}\n    \\label{eq:tf_el_an}\n    \\frac{\n    \\begin{matrix}\n        0.421 s^{17} + 22.9 s^{16} + 404.6 s^{15} + 1728 s^{14} - 2.376e04 s^{13} - 3.177e05 s^{12} \\\\\n        - 1.64e06 s^{11} - 5.127e06 s^{10} - 1.168e07 s^{9} - 1.574e07 s^{8} - 7.901e06 s^{7} \\\\\n        - 5.914e04 s^{6} +  746.3 s^{5} + 4.87 s^{4} - 1.464e-11 s^{3}\n    \\end{matrix}\n    }{\n    \\begin{matrix}\n        s^{18} + 80.51 s^{17} + 2581 s^{16} + 4.234e04 s^{15} + 3.876e05 s^{14} + 2.115e06 s^{13} \\\\\n        + 7.644e06 s^{12} + 2.059e07 s^{11} + 3.952e07 s^{10} + 5.029e07 s^{9} + 4.057e07 s^{8} \\\\\n        + 1.553e07 s^{7} + 5.631e05 s^{6} + 1.073e05 s^{5} + 1159 s^{4} - 8.86e-11 s^{3}\n    \\end{matrix}\n    }\n\\end{equation}\n\nThe transfer function has a zero on the right hand side of the imaginary axis at $9.76+0j$. This zero is the one responsible for the non-minimum-phase behavior. The physical explanation of this is that a pitch up maneuverer with the elevator produces a downwards force which causes the aircraft to accelerate downwards. Eventually the angle of attack will increase as the nose pitches up and the extra lift will accelerate the aircraft upwards.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{figures/an_elev_step}\n    \\label{fig:an_elev_step}\n    \\caption{Normal acceleration after a negative step input on the elevator.}\n\\end{figure}\n\nRepeating the simulation for increasing values of $x_a$ shows that the zero moves away from the origin indicating that its influence becomes less dominant. When $x_a=5.9$ the zero has moved to the left side of the imaginary axis and the non-minimum-phase behavior disappears. Since the value of the zero much further to the left then the other zeros and poles, its motion is negligible. Increasing $x_a$ further moves the zero closer to origin and its motion reappears, this time in the direction of the reference signal.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{figures/an_elev_step_mult}\n    \\caption{Normal acceleration after a negative step input on the elevator for different values of $x_a=5.9$.}\n    \\label{fig:an_elev_step_mult}\n\\end{figure}\n\nOne property of the \\emph{instantaneous center of rotation} is that the linear accelerations at that point are the same as that of the overall aircraft. A point in front of it will accelerate upwards with a pitch up manoeuvre and a point behind it will accelerate downwards during the same manoeuvre. Thus based on the effects of moving $x_a$, it fair to conclude that the instantaneous center of rotation must be near $x=5.9$. Another way to arrive at the same conclusion is that the acceleration due to rotation is caused by the zero mentioned in the previous section since this is the only zero that changes significantly with $x_a$. Thus the instantaneous center of rotation will be at the location where this zero is infinitely far away from the origin.\n\nThe pilot should be placed at or after the instantaneous center of rotation ($x_a\\geq5.9\\ ft$), this is because if he is placed before, he will initially feel the aircraft moving into the opposite direction he is commanding it to and this might confuse the pilot resulting in him compensating for an error that is not there. This could make the combined human-aircraft system unstable or at least difficult to control.\n\nIt is important to place the accelerometer close a node of the most important fuselage bending moment. The reason is because, as the aircraft flies, loads and vibrations acting on the aircraft will make the fuselage bend. The nodes are locations where the displacements due to vibrations or bending are zero. Thus placing the accelerometer far away from a node, will result in the accelerometer measuring extra accelerations due to vibrations or bending. \n\n\n\\clearpage\n", "meta": {"hexsha": "144418f82c3317cd2a32c3560d1bf3036182884d", "size": 7459, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/1_trim_and_linearization.tex", "max_stars_repo_name": "aarondewindt/afcs_assignment", "max_stars_repo_head_hexsha": "ef8e368c9c81c3dcba4193bd2193a68d5e2bd2f6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/1_trim_and_linearization.tex", "max_issues_repo_name": "aarondewindt/afcs_assignment", "max_issues_repo_head_hexsha": "ef8e368c9c81c3dcba4193bd2193a68d5e2bd2f6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/1_trim_and_linearization.tex", "max_forks_repo_name": "aarondewindt/afcs_assignment", "max_forks_repo_head_hexsha": "ef8e368c9c81c3dcba4193bd2193a68d5e2bd2f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-04T15:55:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-04T15:55:23.000Z", "avg_line_length": 75.3434343434, "max_line_length": 758, "alphanum_fraction": 0.7246279662, "num_tokens": 1983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.8774767890838836, "lm_q1q2_score": 0.7386824519902802}}
{"text": "%!TEX root = head-full.tex\n\n\n%  On one hand, the development of the broadband services greatly\n% improves the user experience of \n\n\\section{Introduction} \\label{sec:introduction}\n\n\\para{Markov Chain}\nA Markov Chain is a special stochastic process in which the current state only depends on its previous state, we call this property the Markov property or memorylessness. i.e.\n\\begin{equation}\nP(X_{t+1}=x|X_t, X_{t-1}, \\cdots) =P(X_{t+1}=x|X_t)\n\\end{equation}\n\nGiven a Markov Chain, if a vector $\\pi$, has the property:\n\\begin{equation}\n\\pi=\\pi P\n\\end{equation}\nthen we call $\\pi$ the stationary distribution, it denotes the final state distribution of the stochastic process in a Markov Chain.\n\nMarkov Chain has a wide application in many fields in the real world, such as social science\\cite{acemoglu2011political}, econmics \\& finance\\cite{hamilton1989new} and of course, computer science\\cite{page1999pagerank}, etc.\n\n\\para{Markov Chain Monte Carlo}\nIf we are given a probability distribution $p(x)$, it would be a great thing if we could generate some samples of it by a simple method, so here comes the Markov Chain Monte Carlo(MCMC) method. If we could construct a Markov Chain which its stationary distribution $\\pi$ just equals to $p(x)$, then we could use this Markov Chain to sample from this distribution $p(x)$. And this is the main idea of MCMC.\n\nIn this paper, we implement the Metropolis-Hastings Algorithm\\cite{metropolis1953equation,hastings1970monte}, which is one of the most widely used sampling method. We also deal with the accepting rate, which I will introduce later, for previous work\\cite{roberts1997weak} have shown that the accepting rate may influence the result of the experiment and there is theoretical support in choosing an optimal accepting rate.\n\n\\para{Restricted Boltzmann Machine}\nA Restricted Bolztmann Machine (RBM)\\cite{mcclelland1987parallel} is a significant work bringing theory in statistical physics to computer science. By stacking several layers of RBM, we will get a fundamental model, Deep Belief Network\\cite{hinton2006reducing}, in the field of Deep Learning, which is nowadays the hottest class of algorithms used in Machine Learning.\n\n\\para{Estimating Partition functions} \nIn the process of training an RBM, however, will include incontractable computation of the partition function. When the model grows large, the complexity of this work will be incompletable. The good news is, researches have shown that there are ways to avoid this by using an MCMC approach instead, to estimate it.\n\nIn this paper, we implement three prevalent MCMC methods of estimating a partition function, Thouless-Anderson-Palmer Sampling(TAP)\\cite{gabrie2015training}, Annealed Importance Sampling (AIS)\\cite{neal2001annealed,salakhutdinov2009learning}, Rao-Blackwellized Tempered Sampling(RTS)\\cite{carlson2016partition}, respectively, and give an overall comparison on the theory \\& performance between them.\n\n\n\n\n", "meta": {"hexsha": "32aa32796b06f2b582dd2127c2803b57eda36206", "size": 2949, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/Introduction.tex", "max_stars_repo_name": "lzhbrian/MCMC", "max_stars_repo_head_hexsha": "0dd3aadd1ed2833aff76bd7af4b014282739984b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-09-10T04:42:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-21T16:07:29.000Z", "max_issues_repo_path": "tex/Introduction.tex", "max_issues_repo_name": "lzhbrian/MCMC", "max_issues_repo_head_hexsha": "0dd3aadd1ed2833aff76bd7af4b014282739984b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/Introduction.tex", "max_forks_repo_name": "lzhbrian/MCMC", "max_forks_repo_head_hexsha": "0dd3aadd1ed2833aff76bd7af4b014282739984b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-03-03T17:34:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-24T10:54:53.000Z", "avg_line_length": 75.6153846154, "max_line_length": 421, "alphanum_fraction": 0.7972193964, "num_tokens": 722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357632379241, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7386735527859901}}
{"text": "\\chapter{BSS}\n\n\n\\section{Mixing and demixing}\n\nThe two sources are mixed as follows:\n\\begin{align}\n  y_1(t) & = s_1(t) + s_2(t) \\\\\n  y_2(t) & = s_1(t+\\delta_1) + s_2(t+\\delta_2)\n\\end{align}\nwhere $\\delta_1$ and $\\delta_2$ are delays that depend on the distance\nbetween the microphones and the directions of the sources.\n\n\nIn the frequency domain:\n\\begin{align}\n  Y_1(\\omega) & = S_1(\\omega) + S_2(\\omega) \\\\\n  Y_2(\\omega) & = e^{-\\omega\\delta_1}S_1(\\omega) + e^{-\\omega\\delta_2}S_2(\\omega)\n\\end{align}\n\nThis is a scalar mixture! So we can just do PCA and we are done. Not\nso fast. There is a permutation problem. There is no guarantee that\nsignal 1 will appear on ouput channel 1, or signal 2 on output channel\n2. If we were to apply PCA to all the different frequencies then we\nwould still have the problem of determining which output should be on\nwhich channel. If there are $N$ different frequencies then there will\nbe $2^N$ different possibilities to choose from.\n\nIn radar, there is only one frequency so this doesn't matter so we can\nuse PCA. Speech is broadband. We need a different approach.\n\nLet us write the delay operation as follows:\n\\begin{align}\n  z_1 & =  e^{-\\omega\\delta_1}\\\\\n  z_2 & =  e^{-\\omega\\delta_2}\n\\end{align}\n\nWe can write the mixing process as:\n\\begin{equation}\n  \\begin{bmatrix}\n    Y_1(\\omega)\\\\\n    Y_2(\\omega)\n  \\end{bmatrix}\n  =\n  \\begin{bmatrix}\n  1 & 1\\\\\n  z_1 & z_2\n  \\end{bmatrix}\n  \\begin{bmatrix}\n  S_1(\\omega)\\\\\n  S_2(\\omega)\n    \\end{bmatrix}\n\\end{equation}\n\nThe inverse is\n\\begin{equation}\n  \\begin{bmatrix}\n    S_1(\\omega)\\\\\n    S_2(\\omega)\n  \\end{bmatrix}\n  =\n  \\frac{1}{z_2-z_1}\n  \\begin{bmatrix}\n  z_2 & -1\\\\\n  -z_1 & 1\n  \\end{bmatrix}\n  \\begin{bmatrix}\n  Y_1(\\omega)\\\\\n  Y_2(\\omega)\n    \\end{bmatrix}\n \\end{equation}   \n\nWe are going to ignore the determinant term because of the possibility of dividing by zero (or by some number close to zero).\n\n\\begin{equation}\n  \\begin{bmatrix}\n    X_1(\\omega)\\\\\n    X_2(\\omega)\n  \\end{bmatrix}\n  =\n  \\begin{bmatrix}\n  z_2 & -1\\\\\n  -z_1 & 1\n  \\end{bmatrix}\n  \\begin{bmatrix}\n  Y_1(\\omega)\\\\\n  Y_2(\\omega)\n    \\end{bmatrix}\n \\end{equation}   \n\n\nSo, if we could just find $\\delta_1$ and $\\delta_2$, we would demix as follows:\n\\begin{align}\n  x_1(t) & = y_1(t+\\delta_2) - y_2(t) \\\\\n  x_2(t) & = -y_1(t+\\delta_1) + y_2(t)\n\\end{align}\n\n\n\\section{The cost function}\n\nWe know that $x_1(t)$ and $x_2(t)$ are uncorrelated. That means that\nwe should find $\\delta_1$ and $\\delta_2$ that minimize the correlation\nbetween $x_1(t)$ and $x_2(t)$.\n\nJumping back into the frequency domain, we need to minimize the\nmagnitude of $X_1(\\omega) \\overline{X_2(\\omega)}$. We take the complex\nconjugate because this is not a convolution - it's a correlation:\n\\begin{align}\n  X_1(\\omega) \\overline{X_2(\\omega)} & = \\left(z_2 Y_1(\\omega) - Y_2(\\omega)\\right) \\overline{\\left(-z_1 Y_1(\\omega) + Y_2(\\omega)\\right) }\\\\\n  & = -z_2 \\overline{z_1} Y_1 \\overline{Y_1} + z_2 Y_1 \\overline{Y_2} + \\overline{z_1} Y_2 \\overline{Y_1} - Y_2 \\overline{Y_2}\n\\end{align}\n\nWe sum the square of the magnitude of $X_1(\\omega)\n\\overline{X_2(\\omega)}$ over all frequencies and call that the cost\nfunction.  Summing the square of the magnitude has another\nadvantage. According to Parseval's Theorem, the cost function is\nidentical to the sum of the squares of the cross correlations between\n$x_1(t)$ and $x_2(t)$ in the time domain. This is a nice result\nbecause the time domain justification for this cost function is easy\nto understand.\n\n\n\\subsection{Cost function details}\n\nAs always, the devil is in the details:\n\n\\begin{itemize}\n\n\\item The cost function is multimodal. That's a bad thing if we are\n  using a standard optimization routine because, depending on starting\n  position, it might not find the best solution at the global\n  minimum. Beware the local minimum. To mitigate against this, we do a coarse\n  grid search first. And then use an optimizer to clean up the answer.\n\n\n\\item We take the logarithm of the sum of squares. This is done for the sake of numerical stability because the cost function changes very quickly.\n\n  \\item Note that only $z_1$ and $z_2$ are functions of $\\delta_1$ and $\\delta_2$. We can precompute auto- and cross-correlations of  $Y_1 \\overline{Y_1}$, $Y_1 \\overline{Y_2}$, $Y_2 \\overline{Y_1}$, and $Y_2 \\overline{Y_2}$ in advance to save computation.\n\n\n\\end{itemize}\n\n\n\n", "meta": {"hexsha": "a996508fd0dfc373671f41465132f051d699d283", "size": 4349, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PYTHON/scripts/bss/bss.tex", "max_stars_repo_name": "oruanaidh-ai/wayback_machine", "max_stars_repo_head_hexsha": "2529fc9e18120a092890abbb94483f643682fb90", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "PYTHON/scripts/bss/bss.tex", "max_issues_repo_name": "oruanaidh-ai/wayback_machine", "max_issues_repo_head_hexsha": "2529fc9e18120a092890abbb94483f643682fb90", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PYTHON/scripts/bss/bss.tex", "max_forks_repo_name": "oruanaidh-ai/wayback_machine", "max_forks_repo_head_hexsha": "2529fc9e18120a092890abbb94483f643682fb90", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.9931034483, "max_line_length": 256, "alphanum_fraction": 0.7010807082, "num_tokens": 1459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.8670357735451835, "lm_q1q2_score": 0.7386735501603029}}
{"text": "\\subsection{Monte Carlo method}\nThere are complex problems in a variety of research fields which could take up years or even centuries to compute with simple deterministic methods. For some problems there is an algorithmic solution which makes it possible to cut down computation time significantly, but when no deterministic algorithm is available to speed up the process an empirical probabilistic method might be able to approximate the desired results. \n\nWith the Monte Carlo method random samples are taken from the parameter space ,that describe a data set, and fed into a model which produces a potential outcome. By repeating the process more results are generated until at some point the data can display a pattern that describes the outcome. The result is a quantified probability which describes the chance that something might occur based on the quantity of occurrence generated by the model \\cite{stephanie_monte_2015,wikipedia_monte_2019,wikipedia_monte-carlosimulatie_2018}.\n%Monte Carlo Simulation / Method, Stephanie\n%Monte Carlo method, Wikipedia\n%Monte-Carlosimulatie, Wikipedia\n\\newline\n\\newline\nThe Monte Carlo methods can differ depending on the algorithm and application in which it is used, but in summary most implementations will follow a general pattern \\cite{wikipedia_monte_2019}.\n%Monte Carlo method, Wikipedia\n\\begin{enumerate}\n\t\\setcounter{enumi}{-1}\n\t\\item Construct a model which is able to describe an outcome of the problem.\n\t\\item Define the space of which inputs can be used by the model to get an outcome (creating a parameter space). \n\t\\item Use the model to generate results based on random sampled input from the parameter space.\n\t\\item Order and determine which results are part of a certain outcome and draw conclusions on the generated statistical evidence.\n\\end{enumerate}\n\n\\label{subsec:Monte_Carlo_Method}\n\n\\subsection{The use of the Monte Carlo method and its pitfalls}\nThet MOnte Carlo method is widely used within various applications in different fields of science but is suitable for problems. Where all inputs are known but it is too inefficient to compute the problem with a deterministic method. Problems that require uncertainty to be incorporated into the analysis or prediction and is suitable for discovering new parameters in a model to improve the current model. Monte Carlo is not good at solving problems where answers are known but the inputs are not and in solving problems where no uncertainty should be in the answer produced.\n\nAll  mentioned  problems it can solve all tend to rely on significant quantities of data which makes it a relative time consuming process for generating results. Meaning of the generated result is highly depended on the model and random sampling technique that is used and both contribute to biases in the results \\cite{stephanie_monte_2015,wikipedia_monte_2019,alon_honig_introduction_nodate}.\n%Monte Carlo Simulation / Method, Stephanie\n%Monte Carlo method, Wikipedia\n%Introduction to Monte Carlo Methods, Alon Honig", "meta": {"hexsha": "fcdbe2eca0357f64d2e8802c2e98ed4b74498373", "size": 3014, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/Chapters/Monte_Carlo.tex", "max_stars_repo_name": "Sylt-CSI/variant-protein-prediction", "max_stars_repo_head_hexsha": "2a4451636907e7c54b58c648893b7d92167d1f7e", "max_stars_repo_licenses": ["Python-2.0", "OLDAP-2.7"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Report/Chapters/Monte_Carlo.tex", "max_issues_repo_name": "Sylt-CSI/variant-protein-prediction", "max_issues_repo_head_hexsha": "2a4451636907e7c54b58c648893b7d92167d1f7e", "max_issues_repo_licenses": ["Python-2.0", "OLDAP-2.7"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/Chapters/Monte_Carlo.tex", "max_forks_repo_name": "Sylt-CSI/variant-protein-prediction", "max_forks_repo_head_hexsha": "2a4451636907e7c54b58c648893b7d92167d1f7e", "max_forks_repo_licenses": ["Python-2.0", "OLDAP-2.7"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 107.6428571429, "max_line_length": 575, "alphanum_fraction": 0.8231585932, "num_tokens": 618, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.8670357649558006, "lm_q1q2_score": 0.7386735395834153}}
{"text": "\\section{Graphs}\n\n\\begin{code}{Topological Sort}{$\\mathcal{O}(|V| + |E|)$}{graphs/topoSort.cc}\n  A priority queue can be used if further sorting is necessary.\n\\end{code}\n\n\n\\lst{SCC Tarjan}{$\\mathcal{O}(|V| + |E|)$}{graphs/scc.cc}\n\\lst{Articulation Points}{$\\mathcal{O}(| V | + | E |)$}{graphs/articulationPoints.cc}\n\\lst{Bridges}{$\\mathcal{O}(|V|+|E|)$}{graphs/bridges.cc}\n\n\n\\lst{Minimal Spanning Tree -- Kruskal}{$\\mathcal{O}(|E|\\log|V|)$}{graphs/kruskal.cc}\n\n\\subsection{Shortest Paths}\n\n\\lst{Dijkstra}{$\\mathcal((|E| + |V|)\\log|V|)$}{graphs/dijkstra.cc}\n\n\\begin{code}{Bellman Ford}{$\\mathcal{O}(|E||V|)$}{graphs/bellmanFord.cc}\n\tCheck for negative cycles: \\\\\n\t$dist$ still changes in a $\\lvert V \\rvert$'th relaxation step with $dist_i = 0$ initially for all $i$.\n\\end{code}\n\n\\begin{code}{Bellman Ford with Queue}{$\\mathcal{O}(|E||V|)$}{graphs/bellmanFordQueue.cc}\n  This approach may be faster\n\\end{code}\n\n\\lst{Floyd Warshall}{$\\mathcal{O}(|V|^3)$}{graphs/floydWarshall.cc}\n\n\\subsection{Forest}\n\\lst{Lowest Common Ancestor}{build: $\\mathcal{O}(|V| \\log|V|)$ query: $\\mathcal{O}(1)$}{graphs/LCA.cc}\n\\lst{LCA with binary lifting}{build: $\\mathcal{O}(|V|\\log |V|)$ query: $\\mathcal{O}(\\log|V|)$}{graphs/LCABL.cc}\n\n\\lst{Heavy-light decomposition}{build: $\\mathcal{O}(|V|)$, query/update: $\\mathcal{O}(\\log^2|V|)$/$\\mathcal{O}(\\log|V|)$}{graphs/HLD.cc}\n\n\n\\subsection{Flow}\n\n\\textbf{Max-flow min-cut theorem.} The maximum value of an $s$-$t$ flow is\nequal to the minimum capacity over all $s$-$t$ cuts\n\n\\lst{Edges for flow algorithms}{}{graphs/flowedge.cc}\n\\lst{Edmonds Karp}{$\\mathcal{O}(|V||E|^2)$}{graphs/edmondsKarp.cc}\n\\lst{Dinic}{$\\mathcal{O}(|V|^2|E|)$}{graphs/dinic.cc}\n\\lst{Push Relabel}{$\\mathcal{O}(|V|^3)$}{graphs/pushRelabel.cc}\n\n\\subsubsection{Minimum s-t cut}\n\nTo find a minimal $s$-$t$ cut find all nodes that are reachable in the\nresidual network for a network w/ maximum flow from $s$.  This is the\n$s$ part of the cut.  All other nodes belong to the $t$ part.\n\n\\subsubsection{Closure Problem}\n\nA closure of a directed graph is a set of vertices with no outgoing\nedges.  The closure problem is the task to find the maximum weighted\nclosure.  Solvable through reduction to a maximum flow problem: Add\nsource and target, connect all the vertices with positive weight $w$\nto the source with capacity $w$ and connect all the vertices with\nnegative weight $w$ to the target with capacity $-w$.  All of the\nedges in the original graph have infinite capacity in the new\ngraph.  The weight of the maximum weighted closure is equal to the sum\nof all positive weighted vertices in the original graph minus the\nmaximum flow in the constructed graph.\n\n", "meta": {"hexsha": "cd5f77d293ec07d708d89e06d1eca56b76b7718e", "size": 2656, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "document/graphs.tex", "max_stars_repo_name": "Zeldacrafter/CompProg", "max_stars_repo_head_hexsha": "5367583f45b6fe30c4c84f3ae81accf14f8f7fd3", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-02-06T15:44:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-21T03:51:21.000Z", "max_issues_repo_path": "document/graphs.tex", "max_issues_repo_name": "Zeldacrafter/CompProg", "max_issues_repo_head_hexsha": "5367583f45b6fe30c4c84f3ae81accf14f8f7fd3", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "document/graphs.tex", "max_forks_repo_name": "Zeldacrafter/CompProg", "max_forks_repo_head_hexsha": "5367583f45b6fe30c4c84f3ae81accf14f8f7fd3", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.2424242424, "max_line_length": 136, "alphanum_fraction": 0.7044427711, "num_tokens": 862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706048, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.7386327820833475}}
{"text": "\\chapter{Boolean Functions}\\label{ch04}\n\\section{Introduction to Boolean Functions}\n\nBefore starting a study of Boolean functions, it is important to keep in mind that this mathematical system concerns electronic components that are capable of only two states: \\emph{True} and \\emph{False} (sometimes called \\emph{High-Low} or $ 1 $ - $ 0 $). Boolean functions are based on evaluating a series of \\emph{\\emph{True}-\\emph{False}} statements to determine the output of a circuit.\n\nFor example, a Boolean expression could be created that would describe ``If the floor is dirty OR company is coming THEN I will mop.'' (The things that I do for visiting company!) These types of logic statements are often represented symbolically using the symbols $ 1 $ and $ 0 $, where $ 1 $ stands for \\emph{True} and $ 0 $ stands for \\emph{False}. So, let ``Floor is dirty'' equal $ 1 $ and ``Floor is not dirty'' equal $ 0 $. Also, let ``Company is coming'' equal $ 1 $ and ``Company is not coming'' equal $ 0 $. Then, ``Floor is dirty OR company is coming'' can be symbolically represented by $ 1 $ \\textsf{OR} $ 1 $. Within the discipline of Boolean algebra, common mathematical symbols are used to represent Boolean expressions; for example, Boolean \\textsf{OR} is frequently represented by a mathematics plus sign, as shown below. \n\n% Using + to represent OR\n\\begin{align}\n  \\label{04eq01}\n  0 + 0 &= 0 \\\\\n  \\nonumber\n  0 + 1 &= 1 \\\\\n  \\nonumber\n  1 + 0 &= 1 \\\\\n  \\nonumber\n  1 + 1 &= 1\n\\end{align}\n\nThese look like addition problems, but they are not (as evidenced by the last line). It is essential to keep in mind that these are merely symbolic representations of \\emph{True}-\\emph{False} statements. The first three lines make perfect sense and look like elementary addition. The last line, though, violates the principles of addition for real numbers; but it is a perfectly valid Boolean expression. Remember, in the world of Boolean algebra, there are only two possible values for any quantity: $ 1 $ or $ 0 $; and that last line is actually saying \\emph{True \\textsf{OR} True is True}. To use the dirty floor example from above, ``The floor is dirty'' (\\emph{True}) OR ``Company is coming'' (\\emph{True}) SO ``I will mop the floor'' (\\emph{True}) is symbolized by: $ 1 + 1 = 1 $. This could be expressed as \\emph{T \\textsf{OR} T SO T}; but the convention is to use common mathematical symbols; thus: $ 1 + 1 = 1 $. \n\nMoreover, it does not matter how many or few terms are \\textsf{OR} ed together; if just one is \\emph{True}, then the output is \\emph{True}, as illustrated below:\n\n\\begin{align}\n  \\label{04eq02}\n  1 + 1 + 1 &= 1 \\\\\n  \\nonumber\n  1 + 0 + 0 + 0 + 0 &= 1 \\\\\n  \\nonumber\n  1 + 1 + 1 + 1 + 1 + 1 &= 1\n\\end{align}\n\nNext, consider a very simple electronic sensor in an automobile: IF the headlights are on AND the driver's door is open THEN a buzzer will sound. In the same way that the plus sign is used to mathematically represent \\textsf{OR} , a times sign is used to represent \\textsf{AND} . Therefore, using common mathematical symbols, this automobile alarm circuit would be represented by $ 1 X 1 = 1 $. The following list shows all possible states of the headlights and door:\n\n% Using X to represent AND\n\\begin{align}\n  \\label{04eq03}\n  0 X 0 &= 0 \\\\\n  \\nonumber\n  0 X 1 &= 0 \\\\\n  \\nonumber\n  1 X 0 &= 0 \\\\\n  \\nonumber\n  1 X 1 &= 1\n\\end{align}\n\nThe first row above shows ``\\emph{False} (the lights are not on) AND \\emph{False} (the door is not open) results in \\emph{False} (the alarm does not sound)''. For \\textsf{AND}  logic, the only time the output is \\emph{True} is when all inputs are also \\emph{True}; therefore: $ 1 X 1 X 1 X 1 X 0 = 0 $. In this way, Boolean \\textsf{AND}  behaves somewhat like algebraic multiplication.\n\nWithin Boolean algebra's simple \\emph{True}-\\emph{False} system, there is no equivalent for subtraction or division, so those mathematical symbols are not used. Like real-number algebra, Boolean algebra uses alphabetical letters to denote variables; however, Boolean variables are always CAPITAL letters, never lower-case, and normally only a single letter. Thus, a Boolean equation would look something like this:\n\n\\begin{align}\n  \\label{04eq04}\n  A + B &= Y \n\\end{align}\n\nAs Boolean expressions are realized (that is, turned into a real, or physical, circuit), the various operators become \\emph{gates}. For example, the above equation would be realized using an \\textsf{OR}  gate with two inputs (labeled $ A $ and $ B $) and one output (labeled $ Y $). \n\nBoolean algebra includes three primary and four secondary logic operations (plus a Buffer, which has no logic value), six univariate, and six multivariate properties. All of these will be explored in this chapter.\n\n\\section{Primary Logic Operations}\\label{0401}\n\\subsection{AND}\n\nAn \\textsf{AND}  gate is a Boolean operation that will output a logical one, or \\emph{True}, only if all of the inputs are \\emph{True}. As an example, consider this statement: ``If I have ten bucks AND there is a good movie at the cinema, then I will go see the movie.'' In this statement, ``If I have ten bucks'' is one variable and ``there is a good movie at the cinema'' is another variable. If both of these inputs are \\emph{True}, then the output variable (``I will go see the movie'') will also be \\emph{True}. However, if either of the two inputs is \\emph{False}, then the output will also be \\emph{False} (or, ``I will not go see the movie''). Of course, if I want popcorn, I would need another ten spot, but that is not germane to this example. When written in an equation, the Boolean \\textsf{AND}  term is represented a number of different ways. One method is to use the logic \\textsf{AND} symbol as found in Equation \\ref{BF:eq:and_symbol_logical}.\n\n\\begin{align}\n  \\label{04eq05}\n  A \\wedge B &= Y \n\\end{align}\n\nOne other method is to use the same symbols that are used for multiplication in traditional algebra; that is, by writing the variables next to each other, with parenthesis, or, sometimes, with an asterisk between them, as in Equation \\ref{04eq06}.\n\n% Using X to represent AND\n\\begin{align}\n  \\label{04eq06}\n  AB &= Y \\\\\n  \\nonumber\n  (A)(B) &= Y \\\\\n  \\nonumber\n  A * B &= Y\n\\end{align}\n\n\\marginpar{The multiplication symbols $ X $ and $\\bullet$ (dot) are not commonly used in digital logic equations.} Logic \\textsf{AND} is normally represented in equations by using an algebra multiplication symbol since it is easy to type; however, if there is any chance for ambiguity, then the Logic \\textsf{AND}  symbol ($ \\wedge $) can be used to differentiate between multiplication and a logic \\textsf{AND}  function.\n\nFollowing is the truth table for the \\textsf{AND}  operator.\n\n%******************************************************\n% AND Truth Table\n%******************************************************\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ccc} \n      \\rowcolor{black!75}\n      \\multicolumn{2}{c}{\\head{Inputs}} & \\head{Output} \\\\\n      A & B & Y \\\\\n      \\hline\n      0 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      1 & 0 & 0 \\\\\n      1 & 1 & 1 \n    \\end{tabular}\n  \\end{center}\n  \\caption{Truth Table for AND}\n  \\label{04tt01}\n\\end{table}\n\nA truth table is used to record all possible inputs and the output for each combination of inputs. For example, in the first line of Table \\ref{04tt01}, if input $ A $ is $ 0 $ and input $ B $ is $ 0 $ then the output, $ Y $, will be $ 0 $. All possible input combinations are normally formed in a truth table by counting in binary starting with all variables having a $ 0 $ value to all variables having a $ 1 $ value. Thus, in Table \\ref{04tt01}, the inputs are $ 00 $, $ 01$, $ 10$, $ 11 $. Notice that the output for the \\textsf{AND}  operator is \\emph{False} (that is, $ 0 $) until the last row, when both inputs are \\emph{True}. Therefore, it could be said that just one \\emph{False} input would inactivate a physical \\textsf{AND}  gate. For that reason, an \\textsf{AND}  operation is sometimes called an \\emph{inhibitor}.\n\n% Begin Sidebar Box\n\\begin{tcolorbox}[colback=blue!5!white,colframe=blue!75!black]\n  % Upper half of box: my \"title\" area\n  \\textcolor{blue}{\\textbf{AND Gate Switches}}\n  % Lower half of the box: the content\n  \\tcblower\n  Because a single \\emph{False} input can turn an \\textsf{AND} gate off, these types of gates are frequently used as a switch in a logic circuit. As a simple example, imagine an assembly line where there are four different safety sensors of some sort. The sensor outputs could be routed to a single four-input \\textsf{AND}  gate and then as long as all sensors are \\emph{True} the assembly line motor will run. If, however, any one of those sensors goes \\emph{False} due to some unsafe condition, then the \\textsf{AND}  gate would also output a \\emph{False} and cause the motor to stop.\n\\end{tcolorbox}\n% End Sidebar Box\n\nLogic gates are realized (or created) in electronic circuits by using transistors, resistors, and other components. These components are normally packaged into a single \\ac{IC} ``chip,'' so the logic circuit designer does not need to know all of the details of the electronics in order to use the gate. In logic diagrams, an \\textsf{AND}  gate is represented by a shape that looks like a capital \\textsf{D}. In Figure \\ref{fig:04_01}, the input variables $ A $ and $ B $ are wired to an \\textsf{AND}  gate and the output from that gate goes to $ Y $.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_01}\n\t\\caption{AND Gate}\n\t\\label{fig:04_01}\n\\end{figure}\n\nNotice that each input and output is named in order to make it easier to describe the circuit algebraically. In reality, \\textsf{AND}  gates are not packaged or sold one at a time; rather, several would be placed on a single \\ac{IC}, like the \\emph{7408 Quad AND Gate}. The designer would design the circuit card to use whichever of the four gates are needed while leaving the unused gates unconnected. \n\nThere are two common sets of symbols used to represent the various elements in logic diagrams, and whichever is used is of little consequence since the logic is the same. Shaped symbols, as used in Figure \\ref{fig:04_01}, are more common in the United States; but the \\ac{IEEE} has its own symbols which are sometimes used, especially in Europe. Figure \\ref{fig:04_02} illustrates the circuit in Figure \\ref{fig:04_01} using \\ac{IEEE} symbols:\n\n% Pull Quote - Marginal Note - Sidebar\n\\marginpar{In this book, only shaped symbols will be used.}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_02}\n\t\\caption{AND Gate Using IEEE Symbols}\n\t\\label{fig:04_02}\n\\end{figure}\n\nAs an example of an \\textsf{AND}  gate at work, consider an elevator: if the door is closed (logic $ 1 $) \\textsf{AND} someone in the elevator car presses a floor button (logic $ 1 $), THEN the elevator will move (logic $ 1 $). If both sensors (door and button) are input to an \\textsf{AND}  gate, then the elevator motor will only operate if the door is closed \\textsf{AND}  someone presses a floor button. \n\n\\subsection{OR}\n\\label{BF:subsec:or}\n\nAn \\textsf{OR}  gate is a Boolean operation that will output a logical one, or \\emph{True}, if any or all of the inputs are \\emph{True}. As an example, consider this statement: ``If my dog needs a bath OR I am going swimming, then I will put on a bathing suit.'' In this statement, ``if my dog needs a bath'' is one input variable and ``I am going swimming'' is another input variable. If either of these is \\emph{True}, then the output variable, ``I will put on a bathing suit,'' will also be \\emph{True}. However, if both of the inputs are \\emph{False}, then the output will also be \\emph{False} (or, ``I will not put on a bathing suit''). If you think it odd that I would wear a bathing suit to bathe my dog then you have obviously never met my dog. \n\nWhen written in an equation, the Boolean \\textsf{OR}  term is represented a number of different ways. One method is to use the logic \\textsf{OR}  symbol, as found in Equation \\ref{BF:eq:or_vee}.\n\n\\begin{align}\n  \\label{BF:eq:or_vee}\n  A \\vee B &= Y \n\\end{align}\n\nA more common method is to use the \\emph{plus} sign that is used for addition in traditional algebra, as in Equation \\ref{BF:eq:or_plus}.\n\n\\begin{align}\n  \\label{BF:eq:or_plus}\n  A + B &= Y \n\\end{align}\n\nFor simplicity, the mathematical \\emph{plus} symbol is normally used to indicate \\textsf{OR}  in printed material since it is easy to enter with a keyboard; however, if there is any chance for ambiguity, then the logic \\textsf{OR}  symbol ($ \\vee $) is used to differentiate between addition and logic \\textsf{OR}.\n\nTable \\ref{BF:tab:truth_table_for_or} is the truth table for an \\textsf{OR}  operation.\n\n%******************************************************\n% OR Truth Table\n%******************************************************\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ccc} \n      \\rowcolor{black!75}\n      \\multicolumn{2}{c}{\\head{Inputs}} & \\head{Output} \\\\\n      A & B & Y \\\\\n      \\hline\n      0 & 0 & 0 \\\\\n      0 & 1 & 1 \\\\\n      1 & 0 & 1 \\\\\n      1 & 1 & 1 \n    \\end{tabular}\n  \\end{center}\n  \\caption{Truth Table for OR}\n  \\label{BF:tab:truth_table_for_or}\n\\end{table}\n\nNotice for the \\textsf{OR} truth table that the output is \\emph{True} ($ 1 $) whenever at least one input is \\emph{True}. Therefore, it could be said that one \\emph{True} input would activate an \\textsf{OR} Gate. In the following diagram, the input variables $ A $ and $ B $ are wired to an \\textsf{OR}  gate, and the output from that gate goes to $ Y $. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_03}\n\t\\caption{OR Gate}\n\t\\label{fig:04_03}\n\\end{figure}\n\nAs an example of an \\textsf{OR} gate at work, consider a traffic signal. Suppose an intersection is set up such that the light for the main road is normally green; however, if a car pulls up to the intersection from the crossroad, or if a pedestrian presses the ``cross'' button, then the main light is changed to red to stop traffic. This could be done with a simple \\textsf{OR} gate. An automobile sensor on the crossroad would be one input and the pedestrian ``cross'' button would be the other input; the output of the \\textsf{OR}  gate connecting these two inputs would change the light to red when either input is activated.\n\n\\subsection{NOT}\n\\label{BF:subsec:not}\n\n\\textsf{NOT} (or \\emph{inverter}) is a Boolean operation that inverts the input. That is, if the input is \\emph{True} then the output will be \\emph{False} or if the input is \\emph{False} then the output will be \\emph{True}. When written in an equation, the Boolean \\textsf{NOT}  operator is represented in many ways, though two are most popular. The older method is to overline (that is, a line above) a term, or group of terms, that are to be inverted, as in Equation \\ref{BF:eq:not_bar}.\\marginpar{Equation \\ref{BF:eq:not_bar} is read \\emph{A OR B NOT = Q} (notice that when spoken, the word \\emph{not} follows the term that is inverted).}\n\n\\begin{align}\n  \\label{BF:eq:not_bar}\n  A + \\overline{B} &= Y \n\\end{align}\n\nAnother method of indicating \\textsf{NOT}  is to use the algebra \\emph{prime} indicator, an apostrophe, as in Equation \\ref{BF:eq:not_apostrophe}.\n\n\\begin{align}\n  \\label{BF:eq:not_apostrophe}\n  A + B' &= Y \n\\end{align}\n\nThe reason that \\textsf{NOT} is most commonly indicated with an apostrophe is because that is easier to enter on a computer keyboard. There are many other ways authors use to represent \\textsf{NOT}  in a formula, but none are considered standardized. For example, some authors use an exclamation point: $ A+!B=Q $, others use a broken line: $ A+ \\neg B=Q $, others use a backslash: $ A+ \\backslash B=Q $, and still others use a tilde: $ A+ \\sim B =Q $. However, only the apostrophe and overline are consistently used to indicate \\textsf{NOT}. Table \\ref{BF:tab:truth_table_for_not} is the truth table for \\textsf{NOT}:\n\n%******************************************************\n% NOT Truth Table\n%******************************************************\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ccc} \n      \\rowcolor{black!75}\n      \\head{Input} & \\head{Output} \\\\\n      0 & 1 \\\\\n      1 & 0 \\\\\n    \\end{tabular}\n  \\end{center}\n  \\caption{Truth Table for NOT}\n  \\label{BF:tab:truth_table_for_not}\n\\end{table}\n\nIn a logic diagram, \\textsf{NOT}  is represented by a small triangle with a ``bubble'' on the output. In Figure \\ref{fig:04_04}, the input variable $ A $ is inverted by a \\textsf{NOT}  gate and then sent to output $ Y $. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_04}\n\t\\caption{NOT Gate}\n\t\\label{fig:04_04}\n\\end{figure}\n\n\n%*********************************************************************\n% NAND Gate\n%*********************************************************************\n\\section{Secondary Logic Functions}\n\\label{BF:sec:secondary_logic_functions}\n\\subsection{NAND}\n\\label{BF:subsec:nand}\n\n\\textsf{NAND} is a Boolean operation that outputs the opposite of \\textsf{AND}, that is, \\textsf{NOT AND}; thus, it will output a logic \\emph{False} only if all of the inputs are \\emph{True}. The \\textsf{NAND} operation is not often used in Boolean equations, but when necessary it is represented by a vertical line. Equation \\ref{BF:eq:nand_symbol} shows a \\textsf{NAND}  operation.\n\n\\begin{align}\n  \\label{BF:eq:nand_symbol}\n  A | B &= Y \n\\end{align}\n\nTable \\ref{BF:tab:truth_table_for_nand_gate} is the Truth Table for a \\textsf{NAND}  gate.\n\n%******************************************************\n% NAND Truth Table\n%******************************************************\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ccc} \n      \\rowcolor{black!75}\n      \\multicolumn{2}{c}{\\head{Inputs}} & \\head{Output} \\\\\n      A & B & Y \\\\\n      \\hline\n      0 & 0 & 1 \\\\\n      0 & 1 & 1 \\\\\n      1 & 0 & 1 \\\\\n      1 & 1 & 0 \n    \\end{tabular}\n  \\end{center}\n  \\caption{Truth Table for \\textsf{NAND}  Gate}\n  \\label{BF:tab:truth_table_for_nand_gate}\n\\end{table}\n\nIn Figure \\ref{fig:04_05}, the input variables $ A $ and $ B $ are wired to a NAND gate, and the output from that gate goes to $ Y $.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_05}\n\t\\caption{NAND Gate}\n\t\\label{fig:04_05}\n\\end{figure}\n\n\n\\marginpar{Inverting bubbles are never found by themselves on a wire; they are always associated with either the inputs or output of a logic gate. To invert a signal on a wire, a \\textsf{NOT} gate is used.}The logic diagram symbol for a \\textsf{NAND}  gate looks like an \\textsf{AND} gate, but with a small bubble on the output port. A bubble in a logic diagram always represents some sort of signal inversion, and it can appear at the inputs or outputs of nearly any logic gate. For example, the bubble on a \\textsf{NAND}  gate could be interpreted as ``take whatever the output would be generated by an \\textsf{AND} gate\\textemdash then invert it.'' \n\n%*************************************************************\n% NOR Gate\n%*************************************************************\n\\subsection{NOR}\n\\label{BF:subsec:nor}\n\n\\textsf{NOR}  is a Boolean operation that is the opposite of OR, that is, \\textsf{NOT OR}; thus, it will output a logic \\emph{True} only if all of the inputs are \\emph{False}. The \\textsf{NOR} operation is not often used in Boolean equations, but when necessary it is represented by a downward-pointing arrow. Equation \\ref{BF:eq:nor_symbol} shows a \\textsf{NOR} operation.\n\n\\begin{align}\n  \\label{BF:eq:nor_symbol}\n  A \\downarrow B &= Y \n\\end{align}\n\nTable \\ref{BF:tab:truth_table_for_nor} is the truth table for \\textsf{NOR} . \n\n%******************************************************\n% NOR Truth Table\n%******************************************************\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ccc} \n      \\rowcolor{black!75}\n      \\multicolumn{2}{c}{\\head{Inputs}} & \\head{Output} \\\\\n      A & B & Y \\\\\n      \\hline\n      0 & 0 & 1 \\\\\n      0 & 1 & 0 \\\\\n      1 & 0 & 0 \\\\\n      1 & 1 & 0 \n    \\end{tabular}\n  \\end{center}\n  \\caption{Truth Table for NOR}\n  \\label{BF:tab:truth_table_for_nor}\n\\end{table}\n\nIn Figure \\ref{fig:04_06}, the input variables $ A $ and $ B $ are wired to a \\textsf{NOR}  gate, and the output from that gate goes to $ Y $. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_06}\n\t\\caption{NOR Gate}\n\t\\label{fig:04_06}\n\\end{figure}\n\n\n\\subsection{XOR}\n\\label{BF:subsec:xor}\n\n\\textsf{XOR} (\\emph{Exclusive OR}) is a Boolean operation that outputs a logical one, or \\emph{True}, only if the two inputs are different. This is useful for circuits that compare inputs; if they are different then the output is \\emph{True}, otherwise it is \\emph{False}. Because of this, an \\textsf{XOR}  gate is sometimes referred to as a \\emph{Difference Gate}. The \\textsf{XOR} operation is not often used in Boolean equations, but when necessary it is represented by a plus sign (like the OR function) inside a circle. Equation \\ref{BF:eq:xor_symbol} shows an \\textsf{XOR}  operation.\n\n% XOR in equation\n\\begin{align}\n  \\label{BF:eq:xor_symbol}\n  A \\oplus B &= Y\n\\end{align}\n\nTable \\ref{BF:tab:truth_table_for_xor} is the truth table for an \\textsf{XOR}  gate.\n\n%******************************************************\n% XOR Truth Table\n%******************************************************\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ccc} \n      \\rowcolor{black!75}\n      \\multicolumn{2}{c}{\\head{Inputs}} & \\head{Output} \\\\\n      A & B & Y \\\\\n      \\hline\n      0 & 0 & 0 \\\\\n      0 & 1 & 1 \\\\\n      1 & 0 & 1 \\\\\n      1 & 1 & 0 \n    \\end{tabular}\n  \\end{center}\n  \\caption{Truth Table for XOR}\n  \\label{BF:tab:truth_table_for_xor}\n\\end{table}\n\nIn Figure \\ref{fig:04_07}, the input variables $ A $ and $ B $ are wired to an \\textsf{XOR}  gate, and the output from that gate goes to $ Y $. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_07}\n\t\\caption{XOR Gate}\n\t\\label{fig:04_07}\n\\end{figure}\n\n\nThere is some debate about the proper behavior of an \\textsf{XOR}  gate that has more than two inputs. Some experts believe that an \\textsf{XOR} gate should output a \\emph{True} if one, and only one, input is \\emph{True} regardless of the number of inputs. This would seem to be in keeping with the rules of digital logic developed by George Boole and other early logisticians and is the strict definition of \\textsf{XOR} promulgated by the \\ac{IEEE}. This is also the behavior of the \\textsf{XOR} gate found in \\textit{Logisim-evolution}, the digital logic simulator used in the lab manual accompanying this text. Others believe, though, that an \\textsf{XOR} gate should output a \\emph{True} if an odd number of inputs is \\emph{True}. in \\Le this type of behavior is found in a device called a ``parity gate'' and is covered in more detail elsewhere in this book.\n\n%**********************************************************\n% XNOR Gate\n%**********************************************************\n\\subsection{XNOR}\n\\label{BF:subsec:xnor}\n\n\\textsf{XNOR} is a Boolean operation that will output a logical one, or \\emph{True}, only if the two inputs are the same; thus, an \\textsf{XNOR} gate is often referred to as an \\emph{Equivalence Gate}. The \\textsf{XNOR} operation is not often used in Boolean equations, but when necessary it is represented by a dot inside a circle. Equation \\ref{BF:eq:xnor_symbol} shows an \\textsf{XNOR}  operation. \n\n% XNOR in equation\n\\begin{align}\n  \\label{BF:eq:xnor_symbol}\n  A \\odot B &= Y\n\\end{align}\n\nTable \\ref{BF:tab:truth_table_for_xnor} is the truth table for \\textsf{XNOR} . \n\n%******************************************************\n% XNOR Truth Table\n%******************************************************\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ccc} \n      \\rowcolor{black!75}\n      \\multicolumn{2}{c}{\\head{Inputs}} & \\head{Output} \\\\\n      A & B & Y \\\\\n      \\hline\n      0 & 0 & 1 \\\\\n      0 & 1 & 0 \\\\\n      1 & 0 & 0 \\\\\n      1 & 1 & 1 \n    \\end{tabular}\n  \\end{center}\n  \\caption{Truth Table for XNOR}\n  \\label{BF:tab:truth_table_for_xnor}\n\\end{table}\n\nIn Figure \\ref{fig:04_08}, the input variables $ A $ and $ B $ are wired to an \\textsf{XNOR}  gate, and the output from that gate goes to $ Y $. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_08}\n\t\\caption{XNOR Gate}\n\t\\label{fig:04_08}\n\\end{figure}\n\n\n\\subsection{Buffer}\n\\label{BF:subsec:buffer}\n\nA buffer (sometimes called \\emph{Transfer}) is a Boolean operation that transfers the input to the output without change. If the input is \\emph{True}, then the output will be \\emph{True} and if the input is \\emph{False}, then the output will be \\emph{False}. It may seem to be an odd function since this operation does not change anything, but it has an important use in a circuit. As logic circuits become more complex, the signal from input to output may become weak and no longer able to drive (or activate) additional gates. A buffer is used to boost (and stabilize) a logic level so it is more dependable. Another important function for a buffer is to clean up an input signal. As an example, when an electronic circuit interacts with the physical world (such as a user pushing a button), there is often a very brief period when the signal from that physical device waivers between high and low unpredictably. A buffer can smooth out that signal so it is a constant high or low without voltage spikes in between. \n\nTable \\ref{BF:tab:truth_table_for_a_buffer} is the truth table for buffer.\n\n%******************************************************\n% Buffer Truth Table\n%******************************************************\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ccc} \n      \\rowcolor{black!75}\n      \\head{Input} & \\head{Output} \\\\\n      0 & 0 \\\\\n      1 & 1 \n    \\end{tabular}\n  \\end{center}\n  \\caption{Truth Table for a Buffer}\n  \\label{BF:tab:truth_table_for_a_buffer}\n\\end{table}\n\nBuffers are rarely used in schematic diagrams since they do not actually change a signal; however, Figure \\ref{fig:04_09}, illustrates a buffer. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_09}\n\t\\caption{Buffer}\n\t\\label{fig:04_09}\n\\end{figure}\n\n\\section{Univariate Boolean Algebra Properties}\n\\label{BF:sec:univariate_boolean_algebra_properties}\n\\subsection{Introduction}\n\\label{BF:subsec:introduction_to_univariate}\n\nBoolean Algebra, like real number algebra, includes a number of properties. This unit introduces the univariate Boolean properties, or those properties that involve only one input variable. These properties permit Boolean expressions to be simplified, and circuit designers are interested in simplifying circuits to reduce construction expense, power consumption, heat loss (wasted energy), and troubleshooting time.  \n\n\\subsection{Identity}\n\\label{BF:subsec:identity}\n\nIn mathematics, an identity is an equality where the left and right members are the same regardless of the values of the variables present. As an example, Equation \\ref{BF:eq:identity_example} is an identity since the two members are identical regardless of the value of $ \\alpha $:\n\n\\begin{align}\n  \\label{BF:eq:identity_example}\n  \\frac{\\alpha}{2} &= 0.5\\alpha\n\\end{align}\n\nAn \\emph{Identity Element} is a special member of a set such that when that element is used in a binary operation the other element in that operation is not changed. This is sometimes called the \\emph{Neutral Element} since it has no effect on binary operations. As an example, in Equation \\ref{BF:eq:identity_element_of_addition} the two members of the equation are always identical. Therefore, zero is the identity element for addition since anything added to zero remains unchanged.\n\n\\begin{align}\n  \\label{BF:eq:identity_element_of_addition}\n  a + 0 &= a \n\\end{align}\n\nIn a logic circuit, combining any logic input with a logic zero through an \\textsf{OR}  gate yields the original input. Logic zero, then, is considered the \\textsf{OR} identity element because it causes the input of the gate to be copied to the output unchanged. Because \\textsf{OR}  is represented by a plus sign when written in a Boolean equation, and the identity element for \\textsf{OR}  is zero, Equation \\ref{BF:eq:or_identity} is \\emph{True}.\n\n\\begin{align}\n  \\label{BF:eq:or_identity}\n  A + 0 &= A \n\\end{align}\n\nThe bottom input to the \\textsf{OR} gate in \\ref{fig:04_10} is a constant logic zero, or \\emph{False}. The output for this circuit, $ Y $, will be the same as input $ A $; therefore, the identity element for \\textsf{OR}  is zero.  \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_10}\n\t\\caption{OR Identity Element}\n\t\\label{fig:04_10}\n\\end{figure}\n\nIn the same way, combining any logic input with a logic one through an \\textsf{AND}  gate yields the original input. Logic one, then, is considered the \\textsf{AND}  identity element because it causes the input of the gate to be copied to the output unchanged. Because \\textsf{AND}  is represented by a multiplication sign when written in a Boolean equation, and the identity element for \\textsf{AND} is one, Equation \\ref{BF:eq:and_identity} is \\emph{True}.\n\n\\begin{align}\n  \\label{BF:eq:and_identity}\n  A * 1 &= A \n\\end{align}\n\nThe bottom input to the \\textsf{AND} gate in \\ref{fig:04_11} is a constant logic one, or \\emph{True}. The output for this circuit, $ Y $, will be the same as input $ A $; therefore, the identity element for \\textsf{AND}  is one.  \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_11}\n\t\\caption{AND Identity Element}\n\t\\label{fig:04_11}\n\\end{figure}\n\n\\subsection{Idempotence}\n\\label{BF:subsec:idempotence}\n\nIf the two inputs of either an \\textsf{OR} or \\textsf{AND} gate are tied together, then the same signal will be applied to both inputs. This results in the output of either of those gates being the same as the input; and this is called the idempotence property. An electronic gate wired in this manner performs the same function as a buffer. \n\n% Pull Quote - Marginal Note - Sidebar\n\\marginpar{Remember that in Boolean expressions a plus sign represents an \\textsf{OR}  gate, not mathematical addition.}\n\n\\begin{align}\n  \\label{BF:eq:idempotence_for_or}\n  A + A &= A \n\\end{align}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_12}\n\t\\caption{Idempotence Property for OR Gate}\n\t\\label{fig:04_12}\n\\end{figure}\n\nFigure \\ref{fig:04_12} illustrates the idempotence property for an \\textsf{AND} gate.\n\n% Pull Quote - Marginal Note - Sidebar\n\\marginpar{Remember that in a Boolean expression a multiplication sign represents an AND gate, not mathematical multiplying.}\n\n\\begin{align}\n  \\label{BF:eq:idempotence_for_and}\n  A * A &= A \n\\end{align}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_13}\n\t\\caption{Idempotence Property for AND Gate}\n\t\\label{fig:04_13}\n\\end{figure}\n\n\\subsection{Annihilator}\n\\label{BF:subsec:annihilator}\n\nCombining any data and a logic one through an \\textsf{OR} gate yields a constant output of one. This property is called the annihilator since the \\textsf{OR} gate outputs a constant one; in other words, whatever other data were input are lost. Because \\textsf{OR} is represented by a plus sign when written in a Boolean equation, and the annihilator for \\textsf{OR} is one, the following is true:\n\n\\begin{align}\n  \\label{BF:eq:annihilator_or}\n  A + 1 &= 1 \n\\end{align}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_14}\n\t\\caption{Annihilator For OR Gate}\n\t\\label{fig:04_14}\n\\end{figure}\n\nThe bottom input for the \\textsf{OR}  gate in Figure \\ref{fig:04_14} is a constant logic one, or \\emph{True}. The output for this circuit will be \\emph{True} (or $ 1 $) no matter whether input $ A $ is \\emph{True} or \\emph{False} ($ 1 $ or $ 0 $).\n\nCombining any data and a logic zero with an \\textsf{AND} gate yields a constant output of zero. This property is called the annihilator since the \\textsf{AND}  gate outputs a constant zero; in other words, whatever logic data were input are lost. Because \\textsf{AND}  is represented by a multiplication sign when written in a Boolean equation, and the annihilator for \\textsf{AND} is zero, the following is true:\n\n\\begin{align}\n  \\label{BF:eq:annihilator_and}\n  A * 0 &= 0 \n\\end{align}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_15}\n\t\\caption{Annihilator For AND Gate}\n\t\\label{fig:04_15}\n\\end{figure}\n\nThe bottom input for the \\textsf{AND} gate in Figure \\ref{fig:04_15} is a constant logic zero, or \\emph{False}. The output for this circuit will be \\emph{False} (or $ 0 $) no matter whether input $ A $ is \\emph{True} or \\emph{False} ($ 1 $ or $ 0 $).\n\n\\subsection{Complement}\n\\label{BF:subsec:complement}\n\nIn Boolean logic there are only two possible values for variables: $ 0 $ and $ 1 $. Since either a variable or its complement must be one, and since combining any data with one through an \\textsf{OR} gate yields one (see the Annihilator in Equation \\ref{BF:eq:annihilator_or}), then the following is true:\n\n\\begin{align}\n  \\label{BF:eq:complement_or}\n  A + A' &= 1 \n\\end{align}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_16}\n\t\\caption{OR Complement}\n\t\\label{fig:04_16}\n\\end{figure}\n\nIn Figure \\ref{fig:04_16}, the output ($ Y $) will always equal one, regardless of the value of input $ A $. This leads to the general property that when a variable and its complement are combined through an \\textsf{OR} gate the output will always be one. \n\nIn the same way, since either a variable or its complement must be zero, and since combining any data with zero through an \\textsf{AND} gate yields zero (see the Annihilator in Equation \\ref{BF:eq:annihilator_and}), then the following is true: \n\n\\begin{align}\n  \\label{BF:eq:complement_and}\n  A * A' &= 0\n\\end{align}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_17}\n\t\\caption{AND Complement}\n\t\\label{fig:04_17}\n\\end{figure}\n\n\\subsection{Involution}\n\\label{BF:subsec:involution}\n\n\\marginpar{The Involution Property is sometimes called the ``Double Complement'' Property.}\n\nAnother law having to do with complementation is that of Involution. Complementing a Boolean variable two times (or any even number of times) results in the original Boolean value. \n\n\\begin{align}\n  \\label{BF:eq:involuton}\n  (A')' &= A\n\\end{align}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_18}\n\t\\caption{Involution Property}\n\t\\label{fig:04_18}\n\\end{figure}\n\nIn the circuit illustrated in Figure \\ref{fig:04_18}, the output ($ Y $) will always be the same as the input ($ A $). \n\n% Begin Sidebar Box\n\\begin{tcolorbox}[colback=blue!5!white,colframe=blue!75!black]\n  % Upper half of box: my \"title\" area\n  \\textcolor{blue}{\\textbf{Propagation Delay}}\n  % Lower half of the box: the content\n  \\tcblower\n  It takes the two \\textsf{NOT} gates a short period of time to pass a signal from input to output, which is known as ``propagation delay.'' A designer occasionally needs to build an intentional signal delay into a circuit for some reason and two (or any even number of) consecutive \\textsf{NOT} gates would be one option.\n\\end{tcolorbox}\n% End Sidebar Box\n\n\\section{Multivariate Boolean Algebra Properties}\n\\label{BF:sec:multivariate_boolean_algebra_properties}\n\\subsection{Introduction}\n\\label{BF:subsec:introduction_to_multivariate}\n\nBoolean Algebra, like real number algebra, includes a number of properties. This unit introduces the multivariate Boolean properties, or those properties that involve more than one input variable. These properties permit Boolean expressions to be simplified, and circuit designers are interested in simplifying circuits to reduce construction expense, power consumption, heat loss (wasted energy), and troubleshooting time.  \n\n\\subsection{Commutative}\n\\label{BF:subsec:commutative_property}\n\n\\marginpar{The examples here show only two variables, but this property is true for any number of variables.}\n\nIn essence, the commutative property indicates that the order of the input variables can be reversed in either \\textsf{OR} or \\textsf{AND} gates without changing the truth of the expression. Equation \\ref{BF:eq:commutative} expresses this property algebraically.\n\n\\begin{align}\n  \\label{BF:eq:commutative}\n  A + B &= B + A \\\\\n  \\nonumber\n  A * B &= B * A\n\\end{align}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_19}\n\t\\caption{Commutative Property for OR}\n\t\\label{fig:04_19}\n\\end{figure}\n\n\\marginpar{\\textsf{XOR} and \\textsf{XNOR} are also commutative; but for only two variables, not three or more.}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_20}\n\t\\caption{Commutative Property for AND}\n\t\\label{fig:04_20}\n\\end{figure}\n\nIn Figures \\ref{fig:04_19} and \\ref{fig:04_20} the inputs are reversed for the two gates, but the outputs are the same. For example, $ A $ is entering the top input for the upper \\textsf{OR} gate, but the bottom input for the lower gate; however, $ Y1 $ is always equal to $ Y2 $.\n\n\\subsection{Associative}\n\\label{BF:subsec:associative_property}\n\n\\marginpar{The examples here show only three variables, but this property is true for any number of variables.}\n\nThis property indicates that groups of variables in an \\textsf{OR} or \\textsf{AND} gate can be associated in various ways without altering the truth of the equations. Equation \\ref{BF:eq:associative} expresses this property algebraically: \n\n\\begin{align}\n  \\label{BF:eq:associative}\n  ( A + B ) + C &= A + ( B + C ) \\\\\n  \\nonumber\n  ( A * B ) * C &= A * ( B * C )\n\\end{align}\n\n\\marginpar{\\textsf{XOR} and \\textsf{XNOR} are also associative; but for only two variables, not three or more.}\n\nIn the circuits in Figure \\ref{fig:04_21} and \\ref{fig:04_22} , notice that $ A $ and $ B $ are associated together in the first gate, and then $ C $ is associated with the output of that gate. Then, in the lower half of the circuit, $ B $ and $ C $ are associated together in the first gate, and then $ A $ is associated with the output of that gate. Since $ Y1 $ is always equal to $ Y2 $ for any combination of inputs, it does not matter which of the two variables are associated together in a group of gates.  \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_21}\n\t\\caption{Associative Property for OR}\n\t\\label{fig:04_21}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_22}\n\t\\caption{Associative Property for AND}\n\t\\label{fig:04_22}\n\\end{figure}\n\n\\subsection{Distributive}\n\\label{BF:subsec:distributive_property}\n\nThe distributive property of real number algebra permits certain variables to be ``distributed'' to other variables. This operation is frequently used to create groups of variables that can be simplified; thus, simplifying the entire expression. Boolean algebra also includes a distributive property, and that can be used to combine \\textsf{OR}  or \\textsf{AND}  gates in various ways that make it easier to simplify the circuit. Equation \\ref{BF:eq:distributive} expresses this property algebraically:\n\n\\begin{align}\n  \\label{BF:eq:distributive}\n  A( B + C ) &= AB + AC \\\\\n  \\nonumber\n  A + (BC) &= (A + B) (A + C)\n\\end{align}\n\nIn the circuits illustrated in Figures \\ref{fig:04_23} and \\ref{fig:04_24}, notice that input $ A $ in the top half of the circuit is distributed to inputs $ B $ and $ C $ in the bottom half. However, output $ Y1 $ is always equal to output $ Y2 $ regardless of how the inputs are set. These two circuits illustrate Distributive of \\textsf{AND} over \\textsf{OR}  and Distributive of \\textsf{OR} over \\textsf{AND} .\n \n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_23}\n\t\\caption{Distributive Property for AND over OR}\n\t\\label{fig:04_23}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_24}\n\t\\caption{Distributive Property for OR over AND}\n\t\\label{fig:04_24}\n\\end{figure}\n\n\\subsection{Absorption}\n\\label{BF:subsec:absorption_property}\n\nThe absorption property is used to remove logic gates from a circuit if those gates have no effect on the output. In essence, a gate is ``absorbed'' if it is not needed. There are two different absorption properties:\n\n\\begin{align}\n  \\label{BF:eq:absorption}\n  A + (AB) &= A \\\\\n  \\nonumber\n  A(A + B) &= A\n\\end{align}\n\nThe best way to think about why these properties are true is to imagine a circuit that contains them. The first circuit below illustrates the top equation. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_25}\n\t\\caption{Absorption Property (Version 1)}\n\t\\label{fig:04_25}\n\\end{figure}\n\nTable \\ref{BF:tab:truth_table_for_absorption_property_version_1} is the truth table for the circuit in Figure \\ref{fig:04_25}.\n\n%******************************************************\n% Absorption (Version 1) Truth Table\n%******************************************************\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ccc} \n      \\rowcolor{black!75}\n      \\multicolumn{2}{c}{\\head{Inputs}} & \\head{Output} \\\\\n      A & B & Y \\\\\n      \\hline\n      0 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      1 & 0 & 1 \\\\\n      1 & 1 & 1 \n    \\end{tabular}\n  \\end{center}\n  \\caption{Truth Table for Absorption Property}\n  \\label{BF:tab:truth_table_for_absorption_property_version_1}\n\\end{table}\n\nNotice that the output, $ Y $, is always the same as input $ A $. This means that input $ B $ has no bearing on the output of the circuit; therefore, the circuit could be replaced by a piece of wire from input $ A $ to output $ Y $. Another way to state that is to say that input $ B $ is absorbed by the circuit.\n\nThe circuit illustrated in Figure \\ref{fig:04_26} is the second version of the Absorption Property. Like the first Absorption Property circuit, a truth table would demonstrate that input $ B $ is absorbed by the circuit. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_26}\n\t\\caption{Absorption Property (Version 2)}\n\t\\label{fig:04_26}\n\\end{figure}\n\n\\subsection{Adjacency}\n\\label{BF:subsec:adjacency_property}\n\nThe adjacency property simplifies a circuit by removing unnecessary gates.\n\n\\begin{align}\n  \\label{BF:eq:adjacency}\n  AB + AB' &= A\n\\end{align}\n\nThis property can be proven by simple algebraic manipulation:\n\n\\begin{align}\n  \\label{BF:eq:adjacency_solved}\n  AB + AB' && \\text{Original Expression} \\\\\n  \\nonumber\n  A ( B + B') && \\text{Distributive Property} \\\\\n  \\nonumber\n  A1 && \\text{Complement Property} \\\\\n  \\nonumber\n  A && \\text{Identity Element}\n\\end{align}\n\nThe circuit in Figure \\ref{fig:04_27} illustrates the adjacency property. If this circuit were constructed it would be seen that the output, $ Y $, is always the same as input $ A $; therefore, this entire circuit could be replaced by a single wire from input $ A $ to output $ Y $.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_27}\n\t\\caption{Adjacency Property}\n\t\\label{fig:04_27}\n\\end{figure}\n\n\\section{DeMorgan's Theorem}\n\\label{BF:sec:demorgans_theorem}\n\\subsection{Introduction}\n\\label{BF:subsec:introduction_demorgans}\n\nA mathematician named Augustus DeMorgan developed a pair of important theorems regarding the complementation of groups in Boolean algebra. DeMorgan found that an \\textsf{OR} gate with all inputs inverted (a Negative-\\textsf{OR} gate) behaves the same as a \\textsf{NAND}  gate with non-inverted inputs; and an \\textsf{AND} gate with all inputs inverted (a Negative-\\textsf{AND} gate) behaves the same as a \\textsf{NOR} gate with non-inverted inputs. DeMorgan's theorem states that inverting the output of any gate is the same as using the opposite type of gate with inverted inputs. Figure \\ref{fig:04_28} illustrates this in circuit terms: the \\textsf{NAND} gate with normal inputs and the \\textsf{OR} gate with inverted inputs are functionally equivalent; that is, $ Y1 $ will always equal $ Y2 $, regardless of the values of input $ A $ or $ B $.  \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_28}\n\t\\caption{DeMorgan's Theorem Defined}\n\t\\label{fig:04_28}\n\\end{figure}\n\nThe NOT function is commonly represented in an equation as an apostrophe because it is easy to enter with a keyboard, like: $ (AB)' $ for \\emph{A AND B NOT}. However, it is easiest to work with DeMorgan's theorem if \\textsf{NOT} is represented by an overline rather than an apostrophe, so it would be written as $ \\overline{AB} $ rather than $ (AB)' $. Remember that an overline is a grouping symbol (like parenthesis) and it means that everything under that bar would first be combined (using an \\textsf{AND} or \\textsf{OR} gate) and then the output of the combination would be complemented.\n\n\\subsection{Applying DeMorgan's Theorem}\n\\label{BF:subsec:applying_demorgans_theorem}\n\nApplying DeMorgan's theorem to a Boolean expression may be thought of in terms of \\emph{breaking the bar}. When applying DeMorgan's theorem to a Boolean expression:\n\n\\begin{enumerate}\n\\item A complement bar is broken over a group of variables.\n\\item The operation (\\textsf{AND}  or \\textsf{OR} ) directly underneath the broken bar changes.\n\\item Pieces of the broken bar remain over the individual variables. \n\\end{enumerate}\n\nTo illustrate:\n\n\\begin{align}\n  \\label{BF:eq:demorgan_nand}\n  \\overline{A*B} \\leftrightarrow \\overline{A}+\\overline{B}\n\\end{align}\n\n\\begin{align}\n  \\label{BF:eq:demorgan_nor}\n  \\overline{A+B} \\leftrightarrow \\overline{A}*\\overline{B}\n\\end{align}\n\nEquation \\ref{BF:eq:demorgan_nand} shows how a two-input \\textsf{NAND} gate is ``broken'' to form an \\textsf{OR} gate with two inverted inputs and equation \\ref{BF:eq:demorgan_nor} shows how a two-input \\textsf{NOR} gate is ``broken'' to form an \\textsf{AND} gate with two complemented inputs.\n\n\\subsection{Simple Example}\n\\label{BF:subsec:simple_example_demorgan}\n\nWhen multiple ``layers'' of bars exist in an expression, only one bar is broken at a time, and the longest, or uppermost, bar is broken first. As an example, consider the circuit in Figure \\ref{fig:04_29}: \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_29}\n\t\\caption{DeMorgan's Theorem Example 1}\n\t\\label{fig:04_29}\n\\end{figure}\n\nBy writing the output at each gate (as illustrated in Figure \\ref{fig:04_29}), it is easy to determine the Boolean expression for the circuit. Note: all circuit diagrams in this book are generated with \\Le and the text tool in that software does not permit drawing overbars. Therefore, the circuit diagram will use the apostrophe method of indicating NOT but overbars will be used in the text.\n\n\\begin{align}\n  \\label{BF:eq:demorgan_simple_example}\n  \\overline{A+\\overline{BC}}\n\\end{align}\n\nTo simplify the circuit, break the bar covering the entire expression (the ``longest bar''), and then simplify the resulting expression.\n\n\\begin{align}\n  \\label{BF:eq:demorgan_simple_solved}\n  \\overline{A+\\overline{BC}} && \\text{Original Expression} \\\\\n  \\nonumber\n  \\overline{A}\\,\\overline{\\overline{BC}} && \\text{''Break'' the longer bar} \\\\\n  \\nonumber\n  \\overline{A}BC && \\text{Involution Property}\n\\end{align}\n\nAs a result, the original circuit is reduced to a three-input \\textsf{AND} gate with one inverted input.\n\n\\subsection{Incorrect Application of DeMorgan's Theorem}\n\\label{BF:subsec:incorrect_application_of_demorgans_theorem}\n\nMore than one bar is never broken in a single step, as illustrated in Equation \\ref{BF:eq:demorgan_incorrect_solution}: \n\n\\begin{align}\n  \\label{BF:eq:demorgan_incorrect_solution}\n  \\overline{A+\\overline{BC}} && \\text{Original Expression} \\\\\n  \\nonumber\n  \\overline{A\\overline{B}}+\\overline{\\overline{C}} && \\text{Improperly Breaking Two Bars} \\\\\n  \\nonumber\n  \\overline{A}B+C && \\text{Incorrect Solution}\n\\end{align}\n\nThus, as tempting as it may be to take a shortcut and break more than one bar at a time, it often leads to an incorrect result. Also, while it is possible to properly reduce an expression by breaking the short bar first; more steps are usually required and that process is not recommended.  \n\n\\subsection{About Grouping}\n\\label{BF:subsec:demorgans_about_grouping}\n\nAn important, but easily neglected, aspect of DeMorgan's theorem concerns grouping. Since a bar functions as a grouping symbol, the variables formerly grouped by a broken bar must remain grouped or else proper precedence (order of operation) will be lost. Therefore, after simplifying a large grouping of variables, it is a good practice to place them in parentheses in order to keep the order of operation the same.  \n\nConsider the circuit in Figure \\ref{fig:04_30}.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_30}\n\t\\caption{DeMorgan's Theorem Example 2}\n\t\\label{fig:04_30}\n\\end{figure}\n\nAs always, the first step in simplifying this circuit is to generate the Boolean expression for the circuit, which is done by writing the sub-expression at the output of each gate. That results in Expression \\ref{BF:eq:demorgan_grouping_solution}, which is then simplified. \n\n\\begin{align}\n  \\label{BF:eq:demorgan_grouping_solution}\n  \\overline{ \\overline{A+BC} + \\overline{A \\overline{B}}} && \\text{Original Expression} \\\\\n  \\nonumber\n  ( \\overline{\\overline{A+BC}} ) ( \\overline{\\overline{A\\overline{B}}} ) && \\text{Breaking the Longest Bar} \\\\\n  \\nonumber\n  (A+BC)(A\\overline{B}) && \\text{Involution} \\\\\n  \\nonumber\n  (AA\\overline{B}) (BCA\\overline{B}) && \\text{Distribute $ A\\overline{B} $ to $ (A+BC) $} \\\\\n  \\nonumber\n  (A\\overline{B})+(BCA\\overline{B}) && \\text{Idempotence: $ AA=A $} \\\\\n  \\nonumber\n  (A\\overline{B})+(0CA)) && \\text{Complement: $ B\\overline{B}=0 $} \\\\\n  \\nonumber\n  (A\\overline{B})+0 && \\text{Annihilator: $ 0CA=0 $} \\\\\n  \\nonumber\n  A\\overline{B} && \\text{Identity: $ A+0=A $}\n\\end{align}\n\nThe equivalent gate circuit for this much-simplified expression is as follows:\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_31}\n\t\\caption{DeMorgan's Theorem Example 2 Simplified}\n\t\\label{fig:04_31}\n\\end{figure}\n\n\\subsection{Summary}\n\\label{BF:subsec:demorgans_summary}\n\nHere are the important points to remember about DeMorgan's Theorem: \n\n\\begin{itemize}\n  \\item It describes the equivalence between gates with inverted inputs and gates with inverted outputs. \n  \\item When \"breaking\" a complementation (or \\textsf{NOT}) bar in a Boolean expression, the operation directly underneath the break (\\textsf{AND} or \\textsf{OR}) reverses and the broken bar pieces remain over the respective terms. \n  \\item It is normally easiest to approach a problem by breaking the longest (uppermost) bar before breaking any bars under it. \n  \\item Two complementation bars are never broken in one step. \n  \\item Complementation bars function as grouping symbols. Therefore, when a bar is broken, the terms underneath it must remain grouped. Parentheses may be placed around these grouped terms as a help to avoid changing precedence.\n\\end{itemize}\n\n\\subsection{Example Problems}\n\\label{BF:subsec:demorgans_example_problems}\n\nThe following examples use DeMorgan's Theorem to simplify a Boolean expression.\n\n%******************************************************\n% DeMorgan's Problems\n%******************************************************\n\\begin{table}[H]\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{c|cc} \n      \\rowcolor{black!75}\n      & \\head{Original Expression} & \\head{Simplified} \\\\\n      1 & $ (\\overline{A+B})(\\overline{ABC})(\\overline{\\overline{A}C}) $ \n        & $ \\overline{A}\\,\\overline{B}\\,\\overline{C} $ \\\\\n      2 & $ \\overline{(AB+\\overline{B}C)+(B\\overline{C}+\\overline{A}B)} $ \n        & $ \\overline{B}\\,\\overline{C} $ \\\\\n      3 & $ (AB+\\overline{B}C)(AC+\\overline{A}\\,\\overline{C}) $ \n        & $ \\overline{A}+\\overline{C} $ \n    \\end{tabular}\n  \\end{center}\n  \\label{BF:tab:demorgans_example_problems}\n  \\sffamily\n\\end{table}\n\n\\section{Boolean Functions}\n\\label{BF:sec:boolean_functions}\n\nConsider Figure \\ref{fig:04_32}, which is a generic circuit with two inputs and one output.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_32}\n\t\\caption{Generic Function}\n\t\\label{fig:04_32}\n\\end{figure}\n\nWithout knowing anything about what is in the unlabeled box at the center of the circuit, there are a number of possible truth tables which could describe the circuit's output. Two possibilities are shown in Truth Table \\ref{BF:tab:truth_table_for_generic_circuit_one} and Truth Table \\ref{BF:tab:truth_table_for_generic_circuit_two}.\n\n%******************************************************\n% Generic Truth Table 1\n%******************************************************\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ccc} \n      \\rowcolor{black!75}\n      \\multicolumn{2}{c}{\\head{Inputs}} & \\head{Output} \\\\\n      A & B & Y \\\\\n      \\hline\n      0 & 0 & 0 \\\\\n      0 & 1 & 1 \\\\\n      1 & 0 & 0 \\\\\n      1 & 1 & 1 \n    \\end{tabular}\n  \\end{center}\n  \\caption{Truth Table for Generic Circuit One}\n  \\label{BF:tab:truth_table_for_generic_circuit_one}\n\\end{table}\n\n%******************************************************\n% Generic Truth Table 2\n%******************************************************\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ccc} \n      \\rowcolor{black!75}\n      \\multicolumn{2}{c}{\\head{Inputs}} & \\head{Output} \\\\\n      A & B & Y \\\\\n      \\hline\n      0 & 0 & 0 \\\\\n      0 & 1 & 1 \\\\\n      1 & 0 & 1 \\\\\n      1 & 1 & 0 \n    \\end{tabular}\n  \\end{center}\n  \\caption{Truth Table for Generic Circuit Two}\n  \\label{BF:tab:truth_table_for_generic_circuit_two}\n\\end{table}\n\nIn fact, there are $ 16 $ possible truth tables for this circuit. Each of those truth tables reflect a single potential function of the circuit by setting various combinations of input/output. Therefore, any two-input, one-output circuit has $ 16 $ possible functions. It is easiest to visualize all $ 16 $ combinations of inputs/outputs by using an odd-looking truth table. Consider only one of those $ 16 $ functions, the one for the generic circuit described by Truth Table \\ref{BF:tab:truth_table_for_generic_circuit_two}. That function is also found in the Boolean Functions Table \\ref{BF:tab:boolean_functions} and one row from that table is reproduced in Table \\ref{BF:tab:boolean_function_six}.\n\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    %\\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{llllll}\n      \\textbf{A} & 0 & \\cellcolor{gray!10}0 & 1 & 1 &  \\\\ \n      \\textbf{B} & 0 & \\cellcolor{gray!10}1 & 0 & 1 &  \\\\ \\hline\n      $ F_{6} $ & 0 & \\cellcolor{gray!10}1 & 1 & 0 \n      & Exclusive Or (XOR): $ A \\oplus B $ \\\\ \n    \\end{tabular} \n  \\end{center}\n  \\caption{Boolean Function Six}\n  \\label{BF:tab:boolean_function_six}\n\\end{table}\n\nThe line shown in Table \\ref{BF:tab:boolean_function_six} is for \\emph{Function 6}, or $ F_6 $ (note that the pattern of the outputs is $ 0110 $, which is binary $ 6 $). Inputs $ A $ and $ B $ are listed at the top of the table. For example, the highlighted column of the table shows that when $ A $ is zero and $ B $ is one the output is one. Therefore, on the line that defines $ F_6 $, the output is \\emph{True} when $ [ (A=0 $ \\textsf{AND} $ B=1) $ \\textsf{OR} $ (A=1 $ \\textsf{AND} $ B=0) ] $ This is an \\textsf{XOR} function, and the last column of the table verbally describes that function.   \n\nTable \\ref{BF:tab:boolean_functions} is the complete Boolean Function table.\n\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{llllll}\n    \\textbf{A} & 0 & 0 & 1 & 1 &  \\\\ \n    \\textbf{B} & 0 & 1 & 0 & 1 &  \\\\ \\hline\n    $ F_{0} $ & 0 & 0 & 0 & 0 \n      & Zero or Clear. Always zero (Annihilation) \\\\ \n    $ F_{1} $ & 0 & 0 & 0 & 1 \n      & Logical AND: $ A * B $  \\\\ \n    $ F_{2} $ & 0 & 0 & 1 & 0 \n      & Inhibition: $ AB' $ or $ A>B $ \\\\ \n    $ F_{3} $ & 0 & 0 & 1 & 1 \n      & Transfer A to Output, Ignore B \\\\ \n    $ F_{4} $ & 0 & 1 & 0 & 0 \n      & Inhibition: $ A'B $ or $ B>A $ \\\\ \n    $ F_{5} $ & 0 & 1 & 0 & 1 \n      & Transfer B to Output, Ignore A \\\\ \n    $ F_{6} $ & 0 & 1 & 1 & 0 \n      & Difference, XOR: $ A \\oplus B $ \\\\ \n    $ F_{7} $ & 0 & 1 & 1 & 1 \n      & Logical OR: $ A + B $ \\\\ \n    $ F_{8} $ & 1 & 0 & 0 & 0 \n      & Logical NOR: $ (A + B)' $ \\\\ \n    $ F_{9} $ & 1 & 0 & 0 & 1 \n      & Equivalence, XNOR: $ (A = B)' $ \\\\ \n    $ F_{10} $ & 1 & 0 & 1 & 0 \n      & Not B and ignore A, B Complement \\\\ \n    $ F_{11} $ & 1 & 0 & 1 & 1 \n      & Implication, $ A + B' $, $ B >= A $ \\\\ \n    $ F_{12} $ & 1 & 1 & 0 & 0 \n      & Not A and ignore B, A Complement \\\\ \n    $ F_{13} $ & 1 & 1 & 0 & 1 \n      & Implication, $ A' + B $, $ A >= B $ \\\\ \n    $ F_{14} $ & 1 & 1 & 1 & 0 \n      & Logical NAND: $ (A*B)' $ \\\\ \n    $ F_{15} $ & 1 & 1 & 1 & 1 \n      & One or Set. Always one (Identity) \\\\ \n    \\end{tabular} \n  \\end{center}\n  \\caption{Boolean Functions}\n  \\label{BF:tab:boolean_functions}\n\\end{table}\n\n\\section{Functional Completeness}\n\\label{BF:sec:functional_completeness}\n\nA set of Boolean operations is said to be \\emph{functionally complete} if every possible Boolean function can be derived from that set. The Primary Logic Operations (page \\pageref{BF:sec:primary_logic_operations}) are functionally complete since the Secondary Logic Functions (page \\pageref{BF:sec:secondary_logic_functions}) can be derived from them. As an example, Equation \\ref{BF:eq:xor_from_and} and Figure \\ref{fig:04_33} shows how an \\textsf{XOR} function can be derived from only \\textsf{AND}, \\textsf{OR}, and \\textsf{NOT} gates.\n\n% XOR in equation\n\\begin{align}\n  \\label{BF:eq:xor_from_and}\n  ( (A * B)' * ( A + B) )  &= A \\oplus B\n\\end{align}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/04_33}\n\t\\caption{XOR Derived From AND/OR/NOT}\n\t\\label{fig:04_33}\n\\end{figure}\n\nWhile the Primary Operations are functionally complete, it is possible to define other functionally complete sets of operations. For example, using DeMorgan's Theorem, the set of \\{\\textsf{AND}, \\textsf{NOT}\\} is also functionally complete since the \\textsf{OR}  operation can be defined as $ (A'B')' $. In fact, both \\{\\textsf{NAND}\\} and \\{NOR\\} operations are functionally complete by themselves. As an example, the \\textsf{NOT}  operation can be derived using only \\textsf{NAND} gates: $ ( A | A ) $. Because all Boolean functions can be derived from either \\textsf{NAND} or \\textsf{NOR} operations, these are sometimes considered \\emph{universal} operations and it is a common challenge for students to create some complex Boolean function using only one of these two types of operations.", "meta": {"hexsha": "cee91b0fc138b941237dfb39a780bc403af93fba", "size": 60844, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/04_Bool_Functions.tex", "max_stars_repo_name": "grself/CIS221_Text", "max_stars_repo_head_hexsha": "e5d78f880e0bae66b33823ee22c68ed16696af3c", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2019-03-10T15:35:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T17:09:02.000Z", "max_issues_repo_path": "Chapters/04_Bool_Functions.tex", "max_issues_repo_name": "grself/CIS221_Text", "max_issues_repo_head_hexsha": "e5d78f880e0bae66b33823ee22c68ed16696af3c", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-05-09T19:18:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-09T19:18:59.000Z", "max_forks_repo_path": "Chapters/04_Bool_Functions.tex", "max_forks_repo_name": "grself/CIS221_Text", "max_forks_repo_head_hexsha": "e5d78f880e0bae66b33823ee22c68ed16696af3c", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-01-20T17:30:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-20T06:06:00.000Z", "avg_line_length": 51.475465313, "max_line_length": 1018, "alphanum_fraction": 0.69715995, "num_tokens": 17659, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564152, "lm_q2_score": 0.8128673155708976, "lm_q1q2_score": 0.7385857967938538}}
{"text": "\\section{Testing of Causal Graphs}\n\\label{sec:graph-testing}\n\n\\subsection{Testing observable assumptions}\n\\label{sec:observable-tests}\n\nIn the last section, we reviewed a process for creating an initial causal graph using expert opinion.\nCritically, after drafting a causal graph, we should test it against our available data.\nDoing so will add robustness and credibility to our final conclusions.\nThis is important because, if our graph captures inaccurate assumptions about the data generating process, then we have no reason to think that our conclusions from using the graph will be accurate.\n\nTo test our causal graphs against data, we will first test the implications of our graph that involve observable variables only.\nWe will defer the task of testing implications that involve unobserved / latent variables to later in this subsection.\nFor now, recall our discussion in Section \\ref{sec:graph-overview} about the two basic implications of causal graphs: marginal independence and conditional independence.\nIn both cases, direct testing of marginal or conditional independence amongst nodes in the causal graph may be difficult.\nIndeed, there are no direct tests of conditional independence that can detect all types of dependence, especially for continuous variables \\citep{bergsma_2004_testing, shah_2020_hardness}.\n\nAs a result of this hardness, there are a myriad of research efforts aimed at testing conditional independence.\nThese efforts rely on additional assumptions about the variables or the test statistic itself.\nSome researchers create tests under the assumption that one has access to an approximation of the conditional distribution of $X \\mid Z$ \\citep{candes_2018_panning, berrett_2019_conditional}.\nOther researchers designed conditional independence tests for general cases, assuming smoothness of the underlying data distributions and assuming accurate estimation of the distribution of the test statistic under the null hypothesis of conditional independence (e.g. \\citet{zhang_2012_kernel, strobl_2019_approximate}).\n\nIn this chapter, we will take an easier and less decisive route to testing independence.\nIf a pair of variables have conditionally or marginally independent distributions, then their statistical moments will also be conditionally or marginally independent.\nAccordingly, we will not test for marginal or conditional independence in distribution.\nWe will instead perform a more tractable test for marginal or conditional independence in means.\nIf the variables in question are not conditionally or marginally independent in their means, then we know they are not independent in their distributions.\nConversely, even if a set of variables are marginally or conditionally independent in their means, this \\textbf{does not} imply that the variables are independent in distribution.\nMean independence simply provides justification for placing greater belief in the variables being distributionally independent.\n\nThis approach of indirectly assessing distributional independence by testing mean independence is not new.\nThe following papers have all proposed and implemented such an idea: \\citet{burkart_2017_predictive, chalupka_2018_fast, inacio_2019_conditional}.\nFor conditional independencies, the crux of the approach is to predict $Y$ based on $X$ and $Z$.\nThen, compare against a prediction of $Y$ based on a resampled value of $X$ and the original $Z$.\nIf $Y$ is mean-independent of $X$ given $Z$, i.e. $E \\left[ Y \\mid X, Z \\right] = E\\left[ Y \\mid Z \\right]$, then the predictive power of a model with resampled $X$ should resemble the predictive power of a model with the original $X$.\nAfter all, in both cases, the conditional expectation of $Y$ is independent of our $X$ values (real or resampled).\nWhen assessing marginal independencies, we removes $Z$ from the models for the expectation of $Y$ and proceed as described.\n\nNote that as with the case of testing distributional independence, testing mean independence still requires researchers to make choices.\nFirst, we have to select models for $E \\left[ Y \\mid X, Z \\right]$ and $E\\left[ Y \\mid Z \\right]$, respectively, for testing conditional and marginal mean-independence.\nSecond, we have to choose the performance statistic (e.g. $R^2$, log-likelihood, etc.) to compare these models.\nLastly, we also have to select a resampling method.\nIn particular, how (if at all) will our resampling strategy account for the possible dependence between $X$ and $Z$?\n\n% State the choices made in this work.\n% Provide some discussion of the alternatives and the effects of different choices.\nFor our demonstration, we made the following choices.\nFirst, we used linear regressions to model $E \\left[Y \\mid X, Z \\right]$ and $E \\left[ Y \\mid Z \\right]$.\nSecond, we used $R^2$ as our test statistic for judging the regressions' predictive performances.\nThird, we resampled $X$ without replacement, keeping the length of the resampled vector equal to the length of the original vector.\nIn other words, we permuted $X$.\nFinally, we visualized our tests by encoding our observed test-statistic as a vertical line and by plotting the kernel density estimate of our test statistic's distribution.\n\nOur rationales for these choices are as follows.\nIn our dataset, most of our explanatory variables were continuous (at least in theory).\nAccordingly, $R^2$ seemed a sensible performance metric for a model of the conditional expectation of a continuous random variable.\n\nIn contrast to our choice of performance metric, we chose our conditional expectation models and resampling methods through empirical testing.\nIn particular, we created simulations to assess our mean-independence testing procedure.\nWe assessed the performance of our mean-independence testing procedures using simulations where $Y \\leftarrow Z \\rightarrow X$ and $X$ either did or did not cause $Y$.\n\nOf particular importance were our simulations under the null hypothesis where $X$ was conditionally independent of $Y$.\nOur initial simulations used random forests as our conditional expectation models and permutations as resampling methods.\nRandom forests are a non-parametric method that would allow us to have less fear of model misspecification, and permutations are easy to implement.\nHowever, under the null hypothesis, the random forest-based tests resulted in non-uniform p-values.\nSuch non-uniform p-values makes it harder to a-priori reject a false model \\citep{gelman_2013_two}.\nWhen we switched from the combination of random forests and permutations to linear regressions and permutations, our p-values turned out to be empirically, uniformly distributed.\nMoreover, we still retained high statistical power.\n\nWe do not claim that these choices for assessing mean independence will always be appropriate.\nIndeed, one should assess one's tests on simulated data that resembles one's real data.\nFor our dataset and simulations though, the combination of linear regressions, permutations, and $R^2$ resulted in adequate tests of marginal and conditional mean-independence.\n\n\\subsection{Demonstration}\n\\label{sec:testing-demonstration}\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.85\\textwidth]{drive-alone-utility-graph}\n   \\caption{Expository causal graph of drive alone utility}\n   \\label{fig:graph-for-testing}\n\\end{figure}\n% Illustrative causal graph\nTo demonstrate the testing procedures described above, we used the causal graph in Figure \\ref{fig:graph-for-testing}.\nThis causal graph shows a set of hypothesized causal relationships between variables thought to contribute to the utility of the drive-alone travel alternative in our dataset.\nAs drawn, this graph encodes multiple marginal and conditional independence assumptions.\nLuckily, tools such as Daggity \\citep{textor_2016_robust} can infer all independencies based on one's graph.\nFor didactic purposes, however, we focused our attention on two particular independence assumptions.\n\nFirst, we tested the assumption of marginal independence between the number of licensed drivers and the number of automobiles in a household.\nA-priori, we assign low probability to this independence.\nGenerally, we expect the number of automobiles to be positively related to the number of licensed drivers in a household.\nSecondly, we tested the assumption that travel cost was independent of travel time, conditional on travel distance.\nUnlike the previous independence assertion, this conditional independence is a-priori more credible.\nIn both cases, we will test our assumptions using the previous subsection's procedures.\n\n% Marginal testing results\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.5\\textwidth]{mit--num_drivers_vs_num_autos}\n   \\caption{Marginal independence test results for the number of cars and licensed drivers in a household}\n   \\label{fig:marginal-independence-test}\n\\end{figure}\n\nIn particular, Figure \\ref{fig:marginal-independence-test} shows the results of using permutation, linear regression, and $R^2$ to test the hypothesis of marginal independence between the number of automobiles and the number of licensed drivers in a household.\nThe empirical p-value of 0 confirms that the observed data is unlikely given the null-hypothesis of marginal, mean-independence.\nMore specifically, when regressing the number of licensed drivers in a household on the number of cars in that household, one achieves an $R^2$ near 0.4.\nIn contrast, when permuting the number of cars in the household and re-estimating the regression, the distribution of p-values concentrates around 0.\nThis plot visualizes the fact that---through the lens of our chosen test statistic ($R^2$), linear regression model, and permutation-based resampling strategy---data generated under an assumption of marginal mean-independence does not ``look like'' the observed data.\nAccordingly, we should consider the weaker assumption of marginal dependence.\nThis relaxation may contain data-generating assumptions that better reflect our observations.\n\n% Conditional testing results\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.5\\textwidth]{cit--time_vs_cost_given_distance}\n   \\caption{Conditional independence test results for travel time and travel cost given travel distance}\n   \\label{fig:conditional-independence-test}\n\\end{figure}\nIn Figure \\ref{fig:conditional-independence-test}, we have an analogous visualization of a conditional independence test.\nHere, we test the hypothesis that travel time is mean-independent of travel cost, conditional on travel distance.\nTo execute this test, we model the conditional expectation of travel time as a linear function of travel cost and travel distance.\nAs with the marginal independence test results, the $R^2$ of the model using the observed values of travel cost are greater than the model's $R^2$ using any simulated datasets.\nIn fact, the simulated $R^2$ values are so tightly distributed between $0.9371$ and $0.9373$ that the distribution is not visible in relation to the observed value of $0.95$.\nAgain, this means that the $R^2$ using observed data is unlikely given our method of sampling from the null distribution of $R^2$ given conditional, mean-independence of travel time and travel cost.\n\nAs before, these results suggest conditional dependence between our variables of interest.\nIn particular, we should investigate how travel time and travel cost relate, conditional on travel distance.\nWhy might this be the case?\nDoes travel time cause travel cost when driving alone?\nDoes travel cost cause travel time while driving alone?\nDoes some other set of variables (potentially unmeasured) cause both travel time and travel cost?\n\nThinking through these questions, we can immediately think of latent variables that cause both travel time, travel cost, and the choice, even after conditioning on one's travel distance.\nFor example, consider whether one drives alone over the San Francisco Bay Bridge.\nIf one crosses the bridge, then traffic delays will likely increase one's travel time.\nMoreover, if one crosses the bridge, then one's travel cost is higher due to tolls that one must pay.\nAnd finally, if one takes a toll lane to get across the bridge faster, then one also pays a higher price.\nOverall, intuitive explanations exist for conditional dependence between travel time and travel cost.\nThese explanations suggest particular relationships to analyze and particular variables, such as bay bridge crossings, to include in one's mode choice (i.e. outcome) model.\n\n\\subsection{Testing assumptions involving latent variables}\n\\label{sec:latent-tests}\n% Describe latent variable testing\nNow that we have described testing with observable variables, we can more easily describe conditional independence tests that involve unobserved (i.e., latent) variables.\nIndeed, when dealing with observational data, we will frequently find ourselves not having observed all variables that are of interest.\nNevertheless, we still wish to test whether our data contradicts our graph.\nOne way to directly extend our conditional independence testing to account for latent variables is to adopt a missing data perspective and impute the latent variables from a prior distribution.\nIn particular, we can generalize our previous tests as follows.\n\nFirst, we can consider expanding our test.\nInstead of performing one test with a set of observed $X$, observed $Y$ and observed $Z$, we perform tests of observed $X$, observed $Y$, and imputed $Z$.\nThis recasts the randomness underlying the null-distribution in our original test statistic of $R^2$ as a function of our permutation of $Y$ and our imputation of $Z$.\nHere, we impute $Z$ by sampling from the prior or posterior distribution of $Z$, depending on whether we're testing independencies before or after performing inference on our model's parameters.\nMoreover, we'll now compute this test's p-value by averaging over the permutations and imputations.\nSpecifically, our p-value will be\n\\begin{equation}\nE_{\\textrm{samples, permutations}} \\left[ \\mathbb{I} \\left \\lbrace R^2 \\left( X, Y, Z_{\\textrm{sampled}} \\right) <  R^2 \\left( X_{\\textrm{sampled}}, Y_{\\textrm{sampled}} ^{\\textrm{permuted}}, Z_{\\textrm{sampled}} \\right) \\right \\rbrace \\right]\n\\end{equation}\nwhere $\\mathbb{I}$ represents the indicator function that equals one if the condition inside its braces is true and zero otherwise.\nFor reference, this is the same as the p-value for test statistics (or discrepancies) defined in \\citet[Eq. 7]{gelman_1996_posterior}.\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.85\\textwidth]{deconfounder-causal-graph}\n   \\caption{Causal graph from applying the deconfounder algorithm \\citep{wang_2019_blessings} to our dataset.}\n   \\label{fig:deconfounder-graph}\n\\end{figure}\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.5\\textwidth]{latent-drivers-vs-num-autos}\n   \\caption{Results of testing that the number of drivers is independent of the number of automobiles in the household, conditional on the latent variable.}\n   \\label{fig:latent-cit-results}\n\\end{figure}\n\nLastly, note that our ``observed'' test statistic is itself a random variable: it depends on the imputed values of $Z$.\nBecause we now have a distribution of observed test statistics, we change our visualization method.\nInstead of plotting a single line versus a distribution, we now plot two distributions against one another.\nWe first plot the distribution of ``observed'' test statistics that we computed using the observed $X$, observed $Y$ and imputed $Z$ values.\nThen, we plot the distribution of ``sampled'' test statistics using prior samples of $\\left( X, Y, Z \\right)$ as a reference.\nHere, we have one value per imputed vector $Z$ in both the observed and sampled distributions.\nHowever, for the distribution of ``sampled'' test statistics, we marginalize over permutations of $Y$ since this distribution represents the null hypothesis of conditional or marginal independence.\n\nThat last paragraph may have been confusing, so we'll walk through an example.\nHere, we apply the deconfounder algorithm of \\citet{wang_2019_blessings} to our data.\nIn particular, Figure \\ref{fig:deconfounder-graph} shows the deconfounder's assumed causal graph.\nNote, we describe this application more thoroughly in Section \\ref{sec:latent-confounding}.\nFor now, we present the graph to highlight the assumptions that we will test.\nSpecifically, we'll examine the assumption that the observed number of licensed drivers in a household is independent of the observed number of automobiles in that household, conditional on the latent variable $X^{*}$.\n\nFigure \\ref{fig:latent-cit-results} shows the result of following the aforementioned testing procedures for assumptions involving latent variables.\nFrom the Figure, we see that the distribution of ``observed'' test statistics clusters around zero while the distribution of ``sampled'' test statistics is closer to uniform.\nThis result highlights the fact that (generally) there is ``no free lunch'': our approach to testing assumptions involving latent variables has its drawbacks.\nIn particular, these tests are sensitive to assumptions about the joint prior distribution, $P_{\\textrm{prior}} \\left( X, Y, Z \\right)$.\n\nIf, as in this case\\footnote{Details of the prior predictive checks that show prior-data mismatch are not shown due to space constraints. Please see \\url{https://github.com/hassan-obeid/tr_b_causal_2020/blob/master/notebooks/final/_04-tb-testing-your-causal-graph.ipynb}}, the observed data $\\left( X, Y \\right)$ is unlikely under the joint prior distribution $P_{\\textrm{prior}} \\left( X, Y, Z \\right)$ then the conditional independence test is likely to fail.\nAs always, the failing test indicates that the observed data is unlike the simulated data used to make the reference distribution.\nUnfortunately, we are unsure of how much dissimilarity comes from conditional independence violations.\nThe observed data can differ distributionally from the simulated data in many ways.\nThis highlights the need for extensive prior predictive checking of one's assumed joint prior, $P_{\\textrm{prior}} \\left( X, Y, Z \\right)$, \\textit{before} using conditional independence tests on causal graphs with latent variables.\nSpecifically, we want our marginal priors $P_{\\textrm{prior}} \\left( X^{*} \\right) = \\int P_{\\textrm{prior}} \\left( X^{*} \\mid Z^{*} \\right) P \\left( Z^{*} \\right) \\partial Z^{*}$ to reasonably well represent the observed $X$ (and the same for $P_{\\textrm{prior}} \\left( Y^{*} \\right)$ and $Y$).\nThen, any remaining discrepancies between our observed data and our simulated data can be mainly attributed to their differing conditional independence properties.\n\n\\subsection{Additional techniques}\n\\label{sec:testing-addendum}\n\nThe methods presented in this section test independence assertions using one's dataset.\nWhile perhaps the most accessible strategy for testing one's causal graph, other techniques apply as well.\nFor instance, \\citet{pitchforth_2013_proposed} proposed a checklist of qualitative questions for one's causal graph.\nAnswering these questions should increase the trustworthiness of one's graph.\nAlternatively, there are other quantitative tests of one's causal graph that were not explored in this section.\n\nFor instance, causal graphs encode assumptions about the number of independent variables in one's data.\nThe independent variables are the parentless-nodes in one's graph.\nCrucially, each graph assumes a particular number of such parentless-nodes.\nTo test this assumption we first estimate our data's ``intrinsic dimension.''\nThen, we test whether the intrinsic dimension equals the number of parentless-nodes in our graph.\nFor more information on estimating the intrinsic dimension of a dataset, see \\citet{camastra_2016_intrinsic, song_2019_identification}.\nAdditionally, see \\citet{chenwei_2019_likelihood} for an extension of this idea when we cannot rule out unobserved confounding.\n\n% Test vanishing tetrads / t-separation\nAnother empirical implication of one's causal graph is the existence of so-called ``vanishing tetrads'' \\citep{spearman_1904_general}.\nThis term signifies that the difference between the product of two particular pairs of covariances must be zero.\nAs stated, this implication of one's causal graph is hard to intuitively understand.\nHowever, one can graphically determine the existence of vanishing tetrads and determine which variables are part of these tetrads.\nThen, one can estimate the necessary covariances and test to see if their difference of products is indeed unlikely to be zero.\nSuch a test is yet another way to empirically determine whether one's graph is incompatible with one's dataset.\nFor the original theorems proving that tetrads can be graphically identified and characterized, see \\citet{shafer_1996_vanishing} and references therein.\nFor a more detailed and intuitive explanation of the graphical criterion for vanishing tetrads, see \\citet{thoemmes_2018_local}.\n\n% Test functional inequalities / constraints, i.e. entropy constraints / inflation technique\nFinally, we note that there are still a whole host of other techniques for testing one's causal graphs.\nMany of these remaining techniques are useful when one's causal graph contains unobserved (i.e., latent) variables.\nOn one hand, we can use ``triad constraint'' tests that test independence between ``pseudo-residual'' values and one's explanatory variables \\citep{cai_2019_triad}.\nResults from these tests are useful for judging how unobserved variables in our graph relate to each other and to our observed variables.\n\nRelatedly, one can make use of constraints on entropies of our observed variables instead of independencies.\nThe idea is that differing latent variable graphs imply differing entropies in our observed variables.\nAccordingly, we test for these entropies and constraints.\nFor more information and examples, see the literature about:\n\\begin{itemize}\n  \\item inequality constraints, e.g. \\citet{tian_2002_testable, kang_2006_inequality, ver_2011_sequence}\n  \\item information inequalities, e.g. \\citet{chaves_2014_inferring}\n  \\item entropic inequalities, e.g. \\citet{chaves_2014_causal}\n  \\item the inflation technique, e.g. \\citet{wolfe_2019_inflation, navascues_2020_inflation}\n\\end{itemize}\n", "meta": {"hexsha": "e8d198b88aab31d79294af1752cfa33837b8298f", "size": 22271, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "article/sections/_5_graph_testing.tex", "max_stars_repo_name": "hassanobeid1994/tr_b_causal_2020", "max_stars_repo_head_hexsha": "1ffaeb7dcefccf5e1f24c459e9a2f140b2a052a5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "article/sections/_5_graph_testing.tex", "max_issues_repo_name": "hassanobeid1994/tr_b_causal_2020", "max_issues_repo_head_hexsha": "1ffaeb7dcefccf5e1f24c459e9a2f140b2a052a5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 89, "max_issues_repo_issues_event_min_datetime": "2020-02-10T02:52:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-23T03:50:27.000Z", "max_forks_repo_path": "article/sections/_5_graph_testing.tex", "max_forks_repo_name": "hassan-obeid/tr_b_causal_2020", "max_forks_repo_head_hexsha": "1ffaeb7dcefccf5e1f24c459e9a2f140b2a052a5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 89.8024193548, "max_line_length": 461, "alphanum_fraction": 0.8037807014, "num_tokens": 4833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.7385094155772621}}
{"text": "%!TEX root = guide2.0.tex\n\n\\hypertarget{monte-carlo-methods-in-bayesian-analysis}{}\n\\pdfbookmark[0]{Monte Carlo Methods in Bayesian Analysis}{monte-carlo-methods-in-bayesian-analysis}\n\n\\section{Monte Carlo Methods in Bayesian Analysis}\n\nBayesian analysis often requires integration over multiple dimensions that is intractable both via analytic methods or standard methods of numerical integration. However, it is often possible to compute these integrals by simulating (drawing samples) from posterior distributions. For example, consider the expected value of a random variable $\\mathbf{x}$:\n\n\\[\nE[{\\bf x}] = \\int {\\bf x} f({\\bf x}) d{\\bf x}, \\qquad\n{\\bf x} = \\{x_1,...,x_k\\}\n\\]\n\n\\noindent where $k$ (the dimension of vector $x$) is perhaps very large. If we can produce a reasonable number of random vectors $\\{{\\bf x_i}\\}$, we can use these values to approximate the unknown integral. This process is known as {\\em Monte Carlo integration}. In general, MC integration allows integrals against probability density functions:\n\n\\[\nI = \\int h(\\mathbf{x}) f(\\mathbf{x}) \\mathbf{dx}\n\\]\n\n\\noindent to be estimated by finite sums:\n\n\\[\n\\hat{I} = \\frac{1}{n}\\sum_{i=1}^n h(\\mathbf{x}_i),\n\\]\n\n\\noindent where $\\mathbf{x}_i$ is a sample from $f$. This estimate is valid and useful because:\n\n\\begin{itemize}\n\\item\nBy the strong law of large numbers:\n\\[\\hat{I} \\rightarrow I   \\mbox{   with probability 1}\\]\n\\item\nSimulation error can be measured and controlled:\n\\[Var(\\hat{I}) = \\frac{1}{n(n-1)}\\sum_{i=1}^n (h(\\mathbf{x}_i)-\\hat{I})^2\\]\n\\end{itemize}\n\nWhy is this relevant to Bayesian analysis? If we replace $f(\\mathbf{x})$ with a posterior, $f(\\theta|d)$ and make $h(\\theta)$ an interesting function of the unknown parameter, the resulting expectation is that of the posterior of $h(\\theta)$:\n\n\\[\nE[h(\\theta)|d] = \\int f(\\theta|d) h(\\theta) d\\theta \\approx \\frac{1}{n}\\sum_{i=1}^n h(\\theta)\n\\]\n\n%___________________________________________________________________________\n\n\\hypertarget{rejection-sampling}{}\n\\pdfbookmark[1]{Rejection Sampling}{rejection-sampling}\n\\subsection{Rejection Sampling}\n\nThough Monte Carlo integration allows us to estimate integrals that are unassailable by analysis and standard numerical methods, it relies on the ability to draw samples from the posterior distribution. For known parametric forms, this is not a problem; probability integral transforms or bivariate techniques (e.g Box-Muller method) may be used to obtain samples from uniform pseudo-random variates generated from a computer. Often, however, we cannot readily generate random values from non-standard posteriors. In such instances, we can use rejection sampling to generate samples.\n\n\\begin{figure}[ht]\n        \\begin{center}\n        \\includegraphics[scale=0.4]{reject.png}\n    \\end{center}\n    \\caption{Rejection sampling of a bounded form. Area is estimated by the ratio of accepted (open squares) to total points, multiplied by the rectangle area.}\n    \\label{fig:bound}\n\\end{figure}\n\nPosit a function, $f(x)$ which can be evaluated for any value on the support of $x:S_x = [A,B]$, but may not be integrable or easily sampled from. If we can calculate the maximum  value of $f(x)$, we can then define a rectangle that is guaranteed to contain all possible values $(x,f(x))$. It is then trivial to generate points over the box and enumerate the values that fall under the curve (Figure \\ref{fig:bound}).\n\n\\[\n\\frac{\\mbox{Points under curve}}{\\mbox{Points generated}} \\times \\mbox{box area} = \\lim_{n \\to \\infty} \\int_A^B f(x) dx\n\\]\n\n\\begin{figure}[h]\n        \\begin{center}\n        \\includegraphics[scale=0.4]{envelope.png}\n    \\end{center}\n    \\caption{Rejection sampling of an unbounded form using an enveloping distribution.}\n    \\label{fig:unbound}\n\\end{figure}\n\n\\noindent This approach is useful, for example, in estimating the normalizing constant for posterior distributions.\n\nIf $f(x)$ has unbounded support (i.e. infinite tails), such as a Gaussian distribution, a bounding box is no longer appropriate. We must specify a majorizing (or, enveloping) function, $g(x)$, which implies:\n\n\\[\ng(x) \\ge  f(x) \\qquad\\forall x \\in (-\\infty,\\infty)\n\\]\n\nHaving done this, we can now sample ${x_i}$ from $g(x)$ and accept or reject each of these values based upon $f(x_i)$. Specifically, for each draw $x_i$, we also draw a uniform random variate $u_i$ and accept $x_i$ if $u_i < f(x_i)/cg(x_i)$, where $c$ is a constant (Figure \\ref{fig:unbound}). This approach is made more efficient by choosing an enveloping distribution that is ``close'' to the target distribution, thus maximizing the number of accepted points. Further improvement is gained by using optimized algorithms such as importance sampling which, as the name implies, samples more frequently from important areas of the distribution.\n\nRejection sampling is usually subject to declining performance as the dimension of the parameter space increases, so it is used less frequently than MCMC for evaluation of posterior distributions \\citep{Gamerman:1997tb}.\n\n%___________________________________________________________________________\n\n\\hypertarget{markov-chains}{}\n\\pdfbookmark[0]{Markov Chains}{markov-chains}\n\\section{Markov Chains}\n\nA Markov chain is a special type of \\emph{stochastic process}. The standard definition of a stochastic process is an ordered collection of random variables:\n\n\\[\n\\{X_t:t \\in T\\}\n\\]\n\n\\noindent where $t$ is frequently (but not necessarily) a time index. If we think of $X_t$ as a state $X$ at time $t$, and invoke the following dependence condition on each state:\n\n\\[\nPr(X_{t+1}=x_{t+1} | X_t=x_t, X_{t-1}=x_{t-1},\\ldots,X_0=x_0) = Pr(X_{t+1}=x_{t+1} | X_t=x_t)\n\\]\n\n\\noindent then the stochastic process is known as a Markov chain. This conditioning specifies that the future depends on the current state, but not past states. Thus, the Markov chain wanders about the state space, remembering only where it has just been in the last time step. The collection of transition probabilities is sometimes called a \\emph{transition matrix} when dealing with discrete states, or more generally, a \\emph{transition kernel}.\n\n\\noindent In the context of Markov chain Monte Carlo, it is useful to think of the Markovian property as ``mild non-independence''. MCMC allows us to indirectly generate independent samples from a particular posterior distribution.\n\n%___________________________________________________________________________\n\n\\hypertarget{jargon-busting}{}\n\\pdfbookmark[1]{Jargon-busting}{jargon-busting}\n\\subsection{Jargon-busting}\n\nBefore we move on, it is important to define some general properties of Markov chains. They are frequently encountered in the MCMC literature, and some will help us decide whether MCMC is producing a useful sample from the posterior.\n\n\\begin{itemize}\n\\item \\emph{Homogeneity}: A Markov chain is homogeneous at step $t$ if the transition probabilities are independent of time $t$.\n\\item \\emph{Irreducibility}: A Markov chain is irreducible if every state is accessible in one or more steps from any other state. That is, the chain contains no absorbing states. This implies that there is a non-zero probability of eventually reaching state $k$ from any other state in the chain.\n\\item \\emph{Recurrence}: States which are visited repeatedly are \\emph{recurrent}. If the expected time to return to a particular state is bounded, this is known as \\emph{positive recurrence}, otherwise the recurrent state is \\emph{null recurrent}. Further, a chain is \\emph{Harris recurrent} when it visits all states $X \\in S$ infinitely often in the limit as $t \\to \\infty$; this is an important characteristic when dealing with unbounded, continuous state spaces. Whenever a chain ends up in a closed, irreducible set of Harris recurrent states, it stays there forever and visits every state with probability one.\n\\item \\emph{Stationarity}: A stationary Markov chain produces the same marginal distribution when multiplied by the transition kernel.  Thus, if $P$ is some $n \\times n$ transition matrix:\n\n\\[{\\bf \\pi P} = {\\bf \\pi}\\]\n\n\\noindent for Markov chain $\\pi$. Thus, $\\pi$ is no longer subscripted, and is referred to as the \\emph{limiting distribution} of the chain. In MCMC, the chain explores the state space according to its limiting marginal distribution.\n\\item \\emph{Ergodicity}: Ergodicity is an emergent property of Markov chains which are irreducible, positive Harris recurrent and aperiodic. Ergodicity is defined as:\n\n\\[\n\\lim_{n \\to \\infty} Pr^{(n)}(\\theta_i \\rightarrow \\theta_j) = \\pi(\\theta) \\quad \\forall \\theta_i, \\theta_j \\in \\Theta\n\\]\n\n\\noindent or in words, after many steps the marginal distribution of the chain is the same at one step as at all other steps. This implies that our Markov chain, which we recall is dependent, can generate samples that are independent if we wait long enough between samples. If it means anything to you, ergodicity is the analogue of the strong law of large numbers for Markov chains. For example, take values $\\theta_{i+1},\\ldots,\\theta_{i+n}$ from a chain that has reached an ergodic state. A statistic of interest can then be estimated by:\n\n\\[\n\\frac{1}{n}\\sum_{j=i+1}^{i+n} h(\\theta_j) \\approx \\int f(\\theta) h(\\theta) d\\theta\n\\]\n\n\\end{itemize}\n\n%___________________________________________________________________________\n\n\\hypertarget{reversible-markov-chains}{}\n\\pdfbookmark[0]{Why MCMC Works: Reversible Markov Chains}{reversible-markov-chains}\n\\section{Why MCMC Works: Reversible Markov Chains}\n\nMarkov chain Monte Carlo simulates a Markov chain for which some function of interest (\\emph{e.g.} the joint distribution of the parameters of some model) is the unique, invariant limiting distribution. An invariant distribution with respect to some Markov chain with transition kernel $Pr(y \\mid x)$ implies that:\n\\[\n\\int_x Pr(y \\mid x) \\pi(x) dx = \\pi(y).\n\\]\n\nInvariance is guaranteed for any \\textbf{reversible} Markov chain. Consider a Markov chain in reverse sequence: $\\{\\theta^{(n)},\\theta^{(n-1)},...,\\theta^{(0)}\\}$. This sequence is still Markovian, because:\n\\[\nPr(\\theta^{(k)}=y \\mid \\theta^{(k+1)}=x,\\theta^{(k+2)}=x_1,\\ldots ) = Pr(\\theta^{(k)}=y \\mid \\theta^{(k+1)}=x)\n\\]\nForward and reverse transition probabilities may be related through Bayes theorem:\n\\begin{eqnarray}\nPr(\\theta^{(k)}=y \\mid \\theta^{(k+1)}=x) &=& \\frac{Pr(\\theta^{(k+1)}=x \\mid \\theta^{(k)}=y) Pr(\\theta^{(k)}=y)}{Pr(\\theta^{(k+1)}=x)} \\nonumber \\\\\n&=& \\frac{Pr(\\theta^{(k+1)}=x \\mid \\theta^{(k)}=y) \\pi^{(k)}(y)}{\\pi^{(k+1)}(x)} \\nonumber\n\\end{eqnarray}\n\n\\[\n\\frac{Pr(\\theta^{(k+1)}=x \\mid \\theta^{(k)}=y) \\pi^{(k)}(y)}{\\pi^{(k+1)}(x)}\n\\]\n\n\\noindent Though not homogeneous in general, $\\pi$ becomes homogeneous if \\textbf{Do you ever call the stationary distribution itself homogeneous?}:\n\\begin{itemize}\n\\item $n \\rightarrow \\infty$\n\\item $\\pi^{(0)}=\\pi$ for some $i < k$ \\textbf{Is it meant to be $\\pi^(i)$, and }\n\\end{itemize}\n\n\\noindent If this chain is homogeneous it is called reversible, because it satisfies the \\textbf{detailed balance equation}:\n\\[\n\\pi(x)Pr(y \\mid x) = \\pi(y) Pr(x \\mid y)\n\\]\nReversibility is important because it has the effect of balancing movement through the entire state space. When a Markov chain is reversible, $\\pi$ is the unique, invariant, stationary distribution of that chain.\nHence, if $\\pi$ is of interest, we need only find the reversible Markov chain for which $\\pi$ is the limiting distribution. This is what MCMC does!\n\n%___________________________________________________________________________\n\n\\hypertarget{gibbs-sampling}{}\n\\pdfbookmark[0]{Gibbs Sampling}{gibbs-sampling}\n\\section{Gibbs Sampling}\n\nThe Gibbs sampler is the simplest and most prevalent MCMC algorithm. If a posterior has $k$ parameters to be estimated, we may condition each parameter on current values of the other $k-1$ parameters, and sample from the resultant distributional form (usually easier), and repeat this operation on the other parameters in turn. This procedure generates samples from the posterior distribution. Note that we have now combined Markov chains (conditional independence) and Monte Carlo techniques (estimation by simulation) to yield Markov chain Monte Carlo.\n\nHere is a stereotypical Gibbs sampling algorithm:\n\n\\newcounter{lcount}\n\\begin{list}{\\arabic{lcount}}\n{\\usecounter{lcount}}\n\\item Choose starting values for states (parameters): ${\\bf \\theta} = [\\theta_1^{(0)},\\theta_2^{(0)},\\ldots,\\theta_k^{(0)}]$\n\\item Initialize counter $j=1$\n\\item Draw the following values from each of the $k$ conditional distributions:\n\\begin{eqnarray*}\n\\theta_1^{(j)} &\\sim& \\pi(\\theta_1 | \\theta_2^{(j-1)},\\theta_3^{(j-1)},\\ldots,\\theta_{k-1}^{(j-1)},\\theta_k^{(j-1)}) \\\\\n\\theta_2^{(j)} &\\sim& \\pi(\\theta_2 | \\theta_1^{(j)},\\theta_3^{(j-1)},\\ldots,\\theta_{k-1}^{(j-1)},\\theta_k^{(j-1)}) \\\\\n\\theta_3^{(j)} &\\sim& \\pi(\\theta_3 | \\theta_1^{(j)},\\theta_2^{(j)},\\ldots,\\theta_{k-1}^{(j-1)},\\theta_k^{(j-1)}) \\\\\n\\vdots \\\\\n\\theta_{k-1}^{(j)} &\\sim& \\pi(\\theta_{k-1} | \\theta_1^{(j)},\\theta_2^{(j)},\\ldots,\\theta_{k-2}^{(j)},\\theta_k^{(j-1)}) \\\\\n\\theta_k^{(j)} &\\sim& \\pi(\\theta_k | \\theta_1^{(j)},\\theta_2^{(j)},\\theta_4^{(j)},\\ldots,\\theta_{k-2}^{(j)},\\theta_{k-1}^{(j)})\n\\end{eqnarray*}\n\\item Increment $j$ and repeat until convergence occurs.\n\\end{list}\n\nAs we can see from the algorithm, each distribution is conditioned on the last iteration of its chain values, constituting a Markov chain as advertised. The Gibbs sampler has all of the important properties outlined in the previous section: it is aperiodic, homogeneous and ergodic. Once the sampler converges, all subsequent samples are from the target distribution. This convergence occurs at a geometric rate.\n\n\\hypertarget{the-metropolis-hastings-algorithm}{}\n\\pdfbookmark[0]{The Metropolis-Hastings Algorithm}{the-metropolis-hastings-algorithm}\n\\section{The Metropolis-Hastings Algorithm}\n\nThe key to success in applying the Gibbs sampler to the estimation of Bayesian posteriors is being able to specify the form of the complete conditionals of ${\\bf \\theta}$. In fact, the algorithm cannot be implemented without them. Of course, the posterior conditionals cannot always be neatly specified. In contrast to the Gibbs algorithm, the Metropolis-Hastings algorithm generates candidate state transitions from an alternate distribution, and accepts or rejects each candidate probabilistically.\n\nLet us first consider a simple Metropolis-Hastings algorithm for a single parameter, $\\theta$. We will use a standard sampling distribution, referred to as the \\emph{proposal distribution}, to produce candidate variables $q_t(\\theta^{\\prime} | \\theta)$. That is, the generated value, $\\theta^{\\prime}$, is a \\emph{possible} next value for $\\theta$ at step $t+1$. We also need to be able to calculate the probability of moving back to the original value from the candidate, or $q_t(\\theta | \\theta^{\\prime})$. These probabilistic ingredients are used to define an \\emph{acceptance ratio}:\n\n\\[\na(\\theta^{\\prime},\\theta) = \\frac{q_t(\\theta^{\\prime} | \\theta) \\pi(\\theta^{\\prime})}{q_t(\\theta | \\theta^{\\prime}) \\pi(\\theta)}\n\\]\n\n\\noindent The value of $\\theta^{(t+1)}$ is then determined by:\n\n\\[\n\\theta^{(t+1)} = \\left\\{\\begin{array}{l@{\\quad \\mbox{with prob.} \\quad}l}\\theta^{\\prime} & \\min(a(\\theta^{\\prime},\\theta),1) \\\\ \\theta^{(t)} & 1 - \\min(a(\\theta^{\\prime},\\theta),1) \\end{array}\\right.\n\\]\n\n\\noindent This transition kernel implies that movement is not guaranteed at every step. It only occurs if the suggested transition is likely based on the acceptance ratio.\n\nA single iteration of the Metropolis-Hastings algorithm proceeds as follows:\n\n\\newcounter{lcount2}\n\\begin{list}{\\arabic{lcount2}}\n{\\usecounter{lcount2}}\n\\item Sample $\\theta^{\\prime}$ from $q(\\theta^{\\prime} | \\theta^{(t)})$.\n\\item Generate a Uniform[0,1] random variate $u$.\n\\item If $a(\\theta^{\\prime},\\theta) > u$ then $\\theta^{(t+1)} = \\theta^{\\prime}$, otherwise $\\theta^{(t+1)} = \\theta^{(t)}$.\n\\end{list}\n\n\\noindent The original form of the algorithm specified by Metropolis required that $q_t(\\theta^{\\prime} | \\theta) = q_t(\\theta | \\theta^{\\prime})$, which reduces $a(\\theta^{\\prime},\\theta)$ to $\\pi(\\theta^{\\prime})/\\pi(\\theta)$, but this is not necessary. In either case, the state moves to high-density points in the distribution with high probability, and to low-density points with low probability. After convergence, the Metropolis-Hastings algorithm describes the full target posterior density, so all points are recurrent.\n\n%___________________________________________________________________________\n\n\\hypertarget{random-walk-metropolis-hastings}{}\n\\pdfbookmark[1]{Random-walk Metropolis-Hastings}{random-walk-metropolis-hastings}\n\\subsection{Random-walk Metropolis-Hastings}\n\nA practical implementation of the Metropolis-Hastings algorithm makes use of a random-walk proposal. Recall that a random walk is a Markov chain that evolves according to:\n\n\\begin{eqnarray*}\n\\theta^{(t+1)} &=& \\theta^{(t)} + \\epsilon_t \\\\\n\\epsilon_t &\\sim& f(\\phi)\n\\end{eqnarray*}\n\nAs applied to the MCMC sampling, the random walk is used as a proposal distribution, whereby dependent proposals are generated according to:\n\n\\[\nq(\\theta^{\\prime} | \\theta^{(t)}) = f(\\theta^{\\prime} - \\theta^{(t)}) = \\theta^{(t)} + \\epsilon_t\n\\]\n\nGenerally, the density generating $\\epsilon_t$ is symmetric about zero, resulting in a symmetric chain. Chain symmetry implies that $q(\\theta^{\\prime} | \\theta^{(t)}) = q(\\theta^{(t)} | \\theta^{\\prime})$, which reduces the Metropolis-Hastings acceptance ratio to:\n\n\\[\na(\\theta^{\\prime},\\theta) = \\frac{\\pi(\\theta^{\\prime})}{\\pi(\\theta)}\n\\]\n\nThe choice of the random walk distribution for $\\epsilon_t$ is frequently a normal or Student's $t$ density, but it may be any distribution that generates an irreducible proposal chain.\n\nAn important consideration is the specification of the scale parameter for the random walk error distribution. Large values produce random walk steps that are highly exploratory, but tend to produce proposal values in the tails of the target distribution, potentially resulting in very small acceptance rates. Conversely, small values tend to be accepted more frequently, since they tend to produce proposals close to the current parameter value, but may result in chains that mix very slowly. Some simulation studies suggest optimal acceptance rates in the range of 20-50\\%. It is often worthwhile to optimize the proposal variance by iteratively adjusting its value, according to observed acceptance rates early in the MCMC simulation \\citep{Gamerman:1997tb}.\n", "meta": {"hexsha": "7b0badb5fbbe6b67c70448367803ff9741d3bc96", "size": 18516, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/theory.tex", "max_stars_repo_name": "matthew-brett/pymc", "max_stars_repo_head_hexsha": "3a31613f056e7993a449d89bafef5fdaa40d47e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-12-03T09:42:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-06T19:23:29.000Z", "max_issues_repo_path": "docs/theory.tex", "max_issues_repo_name": "matthew-brett/pymc", "max_issues_repo_head_hexsha": "3a31613f056e7993a449d89bafef5fdaa40d47e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-09-27T02:00:41.000Z", "max_issues_repo_issues_event_max_datetime": "2016-09-27T02:15:32.000Z", "max_forks_repo_path": "docs/theory.tex", "max_forks_repo_name": "matthew-brett/pymc", "max_forks_repo_head_hexsha": "3a31613f056e7993a449d89bafef5fdaa40d47e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-10-27T13:27:32.000Z", "max_forks_repo_forks_event_max_datetime": "2017-10-27T13:27:32.000Z", "avg_line_length": 69.6090225564, "max_line_length": 761, "alphanum_fraction": 0.7450313243, "num_tokens": 4970, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.738509415577262}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Polynomial Long Division}\n\n\\objective{Use and known when to use polynomial and synthetic division}\n\n\nFirst, we recall long division.  Surprisingly, it can actually be more difficult than polynomial long division at times, so we should pick an easy example:\n\n\\vspace{5mm}\n\n\\longdiv{11}{3678}\n\nWe restrict our vision to the left two digits of the dividend, as we know that 11 will go 3 times into\n36.  We write a 3 above the 6, write 33 below the 36 and subtract it.  Next, we bring down the 7\nand do the same manner of work on 37.  The process repeats, but moves progressively right\nand we get an answer of 334, but with a remainder of 4.  Since we most want a number that\nwhen multiplied by 11 obtains 3678, we should write the answer as $334+\\frac{4}{11}$ because\n$\\left(334+\\frac{4}{11}\\right)(11) = 3678$.\n\n\nNow, polynomial long division is no different.  We start at the left edge of the dividend, and use \nonly the leading term of the divisor.\n\n\\polylongdiv[stage=3]{x^3-x^2+x-1}{x+1}\n\nWe only regarded the leading (left) edge of the larger polynomial.  In this case, that is $x^3$.  \nWe might ask ourselves, ``What do I need to multiply $x$ by to get to $x^3$?''.  \nThe answer is $x^2$.   That term is the first in our quotient, and we multiply it by \nthe entire divisor.  We subtract, and bring down the next term.\n\n\\polylongdiv[stage=4]{x^3-x^2+x-1}{x+1}\n\nThis process continues, only working on the left-edge as we go down.  \n\n\\polylongdiv[stage=13]{x^3-x^2+x-1}{x+1}\n\nThe final answer is $x^3-x^2+x-1 = (x+1)\\left(x^2-2x+3-\\cfrac{4}{x+1}\\right)$.\n\n\\subsection{Synthetic Division}\nOne might ask, ``Isn't there a faster way?'' and indeed there is.  Let us first consider\nhow we might compactify the polynomial.  Consider the first two terms, and look for\na common factor:\n$$\n(x^3-x^2)+x-1\n$$\nObviously, we can take out an $x^2$ from the first two terms.  Having condensed the\nfirst two terms into one (because multiplication does not increase the term count),\nnow consider the greatest common factor of the new first two term:\n$$\n\\left[x^2(x-1)+x\\right]-1\n$$\nEvery term has at least one $x$, so that can be safely factored out.  Look at what we have made,\ncalled \\textbf{nested form}:\n$$\nx\\left[(x-1)x+1\\right]-1\n$$\nSubstituting any value into this function now only involves multiplication and addition/subtraction,\never exponents.  This process can be represented in half-box, called \\textbf{synthetic division}\n\n\\polyhornerscheme[showvar=true,resultbottomrule=true,resultleftrule=true,resultrightrule=true,x=-1]{x^3-x^2+x-1}\n\nStudy this carefully, and notice how it is the same answer as the coefficients of the polynomial\nlong division problem.  There are lots of things to notice.  The technique with synthetic division is\nto remember that the first number falls straight down, but from then on we  ``multiply up, add down''.  \nIt is helpful to draw a box around the final number, to remember that it is special: it is the remainder.  \nReading right-to-left: 3 is the $x^0$ coefficient, $-2$ is on $x^1$, 1 is on $x^2$.  \nIn the long division, we divided by $x + 1$.  Here, we are plugging in a value, so it's $x + 1 = 0$, \nwhich is $x=-1$. \n\n\\begin{example}[Synthetic Division]\n\\exProblem\nGiven $g(x) = x^3-7x+6$, find $g(2)$.  What does this tell you about $\\frac{g(x)}{x-2}$?\n\n\\exSolution\nFirst, we write our box and the $x=$ we want to test:\\\\\n\n\n\\polyhornerscheme[showvar=true,stage=1,x=2]{x^3-7x+6}\n(Note the zero.  Failure to notice this is crucial mistake!)\n\n\nThe first number passes down freely:\n\\polyhornerscheme[showvar=true,tutor=true,stage=2,x=2]{x^3-7x+6}\n\n\nThen we ``multiply up...\n\\polyhornerscheme[showvar=true,tutor=true,stage=3,x=2]{x^3-7x+6}\n\n\n..., add down''\n\\polyhornerscheme[showvar=true,tutor=true,stage=4,x=2]{x^3-7x+6}\n\n\nand so on and so forth:\n\\polyhornerscheme[showvar=true,resultbottomrule=true,resultleftrule=true,resultrightrule=true,x=2]{x^3-7x+6}\n\nThe fact that the remainder is 0 is significant.  $(x-2)$ is a factor in $x^3-7x+6$.  We can write\nthis as $(x-2)(x^2+2x-3)=x^3-7x+6$.  The quadratic factors easily into (x+3)(x-1), leaving the\nentire cubic equation solved.\n\\end{example}\n\n\\subsection{Complex Zeros}\nWhat if nothing so need exists as a solution?  We might slightly alter our $g(x)$ to be\n$x^3-2x^2-7x+2$.  There is no easy factorization (grouping won't work).  We are forced\nto use more complicated algorithms.  In the past, mathematicians invented very complicated\nmethods for find, eliminating, and testing solutions to polynomial equations.  You will research\none of these in problem number one of the exercises.  But in our age, why not use a computer?\nIf done intelligently, we can get the same level of precision as in the past.\n\nFor example, if you take our new $g(x)$ and put it in your TI-8*, you can see --- either in the\nTABLE or on the graph --- that it passes through (-3,0), which should lead you to want to\nfactor out (x+3).  You can use synthetic division as so:\n\n\n\\polyhornerscheme[showvar=true,resultbottomrule=true,resultleftrule=true,resultrightrule=true,x=-3]{x^3-2x^2-7x+24}\n\nThis proves that $(x+3)(x^2-5x+8)=x^3-2x^2-7x+24$.  However, now we have a new problem: how\ncan we solve $x^2-5x+8=0$?  It is not factorable.  Well, any quadratic can be solved with\nthe quadratic formula, so that will have to do.\n\n$$\nx=\\frac{5\\pm\\sqrt{(-5)^2-4(1)(8)}}{2\\cdot{}1}\n=\\frac{5\\pm i\\sqrt{7}}{2}\n$$\n\nAs you can see, unfactorable quadratics will always have some quantity inside the square root,\nonce plugged into the quadratic formula.  This means they will produce either a pair of\nirrational solutions, or else a pair of complex (imaginary) ones.  This has other to prove\n(elsewhere) that such solutions \\emph{always} occur in pairs.\n\nFor example, if we are building a polynomial, and we know solutions include 2 and $3+2i$,\nthen we can be sure that $3-2i$ is also a solution.  What factor would produce such zeros?\nWell, x-2 is an obvious one, but what about the more difficult one?  If $x=3 \\pm 2i$, what\nwould have lead to two possibilities like that?\n\n\\begin{align*}\n  x & = 3 \\pm 2i\\\\\n  x - 3 & =  2i \\\\\n  (x-3)^2 & = -5\\\\\n  x^2-6x+9 &= -5\\\\\n  x^2-6x+14 &= 0\n\\end{align*}\n\nSince plus-or-minus solution come from square rooting, the inverse operation must be to\nsquare both sides.  $(+2i)(+2i) = (-2i)(-2i) = -5$, so writing plus or minus does not matter.\n", "meta": {"hexsha": "0b314db9aaf10e08b7979d9d16308a29a3664416", "size": 6368, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch06/0602.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch06/0602.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch06/0602.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.3197278912, "max_line_length": 155, "alphanum_fraction": 0.7231469849, "num_tokens": 1969, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117769928211, "lm_q2_score": 0.8933093954028816, "lm_q1q2_score": 0.7385093976778988}}
{"text": "\\chapter{Approximation properties of width-bounded ReLU DNN}\nIn this part, we will show a universal approximation theorem for width-bounded ReLU networks: width-(d+4) ReLU networks, where $d$ is the input dimension.\n\n\\begin{theorem}\n\t\\label{width-bdd}\n\tFor any Lebesgue-integrable function $f:\\mathbb{R}^d\\to\\mathbb{R}$ and any $\\epsilon>0$, there exists a fully-connected ReLU network $\\mathcal{A}$ with width at most $d+4$, such that the function \n\t$F_{\\mathcal{A}}$ represented by this network satisfies\n\t\\begin{equation}\n\t\\int_{\\mathbb{R}^d}|f(x)-F_{\\mathcal{A}}(x) |dx<\\epsilon\n\t\\end{equation}\n\\end{theorem}\nThe proof of the above theorem involves the following three steps,\n\\begin{enumerate}\n\t\\item Show that $f$ can be approximated by finite weighted sum of indicator functions on d-dimensional cubes.\n\t\\item  Use ReLU network to approximate an indicator function on an d-dimensional cube. \n\t\\item  Show that the constructed ReLU network can ``store\" the quantites and sum them up.\n\\end{enumerate}\n The first step can be shown by the knowledge from real analysis.\n \n As for the second step, let us consider the easy case in 1D to demonstrate the idea. Given $[a,b]$, the goal now is to use ReLU function to approximate the indicator function $\\chi_{[a,b]}$.\n \n For $1/2>\\delta>0$, consider the interval $[a+\\delta(b-a),b-\\delta(b-a)]$, we can construct a ReLU network $r(x)$ such that \n $$\n r(x)=1\\quad x\\in[a+\\delta(b-a),b-\\delta(b-a)],\\quad r(x)=0\\quad x\\notin[a,b]\n $$\n Define \n $$\n r(x)=ReLU(ReLU(1-ReLU(\\frac{x-(b-\\delta(b-a))}{\\delta(b-a)}))-ReLU(1-ReLU(\\frac{x-a}{\\delta(b-a)})))\n $$\n Actually the last ReLU can be removed, but in order to be consistent with the structure of ReLU DNN, we write one ReLU function here to indicate one hidden layer.\n\nWith the above 1D example, now we can construct the ReLU network to approximate an indicator function on an d-dimensional cube. The key idea here is to do the procedure above one dimension by one dimension. Assume the cube is $[a_1,b_1]\\times[a_2,b_2]\\times\\cdots\\times[a_d,b_d]$ and suppose now we have constructed $r_k$ to approximate the indicator function on $[a_1,b_1]\\times[a_2,b_2]\\times\\cdots\\times[a_k,b_k]$. Now we define:\n\\begin{equation}\n\\begin{aligned}\n&r_{k+1}(x_1,\\dots,x_{k+1})\\\\\n=&ReLU(ReLU(r_k(x_1,\\dots,x_k)-ReLU(\\frac{x_{k+1}-(b_{k+1}-\\delta(b_{k+1}-a_{k+1}))}{\\delta(b_{k+1}-a_{k+1})}))\\\\\n&-ReLU(r_k(x_1,\\dots,x_k)-ReLU(\\frac{x_{k+1}-a_{k+1}}{\\delta(b_{k+1}-a_{k+1})})))\n\\end{aligned}\n\\end{equation}\nIt is easy to check that $r_{k+1}$ can be used to approximate the indicator function on $[a_1,b_1]\\times[a_2,b_2]\\times\\cdots\\times[a_{k+1},b_{k+1}]$.\n\nNow we proceed to the third step, where we combine all the indicator functions together with their weights. To do this, we need to consider again the $d+4$-width.\n\nThe first $d$ nodes in hidden layer are used to pass the information of the input. For the $d+1$-th and $d+2$-th nodes, we use them to store the information we get from $r_d$. And as for the last two nodes, they are used for the computation of $r_k$ functions. See \\cite{lu2017expressive} for detailed graph.\n\n\n\n", "meta": {"hexsha": "5b73b71896671a2291bcc192768d04d10d95c030", "size": 3112, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/width-bdd.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/width-bdd.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/width-bdd.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.8333333333, "max_line_length": 432, "alphanum_fraction": 0.7220437018, "num_tokens": 976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7384777284045562}}
{"text": "%---------------------------------------------------------------------------------\n\\chapter{Numerical methods}\n\\label{chap:numerical-methods}\n%---------------------------------------------------------------------------------\n\\section{Ordinary differential equation}\nAn ordinary differential equation (ODE) is an equation that contains derivatives of single independent variable functions. Examples of ODEs would be $\\frac{df}{dx}=-x$ and $\\frac{df}{dx} + \\frac{dg}{dx} = 4x$, where $x$ is an independent variable, $f$ and $g$ are functions of $x$. In general, ODEs are used to describe changes. One of the simplest example is speed, change in distance travelled per unit time. \n\nThere are different ways to describe an ODE. The order of an ODE is the order of the highest derivative in an ODE. The ODE $\\frac{d^3f}{dx^3} = -1$ has order 3. Other than the order, ODEs can be classified into linear or non-linear ODE. Linear ODEs are functions that can be expressed as linear combinations of derivatives, while non-linear ODEs cannot. The equation, $\\frac{df}{dx} \\frac{dg}{dx} = 1$, for example, is non-linear ODE; the equation $\\frac{df}{dx} + \\frac{dg}{dx} = 1$ is linear. Linear ODE can further be categorised into homogeneous and non-homogeneous ODEs. In a general linear ODE, $a_0(x)f(x)+a_1(x)f'(x)+...+a_n(x)f^{(n)}(x)+b(x) = 0$, the function is homogeneous if $b(x) = 0$ and non-homogeneous if $b(x) \\neq 0$.\n\nODEs are widely used in biological problem. An example of biological problem would be the SEIR model. The SEIR model describes the spread of a disease in a population with time $t$. The model compartmentalises the population into groups of susceptibles ($S$), exposed ($E$), infectious ($I$) and recovered ($R$). Transitions of individuals from groups are described by a system of ODEs, with independent variable time $t$. It is defined as \n\\begin{align}\n\\label{eqn:SEIR-model}\n    \\frac{dS(t)}{dt} &= -\\beta S(t)I(t),  \\\\ \n    \\frac{dE(t)}{dt} &= \\beta S(t)I(t) - \\kappa E(t), \\\\\n    \\frac{dI(t)}{dt} &= \\kappa E(t) - \\gamma I(t), \\\\\n    \\frac{dR(t)}{dt} &= \\gamma I(t) \\label{eqn:SEIR-end}\n\\end{align}\nwhere the parameters $\\beta$, $\\kappa$ and $\\gamma$ are infection rate, incubation rate and recovery rate respectively. The incidence cases, $N$ at time, $t$, is defined as the difference between the current total number of infected and recovered and that of the previous time, according to the equation\n\\begin{equation}\n    N(t) = I(t) + R(t) - I(t-1) - R(t-1)\n\\end{equation}\nFigure \\ref{fig:SEIR_simulation} shows the incidence cases simulated by the SEIR model.\n\n\\begin{figure}\n    \\includegraphics[width=0.95\\columnwidth]{SEIR_simulation}\n    \\caption{Simulation of the SEIR model. The bar graph shows the incidence number, while the line graph shows the number of individuals in each group. All values shown are in fractions of the whole population.}\n    \\label{fig:SEIR_simulation}\n\\end{figure}\n\nAnother example is the modelling of excitable systems. The heart muscle cells and nerve cells are excitable systems. The Hodgkin \\& Huxley model models the ionic currents across the cell membrane, to explain the action potential of nerve cells\\cite{Keener2009}.\nTheir model is defined as\n\\begin{equation}\n\\label{model:HH}\n    C_m \\frac{dV}{dt} = -g_{\\text{eff}}(V - V_{\\text{eq}}) + I_{\\text{app}} \\\\\n\\end{equation}\nwhere $C_m$ is membrane capacitance, $V$ is membrane potential, $g_{\\text{eff}}$ is sum of conductance for all ion channels, $V_{\\text{eq}}$ is membrane resting potential and $I_{\\text{app}}$ is applied current. Here, the independent variable is also time $t$. The value of potential is obtained by subtracting the membrane resting potential from the membrane potential, that is $V - V_{\\text{eq}}$. Figure \\ref{fig:AP_simulation} shows the simulated action potential of the Hodgkin and Huxley model. \n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=0.5\\columnwidth]{AP_simulation}\n    \\caption{The action potential in the Hodgkin and Huxley model, adapted from \\cite{Keener2009}.}\n    \\label{fig:AP_simulation}\n\\end{figure}\n\n\\section{Initial value problem}\nGiven an ODE system, we would like to solve for the function. As an example, given an ODE $\\frac{df(x)}{dx} = -f(x)$, we would like to know the function $f$. To solve ODE systems, initial conditions are required to pinpoint the solution of interest, as there are infinitely possible solutions to an ODE. The ODEs, together with the initial conditions, set up the initial value problem.\n\nA general form of an initial value problem is as follows: \n\\begin{align}\n\\label{eqn:initial_value_start}\n    y'&=f(x,y)\\\\\n    y(x_0) &= y_0 \\label{eqn:initial_value}\n\\end{align}\nfor $x \\in [x_0, X_M]$, where Eq.~\\eqref{eqn:initial_value} describes the initial condition. For example, initial values of $S(0)=0.8, E(0)=0, I(0)=0.1$ and $R(0)=0$ are used to solve the SEIR model in Figure \\ref{fig:SEIR_simulation}.\n\n\\section{Numerical method}\nMany ODE systems cannot be solved analytically. Some examples would be the given SEIR Model, Eqs.~\\eqref{eqn:SEIR-model}-\\eqref{eqn:SEIR-end} and Hodgkin \\& Huxley Model, Eq.~\\eqref{model:HH}. Solutions to such models have to be estimated by numerical methods.\n\nThroughout the report, the following notation will be used:\n\\begin{itemize}\n    \\item $y_n$ - numerical approximation of $y(x_n)$\n    \\item $y(x_n)$ - analytical solution at mesh point $x_n$\n    \\item $x_n$ - mesh points of defined range, where\n        \\begin{align}\n            x_n &= x_0 + nh\\\\\n            h &= \\frac{(X_M - x_0)}{N}\n        \\end{align}\n        for $n = 0,\\dots, N$\n    \\item $h$ - step size\n\\end{itemize}\n\n\\subsection{One-step methods}\n\\label{subsec:one-step-method}\nThe simplest numerical method in solving ODEs is Euler's explicit method. Intuitively, Euler's explicit method assumes for a small step size $h$, the solution of the function can be estimated by its tangent line. As seen in Figure \\ref{fig:Euler_method}, following the tangent line at point $x_0$, the difference between the $y$ value for point $x_0$ and point $x_1$ is $hF(x_0,y_0)$. So, the estimated value of $y_1$ is $y_0 + hF(x_0,y_0)$, where $y_0$ is the value of solution curve at $x_0$.\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=0.5\\columnwidth]{Euler_method_img}\n    \\caption{Intuition of Euler's method, adapted from \\cite{CalcWorkshop2019}.}\n    \\label{fig:Euler_method}\n\\end{figure}\n\nEuler's explicit method has the following definition,  \n\\begin{equation}\n    y_{n+1} = y_n + hf(x_n,y_n)\\\\\n\\end{equation}\nStarting from the initial value, the solution at the subsequent mesh point is estimated to follow a straight line with gradient as given.\n\nThe implementation is as follows:\n\n\\begin{algorithm}[H]\n    \\SetAlgoLined\n    \\SetKwInOut{Output}{Output}\n    \\Output{mesh points and its numerical solution}\n    solution = [initial value]\\;\n    meshpoints = [starting point]\\;\n    \\For{$n$ \\text{from} 1 \\text{to total number of mesh points}}{\n    solution.append(solution[$n-1$] + step size $\\times$ $f$(meshpoints[$n-1$], solution[$n-1$])\\;\n    meshpoints.append(meshpoints[$n-1$] + $n$ $\\times$ step size)\\;\n    }\n    \\Return{meshpoints and solution}\\;\n\\caption{Euler's explicit method}\n\\end{algorithm}\n\nA vector containing the numerical solution and a vector of mesh points are initialised with their respective initial values. At each iteration, the mesh point and the numerical solution at the mesh point are calculated. The series of mesh points and its solution are returned. The mesh points are returned for consistency of the software, where all methods return the same outputs. Adaptive methods does not have fixed step sizes, thus it is important to return the mesh points. \n\nTruncation error of the numerical methods is defined to be the difference between the exact solution and the numerical solution, assuming the exact solution at the previous mesh point is known. We have that the truncation error for Euler's explicit method is\n\n\\begin{equation}\n\\label{eqn:trun_err_def}\n    T_n \\defeq \\frac{y(x_{n+1}) - y(x_{n})}{h} - f(x_n, y(x_n))\n\\end{equation}\nAccording to Taylor's series expansion, we have \n\\begin{equation}\n\\label{eqn:Taylor_expansion}\n    y(x_n + h) = y(x_n) + hy'(x_n) + \\frac{1}{2}hy''(\\xi_n)\n\\end{equation}\nfor some $\\xi_n \\in (x_n, x_{n+1})$. Substitute (\\ref{eqn:Taylor_expansion}) to (\\ref{eqn:trun_err_def}), noting that $f(x_n, y(x_n)) = y'(x_n)$, we get\n\\begin{equation}\n    T_n = \\frac{1}{2}hy''(\\xi_n)\n\\end{equation}\nTherefore, the truncation error for Euler's explicit method varies linearly with the step size.\n\nA test problem\n\\begin{align}\n\\label{eqn:example_model}\n    f(x,y) &= -y \\\\\n    y(0) &= 1 \\label{eqn:example-end}\n\\end{align}\nfor $x \\in [0, 5]$ is used throughout this report to check that the implementation is in line with the theory. The analytical solution to this problem is $y = e^{-x}$. Some examples of solutions to the given test problem Eqs.~\\eqref{eqn:example_model}-\\eqref{eqn:example-end} can be found via this link: \\href{https://nbviewer.jupyter.org/github/FarmHJ/numerical-solver/blob/main/examples/solver_convergence.ipynb}{\\underline{\\emph{test problem notebook}}}. This Jupyter Notebook is a tutorial example that demonstrates the use of the fully tested package I developed on the test problem.\n\nWith the test problem Eqs.~\\eqref{eqn:example_model}-\\eqref{eqn:example-end} as a reference, the truncation error versus step size graph is shown in Figure \\ref{fig:Euler_explicit_error_behaviour}. The computation and comparison of one-step methods and their truncation error can be found at this link: \\href{https://nbviewer.jupyter.org/github/FarmHJ/numerical-solver/blob/main/examples/Onestep_methods_convergence.ipynb}{\\underline{\\emph{error behaviour of one-step methods}}}. The truncation error is computed by taking the difference between the exact solution and the numerical solution at a randomly chosen $x$ value of 3. The truncation error is computed for solutions obtained by using different step sizes. Figure \\ref{fig:Euler_explicit_error_behaviour} is plotted in logarithmic scale for both variables. It can be observed that $\\log |T_n|$ increases linearly with $\\log h$. The line gradient of 1 shows that $|T_n| \\propto h$, which matches the theoretical prediction. \n\n\\begin{figure}\n    \\includegraphics[width=0.95\\columnwidth]{Euler_explicit_error_behaviour}\n    \\caption{Truncation error of Euler's explicit method for various step sizes. The test problem Eqs.~\\eqref{eqn:example_model}-\\eqref{eqn:example-end} is solved with Euler's explicit method at different step sizes. The error is the absolute difference between exact solution and numerical solution at $x=3$.}\n    \\label{fig:Euler_explicit_error_behaviour}\n\\end{figure}\n\nOther than Euler's explicit method, the other one-step methods implemented are Euler's implicit method, the trapezium rule method and the four-stage explicit Runge-Kutta method. Euler's implicit method is defined to be\n\\begin{equation}\n    y_{n+1} = y_n + hf(x_{n+1},y_{n+1}),\\\\\n\\end{equation}\nwhile the trapezium rule method is\n\\begin{equation}\n    y_{n+1} = y_n + \\frac{1}{2}h[f(x_n,y_n) + f(x_{n+1},y_{n+1})].\\\\\n\\end{equation}\nThe definition of the four-stage Runge-Kutta method is\n\\begin{equation}\n    y_{n+1} = y_n + \\frac{1}{6}h(k_1 + 2k_2 + 2k_3 + k4)\n\\end{equation}\nwhere\n\\begin{align}\n    k_1 &= f(x_n, y_n) \\\\\n    k_2 &= f(x_n + \\frac{1}{2}h, y_n + \\frac{1}{2}hk_1) \\\\\n    k_3 &= f(x_n + \\frac{1}{2}h, y_n + \\frac{1}{2}hk_2) \\\\\n    k_4 &= f(x_n + h, y_n + hk_3).\n\\end{align}\n\nUsing the same definition for truncation error as in Eq.~\\eqref{eqn:trun_err_def}, we have that the truncation error of Euler's implicit method, the trapezium rule method and the four-stage Runge-Kutta method are $T_n = -\\frac{1}{2}hy''(\\xi_n)$ for $\\xi_n \\in (x_n, x_{n+1})$, $T_n = -\\frac{1}{12}h^2y^{(3)}(\\xi_n)$ for $\\xi_n \\in (x_n, x_{n+1})$ and $T_n = \\mathcal{O}(h^4)$ respectively.\n\nThese methods are tested on the test problem Eqs.~\\eqref{eqn:example_model}-\\eqref{eqn:example-end}, and the truncation error behaviour graph is shown in Figure \\ref{fig:onestep_error_behaviour}. Since the graph is plotted in logarithmic scale, the gradient of the lines shows the order of accuracy of the methods. The gradient for Euler's explicit, Euler's implicit, the trapezium rule method and the four-stage Runge-Kutta method are 1, 1, 2 and 4 respectively. The gradients on the graph match the theoretical behaviour of truncation error. In Figure \\ref{fig:onestep_error_behaviour}, the truncation error behaviour of Euler's implicit method overlaps that of Euler's explicit method because both have the same order of accuracy. \n\n\\begin{figure}\n    \\includegraphics[width=0.95\\columnwidth]{onestep_error_behaviour}\n    \\caption{Truncation error of Euler's explicit method, Euler's implicit method, the trapezium rule method and the four-stage Runge-Kutta method for various step sizes. The test problem Eqs.~\\eqref{eqn:example_model}-\\eqref{eqn:example-end} is solved with Euler's explicit method, Euler's implicit method, the trapezium rule method and the four-stage Runge-Kutta method at different step sizes. The error is the absolute difference between exact solution and numerical solution at $x=3$. The line for Euler's implicit method overlaps the line for Euler's explicit method because both have the same order of accuracy. The truncation errors follow theoretical prediction.}\n    \\label{fig:onestep_error_behaviour}\n\\end{figure}\n\n\\subsection{Predictor-corrector methods}\n\\label{sec:predictor-corrector}\nFor implicit one-step methods, the fixed point iteration algorithm is used to obtain the numerical solution. Implicit functions cannot be solved with a general method, therefore a general algorithm, the fixed point iteration, is used to estimate the solution to the implicit functions. Initial guesses for this algorithm are taken as the numerical solution at previous mesh point. However, in practice, the computational cost of the fixed point algorithm is too high. The predictor-corrector method suggests a more carefully chosen initial guess for the implicit methods. An explicit numerical method is used as a predictor for the initial guess of an implicit method. The initial guess is then used for the iterations in the algorithm to solve an implicit function. The implicit method that refines the solution is known as the corrector method. \n\nThe Euler-Trapezoidal method is a predictor-corrector method that uses Euler's explicit method as the predictor and the trapezium rule method as the corrector. In this implementation, the trapezium rule method corrector is iterated until a set of conditions are satisfied. The conditions are set to be the difference between the current iteration and the previous iteration is lesser than a given threshold value or the number of iterations exceeds a certain amount. Figure \\ref{fig:predictor_corrector_error_behaviour} shows the graph of $\\log |T_n|$ against $\\log h$ for the Euler-Trapezoidal method.\n\n\\begin{figure}\n    \\includegraphics[width=0.95\\columnwidth]{predictor_corrector_error_behaviour}\n    \\caption{Error of Euler-Trapezoidal method for various step sizes. The test problem Eqs.~\\eqref{eqn:example_model}-\\eqref{eqn:example-end} is solved with Euler-Trapezoidal method at different step sizes. The error is the absolute difference between exact solution and numerical solution at $x=3$.}\n    \\label{fig:predictor_corrector_error_behaviour}\n\\end{figure}\n\n\\subsection{Adaptive method}\n\\label{sec:adaptive-method}\nIn some types of problem, the solution to the problem exhibits a behaviour where step sizes have to be sufficiently small to obtain a stable solution. In other words, the solution changes rapidly as a function of the independent variable in some regions of the solution domain. Such problems are called stiff problems. In order to obtain a stable solution for stiff problems, the computational cost would be high. Moreover, such a stable solution would have resolution higher than required for practical purposes in some regions.\n\nAdaptive methods try to achieve the desired accuracy with low computational cost. The main idea of an adaptive method is to control the precision at each mesh point and from there assumes the precision of the solution is within the desired range. To achieve this, the error at each mesh point is estimated. If the error is larger than a threshold value, a smaller step size is chosen. These steps are repeated until the error is smaller than the given threshold value.\n\nThe adaptive methods implemented in my package are based on the BS23 (Bogacki and Shampine) and RKF45 (Runge-Kutta-Fehlberg) method, referenced from \\cite{Forsythe1977}. A lower order method is used to estimate the solution, while a higher order method is used to estimate the error. \n\nAbsolute tolerance and relative tolerance are used in the implementation of the adaptive methods to control the error. Similarly, the implemented adaptive method is used to solve the test problem Eqs.~\\eqref{eqn:example_model}-\\eqref{eqn:example-end} and tested for convergence. Two comparisons were made, one based on absolute tolerance and the other on relative tolerance. As shown in Figure \\ref{fig:ode45_absolute_sum_error_behaviour} and Figure \\ref{fig:ode45_relative_sum_error_behaviour}, the error of the method is smaller for smaller tolerance, regardless of absolute tolerance or relative tolerance.\n\n\\begin{figure}\n    \\includegraphics[width=0.95\\columnwidth]{ode45_absolute_sum_error_behaviour}\n    \\caption{Total error of RKF45 method for various absolute tolerance values. The test problem Eqs.~\\eqref{eqn:example_model}-\\eqref{eqn:example-end} is solved with RKF45 method at different absolute tolerance values. The relative tolerance is fixed at $1^{-15}$. The error is the sum of absolute difference between exact solution and numerical solution at all mesh points.}\n    \\label{fig:ode45_absolute_sum_error_behaviour}\n\\end{figure}\n\n\\begin{figure}\n    \\includegraphics[width=0.95\\columnwidth]{ode45_relative_sum_error_behaviour}\n    \\caption{Total error of RKF45 method for various relative tolerance values. The test problem Eqs.~\\eqref{eqn:example_model}-\\eqref{eqn:example-end} is solved with RKF45 method at different relative tolerance values. The absolute tolerance is fixed at $1^{-15}$. The error is the sum of absolute difference between exact solution and numerical solution at all mesh points.}\n    \\label{fig:ode45_relative_sum_error_behaviour}\n\\end{figure}", "meta": {"hexsha": "3123083acf778ad3d9c6d7de890e25e83251a71c", "size": 18462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/numerical_method.tex", "max_stars_repo_name": "FarmHJ/numerical-solver", "max_stars_repo_head_hexsha": "8a9b823b0ca6eb3c714c055324f35c74d5af5263", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/numerical_method.tex", "max_issues_repo_name": "FarmHJ/numerical-solver", "max_issues_repo_head_hexsha": "8a9b823b0ca6eb3c714c055324f35c74d5af5263", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2020-12-12T08:05:30.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-23T15:12:32.000Z", "max_forks_repo_path": "report/numerical_method.tex", "max_forks_repo_name": "FarmHJ/numerical-solver", "max_forks_repo_head_hexsha": "8a9b823b0ca6eb3c714c055324f35c74d5af5263", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 91.396039604, "max_line_length": 982, "alphanum_fraction": 0.751652042, "num_tokens": 4929, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.8688267711434708, "lm_q1q2_score": 0.7384777154134777}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage{enumitem}\n\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{1em}\n\n\\begin{document}\n\n\\section{Chebyshev's inequality} \nFor real numbers $a_1 \\geq \\dots \\geq a_n$ and $b_1 \\geq \\dots \\geq b_n$\n$$\\frac{1}{n} \\sum_{i=1}^{n} a_ib_i\n\\geq\n\\left(\\frac{1}{n}\\sum_{i=1}^{n}a_i\\right)\n\\left(\\frac{1}{n}\\sum_{i=1}^{n}b_i\\right)\n\\geq\n\\frac{1}{n} \\sum_{i=1}^{n} a_ib_{n+1-i} $$\n\n\\begin{enumerate}[resume]\n\t\n\t\\item % Võrratused 25\n\tProve Chebyshev's inequality by proving the following equation.\n\t \n\tProve that\n\t$$ \n\t\\frac{1}{2} \\sum_{i=1}^{n} \\sum_{j=1}^{n}(a_i-a_j)(b_i-b_j)\n\t=\n\tn \\sum_{k=1}^{n}a_k b_k - \\sum_{k=1}^{n}a_k \\sum_{k=1}^{n}b_k\n\t$$\n\tWhen does the equality hold?\n\t\n\t\\item\n\tFor triangle with angles $\\alpha,\\beta,\\gamma$ and opposite sides with lengths $a,b,c$ respectively prove that\n\t$$\\frac{\\pi}{3} \\leq \\frac{\\alpha a + \\beta b + \\gamma c}{a+b+c} \\leq \\frac{\\pi}{2} $$\n\t\n\t\\item % nesbitt inequality\n\tProve that for positive real numbers\n\t$$ \\frac{a}{b+c}+\\frac{b}{a+c}+ \\frac{c}{a+b} \\geq \\frac{3}{2}$$\n\t\n\t\\item % https://artofproblemsolving.com/community/c1642h1004527s3_chebyshevs_inequality\n\tProve that for positive real numbers\n\t\t$$ \\frac{(b+c)(b^2+c^2)}{a} + \\frac{(a+c)(a^2+c^2)}{b}+\\frac{(a+b)(a^2+b^2)}{c}\n\t\t\\geq\n\t\t4 (a^2+b^2+c^2)\n\t\t$$\n\t\n\t\\item %https://artofproblemsolving.com/community/c1642h1004527s3_chebyshevs_inequality\n\t\n\tProve that for positive real numbers\n\t$$\\frac{x}{x^2+yz}+\\frac{y}{y^2+xz}+\\frac{z}{z^2+xy} \\leq \\frac{x^2+y^2+z^2}{2xyz} $$\n\t\n\t\\item % vv2010-3\n\tTriangle has angles $\\alpha,\\beta,\\gamma$, perimeter $2p$ and radius of circumcircle $R$. Prove that\n\t\n\t$$\\cot^2 \\alpha + \\cot^2 \\beta + \\cot^2 \\gamma  \\geq 3 \\left(\\frac{9R^2}{p^2}-1\\right)$$\n\tWhen does the equality hold?\n\t\n\\end{enumerate}\n\n\\newpage\n\\section{Rearrangement inequality}\n\nFor real numbers $a_1 \\geq \\dots \\geq a_n$ and $b_1 \\geq \\dots \\geq b_n$ and a permutation $a'_1,\\dots,a'_n$ of $a_1,\\dots,a_n$\n\n$$a_1b_1+\\dots+a_nb_n \\geq a'_1b_1 + \\dots + a'_nb_n \\geq a_1b_n+ \\dots+ a_nb_1 $$\n\n\\begin{enumerate}[resume]\n\t\\item\n\tProve rearrangement inequality. When does the equality hold?\n\n\t\\item\n\tFor real numbers $a_1,\\dots,a_n$ and for its permutation $a'_1,\\dots,a'_n$, prove that\n\t$$\\sum_{i=1}^{n} \\frac{a_i}{a'_i} \\geq n $$\n\t\t\n\t\\item\n\tProve the mean inequalities by using rearrangement inequality\n\t$$\tSM \\geq AM \\geq GM \\geq HM$$\n\n\t\\item\n\tProve Cauchy inequality using rearrangement inequality.\n\n\t\\item\n\tProve Chebyshev's inequality using rearrangement inequality.\n\n\\end{enumerate}\n\n\\end{document}", "meta": {"hexsha": "5292294551c572bb22100194befb04c5792d1945", "size": 2600, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "05_chebysevrearrangement.tex", "max_stars_repo_name": "ZhaoWanLong/maths-olympiad", "max_stars_repo_head_hexsha": "0dcacba8a6d1769bbccfedda89d08fa22c3f55a1", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-21T21:57:43.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-21T21:57:43.000Z", "max_issues_repo_path": "05_chebysevrearrangement.tex", "max_issues_repo_name": "ZhaoWanLong/maths-olympiad", "max_issues_repo_head_hexsha": "0dcacba8a6d1769bbccfedda89d08fa22c3f55a1", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "05_chebysevrearrangement.tex", "max_forks_repo_name": "ZhaoWanLong/maths-olympiad", "max_forks_repo_head_hexsha": "0dcacba8a6d1769bbccfedda89d08fa22c3f55a1", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-08T07:04:43.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-08T07:04:43.000Z", "avg_line_length": 29.2134831461, "max_line_length": 127, "alphanum_fraction": 0.6711538462, "num_tokens": 1069, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826769445233, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7384777057153069}}
{"text": "\n\\subsection{Gaussian Mixture Models}\n\\subsubsection{Mixture models}\n\nWe have a latent variable which is part of the process\n\nThe variable is distributed according to parametric distribution, but parameters are different for differnet latent classes.\n\nThere are \\(K\\) latent classes, and so \\(K\\) sets of parameters.\n\nThe population is weighted into the \\(K\\) classes.\n\nWe have a distribution, but we have different parameters for the distribution for different populations.\n\nFor example we could observe the height of men and women, where both are normally distributed but with different parameters.\n\nWhere there is a normal distribution, this is a Gaussian mixture model.\n\nIf there is more than one variable to observe, this is a multivariate Gaussian mixture model.\n\n\\subsubsection{Gaussian Mixture Models (GMM)}\n\nIn a Gaussian Mixture Model each non latent variable has a normal distriubtion with a mean and variance. For multiple variables there is a covariance matrix.\n\n", "meta": {"hexsha": "5ce080e53aec6ec48cc407fe1f2be0f72799d9fc", "size": 976, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/distributionsMixture/01-01-MM.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/distributionsMixture/01-01-MM.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/distributionsMixture/01-01-MM.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.04, "max_line_length": 157, "alphanum_fraction": 0.8012295082, "num_tokens": 195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297941266013, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7383383730328862}}
{"text": "\n\\subsection{Introduction}\n\nIf we have a partitioned linear regression model:\n\n\\(\\mathbf y=\\mathbf X\\theta+\\mathbf Z\\beta+\\mathbf \\mu\\)\n\nUse the annihilator matrix:\n\n\\(M_X\\mathbf y=M_X\\mathbf X\\theta+M_X\\mathbf Z\\beta+M_X\\mathbf \\mu\\)\n\n\\(M_X\\mathbf y=M_X\\mathbf Z\\beta+M_X\\mathbf \\mu\\)\n\nWe can then estimate \\(\\beta \\).\n\nFrisch-Waugh-Lovell theorem says that this is the same estimate as the original regression.\n\n", "meta": {"hexsha": "9162e46423f9a77f35da52102da0f453f3a044cc", "size": 414, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/ols/04-01-introduction.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/ols/04-01-introduction.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/ols/04-01-introduction.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.0, "max_line_length": 91, "alphanum_fraction": 0.7391304348, "num_tokens": 136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7383120448994508}}
{"text": "\\section{Principle of Least Action; Noether's Theorem}\r\nConsider a particle in $\\mathbb R^3$ with kinetic energy and potential energy denotes by $T,V$ respectively.\r\nDefine the Lagrangian to be $L(\\underline{x},\\underline{\\dot{x}},t)=T-V$ and the action\r\n$$S[\\underline{x}]=\\int_{t_1}^{t_2}L\\,\\mathrm dt$$\r\nHamilton's Principle (or Principle of Least Action) postulates that the motion of the particle is a stationary point of the action functional $S$, i.e. $\\underline{x}$ satisfies the Euler-Lagrange equations with the integrand being $L$.\r\n\\begin{example}\r\n    Take the kinetic energy to be $T=m|\\underline{\\dot{x}}|^2/2$ and $V=V(\\underline{x})$, then the Euler-Lagrange equation gives\r\n    $$\\frac{\\mathrm d}{\\mathrm dt}\\frac{\\partial f}{\\partial \\dot{x}_i}-\\frac{\\partial L}{\\partial x_i}=0$$\r\n    for any $i$.\r\n    This simplifies to\r\n    $$m\\ddot{x}_i=-\\frac{\\partial V}{\\partial x_i}$$\r\n    which is just Newton's Second Law.\r\n\\end{example}\r\n\\begin{example}[Central Force in Two Dimensions]\r\n    We have\r\n    $$L=\\frac{1}{2}m(\\dot{r}^2+r^2\\dot{\\theta}^2)-V(r)$$\r\n    So the Euler-Lagrange equations give\r\n    $$\\frac{\\mathrm d}{\\mathrm dt}\\frac{\\partial L}{\\partial \\dot{r}}-\\frac{\\partial L}{\\partial r}=0=\\frac{\\mathrm d}{\\mathrm dt}\\frac{\\partial L}{\\partial \\dot{\\theta}}-\\frac{\\partial L}{\\partial \\theta}=\\frac{\\mathrm d}{\\mathrm dt}\\frac{\\partial L}{\\partial \\dot{\\theta}}$$\r\n    The first observation is that the rightmost expression vanishes, hence\r\n    $$mr^2\\dot{\\theta}=\\frac{\\partial L}{\\partial\\dot{\\theta}}=\\text{const.}$$\r\n    which is just the conservation of angular momentum.\r\n    Now $\\partial L/\\partial t=0$, so by our previous discussion of the first integrals,\r\n    $$\\dot{r}\\frac{\\partial L}{\\partial \\dot{r}}+\\dot{\\theta}\\frac{\\partial L}{\\partial\\dot{\\theta}}-L=\\text{const.}$$\r\n    So by substitution and a bit of simplification, we are left with\r\n    $$\\frac{1}{2}m\\dot{r}^2+\\frac{1}{2}mr^2\\dot{\\theta}^2+V(r)=\\text{const.}$$\r\n    Note that the left hand side is precisely $L+2V=E+V$, so this can be viewed as the conservation of energy.\r\n\\end{example}\r\n\\begin{example}[Configuration Space and Generalised Coordinates]\r\n    Consider $N$ particles in $\\mathbb R^3$.\r\n    We can put the information of the coordinates of the particles as a $3N$-tuple, which allows us to take the $N$ particles as a single particle in $\\mathbb R^{3N}$.\r\n    The coordinates of all $N$ particles ordered in the obvious way is called a generalised coordinate, and the particle system described in $\\mathbb R^{3N}$ makes it a configuration space.\r\n    So the motion of the particles can be characterised by a path (i.e. the motion of one single particle) in $\\mathbb R^{3N}$, i.e. $t\\mapsto (q_i,\\dot{q}_i,t)$ where $q_i$ is the $i^{th}$ generalised coordinate, $i=1,\\ldots,3N$.\r\n    The Lagrangian considered this way is then $L=L(q_i,\\dot{q}_i,t)$ which we can solve the corresponding Euler-Lagrange equation for.\r\n    There is a perspective of classical dynamics that takes this point of view to solve for the motions of the system of particles.\r\n\\end{example}\r\nConsider the functional\r\n$$F[\\underline{y}]=\\int_\\alpha^\\beta f(y_i,y_i^\\prime,x)\\,\\mathrm dx,i=1,\\ldots,n$$\r\nConsider a $1$-parameter family of transformations\r\n$$y_i(x)\\mapsto Y_i(s,x),s\\in\\mathbb R$$\r\nWe call this a continuous symmetry (or simply symmetry) of a Lagrangian if\r\n$$\\frac{\\mathrm d}{\\mathrm ds}f(Y_i(s,x),Y^\\prime(s,x),x)=0$$\r\nWith these set-ups, we have\r\n\\begin{theorem}[Noether's Theorem, simple version]\r\n    Given a continuous symmetry $Y_i(s,x)$ of $f$ with $Y_i(x,0)=y_i(x)$ for all $i$, the quantity\r\n    $$\\sum_i\\frac{\\partial f}{\\partial y_i}\\left.\\frac{\\partial Y_i}{\\partial s}\\right|_{s=0}$$\r\n    is a first integral of the Euler-Lagrange equations (i.e. is constant).\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Below by $f$ we mean $f(Y_i(s,x),Y^\\prime(s,x),x)$.\r\n    Summation convention is used.\r\n    \\begin{align*}\r\n        0&=\\left.\\frac{\\mathrm df}{\\mathrm ds}\\right|_{s=0}\\\\\r\n        &=\\frac{\\partial f}{\\partial y_i}\\left.\\frac{\\partial Y_i}{\\partial s}\\right|_{s=0}+\\frac{\\partial f}{\\partial y_i^\\prime}\\left.\\frac{\\partial Y_i^\\prime}{\\partial s}\\right|_{s=0}\\\\\r\n        &=\\left.\\frac{\\partial Y_i}{\\partial s}\\right|_{s=0}\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\partial f}{\\partial y_i}+\\frac{\\partial f}{\\partial y_i^\\prime}\\left.\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\partial Y_i}{\\partial s}\\right|_{s=0}\\\\\r\n        &=\\frac{\\mathrm d}{\\mathrm dx}\\left( \\frac{\\partial f}{\\partial y_i}\\left.\\frac{\\partial Y_i}{\\partial s}\\right|_{s=0} \\right)\r\n    \\end{align*}\r\n    The theorem follows.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider\r\n    $$f=\\frac{1}{2}(y^\\prime)^2+\\frac{1}{2}(z^\\prime)^2-V(y-z)$$\r\n    which is the Lagrangian of a potential that depends only on difference of the components.\r\n    Consider $Y=y+s, Z=z+s$, then $Y^\\prime=y^\\prime$ and $Z^\\prime=z^\\prime$ and $V(Y-Z)=V(y-z)$, so indeed it is a continuous symmetry.\r\n    Noether's Theorem then implies that\r\n    $$\\left.\\left( \\frac{\\partial f}{\\partial y^\\prime}\\frac{\\partial Y}{\\partial s}+\\frac{\\partial f}{\\partial z^\\prime}\\frac{\\partial Z}{\\partial s} \\right)\\right|_{s=0}=y^\\prime+z^\\prime$$\r\n    is constant.\r\n    This is just saying the conservation of momentum in the $y+z$ direction.\r\n\\end{example}\r\n\\begin{example}\r\n    Back to our previous discussion on central force, then the transformation $\\Theta=\\theta+s,R=r$ is certainly a continous symmetry.\r\n    Therefore we have the conserved quantity\r\n    $$\\left( \\frac{\\partial L}{\\partial\\dot{\\theta}}\\frac{\\partial\\Theta}{\\partial s}+\\frac{\\partial L}{\\partial\\dot{r}}\\frac{\\partial R}{\\partial s} \\right)_{s=0}=mr^2\\dot{\\theta}$$\r\n    which is just the magnitude of angular momentum.\r\n    In general, isotopy of space gives rise to rotational invariants of the Lagrangian.\r\n\\end{example}\r\n", "meta": {"hexsha": "a8e974bf23cf10746a5b2740a04f9f82b801b8e7", "size": 5827, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/least.tex", "max_stars_repo_name": "david-bai-notes/IB-Variational-Principles", "max_stars_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4/least.tex", "max_issues_repo_name": "david-bai-notes/IB-Variational-Principles", "max_issues_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4/least.tex", "max_forks_repo_name": "david-bai-notes/IB-Variational-Principles", "max_forks_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 76.6710526316, "max_line_length": 277, "alphanum_fraction": 0.6785652995, "num_tokens": 1787, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.738249398796227}}
{"text": "\n\\section{Context-free grammar}\n\nContext-free grammars are part of the Chomsky hierarchy \\cite{grammars_hierarchy, grammars} and can be defined as a quadruple $G = (N, \\Sigma, P, S)$ that consists of the following components:\n\n\\begin{itemize}\n    \\item[$-$] $N$ is a finite set of \\textit{non-terminal} variables.\n    \\item[$-$] $\\Sigma$ is a finite set of \\textit{terminal} variables.\n    \\item[$-$] $P$ is a finite set of \\textit{production rules}, also called \\textit{rewrite rules}, it specifies a symbol substitution that can be recursively performed to generate new symbol sequences. In an unrestricted grammar, which is the most general form of the Chomsky hierarchy, a production is of the form $u \\to v$ where $u$ and $v$ are arbitrary strings of \\textit{terminals} and \\textit{non-terminals}.\n    \\item[$-$] $S \\in N$ is a distinguished symbol that is the \\textit{start symbol}, also called the \\textit{sentence symbol}.\n\\end{itemize}\n\nThe language $L(G)$ is the language generated by the grammar G \\cite{intro_automata}.\nTo generate a string of the language, one begins with a string consisting of only a single start symbol, and then successively applies the rules (any number of times, in any order) to rewrite this string. \nThis stops when we obtain a string containing only terminals.\nThe language consists of all the strings that can be generated in this manner.\n\nThe same process can be applied backward to check weither a given string can be generated by the grammar or not.\n\n\\subsection{Description of the Chomsky normal-form}\n\nHere is an example of a context-free grammar in the Chomsky normal-form:\n\n\\begin{align*} \n&S \\to AB|BC\\\\\n&A \\to BA|a\\\\\n&B \\to CC|b\\\\\n&C \\to AB|a\n\\end{align*}\n\nThe grammar can be described as a finite set of production rules, in those productions we can find four types of symbols:\n\n\\begin{itemize}\n    \\item[$-$] The `$\\to$' symbol is what seperates the left-hand from the right-hand(s) of the rules.\n    \\item[$-$] In this grammar every single uppercase letter is a \\textit{non-terminal} variable.\n    \\item[$-$] The \\textit{terminals} are primitive symbols, they can only be found on the right-hand of a production.\n    \\item[$-$] A left-hand is constitued of one \\textit{non-terminal}, it can relate to one or several right-hands seperated by the `$|$' symbol. A right-hand is constitued either by one \\textit{terminal} or a pair of \\textit{non-terminals}.\n\\end{itemize}\n\nHere S, A, B, and C are \\textit{non-terminals}, a and b are \\textit{terminals} and S is the \\textit{start symbol}.\n\n\\subsection{Convert grammar to Chomsky normal-form}\n\nSometimes it is needed to convert a context-free grammar to the Chomsky normal-form.\nLater in this report is presented an algorithm that follows the next pseudo-code in order to automaticly convert a given context-free grammar into the Chomsky normal-form.\n\\\\\n\\\\\nFor example this is how to convert the following grammar:\n\n\\begin{align*} \n&S \\to S+P|P\\\\\n&P \\to P*C|C\\\\\n&C \\to (S)|0|1\\\\\n\\end{align*}\n\n\\begin{enumerate}\n    \\item The first thing to do is to eliminate the \\textit{start symbol} from the right-hands of the grammar by replacing the \\textit{start symbol} by a new one (some labels have been modified):\n        \\begin{align*} \n        &S \\to A\\\\\n        &A \\to A+B|B\\\\\n        &B \\to B*C|C\\\\\n        &C \\to (A)|0|1\\\\\n        \\end{align*}\n\n    \\item Then the goal is to replace the \\textit{terminals} that are not the only symbols on the right-hand by a new \\textit{non-terminal}:\n        \\begin{align*} \n        &S \\to A        &P \\to +\\\\\n        &A \\to APB|B    &M \\to *\\\\\n        &B \\to BMC|C    &L \\to (\\\\\n        &C \\to LAR|0|1  &R \\to )\\\\\n        \\end{align*}\n    \n    \\item The next step is to delete the right-hands with more than 2 \\textit{non-terminals} by adding \\textit{non-terminals} that will relate to a pair:\n        \\begin{align*} \n        &S \\to A        &F \\to AR\\\\\n        &A \\to AD|B     &P \\to +\\\\\n        &B \\to BE|C     &M \\to *\\\\\n        &C \\to LF|0|1   &L \\to (\\\\\n        &D \\to PB       &R \\to )\\\\\n        &E \\to MC\\\\\n        \\end{align*}\n\n    \\item At last it is needed to eliminate the unit rules, those are the right-hands in which there is one \\textit{non-terminal} alone:\n        \\begin{align*} \n        &S \\to AD|BE|LG|0|1 &F \\to AR\\\\\n        &A \\to AD|BE|LG|0|1 &P \\to +\\\\\n        &B \\to BE|LG|0|1    &M \\to *\\\\\n        &C \\to LF|0|1       &L \\to (\\\\\n        &D \\to PB           &R \\to )\\\\\n        &E \\to MC\\\\\n        \\end{align*}\n\n\\end{enumerate}\n\n\\section{CYK algorithm}\n\nThe CYK algorithm is a parser for context-free grammar, it is named after its inventors, John Cocke, Daniel Younger and Tadao Kasami.\nThe algorithm takes a string and a context-free grammar as input and determines if the string is part of the language of the grammar or not.\nIt uses the backward process explained in the presentation of section 1.1.\n\nContext-free grammar parsers can be used for example in computer sciences to check code structure in compilers or in biology for DNA and RNA strings analysis.\n\n\\section{Diverse development approaches}\n\nThe goal of the assignment is to implement CYK parsers using different development approaches in order to compare the efficiency of those.\nIn this section the three used development methods are briefly presented.\n\n\\subsection{Divide and conquer}\n\nDivide and conquer is an algorithmic strategy that consists in recursively breaking down a problem into several others, and do so until the problems become easy enough to solve. \nThe obtained results are then combined in order to solve the initial problem.\n\\\\\n\\\\\nThose are the steps of the general structure of that strategy:\n\n\\begin{enumerate}\n    \\item Divide the problem instance given as input into smaller instances.\n    \\item Recursively compute the results for those smaller instances.\n    \\item Assemble the recursively obtained results into a result for the entire input and return it.\n\\end{enumerate}\n\n\\subsubsection{Recurrence relation}\n\nIt is possible to find a function that satisfies the recurrence relation of the divide and conquer strategy.\nLet's suppose that a recursive algorithm divides a problem of size $n$ into $a$ sub-problems, where each sub-problem is of size $\\dfrac{n}{b}$\nSuppose also that $g(n)$ is the total time needed to create the sub-problems and combine their results.\n\nThen we can define $f(n)$, being the number of operations needed to solve the problem of size $n$, as:\n$$\nf(n) = a * f(\\dfrac{n}{b}) + g(n)\n$$\n\n\\subsubsection{Master theorem}\n\nThe Master theorem for the divide and conquer recurrences provides an asymptotic analysis of the complexity, using the Big O notation.\nIt allows one to solve $f(n)$ depending on three different cases.\n\\\\\n\\\\\nNow that we have the function $f(n)$ we suppose that $g(n) = \\Theta(n^d)$.\n\\\\\n\\\\\nThen the master theorem is:\n$$\nf(n) = \n\\begin{cases}\n    \\Theta(n^d) &\\text{if } a < b^d\\\\\n    \\Theta(n^dlog(n)) &\\text{if } a = b^d\\\\\n    \\Theta(n^{log_b(a)}) &\\text{if } a > b^d\\\\\n\\end{cases}\n$$\n\nHere the first case is when it is possible to ignore the solving of the subproblems before the creation and combination of the sub-problems. The running time is then the time needed to create and combine the sub-problems, $g(n) = \\Theta(n^d)$.\n\nThe second case is when it is not possible to ignore anything.\n\nThe final case is when it is possible to ignore the creation and combination of the sub-problems. The running time is then the time needed to solve $a^{log_b(n)}$ subproblems of size 1.\n\n\\subsection{Dynamic programing}\n\nDynamic programing is an algorithmic paradigm that solves a given complex problem by breaking it down into subproblems and storing the results of those subproblems to avoid computing the same results again.\n\n\\subsubsection{Top-down approach}\n\nThe top-down approach is similar to the divide and conquer approach, the initial problem is recursively broken down into several sub-problems.\nThe difference is that in this approach a global variable memorize every computed result. \nIn that way when the program runs into a known problem the memorized result is directly returned.\nThe program generally computes less operations and goes less deep in the recursion than the divide and conquer method.\n\n\\subsubsection{Bottom-up approach}\n\nThe bottom-up approach consists in solving the simplest sub-problems first, memorizing every computed result, and then going up solving bigger and bigger sub-problems until it can solve the initial problem.\nThis approach is a way to avoid recursion, which saves some memory, but on the other hand it can sometimes solve sub-problems that will never be used to solve the initial problem, which is a waste of time.\n\nA good analogy for the bottom-up design are building blocks, indeed you have to start assembling the most little pieces together in order to construct bigger ones that you will then assemble to get the final result.\n\n", "meta": {"hexsha": "609f7a4e8d6ed88a14efe456da9b0e72bc42093f", "size": 8867, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/chapter_1.tex", "max_stars_repo_name": "ThomasRanvier/cyk_algorithm_analysis", "max_stars_repo_head_hexsha": "f6d7fbf95533461b58b0a9937530f1e4d8bc2e29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/sections/chapter_1.tex", "max_issues_repo_name": "ThomasRanvier/cyk_algorithm_analysis", "max_issues_repo_head_hexsha": "f6d7fbf95533461b58b0a9937530f1e4d8bc2e29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/sections/chapter_1.tex", "max_forks_repo_name": "ThomasRanvier/cyk_algorithm_analysis", "max_forks_repo_head_hexsha": "f6d7fbf95533461b58b0a9937530f1e4d8bc2e29", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-13T17:38:35.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-13T17:38:35.000Z", "avg_line_length": 50.3806818182, "max_line_length": 416, "alphanum_fraction": 0.7178301568, "num_tokens": 2297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7382384248534737}}
{"text": "\\section{Continuity Properties}\r\nThese properties should look very similar to the properties of limits.\r\nLet $f$ and $g$ be continuous functions at $c$.\r\n\\begin{align*}\r\n\t\\textbf{Sum and Difference Rule: }& f \\pm g \\text{ is continuous at } c. \\\\\r\n\t\\textbf{Product Rule: }& f \\cdot g \\text{ is continuous at } c. \\\\\r\n\t\\textbf{Constant Multiple Rule: }& kf \\text{ is continous at } c \\text{ for all real } k. \\\\\r\n\t\\textbf{Quotient Rule: }& \\frac{f}{g} \\text{ is continuous at } c \\text{ as long as the value of the extended function of } \\\\\r\n\t\tg \\text{ at } c \\text{ is not } 0. \\\\\r\n\t\\textbf{Composition Rule: }& f \\circ g \\text{ is continuous at } c \\text{ if } f \\text{ is continuous at } g(c). \\\\\r\n\t\\textbf{Absolute Value Rule: }& \\abs{f} \\text{ is continuous at } c.\r\n\\end{align*}\r\n\r\nThe following types of functions are continuous on their domains\r\n\\begin{itemize}\r\n\t\\item Polynomials\r\n\t\\item Rational functions, except where the denominator is 0\r\n\t\\item Trigonometric functions where defined\r\n\\end{itemize}\r\n\r\n\\begin{example}\r\n\tShow that the following function is continuous.\r\n\t\\begin{equation*}\r\n\t\tf(x) = \\tan{\\left(\\frac{x^2}{x^2+4}\\right)}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe can write $f$ as the composition of $\\tan{x}$ and $\\frac{x^2}{x^2+4}$.\r\n\t$\\tan{x}$ is continuous on its domain because it is a trigonometric function.\r\n\tThe only points not in its domain are $(2n+1)\\frac{\\pi}{2}$, where $n$ is an integer.\r\n\t$\\frac{x^2}{x^2+4}$ is a rational function, but it's denominator is never $0$, so it is continuous over all real numbers.\r\n\tNow, we just need to check that all points in the range of $\\frac{x^2}{x^2+4}$ are in the domain of $\\tan{x}$.\r\n\tThe range of $\\frac{x^2}{x^2+4}$ is $[0,1)$.\r\n\tNone of the points in this interval are not in the domain of $\\tan{x}$, so the composition is continuous over all real numbers.\r\n\\end{answer}", "meta": {"hexsha": "20c61b881b6b5eca12060bfd90d8b073218434fa", "size": 1869, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/limits_continuity/continuity_properties.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/limits_continuity/continuity_properties.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/limits_continuity/continuity_properties.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 53.4, "max_line_length": 129, "alphanum_fraction": 0.6757624398, "num_tokens": 581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.8705972734445508, "lm_q1q2_score": 0.7382384184126228}}
{"text": "\\section{Spectral Theory}\n\n\\subsection{Exercise 1}\n(a) We can re-express $h$ as a linear combination of its eigenvectors,\nfrom which we can see that $A^n$ causes all of these components to go to 0.\n\n(b) Same as in part (a), except all of the components now go to $\\infty$.\n\n\\subsection{Exercise 2}\n$A (A^N f) = A(a^N f + Na^{N - 1} h) = a^{N+1} f + a^N h + Na^N h$.\n\n\\subsection{Exercise 3}\nSuppose $q(A) = \\sum_{i = 0}^N q_i A^i$. Then $q_i A^i f = q_i a^i f + q_i i a^{i-1} h$ by\nExercise 2. From the linearity of the derivative it then follows that $q(A) f = q(a) f + q'(a) h$. \n\n\\subsection{Exercise 4}\nApplying Lemma 9 to $p_1 ... p_k$ and $p_{k+1}$ gives the desired result.\n\n\\subsection{Exercise 5}\n$(A - aI)^d x = 0 \\implies A (A - aI)^d x = 0 \\implies (A - aI)^d (Ax) = 0 \\implies Ax \\in N_d$.\n\n\\subsection{Exercise 6}\nSince $m_A$ divides the characteristic polynomial of $A$ (by definition of $d_i$), $m_A (A) = 0$ by Cayley-Hamilton. \nSuppose there is some polynomial $q(A) = 0$ with $\\deg(q) < \\deg(m_A)$.\nThe roots of $q$ must contain all of the eigenvalues of $A$, since for any eigenvector $h$ we have that\n$q(A)h = q(a_h)h$ (where $a_h$ denotes the eigenvalue associated with $h$). Thus, the roots of $q$ can\nonly differ in multiplicity from $m_A$. However, if any root of $q$ has multiplicity $d_i' < d_i$, then\nwe can choose an element $x \\in N_{d_i}$ such that $q(A)x \\neq 0$, which is a contradiction (since\n$N_{d_i'} \\subset N_{d_i}$).\n\n\\subsection{Exercise 7}\nThe columns of $A$ are $Ax_i$.\n\n\\subsection{Exercise 8}\nBy induction.\n\n\\subsection{Exercise 9}\nThe minimal polynomial of $A$ divides the minimal polynomial of $A^{\\top}$, and vice versa,\nso they must be the same. Thus, the indices of each eigenvalue of $A$ and $A^{\\top}$ must be the same,\nwhich means we can apply Theorem 12 to see that they are similar.\n\n\\subsection{Exercise 10}\n$(\\xi^{(i)}, x) = \\sum k_j (\\xi^{(i)}, x^{(j)}) = k_i (\\xi^{(i)}, x^{(i)})$ since\n$(\\xi^{(i)}, x^{(j)}) = 0$ by Theorem 17.\n", "meta": {"hexsha": "259b8c9602c982fd411a51147b46251212592960", "size": 1988, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear_Algebra_Lax/chapter_6.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "Linear_Algebra_Lax/chapter_6.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Linear_Algebra_Lax/chapter_6.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.1777777778, "max_line_length": 117, "alphanum_fraction": 0.6579476861, "num_tokens": 709, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.8705972583359805, "lm_q1q2_score": 0.7382383989112528}}
{"text": "\\chapter{Mathematical Tools}\n\nThis appendix covers some of the basic mathematics used in econometrics. We briefly discuss the properties of summation operators, study the properties of linear and some nonlinear equations, and review the ratios and percentages. We also introduce some special functions that are common in econometrics applications, including quadratic functions and natural logarithms. The first four sections require only basic algebraic techniques. The fifth section briefly reviews differential Calculus Although Calculus is not necessary to understand much of this book, it is used in some of the end-of-chapter appendices and in some of the more advanced topics in part 3.\n\n\\section{Summation Operator and Description Statistics}\n\n\\textbf{Summation Operator} is an abbreviation used to express the summation of numbers, it plays an important role in statistics and econometrics analysis. If $\\{x_i: i=1, 2, \\ldots, n\\}$ is a sequence of $n$ numbers, the summation of the $n$ numbers is:\n\n\\begin{equation}\n\\sum_{i=1}^n x_i \\equiv x_1 + x_2 +\\cdots + x_n\n\\end{equation}\n\n", "meta": {"hexsha": "23286511d1fca16c4e8e9e06feed67f32ff0b827", "size": 1090, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "body/en-ch7.tex", "max_stars_repo_name": "yoczhang/latexBook-template", "max_stars_repo_head_hexsha": "2893eb15c8f3faaf1ea0a0ddfef21e9b94fd5d41", "max_stars_repo_licenses": ["LPPL-1.3c"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-29T03:10:52.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-29T03:10:52.000Z", "max_issues_repo_path": "body/en-ch7.tex", "max_issues_repo_name": "yoczhang/latexBook-template", "max_issues_repo_head_hexsha": "2893eb15c8f3faaf1ea0a0ddfef21e9b94fd5d41", "max_issues_repo_licenses": ["LPPL-1.3c"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "body/en-ch7.tex", "max_forks_repo_name": "yoczhang/latexBook-template", "max_forks_repo_head_hexsha": "2893eb15c8f3faaf1ea0a0ddfef21e9b94fd5d41", "max_forks_repo_licenses": ["LPPL-1.3c"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 83.8461538462, "max_line_length": 663, "alphanum_fraction": 0.7990825688, "num_tokens": 252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693688269984, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7381778685510825}}
{"text": "%! Author = tstreule\n\n\\section{General}\n\n\\subsection{SigSys Basics \\textnormal{\\hfill $\\textrm{SNR}\\uparrow \\hat{=} \\textrm{resolution}\\downarrow$ \\hfill $x\\leftrightarrow t$, $k\\leftrightarrow f$}}\n%\nIFFT:\\hfill\n\\highlight{$\\displaystyle f(x,y) = \\frac{1}{2\\pi} \\iint \\mathcal{F}[f](k_x, k_y) \\eu^{\\iu(k_x x + k_y y)} \\diff k_x \\diff k_y$}\\\\\nFFT:\\hfill\n\\highlight{$\\displaystyle \\mathcal{F}[f](k_x,k_y) = \\frac{1}{2\\pi} \\iint f(x,y) \\eu^{-\\iu(k_x x + k_y y)} \\diff x \\diff y$}\n\\\\\n\\includegraphics[width=\\linewidth]{Basics_Comb}\n\\\\\nPrevent \\textbf{aliasing}: \\fbox{$\\Delta x<\\frac{2\\pi}{\\textrm{BW}}$} $\\leftrightarrow$ \\fbox{$\\Delta k<\\frac{2\\pi}{\\textrm{FOV}}$}\n\\begin{minipage}{.25\\linewidth}sampl. res.\\\\ $\\leftrightarrow$ image size\\end{minipage}\n\\\\\n\\highlight{$\\displaystyle \\mathcal{F}[f](k_m) = \\underbrace{ \\eu^{-\\iu k_m x_0}\\vspace{-1mm} }_{ \\vspace{-1mm}\\textrm{shift} } \\sum \\limits_{n=0}^{N-1} f(x_n) \\eu^{-\\iu\\frac{2 \\pi m n}{N}}$}\nnormally: $x_0 = 0$\n\n\\textbf{Noise}:\n\\begin{minipage}[t]{.88\\textwidth}\n    \\textbf{Gaussian}:\n    $\\highlight{P_n(\\eta) = \\frac{1}{\\sqrt{2 \\pi \\sigma^2}} e^{-\\frac{\\eta^2}{2 \\sigma^2}}} \\mathrm{FWHM} = 2\\sqrt{2\\ln 2}$\\\\\n    \\textbf{Poisson}:\n    \\highlight{$\\displaystyle P_\\lambda(x) = \\frac{\\lambda^x}{x!}\\eu^{-\\lambda}$} ($\\to$ discrete events)\\\\\n    \\fbox{$\\textrm{SNR} = \\abs{S[f](x,y)} \\; \\frac{1}{\\sigma}$}\n    $\\leftrightarrow$\n    \\fbox{$\\textrm{CNR}\\ped{AB} = \\abs{ \\textrm{SNR}\\ped{A}-\\textrm{SNR}\\ped{B} }$}\n\\end{minipage}\n", "meta": {"hexsha": "00f052b6b87c7ee8a61730907e081a6468d69b90", "size": 1482, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/BMI18/sections/01_general.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/BMI18/sections/01_general.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/BMI18/sections/01_general.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.4, "max_line_length": 190, "alphanum_fraction": 0.6282051282, "num_tokens": 638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7381754380083967}}
{"text": "\\section{Points and vectors}\n\nIn this section, we will first introduce complex numbers, because they are a useful way to think about and represent 2D points, especially when rotations are involved. We will then present two different ways to represent points in code: one by creating our own structure, the other by using the C++ built-in \\lstinline|complex| type. Either can be used to run the code samples in this book, though \\lstinline|complex| requires less typing.\n\n\\subsection{Complex numbers}\\label{complex}\nComplex numbers are an extension of the real numbers with a new unit, the \\term{imaginary unit}, noted $i$. A complex number is usually written as $a + bi$ (for $a,b \\in\\real$) and we can interpret it geometrically as point $(a,b)$ in the two-dimensional plane, or as a vector with components $\\vv{v}=(a,b)$. We will sometimes use all these notations interchangeably. The set of complex numbers is written as $\\complex$.\n\n\\centerFig{point0}\n\n\\subsubsection{Basic operations}\nComplex numbers are added, subtracted and multiplied by scalars as if $i$ were an unknown variable. Those operations are equivalent to the same operations on vectors.\n\\begin{align*}\n(a+bi) + (c+di) &= (a+c) + (b+d)i &\\mbox{(addition)} \\\\\n(a+bi) - (c+di) &= (a-c) + (b-d)i &\\mbox{(subtraction)} \\\\\nk(a+bi) &= (ka) + (kb)i &\\mbox{(multiplication by scalar)}\n\\end{align*}\nGeometrically, adding or subtracting two complex numbers $\\vv{v}=(a,b)$ and $\\vv{w}=(c,d)$ corresponds to making $\\vv{w}$ or its opposite start at the end of $\\vv{v}$, while multiplying $\\vv{v}$ by a positive real $k$ corresponds to multiplying its length by $k$ but keeping the same direction.\n\n\\centerFig{point1}\n\\centerFig{point5}\n\n\\subsubsection{Polar form}\\label{polar-form}\nThe polar form is another way to represent complex numbers. To denote a complex $\\vv{v} = a+bi$, instead of looking at the real and complex parts, we look at the \\term{absolute value} $r$, the distance from the origin (the length of vector $\\vv{v}$), and the \\term{argument} $\\phi$, the amplitude of the angle that $\\vv{v}$ forms with the positive real axis.\n\n\\centerFig{point2}\n\nFor a given complex number $a+bi$, we can compute its polar form as\n\\begin{align*}\nr &= |a+bi| = \\sqrt{a^2+b^2}\\\\\n\\phi &= \\arg(a+bi) = \\atanTwo(b,a)\n\\end{align*}\nand conversely, a complex number with polar coordinates $r,\\phi$ can be written\n\\[r\\cos\\phi+(r\\sin\\phi)i = r(\\cos\\phi + i\\sin\\phi) \\eqqcolon r\\cis\\phi\\]\nwhere $\\cis\\phi = \\cos\\phi+i\\sin\\phi$ is the unit vector that forms an angle of amplitude $\\phi$ with the positive real axis.\n\nNote that this is not a one-to-one mapping. Firstly, adding or subtracting $\\turn$ from $\\phi$ doesn't change the point being represented; to solve this problem, $\\phi$ is generally taken in $(-\\half,\\half]$. Secondly, when $r=0$, all values of $\\phi$ represent the same point.\n\n\\subsubsection{Multiplication}\n\nComplex multiplication is easiest to understand using the polar form. When multiplying two complex numbers, their absolute values are multiplies, while their arguments are added. In other words,\n\\[(r_1\\cis\\phi_1) \\ast (r_2\\cis\\phi_2) = (r_1r_2) \\cis (\\phi_1+\\phi_2).\\]\n\nIn the illustration below, $|\\vv{v}\\ast\\vv{w}| = |\\vv{v}||\\vv{w}|$ and the angle between the $x$-axis and $\\vv{v}$ is the same as the angle between $\\vv{w}$ and $\\vv{v}\\ast\\vv{w}$.\n\n\\centerFig{point3}\n\nRemarkably, multiplication is also very simple to compute from the coordinates: it works a bit like polynomial multiplication, except that we transform $i^2$ into $-1$.\n\\begin{align*}\n(a+bi)\\ast(c+di) &= ac + a(di) + (bi)c + (bi)(di)\\\\\n&= ac + adi + bci + (bd)i^2\\\\\n&= ac + (ad+bc)i + (bd)(-1)\\\\\n&= (ac-bd) + (ad+bc)i\n\\end{align*}\n\n\\exoWithSolution{\n    Prove that $(r_1\\cis\\phi_1) \\ast (r_2\\cis\\phi_2) = (r_1r_2) \\cis (\\phi_1+\\phi_2)$ using this new definition of product.\n}{\n    \\protect \\begin{align*}\n        (r_1\\cis\\phi_1)&\\ast(r_2\\cis\\phi_2)\\\\\n        &=\\left(r_1\\cos\\phi_1 + (r_1\\sin\\phi_1)i\\right)\n            \\ast \\left(r_2\\cos\\phi_2 + (r_2\\sin\\phi_2)i\\right)\\\\\n        &= r_1r_2[(\\cos\\phi_1\\cos\\phi_2 - \\sin\\phi_1\\sin\\phi_2)\\\\\n        &\\qquad + (\\cos\\phi_1\\sin\\phi_2 + \\sin\\phi_1\\cos\\phi_2)i] \\\\\n        &= r_1r_2(\\cos(\\phi_1 + \\phi_2) + i\\sin(\\phi_1+\\phi_2)) \\\\\n        &= r_1r_2 \\cis(\\phi_1 + \\phi_2)\n    \\protect \\end{align*}\n}{polar-multiplication}\n\nAnother way to explain complex multiplication is to say that multiplying a number by $r\\cis\\phi$ will scale it by $r$ and rotate it by $\\phi$ counterclockwise. For example, multiplying a number by $\\frac{1}{2}i = \\frac{1}{2}\\cis\\quarter$ will divide its length by 2 and rotate it $90\\degree$ counterclockwise.\n\n\\centerFig{point4}\n\n%This also makes defining division very intuitive: just \\emph{divide} the absolute values and \\emph{subtract} the arguments: $(r_1\\cis\\phi_1) / (r_2\\cis\\phi_2) = \\frac{r_1}{r_2} \\cis(\\phi_1-\\phi_2)$. Without going through polar coordinates, it can also be written as\n%\\[z/w = \\frac{z\\ast\\conj{w}}{\\norm{w}^2}\\]\n%where $\\conj{w}$ is the \\term{complex conjugate} of $w$, an operation that changes the sign of the complex part: $\\conj{a+bi} = a-bi$.\n\n\\subsection{Point representation}\\label{ss:point-representation}\nIn this section we explain how to implement the point structure that we will use throughout the rest of the book. The code is only available in C++ at the moment, but should be easy to translate in most languages.% Our long-term plan is to offer code snippets in other languages as well.\n\n\\subsubsection{With a custom structure}\nLet us first declare the basic operations: addition, subtraction, and multiplication/division by a scalar.\n\\begin{lstlisting}\ntypedef double T;\nstruct pt {\n    T x,y;\n    pt operator+(pt p) {return {x+p.x, y+p.y};}\n    pt operator-(pt p) {return {x-p.x, y-p.y};}\n    pt operator*(T d) {return {x*d, y*d};}\n    pt operator/(T d) {return {x/d, y/d};} // only for floating-point\n};\n\\end{lstlisting}\nFor generality, we declare type \\lstinline|T|: the type of the the coordinates. Generally, either \\lstinline|double| or \\lstinline|long long| (for exact computations with integers) is appropriate. \\lstinline|long double| can also be very useful if extra precision is required. The cases where integers cannot be used are often quite clear (e.g. division by scalar, rotation by arbitrary angle).\n\nWe define some comparators for convenience:\n\\begin{lstlisting}\nbool operator==(pt a, pt b) {return a.x == b.x && a.y == b.y;}\nbool operator!=(pt a, pt b) {return !(a == b);}\n\\end{lstlisting}\nNote that there is no obvious way to define a $<$ operator on 2D points, so we will only define it as needed.\n\nHere are some functions linked to the absolute value:\n\\begin{lstlisting}\nT sq(pt p) {return p.x*p.x + p.y*p.y;}\ndouble abs(pt p) {return sqrt(sq(p));}\n\\end{lstlisting}\nThe squared absolute value \\lstinline|sq()| can be used to compute and compare distances quickly and exactly if the coordinates are integers. We use \\lstinline|double| for \\lstinline|abs()| because it will return floating-point values even for integer coordinates (if you are using \\lstinline|long double| you should probably change it to \\lstinline|long double|).\n\nWe also declare a way to print out points, for debugging purposes:\n\\begin{lstlisting}\nostream& operator<<(ostream& os, pt p) {\n    return os << \"(\"<< p.x << \",\" << p.y << \")\";\n}\n\\end{lstlisting}\n\nSome example usage:\n\\begin{lstlisting}\npt a{3,4}, b{2,-1};\ncout << a+b << \" \" << a-b << \"\\n\"; // (5,3) (1,5)\ncout << a*-1 << \" \" << b/2 << \"\\n\"; // (-3,-4) (1.5,2)\n\\end{lstlisting}\n\nWe also define a signum function, which will be useful for several applications. It returns \\lstinline|-1| for negative numbers, \\lstinline|0| for zero, and \\lstinline|1| for positive numbers.\n\\begin{lstlisting}\ntemplate <typename T> int sgn(T x) {\n    return (T(0) < x) - (x < T(0));\n}\n\\end{lstlisting}\n\n\\subsubsection{With the C++ \\lstinline|complex| structure}\nUsing the \\lstinline|complex| type in C++ can be a very practical choice in contests such as ACM-ICPC where everything must be typed from scratch, as many of the operations we need are already implemented and ready to use.\n\nThe code below defines a \\lstinline|pt| with similar functionality.\n\\begin{lstlisting}\ntypedef double T;\ntypedef complex<T> pt;\n#define x real()\n#define y imag()\n\\end{lstlisting}\n\n\\begin{warning}\nAs with the custom structure, you should choose the appropriate coordinate type for \\lstinline|T|. However, be warned that if you define it as an integral type like \\lstinline|long long|, some functions which should always return floating-point numbers (like \\lstinline|abs()| and \\lstinline|arg()|) will be truncated to integers.\n\\end{warning}\n\nThe macros \\lstinline|x| and \\lstinline|y| are shortcuts for accessing the real and imaginary parts of a number, which are used as $x$- and $y$-coordinates:\n\\begin{lstlisting}\npt p{3,-4};\ncout << p.x << \" \" << p.y << \"\\n\"; // 3 -4\n// Can be printed out of the box\ncout << p << \"\\n\"; // (3,-4)\n\\end{lstlisting}\n\nNote that the coordinates can't be modified individually:\n\\begin{lstlisting}\npt p{-3,2};\np.x = 1; // doesn't compile\np = {1,2}; // correct\n\\end{lstlisting}\n\nWe can perform all the operations that we have with the custom structure and then some more. Of course, we can also use complex multiplication and division. Note however that we can only multiply/divide by scalars of type \\lstinline|T| (so if \\lstinline|T| is \\lstinline|double|, then \\lstinline|int| will not work).\n\\begin{lstlisting}\npt a{3,1}, b{1,-2};\na += 2.0*b; // a = (5,-3)\ncout << a*b << \" \" << a/-b << \"\\n\"; // (-1,-13) (-2.2,-1.4)\n\\end{lstlisting}\n\nThere are also useful methods for dealing with polar coordinates:\n\\begin{lstlisting}\npt p{4,3};\n// Get the absolute value and argument of point (in [-pi,pi])\ncout << abs(p) << \" \" << arg(p) << \"\\n\"; // 5 0.643501\n// Make a point from polar coordinates\ncout << polar(2.0, -M_PI/2) << \"\\n\"; // (1.41421,-1.41421)\n\\end{lstlisting}\n\n\\begin{warning}\nThe \\lstinline|complex| library provides function \\lstinline|norm|, which is mostly equivalent to the \\lstinline|sq| that we defined earlier. However, it is not guaranteed to be exact for \\lstinline|double|: for example, the following expression evaluates to \\lstinline|false|.\n\\begin{lstlisting}\nnorm(complex<double>(2.0,1.0)) == 5.0\n\\end{lstlisting}\n\nTherefore, to be safe you should implement a separate \\lstinline|sq()| function as for the custom structure (or you can wait use function \\lstinline|dot()| that we will define later).\n\\end{warning}\n", "meta": {"hexsha": "46ce4a631b5b4e9d6b4ea6caff642fdbac3fd770", "size": 10442, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/basics/point.tex", "max_stars_repo_name": "cbarnson/UVa", "max_stars_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_stars_repo_licenses": ["Unlicense", "MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-07T17:00:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-05T02:08:35.000Z", "max_issues_repo_path": "archives/codelibraries/cp-geo-master/basics/point.tex", "max_issues_repo_name": "cbarnson/UVa", "max_issues_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_issues_repo_licenses": ["Unlicense", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "archives/codelibraries/cp-geo-master/basics/point.tex", "max_forks_repo_name": "cbarnson/UVa", "max_forks_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_forks_repo_licenses": ["Unlicense", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.0601092896, "max_line_length": 439, "alphanum_fraction": 0.7051331163, "num_tokens": 3127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7380753220588373}}
{"text": "\\subsection{Dot Products}\r\n\\noindent\r\nA dot product is a way of multiplying two vectors so that the result is a scalar. $\\vec{a}\\cdot\\vec{b} = \\norm{\\vec{a}}\\norm{\\vec{b}}\\cos{\\theta}$ where $\\theta$ is the angle between $\\vec{a}$ and $\\vec{b}$. One way to think of the dot product is as a measure of how much two vectors point in the same direction.\\\\\r\nWe can also show using the law of cosines that $\\vec{a}\\cdot\\vec{b} = a_1b_1+a_2b_2+...+a_nb_n$.\\\\\r\nKnowing the lengths of two vectors and their dot product we can calculate the angle between them as\r\n\\begin{equation*}\r\n\t\\theta = \\arccos{\\left(\\frac{\\vec{a} \\cdot \\vec{b}}{\\norm{\\vec{a}} \\norm{\\vec{b}}}\\right)}\r\n\\end{equation*}\r\n\r\n\\begin{figure}[h]\r\n\t\\centering\r\n\t\\includegraphics[scale=0.33]{Images/backgroundReview/DotProduct}\r\n\\end{figure}\r\n\r\n\\noindent\r\nAlthough similar to scalar multiplication, dot products have some properties that set them apart.\r\n\\begin{itemize}\r\n\t\\item Commutative\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{a}\\cdot\\vec{b} = \\vec{b}\\cdot\\vec{a}\t\r\n\t\t\\end{equation*}\r\n\t\tthe same as scalar multiplication.\r\n\t\\item Distributive\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{a}\\cdot\\left(\\vec{b}+\\vec{c}\\right) = \\vec{a}\\cdot\\vec{b}+\\vec{a}\\cdot\\vec{c}\r\n\t\t\\end{equation*}\r\n\t\tthe same as scalar multiplication.\r\n\t\\item \\textbf{NOT} Associative $\\left(\\vec{a}\\cdot\\vec{b}\\right)\\cdot\\vec{c}$ is a nonsense expression. However, like scalar multiplication, dot products are scalar associative.\r\n\t\\begin{equation*}\r\n\t\t\\left(c\\cdot\\vec{a}\\right)\\cdot\\vec{b} = \\vec{a}\\cdot\\left(c\\cdot\\vec{b}\\right)\r\n\t\\end{equation*}\r\n\\end{itemize}", "meta": {"hexsha": "18c43afbdb8b31e3b1d784c50803e4b50ed25e40", "size": 1573, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/backgroundReview/dotProducts.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/backgroundReview/dotProducts.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/backgroundReview/dotProducts.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.15625, "max_line_length": 315, "alphanum_fraction": 0.6948506039, "num_tokens": 527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7380753091463216}}
{"text": "\\paragraph{\\underline{Hypothesis tests for the mean}}\n$\\mu$\n\n\\vspace{5pt}\n\\noindent \\textbf{One-sample z-test}\n$H_0: \\mu=\\mu_0$\n\nWe use it to check hypothesis that mean $\\mu$ is equal to the specific value $\\mu_0$. Critical\nregion is: $ \\mathcal{K}_\\alpha = (-\\infty, k] \\cup [k, +\\infty) $\n\n\\vspace{5pt}\n\\textbf{\\em Model 1}:\n$X$ i.i.d. $\\distnormal(\\mu, \\sigma)$, known $\\sigma$\n\n\\vspace{-15pt}\n\\begin{gather*}\nT=\\frac{\\bar{X}-\\mu_0}{\\sigma}\\sqrt{n} \n\\overset{H_0}{\\longrightarrow} \\distnormal(0,1)\n\\end{gather*}\n\n\\vspace{-20pt}\n\\begin{gather*}\nk = z_{1-\\frac{\\alpha}{2}}\n\\end{gather*}\n\n\\textbf{\\em Model 2}:\n$X$ i.i.d. ?, large $n$\n\n\\vspace{-15pt}\n\\begin{gather*}\nT=\\frac{\\bar{X}-\\mu_0}{s_X}\\sqrt{n} \n\\overset{H_0}{\\underset{n \\rightarrow \\infty}{\\longrightarrow}} \\distnormal(0,1)\n\\end{gather*}\n\n\\vspace{-15pt}\n\\begin{gather*}\nk = \\diststudentt^{[n-1]}_{1-\\frac{\\alpha}{2}}\n\\end{gather*}\n\n\\noindent \\textbf{One-sample t-test}\n$X$ i.i.d. $\\distnormal(\\mu, \\sigma)$, $\\sigma=?$, $H_0: \\mu=\\mu_0$\n\n\\vspace{-15pt}\n\\begin{gather*}\nz=\\frac{\\bar{X}-\\mu_0}{s_X}\\sqrt{n} \n\\overset{H_0}{\\longrightarrow} \\diststudentt^{[n-1]}\n\\end{gather*}\n\n\\vspace{-15pt}\n\\begin{gather*}\nk = z_{1-\\frac{\\alpha}{2}}\n\\end{gather*}\n\n\\noindent \\textbf{Two-sample z-test}\n\nWe use it to check a hypothesis that means of two samples are equal. The test can be applied in\nfollowing 2 cases:\n\n\\vspace{10pt}\n\\textbf{\\em Model 1}:\n$X$, $Y$ i.i.d. $\\distnormal(\\mu_{X,Y}, \\sigma_{X,Y})$,\n\nknown $\\sigma_X$ and $\\sigma_Y$, $H_0: \\mu_X=\\mu_Y$\n\n\\vspace{-15pt}\n\\begin{gather*}\na_I=\\frac{\\sigma_I^2}{n_I} \\;,\\;\nz=\\frac{\\bar{X}-\\bar{Y}}{ \\sqrt{a_X+a_Y} }\n\\longrightarrow \\distnormal(0,1)\n\\end{gather*}\n\n\\textbf{\\em Model 2}:\n$X$, $Y$ i.i.d. ?, large $n_{X,Y}$,\n\n$H_0: \\mu_X=\\mu_Y$\n\n\\vspace{-15pt}\n\\begin{gather*}\na_I=\\frac{s_X^2}{n_X} \\;,\\;\nz=\\frac{\\bar{X}-\\bar{Y}}{ \\sqrt{a_X+a_Y} }\n\\underset{n \\rightarrow \\infty}{\\longrightarrow} \\distnormal(0,1)\n\\end{gather*}\n\n\\noindent \\textbf{Two-sample t-test}\n\n\\vspace{10pt}\n\\textbf{\\em Model 1}:\n$X$, $Y$ i.i.d. $\\distnormal(\\mu_{X,Y}, \\sigma_{X,Y})$, \n\n$\\sigma_X=\\sigma_Y=?$, $H_0: \\mu_X=\\mu_Y$, \n$d = n_X+n_Y-2$, $a_i = (n_i - 1)s_i^2$\n\n\\vspace{-15pt}\n\\begin{gather*}\n\\dot{s}^2 = \\frac{a_X + a_Y}{d} \\;,\\; \nb_I=\\frac{\\dot{s}^2}{n_I}\n\\end{gather*}\n\n\\[ t=\\frac{\\bar{X}-\\bar{Y}}{ \\sqrt{b_X+b_Y} }\n\\overset{H_0}{\\longrightarrow} \\diststudentt^{[d]} \\]\n\n\\textbf{\\em Model 2}:\n$X$, $Y$ i.i.d. $N(\\mu_{X,Y}, \\sigma_{X,Y})$, \n\n$\\sigma_X=?$ and $\\sigma_Y=?$, $H_0: \\mu_X=\\mu_Y$\n\n\\vspace{-15pt}\n\\begin{gather*}\na_i = \\frac{s_i^2}{n_i} \\;,\\;\nd = \\frac{(a_X + a_Y)^2}{ \\frac{a_X^2}{n_X-1}+\\frac{a_Y^2}{n_Y-1} }\n\\end{gather*}\n\n\\vspace{-15pt}\n\\begin{gather*}\nt=\\frac{\\bar{X}-\\bar{Y}}{ \\sqrt{ a_X + a_Y } }\n\\overset{H_0}{\\longrightarrow} \\diststudentt^{[d]}\n\\end{gather*}\n\n\\vfill\n\\columnbreak\n\n\\noindent \\textbf{Paired t-test}\n$X$, $Y$ i.i.d. $\\distnormal(\\mu_{X,Y}, \\sigma_{X,Y})$, \n\n$\\sigma_X=?$ and $\\sigma_Y=?$, $H_0: \\mu_X=\\mu_Y$, \n\n$\\forall i: (X_i,Y_i)$ are dep., $Z=X-Y$\n\n\\vspace{-15pt}\n\\begin{gather*}\nt= \\frac{\\bar{Z}-0}{s_Z}\\sqrt{n} \n\\overset{H_0}{\\longrightarrow} \\diststudentt^{[n-1]}\n\\end{gather*}\n\nIt is usually used when identical samples are taken at two points in time, and we wish to check\nwhether there are significant differences between them.\n\n\\paragraph{\\underline{Hypothesis tests for variance}}\n$\\sigma^2$\n\n\\vspace{5pt}\n\\noindent \\textbf{One-sample test}\n$X$ i.i.d. $\\distnormal(\\mu, \\sigma)$, $H_0: \\sigma^2=\\sigma_0^2$\n\nWe use this test to test a hypothesis that $\\sigma^2$ is equal to a specific value $\\sigma_0^2$.\n$ \\mathcal{K}_\\alpha = (0, \\distchisquare_{k, \\frac{\\alpha}{2}}] \\cup [\\distchisquare_{k, 1-\\frac{\\alpha}{2}}, +\\infty) $\n\n\\vspace{5pt}\n\\textbf{\\em Model 1}:\nknown $\\mu$\n\n\\vspace{-15pt}\n\\begin{gather*}\nT = \\frac{n s_X^2}{\\sigma_0^2}\n\\overset{H_0}{\\longrightarrow} \\distchisquare_{n-1}\n\\end{gather*}\n\n\\vspace{-15pt}\n\\begin{gather*}\nk = n\n\\end{gather*}\n\n\\textbf{\\em Model 2}:\n$\\mu=?$\n\n\\vspace{-15pt}\n\\begin{gather*}\nT = \\frac{(n-1)s_X^2}{\\sigma_0^2}\n\\overset{H_0}{\\longrightarrow} \\distchisquare_{n-1}\n\\end{gather*}\n\n\\vspace{-15pt}\n\\begin{gather*}\nk = n-1\n\\end{gather*}\n\n\\noindent \\textbf{F-test}\n$X$, $Y$ i.i.d. $\\distnormal(\\mu_{X,Y}, \\sigma_{X,Y})$, \n\n$\\mu_X=?$ and $\\mu_Y=?$, $H_0: \\sigma_X^2=\\sigma_Y^2$\n\nWe use this test to test a hypothesis that two variances $\\sigma_X^2$ and $\\sigma_Y^2$ (for samples\n$X$ and $Y$ respectively) are equal.\n\n\\vspace{-15pt}\n\\begin{gather*}\nF = \\frac{s_X^2}{s_Y^2} \\overset{H_0}{\\longrightarrow} \\distf^{[n_1-1,n_2-2]}\n\\end{gather*}\n\n\\paragraph{\\underline{Hypothesis tests for proportion}} $p$\n\n\\vspace{5pt}\n\\noindent \\textbf{One-sample z-test}\n$X$ i.i.d. $Bern(p)$, $H_0: p=p_0$\n\nWe use this test to test a hypothesis that $p$ is equal to a specific value $p_0$. It applies to two\nsuch models:\n\n\\vspace{10pt}\n\\textbf{\\em Model 1}:\n$n_{X,Y}\\geq100$\n\n\\vspace{-15pt}\n\\begin{gather*}\nz=\\frac{\\hat{p}-p_0}{\\sqrt{p_0(1-p_0)}}\\sqrt{n}\n\\overset{H_0}{\\underset{n \\rightarrow \\infty}{\\longrightarrow}} \\distnormal(0,1)\n\\end{gather*}\n\n\\textbf{\\em Model 2}:\n$n_{X,Y}<100$, $A = \\arcsin$\n\n\\vspace{-15pt}\n\\begin{gather*}\nz=2\\left(A{\\sqrt{\\hat{p}}}-A{\\sqrt{p_0}} \\right)\\sqrt{n}\n\\longrightarrow \\distnormal(0,1)\n\\end{gather*}\n\n\\noindent \\textbf{Two-sample z-test}\n$X$, $Y$ i.i.d. $\\distbernoulli(p_{X,Y})$, $H_0: p_X=p_Y$\n\nWe use this test to test a hypothesis that parameters $p_X$ and $p_Y$ (which are empirical success\nrates for samples $X$ and $Y$ respectively) are equal. It applies to two such models:\n\n\\vspace{10pt}\n\\textbf{\\em Model 1}:\n$n_{X,Y}\\geq100$, $ k_I = \\Sigma_{i=1}^{n_I} I_i $\n\n$ \\dot{p}=\\frac{k_X+k_Y}{n_X+n_Y} \\mbox{ , } \\dot{n}=\\frac{n_X n_Y}{n_X+n_Y} $\n\n\\vspace{-15pt}\n\\begin{gather*}\nz=\\frac{\\hat{p_X}-\\hat{p_Y}}{\\sqrt{\\dot{p}(1-\\dot{p})}}\\sqrt{\\dot{n}}\n\\underset{n_{X,Y} \\rightarrow \\infty}{\\longrightarrow} \\distnormal(0,1)\n\\end{gather*}\n\n\\textbf{\\em Model 2}:\n$n_{X,Y}<100$, $A \\equiv \\arcsin$\n\n\\vspace{-15pt}\n\\begin{gather*}\nz=2\\left(A{\\sqrt{\\hat{p_X}}}-A{\\sqrt{\\hat{p_Y}}} \\right)\\sqrt{\\dot{n}}\n\\longrightarrow \\distnormal(0,1)\n\\end{gather*}\n\n\\vfill\n", "meta": {"hexsha": "7f1aa35d8c1f9db439d1c43b9b79dfab5fbb0819", "size": 6035, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_7b_tests_parametric_example.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_stars_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs_7b_tests_parametric_example.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_issues_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs_7b_tests_parametric_example.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_forks_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.5325203252, "max_line_length": 121, "alphanum_fraction": 0.6386081193, "num_tokens": 2463, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7380184927131418}}
{"text": "\\paragraph{Simplicial complexes.} \nA simplicial complex is a collection of finite sets closed under taking subsets.\nWe call a member of a simplicial complex $K$ a \\emph{simplex} of \\emph{dimension $p$} if it has cardinality $p+1$, and denote the set of all such $p$-simplices $K_p$.\nA $p$-simplex has $p+1$ \\emph{faces} of dimension $p-1$, namely the subsets omitting one element. We denote these $[v_0,\\dotsc,\\hat{v}_i,\\dotsc, v_p]$ when omitting the $i$'th element.\nIf a simplex $\\sigma$ is a face of $\\tau$, we say that $\\tau$ is a \\emph{coface} of $\\sigma$. While this definition is entirely combinatorial, there is a geometric interpretation, and it will make sense to refer to and think of $0$-simplices as \\emph{vertices}, $1$-simplices as \\emph{edges}, $2$-simplices as \\emph{triangles}, $3$-simplices as \\emph{tetrahedra}, and so forth (see Figure~\\ref{fig:data2complex}, (b)).\n\nLet $C^p(K)$ be the set of functions $K_p\\to\\RR$, with the obvious vector space structure. These \\emph{$p$-cochains} will encode our data. Define the linear \\emph{coboundary} maps $\\delta^p:C^p(K)\\to C^{p+1}(K)$ by\n\\begin{equation*}\n\\delta^p(f)([v_0,\\dotsc,v_{p+1}]) = \\sum_{i=0}^{p+1} (-1)^i f([v_0,\\dotsc,\\hat{v}_i,\\dotsc,v_{p+1}]).\n\\end{equation*}\nObserve that this definition can be thought of in geometric terms: The support of $\\delta^p(f)$ is contained in the set of $(p+1)$-simplices that are cofaces of the $p$-simplices that make up the support of $f$.\n\n\\begin{figure}[htpb]\n%\\begin{table*}[!t]\n\\savebox{\\tempbox}{% compute size of tabulat\n\\scriptsize{\n\\begin{tabular}{llr}\n    \\toprule\n    Papers & Authors & Citations \\\\\n    \\midrule\n    Paper I & A, B, C  & 100  \\\\\n    Paper II &  A, B & 50\\\\\n    Paper III & A, D & 10\\\\\n    Paper IV & C, D & 4\\\\\n    \\bottomrule\n  \\end{tabular}\n}}%\n\\settowidth{\\tempwidth}{\\usebox{\\tempbox}}%\n\\hfil\\begin{minipage}[b]{\\tempwidth}%\n\\raisebox{-\\height}{\\usebox{\\tempbox}}%\n%\\vspace{-7pt}\n\\scriptsize{\\caption*{(a)}}%\n\\label{table:data}%\n\\end{minipage}%\n\\savebox{\\tempbox}{\n\\input{figures/coauthorship_complex.tex}\n}%\n\\settowidth{\\tempwidth}{\\usebox{\\tempbox}}%\n\\hfil\\begin{minipage}[b]{\\tempwidth}%\n\\raisebox{-\\height}{\\usebox{\\tempbox}}%\n\\vspace{-3pt}\n\\scriptsize{\\captionof*{figure}{(b)}}%\n\\label{fig:co-authoship-complex}%\n\\end{minipage}%\n%\\vspace{5pt}\n%\\end{table*}\n\\savebox{\\tempbox}{\\scriptsize{\n\\begin{blockarray}{cccccc}\n\\tiny{AB} & \\tiny{AC} & \\tiny{AD} & \\tiny{BC} & \\tiny{CD} \\\\\n\\begin{block}{(ccccc)c}\n  3 & 0 & 1 & 0 & 0 & \\tiny{AB} \\\\\n  0 & 3 & 1 & 0 & -1 & \\tiny{AC} \\\\\n  1 & 1 & 2 & 0 & 1 & \\tiny{AD} \\\\\n  0 & 0 & 0 & 3 & -1 & \\tiny{BC}\\\\\n  0 & -1 & 1 & -1 & 2 & \\tiny{CD}\\\\\n\\end{block}\n\\end{blockarray}}}%\n\\settowidth{\\tempwidth}{\\usebox{\\tempbox}}%\n\\hfil\\begin{minipage}[b]{\\tempwidth}%\n\\raisebox{-\\height}{\\usebox{\\tempbox}}%\n\\vspace{-7pt}\n\\scriptsize{\\captionof*{figure}{(c)}}%\n\\end{minipage}%\n\n%\\end{table*}\n\\caption{Constructing a simplicial complex from data. (a)~Coauthorship data. (b)~Coauthorship complex with corresponding cochains from the data. (c)~Degree-$1$ Laplacian $L_1$ of the coauthorship complex.}\\label{fig:data2complex}\n\\end{figure}\n\n\n\\paragraph{Simplicial Laplacians.}\nWe are in this paper concerned with finite abstract simplicial complexes, although our method is applicable to a much broader setting, e.g.\\ CW-complexes. In analogy with Hodge--de Rham theory~\\cite{madsen1997calculus}, we define the \\emph{degree-$i$ simplicial Laplacian} of a simplicial complex $K$ as the linear map\n\\begin{align*}\n  &\\lap_i:C^i(K)\\to C^i(K) \\\\\n  &\\lap_i = \\lapu_i + \\lapd_i = \\delta^{i\\ast}\\circ\\delta^{i} + \\delta^{i-1}\\circ\\delta^{i-1\\ast},\n\\end{align*}\nwhere $\\delta^{i\\ast}$ is the adjoint of the coboundary with respect to the inner product (typically the one making the indicator function basis orthonormal). In most practical applications, the coboundary can be represented as a sparse matrix $B_i$ and the Laplacians can be efficiently computed as $L_i=B_i\\transpose B_{i}+B_{i-1}B_{i-1}\\transpose$. The matrices $L_0$ and $B_0$ are the classic graph Laplacian and incidence matrix. Note that the Laplacians carry valuable topological information about the complex: The kernel of the $k$-Laplacian is isomorphic to the $k$-(co)homology of its associated simplicial complex~\\cite{eckmann1944,horak2013spectra}\\footnote{In other words, the number of zero-eigenvalues of the $k$-Laplacian corresponds to the number of $k$-dimensional holes in the simplicial complex.}.\n", "meta": {"hexsha": "e1e8c9dfca1e15ecbe12f4f84b595a4cf5293749", "size": 4437, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "simpl.tex", "max_stars_repo_name": "stefaniaebli/paper-snn-neurips2020tda", "max_stars_repo_head_hexsha": "935658c9fa93897b4e288918e6e9c3fb0a0bee3e", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-01-06T18:45:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T05:09:20.000Z", "max_issues_repo_path": "simpl.tex", "max_issues_repo_name": "stefaniaebli/paper-snn-neurips2020tda", "max_issues_repo_head_hexsha": "935658c9fa93897b4e288918e6e9c3fb0a0bee3e", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "simpl.tex", "max_forks_repo_name": "stefaniaebli/paper-snn-neurips2020tda", "max_forks_repo_head_hexsha": "935658c9fa93897b4e288918e6e9c3fb0a0bee3e", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.6233766234, "max_line_length": 817, "alphanum_fraction": 0.6988956502, "num_tokens": 1560, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328345, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7379994391510795}}
{"text": "\n\\chapter{Machine Learning}\n\nThe general idea behind machine learning is this: Given a set of data, a machine creates a model that can be used to predict relationships between the various datum. The reasons for using a machine is generally because the size of the dataset, as well as the necessary computational requirements needed to make these models, is well beyond what is reasonable for a human to do alone.\n\nMachine learning breaks down each element of a dataset into a set of \\textbf{features} which describe it and differentiate it from the other elements. The resultant model is a collection of \\textbf{parameters} that describe the relationship between elements of the dataset. \\textbf{Hyperparameters} are parameters used in running the algorithm which arrives at the aforementioned parameters, and are not considered parameters of the model themselves.\n\nMost of machine learning can be broken up into three general sub-disciplines:\n\\begin{itemize}\n\t\\item \\B{Supervised Learning}: takes a set of labelled feature vectors and builds a model to predict unlabelled data. Simple linear regression is an example of supervised learning.\n\t\\item \\B{Unsupervised Learning}: takes a set of unlabelled feature vectors. This type of learning is useful for things like clustering, here the model looks to pair like-with-like, or dimensionality reduction, where the model translates a large set of features into a smaller set.\n\t\\item \\B{Reinforcement Learning}: uses a set of feature vectors to approximate a state which it can interact with through a set of actions, each of which are chosen to try to maximize some numerical reward signal. \n\\end{itemize}\n\n\n\nIn general, any machine learning algorithm can be broken down into three components \\cite{burkov}\n\\begin{itemize}\n    \\item A loss function (e.g. least squares)\n    \\item An optimization criterion based on the loss function (e.g. the loss landscape is convex); and\n    \\item An optimization routine leveraging training data to find a solution to the optimization criterion (e.g. gradient descent)\n\\end{itemize}\n\nA \\textbf{metric} is a function that measures the quality of the model's prediction (e.g. accuracy), whereas a \\textbf{loss function} is what is used by the training system to update its weights automatically (e.g. SSE). Metrics are primarily for human consumption, at the end of training cycles.\n\n\\subsection{Hyperparameters}\n\nHyperparameters are not optimized via the machine learning algorithm itself and instead are configured by the data analyst. One method to find a good set is \\B{grid search} which combinatorically scans over each parameter (typically in log scale). This of course doesn't work too well when the number of hyperparameters in your model grows. \n\n\\B{Random search} uses a statistical distribution for each hyperparameter which each get sampled from when making a new model to test.\n\n\\B{Bayesian hyperparemeter optimization} uses past evaluation results to choose the next values to evaluate. This aims to minimize the number of expensive optimizations you have to do.\n\n\n\n\n\n\\section{Support Vector Machines}\\label{sub:svm}\nSupport Vector Machines (SVM) classify data-points by drawing boundaries between them. These boundaries are called ``Hyperplanes\" and slice the points in their feature vectors. The technical definition of a hyperplane is any flat affine subspace. The data points “support\" the each of these planes. i.e those closest to each plane are optimized around. In the case of two classes $y_i \\in {-1,1}$. The ideal plane is defined as\n\\begin{align}\n\t\t\\B{wx}_i-b =0\n\\end{align}\nWhere $\\B{w}$ is the weights vector, which is optimized for, $\\B{x}_i$ is the feature vector, and $b$ is the offset. This plane separates the two classes based off of the sign of any feature vector put into this equation\n\\begin{align}\n\ty = \\textrm{sign}(\\B{wx}_i-b)\n\\end{align}\nOne should class should give positive values, and the other, negative values. Mathematically we look for each point to obey\n\n\\begin{align}\n\t\\B{wx}_i-b &\\ge +1 ~\\textrm{if}~ y_i = +1.  \\label{svm_planes_pos}\\\\\n\t\\B{wx}_i-b &\\le -1 ~\\textrm{if}~ y_i = -1.  \\label{svm_planes_neg}\n\\end{align}\n\nThe above equations define planes as shown in Figure \\ref{fig:svm}. The closest points of either classes are a separated by a distance $2/ ||\\B{w}||$. We want the plane to be maximally discriminating, which is equivalent to maximizing this distance, or equivalently, \\emph{minimizing} $||\\B{w}||$. Using quadratic programming optimization we typically look to minimize \\cite{burkov}\n\n\n\\begin{align}\\label{svm_loss}\n||\\B{w}||^2\n\\end{align}\n\nSVMs that minimize this function are said to have \\emph{hard-margin}s, since points that fall on the wrong side of the hyperplane are not considered in the minimization procedure. \n\n\\begin{figure}\n\\centerline{\\includegraphics[width=0.5\\linewidth]{mathematics/fig/svm.png}}\n\\caption{Maximum-margin hyperplane for an SVM trained with two classes \\cite{wiki_svm}}\n\\label{fig:svm}\n\\end{figure}\n\n\\subsection{Hinge Loss}\n\nIf the classes are not cleanly distinguishable, which can happen if there is noise in the data, or the classes aren't entirely separable, one can look to minimize the \\textbf{hinge loss function}, defined as\n\\begin{align}\\label{hinge}\n\tC||\\B{w}||^2 + \\frac{1}{N}\\sum_{i=1}^N \\max(0,1-y_i(\\B{wx}_i-b))\n\\end{align}\nThe first term in Equation \\ref{hinge} is proportional to \\ref{svm_loss}, while the second term is related to components on the wrong side of the boundary. Looking at Equations \\ref{svm_planes_pos} and \\ref{svm_planes_neg}, we see they are equivalent to \n\\begin{align}\n\ty_i(\\B{wx}_i-b) -1\\ge 0\\rightarrow 1- y_i(\\B{wx}_i-b) \\le 0\n\\end{align}\nTherefore for any points on the correct side of the boundary, this expression is negative and $0$ is taken from the $\\max$ function. However, if the point is on the \\emph{wrong} side of the hyperplane, the loss function then has an added term proportional to how far away it is from the decision boundary.\n\nSVMs that minimize the hinge loss are considered \\emph{soft-margin}, since they allow for points fo fall on either side.\n\nThe choice of $C$ determines how much relative weight to give to the margin size (first term) and mislabelling (second term). A large $C$ gives a large margin which is good for generalizing the problem, while a small $C$  looks to classify the training data well.\n\n\\section{Decision Trees}\nA decision tree is an acyclic graph that can be used to make decisions. Each ``leaf\" of the tree assigns a label to the given feature vector. A balanced decision tree is one for which the questions split the groups into equal parts.\n\n\\subsection{Entropy}\nGiven $N$ different possible labels a feature vector could be associated to, we define $p_i$ with $i\\in (1,N)$ as the proportion of any given label $i$. Using our full training dataset $D$, we can then define the entropy $S$ of the model as \n\n\\begin{align}\n\tS^{(D)} = -\\sum_{i=1}^N p^{(D)}_i\\ln p^{(D)}_i\n\\end{align}\n\nThis tells us roughly how mixed up our dataset is. If the training data has two labels which are equally populated in the dataset, we have correspondingly larger energy than if we had only one of the labels show up. In the ideal case, each leaf of a decision tree will have just one label. A metric by which we can gauge how close we are to this ideal is by \\emph{minimizing the entropy} of our model. \n\nThere are a number of algorithms that that recursively split the dataset into those with smaller entropy i.e. $D\\rightarrow D_1, D_2$. After doing this the effective entropy among the two independent datasets can be remeasured and compared with that before the split. This can then continue until a number of conditions are met such as you have only one kind of label, or there are no more splits that could further reduce the entropy.\n\n\n\\subsection{Ensemble Learning}\n\nOne method of training a machine learning model is to train many low-accuracy models at once and combining their predictions. This paradigm is known as \\textbf{ensemble learning}. Overall this collective of models should then give a high-accuracy \\textbf{meta-model}. This methodology is preferred because each of the individual models are simple \\textbf{weak learner} models which have their votes combined using a weighted average method.\n\n\\textbf{Boosting} is the general procedure of iteratively adding together weak learners to create a strong one. Essentially one weak-learner is trained and the next one begins, although the weights assigned to previously misclassified data are increased while those assigned to well-classified data are decreased.\n\nBootstrap aggregating or \\textbf{bagging} creates multiple datasets on which a weak learner can be trained. Generally this is done \\emph{with} replacement. \n\nIn the case of decision trees \\textbf{random forests} use this technique. For a tree used in a random forest, when a split would happen, instead of splitting on the the best feature, instead a random subset of all the features is chosen and the best feature among them is chosen to split on. This results in a collection of trees that each look \\emph{different} from each other and reduces the correlation that the trees would have if each were just to train the same way. This prevents the model from overfitting the data.\n\n\n\n\\section{Training Models}\n\n\n\\subsection{Linear Regression}\nLinear regression is a model which presumes a linear relationship between the feature vectors $\\B{x}$ and their corresponding label $y$. The linear model is defined as\n\n\\begin{align}\n    y_i = \\B{wx}_i +b\n\\end{align}\nWhere the index $i\\in(1,N)$ denotes the specific data point of the $N$ you are considering. The typical \\B{error function} $\\mathcal{E}$ (sometimes called a loss function) that is used is \\B{sum of squared error} (SSE) which is written as\n\\begin{align}\n    \t\\min_\\B{w}\\sum_{i=1}^N\\Big(\\B{wx}_i +b - y_i\\Big)^2\n\\end{align}\n\nWhich is read as a minimization of the expression with respect to the weights $\\B{w}$. \n\n\n\\subsubsection{Exact Solution}\\label{lin-reg-exact}\nThe sum of squared error (SSE) loss function is preferred in part because it is differentiable, which allows for an exact solution. We can take as an example a dataset with $i\\in(1,N)$ which includes one feature $x_i$ and its corresponding label $y_i$. This linear model is defined as\n\n\\begin{align}\ny_i = wx_i + b\n\\end{align}\n\nNow we wish to minimize our loss function. We can then recall that a function is at its extremum (here minimum) when the derivative is zero. Therefore we take the derivative with respect to both of the weights. For $w$ we have\n\\begin{align}\n\\frac{\\partial \\mathcal{E}}{\\partial w} = 0 &= \\frac{\\partial}{\\partial w} \\sum_i \\Big(wx_i + b - y_i \\Big)^2 \\\\\n&= 2\\sum_i \\Big(wx_i + b - y_i\\Big)x_i\\\\\n&= w\\sum_ix_i^2 + b\\sum_i x_i -\\sum_i y_i x_i \n\\end{align}\nSimilarly, for $b$\n\\begin{align}\n\\frac{\\partial \\mathcal{E}}{\\partial b} = 0 &= 2\\sum_i \\Big(wx_i + b - y_i\\Big)\\\\\n&= bN + w \\sum_i x_i - \\sum_i y_i \n\\end{align}\nNow we have a set of linear equations. We can easily calculate all of the sums, since they are by definition the data we are fitting to, and after some algebra, we can solve for the $w$ and $b$ which minimize the sum of squares.\n\\begin{align}\nw = \\frac{N\\sum_i y_i x_i  - \\sum_j y_j \\sum_i x_i }{N\\sum_i x_i^2 -\\Big(\\sum_i x_i\\Big)^2}\n&&b = \\frac{\\sum_i y_i - w \\sum_i x_i}{N}\\\\\n\\end{align}\nIn actual code, we can implement it as follows\n\n\n\\lstinputlisting[language=Python]{mathematics/code/linearRegressionExact.py}\n\n\\centerline{\\includegraphics[width=0.7\\textwidth]{mathematics/fig/linearRegressionExact.png}}\n\n\\subsubsection{$\\boldsymbol{\\chi}^2$ Minimization}\nIf each measurement is not made equally well for all points in the data set, the loss function can be adjusted to accommodate each individual measurements uncertainty. The $\\chi^2$ of the fit is then used as the loss function, defined as\n \\begin{align}\n    \t\\chi^2 = \\sum_{i=1}^N\\Big(\\frac{\\B{wx}_i +b - y_i}{\\sigma_i}\\Big)^2\n\\end{align}\nWhere $\\sigma_i$ is the uncertainty on the measured value $y_i$. An optimizer then looks to minimize this quantity\n\\begin{align}\n    \\min_\\B{w}  \\sum_{i=1}^N\\Big(\\frac{\\B{wx}_i +b - y_i}{\\sigma_i}\\Big)^2\n\\end{align}\n\n\n\\subsubsection{Ridge Regression}\nRidge regression is a linear regression with an added penalty term proportional to the sum of the squared weights. If we have $M$ total features, then we can express each break up our weight vector $\\B{w}$ into individual components as  $w_j$ for $j\\in (1,M)$. For simplicity we will also take $w_0 = b$. Ridge regression therefore use the loss function defined below\n\\begin{align}\n    \t\\min_\\B{w} \\Big[\\alpha\\sum_{j=0}^Mw_j^2 + \\sum_{i=1}^N\\Big(\\B{wx}_i +b - y_i\\Big)^2 \\Big]\n\\end{align}\nRidge regression looks to prevent any one weight $w_j$ from becoming significantly larger than the rest due to the squaring. This effectively prevents the model from becoming heavily dependent on any single weight which is helpful in situations where the feature vectors are correlated (multicollinearity). \n\nRidge regression is also preferred in some cases due to its differentiability, which allows it to be optimized using gradient descent. Ridge regression is sometimes called L2 regularization, since it is regularization associated with the square.\n\n\\subsubsection{Lasso}\nThe LASSO (Least Absolute Shrinkage and Selection Operator) is defined as \n\n\\begin{align}\n    \t\\min_\\B{w} \\Big[\\alpha\\sum_{j=0}^M|w_j| + \\sum_{i=1}^N\\Big(\\B{wx}_i +b - y_i\\Big)^2 \\Big]\n    \t\\end{align}\n    \t\nWith $w_j$ in our $\\B{w}$ vector for $j\\in (1,M)$ and $w_0 = b$. It is similar in appearance to Ridge regression, although each weight is no longer squared. This  allows for the individual weights to go to zero (unlike Ridge Regression) and effectively selects for the smallest number of applicable weights. This is helpful if we want to reduce the number of parameters our model is dependent on. Lasso regression is sometimes called L1 regularization, since it is regularization associated with the linear term.\n\n\n\\subsection{Gradient Descent}\\label{grad-descent}\n\nThe gradient is the localized slope of a function. Gradient descent is a means of finding a minimum (typically of a loss function) by following this slope towards a minimum. The crux of gradient descent goes like this\n\\begin{enumerate}\n    \\item Initialize each of our weights $w_j$\n    \\item Begin a new \\B{epoch} for which we use the entire dataset to calculate our error function $\\mathcal{E}$ using our current weights $w_j$\n    \\begin{itemize}\n    \\item If this loss is below a threshold, we're done, otherwise we continue    \n    \\end{itemize}\n    \\item Calculate the gradient of our error function \n    \\begin{align}\n        \\frac{\\partial \\mathcal{E}}{\\partial w_j}\n    \\end{align}\n    \\item Move the weights in a direction such that the loss function should shrink by an amount proportional to the \\B{learning rate} $\\alpha$\n    \\begin{align}\n        w_j \\leftarrow w_j - \\alpha\\frac{\\partial \\mathcal{E}}{\\partial w_j}\n    \\end{align}\n    \\item Loop back to Step 2.\n\\end{enumerate}\n\n\\subsubsection{Linear Regression with Gradient Descent}\n\n As an example, we have already calculated the gradient of our linear regression model in Section \\ref{lin-reg-exact}. The gradient of the sum of squared errors is given by\n\\begin{align}\n    \\frac{\\partial \\mathcal{E}}{\\partial w} &= 2\\Big(w\\sum_ix_i^2 + b\\sum_i x_i -\\sum_i y_i x_i\\Big)\\label{grad_sse_w}\\\\\n    \\frac{\\partial \\mathcal{E}}{\\partial b} &= 2\\Big(bN + w \\sum_i x_i - \\sum_i y_i \\Big)\\label{grad_sse_b}\n\\end{align}\nAlthough we were able to solve this method exactly with some algebra before, it is instructive to show how gradient descent can be used on the same model, since in general it can be used in cases were we \\emph{do not} have an exact solution.\n\nBelow shows the implementation of the algorithm described in Section \\ref{grad-descent} for the same set of data as was used in the exact case.\n\n\\lstinputlisting[language=Python]{mathematics/code/linearRegressionGradient.py}\n\n\\centerline{\\includegraphics[width=0.7\\textwidth]{mathematics/fig/linearRegressionGradient.png}}\n\n\n\n\\subsubsection{Minibatch and Stochastic Gradient Descent}\n\nGradient descent is powerful in its generality but can be rather slow since it requires looping over the entire dataset once for each epoch. This issue can be mitigated using one (or both) of the methods below\n\\begin{itemize}\n    \\item \\B{Minibatch Gradient Descent}: Chops up the dataset into shuffled ``minibatches\" for which gradients are calculated and the weights are adjusted within each epoch\n    \\item \\B{Stochastic Gradient Descent}: Adjusts the weights based off of \\emph{every data point} within each epoch. It is particularly useful when there is redundancy in the data and the gradient is stable.\n\\end{itemize}\n\n\n\\subsubsection{Gradient Boosting}\nBoosting involves using many simple, weak-learner, models together to obtain a strong-learner when they are combined. Gradient boosting involves refitting the residual of the last weak-learner trained. For instance lets start with a simple regression model\n\\begin{align}\n    f = f_0(\\textbf{x}) \\equiv \\frac{1}{N}\\sum_{i=1}^N y_i\n\\end{align}\nThe first weak learner would output this value. Then the residuals of this model are calculated\n\\begin{align}\n    \\hat{y}_i \\leftarrow y_i - f(\\textbf{x}_i)\n\\end{align}\nThe subsequent weak-learner $f_1$ is then trained on these values and the overall model is updated to $f \\equiv f_0 + \\alpha f_1$ where $\\alpha$ is a hyperparameter. This effectively calculates a Taylor series expansion when all the weak-learners are put together.\n\n\\subsection{Newton's Method}\nNewton's method uses the second order Taylor expansion of the function to estimate the extremum in an optimization problem. This is contrasted with gradient descent which uses only the first order. Given a point $x_k$ where the optimizer is currently while looking for the extremum of $f(x)$, we have that\n\\begin{align}\n\tf(x_k+t)\\approx f(x_k) + f'(x_k)t + \\frac{1}{2}f''(x_k)t^2\n\\end{align}\nIf the second derivative $f''(x_k)$ is positive, the extremum of $f(x_k+t)$ will be when $f'(x_k+t) = d/dt f(x_k+t) = 0$ since $x=x_k+t$. This can be written as \n\\begin{align}\n\t\\frac{d}{dt}\\Big( f(x_k) + f'(x_k)t + \\frac{1}{2}f''(x_k)t^2\\Big) = f'(x_k)+f''(x_k)t = 0 \n\\end{align}\nTherefore under these conditions, $t = -f'(x_k)/f''(x_k)$ and the we assign the best estimate for the extremum of the function as\n\\begin{align}\n\tf(x_{k+1}) = f(x_k)-\\frac{f'(x_k)}{f''(x_k)}\n\\end{align} \n\n\n\\subsection{$k$-Nearest Neighbors}\\label{sub:knn}\nOne of the simpler machine learning algorithms, $k$-nearest neighbors (KNN) takes in a new event (with it's own set of features) and finds the  $k$ events in the training data which it is closest to. This distance definition is adjustable. Once all the neighbors have been found, each votes on how to classify the new event.\n\nThis distance metric generally scales exponentially when new dimension are introduced, so it is advised to run dimensionality reduction (Section \\ref{dim_red}) if using KNN for a high dimensional dataset.\n\\subsection{Naive Bayes}\nWhen trying to deduce the probability of something dependent on many features $X_i$ conditional on something $S$, the naive way to do it is to assume they are all independent of each other\n\\begin{align}\\label{naive_bayes}\n\tP(X_1,X_2,\\dots,X_n|S) = P(X_1|S)P(X_2|S)\\dots P(X_n|S)\n\\end{align}\nThis is the assumption made in Naive Bayes, for which computing the right side of Equation \\ref{naive_bayes} is much easier than when one would need to look out for correlations.\n\nWhen estimating $P(X_i|S)$ it is typical to use a \\textit{pseudocount} for it's estimate so we don't assign 0 or 1 to the probability and bias our results. According to \\cite{sutton} this is\n\\begin{align}\n\tP(X_i|S) = (k+\\textrm{number~of~} S's\\textrm{~with~} X_i's) / (2k+\\textrm{number~of~} S \\textrm{~total})\n\\end{align}\n\n\\subsection{Cross-Validation}\nCross-validation is helpful in cases where you do not have enough data to split into the training-validation-test sets \\cite{burkov}. The procedure creates effective validation regions as follows\n\n\\begin{enumerate}\n    \\item Fix the values of the hyperparameters you want to evaluate\n    \\item Split your training set into several subsets of the same size (each called a \\B{fold}). Typically five-fold cross-validation is what is done e.g $\\{F_1, F_2, \\ldots, F_5\\}$\n    \\item Train the same number of models as you have folds. Each model $f_i$ should be trained using each fold $F_j$ except for $F_{j=i}$. In our example model $f_1$ would use $\\{F_2, F_3, F_4,F_5\\}$\n    \\item Use the remaining fold $F_{j=i}$ as a validation region for each model $f_i$\n    \\item Assign the average value of the metric of interest you are looking at as the final value\n\\end{enumerate}\nGrid search and cross-validation are sometimes used together to find the best values of hyperparameters for a given model.\n\n\\subsection{Ant Colony Optimization}\nTODO\n\n\\subsection{Dealing with Missing Features}\nIf the dataset you have contains entries for which some of the features are missing, the easiest thing to do is remove them from the dataset and proceed with the learning algorithm. If not, one option is to use \\B{data imputation} which replaces the missing value be an average value over the dataset.\n\n\\section{Fitting Models}\n\nA machine learning model is said to \\B{underfit} the data if the model makes many mistakes on the training data. For example if a linear function is fit to set of features that change quadratically. A model that underfits its training data is said to have \\B{high bias}, in that its expected value is know to differ from the true underlying distribution being estimated.\n\nOn the other hand, a model is said to \\B{overfit} the data if the model fits the training data very well, but is seen to perform poorly on validation or test datasets. Models which overfit the data are said to have \\B{high variance}, meaning small changes in your training data produce big changes to your model.\n\n\\subsection{Regularization}\nRegularization is an umbrella term that encompasses a collection of methods that are used to decrease the complexity of models that machine learning algorithms produce.\n\n\\subsubsection{Dropout}\nDropout involves randomly selecting some units in your network to ignore in your computation when running a training example through the network. This has the benefit of making the model less dependent on any one unit.\n\n\\subsubsection{Batch-Normalization}\nNormalizing the data involves scaling it to have a mean of 0 and standard deviation of 1. Batch-normalization is the process of standardizing the data between each neural network layer such that the following layer sees normalized data. This results in faster and more stable training. \n\n\\subsection{Model-Based vs Instance-Based Learning}\nModel-based learning involves finding optimal parameters and uses a training dataset for its construction. An example is Support Vector Machines (Section \\ref{sub:svm}). Model-based architectures typically construct three different datasets\n\\begin{itemize}\n    \\item \\B{Training Dataset}: used to train the model\n    \\item \\B{Validation Dataset}: used choose the best algorithm and  for tuning the hyperparameters \n    \\item \\B{Test Dataset}: Assesses the model before it is deployed in the wild\n\\end{itemize}\n\nInstance-based learning involves using the whole dataset as the model. An example is $k$-Nearest Neighbors (Section \\ref{sub:knn}).\n\n\n\\section{Classification}\nClassification attempts to group like items together. In machine learning, a classification model attempts to ascribe a label given a set of features (e.g. ``spam\", or ``not spam\"). The performance breakdown of classifiers generally involves combinations of the following quantities\n\n\\begin{center}\n \\begin{tabular}{||c c||} \n \\hline\n\\B{Name} (Abbr.) & \\B{Description} \\\\ [0.5ex] \n \\hline\\hline\nPositive (P) & Real positive cases in the data  \\\\ \n \\hline\n Negative (N)& Real negative cases in the data  \\\\\n \\hline\n True Positive (TP) & Positive cases correctly identified  \\\\\n \\hline\nTrue Negative (TN) & Negative cases correctly identified \\\\\n \\hline\nFalse Positive (FP) & Positive cases incorrectly identified   \\\\ \n \\hline\n False Negative (FN) &   Negative cases incorrectly identified\\\\\n \\hline\n\\end{tabular}\\label{forcing}\n\\end{center}\n\nAnother helpful breakdown of the table considers the total positive (P) and negative (N) cases in terms of those in the table\n\\begin{align}\n    \\textrm{P} = \\textrm{TP+FN} && \\textrm{N} = \\textrm{TN+FP} \n\\end{align}\n\n\\subsection{Accuracy}\nA tests accuracy tells you how often you get the right answer, defined as\n\\begin{align}\n\t\\textrm{Accuracy} = \\frac{\\textrm{TP+TN}}{\\textrm{P+N}}\n\\end{align}\n\nWhen writing a classifier, the accuracy of the model is not all that counts. For instance one can quite simply build a model that predicts with over $98\\%$ accuracy if a newborn baby will ever develop leukemia. This model just predicts that no baby will develop leukemia, and is clearly not the kind of model that makes machine learning interesting.\n\n\\subsection{Confusion Matrix} \n \n The confusion matrix (sometimes called the error matrix) is a tool used to visualize a classifiers performance which compares the label the algorithm predicted, and what it actually is.\n\\\\\n\\\\\n\\centerline{\\begin{tabular}{cc|c|c|}\n\\cline{3-4}\n && \\multicolumn{2}{ c| }{\\B{Actual Value}} \\\\ \\cline{3-4}\n && True & False  \\\\ \\cline{1-4}\n\\multicolumn{1}{ |c  }{\\multirow{2}{*}{\\B{Predicted}}} &\n\\multicolumn{1}{ |c| }{True} & TP & FP       \\\\ \\cline{2-4}\n\\multicolumn{1}{ |c  }{}                        &\n\\multicolumn{1}{ |c| }{False} & FN & TN     \\\\ \\cline{1-4}\n\\end{tabular}}\n\\\\\n\nFrom these values we can measure the precision and recall which are both standard ways of measuring a classifiers performance. \\B{Precision} is defined as\n\\begin{align}\n\t\\textrm{Precision} = \\frac{\\textrm{TP}}{\\textrm{TP+FP}}\n\\end{align}\nwhich tells us the correct positive predictions to the total positive predictions. Another important quantity is the \\B{recall} (sometimes called the sensitivity) which is defined as\n\\begin{align}\n\t\\textrm{Recall} = \\frac{\\textrm{TP}}{\\textrm{TP+FN}}\n\\end{align}\n\nwhich tells us the correct positive predictions out of the total positive true cases. Both tell us different things. In the case of spam detection, we generally want high precision (i.e. all of the things we label as spam are actually spam) and can afford lower recall (i.e. we don't have to mark every piece of spam as spam). Both should always be reported together. The classifier is perfect if both precision and recall are one.\n\n\\subsection{ROC Curve}\nThe ROC curve stands for \"receiver operating characteristic\" and originates from radar engineering. Each curve, such as those shown in Figure \\ref{fig:roc-curve} characterize the performance of a classifier. Each curve shows the \\B{true positive rate} (TPR) against the \\B{false positive rate} (FPR) for a given classifier with\n\\begin{align}\n    \\textrm{TPR} \\doteq \\frac{\\textrm{TP}}{\\textrm{TP+FN}} && \\textrm{FPR} \\doteq \\frac{\\textrm{FP}}{\\textrm{FP+TN}}\n\\end{align}\nClassifiers are only good if they are better than a random choice. The diagonal line defines the curve $\\textrm{TP}/\\textrm{P} = \\textrm{FP} /\\textrm{N}$, which is to say that the proportion of positives the classifier selects among actual positive values is equal to the amount of positives you mistakenly select among all the negative values. A good classifier however will always find the proportion of positives among all positive values at a greater rate than it will find positives among the negative values. This equates to \n\\begin{align}\n        \\textrm{TPR} \\geq \\textrm{FPR}\n\\end{align}\nand equates to a curve to the left of the random classifier. In the ideal case\nwe get all our positive guesses correct, which equates to a point at the top left.\n\nDifferent curves are compared using the area under the curve (AUC), with a higher value implies a better classifier. Areas range from $0$ to $1$.\n\n\\begin{figure}\n\\centerline{\\includegraphics[width=0.7\\textwidth]{mathematics/fig/rocCurve.png}}\n\\label{fig:roc-curve}\n\\caption{ROC curve}\n\\end{figure}\n\n\\subsection{Logistic Regression}\nLogistic regression is not in fact a regression but a classification algorithm. The idea is to parameterize how certain you are some set of features $\\B{x}$ is, or is not within a certain class (i.e. $y\\in \\{0,1\\}$). We do this via a function which outputs a value which corresponds to which class we think it is in. In essence we need a function with the properties\n\\begin{align}\n    f(x)=1 &&\\textrm{when}&~ x\\rightarrow\\infty\\\\\n    f(x)=0 &&\\textrm{when}&~ x\\rightarrow-\\infty\n\\end{align}\nwhich is smooth (differentiable) in between. The class of these functions are known as \\B{sigmoid functions}.  One example of a sigmoid function is the \\B{logisitic function} which spans $(0,1)$ increasing monotonically with its argument.\n\\begin{align}\n\tf(x) = \\frac{1}{1+e^{-x}}\n\\end{align}\nThis distribution is identical to the Fermi-Dirac distribution from Physics which describes the average number of fermions that occupy a given energy state. The logistic function also holds an attractive feature in its derivative\n\\begin{align}\\label{eq:sig_der}\n    \\frac{d}{dx}f(x) = \\frac{e^x\\cdot(1+e^x)-e^x\\cdot e^x}{(1+e^x)^2} = f(x)\\Big(1-f(x)\\Big)\n\\end{align}\nWhich allows for easy calculation of gradients. When doing machine learning typically a linear regression term is used for the exponent, to account for different dependencies of each feature.\n\\begin{align}\n\tf_{\\mathbf{w},b}(\\mathbf{x}) = \\frac{1}{1+e^{-(\\mathbf{wx} +b)}}\n\\end{align}\nWhere $\\B{w}$ the weight vector and $b$ the offset are parameters to be fit. The optimal values for $\\B{w}$ and $b$ are typically found via gradient descent. Following Equation \\ref{eq:sig_der}, each parameter would be updated with the rule\n\\begin{align}\n    \\B{w}&\\leftarrow\\B{w}+\\alpha~\\B{x} f_{\\mathbf{w},b}(\\mathbf{x}) \\Big(1-f_{\\mathbf{w},b}(\\mathbf{x})\\Big)\\\\\n    b&\\leftarrow b +\\alpha f_{\\mathbf{w},b}(\\mathbf{x}) \\Big(1-f_{\\mathbf{w},b}(\\mathbf{x})\\Big)\n\\end{align}\n\n\n\\subsubsection{Softmax Function}\nThe softmax function is the multinomial version of the logisitic function, used for when we have more than two categories. It is defined as \n\\begin{align}\n    \\sigma(x_i) = \\frac{e^{x_i}}{\\sum_{j=1}^K e^{x_j}}\n\\end{align}\nWhere $K$ is the total amount of categories you have and $i\\in(1,\\ldots,K)$. For each category $i$, some real-valued quantity $x_i\\in(-\\infty,\\infty)$ is calculated from the objects features $\\B{x}$. Those with features similar to a category have a large $x_i$, and those unlike the category yield a small $x_i$. The relative probability among the different categories is then given by $\\sigma(x_i)$. The denominator is used to normalize the quantity to unity. The softmax function is identical to the Boltzmann distribution of Physics.\n\n\n\n\\section{Neural Networks}\nThe main ingredients in neural networks are units that perform logistic regression. Each of these units, which acts analogously to a neuron in the brain, are called a \\B{perceptron}. These perceptrons are put in \\B{layers} which generally feed the into one another. Each perceptron itself is a mathematical function which acts on its input via it's activation function $g$, and provides an output $y$\n\n%\n%\\begin{figure}[t]\n%\t\\centering\n%\t\\begin{tikzpicture}[shorten >=1pt]\n%\t\t\\tikzstyle{unit}=[draw,shape=circle,minimum size=1.cm]\n% \t\t\\tikzstyle{hidden}=[draw,shape=rectangle,minimum size=1.15cm]\n%        \\tikzstyle{annot_small} = [text width=4em, text centered]\n%        \\tikzstyle{annot_big} = [text width=8em, text centered]\n%\n%\t\t\\node[unit](x0) at (-2,3){$x_0$};\n%\t\t\\node[unit](x1) at (-2,1){$x_1$};\n% \n%\t\t\\node[hidden](h10) at (1.7,3.5){$y_0^{(1)}\\leftarrow g^{(1)}(\\B{w}_{1,0}\\B{x}+b_{1,0})$};\n%\t\t\\node[hidden](h11) at (1.7,2){$y_1^{(1)}\\leftarrow g^{(1)}(\\B{w}_{1,1}\\B{x}+b_{1,1})$};\n%\t\t\\node[hidden](h12) at (1.7,0.5){$y_2^{(1)}\\leftarrow g^{(1)}(\\B{w}_{1,2}\\B{x}+b_{1,2})$};\n% \n%\t\t\\node(h22) at (5,0){};\n%\t\t\\node(h21) at (5,2){};\n%\t\t\\node(h20) at (5,4){};\n%\t\t\n%\t\t\\node[hidden](h20) at (7.5,3.5){$y_0^{(2)}\\leftarrow g^{(2)}(\\B{w}_{2,0}\\B{y}^{(1)}+b_{2,0})$};\n%\t\t\\node[hidden](h21) at (7.5,2){$y_1^{(2)}\\leftarrow g^{(2)}(\\B{w}_{2,1}\\B{y}^{(1)}+b_{2,1})$};\n%\t\t\\node[hidden](h22) at (7.5,0.5){$y_2^{(2)}\\leftarrow g^{(2)}(\\B{w}_{2,2}\\B{y}^{(1)}+b_{2,2})$};\n%\t\t\n%\t\n%\t\t\\node[unit](y1) at (11,2){$y$};\n%\t\t\n%\t\t\\foreach \\i in {0,...,1}\n%\t\t  \\foreach \\j in {0,...,2}\n%\t\t{\n%\t\t  \\draw[->] (x\\i) -- (h1\\j.west);\n%\t\t}\n%\t\t\n%\t\t\\foreach \\i in {0,...,2}\n%\t\t  \\foreach \\j in {0,...,2}\n%\t\t{\n%\t\t  \\draw[->] (h1\\i.east) -- (h2\\j.west);\n%\t\t}\n% \n%\t\t\\foreach \\i in {0,...,2}\n%\t\t{\n%\t\t  \\draw[->] (h2\\i.east) -- (y1);\n%\t\t}    \n%        \n%        \\node[annot_small, above of=x0, node distance=1.5cm](input){input layer};\n%        \\node[annot_big, above of=h10, node distance=1.5cm](hide1){$1^{\\textrm{st}}$ hidden layer};\n%        \\node[annot_big, above of=h20, node distance=1.5cm](hide2){$2^{\\textrm{nd}}$ hidden layer};\n%        \\node[annot_small, above of=y1, node distance=2.cm](output){output layer};\n%        \n%        \\end{tikzpicture}\n%\t\\caption[mlp]{Two hidden-layer, feedforward neural network. Two features are feed into the first hidden layer with activation function $g^{(1)}$. The outputs of the first hidden layer $y^{(1)}$ are feed into the second layer with activation function $g^{(2)}$. The output of the second layer $y^{(2)}$ are then combined to form a single output.}\n%\t\\label{fig:multilayer-perceptron}\n%\\end{figure}\n\n\n\n\\begin{figure}[t]\n\t\\centering\n\t\\begin{tikzpicture}[shorten >=1pt]\n\t\t\\tikzstyle{unit}=[draw,shape=circle,minimum size=1.cm]\n \t\t\\tikzstyle{hidden}=[draw,shape=rectangle,minimum size=1.15cm]\n        \\tikzstyle{annot_small} = [text width=4em, text centered]\n        \\tikzstyle{annot_big} = [text width=8em, text centered]\n\n\t\t\\node[unit](x0) at (-2,3){$x_0$};\n\t\t\\node[unit](x1) at (-2,1){$x_1$};\n \n\t\t\\node[hidden](h10) at (1.3,3.5){$o_0^{(1)}\\leftarrow g^{(1)}(w_{0j}^{(1)}x_j^{(0)})$};\n\t\t\\node[hidden](h11) at (1.3,2){$o_1^{(1)}\\leftarrow g^{(1)}(w_{1j}^{(1)}x_j^{(0)})$};\n\t\t\\node[hidden](h12) at (1.3,0.5){$o_2^{(1)}\\leftarrow g^{(1)}(w_{2j}^{(1)}x_j^{(0)})$};\n \n\t\t\\node(h22) at (5,0){};\n\t\t\\node(h21) at (5,2){};\n\t\t\\node(h20) at (5,4){};\n\t\t\n\t\t\\node[hidden](h20) at (6.,3.5){$o_0^{(2)}\\leftarrow g^{(2)}(w_{0j}^{(2)}o_j^{(1)})$};\n\t\t\\node[hidden](h21) at (6.,2){$o_1^{(2)}\\leftarrow g^{(2)}(w_{1j}^{(2)}o_j^{(1)})$};\n\t\t\\node[hidden](h22) at (6.,0.5){$o_2^{(2)}\\leftarrow g^{(2)}(w_{2j}^{(2)}o_j^{(1)})$};\n\t\t\n\t\n\t\t\\node[hidden](y1) at (10,2){$y\\leftarrow g^{(3)}(w_{0j}^{(3)}o_j^{(2)})$};\n\t\t\n\t\t\\foreach \\i in {0,...,1}\n\t\t  \\foreach \\j in {0,...,2}\n\t\t{\n\t\t  \\draw[->] (x\\i) -- (h1\\j.west);\n\t\t}\n\t\t\n\t\t\\foreach \\i in {0,...,2}\n\t\t  \\foreach \\j in {0,...,2}\n\t\t{\n\t\t  \\draw[->] (h1\\i.east) -- (h2\\j.west);\n\t\t}\n \n\t\t\\foreach \\i in {0,...,2}\n\t\t{\n\t\t  \\draw[->] (h2\\i.east) -- (y1);\n\t\t}    \n        \n        \\node[annot_small, above of=x0, node distance=1.5cm](input){input};\n        \\node[annot_big, above of=h10, node distance=1.5cm](hide1){$1^{\\textrm{st}}$ hidden layer};\n        \\node[annot_big, above of=h20, node distance=1.5cm](hide2){$2^{\\textrm{nd}}$ hidden layer};\n        \\node[annot_small, above of=y1, node distance=2.cm](output){output layer};\n        \n        \\end{tikzpicture}\n\t\\caption[mlp]{Three layer feed-forward neural network with two hidden-layers. Two features are feed into the first hidden layer with activation function $g^{(1)}$. The outputs of the first hidden layer $o_j^{(1)}$ are feed into the second layer with activation function $g^{(2)}$. The output of the second layer $o_j^{(2)}$ are then feed into the output layer activation function $g^{(3)}$ and combined to form a single output.}\n\t\\label{fig:multilayer-perceptron}\n\\end{figure}\n\n\nFigure \\ref{fig:multilayer-perceptron} shows a \\B{multilayer perceptron} (MLP) neural network architecture. This network is \\B{feed-forward} meaning that all perceptrons connect in the direction going from input to output. Each layer itself is \\B{fully-connected}, meaning that each output the preceding layer is used as input for each of the nodes in the following layer.\n\n\\subsubsection{Notation}\nList of terms used to describe an $m$ layer neural network are listed below\\cite{brilliant_backpropagation}. Values in parentheses \n\\\\\n\\begin{tabular}{ l c }\n  $r_l$ & number of neurons on layer $l\\in[1,m]$\\\\\n  $w_{ij}^{(l)}$ & weight given to output of neuron $j$ used in neuron $i$ on layer $l$  \\\\\n  $b_i^{(l)}$ & bias used in neuron $i$ on layer $l$   \\\\\n  $a_i^{(l)}$ & the product sum plus bias (activation) for node $i$ on layer $l$  \\\\\n  $o_i^{(l)}$ & the output of neuron $i$ on layer $l$ \\\\\n  $g^{(l)}$ & activation function for the hidden layer neurons\\\\\n\\end{tabular}\\\\\n\\\\\nExplicitly, the activation is written as\n\\begin{align}\n\ta_i^l =b_i^l + w_{ij}^lo_j^{l-1}\n\\end{align}\nWith summation implied following Einstein notation (Section \\ref{einstein_notation}) and $j\\in [1,r_{l-1}]$. If we define\n\\begin{align}\n\tw^l_{0i}=b_i^l && o_0^{l-1}=1\n\\end{align}\nWe can simplify the sum to\n\\begin{align}\\label{nn_activation}\n\ta_i^l = w_{ij}^lo_j^{l-1}\n\\end{align}\nwith $j\\in [0,r_{l-1}]$.\n\n\\subsubsection{Activation Functions}\nThe activation function $g$ of a neural network must be differentiable, but otherwise has no hard constraints. Some that are typically used:\n\\begin{itemize}\n    \\item \\B{Logistic function}\n\\begin{align}\n\tg(x) = \\frac{1}{1+e^{-x}}\n\\end{align}\nRecently fallen out of favor since $g(0)=1/2$, which means a perceptron with input sum $0$ would have a positive output. Additionally the gradient is very small for large $|x|$, which leads to weights getting stuck \\cite{grus}.\n    \\item \\B{TanH}\n\\begin{align}\n    g(x) = \\tanh (x) = \\frac{e^x-e^{-x}}{e^x+e^{-x}}\n\\end{align}\n    Hyperbolic tangent is a popular alternative to the logistic function.\n    \\item \\B{ReLU}\n    \\begin{align}\n     g(x)= \n\\begin{cases}\n    0 & \\text{if } x <  0\\\\\n    x & \\text{otherwise}\n\\end{cases}\n\\end{align}\nThe Rectified Linear Unit is popular because its derivative is so simple to calculate which allows neural networks with many layers to update more easily. Additionally it does not have a problem with a vanishing gradient explained in Section \\ref{sec:backprop}, unlike both TanH and the Logistic function.\n\\end{itemize}\n\n\\subsection{Backpropagation}\\label{sec:backprop}\nTo calculate the correct weights used by the activation function of each perceptron, typically some form of gradient descent is used in conjunction with an error function $\\mathcal{E}$. This requires one to be able to compute the gradient of $\\mathcal{E}$ with respect to the individual perceptrons weights. Using gradient descent, we look for\n\\begin{align}\n\\frac{\\partial \\mathcal{E}}{\\partial w_{ij}^l}\n\\end{align}\nBetween the output and the weights themselves, a lot of manipulation goes on. Firstly the weights are combined in the activation product sum $a_i^l$ of layer $l$. Mathematically this lets us break up the derivative via the chain rule. \n\\begin{align}\\label{eq:nn_weight_chain_rule}\n    \\frac{\\partial \\mathcal{E}}{\\partial w_{ij}^l} = \\frac{\\partial \\mathcal{E}}{\\partial a_i^l}\\frac{\\partial a_i^l}{\\partial w_{ij}^l}\n\\end{align}\nThe second term is easily computed using Equation \\ref{nn_activation} with\n\\begin{align}\n\t\\frac{\\partial a_{i}^l}{\\partial w_{ij}^l} = o_j^{l-1}\n\\end{align}\nThe first term is usually called the \\textbf{error}, defined as \n\\begin{align}\n\t\\delta_{i}^l \\equiv \\frac{\\partial \\mathcal{E}}{\\partial a_{i}^l}\n\\end{align}\nIn general this term can be complicated since there are potentially many perceptron layers through which the activation $a_i^l$ must pass through before it eventually affects the final output and therefore the error function $\\mathcal{E}$. One can most clearly arrive at an expression for $\\delta^l_i$ by first considering the output layer, layer $m$, for which the expression is given as\n\\begin{align}\\label{eq:error_out_lay}\n\t\\delta_{i}^m \\equiv \\frac{\\partial \\mathcal{E}}{\\partial a_{i}^m} &=  \\frac{\\partial \\mathcal{E}}{\\partial g^m} \\frac{\\partial g^m}{\\partial a_{i}^m}\n\\end{align}\nThe first term is typically trivially computed; for example if the error function is SSE, then\n\\begin{align}\\label{eq:error_out_lay_1}\n    \\frac{\\partial \\mathcal{E}}{\\partial g^m} = \\frac{\\partial }{\\partial g^m}\\sum_{p=0}^N (g^m - y_p)^2 = \\sum_{p=0}^N 2(g^m - y_p)\n\\end{align}\nWhere $p\\in(1,\\ldots,N)$ are the total number of data points you have. The second term of Equation \\ref{eq:error_out_lay} is just the derivative of the activation function.\n\\begin{align}\\label{eq:error_out_lay_2}\n    \\frac{\\partial g^m}{\\partial a_{i}^m} = g'^{~m}(a_{i}^m)\n\\end{align}\nThe activation function is typically chosen such that the derivative is either easily computed, or can be expressed in terms of the function itself (e.g. the logistic function). \n\nAt this stage, we are capable of expressing the gradient with respect to the weights of the last layer. We simply plug in our current weight values into Equations \\ref{eq:error_out_lay_1} and \\ref{eq:error_out_lay_2} and then \\ref{eq:nn_weight_chain_rule} we get a numerical expression for our gradient with respect to the weights. \n\n\n\nThe reason why this method is called \\textbf{backpropagation} is because the $\\delta_i^m$ term from the last layer is then propagated backwards through the network to adjust weights in the other neurons. Let us next look for the change in layer $m-1$\n\\begin{align}\n\t\\delta_j^{m-1} \\equiv \\frac{\\partial \\mathcal{E}}{\\partial a_{j}^{m-1}} &= \\frac{\\partial \\mathcal{E}}{\\partial a_{i}^{m}}\\frac{\\partial a_{i}^{m}}{\\partial a_{j}^{m-1}}\n\\end{align}\nHowever we already have an expression for the first term, $\\delta_i^m$! We also have the numerical value for this expression as well. This leaves us with only having to calculate the second term.\nWe can then recognize that the output of the previous layer is whatever its activation function spits out\n\\begin{align}\n\to_j^{l-1} &= g^{l-1}(a_j^{l-1})\n\\end{align}\nthis then tells us that the activation fed into the last layer can be expressed as a function of the previous layers activation\n\\begin{align}\n\ta_i^m = w_{ij}^m g^{m-1}(a_j^{m-1})\n\\end{align}\nAnd thus we have a recursive relation with\n\\begin{align}\n\t\\delta_j^{l-1} = \\delta_i^l w_{ij}^l g'^{~l-1}(a_j^{l-1})\n\\end{align}\nWhich gives us the gradient for an arbitrary hidden layer  after starting from the output layer\n\\begin{align}\n\t\\frac{\\partial \\mathcal{E}}{\\partial w_{ij}^l} = \\delta_j^{l}o_i^{l-1} = \\delta_n^{l+1} w_{nj}^{l+1} g'^{~l}(a_j^{l})o_j^{l-1}\n\\end{align}\nThe weights are then adjusted using gradient descent with\n\\begin{align}\n\t\\Delta w_{ij}^l = -\\alpha~  \\frac{\\partial \\mathcal{E}}{\\partial w_{ij}^l}\n\\end{align}\nThe issue with the chain rule being applied so many times is that one can run into a \\B{vanishing gradient}. Using ReLU activation functions is one method of fixing this. The problem of an  \\B{exploding gradient} can be solved by regularizing the loss function (e.g. hinge or LASSO).\n\n\\subsection{Convolutional Neural Networks}\n\nAs one continues to add more parameters to a fully connected feed forward network, each additional hidden layer increases the number of parameters by $(r_{l-1}+1)\\cdot r_l$. This can be seen picturing each neuron $r_l$ which has a weight for each connection to the previous layer $r_{l-1}$ and  plus an offset. Convolutional neural networks (CNN) reduce the number of parameters that you need by using convolutional windows which generalize patterns in the data. CNN were initially developed for image recognition but nowadays are also used in text processing. \n\nImagine you are looking for a feature in an image that is a sloping diagonal line. A \\textbf{filter} for that image may look like\n\\begin{align}\n    \\textbf{F} = \n\\begin{pmatrix}\n0 & 0 & 1 \\\\\n0 & 1 & 0 \\\\\n1 & 0 & 0\n\\end{pmatrix}\n\\end{align}\nThe filter itself is \\emph{learned} just as how weights are learned in a standard FFNN, with each matrix element being a parameter that is optimized for.\n\nLet us now imagine the photo we want to recognize, which is an matrix of integers corresponding to the color intensity. Lets imagine we have a grayscale image, which happens to be the size of our filter.\n\\begin{align}\n    \\textbf{I} = \n\\begin{pmatrix}\n0 & 2 & 5 \\\\\n9 & 7 & 0 \\\\\n1 & 2 & 9\n\\end{pmatrix}\n\\end{align}\nThe \\textbf{convolution} of the two is defined as\n\\begin{align}\n\\textbf{F} * \\textbf{I} = \n\\begin{pmatrix}\n0 & 0 & 1 \\\\\n0 & 1 & 0 \\\\\n1 & 0 & 0\n\\end{pmatrix}\n*\n    \\begin{pmatrix}\n0 & 2 & 5 \\\\\n9 & 7 & 0 \\\\\n1 & 2 & 9\n\\end{pmatrix}\n=     \n\\begin{pmatrix}\n0\\cdot 0 & 0\\cdot2 & 1\\cdot 5 \\\\\n0\\cdot 9 & 1\\cdot 7 & 0\\cdot 0 \\\\\n1\\cdot 1 & 0\\cdot 2 & 0 \\cdot 9\n\\end{pmatrix} = 13\n\\end{align}\nWe can recognize that the filter shrinks down the output that is fed into the next layer, we start here with a $3\\times 3$ image which is filtered by a $3\\times 3$ filter, leading to a single output. If we hitched another layer at the end of the filter layer, it would therefore have only \\emph{one} input, whereas in a standard FFNN, we would have the same as the input.\n\nOf course we often want to scan images for features smaller than their size. In this typical case the convolution is calculated using a scanning window, and is calculated everywhere it can fit. This operation results in a matrix smaller than the original input size. How to interact with the edge of the image is determined by \\textbf{padding} which places arrays of zeroes on the edges of the image such that the convolution can be calculated outside the body of the image. One can also set the \\textbf{stride} which determines how many pixels the filter skips over when moving to the next window.\n\nTo decrease the training time and the number of parameters needed in the model, \\textbf{pooling} is often used as an alternative to trainable filters. Generally the windows have either their $\\max$ or $\\textrm{average}$ calculated instead of a convolution with a filter. Both are pooling and convolution are often used together, with a pooling layer typically following a convolutional layer.\n\n\n\\subsection{Recurrent Neural Networks}\nRecurrent neural networks (RNNs) are used to label, classify, or generate sequences. They are typically used in text and speech processing. The distinguishing feature of a RNN is that they contain \\emph{loops}. Each perceptron has its own internal state it keeps track of which persists while data passes through it. Each perceptron itself has as input:\n\\begin{enumerate}\n    \\item A vector of states from the previous layer $l-1$\n    \\item A vector of states from the same layer $l$ at the previous time step\n\\end{enumerate}\nWhen looking at a sentence for example, this allows for the neural network to build context as to the words around it. In practice this typically leads to a vanishing gradient problem when using either $\\tanh$ or the softmax function, because the added time dependence further complicates the optimization, known as \\textbf{backpropagation through time}. Typical RNNs in practice are \\textbf{gated RNNs} including both  networks based on the \\textbf{gated recurrent unit} (GRU) and \\textbf{long short-term memory} (LSTM) networks.\n\n\\subsubsection{Gated Recurrent Units (GRU)}\nThe memory of a gated recurrent unit (GRU) is used to remember specific information about feature vectors seen early in the sequence. They were designed to remember which type of word goes with \\emph{their} when \\emph{she} was seen earlier in the sentence. \n\nThis is done using a \\textbf{gate} which takes the same inputs as the perceptron itself and outputs a number close to either $0$ or $1$, typically determined by the sigmoid function. If the gate outputs a value close to $0$, the state of the perceptron remains similar to what it was during the last time step, while if it is close to $1$, it is overwritten with a new state. In our example, a relevant gate could activate as $1$ upon reading the word \\emph{she} which would inform the network of the relevant gender for the rest of the sentence.\n\nThis architecture works well for neural networks because the derivative of the perceptrons state generally doesn't move very much over time; typically it is a constant since the gate doesn't often allow it to change. This solves the vanishing gradient problem and is the reason for the popularity of GRUs.\n\n\\subsubsection{Long-Short Term Memory (LSTM) Networks}\nTODO\n\n\\subsection{Activation Functions}\n% TODO Tanh, ReLU, Sigmoid, ...\nReLU fixes the problem of vanishing gradient\n\n\n\\subsection{Encoders and Decoders}\nTake two different sequences of data, for instance an English sentence composed of words $x_i$ with $i\\in (1,N)$ and its corresponding translation into French words $y_j$ with $j\\in(1,M)$.\n\nThe encoder transforms the input sequence of words $x_i$ into something called an \\textbf{embedding}, or context vector (e.g. One-Hot encoding).The context vector is then feed to the decoder, which uses it together with the previously generated symbol of the output sequence. This is shown in the diagram in Figure \\ref{fig:encoder-decoder}.\n\nTypically both the encoder and decoder are built using RNNs which can keep track of states. The full encoder-decoder machinery is typically trained at once using backpropagation.\n\n\\begin{figure}\n\\centerline{\\includegraphics[width=\\textwidth]{mathematics/fig/seq2seq1.pdf}}\n\\label{fig:encoder-decoder}\n\\caption{Simple encoder-decoder architecture. Input sequence ``hello world.\" creates an embedded hidden state. This hidden state is fed into the decoder which constructs its output iteratively starting with the initial embedding and iteratively building itself off of the previous eleent of the sequence. \\cite{zhang}}\n\\end{figure}\n\n\n\\subsubsection{One-Hot Encoding}\nOne way to convert categorical data into learnable features is by using one-hot encoding. This method converts each category into an index in an array. For instance if we have three categories (red, green, blue), we can represent these as\n\\begin{align}\n    \\textrm{red} &= [1,0,0]\\\\\n    \\textrm{green} &= [0,1,0]\\\\\n    \\textrm{blue} &= [0,0,1]\n\\end{align}\n\nThe location of each category can then be used as a feature which can be learned.\n\n\\subsubsection{Autoencoders}\n\nAutoencoders is a feed-forward neural network with an encoder-decoder architecture built to give an output identical to its input. This may seem trivial, but the idea is that the embedding layer has smaller dimensionality than the feature vector itself. This layer is called the \\textbf{bottleneck layer}.\n\n\\subsection{Attention}\n\nThe attention mechanism provides a state which the tells the decoder what specifically to pay attention to. This allows for better retention of long-term dependencies (i.e. keeping track of where pronouns go when translating between languages).\n\nFrom Wikipedia: ``In the context of neural networks, attention is a technique that mimics cognitive attention. The effect enhances the important parts of the input data and fades out the rest -- the thought being that the network should devote more computing power on that small but important part of the data. Which part of the data is more important than others depends on the context and is learned through training data by gradient descent.\"\n\nThis is currently an area of active research with much ongoing development in the field of computer science.\n\n\n\\subsection{Transformers}\nTODO\n\n\\url{https://jalammar.github.io/illustrated-transformer/}\\\\\n\\url{https://wiki.pathmind.com/attention-mechanism-memory-network}\nTransformers are Graph Neural Networks (fully connected graphs)\n\\url{https://www.youtube.com/watch?v=uF53xsT7mjc&t=10s}\n\n\\section{Dimensionality Reduction}\\label{dim_red}\nWhen fitting to a high dimensional space, the model can become overfit and/or the correlation within the feature vectors can be overlooked. In order to reduce the feature vectors into a space which has more discriminating power, it is helpful to reduce the total dimensions of the problem at hand.\n\\subsection{Principal Component Analysis (PCA)}\nPrincipal Component Analysis (PCA) turns our feature space into ``Principal Components\", eigenvectors of our individual features. The analysis finds the dimension in the data that contains the most variance, thereby having the most discriminating power between events.\n\nWe first begin with our feature vectors\n$$\\mathbf{X} = \\left.\\left( \n                  \\vphantom{\\begin{array}{c}1\\\\1\\\\1\\\\1\\\\1\\end{array}}\n                  \\smash{\\underbrace{\n                      \\begin{array}{ccccc}\n                             x_{00}&x_{10}&x_{20}&\\cdots &x_{p0}\\\\\n                             x_{01}&x_{11}&x_{21}&\\cdots &x_{p1}\\\\\n                             x_{02}&x_{12}&x_{22}&\\cdots &x_{p2}\\\\\n                             \\vdots&&&\\ddots&\\vdots\\\\\n                             x_{0n}&x_{1n}&x_{2n}&\\cdots &x_{pn}\n                      \\end{array}\n                      }_{p\\text{ features}}}\n              \\right)\\right\\}\n              \\,n\\text{ events}\n$$\\\\\n\nThe idea is to shrink the dimensionality, so change $p\\rightarrow l$ where $l$ is the desired dimensionality after PCA. \n\nWe first start by normalizing each feature $k=1,\\dots,p$ to have $\\mu=0$ (centers the data) and $\\sigma=1$ (accounts for different units).\n\n\\begin{align}\n\\mu_k = \\frac{1}{n}\\sum_{j=1}^n x_{kj} && \\sigma_k^2 = \\frac{1}{n-1}\\sum_{j=1}^n (x_{kj}-\\mu_k)^2 \\\\\n\\end{align}\nIt is worth noting the definition used by $\\texttt{scikitlearn}$ only normalizes the mean, but not the standard deviation of each feature. We then redefine each column $k$ in the matrix with\n\\begin{align}\n\t\\rho_{kj} = (x_{kj} - \\mu_k)/\\sigma_k\n\\end{align}\nThis gives us a new matrix\n$$\\mathbf{\\tilde{X}} =  \\left.\\left( \n                  \\vphantom{\\begin{array}{c}1\\\\1\\\\1\\\\1\\\\1\\end{array}}\n                  \\smash{\\underbrace{\n                      \\begin{array}{ccccc}\n                             \\rho_{00}&\\rho_{10}&\\rho_{20}&\\cdots &\\rho_{p0}\\\\\n                             \\rho_{01}&\\rho_{11}&\\rho_{21}&\\cdots &\\rho_{p1}\\\\\n                             \\rho_{02}&\\rho_{12}&\\rho_{22}&\\cdots &\\rho_{p2}\\\\\n                             \\vdots&&&\\ddots&\\\\\n                             \\rho_{0n}&\\rho_{1n}&\\rho_{2n}&\\cdots &\\rho_{pn}\n                      \\end{array}\n                      }_{p\\text{ features}}}\n              \\right)\\right\\}\n              \\,n\\text{ events}\n$$\\\\\n\nNow we look at the Covariance matrix (Section \\ref{covmat}) of each of our $p$ features, with\n\\begin{align}\n\\textbf{K}_{\\rho_i,\\rho_j} = \\begin{pmatrix} \n                             \\Cov[\\rho_0,\\rho_0]&\\Cov[\\rho_1,\\rho_0]&\\cdots &\\Cov[\\rho_p,\\rho_0]\\\\\n                             \\Cov[\\rho_0,\\rho_1]&\\Cov[\\rho_1,\\rho_1]&\\cdots &\\Cov[\\rho_p,\\rho_1]\\\\\n                             \\vdots&\\vdots&\\ddots&\\vdots\\\\\n                             \\Cov[\\rho_0,\\rho_p]&\\Cov[\\rho_1,\\rho_p]&\\cdots &\\Cov[\\rho_p,\\rho_p] \\end{pmatrix}\n\\end{align}\nThis matrix will be symmetric, with $1$ along the diagonal (since we scale each feature to have a variance of 1). The next step is to diagonalize this matrix following Section \\ref{diagonalize} and find it's eigenvalues $\\lambda_i$ and eigenvectors $\\textbf{a}_i = a_{ik}$. This puts the matrix into the form\n\n$$\\bf{K}' = \\left(\n{\\begin{array}{cccc}\n\\lambda_0 & 0 &...&0 \\\\\n0 & \\lambda_1 & ...&0\\\\\n\\vdots & \\vdots &\\ddots & \\vdots \\\\\n0 & 0 & ... &\\lambda_p\n\\end{array}}\n\\right)\n$$\n\nOne can recognize now that in our new coordinate system, we have a new set of variables which each have a variance represented by the eigenvalue $\\lambda_i$ itself. Because we want the most discriminating variable, we sort the eigenvectors and eigenvalues by the largest $\\lambda_i$, which corresponds to the largest variance. Our new feature space is therefore\n\\begin{align}\n\t\\rho_{ij} = a_{ik}\\rho_{kj}\n\\end{align}\nWith $i=1,\\dots,l$.\n\n\n\\section{Reinforcement Learning}\nReinforcement learning aims to try to maximize some numerical reward signal. The most important distinguishing feature is that it uses training information to evaluate actions taken rather than instruct which action to take \\cite{sutton}.\n\n\n\\subsection{$k$-armed Bandits}\nSlot machines are sometimes called \"one-armed bandits\" for the single lever they have together with their ability to steal money from peoples pockets. The idea behind $k$-armed bandits is to imagine instead of a single slot machine, you have $k$ of them. Each machine has a probability distribution of for hitting the \"jackpot\", and your job is to find out which one gives you the highest payoff.\n\nSearching for the highest value machine involves a trade-off between $exploiting$ the information you have now and $exploring$ the space to look for something better you haven't found yet.\n\nGreedy algorithms, in this case, use the lever which currently has the highest estimated chance of success. $\\epsilon$-greedy algorithms do the same thing, but one in $\\epsilon$ times, will select one of the levers at random instead to explore.\n\n\n\\subsubsection{Upper-Confidence-Bound Action Selection}\n\nOne can also use confidence bounds on the unknown probabilities to determine which lever to pull next. Because we don't want to miss out on a lever which could potentially be higher than the one we currently see is highest, we use the upper-confidence-bound when picking our current highest value estimate. To find the relevant confidence interval, we start with Hoeffding's Inequality (Section \\ref{hoeffding}), which eventually tells us\n\\begin{align}\n\tA_t = \\textrm{argmax}\\Big[Q_t(a) + c\\sqrt{\\frac{\\ln t}{N_t(a)}}\\Big]\n\\end{align}\nWhere $A_t$ is the next action taken at time $t$ (i.e. iterations through the algorithm). $Q_t(a)$ is the expected value of action $a$ at time $t$. $c$ is the confidence level. $N_t(a)$ is the amount of times $a$ has been tried.\n\nOverall, this tells us if an action $a$ is tried many times, $N_t(a)$ gets larger and the bound shrinks. Meanwhile, as time goes on, the bound itself grows to represent uncertainty in the system itself as to if it changes with time.\n\n\n\\subsection{Markov Decision Processes}\nMarkov Decision Processes (MDP) concerns using probability to optimize movement between \"states\". The framework proposes that the learning problem can be broken down into three signals that are passed back and forth: \n\\begin{enumerate}\n\t\\item Actions $A$\n\t\\item States $S$\n\t\\item Rewards $R$\n\\end{enumerate}\nAt present, how to represent states and actions is more of an art than a science \\cite{sutton}. Rewards however are simple single numbers.\n\n\n\\section{Modern Developments}\nThe machine learning field is quickly evolving with lots of terminology that is easy to forget. Here is a collection of terms and ideas on the forefront of the field.\n\n\n\\subsection{Metrics}\nDifferent metrics are used to gauge the performance of a machine learning model\n\nBLEU: bilingual evaluation understudy (used for evaluating language translation tasks).\n\n", "meta": {"hexsha": "c4d78cb03078020b8099bf757bcd391f57a33a30", "size": 58958, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mathematics/machineLearning.tex", "max_stars_repo_name": "williamnash/notes", "max_stars_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mathematics/machineLearning.tex", "max_issues_repo_name": "williamnash/notes", "max_issues_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-08-23T23:01:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-16T23:17:43.000Z", "max_forks_repo_path": "mathematics/machineLearning.tex", "max_forks_repo_name": "williamnash/notes", "max_forks_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.3636363636, "max_line_length": 598, "alphanum_fraction": 0.7316733946, "num_tokens": 16334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.8289388040954684, "lm_q1q2_score": 0.7379994359204541}}
{"text": "%!TEX root = ../CombinatoricsNotes.tex\n\n\\section{Set systems as an introduction to extremal combinatorial results}\\marginnote{The following is a brief introduction to some of the results we will see in the course. \n\nNote that the superscripted symbols $^\\dagger$, $^\\ddagger,$ and $^*$ are reserved to point towards notes in this margin. \n\nIn this introduction, full references will be included in the margin; afterwards, they will appear at the end of each section.}\n A \\emph{set system} is any $\\F\\subset \\P(X)$.\nLet $X$ be a finite set, and $\\P(X)$ the collection of all subsets of $X$.  Then $|\\P(X)|  = 2^{|X|}$. We'll denote $X^{(r)}$ as the collection of all $r$-element subsets of $X$.\n\\begin{example}\nIf $X = \\{1,2,3\\}$, then $\\P(X)=$ \n\\begin{center}\n \\begin{tikzcd}\nX^{(3)}  & &\\{1,2,3\\} \\\\\nX^{(2)} &\\{1,2\\} & \\{1,3\\} & \\{2,3\\} \\\\\nX^{(1)} & \\{1\\} & \\{2\\}&\\{3\\} \\\\\nX^{(0)} & & \\emptyset\n\\end{tikzcd}\n\\end{center}\n\\end{example}\n\n\n\\begin{definition}\n$\\F$ is an \\defn{intersecting set system} if $A\\cap B\\neq\\emptyset$ for all $A,B\\in \\F$.\n\\end{definition}\n\n\\subsection*{Largest intersecting set system}\nGiven $X$ with $|X| = n$, what is the maximum $|\\F|$ with $\\F\\subset \\P(X)$ intersecting? Let's start with $n=3$ (returning to our example). We can select at least 4: every set that contains 1\\marginnote{In this case, we could also choose $X^{(2)}\\cup X^{(3)}$, but that only works for $n$ odd.}. This method gives us $2^{n-1}= |\\P(X \\setminus\\{1\\})|$\\sidenote{since the number of subsets without 1 is in bijection with the number of subsets with 1. For a subset without 1, we add in 1, and get a new valid subset with 1. On the other hand, for a subset with 1, we take out 1 and get a valid subset without 1. These are clearly injective.}. Why can't we do better? We can subdivide $\\P(X)$ into pairs $\\{Y, X\\setminus Y\\}$. But $Y\\cap (X\\setminus Y) = \\emptyset$, so any intersecting $\\F$ contains at most one element of each pair. Thus, we can't do better than $2^{n-1}$.\n\n\\subsection*{Largest intersecting set system with fixed number of elements}\nHow large can $\\F$ intersecting be if $\\F\\subset X^{(r)}$ for some $r$? Our answer will depend on $r$ and $|X| = n$. Since $|X^{(r)}| = {n \\choose r}$, that is an upper bound. When can we achieve it, i.e. when is $X^{(r)}$ intersecting? When $r > n/2$. In this case, every subset has more than half of the elements of $X$, so no two subsets can be disjoint.\n\nIf $r = n/2$, then because of  complement pairing, the maximum is ${n \\choose r}/2$. By choosing $\\F$ as all of the sets that contain a particular element, we get ${n -1\\choose r-1}$. So for $r=n/2$, we have\n\\[\n {n-1\\choose r-1} \\leq \\max |\\F| \\leq \\frac{1}{2}{n\\choose r}.\n\\]\nBut for $r=n/2$, these two bounds are equal\\sidenote{Why? the LHS is the number of sets containing 1. But half of the sets contain 1 and half don't, by the complement argument.}.\nFor $r< n/2$, the answer is ${n -1 \\choose r-1}$; this is a lower bound by selecting all sets containing a given element.  That this is an upper bound is the content of the following non-trivial theorem.\n\\begin{theorem*}[\\erdos-Ko-Rado] \\marginnote{\\fullcite{erdos-ko-rado-1961}}\nLet $r\\leq n/2$. Let $\\F\\subset X^{(r)}$ with $|X| = n$ be intersecting. Then $|F| \\leq { n-1\\choose r-1}$.\n\\end{theorem*}\n\nNext, let's consider other types of set systems.\n\\subsection*{Littlewood-Offord problem}\nWe'll say $\\F$ is a \\defn{Sperner system} if $A\\subset B$ for $A,B\\in \\F$, then  $A=B$.\nGiven $X$, $|X|=n$, what is $\\max |\\F|$ such that $\\F\\subset \\P(X)$ is Sperner? Well, any $X^{(r)}$ is Sperner\\sidenote{If you take any element out, you reduce the number of elements, so aren't in $X^{(r)}$ anymore.}. So we can achieve ${n \\choose \\floor{n/2} }$. It turns out that one cannot do better. For $n=3$, we may make a graph by connecting subsets by edges. Then we need the largest independent set of this graph; it's easy to show in this case that this is ${n \\choose \\floor{n/2} }$. This is in fact the general result.\n\\begin{problem}[Littlewood-Offord 1938] \\marginnote{\\fullcite{LO1943}}\nSuppose we have non-zero numbers $a_1,a_2,\\ldots,a_n \\in \\C$. For $I\\subset \\{1,2,\\dotsc,n\\}$, consider $\\sum_{i\\in I} a_i$. There are then $2^n$ possible such sums. What is the maximal number of them that can be equal to be zero? \n\\end{problem}\nClearly we can shift to any number $z$ instead of zero without changing the answer.  \\erdos\\ solved this in 1945 for real numbers. Let's consider the case of positive numbers. \nFirst, if $a_1=\\dotsm = a_n=1$, then the maximum number of equal sums is ${n \\choose \\floor{n/2} }$. \nNow for general positive numbers, consider $\\F_z = \\{ I: \\sum_{i\\in I} a_i = z\\}$. Then $\\F_z$ is a Sperner system, so by the previously quoted result its maximum size is ${n \\choose \\floor{n/2} }$.\nThe Littlewood-Offord problem was treated in general in 1966 by Kleitman\\footfullcite{KLEITMAN1970}.\n\n\\subsection*{\\erdos-Szemer\\'edi conjcture}\n% \\begin{conjecture}[]\nLet $A\\subset \\Z_+$, $|A| = n$. Let $A+A = \\{ a+b: a,b\\in A\\}$. We wish to compare $|A+A|$ to $|A|$.\nNow, $\\max |A+A| = {n \\choose 2} + n = {n+1 \\choose 2}$ by choosing our elements so no two sums are the same unless they have to be\\sidenote{Intuitively then, we've achieved the maximum by a set with very little structure.}.\n\nWhat is $\\min|A+A|$?\nWe'll choose a set with a lot of structure: $A= \\{1,\\dotsc,n\\}$. Then $A+A = \\{2,3,\\dotsc,2n\\}$, and $|A+A| = 2n-1$. We'll prove that this is actually the minimum.\n% \\end{conjecture}\n\\begin{proof}  \nLet $a_1  < a_2  <\\dotsm < a_n$\\marginnote{The elements are distinct because $A$ is a set.}. Then\n\\[\n\\underbrace{a_1 + a_1 < a_1 + a_2 < \\dotsm < a_1 + a_n}_{n} < \\underbrace{a_2 + a_n < a_3 + a_n < \\dotsm < a_n + a_n}_{n-1}\n\\]\nso we found $2n-1$ different terms already.\n\\end{proof}\n\nWhat about $|A\\cdot A|$? Then $\\max |A\\cdot A| = {n\\choose 2} +n$, and $\\min |A\\cdot A| = 2n-1$. The second is by $A = \\{1,2,2^2,\\dotsm, 2^{n-1}\\}$. Generally we can transform additive problems into multiplicative by exponentiation, and back by the logarithm.\nNow, what's $\\min ( |A+A| + |A\\cdot A|)$? \n\\begin{conjecture*}[\\erdos-Szemer\\'edi] \\marginnote{\\fullcite{Erdos-Szemeredi-1983}}\n\\marginnote{This qualitatively means the additive and multiplicative structures do not get along; you reduce $|A+A|$ only at the cost of increasing $|A\\cdot A|$.}\n\\[\n|A+A| + |A\\cdot A| = \\Omega_\\epsilon (|A|^{2-\\epsilon})\n\\]\nThat is, for all $\\epsilon>0$, there exists $c>0$ such that for all $A\\subset \\Z_+ \\setminus \\{0\\}$,\n\\[\n|A + A| + |A\\cdot A| \\geq c_\\epsilon |A|^{2- \\epsilon}.\n\\]\n\\end{conjecture*}\nElekes showed that $|A +A| + |A\\cdot A| \\geq c |A|^{5/4}$ (\\cite{elekes1997number}) and Solymosi improved this to bound to  $|A|^{4/3 - \\epsilon}$~(\\cite{Solymosi2009}).\nIn fact, this is related to the following geometric problem (see \\cref{fig:IPLexample} for an example).\n\\begin{theorem*}[Szemer\\'edi-Trotter theorem] \\marginnote{\\fullcite{Szemeredi-Trotter1983}}\n\\begin{marginfigure}[2cm]\n\\includegraphics{L1f1.pdf}\n\\caption{An example of a collection $L$ of lines and $P$ of points. We are interested in the number of \\defn{incidences} $I(P,L)$ between points in $P$ and lines in $L$. Here, $I(P,L) = 5$.} \\label{fig:IPLexample}\n\\end{marginfigure}\nSuppose we have a collection $L$ of lines in the plane, and $P$ a collection of points in the plane. The set of incidences is $\\{(p,\\ell): p\\in P, \\ell\\in L, p\\in \\ell\\}$.   Let $I(P,L)$ denote the number of incidences for $P$ and $L$\\sidenote{Clearly, $I(P,L) \\leq |P| \\cdot |L|$, as a subset of $P\\times L$.}. Then\n\\[ \nI(P,L) \\leq O ( |P|^{2/3} |L|^{2/3} + |P| + |L| ).\n\\]\n\\end{theorem*}\nElekes used this theorem to make progress on the \\erdos-Szemer\\'edi conjecture by mapping the set $A$ to a collection of points and lines. He showed that if both $|A\\cdot A|$ and $|A+A|$ are small, then you find too many incidences.\nThe Szemer\\'edi-Trotter theorem uses the following result:\n\\begin{lemma*}[Crossing lemma]\nLet $G$ be a graph drawn in the plane with crossings. Suppose that $G$ has $m$ edges and $n$ verticies\\marginnote{If $m > 3n-6$, then there is at least one crossing, by the result stated at the beginning of the lecture, which comes from Euler's formula. In fact, this is how one proves the crossing lemma.}. If $m\\geq 4n$, then there are at least $\\frac{m^3}{64 n^2}$ crossings.\n\\end{lemma*}\nFrom $P$ and $L$, one makes a graph and applies the Crossing Lemma to prove Szemer\\'edi-Trotter.\n", "meta": {"hexsha": "b2a64068cf85680abec2ee49c6fe492450041790", "size": 8430, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/ch0_intro.tex", "max_stars_repo_name": "ericphanson/CombinatoricsNotes", "max_stars_repo_head_hexsha": "6b369a77b77cf6f0281b59f227aaa31e6903079c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-04-24T06:43:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-20T04:27:41.000Z", "max_issues_repo_path": "chapters/ch0_intro.tex", "max_issues_repo_name": "Marathe/CombinatoricsNotes", "max_issues_repo_head_hexsha": "6b369a77b77cf6f0281b59f227aaa31e6903079c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/ch0_intro.tex", "max_forks_repo_name": "Marathe/CombinatoricsNotes", "max_forks_repo_head_hexsha": "6b369a77b77cf6f0281b59f227aaa31e6903079c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-09-19T20:45:49.000Z", "max_forks_repo_forks_event_max_datetime": "2017-09-19T20:45:49.000Z", "avg_line_length": 83.4653465347, "max_line_length": 872, "alphanum_fraction": 0.6786476868, "num_tokens": 2887, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105941403651, "lm_q2_score": 0.9304582559762669, "lm_q1q2_score": 0.7379519710428564}}
{"text": "The grey value of each pixel in the detector can be modelled as a random variable, due to the random behaviour of photons being produced, interacting with the test sample and the scintillator in the detector. By modelling using a random variable, the uncertainty can be quantified and considered when conducting inference about any detected defects.\n\nThe compound Poisson distribution is studied here because of the compound Poission-like behaviour from the detection of photons \\citep{whiting2002signal, elbakri2003efficient, whiting2006properties}. It is defined by defining a latent variable $Y\\sim\\poisson(\\lambda)$ with probability mass function (p.m.f.) $\\prob(Y=y)=\\euler^{-\\lambda}\\frac{\\lambda^y}{y!}$ for $y=0,1,2,\\ldots$, where $\\lambda>0$ is the Poisson rate parameter. Let $U_i$ be some independent and identically distributed (i.i.d.) latent random variables with probability density function (p.d.f.) $p_U(u)$ for $i=1,2,3,\\ldots$. Let $X$ be a compound Poisson random variable where\n\\begin{equation}\n  X|Y = \\sum_{i=1}^{Y}U_i \\ .\n  \\label{eq:compoundPoisson_X|Y}\n\\end{equation}\nThe p.d.f.~of $X$ can be obtained by marginalising the joint p.d.f.\n\\begin{equation}\n  p_X(x)=\\sum_{y=0}^\\infty p_{X|Y}(x|y)\\prob(Y=y) \\quad\\text{for }x\\geqslant 0\n  \\ .\n\\end{equation}\nIt should be noted that $X=0$ if and only if $Y=0$ and this happens with probability $\\prob(Y=0)=\\euler^{-\\lambda}$. This implies that $X$ has probability mass at zero and probability density for positive numbers which results in the p.d.f.\n\\begin{equation}\n  p_X(x) =\n  \\begin{cases}\n    \\delta(x) \\euler^{-\\lambda}  & \\text{ for } x=0 \\\\\n    \\sum_{y=1}^\\infty p_{X|Y}(x|y)\\euler^{-\\lambda}\\frac{\\lambda^y}{y!} \\quad\\text{for } & \\text{ for } x>0\n  \\end{cases}\n\\end{equation}\nwhere $\\delta(x)$ is the Dirac delta function.\n\nThe compound Poisson distribution has applications in, for example, modelling rainfall \\citep{revfeim1984initial} and insurance claims \\citep{jorgensen1994fitting, smyth2002fitting}.\n\nThis chapter starts with a literature review on the compound Poisson distribution, how it is derived from the behaviour of photons, how its likelihood is evaluated and methods for fitting it onto data. A model was proposed for the grey values and the expectation-maximisation (EM) algorithm was implemented to fit the model onto data. It was found that for high photon rates, there were identifiability issues. The chapter is concluded on a discussion on why the EM algorithm failed.\n\n\\section{Literature Review}\n\n\\subsection{Compound Poisson in X-ray Detection}\n\nIn an x-ray tube, photons are emitted as a Poisson process \\citep{whiting2006properties, cierniak2011x} and each photon has some random energy due to bremsstrahlung and characteristic radiation \\citep{sun2012overview}. This is similar to the compound Poisson distribution. Let $Y$ be the number of photons emitted for some time exposure $\\tau$, then $Y\\sim\\poisson(\\lambda)$. Each photon is assumed to be i.i.d.~with random energy $U_i$ for $i=1,2,3,\\ldots$ with p.d.f.~$p_U(u)$. The random variables discussed here cover all the latent variables in the compound Poisson.\n\nPhotons emitted from the x-ray tube undergo attenuation when propagating through the test sample. Assuming no beam hardening, some photons are either absorbed or scattered, making them undetectable. Scattered photons may be detected but it is very rare \\citep{cantatore2011introduction}. The energy of the attenuated photons remain unaffected so attenuation decreases the parameter $\\lambda$. The amount it decreases by depends on the attenuation coefficient of the material and the amount of material the x-ray attenuates. The density of the random variable $U_i$ remains unchanged because the energy of each photon remains the same after attenuation, assuming no beam hardening.\n\nWhen the photons interact with the scintillator in the detector, they are converted into visible light. The visible light photons are then detected and converted into a digital signal or grey value. A quantum counter set the digital signal to be linear with the number of photons detected \\citep{whiting2006properties}. Let $X$ be the grey value observed, then\n\\begin{equation}\nX = bY + \\epsilon\n\\end{equation}\nwhere $\\epsilon\\sim\\normal(a,\\kappa)$, $b$ and $a$ are some constant and $\\kappa$ is the variance of electronic noise. The mean and variance of the grey value are\n\\begin{equation}\n\\expectation\\left[X\\right] = b\\lambda + a\n\\end{equation}\nand\n\\begin{equation}\n\\variance\\left[X\\right] = b^2\\lambda + \\kappa\n\\end{equation}\nrespectively. By eliminating $\\lambda$\n\\begin{equation}\n\\variance\\left[X\\right] = b\\expectation\\left[X\\right]+\\kappa-ab \\ ,\n\\end{equation}\na linear relationship between the variance and expectation of the grey value \\citep{ma2012varaince} is obtained.\n\nIn an energy integrating detector, the recorded grey value is linear to the energy detected \\citep{whiting2006properties}. The grey value $X$ is\n\\begin{equation}\nX|Y = \\sum_{i=1}^Y U_i + \\epsilon \\ .\n\\end{equation}\nThis is the compound Poisson distribution with Normal noise added to it. The scale factor $b$ is not included as this can be absorbed into $U$. Using the result that $\\expectation\\left[X\\right]=\\expectation\\expectation\\left[X|Y\\right]$ and $\\variance\\left[X\\right] = \\variance\\expectation\\left[X|Y\\right] + \\expectation\\variance\\left[X|Y\\right]$, the mean and variance of the grey value are\n\\begin{equation}\n\\expectation\\left[X\\right] = \\lambda\\expectation\\left[U\\right]+a\n\\end{equation}\nand\n\\begin{equation}\n\\variance\\left[X\\right] = \\lambda \\expectation\\left[U^2\\right]+\\kappa\n\\end{equation}\nrespectively. Eliminating $\\lambda$ obtains\n\\begin{equation}\n\\variance\\left[X\\right] = \\dfrac{\\expectation\\left[U^2\\right]}{\\expectation\\left[U\\right]} \\expectation\\left[X\\right] + \\kappa - a\\dfrac{\\expectation\\left[U^2\\right]}{\\expectation\\left[U\\right]} \\ .\n\\end{equation}\nBy assuming no beam hardening, $\\expectation\\left[U\\right]$ and $\\expectation\\left[U^2\\right]$ remains constant, thus there is a linear relationship between the variance and expectation of the grey value \\citep{yang2009evaluation}. There are other types of detection schemes \\citep{whiting2006properties} but it shall not be considered here.\n\nExperiments have been done to verify the compound Poisson nature of the detector. This was done by investigating the variance of radiographs of air \\citep{hsieh2015compound} and a polyethene cylinder \\citep{yang2009evaluation, yang2010noise} using different exposures. It was found there were two components in the noise, one was signal-dependent and comes from the compound Poisson distribution, the other was signal independent and maybe electronic noise. The electronic noise can be modelled using a Normal distribution \\citep{xu2009electronic}.\n\n\\subsection{Moment Generating Function}\n\nReturning to the compound Poisson distribution with no electronic noise $X|Y = \\sum_{i=1}^{Y}U_i$, let the moment generating function (m.g.f.)~of $X$ be $M_X(\\theta)=\\expectation\\left[\\euler^{X\\theta}\\right]$. It can be shown that the m.g.f.~is\n\\begin{equation}\n  M_X(\\theta)=\n  \\exp\\left[\n    \\lambda\n    \\left(\n      M_U(\\theta)-1\n    \\right)\n  \\right]\n\\end{equation}\n\\citep{gatto2010saddlepoint}. The derivation is shown in Appendix \\ref{chapter:appendix_compoundPoissonMgf}. Moments of $X$ can be obtained from the m.g.f.~by differentiating it and setting $\\theta$ to zero. In other words, $\\expectation[X^r]=M_X^{(r)}(0)$. Then it can be shown that\n\\begin{align}\n  \\expectation\\left[X\\right]&=\\lambda\\expectation\\left[U\\right]\n  \\\\\n  \\variance\\left[X\\right] &= \\lambda\\expectation\\left[U^2\\right]\n  \\\\\n  \\expectation\\left[(X-\\expectation[X])^3\\right] &=\\lambda\\expectation\\left[U^3\\right]\n\\end{align}\nwhich agrees with the expectation and variance results in the previous section. The derivation is shown in Appendix \\ref{chapter:appendix_compoundPoissonMgf}.\n\n\\subsection{Compound Poisson-Gamma Distribution}\n\\label{chapter:compoundPoisson_compoundPoissonGamma}\nA special case of the compound Poisson distribution is when $U\\sim\\gammaDist\\left(\\alpha,\\beta\\right)$ where $\\alpha>0$ is the gamma shape parameter and $\\beta>0$ is the gamma rate parameter. This was used for example in \\cite{xu2009electronic}. The distribution is known as the compound Poisson-gamma distribution and is denoted by $X\\sim\\CPoisson(\\lambda,\\alpha,\\beta)$. The p.d.f.~is\n\\begin{equation}\n  p_X(x) =\n  \\begin{cases}\n    \\delta(x) \\euler^{-\\lambda} & \\text{ for } x=0 \\\\\n    \\displaystyle\\sum_{y=1}^{\\infty}\\dfrac{\\beta^{y\\alpha}}{\\Gamma(y\\alpha)}x^{y\\alpha-1}\\euler^{-\\beta x}\\euler^{-\\lambda}\\frac{\\lambda^y}{y!} & \\text{ for } x>0\n  \\end{cases}\n  \\ .\n  \\label{eq:compoundPoisson_pdf}\n\\end{equation}\nRecall that $X|Y=\\sum_{i=1}^YU_i$ which involves a sum of gamma random variables. It can be shown that\n\\begin{equation}\n  X|Y\\sim\\gammaDist\\left(Y\\alpha,\\beta\\right).\n\\end{equation}\n\nThe m.g.f.~of $U$ is $M_U(\\theta) = \\left(\\dfrac{\\beta}{\\beta-\\theta}\\right)^\\alpha$, then the m.g.f.~of $X$ is\n\\begin{equation}\n  M_X(\\theta)=\\exp\\left[\\lambda\\left(\\left(\\frac{\\beta}{\\beta-\\theta}\\right)^{\\alpha}-1\\right)\\right]\n\\end{equation}\nand moments can be obtained from it such as\n\\begin{equation}\n  \\expectation\\left[X\\right]=\\frac{\\alpha\\lambda}{\\beta}\n\\end{equation}\n\\begin{equation}\n  \\variance\\left[X\\right]=\\frac{\\alpha(\\alpha+1)\\lambda}{\\beta^2}\n  \\label{eq:compoundPoisson_variance}\n\\end{equation}\nand\n\\begin{equation}\n  \\expectation\\left[(X-\\expectation[X])^3\\right] = \\frac{\\alpha(\\alpha+1)(\\alpha+2)\\lambda}{\\beta^3}\n  \\ .\n\\end{equation}\n\n\\subsection{Generalised Linear Model}\n\nIt can be shown that the compound Poisson-gamma distribution is in the exponential family for fixed $\\alpha$ \\citep{jorgensen1987exponential}. To show this, the compound Poisson-gamma distribution was parametrised using the following:\n\\begin{equation}\n  p=\\frac{2+\\alpha}{1+\\alpha}\n  \\ ,\n\\end{equation}\n\\begin{equation}\n  \\mu=\\frac{\\lambda\\alpha}{\\beta}\n  \\ ,\n\\end{equation}\n\\begin{equation}\n  \\phi = \\frac{\\alpha+1}{\\beta^{2-p}(\\lambda\\alpha)^{p-1}}\n  \\ .\n\\end{equation}\nThe parameters $p$, $\\mu$ and $\\phi$ are called the index, mean and dispersion parameters respectively and take the values of $1<p<2$, $\\mu>0$ and $\\phi>0$. It can be shown that the p.m.f.~at zero is\n\\begin{equation}\n  \\prob(X=0) = \\exp\n  \\left[\n      -\\frac{\\mu^{2-p}}{\\phi(2-p)}\n  \\right]\n\\end{equation}\nand the p.d.f.~for $x>0$ is\n\\begin{equation}\n  p_X(x) =\n  \\exp\\left[\n    \\frac{1}{\\phi}\n    \\left(\n      x\\frac{\\mu^{1-p}}{1-p}-\\frac{\\mu^{2-p}}{2-p}\n    \\right)\n  \\right]\n  \\frac{1}{x}\n  \\sum_{y=1}^{\\infty}W_y(x,p,\\phi)\n\\end{equation}\nwhere\n\\begin{equation}\n  W_y = W_y(x,p,\\phi)=\\frac{x^{y\\alpha}}{\\phi^{y(1+\\alpha)}(p-1)^{y\\alpha}(2-p)^yy!\\Gamma(y\\alpha)}\n  \\ .\n\\end{equation}\nThe derivation is shown in Appendix \\ref{chapter:appendix_tweedie}. This is in the form of a distribution in the dispersive exponential family \\citep{nelder1972generalized, nelder1972generalized_2, mccullagh1984generalized} for fixed $p$.\n\nParameter estimation for known $p$ can be done via the generalised linear model framework and can be extended to include linear mixed models \\citep{zhang2013likelihood}. Estimating $p$ is difficult and various methods were discussed \\citep{zhang2013likelihood}. One way is to estimate $\\mu$ and $\\phi$ on a grid of $p$'s and then select the $p$ which maximises the likelihood \\citep{dunn2005series}.\n\nOne special property of the compound Poisson-gamma distribution is that it is in the Tweedie dispersion exponential family \\citep{jorgensen1987exponential}. It can be shown that it has a special variance-mean relationship\n\\begin{equation}\n  \\variance[X] = \\phi \\mu^p\n\\end{equation}\nwhere $1<p<2$. This is derived in Appendix \\ref{chapter:appendix_tweedie}. It should be noted that this relationship is for fixed $p$ and $\\phi$. This is different from the linear variance-mean relationship found at the start of the chapter which was for fixed $\\alpha$ and $\\beta$ from assuming no beam hardening.\n\n\\subsection{Method of Moments}\n\nThe method of moments is a simpler method to estimate the parameters of a compound Poisson-gamma distribution. Suppose $\\widehat{\\mu}_1$ is an estimator of $\\expectation[X]$ and $\\widehat{\\mu}_j$ is an estimator of $\\expectation\\left[\\left(X-\\expectation[X]\\right)^j\\right]$ for $j=2,3$, then the estimators\n\\begin{equation}\n  \\widehat{\\lambda}=\\frac{\\widehat{\\mu}_1^2\\widehat{\\mu}_2}{2\\widehat{\\mu}_2^2-\\widehat{\\mu}_1\\widehat{\\mu}_3}\n\\end{equation}\n\\begin{equation}\n  \\widehat{\\alpha}=\\frac{2\\widehat{\\mu}_2^2-\\widehat{\\mu}_1\\widehat{\\mu}_3}{\\widehat{\\mu}_1\\widehat{\\mu}_3-\\widehat{\\mu}_2^2}\n\\end{equation}\n\\begin{equation}\n  \\widehat{\\beta}=\\frac{\\widehat{\\mu}_1\\widehat{\\mu}_2}{\\widehat{\\mu}_1\\widehat{\\mu}_3-\\widehat{\\mu}_2^2}\n\\end{equation}\nare method of moments estimators of $\\lambda$, $\\alpha$ and $\\beta$ respectively \\citep{withers2011compound}, this is shown in Appendix \\ref{chapter:appendix_methodofmoments}. These estimators suffer because estimation is not done through the sufficient statistics and can be negative. This is a problem because the parameters do not take non-positive values.\n\n\\subsection{Normal Approximation}\n\nThe evaluation of the p.d.f.~of a compound Poisson-gamma distribution is useful so that the likelihood can be obtained. The likelihood can be used to find, for example, maximum likelihood estimators. A problem occurs when dealing with the infinite sum in the p.d.f.~because it cannot be simplified. There are several approximations or computational methods to evaluate the p.d.f.~such as Fourier inverting the characteristic function \\citep{dunn2008evaluation}, using the saddlepoint approximation \\citep{daniels1954saddlepoint} or cleverly sum over certain terms in the infinite sum \\citep{dunn2005series}. Monte Carlo methods can be used to evaluate the p.d.f.~by simulating compound Poisson-gamma random variables.\n\nThe m.g.f.~provides a starting point to what limiting distributions the compound Poisson-gamma distribution converges to for large parameters. These limiting distributions can be used to approximate the p.d.f.~of the compound Poisson-gamma distribution.\n\nIt can be shown for large $\\lambda$, the Normal approximation \\citep{shevtsova2014on} is\n\\begin{equation}\n  X\\sim\\normal\\left(\\frac{\\lambda\\alpha}{\\beta},\\frac{\\lambda\\alpha(\\alpha+1)}{\\beta^2}\\right) \\ .\n\\end{equation}\nThe solution is shown in Appendix \\ref{chapter:appendix_normalApproximation}.\n\n\\subsection{Saddlepoint Approximation}\n\nThe saddlepoint approximation \\citep{daniels1954saddlepoint} uses the approximate solution to inverting the Laplace transformation or the m.g.f. This has been used in XCT \\citep{elbakri2003statistical, elbakri2003efficient}. Inverting the Fourier transformation of the characteristic function also gives the p.d.f.~using computational methods \\citep{dunn2008evaluation}. The saddlepoint approximation will be studied here.\n\nFor a given m.g.f.~$M_X(\\theta)$, the saddlepoint approximation \\citep{daniels1954saddlepoint, butler2007saddlepoint} finds an approximate p.d.f.~$p_X(x)$. The saddlepoint approximation is given as\n\\begin{equation}\n  p_X(x)\\approx\\left(2\\pi K_X''(s)\\right)^{-1/2}\\exp\\left[K_X(s)-sx\\right]\n  \\label{eq:saddlePoint:generalSaddlePoint}\n\\end{equation}\nwhere $K_X(\\theta) = \\ln\\left(M_X(\\theta)\\right)$ and $s=s(x)$ is the solution to the saddle point equation $K_X'(s)=x$.\n\nFor the compound Poisson-gamma distribution, the saddle point approximation \\citep{jensen1991saddlepoint} is given as\n\\begin{multline}\n  p_X(x)\\approx\n  \\frac{\\left(\\lambda\\alpha\\beta^\\alpha\\right)^{\\frac{1}{2(\\alpha+1)}}\\euler^{-\\lambda}}{\\sqrt{2\\pi(\\alpha+1)}}x^{-\\frac{\\alpha+2}{2(\\alpha+1)}}\n  \\euler^{-x\\beta}\n  \\exp\\left[x^{\\frac{\\alpha}{\\alpha+1}}\n    \\frac{(\\lambda\\beta^\\alpha)^{\\frac{1}{\\alpha+1}}(\\alpha+1)}{\\alpha^{\\frac{\\alpha}{\\alpha+1}}}\n  \\right]\n  \\\\\n  \\text{for }x>0\n  \\label{eq:saddle_point_approx}\n\\end{multline}\nwith the derivation shown in Appendix \\ref{chapter:appendix_saddlepoint}. The approximation is not well defined for $x=0$.\n\nThe integral of the density approximation over the support may not equal to one and it can be numerically re-normalised if necessary. Thus, it may be more sensible to write the approximation up to a constant\n\\begin{equation}\n  p_X(x)\\propto x^{-\\frac{\\alpha+2}{2(\\alpha+1)}}\\euler^{-x\\beta}\n  \\exp\\left[\n    x^{\\frac{\\alpha}{\\alpha+1}}\n    \\frac{\n      (\\lambda\\beta^\\alpha)^{\\frac{1}{\\alpha+1}}(\\alpha+1)\n    }\n    {\n      \\alpha^{\\frac{\\alpha}{\\alpha+1}}\n    }\n  \\right]\n  \\ .\n\\end{equation}\n\n\\subsection{Series Evaluation}\n\nThe infinite sum, $\\sum_{y=1}^\\infty W_y$, can be computationally summed cleverly to evaluate the p.d.f. This was done by summing only large terms in the sum and ignoring small terms \\citep{dunn2005series}. \\cite{dunn2005series} approximated the sum by truncation\n\\begin{equation}\n  \\sum_{y=1}^\\infty W_y \\approx \\sum_{y=y_\\text{l}}^{y_\\text{u}}W_y\n\\end{equation}\nwhere $y_\\text{l}<y_{\\text{max}}<y_\\text{u}$ and $y_{\\text{max}}$ is the value of $y$ which maximises $W_y$. \\cite{dunn2005series} used Stirling's approximation to find that\n\\begin{equation}\n  y_{\\text{max}} \\approx \\frac{x^{2-p}}{\\phi(2-p)}\n\\end{equation}\nby treating $W_y$ as a continuous and differentiable function of $y$. The derivation is shown in Appendix \\ref{chapter:appendix_compoundPoissonSeries}. Because values of $y$ are positive integers, it would be appropriate to round $y_\\text{max}$ accordingly\n\\begin{equation}\n  y_{\\text{max}} = \\text{max}\\left[\n    1,\\text{round}\\left(\\frac{x^{2-p}}{\\phi(2-p)}\\right)\n  \\right]\n  \\ .\n\\end{equation}\n\nThe limits, $y_\\text{l}$ and $y_\\text{u}$, can be chosen such that $W_{y_\\text{l}}$ and $W_{y_\\text{u}}$ are less than $\\epsilon W_{y_\\text{max}}$ where $\\epsilon$ is some small constant, for example, $\\epsilon=\\euler^{-37}$ will be better than machine precision in 64 bits \\citep{dunn2005series}. To prevent overflow problems, it is advised to calculate each term in the summation in log scale \\citep{dunn2005series} by using the equation\n\\begin{equation}\n  \\ln\\left[\n    \\sum_{y=y_\\text{l}}^{y_\\text{u}}W_y\n  \\right]\n  =\n  \\ln\\left(\n    W_{y_\\text{max}}\n  \\right)\n  +\\ln\\sum_{y=y_\\text{l}}^{y_\\text{u}}\n  \\exp\\left[\n    \\ln\\left(W_y\\right)-\\ln\\left(W_{y_\\text{max}}\\right)\n  \\right]\n  \\ .\n\\end{equation}\n\n\\section{Simulation Studies on Density Evaluation}\n\nSimulations of a compound Poisson-gamma random variable were conducted to compare how well these density evaluation methods performed. This was done by comparing the evaluated densities using the histogram of simulations and a Q-Q plot. The following compound Poisson-gamma distributions were used in the simulations to capture the variety in the compound Poisson-gamma family: $\\CPoisson(1,1,1)$, $\\CPoisson(1,100,1)$, $\\CPoisson(10,1,1)$, $\\CPoisson(100,100,1)$. For each of these distribution, 1\\,000 random variables were simulated. Varying $\\beta$ is not interesting as this only scales the random variable.\n\nThere were a few technical problems with the histogram because the compound Poisson has probability mass at zero and probability density for positive numbers. To correctly represent the empirical density of a compound Poisson random variable, a bar chart was used to show the frequency of zeros and a histogram to show the frequency density of positive numbers. However, the Normal approximation and the saddlepoint approximation does not have mass support at zero. Therefore, to compare these approximate densities to the empirical distribution fairly, a histogram containing both zero and positive samples was used when appropriate.\n\nThe evaluation of the p.d.f.~using the saddlepoint approximate required a bit of caution to avoid over/underflow problems. Suppose realisations of $X$ were simulated $\\left\\{x_1,x_2,x_3,\\ldots,x_n\\right\\}$. The saddlepoint approximation was computed up to a constant using\n\\begin{equation}\n  p_X(x) \\propto\n  \\exp\\left[\n    -\\frac{\\alpha+2}{2(\\alpha+1)}\n    \\ln(x)\n    -x\\beta\n    +\\left(\n    \\frac{x\\beta}{\\alpha}\n    \\right)^{\\frac{\\alpha}{\\alpha+1}}\\lambda^{\\frac{1}{\\alpha+1}}(\\alpha+1) - k\n  \\right]\n\\end{equation}\nfor 10\\,000 equally spaced points from and including the minimum non-zero simulated value to the maximum simulated value. $k$ is some constant which was chosen to be\n\\begin{equation}\n  k =\n  \\max_{i\\in\\left\\{1,2,3,\\ldots,n\\right\\}}\n  \\left[\n    -\\frac{\\alpha+2}{2(\\alpha+1)}\n    \\ln(x_i)\n    -x_i\\beta\n    +\\left(\n      \\frac{x_i\\beta}{\\alpha}\n    \\right)^{\\frac{\\alpha}{\\alpha+1}}\\lambda^{\\frac{1}{\\alpha+1}}(\\alpha+1)\n  \\right]\n  \\ .\n\\end{equation}\nThe density was then normalised by numerically integrating it using the trapezium rule using the 10\\,000 evaluated points.\n\nA Q-Q plot is a plot which compares the empirical quantiles with the theoretical quantiles. Let\n\\begin{equation}\n  F_X(x) = \\prob(X\\leqslant x)\n\\end{equation}\nand\n\\begin{equation}\n  \\widehat{F}_X(x) = \\frac{1}{n}\\cdot\\text{max}\n  \\left[\n    \\left(\\sum_{i=1}^n\\mathbb{I}(x_i\\leqslant x)\\right)-0.5,0\n  \\right]\n  \\ ,\n\\end{equation}\nthen a Q-Q plot is a parametric plot which plots $\\widehat{F}_X^{-1}(p)$ against $F_X^{-1}(p)$ for $p=\\frac{0.5}{n},\\frac{1.5}{n},\\frac{2.5}{n},\\ldots,\\frac{n-0.5}{n}$. If $F_X(x)$ and $\\widehat{F}_X(x)$ are similar, a Q-Q plot should be a straight line with gradient 1, intercepting the origin. For the exact method and the saddlepoint approximation, $F_X(x)$ was found numerically by evaluating the p.d.f.~at $10\\,000$ equally spaced points from and including the minimum to the maximum of the simulated samples, and then summing the required trapeziums. For the saddlepoint approximation, it does not support zero, thus the numerical integration started at a non-zero value. $\\widehat{F}_X^{-1}(p)$ was then calculated by interpolation.\n\nWhen plotting the probability of obtaining a zero or the p.d.f.~for positive values, confidence intervals were plotted as well. Consider a bin in a histogram, the confidence intervals were obtained by assuming that the frequency in a bin $\\sim\\poisson(\\text{p.d.f.~evaluated at the bin}\\times 1\\,000 \\times \\text{bin width})$. The 68\\% confidence interval was chosen because this is a typical choice in physics \\citep{cowan1998statistical}.\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\mainSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_CompoundPoissonlambda1alpha1beta1.eps}\n        \\caption{Left: Observed and expected frequency of a zero. Right: Histogram and p.d.f.~of non-zero values.}\n    \\end{subfigure}\n    }\n    \\vspace{2em}\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_qq_CompoundPoissonlambda1alpha1beta1.eps}\n        \\caption{Q-Q plot}\n    \\end{subfigure}\n    }\n    \\caption{1\\,000 $\\CPoisson(1,1,1)$ random variables were simulated and its empirical density is compared to the p.d.f.~evaluated using the exact method. In a), the dotted red line shows the 68\\% confidence interval of the expected frequency or frequency density.}\n    \\label{fig:compoundPoisson_histogram_1_1_1}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\mainSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_CompoundPoissonlambda1alpha100beta1.eps}\n        \\caption{Left: Observed and expected frequency of a zero. Right: Histogram and p.d.f.~of non-zero values.}\n    \\end{subfigure}\n    }\n    \\vspace{2em}\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_qq_CompoundPoissonlambda1alpha100beta1.eps}\n        \\caption{Q-Q plot}\n    \\end{subfigure}\n    }\n    \\caption{1\\,000 $\\CPoisson(1,100,1)$ random variables were simulated and its empirical density is compared to the p.d.f.~evaluated using the exact method. In a), the dotted red line shows the 68\\% confidence interval of the expected frequency or frequency density.}\n    \\label{fig:compoundPoisson_histogram_1_100_1}\n\\end{figure}\n\n\\begin{figure}[t]\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_CompoundPoissonNormlambda1alpha1beta1.eps}\n        \\caption{Histogram - Normal approx.}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_qq_CompoundPoissonNormlambda1alpha1beta1.eps}\n        \\caption{Q-Q plot - Normal approx.}\n    \\end{subfigure}\n    }\n    \\vspace{1em}\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_CompoundPoissonSaddlelambda1alpha1beta1.eps}\n        \\caption{Histogram - Saddlepoint approx.}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_qq_CompoundPoissonSaddlelambda1alpha1beta1.eps}\n        \\caption{Q-Q plot - Saddlepoint approx.}\n    \\end{subfigure}\n    }\n    \\caption{1\\,000 $\\CPoisson(1,1,1)$ random variables were simulated and its empirical density is compared to the approximate p.d.f. On the left, the dotted red line shows the 68\\% confidence interval of the expected frequency density.}\n    \\label{fig:compoundPoisson_histogram_approx_1_1_1}\n\\end{figure}\n\n\\begin{figure}[t]\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_CompoundPoissonNormlambda1alpha100beta1.eps}\n        \\caption{Histogram - Normal approx.}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_qq_CompoundPoissonNormlambda1alpha100beta1.eps}\n        \\caption{Q-Q plot - Normal approx.}\n    \\end{subfigure}\n    }\n    \\vspace{1em}\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_CompoundPoissonSaddlelambda1alpha100beta1.eps}\n        \\caption{Histogram - Saddlepoint approx.}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_qq_CompoundPoissonSaddlelambda1alpha100beta1.eps}\n        \\caption{Q-Q plot - Saddlepoint approx.}\n    \\end{subfigure}\n    }\n    \\caption{1\\,000 $\\CPoisson(1,100,1)$ random variables were simulated and its empirical density is compared to the approximate p.d.f. On the left, the dotted red line shows the 68\\% confidence interval of the expected frequency density.}\n    \\label{fig:compoundPoisson_histogram_approx_1_100_1}\n\\end{figure}\n\n\nFor low $\\lambda$ (Figures \\ref{fig:compoundPoisson_histogram_1_1_1} to \\ref{fig:compoundPoisson_histogram_approx_1_100_1}) there was a chance of simulating zeros. The exact method has an advantage here because it can evaluate probability mass at zero. The Normal approximation failed to capture the probability mass at zero because the Normal distribution is symmetric and supports negative values. The saddlepoint approximation improves on the Normal approximation by capturing the skewness and kurtosis of the distribution \\citep{bedrick1992empirical, butler2007saddlepoint}. As a result, it captured the probability mass at zero as shown by an increase in probability density towards zero.\n\nFor $\\CPoisson(1,100,1)$, the compound Poisson-gamma p.d.f.~contained multiple peaks. Figure \\ref{fig:compoundPoisson_histogram_approx_1_100_1} shows that the saddlepoint approximation was not flexible enough to capture them. In Figure \\ref{fig:compoundPoisson_histogram_1_100_1}, the Q-Q plot for the exact method was quite sensitive at the tails of each peak, perhaps there were a few inaccuracies in the exact evaluation of the p.d.f.~or in the calculation of the numerical calculation of the c.d.f.~and its inversion.\n\nAs $\\lambda$ increased (Figures \\ref{fig:compoundPoisson_histogram_10_1_1} and \\ref{fig:compoundPoisson_histogram_100_1_1}), all 3 density evaluation methods performed quite well. For $\\CPoisson(10,1,1)$ in Figure \\ref{fig:compoundPoisson_histogram_10_1_1}, the Normal approximation did not capture the skewness. In Figure \\ref{fig:compoundPoisson_histogram_100_1_1}, $\\lambda$ was high enough where the compound-Poisson distribution started to converge to a Normal distribution. All methods performed well in this realm.\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_CompoundPoissonlambda10alpha1beta1.eps}\n        \\caption{Histogram - Exact method}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_qq_CompoundPoissonlambda10alpha1beta1.eps}\n        \\caption{Q-Q plot - Exact method}\n    \\end{subfigure}\n    }\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_CompoundPoissonNormlambda10alpha1beta1.eps}\n        \\caption{Histogram - Normal approx.}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_qq_CompoundPoissonNormlambda10alpha1beta1.eps}\n        \\caption{Q-Q plot - Normal approx.}\n    \\end{subfigure}\n    }\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_CompoundPoissonSaddlelambda10alpha1beta1.eps}\n        \\caption{Histogram - Saddlepoint approx.}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_qq_CompoundPoissonSaddlelambda10alpha1beta1.eps}\n        \\caption{Q-Q plot - Saddlepoint approx.}\n    \\end{subfigure}\n    }\n    \\caption{1\\,000 $\\CPoisson(10,1,1)$ random variables were simulated and its empirical density is compared to the p.d.f. On the left, the dotted red line shows the 68\\% confidence interval of the expected frequency density.}\n    \\label{fig:compoundPoisson_histogram_10_1_1}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_CompoundPoissonlambda100alpha100beta1.eps}\n        \\caption{Histogram - Exact method}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_qq_CompoundPoissonlambda100alpha100beta1.eps}\n        \\caption{Q-Q plot - Exact method}\n    \\end{subfigure}\n    }\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_CompoundPoissonNormlambda100alpha100beta1.eps}\n        \\caption{Histogram - Normal approx.}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_qq_CompoundPoissonNormlambda100alpha100beta1.eps}\n        \\caption{Q-Q plot - Normal approx.}\n    \\end{subfigure}\n    }\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_CompoundPoissonSaddlelambda100alpha100beta1.eps}\n        \\caption{Histogram - Saddlepoint approx.}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpHistogram_qq_CompoundPoissonSaddlelambda100alpha100beta1.eps}\n        \\caption{Q-Q plot - Saddlepoint approx.}\n    \\end{subfigure}\n    }\n    \\caption{1\\,000 $\\CPoisson(100,100,1)$ random variables were simulated and its empirical density is compared to the p.d.f. On the left, the dotted red line shows the 68\\% confidence interval of the expected frequency density.}\n    \\label{fig:compoundPoisson_histogram_100_1_1}\n\\end{figure}\n\n\\section{Proposed Model}\n\\label{chapter2:proposed_model}\n\nThe compound Poisson-gamma distribution can be used to model the grey value of each pixel in a projection. Suppose a projection has $N$ pixels and $m$ replicate projections were obtained. Let $X_{i,j}$ and $Y_{i,j}$ be the grey value and photon count, respectively, of the $i$th pixel in the $j$th replicate projection.\n\nBy assuming no beam hardening, the distribution of the photon energy does not change with attenuation. As a result, all pixels will detect photons with identical energy distributions, thus, $\\alpha$ and $\\beta$ are the same for all pixels. Attenuation does affect the photon count, the more material a photon has to attenuate, the lower the number of detectable photons. The amount of attenuation depends on the specific path from the source to a pixel in a detector, so $\\lambda_i$ varies from pixel to pixel. Electronic Normal noise $\\epsilon_{i,j}\\sim\\normal(a,\\kappa)$ is added to model noise recorded by the x-ray detector when no x-rays are exposed. This was observed in the black images in Chapter \\ref{chapter2}.\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=0.6\\textwidth]{../figures/compoundpoisson/graphicalModel.pdf}\n  \\caption{Graphical model of the grey value $X_{i,j}$ for each of the $N$ pixels in the $m$ replicate projections. $Y_{i,j}\\sim\\poisson(\\lambda_i)$ is the photon count. The grey value has a compound Poisson gamma element $X_{i,j}|Y_{i,j}\\sim\\gammaDist(Y_{i,j}\\alpha,\\beta)$ and can be extended by adding electronic noise $\\epsilon_{i,j}\\sim\\normal(a,\\kappa)$.}\n  \\label{fig:compoundPoisson_graphicalModel}\n\\end{figure}\n\nThe graphical model in Figure \\ref{fig:compoundPoisson_graphicalModel} illustrates how all of these variables are linked. $a$ and $\\kappa$ are unknown parameters but can be estimated beforehand from replicate black images. Care must be taken to use the replicate black images for either shading correction or for estimating $a$ and $\\kappa$ to avoid using the data twice. The energy of each photon $U\\sim\\gammaDist(\\alpha,\\beta)$ was omitted in the graphical model because the conditional distribution $X|Y\\sim\\gammaDist(Y\\alpha,\\beta)$ encapsulates each detected photon energy already.\n\nThe assumption of a gamma-distributed x-ray photon energy and Normal electronic noise was applied to XCT by \\cite{xu2009electronic}. The assumptions were verified by investigating the variance of radiographs for different x-ray exposures. More statistically sound methods could use goodness of fit tests or Q-Q plots. The use of the gamma distribution will not be exactly correct because the sources of x-ray photon energy are characteristic and bremsstrahlung radiation which does not behave like a gamma random variable. However, characterisation of the density of the x-ray photon energy is difficult and usually involve more apparatuses and numerical methods \\citep{fewell1977photon, stumbo2004direct}.\n\nThe model may be simplified by omitting the electronic noise and this can be done by setting $a=0$ and $\\kappa=0$. Further simplification can be done by removing spatial variation by setting $\\lambda=\\lambda_1=\\lambda_2=\\ldots=\\lambda_N$. Parameter estimation can be done using gradient methods because the likelihood of the compound Poisson can be evaluated \\citep{dunn2005series}. However, the EM algorithm is faster and the model is well set up for it.\n\n\\section{EM Algorithm}\n\nThe EM algorithm \\citep{dempster1977maximum} was proposed to estimate the parameters of a $X\\sim\\CPoisson(\\lambda,\\alpha,\\beta)$ random variable given a sample of measurements of it $\\left\\{x_1,x_2,x_3,\\ldots,x_n\\right\\}$. The use of the EM algorithm for the compound Poisson distribution in XCT have been studied in \\cite{elbakri2003statistical, xie2008x, xu2009electronic}.\n\nLet $\\widehat{\\lambda}$, $\\widehat{\\alpha}$ and $\\widehat{\\beta}$ be estimators of $\\lambda$, $\\alpha$ and $\\beta$ respectively. The log-likelihood is defined to be\n\\begin{equation*}\n  \\ln L(\\lambda,\\alpha,\\beta;X) = \\sum_{i=1}^n\n  \\left[\n    \\mathbb{I}(x_i=0)\\ln \\prob(X=x_i)\n    +\\mathbb{I}(x_i>0)\\ln p_X(x_i)\n  \\right]\n\\end{equation*}\nand using the results in Appendix \\ref{chapter:appendix_tweedie}\n\\begin{equation}\n  \\ln L(\\lambda,\\alpha,\\beta;X) =\n    \\sum_{i=1}^n\n    \\left[\n      -\\mathbb{I}(x_i=0)\\lambda\n      \\vphantom{\\sum_i^i}\n    \\right.\n    {}\\\\\n    \\left.\n      +\\mathbb{I}(x_i>0)\\left(\n      -\\beta x_i-\\lambda-\\ln x +\\ln\\sum_{y=1}^\\infty W_y\n      \\right)\n    \\right] \\ .\n\\end{equation}\nMaximum likelihood estimators are values of $\\lambda$, $\\alpha$ and $\\beta$ which jointly maximise the log-likelihood.\n\nThe EM algorithm \\citep{dempster1977maximum} treats $Y\\sim\\poisson(\\lambda)$ as a latent variable. Let $\\left\\{Y_1,Y_2,Y_3,\\ldots, Y_n\\right\\}$ be realisations of $Y$. Define the joint log-likelihood to be\n\\begin{multline*}\n  \\ln L(\\lambda,\\alpha,\\beta;X,Y)\n  =\n  \\sum_{i=1}^n\n  \\left[\n    \\mathbb{I}(x_i=0)\n    \\ln\n    \\prob(Y=0)\n  \\right.\n  \\\\\n  \\left.\n    +\n    \\mathbb{I}(x_i>0)\n    \\ln\n    \\left[\n      p_{X|Y}(x_i|Y_i)\\prob(Y=Y_i)\n    \\right]\n  \\right]\n\\end{multline*}\nso that\n\\begin{multline}\n  \\ln L(\\lambda,\\alpha,\\beta;X,Y)=\n  \\sum_{i=1}^n\n  \\left[\n    -\\mathbb{I}(x_i=0)\n    \\lambda\n  \\right.\n  \\\\\n  \\left.+\n    \\mathbb{I}(x_i>0)\n    \\left(\n      Y_i\\alpha\\ln\\beta-\\ln\\Gamma(Y_i\\alpha)+(Y_i\\alpha-1)\\ln x_i - \\beta x_i\n    \\right.\n  \\right.\n  \\\\\n  \\left.\n    \\left.\n      - \\lambda + Y_i \\ln \\lambda - \\ln(Y_i!)\n    \\right)\n  \\right]\n  \\ .\n  \\label{eq:compoundPoisson_jointLogLikelihood}\n\\end{multline}\nThe estimators were found by optimising the joint log-likelihood. This was done iteratively by estimating the $Y$'s given the $X$'s and parameters (E step), followed by estimating the parameters given the $Y$'s and $X$'s (M step) until some convergence conditions were met.\n\nIt will be shown that using some approximations, the E step and M step can be implemented. However, simulations showed that these estimators struggle for high $\\lambda$.\n\n\\subsection{E Step}\n\nIn the E step, the realisations of $Y$ are estimated using\n\\begin{equation}\n  y_i =\n  \\expectation\\left[\n    Y|X=x_i\n  \\right]\n\\end{equation}\ngiven the parameters $\\lambda$, $\\alpha$ and $\\beta$. The conditional expectation is calculated using\n\\begin{equation}\n  y_i =\n  \\begin{cases}\n    0 & \\text{ for } x=0 \\\\\n    \\dfrac{\\sum_{y=1}^\\infty y \\prob(Y=y|X=x_i)}{\\sum_{y=1}^\\infty \\prob(Y=y|X=x_i)} & \\text{ for } x>0\n  \\end{cases}\n\\end{equation}\nwhere\n\\begin{equation*}\n  \\prob(Y=y|X=x) = \\frac{p_{X|Y}(x|y)\\prob(Y=y)}{p_X(x)}\n  \\ .\n\\end{equation*}\nFocussing on the $x>0$ case for now\n\\begin{equation*}\n  \\prob(Y=y|X=x) = \\frac{1}{p_X(x)}\\frac{\\beta^{y\\alpha}}{\\Gamma(y\\alpha)}x^{y\\alpha-1}\\euler^{-\\beta x}\\frac{\\euler^{-\\lambda}\\lambda^y}{y!}\n\\end{equation*}\nwhich is simplified to\n\\begin{equation}\n  \\prob(Y=y|X=x) = W_y \\frac{\\euler^{-\\lambda-\\beta x}}{x p_X(x)} \\ .\n\\end{equation}\nAs a result, the conditional expectation is\n\\begin{equation}\n  y_i = \\frac{\\sum_{y=1}^\\infty y W_y}{\\sum_{y=1}^\\infty W_y}\n  \\ .\n\\end{equation}\nAs discussed before, the sum in the denominator can be evaluated using the method by \\cite{dunn2005series}. A similar method for evaluating the numerator can be obtained by truncating the sum and summing over large terms.\n\nLet\n\\begin{equation}\n  W_y^{(r)} = y^r W_y \\quad \\text{for }r=1,2,3,\\ldots\n\\end{equation}\nso that\n\\begin{equation}\n  y_i = \\frac{\\sum_{y=1}^\\infty W^{(1)}_y}{\\sum_{y=1}^\\infty W_y} \\ .\n\\end{equation}\nSimilarly,\n\\begin{equation}\n  \\zeta_i = \\variance[Y|X=x_i] = \\frac{\\sum_{y=1}^\\infty W^{(2)}_y}{\\sum_{y=1}^\\infty W_y} - \\left(y_i\\right)^2\n  \\ .\n\\end{equation}\nThe expectation terms, $y_i$ and $\\zeta_i$, are evaluated here so that they can be used in the M step. The evaluation can be done by truncating the sum\n\\begin{equation}\n  \\sum_{y=1}^\\infty W^{(r)}_y \\approx \\sum_{y=y_\\text{l}}^{y_\\text{u}} W^{(r)}_y\n\\end{equation}\nwhere $y_\\text{l}<y_\\text{max}<y_\\text{u}$ and $y_\\text{max}$ is the value of $y$ which maximises $W_y^{(r)}$. This term can be expressed as\n\\begin{equation}\n  \\ln W_y^{(r)} =r\\ln y+\\ln W_y\n\\end{equation}\nand taking the derivative with respect to $y$ obtains\n\\begin{equation}\n  \\frac{\\partial }{\\partial y} \\ln W_y^{(r)} = \\frac{r}{y } + \\frac{\\partial }{\\partial y}\\ln W_y\n  \\ .\n\\end{equation}\nKeep in mind that $y=1,2,3,\\ldots$ so for large $y$, an approximation can be made $r/y\\approx 0$ so that\n\\begin{equation}\n  \\frac{\\partial }{\\partial y} \\ln W_y^{(r)}\\approx \\frac{\\partial }{\\partial y} \\ln W_y\n  \\ .\n\\end{equation}\nTherefore, the maximum of $W_y^{(r)}$ is located at $y_\\text{max}=\\dfrac{x^{2-p}}{\\phi(2-p)}$ for all $r=0,1,2,\\ldots$. As a result, the same method for evaluating $W_y$ can be used to evaluate $W_y^{(r)}$. For a given $r=0,1,2,\\ldots$, the limit of the sum $\\sum_{y=y_\\text{l}}^{y_\\text{u}} W^{(r)}_y$ were chosen such that $W^{(r)}_{y_\\text{l}}$ and $W^{(r)}_{y_\\text{u}}$ are less than $\\epsilon W_{y_\\text{max}}^{(r)}$ where $\\epsilon$ is some small constant. The limits will be different for different values of $r$.\n\n\\subsection{M Step}\n\nIn the M step, the conditional expected joint log-likelihood is maximised with respect to the parameters $\\lambda$, $\\alpha$ and $\\beta$. The objective function is\n\\begin{align}\n  T(\\lambda,\\alpha,\\beta)&=\n  \\begin{multlined}[t]\n    \\sum_{i=1}^n\n    \\expectation\\left[\n      -\\mathbb{I}(x_i=0)\n      \\lambda\n    \\right.\n    \\\\\n    \\left.+\n      \\mathbb{I}(x_i>0)\n      \\left(\n        Y_i\\alpha\\ln\\beta-\\ln\\Gamma(Y_i\\alpha)+(Y_i\\alpha-1)\\ln x_i - \\beta x_i\n      \\right.\n    \\right.\n    \\\\\n    \\left.\n      \\left.\n        - \\lambda + Y_i \\ln \\lambda - \\ln(Y_i!)\n      \\right)\n      |X_i=x_i\n    \\right]\n  \\end{multlined}\n  \\nonumber\\\\\n  &=\\begin{multlined}[t]\n    -n\\lambda\n    \\\\\n    +\\sum_{i=1}^n\n    \\mathbb{I}(x_i>0)\n    \\left[\n      \\expectation[Y_i|X_i=x_i]\\alpha\\ln\\beta-\\expectation[\\ln\\Gamma(Y_i\\alpha)|X_i=x_i]\n    \\right.\n    {}\\\\\n    \\left.\n      +\\expectation[Y_i|X_i=x_i]\\alpha\\ln x_i - \\beta x_i\n      + \\expectation[Y_i|X_i=x_i] \\ln \\lambda\n    \\right] + c\n  \\end{multlined}\n\\end{align}\nwhere $c$ is some constant not dependent on $\\lambda$, $\\alpha$ or $\\beta$.\n\nThe conditional expectation $y_i = \\expectation[Y_i|X_i=x_i]$ and $\\zeta_i = \\variance[Y_i|X_i=x_i]$ were calculated beforehand in the E step. The quantity $\\expectation[\\ln\\Gamma(Y_i\\alpha)|X_i=x_i]$ can be calculated using the approximation\n\\begin{equation}\n  \\expectation[\\ln\\Gamma(Y_i\\alpha)|X_i=x_i] \\approx\n  \\ln\\Gamma(\\alpha y_i) + \\frac{1}{2}\\zeta_i\\alpha^2\\psi'(y_i\\alpha)\n\\end{equation}\nwhere $\\psi(n)$ is the digamma function. The objective function is then\n\\begin{multline}\n  T(\\lambda,\\alpha,\\beta)\\approx\n  -n\\lambda\n  +\\sum_{i=1}^n\n  \\mathbb{I}(x_i>0)\n  \\left[\n    y_i\\alpha\\ln\\beta-\\ln\\Gamma(\\alpha y_i) - \\frac{1}{2}\\zeta_i\\alpha^2\\psi'(y_i\\alpha)\n  \\right.\n  \\\\\n  \\left.\n    +y_i\\alpha\\ln x_i - \\beta x_i\n    + y_i \\ln \\lambda\n    \\vphantom{\\frac{1}{1}}\n  \\right]\n  + c\n  \\ .\n\\end{multline}\n\nTaking the derivative with respect to $\\lambda$\n\\begin{equation}\n  \\frac{\\partial T}{\\partial\\lambda} = -n + \\frac{\\sum_{i=1}^ny_i}{\\lambda}\n\\end{equation}\nand setting it to zero\n\\begin{equation}\n  \\widehat{\\lambda} = \\frac{\\sum_{i=1}^n y_i}{n}\n\\end{equation}\nobtains a M step estimator for $\\lambda$. Taking the second-order derivative with respect to $\\lambda$\n\\begin{equation}\n  \\frac{\\partial^2 T}{\\partial \\lambda^2} = -\\frac{\\sum_{i=1}^ny_i}{\\lambda^2} < 0\n\\end{equation}\nverifies that $\\widehat{\\lambda}$ maximises $T$. In addition,\n\\begin{equation}\n  \\frac{\\partial^2 T}{\\partial \\alpha \\partial \\lambda } = 0\n\\end{equation}\nand\n\\begin{equation}\n  \\frac{\\partial^2 T}{\\partial \\beta \\partial \\lambda } = 0\n  \\ .\n\\end{equation}\n\nMaximising $T$ with respect to $\\alpha$ and $\\beta$ can be done numerically using the Newton-Raphson method since derivatives up to the second-order can be obtained. For the first-order derivatives, these are\n\\begin{multline}\n  \\frac{\\partial T}{\\partial \\alpha} =\n  \\sum_{i=1}^n\\mathbb{I}(x_i>0)\n  \\left[\n    y_i\\ln\\beta -\\psi(\\alpha y_i)y_i-\\zeta_i\\alpha\\psi'(\\alpha y_i)\n    \\vphantom{\\frac{1}{1}}\n  \\right.\n  \\\\\n  \\left.\n    - \\frac{1}{2}\\zeta_i\\alpha^2\\psi''(\\alpha y_i)y_i + y_i\\ln x_i\n  \\right]\n\\end{multline}\nand\n\\begin{equation}\n  \\frac{\\partial T}{\\partial \\beta} = \\sum_{i=1}^n\\mathbb{I}(x_i>0)\\left[\n  \\frac{\\alpha y_i}{\\beta}-x_i\n  \\right]\n  \\ .\n\\end{equation}\nThe second-order derivatives are\n\\begin{equation}\n  \\frac{\\partial^2 T}{\\partial \\alpha \\partial \\beta} =\n  \\sum_{i=1}^n \\mathbb{I}(x_i>0)\\left[\\frac{y_i}{\\beta}\\right]\n  \\ ,\n  \\label{eq:compoundPoisson:d2tdadb}\n\\end{equation}\n\\begin{equation}\n  \\frac{\\partial^2 T}{\\partial \\beta^2} = \\sum_{i=1}^n\\mathbb{I}(x_i>0)\\left[-\\frac{\\alpha y_i}{\\beta^2}\n  \\right]\n  \\ ,\n  \\label{eq:compoundPoisson:d2td2b}\n\\end{equation}\nand\n\\begin{multline*}\n  \\frac{\\partial^2 T}{\\partial \\alpha^2} =\n  \\sum_{i=1}^n\\mathbb{I}(x_i>0)\n  \\left[\n    -y_i^2\\psi'(\\alpha y_i) - \\zeta_i\\psi'(\\alpha y_i) - \\zeta_i\\alpha y_i\\psi''(\\alpha y_i)\n    \\vphantom{\\frac{1}{2}}\\right.\\\\\\left.\n    - \\zeta_i\\alpha\\psi''(\\alpha y_i)y_i\n    -\\frac{1}{2}\\zeta_i\\alpha^2\\psi'''(\\alpha y_i)y_i^2\n  \\right]\n\\end{multline*}\nsimplifying to\n\\begin{multline}\n  \\frac{\\partial^2 T}{\\partial \\alpha^2} =\n  \\sum_{i=1}^n\\mathbb{I}(x_i>0)\n  \\left[\n    -(y_i^2+\\zeta_i)\\psi'(\\alpha y_i) - 2\\zeta_i\\alpha y_i\\psi''(\\alpha y_i)\n    \\vphantom{\\frac{1}{2}}\n  \\right.\n  \\\\\n  \\left.\n    -\\frac{1}{2}\\zeta_i\\alpha^2y_i^2\\psi'''(\\alpha y_i)\n  \\right] \\ .\n  \\label{eq:compoundPoisson:d2td2a}\n\\end{multline}\n\nAll the derivatives can be used in the Newton-Raphson iterative update to update the estimators $\\widehat{\\alpha}$ and $\\widehat{\\beta}$. The update is\n\\begin{equation}\n  \\begin{pmatrix}\n    \\widehat{\\alpha} \\\\ \\widehat{\\beta}\n  \\end{pmatrix}\n  \\leftarrow\n  \\begin{pmatrix}\n    \\widehat{\\alpha} \\\\ \\widehat{\\beta}\n  \\end{pmatrix}\n  -\n  \\left[\n    \\nabla_{\\alpha,\\beta}\\nabla_{\\alpha,\\beta}\\T \\left. T \\right |_{\\alpha = \\widehat{\\alpha}, \\beta=\\widehat{\\beta}}\n  \\right]^{-1}\n  \\left[\n    \\nabla_{\\alpha,\\beta} \\left. T \\right |_{\\alpha = \\widehat{\\alpha}, \\beta=\\widehat{\\beta}}\n  \\right]\n\\end{equation}\nwhere\n\\begin{equation}\n  \\nabla_{\\alpha,\\beta}=\n  \\begin{pmatrix}\n    {\\partial}/{\\partial \\alpha}\n    \\\\\n    {\\partial}/{\\partial \\beta}\n  \\end{pmatrix}\n  \\ .\n\\end{equation}\nSince increasing $T$ is sufficient for the EM algorithm \\citep{dempster1977maximum}, one step of the Newton-Raphson iterative update was chosen in the M step to avoid implementing a convergence condition for the Newton-Raphson method.\n\n\\subsection{Simulations}\n\nAn experiment was conducted to assess the performance on the EM algorithm. For a given set of parameters, 1\\,000 samples of a $\\CPoisson(\\lambda,\\alpha,\\beta)$ random variable were simulated. The EM algorithm was initialised with its parameters at the true values to investigate the convergence in that vicinity. The log-likelihood $\\ln L(\\lambda,\\alpha,\\beta;X)$ and the parameters were recorded at every EM step. The experiment was repeated 10 times using different simulated samples.\n\nThe results for $\\CPoisson(1,1,1)$, $\\CPoisson(1,100,1)$, $\\CPoisson(10,1,1)$ and $\\CPoisson(100,100,1)$ are shown in Figures \\ref{fig:compoundPoisson_convergence_1}, \\ref{fig:compoundPoisson_convergence_2}, \\ref{fig:compoundPoisson_convergence_3} and \\ref{fig:compoundPoisson_convergence_4} respectively. Good performance was observed in the $\\lambda=1$ case with convergence of all three parameters within a step or two. The Cram\\'er-Rao lower bound captured the spread of the estimates well.\n\nFor $\\lambda=10$ and $\\lambda=100$, the estimates of $\\alpha$ and $\\beta$ struggled to converge and increased/decreased without bounds without affecting the log-likelihood. It appeared that the EM algorithm failed for $\\lambda>10$ looking at these particular examples.\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda1alpha1beta1_lnL.eps}\n        \\caption{Log-likelihood}\n    \\end{subfigure}\n        \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda1alpha1beta1_lambda.eps}\n        \\caption{$\\lambda$}\n    \\end{subfigure}\n    }\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda1alpha1beta1_alpha.eps}\n        \\caption{$\\alpha$}\n    \\end{subfigure}\n        \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda1alpha1beta1_beta.eps}\n        \\caption{$\\beta$}\n    \\end{subfigure}\n    }\n    \\caption{The EM algorithm was used to estimate the parameters of a $\\CPoisson(1,1,1)$ random variable using 1\\,000 simulated samples. The graphs show the log-likelihood and the estimated parameters at each EM step for 10 different simulations.}\n    \\label{fig:compoundPoisson_convergence_1}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda1alpha100beta1_lnL.eps}\n        \\caption{Log-likelihood}\n    \\end{subfigure}\n        \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda1alpha100beta1_lambda.eps}\n        \\caption{$\\lambda$}\n    \\end{subfigure}\n    }\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda1alpha100beta1_alpha.eps}\n        \\caption{$\\alpha$}\n    \\end{subfigure}\n        \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda1alpha100beta1_beta.eps}\n        \\caption{$\\beta$}\n    \\end{subfigure}\n    }\n    \\caption{The EM algorithm was used to estimate the parameters of a $\\CPoisson(1,100,1)$ random variable using 1\\,000 simulated samples. The graphs show the log-likelihood and the estimated parameters at each EM step for 10 different simulations.}\n    \\label{fig:compoundPoisson_convergence_2}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda10alpha1beta1_lnL.eps}\n        \\caption{Log-likelihood}\n    \\end{subfigure}\n        \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda10alpha1beta1_lambda.eps}\n        \\caption{$\\lambda$}\n    \\end{subfigure}\n    }\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda10alpha1beta1_alpha.eps}\n        \\caption{$\\alpha$}\n    \\end{subfigure}\n        \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda10alpha1beta1_beta.eps}\n        \\caption{$\\beta$}\n    \\end{subfigure}\n    }\n    \\caption{The EM algorithm was used to estimate the parameters of a $\\CPoisson(10,1,1)$ random variable using 1\\,000 simulated samples. The graphs show the log-likelihood and the estimated parameters at each EM step for 10 different simulations.}\n    \\label{fig:compoundPoisson_convergence_3}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda100alpha100beta1_lnL.eps}\n        \\caption{Log-likelihood}\n    \\end{subfigure}\n        \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda100alpha100beta1_lambda.eps}\n        \\caption{$\\lambda$}\n    \\end{subfigure}\n    }\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda100alpha100beta1_alpha.eps}\n        \\caption{$\\alpha$}\n    \\end{subfigure}\n        \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/CpEmAlgorithm_CompoundPoissonlambda100alpha100beta1_beta.eps}\n        \\caption{$\\beta$}\n    \\end{subfigure}\n    }\n    \\caption{The EM algorithm was used to estimate the parameters of a $\\CPoisson(100,100,1)$ random variable using 1\\,000 simulated samples. The graphs show the log-likelihood and the estimated parameters at each EM step for 10 different simulations.}\n    \\label{fig:compoundPoisson_convergence_4}\n\\end{figure}\n\n\\afterpage{\\clearpage}\n\n\\section{Failure Evaluation}\n\nIt should be convincing that the EM algorithm failed when the compound Poisson-gamma random variable starts behaving Normally. In particular, in Figure \\ref{fig:compoundPoisson_convergence_4}, estimates of $\\lambda$ were stable while estimates of $\\alpha$ and $\\beta$ struggled to converge. This could be because as the compound Poisson-gamma distribution approaches the Normal distribution, the parameters $(\\lambda,\\alpha,\\beta)$ becomes degenerate because there is more than one way to represent a two-parameter random variable $\\normal(\\mu,\\sigma^2)$ using three parameters $(\\lambda,\\alpha,\\beta)$.\n\n\\subsection{Determinant of the Hessian}\n\nOne investigation is to look at the Newton-Raphson step in the M step, in particular, the Hessian matrix $\\nabla_{\\alpha,\\beta}\\nabla_{\\alpha,\\beta}\\T T$ for high $\\lambda$. The elements of the Hessian matrix can be found in Equations \\eqref{eq:compoundPoisson:d2tdadb}, \\eqref{eq:compoundPoisson:d2td2b} and \\eqref{eq:compoundPoisson:d2td2a}. Recall that\n\\begin{multline*}\n  \\frac{\\partial^2 T}{\\partial \\alpha^2} =\n  \\sum_{i=1}^n\\mathbb{I}(x_i>0)\\left[\n    -(y_i^2+\\zeta_i)\\psi'(\\alpha y_i) - 2\\zeta_i\\alpha y_i\\psi''(\\alpha y_i)\n    \\vphantom{\\frac{1}{2}}\n  \\right.\n  \\\\\n  \\left.\n    -\\frac{1}{2}\\zeta_i\\alpha^2y_i^2\\psi'''(\\alpha y_i)\n  \\right]\n  \\ .\n\\end{multline*}\nFor high $\\alpha$ and $\\lambda$, and hence high $y_i$'s, an approximation can be used for the polygamma functions $\\psi^{(k)}(n)$. Using Stirling's approximation $\\ln\\Gamma(n)\\approx\\ln(n!)\\approx n\\ln n-n$, then\n\\begin{equation}\n  \\psi(n) = \\frac{\\partial\\ln\\Gamma(n)}{\\partial n} \\approx \\ln n\n  \\ .\n\\end{equation}\nDifferentiating further\n\\begin{align}\n  \\psi'(n) &\\approx 1/n \\\\\n  \\psi''(n) & \\approx -1/n^2 \\\\\n  \\psi'''(n) & \\approx 2/n^3\n  \\ .\n\\end{align}\n$\\dfrac{\\partial^2T}{\\partial\\alpha^2}$ can be approximated\n\\begin{equation*}\n  \\frac{\\partial^2 T}{\\partial \\alpha^2} \\approx\n  \\sum_{i=1}^n\\mathbb{I}(x_i>0)\n  \\left[\n    -\\frac{y_i^2+\\zeta_i}{\\alpha y_i} + 2\\frac{\\zeta_i\\alpha y_i}{\\alpha^2 y_i^2}\n    -\\frac{1}{2}\\frac{2\\zeta_i\\alpha^2y_i^2}{\\alpha^3 y_i^3}\n  \\right]\n\\end{equation*}\nto get\n\\begin{equation}\n  \\frac{\\partial^2 T}{\\partial \\alpha^2} \\approx\n  \\sum_{i=1}^n\\mathbb{I}(x_i>0)\n  \\left[\n    -\\frac{y_i}{\\alpha}\n  \\right]\n  \\ .\n\\end{equation}\n\nThe Hessian matrix is, omitting the $\\mathbb{I}(x_i>0)$ term,\n\\begin{equation}\n  \\nabla_{\\alpha,\\beta}\\nabla_{\\alpha,\\beta}\\T T \\approx\n  \\sum_{i=1}^n\n  \\begin{pmatrix}\n    -y_i/\\alpha  & y_i/\\beta \\\\\n    y_i/\\beta & -\\alpha y_i/\\beta^2\n  \\end{pmatrix}\n  \\ .\n\\end{equation}\nThe determinant of the Hessian matrix is\n\\begin{align*}\n  \\|\\nabla_{\\alpha,\\beta}\\nabla_{\\alpha,\\beta}\\T T\\|\n  &\\approx\n  \\left(\\sum_{i=1}^n-\\frac{\\alpha y_i}{\\beta^2}\\right)\n  \\left(\\sum_{i=1}^n-\\frac{y_i}{\\alpha}\\right) - \\left(\\sum_{i=1}^n\\frac{y_i}{\\beta}\\right)^2\n  \\\\\n  &\\approx\n  \\left(\\sum_{i=1}^n\\sum_{j=1}^n\\frac{y_iy_j}{\\beta^2}\\right)\n   - \\left(\\sum_{i=1}^n\\frac{y_i}{\\beta}\\right)\\left(\\sum_{j=1}^n\\frac{y_j}{\\beta}\\right)\n  \\\\\n  &\\approx\n  \\left(\\sum_{i=1}^n\\sum_{j=1}^n\\frac{y_iy_j}{\\beta^2}\\right)\n   - \\left(\\sum_{i=1}^n\\sum_{j=1}^n\\frac{y_iy_j}{\\beta^2}\\right)\n\\end{align*}\nto obtain\n\\begin{equation}\n  \\|\\nabla_{\\alpha,\\beta}\\nabla_{\\alpha,\\beta}\\T T\\|\n  \\approx\n  0\n  \\ .\n\\end{equation}\n\nThis results in a few things. Firstly, $\\nabla_{\\alpha,\\beta}\\nabla_{\\alpha,\\beta}\\T T$ is singular thus its inverse cannot be evaluated which is needed for the Newton-Raphson method. Secondly, the sufficient conditions to classify a stationary point as a maximum are that the diagonal elements of the Hessian matrix are negative and the determinate is positive. For high $\\lambda$ and $\\alpha$, the second condition is not met.\n\n\\subsection{Constrained Objective}\n\nThe parameter $\\beta$ can be constrained for a given mean to be\n\\begin{equation}\n  \\beta = \\frac{\\lambda\\alpha}{\\widehat{\\mu}}\n  \\label{eq:compoundPoisson:beta_restrict}\n\\end{equation}\nwhere\n\\begin{equation}\n  \\widehat{\\mu} = \\frac{1}{n}\\sum_{i=1}^n x_i\n\\end{equation}\nand it was investigated whenever a unique solution to $\\dfrac{\\partial T}{\\partial \\alpha} = 0$ can be found for high $\\lambda$ and $\\alpha$. The constrained objective function is\n\\begin{multline}\n  T(\\lambda,\\alpha)\n  =\n  -n\\lambda+\n  \\sum_{i=1}^n\n  \\mathbb{I}(x_i>0)\n  \\left[\n  y_i\\alpha\n  \\ln\\left(\\frac{\\lambda\\alpha}{\\widehat{\\mu}}\\right)-\\ln\\Gamma(\\alpha y_i) - \\frac{1}{2}\\zeta_i\\alpha^2\\psi'(y_i\\alpha)\n  \\right.\n  \\\\\n  \\left.\n    +y_i\\alpha\\ln x_i - \\frac{\\lambda\\alpha x_i}{\\widehat{\\mu}}\n    + y_i \\ln \\lambda\n    \\vphantom{\\frac{1}{1}}\n  \\right]\n  + c\n\\end{multline}\nwhich can be approximated to\n\\begin{align}\n  T(\\lambda,\\alpha)&\\approx\n  \\begin{multlined}[t]\n    -n\\lambda+\n    \\sum_{i=1}^n\n    \\mathbb{I}(x_i>0)\n    \\left[\n      y_i\\alpha\\ln\\left(\\frac{\\lambda\\alpha}{\\widehat{\\mu}}\\right)-\\alpha y_i\\ln(\\alpha y_i) + \\alpha y_i - \\frac{1}{2}\\frac{\\zeta_i\\alpha}{y_i}\n    \\right.\n    \\\\\n    \\left.\n      +y_i\\alpha\\ln x_i - \\frac{\\lambda\\alpha x_i}{\\widehat{\\mu}}\n      + y_i \\ln \\lambda\n      \\vphantom{\\frac{1}{1}}\n    \\right]\n    + c\n  \\end{multlined}\n  \\nonumber\\\\\n  &\\!\\begin{multlined}[b]\\approx\n    -n\\lambda+\n    \\sum_{i=1}^n\n    \\mathbb{I}(x_i>0)\n    \\left[\n      y_i\\alpha\\ln\\left(\\frac{\\lambda}{y_i\\widehat{\\mu}}\\right) + \\alpha y_i - \\frac{1}{2}\\frac{\\zeta_i\\alpha}{y_i}\n    \\right.\n    {}\\\\\n    \\left.\n      +y_i\\alpha\\ln x_i - \\frac{\\lambda\\alpha x_i}{\\widehat{\\mu}}\n      + y_i \\ln \\lambda\n      \\vphantom{\\frac{1}{1}}\n    \\right]\n    + c\n    \\ .\n  \\end{multlined}\n\\end{align}\nTaking the derivative with respect to $\\alpha$\n\\begin{equation}\n  \\frac{\\partial T}{\\partial \\alpha} \\approx\n  \\sum_{i=1}^n\n  \\mathbb{I}(x_i>0)\n  \\left[\n    y_i\\ln\\left(\\frac{\\lambda}{y_i\\widehat{\\mu}}\\right)\n    + y_i - \\frac{1}{2}\\frac{\\zeta_i}{y_i}\n    +y_i\\ln x_i - \\frac{\\lambda x_i}{\\widehat{\\mu}}\n    \\vphantom{\\frac{1}{1}}\n  \\right]\n\\end{equation}\nand this is not $\\alpha$ dependent, thus there is no solution for $\\alpha$.\n\n\\subsection{Log-Likelihood Plot}\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpLogLikelihoodPlot_CompoundPoissonlambda1alpha1beta1.eps}\n        \\caption{$\\CPoisson(1,1,1)$}\n    \\end{subfigure}\n        \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpLogLikelihoodPlot_CompoundPoissonlambda1alpha100beta1.eps}\n        \\caption{$\\CPoisson(1,100,1)$}\n    \\end{subfigure}\n    }\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpLogLikelihoodPlot_CompoundPoissonlambda10alpha1beta1.eps}\n        \\caption{$\\CPoisson(10,1,1)$}\n    \\end{subfigure}\n        \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/compoundpoisson/cpLogLikelihoodPlot_CompoundPoissonlambda100alpha100beta1.eps}\n        \\caption{$\\CPoisson(100,100,1)$}\n    \\end{subfigure}\n    }\n    \\caption{Log-likelihood from a simulation of 100 compound Poisson-gamma random variables. $\\lambda$ is fixed at the true value.}\n    \\label{fig:compoundPoisson_loglikelihoodplot}\n\\end{figure}\n\nThe log-likelihood, using a simulation of 100 compound Poisson-gamma random variables, are plotted for fixed $\\lambda$ in Figure \\ref{fig:compoundPoisson_loglikelihoodplot}. These plots are concerning because the likelihood appeared not convex and there is no unique maximum for all $\\lambda$ investigated.\n\nIt was observed that there is a saddle point in the log-likelihood for the $\\CPoisson(1,100,1)$ case. This is when the log-likelihood increased and decreased when varying $\\alpha$ and $\\beta$. This suggests the possibility of local maxima.\n\nAs a result, there is no unique maximum likelihood estimator and the EM algorithm would be very sensitive to the starting position, including for small $\\lambda$.\n\n\\section{Conclusion}\nThe compound Poisson-gamma distribution was studied but it was found there were identifiability issues when fitting the model onto simulated data, in particular for high $\\lambda$. It was found that the log-likelihood was quite flat because, by using numerous approximations, it was found that the determinant of the Hessian is about zero. This cast doubts if a unique maximum likelihood estimator exists. Tighter bounds for the Hessian is beyond the scope of this thesis.\n\nThe problem with the EM algorithm is that it is sensitive to the initial value and does not guarantee convergence to a global maximum \\citep{moon1996expectation}. Another disadvantage is that the EM algorithm does not produce uncertainty quantification for the estimators. Methods such as bootstrapping \\citep{efron1979bootstrap} and Louis' missing information principle \\citep{louis1982finding} can be used to obtain such uncertainty quantification.\n\nThere are methods to deal with flat likelihoods by extending the likelihood to include penalising terms \\citep{cole2014maximum}. Another approach is to use Bayesian methods \\citep{bishop2006pattern} where a prior distribution is defined for the parameters $\\alpha$, $\\beta$, $\\lambda_1,\\lambda_2,\\ldots,\\lambda_N$, $a$ and $\\kappa$ where $N$ is the number of pixels and $a$ and $\\kappa$ are the mean and variance terms for the Normal noise, defined in Section \\ref{chapter2:proposed_model}. The prior distribution can reflect prior knowledge of the model, for example, the statistical properties of the sample of black images can be embedded into the priors of $a$ and $\\kappa$. Back of the envelope calculations can be used to show that $\\lambda_i \\sim 10^7\\,\\si{{photon}\\,\\pixel^{-1}}$ which can be used to aid in the creation of a prior distribution for $\\lambda_i$. Poisson graphical models \\citep{yang2013poisson} and Gaussian processes \\citep{williams1996gaussian} can impose a spatial dependency on $Y_{i,j}$ and $\\lambda_i$ respectively as well.\n\nBayesian inference is done by studying the posterior distribution where\n\\begin{equation*}\n\\mathrm{posterior} \\propto \\mathrm{likelhood} \\times \\mathrm{prior} \\ .\n\\end{equation*}\nBy multiplying the likelihood with the prior, the posterior should hopefully be convex and enable better convergence. Studying the posterior distribution typically requires Markov chains using Monte Carlo methods \\citep{brooks2011handbook} such as Metropolis-Hastings \\citep{metropolis1953equation, hastings1970monte}, Gibbs sampling \\citep{geman1984stochastic}, Hamiltonian Monte Carlo \\citep{neal2011mcmc, hoffman2014no} and slice sampling \\citep{neal2003slice, murray2010elliptical}.\n\nTo keep the frequentist theme throughout this thesis, the next chapter studies the linear relationship between the variance and mean of the grey value in a pixel. The uncertainty can be predicted by using such a relationship.\n", "meta": {"hexsha": "d9e5045c7e0dd595af9fb423e3f1e8ab8751c6df", "size": 63546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/thesis/chapters/3_compoundPoisson.tex", "max_stars_repo_name": "shermanlo77/oxwasp_phd", "max_stars_repo_head_hexsha": "2b2d337356d35aa3db77dca4ef2a9bd3b6a45c12", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "reports/thesis/chapters/3_compoundPoisson.tex", "max_issues_repo_name": "shermanlo77/oxwasp_phd", "max_issues_repo_head_hexsha": "2b2d337356d35aa3db77dca4ef2a9bd3b6a45c12", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "reports/thesis/chapters/3_compoundPoisson.tex", "max_forks_repo_name": "shermanlo77/oxwasp_phd", "max_forks_repo_head_hexsha": "2b2d337356d35aa3db77dca4ef2a9bd3b6a45c12", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.2201365188, "max_line_length": 1053, "alphanum_fraction": 0.7243256853, "num_tokens": 19411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7378641233238883}}
{"text": "\\chapter{Mass and Inertia}\n\n\\section{Empty Aircraft Moments of Inertia}\n\nAircraft is divided into structure groups which mass is estimated. This groups are assumed to be homogeneous rigid body with simple shape which allows to calculate its moment of inertia using an exact closed-form expression, given e.g. in \\cite{HousnerHudson1980}.\n\nSteiner’s theorem, given by the following expression, is used to express aircraft structure groups inertia tensor in Body Axis System. \\cite{Taylor2005, ResnickHalliday2011}\n\\begin{equation}\n  \\label{eq-mass-steiners}\n  {\\boldsymbol I}_b\n  =\n  {\\boldsymbol I}_0\n  +\n  m\n  \\left[\n    \\begin{matrix}\n      y^2 + z^2 &       -xy &       -xz \\\\\n            -yx & x^2 + z^2 &       -yz \\\\\n            -zx &       -zy & x^2 + y^2 \\\\\n    \\end{matrix}\n  \\right]\n\\end{equation}\n\nSum of all aircraft structure groups inertia tensors gives empty aircraft inertia tensor:\n\\begin{equation}\n  {\\boldsymbol I}_b = \\sum_{j} {\\boldsymbol I}_{j,b}\n\\end{equation}\n\n\\section{Variable Masses}\n\nAll variable masses, crew, fuel, payload, etc., are considered to be point masses. Point mass inertia tensor can be calculated using formula (\\ref{eq-mass-steiners}), where ${\\boldsymbol I}_b = 0$. This tensors are then added to the empty aircraft inertia tensor giving total aircraft inertia tensor.\n\nAircraft total first moment of mass is given as follows:\n\\begin{equation}\n  {\\vec S}_b = \\sum_{j} m_j {\\vec r}_{CM,j,b}\n\\end{equation}\n\nPosition of aircraft center of mass including variable masses is then given by following formula:\n\\begin{equation}\n  {\\vec r}_{CM,b} = \\frac{ {\\vec S}_b }{ \\sum_{j} m_j }\n\\end{equation}\n", "meta": {"hexsha": "00fd4425bd51695551fda60985545e019aec1b22", "size": 1636, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/fdm_6.tex", "max_stars_repo_name": "marek-cel/mscsim-docs", "max_stars_repo_head_hexsha": "9984f33c84787c4420f11f2834bb35e040e1f36f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-12-01T02:27:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-09T07:02:20.000Z", "max_issues_repo_path": "tex/fdm_6.tex", "max_issues_repo_name": "marek-cel/mscsim-docs", "max_issues_repo_head_hexsha": "9984f33c84787c4420f11f2834bb35e040e1f36f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/fdm_6.tex", "max_forks_repo_name": "marek-cel/mscsim-docs", "max_forks_repo_head_hexsha": "9984f33c84787c4420f11f2834bb35e040e1f36f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-12-01T10:56:23.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-01T19:41:05.000Z", "avg_line_length": 38.9523809524, "max_line_length": 300, "alphanum_fraction": 0.7047677262, "num_tokens": 450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7378641133890794}}
{"text": "\\chapter{Linear and Logistic Regression}\n\n\\begin{ex}\n  Recall that the least squares estimates are the values $\\betahat_0$ and\n  $\\betahat_1$ that minimize\n  $\\textsc{rss}=\\sum_{i=1}^n(Y_i-\\betahat_1X_i-\\betahat_0)^2$. This is a\n  quadratic function with positive leading coefficients in both $\\betahat_1$ and\n  $\\betahat_0$, and therefore will achieve its minimum at a critical point. To\n  that end, we take partial derivatives with respect to $\\betahat_1$ and\n  $\\betahat_1$, set them equal to zero and solve.\n  \\begin{align*}\n    0 & =\\frac{\\pd{\\textsc{RSS}}}{\\pd \\betahat_0}    \\\\\n      & =2\\sum_{i=1}^n(Y_i-\\betahat_1X_i-\\betahat_0) \\\\\n      & =2n(\\Ybar-\\betahat_1\\Xbar-\\betahat_0),\n  \\end{align*}\n  and therefore,\n  \\[\n    \\betahat_0 = \\Ybar-\\betahat_1\\Xbar.\n  \\]\n\n  Hence,\n  \\begin{align*}\n    0 & =\\frac{\\pd{\\textsc{RSS}}}{\\pd \\betahat_1}               \\\\\n      & =-2\\sum_{i=1}^nX_i(Y_i-\\betahat_1X_i-\\betahat_0)        \\\\\n      & =-2\\left(\\sum_{i=1}^nX_iY_i-\\betahat_1\\sum_{i=1}^nX^2_i\n    +n\\betahat_1\\Xbar^2-n\\Xbar\\Ybar\\right),\n  \\end{align*}\n  or,\n  \\[\n    \\betahat_1=\\frac{\\sum_{i=1}^nX_iY_i-n\\Xbar\\Ybar}{\\sum_{i=1}^nX_i^2-n\\Xbar^2}.\n  \\]\n\n  Since\n  \\begin{align*}\n    \\sum_{i=1}^nX_iY_i-n\\Xbar\\Ybar\n     & =\\sum_{i=1}^n\\left(X_iY_i-\\Xbar\\Ybar\\right)                       \\\\\n     & =\\sum_{i=1}^n\\left(X_iY_i-\\Xbar\\Ybar-\\Xbar\\Ybar+\\Xbar\\Ybar\\right) \\\\\n     & =\\sum_{i=1}^n\\left(X_iY_i-X_i\\Ybar-\\Xbar Y_i+\\Xbar\\Ybar\\right)    \\\\\n     & =\\sum_{i=1}^n\\left(X_i(Y_i-\\Ybar)-\\Xbar(Y_i-\\Ybar)\\right)         \\\\\n     & =\\sum_{i=1}^n(X_i-\\Xbar)(Y_i-\\Ybar),\n  \\end{align*}\n  and\n  \\begin{align*}\n    \\sum_{i=1}^nX_i^2-n\\Xbar^2\n     & =\\sum_{i=1}^n\\left(X_i^2-\\Xbar^2\\right)           \\\\\n     & =\\sum_{i=1}^n\\left(X_i^2-2\\Xbar^2+\\Xbar^2\\right)  \\\\\n     & =\\sum_{i=1}^n\\left(X_i^2-2X_i\\Xbar+\\Xbar^2\\right) \\\\\n     & =\\sum_{i=1}^n\\left(X_i-\\Xbar\\right)^2,\n  \\end{align*}\n  it follows that\n  \\[\n    \\betahat_1\n    =\\frac{\\sum_{i=1}^n(X_i-\\Xbar)(Y_i-\\Ybar)}{\\sum_{i=1}^n\\left(X_i-\\Xbar\\right)^2}.\n  \\]\n\n  Note that\n  \\begin{align*}\n    \\widehat{\\epsilon}_i\n     & =Y_i-\\Yhat_i                                                             \\\\\n     & =\\beta_1X_i+\\beta_0+\\epsilon_i\n    -\\betahat_1X_i-\\betahat_0                                                   \\\\\n     & =\\beta_1X_i+\\beta_0+\\epsilon_i\n    -\\betahat_1X_i+\\betahat_1\\Xbar-\\Ybar                                        \\\\\n     & =(\\epsilon_i+\\beta_1\\Xbar+\\beta_0-\\Ybar)-(\\betahat_1-\\beta_1)(X_i-\\Xbar) \\\\\n     & =(\\epsilon_i-\\epsbar)-(\\betahat_1-\\beta_1)(X_i-\\Xbar),\n  \\end{align*}\n  since\n  \\begin{align*}\n    \\beta_1\\Xbar+\\beta_0-\\Ybar\n     & =\\beta_1\\left(\\sum_{i=1}^nX_i\\right)+\\beta_0-\\sum_{i=1}^n Y_i                                                   \\\\\n     & =\\frac{\\beta_1}{n}\\left(\\sum_{i=1}^n X_i\\right)+\\beta_0-\\frac{1}{n}\\sum_{i=1}^n (\\beta_1X_i+\\beta_0+\\epsilon_i) \\\\\n     & =-\\frac{1}{n}\\sum_{i=1}^n\\epsilon_i.\n  \\end{align*}\n\n  Therefore,\n  \\begin{align*}\n    \\var{\\widehat{\\epsilon}_i}\n     & =\\var{(\\epsilon_i-\\epsbar)-(\\betahat_1-\\beta_1)(X_i-\\Xbar)}     \\\\\n     & =\\var{\\epsilon_i-\\epsbar}+\\var{(\\betahat_1-\\beta_1)(X_i-\\Xbar)}\n    -2\\cov{\\epsilon_i-\\epsbar, (\\betahat_1-\\beta_1)(X_i-\\Xbar)}        \\\\\n     & =\\var{\\epsilon_i-\\epsbar}+(X_i-\\Xbar)^2\\var{\\betahat_1-\\beta_1}\n    -2(X_i-\\Xbar)\\cov{\\epsilon_i-\\epsbar, \\betahat_1-\\beta_1},\n  \\end{align*}\n  where\n  \\begin{align*}\n    \\var{\\epsilon_i-\\epsbar}\n     & =\\var{\\epsilon_i}+\\var{\\epsbar}-2\\cov{\\epsilon_i,\\epsbar}   \\\\\n     & =\\var{\\epsilon_i}+\\frac{1}{n^2}\\var{\\sum_{j=1}^n\\epsilon_j}\n    -\\frac{2}{n}\\cov{\\epsilon_i,\\sum_{j=1}^n\\epsilon_j}            \\\\\n     & =\\sigma^2+\\frac{n\\sigma^2}{n^2}-\\frac{2}{n}\\sigma^2         \\\\\n     & =\\sigma^2\\left(1-\\frac{1}{n}\\right),\n  \\end{align*}\n  \\[\n    \\var{\\betahat_1-\\beta_1}=\\var{\\betahat_1}=\\frac{\\sigma^2}{ns_X^2},\n  \\]\n  \\begin{align*}\n    \\betahat_1-\\beta_1\n     & =\\frac{\\sum_{j=1}^n(X_j-\\Xbar)(Y_j-\\Ybar)}{\\sum_{j=1}^n(X_j-\\Xbar)^2}-\\beta_1                           \\\\\n     & =\\frac{\\sum_{j=1}^n\\left[(X_j-\\Xbar)(Y_j-\\Ybar)-\\beta_1(X_j-\\Xbar)^2\\right]}{\\sum_{j=1}^n(X_j-\\Xbar)^2} \\\\\n     & =\\frac{\\sum_{j=1}^n(X_j-\\Xbar)(Y_j-\\Ybar-\\beta_1X_j+\\beta_1\\Xbar)}{\\sum_{j=1}^n(X_j-\\Xbar)^2}           \\\\\n     & =\\frac{\\sum_{j=1}^n(X_j-\\Xbar)(\\epsilon_j-\\epsbar)}{\\sum_{j=1}^n(X_j-\\Xbar)^2},\n  \\end{align*}\n  \\begin{align*}\n    \\cov{\\epsilon_i-\\epsbar, \\betahat_1-\\beta_1}\n     & =\\E{(\\epsilon_i-\\epsbar)(\\betahat_1-\\beta_1)}\n    -\\E{\\epsilon_i-\\epsbar}\\E{\\betahat_1-\\beta_1}              \\\\\n     & =\\E{\n      \\frac{\\sum_{j=1}^n(X_j-\\Xbar)(\\epsilon_i-\\epsbar)(\\epsilon_j-\\epsbar)}{\\sum_{j=1}^n(X_j-\\Xbar)^2}\n    }                                                          \\\\\n     & =\\frac{(X_i-\\Xbar)\n      \\E{(\\epsilon_i-\\epsbar)^2}\n      +\\sum_{\\substack{j=1                                     \\\\ j\\neq i}}^n\n      (X_i-\\Xbar)\\E{(\\epsilon_i-\\epsbar)(\\epsilon_j-\\epsbar)}\n    }{\\sum_{j=1}^n(X_j-\\Xbar)^2}                               \\\\\n     & =\\frac{(X_i-\\Xbar)\\sigma^2}{\\sum_{j=1}^n(X_j-\\Xbar)^2},\n  \\end{align*}\n  since\n  \\begin{align*}\n    \\E{(\\epsilon_i-\\epsbar)^2}\n     & =\\E{(\\epsilon_i-\\epsbar)^2}\n    -\\E{\\epsilon_i-\\epsbar}^2               \\\\\n     & =\\var{\\epsilon_i-\\epsbar}            \\\\\n     & =\\sigma^2\\left(1-\\frac{1}{n}\\right),\n  \\end{align*}\n  \\begin{align*}\n    \\E{(\\epsilon_i-\\epsbar)(\\epsilon_j-\\epsbar)}\n     & =\\E{(\\epsilon_i-\\epsbar)(\\epsilon_j-\\epsbar)}\n    -\\E{\\epsilon_i-\\epsbar}\\E{\\epsilon_j-\\epsbar}    \\\\\n     & =\\cov{\\epsilon_i-\\epsbar,\\epsilon_j-\\epsbar}  \\\\\n     & =\\cov{\\epsilon_i,\\epsilon_j}\n    -\\cov{\\epsilon_i,\\epsbar}\n    -\\cov{\\epsbar,\\epsilon_j}\n    +\\var{\\epsbar}                                   \\\\\n     & =-\\frac{2\\sigma^2}{n}+\\frac{\\sigma^2}{n}      \\\\\n     & =-\\frac{\\sigma^2}{n}\n  \\end{align*}\n  and\n  \\[\n    \\sum_{\\substack{j=1                                       \\\\ j\\neq i}}^n\n    (X_j-\\Xbar)\\E{(\\epsilon_i-\\epsbar)(\\epsilon_j-\\epsbar)}\n    =-\\frac{\\sigma^2}{n}\\left(n\\Xbar-X_i-(n-1)\\Xbar\\right)\n    =\\frac{\\sigma^2}{n}\\left(\\Xbar-X_i\\right).\n  \\]\n\n  Therefore,\n  \\begin{align*}\n    \\var{\\widehat{\\epsilon}_i}\n     & =\\sigma^2\\left(1-\\frac{1}{n}\\right)\n    +(X_i-\\Xbar)^2\\frac{\\sigma^2}{ns_X^2}\n    -2(X_i-\\Xbar)\\frac{(X_i-\\Xbar)\\sigma^2}{ns_X^2} \\\\\n     & =\\sigma^2\\left(1-\\frac{1}{n}\\right)\n    -(X_i-\\Xbar)^2\\frac{\\sigma^2}{ns_X^2},\n  \\end{align*}\n  and\n  \\begin{align*}\n    \\sum_{i=1}^n\\var{\\widehat{\\epsilon}_i}\n     & =\\sigma^2\\sum_{i=1}^n\\left(\n    \\left(1-\\frac{1}{n}\\right)\n    -(X_i-\\Xbar)^2\\frac{1}{ns_X^2}\n    \\right)                                             \\\\\n     & =n\\sigma^2\\left(\\frac{n-1}{n}-\\frac{1}{n}\\right) \\\\\n     & =(n-2)\\sigma^2.\n  \\end{align*}\n  Hence,\n  \\begin{align*}\n    \\E{\\frac{1}{n-2}\\sum_{i=1}^n\\widehat{\\epsilon}_i^2}\n     & =\\frac{1}{n-2}\\sum_{i=1}^n\\E{\\widehat{\\epsilon}_i^2}                                                     \\\\\n     & =\\frac{1}{n-2}\\left[\\sum_{i=1}^n\\var{\\widehat{\\epsilon}_i}+\\sum_{i=1}^n\\E{\\widehat{\\epsilon}_i}^2\\right] \\\\\n     & =\\sigma^2.\n  \\end{align*}\n\\end{ex}\n\n\\begin{ex}\n  We begin by rewriting $\\betahat_1$ in a more convenient form.\n  \\begin{align*}\n    \\betahat_1\n     & =\\frac{\\sum_{i=1}^n(X_i-\\Xbar)(Y_i-\\Ybar)}{\\sum_{i=1}^n(X_i-\\Xbar)^2}               \\\\\n     & =\\frac{\\sum_{i=1}^n(X_iY_i-\\Xbar\\Ybar)}{\\sum_{i=1}^n(X_i-\\Xbar)^2}                  \\\\\n     & =\\frac{\\sum_{i=1}^n(X_i(\\beta_1X_i+\\beta_0+\\epsilon_i)\n      -\\Xbar(\\beta_1\\Xbar+\\beta_0+\\epsbar))}{\\sum_{i=1}^n(X_i-\\Xbar)^2}                    \\\\\n     & =\\frac{\\beta_1\\sum_{i=1}^nX_i^2+n\\beta_0\\Xbar+\\sum_{i=1}^n X_i\\epsilon_i\n      -n\\beta_1\\Xbar^2-n\\beta_0\\Xbar-n\\epsbar\\Xbar}{\\sum_{i=1}^n(X_i-\\Xbar)^2}             \\\\\n     & =\\beta_1+\\frac{\\sum_{i=1}^nX_i\\epsilon_i-n\\epsbar\\Xbar}{\\sum_{i=1}^n(X_i-\\Xbar)^2}  \\\\\n     & =\\beta_1+\\frac{\\sum_{i=1}^n(X_i\\epsilon_i-\\epsbar\\Xbar)}{\\sum_{i=1}^n(X_i-\\Xbar)^2} \\\\\n     & =\\beta_1+\\frac{\\sum_{i=1}^n(X_i-\\Xbar)\\epsilon_i}{\\sum_{i=1}^n(X_i-\\Xbar)^2}\n  \\end{align*}\n\n  Therefore,\n  \\begin{align*}\n    \\E{\\betahat_1}\n     & =\\E{\\beta_1+\\frac{\\sum_{i=1}^n(X_i-\\Xbar)\\epsilon_i}{\\sum_{i=1}^n(X_i-\\Xbar)^2}} \\\\\n     & =\\beta_1+\\frac{\\sum_{i=1}^n(X_i-\\Xbar)\\E{\\epsilon_i}}{\\sum_{i=1}^n(X_i-\\Xbar)^2} \\\\\n     & =\\beta_1,\n  \\end{align*}\n  and\n  \\begin{align*}\n    \\E{\\betahat_0}\n     & =\\E{\\Ybar-\\betahat_1\\Xbar}                        \\\\\n     & =\\E{\\beta_1\\Xbar+\\beta_0-\\epsbar-\\betahat_1\\Xbar} \\\\\n     & =\\beta_0+\\E{\\beta_1-\\betahat_1}\\Xbar-\\E{\\epsbar}  \\\\\n     & =\\beta_0.\n  \\end{align*}\n\n  Likewise,\n  \\begin{align*}\n    \\var{\\betahat_1}\n     & =\\var{\\beta_1+\\frac{\\sum_{i=1}^n(X_i-\\Xbar)\\epsilon_i}{\\sum_{i=1}^n(X_i-\\Xbar)^2}}          \\\\\n     & =\\frac{\\sum_{i=1}^n(X_i-\\Xbar)^2\\var{\\epsilon_i}}{\\left(\\sum_{i=1}^n(X_i-\\Xbar)^2\\right)^2} \\\\\n     & =\\frac{\\sigma^2}{ns_X^2},\n  \\end{align*}\n  \\begin{align*}\n    \\cov{\\epsbar, \\betahat_1}\n     & =\\cov{\\epsbar, \\beta_1+\\frac{\\sum_{i=1}^n(X_i-\\Xbar)\\epsilon_i}{\\sum_{i=1}^n(X_i-\\Xbar)^2}} \\\\\n     & =\\frac{1}{s_X^2}\\cov{\\sum_{i=1}^n\\epsilon_i, \\sum_{i=1}^n(X_i-\\Xbar)\\epsilon_i}             \\\\\n     & =\\frac{1}{s_X^2}\\sum_{i=1}^n(X_i-\\Xbar)\\sigma^2                                             \\\\\n     & =0,\n  \\end{align*}\n  \\begin{align*}\n    \\var{\\betahat_0}\n     & =\\var{\\Ybar-\\betahat_1\\Xbar}                                           \\\\\n     & =\\var{\\beta_1\\Xbar+\\beta_0+\\epsbar-\\betahat_1\\Xbar}                    \\\\\n     & =\\var{\\epsbar}+\\Xbar^2\\var{\\betahat_1}-2\\Xbar\\cov{\\epsbar, \\betahat_1} \\\\\n     & =\\frac{\\sigma^2}{n}+\\Xbar^2\\frac{\\sigma^2}{ns_X^2}                     \\\\\n     & =\\frac{\\sigma^2}{ns_X^2}\\left(s_X^2+\\Xbar^2\\right)                     \\\\\n     & =\\frac{\\sigma^2\\left(\\frac{1}{n}\\sum_{i=1}^nX_i^2\\right)}{ns_X^2},\n  \\end{align*}\n  and\n  \\begin{align*}\n    \\cov{\\betahat_0, \\betahat_1}\n     & =\\cov{\\Ybar-\\betahat_1\\Xbar, \\betahat_1}         \\\\\n     & =\\cov{\\beta_1\\Xbar+\\beta_0+\\epsbar, \\betahat_1}\n    -\\Xbar\\cov{\\betahat_1, \\betahat_1}                  \\\\\n     & =\\cov{\\epsbar, \\betahat_1}-\\Xbar\\var{\\betahat_1} \\\\\n     & =-\\Xbar\\frac{\\sigma^2}{ns_X^2}.\n  \\end{align*}\n\\end{ex}\n\n\\begin{ex}\n  Assume that $Y_i=\\beta X_i+\\epsilon_i$, with $\\cE{\\epsilon_i}{X_i}=0$\n  and $\\cVar{\\epsilon_i}{X_i}=\\sigma^2$.\n\n  The least squares estimate for $\\beta$ is the value $\\betahat$ that minimizes\n  $\\textsc{rss}=\\sum_{i=1}^n(Y_i-\\betahat X_i)^2$. This is a quadratic function\n  in $\\betahat$ with a positive leading coefficient and therefore will achieve\n  its minimum at the critical point. We have\n  \\[\n    0\n    =\\frac{\\pd RSS}{\\pd\\betahat}\n    =2\\sum_{i=1}^nX_i(Y_i-\\betahat X_i)\n    =2\\sum_{i=1}^n X_iY_i-2\\betahat\\sum_{i=1}^n X_i^2,\n  \\]\n  which implies that\n  \\[\n    \\betahat\n    =\\frac{\\sum_{i=1}^n X_iY_i}{\\sum_{i=1}^n X_i^2}\n    =\\frac{\\sum_{i=1}^n X_i(\\beta X_i+\\epsilon_i)}{\\sum_{i=1}^n X_i^2}\n    =\\beta+\\frac{\\sum_{i=1}^n X_i\\epsilon_i}{\\sum_{i=1}^n X_i^2}.\n  \\]\n\n  Note that then\n  \\[\n    \\E{\\betahat}\n    =\\E{\\beta+\\frac{\\sum_{i=1}^n X_i\\epsilon_i}{\\sum_{i=1}^n X_i^2}}\n    =\\beta+\\frac{\\sum_{i=1}^n X_i\\E{\\epsilon_i}}{\\sum_{i=1}^n X_i^2}\n    =\\beta,\n  \\]\n  and\n  \\[\n    \\var{\\betahat}\n    =\\var{\\beta+\\frac{\\sum_{i=1}^n X_i\\epsilon_i}{\\sum_{i=1}^n X_i^2}}\n    =\\frac{\\sum_{i=1}^n X_i^2\\var{\\epsilon_i}}{\\left(\\sum_{i=1}^n X_i^2\\right)^2}\n    =\\frac{\\sigma^2}{\\sum_{i=1}^nX_i^2}\n  \\]\n\n  Therefore,\n  \\[\n    \\sehat(\\betahat)=\\frac{\\sigmahat^2}{\\sqrt{\\sum_{i=1}^nX_i^2}}.\n  \\]\n\n  Finally, note that\n  \\[\n    \\betahat\n    =\\beta+\\frac{n^{-1}\\sum_{i=1}^n X_i\\epsilon_i}{n^{-1}\\sum_{i=1}^n X_i^2},\n  \\]\n  and that therefore, assuming the $X_i$ are \\textsc{iid}, with finite mean\n  $\\mu$ and variance $\\rho^2$, but not identically equal to zero, it follows by\n  the weak law of large numbers that\n  \\[\n    n^{-1}\\sum_{i=1}^n X_i\\epsilon_i\\xrightarrow{P} \\mu\\cdot 0 =0,\\quad\n    n^{-1}\\sum_{i=1}^n X_i^2\\xrightarrow{P}\\rho^2+\\mu^2\n  \\]\n  and that therefore, by Slutsky's theorem,\n  \\[\n    \\betahat\\xrightarrow{P} \\beta.\n  \\]\n\\end{ex}\n\n\\newcommand{\\Rtr}{\\widehat{R}_\\text{tr}}\n\n\\begin{ex}\n  We have\n  \\begin{align*}\n    \\E{\\Rtr(S)}-R(S)\n     & =\\E{\\sum_{i=1}^n(\\Yhat_i-Y_i)^2}-\\sum_{i=1}^n\\E{\\left(\\Yhat_i-Y_i^*\\right)}^2 \\\\\n     & =\\sum_{i=1}^n\\left[\\E{\\Yhat_i^2}-2\\E{Y_i\\Yhat_i}+\\E{Y_i^2}\n    -\\E{\\Yhat_i^2}+2\\E{Y_i^*\\Yhat_i}-\\E{Y_i^{*,2}}\\right]                            \\\\\n     & =\\sum_{i=1}^n\\left[-2\\E{Y_i\\Yhat_i}+\\E{Y_i^2}\n    +2\\E{Y_i^*\\Yhat_i}-\\E{Y_i^{*,2}}\\right]                                          \\\\\n     & =-2\\sum_{i=1}^n\\left[\\E{Y_i\\Yhat_i}-\\E{Y_i^*\\Yhat_i}\\right],\n  \\end{align*}\n  since\n  \\begin{align*}\n    \\E{Y_i^{*,2}}\n     & =\\var{X_i\\beta+\\epsilon_i^*}+\\left[\\E{X_i\\beta+\\epsilon_i^*}\\right]^2           \\\\\n     & =\\var{X_i\\beta}+\\var{\\epsilon_i^*}+\\left[\\E{X_i\\beta}+\\E{\\epsilon_i^*}\\right]^2 \\\\\n     & =\\var{X_i\\beta}+\\var{\\epsilon_i}+\\left[\\E{X_i\\beta}+\\E{\\epsilon_i}\\right]^2     \\\\\n     & =\\var{X_i\\beta + \\epsilon_i}+\\left[\\E{X_i\\beta + \\epsilon_i}\\right]^2           \\\\\n     & =\\E{Y_i^2}.\n  \\end{align*}\n\n  Finally, note that $Y_i^*$ and $\\Yhat_i$ are independent, since the $Y_i^*$'s\n  denote the values of different observations of $Y_i$ from the ones we used to\n  compute the value of $\\betahat$. Hence,\n  \\begin{align*}\n    \\E{\\Rtr(S)}-R(S)\n     & =-2\\sum_{i=1}^n\\left[\\E{Y_i\\Yhat_i}-\\E{Y_i^*}\\E{\\Yhat_i}\\right] \\\\\n     & =-2\\sum_{i=1}^n\\left[\\E{Y_i\\Yhat_i}-\\E{Y_i}\\E{\\Yhat_i}\\right]   \\\\\n     & =-2\\sum_{i=1}^n\\cov{\\Yhat_i, Y_i}.\n  \\end{align*}\n\\end{ex}\n\n% 5\n\\begin{ex}\n  Note that $H_0:\\beta_1=17\\beta_0$ is equivalent to $H_0:\\beta_1-17\\beta_0=0$.\n  We then have\n  \\begin{align*}\n    \\se(\\beta_1-17\\beta_0)\n     & =\\sqrt{\\var{\\beta_1}+\\var{-17\\beta_0}}                                                                    \\\\\n     & =\\sqrt{\\frac{\\sigma^2}{ns^2_X}+17^2\\frac{\\sigma^2\\sum_{i=1}^nX_i^2}{n^2s^2_X}} & (\\text{by Theorem 13.8}) \\\\\n     & =\\frac{\\sigma}{ns_X}\\sqrt{n+289\\sum_{i=1}^nX_i^2}.\n  \\end{align*}\n  The size $\\alpha$ Wald test is then: reject $H_0$ when\n  \\[\n    \\left|\\frac{\\betahat_1-17\\betahat_0}{\\frac{\\sigma}{ns_X}\\sqrt{n+289\\sum_{i=1}^nX_i^2}}\\right|\n    >z_{\\alpha/2}.\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  \\begin{enumerate}[(a)]\n    \\item~\n          \\inputminted{python}{../code/ex13_06a.py}\n          \\inputminted{text}{../output/ex13_06a.txt}\n\n          \\begin{figure}[H]\n            \\centering\n            \\includegraphics{../images/13-06a}\n            \\caption{Plot of the data with the fitted line from the linear model.}\n          \\end{figure}\n    \\item\n          \\inputminted{python}{../code/ex13_06b.py}\n          \\inputminted{text}{../output/ex13_06b.txt}\n\n          \\begin{figure}[H]\n            \\centering\n            \\includegraphics{../images/13-06b}\n            \\caption{Plot of the $\\log(\\text{MPG})$ response data with the\n              fitted line from the linear model.}\n          \\end{figure}\n\n          A linear model seems to fit the $\\log(\\text{MPG})$ response data\n          better than then original $\\text{MPG}$ response.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  \\begin{enumerate}[(a)]\n    \\item~\n          \\inputminted{python}{../code/ex13_07a.py}\n          \\inputminted{text}{../output/ex13_07a.txt}\n    \\item\n          \\inputminted{python}{../code/ex13_07b.py}\n          \\inputminted{text}{../output/ex13_07b.txt}\n    \\item\n          \\inputminted{python}{../code/ex13_07c.py}\n          \\inputminted{text}{../output/ex13_07c.txt}\n    \\item\n          \\inputminted{python}{../code/ex13_07d.py}\n          \\inputminted{text}{../output/ex13_07d.txt}\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Let $Y=X\\beta+\\epsilon$. Suppose that $\\epsilon_i\\,|\\,X_i\\sim N(0,\\sigma^2)$,\n  and note that then by an identical argument to Section 13.2,\n  \\[\n    \\ell_S\n    =-n\\log{\\sigma}\n    -\\frac{1}{2\\sigma^2}\\sum_{i=1}^n\\left(Y_i-X_i\\beta\\right)^2.\n  \\]\n  We then have\n  \\begin{align*}\n    -2\\sigma^2(\\ell_S-|S|)-2n\\sigma^2\\log{\\sigma}\n     & =-2\\sigma^2\\left(\n    -n\\log{\\sigma}-\\frac{1}{2\\sigma^2}\\sum_{i=1}^n\\left(Y_i-X_i\\beta\\right)^2-|S|\n    \\right)-2n\\sigma^2\\log{\\sigma}                                                              \\\\\n     & =\\sum_{i=1}^n(Y_i-X_i\\beta)^2+2|S|\\sigma^2+2n\\sigma^2\\log{\\sigma}-2n\\sigma^2\\log{\\sigma} \\\\\n     & =\\Rtr+2|S|\\sigma^2,\n  \\end{align*}\n  i.e.\\ Mallow's $C_p$ statistic is equal to a negative constant times AIC plus\n  a constant. Therefore, maximizing AIC is equivalent to minimizing Mallow's\n  $C_p$.\n\\end{ex}\n\n\\begin{ex}\n  \\begin{enumerate}[(a)]\n    \\item We have\n          \\begin{align*}\n            \\P{J_n=0}\n             & =\\P{AIC_0 > AIC_1}                                                           \\\\\n             & =\\P{\\ell(0) > \\ell(\\thetahat)-1}                                             \\\\\n             & =\\P{-\\frac{1}{2}\\sum_{i=1}^nX_i^2 > -\\frac{1}{2}\\sum_{i=1}^n(X_i-\\Xbar)^2-1} \\\\\n             & =\\P{\\sum_{i=1}^nX_i^2-\\sum_{i=1}^n(X_i-\\Xbar)^2 < 2}                         \\\\\n             & =\\P{\\sum_{i=1}^n\\left[X_i^2-X_i^2+2X_i\\Xbar-\\Xbar^2 \\right] < 2}             \\\\\n             & =\\P{n\\Xbar^2 < 2}.\n          \\end{align*}\n          If $\\mathcal{M}_0$ is the true model, i.e.\\ $\\theta=0$, we have\n          \\[\n            \\P{J_n=0}\n            =\\P{|\\sqrt{n}\\Xbar| < \\sqrt{2}}\n            =\\Phi(\\sqrt{2})-\\Phi(-\\sqrt{2})\n            \\approx 0.8427.\n          \\]\n          Otherwise,\n          \\begin{align*}\n            \\P{J_n=0}\n             & =\\P{n\\Xbar^2 < 2}                                                                \\\\\n             & =\\P{-\\sqrt{\\frac{2}{n}} < \\Xbar < \\sqrt{\\frac{2}{n}}}                            \\\\\n             & =\\P{-\\sqrt{\\frac{2}{n}}-\\theta < \\Xbar-\\theta < \\sqrt{\\frac{2}{n}}-\\theta}       \\\\\n             & =\\P{-\\sqrt{2}-\\sqrt{n}\\theta < \\sqrt{n}(\\Xbar-\\theta) < \\sqrt{2}-\\sqrt{n}\\theta} \\\\\n             & =\\Phi(\\sqrt{2}-\\sqrt{n}\\theta)-\\Phi(-\\sqrt{2}-\\sqrt{n}\\theta),\n          \\end{align*}\n          and therefore\n          \\[\n            \\lim_{n\\to\\infty}\\P{J_n=0}\n            =\\lim_{n\\to\\infty}\\left[\\Phi(\\sqrt{2}-\\sqrt{n}\\theta)-\\Phi(-\\sqrt{2}-\\sqrt{n}\\theta)\\right]\n            =0.\n          \\]\n    \\item We proved earlier that assuming $\\theta\\neq 0$,\n          $\\widehat{f}_n\\xrightarrow{P}\\phi_{\\thetahat}$. Note that\n          \\begin{align*}\n            D(\\phi_\\theta, \\phi_{\\thetahat})\n             & =\\int \\frac{1}{\\sqrt{2\\pi}}\\exp\\left\\{-\\frac{(x-\\theta)^2}{2}\\right\\}\n            \\log\\left(\\frac{\\frac{1}{\\sqrt{2\\pi}}\\exp\\left\\{-\\frac{(x-\\theta)^2}{2}\\right\\}}{\\frac{1}{\\sqrt{2\\pi}}\\exp\\left\\{-\\frac{(x-\\thetahat)^2}{2} \\right\\}}\\right)\\,\\d{x} \\\\\n             & =\\int \\frac{1}{\\sqrt{2\\pi}}\\exp\\left\\{-\\frac{(x-\\theta)^2}{2}\\right\\}\n            \\left(\\frac{(x-\\thetahat)^2}{2}-\\frac{(x-\\theta)^2}{2}\\right)\\,\\d{x}                                                                                                \\\\\n             & =\\frac{1}{2}\\int \\frac{1}{\\sqrt{2\\pi}}\\exp\\left\\{-\\frac{(x-\\theta)^2}{2}\\right\\}\n            \\left((\\thetahat^2-\\theta^2)-2x(\\thetahat-\\theta)\\right)\\,\\d{x}                                                                                                     \\\\\n             & =\\frac{\\thetahat^2-\\theta^2}{2}-\\theta(\\thetahat-\\theta)                                                                                                         \\\\\\\n             & =\\frac{1}{2}(\\thetahat-\\theta)^2,\n          \\end{align*}\n          which converges in probability to $0$ since $\\thetahat-\\theta$\n          converges in probability to $0$.\n    \\item We have\n          \\begin{align*}\n            \\P{J_n=0}\n             & =\\P{BIC_0 > BIC_1}                                                                            \\\\\n             & =\\P{\\ell(0) > \\ell(\\thetahat)-\\frac{1}{2}\\log{n}}                                             \\\\\n             & =\\P{-\\frac{1}{2}\\sum_{i=1}^nX_i^2 > -\\frac{1}{2}\\sum_{i=1}^n(X_i-\\Xbar)^2-\\frac{1}{2}\\log{n}} \\\\\n             & =\\P{\\sum_{i=1}^nX_i^2-\\sum_{i=1}^n(X_i-\\Xbar)^2 < \\log{n}}                                    \\\\\n             & =\\P{\\sum_{i=1}^n\\left[X_i^2-X_i^2+2X_i\\Xbar-\\Xbar^2 \\right] < \\log{n}}                        \\\\\n             & =\\P{-\\sqrt{\\frac{\\log{n}}{n}}<\\Xbar < \\sqrt{\\frac{\\log{n}}{n}}}                               \\\\\n             & =\\P{-\\sqrt{\\log{n}}-\\sqrt{n}\\theta <\\sqrt{n}(\\Xbar-\\theta) < \\sqrt{\\log{n}}-\\sqrt{n}\\theta}.\n          \\end{align*}\n          Assuming the true model is $\\theta=0$,\n          \\begin{align*}\n            \\lim_{n\\to\\infty}\\P{J_n=0}\n             & =\\lim_{n\\to\\infty}\\P{-\\sqrt{\\log{n}}<\\sqrt{n}\\Xbar < \\sqrt{\\log{n}}}          \\\\\n             & =\\lim_{n\\to\\infty}\\Phi(\\sqrt{\\log{n}})-\\lim_{n\\to\\infty}\\Phi(-\\sqrt{\\log{n}}) \\\\\n             & =0,\n          \\end{align*}\n          while if $\\theta\\neq 0$,\n          \\begin{align*}\n            \\lim_{n\\to\\infty}\\P{J_n=0}\n             & =\\lim_{n\\to\\infty}\\Phi(\\sqrt{\\log{n}}-\\sqrt{n}\\theta)\n            -\\lim_{n\\to\\infty}\\Phi(-\\sqrt{\\log{n}}-\\sqrt{n}\\theta)\n            =0.\n          \\end{align*}\n  \\end{enumerate}\n\\end{ex}\n\n% 10\n\\begin{ex}\n  \\begin{enumerate}[(a)]\n    \\item Note that\n          \\[\n            \\P{\\Yhat_*-2s < Y_* < \\Yhat_*+2s}\n            =\\P{-2 < \\frac{Y_*-\\Yhat_*}{s} < 2},\n          \\]\n          where $\\var{Y_*-\\Yhat_*}=\\var{\\epsilon}+\\var{\\Yhat_*}=\\sigma^2+s^2$\n          and $\\E{Y_*-\\Yhat_*}=0$. Therefore,\n          \\[\n            \\frac{Y_*-\\Yhat_*}{s}\\approx N\\left(0, 1+\\frac{\\sigma^2}{s^2}\\right),\n          \\]\n          and thus\n          \\[\n            \\P{-2 < \\frac{Y_*-\\Yhat_*}{s} < 2}\\neq 0.95.\n          \\]\n    \\item We have\n          \\begin{align*}\n            \\var{Y_*-\\Yhat_*}\n             & =\\var{Y_*-\\Yhat_*}                                                                     \\\\\n             & =\\var{\\beta_0+\\beta_1X_*+\\epsilon-\\betahat_0-\\betahat_1X_*}                            \\\\\n             & =\\var{\\betahat_0+\\betahat_1X_*}+\\var{\\epsilon}                                         \\\\\n             & =\\var{\\betahat_0}+X_*^2\\var{\\betahat_1}+2X_*\\cov{\\betahat_0,\\betahat_1}+\\var{\\epsilon} \\\\\n             & =\\frac{\\sigma^2}{n^2s_X^2}\n            \\sum_{i=1}^n\\left(X_i^2-2X_*X_i+X_*^2\n            \\right)+\\sigma^2                                                                          \\\\\n             & =\\left[\\frac{\\sum_{i=1}^n(X_i-X_*)^2}{n\\sum_{i=1}^n(X_i-\\Xbar)^2}+1\\right]\\sigma^2     \\\\\n             & =\\xi_n^2,\n          \\end{align*}\n          and therefore,\n          \\begin{align*}\n            \\P{\\Yhat_*-2\\widehat{\\xi}_n < Y_* < \\Yhat_*+2\\widehat{\\xi}_n}\n             & =\\P{-2 < \\frac{Y_*-\\Yhat_*}{\\widehat{\\xi}_n} < 2} \\\\\n             & \\approx \\P{-2 < N(0,1) < 2}                       \\\\\n             & \\approx 0.95.\n          \\end{align*}\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}~\n  \\inputminted{python}{../code/ex13_11.py}\n  \\inputminted{text}{../output/ex13_11.txt}\n\\end{ex}", "meta": {"hexsha": "9bc17268b42230ca18677fc927ba9e8c2889e327", "size": 22529, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/ch13.tex", "max_stars_repo_name": "dtrifuno/all-of-stats-solutions", "max_stars_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/tex/ch13.tex", "max_issues_repo_name": "dtrifuno/all-of-stats-solutions", "max_issues_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tex/ch13.tex", "max_forks_repo_name": "dtrifuno/all-of-stats-solutions", "max_forks_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.1102803738, "max_line_length": 179, "alphanum_fraction": 0.4887034489, "num_tokens": 9013, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7377198376718287}}
{"text": "\n\\section{Results}\n\n\\begin{frame}{Results}\n  \n  Revisiting the model\n  $$\\begin{cases}\n    \\begin{array}{rl}\n      dM\\hspace{-.8em}&=[aMC - \\frac{gM(t-\\tau)}{1-C(t-\\tau)} + \\gamma M (1-M-C)]dt+\\beta M(1-M)dW,\\\\\n      dC\\hspace{-.8em}&=[rC(1-M-C) - dC - aMC]dt.\\\\\n    \\end{array}\n    \\end{cases}$$\\\\\n  We are interested in the effects of:\n  \\begin{itemize}\n  \\item $\\theta$ (the initial condition)\\\\\n  \\item $\\beta$\\\\\n  \\item $\\tau$\\\\\n  \\item $g$\\\\\n  \\end{itemize}\n  \n  \n\n\\end{frame}\n\n\\begin{frame}{Theta}\n\\includegraphics[scale=.325]{nullclinesarc.png}\n\n\\end{frame}\n\n\\begin{frame}{The Simulation}\nWe sampled the following values:\n\\begin{itemize}\n\\item $\\theta$ = $\\frac{\\pi}{42}$ to $\\frac{20\\pi}{42}$ by $\\frac{\\pi}{42}$\\\\\n\\item $\\beta$ = 0 to 1 by 0.05\\\\\n\\item $\\tau$ = 0.5 to 1 by 0.05\\\\\n\\item $g$ = 0.2 to 0.8 by 0.1\\\\\n\\end{itemize}\nWe performed Monte Carlo simulations.\n\\end{frame}\n\n% %\\begin{frame}\\frametitle{At First Glance}\n% %\\includegraphics[scale=.325]{qqplot_lgcoral.png}\n% %\\end{frame}\n\n\\begin{frame}\n\\includegraphics[scale=.325]{scatter_lgcoral_gpt4_betapt4_theta10.png}\n\\end{frame}\n\n\\begin{frame}{Initial Conditions}\n\\includegraphics[scale=.325]{scatter_gpt4_betapt4.png}\n\\end{frame}\n\n\\begin{frame}{The Three Models}\nBased on the plot, we will try the following three models\n\\begin{itemize}\n\\item Binomial Logit\\\\\nFits the model $logit(p)=a+b\\theta$ where $logit(p)=log(\\frac{p}{1-p})$\\\\\n\\item Poisson Log\\\\\nFits the model $log(n)=a+b\\theta$\\\\\n\\item Ordinary Least Squares (OLS)\\\\\nFits the model $p=a+b\\theta$\\\\\n\\end{itemize}\n\\end{frame}\n\n\n\n\n\\begin{frame}\\frametitle{The Binomial Logit Model}\n{\\fontsize{8}{3} \\color{RBlue} \\verbatiminput{theta_logit_summary.txt}}\n\nConducting a goodness of fit test: \\\\\n$P(\\chi^{2}_{1}>10485-2171)<0.0001$\\\\\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{The Poisson Log Model}\n{\\fontsize{8}{3} \\color{RBlue} \\verbatiminput{theta_log_summary.txt}}\n\nConducting a goodness of fit test: \\\\\n$P(\\chi^{2}_{1}>3714.9-1970.4)<0.0001$\\\\\n\n\\end{frame}\n\n%\\begin{frame}\\frametitle{Problematic Poisson}\n%From the summary statistics, there is a problem with overdispersion.\\\\\n%\\\\\n%$\\frac{G^2}{df}\\approx1$\\\\\n%$\\frac{2006.7}{37}\\approx54.2$\\\\\n%\\\\\n%Therefore, we fit a negative binomial model.\\\\\n%\\end{frame}\n\n%\\begin{frame}\\frametitle{The Negative Binomial}\n\n%\\end{frame}\n\n\\begin{frame}\\frametitle{Problematic Poisson}\nThere may be a problem with the model.\nIn the data, there is an overabundance of zeros.\nTherefore, we fit a zero-inflated Poisson model (ZIP).\n{\\fontsize{8}{3} \\color{RBlue} \\verbatiminput{theta_zeros.txt}}\n\\end{frame}\n\n\\begin{frame}\\frametitle{The ZIP Model}\n{\\fontsize{8}{3} \\color{RBlue} \\verbatiminput{theta_log_zip_summary.txt}}\n\\end{frame}\n\n\\begin{frame}\\frametitle{The OLS Model}\n{\\fontsize{8}{3} \\color{RBlue} \\verbatiminput{theta_ols_summary.txt}}\n\nConducting a goodness of fit test: \\\\\n$P(\\chi^{2}_{1}>4.5824-1.4317)\\approx0.07589$\\\\\n\n\\end{frame}\n\n\\begin{frame}\\frametitle{Comparing the Models}\nOur three models are \\\\\n\\begin{itemize}\n\\item Binomial Logit $p=\\frac{e^{-2.48378+6.01631\\theta}}{1+e^{-2.48378+6.01631\\theta}}$\\\\\n\\item Poisson Log $n=e^{4.89295+0.90423\\theta}$\\\\\n\\item OLS $p=0.22856+0.64310\\theta$\\\\\n\\end{itemize}\nHow do we determine which model is the most appropriate?\\\\\n\\end{frame}\n\n\\begin{frame}{Binomial Logit, Poisson Log, or OLS}\n\\includegraphics[scale=.325]{theta_threemodels.png}\n\\end{frame}\n\n\\begin{frame}\\frametitle{The Whole Picture}\n\\includegraphics[scale=.325]{allscatter11.png}\n\\end{frame}\n\n\\begin{frame}\\frametitle{The Binomial Logit}\n{\\fontsize{8}{3} \\color{RBlue} \\verbatiminput{all_logit_summary.txt}}\n\\end{frame}\n\n\\begin{frame}\\frametitle{Interpreting the Results}\nKeeping theta and beta constant, an \\textbf{increase} in g of:\n\\begin{itemize}\n\\item 0.01 has an odds ratio of coral survival of 3.21\\\\\n\\item 0.1 has an odds ratio of coral survival of 116413.1\n\\end{itemize}\n\\end{frame}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"Presentation2\"\n%%% End:\n", "meta": {"hexsha": "fff57e6c0efbf67b577092396f3ebe7a42e261ed", "size": 3953, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Presentations/Final/results.tex", "max_stars_repo_name": "SUNY-SDE-2015/REU15", "max_stars_repo_head_hexsha": "a54ace642d8696250c7fa0bf574b16a931ec91c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Presentations/Final/results.tex", "max_issues_repo_name": "SUNY-SDE-2015/REU15", "max_issues_repo_head_hexsha": "a54ace642d8696250c7fa0bf574b16a931ec91c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-06-04T17:55:32.000Z", "max_issues_repo_issues_event_max_datetime": "2015-07-09T15:38:17.000Z", "max_forks_repo_path": "Presentations/Final/results.tex", "max_forks_repo_name": "SUNY-SDE-2015/REU15", "max_forks_repo_head_hexsha": "a54ace642d8696250c7fa0bf574b16a931ec91c9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.3533333333, "max_line_length": 101, "alphanum_fraction": 0.6974449785, "num_tokens": 1403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7377198353586945}}
{"text": "% !TEX root = hw3.tex\n\n\\section{Influence Maximization [25 points]}\n\nIn class we discussed the influence maximization problem and the greedy hill-climbing approach to solving it. In the algorithm, we add nodes to the current seed set one at a time. At step 0, we have an empty set $S_0$. At step $i > 0$, we pick the node which maximizes the marginal gain: $S_i = S_{i-1} \\cup \\left\\{ \\arg \\max_u f(S_{i-1} \\cup \\{u\\})-f(S_{i-1})\\right\\}$, where $f(S)$ denotes the number of nodes influenced by the initially active set $S$ (includes the set $S$ itself).\n\nAs we showed in  class the hill climbing algorithm cannot guarantee an optimal solution. In other words, there might exist a set $T$ with $|T| = i$ such that $f(S_i) < f(T)$. It is also known that the greedy algorithm is a $(1-(1-\\frac{1}{k})^k)$ - approximation for the influence maximization problem (its sub-optimality is bounded). In other words, for every $k \\geq 1$, the greedy hill-climbing algorithm outputs a set $S_k$ such that $f(S_k) \\geq (1-(1-\\frac{1}{k})^k) f(T)$ where T is the optimal set for influence maximization.  \n\nParts 1 and 2 of this problem ask you to construct examples where the greedy hill climbing returns a sub-optimal solution. In part 2, you will explore examples close to the non-optimal bound for the greedy algorithm for $k=3$. Your answer should consist of: (1) For every node $u$ its influence set $X_u$ (you can describe the set or draw a directed graph where an edge from $A$ to $B$ indicates that node $A$ influences node $B$ with probability $1$),\n(2) $S_i$, the set of nodes that a greedy hill climbing would choose after $i$ iterations, and (3) $T$, the optimal set of $i$ nodes.\n\n\n\nFor all the questions, you can assume: (1) The nodes in $S$ are influencing themselves, i.e., the count of total influence $f(S)$ includes the nodes in $S$. (2) The influence set $X_{u}$ contains all nodes that are influenced by node $u$, both directly and eventually. (3) When several nodes have the same level of marginal gain, we choose one of them at random.\\\\\n\n\\subsection{Non-Optimal Hill-Climbing [8 points]} For $k = 2$, construct an example where $f(S_k) < f(T)$. That is, hill-climbing will only find a non-optimal solution. (Hint: the last step of the greedy approach is optimal given the $k-1$ previous steps.)\\\\\n\n\\subsection{Bounded Non-Optimal Hill-Climbing [8 points]} \n\n\nFor $k= 3$, construct an example where  $f(S_k) \\leq 0.8 f(T)$. That is, hill-climbing will only find a solution that is at most 80\\% of the optimal solution.\\\\\n( Note: 0.8 is very close to the true lower bound for $f(S_k)$ when $k=3$ which is approximately 0.70 )\n\n\\subsection{Optimality of Hill-Climbing [4 points]} Give a property of influence sets $X_u$ such that $f(S_i) = f(T)$.  In other words, what is a \\emph{sufficient} property of influence sets of nodes such that greedy hill-climbing always outputs a set which achieves the maximum possible influence for a set of $i$ nodes? If your condition holds, the algorithm should produce an optimal output for any choice of $i$ between 1 and the number of nodes in the graph. The property does not need to be a necessary one. It must be a property of $X_u$. Properties such as ``the network has only $i$ nodes'' are not valid as correct answers.\n\nThere are several correct answers; we will accept all reasonable answers.\\\\\n\n\\subsection{More Hill-Climbing... [5 points]}\n\nAssume that we stop hill-climbing after $k$ steps and $|S_k| = |T| = k$. Recall that in the class we proved a bound in the form of\n\\begin{equation}\nf(T) \\leq f(S_k) + \\sum_{i=1}^k \\delta_i,\n\\end{equation}\nwhere $ \\delta_1, .., \\delta_k $ are the largest $k$ values of $f(S_k \\cup \\{u\\}) - f(S_k)$ for any node $u$ in the graph. Construct a family of examples for which $f(S_k) + \\sum_{i=1}^k \\delta_i - f(T)$ can be arbitrarily large.\n\nTo be more specific, given any number $b$ you should exhibit a network (graph) such that $f(S_k) + \\sum_{i=1}^k \\delta_i - f(T)>b$.\n\nNote: A {\\em family} of examples is a set $F$ of examples such that for any number $b$, there exists a network (graph) $E(b) \\in F$ (corresponding to $b$) such that $f(S_k) + \\sum_{i=1}^k \\delta_i - f(T)>b$.\n\n\\subsection*{What to submit}\n\\begin{enumerate}[{Page} 1:]\n\\setcounter{enumi}{12}\n\\item\n\\begin{itemize} \\item Submit an example: $X_u$, $S$, $T$. \\end{itemize}\n\n\\item \n\\begin{itemize} \\item  Submit an example: $X_u$, $S$, $T$. \\end{itemize}\n\n\\item \n\\begin{itemize} \\item Submit a property and a brief explanation. \\end{itemize}\n\n\\item\n\\begin{itemize} \\item  Submit a family of examples and a brief explanation. \\end{itemize}\n\\end{enumerate}\n", "meta": {"hexsha": "faba31d4865ca63bcb7806efe44d6bb1cb3fab17", "size": 4613, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw3-bundle/hw3_source/hw3_q4.tex", "max_stars_repo_name": "zlpure/cs224w", "max_stars_repo_head_hexsha": "03fc4d179e430454632e1eeaf457626b3ba18a4e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-09-02T15:40:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T05:22:33.000Z", "max_issues_repo_path": "H3/bundle/hw3_source/hw3_q4.tex", "max_issues_repo_name": "Cauchemare/CS224W_2020_Solutions", "max_issues_repo_head_hexsha": "0a37c06e804a0600a505229008e78557a663eabb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "H3/bundle/hw3_source/hw3_q4.tex", "max_forks_repo_name": "Cauchemare/CS224W_2020_Solutions", "max_forks_repo_head_hexsha": "0a37c06e804a0600a505229008e78557a663eabb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-22T16:37:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T16:05:32.000Z", "avg_line_length": 83.8727272727, "max_line_length": 633, "alphanum_fraction": 0.716453501, "num_tokens": 1367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.9184802479302793, "lm_q1q2_score": 0.7376992676089905}}
{"text": "\\section{Miscellaneous}%\n\\label{sec:miscellaneous}\n\n\\begin{thm}[Markov Inequality]\n    If $X$ is a non-negative RV and $a > 0$ then $\\prb(X \\ge a) \\le \\frac{\\E X}{a}$.\n\\end{thm}\n\n\n\\begin{thm}[Binomial $p_n$]\n    If $ \\frac{1}{n} = o_p(p_n)$ then \n    \\begin{equation*}\n        \\frac{S_n - n p_n}{\\sqrt{n p_n q_n}} \\convl N(0, 1).\n    \\end{equation*}\n\\end{thm}\n", "meta": {"hexsha": "1213e177e68686e4eb64f5c801ac7faced9644fe", "size": 360, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "statistics/inference/src/misc.tex", "max_stars_repo_name": "jems-lee/notes", "max_stars_repo_head_hexsha": "2e121f2131c4225776d3c820ac4372968e8248d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "statistics/inference/src/misc.tex", "max_issues_repo_name": "jems-lee/notes", "max_issues_repo_head_hexsha": "2e121f2131c4225776d3c820ac4372968e8248d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "statistics/inference/src/misc.tex", "max_forks_repo_name": "jems-lee/notes", "max_forks_repo_head_hexsha": "2e121f2131c4225776d3c820ac4372968e8248d3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0, "max_line_length": 84, "alphanum_fraction": 0.5888888889, "num_tokens": 151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.7981867777396211, "lm_q1q2_score": 0.7376377864661161}}
{"text": "\\chapter{Real Analysis} \\label{app:RealAnalysis}\n\nThis appendix is devoted to present some definitions and results from real analysis that are used in the manuscript.\n%\nFurther details and proofs can be found in \\cite{rudin1976principles}.\n\n\\begin{definition}[\\textbf{Metric Space}] \\label{def:metric_space}\n    A metric space is an ordered pair $(M,d)$, where $M$ is a set and $d:M \\times M \\longrightarrow \\R$ is a metric on $M$ that for any $x,y,z \\in M$ satisfies:\n    \\begin{align*}\n        1.&~d(x,y) = 0 \\text{ if and only if } x=y, &&\\text{(identity of indiscernibles)}\\\\\n        2.&~d(x,y) = d(y,x), &&\\text{(symmetry)}\\\\\n        3.&~d(x,z) \\le d(x,y) + d(y,z), &&\\text{(triangle inequality)}.\n    \\end{align*}\n\\end{definition}\n\nThe non-negativity property (i.e., $d(x,y) \\ge 0$ for any $x,y\\in M$) follows from the axioms.\n\n\\begin{definition}[\\textbf{Neighborhood}] \\label{def:neighborhood}\n    In a metric space $(M,d)$, a set $V$ is a \\textit{neighbourhood} of a point $x_0\\in M$ if there exists an open ball $B_r(x_0) \\triangleq \\{x \\in M \\mid d(x,x_0) < r\\}$ with centre $x_0$ and radius $r>0$, such that the set $B_r(x_0) \\subset V$. \n\\end{definition}\n\nIntuitively, a neighborhood $V$ of a point $x_0$ is a set that encloses $x_0$ in the sense that one can move a certain amount in any direction starting from $x_0$ without leaving $V$.\n\n\\begin{theorem}[\\textbf{Intermediate value theorem}] \\label{th:IVT}\n    Let $a < b$. Let the interval $I = [a,b]$ of $\\R$ and a continuous function $f:I\\longrightarrow\\R$.\n    %\n    If $u\\in\\R$ is such that \\[\\min\\{f(a),f(b)\\} < u < \\max\\{f(a),f(b)\\},\\] then there exists $c\\in(a,b)$ such that $f(c) = u$.\n\\end{theorem}\n\nAbove we state the well known property of continuous functions that roughly says a function $f$ assumes at least all values between $f(a)$ and $f(b)$ if we consider the interval $[a,b]$.\n\n\\begin{theorem}[\\textbf{Banach fixed point theorem}] \\label{th:banach}\n    Let $(M,d)$ be a non-empty \\textit{complete}\\footnote{A metric space $M$ is \\textit{complete} if every limit point of $M$ is in $M$.} metric space with a function $\\varphi:M\\longrightarrow M$ such that for some $c\\in[0,1)$ we have that $d(\\varphi(x),\\varphi(y))\\le c\\,d(x,y)$ for all $x,y\\in M$.\n    %\n    Then, $\\varphi$ admits a unique fixed point in $M$.\n\\end{theorem}\n\nAbove we state an extremely important tool to prove existence and uniqueness of solutions to equations, integral and differential equations, recurrence equations, and so on.\n\nIt is interesting to note that the unicity comes trivially as follows.\n%\nLet $x$ and $y$ be two fixed points. Then, $d(\\varphi(x),\\varphi(y)) = d(x,y) \\le c\\,d(x,y)$, which is only true if $x=y$.\n\n% % % % % % % % % % % % % % % %\n% % % % % % % % % % % % % % % % \n\\chapter{Queueing Theory}\n\nThis appendix is devoted to present some definitions and results from queueing theory that are used in the manuscript.\n%\nFurther details and proofs can be found in \\cite{baccelli2013elements}.\n\nLet us define a queue $\\{Q(t)\\}_t$ as a Markov chain (Definition~\\ref{def:markov_chain}) with state space $\\N$ and index space $\\T$ (usually $\\N$ or $\\R_+$).\n%\nThe number of packets (or entities) in a queue at time $t\\in \\T$ is denoted by the random variable $Q(t)$ and it must satisfy an equation of the kind\n\\begin{align}\n    Q(t) = Q(t_0) + A(t_0,t] - E(t_0,t], \\qquad \\text{for every}~ t_0,t\\in\\T,\n\\end{align}\nwhere $A$ and $E$ are point processes on $\\T$ and represent the arrival and the departure of packets, respectively.\n%\nNote that $E(t_0,t]$ cannot be independent from $Q(t_0)$, otherwise we might have a negative amount of queued packets at a moment.\n\nTo eliminate this dependence in our context of telecommunication, we usually define a point process $T$ on $\\T$ that represents the moments the transmission can begin.\n%\nLet $T$ be the times for which a transmitter can access the channel.\n%\nThis transmitter will not access the channel if its queue is empty.\nThen, we use the function $\\ind\\{Q(\\cdot) > 0\\}$ that is $1$ if the queue is non-empty, and $0$ otherwise.\n%\n% Let $T^*$ be a \\textit{thinning} of $T$ without the points for which the queue is empty, i.e., $T^* = T^{(\\ind\\{Q(\\cdot)>0\\})}$.\n%\nWe also define a \\textit{measurable} success function $f_s:\\T\\to[0,1]$ that represents the probability for which a transmission is successful at a given time.\n%\nSupposing the transmission time is $\\tau>0$, a simple form to define a queue process is using the \\textit{thinning} of the point process $T$ through the functions $f_s$ and $\\ind\\{Q(\\cdot) > 0\\}$. Then,\n\\begin{align} \\label{eq:def_queue}\n    Q(t+\\tau) = Q(t) + A(t,t+\\tau] - T^{(\\ind\\{Q(\\cdot) > 0\\} f_s)}(t-\\tau,t], \\qquad \\text{for every} ~ t\\in\\T.\n\\end{align}\n\nA handful theorem to calculate the mean delay in queueing systems is known as Little's law \\cite{little1961proof}, which is stated below.\n\n\\begin{theorem}[\\textbf{Little's law}] \\label{th:little}\n    For a queueing system\\footnote{A queueing system is represented by a collection of queues $\\{Q_1(t), Q_2(t), \\dots\\}_{t\\in\\T}$ and we assume the arrival and departure processes are strictly jointly stationary.}, $L = a\\,W$ holds, where $L$ is the time average of the number of packets in the system, $a$ is the average number of packets that arrived per unit of time, and $W$ is the average time each packet waited in the system.\n    \n    For a queue $\\{Q(t)\\}_{t\\in\\T}$, $\\T=[0,\\infty)$, these quantities are given by\\footnote{For general \\textit{measure space} $(\\T,\\cal{B}(\\T),\\mu_T)$, take the integrals in respect to the measure $\\mu_\\T$.}\n    \\begin{align*}\n        L = \\lim_{\\tau\\to\\infty} \\frac{1}{\\tau} \\int_0^\\tau Q(t)\\,\\d t,\n        \\quad\n        a = \\lim_{\\tau\\to\\infty} \\frac{A[0,\\tau]}{\\tau},\n        \\quad\n        W = \\lim_{\\tau\\to\\infty} \\frac{1}{A[0,\\tau]} \\int_0^\\tau Q(t)\\,\\d t,\n    \\end{align*}\n    from which $L = a\\,W$ immediately follows.\n\\end{theorem}\n\nUsually it is easier to calculate the mean number of packets and the mean arrival rate of packets in the system. Then, using Little's law, the mean delay is easily obtained from those.\n\nNow, we present the important concept of stability in a queueing system. Let us adopt the definition used by Szpankowski \\cite{szpankowski1994stability}, presented next.\n\n\\begin{definition}[\\textbf{Stability}] \\label{def:stability}\n\tA queue $\\{Q(t)\\}_t$ is stable if for $x\\in\\N$\n    \\begin{equation*}\n    \t\\lim_{t\\to\\infty} \\P(Q(t) \\le x)\n    \t    = F(x) \\quad\\text{and}\\quad \\lim_{x\\to\\infty} F(x) = 1,\n    \\end{equation*}\n    where $F:\\R_+\\longrightarrow[0,1]$ is the limiting distribution function.\n    \n    A queueing system $\\{Q_1(t), Q_2(t), \\dots\\}_t$ is stable if, for every $i$, each queue $\\{Q_i(t)\\}_t$ is stable \\textit{almost surely}.\n    %\n    % Then, the \\textit{stability region} is the set of mean arrival rates $\\bm{a} = (a_1, a_2, \\dots)$ that makes the queueing system stable.\n\\end{definition}\n\nMore succinctly, we can say a queueing system is stable if it admits a \\textit{proper} limiting distribution.\n%\nAn important form to verify whether a queue or a queueing system is stable is through the following theorem, known as Loyne's theorem \\cite{loynes1962stability}.\n\n\\begin{theorem}[\\textbf{Loyne's theorem}] \\label{th:loynes}\n    Let $\\{Q(t)\\}_{t\\in\\T}$ as defined in \\eqref{eq:def_queue} be a queue with ergodic arrival and access point processes $A$ and $T$, respectively, and success function $f_s$.\n    %\n    Let \\vspace{-5mm}\n    \\begin{align*}\n        \\rho\\triangleq \\displaystyle\\lim_{t\\to\\infty}\\frac{\\E[A[0,t)]}{\\E[T^{(f_s)}[0,t)]}.\n    \\end{align*}\n    \n    If $\\rho < 1$, then the queue $\\{Q(t)\\}_t$ is stable.\n\\end{theorem}\n\nIn fact, Loyne's theorem is more general and deep than what we stated here.\n%\nIt guarantees existence and uniqueness of the delay distribution and deals with the cases $\\rho=1$ and $\\rho>1$.\n%\nHowever, for our purposes, the above statement is enough.\n\nA queue that is evoked throughout the thesis is the Geo/Geo/1 queue. The definition follows.\n%\n\\begin{definition}[\\textbf{Geo/Geo/1}] \\label{def:geo/geo/1}\n    The Geo/Geo/1 queue is a queue $\\{Q(t)\\}_{t\\in\\T}$, as defined in \\eqref{eq:def_queue}, for which we have $\\T=\\N$, $A$ and $T$ are discrete Bernoulli point processes\\footnote{A discrete Bernoulli point process $\\Phi$ is a point process on a discrete set $\\T$, such that, for every $t\\in\\T$, $\\Phi(\\{t\\})$ follows iid Bernoulli distributions.} on $\\T$, $f_s$ is a constant function, and $\\tau = 1$.\n    \n    We let the constants $a,p,p_s\\in[0,1]$ represent the arrival rate, access rate and success probability. More precisely, for every $t\\in\\T$, $A(\\{t\\})\\sim\\mathscr{B}(a)$, $T(\\{t\\})\\sim\\mathscr{B}(p)$, and $f_s \\equiv p_s$.\n\\end{definition}\n\nThe delay and the distribution of the elements of this queue at stationary are given by the following theorem.\n\n\\begin{theorem} \\label{th:geo/geo/1}\n    Let $\\{Q(t)\\}_t$ be a \\textrm{Geo/Geo/1} queue.\n    %\n    If this queue satisfies the conditions of the Loyne's theorem, i.e., $\\rho = a/(p\\,p_s) < 1$.\n    %\n    Then, the stationary distribution of the number of elements in the queue is given by\n    \\[  \\lim_{t\\to\\infty} \\P\\big(Q(t)=n\\big) =\n        \\begin{cases}\n            \\dfrac{\\rho\\,(1-\\rho)}{\\rho-a}\\left(\\dfrac{\\rho-a}{1-a}\\right)^n, & n\\in\\N^*\\\\\n            1-\\rho, & n = 0.\n        \\end{cases}\n    \\]\n    \n    Furthermore, from Little's law, the average time each packet waits in the system is\n    \\begin{align*}\n        W = \\lim_{t\\to\\infty}\\frac{\\E[Q(t)]}{a} = \\frac{\\rho}{a}\\, \\frac{1-a}{1-\\rho} = \\frac{1-a}{p\\,p_s - a}.\n    \\end{align*}\n\\end{theorem}\n\n", "meta": {"hexsha": "a3f13c58d6b74dee7ccc5607ce3c4f72ecaa4aaa", "size": 9564, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix.tex", "max_stars_repo_name": "pliniodester/PhD_thesis", "max_stars_repo_head_hexsha": "65b00b31ebdac9dda68b1e83e937fcaed92ce354", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Appendix.tex", "max_issues_repo_name": "pliniodester/PhD_thesis", "max_issues_repo_head_hexsha": "65b00b31ebdac9dda68b1e83e937fcaed92ce354", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Appendix.tex", "max_forks_repo_name": "pliniodester/PhD_thesis", "max_forks_repo_head_hexsha": "65b00b31ebdac9dda68b1e83e937fcaed92ce354", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.4037267081, "max_line_length": 433, "alphanum_fraction": 0.671371811, "num_tokens": 3049, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.9073122276263202, "lm_q1q2_score": 0.7375244569118409}}
{"text": "%================================\n\\section{The Definition of Topological Space}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\tLet $X$ be a set. A \\textit{topological} on $X$ is a collection $\\mathcal T \\in \\mathcal P(X)$ with the following properties.\n\t\\begin{enumerate}[T1.]\n\t\t\\item $\\mathcal T$ is closed under arbitrary union;\n\t\t\\item $\\mathcal T$ is closed under finite intersection;\n\t\t\\item $X \\in \\mathcal T$.\n\t\\end{enumerate}\n\t\n\tThe \\textit{Topological Space} $(X, \\mathcal T)$ is a set $X$ with a topology $\\mathcal T$ on $X$. All $\\mathcal T$-sets are said to be \\textit{open} in $(X, \\mathcal T)$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{lemma}\n\t$\\emptyset \\in \\mathcal T$.\n\\end{lemma}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proof}\n\tBy T1, given $I$ as any index set, if for all $i \\in I$, $U_i \\in \\mathcal T$, then\n\t$$\n\tU = \\bigcup_{i \\in I} U_i \\in \\mathcal T.\n\t$$\n\tIf $I = \\emptyset$, then $U = \\emptyset$.\n\\end{proof}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tLet $X = \\{1,2,3\\}$ with topology\n\t$$\n\t\\mathcal T = \\big\\{ \\{1,2\\}, \\{3\\} \\big\\}.\n\t$$\n\t$\\{1,2\\} \\in \\mathcal T$ implies $\\{3\\} = X \\setminus \\{1,2\\}$ is closed; $\\{3\\} \\in \\mathcal T$ implies that $\\{1,2\\} = X \\setminus \\{3\\}$ is closed. $\\{2\\} \\in \\mathcal P(X)$, but $\\{2\\} \\notin \\mathcal T$, so $\\{2\\}$ is not open in $(X, \\mathcal T)$, $\\{1,3\\} = X \\setminus \\{2\\}$ is not closed. For any $U \\in \\mathcal T$, $\\{2\\} \\ne X \\setminus U$, so $\\{2\\}$ is not open.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\tGiven $(X, \\rho)$ as a metric space, the topology\n\t$$\n\t\\mathcal T_\\rho = \\left\\{U \\in \\mathcal P(X) : U = \\bigcup_{x \\in U} B(x, \\delta)\\right\\},\n\t$$\n\tthen we call $\\mathcal T_\\rho$ the topology \\textit{induced} by $\\rho$, and $(X, \\mathcal T_\\rho)$ the \\textit{underlying topological space} of metric space $(X, \\rho)$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tThese topology is induced by metric.\n\t%--------------------------------\n\t\\begin{enumerate}\n\t\t%--------------------------------\n\t\t\\item In this case, $U$ is open in $(X, \\rho)$ iff $U \\in \\mathcal T_\\rho$.\n\t\t%--------------------------------\n\t\t\n\t\t%--------------------------------\t\n\t\t\\item The metric $\\rho_p :\\mathbb R \\times \\mathbb R^n \\to \\mathbb R_{> 0}$ (surjective) induces $\\mathcal T_{\\rho_p} \\subseteq \\mathcal P(X)$. And we'll see that for all $p, q \\ge 1$, $\\mathcal T_{\\rho_p} = \\mathcal T_{\\rho_q}$.\n\t\t%--------------------------------\n\t\t\n\t\t%--------------------------------\n\t\t\\item The discrete topology $\\rho_\\mathrm{disc} : X \\times X \\to \\mathbb R_{> 0}$ (non-sujective) induces $\\mathcal T_{\\rho_\\mathrm{disc}} = \\mathcal P(X)$. It is the largest topology on $X$, and $\\rho[X \\times X] \\subseteq \\{0,1\\}$.\n\t\t%--------------------------------\n\t\t\n\t\t%--------------------------------\n\t\t\\item The metric $\\rho_p: C[a,b] \\times C[a,b] \\to \\mathbb R_{>0}$ (surjective) induces $\\mathcal T_{\\rho_p} \\subseteq \\mathcal P(X)$. And we'll see that $\\mathcal T_{\\rho_1} \\ne \\mathcal {T}_{\\rho_\\infty}$.\n\t\t%--------------------------------\n\t\t\n\t\t%--------------------------------\n\t\t\\item Given $X$ as a space, the Hausdorff metric $\\rho_H: \\mathcal P(X) \\times \\mathcal P(X) \\to \\mathbb R_{>0}$ (surjective) induces $\\mathcal T_{\\rho_H} \\subseteq \\mathcal P(\\mathcal P(X))$.\n\t\t%--------------------------------\n\t\t\n\t\t%--------------------------------\n\t\t\\item Given $A$ as a set, the hamming metric $\\rho: A^n \\times A^n \\to \\mathbb R_{> 0}$ (non-surjective) with $n \\in \\mathbb N$ induces $\\mathcal T_\\rho \\subseteq \\mathcal P(X)$. $\\rho[A^n \\times A^n] = \\mathbb N_{\\le n}$.\n\t\t%--------------------------------\n\t\\end{enumerate}\n\t%--------------------------------\n\t\n\tThese topology is not induced by any metric.\n\t%--------------------------------\n\t\\begin{enumerate}\n\t\t%--------------------------------\n\t\t\\item The indiscrete topology $\\mathcal T = \\{\\emptyset, X\\}$ on $X$ is not induced by any metric space. Suppose it was, then there would be a metric $\\rho$ such that for all $x \\in X$, for all $\\varepsilon > 0$, $B(x, \\varepsilon) \\in \\mathcal T$. But, clearly, for those $\\varepsilon \\in (0, \\phi X)$, $B(x, \\varepsilon) \\notin \\mathcal T$.\n\t\t%--------------------------------\n\t\t\n\t\t%--------------------------------\n\t\t\\item Let $X = \\{1,2,3\\}$ with topology\n\t\t$$\n\t\t\\mathcal T = \\big\\{ \\{1,2\\}, \\{3\\} \\big\\}.\n\t\t$$\n\t\tThese is no such metic $\\rho$ induces $\\mathcal T$ for same reason.\n\t\t%--------------------------------\n\t\\end{enumerate}\n\t%--------------------------------\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\tLet $X$ be a set and $\\mathcal T, \\mathcal T'$ be topologies on $X$. If $\\mathcal T \\subseteq \\mathcal T'$, then we say that $\\mathcal T'$ is \\textit{finer} than $\\mathcal T$, or $\\mathcal T$ is \\textit{coarser} than $\\mathcal T'$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note} \\\n\t\\begin{enumerate}\n\t\t%--------------------------------\n\t\t\\item Given $X$ as a set, for all topology $\\mathcal T$ on $X$, $\\mathcal T \\subseteq \\mathcal T_\\mathrm{disc}$ and $\\mathcal T \\supseteq \\mathcal T_\\mathrm{indisc}$, Thus, $\\mathcal T_\\mathrm{disc}$ is the finest topology on $X$, and $\\mathcal T_\\text{indisc}$ is the coarsest.\n\t\t%--------------------------------\n\t\t\n\t\t%--------------------------------\n\t\t\\item $\\rho_p$ and $\\rho_\\text{disc}$ induced same topology on $\\mathbb Z$. But on $\\mathbb Q$, $\\mathcal T_{\\rho_p}$ is coarser than $\\mathcal T_{\\rho_\\text{disc}}$.\n\t\t%--------------------------------\n\t\\end{enumerate}\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\tGiven $(X, \\mathcal T)$ as a topological space, a set $V \\subseteq X$ is said to be \\textit{closed} in $(X, \\mathcal T)$ iff $X \\setminus V \\in \\mathcal T$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition} \\\n\t\\begin{enumerate}\n\t\t\\item In the discrete topology on $X$, all subsets are closed. Because for all $U \\in \\mathcal T_\\text{disc}$, $X \\setminus U \\in \\mathcal T_\\text{disc}$.\n\t\t\\item In the indiscrete topology on $X$, only $\\emptyset$ and $X$ is closed.\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{lemma}\n\tLet $X = (X, \\mathcal T)$ be a topological space, and let\n\t$$\n\t\\mathcal C = \\left\\{ V \\subseteq X : V = X \\setminus U , \\; U \\in \\mathcal T\\right\\}.\n\t$$\n\t\\begin{enumerate}[(i)]\n\t\t\\item $\\mathcal C$ is closed under arbitrary intersection;\n\t\t\\item $\\mathcal C$ is closed under finite intersection;\n\t\t\\item $\\emptyset, X \\in \\mathcal C$.\n\t\\end{enumerate}\n\\end{lemma}\n%--------------------------------\n\n%--------------------------------\n\\begin{proof} \\\n\t\\begin{enumerate}[(i).]\n\t\t\\item By De Morgan's laws,\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\tV = X \\setminus \\bigcup_{i \\in I} U_i = \\bigcap_{i \\in I} (X \\setminus U_i).\n\t\t\\end{aligned}\n\t\t$$\n\t\tSo, if $U_i \\in \\mathcal T$, then $V \\in \\mathcal C$.\n\t\t\n\t\t\\item By De Morgan's laws,\n\t\t\t$$\n\t\t\tV = X \\setminus \\bigcap_{i = 1}^n U_i = \\bigcup_{i = 1}^n (X \\setminus U_i).\n\t\t\t$$\n\t\t\t\n\t\t\\item \n\t\t\t$$\n\t\t\t\\emptyset = X \\setminus X, \\; X = X \\setminus \\emptyset.\n\t\t\t$$\n\t\\end{enumerate}\n\\end{proof}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\tLet $(X, \\mathcal T)$ be a topological space, and let $x \\in X$. An \\textit{open neighbourhood} of $x$ is a set $N_x \\in \\mathcal T$ with $x \\in N_x$. A \\textit{neighbourhood} of $x$ is any $N_x' \\supseteq N_x$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tGiven $(X, \\mathcal T)$ as a topological space. If $A \\in \\mathcal T$,\n\t$$\n\tA = \\bigcup_{x \\in A} B, \\quad B \\in x, \\text{ and } B \\in \\mathcal T.\n\t$$\n\tIf $\\mathcal T = \\mathcal T_\\rho$ for some metric $\\rho$ on $X$, then $A \\in \\mathcal T$ implies\n\t$$\n\tA= \\bigcup_{x \\in A} B(x, \\varepsilon)\n\t$$\n\tfor some $\\varepsilon > 0$.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{lemma}\n\tLet $(X, \\mathcal T)$ be a topological space and $U \\subseteq X$. Then $U \\in \\mathcal T$ iff for all $x \\in U$, there is a neighbourhood $N_x' \\subseteq U$.\n\\end{lemma}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proof}\n\tIf $U \\ni x$ and $U \\in \\mathcal T$, then $U$ is an open neighbourhood of $x$, naturally, it is a neighbourhood of $x$.\n\t\n\tFor only if, clearly, if for all $x \\in U$, there is a neighbourhood $N_x' \\subseteq U$, then, by definition, there is $N_x \\subseteq N_x'$ with $N_x \\in \\mathcal T$. Now we have $x \\in N_x \\subseteq N_x' \\subseteq U$, then,\n\t$$\n\tU = \\bigcup_{x \\in U} N_x.\n\t$$\n\tBy definition, $\\mathcal T$ is closed under arbitrary union, thus $U$ is open.\n\\end{proof}\n%--------------------------------\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n%\n", "meta": {"hexsha": "d66adebe6598d9ddbb6bc001bd559929f86b0fc2", "size": 9083, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-by-tom-leinster/c1_topological-space/s2_the-definition-of-topological-space.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-by-tom-leinster/c1_topological-space/s2_the-definition-of-topological-space.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-by-tom-leinster/c1_topological-space/s2_the-definition-of-topological-space.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.5166051661, "max_line_length": 378, "alphanum_fraction": 0.4900363316, "num_tokens": 2840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.8128673223709252, "lm_q1q2_score": 0.7375244498200104}}
{"text": "\\section{Adam, Momentum etc}\n\\subsubsection{Momentum Mini-Batch}\nThen we are going to introduce the momentum method to accelerate the gradient method.  \n{\\bf Without special statement, the general setup for those next algorithms are the same to Mini-Batch}\n\n\\begin{algorithm}[H]\n\\caption{Momentum Mini-Batch}\n\\label{alg:mom}\n{\\bf Input}: momentum coefficient $\\alpha$(we often choose as: 0.5, 0.9, 0.999) \\\\\nCompute the gradient on $B_{i_t}$:\n$$\ng_t = \\nabla_{w} \\frac{1}{m} \\sum_{i \\in B_{i_t}} f_i(w_{t}).\n$$\nCompute the momentum:\n\\begin{equation}\nv_t = \\alpha v_{t-1} - \\eta_t g_t \\quad (v_0 = 0).\n\\end{equation}\nUpdate $w$:\n\\begin{equation}\nw_{t+1} = w_t + v_t.\n\\end{equation}\n\\end{algorithm}\n\n\\subsubsection{Nesterov Momentum Mini-Batch Method}\nWe may also use the Nesterov accelerated skill and get the Nesterov momentum Mini-Batch method.\n\\begin{algorithm}[H]\n\\caption{Nesterov Momentum Mini-Batch}\n\\label{alg:Nesterov}\n{\\bf Input}: momentum coefficient $\\alpha$\\\\\nCompute the gradient on $B_{i_t}$:\n$$\ng_t = \\nabla_{w} \\frac{1}{m} \\sum_{i \\in B_{i_t}} f_i(w_{t} + \\alpha v_{t-1}) \\quad (v_0 = 0).\n$$\nCompute the momentum:\n\\begin{equation}\nv_t = \\alpha v_{t-1} - \\eta_t g_t.\n\\end{equation}\nUpdate $w$:\n\\begin{equation}\nw_{t+1} = w_t + v_t.\n\\end{equation}\n\\end{algorithm}\n\n\n\\subsection{Adaptive Learning Rate Mini-batch Based Method}\nThe delta-bar-delta algorithm (Jacobs, 1988) is an early heuristic approach to adapting individual learning rates for model parameters during training. The approach is based on a simple idea: if the partial derivative of the loss, with respect to a given model parameter, remains the same sign, then the learning rate should increase. If the partial derivative with respect to that parameter changes sign, then the learning rate should decrease. Of course, this kind of rule can only be applied to full batch optimization. More recently, a number of incremental (or mini-batch-based) methods have been introduced that adapt the learning rates of model parameters.\n\n\\subsubsection{AdaGrad}\nThe AdaGrad algorithm, individually adapts the learning rates of all model parameters by scaling them inversely proportional to the square root of the sum of all of their historical squared values (Duchi et al., 2011).  \n\\begin{algorithm}[H]\n\\caption{AdaGrad}\n\\label{alg:AdaGrad}\n{\\bf Input}: small constant $\\delta$(perhaps $10^{-7}$, for numerical stability)\\\\\nCompute the gradient on $B_{i_t}$:\n$$\ng_t = \\nabla_{w} \\frac{1}{m} \\sum_{i \\in B_{i_t}} f_i(w_{t}).\n$$\nAccumulate squared gradient:\n\\begin{equation}\nr_t = r_{t-1} + g_t \\otimes g_t. \\quad (r_0 = 0),\n\\end{equation}\nwith $\\otimes$ means multiplication element-wise.  \\\\\nCompute Update:\n\\begin{equation}\n\\Delta w_t = -\\frac{\\eta_t}{\\delta + \\sqrt{r_t}} \\otimes g_t,\n\\end{equation}\nwith division and square root applied element-wise. \\\\\nUpdate $w$:\n\\begin{equation}\nw_{t+1} = w_t + \\Delta w_t.\n\\end{equation}\n\\end{algorithm}\n\n\\subsubsection{RMSProp}\nThe RMSProp algorithm (Hinton, 2012) modifies AdaGrad to perform better in the non-convex setting by changing the gradient accumulation into an exponentially weighted moving average. \n\n\\begin{algorithm}[H]\n\\caption{RMSProp}\n\\label{alg:RMSProp}\n{\\bf Input}: decay rate $\\rho$, small constant $\\delta$(usually $10^{-6}$)\\\\\nCompute the gradient on $B_{i_t}$:\n\\begin{equation}\ng_t = \\nabla_{w} \\frac{1}{m} \\sum_{i \\in B_{i_t}} f_i(w_{t}).\n\\end{equation}\nAccumulate squared gradient:\n\\begin{equation}\nr_t = \\rho r_{t-1} + (1-\\rho)g_t \\otimes g_t. \\quad (r_0 = 0),\n\\end{equation}\nCompute update:\n\\begin{equation}\n\\Delta w_t = -\\frac{\\eta_t}{\\sqrt{\\delta + {r_t}}} \\otimes g_t\n\\end{equation}\nUpdate $w$:\n\\begin{equation}\nw_{t+1} = w_t + \\Delta w_t.\n\\end{equation}\n\\end{algorithm}\n\nAnd if we combine RMSProp  with Nesterov momentum, we can get:\n\n\\begin{algorithm}[H]\n\\caption{RMSProp with Nesterov momentum}\n\\label{alg:RMSPropNesterov}\n{\\bf Input}: decay rate $\\rho$, momentum coefficient $\\alpha$\\\\\nCompute the gradient on $B_{i_t}$:\n\\begin{equation}\ng_t = \\nabla_{w} \\frac{1}{m} \\sum_{i \\in B_{i_t}} f_i(w_{t} + \\alpha v_{t-1}), \\quad (v_0 = 0).\n\\end{equation}\nAccumulate squared gradient:\n\\begin{equation}\nr_t = \\rho r_{t-1} + (1-\\rho)g_t \\otimes g_t. \\quad (r_0 = 0),\n\\end{equation}\nCompute velocity update:\n\\begin{equation}\nv_t = \\alpha v_{t-1} -\\frac{\\eta_t}{\\sqrt{{r_t}}} \\otimes g_t\n\\end{equation}\nUpdate $w$:\n\\begin{equation}\nw_{t+1} = w_t + v_t.\n\\end{equation}\n\\end{algorithm}\n\n\\subsubsection{Adam}\nAdam (Kingma and Ba, 2014) is yet another adaptive learning rate optimization algorithm, and its name ``Adam'' derives from the phrase \\emph{Adaptive Moment Estimation}, which adapt both learning rate $\\eta$ and subgradient $g$.\nUse moving average of both $g$ and $g^2$ (here $g^2$ indicates the element-wise square $g \\bigodot g$) to compute first order moment vector\n\\begin{equation}\nm_t  =\\beta_1 m_{t-1} + (1-\\beta_1) g_t=(1-\\beta_1)\\sum_{i=1}^{t}\\beta_1^{t-i} g_i ,\n\\end{equation}\nand second order moment vector\n\\begin{equation}\nv_t  =\\beta_2 v_{t-1} + (1-\\beta_2) g_t^2=(1-\\beta_2)\\sum_{i=1}^{t}\\beta_2^{t-i} g^2_i.\n\\end{equation}\nHere $\\beta_1 = 0.9$, $\\beta_2 = 0.99$.\n\nSince\n\\begin{align}\n\\mathbb{E} \\left[ m_t \\right] & =\\mathbb{E} \\left[ g_t \\right] \\cdot (1-\\beta_1^t) +\\zeta\\\\\n\\mathbb{E} \\left[ v_t \\right] & =\\mathbb{E} \\left[ g^2_t \\right] \\cdot (1-\\beta_2^t) +\\zeta.\n\\end{align}\nHere $\\zeta=0$ if the true moment is stationary.\nSo, we use a bias-corrected version here\n\\begin{align}\n\\tilde{m}_t=\\frac{m_t}{1-\\beta_1^t} \\\\\n\\tilde{v}_t=\\frac{v_t}{1-\\beta_2^t}.\t\n\\end{align}\n\nThe iterate can be written as \n\\begin{equation}\\label{Adam}\nw_{t+1}=w_t-\\frac{\\eta}{\\sqrt{\\tilde{v}_t}+\\delta} \\tilde{m}_t.\n\\end{equation}\n\n\n\\begin{algorithm}[H]\n\\caption{Adam}\n\\label{alg:Adam}\n{\\bf Input}: small constant $\\delta$ (can be $10^{-8}$), decay rate for moment estimates $\\rho_1$ and $\\rho_2$ (suggested defaults: 0.9 and 0.999 respectively)\\\\\nCompute the gradient on $B_{i_t}$:\n\\begin{equation}\ng_t = \\nabla_{w} \\frac{1}{m} \\sum_{i \\in B_{i_t}} f_i(w_{t}).\n\\end{equation}\nUpdate biased first moment estimate:\n\\begin{equation}\nm_t = \\rho_1 m_{t-1} + (1-\\rho_1)g_t, \\quad (m_0 = 0).\n\\end{equation}\nUpdate biased second moment estimate:\n\\begin{equation}\nv_t = \\rho_2 v_{t-1} + (1-\\rho_2)g_t \\otimes g_t, \\quad (v_0 = 0).\n\\end{equation}\nCorrect bias in first moment:\n\\begin{equation}\n\\tilde m_t = \\frac{m_t}{1 - \\rho_1^{t}}.\n\\end{equation}\nCorrect bias in second moment:\n\\begin{equation}\n\\tilde v_t = \\frac{v_t}{1 - \\rho_2^{t}}.\n\\end{equation}\nCompute update:\n\\begin{equation}\n\\Delta w_t =  -\\frac{\\eta_t}{\\sqrt{\\tilde v_t} + \\delta} \\otimes \\tilde m_t\n\\end{equation}\nUpdate $w$:\n\\begin{equation}\nw_{t+1} = w_t + \\Delta w_t.\n\\end{equation}\n\\end{algorithm}\n\n\\subsection{For linear problems}\nNow we apply Adam for the following SPD linear system\n\\begin{equation}\n\tA u-b=0\n\\end{equation}\nwhere $A \\in \\mathbb{R}^{n \\times n}$ is \\emph{symmetric positive definite} matrix and $b \\in \\mathbb{R}^n$.\nIt is equal to solve the following minimization problem\n\\begin{equation}\n\t\\min_u\\ \\left\\{f(u):= \\frac{1}{2} u^T Au - b^T u\\right\\}.\n\\end{equation}\n\nAssume that we didn't take stochastic technique into consideration, then\n\\begin{equation}\ng_k=A u_k-b.\n\\end{equation}\nCompute first order moment vector\n\\begin{align}\nm_k & = \\beta_1 m_{k-1} +(1-\\beta_1) g_k\\\\\n&= \\beta_1 m_{k-1} + (1-\\beta_1) (A u_k - b)\n\\end{align}\nThe update can be written as\n\\begin{equation}\nu_{k+1}=u_k-\\eta P^{-1}_k R_k\n\\end{equation}\nwhere\n\\begin{align}\nR_k & =\\frac{1-\\beta_1}{1-\\beta_1^k} \\sum_{i=1}^{k} \\beta_1^{k-i} (A u_i -b)\\\\\n& = \\frac{(1-\\beta_1) \\beta_1^{(k-1)}}{1-\\beta_1^k} (Au_1 -b) + \\frac{(1-\\beta_1) \\beta_1^{(k-2)}}{1-\\beta_1^k} (Au_2 -b) +\\cdots \\\\\n& +\\frac{(1-\\beta_1) \\beta_1^{0}}{1-\\beta_1^k} (Au_k -b) \\\\\n& =c_1 (Au_1-b) + c_2(Au_2-b) + \\cdots + c_k (Au_k-b).\n\\end{align}\nHere\n\\begin{equation}\nc_i = \\frac{(1-\\beta_1) \\beta_1^{(k-i)}}{1-\\beta_1^k}\n\\end{equation}\nis increase geometrical sequence. \nAnd we can easily draw the conclusion that\n\\begin{equation}\n\\sum_{i=1}^{k} c_i =1.\n\\end{equation}\nSo $R_k$ is weighted average of $\\left\\{u_1, u_2, \\dots, u_k\\right\\}$.\n\n$P_k$ is a diagonal matrix\n\\begin{align}\nP_k & =\\text{diag} \\left\\{\n\\sqrt{ \\frac{1-\\beta_2}{1-\\beta_2^k} \\sum_{i=1}^{k} \\beta_2^{k-i} (A u_i -b)^2 }+\\epsilon \n\\right\\}\\\\\n& = \\text{diag} \\left\\{ p_1, p_2, \\cdots, p_n \\right\\},\n\\end{align}\nwhere $(Au_i -b)^2$ is element-wise product.\n$p_i^2$ is weighted average of $(A u_i-b)^2$.\n\nTo simplify our analysis, we will use $A u_k - b$ instead of $R_k$, as well as\n\\begin{equation}\n\tP_k=\\text{diag} \\left\\{ |A u_k-b| \\right\\}\n\\end{equation}\n\n\nAssume $u^*$ is the solution of $Au-b=0$.\nSo\n\\begin{equation}\nu^* = u^* + \\eta P^{-1} (A u^* -b)\n\\end{equation}\nAnd\n\\begin{equation}\nu^* -u_k = (I- \\eta P_k^{-1} A) (u^* - u_k)\n\\end{equation}\nWe need estimate the upper bound of $\\|I-\\eta P^{-1}_k A\\|$.\n\nIn other way, we will find the relation of ADAM and SDA.\n\n\n\\subsection{Choosing the Right Optimization Algorithm}\nSchaul et al. (2014) presented a valuable comparison of a large number of optimization algorithms across a wide range of learning tasks. While the results suggest that the family of algorithms with adaptive learning rates (represented by RMSProp and Adam) performed fairly robustly, no single best algorithm has emerged.\n\nCurrently, the most popular optimization algorithms actively in use include SGD, SGD with momentum, RMSProp, RMSProp with momentum, AdaDelta and Adam. The choice of which algorithm to use, at this point, seems to depend largely on the user's familiarity with the algorithm (for ease of hyperparameter tuning).\n\n%\\section{Incremental Methods}\n%%\\subsection{Problem setting}\n%Now we consider those kind of problem:\n%\\begin{problem}Find ${x}^{*} \\in \\mathcal{X}$  s.t:\n%\t\\begin{equation}\\label{equ:sum-opt}\n%\t{x}^* = \\mathop{\\arg\\min}_{{x} \\in \\mathcal{X} \\subseteq \\mathbb{R}^{n}} \\frac{1}{N}\\sum_{i=1}^N f_i(x).\n%\t\\end{equation}\n%\tHere $\\mathcal{X}$ is a convex compact subset. (This condition is used\n%\tto prove the gradient is bounded, i.e. $\\|\\nabla f_i(x)\\| \\le M$.)\n%\\end{problem}\n", "meta": {"hexsha": "ddca8f870a45105ab079f493d9c1fba2422ba864", "size": 10053, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/AdamSGD.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/AdamSGD.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/AdamSGD.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6897810219, "max_line_length": 663, "alphanum_fraction": 0.6972048145, "num_tokens": 3586, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.8128673087708698, "lm_q1q2_score": 0.737524445629602}}
{"text": "\\columnbreak\n\n\\section{Maximum Entropy Inference}\n\n% ===\n\\iffalse\n    Max. entropy via $\\partial\\mathcal L / \\partial p(x) {=} 0$.\n    \\quad $\\mathcal L$ given by\n    \\\\\n    $\\sup_{p(X)} \\left\\{ -\\sum_x p(x) \\log p(x) \\right\\}$,\\;\n    s.t. $\\sum_x p(x) = 1$,\\;\n    $p(x) \\geq 0$,\\;\n    $\\sum_x p(x) r_j(x) = \\mu_j, 1\\leq j\\leq m$.\n    \\\\\n    $\\implies$\n    \\emph{Gibbs dist.:}\n    $p(x) {=} \\frac{ \\exp(-\\sum_j \\lambda_j r_j(x)) }{ \\sum_{x'} \\exp(-\\sum_j \\lambda_j r_j(x')) }$\n\\fi\n\nSample $c \\sim p(\\cdot\\mid X)$\\enspace s.t.\\enspace $H[p(\\cdot\\mid x)]$ is maximal, $\\E[C\\mid X]{R(C,X)} = \\mu$ and $\\sum_c p(c\\mid X) = 1$.\n\\\\\n$\\implies$\n\\emph{Gibbs dist.:}\\enspace\n$\\highlight*{p(c\\mid X) = \\frac{1}{Z(X)} \\exp(-\\beta R(c,X))}$\n%$p(c\\vert X) = \\frac{ \\exp(-\\beta R(c,X)) }{ \\sum_{\\tilde c\\in \\mathcal C} \\exp(-\\beta R(\\tilde c,X)) }$%$\\substack{\\\\\\\\ \\eqqcolon Z(X)}$\n\\\\\n\\textbf{Free energy:}\\enspace $F(X) \\coloneqq - \\frac1\\beta \\log Z(X)$ % = -\\frac1\\beta \\log \\sum_c \\eu^{-\\beta R(c,X)}\n\\\\\n$\\iff \\highlight*{p(c\\mid X)} = \\exp\\paren*{-\\beta [R(c,X) - F(X)]}$\n\\\\\n$\\implies$ \\textbf{entropy:}\\enspace $H[c\\mid X] = \\beta \\underbracket[.7pt][.7pt]{\\E[C\\mid X]{R(C,X)}}_{=\\mu} - \\beta F(X)$\n\n\\emph{ME:}\\enspace\n\\highlight*{$\\max H[c\\mid X] \\iff \\max Z(X) \\iff \\min F(X)$}\n\\begin{itemize}\n    \\item Exp. generalisation costs:\\enspace\n        $\\mathbb E_{X''} \\cancelto{\\mathbb E_C}{\\mathbb E_{X'} \\mathbb E}_{C\\mid X'} \\brack{ R(c,X'') }$\n    \\item Min. out-of-sample descr. length per deg. of freedom\\\\\n        $\\min\\limits_{p(\\cdot\\mid\\cdot)} \\mathbb E_{X',X''} \\E*[C\\mid X']{-\\log \\frac{p(c\\mid X'')}{p(c)}}$\\hfill $\\color{gray} p(c) = \\E[X]{p(c\\mid X)}$\\\\\n        \\enspace $\\overset{\\text{Jensen}}{\\geq} \\min_{p(\\cdot\\mid\\cdot)} \\E*[X',X'']{ -\\log \\E[C\\mid X']{p(c\\mid X'')} } - H[c]$\\\\\n        \\enspace $\\overset{\\phantom{\\text{Jensen}}}{=} \\max_{p(\\cdot\\mid\\cdot)} \\E[X',X'']{\\eu^{H[c]} \\cdot \\kappa(X',X'')}$\n\\end{itemize}\n\n%\\emph{Goal:}\n%$p(c\\mid X) \\propto \\exp(-\\frac1T \\mathcal R(c,X))$, \\quad $T>0$\n\n\n%\\todo{Below to be reviewed \\\\\\hfill $\\to$ \\texttt{slt21\\_lecture03\\_notes.pdf}}\n\n\\emph{PA:}\\enspace\n\\highlight*{$T^\\ast = \\arg\\max_T \\kappa(X', X'')$}\n\\begin{itemize}\n    \\item PA-kernel:\\enskip $\\kappa (X', X'') \\coloneqq \\sum_c p(c\\mid X') p(c\\mid X'')$\n    \\item combined:\\enskip $p(c\\mid X', X'') \\propto p(c\\mid X') p(c\\mid X'')$\n\\end{itemize}\n\n% ===\n", "meta": {"hexsha": "ed7821afbbf335c9f122bc67a14b7cdc7bc19891", "size": 2368, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/SLT21/sections/03_max_entropy.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/SLT21/sections/03_max_entropy.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/SLT21/sections/03_max_entropy.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.8275862069, "max_line_length": 155, "alphanum_fraction": 0.551097973, "num_tokens": 1035, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7375005159763802}}
{"text": "\nThe main idea of this project is to extract some characteristic audio data from\nthe signal without having to resort to memory and computationally expensive\nfourier transforms. The 2KiB SRAM of the Arduino is the biggest botleneck here\nfor doing any processing. In order to do this processing, we came up with\nmultiple optimizations. \n\n\\subsection{Optimizations}\n\n\\subsubsection{Cross Correlations} \nInstead of doing a FFT on the data, we will extract a few characteristic\nfrequencies components by correlating the signal with a set of frequencies. The\nexpression for crosscorrelation of 2 discrete signals \\(x,y\\) is given by\n\n\\begin{equation}\n    R_{xy}[k] = \\sum_{i} x[i]y[i-k]\n\\end{equation}\n\nAlong with some normalization. The harmonics form a linearly independent set and\nreturn zero-correlation when the product is integrated over several time periods,\ni.e.\n\n\\begin{equation}\n    \\frac{1}{\\pi} \\int_0^{2\\pi}sin(n_1x)sin(n_2x) = \\delta_{nn'}  \n\\end{equation} \n\nWhere \\(\\delta\\) is the usual Kronecker delta. We can normalize the correlation\nwith the autocorrelation at 0 to get a number between -1 and 1 that\ncharacterized the coefficients.\n\n\\begin{equation}\n    c_{xy} = \\frac{R_{xy}[0]}{\\sqrt{R_{xx}[0]R_{yy}[0]} }\n\\end{equation} \n\nHowever, the above expression does not account for the phase shift \\(\\phi\\)\nbetween the harmonics which reduces the correlation by a factor of\n\\(cos(\\phi)\\)Therefore we modify check the signal with phase shifted test\nharmonics by modifying the expression to:\n\n\\begin{equation}\n    c_{xy} = \\frac{\\mathnormal{max}\\{R_{xy}[k]\\}}{\\sqrt{R_{xx}[0]R_{yy}[0]} }\n\\end{equation}\n\nThis ensures that the loss due to potential phase shift is avoided by getting an\nestimate of the phase. Further, these correlations avoid the complex\nmultiplications required in FFT calculations while giving more characteristic\ndata. \n\n\\subsubsection{Memory Management}\nWe store the signal using an array of 4 bit numbers, i.e. numbers from -7 to 7.\nThis has multiple benefits, such as being able to outright store more numbers,\nand more subtly, perform calculations in a smaller time period as the Arduino\nprocessor is based around an 8-bit bus. Instead of requiring multiple clock\ncycles to process 16 / 32 bit datatypes like \\texttt{float} and \\texttt{int}, we\ncan process the signals much faster.\n\n\\subsubsection{Frequency Space Pruning}\nBeginning with a Dirac comb in frequency space, we prune a lattice tree of the\nfrequency power set via depth first binary search. This bypasses the\ncomputationally expensive cross correlation calculations for a lot of (wrong)\nfrequencies. ", "meta": {"hexsha": "cbdd8fab5115fadc486fa43ebb9f36431476d45e", "size": 2592, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/setup.tex", "max_stars_repo_name": "sankalpgambhir/ardio", "max_stars_repo_head_hexsha": "c70c28ddd00690aab04aeb8f1e84fe90fcdb5d02", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-29T18:00:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-29T18:00:57.000Z", "max_issues_repo_path": "doc/setup.tex", "max_issues_repo_name": "sankalpgambhir/ardio", "max_issues_repo_head_hexsha": "c70c28ddd00690aab04aeb8f1e84fe90fcdb5d02", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/setup.tex", "max_forks_repo_name": "sankalpgambhir/ardio", "max_forks_repo_head_hexsha": "c70c28ddd00690aab04aeb8f1e84fe90fcdb5d02", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.4918032787, "max_line_length": 81, "alphanum_fraction": 0.774691358, "num_tokens": 659, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7375005035325024}}
{"text": "\\subsection{\\acrlong{mdp}}%\n\\label{sub:mdp}\n\nOptimization problem solved using \\gls{mcts} algorithm are modelised as a \\gls{mdp}.\nit modelises the problem as a set of states and actions that can be applies or played on a state.\nA state contains all the information necessary to understand the situation meaning that the past state are irrelevant.\nIn this section, we will give a vulgarize explanation of what a game is and a more definition of a \\gls{mdp}.\n\n\\subsubsection{Sequential problem modelization}%\n\\label{ssub:sequential_problem_modelization}\n\nLet's consider a single player basic game called the \\gls{lmp}.\nIts rules are simple:\n\n\\begin{itemize}\n    \\item Each turn the player can choose \\textit{left}  or \\textit{right}.\n    \\item A player choosing \\textit{left} gain one point.\n    \\item A player choosing \\textit{right} gain no point.\n    \\item The game ends after \\(N\\) turn.\n\\end{itemize}\n\nThe goal of the game is to have as much point as possible at the end.\nIt is a very simple problem but is perfect to explaine the key concept.\nA state of the game can be represented by two elements: the score of the player and the number of turn that passed.\nSo if we define the state \\(s=(6, 10)\\) it means that the player has 6 points and has played 10 turns.\nPast states are irrelevant to describe \\(s\\), it contains all information necessary to describe the situation.\nSome states are called terminal because they correspond to state where the game has ended.\nHere, all the states where the player has played \\(N\\) turns are final or terminal.\n\nThe actions the player can choose are \\textit{left} and \\textit{right}.\nIf the player applies \\textit{left}  to \\(s\\) then, we will obtain a new state \\(s'=(7, 11)\\).\nThe transition from \\(s\\) to \\(s'\\) is always the same if we apply \\textit{left} to \\(s\\).\n\nThe goal being to obtain the most point as possible, a player will learn to always pick \\textit{left}.\nThis is called a policy or, more conviniently, a strategy: it dictates the action according to a situation.\nIn other, if I give \\(s\\) to a player following the policy to always go right, he will choose \\textit{right} and will go to state \\(s''=(6, 11)\\).\n\nThis simply explains the key concepts of a \\gls{mdp}.\nYou have states on which you apply actions.\nApplying certain actions on certain states will give you a new state.\nAnd states have what is called a reward, which is the number of point the player scored.\n\n\\subsubsection{Definition}%\n\\label{ssub:definition}\n\nNow for a more formal definition, a \\gls{mdp} is composed of:\n\n\\begin{itemize}\n    \\item \\(S\\) a set of state.\n    \\item \\(A\\) a set of actions\n        \\begin{itemize}\n            \\item \\(A_{s} \\subseteq A\\) are the legal actions or actions that can be applied to \\(s\\)\n            \\item If \\(A_{s} = \\emptyset\\) then it means that \\(s\\) is a final or terminal state\n        \\end{itemize}\n    \\item \\(P_{a}(s, s') = P(s_{t+1} = s' | s_{t} = s, a_{t} = a)\\) is the probability that when applying action \\(a\\) to state \\(s\\), we obtain state \\(s'\\)\n    \\item \\(R_{a}(s, s')\\) is the reward obtained when transitioning from \\(s\\) to \\(s'\\) by applying action \\(a\\)\n\\end{itemize}\n\nWhen optimizing a \\gls{mdp}, we search for the best policy, that means the policy that will give the best expected reward possible.\nA policy \\(\\pi(s)\\) is a distribution of probability over all the elements of \\(A_s\\).\nA policy that maximizes the reward is called an optimal policy and is often noted \\(\\pi^{*}\\).\n\nA \\gls{mdp} represents a stochastic game if the probabilities given by \\(P_{a}(s, s')\\) are not equal to 1.\nThat is to say, if the transitions between the states are uncertain, therefore random, the modelized problem is stochastic.\n\n", "meta": {"hexsha": "98734926e5459e68219825e2104f0791585f4fa1", "size": 3707, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/report/src/sections/mcts/subs/mdp.tex", "max_stars_repo_name": "XanX3601/stochastic_mcts_optimization", "max_stars_repo_head_hexsha": "743ef3df090427750fee55fd69d7646a88d5946a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "documents/report/src/sections/mcts/subs/mdp.tex", "max_issues_repo_name": "XanX3601/stochastic_mcts_optimization", "max_issues_repo_head_hexsha": "743ef3df090427750fee55fd69d7646a88d5946a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "documents/report/src/sections/mcts/subs/mdp.tex", "max_forks_repo_name": "XanX3601/stochastic_mcts_optimization", "max_forks_repo_head_hexsha": "743ef3df090427750fee55fd69d7646a88d5946a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.1666666667, "max_line_length": 157, "alphanum_fraction": 0.7232263286, "num_tokens": 971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7373939369089356}}
{"text": "\\documentclass[twocolumns]{IEEEtran}\n\\usepackage{algorithm}\n\\usepackage{algpseudocode}\n\\usepackage{graphicx}\n\\usepackage{caption}\n\\usepackage{url}\n\\captionsetup{justification=centering}\n\n\n\\algnewcommand\\algorithmicforeach{\\textbf{for each}}\n\\algdef{S}[FOR]{ForEach}[1]{\\algorithmicforeach\\ #1\\ \\algorithmicdo}\n\n\\author{Erdal Sidal Dogan, Alp Gokcek \\\\ MEF University \\\\ \\today}\n\\title{Dijkstra's Shortest Path Algorithm Implementation \\& Visualization}\n\n\n\\begin{document}\n\t\\maketitle\n\t\\begin{abstract}\n\t\tDijkstra's Shortest Path Algorithm \\cite{dijkstra} is an algorithm which finds the shortest path between two nodes in a graph. It is widely used and adopted for many different applications, such as computer networks, road maps, social platforms etc. In this project we implemented algorithm in Python Language and visualized the shortest path.\n\t\\end{abstract}\n\t\\begin{IEEEkeywords}\n\t\tGraph, Node, Vertex, Edge\n\t\\end{IEEEkeywords}\n\t\\section{Introduction}\n\t\\textit{Dijkstra's Algorithm} calculates the shortest path from one desired node of the graph to every other nodes. There are varios implementations of the algorithm, main difference between them is how they store the verticies of the graph, denoted with $Q$. They can be stored in regular arrays, linked lists, adjacency lists or tree structures.\\cite{524471} Running time of the algorithm can be represented with number of edges $|E|$ and number of verticies $|V|$ using big-o notation. Running time mainly depends on these structures, storing $Q$ in arrays it is $\\mathcal{O}(|V|^2)$. In this project we utilized the \\textit{priority queue} structure while implementing. It is more efficient way to implement comparing to arrays and adjacency lists etc. The \\textit{priority queue} implementation requires $\\mathcal{O}((|E| + |V|) \\log{|V|})$ time in the worst case. \n\t\\begin{algorithm}\n\t\t\\caption{Using a priority queue \\cite{wiki} \\hfill Cost}\n\t\t\\begin{algorithmic}[1]\n\t\t\t\\Function {Dijkstra} {\\textit{Graph, source}}\n\t\t\t\t\\ForEach {vertex \\textbf{v} in \\textit{Graph}}\t\\hfill v + 1\n\t\t\t\t\t\\State $dist[v] \\leftarrow$ INFINITY\t\\hfill v\n\t\t\t\t\t\\State $prev[v] \\leftarrow$ UNDEFINED\t\\hfill v\n\t\t\t\t\t\\State add $v$ to $Q$\t\\hfill v                      \n\t\t\t\t\\EndFor\n\t\t\t\t\\State $dist[source] \\leftarrow$ 0\t\\hfill 1\n\t\n\t\t\t\t\\While {$Q$ is not empty}\t\\hfill v + 1\n\t\t\t\t\t\\State $u \\leftarrow$ vertex in $Q$ with min $dist[u]$\t\\hfill v\n\t\t\t\t\t\\State remove $u$ from $Q$\t\\hfill v\n\t\t\t\t\t\\ForEach {neighbor $v$ of $u$}\t\\hfill $\\sum_{i=0}^{v}(v-i+2)$\n\t\t\t\t\t\t\\State $alt \\leftarrow dist[u] + length(u, v)$ $\\sum_{i=0}^{v}(v-i+1)$\n\t\t\t\t\t\t\\If{alt $<$ dist[v]}\t\\hfill $\\sum_{i=0}^{v}(v-i+2)$\n\t\t\t\t\t\t\t\\State $dist[v] \\leftarrow alt$\t\\hfill $\\sum_{i=0}^{v}(v-i+2)$\n\t\t\t\t\t\t\t\\State $prev[v] \\leftarrow u$\t\\hfill $\\sum_{i=0}^{v}(v-i+2)$\n\t\t\t\t\t\t\\EndIf\n\t\t\t\t\t\\EndFor\n\t\t\t\t\\EndWhile \\\\\n\t\t\t\t\\Return dist[], prev[]\n\t\t\t\\EndFunction\n\t\t\\end{algorithmic}\n\t\\end{algorithm}\n\n\t\\section{The Program}\n\n\tThe program consists a simple and intuitive Graphical User Interface. On the top there are text fields where the user can type de number of nodes, start node and the destination node respectively. Below, there is the path from source to destination and time it took to travel between these nodes. Rest of the application window displays the nodes and emphasizes the shortest path between two given nodes in red color edges.\n\n\t\\begin{figure}[h]\n\t\t\\centering\n\t\t\\includegraphics[scale=.2]{main_window.png}\n\t\\end{figure}\n\t\\captionof{figure}{Main Window of the program for values selected as; N=10, S=1, D=6} \n\t\n\t\\section{Time Measurements}\n\t\n\tAfter the implementation, we measured the time it takes to calculate shortest path from 1 to $N$ in a graph with $N$ number of nodes. We observed a correlation between theory and the practice.\n\tTheoritical results are calculated by the $\\mathcal{O}((|E| + |V|) \\log{|V|})$ which stated in \\textit{Introduction} section previously. Time it takes to run the program depends on the computer it ran on. During our demonstration we used the same machine with same configuration in order to get most accurate results. For different machines the expectation is to get ratios that are closer to ratio of our results. Results can be seen in detail from the figure below; \\\\\n\t\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\includegraphics[scale=.4]{matlab/time_2.eps}\n\t\t\\caption{$|V|$ vs. time (in seconds)}\n\t\\end{figure}\n\n\tNote that theoretical time (showed in green line) doesn't correspond to any value of time, it is put there to emphasize the overall similarities such as curvature and trajectory etc. between actual results and calculated results.\n\t\n\n\t\\section{Conclusion \\& Discussion}\n\tIn this project we implemented \\textit{Dijkstra's Algorithm} using Python. We developed an GUI in order to visualize the graph and the shortest path. After the implementation, we compared our results with the theoritical results. This project helped us to develop a deeper insight about the graphs and the shortest path algorithms.\n\n\t\\bibliographystyle{IEEEtran}\n\t\\bibliography{references}\n\n\\end{document}", "meta": {"hexsha": "03e1527b16fe0d1ad8af05ad816a1dce1ab07f6e", "size": 5025, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/document.tex", "max_stars_repo_name": "alpgokcek/dijkstra-visualization", "max_stars_repo_head_hexsha": "68a1a2812d5bb5dcfc3c579ec049ea11d97908b4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/document.tex", "max_issues_repo_name": "alpgokcek/dijkstra-visualization", "max_issues_repo_head_hexsha": "68a1a2812d5bb5dcfc3c579ec049ea11d97908b4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/document.tex", "max_forks_repo_name": "alpgokcek/dijkstra-visualization", "max_forks_repo_head_hexsha": "68a1a2812d5bb5dcfc3c579ec049ea11d97908b4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-23T08:10:04.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-23T08:10:04.000Z", "avg_line_length": 59.8214285714, "max_line_length": 871, "alphanum_fraction": 0.7351243781, "num_tokens": 1399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.8872045892435128, "lm_q1q2_score": 0.7373939300885483}}
{"text": "\\subsection{Floating Point and Testing}\nNearly all computational research is done using the floating-point arithmetic supplied by the vendor. These days this is normally assumed to conform to the IEEE (binary) floating point system \\cite{IEEE2008}, which specifies the results of a sequence of floating-point operations. This actually \\emph{does} simplify the developers' life (compared to the days of negotiating hexadecimal-based IBM formats etc.), but does \\emph{not} mean that there are no problems with the floating point. \n\n\\begin{enumerate}\n\\item Floating-point may not produce the results the na\\\"\\i{}ve expect:\n\\begin{equation}\\label{eq:plus1}\n\\left(1+10^{20}\\right)-10^{20}=10^{20}-10^{20}=0,\n\\end{equation}\nnot the $1$ one might expect. Of course,\n\\begin{equation}\\label{eq:plus2}\n1+\\left(10^{20}-10^{20}\\right)=1+0=1.\n\\end{equation}\n\\item \\cite{IEEE2008} does specify the result of a sequence of floating-point operations, but the user may not fully specify the sequence! In particular, in most programming languages, \n\\begin{equation}\\label{eq:plus3}\n1+10^{20}-10^{20}\n\\end{equation}\nis ambiguous as to whether it is (\\ref{eq:plus1}) or  (\\ref{eq:plus2}), and therefore the compiler is free to produce 1 or 0. In practice, of course, the code will not be (\\ref{eq:plus3}) but \\verb!a+b+c!, and indeed \\verb!a! etc. will probably be array elements, or expressions themselves. A slight change in \\verb!a! etc., or indeed in the surrounding program, can change which order the compiler chooses to do the additions in, and, as we have seen, change the result.\n\\par\nThis ambiguity is multiplied if our language allows us to write vector or array operations, or if we use parallel operations like MPIs' \\verb+Reduce+\\footnote{See section \\ref{test:parallel}.}.\n\\end{enumerate}\nThis means that it is futile to expect a program to be as deterministic as we would na\\\"\\i{}vely expect. Even a recompilation of an untouched source program can arrange operations differently, and re-running an untouched parallel program can perform additions in a different order. Hence exact reproducibility is impossible, and there isn't necessarily a ``right answer''.\n\\begin{quote}\nSo how do I tell the difference between such legitimate variations and a bug?\n\\end{quote}\nThis is the key question, and the worrying answer is that only an expert can truly know. However, we can give some suggestions.\n\\begin{enumerate}\n\\item Consider \\emph{relative errors} rather than absolute ones, i.e., rather than asking whether $|a-b|$ is small, ask whether $\\frac{|a-b|}{\\max(|a|,|b|)}$ is small.\n\\end{enumerate}\n\n\nSee \\cite{Barba2016b}.\n", "meta": {"hexsha": "1502aac87f97da2c8fe7fa634e9b177d14b2c49c", "size": 2616, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "FloatingPoint.tex", "max_stars_repo_name": "drvinceknight/TestingPaper", "max_stars_repo_head_hexsha": "584eda01789ecc66ef58420dd4fefffbaca35ec5", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2016-03-23T09:07:42.000Z", "max_stars_repo_stars_event_max_datetime": "2016-03-23T21:00:48.000Z", "max_issues_repo_path": "FloatingPoint.tex", "max_issues_repo_name": "drvinceknight/TestingPaper", "max_issues_repo_head_hexsha": "584eda01789ecc66ef58420dd4fefffbaca35ec5", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-04-04T18:33:40.000Z", "max_issues_repo_issues_event_max_datetime": "2016-06-22T17:31:05.000Z", "max_forks_repo_path": "FloatingPoint.tex", "max_forks_repo_name": "drvinceknight/TestingPaper", "max_forks_repo_head_hexsha": "584eda01789ecc66ef58420dd4fefffbaca35ec5", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 81.75, "max_line_length": 488, "alphanum_fraction": 0.7637614679, "num_tokens": 670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8872045907347108, "lm_q1q2_score": 0.7373939276171382}}
{"text": "\n\\input{SingleAssignmentSetup.tex}\n\\input{../WeekTitles.tex}\n\\begin{document}\n\n\\begin{center}\n\\subsection*{MNTC P01 - Week \\#7 - \\WeekTitleSeven}\n\\end{center}\n\n\\begin{enumerate}\n\n\\subsection*{Verifying Solutions}\n% ******************************\n\\item \n\\begin{Question} %9.1 - 1\n  Show that $\\ds y = \\frac{2}{3}\\text{e}^{x} + \\text{e}^{-2x}$ is a solution of the differential equation $y' + 2y = 2\\text{e}^{x}$. \\\\\n\\end{Question}\n\n% 1 - Solution\n\\begin{Solution}\n\\begin{equation*}\ny = \\frac{2}{3}\\text{e}^{x} + \\text{e}^{-2x} \\Rightarrow\ny' = \\frac{2}{3}\\text{e}^{x} - 2\\text{e}^{-2x}\n\\end{equation*}\nTo show that $y$ is a solution of the differential equation, we will substitute the expressions for $y$ and $y'$ in the left-hand side of the equation and show that the left-hand side of the equation and show that the left-hand side is equal to the right-hand side.\n\n\\begin{align*}\n\t\\text{LHS} &= y' + 2y = \\frac{2}{3}\\text{e}^{x} - 2\\text{e}^{-2x} + 2(\\frac{2}{3}\\text{e}^{x} + \\text{e}^{-2x}) \\\\\n\t&= \\frac{2}{3}\\text{e}^{x} - 2\\text{e}^{-2x} + \n\t\\frac{4}{3}\\text{e}^{x} + 2\\text{e}^{-2x} =\n\t\\frac{6}{3}\\text{e}^{x} = 2\\text{e}^{x} \\\\ \n\t&= \\text{RHS}\n\\end{align*}\n\\end{Solution}\n%%%%%%%%%%%%%%%%%%\n\n%9.1 - 3\n\\item\n\\begin{Question}\n\\begin{enumerate}[(a)]\n\\item For what values of $r$ does the function $y = \\text{e}^{rx}$ satisfy the differential equation $2y'' + y' - y = 0$?\n\n\\item If $r_1$ and $r_2$ are the values of $r$ that you found in part (a), show that every member of the family of functions $y = a\\text{e}^{r_{1}x} + b\\text{e}^{r_{2}x}$ is also a solution.\n\\end{enumerate}\n\\end{Question}\n\n\\begin{Solution}\n\\begin{enumerate}[(a)]\n\\item \\begin{equation*}\n\t\ty = \\text{e}^{rx} \\Rightarrow\n\t\ty' = r\\text{e}^{rx} \\Rightarrow\n\t\ty'' = r^2\\text{e}^{rx}\n\t\\end{equation*}\n\tSubstituting these expressions into the differential equation \n\t$2y'' + y' - y = 0$, we get\n\t\\begin{align*}\n\t\t&2r^2\\text{e}^{rx} + r\\text{e}^{rx} - \\text{e}^{rx} = 0 \\\\\n\t\t\\Rightarrow \\quad &(2r^2 + r - 1)\\text{e}^{rx} = 0 \\\\\n\t\t\\Rightarrow \\quad &(2r - 1)(r + 1) = 0\n\t\\end{align*}\n\t(since $\\text{e}^{rx}$ is never zero) $r = \\frac{1}{2}$ or -1.\n\n\\item Let $r_1 = \\frac{1}{2}$ and $r_2 = -1$, so we need to show that every member of the family of functions $y = a\\text{e}^{x/2} + b\\text{e}^{-x}$ is a solution of the differential equation $2y'' + y' - y = 0$.\\\\\n\\begin{align*}\n\t&y = a\\text{e}^{x/2} + b\\text{e}^{-x} \\\\\n\t\\Rightarrow \\quad &y' = \\frac{1}{2}a\\text{e}^{x/2} - b\\text{e}^{-x}\\\\\n\t\\Rightarrow \\quad &y'' = \\frac{1}{4}a\\text{e}^{x/2} + b\\text{e}^{-x}\n\\end{align*}\n\\begin{align*}\n\t\\text{LHS} &= 2y'' + y' - y \\\\ \n\t&= 2(\\frac{1}{4}a\\text{e}^{x/2} + b\\text{e}^{-x}) + (\\frac{1}{2}a\\text{e}^{x/2} - b\\text{e}^{-x}) \\\\ & \\hspace{4mm}- (a\\text{e}^{x/2} + b\\text{e}^{-x}) \\\\\n\t&= \\frac{1}{2}a\\text{e}^{x/2} + 2b\\text{e}^{-x} + \\frac{1}{2}a\\text{e}^{x/2} - b\\text{e}^{-x}  \\\\\n\t& \\hspace{4mm}- a\\text{e}^{x/2} - b\\text{e}^{-x} \\\\\n\t&= (\\frac{1}{2}a + \\frac{1}{2}a - a)\\text{e}^{x/2} + (2b - b -b)\\text{e}^{-x} \\\\\n\t&= 0 \\\\ &= \\text{RHS}\n\\end{align*}\n\\end{enumerate}\n\\end{Solution}\n%%%%%%%%%%%%%%%%%%\n\n%9.1 - 4\n\\item\n\\begin{Question}\n\\begin{enumerate}[(a)]\n\\item For what values of $k$ does the function $y = \\cos(kt)$ satisfy\n  the differential equation $4y'' = -25y$?\n\\item For those values of $k$, verify that every member of the vamily of functions $y = A\\sin kt + B\\cos kt$ is also a solution.\n\\end{enumerate}\n\\end{Question}\n\n\\begin{Solution}\n\\begin{enumerate}[(a)]\n\\item \\begin{equation*}\n\t\ty = \\cos kt \\ \\Rightarrow \\ y' = -k \\sin kt \\ \\Rightarrow \\ y'' = -k^2 \\cos kt\n\t\\end{equation*}\n\tSubstituting expressions into the differential equation $4y'' = -25y$, we get \n\t\\begin{align*}\n\t\t&4(-k^2\\cos kt) = -25(\\cos kt) \\\\\n\t\t\\Rightarrow \\quad &(25 - 4k^2) \\cos kt = 0 (\\text{for all } t)\\\\\n\t\t\\Rightarrow \\quad &25 - 4k^2 = 0 \\\\\n\t\t\\Rightarrow \\quad &k^2 = \\frac{25}{4} \\ \\Rightarrow \\ k = \\pm \\frac{5}{2}\n\t\\end{align*}\n\t\n\\item \\begin{align*}\n\t\t&y = A\\sin kt + B \\cos kt \\\\\n\t\t\\Rightarrow \\quad &y' = Ak\\cos kt - Bk \\sin kt \\\\\n\t\t\\Rightarrow \\quad &y'' = -Ak^2 \\sin kt - Bk^2 \\cos kt\n\t\\end{align*}\n\tThe given differential equation $4y'' = -25y$ is equivalent to $4y'' + 25y = 0$.  Thus,\n\\begin{align*}\n\t\\text{LHS} &= 4y'' + 25y \\\\\n\t&= 4(-Ak^2 \\sin kt - Bk^2 \\cos kt) \\\\\n\t& \\quad + 25(A\\sin kt + B\\cos kt) \\\\\n\t&= -4Ak^2 \\sin kt - 4Bk^2 \\cos kt \\\\\n\t& \\quad+ 25A\\sin kt + 25B \\cos kt \\\\\n\t&= (25 - 4k^2)A\\sin kt + (25 - 4k^2)B\\cos kt \\\\\n\t&= 0 \\hspace{4mm} \\text{since } k^2 = \\frac{25}{4}\n\\end{align*}\n\\end{enumerate}\n\\end{Solution}\n%%%%%%%%%%%%%%%%%%\n\n%9.1 - 7\n\\item\n\\begin{Question}\n  Consider the differential equation $\\ds \\frac{dy}{dx} = -y^2$.\n\\begin{enumerate}[(a)]\n\\item If you were asked whether the solutions to this equation would\n  {\\em increase} or {\\em decrease} as $x$ increased, what could you\n  say based on only the equation itself?\n\\item Verify that all members of the family $y = 1/(x + C)$ are\n  solutions of the equation in part (a).\n\\item Can you think of a (very simple) solution of the differential\n  equation $y' = -y^2$ that is {\\em not} a member of the family in\n  part (b)?\n\\item Find the solution to the initial-value problem\n\\begin{equation*}\n\ty' = -y^2 \\hspace{6mm} y(0) = 0.5\n\\end{equation*}\n\\end{enumerate}\n\\end{Question}\n\\begin{Solution}\n\\begin{enumerate}[(a)]\n\\item Since the derivative of $y' = -y^2$ is always negative (or 0 if\n  $y = 0$), the function $y$ must be {\\bf decreasing} (or maybe\n  horizontal) on any interval on which it is defined.\n\\item We sub in the proposed solution into the original equation.  To do this, we will need the derivative of $y$:  $\\ds y = \\frac{1}{x + C} \\Rightarrow y' = -\\frac{1}{(x + C)^2}$.\\\\\n  $\\text{LHS} = y' = -\\frac{1}{(x + C)^2} = -\\left(\\frac{1}{x + C}\n  \\right)^2 = -y^2 = \\text{RHS}$ Therefore, any function of the form\n  $y(x) = \\frac{1}{x+C}$ {\\bf is} a solution to $y' = -y^2$.\n\\item $y=0$ is a simple solution to $y'=-y^2$ that is not a member of\n  the family in part (b).  We can confirm this by subbing $y=0$ into\n  the DE and checking the LHS equals the RHS.  If $y=0$, then $y'= 0$\n  as well, so $\\text{LHS} = y' = 0 = -y^2 = RHS$.\n\\item We already know that the solutions will be of the form\n  $y(x) = \\frac{1}{x+C}$; we just need to sub in the initial value to\n  solve for $C$.\n\n  If $y(x) = \\frac{1}{x + C}$, then\n  $y(0) = \\frac{1}{0 + C} = \\frac{1}{C}$.  Since $y(0) = 0.5$,\n  $\\frac{1}{C} \\frac{1}{2} \\Rightarrow C = 2$, so $y =\\frac{1}{x + 2}$\n\\end{enumerate}\n\\end{Solution}\n%%%%%%%%%%%%%%%%%%\n\n\\hrulefill\n\n\\subsection*{Numerical ODE Solutions With MATLAB}\n\n\n%*******************************\n\\item\n\\begin{Question}\n  Create a plot for the solution to the differential equation\n  $y' - \\frac{y^2}{x^3} = 0$ if y(2) = 1.  Include a large enough\n  \\verb#xspan# to see the long-term behaviour.\n\\end{Question}\n\n\\begin{Solution}\n  For this first example of use MATLAB to build a numerical solution\n  to a DE, we will show the full listing of a script that generates a\n  solution to the given differential equation.  In later solutions, we\n  will only include the key lines for the MATLAB script.\n\n  Notes: \n  \\begin{itemize}\n  \\item We set \\verb#xspan# to start at 2 in the line\n    \\verb#xspan = [2, 30]#.  This is used because the solution MATLAB\n    is generating will start at the coordinates $x_0$ = first element\n    of \\verb#xspan#, and $y_0$ = \\verb#y0# in the code, and our\n    initial condition is $x = 2$, $y=1$.\n  \\item We find the second value in the time span with some trial and\n    error.  Any value larger than 15 or 20 would be sufficient to show\n    the long-term trend in the solution.\n  \\end{itemize}\n\\lstinputlisting[showstringspaces=false]{MATLAB/W07DE01.m}\n\nLink to the MATLAB code: \\\\\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W07DE01.m}{W07DE01.m}\n\nHere is the graph of the solution.\n\n\\includegraphics[width = 0.5\\linewidth]{graphics/Week07_DESolutions/W07DE01}\n\n    \n\\end{Solution}\n\n\n%*******************************\n\\item\n\\begin{Question}\nCreate a plot for the solution to the differential equation\n  $(2y - 4)y' - 3x^2 = 4x - 4$, if y(1) = 3.\n    \n\\end{Question}\n\n\\begin{Solution}\n  To generate a first-order DE solution in MATLAB, the differential\n  equation must be written first in the form $y' = \\ldots$.\n  \\begin{align*}\n    (2y - 4)y' - 3x^2 & = 4x - 4 \\\\\n    (2y - 4)y' & =  3x^2 +4x - 4 \\\\\n    y' & =  \\frac{(3x^2 +4x - 4)}{(2y - 4)} \\\\\n  \\end{align*}\n    \nLink to the MATLAB code: \\\\\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W07DE02.m}{W07DE02.m}\n\nHere is the graph of the solution.\n\n\\includegraphics[width = 0.5\\linewidth]{graphics/Week07_DESolutions/W07DE02}\n\\end{Solution}\n\n\n%*******************************\n\\item\n\\begin{Question}\nCreate a plot for the solution to the differential equation\n  $y' = e^{-y}(2t - 4)$ if $y(0) = 5$\n    \n\\end{Question}\n\n\\begin{Solution}\n  This DE is already in the form $y' = \\ldots$, so we can input it\n  into MATLAB as-is.  Note that the independent variable in this\n  example is $t$, so we will use that in MATLAB instead of the\n  variable $x$.\n\n\nLink to the MATLAB code: \\\\\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W07DE03.m}{W07DE03.m}\n\nHere is the graph of the solution.\n\n\\includegraphics[width = 0.5\\linewidth]{graphics/Week07_DESolutions/W07DE03}\n\n\n    \n\\end{Solution}\n\n%*******************************\n\\item\n\\begin{Question}\nCreate a plot for the solution to the differential equation\n  $ty' - 2y = t^5 \\sin (2t) - t^3 + 4t^4$, if\n  $y(\\pi) = \\frac{3}{2}\\pi^4$\n    \n\\end{Question}\n\n\\begin{Solution}\n  To generate a first-order DE solution in MATLAB, the differential\n  equation must be written first in the form $y' = \\ldots$.\n  \\begin{align*}\n    ty' - 2y & = t^5 \\sin (2t) - t^3 + 4t^4 \\\\\n    ty' & = 2y + t^5 \\sin(2t) - t^3 + 4t^4 \\\\\n    y' & = \\frac{1}{t} (2y + t^5 \\sin(2t) - t^3 + 4t^4) \\\\\n  \\end{align*}\n    \nLink to the MATLAB code: \\\\\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W07DE04.m}{W07DE04.m}\n\nHere is the graph of the solution.\n\n\\includegraphics[width = 0.5\\linewidth]{graphics/Week07_DESolutions/W07DE04}\n    \nNote that in this example, because of the $\\sin(2t)$ introducing an\noscillation in the system, the solution won't look at simple as some\nof the other examples.\n\\end{Solution}\n\n%*******************************\n\\item\n\\begin{Question}\n  Create a plot for the solution to the differential equation\n  $ty' + 2y = t^2 - t + 1$, if $y(1) = 0.5$.\n    \n\\end{Question}\n\n\\begin{Solution}\n  To generate a first-order DE solution in MATLAB, the differential\n  equation must be written first in the form $y' = \\ldots$.\n  \\begin{align*}\n    ty' + 2y = t^2 - t + 1 \\\\\n    ty' = -2y + t^2 - t + 1 \\\\\n    y' = \\frac{1}{t} (-2y + t^2 - t + 1) \\\\\n  \\end{align*}\n    \nLink to the MATLAB code: \\\\\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W07DE05.m}{W07DE05.m}\n\nHere is the graph of the solution.\n\n\\includegraphics[width = 0.5\\linewidth]{graphics/Week07_DESolutions/W07DE05}\n    \n    \n\\end{Solution}\n\n%*******************************\n\\item\n\\begin{Question}\n  Create a plot for the solution to the differential equation\n  $2xy^2 + 4 = 2(3 - x^2y)y'$ if $y(5) = 8$.\n    \n\\end{Question}\n\n\\begin{Solution}\n  To generate a first-order DE solution in MATLAB, the differential\n  equation must be written first in the form $y' = \\ldots$.  We start\n  by switching both sides of the equation to put $y'$ on the left.\n  \\begin{align*}\n    2(3 - x^2y)y' & = 2xy^2 + 4   \\\\\n    y' & = \\frac{ 2xy^2 + 4}{2 (3-x^2 y)} \n  \\end{align*}\n    \nLink to the MATLAB code: \\\\\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W07DE06.m}{W07DE06.m}\n\nHere is the graph of the solution.\n\n\\includegraphics[width = 0.5\\linewidth]{graphics/Week07_DESolutions/W07DE06}\n    \n    \n\\end{Solution}\n\n\n\\end{enumerate}\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "95ed069d5dcb7d6cd35d3160ab4af738d9e039fe", "size": 11827, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PracticeProblems/Week07.tex", "max_stars_repo_name": "aableson/MNTCP01", "max_stars_repo_head_hexsha": "1845fe6ac290b008b070f00f1b68856bdbdfc584", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-11-27T16:10:35.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-27T16:10:35.000Z", "max_issues_repo_path": "PracticeProblems/Week07.tex", "max_issues_repo_name": "aableson/MNTCP01", "max_issues_repo_head_hexsha": "1845fe6ac290b008b070f00f1b68856bdbdfc584", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PracticeProblems/Week07.tex", "max_forks_repo_name": "aableson/MNTCP01", "max_forks_repo_head_hexsha": "1845fe6ac290b008b070f00f1b68856bdbdfc584", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.5042492918, "max_line_length": 265, "alphanum_fraction": 0.6149488459, "num_tokens": 4445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.8872045877523147, "lm_q1q2_score": 0.737393917716722}}
{"text": "%!TEX root = ceres-solver.tex\n\\chapter{Hello World!}\n\\label{chapter:tutorial:helloworld}\nTo get started, let us consider the problem of finding the minimum of the function\n\\begin{equation}\n \\frac{1}{2}(10 -x)^2.\n\\end{equation}\nThis is a trivial problem, whose minimum is easy to see is located at $x = 10$, but it is a good place to start to illustrate the basics of solving a problem with Ceres\\footnote{Full working code for this and other examples in this manual can be found in the \\texttt{examples} directory. Code for this example can be found in \\texttt{examples/quadratic.cc}}. \n\n\nLet us write this problem as a non-linear least squares problem by defining the scalar residual function $f_1(x) = 10 - x$. Then $F(x) = [f_1(x)]$ is a residual vector with exactly one component.\n\nWhen solving a problem with Ceres, the first thing to do is to define a subclass of \\texttt{CostFunction}. It is responsible for computing the value of the residual function and its derivative (also known as the Jacobian) with respect to $x$.\n\\begin{minted}[mathescape]{c++}\nclass SimpleCostFunction\n  : public ceres::SizedCostFunction<1 /* number of residuals */,\n                                    1 /* size of first parameter */> {\n public:\n  virtual ~SimpleCostFunction() {}\n  virtual bool Evaluate(double const* const* parameters,\n                        double* residuals,\n                        double** jacobians) const {\n    const double x = parameters[0][0];\n    residuals[0] = 10 - x;  // $f(x) = 10 - x$\n    // Compute the Jacobian if asked for.\n    if (jacobians != NULL && jacobians[0] != NULL) {\n      jacobians[0][0] = -1;\n    }\n    return true;\n  }\n};\n\\end{minted}\n\\texttt{SimpleCostFunction} is provided with an input array of parameters, an output array for residuals and an optional output array for Jacobians. In our example, there is just one parameter and one residual and this is known at compile time, therefore we can save some code and instead of inheriting from \\texttt{CostFunction}, we can instaed inherit from the templated \\texttt{SizedCostFunction} class. \n\n\nThe \\texttt{jacobians} array is optional, \\texttt{Evaluate} is expected to check when it is non-null, and if it is the case then fill it with the values of the derivative of the residual function. In this case since the residual function is linear, the Jacobian is constant.\n\nOnce we have a way of computing the residual vector, it is now time to construct a Non-linear least squares problem using it and have Ceres solve it.\n\\begin{minted}{c++}\nint main(int argc, char** argv) {\n  double x = 5.0;\n  ceres::Problem problem;\n\n  // The problem object takes ownership of the newly allocated\n  // SimpleCostFunction and uses it to optimize the value of x.\n  problem.AddResidualBlock(new SimpleCostFunction, NULL, &x);\n\n  // Run the solver!\n  Solver::Options options;\n  options.max_num_iterations = 10;\n  options.linear_solver_type = ceres::DENSE_QR;\n  options.minimizer_progress_to_stdout = true;\n  Solver::Summary summary;\n  Solve(options, &problem, &summary);\n  std::cout << summary.BriefReport() << \"\\n\";\n  std::cout << \"x : 5.0 -> \" << x << \"\\n\";\n  return 0;\n}\n\\end{minted}\n\nCompiling and running this program gives us\n\\begin{minted}{bash}\n0: f: 1.250000e+01 d: 0.00e+00 g: 5.00e+00 h: 0.00e+00 rho: 0.00e+00 mu: 1.00e-04 li:  0\n1: f: 1.249750e-07 d: 1.25e+01 g: 5.00e-04 h: 5.00e+00 rho: 1.00e+00 mu: 3.33e-05 li:  1\n2: f: 1.388518e-16 d: 1.25e-07 g: 1.67e-08 h: 5.00e-04 rho: 1.00e+00 mu: 1.11e-05 li:  1\nCeres Solver Report: Iterations: 2, Initial cost: 1.250000e+01,  \\\nFinal cost: 1.388518e-16, Termination: PARAMETER_TOLERANCE.\nx : 5 -> 10\n\\end{minted}\n\nStarting from a $x=5$, the solver in two iterations goes to 10~\\footnote{Actually the solver ran for three iterations, and it was by looking at the value returned by the linear solver in the third iteration, it observed that the update to the parameter block was too small and declared convergence. Ceres only prints out the display at the end of an iteration, and terminates as soon as it detects convergence, which is why you only see two iterations here and not three.}. The careful reader will note that this is a linear problem and one linear solve should be enough to get the optimal value.  The default configuration of the solver is aimed at non-linear problems, and for reasons of simplicity we did not change it in this example. It is indeed possible to obtain the solution to this problem using Ceres in one iteration. Also note that the solver did get very close to the optimal function value of 0 in the very first iteration. We will discuss these issues in greater detail when we talk about convergence and parameter settings for Ceres.\n", "meta": {"hexsha": "04b677af0571ee7056a20141b04ac44d8b0ae64c", "size": 4691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/helloworld.tex", "max_stars_repo_name": "pritasam/ceres-solver", "max_stars_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/helloworld.tex", "max_issues_repo_name": "pritasam/ceres-solver", "max_issues_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/helloworld.tex", "max_forks_repo_name": "pritasam/ceres-solver", "max_forks_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.1527777778, "max_line_length": 1050, "alphanum_fraction": 0.7282029418, "num_tokens": 1285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282706, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.737392138555991}}
{"text": "%!TEX root = ../thesis.tex\n% ******************************* Thesis Appendix B ********************************\n\n\\input{style.tex}\n\n\n\\chapter{Convolution}\n\\label{appendix.convolution}\nSay we want to measure an observable $Q$, for example, for a specific occupied number of sites(bonds) in site(bond) percolation. But doing this we ignore the fact that we would have chose to fix a probability $p$ first and starting occupying the lattice sequentially then after we have had visited all the sites we would not have $p=n/(L^2)$ for site or $p=n/(2 L^2)$ for bond percolation each time. Therefore it would lead to some error. We can solve this dilemma by the following process. \nThe trick \\cite{Hu1992, Gould2006} is to measure $Q$ for fixed numbers of occupied sites (or bonds) $n$ in the range of interest. Let us refer to the ensemble of states of a percolation system with exactly $n$ occupied sites or bonds as a \"microcanonical percolation ensemble,\" the number $n$ playing the role of the energy in thermal statistical mechanics. The more normal case in which only the occupation probability $p$ is fixed is then the \"canonical ensemble\" for the problem. (If one imagines the occupied sites or bonds as representing particles instead, then the two ensembles would be \"canonical\" and \"grand canonical,\" respectively. Taking site\npercolation as an example, the probability of there being\nexactly $n$ occupied sites on the lattice for a canonical percolation ensemble is given by the binomial distribution\n\t\\begin{equation}\n\t\tB(N,n,p) = {N\\choose n} p^n (1-p)^{N-n}\n\t\\end{equation}\n\tThe same expression applies for bond percolation, but\n\twith $N$ replaced by $M$ , the total number of bonds.\tThus, if we can measure our observable within the microcanonical ensemble for all values of $n$, giving a set\n\tof measurements ${Q_n}$, then the value in the canonical\n\tensemble will be given by\n\t\\begin{equation}\n\t\tQ(p) \n\t\t= \\sum_{n=0}^{N} B(N,n,p) Q_n \n\t\t= \\sum_{n=0}^{N} {N\\choose n} p^n(1-p)^{N-n} Q_n \t\n\t\\end{equation}\n\tThus we need only measure $Q_n$ for all values of $n$.\n\t\\cite{Newman2001}.\n\t\n\t\n\n\t\n\\section{Algorithm}\n\tBut using this formula to calculate $Q(p)$ is quite expensive since the number of sites(bonds) can be quite large  direct evaluation of the binomial coefficients using factorials is not possible. We use alternative way to measure $Q(p)$, which is basically does the same thing but in an efficient way.\n \n\tInstead, therefore, we recommend the following method of evaluation. The binomial distribution, Eq. (1), has its largest value for given $N$ and $p$ when $n = n_{max} = p N$ . We arbitrarily set this value to $1$. Now we calculate $B(N, n, p)$ iteratively for all other $n$ from\n\t\n\t\\begin{equation*}\n\tB(N,n,p) = \n\t\\begin{cases}\n\t\tB(N, n-1, p) \\frac{N-n+1}{n} \\frac{p}{1-p}  \\text{ if } n > n_{max}\\\\\n\t\tB(N, n+1, p) \\frac{n+1}{N-n} \\frac{1-p}{p}  \\text{ if } n < n_{max}\n\t\\end{cases}   \n\t\\end{equation*}\n\tThen we calculate the normalization coefficient $C = \\sum_{n} B(N, n, p)$ and divide all the $B(N, n, p)$ by it, to correctly normalize the distribution \t\\cite{Newman2000, Newman2001}.\n\t\n\\section{Code}\n\tIn order to use convolution the following function can be used. It is very efficient and uses OpenMP for parallel run, meaning, all the cores of the processors performs the same task in a divide-and-conquer manner. This function takes an array as input and returns the convoluted version as output.\n\t\\begin{lstlisting}[style=CStyle]\n\tvector<double> convolution(vector<double>& data_in) {\n\tsize_t N = data_in.size();\n\tstd::vector<double> _forward_factor(N);\n\tstd::vector<double> _backward_factor(N);\n\tfor (size_t i=0; i < N; ++i)\n\t{\n\t_forward_factor[i]  = (double) (N - i + 1) / i;\n\t_backward_factor[i] = (double) (i + 1) / (N - i);\n\t}\n\tvector<double> data_out(N);\n\tlong step = N / 1000;\n\t#pragma omp parallel for schedule(dynamic)\n\tfor (long j=0; j <N; ++j) // start from j=1\n\t{\n\tdouble prob     = (double) j / N;\n\tdouble factor   = 0;\n\tdouble binom    = 0;\n\tdouble prev     = 0;\n\tdouble bn_tot   = 1; // normalization factor\n\tdouble sum      = data_in[j];\n\t// forward iteraion part\n\tfactor = prob / (1-prob);\n\tprev   = 1;\n\tfor (long i=j+1; i<N; ++i)\n\t{\n\tbinom     = prev * _forward_factor[i] * factor;\n\tbn_tot += binom;\n\tsum      += data_in[i] * binom;\n\tprev      = binom;\n\t}\n\t// backward iteration part\n\tfactor = (1-prob)/prob;\n\tprev   = 1;\n\tfor (long i=j-1; i>=0; --i)\n\t{\n\tbinom     = prev * _backward_factor[i] * factor;\n\tbn_tot += binom;\n\tsum      += data_in[i] * binom;\n\tprev      = binom;\n\t}\n\t// normalizing data\n\tdata_out[j] = sum / bn_tot;\n\tcout << bn_tot << endl;\n\t}\n\treturn data_out;\n\t}\n\t\\end{lstlisting}\nComplete code for convolution is available at \n\\url{https://github.com/sha314/Convolution}.\\\\\n\nThe program linked above works using command line arguments. For example to perform convolution on a file \"data.txt\" which contains two columns out of which only second column needed to be convoluted use the following command.\n\n\\begin{lstlisting}[language=bash]\n./convolute -f data.txt -a 0 -b 1\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=Instruction]\nUsage:\nconvolution [-f <STRING>] [-a <INT>,<INT>,...[:[<STRING>,<STRING>,...]]] [-b <INT>,<INT>,...[:[<STRING>,<STRING>,...]]] [-h] [-t <INT>] [-i <STRING>]\nperform convolution based on provided options.\nOptions                      Description\n-a,                        columns that we want in the output file without performing convolution.\nNo default value.\n-b,                        columns that we want in the output file with performing convolution.\nNo default value.\n-c,                        If provided the header and comment from the input file will be written\nwithout modification to the output file. Header is the first line of the\ninput file.\n-d                         Delimeter to use. Default value is ' '.\n-f                         name of the input file that we want to convolute. No default value.\n-i                         Info to write as comment in the output file\n-o                         name of the output file. If not provided the string '_convoluted.txt' will be\nappended to the input file.\n-p, --precision            Floating point precision when writing in the data file. Default value is 10\n-s                         Number of rows to skip from the input file. Default value is 0.\n-t                         to test the performance of the convolution program. No default value.\n--threads              Explicitly specify number of thread to use. Default is the max number of thread\nallowed by the system.\n-h, --help                 display this help and exit\n-v, --version              output version information and exit\n-w                         If provided input b data will be written to the output file.\nThe INT argument is an integer.\nThe STRING argument is a string of characters.\nA line that begins with '#' is considered a commented line.\nExit status:\n0  if OK,\n1  if minor problems (e.g., cannot access subdirectory),\n2  if serious trouble (e.g., cannot access command-line argument).\n\\end{lstlisting}\n", "meta": {"hexsha": "3cd138b1084ce411cb9b482b0ee75b67b200b1ca", "size": 7045, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix2/appendix2.tex", "max_stars_repo_name": "sha314/MS_thesis_DU_PH", "max_stars_repo_head_hexsha": "c1981167c2503ce5f30fdaf564aa12e824718031", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Appendix2/appendix2.tex", "max_issues_repo_name": "sha314/MS_thesis_DU_PH", "max_issues_repo_head_hexsha": "c1981167c2503ce5f30fdaf564aa12e824718031", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Appendix2/appendix2.tex", "max_forks_repo_name": "sha314/MS_thesis_DU_PH", "max_forks_repo_head_hexsha": "c1981167c2503ce5f30fdaf564aa12e824718031", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.4233576642, "max_line_length": 655, "alphanum_fraction": 0.6770759404, "num_tokens": 1866, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7373484660315414}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath, amsthm, amsfonts, amssymb, verbatim, hyperref}\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{lemma}[theorem]{Lemma}\n\n\\begin{document}\n\n\\section{Hensel lifts}\nLet $p$ be a prime and suppose we have a polynomial factorization\n\\[\nu = \\bar v \\cdot \\bar w \\mod p\n\\] with \\(p\\)-prime, where \\(\\bar v\\) and \\(\\bar w\\) are relatively prime monic polynomials in the variable \\(x\\). Set \n\\[\n\\deg \\bar v = m\\quad \\deg \\bar  w = n.\n\\] \nOur goal is to construct monic polynomials \\(v, w\\) of the same degrees as \\(\\bar v,\\bar  w\\) with \n\\[\nu = v \\cdot w \\mod p^k.\n\\]\nSince factorization $\\mod p$ is unique, it follows that \\(v =  \\bar v \\mod p \\) and \\(w = \\bar w \\mod p\\). Our secondary goal is to show that, \\(\\mod p^{k}\\), these polynomials are unique. Proceed by induction. Suppose we have already found \\(v, w\\) as above and are looking for \\(v', w'\\) with \n\\[\nu = v'\\cdot w' \\mod p^{k+1}.\n\\]\nOver $\\mathbb Z$, we have that\n\n\\[ \nu = vw + p^k z \n\\]\nfor some polynomial \\(z\\). Since \\(u,v,w\\) are monic, the leading monomials of \\(u\\) and \\(vw\\) are $x^{m+n}$ and so $\\deg z = m + n - 1$. Since  \\(v, w\\) are unique \\(\\mod p^{k}\\), it follows that \\(v', w'\\) must be of the form \n\\[\nv' = v + p^{k} a \\quad w' = w+ p^k b\n\\]\nwith \\(\\deg a < \\deg v= m\\) and \\(\\deg b < \\deg w = n\\). \n\\begin{equation}\\label{eqHenselLift0}\n\\begin{array}{rcl}\nv' w'& =& \\left(v+p^k a\\right)\\left(w + p^k b\\right) \\\\\n&=&vw + p^k(aw + bv) + p^{2k} ab\\\\\n&=&u + p^{k}z + p^{k}(aw+bv) + p^{2k}ab\\\\\n&=&u + p^{k}\\left( z + aw + bv\\right) + p^{2k}ab\n\\end{array}\n\\end{equation}\nIt follows that \n\\begin{equation}\\label{eqHenselLift1}\nz + aw + bv = 0 \\mod p\n\\end{equation} \nIntroduce notation for the coefficients of the polynomials in \\eqref{eqHenselLift1}:\n\\begin{equation}\n\\begin{array}{rcl}\na &=& a_{1} x^{m-1} + \\dots + a_m\\\\\nb &=& b_{1} x^{n-1} + \\dots + b_m \\\\\nz &=& z_{1}x^{m + n - 1} + \\dots +z_{m+n}\\\\\nw &=& x^{m} + w_{1} \\cdot x^{m - 1} + \\dots + w_{m}\\\\\nv &=& x^{n} + v_{1} \\cdot x^{n - 1} + \\dots + v_{n}\\\\\n\\end{array}\n\\end{equation}\nThen \\eqref{eqHenselLift1} is a linear system in the \\(m+n\\) variables \\(a_1, \\dots, a_m, b_1, \\dots, b_n\\) with $\\deg z + 1 = m + n $ equations. More precisely, the matrix form of the equation \\eqref{eqHenselLift1} is given by the Sylvester matrix:\n\\begin{equation}\\label{eqHanselLift2Sylvester}\n\\left( \\begin{array}{ccccccccccc}\nw_0    & 0       & \\cdots & 0       & v_0    & 0       & \\cdots & 0      \\\\\nw_1    & w_0     & \\cdots & 0       & v_1    & v_0     & \\cdots & 0      \\\\\nw_2    & w_1     & \\ddots & 0       & v_2    & v_1     & \\ddots & 0      \\\\\n\\vdots &\\vdots   & \\ddots & w_0     & \\vdots &\\vdots   & \\ddots & v_0    \\\\\nw_m    & w_{m-1} & \\cdots & \\vdots  & v_n    & v_{n-1} & \\cdots & \\vdots  \\\\\n0      & w_m     & \\ddots & \\vdots  & 0      & v_n     & \\ddots & \\vdots  \\\\\n\\vdots & \\vdots  & \\ddots & w_{m-1} & \\vdots & \\vdots  & \\ddots & v_{n-1} \\\\\n0      & 0       & \\cdots & w_m     & 0      & 0       & \\cdots & v_n   \n\n\\end{array}\\right) \\begin{pmatrix}\na_1 \\\\\na_2\\\\\n\\vdots\\\\\na_m\\\\\nb_1\\\\\nb_2\\\\\n\\vdots \\\\\nb_n\n\\end{pmatrix} = \\begin{pmatrix}\nz_1\\\\\nz_2\\\\\n\\vdots\n\\\\ \nz_m\\\\\nz_{m+1} \\\\\nz_{m+2} \\\\\n\\vdots \\\\\nz_{m+n}\n\n\\end{pmatrix} \\mod p,\n\\end{equation}\nwhere for convenience we have set $v_0 = w_0=1$. The determinant of the matrix above, called the resultant, is known to equal \\(\\text{res}(v,w) = \\displaystyle w_0^mv_0^n\\prod_{i, j} \\left(\\nu_i-\\mu_j \\right)\\), where $\\nu_i, \\mu_j$ are the roots of $v$ and $w$ over the algebraic closure of $\\mathbb Z / p\\mathbb Z$. In our starting factorization $u=\\bar v\\cdot \\bar w $, the factors $\\bar v, \\bar w$ are relatively prime and so have no common roots and we have that $\\text{res}(\\bar v, \\bar w)\\neq 0$. At the same time we established that $v =\\bar v \\mod p$ and $w=\\bar w\\mod p $ and so $\\text{res} (\\bar v, \\bar w) = \\text{res}(v,w) \\neq 0$. Since the determinant of \\eqref{eqHanselLift2Sylvester} is non-zero, \\eqref{eqHanselLift2Sylvester} has a unique solution. This shows both the existence and uniqueness of $v',w'$. This in turn concludes our inductive step.\n\\subsection{Hensel lift for more than two factors}\nWe want to extend the Hensel lift from the previous section to the case of more than two factors. Let\n\\[\nu = \\bar v_1 \\dots \\bar v_l \\mod p\n\\]\nbe a factorization with \\(p\\)-prime. The considerations of the two factor case carry over to the multi-factor one. TODO(tmilev): spell out the notation. Equation \\eqref{eqHenselLift0} becomes\n\\[\n\\begin{array}{rcl}\nv_1'\\dots v_k'& = & u + p^k \\left(z+ a_1 v_2\\dots v_l + v_1 a_2\\dots v_l +\\dots + v_1\\dots v_{l-1} a_l   \\right) +p^{2k} s\n\\end{array}\n\\]\nfor some polynomial $s$. Let $t_j$ be the polynomial obtained by removing the $j^{th}$ multiplicand from $v_1\\dots v_l$, i.e., let\n\\[t_j=\\frac{v_1\\dots v_l}{v_j}. \\]\n\nThen equation \\eqref{eqHanselLift2Sylvester} carries over directly. Its matrix becomes\n\\[\n\\left( \\begin{array}{ccccccccccc}\nt_{1,0}       & 0      & \\cdots & 0              & t_{2,0}       & 0      & \\cdots & 0              & \\dots \\\\\n\\vdots        & \\ddots & \\ddots & \\vdots         & \\vdots        & \\ddots & \\ddots & \\vdots         & \\dots \\\\\n\\vdots        & \\ddots & \\ddots & 0              & \\vdots        & \\ddots & \\ddots & 0              & \\dots \\\\\nt_{1,\\deg t_1}& \\ddots & \\ddots & t_{1,0}        & t_{2,\\deg t_2}& \\ddots & \\ddots & t_{2,0}        & \\dots \\\\\n0             & \\ddots & \\ddots & \\vdots         & 0             & \\ddots & \\ddots & \\vdots         & \\dots \\\\\n\\vdots        & \\ddots & \\ddots & \\vdots         & \\vdots        & \\ddots & \\ddots & \\vdots         & \\dots \\\\\n0             & \\cdots & 0      & t_{1,\\deg t_1} & 0             & \\cdots & 0      & t_{2,\\deg t_2} & \\dots \\\\\n\\end{array}\\right)\\]\n\n\\end{document}\n\n", "meta": {"hexsha": "2b2e64a6929dedcff8eb12d5250a6338b31bbb3c", "size": 5742, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/notes.tex", "max_stars_repo_name": "tmilev/calculator", "max_stars_repo_head_hexsha": "e39280f23975241985393651fe7a52db5c7fd1d5", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2017-07-12T11:15:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-29T18:33:33.000Z", "max_issues_repo_path": "notes/notes.tex", "max_issues_repo_name": "tmilev/calculator", "max_issues_repo_head_hexsha": "e39280f23975241985393651fe7a52db5c7fd1d5", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2017-05-16T03:48:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-16T19:51:26.000Z", "max_forks_repo_path": "notes/notes.tex", "max_forks_repo_name": "tmilev/calculator", "max_forks_repo_head_hexsha": "e39280f23975241985393651fe7a52db5c7fd1d5", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-08-02T09:05:08.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-02T09:05:08.000Z", "avg_line_length": 48.2521008403, "max_line_length": 867, "alphanum_fraction": 0.5790665273, "num_tokens": 2232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.8558511506439707, "lm_q1q2_score": 0.7373484587373301}}
{"text": "\\section{Probability interpretation of logistic regression}%Jonathan will input his notes from camera scaned files.\nLogistic regression models the probabilities for classification problems with two possible outcomes. It's an extension of the linear regression model for classification problems.\n\\begin{itemize}\n\\item Input: d-dimension feature vector $x\\in R^{d}$\n\\item Output: a class or label $l \\in\\{1, \\ldots, k\\}$ (how to classify)\n\\item Example 1: Image classfication:\\newline\nGiven input image $x \\in R^{n \\times n}$, predict a label for the image. e.g. cat/ dog;\nMNIST: $\\{0, \\ldots, 9\\}$; CIFAR-10, $\\{0, \\ldots, 9\\}$\n\\item Example 2: Binary Classfication:\\newline\nGiven some medical data $x\\in R^{d}$(features, like heart pressure, resting heart rate, family history, etc), we try to predict incidence of heart disease. The label will be binary $\\{0, 1\\}$, called binary classification.\n\\end{itemize}\n\n\\subsection{Logistic Regression Model}\nGiven input feature vector $x\\in R^{n}$, the model predicts a probability distribution over the labels $\\{0, \\ldots, k\\}$. \n$$\n\\mbox{affine linear map: }Ax+b:\\quad R^{n} \\rightarrow R^{k} \n$$\nwith $A\\in R^{k \\times n}$, $x\\in R^{n}$, $b\\in R^{k}$.\n $$\n \\mbox{softmax} \\left( Ax+b\\right) : \\quad R^{n} \\rightarrow R^{k} \\xrightarrow{softmax}P\\left( \\{1, \\ldots, k\\}\\right) \n $$  \nSoftmax: \n\\begin{enumerate}\n\\item Input: $y \\in \\mathbb{R}^{k}=\\left(\\begin{array}{l}y_{1} \\\\ \\vdots \\\\ y_{k}\\end{array}\\right)$\n\\item Output: Distribution $p(j)=\\frac{e^{y_{j}}}{\\sum_{i=1}^{n} e^{y_{i}}}$ \n\\item Take exponential and normalize\n\\end{enumerate}\n\n{\\bf Logistic Regression Model}: Given input (feature/data) $x \\in R^{n}$, we return the distribution softmax  $\\left( Ax+b\\right) $ where A, b are parameters.\n\\begin{itemize}\n\t\\item Example 1: Divide data into two classes: parameters are $\\vec{a}\\in \\mathbb{R}^{n}, b \\in \\mathbb{R}$ \n\t$$\n\tA\\in \\mathbb{R}^{1\\times n},\\quad Ax+b\\in \\mathbb{R}.\n\t$$\n\tThe probability that the data $x$ belongs to class 1 is \n\t$$\n\tP(1)=\\frac{e^{\\vec{a}\\cdot x+b}}{e^{\\vec{a} \\cdot x+b}+1},\n\t$$\n\tand the probability that the data $x$ belongs to class 2 is\n\t$$\n\tP(2)=\\frac{1}{e^{\\vec{a} \\cdot x+ b}+1}.\n\t$$\n\tIf $\\vec{a} \\cdot x+ b=0$, $P(1)=\tP(2)={1\\over 2}$. We don't know how to classify the data lying on the line $\\vec{a} \\cdot x+ b=0$ as shown in the figure below.\n   \\begin{figure}[ht!]\n  \t\\centering\n  \t\\includegraphics[width=.55\\textwidth]{../figures/probabilityLR1.png}  \n  \\end{figure}\n  Note that \n$$\n\\frac{p(1)}{p(2)}=e^{\\vec{a} \\cdot x+b},\\quad \\log \\left(\\frac{p(1)}{p(2)}\\right)=\\vec{a} \\cdot x+b.\n$$\nBy the above equation, $\\vec{a}$ means which feature is important.  \\newline\nLogarithm of the odds: $ \\log \\left(\\frac{p(1)}{p(2)}\\right)$. \\newline\nAssumption:  $\\log \\left(\\frac{p(1)}{p(2)}\\right)$ is linear in the feature vector\n\\end{itemize}\n\n\n\\subsection{Learning the parameters  $\\vec{a}, b$ from data }\nData: feature vectors $x$ and corresponding labels $l$. Given data \n$$\n\\left\\{\\left(x_{1}, l_{1}\\right), \\ldots,\\left(x_{n}, l_{1}\\right)\\right\\}=D\n$$  \nHow can we estimate A, b? \n\n\\section{Maximamum Likelihood}\nIf parameters $A$ and $b$ are known, for any data $x_1\\in \\mathbb{R}^n$, model gives softmax  $\\left( Ax_1+b\\right) $ \\newline\n$$\n\\frac{1}{\\sum_{i=1}^{k} e^{\\vec{a_{i}}\\cdot x_{i}+b_{i}}} \n\\left(\\begin{array}{c}e^{\\vec{a}_{1}\\cdot x_{1} +b_{1}} \\\\ \\vdots \\\\ e^{a_{k} \\cdot x_{1}+b_{k}}\\end{array}\\right)\n=\n\\left(\\begin{array}{c}\np(1)\n \\\\ \\vdots \\\\ \np(k)\n \\end{array}\\right)\n$$ \nThis means that the probability that the model assigns to $l_{1}$ is\n$$\np(l)=\\frac{1}{\\sum_{i=1}^{k} e^{a_{i}\\cdot x_{i}+b_{i}}} \\cdot e^{\\vec{a}_{l} \\cdot x_{1}+b_{l}}\n$$  \nInstead of considering this probability, we consider its negtive logarithm: \\newline\n$$\n-\\log p(l)=\\log \\left(\\sum_{i=1}^{k} e^{a_{i} \\cdot x_{i}+b_{i}}\\right)-\\left(\\vec{a}_{l} \\cdot x_{1}+b_{l}\\right)\n$$  \nSince data points are independent, so we take product of the probability which leads to the logistic regression loss.\\newline\nLogistic Regression Loss: \n$$\nL_{D}(A, b)=\\sum_{(x, l) \\in D}\\left[\\log \\left(\\sum_{i=1}^{k} a_{i} \\cdot x+b_{i}\\right)-\\left(\\vec{a}_{l} \\cdot x+b_{l}\\right)\\right]\n$$  \nWe want to maximize the probability that the model assigns to $l$, that means we need to minimize $-\\log p(l)$. So we need to find \n$$\n(A, b)=\\min _{A, b} L_{D}(A, b).\n$$\n\n\n\\section{Basic Statistical Learning Theory}\n\\begin{itemize}\n\t\\item Goal: Estimate an unknown probability distribution $D$ on a set $X$ from samples $(i,i,d)$ $x_{1}, \\ldots, x_{n} \\in X$\n\t\\item Introduce a family of distributions $P_{\\theta}$ for $\\theta \\in \\Theta$ and try to choose $\\theta$ to \"match\" the samples.\n\t\\begin{itemize}\n\t\t\\item Maximum Likelihood Estimate: Choose $\\theta$ to maximize the probability of the samples.\n\t\t\\item Example: Let $X=R$, have some samples $x_{1}, \\ldots, x_{n}$ drawn from a distribution D, say $P_{\\theta}$ is a Gaussian with variance 1, centered at $\\theta \\in \\mathbb{R}=\\Theta$, i.e. density  $p_{\\theta}(x)=\\frac{1}{\\sqrt{2 \\pi}} e^{-(x-\\theta)^{2} / 2}$ \n\t\t\n\t\t   \\begin{figure}[ht!]\n\t\t  \t\\centering\n\t\t  \t\\includegraphics[width=.55\\textwidth]{../figures/probabilityLR2.png}  \n\t\t  \\end{figure}\n\t\t\\item Use the samples to find the center $\\theta$.\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{Maximum Likelihood Estimate(MLE)}\n\\begin{itemize}\n\t\\item Given $\\theta \\in \\Theta (=\\mathbb{R}$ for this example), what is the probability of the data $\\left\\{x_{j}\\right\\}_{j=1}^{n}$?\n\t\\begin{itemize}\n\t\t\\item Samles independent: Likelihood function(as a function of $\\sigma$) \n\t\t$$\n\t\tP_{\\theta}\\left(\\left\\{x_{j}\\right\\}_{j=1}^{n}\\right)=\\prod_{j=1}^{n} p_{\\theta}\\left(x_{j}\\right)\n\t\t=\\frac{1}{(\\sqrt{2 \\pi})^{n}}\\prod_{j=1}^{n} e^{-\\left(x_{j}-\\theta\\right)^{2} / 2}\n\t\t=\\frac{1}{(2 \\pi)^{n/ 2}} e^{-\\sum_{j=1}^{n}\\left(x_{j}-\\theta\\right)^{2} / 2}\n\t\t$$\n\t\t\\item MLE: Choose $\\theta$ to maximize this!\n\t\t\\item Often it's useful to consider log likelihood function $\\log \\left(P_{\\theta}\\left(\\left\\{x_{j}\\right\\}_{j=1}^{n}\\right)\\right) $  \n\t\t$$\n\t\t\\begin{aligned} \\theta^{*}= \\operatorname{argmax} _{\\theta \\in \\Theta}\\log \\left(P_{\\theta}\\left(\\left\\{x_{j}\\right\\}_{j=1}^{n}\\right)\\right) \\\\\n\t\t\\left(\\operatorname{argmin} _{\\theta \\in \\Theta}-\\log \\left(P_{\\theta}\\left(\\left\\{x_{j}\\right\\}_{j=1}^{n}\\right)\\right)\\right) \\end{aligned}\n\t\t$$\n\t\\end{itemize}\n     \\item For this example: \n     $$\n     \\log \\left(P_{\\theta}\\left(\\left\\{x_{j}\\right\\}_{j=1}^{n}\\right)\\right)=-\\log (2 \\pi) \\cdot\\left(\\frac{n}{2}\\right)-\\sum_{j=1}^{n} \\frac{\\left(x_{j}-\\theta\\right)^{2}}{2}\n     $$ \n     $$\n     \\theta^{*}=\\operatorname{argmin}_{\\theta \\in \\mathbb{R}} \\sum_{j=1}^{n} \\frac{\\left(x_{j}-\\theta\\right)^{2}}{2}.\n     $$\n     $$\n      \\theta^{*}=\\frac{1}{n} \\sum_{j=1}^{n} x_{j}.\n      $$\n     \n     \t   \\begin{figure}[ht!]\n       \t\\centering\n       \t\\includegraphics[width=.55\\textwidth]{../figures/probabilityLR3.png}  \n       \\end{figure}\n\\end{itemize}\n\n\\section{Classfication/ Logistic Regression}\n\\begin{itemize}\n\t\\item For Classification: X is feature space and Y is label space\n\t$$\n\t\\widetilde{X}=X \\times Y\n\t$$\n\t\\item We have samples $\\left\\{\\left(x_{j}, y_{j}\\right)\\right\\}_{j=1}^{n}$\n\t\\item Suppose that D is an unknown distribution on $\\widetilde{X}$, but we're only trying to estimate $D_{Y|X}$ as a function of X. (Given the feature $X$, what is the possible label.)\n\t\\item Introduce parameters $\\theta\\in \\Theta$, we define $p(y|x, \\theta)$ (called the model)\n\t\\item Now choose $\\theta$ to match the data $\\left\\{\\left(x_{j}, y_{j}\\right)\\right\\}_{j=1}^{n}$\n\t\\item MLE: \n\t\\begin{align*}\n\t\\theta^{*}&=\\operatorname{argmax}_{\\theta \\in\\Theta} p\\left(\\left\\{y_{i}\\right\\}_{j=1}^{n} |\\left\\{x_{j}\\right\\}_{j=1}^{n}, \\theta\\right)\\\\\n\t&=\\operatorname{argmax}_{\\theta \\in\\Theta}  \\prod_{j=1}^{n} p\\left(y_{j} | x_{j}, \\theta\\right)   \\\\\n\t&=\\operatorname{argmin}_{\\theta \\in\\Theta}  \\sum_{j=1}^{n}-\\log \\left(p\\left(y_{j} | x_{j}, \\theta\\right)\\right)\n\t\\end{align*}\n\t\\item Example: Logistic Regression:\n\t\\begin{itemize}\n\t\t\\item Model \n\t\t$$\n\t\tp(y | x, \\theta)=p(y | x, w, b)\n\t\t$$\n\t\twith $W\\in \\mathbb{R}^{d\\times d}$ and $b\\in \\mathbb{R}^k$ (parameters for affine linear map)\n\t\t\\item d: dimension of features, i.e. number of pixels\n\t\t\\item k: number of classes\n\t\\end{itemize}\n$$\np(y | x, w, b)=\\mbox{ softmax} \\left( W x+b\\right)=\\frac{1}{\\sum_{i=1}^{k} e^{w_{i}\\cdot x+b_{i}}}\\left(\\begin{array}{c}e^{w_{1}\\cdot x +b_{1}}  \\\\ \\vdots \\\\ e^{w_{k} \\cdot x +b_{k}}\\end{array}\\right)\n$$\n\\item Need to calculate:\n\\begin{equation}\\label{eq:pp}\n\\begin{split}\n&-\\log \\left(p\\left(y_{i} | x_{i}, w, b\\right)\\right)\\\\\n&=-\\log \\left(\\frac{1}{e^{w  x_i+b} \\cdot \\mathbb{I}} e^{w x_i+b} \\cdot y_{i}\\right)\\\\\n&=\\log \\left(e^{w x_i  +b} \\cdot 1\\right)-\\log \\left(e^{w x_i+b} \\cdot y_{i}\\right)\n\\end{split}\n\\end{equation}\nwith $y_i=(0,\\cdots, 0,1,0,\\cdots, 0)$(only the $i$-th entry is 1, all others are 0) and all the entries of $\\mathbb{I}$  are 1.\n$$\n(w, b)^{*}=\\underset{w,b}{\\operatorname{argmin}} \\sum_{i=1}^{n} \\log \\left(e^{wx_{i}+b} \\cdot \\mathbb{I}\\right)-\\log \\left(e^{wx_{i}+b} \\cdot y_{i}\\right)\n$$\n\\end{itemize}\n\n\\section{Bayesian Approach to Machine Learning}\n\\subsection{Goal}\n\\begin{itemize}\n\t\\item Goal: Estimate an unknown distribution on X from data $\\left\\{x_{j}\\right\\}_{j=1}^{n}$\n\t\\begin{itemize}\n\t\t\\item Build a model \n\t    \\begin{itemize}\n\t    \t\\item Set of parameters $\\Theta$\n\t    \t\\item Family of distribution on X, \n\t\t$$p(x|\\theta)\\quad \\mbox{with}\\quad \\theta \\in \\Theta $$\n\t    \t\\item Prior distribution on the parameters $\\Theta$, \n\t\t$$\n\t\tq(\\theta).\n\t\t$$\n\t    \\end{itemize}\n    \\item Use Bayes' Law \n    $$\n    p(\\theta|x) p(x)=p(x \\  and \\   \\theta )=p(x | \\theta) p(\\theta)\n    $$\n    \\item Recall if $A_{1} , A_{2}$ are events:    \n    $$\n    p\\left(A_{1} | A_{2}\\right)=\\frac{P\\left(A_{1} \\cap A_{2}\\right)}{P\\left(A_{2}\\right)}\n    $$\n    $$\n    p(\\theta | x)=\\frac{p(x | \\theta) q(\\theta)}{p(x)}\n    $$\n    $$\n    p(\\theta |x) \\sim p(x | \\theta) q(\\theta)\n    $$\n    where $p(\\theta |x)$ is the posteriori distribution, $q(\\theta)$ is the prior distribution and $p(x | \\theta)$ is the likelihood function.\n\t\\end{itemize}\n\\item Stant with: prior $q(\\theta)$  \n\\item Add data $x$, replace $q$ with the posterior\n $$\n p(\\theta | x) \\sim p(x | \\theta) q(\\theta)\n $$\n\\item More data: multiply by likelihood function and then normalize\n\\item Left with a posterior distribution\n     \\begin{itemize}\n\t\\item Sample from posterion distribution to approximate\n\t$$\n\tP_{pred}(x)=\\int_{\\Theta} p(x | \\theta) p(\\theta) d \\theta\n\t$$ \n\t\\item Choose $\\theta $ to maximize posterior distribution  \n\t\\begin{align*}\n\t\\theta^{*}&=\\arg \\max _{\\theta \\in \\Theta} p(\\theta|x)\\\\\n &=\\arg \\min _{\\theta \\in \\Theta}-\\log p(\\theta|x)\\\\\n&=\\arg \\min _{\\theta \\in \\Theta}-\\log (p(x | \\theta))-\\log (q(\\theta))+\\log (p(x))\\\\\n&=\\arg \\min _{\\theta \\in \\Theta}-\\log (p(x | \\theta))-\\log (q(\\theta))\n\\end{align*}\nwhere $-\\log (p(x | \\theta))$ is the negative log likelihood and $ -\\log (q(\\theta))$ is the regularization coming from prior.\n    \\end{itemize}\n\\subsection{Example: Image  Classification/ Logistic Regression}\n\\item Images $x \\in X=\\mathbb{R}^{d}$\n\\item Labels $y \\in Y=\\left\\{e_{1}, \\ldots, e_{k}\\right\\}$ with $k$ is the dimension of labels\n\\item Data $\\left\\{(x_{j},y_{j})\\right\\}_{j=1}^{n}$\n\\item Model $\\theta=(W, b) \\in \\mathbb{R}^{k \\times d} \\times \\mathbb{R}^{k}$. By \\eqref{eq:pp},\n$$\np(y | x, \\theta)=\\frac{e^{Wx+b} \\cdot y}{e^{Wx+b} \\cdot \\mathbb{I}}\n$$\n\\item Prior distribution: suppose it is a Gaussian,\n$$\nq(W, b)=C e^{-\\alpha\\left(\\left\\|W\\right\\|_{2}^{2}+ \\left\\|b\\right\\|_{2}^{2}\\right)}\n$$\n\n     \t%   \\begin{figure}[ht!]\n%  \t\\centering\n%  \t\\includegraphics[width=.35\\textwidth]{../figures/probability1.png}  \n%  \\end{figure}\n\n\\begin{itemize}\n\t\\item Calculate the posterior: here $q(W,b)=p(W, b|x)$,\n\t$$\n\tp(W, b | x, y)=\\frac{p(y | x, W, b) p(W, b|x) }{p(y | x)} \n\t$$\n\t$$\n\tp(y | x)=\\int_{\\Theta} p(y|x, W, b) q(W, b) d \\theta\n\t$$\n\t\\begin{align*}\n\t(W, b)^{*}&=\\underset{W,b}{\\arg \\min }-\\log \\left( p\\left(W, b |\\left\\{x_{j},y_{j}\\right\\}_{j=1}^{n}\\right)\\right) \\\\\n&=\\underset {W,b}\\arg  \\min -\\log \\left( p\\left(\\left\\lbrace y_{j}\\right\\rbrace _{j=1}^{n} | \\left\\lbrace x_{j}\\right\\rbrace _{j=1}^{n}, W, b\\right)\\right)-\\log (q(W, b))\\\\\n&=\\underset {W,b}\\arg  \\min\t-\\log \\left(\\prod_{i=1}^{n} p\\left(y_{j} | x_{j}, W, b\\right)\\right)-\\log (q(W, b))\\\\\n&=\\underset{W, b}{\\operatorname{argmin}} \\sum_{j=1}^{n} \\log \\left(e^{Wx+b} \\cdot \\mathbb{I}\\right)-\\log \\left(e^{Wx_j+b} \\cdot y_{j}\\right)+\\alpha\\left(\\|W\\|_{2}^{2}+\\| b\\|_{2}^{2}\\right).\n\t\\end{align*}\n\n\n\\end{itemize}\n\n\\end{itemize}\n\n\n\n\n%\\includepdf{HandWrittenNotes/LR1.pdf}\n%\\includepdf{HandWrittenNotes/LR2.pdf}\n%\\includepdf{HandWrittenNotes/LR3.pdf}\n%\\includepdf{HandWrittenNotes/BasicSLT1.pdf}\n%\\includepdf{HandWrittenNotes/BasicSLT2.pdf}\n%\\includepdf{HandWrittenNotes/BasicSLT3.pdf}\n%\\includepdf{HandWrittenNotes/BasicSLT4.pdf}\n%\\includepdf{HandWrittenNotes/Bayesian2.pdf}\n%\\includepdf{HandWrittenNotes/Bayesian1.pdf}\n%\\includepdf{HandWrittenNotes/Bayesian3.pdf}\n%\\includepdf{HandWrittenNotes/Bayesian4.pdf}", "meta": {"hexsha": "01ee9a6ef5d079091a6f671c9b3fe80996925397", "size": 13052, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/3 Probability/3.3-DL-LR-Prob.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/3 Probability/3.3-DL-LR-Prob.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/3 Probability/3.3-DL-LR-Prob.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.698630137, "max_line_length": 267, "alphanum_fraction": 0.6307845541, "num_tokens": 4955, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.737270701730925}}
{"text": "\\lab{Markov Chains}{Markov Chains}\n\\objective{Learn about Markov chains.}\n\\label{lab:EigSolve}\n\n\\section*{Markov chains}\nA Markov chain is a collection of states with specified probabilities for transitioning from one state to another.\nMarkov chains are characterized by the fact that future behavior of the system depends only on its current state.\n\nThis lab is a very brief introduction to Markov chains. To learn more, see [TODO: ref something].\n\n\\subsection*{An example}\nSuppose Fredo the frog is jumping between the three lily pads 1, 2, and 3.\nThese three pads are the \\emph{possible states} of the system, and the lily pad on which Fredo is presently sitting is the \\emph{current state}.\nIf Fredo is on lily pad 1 and jumps, there is a 25\\% chance that it will land back on lily pad 1, a 25\\% chance that it will land on lily pad 2, and a 50\\% chance that it will land on lily pad 3.\nThese probabilities are the \\emph{transition probabilities}.\nFigure \\ref{fig:markov1} is a \\emph{transition diagram} that depicts all transition probabilities.\n\n\\begin{figure}\n\\begin{tikzpicture}[normalcircle/.style={draw, circle, minimum size=1cm, fill=shadecolor, thick, node distance=1.5cm} ]\n\n\\node[normalcircle](circle1)[]{};\n\\node[draw=none](one)[]{1};\n\n\\node[draw=none, node distance=2.5cm](dummy)\n\t[below of=circle1]{};\n\n\\node[normalcircle](circle2)[left of=dummy]{};\n\\node[draw=none, node distance= 1.5cm](two)[left \n\tof=dummy]{2};\n\\node[normalcircle](circle3)[right of=dummy]{};\n\\node[draw=none, node distance= 1.5cm](three)\n\t[right of=dummy]{3};\n\n\\foreach \\s /\\t in {circle2/circle1, circle1/circle3, circle3/circle2}\n\t{\\path[draw,bend left=20, thick, ->, >=stealth'] (\\s)edge(\\t);}\n\\foreach \\s /\\t in {circle1/circle2, circle3/circle1, circle2/circle3}\n\t{\\path[draw,bend left=20, thick, ->, >=stealth'] (\\s)edge(\\t);}\n\n\\draw[thick,->, >=stealth'](-1.9,-2.8) arc (325:40:.4 and .5); \n\\draw[thick,->, >=stealth'](1.9,-2.2) arc (500:215:.4 and .5); \n\\draw[thick,->, >=stealth'](-.4,.3) arc (220:-35:.5 and .4); \n\n\\node[draw=none, node distance=1.6cm](dummy2)\n\t[below of=circle1]{};\n\\node[draw= none, node distance=.3cm](midvalues)\n\t[above left of=dummy2]{$\\frac{1}{4}$};\n\\node[draw= none, node distance=.3cm](midvalues2)\n\t[above right of=dummy2]{$\\frac{1}{2}$};\n\\node[draw= none, node distance=.25cm](midvalues3)\n\t[below of=dummy2]{$\\frac{1}{3}$};\n\\node[draw=none, node distance=1.6cm](outsidevalue)\n\t[above left of=midvalues3]{$\\frac{1}{2}$};\n\\node[draw=none, node distance=1.6cm](outsidevalue2)\n\t[above right of=midvalues3]{$\\frac{1}{2}$};\n\\node[draw=none, node distance=1.35cm](outsidevalue3)\n\t[below of=midvalues3]{$\\frac{1}{2}$};\n\\node[draw=none, node distance=1.25cm](circlevalue)\n\t[above of=circle1]{$\\frac{1}{4}$};\n\\node[draw=none, node distance=2.8cm](circlevalue2)\n\t[left of=dummy]{$\\frac{1}{6}$};\n\\node[draw=none, node distance=2.8cm](circlevalue3)\n\t[right of=dummy]{$0$};\n\n\\end{tikzpicture}\n\\caption{Transition diagram for Fredo the Frog.}\n\\label{fig:markov1}\n\\end{figure}\n\nWe can convert our transition diagram into a \\emph{transition matrix} The $(i,j)$-entry of the transition matrix is the probability that Fredo jumps from lily pad $j$ to lily pad $i$.\nFredo's transition matrix is\n\\[\nA = \\begin{pmatrix}\n1/4 & 1/2 & 1/2\\\\\n1/4 & 1/6 & 1/2\\\\\n1/2 & 1/3 & 0\n\\end{pmatrix}.\n\\]\n\nAt any time, the chances that Fredo is on each lily pad is encoded by a \\emph{state distribution vector} $\\x = (x_1, x_2, x_3)^T$, where $x_i$ is the probability that Fredo is on lily pad $i$. \nFor $\\x$ to be a state distribution vector, we require $x_i\\geq 0$ and $\\|\\x\\|_1=1$ (recall that the 1-norm of a column vector is the sum of the magnitudes of its entries). \nThen $A\\x$ will be another state distribution vector, which tells us the probability that Fredo is on each lily pad after one jump.\n\nThus, we can use Fredo's transition matrix to find where he will be after $k$ jumps. In fact, the $(i,j)$-entry of $A^k$ is the probability that Fredo goes from lily pad $j$ to lily pad $i$ in $k$ jumps. \nIn our case,\n\n\\[\nA^2 \\approx \\begin{pmatrix}\n0.4375 & 0.3750 & 0.3750\\\\\n0.3542 & 0.3194 & 0.2083\\\\\n0.2083 & 0.3056 & 0.4167\n\\end{pmatrix}.\n\\]\nTherefore, if Fredo starts on lily pad 1, there is a 43.75\\% chance it will still be on lily pad 1 after two jumps.\nMaybe Fredo jumped from 1 to 1 to 1, denoted $1 \\rightarrow 1 \\rightarrow 1$, or perhaps it jumped to one of the other lily pads and then back again, that is, either $1 \\rightarrow 2 \\rightarrow 1$ or $1 \\rightarrow 3 \\rightarrow 1$.\n\nIn addition, there is a 35.42\\% chance Fredo will be on lily pad 2 and a 20.83\\% chance that it will be on lily pad 3.\nWe can type our transition matrix into Python and see where Fredo is likely to be after any number of jumps.\n\n\\begin{lstlisting}\n# The 1.'s in the numerator force floating point division.\n>>> A = np.array([[1./4,1./2,1./2],[1./4,1./6,1./2],[1./2,1./3,0]])\n>>> np.linalg.matrix_power(A,10)\narray([[ 0.40000057,  0.39999962,  0.39999962],\n       [ 0.30002369,  0.29999268,  0.29997574],\n       [ 0.29997574,  0.3000077 ,  0.30002464]])\n\\end{lstlisting}\n\nIn fact, as we take higher and higher powers of $A$, it appears that \n\\[\n\\lim_{k \\rightarrow \\infty} A^k = \\begin{pmatrix}\n0.4 & 0.4 & 0.4\\\\\n0.3 & 0.3 & 0.3\\\\\n0.3 & 0.3 & 0.3\n\\end{pmatrix}.\n\\]\nThis means that Fredo's state distribution approaches $(0.4, 0.3, 0.3)^T$ after many jumps, regardless of his initial state distribution.\n\nMoreover, suppose Fredo's initial state distribution is $(0.4, 0.3, 0.3)^T$. \nWe can use Python to compute his state distribution after 1 jump.\n\\begin{lstlisting}\n>>> A.dot(np.array([0.4,0.3,0.3]))\narray([ 0.4,  0.3,  0.3])\n\\end{lstlisting} \nFredo's state distribution after a jump stays ``fixed.'' We call the vector $(0.4, 0.3, 0.3)^T$ a \\emph{stable fixed point} for Fredo.\n\n\n\\subsection*{General Markov chains}\nLet us generalize this example. A Markov chain is a collection of states with the probabilities that we will move from one state to another. \nThese transition probabilities are encoded in a transition matrix, whose $(i-j)$-entry is the probability of moving from state $j$ to state $i$. \nEach column of such a matrix will necessarily have entries that sum to 1. \n\n%When we have a Markov chain, we want to know what the state distribution is after our system has been running for some time. We are especially interested if the state distributions converge to something that is independent of the initial state, as was the case for Fredo. That is, we want to know about stable fixed points.\n\nLet $A$ be the transition matrix of a Markov chain. \nThen a state distribution vector $\\x$ is a \\emph{stable fixed point} if $A\\x=\\x$. \nSo $\\x$ is a stable fixed point if and only if $\\x$ is a positive unit eigenvector of $A$ corresponding to the eigenvalue 1. \n\n\nEvery Markov chain has at least one stable fixed point. \nIf in addition we assume some power $A^k$ of $A$ has all positive (nonzero) entries, then the stable fixed point is unique. \nIn this case, $A^k$ will converge to a matrix whose columns are all equal to the unique stable fixed point.\n\nNote that Fredo's transition matrix does not have positive entries, but its square does. \nSo Fredo has the unique stable fixed point $(0.4, 0.3, 0.3)^T$.\n\n\\subsection*{Finding stable fixed points}\nCalculating stable fixed points is an important problem in Markov chain analysis. \nSuppose a Markov chain has a transition matrix $A$ such that $A^k$ has strictly positive entries for some $k$. \nThen the \\emph{Perron-Frobenius theorem} says that 1 is the unique eigenvalue of $A$ of largest magnitude, and the corresponding eigenvector is unique. \nThis means that we can use the power method to find the unique stable fixed point of $A$.\n\nLet us look at what the power method is doing in the example of Fredo the frog. \nWe will use the 1-norm. \n\nSuppose we know Fredo starts on lily pad 1. Then we begin with the state distribution vector\n\\[\n\\x_0 = \\begin{bmatrix}\n1\\\\\n0\\\\\n0\n\\end{bmatrix}\n\\]\nbecause we know for certainty (100\\%) that Fredo is in the first state.\nThe next iteration of the power method is $\\x_1=A\\x_0/\\|A\\x_0\\|_1$. But since $\\|A\\x_0\\|_1=1$, this is just\n\\[\n\\x_1 = A \\x_0 = \\begin{bmatrix}\n0.25\\\\\n0.25\\\\\n0.50\n\\end{bmatrix},\n\\]\nwhich is exactly Fredo's state distribution after 1 jump.\nAfter two jumps, Fredo's state distribution is\n\\[\n\\x_2 = A \\x_1 = A^2 \\x_0 = \\begin{bmatrix}\n0.4375\\\\\n0.3542\\\\\n0.2083\n\\end{bmatrix},\n\\]\nwhich is also the second iteration of the power method.\nAfter a large number of jumps, we have\n\\[\n\\x_n = A \\x_{n-1} = \\dots = A^n \\x_0 \\approx \\begin{bmatrix}\n0.4\\\\\n0.3\\\\\n0.3\n\\end{bmatrix}.\n\\]\nThus, the limiting vector of the power method is exactly the unique stable fixed point of the Markov chain. \n\n\\subsection*{A final example}\nConsider the Markov chain with transition matrix\n\\[\nA = \\begin{pmatrix}\n0.5 & 0.3 & 0.4\\\\\n0.2 & 0.2 & 0.3\\\\\n0.3 & 0.5 & 0.3\n\\end{pmatrix}.\n\\]\n\nBecause all entries of $A$ are positive, the Markov chain has a unique stable fixed point. \nWe could find this fixed point with the power method as outlined above, or we can do it by computing eigenvalues and eigenvectors in Python, as shown below.\n\\begin{lstlisting}\n>>> from scipy import linalg as la\n>>> A = np.array([[.5,.3,.4],[.2,.2,.3],[.3,.5,.3]])\n>>> evals, evecs = la.eig(A)\n>>> evals\narray([ 1.        ,  0.14142136, -0.14142136])\n\\end{lstlisting}\nWe are interested in the eigenvalue 1, which is the first one outputted in this case. \nThe corresponding eigenvector is the first column of \\li{evecs}; let us call it \\li{x}.\n\\begin{lstlisting}\n>>> x = evecs[:,0]\n\\end{lstlisting}\nNow, the one-norm of \\li{x} will probably not be 1. To make it 1, we divide by the one-norm of \\li{x}.\n\\begin{lstlisting}\n>>>x = x/np.sum(x)\n\\end{lstlisting}\nFinally, let us check that \\li{x} is a stable fixed point of $A$. There are two things to check.\n\\begin{lstlisting}\n# Check Ax = x\n>>> np.allclose(A.dot(x),  x)\nTrue\n\n# Check ||x||_1 = 1\n>>> np.sum(x)==1\nTrue\n\\end{lstlisting}\n\n\\begin{problem}\nWrite a function that accepts as input a transition matrix, a vector representing the initial state, and a number of iterations \\li{niter}. Your function should\n\\begin{enumerate}\n\\item Assume that the input matrix has a unique stable fixed point.\n\\item Calculate the unique stable fixed point by computing eigenvectors and eigenvalues in Python.\n\\item Return the current state of the Markov chain after \\li{niter} iterations and the stable fixed point.\n\\end{enumerate}\n\\label{prob:markov}\n\\end{problem}\n\n\\begin{problem}\nSuppose a basketball player's success at shooting free throws can be described with the following Markov chain\n\\[\nA = \\begin{pmatrix}.75&.50\\\\.25&.50\\end{pmatrix}\n\\]\nwhere the first state corresponds to success and the second state to failure. Use the function you wrote in Problem \\ref{prob:markov} to answer the following questions.\n\\begin{enumerate}\n\\item If the player makes his first free throw, what is the probability that he also makes his third one? \n(That is, what is the probability that this system starts in state 1 and is still in state 1 after 3 steps?)\n\\item What is the player's average free throw percentage? \n(This is equal to the success-component of the stable fixed point.)\n\\end{enumerate}\n\\label{prob:markov_freethrow}\n\\end{problem}\n\n\\begin{comment}\n\\begin{problem}\nConsider the Markov process given by the transition diagram in Figure \\ref{fig:markov2}.\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{markov2}\n\\caption{Transition diagram}\n\\label{fig:markov2}\n\\end{figure}\n\n\\begin{enumerate}\n\\item Find the transition matrix.\n\\item If the Markov process is in state 1 initially, find the probability that it is in state 2 after two transitions.\n\\item Find the stable fixed point if it exists.\n\\end{enumerate}\n\\label{prob:markov_stablept}\n\\end{problem}\n\\end{comment}", "meta": {"hexsha": "67b31dc8d1ad75515f5333b6c70b1d3a1ae335a3", "size": 11768, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/MarkovChains/Markov.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/MarkovChains/Markov.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/MarkovChains/Markov.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 43.2647058824, "max_line_length": 324, "alphanum_fraction": 0.719153637, "num_tokens": 3731, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256631249077, "lm_q2_score": 0.8757870029950159, "lm_q1q2_score": 0.7372599745524547}}
{"text": "\\section{Functions and Polynomials}\n\n\\subsection{Floor function}\n\nThe floor function $\\lfloor x \\rfloor$ yields greatest integer\nleq to argument. For positive values, equivalent to rounding down (truncating decimals).\nFor negative values, equivalent to next lowest negative integer.\n\n\\begin{example}\n    $$\\lfloor -3.2 \\rfloor = -4$$\n\\end{example}\n\nA useful simplification is\n\n\\begin{equation}\n    \\lfloor x \\rfloor = \\lfloor y+k \\rfloor\n\\end{equation}\n\nwhere $y$ is an integer and $0 \\leq k < 1$. An alternate definition\nis\n\n\\begin{equation}\n    \\lfloor x \\rfloor = x - \\{x\\}\n\\end{equation}\n\nwhere $\\{x\\}$ is the fractional component of $x$.\n\n\\subsection{Change of base formula}\n\nExpress a logarithm in base $b$ using logarithms of base $d$.\nLet $d,a,b\\in \\R$ s.t $d,b\\neq 1$.\n\n\\begin{equation}\n    \\log _{b} a=\\frac{\\log _{d} a}{\\log _{d} b}\n\\end{equation}\n\n\\subsection{Polynomial division}\n\n\\begin{definition}[Polynomial remainder theorem]\n    Upon dividing any polynomial $P(x)$ by linear polynomial $x-a$, the remainder is $P(a)$.\n\\end{definition} \n\nWe can express $P(x)$ as the following\n\n\\begin{equation}\n    P(x)=(x-a)Q(x)+R(x)\n\\end{equation}\n\nwhere $x-a$ is the dividend, $Q(x)$ is the quotient and $R(x)$ is the remainder.\nAlso, $\\operatorname{deg} R(x)<\\operatorname{deg}(x-a)$, hence $R(x)\\in \\R$.\n\nThe general approach is $P(x)=D(x)Q(x)-R(x)\\implies R(x)=D(x)Q(x)-P(x)$.\nFind zeros of $D(x)$ to eliminate $Q(x)$ and thus find $R(x)$ through substitution into $-P(x)$.\n\n\\subsection{Inverse functions}\n\n\\begin{definition}[Inverse of a function]\n    Let $f(x):A\\to B$ with range $C$. The inverse is $f^{-1}(x):C\\to A$ iff $f$ is injective (i.e. a distinct one-to-one mapping from every value in $A$ to $C$).\n    Can verify via horizontal line test.\n\\end{definition}\n\nThe properties are $f(f^{-1}(x))=x$ and $f^{-1}(f(x))=x$", "meta": {"hexsha": "abd6612e319ae3d28ee1c11ebd84281da5f5d162", "size": 1833, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "competitive-math/tex/functions-poly.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "competitive-math/tex/functions-poly.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "competitive-math/tex/functions-poly.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.564516129, "max_line_length": 161, "alphanum_fraction": 0.6781232951, "num_tokens": 590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.7372539463227397}}
{"text": "\t\\subsubsection*{FLGV$\\Rightarrow$ FLLPV}\n\tConstruct \\boldmath $A'=\n\t\\begin{pmatrix}\n\tA\\ I\n\t\\end{pmatrix}$ where $I$ is identity matrix. Use algorithm for FLGV on $A'$ and $b$. Then we have exact one of the following:\n\t\\begin{enumerate}\n\t\t\\item $\\exists x'\\in \\mathbb{R}^{n+m}:x'\\geq 0,A'x'=b$.\\\\ Let $x'=\\begin{pmatrix}\n\t\tx\\\\x''\n\t\t\\end{pmatrix}$,$x\\in \\mathbb{R}^n,x''\\in \\mathbb{R}^m$.\\\\ So we have $b=A'x'=Ax+Ix''=Ax+x''\\geq Ax$, thus $x\\geq 0,Ax\\leq b$\n\t\t\\item $\\exists y\\in \\mathbb{R}^{m}:A'^Ty\\geq 0,b^Ty<0$.\\\\ So we have $\\left\\{\\begin{aligned}\n\t\tA^Ty\\geq& 0\\\\\n\t\tI^Ty\\geq& 0\n\t\t\\end{aligned}\\right.$, thus $y\\geq0,A^Ty\\geq 0,b^Ty<0$\n\t\\end{enumerate}\n\t\\subsubsection*{FLLPV$\\Rightarrow$ FLGV}\n\tConstruct \\boldmath $A'=\n\t\\begin{pmatrix}\n\tA\\\\ -A\n\t\\end{pmatrix}$,$b'=\\begin{pmatrix}\n\tb\\\\ -b\n\t\\end{pmatrix}$. Use algorithm for FLLPV on $A'$ and $b'$. Then we have exact one of the following:\n\t\\begin{enumerate}\n\t\t\\item $\\exists x\\in \\mathbb{R}^n:x\\geq 0,A'x\\leq b'$.\\\\ So we have $\\left\\{\\begin{aligned}\n\t\tAx\\leq& b\\\\\n\t\t-Ax\\leq& -b\n\t\t\\end{aligned}\\right.$, thus $x\\geq 0,Ax=b$\n\t\t\\item $\\exists y'\\in \\mathbb{R}^{2m}:y'\\geq 0,A'^Ty'\\geq 0,b^Ty'<0$.\\\\ Let $y'=\\begin{pmatrix}\n\t\ty_1\\\\ y_2\n\t\t\\end{pmatrix}$,where $y_1\\in \\mathbb{R}^m,y_2\\in \\mathbb{R}^m$.\\\\ So we have $A'^Ty'=A^Ty_1-A^Ty_2=A^T(y_1-y_2)\\geq 0$, $b'^Ty'=b^Ty_1-b^Ty_2=b^T(y_1-y_2)<0$.\\\\ Let $y\\in \\mathbb{R}^m,y=y_1-y_2$, thus $A^Ty\\geq 0,b^Ty<0$\n\t\\end{enumerate}\n\t\\subsubsection*{FLEV$\\Rightarrow$ FLLPV}\n\tConstruct \\boldmath $A'=\n\t\\begin{pmatrix}\n\tA\\\\ -I\n\t\\end{pmatrix}$ where $I$ is identity matrix, $b'=\\begin{pmatrix}\n\tb\\\\ 0\n\t\\end{pmatrix}$. Use algorithm for FLEV on $A'$ and $b'$. Then we have exact one of the following:\n\t\\begin{enumerate}\n\t\t\\item $\\exists x\\in \\mathbb{R}^n:A'x\\leq b'$.\\\\ So we have $\\left\\{\\begin{aligned}\n\t\tAx\\leq b\\\\\n\t\t-Ix\\leq 0\n\t\t\\end{aligned}\\right.$, thus $x\\geq 0,Ax\\leq b$\n\t\t\\item $\\exists y'\\in \\mathbb{R}^{n+m}:y'\\geq 0,A'^Ty'= 0,b'^Ty'<0$.\\\\ Let $y'=\\begin{pmatrix}\n\t\ty\\\\y''\n\t\t\\end{pmatrix},y\\in \\mathbb{R}^m,y''\\in \\mathbb{R}^n$.\\\\ So we have $A'^Ty'=A^Ty-Iy''=0$, $b'^Ty'=b^Ty<0$, thus $y\\geq0,A^Ty\\geq 0,b^Ty<0$\n\t\\end{enumerate}\n\t\\subsubsection*{FLLPV$\\Rightarrow$ FLEV}\n\tConstruct \\boldmath $A'=\n\t\\begin{pmatrix}\n\tA\\ \\ -A\n\t\\end{pmatrix}$. Use algorithm for FLLPV on $A'$ and $b$. Then we have exact one of the following:\n\t\\begin{enumerate}\n\t\t\\item $\\exists x'\\in \\mathbb{R}^{2n}:x'\\geq 0,A'x'\\leq b$.\\\\ Let $x'=\\begin{pmatrix}\n\t\tx_1\\\\ x_2\n\t\t\\end{pmatrix}$, where$x_1\\in \\mathbb{R}^n,x_2\\in \\mathbb{R}^n$.\\\\ So we have $A'x'=Ax_1-Ax_2=A(x_1-x_2)\\leq b$. \\\\Let $x\\in \\mathbb{R}^n,x=x_1-x_2$, thus $Ax\\leq b$\n\t\t\\item $\\exists y\\in \\mathbb{R}^m:y\\geq 0,A'^Ty\\geq 0,b^Ty<0$.\\\\ So we have $\\left\\{\\begin{aligned}\n\t\tA^Ty\\geq& 0\\\\\n\t\t-A^Ty\\geq& 0\n\t\t\\end{aligned}\\right.$, thus $A^Ty=0,b^Ty<0$\n\t\\end{enumerate}\n", "meta": {"hexsha": "124854393ee3c3604403813853f7929f9ac44a0d", "size": 2805, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Week 5/source/qwdxzj/ex7.tex", "max_stars_repo_name": "PrayStarJirachi/Algorithm-Homework", "max_stars_repo_head_hexsha": "22ec83e6d4a202d994a177e3dcbfd9225736666f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Week 5/source/qwdxzj/ex7.tex", "max_issues_repo_name": "PrayStarJirachi/Algorithm-Homework", "max_issues_repo_head_hexsha": "22ec83e6d4a202d994a177e3dcbfd9225736666f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Week 5/source/qwdxzj/ex7.tex", "max_forks_repo_name": "PrayStarJirachi/Algorithm-Homework", "max_forks_repo_head_hexsha": "22ec83e6d4a202d994a177e3dcbfd9225736666f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.9836065574, "max_line_length": 222, "alphanum_fraction": 0.6124777184, "num_tokens": 1333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730775, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7371836335526653}}
{"text": "\\section{Convexity, Lipschitzness, and Smoothness}\n\\frame{\\tableofcontents[currentsection, hideothersubsections]}\n\n\\begin{frame}\n\\frametitle{Convexity: Convex sets}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.35]{cvx_noncvx}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.4]{cvx_set}\n\\end{figure}\n\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Convexity: Convex functions}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.35]{cvx_fn}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.4]{cvx_fn_def}\n\\end{figure}\n\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Convexity: Convex functions}\n\nProperties of convex fn:\n\\begin{itemize}\n    \\item  every local minimum is also a global minimum\n    \\item  for every $\\mathbf{w}$ we can construct a tangent to $f$\n    at $\\mathbf{w}$ that lies below $f$ everywhere.\n    If f is differentiable, this tangent is the linear function\n    % $l(u) = f(w) + h∇f (w), u − wi$\n\\end{itemize}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.25]{cvx_fn_tangent}\n\\end{figure}\n\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Convexity: Convex functions}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.35]{lemma_12_3}\n\\end{figure}\n\n\\noindent\\makebox[\\linewidth]{\\rule{\\paperwidth}{0.4pt}}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.375]{claim_12_4}\n\\end{figure}\n\n\\noindent\\makebox[\\linewidth]{\\rule{\\paperwidth}{0.4pt}}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.375]{claim_12_5}\n\\end{figure}\n\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitle{Lipschitzness}\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.45]{def_12_6}\n\\end{figure}\n\nProperties:\n\\begin{itemize}\n    \\item a Lipschitz function can \\textbf{not} change too fast\n    \\item if the derivative of $f$ is everywhere bounded (in absolute value) by $\\rho$,\n        then the function is $\\rho$-Lipschitz.\n    \\item \\textbf{composition} of Lipschitz functions \\textbf{preserves} Lipschitzness.\n\\end{itemize}\n\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitle{Smoothness}\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.45]{def_12_8}\n\\end{figure}\n\nProperties:\n\\begin{itemize}\n    \\item when a function is \\textbf{both} convex and smooth,\\\\\n        we have both \\textbf{upper and lower bounds} on the difference between\n        the function and its first order approximation.\n    \\item a \\text{composition} of a smooth scalar function over a linear function \\textbf{preserves} smoothness.\n    \\begin{figure}\n        \\centering\n        \\includegraphics[scale=0.225]{claim_12_9}\n    \\end{figure}\n\\end{itemize}\n\n\\end{frame}\n", "meta": {"hexsha": "89ca5f3be82e1fa296847c136f81b614e38a0600", "size": 2615, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "talk/tor/cvx-sgd-20180316/cvx.tex", "max_stars_repo_name": "tttor/robot-foundation", "max_stars_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "talk/tor/cvx-sgd-20180316/cvx.tex", "max_issues_repo_name": "tttor/robot-foundation", "max_issues_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "talk/tor/cvx-sgd-20180316/cvx.tex", "max_forks_repo_name": "tttor/robot-foundation", "max_forks_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5431034483, "max_line_length": 112, "alphanum_fraction": 0.7093690249, "num_tokens": 839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7371836273794792}}
{"text": "\\problemname{Infinite Slides}\nAgneta and Beata are visiting the famous Swedish Amusement Park of Infinite Fun and Games.\nTheir favourite attraction is the Infinitely Long Slides.\nEach slide can be viewed as an infinitely long, completely vertical spiral of radius $1$.\n\nWhen projected into the (flat) ground, the first slide has $(0, 0)$ as its centre point, and the second one has $(1, 0)$ as its centre point.\nFurthermore, the start of the slides are at $(1, 0)$ and $(2, 0)$ respectively, and then proceeds counter-clockwise around their respective centres.\nWhen Agneta rides her slide (the first one), she does so with vertical speed $1\\text{ m/s}$, while Beatas slide has a bit higher gradient, so she goes with vertical speed $2\\text{ m/s}$.\nHowever, their angular speeds around the centre is both equal to $1 \\text{ rad/s}$.\nSince Beata is a little afraid of the slides, she always waits for Agneta to go first.\n$W$ seconds after Agneta went, Beata starts her descent.\n\nTo make the infinite ride a bit more fun, the amusement park gives a price if the two riders on the slides manage to pass a ball between them at some point.\nThis price consists of a lot of chocolate, which is Beata's favourite treat.\nTo maximize their chances of passing the ball successfully, they want to wait until their Euclidean distance is the smallest possible during the ride.\nHow small will this distance be?\n\n\\section*{Input}\nThe first and only line of the input contains the decimal number $0 \\le W \\le 1000$.\nThe number contains at most $6$ digits after the decimal point.\n\n\\section*{Output}\nOutput a single number -- the minimal Euclidean distance between Agneta and Beata during their trip.\nYour answer will be accepted if it is within a relative or absolute error of $10^{-4}$ of the judges' answer.\n", "meta": {"hexsha": "48021e4e0849ea8b86c8fa7fbc5d3d1783083169", "size": 1792, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "infiniteslides/problem_statement/problem.en.tex", "max_stars_repo_name": "jsannemo/hiq-challenge-2017", "max_stars_repo_head_hexsha": "8271c716fe249674d585731f472b64616370300a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "infiniteslides/problem_statement/problem.en.tex", "max_issues_repo_name": "jsannemo/hiq-challenge-2017", "max_issues_repo_head_hexsha": "8271c716fe249674d585731f472b64616370300a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "infiniteslides/problem_statement/problem.en.tex", "max_forks_repo_name": "jsannemo/hiq-challenge-2017", "max_forks_repo_head_hexsha": "8271c716fe249674d585731f472b64616370300a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 71.68, "max_line_length": 186, "alphanum_fraction": 0.7706473214, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7371326181504746}}
{"text": "\\subsection{Introduction}\r\nRSA (inventors: Rivest-Shamir-Adleman) belongs to PKCS (public key cryptosystem) where a pair of keys are required, one to encrypt another to decrypt the encrypted one. Encryption means changing a message to another using such a popular rule using some secret value (that no one but the person who is encrypting knows) no one can understand. In case of PKCS it is asymmetric cryptographic algorithm means one key is kept secret (private key) and another one is sent to everyone (public key) for decryption. The keys are long enough to make the adversary break both the keys.\r\n\r\n\\subsection{Property}\r\nThe security of RSA depends on the strengths of two separate functions. The RSA cryptosystem is most popular public-key cryptosystem strength of which is based on the practical difficulty of factoring the very large numbers.\r\n\r\n\\begin{itemize}\r\n\\item \\textbf{Encryption Function:} It is considered as a one-way function of converting plaintext into ciphertext and it can be reversed only with the knowledge of private key d.\r\n\\item \\textbf{Key Generation:} The difficulty of determining a private key from an RSA public key is equivalent to factoring the modulus n. An attacker thus cannot use knowledge of an RSA public key to determine an RSA private key unless he can factor n. It is also a one way function, going from p \\& q values to modulus n is easy but reverse is not possible.\r\n\\end{itemize}\r\n\r\nIf either of these two functions are proved non one-way, then RSA will be broken. In fact, if a technique for factoring efficiently is developed then RSA will no longer be safe.\r\n\r\nThe strength of RSA encryption drastically goes down against attacks if the number p and q are not large primes and (or) chosen public key e is a small number.\r\n\r\n\\subsection{Algorithm}\r\n\\begin{enumerate}\r\n\\item Choose two different large random prime numbers $p$ and $q$\r\n\\item Calculate Maximum range of considered numbers: $$ n = p \\times q $$\r\n\\item Calculate Euler's totient or Carmichael's totient (number of $+(ve)$ coprimes that are less than the given numbers): $$ \\phi(n) = (p - 1) \\times (q - 1) $$\r\n\\item Choose a random number in the range $[2, \\phi(n))$ that is co-prime with both $n$ and $\\phi(n)$; two numbers $a$ and $b$ are are co-prime means they have no common factor \\textit{i.e.} $$ gcd(a, b) = 1 $$\r\n\\item Compute $d$ to satisfy the congruence relation\r\n$$ d \\times e \\equiv 1 \\mod \\phi(n) $$\r\nor $$ d \\times e = 1 + k \\times \\phi(n) $$\r\nor $$ d = \\frac{1 + k \\times \\phi(n)}{e} $$\r\n\\item Private Key \\{$d, n$\\} is kept secret to decrypt the encrypted message after receiving from others and Public Key \\{$e, n$\\} is sent to everyone in the network to encrypt the encrypted message sent to the person who shared the public key.\r\n\\item Sender side encryption:\r\n$$ c = m ^ e \\mod n $$\r\n\\item Reciever side decryption:\r\n$$ m = c ^ d \\mod n $$\r\n\\item Afterwards they changed $\\phi(n)$ to $\\lambda(n)$ where,\r\n$$ \\lambda(n) = lcm(p - 1, q - 1) $$\r\n\r\n\\end{enumerate}\r\n\r\n\\subsection{Application}\r\nSuppose Alice uses Bob's public key to send him an encrypted message. In the message, she can claim to be Alice but Bob has no way of verifying that the message was actually from Alice since anyone can use Bob's public key to send him encrypted messages. So, in order to verify the origin of a message, RSA can also be used to sign a message.\r\n\r\nSuppose Alice wishes to send a signed message to Bob. She produces a hash value of the message, raises it to the power of d mod n (just like when decrypting a message), and attaches it as a \\q(signature) to the message. When Bob receives the signed message, he raises the signature to the power of e mod n (just like encrypting a message), and compares the resulting hash value with the message's actual hash value. If the two agree, he knows that the author of the message was in possession of Alice's secret key, and that the message has not been tampered with since.\r\n\r\nNote that secure padding schemes such as RSA-PSS are as essential for the security of message signing as they are for message encryption, and that the same key should never be used for both encryption and signing purposes.\r\n\r\n\\subsection{Citing}\r\nThere is a nice description in wikipedia ~\\cite{wiki_rsa} and ~\\cite{geeks4geeks_rsa}. The real paper ~\\cite{rsa_rsa} and the paper ~\\cite{milanov_rsa} helps making the code ourselves.\r\n", "meta": {"hexsha": "0746f5b201f73ddc0fcddb89d070f09ee33809f9", "size": 4379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/thesis/doc_src/rsa.tex", "max_stars_repo_name": "TheScienceUniverse/BlockChain", "max_stars_repo_head_hexsha": "03c33fabfa702fad7f6e3a9de5757a2ccda2d909", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/thesis/doc_src/rsa.tex", "max_issues_repo_name": "TheScienceUniverse/BlockChain", "max_issues_repo_head_hexsha": "03c33fabfa702fad7f6e3a9de5757a2ccda2d909", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/thesis/doc_src/rsa.tex", "max_forks_repo_name": "TheScienceUniverse/BlockChain", "max_forks_repo_head_hexsha": "03c33fabfa702fad7f6e3a9de5757a2ccda2d909", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 97.3111111111, "max_line_length": 575, "alphanum_fraction": 0.7494861841, "num_tokens": 1058, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603709, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7371326136988242}}
{"text": "\\documentclass{article}\n\\usepackage{color}\n\\usepackage{bigints}\n\\usepackage[italicdiff]{physics}\n\\color{white}\n\\definecolor{Blue}{RGB}{0,33,71}\n\\begin{document}\n\\pagecolor{Blue}\n\\title{Solution to Mathemaddict\\textsc{\\char13}s Problem}\n\\author{Jose Bedoya}\n\\maketitle\n\\section{Question}\n{\\LARGE\n$$I=\\bigintss_{1}^{\\infty} \\frac{2x\\{x\\}-\\{x\\}^2}{x^2\\lfloor x\\rfloor^2}\\,dx=\\frac{\\pi^A}{B}-\\phi^C$$\n\n\\vspace{4mm}\nThen,\n$$L=\\lim_{\\theta\\to C} \\frac{\\sin\\left(A\\theta\\right)\\sec \\left(\\theta\\right)}{B\\theta}=\\,?$$\n\n\\vspace{3mm}\nNote: $\\{x\\}=x-\\lfloor x\\rfloor$\n}\n\\section{Solution}\n{\\Large\nLet\\textsc{\\char13}s expand the integral using the definition of the fractional part\n$$I=\\bigintsss_{1}^{\\infty}\\frac{2x^2-2x\\lfloor x\\rfloor-x^2+2x\\lfloor x\\rfloor-\\lfloor x\\rfloor^2}{x^2\\lfloor x\\rfloor^2}\\,dx $$\n\n\\vspace{5mm}\nSimplifying and by the definition of the floor function \n$$I=\\sum_{k=1}^{\\infty}\\bigintsss_{k}^{k+1}\\frac{1}{k^2}-\\frac{1}{x^2}\\,dx$$\n\n\\vspace{4mm}\nTherefore,\n\\newpage\n$$I=\\sum_{k=1}^{\\infty}\\left(\\frac{x}{k^2}\\Big|_k^{k+1}+\\frac{1}{x}\\Big|_k^{k+1}\\right)$$\n$$=\\sum_{k=1}^{\\infty}\\left(\\frac{1}{k^2}+\\frac{1}{k+1}-\\frac{1}{k}\\right)$$\n\n\\vspace{3mm}\nEvaluating the series we get\n$$I=\\frac{\\pi^2}{6}-1$$\n\n\\vspace{3mm}\nClearly,\n$$A=2,\\,B=6,\\, C=0$$\n\n\\vspace{5mm}\nSubstituting in the limit, we get\n$$\\lim_{\\theta\\to0} \\frac{\\sin\\left(2\\theta\\right)\\sec\\left(\\theta\\right)}{6\\theta}=\\frac{1}{3}$$\n\n\\vspace{3mm}\nOur final answer is\n}\n{\\LARGE\n$$L=\\frac{1}{3}$$\n}\n\\end{document} ", "meta": {"hexsha": "a2dfd565d0016d05bc0411bc0255dd03bb74e3b8", "size": 1487, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/Jose Bedoya's questions/Integral with fractional part (2).tex", "max_stars_repo_name": "Nanu00/LaTeX", "max_stars_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-05-29T17:22:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T18:47:05.000Z", "max_issues_repo_path": "Calculus/Jose Bedoya's questions/Integral with fractional part (2).tex", "max_issues_repo_name": "Nanu00/LaTeX", "max_issues_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-06-26T07:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-11T12:14:49.000Z", "max_forks_repo_path": "Calculus/Jose Bedoya's questions/Integral with fractional part (2).tex", "max_forks_repo_name": "Shreenabh664/LaTeX", "max_forks_repo_head_hexsha": "675e03f3ec555456b9a2cc714825ec75317848c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-06-22T07:50:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-08T05:11:14.000Z", "avg_line_length": 26.5535714286, "max_line_length": 129, "alphanum_fraction": 0.661735037, "num_tokens": 643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.7371300909474129}}
{"text": "\\documentclass{article}\n%\\usepackage{fullpage}\n%\\usepackage{nopageno} \n\\usepackage[margin=1.5in]{geometry}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage[normalem]{ulem}\n\\usepackage{fancyhdr}\n%\\renewcommand\\headheight{12pt}\n\\pagestyle{fancy}\n\\lhead{March 5, 2014}\n\\rhead{Jon Allen}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\section*{Chapter 4}\n\\subsection*{\\#43}\nLet $X=\\{a,b,c,d,e,f\\}$ and let the relation $R$ on $X$ be defined by $a\\,R\\,b,b\\,R\\,c,c\\,R\\,d,a\\,R\\,e,e\\,R\\,f,f\\,R\\,d$. Verify that $R$ is the cover relation of a partially ordered set, and determine all the linear extensions of this partial order.\n\\begin{align*}\n  a<_cb<_cc<_cd\\\\\n  a<_ce<_cf<_cd\n\\end{align*}\nLooks like $R$ is a cover relation since no elements can fit between any others, and all the elements are accounted for. I'll list the linear extensions now. These are basically all the combinations that have $a$ and $d$ on the ends and that respect $b<c, e<f$\n\\begin{align*}\n  a<b<c<e<f<d\\\\\n  a<b<e<c<f<d\\\\\n  a<b<e<f<c<d\\\\\n  a<e<b<c<f<d\\\\\n  a<e<b<f<c<d\\\\\n  a<e<f<b<c<d\n\\end{align*}\n\\subsection*{\\#50}\nConsider the partially ordered set $(X,\\subseteq)$ of subsets of the set $X=\\{a,b,c\\}$ of three elements. How many linear extensions are there?\n\nThere is one set of no elements, 3 sets of 1 and 2 elements each, and one set of three elements. The number of linear extensions is the number of ways we can arrange the 1 and 2 element sets multiplied together. So $(3!)^2$ or 36.\n\\section*{Chapter 5}\n\\subsection*{\\#22}\nProve that, for all real number $r$ and all integers $k$ and $m$,\n\\[\\binom{r}{m}\\binom{m}{k}=\\binom{r}{k}\\binom{r-k}{m-k}\\]\nI'll just let the algebra speak for itself\n\\begin{align*}\n  \\binom{r}{m}\\binom{m}{k}&=\\frac{r(r-1)\\dots(r-m+1)}{m!}\\cdot\\frac{m!}{k!(m-k)!}\\\\\n  &=\\frac{r(r-1)\\dots(r-k+1)(r-k)(r-k-1)\\dots(r-m+1)}{k!(m-k)!}\\\\\n  &=\\frac{r(r-1)\\dots(r-k+1)}{k!}\\frac{(r-k)(r-k-1)\\dots(r-m+1)}{(m-k)!}\\\\\n  &=\\binom{r}{k}\\frac{(r-k)(r-k-1)\\dots((r-k)-(m-k)+1)}{(m-k)!}\\\\\n  &=\\binom{r}{k}\\binom{r-k}{m-k}\\\\\n\\Box\n\\end{align*}\n\\subsection*{\\#25}\nUse a combinatorial argument to prov the \\emph{Vandermonde convolution} for the binomial coefficients: For all positive integers $m_1,m_2$ and $n$,\n\\[\\sum\\limits_{k=0}^n{\\binom{m_1}{k}\\binom{m_2}{n-k}}=\\binom{m_1+m_2}{n}\\]\nDeduce the identity (5.16) as a special case.\n\\subsubsection*{proof}\nLet $S$ be a set with $m_1+m_2$ elements.\nThe right side counts the number of $n$-subsets of $S$.\nWe partition $S$ into two subsets, $A$ and $B$, of $m_1$ and $m_2$ elements respectively.\nWe use this partition of $S$ to partition the $n$ subsets of $S$.\nEach $n$-sized subset of $S$ contains $k$ elements from $A$ and $n-k$ elements from $B$.\nHere, $k$ may be any integer between $0$ and $n$.\nWe partition the $n$-subsets of $S$ into $n+1$ parts,\n\\[C_0,C_1,C_2,\\dots,C_n,\\]\nWhere $C_k$ consists of those $n$-subsets which contain $k$ elements from $A$ and $n-k$ elements from $B$. By the addition principle,\n\\[\\binom{m_1+m_2}{n}=\\abs{C_0}+\\abs{C_1}+\\abs{C_1}+\\dots+\\abs{C_n}.\\]\nAn $n$-subset in $C_k$ is obtained by choosing $k$ elements from $A$ (there are $\\binom{m_1}{k}$ choice) and then $(n-k)$ elements from $B$ (there are $\\binom{m_2}{n-k}$ choices).\nHence by the multiplication principle,\n\\[\\abs{C_k}=\\binom{m_1}{n}\\binom{m_2}{n-k},\\quad(k=0,1,\\dots,n)\\]\nCombining our last two equations, we have our result\n\\[\\sum\\limits_{k=0}^n{\\binom{m_1}{k}\\binom{m_2}{n-k}}=\\binom{m_1+m_2}{n}\\]\n$\\Box$\n\nDeducing $\\sum\\limits_{k=0}^n{\\binom{n}{k}^2}=\\binom{2n}{n},\\quad(n\\ge 0)$ is pretty straightforward. We just have to set $m_1=m_2=n$ and then we have $m_1+m_2=2n$. Since $\\binom{n}{k}=\\binom{n}{n-k}$\n\\begin{align*}\n  \\sum\\limits_{k=0}^n{\\binom{m_1}{k}\\binom{m_2}{n-k}}=\\binom{m_1+m_2}{n}\\\\\n  \\sum\\limits_{k=0}^n{\\binom{n}{k}\\binom{n}{n-k}}=\\binom{2n}{n}\\\\\n  \\sum\\limits_{k=0}^n{\\binom{n}{k}\\binom{n}{k}}=\\binom{2n}{n}\\\\\n  \\sum\\limits_{k=0}^n{\\binom{n}{k}^2}=\\binom{2n}{n}\\\\\n\\end{align*}\n\\subsection*{\\#26}\nLet $n$ and $k$ be integers with $1\\le k\\le n$. Prove that\n\\[\\sum\\limits_{k=0}^n{\\binom{n}{k}\\binom{n}{k-1}=\\frac{1}{2}\\binom{2n+2}{n+1}-\\binom{2n}{n}}\\]\n\\subsection*{\\#29}\nFind and prove a formula for\n\\[\\sum\\limits_{r,s,t\\ge 0}{\\binom{m_1}{r}\\binom{m_2}{s}\\binom{m_3}{t}}\\]\n\\[r+s+t=n\\]\nThe formula is:\n\\[\\binom{m_1+m_2+m_3}{n}=\\sum\\limits_{r,s,t\\ge 0}{\\binom{m_1}{r}\\binom{m_2}{s}\\binom{m_3}{t}}\\]\n\\subsubsection*{proof}\nImagine we have a set $S$ partitioned into parts $A,B$ and $C$ sized $m_1,m_2$ and $m_3$ respectively. We can grab $n$ elements from $S$ in $\\binom{m_1+m_2+m_3}{n}$ different ways. Now lets take some positive integers $r,s,t$ such that $r+s+t=n$. Lets imagine that when we grab our $n$ elements, that $r$ of them come from $A$, $s$ from $B$ and $t$ from $C$. The number of ways we can do this is $\\binom{m_1}{r}\\binom{m_2}{s}\\binom{m_3}{t}$. Now if we wish to count all the ways we can grab those $n$ elements we must sum $\\binom{m_1}{r}\\binom{m_2}{s}\\binom{m_3}{t}$ for all values of $r,s$ and $t$, which is $\\sum\\limits_{r,s,t\\ge 0}{\\binom{m_1}{r}\\binom{m_2}{s}\\binom{m_3}{t}}$. And so we see the formulas must be equal.$\\Box$\n\\subsection*{\\#43}\nProve by induction on $n$ that, for $n$ a positive integer,\n\\[\\frac{1}{(1-z)^n}=\\sum\\limits_{k=0}^\\infty{\\binom{n+k-1}{k}z^k},\\quad\\abs{z}<1.\\]\nAssume the validity of\n\\[\\frac{1}{1-z}=\\sum\\limits_{k=0}^\\infty{z^k},\\quad\\abs{z}<1.\\]\nYou may use a combinatorial proof instead of induction.\n\\begin{align*}\n  \\frac{1}{(1-z)^n}=\\sum\\limits_{k=0}^\\infty{\\binom{n+k-1}{k}z^k}\\\\\n  \\frac{1}{(1-z)^{n+1}}=\\frac{1}{(1-z)^n(1-z)}\\\\\n  \\frac{1}{(1-z)^{n+1}}=\\sum\\limits_{k=0}^\\infty{\\binom{n+k-1}{k}\\frac{z^k}{1-z}}\\\\\n  \\frac{1}{(1-z)^{n+1}}=\\sum\\limits_{k=0}^\\infty{\\frac{(n+k-1)(n+k-2)\\dots(n+1)n}{k!(n+k-1-k)!}\\frac{z^k}{1-z}}\\\\\n  \\frac{1}{(1-z)^{n+1}}=\\sum\\limits_{k=0}^\\infty{\\frac{(n+k)(n+k-1)\\dots(n+2)(n+1)}{k!(n+k-k)!}z^k}\\\\\n  \\frac{1}{(1-z)^{n+1}}=\\sum\\limits_{k=0}^\\infty{\\frac{(n+k-1+1)(n+k-2+1)\\dots(n+1+1)(n+1)}{k!(n+k-1-k+1)!}z^k}\\\\\n\\end{align*}\n\\subsection*{\\#46}\nUse Newton's binomial theorem to approximate $\\sqrt{30}$. You may use the formula on p. 149.\n\\begin{align*}\n  \\sqrt{30}=\\sqrt{25+5}&=5(1+0.2)^{1/2}=1+\\sum\\limits_{k=1}^\\infty{\\frac{(-1)^{k-1}}{k\\cdot2^{2k-1}}\\binom{2k-2}{k-1}0.2^k}\\\\\n  &=5\\left(1+\\frac{1}{2}0.2-\\frac{1}{2\\cdot2^3}\\binom{2}{1}0.2^2+\\frac{1}{3\\cdot2^5}\\binom{4}{2}0.2^3-\\dots\\right)\\\\\n  &\\approx5.4775\n\\end{align*}\n\\subsection*{\\#47}\nUse Newton's binomial theorem to approximate $10^{1/3}$. It should be sufficient to evaluate 1/3 choose $k$ for $k=0,1,2,3$\n\\begin{align*}\n  \\sqrt[3]{10}&=\\sqrt[3]{8(1+0.25)}=2\\sqrt[3]{1+0.25}\\\\\n  &=2(1+0.25)^{1/3}\\\\\n  &=2\\cdot\\sum\\limits_{k=0}^\\infty{\\binom{1/3}{k}0.25^k}\\\\\n  &=2+2\\cdot\\sum\\limits_{k=1}^\\infty{\\binom{1/3}{k}0.25^k}\\\\\n  &=2+2\\frac{1}{3}\\cdot\\frac{1}{4}+2\\cdot\\sum\\limits_{k=2}^\\infty{\\binom{1/3}{k}0.25^k}\\\\\n  &=2+\\frac{1}{6}+2\\frac{\\frac{1}{3}\\cdot-\\frac{2}{3}}{2}\\left(\\frac{1}{4}\\right)^2+2\\cdot\\sum\\limits_{k=3}^\\infty{\\binom{1/3}{k}0.25^k}\\\\\n  &=2+\\frac{1}{6}-\\frac{1}{72}+2\\frac{\\frac{1}{3}\\cdot-\\frac{2}{3}\\cdot-\\frac{5}{3}}{3!}\\left(\\frac{1}{4}\\right)^3+2\\cdot\\sum\\limits_{k=4}^\\infty{\\binom{1/3}{k}0.25^k}\\\\\n  &=2+\\frac{1}{6}-\\frac{1}{72}+\\frac{5}{27\\cdot6}\\left(\\frac{1}{4}\\right)^2+2\\cdot\\sum\\limits_{k=4}^\\infty{\\binom{1/3}{k}0.25^k}\\\\\n  &=2+\\frac{1}{6}-\\frac{1}{72}+\\frac{5}{2592}+2\\cdot\\sum\\limits_{k=4}^\\infty{\\binom{1/3}{k}0.25^k}\\\\\n  &\\approx2.1547+2\\cdot\\sum\\limits_{k=4}^\\infty{\\binom{1/3}{k}0.25^k}\\\\\n\\end{align*}\n\\subsection*{\\#48}\nUse theorem 5.6.1 to show that, if $m$ and $n$ are positive integers, then a partially ordered set of $mn+1$ elements has a chain of size $m+1$ or an antichain of size $n+1$.\n\\subsection*{\\#50}\nConsider the partially ordered set $(X,\\mid)$ on the set $X=\\{1,2,\\dots,12\\}$ of the first 12 positive integers, partially ordered by ``is divisible by.''\n\\subsubsection*{(a)}\nDetermine a chain of largest size and a partition of $X$ into the smallest number of antichains.\n\\subsubsection*{(b)}\nDetermine an antichain of largest zise and a partition of $X$ into the smallest number of chains.\n\\end{document}\n", "meta": {"hexsha": "57b7337cdcc27176994f870ea29e28a5b878638e", "size": 8099, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combinatorics/combinatorics-hw-2014-03-05.tex", "max_stars_repo_name": "ylixir/school", "max_stars_repo_head_hexsha": "66d433f2090b6396c8dd2a53a733c25dbe7bc90f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "combinatorics/combinatorics-hw-2014-03-05.tex", "max_issues_repo_name": "ylixir/school", "max_issues_repo_head_hexsha": "66d433f2090b6396c8dd2a53a733c25dbe7bc90f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "combinatorics/combinatorics-hw-2014-03-05.tex", "max_forks_repo_name": "ylixir/school", "max_forks_repo_head_hexsha": "66d433f2090b6396c8dd2a53a733c25dbe7bc90f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.9925925926, "max_line_length": 728, "alphanum_fraction": 0.639708606, "num_tokens": 3516, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.8652240756264639, "lm_q1q2_score": 0.7371300723080786}}
{"text": "\n\\subsection{The fixed effects estimator}\n\\subsubsection{Recap on the model}\n\nOur model is:\n\n\\(y_{ij}=\\alpha + X_{ij}\\theta + \\xi_j + \\epsilon_{ij}\\)\n\n\\subsubsection{The fixed effects estimator}\n\nWith fixed effects we assume that \\(U_{ij}\\) is a constant for each group. That is:\n\n\\(U_{ij}=\\delta_{ij}U_j\\)\n\n\\(y_{ij}=\\alpha + X_{ij}\\theta +\\epsilon_{ij}+\\delta_{ij}U_{j}\\)\n\nWe can use this in a regression if the standard assumptions of OLS are met. In particular, that group membership is uncorrelated with the error term.\n\nWe add these dummies to \\(X_{ij}\\) and regress:\n\n\\(y_{ij}=\\alpha + X_{ij}\\theta +\\epsilon_{ij}\\)\n\nThe parameter for the dummy is the fixed effect of group membership.\n\nAs we are including membership in the dependent variables, there is no problem if group membership correlates with other independent variables.\n\n\\subsubsection{Using the within and between transformations}\n\n\\((y_{ij}-\\bar y_{i})=(X_{ij}-\\bar X_{i})\\theta +(U_{ij} -\\bar U_{i}) +(\\epsilon_{ij}-\\bar \\epsilon_{i})\\)\n\nOr:\n\n\\(\\ddot y_{ij}=\\ddot X_{ij}\\theta +\\ddot \\epsilon_{ij}\\)\n\nThis this get the same outcome, but is a different computational process.\n\n", "meta": {"hexsha": "2abfd98c0bca2af1122296832fbf80e3c27ccbcf", "size": 1146, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/generalLinearModels/03-02-fixed.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/generalLinearModels/03-02-fixed.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/generalLinearModels/03-02-fixed.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.972972973, "max_line_length": 149, "alphanum_fraction": 0.7164048866, "num_tokens": 329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7370736555988396}}
{"text": "\\chapter{Completions}\n\t\\setlist[enumerate,1,2]{leftmargin=1.8cm}\n\tIn this chapter we are intended to do \\textit{elementary calculus} with a heavy taste of algebra instead of analysis. A lot of concepts in analysis are stolen by algebraists with different generalisations.\n\t\\section{Absolute value}\n\t\tLet $K$ be a field. An \\textbf{absolute value} on $K$ is a function $K \\to \\mathbb{R}$, $x \\mapsto |x|_v$ satisfying the following three properties:\n\t\t\\begin{enumerate}[start=1,label={\\bfseries AV \\arabic*}]\n\t\t\t\\item We have $|x|_v \\ge 0$ and $=0$ if and only if $x = 0$.\n\t\t\t\\item For all $x,y \\in K$ we have $|xy|_v = |x|_v|y|_v$.\n\t\t\t\\item $|x+y|_v \\le |x|_v + |y|_v$. \\label{av3}\n\t\t\\end{enumerate}\n\t\n\t\tIf instead of \\ref{av3} the absolute value satisfies the stronger condition\n\t\t\\begin{enumerate}[start=4,label={\\bfseries AV \\arabic*}]\n\t\t\t\\item $|x+y|_v \\le \\max(|x|_v,|y|_v)$\n\t\t\\end{enumerate}\n\t\tthen we shall say that it is a \\textbf{valuation} or that it is non-archimedean. in particular, if the absolute value $|\\cdot|$ satisfy $|x|=1$ for all $x \\ne 0$, then we say $|\\cdot|$ is \\textbf{trivial}. We will exclude this case from now on. Our first goal is to study many possible valuations in general and in $\\Q$. We are more interested in non-archimedean case because it \\textit{breaks} our common sense in algebra:\n\t\t\\begin{theorem}\n\t\t\tAn absolute value $|\\cdot|$ is non-archimedean if and only if there exists $M>0$ such that $|n \\cdot 1|<M$ for all $n \\in \\N$.\n\t\t\\end{theorem}\n\t\t\\begin{proof}\n\t\t\tIf $|\\cdot|$ is non-archimedean, then\n\t\t\t\\[\n\t\t\t\t|n| = |1+\\cdots+1| \\le 1, \\forall n \\in \\N.\n\t\t\t\\]\n\t\t\t\n\t\t\tConversely, pick $x,y \\in K$ and suppose $|x| \\ge |y|$. Then\n\t\t\t\\[\n\t\t\t\t\\begin{aligned}\n\t\t\t\t\t|x+y|^n &= |(x+y)^n| \\\\\n\t\t\t\t\t\t\t&= \\left|\\sum_{j=0}^{n}{n \\choose j}x^jy^{n-j}\\right| \\\\\n\t\t\t\t\t\t\t&\\le \\sum_{j=0}^{n}\\left|{n \\choose j} \\right||x|^j|y|^{n-j} \\\\\n\t\t\t\t\t\t\t&\\le M(n+1)|x|^n.\n\t\t\t\t\\end{aligned}\n\t\t\t\\]\n\t\t\tHence\n\t\t\t\\[\n\t\t\t\t|x+y| \\le \\left(M(1+n)\\right)^{1/n}|x| \\to |x| \\quad (n \\to \\infty).\n\t\t\t\\]\n\t\t\\end{proof}\n\t\tIf $K$ is a infinite dimensional space, then this is not a big deal, but if we put $K=\\Q$, does it make sense? Normally we would think the norm should grow bigger as $n$ grows.\n\t\n\t\\section{Polynomials in complete fields}", "meta": {"hexsha": "e8fdb7b6b417f8c6c4d9221d65db2603c7790dfd", "size": 2242, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/Ch02.tex", "max_stars_repo_name": "Admiraldesvl/algebraic-number-theory-note", "max_stars_repo_head_hexsha": "95afd3f2d8b52e317af7382860f58bbe4195b0c8", "max_stars_repo_licenses": ["ECL-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/Ch02.tex", "max_issues_repo_name": "Admiraldesvl/algebraic-number-theory-note", "max_issues_repo_head_hexsha": "95afd3f2d8b52e317af7382860f58bbe4195b0c8", "max_issues_repo_licenses": ["ECL-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-07-27T00:20:07.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-27T10:40:49.000Z", "max_forks_repo_path": "Chapters/Ch02.tex", "max_forks_repo_name": "Admiraldesvl/algebraic-number-theory-note", "max_forks_repo_head_hexsha": "95afd3f2d8b52e317af7382860f58bbe4195b0c8", "max_forks_repo_licenses": ["ECL-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-26T15:24:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-26T15:24:03.000Z", "avg_line_length": 53.380952381, "max_line_length": 425, "alphanum_fraction": 0.6409455843, "num_tokens": 831, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7370210699900107}}
{"text": "\\section{Approach}\\label{approach}\nGene expression data are usually represented by the matrix $X = x_{ij}$ of the expression profiles of $i$ genes and $j$ individuals or sample tissues. \nThe main goal of the approach described in the current section is to infer the network topology that regulates the main interactions of the genes under investigation. \nGenerally speaking, a network model is formed by a set of vertices $G$, representing the genes in our specific case, and a set of edges $E$ representing pairwise interactions. The existence of edge $(i,j)$ represents the conditional dependency between gene $i$ and gene $j$.  If such an edge is not present, the two genes are considered conditionally independent, in the symbolic representation $(G_i \\perp G_j) | G_k, \\forall k \\neq j$.\nIn the specific application described in this paper, we aim at finding the best set of neighbours associated to each gene. We interpret the biological meaning of genetic associations within the terms specified by regression analysis. Regressing the expression value of a gene (\\emph{response}) against the remaining ones in the dataset (\\emph{independent variables}) leads to selecting a subset of the most influential genes associated with the response.\nRegardless of the number of mathematical models that have been considered for inferring the association between variables in genetics, linear regression is a type of analysis that has found large consensus in the field of computational biology due to its simplicity of modelling (\\citealp{linregression2, linregression1}). %Moreover, the capabilities of linear regression can be extended to other genetic compounds from the field of proteomics, metabolomics, methylation etc. [move to intro]\nOne limitation of linear regression methods prevails in assuming a linear dependency between variables, a hypothesis that does not always apply in biology. One strategy to overcome such a limitation consists of splitting the problem of learning the topology of the entire network of genes into a number of smaller linear problems. This can be achieved by regressing each covariate against all the remaining ones.  Such a strategy, which has been used first in the work reported in (\\citealp{Meinshausen06highdimensional}) makes the assumption of linearity more suitable to the analysis of biological data.  Assuming the presence of linearities on a local scale is a much more convincing and appropriate conjecture that might find an application to data from genomics and proteomics.\nAnother limitation that researchers have to take into account appears in the case of high-dimensional data. In such a scenario, the number of genes is usually some orders of magnitude larger than the number of the individuals. \nPenalised regression has been considered as a way to circumvent such limitation due to the presence of a penalty factor that encourages sparsity of the final network.\nSpecifically, Lasso is one such regression method that converts the problem of estimating the covariance matrix into an optimisation problem in which a convex function, applied to each variable, is minimised.\n\nGiven $X_i$ the expression of gene $i$ and the expression profiles of the remaining genes  (referred to as $X$, for simplicity), the Lasso-based estimate consists of providing a solution for Equation \\ref{eq:lasso}\n  \n\\begin{equation}\n\\label{eq:lasso}\n    \\hat{\\Theta}^{a,\\lambda} = \n    \\argmin_{%\n      \\substack{%\n        \\text{s.\\,t.}\\, \\Theta:\\Theta_a = 0 \\\\\n        \\phantom{}\\, \n      }\n    }\n    (\\frac{1}{n} \\| X_i - X\\Theta \\|^{2}_2 + \\lambda \\| \\Theta \\|_1)\n  \\end{equation}\n  \nThe vector of regression coefficients $\\Theta$ determines the conditional independence structure between variables. The $l_1$-norm of the coefficient vector tends to shrink the coefficients of some variables to zero, removing them from the set of selected variables associated to the response, as extensively explained in (\\citealp{Tibshirani94regressionshrinkage}). \nThe right choice of the shrinkage factor $\\lambda$ is crucial to controlling the rate of false positives and false negatives. Regardless of the number of approaches to approximate the optimal $\\lambda$, reported in (\\citealp{adalasso, efron2004, tuneparamsel}), a reliable estimate that is widely used in practice is provided by cross-validation (\\citealp{glmnet}). \nWe use a 3-fold cross validation approach and estimate $\\hat{\\lambda_{cv}}$ from a subset of the data. Cross-validation can be a time consuming task especially when applied to datasets with a high number of covariates. Therefore, we estimate the shrinkage factor that minimises the expected generalisation error, for a grid of $\\lambda$ values, on the $10\\%$ of the total number of genes. The R package $glmnet$ has been used to provide such an estimate.  \n\nThe method we describe in this paper is a two-step approach that recursively performs the regression of Equation \\ref{eq:lasso} for each gene, considered as response, with respect to all remaining genes, considered as independent variables. The response gene is not included in the set of independent variables. Regardless of biological evidence that supports the existence of self interactions and positive/negative feedback loops within regulatory networks (\\citealp{netmotif, avrahamfeedback2011, generegmodel}), those are not considered here, in order to avoid complex interactions and simplify as much as possible the inferred network topology.\n\n\\textbf{In step 1}, the set $S$ of variables associated with the current response gene is selected. We use a Lasso method that does not fit the intercept. As explained, the choice of the optimal $\\lambda$ occurs prior to this stage.\n\n\\textbf{In step 2}, we use a permutation-based approach to assess the significance of the associated edges detected in step 1. The values of the response variables are permuted a number of times specified as parameter. For each permutation we count how many times each variable within the set $S$ of selected genes has been selected again. At the end of the permutation test, the variables with the smallest counter are selected as the best candidate variables associated with the current response gene. \n\nThis approach is supported by the fact that after permuting the response variable, the genes selected at step 1 should be no longer associated and therefore should be considered as selected by chance. \n\n\\begin{algorithm}\n \\begin{algorithmic}[1]\n \\Procedure{lasso2net}{$X_i,X, B, fanout, best$}\n \\State $fit \\gets lasso.cv(X_i,X$)\n \\State $\\lambda_{cv} \\gets fit.lambda$\n \\State $S \\gets fit.coeffs$\n \\State $S \\gets sort(S, decreasing)[1:best] $ \n \\While{$r < B$}\n \\State $X^{perm}_i \\gets permute(X_i)$\n \\State $permfit \\gets lasso(X^{perm}_i, X, \\lambda_{cv}$)\n \\State $update(counter[S])$  update counters of selected variables \n \\State $r\\gets r+1$\n \\EndWhile\n \\State $sel\\gets sort(counter[S], increase)[1:fanout] $ order and select first fanout\n %\\Comment{variables sorted by increasing order of counter}\n \\State \\textbf{return} $sel$ \n \\EndProcedure\n \\end{algorithmic}\n \\caption{Variable selection and permutation-based stability test}\n \\label{algo:perm}\n\\end{algorithm}\n\nThe procedure we propose is summarised in Algorithm \\ref{algo:perm}. \nIt selects the $best$ number of genes associated to the current response. Namely, the vector of the associated genes is sorted in decreasing order and the first $best$ are selected (\\emph{line 5}). The parameter $best$ can be tuned in order to select a variable number of strong genetic effects according to the type of disease under investigation and the dataset at the researcher's disposal which, in turn, might determine the amount of significant genetic compounds to be considered for further analysis.   \nAt each permutation, the counters of the selected variables are updated (\\emph{line 9}) and after $B$ permutations the first $fanout$ genes are selected. These variables represent the most stable genes associated with the response variable (\\emph{line 12}).\n\nFor large values of $B$ we perform an additional significance test for the smallest  counter. A critical case to deal with occurs whenever different covariates are selected with similar frequency. This phenomenon in turns produces uniform values of counters for a high number of selected variables. Lasso-based regression methods are affected by issues of this type due to the fact that one from a group of highly correlated variables can be randomly selected at each permutation. To mitigate such side effects, we compute the empirical distribution of the counters of the selected covariates regressed against each permuted response. The p-value of the smallest counter is calculated from the aforementioned empirical distribution. We found that a significance level of $0.05$ improves the precision (calculated as $\\frac{TP}{TP+FP}$ ) by $3\\%$.\n\nThe algorithm described above finds a solution of Equation \\ref{eq:lasso} for each response variable. Subsequently, it finds the most stable non-zero regression coefficients associated to each gene. \nConsequently, when the described procedure is performed on the entire set of genes, an adjacency matrix can be built directly from the counters of selected variables. The aforementioned adjacency matrix can be used to visualise the network topology of the inferred network of interactions. \nSince we are interested in discovering genetic interactions we convert the non-zero values of the adjacency matrix to $1$, in order to denote the presence of an edge in the graph.\nAs one would expect, the method does not guarantee the adjacency matrix to be symmetric. A symmetrisation procedure would be required before further analysis or visualisation of the predicted network. \n\nA number of approaches that perform matrix symmetrisation have been proposed in \\citealp{wna}. Given two nodes $i$ and $j$ and the weights of the edges $M_{ij}$ and $M_{ji}$, the symmetric adjacency matrix can be built by taking the average value as in $M_{ij} = M_{ji} = mean(\\frac{M_{ij}+M{ji}}{2})$; by selecting the largest weight $M_{ij} = M_{ji} = max(M_{ij}, M_{ji})$; or by selecting the smallest weight  $M_{ij} = M_{ji} = min(M_{ij}, M{ji})$. \nFor a binary adjacency matrix, in which each entry represents the presence or absence of the edge $(i,j)$, the AND rule will set $M_{ij} = M_{ji} = (M_{ij} \\land M_{ji})$.\nIn order to detect a generic association between nodes $i$ and $j$, we symmetrise the adjacency matrix by applying the $OR$ rule which considers two variables as associated if only one of the two variables is associated with the other. Namely,\n$M_{ij} = M_{ji} = (M_{ij} \\vee M_{ji})$.\n\nThe main goal of the work described here is to detect the structure of the network of the main genetic associations, passing over the magnitude of interaction and its direction. \n\n", "meta": {"hexsha": "028cf1cd75ae0c2b38226d4ecc4107f23020b83d", "size": 10835, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LABnet bioinformatics/approach.tex", "max_stars_repo_name": "worldofpiggy/academic-papers", "max_stars_repo_head_hexsha": "a9ad707cf504e6460ebc0ec53e6217156726022a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-10-31T19:39:38.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-31T19:39:38.000Z", "max_issues_repo_path": "LABnet bioinformatics/approach.tex", "max_issues_repo_name": "worldofpiggy/academic-papers", "max_issues_repo_head_hexsha": "a9ad707cf504e6460ebc0ec53e6217156726022a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LABnet bioinformatics/approach.tex", "max_forks_repo_name": "worldofpiggy/academic-papers", "max_forks_repo_head_hexsha": "a9ad707cf504e6460ebc0ec53e6217156726022a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 138.9102564103, "max_line_length": 846, "alphanum_fraction": 0.7844946931, "num_tokens": 2413, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541643004809, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.7369973730004667}}
{"text": "\\section{Sequences}\n\nSum for finite arithmetic series with starting value $a$:\n\n\\begin{equation}\n    \\frac{2a+(n-1)d}{2}\\cdot n\n\\end{equation}\n\nSum for infinite geometric series:\n\n\\begin{equation}\n    \\frac{a}{1-r}\n\\end{equation}\n\nSum for finite geometric series:\n\n\\begin{equation}\n    \\frac{a(1-r^n)}{1-r}\n\\end{equation}", "meta": {"hexsha": "e871280affd7d515b26acb5dfc83233f47edf07b", "size": 321, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "competitive-math/tex/sequences.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "competitive-math/tex/sequences.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "competitive-math/tex/sequences.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.8947368421, "max_line_length": 57, "alphanum_fraction": 0.691588785, "num_tokens": 106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465044347828, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.7369886825928897}}
{"text": "\\section{Normal Form Games and Nash Equilibria}\n\\label{gth-sect}\n\nThe idea of {\\em game} as model of strategic interaction was first\nintroduced by von Neumann \\cite{vn28}. A {\\em finite normal form game} is\n$\\Gamma=(P,S,u)$ where both $P$ and $S$ are finite.\nHere $P$ is the set of {\\em players}, and $S=\\times_{p\\in P} S_p$ is\nthe set of {\\em pure strategy profiles}, where $S_p$ is the set of\n{\\em pure strategies} of player~$p$.\nThe aim of each player $p\\in P$ is to maximize their\n{\\em payoff function} $u^p:S\\to\\reals$.\nThe vector of payoffs is $u=\\times_{p\\in P}u^p$.\nBy ``game'' we will always mean ``finite normal form game.''\nA {\\em mixed strategy} of player $p$ is a probability\ndistribution on $S_p$. It can be described as a point on the\n$(|S_p|-1)$-dimensional {\\em mixed strategy simplex}\n% you used subscript for the dimension earlier and should\n% not use it for the player; hence superscript\n\\[\n\\Delta^p=\\{ x\\in\\reals^{|S_p|}\\ \\mid\\ x\\geq\\0,\\ \\1\\T x = 1 \\}.\n\\]\nThe set of {\\em mixed strategy profiles} is the simplicial polytope\n$\\Delta=\\times_{p\\in P}\\Delta^p$.\nWe extend the payoff functions to $u^p:\\Delta\\to\\reals$ linearly.\nA {\\em Nash equilibrium} of a game is a strategy profile in which each\nplayer cannot improve their expected payoff by unilaterally changing their\nstrategy; such a strategy is called a {\\em best response}.\nNotice that applying a positive affine transformation to all the payoffs\ndoes not change the Nash equilibria of the game.\nThe following ``best-response condition'' is useful and easy\nto show (e.g., Nash \\cite{nash}).\n\n\\begin{proposition}\n\\label{br-played-thm}\nA mixed strategy $x\\in \\Delta^p$ is a best response against some mixed\nstrategy profile $y\\in \\times_{q\\neq p}\\Delta^{q}$ of the other players\nif and only if\nevery pure strategy $s_i\\in S_p$ chosen with positive probability\nin $x$ is a best response to $y$.\n\\end{proposition}\n\nThe existence of a Nash equilibrium is guaranteed by\nthe fundamental theorem by Nash (\\cite{nash}). Notice that there can be\nmore than one equilibrium.\n\n\\begin{theorem}{\\rm (Nash \\cite{nash})}\\label{nash-thm}\nEvery finite game in normal form has at least one Nash equilibrium.\n\\end{theorem}\n\n{\\em Bimatrix games} are games with only two players. They can be\n% characterized by  % \"characterized\" suggests a theorem\ndescribed by\ntwo $m \\times n$ payoff matrices $A$ and $B$, where $a_{ij}$ and $b_{ij}$ are\nthe payoffs of respectively player 1 and of player 2 when the former plays\nher $i$th pure strategy and the latter plays his $j$th pure\nstrategy, and $m=|S_1|$ and $n=|S_2|$.\nA bimatrix game is {\\em zero-sum} if $B=-A$, and {\\em symmetric} if  $B=A\\T$.\nWe give two classic examples of bimatrix games: the prisoners' dilemma and\nthe coordination game.\n\n\\begin{example}\nIn the symmetric non zero-sum {\\em prisoners' dilemma} of\nTable~\\ref{prisoners-dilemma}, each player must\ndecide whether to ``help'' the other one or to ``betray'' them. If both\nplayers help each other, they will get a small reward. If both betray, they\nwill pay a small penalty. If one betrays and the other cooperate the former\nwill get a large reward and the latter will pay a large penalty.\nThe only equilibrium is the profile in which both players betray.\nIf player~2 betrays, the best response of player~1 is to betray, since\nit gives her payoff 1 instead of 0. If player~2 helps, her payoff\nfor betraying is 3 and her payoff for helping is 2, so betraying is\nagain the best response. The same holds for player~2, so at the\nequilibrium both players will betray.\n\n\\begin{table}[hbt]\n\\begin{center}\n\\def\\mm#1{\\makebox(0,0){\\strut#1}}\n\\bimatrixgame{3mm}{2}{2}{1}{2}\n{{\\scriptsize betray}{\\scriptsize help}}\n{{\\scriptsize betray}{\\scriptsize help}}\n{\n\\payoffpairs{1}{{1}{3}}{{1}{0}}\n\\payoffpairs{2}{{0}{2}}{{3}{2}}\n}\n\\end{center}\n\\caption[The prisoners' dilemma]{The prisoners' dilemma.}\n\\label{prisoners-dilemma}\n\\end{table}\n\nTable~\\ref{coordination-game} shows a {\\em coordination} game.\nBoth players can\n% match the Table description\ndrive on either a mountain or a valley road. They lose if\nthey drive on the same road and win if they avoid each\nother, regardless of which road they take.\nThe pure strategy Nash equilibria are (mountain,~valley) and\n(valley,~mountain). There is also a symmetric equilibrium in\nmixed strategies which can be represented as the vectors of probabilities\n$((1/2,1/2),(1/2,1/2))$.\n\n\\begin{table}[hbt]\n\\begin{center}\n\\def\\mm#1{\\makebox(0,0){\\strut#1}}\n\\bimatrixgame{3mm}{2}{2}{{{\\small 1}}}{{{\\small 2}}}\n{{\\scriptsize mountain}{\\scriptsize valley}}\n{{\\scriptsize mountain}{\\scriptsize valley}}\n{\n\\payoffpairs{1}{{0}{1}}{{0}{1}}\n\\payoffpairs{2}{{1}{0}}{{1}{0}}\n}\n\\end{center}\n\\caption[A coordination game]{A coordination game.}\n\\label{coordination-game}\n\\end{table}\n\\end{example}\n", "meta": {"hexsha": "331f54562312ff521eae3e78d493555834d02e90", "size": 4774, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chapter-1/games.tex", "max_stars_repo_name": "mmcasetti/mphil-thesis", "max_stars_repo_head_hexsha": "6d9902c4f813cf3239d1b312e9453b3ea690c3db", "max_stars_repo_licenses": ["OLDAP-2.4"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "thesis/chapter-1/games.tex", "max_issues_repo_name": "mmcasetti/mphil-thesis", "max_issues_repo_head_hexsha": "6d9902c4f813cf3239d1b312e9453b3ea690c3db", "max_issues_repo_licenses": ["OLDAP-2.4"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thesis/chapter-1/games.tex", "max_forks_repo_name": "mmcasetti/mphil-thesis", "max_forks_repo_head_hexsha": "6d9902c4f813cf3239d1b312e9453b3ea690c3db", "max_forks_repo_licenses": ["OLDAP-2.4"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.1551724138, "max_line_length": 77, "alphanum_fraction": 0.7314620863, "num_tokens": 1422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035763237924, "lm_q2_score": 0.8499711699569786, "lm_q1q2_score": 0.7369554020738802}}
{"text": "\\lab{Gradient Descent Methods}{Gradient Descent Methods}\n\n\\objective{Iterative optimization methods choose a search direction and a step size at each iteration.\nOne simple choice for the search direction is the negative gradient, resulting in the method of steepest descent.\nWhile theoretically foundational, in practice this method is often slow to converge.\nAn alternative method, the conjugate gradient algorithm, uses a similar idea that results in much faster convergence in some situations.\nIn this lab we implement a method of steepest descent and two conjugate gradient methods, then apply them to regression problems.\n}\n\n\\section*{The Method of Steepest Descent} % ===================================\n\nLet $f:\\mathbb{R}^n \\rightarrow \\mathbb{R}$ with first derivative $Df:\\mathbb{R}^n \\rightarrow \\mathbb{R}^n$.\n% (by convention, $Df(\\x)$ is a row vector).\nThe following iterative technique is a common template for methods that aim to compute a local minimizer $\\x^*$ of $f$.\n% Many optimization methods fall under the umbrella of descent algorithms.\n% These algorithms utilize an initial guess, a direction on which the objective function decreases, and a step size to perform a line search for the next point in the iteration.\n% This can be mathematically formulated at the $k$th iteration with the following:\n\\begin{equation}\n\\x_{k+1} = \\x_k + \\alpha_{k}\\mathbf{p}_k\n\\label{eq:gradientmethods-linesearch}\n\\end{equation}\nHere $\\x_k$ is the $k$th approximation to $\\x^*$, $\\alpha_k$ is the \\emph{step size}, and $\\mathbf{p}_k$ is the \\emph{search direction}.\nNewton's method and its relatives follow this pattern, but they require the calculation (or approximation) of the inverse Hessian matrix $Df^2(\\x_k)^{-1}$ at each step.\nThe following idea is a simpler and less computationally intensive approach than Newton and quasi-Newton methods.\n\nThe derivative $Df(\\x)\\trp$ (often called the \\emph{gradient} of $f$ at $\\x$, sometimes notated $\\nabla f(\\x)$) is a vector that points in the direction of greatest \\textbf{increase} of $f$ at $\\x$.\nIt follows that the negative derivative $-Df(\\x)\\trp$ points in the direction of steepest \\textbf{decrease} at $\\x$.\nThe \\emph{method of steepest descent} chooses the search direction $\\p_k = -Df(\\x_k)\\trp$ at each step of \\eqref{eq:gradientmethods-linesearch}, resulting in the following algorithm.\n\\begin{equation}\n\\x_{k+1} = \\x_k - \\alpha_{k}Df(\\x_k)\\trp\n\\label{eq:gradientmethods-steepest-descent}\n\\end{equation}\n\nSetting $\\alpha_k = 1$ for each $k$ is often sufficient for Newton and quasi-Newton methods.\nHowever, a constant choice for the step size in \\eqref{eq:gradientmethods-steepest-descent} can result in oscillating approximations or even cause the sequence $(\\x_k)_{k=1}^\\infty$ to travel away from the minimizer $\\x^*$.\nTo avoid this problem, the step size $\\alpha_k$ can be chosen in a few ways.\n\\begin{itemize}\n    \\item Start with $\\alpha_k = 1$, then set $\\alpha_k = \\frac{\\alpha_k}{2}$ until $f(\\x_k - \\alpha_k Df(\\x_k)\\trp) < f(\\x_k)$, terminating the iteration if $\\alpha_k$ gets too small.\n    This guarantees that the method actually descends at each step and that $\\alpha_k$ satisfies the Armijo rule, without endangering convergence.\n\n    \\item At each step, solve the following one-dimensional optimization problem.\n    \\[\n    \\alpha_k = \\underset{\\alpha}{\\text{argmin}}\\ f(\\x_k - \\alpha Df(\\x_k)\\trp)\n    \\]\n    Using this choice is called \\emph{exact steepest descent}.\n    This option is more expensive per iteration than the above strategy, but it results in fewer iterations before convergence.\n\\end{itemize}\n\n\\begin{problem} % Implement exact steepest descent.\nWrite a function that accepts an objective function $f:\\mathbb{R}^n\\rightarrow\\mathbb{R}$, its derivative $Df:\\mathbb{R}^n\\rightarrow\\mathbb{R}^n$, an initial guess $\\x_0\\in\\mathbb{R}^n$, a convergence tolerance \\li{tol} defaulting to $1e^{-5}$, and a maximum number of iterations \\li{maxiter} defaulting to $100$.\nImplement the exact method of steepest descent, using a one-dimensional optimization method to choose the step size (use \\li{opt.minimize_scalar()} or your own 1-D minimizer).\nIterate until $\\|Df(\\x_k)\\|_{\\infty} < $ \\li{tol} or $k > $ \\li{maxiter}.\nReturn the approximate minimizer $\\x^*$, whether or not the algorithm converged (\\li{True} or \\li{False}), and the number of iterations computed.\n\nTest your function on $f(x,y,z) = x^4 + y^4 + z^4$ (easy) and the Rosenbrock function (hard).\nIt should take many iterations to minimize the Rosenbrock function, but it should converge eventually with a large enough choice of \\li{maxiter}.\n\\label{prob:gradientmethods-steepest-descent}\n\\end{problem}\n\n\\section*{The Conjugate Gradient Method} % ====================================\n\nUnfortunately, the method of steepest descent can be very inefficient for certain problems.\nDepending on the nature of the objective function, the sequence of points can zig-zag back and forth or get stuck on flat areas without making significant progress toward the true minimizer.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=.7\\textwidth]{figures/steepest.pdf}\n\\caption{On this surface, gradient descent takes an extreme number of iterations to converge to the minimum because it gets stuck in the flat basins of the surface.}\n\\label{basis:steepest}\n\\end{figure}\n\nUnlike the method of steepest descent, the \\emph{conjugate gradient algorithm} chooses a search direction that is guaranteed to be a descent direction, though not the direction of greatest descent.\nThese directions are using a generalized form of orthogonality called \\emph{conjugacy}.\n\nLet $Q$ be a square, positive definite matrix.\nA set of vectors $\\{\\x_0, \\x_1, \\ldots, \\x_m\\}$ is called \\emph{Q-conjugate} if each distinct pair of vectors $\\x_i,\\x_j$ satisfy $\\x_i\\trp Q\\x_j = 0$.\nA $Q$-conjugate set of vectors is linearly independent and can form a basis that diagonalizes the matrix $Q$.\nThis guarantees that an iterative method to solve $Q\\x = \\b$ only require as many steps as there are basis vectors.\n\nSolve a positive definite system $Q\\x = \\b$ is valuable in and of itself for certain problems, but it is also equivalent to minimizing certain functions.\nSpecifically, consider the quadratic function\n\\[\nf(\\x) = \\frac{1}{2}\\x\\trp Q\\x - \\b\\trp\\x + c.\n\\]\nBecause $Df(\\x)\\trp = Q\\x - \\b$, minimizing $f$ is the same as solving the equation\n\\[\n\\0 = Df(\\x)\\trp = Q\\x - \\b\\quad\\Rightarrow\\quad Q\\x = \\b,\n\\]\nwhich is the original linear system.\nNote that the constant $c$ does not affect the minimizer, since if $\\x^*$ minimizes $f(\\x)$ it also minimizes $f(\\x)+c$.\n\n% This technique is very useful for solving large systems of equations in situations where other methods are unsuitable and where the matrix $Q$ is positive definite, which implies invertibility.\n% It works equally well for optimizing convex quadratic functions and can be extended to more general non-linear classes of optimization.\n\n% \\subsection*{The Algorithm} % -----------------------------------------------\n\nUsing the conjugate directions guarantees an iterative method to converge on the minimizer because each iteration minimizes the objective function over a subspace of dimension equal to the iteration number.\nThus, after $n$ steps, where $n$ is the number of conjugate basis vectors, the algorithm has found a minimizer over the entire space.\nIn certain situations, this has a great advantage over gradient descent, which can bounce back and forth.\nThis comparison is illustrated in Figure \\ref{basis:steepVsConj}.\nAdditionally, because the method utilizes a basis of conjugate vectors, the previous search direction can be used to find a conjugate projection onto the next subspace, saving computational time.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=.7\\textwidth]{figures/steepVsConj.pdf}\n\\caption{Paths traced by Gradient Descent (orange) and Conjugate Gradient (red) on a quadratic surface.\nNotice the zig-zagging nature of the Gradient Descent path, as opposed to the Conjugate Gradient path, which finds the minimizer in 2 steps.}\n\\label{basis:steepVsConj}\n\\end{figure}\n\n% Algorithm \\ref{Alg:linear-conjugate-gradient} contains these techniques and outlines an iterative process2 for solving the linear system $Q\\x = \\b$.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{Conjugate Gradient}{$\\x_0$, $Q$, $\\mathbf{b}$, \\li{tol}}\n    % \\State \\textrm{Choose initial point } $\\x_0$.\n    \\State $\\mathbf{r}_0 \\gets Q\\x_0 - \\b$\n    \\State $\\mathbf{d}_0 \\gets -\\mathbf{r}_0$\n    \\State $k \\gets 0$\n    \\While{$\\|\\mathbf{r}_k\\| \\geq $ \\li{tol},\\ $k < n$}\n        \\State $\\alpha_k \\gets \\mathbf{r}_k\\trp \\mathbf{r}_k / \\mathbf{d}_k\\trp Q\\mathbf{d}_k$\n        \\State $\\x_{k+1} \\gets \\x_k + \\alpha_k \\mathbf{d}_k$\n        \\State $\\mathbf{r}_{k+1} \\gets \\mathbf{r}_k + \\alpha_k Q\\mathbf{d}_k$\n        \\State $\\beta_{k+1} \\gets \\mathbf{r}_{k+1}\\trp \\mathbf{r}_{k+1} / \\mathbf{r}_k\\trp \\mathbf{r}_k$\n        \\State $\\mathbf{d}_{k+1} \\gets -\\mathbf{r}_{k+1} + \\beta_{k+1}\\mathbf{d}_k$\n        \\State $k \\gets k+1$.\n    \\EndWhile\n    \\pseudoli{return} $\\x_{k+1}$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\label{Alg:linear-conjugate-gradient}\n\\end{algorithm}\n\nThe points $\\x_k$ are the successive approximations to the minimizer, the vectors $\\mathbf{d}_k$ are the conjugate descent directions, and the vectors $\\mathbf{r}_k$ (which actually correspond to the steepest descent directions) are used in determining the conjugate directions.\nThe constants $\\alpha_k$ and $\\beta_k$ are used, respectively, in the line search, and in ensuring the $Q$-conjugacy of the descent directions.\n\n\\begin{problem} % Conjugate gradient for linear systems.\nWrite a function that accepts an $n \\times n$ positive definite matrix $Q$, a vector $\\b\\in\\mathbb{R}^n$, an initial guess $\\x_0\\in\\mathbb{R}^n$, and a stopping tolerance.\nUse Algorithm \\ref{Alg:linear-conjugate-gradient} to solve the system $Q\\x = \\b$.\nContinue the algorithm until $\\|\\mathbf{r}_k\\|$ is less than the tolerance, iterating no more than $n$ times.\nReturn the solution $\\x$, whether or not the algorithm converged in $n$ iterations or less, and the number of iterations computed.\n\nTest your function on the simple system\n\\[\nQ = \\left[\\begin{array}{cc}2 & 0 \\\\ 0 & 4\\end{array}\\right],\n\\qquad\n\\b = \\left[\\begin{array}{c}1 \\\\ 8\\end{array}\\right],\n\\]\nwhich has solution $\\x^* = \\left[\\frac{1}{2}, 2\\right]\\trp$.\nThis is equivalent to minimizing the quadratic function $f(x,y) = x^2 + 2y^2 - x - 8y$; check that your function from Problem \\ref{prob:gradientmethods-steepest-descent} gets the same solution.\n\nMore generally, you can generate a random positive definite matrix $Q$ for testing by setting setting $Q = A\\trp A$ for any $A$ of full rank.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import linalg as la\n\n# Generate Q, b, and the initial guess x0.\n>>> n = 10\n>>> A = np.random.random((n,n))\n>>> Q = A.T @ A\n>>> b, x0 = np.random.random((2,n))\n\n>>> x = la.solve(Q, b)      # Use your function here.\n>>> np.allclose(Q @ x, b)\n<<True>>\n\\end{lstlisting}\n\\label{prob:gradientmethods-linear-cg}\n\\end{problem}\n\n\\subsection*{Non-linear Conjugate Gradient}\nThe algorithm presented above is only valid for certain linear systems and quadratic functions, but the basic strategy may be adapted to minimize more general convex or non-linear functions.\nThough the non-linear version does not have guaranteed convergence as the linear formulation does, it can still converge in less iterations than the method of steepest descent.\nModifying the algorithm for more general functions requires new formulas for $\\alpha_k$, $\\mathbf{r}_k$, and $\\beta_k$.\n\n\\begin{itemize}\n\\item The scalar $\\alpha_k$ is simply the result of performing a line-search in the given direction $\\mathbf{d}_k$ and is thus defined $\\alpha_k = \\underset{\\alpha}{\\text{argmin}}\\ f(\\x_k + \\alpha \\mathbf{d}_k)$.\n\\item The vector $\\mathbf{r}_k$ in the original algorithm was really just the gradient of the objective function, so now define $\\mathbf{r}_k = Df(\\x_k)\\trp$.\n\\item The constants $\\beta_k$ can be defined in various ways, and the most correct choice depends on the nature of the objective function.\nA well-known formula, attributed to Fletcher and Reeves, is $\\beta_{k} = Df(\\x_k)Df(\\x_{k})\\trp / Df(\\x_{k-1}) Df(\\x_{k-1})\\trp$.\n\\end{itemize}\n%\n% Inserting these adjustments to Algorithm \\ref{Alg:linear-conjugate-gradient} results in the following routine.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{Non-Linear Conjugate Gradient}{$f$,\\ $Df$,\\ $\\x_0$,\\ \\li{tol},\\ \\li{maxiter}}\n    \\State $\\mathbf{r}_0 \\gets -Df(\\x_0)\\trp$\n    \\State $\\mathbf{d}_0 \\gets \\mathbf{r}_0$\n    \\State $\\alpha_0 \\gets \\underset{\\alpha}{\\text{argmin}} f(\\x_0 + \\alpha\\mathbf{d}_0)$\n    \\State $\\x_{1} \\gets \\x_0 + \\alpha_0 \\mathbf{d}_0$\n    \\State $k \\gets 1$\n    \\While{$\\|\\mathbf{r}_k\\| \\geq$ \\li{tol},\\ $k < $ \\li{maxiter}}\n        \\State $\\mathbf{r}_{k} \\gets -Df(\\x_k)\\trp$\n        \\State $\\beta_{k} = \\mathbf{r}_{k}\\trp \\mathbf{r}_k / \\mathbf{r}_{k-1}\\trp \\mathbf{r}_{k-1}$\n        \\State $\\mathbf{d}_{k} \\gets \\mathbf{r}_{k} + \\beta_{k}\\mathbf{d}_{k-1}$.\n        \\State $\\alpha_k \\gets \\underset{\\alpha}{\\text{argmin}}\\ f(\\x_k + \\alpha\\mathbf{d}_k)$.\n        \\State $\\x_{k+1} \\gets \\x_k + \\alpha_k\\mathbf{d}_k$.\n        \\State $k \\gets k+1$.\n    \\EndWhile\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\label{Alg:nonlinear-conjugate-gradient}\n\\end{algorithm}\n\n\\begin{problem}\nWrite a function that accepts a convex objective function $f$, its derivative $Df$, an initial guess $\\x_0$, a convergence tolerance defaultin to $1e^{-5}$, and a maximum number of iterations defaultin to $100$.\nUse Algorithm \\ref{Alg:nonlinear-conjugate-gradient} to compute the minimizer $\\x^*$ of $f$.\nReturn the approximate minimizer, whether or not the algorithm converged, and the number of iterations computed.\n\nCompare your function to SciPy's \\li{opt.fmin_cg()}.\n\\begin{lstlisting}\n>>> opt.fmin_cg(opt.rosen, np.array([10, 10]), fprime=opt.rosen_der)\n<<Optimization terminated successfully.\n         Current function value: 0.000000\n         Iterations: 44\n         Function evaluations: 102>>  # Much faster than steepest descent!\n         <<Gradient evaluations: 102>>\narray([ 1.00000007,  1.00000015])\n\\end{lstlisting}\n\\label{prob:gradientdescent-nonlinear-cg}\n\\end{problem}\n\n\\section*{Regression Problems} % ==============================================\n\nA major use of the conjugate gradient method is solving linear least squares problems.\nRecall that a least squares problem can be formulated as an optimization problem:\n\\[\n\\x^* = \\min_\\x \\|A\\x -\\textbf{ b}\\|_2,\n\\]\nwhere $A$ is an $m \\times n$ matrix with full column rank, $\\x \\in \\mathbb{R}^n$, and $\\b \\in \\mathbb{R}^m$. The solution can\nbe calculated analytically, and is given by\n\\[\n\\x^* = (A\\trp A)^{-1}A\\trp \\b.\n\\]\nIn other words, the minimizer solves the linear system\n\\begin{equation}\nA\\trp A\\x = A\\trp \\b.\n\\label{eq:ls}\n\\end{equation}\nSince $A$ has full column rank, it is invertible, $A\\trp A$ is positive definite, and for any non-zero vector $\\textbf{z}$, $A\\textbf{z}\\neq 0$.\nTherefore, $\\textbf{z}\\trp A\\trp A\\textbf{z} = \\Vert A\\textbf{z} \\Vert^2 > 0$.\nAs $A\\trp A$ is positive definite, conjugate gradient can be used to solve Equation \\ref{eq:ls}.\n\nLinear least squares is the mathematical underpinning of \\emph{linear regression}.\nLinear regression involves a set of real-valued data points \\{$y_1,\\ldots, y_m\\}$, where each\n$y_i$ is paired with a corresponding set of predictor variables $\\{x_{i,1}, x_{i,2}, \\ldots, x_{i,n}\\}$ with $n < m$.\nThe linear regression model posits that\n\\[\ny_i = \\beta_0 + \\beta_1 x_{i,1} + \\beta_2 x_{i,2} + \\cdots + \\beta_n x_{i,n} + \\epsilon_i\n\\]\nfor $i = 1, 2, \\ldots, m$.\nThe real numbers $\\beta_0,\\ldots,\\beta_n$ are known as the parameters of the model, and the $\\epsilon_i$ are independent, normally-distributed error terms.\nThe goal of linear regression is to calculate the parameters that best fit the data.\nThis can be accomplished by posing the problem in terms of linear least squares.\nDefine\n\\[\n\\b = \\left[\\begin{array}{c}y_1 \\\\ \\vdots \\\\ y_m\\end{array}\\right],\n\\quad\nA =\n\\left[\\begin{array}{ccccc}\n1 & x_{1,1} & x_{1,2} & \\cdots & x_{1,n}\\\\\n1 & x_{2,1} & x_{2,2} & \\cdots & x_{2,n}\\\\\n\\vdots & \\vdots & \\vdots & \\ddots & \\vdots\\\\\n1 & x_{m,1} & x_{m,2} & \\cdots & x_{m,n}\n\\end{array}\\right],\n\\quad\n\\x = \\left[\\begin{array}{c}\n    \\beta_0 \\\\ \\beta_1 \\\\ \\vdots \\\\ \\beta_n\n\\end{array}\\right].\n\\]\nThe solution $\\x^* = [\\beta_0^*, \\beta_1^*, \\ldots, \\beta_n^*]\\trp$ to the system $A\\trp A\\x = A\\trp\\b$ gives the parameters that best fit the data.\nThese values can be understood as defining the hyperplane that best fits the data.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=.7\\textwidth]{figures/linregression.pdf}\n\\caption{Solving the linear regression problem results in a best-fit hyperplane.}\n\\label{fig:linregression}\n\\end{figure}\n\n\\begin{problem}\nUsing your function from Problem \\ref{prob:gradientmethods-linear-cg}, solve the linear regression problem specified by the data contained in the file\\footnote{Source: Statistical Reference Datasets website at \\url{http://www.itl.nist.gov/div898/strd/lls/data/LINKS/v-Longley.shtml}.}\n\\texttt{linregression.txt}.\nThis is a whitespace-delimited text file formatted so that the $i$-th row consists of $y_i, x_{i,1}, \\ldots, x_{i,n}$.\nUse \\li{np.loadtxt()} to load in the data and return the solution to the normal equations.\n\\end{problem}\n\n\\subsection*{Logistic Regression} % -------------------------------------------\n\n\\emph{Logistic regression} is another important technique in statistical analysis and machine learning that builds off of the concepts of linear regression.\nAs in linear regression, there is a set of predictor variables $\\{x_{i, 1}, x_{i, 2}, \\dots, x_{i, n}\\}_{i = 1}^{m}$ with corresponding outcome variables $\\{y_i\\}_{i = 1}^{m}$.\nIn logistic regression, the outcome variables $y_i$ are binary and can be modeled by a \\emph{sigmoidal} relationship.\nThe value of the predicted $y_i$ can be thought of as the probability that $y_i = 1$.\nIn mathematical terms,\n\\[\n\\mathbb{P}(y_i = 1 \\, | \\, x_{i,1}, \\dots, x_{i,n}) = p_i,\n\\]\nwhere\n\\[\np_i = \\frac{1}{1+\\exp(-(\\beta_0 + \\beta_1x_{i,1} + \\dots + \\beta_nx_{i,n}))}.\n\\]\nThe parameters of the model are the real numbers $\\beta_0, \\beta_1,\\dots, \\beta_n$.\nNote that $p_i \\in (0, 1)$ regardless of the values of the predictor variables and parameters.\n\nThe probability of observing the outcome variables $y_i$ under this model, assuming they are independent, is given by\nthe \\emph{likelihood function} $\\mathcal{L}:\\mathbb{R}^{n+1} \\rightarrow \\mathbb{R}$\n\\[\n\\mathcal{L}(\\beta_0, \\dots, \\beta_n) = \\prod_{i=1}^m p_i^{y_i}(1-p_i)^{1-y_i}.\n\\]\nThe goal of logistic regression is to find the parameters $\\beta_0, \\dots, \\beta_k$ that maximize this likelihood function.\nThus, the problem can be written as:\n\\[\n\\max_{(\\beta_0,\\dots,\\beta_n)}\\mathcal{L}(\\beta_0, \\dots, \\beta_n).\n\\]\n\nMaximizing this function is often a numerically unstable calculation.\nThus, to make the objective function more suitable, the logarithm of the objective function may be maximized because the logarithmic function is strictly monotone increasing.\nTaking the $\\log$ and turning the problem into a minimization problem, the final problem is formulated as:\n\\[\n\\min_{(\\beta_0,\\dots,\\beta_n)} - \\log\\mathcal{L}(\\beta_0, \\dots, \\beta_n).\n\\]\n\nA few lines of calculation reveal that this objective function can also be rewritten as\n\\begin{align*}\n-\\log\\mathcal{L}(\\beta_0,\\dots,\\beta_n) = &\\sum_{i=1}^{m}\\log(1+\\exp(-(\\beta_0 + \\beta_1x_{i,1} + \\dots +\\beta_nx_{i,n}))) +\\\\\n &\\sum_{i=1}^m (1- y_i)(\\beta_0 + \\beta_1x_{i,1} + \\dots + \\beta_nx_{i,n}).\n\\end{align*}\n\nThe values for the parameters  $\\{\\beta_i\\}_{i = 1}^{n}$ that we obtain are known as the \\emph{maximum likelihood estimate} (MLE).\nTo find the MLE, conjugate gradient can be used to minimize the objective function.\n\nFor a one-dimensional binary logistic regression problem, we have predictor data $\\{x_i\\}_{i=1}^m$ with labels $\\{y_i\\}_{i=1}^m$ where each $y_i \\in \\{0, 1\\}$.\nThe negative log likelihood then becomes the following.\n\\begin{equation}\n-\\log\\mathcal{L}(\\beta_0, \\beta_1) = \\sum_{i=1}^m \\log(1 + e^{-(\\beta_0 + \\beta_1 x_i)}) + (1 - y_i)(\\beta_0 + \\beta_1 x_i)\n\\label{eq:gradientmethods-negative-log-likelihood}\n\\end{equation}\n\n\\begin{problem}\nWrite a class for doing binary logistic regression in one dimension that implement the following methods.\n\\begin{enumerate}\n\\item \\li{fit()}: accept an array $\\x\\in\\mathbb{R}^n$ of data, an array $\\y\\in\\mathbb{R}^n$ of labels ($0$s and $1$s), and an initial guess $\\boldsymbol{\\beta}_0\\in\\mathbb{R}^2$.\nDefine the negative log likelihood function as given in \\eqref{eq:gradientmethods-negative-log-likelihood}, then minimize it (with respect to $\\boldsymbol{\\beta}$) with your function from Problem \\ref{prob:gradientdescent-nonlinear-cg} or \\li{opt.fmin_cg()}.\nStore the resulting parameters $\\beta_0$ and $\\beta_1$ as attributes.\n\n\\item \\li{predict()}: accept a float $x\\in\\mathbb{R}$ and calculate\n\\[\\sigma(x) = \\frac{1}{1 + \\exp(- (\\beta_0 + \\beta_1 x))},\\]\nwhere $\\beta_0$ and $\\beta_1$ are the optimal values calculated in \\li{fit()}.\nThe value $\\sigma(x)$ is the probability that the observation $x$ should be assigned the label $y=1$.\n\\end{enumerate}\nThis class does not need an explicit constructor.\nYou may assume that \\li{predict()} will be called after \\li{fit()}.\n\\label{prob:gradientmethods-logistic-regression}\n\\end{problem}\n\n\\begin{problem}\nOn January 28, 1986, less than two minutes into the Challenger space shuttle's 10th mission, there was a large explosion that originated from the spacecraft, killing all seven crew members and destroying the shuttle.\nThe investigation that followed concluded that the malfunction was caused by damage to O-rings that are used as seals for parts of the rocket engines.\nThere were 24 space shuttle missions before this disaster, some of which had noted some O-ring damage.\nGiven the data, could this disaster have been predicted?\n\nThe file \\texttt{challenger.npy} contains data for 23 missions (during one of the 24 missions, the engine was lost at sea).\nThe first column ($\\x$) contains the ambient temperature, in Fahrenheit, of the shuttle launch.\nThe second column ($\\y$) contains a binary indicator of the presence of O-ring damage (1 if O-ring damage was present, 0 otherwise).\n\nInstantiate your class from Problem \\ref{prob:gradientmethods-logistic-regression} and fit it to the data, using an initial guess of $\\boldsymbol{\\beta}_0 = [20, -1]\\trp$.\nPlot the resulting curve $\\sigma(x)$ for $x \\in [30, 100]$, along with the raw data.\nReturn the predicted probability (according to this model) of O-ring damage on the day the shuttle was launched, given that it was $31^\\circ$F.\n\n\\begin{figure}[H]\n\\centering\n    \\includegraphics[width=.7\\textwidth]{figures/logreg.pdf}\n    % \\caption{The logistic curve models the probability of O-ring damage on the Challenger shuttle. According to this model, given that the temperature was $31^\\circ$ on the day of launch, the shuttle had close to $100\\%$ likelihood of O-ring damage. This model had an initial guess of $1.$ and $-1$ for $\\beta_0$ and $\\beta_1$ respectively.}\n    \\label{fig:logistic_curve}\n\\end{figure}\n\\end{problem}\n", "meta": {"hexsha": "1e2f3c8f357ed1e62eddbbe030fabd56b0a5ad4c", "size": 23293, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume2/GradientMethods/GradientMethods.tex", "max_stars_repo_name": "frigusgulo/Labs", "max_stars_repo_head_hexsha": "58faeab611e2d54bf2debded58d6e13db40f4146", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-27T06:20:37.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-27T06:20:37.000Z", "max_issues_repo_path": "Volume2/GradientMethods/GradientMethods.tex", "max_issues_repo_name": "frigusgulo/Labs", "max_issues_repo_head_hexsha": "58faeab611e2d54bf2debded58d6e13db40f4146", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Volume2/GradientMethods/GradientMethods.tex", "max_forks_repo_name": "frigusgulo/Labs", "max_forks_repo_head_hexsha": "58faeab611e2d54bf2debded58d6e13db40f4146", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.4591029024, "max_line_length": 343, "alphanum_fraction": 0.7201734427, "num_tokens": 6845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711642563824, "lm_q2_score": 0.8670357615200474, "lm_q1q2_score": 0.7369553956711138}}
{"text": "% !TeX spellcheck = en_GB\n%\\documentclass[12pt,a4paper]{article}\n%\\usepackage{import}\n%\\subimport{../}{uebung.tex}\n\n%\\toggletrue{showSolution}\n\n\n%\\title{\\thetitle{}\\\\Tutorial 2}\n%\\date{\\WeeksAfter{8}}\n\n%\\begin{document}\n\n% \\maketitle\n\n\\BoSSSopen{tutorial2/uebung2tutorial}\n\\graphicspath{{tutorial2/uebung2tutorial.texbatch/}}\n\n\\BoSSScmd{\n/// \\section*{What's new}\n///\n/// \\begin{itemize}\n/// \\item Creating numerical grids\n/// \\item Projecting functions onto the DG space and further evaluation\n/// \\item Performing a hp-convergence study\n/// \\end{itemize}\n///\n/// \\section*{Prerequisites}\n/// No \\BoSSS{} specific prerequisites are needed to complete this tutorial.\n///\n/// \\section{Problem statement}\n/// First, we define two functions: $g_1$ is continuous, $g_2$ has a discontinuity at $\\vec{X} = \\pi$ in the first derivative\n/// \\begin{align*}\n/// g_1 =& \\sin(\\vec{X}), \\\\\n/// g_2 =& \\vert(\\sin(\\vec{X})\\vert\\, .\n/// \\end{align*}\n/// The function argument is a vector $\\vec{X}$, consisting only of one entry since we are working in a one dimensional space. \\BoSSS{} however supports 1D, 2D and 3D, so the spatial coordinate is a general vector.\n///\n/// \\section{Solution within the BoSSS framework}\n///\n/// To initialize, we have to call \\code{restart}:\\textsl{}\n }\n\\BoSSSexeSilent\n\\BoSSScmd{\nrestart;\n }\n\\BoSSSexeSilent\n\\BoSSScmd{\nusing NUnit.Framework;\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\subsection{Plotting the functions} First, we plot the functions that are defined above over the interval $(0 ,2 \\pi)$ with \n/// 1000 sampling points using a Gnuplot-object.\n/// %=======================================================================================\n }\n\\BoSSSexe\n\\BoSSScmd{\nFunc<double[],double> g1 = (X => Math.Sin(X[0]));          \\newline \n// continuous, smooth         \\newline \nFunc<double[],double> g2 = (X => Math.Abs(Math.Sin(X[0])));          \\newline \n// continuous, non-smooth\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We define equidistant sampling points...\ndouble[] x = GenericBlas.Linspace(0, 2.0*Math.PI, 1000);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// ...and compute the function values. In the loop, we have to convert the scalar \\code{x[i]} into an array\n/// with one element, since \\code{g1} has to be feed with arrays.\ndouble[] g1\\_values = new double[x.Length];\\newline \nfor(int i = 0; i < x.Length; i++) \\{\\newline \n\\btab g1\\_values[i] = g1(new[] \\{ x[i]\\} );\\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Instead of loops, we can also use Linq-functions:\ndouble[] g2\\_values = x.Select(x => g2(new []\\{ x \\})).ToArray();\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// For now, we are using the simple plotting interface, which supports\n/// Matlab-Style format specifiers and color names. (More advanced plots\n/// can be produced with \\code{Plot2Ddata} and/or \\code{Gnuplot} classes)\nPlot(X1:x, Y1:g1\\_values, Name1:\"function g1\", Format1:\"--red\",\\newline \n\\btab  X2:x, Y2:g2\\_values, Name2:\"function g2\", Format2:\"-.blue\");\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Next, we create a grid which has a cell boundary exactly at the position of\n/// the discontinuity of \\code{g2}.\n/// %=========================================================================================\n }\n\\BoSSSexe\n\\BoSSScmd{\nvar Nodes1 = new double[] \\{0, 2, Math.PI, 4.5, 2*Math.PI \\};         \\newline \nvar Grid1 = Grid1D.LineGrid(Nodes1);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We can get the total number of cells by using the following command:\n }\n\\BoSSSexe\n\\BoSSScmd{\nGrid1.NumberOfCells;\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// The recently created grid-object is not directly usable because it contains only the nodes of the grid. \n/// We have to create a \\code{GridData}-object which provides all necessary transformation metrics, etc. .\n/// %=======================================================================================\n }\n\\BoSSSexe\n\\BoSSScmd{\nvar gdata1 = new GridData(Grid1);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\subsection{Projection onto the DG space}\n/// At this point, we are able to create the so-called \\emph{DG fields} to approximate \\code{g1}\n/// on \\code{grid1}. Therefore, we project \\code{g1} onto \\code{grid1} using polynomial orders\n/// of $p=2$ and $p=8$.\n/// % =======================================================================================\n }\n\\BoSSSexe\n\\BoSSScmd{\nvar g1\\_grid1\\_p2 = new SinglePhaseField(new Basis(gdata1, 2), \"g1 with p2 at Grid 1\");      \\newline \ng1\\_grid1\\_p2.ProjectField(g1);\n }\n\\BoSSSexe\n\\BoSSScmd{\nvar g1\\_grid1\\_p8 = new SinglePhaseField(new Basis(gdata1, 8), \"g1 with p8 at Grid 1\");         \\newline \ng1\\_grid1\\_p8.ProjectField(g1);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Now, let us plot the projected solution for $p=2$. \n/// By using the upsampling parameter, we can determine \n/// the amount of sampling points per cell.\n/// %=======================================================================================\n }\n\\BoSSSexe\n\\BoSSScmd{\nvar upsampling = 20;\n }\n\\BoSSSexe\n\\BoSSScmd{\nvar gp1 = new Gnuplot();\n }\n\\BoSSSexe\n\\BoSSScmd{\ngp1.PlotField(g1\\_grid1\\_p2,          \\newline \n\\btab new PlotFormat(lineColor: (LineColors)(1)),\\newline \n\\btab upsampling);\n }\n\\BoSSSexe\n\\BoSSScmd{\ngp1.PlotNow(); // shows the plot\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\subsection{Computing the $L^2$-error}\n/// Next, we learn how to compute the $L^2$-error for both \n/// approximations of \\code{g1} with different polynomial degrees:\n/// %=======================================================================================\n }\n\\BoSSSexe\n\\BoSSScmd{\ng1\\_grid1\\_p2.L2Error(g1);\n }\n\\BoSSSexe\n\\BoSSScmd{\ng1\\_grid1\\_p8.L2Error(g1);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\subsection{Plotting the point-wise error}\n/// Now, we plot the point-wise error for the approximation of \\code{g1}\n/// on \\code{grid1} with a polynomial degree of 8.\n/// %=======================================================================================\n }\n\\BoSSSexe\n\\BoSSScmd{\nint K = 20; // number of points per cell         \\newline \nvar gp2 = new Gnuplot();         \\newline \ngp2.PlotLogError(g1\\_grid1\\_p8, g1, \"g1 with p8 at Grid 1\", 20,          \\newline \n\\btab new PlotFormat(lineColor: (LineColors)(1)));         \\newline \ngp2.PlotNow();\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\subsection{Decay behavior of the DG modes for smooth and non-smooth functions}\n/// We investigate the decay behavior of the DG modes for smooth and non-smooth \n/// functions. For this purpose, we create a second grid which has the\n/// discontinuity of \\code{g2} within a cell and project \\code{g2} onto this grid\n/// like mentioned above.\n/// %=======================================================================================\n }\n\\BoSSSexe\n\\BoSSScmd{\nvar Nodes2      = new double[] \\{0, 2, 4.5, 2*Math.PI \\};         \\newline \nvar Grid2       = Grid1D.LineGrid(Nodes2);         \\newline \nvar gdata2      = new GridData(Grid2);         \\newline \nvar g2\\_grid2\\_p8 = new SinglePhaseField(new Basis(gdata2, 8), \"g2\\_p8 at Grid2\");         \\newline \ng2\\_grid2\\_p8.ProjectField(g2);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// The cell coordinates can be extracted by using the \\code{Coordinates} parameter.\n }\n\\BoSSSexe\n\\BoSSScmd{\ndouble[] cell1 = g2\\_grid2\\_p8.Coordinates.GetRow(1);          \\newline \n\\btab // coord. in cell 1 (with kink)\n }\n\\BoSSSexe\n\\BoSSScmd{\ndouble[] cell0 = g2\\_grid2\\_p8.Coordinates.GetRow(0);          \\newline \n\\btab // coord. in cell 0 (smooth)\n }\n\\BoSSSexe\n\\BoSSScmd{\ndouble[] cell2 = g2\\_grid2\\_p8.Coordinates.GetRow(2);          \\newline \n\\btab // coord. in cell 2 (smooth)\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Only the absolute value shall be plotted. We use a for-loop to replace the data in \n/// \\code{cell0}, \\code{cell1} and \\code{cell2} by their absolute values.\n/// %=======================================================================================\n }\n\\BoSSSexe\n\\BoSSScmd{\nfor(int i = 0; i < cell0.Length; i++) \\{         \\newline \n\\btab cell0[i] = Math.Abs(cell0[i]);         \\newline \n\\btab cell1[i] = Math.Abs(cell1[i]);         \\newline \n\\btab cell2[i] = Math.Abs(cell2[i]);         \\newline \n \\}\n }\n\\BoSSSexe\n\\BoSSScmd{\nPlot(X1:null, Y1:cell1, Name1:\"disc. cell\", Format1:\"*-magenta\",\\newline \n\\btab  X2:null, Y2:cell0, Name2:\"cell0\",      Format2:\"o-blue\",\\newline \n\\btab  X3:null, Y3:cell2, Name3:\"cell2\",      Format3:\"o-red\");\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Note: Using a shortcut for the for-loop above, the absolute values in cell 0\n/// can also be stored using the following command:\n }\n\\BoSSSexe\n\\BoSSScmd{\ndouble[] cell0 = g2\\_grid2\\_p8.Coordinates.GetRow(0)         \\newline \n\\btab .Select(d => Math.Abs(d)).ToArray();\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Now, we would like to plot the logarithm (use \\code{Math.Log10(...)}) of the absolute\n/// values of the DG coordinates.\n }\n\\BoSSSexe\n\\BoSSScmd{\nPlot(X1:null, Y1:cell1, Name1:\"disc. cell\", Format1:\"*-magenta\",\\newline \n\\btab  X2:null, Y2:cell0, Name2:\"cell0\",      Format2:\"o-blue\",\\newline \n\\btab  X3:null, Y3:cell2, Name3:\"cell2\",      Format3:\"o-red\",\\newline \n\\btab  logY:true);\n }\n\\BoSSSexe\n\\BoSSScmd{\n///\\subsection{Convergence study}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// In this section, we learn how to perform a convergence study for \\code{g2} \n/// for two different sequences of grid resolutions and different polynomial\n/// orders. Therefore, we define two different sequences of grid resolutions:\n/// %=======================================================================================\n }\n\\BoSSSexe\n\\BoSSScmd{\nint[][] ResSeq = new int[2][];\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Grid resolutions so that the kink in \\code{g2} is located at a cell boundary:\nResSeq[0] = new int[] \\{ 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048 \\};\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Grid resolutions so that the kink in \\code{g2} is located within a cell:\nResSeq[1] = new int[] \\{ 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047 \\};\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We save our errors into a multidimensional array by looping over \n/// \\begin{enumerate}\n/// \\item the resolution sequence\n/// \\item the polynomial order\n/// \\item the resolution\n/// \\end{enumerate}\nvar Errors = MultidimensionalArray.Create(2, 5, ResSeq[0].Length);\n }\n\\BoSSSexe\n\\BoSSScmd{\nfor(int i = 0; i < 2; i++) \\{ // loop over the resolution sequence         \\newline \n\\btab for(int p = 0; p <= 4; p++) \\{ // loop over polynomial orders         \\newline \n\\btab \\btab for(int k = 0; k < ResSeq[i].Length; k++) \\{ // loop over different resolutions        \\newline \n \\newline \n\\btab \\btab \\btab Console.Write(\"polynomial order \\{1\\}\"+         \\newline \n\\btab \\btab \\btab \",\\textbackslash tResolution \\{0\\}... \", ResSeq[i][k], p);         \\newline \n \\newline \n\\btab \\btab \\btab var grid  = Grid1D.LineGrid(GenericBlas.Linspace(0,         \\newline \n\\btab \\btab \\btab 2.0*Math.PI, ResSeq[i][k] + 1));           \\newline \n\\btab \\btab \\btab \\btab  // number of nodes == number of cells + 1         \\newline \n \\newline \n\\btab \\btab \\btab var gData = new GridData(grid);         \\newline \n \\newline \n\\btab \\btab \\btab var g2\\_h  = new SinglePhaseField(new Basis(gData, p));         \\newline \n \\newline \n\\btab \\btab \\btab g2\\_h.ProjectField(g2);         \\newline \n \\newline \n\\btab \\btab \\btab Errors[i,p,k] = g2\\_h.L2Error(g2);         \\newline \n \\newline \n\\btab \\btab \\btab Console.WriteLine(\"\\textbackslash tdone: L2 error is \\{0:0.###e-00\\}.\", Errors[i,p,k]);         \\newline \n\\btab \\btab \\}         \\newline \n\\btab \\}         \\newline \n \\}\n }\n\\BoSSSexe\n\\BoSSScmdSilent{\n/// NUnit test (few random tests) BoSSScmdSilent\nAssert.LessOrEqual(Errors[1,4,9],8E-06);       \\newline \nAssert.LessOrEqual(Errors[1,3,9],7.5E-06);       \\newline \nAssert.LessOrEqual(Errors[1,2,9],2E-05);       \\newline \nAssert.LessOrEqual(Errors[1,1,9],2E-05);       \\newline \nAssert.LessOrEqual(Errors[0,3,9],1E-12);       \\newline \nAssert.LessOrEqual(Errors[0,3,9],1E-12);       \\newline \nAssert.LessOrEqual(Errors[1,4,0],0.25);       \\newline \nAssert.LessOrEqual(Errors[0,0,0],0.2);       \\newline \nAssert.LessOrEqual(Errors[0,3,0],1E-03);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We plot the error for the grids which have the kink at the cell boundary,\n/// there we reach spectral convergence:\n }\n\\BoSSSexe\n\\BoSSScmd{\nvar hValues = ResSeq[0].Select(J => Math.PI*2.0/J);\\newline \nPlot(X1:hValues, Y1:Errors.ExtractSubArrayShallow(0,0,-1).To1DArray(),\\newline \n\\btab  Name1:\"grid1,p0\", Format1:\"o-red\",\\newline \n\\btab  X2:hValues, Y2:Errors.ExtractSubArrayShallow(0,1,-1).To1DArray(),\\newline \n\\btab  Name2:\"grid1,p0\", Format2:\"o-blue\",\\newline \n\\btab  X3:hValues, Y3:Errors.ExtractSubArrayShallow(0,2,-1).To1DArray(),\\newline \n\\btab  Name3:\"grid1,p0\", Format3:\"o-green\",\\newline \n\\btab  X4:hValues, Y4:Errors.ExtractSubArrayShallow(0,3,-1).To1DArray(),\\newline \n\\btab  Name4:\"grid1,p0\", Format4:\"o-magenta\",\\newline \n\\btab  X5:hValues, Y5:Errors.ExtractSubArrayShallow(0,4,-1).To1DArray(),\\newline \n\\btab  Name5:\"grid1,p0\", Format5:\"o-orange\",\\newline \n\\btab  logX:true, logY:true);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Now we plot the error for the grids which have the kink within a cell;\n/// due to the low regularity, the convergence of the DG method\n/// degenerates:\n }\n\\BoSSSexe\n\\BoSSScmd{\nvar hValues = ResSeq[0].Select(J => Math.PI*2.0/J);\\newline \nPlot(X1:hValues, Y1:Errors.ExtractSubArrayShallow(1,0,-1).To1DArray(),\\newline \n\\btab  Name1:\"grid1,p0\", Format1:\"o-red\",\\newline \n\\btab  X2:hValues, Y2:Errors.ExtractSubArrayShallow(1,1,-1).To1DArray(),\\newline \n\\btab  Name2:\"grid1,p0\", Format2:\"o-blue\",\\newline \n\\btab  X3:hValues, Y3:Errors.ExtractSubArrayShallow(1,2,-1).To1DArray(),\\newline \n\\btab  Name3:\"grid1,p0\", Format3:\"o-green\",\\newline \n\\btab  X4:hValues, Y4:Errors.ExtractSubArrayShallow(1,3,-1).To1DArray(),\\newline \n\\btab  Name4:\"grid1,p0\", Format4:\"o-magenta\",\\newline \n\\btab  X5:hValues, Y5:Errors.ExtractSubArrayShallow(1,4,-1).To1DArray(),\\newline \n\\btab  Name5:\"grid1,p0\", Format5:\"o-orange\",\\newline \n\\btab  logX:true, logY:true);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\section{Advanced topics} This tutorial addressed the very basics of setting up a \\BoSSS{}~application, namely grid instantiation, the $L^2$-projection of functions onto the DG space and performing a spatial convergence study. Where do you go from here? We recommend that you continue with other relevant basics as provided in the tutorials dealing with the creation of a spatial operator, explicit time integration and the implementation of numerical fluxes.\n }\n\\BoSSSexe\n", "meta": {"hexsha": "0f709feafa9d21c746f3b17cb3174e0e4a6facf2", "size": 14207, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/handbook/tutorial2/uebung2tutorial.tex", "max_stars_repo_name": "leyel/BoSSS", "max_stars_repo_head_hexsha": "39f58a1a64a55e44f51384022aada20a5b425230", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-20T10:55:58.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-20T10:55:58.000Z", "max_issues_repo_path": "doc/handbook/tutorial2/uebung2tutorial.tex", "max_issues_repo_name": "leyel/BoSSS", "max_issues_repo_head_hexsha": "39f58a1a64a55e44f51384022aada20a5b425230", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/handbook/tutorial2/uebung2tutorial.tex", "max_forks_repo_name": "leyel/BoSSS", "max_forks_repo_head_hexsha": "39f58a1a64a55e44f51384022aada20a5b425230", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.3350383632, "max_line_length": 463, "alphanum_fraction": 0.6359541071, "num_tokens": 4517, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.7369553821550134}}
{"text": "\\section{Mathematical Model}\n\\label{sec:model}\n\nIn this section we give a summary of the mathematical model.  \n\n\\subsection{Boltzmann Equation}\n\nWe consider approximate solutions to the Boltzmann equation for the transport of massless particles through a static material in Cartesian geometry, which, after scaling to dimensionless units, can be written as\n\\begin{equation}\n  \\pd{f}{t}+\\vect{\\ell}\\cdot\\nabla f\n  =\\f{1}{\\tau}\\,\\cC(f),\n  \\label{eq:boltzmann}\n\\end{equation}\nwhere the distribution function $f\\colon(\\omega,\\varepsilon,\\vect{x},t)\\in\\bbS^{2}\\times\\bbR^{+}\\times\\bbR^{3}\\times\\bbR^{+}\\to\\bbR^{+}$ gives the number of particles propagating in the direction $\\omega\\in\\bbS^{2}:=\\{\\,\\omega=(\\thetaNu,\\phiNu)~|~\\thetaNu\\in[0,\\pi],\\phiNu\\in[0,2\\pi)\\,\\}$, with energy $\\varepsilon\\in\\bbR^{+}$, at position $\\vect{x}\\in\\bbR^{3}$ and time $t\\in\\bbR^{+}$.  \nHere we use spherical momentum space coordinates $(\\varepsilon,\\omega)$, and the unit vector $\\vect{\\ell}(\\omega)\\in\\bbR^{3}$ (independent of $\\varepsilon$ and $\\vect{x}$) is parallel to the particle three-momentum $\\vect{p}=\\varepsilon\\,\\vect{\\ell}$.  \nWe also define the energy-position coordinates $\\vect{z}:=\\{\\varepsilon,\\vect{x}\\}\\in\\bbR^{+}\\times\\bbR^{3}$.  \nOn the right-hand side of Eq.~\\eqref{eq:boltzmann}, $\\tau$ is the ratio of the particle mean-free path (due to interactions with a background) to some characteristic length scale of the problem.  \nIn opaque regions, $\\tau\\ll1$, while for free streaming particles, $\\tau\\gg1$.  \nThe collision operator, which models emission, absorption, and isotropic and elastic scattering, is given by\n\\begin{equation}\n  \\cC(f)=\\xi\\,\\big(\\,f_{0}-f\\,\\big)\n  +(1-\\xi)\\,\\big(\\,\\f{1}{4\\pi}\\int_{\\bbS^{2}}f\\,d\\omega-f\\,\\big),\n  \\label{eq:collisionTerm}\n\\end{equation}\nwhere $\\xi=\\sigma_{\\Ab}/\\sigma_{\\Tot}\\in[0,1]$ is the ratio of the absorption opacity $\\sigma_{\\Ab}\\,(\\ge0)$ to the total opacity $\\sigma_{\\Tot}=\\sigma_{\\Ab}+\\sigma_{\\Scatt}$, and $\\sigma_{\\Scatt}\\,(\\ge0)$ is the scattering opacity.  \nIn particular, $\\xi=1$ models pure emission and absorption, while $\\xi=0$ models pure scattering.  \nIn general, $\\sigma_{\\Ab}$ and $\\sigma_{\\Scatt}$ (and $\\tau$ and $\\xi$) depend on $\\vect{z}$.  \nThe equilibrium distribution function is denoted by $f_{0}(\\vect{z})$.  \nHere, we consider transport of Fermions (e.g., neutrinos), so the equilibrium distribution function takes the form\n\\begin{equation}\n  f_{0}(\\vect{z})=\\f{1}{e^{(\\varepsilon-\\mu(\\vect{x}))/T(\\vect{x})}+1},  \n  \\label{eq:fermiDirac}\n\\end{equation}\nwhere the temperature $T$ and the chemical potential $\\mu$ depend on properties of the background.  \n\n\\subsection{Angular Moment Equations: Two-Moment Model}\n\nThe Boltzmann equation is often too expensive to solve directly.  \nInstead, approximate equations for angular moments of the distribution function are solved.  \nTo this end, we define the angular moments of the distribution function\n\\begin{equation}\n  \\big\\{\\,\\cJ,\\vect{\\cH},\\vect{\\cK}\\,\\big\\}(\\vect{z},t)\n  =\\f{1}{4\\pi}\\int_{\\bbS^{2}}f(\\omega,\\vect{z},t)\\,\\{\\,1,\\vect{\\ell},\\vect{\\ell}\\otimes\\vect{\\ell}\\,\\}\\,d\\omega.  \n  \\label{eq:angularMoments}\n\\end{equation}\nWe refer to $\\cJ$ (zeroth moment) as the particle density, $\\vect{\\cH}$ (first moment) as the particle flux, and $\\vect{\\cK}$ (second moment) as the stress tensor.  \nNote that the moments defined in Eq.~\\eqref{eq:angularMoments} are \\emph{spectral moments} (depending on energy as well as position and time).  \nThe \\emph{grey moments} (depending only on position and time) are obtained by integration over energy:\n\\begin{equation}\n  \\big\\{\\,J,\\vect{H},\\vect{K}\\,\\big\\}(\\vect{x},t)\n  =\\int_{\\bbR^{+}}\\big\\{\\,\\cJ,\\vect{\\cH},\\vect{\\cK}\\,\\big\\}(\\varepsilon,\\vect{x},t)\\,\\varepsilon^{2}d\\varepsilon.  \n\\end{equation}\n\nTaking the zeroth and first moments of Eq.~\\eqref{eq:boltzmann} gives the two-moment model, comprising a system of conservation laws with sources\n\\begin{equation}\n  \\pd{\\vect{\\cM}}{t}+\\nabla\\cdot\\vect{\\cF}=\\f{1}{\\tau}\\,\\vect{\\cC}(\\vect{\\cM}),\n  \\label{eq:momentEquations}\n\\end{equation}\nwhere $\\vect{\\cM}=(\\cJ,\\vect{\\cH})^{T}$ and $\\vect{\\cF}=(\\vect{\\cH},\\vect{\\cK})^{T}$.  \nComponents of the fluxes in each coordinate direction are $\\vect{\\cF}^{i}=\\vect{e}_{i}\\cdot\\vect{\\cF}=(\\vect{e}_{i}\\cdot\\vect{\\cH},\\vect{e}_{i}\\cdot\\vect{\\cK})^{T}$, where $\\vect{e}_{i}$ is the unit vector parallel to the $i$th coordinate direction.  \nOn the right-hand side of Eq.~\\eqref{eq:momentEquations}, the source term is\n\\begin{equation}\n  \\vect{\\cC}(\\vect{\\cM})=\\vect{\\eta}-\\vect{\\cD}\\,\\vect{\\cM}, \n  \\label{eq:collisionTermMoments}\n\\end{equation}\nwhere $\\vect{\\eta}=(\\xi\\,f_{0},\\vect{0})^{T}$ and $\\vect{\\cD}=\\mbox{diag}(\\xi,\\vect{I})$, with $\\vect{I}$ the identity matrix.  \n\nIn order to close the system given by Eq.~\\eqref{eq:momentEquations}, the components of the stress tensor $\\vect{\\cK}$ must be related to the lower moments through a closure procedure.  \nTo this end, Levermore \\cite{levermore_1984} defined the Eddington tensor $\\vect{k}=\\vect{\\cK}/\\cJ$ and assumed that the radiation field is symmetric about a preferred direction $\\widehat{\\vect{h}}=\\vect{\\cH}/|\\vect{\\cH}|$ so that\n\\begin{equation}\n  \\vect{k}=\\f{1}{2}\\big[\\,\\big(1-\\chi\\big)\\,\\vect{I}+\\big(3\\,\\chi-1\\big)\\,\\widehat{\\vect{h}}\\otimes\\widehat{\\vect{h}}\\,\\big],\n  \\label{eq:eddingtonTensor}\n\\end{equation}\nwhere $\\chi=\\chi(\\cJ,|\\vect{\\cH}|)$ is the Eddington factor.  \nThe two-moment model is then closed once the Eddington factor is determined from $\\cJ$ and $\\vect{\\cH}$.  \nWe will return to the issue of determining the Eddington factor in Section~\\ref{sec:algebraicClosure}.  ", "meta": {"hexsha": "23723c46a67dfe43159e110c50c028008c3e34b2", "size": 5602, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/M1/realizableFermionicM1/sections/model.tex", "max_stars_repo_name": "srichers/thornado", "max_stars_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-12-08T16:16:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-24T19:31:21.000Z", "max_issues_repo_path": "Documents/M1/realizableFermionicM1/sections/model.tex", "max_issues_repo_name": "srichers/thornado", "max_issues_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2019-07-10T20:13:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-11T13:21:00.000Z", "max_forks_repo_path": "Documents/M1/realizableFermionicM1/sections/model.tex", "max_forks_repo_name": "srichers/thornado", "max_forks_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-11-14T01:13:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T02:08:20.000Z", "avg_line_length": 73.7105263158, "max_line_length": 388, "alphanum_fraction": 0.6935023206, "num_tokens": 1873, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.7367534645195919}}
{"text": "\\chapter{Bayes' Theorem}\n\nLet's say that that I am holding a bag of marbles in each of my hands.\nYou know that one bag contains 60 white marbles and 40 red marbles. You\nknow that the other holds 10 white marbles and 90 red marbles. You\ndon't know which is which -- you can't see the marbles.\n\nI say ``Guess which bag is mostly red marbles.'' You pick one.\n\nHolding out choosen bag, I ask ``What is the probability\nthat this is the bag that is mostly red marbles?'' You answer ``That\nis the mostly-red-marbles bag with a probability of 0.5.  There is\nalso a 0.5 probability that it is the mostly-white-marbles bag.''\n\nThen I let you pick one marble from the bag.  It is red. Now you must\nupdate your beliefs. Clearly, it is more likely that this is the\nmostly-red-marbles bag. What is the probability now?\n\nBayes Theorem gives you the rule for updating your beliefs based on\nnew data.\n\n\\section{Bayes Theorem}\n\nLet's say you have two events or conditions $C$ and $D$.  Maybe $C$ is\n``The person has a cough'' and $D$ is ``The person is waiting to see a doctor.''\n\nUsing the chain rule of probability, we now have two ways to calculate $p(C \\text{ AND } D)$:\n\n$$p(C \\text{ AND } D) = p(C | D) p(D)$$\n\n(The probability the person is at the doctor times the probability they have a cough if they are at the doctor.)\n\nor \n\n$$p(C \\text{ AND } D) = p(C | D) p(D)$$\n\n(The probability the person has a cough times times the probability they are at the doctor if they have a cough.)\n\nThus:\n\n$$p(D | C) = \\frac {p(C | D)p(D)}{P(C)}$$\n\nNow you can calculate $p(D | C)$ (in this case, the probability that\nyou are waiting to see a doctor given that you have a cough.) if you\nknow:\n\n\\begin{itemize}\n\\item $p(C | D)$ (The probability that you have a cough given that you are waiting to see a doctor)\n\\item $p(D)$ (The probabilty that you are waiting for a doctor for any reason.)\n\\item $p(C)$ (The probability that you have a cough anywhere)\n\\end{itemize}\n\nPretty much all modern statistical methods (including most artificial\nintelligence) are based on this formula, which is known as Bayes'\nTheorem.  It was written down by Thomas Bayes before he died in\n1761. It was found and published after his death.\n\n\\section{Using Bayes' Theorem}\n\nBack to the example at the beginning. To review:\n\n\\begin{itemize}\n\\item There are two bags that look exactly the same.\n\\item Bag W has 60 white marbles and 40 red marbles.\n\\item Bag R has 10 white marbles and 90 red marbles.\n\\item You pull one marble from the selected bag -- it is red.\n\\end{itemize}\n\nWhat is the probabilty that the selected bag is Bag R? Intuitively,\nyou know that the probability is now more than 0.5. What is the exact\nnumber?\n\nIn terms of conditional probability, we say we are looking for ``the probability\nthat the selected bag is Bag R, given that you drew a red marble?'' or\n$p(B_R | D_R)$, where $B_R$ is ``The selected bag is Bag R'' and $D_R$ is\n``You drew a red marble from the selected bag''.\n\nFrom Bayes' Theorem, we can write:\n\n$$p(B_R | D_R) = \\frac{ P(D_R | B_R) P(B_R) } {P(D_R)}$$\n\n$P(D_R | B_R)$ is just the probability of drawing a red marble given that the\nselected bag is Bag R. That is easy to calculate: There are 100\nmarbles in the bag, and 90 are red.  Thus $P(D_R | B_R) = 0.9$.\n\n$P(B_R)$ is just the probability that you chose Bag R before you drew\nout a marble. Both bags look the same, so $P(B_R)= 0.5$.  This is\ncalled \\textit{the prior} because it represents what you thought the\nprobability was before you got more information.\n\n$P(D_R)$ is the probabilty of drawing a red marble. There was 0.5\nprobability that you put your hand into Bag W (in which 40 of the 100\nmarbles are red) and a 0.5 probability that you put your hand into Bag\nR (in which 90 of the 100 marbles are red).  So\n\n$$P(D_R) = 0.5 \\frac{40}{100} + 0.5 \\frac{90}{100} = 0.65$$\n\nPutting it together:\n\n$$p(B_R | D_R) = \\frac{ P(D_R | B_R) P(B_R) } {P(D_R)} = \\frac{(0.9)(0.5)}{0.65} = \\frac{9}{13} \\approx 0.69$$\n\nThus, given that you have pulled a red marble, there is about a 69\\% chance\nthat you have selected the bag with 90 red marbles.\n\n\\section{Confidence}\n\nBayes' Theorem, then, is about updating your beliefs based on\nevidence.  Before you drew out the red marble, you selected one bag\nthinking it might contain 90 red marbles. How certain were you? You\nwere 0.5 certain, where 0.0 is complete disbelief and 1.0 is complete\nconfidence.  After pulling out the red marble, you were about 0.69\nconfident that you had chosen the bag with 90 red marbles.\n\nThe question ``How confident are you in your guess?'' is very\nimportant in some situations. For example in medicine, diagnoses often\nlead to risky interventions. Few diagnoses come with 100\\% confidence.\nAll doctors should know how to use Bayes' Theorem.\n\nIn a trial, a jury is asked to determine if the accused person is\nguilty of a crime. Few jurors at 100\\% certain. In some trials, Bayes'\nTheorem is a really important tool.\n\n", "meta": {"hexsha": "7198ff518e00042dc90c7fe61ddbfb2d8da4c38b", "size": 4933, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/DiscreteProbability/bayes-en_US.tex", "max_stars_repo_name": "rajivjhoomuck/sequence", "max_stars_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Modules/DiscreteProbability/bayes-en_US.tex", "max_issues_repo_name": "rajivjhoomuck/sequence", "max_issues_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/DiscreteProbability/bayes-en_US.tex", "max_forks_repo_name": "rajivjhoomuck/sequence", "max_forks_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.1056910569, "max_line_length": 113, "alphanum_fraction": 0.7275491587, "num_tokens": 1405, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.9173026522382527, "lm_q1q2_score": 0.7367534622498636}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=1}^\\infty \\frac{15n^4+4n^3+3n^2+2n+1}{3n^5+n^4+n^3+n^2+n+1}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution}\r\n\r\nThe function $\\displaystyle f(x)=\\frac{15x^4+4x^3+3x^2+2x+1}{3x^5+x^4+x^3+x^2+x+1}$ is continuous, positive, and decreasing.\r\n\r\nWe will apply the Integral Test, so we integrate $f(x)$ using the substitution $u=3x^5+x^4+x^3+x^2+x+1$ to get\r\n\\begin{align*}\r\n\\int \\frac{15x^4+4x^3+3x^2+2x+1}{3x^5+x^4+x^3+x^2+x+1}\\,dx \r\n&= \\int \\frac1u\\,du\\\\\r\n&= \\ln|u|+C\\\\\r\n&= \\ln|3x^5+x^4+x^3+x^2+x+1|+C.\r\n\\end{align*}\r\n\r\nThus the definite, improper integral is\r\n\\begin{align*}\r\n\\int_1^\\infty  \\frac{15x^4+4x^3+3x^2+2x+1}{3x^5+x^4+x^3+x^2+x+1}\\,dx \r\n&= \\lim_{t \\to \\infty} \\int_1^t  \\frac{15x^4+4x^3+3x^2+2x+1}{3x^5+x^4+x^3+x^2+x+1}\\,dx \\\\\r\n&= \\lim_{t \\to \\infty} ( \\ln|3t^5+t^4+t^3+t^2+t+1| -  \\ln|8|)\\\\\r\n&= \\infty.\r\n\\end{align*}\r\nSince the integral $\\displaystyle \\int_1^\\infty f(x)\\,dx$ diverges, by the Integral Test, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{15n^4+4n^3+3n^2+2n+1}{3n^5+n^4+n^3+n^2+n+1}$ diverges.\r\n\r\n\\subsection*{Comment}\r\n\r\nThis series can be studied using the Limit Comparison Test, and would be rather awful (but possible!) using the Direct Comparison Test. However, the Integral Test (above) is probably going to be much shorter!\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\left|\\frac{a_{n+1}}{a_n}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\right|\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} a_n\r\n&= \\lim_{n \\to \\infty} \\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "9c148e021284936ee95e57b1541abef76bc58cc8", "size": 2227, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/i3.tex", "max_stars_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_stars_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "key/series/i3.tex", "max_issues_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_issues_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "key/series/i3.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 34.2615384615, "max_line_length": 209, "alphanum_fraction": 0.6322406825, "num_tokens": 919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198946, "lm_q2_score": 0.8688267881258483, "lm_q1q2_score": 0.7367371072837741}}
{"text": "\\section{Divide and Conquer}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Integer multiplication (Problem 2.15)}\n  \\begin{exampleblock}{Integer Multiplication}\n    Multiplying two $n$-bit integers in $o(n^2)$ time. {\\small (Assuming $n = 2^k$.)}\n  \\end{exampleblock}\n\n  \\vspace{0.50cm}\n\n  \\centerline{Column multiplication in $\\Theta(n^2)$}\n\n  \\begin{block}{Elementray operations:}\n\t\\begin{itemize}\n\t  \\item $n$-bit + $n$-bit: $O(n)$\n\t  \\item $1$-bit $\\times$ $1$-bit: $O(1)$\n\t  \\item $n$-bit shifted by $1$-bit: $O(1)$\n\t\\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Integer multiplication (Problem 2.15)}\n  \\begin{block}{Simple divide and conquer:}\n\t\\begin{align*}\n\t  x & = x_L : x_R = 2^{n/2} x_L + x_R  \\\\\n\t  y & = y_L : y_R = 2^{n/2} y_L + y_R\n\t\\end{align*}\n\n\t\\begin{align*}\n\t  xy & = (2^{n/2} x_L + x_R) (2^{n/2} y_L + y_R) \\\\\n\t\t & = 2^{n} x_L y_L + 2^{n/2} (x_L y_R + x_R y_L) + x_R y_R\n\t\\end{align*}\n\n\t\\[\n\t  T(n) = 4T(n/2) + \\Theta(n) = \\Theta(n^2)\n\t\\]\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Integer multiplication (Problem 2.15)}\n  \\begin{block}{A little history:}\n  \\begin{itemize}\n    \\item Kolmogorov (1952) conjecture: $\\Omega(n^2)$\n    \\item Kolmogorov (1960) seminar\n    \\item Karatsuba (\\emph{within a week}): $\\Theta(n^{1.59})$\n    \\item ``The Complexity of Computations'' by Karatsuba, 1995\n  \\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Integer multiplication (Problem 2.15)}\n  \\begin{block}{Karatsuba algorithm:}\n    \\[\n      T(n) = 3T(n/2) + \\Theta(n) = \\Theta(n^{\\log_{2}{3}}) = \\Theta(n^{1.59})\n    \\]\n\n\t\\pause\n\n\t\\[\n      xy = 2^{n} x_L y_L + 2^{n/2} (x_L y_R + x_R y_L) + x_R y_R\n\t\\]\n\t\n    \\[\n      \\underbrace{(x_L + x_R) (y_L + y_R)}_{P_0} = \\underbrace{x_L y_L}_{P_1} +\n      (x_L y_R + x_R y_L) + \\underbrace{x_R y_R}_{P_2}\n    \\]\n\n    \\[\n      xy = 2^{n} P_1 + 2^{n/2} (P_0 - P_1 - P_2) + P_2\n    \\]\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Matrix multiplication (Problem 2.16)}\n  \\begin{exampleblock}{Matrix multiplication}\n    Multiplying two $n \\times n$ matrices in $o(n^3)$ time. {\\small (Assuming $n = 2^k$.)}\n    \\[ Z = X \\times Y \\]\n  \\end{exampleblock}\n\n  \\vspace{0.50cm}\n  \\begin{columns}\n    \\column{0.40\\textwidth}\n\t  \\[ Z_{ij} \\]\n\n\t  \\[ T(n) = \\Theta(n^2 \\cdot n) = \\Theta(n^3) \\]\n    \\column{0.60\\textwidth}\n\t  \\begin{block}{Elementrary operations:}\n\t    \\begin{itemize}\n\t      \\item integer addition: $O(1)$\n\t      \\item integer multiplication: $O(1)$\n\t    \\end{itemize}\n\t  \\end{block}\n  \\end{columns}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Matrix multiplication (Problem 2.16)}\n  \\begin{displaymath}\n\tX = \\begin{bmatrix} A & B \\\\ C & D \\end{bmatrix}, \\quad\n\tY = \\begin{bmatrix} E & F \\\\ G & H \\end{bmatrix} \\qquad (A \\ldots H \\in\n\t\\mathbb{R}^{n/2} \\times \\mathbb{R}^{n/2})\n  \\end{displaymath}\n\n  \\[\n    XY = \\begin{bmatrix} AE + BG & AF + BH \\\\ CE + DG & CF + DH \\end{bmatrix}\n  \\]\n\n  \\[\n    T(n) = 8T(n/2) + \\Theta(n^2) = \\Theta(n^3)\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Matrix multiplication (Problem 2.16)}\n  \\begin{block}{Strassen algorithm:}\n    \\[\n      T(n) = 7T(n/2) + \\Theta(n^2) = \\Theta(n^{\\lg {7}}) = \\Theta(n^{2.808})\n    \\]\n  \\end{block}\n\n  \\[\n\tXY = \\begin{bmatrix} P_5 + P_4 - P_2 + P_6 & P_1 + P_2 \\\\ P_3 + P_4 & P_1 + P_5 - P_3 - P_7 \\end{bmatrix}\n  \\]\n\n  \\begin{columns}\n\t\\column{0.40\\textwidth}\n\t{\\footnotesize\n\t  \\begin{align*}\n\t\tP_1 &= A(F - H) \\\\\n\t\tP_2 &= (A + B)H \\\\\n\t\tP_3 &= (C + D)E \\\\\n\t\tP_4 &= D(G - E) \\\\\n\t\tP_5 &= (A + D)(E + H) \\\\\n\t\tP_6 &= (B - D)(G + H) \\\\\n\t\tP_7 &= (A - C)(E + F)\n\t  \\end{align*}\n\t}\n\t\\column{0.60\\textwidth}\n\t  \\pause\n\t  \\begin{itemize}\n\t\t\\item Strassen (1969): $\\Theta(n^{2.808})$ \\\\\n\t\t  ``Gaussian Elimination is Not Optimal''\n\t\t  \\pause\n\t\t\\item (2014): $\\Theta(n^{2.373})$\n\t\t  \\pause\n\t\t\\item Known lower bound: $\\Omega(n^{2})$\n\t  \\end{itemize}\n  \\end{columns}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{1-D DP}\n  \\begin{exampleblock}{Maximal sum subarray (Problem 1.3.5)}\n    \\begin{itemize}\n      \\item array $A[1 \\cdots n], a_{i} >=< 0$\n      \\item to find (the sum of) an MS in $A$\n    \\end{itemize}\n\t\n    \\[\n      A[-2,1 ,-3,4,-1,2,1,-5,4] \\Rightarrow [4,-1,2,1]\n    \\]\n  \\end{exampleblock}\n\n  \\pause\n  \\begin{alertblock}{Trial and error.}\n    \\begin{itemize}\n      \\item try subproblem $\\text{MSS}[i]$: the sum of the MS (\\text{MS}[i]) in $A[1 \\cdots i]$\n      \\item goal: $\\text{mss} = \\text{MSS}[n]$\n      \\item question: Is $a_{i} \\in \\text{MS}[i]$?\n      \\item recurrence: \n\t\\[ \n\t  \\text{MSS}[i] = \\max \\set{\\text{MSS}[i-1], \\textcolor{red}{???}}\n\t\\]\n    \\end{itemize}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{1-D DP}\n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item subproblem $\\text{MSS}[i]$: the sum of the MS \\textcolor{red}{\\it ending with} $a_{i}$ or 0\n      \\item goal: $\\text{mss} = \\max_{1 \\le i \\le n} \\text{MSS}[i]$\n      \\item<2-> question: where does the $\\text{MS}[i]$ start?\n      \\item<2-> recurrence: \n\t\t\\[ \n\t\t  \\text{MSS}[i] = \\max \\set{\\text{MSS}[i-1] + a_{i}, 0} \\text{ \\textcolor{red}{(prove it!)}}\n\t\t\\]\n      \\item<3-> initialization: $\\text{MSS}[0] = 0$\n    \\end{itemize}\n\n    % \\begin{displaymath}\n    %   \\text{MSS}[i] = \\left\\{ \\begin{array}{ll}\n    %     0 & i = 0 \\\\\n    %     \\max \\set{\\text{MSS}[i-1] + a_{i}, 0} & i > 0\n    %   \\end{array} \\right.\n    % \\end{displaymath}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}[fragile]{1-D DP}\n  \\begin{block}{Code.}\n    \\begin{verbatim}\n      MSS[0] = 0\n      For i = 1 to n\n        MSS[i] = max{MSS[i-1] + A[i], 0}\n      return max_{i = 1 to n} MSS[i]\n    \\end{verbatim}\n  \\end{block}\n\n  \\pause\n\n  \\begin{block}{Simpler code.}\n    \\begin{verbatim}\n      mss = 0\n      MSS = 0\n      For i = 1 to n\n        MSS = max{MSS + A[i], 0}\n        mss = max{mss, MSS}\n      return mss\n    \\end{verbatim}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Pancake sorting (Problem 1.3.1)}\n  \\fignocaption{width = 0.25\\textwidth}{figs/pancake-sorting.png}\n\n  \\pause\n  \\centerline{How to bring the biggest pancake to the bottom?}\n\n  \\pause\n  \\[\n\tT(n) = 2n-3\n  \\]\n\n  \\pause\n  \\begin{alertblock}{Reference}\n\t\\begin{itemize}\n\t  \\item $T(n) \\le \\frac{5n+5}{3}$, 1979: ``Sorting by Perfix Reversals'' \\pause by Bill Gates \\emph{et al.}\n\t\t\\pause\n\t  \\item $T(n) \\le \\frac{18n}{11}$, 2009\n\t\\end{itemize}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{\\# Big V's (Problem 1.3.8)}\n  \\centerline{How many Big V's are there at most?}\n\n  \\pause\n  \\vspace{0.50cm}\n  \\centerline{``Does A follow B?''}\n\n  \\pause\n  \\vspace{0.50cm}\n  \\centerline{Don't forget to check it!}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Bolts and nuts (Problem 2.10)}\n  \\fignocaption{width = 0.30\\textwidth}{figs/bolts-nuts.jpg}\n\n  \\pause\n  \\centerline{Using quicksort}\n\n  \\pause\n  \\[\n\tA(n) = O(n \\log n)\n  \\]\n\n  \\pause\n  \\begin{alertblock}{Reference}\n\tIn the worst case:\n\t\\begin{itemize}\n\t  \\item ``Matching Nuts and Bolts'' by Alon \\emph{et al.}, $\\Theta(n \\log^4 n)$\n\t  \\pause\n\t  \\item ``Matching Nuts and Bolts Optimality'' by Bradford, 1995, $\\Theta(n \\log n)$ \n\t\\end{itemize}\n  \\end{alertblock}\n\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Bolts and nuts (Problem 2.10)}\n  \\fignocaption{width = 0.30\\textwidth}{figs/bolts-nuts.jpg}\n\n  \\[\n\t\\Omega(n \\log n)\n  \\]\n\n  \\pause\n  \\centerline{At least as hard as the sorting problem.}\n\n  \\pause\n  \\[\n\t3^{H} \\ge L \\textcolor{red}{\\ge n!} \\Rightarrow H \\ge \\log (n!) \\Rightarrow H = \\Omega(n \\log n)\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{$K$-sorted (Problem 2.9)}\n  \\[\n\t1,\\;2,\\;4,\\;3;\\quad 7,\\;6,\\;8,\\;5;\\quad 10,\\;11,\\;9,\\;12;\\quad 15,\\;13,\\;16,\\;14\n  \\]\n\n  \\pause\n  \\vspace{0.20cm}\n\n  \\begin{center}\n\t$1\\text{-sorted}$? \\\\ \\pause\n\t$2\\text{-sorted}$? \\\\ \\pause\n\t$n\\text{-sorted}$?\n  \\end{center}\n\n  \\pause\n  \\[\n\t1\\text{-sorted} \\to 2\\text{-sorted} \\to 4\\text{-sorted} \\to \\cdots \\to n\\text{-sorted}\n  \\]\n\n  \\pause\n  \\centerline{Quicksort (with median) stops after the $\\log k$ recursions.}\n\n  \\pause\n  \\[\n\tO(n \\log k)\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{$K$-sorted (Problem 2.9)}\n  \\[\n    \\Omega(n \\log k)\n  \\]\n\n  \\pause\n  \\[\n\tL = \\frac{n!}{\\left( (\\frac{n}{k})! \\right)^{k}}\n  \\]\n\n  \\pause\n  \\[\n\tH \\ge \\log \\left(\\frac{n!}{\\left( (\\frac{n}{k})! \\right)^{k}} \\right)\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Dutch national flag problem (Problem 2.5)}\n  \\begin{columns}\n\t\\column{0.50\\textwidth}\n\t  \\fignocaption{width = 0.50\\textwidth}{figs/dutch-flag.png}{\\centerline{The Dutch national flag}}\n\t\\column{0.50\\textwidth}\n\t  \\fignocaption{width = 0.35\\textwidth}{figs/dijkstra.jpg}{\\centerline{Edsger W. Dijkstra}}\n  \\end{columns}\n\n  \\vspace{0.50cm}\n  \\centerline{Red balls \\emph{before} White balls \\emph{before} Blue balls}\n\n  \\pause\n  \\[\n\t\\textsc{Color}(i) \\quad \\textsc{Swap}(i,j)\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Dutch national flag problem (Problem 2.5)}\n  Loop invariant:\n\n  \\begin{equation*}\n\t\\begin{cases}\n\t  \\text{White} & r \\le i < w \\\\\n\t  \\text{Red} & 0 \\le i < r \\\\\n\t  \\text{Blue} & b \\le i < n\n\t\\end{cases}\n  \\end{equation*}\n\n  \\pause\n  \\[\n\t\\text{Init: } r = 0; \\; w = 0; \\; b = n - 1\\;\n  \\]\n\n  \\vspace{0.30cm}\n  \\begin{description}\n\t\\item[Red:] \\uncover<3->{$\\textsc{Swap}(r,w); \\; r \\gets r + 1; \\; w \\gets w + 1;$}\n\t\\item[White:] \\uncover<4->{$w \\gets w + 1;$}\n\t\\item[Blue:] \\uncover<5->{$\\textsc{Swap}(b-1, w); \\; b \\gets b - 1;$}\n  \\end{description}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Repeated elements (Problem 2.12)}\n  \\begin{itemize}\n\t\\item $R[1 \\dots n]$\n\t\\item $\\text{check}(R[i], R[j])$\n\t\\item $\\# > \\frac{n}{13}$\n  \\end{itemize}\n\n  \\pause\n  \\vspace{0.30cm}\n\n  \\[\n\t\\# > \\frac{n}{k}\n  \\]\n\n  \\begin{center}\n    an $O(n \\log k)$ algorithm \\\\\n    the lower bound $\\Omega(n \\log k)$\n  \\end{center}\n\n  \\begin{alertblock}{Reference}\n\t``Finding Repeated Elements'' by Misra \\& Gries, 1982\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{VLSI layout}\n%   \\begin{exampleblock}{Problem (Area-Efficient VLSI Layout)}\n%     Embedding a complete binary tree with $n$ leaves into a grid with minimum\n%     area.\n%     \\begin{itemize}\n%       \\item VLSI: Very Large Scale Integration\n%       \\item complete binary tree circuit of $\\#layer = 3,5,7,\\ldots$\n% %       \\item $n$ leaves (\\textcolor{red}{why only leaves?})\n%       \\item vertex on grid; no crossing edges\n%       \\item area = width $\\times$ height\n%     \\end{itemize}\n%   \\end{exampleblock}\n% \\end{frame}\n% %%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{VLSI layout}\n%   Na\\\"{\\i}ve embedding:\n%    \\[ H(n) = H(\\frac{n}{2}) + \\Theta(1) = \\Theta(\\lg n) \\]\n%    \\[ W(n) = 2W(\\frac{n}{2}) + \\Theta(1) = \\Theta(n) \\]\n%    \\[ A(n) = \\Theta(n \\lg n) \\]\n% \\end{frame}\n% %%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{VLSI layout}\n%   Smart (H-Layout) embedding:\n%   \\[ \\Box \\times \\Box = n? \\; 1 \\times n;\\; \\frac{n}{\\lg n} \\times \\lg n;\\;\n%   \\textcolor{blue}{\\sqrt{n} \\times \\sqrt{n}}\n%   \\]\n%   Goal: $H(n) = \\Theta(\\sqrt{n}); W(n) = \\Theta(\\sqrt{n}); A(n) = \\Theta(n).$\n%   \\pause\n%   \\[\n% \tH(n) = \\Box H(\\frac{n}{\\Box}) + O(\\Box); H(n) = 2 H(\\frac{n}{4}) +\n% \tO(n^{\\frac{1}{2} - \\epsilon})\n%   \\]\n%   \\pause\n%   \\[ H(n) = 2H(\\frac{n}{4}) + \\Theta(1) \\]\n%   \\pause\n%   \\centering \\textcolor{blue}{Here it is: H-Layout}\n% \\end{frame}\n% %%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{VLSI layout}\n%   \\begin{figure}[htp]\n% \t\\begin{center}\n% \t  \\includegraphics[width = 0.80\\textwidth]{figs/vlsi}\n% \t\\end{center}\n%   \\end{figure}\n% \\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}[noframenumbering]\n  \\fignocaption{width = 0.50\\textwidth}{figs/thankyou.jpg}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{Counting inversions (Problem 2.11)}\n% \\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{Maxima-finding (Problem 2.14)}\n%   \\centerline{Wrong recursions!}\n%   \\pause\n%   \\vspace{0.30cm}\n% \n%   \\centerline{3D?}\n%   \\pause\n%   \\vspace{0.30cm}\n% \n%   \\centerline{Lower bound $\\Omega(n \\log n)$!}\n% \\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "ff5ced1a41b4b362143c7a787315cbfbacbbeb92", "size": 11929, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/algorithm-tutorial-math-dc-20170329/sections/divideconquer.tex", "max_stars_repo_name": "hengxin/algorithm-ta-tutorial", "max_stars_repo_head_hexsha": "0bb0376d96f388671597903fc833f68d7946020e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 45, "max_stars_repo_stars_event_min_datetime": "2017-03-29T08:22:32.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-02T15:12:15.000Z", "max_issues_repo_path": "alg-ta-by-years/alg-ta-2017/algorithm-tutorial-math-dc-20170329/sections/divideconquer.tex", "max_issues_repo_name": "courses-at-nju-by-hfwei/algorithm-ta-tutorial", "max_issues_repo_head_hexsha": "0bb0376d96f388671597903fc833f68d7946020e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "alg-ta-by-years/alg-ta-2017/algorithm-tutorial-math-dc-20170329/sections/divideconquer.tex", "max_forks_repo_name": "courses-at-nju-by-hfwei/algorithm-ta-tutorial", "max_forks_repo_head_hexsha": "0bb0376d96f388671597903fc833f68d7946020e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-10T08:47:12.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-18T07:58:43.000Z", "avg_line_length": 25.5438972163, "max_line_length": 108, "alphanum_fraction": 0.5453097494, "num_tokens": 4732, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522813, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.7367370790068261}}
{"text": "\n\\section*{Section A : Multiple Choice Questions [10 points] (Dan)}\n\n\\begin{enumerate}\n\t\\item {\\textbf{[2 points]} Suppose that you are using ridge regression to estimate the relationship between your data and a value of interest. Your estimate for $\\hat{\\beta}$ is given by:\n\t$$\\hat{\\beta} = \\argmin_\\beta \\norm{y - X \\beta}_2^2 + \\lambda \\norm{\\beta}_2^2$$\n\tWhere $\\lambda$ is a hyper-parameter that governs how much to penalize model complexity. Which of the following would be valid ways to use a 10-fold cross validation scheme? Select all that apply.\n\t}\n\t\\begin{enumerate}[label=\\Alph*)]\n\t\t\t\\item {\n\t\t\t\t For different values of $\\lambda$, train on 9 of the folds and estimate the risk on the 10th fold. Select $\\lambda$ by using the value that has the lowest risk on this 10th fold. Repeat this procedure 10 times for each possible hold out and use the mean of the risks for the estimators selected at each round as an estimate of the true risk of the model.\n\t\t\t}\n\t\t\t\\item {\n\t\t\t\t For different values of $\\lambda$, train on 8 of the folds and estimate the risk on the 9th fold. Select $\\lambda$ by using the value that has the lowest risk on this 9th fold. Then estimate the risk using this $\\lambda$ on the 10th fold. Repeat this procedure 45 (10 choose 2) times and use the mean of the risks for the estimators selected each round as an estimate of the true risk of the model.\n\t\t\t}\n\t\t\t\\item {\n\t\t\t\t For different values of $\\lambda$, train on 1 of the folds, and estimate the risk on this same fold. Select $\\lambda$ by using the value that has the lowest risk on this fold. Repeat this procedure 10 times (once for each fold), and use the mean of the risks for the estimators as an estimate of the true risk of the model.\n\t\t\t}\n\t\t\t\\item {\n\t\t\t\t Select a value of $\\lambda$ before doing your experiment. Train on 9 of the folds and estimate the risk on the 10th fold. Repeat this procedure 10 times (once for each fold), and use the mean of the risks for the estimators as an estimate of the true risk of the model.\n\t\t\t}\n\t\\end{enumerate}\n\t\\textbf{Answer:}\\underline{D}\\\\\n\tTo estimate the true risk from a CV, a fix $\\lambda$ should be selected first.\n\t\n\t\\item {\\textbf{[2 points]} For a k-Nearest Neighbor classifier and the data set below, which class will the test point (marked by the black circle) be  classified as for each of the following values of $k$? \\\\\n\t\\begin{minipage}[!ht]{0.5\\textwidth}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=1.0\\textwidth]{knn_test_point.png}\n\t\t\t\\label{fig:knn_test_point}\n\t\t\\end{minipage}\n\t\\begin{minipage}[!ht]{0.25\\textwidth}\n\t\t\\begin{enumerate}[label=(\\roman*)]\n\t\t\t\\item $k = 1$ \\textbf{Answer:}\\underline{A}\n\t\t\t\\item $k = 2$ \\textbf{Answer:}\\underline{A}\n\t\t\t\\item $k = 7$ \\textbf{Answer:}\\underline{B}\n\t\t\\end{enumerate}\n\t\\end{minipage}\n\t\\begin{minipage}[!ht]{0.25\\textwidth}\n\t\t\\begin{enumerate}[label=\\Alph*)]\n\t\t\t\\item Red\n\t\t\t\\item Green\n\t\t\t\\item Blue\n\t\t\\end{enumerate}\n\t\\end{minipage}\n\t}\n\t\n\t\\item {\\textbf{[2 points]} Which of the following statements is true about the k-Nearest Neighbor classifier? Select all that apply.\n\t\t\\begin{enumerate}[label=\\Alph*)]\n\t\t\t\\item{ As the value of $k$ increases, the variance of the model increases }\n\t\t\t\\item{ As the value of $k$ increases, the bias of the model increases }\n\t\t\t\\item{ As the value of $k$ increases, the model complexity increases }\n\t\t\t\\item{ As the value of $k$ increases, the number of parameters in the model increases }\n\t\t\t\\item{ As the number of training data points increases, the memory requirements of the model increase }\n\t\t\\end{enumerate}\n\t}\n\t\\textbf{Answer:}\\underline{B, E}\\\\\n\t\\begin{itemize}\n\t\t\\item For A: the variance of the model will decrease\n\t\t\\item For C: the model complexity will decrease\n\t\t\\item For D: the number of parameters in the model will not change\n\t\\end{itemize}\n\t\n\t\n\t\\item {\\textbf{[2 points]} What is the maximum training error for a decision tree on an arbitrary data set with $k$ discrete output classes?\n\t\n\t\t\\begin{enumerate}[label=\\Alph*)]\n\t\t\t\\item $\\frac{1}{k}$\n\t\t\t\\item $1$\n\t\t\t\\item $\\frac{1}{\\log_2{k}}$\n\t\t\t\\item $\\frac{k - 1}{k}$\n\t\t\\end{enumerate}\n\t\n\t}\n\t\\textbf{Answer}:\\underline{D}\\\\\n\tThis may happen when $P(Y)=P(Y|X_i),~\\forall i$, and all data will be in a leaf node with a class label whose prior $P(Y)$ is the highest. To maximize the training error, the minimum training accuracy will be $1/k$; therefore, the maximum training error is $(k-1)/k$\n\t\n\t\\item {\\textbf{[2 points]} Consider the following data set. Which methods will classify all data points in this set correctly? Select all that apply. \\\\\n\t\t\\begin{minipage}[!ht]{0.5\\textwidth}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=1.0\\textwidth]{mcq_data.png}\n\t\t\t\\label{fig:svm_quad_a}\n\t\t\\end{minipage}\n\t\t\\begin{minipage}[!ht]{0.5\\textwidth}\n\t\t\t\\begin{enumerate}[label=\\Alph*)]\n\t\t\t\t\\item Soft-Margin SVM (with no kernel)\n\t\t\t\t\\item SVM with a quadratic kernel, when the coefficient on the penalty for slack variables $C = 0$\n\t\t\t\t\\item SVM with a quadratic kernel, when the coefficient on the penalty for slack variables $C \\rightarrow \\infty$\n\t\t\t\t\\item Logistic regression (no kernel)\n\t\t\t\t\\item 3-NN\n\t\t\t\\end{enumerate}\n\t\t\\end{minipage} \n\t}\n\t\\textbf{Answer}:\\underline{C}\\\\\n\t\\begin{itemize}\n\t\t\\item For A: The data is not linear separable. Two outlier red points will be misclassified.\n\t\t\\item For B: Because $C=0$, there will be no classification at all.\n\t\t\\item For C: $C\\rightarrow \\infty$ means hard-margin SVM is used. The quadratic kernel is used, and the data is non-linear separable.\n\t\t\\item For D: Logistic is linear classifier.\n\t\t\\item For E: The two outlier red points will be misclassified.\n\t\\end{itemize}\n\t\n\\end{enumerate}\n\n\\newpage\n", "meta": {"hexsha": "8a08f220ac08b11f898d1e94c4555de8aee782cf", "size": 5642, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homeworks/HW3/mcq.tex", "max_stars_repo_name": "MengwenHe-CMU/17S_10701_MachineLearning", "max_stars_repo_head_hexsha": "613a3087a57a206b83d79855cec359e04cb440f7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-04T01:53:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-14T09:17:05.000Z", "max_issues_repo_path": "Homeworks/HW3/mcq.tex", "max_issues_repo_name": "MengwenHe-CMU/17S_10701_MachineLearning", "max_issues_repo_head_hexsha": "613a3087a57a206b83d79855cec359e04cb440f7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homeworks/HW3/mcq.tex", "max_forks_repo_name": "MengwenHe-CMU/17S_10701_MachineLearning", "max_forks_repo_head_hexsha": "613a3087a57a206b83d79855cec359e04cb440f7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-10-20T15:07:29.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-20T15:07:29.000Z", "avg_line_length": 53.2264150943, "max_line_length": 403, "alphanum_fraction": 0.7151719248, "num_tokens": 1664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7366916821900134}}
{"text": "\n\\subsection{Tan}\n\n\nThe \\(\\tan(\\theta )\\) function is defined as:\n\n\\(\\tan(\\theta ):=\\dfrac{\\sin(\\theta )}{\\cos(\\theta )}\\)\n\n\\subsubsection{Behaviour around \\(0\\)}\n\n\\(\\sin(0)=0\\)\n\n\\(\\cos(0)=1\\)\n\n\\(\\tan(0):=\\dfrac{\\sin(0)}{\\cos(0)}\\)\n\n\\(\\tan(0)=\\dfrac{0}{1}\\)\n\n\\(\\tan(0)=0\\)\n\n\\subsubsection{Behaviour around \\(\\cos(\\theta )=0\\)}\n\n\\(\\tan(\\theta )=\\dfrac{\\sin(\\theta )}{\\cos(\\theta )}\\)\n\nSo \\(\\tan (\\theta )\\) is undefined where \\(\\cos(\\theta )=0\\).\n\nThis happens where:\n\n\\(\\theta=\\dfrac{\\tau }{4}+\\dfrac{1}{2}n\\tau \\)\n\n\\(\\theta=\\dfrac{1}{4}\\tau (1+2n)\\)\n\nWhere \\(n\\in \\mathbb{Z}\\).\n\n\\subsubsection{Derivatives}\n\n\\(\\tan(\\theta )=\\dfrac{\\sin(\\theta )}{\\cos(\\theta )}\\)\n\n\\(\\dfrac{\\delta }{\\delta \\theta } \\tan(\\theta )=\\dfrac{\\delta }{\\delta \\theta }\\dfrac{\\sin(\\theta )}{\\cos(\\theta )}\\)\n\n\\(\\dfrac{\\delta }{\\delta \\theta } \\tan(\\theta )=\\dfrac{\\cos(\\theta )}{\\cos(\\theta )}+ \\dfrac{\\sin^2(\\theta )}{\\cos^n(\\theta )}\\)\n\n\\(\\dfrac{\\delta }{\\delta \\theta } \\tan(\\theta )=1+\\tan^2(\\theta )\\)\n\nNote this is always positive. This means:\n\n\\(\\lim_{\\cos(\\theta )\\rightarrow 0^+}=-\\infty\\)\n\n\\(\\lim_{\\cos(\\theta )\\rightarrow 0^-}=\\infty\\)\n\n", "meta": {"hexsha": "5ba6b354bec9d664da9189ca70e5ad96e895c919", "size": 1123, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/trigonometryPi/01-01-trigTan.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/trigonometryPi/01-01-trigTan.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/trigonometryPi/01-01-trigTan.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.0196078431, "max_line_length": 128, "alphanum_fraction": 0.5699020481, "num_tokens": 438, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768572945969, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7364512501027269}}
{"text": "\\section*{Generative Models}\n\\subsection*{Variational Autoencoder (VAE)}\nSample random vector $\\mathbf{z} \\sim \\mathcal{N}(0,\\mathbf{I})$. Transform through (deterministic) DNN $F_\\theta : \\mathbb{R}^m \\to \\mathbb{R}^n$. Note: expectations $\\mathbb{E}_x[f(x)] = \\mathbb{E}_z [f(F_\\theta(z))]$ (law of the unconscious statistician). Infeasible, would need to find inv. Jacobian determinant\\\\\n$D_{KL}(P\\|Q)=\\sum_i P(i)\\log\\frac{P(i)}{Q(i)}=\\mathbb{E}_i [\\frac{\\log P_i}{\\log Q_i}]$ \\\\\nMore general: $p_\\theta (\\mathbf{x}|\\mathbf{z}) $ instead of $F_\\theta$: ELBO \\\\\n$\\log p_\\theta(x^{(i)})\n% = \\mathbb{E}_{z \\sim q_\\phi (z|x)}[\\log p_\\theta (x^{(i)})]\n= \\mathbb{E}_{z \\sim q_\\phi (z|x)} \\left[\\log \\frac{p_\\theta(z) \\cdot p_\\theta(x^{(i)}|z)}{p_\\theta(z|x^{(i)}}\\frac{q_\\Phi(z|x^{(i)})}{q_\\Phi(z|x^{(i)})} \\right] \\allowbreak\n= \\mathbb{E}_z[\\log p_\\theta (x^{(i)}|z)] - D_{KL}(q_\\Phi(z|x^{(i)}) || p_\\theta(z))$ \\\\\n$ + D_{KL}(q_\\Phi(z|x^{(i)}) || p_\\theta(z|x^{(i)})$ (drop last part)\\\\\n1st: reconstr. quality, 2nd: posterior close to prior. \\\\\nUpdate: $\\nabla_\\theta \\mathbb{E}_{q_\\phi}[\\log p_\\theta(x|z)] = \\mathbb{E}[\\nabla_\\theta \\log p_\\theta(x|z)] \\allowbreak \\approx \\frac 1 L \\sum_{r=1}^L \\nabla_\\theta \\log p_\\theta(x|z^{(r)}), z^{(r)} \\sim^{iid} q_\\theta (\\cdot | x) $\\\\\n\\textbf{Reinforce trick:}\\\\\n$\\nabla_\\theta\\mathbb{E}_{q_\\phi}[\\mathcal{L}(\\mathbf{x}, \\mathbf{z})] = \\mathbb{E}_{q_\\phi}[\\mathcal{L}(\\mathbf{x}, \\mathbf{z}) \\nabla_\\theta\\log q_\\theta(\\mathbf{z};\\mathbf{x})]$ \\\\\n\\textbf{Re-parameterization trick:} use variational distribution  $q_\\phi(\\mathbf{z};\\mathbf{x})=g_\\phi(\\zeta;\\mathbf{x})$ for $\\zeta$ simple \\\\\n(e.g. $\\zeta \\sim \\mathcal{N}(\\mathbf{0},\\mathbf{I}), \\mathbf{z}=\\mathbf{\\mu} + \\mathbf{U}\\zeta \\Rightarrow \\mathbf{z}\\sim \\mathbf{N}(\\mathbf{\\mu}, \\mathbf{UU}^T)$)\\\\\n\\textbf{Stochastic Backprop:} for $\\zeta^{(r)} \\sim^{iid} \\text{simple}$ \\\\\n$\\mathbb{E}_{q_\\phi}[\\nabla_\\phi\\mathcal{L}(\\mathbf{x}, \\mathbf{z})] \\approx \\frac 1 L \\sum_{r=1}^L [\\nabla_\\phi \\mathcal{L}(\\mathbf{x}, g_\\phi(\\zeta^{(r)})] $ \n\\subsection*{Generative Adversarial Network (GAN)}\n$\\min_G \\max_D V(D,G) = \\mathbb{E}_{\\mathbf{x}\\sim p_{data}(\\mathbf{x})}[\\log D(\\mathbf{x}) ]$ \\\\\n$+ \\mathbb{E}_{\\mathbf{z}\\sim p_{\\mathbf{z}}(\\mathbf{\\mathbf{z}})}[\\log (1 - D(G(\\mathbf{x})) ] \\\\\n$ $\\theta^* := \\argmin_{\\theta\\in \\Theta} \\{ \\sup_{\\phi \\in \\Phi} l(\\theta, \\phi)\\}$\n\\textbf{SGD:}  $\\theta^{t+1} = \\theta^t - \\eta \\nabla_\\theta l(\\theta^t, \\phi^t)$ ; $\\phi^{t+1} = \\phi^t + \\eta \\nabla_\\phi l(\\theta^{t+1}, \\phi^t)$ \n\\subsection*{Autoregressive Models}\nGenerate output one variable at a time: $p(x_1, ..., x_m) = \\prod_{t=1}^m p(x_t|x_{1:t-1})$ \\\\\\textbf{PixelCNN:} uses exactly that over a window to predict the next pixel (slow process).\n", "meta": {"hexsha": "d2c207e4cf13d1f7a325a106cc52ed4b2f36cb3a", "size": 2747, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Generative.tex", "max_stars_repo_name": "anklinv/Computational-Intelligence-Lab-ETH-FS19", "max_stars_repo_head_hexsha": "2ef62f626fa83d1410fbb1b2f8a0501937c0dabe", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-20T20:58:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-20T20:58:16.000Z", "max_issues_repo_path": "Generative.tex", "max_issues_repo_name": "anklinv/Computational-Intelligence-Lab-ETH-FS19", "max_issues_repo_head_hexsha": "2ef62f626fa83d1410fbb1b2f8a0501937c0dabe", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Generative.tex", "max_forks_repo_name": "anklinv/Computational-Intelligence-Lab-ETH-FS19", "max_forks_repo_head_hexsha": "2ef62f626fa83d1410fbb1b2f8a0501937c0dabe", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-06T16:55:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-21T01:02:09.000Z", "avg_line_length": 105.6538461538, "max_line_length": 317, "alphanum_fraction": 0.6199490353, "num_tokens": 1159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768620069626, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7364512441209259}}
{"text": "\n% % % % % % Notation % % % % %\n\n\n\\chapter{Notation}\n\\label{apx:notation}\n\nIn this text we use the following notation conventions:\n\\begin{description}\n\\item[$x$] A column vector, or scalar, as implied by the text. \n\\item[$x'$] We use $'$ for the transpose operation. \nFor a $1\\times p$ row vector $x$, then $x'$ is a $p \\times 1$ column vector.\n\\item[$:=$] An assignment, or definition. $A:=a$ means that $A$ is defined to be $a$. \n\\item[$\\prod_{i=1}^{n}$] The product operator: $\\prod_{i=1}^{n} x_i:= x_1 \\times \\dots \\times x_n$.\n\\item[$\\coprod_{i=1}^{n}$] The coproduct operator: $\\coprod_{i=1}^{n} x_i:= 1-(1-x_1) \\times \\dots \\times (1-x_n)$.\n\\item[$\\#\\set{A}$] The count operator. Returns the number of elements of the set $A$. Also known as the \\emph{cardinality}.\n\\item[$\\Phi(t)$] The standard Gaussian CDF at $t$: $\\Phi(t):= P(Z<t)$.\n\\item[$\\phi(t)$] The standard Gaussian density at $t$: $\\phi(t):= \\frac{\\partial}{\\partial t}\\Phi(t)$.\n\\item[$\\Phi(x)$] The structure function of a system in reliability analysis.\n\\item[$\\x_n \\rightsquigarrow \\dist$] Convergence in distribution: for large enough $n$, then $\\x_n$ is distributed like $\\dist$.\n\\item[$\\conv$] The convolution operator: $f \\conv g=(f \\conv g)(t)=\\int f(s) g(t-s) ds$.\n\\item[$f^{\\conv n}$] The convolution power: $n$ convolutions of $f$ with itself.\n\\item[$\\sigma_{(j)}(A)$] The $j$'th largest singular value of matrix $A$. \n\\item[$\\sigma_{max}(A)$] The largest singular value of matrix $A$. \n\\item[$\\lambda_{max}(A)$] The largest eigenvalue of a symmetric positive definite matrix $A$.  \n\\end{description}\n\n\n", "meta": {"hexsha": "d57597e2a5fb8d4ce1f15510f0bbc8e126edef5f", "size": 1581, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Class_notes/notation.tex", "max_stars_repo_name": "johnros/qualityEngineering", "max_stars_repo_head_hexsha": "4a1c0959672fb5c5a6e59829e543c95beb4e5b44", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Class_notes/notation.tex", "max_issues_repo_name": "johnros/qualityEngineering", "max_issues_repo_head_hexsha": "4a1c0959672fb5c5a6e59829e543c95beb4e5b44", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Class_notes/notation.tex", "max_forks_repo_name": "johnros/qualityEngineering", "max_forks_repo_head_hexsha": "4a1c0959672fb5c5a6e59829e543c95beb4e5b44", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.5172413793, "max_line_length": 128, "alphanum_fraction": 0.6584440228, "num_tokens": 532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7364495214537188}}
{"text": "\\section[Applications]{The homology of $\\Omega S^n$, and the Serre exact sequence}\n%Leray originally invented his spectral sequences for locally compact things,\n%but $\\Omega S^n$ for instance isn't locally compact.\nThe goal of this section is to describe a computation of the homology of\n$\\Omega S^n$ via the Serre spectral sequence, as well as describe a\n``degenerate'' case of the Serre spectral sequence.\n\n\\subsection*{The homology of $\\Omega S^n$}\\label{loops-sn}\nLet us first consider the case $n=1$. The space $\\Omega S^1$ is the base of a\nfibration $\\Omega S^1 \\to PS^1 \\to S^1$. Comparing this to the fibration $\\Z\\to\n\\RR\\to S^1$, we find that $\\Omega S^1 \\simeq \\Z$. Equivalently, this follows\nfrom the discussion in \\S \\ref{loops-bg} and the observation that $S^1 \\simeq\nK(\\Z,1)$.\n\nHaving settled that case, let us now consider the case $n>1$. Again, there is a\nfibration $\\Omega S^n\\to PS^n \\to S^n$. In general, if $F\\to E\\to B$ is a\nfibration and the space $F$ has torsion-free homology, we can (via the\nuniversal coefficients theorem) rewrite the $E^2$-page:\n$$E^2_{s,t} = H_s(B;H_t(F)) \\simeq H_s(B)\\otimes H_t(F).$$\nSince $S^n$ has torsion-free homology, the Serre spectral sequence (see \\S\n\\ref{serre-sseq}) runs:\n$$E^2_{s,t} = H_s(S^n) \\otimes H_t(\\Omega S^n) \\Rightarrow H_{\\ast}(PS^n) =\n\\Z.$$\nSince $H_s(S^n)$ is concentrated in degrees $0$ and $n$, we learn that\n$E^2$-page is concentrated in columns $s=0,n$. For instance, if $n=4$, then the\n$E^2$-page (without the differentials drawn in) looks like:\n\\sseqset{classes={draw=none}}\n\\begin{sseqdata}[name = {loops-Sn}, x range={0}{5}, y range={0}{5},\n    homological Serre grading, differentials={->}, y axis gap=0.8cm, x label =\n    {$H_\\ast(S^4)$}, y label = {$H_\\ast(\\Omega S^4)$}]\n    \\foreach \\y in {0,...,6} {\\class[\"H_{\\y}(\\Omega S^n)\"](0,\\y)}\n    \\foreach \\y in {0,...,6} {\\class[\"H_{\\y}(\\Omega S^n)\"](4,\\y)}\n    \\foreach \\y in {0,...,2} {\\d[\"d^4\"]4(4,\\y)}\n\\end{sseqdata}\n\\begin{center}\n    \\printpage[name={loops-Sn},page=0,no differentials]\n\\end{center}\nWe know that $H_0(\\Omega S^n) = \\Z$. Since the target has homology concentrated\nin degree $0$, we know that $E^2_{n,0}$ has to be killed. The only possibility\nis that it is hit by a differential, or that it supports a nonzero\ndifferential.\n\nThere are not very many possibilities for differentials in this spectral\nsequence. In fact, up until the $E^n$-page, there are no differentials (either\nthe target or source of the differential is zero), so $E^2\\simeq E^3 \\simeq\n\\cdots \\simeq E^n$. On the $E^n$-page, there is only one possibility for a\ndifferential: $d^n:E^2_{n,0} \\to E^n_{0,n-1}$. This differential has to be a\nmonomorphism because if it had anything in its kernel, that will be left over\nin the position. In our example above (with $n=4$), we have\n\\begin{center}\n    \\printpage[name={loops-Sn},page=4]\n\\end{center}\n\nHowever, we still do not know the group $E^n_{0,n-1}$. If it is bigger than\n$\\Z$, then $d^n$ is not surjective. There can be no other differentials on the\n$E^r$-page for $r\\geq n+1$ (because of sparsity), so the $d^n$ differential is\nour last hope in killing everything in degree $(0,n-1)$.  This means that $d^n$\nis an epimorphism. We find that $E^n_{0,n-1} = H_{n-1}(\\Omega S^n) \\simeq \\Z$,\nand that $d^n$ is an isomorphism.\n\nWe have now discovered that $H_{n-1}(\\Omega S^n) \\simeq \\Z$ --- but there is a\nlot more left in the $E^2$-page! For instance, we still have a $\\Z$ in\n$E^n_{n,n-1}$. Because $H^\\ast(PS^n)$ is concentrated in degree $0$, this, too,\nmust die! We are in exactly the same situation as before, so the same arguments\nshow that the differential $d^n:E^n_{n,n-1}\\to E^n_{0,2(n-1)}$ has to be an\nisomorphism. Iterating this argument, we find:\n\\begin{equation*}\n    H_q(\\Omega S^n) \\simeq \\begin{cases}\n        \\Z & \\text{if }(n-1)|q\\geq 0\\\\\n        0 & \\text{else}\n    \\end{cases}\n\\end{equation*}\nThis is a great example of how useful spectral sequences can be.\n\\begin{remark}\n    The loops $\\Omega X$ is an associative $H$-space. Thus, as is the case for\n    any $H$-space, the homology $H_\\ast(\\Omega X; R)$ is a graded associative\n    algebra. Recall that the suspension functor $\\Sigma$ is the left adjoint to\n    the loops functor $\\Omega$, so there is a unit map $A\\to \\Omega \\Sigma A$.\n    This in turn begets a map $\\widetilde{H}_\\ast(A)\\to H_\\ast(\\Omega \\Sigma A)$.\n    \n    Recall that the universal tensor algebra\n    $\\mathrm{Tens}(\\widetilde{H}_\\ast(A))$ is the free associative algebra on\n    $\\widetilde{H}_\\ast(A)$. Explicitly:\n    $$\\mathrm{Tens}(\\widetilde{H}_\\ast(A)) = \\bigoplus_{n\\geq\n    0}\\widetilde{H}_\\ast(A)^{\\otimes n}.$$\n    In particular, by the universal property of\n    $\\mathrm{Tens}(\\widetilde{H}_\\ast(A))$, we get a map\n    $\\alpha:\\mathrm{Tens}(\\widetilde{H}_\\ast(A))\\to H_\\ast(\\Omega \\Sigma A)$.\n    \\begin{theorem}[Bott-Samelson]\\label{bott-samelson}\n\tThe map $\\alpha$ is an isomorphism if $R$ is a PID and $H_\\ast(A)$ is\n\ttorsion-free.\n    \\end{theorem}\n    For instance, if $A = S^{n-1}$ then $\\Omega S^n = \\Omega \\Sigma A$. Theorem\n    \\ref{bott-samelson} then shows that\n    $$\n    H_\\ast(\\Omega S^n) = \\mathrm{Tens}(\\widetilde{H}_\\ast(S^{n-1})) = \\langle\n    1, x, x^2, x^3, \\cdots\\rangle,\n    $$\n    where $|x| = n-1$. It is a mistake to call this ``polynomial'', since if\n    $n$ is even, $x$ is an odd class (in particular, $x$ squares to zero by the\n    Koszul sign rule).\n\\end{remark}\n%Note that $H_\\ast(\\Omega S^n)$ acts on this spectral sequence.\n%Then the $d^r$'s are linear (module homomorphisms).\n\nTheorem \\ref{bott-samelson} suggests thinking of $\\Omega \\Sigma A$ as the\n``free associative algebra'' on $A$. Let us make this idea more precise.\n\\begin{remark}\n    The space $\\Omega A$ is homotopy equivalent to a topological monoid\n    $\\Omega_M A$, called the \\emph{Moore loops} on $A$. This means that\n    $\\Omega_M A$ has a \\emph{strict} unit and is \\emph{strictly} associative\n    (i.e., not just up to homotopy). Concretely,\n    $$\\Omega_M A := \\{(\\ell,\\omega):\\ell\\in\\RR_{\\geq 0}, \\omega:[0,\\ell]\\to A,\n    \\omega(0) = \\ast = \\omega(\\ell)\\},$$\n    topologized as a subspace of the product. There is an identity class\n    $1\\in\\Omega_M A$, given by $1 = (0,c_\\ast)$ where $c_\\ast$ is the constant\n    loop at the basepoint $\\ast$. The addition on this space is just given by\n    concatenatation. In particular, the lengths get added; this overcomes the\n    obstruction to $\\Omega A$ not being strictly associative, so the Moore\n    loops $\\Omega_M A$ are indeed strictly associative.\n    If the basepoint is nondegenerate, it is not hard to see that the inclusion\n    $\\Omega A\\hookrightarrow \\Omega_M A$ is a homotopy equivalence.\n\n    Given the space $A$, we can form the free monoid $\\mathrm{FreeMon}(A)$. The\n    elements of this space are just formal sequences of elements of $A$\n    (with topology coming from the product topology), and the multiplication is\n    given by juxtaposition. Let us adjoin the element $1 = \\ast$. As with all\n    free constructions, there is a map $A\\to\\mathrm{FreeMon}(A)$ which is\n    universal in the sense that any map $A\\to M$ to a monoid factors through\n    $\\mathrm{FreeMon}(A)$.\n    \n    The unit $A\\to\\Omega\\Sigma A$ is a map from $A$ to a monoid, so we get a\n    monoid map $\\beta:\\mathrm{FreeMon}(A)\\to\\Omega\\Sigma A$.\n    \\begin{theorem}[James]\n\tThe map $\\beta:\\mathrm{FreeMon}(A)\\to \\Omega\\Sigma A$ is a weak\n\tequivalence if $A$ is path-connected.\n    \\end{theorem}\n    The free monoid looks very much like the tensor product, as the following\n    theorem of James shows.\n    \\begin{theorem}[James]\\label{james-splitting}\n\tLet $J(A) = \\mathrm{FreeMon}(A)$. There is a splitting:\n\t$$\n\t\\Sigma J(A) \\simeq_w \\Sigma \\left(\\bigvee_{n\\geq 0}A^{\\wedge n}\\right).\n\t$$\n    \\end{theorem}\n    Applying homology to the splitting of Theorem \\ref{james-splitting} shows\n    that:\n    $$\n    \\wt{H}_\\ast(J(A)) \\simeq \\bigoplus_{n\\geq 0} \\wt{H}_\\ast(A^{\\wedge n}).\n    $$\n    Assume that our coefficients are in a PID, and that $\\wt{H}_\\ast(A)$ is\n    torsion-free; then this is just $\\bigoplus_{n\\geq 0}\\wt{H}_\\ast(A)^{\\otimes\n    n}$. In particular, we recover our computation of $H_\\ast(\\Omega S^n)$ from\n    these general facts.\n\\end{remark}\n\\subsection{The Serre exact sequence}\nSuppose $\\pi:E\\to B$ is a fibration over a path-connected base. Assume that\n$\\widetilde{H}_s(B) = 0$ for $s<p$ where $p\\geq 1$. Let $\\ast\\in B$ be a chosen\nbasepoint. Denote by $F$ the fiber $\\pi^{-1}(\\ast)$. Assume $\\widetilde{H}_t(F)\n= 0$ for $t<q$, where $q\\geq 1$.  We would like to use the Serre spectral\nsequence to understand $H_\\ast(E)$. As always, we will assume that $\\pi_1(B)$\nacts trivially on $H_\\ast(F)$. \n\nRecall that the Serre spectral sequence runs\n$$\nE^2_{s,t} = H_s(B;H_t(F)) \\Rightarrow H_{s+t}(E).\n$$\nOur assumptions imply that $E^2_{0,0}=\\Z$, and $E^2_{0,t} = 0$ for $t<q$.\nMoreover, $E^2_{s,0} = 0$ for $s<p$. In particular, $E^2_{0,q+t} = H_{q+t}(F)$\nand $E^2_{p+k,0} = H_{p+k}(B)$ --- the rest of the spectral sequence is\nmysterious.\n\nBy sparsity, the first possible differential is $d^{p}:H_p(B) \\to H_{p-1}(F)$, and\n$d^{p+q}:H_{p+1}(B)\\to H_{p}(F)$. In the mysterious zone, there are\ndifferentials that hit $E^2_{p,q}$.\n\nAgain by sparsity, the only differential is $d^s:E^s_{s,0}\\to E^s_{0,s-1}$ for\n$s<p+q-1$. This is called a \\emph{transgression}. It is the last possible\ndifferential which has a chance at being nonzero. This means that the cokernel\nof $d^s$ is $E^\\infty_{0,s-1}$. There is also a map $E^\\infty_{s,0}\\to\nE^s_{s,0}$. We obtain a mysterious composite \n\\begin{equation}\\label{part1-serre-lexseq}\n    0\\to E^\\infty_{s,0}\\to E^s_{s,0} \\simeq H_s(B) \\xrightarrow{d^s}\n    E^s_{0,s-1}\\simeq H_{s-1}(F) \\to E^\\infty_{0,s-1}\\to 0.\n\\end{equation}\n\nLet $n<p+q-1$. Recall that $F_s H_n(E) =\n\\img(H_\\ast(\\pi^{-1}(\\mathrm{sk}_s(B)))\\to H_\\ast(E))$, so $F_0 H_n(E) =\nE^\\infty_{0,n}$. Here, we are using the fact that $F_{-1} H_\\ast(E) = 0$. In\nparticular, there is a map $E^\\infty_{0,n}\\to H_n(E)$. By our hypotheses, there\nis only one other potentially nonzero filtration in this range of dimensions,\nso we have a short exact sequence:\n\\begin{equation}\\label{part2-serre-lexseq}\n    0\\to F_0 H_n(E) = E^\\infty_{0,n} \\to H_n(E) \\to E^\\infty_{n,0} \\to 0\n\\end{equation}\nSplicing the short exact sequences \\eqref{part1-serre-lexseq} and\n\\eqref{part2-serre-lexseq}, we obtain a long exact sequence:\n$$\nH_{p+q-1}(F)\\to \\cdots\\to H_n(F)\\to H_n(E)\\to H_n(B) \\xrightarrow{\\text{transgression}} H_{n-1}(F) \\to H_{n-1}(E)\\to \\cdots\n$$\nThis is called the \\emph{Serre exact sequence}. In this range of dimensions,\nhomology behaves like homotopy.\n", "meta": {"hexsha": "4df1bcb10f7c7c38fbb4df69e1397968a22b0c48", "size": 10618, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-63-sseq-applications.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "906/lec-63-sseq-applications.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "906/lec-63-sseq-applications.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 52.3054187192, "max_line_length": 123, "alphanum_fraction": 0.6738557167, "num_tokens": 3661, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673133042217, "lm_q2_score": 0.9059898273638387, "lm_q1q2_score": 0.7364495168501992}}
{"text": "\\documentclass[12pt,a4paper]{article}\r\n\\usepackage[utf8]{inputenc}\r\n\\usepackage{amsmath}\r\n\\usepackage{amsfonts}\r\n\\usepackage{amssymb}\r\n\\author{Karthik A}\r\n\\title{Machine Learning -- Course summary notes and guidelines}\r\n\\begin{document}\r\n\r\n\r\n\\maketitle\r\n\\part{Algorithms}\r\n\\section{Supervised Learning}\r\n\\subsection{Regression}\r\nCost function:\r\n$$J(\\theta) = \\frac{1}{2m}\\sum_{i=1}^m(y^{(i)}-h_\\theta(x^{(i)}))^2  + \\frac {\\lambda}{2m}\\sum_{j=1}^{n}\\theta_{j}^2$$\r\n\r\nGradient descent:\r\nSimultaneous update: $\\{$\r\n\r\n$\\theta_j := \\theta_j - \\frac {\\alpha}{m}\\frac {\\partial }{\\partial \\theta_j}J(\\theta) - \\alpha \\frac{\\lambda}{m}\\theta_j$\r\n\r\n$\\}$\r\n\r\n\r\nSimultaneous update: $\\{$\r\n\r\n$\\theta_j := \\theta_j - \\frac {\\alpha}{m} \\sum_{i=1}^{m} (h_\\theta(x^{(i)})-y)x^{(i)}$\r\n\r\n$\\}$\r\n\r\n\r\nFor small $\\alpha$, $J(\\theta)$ should reduce with every iteration\r\nIf polynomial regression, ensure feature scaling and mean normalization\r\n\r\nReplace each value with $(x-\\mu)/s$ where $s=(x_{max}- x_{min})$ or s=Std Deviation\r\n\r\n\\subsection{Logistic Regression}\r\n\r\nLogistic and cost function\r\n$$h_\\theta(x) = \\frac{1}{(1+e^-\\theta^T X)}$$\r\n$$J(\\theta) = -\\frac{1}{m}\\sum_{i=1}^{m}[y^{(i)}log(h_\\theta(x^{(i)}))+(1-y^{(i)})log(1-h_\\theta(x^{(i)}))]$$\r\n\r\nSimultaneous update: $\\{$\r\n\r\n$\\theta_j := \\theta_j - \\frac {\\alpha}{m} \\sum_{i=1}^{m} (h_\\theta(x^{(i)})-y)x^{(i)}$\r\n\r\n$\\}$\r\n\r\n\\subsection{Support Vector Machines (SVM)}\r\n\\begin{itemize}\r\n\\item if n is small (10k) and m is intermedeate (50k) use SVM. If n is small and m is large -- use logistic regression. Neural network is good for all but difficult to train\r\n\\item In SVM $C=1/\\lambda$\r\n\\item Without kernel or linear regression SVM is logistic regression\r\n\\end{itemize}\r\n\r\n\\subsection{Neural Network}\r\nBack propogation - neural network terminology for minimizing our cost funtion\r\n$\\delta = a -y$, where a is the activation value\\\\\r\nLayer L = Output layer\\\\\r\nLayer 1 = Input layer\\\\\r\n$s_j$ = units in layer j\\\\\r\n$a_i^{j}$ = activation of unit i in layer j\\\\\r\n$\\Theta^{(j)}$ =matrix of weights controlling function mapping from layer j to layer j+1\\\\\r\n$a^{j+1} = g(\\Theta^TX)$\\\\\r\nIf $s_j$ units in layer j, $s_{j+1}$ units in layer $(j+1)$, then dimensions of $\\Theta^{j}$ will be $s_{j+1}\\times(s_{j}+1)$\r\n\r\n\\section{Unsupervised Learning}\r\n\\subsection{K Means and Dimensionality reduction}\r\n\r\nHow to choose K in Kmeans \r\n\\begin{enumerate}\r\n\\item $J(\\theta)$ vs K -- see if it elbows out\r\n\\item No good elbows, use the downstream purpose. For example, shirt sizes\r\n\\end{enumerate}\r\n\r\n\r\nDimensionality reduction\r\n\\begin{itemize}\r\n\\item Data compression\r\n\\item Visualization\r\n\\end{itemize}\r\n\r\n\\[\r\n[U S V] = svd(\\Sigma)    \\;where , \\Sigma  = (1/m)\\sum (X*X^T)\r\n\\]\r\n\r\nDetermining number of dimensions k explaining variation of a target say 95\\% \r\n\\[Explained\\;Variation = 1 - \\sum_{i=1}^k s_{ii}/\\sum_{i=1}^n s_{ii}\\]\r\n\r\n\\subsection{Anomaly detection}\r\nCommon applications : Fraud detection, Manufacturing, monitoring machines in a large cluster\r\n\r\n\r\nDifferences between Anomaly detection and clustering\r\n\\begin{enumerate}\r\n\\item y=1 is very small , typically 0--20\r\n\\item y=0 is a large number\r\n\\item Different types of anamolies exist which are not known upfront\r\n\\end{enumerate}\r\n\r\nSome tips for anomaly detection\r\n\\begin{itemize}\r\n\\item Add a few failed samples to CV and test, do a $F_1$ score and evaluate the $\\epsilon$ values\r\n\\item When features are not gaussian distributed, use the $x^{(1/10)}$ or $x^{(1/2)}$  or $log(x)$ etc and make gaussian\r\n\\item When encountering common problem that p(x) is similar to regular in muti dimensions try,\r\n\\subitem --Introducing features such as \\\\$CPU Load/network traffic$ or \\\\$(CPU load)^2/network traffic$\r\n\\subitem --Use multivariate gaussian - automatically captures the correlation between features but is computationally expensive (also m \\textgreater n else $\\Sigma$ is not inversible)\r\n\\end{itemize}\r\n\r\n\\section{Recommend-er systems and COllaborative FIltering}\r\n\r\n$n_u$ = number of users (columns)(j)\r\n$n_m$ = number of movies (i)\r\n$r(i,j) = 1$ if user j has rated movie i\r\n\r\nX = hypothetical or real vector such as Genre - action, comedy each being a column $x^1$ or $x^2$ or $x^n$\r\n$m^j$ = number of movies rated by user j\r\n\r\nIn COFI , X is also not known\r\n\\begin{itemize}\r\n\\item min $\\theta$  = $\\sum_i \\sum _n$  and get the double gradient over X and $\\theta$\r\n\\item Initialize with small random values\r\n\\item Feature scaling is not required as the rating scale is always same across uses but mean normalization helps faster convergence\r\n\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\part{Practical suggestions for machine learning}\r\n\\section{Model selection and refinement}\r\n\r\n\\subsection{Over--fitting problem}\r\n\\begin{itemize}\r\n\\item Reduce the number of features\r\n\\item Use the model selection algorithm described later\r\n\\item Use regularization to reduce the magnitude of theta ($\\lambda$ high)\r\n\\end{itemize}\r\n\r\n\\subsection{Model selection}\r\n60\\%--20\\%--20\\% is a broad split for the train, cross validation and test sets\r\n\r\n\\begin{enumerate}\r\n\\item Get  the polynomial degree -- Find $J(\\theta)$ for each increasing polynomial feature. Test on CV to fix the polynomial features. Check on test \r\n\\item If underfit reduce $\\lambda$, if overfit , increase $\\lambda$ \\-- check the error on the CV set to fix the lambda value\r\n\\item To determine whether more or less data,  review the learning curves i.e plot the $J_{cv}$ and $J_{train}$ against increasing number of examples\r\n\\subitem ---- if $J_{cv}$ and $J_{train}$ are converging with less samples and the value is high, then it is High Bias problem and adding more data to the problem will not help\r\n\\subitem ---- if $J_{cv}$ and $J_{train}$ are different, then adding more samples will help them converge \\-- high variance problem\r\n\\item Error Analysis: General guideline, start with a simple algorithm and then increase the number of features. Manually examine the errors on examples in the cross validation set and try to spot a trend where most of the errors were made. We can find some feaures that may be useful\r\n\\end{enumerate}\r\n\r\n\\subsection{Types of actions possible}\r\n\\begin{enumerate}\r\n\\item Collect more data -- High variance\r\n\\item Try smaller set of features -- High Variance\r\n\\item Try additional features -- High Bias\r\n\\item Try polynomial features -- High Bias\r\n\\item Increasing $\\lambda$ -- High Variance\r\n\\item Decreasing $\\lambda$ -- High Bias\r\n\\end{enumerate}\r\n\r\n\r\n\r\n\\section{Pipeline Analysis}\r\nExample of pipeline for machine learning is given below:\r\nImage $\\rightarrow$ text detection $\\rightarrow$ Character segmentation $\\rightarrow$ Character recognition\r\n\r\n\r\n\\begin{itemize}\r\n\\item Sliding windows - step size or stride\r\n\\item 1D sliding window for char segmentation\r\n\\item Get lots of data and artificial data\r\n\\end{itemize}\r\n\r\n\\section{Rules for getting more data}\r\n\\begin{itemize}\r\n\\item Make sure you have a low bias classifier before starting data collection eg. add more features or hidden units in a neural network until bias is low\r\n\\item Estimate data collection effort\r\n\\item Ceiling analysis - which part of the pipeline must I improve - Look at the accuracy in the test set by feeding the $y_{actual}$ to the next part of the pipeline and see how it improves - delta accuracy should be used to determine where to put the effort\r\n\\end{itemize}\r\n\r\n\r\n\\section{Learning with large data sets}\r\n\\begin{itemize}\r\n\\item \\emph{It is not who has the best algorithm that wins but who has the most data. The problem with large data sets is that gradient descent is computationally expensive for each iteration} \r\n\\item Plot the learning curve and if high bias and J is ok, no need to do on the full data set (m) as it will converge before then -- adding more samples has no benefit\r\n\\item If high variance use map reduce -- i.e split the summation into separate machines\r\n\r\n\\end{itemize}\r\n\r\n\r\n\\subsection{Stochastic gradient} \r\n\\begin{itemize}\r\n\\item Stochastic gradient - Do gradient descent with m=1 after shuffling the data set\r\n\\item Mini batch - do gradient descent in batches b \\textless m\r\n\\item Batch gradient descent - full m\r\n\\end{itemize}\r\n\r\nPlot J over number of iterations and average over the batch sizes\r\n\\begin{enumerate}\r\n\\item Gets smoother with smaller $\\alpha$\r\n\\item Gets smoother with larger b\r\n\\item Clarifies with larger b if there is a lot of zig-zag in the chart\r\n\\item If J increases with b, use smaller $\\alpha$\r\n\\item interesting but not often used is reducing $\\alpha$ with iterations = $\\alpha = const/(const+iterations)$\r\n\r\n\\end{enumerate}\r\n\r\nOnline learning is extreme example where the data is taken evaluated and dropped immediately\r\n\r\n$P(y=1|r;\\theta)$ - predicted CTR (Click Through Rate)\r\n\r\n\r\n\r\n\\end{document}\r\n", "meta": {"hexsha": "2ab42d3f9fe7cdea299e9be5a474b332ee7db942", "size": 8713, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ML_AI_Rules_AndrewNg-20200419T122840Z-001/ML_AI_Rules_AndrewNg/my_summary.tex", "max_stars_repo_name": "tildekarthik/reflearn", "max_stars_repo_head_hexsha": "5615bdc49a96cd129d2f936498e945a0c2be4a03", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ML_AI_Rules_AndrewNg-20200419T122840Z-001/ML_AI_Rules_AndrewNg/my_summary.tex", "max_issues_repo_name": "tildekarthik/reflearn", "max_issues_repo_head_hexsha": "5615bdc49a96cd129d2f936498e945a0c2be4a03", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ML_AI_Rules_AndrewNg-20200419T122840Z-001/ML_AI_Rules_AndrewNg/my_summary.tex", "max_forks_repo_name": "tildekarthik/reflearn", "max_forks_repo_head_hexsha": "5615bdc49a96cd129d2f936498e945a0c2be4a03", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.337962963, "max_line_length": 285, "alphanum_fraction": 0.7192700562, "num_tokens": 2305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092415, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.736415643806581}}
{"text": "\\section{Bin smoothers}\nA bin smoother, also known as a regressogram, mimics a categorical\nsmoother by partitioning the predicted value into disjoint and\nexhaustive regions, then averaging the response in each\nregion. Formally, we choose cut-points $c_0 < \\dots <c_K$ where $c_0 =\n-\\infty$ and $c_K = \\infty$, and define\n\\[\nR_k = \\{i; c_k \\leq x_i < c_{k+1} \\}; k=0,\\dots,K\n\\]\nthe indexes of the data points in each region. Then $S[\\by|\\bx]$ is\ngiven by \n\\[\ns(x_0) = \\ave_{i \\in R_k}\\{ y_i \\} \\mbox{ if } x_0 \\in R_k\n\\]\n\nNotice that the bin smoother will have discontinuities. \n\n\n\\begin{figure}[htp]\n\\caption{\\label{f2.3} CD4 cell count since seroconversion for HIV\n  infected men.} \n\\centerline{\\epsfig{figure=Plots/plot-02-03.ps,angle=270,width=.8\\textwidth}}\n\\end{figure}\n\n", "meta": {"hexsha": "b72f1bca1667c0867f4051d8afc61e71d945d395", "size": 776, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-02-02.tex", "max_stars_repo_name": "igrabski/rafalab.github.io", "max_stars_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2016-08-17T23:04:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T19:21:02.000Z", "max_issues_repo_path": "pages/754/section-02-02.tex", "max_issues_repo_name": "igrabski/rafalab.github.io", "max_issues_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-18T00:41:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-21T22:35:40.000Z", "max_forks_repo_path": "pages/754/section-02-02.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 31.04, "max_line_length": 77, "alphanum_fraction": 0.7100515464, "num_tokens": 267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7363947808831892}}
{"text": "\\section*{Objective function}\nThe goal of the problem is to minimize the total amount of penalties generated by near conflicting exams, weighted on the number of enrolled students.\n\\[\n\\min{\\sum_{i=1}^n \\sum_{j=1}^n {\\frac{ns_{ij}}{|S|} (p_{1} y_{ij1} + p_{2} y_{ij2} + p_{3} y_{ij3} + p_{4} y_{ij4} + p_{5} y_{ij5})}}\n\\]\n\\[\n\\Rightarrow \\min{\\frac{1}{|S|} \\sum_{i=1}^n \\sum_{j=1}^n {ns_{ij} \\sum_ {k=1}^5 {p_{k} y_{ijk}}}}\n\\]", "meta": {"hexsha": "a520bf12d6ac67d9b868de72834781a8fc42aa81", "size": 424, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Model/obj_function.tex", "max_stars_repo_name": "enricofranco/examination-timetabling-problem", "max_stars_repo_head_hexsha": "b319595d93f560f1c34e753b44d5ba24dda17c2b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-02T17:49:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-02T17:49:44.000Z", "max_issues_repo_path": "Model/obj_function.tex", "max_issues_repo_name": "enricofranco/examination-timetabling-problem", "max_issues_repo_head_hexsha": "b319595d93f560f1c34e753b44d5ba24dda17c2b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Model/obj_function.tex", "max_forks_repo_name": "enricofranco/examination-timetabling-problem", "max_forks_repo_head_hexsha": "b319595d93f560f1c34e753b44d5ba24dda17c2b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-06-17T10:46:00.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-17T10:46:00.000Z", "avg_line_length": 53.0, "max_line_length": 150, "alphanum_fraction": 0.6320754717, "num_tokens": 180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517095103498, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.7363711914391864}}
{"text": "\\subsection{Vertex Bends}\n\\label{sec:Vertex-Bends}\n\n\\begin{figure}[!htp]\n\\centering\n\\begin{verbatim}\n                   e1\n             p1 o--------o p0\n                        a \\\n                           \\ e2\n                            \\\n                             o p2\n\\end{verbatim}\n\\caption{Polyline vertex neighborhood.\n\\label{fig:Polyline-vertex-neighborhood}}\n\\end{figure}\n\nIn this section, I disuss measures of curvature\nbased on the bending at each vertex in a polyline.\n\n%------------------------------------------------------------------\n\n\\subsubsection{Cosine}\n\\label{sec:polyline-vertex-cosine}\n\nConsider the non-boundary vertex\nat point $\\p_0 \\in \\Reals^3$ in figure \\ref{fig:Polyline-vertex-neighborhood}.\n$\\v$ has degree $2$;\nthe incident edges are labeled $\\e_1$ and $e_2$;\nand the neighboring vertices are at points $\\p_1 \\in \\Reals^3$\nand $\\p_2 \\in \\Reals^3$.\nThe shape of the neighborhood is determined by\n$\\p = (\\p_0, \\p_1, \\p_2) \\in \\Reals^9$\nThe unsigned angle between edges $\\e_1$ and $\\e_2$ is $\\alpha(\\p)$.\n\nOne measure of the amount of bending is the cosine of $\\alpha$:\n\\begin{equation}\n\\cos(\\alpha(\\p)) =\n{{(\\p_1 - \\p_0)} \\over {\\| \\p_1 - \\p_0 \\|} }\n\\bullet\n{{(\\p_2 - \\p_0)} \\over {\\| \\p_2 - \\p_0 \\|} }\n\\end{equation}\n\nA little calculus shows that the partial gradients are:\n\\begin{eqnarray}\n\\label{eq:polyline-vertex-cosine-gradient}\n\\Gf{\\p_0}{\\cos(\\alpha(\\p))}\n& = &\n-\n\\left[\n{{(\\p_1 - \\p_0) \\perp  (\\p_2 - \\p_0)}\n\\over\n{\\| \\p_1 - \\p_0 \\| \\| \\p_2 - \\p_0 \\|} }\n+\n{{(\\p_2 - \\p_0) \\perp  (\\p_1 - \\p_0)}\n\\over\n{\\| \\p_1 - \\p_0 \\| \\| \\p_2 - \\p_0 \\|} }\n\\right]\n\\\\\n\\Gf{\\p_1}{\\cos(\\alpha(\\p))}\n& = &\n{{(\\p_2 - \\p_0) \\perp  (\\p_1 - \\p_0)}\n\\over\n{\\| \\p_1 - \\p_0 \\| \\| \\p_2 - \\p_0 \\|} }\n\\nonumber\n\\\\\n\\Gf{\\p_2}{\\cos(\\alpha(\\p))}\n& = &\n{{(\\p_1 - \\p_0) \\perp  (\\p_2 - \\p_0)}\n\\over\n{\\| \\p_1 - \\p_0 \\| \\| \\p_2 - \\p_0 \\|} }\n\\nonumber\n\\end{eqnarray}\n\n%------------------------------------------------------------------\n\n\\subsubsection{Squared Cosine}\n\\label{sec:polyline-vertex-squared-cosine}\n\nFor any positive measure of bending,\nminimizing the sum of squared bends,\nrather than simply the sum of bends,\nwill tend to produce a more even distribution of curvature.\nSince $\\cos(\\alpha)$ ranges over $[-1,1]$,\nwe use $\\left( \\frac{1 + \\cos(\\alpha)}{2} \\right)^2$.\n\nThe gradient is:\n\\begin{equation}\n\\Gf{\\p}{\\left( {{1 + \\cos(\\alpha(\\p))} \\over 2} \\right)^2}\n=\n\\left( 1 + \\cos(\\alpha(\\p)) \\right)\n\\Gf{\\p}{\\cos\\left(\\alpha(\\p)\\right)}\n\\end{equation}\n\n$\\Gf{\\p}{\\cos\\left(\\alpha(\\p)\\right)}$ is given\nin equation \\ref{eq:polyline-vertex-cosine-gradient}.\n\n%------------------------------------------------------------------\n\n\\subsubsection{Angle}\n\\label{sec:polyline-vertex-angle}\n\n\nThe angle $\\alpha$ is $\\pi$ for a straight polyline,\nand $0$ for a maximally bent vertex.\nTherefore we may choose to minimize the sum of negative angles:\n\\begin{equation}\n-\\alpha(\\p) =\n-\\cos^{-1} \\left(\n{{(\\p_1 - \\p_0)} \\over {\\| \\p_1 - \\p_0 \\|} }\n\\bullet\n{{(\\p_2 - \\p_0)} \\over {\\| \\p_2 - \\p_0 \\|} }\n\\right)\n\\end{equation}\n\nThe gradient is:\n\\begin{equation}\n\\Gf{\\p}{-\\alpha(\\p)}\n=\n{{1} \\over {\\sqrt{ 1 - \\cos(\\alpha(\\p))^2}}}\n\\Gf{\\p}{\\cos\\left(\\alpha(\\p)\\right)}\n\\end{equation}\n\n$\\Gf{\\p}{\\cos\\left(\\alpha(\\p)\\right)}$ is given\nin equation \\ref{eq:polyline-vertex-cosine-gradient}.\n\n%------------------------------------------------------------------\n\n\\subsubsection{Squared Angle}\n\\label{sec:polyline-vertex-squared-angle}\n\nSince $-\\alpha$ ranges over $[-\\pi,0]$\nwe square $\\pi - \\alpha$.\n\nThe gradient is:\n\\begin{equation}\n\\Gf{\\p}{\\left( \\pi - \\alpha(\\p) \\right)^2}\n=\n{{2 \\left( \\pi - \\alpha(\\p) \\right)}\n\\over\n{\\sqrt{ 1 - \\cos(\\alpha(\\p))^2}}}\n\\Gf{\\p}{\\cos\\left(\\alpha(\\p)\\right)}\n\\end{equation}\n\n$\\Gf{\\p}{\\cos \\left( \\alpha(\\p) \\right)}$ is given\nin equation \\ref{eq:polyline-vertex-cosine-gradient}.\n\n", "meta": {"hexsha": "98db5f7aec960ecc9b912d8545743bfa8a29d207", "size": 3802, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fotm/curves.tex", "max_stars_repo_name": "palisades-lakes/les-elemens", "max_stars_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/old/fotm/curves.tex", "max_issues_repo_name": "palisades-lakes/les-elemens", "max_issues_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/old/fotm/curves.tex", "max_forks_repo_name": "palisades-lakes/les-elemens", "max_forks_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.6891891892, "max_line_length": 78, "alphanum_fraction": 0.5602314571, "num_tokens": 1350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7362501641793358}}
{"text": "%================================\n\\section{Quotient Spaces}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t[quotient topology]\n\t\\label{def: quotient topology}\n\tLet $(X, \\mathcal T)$ be a topological space and let $\\sim$ be an equivalence relation on $X$. The \\textit{quotient topology} is a topology on $\\mathcal P(X/ \\sim)$; it is defined as\n\t$$\n\t\\mathcal T_{X / \\sim} = \\left\\{ U \\in \\mathcal P(X/\\sim) : \\{ x \\in X: [x] \\in U \\} \\in \\mathcal T_X \\right\\}.\n\t$$\n\\end{definition}\n%--------------------------------", "meta": {"hexsha": "1f8a59a0ac6b6f7250dcda4d235c4f75da811284", "size": 556, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-v0/quotient-spaces.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-v0/quotient-spaces.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-v0/quotient-spaces.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.0666666667, "max_line_length": 183, "alphanum_fraction": 0.4946043165, "num_tokens": 160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7362501621779485}}
{"text": "\\documentclass{article}\n\\usepackage{graphics} % Required for the inclusion of images\n\\usepackage{graphicx}\n\\usepackage{caption}\n\\usepackage{amsmath,amsfonts}\n\\usepackage{subfigure}\n\\usepackage{listings}\n\\title{Math Cookbook}\n\\author{Junyan Su} \n\\date{\\today}\n\\begin{document}\n\\maketitle\n\n\\section{Linear Algebra}\n\\textbf{Sherman–Morrison formula:} \n\\begin{equation}\n\\left(A+u v^{\\top}\\right)^{-1}=A^{-1}-\\frac{A^{-1} u v^{\\top} A^{-1}}{1+v^{\\top} A^{-1} u}\n\\end{equation}\n\\begin{equation}\n(A+U C V)^{-1}=A^{-1}-A^{-1} U\\left(C^{-1}+V A^{-1} U\\right)^{-1} V A^{-1}\n\\end{equation}\n\n\\section{Caculus}\n\\noindent\\textbf{Leibniz integral rule:}\n\\begin{equation}\n\\frac{d}{d x}\\left(\\int_{a(x)}^{b(x)} f(x, t) d t\\right)=f(x, b(x)) \\cdot \\frac{d}{d x} b(x)-f(x, a(x)) \\cdot \\frac{d}{d x} a(x)+\\int_{a(x)}^{b(x)} \\frac{\\partial}{\\partial x} f(x, t) d t\n\\end{equation}\n\\textbf{Grönwall's inequality} from two useful references~\\cite{jonesFundamental1964,mitrinovicInequalities2012}. \n\\begin{align}\n\tf(x) &\\geq a(x)+b(x) \\int_{\\underline{x}}^{x} f(u) d u, x \\in[\\underline{x}, \\bar{x}] \\\\\n\t\\implies f(x) &\\geq a(x)+b(x) \\int_{\\underline{x}}^{x} a(u) \\exp \\left(\\int_{u}^{x} b(s) d s\\right) d u, \\quad x \\in[\\underline{x}, \\bar{x}]\n\\end{align}\n\n\\noindent\\textbf{Grönwall's inequality in differential form:}\n\\begin{align}\n\tf'(x) &\\leq b(x) f(x) \\\\\n\t\\implies f(x) &\\leq f(\\underline{x}) \\exp\\left( \\int_{\\underline{x}}^{x} b(s) ds \\right)\n\\end{align}\n\n\n\\bibliographystyle{plain}\n\\bibliography{ref}\n\n\n\n\\end{document}", "meta": {"hexsha": "2c886d62a279bb17f275c586f46df958628dec6c", "size": 1501, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/pdf/math/math.tex", "max_stars_repo_name": "sujunyan/al-folio", "max_stars_repo_head_hexsha": "d4ecbcdbc197e96218047ad8205bfd768b476a42", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assets/pdf/math/math.tex", "max_issues_repo_name": "sujunyan/al-folio", "max_issues_repo_head_hexsha": "d4ecbcdbc197e96218047ad8205bfd768b476a42", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assets/pdf/math/math.tex", "max_forks_repo_name": "sujunyan/al-folio", "max_forks_repo_head_hexsha": "d4ecbcdbc197e96218047ad8205bfd768b476a42", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-13T08:25:49.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-13T08:25:49.000Z", "avg_line_length": 32.6304347826, "max_line_length": 187, "alphanum_fraction": 0.6508994004, "num_tokens": 600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7361696806421271}}
{"text": "\\section{Local minimums}\n\\par Now we want to start studying the unconstrained optimisation problems. The optimisation problems are always conducted over a set of values, and the most simple form of optimisation problems are those whose sets are not constrained at all. Thus the name of \\textit{unconstrained} optimisation.\n\\par The problem that we deal with is typically described by the following syntax:\n\\begin{equation}\n    f_* = \\min \\{f(x) : x \\in \\mathbb{R}^n\\}\n\\end{equation}\n\\par In these kind of problems only the objective function accounts. Since the set is unbounded, the Weierstrass theorem cannot be applied. Many problems in Machine Learning are of this very kind. Thus, these problems are quite important to study. Moreover, the things that we are going to develop will also be very important for the more difficult version of optimisation problems, that is the constrained version. You need to be able to do the unconstrained optimisation in order to do the constrained optimisation.\n\\par Note that in unconstrained optimisation, the set over which the function is defined is the whole space $\\mathbb{R}^n$. This implies that we cannot use Weierstrass theorem.\n\\par If we aim to find a global minimum of a problem that does not have any special property, is a very hard to solve. Even when we know that a function admits a global minimum, it may be very hard to recognise it. Actually this is usually the major problem. Detecting \\textit{a} minimum may be easy, recognising (proving that it is actually a global minimum is what is difficult (see figure \\ref{fig:chapter2-many_minimums}). We won't touch this argument in this course, but for not fainted heart look into globalisation techniques.\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.3]{figures/2/chapter2-many_minimums.png}\n    \\caption{There are different minimums, which one is local and which one is global? It depends where we start looking for it.}\n    \\label{fig:chapter2-many_minimums}\n\\end{figure}\n\\par For this reason, we usually start simple and small: find a local minimum. We say that $x_*$ is a local minimum if it solves the problem:\n\\begin{equation}\n    \\min \\{f(x) : x \\in \\mathcal{B}(x_*,\\epsilon)\\}\n\\end{equation}\nfor some $\\epsilon > 0$. We say it is a strict local minimum if: $f(x) < f(y)\\ \\forall y \\in \\mathcal{B}(x_*,\\epsilon)$.\n\\par If the objective function $f$ is differentiable, then we already know how to compute it. If $x_*$ is a local minimum then its first order derivative (the gradient $\\nabla$) is zero:\n\\begin{equation}\n    x^* \\textit{ is local minimum} \\Rightarrow \\nabla f(x^*) = 0\n\\end{equation}\nThis is called \\textbf{first order (necessary, local) optimality condition}.\n\\begin{proof}\nBy contradiction. Suppose that $x^*$ is a local minimum and that $\\nabla f(x^*) \\neq 0$. Since the gradient is not 0, we can perform a step in the opposite direction in order to lower a little bit the objective function:\n\\begin{equation}\n    f(x-\\alpha\\nabla f(x))\n\\end{equation}\n\\par Let us now consider the Taylor extension (first order) of $f$ in the point $x-\\alpha\\nabla f(x)$:\n\\begin{equation}\n\\begin{split}\n    f(x-\\alpha\\nabla f(x)) &= f(x) + ((x - \\alpha\\nabla f(x)) - x)\\nabla f(x) + R(-\\alpha\\nabla f(x)) =\\\\\n    &= f(x) - \\alpha \\Vert \\nabla f(x) \\Vert^2 + R(-\\alpha\\nabla f(x))\n\\end{split}\n\\end{equation}\nwhere:\n\\begin{equation}\n    \\lim_{h \\rightarrow 0} \\frac{R(h)}{\\Vert h \\Vert} = 0\n\\end{equation}\n\\par The point here is that residual goes to 0 quicker than linear. In other words, if we consider the limit in $\\alpha$ (because we are moving a little bit further from $x^*$), the limit must obey to the following relation:\n\\begin{equation}\n    \\lim_{\\alpha \\rightarrow 0} \\frac{R(-\\alpha\\nabla f(x))}{\\Vert -\\alpha\\nabla f(x) \\Vert} = \\frac{R(-\\alpha\\nabla f(x))}{\\alpha\\Vert \\nabla f(x) \\Vert}\n\\end{equation}\n\\par But what is the definition of the good old limit?\n\\begin{equation}\n    \\forall\\epsilon\\ \\exists\\bar{\\alpha}\\ s.t.\\ \\frac{R(-\\alpha\\nabla f(x))}{\\alpha\\Vert \\nabla f(x) \\Vert} \\leq \\epsilon\\ \\forall \\alpha\\ 0 < \\alpha < \\bar{\\alpha}\n\\end{equation}\n\\par We can choose $\\epsilon$ however small, as long as it is greater than 0. So let's take $\\epsilon$ strictly less than $\\nabla f(x)$. This is possible since we assumed it is $\\neq 0$.\n\\begin{equation}\n    \\epsilon < \\Vert \\nabla f(x) \\Vert \n\\end{equation}\n\\par But then we have that:\n\\begin{equation}\n    \\forall\\epsilon\\ \\exists\\bar{\\alpha}\\ s.t.\\ \\frac{R(-\\alpha\\nabla f(x))}{\\alpha\\Vert \\nabla f(x) \\Vert} \\leq \\epsilon < \\Vert \\nabla f(x) \\Vert\\ \\forall \\alpha\\ 0 < \\alpha < \\bar{\\alpha}\n\\end{equation}\n\\par This leads us to:\n\\begin{equation}\n    \\forall\\epsilon\\ \\exists\\bar{\\alpha}\\ s.t.\\ R(-\\alpha\\nabla f(x)) \\leq \\epsilon < \\alpha \\Vert \\nabla f(x) \\Vert^2\\ \\forall \\alpha\\ 0 < \\alpha < \\bar{\\alpha}\n\\end{equation}\n\\par Finally we get the contradiction:\n\\begin{equation}\n\\begin{split}\n    f(x-\\alpha\\nabla f(x)) &= f(x) - \\alpha \\Vert \\nabla f(x) \\Vert^2 + R(-\\alpha\\nabla f(x)) = \\\\\n    &= f(x) - \\alpha \\Vert \\nabla f(x) \\Vert^2 + R(-\\alpha\\nabla f(x)) < f(x)\n\\end{split}\n\\end{equation}\nwhich holds $\\forall \\alpha < \\bar{\\alpha}$.\n\\end{proof}\n\\par Note that in order to be able to to the first order Taylor extension, we need the function to be continuous, in other words $f \\in C^1$.\n\\par If we are in a point whose first order derivative is not 0, then we can consider a ball around it, however small, we can make a step into anti-gradient direction in order to lower a bit the objective function value.\n\\par This is actually only a necessary condition and not also the sufficient. If we have a point $x$ where the first order derivative is 0 then we know only that $x$ is a stationary point. A stationary point is a point on the graph where the function stops increasing or decreasing. Basically, it could also be a simple inflection (saddle) point or a maximum (local or global). They all look the same when you consider the first order information. That's why we say that the problem is not finding but rather recognising the global minimum. The techniques that are used for distinguish between local and global minimums are called globalisation techniques. We won't touch them in this course.\n\\par Take away is: whenever we are dealing with nasty functions, we will not require a global minimum. Only under certain conditions, when it is easy, we will deal with global minimums.\n\\par To distinguish between saddle points, maximums and minimums, we need to look into the Hessian (second order derivative, i.e. derivative of the gradient). Positive definite Hessian identifies a strict minimum point, a positive negative Hessian identifies a strict maximum point, a indefinite Hessian identifies a saddle point.\n\\begin{equation}\n    x^* \\textit{ is a local minimum} \\Rightarrow \\nabla^2 f(x^*) \\succeq 0\n\\end{equation}\nThis is called \\textbf{Second order (necessary, local) optimality condition}. Let us now prove this.\n\\begin{proof}\nBy contradiction. Assume that $x^*$ is a local minimum and that its Hessian is not positive semi-definite, i.e. $\\nabla^2 f(x^*) \\prec 0$. If the Hessian is negative, this means that there is a vector $d$ with $\\Vert d \\Vert = 1$ such that:\n\\begin{equation}\n    d^T \\nabla^2 f(x^*) d \\leq 0\n\\end{equation}\nAt the same time, since we are talking about a stationary point, we know that the gradient in $x^*$ is 0, i.e. $\\nabla f(x^*) = 0$. Let us now consider the Taylor expansion up to the second level:\n\\begin{equation}\n\\begin{split}\n    f(x^* + \\alpha d) &= f(x^*) + ((x^* + \\alpha d) - x^*) \\nabla f(x^*) +\\\\\n    &+ \\frac{1}{2}((x^* + \\alpha d) - x^*)^2 \\nabla^2 f(x^*) + R(\\alpha d) =\\\\\n    &= f(x^*) + \\frac{1}{2}\\alpha^2 d^T \\nabla^2 f(x^*) d + R(\\alpha d)\n\\end{split}\n\\end{equation}\nwhere:\n\\begin{equation}\n    \\lim_{\\alpha \\rightarrow 0} \\frac{R(\\alpha d)}{\\Vert \\alpha d \\Vert^2} = \\lim_{\\alpha \\rightarrow 0} \\frac{R(\\alpha d)}{\\alpha^2 \\Vert d \\Vert^2} = \\lim_{\\alpha \\rightarrow 0} \\frac{R(\\alpha d)}{\\alpha^2} = 0\n\\end{equation}\nThat is, the remainder goes to 0 quicker that the quadratic function in $\\alpha$.\n\\par By applying now the definition of the limit we get:\n\\begin{equation}\n    \\forall \\epsilon > 0\\ \\exists \\bar{\\alpha} > 0\\ s.t.\\ R(\\alpha d) \\leq \\epsilon \\alpha^2\\ \\forall \\alpha < \\bar{\\alpha}\n\\end{equation}\nLet us now take $0 < \\epsilon < - \\frac{1}{2} d^T \\nabla^2 f(x^*) d$. Remember that our Hessian is negative definite and that we assumed that $d$ is mapped to a negative number. If we choose such an $\\epsilon$, we get the following:\n\\begin{equation}\n    R(\\alpha d) < - \\alpha^2 \\frac{1}{2} d^T \\nabla^2 f(x^*) d\n\\end{equation}\nand so:\n\\begin{equation}\n    f(x^* + \\alpha d) = f(x^*) + \\frac{1}{2} \\alpha^2 d^T \\nabla^2 f(x^*) d + R(\\alpha d) < f(x^*)\\ \\forall \\alpha < \\bar{\\alpha}\n\\end{equation}\n\\end{proof}\n\\par Note that in order to be able to to the second order Taylor extension, we need the function to be continuously differentiable, in other words $f \\in C^2$.\n\\par If we want to be sure that we are in a local minimum, we need to require the Hessian to be strictly positive definite, not positive semi-definite. That is, we have the \\textbf{Second order (sufficient, local) optimality condition}:\n\\begin{equation}\n    f \\in C^2 \\wedge \\nabla f(x^*) = 0 \\wedge \\nabla^2 f(x^*) \\succ 0 \\Rightarrow x^* \\textit{ is a local minimum}\n\\end{equation}\n\\begin{proof}\nLet us consider again the second order Taylor expansion:\n\\begin{equation}\n    f(x^* + d) = f(x^*) + \\frac{1}{2} d^T \\nabla^2 f(x^*) d + R(d)\n\\end{equation}\nagain with:\n\\begin{equation}\n    \\lim_{d \\rightarrow 0} \\frac{R(d)}{\\Vert d \\Vert^2} = 0\n\\end{equation}\nSince the Hessian is positive definite, we know that all its eigenvalues are strictly positive and that every vector $d$ is mapped to another space with the following relation:\n\\begin{equation}\n    \\lambda_{\\min} \\Vert d \\Vert^2 \\leq d^T \\nabla^2 f(x^*) d \\leq \\lambda_{\\max} \\Vert d \\Vert^2\n\\end{equation}\nConsider again the definition of the limit:\n\\begin{equation}\n    \\forall \\epsilon > 0\\ \\exists \\delta > 0\\ s.t.\\ R(d) \\leq \\epsilon \\Vert d \\Vert^2\\ \\forall d\\ \\Vert d \\Vert < \\delta\n\\end{equation}\nLet us now take $\\epsilon < \\lambda_{\\min}$. We then get:\n\\begin{equation}\n    f(x^* + d) = f(x^*) + \\frac{1}{2} d^T \\nabla^2 f(x^*) d + R(d) \\geq f(x^*) + (\\lambda_{\\min} - \\epsilon) \\Vert d \\Vert^2 > f(x^*)\n\\end{equation}\nThis means that in each direction we take from $x^*$ we end up in a place where the value of the objective function is strictly greater than in $x^*$.\nThis means that we have a strictly quadratic function that locally (in a ball $\\mathcal{B}(x^*,\\epsilon)$) approximates our function.\n\\end{proof}\n\\par Unfortunately, these conditions are also locally defined. They cannot be applied to the global case. Some properties need to be valid on our problem in order to be able to find global minimums.\n%\n%\n%\n\\section{Towards global minimum}\n\\par Let us start with an intuition: if we are in the local minimum that is not the global minimum, then we necessarily have to grow from that local minimum and then decrease towards a global minimum (figure \\ref{fig:chapter2-towards_global1}). In other words, there has to be a local maximum before the global minimum (remember Rolle's theorem).\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.3]{figures/2/chapter2-towards_global1.png}\n    \\caption{Between a local minimum and a global minimum, there must be a local/global maximum.}\n    \\label{fig:chapter2-towards_global1}\n\\end{figure}\n\\par We want our function to have only local minimums in the stationary points. That is each time we are in a stationary point, we have a positive semi-definite matrix. In formula:\n\\begin{equation}\n    \\label{eq:sufficient-local-global}\n    \\nabla f(x) = 0 \\Rightarrow \\nabla^2 f(x) \\succeq 0\n\\end{equation}\nThe sufficient condition for having \\ref{eq:sufficient-local-global} is to have the positive semi-definite Hessian on the whole space over which our function is defined. That is:\n\\begin{equation}\n    \\forall x \\in \\mathbb{R}^n \\dot \\nabla^2 f(x) \\succeq 0\n\\end{equation}\nThe functions satisfying this property are called \\textbf{Convex Functions} (figure \\ref{fig:chapter2-convex_function}).\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.3]{figures/2/chapter2-convex_function.png}\n    \\caption{An example of a convex function.}\n    \\label{fig:chapter2-convex_function}\n\\end{figure}\n\\par Optimising convex functions is usually an easy problem (not always). Optimising non convex functions is instead a much more difficult problem. Infact in ML usually one always tries to build a convex model because every local minimum is also a global minimum, mathematically true. Whenever this is not possible, one usually does not require a global minimum and gets satisfied with a local one.\n%\n%\n%\n\\section{Convexity}\n\\subsection{Introduction}\n\\par Given two points $x,y$ in a space $\\mathbb{R}^n$, we define the segment (set of points) joining those two points with the following equation:\n\\begin{equation}\n    \\textit{conv}(x,y) = \\{z = \\alpha x + (1-\\alpha) y \\ :\\ \\alpha \\in [0,1]\\}\n\\end{equation}\n\\par Given a set, we say that it is a \\textbf{convex set}, if any time we take two points inside the set, the segment joining these two points is entirely contained in the set (see figure \\ref{fig:chapter2-convex_set}).\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.4]{figures/2/chapter2-convex_set.png}\n    \\caption{An example of the convex set with the segment joining two points entirely contained in the set.}\n    \\label{fig:chapter2-convex_set}\n\\end{figure}\nSimilarly, if the set does not contain the whole segment, the set is not a convex set (see figure \\ref{fig:chapter2-non_convex_set}).\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.4]{figures/2/chapter2-non_convex_set.png}\n    \\caption{An example of the non convex set.}\n    \\label{fig:chapter2-non_convex_set}\n\\end{figure}\n\\par The nice thing is that every non convex set can be made a convex set. Basically, you perform a closure operation until there are some points to be added (see figure \\ref{fig:chapter2-completed_non_convex_set}). There are actually in infinite number of sets that ``complete'' the non convex set, but the smallest one is of our interest and it is called \\textbf{convex hull}.\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.4]{figures/2/chapter2-completed_non_convex_set.png}\n    \\caption{Any non convex set can be completed into a convex set.}\n    \\label{fig:chapter2-completed_non_convex_set}\n\\end{figure}\n\\par Clearly, we can generalise the concept from above. Instead of using two points, we can use an arbitrarily large number of points.\n\\begin{equation}\n    \\textit{conv}(\\{x_1,...,x_k\\}) = \\{x = \\sum_{i=1}^k \\alpha_i x_i\\ :\\ \\sum_{i=1}^k \\alpha_i = 1 \\wedge \\forall \\alpha_i \\geq 0\\}\n\\end{equation}\n\\par We then have the following relation:\n\\begin{equation}\n    C \\textit{ is convex} \\iff \\textit{conv}(\\{x_1,...,x_k\\}) \\subseteq C\\  \\forall x_1,...,x_k \\in C\n\\end{equation}\nIn other words, a set $C$ is convex if every time we take $k$ elements and we make a convex hull of them, that convex hull is completely inside the $C$.\n\\par \\textbf{Exercise}. Close and convex properties are not the same. Provide an example of a set that is closed but not convex and viceversa. Moreover, prove that:\n\\begin{equation}\n    \\label{eq:closed_and_convex}\n    C \\textit{ closed} \\centernot \\Rightarrow \\textit{conv}(C) \\textit{ closed}\n\\end{equation}\nUltimately, explain under which condition the logical equation \\ref{eq:closed_and_convex} is true. Actually, quite always this is the case.\n\\par \\textbf{Solution}. One example of a closed but not convex set is the set of natural numbers. An example of convex but not closed set is $(0,1)$. In order to prove \\ref{eq:closed_and_convex}, we need an example of the closed set whose convex hull is not closed. TO FINISH.\n%\n\\subsection{Examples of convex sets}\n\\par The convex sets are not rare. There are plenty of them, and we use some operations that preserve convexity in order to create other convex sets. Let us see some of the obvious convex sets:\n\\begin{itemize}\n    \\item Convex hull. Of course.\n    \\item Affine hyperplane: $\\mathcal{H} = \\{ax = b\\ :\\ x \\in \\mathbb{R}^n\\}$. A hyperplane is a subspace whose dimension is one less than that of its ambient space. If a space is 3-dimensional then its hyperplanes are the 2-dimensional planes, while if the space is 2-dimensional, its hyperplanes are the 1-dimensional lines.\n    \\item Affine subspaces: $\\mathcal{H} = \\{ax \\leq b\\ :\\ x \\in \\mathbb{R}^n\\}$.\n    \\item Ball in $p$-norm, $p \\geq 1$: $\\mathcal{B}_p(x,r) = \\{y \\in \\mathbb{R}^n\\ :\\ \\Vert x-y \\Vert_p \\leq r\\}$.\n    \\item Ellipsoid (figure \\ref{fig:chapter2-ellipsoid}): $\\mathcal{E}(Q,x,r) = \\{y \\in \\mathbb{R}^n\\ :\\ (y-x)^T Q (y-x) \\leq r\\}$, and $Q$ positive semidefinite.\n    \\begin{figure}\n        \\centering\n        \\includegraphics[scale=0.4]{figures/2/chapter2-ellipsoid.png}\n        \\caption{An example of an Ellipsoid.}\n        \\label{fig:chapter2-ellipsoid}\n    \\end{figure}\n    \\item All of the previous sets are closed, but also the open version is convex.\n    \\item Convex cones. There are different kinds of cones, for instances:\n    \\begin{itemize}\n        \\item Conical hull (polyhedral cone, see figure \\ref{fig:chapter2-polyhedral_cone}):\n        \\begin{equation}\n            \\textit{cone}(\\{d_1,...,d_k\\}) = \\{d = \\sum_{i=1}^k \\mu_i d_i\\ :\\ \\mu_i \\geq 0\\ \\forall i\\}\n        \\end{equation}\n        \\begin{figure}\n            \\centering\n            \\includegraphics[scale=0.5]{figures/2/chapter2-polyhedral_cone.png}\n            \\caption{An example of a polyhedral cone.}\n            \\label{fig:chapter2-polyhedral_cone}\n        \\end{figure}\n        \\item Lorentz (ice-cream) cone (see figure \\ref{fig:chapter2-lorentz_cone}):\n        \\begin{equation}\n            \\mathbb{L} = \\Bigg\\{x \\in \\mathbb{R}^n\\ :\\ x_n \\geq \\sqrt{\\sum_{i=1}^{n-1} x_i^2}\\Bigg\\}\n        \\end{equation}\n        \\begin{figure}\n            \\centering\n            \\includegraphics[scale=0.5]{figures/2/chapter2-lorentz_cone.png}\n            \\caption{An example of a Lorentz cone.}\n            \\label{fig:chapter2-lorentz_cone}\n        \\end{figure}\n        \\item Cone of the positive semidefinite matrices (see figure \\ref{fig:chapter2-cones_positive_semidefinite_matrices}):\n        \\begin{equation}\n            \\mathbb{S}_+ = \\{A \\in \\mathbb{R}^{n \\times n}\\ :\\ A \\succeq 0\\}\n        \\end{equation}\n        \\begin{figure}\n            \\centering\n            \\includegraphics[scale=0.4]{figures/2/chapter2-cones_positive_semidefinite_matrices.png}\n            \\caption{Some examples of positive semidefinite matrices that generate cones.}\n            \\label{fig:chapter2-cones_positive_semidefinite_matrices}\n        \\end{figure}\n        The last two cases of cones, are examples of non-polyhedral cones.\n    \\end{itemize}\n\\end{itemize}\n\\par \\textbf{Exercise}. Prove that the above sets are convex. Provide an example of a non convex cone.\n%\n\\subsection{Operations that preserve convexity}\n\\par Let us now see some operations that preserve the convexity. These operations are frequently used to extend the set of convex sets.\n\\begin{itemize}\n    \\item The intersection of convex sets $\\{C_i\\}_{i \\in I} = \\bigcap_{i \\in I} C_i$ is a convex set.\n    \\item The Cartesian product of convex sets $\\{C_i\\}_{i \\in I} = C_1 \\times ... \\times C_{|I|}$ is a convex set.\n    \\item Given a convex set $C$, then the image of its linear transformation (scaling, rotating, translating) $A(C) = \\{x = Ay + b\\ :\\ y \\in C\\}$ is a convex set.\n    \\item Given a convex set $C$, then the inverse image of its linear transformation (scaling, rotating, translating) $A^{-1}(C) = \\{x\\ :\\ Ax + b \\in C\\}$ is a convex set.\n    \\item Given two convex sets $C_1$ and $C_2$, then its linear combination $\\alpha_1 C_1 + \\alpha_2 C_2 = \\{x = \\alpha_1 x_1 + \\alpha_2 x_2\\ :\\ x_1 \\in C_1, x_2 \\in C_2\\}$ with any $\\alpha_1, \\alpha \\in \\mathbb{R}$ is a convex set.\n    \\item Slice is a convex set: given that $C \\subseteq \\mathbb{R}^n = \\mathbb{R}^{n_1} \\times \\mathbb{R}^{n_1}$, then we define slice $C(y) = \\{x \\in \\mathbb{R}^{n_1}\\ :\\ (x,y) \\in C\\}$ (see figure \\ref{fig:chapter2-slice}).\n    \\begin{figure}\n        \\centering\n        \\includegraphics[scale=0.3]{figures/2/chapter2-slice.png}\n        \\caption{An example of a slice object.}\n        \\label{fig:chapter2-slice}\n    \\end{figure}\n    \\item Shadow is a convex set: given that $C \\subseteq \\mathbb{R}^n = \\mathbb{R}^{n_1} \\times \\mathbb{R}^{n_1}$, then we define shadow $C^1 = \\{x \\in \\mathbb{R}^{n_1}\\ :\\ \\exists y\\ s.t.\\ (x,y) \\in C\\}$ (see figure \\ref{fig:chapter2-shadow}).\n    \\begin{figure}\n        \\centering\n        \\includegraphics[scale=0.05]{figures/2/chapter2-shadow.png}\n        \\caption{An example of a shadow object.}\n        \\label{fig:chapter2-shadow}\n    \\end{figure}\n\\end{itemize}\n\\par \\textbf{Exercise}. Is the union of two convex set convex? Given a matrix $A \\in \\mathbb{R}^{m \\times n}$, prove that the polyhedron of type $\\mathcal{P} = \\{x \\in \\mathbb{R}^n\\ :\\ Ax \\leq b\\}$ is convex.\n\\par \\textbf{Exercise}. Given a polyhedron $\\mathcal{P}$, prove that $\\{d\\ :\\ x + \\alpha d \\in \\mathcal{P}, \\forall x \\in \\mathcal{P}, \\alpha \\geq 0\\}$ (its recession cone) is a cone. (hint: look at $\\mathcal{C} = \\{x \\in \\mathbb{R}^n\\ :\\ Ax \\leq 0\\}$)\n%\n\\subsection{Convex functions}\n\\par Let us define a convex function informally. A function is said to be convex if for any two points of its domain, the line connecting those two points is completely above the function itself (see figure \\ref{fig:chapter2-informal_convex_function}).\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.6]{figures/2/chapter2-informal_convex_function.png}\n    \\caption{An example of a convex function.}\n    \\label{fig:chapter2-informal_convex_function}\n\\end{figure}\n\\par Formally (see figure \\ref{fig:chapter2-formal_convex_function}), for any two points $x,y \\in \\text{dom}(f) \\subseteq \\mathcal{R}^n, \\alpha \\in [0,1]$ we have that:\n\\begin{equation}\n    \\alpha f(x) + (1-\\alpha)f(y) \\geq f(\\alpha x + (1-\\alpha)y)\n\\end{equation}\nWhat we are saying is that given two points in the domain of the function, the line connecting them is the approximation model of the real function, given that we know just those two points. This line is at least the very same piece of the function $f$ or it must be that it is above. This must happen for every two points in the domain of $f$ in order to define $f$ convex.\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.6]{figures/2/chapter2-formal_convex_function.png}\n    \\caption{The definition of the convex function.}\n    \\label{fig:chapter2-formal_convex_function}\n\\end{figure}\n\\par Let us now be a little bit more Einstein and generalise the above convex definition to more than two points.\n\\begin{equation}\n    \\forall x_1,...,x_k, \\forall \\alpha_1,...,\\alpha_k \\in [0,1]\\ s.t.\\ \\sum_{i=1}^k \\alpha_i = 1\\ .\\ f\\Big(\\sum_{i=1}^k \\alpha_i x_i\\Big) \\leq \\sum_{i=1}^k \\alpha_i f(x_i)\n\\end{equation}\n\\par \\textbf{Property}. If a function $f$ is convex, then any level set $S(f,v)$ is convex $\\forall v \\in \\mathbb{R}$. TODO proof.\n\\par Nevertheless, it is not true the reverse. It is not true that if $\\forall v \\in \\mathbb{R}$ level set $S(f,v)$ is convex then $f$ is itself convex. Counterexample? Imagine Bullet-nose curve in some dimension. Yeah, you said: err.. imagine what?? See the figure \\ref{fig:chapter2-sandglass}. Clearly whatever level set has to be convex. But, this is not a convex function.\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.3]{figures/2/chapter2-sandglass.png}\n    \\caption{Bullet-nose curve. Also called sandglass by humans.}\n    \\label{fig:chapter2-sandglass}\n\\end{figure}\n\\par There is also a strict version of the convexity, where the signs $\\leq,\\geq$ are exchanged with their strict alternative, i.e. $<,>$.\n\\par One particularly important version of convexity is \\textbf{strong convexity}. $f$ is said to be strongly convex with modulus $\\tau > 0$ if the following holds:\n\\begin{equation}\n    f(x)-\\frac{\\tau}{2}\\Vert x \\Vert^2\n\\end{equation}\nor in more obvious terms:\n\\begin{equation}\n    \\alpha f(x) + (1-\\alpha) f(y) \\geq f(\\alpha x + (1-\\alpha) y) + \\frac{\\tau}{2} \\alpha(1-\\alpha) \\Vert x-y \\Vert^2\n\\end{equation}\nThis basically means that the functions is bellow quadratically much. In other words, given a point $x$ our function $f$ in that point is steeper than the quadratic model in that point.\n\\par Convex functions cannot be unbounded bellow. The only case of a convex function that is unbounded below is the linear case, in any dimension.\n\\par Last but not least, $f$ is called concave if $-f$ is convex. Clearly, we have also strictly and strongly concave functions.\n%\n\\subsection{Prototypical convex functions}\n\\par As for the convex sets, we have some prototypical functions that are simple and we know that are convex. These, and many other, functions can be composed to get more complicated convex functions.\n\\par Let us illustrate some of the simplest convex functions:\n\\begin{itemize}\n    \\item $f(x) = wx$, i.e. the linear object. This is the only case that is both convex and concave.\n    \\item $f(x) = \\frac{1}{2}x^T Q x + qx$ quadratic function, convex if and only if the Hessian matrix is positive semidefinite.\n    \\item $f(x) = e^{\\alpha x}, \\forall \\alpha \\in \\mathbb{R}, x \\in \\mathbb{R}^n$ the exponential function.\n    \\item $f(x) = - \\log(x), x > 0$ the complement logarithm function.\n    \\item $f(x) = x^\\alpha, \\forall \\alpha \\in \\mathbb{R} \\setminus (0,1), x \\in \\mathbb{R}^n$ the power function.\n    \\item $f(x) = \\Vert x \\Vert_p, p \\geq 1$ the norm function.\n    \\item $f(x) = \\max\\{x_1,...,x_n\\}$ the maximum function.\n    \\item For any convex set $C$, its indicator function is convex:\n    \\begin{equation}\n        I_C(x) = \\begin{cases} 0, & \\mbox{if } x \\in C \\\\ +\\infty, & \\mbox{if } x \\notin C \\end{cases}\n    \\end{equation}\n    The indicator function simply maps to 0 all the elements that belong to the set and to +$\\infty$ those that don't. Since the underlying set is convex, it is obvious that the mathematical object that we obtain when we apply the indicator function transformation is indeed convex.\n\\end{itemize}\n\\par \\textbf{Exercise}. Prove that the above functions are convex.\n\\par \\textbf{Exercise}. Is the function $f(x) = \\min\\{x_1,...,x_n\\}$ convex?\n\\subsection{Functional operations that preserve convexity}\n\\par Let us now show some of the composition operators that can be used over convex functions in order to get other, more complex, convex functions. There are basically two ways of checking if a given function $f$ is convex. Either we compute the Hessian and then verify that it is positive semidefinite everywhere on the function domain, or we try to get $f$ as composition of some basic convex functions using the some operators that preserve convexity. Some of these operators are:\n\\begin{itemize}\n    \\item Given $f$ and $g$ convex, $\\alpha, \\beta \\in \\mathbb{R}_+$, then the linear non negative combination $\\alpha f + \\beta g$ is also convex.\n    \\item Given a set of infinitely many convex functions $\\{f_i\\}_{i \\in I}$, the function $f(x) = \\sup_{i \\in I} f_i(x)$ is convex.\n    \\item Given a convex function $f$, then the linear precomposition $f(Ax+b)$ is also convex.\n    \\item Given a convex multivariable function $f : \\mathbb{R}^n \\rightarrow \\mathbb{R}$ and a convex increasing function $g : \\mathbb{R} \\rightarrow \\mathbb{R}$, the composition $g \\circ f = g(f(x))$ is a convex function.\n    \\item FINISH THE REMAINING\n\\end{itemize}\n\\par \\textbf{Exercise}. Prove that the above composition operators preserve the convexity.\n%\n\\subsection{First order conditions over convex functions}\n\\par The question is: why the heck we like the convex functions so much? Are they that pretty? Yes. They are like Sweden girls.\n\\par Given a function $f$ that is convex, then its gradient exists almost everywhere. Let us prove the following property:\n\\begin{equation}\n    f \\in C^1 \\mbox{convex over convex set C} \\iff f(y) \\geq f(x) + (y-x)\\nabla f(x), \\forall x,y \\in C\n    \\label{eq:chapter2-first_order_convex}\n\\end{equation}\nIn other words, the linear model of our function $f$ tangent in the point $x$ is always under the function in whatever other point $y$ (see figure \\ref{fig:chapter2-first_order_convex}).\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}{0.31\\textwidth}\n    \\includegraphics[width=\\linewidth]{figures/2/first-order-convex/1.png}\n    \\caption{Suppose you have a convex function} \\label{fig:foc1}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n    \\includegraphics[width=\\linewidth]{figures/2/first-order-convex/2.png}\n    \\caption{Take a point $x$} \\label{fig:foc2}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n    \\includegraphics[width=\\linewidth]{figures/2/first-order-convex/3.png}\n    \\caption{Project on $f$ and take its value} \\label{fig:foc3}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n    \\includegraphics[width=\\linewidth]{figures/2/first-order-convex/4.png}\n    \\caption{Build the linear model in point $x$. Call it $L_x$} \\label{fig:foc4}\n    \\end{subfigure}\n    \\hspace*{\\fill} % separation between the subfigures\n    \\begin{subfigure}{0.31\\textwidth}\n    \\includegraphics[width=\\linewidth]{figures/2/first-order-convex/5.png}\n    \\caption{The epigraph of $L_x$} \\label{fig:foc5}\n    \\end{subfigure}\n    \\hspace*{\\fill} % separation between the subfigures\n    \\begin{subfigure}{0.31\\textwidth}\n    \\includegraphics[width=\\linewidth]{figures/2/first-order-convex/6.png}\n    \\caption{The epigraph of $f$, subset of the epigraph of $L_x$} \\label{fig:foc6}\n    \\end{subfigure}\n    \\caption{Visual explanation of the equation \\ref{eq:chapter2-first_order_convex}.}\n    \\label{fig:chapter2-first_order_convex}\n\\end{figure}\n\\par What happens when we have the gradient 0? That is, what happens if we are in a stationary point? Well, the following happens (see figure \\ref{fig:chapter2-first_order_convex_stationary}):\n\\begin{equation}\n    \\nabla f(x) = 0 \\Rightarrow f(y) \\geq f(x), \\forall y \\in \\mathbb{R}^n\n    \\label{eq:chapter2-first_order_convex_stationary}\n\\end{equation}\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}{0.31\\textwidth}\n    \\includegraphics[width=\\linewidth]{figures/2/first-order-convex/7.png}\n    \\caption{Point $x$ is a stationary point} \\label{fig:foc7}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n    \\includegraphics[width=\\linewidth]{figures/2/first-order-convex/8.png}\n    \\caption{$\\nabla f(x) = 0$} \\label{fig:foc8}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n    \\includegraphics[width=\\linewidth]{figures/2/first-order-convex/9.png}\n    \\caption{Epigraph of $L_x$} \\label{fig:foc9}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n    \\includegraphics[width=\\linewidth]{figures/2/first-order-convex/91.png}\n    \\caption{Epigraph of $f(x)$} \\label{fig:foc91}\n    \\end{subfigure}\n    \\caption{Visual explanation of the equation \\ref{eq:chapter2-first_order_convex_stationary}.}\n    \\label{fig:chapter2-first_order_convex_stationary}\n\\end{figure}\n\\par What?! Yes, exactly! If we are in a stationary point $x$, pick any other $y$ from the function domain, the value of $f$ in $y$ will be $\\geq$ than the value in the point $x$. Wait, but that means that...? Yes! That means that $x$ is the global minimum solution and that $f(x)$ is the global minimum value. That's!, why the heck we like the convex functions!\n\\begin{theorem}\n    Given $f$ convex and continuous, then if $x$ is a stationary point of $f$ then $x$ is the global minimum.\n\\end{theorem}\n%\n\\subsection{Second order conditions over convex functions}\n\\par We said that proving that the function is convex entirely on its domain requires computing its Hessian. In order to be able to do that we need the function to be continuously differentiable, that is it needs to have continuous first derivative. Usually, this is the simplest way to check convexity of a function.\n\\begin{theorem}\n    A function $f \\in C^2$, i.e. continuously differentiable, is convex over an open domain $S$ if and only if its Hessian is positive semidefinite, in formulae:\n    \\begin{equation}\n        f \\mbox{ is convex} \\iff \\nabla^2 f(x) \\succeq 0\n    \\end{equation}\n\\end{theorem}\n\\par TODO add exercises from the slide\n%\n\\subsection{Subgradients and subdifferentiales}\n\\par Convexity is nice. But we spoke only about differentiable stuff, otherwise no gradient and no Hessian. Do we really need differentiability? Well, no. With convex functions we can even non differentiable things. But it get complicated.\n\\par As a side note, consider the function $f$ and the set over which is defined to be convex. We could actually define the minimisation problem in the following way:\n\\begin{equation}\n    (P) \\equiv \\inf\\{f_X(x) = f(x) + I_X(x) : x \\in \\mathbb{R}^n\\}\n\\end{equation}\nWhere $I_X(x)$ is the indicator function, which is non differential by design. $f_X$ is called \\textbf{essential objective}. Now look at this magic:\n\\begin{equation}\n    x_* \\mbox{ is a global optimum} \\iff x_* \\mbox{ is local minimum for } f_X\n\\end{equation}\n\\begin{proof}\n    By contradiction. Assume $\\exists y \\in \\mathbb{R}^n : f(y) < f(x_*)$. Then:\n    \\[\n        f(x_*) \\leq f(\\alpha x_* + (1-\\alpha) y) \\leq \\alpha f(x_*) + (1 - \\alpha) f(y) < f(x_*)\n    \\]\n    Which is a contradiction.\n\\end{proof}\n\\par Cool. But the question is still: how do I identify the local minimum without the gradient $\\nabla f(x)$? We don't have the gradient. We need something that is similar to the gradient but not the gradient :). What was the main property of the gradient when we looked at first order conditions? The epigraph. Consider again something like in figure \\ref{fig:chapter2-foc9}. The important thing was that the epigraph of the linear model was under the epigraph of the actual function it was approximating in the stationary point. In other point, it is not important that it is the gradient but that it is completely under the function.\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.4]{figures/2/first-order-convex/9.png}\n    \\caption{Caption}\n    \\label{fig:chapter2-foc9}\n\\end{figure}\n\\par So what is the subgradient $s$ of $f$, the country cousin of the gradient $\\nabla$:\n\\begin{equation}\n    s \\mbox{ is the subgradient of } f \\mbox{ in } x \\iff f(y) \\geq f(x) + s(y-x), \\forall y \\in \\mathbb{R}^n\n    \\label{eq:subgradient}\n\\end{equation}\n\\par Consider the function in figure \\ref{fig:sub_diffs1}. As you can see, there are some kinks. One of the kinks is also our nice global minimum (figure \\ref{fig:sub_diffs2}). In those kinks there are infinitely many linear models that satisfy the equation \\ref{eq:subgradient} (see figure \\ref{fig:sub_diffs3}). And that is fine. Because in that point we can have a (sub)gradient that is 0.\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[scale=0.4]{figures/2/sub-diffs/sub_diffs1.png}\n        \\caption{Caption}\n        \\label{fig:sub_diffs1}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[scale=0.4]{figures/2/sub-diffs/sub_diffs2.png}\n        \\caption{Caption}\n        \\label{fig:sub_diffs2}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[scale=0.4]{figures/2/sub-diffs/sub_diffs3.png}\n        \\caption{Caption}\n        \\label{fig:sub_diffs3}\n    \\end{subfigure}\n\\end{figure}\n\\par What is the problem? The problem is that in the point that is actually a stationary point, and so the gradient is 0, and so it is a local minimum, and so due to the convexity it is also a global minimum; there are infinitely many subgradients. A sub set of these tell you go on the right to find the minimum, another set tells you go on the left, and a singleton set tells you that you are at the right place. Solutions? Keep a set of subgradients.\n\\par Let us now define the \\textbf{subdifferential}:\n\\begin{equation}\n    \\partial f(x) = \\{s \\in \\mathbb{R}^n : s \\mbox{ is a subgradient at } x\\}\n\\end{equation}\n\\par Clearly, if $f$ is differentiable in $x$ then it must be the case that the subdifferential is a singleton set containing just the regular gradient.\n\\par You remember that the gradient characterise all the directional derivatives in a point $x$ (scalar product). If you want to know if a direction is a descent direction, you just need to compute the scalar product with the directional derivative and the gradient. It turns out that with subgradient it is a bit more complicated. Taking just one gradient does not tells you the whole story. If you want to be sure that you are going in the descent direction, you need to have a subdifferential full of directions that in scalar product with the gradient give a negative value.\n\\par The steepest descent direction for such non differentiable functions in a point of a kink, the computation requires solving an optimisation problem:\n\\begin{equation}\n    s_* = - \\mbox{argmin}\\{\\Vert s \\Vert : s \\in \\partial f(x)\\}\n\\end{equation}\nNote that the set over which this problem is operating, i.e. subdifferential, is closed and convex. Thus it is again a convex optimisation. Note also that if the solution is 0, it means that we are in the global minimum.\n\\par Let us now consider the following example. In figure \\ref{fig:sub_example1} you can see the level sets of the multivariable function:\n\\begin{equation}\n    f(x,y) = \\max\\{x^2 + (y-1)^2, x^2 + (y+1)^2\\}\n\\end{equation}\nThis function is convex, non differentiable, and the minimum value is located in the point $x_* = [0,0]$.\n\\par In the differentiable case the things are easy (figure \\ref{fig:sub_example2}), we have our nice gradient that is normal (orthogonal) to the level sets and the opposite of it goes straight to the minimum (figure \\ref{fig:sub_example3}), the steepest descent direction. Actually, whatever direction that is opposite to the gradient is a descent direction (figure \\ref{fig:sub_example4}).\n\\par This does not occur in the non differentiable points. Suppose you are in the point shown on figure \\ref{fig:sub_example5}. In that case, we have infinitely many subgradients. In particular, there are two directions (one is shown in figure \\ref{fig:sub_example6}), that are not even pointing in the direction of the descent (they are pointing out of the level set). In other words, in those two directions the function is increasing. Nevertheless, the two direction form a closed and convex set that you can see in figure \\ref{fig:sub_example7}. Each of the direction in that set is obtainable from the convex combination of these two extreme directions. The point is that each of these directions points inside the level set (figure \\ref{fig:sub_example8}) and the one with the smallest norm is actually the steepest descent direction (figure \\ref{fig:sub_example9}).\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[scale=0.35]{figures/2/sub-example/sub_example1.png}\n        \\caption{Caption}\n        \\label{fig:sub_example1}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[scale=0.35]{figures/2/sub-example/sub_example2.png}\n        \\caption{Caption}\n        \\label{fig:sub_example2}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[scale=0.35]{figures/2/sub-example/sub_example3.png}\n        \\caption{Caption}\n        \\label{fig:sub_example3}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[scale=0.35]{figures/2/sub-example/sub_example4.png}\n        \\caption{Caption}\n        \\label{fig:sub_example4}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[scale=0.35]{figures/2/sub-example/sub_example5.png}\n        \\caption{Caption}\n        \\label{fig:sub_example5}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[scale=0.35]{figures/2/sub-example/sub_example6.png}\n        \\caption{Caption}\n        \\label{fig:sub_example6}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[scale=0.35]{figures/2/sub-example/sub_example7.png}\n        \\caption{Caption}\n        \\label{fig:sub_example7}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[scale=0.35]{figures/2/sub-example/sub_example8.png}\n        \\caption{Caption}\n        \\label{fig:sub_example8}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[scale=0.35]{figures/2/sub-example/sub_example9.png}\n        \\caption{Caption}\n        \\label{fig:sub_example9}\n    \\end{subfigure}\n\\end{figure}\n%\n\\subsection{Subdifferential calculus}\n\\par Like in the case of convex sets and convex functions composition operators that preserve convexity, we have similarly the composition operations over subdifferentials that preserve subdifferentiability.\n\\par Let us now illustrate some of these composition operators:\n\\begin{itemize}\n    \\item TODO\n\\end{itemize}\n%\n\\subsection{Approximate subgradients}\n\\par TODO\n%\n%\n%\n\\section{Descent Methods}\n\\par Let us now ask our self a very basic question: what is so special with the gradient? Can we use something different? The answer is yes. The only thing that we really care about is to go in a \\textit{descent} direction. The crucial arguments in our previous proofs about convergence was that the derivative was promising a significant descent along the direction $d = -\\nabla f(x)$. But what if our direction is, let's say, rotated 45 degrees? We would still go in a descent direction. So we would expect the various proofs to carry on even in these cases, provided that the angle with the opposite of the gradient and the descent direction is not too big.\n\\par Let us now define mathematically a descent direction. A \\textbf{descent direction} is a direction $d$ such that:\n\\begin{equation}\n    d = \\frac{\\partial f}{\\partial d^i}(x^i) \\equiv d \\cdot \\nabla f(x) < 0 \\equiv \\cos (\\theta^i) \\geq 0\n\\end{equation}\nThis means that the direction $d$ points roughly in the same direction of $-\\nabla f(x^i)$.\n\\par There are infinitely many descent direction of course. The whole half space of descent directions. There is a nice result called \\textit{Zoutendijk condition} that states the following:\n\\begin{theorem}\n    Suppose we have a bounded function whose gradient is Lipschitz continuous. Then under Armijo and strong Wolfe we have that:\n    \\begin{equation}\n        \\sum_{i=1}^\\infty \\cos^2(\\theta^i)\\Vert \\nabla f(x^i) \\Vert^2 < \\infty\n    \\end{equation}\n\\end{theorem}\nBasically, this means that provided that the angle $\\theta^i$ between $-\\nabla f(x^i)$ and $d^i$ is not too big, our sequence is converging to the minimum, i.e. $\\nabla f(x)$ converges to 0. Think of the sequence that instead of moving straight to the minimum (when $d^i = -\\nabla f(x^i)$), it circulate around in a spiral manner, until it reaches the minimum (centre). This happens provided that the angle is not too big. Actually Zoutendijk says that the sequence converges also in case $\\theta^i$ converges to 90 degrees with the gradient ($\\cos (\\theta^i)$ converges to 0) provided that it does not converge too fast.\n\\par Note that if $\\cos^2(\\theta^i) = 1$ the formula above is the usual gradient method.\n\\par Note also that usually a non negative sequence has to converge to 0 quite fast in order for the summation to be convergent. Here, on the contrary, we require the sequence to not converge to 0 that fast, in order to have the overall summation convergent.\n%\n%\n%\n\\section{Newton Method}\n\\par Let us now talk about one of the most important methods for unconstrained optimisation, the \\textbf{Newton method}. You want a better direction? Use a better model. So instead of using just linear approximation, use the quadratic one.\n\\par Let us assume that the Hessian is positive definite:\n\\begin{equation}\n    \\nabla^2 f(x) \\succ 0\n\\end{equation}\nSo our second order model becomes:\n\\begin{equation}\n    f(x^i) + \\nabla f(x^i) (x - x^i) + \\frac{1}{2} \\nabla^2 f(x^i) (x - x^i)\n\\end{equation}\nA side note: it is easy to say ``let us use the Hessian''. But suppose you have a function of thousands of variables. Since Hessian is a square matrix, its dimensions are order of millions. Those are huge matrices to deal with.\n\\par The Newton direction $d^i$ is defined as:\n\\begin{equation}\n    d^i = - [\\nabla^2 f(x^i)]^{-1} \\nabla f(x^i)\n\\end{equation}\nRemember that in order to Newton to work, the quadratic model has to have a minimum. This basically means that the Hessian needs to be positive semi definite. But since in the direction computation we also need it invertible (non singular) we must require that the matrix is positive definite.\n\\par Consider the following nonlinear equation interpretation of Newton method. What we want to do is to solve the nonlinear set of equations of the form $\\nabla f(x) = 0$. What we can do is to ``linearise'' this nonlinear system by applying Taylor to the gradient:\n\\begin{equation}\n    \\nabla f(x) \\approx \\nabla f(x^i) + \\nabla^2 f(x^i) (x - x^i)\n\\end{equation}\nSince we are looking for $\\nabla f(x) = 0$ the model becomes:\n\\begin{equation}\n    (x - x^i) \\approx - [\\nabla^2 f(x^i]^{-1} \\nabla f(x) \n\\end{equation}\nAnd what is $x - x^i$? It is the direction from the point $x^i$ to the point $x$, in other words it is the direction $d$.\n\\par We have seen a proof that Newton method converges quadratically in a ball around local optimum. It is not surprising that the very same proof holds also for this more general case:\n\\begin{align}\n    &f \\in C^3 \\wedge x^* \\mbox{ is a stationary point } \\wedge \\nabla^2 f(x^*) \\succ 0 \\Rightarrow\\\\\n    &\\exists \\mathcal{B}(x^*,r) : x^0 \\in \\mathcal{B}(x^*, r) \\Rightarrow \\{x^i\\} \\rightarrow x^* \\mbox{ quadratically}\n\\end{align}\nIn a more human language: if we have a function with continuous third derivative, a point $x^*$ that is a stationary point on that function, and the Hessian is positive definite, then if we start in a point within a ball around the local optimum, then the converging sequence will converge at quadratic rate. Moreover, we also know that in that ball we can use the maximum step size of 1.\n\\par But what if we don't start in the ball around the local optimum? Line search. This is why we have studied techniques like backtracking. We start with the step size of 1 and if it does not work, then we backtrack and we redo with the line search.\n\\par Let us now interpret Newton method from another point of view. The gradient method is a good method if the Hessian is well conditioned, meaning that the largest and smallest eigenvalue are close together. Newton method is nothing else than the gradient method in a different space. What you actually do is to treat Hessian as space transformer. Wait, what?\n\\par Remember that the matrices map vectors to other vectors. So $y = Ax$ means that the $x$ vector is mapped to $y$ through $A$. Nice. What is our direction? $d = - [\\nabla^2 f(x)] \\nabla f(x)$ the gradient in $x$ is mapped to $-d$ through the Hessian in $x$. Let us develop this mathematically.\n\\par Suppose we define the matrix $R = Q^{\\frac{1}{2}}$. The matrix $Q$ is our Hessian and we suppose that it is $Q \\succeq 0$. This means that we can write our $Q$ as $Q = RR$. Cool. Are we sure that $R$ exists? Yeah man! Remember the eigenvalue decomposition:\n\\begin{equation}\n    Q = H \\Lambda H^T\n\\end{equation}\nSince $Q \\succeq 0$, no eigenvalue is negative, so we can take the square roots:\n\\begin{equation}\n    R = H \\sqrt{\\Lambda} H^T\n\\end{equation}\nWe can now check what is $RR$:\n\\begin{equation}\n    RR = H \\sqrt{\\Lambda} H^T H \\sqrt{\\Lambda} H^T = H \\sqrt{\\Lambda} I \\sqrt{\\Lambda} H^T = H \\Lambda H^T = Q\n\\end{equation}\nSince $H$ is a unitary matrix ($H H^T = I$).\n\\par So let us consider a quadratic problem:\n\\begin{equation}\n    f(x) = \\frac{1}{2} x^T Q x + q x\n\\end{equation}\nthe gradient is:\n\\begin{equation}\n    \\nabla f(x) = Q x + q\n\\end{equation}\nand our cool Newton direction is:\n\\begin{equation}\n    d = - [\\nabla^2 f(x)]^{-1} \\nabla f(x) = - [Q]^{-1} (Q x + q) = - Q^{-1} Q x - Q^{-1} q = - Q^{-1}q\n\\end{equation}\n\\par What happens now if we use $R$ to project all the vectors into another space?\n\\begin{equation}\n    y = R x\n\\end{equation}\nWe get a function in another variable, i.e. $y$. Let's see how it looks:\n\\begin{align}\n    f(y) &= \\frac{1}{2} (R^{-1}y)^T Q (R^{-1}y) + q (R^{-1}y) =\\\\\n    &=\\frac{1}{2} y^T (R^{-1})^T Q R^{-1} y + q R^{-1} y =\\\\\n    &=\\frac{1}{2} y^T I y + q R^{-1} y\n\\end{align}\nwhose gradient is:\n\\begin{equation}\n    \\nabla f(y) = I y + q R^{-1}\n\\end{equation}\nand whose Hessian is $I$. The largest and smallest eigenvalue are the same. Basically, the gradient method here along a direction $d$ finishes in one iteration. Well, for the quadratic functions :). But it also works pretty well in case of non quadratic functions.\n\\par What is the direction? Let's see:\n\\begin{equation}\n    d = - [I]^{-1} \\nabla f(y) = - \\nabla f(y) = - q R^{-1}\n\\end{equation}\nWhat is this direction in the original space? Exactly the Newton direction.\n\\par Geometrically, given a function in the original space, the level sets may be quite elongated. Thus, the gradient method performs quite poor. Then we apply an intelligent trick: we use the Hessian to change the space where the level set of the functions are quite round. In this way, the gradient method performs extremely well. And that's what we do.\n\\par So in the end, Newton method means space transformation plus gradient method.\n%\n\\subsection{Apropos convergence}\n\\par What about the convergence of this method? We have the global convergence provided that the angle is not to close to 0. There are some technicalities that need to be true, such as that the gradient needs to be Lipschitz, so that the Hessian is strictly positive definite and bounded:\n\\begin{equation}\n    u I \\preceq \\nabla^2 f \\preceq L I\n\\end{equation}\nIn order to be convergent, we need to prove that the angle does not go to 0. What follows from the Hessian being positive definite is that:\n\\begin{align}\n    \\nabla^2 f(x^i) d^i &= - \\nabla f(x^i) \\label{eq:chapter2-newton_convergence_internal1}\\\\\n    & \\Rightarrow\\\\\n    \\mbox{(multiply both s}&\\mbox{ides with $-(d^i)^T$)}\\\\\n    - (d^i)^T \\nabla^2 f(x^i) d^i &= (d^i)^T \\nabla f(x^i)\n\\end{align}\nNow from Poloni world, we know that:\n\\begin{equation}\n    \\lambda^n \\Vert d \\Vert^2 \\leq d^T M d \\leq \\lambda^1 \\Vert d \\Vert^2\n\\end{equation}\nSo we have that the previous equality is:\n\\begin{equation}\n    - (d^i)^T \\nabla^2 f(x^i) d^i = (d^i)^T \\nabla f(x^i) \\leq - \\lambda^n \\Vert d^i \\Vert^2\n\\end{equation}\nLet us not apply norm operator to both sides of the equation \\ref{eq:chapter2-newton_convergence_internal1}. We get the following:\n\\begin{equation}\n    \\Vert \\nabla^2 f(x^i) d^i \\Vert = \\Vert \\nabla f(x^i) \\Vert\n\\end{equation}\nBy Cauchy Schwarz inequality we have:\n\\begin{equation}\n    \\Vert \\nabla f(x^i) \\Vert = \\Vert \\nabla^2 f(x^i) d^i \\Vert \\leq \\Vert \\nabla^2 f(x^i) \\Vert \\Vert d^i \\Vert \\leq \\lambda^1 \\Vert d^i \\Vert\n\\end{equation}\nFrom the scalar product between Newton direction and the gradient we get the following:\n\\begin{align}\n    \\cos (\\theta^i) &= \\frac{d^i \\cdot \\nabla f(x^i)}{\\Vert d^i \\Vert \\Vert \\nabla f(x^i) \\Vert} = \\frac{-\\nabla f(x^i)^T [\\nabla^2 f(x^i)]^{-1} \\nabla f(x^i)}{\\Vert d^i \\Vert \\Vert \\nabla f(x^i) \\Vert} \\leq\\\\\n    &\\leq \\frac{-\\lambda^n \\Vert d \\Vert^2}{\\Vert d^i \\Vert \\Vert \\nabla f(x^i) \\Vert} = -\\frac{1}{\\Vert \\nabla f(x^i) \\Vert} \\lambda^n \\Vert d^i \\Vert \\leq - \\frac{\\lambda^n \\Vert d^i \\Vert}{\\lambda^1 \\Vert d^i \\Vert} =\\\\\n    &= - \\frac{\\lambda^n}{\\lambda^1} \\leq - \\frac{u}{L}\n\\end{align}\nThus, since both eigenvalues and the pair $(u,L)$ are all positive numbers, we have proven that the angle stays always below $\\frac{u}{L}$, and so away from 0. Thus, we have the global convergence.\n\\par So now we know that our Newton method converges but we don't know how fast. We will not prove it but the Newton method has a superlinear convergence except from when we enter into the ball around the local optimum where the convergence gets quadratic.\n\\par Now, all of this seems to work only for convex functions. Except it does not :). It also work with non convex functions. Why, how? Look at the previous mathematics, we have used Hessian everywhere but what really matters is that the matrix is positive definite. So as long as you can provide a matrix $H$ that satisfies:\n\\begin{equation}\n    u I \\preceq H  \\preceq L I\n\\end{equation}\nwe can proceed with the very same mathematics that we have employed with the Hessian. So the descent method does not depend on the fact that we have used the Hessian but only that we have used a positive definite matrix with the bounded eigenvalues.\n\\par But given a non convex function, its Hessian will obviously not be positive definite, not either positive semi definite. It will probably be indefinite. So what matrix can we use? Well let's hack its whatever definite Hessian into a positive definite. How? Take the Hessian of the function, take its minimum eigenvalue $\\lambda^n$ (which will be $\\leq 0$. otherwise the matrix would be positive definite), take an $\\epsilon > - \\lambda^n$. Consequently, take $H^i = \\nabla^2 f(x^i) + \\epsilon^i I$ as the positive definite matrix to use in Newton method. This hack actually has a name and it is called \\textbf{Hessian modification}. But beware! The larger is $\\epsilon$ the more $H^i$ will be different from the true Hessian and thus you are getting far from real things. But the more $\\epsilon$ is near to $- \\lambda^n$ the more you get numerical issues of machine precision stuff. Moreover, there are some algorithmic issues.\n\\par Usually what we do is to set $\\epsilon = \\max\\{0, \\delta - \\lambda^n\\}$ for some $\\delta$. In this way when, hopefully, we are close to the local optimum, the Hessian will be positive definite. In such case, $\\lambda^n > 0$ thus the quantity $\\delta - \\lambda^n > 0$, and so we do not change the Hessian. This will allow the Newton method to run quadratically in the ball around the optimum solution. If on the other hand the minimum eigenvalue is negative, then $\\delta + \\lambda^n > 0$ and so we will perturb slightly the original Hessian. The problem still remains: how much is $\\delta$?\n\\par Note that what we are trying to do here is to solve a constrained problem that is quite frequent in linear algebra and optimisation. The problem is:\n\\begin{equation}\n    \\min \\{\\Vert H - \\nabla^2 f(x^i) \\Vert\\ : H \\succeq \\delta I\\}\n\\end{equation}\nthat is: find the closest matrix to the Hessian that is at least positive definite as the matrix $\\delta I$.\n\\par The problem with Newton method is clear. At each point I need to have a Hessian, or a modification of the Hessian, which means that I have to compute it! Moreover, and probably even worse news, we need to invert it. This takes $\\mathcal{O}(n^3)$. Newton is okay for problems with hundred or even thousands of variables. But take a problem with millions of variables and you will kill Newton instantly. Suggestions for better stuff? Continue to read...\n%\n%\n%\n\\section{Quasi-Newton methods}\n\\par We have already said that if we are able to provide the positive definite matrix instead of the Hessian we can get the superlinear convergence and quadratic in the proximity of the optimal value. Let us then forget about the Hessian. So let us compute a matrix $H$ that is near the Hessian and we want to compute it without ever touching the Hessian itself. We want to compute an approximation of the Hessian using only the gradients. The Hessian is the derivative of the gradient. So one approximation of the Hessian could be that once we have a gradient in a point, we move a little bit, take the gradient in that point, make the difference, divide by the step and that is an approximation of the Hessian. You can always approximate the derivative if you know the function. In this case the function is the derivative and we are approximating its derivative, i.e. the Hessian. But we want to do something more clever.\n\\par Suppose we have the following model:\n\\begin{align}\n    m^i(x) &= \\nabla f(x^i) (x - x^i) + \\frac{1}{2} (x - x^i)^T H^i (x - x^i)\\\\\n    x^{i+1} &= x^i + \\alpha^i d^i\n\\end{align}\nNow, suppose we have computed $\\nabla f(x^{x+1})$. We want to update the model in the following manner:\n\\begin{align}\n    m^{i+1}(x) &= \\nabla f(x^{i+1}) (x - x^{i+1}) + \\frac{1}{2} (x - x^{i+1})^T H^{i+1} (x - x^{i+1})\\\\\n    x^{i+2} &= x^{i+1} + \\alpha^{i+1} d^{i+1}\n\\end{align}\nHow can we choose $H^{i+1}$? Let us reason about what we properties we want our matrix to have:\n\\begin{itemize}\n    \\item We want the matrix $H^{i+1}$ to be positive definite because we need it to solve the system.\n    \\item We want that in the new model the gradient in the previous point is exactly the true gradient of the function, i.e.:\n    \\begin{equation}\n        \\nabla m^{i+1}(x^i) = \\nabla f (x^i)\n    \\end{equation}\n    This is also called Secant equation since it can be also written as:\n    \\begin{equation}\n        H^{i+1} (x^{i+1} - x^i) = \\nabla f(x^{i+1}) - \\nabla f(x^i)\n    \\end{equation}\n    \\item We want that the two consecutive Hessians are not that different, i.e. $\\Vert H^{i+1} - H^i \\Vert$ is ``small''.\n\\end{itemize}\nHow if we want to develop something like this, it is useful to work in the space of movements. Let us define some quantities:\n\\begin{align}\n    &s^i = x^{i+1} - x^i = \\alpha^i d^i\\\\\n    &y^i = \\nabla f(x^{i+1}) - \\nabla f(x^i)\n\\end{align}\nFrom these two, our secant equation becomes:\n\\begin{equation}\n    (S)\\ H^{i+1} s^i = y^i\n\\end{equation}\nLet us now multiply both sides by $(s^i)^T$, and employ the first property that we want $H^{i+1}$ to have:\n\\begin{equation}\n    (C)\\ (s^i)^T H^{i+1} s^i = (s^i)^T y^i = \\Vert s^i \\Vert^2 > 0\n    \\label{eq:chapter3-secant_equation}\n\\end{equation}\nNote that once that we do a step, $s^i$ and $y^i$ are fixed and they are not something that we can choose. But in order to have solvable the secant equation, you need to assure that the scalar product from equation \\ref{eq:chapter3-secant_equation} is positive. This is because our $H$ is positive definite, and it maps positive (resp. negative) vectors to positive (resp. negative) vectors. The equation \\ref{eq:chapter3-secant_equation} is called \\textbf{curvature condition}.\n\\par If we have chosen the direction $d$ and the step size satisfies the strong Wolfe condition, then the curvature condition holds. Let us prove it:\n\\begin{proof}\n    We want to prove that $(W') \\Rightarrow (C)$. Strong Wolfe means that:\n    \\begin{align}\n        &\\phi'(\\alpha^i) = \\nabla f(x^{i+1}) d^i \\geq m_3 \\phi'(0) = m_3 \\nabla f(x^i) d^i\\\\\n        &\\Rightarrow \\mbox{ subtract on both sides $\\nabla f(x^i) d^i$}\\\\\n        &\\nabla f(x^{i+1}) d^i - \\nabla f(x^i) d^i \\geq m_3 \\nabla f(x^i) d^i - \\nabla f(x^i) d^i\\\\\n        &\\iff\\\\\n        &(\\nabla f(x^{i+1}) - \\nabla f(x^i)) d^i \\geq (m_3 - 1) \\nabla f(x^i) d^i = (m_3 - 1)\\phi'(0) > 0\\\\\n        &\\iff\\\\\n        &y^i d^i \\geq (m_3 - 1) \\phi'(0) > 0\n    \\end{align}\n\\end{proof}\nSo everything holds if you do the step reasonably. And in this case reasonably means that it must respect the strong Wolfe condition.\n\\par There are many matrices that satisfy $(S)$. Infact it is a linear system with $n^2$ unknowns. Clearly due to the third condition, we want to solve the following minimisation constrained problem:\n\\begin{equation}\n    \\min \\{\\Vert H - H^i \\Vert : H s^i = y^i, H \\succeq 0\\}\n\\end{equation}\nThis problem highly depends on the type of the employed norm. Different norms bring different solutions. But if we chose the norm in a good way, reasonable norms, it turns out that there is a closed formula that comes in our help. One of these formulas is \\textbf{DFP formula} due to Davidon-Fletcher-Powell. By setting $\\rho^i = \\frac{1}{y^i s^i}$ which is $> 0$, we have the following formula:\n\\begin{equation}\n    H^{i+1} = (I - \\rho^i y^i (s^i)^T) H^i (I - \\rho^i s^i (y^i)^T) + \\rho^i y^i (y^i)^T\n\\end{equation}\nThis is a clever way to describe what the approximation of the Hessian should be. But there is still one thing. We will still have to invert the matrix $H^{i+1}$ at each step, which is something we don't want to do because we pay $\\mathcal{O}(n^3)$. And here comes the real elegant fact. What we really want is to work with the inverses. So assume we have just computed the inverse of $H^i$, i.e. $(H^i)^{-1}$. What we want to get is $(H^{i+1})^{-1}$. Now, if we look better at our DFP formula from above, we can see that it is a so called \\textit{rank-two correction}. A \\textit{rank-n correction} of a matrix $M$ is the addition to $M$ of a matrix $N$ or rank $n$. In our case $y$ and $s$ form a matrix of rank 1 and in the formula above we add twice a rank 1 matrix, so we get a rank 2 correction.\n\\par Rank two correction of $H^i$ can use the formula called \\textbf{Sherman-Morrison-Woodbury} formula to get the inverse of rank 1 correction:\n\\begin{equation}\n    [A + a b^T]^{-1} = A^{-1} - \\frac{A^{-1} a b^T A^{-1}}{1 - b^T A^{-1} a}\n\\end{equation}\nLet us call $B^{i+1} = (H^{i+1})^{-1}$. Then by injecting SMW formula in DFP from above, we get:\n\\begin{equation}\n    B^{i+1} = B^i + \\rho^i s^i (s^i)^T - \\frac{B^i y^i (y^i)^T B^i}{(y^i)^T B^i y^i}\n\\end{equation}\nIt is the inverse of $H^i$ plus rank one correction, plus another rank one correction. Computing $B^{i+1}$ is $\\mathcal{O}(n^2)$ and solving the Newton system is also $\\mathcal{O}(n^2)$ because the matrix $B^{i+1}$ is already the inverse. You just multiply this matrix with the gradient.\n\\par Another formula instead of DFP is called BFGS due to Broyden-Fletcher-Goldfarb-Shanno. Turns out that if you use BFGS the matrices $B$ that you get along the various iterations are better matrices than those obtained with DFP formula.\n\\par Write $H^{i+1} s^i = y^i$ in terms of $B^{i+1}$:\n\\begin{equation}\n    s^i = B^{i+1} y^i\n\\end{equation}\nSubstitute $H$ with $B$ and $y$ with $s$ and invert everything:\n\\begin{align}\n    H^{i+1} &= H^i + \\rho^i y^i (y^i)^T - \\frac{H^i s^i (s^i)^T H^i}{(s^i)^T H^i s^i}\\\\\n    B^{i+1} &= (I - \\rho^i s^i (y^i)^T) B^i (I - \\rho^i y^i (s^i)^T) + \\rho^i s^i (s^i)^T =\\\\\n    &=B^i + \\rho^i [(1 + \\rho^i (y^i)^T B^i y^i) s^i (s^i)^T - (B^i y^i (s^i)^T + s^i (y^i)^T B^i)]\n\\end{align}\n\\par Actually, people are crazy so they have been making this funny stuff of combining the two approaches. This gives rise to the so called \\textbf{Broyden family}:\n\\begin{equation}\n    \\beta H_{\\text{DFP}}^{i+1} + (1 - \\beta) H_{\\text{BFGS}}^{i+1} : \\succeq \\mbox{ if } \\beta \\in [0,1] \\wedge (S) \\mbox{ is satisfied}\n\\end{equation}\n\\par There is one last thing to say. How do we choose the first matrix? Remember that we don't want to compute the Hessian. So we could do the finite differences method.\n\\par Let us now recap. We started with Newton. It is a good method but computing the Hessian is not cheap. Then we moved to Quasi-Newton methods whose aim is to approximate at best the Hessian. We got $\\mathcal{O}(n^2)$ both in time and space. This is a good achievement. But still, if we deal with problems that have millions of variables, even Quasi-Newton methods won't work. Note that there are plenty of problems with so many variables, especially in ML. So can we do better? Yes.\n%\n%\n%\n\\section{Limited memory BFGS}\n\\par Limited-memory BFGS (L-BFGS or LM-BFGS) is an optimisation algorithm in the family of quasi-Newton methods that approximates the Broyden Fletcher Goldfarb Shanno algorithm (BFGS) using a limited amount of computer memory. It is quite popular algorithm for parameter estimation in machine learning. The algorithm's target problem is to minimise $f(x)$ over unconstrained values of the real-vector $x$  where $f$ is a differentiable scalar function.\n\\par Like the original BFGS, L-BFGS uses an estimate of the inverse Hessian matrix to steer its search through variable space, but where BFGS stores a dense $n \\times n$ approximation to the inverse Hessian ($n$ being the number of variables in the problem), L-BFGS stores only a few vectors that represent the approximation implicitly. Due to its resulting linear memory requirement, the L-BFGS method is particularly well suited for optimisation problems with many variables. Instead of the inverse Hessian $H_k$, L-BFGS maintains a history of the past m updates of the position x and gradient $\\nabla f(x)$, where generally the history size m can be small (often $m < 10$). These updates are used to implicitly do operations requiring the Hessian vector product.\n\\par Memory and time worsen proportionally to the increase of $k$. But the converges improves with the increase of $k$. So the more $k$ is small, the more L-BFGS performs similar to the gradient method. On the contrary, the more it approaches to $n$ the more it resembles the Quasi-Newton method. So a trade off is necessary here.\n%\n%\n%\n\\section{Conjugate Gradient Method}\n\\par Conjugate gradient method is yet another algorithm for dealing with very large scale problems. Conjugate gradient is actually a Krylov method.\n\\par Let us start with quadratic functions. Remember what the gradient does. At each iteration it take a step of size $\\alpha^{i+1}$ in the direction $d^{i+1}$ that is perfectly orthogonal to the previous direction $d^i$. This is because it has already performed the optimal step in that direction. In other words, it optimises in one of $n$ dimensions of the space at each iteration. The problem is that, each time you go orthogonal to the previous direction, you loose all that you have done up until that previous direction. Mathematically speaking $d^{i+1} \\not \\perp d^{i-1}$. So people asked them self, could we construct a chain of direction such that:\n\\begin{equation}\n    d^1 \\perp d^2 \\perp ... \\perp d^i = 0\n\\end{equation}\nActually what we want is to have direction that are conjugate between them when passed through $Q$, $(d^i)^T Q d^{i-1} = 0$.\n\\par To achieve this, we cannot use the old nice gradient as the next direction. We need to modify it slightly so that we can get what we want. Turns out that if we modify the gradient in the following manner, we get what we want:\n\\begin{align}\n    &d^0 = 0\\\\\n    &d^i = \\nabla f(x^i) + \\beta^i d^{i-1}\n\\end{align}\nWe say that the gradient is \\textbf{deflected} using $d^{i-1}$. The ``only'' complicated term in the formula is $\\beta^i$ (a scalar value). Fortunately, for the quadratic functions there is a closed formula:\n\\begin{equation}\n    \\beta^i = \\frac{(\\nabla f(x^i))^T Q d^{i-1}}{(d^{i-1})^T Q d^{i-1}} = \\frac{\\Vert \\nabla f(x^i) \\Vert^2}{\\Vert \\nabla f(x^{i-1}) \\Vert^2}\n\\end{equation}\nAlso for the step size there is a closed formula which is:\n\\begin{equation}\n    \\alpha^i = - \\frac{(\\nabla f(x^i))^T d^i}{(d^i) Q d^i} = \\frac{\\Vert \\nabla f(x^i) \\Vert^2}{(d^i)^T Q d^i}\n\\end{equation}\n\\par In figure \\ref{fig:chapter2-cgm} you can find the algorithm for Conjugate Gradient method. The algorithm starts with the first direction just the opposite of the gradient. In all the other iterations the algorithm computes the deflected gradient and the next point, exploiting the closed formula of both $\\alpha$ and $\\beta$. End of story.\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{figures/2/chapter2-cgm.png}\n    \\caption{Conjugate Gradient method.}\n    \\label{fig:chapter2-cgm}\n\\end{figure}\n\\par A powerful property of this algorithm is that it ends in at most $n$ iterations. This is because at each iteration we are minimising over a subset of $k \\leq n$ dimensions. Actually, the algorithm can even finish in strictly less than $n$ iterations. This has to do with how are the eigenvalues of $Q$ clustered. If the matrix has $t$ eigenvectors that have equal or almost equal eigenvalues, those $t$ vectors will be killed in just one iteration. In other words, we will minimise along all $t$ directions in just one step. So if we have matrices of 10 thousands variables, but only 10 different eigenvalues, then the algorithm will find the optimum in just 10 iterations. This is very powerful property because what we could do is to do some preconditioning on the initial matrix Q. For instance multiply it with some matrix that cluster the eigenvalues together.\n\\par The interesting idea is that all this idea can be used also in case of non linear objective function (see figure \\ref{fig:chapter2-cgm_nl}). The only difference is that we don't have a closed formula for $\\alpha$. No, it is not an error. Look closely at $\\beta$ and you will see that the second expression of $\\beta$ does not have anything to do with $Q$. Unfortunately we can't say the same for $\\alpha$. So we need the saint ways of the line search. This non linear version of Conjugate Gradient with this particular $\\beta$ closed formula is called \\textbf{Fletcher Reeves method}.\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.54]{figures/2/chapter2-cgm_nl.png}\n    \\caption{Conjugate Gradient method for non linear objective function.}\n    \\label{fig:chapter2-cgm_nl}\n\\end{figure}\n\\par There are more ways to compute $\\beta$. And of course each one has its own positive and negative sides. In particular there are some formulas that are identical to the one that we have seen in quadratic case, while very different in the non linear case.\n\\subsection{Convergence and efficiency}\n\\par The convergence of conjugate gradient method is not trivial and it highly depends on $\\beta$. Turns our that for some formulas, it may even not be sufficient to assure Armijo-Wolfe in order to have a descent direction.\n\\par Sometimes it is also suggested to ``restart'' the direction. Meaning that at a certain point, do not employ the deflected gradient, but just take a plain gradient and deflected gradient from the next iteration.\n\\par The convergence of conjugate gradient is rather good. It has an \\textit{$n$ step quadratic} convergence. Meaning that each $n$ steps the convergence is approximately quadratic. If you think about it, conjugate gradient method minimises optimally a quadratic function in $n$ steps.\n%\n%\n%\n\\section{Heavy Ball Gradient}\n\\par It all starts with the following point update:\n\\begin{equation}\n    x^{i+1} = x^i - \\alpha \\nabla f(x^i) + \\beta^i (x^i - x^{i-1})\n\\end{equation}\n\\par This method is called Heavy Ball because it is as if $x_i$ was a heavy ball and the gradient is something like a force that wants to steer it away. But since the ball is heavy, it cannot change immediately the direction to 90 degree but it takes time. This is why $\\beta$ is called momentum.\n\\par This is not a descent algorithm. For this reason no one is guaranteeing that each iteration the function is monotonically decreasing. For this reason, the convergence analysis is quite complicated and we won't go into the details.\n\\par In case of strongly convex function, i.e. $(\\lambda^n = u) I \\preceq \\nabla^2 f(x) \\preceq (\\lambda^1 = L) I$, actually $\\alpha$ and $\\beta$ can be estimated:\n\\begin{align}\n    &\\alpha = \\frac{4}{(\\sqrt{\\lambda^1} + \\sqrt{\\lambda^n})^2}\\\\\n    &\\beta = \\max\\{|1-\\sqrt{\\alpha \\lambda^n}|,|1-\\sqrt{\\alpha \\lambda^1}|\\}^2\n\\end{align}\nWith this choices that we do not prove because it takes a lot of algebra and math, we get the following result:\n\\begin{equation}\n    \\Vert x^{i+1} - x^* \\Vert \\leq (\\frac{\\sqrt{\\lambda^1} - \\sqrt{\\lambda^1}}{\\sqrt{\\lambda^1} + \\sqrt{\\lambda^1}}) \\Vert x^{i} - x^* \\Vert\n\\end{equation}\nNote that in case of the gradient, the two differences in the norm are in the output space, while here we are getting the difference in the input space. This is a stronger result. This is not a surprising result because strongly convex means just one minimum and the level sets are compact, the best possible situation.\n\\par The other important difference with the gradient is that we have the square roots. It may seem not a big deal but, square root of the biggest eigenvalue lowers the value of the difference a lot. This means that the expression is nearer to 1, which translates into better convergence. This is the reason why many use Heavy Ball gradient instead of the simple plain gradient.\n%\n%\n%\n\\section{Accelerated Gradient}\n\\par There is a version of Heavy Ball gradient that is actually better and it is called \\textbf{accelerated gradient} (see figure \\ref{fig:chapter2-ag}). It is only for convex functions. This algorithm is obtained from a sophisticated theoretical analysis so will just go through it very quickly.\n%\n%\n%\n\\section{$< \\nabla$ methods}\n\\par Up until now we have assumed to have the gradient. We can use the gradient method, if we want something faster we can use more than gradient methods. But what if we don't have gradient? What if the function is non differentiable or it is just too difficult to compute the gradient?\n%\n\\subsection{Machine Learning applications}\n\\par Let us first motivate why we need less than gradient methods. One of the direct application is Machine Learning. In machine learning one has a set of inputs $X = [X^i \\subset \\mathcal{X}]_{i \\in I}$ (it is a matrix) for a given $I = \\{1,...,m\\}$ and a corresponding set of outputs $Y = [y_i]_{i \\in I}$ (a vector). Then one usually wants to devise a mapping function $\\Phi : \\mathcal{X} \\rightarrow \\mathcal{F}$ from the space of inputs to the space of features, such that:\n\\begin{equation}\n    \\min \\{\\sum_{i \\in I} L(y^i, \\Phi(X^i) \\cdot w) : w \\in \\mathbb{R}^n\\}\n\\end{equation}\nwhere $L(\\cdot,\\cdot)$ is a \\textbf{loss function}. In other words, one wants to minimise the loss function, that is a function that computes the distance of the observed outputs from the true outputs.\n\\par If the loss function is simply the two norm, it becomes the least squares problem:\n\\begin{equation}\n    D\n\\end{equation}\nNote that in ML one has $m$ observations and $n$ weights and usually $m \\gg n$. So in case of least squares, we are summing a lot of stuff. So what is that people usually do? Usually the inputs are drawn randomly from some distribution and hopefully they are independently distributed. This means that a small subset of the whole set of observation could be as well as representative. So this is what actually people do. Take a small subset, compute the gradient for that small subset and treat it as it was the gradient of the whole function. So two important questions arise now. How do I choose the subset, and how many do I need? This method takes name of \\textbf{stochastic gradient descent} or \\textbf{incremental gradient}.\n\\par Typically, this is not end of story. Convergence may be very hard to achieve. It is for this reason that one usually \\textbf{regularise} the objective function:\n\\begin{equation}\n    \\min \\{\\sum_{i \\in I} L(y^i, \\Phi(X^i) \\cdot w) + \\mu \\Omega(w) : w \\in \\mathbb{R}^n\\}\n\\end{equation}\n$\\mu$ is a hyper parameter to decide empirically, $\\Omega(w)$ is the regulariser, which is usually $\\Omega(w) = \\Vert w \\Vert_1$ called \\textbf{lasso}. Actually, people would like to have 0 norm instead of 1 norm. This is because 0 norm would count how many features are used in the objective function. The problem is that 0 norm is not convex thus it would make the overall problem not convex. So the best convex approximation of the 0 norm is the 1 norm. Unfortunately, 1 norm is not differentiable. This is why of this topic now :).\n%\n\\subsection{Subgradient methods}\n\\par Remember what a subgradients are:\n\\begin{equation}\n    g \\in \\partial f(x) \\equiv f(y) \\geq f(x) + g(y - x), \\forall y \\in \\mathbb{R}^n\n\\end{equation}\nBasically all the functions tangent to the kinks whose epigraph contains entirely the epigraph of the objective function. Each opposite of the subgradient points towards the half space where the optimal solution is located. So going along the direction of one of the opposite of the subgradient should bring us closer to the optimal solution, provided that we do the right step. So the question is: what is the right step?\n\n\n\\section{$> \\nabla$ methods}\n\\par In this section we are going to examine the so called ``more than Gradient methods''. The name comes from the fact that these approaches does not necessarily require to go \\textit{strictly} in the opposite direction of the gradient. As we will see, as long as we are going in a descent direction, we are going well.\n\\par Let us recap briefly what does it mean descent direction and why we selected the opposite of the gradient as the king of such directions. A direction is a descent direction if:\n\\begin{equation}\n    \\langle \\nabla f(x), d \\rangle < 0\n\\end{equation}\nbut what does it mean actually? Remember what is the definition of the scalar product:\n\\begin{equation}\n    \\langle \\nabla f(x), d \\rangle = \\lVert \\nabla f(x) \\rVert \\lVert d \\rVert \\cos (\\theta)\n\\end{equation}\nwhere $\\theta$ is the angle between $d$ and $\\nabla f(x)$. From the moment that both $\\lVert d \\rVert$ and $\\lVert \\nabla f(x) \\rVert$ are positive (a norm is always $\\leq 0$), the only factor that influences the sign of the scalar product is the cosine $\\cos(\\theta)$. Accordingly, if we set gradient to be the direction of the $x$ asix, as long as the direction $d$ is pointing in the same direction of the $x$ asix, the cosine will be positive. The opposite for the negative value. Thus, the maximum negative value is when the angle $\\theta$ is $\\pi$, i.e. $\\cos(\\pi) = -1$, i.i.e. $d = - \\nabla f(x)$.\n\\par Nevertheless, as long as $\\cos(\\theta) < 0$ we are going down. It is just the matter of a factor $\\in [-1,0)$. Provided that the angle is not too far from $\\pi$ (or equivalently too small), we can expect that the methods that we are going to present converge. And indeed they do. There is a general result regarding these kind of methods, we announce it without proving it:\n\\begin{theorem}\n    Suppose we have a non unbounded function $f \\in C^1$ with $\\nabla f$ Lipschitz. Then:\n    \\[\n        (A) \\cap (W') \\Rightarrow \\sum_{i=1}^{\\infty} \\cos^2(\\theta_i) \\lVert \\nabla f(x_i) \\rVert^2 < \\infty\n    \\]\n\\end{theorem}\nThis result basically says that, as long as our angle $\\theta_i$ is bounded away from 0, we will converge. Note that: if an infinite sequence converges then $\\{a_i\\} \\rightarrow 0$, but not conversely, i.e. a converging sequence to 0 does not imply a converging infinite sum. In our case, actually, it is also possible to converge even if $\\cos(\\theta)$ is not bounded away from 0, i.e. $cos(\\theta) \\approx 0$, provided that this does not happen to fast in the series.\n%\n%\n%\n\\subsection{Newton's Method}\n\\par Instead of using just the first order model for $f$, we the second order, i.e. quadratic model. Assume for now that the Hessian is positive definite:\n\\[\n    \\nabla ^ 2 f(x_i) \\succ 0\n\\]\nthen exists the minimum of the second order model:\n\\[\n    f(x_i) + \\nabla f(x_i) (x-x_i) + \\frac{1}{2} (x-x_i)^{T} \\nabla ^ 2 f(x_i) (x-x_i)\n\\]\nWe can then compute the Newton's direction by:\n\\begin{align}\n    & \\nabla f(x) \\approx \\nabla f(x_i) (x-x_i) + \\frac{1}{2} (x-x_i)^{T} \\nabla ^ 2 f(x_i) (x-x_i)\\\\\n    & \\nabla f(x) = 0\\\\\n    & \\nabla f(x_i) (x-x_i) + \\frac{1}{2} (x-x_i)^{T} \\nabla ^ 2 f(x_i) (x-x_i) = 0\\\\\n    & x = x_i - [\\nabla ^ 2 f(x_i)] ^ {-1} \\nabla f(x_i)\n\\end{align}\nThus the direction is given by $- [\\nabla ^ 2 f(x_i)] ^ {-1} \\nabla f(x_i)$ with $\\alpha_i = 1$.\n\\par Thus the Newton's method is just take a unitary step size along the direction $- [\\nabla ^ 2 f(x_i)] ^ {-1} \\nabla f(x_i)$.\n\\par We have seen that Newton converges superlinearly and quadratically in the tail of the convergence:\n\\begin{align*}\n    &f \\in C^3 \\wedge x_{\\star} \\text{ saddle point } \\wedge \\nabla ^ 2 f(x_{\\star}) \\succ 0 \\Rightarrow\\\\\n    &\\exists \\mathcal{B}(x_{\\star}, r) : (x_1 \\in \\mathcal{B}(x_{\\star}, r) \\Rightarrow \\{x_i\\} \\rightarrow x_{\\star} \\text{ quadratically})\n\\end{align*}\nThis means that if the algorithm starts in a ball around the saddle point, it will converge quadratically to the optimum point. The issue is that we cannot know whether or not we are starting in the proximity of the optimal point. Not a big deal: we could try to run Netwon's method and in case we do not get the quadratic convergence we restart by using the standard Armijo-Wolfe line search.\n\\par The function must have a positive definite Hessian since we need to invert it to get the direction. The direction obtained is surely a descent direction as we can verify it by the following:\n\\[\n    d_i \\nabla f(x_i) = - \\nabla f(x_i)^{T} [\\nabla^2 f(x_i)]^{-1} \\nabla f(x_i) < 0\n\\]\nwhere the last inequality follows from the fact that the Hessian is a symmetric positive definite matrix.\n\\par We can interpret Newton's method from another point of view (\\textbf{Space Dilatation}). Suppose Hessian $Q$ is symmetric and positive definite. Then we can find a matrix $R$ such that $Q = R^TR$ and $R = \\sqrt{Q}$. We are sure that such an $R$ exists and that it is symmetric. Thus:\n\\[\n    Q = H \\Lambda H^T \\Rightarrow R = H \\sqrt{\\Lambda} H^T\n\\]\ninfact:\n\\[\n    R^TR = (H \\sqrt{\\Lambda} H^T)^T H \\sqrt{\\Lambda} H^T = H \\sqrt{\\Lambda} H^T H \\sqrt{\\Lambda} H^T = H \\Lambda H^T\n\\]\nSuppose now:\n\\[\n    f(x) = \\frac{1}{2} x^T Q x + q^T x\n\\]\nthe gradient of this function is:\n\\[\n    \\nabla f(x) = Qx + q\n\\]\nand the direction is:\n\\[\n    d = -Q^{-1}q\n\\]\nSince we have $Q = R^TR$, we can rewrite the function as:\n\\[\n    f(x) = \\frac{1}{2} x^T R^TR x + q^Tx\n\\]\nWe then set $y = Rx$ and proceed like:\n\\[\n    f(y) = \\frac{1}{2} y^T I y + q^T R^{-1}y\n\\]\nwith the gradient:\n\\[\n    \\nabla f(y) = y + R^{-1}q\n\\]\nand the direction:\n\\[\n    d = -R^{-1}q\n\\]\nAs we can see, the Hessian of this new function is surely symmetric positive definite (identity matrix). Moreover, $\\lambda_n(I) = \\lambda_1(I)$ which means that the Newton's method \\textit{finishes in one iteration}. \n\\par Let us now speak about Newton's convergence. We suppose our function is convex with gradient Lipschitz continuous. This implies the following:\n\\[\n    uI \\leq \\nabla ^ 2 f \\leq LI\n\\]\nWe can now prove that it is convergent provided that $\\cos(\\theta)$ does not go to 0 too fast, otherwise we will not go in the descent direction.\n\\begin{proof}\nWe want to prove the following:\n\\[\n    \\cos(\\theta_i) \\leq 0\n\\]\nSince the dot product between $\\nabla f(x_i)$ and $d_i$ must be negative. Thus we need to show that:\n\\[\n    \\frac{\\langle \\nabla f(x_i), d_i \\rangle}{\\lVert \\nabla f(x_i) \\rVert \\lVert d_i \\rVert} \\leq 0\n\\]\nLet us start with the numerator:\n\\[\n    d_i = - [\\nabla ^ 2 f(x_i)]^{-1} \\nabla f(x_i) \\Rightarrow [\\nabla ^ 2 f(x_i)] d_i = - \\nabla f(x_i)\n\\]\nwe now multiply both sides by $- d_i^T$:\n\\[\n    - d_i^T[\\nabla ^ 2 f(x_i)] d_i = d_i^T \\nabla f(x_i)\n\\]\nSince the Hessian is symmetric we can use the Spectra decomposition:\n\\[\n    \\lambda_n \\lVert d_i \\rVert ^ 2 \\leq d_i^T[\\nabla ^ 2 f(x_i)] d_i \\leq \\lambda_1 \\lVert d_i \\rVert ^ 2\n\\]\nBut be careful, we have a minus up there, thus:\n\\[\n    - \\lambda_n \\lVert d_i \\rVert ^ 2 \\geq - d_i^T[\\nabla ^ 2 f(x_i)] d_i \\geq - \\lambda_1 \\lVert d_i \\rVert ^ 2\n\\]\nSo we then obtain:\n\\[\n    d_i^T \\nabla f(x_i) = - d_i^T[\\nabla ^ 2 f(x_i)] d_i \\leq - \\lambda_n \\lVert d_i \\rVert ^ 2\n\\]\nAs for the denominator, we get:\n\\[\n    \\lVert \\nabla f(x_i) \\rVert = \\lVert \\nabla ^ 2 f(x_i) d_i \\rVert\n\\]\nfrom the definition of the Newton's direction. Now we use the Cauchy-Schwartz inequality:\n\\[\n    \\lVert \\nabla f(x_i) \\rVert = \\lVert \\nabla ^ 2 f(x_i) d_i \\rVert \\leq \\lVert \\nabla ^ 2 f(x_i) \\rVert \\lVert d_i \\rVert = \\lambda_1 \\lVert d_i \\rVert\n\\]\nwhere the last equality follows from the fact that the norm of the Hessian, by spectral decomposition, is the norm of the diagonal matrix $\\Lambda$, i.e. $\\lambda_1$.\n\\par We can now give an upper bound for $\\cos(\\theta_i)$:\n\\[\n    \\cos(\\theta_i) = \\frac{\\langle \\nabla f(x_i), d_i \\rangle}{\\lVert \\nabla f(x_i) \\rVert \\lVert d_i \\rVert} = \\frac{\\nabla d_i^T f(x_i)}{\\lVert \\nabla f(x_i) \\rVert \\lVert d_i \\rVert} \\leq \\frac{- \\lambda_n \\lVert d_i \\rVert ^ 2}{\\lambda_1 \\lVert d_i \\rVert \\lVert d_i \\rVert} = - \\frac{\\lambda_n}{\\lambda_1} \\leq - \\frac{u}{L}\n\\]\nSince $u$ and $L$ are strictly positive, we have that the value of cosine is strictly negative.\n\\end{proof}\n\\par Newton works very well on convex and strictly convex function. But does it also work with non convex ones? Yes.\n\\par When we spoke about the convergence above, we did not use the fact that the function is convex really. What we used is the fact that Hessian is positive definite. Thus if our function does not have a positive definite matrix we can perturb it slightly in order to get a close positive definite one. This method is called \\textbf{Hessian modification}. We choose the smallest $\\epsilon_i$ such that:\n\\[\n    H^i = \\nabla ^ 2 f(x_i) + \\epsilon_i I \\succ 0\n\\]\nNevertheless, we have a minor numerical issue here. Every $\\epsilon_i > - \\lambda_n$ will work fine (remember: since $\\nabla ^2 f \\succ 0$ we know that the smallest eigenvalue is strictly positive). But if $\\lambda_n$ is of machine precision order, we could risk to set $\\epsilon_i = 0$. We suppose here that this does not occur.\n\\par Accordingly, we take $\\epsilon_i = \\max \\{0, \\delta - \\lambda_n\\}$ and we solve the following constraint optimisation problem:\n\\[\n    \\min_{H_i}\\{\\lVert H_i - \\nabla ^ 2 f(x_i) \\rVert_{F} :  H \\geq \\delta I\\}\n\\]\nHow can we solve such a problem. Using spectral decomposition of the Hessian:\n\\[\n    \\nabla ^ 2 f(x_i) = H \\Lambda H^T\n\\]\nWe then take:\n\\[\n    H_i = H \\bar{\\Lambda} H^T\n\\]\nwhere $\\bar{\\Lambda}$ has on diagonal $\\bar{\\gamma}_i = \\max \\{\\lambda_i, \\delta\\}$.\n\\par The problem with this approach is that at each iteration we need to invert and factorise. This costs $\\mathcal{O}(n^3)$, cubic complexity. That's the reason why we move now to the Quasi-Newton methods.\n%\n%\n%\n\\subsection{Quasi-Newton Methods}\nQuasi-Newton methods can be used if the Hessian is unavailable or is too expensive to compute at every iteration. We do not need actually the exact Hessian in the quadratic model of the function, we just need a positive definite matrix. The model $m$ of our function $f$ then becomes:\n\\[\n    m_i(x) \\approx f(x_i) + \\nabla f(x_i) (x-x_i) + \\frac{1}{2} (x-x_i)^T H_i (x-x_i)\n\\]\nAfter computing $\\nabla f(x_{i+1})$ where $x_{i+1} = x_i + \\alpha_i d_i$, we update our model $m$ of $f$ by:\n\\[\n    m_{i+1}(x) \\approx f(x_{i+1}) + \\nabla f(x_{i+1}) (x-x_{i+1}) + \\frac{1}{2} (x-x_{i+1})^T H_i (x-x_{i+1})\n\\]\nThe problem is: how can we compute $H^{i+1}$ efficiently. Let us reason about what we want that $H^{i+1}$ satisfy:\n\\begin{enumerate}\n    \\item $H^{i+1} \\succ 0$\n    \\item $\\nabla m^{i+1}(x_i) = \\nabla f(x_i)$, i.e. the gradient in the previous point $x_i$ of the new model must be the same of the previous model in the same point. This is called \\textbf{Secant equation}\n    \\item $\\lVert H^{i+1} - H^i \\rVert$ is small\n\\end{enumerate}\nNote how the second point can be also written as:\n\\begin{align*}\n    \\nabla m^{i+1}(x_{i+1} - x_i) &= f(x_{i+1}) + \\nabla f(x_{i+1}) (x_{i+1} - x_i - x_{i+1}) +\\\\\n    &+\\frac{1}{2} (x_{i+1} - x_i -x_{i+1})^T H_i (x_{i+1} - x_i -x_{i+1}) =\\\\\n    & = f(x_{i+1}) - \\nabla f(x_{i+1}) (x_i) + \\frac{1}{2} (- x_i)^T H_i (- x_i) TO FINISH\n\\end{align*}\n\\par Let us now see how can we compute such a matrix $H^{i+1}$. We define the following:\n\\[\n    s_i = x_{i+1} - x_i\n\\]\nand\n\\[\n    y_i = f(x_{i+1}) - f(x_i)\n\\]\nThus we can write:\n\\[\n    H^{i+1}s_i = y_i\n\\]\nWe then multiply both sides by $s_i^T$:\n\\subsection{Conjugate Gradient Method}\n\\subsection{Deflected Gradient Methods}", "meta": {"hexsha": "ddb4608ac3c65243e1e8b05fc2486876572d498b", "size": 87608, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/2-unconstrained.tex", "max_stars_repo_name": "ig92/CM4LDA", "max_stars_repo_head_hexsha": "47b323730a9d47edbba3f5ddc64fe9ad6dc70f4e", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/2-unconstrained.tex", "max_issues_repo_name": "ig92/CM4LDA", "max_issues_repo_head_hexsha": "47b323730a9d47edbba3f5ddc64fe9ad6dc70f4e", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/2-unconstrained.tex", "max_forks_repo_name": "ig92/CM4LDA", "max_forks_repo_head_hexsha": "47b323730a9d47edbba3f5ddc64fe9ad6dc70f4e", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 77.3239187996, "max_line_length": 932, "alphanum_fraction": 0.7111679299, "num_tokens": 26260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594991, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.7361696692792995}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Graphs}\n\n\\objective{Graph arbitrary power functions by hand}\n\n\n\\index{power function!graphs}\nWhat is the simplest rational exponent function to graph?  $f(x)=x^1$, because $1=\\frac{1}{1}$!  \n1 is the identity of multiplication, and powers --- as groups of multiplication --- all go through\nit.  Every graph of the type $f(x)=x^{\\frac{m}{n}}$ passes through $(1,1)$.  In this section, we will\ndiscuss how to graph any function of this type, but you must be sure that $\\frac{m}{n}$ is a fraction\nin simplest form (i.e. no common factors).\n\n\\subsection{Behavior $<1$}\nPick a number.  Square it.  Did it get bigger or smaller?  Bigger, of course, you say.  Well, \nthat assumes you picked a number bigger than 1.  What would have happened if you had\npicked a number $(0,1)$?  What is $0.5^2$?  $0.1^2$?  They both get smaller, 0.25 and 0.01\nrespectively.  \n\n\n\\begin{derivation}{Small Exponents and Small Numbers}\nSize of the exponent will shape the graph\ndifferently between $(0,1)$ than it will $(1,\\infty)$.\n\\begin{itemize}\n\\item For $\\frac{m}{n}>1$, $b^\\frac{m}{n}$ will increase \\emph{more} rapidly if $b>1$ and less rapidly  if $0<b<1$.\\\\\n\\item For $\\frac{m}{n}<1$, $b^\\frac{m}{n}$ will increase \\emph{less} rapidly if $b<1$ and more rapidly if $0<b<1$.\n\\end{itemize}\n\\end{derivation}\n\n\nSo, if small exponents grow quickly to 1, and then slow down, while large exponents grow\nslowly towards 1 and then quickly afterwards, we may broadly sketch graphs.\n\n\\begin{figure}\n\\begin{centering}\n\\begin{tikzpicture}[scale=3]\n\t\\draw [help lines] (-0.2, -0.2) grid (2, 2);\n\t\\draw [thick,<->] (-.2, 0) -- (2.2, 0);\n\t\\draw [thick,<->] (0, -.2) -- (0, 2.2);\n        % x-axis label\n        \\node at (2.5, 0) {x};\n        % y-axis label\n        \\node at (0, 2.5) {y};\n\n        \\draw[dashed, -] (-.2,-.2) -- (2,2) node [anchor=south] {$y=x^1$};\n\n        \\draw[domain=-.2:1.45,<->,ultra thick,blue] plot (\\x,\\x*\\x);\n\t\\node at (1.5,2.1) [anchor=south] {$y=x^2$};\n\n        \\draw[domain=-.2:1.14,<->,ultra thick,orange] plot (\\x,\\x*\\x*\\x*\\x*\\x*\\x);\n\t\\node at (1.03,2.2) [anchor=south] {$y=x^6$};\n\n        \\draw[domain=0:2,->,ultra thick,red,samples=200,smooth] plot (\\x,{sqrt(\\x)});\n\t\\node at (2,1.45) [anchor=west] {$y=x^{\\frac{1}{2}}$};\n\n        \\draw[domain=0:2,->,ultra thick,purple,samples=400,smooth] plot (\\x,{(\\x)^(1/6)});\n\t\\node at (2,1.1) [anchor=west] {$y=x^{\\frac{1}{6}}$};\n\\end{tikzpicture}\n\\caption{Various power function graphs with exponents more and less than 1}\n\\end{centering}\n\\end{figure}\n\n\\subsection{Even, Odd, and Negative}\nIf the functions we are graphing are all of the type $f(x)=x^\\frac{m}{n}$, then there will be\nobvious patterns dependent upon what kind of numbers $m$ and $n$ are.  \n\n\\subsubsection{$n$ is odd}\nIf the root we are taken is odd, then it is easily defined for both positive and negative real input,\nso the function will exist across the entire real domain.  In other words, there will be both a\nleft and right half.\n\n\\subsubsection{$n$ is even}\nIf the root we are taken is even, then negative inputs will be undefined.  Notice that this leads to\nthe major exception to our rule mentioned previously, that rational exponents are strictly equivalent\nto powers over roots.  $\\sqrt[4]{x^2}$ will work for negative inputs, but $x^\\frac{1}{2}$ will not.\n\n\\subsubsection{$\\frac{m}{n}$ is negative}\nWhen an exponent is negative, that is equivalent to a positive exponent in the denominator.\nThese reciprocal transformations were covered in chapter 4.\n", "meta": {"hexsha": "bfc2cd739bbe8a945bb71e6edc12893cfe3b5bf1", "size": 3504, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch05/0503.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch05/0503.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch05/0503.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.2592592593, "max_line_length": 117, "alphanum_fraction": 0.6686643836, "num_tokens": 1153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409024, "lm_q2_score": 0.8856314677809303, "lm_q1q2_score": 0.7360864411149065}}
{"text": "\\section{Optimization Functions}\n\nThe functions in this section are models with analytic optimal points.\n\\setcounter{tocdepth}{4}\n\\subsection{Continuous}\n\\subsubsection{Unconstrained}\n\\paragraph{Beale's Function}\nBeale's function has a two-dimensional input space and a single global/local minimum.\nSee \\url{https://en.wikipedia.org/wiki/Test_functions_for_optimization}.\n\n\\begin{itemize}\n  \\item Objective Function: $f(x,y) = (1.5-x+xy)^2+(2.25-x+xy^2)^2+(2.625-x+xy^3)^2$\n  \\item Domain: $-4.5 \\leq x,y \\leq 4.5$\n  \\item Global Minimum: $f(3,0.5)=0$\n\\end{itemize}\n\n\n\\paragraph{Rosenbrock Function}\nThe Rosenbrock function can take a varying number of inputs.  For up to three inputs, a single global minimum\nexists.  For four to seven inputs, there is one local minimum and one global maximum.\nSee \\url{https://en.wikipedia.org/wiki/Rosenbrock_function}.\n\n\\begin{itemize}\n  \\item Objective Function: $f(\\vec x) = \\sum_{i=1}^{n-1}\\left[100\\left(x_{i+1}-x_i^2\\right)^2+\\left(x_i-1)^2\\right) \\right]$\n  \\item Domain: $ -\\infty \\leq x_i \\leq \\infty \\hspace{10pt} \\forall \\hspace{10pt} 1\\leq i \\leq n$\n  \\item Global Minimum: $f(1,1,\\cdots,1,1)=0$\n  \\item Local minimum ($n\\geq4$): near $f(-1,1,\\cdots,1)$\n\\end{itemize}\n\n\n\\paragraph{Goldstein-Price Function}\nThe Goldstein-Price function is a two-dimensional input function with a single global minimum.\nSee \\url{https://en.wikipedia.org/wiki/Test_functions_for_optimization}.\n\n\\begin{itemize}\n  \\item Objective Function:\n    \\begin{align}\n      f(x,y) =& \\left[1+(x+y+1)^2\\left(19-14x+3x^2-14y+6xy+3y^2\\right)\\right] \\\\ \\nonumber\n        & \\cdot\\left[30+(2x-3y)^2(18-32x+12x^2+48y-36xy+27y^2)\\right]\n    \\end{align}\n  \\item Domain: $-2 \\leq x,y \\leq 2$\n  \\item Global Minimum: $f(0,-1)=3$\n\\end{itemize}\n\n\\paragraph{McCormick Function}\nThe McCormick function is a two-dimensional input function with a single global minimum.\nSee \\url{https://en.wikipedia.org/wiki/Test_functions_for_optimization}.\n\n\\begin{itemize}\n  \\item Objective Function: $f(x,y) = \\sin(x+y) + (x-y)^2 - 1.5x + 2.5y + 1$\n  \\item Domain: $-1.5 \\leq x \\leq 4$, $-3 \\leq y \\leq 4$\n  \\item Global Minimum: $f(-0.54719,-1.54719) = -1.9133$\n\\end{itemize}\n\n\\paragraph{2D Canyon}\nThe two-dimensional canyon offers a low region surrounded by higher walls.\n\n\\begin{itemize}\n  \\item Objective Function: $f(x,y) = xy\\cos(x+y)$\n  \\item Domain: $0 \\leq x,y \\leq \\pi$\n  \\item Global Minimum: $f(1.8218,1.8218)=-2.90946$\n\\end{itemize}\n\n\\paragraph{Stochastic Diagonal Valley}\nThe stochastic three-dimensional diagonal valley offers a low region surrounded by higher walls.\n\n\\begin{itemize}\n  \\item Objective Function: $f(x,y,stoch) = stoch * R + (x+0.5)^2 + (y-0.5)^2 + \\sqrt{(x - \\cfrac{x}{x-y})^2 + (y - \\cfrac{y}{y-x})*^2} * 10, while R\\sim ([-0.1,0.1])$\n  \\item Domain: $0 \\leq x,y \\leq 1$\n  \\item Global Minimum if $stoch =0$: $f(-0.5,0.5)=0$\n\\end{itemize}\n\n\\paragraph{Parabolic Valley}\nThe parabolic valley is dominated by distance from $x=y$ but secondarily motivated by $x+y$.\n\n\\begin{itemize}\n  \\item Objective Function: $f(x,y) = 100 (x - y)^2 + (x + y)^2$\n  \\item Domain: $-1 \\leq x,y \\leq 1$\n  \\item Global Minimum: $f(0,0)=0$\n\\end{itemize}\n\n\\paragraph{Paraboloid}\nThe elliptic paraboloid is a two-dimensional function with a single global minimum.\n\n\\begin{itemize}\n  \\item Objective Function: $f(x,y) = 10(x+0.5)^2 + 10(y-0.5)^2 $\n  \\item Domain: $-2 \\leq x \\leq 2$, $-2 \\leq y \\leq 2$\n  \\item Global Minimum: $f(-0.5,0.5) = 0$\n\\end{itemize}\n\n\\paragraph{Time-Parabola}\nThis model features the sum of a parabola in both $x$ and $y$; however, the parabola in $y$ moves in time and\nhas a reduced magnitude as time increases. As such, the minimum is always found at $x=0$ and at $(t-y)=0$, with\n$y$ values at low $t$ being more impactful than at later $t$, and $x$ as impactful as $y(t=0)$.\n\n\\begin{itemize}\n  \\item Objective Function: $f(x,y,t) = x^2 + \\sum_{t} (t-y)^2 \\exp{-t}$\n  \\item Domain: $-10 \\leq x,y,t \\leq 10$\n  \\item Global Minimum: $f(0,y=t,t) = 0$\n\\end{itemize}\n\n\\paragraph{Eggholder}\nThis is a 2D function with a plethora of local minima and maxima (i.e., non-convex). It is challenging for most optimizers to find the global minimum for such a function. Metaheuristic methods are prefered for their ability to avoid getting stuck in local optima.\n\n\\begin{itemize}\n\t\\item Objective Function: $f(x,y,) =-(y+47) \\sin(\\sqrt{|\\frac{x}{2}+(y+47)|}) - x\\sin(\\sqrt{|x - (y+47)|})$\n\t\\item Domain: $-512 \\leq x,y \\leq 512$\n\t\\item Global Minimum: $f(x=512, y=404.2319) = -959.6407$\n\\end{itemize}\n\n\\subsubsection{Constrained}\n\\paragraph{Mishra's Bird Function}\nThe Mishra bird function offers a constrained problem with multiple peaks, local minima, and one steep global\nminimum.\nSee \\url{https://en.wikipedia.org/wiki/Test_functions_for_optimization}.\n\n\\begin{itemize}\n  \\item Objective Function: $f(x,y) = \\sin(y)\\exp[1-\\cos(x)]^2 + \\cos(x)\\exp[1-\\sin(y)]^2 + (x-y)^2$\n  \\item Constraint: $(x+5)^2 + (y+5)^2 < 25$\n  \\item Domain: $-10 \\leq x \\leq 0$, $-6.5 \\leq y \\leq 0$\n  \\item Global Minimum: $f(-3.1302468, -1.5821422) = -106.7645367$\n\\end{itemize}\n\n\\paragraph{ND Slant}\nThis trivial linear problem extends to arbitrary dimension and has optimal points at infinities,\nwhich is usually outside the domain of exploration.\n\\begin{itemize}\n  \\item Objective Function: $f(\\vec x) = 1 - \\frac{1}{N}\\sum_{x_i\\in \\vec x} x_i$\n  \\item Domain: $0 \\leq x_i \\leq 1 \\forall x_i \\in \\vec x$\n  \\item Global Minimum: $f(\\{1\\}_N) = 0$\n\\end{itemize}\n\n% \\paragraph{Rosenbrock with cubic and linear constraints}\n% Here the Rosenbrock is another two dimensional highly nonlinear function. The global maximum is on the intersection of the two constraints which renders this problem challenging for optimizers that uses random decisions for next points such as simulated annealing and genetic algorithms.\n% \\begin{itemize}\n% \t\\item Objective Function: $f(x,y) = (1-x^2) + 100(y-x^2)^2$\n% \t\\item Domain: $-1.5 \\leq x \\leq 1.5$ and $ -0.5 \\leq y \\leq 2.5$\n% \t\\item Constraints: $(x-1)^3 - y +1 \\leq 0$ and $x+y-2 \\leq 0$\n% \t\\item Global Maximum: $f(1.0,1.0) = 0$\n% \\end{itemize}\n\n\\paragraph{Rosenbrock with a disk constraint}\nThis is the same 2D function, but constrained to a disk. This constraint makes it a little easier than the previous function.\n\\begin{itemize}\n\t\\item Objective Function: $f(x,y) = (1-x^2) + 100(y-x^2)^2$\n\t\\item Domain: $-1.5 \\leq x,y \\leq 1.5$\n\t\\item Constraint: $x^2 + y^2 \\leq 2$\n\t\\item Global Maximum: $f(1.0,1.0) = 0$\n\\end{itemize}\n\n\\paragraph{Townsend}\nIt is a highly nonlinear non convex function with multiple minima and maxima. The constraint is highly nonlinear and the y-domain is asymmetric.\n\\begin{itemize}\n\t\\item Objective Function: $f(x,y) = -\\left[\\cos((x-0.1)y)\\right]^2-x\\sin(3x+y)$\n\t\\item Domain: $-2.25 \\leq x \\leq 2.25$ and $-2.5 \\leq y \\leq 1.75$\n\t\\item Constraint: $x^2 + y^2 \\leq \\left[2\\cos(t)-\\frac{1}{2}\\cos(2t)-\\frac{1}{4}\\cos(3t) - \\frac{1}{8}cos(4t) \\right]^2+\\left[2\\sin(t)\\right]^2 $;  \\[ \\text{where: } t=\\arctan2(x,y) \\]\n\t\\item Global Minimum: $f(2.0052938,1.1944509) = -2.0239884$\n\\end{itemize}\n\n\\paragraph{Simionescu}\nAn exteremly simple two dimensional nonlinear function formed from 45-degrees hyperbolas. Subjected to highly nonlinear constraint.\n\\begin{itemize}\n\t\\item Objective Function: $f(x,y) = 0.1xy$\n\t\\item Domain: $-1.25 \\leq x,y \\leq 1.25$\n\t\\item Constraint: $x^2 + y^2 \\leq \\left[r_{\\Gamma}+r_S\\cos\\left(n \\arctan(\\frac{x}{y})\\right)\\right]^2 $; \\[ \\text{where: } r_{\\Gamma}=1, r_S = 0.2, \\text{and } n=8 \\]\n\t\\item Global Minimum: $f(\\pm 0.84852813,\\mp0.84852813) = -0.072$\n\\end{itemize}\n\\subsection{Discrete}\n\\subsubsection{Unconstrained}\n\\paragraph{Locally weighted sum without replacement}\nThis function computes the sum of the input vector components weighted by the location in the vector (i.e., component/dimension number). The input vector is sampled from a disrete uniform distribution of intergers between an upper bound $ub$, and a lower bound $lb$ without replacement (i.e., if an integer is selected for one variable (a component in the $n$-th dimensional input vector it cannot be selected for the remaining components)).\n\\begin{itemize}\n\t\\item Objective Function: $f(\\vec{x}) = \\sum_{i=1}^{G}i \\times x_i$; where $G$ is the number of variables (aka dimension of search/design space or number of Genes in Genetic algorithms) \n\t\\item Domain: $x_i \\sim \\mathcal{U}^{\\text{Discrete int}}_{\\text{w/o replacement}} (lb,ub)$\n\t\\item Global Minimum: $f(\\vec{x}_{opt}|x_i = lb + G - i) = \\sum_{i=1}^{G} (lb + G -i) \\times i$\n\tFor instance, if $lb =1$, $ub=20$ , $G=6$, $\\vec{x}_{opt} = [\\vec{x}]_i | x_i = lb + G - i = 1+6-i = \\begin{bmatrix}\n\t6 & 5 & \\dots & 1 \\end{bmatrix}$ and the minimum will be $f_{min} = \\sum_{i=1}^{G} (1 + 6 -i) \\times i = \\frac{G(G+1)}{6}[3lb+G-1] = 56$\n\t\\item Global Maximum: $f(\\vec{x}_{opt}|x_i = ub - G + i) = \\sum_{i=1}^{G} (ub - G +i) \\times i$\n\tFor instance, if $lb =1$, $ub=20$ , $G=6$, $\\vec{x}_{opt} = [\\vec{x}]_i | x_i = ub - G + i = 20-6+i = \\begin{bmatrix}\n\t15 & 16 & \\dots & 20 \\end{bmatrix}$ and the maximum will be $f_{max} = \\sum_{i=1}^{G} (20 - 6 +i) \\times i = \\frac{G(G+1)}{6}[3ub-G+1] = 385$\n\\end{itemize}\n\n\\paragraph{Locally weighted sum with replacement}\nThis function computes the sum of the input vector components weighted by the location in the vector (i.e., component/dimension number). The input vector is sampled from a disrete uniform distribution of intergers between an upper bound $ub$, and a lower bound $lb$ with replacement (i.e., if an integer is selected for one variable, it can be selected again for any or all other variables).\n\\begin{itemize}\n\t\\item Objective Function: $f(\\vec{x}) = \\sum_{i=1}^{G}i \\times x_i$; where $G$ is the number of variables (aka dimension of search/design space or number of Genes in Genetic algorithms) \n\t\\item Domain: $x_i \\sim \\mathcal{U}^{\\text{Discrete int}}_{\\text{w/ replacement}} (lb,ub)$\n\t\\item Global Minimum: $f(\\vec{x}_{opt}|x_i = lb) = \\sum_{i=1}^{G} lb \\times i$\n\tFor instance, if $lb =1$, $ub=20$ , $G=6$, $\\vec{x}_{opt} = [\\vec{x}]_i | x_i = lb = 1 = \\begin{bmatrix}\n\t1 & 1 & \\dots & 1 \\end{bmatrix}$ and the minimum will be $f_{min} = \\sum_{i=1}^{G} i = \\frac{G(G+1)}{2}[lb] = 21$\n\t\\item Global Maximum: $f(\\vec{x}_{opt}|x_i = ub) = \\sum_{i=1}^{G} ub \\times i$\n\tFor instance, if $lb =1$, $ub=20$ , $G=6$, $\\vec{x}_{opt} = [\\vec{x}]_i | x_i = ub = 20 = \\begin{bmatrix}\n\t20 & 20 & \\dots & 20 \\end{bmatrix}$ and the maximum will be $f_{max} = \\sum_{i=1}^{G} 20 \\times i = \\frac{G(G+1)}{2}[ub] = 420$\n\\end{itemize}\n\n\\subsubsection{Constrained}\n\\paragraph{Locally weighted sum with replacement linearly constrained}\nIt uses the same function but adds a constraint.\n\\begin{itemize}\n\t\\item Objective Function: $f(\\vec{x}) = \\sum_{i=1}^{G}i \\times x_i$; where $G$ is the number of variables (aka dimension of search/design space or number of Genes in Genetic algorithms) \n\t\\item Domain: $x_i \\sim \\mathcal{U}^{\\text{Discrete int}}_{\\text{w/o replacement}} (lb,ub)$\n\t\\item constraint $x_2 \\leq 8.5 - 0.5 * x_1$\n\t\\item Global Minimum if $lb = 1, ub = 6, G =3$: $f(\\vec{x}_{opt} = \\begin{bmatrix}\n\t1 & 1 & 1 \\end{bmatrix}) = 6.0$\n\t\\item Global Maximum if $lb = 1, ub = 6, G =3$: $f(\\vec{x}_{opt} = \\begin{bmatrix}\n\t6 & 5 & 6 \\end{bmatrix} = 34.0$\n\\end{itemize}\n\n\\paragraph{Locally weighted sum with replacement sphere constrained}\nIt uses the same function but adds a constraint.\n\\begin{itemize}\n\t\\item Objective Function: $f(\\vec{x}) = \\sum_{i=1}^{G}i \\times x_i$; where $G$ is the number of variables (aka dimension of search/design space or number of Genes in Genetic algorithms) \n\t\\item Domain: $x_i \\sim \\mathcal{U}^{\\text{Discrete int}}_{\\text{w/o replacement}} (lb,ub)$\n\t\\item constraint $x^{2}_{1} + x^{2}_{2} \\leq 72$\n\t\\item Global Minimum if $lb = 1, ub = 6, G =3$: $f(\\vec{x}_{opt} = \\begin{bmatrix}\n1 & 1 & 1 \\end{bmatrix})= 6.0$\n\\item Global Maximum if $lb = 1, ub = 6, G =3$: $f(\\vec{x}_{opt} = \\begin{bmatrix}\n6 & 5 & 6 \\end{bmatrix} = 34.0$\n\\end{itemize}\n", "meta": {"hexsha": "19e2d5065d60e28d1e23accdc015718e22f3c4f4", "size": 11946, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tests/optimization_functions.tex", "max_stars_repo_name": "FlanFlanagan/raven", "max_stars_repo_head_hexsha": "bd7fca18af94376a28e2144ba1da72c01c8d343c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 159, "max_stars_repo_stars_event_min_datetime": "2017-03-24T21:07:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:44:40.000Z", "max_issues_repo_path": "doc/tests/optimization_functions.tex", "max_issues_repo_name": "FlanFlanagan/raven", "max_issues_repo_head_hexsha": "bd7fca18af94376a28e2144ba1da72c01c8d343c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1667, "max_issues_repo_issues_event_min_datetime": "2017-03-27T14:41:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T19:50:06.000Z", "max_forks_repo_path": "doc/tests/optimization_functions.tex", "max_forks_repo_name": "wanghy-anl/raven", "max_forks_repo_head_hexsha": "ef1372364a2776385931763f2b28fdf2930c77b9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 95, "max_forks_repo_forks_event_min_datetime": "2017-03-24T21:05:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-08T17:30:22.000Z", "avg_line_length": 54.3, "max_line_length": 441, "alphanum_fraction": 0.6752887996, "num_tokens": 4328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7360167350275655}}
{"text": "While first and second moments give us some idea of the performance of our sampling algorithms, we ideally would like a fuller picture.  In this section we compare the performance of algorithms using the total variation distance, Wasserstein distance and Kullback--Leibler divergence.  Using these measures, we can compare the performance to theoretical upper bounds for \\texttt{ULA}.\n\n\\subsection{Statistical Distances}\nLet $\\mathcal{B}(\\R^d)$ denote the Borel $\\sigma$-algebra on $\\R^d$. Let $P$ and $Q$ be probability measures on the space $(\\R^d, \\mathcal{B}(\\R^d))$.  Then we define the total variation distance, Kullback--Leibler divergence and Wasserstein metric as follows:\n\n\\begin{defn}[Total Variation]\nThe total variation distance between two probability measures $P$ and $Q$ on $(\\Omega, \\mathcal{F})$ is defined as\n$$\n\\norm{P - Q}_{TV} = \\sup_{A \\in \\mathcal{F}} \\abs{P(A) - Q(A)}.\n$$\n\\end{defn}\nIn other words, total variation measures the greatest possible difference between the probability of an event according to $P$ and $Q$.\n\\begin{prop}\nIf the set $\\Omega$ is countable then this is equivalent to half the $L^1$ norm.\n$$\n\\norm{P - Q}_{TV} = \\frac{1}{2} \\norm{P-Q}_1 = \\frac{1}{2} \\sum_{\\omega \\in \\Omega} \\abs{P(\\omega) - Q(\\omega)}\n$$\n\\end{prop}\n\\begin{proof}\nLet $B = \\{\\omega: P(\\omega) \\geq Q(\\omega)\\}$ and let $A \\in \\mathcal{F}$ be any event.  Then\n$$\nP(A) - Q(A) \\leq P(A \\cap B) - Q(A \\cap B) \\leq P(B) - Q(B).\n$$\nThe first inequality holds since $P(\\omega)-Q(\\omega) < 0$ for any $\\omega \\in A \\cap B^c$, and so the difference in probability cannot be greater if these elements are excluded.  For the second inequality, we observe that including further elements of $B$ cannot decrease the difference in probability.\nSimilarly,\n$$\nQ(A) - P(A) \\leq Q(B^c) - P(B^c) = P(B) - Q(B)\n$$\nThus, setting $A=B$, we have that $\\abs{P(A)-Q(A)}$ is equal to the upper bound in the total variation distance.  Hence,\n$$\n\\norm{P-Q}_{TV} = \\frac{1}{2} \\abs{P(B)-Q(B)+Q(B^c)-P(B^c)} = \\frac{1}{2} \\sum_{\\omega \\in \\Omega} \\abs{P(x)-Q(x)}\n$$\n\\end{proof}\n\n\\begin{defn}[Kullback--Leibler Divergence]\nLet $P$ and $Q$ be two probability measures on $(\\Omega, \\mathcal{F})$.  If $P \\ll Q$, the Kullback--Leibler divergence of $P$ with respect to $Q$ is defined as\n$$\nD_{\\text{KL}}(P\\,||\\,Q) = \\int_\\Omega \\od{P}{Q} \\log \\left(  \\od{P}{Q} \\right) \\dif  Q.\n$$\n\\end{defn}\nThe Kullback--Leibler divergence from $Q$ to $P$ measures the information lost in using $Q$ to approximate $P$  \\cite{anderson2004model} and is also known as the relative entropy.  It is worth noting that, unlike the other two measures considered here, the Kullback--Leibler divergence is not a metric, and in particular is not symmetric.\n\nFinally we consider the Wasserstein distance.  If $P$ and $Q$ are probability measures on $(\\Omega, \\mathcal{F})$, we say that $\\gamma$ is a transport plan between two probability measures $P$ and $Q$ if it is a probability measure on $(\\Omega \\times \\Omega, \\mathcal{F} \\times \\mathcal{F})$ such that for any Borel set $A \\subset \\mathcal{F}$, $\\gamma(A \\times \\Omega)=P(A)$ and $\\gamma(\\Omega \\times A) = Q(A)$.  We denote the set of all such transport plans by $\\Pi(P,Q)$.  In simple terms, the set of transport plans, $\\Pi(P,Q)$, represents the possible ways of transporting mass distributed according to $P$ to a distribution according to $Q$, without creating or destroying mass in the process.  The `effort' to transport mass is then represented by a cost function $d:\\Omega \\to \\Omega$, so that $d(x,y)$ is the cost of moving unit mass from $x$ to $y$.\n\n\\begin{defn}[Wasserstein distance]\nFor two probability measures, $P$ and $Q$, the $p$-Wasserstein distance is given by\n$$\nW_p(P,Q) = \\left( \\inf_{\\gamma \\in \\Pi(P,Q)} \\int_{\\Omega \\times \\Omega} d(x,y)^p d \\gamma(x,y) \\right)^{1/p}.\n$$\n\\end{defn}\n\nThe Wasserstein distance represents the amount of `effort' required to move mass distributed according to $P$ to $Q$.  We restrict our attention to $L^1$-Wasserstein and $L^2$-Wasserstein distances, which is to say that we choose our cost function $d$ to be the Euclidean distance, and $p=1,2$.\n\nOne particular advantage of Wasserstein distance compared to total variation or Kullback--Leibler divergence is that bounds on Wasserstein distance can be used directly to bound the accuracy of the first and second moment approximations, and so for application to statistics there is some evidence to suggest it is the most appropriate of the three measures for our purposes \\cite{dalalyan2019user}.\n\nDue to impracticality of computing higher-dimensional Wasserstein distances, we use a computationally more feasible variant, the Sliced Wasserstein distance. First proposed in \\cite{rabin2011wasserstein} and further elaborated on, for example, in \\cite{gswd}, the Sliced Wasserstein distance exploits the fact that the Wasserstein distance between 1-dimensional probability measures $P, Q$ can be computed with an explicit formula $\\abs{F^{-1}(t)-G^{-1}(t)}^p dt$ where $F$ and $G$ are the CDFs of $P$ and $Q$ respectively \\cite{ramdas2017wasserstein}.\n\n\n\\begin{defn}[Sliced Wasserstein distance]\nFor two probability measures, $P$ and $Q$, the $L^p$ Sliced Wasserstein distance is given by\n$$\nSW_p(P,Q) = \\left(\\int_{\\mathbb S^{d-1} }  W_p^p\\left(\\mathcal{RI}_P(\\cdot, \\theta), \\mathcal{RI}_Q(\\cdot, \\theta) \\right) d \\theta \\right)^{\\frac 1 p}\n$$\n\\end{defn}\n\nwhere $\\mathbb S^{d-1}$ is the $(d-1)$-dimensional sphere and $\\mathcal RI$ denotes the Inverse Radon transform. In the above references, it is also proved that $SW_p$ is indeed a metric. The main reason why we can use the Sliced Wasserstein distance as an approximation to the Wasserstein distance is that these two metrics are equivalent\\cite{Santa}.\n\n\\subsubsection{Numerical Comparison}\nIn this section we present a numerical comparison of the algorithms considered, extending the results of \\cite{Brosse18tULA} which only considered first and second moments.  It should be noted that the results in the aforementioned paper are in dimension 100, while here our results are in dimension 2.  This is due to the bin-filling problem when approximating the density function, which is explained in section \\ref{sec:Imp}.  We do not have evidence to suggest the performance of these algorithms would be similar in higher dimensions.  Due to lack of space in this report, the results here are mostly in total variation distance.  The functionality for the experiments is available in our GitHub repository (see section \\ref{sec:Imp}), and tests can easily be performed in Sliced 1-Wasserstein distance and Kullback--Leibler divergence.\n\n\\begin{note}\n    It is important to state here that the accuracy of our implementation of these measures has not been thoroughly tested.  The number of bins chosen for the histogram heavily influences results, and our default choice of 100 bins for 2 dimensions is somewhat arbitrary.  As such, the results presented here should be treated with some caution.\n\\end{note}\n  \n\nThe results for total variation in the case of the Gaussian (Figure \\ref{fig:TVgauss}) support the claim of \\cite{Brosse18tULA} that tamed algorithms have similar performance to untamed for small step size.  As expected, they do perform slightly worse than the untamed equivalent, but this difference is relatively small.  For the ill-conditioned case (Figure \\ref{fig:TV_ICgauss}), the unadjusted versions of each algorithm diverge, but the tamed versions are stable.  While the performance of all Langevin-based methods is poor, coordinate-wise taming, as predicted, improves performance, and we expect this effect to be more pronounced in higher dimensions.\n\nThe double well presents a more interesting case.  For small step size (Figure \\ref{fig:TVdouble02}) there is not much difference between the algorithms, with \\texttt{LM} performing the poorest of all the Langevin-based methods, for higher step sizes (Figures \\ref{fig:TVdouble1}, \\ref{fig:TVdouble2}) it outperforms all other algorithms, even those with Metropolis--Hastings adjustments.  For step size 0.1 and higher, the matrix multiplication step in \\texttt{HOLA} results in an overflow, while for step size 0.2, \\texttt{ULA} diverges.  It is only for step size 0.3 that \\texttt{LM} finally diverges (Figure \\ref{fig:TVdouble3}).  The reasons for this behaviour is unclear, but these results seem to support the claims made in \\cite{LM12}.  To verify this, the experiment for the double well with step size 0.1 was repeated in Sliced 1-Wasserstein distance (Figure \\ref{fig:SWdouble1}).  The results broadly agree with those of the total variation, although Metropolised algorithms appear to be favoured by this metric, and tamed algorithms graded more harshly.\n\nThe final three plots (Figures \\ref{fig:TVginz01}-\\ref{fig:TVrosen01}) are included mostly for completeness.  It is interesting to note however, that on the Rosenbrock distribution (Figure \\ref{fig:TVrosen001}) \\texttt{LM} again outperforms \\texttt{ULA} for step size 0.001.\n\\begin{figure}[ht!]\n\t\\centering\n\t\t\\includegraphics[height=0.43\\textheight]{Figures/TV_gaussian11_step0pt02.png}\n\t\\caption{$10^5$ samples from standard Gaussian with step size 0.02}\n\t\\label{fig:TVgauss}\n\\end{figure}\n\n\\begin{figure}[ht!]\n\t\\centering\n\t\t\\includegraphics[height=0.43\\textheight]{Figures/TV_ICgaussian10pt0001_step0pt02.png}\n\t\\caption{$10^5$ samples from ill-conditioned Gaussian with step size 0.02}\n\t\\label{fig:TV_ICgauss}\n\\end{figure}\n\n\\begin{figure}[ht!]\n\t\\centering\n\t\t\\includegraphics[height=0.43\\textheight]{WriteUp/TV_doublewell_step0pt02.png}\n\t\\caption{$10^5$ samples from double well with step size 0.02}\n\t\\label{fig:TVdouble02}\n\\end{figure}\n\n\\begin{figure}[ht!]\n\t\\centering\n\t\t\\includegraphics[height=0.43\\textheight]{WriteUp/TV_doublewell_step0pt1.png}\n\t\\caption{$10^5$ samples from double well with step size 0.1}\n\t\\label{fig:TVdouble1}\n\\end{figure}\n\n\\begin{figure}[ht!]\n\t\\centering\n\t\t\\includegraphics[height=0.43\\textheight]{WriteUp/SW_doublewell_0pt1.pdf}\n\t\\caption{SW1 distance $10^5$ samples from double well with step size 0.1}\n\t\\label{fig:SWdouble1}\n\\end{figure}\n\n\\begin{figure}[ht!]\n\t\\centering\n\t\t\\includegraphics[height=0.43\\textheight]{WriteUp/TV_doublewell_step0pt2.png}\n\t\\caption{$10^5$ samples from double well with step size 0.2}\n\t\\label{fig:TVdouble2}\n\\end{figure}\n\n\\begin{figure}[ht!]\n\t\\centering\n\t\t\\includegraphics[height=0.43\\textheight]{WriteUp/TV_doublewell_step0pt3.png}\n\t\\caption{$10^5$ samples from double well with step size 0.3}\n\t\\label{fig:TVdouble3}\n\\end{figure}\n\n\\begin{figure}[ht!]\n\t\\centering\n\t\t\\includegraphics[height=0.43\\textheight]{WriteUp/TV_ginzburg_step0pt01.png}\n\t\\caption{$10^5$ samples from 1D Ginzburg Landau with step size 0.01}\n\t\\label{fig:TVginz01}\n\\end{figure}\n\n\\begin{figure}[ht!]\n\t\\centering\n\t\t\\includegraphics[height=0.43\\textheight]{WriteUp/TV_rosenbrock_step0pt001.png}\n\t\\caption{$10^5$ samples from Rosenbrock with step size 0.001}\n\t\\label{fig:TVrosen001}\n\\end{figure}\n\n\\begin{figure}[ht!]\n\t\\centering\n\t\t\\includegraphics[height=0.43\\textheight]{WriteUp/TV_rosenbrock_step0pt01.png}\n\t\\caption{$10^5$ samples from Rosenbrock with step size 0.01}\n\t\\label{fig:TVrosen01}\n\\end{figure}\n\n\\newpage\n\\subsection{Theoretical Non-asymptotic Error Bounds}\n\nWhile the asymptotic behaviour of \\texttt{ULA} and \\texttt{MALA} is well-understood \\cite{RT96}, the results do not consider the effect of dimension on the complexity of the algorithms.  For practical purposes, an understanding of the non-asymptotic behaviour of the algorithms would be useful and, in particular, theoretical results which could determine the step size and number of iterations required to guarantee an error of no more than some acceptable value $\\epsilon$.\n\nTheoretical bounds of this nature were first provided in \\cite{dalalyan2017theoretical}, which proved bounds on the total variation distance between the distribution of the $n^{\\text{th}}$ iterate of the unadjusted Langevin Algorithm, under restrictive assumptions, which will be outlined shortly.  In the case of a `warm start', where the distribution of the initial value is close to $\\Pi$, it was shown that \\texttt{ULA} had an upper bound of $\\mathcal{O}(d/\\epsilon)$ iterations to achieve precision level $\\epsilon$.  This result was improved by \\cite{durmus2016high, durmus2017nonasymptotic} which extended the analysis to the Wasserstein distance and dispensed with the assumption of a warm start, showing that the upper bound on iterations could be reduced to $\\mathcal O (d/\\epsilon)$, provided the Hessian of the potential is Lipschitz continuous.  Most recently, \\cite{dalalyan2019user} has provided `user-friendly' bounds on the Wasserstein distance, further improving the constants in these bounds.\n\nIt is important to note here that these results provide explicit constants for the non-asymptotic behaviour for \\texttt{ULA}.  This is in contrast to the theory for \\texttt{MALA} \\cite{bou2013nonasymptotic}, and the tamed \\cite{Brosse18tULA} and higher order algorithms \\cite{Sabanis18tHOLA}, for which only the existence of a constant is proven.  For the Leimkuhler--Matthews method, no such guarantees are known.  As such the non-asymptotic theory for the unadjusted algorithm is practically much more useful.\n\n\\subsubsection{Non-asymptotic Bounds for \\texttt{ULA}}\nWe present without proof the results of \\cite{durmus2017nonasymptotic, dalalyan2019user} which to our knowledge are the best known bounds in total variation and Wasserstein distance respectively. For both results we assume that the potential $U$ is continuously differentiable on $\\R^d$, and there exist positive constants $m$ and $M$ such that $U$ is $m$-strongly convex and $M$-gradient Lipschitz, i.e. for all $x$, $y \\in \\R^d$,\n\\begin{align} \\label{m-convex}\n    &\\text{($m$-strongly convex) \\ } U(x) - U(y) - \\grad U(y)^\\top (x - y) \\geq \\frac{m}{2}\\norm{x-y}_2^2\\\\\n    &\\text{($M$-gradient Lipschitz) \\ } \\norm{\\grad U(x) - \\grad U(y)}_2 \\leq M \\norm{x-y}_2. \\label{M-GradLipschitz}\n\\end{align}\n\nDenote the unique minimiser of $U$ by $y=\\arg \\min_{x \\in \\R^d} U(x)$.  Let $\\nu_N$ denote the distribution of the $N^{\\text{th}}$ sample\n\n\\begin{theorem}[Total Variation part (i)]\n    Assume $h \\in (0, 2/(m+M))$ and $U$ satisfies the assumptions (\\ref{m-convex}, \\ref{M-GradLipschitz}) above.  Let $\\kappa = \\frac{2mM}{m+M}$  Then for any initial value $x_0 \\in \\R^d$ and $N \\geq 1$,\n    $$\n    \\norm{\\pi_h - \\nu_N}_{TV} \\leq \\left\\{ 4 \\pi \\kappa (1-(1-\\kappa h)^{N/2} \\right\\}^{-1/2} (1-\\kappa \\gamma)^{N/2} \\left\\{ \\norm{x_0 - y}_2 + (2 \\kappa^{-1}d)^{1/2} \\right\\}\n    $$\n\\end{theorem}\n\n\\begin{theorem}[Total Variation part (ii)]\n    Assume $h \\in (0, 1/(m+M))$, $U$ satisfies the assumptions (\\ref{m-convex}, \\ref{M-GradLipschitz}) above, and further, assume that $U$ is three times continuously differentiable, and there exists $L$ such that for all $x,y \\in \\R^d$,\n    $$\n    \\norm{\\grad^2 U(x) - \\grad^2 U(y)} \\leq L \\norm{x-y}.\n    $$\n    Then\n    \\begin{align*}\n        \\norm{\\pi_h - \\pi}_{TV} &\\leq (4 \\pi)^{-1/2} \\left\\{ h^2 E_1(h, d) + 2dh^2 E_2(h)/(\\kappa m)\\right\\}^{1/2}\\\\\n        &+ (4 \\pi)^{-1/2} \\lceil \\log(h^{-1}/\\log(2) \\rceil \\left\\{ h^2 E_1(h,d) + h^2 E_2(h)(2 \\kappa^{-1}d + d/m) \\right\\}^{1/2}\\\\\n        &+ 2^{-3/2} M \\left\\{ 2d h^3 L^2/(3\\kappa) + dh^2\\right\\}^{1/2}\n    \\end{align*}\n    where $E_1(h,d)$ and $E_2(h)$ are defined as\n    \\begin{align*}\n        E_1(h,d) &= 2 d \\kappa^{-1} \\left\\{2L^2 + 4 \\kappa^{-1} (dL^2/3 + h M^4 /4) + h^2 M^4/6 \\right\\}\\\\\n        E_2(h) &= L^4(4\\kappa^{-1}/3 + h)\n    \\end{align*}\n\\end{theorem}\n\nThe triangle inequality gives our desired bound on $\\norm{\\pi - \\nu_N}_{TV}$.  We next present the `user-friendly' bound in Wasserstein distance.\n\n\\begin{theorem}[Wasserstein distance]\n    Assume $h \\in (0, 2/M)$ and $U$ satisfies the assumptions (\\ref{m-convex}, \\ref{M-GradLipschitz}) above. \n    \\begin{itemize}\n        \\item If $h \\leq \\frac{2}{m+M}$, then $W_2(\\nu_N, \\pi) \\leq (1-mh)^N W_2(\\nu_0, \\pi) + 1.65 \\frac{M}{m}(hp)^{1/2}.$\n        \\item If $h \\geq \\frac{2}{m+M}$, then $W_2(\\nu_N, \\pi) \\leq (Mh-1)^N W_2(\\nu_0, \\pi) + \\frac{1.65Mh}{2-Mh}(hp)^{1/2}.$\n\\end{itemize}\n\\end{theorem}\n\\begin{prop}\n    If the initial value $X_0 = x_0$ is deterministic then,\n    $$\n    W_2(\\nu_0, \\pi)^2 = \\int_{\\R^p} \\norm{x_0-x}_2^2 \\pi(dx) \\leq \\norm{x_0-y}_2^2 + \\frac{p}{m}.\n    $$\n\\end{prop}\n\n\\begin{remark}\n    If we choose $h$ and $N$ such that\n    $$\n    h \\leq \\frac{2}{m+M}, \\quad e^{-mhN}W_2(\\nu_0, \\pi) \\leq \\epsilon/2, \\quad 1.65\\frac{M}{m}(hp)^{1/2} \\leq \\epsilon/2\n    $$\n    then $W_2(\\nu_N,\\pi) \\leq \\epsilon$.  Hence, for a deterministic initial value $X_0=x_0$, it is sufficient to choose\n    $$\n    h \\leq \\frac{m^2 \\epsilon^2}{11M^2p} \\wedge \\frac{2}{m+M}, \\quad hN \\geq \\frac{1}{m} \\log \\left( \\frac{2(\\norm{x_0-y}_2^2+p/m)^{1/2}}{\\epsilon} \\right)\n    $$\n    for a precision $\\epsilon$ in $W_2(\\nu_K, \\pi)$.\n\\end{remark}\n\n\\begin{note}\n    In practice, $\\norm{x_0-y}_2$ may be difficult to calculate.  An alternative bound can easily be derived from the strong convexity of $U$ and the fact that $y$ minimises $U$:\n    \\begin{align*}\n        m W_2(\\nu_0, \\pi)^2 &\\leq m \\norm{x_0-y}_2^2 + p\\\\\n        &\\leq 2(f(x_0) - f(y) - \\nabla U(y)^{\\top}(x_0-y) + p\\\\\n        &= 2(f(x_0)-f(y))+p.\n    \\end{align*}\n    If $U$ is bounded below by a constant, say $U \\geq 0$, this provides an easily computable upper bound on $W_2(\\nu_0, \\pi)$.\n\\end{note}\n\n\\subsubsection{Numerical Tests}\nDespite the `user-friendly' nature of the bounds in Wasserstein distance, it was not possible to verify them numerically, as computing the $W_2$ distance is computationally infeasible.  This problem is explained in more detail in section \\ref{sec:Imp}.  We were, however, able to test the bounds in total variation.  The only distribution we have implemented which satisfies the assumptions above was the Gaussian.  For the following results, we test on a 1-dimensional $N(0,1)$ distribution.\n\n\\begin{figure}[H]\n\t\\centering\n\t\t\\includegraphics[height=0.35\\textheight]{WriteUp/DM_Pih.pdf}\n\t\\caption{Bound in $\\norm{\\pi_h - \\pi}_{TV}$ as function of $h$.  This bound can be used to select a suitable step size to give error $\\epsilon/2$}\n\t\\label{fig:DM_Pih}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\t\\includegraphics[height=0.35\\textheight]{WriteUp/DM_EM_step0pt01.pdf}\n\t\\caption{Bound in $\\norm{\\pi_h - \\nu_N}_{TV}$ as function of $N$, for $h=0.01$.  Having chosen a suitable $h$ according to the bound above, a suitable $N$ can be chosen to give error $\\epsilon/2$}\n\t\\label{fig:DM_Pih}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\t\\includegraphics[height=0.35\\textheight]{Figures/DM_plot_nth_sample.png}\n\t\\caption{$\\norm{\\pi - \\nu_N}_{TV}$ as function of $N$, plotted against theoretical bounds.  The experiment was run with 600 chains, to produce a histogram with 80 bins.  This number of chains is insufficient to calculate the total variation to a higher level of accuracy, which may explain the difference between our calculated result and the theoretical bound.}\n\t\\label{fig:DMnth}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\t\\includegraphics[height=0.35\\textheight]{Figures/DM_plot_whole_chain.png}\n\t\\caption{Total Variation distance between distribution taken by pooling all $N$ samples from multiple chains and true (standard normal) distribution as function of $N$, plotted against theoretical bounds.  Although the error for the pooled distribution should be worse than that for the $N^{\\text{th}}$ sample, a much higher accuracy is achieved.  This supports our claim that the higher than expected error in the above plot is a result of too few chains being run.}\n\t\\label{fig:DMwhole}\n\\end{figure}", "meta": {"hexsha": "c71b44ef05422eb7dbf41abc7fba55cc68a668c2", "size": 19634, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WriteUp/BeyondMoments.tex", "max_stars_repo_name": "Tom271/LangevinMC", "max_stars_repo_head_hexsha": "ed36a17ce9b7d1e39097aeaf5b92f0fa286d5489", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2019-02-07T12:51:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T13:35:13.000Z", "max_issues_repo_path": "WriteUp/BeyondMoments.tex", "max_issues_repo_name": "swyoon/LangevinMC", "max_issues_repo_head_hexsha": "ed36a17ce9b7d1e39097aeaf5b92f0fa286d5489", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WriteUp/BeyondMoments.tex", "max_forks_repo_name": "swyoon/LangevinMC", "max_forks_repo_head_hexsha": "ed36a17ce9b7d1e39097aeaf5b92f0fa286d5489", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-19T17:44:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-19T17:44:19.000Z", "avg_line_length": 75.2260536398, "max_line_length": 1065, "alphanum_fraction": 0.7247631659, "num_tokens": 6127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.826711776992821, "lm_q2_score": 0.8902942348544447, "lm_q1q2_score": 0.7360167289429819}}
{"text": "% -*- root: Main.tex -*-\n\\section{Essentials}\n\\subsection*{Derivatives}\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{a}^\\top \\mathbf{x}) = \\mathbf{a}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{A} \\mathbf{x}) = \\mathbf{A}^\\top$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{x}^\\top \\mathbf{A}) = \\mathbf{A}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{x}^\\top \\mathbf{x}) = 2\\mathbf{x}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{x}^\\top \\mathbf{A}\\mathbf{x}) = (\\mathbf{A} + \\mathbf{A}^\\top)\\mathbf{x}$ \\\\\n$\\frac{\\partial}{\\partial \\mathbf{X}}(\\mathbf{c}^\\top \\mathbf{X} \\mathbf{b}) = \\mathbf{c}\\mathbf{b}^\\top$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{X}}(\\mathbf{c}^\\top \\mathbf{X}^\\top \\mathbf{b}) = \\mathbf{b}\\mathbf{c}^\\top$ \\\\\n$\\frac{\\partial}{\\partial \\mathbf{X}}(\\|\\mathbf{X}\\|_F^2) = 2\\mathbf{X}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{X}}(log(det(\\mathbf{X}))) = \\mathbf{(X^\\top)^{-1}}$\\\\\n$\\frac{\\partial}{\\partial \\mathbf{a}}(\\mathbf{(x-a)^\\top W(x-a)}) = -2\\mathbf{W(x-a)}$ \\\\\n$\\frac{\\partial}{\\partial \\mathbf{X}}(\\mathbf{a^\\top X^{-1}b}) = \\mathbf{-(X^\\top)^{-1}ab^\\top(X^\\top)^{-1}}$ \\\\\n$\\frac{\\partial}{\\partial \\mathbf{X}}(Tr(\\mathbf{AX})) = \\frac{\\partial}{\\partial \\mathbf{X}}(Tr(\\mathbf{XA})) = \\mathbf{A^\\top}$ \\\\\n$\\frac{\\partial}{\\partial \\mathbf{X}}(Tr(\\mathbf{AX^\\top})) = \\frac{\\partial}{\\partial \\mathbf{X}}(Tr(\\mathbf{X^\\top A})) = \\mathbf{A}$ \\\\\n$\\frac{\\partial}{\\partial \\mathbf{X}}(Tr(\\mathbf{X^\\top AX})) = \\mathbf{(A+A^\\top)X}$ \\\\ \n\n\\subsection*{Jacobian}\n$J_F= \\begin{bmatrix} \\nabla_x^\\top F_1\\\\...\\\\\\nabla_x^\\top F_m\\end{bmatrix}$ where $F:\\mathbb{R}^n \\rightarrow \\mathbb{R}^m$ for $x \\in \\mathbb{R}^n$\n\n\\subsection*{LinAlg}\n$\\bullet$ A is \\textbf{psd} if $v^\\top Av \\geq 0$, note: if $A=B^\\top B$ then $A$ is psd, psd $\\Leftrightarrow \\lambda \\geq 0$ \\\\\n$\\bullet$ \\textbf{orthogonal matrix}: $U^\\top U = UU^\\top = \\mathbb{1}$ \\\\\n1.unit length columns/rows 2.orthogonal columns/rows 3. square matrix \\\\\nproperties: preserve norm $\\|Ux\\|_2^2 = \\|x\\|_2^2$, $det(U) = \\pm1$, full rank because invertible.\\\\\n$\\bullet$ $\\langle \\mathbf{x}, \\mathbf{y} \\rangle = \\|\\mathbf{x}\\|_2 \\cdot \\|\\mathbf{y}\\|_2 \\cdot \\cos(\\theta)$ \\\\\n$\\bullet$ \\textbf{spectral theorem}: Matrix $A$ is diagonalizable by orthogonal matrix iff $A$ is symmetric. \\\\\n$\\bullet$ $A$ is degenerate/non-invertible $\\Leftrightarrow det(A)=0$. \\\\\n$\\bullet$ \\textbf{rank-nullity theorem}: $dim(kernel(A))+dim(range(A)) = n$ where $n$ is input dimension.\n$\\bullet$ \\textbf{determinant}: $det(diag(a_1,...,a_n))=a_1*...*a_n$ \\quad $det(\\begin{bmatrix}a & b \\\\c&d\\end{bmatrix})=ad-bc$ \\\\\n$\\bullet$ \\textbf{cauchy-schwarz}: $x^\\top y \\leq \\|x\\|_2 \\|y\\|_2$ \\\\\n$\\bullet$ \\textbf{trace} of a matrix is equal to the sum of its eigenvalues. Trace operator is linear and cyclic. \\\\\n$\\bullet$ eigenvectors corresponding to distinct eigenvalues of a symmetric matrix are orthogonal to each other. \\\\\n$\\bullet$ a function is convex iff its Hessian $\\nabla^2$ is psd.\\\\\n$\\bullet$ $f$ convex $\\Leftrightarrow \\forall \\lambda \\in [0,1], x,y \\in X. f(\\lambda x + (1- \\lambda)y) \\leq \\lambda f(x) + (1 - \\lambda) f(y)$\\\\\n$\\bullet$ \\textbf{jensens inequality}: $E[f(X)] \\geq f(E[X])$ for $f$ convex ($\\leq$ for $f$ concave). \\\\\n\n\\subsection*{Eigendecomposition}\n$\\Sigma = U\\Lambda U^\\top$ where $\\Lambda=diag(\\lambda_1,...,\\lambda_m)$ with eigenvalues $\\lambda_1 \\geq...\\geq\\lambda_m$, $U=(u_1|...|u_m)$ eigenvectors orthogonal. Only exists if $\\Sigma$ is symmetric.\n\n\\subsection*{Eigenvalue / -vectors}\nEigenvalue Problem: $\\mathbf{Ax} = \\lambda \\mathbf{x}$\\\\\n1. solve $\\operatorname{det}(\\mathbf{A} - \\lambda \\mathbb{1}) \\overset{!}{=} 0$ resulting in $\\{\\lambda_i\\}_i$\\\\\n2. $\\forall \\lambda_i$:\nsolve $(\\mathbf{A} - \\lambda_i \\mathbb{1}) \\mathbf{x}_i = \\mathbf{0}$, for $\\mathbf{x}_i$.\n\n\\subsection*{Norms}\n$\\|\\mathbf{A}\\|_F =\\allowbreak \\sqrt{\\sum_{i=1}^{m} \\sum_{j=1}^{n}\\mathbf{a}_{i,j}^2} = \\sqrt{trace(A^\\top A)} = \\sqrt{trace(AA^\\top)} =\\allowbreak \\sqrt{\\sum_{i=1}^{\\min\\{m, n\\}} \\sigma_i^2}$\\\\\n$\\|\\mathbf{A}\\|_2 = sup\\{\\|Ax\\|: \\|x\\|=1\\} = \\sigma_1$ \\\\\n$\\|\\mathbf{M}\\|_\\star = \\sum_{i=1}^{\\min(m, n)} \\sigma_i$\n\n\\subsection*{Probability / Statistics}\n\\begin{inparaitem}\n\t\\item $Var(X)=E[(X-\\mu)^2]$\n\t\\item sample variance: $\\frac{1}{N}\\sum_{i=1}^{N}(x_i-\\bar{x})^2$\n\\end{inparaitem}", "meta": {"hexsha": "13c77ceba53c98457ac79bd80d8e3aec4a744dc0", "size": 4300, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Essentials.tex", "max_stars_repo_name": "florianmorath/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-19T15:10:37.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-19T15:10:37.000Z", "max_issues_repo_path": "Essentials.tex", "max_issues_repo_name": "florianmorath/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Essentials.tex", "max_forks_repo_name": "florianmorath/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 75.4385964912, "max_line_length": 204, "alphanum_fraction": 0.6262790698, "num_tokens": 1714, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7359996840529908}}
{"text": "\\lab{Algorithms}{Numerical Derivatives}{Numerical Derivatives}\n\\label{Ch:Numerical Derivatives}\n\n\\objective{Understand and implement finite difference approximations of the derivative. Then explore Image Filters. In particular, we will explore the Sobel Filter, which uses \nnumerical derivatives to find edges in images.}\n\n\\section*{One Dimension}\n\nThe derivative of a function at a point is formally defined as\n\n\\begin{equation}\n\\label{eqn:deriv}\nf'(x) = \\lim_{h\\rightarrow 0} \\frac{f(x + h)-f(x)}{h}.\n\\end{equation}\n\nIn most real world applications we will be solving problems using computers. How does a computer calculate a limit? In short it can't. Computers can only approximate functions at specific points, and the notion of a limit graces infinity in a way that a computer never can.\n\nSo how can we use a computer to find the derivative of a function, particularly when we can't differentiate the function by hand? We use methods known as finite difference methods. For example suppose that in equation \\ref{eqn:deriv}, instead of taking a limit we just pick a particularly small value for h. Then we have\n\n\\begin{equation*}\nf'(x) \\approx \\frac{f(x + h)-f(x)}{h}\n\\end{equation*}\n\nThis is known as the first order forward difference approximation of the derivative.\n\nHow do we know the quality of this approximation? We can use Taylor's formula to find\n\n\\begin{equation*}\nf(x_0 + h) = f(x_0) + hf'(x_0) + h^2/2 f''(\\xi),\\hspace{5mm} \\xi \\in (x_0,x_0 + h)\n\\end{equation*}\n\nWhich can be also expressed as\n\n\\begin{equation*}\nf'(x_0) = \\frac{f(x_0 + h) - f(x)}{h} + \\frac{h}{2}f''(\\xi) = \\frac{f(x_0 + h) - f(x)}{h} + O(h)\n\\end{equation*}\n\nHere we use the big-O notation to denote that the errors are bounded by some constant multiplied by $h$.\n\nWe can use Taylor expansions to find approximations that have different big-O error bounds, up to any polynomial of arbitrary degree. Tables \\ref{Table:CDiff} and \\ref{Table:FDiff} offer the coefficients for centered and forward difference schemes.\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|c|c|c|c|c|c|c|c|c|}\n\\hline\nDerivative & Accuracy & -3 & -2 & -1 & 0 & 1 & 2 & 3 \\\\ \\hline\n & 2 & & & -1/2 & 0 & 1/2 & & \\\\ \\cline{2-9}\n 1 & 4 & & 1/12 & -2/3 &  0 & 2/3 & -1/12 & \\\\ \\cline{2-9}\n  & 6 & -1/60 & 3/20 & -3/4 & 0 & 3/4 & -3/20 & 1/60 \\\\ \\hline\n  & 2 & & & 1 & -2 & 1 & & \\\\ \\cline{2-9}\n 2 & 4 & & -1/12 & 4/3 &  -5/2 & 4/3 & -1/12 & \\\\ \\cline{2-9}\n  & 6 & 1/90 & -3/20 & 3/2 & -49/18 & 3/2 & -3/20 & 1/90 \\\\ \\hline\n\\end{tabular}\n\\caption{Centered Difference Coefficients}\n\\label{Table:CDiff}\n\\end{center}\n\\end{table}\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|c|c|c|c|c|c|c|}\n\\hline\nDerivative & Accuracy & 0 & 1 & 2 & 3 & 4 \\\\ \\hline\n & 1 & -1 & 1 &  & &  \\\\ \\cline{2-7}\n 1 & 2 & -3/2 & 2 & -1/2 & &  \\\\ \\cline{2-7}\n  & 3 & -11/6 & 3 & -3/2 & 1/3 &  \\\\ \\hline\n  & 1 & 1 & -2 & 1 &  & \\\\ \\cline{2-7}\n 2 & 2 & 2 & -5 & 4 &  -1 &  \\\\ \\cline{2-7}\n  & 3 & 35/12 & -26/3 & 19/2 & -14/3 & 11/12 \\\\ \\hline\n\\end{tabular}\n\\caption{Forward Difference Coefficients}\n\\label{Table:FDiff}\n\\end{center}\n\\end{table}\n\nThese tables can be used by simply summing the function evaluations (the number at the top represents how many times $h$ is added to $x$), and then dividing by $h^n$, where $n$ is the degree of the derivative.\n\nSo, for example, the centered difference estimate of the second derivative that is $O(h^4)$ is\n\\begin{equation*}\nf''(x) \\approx \\frac{-1/12(f(x-2h) + f(x+2h)) + 4/3(f(x-h) + f(x+h)) -5/2f(x)}{h^2}\n\\end{equation*}\n\nOr, the forward difference estimate for the first derivative that is $O(h^2)$ is\n\n\\begin{equation*}\nf'(x) \\approx \\frac{-3/2f(x) + 2f(x+h) - 1/2 f(x+2h)}{h}\n\\end{equation*}\n\nIt should be noted that we can convert a forward difference estimate to a backwards difference estimate by using $-h$. So the backwards difference estimate for the first derivative that is $O(h^2)$ is\n\n\\begin{equation*}\nf'(x) \\approx \\frac{3/2f(x) - 2f(x-h) + 1/2 f(x-2h)}{h}\n\\end{equation*}\n\nThere are two important observations that you should make about these tables. First, in order to get higher order approximations we need to evaluate the function at more points. This should not be surprising. Second, you should notice that centered difference formulas require less function evaluations to get higher order approximations. However, in certain applications it is not possible to use centered difference formulas, so the backwards and forwards formulas are still very applicable.\n\nOne important aspect of this method is selecting an appropriate $h$. The natural temptation is to pick a very very small value. However, this is not always advisable. Note the values in table \\ref{Table:FloatingError}, which approximates the derivative of $e(x)$ at $x = 1$:\n\n\\begin{table}[h!]\n\\begin{center}\n\\begin{tabular}{|cc|}\n\\hline\nh & Error  = $|f'(1)-f'_{app}(1)|$ \\\\ \\hline\n1e-1 & 4.5e-3 \\\\\n1e-3 & 4.5305e-7 \\\\\n1e-7 & 5.8587e-11 \\\\\n1e-10 & 6.7274e-7 \\\\ \\hline\n\\end{tabular}\n\\caption{Error in numerical derivative, using double precision floating point arithmetic}\n\\label{Table:FloatingError}\n\\end{center}\n\\end{table}\n\nAs you can see, the error actually increases as $h$ becomes very small. Why is this? Division by small numbers causes errors in floating point arithmetic. So, be aware that usually the optimal $h$ is of moderately small size. However, in the framework of double floating point arithmetic, this is usually less of a concern.\n\nAs a matter of reference, calculating numerical derivatives is an unstable operation. An unstable operation, informally, is one where errors are magnified by the operation. This usually is not an issue, but it's important to know that taking derivatives can amplify errors.\n\n\\begin{problem}\nWrite a function \\li{numDer1} that accepts as inputs: a callable function object \\li{f} and\na keyword argument \\li{h} giving the step size (default \\li{h = 1e-5}). Have the function return an array of the approximate 1st order derivative with accuracy 1 of \\li{f} at each of the points in \\li{pts}, using the centered  coefficients.\n\\end{problem}\n\n\\begin{problem}\nWrite a function \\li{numDer2} that accepts as inputs: a callable function object \\li{f} and\na keyword argument \\li{h} giving the step size (default \\li{h = 1e-5}). Have the function return an array of the approximate 2nd order derivative with accuracy 1 of \\li{f} at each of the points in \\li{pts}, using the centered  coefficients.\n\\end{problem}\n\n\\begin{comment}\n\\begin{problem}\nWrite a function \\li{numDer} that accepts as inputs: a callable function object \\li{f}, an\narray of numbers \\li{pts}, a keyword argument \\li{mode} (taking one of the values \n\\li{'centered'}, \\li{'forward'}, or \\li{'backward'}), a keyword argument \\li{d} (taking one of \nthe values \\li{1} or \\li{2}), a keyword argument \\li{o} (taking an integer value in \n\\li{[2, 4, 6]} if \\li{mode = 'centered'}, and otherwise taking a value in \\li{[1, 2, 3]}), and\na keyword argument \\li{h} giving the step size. The default settings of the keyword\narguments should be \\li{mode = 'centered', d = 1, o = 2, h = 1e-5}.\n \nHave the function return an array of the approximate derivative of order \\li{d} with accuracy\n \\li{o} of \\li{f} at each of the points in \\li{pts}, using the coefficients indicated by \\li{mode}.\n\\end{problem}\n\\end{comment}\n\nWe note that higher order approximations of the derivative can be derived using the Taylor series and Lagrange polynomials, but generally higher-order approximations are not practically useful as they can often be ill-conditioned.\n\nFor any numerical approximation method, it is important to be able to empirically calculate\nthe order of convergence. We will do so for our numerical derivative approximation. \nFor an $m$-th order approximation of the first derivative, we have that the error is in\n$O(h^m)$, so that\n$$\nerr(h) \\approx Ch^m\n$$\nfor some constant $C$.\nHence, taking the log of both sides, we obtain\n$$\n\\log err(h) \\approx \\log C + m\\log h,\n$$\nwhich means that if we plot the log of the errors against the log of the $h$ values, we \nought to see a linear relationship whose slope gives the rate of convergence. \n\nWe do this in python as follows (The \\li{numDer} function in this code can use any of the coefficients from \\ref{Table:CDiff} and \\ref{Table:FDiff}):\n\\begin{lstlisting}\n# assume that the function numDer has already been written\nimport numpy as np\nfrom matplotlib import pyplot as plt\n\n# approximate the derivative of cosine at x = 3\n# create a callable function object\ndef myCosine(x):\n    return np.cos(x)\nf = myCosine\n\n# calculate the actual derivative\nactual = -np.sin(3.0)\n\n# initialize array of h values at which to calculate the error\nhvals = np.linspace(1e-5, 1e-1)\nerr1 = np.zeros(hvals.shape)\nerr2 = np.zeros(hvals.shape)\n\n# calculate the errors for order 1 and order 2 approximations for the forward coeffiects\nfor i in xrange(len(hvals)):\n    err1[i] = np.abs(actual - numDer(f, np.array([3.0]), mode = 'forward', h = hvals[i], o=1))\n    err2[i] = np.abs(actual - numDer(f, np.array([3.0]), mode = 'forward', h = hvals[i], o=2))\n\n# plot the log of the h values against the log of the errors\nplt.subplot(121)\nplt.loglog(hvals, err1)\nplt.ylim((1e-11, 1e-1))\nplt.subplot(122)\nplt.loglog(hvals, err2)\nplt.ylim((1e-11, 1e-1))\nplt.show()\n\\end{lstlisting}\n\nThe generated plot is shown in Figure \\ref{fig:convergence}. Note that the slope\nof the line in the left plot is about 1, and the slope of the line in the right\nplot is about 2. Further, the log of the errors for the order 2 approximations\nare much lower than the log of the errors of the order 1 approximations.\n\n\\begin{figure}[t]\n    \\includegraphics[width=0.8\\textwidth]{convergence.pdf}\n    \\caption{Convergence plots for our numerical derivative approximations.\n    The left plot shows the convergence for order 1 approximations. \n    The right plot shows the convergence for order 2 approximations.}\n    \\label{fig:convergence}\n\\end{figure}\n\n\\begin{comment}\n\\begin{problem}\nExplore the convergence properties for different orders of approximation,\nand for the second derivative as well. You may need to adjust your $h$\nvalues, as they may be too small for some of the calculations.\n\\end{problem}\n\\end{comment}\n\n\\section*{Multi Dimensions}\n\nThe Jacobian is a generalization of the derivative in many dimensions. We can think of it, \nintuitively, as defining a linear approximation to the function in a neighborhood of some given\npoint. If the function happens to be real-valued, the Jacobian defines a tangent plane to the graph of \nthe function at a point. \nThe Jacobian is of critical importance in a variety of areas, and we will use it in lab \\ref{lab:NewtonsMethod}\nto find zeros of multivariate functions.\n\nFormally, the Jacobian of a function $f:\\mathbb{R}^n \\rightarrow \\mathbb{R}^m$ is an $m \\times n$ matrix. It is defined by the formula:\n\\begin{equation*}\nJ_{ij} = \\frac{\\partial f_i}{\\partial x_j}\n\\end{equation*}\n\nWe can use finite difference approximations to find partial derivatives in the natural manner:\n\\begin{equation*}\n\\frac{\\partial f}{\\partial x_i} (x) \\approx \\frac{f(x+h e_i)-f(x)}{h}\n\\end{equation*}\nwhere $e_i$ is a unit vector in the $i$th coordinate (the direction $x_i$). Higher order approximations and centered and backwards differences follow by naturally extending this definition.\n\n\\begin{problem}\nWrite a function \\li{Jacobian} that accepts a function handle, an integer giving the dimension of the\nrange of the function, an integer giving the dimension of the domain of the function, a NumPy array giving\nthe point at which to approximate the Jacobian, and an optional argument giving the step size $h$. Use center approximation of order 1.\nReturn a NumPy array giving the approximated Jacobian matrix at the given point.\n\nIf the function under consideration maps from $\\mathbb{R}^n$ to $\\mathbb{R}^m$, the function handle should\naccept as input an array of shape \\li{(n,)} and return an array of shape \\li{(m,)}.\n\nTest your function on the following $f: \\mathbb{R}^2 \\to \\mathbb{R}^2$:\n\\begin{equation*}\nf(x, y) =\n\\begin{pmatrix}\ne^{x} \\sin(y) + y^3 \\\\\n3y - \\cos(x)\n\\end{pmatrix}\n\\end{equation*}\n\nCompare your \\li{Jacobian} function against the analytically computed derivative on the square $[-1,1] \\times [-1,1]$ using ten thousand grid points (100 per side). Which method is faster? What is the maximum error of your function?\n\\end{problem}\n\nGiven a function from $\\mathbb{R}^n \\to \\mathbb{R}$, sometimes the mixed partial derivatives are useful. In particular, the mixed partials will be useful when we study optimization in Volume 2. This information is contained in the Hessian matrix, which is defined as\n\n\\begin{equation*}\nH_{ij} = \\frac{\\partial^2 f}{\\partial x_i \\partial x_j}\n\\end{equation*}\n\nWe can use the following formula to approximate mixed partial derivatives\n\\small\n\\begin{equation*}\n\\frac{\\partial^2 f}{\\partial x_i \\partial x_j} = \\frac{f(x + (e_i + e_j)h) - f(x + (e_i-e_j)h) -f(x + (e_j-e_i)h) + f(x - (e_i + e_j)h)}{4h^2}\n\\end{equation*}\n\\normalsize\n\n\\begin{problem}\nWrite a Python function that numerically calculates the Hessian of a given function. \nThe function should be named \\li{Hessian}, and should accept as inputs a function handle, \nan integer giving the dimension of the domain of the function, a NumPy \narray giving the point at which to approximate the Hessian, and an optional argument giving the \nstep size.\nReturn the approximated Hessian matrix at the given point.\n\nTest it on the following function\n\\begin{equation*}\nf(x,y) = (1-x)^2 + 100(y-x^2)^2\n\\end{equation*}\nThis function is known as the Rosenbrock Banana function, or Rosenbrock's Valley. It is a common test function for optimization algorithms because it is non-convex and the global minimum is hard to find from certain starting points. A graph is shown in figure \\ref{Fig:Rosenbrock}. Compare the output of your function with the analytic solution on the region $[-2,2] \\times [0,2]$, using ten thousand points. What is the maximum error of your function?\n\\end{problem}\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width = \\textwidth]{Rosenbrock}\n\\caption{The Rosenbrock Banana Function, a common test function in optimization algorithms}\n\\label{Fig:Rosenbrock}\n\\end{center}\n\\end{figure}\n\n\\section*{Application: Image Filters}\nOne of the primary tools in image processing is the use of filters to identify important information \nin images. In this section we will implement our own filters and explore applications.\n\nOne of the easiest filters to implement is matrix based. In this implementation, the filter that we \nselect is a matrix, which represents how much we want certain pixels to contribute to the output image. \nSuppose that we choose our filter to be:\n\n\\[\nA = \\begin{pmatrix}\na_{-1,-1}&a_{-1,0}&a_{-1,1}\\\\\na_{0,-1}&a_{0,0}&a_{0,1}\\\\\na_{1,-1}&a_{1,0}&a_{1,1}\n\\end{pmatrix}.\n\\]\n\nWe will call our input image $B$ and our output image $C$ (both images are represented as matrices).\nOur matrix filter operates according to the following formula:\n\\[\nC_{ij} = \\sum_{k=-1}^1 \\sum_{m=-1}^1 a_{km}B_{i+k,j+m}.\n\\]\n\nEssentially this computes each pixel of the output image as the weighted sum of the surrounding\npixels in the input image. The technical term for this type of operation is a convolution.\n\nSuppose that our image $B$ is an $m\\times n$ matrix. Note that the definition for\n$C_{ij}$ given above does not make sense when $i = 0, m-1$ or $j = 0, n-1$, since we would be trying\nto access matrix elements $B_{-1,j}, B_{m,j}, B_{i,-1},$ or $B_{i,n}$, which are out of bounds.\n%One fix is to treat these out-of-bounds elements as copies of the nearest in-bounds element.\n%That is, define\n%\\begin{align*}\n%B_{-1,j} &:= B_{0,j},\\\\\n%B_{m,j} &:= B_{m-1,j},\\\\\n%B_{i,-1} &:= B_{i,0},\\\\\n%B_{i,n} &:= B_{i,n-1}.\n%\\end{align*}\n%For the corners, define\n%\\begin{align*}\n%B_{-1,-1} &:=B_{0,0},\\\\\n%B_{m,-1}&:= B_{m-1,0},\\\\\n%B_{-1,n}&:=B_{0,n-1},\\\\\n%B_{m,n}&:=B_{m-1,n-1}.\n%\\end{align*}\nOne fix is to assign the value of 0 to these out-of-bounds elements. This process is know as \\emph{padding}\nthe image with zeros. The amount of padding necessary is dependent on the size of the filter.\nIn the following code, we create a padded version of the image $B$ with respect to a filter $f$ of shape \n$h\\times k$, where we assume that $h$ and $k$ are odd integers.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> # assume that the matrix B and filter f already exist.\n>>> # create padded version of B.\n>>> m, n = B.shape\n>>> h, k = f.shape\n>>> B_pad = np.zeros((m + h - 1, n + k - 1))\n>>> B_pad[h/2:h/2 + m, k/2:k/2 + n] = B\n\\end{lstlisting}\n\nWe can now easily calculate a given element of the filtered image $C$ as follows:\n\\begin{lstlisting}\n>>> C[i,j] = (f*B_pad[i:i + h, j:j + k]).sum()\n\\end{lstlisting}\n\nMake sure that you understand why this Python code does what we want it to do.\n\\begin{problem}\nWrite a function \\li{Filter} that takes an image and an arbitrary filter matrix, and outputs the\nfiltered image. Note that for these filters to be meaningful, the number of columns and number \nof rows need to be odd (there are ways to deal with even size filters, but we won't handle them here).\n\\end{problem}\n\nSo what can we do with these filters? We will show an example of how to apply a Gaussian blur \nusing this type of filter. You will also be able to test your code with this example. \nTo begin, load the following picture:\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from matplotlib import pyplot as plt\n>>> K = plt.imread('cameraman.tif')\n>>> plt.imshow(K, cmap = plt.cm.Greys_r)\n>>> plt.show()\n\\end{lstlisting}\n\nThis code should display an image like the one shown in Figure \\ref{imfil:camclean} (provided\nthat you have the correct image file, of course).\n\n\\begin{figure}\n\\includegraphics{cameramanClean.pdf}\n\\caption{An example image.}\n\\label{imfil:camclean}\n\\end{figure}\n\nNow that you have a simple filter function, try the following filter on this image:\n\n\\[\nA = \\frac{1}{159}\\begin{pmatrix}\n2&4&5&4&2\\\\\n4&9&12&9&4\\\\\n5&12&15&12&5\\\\\n4&9&12&9&4\\\\\n2&4&5&4&2\n\\end{pmatrix}\n\\]\n\n\\begin{lstlisting}\n>>> A = np.array([[2,4,5,4,2],\n                 [4,9,12,9,4],\n                 [5,12,15,12,5],\n                 [4,9,12,9,4],\n                 [2,4,5,4,2]])/159.\n>>> C = Filter(K, A)\n>>> plt.imshow(C, cmap = plt.cm.Greys_r)\n>>> plt.show()\n\\end{lstlisting}\nYou should get an output that looks something like Figure \\ref{imfil:camblur}.\n\\begin{figure}\n\\includegraphics{cameramanBlur.pdf}\n\\caption{A blurred version of Figure \\ref{imfil:camclean}.}\n\\label{imfil:camblur}\n\\end{figure}\nYou can see that the filter blurred the image. This can be very important in trying to \nwash out images that are ``noisy.''\n\nWe now turn our attention to the problem of edge detection. Automatically detecting edges in an image\ncan be useful in segmenting the image, detecting and extracting certain features in the image, and\nsharpening contrast in the image. There are many approaches to this problem, and in this lab, we will\ndesign a filter that numerically approximates the gradient of the image at each pixel. The magnitude\nof the gradient tells us the local rate of change of the pixel values, and so large magnitudes \ncorrespond to regions of high contrast in the image. Since there is high contrast at edges within\nthe image, we have reason to hope that this approach will be effective.\n\nThe filter we will use is called the \\emph{Sobel Filter}. To find the gradient \nin the vertical direction, the filter is given by:\n\\[\nA = \\frac{1}{8}\\begin{pmatrix}\n-1&-2&-1\\\\\n0&0&0\\\\\n1&2&1\n\\end{pmatrix}\n\\]\nThe filter for the horizontal gradient is simply the transpose of the above matrix.\n\nFor an image $B$, suppose that filtered images using the Sobel filter in the vertical and\nhorizontal directions are given by $B_y$ and $B_x$, respectively. These two matrices give\nthe $y$ and $x$ components of the gradient, respectively, at each pixel. To obtain the \nmagnitude of the gradient (i.e. the length of the gradient vector), we use the formula\n$$\nB_{grad} = \\sqrt{B_x^2 + B_y^2},\n$$\nwhere the square root and squaring operations are performed pointwise on the matrices. \nThe matrix $B_{grad}$ now gives the magnitude of the gradient at each pixel, and so we\ncan threshold this matrix to isolate the pixels with the largest gradient, setting all \nother pixel values to 0. \nIn Python, this can be done as follows:\n\\begin{lstlisting}\n>>> B_edges = B_grad > thresh\n\\end{lstlisting}\nwhere \\li{thresh} is some positive threshold value of our choosing. In general, a reasonable\nvalue for this threshold is $4\\mu(B_{grad})$, where $\\mu(B_{grad})$ is the mean value of the \nmatrix $B_{grad}$.\nIf we now plot the matrix \\li{B_edges}, we will see a black-and-white image with the edges \nshown as white lines.\n\n\\begin{problem}\nWrite a function \\li{plotEdges} that finds and plots the edges of an image using the Sobel filter.\nThe function should take an image, and the last line of code should be a call \nto \\li{plt.show}. The function should not return anything. For your threshold value, use the \nsuggestion given above.\n\nFor the cameraman example, you should obtain an output similar to that displayed in \nFigure \\ref{imfil:edges}.\n\\end{problem}\n\n\\begin{figure}[h!]\n\\includegraphics{edges.pdf}\n\\caption{A filtered version of Figure \\ref{imfil:camclean}.}\n\\label{imfil:edges}\n\\end{figure}\n\n\n", "meta": {"hexsha": "3b4742e07012ca0c12f16e20be26609dcb6a6422", "size": 21258, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/NumDeriv/FiniteDiff.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/NumDeriv/FiniteDiff.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/NumDeriv/FiniteDiff.tex", "max_forks_repo_name": "lcbendall/numerical_computing", "max_forks_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.1337579618, "max_line_length": 493, "alphanum_fraction": 0.7226455922, "num_tokens": 6256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.8807970889295663, "lm_q1q2_score": 0.7358914601131727}}
{"text": "\\section{Maxima and Minima}\\label{sec:MultivariateMaximaMinima}\n\nSuppose a surface given by $f(x,y)$ has a local maximum at\n$(x_0,y_0,z_0)$; geometrically, this point on the surface looks like\nthe top of a hill. If we look at the cross-section in the plane\n$y=y_0$, we will see a local maximum on the curve at $(x_0,z_0)$, and\nwe know from single-variable calculus that ${\\partial z\\over\\partial x}=0$\nat this point. Likewise, in the plane $x=x_0$, ${\\partial\n  z\\over\\partial y}=0$. So if there is a local maximum at\n$(x_0,y_0,z_0)$, both partial derivatives at the point must be zero,\nand likewise for a local minimum. Thus, to find local maximum and\nminimum points, we need only consider those points at which both\npartial derivatives are 0. As in the single-variable case, it is\npossible for the derivatives to be 0 at a point that is neither a\nmaximum or a minimum, so we need to test these points further.\n\nYou will recall that in the single variable case, we examined three\nmethods to identify maximum and minimum points; the most useful is the\nsecond derivative test, though it does not always work. For functions\nof two variables there is also a second derivative test; again it is\nby far the most useful test, though it doesn't always work.\n\n\\begin{theorem}{Extrema Test for Multivariate Functions}{}\nSuppose that the second partial derivatives of $f(x,y)$ are\ncontinuous near $(x_0,y_0)$, and $f_x(x_0,y_0)=f_y(x_0,y_0)=0$.\nWe denote by $D$ the \\dfont{discriminant}\\index{discriminant}\n$D(x_0,y_0)=f_{xx}(x_0,y_0)f_{yy}(x_0,y_0)-f_{xy}(x_0,y_0)^2$.\nIf $D>0$ and $f_{xx}(x_0,y_0)<0$ there is a local maximum at $(x_0,y_0)$;\nif $D>0$ and $f_{xx}(x_0,y_0)>0$ there is a local minimum at $(x_0,y_0)$;\nif $D<0$ there is neither a maximum nor a minimum at $(x_0,y_0)$;\nif $D=0$, the test fails.\\index{local extrema!multivariate}\n\\end{theorem}\n\n\\begin{example}{Extrema on an Elliptic Paraboloid}{}\nVerify that $f(x,y)=x^2+y^2$ has a minimum at $(0,0)$.\n\\end{example}\n\\begin{solution}\nFirst, we compute all the needed derivatives:\n$$f_x=2x \\qquad f_y=2y \\qquad f_{xx}=2 \\qquad f_{yy}=2 \\qquad\nf_{xy}=0.$$\nThe derivatives $f_x$ and $f_y$ are zero only at $(0,0)$. Applying the\nsecond derivative test there:\n$$D(0,0)=f_{xx}(0,0)f_{yy}(0,0)-f_{xy}(0,0)^2=\n2\\cdot2-0=4>0,$$\nso there is a local minimum at $(0,0)$, and there are no other\npossibilities. \n\\end{solution}\n\n\\begin{example}{Extrema on a Hyperbolic Paraboloid}{}\nFind all local maxima and minima for $f(x,y)=x^2-y^2$.\n\\end{example}\n\\begin{solution}\nThe derivatives:\n$$f_x=2x \\qquad f_y=-2y \\qquad f_{xx}=2 \\qquad f_{yy}=-2 \\qquad\nf_{xy}=0.$$\nAgain there is a single critical point, at $(0,0)$, and\n$$D(0,0)=f_{xx}(0,0)f_{yy}(0,0)-f_{xy}(0,0)^2=\n2\\cdot-2-0=-4<0,$$\nso there is neither a maximum nor minimum there, and so there are no\nlocal maxima or minima. The surface is shown in\nFigure~\\ref{fig:saddle}. \n\\end{solution}\n\n\\begin{figure}[H]\n%\\texonly\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from -1 to 1, y from 0 to 1\n\\put {\\hbox{\\epsfxsize8cm\\epsfbox{images/saddle.eps}}} at 0 -0.15\n\\endpicture}}\n%\\endtexonly\n\\caption{A saddle point, neither a maximum nor a minimum.}\n\\label{fig:saddle}\n\\end{figure}\n\n\\begin{example}{Finding Extrema}{}\nFind all local maxima and minima for $f(x,y)=x^4+y^4$.\n\\end{example}\n\\begin{solution}\nThe derivatives:\n$$f_x=4x^3 \\qquad f_y=4y^3 \\qquad f_{xx}=12x^2 \\qquad f_{yy}=12y^2 \\qquad\nf_{xy}=0.$$\nAgain there is a single critical point, at $(0,0)$, and\n$$D(0,0)=f_{xx}(0,0)f_{yy}(0,0)-f_{xy}(0,0)^2=\n0\\cdot0-0=0,$$\nso we get no information. However, in this case it is easy to see that\nthere is a minimum at $(0,0)$, because $f(0,0)=0$ and\nat all other points $f(x,y)>0$.\n\\end{solution}\n\n\\begin{example}{Finding Extrema}{}\nFind all local maxima and minima for $f(x,y)=x^3+y^3$.\n\\end{example}\n\\begin{solution}\nThe derivatives:\n$$f_x=3x^2 \\qquad f_y=3y^2 \\qquad f_{xx}=6x^2 \\qquad f_{yy}=6y^2 \\qquad\nf_{xy}=0.$$\nAgain there is a single critical point, at $(0,0)$, and\n$$D(0,0)=f_{xx}(0,0)f_{yy}(0,0)-f_{xy}(0,0)^2=\n0\\cdot0-0=0,$$\nso we get no information. In this case, a little thought shows there\nis neither a maximum nor a minimum at $(0,0)$: when $x$ and $y$ are\nboth positive, $f(x,y)>0$, and when $x$ and $y$ are\nboth negative, $f(x,y)<0$, and there are points of both kinds\narbitrarily close to $(0,0)$. Alternately, if we look at the\ncross-section when $y=0$, we get $f(x,0)=x^3$, which does not have\neither a maximum or minimum at $x=0$.\n\\end{solution}\n\n\\begin{example}{Optimizing Dimensions of a Box}{}\nSuppose a box with no top is to hold a certain volume $V$. Find\nthe dimensions for the box that result in the minimum surface area.\n\\end{example}\n\\begin{solution}\nThe area of the box is $A=2hw+2hl+lw$, and the volume is $V=lwh$, so\nwe can write the area as a function of two variables,\n$$A(l,w)={2V\\over l}+{2V\\over w}+lw.$$\nThen\n$$A_l=-{2V\\over l^2}+w \\hbox{\\quad and\\quad} A_w=-{2V\\over w^2}+l.$$\nIf we set these equal to zero and solve, we find\n$\\ds w=(2V)^{1/3}$ and $\\ds l=(2V)^{1/3}$, and the corresponding\nheight is $h=V/(2V)^{2/3}$.\n\nThe second derivatives are\n$$A_{ll}={4V\\over l^3}\\qquad A_{ww}={4V\\over w^3}\\qquad\nA_{lw}=1,$$\nso the discriminant is\n$$D={4V\\over l^3}{4V\\over w^3}-1=4-1=3>0.$$\nSince $A_{ll}$ is 2, there is a local minimum at the critical point.\nIs this a global minimum? It is, but it is difficult to see this\nanalytically; physically and graphically it is clear that there is a\nminimum, in which case it must be at the single critical point. \n%\\texonly\n%%\\expandafter\\url\\expandafter{\\sageurl critical_point_on_surface}Here\\endurl\\ \n%\\expandafter\\url\\expandafter{\\liveurl jmol_surface_minimum}Here\\endurl\\ \n%is the graph as rendered by Sage, as an example.\n%\\endtexonly\n%\\htmlonly\n%Here is the graph as rendered by Sage, as an example.\n%\\endhtmlonly\n%\\htmlfigure{Partial_Differentiation_minimum_point_on_surface.html}\n%Note that we must\n%choose a value for $V$ in order to graph it.\n\\end{solution}\n\nRecall that when we did single variable global maximum and minimum\nproblems, the easiest cases were those for which the variable could be\nlimited to a finite closed interval, for then we simply had to check\nall critical values and the endpoints. The previous example is\ndifficult because there is no finite boundary to the domain of the\nproblem---both $w$ and $l$ can be in $(0,\\infty)$. As in the single\nvariable case, the problem is often simpler when there is a finite\nboundary. \n\n\\begin{theorem}{Multivariate Absolute Extrema}{}\nIf $f(x,y)$ is continuous on a closed and bounded subset of\n$\\R^2$, then it has both a maximum and minimum value.\\index{absolute extrema!multivariate}\n\\end{theorem}\n\nAs in the case of single variable functions, this means that the\nmaximum and minimum values must occur at a critical point or on the\nboundary; in the two variable case, however, the boundary is a curve,\nnot merely two endpoints.\n\n\\begin{example}{Optimizing Volume of a Box}{box diagonal}\nThe length of the diagonal of a box is to be 1 meter; find the\nmaximum possible volume.\n\\end{example}\n\\begin{solution}\nIf the box is placed with one corner at the origin, and sides along\nthe axes, the length of the diagonal is $\\ds\\sqrt{x^2+y^2+z^2}$, and\nthe volume is\n$$V=xyz=xy\\sqrt{1-x^2-y^2}.$$\nClearly, $x^2+y^2\\le 1$, so the domain we are interested in\nis the quarter of the unit disk in the first quadrant.\nComputing derivatives:\n\\begin{align*}\nV_x&={y-2yx^2-y^3\\over\\sqrt{1-x^2-y^2}}\t\\\\\nV_y&={x-2xy^2-x^3\\over\\sqrt{1-x^2-y^2}}\t\\\\\n\\end{align*}\nIf these are both 0, then $x=0$ or $y=0$, or $x=y=1/\\sqrt3$. The boundary of\nthe domain is composed of three curves: $x=0$ for $y\\in[0,1]$; $y=0$\nfor $x\\in[0,1]$; and $x^2+y^2=1$, where $x\\ge0$ and $y\\ge0$. In all\nthree cases, the volume  $xy\\sqrt{1-x^2-y^2}$ is 0, so the maximum\noccurs at the only critical point $(1/\\sqrt3,1/\\sqrt3,1/\\sqrt3)$. See\nFigure~\\ref{fig:max volume}.\n\\end{solution}\n\n\\begin{figure}[H]\n%\\texonly\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from -1 to 1, y from 0 to 1\n\\put {\\hbox{\\epsfxsize8cm\\epsfbox{images/max_volume.eps}}} at 0 0\n\\endpicture}}\n%\\endtexonly\n\\caption{The volume of a box with fixed length diagonal.}\n\\label{fig:max volume}\n\\end{figure}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:MultivariateMaximaMinima}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nFind all local maximum and minimum points of\n$f=x^2+4y^2-2x+8y-1$.\n\\begin{sol}\nminimum at $(1,-1)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all local maximum and minimum points of\n$f=x^2-y^2+6x-10y+2$.\n\\begin{sol}\nnone\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all local maximum and minimum points of\n$f=xy$.\n\\begin{sol}\nnone\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all local maximum and minimum points of\n$f=9+4x-y-2x^2-3y^2$.\n\\begin{sol}\nmaximum at $(1,-1/6)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all local maximum and minimum points of\n$f=x^2+4xy+y^2-6y+1$.\n\\begin{sol}\nnone\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind all local maximum and minimum points of\n$f=x^2-xy+2y^2-5x+6y-9$.\n\\begin{sol}\nminimum at $(2,-1)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the absolute maximum and minimum points of\n$f=x^2+3y-3xy$ over the region bounded by\n$y=x$, $y=0$, and $x=2$.\n\\begin{sol}\n$f(2,2)=-2$, $f(2,0)=4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nA six-sided rectangular box is to hold $1/2$ cubic meter;\nwhat shape should the box be to minimize surface area?\n\\begin{sol}\na cube $1/\\root 3 \\of {2}$ on a side\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nThe post office will accept packages whose combined length\nand girth is at most 130 inches. (Girth is the maximum distance around\nthe package perpendicular to the length; for a rectangular box, the\nlength is the largest of the three dimensions.) What is the largest volume\nthat can be sent in a rectangular box?\n\\begin{sol}\n$65/3\\times 65/3\\times 130/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nThe bottom of a rectangular box costs twice as much per unit\narea as the sides and top. Find the shape for a given volume that will\nminimize cost.\n\\begin{sol}\nIt has a square base, and is one and one half times as tall as wide.\nIf the volume is $V$ the dimensions are $\\root 3 \\of {2V/3}\\times\n\\root 3 \\of {2V/3}\\times \\root 3\\of {9V/4}$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nUsing the methods of this section, find the shortest\ndistance from the origin to the plane $x+y+z=10$.\n\\begin{sol}\n$\\sqrt{100/3}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nUsing the methods of this section, find the shortest\ndistance from the point $(x_0,y_0,z_0)$ to the plane $ax+by+cz=d$.\nYou may assume that $c\\not=0$; use of Sage or similar software\nis recommended.\n\\begin{sol}\n$|ax_0+by_0+cz_0-d|/\\sqrt{a^2+b^2+c^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nA trough is to be formed by bending up two sides of a long\nmetal rectangle\nso that the cross-section of the trough is an isosceles trapezoid.\nIf the width of the metal sheet is 2\nmeters, how should it be bent to maximize the volume of the trough?\n\\begin{sol}\nThe sides and bottom should all be $2/3$ meter, and the sides\nshould be bent up at angle $\\pi/3$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nGiven the three points $(1,4)$, $(5,2)$, and $(3,-2)$, \n$\\ds(x-1)^2+(y-4)^2+(x-5)^2+(y-2)^2+(x-3)^2+(y+2)^2$\nis the sum of the squares of the distances from point $(x,y)$ to the\nthree points. Find $x$ and $y$ so that this quantity is minimized.\n\\begin{sol}\n$(3,4/3)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nSuppose that $f(x,y)=x^2+y^2+kxy$. Find and classify the\n  critical points, and discuss how they change when $k$ takes on\n  different values.\n\\end{ex}\n\n\\begin{ex}\nFind the shortest distance from the point $(0,b)$ to the\n  parabola $y=x^2$.\n\\begin{sol}\n$|b|$ if $b\\le1/2$, otherwise $\\ds\\sqrt{b-1/4}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the shortest distance from the point $(0,0,b)$ to the\n  paraboloid $z=x^2+y^2$.\n\\begin{sol}\n$|b|$ if $b\\le1/2$, otherwise $\\ds\\sqrt{b-1/4}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nConsider the function $f(x,y)=x^3-3x^2y+y^3$.\n\n\\begin{enumerate}\n\t\\item Show that $(0,0)$ is the only critical point of $f$.\n\t\\item Show that the discriminant test is inconclusive for $f$.  \n\t\\item Determine the cross-sections of $f$ obtained by setting $y=kx$ for\n\t  various values of $k$.\n\t\\item What kind of critical point is $(0,0)$?\n\\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\nFind the volume of the largest rectangular box with edges\n  parallel to the axes that can be inscribed in the ellipsoid\n  $2x^2+72y^2+18z^2=288$.\n\\begin{sol}\n$\\ds 1024/\\sqrt3$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "f3307291e7488c47e968f9504a3b3ad1ba35c099", "size": 12577, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14-partial-differentiation/14-7-multivariate-max-min.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "14-partial-differentiation/14-7-multivariate-max-min.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "14-partial-differentiation/14-7-multivariate-max-min.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6675324675, "max_line_length": 90, "alphanum_fraction": 0.7064482786, "num_tokens": 4375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.8807970701552505, "lm_q1q2_score": 0.7358914588597639}}
{"text": "\\section{The Hopf fibration}\n\nOur goal in this section is to construct the \\define{Hopf fibration}. The Hopf fibration is a fiber sequence\n\\begin{equation*}\n\\sphere{1}\\hookrightarrow\\sphere{3}\\twoheadrightarrow\\sphere{2}.\n\\end{equation*}\nMore generally, we show that for any type $A$ equipped with a multiplicative operation $\\mu:A\\to (A\\to A)$ for which $\\mu(x,\\blank)$ and $\\mu(\\blank,x)$ are equivalences, there is a fiber sequence\n\\begin{equation*}\n  A\\hookrightarrow \\join{A}{A}\\twoheadrightarrow \\susp A.\n\\end{equation*}\nThe construction of this fiber sequence is known as the \\define{Hopf construction}. We then get the Hopf fibration from the Hopf construction by using the multiplication on $\\sphere{1}$ constructed in \\cref{sec:mulcircle} after we show that $\\eqv{\\join{\\sphere{1}}{\\sphere{1}}}{\\sphere{3}}$.\n\nWe then introduce the long exact sequence of homotopy groups. The long exact sequence is an important tool to compute homotopy groups which applies to any fiber sequence\n\\begin{equation*}\n  F \\hookrightarrow E \\twoheadrightarrow B.\n\\end{equation*}\nIn the case of the Hopf fibration, we will use the long exact sequence to show that\n\\begin{equation*}\n  \\pi_k(\\sphere{3})=\\pi_k(\\sphere{2})\n\\end{equation*}\nfor any $k\\geq 3$.\n\nSince the Hopf fibration is closely related to the multiplication operation of the complex numbers on the unit circle, the Hopf fibration is sometimes also called the \\emph{complex} Hopf fibration. Indeed, there is also a \\emph{real} Hopf fibration\n\\begin{equation*}\n  \\sphere{0}\\hookrightarrow\\sphere{1}\\twoheadrightarrow\\sphere{1}.\n\\end{equation*}\nThis is just the double cover of the circle. There is even a \\emph{quaternionic} Hopf fibration\n\\begin{equation*}\n  \\sphere{3}\\hookrightarrow\\sphere{7}\\twoheadrightarrow\\sphere{4},\n\\end{equation*}\nwhich uses the multiplication of the quaternionic numbers on the unit sphere. The main difficulty in defining the quaternionic Hopf fibration in homotopy type theory is to define the quaternionic multiplication\n\\begin{equation*}\n  \\mulsphere{3} : \\sphere{3}\\to(\\sphere{3}\\to\\sphere{3}).\n\\end{equation*}\nThe construction of the octonionic Hopf fibration\n\\begin{equation*}\n  \\sphere{7}\\hookrightarrow\\sphere{15}\\twoheadrightarrow\\sphere{8}\n\\end{equation*}\nin homotopy type theory is still an open problem. Another open problem is to formalize Adams' theorem \\cite{Adams58} in homotopy type theory, that there are \\emph{no} further fiber sequences of the form\n\\begin{equation*}\n  \\sphere{k}\\hookrightarrow\\sphere{l}\\twoheadrightarrow\\sphere{m},\n\\end{equation*}\nfor $k,l,m\\geq 0$.\n\n\\subsection{Fiber sequences}\n\n\\begin{defn}\n  A \\define{short sequence} of maps into a pointed type $B$ with base point $b$ consists of maps\n  \\begin{equation*}\n    \\begin{tikzcd}\n      F \\arrow[r,\"i\"] & E \\arrow[r,\"p\"] & B\n    \\end{tikzcd}\n  \\end{equation*}\n  equipped with a homotopy $p\\circ i\\htpy \\const_b$. We say that a short sequence as above is an \\define{unpointed fiber sequence} if the commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=large]\n      F \\arrow[r,\"i\"] \\arrow[d,swap,\"\\const_\\star\"] & E \\arrow[d,\"p\"] \\\\\n      \\unit \\arrow[r,swap,\"\\const_b\"] & B\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pullback square.\n\\end{defn}\n\n\\begin{defn}\n  A \\define{short sequence} of pointed maps into a pointed type $B$ with base point $b$ consists of pointed maps\n    \\begin{equation*}\n    \\begin{tikzcd}[column sep=large]\n      F \\arrow[r,\"i\"] & E \\arrow[r,\"p\"] & B\n    \\end{tikzcd}\n  \\end{equation*}\n  equipped with a pointed homotopy $p\\circ i\\htpy_\\ast \\const_b$. We say that a short sequence as above is an \\define{fiber sequence} if the commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      F \\arrow[r,\"i\"] \\arrow[d,swap,\"\\const_\\star\"] & E \\arrow[d,\"p\"] \\\\\n      \\unit \\arrow[r,swap,\"\\const_b\"] & B\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pullback square.\n\\end{defn}\n\n\\subsection{The Hopf construction}\n\nThe Hopf construction is a general construction of a fiber sequence\n\\begin{equation*}\n  A \\hookrightarrow \\join{A}{A}\\twoheadrightarrow \\susp A,\n\\end{equation*}\nthat applies to any H-space $A$. Our definition of an H-space is chosen such that it provides only the necessary structure to apply the Hopf construction. We give an unpointed and a pointed variant, and moreover we give a coherent variant that is more closely related to the traditional definition of an H-space.\n\n\\begin{defn}\n  ~\n  \\begin{enumerate}\n  \\item An \\define{unpointed H-space} structure on a type $A$ consists of a multiplicative operation\n  \\begin{equation*}\n    \\mu:A\\to(A\\to A)\n  \\end{equation*}\n  such that $\\mu(x,\\blank)$ and $\\mu(\\blank,x)$ are equivalences, for each $x:A$.\n  \\item If $A$ is a pointed type with base point $e:A$, then an \\define{H-space} structure on $A$ is an unpointed H-space structure on $A$ equipped with an identification $\\mu(e,e)=e$.\n  \\item A \\define{coherent H-space} structure on a pointed type $A$ with base point $e:A$ consists of an unpointed H-space structure $\\mu$ on $A$ that satisfies the unit laws, i.e., $\\mu$ comes equipped with identifications\n  \\begin{align*}\n    \\leftunit_\\mu & : \\mu(e,a) = a \\\\\n    \\rightunit_\\mu & : \\mu(a,e) = a \\\\\n    \\cohunit_\\mu & : \\leftunit_\\mu(e)=\\rightunit_\\mu(e).\n  \\end{align*}\n  \\end{enumerate}\n\\end{defn}\n\n\\begin{eg}\n  The loop space $\\loopspace{A}$ of any pointed type is a coherent H-space, where the multiplication is given by path concatenation.\n\\end{eg}\n\nBy an unpointed fiber sequence, we mean a sequence\n\\begin{equation*}\n  \\begin{tikzcd}\n    F \\arrow[r,hook,\"i\"] & E \\arrow[r,->>,\"p\"] & B\n  \\end{tikzcd}\n\\end{equation*}\nwhere only the type $B$ is assumed to be pointed (with base point $b$), and the square\n\\begin{equation*}\n  \\begin{tikzcd}\n    F \\arrow[r,\"i\"] \\arrow[d,swap,\"\\const_{\\star}\"] & E \\arrow[d,\"p\"] \\\\\n    \\unit \\arrow[r,swap,\"\\const_{b}\"] & B\n  \\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n\n\n\\begin{thm}[The Hopf construction]\\label{thm:hopf-construction}\n  Consider a type $A$ equipped with an H-space structure $\\mu$. Then there is an unpointed fiber sequence\n  \\begin{equation*}\n    A \\hookrightarrow \\join{A}{A} \\twoheadrightarrow \\susp A.\n  \\end{equation*}\n  If $A$ and the $H$-space structure are pointed, then this unpointed fiber sequence is an fiber sequence.\n\\end{thm}\n\n\\begin{proof}\n  Note that there is a unique map $h:\\join{A}{A}\\to \\susp A$ such that the cube\n  \\begin{equation*}\n    \\begin{tikzcd}\n      & A \\times A \\arrow[d,swap,\"\\mu\"] \\arrow[dl,swap,\"\\proj 1\"] \\arrow[dr,\"\\proj 2\"] \\\\\n      A \\arrow[d] & A \\arrow[dl] \\arrow[dr] & A \\arrow[dl,crossing over] \\arrow[d] \\\\\n      \\unit \\arrow[dr] & \\join{A}{A} \\arrow[from=ul,crossing over] \\arrow[d,swap,densely dotted,\"h\"] & \\unit \\arrow[dl] \\\\\n      & \\susp A\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. Thus we see that we obtain a fiber sequence $A\\hookrightarrow\\join{A}{A}\\twoheadrightarrow\\susp A$ if we show that the front two squares are pullback squares. By the descent theorem, \\cref{thm:descent}, it suffices to show that the two squares in the back\n    \\begin{equation*}\n    \\begin{tikzcd}\n      A\\times A \\arrow[d,swap,\"\\proj 1\"] \\arrow[r,\"\\mu\"] & A \\arrow[d] &[2em] A\\times A \\arrow[r,\"\\mu\"] \\arrow[d,swap,\"\\proj 2\"] & A \\arrow[d] \\\\\n      A \\arrow[r] & \\unit & A \\arrow[r] & \\unit\n    \\end{tikzcd}\n  \\end{equation*}\n  are pullback squares. We claim that in both squares, the multiplicative operation $\\mu$ induces equivalences on the fibers, and hence both squares are pullbacks by \\cref{cor:pb_fibequiv}. To see this, note that the induced map on fibers fit in commuting squares\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\fib{\\proj 1}{x} \\arrow[r,densely dotted] \\arrow[d,swap,\"\\simeq\"] & \\fib{\\const_{\\star}}{\\star} \\arrow[d,\"\\simeq\"] & \\fib{\\proj 2}{x} \\arrow[r,densely dotted] \\arrow[d,swap,\"\\simeq\"] & \\fib{\\const_{\\star}}{\\star} \\arrow[d,\"\\simeq\"] \\\\\n      A \\arrow[r,swap,\"{\\mu(x,\\blank)}\"] & A & A \\arrow[r,swap,\"{\\mu(\\blank,x)}\"] & A.\n    \\end{tikzcd}\n  \\end{equation*}\n  The claim now follows, since we have assumed that $\\mu(x,\\blank)$ and $\\mu(\\blank,x)$ are equivalences for each $x:X$.\n\\end{proof}\n\n\\begin{rmk}\n  The Hopf map $h$ constructed in \\cref{thm:hopf-construction} is the unique map $\\join{A}{A}\\to\\susp A$ equipped with identifications\n  \\begin{align*}\n    p & : \\north = h(\\inl(x)) \\\\\n    p' & : \\south = h(\\inr(x'))\n  \\end{align*}\n  and an identification $q$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\north \\arrow[d,equals,swap,\"{\\merid(\\mu(x,x'))}\"] \\arrow[r,equals,\"p\"] & h(\\inl(x)) \\arrow[d,equals,\"\\ap{h}{\\glue(x,x')}\"] \\\\\n      \\south \\arrow[r,equals,swap,\"{p'}\"] & h(\\inr(x'))\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes.\n\\end{rmk}\n\n\\begin{cor}\nThere is a fiber sequence\n\\begin{equation*}\n\\sphere{1}\\hookrightarrow \\join{\\sphere{1}}{\\sphere{1}} \\twoheadrightarrow \\sphere{2}.\n\\end{equation*}\n\\end{cor}\n\n\\begin{proof}\n  By \\cref{thm:hopf-construction} it suffices to construct an H-space structure on $\\sphere{1}$. This H-space structure $\\sphere{1}\\times\\sphere{1}\\to\\sphere{1}$ is determined by the complex multiplication operation constructed in \\cref{defn:mul-circle}.\n\\end{proof}\n\n\\begin{lem}\nThe join operation is associative\n\\end{lem}\n\n\\begin{proof}\n\\begin{equation*}\n\\begin{tikzcd}\nA & A\\times C \\arrow[l] \\arrow[r] & A\\times C \\\\\nA\\times B \\arrow[u] \\arrow[d] & A\\times B \\times C \\arrow[r] \\arrow[d] \\arrow[l] \\arrow[u] & A\\times C \\arrow[u] \\arrow[d] \\\\\nB & B\\times C \\arrow[l] \\arrow[r] & C\n\\end{tikzcd}\n\\end{equation*}\n\\end{proof}\n\n\\begin{cor}\nThere is an equivalence $\\eqv{\\join{\\sphere{1}}{\\sphere{1}}}{\\sphere{3}}$.\n\\end{cor}\n\n\\begin{thm}\nThere is a fiber sequence $\\sphere{1}\\hookrightarrow\\sphere{3}\\twoheadrightarrow\\sphere{2}$. \n\\end{thm}\n\n\\begin{lem}\nSuppose $f:G\\to H$ is a group homomorphism, such that the sequence\n\\begin{equation*}\n\\begin{tikzcd}\n0 \\arrow[r] & G \\arrow[r,\"f\"] & H \\arrow[r] & 0\n\\end{tikzcd}\n\\end{equation*}\nis exact at $G$ and $H$, where we write $0$ for the trivial group consisting of just the unit element. Then $f$ is a group isomorphism.\n\\end{lem}\n\n\\begin{cor}\nWe have $\\pi_2(\\sphere{2})=\\Z$, and for $k>2$ we have $\\pi_k(\\sphere{2})=\\pi_k(\\sphere{3})$.\n\\end{cor}\n\n\\subsection{The long exact sequence}\n\n\\begin{defn}\nA fiber sequence $F\\hookrightarrow E \\twoheadrightarrow B$ consists of:\n\\begin{enumerate}\n\\item Pointed types $F$, $E$, and $B$, with base points $x_0$, $y_0$, and $b_0$ respectively, \n\\item Base point preserving maps $i:F\\to_\\ast E$ and $p:E\\to_\\ast B$, with $\\alpha:i(x_0)=y_0$ and $\\beta:p(y_0)=b_0$,\n\\item A pointed homotopy $H:\\mathsf{const}_{b_0}\\htpy_\\ast p\\circ_\\ast i$ witnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}\nF \\arrow[r,\"i\"] \\arrow[d] & E \\arrow[d,\"p\"] \\\\\n\\unit \\arrow[r,swap,\"\\mathsf{const}_{b_0}\"] & B,\n\\end{tikzcd}\n\\end{equation*}\ncommutes and is a pullback square.\n\\end{enumerate}\n\\end{defn}\n\n\\begin{lem}\nAny fiber sequence $F\\hookrightarrow E\\twoheadrightarrow B$ induces a sequence of pointed maps\n\\begin{equation*}\n\\begin{tikzcd}\n\\loopspace{F} \\arrow[r,\"\\loopspace{i}\"] & \\loopspace{E} \\arrow[r,\"\\loopspace{p}\"] & \\loopspace{B} \\arrow[r,\"\\partial\"] & F \\arrow[r,\"i\"] & E \\arrow[r,\"p\"] & B,\n\\end{tikzcd}\n\\end{equation*}\nin which every two consecutive maps form a fiber sequence.\n\\end{lem}\n\n\\begin{proof}\nBy taking pullback squares repeatedly, we obtain the diagram\n\\begin{equation*}\n\\begin{gathered}[b]\n\\begin{tikzcd}[column sep=large]\n\\loopspace{F} \\arrow[d,swap,\"\\loopspace{i}\"] \\arrow[r] & \\unit \\arrow[d,\"\\mathsf{const}_{\\refl{b_0}}\"] \\\\\n\\loopspace{E} \\arrow[r,\"\\loopspace{p}\"] \\arrow[d] & \\loopspace{B} \\arrow[r] \\arrow[d,swap,\"\\partial\"] & \\unit \\arrow[d,\"\\mathsf{const}_{y_0}\"] \\\\\n\\unit \\arrow[r,swap,\"\\mathsf{const}_{x_0}\"] & F \\arrow[r,\"i\"] \\arrow[d] & E \\arrow[d,\"p\"] \\\\\n& \\unit \\arrow[r,swap,\"\\mathsf{const}_{b_0}\"] & B.\n\\end{tikzcd}\\\\[-\\dp\\strutbox]\n\\end{gathered}\\qedhere\n\\end{equation*}\n\\end{proof}\n\n\\begin{defn}\nWe say that a consecutive pair of pointed maps between pointed sets\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[r,\"f\"] & B \\arrow[r,\"g\"] & C\n\\end{tikzcd}\n\\end{equation*}\nis \\define{exact} at $B$ if we have\n\\begin{equation*}\n\\Big(\\exis{a:A}f(a)=b\\Big)\\leftrightarrow (g(b)=c)\n\\end{equation*}\nfor any $b:B$. \n\\end{defn}\n\n\\begin{rmk}\nIf a pair of consecutive pointed maps between pointed sets\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[r,\"f\"] & B \\arrow[r,\"g\"] & C\n\\end{tikzcd}\n\\end{equation*}\nis exact at $B$, it directly that $\\im(f)=\\fib{g}{c}$. Indeed, such a pair of pointed maps is exact at $B$ if and only if there is an equivalence $e:\\im(f)\\eqvsym \\fib{g}{c}$ such that the triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=tiny]\n\\im(f) \\arrow[dr] \\arrow[rr,\"e\"] & & \\fib{g}{c} \\arrow[dl] \\\\\n& B\n\\end{tikzcd}\n\\end{equation*}\ncommutes. In other words, $\\im(f)$ and $\\fib{g}{c}$ are equal \\emph{as subsets of $B$}.\n\\end{rmk}\n\n\\begin{lem}\nSuppose $F\\hookrightarrow E \\twoheadrightarrow B$ is a fiber sequence. Then the sequence\n\\begin{equation*}\n\\begin{tikzcd}\n\\trunc{0}{F} \\arrow[r,\"\\trunc{0}{i}\"] & \\trunc{0}{E} \\arrow[r,\"\\trunc{0}{p}\"] & \\trunc{0}{B}\n\\end{tikzcd}\n\\end{equation*}\nis exact at $\\trunc{0}{E}$. \n\\end{lem}\n\n\\begin{proof}\nTo show that the image $\\im\\trunc{0}{i}$ is the fiber $\\fib{\\trunc{0}{p}}{\\tproj{0}{b_0}}$, it suffices to construct a fiberwise equivalence\n\\begin{equation*}\n\\prd{x:\\trunc{0}{E}} \\trunc{-1}{\\fib{\\trunc{0}{i}}{x}} \\eqvsym \\trunc{0}{p}(x)=\\tproj{0}{b_0}.\n\\end{equation*}\nBy the universal property of $0$-truncation it suffices to show that\n\\begin{equation*}\n\\prd{x:E} \\trunc{-1}{\\fib{\\trunc{0}{i}}{\\tproj{0}{x}}} \\eqvsym \\trunc{0}{p}(\\tproj{0}{x})=\\tproj{0}{b_0}.\n\\end{equation*}\nFirst we note that \n\\begin{align*}\n\\trunc{0}{p}(\\tproj{0}{x})=\\tproj{0}{b_0} & \\eqvsym \\tproj{0}{p(x)} = \\tproj{0}{b_0} \\\\\n& \\eqvsym \\trunc{-1}{p(x)=b_0}.\n\\end{align*}\nNext, we note that\n\\begin{align*}\n\\fib{\\trunc{0}{i}}{\\tproj{0}{x}} & \\eqvsym \\sm{y:\\trunc{0}{F}}\\trunc{0}{i}(y)=\\tproj{0}{x} \\\\\n& \\eqvsym \\trunc{0}{\\sm{y:F}\\trunc{0}{i}(\\tproj{0}{y})=\\tproj{0}{x}} \\\\\n& \\eqvsym \\trunc{0}{\\sm{y:F}\\tproj{0}{i(y)}=\\tproj{0}{x}} \\\\\n& \\eqvsym \\trunc{0}{\\sm{y:F}\\trunc{-1}{i(y)=x}}.\n\\end{align*}\nTherefore it follows that\n\\begin{align*}\n\\trunc{-1}{\\fib{\\trunc{0}{i}}{\\tproj{0}{x}}} & \\eqvsym \\trunc{-1}{\\sm{y:F}\\trunc{-1}{i(y)=x}} \\\\\n& \\eqvsym \\trunc{-1}{\\sm{y:F}i(y)=x} \\\\\n\\end{align*}\nNow it suffices to show that $\\eqv{\\big(\\sm{y:F}i(y)=x\\big)}{p(x)=b_0}$. This follows by the pasting lemma of pullbacks\n\\begin{equation*}\n\\begin{tikzcd}\n(p(x)=b_0) \\arrow[r] \\arrow[d] & \\unit \\arrow[d] \\\\\nF \\arrow[r] \\arrow[d] & E \\arrow[d] \\\\\n\\unit \\arrow[r] & B\n\\end{tikzcd}\n\\end{equation*}\n\\end{proof}\n\n\\begin{thm}\nAny fiber sequence $F\\hookrightarrow E\\twoheadrightarrow B$ induces a long exact sequence on homotopy groups\n\\begin{equation*}\n\\begin{tikzcd}\n& & \\cdots \\arrow[out=355,in=175,dll] \\\\\n\\pi_n(F) \\arrow[r,\"\\pi_n(i)\"] & \\pi_n(E) \\arrow[r,\"\\pi_n(p)\"] & \\pi_n(B) \\arrow[out=355,in=175,dll,densely dotted] \\\\\n\\pi_1(F) \\arrow[r,\"\\pi_1(i)\"] & \\pi_1(E) \\arrow[r,\"\\pi_1(p)\"] & \\pi_1(B) \\arrow[out=355,in=175,dll] \\\\\n\\pi_0(F) \\arrow[r,\"\\pi_0(i)\"] & \\pi_0(E) \\arrow[r,\"\\pi_0(p)\"] & \\pi_0(B)\n\\end{tikzcd}\n\\end{equation*}\n\\end{thm}\n\n\\subsection{The universal complex line bundle}\n\n\\begin{defn}\n  A \\define{coherently associative unpointed H-space} structure on a type $X$ consists of \n\\end{defn}\n\n\n\\subsection{The finite dimensional complex projective spaces}\n\n\\begin{rmk}\n  The universe of types that are merely equal to the circle does not classify complex line bundles.\n\\end{rmk}\n\n\n\n\\begin{exercises}\n  \\exercise Consider an unpointed H-space $X$ of which the multiplication is associative, and consider $x:X$. Construct a unit for the multiplication, and show that it satisfies the coherent unit laws.\n  \\exercise\n  \\begin{subexenum}\n  \\item Show that the type of associative unpointed H-space structures on $\\bool$ is equivalent to $\\bool$.\n  \\item Show that the type of associative (pointed) H-space structures on $(\\bool,\\btrue)$ is contractible.\n  \\end{subexenum}\n  \\exercise Show that any fiber sequence\n\\begin{equation*}\n  F \\hookrightarrow E \\twoheadrightarrow B\n\\end{equation*}\nwhere the base points are $x_0:B$, $y_0:F$, and $z_0:E$ induces a fiber sequence of connected components\n\\begin{equation*}\n  \\mathsf{BAut}(y_0) \\hookrightarrow \\mathsf{BAut}(z_0) \\twoheadrightarrow \\mathsf{BAut}(x_0).\n\\end{equation*}\n  \\exercise Show that there is a fiber sequence\n\\begin{equation*}\n  \\sphere{3}\\hookrightarrow\\sphere{2}\\twoheadrightarrow\\trunc{2}{\\sphere{2}},\n\\end{equation*}\nwhere the map $\\sphere{2}\\to\\trunc{2}{\\sphere{2}}$ is the unit of the $2$-truncation.\n  \\exercise Show that $\\cprojective{\\infty}$ is a coherent H-space. Note: the $2$-sphere is not an H-space, and yet its $2$-truncation is!\n  \\exercise Construct for every group $G$ of order $n+1$ a fiber sequence\n  \\begin{equation*}\n    \\begin{tikzcd}\n      G \\arrow[r,hook] & \\bigvee_{(i:\\Fin(n^2))}\\sphere{1}\\arrow[r,->>] & \\bigvee_{(i:\\Fin(n))}\\sphere{1}\n    \\end{tikzcd}\n  \\end{equation*}\n  \\exercise Show that there is a fiber sequence\n\\begin{equation*}\n  \\rprojective{\\infty}\\hookrightarrow\\cprojective{\\infty}\\twoheadrightarrow\\cprojective{\\infty}.\n\\end{equation*}\n\\exercise Show that the type of (small) fiber sequences is equivalent to the type of quadruples $(B,P,b_0,x_0)$, consisting of\n\\begin{align*}\nB & : \\UU \\\\\nP & : B \\to \\UU \\\\\nb_0 & : B \\\\\nx_0 & : P(b_0).\n\\end{align*}\n\\end{exercises}\n", "meta": {"hexsha": "520e74c5c47ea93e8663aa64d6a41f48d7fcdd0c", "size": 17343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/hopf.tex", "max_stars_repo_name": "hemangandhi/HoTT-Intro", "max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 333, "max_stars_repo_stars_event_min_datetime": "2018-09-26T08:33:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:50:15.000Z", "max_issues_repo_path": "Book/hopf.tex", "max_issues_repo_name": "hemangandhi/HoTT-Intro", "max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-06-18T04:16:04.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-16T15:27:01.000Z", "max_forks_repo_path": "Book/hopf.tex", "max_forks_repo_name": "hemangandhi/HoTT-Intro", "max_forks_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2018-09-26T09:08:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T00:33:50.000Z", "avg_line_length": 42.3, "max_line_length": 312, "alphanum_fraction": 0.6816006458, "num_tokens": 6087, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055545, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7358206459932999}}
{"text": "% !TEX root = /Users/hzd88688126com/Desktop/USFD_Academic-_Report_LaTeX-Template/main.tex\n\\allowdisplaybreaks[4]\n\\section{The Least Mean Square (LMS) Algorithm}\n\\subsection{Correlation matrix}\nThe autocorrelation matrix is defined \\cite{Mandic2019} as $\\mathbf{R}_{xx}=\\mathbb{E}\\{\\mathbf{x}(n)\\mathbf{x}^T(n)\\}$ and $\\mathbf{x}(n)$ is $[ x(n-1), x(n-2)]^T$, thus $\\mathbf{R}_{xx}$ is\n\\begin{equation}\n\\mathbf{R}_{xx}=\\mathbb{E}\\left \\{ \\left[\n\t\\begin{matrix}\n\tx(n-1)x(n-1) & x(n-1)x(n-2)\\\\\n\tx(n-2)x(n-1) & x(n-2)x(n-2)\n\t\\end{matrix}\n\t\t\\right]\n\\right \\}=\n\\left[\n\t\\begin{matrix}\n\t\\mathbf{r}_{xx}(0) & \\mathbf{r}_{xx}(1)\\\\\n\t\\mathbf{r}_{xx}(1) & \\mathbf{r}_{xx}(0)\n\t\\end{matrix}\n\t\t\\right]\n\\end{equation}\nGiven by the $x(n)$ is a second-order auto-regressive process as \n\\begin{equation}\nx(n)=a_1x(n-1)+a_2x(n-2)+\\eta(n) \\quad where \\quad \\eta(n)\\sim \\mathcal{N}(0,\\sigma_{\\eta}^2)\n\\end{equation}\nthe $\\mathbf{r}_{xx}(0)$ and $\\mathbf{r}_{xx}(1)$ can be calculated by following steps due to the correlation matrix $\\mathbf{r}_{xx}(k)=\\mathbb{E}\\{x(n)x(n-k)\\}$\n\\begin{align}\n\\mathbf{r}_{xx}(0)\n\t&=\\mathbb{E}\\{x(n)x(n)\\} \\notag \\\\\n\t&=\\mathbb{E}\\{ a_1^2x^2(n-1)+ a_2^2x^2(n-2)+2 a_1a_2 x(n-1) x(n-2)\\notag\\\\\n\t&\\quad+\\eta(n)[a_1x(n-1)+a_2x(n-2)]\\}+\\sigma^2_\\eta \\notag\\\\\n\t&=a_1^2\\mathbf{r}_{xx}(0)+a_2^2\\mathbf{r}_{xx}(0)+2a_1a_2\\mathbf{r}_{xx}(1)+\\sigma^2_\\eta\t\\label{equation:r0}\n\\end{align}\nCause the noise subspace is orthogonal with signal subspace, the product term $\\mathbb{E}\\{\\eta(n)[a_1x(n-1)+a_2x(n-2)]\\}$ is zero. In the same way, the $\\mathbf{r}_{xx}(1)$ can be calculated as well as shown in Eq.\\ref{equation:r1}.\n\\begin{align}\n\\mathbf{r}_{xx}(1)\n\t&=\\mathbb{E}\\{x(n)x(n-1)\\} \\notag \\\\\n\t&=\\mathbb{E}\\{ a_1x^2(n-1)+ a_2x(n-1)x(n-2)+\\eta(n)x(n-1)\\}\\notag\\\\\n\t&=a_1\\mathbf{r}_{xx}(0)+a_2\\mathbf{r}_{xx}(1)\t\\label{equation:r1}\n\\end{align}\nTherefore, substituting Eq.\\ref{equation:r0} to Eq.\\ref{equation:r1}, the unique solutions of $\\mathbf{r}_{xx}(0)$ and $\\mathbf{r}_{xx}(1)$ are $\\frac{25}{27}$ and $\\frac{25}{54}$ respectively. The autocorrelation matrix $\\mathbf{R}_{xx}$ is\n\\begin{equation}\n\\mathbf{R}_{xx}=\\left[\n\\begin{matrix}\n\\frac{25}{27}&\\frac{25}{54}\\\\\n\\frac{25}{54}&\\frac{25}{27}\n\\end{matrix}\\right]\n\\end{equation} \nAs to LMS algorithm, the convergence step $\\mu$ is defined in the range of $0<\\mu<\\frac{2}{\\lambda_{max}}$., where $\\lambda_{max}$ is the maximum eigenvalue of $\\mathbf{R}_{xx}$. Applying eigendecomposition to autocorrelation matrix, the eigenvalues are approximate 0.463 and 1.3889. Taking the large one into account, the range of step $\\mu$ is\n\\begin{equation}\n0<\\mu<\\frac{2}{1.3889}=1.44\n\\label{eq:range}\n\\end{equation}\n\\subsection{LMS filter}\nThe LMS adaptive filter is implemented to estimate AR model's weights using $N=1000$ samples with 100 realizations. As a comparison of convergence, tow different steps $\\mu=0.01,\\text{ }0.05$ are considered within the limited range in Eq.\\ref{eq:range}. Fig.\\ref{fig:2_1_b} shows the estimated errors of single realization and mean error with two steps.\\\\\nAs to a single realization, the impact of descent step is not significant, since the white noise signal is randomly. However, taking account into mean error of 100 realizations, the convergence speed of large steps is faster than the smaller one. Specifically, the learning curve converges approximately after 100 samples at $\\mu=0.05$, while it is 250 samples at $\\mu=0.01$. Nevertheless, large step size causes significant fluctuation as well which should be trade-off.\n\\begin{figure}[htp]\n     \\centering\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/21/21b1.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/21/21b2.eps}\n     \\end{subfigure}\n        \\caption{LMS estimated error with different realizations and steps}\n        \\label{fig:2_1_b}\n\\end{figure}\n\\subsection{Misadjustment of LMS}\nThe theoretical misadjustent of the LMS is approximated as $\\mathcal{M}_{LMS} \\approx \\frac{\\mu}{2}\\mathrm{Tr}\\{\\mathbf{R}_{xx}\\}$, where the autocorrelation matrix $\\mathbf{R}_{xx}$ is calculated. However, the estimated misadjustment is the ratio of excess MSE and minimum MSE, which is $\\mathcal{M}=\\frac{MSE-\\sigma^2}{\\sigma^2}$. In addition, in order to guarantee the error calculated during steady state, the samples are selected after 400. Table.\\ref{tab:M} shows the values of misadjustment. As shown in table, the measured MSE and misadjustment is slightly larger than theoretical values. However, small step size introduces a small misadjustment, whereas the convergence speed is slow..\n\\begin{table}[htp]\n\\centering\n\\caption{Theoretical and Actual Misadjustment values for step sizes}\n\\begin{tabular}{ |c|c|c| } \n \\hline\n $\\mu$ & $\\mathcal{M}_{LMS}$ & $\\mathcal{M}$ \\\\ \n \\hline\n 0.01 & 0.0093 & 0.0134\n \\\\ \n \\hline\n 0.05 & 0.0463 & 0.0534\n \\\\ \n \\hline\n\\end{tabular}\n\\label{tab:M}\n\\end{table}\n\\subsection{LMS: estimated weights}\nFig.\\ref{fig:2_1_d} depicts the estimated weights $a_1=0.1$ and $a_2=0.8$ with steps $\\mu=0.01$ and $\\mu=0.05$. Compared these estimated weights with true values, small step size provides an acceptable steady state error which is closer to actual weights. However, the convergence speed is relatively slow compared with large step size. On the contrast, when $\\mu=0.05$, the convergence speed is significantly improved, resulting in a large difference with actual values. Thus, there is a trade-off between steady state error and convergence speed.\n\\begin{figure}[htp]\n     \\centering\n     \\includegraphics[width=0.4\\textwidth]{fig/21/21d.eps}\n     \\caption{LMS estimated weights with different steps}\n     \\label{fig:2_1_d}\n\\end{figure}\n\\subsection{Leaky LMS}\nFor the leaky LMS, the cost function is \n\\begin{align}\n\\mathcal J_2(n)&=\\frac{1}{2}(e^2(n)+\\gamma ||\\mathbf {w}(n)||_2^2)\\label{eq:cost2}\\\\\nwhere \\quad e(n)&=d(n)-\\mathbf{w}_T(n)\\mathbf {x}(n)\\notag\n\\end{align}\nTo get the minimum squared error, the gradient with weight $\\mathbf{w}$ of Eq.\\ref{eq:cost2} is taken, \n\\begin{align}\n\\nabla \\mathcal J_2(n)&=\\frac{1}{2}\\partial (e^2(n)+\\gamma ||\\mathbf {w}(n)||_2^2)/\\partial \\mathbf {w}\\notag\\\\\n&=\\frac{1}{2}(\\frac{\\partial(e^2(n))}{e(n)}\\frac{\\partial(e(n))}{\\mathbf {w}}+2\\gamma ||\\mathbf {w}(n)||_2)\\notag\\\\\n&=-e(n)\\mathbf{x}(n)+\\gamma \\mathbf {w}(n)\n\\label{eq:J2}\n\\end{align}\nTherefore, the updated weight is \n\\begin{align}\n\\mathbf {w}(n+1)&=\\mathbf {w}(n)+\\mu (-\\nabla \\mathcal J_2(n))\\notag\\\\\n\t\t\t\t&=\\mathbf {w}(n)+\\mu (e(n)\\mathbf{x}(n)-\\gamma \\mathbf {w}(n))\\notag\\\\\n\t\t\t\t&=(1-\\mu \\gamma)\\mathbf {w}(n)+\\mu e(n)\\mathbf{x}(n)\n\\label{eq:llms}\n\\end{align}\n\\subsection{Leaky LMS: estimated weights}\nFig.\\ref{fig:2_1_f} illustrated the estimated weights using leaky LMS filter with $\\gamma=$ 0.2, 0.4, 0.6 and $\\mu=$ 0.01, 0.05. However, the estimated values converges to a certain value with a large difference with actual coefficient. With the incremental of $\\gamma$, the steady state error significantly rises up. Observing weights curves, increasing $\\gamma$ introduces a larger bias for lager weight than small weight. Thus, Leaky LMS causes large penalty for the large weight estimation.\n\\begin{figure}[htb]\n     \\centering\n      \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/21/21f1.eps}\n     \\end{subfigure}\n     \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/21/21f2.eps}\n     \\end{subfigure}\n      \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/21/21f3.eps}\n     \\end{subfigure}\n        \\caption{Leaky LMS estimated weights with different $\\gamma$ and $\\mu$}\n        \\label{fig:2_1_f}\n\\end{figure}\\\\\nAs to the general LMS algorithm, the optimal weight is\n\\begin{align}\n \\mathbf {w}_{opt}=\\mathbf{R}_{xx}^{-1} \\mathbf{p}\\quad \\text{where} \\quad \\mathbf{p}= \\mathbb{E}\\{\\mathbf{x}(n)d(n)\\}\n\\end{align}\nThe autocorrelation matrix is semi-positive definite and can be invertible. However, the gradient vanishing problem is suffered when the eigenvalues of $\\mathbf{R}_{xx}$ are zeros, resulting in divergence to expected values. By adding a small number $\\gamma$ of $\\mathbf{R}_{xx}$, the weights can converge, which is the purpose of Leaky LMS. Thus, the optimal weight is \n\\begin{equation}\n \\mathbf {w}_{opt}=(\\mathbf{R}_{xx}+\\gamma \\mathbf{I})^{-1} \\mathbf{p}\n\\end{equation}\nNevertheless, the eigenvalues of autocorrelation matrix are non-zeros for this experiment. Hence, adding large value of $\\gamma$ leads to an obvious bias and the estimated weights converge to incorrect coefficients. \n\n\n\n", "meta": {"hexsha": "268d4600de6794a56f422d06cef91dc5a366aef4", "size": 8772, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/sections/Part2/21.tex", "max_stars_repo_name": "zdhank/Adaptive-Signal-Processing", "max_stars_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-05T10:27:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-19T08:55:10.000Z", "max_issues_repo_path": "Report/sections/Part2/21.tex", "max_issues_repo_name": "zdhank/Adaptive-Signal-Processing", "max_issues_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/sections/Part2/21.tex", "max_forks_repo_name": "zdhank/Adaptive-Signal-Processing", "max_forks_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.48, "max_line_length": 695, "alphanum_fraction": 0.6950524396, "num_tokens": 3002, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.8740772302445241, "lm_q1q2_score": 0.7358206300984546}}
{"text": "\\chapter{A refined complexity calculus model: r-Complexity }\n\n\n\\section{Introduction and Motivation}\nThis chapter will present a new approach in the field of algorithm's computational complexity. Similar to the conventional asymptotic notations proposed in the literature,  \\textit{rComplexity} will be expressed as a function $f:\\mathbb{N}\\longrightarrow\\mathbb{R}$, where the function is characterized by the size of the input, while the evaluated value $f(n)$, for a given input size $n$, represents the amount of resources needed in order to compute the result.\n\nThis new calculus model aims to produce new asymptotic notations that offer better complexity feedback for similar algorithms, providing subtle insights even for algorithms that are part of the same conventional complexity class $\\Theta(g(n))$ denoted by an arbitrary function $g:\\mathbb{N}\\longrightarrow\\mathbb{R}$, in the definition of \\textit{Bachmann–Landau} notations. The additional information contained by \\textit{rComplexity} classes consists of the fine-granularity obtained by the model based on a refined clustering strategy for functions that used to belong to the same \\textit{Bachmann–Landau} group in different complexity classes, established on asymptotic constant analysis.\n\nThe classical complexity calculus model is a long-established, verified metric of evaluating an algorithm's performance and it is a valuable measurement in estimating feasibility of computing a considerable algorithm.\n\nHowever, the model has few shortfalls in making discrepancy between similar algorithms with two similar complexity functions, $v,w:\\mathbb{N}\\longrightarrow\\mathbb{R}$, such that $v(n),w(n) \\in \\Theta(g(n))$. In order to highlight the lack of distinction, suppose two algorithms $Alg1$ and $Alg2$ that solve exactly the same problem, with the following complexity functions:\n$f_{1},f_{2}:\\mathbb{N}\\longrightarrow\\mathbb{R}$ where $f_{1} = x \\cdot f_{2}$, with $x \\in \\mathbb{R}_{+}, \\ x > 1$.\nIf \\[ f_{2} \\in \\Theta(g(n)) \\Rightarrow \\exists c_{1}, c_{2} \\in \\mathbb{R}^{*}_{+}, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\ \\ c_{1} \\cdot g(n) \\leq f_{2}(n) \\leq c_{2} \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0} \\]\nTherefore, $f_{1} \\in \\Theta(g(n))$, as there exists $ c_{1}^{'}, c_{2}^{'} \\in \\mathbb{R}^{*}_{+}, n_{0}^{'} \\in \\mathbb{N}^{*}$ such that $ c_{1}^{'} = x \\cdot c_{1} $, $ c_{2}^{'} = x \\cdot c_{2} $ and $n_{0}^{'} = n_{0}$ and  $\\forall n \\geq n_{0}^{'} $ :  $c_{1}^{'} \\cdot g(n) \\leq f_{1}(n) \\leq c_{2}^{'} \\cdot g(n)$.\n\\\\ \\\\\nRemark that even if $f_{1} > f_{2}$, both complexity functions are part of the same complexity class. This observation implies that two algorithms, whose complexity functions can differ by a constant, even as high as $2020^{2020}$, are part of the same complexity class, even if the actual run-time might differ by over $6676$ orders of magnitude.\n\n\\begin{remark}\n    The discussion of how big numbers really are is fruitless and worthless. In this discussions the only bound can be expressed by the idiom \\textit{sky is the limit}, as numbers such as $2020 \\uparrow \\uparrow 2020$ defer by colossal orders of magnitude. Knuth's up\\-arrow notation is a method of notation for very large integers, introduced by Donald Knuth in 1976. ~\\cite{knuth1976mathematics} The idea is based on the fact that multiplication can be viewed as iterated addition and exponentiation as iterated multiplication.\n\\end{remark}\n\n\nFor comparison, only a $30$ magnitude order between the two complexity functions $f_{1} = 10^{30} \\cdot f_{2}$, signify\nthat if for a given input $n$, if $Alg2$ ends execution in 1 \\textit{attosecond} ($10^{-9}$ part of a nanosecond), then $Alg1$ is expected to end execution in about 3 \\textit{millenniums}. Despite of the colossal difference in time, classical complexity model is not perceptive between algorithms whose complexity functions differs only through constants. \\\\ \\\\\n\\textbf{\\textit{rComplexity}} calculus aims to clarify this issue by taking into deep analysis the preeminent constants that can state major improvements in an algorithm's complexity and can have tremendous effect over total execution time.\n\n\n\\section{Adjusting the Bachmann–Landau notations for rComplexity Calculus}\nThe following notations and names will be used for describing the asymptotic behavior of a algorithm's complexity characterized by a function, $f:\\mathbb{N}\\longrightarrow\\mathbb{R}$. \\\\\nWe define the set of all complexity calculus $\\mathcal{F}= \\lbrace f:\\mathbb{N}\\longrightarrow\\mathbb{R} \\rbrace$\n\\\\Assume that $n, n_{0}\\in\\mathbb{N}$. Also, we will consider an arbitrary complexity function $g \\in \\mathcal{F}$.\nAcknowledge the following notations $\\forall r \\neq 0$:\n\n\\begin{definition}\n    \\textbf{Big \\textit{r-}Theta}: This set defines the group of mathematical functions similar in magnitude with  $g(n)$ in the study of asymptotic behavior. A set-based description of this group can be expressed as:\n    \\[\\begin{split}\n          \\Theta_{r}(g(n)) = \\lbrace f \\in \\mathcal{F}\\ |\\ \\forall c_{1}, c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1}< r < c_{2} , \\exists n_{0} \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\ c_{1} \\cdot g(n) \\leq f(n) \\leq c_{2} \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0} \\rbrace\n    \\end{split} \\]\n\\end{definition}\n\n\\begin{definition}\n    \\textbf{Big \\textit{r-}O}: This set defines the group of mathematical functions that are known to have a similar or lower\n    asymptotic performance in comparison with  $g(n)$. The set of such functions is defined as it follows:\n    \\[\\mathcal{O}_{r}(g(n)) = \\lbrace f \\in \\mathcal{F}\\ |\\ \\forall c  \\in \\mathbb{R}^{*}_{+} \\ s.t.\\  r<c, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f(n) \\leq c \\cdot g(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n\\end{definition}\n\n\\begin{definition}\n    \\textbf{Big \\textit{r-}Omega}: This set defines the group of mathematical functions that are known to have a similar or higher asymptotic performance in comparison with  $g(n)$. The set of all function is defined as:\n    \\[\\Omega_{r}(g(n)) = \\lbrace f \\in \\mathcal{F}\\ |\\ \\forall c  \\in \\mathbb{R}^{*}_{+}\\ s.t. \\ c < r, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f(n) \\geq c \\cdot g(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n\\end{definition}\n\n\\begin{definition}\n    \\textbf{Small \\textit{r-}O}:\n    This set defines the group of mathematical functions that are known to have a humble\n    asymptotic performance in comparison with  $g(n)$. The set of such functions is defined as it follows:\n    \\[o_{r}(g(n)) = \\lbrace f \\in \\mathcal{F}\\ |\\ \\forall c \\in \\mathbb{R}^{*}_{+}, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f(n) < c \\cdot g(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n\\end{definition}\n\\begin{remark}\n    This set is defined for symmetry of the model and it is equal with the set defined by \\textbf{Small O} notation in \\textit{Bachmann–Landau notations}, as the definition is independent on $r$.\n\\end{remark}\n\n\\begin{definition}\n    \\textbf{Small \\textit{r-}Omega}:\n    This set defines the group of mathematical functions that are known to have a commanding asymptotic performance in comparison with  $g(n)$.\n    The set of such functions is defined as it follows:\n    \\[\\omega_{r}(g(n)) = \\lbrace f \\in \\mathcal{F}\\ |\\ \\forall c \\in \\mathbb{R}^{*}_{+}, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f(n) > c \\cdot g(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n\\end{definition}\n\\begin{remark}\n    This set is defined for symmetry of the model and it is equal with the set defined by \\textbf{Small Omega} notation in \\textit{Bachmann–Landau notations}, as the definition is independent on $r$.\n\\end{remark}\n\n\n\\section{Asymptotic Analysis}\nCalculus in $rComplexity$ can be performed either using limits of sequences or limits of functions. Consider any two complexity functions $f,g:\\mathbb{N}_{+}\\longrightarrow\\mathbb{R}_{+}$.\n\n\\begin{theorem}\n    Admittance of a function $f$ in \\textbf{Big \\textit{r-}Theta} class defined by a function $g$:\n    \\[ f \\in \\Theta_{r}(g(n)) \\Leftrightarrow \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = r \\]\n\\end{theorem}\n\n\\begin{theorem}\n    Admittance of a function $f$ in \\textbf{Big \\textit{r-}O} class defined by a function $g$:\n    \\[ f \\in \\mathcal{O}_{r}(g(n)) \\Leftrightarrow \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = l,\\ l \\in \\left[ 0, r \\right] \\]\n\\end{theorem}\n\n\\begin{theorem}\n    Admittance of a function $f$ in \\textbf{Big \\textit{r-}Omega} class defined by a function $g$:\n    \\[ f \\in \\Omega_{r}(g(n)) \\Leftrightarrow \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = l,\\ l \\in \\left[ r, \\infty \\right) \\]\n\\end{theorem}\n\n\\begin{theorem}\n    Admittance of a function $f$ in \\textbf{Small \\textit{r-}O} class defined by a function $g$:\n    \\[ f \\in o_{r}(g(n)) \\Leftrightarrow \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 0 \\]\n\\end{theorem}\n\n\\begin{theorem}\n    Admittance of a function $f$ in \\textbf{Small \\textit{r-}Omega} class defined by a function $g$:\n    \\[ f \\in \\omega_{r}(g(n)) \\Leftrightarrow \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = \\infty \\]\n\\end{theorem}\n\n\n\\section{Common properties}\nThis chapter will present new implications in terms of \\textit{reflexivity, transitivity, symmetry and projections} compared with conventional \\textit{Bachmann–Landau notations}.\n\n\\begin{theorem}\n    Reflexivity in $rComplexity$: - Big r-Theta notation  \\[ f \\in \\Theta_{r} \\left( \\frac{1}{r} \\cdot f(n) \\right)\\ \\forall r \\neq 0 \\]\n\\end{theorem}\n\\begin{proof}\n    Using the definition of $ \\Theta_{r}(f(n))$\n    \\[\\begin{split}\n          \\Theta_{r}(f(n)) = \\lbrace f' \\in \\mathcal{F}\\ |\\ \\forall c_{1}, c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1}< r < c_{2} , \\exists n_{0} \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\ c_{1} \\cdot f(n) \\leq f'(n) \\leq c_{2} \\cdot f(n)\\ ,\\  \\forall n \\geq n_{0} \\rbrace\n    \\end{split} \\]\n    Using substitution $ f(n) \\longleftarrow \\frac{1}{r} \\cdot f(n)$\n    \\[\\begin{split}\n          \\Theta_{r} \\left( \\frac{1}{r} \\cdot f(n) \\right) = \\lbrace f' \\in \\mathcal{F}\\ |\\ \\forall c_{1}, c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1}< r < c_{2} , \\exists n_{0} \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\frac{1}{r} \\cdot \\ c_{1} \\cdot f(n) \\leq  f'(n) \\leq \\frac{1}{r} \\cdot c_{2} \\cdot f(n)\\ ,\\  \\forall n \\geq n_{0} \\rbrace\n    \\end{split} \\]\n    By choosing $c_{1}' = \\frac{1}{r} \\cdot c_{1}, c_{2}' = \\frac{1}{r} \\cdot c_{2}$\n    \\[\\begin{split}\n          \\Theta_{r} \\left( \\frac{1}{r} \\cdot f(n) \\right) = \\lbrace f' \\in \\mathcal{F}\\ |\\ \\forall c_{1}', c_{2}' \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1}'< 1 < c_{2}' , \\exists n_{0} \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\  \\ c_{1}' \\cdot f(n) \\leq  f'(n) \\leq c_{2}' \\cdot f(n)\\ ,\\  \\forall n \\geq n_{0} \\rbrace\n    \\end{split} \\]\n    For any $x \\in \\mathbb{R}^{*}$,  $\\forall c_{1}, c_{2}\\ \\ s.t. c_{1} \\leq 1 \\leq c_{2}$, we have $ x \\cdot c_{1} \\leq x \\leq x \\cdot c_{2} $. \\\\\n    Thus, if $f:\\mathbb{N}\\longrightarrow\\mathbb{R}$, $\\forall c_{1}, c_{2}\\ \\  s.t. c_{1} \\leq 1 \\leq c_{2}$, we have $f(n) \\cdot c_{1} \\leq f(n) \\leq f(n) \\cdot c_{2}\\ \\ \\forall n \\in \\mathbb{N}^{*}$ or $f(n) \\cdot c_{1} \\geq f(n) \\geq f(n) \\cdot c_{2}\\ \\ \\forall n \\in \\mathbb{N}^{*}$\\\\\n\n    Therefore:\n    \\[\\forall c_{1}', c_{2}' \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1}'< 1 < c_{2}' , \\exists n_{0} = 1 s.t.\\  \\ c_{1}' \\cdot f(n) \\leq  f(n) \\leq c_{2}' \\cdot f(n)\\ ,\\  \\forall n \\geq n_{0}=1 \\Rightarrow \\]\n    \\[ f \\in \\Theta_{r} \\left( \\frac{1}{r} \\cdot f(n) \\right)\\ \\forall r \\neq 0 \\]\n\\end{proof}\n\n\n\\begin{theorem}\n    Reflexivity in $rComplexity$: - Big r-O notation\n    \\[ f \\in \\mathcal{O}_{r} \\left( x \\cdot f(n) \\right)\\ \\forall x \\geq \\dfrac{1}{r} \\]\n\\end{theorem}\n\\begin{proof}\n    :\n    Using the definition of $ \\mathcal{O}_{r}(f(n))$\n    \\[\\mathcal{O}_{r}(f(n)) = \\lbrace f' \\in \\mathcal{F}\\ |\\ \\forall c  \\in \\mathbb{R}^{*}_{+} \\ s.t.\\  r<c, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f'(n) \\leq c \\cdot f(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n    Using substitution $ f(n) \\longleftarrow x \\cdot f(n), \\forall x \\geq \\dfrac{1}{r}, \\forall r \\neq 0$\n    \\[\\mathcal{O}_{r}(x \\cdot f(n)) = \\lbrace f' \\in \\mathcal{F}\\ |\\ \\forall c  \\in \\mathbb{R}^{*}_{+} \\ s.t.\\  r<c, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f'(n) \\leq c \\cdot x \\cdot f(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n    If $r<c$ and $x \\geq \\dfrac{1}{r}$, then $c \\cdot x \\geq 1, \\forall r,c,x\\ \\ r \\neq 0$\n    Thus, if $f:\\mathbb{N}\\longrightarrow\\mathbb{R}$, we have $ f(n) \\leq 1 \\cdot f(n) \\leq  c \\cdot x\\cdot f(n) \\ \\ \\forall n \\in \\mathbb{N}^{*}$.\n\n    Therefore:\n    \\[\\forall x \\geq \\dfrac{1}{r}, \\ \\forall c \\in \\mathbb{R}^{*}_{+} \\ s.t.\\  r<c , \\exists n_{0} = 1 s.t.\\  \\  f(n) \\leq  c \\cdot x\\cdot f(n) \\ \\ \\forall n \\in \\mathbb{N}^{*} ,\\  \\forall n \\geq n_{0}=1 \\Rightarrow \\]\n    \\[ f \\in \\mathcal{O}_{r} \\left( x \\cdot f(n) \\right)\\ \\forall x \\geq \\dfrac{1}{r} \\]\n\\end{proof}\n\n\\begin{theorem}\n    Reflexivity in $rComplexity$: - Big r-Omega notation\n    \\[ f \\in \\Omega_{r} \\left( x \\cdot f(n) \\right)\\ \\forall x \\leq \\dfrac{1}{r} \\]\n\\end{theorem}\n\\begin{proof}\n    Using the definition of $\\Omega_{r}(f(n))$\n    \\[\\Omega_{r}(f(n)) = \\lbrace f' \\in \\mathcal{F}\\ |\\ \\forall c  \\in \\mathbb{R}^{*}_{+} \\ s.t.\\  c<r, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f'(n) \\geq c \\cdot f(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n    Using substitution $ f(n) \\longleftarrow x \\cdot f(n), \\forall x \\leq \\dfrac{1}{r}, \\forall r \\neq 0$\n    \\[\\Omega_{r}(x \\cdot f(n)) = \\lbrace f' \\in \\mathcal{F}\\ |\\ \\forall c  \\in \\mathbb{R}^{*}_{+} \\ s.t.\\  c<r, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f'(n) \\geq x \\cdot c \\cdot f(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n    If $r>c$ and $x \\leq \\dfrac{1}{r}$, then $c \\cdot x \\leq 1, \\forall r,c,x\\ \\ r \\neq 0$\n\n    Therefore:\n    \\[\\forall x \\leq \\dfrac{1}{r}, \\ \\forall c \\in \\mathbb{R}^{*}_{+} \\ s.t.\\  c<r , \\exists n_{0} = 1 s.t.\\  \\  f(n) \\geq  c \\cdot x\\cdot f(n) \\ \\ \\forall n \\in \\mathbb{N}^{*} ,\\  \\forall n \\geq n_{0}=1 \\Rightarrow \\]\n    \\[ f \\in \\Omega_{r} \\left( x \\cdot f(n) \\right)\\ \\forall x \\leq \\dfrac{1}{r} \\]\n\\end{proof}\n\n\n\n\\begin{remark}\n    Reflexivity does not hold in $rComplexity$ for small r-O notation.\n    \\[ f \\notin o_{r}(f(n)) \\]\n\n    The reflexivity does not hold for Small \\textit{r-}o and Small \\textit{r-}Omega, as these two sets are equal with the classical sets defined in \\textit{Bachmann–Landau notations}\n\\end{remark}\n\n\\begin{remark}\n    Reflexivity does not hold in $rComplexity$ for small r-Omega notation.\n    \\[ f \\notin \\omega_{r}(f(n)) \\]\n\n    The reflexivity does not hold for Small \\textit{r-}o and Small \\textit{r-}Omega, as these two sets are equal with the classical sets defined in \\textit{Bachmann–Landau notations}\n\\end{remark}\n\n\n\\begin{theorem}\n    Transitivity in $rComplexity$ - Big r-Theta notation:  \\\\  $ f \\in \\Theta_{r}(g(n)), g \\in \\Theta_{r'}(h(n)) \\Rightarrow  f \\in \\Theta_{r \\cdot r'}(h(n))$\n\\end{theorem}\n\\begin{proof}\n    If $ f \\in \\Theta_{r}(g(n)) \\Rightarrow \\forall c_{1}, c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1}< r < c_{2} , \\exists n_{0} \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\ c_{1} \\cdot g(n) \\leq f(n) \\leq c_{2} \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0} $ \\\\\n    If $ g \\in \\Theta_{r'}(h(n)) \\Rightarrow \\forall c_{1}, c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1} < r' < c_{2} , \\exists n_{0}' \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\ c_{1} \\cdot h(n) \\leq g(n) \\leq c_{2} \\cdot h(n)\\ ,\\  \\forall n \\geq n_{0}' $ \\\\\n    Thus, if $ f \\in \\Theta_{r}(g(n))$ and $ g \\in \\Theta_{r'}(h(n))$ \\\\ $\\Rightarrow \\forall c_{1}, c_{2}, c_{1}', c_{2}' \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1} < r < c_{2}, c_{1}' < r' < c_{2}' , \\exists n''_{0}=max(n_{0}, n'_{0}) \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\ c_{1}' \\cdot c_{1} \\cdot h(n) \\leq c_{1} \\cdot g(n) \\leq f(n) \\leq c_{2} \\cdot g(n) \\leq c_{2}' \\cdot c_{2} \\cdot h(n)\\ ,\\  \\forall n \\geq n''_{0} $ \\\\\n    Let $c_{1}'' = c_{1} \\cdot c_{1}' , c_{2}'' = c_{2} \\cdot c_{2}'$. \\\\\n    Then, $c_{1}'' < r \\cdot r' < c_{2}''$ \\\\\n    Therefore, $\\forall c_{1}'', c_{2}'' \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1}'' < r \\cdot r' < c_{2}'' \\ \\ \\exists n''_{0}=max(n_{0}, n'_{0}) \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\ c_{1}'' \\cdot h(n) \\leq f(n) \\leq c_{2}'' \\cdot h(n)\\ ,\\  \\forall n \\geq n''_{0} \\Rightarrow f \\in \\Theta_{r \\cdot r'}(h(n))$ \\\\\n\n\\end{proof}\n\nAll other Transitivity properties hold as well in $rComplexity$ Calculus. The proof is similar with the above.\n\\begin{theorem}\n    Transitivity in $rComplexity$ - Big r-O notation\n\n    $ f \\in \\mathcal{O}_{r}(g(n)), g \\in \\mathcal{O}_{r}(h(n)) \\Rightarrow  f \\in \\mathcal{O}_{r \\cdot r'}(h(n))$\n\\end{theorem}\n\\begin{theorem}\n    Transitivity in $rComplexity$ - Big r-Omega notation\n\n    $ f \\in \\Omega_{r}(g(n)), g \\in \\Omega_{r}(h(n)) \\Rightarrow  f \\in \\Omega_{r \\cdot r'}(h(n))$\n\\end{theorem}\n\\begin{theorem}\n    Transitivity in $rComplexity$ - Small r-O notation\n\n    $ f \\in o_{r}(g(n)), g \\in o_{r'}(h(n)) \\Rightarrow  f \\in o_{r \\cdot r'}(h(n))$\n\\end{theorem}\n\\begin{theorem}\n    Transitivity in $rComplexity$ - Small r-Omega notation\n\n    $ f \\in \\omega_{r}(g(n)), g \\in \\omega_{r'}(h(n)) \\Rightarrow  f \\in \\omega_{r \\cdot r'}(h(n))$\n\\end{theorem}\n\n\\begin{theorem}\n    \\textbf{Symmetry in $rComplexity$:}  \\\\  $ f \\in \\Theta_{r}(g(n)) \\Rightarrow g \\in \\Theta_{\\frac{1}{r}}(f(n)) $\n\\end{theorem}\n\n\\begin{proof}\n    $ f \\in \\Theta_{r}(g(n)) \\Rightarrow \\forall c_{1}, c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1}< r < c_{2} , \\exists n_{0} \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\ c_{1} \\cdot g(n) \\leq f(n) \\leq c_{2} \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0} $\n    \\\\ Using the substitution $c_{1}' = \\dfrac{c_{1}}{r}, c_{2}' = \\dfrac{c_{2}}{r} \\Rightarrow \\forall c_{1}', c_{2}' \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1} < 1 < c_{2} , \\exists n_{0} \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\ c_{1}' \\cdot g(n) \\leq \\dfrac{1}{r} \\cdot f(n) \\leq c_{2}' \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0} $\n    \\\\ The previous inequality can be re-written as:\n    \\[\\begin{cases}\n          g(n) \\leq \\dfrac{1}{c_{1}'} \\cdot \\dfrac{1}{r} \\cdot f(n) \\\\ g(n) \\geq \\dfrac{1}{c_{2}'} \\cdot \\dfrac{1}{r} \\cdot f(n)\n    \\end{cases}\\]\n    \\\\ Using notation $c_{1}'' = \\dfrac{1}{c_{2}'}, c_{2}'' = \\dfrac{1}{c_{1}'}$ the inequality becomes:  \\\\\n    $\\forall c_{1},'' c_{2}'' \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1}'' < r < c_{2}'' , \\exists n_{0} \\in \\mathbb{N}^{*}\\ $\n    \\[ {c_{1}''} \\cdot \\dfrac{1}{r} \\cdot f(n) \\leq g(n) \\leq {c_{2}'} \\cdot \\dfrac{1}{r} \\cdot f(n)\\ \\ \\forall n \\geq n_{0} \\]\n    Thus, using the definition of $ \\Theta_{r}(f(n))$, $ f \\in \\Theta_{r}(g(n)) \\Rightarrow g \\in \\Theta_{\\frac{1}{r}}(f(n)) $.\n\\end{proof}\n\n\n\\begin{theorem}\n    \\textbf{Transpose symmetry in $rComplexity$:}  \\\\  $ f \\in \\mathcal{O}_{r}(g(n)) \\Leftrightarrow g \\in \\Omega_{\\frac{1}{r}}(f(n)) $\n\\end{theorem}\n\n\\begin{proof}\n    Using the property of $ \\mathcal{O}_{r}(f(n))$ and $f \\in \\mathcal{O}_{r}(g(n))$:\n    \\begin{enumerate}[label=(\\roman*)]\n        \\item\n        \\[\\mathcal{O}_{r}(g(n)) \\supseteq \\lbrace f \\rbrace \\]\n        \\item\n        \\[ \\ \\forall c  \\in \\mathbb{R}^{*}_{+} \\ s.t.\\  r<c, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  g(n) \\leq c \\cdot f(n),\\  \\forall n \\geq n_{0} \\]\n    \\end{enumerate}\n    We can rewrite the previous relation as following:\n    \\[ \\ \\forall c  \\in \\mathbb{R}^{*}_{+} \\ s.t.\\  r<c, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  \\dfrac{1}{c} \\cdot g(n) \\leq f(n),\\  \\forall n \\geq n_{0} \\]\n    Substituting the constant $ c' = \\dfrac{1}{c}$:\n    \\[ \\ \\forall c'  \\in \\mathbb{R}^{*}_{+} \\ s.t.\\  c' < \\dfrac{1}{r}, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f(n) \\geq c' \\cdot g(n) ,\\  \\forall n \\geq n_{0} \\]\n\n    Therefore:\n    \\[\\Omega_{\\frac{1}{r}}(f(n)) \\supseteq \\lbrace g \\rbrace \\]\n\\end{proof}\n\\begin{theorem}\n    \\textbf{Transpose symmetry in $rComplexity$:}\n    $ f \\in o_{r}(g(n)) \\Leftrightarrow g \\in \\omega_{\\frac{1}{r}}(f(n)) $\n\\end{theorem}\n\n\\begin{proof}\n    The Transpose symmetry hold for Small \\textit{r-}o and Small \\textit{r-}Omega, as these two sets are equal with the classical sets defined in \\textit{Bachmann–Landau notations}\n\\end{proof}\n\n\n\\begin{theorem}\n    \\textbf{Projection in $rComplexity$:}  \\\\  $ f \\in \\Theta_{r}(g(n)) \\Leftrightarrow f \\in \\mathcal{O}_{r}(g(n)), f \\in \\Omega_{r}(g(n)) $\n\\end{theorem}\n\\begin{proof}\n    The proof is straightforward, usind the definitions of \\textbf{Big \\textit{r-}Theta}, \\textbf{Big \\textit{r-}O} and \\textbf{Big \\textit{r-}Omega}. \\\\\n    \" $\\Rightarrow$ \" $ f \\in \\Theta_{r}(g(n)) \\Rightarrow f \\in \\mathcal{O}_{r}(g(n)), f \\in \\Omega_{r}(g(n)) $\n    Using the definition of $\\Theta_{r}(g(n))$, $ f \\in \\Theta_{r}(g(n)) \\Rightarrow$\n    \\[\\forall c_{1}, c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1} < r < c_{2} , \\exists n_{0} \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\ c_{1} \\cdot g(n) \\leq f(n) \\leq c_{2} \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0} \\]\n    By splitting the inequality:\n    \\[\\begin{cases}\n          \\forall c_{1} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1} < r , \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\ \\ c_{1} \\cdot g(n) \\leq f(n) ,\\  \\forall n \\geq n_{0} \\\\ \\forall  c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. r < c_{2} , \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\ f(n) \\leq c_{2} \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0}\n    \\end{cases}\\]\n    Therefore:\n    \\[\\begin{cases}\n          f \\in \\mathcal{O}_{r}(g(n)) \\\\ f \\in \\Omega_{r}(g(n))\n    \\end{cases}\\]\n\n    \" $\\Leftarrow$ \" $ f \\in \\mathcal{O}_{r}(g(n)), f \\in \\Omega_{r}(g(n)) \\Rightarrow f \\in \\Theta_{r}(g(n)) $\n    Using the definitions of \\textbf{Big \\textit{r-}O} and \\textbf{Big \\textit{r-}Omega}:\n    \\[\\begin{cases}\n          \\forall c_{1} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1} < r , \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\ \\ c_{1} \\cdot g(n) \\leq f(n) ,\\  \\forall n \\geq n_{0} \\\\ \\forall  c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. r < c_{2} , \\exists n_{0}' \\in \\mathbb{N}^{*}\\ s.t.\\ f(n) \\leq c_{2} \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0}'\n    \\end{cases}\\]\n    By choosing $n_{0}'' = max(n_{0}, n_{0}')$:\n    \\[\\begin{cases}\n          \\forall c_{1} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1} < r ,\\Rightarrow\\ \\ c_{1} \\cdot g(n) \\leq f(n) ,\\  \\forall n \\geq n_{0}'' \\\\ \\forall  c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. r < c_{2} , \\Rightarrow \\ f(n) \\leq c_{2} \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0}''\n    \\end{cases}\\]\n    By merging the inequalities, we have:\n    \\[\\forall c_{1}, c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1} < r < c_{2} , \\exists n_{0}'' = max(n_{0}, n_{0}' \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\ c_{1} \\cdot g(n) \\leq f(n) \\leq c_{2} \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0}'' \\]\n    Therefore $f \\in \\Theta_{r}(g(n))$\n\\end{proof}\n\n\n\\section{Interdependence properties}\nAn interesting property of the \\textbf{Big \\textit{r-}Theta},  \\textbf{Big \\textit{r-}O} and \\textbf{Big \\textit{r-}Omega} classes is the simple technique of conversion between various values for the $r$s parameters. The following results arise:\n\n\\begin{theorem}\n    \\textbf{Big r-Theta conversion}:\n    \\[  f \\in \\Theta_{r}(g) \\Rightarrow f \\in \\Theta_{q} \\left( \\frac{q}{r} \\cdot g \\right) \\ \\forall r,q \\in \\mathbb{R}_{+}\\]\n\\end{theorem}\n\n\\begin{proof}\n    $ f \\in \\Theta_{r}(g(n)) \\Rightarrow \\forall c_{1}, c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1}< r < c_{2} , \\exists n_{0} \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\ c_{1} \\cdot g(n) \\leq f(n) \\leq c_{2} \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0} $ \\\\\n    Therefore, $\\forall c_{1}, c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1} < q < c_{2} , \\exists n_{0} \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\ \\frac{r}{q} \\cdot c_{1} \\cdot g(n) \\leq f(n) \\leq \\frac{r}{q} \\cdot c_{2} \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0}$. \\\\\n    Thus, $f \\in \\Theta_{q} \\left( \\frac{q}{r} \\cdot g \\right)$.\n\\end{proof}\n\nAnother interesting result is obtained by multiplying the last equation by $\\frac{q}{r}$: \\\\\n$\\forall c_{1}, c_{2} \\in \\mathbb{R}^{*}_{+} \\ s.t. c_{1} < q < c_{2} , \\exists n_{0}' = n_{0} \\in \\mathbb{N}^{*}\\ \\\\ s.t.\\ \\ c_{1} \\cdot g(n) \\leq \\frac{q}{r} \\cdot f(n) \\leq \\frac{r}{q} \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0}$\n\\begin{corollary}\n    \\[ \\frac{q}{r} \\cdot f \\in \\Theta_{q} \\left( g \\right)\\].\n\\end{corollary}\n\n\n\n\n\\begin{theorem}\n    \\textbf{Big r-O Conversion}:\n    \\[  f \\in \\mathcal{O}_{r}(g) \\Rightarrow f \\in \\mathcal{O}_{q} \\left( \\frac{q}{r} \\cdot g \\right) \\ \\forall r,q \\in \\mathbb{R}_{+}\\]\n\\end{theorem}\n\\begin{proof}\n    Is similar with the proof for Big r-Theta, with the inequalities becoming $f(n) \\leq c \\cdot g(n)$.\n\\end{proof}\n\\begin{corollary}\n    The following conversion relationship arises:\n    \\[  f \\in \\mathcal{O}_{r}(g) \\Rightarrow \\frac{q}{r} \\cdot f \\in \\mathcal{O}_{q} \\left(  g \\right) \\ \\forall r,q \\in \\mathbb{R}_{+}\\]\n\\end{corollary}\n\\begin{theorem}\n    \\textbf{Big r-Omega Conversion}:\n    \\[  f \\in \\Omega_{r}(g) \\Rightarrow f \\in \\Omega_{q} \\left( \\frac{q}{r} \\cdot g \\right) \\ \\forall r,q \\in \\mathbb{R}_{+}\\]\n\\end{theorem}\n\\begin{proof}\n    Is similar with the proof for Big r-Theta, with the inequalities becoming $f(n) \\geq c \\cdot g(n)$.\n\\end{proof}\n\\begin{corollary}\n    The following conversion relationship arises:\n    \\[  f \\in \\Omega_{r}(g) \\Rightarrow \\frac{q}{r} \\cdot f \\in \\Omega_{q} \\left( g \\right) \\ \\forall r,q \\in \\mathbb{R}_{+}\\]\n\\end{corollary}\n\n\nFurthermore, we present some interesting results regarding the connection between $rComplexity$ functions and the correspondent class in the $Bachmann-Landau$ notations. For Small notations, we already presented the connection in definition section.\n\nFor Big notations $(\\Theta, \\mathcal{O}, \\Omega)$, we present further some results:\n\n\\begin{theorem}\n    Relationship between Big r-Theta and Big Theta:\n    \\[  f \\in \\Theta_{r}(g) \\Rightarrow f \\in \\Theta (g) \\]\n    \\[  f \\in \\Theta(g) \\Rightarrow \\exists r \\in \\mathbb{R}_{+}\\ f \\in \\Theta_{r}(g) \\]\n\\end{theorem}\n\n\\begin{theorem}\n    Relationship between Big r-O and Big O:\n    \\[  f \\in \\mathcal{O}_{r}(g) \\Rightarrow f \\in \\mathcal{O} (g) \\]\n    \\[  f \\in \\mathcal{O}(g) \\Rightarrow \\exists r \\in \\mathbb{R}_{+}\\ f \\in \\mathcal{O}{r}(g) \\]\n\\end{theorem}\n\n\n\\begin{theorem}\n    Relationship between Big r-Omega and Big Omega:\n    \\[  f \\in \\Omega_{r}(g) \\Rightarrow f \\in \\Omega (g) \\]\n    \\[  f \\in \\Omega(g) \\Rightarrow \\exists r \\in \\mathbb{R}_{+}\\ f \\in \\Omega_{r}(g) \\]\n\\end{theorem}\n\n\n\\section{Addition properties}\nSimilar to the calculus in $Bachmann-Landau$ notations (including Big-O arithmetic), a useful technique can be obtained by analyzing the behavior of $r-$Complexity classes in regards to addition exercises.\n\n\n\n\\begin{itemize}\n    \\item Addition in \\textbf{Big r-Theta}:  \\\\\n    The following relations hold for any correctly defined functions $f, g, f', g', h:\\mathbb{N}\\longrightarrow\\mathbb{R}$, where $ h(n) = f'(n) + g'(n)\\  \\forall n \\in  \\mathbb{N} $, where $f',g'$ are two arbitrary functions such that $ f' \\in \\Theta_{r}(f), g' \\in \\Theta_{q}(g) $ and $r,q \\in \\mathbb{R}_{+}$:\n    \\begin{theorem}\n        \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 0 \\Rightarrow  h \\in \\Theta_{q}(g) $. \\\\\n    \\end{theorem}\n    \\begin{proof}\n        $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 0 \\Rightarrow \\lim_{n\\to\\infty} \\dfrac{f'(n)}{g'(n)} = 0 \\Rightarrow \\lim_{n\\to\\infty} \\dfrac{g'(n) + f'(n)}{g'(n)} = 1 $ and using the result from asymptotic analysis section, we have $ g'(n) + f'(n) = h(n) \\in \\Theta_{1}(g')$. \\\\ Using reflexivity property, $ h(n) \\in \\Theta_{q}(g)$.\n    \\end{proof}\n\n    \\begin{theorem}\n        \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = \\infty \\Rightarrow  h \\in \\Theta_{r}(f) $. \\\\\n    \\end{theorem}\n    \\begin{proof}\n        Using the last result, by swapping $f \\leftarrow g, g \\leftarrow f$ and considering the commutativity of addition, we obtain the proof for this statement.\n    \\end{proof}\n\n\n    \\begin{theorem}\n        \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = t, \\ t \\in \\mathbb{R}_{+} \\Rightarrow  h \\in \\Theta_{r} \\left( f + \\dfrac{r}{q} \\cdot g \\right) $. \\\\\n    \\end{theorem}\n    \\begin{proof}\n\n        $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = t \\Rightarrow \\lim_{n\\to\\infty} \\dfrac{f'(n)}{g'(n)} = t \\cdot \\dfrac{r}{q} = t' \\Rightarrow \\lim_{n\\to\\infty} \\dfrac{g'(n) + f'(n)}{g'(n)} = t' + 1 $ and using the result from asymptotic analysis section, we have $ g'(n) + f'(n) = h(n) \\in \\Theta_{t' + 1}(g')$. \\\\\n        Using reflexivity property, $ h(n) \\in \\Theta_{t' + 1} (q \\cdot g)$. \\\\\n        Using the conversion technique, we have $ h(n) \\in \\Theta_{r}( \\dfrac{1}{r} \\cdot t \\cdot \\dfrac{r}{q} + 1) \\cdot q \\cdot g)$. \\\\\n        By swapping back $t$, asymptotically, we can establish: $ h(n) \\in \\Theta_{r} \\left( \\dfrac{1}{r} \\cdot ( \\dfrac{f(n)}{g(n)} \\cdot \\dfrac{r}{q} + 1) \\cdot q \\cdot g \\right) $ \\\\\n        Therefore $ h \\in \\Theta_{r} \\left( f + \\dfrac{r}{q} \\cdot g \\right) $.\n    \\end{proof}\n\n\n\n    \\item Addition in \\textbf{Big r-O}: \\\\\n    The following relations hold for any correctly defined functions $f, g, f', g', h:\\mathbb{N}\\longrightarrow\\mathbb{R}$, where $ h(n) = f'(n) + g'(n)\\  \\forall n \\in \\mathbb{N} $, where $f',g'$ are two arbitrary functions such that $ f' \\in \\mathcal{O}_{r}(f), g' \\in \\mathcal{O}_{q}(g) $ and $r,q \\in \\mathbb{R}_{+}$:\n    \\begin{theorem}\n        \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 0 \\Rightarrow  h \\in \\mathcal{O}_{q}(g) $. \\\\\n    \\end{theorem}\n\n    \\textit{Proof}:\n    Is similar with the proof for addition in Big Theta, using conversion presented for Big r-O class.\n    \\hfill\\break\n\n    \\begin{theorem}\n        \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = \\infty \\Rightarrow  h \\in \\mathcal{O}_{r}(f) $. \\\\\n    \\end{theorem}\n\n    \\textit{Proof}:\n    Is similar with the proof for addition in Big Theta, using conversion presented for Big r-O class.\n    \\hfill\\break\n    \\begin{theorem}\n        \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = t, \\ t \\in \\mathbb{R}_{+} \\Rightarrow  h \\in \\mathcal{O}_{r} \\left( f + \\dfrac{r}{q} \\cdot g \\right) $. \\\\\n    \\end{theorem}\n\n    \\textit{Proof}:\n    Is similar with the proof for addition in Big Theta, using conversion presented for Big r-O class.\n    \\hfill\\break\n\n\n    \\item Addition in \\textbf{Big r-Omega}:\n    The following relations hold for any correctly defined functions $f, g, f', g', h:\\mathbb{N}\\longrightarrow\\mathbb{R}$, where $ h(n) = f'(n) + g'(n)\\  \\forall n \\in \\mathbb{N} $, where $f',g'$ are two arbitrary functions such that $ f' \\in \\Omega_{r}(f), g' \\in \\Omega_{q}(g) $ and $r,q \\in \\mathbb{R}_{+}$:\n    \\begin{theorem}\n        \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 0 \\Rightarrow  h \\in \\Omega_{q}(g) $. \\\\\n    \\end{theorem}\n    \\textit{Proof}:\n    Is similar with the proof for addition in Big Theta, using conversion presented for Big r-O class.\n    \\hfill\\break\n\n    \\begin{theorem}\n        \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = \\infty \\Rightarrow  h \\in \\Omega_{r}(f) $. \\\\\n    \\end{theorem}\n    \\textit{Proof}:\n    Is similar with the proof for addition in Big Theta, using conversion presented for Big r-Omega class.\n    \\hfill\\break\n    \\begin{theorem}\n        \\textbf{If} $ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = t, \\ t \\in \\mathbb{R}_{+} \\Rightarrow  h \\in \\Omega_{r} \\left( f + \\dfrac{r}{q} \\cdot g \\right) $. \\\\\n    \\end{theorem}\n    \\textit{Proof}:\n    Is similar with the proof for addition in Big Theta, using conversion presented for Big r-Omega class.\n    \\hfill\\break\n\n    \\item Addition in \\textbf{Small r-O}:\n    Same property as described in $Bachmann-Landau$ notations.\n    \\item Addition in \\textbf{Small r-Omega}:\n    Same property as described in $Bachmann-Landau$ notations.\n\\end{itemize}\n\n\nIn a relax notation (consider that by any  $r-$Complexity class notation, we denote an arbitrary function part of the class), the following relations can be settled:\n\n\nIf $\\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 0$:\n\\begin{itemize}\n    \\item \\textbf{Big r-Theta}:\n    \\begin{lemma}\n        \\[  \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 0 \\Rightarrow \\Theta_{r}(f) + \\Theta_{q}(g) = \\Theta_{q}(g)\\]\n    \\end{lemma}\n    \\item \\textbf{Big r-O}:\n    \\begin{lemma}\n        \\[  \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 0 \\Rightarrow \\mathcal{O}_{r}(f) + \\mathcal{O}_{q}(g) = \\mathcal{O}_{q}(g)\\]\n    \\end{lemma}\n    \\item \\textbf{Big r-Omega}:\n    \\begin{lemma}\n        \\[  \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = 0 \\Rightarrow \\Omega_{r}(f) + \\Omega_{q}(g) = \\Omega_{q}(g)\\]\n    \\end{lemma}\n\\end{itemize}\n\n\nIf $\\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = \\infty$:\n\\begin{itemize}\n    \\item \\textbf{Big r-Theta}:\n    \\begin{lemma}\n        \\[  \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = \\infty \\Rightarrow \\Theta_{r}(f) + \\Theta_{q}(g) = \\Theta_{r}(f)\\]\n    \\end{lemma}\n    \\item \\textbf{Big r-O}:\n    \\begin{lemma}\n        \\[ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = \\infty \\Rightarrow \\mathcal{O}_{r}(f) + \\mathcal{O}_{q}(g) = \\mathcal{O}_{r}(f)\\]\n    \\end{lemma}\n    \\item \\textbf{Big r-Omega}:\n    \\begin{lemma}\n        \\[ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = \\infty \\Rightarrow \\Omega_{r}(f) + \\Omega_{q}(g) = \\Omega_{r}(f)\\]\n    \\end{lemma}\n\\end{itemize}\n\nIf $\\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = t, \\ t \\in \\mathbb{R}_{+}$:\n\\begin{itemize}\n    \\item \\textbf{Big r-Theta}:\n    \\begin{lemma}\n        \\[ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = t, \\ t \\in \\mathbb{R}_{+} \\Rightarrow \\Theta_{r}(f) + \\Theta_{q}(g) = \\Theta_{r}(f + \\dfrac{r}{q} \\cdot g)\\]\n    \\end{lemma}\n    \\item \\textbf{Big r-O}:\n    \\begin{lemma}\n        \\[ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = t, \\ t \\in \\mathbb{R}_{+} \\Rightarrow \\mathcal{O}_{r}(f) + \\mathcal{O}_{q}(g) = \\mathcal{O}_{r}(f + \\dfrac{r}{q} \\cdot g)\\]\n    \\end{lemma}\n    \\item \\textbf{Big r-Omega}:\n    \\begin{lemma}\n        \\[ \\lim_{n\\to\\infty} \\dfrac{f(n)}{g(n)} = t, \\ t \\in \\mathbb{R}_{+} \\Rightarrow \\Omega_{r}(f) + \\Omega_{q}(g) = \\Omega_{r}(f + \\dfrac{r}{q} \\cdot g)\\]\n    \\end{lemma}\n\\end{itemize}\n\nThe proofs of these Lemmas are imminent from the corresponding theorems.", "meta": {"hexsha": "ed7314d521938461ec9562add957608601e71542", "size": 33405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TeX/complexity/rComplexity.tex", "max_stars_repo_name": "raresraf/rafMetrics", "max_stars_repo_head_hexsha": "21eb5e8210364bf70eee746d71c45f3e353dcb10", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2019-11-03T18:01:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T20:54:57.000Z", "max_issues_repo_path": "TeX/complexity/rComplexity.tex", "max_issues_repo_name": "raresraf/rafMetrics", "max_issues_repo_head_hexsha": "21eb5e8210364bf70eee746d71c45f3e353dcb10", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 392, "max_issues_repo_issues_event_min_datetime": "2019-11-09T21:28:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T13:04:45.000Z", "max_forks_repo_path": "TeX/complexity/rComplexity.tex", "max_forks_repo_name": "raresraf/rafMetrics", "max_forks_repo_head_hexsha": "21eb5e8210364bf70eee746d71c45f3e353dcb10", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-11T18:35:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-11T18:35:16.000Z", "avg_line_length": 65.3718199609, "max_line_length": 692, "alphanum_fraction": 0.6042807963, "num_tokens": 12752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.8418256393148981, "lm_q1q2_score": 0.7358206273032633}}
{"text": "\\section{A few examples, double complexes, Dress sseq}\\label{dress-sseq}\nWay back in 905 I remember computing the cohomology ring of $\\CP^n$ using Poincar\\'e duality.\nLet's do it fresh using the fiber sequence\n$$\nS^1\\to S^{2n+1}\\to \\CP^n\n$$\nwhere $S^1$ acts on $S^{2n+1}$.\nHere we know the cohomology of the fiber and the total space, but not the cohomology of the base.\nLet's look at the cohomology sseq for this.\nThen\n$$\nE_2^{s,t} = H^s(\\CP^n;H^t(S^1)) \\simeq H^s(\\CP^n)\\otimes H^t(S^1) Rightarrow H^{s+t}(S^{2n+1})\n$$\nThe isomorphism $H^s(\\CP^n;H^t(S^1)) \\simeq H^s(\\CP^n)\\otimes H^t(S^1)$ follows from the UCT.\n\nWe know at least that $\\CP^n$ is simply connected by the lexseq of homotopy groups.\nI don't have to worry about local coefficients.\nLet's work with the case $S^5$.\nWe know that $\\CP^n$ is simply connected, so the one-dimensional cohomology is $0$.\nThe only way to kill $E_2^{0,1}$ is by sending it via $d_2$ to $E_2^{2,0}$.\nIs this map surjective?\nYes, it's an isomorphism.\n\nNow I'm going to give names to the generators of these things; see the below diagram.\n$E_2^{2,1}$ is in total degree $3$ and so we have to get rid of it.\nI will compute $d_2$ on this via Leibniz:\n$$\nd_2(xy) = (d_2 x)y - x d_2y = (d_2 x)y = y^2\n$$\nwhich gives (iterating the same computation):\n\\begin{sseqdata}[name=example1,classes={draw = none},degree={#1}{-#1+1},classes={inner sep=1ex}]\n    \\class[\"\\Z x\"](0,1)\n    \\class[\"\\Z\"](0,0)\n    \\class[\"0\"](1,0)\n    \\class[\"0\"](1,1)\n    \\class[\"\\Z y\"](2,0)\n    \\class[\"\\Z xy\"](2,1)\n    \\class[\"0\"](3,0)\n    \\class[\"0\"](3,1)\n    \\class[\"\\Z y^2\"](4,0)\n    \\class[\"\\Z xy^2\"](4,1)\n    \\d[\"d_2\"]2(0,1)\n    \\d[\"d_2\"]2(2,1)\n\\end{sseqdata}\n\\begin{equation*}\n        \\printpage[name=example1,page=2]\n\\end{equation*}\nThis continues until the end where you reach $\\Z xy^{??}$ which is a permanent cycle since it lasts until the $E_\\infty$-page.\n\nAnother example:\nlet $C_m$ be the cyclic group of order $m$ sitting inside $S^1$.\nHow can we analyse $S^{2n+1}/C_m=:L$?\nThis is the lens space.\nWe have a map $S^{2n+1}/C_m\\to S^{2n+1}/S^1 = \\CP^n$.\nThis is a fiber bundle whose fiber is $S^1/C_m$.\nThe spectral sequence now runs:\n$$\nE^2_{s,t} = H_s(\\CP^n)\\otimes H_t(S^1/C_m) \\Rightarrow H_{s+t}(L)\n$$\nWe know the whole $E^2$ term now:\n\\begin{sseqdata}[name=example2,classes={draw = none},homological Serre grading,classes={inner sep=1ex}]\n    \\class[\"\\Z\"](0,1)\n    \\class[\"\\Z\"](0,0)\n    \\class[\"0\"](1,0)\n    \\class[\"0\"](1,1)\n    \\class[\"\\Z\"](2,0)\n    \\class[\"\\Z\"](2,1)\n    \\class[\"0\"](3,0)\n    \\class[\"0\"](3,1)\n    \\class[\"\\Z\"](4,0)\n    \\class[\"\\Z\"](4,1)\n    \\d[\"m\"]2(2,0)\n\\end{sseqdata}\n\\begin{equation*}\n        \\printpage[name=example2,page=2]\n\\end{equation*}\nIn cohomology, we have something dual:\n\\begin{sseqdata}[name=example3,classes={draw = none},degree={#1}{-#1+1},classes={inner sep=1ex}]\n    \\class[\"u\"](0,1)\n    \\class[\"1\"](0,0)\n    \\class[\"0\"](1,0)\n    \\class[\"0\"](1,1)\n    \\class[\"y\"](2,0)\n    \\class[\"uy\"](2,1)\n    \\class[\"0\"](3,0)\n    \\class[\"0\"](3,1)\n    \\class[\"y^2\"](4,0)\n    \\class[\"uy^2\"](4,1)\n    \\d[\"m\"]2(0,1)\n    \\d[\"m\"]2(2,1)\n\\end{sseqdata}\n\\begin{equation*}\n        \\printpage[name=example3,page=2]\n\\end{equation*}\nWhat's the ring structure?\nWe get that $H^\\ast(L) = \\Z[y,v]/(my,y^{n+1},yv,v^2)$ where $|v| = 2n+1$ and $|y| = 2$.\nBy the way, when $m=1$, this is $\\RP^{2n+1}$.\nThis is a computation of the cohomology of odd real projective spaces.\nRemember that odd projective spaces are orientable and you're seeing that here because you're picking up a free abelian group in the top dimension.\n\\subsection{Double complexes}\n$A_{s,t}$ is a bigraded abelian group with $d_h:A_{s,t}\\to A_{s-1,t}$ and $d_v:A_{s,t}\\to A_{s,t-1}$ such that $d_vd_h = d_hd_v$.\nAssume that $\\{(smt):s+t=n,A_{s,t}\\neq 0\\}$ is finite for any $n$.\nThen\n$$\n(tA)_n = \\bigoplus_{s+t=n}A_{s,t}\n$$\nUnder this assumption, there's only finitely many nonzero terms.\nI like this personally because otherwise I'd have to decide between the direct sum and the direct product, so we're avoiding that here.\nIt's supposed to be a chain complex.\nHere's the differential:\n$$\nd(a_{s,t}) = d_ha_{s,t} + (-1)^s d_v a_{s,t}\n$$\nThen $d^2 = 0$, as you can check.\n\\begin{question}\n    What is $H_\\ast(tA_\\ast)$?\n\\end{question}\nDefine a filtration as follows:\n$$\nF_p(tA)_n = \\bigoplus_{s+t=n,s\\leq p}A_{s,t}\\subseteq (tA)_n\n$$\nThis kinda obviously gives a filtered complex.\nLet's compute the low pages of the sseq.\nWhat is $\\gr_s(tA)$?\nWell\n$$\n\\gr_s(tA)_{s+t} = (F_s/F_{s-1})_{s+t} = A_{s,t}\n$$\nThis associated graded object has its own differential $\\gr_s(tA)_{s+t}=A_{s,t}\\xar{d_v} A_{s,t-1} = \\gr_s(tA)_{s+t-1}$.\nLet $E^0_{s,t} = \\gr_s(tA)_{s+t} = A_{s+t}$, so that $d^0 = d_v$.\nThen $E^1 = H(E^0_{s,t},d^0) = H(A_{s,t};d_v) =: H^v_{s,t}(A)$.\nSo computing $E^1$ is ez.\nWell, what's $d^1$ then?\n\nTo compute $d^1$ I take a vertical cycle that and the differential decreases the ... by $1$, so that $d^1$ is induced by $d_h$.\nThis means that I can write $E^2_{s,t} = H^h_{s,t}(H^v(A))$.\n\\begin{question}\n    You can also do $^\\prime E^2_{s,t} = H^v_{s,t}(H^h(A))$, right?\n\\end{question}\nRather than do that, you can define the transposed double complex $A^\\mathsf{T}_{t,s} = A_{s,t}$, and $d^\\mathsf{T}_h(a_{s,t}) = (-1)^s d_v(a_{s,t})$ and $d^\\mathsf{T}_v(a_{s,t}) = (-1)^t d_h a_{s,t}$.\nWhen I set the signs up like that, then\n$$\ntA^\\mathsf{T} \\simeq tA\n$$\n\\emph{as complexes} and not just as groups (because of those signs).\nThus, you get a spectral sequence\n$$\n^\\mathsf{T}E^2_{s,t} = H^v_{s,t}(H^h(A))\n$$\nconverging to the same thing.\nI'll reserve telling you about Dress' construction until Monday because I want to give a double complex example.\nIt's not ... it's just a very clear piece of homological algebra.\n\\begin{example}[UCT]\n    For this, suppose I have a (not necessarily commutative) ring $R$.\n    Let $C_\\ast$ be a chain complex, bounded below of right $R$-modules, and let $M$ be a left $R$-module.\n    Then I get a new chain complex of abelian groups via $C_\\ast\\otimes_R M$.\n    What is $H(C_\\ast\\otimes_R M)$?\n    I'm thinking of $M$ as some kind of coefficient.\n    Let's assume that each $C_n$ is projective, or at least flat, for all $n$.\n\n    Shall we do this?\n\n    Let $M\\leftarrow P_0 \\leftarrow P_1\\leftarrow \\cdots$ be a projective resolution of $M$ as a left $R$-module.\n    Then $H_\\ast(P_\\ast)\\xar{\\simeq} M$.\n    Form $C_\\ast\\otimes_R P_\\ast$: you know how to do this!\n    I'll define $A_{s,t}$ to be $C_s\\otimes_R P_t$.\n    It's got two differentials, and it's a double complex.\n    Let's work out the two sseqs.\n\n    Firstly, let's take it like it stands and take homology wrt $P$ first.\n    I'm organizing it so that $C$ is along the base and $P$ is along the fiber.\n    What is the vertical homology $H^v(A_{\\ast,\\ast})$?\n    If the $C$ are projective then tensoring with them is exact, so that $H^v(A_{s,\\ast}) = C_s\\otimes_R H_\\ast(P_\\ast)$, so that\n    $E^1_{s,t} = H^v_{s,t}(A_{\\ast,\\ast}) = C_s\\otimes M$ if $t=0$ and $0$ otherwise.\n    The spectral sequence is concentrated in one row.\n    Thus,\n    $$E^2_{s,t} = \\begin{cases}\n\tH_s(C_\\ast\\otimes_R M) & \\text{ if }t = 0\\\\\n\t0 & \\text{else}\n    \\end{cases}$$\n    This is canonically the same thing as $E^\\infty_{s,0}\\simeq H_s(tA)$.\n\n    Let me go just one step further here.\n    The game is to look at the \\emph{other} spectral sequence, where I do horizontal homology first.\n    Then $H^h(A_{\\ast,\\ast}) = H_t(C_\\ast)\\otimes P_s$ again because the $P_\\ast$ are projective.\n    Thus,\n    $$\n    E^2_{s,t} = H^v(H^h(A_{\\ast,\\ast})) = \\Tor^R_s(H_t(C),M)\\Rightarrow H_{s+t}(C_\\ast\\otimes_R M)\n    $$\n    That's the \\emph{universal coefficients spectral sequence}.\n\n    What happens if $R$ is a PID?\n    Only two columns are nonzero, and $E^2_{0,n} = H_n(C)\\otimes_R M$ and $E^2_{1,n-1} = \\Tor_1(H_{n-1}(C),M)$.\n    This exactly gives the universal coefficient exact sequence.\n\\end{example}\nLater we'll use this stuff to talk about cohomology of classifying spaces and Grassmannians and Thom isomorphisms and so on.\n", "meta": {"hexsha": "d1a3527d1a632270f7c0856f56dc904f9cc1d854", "size": 8002, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-67-dress-sseq.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "906/lec-67-dress-sseq.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "906/lec-67-dress-sseq.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 40.6192893401, "max_line_length": 201, "alphanum_fraction": 0.6428392902, "num_tokens": 2973, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.8740772335247532, "lm_q1q2_score": 0.7358206259225729}}
{"text": "\\section{The Valency Theorem; Euler Characteristic; The Riemann-Hurwitz Theorem}\r\n\\subsection{The Valency Theorem}\r\nWe want to relate the branching data of an analytic map and the topology of a compact Riemann surface.\r\n\\begin{theorem}[Valency Theorem]\r\n    Suppose $f:R\\to S$ is a non-constant analytic map between compact Riemann surfaces $R,S$, then the function $n:S\\to\\mathbb N$ defined by\r\n    $$n(q)=\\sum_{p\\in f^{-1}(\\{q\\})}m_f(p)$$\r\n    is constant on $S$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    By the identity principle, $f^{-1}(\\{q\\})$ is finite, therefore $n$ is well-defined.\r\n    As $S$ is connected, it suffices to show that $n$ is locally constant.\r\n    Let $q_0\\in S$ and $f^{-1}(q_0)=\\{p_1,\\ldots,p_k\\}$.\r\n    Our goal is to find local coordinates about the $p_i$ and $q_0$ such that $f$ is a power map.\r\n    Let $(\\psi,V)$ be a chart about $q_0$ such that $\\psi(q_0)=0$, then there exists disjoint charts $(\\phi_1,U_1),\\ldots,(\\phi_k,U_k)$ such that $p_i\\in U_i$ and $\\psi\\circ f\\circ\\phi_i^{-1}(z)=z^{m_f(p_i)}$.\\\\\r\n    Let $U=\\bigcup_iU_i$, then $U$ is open, so $R\\setminus U$ is closed subset of $R$, hence is compact.\r\n    So $K=f(R\\setminus U)$ is compact and hence closed as $S$ is Hausdorff.\r\n    Set $V'=V\\setminus K$.\r\n    Now quite obviously $f^{-1}(V')\\subset U$.\r\n    Set $U_i'=U_1\\cap f^{-1}(V')$, then $f^{-1}(V')=\\bigcup_iU_i'$, then in the charts $(\\phi_i,U_i')$ and $(\\psi,V')$, $f$ takes the form of power maps, therefore $n(q)=n(q_0)$ for any $q\\in V'$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    This constant $n$ is called the valency or degree $\\deg f$ of $f$.\r\n\\end{definition}\r\n\\begin{example}\r\n    If $f$ is a polynomial, then the degree of $f$ equals the polynomial degree of $f$.\r\n\\end{example}\r\n\\begin{corollary}[Fundamental Theorem of Algebra]\r\n    Any nonconstant polynomial of degree $d$ has exactly $d$ zeros in $\\mathbb C$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Extend it analytically to $\\mathbb C_\\infty\\to\\mathbb C_\\infty$.\r\n\\end{proof}", "meta": {"hexsha": "0f88523ee63a2e47e13b1d8850923fd03aada502", "size": 1982, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11/valency.tex", "max_stars_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_stars_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "11/valency.tex", "max_issues_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_issues_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "11/valency.tex", "max_forks_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_forks_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.9375, "max_line_length": 212, "alphanum_fraction": 0.6599394551, "num_tokens": 675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.8740772318846386, "lm_q1q2_score": 0.7358206176046194}}
{"text": "\\section{Cubic spline interpolation}\n\t\\begin{frame}{Cubic spline interpolation}\n\t\t\\begin{block}{}\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item $s_{j}$ on $[x_{j},x_{j+1}] \\rightarrow$ cubic polynomial:\n                $\\newline \\ \\ \\ s_{j}(x)=a_{j}+b_{j}(x-x_{j})+c_{j}(x-x_{j})^{2}+\n                d_{j}(x-x_{j})^{3}$\n                \\item $s_{j}(x_{j+1})=f(x_{j+1})$\n                \\item $s_{j}(x_{j+1})=s_{j+1}(x_{j+1})$\n                \\item $s^{'}_{j}(x_{j+1})=s^{'}_{j+1}(x_{j+1})$\n                \\item $s^{''}_{j}(x_{j+1})=s^{''}_{j+1}(x_{j+1})$\n\t\t\t\\end{itemize}\n\t\t\\end{block}\n        \\begin{figure}[h]\n\t\t\t\\includegraphics[width=.55\\linewidth]{img/4/spline_img_4}\n\t\t\\end{figure}\n\t\\end{frame}", "meta": {"hexsha": "1460bae79453d61f2f843737107367deed1fe765", "size": 685, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4_spline/4_3_Cubic_spline_interpolation.tex", "max_stars_repo_name": "AGH-MOWNiT-2017/lectures", "max_stars_repo_head_hexsha": "0dbc5e4df150194729ccb93d2059c041bd45dc77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-07-30T20:04:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-04T07:17:48.000Z", "max_issues_repo_path": "4_spline/4_3_Cubic_spline_interpolation.tex", "max_issues_repo_name": "AGH-MOWNiT-2017/lectures", "max_issues_repo_head_hexsha": "0dbc5e4df150194729ccb93d2059c041bd45dc77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2017-07-03T20:03:30.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-02T19:31:19.000Z", "max_forks_repo_path": "4_spline/4_3_Cubic_spline_interpolation.tex", "max_forks_repo_name": "AGH-MOWNiT-2017/lectures", "max_forks_repo_head_hexsha": "0dbc5e4df150194729ccb93d2059c041bd45dc77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-11-13T17:10:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-14T09:41:13.000Z", "avg_line_length": 40.2941176471, "max_line_length": 81, "alphanum_fraction": 0.4846715328, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475699138559, "lm_q2_score": 0.7799928951399099, "lm_q1q2_score": 0.7358044021803071}}
{"text": "\\chapter{The pull-through relation}\\label{app:pull-through-relation}\n\n\\begin{prop}\\label{prop:pull-through-relation}\n\\thmtitle{Pull-through relation}\n\\thmstatement{\n  For any non-commuting $x_1,\\ld,x_n$, and $y$ for which addition, subtraction and multiplication are defined, $x_1\\cd x_ny=\\pr{\\mp}^nyx_1\\cd x_n+\\sum_{k=1}^n\\pr{\\mp}^{n-k}x_1\\cd[x_k,y]_{\\pm}\\cd x_n$, where $[x,y]_{\\pm}\\equiv xy\\pm yx$.\n}\n\\thmproof{\n  The $n=1$ case follows from the definition of the commutator brackets: $xy=\\mp yx+[x,y]_{\\pm}$.\n  Now, assume it holds for $n$ and consider the $n+1$ case.\n  Since $x_1\\cd x_{n+1}y=x_1\\cd x_n(\\mp yx_{n+1}+[x_{n+1},y]_{\\pm})$, we find\n  \\begin{align*}\n    x_1\\cd x_{n+1}y\n  =&\\\n  \\mp\n    \\pr{\n      \\pr{\\mp}^nyx_1\\cd x_n\n    +\n      \\sum_{k=1}^n\n      \\pr{\\mp}^{n-k}\n      x_1\\cd [x_k,y]_{\\pm}\\cd x_n\n    }\n    x_{n+1}\n  +\n    x_1\\cd x_n[x_{n+1},y]_{\\pm}\n  \\\\=&\\\n    \\pr{\\mp}^{n+1}\n    yx_1\\cd x_{n+1}\n  +\n    \\sum_{k=1}^{n+1}\n    \\pr{\\mp}^{n+1-k}\n    x_1\\cd[x_k,y]_{\\pm}\\cd x_{n+1}\n  \\end{align*}\n  and, by induction, the result holds for all $n$.\n}\n\\end{prop}", "meta": {"hexsha": "d669714198b7c49f561747675b59018bd33556c4", "size": 1077, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "handouts/sections/pull-through-relation.tex", "max_stars_repo_name": "GQCG-edu/chem-8950", "max_stars_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "handouts/sections/pull-through-relation.tex", "max_issues_repo_name": "GQCG-edu/chem-8950", "max_issues_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-07-13T12:11:58.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-13T15:31:47.000Z", "max_forks_repo_path": "handouts/sections/pull-through-relation.tex", "max_forks_repo_name": "GQCG-edu/chem-8950", "max_forks_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.9166666667, "max_line_length": 236, "alphanum_fraction": 0.5905292479, "num_tokens": 483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7357952350230057}}
{"text": "\\chapter{Functions and Their Graphs}\n\nYou can think of a function as a machine: you put something into the\nmachine, it processes it, and out comes something else. Just as we\noften use the variable $x$ to stand in for a number, we often use the\nvariable $f$ to stand in for a function.\n\nFor example, we might ask, ``Let the function $f$ be defined like this:\n\n\\begin{equation*}\nf(x) = -5x^2 + 12x + 2\n\\end{equation*}\n\nWhat is the value of $f(3)$?''\n\nYou would run the number 3 through ``the machine'': $-5(3^2) + 12(3) + 2 = -7$. The answer would be ``$f(3)$ is $7$''.\n\nSome functions are not defined for every possible input. For example:\n\n\\begin{equation*}\n  f(x) = \\frac{1}{x}\n\\end{equation*}\n\n  This is defined for any $x$ except 0. The set of values that a function can process is called its \\textit{domain}.\n\n\\begin{Exercise}[title={Domain of a function}, label=function_domain]\n\n  Let the function $f$ be given by $f(x) = \\sqrt{x - 3}$.  What is its domain?\n\n\\end{Exercise}\n\\begin{Answer}[ref=function_domain]\n  You can only take the square root of nonnegative numbers, so the\n  function is only defined when $x - 3 \\geq 0$.  Thus the domain is\n  all real numbers greater than or equal to 3.\n\\end{Answer}\n\n\\section{Graphs of Functions}\n\nIf you have a function $f$, its graph is the set of pairs $(x, y)$\nsuch that $y = f(x)$.  We usually draw a picture of this set, so we\nwill use the term \\textit{graph} to mean the set and also the picture.\n\nHere is the graph of the function $f(x) = -5x^2 + 12x + 2$:\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-1,xmax=3.5,\n        ymin=-10,ymax=11,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$x$},\n        ylabel={$y$},\n        ]\n        \\addplot[no marks,sdkblue,<->] expression[domain=-0.7:3.05,samples=100]{(-5)*(x^2) + (12 * x) + 2}; \n    \\end{axis}\n\\end{tikzpicture}\n\n(Note that is just part of the graph: it goes infinitely in both\ndirections, so I could not fit the whole thing on the page.)\n\nHere is the graph of the function $f(x) = \\frac{1}{x}$:\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-7,xmax=7,\n        ymin=-7,ymax=7,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$x$},\n        ylabel={$y$},\n        ]\n        \\addplot[no marks,sdkblue,<->] expression[domain=-6.5:-0.15,samples=100]{1/x}; \n        \\addplot[no marks,sdkblue,<->] expression[domain=0.15:6.5,samples=100]{1/x}; \n    \\end{axis}\n\\end{tikzpicture}\n\n\\begin{Exercise}[title={Draw a graph}, label=draw_graph]\n\n  Let the function $f$ be given by $f(x) = -3x + 3$. Sketch its graph.\n\n\\end{Exercise}\n\\begin{Answer}[ref=draw_graph]\n\n  The graph of this function is line. Its slope is -3.  It intersects the y axis at $(0, 3)$\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-1,xmax=3,\n        ymin=-7,ymax=7,\n        xtick={1},\n        ytick={3},\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$x$},\n        ylabel={$y$},\n        ]\n        \\addplot[no marks,sdkblue,<->] expression[domain=-0.75:2.74,samples=100]{-3 * x + 3}; \n    \\end{axis}\n\\end{tikzpicture}\n  \n  \n\\end{Answer}\n\n\n\\section{Can this be expressed as a function?}\n\nNote that not all sets can be expressed as graphs of functions.  For\nexample, here is the set of points $(x,y)$ such that $x^2 + y^2 = 9$:\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-3.5,xmax=3.5,\n        ymin=-3.5,ymax=3.5,\n        ytick={-3,-2,-1,0,1,2,3},\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$x$},\n        ylabel={$y$},\n        ]\n        \\addplot[no marks,sdkblue] expression[domain=-3:3,samples=100]{sqrt(9 - x^2)}; \n        \\addplot[no marks,sdkblue] expression[domain=-3:3,samples=100]{-1 * sqrt(9 - x^2)}; \n    \\end{axis}\n\\end{tikzpicture}\n\nThis cannot be the graph of a function because what would $f(0)$ be? 3\nor -3?  This set fails what we call ``the vertical line test'': If any\nvertical line contains more than one point from the set, it isn't the graph\nof a function.  For example, the vertical line $x = 2$ would cross\nthe graph twice:\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-3.5,xmax=3.5,\n        ymin=-3.5,ymax=3.5,\n        ytick={-3,-2,-1,0,1,2,3},\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$x$},\n        ylabel={$y$},\n        ]\n        \\addplot[no marks,sdkblue] expression[domain=-3:3,samples=100]{sqrt(9 - x^2)}; \n        \\addplot[no marks,sdkblue] expression[domain=-3:3,samples=100]{-1 * sqrt(9 - x^2)};\n        \\addplot [thick, dashed] coordinates {(2,-2.5)(2,2.5)};\n\n    \\end{axis}\n\n\\end{tikzpicture}\n\n\n\n\\section{Inverses}\n\nSome functions have inverse functions. If a function $f$is a machine that turns\nnumber $x$ into $y$, the inverse (usually denoted $f^{-1}$) is the machine that turns $y$ back\ninto $x$.\n\nFor example, let $f(x) = 5x + 1$. Its inverse is\n$f^{-1}(x) = (x - 1)/5$. (Spot check it: $f(3) = 16$ and $f^{-1}(16) = 3$)\n\nDoes the function $f(x) = x^3$ have an inverse? Yes, $f^{-1}(x) =\n\\sqrt[3]{x}$. Let's plot the function (solid line) and its inverse (dashed):\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-3.5,xmax=3.5,\n        ymin=-3.5,ymax=3.5,\n        ytick={-3,-2,-1,0,1,2,3},\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$x$},\n        ylabel={$y$},\n        ]\n        \\addplot[no marks,sdkblue] expression[domain=-3:3,samples=100]{x^3}; \n        \\addplot[no marks,sdkblue,dashed] expression[domain=0:3,samples=100]{x^(1/3)}; \n        \\addplot[no marks,sdkblue,dashed] expression[domain=-3:0,samples=100]{-1 * (-1 * x)^(1/3)}; \n    \\end{axis}\n\\end{tikzpicture}\n\nThe inverse is the same as the function, just with its axes swapped.\nThis tells us how to solve for an inverse: We swap $x$ and $y$ and\nsolve for $y$.\n\nFor example, if you are given the function $f(x) = 5x + 1$, its graph\nis all $(x,y)$ such that $y = 5x + 1$.  The graph of its inverse is\nall $(x, y)$ such that $x = 5y + 1$. So you solve for $y$: $y = (x -\n1)/5$.\n\nNot every function has an inverse.  For example, $f(x) = x^2$.  Note\nthat $f(2) = f(-2) = 4$.  What would $f^{-1}(4)$ be? 2 or -2?  This\nimplies the ``horizontal line test'': If any horizontal line contains\nmore than one point of a function's graph, that function has no\ninverse.\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-3.5,xmax=3.5,\n        ymin=-1, ymax=6,\n        ytick={-1,0,1,2,3,4,5,6},\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$x$},\n        ylabel={$y$},\n        ]\n      \\addplot[no marks,sdkblue] expression[domain=-3:3,samples=100]{x^2};\n      \\addplot [thick, dashed] coordinates {(-3,4)(3,4)};\n    \\end{axis}\n\\end{tikzpicture}\n\nIn some problems, you need an inverse and you don't really need the\nwhole domain, so you trim the domain to a set you can define an\ninverse on. This allow you to say things like ``If we restrict the domain to\nthe nonnegative numbers, the function $f(x) = x^2 - 5$ has an inverse:\n$f^{-1}(x) =\\sqrt{x + 5}$.\n\nThis begs the question: What is the domain of the inverse function $f^{-1}$?\n\nIf we let $X$ be the domain of $f$, we can run every member of $X$\nthrough ``the machine'' $f$ and gather them in a set on the other\nside. This set would be the \\textit{image} of $f$. (Some people call\nthis the \\textit{range} of $f$.)\n\nWhat is the image of $f(x) = x^2 - 5$? It is the set of all real\nnumbers greater than or equal to -5. We write this\n\n\\begin{equation*}\n  \\{ x \\in {\\rm I\\!R} | x \\geq -5 \\}\n  \\end{equation*}\n\nNow we have the words we need: \\textbf{The image of the function is the domain\n  of the inverse function.}\n\nIn our example, we can use any number greater\nthan or equal to -5 as input into the inverse function.\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-5.5,xmax=7.5,\n        ymin=-6, ymax=5,\n        xtick={-3, 2},\n        ytick={-5, 1},\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        ]\n      \\addplot[no marks,sdkblue, ->] expression[domain=0:3,samples=100]{x^2 - 5} node[right] {$y = x^2 - 5$};\n      \\addplot [thick, dashed, red, ->] coordinates {(-0.05,-5)(-0.05,4.5)}\n      node [draw, red, left, align=left, yshift=-0.6cm, xshift=-0.1cm] {image of $f$ \\textit{or}\\\\ domain of $f^{-1}$};\n      \\addplot [thick, dashed, blue, ->] coordinates {(-0,-5.1)(6.75,-5.1)}\n      node [draw, align=left, above, blue, yshift=0.1cm, xshift=-1.3cm] {domain of $f$ \\textit{or}\\\\image of $f^{-1}$};\n    \\end{axis}\n\\end{tikzpicture}\n\n\n\\begin{Exercise}[title={Find the inverse}, label=simple_inverse]\n\n  Let $f(x) = (x - 3)^2 + 2$.  Sketch the graph.\n\n  Using all the real numbers as a domain, does this function have an inverse?\n\n  How would you restrict the domain to make the function invertible?\n\n  What is the inverse of that restricted function?\n\n  What is the domain of the inverse?\n\n\\end{Exercise}\n\\begin{Answer}[ref=simple_inverse]\n\n  This graph is the graph of $y = x^2$ that has been moved to the right by three units and up two units:\n \n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-1,xmax=7,\n        ymin=-1,ymax=7,\n        xtick={3, 6},\n        ytick={2, 4},\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$x$},\n        ylabel={$y$},\n        ]\n      \\addplot[no marks,sdkblue,<->] expression[domain=-2.5:6.5,samples=100]{(x - 3)^2 + 2};\n      \\addplot[dashed] coordinates {(-1, 2)(4,2)};\n      \\addplot[dashed] coordinates {(3, -1)(3, 3)};\n    \\end{axis}\n\\end{tikzpicture}\n\nTo prevent any horizontal line from containing more than one point of\nthe graph, you would need to use the left or the right side: Either\n$\\{x \\in {\\rm I\\!R}  | x \\leq 3\\}$ or $\\{x {\\rm I\\!R}| x \\geq 3\\}$. Most people will choose the\nright side; the rest of the solution will assume that you did too.\n\nTo find the inverse we swap $x$ and $y$: $x = (y -3)^2 + 2$\n\nThe we solve for $y$ to get the inverse: $y = \\sqrt{x - 2} + 3$\n\nYou can take the square root of nonnegative numbers. So the function\n$f^{-1}(x) = \\sqrt{x - 2} + 3$ is defined whenever $x$ is greater than\nor equal to 2.\n\n\\end{Answer}\n\n\\section{Graphing Calculators}\n\nOne really easy way to understand your function better is to use a graphing\ncalculator.  Desmos is a great, free online graphing calculator. \n\nIn a web browser, go to Desmos: \\url{https://www.desmos.com/calculator}\n\nIn the field on the left, enter the function $y = x^2 - x - 6$. (For\nthe exponent, just prefix it with a caret symbol: ``x\\^2''.)\n\n\\includegraphics[width=0.85\\textwidth]{Desmos.png}\n", "meta": {"hexsha": "fa852bc6eb634ce8bc2e4e6438c22500e544f350", "size": 10660, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/MatterEnergy/functions-en_US.tex", "max_stars_repo_name": "rajivjhoomuck/sequence", "max_stars_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/MatterEnergy/functions-en_US.tex", "max_issues_repo_name": "rajivjhoomuck/sequence", "max_issues_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/MatterEnergy/functions-en_US.tex", "max_forks_repo_name": "rajivjhoomuck/sequence", "max_forks_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 33.1055900621, "max_line_length": 119, "alphanum_fraction": 0.617260788, "num_tokens": 3534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990283, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.7357952322280433}}
{"text": "\\chapter{Neural Networks}\n\\label{chapter:neural networks}\n\nApplicability of models that comprised linear combinations of \\textbf{fixed basis functions} is limited by the curse of dimensionality.In order the apply such models to large-scale problems,it is necessary to adapt the basis functions to the data.\n\nSupport vector machines and relevance vector machine \\textbf{choose a subset from a fixed set of basis functions} and results in much sparser models.\n\nAn alternative approach is to fix the number of basis functions in advance but allow them to be \\textbf{adaptive},in other words to use parametric forms for the basis function \n\\section{Feed-forward Network Functions}\nThe linear models are based on linear combinations of fixed nonlinear basis functions $\\phi_j(\\vec{x})$ and take the form\n\\begin{align}\n    y(\\vec{x},\\vec{w}) = f(\\sum_{j=1}^{M}w_j\\phi_j(\\vec{x})) = f(\\vec{w}^T\\vec{\\phi}(\\vec{x}))\n\\end{align}\nwhere $f(\\cdot)$ is a nonlinear activation function in the case of classification and is the identity in the case of regression.\n\nNeural network model can be described a series of functional transformations.First construct $M$ linear combinations of the input variables $x_1,\\ldots,x_D$ in the form\n\\begin{align}\n    a_j^{(l+1)} &= \\sum_{i=1}^{D}w_{ji}^{(l)}x_i+w_{j0}^{(l)} \\\\\n\t    &= \\vec{w}^{(l)}\\vec{x}^{(l)}\n\\end{align}\nwhere $j=1,\\ldots,M$,and the superscript $(l)$ indicates the $l-the$ layer of the network.We refer the parameters $w_{ji}^{(l)}$ as \\textbf{weights} and $w_{j0}^{(l)}$ as \\textbf{biases}.The quantity $a_j$ are known as \\textbf{activations}.Each of them is then transformed using \\textbf{activation function} $h(\\cdot)$ to give\n\\begin{align}\n    z_j=h(a_j)\n\\end{align}\nThese quantities correspond to the outputs of the basis functions in linear model that,in the context of neural networks,are called \\textbf{hidden units}.The nonlinear functions $h(\\cdot)$ are generally chosen to be sigmoidal or the '$tanh$' function.\n\nThe transformation of the following layer of the network,combine these values to give \\textbf{output unit activations}\n\\begin{align}\n    a_k=\\sum_{j=1}^{M}w_{kj}^{(2)}z_j+w_{k0}^{(2)}\n\\end{align}\nwhere $k=1,\\ldots,K$,and $K$ is the total number of outputs.\n\n\\begin{figure}\n    \\includegraphics[ ]{figures/prml/Figure5.1.jpg}\n    \\caption{Network diagram for two-layer neural network}\n\\end{figure}\n\nFor regression,$y_k=a_k$ and binary classification,we can use $y_k=\\sigma(a_k)=\\dfrac{1}{1+\\exp(-a)}$.Finally,for multiclass problems,a \\textbf{softmax} activation function is used.\\textbf{Unit activation function} is discussed later.\n\nThe process of evaluating the output of the network diagram is interpreted as a \\textbf{forward propagation} of information through the network.Deterministic rather than stochastic variables of internal nodes do not represent probabilistic graphical models.Each (hidden or output) unit in such network computes a function given by\n\\begin{align}\n    z_k=h(\\sum_j w_{kj}z_j)\n\\end{align}\nwhere the sum runs over all units that send connections to unit $k$ (including the bias parameter).\n\n\\subsection{Weight-space symmetries}\nConsider a two-layer network as shown before.For $M$ hidden units,there will be $M$ 'sign-flip' symmetries,i.e.,$2^M$ equivalent weight vectors.Similarly,interchanging the values of all the weights(and the bias) can give rise to the same mapping function from inputs to outputs represented by the network.There will be $M!$ equivalent weight vectors.The network have an overall weight-space symmetry factor of $M!2^M$.\n\n\n\\section{Network Training}\nGiven a training set comprising a set of input vectors ${\\vec{x}_n}$,where $n=1,\\ldots,N$,together with a corresponding set of target vectors ${\\vec{t}_n}$,we minimize the error function.We can provide a probabilistic interpretation to the network outputs.\n\nFor regression,and for the moment we consider a single target variable $t$ that can take any real value.We assume that $t$ has a Gaussian distribution with an $\\vec{x}$-dependent mean,which is given by the output of the neural network,so that\n\\begin{align}\n    p(t|\\vec{w},\\vec{w})=\\mathcal{N}(t|y(\\vec{x},\\vec{w}),\\beta^{-1})\n\\end{align}\nwhere $\\beta$ is the precision (inverse variance) of the Gaussian noise.Maximize the likelihood function as in linear models.View the network as having an output activation function that id the identity,so that $y_k=a_k$.The corresponding sum-of-squares error function has the property\n\\begin{align}\\label{eqn:output activation function derivative}\n    \\dfrac{\\partial E}{\\partial a_k}=\\dfrac{\\partial E}{\\partial y_k}=y_k - t_k\n\\end{align}\n\nFor binary classification in which $t\\in{0,1}$,consider a network having a single output whose activation function is a logistic sigmoid\n\\begin{align}\n    y=\\sigma(a)=\\dfrac{1}{1+\\exp(-a)}\n\\end{align}\nWe can interpret $y(\\vec{x},\\vec{w})$ as the conditional probability $p(\\mathcal{C}_1|\\vec{x})$.the conditional distribution of targets given inputs is then a Bernoulli distribution of the form\n\\begin{align}\n    p(t|\\vec{x},\\vec{w})=y(\\vec{x},\\vec{w})^t\\{{1-y(\\vec{x},\\vec{w})}^{1-t}\\}\n\\end{align}\n\nFor $K$ separate binary classifications,the conditional distribution of the targets is\n\\begin{align}\n    p(\\vec{t}|\\vec{x},\\vec{w})=\\prod_{k=1}^{K}y_k(\\vec{x},\\vec{w})^t_k[1-y(\\vec{x},\\vec{w})]^{1-t_k}\n\\end{align}\nTaking the negative logarithm of the corresponding likelihood function,we get \\textbf{cross-entropy} error function\n\\begin{align}\n    E(\\vec{w})=-\\sum_{n=1}^{N}\\sum_{k=1}^{K}{t_{nk}\\ln y_{nk}+(1-t_{nk})\\ln(1-y_{nk})}\n\\end{align}\nThe derivative of the error function with respect to the \\textbf{activation} for a particular output unit is\n\\begin{align}\n    \\dfrac{\\partial E_n}{\\partial a_k}\n    &=\\dfrac{\\partial {-\\sum_{k=1}^{K}{t_{nk}\\ln y_{nk}+(1-t_{nk})\\ln(1-y_{nk})} }}{\\partial a_k} \\\\\n    &=-{t_{k} \\dfrac{y_{k}(1-y_{k})}{y_{k}} +(1-t_{k}\\dfrac{-y_{k}(1-y_{k})}{1-y_{k}}) } \\\\\n    &={y_{k}-t_{k}}\n\\end{align}\n\nFollowing the logistic regression,the \\textbf{output unit activation} is given by the \\textbf{softmax} function\n\\begin{align}\n    y_k(\\vec{x},\\vec{w})=\\dfrac{\\exp(a_k(\\vec{x},\\vec{w}))}{\\sum_j\\exp(a_j(\\vec{x},\\vec{w})) }\n\\end{align}\n\n\\subsection{Parameter optimization}\nTurn next to the task of finding a weight vector $\\vec{w}$ which minimizes the chosen function $E(\\vec{w})$.\n\\begin{figure}\n    \\includegraphics{figures/prml/Figure5.5.jpg}\n    \\caption{geometrical view of the error function $E(\\vec{w})$ as a surface sitting over weight space.A is a local minimum and B is the global minimum.The local gradient of the error surface is given by the vector $\\nabla E$.}\n\\end{figure}\nResort to \\textbf{iterative} numerical procedures.Most techniques involve choosing some initial value $\\vec{w}^{(0)}$ for weight vector and then moving through weight space in a succession of steps of the form\n\\begin{align}\n    \\vec{w}^{(\\eta+1)}=\\vec{w}^{(\\eta)}+\\Delta \\vec{w}^{(\\eta)}\n\\end{align}\n\nMany algorithms make use of gradient information,evaluating $\\nabla E(\\vec{w})$  at the new weight vector $\\vec{w}^{(\\eta+1)}$.\n\n\\subsection{Local quadratic approximation}\nConsider the \\textbf{Taylor expansion} of $E(\\vec{w})$ around some point in weight space.\n\n\\subsection{Use of gradient information}\nIt is possible to evaluate the gradient of an error function efficiently by means of the backpropagation procedure.Because each evaluation of $\\nabla E$ brings $W$ items of information,we might hope to find the minimum of the function in $O(W)$ gradient evaluations.Each such evaluation takes only $O(W)$ steps and so the minimum can be now found in $O(W^2)$ steps.\n\\subsection{Gradient descent optimization}\n\\textbf{Batch gradient descent}\n\\begin{align}\n    \\vec{w}^{(\\tau+1)}=\\vec{w}^{(\\tau)}-\\eta\\nabla E(\\vec{w})^{(\\tau)}\n\\end{align}\nwhere the parameter $\\eta>0$ is known as the \\textbf{learning rate}.\n\nMore efficient methods than this poor algorithm are \\textbf{conjugate gradients} and \\textbf{quasi-Newton} methods,which are more robust and much faster.\\textbf{On-line} version of gradient has also proved useful in practice.On-line gradient descent,known as \\textbf{sequential gradient descent } or \\textbf{stochastic gradient descent},makes an update to the weight vector based on one data point at a time,so that\n\\begin{align}\n    \\vec{w}^{(\\tau+1)}=\\vec{w}^{(\\tau)}-\\eta \\nabla E(\\vec{w}^{(\\tau)})\n\\end{align}\n\n\n\\section{Error Backpropagation}\nThe goal in this section is to find an efficient technique for evaluating the gradient of an error function $E(\\vec{w})$ for a feed-forward neural network.This can be achieved using a local message passing scheme in which information is sent alternately forwards and backwards through the network,known as \\textbf{error backpropagation} or \\textbf{backprop}.\n\n\\subsection{Evaluation of error-function derivatives}\nMany error functions of practical interest,for instance those defined by maximum likelihood for a set of i.i.d data,comprise a sum of terms,on for each data point,so that\n\\begin{align}\n    E(\\vec{w})=\\sum_{n=1}^{N}E_n(\\vec{w})\n\\end{align}\n\nIn a general feed-forward network,each unit computes a weighted sum of its inputs of the form\n\\begin{align}\n    a_j=\\sum_i w_{ji} z_i\n\\end{align}\nwhere $z_i$ is the activation of a unit that sends a connection to unit $j$ and $w_{ji}$ is the weight associated with that connection.The sum is transformed by an activation function $h(\\cdot)$ to give the activation $z_j$ of unit $j$ in the form\n\\begin{align}\n    z_j=h(a_j)\n\\end{align}\n\nEvaluate the derivate of $E_n$ with respect to a weight $w_{ji}$,applying the \\textbf{chain rule} for partial derivatives\n\\begin{align}\n    \\dfrac{\\partial E_n}{\\partial w_{ji}}=\\dfrac{\\partial E_n}{\\partial \\vec{a}_j}\\dfrac{a_j}{\\partial w_{ji}}\n\\end{align}\nNow introduce a notation\n\\begin{align}\n    \\delta_j \\equiv \\dfrac{\\partial E_n}{\\partial a_j}\n\\end{align}\nreferred as \\textbf{errors}.\nUsing the sum form\n\\begin{align}\n    \\dfrac{\\partial a_j}{\\partial w_{ji}} = z_i\n\\end{align}\nSubstituting them back\n\\begin{align}\n    \\dfrac{\\partial E_n}{\\partial w_{ji}}=\\delta_j z_i.\n\\end{align}\nFor the output units,we have\n\\begin{align}\n    \\delta_k=y_k-t_k\n\\end{align}\n\nFor hidden units,make use of the chain rule for partial derivatives\n\\begin{align}\n    \\delta_j\\equiv \\dfrac{\\partial E_n}{\\partial a_j}=\n    \\sum_k \\dfrac{\\partial E_n}{\\partial a_k}\\dfrac{\\partial a_k}{\\partial a_j} \\\\\n\\end{align}\nwhere the sum runs over all units $k$ to which unit $j$ sends connections.\n\\begin{align}\n    \\because \\delta_k &= \\dfrac{\\partial E_n}{\\partial a_k}\\\\\n    \\therefore\n    \\delta_j\\equiv \\dfrac{\\partial E_n}{\\partial a_j} &=\n    \\sum_k \\dfrac{\\partial E_n}{\\partial a_k}\\dfrac{\\partial a_k}{\\partial a_j} \\\\\n    &=\\sum_k \\delta_k\\dfrac{\\partial a_k}{\\partial a_j} \\\\\n    &=\\sum_k \\delta_k h'(a_j)w_{kj} \\\\\n    &= h'(a_j)\\sum_k w_{kj}\\delta_k\n\\end{align}\n\n\\subsubsection{back-propagation algorithm wrap-up}\n\nWe'll use $\\vec{w}_{ij}^{l}$ to denote the \\textbf{weight} for the connection from the $k$th neuron in the $(l-1)$th layer to the $j$th neuron in the $(l)$th layer.And $b_j^l$  for the bias of the $j$th neuron in the $l$th layer, $a_j^l$ for the activation(weighted input) of the $j$th neuron in the $l$th layer,$\\sigma$ denotes the element-wise activation function,$z_j^l$ denotes the output of $j$th neuron in the $l$th layer.\nThen we have\n\\begin{align}\n\t\\vec{a}^l &\\equiv \\vec{W}^l \\vec{z}^{l-1}+\\vec{b}^l \\\\\n\t\\vec{z}^{l} &\\equiv \\sigma(\\vec{a}^{l})\n\\end{align}\n\n$s\\odot t$ denotes \\textbf{element-wise product} of two matrices (vectors):\n\\begin{align}\n(s\\odot t)_j = s_jt_j\n\\end{align}\n\nDefine the error $\\sigma_j^l$ of neuron $J$ in the layer $l$ by\n\\begin{align}\n\\vec{\\delta}^l_j \\equiv \\frac{\\partial C}{\\partial \\vec{a}^l_j}\n\\end{align}\n\nUsing \\textbf{chain rule of derivatives},the error in the output layer is:\n\\begin{eqnarray} \n\\delta^L_j &=& \\frac{\\partial C}{\\partial a^L_j} \\\\\n&=& \\sum_k \\frac{\\partial C}{\\partial z^L_k} \\frac{\\partial z^L_k}{\\partial a^L_j} \\\\\n&=& \\frac{\\partial C}{\\partial z^L_j} \\frac{\\partial z^L_j}{\\partial a^L_j},\\text{if output only depends on same neuron's input } \\\\\n&=& \\frac{\\partial C}{\\partial \\vec{z}^L_j} \\sigma'(\\vec{a}^L_j).\n\\end{eqnarray}\nAnd the matrix-based form is:\n\\begin{eqnarray} \n\\delta^L & = & \\nabla_z C \\odot \\sigma'(a^L). \\\\\n\\delta^L & = &\\Sigma'(a^L) \\nabla_z C,\n\\end{eqnarray}\nwhere $\\Sigma'(z^L)$ is a square matrix whose diagonal entries are the values $\\sigma'(z^L)$, and whose off-diagonal entries are zero.\n\nPropagation (recursive relationship) in hidden layer:\n\\begin{eqnarray} \n\\delta_j^l &=& \\frac{\\partial C}{\\partial a^l_j}\\\\\n&=& \\sum_k \\frac{\\partial C}{\\partial a^{l+1}_k} \\frac{\\partial a^{l+1}_k}{\\partial a^l_j}\\\\ \n&=& \\sum_k \\frac{\\partial a^{l+1}_k}{\\partial a^l_j} \\delta^{l+1}_k, \\\\\n\\because a^{l+1}_k &=& \\sum_j w^{l+1}_{kj} z^l_j +b^{l+1}_k = \\sum_j w^{l+1}_{kj} \\sigma(a^l_j) +b^{l+1}_k. \\\\\n\\therefore \\frac{\\partial a^{l+1}_k}{\\partial a^l_j} &=& w^{l+1}_{kj} \\sigma'(a^l_j) \\\\\n\\therefore\n\\delta^l_j &=& \\sum_k w^{l+1}_{kj}  \\delta^{l+1}_k \\sigma'(a^l_j) \\\\\n\\delta^l &=& ((\\vec{W}^{l+1})^T \\delta^{l+1}) \\odot \\sigma'(\\vec{a}^l), \\\\\n\\delta^l &=& \\Sigma'(a^l) (w^{l+1})^T \\delta^{l+1}.\\\\\n\\end{eqnarray}\n\nRate of change of cost with respect to bias in the network:\n\\begin{eqnarray}  \n\\frac{\\partial C}{\\partial b^l_j} \n&=\\frac{\\partial C}{\\partial \\vec{a}^l_j}\\frac{\\partial \\vec{a}^l_j}{\\partial b^l_j} \\\\\n&= \\frac{\\partial C}{\\partial \\vec{a}^l_j} \\cdot 1 \n&=\\vec{\\delta}^l_j \n\\end{eqnarray}\n\nRate of change of the cost with respect to any weight matrix in the network:\n\\begin{align}\n    \\frac{\\partial C}{\\partial w^l_{jk}} \n&= \\frac{\\partial C}{\\partial \\vec{a}^l_j}\\frac{\\partial \\vec{a}^l_j}{\\partial w^l_{jk}}\\\\\n&= z^{l-1}_k \\delta^l_j \\\\\n\\frac{\\partial C}{\\partial w} &= \\vec{\\delta_{\\rm out}} \\vec{z_{\\rm in}}^T,\n\\end{align}\n\nWhen dealing with \\textbf{batch} training instances, we sum derivatives with respect to parameters over these instances.\n\n\\subsection{Efficiency of back propagation}\n\n\\subsection{The Jacobian matrix}\nBack-propagation can also be applied to the calculation of other derivatives.Consider the evaluation of the \\textbf{Jacobian matrix},whose elements are given by the derivatives of the network outputs with respects to the inputs\n\\begin{align}\n    J_{ki}=\\dfrac{\\partial y_k}{\\partial x_i}\n\\end{align}\n\n\n\\section{The Hessian Matrix}\n\n\\section{Regularization in Neural Networks}\n\n\n\n\n\n\n\n\n\n\n\\section{Mixture Density Networks}\n\n\\section{Bayesian Neural Networks}\n", "meta": {"hexsha": "c3e9871454eaf0f312e61d5b514d00134811c013", "size": 14461, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/Neural Networks.tex", "max_stars_repo_name": "Alexoner/Statistical-formula", "max_stars_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-02-15T17:00:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-24T13:46:00.000Z", "max_issues_repo_path": "prml/Neural Networks.tex", "max_issues_repo_name": "Alexoner/Statistical-formula", "max_issues_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "prml/Neural Networks.tex", "max_forks_repo_name": "Alexoner/Statistical-formula", "max_forks_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-02-25T15:40:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-25T04:26:03.000Z", "avg_line_length": 53.9589552239, "max_line_length": 428, "alphanum_fraction": 0.7162713505, "num_tokens": 4458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7357952315911235}}
{"text": "\n\\section{Legendre Polynomials}\n\nThe routines in this section compute Legendre polynomials,  normalized associated Legendre polynomials and their derivatives in formats useful to scattering. Associated Legendre polynomials are computed at both positive and negative $m$ and automatically include the Condon-Shortley phase.  \n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Legendre Polynomials, $P_l(x)$}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\n\nThe Legendre polynomials satisfy the equation\n\\begin{equation}\n\\dfrac{d}{dx} \\left[ (1-x^2)\\dfrac{d}{dx}P_l(x)\\right] + l(l+1)P_l(x) = 0\n\\end{equation}\n\nfor $-1 \\le x \\le 1$, with the following recurrence relation\n\\begin{equation}\n(l+1)P_{l+1}(x) = (2l+1)xP_l(x) - lP_{l-1}(x) \\label{plrec}\n\\end{equation}\n\nThe routine \\texttt{legendrePl} returns $P_l(x)$ on a 2D array with degrees $0$ to $L$ along rows and evaluation points along columns.  \n\n\n{\\footnotesize\n\\VerbatimInput{\\code/LegendrePolynomials/legendrePl.m}\n}\n\n\\clearpage\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Legendre Polynomial Derivative, $d/dx P_l(x)$}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nThe derivative of the Legendre polynomials satisfies either of the following recurrence relations\n\\begin{equation}\n\\dfrac{x^2-1}{l}\\dfrac{d}{dx}P_l(x) = xP_l(x) - P_{l-1}(x)\n\\end{equation}\n\n\\begin{equation}\n(2l+1)P_l(x) = \\dfrac{d}{dx}(P_{l+1}(x) - P_{l-1}(x))\n\\end{equation}\n\nThe first has a divide by zero when $x$ is 1 or -1.  Rearranging the second equation we get the following recurrence \n\\begin{equation}\n\\dfrac{d}{dx}P_{l+1}(x) = (2l+1)P_l(x) + \\dfrac{d}{dx} P_{l-1}(x)\n\\end{equation}\n\n\\noindent which is safe on $x=[-1, 1]$.  Initial conditions are the special cases $P'_0(x) = 0$ and $P'_1(x) = 1$, and the derivative has the feature that $P'_l(1) = l(l+1)/2$.  The routine \\texttt{legendrePlp} is like \\texttt{legendrePl}: it returns $d/dx P_l(x)$ on a 2D array with degrees $0$ to $L$ along rows and evaluation points along columns.  \n\n{\\footnotesize\n\\VerbatimInput{\\code/LegendrePolynomials/legendrePlp.m}\n}\n\n\\clearpage\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Normalized Associated Legendre Polynomials, $\\widetilde{P}_l^m(x)$}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\n\nThe associated Legendre polynomials, $P_l^m(x)$, are given by\n\\begin{equation}\nP_l^m(x) = \\dfrac{(-1)^m}{2^l l!} (1-x^2)^{m/2} \\dfrac{d^{l+m}}{dx^{l+m}} (x^2 - 1)^l \\label{plm}\n\\end{equation}\n\n\\noindent for integers $l$ and $m$ such that $l \\ge 0$ and $-l \\le m \\le l$.  The Condon-Shortley phase is included in the definition of the associated Legendre polynomials. The following identity relates positive and negative $m$\n\\begin{equation}\nP_l^{-m}(x) = (-1)^m \\dfrac{(l-m)!}{(l+m)!} P_l^m(x)\\\n\\label{eq2}\n\\end{equation}\n\nThe normalized associated Legendre polynomials $\\widetilde P_l^m(x)$ are recommended for scattering computations because they avoid direct computation of factorials. These are given by\n\\begin{equation}\n\\widetilde P_l^m(x) = \\sqrt{\\dfrac{(l + \\frac{1}{2})(l-m)!}{(l+m)!}} P_l^m(x) \\label{plmnorm}\n\\end{equation}\n\n\\noindent where\n\\begin{equation}\n\\widetilde P_l^{-m}(x) = (-1)^m \\widetilde{P}_l^m(x)\n\\end{equation}\n\nThe routine \\texttt{Plm} returns the normalized associated Legendre polynomials for $l=0,...,L$, all $\\pm m$, linearly indexed (see Chapter \\ref{chap:wavefunctions} on linear indexing). The result is returned with harmonics indexed along rows, and evaluation points along columns. It calls Matlab's \\texttt{legendre} with the \\texttt{'norm'} option, which returns $m = 0,...,l$ and an extra factor of $(-1)^m$. \\texttt{Plm} takes out the extra $(-1)^m$ from Matlab's normalization so that the one factor of $(-1)^m$ in \\eqref{plm} remains. %Use the switch \\texttt{'scalar'} to include the $(l,m) = (0,0)$ term. The total number of harmonics is $N = L^2 + 2L$ or $N = L^2 + 2L + 1$ for scalar.\n\n{\\footnotesize\n\\VerbatimInput{\\code/LegendrePolynomials/Plm.m}\n}\n\n\n\n%\n%\\subsection{Normalized Associated Legendre Polynomials Derivative, $d/dx\\widetilde{P}_l^m(x)$}\n%\n%The derivative of the associated Legendre polynomials has several recurrence relations that are given in terms of the non-differentiated functions, but they all have the problem of divide by zero at $\\pm1$. A mixed recurrence on $l$ can be derived starting with the unnormalized recurrence\n%\\eq{(l-m+1)P_{l+1}^m(x) = (2l+1)xP_l^m(x) - (l+m)P_{l-1}^m(x)}\n%\n%and differentiating, which gives\n%\\eq{(l-m+1)\\dfrac{d}{dx}P_{l+1}^m(x) =  (2l+1)\\left( P_l^m(x) +  x\\dfrac{d}{dx}P_l^m(x)\\right)- (l+m)\\dfrac{d}{dx}P_{l-1}^m(x) \\label{dpplus}}\n%\n%Substituting the expression for the normalized Legendre polynomials into \\eqref{dpplus} and simplifying\n%%\n%%\\eq{\\sqrt{\\dfrac{(l+m)!}{(l + \\frac{1}{2})(l-m)!}} \\widetilde P_l^m(x) =  P_l^m(x)}\n%%\n%%\\ea{(l-m+1)\\sqrt{\\dfrac{(l+1+m)!}{(l +1+ \\frac{1}{2})(l+1-m)!}} \\dfrac{d}{dx}\\widetilde P_{l+1}^m(x) &=&  (2l+1)\\sqrt{\\dfrac{(l+m)!}{(l + \\frac{1}{2})(l-m)!}} \\left( \\widetilde P_l^m(x)   +  x\\dfrac{d}{dx}\\widetilde P_l^m(x)\\right)\\\\\n%%\\ &\\ & - (l+m)\\sqrt{\\dfrac{(l-1+m)!}{(l -1 + \\frac{1}{2})(l-1-m)!}} \\dfrac{d}{dx}\\widetilde P_{l-1}^m(x)  \\label{dpplus} }\n%%\n%%\\ea{(l-m+1)\\sqrt{\\dfrac{(l+1+m)(l+m)}{(l +1+ \\frac{1}{2})(l+1-m)(l-m)}} \\dfrac{d}{dx}\\widetilde P_{l+1}^m(x) &=&  (2l+1)\\sqrt{\\dfrac{(l+m)}{(l + \\frac{1}{2})(l-m)}} \\left( \\widetilde P_l^m(x)   +  x\\dfrac{d}{dx}\\widetilde P_l^m(x)\\right)\\\\\n%%\\ &\\ & - (l+m)\\sqrt{\\dfrac{1}{(l -1 + \\frac{1}{2})}} \\dfrac{d}{dx}\\widetilde P_{l-1}^m(x)  \\label{dpplus} }\n%\n%\\ea{  \\dfrac{d}{dx}\\widetilde P_{l+1}^m(x) &=&   a_{l,m} \\left( \\widetilde P_l^m(x)   +  x\\dfrac{d}{dx}\\widetilde P_l^m(x)\\right) -  b_{l,m} \\dfrac{d}{dx}\\widetilde P_{l-1}^m(x)  }\n%%\n%%\\ea{a_{l,m} &=& \\dfrac{1}{(l-m+1)}\\sqrt{\\dfrac{(l +1+ \\frac{1}{2})(l+1-m)(l-m)}{(l+1+m)(l+m)}}  (2l+1)\\sqrt{\\dfrac{(l+m)}{(l + \\frac{1}{2})(l-m)}} \\\\\n%%b_{l,m} &=&  \\dfrac{1}{(l-m+1)}\\sqrt{\\dfrac{(l +1+ \\frac{1}{2})(l+1-m)(l-m)}{(l+1+m)(l+m)}}(l+m)\\sqrt{\\dfrac{1}{(l -1 + \\frac{1}{2})}}}\n%\n%\\ea{a_{l,m} &=&  2 \\sqrt{\\dfrac{(l + \\frac{3}{2})(l + \\frac{1}{2}) }{(l-m+1)(l+m+1) }}   \\\\\n%b_{l,m} &=&   \\sqrt{\\dfrac{(l +\\frac{3}{2}) (l-m)(l+m)}{(l - \\frac{1}{2})(l-m+1)(l+m+1) }} }\n%\n%This is initialized along the $m = l$ diagonal with \n%\\eq{ \\dfrac{d}{dx} \\widetilde P_{0}^0(x) = 0}\n%\\eq{  \\dfrac{d}{dx} \\widetilde P_{l+1}^l(x) = \\sqrt{\\dfrac{(2l+1)(l + \\frac{3}{2})}{(l + \\frac{1}{2})}} \\left(\\widetilde P_l^l(x) + x \\dfrac{d}{dx} \\widetilde P_{l}^l(x) \\right)}\n%\n%which comes from differentiating $P_{l+1}^l (x) = x(2l+1)P_l^l(x)$ and normalizating. \n%\n%%\\eq{\\sqrt{\\dfrac{(l+m)!}{(l + \\frac{1}{2})(l-m)!}} \\widetilde P_l^m(x) =  P_l^m(x)}\n%\n%\n%%\\eq{ \\sqrt{\\dfrac{(l+1+m)!}{(l + 1 + \\frac{1}{2})(l+1-m)!}} \\widetilde P_{l+1}^m(x) = x(2l+1) \\sqrt{\\dfrac{(l+m)!}{(l + \\frac{1}{2})(l-m)!}} \\widetilde P_l^m(x) }\n%%\n%%\\eq{ \\sqrt{\\dfrac{(l+1+l)!}{(l + 1 + \\frac{1}{2})}} \\widetilde P_{l+1}^l(x) = x(2l+1) \\sqrt{\\dfrac{(l+l)!}{(l + \\frac{1}{2})}} \\widetilde P_l^l(x) }\n%%\n%%\\eq{ \\sqrt{\\dfrac{(2l+1)}{(l + 1 + \\frac{1}{2})}} \\widetilde P_{l+1}^l(x) = x(2l+1) \\sqrt{\\dfrac{1}{(l + \\frac{1}{2})}} \\widetilde P_l^l(x) }\n%\n%%\\eq{  \\widetilde P_{l+1}^l(x) = c_{l,m} x  \\widetilde P_l^l(x) }\n%\n%\n%This recurrence requires both degrees less than or equal to $l$.  This is given by the routine \\texttt{Plmp}, and has the same structure as \\texttt{Plm}.   \n%\n%{\\footnotesize\n%\\VerbatimInput{\\code/LegendrePolynomials/Plmp.m}\n%}\n%\n%\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Normalized Associated Legendre Polynomials Derivative, $d/dx\\widetilde{P}_l^m(x)$}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\n\nThe derivative of the normalized associated Legendre polynomials is found by substituting \\eqref{plmnorm} into the following non-normalized recurrence relation for the associated Legendre polynomial derivative:\n\\eq{(x^2-1) \\dfrac{d}{dx} P_l^m(x) = lx P_l^m(x) - (l+m)P_{l-1}^m(x)}\n\nwhich gives\n\\begin{equation}\n\\dfrac{d}{dx}\\widetilde P_l^m(x) = \\dfrac{1}{x^2-1}\\left( lx \\widetilde P_l^m(x) - \\sqrt{\\dfrac{(l+1/2)}{(l-1/2)}}\\sqrt{(l+m)(l-m)} \\widetilde P_{l-1}^m(x)\\right)\n\\end{equation}\n\nThis recurrence only requires $\\widetilde P_l^m(x)$ to be computed at degrees less than or equal to $l$.  This is computed by the routine \\texttt{Plmp}, and has the same structure as \\texttt{Plm}, which returns $l=0,...,L$, all $\\pm m$, linearly indexed (see Chapter \\ref{chap:wavefunctions}). This version is not suitable at the end points $x = [-1, 1]$. In fact, the difficultly of computing the derivative of the associated Legendre polynomials at the end-points is well-known, and other routines can be found elsewhere. However, we use this routine in scattering problems when the poles do not need to be sampled, for example, when using Gauss-Legendre quadrature as the basis for spherical harmonic transforms (see Chapter \\ref{chap:fmm}). \n\n{\\footnotesize\n\\VerbatimInput{\\code/LegendrePolynomials/Plmp.m}\n}\n\n\\clearpage\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Normalized Associated Legendre Polynomials, $m\\widetilde{P}_l^m(\\cos\\theta)/\\sin\\theta $}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\n\nThe variant $m\\widetilde{P}_l^m(\\cos\\theta)/\\sin\\theta $ is needed for vector wave functions. Numerically, direct division by $\\sin\\theta$ is a problem at the poles, however, analytically, dividing by $\\sin\\theta$ is harmless because $P_l^m(\\cos\\theta) \\sim \\sin^m\\theta$.  With the right recurrence relation, it can be computed directly.  Start with the following unnormalized recurrence relation\n\\begin{equation}\n\\dfrac{m}{\\sin\\theta}P_l^m(\\cos\\theta) = -\\dfrac{1}{2}\\left(P_{l-1}^{m+1}(\\cos\\theta) + (l+m-1)(l+m)P_{l-1}^{m-1}(\\cos\\theta) \\right) \n\\end{equation}\n\nThen substituting \\eqref{plmnorm} and canceling like factorials\n\\begin{eqnarray}\n\\dfrac{m}{\\sin\\theta}\\widetilde P_l^m(\\cos\\theta)& =& \\dfrac{1}{2}\\sqrt{\\dfrac{l-\\frac{1}{2}}{l+\\frac{1}{2}}}\\left(\\sqrt{(l-m)(l-m-1)}\\widetilde P_{l-1}^{m+1}(\\cos\\theta)\\right. \\nonumber \\\\\n\\ & \\ & +\\left. \\sqrt{(l+m)(l+m-1)}\\widetilde P_{l-1}^{m-1}(\\cos\\theta) \\right) \n\\end{eqnarray}\n\nThis is computed by the routine \\texttt{mPlmsin}, and has similar structure to \\texttt{Plm}.  It returns degrees $l = 1,..,L$, all $m$, linearly indexed along rows with evaluation points along columns.  We exclude the monopole because this variant is only used for vector wave functions. It uses the initial condition\n\\begin{equation}\n\\dfrac{(1)}{\\sin\\theta}\\widetilde P_1^1(\\cos\\theta) = \\sqrt{\\dfrac{3}{4}}\n\\end{equation}\n\nTechnically this initial condition should have a negative sign. However, we iterate on the output of the Matlab's \\texttt{legendre}, which has an extra negative sign. Therefore, we adjust the negative signs at the end of the routine so that the outputs will match a direct computation of the quantity $m\\widetilde{P}_l^m(\\cos\\theta)/\\sin\\theta $ when using \\texttt{Plm}. \n\n{\\footnotesize\n\\VerbatimInput{\\code/LegendrePolynomials/mPlmsin.m}\n}\n\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Normalized Associated Legendre Polynomials Derivative, $d/d\\theta\\widetilde{P}_l^m(\\cos\\theta)$}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\n\nThe variant $d/d\\theta\\widetilde{P}_l^m(\\cos\\theta)$ is the derivative of the normalized associated Legendre polynomials with respect to $\\theta$ when the argument is $\\cos\\theta$.  Start with the recurrence relation for unnormalized Legendre polynomials \n\\begin{eqnarray}\n\\dfrac{d}{d\\theta}P_l^m(\\cos\\theta) &= &-\\sin\\theta \\dfrac{d}{d\\cos\\theta}P_l^m(\\cos\\theta)  \\\\\n\\ &=& -\\dfrac{1}{2}\\left((l+m)(l-m+1)P_l^{m-1}(\\cos\\theta) -P_l^{m+1}(\\cos\\theta)\\right) \n\\end{eqnarray}\n\nSubstituting the expression for the normalized Legendre polynomials and canceling like factorials \n\\eq{\n\\dfrac{d}{d\\theta}\\widetilde P_l^m(\\cos\\theta) = \\dfrac{1}{2}\\left(\\sqrt{(l+m)(l-m+1)}\\widetilde P_l^{m-1}(\\cos\\theta) - \\sqrt{(l-m)(l+m+1)}\\widetilde P_l^{m+1}(\\cos\\theta)\\right)  \n}\n%\n%\\begin{eqnarray}\n%\\dfrac{d}{d\\theta}\\widetilde P_l^m(\\cos\\theta) &=& \\dfrac{1}{2}\\left(\\sqrt{(l+m)(l-m+1)}\\widetilde P_l^{m-1}(\\cos\\theta)\\right. \\nonumber \\\\\n%\\ & \\ & -\\left. \\sqrt{(l-m)(l+m+1)}\\widetilde P_l^{m+1}(\\cos\\theta)\\right)  \n%\\end{eqnarray}\n\nThis recurrence only requires degrees equal to $l$.  This is given by the routine \\texttt{Plmp2}, and has similar structure to \\texttt{Plm}.  It returns degrees $l = 1,..,L$, all $m$, linearly indexed in rows and evaluation points along columns.  We exclude the monopole because this variant is used for vector wave functions, and because the derivative for $(l,m) = (0,0)$ is zero.  It uses the initial condition \n\\begin{equation}\n\\dfrac{d}{d\\theta}\\widetilde{P}_l^0(\\cos\\theta) = -\\sqrt{l(l+1)}\\widetilde{P}_l^1(\\cos\\theta) \n\\end{equation}\n\n{\\footnotesize\n\\VerbatimInput{\\code/LegendrePolynomials/Plmp2.m}\n}\n", "meta": {"hexsha": "9741c422c84d2808a32e915e014dcb7aa6766c98", "size": 12839, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/Utilities/LegendrePolynomials.tex", "max_stars_repo_name": "nasa-jpl/Waveport", "max_stars_repo_head_hexsha": "caeb9540693185e000e08d826bc2ccabb6aa82bd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-08-29T13:29:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T20:09:47.000Z", "max_issues_repo_path": "Tex/Utilities/LegendrePolynomials.tex", "max_issues_repo_name": "ruzakb/Waveport", "max_issues_repo_head_hexsha": "caeb9540693185e000e08d826bc2ccabb6aa82bd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tex/Utilities/LegendrePolynomials.tex", "max_forks_repo_name": "ruzakb/Waveport", "max_forks_repo_head_hexsha": "caeb9540693185e000e08d826bc2ccabb6aa82bd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-08-29T13:28:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-08T19:58:04.000Z", "avg_line_length": 58.8944954128, "max_line_length": 745, "alphanum_fraction": 0.6771555417, "num_tokens": 4815, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511579973931, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.7357442194394312}}
{"text": "\\lab{State Machines}{State Machines}\n\\objective{Explore deterministic and non deterministic finite automatons.}\n\nA state machine is the simplest machine that can be considered a computer.\nIt is very similar to a Markov chain.\nBoth have a set of states and have a defined set of transitions between states.\n\n\\begin{definition}\nA deterministic finite automaton (DFA) is described by a 5-tuple $(Q, \\Sigma, \\delta, q_0, A)$,\nwhere\n\\begin{itemize}\n\\item $Q$ is a finite set of states\n\\item $\\Sigma$ is a finite alphabet of recognized input symbols\n\\item $\\delta$ is the machine's transition function\n\\item $q_0 \\in Q$ is the machine's start state\n\\item $A \\subseteq Q$ is the set of accept states\n\\end{itemize}\n\\end{definition}\n\nA DFA describes a language or set of accepted inputs.  \nIf we give a DFA a particular input, it will tell us if that input exists in its language or not.\nLet's look at a simple example in Figure \\ref{fig:simple_dfa}.  \nWe assume a two symbol alphabet, \\{0, 1\\}.  \nAll the other elements of the DFA are shown graphically ($q_1$ is an accept state, denoted by the double circle).\n\\begin{figure}\n\\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]\n\\node[state,initial](q0) {$q_0$};\n\\node[state,accepting] (q1) [right=of q0]{$q_1$};\n\n\\path[->] (q0) edge node {0} (q1);\n\\end{tikzpicture}\n\\caption{A simple deterministic finite automaton.}\n\\label{fig:simple_dfa}\n\\end{figure}\nThis only input accepted by this DFA is the string \\texttt{0}.\nThat means, only the string \\texttt{0} will cause the machine to transition to an accepting state, namely $q_1$.\nOnce we have consumed all the input, we stop.\nIf the final state is an accepting state, then the string is a member of the language represented by this DFA.\nYou can think of every state having a transition to an implied failure state on unmatched input.\nFor example, if we gave this DFA the input \\texttt{1} or \\texttt{01} we would transition immediately to the failure state on the unmatched symbol.\nA symbol is matched if there is a transition defined for it.\nOtherwise, we automatically transition to a failure state.\nOne possible way to represent this DFA in Figure \\ref{fig:simple_dfa} is:\n\\begin{lstlisting}\ndef consume(in_str):\n    for char in in_str:\n        yield char\n    \ndef state0(scanner):\n    try:\n        if scanner.next() == '0':\n            return state1(scanner)\n    except:\n        pass\n    return False\n    \ndef state1(scanner):\n    try:\n        c = scanner.next()\n    except StopIteration:\n        return True\n    return False\n    \ndef dfa(in_str):\n    scanner = consume(in_str)\n    return state0(scanner)\n\\end{lstlisting}\n\n\n\\begin{problem}\nWrite a Python function that will simulate any given DFA.  \nThe above approach will not work (each state requires a new function).\nYour function should accept as parameters an input string and a 4-tuple, \\li{machine}, that describes the DFA as $(\\Sigma, \\delta, q_0, A)$ in the following format\n\\begin{itemize}\n\\item[$\\Sigma$:] A set with all symbols of the language's alphabet represented as strings.\n\\item[$\\delta$:] A dictionary that defines the transition function.\nIt should map tuples of the form \\li{(m, c)} to values, $n$, to represent the transition $q_m \\xrightarrow{c} q_n$ ($m, n \\in \\mathbb{Z}$ and $c$ is a string character).\n\\item[$q_0$:] An integer, $i$, representing $q_i$, the initial state.\n\\item[$A$:] A set of integers representing the accepting states.\n\\end{itemize}\nYou function should return true if the given input string is a member of the language described by the DFA and false otherwise.\nYour function should test the entire input string.  Be careful not to return true prematurely.\n\\label{prob:dfa_sim}\n\\end{problem}\n\n\\begin{problem}\nDefine the following DFAs using the format in Problem \\ref{prob:dfa_sim} for describing a DFA.\n\n\\begin{figure}[H]\n\\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]\n\\node[state,initial,accepting] (q0) {$q_0$};\n\\node[state] (q1) [right=of q0] {$q_1$};\n\n\\path[->] \n(q0) edge[loop above] node {a} (q0)\n(q1) edge[loop above] node {a} (q1)\n(q0) edge[bend left] node {b} (q1)\n(q1) edge[bend left] node {b} (q0);        \n\\end{tikzpicture}\n\\caption*{\\ref{prob:reprDFA}(a)}\n\\label{prob:reprDFA_a}\n\\end{figure}\n\n\\begin{figure}[H]\n\\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]\n\\node[state,initial] (q0) {$q_0$};\n\\node[state] (q1) [right=of q0] {$q_1$};\n\\node[state,accepting] (q2) [right=of q1] {$q_2$};\n\\node[state] (q3) [right=of q2] {$q_3$};\n\n\\path[->]\n(q0) edge[loop above] node {1} (q0)\n(q0) edge node {0} (q1)\n(q1) edge[loop above] node {1} (q1)\n(q1) edge node {0} (q2)\n(q2) edge[loop above] node {1} (q2)\n(q2) edge node {0} (q3)\n(q3) edge[loop above] node {0,1} (q3);\n\\end{tikzpicture}\n\\caption*{\\ref{prob:reprDFA}(b) The self-loop on $q_3$ transitions to itself on either a 0 or 1.}\n\\label{prob:reprDFA_b}\n\\end{figure}\n\n\\begin{figure}[H]\n\\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]\n\\node[state,initial] (q0) {$q_0$};\n\\node[state,accepting] (q1) [right=of q0] {$q_1$};\n\\node[state,accepting] (q2) [above right=of q0] {$q_2$};\n\\node[state] (q3) [right=of q1] {$q_3$};\n\\node[state] (q4) [right=of q3] {$q_4$};\n\n\\path[->]\n(q0) edge node {1} (q1)\n(q0) edge node {0} (q2)\n(q1) edge node {1} (q3)\n(q1) edge node {0} (q2)\n(q2) edge[loop above] node {0,1} (q2)\n(q3) edge node {1} (q4)\n(q3) edge node {0} (q2)\n(q4) edge node {0,1} (q2);\n\\end{tikzpicture}\n\\caption*{\\ref{prob:reprDFA}(c)}\n\\label{prob:reprDFA_c}\n\\end{figure}\n\\label{prob:reprDFA}\n\\end{problem}\n\n\\section*{Non-Deterministic Finite Automatons}\nA non-deterministic finite automaton (NFA) are a generalization of deterministic state machines.\nThe difference between and NFA and a DFA is the transition function.\nA transition for a DFA maps the current state and the input symbol to exactly one result state.\nIn contrast, an NFA can map the current state and the input symbol (or the empty string, $\\epsilon$) to a set of resulting states.\nIf the set of resulting states has a cardinality greater than 1, the computation separates into independent branches.\nFor example, in Figure \\ref{fig:simple_nfa}, given the input \\texttt{0100}, we start at state $q_0$.  We match the first 0 and the active state is again $q_0$.  Next, we match a 1 and the resulting states are \\{$q_0$, $q_1$, $q_2$\\}.\nAt this point, our machine is in three states simultaneously (we transition to state $q_2$ on the $\\epsilon$ transition).\nThis is the non-deterministic behavior of our state machine.\nOur next input symbol is 0.\nIt is helpful to think of three separate and independent branches of computations.\n\\begin{enumerate}\n\\item State $q_0$ transitions back to $q_0$\n\\item State $q_1$ transitions to $q_2$\n\\item State $q_2$ transitions to $q_3$\n\\end{enumerate}\nOur matching could terminate here, but since we have not completely read out input, we must still keep going.\nThe most we can say at this point is the string \\texttt{010} is in the NFA's language.\nOur current states are the set \\{$q_0$, $q_2$, $q_3$\\}.\nOur last symbol is another 0.\n\\begin{enumerate}\n\\item State $q_0$ transitions back to itself\n\\item State $q_2$ transitions to $q_3$\n\\item State $q_3$ transitions to the implied fail state\n\\end{enumerate}\nNow that we have read all of our input, and one of our final resulting states is an accepting state, we accept the entire string.\nDoes the string \\texttt{01000} exist in the NFA's language?\n\nYou might think that this new power of NFAs will allow us to represent many more languages.\nHowever, every language that can be represented as an NFA can also be represented by an equivalent DFA.\nThis is to say that an NFA is equivalent to a DFA in computing power.\nIn fact a method exists that will transform any NFA into an equivalent DFA.\nThis is, however, beyond the scope of this lab.\nNFAs are quite useful though because they can often represent complex languages very simply and intuitively.\n\\begin{figure}\n\\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]\n\\node[state,initial] (q0) {$q_0$};\n\\node[state] (q1) [right=of q0] {$q_1$};\n\\node[state] (q2) [right=of q1] {$q_2$};\n\\node[state,accepting] (q3) [right=of q2] {$q_3$};\n\n\\path[->]\n(q0) edge node {1} (q1)\n(q0) edge[loop above] node {0,1} (q0)\n(q1) edge node {0,1,$\\epsilon$} (q2)\n(q2) edge node {0,1} (q3);\n\\end{tikzpicture}\n\\caption{A simple non-deterministic finite automaton.}\n\\label{fig:simple_nfa}\n\\end{figure}\n\n\\begin{problem}\nDraw a non-deterministic finite automaton that can match the following language.\n\n\\emph{Let $w \\in L$ where the number of a's is a multiple of 3, or contains least 4 b's, or where the number of c's is odd.}\n\\label{prob:drawnfa}\n\\end{problem}\n\n\n\\section*{Operations on Regular Languages}\nWe can build machines that represent more complex languages by concatenating several simpler DFAs or NFAs together.\nThe format expression for concatenating the languages $A$ and $B$ is $A \\circ B$.\nWe can also union the machines and thus union the languages they each represent (expressed as $A \\cup B$).  \nThere are two more basic operations, \\emph{star} and \\emph{plus}, that are extremely useful.\nGiven a language, $L$, $L^*$ means that we can concatenate any number of strings in $L$ to get another string in $L^*$.  $L^+$ denotes one or more strings of $L$ have been attached to form a new string in $L^+$.\nNote that $L^*$ and $L^+$ are different languages than $L$.\n\n\\section*{Introduction to Regular Expressions}\nRegular expressions are not trivial or easy, but understanding them can be very straightforward.\nThe best way to think of regular expressions is the view them as operations on regular languages.  \nThe entire regular expression represents a regular language.  \nIn fact, the definition of being a regular language, $L$ means that there is a regular expression that represents $L$.\nSince a every regular language can be represented by a DFA, we have an equivalence between regular expressions and DFAs.\nAnd, because every NFA is equivalent to some DFA, we have a three-way equivalence (DFA=NFA=RE).\nRegular epxressions are a \\emph{very} compact way of representing complex state machines.\nSometimes it can be easier to use a DFA representation (much easier to write and define) or other times it can be easier to use a regular expression (more expressive, more compact).\nAs noted, regular expressions can only represent a language if it is regular.\nThere exist languages that are non-regular.\nThere are ways to rigorously prove that a language is non-regular, but that is beyond the scope of this lab.\nA regular language is any language that can be represented as a regular expression, an NFA, or a DFA.\n\nRegular expressions are especially useful and powerful for finding and matching patterns in text.\nMany tools can take advantage of the powerful matching features of regular expressions.\nYou can think of regular expressions as operations on state machines.\nFor example, the regular expression $(a^*b)^* b^*a$ could be represented as the NFA in \\ref{fig:nfa_concat}.\n\\begin{figure}\n\\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]\n\\node[state,initial] (q0) {$q_0$};\n\\node[state] (q1) [right=of q0] {$q_1$};\n\\node[state] (q2) [right=of q3] {$q_2$};\n\\node[state] (q3) [right=of q1] {$q_3$};\n\\node[state,accepting] (q4) [right=of q2] {$q_4$};\n\n\\path[->]\n(q0) edge node {$\\epsilon$} (q1)\n(q0) edge[bend right] node {$\\epsilon$} (q2)\n\n(q1) edge[loop above] node {a} (q1)\n(q1) edge node {b} (q3)\n(q3) edge node {$\\epsilon$} (q2)\n(q2) edge[loop below] node {b} (q2)\n(q2) edge node {a} (q4);\n\\end{tikzpicture}\n\\caption{An NFA for the regular expression $(a^*b)^* b^*a$.}\n\\label{fig:nfa_concat}\n\\label{fig:simple_nfa}\n\\end{figure}\nWhich is simply a concatenation of the NFAs \\ref{fig:nfa1} and \\ref{fig:nfa2}.\n\\begin{figure}\n\\centering\n\\begin{subfigure}[b]{.5\\textwidth}\n\\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]\n\\node[state,initial] (q1) {$q_1$};\n\\node[state,accepting] (q3) [right=of q1] {$q_3$};\n\n\\path[->]\n(q1) edge[loop above] node {a} (q1)\n(q1) edge node {b} (q3);\n\\end{tikzpicture}\n\\caption{NFA for $a^*b$.}\n\\label{fig:nfa1}\n\\end{subfigure}\n\n\\begin{subfigure}[b]{.5\\textwidth}\n\\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]\n\\node[state,initial] (q2) {$q_2$};\n\\node[state,accepting] (q4) [right=of q2] {$q_4$};\n\n\\path[->]\n(q2) edge[loop above] node {b} (q2)\n(q2) edge node {a} (q4);\n\\end{tikzpicture}\n\\caption{NFA for $b^*a$.}\n\\label{fig:nfa2}\n\\end{subfigure}\n\\end{figure}\n\n\\begin{problem}\nFor parts a and b in Problem \\ref{prob:reprDFA}, write a  regular expression that is equivalent to state machine.\n\\label{prob:equiv_regex}\n\\end{problem}\n\nBecause of a regular expression's ability to compactly represent complex state machines, they are very useful in matching patterns in a string (both trivial and non-trivial).\nInstead of matching exact strings (a standard string search find and replace), the regular expression matches the form or pattern of a string (like a formatted date or email address pattern).\nFor example, we can use a regular expression to match phone numbers, email addresses, HTTP addresses.\n\nThere are many libraries that implement regular expression matching.\nMost programming languages also have their own regular expression library.\nUnfortunately, the syntax for regular expressions may be slightly different in each implementation. \nThere is no universal standard for all regular expressions across all platforms. \nHowever, a common syntax with a few variations is very widely used, so most regular expression patterns can be used with any library.\n\n\\begin{warn}\nTheoretically, regular expressions have a linear runtime.\nHowever, because of more advanced features that many regular expression libraries have, poorly written regular expressions can have exponential runtime!\nProfiling regular expressions is tricky because of their syntax.\nA single character or two  could mean the difference between an efficient regular expression and a regular expression that has practically infinite runtime for long inputs.\n\\end{warn}\n\n\\section*{Using Regular Expressions in Python}\nThe Python Standard Library includes a module that will handle regular expressions.\nYou can read the documentation for the module at \\url{http://docs.python.org/2/library/re.html}.\nWe begin by importing the \\li{re} module from the standard library.\n\\begin{lstlisting}\n>>> import re\n>>> m = re.match(r\"(a*b)*b*a\", \"abba\")\n>>> type(m)\n_sre.SRE_Match\n\\end{lstlisting}\nWe have just performed our first match!\nAs you can see, \\li{re.match} returns an \\li{SRE_Match} object (or MatchObject).\nIf there was not match to the regular expression, \\li{None} is returned.\nThe MatchObject object has several methods and attributes that give us information about the match.\nWe mention a few here, but all of them are explained in the standard library documentation.\nTo view what a regular expression matched, we can use the \\li{group()} method.\n\\begin{lstlisting}\n>>> m = re.match(r\"(.*) (.*) (.*)\", \"These are a lot of words!\")\n>>> m.group()\n'These are a lot of words!'\n>>> m.groups()\n('These are a lot', 'of', 'words!')\n>>> m.group(1)\n'These are a lot'\n>>> m.group(3)\n'words!'\n\\end{lstlisting}\nAs you can see, we matched the entire string.\nOur regular expression split the string into 3 groups.\nWe can access all the groups with \\li{groups()} or individual subgroups with \\li{group()}.\nWe can know the span of the group with the \\li{span()} method.\n\\begin{lstlisting}\n>>> m.span(1)\n(0, 15)\n>>> m.span(3)\n(19, 25)\n>>> m.string[19:25]\n'words!'\n>>> m.regs #gives the span of each group\n((0, 25), (0, 15), (16, 18), (19, 25))\n\\end{lstlisting}\n\nWe have compiled a table of the important characters and their meanings in Python.\nYou can think of each of these characters representing simple state machines.\nA worthwhile exercise would be to define the state machines that correspond to each row in Table \\ref{table:regexchars}.\n\\begin{table}\n\\begin{tabular}{|l|l|}\n\\hline\nCharacter & Meaning \\\\\n\\hline\n\\li{.} & Matches any character (except newlines) \\\\\n\\li{^} & Matches at the start of a line \\\\\n\\li{\\$} & Matches at the end of a line \\\\\n\\li{*} & Matches 0 or more repetitions of a regular expression (greedy) \\\\\n\\li{+} & Matches 1 or more repetitions of a regular expression (greedy) \\\\\n\\li{?} & Matches 0 or 1 repetition of a regular expression \\\\\n\\li{(m)} & Matches exactly $m$ repetitions of a regular expression \\\\\n\\li{(m, n)} & Matches between $m$ and $n$ repetitions of a regular expression \\\\\n\\li{[]} & Matches a set or range of characters \\\\\n\\li{[^ ]} & Matches the complement of a range of characters \\\\\n\\li{A|B} & A, B are regular expression.  Match either A or B \\\\\n\\li{\\\\w} & Matches any alphanumeric character and underscore \\\\ \n\\li{\\\\W} & Matches any non-alphanumeric character \\\\\n\\li{\\\\s} & Matches any whitespace character \\\\\n\\li{\\\\S} & Matches any non-whitespace character \\\\\n\\hline\n\\end{tabular}\n\\caption{Common character sequences in regular expressions.}\n\\label{table:regexchars}\n\\end{table}\nNotice that some of the operator characters in Table \\ref{table:regexchars} are \\emph{greedy} operators.\nThis means that this part of the regular expression will try to consume as much of the input as possible needed to make a match.\nThere are cases where this is not desirable.\nWe can make these greedy operators non-greedy, or lazy, by suffixing them with a question mark.\nThe lazy star operator is then \\texttt{*?}.\nA lazy operator will consume as little of the input as possible needed to make a match.\n\\begin{lstlisting}\n# greedy + operator\n>>> re.match(r\"<.+>\", '<a href=\"super.png\">Superman</a>').group()\n<a href=\"super.png\">Superman</a>\n# non-greedy/lazy + operator\n>>> re.match(r\"<.+?>\", '<a href=\"super.png\">Superman</a>').group()\n<a href=\"super.png\">\n\\end{lstlisting}\n\n\\subsection*{Matching, Searching, Splitting, and Substituting}\nHaving now an understanding of the MatchObject, we can begin to talk about how to use the powerful features of Python's regular expression library.\nMost of your regular expression use will revolve around \\li{re.match()}, \\li{re.search()}, \\li{re.split()}, and \\li{re.sub}.\n\\begin{description}\n\\item \\emph{re.match(pattern, string, flags=0)}:  Apply a pattern beginning at start of \\emph{string}.  Returns a MatchObject if successful, otherwise None.\n\\item \\emph{re.search(pattern, string, flags=0)}:  Look in \\emph{string} for any occurrence of \\emph{pattern}.  Returns a MatchObject if the pattern is found.\n\\item \\emph{re.split(pattern, string, maxsplit=0, flags=0)}: Split \\emph{string} by occurrences of \\emph{pattern}.  Returns a list of all matching substrings.\n\\item \\emph{re.sub(pattern, repl, string, count=0, flags=0)}: Search \\emph{string} for occurrences of \\emph{pattern}, and replace each occurrence with the result of \\emph{repl} (can be a string or function that returns a string).\n\\end{description}\nNotice that all four of these commands operate from the same workflow.\nEach accepts a pattern or regular expression and a string.\nThat pattern is run on the string and then results are returned.\nIn the case of splitting and substituting, we manipulate the string based off the matching parts of the pattern.\n\\begin{lstlisting}\n# match one or more words (non-alphanumeric characters)\n>>> re.split('\\W+', 'Hi there! This is a splitted sentence.')\n['Hi', 'there', 'This', 'is', 'a', 'splitted', 'sentence', '']\n\\end{lstlisting}\n\n\\begin{problem}\nWrite an expression that can be used to validate most email addresses of the form a@b.c where a is any character (including periods, dashes and underscores), b can be any domain (including periods, dashes, and underscores), and c is any three or four character alphanumeric sequence.\n\nYour expression should split the email address into three groups: a, b, and c (using the notation above).\nSubstitute the letter x for group b.\nFor example, your substitution should transform abc123@email.com to abc123@xxxxx.com (the number of x's should be equal to the number of characters in group b).\n\\label{prob:emailvaldiator}\n\\end{problem}\n\n\\begin{problem}\nUsing Table \\ref{table:regexchars}, describe the parts of the following regular expressions:\n\\begin{enumerate}\n\\item \\li{^([a-z0-9]\\{32\\})\\$}\n\\item \\li{^(19|20)\\\\d\\\\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])\\$}\n\\item \\li{^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?\\$}\n\\end{enumerate}\n\\label{prob:readingregex}\n\\end{problem}\n\n", "meta": {"hexsha": "2a2c86f5f17594a9a757ee6cccea4d9b0df8fac0", "size": 20372, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Python/StateMachines/StateMachines.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Python/StateMachines/StateMachines.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Python/StateMachines/StateMachines.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 47.376744186, "max_line_length": 283, "alphanum_fraction": 0.7310033379, "num_tokens": 5806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.8596637577007394, "lm_q1q2_score": 0.7357442193558329}}
{"text": "\\section{Gauss-Jordan elimination}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find the {\\rref} of a matrix.\n  \\item Solve a system of linear equations using Gauss-Jordan elimination.\n  \\end{enumerate}\n\\end{outcome}\n\nIn the previous section, we saw how to solve a system of equations by\nusing Gaussian elimination and back substitution. The back\nsubstitution step can be quite confusing and error prone, especially\nwhen there are parameters. For example, in\nExample~\\ref{exa:two-parameter-set-of-solution}, we had to substitute $y=s$,\n$z=2-t$, and $w=t$ into the equation $x=3-2y+2z-2w$, which required\nanother simplification step.\n\nIn this section, you will learn an alternative procedure called {\\em\n  Gauss-Jordan elimination} which eliminates the need for back\nsubstitution, at the expense of doing a few additional row operations.\nThe key to this technique is a special kind of {\\ef} called a\n{\\em {\\rref}}.\n\n\\begin{definition}{\\Rref}{rref}\n  An augmented matrix is in \\textbf{\\rref}%\n  \\eindex{\\rref}%\n  \\eindex{\\ef!reduced} if\n\n  \\begin{enumerate}\n  \\item It is in {\\ef}.\n\n  \\item Each leading entry is equal to $1$.\n\n  \\item All entries above a leading entry are zero.\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{example}{{\\Rref}}{rref-matrices}\n  The following augmented matrices are in {\\rref}. The leading entries\n  have been circled for emphasis. Note how all of the leading entries\n  are equal to $1$, and they have zeros above them.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrrr|r}\n      \\circled{1} & 2 & 0 & 5 & 0 & 3 \\\\\n      0 & 0 & \\circled{1} & 2 & 0 & 0 \\\\\n      0 & 0 & 0 & 0 & \\circled{1} & 1 \\\\\n      0 & 0 & 0 & 0 & 0 & 0\n    \\end{mymatrix},\\quad\\begin{mymatrix}{rrr|r}\n      \\circled{1} & 0 & 0 & 0 \\\\\n      0 & \\circled{1} & 0 & 0 \\\\\n      0 & 0 & \\circled{1} & 0 \\\\\n      0 & 0 & 0 & \\circled{1} \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix}, \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 0 & 0 & 4 \\\\\n      0 & \\circled{1} & 0 & 3 \\\\\n      0 & 0 & \\circled{1} & 2\n    \\end{mymatrix}\n  \\end{equation*}\n\\end{example}\n\nWe can carry every augmented matrix to {\\rref} by doing elementary row\noperations.\n\n\\begin{algorithm}{Gauss-Jordan elimination}{gauss-jordan}\n  This algorithm provides a method for using row operations to take a\n  matrix to its {\\rref}%\n  \\eindex{\\rref!algorithm}%\n  \\index{Gauss-Jordan elimination}.\n  \\begin{enumerate}\n  \\item First, use Gaussian elimination\n    (Algorithm~\\ref{algo:gaussian-elimination}) to reduce the matrix to\n    {\\ef}.\n  \\item Moving from right to left, consider each pivot entry. Without\n    changing the row containing the pivot entry, or any rows below it,\n    use row operations to create zeros in the column above the pivot\n    entry. Finally, divide the row by its pivot entry, to make the\n    pivot entry equal to $1$.\n  \\end{enumerate}\n\\end{algorithm}\n\n\\begin{example}{Gauss-Jordan elimination}{gauss-jordan1}\n  Solve the system of equations from\n  Example~\\ref{exa:system-with-one-solution} using Gauss-Jordan elimination.\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x+4y+3z &=& 11 \\\\\n      2x+10y+7z &=& 27 \\\\\n      x+y+2z &=& 5.\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  In Example~\\ref{exa:system-with-one-solution}, we had already reduced the\n  system to {\\ef}:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 4 & 3 & 11 \\\\\n      0 & \\circled{2} & 1 & 5 \\\\\n      0 & 0 & \\circled{1} & 3\n    \\end{mymatrix}.\n  \\end{equation*}\n  We reduce it to {\\rref} by performing the following row operations:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 4 & 3 & 11 \\\\\n      0 & \\circled{2} & 1 & 5 \\\\\n      0 & 0 & \\circled{1} & 3\n    \\end{mymatrix}\n    \\!\\!\\!\\stackrel{R_2\\rowop R_2-R_3}{\\stackrel{R_1\\rowop R_1-3R_3}{\\roweq}}\\!\\!\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 4 & 0 & 2 \\\\\n      0 & \\circled{2} & 0 & 2 \\\\\n      0 & 0 & \\circled{1} & 3\n    \\end{mymatrix}\n    \\!\\!\\stackrel{R_1\\rowop R_1-2R_2}{\\roweq}\\!\\!\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 0 & 0 & -2 \\\\\n      0 & \\circled{2} & 0 & 2 \\\\\n      0 & 0 & \\circled{1} & 3\n    \\end{mymatrix}\n    \\!\\!\\stackrel{R_2\\rowop \\frac{1}{2}R_2}{\\roweq}\\!\\!\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 0 & 0 & -2 \\\\\n      0 & \\circled{1} & 0 & 1 \\\\\n      0 & 0 & \\circled{1} & 3\n    \\end{mymatrix}\\!\\!.\n  \\end{equation*}\n  The resulting matrix is in {\\rref}. Note that the final system of\n  equations is especially easy to solve, because the three equations\n  are $x=-2$, $y=1$, and $z=3$. No back substitution is needed.\n\\end{solution}\n\n\\begin{example}{Gauss-Jordan elimination}{gauss-jordan2}\n  Solve the system of equations from\n  Example~\\ref{exa:two-parameter-set-of-solution} using Gauss-Jordan\n  elimination.\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x + 2y - 2z + 2w &=& 3 \\\\\n      x + 2y - z  + 3w &=& 5 \\\\\n      x + 2y - 3z + 1w &=& 1.\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  In Example~\\ref{exa:two-parameter-set-of-solution}, we had obtained the\n  following {\\ef}:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrr|r}\n      \\circled{1} & 2 & -2 & 2 & 3 \\\\\n      0 & 0 & \\circled{1} & 1 & 2 \\\\\n      0 & 0 & 0 & 0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  We reduce this to {\\rref} by performing the following additional\n  step:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrr|r}\n      \\circled{1} & 2 & -2 & 2 & 3 \\\\\n      0 & 0 & \\circled{1} & 1 & 2 \\\\\n      0 & 0 & 0 & 0 & 0\n    \\end{mymatrix}\n    \\stackrel{R1\\rowop R1+2R2}{\\roweq}\n    \\begin{mymatrix}{rrrr|r}\n      \\circled{1} & 2 & 0 & 4 & 7 \\\\\n      0 & 0 & \\circled{1} & 1 & 2 \\\\\n      0 & 0 & 0 & 0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  The first equation states that $x=7-2y-4w$, and the second equation\n  states that $z=2-w$. Using the free variables $y$ and $w$ as\n  parameters, we obtain the following general solution:\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x &=& 7-2y-4w \\\\\n      y &=& y \\\\\n      z &=& 2-w \\\\\n      w &=& w.\n    \\end{array}\n  \\end{equation*}\n  Note that we did not really have to do back substitution; all we had\n  to do is to shift parts of the equations to the right-hand side. If\n  the solution looks strange, because it has equations like ``$y=y$''\n  in it, keep in mind that this means that $y$ and $w$ are arbitrary\n  numbers, i.e., parameters. We can replace $y$ and $w$ by parameters\n  $s$ and $t$ on the right-hand side, as before:\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x &=& 7-2s-4t \\\\\n      y &=& s \\\\\n      z &=& 2-t \\\\\n      w &=& t.\n    \\end{array}\n  \\end{equation*}\n\\end{solution}\n\n\\begin{discussion}{Which procedure is better?}{g-vs-gj}\n  Which one is the better procedure to use, Gaussian elimination with\n  back substitution, or Gauss-Jordan elimination? The answer is: it\n  depends. In certain applications, it is not necessary to completely\n  solve a system of equations. Sometimes it is sufficient just to figure\n  out whether the system is consistent or inconsistent, or whether the\n  solution is unique or not. In those situations, you already get the\n  required information from the {\\ef} and there is no need to do the\n  additional steps to reduce the system to {\\rref}. Also, in some\n  situations, Gauss-Jordan elimination can introduce fractions into your\n  augmented matrix, making the matrix more complicated to work with. In\n  such cases, it may sometimes be easier to do back substitution. But in\n  most cases, Gauss-Jordan elimination is simpler to do than back\n  substitution, and therefore I recommend using the Gauss-Jordan method\n  most of the time.\n\\end{discussion}\n\nOne situation where Gauss-Jordan elimination excels is when you have\nto solve many systems of equations that all have the same coefficient\nmatrix.\n\n\\begin{example}{Multiple systems sharing the same left-hand side}{multiple-systems}\n  Solve the following two systems of equations.\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l@{~}}\n      x       +  z &=& 1 \\\\\n      2x +  y + 3z &=& 2 \\\\\n      3x + 2y + 5z &=& 4 \\\\\n    \\end{array}\n    \\quad\\quad\n    \\begin{array}{r@{~}c@{~}l@{~}}\n      x       +  z &=& 2 \\\\\n      2x +  y + 3z &=& 5 \\\\\n      3x + 2y + 5z &=& 8 \\\\\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We could certainly solve each system of equations separately. But\n  since the left-hand sides are the same, we will perform exactly the\n  same row operations on both systems. We can save some work by\n  solving both systems together. Instead of a usual augmented matrix\n  with only one constant vector, we create an augmented matrix\n  containing both constant vectors at the same time.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|rr}\n      1 & 0 & 1 & 1 & 2 \\\\\n      2 & 1 & 3 & 2 & 5 \\\\\n      3 & 2 & 5 & 4 & 8 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  Then we row-reduce the coefficient matrix to {\\rref} as usual. (We\n  do not need to bother reducing the right-hand size to {\\rref}).\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|rr}\n      1 & 0 & 1 & 1 & 2 \\\\\n      2 & 1 & 3 & 2 & 5 \\\\\n      3 & 2 & 5 & 4 & 8 \\\\\n    \\end{mymatrix}\n    \\stackrel{R_2\\rowop R_2-2R_1}{\n      \\stackrel{R_3\\rowop R_3-3R_1}{\\roweq}}\n    \\begin{mymatrix}{rrr|rr}\n      1 & 0 & 1 & 1 & 2 \\\\\n      0 & 1 & 1 & 0 & 1 \\\\\n      0 & 2 & 2 & 1 & 2 \\\\\n    \\end{mymatrix}\n    \\stackrel{R_3\\rowop R_3-2R_2}{\\roweq}\n    \\begin{mymatrix}{rrr|rr}\n      1 & 0 & 1 & 1 & 2 \\\\\n      0 & 1 & 1 & 0 & 1 \\\\\n      0 & 0 & 0 & 1 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  We see that the first system is inconsistent, because it contains a\n  row of the form $\\mat{0~0~0~|~1}$. The second system is consistent,\n  and we get the general solution $z=t$, $y=1-t$, $x=2-t$.\n\\end{solution}\n", "meta": {"hexsha": "eb2164dca2b044f4a38c11d66c29b33c5ec4a6f7", "size": 9684, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/SystemsofEquations-GaussJordanElimination.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/SystemsofEquations-GaussJordanElimination.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/SystemsofEquations-GaussJordanElimination.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 34.8345323741, "max_line_length": 83, "alphanum_fraction": 0.6210243701, "num_tokens": 3443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604134, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7357441896214404}}
{"text": "\n\\subsection{Primal and dual problems}\n\n\\subsubsection{The primal problem}\n\nWe already have this.\n\n\\subsubsection{The dual problem}\n\nWe can define the Lagrangian dual function:\n\n\\(g(\\lambda, \\nu ) = \\inf_{x\\in X} \\mathcal{L}(x, \\lambda ,\\nu )\\)\n\nThat is, we have a function which chooses the returns the value of the optimised Lagrangian, given the values of \\(\\lambda \\) and \\(\\nu\\).\n\nThis is an unconstrained function.\n\nWe can prove this function is concave (how?).\n\nThe infimum of a set of concave (and therefore also affine) functions is concave.\n\nThe supremum of a set of convex (and therefore also affine) functions is convex.\n\nGiven a function with inputs \\(x\\), what values of \\(x\\) maximise the function?\n\nWe explore constrained and unconstrained optimisation. The former is where restrictions are placed on vector \\(x\\), such as a budget constraint in economics.\n\n\\subsubsection{The dual problem is concave}\n\n\\subsubsection{The duality gap}\n\nWe refer to the optimal solution for the primary problem as \\(p^*\\), and the optimal solution for the dual problem as \\(d^*\\).\n\nThe duality gap is \\(p^*-d^*\\).\n\n", "meta": {"hexsha": "363c0312ff191e56e1b9a845d13e39781dacd723", "size": 1113, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/optimisationMulti/03-02-duality.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/optimisationMulti/03-02-duality.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/optimisationMulti/03-02-duality.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.9166666667, "max_line_length": 157, "alphanum_fraction": 0.739442947, "num_tokens": 280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.735686178106056}}
{"text": "\\subsection{Linear second order PDE}\n\n\\begin{Notation}{coordinates}\n  Dimension of ``physical space'' will be denoted by $d$.  We denote\n  coordinates in $\\R^d$ as\n  \\begin{gather*}\n    \\vx = (x_1,\\dots,x_d)^T  .\n  \\end{gather*}\n  In the special cases $d=2,3$ we also write\n  \\begin{gather*}\n  \\vx =\n  \\begin{pmatrix}\n    x\\\\y\n  \\end{pmatrix},\n  \\qquad\\qquad\n  \\vx = \\begin{pmatrix}\n    x\\\\y\\\\z\n  \\end{pmatrix},\n  \\end{gather*}\n  respectively.\n  The Euclidean norm on $\\R^d$ is denoted as\n  \\begin{gather*}\n     \\abs{\\vx} = \\sqrt{\\sum_{i=1}^d x_i^2}.\n  \\end{gather*}\n\\end{Notation}\n\n\\begin{Notation}{partial-derivative}\n  Partial derivatives of a function $u\\in C^1(\\R^d)$ are denoted by\n  \\begin{gather*}\n    \\frac{\\d u(\\vx)}{\\d x_i} = \\tfrac{\\d}{\\d x_i} u(\\vx)\n    = \\d_{x_i} u(\\vx) = \\d_i u(\\vx).\n  \\end{gather*}\n\n  The \\define{gradient} of $u \\in C^1$ is the row vector\n  \\begin{gather*}\n    \\nabla u = (\\d_1u,\\dots,\\d_du)\n  \\end{gather*}\n\n  The \\define{Laplacian} of a function $u\\in C^2(\\R^d)$ is\n  \\begin{gather*}\n    \\Delta u = \\d_1^2 u + \\dots + \\d_d^2 u = \\sum_{i=1}^d \\d_i^2 u\n  \\end{gather*}\n\\end{Notation}\n\n\\begin{Notation}{elim-coord}\n  When we write equations, we typically omit the independent variable\n  $\\vx$. Therefore,\n  \\begin{gather*}\n    \\Delta u \\equiv \\Delta u(\\vx).\n  \\end{gather*}\n\\end{Notation}\n\n\\begin{Definition}{lin-pde-2order}\n  A linear PDE of second order in divergence form for a function\n  $u\\in C^2(\\R^d)$ is an equation of the form\n  \\begin{gather}\n    -\\sum_{i,j=1}^d \\d_i \\bigl(a_{ij}(\\vx) \\d_j u\\bigr)\n    + \\sum_{i=1}^d \\bigl(b_i(\\vx) \\d_i u\\bigr) + c(\\vx) u = f(x)\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Definition}{poisson-eqn}\n  An important model problem for the equations we are going to study\n  is \\define{Poisson's equation}\n  \\begin{gather}\n    \\label{eq:Poisson}\n    -\\Delta u = f.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{intro}\n  Already with ordinary differential equations we experience that we\n  typically do not search for solutions of the equation itself, but\n  that we ``anchor'' the solution by solving an initial value problem,\n  fixing the solution at one point on the time axis.\n\n  It does not make sense to speak about an initial point in\n  $\\R^d$. Instead, it turns out that it is appropriate to consider\n  solutions on certain subsets of $\\R^d$ and impose conditions at the\n  boundary.\n\\end{intro}\n\n\\begin{Definition}{domain}\n  A \\define{domain} in $\\R^d$ is a connected, open set of $\\R^d$. We\n  typically use the notation $\\domain\\subset\\R^d$.\n\n  The \\define{boundary} of a domain $\\domain$ is denoted by\n  $\\d\\domain$. To any point $\\vx\\in\\d\\domain$, we associate the outer\n  unit \\define{normal vector} $\\vn \\equiv \\vn(\\vx)$.\n\n  The symbol $\\d_n u \\equiv (\\nabla u) \\vn$ denotes the \\define{normal\n    derivative} of a function $u\\in C^1(\\overline{\\domain})$ at a point\n  $\\vx\\in\\d\\domain$.\n\\end{Definition}\n\n\\begin{Definition}{boundary-conditions}\n  We distinguish three types of boundary conditions for Poisson's\n  equation, namely for a point $\\vx\\in\\d\\domain$ with a given function $g$\n  \\begin{enumerate}\n  \\item Dirichlet:\n    \\begin{gather*}\n      u(\\vx) = g(\\vx)\n    \\end{gather*}\n  \\item Neumann:\n    \\begin{gather*}\n      \\d_n u(\\vx) = g(\\vx)\n    \\end{gather*}\n  \\item Robin: for some positive function $\\alpha$ on $d\\domain$\n    \\begin{gather*}\n      \\d_n u(\\vx) + \\alpha(\\vx) u(\\vx) = g(\\vx)\n    \\end{gather*}\n  \\end{enumerate}\n  While only one of these boundary conditions can hold in a single\n  point $\\vx$, different boundary conditions can be active on\n  different subsets of $\\d\\domain$. We denote such subsets as\n  $\\Gamma_D$, $\\Gamma_N$, and $\\Gamma_R$.\n\\end{Definition}\n\n\\begin{Definition}{dirichlet-problem-differential}\n  The \\define{Dirichlet problem} for \\putindex{Poisson's equation} (in\n  differential form) is: find\n  $u\\in C^2(\\domain)\\cap C(\\overline{\\domain})$, such that\n  \\begin{subequations}\n    \\begin{xalignat}2\n      -\\Delta u(\\vx) &= f(\\vx) & x&\\in \\domain, \\\\\n      u(\\vx) &= g(\\vx) & x&\\in \\d\\domain.\n    \\end{xalignat}\n  \\end{subequations}\n  Here, the functions $f$ on $\\domain$ and $g$ on $\\d\\domain$ are data\n  of the problem.\n\n  The Dirichlet problem is called \\define{homogeneous}, if $g\\equiv 0$.\n\\end{Definition}\n\n\\begin{Theorem*}{Dirichlet-principle}{Dirichlet principle}\n  If a function $u\\in C^2(\\domain)\\cap C(\\overline{\\domain})$ solves\n  the \\putindex{Dirichlet problem}, then it minimizes the\n  \\define{Dirichlet energy}\n  \\begin{gather}\n    \\label{eq:Dirichlet-energy}\n    E(v) = \\int_{\\domain} \\tfrac12 \\abs{\\nabla v}^2 \\dvx - \\int_{\\domain} f v \\dvx,\n  \\end{gather}\n  among all functions $v$ from the set\n  \\begin{gather}\n    V_g = \\bigl\\{ v\\in C^2(\\domain)\\cap C(\\overline{\\domain})\n    \\big| v_{|\\d\\domain} = g \\bigr\\}.\n  \\end{gather}\n  This minimizer is unique.\n\\end{Theorem*}\n\n\\begin{proof}\n  Using variation of $E$, we will show that\n  \\begin{gather*}\n    \\frac{\\diffd}{\\diffd \\varepsilon} E(u+\\varepsilon v)\n    \\Big|_{\\varepsilon=0} = 0\n  \\end{gather*}\n  for all $v \\in V_0$ since this implies $u + \\varepsilon v = g$\n  on $\\d\\domain$. By evaluating the square we have\n  \\begin{gather*}\n    \\frac{\\diffd}{\\diffd \\varepsilon} E(u+\\varepsilon v)\n    = \\int_\\domain \\nabla u \\nabla v + \\varepsilon \\abs{\\nabla v}^2 - fv \\dx\n  \\end{gather*}\n  Since we are intersted in $E(u)$, we now consider $\\varepsilon=0$. We\n  get that $u$ minimizes $E(u+\\varepsilon v)$ at $\\varepsilon = 0$ implies\n  \\begin{gather*}\n    \\int_\\domain \\nabla u \\nabla v \\dx = \\int_\\domain fv \\dx,\n    \\qquad\\forall v\\in V_0.\n  \\end{gather*}\n  By Green's formula\n  \\begin{gather*}\n    \\int_\\domain \\nabla u \\nabla v \\dx = \\int_\\domain - \\Delta u v \\dx\n    + \\int_{\\d\\domain} \\d_n u v \\ds\n  \\end{gather*}\n  we obtain that if $u$ minimizes $E(\\cdot)$, then\n  \\begin{gather*}\n    \\int_\\domain \\nabla u \\nabla v \\dx = \\int_\\domain fv \\dx,\n    \\qquad\\forall v\\in V_0,\n  \\end{gather*}\n  since $v \\in V_0$ vanishes on $\\d\\domain$. In summary, we have\n  proven so far that if $u$ solves Poisson's Equation, then it is a\n  stationary point of $E(\\cdot)$. It remains to show that\n  $E(u) \\le E(u+v)$ for any $v\\in V_0$.  Using\n  $\\int_\\domain fv \\dx = \\int_\\domain \\nabla u \\nabla v$ yields\n  \\begin{multline*}\n    E(u+v) - E(u) = \\frac 12 \\int_\\domain |\\nabla (u+v)|^2 - 2 \\nabla (u+v) \\nabla u\n    + |\\nabla u|^2 \\dx\n    = \\frac 12 |\\nabla v|^2 \\dx \\ge 0.\n  \\end{multline*}\n  This also proves uniqueness.\n\\end{proof}\n\n\\begin{Lemma}{Dirichlet-Cauchy}\n  A minimizing sequence for the Dirichlet energy exists and it is a\n  Cauchy sequence.\n\\end{Lemma}\n\n\\begin{proof}\n  The Dirichlet energy $E(\\cdot)$ is bounded from\n  below and hence an infinum exists. Thus, there also exists a series\n  $\\{u^{(n)}\\}_{n \\in \\mathbb{N}}$ converging to this infinum, i.e.\n  \\begin{gather*}\n    \\lim_{n \\to \\infty} E(u^{(n)}) = \\inf_{v \\in V_0} E(v).\n  \\end{gather*}\n  Second, we show that $\\{u^{(n)}\\}_n$ is a Cauchy sequence.\n  \n  For the first part we use Friedrich's inequality\n  \\begin{gather*}\n    \\norm{v}_{L^2(\\domain)} \\le \\lambda(\\Omega)\n    \\norm{\\nabla v}_{L^2(\\domain)} \\qquad v \\in V_0.\n  \\end{gather*}\n  The proof of this result will be given later. Using Hölder's inequality\n  we obtain\n  \\begin{gather*}\n    E(v) = \\frac 12 \\norm{\\nabla v}^2 _{L^2(\\domain} - \\int_\\domain fv \\dx\n    \\ge \\frac 12 \\norm{\\nabla v}^2 _{L^2(\\domain}\n    - \\norm{f}_{L^2(\\domain} \\norm{v}_{L^2(\\domain}\n  \\end{gather*}\n  Applying Friedrich's inquality yields that the above expression is\n  greater or equal than\n  \\begin{gather*}\n    \\frac 12 \\norm{\\nabla v}^2 _{L^2(\\domain}\n    - \\norm{\\nabla v}_{L^2(\\domain} \\frac 1{\\lambda (\\domain)}\n    \\norm{f}_{L^2(\\domain}.\n  \\end{gather*}\n  Finally, we apply Young's inequality $ab \\le \\nicefrac 12 (a^2 + b^2)$ to obtain\n  \\begin{gather*}\n    \\frac 12 \\norm{\\nabla v}^2 _{L^2(\\domain}\n    - \\norm{\\nabla v}_{L^2(\\domain}^2 - \\frac 1{2\\lambda (\\domain)} \\norm{f}_{L^2(\\domain}^2\n  \\end{gather*}\n  which yields $E(v) \\ge - \\frac 1{2\\lambda (\\domain)^2} \\norm{f}_{L^2(\\domain}^2$\n  as a lower bound independent of $v$. To prove the second part,\n  we use the parallelogram identity $\\abs{v+w}^2 + \\abs{v-w}^2 = 2\\abs{v}^2 + 2 \\abs{w}^2$.\n  Let $m, n$ be natural numbers, then\n  \\begin{align*}\n    \\snorm{u^{(n)} - u^{(m)}}^2 _1 =& 2 \\snorm{u^{(n)}}^2 _1\n                                      + 2 \\snorm{u^{(m)}}^2_1- 4 \\snorm{\\nicefrac 12 (u^{(n)} + u^{(m)}}^2_1 \\\\\n    =& 4 E(u^{(n)}) + 4\\int f u^{(n)} \\dx + 4 E(u^{(m)}) + 4\\int f u^{(m)} \\dx \\\\\n                                    &- 8 E(\\nicefrac 12 (u^{(n)} + u^{(m)}) - 8 \\int \\nicefrac 12 f(u^{(n)} + u^{(m)}) \\\\\n    =& 4 E(u^{(n)}) + 4 E(u^{(m)}) - 8 E(\\nicefrac 12 f(u^{(n)} + u^{(m)}))\n  \\end{align*}\n  Taking the limit $m,n\\to \\infty$ yields $4 E(u^{(n)}) + 4 E(u^{(m)})\n  \\to 8 \\inf_{v \\in V_0} E(v)$. Lastly, $-E(\\nicefrac 12 f(u^{(n)} + u^{(m)}))$ can\n  be bounded by $\\inf_{v \\in V_0} E(v)$. It follows that $\\limsup_{m,n\\to\\infty}\n  \\snorm{u^{(n)}-u^{(m)}}^2_1 \\le 0$ and consequently as desired\n  \\begin{gather*}\n    \\lim_{m,n\\to\\infty} \\snorm{u^{(n)}-u^{(m)}}^2_1 = 0.\n  \\end{gather*}    \n\\end{proof}\n\n\\begin{notes}{Dirichlet-proof}\n  Dirichlet's principle proved essential for the development of a\n  rigorous solution theory for Poisson's equation.  Its proof will be\n  deferred to the next theorem.\n\\end{notes}\n\n\\subsection{Variational principle and weak formulation}\n\\begin{Theorem}{Dirichlet-variational-principle}\n  A function $u\\in V_g$ minimizes the Dirichlet energy, if and only if\n  there holds\n  \\begin{gather}\n    \\int_{\\domain} \\nabla u\\cdot\\nabla v \\dx\n    = \\int_{\\domain} fv\\dx, \\qquad\\forall v\\in V_0.\n  \\end{gather}\n  Moreover, any solution to the Dirichlet problem in\n  \\slideref{Definition}{dirichlet-problem-differential} solves this\n  equation.\n\\end{Theorem}\n\n\\begin{Corollary}{Dirichlet-uniqueness}\n  If a minimizer of the Dirichlet energy exists, it is necessarily unique.\n\\end{Corollary}\n\n\\begin{Lemma}{reduction-to-zero-bc}\n  A function $u\\in V_g$ minimizes the Dirichlet energy admits the\n  representation $u = u_g + u_0$, where $u_g\\in V_g$ is arbitrary and\n  $u_0\\in V_0$ solves\n  \\begin{gather}\n    \\int_{\\domain} \\nabla u\\cdot\\nabla v \\dx\n    = \\int_{\\domain} fv\\dx\n    - \\int_{\\domain} \\nabla u_g\\cdot\\nabla v \\dx,\n    \\qquad\\forall v\\in V_0.\n  \\end{gather}\n  The function $u_0$ depends on the choice of $u_g$, but not the minimizer $u$.\n\\end{Lemma}\n\n\\begin{Notation}{l2}\n  The inner product of $L^2(\\domain)$ is denoted by\n  \\begin{gather*}\n    \\form(u,v) \\equiv \\form(u,v)_{\\domain}\n    \\equiv \\form(u,v)_{L^2(\\domain)}\n    = \\int_{\\domain} u v \\dvx.\n  \\end{gather*}\n  Its norm is\n  \\begin{gather*}\n    \\norm{u} \\equiv \\norm{u}_{\\domain} \\equiv \\norm{u}_{L^2(\\domain)}\n    \\equiv \\norm{u}_{L^2} = \\sqrt{\\form(u,v)_{L^2(\\domain)}}.\n  \\end{gather*}\n\\end{Notation}\n\\begin{Lemma*}{Friedrichs-continuous}{Friedrichs inequality}\n  For any function in $v\\in V_0$ there holds\n  \\begin{gather}\n      \\norm{v}_{\\domain}\n      \\le \\diam(\\domain) \\norm{\\nabla v}_{\\domain}.\n  \\end{gather}\n\\end{Lemma*}\n\n\\begin{Lemma}{h1-norm}\n  The definitions\n  \\begin{gather}\n    \\begin{split}\n      \\abs{v}_1 &= \\norm{\\nabla v}_{L^2(\\domain)},\\\\\n      \\norm{v}_1 &= \\sqrt{\\norm{v}^2_{L^2(\\domain)}\n        + \\abs{v}^2_1},\n    \\end{split}\n  \\end{gather}\n  both define a norm on $V_0$.\n\\end{Lemma}\n\n\\begin{Problem}{Friedrichs}\n  Prove the Friedrichs inequality.\n\\end{Problem}\n\n\\begin{Lemma}{Dirichlet-energy-boundedness}\n  The Dirichlet energy with homogeneous boundary conditions is bounded\n  from below and thus has an infimum. In particular, there exists a\n  \\define{minimizing sequence} $\\{u^n\\}$ such that as $n\\to\\infty$,\n  \\begin{gather}\n    E(u^n) \\to \\inf_{v\\in V_0} E(v).\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Lemma}{minimizing-sequence}\n  The minimizing sequence for the Dirichlet energy is a\n  \\putindex{Cauchy sequence}.\n\\end{Lemma}\n\n\\begin{Definition}{h10}\n  The completion of $V_0$ under the norm $\\norm{v}_1$ is the\n  \\define{Sobolev space} $H^1_0(\\domain)$.\n\\end{Definition}\n\n\\begin{Lemma*}{Friedrichs-h1}{Friedrichs inequality}\n  For any function in $v\\in H^1_0$ there holds\n  \\begin{gather}\n      \\norm{v}_{\\domain}\n      \\le \\diam(\\domain) \\norm{\\nabla v}_{\\domain}.\n  \\end{gather}\n\\end{Lemma*}\n\n\\begin{proof}\n  Let $v\\in H^1_0(\\domain)$.  We make use of the fact, that by\n  definition of $H^1_0(\\domain)$, there is a sequence $v_n \\to v$ with\n  $v_n \\in V_0$. By~\\slideref{Lemma}{Friedrichs-continuous},\n  Friedrichs' inequality holds for $v_n$ uniformly in $n$. We conclude\n  \\begin{align*}\n    \\norm{v}_\\domain &\\le \\norm{v - v_n}_\\domain + \\norm{v_n}_\\domain \\\\\n    & \\le \\norm{v - v_n}_\\domain + \\diam\\domain \\norm{\\nabla v_n}_\\domain \\\\\n    & \\le \\norm{v - v_n}_\\domain + \\diam\\domain\n      \\bigl(\\norm{\\nabla v_n - \\nabla v}_\\domain + \\norm{\\nabla v}_\\domain\\bigr)\n  \\end{align*}\n  As $n\\to\\infty$, the norms of the differences converge to zero, such\n  that the desired result holds in the limit.\n\\end{proof}\n\n\\begin{Definition}{weak-formulation}\n  The \\putindex{Dirichlet problem} for Poisson's equation in weak form\n  reads: find $u\\in H^1_g(\\domain)$ such that\n  \\begin{gather}\n    \\int_{\\domain} \\nabla u\\cdot\\nabla v \\dx\n    = \\int_{\\domain} fv\\dx, \\qquad\\forall v\\in H^1_0(\\domain).\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Theorem}{weak-unique-solution-1}\n  The weak formulation in \\slideref{Definition}{weak-formulation} has\n  a unique solution.\n\\end{Theorem}\n\n\\subsection{Boundary conditions in weak form}\n\n\\begin{Lemma}{neumann-weak}\n  Let $u\\in V=H^1(\\domain)$ be a solution to the weak formulation\n  \\begin{gather}\n    \\int_{\\domain} \\nabla u\\cdot\\nabla v \\dx\n    = \\int_{\\domain} fv\\dx, \\qquad\\forall v\\in V(\\domain).\n  \\end{gather}\n  If $u\\in C^2(\\domain) \\cap C^1(\\overline{\\domain})$ and $\\domain$\n  has $C^1$-boundary, then $u$ solves the boundary value problem\n  \\begin{gather}\n    \\begin{aligned}\n      -\\Delta u &= f &\\qquad \\text{in } &\\domain\\\\\n      \\d_n u &= 0 &\\text{on } &\\d\\domain.\n    \\end{aligned}\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Definition}{natural-bc}\n  A boundary condition inherent in the weak formulation and not\n  explicitly stated is called \\define{natural boundary condition}. If\n  boundary values are obtained by constraining the function space it\n  is called \\define{essential boundary condition}.\n\n  We also call a boundary condition in strong form, if it is a\n  constraint on the function space, and in weak form, if it is part of\n  the weak formulation.\n\\end{Definition}\n\n\\begin{remark}\n  Dirichlet and homogeneous Neumann boundary conditions are examples\n  for essential and natural boundary conditions.\n\\end{remark}\n\n\\begin{Lemma}{mixed-bc-weak}\n  The boundary value problem\n  \\begin{gather}\n    \\begin{aligned}\n      -\\Delta u &= f &\\qquad \\text{in } &\\domain\\\\\n      u &= 0 &\\text{on } &\\Gamma_D \\subset \\d\\domain\\\\\n      \\d_n u + \\alpha u &= g &\\text{on } &\\Gamma_R \\subset \\d\\domain,\n    \\end{aligned}\n  \\end{gather}\n  has the weak form: find $u\\in V$ such that\n  \\begin{gather}\n    \\int_{\\domain} \\nabla u\\cdot\\nabla v \\dx\n    + \\int_{\\Gamma_R}\\alpha u v \\ds\n    = \\int_{\\domain} f v\\dx\n    + \\int_{\\Gamma_R} g v \\ds, \\qquad\\forall v\\in V(\\domain).    \n  \\end{gather}\n\\end{Lemma}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End: \n", "meta": {"hexsha": "eb0889c6d78b3449393f152d73dfa3bbfb3cdea1", "size": 15206, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "fem/pde.tex", "max_stars_repo_name": "Miraculixilein/notes", "max_stars_repo_head_hexsha": "6421317ecd80e08ba14b4b8f3057803c18f2897c", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fem/pde.tex", "max_issues_repo_name": "Miraculixilein/notes", "max_issues_repo_head_hexsha": "6421317ecd80e08ba14b4b8f3057803c18f2897c", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fem/pde.tex", "max_forks_repo_name": "Miraculixilein/notes", "max_forks_repo_head_hexsha": "6421317ecd80e08ba14b4b8f3057803c18f2897c", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.9563218391, "max_line_length": 121, "alphanum_fraction": 0.6444824411, "num_tokens": 5522, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7356784689927659}}
{"text": "\\section{The Basics}\n\n\\subsection{Exercises}\n\n\\subsubsection{Exercise 2.1}\nLet $a = nb + k$. If $n \\geq 2$, then $\\frac{a}{2} \\geq b > a \\mod b$ since $a \\mod b \\leq b-1$. For $n = 1$\nwe have\n\\begin{align*}\n        k < b \\implies \\frac{k}{2} < \\frac{b}{2} \\implies k < \\frac{b}{2} + \\frac{k}{2} = \\frac{a}{2}\n\\end{align*}\nSince Euclid's algorithm ``alternates'' between performing divisions on $a$ and $b$ (since $a$ is replaced\nby $b$ after a step), the number of divisions it performs is bounded by $2\\log_2 a$.\n\n\\subsubsection{Exercise 2.2}\nThe maximum divisor of $a$ is bounded by $\\sqrt{a}$. We can find all primes less than or equal to $\\sqrt{a}$ \nin polynomial time by using a prime number sieve approach (e.g. Sieve of Eratosthenes). Once we have\nthe primes, the number of operations it takes to compute the prime factorization of $a$ is bounded by\n$\\sqrt{a} \\log_2 a$, since the number of primes is bounded by $\\sqrt{a}$ and  2 is the smallest prime.\n\n\\subsubsection{Exercise 2.3}\nChanging logarithm base amounts to multiplying by a constant.\n\n\\subsubsection{Exercise 2.4}\nWe have the following\n\\begin{itemize}\n        \\item $4\\log_2 n = \\log_2 n^4 \\implies n^4$\n        \\item $4\\sqrt{n} = \\sqrt{16n} \\implies 16n$\n        \\item $4n \\implies 4n$ \n        \\item $4n^2 = (2n)^2 \\implies 2n$\n        \\item $4 * 2^n = 2^{n+2} \\implies n + 2$ \n        \\item $4 * 4^n = 4^{n+1} \\implies  n + 1$\n\\end{itemize}\n\n\\subsection{Problems}\n\n\\subsubsection{Problem 2.18}\nAn adjacency matrix requires a single bit for each vertex pair, so we need $n^2$ bits to specify it. A list\nof edges consists of  $m$ tuples of the form $(a, b)$ for $1 \\leq a, b \\leq n$, so it requires $2m\\log n$ \nbits. Thus, we are better off using the adjacency list format for sparse graphs and the adjacency matrix \nformat for dense graphs. If, however, we consider multigraphs, then the adjacency matrix requires $n^2 \\log n$\nbits (as we need to store the number of edges from $a$ to $b$). Thus, in the multigraph case, we can always\nchoose to use adjacency lists.\n\n\\subsubsection{Problem 2.19}\nSuppose $f(n) = O(n^a)$ and $g(n) = O(n^b)$. Then we have that\n\\begin{align*}\n        \\exists c_1, c_2, N \\: | \\: f(n) &\\leq c_1 n^a, \\: g(n) \\leq c_2 n^b \\quad \\forall n \\geq N\\\\\n        \\implies g(f(n)) &\\leq g(c_1 n^a) \\leq c_2 (c_1 n^a)^b = O(n^{ab})\n\\end{align*}\nso $\\text{poly}(n)$ is closed under composition. Thus, any polynomial time algorithm that calls another \npolynomial time algorithm remains polynomial.\n\n\\subsubsection{Problem 2.20}\nSince $f(n) = 2^{\\Theta(\\log^k n)}$ and $g(n) = O(n^a)$, there exists $N$ such that for all $n \\geq N$\nwe have $f(n) \\geq 2^{c_1 \\log^k n}$ and $g(n) \\leq c_2 n^a$ for some constants $c_1, c_2$. Thus,\n\\begin{align*}\n        \\lim_{n \\to \\infty} \\frac{f(n)}{g(n)} &\\geq \\lim_{n \\to \\infty} \\frac{2^{c_1 \\log^k n}}{c_2 n^a} \\\\\n                                              &= \\lim_{n \\to  \\infty} \\frac{(n^{c_1})^{\\log^{k - 1} n}}{c_2 n^a}\n\\end{align*}\nSince $\\lim_{n \\to \\infty}\\log^{k - 1} n = \\infty$, we have that $f(n) = \\omega(g(n))$. To see that \n$f(n) = o(h(n))$, we substitute $n = 2^x$ to get\n\\begin{align*}\n        \\lim_{x \\to \\infty} \\frac{f(2^x)}{g(2^x)} &\\leq \\lim_{x \\to \\infty} \\frac{2^{a_1 x^k}}{2^{a_2 2^{c x}}} \\\\\n                                                  &= 0\n\\end{align*}\nWhere we used the fact that $\\lim_{x \\to \\infty} \\frac{a_1 x^k}{a_2 2^{c x}} = 0$. Finally, to see that \n$\\text{QuasiP}$ is closed under composition, we can check that \n\\begin{align*}\n        2^{\\log^{k_1} 2^{\\log^{k_2} n}} = 2^{\\log^{k_1 k_2} n}\n\\end{align*}\n\n", "meta": {"hexsha": "93e52f39e8638986e0ce5a95a6525cb44743f951", "size": 3574, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Nature_of_Computation_Moore_Mertens/chapter_2.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "Nature_of_Computation_Moore_Mertens/chapter_2.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Nature_of_Computation_Moore_Mertens/chapter_2.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.6388888889, "max_line_length": 114, "alphanum_fraction": 0.6186345831, "num_tokens": 1330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964034, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7356784684912028}}
{"text": "\\chapter{Classical Computational Complexity Calculus }\n\n\n\\section{Introduction and Motivation}\nThis chapter will present the traditional methodology of calculus in the field of algorithm's computational complexity. The complexity will be expressed as a function $f:\\mathbb{N}\\longrightarrow\\mathbb{R}$, where the function is characterized by the size of the input, while the evaluated value $f(n)$, for a given input size $n$, represents the amount of resources needed in order to compute the result. While the most often analyzed resource is time, expressed in primitive computational operations, the mathematical model is self-reliant for others natures of resources, including space reasoning or hybrid metrics.\n\nAll the results of this chapter are well known in the literature and they represent the reference standard in calculating algorithm complexity in the field \\textit{Computer Science}.\n\nBecause of the difficulty of having a rigorous calculus of the complexity, an asymptotic computation approach for an algorithm's complexity offers a valuable insight about the real computational cost without requiring a precisely, flawless calculus.\n\n\n\\section{Family of Bachmann–Landau notations}\nThe following notations and names will be used for describing the asymptotic behavior of a algorithm's complexity characterized by a function, $f:\\mathbb{N}\\longrightarrow\\mathbb{R}$. \\\\\nWe define the set of all complexity calculus $\\mathcal{F}= \\lbrace f:\\mathbb{N}\\longrightarrow\\mathbb{R} \\rbrace$\n\\\\Assume that $n, n_{0}\\in\\mathbb{N}$. Also, we will consider an arbitrary complexity function $g \\in \\mathcal{F}$. \\\\\n\n\\begin{definition}\n    Assume that two continuous and derivable functions $v,w:\\mathbb{R}\\longrightarrow\\mathbb{R}$ are considered to be similar in an \\textbf{asymptotic analysis} iff:\n    \\[\\lim_{x\\to\\infty} \\frac{v(x)}{w(x)} = c \\in (-\\infty, 0) \\cup (0,\\infty) \\]\n\\end{definition}\n\n\\begin{lemma}\n    Consider that if we analyses asymptotic behavior of functions defined over $\\mathbb{N}$ the functions $v,w:\\mathbb{N}\\longrightarrow\\mathbb{R}$ are similar iff there exists a function $r:\\mathbb{N}\\longrightarrow\\mathbb{R}$, with $r(x) = \\frac{v(x)}{w(x)}\\ \\forall\\ x\\in\\mathbb{N}$, such that\n    \\[\\lim_{x\\to\\infty} r(x) = \\lim_{x\\to\\infty} \\frac{v(x)}{w(x)} = C \\in (-\\infty, 0) \\cup (0,\\infty) \\]\n\\end{lemma}\n\nThe following function classes can be therefore defined for any function $g:\\mathbb{N}\\longrightarrow\\mathbb{R}$ that describes a convergent sequence or a divergent sequence with a limit that tends to infinity:\n\\begin{definition}\n    \\textbf{Big Theta}: This set defines the group of mathematical functions similar in magnitude with  $g(n)$ in the study of asymptotic behavior. A set-based description of this group can be expressed as:\n    \\[\\Theta(g(n))= \\lbrace f \\in \\mathcal{F}\\ |\\ \\exists c_{1}, c_{2} \\in \\mathbb{R}^{*}_{+}, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\ \\ c_{1} \\cdot g(n) \\leq f(n) \\leq c_{2} \\cdot g(n)\\ ,\\  \\forall n \\geq n_{0} \\rbrace\\]\n\\end{definition}\n\n\\begin{lemma}\n    Another useful method of establishing a Big-Theta acceptance, if the composed sequence defined by the ratio of the two functions exists and also $ \\lim_{x\\to\\infty} \\frac{f(x)}{g(x)}$ exists, is by applying the sufficient condition:\n    \\[ f \\in \\Theta(g(n))\\ \\Leftrightarrow\\ \\lim_{x\\to\\infty} \\frac{f(x)}{g(x)} = C \\in (-\\infty, 0) \\cup (0,\\infty) \\]\n\\end{lemma}\n\nRemark that both $f,g$ can define divergent sequence with limits that tend to infinity, while the sequence $r(x) = \\frac{f(x)}{g(x)}\\ \\forall\\ x\\in\\mathbb{N}$ can be convergent and can have a nonzero limit. \\\\\nIff $ r(x) = \\frac{f(x)}{g(x)}\\ $ exists, a sufficient condition can be defined using the formal limit definition for an arbitrary sequence if the following condition holds:\n\\[\\exists \\  C \\in \\mathbb{R}, \\ \\ C \\neq 0 \\ s.t. \\ \\forall \\epsilon > 0,\\exists n_{0} \\in \\mathbb{N}\\ \\ s.t.\\ \\forall n\\geq n_{0}, \\ \\  |r(n) - C| < \\epsilon  \\]\nThus, if $ \\exists \\  C \\in \\mathbb{R}, C \\neq 0 \\  \\Rightarrow\\  f \\in \\Theta(g(n))\\ $\n\n\n\\begin{definition}\n    \\textbf{Big O}: This set defines the group of mathematical functions that are known to have a similar or lower\n    asymptotic performance in comparison with  $g(n)$. The set of such functions is defined as it follows:\n    \\[\\mathcal{O}(g(n)) = \\lbrace f \\in \\mathcal{F}\\ |\\ \\exists c \\in \\mathbb{R}^{*}_{+}, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f(n) \\leq c \\cdot g(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n\\end{definition}\n\\begin{lemma}\n    In order to establish a Big-O acceptance, the sufficient condition is that the $ \\lim_{x\\to\\infty} \\frac{f(x)}{g(x)}$ exists and it is finite.\n    \\[ f \\in \\mathcal{O}(g(n))\\ \\Leftrightarrow\\ \\lim_{x\\to\\infty} \\frac{f(x)}{g(x)} = C \\in (-\\infty, \\infty) \\]\n\\end{lemma}\n\n\n\\begin{definition}\n    \\textbf{Big Omega}: This set defines the group of mathematical functions that are known to have a similar or higher asymptotic performance in comparison with  $g(n)$. The set of all function is defined as:\n    \\[\\Omega(g(n)) = \\lbrace f \\in \\mathcal{F}\\ |\\ \\exists c \\in \\mathbb{R}^{*}_{+}, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f(n) \\geq c \\cdot g(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n\\end{definition}\n\n\\begin{lemma}\n    In order to establish a Big-Omega acceptance, a sufficient condition is one of the following:\n    \\begin{enumerate}[label=(\\roman*)]\n\n        \\item  \\[  \\lim_{x\\to\\infty} \\frac{f(x)}{g(x)} = -\\infty \\Rightarrow f \\in \\Omega(g(n))\\ \\]\n        \\item  \\[ \\lim_{x\\to\\infty} \\frac{f(x)}{g(x)} = \\infty \\Rightarrow f \\in \\Omega(g(n))\\  \\]\n        \\item  \\[ \\lim_{x\\to\\infty} \\frac{f(x)}{g(x)} = C \\in (-\\infty, 0) \\cup (0,\\infty) \\Rightarrow f \\in \\Omega(g(n))\\ \\]\n    \\end{enumerate}\n\\end{lemma}\n\n\\begin{definition}\n    \\textbf{Small O}:\n    This set defines the group of mathematical functions that are known to have a humble\n    asymptotic performance in comparison with  $g(n)$. The set of such functions is defined as it follows:\n    \\[o(g(n)) = \\lbrace f \\in \\mathcal{F}\\ |\\ \\forall c \\in \\mathbb{R}^{*}_{+}, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f(n) < c \\cdot g(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n\\end{definition}\n\\begin{lemma}\n    In order to establish a Small-O acceptance, the sufficient condition is that the $ \\lim_{x\\to\\infty} \\frac{f(x)}{g(x)}$ exists and it is finite.\n    \\[ f \\in o(g(n))\\ \\Leftrightarrow\\ \\lim_{x\\to\\infty} \\frac{f(x)}{g(x)} = 0 \\]\n\\end{lemma}\n\n\\begin{definition}\n    \\textbf{Small Omega}:\n    This set defines the group of mathematical functions that are known to have a commanding asymptotic performance in comparison with  $g(n)$.\n    The set of such functions is defined as it follows:\n    \\[\\omega(g(n)) = \\lbrace f \\in \\mathcal{F}\\ |\\ \\forall c \\in \\mathbb{R}^{*}_{+}, \\exists n_{0} \\in \\mathbb{N}^{*}\\ s.t.\\  f(n) > c \\cdot g(n),\\  \\forall n \\geq n_{0} \\rbrace\\]\n\\end{definition}\n\\begin{lemma}\n    In order to establish a Small-Omega acceptance, the sufficient condition is that the $ \\lim_{x\\to\\infty} \\frac{f(x)}{g(x)}$ exists and one of the following occurs:\n    \\begin{enumerate}[label=(\\roman*)]\n        \\item \\[  \\lim_{x\\to\\infty} \\frac{f(x)}{g(x)} = +\\infty \\Rightarrow f \\in \\omega(g(n))\\ \\]\n        \\item  \\[  \\lim_{x\\to\\infty} \\frac{f(x)}{g(x)} = -\\infty \\Rightarrow f \\in \\omega(g(n))\\ \\]\n    \\end{enumerate}\n\\end{lemma}\n\n\n\\section{Common properties}\nWe will study few aspects~\\cite{mogocs2015new};\nwith impact on defining equivalence relations over classes defined in \\textit{Bachmann–Landau} notations.\n\\hfill\\break\n\\begin{theorem}\n    The reflexivity property holds for Big Theta, Big O and Big Omega notations.  \\\\  $ f \\in \\Theta(f(n)) $ \\\\$ f \\in \\mathcal{O}(f(n)) $ \\\\$ f \\in \\Omega(f(n)) $\n\\end{theorem}\n\n\\begin{remark}\n    The reflexivity property does not hold for Small O and Small Omega notations \\\\\n    $ f \\notin \\theta(f(n)) $ \\\\$ f \\notin \\omega(f(n)) $\n\\end{remark}\n\n\\begin{theorem}\n    The transitivity property holds for \\textit{Bachmann–Landau} notations.  \\\\  $ f \\in \\Theta(g(n)), g \\in \\Theta(h(n)) \\Rightarrow  f \\in \\Theta(h(n))$ \\\\\n    $ f \\in \\mathcal{O}(g(n)), g \\in \\mathcal{O}(h(n)) \\Rightarrow  f \\in \\mathcal{O}(h(n))$ \\\\\n    $ f \\in \\Omega(g(n)), g \\in \\Omega(h(n)) \\Rightarrow  f \\in \\Omega(h(n))$ \\\\\n    $ f \\in o(g(n)), g \\in o(h(n)) \\  \\Rightarrow  f \\in o(h(n))$ \\\\\n    $ f \\in \\omega(g(n)), g \\in \\omega(h(n)) \\Rightarrow  f \\in \\omega(h(n))$\n\\end{theorem}\n\n\\begin{theorem}\n    The symmetry property holds for Big Theta notation. \\\\  $ f \\in \\Theta(g(n)) \\Rightarrow g \\in \\Theta(f(n)) $\n\\end{theorem}\n\n\\begin{theorem}\n    The transpose symmetry property for \\textit{Bachmann–Landau} notations.  \\\\  $ f \\in \\mathcal{O}(g(n)) \\Leftrightarrow g \\in \\Omega(f(n)) $\n    \\\\  $ f \\in o(g(n)) \\Leftrightarrow g \\in \\omega(f(n)) $\n\\end{theorem}\n\n\\begin{theorem}\n    The projection property for Big Theta, Big O and Big Omega notations. \\\\  $ f \\in \\Theta(g(n)) \\Leftrightarrow f \\in \\mathcal{O}(g(n)), f \\in \\Omega(g(n)) $\n\\end{theorem}\n\n\n\\section{Addition properties}\nCalculus in $Bachmann-Landau$ notations (including Big-O arithmetic) is extremely powerful and when it comes to addition operations, it is straightforward. The following relations hold for any correctly defined functions $f, g, h:\\mathbb{N}\\longrightarrow\\mathbb{R}$ :\n\n\n\n\\begin{lemma}\n    Addition in \\textbf{Big Theta}\n\n    If  $ h(n) = f(n) + g(n)\\  \\forall n \\in  \\mathbb{N} $ and $\\exists n_{0} \\in \\mathbb{N},\\ s.t.\\ \\forall n \\in \\mathbb{N} \\ \\Rightarrow f(n) \\leq g(n)$, then:\n    \\[  h \\in \\Theta(g)\\]\n\n\\end{lemma}\n\\begin{remark}\n    For each theorem, we will expose a corollary using a relax notation (consider that by any $Bachmann-Landau$ class notation, we denote an arbitrary function part of the class), some relations that can be settled.\n\\end{remark}\n\\begin{corollary}\n    Addition in \\textbf{Big Theta} using the relaxed notation:\n    \\[  \\Theta(f) + \\Theta(g) = \\Theta(g)\\]\n\\end{corollary}\n\n\\begin{lemma}\n    Addition in \\textbf{Big O}:\n\n    If  $ h(n) = f(n) + g(n)\\  \\forall n \\in  \\mathbb{N} $ and $\\exists n_{0} \\in \\mathbb{N},\\ s.t.\\ \\forall n \\in \\mathbb{N} \\ \\Rightarrow f(n) \\leq g(n)$, then:\n    \\[  h \\in \\mathcal{O}(g)\\]\n\n\\end{lemma}\n\\begin{corollary}\n    Addition in \\textbf{Big O} using the relaxed notation:\n    \\[  \\mathcal{O}(f) + \\mathcal{O}(g) = \\mathcal{O}(g)\\]\n\\end{corollary}\n\n\\begin{lemma}\n    Addition in \\textbf{Big Omega}:\n\n    If  $ h(n) = f(n) + g(n)\\  \\forall n \\in  \\mathbb{N} $ and $\\exists n_{0} \\in \\mathbb{N},\\ s.t.\\ \\forall n \\in \\mathbb{N} \\ \\Rightarrow f(n) \\leq g(n)$, then:\n    \\[  h \\in \\Omega(g)\\]\n\n\\end{lemma}\n\\begin{corollary}\n    Addition in \\textbf{Big Omega} using the relaxed notation:\n    \\[  \\Omega(f) + \\Omega(g) = \\Omega(g)\\]\n\\end{corollary}\n\n\\begin{lemma}\n    Addition in \\textbf{Small O}:\n\n    If  $ h(n) = f(n) + g(n)\\  \\forall n \\in  \\mathbb{N} $ and $\\exists n_{0} \\in \\mathbb{N},\\ s.t.\\ \\forall n \\in \\mathbb{N} \\ \\Rightarrow f(n) \\leq g(n)$, then:\n    \\[  h \\in o(g)\\]\n\n\\end{lemma}\n\\begin{corollary}\n    Addition in \\textbf{Small O} using the relaxed notation:\n    \\[  o(f) + o(g) = o(g)\\]\n\\end{corollary}\n\n\\begin{lemma}\n    Addition in \\textbf{Small Omega}:\n\n    If  $ h(n) = f(n) + g(n)\\  \\forall n \\in  \\mathbb{N} $ and $\\exists n_{0} \\in \\mathbb{N},\\ s.t.\\ \\forall n \\in \\mathbb{N} \\ \\Rightarrow f(n) \\leq g(n)$, then:\n    \\[  h \\in \\omega(g)\\]\n\n\\end{lemma}\n\\begin{corollary}\n    Addition in \\textbf{Small Omega} using the relaxed notation:\n    \\[  \\omega(f) + \\omega(g) = \\omega(g)\\]\n\\end{corollary}\n", "meta": {"hexsha": "2d5f5019d28c49d7b5eaefc6b5fd5d6801e0e2ea", "size": 11451, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TeX/complexity/complexity.tex", "max_stars_repo_name": "raresraf/rafMetrics", "max_stars_repo_head_hexsha": "21eb5e8210364bf70eee746d71c45f3e353dcb10", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2019-11-03T18:01:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T20:54:57.000Z", "max_issues_repo_path": "TeX/complexity/complexity.tex", "max_issues_repo_name": "raresraf/rafMetrics", "max_issues_repo_head_hexsha": "21eb5e8210364bf70eee746d71c45f3e353dcb10", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 392, "max_issues_repo_issues_event_min_datetime": "2019-11-09T21:28:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T13:04:45.000Z", "max_forks_repo_path": "TeX/complexity/complexity.tex", "max_forks_repo_name": "raresraf/rafMetrics", "max_forks_repo_head_hexsha": "21eb5e8210364bf70eee746d71c45f3e353dcb10", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-11T18:35:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-11T18:35:16.000Z", "avg_line_length": 57.8333333333, "max_line_length": 619, "alphanum_fraction": 0.6586324338, "num_tokens": 3769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.8615382147637195, "lm_q1q2_score": 0.7356784623360798}}
{"text": "\\section{Designing a Greatest Common Divisor Circuit}\n\\subsection{Theory}\nGreatest Common Divisor (GCD) of two non zero integers is the largest number that is a common divisor of both integers. In this implementation, we are more focused on circuit size and speed rather than optimizing the algorithm. The common way of computing the GCD can be accomplished by the following algorithm:\n\n\\begin{algorithm}\n\\caption{Computing GCD algorithm}\\label{euclid gcd}\n\\begin{algorithmic}[1]\n\\Procedure{GCD(A, B)}{}\n\\BState \\emph{begin}:\n\\If {(A==B)} \\textbf{goto} \\emph{end}\n\\EndIf\n\\If {(A>B)} $\\textit A \\gets A-B$\n\\EndIf\n\\If {(B<A)} $\\textit B \\gets B-A$\n\\EndIf\n\\State \\textbf{goto} \\emph{begin}\n\\BState \\emph{end}:\n\\State $\\textit return \\ A$\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\nThe algorithm subtracts the largest number between the two inputs, from the other one. It will then update the largest input by the result of subtraction. This procedure will be continued until the two numbers are equal. This algorithm can be recursively implemented in System-Verilog as follows:\n\n\n\\begin{minted}{verilog}\nfunction int gcd_fcn(int a, int b);\n    return b == 0 ? a : gcd_fcn(b, a % b);\nendfunction\n\\end{minted}\n\n\\subsection{Implementation}\nThe behavioral model presented in previous section cannot be implemented in hardware. For that we need to extract the essential computational blocks from the algorithm. We are also going to need a state machine to keep track of states we are in. The state machine should also compute the next state. Adding state machine would increase our design size. This is due to the gate level implementation of registers that are required by the state machine to hold values between clock cycles. This means that one of the best ways of reducing the design size is to reduce the number of states that we need. In the first implementation of GCD, we used 3 states to compute the GCD. The following listing shows only the combinational logic part (the source code for this implementation can be found in \\href{https://github.com/hossein1387/random_hw_experiments/blob/master/GCD/GCDopt.sv}{link to GCD repository}):\n\n\\begin{minted}{verilog}\n    case (state)\n      s0: begin\n            a_next      = a_in;\n            b_next      = b_in;\n            gcd         = 32'd0;\n            state_next  = s1; \n            done        = 0;\n        end\n      s1: begin\n        if(a!=b) begin\n            a_next= (a >= b) ? a - b : a;\n            b_next     = (b >  a) ? b - a : b;\n            gcd        = 32'd0;\n            state_next = s1;\n        end else begin\n            state_next = s2;\n            end\n        end\n      s2: begin\n            gcd = a;\n            state_next = s0;\n            done = 1;\n        end\n        default: begin\n            state_next = s0;\n        end\n    endcase\n\\end{minted}\n\nIn the code above, \\mintinline{latex}{s0} samples the input and pulls down the $done$ signal (that indicates the output is ready to be sampled). In \\mintinline{latex}{s1}, we subtract the largest number from the other one and update the next state. Finally \\mintinline{latex}{s2} changes the next state to \\mintinline{latex}{s0} and more importantly, pulls up the ``done'' signal and outputs the result on the output line. Figure \\ref{SCHEMATIC} shows the schematic view of the circuit:\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=1.0\\textwidth]{Images/schematic.png}\n    \\caption{High level Schematic view of GCD implementation showing combinational and sequential logic }\n    \\label{SCHEMATIC}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=1.0\\textwidth]{Images/GCDNormal.png}\n    \\caption{GCD optimized}\n    \\label{GCDNORMAL}\n\\end{figure}\n\nFigure \\ref{GCDNORMAL} shows the waveform generated by GTKWave. As it is illustrated, GCD 14 and 161 is computed after 12 clock cycles and after that the ``done'' signal stays high for one clock cycle. As described earlier, by reducing number of states in the state machine, we can reduce the circuit size.  \n\nTo reduce the number of states, we can combine states 1 and 2 so that only 1 bit is required to hold the state and we will end up with less number of registers. The following listing shows how this can be achieved:\n\\begin{minted}{verilog}\n    case (state)\n      s0: begin\n            a_next      = a_in;\n            b_next      = b_in;\n            gcd         = 32'd0;\n            state_next  = s1; \n            done        = 0;\n        end\n      s1: begin\n        if(a!=b) begin\n            a_next= (a >= b) ? a - b : a;\n            b_next     = (b >  a) ? b - a : b;\n            gcd        = 32'd0;\n            state_next = s1;\n        end else begin\n            gcd = a;\n            state_next = s0;\n            done = 1;\n            end\n        end\n        default: begin\n            state_next = s0;\n        end\n\\end{minted}\n\nFigure \\ref{GCDOPT} shows that the same result is achieved but with less number of registers. The synthesis of this circuit is done using Yosys 3.0 available at \n\\href{https://www.edaplayground.com/x/4reN}{Synthesis Result}.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=1.0\\textwidth]{Images/GCDOpt.png}\n    \\caption{GCD optimized}\n    \\label{GCDOPT}\n\\end{figure}\n\n\\subsection{Results and Source Code}\n\n\\markdownInput{GCD.md}\n", "meta": {"hexsha": "3547412cb3eddabc8b15cd3201a743cd21365af1", "size": 5301, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "GCD/docs/GCD.tex", "max_stars_repo_name": "hossein1387/random_hw_experiments", "max_stars_repo_head_hexsha": "af6d06510cda42f83025f8a07624bc7eaa27d49e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "GCD/docs/GCD.tex", "max_issues_repo_name": "hossein1387/random_hw_experiments", "max_issues_repo_head_hexsha": "af6d06510cda42f83025f8a07624bc7eaa27d49e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "GCD/docs/GCD.tex", "max_forks_repo_name": "hossein1387/random_hw_experiments", "max_forks_repo_head_hexsha": "af6d06510cda42f83025f8a07624bc7eaa27d49e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.0975609756, "max_line_length": 903, "alphanum_fraction": 0.6659120921, "num_tokens": 1398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916240341031, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7355689084236633}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{float}\n\\usepackage{bm}\n\\usepackage{url}\n\\usepackage[utf8]{inputenc}\n\\usepackage[margin=2cm]{geometry}\n\\setlength\\parindent{0pt}\n\n\\begin{document}\n\n\\title{An investigation into the Ethereum Cryptocurrency through Principal Component Analysis}\n\\author{Andrew P Talbot 1434667}\n\\date{\\today}\n\\maketitle\n\n\\vspace{5mm}\n\\section{Introduction}\nRecently, we have seen the words 'blockchain' and 'cryptocurrency' become real buzzwords, the most famous implementation of this is Bitcoin. This is currently the number one valued cryptocurrency both in price per coin, and total investment into the coin. Bitcoin is a decentralized currency that allows its users to send money using only their computer. It was created by an unknown person under the name of Satoshi Nakamoto, and since its creation we have seen plenty of new coins, and a community of people passionate about the technology that it provides, and other people interested in the opportunity that it's volatile market offers. This project however focuses on the current second largest cryptocurrency, which is Ethereum. This is runs on a completely different blockchain protocol, which has its own currency named Ether, which allows for new applications to be built on its blockchain system.\n\\vspace{3mm}\n\nI am performing Principal Component Analysis (PCA) on this dataset in the hope that we can learn about Ethereum, specifically what attributes can describe most of the variation in the behaviour of certain aspects of Ethereum. The first PCA experiment that we will perform on our data is where we label the price of Ether, and then we manipulate the leftover information to see what the important components are. I will be using Matlab for the computation in this project, due to its excellent built in methods for handling matrix computations, it also makes data visualization very easy.\n\n\\section{Our Dataset}\n\nIn this section, I provide a brief introduction to the dataset that I am conducting the first experiment on. I have sourced this data from \\texttt{www.kaggle.com}, and the exact link is found here\\cite{dataset}, and the specific dataset that I am using is found in the file \\texttt{ethereum\\_dataset.csv}. In the final section I also use the data found in the file \\texttt{bitcoin\\_price.csv}.\n\\vspace{3mm}\n\nThe dataset contains 18 attributes, and there are 832 instances of the data. The data contains information about the current state of Ethereum every day between the dates $30/07/2015$ to $07/11/2017$. The dataset has no missing variables, except for the \\texttt{eth\\_ens\\_register} column which only began collecting data from the date $03/05/2017$.\n\n\\subsection{Dataset Attributes}\nHere, we list the 18 attributes contained in our dataset, as displayed on the \\texttt{www.kaggle.com} webpage for our dataset\\cite{dataset}.\n\n\\begin{center}\n\\begin{itemize}\n\\item Date(UTC) : Date of transaction\n\\item UnixTimeStamp : unix timestamp\n\\item eth\\_etherprice : price of ethereum\n\\item eth\\_tx : number of transactions per day\n\\item eth\\_address : Cumulative address growth\n\\item eth\\_supply : Number of ethers in supply\n\\item eth\\_marketcap : Market cap in USD\n\\item eth\\_hashrate : hash rate in GH/s\n\\item eth\\_difficulty : Difficulty level in TH\n\\item eth\\_blocks : number of blocks per day\n\\item eth\\_uncles : number of uncles per day\n\\item eth\\_blocksize : average block size in bytes\n\\item eth\\_blocktime : average block time in seconds\n\\item eth\\_gasprice : Average gas price in Wei\n\\item eth\\_gaslimit : Gas limit per day\n\\item eth\\_gasused : total gas used per day\n\\item eth\\_ethersupply : new ether supply per day\n\\item eth\\_ens\\_register : Ethereal Name Service (ENS) registrations per day\n\\end{itemize}\n\\end{center}\n\n\\vspace{3mm}\nNext, we begin some of the experiments on our dataset.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Global Experiment Labelling Ether Price}\nIn our first PCA experiment that we will perform on our dataset, we will remove the attribute \\texttt{eth\\_etherprice}, and we will label this attribute into appropriate price ranges.\n\n\\subsection{Preprocessing the Data}\nIn order to perform the PCA, we must first process our dataset. Our dataset was originally in an Excel (csv) file, so we first turn this into a plain text file separated by spaces only, to allow for greater ease of use with Matlab. We furthermore note that there are a few issues with our dataset. The first of which is to do with the \\texttt{eth\\_ens\\_register} attribute, we note that there are only 187 instances of our data containing this attribute, and the rest are missing, as this data has only been collected since $05/04/2017$. Thus, as we are looking into a global view of the dataset, it makes sense to disregard this attribute for this part of the experiment. Furthermore, we note that the first few rows in our data, is filled with 0's, and our data is already right-skewed, so to slightly lessen their impact, we disregard the first few rows of our dataset, and thus we are left with a dataset of 14 attributes and 825 instances of the data.\n\\vspace{3mm}\n\nFurthermore, for this experiment, we will disregard the time variables, which are in fact the first two columns in our dataset, \\texttt{Date(UTC)}, and \\texttt{UnixTimeStamp}. As we are labelling the \\texttt{eth\\_etherprice} column, we will also be removing that data from the dataset. We must note that our dataset consists of mostly real variables, so we have not had to remove any boolean/categorical attributes as we may have to in other data sets. The only exception to this is the date attribute(e.g 20/02/2017).\n\\vspace{3mm}\n\nSo in total we have gone from an 18 dimensional data set to a 14 dimensional data set for our calculations. In the next step, we will normalize the 14 dimensional data set. We do this because PCA is a variance maximising procedure, if we normalize the data, then we will get a much better view of the dataset, and we will see how the lesser principal components do indeed provide more information about the variance of our data than we may have thought if we did not normalize. Here, we visualize the distribution of the attributes in our dataset before normalizing the columns.\n\\begin{figure}[H]\n\\centering\n\\caption{Here are multiple boxplots which allow us to visualize the distribution of the 14  attributes once they have been normalized that we are going to perform PCA on before they have been normalized}\n\\includegraphics[scale = 0.9]{main/boxplot_before_norm.eps}\n\\end{figure}\n\n\nNext, we visualize the distribution of the dataset after normalizing the columns. Note that we normalize each column in the dataset using the method that is used in that of the Boston Example provided by Peter Tino.\n\n\\begin{figure}[H]\n\\centering\n\\caption{Here is a boxplot of the 14 attributes that we are going to perform PCA on after they have been normalized, note that these are more suitable distributions to perform PCA on.}\n\\includegraphics[scale = 0.9]{main/boxplot_after_norm.eps}\n\\end{figure}\n\n\n\\subsection{Labelling the Ether Price}\nNext, we must label the price of Ether, we do this so that in the later stages we may visualize our PCA into some dimensional projection. Due to the interesting nature of this data set, we must use a slightly different labelling scheme. In order to better justify this scheme, we see a histogram of the \\texttt{eth\\_etherprice} column.\n\n\\begin{figure}[H]\n\\centering\n\\caption{Here is a histogram that allows us to visualize the Price of Ether, and the total number of occurences tha these prices happen. Note the right skew that we get from this graph}\n\\includegraphics{main/eth_priceOnly_noYMax.eps}\n\\end{figure}\n\nAs we can see in the above histogram, the price of Ether is quite drastically skewed to the right. This can be explained in that Ethereum spent a great deal of its life below the $\\$25$ mark, and sharply increased in price in the Summer of 2017. Now, because of the right skew of the data, we use a different labelling scheme. Our scheme is as follows:\n\n\\begin{center}\n\\begin{tabular}{ |c|c|c| } \n\\hline\nEther Price p & Label & Value\\\\\n\\hline\n$p < 25$ & Very Low & 1\\\\ \n$25 \\leq p < 118.75$ & Low & 2\\\\ \n$118.75 \\leq p < 212.5$ & Medium & 3\\\\ \n$212.5 \\leq p < 306.25$ & High & 4\\\\ \n$p \\geq 306.25$ & Very High & 5\\\\ \n\\hline\n\\end{tabular}\n\\end{center}\n\nBy doing this, we are essentially considering the Ether Prices under 25 as one single block (Very Low), then we split up the remaining values into 4 remaining blocks. Thus, we end up with the following histogram for the Ether Price, note that in this diagram, the y axis has been limited to 100 (we already know it hits a high of around 500), so that we can better view the data.\n\n\\begin{figure}[H]\n\\centering\n\\caption{Here is a histogram showing the Prices of Ethereum with the Labels indicated by a Red Line, Please note that we have limited the y axis to be from 0 - 100, so that we can get a better view of the data}\n\\includegraphics[scale=0.75]{main/eth_priceOnly.eps}\n\\end{figure}\n\n\\subsection{Principal Component Analysis}\nNow that we have preprocessed our data into a single dataset, and a labelled attribute, we are ready to perform some PCA. The first step we take is to create a Covariance Matrix of our data. We do this through the \\texttt{cov()} method that is provided in Matlab. This yields a $14$x$14$ matrix. \n\\vspace{3mm}\n\nNext, we calculate the eigenvectors and eigenvalues through the \\texttt{eig()} method, again provided by Matlab. Once we have done this, we now have the ability to analyze our principal components. Here is a scree plot that we can use to visualize our eigenvalues. The bars represents the percentage of variance described  by only that principal component. Whereas the line shows us the cumulative variance described by each of the principal components in descending order.\n\n\\begin{figure}[H]\n\\centering\n\\caption{A Scree Plot Showing the Variance described by each eigenvector, up to the 8th Principal Component. The blue line shows the cumulative percentage variance described by the data, whereas the orange bars describe the percentage of variance described by that particular component. Note, we only show the first 8 principal components, as thet are so small.}\n\\includegraphics[scale = 0.75]{main/scree_plot.eps}\n\\end{figure}\n\nPlease note that in our Scree plot we are only considering the first 8 principal components because the components 9 - 14 are extremely small. In fact, from the first 8 components we are capturing 99.5342\\% of the variation in the data. We want to project our data into the new space using some number of the principal eigenvectors. So, now we must choose this number, I have provided this table as it gives the exact percentages, as opposed to our Scree, which simply provides an overview.\n\n\\begin{center}\n\\begin{tabular}{ |c|c| } \n\\hline\nPrincipal Component & Cumulative Variance Present (\\%) \\\\\n\\hline\n1 & 67.04 \\\\ \n2 & 81.98 \\\\ \n3 & 89.12 \\\\ \n4 & 94.03 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\nWe see that our first principal component is able to describe $67.04\\%$ of the variance in our data, which is very high. Furthermore, our first two principal components are able to describe $81.98\\%$ of the variance in our dataset. As we are able to hold over $80\\%$ of our data from the first two components, it makes sense to project our data into its new space using the first two principle components .\n\\vspace{3mm}\n\nWe let $\\bm{A}$ be the $825$x$14$ matrix storing our normalized data. Then, we let $\\bm{B}$ be the $14$x$2$ matrix which we call our projection matrix. This projection matrix is the concatenation of the two eigenvectors with the largest eigenvalues. Thus we calculate the 2 dimensional projection of our data $\\bm{P}$ by\n\n$$\n\\bm{P} = \\bm{A} \\cdot \\bm{B}\n$$\n\nHere is the 2D projection of our dataset into the the new subspace that is created by the first two principal components, first we show the legend which shows the labelling scheme.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale = 0.7]{main/legend_2D_proj_copy.pdf}\n\\end{figure}\n\\begin{figure}[H]\n\\centering\n\\caption{Here is a projection of our original 14 dimensional dataset into the new 2 dimensional subspace under the labelling scheme on the Pricer of Ether that we have described earlier. We include the legend above.}\n\\includegraphics{main/eth_2d_projection.eps}\n\\end{figure}\n\nAs we might have expected, this 2D projection shows some very close clustering, as our scree plot might have suggested. This is down to the fact that we are able to capture over 80\\% of the variance in our dataset in this new subspace. If we were to extend this and create a 3D plot, we could capture nearly 90\\% of the variance in our data. This however is not necessary for the majority of this project as 81.98\\% is very high for 2 dimensions. If the variance captured was lower, I would expect to see much less clustering. Another note is that we see the best clustering for the values labelled Very Low (the magenta stars), this is perhaps because this is the label that was put on the greatest number of points in our dataset. We also include a biplot for this PCA experiment, seen below.\n\n\n\\begin{figure}[H]\n\\centering\n\\caption{A Biplot of our original data projected into the new 2D subspace by the first two principal components. I have omitted the labels lines that are clustered to the left as they are too close to view. Here are the missing labels in order from highest to lowest in the y axis: \\texttt{tx}, \\texttt{gasused}, \\texttt{gaslimit}, \\texttt{address}, \\texttt{marketcap}, \\texttt{hashrate}, \\texttt{blocksize}, \\texttt{difficulty}.}\n\\includegraphics{main/eth_2d_biplot_better.eps}\n\\end{figure}\n\n%%%%%%POTENTIALLY SERIOUSLY WRONG HERE, MIGHT NEED TO CHANGE THIS BIT%%%%%%%%\nThe biplot consists of all of our data points plotted in the new subspace, with the addition of 14 vectors. This allows us to visualize our data points, and the points in our eigenvector for each attribute. We note that the points to the right, in particular the ethersupply and blocks variables seem to play the largest role in the first principal component, note that these points are pointing north-west, and thus means that they played a large role in the second principal component. Perhaps this suggests that our \\texttt{eth\\_ethersupply} and \\texttt{eth\\_blocks} attributes provide a lot of the variance in our data. In fact, this is one of the reasons that I have chosen to perform my second PCA experiment on this attribute. It is also important to note that the vectors which appear close together are very closely related. In particular we note that out \\texttt{eth\\_marketcap} and \\texttt{eth\\_hashrate} attributes are very close together, and the vector is very small. There is likely to be a negative correlation between these two attributes for our dataset. This is to be expected, as the Ethereum marketcap often increases with time, and the Hash rate is becoming higher as time increases and mining Ether gets harder.\n\\vspace{3mm}\n\nHere, we have projected our dataset into a new 3 dimensional subspace using the first three principal components, just out of curiosity, to see how it compares to the 2D projection. The 2D projection captures 81.98\\% of the variance in our data, wheres, this 3D projection should capture 89.12\\% of the variance in our dataset. Thus, we expect that this will not show a great deal more clustering than the 2D projection does. \n\n\\begin{figure}[H]\n\\centering\n\\caption{Here is a 3D projection which is created from our first three principal components being concatenated into our 3x3 projection matrix. We then multiply this by our original data to view this projection on our labelling of Ether Price, these first 3 principal components allow us to capture 89.12\\% of the variance in our data, which is extremely high. We do not need this 3D projection, we have just included it to see if we are able to visualize better any clustering in our data.}\n\\includegraphics{main/eth_3d_projection.eps}\n\\end{figure}\n\n\n % It can be seen in Figure 5.  The direction and length of the\n%vectors produced indicates the contribution to the principal components from each attribute.  The attributes to\n%the right of the y-axis had the largest contribution to the first principle component, whilst those above the x-axis\n%had larger contributions towards the second principle component.  Furthermore, vectors that are close to each\n%other provide relationships.  For example,  it proves that total phenols is strongly related to proanthocyanins\n%and flavinoids, which are what make up total phenols.  The nonflavanoidal phenols seem to contribute to the\n%alkalinity of ash, and vice versa.  These were tested through some coordinate projections.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Local Experiment Labelling Ether Supply}\nA number of the attributes in our dataset can be used to describe how hard it is to currently mine Ether. This is the computationally intensive work, often performed by large machines with multiple Graphics Processing Units, which specifically is the validation of transactions within the Ethereum blockchain. By doing this the machines doing this work are rewarded fractions of Ether\\cite{ethereum_info}. There are a number of interesting problems surrounding the creation of Ethereum, in particular the creation and circulation of too much Ether could potentially negatively effect the Ether market. In fact, it's developers intend on limiting the supply of Ether, and even destroying some. In this section, I will label the column \\texttt{eth\\_ethersupply}, which describes the new supply of Ether each day. \n\n%There are a number of interesting problems surrounding the creation of Ethereum, in particular the creation and circulation of too much Ether could potentially negatively effect the Ether market.\n\n\\subsection{Preprocessing our data}\nIn the previous experiment, we had to perform PCA on our data whilst excluding the \\texttt{eth\\_ens\\_register} attribute, so in this section, we consider the subset of our original data in which that attribute has valid points. That is data collected between 08/05/2017 and 2/20/2018. Note, that the data I am using is being constantly updated and hence we have more current data with some information about 2018. Furthermore, we have deleted the attribute \\texttt{eth\\_supply}, due to its large correlation to the new supply of Ether daily. Thus, we are left with a dataset that has 287 instances of 14 attributes. \n\nAs we saw in our previous experiment of the global dataset, it was clear that we had to normalize each attribute, the same must be true for this experiment. I have included a boxplot of all attributes to provide a comparison to that of our new variable \\texttt{eth\\_ens\\_register}, and \\texttt{eth\\_etherprice}, which has been added back into our data. as before, we of course remove the attribute that we are labelling, which is \\texttt{eth\\_ethersupply}.\n\n\\begin{figure}[H]\n\\centering\n\\caption{A Boxplot visualizing the distribution of our 14 attributes, from the last boxplot, we have added the \\texttt{eth\\_ens\\_register} and \\texttt{eth\\_etherprice} attributes. We have included all of the attributes which are duplicates from Figures 1 and 2 so that they can be compared to our new variables.}\n\\includegraphics{local/boxplot_after_norm_supply.eps}\n\\end{figure}\n\n\\subsection{Labelling The Supply of Ether}\nIn this section, we aim to label the new supply of Ether per day in an appropriate manner. We chose the following labelling scheme:\n\n\\begin{center}\n\\begin{tabular}{ |c|c|c| } \n\\hline\nEther Supply s & Label & Value\\\\\n\\hline\n$s < 18350$ & Very Low & 1\\\\ \n$18350 \\leq s < 22100$ & Low & 2\\\\ \n$22100 \\leq s < 25850$ & Medium & 3\\\\ \n$ s \\geq 25850$ & High & 4\\\\ \n\\hline\n\\end{tabular}\n\\end{center}\n\nAgain, we plot a histogram of this data, so we can visualize its distribution. Note that we have added red Lines, which seperates the data into our seperate labels. This labelling scheme was chosen so that the first cluster is contained in the Very Low section. Then we split the remaining space of our graph into 3, then added a Line there to seperate them. We chose to call the term Very Low to describe the lowest number of New Ether supply as it is significantly lower than the rest of the data.\n\n\\begin{figure}[H]\n\\centering\n\\caption{Here is a histogram that we use to visualize the distribution of the Ether Supply Per Day, note that we visualize our labelling scheme by the four red lines appearing on the graph.}\n\\includegraphics[scale=0.75]{local/eth_supplyOnly.eps}\n\\end{figure}\n\nNow we have an appropriate labelling scheme and have preprocessed the data, we are now ready to perform the Principal Component Analysis.\n\n\\subsection{Principal Component Analysis}\nIn the previous section we performed the Principal Component Analysis on the global data, we will now do the same on our localized data. Please note that for these calculations, we use the same functions in Matlab as we did previously. We again create a Scree plot and we note that it is fairly similar to the Scree plot that was previously considered.\n\n\\begin{figure}[H]\n\\centering\n\\caption{A Scree Plot Showing the Variance described by each eigenvector, up to the 8th Principal Component. The blue line shows the cumulative percentage variance described by the data, whereas the orange bars describe the percentage of variance described by that particular component. Note, we only show the first 8 principal components, as thet are so small. This scree plot is different to that of the Scree of the First experiment as our data has changed, in particular we have a local view of our dataset and we have changed the attributes.}\n\\includegraphics[scale = 0.75]{local/scree_plot_supply.eps}\n\\end{figure}\n\nHere are the exact cumulative percentages as described by our Scree Plot for our first four principal components, to 2 decimal places.\n\n\\begin{center}\n\\begin{tabular}{ |c|c| } \n\\hline\nPrincipal Component & Cumulative Variance Present (\\%) \\\\\n\\hline\n1 & 64.79 \\\\ \n2 & 83.73 \\\\ \n3 & 92.23 \\\\ \n4 & 95.50 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\nWe thus see that our first principal component again provides a great amount of detail about the variance of our dataset, however it tells us slightly less than the first principal component did in our global experiment. We also note that our second and third principal components are larger than in our first experiment. So overall, from our first two principal components we are able to view 83.79\\% of our data. This is quite large, so again it makes sense for us to project our data using the first two principal components, as we will still be able to capture a lot about the data. We do the same calculations as before to calculate our 2d projections, except this time our 2D projection will have 297 points of data in our new space. We get the following projection:\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale = 0.7]{local/legend_2D_proj_copy.pdf}\n\\end{figure}\n\\begin{figure}[H]\n\\centering\n\\caption{Here is a projection of our original dataset into the new 2 dimensional subspace by the first two principal components calculated from the covariance matrix of our dataset.}\n\\includegraphics{local/eth_2d_projection_supply.eps}\n\\end{figure}\n\nThis 2D projection into our new subspace again shows some tight clusters. This is again due to the fact that this new subspace is able to capture such a high percentage of the variance in our dataset (83.73\\%). However, in this case we do note that there are some outliers, for example there is a magenta asterisk(Very Low) at approximately $(0.5, 0.75)$. Furthermore, we notice the blue circles have one main cluster, and then two seperate clusters. We note that there are less instances of our dataset in this PCA experiment, perhaps if we had a larger dataset, the clustering might become a bit more apparent.\n\n\\begin{figure}[H]\n\\centering\n\\caption{A Biplot of our original data projected into the new 2D subspace by the first two principal components. I have omitted the labels lines that are clustered to the left as they are too close to view. Here are the missing labels in order from highest to lowest in the y axis: \\texttt{gasused}, \\texttt{tx}, \\texttt{etherprice}, \\texttt{marketcap}, \\texttt{address}, \\texttt{hashrate}, \\texttt{gasprice}, \\texttt{blocksize}, \\texttt{gaslimit}.}\n\\includegraphics{local/eth_2d_biplot_supply.eps}\n\\end{figure}\n\nFrom the biplot we see that the \\texttt{eth\\_blocks} attribute contributes greatly to the second principal component. We also see that the \\texttt{eth\\_ens\\_register} attribute is significant in terms of the first and second principal component. Again we see an unsurprising result in that the \\texttt{eth\\_marketcap} and \\texttt{eth\\_etherprice} vectors are almost identical. This suggests a great correlation between the data of these attribute, which are clearly heavily linked.\n\n\\begin{figure}[H]\n\\centering\n\\caption{Here is a 3D projection which is created from our first three principal components being concatenated into our 3x3 projection matrix. We then multiply this by our original data to view this projection on our label of the Ether Supply, these first 3 principal components allow us to capture 92.23\\% of the variance in our data, which is extremely high. We do not need this 3D projection, we have just included it to see if we are able to visualize better any clustering in our data.}\n\\includegraphics{local/supply_3d_projection.eps}\n\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{A Final Experiment on the Price of Bitcoin Using our Ethereum Dataset}\n\nIn the final PCA experiment for this project, I have chosen to extend the dataset that I am currently using. I have added the daily high market price of Bitcoin to the corresponding day that the Ethereum data was collected(The day is what connects these two dataset). I chose to use the high price, as opposed to the starting, low or closing price, I decided this for no particular reason, as for the purpose of this project it will not matter. The cryptocurrency markets can be extremely volatile, and it often is the case that if Bitcoin sees a sharp increase or decrease in market price, then the majority of the smaller coins will follow the same trend. Upon completion of this PCA experiment, perhaps we can compare our data projections to that of the Ether price, to see if our calculations on the Ethereum dataset will also provide a good tool to decrease the number of dimensions when we need to consider the price of Bitcoin, instead of Ether. First, we preprocess the data and label the Bitcoin price.\n\n\\subsection{Preprocessing the data}\nOur preprocessing in this section is again extremely similar. We first get the Bitcoin Price data for the matching dates that our Ethereum data is taken from, in this case we are again considering a global view of the dataset. From the previous experiments, it is clear that we must again normalize our data. We do this using the same methods, and we include the following boxplot to again compare the distribution of our attributes again. We again note that because our data has been updated since the first global experiment, and we now consider all attributes except for \\texttt{eth\\_ens\\_register}, thus we  are preprocessing a dataset of 927 instances, and 15 attributes.\n\n\\begin{figure}[H]\n\\centering\n\\caption{Here is a box plot that we use to visualize the distribution of our 15 attributes after they have been normalized. It is clear that we must normalize our data because of our previous experiments. Further, we note that we include all attributes in the box plot just so they can be better visualized or compared.}\n\\includegraphics{final/boxplot_after_norm_btc.eps}\n\\end{figure}\n\nNow, we label the the Bitcoin Price attribute.\n\n\\subsection{Labelling the Price of Bitcoin}\nHere, we plot a histogram of all of our data points, so that we can visualize how the price of Bitcoin is distributed. We again notice a similar pattern that we have seen in the price of Ether, in that each attribute is skewed to the right. It is because of this that I have chosen to use a similar labelling scheme to the one that I used when labelling the \\texttt{eth\\_etherprice} attribute.\n\n\\begin{figure}[H]\n\\centering\n\\caption{Here is a basic histogram visualizing the distribution of the price of Bitcoin. It is noteworthy that our Bitcoin price is quite heavily skewed to the right.}\n\\includegraphics{final/btc_priceOnly.eps}\n\\end{figure}\n\nFrom this box plot, we choose the following labelling scheme, note that as in our first Global experiment, we choose a very small first block, and then split up the remaining parts into three separate parts, due to the our data being skewed to the right.\n\n\\begin{center}\n\\begin{tabular}{ |c|c|c| } \n\\hline\nBitcoin Price p & Label & Value\\\\\n\\hline\n$p < 1500$ & Low & 1\\\\ \n$1500 \\leq p < 7600$ & Medium & 2\\\\ \n$7600 \\leq p < 14100$ & High & 3\\\\ \n$ p \\geq 14100$ & Very High & 4\\\\ \n\\hline\n\\end{tabular}\n\\end{center}\n\nSo, we end up with the following histogram, please note that we have limited the y axis between 0 and 60, so that we can get a better view of all of the data, we already seen in the previous graph how the total Number of occurrences for the Very Low Bitcoin prices reached over 600. So it is not important for us to visualize this again. We have added the labels as the red lines that appear on the graph. For the purpose of this experiment, from the histogram we see that it makes sense to seperate the data into four classes.\n\n\\begin{figure}[H]\n\\centering\n\\caption{Here is a Histogram showing the Price of Bitcoin with a y axis limited between 0 and 60, we do this to get a better view of the data, in the previous figure we saw the right skew of our dataset, so we do this so we can essentially zoom in on our data. We also include the labels described by the red lines to visualize our labelling scheme.}\n\\includegraphics[scale=0.8]{final/btc_price_withLabel.eps}\n\\end{figure}\n\nWe have now labelled and preprocessed our data, so we are ready for the PCA.\n\n\\subsection{Principal Component Analysis}\nAs before, we perform the same steps by calculating the covariance matrix, and then the eigenvectors and eigenvalues, we then order the eigenvalues and their corresponding eigenvectors in descending order. We consider the eigenvector corresponding to the largest eigenvalue to be our first principal component. We end up with the following Scree Plot.\n\n\\begin{figure}[H]\n\\centering\n\\caption{A Scree Plot Showing the Variance described by each eigenvector, up to the 8th Principal Component. The blue line shows the cumulative percentage variance described by the data, whereas the orange bars describe the percentage of variance described by that particular component. Note, we only show the first 8 principal components, as thet are so small.}\n\\includegraphics[scale = 0.75]{final/scree_plot_btc.eps}\n\\end{figure}\n\nIt is not surprising for us to get a similar result again, as the majority of our dataset has been consistent throughout this project. Here are the exact cumulative percent of variance of our first four principal components, as described above.\n\n\\begin{center}\n\\begin{tabular}{ |c|c| } \n\\hline\nPrincipal Component & Cumulative Variance Present (\\%) \\\\\n\\hline\n1 & 66.53 \\\\ \n2 & 83.88 \\\\ \n3 & 91.54 \\\\ \n4 & 94.84 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\nWe see that the first two principal components describe 83.88\\% of the variance in our data. Thus, we can project our data into a new subspace represented by two dimensions while still maintaining a lot of the variance in our data, that we don't want to lose. We end up with the following 2D projection of our data into this new subspace.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale = 0.7]{local/legend_2D_proj_copy.pdf}\n\\end{figure}\n\\begin{figure}[H]\n\\centering\n\\caption{Here is a projection of our original dataset into the 2 dimensional subspace as described by the first two principal components. Please see the legend above which describes our labelling scheme which we have used to label the price of Bitcoin}\n\\includegraphics{final/btc_2d_projection.eps}\n\\end{figure}\n\nWe see some good clustering in this graph, in particular for the data points that are labelled as Very Low and High. \n\n\n\\begin{figure}[H]\n\\centering\n\\caption{Here is a 3D projection which is created from our first three principal components being concatenated into our 3x3 projection matrix. We then multiply this by our original data to view this projection on our labelling of Ether Price, these first 3 principal components allow us to capture 89.12\\% of the variance in our data, which is extremely high. We do not need this 3D projection, we have just included it to see if we are able to visualize better any clustering in our data.}\n\\includegraphics{final/btc_3d_projection.eps}\n\\end{figure}\n \n\n\\subsection{Comparison between First Global Experiment}\nIn this brief section, we will compare the projections of our datasets from the first and final PCA experiments into their own respective 2D subspaces. We note that in the first PCA experiment on Ether Price, we saw that it was appropriate to put Ether Price into 5 Labels. Thus, to make it a more appropriate comparison, we have redone the PCA with the following 4 Labels, which follows the same labelling criteria as the final PCA experiment did.\n\n\\begin{center}\n\\begin{tabular}{ |c|c|c| } \n\\hline\nEther Price p & Label & Value\\\\\n\\hline\n$p < 25$ & Low & 1\\\\ \n$25 \\leq p < 150$ & Medium & 2\\\\ \n$150 \\leq p < 275$ & High & 3\\\\ \n$ p \\geq 275$ & Very High & 4\\\\ \n\\hline\n\\end{tabular}\n\\end{center}\n\nHere, we visualize the two resulting 2D projections next to each other. Please note that the data points are  not exactly the same due to the inclusion of the Ether price into the attributes considered for our PCA during the final experiment. Thus we notice that the subspace that we project our points into will be different.\n\n\\begin{figure}[H]\n  \\centering\n  \\begin{minipage}[b]{0.4\\textwidth}\n    \\includegraphics[width=\\textwidth]{main/eth_2d_projection_4Labels.eps}\n    \\caption{A 2D Projection of Ether Price into the 2D subspace provided from the first PCA experiment, but with only 4 labels.}\n  \\end{minipage}\n  \\hfill\n  \\begin{minipage}[b]{0.4\\textwidth}\n    \\includegraphics[width=\\textwidth]{final/btc_2d_projection.eps}\n    \\caption{The 2D projection of our data into the new subspace as seen in the final PCA experiment above.}\n  \\end{minipage}\n\\end{figure}\n\nWe notice that the greatest similarities are between that of the Very Low/Low labels, and we can see some similarities between the two graphs. \n\n\\section{Conclusion}\nHaving performed these three seperate PCA experiments on our dataset, we have seen some very good clustering in our 2D projections. This is because the variation in this dataset that is captured from the 2 dimensions of our new subspace have all been extremely high. We saw that we often had greater clustering when we had a higher number of instances of our dataset, as we have seen slightly less clustering in the second PCA experiment on the Supply of Ether. Perhaps, by doing further PCA experiments we could take a deeper look into this.\n\n\\begin{thebibliography}{9}\n\\bibitem{dataset} \nSRK \nCryptocurrency Historical Prices,\n\\\\\\url{https://www.kaggle.com/sudalairajkumar/cryptocurrencypricehistory}\n\\\\Last Used: 24/02/2018\n \n\\bibitem{ethereum_info} \nUseful Information on Ethereum,\n\\\\\\url{https://blockgeeks.com/guides/ethereum}\n\\\\Last Used: 24/02/2018\n\n\\bibitem{pca_components}\nInterpretation of the Principal Components,\n\\\\\\url{https://onlinecourses.science.psu.edu/stat505/node/54/}\n\\\\Last Used: 24/02/2018\n\n\n\\end{thebibliography}\n\n\\end{document}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5\n\n% Useful links : \n\n% DATASETS :\n%     - https://www.kaggle.com/sudalairajkumar/cryptocurrencypricehistory\n\n% FOR INFO ON Ethereum :\n%     - blockgeeks.com/guides/ethereum\n\n% For info on analysing eigenvectors\n% https://onlinecourses.science.psu.edu/stat505/node/54\n", "meta": {"hexsha": "1c8597c6eff62143159b12b093f5edeb74e71ef8", "size": 36157, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/main.tex", "max_stars_repo_name": "talbotp/pca-ethereum", "max_stars_repo_head_hexsha": "9d706d35a2e5f43c408a003c74b5d2079c44537f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/main.tex", "max_issues_repo_name": "talbotp/pca-ethereum", "max_issues_repo_head_hexsha": "9d706d35a2e5f43c408a003c74b5d2079c44537f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/main.tex", "max_forks_repo_name": "talbotp/pca-ethereum", "max_forks_repo_head_hexsha": "9d706d35a2e5f43c408a003c74b5d2079c44537f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 78.431670282, "max_line_length": 1234, "alphanum_fraction": 0.7781895622, "num_tokens": 8640, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916064586998, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.735568903186571}}
{"text": "\n\\section{The \\partialsort algorithm}\n\\Label{sec:partialsort}\n\nOur version of the \\partialsort algorithm compared to the \\cxx Standard\nLibrary \\cite[\\S 28.7.1.3]{cxx-17-draft} has the signature\n\n\\begin{lstlisting}[style = acsl-block]\n\n  void partial_sort(value_type* a, size_type m, size_type n);\n\\end{lstlisting}\n\nThe algorithm \\emph{reorders} the given array \\inl{a} in such a way\nthat it represents a \\emph{partition}:\neach member of the\nleft part \\inl{a[0..m-1]} is less or equal to each member of the right\npart \\inl{a[m..n-1]}.\n%\nMoreover, the algorithm \\emph{sorts} the left part in increasing order.\nThe order of elements in the right part, however, is \\emph{unspecified}.\n%\nFigure~\\ref{fig:partialsort} uses a bar chart to\ndepict a typical result of a call \\inl{partial_sort(a, m, n)}.\n%\nIn the post-state, \nthe left and the right part is colored in green and orange,\nrespectively.\n\n\n\\begin{figure}[hbt]\n\\begin{center}\n\\includegraphics[width=0.75\\textwidth]{Figures/partial_sort.pdf}\n\\caption{\\Label{fig:partialsort} Effects of \\partialsort}\n\\end{center}\n\\end{figure}\n\n\\FloatBarrier\n\n\\subsection{The predicate \\Partition}\n\nWe start by introducing the new predicate \\logicref{Partition}\nwhich formalizes the partitioning property.\n\n\\input{Listings/Partition.acsl.tex}\n\n\\clearpage\n\nThe lemmas in the following listing are used in proofs of properties and annotations\nrelated to the loop invariants \\inl{upper}, \\inl{lower}, and \\inl{partition}\nof \\partialsort.\n\n\\input{Listings/PartitionLemmas.acsl.tex}\n\n\n\\begin{itemize}\n\\item\nLemma \\MultisetReorderSomeEqual states that a value\n\\inl{a[i]} taken from a range \\inl{a[0..n-1]} after some reordering\nmust have been in that range already before reordering.\nIt is used to prove the subsequent lemmas.\n\n\\item\nLemma \\MultisetReorderLowerBound\ninformally says that a lower bound \\inl{v} of a\nrange \\inl{a[0..n-1]} keeps its property even after the range is\nreordered.\n\n\\item\nDually, lemma \\MultisetReorderUpperBound says that reordering a range\ndoesn't affect any of its upper bounds.\n\n\\item\nLemma \\MultisetReorderPartitionLowerBound \ndescribes a more particular\nsituation: if each element in \\inl{a[0..m-1]}\nis known to be a less or equal than element \\inl{a[m..n-1]}\nand the former range is reordered while the latter is kept untouched,\nthen \\inl{a[0]} will still be a lower bound of \\inl{a[m..n-1]}.\nWe employ this lemma to infer that, after \\specref{pushheap} was called, the new\nheap maximum \\inl{a[0]}, is a lower bound of \\inl{a[m..i]},\n\n\\end{itemize}\n\nThe proof of \\logicref{MultisetReorderSomeEqual} relies on the lemma \\logicref{CountSomeEqual}.\nWe also rely on the lemma \\logicref{MultisetSwapMiddle}\nin order to verify that the loop invariant \\inl{reorder} is preserved.\n\n\\subsection{Formal specification of \\partialsort}\n\nThe formal specification of the \\partialsort function is shown in the following listing.\nIt uses the just introduced predicate \\Partition and reuses the\npreviously defined predicates \\logicref{Increasing} and \\logicref{MultisetReorder}.\n\n\\input{Listings/partial_sort.h.tex}\n\n\\subsection{Implementation of \\partialsort}\n\nOur implementation of \\partialsort is shown the next listing.\n%\nIt initially calls \\specref{makeheap} to rearrange the left part \\inl{a[0..m-1]} into a heap.\n%\nAfter that, it scans the right part, from left to right, for elements\nthat are too small;\neach such element is exchanged for the left part's maximum, by applying\n\\specref{popheap}  and \\specref{pushheap}  appropriately.\n%\nWhen the scan is done, the smallest elements are collected in the left\npart.\n%\nWe finally convert it from a heap into an increasingly ordered range,\nby \\sortheap (\\ref{sec:sortheap}).\n\n\\begin{figure}[hbt]\n\\begin{center}\n\\includegraphics[width=0.50\\textwidth]{Figures/partial_sort-loop.pdf}\n\\caption{\\Label{fig:partialsort-loop}An iteration of \\partialsort}\n\\end{center}\n\\end{figure}\n\n\\clearpage\n\nIn the scan loop, we maintain as invariants\n\\begin{itemize}\n\\item that the left part is a heap (invariant \\inl{heap});\n\\item that its maximal element, \\inl{a[0]}, is a ``separating element''\n  between the left part \\inl{a[0..m-1]} and the right part \\inl{a[m..i-1]},\n  i.e., an upper bound of the left (invariant \\inl{upper})\n  and a lower bound of the right part (invariant \\inl{lower}), respectively;\n\\item that \\inl{a[i..m-1]} is yet unchanged (invariant \\inl{unchanged}); and\n\\item that only permutation operations have been applied to\n  \\inl{a[0..i-1]} (invariant \\inl{reorder}).\n\\end{itemize}\n\nIn order to preserve the loop invariants after \\inl{i} is incremented,\nnothing has to be done if \\inl{a[0]} happens to be\nalso a lower bound for \\inl{a[i]}.\nOtherwise, let us follow the algorithm through the \\inl{then} part code,\ndepicting the intermediate states in \nFigure~\\ref{fig:partialsort-loop}.\nThe elements considered so far are shown colored similar to\nFigure~\\ref{fig:partialsort}; in particular the heap part is shown in green.\n\n%\\clearpage\n\n%\nThe overlaid transparent red shape indicates the ranges to which\n\\Partition applies, in each state.\n%\nThe figure assumes the initial contents of \\inl{a[0]} and\n\\inl{a[i]} to be $9$ and $5$,\nfor sake of generality, let us\ncall them $p$ and $q$, respectively.\n\nAfter \\popheap and \\swap,\nwe have $p$ at \\inl{a[i]}, and $q$ at \\inl{a[m-1]}.\n%\nAt that point we know\n%\n\\begin{enumerate}\n\\item $q < p \\leq \\mbox{\\inl{a[k]}}$ for each $m \\leq k < i$,\n  since $p$ was a lower bound for \\inl{a[m..i-1]};\n\\item $q < p = \\mbox{\\inl{a[i]}}$;\n\\item $\\mbox{\\inl{a[j]}} \\leq p \\leq \\mbox{\\inl{a[k]}}$ \n  for each $0 \\leq j < m-1$ and each $m \\leq k < i$,\n  since this held on loop entry, and we didn't more than\n  reordering inside the parts; and\n\\item $\\mbox{\\inl{a[j]}} \\leq p = \\mbox{\\inl{a[i]}}$ \n  since $p$ was the heap maximum on loop entry.\n\\end{enumerate}\n\n\\begin{listing}[t]\n\\begin{minipage}{\\textwidth}\n\\lstinputlisting[linerange={1-38}, style=acsl-block, frame=single]{Source/partial_sort.c}\n\\end{minipage}\n\\caption{\\Label{lst:partialsort-impl1}Implementation of \\partialsort (1)}\n\\end{listing}\n\n\\index[examples]{partial\\_sort@\\texttt{partial\\_sort}}\n\n\n\\FloatBarrier\n\nAltogether, we have  $\\mbox{\\inl{a[j]}} \\leq p \\leq \\mbox{\\inl{a[k]}}$\nfor each $0 \\leq j < m$ and each $m \\leq k < i+1$.\n%\nThat is, \\inl{Partition(a,m,i+1)} holds, although we cannot name a\nseparating element of \\inl{a} here.\n\n\nAfter calling \\pushheap, which just performs some more \nreorderings of the left part, this property is preserved. \nWe can't and we needn't tell which position $q$ is moved to;\nthe former is indicated in Figure~\\ref{fig:partialsort}\nby the vague grey triangle.\n%\nMoreover, we now know again that \\inl{a[0]} has become an upper bound\nof the left part,\nand hence a separating element between\n\\inl{a[0..m-1]} and \\inl{a[m..i]};\nthat is, the loop invariants \\inl{upper} and \\inl{lower} have been\nre-established.\n%\nThese two invariants together are eventually used to prove\nthe property \\inl{partition} of the contract.\n\nCompared to its size, the algorithm makes a\nlot of procedure calls; in this respect it is closer to real-life\nsoftware than most other algorithms of this tutorial.\n%\nTherefore, we use it to illustrate a methodical point:\n%\nFor almost every procedure call, we give the callee's contract,\ntailored to its actual parameters, as a statement contract of the call.\n%\nFor example, everything we know from the \\popheap contract,\ninstantiated to the particular situation, is documented in the\nfirst statement contract.\n%\nIn contrast, we use \\inl{assert} clauses to indicate intermediate\nreasoning to obtain subsequently needed properties.\n\n\\begin{listing}[t]\n\\begin{minipage}{\\textwidth}\n\\lstinputlisting[linerange={39-99}, style=acsl-block, frame=single]{Source/partial_sort.c}\n\\end{minipage}\n\\caption{\\Label{lst:partialsort-impl2}The Implementation of\n\\partialsort (2)}\n\\end{listing}\n\n\\index[examples]{partial\\_sort@\\texttt{partial\\_sort}}\n\n\\FloatBarrier\n\n\nOur implementation has a worst-case time complexity of\n${\\cal O}((n+m) \\cdot \\log m)$.\n%\nOn the other hand, an implementation that ignores \\inl{m} and just sorts \\inl{a[0..n-1]}\nalso satisfies the contract of \\specref{partialsort},\nand may have ${\\cal O}(n \\cdot \\log n)$ complexity.\n%\nSome arithmetic shows that \\partialsort performs better than\nplain sort if, and only if,\n$\\log m < \\dfrac{n}{m} \\cdot \\log\\left(\\dfrac{n}{m}\\right)$,\nthat is, if $n$ is sufficiently larger than $m$.\n\n\n\n\\clearpage\n\n", "meta": {"hexsha": "551d899ab28f40ea0c835e110ade888e275b65a9", "size": 8397, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/sorting/partial_sort.tex", "max_stars_repo_name": "fraunhoferfokus/acsl-by-example", "max_stars_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2017-06-14T04:17:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T06:07:36.000Z", "max_issues_repo_path": "Informal/sorting/partial_sort.tex", "max_issues_repo_name": "fraunhoferfokus/acsl-by-example", "max_issues_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-10-18T13:30:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T07:10:16.000Z", "max_forks_repo_path": "Informal/sorting/partial_sort.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 33.4541832669, "max_line_length": 95, "alphanum_fraction": 0.7450279862, "num_tokens": 2507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8519528019683105, "lm_q1q2_score": 0.735568889334361}}
{"text": "\\section{Methods for pattern selection}\n\n\\subsection{Based on Conditional Mutual Information}\n\nWhen studying methylation we are faced with two main questions:\n  \\begin{enumerate}\n  \\item Which genes exhibit an L-shape, and \n  \\item what is the optimal threshold for binarizing\nmethylation data for each L-shape gene.\n  \\end{enumerate}\nTo determine whether methylation and expression of a gene exhibit an L-shape,\ncompute the conditional Mutual Information (MI) for different choices of threshold\nto binarize the methylation data.\n\n\nIf we consider the continuous valued methylation and expression data as two random variables\n$X$ and $Y$, and denote a nominal threshold as $t$, the conditional MI can be written as a\nweighted sum of MIs on the two sides of the threshold.\n\\[\n\\mathit{cMI}(t)=I(X,Y|X>t)P(X>t) + I(X,Y|X\\le t)P(X\\le t)\n\\]\n\n%When $t$ is $0$ or $1$, $\\mathit{cMI}$ equals to the mutual information derived \n%from all data points.\n\nFor an L-shape gene, as $t$ moves from 0 to 1, $\\mathit{cMI}(t)$ first decreases and then\nincreases, and its value approaches zero when $t$ coincides with the reflection point. \n  \nThe ratio $r=\\frac{\\min\\{\\mathit{cMI}(t)\\}}{\\mathit{cMI}(0)}$ for an L-shape gene is small, \nand $t^{\\ast} = \\mathrm{argmin}\\{ \\mathit{cMI}(t) \\}$ is the \\textbf{optimal threshold} for \ndichotomizing the methylation data of this gene.\n\n\nTo estimate the MI terms we use a kernel-based estimator, which \nconstructs a joint probability distribution by applying a Gaussian kernel to each data point:\n\\[\nI(X,Y) = \\frac 1M \\sum_{i=1}^M \\log\\frac{M\\sum_{j=1}^M e^{-\\frac{1}{2h^2}((x_i-x_j)^2+(y_i-y_j)^2)}}{%\n                                      \\sum_{j=1}^M e^{-\\frac{1}{2h^2}(x_i-x_j)^2} \\sum_{j=1}^M e^{-\\frac{1}{2h^2}(y_i-y_j)^2}}\n\\]\nwhere $h$ is a tuning parameter for the kernel width and empirically set $h=0.3$.\n  \n\n% i and j are indices for samples.\n% In our analysis, we normalize the expression data to zero mean.\n\n\\subsection{Based on Spline regression}\n\n\n%We implemented regression based on  $B$-splines because they are particularly efficient due to the block-diagonal basis matrices that result.\n\nLet \n\n $\\varsigma=\\lbrace t_1 < \\cdots < t_N \\rbrace$ non decreasing  knot sequence \n $\\left[ t_m,t_{m+1} \\right)$ half open interval\n $B_{mp}$ $p$-th order polynomial (degree $p-1$) with finite support over the interval and 0 everywhere else so that  $\\sum_{m=1}^{N-p}B_{mp}(x)=1$\n then  $s(x)=\\sum_{m=1}^{N-p}B_{mp}(x)c_m$ \n\n\nTo represent the curve we set $y_{ij}=s(x_{ij})$, so $\\mathbf{y}_i=\\mathbf{B}_i\\mathbf{c}$\nwith\n\\begin{description}\n\\item $\\mathbf{B}_i =\\left[ B_{1p}\\mathbf{x}_i,B_{2p}\\mathbf{x}_i,\\dots,B_{Lp}\\mathbf{x}_i \\right]$ the spline basis matrix \n\\item $\\mathbf{c}$ the vector of spline coefficients\n\\end{description}\n\n\\textbf{Algorithm}\n\\begin {enumerate}\n\\item Selection of the genes with a negative significant correlation\n\\item Fit cubic regression splines\n\\item Data to cluster: splines coefficients\n\\item Calculation of a distance matrix between genes as $1-\\rho$\n\\item Hierarchical clustering \n\\end{enumerate}\n", "meta": {"hexsha": "30b50411b7654d0b2058e4e18ed23dccebe16ef4", "size": 3068, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Treballs_nostres/2019-07-UseR-A Shiny_App_for_SGRM/2019-07-UseR-Poster/sectionsUseR/methods.tex", "max_stars_repo_name": "bertamiro/Selecting_GRM", "max_stars_repo_head_hexsha": "f7d91df489cb5bd6b6fd6447be9c7a1002705158", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Treballs_nostres/2019-07-UseR-A Shiny_App_for_SGRM/2019-07-UseR-Poster/sectionsUseR/methods.tex", "max_issues_repo_name": "bertamiro/Selecting_GRM", "max_issues_repo_head_hexsha": "f7d91df489cb5bd6b6fd6447be9c7a1002705158", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Treballs_nostres/2019-07-UseR-A Shiny_App_for_SGRM/2019-07-UseR-Poster/sectionsUseR/methods.tex", "max_forks_repo_name": "bertamiro/Selecting_GRM", "max_forks_repo_head_hexsha": "f7d91df489cb5bd6b6fd6447be9c7a1002705158", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.4594594595, "max_line_length": 147, "alphanum_fraction": 0.714797914, "num_tokens": 934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7355554597001945}}
{"text": "\\section{Parallel VGLCS Algorithm}\n\n\\subsection{Dynamic Programming}\n\\begin{frame}\n    \\frametitle{Basic Dynamic Programming}\n\tGiven two strings $A$, $B$, and two gap values $G_{A}$, $G_{B}$\n\t\\begin{align*}\n        C(A, S)[i] - C(A, S)[i-1] \\le G_{A}(c_i) \\\\\n        C(B, S)[i] - C(B, S)[i-1] \\le G_{B}(c_i)\n    \\end{align*}\t\n\n    Recursive formula as follows:\n\n    \\begin{align*}\n    \tV[i][j] = \\left\\{\\begin{matrix}\n \t\t\t(\\max\\limits_{\n \t\t\t\t\\substack{i-G_A(i)-1 \\le x \\le i-1 \\\\ \n \t\t\t\t\t\t  j-G_B(j)-1 \\le y \\le j-1}} \n \t\t\t\tV[x][y])+1\n \t\t\t\t& \\text{, if } A[i] = B[j] \\\\\n \t\t\t\t0 & \\text{, otherwise}\\\\\n\t\t\t\\end{matrix}\\right.\n    \\end{align*}\n\\end{frame}\n\n\\begin{frame}\n    \\frametitle{Illustration for Basic Dynamic Programming}\n\t\\begin{figure}[!thb]\n\t\t\\includegraphics[width=0.5\\linewidth]{\\GraphicPath/fig-VGLCS-dp-naive.pdf}\n\t\t\\caption{How to compute $V$.}\n\t\t\\label{fig:basic-dp-VGLCS}\n\t\\end{figure}\n\\end{frame}\n\n\\subsection{Peng's Algorithm}\n\\begin{frame}\n    \\frametitle{Peng's Algorithm}\n   \tComputation of all $V[i][j]$'s with the same $i$ has the {\\em same}\n\tgap constraint $G_A(i)$, so the maximum within the rectangle can be\n\tcomputed in two steps.\n\n    \\begin{enumerate}\n    \t\\setlength\\itemsep{1em}\n    \t\\item \n    \t\tFirst, we compute the maximum of {\\em every column} of this\n\t\t\trectangle, and place them into another array $R$.\n\t\t\\item \n\t\t\tSecond, we compute the maximum of the {\\em suffix} of length\n\t\t\t$G_B(j)$ on $R$, which is exactly $V[i][j]$.\n    \\end{enumerate}\n\\end{frame}\n\n\\begin{frame}\n    \\frametitle{Illustration for Peng's Algorithm}\n    \\begin{figure}[!thb]\n\t\t\\includegraphics[width=0.5\\linewidth]{\\GraphicPath/fig-VGLCS-dp.pdf}\n\t\t\\caption{Compute $V$ with incremental suffix maximum queries.}\n\t\\end{figure}\n\\end{frame}\n\n\\begin{withoutheadline}\n\\begin{frame}\n\t\\frametitle{Pseudocode for Peng's Algorithm}\n\t\\begin{center}\n\t\t\\scalebox{.7} { \\begin{minipage}{1.2\\textwidth}\n\t\t\t\\input{\\AlgoPath/alg-serial-VGLCS-2e}\n\t\t\t\\end{minipage}\n\t\t}\n\t\\end{center}\n\\end{frame}\n\\end{withoutheadline}\n\n\\subsection{Incremental Suffix Maximum Query}\n\\begin{frame}\n    \\frametitle{Incremental Suffix Maximum Query}\n\n    We need to address the {\\em incremental suffix maximum query} (ISMQ)\n    problem to solve VGLCS problem efficiently.\n    \\\\~\\\\\n    It supports the three operations as follows:\n    \\begin{description}[align=right]\n    \t\\setlength\\itemsep{1em}\n    \t\\item[{\\sc Make}]\n\t\t\tcreates an empty array $A$.\n\t\t\\item[{\\sc Append}$(V)$]\n\t\t\tappends a value $V$ to array $A$. \n\t\t\\item[{\\sc Query}$(x)$]\n\t\t\tfinds the {\\em maximum} value among those from $x$ to the\n\t\t\tend of an array $A$.\n    \\end{description}\n\\end{frame}\n\n\\begin{frame}\n    \\frametitle{Incremental Suffix Maximum Query with Disjoint Set}\n\n    Peng uses a {\\em disjoint-set} data structure to answer incremental\n\tsuffix maximum queries in his VGLCS algorithm.\n\n\t\\begin{itemize}\n\t\t\\setlength\\itemsep{1em}\n\t\t\\item \n\t\t\tThe set of data are stored in a sequence of disjoint sets,\n\t\t\tand the {\\em maximum} of each disjoint set is at the root of\n\t\t\tthe tree, and these maximum are in {\\em decreasing} order.\n\t\t\\item\n\t\t\tThe amortized time per union/find operation is\n\t\t\t$O(\\alpha(n))$.\n\t\t\\item\n\t\t\tUnion/find operation of {\\em incremental tree set union}\n\t\t\truns in amortized time $O(1)$ by constructing the answer\n\t\t\ttable.\n\t\\end{itemize}\n\\end{frame}\n\n\\begin{withoutheadline}\n\\begin{frame}\n\t\\frametitle{Illustration for ISMQ with Disjoint Set}\n\t\\begin{figure}[!thb]\n\t\t\\centering \\subfigure[Before] {\n\t\t\t\\includegraphics[width=0.45\\linewidth]{\\GraphicPath/fig-ISMQ-DS.pdf}\n\t\t} \\subfigure[After] {\n\t\t\t\\includegraphics[width=0.45\\linewidth]{\\GraphicPath/fig-ISMQ-DS-after.pdf}\n\t\t}\n\t\t\\caption{Answer ISMQ with disjoint set. $A$ is the input array,\n\t\t\t$W$ is the maximum weight array of each group, and the $I$\n\t\t\tis the index of the maximum weight array of each group. }\n\t\\end{figure}\n\\end{frame}\n\\end{withoutheadline}\n\n\\subsection{Parallel VGLCS Algorithm}\n\\begin{frame}\n    \\frametitle{Parallel VGLCS Algorithm}\n\tWavefront method is easy to parallel VGLCS algorithm, but row-by-row\n\tapproach provides\n\n    \\begin{itemize}\n    \t\\setlength\\itemsep{1em}\n\t\t\\item \n\t\t\tLess space\n\t\t\\item \n\t\t\tSmaller the length of the critical path\n    \\end{itemize}\n\\end{frame}\n\n\\begin{withoutheadline}\n\\begin{frame}\n\t\\frametitle{Wavefront Method for Parallel VGLCS Algorithm}\n\t\\begin{figure}[!thb]\n\t  \\centering \\subfigure[The first stage]{\n\t    \\includegraphics[width=0.45\\linewidth]{\\GraphicPath/fig-VGLCS-dp-wavefront-second.pdf}\n\t  } \\subfigure[The second stage]{\n\t    \\includegraphics[width=0.45\\linewidth]{\\GraphicPath/fig-VGLCS-dp-wavefront-first.pdf}\n\t  }\n\t  \\caption{The book keeping data of the wavefront method}\n\t  \\label{fig:fig-VGLCS-dp-wavefront}\n\t\\end{figure}\n\\end{frame}\n\\end{withoutheadline}\n\n\\begin{frame}\n\t\\frametitle{The Advantage of Our Algorithm}\n\tOur optimized row-by-row approach\n\t\\begin{itemize}\n\t\t\\setlength\\itemsep{1em}\n\t\t\\item \n\t\t\tLess space\n\t\t\\item \n\t\t\tSmaller the length of the critical path\n\t\t\\item \n\t\t\tMore balanced workload\n\t\t\\item \n\t\t\tSmaller thread synchronization overhead\n\t\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\t\\frametitle{A Sketch of Our Algorithm}\n\tOur algorithm computes $V$ one row at a time.  The computation of\n\teach row has two stages.\n\t\\begin{center}\n\t\t\\scalebox{.7} { \\begin{minipage}{1.2\\textwidth}\n\t\t\t\\begin{figure}\n\t\t\t  \\centering \\subfigure[The first stage]{\n\t\t\t    \\includegraphics[width=0.4\\linewidth]{\\GraphicPath/fig-VGLCS-dp-rmq-first.pdf}\n\t\t\t  } \\subfigure[The second stage]{\n\t\t\t    \\includegraphics[width=0.4\\linewidth]{\\GraphicPath/fig-VGLCS-dp-rmq-second.pdf}\n\t\t\t  }\n\t\t\t  \\caption{Two stages of the computation of one row of $V$.}\n\t\t\t  \\label{fig:fig-VGLCS-dp-rmq}\n\t\t\t\\end{figure}\n\t\t\t\\end{minipage}\n\t\t}\n\t\\end{center}\n\\end{frame}\n\n\\subsection{Data Structure of Parallel VGLCS Algorithm}\n\\subsubsection{Disjoint Set}\n\\begin{frame}\n    \\frametitle{Disjoint Set}\n    It is {\\em not} feasible to parallelize the disjoint set\n\timplementation for three reasons when a large number of threads work\n\ttogether.\n\n\t\\begin{itemize}\n\t\t\\setlength\\itemsep{1em}\n\t\t\\item\n\t\t\t{\\sc Query} will change the data structure because it will\n\t\t\t{\\em compress} the path to the root and lead {\\em\n\t\t\tinconsistent} view of the data structure.\n\t\t\\item \n\t\t\tThe load of compressing different paths among threads could\n\t\t\tbe very different, and this will incur {\\em load imbalance}.\n\t\t\\item \n\t\t\tDifferent parts of the disjoint set will lead to synchronize\n\t\t\tthem {\\em inefficiently}.\n\t\\end{itemize}\n\\end{frame}\n\n\\subsubsection{Sparse Table}\n\\begin{frame}\n    \\frametitle{Sparse Table}\n\tWe use {\\em sparse table} to support incremental suffix/range\n\tmaximum queries in our VGLCS algorithm.\n\n\t\\begin{itemize}\n\t\t\\setlength\\itemsep{1em}\n\t\t\\item \n\t\t\t$O(n \\log n)$ preprocessing, and \n\t\t\\item \n\t\t\t$O(1)$ time to answer queries on one dimensional data.\n\t\\end{itemize}\n\\end{frame}\n\n\\begin{withoutheadline}\n\\begin{frame}\n\t\\frametitle{An Example for Sparse Table}\n\t\\begin{figure}[!thb]\n\t  \\centering \\subfigure[Array]{\n\t    \\includegraphics[width=0.8\\linewidth]{\\GraphicPath/fig-interval-decomposition-origin.pdf}\n\t    \\label{fig:fig-interval-decomposition}\n\t  } \\subfigure[Sparse table]{\n\t    \\includegraphics[width=0.8\\linewidth]{\\GraphicPath/fig-sparse-table-origin.pdf}\n\t    \\label{fig:fig-sparse-table}\n\t  }\n\t  \\caption{A sparse table example}\n\t  \\label{fig:interval-decomposition}\n\t\\end{figure}\n\\end{frame}\n\\end{withoutheadline}\n\n\\begin{withoutheadline}\n\\begin{frame}\n\t\\frametitle{Parallel Sparse Table Building Algorithm}\n\tAlgorithm~\\ref{alg:parallel-sparse-table} runs in $O(n \\log n / p\n\t+ \\log n)$ time, where $p$ is the number of processors.\n\t\\\\~\\\\\n\t\\input{\\AlgoPath/alg-parallel-sparse-table-2e}\n\\end{frame}\n\\end{withoutheadline}\n\n\n\\subsection{Parallel VGLCS Algorithm with Sparse Table}\n\\begin{withoutheadline}\n\\begin{frame}\n\t\\frametitle{Parallel VGLCS Algorithm with Sparse Table}\n\tAlgorithm~\\ref{alg:parallel-VGLCS} runs in $O(n m (\\log n + \\log m)\n\t/ p + n \\log m)$ time, where $p$ is the number of processors.\n\t\\\\~\\\\\n\t\\begin{center}\n\t\t\\scalebox{.7} { \\begin{minipage}{1.4\\textwidth}\n\t\t\t\\input{\\AlgoPath/alg-parallel-VGLCS-2e}\n\t\t\t\\end{minipage}\n\t\t}\n\t\\end{center}\n\\end{frame}\n\\end{withoutheadline}", "meta": {"hexsha": "d21c8b67cb15363efacab6b60a18b41dc13c4b65", "size": 8174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/IEEE/slides/partial/parallel-VGLCS.tex", "max_stars_repo_name": "morris821028/parallel-VGLCS", "max_stars_repo_head_hexsha": "87fe1c71e14cf7ed6092f728b085b735cf683a4b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-02-11T08:45:21.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-22T07:30:24.000Z", "max_issues_repo_path": "doc/IEEE/slides/partial/parallel-VGLCS.tex", "max_issues_repo_name": "morris821028/parallel-VGLCS", "max_issues_repo_head_hexsha": "87fe1c71e14cf7ed6092f728b085b735cf683a4b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T02:01:16.000Z", "max_issues_repo_issues_event_max_datetime": "2017-02-24T00:13:34.000Z", "max_forks_repo_path": "doc/IEEE/slides/partial/parallel-VGLCS.tex", "max_forks_repo_name": "morris821028/parallel-VGLCS", "max_forks_repo_head_hexsha": "87fe1c71e14cf7ed6092f728b085b735cf683a4b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5090252708, "max_line_length": 94, "alphanum_fraction": 0.6974553462, "num_tokens": 2654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.7905303112671295, "lm_q1q2_score": 0.7355554512879925}}
{"text": "\\section{Geometric interpretation of linear transformations}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find the matrix of rotations, reflections, scalings, and\n    shearings in $\\R^2$ and $\\R^3$.\n  \\end{enumerate}\n\\end{outcome}\n\nIn this section, we will examine some special examples of linear\ntransformations in $\\R^2$ and $\\R^3$ including rotations and\nreflections.\n\n\\begin{example}{Rotation by $90^{\\circ}$ in $\\R^2$}{rotation-90-R2}\n  Consider the linear transformation $T:\\R^2\\to\\R^2$ that is given by\n  a counterclockwise rotation by 90 degrees. Find the matrix%\n  \\index{matrix!of a rotation}%\n  \\index{rotation!matrix of}%\n  \\index{linear transformation!rotation} $A$ corresponding to this\n  linear transformation. Find a formula for $T$.\n\\end{example}\n\n\\begin{solution}\n  To visualize a vector function on $\\R^2$, it is often useful to\n  consider a pair of before-and-after pictures such as the following:\n  \\begin{center}\n    \\begin{tikzpicture}\n      \\begin{scope}[scale=0.5]\n        \\draw[red,thick,fill=red!15]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n        \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n        \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n        \\draw[red,thick]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[blue,thick,->] (0,0) -- node[below] {$\\vect{e}_1$} (5,0);\n        \\draw[blue,thick,->] (0,0) -- node[left] {$\\vect{e}_2$} (0,5);\n        \\path (0,-7.2) node {``before''};\n      \\end{scope}\n      \\begin{scope}[xshift=4.5cm]\n        \\path (0,0) node {$\\stackrel{T}{\\longmapsto}$};\n      \\end{scope}\n      \\begin{scope}[xshift=9cm,scale=0.5]\n        \\draw[red,thick,fill=red!15,rotate=90]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n        \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n        \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n        \\draw[red,thick,rotate=90]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[blue,thick,->,rotate=90] (0,0) -- node[right]\n        {$T(\\vect{e}_1) = \\begin{mysmallmatrix}{c}0\\\\1\\end{mysmallmatrix}$}\n        (5,0);\n        \\draw[blue,thick,->,rotate=90] (0,0) --\n        node[below,xshift=-0.1cm] {$T(\\vect{e}_2) = \\begin{mysmallmatrix}{c}-1\\\\0\\end{mysmallmatrix}$}\n        (0,5);\n        \\path (0,-7) node {``after''};\n      \\end{scope}\n    \\end{tikzpicture}\n  \\end{center}\n  The picture illustrates how the function $T$ rotates the entire\n  plane (including the pink letter ``F'') by 90 degrees\n  counterclockwise. The picture also illustrates that when we apply\n  the rotation $T$ to the first and second standard basis vectors\n  $\\vect{e}_1$ and $\\vect{e}_2$, we obtain the vectors\n  \\begin{equation*}\n    T(\\vect{e}_1) = \\begin{mymatrix}{c}0\\\\1\\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    T(\\vect{e}_2) = \\begin{mymatrix}{c}-1\\\\0\\end{mymatrix}.\n  \\end{equation*}\n  The matrix of $T$ has these vectors as its columns. Therefore, the\n  matrix of $T$ is\n  \\begin{equation*}\n    A = \\begin{mymatrix}{cc}\n      0 & -1 \\\\\n      1 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Finally, we can use this to find a formula for the counterclockwise\n  90 degree rotation $T$:\n  \\begin{equation*}\n    T\\paren{\\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}}\n    = \\begin{mymatrix}{cc}\n      0 & -1 \\\\\n      1 & 0 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}\n    = \\begin{mymatrix}{c} -y \\\\ x \\end{mymatrix}.\n  \\end{equation*}\n  To illustrate how this works, consider the top right corner of the\n  letter ``F''. It has the coordinates $(0.6,1)$. Applying the\n  function $T$ to the coordinate vector, we get\n  \\begin{equation*}\n    T\\paren{\\begin{mymatrix}{c} 0.6 \\\\ 1 \\end{mymatrix}}\n    = \\begin{mymatrix}{cc}\n      0 & -1 \\\\\n      1 & 0 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} 0.6 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{c} -1 \\\\ 0.6 \\end{mymatrix}.\n  \\end{equation*}\n  These are precisely the coordinates of the corresponding point on\n  the letter ``F'' after the rotation.\n\\end{solution}\n\n\\begin{example}{Reflection about the $y$-axis in $\\R^2$}{reflection-y-R2}\n  Let $T:\\R^2\\to\\R^2$ be a reflection about the $y$-axis. Find the\n  matrix%\n  \\index{matrix!of a reflection}%\n  \\index{reflection!matrix of}%\n  \\index{linear transformation!reflection} $A$ corresponding to this\n  linear transformation, and a formula for $T$.\n\\end{example}\n\n\\begin{solution}\n  The before-and-after picture for a reflection about the $y$-axis\n  looks like this:\n  \\begin{center}\n    \\begin{tikzpicture}\n      \\begin{scope}[scale=0.5]\n        \\draw[red,thick,fill=red!15]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n        \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n        \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n        \\draw[red,thick]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[blue,thick,->] (0,0) -- node[below] {$\\vect{e}_1$} (5,0);\n        \\draw[blue,thick,->] (0,0) -- node[left] {$\\vect{e}_2$} (0,5);\n      \\end{scope}\n      \\begin{scope}[xshift=4.5cm]\n        \\path (0,0) node {$\\stackrel{T}{\\longmapsto}$};\n      \\end{scope}\n      \\begin{scope}[xshift=9cm,scale=0.5]\n        \\draw[red,thick,fill=red!15,xscale=-1]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n        \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n        \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n        \\draw[red,thick,xscale=-1]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[blue,thick,->,xscale=-1] (0,0) -- node[below]\n        {$T(\\vect{e}_1) = \\begin{mysmallmatrix}{c}-1\\\\0\\end{mysmallmatrix}$}\n        (5,0);\n        \\draw[blue,thick,->,xscale=-1] (0,0) --\n        node[right] {$T(\\vect{e}_2) = \\begin{mysmallmatrix}{c}0\\\\1\\end{mysmallmatrix}$}\n        (0,5);\n      \\end{scope}\n    \\end{tikzpicture}\n  \\end{center}\n  We see that\n  \\begin{equation*}\n    T(\\vect{e}_1) = -\\vect{e}_1 = \\begin{mymatrix}{c}-1\\\\0\\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    T(\\vect{e}_2) = \\vect{e}_2 = \\begin{mymatrix}{c}0\\\\1\\end{mymatrix}.\n  \\end{equation*}\n  Therefore, the matrix of $T$ is\n  \\begin{equation*}\n    A = \\begin{mymatrix}{cc}\n      -1 & 0 \\\\\n      0  & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The formula for a reflection about the $y$-axis is:\n  \\begin{equation*}\n    T\\paren{\\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}}\n    = \\begin{mymatrix}{cc}\n      -1 & 0 \\\\\n      0  & 1 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}\n    = \\begin{mymatrix}{c} -x \\\\ y \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Rotation by an arbitrary angle in $\\R^2$}{rotation-theta-R2}\n  Find the matrix%\n  \\index{matrix!of a rotation}%\n  \\index{rotation!matrix of}%\n  \\index{linear transformation!rotation} $A$ for a counterclockwise rotation by\n  angle $\\theta$ in $\\R^2$.\n\\end{example}\n\n\\begin{solution}\n  The before-and-after picture is as follows:\n  \\begin{center}\n    \\begin{tikzpicture}\n      \\begin{scope}[scale=0.5]\n        \\draw[red,thick,fill=red!15]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n        \\draw[red,thick]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n        \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n        \\draw[blue,thick,->] (0,0) -- node[below] {$\\vect{e}_1$} (5,0);\n        \\draw[blue,thick,->] (0,0) -- node[left] {$\\vect{e}_2$} (0,5);\n      \\end{scope}\n      \\begin{scope}[xshift=4.5cm]\n        \\path (0,0) node {$\\stackrel{T}{\\longmapsto}$};\n      \\end{scope}\n      \\begin{scope}[xshift=9cm,scale=0.5]\n        \\draw[red,thick,fill=red!15,rotate=30]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n        \\filldraw[fill=green!20,draw=green!50!black] (0,0) -- (0:20mm) arc (0:30:20mm) -- cycle;\n        \\node at (15:14mm){$\\theta$};\n        \\draw[red,thick,rotate=30]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n        \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n        \\draw[blue,thick,->,rotate=30] (0,0) -- (5,0) node[right]\n        {$T(\\vect{e}_1) = \\begin{mysmallmatrix}{c}\\cos\\theta\\\\\\sin\\theta\\end{mysmallmatrix}$};\n        \\draw[blue,thick,->,rotate=30] (0,0) -- (0,5)\n        node[left,xshift=-0.1cm] {$T(\\vect{e}_2) = \\begin{mysmallmatrix}{c}-\\sin\\theta\\\\\\cos\\theta\\end{mysmallmatrix}$};\n      \\end{scope}\n    \\end{tikzpicture}\n  \\end{center}\n  Thus the matrix of $T$ is\n  \\begin{equation*}\n    A = \\begin{mymatrix}{cc}\n      \\cos\\theta & -\\sin\\theta \\\\\n      \\sin\\theta & \\cos\\theta \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{More linear transformations of the plane}{more-linear-transformations}\n  Describe the linear transformation that is given by each of the\n  following matrices. Draw a before-and-after picture for each.\n  \\begin{equation*}\n    (a)\\quad\n    A = \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      1 & 0 \\\\\n    \\end{mymatrix},\\quad\n    (b)\\quad\n    B = \\begin{mymatrix}{rr}\n      2 & 0 \\\\\n      0 & 2 \\\\\n    \\end{mymatrix},\\quad\n    (c)\\quad\n    C = \\begin{mymatrix}{rr}\n      \\frac{1}{2} & 0 \\\\\n      0 & 2 \\\\\n    \\end{mymatrix},\\quad\n    (d)\\quad\n    D = \\begin{mymatrix}{rr}\n      1 & 1 \\\\\n      0 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  To draw each before-and-after picture, we can start by drawing the\n  images of the two standard basis vectors $\\vect{e}_1$ and\n  $\\vect{e}_2$, which are the columns of the transformation matrix. We\n  have also drawn the image of the letter ``F'', to better illustrate\n  the effect of each transformation.\n  \\begin{center}\n    \\begin{tikzpicture}[scale=0.96]\n      \\begin{scope}\n        \\path (-2.25,1.5) node {(a)};\n        \\begin{scope}[scale=0.25]\n          \\draw[red,thick,fill=red!15]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n          \\draw[red,thick]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n          \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n          \\draw[blue,thick,->] (0,0) -- node[below] {$\\vect{e}_1$} (5,0);\n          \\draw[blue,thick,->] (0,0) -- node[left] {$\\vect{e}_2$} (0,5);\n        \\end{scope}\n        \\begin{scope}[xshift=2.25cm]\n          \\path (0,0) node {$\\stackrel{A}{\\longmapsto}$};\n        \\end{scope}\n        \\begin{scope}[xshift=4.5cm,scale=0.25]\n          \\draw[red,thick,fill=red!15,cm={0,1,1,0,(0,0)}]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n          \\draw[red,thick,cm={0,1,1,0,(0,0)}]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n          \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n          \\draw[blue,thick,->,cm={0,1,1,0,(0,0)}] (0,0) --\n          node[left] {$T(\\vect{e}_1)$} (5,0);\n          \\draw[blue,thick,->,cm={0,1,1,0,(0,0)}] (0,0) --\n          node[below] {$T(\\vect{e}_2)$} (0,5);\n        \\end{scope}\n      \\end{scope}\n      \\begin{scope}[xshift=9cm]\n        \\path (-2.25,1.5) node {(b)};\n        \\begin{scope}[scale=0.25]\n          \\draw[red,thick,fill=red!15]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n          \\draw[red,thick]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n          \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n          \\draw[blue,thick,->] (0,0) -- node[below] {$\\vect{e}_1$} (5,0);\n          \\draw[blue,thick,->] (0,0) -- node[left] {$\\vect{e}_2$} (0,5);\n        \\end{scope}\n        \\begin{scope}[xshift=2.25cm]\n          \\path (0,0) node {$\\stackrel{B}{\\longmapsto}$};\n        \\end{scope}\n        \\begin{scope}[xshift=4.5cm,scale=0.25]\n          \\draw[red,thick,fill=red!15,cm={2,0,0,2,(0,0)}]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n          \\draw[red,thick,cm={2,0,0,2,(0,0)}]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[semithick] (-6.5,0) -- (6.5,0);\n          \\draw[semithick] (0,-6.5) -- (0,6.5);\n          \\draw[blue,thick,->,cm={2,0,0,2,(0,0)}] (0,0) --\n          node[below] {$T(\\vect{e}_1)$} (5,0);\n          \\draw[blue,thick,->,cm={2,0,0,2,(0,0)}] (0,0) --\n          node[left] {$T(\\vect{e}_2)$} (0,5);\n        \\end{scope}\n      \\end{scope}\n      \\begin{scope}[yshift=-3.75cm]\n        \\path (-2.25,1.5) node {(c)};\n        \\begin{scope}[scale=0.25]\n          \\draw[red,thick,fill=red!15]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n          \\draw[red,thick]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n          \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n          \\draw[blue,thick,->] (0,0) -- node[below] {$\\vect{e}_1$} (5,0);\n          \\draw[blue,thick,->] (0,0) -- node[left] {$\\vect{e}_2$} (0,5);\n        \\end{scope}\n        \\begin{scope}[xshift=2.25cm]\n          \\path (0,0) node {$\\stackrel{C}{\\longmapsto}$};\n        \\end{scope}\n        \\begin{scope}[xshift=4.5cm,scale=0.25]\n          \\draw[red,thick,fill=red!15,cm={0.5,0,0,2,(0,0)}]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n          \\draw[red,thick,cm={0.5,0,0,2,(0,0)}]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n          \\draw[semithick] (0,-6.5) -- (0,6.5);\n          \\draw[blue,thick,->,cm={0.5,0,0,2,(0,0)}] (0,0) --\n          node[below,xshift=0.5cm] {$T(\\vect{e}_1)$} (5,0);\n          \\draw[blue,thick,->,cm={0.5,0,0,2,(0,0)}] (0,0) --\n          node[left] {$T(\\vect{e}_2)$} (0,5);\n        \\end{scope}\n      \\end{scope}\n      \\begin{scope}[xshift=9cm,yshift=-3.75cm]\n        \\path (-2.25,1.5) node {(d)};\n        \\begin{scope}[scale=0.25]\n          \\draw[red,thick,fill=red!15]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n          \\draw[red,thick]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n          \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n          \\draw[blue,thick,->] (0,0) -- node[below] {$\\vect{e}_1$} (5,0);\n          \\draw[blue,thick,->] (0,0) -- node[left] {$\\vect{e}_2$} (0,5);\n        \\end{scope}\n        \\begin{scope}[xshift=2.25cm]\n          \\path (0,0) node {$\\stackrel{D}{\\longmapsto}$};\n        \\end{scope}\n        \\begin{scope}[xshift=4.5cm,scale=0.25]\n          \\draw[red,thick,fill=red!15,cm={1,0,1,1,(0,0)}]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n          \\draw[red,thick,cm={1,0,1,1,(0,0)}]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n          \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n          \\draw[blue,thick,->,cm={1,0,1,1,(0,0)}] (0,0) --\n          node[below] {$T(\\vect{e}_1)$} (5,0);\n          \\draw[blue,thick,->,cm={1,0,1,1,(0,0)}] (0,0) --\n          node[above,yshift=0.5cm] {$T(\\vect{e}_2)$} (0,5);\n        \\end{scope}\n      \\end{scope}\n    \\end{tikzpicture}\n  \\end{center}\n  The transformation $A$ is a reflection%\n  \\index{matrix!of a reflection}%\n  \\index{reflection!matrix of}%\n  \\index{linear transformation!reflection} about the line $x=y$. The\n  transformation $B$ is a scaling%\n  \\index{matrix!of a scaling}%\n  \\index{scaling!matrix of}%\n  \\index{linear transformation!scaling} by a factor of $2$. The\n  transformation $C$ is also a scaling, but by a different factor in\n  the $x$- and $y$-directions. It scales the $x$-direction by a factor\n  of $\\frac{1}{2}$ (or equivalently, shrinks it by a factor of $2$),\n  and scales the $y$-direction by a factor of $2$. The transformation\n  $D$ is called a \\textbf{shearing}%\n  \\index{matrix!of a shearing}%\n  \\index{shearing!matrix of}%\n  \\index{linear transformation!shearing}. It keeps one line (the\n  $x$-axis) fixed, while shifting all other points by varying\n  distances along lines that are parallel to the $x$-axis.\n\\end{solution}\n\n\\begin{example}{Rotation in $\\R^3$}{rotation-R3}\n  Find the matrix of a rotation%\n  \\index{matrix!of a rotation}%\n  \\index{rotation!matrix of}%\n  \\index{linear transformation!rotation} by angle $\\theta$ about the\n  $z$-axis in $3$-dimensional space, counterclockwise when viewed from\n  above.\n\\end{example}\n\n\\begin{solution}\n  Here is the before-and-after picture. A rotation in $3$-dimensional\n  space is usually harder to visualize than in the plane, but\n  fortunately, the rotation is about the $z$-axis, so all the\n  ``action'' is taking place in the $xy$-plane.\n  \\begin{center}\n    \\begin{tikzpicture}[scale=0.9]\n      \\begin{scope}[scale=0.5]\n        \\begin{scope}[cm={-0.4,-0.5,1,0,(0,0)}]\n          \\draw[red,thick,fill=red!15]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[gray!50, very thin] (0,0) circle [radius=5cm];\n          \\draw[red,thick]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n          \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n          \\draw[blue,thick,->] (0,0) -- node[left] {$\\vect{e}_1$} (5,0);\n          \\draw[blue,thick,->] (0,0) -- node[above] {$\\vect{e}_2$} (0,5);\n        \\end{scope}\n        \\draw[semithick,->] (0,0) -- (0,6.5);\n        \\draw[blue,thick,->] (0,0) -- node[left] {$\\vect{e}_3$} (0,5);\n      \\end{scope}\n      \\begin{scope}[xshift=4.5cm]\n        \\path (0,0) node {$\\stackrel{T}{\\longmapsto}$};\n      \\end{scope}\n      \\begin{scope}[xshift=9cm,scale=0.5]\n        \\begin{scope}[cm={-0.4,-0.5,1,0,(0,0)}]\n          \\draw[red,thick,fill=red!15,rotate=30]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\filldraw[fill=green!20,draw=green!50!black] (0,0) -- (0:30mm) arc (0:30:30mm) -- cycle;\n          \\node at (15:20mm){$\\theta$};\n          \\draw[gray!50, very thin] (0,0) circle [radius=5cm];\n          \\draw[red,thick,rotate=30]\n          (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n          (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n          \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n          \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n          \\draw[blue,thick,->,rotate=30] (0,0) -- (5,0) node[below,xshift=1cm]\n          {$T(\\vect{e}_1) = \\begin{mysmallmatrix}{c}\\cos\\theta\\\\\\sin\\theta\\\\0\\end{mysmallmatrix}$};\n          \\draw[blue,thick,->,rotate=30] (0,0) -- (0,5)\n          node[above,xshift=1cm] {$T(\\vect{e}_2) = \\begin{mysmallmatrix}{c}-\\sin\\theta\\\\\\cos\\theta\\\\0\\end{mysmallmatrix}$};\n        \\end{scope}\n        \\draw[semithick,->] (0,0) -- (0,6.5);\n        \\draw[blue,thick,->] (0,0) -- node[left] {$T(\\vect{e}_3)=\\begin{mysmallmatrix}{c}0\\\\0\\\\1\\end{mysmallmatrix}$} (0,5);\n      \\end{scope}\n    \\end{tikzpicture}\n  \\end{center}\n  Therefore, the matrix of the rotation is\n  \\begin{equation*}\n    A = \\begin{mymatrix}{ccc}\n      \\cos\\theta & -\\sin\\theta & 0 \\\\\n      \\sin\\theta & \\cos\\theta & 0 \\\\\n      0 & 0 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n", "meta": {"hexsha": "f47da339954800c46e80db030558dce6f4c14d57", "size": 21397, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/LinearTransformationsRn-Geometric.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/LinearTransformationsRn-Geometric.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/LinearTransformationsRn-Geometric.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 42.6235059761, "max_line_length": 124, "alphanum_fraction": 0.4963779969, "num_tokens": 9058, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.8757869932689566, "lm_q1q2_score": 0.7354280796682312}}
{"text": "\\chapter{Hoare Logic}\nIn this chapter we introduce \\href{http://en.wikipedia.org/wiki/Hoare_logic}{\\emph{Hoare logic}}.\nThis is a formal system that is used to prove the correctness of imperative computer programs.  \nHoare logic has been introduced 1969 by  \n\\href{http://en.wikipedia.org/wiki/C._A._R._Hoare}{Sir Charles Antony Richard Hoare}, \nwho is the inventor of the \\href{http://en.wikipedia.org/wiki/Quicksort}{quicksort} algorithm.\n \n\n\\section{Preconditions and Postconditions}\nHoare logic is based on preconditions and postconditions.  If \\texttt{P}\n is a program fragment and if $F$ and $G$ are logical formul\\ae, then we call\n$F$ a precondition and $G$ a postcondition for the program fragment \\texttt{P}\nif the following holds:  If \\texttt{P} is executed in a state $s$ such that the formula $F$ holds in\n$s$, then the execution of \\texttt{P} will change the state $s$ into a new state $s'$ such that \n$G$ holds in $s'$.  This is written as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\hoare{F}{P}{G} $.\n\\\\[0.2cm]\nWe will read this notation as ``\\emph{executing $P$ changes $F$ into $G$}''.\nThe formula\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\hoare{F}{P}{G} $\n\\\\[0.2cm]\nis called a \\emph{Hoare triple}.\n\\vspace*{0.3cm}\n\n\n\\examplesEng\n\\begin{enumerate}\n\\item The assignment ``\\texttt{x := 1;}'' satisfies the specification\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $ \\hoare{\\mathtt{true}}{x := 1;}{x = 1}. $\n      \\\\[0.2cm]\n      Here, the precondition is the trivial condition ``\\texttt{true}'', since\n      the postcondition ``$x = 1$'' will always be satisfied after this assignment.\n\\item The assignment  ``\\texttt{x = x + 1;}'' satisfies the specification\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $ \\hoare{x=1}{x := x + 1;}{x=2}. $\n      \\\\[0.2cm]\n      If the precondition is ``$x = 1$'', then it is obvious that the postcondition has to be  \n      ``$x = 2$''.\n\\item Let us consider the assignment ``\\texttt{x = x + 1;}'' again.  However, this time\n      the precondition is given as ``$\\textsl{prime}(x)$'', which is only true if $x$ is a\n      prime number.  This time, the Hoare triple is given as\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $ \\hoare{\\textsl{prime}(x)}{x := x + 1;}{\\textsl{prime}(x-1)}$.\n      \\\\[0.2cm]\n      This might look strange at first.  Many students think that this Hoare triple should rather\n      be written as\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $ \\hoare{\\textsl{prime}(x)}{x := x + 1;}{\\textsl{prime}(x+1)} $.\n      \\\\[0.2cm]\n      However, this can easily be refuted by taking $x$ to have the value $2$.  Then, the\n      precondition $\\textsl{prime}(x)$ is satisfied since $2$ is a prime number.  After the\n      assignment, $x$ has the value $3$ and\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $x - 1 = 3 - 1 = 2$\n      \\\\[0.2cm]\n      still is a prime number.  However, we also have\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $x + 1 = 3 + 1 = 4$ \n      \\\\[0.2cm]\n      and as $4 = 2 \\cdot 2$ we see that $x + 1$ is not a prime number!\n\\end{enumerate}\nLet us proceed to show how the different parts of a program can be specified using Hoare triples.\nWe start with the analysis of assignments.\n \n\\subsection{Assignments}\nLet us generalize the previous example.  Let us therefore assume that we have an assignment of the\nform \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\texttt{x := h(x);} $\n\\\\[0.2cm]\nand we want to investigate how the postcondition $G$ of this assignment is related to the\nprecondition $F$.  To simplify matters, let us assume that the function\n$h$ is invertible, i.~e.~we assume that there is a function $h^{-1}$ such that we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ h^{-1}\\bigl(h(x)\\bigr) = x \\quad \\mathtt{and} \\quad h\\bigl(h^{-1}(x)\\bigr) = x $\n\\\\[0.2cm]\nfor all $x$.  Then, the function $h^{-1}$ is the inverse of the function $h$.\nIn order to understand the problem of computing the postcondition for the assignment statement given\nabove, let us first consider an example.  The assignment\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\texttt{x := x + 1;} $\n\\\\[0.2cm]\ncan be written as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\texttt{x := h(x);} $\n\\\\[0.2cm]\nwhere the function $h$ is given as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ h(x) = x + 1 $\n\\\\[0.2cm]\nand the inverse function $h^{-1}$ is \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$h^{-1}(x) = x - 1$. \n\\\\[0.2cm]\nNow we are able to compute the postcondition of the assignment ``\\texttt{x := h(x);}'' from the\nprecondition.  We have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\hoare{F}{x := h(x);}{F\\sigma}$ \\quad where \\quad \n$\\sigma = \\bigl[x \\mapsto h^{-1}(x)\\bigr]$.\n\\\\[0.2cm]\nHere, $F\\sigma$ denotes the application of the substitution $\\sigma$ to the formula $F$.  The\nexpression  $F\\sigma$ is computed from the expression $F$ by replacing every occurrence of the variable\n$x$ by the term $h^{-1}(x)$.  Therefore, the substitution $\\sigma$ undoes the effect of the\nassignment and restores the variables in $F$ to the state before the assignment.\n\nIn order to understand why this is the correct way to compute the \npostcondition, we consider the assignment\n``\\texttt{x := x + 1}'' again and choose the formula $x = 7$ as precondition.  \nSince $h^{-1}(x) = x - 1$, the substitution $\\sigma$ is given as\n$\\sigma = [ x \\mapsto x - 1 ]$.  Therefore, $F\\sigma$ has the form\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ (x = 7)[x \\mapsto x - 1] \\;\\equiv\\; (x - 1 = 7). $\n\\\\[0.2cm]\nI have used the symbol ``$\\equiv$'' here in order to express that these formul\\ae\\ are\nsyntactically identical.  \nTherefore, we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\hoare{x = 7}{x := x + 1;}{x - 1 = 7}. $\n\\\\[0.2cm]\nSince the formula $x - 1 = 7$ is equivalent to the formula $x = 8$ the Hoare triple above can be\nrewritten as  \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\hoare{x = 7}{x := x + 1;}{x = 8} $\n\\\\[0.2cm]\nand this is obviously correct:  If the value of $x$ is $7$ before the assignment\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n``\\texttt{x := x + 1;}'' \n\\\\[0.2cm]\nis executed, then after the assignment is executed, $x$ will have the value $8$.\n\nLet us try to understand why\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\hoare{F}{x := h(x);}{F\\sigma}$ \\quad where \\quad \n$\\sigma = \\bigl[x \\mapsto h^{-1}(x)\\bigr] $\n\\\\[0.2cm]\nis, indeed, correct:   Before the assignment ``x \\texttt{:=} h(x);'' is executed,\nthe variable $x$ has some fixed value $x_0$.  The precondition $F$ is valid for $x_0$.  Therefore,\nthe formula $F[x \\mapsto x_0]$ is valid before the assignment is executed.  However,\nthe variable $x$ does not occur in the formula $F[x \\mapsto x_0]$ because it has been replaced by\nthe fixed value $x_0$.  Therefore, the formula\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ F[x \\mapsto x_0] $\n\\\\[0.2cm]\nremains valid after the assignment  ``\\texttt{x = h(x);}'' is executed.  After this assignment,\nthe variable $x$ is set to $h(x_0)$. Therefore, we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$x = h(x_0)$.\n\\\\[0.2cm]  \nLet us solve this equation for $x_0$.  We find\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$h^{-1}(x) = x_0$.\n\\\\[0.2cm]\nTherefore, after the assignment the formula \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ F[x \\mapsto x_0] \\equiv  F[x \\mapsto h^{-1}(x)]$ \n\\\\[0.2cm]\nis valid and  this is the formula that is written as $F\\sigma$ above.\n\nWe conclude this discussion with another example.  The unary predicate \\textsl{prime} checks whether\nits argument is a prime number.  Therefore, $\\textsl{prime}(x)$ is true if $x$ is a prime number.\nThen we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\hoare{\\textsl{prime}(x)}{x := x + 1;}{\\textsl{prime}(x-1)}$.\n\\\\[0.2cm]\nThe correctness of this Hoare triple should be obvious: If $x$ is a prime and if $x$ is then\nincremented by $1$, then afterwards $x-1$ is prime.\n\n\\paragraph{Different Forms of Assignments}\nNot all assignments can be written in the form ``\\texttt{x := h(x);}'' where the function $h$ is invertible.\nOften, a constant $c$ is assigned to some variable $x$.  If $x$ does not occur in the precondition\n$F$, then we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\hoare{F}{x := c;}{F \\wedge x = c}. $\n\\\\[0.2cm]\nThe formula $F$ can be used to restrict the values of other variables occurring in the program under\nconsideration.\n\n\n\\paragraph{General Form of the Assignment Rule}\nIn the literature the rule for specifying an assignment is given as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\hoare{F[x \\mapsto t]}{x := t;}{F}. $\n\\\\[0.2cm]\nHere, $t$ is an arbitrary term that can contain the variable $x$.  This rule can be read as follows:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\begin{minipage}[c]{0.8\\linewidth}\n``\\emph{If the formula $F(t)$ is valid in some state and $t$ is assigned to $x$,\n        then after this assignment we have $F(x)$.}'' \n\\end{minipage}\n\\\\[0.2cm]\nThis rule is obviously correct.  However, it is not very useful because in order to apply this rule \nwe first have to rewrite the precondition as $F(t)$.  If $t$ is some complex term, this is often\nvery difficult to do.\n\n\n\\subsection{The Weakening Rule}\nIf a program fragment $P$ satisfies the specification\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\hoare{F}{P}{G} $\n\\\\[0.2cm]\nand if, furthermore, the formula $G$ implies the validity of the formula $H$, that is if\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$G \\rightarrow H$\n\\\\[0.2cm]\nholds, then the program fragment $P$ satisfies\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\hoare{F}{P}{H}$.\n\\\\[0.2cm]\nThe reasoning is as follows:  If after executing $P$ we know that $G$\nis valid, then, since $G$ implies $H$,  the formula $H$ has to be\nvalid, too.\nTherefore, the  following \\emph{verification rule}, which is known as the \\emph{weakening rule}, is valid:\n\\\\[0.4cm]\n$\\bruch{\\quad \\hoare{F}{P}{G}, \\qquad G \\rightarrow H \\quad}{\\hoare{F}{P}{H}}$ \n\\\\[0.2cm]\nThe formul\\ae\\ written over the fraction line are called the \\emph{premisses} and the formula under the\nfraction line is called the \\emph{conclusion}.   The conclusion and the first premiss  are \nHoare triples, the second premiss is a formula of first order logic.\nThe interpretation of this rule is that the conclusion is true if the premisses are true.\n\n\n\\subsection{Compound Statements}\nIf the program fragments $\\texttt{P}$ and $\\texttt{Q}$ have the specifications\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\hoare{F_1}{P}{G_1}$  \\quad and \\quad $\\hoare{F_2}{Q}{G_2}$\n\\\\[0.2cm]\nand if, furthermore, the postcondition $G_1$ implies the precondition $F_2$,\nthen the composition $\\texttt{P;Q}$ of $\\texttt{P}$ and $\\texttt{Q}$ satisfies the specification\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\hoare{F_1}{P;Q}{G_2}$.\n\\\\[0.2cm]\nThe reasoning is as follows:  If, initially, $F_1$ is satisfied and we execute $P$ then we have\n$G_1$ afterwards.  Therefore we also have $F_2$ and if we now execute $Q$ then afterwards we will have\n$G_2$.  This chain of thoughts is combined in the following verification rule:\n\\\\[0.4cm]\n\\hspace*{1.3cm}\n$\\bruch{\\quad\\hoare{F_1}{P}{G_1}, \\qquad G_1 \\rightarrow F_2, \\qquad \\hoare{F_2}{Q}{G_2}\\quad}{\\hoare{F_1}{P;Q}{G_2}} \n$\n\\\\[0.2cm] \nIf the formul\\ae\\ $G_1$ and $F_2$ are identical, then this rule can be simplified as follows:\n\\\\[0.4cm]\n\\hspace*{1.3cm}\n$\\bruch{\\quad\\hoare{F_1}{P}{G_1}, \\qquad \\hoare{G_1}{Q}{G_2}\\quad}{ \\hoare{F_1}{P;Q}{G_2}}$\n\n\n\\exampleEng\nLet us analyse the program fragment shown in Figure \\ref{fig:swap}.  \nWe start our analysis by using the precondition\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\texttt{x} = a \\wedge \\texttt{y} = b. $\n\\\\[0.2cm]\nHere, $a$ and $b$ are two variables that we use to store the initial values of \\texttt{x} and\n\\texttt{y}.  The first assignment yields the Hoare triple\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\hoare{\\texttt{x} = a \\wedge \\texttt{y} = b}{x := x - y;}{(\\texttt{x} = a \\wedge \\texttt{y} =  b)\\sigma}$\n\\\\[0.2cm] \nwhere $\\sigma = [x \\mapsto x + y]$. The form of $\\sigma$ follows from the fact that the function $x \\mapsto x + y$ is the inverse of the\nfunction $x \\mapsto x - y$.  If we apply $\\sigma$ to the formula $x = a \\wedge y = b$\nwe get\n\\begin{equation}\n  \\label{eq:swap1}\n \\hoare{\\texttt{x} = a \\wedge \\texttt{y} = b}{x := x - y;}{\\texttt{x + y} = a \\wedge \\texttt{y} = b}.   \n\\end{equation}\nThe second assignment yields the Hoare triple\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\hoare{\\texttt{x + y} = a \\wedge \\texttt{y} = b}{y := y + x;}{(\\texttt{x + y} = a \\wedge  \\texttt{y} = b)\\sigma}$\n\\\\[0.2cm] \nwhere $\\sigma = [y \\mapsto y - x]$.  The reason is that the function $y \\mapsto y - x$ is the inverse of the function $y \\mapsto y + x$.\nThis time, we get\n\\[ \\hoare{\\texttt{x + y} = a \\wedge \\texttt{y} = b}{y := y + x;}{\n          \\texttt{x + y - x} = a \\wedge \\texttt{y - x} = b}.\n\\]\nSimplifying the postcondition yields\n\\begin{equation}\n  \\label{eq:swap2}\n \\hoare{\\texttt{x + y} = a \\wedge \\texttt{y} = b}{y := y + x;}{ \\texttt{y} = a \\wedge \\texttt{y - x} = b}.\n\\end{equation}\nLet us consider the last assignment.  We have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\hoare{\\texttt{y} = a \\wedge \\texttt{y - x} = b}{x := y - x;}{ (\\texttt{y} = a \\wedge \\texttt{y - x} = b)\\sigma}$ \n\\\\[0.2cm] \nwhere $\\sigma = [x \\mapsto y - x]$,\nsince the function $x \\mapsto y - x$ is the inverse of the function $x \\mapsto y - x$.\nThis yields\n\\[ \\hoare{\\texttt{y} = a \\wedge \\texttt{y - x} = b}{x := y - x;}{\n          \\texttt{y} = a \\wedge \\texttt{y - (y - x)} = b} \n\\]\nSimplifying the postcondition gives\n\\begin{equation}\n  \\label{eq:swap3}\n  \\hoare{\\texttt{y} = a \\wedge \\texttt{y - x} = b}{x := y - x;}{ \\texttt{y} = a \\wedge \\texttt{x} = b}.   \n\\end{equation}\nCombining the Hoare triples (\\ref{eq:swap1}), (\\ref{eq:swap2}) and (\\ref{eq:swap3})\nwe get\n\\begin{equation}\n  \\label{eq:swap}\n  \\hoare{\\texttt{x} = a \\wedge \\texttt{y} = b}{x:=x-y; y:=y+x; x:=y-x;}{ \n         \\texttt{y} = a \\wedge \\texttt{x} = b}.   \n\\end{equation}\nThe Hoare triple (\\ref{eq:swap}) shows that the program fragment shown in Figure\n\\ref{fig:swap} swaps the values of the variables $x$ and $y$: If the value of \n$x$ is $a$ and $y$ has the value $b$ before the program is executed, then afterwards\n$y$ has the value $a$ and $x$ has the value $b$.  The trick shown in Figure\n\\ref{fig:swap} \ncan be used to swap variables without using an auxiliary variable.  This is useful because when this\ncode is compiled into machine language, the resulting code will only use two registers.\n\n\n\\begin{figure}[!ht]\n\\centering\n\\begin{Verbatim}[ frame         = lines, \n                  framesep      = 0.3cm, \n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 0.8cm,\n                  xrightmargin  = 0.8cm,\n                ]\n    x := x - y;\n    y := y + x;\n    x := y - x;\n\\end{Verbatim}\n\\vspace*{-0.3cm}\n\\caption{A tricky way to swap variables.}\n\\label{fig:swap}\n\\end{figure}\n\n\n\n\\subsection{Conditional Statements}\nIn order to compute the effect of a conditional of the form\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{if ($B$) \\{ P \\} else \\{  Q \\}}\n\\\\[0.2cm]\nlet us assume that before the conditional statement is executed, the\nprecondition $F$ is satisfied.   We have to analyse the effect of the program fragments $P$ and $Q$.\nThe program fragment $P$ is only executed when $B$ is true.  Therefore, the precondition for $P$ is \n$F \\wedge B$.  On the other hand, the precondition for the program fragment $Q$ is $F \\wedge \\neg B$,\nsince $Q$ is only executed if $B$ is false.\nHence, we have the following verification rule:\n\\begin{equation}\n  \\label{eq:hoareIf}\n  \\bruch{\\quad\\hoare{F \\wedge B}{P}{G}, \\qquad \\hoare{F \\wedge \\neg B}{Q}{G}\\quad}{\n              \\hoare{F}{if ($B$) P else Q}{G}}  \n\\end{equation}\nIn this form, the rule is not always applicable.  The reason is that the analysis of the program\nfragments \\texttt{P} and \\texttt{Q} yields Hoare triple of the form\n\\begin{equation}\n  \\label{eq:hoareI}\n \\hoare{F \\wedge B}{P}{G_1} \\qquad \\mathrm{and} \\qquad \\hoare{F \\wedge \\neg B}{Q}{G_2},   \n\\end{equation}\nand in general $G_1$ and $G_2$ will be different from each other.  In order to be able to apply the\nrule for conditionals we have to find a formula $G$ that is a consequence of $G_1$ and also a\nconsequence of $G_2$, i.~e.~we want to have\n\\[ G_1 \\rightarrow G \\qquad \\mathrm{and} \\qquad G_2 \\rightarrow G. \\]\nIf we find $G$, then the weakening rule  can be applied to conclude the validity of\n\\[ \\hoare{F \\wedge B}{P}{G} \\qquad \\mathrm{and} \\qquad \\hoare{F \\wedge \\neg B}{Q}{G},    \\] \nand this gives us the premisses that are needed for the rule\n(\\ref{eq:hoareIf}).\n\\pagebreak\n\n\\exampleEng\nLet us analyze the following program fragment:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{if (x < y) \\{ z := x; \\} else \\{ z := y; \\}}\n\\\\[0.2cm]\nWe start with the precondition\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$F = \\bigl(\\texttt{x} = a \\wedge \\texttt{y} = b\\bigr)$\n\\\\[0.2cm]\nand want to show that the execution of the conditional establishes the postcondition\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$G = \\bigl(z = \\textsl{min}(a, b)\\bigr)$.\n\\\\[0.2cm]\nThe first assignment ``\\texttt{z := x;}'' gives the Hoare triple \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\hoare{\\texttt{x} = a \\wedge \\texttt{y} = b \\wedge \\texttt{x} < \\texttt{y}}{z := x}{\n          \\texttt{x} = a \\wedge \\texttt{y} = b \\wedge \\texttt{x} < \\texttt{y} \\wedge \\texttt{z} = \\texttt{x}}\n$.\n\\\\[0.2cm]\nIn the same way, the second assignment ``\\texttt{z := y}'' yields\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\hoare{\\texttt{x} = a \\wedge \\texttt{y} = b \\wedge \\texttt{x} \\geq \\texttt{y}}{z := y}{\n          \\texttt{x} = a \\wedge \\texttt{y} = b \\wedge \\texttt{x} \\geq \\texttt{y} \\wedge\n          \\texttt{z} = \\texttt{y}}$.\n\\\\[0.2cm]\nSince we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\texttt{x} = a \\wedge \\texttt{y} = b \\wedge \\texttt{x} < \\texttt{y} \\wedge \\texttt{z} = \\texttt{x}\n   \\rightarrow \\texttt{z} = \\min(a,b)$\n\\\\[0.2cm]\nand also\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\texttt{x} = a \\wedge \\texttt{y} = b \\wedge \\texttt{x} \\geq \\texttt{y} \\wedge \\texttt{z} = \\texttt{y} \n   \\rightarrow \\texttt{z} = \\min(a,b)\n$.\n\\\\[0.2cm]\nUsing the weakening rule we conclude that \n\\begin{eqnarray*}\n\\hoare{\\texttt{x} = a \\wedge \\texttt{y} = b \\wedge \\texttt{x} < \\texttt{y}}{z := x;}{\n       \\texttt{z} = \\min(a,b)} & & \\mathrm{and} \\\\\n\\hoare{\\texttt{x} = a \\wedge \\texttt{y} = b \\wedge \\texttt{x} \\geq \\texttt{y}}{z := y;}{\n          \\texttt{z} = \\min(a,b)}\n\\end{eqnarray*}\nholds.  Now we can apply the rule for the conditional and conclude\nthat \n\\\\[0.2cm]\n$ \\hoare{\\texttt{x} = a \\wedge \\texttt{y} = b}{if (x < y) \\{ z := x; \\} else \\{ z := y; \\}}{ \\texttt{z} = \\min(a,b)} $\n\\\\[0.2cm]\nholds.  Thus we have shown that the program fragment above computes\nthe minimum of the numbers $a$ and $b$.\n\n\\subsection{Loops}\nFinally, let us analyze the effect of a loop of the form\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{while ($B$) \\{ P \\}} \n\\\\[0.2cm]\nThe important point here is that the postcondition of the $n$-th\nexecution of the body of the loop $P$ is the precondition of the $(n\\!+\\!1)$-th\nexecution of $P$.  Basically this means that the precondition and the\npostcondition of $P$ have to be more or less the same.\nHence, this condition is called the \\emph{loop invariant}.  Therefore,\nthe details of the verification rule for \\texttt{while} loops are as follows:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\bruch{\\hoare{I \\wedge B}{P}{I}}{\\quad \\hoare{I}{while ($B$) \\{ P \\}}{I \\wedge \\neg B}\\quad}$\n\\\\[0.2cm]\nThe premiss of this rule expresses the fact that the invariant $I$ remains valid on execution of $P$.\nHowever, since $P$ is only executed as long as $B$ is \\texttt{true}, the precondition for $P$ is actually \nthe formula $I \\wedge B$.  The conclusion of the rule says that if the invariant $I$ is true before\nthe loop is executed, then $I$ will be true after the loop has finished.  This result is intuitive\nsince every time $P$ is executed $I$ remains valid.  Furthermore, the loop only terminates once $B$\ngets \\texttt{false}.  Therefore, the postcondition of the loop can be strengthened by adding $\\neg B$.\n\n\n\n\\section{The Euclidean  Algorithm}\nIn this section we show how the verification rules of the last section can be used to prove the\ncorrectness of a non-trivial program.\nWe will show that the algorithm shown in Figure \\ref{fig:gcd.stlx} on page \\pageref{fig:gcd.stlx} is correct.\nThe procedure shown in this figure implements the\n\\href{http://en.wikipedia.org/wiki/Euclidean_algorithm}{\\emph{Euclidean algorithm}}\nto compute the greatest common divisor of two natural numbers.  Our proof is based on the following\nproperty of the function \\texttt{gcd}:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\texttt{gcd}(x + y, y) = \\texttt{gcd}(x,y) \\quad \\mbox{for all $x, y \\in \\mathbb{N}$}$.\n\n\n\\begin{figure}[!ht]\n\\centering\n\\begin{Verbatim}[ frame         = lines, \n                  framesep      = 0.3cm, \n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 0.8cm,\n                  xrightmargin  = 0.8cm,\n                ]\n    gcd := procedure(x, y) {\n        while (x != y) {\n            if (x < y) {\n                y := y - x;\n            } else {\n                x := x - y;\n            }\n        }\n        return x;\n    };\n\\end{Verbatim}\n\\vspace*{-0.3cm}\n\\caption{The Euclidean Algorithm to compute the greatest common divisor.}\n\\label{fig:gcd.stlx}\n\\end{figure}\n\n\\subsection{Correctness Proof of the Euclidean Algorithm} \nTo start our correctness proof we formulate the invariant of the \\texttt{while} loop.\nLet us define\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ I := \\bigl(x > 0 \\wedge y > 0 \\wedge \\texttt{gcd}(x,y) = \\texttt{gcd}(a,b) \\bigr)$\n\\\\[0.2cm]\nIn this formula we have defined the initial values of $x$ and $y$ as $a$ and $b$.\nIn order to establish the invariant at the beginning we have to ensure that the function\n\\texttt{gcd} is only called with positive natural numbers.  If we denote these numbers as \n$a$ and $b$, then the invariant $I$ is valid initially.  The reason is that $x = a$ and $y = b$\nimplies $\\texttt{gcd}(x,y) = \\texttt{gcd}(a,b)$.\n\n\nIn order to prove that the invariant $I$ is maintained in the loop we formulate the Hoare triples\nfor both alternatives of the conditional.  For the first conditional we know that\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\hoare{I \\wedge x \\not= y \\wedge x < y}{y := y - x;}{(I \\wedge x \\not= y \\wedge x < y)\\sigma}$\n\\\\[0.2cm]\nholds, where $\\sigma$ is defined as $\\sigma = [y \\mapsto y + x]$.  Here, the condition $x \\not= y$\nis the condition controlling the execution of the  \n\\texttt{while} loop and the condition $x < y$ is the condition of the \\texttt{if} conditional.\nWe rewrite the formula $(I \\wedge x \\not= y \\wedge x < y)\\sigma$:\n\\begin{eqnarray*}\n &                 & \\bigl(I \\wedge x \\not= y \\wedge x < y\\bigr)\\sigma \\\\\n & \\leftrightarrow & \\bigl(I \\wedge x < y\\bigr)\\sigma \n                     \\qquad\\qquad \\mbox{because $x < y$ implies $x \\not= y$} \\\\\n & \\leftrightarrow & \\bigl(x > 0 \\wedge y > 0 \\wedge \\texttt{gcd}(x,y) = \\texttt{gcd}(a,b) \\wedge \n                     x < y\\bigr)[y \\mapsto y + x] \\\\\n & \\leftrightarrow & x > 0 \\wedge y + x > 0 \\wedge \\texttt{gcd}(x,y+x) = \\texttt{gcd}(a,b)\n                     \\wedge x < y + x \\\\\n & \\leftrightarrow & x > 0 \\wedge y + x > 0 \\wedge \\texttt{gcd}(x,y) = \\texttt{gcd}(a,b) \\wedge 0 < y\n\\end{eqnarray*}\nIn the last step we have used the formula\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ \\texttt{gcd}(x,y+x) = \\texttt{gcd}(x,y) $\n\\\\[0.2cm]\nand we have simplified the inequality $x < y + x$ as $0 < y$.\nThe last formula implies\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ x > 0 \\wedge y > 0 \\wedge \\texttt{gcd}(x,y) = \\texttt{gcd}(a,b) $.\n\\\\[0.2cm]\nHowever, this is precisely the invariant $I$.  Therefore we have shown that\n\\begin{equation}\n  \\label{eq:if1}\n  \\hoare{I \\wedge x \\not= y \\wedge x < y}{y := y - x;}{I}\n\\end{equation}\nholds.  Next, let us consider the second alternative of the \\texttt{if} conditional.  We have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\hoare{I \\wedge x \\not= y \\wedge x \\geq y}{x := x - y;}{(I \\wedge x \\not= y \\wedge x \\geq y)\\sigma}$ \n\\\\[0.2cm]\nwhere $\\sigma = [x \\mapsto x + y]$. The expression $(I \\wedge x \\not= y \\wedge x \\geq y)\\sigma$ is rewritten as follows:\n\\begin{eqnarray*}\n &   & \\bigl(I \\wedge x \\not= y \\wedge x \\geq y\\bigr)\\sigma \\\\\n & \\leftrightarrow & \\bigl(I \\wedge x > y \\bigr)\\sigma \\\\\n & \\leftrightarrow & \\bigl(x > 0 \\wedge y > 0 \\wedge \\texttt{gcd}(x,y) = \\texttt{gcd}(a,b) \\wedge \n             x > y \\bigr)[x \\mapsto x + y] \\\\\n & \\leftrightarrow & x + y > 0 \\wedge y > 0 \\wedge \\texttt{gcd}(x+y,y) = \\texttt{gcd}(a,b) \n       \\wedge x + y > y  \\\\\n & \\leftrightarrow & x + y > 0 \\wedge y > 0 \\wedge \\texttt{gcd}(x,y) = \\texttt{gcd}(a,b) \n       \\wedge x > 0 \n\\end{eqnarray*}\nThe last formula implies that\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ x > 0 \\wedge y > 0 \\wedge \\texttt{gcd}(x,y) = \\texttt{gcd}(a,b). $\n\\\\[0.2cm]\nholds.  Again, this is our invariant $I$.  Therefore we have shown that\n\\begin{equation}\n  \\label{eq:if2}\n  \\hoare{I \\wedge x \\not= y \\wedge x \\geq y}{x := x - y;}{I} \n\\end{equation}\nholds.  If we use the Hoare triples (\\ref{eq:if1}) and (\\ref{eq:if2}) as premisses\nfor the rule for conditionals we have shown that\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$  \\hoare{I \\wedge x \\not= y}{if (x < y) \\{ y := y - x; \\} else \\{  x := x - y; \\}}{I} $\n\\\\[0.2cm]\nholds.  Now the verification rule for \\texttt{while} loops yields\n\n\n\\noindent\n\\hspace*{1.3cm} \n$\\{ I \\}$\n\\\\[0.1cm]\n\\hspace*{2.2cm}\n\\texttt{while (x != y ) \\{} \\\\[0.1cm]\n\\hspace*{3.2cm}\n         \\texttt{if (x < y) \\{ y := y - x; \\} else \\{ x := x - y;\\}}\n\\\\[0.1cm]\n\\hspace*{2.2cm}\n\\texttt{\\}} \\quad \n\\\\[0.1cm]\n\\hspace*{1.3cm}\n$\\{ I \\wedge x = y \\}$. \n\\\\[0.2cm]\nExpanding the invariant $I$ in the formula $I \\wedge x = y$ shows that the postcondition of the \n\\texttt{while} loop is given as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$x > 0 \\wedge y > 0 \\wedge \\texttt{gcd}(x,y) = \\texttt{gcd}(a,b) \\wedge x = y$.\n\\\\[0.2cm]\nNow the correctness of the Euclidean algorithm can be established as follows:\n\\begin{eqnarray*}\n&             &  x > 0 \\wedge y > 0 \\wedge \\texttt{gcd}(x,y) = \\texttt{gcd}(a,b) \\wedge x = y \\\\\n& \\Rightarrow & \\texttt{gcd}(x,y) = \\texttt{gcd}(a,b) \\wedge x = y \\\\\n& \\Rightarrow & \\texttt{gcd}(x,x) = \\texttt{gcd}(a,b)  \\\\\n& \\Rightarrow & x = \\texttt{gcd}(a,b) \\qquad\\qquad \\mathrm{because} \\quad \\texttt{gcd}(x,x) = x.\n\\end{eqnarray*}\nAll in all we have shown the following: If the \\texttt{while} loop terminates, then\nthe variable $x$ will be set to the greatest common divisor of $a$ and $b$, where $a$ and $b$ are\nthe initial values of the variables $x$ and $y$.  In order to finish our correctness proof we have\nto show that the \\texttt{while} loop does indeed terminate for all choices of $a$ and $b$.\nTo this end let us define the variable $s$ as follows:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ s := x + y. $\n\\\\[0.2cm]\nThe variables $x$ and $y$ are natural numbers.  Therefore $s$ is a natural number, too.\nEvery iteration of the loop reduces the number $s$: either $x$ is subtracted from $s$\nor $y$ is subtracted from  $s$ and the invariant $I$ shows that both $x$ and $y$ are\npositive.  Therefore, if the \\texttt{while} loop would run forever, at some point $s$ would get\nnegative.  Since $s$ can not be negative, the loop must terminate.\nHence we have shown the correctness of the Euclidean  algorithm.\n\\pagebreak\n\n\\exerciseEng\nShow that the function $\\texttt{power}(x,y)$ that is defined in Figure\n\\ref{fig:power-iterative.stlx} does compute $x^y$, i.~e.~show that $\\texttt{power}(x,y) = x^y$ \nfor all natural numbers $x$ and $y$.\n\n\n\\begin{figure}[!h]\n\\centering\n\\begin{Verbatim}[ frame         = lines, \n                  framesep      = 0.3cm, \n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 1.3cm,\n                  xrightmargin  = 1.3cm,\n                ]\n    power := procedure(x, y) {\n        r := 1;\n        while (y > 0) {\n            if (y % 2 == 1) {\n                r := r * x;\n            }\n            x := x * x;\n            y := y \\ 2;\n        }\n        return r;\n    };\n\\end{Verbatim}\n\\vspace*{-0.3cm}\n\\caption{A program to compute $x^y$ iteratively.}\n\\label{fig:power-iterative.stlx}\n\\end{figure}\n\n\n\\noindent\n\\textbf{Hints}: \n\\begin{enumerate}\n\\item If the initial values of $x$ and $y$ are called $a$ and $b$,\n      then an invariant for the \\texttt{while} loop is given as \n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $I := \\bigl(r \\cdot x^y = a^b\\bigr)$.\n\\item The verification rule for the conditional without \\texttt{else} is given as\n      \\\\[0.4cm]\n      \\hspace*{1.3cm}\n      $\\bruch{\\quad\\hoare{F \\wedge B}{P}{G}, \\qquad F \\wedge \\neg B \\rightarrow G\\quad}{\n                     \\hoare{F}{if ($B$) \\{ P \\}}{G}}\n      $\n      \\\\[0.2cm]\n      This rule is interpreted as follows:\n      \\begin{enumerate}\n      \\item If both the precondition $F$ and the condition $B$ is valid, then execution of the\n            program fragment $P$ has to establish the validity of the postcondition $G$.\n      \\item If the precondition $F$ is valid but we have $\\neg B$, then this must imply the postcondition\n            $G$.\n      \\end{enumerate}\n\\end{enumerate}\n\n\\remark\nProving the correctness of a nontrivial program is very tedious.\nTherefore, various attempts have been made to automate the task.  For\nexample, \\href{http://www.key-project.org/download/hoare/}{\\emph{KeY Hoare}}\nis a tool that can be used to verify the correctness of programs.  It is based on\nHoare calculus.\n\n\n\\section{Symbolic  Program Execution}\nThe last section has shown that using Hoare logic to verify a program can be quite difficult.\nThere is another method to prove the correctness of imperative programs.  This method is called\n\\emph{symbolic program execution}.  Let us demonstrate this method.  Consider the program\nshown in Figure \\ref{fig:power-iterative-annotated.stlx}.\n\n\n\\begin{figure}[!h]\n\\centering\n\\begin{Verbatim}[ frame         = lines, \n                  framesep      = 0.3cm, \n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 1.3cm,\n                  xrightmargin  = 1.3cm,\n                  codes         = {\\catcode`_=8\\catcode`$=3},\n                  commandchars  = \\\\\\{\\},\n                ]\n    power := procedure(x$_0$, y$_0$) \\{\n        r$_0$ := 1;\n        while (y$_n$ > 0) \\{\n            if (y$_n$ % 2 == 1) \\{\n                r$_{n+1}$ := r$_n$ * x$_n$;\n            \\} \n            x$_{n+1}$ := x$_n$ * x$_n$;\n            y$_{n+1}$ := y$_n$ \\symbol{92} 2;            \n        \\} \n        return r$_N$;\n    \\};\n\\end{Verbatim}\n\\vspace*{-0.3cm}\n\\caption{An annotated programm to compute powers.}\n\\label{fig:power-iterative-annotated.stlx}\n\\end{figure} % $\n\nThe main difference between a mathematical formula and a program is that in a formula all\noccurrences of a variable refer to the same value.   This is different in a program because the\nvariables change their values dynamically.  In order to deal with this property of program variables\nwe have to be able to distinguish the different occurrences of a variable.  To this end,  we \nindex the program variables. \nWhen doing this we have to be aware of the fact that the same occurrence of a program variable can\nstill denote different values if the variable occurs inside  a loop.  In this case we have to index\nthe variables in a way that the index includes a counter that counts the number of loop iterations.\nFor concreteness, consider the  program shown in \nFigure \\ref{fig:power-iterative-annotated.stlx}.  \nHere, in line 5 the variable \\texttt{r} has the index $n$ on the right side of the assignment,\nwhile it has the index $r_{n+1}$ on the left side of the assignment in line 5.  Here, $n$ denotes \nthe number of times the \\texttt{while} loop has been iterated.\nAfter the loop in line 10 the variable is indexed as\n$\\texttt{r}_N$, where $N$ denotes the total number of loop iterations.\nWe show the correctness of the given program next.  Let us define\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$ a := x_0, \\quad b := y_0$.\n\\\\[0.2cm]\nWe show, that the \\texttt{while} loop satisfies the invariant\n\\begin{equation}\n  \\label{eq:powerInv}\n   r_n \\cdot x_n^{y_n} = a^b.\n\\end{equation}\nThis claim is proven by induction on the number of loop iterations.\n\\begin{enumerate}\n\\item[B.C.] $n=0$: Since we have $r_0 = 1$, $x_0 = a$, and $y_0 = b$ we have \n            \\\\[0.2cm]\n            \\hspace*{1.3cm}\n            $r_n \\cdot x_n^{y_n} = r_0 \\cdot x_0^{y_0} = 1 \\cdot a^{b} = a^b$.\n\\item[I.S.] $n \\mapsto n + 1$:  We need a case distinction with respect to $y \\mod 2$:\n            \\begin{enumerate}\n            \\item $y_n \\mod 2 = 1$.  Then we have $y_{n} = 2 \\cdot (y_n\\symbol{92}2) + 1$ and\n                  $r_{n+1} = r_n \\cdot x_n$.  Hence\n                  \\begin{eqnarray*}\n                      &   & r_{n+1} \\cdot x_{n+1}^{y_{n+1}} \\\\[0.2cm] \n                      & = & (r_{n} \\cdot x_n) \\cdot (x_{n} \\cdot x_{n})^{y_{n}\\symbol{92}2} \\\\[0.2cm] \n                      & = & r_{n} \\cdot x_n^{2 \\cdot (y_{n}\\symbol{92}2) + 1} \\\\[0.2cm] \n                      & = & r_{n} \\cdot x_n^{y_n} \\\\\n                      & \\stackrel{i.h.}{=} & a^{b} \n                  \\end{eqnarray*}\n\n\n            \\item $y_n \\mod 2 = 0$.  Then we have $y_{n} = 2 \\cdot (y_n\\symbol{92}2)$ and $r_{n+1} = r_n$.\n                  Therefore\n                  \\begin{eqnarray*}\n                      &   & r_{n+1} \\cdot x_{n+1}^{y_{n+1}} \\\\[0.2cm] \n                      & = & r_{n} \\cdot (x_{n} \\cdot x_{n})^{y_{n}\\symbol{92}2} \\\\[0.2cm] \n                      & = & r_{n} \\cdot x_n^{2 \\cdot (y_{n} \\symbol{92} 2)} \\\\[0.2cm] \n                      & = & r_{n} \\cdot x_n^{y_n} \\\\\n                      & \\stackrel{i.h.}{=} & a^{b} \n                  \\end{eqnarray*}\n            \\end{enumerate}\n\\end{enumerate}\nThis shows the validity of the equation (\\ref{eq:powerInv}).   If the \\texttt{while} loop\nterminates, we must have $y_N = 0$.  If $n=N$, then equation (\\ref{eq:powerInv}) yields:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$r_N \\cdot x_N^{y_N} = x_0^{y_0} \n \\;\\Longleftrightarrow\\; r_N \\cdot x_N^{0}   = a^b\n \\;\\Longleftrightarrow\\;  r_N \\cdot 1         = a^b\n \\;\\Longleftrightarrow\\;  r_N                 = a^b\n$\n\\\\[0.2cm]\nThis shows $r_N = a^b$ and since we already know that the\n\\texttt{while} loop terminates, we have proven that\n$\\texttt{power}(a,b) =a^b$.\n\n\\exerciseEng\nUse the method of symbolic program execution to prove the correctness of the implementation of the\nEuclidean algorithm that is shown in Figure \\ref{fig:gcd.stlx}.  During the proof you should make\nuse of the fact that for all positive natural numbers $a$ and $b$ the equation\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\mathtt{gcd}(a, b) = \\mathtt{gcd}(a \\,\\texttt{\\%}\\, b, b)$\n\\\\[0.2cm]\nis valid.  \n\n\\begin{figure}[!ht]\n\\centering\n\\begin{Verbatim}[ frame         = lines, \n                  framesep      = 0.3cm, \n                  firstnumber   = 1,\n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 0.8cm,\n                  xrightmargin  = 0.8cm,\n                ]\n    gcd := procedure(a, b) {\n        while (b != 0) {\n            [a, b] := [b, a % b];\n        }\n        return a;\n    };\n\\end{Verbatim}\n\\vspace*{-0.3cm}\n\\caption{An efficient version of the Euclidean algorithm.}\n\\label{fig:gcd.stlx}\n\\end{figure}\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"logik\"\n%%% End: \n", "meta": {"hexsha": "7ff3405661fa8581ff0d06e0f99c776824ec1d7d", "size": 34994, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-Notes/hoare.tex", "max_stars_repo_name": "AbdalrohmanGitHub/Logik", "max_stars_repo_head_hexsha": "62270c224061f38b637cb6920a0fbe5a56495bb9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-10-03T13:25:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-26T11:49:25.000Z", "max_issues_repo_path": "Lecture-Notes/hoare.tex", "max_issues_repo_name": "AbdalrohmanGitHub/Logik", "max_issues_repo_head_hexsha": "62270c224061f38b637cb6920a0fbe5a56495bb9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2015-01-14T15:36:24.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-21T02:13:23.000Z", "max_forks_repo_path": "Lecture-Notes/hoare.tex", "max_forks_repo_name": "AbdalrohmanGitHub/Logik", "max_forks_repo_head_hexsha": "62270c224061f38b637cb6920a0fbe5a56495bb9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-10-03T16:05:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-10T19:44:15.000Z", "avg_line_length": 40.5023148148, "max_line_length": 136, "alphanum_fraction": 0.620020575, "num_tokens": 12230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.7354155175224741}}
{"text": "\\subsection{Notations}\n  Vectors will be written in column form and denoted by boldface lower-case letters. \n  The set of integers $\\{\\ell,\\ldots,k\\}$ is denoted by $[\\ell,k]$.\n  For a non-negative integer $a$, let $\\texttt{wt}(a)$ be the Hamming weight of its binary expansion. We denote the set of residue classes modulo $p$ by $\\Z_p$ and the class representatives of $\\Z_p$ are taken from the half-open interval $[-p/2, p/2)$.\n\n\\subsection{Comparison of integers with finite fields operations}\n  Let $\\S$ be a totally ordered set with a binary relation $<$.\n  For any $x,y \\in \\S$, we can define the less-than and the equality functions as follows.\n  \\begin{align*}\n    \\LT_\\S(x,y) = \n    \\begin{cases}\n      1, & \\text{if } x < y; \\\\\n      0, & \\text{if } x \\ge y, \\\\\n    \\end{cases}\n    \\\\\n    \\EQ_\\S(x,y) = \n    \\begin{cases}\n      1, & \\text{if } x = y; \\\\\n      0, & \\text{if } x \\neq y. \\\\\n    \\end{cases}\n  \\end{align*}\n  %In our case, $\\S$ is a set of consecutive integers.\n\n\\subsubsection{Functions over finite fields}\\label{subsec:funcff}\nThe map defined by $\\princhar: x \\mapsto x^{p^d-1}$ from $\\F_{p^d}$ to the binary set $\\{0,1\\}$ is called the \\emph{principal character}. \nAccording to Euler's theorem, it returns $1$ if $x$ is non-zero and $0$ otherwise. \n%It can thus be used to compute the equality function:\n%\\begin{align*}\n%  \\EQ_{\\F_{p^d}}(x,y) = 1 - \\princhar (x-y).\n%\\end{align*}\n%Moreover, note that since:\n%\\begin{align}\\label{eq:exp_frob}\n%  a^{p^d-1} = a^{(p-1)(p^{d-1} + \\dots + 1)} = \\prod_{i=0}^{d-1} \\left(a^{p-1}\\right)^{p^i},\n%\\end{align}\n%$\\chi$ can be computed with Frobenius maps ($x \\mapsto x^p$) and multiplications.\nUsing the principal character, every function from $\\F_{p^d}^l$ to $\\F_{p^d}$ can be interpolated by a unique polynomial according to the following well-know lemma. \n\\begin{lemma}\\label{lem:interpolation}\n  Every function $f: \\F_{p^d}^l \\rightarrow \\F_{p^d}$ is a polynomial function represented by a unique polynomial $P_f(X_1,\\dots,X_{l})$ of degree at most $p^d - 1$ in each variable.\n  In particular,\n  \\begin{align*}\n    P_f(X_1,\\dots,X_{l}) = \\sum_{\\va \\in \\F^l_{p^d}} f(\\va) \\prod_{i=1}^{l} \\left(1 - \\princhar(X_i - a_i)\\right)\\,.\n  \\end{align*}\n  where $a_i$ is the $i$th coordinate of vector $\\va$. \n\\end{lemma}\n\n\\subsubsection{Comparison of integers}\n  Let $\\F_{p^d} = \\F_p[X]/\\ideal{f(X)}$ for some irreducible monic polynomial $f(X)$ of degree $d$.\n  Let $d'\\leq d$ and $\\S \\subseteq [0,p^{d'}-1]$, we can map $\\S$ into $\\F_{p^d}$ by using the decomposition of integers in base $p$:\n  $$\\begin{array}{cccc}\n      \\iota_p : & \\S & \\rightarrow & \\F_{p^d}\\,, \\\\\n              & \\displaystyle\\sum_{i=0}^{d'-1}a_ip^i & \\mapsto & \\displaystyle\\sum_{i=0}^{d'-1}a_i X^{i-1}\\,. \n    \\end{array}$$\n  Note that the map $\\iota_p$ is injective and gives a one-to-one correspondence between $\\S$ and $\\F_{p^{d}}$ when $d'=d$ and $\\S = [0,p^d-1]$. \n  Therefore, we identify integers belonging to $\\S$ with their image by $\\iota_p$ and thus omit $\\iota_p$ when the situation is clear from the context.\n\n  Let $a,b \\in \\S$ be two integers to be compared and $\\sum_{i=0}^{d'-1} a_i X^i$ and $\\sum_{i=0}^{d'-1} b_i X^i$ with $a_i, b_i \\in \\F_p$ are their respective encodings into $\\F_{p^d}$.\n  The order of the set $\\S$ induces a polynomial function in $\\F_{p^d}$, which can be interpolated by Lemma~\\ref{lem:interpolation}.\n  However, since $\\LT_\\S(0,y) = 1$ for any non-zero $y \\in \\F_{p^d}$ and zero otherwise, we obtain $\\LT_\\S(0,y) = \\chi(y)$.\n  Hence, the total degree of the interpolation polynomial is at least $p^d-1$, \n  which might be prohibitive in practice.\n\n  Tan et al.~\\cite{TLWRK20} proposed an alternative approach where $\\S = [0,p-1]$.\n  If input integers $a$ and $b$ belong to $\\S$, the result of $\\LT_\\S$(a,b) is computed with its interpolation polynomial over $\\F_p$.  \n  If $a,b$ are larger, e.g. $a,b \\in [0,p^{d'-1}]$, they are encoded into $\\F_{p^d}$ as above, but their comparison is performed via the lexicographic order defined on $\\F_p^{d'}$.\n  This method is based on the extraction of coefficients $a_i, b_i \\in \\F_p$ thanks to the following result from the theory of finite fields (see \\cite[Theorem 2.24]{LN86} for the proof).\n  \\begin{lemma}\\label{lem:extraction}\n    The linear transformations from $\\F_{p^d}$ to $\\F_p$ are exactly the mappings $L_{\\alpha}(x) = \\Tr_{\\F_{p^d}/\\F_p}(\\alpha x)$ for some $\\alpha \\in \\F_{p^d}$.\n    Furthermore, $L_{\\alpha} \\ne L_{\\beta}$ if $\\alpha \\ne \\beta$.\n  \\end{lemma}\n  This lemma implies that for any $i \\in [0,d'-1]$ there exist $\\alpha_i \\in \\F_{p^d}$ such that $L_{\\alpha_i}(a) = a_i$ for any $a$ from the vector subspace $\\F_p^{d'}$ of $\\F_{p^d}$.\n  Such $\\alpha_i$'s can be computed by solving the following system of equations over $\\F_{p^d}$ \n  \\begin{align*}\n    \\mX \\mA\n    =\n    \\mI_{d}\n  \\end{align*}\n  where\n  \\begin{align*}\n  \\mX &= \\begin{pmatrix}\n      1       & 1       & \\dots   & 1             \\\\\n      x       & x^p     & \\dots   & x^{p^{d-1}}   \\\\\n      \\vdots  & \\vdots  & \\ddots  & \\vdots        \\\\\n      x^{d-1}     & x^{(d-1)p}    & \\dots   & x^{(d-1)p^{d-1}}  \\\\\n    \\end{pmatrix}\\,,\n    \\\\\n    \\mA &= \\begin{pmatrix}\n      \\alpha_0      & \\alpha_1      & \\dots   & \\alpha_{d-1}      \\\\\n      \\alpha_0^{p}  & \\alpha_1^{p}  & \\dots   & \\alpha_{d-1}^{p}  \\\\\n      \\vdots        & \\vdots        & \\ddots  & \\vdots            \\\\\n      \\alpha_0^{p^{d-1}}  & \\alpha_1^{p^{d-1}}  & \\dots   & \\alpha_{d-1}^{p^{d-1}}  \\\\\n    \\end{pmatrix}\n  \\end{align*}\n  and $\\mI_d \\in \\F_{p^d}^{d \\times d}$ is the identity matrix.\n  Hence, the $i$th column of $\\inv{\\mX}$ contain the powers $\\alpha_i, \\alpha_i^p, \\dots, \\alpha_i^{p^{d-1}}$, which define the linear map $L_{\\alpha_i}$.\n\n  Given the input encodings $\\sum_{i=0}^{d'-1} a_i X^i$ and $\\sum_{i=0}^{d'-1} b_i X^i$, we can extract and then compare their vectors of coefficients $\\bm{a} = (a_0,a_1,\\ldots,a_{d'-1})$ and $\\bm{b} = (b_0,b_1,\\ldots,b_{d'-1}) \\in \\F_p^{d'}$ using the lexicographical order $\\bm{<}$ on $\\F_{p}^{d'}$ defined by\n   \\begin{align*}\n      \\bm{a} \\bm{<} \\bm{b} \\Leftrightarrow \\exists i\\in[0,d'-1] \\text{ such that } & a_i < b_i \\text{ and } \\\\\n       & a_j = b_j ~~ \\forall j > i \\,.\n    \\end{align*}\n    The corresponding less-than function is equal to\n    \\begin{align*}\n      \\LT_{\\S^{d'}}(\\bm{a}, \\bm{b}) = \\sum_{i=0}^{d'-1} \\LT_{\\S}(a_{i}, b_{i}) \\prod_{j=i+1}^{d'-1} \\EQ_{\\S}(a_{j}, b_{j})\\,,\n    \\end{align*}\n    whereas the equality function is defined by\n    \\begin{align*}\n      \\EQ_{\\S^{d'}}(\\bm{a}, \\bm{b}) = \\prod_{i=0}^{d'-1} \\EQ_{\\S}(a_{i}, b_{i})\\,,\n    \\end{align*}\n    Notice that the above construction is generic for any set $\\S$ embedded into $\\F_p$.\n    For example, if $\\S = [0,s-1]$ for some $s < p$, then one can encode input integers via decomposition in base $s$ and compare them using $\\LT_{\\S^{d'}}$.\n  %This function requires $d'$ evaluations of $\\LT_{\\F_{p}}$ which has degree at most $p-1$, $d'-1$ evaluations of $\\EQ_{\\F_{p}}$ which has also degree $p-1$ and $2d'-1$ additional multiplications.\n  %Thus, if we ignore the complexity of digit extraction, the total complexity of comparing elements of $\\F_{p}^{d'}$ in terms of multiplications is $O(d'(p-1))$.\n\n\\subsubsection{Comparison of large integers}\\label{sec:comparison_of_large_integers}\nWhen the size of input integers exceeds $|\\S|^d$, we can decompose integers in base $|\\S|^{d'}$ and then compare their vectors of digits using the lexicographical order $\\bm{<}$ on $\\left(\\F_{p}^{d'}\\right)^l$, for some $d' \\le d$.\nIn fact, we compute two lexicographical orders on top of each other.\n\nLet $a,b \\in [0, |\\S|^{ld'}-1]$ be input integers. \nWe represent an integer $a = \\sum_{i=0}^l a_i |\\S|^{id'}$ by the vector $\\va=(\\bm{a}_0,\\bm{a}_1,\\ldots,\\bm{a}_{l-1}) \\in \\left(\\F_{p}^{d'}\\right)^l$ of its digits of length $l$. \nThe comparison of two integers $a$ and $b$ is thus equivalent to the comparison of their vector of digits $\\va=(\\bm{a}_0,\\bm{a}_1,\\ldots,\\bm{a}_{l-1})$ and $\\vb=(\\bm{b}_0,\\bm{b}_1,\\ldots,\\bm{b}_{l-1})$ using the lexicographical order $\\bm{<}$ on $\\left(\\F_{p}^{d'}\\right)^l$ defined as follows\n    \\begin{align*}\n      \\va \\bm{<} \\vb \\Leftrightarrow \\exists i\\in[0,l-1] \\text{ such that } & \\bm{a}_i < \\bm{b}_i \\text{ and } \\\\\n      & \\bm{a}_j = \\bm{b}_j ~~ \\forall j > i\\,.\n    \\end{align*}\n  As done in~\\cite{TLWRK20}, we can employ $\\EQ_{\\S^{d'}}$ and $\\LT_{\\S^{d'}}$ to compute the corresponding less-than function $\\LT(\\va, \\vb)$ as follows\n  \\begin{align}\\label{eq:general_lex_order}\n    \\LT(\\va, \\vb) = \\sum_{i=0}^{l-1} \\LT_{\\S^{d'}}(\\bm{a}_{i}, \\bm{b}_{i}) \\prod_{j=i+1}^{l-1} \\EQ_{\\S^{d'}}(\\bm{a}_{j}, \\bm{b}_{j}).\n  \\end{align}\n  %Notice that the multiplicative depth of this function depends essentially of the products of the equality functions.\n  %In fact, these products compare subvectors $\\va_i = (\\bm{a}_i, \\bm{a}_{i+1},\\dots,\\bm{a}_{k-1})$ and $\\vb_i = (\\bm{b}_i, \\bm{b}_{i+1},\\dots,\\bm{b}_{k-1})$ for $i \\in [1,l-1]$.\n  %Thus, we can rewrite $\\LT$ as:\n  %\\begin{align}\\label{eq:general_lex_order}\n  %  \\LT(\\va, \\vb) = \\sum_{i=0}^{k-1} \\LT_{\\F_{p}^{d'}}(\\bm{a}_{i},\\bm{b}_{i}) \\EQ_{\\F_{p}^{d'}}(\\va_{i+1}, \\vb_{i+1}) \n  %\\end{align}\n  %with the equality function $\\EQ_{\\F_{p}^{d'}}(\\va_{i+1}, \\vb_{i+1})$ that returns $1$ if $\\va_{i+1} = \\vb_{i+1}$ and $0$ otherwise.\n  % As shown in~\\todo{cite our work}, this function can be realized by a constant-depth circuit in the following way.\n  % \\begin{align}\\label{eq:rand_eq_circuit}\n  %   \\EQ_{\\F_\\fieldcard, e}(\\vx_{i+1},\\vy_{i+1}) = 1 - \\princhar_{\\fieldcard^e}\\left(\\sum_{j=i+1}^{\\ell-1} r_j (x_j - y_j)\\right)\n  % \\end{align}\n  % where $r_j$ are uniformly random elements from $\\F_{\\fieldcard^e}$.\n  % This circuit is false-biased with error probability $\\fieldcard^{-e}$.\n  % We can compute all $\\EQ_{\\F_\\fieldcard, e}(\\vx_{i+1},\\vy_{i+1})$ using the same number of multiplications as for the single equality using Algorithm~\\ref{alg:vector_equalities_circuit}.\\todo{What is the complexity?}\n\n\n%If $\\S$ is a complete set of representatives of a finite field $\\F_{p^d}$, then the equality function can be easily realized using the principal character of $\\F_{p^d}$, namely $\\EQ_\\S(x,y) = 1 - \\princhar_{p^d}(x-y)$.\n% Since this function is independent of the choice of $\\S$, we can write\n% \\begin{align*}\n%   \\EQ_{\\F_{p^d}}(x,y) = 1 - \\princhar_\\fieldcard(x-y).\n% \\end{align*}\n% Unfortunately, the comparison function is not as simple and we have to rely on Lagrange interpolation (Lemma \\ref{lem:interpolation}) to compute it. Yet, there are two different ways to evaluate it: either interpolate $\\LT_\\S$ as a bivariate function over $\\S^2$  -- i.e. compute $\\LT_\\S(x,y)$ -- or transform it as a univariate function in $z=x-y$ -- i.e. compute $\\LT_\\S(x-y,0)$.\n\n% While the second approach might seems simpler, it requires nonetheless to be able to distinguish between ``postive'' and ``negative'' values. This means that if $\\S = [0,p']$ for some $p'\\geq 1$, since the values of $z = x-y$ can range within the interval $[-p',p']$, it requires to use a plaintext modulus $p\\geq 2p'+1$ while being only able to use ``half'' of it.  \n\n\n\\subsection{Homomorphic Encryption}\nWe are interested in homomorphic encryption schemes that support SIMD operations on their plaintexts. \nThis section aims at giving the necessary background regarding these schemes.\n\n\\subsubsection{Cyclotomic fields and Chinese Remainder Theorem}\\label{subsec:crt}\n\nLet $m$ be a positive integer and $n = \\varphi(m)$ where $\\varphi$ is Euler's totient function. \nLet $\\mathcal{K} = \\Q(\\zeta_{m})$ be the cyclotomic number field constructed by adjoining a primitive $m$-th root of unity $\\zeta_{m}\\in\\C$ to the field of rational numbers. \nThe ring of integers of $\\mathcal{K}$, denoted by $\\intring$, is isomorphic to $\\Z[X]/\\ideal{\\Phi_m(X)}$ where $\\Phi_m(X)$ is the $m$-th cyclotomic polynomial. \nLet $p>1$ be a prime number coprime to $m$, then $\\Phi_m(X)$ splits modulo $p$ into $\\ell$ irreducible factors of same degree $d$, i.e. $\\Phi_m(X) = F_1(X)\\cdots F_\\ell(X) \\bmod p$. \nThe degree $d$ is actually the order of $p$ modulo $m$, and $\\ell = n/d$. \nThe \\ac{CRT} states that in this case the following ring isomorphism holds:\n\\begin{align*}\n  \\intring_p &= \\Z_p[X]/\\ideal{\\Phi_m(X)} \\nonumber \\\\ \n  & \\cong \\Z_p[X]/\\ideal{F_1(X)} \\times \\ldots \\times \\Z_p[X]/\\ideal{F_{\\ell}(X)}\n\\end{align*}\nFor each $i \\in [1,\\ell]$ the quotient ring $\\Z_p[X]/\\ideal{F_i(X)}$ is isomorphic to the finite field $\\F_{p^d}$. \nHence, the above isomorphism can be rewritten as $\\intring_p \\cong \\F_{p^d}^\\ell$.\nWe call every copy of $\\F_{p^d}$ in this direct product a \\emph{slot}. \nTherefore, every element of $\\intring_p$ contains $\\ell$ slots, which implies that an array of $\\ell$ independent $\\F_{p^d}$-elements can be encoded as a unique element of $\\intring_p$. \nThe slot isomorphic to $\\Z_p[X]/\\ideal{F_i(X)}$ is referred to as the \\emph{$i$th} slot.\n\nAdditions and multiplications of $\\intring_p$-elements results in the corresponding coefficient-wise operations of their respective slots. \nIn other words, each ring operation on $\\intring_p$ is applied to every slot in parallel, which resembles the Single-Instruction Multiple-Data (SIMD) instructions used in parallel computing.\nTherefore, the above encoding method from $\\F_{p^d}^\\ell$ to $\\intring_p$ is often called the \\emph{SIMD packing}.\n\n%Using multiplication, we can easily define a projection map $\\proj_i$ on $\\intring_p$ that sends $a \\in \\intring_p$ encoding slots $(m_0, \\dots, m_{\\ell-1})$ to $\\pi_i(a)$ encoding $(0, \\dots, m_i, \\dots, 0)$.\n%In particular, $\\proj_i(a) = a g_i$, where $g_i \\in \\intring_t$ encodes $(0 \\dots, 1, \\dots, 0)$.\n%We can generalize this projection for any $I \\subseteq \\{1,\\dots,\\ell\\}$ to $\\proj_I(a) = a g_I$ with $g_I \\in \\intring_p$ encoding $1$ in the SIMD slots indexed by $I$.\\newline\n\n%The field $\\numfield = \\Q(\\zeta_{m})$ is a Galois extension and its Galois group $\\mathcal{G} = \\Gal{(\\numfield/\\Q)}$ is isomorphic to $\\Z_m^\\times$  through: $i \\mapsto (\\sigma_i: X \\mapsto X^i)$ where $i \\in \\Z_m^\\times$. \n%The automorphism $\\sigma_p$ corresponding to $p$ is called \\emph{the Frobenius automorphism} and generates the Galois group $\\Gal{(\\F_{p^d}/\\F_p)}$ of each slot. \n%This means that $\\mathcal{F} = \\ideal{\\sigma_p} \\subset \\mathcal{G}$ partitions the roots of $\\Phi_m$  into $\\ell$ sets $S_i$ of $d$ elements, each set corresponding to the roots of a factor $F_i$ over $\\C$. \n%Therefore, the group $\\mathcal{H} = \\mathcal{G}/\\mathcal{F}$ acts transitively on a set of representatives $\\bar{S}_i$ of each $S_i$ and thus maps $\\bar{S}_i$ to $\\bar{S}_j$. \n%In other words, the elements of $\\mathcal{H}$ permute the SIMD slots. \n%However, the order of $\\mathcal{H}$ is $n/d = \\ell$, which is less than $\\ell!$, the number of all possible permutations of the $\\ell$ SIMD slots. \n%Nonetheless, it was shown in~\\cite{GHS12} that every permutation of SIMD slots can be realized by combination of automorphisms from $\\mathcal{H}$, projection maps and additions.\n\nThe HE schemes that support SIMD packing and \\emph{exact} computations over encrypted data include $\\BGV$~\\cite{BGV12} and $\\FV$~\\cite{FV12}. \nThese schemes have a common framework described below.\n\n\\subsubsection{Basic setup}\n\nLet $\\lambda$ be the security level of an HE scheme.\nLet $L$ be the maximal multiplicative depth of homomorphic circuits we want to evaluate.\nLet $d$ be the order of the plaintext modulus $p$ modulo the order $m$ of $\\intring$.\nAssume that the plaintext space $\\intring_p$ has $\\slots$ SIMD slots, i.e. $\\intring_p \\cong \\F^\\ell_{p^d}$.\n% For a vector $\\va \\in \\F^k_{p^d}$, we denote the plaintext encoding of $\\va$ by $\\pt(\\va)$. \nThe basic part of any HE schemes consists of key generation, encryption and decryption algorithms.\n\n$\\KeyGen(1^\\lambda, 1^L) \\rightarrow (\\sk, \\pk)$. Given $\\lambda$ and $L$, this function outputs the secret key $\\sk$ and the public key $\\pk$.\n%Note that the public key contains special key-switching keys that help to transform ciphertexts encrypted under other secret keys back to ciphertexts encrypted under $\\sk$. \n\n$\\Encrypt(\\pt \\in \\intring_p, \\pk) \\rightarrow \\ct$. The encryption algorithm takes a plaintext $\\pt$ and the public key $\\pk$ and outputs a ciphertext $\\ct$.\n\n$\\Decrypt(\\ct, \\sk) \\rightarrow \\pt$. The decryption algorithm takes a ciphertext $\\ct$ and the secret key $\\sk$ and returns a plaintext $\\pt$.\nFor freshly encrypted ciphertexts, the decryption correctness means that $\\Decrypt(\\Encrypt(\\pt, \\pk), \\sk) = \\pt$. \n\n\n\\subsubsection{Homomorphic operations}\n\nThe homomorphic addition (multiplication) algorithm takes two input ciphertexts $\\ct_1$ and $\\ct_2$ encrypting plaintexts $\\pt_1$ and $\\pt_2$ respectively.\nIt outputs a ciphertext $\\ct$ that encrypts the sum (product) of these plaintexts in the ring $\\intring_p$.\nIt implies that homomorphic addition (multiplication) sums (multiplies) respective SIMD slots of $\\pt_1$ and $\\pt_2$.\nSimilar operations between ciphertexts and plaintexts are defined as well.  \n\n%As shown in Section~\\ref{subsec:crt}, the projection map $\\proj_I$ can select the SIMD slots indexed by a set $I \\subseteq \\{0,\\dots,\\slots-1\\}$ and set the rest to zero.\n%This functionality is homomorphically realized by the $\\Select$ function.\n\n%$\\Select(\\ct, I) = \\MulPlain(\\ct, \\pt(\\1_I)) \\rightarrow \\ct'$ where $\\1_I$ is a vector having $1$'s in the coordinates indexed by a set $I$ and zeros everywhere else.\n%Given a ciphertext $\\ct$ encrypting SIMD slots $\\vm = (m_0,m_1,\\dots,m_{\\slots-1})$ and a set $I$, this function returns a ciphertext $\\ct'$ that encrypts $\\vm' = (m'_0,\\dots,m'_{\\slots-1})$ such that $m'_i = m_i$ if $i \\in I$ and $m'_i = 0$ otherwise.\n\n%\\subsubsection{Special operations}\\label{subsec:special_operations}\n\n%One can also homomorphically permute the SIMD slots of a given ciphertext and act on them with the Frobenius automorphism. \n\n%$\\Rotate(\\ct, i) \\rightarrow \\ct'$ with $i \\in [0, \\slots-1]$. Given a ciphertext $\\ct$ encrypting SIMD slots \n%$$\\vm = (m_0,m_1,\\dots,m_{\\slots-1}),$$\n%the rotation algorithm returns a ciphertext $\\ct'$ that encrypts the cyclic shift of $\\vm$ by $i$ positions, namely $(m_i,m_{(i+1) \\mod \\slots},\\dots,m_{(i-1) \\mod \\slots})$.\n\n%$\\Frob(\\ct, i) \\rightarrow \\ct'$ with $i\\in[0,d-1]$. Given a ciphertext $\\ct$ encrypting SIMD slots $\\vm$ as above, the Frobenius algorithm returns a ciphertext $\\ct'$ that encrypts a Frobenius map action on $\\vm$, namely $(m^{p^i}_0,m^{p^i}_1,\\dots,m^{p^i}_{\\slots-1})$.\n\n%As discussed in Section~\\ref{subsec:funcff}, the $\\Frob$ and $\\Mul$ operations can be combined to compute the principal character $\\princhar$, which turns non-zero values of SIMD slots into $1$ and leaves slots with zeros unchanged.\n\n%$\\IsNonZero(\\ct) \\rightarrow \\ct'$. Given a ciphertext $\\ct$ encrypting SIMD slots $\\vm = (m_0,m_1,\\dots,m_{\\slots-1})$, this function returns a ciphertext $\\ct'$ that encrypts:\n%\\[\n%  (\\princhar(m_0), \\princhar(m_1), \\dots, \\princhar(m_{\\slots-1})).\n%\\]\n% Kim et al.~\\cite{TDSC:KLLW16} showed that one can employ the Frobenius map to decrease the multiplicative depth of $\\IsNonZero$.\n%Recall that $\\princhar(m) = m^{p^d-1} = \\prod_{i=0}^{d-1} (m^{p-1})^{p^i}$ as shown in~(\\ref{eq:exp_frob}).\n%The multiplicative depth of $x^{p-1}$ is equal to $\\ceil{\\log_2 (p-1)}$.\n%The multiplicative depth of $x^{p^i}$ is zero as it can be done by the $\\Frob$ operation.\n%In total, $d-1$ $\\Frob$ operations are needed to compute $\\princhar(m)$.\n%As a result, the total multiplicative depth of $\\IsNonZero$ is\n%\\begin{align}\\label{eq:nonzero_depth}\n%  \\ceil{\\log_2 (p-1)} + \\ceil{\\log_2 d}.\n%\\end{align}\n%Using general exponentiation by squaring, $x^{p-1}$ requires $\\floor{\\log_2 (p-1)} + \\wt(p-1) - 1$ field multiplications.\n%Since $d-1$ field multiplications are needed to compute $\\prod_{i=0}^{d-1} (x^{p-1})^{p^i}$, the total number of multiplications to compute $\\princhar(m)$ is:\n%\\begin{align}\\label{eq:nonzero_width}\n%  \\floor{\\log_2 (p-1)} + \\wt(p-1) + d - 2.\n%\\end{align} \n\nEvery homomorphic ciphertext contains a special component called \\emph{noise} that is removed during decryption.\nHowever, the decryption function can deal only with noise of small enough magnitude; otherwise, this function fails.\nThis noise bound is defined by encryption parameters in a way that larger parameters result in a larger bound.\nThe ciphertext noise increases after every homomorphic operation and, therefore, approaches its maximal possible bound.\nIt implies that to reduce encryption parameters one needs to avoid homomorphic operations that significantly increase the noise.\nTherefore, while designing homomorphic circuits, we need to take into account not only the running time of homomorphic operations but also their effect on the noise.  \n\n%Table~\\ref{table:he_operations} summarizes the running time and the noise cost of the aforementioned homomorphic operations.\n%Similar to~\\cite{C:HalSho14}, we divide the operations into expensive, moderate and cheap.\n%The expensive operations dominate the cost of a homomorphic circuit.\n%The moderate operations are less important, but if there are many of them in a circuit, their total cost can dominate the total cost.\n%The cheap operations are the least important and can be omitted in the cost analysis.\nThe most expensive homomorphic operation with relation to both noise and running time is ciphertext-ciphertext multiplication ($\\Mul$).\nThis operations takes place when two expressions containing input values are multiplied.\nSuch multiplication is called \\emph{non-scalar}.\nIn contrast, ciphertext-plaintext multiplication ($\\MulPlain$) is used when an expression with input values is multiplied by an unencrypted or publicly known value.\nThis is a \\emph{scalar} multiplication.\nSince $\\Mul$ is much more expensive than $\\MulPlain$, the multiplicative depth and complexity of a homomorphic circuit is usually calculated with relation to the number of $\\Mul$'s, or non-scalar multiplications.\nThus, in the following sections we focus on the non-scalar complexity of comparison circuits.\n%\\begin{table}[t!]\n%  \\centering\n%  \\begin{tabular*}{6.5cm}{ p{2cm} p{2cm} p{2cm} }\n%    \\toprule\n%    Operation\t& Time\t\t\t& Noise \\\\\n%    \\midrule\n%    $\\Add$\t\t& cheap\t\t\t& cheap \t\\\\\n%    $\\AddPlain$\t& cheap\t\t\t& cheap \\\\\n%    $\\Mul$\t\t& expensive\t\t& expensive \t\\\\\n%    $\\MulPlain$\t& cheap\t\t\t& moderate \t\\\\\n%    $\\Sub$\t\t& cheap\t\t\t& cheap  \\\\\n%    $\\SubPlain$\t& cheap\t\t\t& cheap  \\\\\n%    $\\Select$\t& cheap\t\t\t& moderate \\\\\n%    $\\Rotate$ \t & expensive\t& moderate \\\\\n%    $\\Frob$\t\t & expensive\t& cheap \\\\\n%    $\\IsNonZero$ & expensive    & expensive \\\\\n%    \\bottomrule\n%  \\end{tabular*}\n%  \\caption{The cost of homomorphic operations with relation to running time and noise growth.}\n%  \\label{table:he_operations}\n%\\end{table}\n\n\n% Let $\\F_\\fieldcard$ be a finite field of characteristic $\\fieldchar$.\n% We define the multiplicative map $\\princhar_\\fieldcard: \\F_\\fieldcard \\rightarrow \\{0,1\\}, x \\mapsto x^{\\fieldcard-1} \\mod \\fieldchar$, which is called the \\emph{principal character}.\n% Due to Euler's theorem, $\\princhar_\\fieldcard(0) = 0$ and $\\princhar_\\fieldcard(x) = 1$ for any $x \\in \\F_\\fieldcard^\\times$.\n% Since\n% \\begin{align}\\label{eq:exp_frob}\n% a^{t^d-1} = a^{(t-1)(t^{d-1} + \\dots + 1)} = \\prod_{i=0}^{d-1} (a^{t-1})^{t^i},\n% \\end{align}\n% the principal character can be realized by Frobenius maps and multiplications.\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main_pets\"\n%%% End:\n", "meta": {"hexsha": "6557369e7a5e89735287b232e321ba9e2bea07a1", "size": 23468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/background.tex", "max_stars_repo_name": "iliailia/comparison-circuit-over-fq", "max_stars_repo_head_hexsha": "bc48a9101278997f0847b6ace59c8f3b83884dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-03-24T07:58:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T00:41:08.000Z", "max_issues_repo_path": "paper/background.tex", "max_issues_repo_name": "iliailia/comparison-circuit-over-fq", "max_issues_repo_head_hexsha": "bc48a9101278997f0847b6ace59c8f3b83884dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-03-24T03:03:11.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-01T09:23:59.000Z", "max_forks_repo_path": "paper/background.tex", "max_forks_repo_name": "iliailia/comparison-circuit-over-fq", "max_forks_repo_head_hexsha": "bc48a9101278997f0847b6ace59c8f3b83884dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-19T16:28:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T16:28:37.000Z", "avg_line_length": 74.9776357827, "max_line_length": 383, "alphanum_fraction": 0.6720214761, "num_tokens": 7667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8104788995148792, "lm_q1q2_score": 0.7353574106847589}}
{"text": "\\section{Schr\\\"odinger's Equation in Three Dimensions}\r\n\\subsection{TISE in 3D for Spherically Symmetric Potentials}\r\nThe TISE in 3D is in the form $\\hat{H}X=EX$ where\r\n$$\\hat{H}=-\\frac{\\hbar^2}{2m}\\nabla^2X+UX$$\r\nIn spherical coordiates $x=r\\cos\\phi\\cos\\theta,y=r\\sin\\phi\\sin\\theta,z=r\\cos\\theta$ where $r\\in[0,\\infty],\\theta\\in[0,\\pi],\\phi\\in[0,2\\pi)$, the Laplacian becomes\r\n$$\\nabla^2X=\\frac{1}{r}\\frac{\\partial^2(rX)}{\\partial r^2}+\\frac{1}{r^2\\sin^2\\theta}\\left( \\sin\\theta\\frac{\\partial}{\\partial\\theta}\\left( \\sin\\theta\\frac{\\partial X}{\\partial\\theta} \\right)+\\frac{\\partial^2X}{\\partial\\phi^2} \\right)$$\r\nWe consider the case where $U=U(r,\\theta,\\phi)=U(r)$ and we are only looking for spherically symmetric solutions $X(r,\\theta,\\phi)=X(r)$.\r\nThen the Hamiltonian becomes\r\n$$\\hat{H}X=-\\frac{\\hbar^2}{2m}\\frac{1}{r}\\frac{\\mathrm d^2(rX)}{\\mathrm dr^2}+UX=-\\frac{\\hbar^2}{2m}\\left( \\frac{\\mathrm d^2X}{\\mathrm dr^2}+\\frac{2}{r}\\frac{\\mathrm dX}{\\mathrm dr} \\right)+UX$$\r\nWe have the normalisation condition\r\n$$\\int_{\\mathbb R^3}|\\psi^2|\\,\\mathrm dV<\\infty\\implies \\int_0^\\infty|X(r)|^2r^2\\,\\mathrm dr<\\infty$$\r\nwhich means $X(r)\\to 0$ sufficiently fast as $r\\to\\infty$.\\\\\r\nConsider $\\sigma(r)=rX(r)$, then TISE becomes $\\hat{H}\\sigma=E\\sigma$ on the half-plane $r\\ge 0$.\r\nNow the plan is to solve this on the whole line with $U(-r)=U(r)$.\r\nAs $X(0)$ are defined, $\\sigma(0)=0$.\r\nWe only need to look for odd solutions $\\sigma(-r)=-\\sigma(r)$ since:\r\n\\begin{lemma}\r\n    There is no nontrivial even solution to the problem.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Suppose there is, say it is $\\sigma_+$, then necessarily it is $C^2$ (for the equation to make sense) and hence $\\sigma_+^\\prime(0)=\\sigma_+^{\\prime\\prime}(0)=0$.\r\n    Then we have a corresponding odd solution\r\n    $$\\sigma_-(r)=\\begin{cases}\r\n        \\sigma_+(r)\\text{, for $r\\ge 0$}\\\\\r\n        -\\sigma_+(r)\\text{, for $r<0$}\r\n    \\end{cases}$$\r\n    But then $\\sigma(r)=\\sigma_+(r)-\\sigma_-(r)$ is a solution to the equation by linearity and vanishes for any $r>0$, which should not happen.\r\n    \\footnote{Well.}\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider the symmetric potential well\r\n    $$U(r)=\\begin{cases}\r\n        0\\text{, for $r\\le a$}\\\\\r\n        U_0\\text{, for $r>a$}\r\n    \\end{cases}$$\r\n    where $a,U_0>0$.\r\n    For $0<E<U_0$, again let $k=\\sqrt{2mE/\\hbar^2}$ and $\\bar{k}=\\sqrt{2m(U_0-E)/\\hbar^2}$, so\r\n    $$\\sigma(r)=\\begin{cases}\r\n        A\\sin(kr)\\text{, for $r\\le a$}\\\\\r\n        Be^{-\\bar{k}r}\\text{, for $r<a$}\r\n    \\end{cases}$$\r\n    The boundary conditions gives $-k\\cot(ka)=\\bar{k}$ and we already know that $k^2+\\bar{k}^2=2mU_0/\\hbar^2$.\r\n    Again define $\\xi=ka,\\eta=\\bar{k}a$ and $r_0=a\\sqrt{2mU_0/\\hbar^2}$, so we have\r\n    $$\\begin{cases}\r\n        -\\xi\\cot(\\xi)=\\eta\\\\\r\n        \\xi^2+\\eta^2=r_0^2\r\n    \\end{cases}$$\r\n    Now if $r_0<\\pi/2$ (that is $U_0<\\pi^2\\hbar^2/(8ma^2)$), then there is no bounded solution.\r\n    But unlike the one-dimensional case, we can always find at least one bounded state.\r\n\\end{example}\r\n\\subsection{The Radial Wavefunction of Hydrogen Atom}\r\nThe hydrogen atom consists of a proton $p^+$ and an electron $e^-$.\r\nThe Coulomb force is\r\n$$F=-\\frac{e^2}{4\\pi\\epsilon_0r^2}=-\\frac{\\partial U}{\\partial r}\\implies U(r)=-\\frac{e^2}{4\\pi\\epsilon_0r}$$\r\nSo the bound states must have $E<0$, and $e^-$ is at rest $E=0$ as $r\\to\\infty$.\r\nWe want to look for stationary states of $e^-$ with spherically symmetric wavefunction $X=X(r)$ to\r\n$$-\\frac{\\hbar^2}{2m}\\left( \\frac{\\mathrm d^2X}{\\mathrm dr^2}+\\frac{2}{r}\\frac{\\mathrm dX}{\\mathrm dr} \\right)-\\frac{e^2}{4\\pi\\epsilon_0r}X=EX$$\r\nThen we need $E<0$ for bound states.\r\nDefine\r\n$$\\nu=\\sqrt{-\\frac{2mE}{\\hbar^2}},\\beta=\\frac{e^2m}{2\\pi\\epsilon_0\\hbar^2}$$\r\nThen the equation becomes\r\n$$\\frac{\\mathrm d^2X}{\\mathrm dr^2}+\\frac{2}{r}\\frac{\\mathrm dX}{\\mathrm dr}+\\left( \\frac{\\beta}{r}-\\nu^2 \\right)X=0$$\r\nAs $r\\to\\infty$, if we assume $X,X^\\prime$ do not explode near $\\infty$, then the equation becomes $X^{\\prime\\prime}-\\nu^2X=0$, so $X(r)\\sim e^{-\\nu r}$ as $r\\to\\infty$.\r\nThis inspires us to try $X(r)=f(r)e^{-\\nu r}$, which transforms the equation into\r\n$$\\frac{\\mathrm d^2f}{\\mathrm dr^2}+\\frac{2}{r}(1-\\nu r)\\frac{\\mathrm df}{\\mathrm dr}+\\frac{1}{r}(\\beta-2\\nu)f=0$$\r\nwhich has a regular singular point at $r=0$, so we shall try the series solution $f(r)=r^c\\sum_n a_nr^n$.\r\nPlugging in,\r\n$$0=\\sum_{r=0}^\\infty a_n(c+n)(c+n-1)r^{c+n-2}+\\frac{2}{r}(1-\\nu r)a_n(c+n)r^{c+n-1}+(\\beta-2\\nu)r^{c+n-1}$$\r\nBy looking at the coefficient of $r^{c-2}$, we have $0=a_0c(c+1)r^{c-2}$, so $c=-1$ or $c=0$.\r\nThe former is discarded as it has a singularity at $0$.\r\nSo $c=0$, hence $f(r)=\\sum_na_nr^n$ and\r\n$$0=\\sum_{n=2}^\\infty (a_nn(n+1)+a_{n-1}(\\beta-2\\nu))r^{n-2}=0\\implies a_n=\\frac{2\\nu n-\\beta}{n(n+1)}a_{n-1}$$\r\nSo all the coefficients are determined from $a_0$.\r\n\\begin{lemma}\r\n    If the series above does not terminate, then the function $X(r)=f(r)e^{-\\nu r}$ is not normalisable.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    If the series does not terminate then asymptotically $a_n\\sim C(2\\nu)^n/n!$ for some nonzero constant $C$ as $n\\to\\infty$.\r\n    Therefore $f(r)\\sim e^{2\\nu r}$, hence $X(r)\\sim e^{\\nu r}$ as $r\\to\\infty$ which means that it is not normalisale.\r\n\\end{proof}\r\nSo necessarily there is some $N$ such that $2\\nu N-\\beta=0$, so $\\nu=\\beta/(2N)$.\r\nWe can work out the energy eigenfunction from that:\r\n$$\\nu^2=-\\frac{2mE}{\\hbar^2},\\beta=\\frac{e^2m}{2\\pi\\epsilon_0\\hbar^2}\\implies E=E_N=-\\frac{e^4m}{32\\pi^2\\epsilon_0^2\\hbar^2}\\frac{1}{N^2}$$\r\nwhich is exactly the energy levels deduced by Bohr's radius.\r\nWould this mean that Bohr's model is fully correct?\r\nNot really, as there can be solutions that are not spherically symmetric.\\\\\r\nLet's find the eigenfunctions now.\r\nPlugging the relation between $N,\\nu$ and $\\beta$ we have\r\n$$\\frac{a_n}{a_{n-1}}=-2\\nu\\frac{N-n}{n(n+1)}$$\r\n$N=1$ gives a constant $f=f_1$, so $X_1(r)\\propto e^{-\\nu r}$.\r\n$N=2$ gives $f_2(r)\\propto 1-\\nu r$, so $X_2(r)\\propto (1-\\nu r)e^{-\\nu r}$.\r\n$N=3$ gives $f_3(r)\\propto 1-2\\nu r+2\\nu^2r^2/3$, so $X_3(r)=(1-2\\nu r+2\\nu^2r^2/3)e^{-\\nu r}$.\r\nAnd in general $f_N(r)=L_N(\\nu r)$ where $L_N$ is the Legendre polynomial of order $N-1$ and hence $X_N(r)=L_N(\\nu r)e^{-\\nu r}$.\r\nIt is easy enough to normalise this for small $N$.\r\nFor the ground state $N=1$, the normalised wavefunction is\r\n$$X_1(r)=\\frac{\\nu^{3/2}}{\\sqrt{\\pi}}e^{-2\\nu r}=\\frac{1}{\\sqrt\\pi}\\left( \\frac{e^2m}{4\\pi \\epsilon_0\\hbar^2} \\right)^{3/2}e^{-2\\nu r}$$\r\nWith a little calculation we have $\\langle r\\rangle_{X_1}=3a_0/2$ where $a_0=2/\\beta$ is the Bohr radius.\r\n\\subsection{Angular Momentum in Quantum Mechanics}\r\nIn classical dynamics, we defined the angular momentum $\\underline{L}=\\underline{x}\\times\\underline{p}$ which is a conserved quantity subject to spherically symmetrical potential.\r\nWhereas in quantum mechanics, we have an analogous notion.\r\n\\begin{definition}\r\n    The angular momentum operator is defined by $\\underline{\\hat{L}}=\\underline{\\hat{x}}\\times\\underline{\\hat{p}}=-i\\hbar\\underline{x}\\times\\nabla$.\r\n\\end{definition}\r\nConsequently components of $\\underline{\\hat{L}}$ are Hamiltonian and $[\\hat{L}_i,\\hat{L}_j]=i\\hbar\\epsilon_{ijk}\\hat{L}_k\\neq 0$ for $i\\neq j$.\r\nTherefore components of $\\underline{\\hat{L}}$ cannot be simultaneously measured.\r\n\\begin{definition}\r\n    The total angular momentum operator is defined as $\\hat{L}^2=|\\hat{L}|^2=\\hat{L}_1^2+\\hat{L}_2^2+\\hat{L}_3^2$.\r\n\\end{definition}\r\nThen $[\\hat{L}^2,\\hat{L}_i]=0$ for all $i$ and $[\\hat{H},\\hat{L}^2]=0$ if $U$ is spherically symmetric.\r\nTo see the latter property, just observe that $[\\hat{L}_i,\\hat{x}_j]=i\\hbar\\epsilon_{ijk}\\hat{x}_k$ and $[\\hat{L}_i,\\hat{p}_j]=i\\hbar\\epsilon_{ijk}\\hat{p}_k$ and write $\\hat{H}=\\hat{p}^2/2m+\\hat{U}$.\r\nConsequently, fixing any $i$, $\\{\\hat{H},\\hat{L}^2,\\hat{L}_i\\}$ is a set of $3$ mutually commuting operators.\r\nChoose $i=3$, then $\\hat{L}_3=\\hat{L}_z$ is the $z$ component of angular momentum.\r\nWe can find simultaneous eigenstates of all three operators $\\{\\hat{H},\\hat{L}^2,\\hat{L}_3\\}$.\r\nThe corresponding eigenvalues are observables.\r\nAlso, this set if maximal in the sense that there does not exists another independent operator other than $\\hat{I}$ which commutes with all three.\\\\\r\nWhat are the eigenfunctions?\r\nWe first try to find joint eigenfunctions of $\\hat{L}^2,\\hat{L}_3$.\r\nIn spherical polar coordinate, we can expand\r\n$$\\hat{L}^2=-\\frac{\\hbar^2}{\\sin^2\\theta}\\left( \\sin\\theta\\frac{\\partial}{\\partial\\theta}\\left( \\sin\\theta\\frac{\\partial}{\\partial\\theta} \\right)+\\frac{\\partial^2}{\\partial\\phi^2} \\right),\\hat{L}_3=-i\\hbar\\frac{\\partial}{\\partial\\phi}$$\r\nIf $Y=Y(\\theta,\\phi)$ is an eigenfunction of $\\hat{L}_3$, then $\\hat{L}_3Y=\\hbar mY$ for some $m$.\r\nConsequently $-iY_\\phi=mY$.\r\nSeperation of variables $Y(\\theta,\\phi)=y(\\theta)x(\\phi)$ gievs $x_\\phi=imx$, so $x(\\phi)=e^{im\\phi}$.\r\nBut $x$ has to have period $2\\pi$, so $m\\in\\mathbb Z$.\r\nNow $\\hat{L}^2(y(\\theta)e^{im\\phi})=\\lambda y(\\theta)e^{im\\phi}$ gives\r\n$$\\frac{1}{\\sin\\theta}\\frac{\\partial}{\\partial\\theta}\\left( \\sin\\theta\\frac{\\partial y}{\\partial\\theta} \\right)-\\frac{m^2}{\\sin^2\\theta}y(\\theta)=-\\frac{\\lambda}{\\hbar^2}y(\\theta)$$\r\nWhich is Legendre equation.\r\nBy our study in Methods, we have\r\n$$y_l(\\theta)=P_{l,m}(\\cos\\theta)=(\\sin\\theta)^{|m|}\\left.\\frac{\\mathrm d^{|m|}}{\\mathrm dx^{|m|}}P_l(x)\\right|_{x=\\cos\\theta}$$\r\nwhere $P_l$ are the ordinary Legendre polynomials and $\\lambda=l(l+1)\\hbar^2$ for $-l\\le m\\le l$.\r\nSo the simultaneous eigenfunctions of $\\hat{L}^2$ and $\\hat{L}_3$ are labelled by $l=0,1,2,\\ldots,m\\in\\{-l,\\ldots,l\\}$ and take the form\r\n$$y_{l,m}(\\theta,\\phi)=P_{l,m}(\\cos\\theta)e^{im\\phi}$$\r\nwith eigenvalues $m\\hbar$ and $l(l+1)\\hbar^2$ respectively.\r\nPhysically, we interpret $l$ as the total angular momentum numbers and $m$ the azimuthal quantum numbers.\r\nNote that the constraint $m\\in[-l,l]$ corresponds to the classical mechanical result of $-|L|\\le L_3\\le |L|$.\\\\\r\nWe can compute (whyyyyyyyy) some of these eigenfunctions (known as spherical harmonics):\r\n$$Y_{0,0}=\\frac{1}{\\sqrt{4\\pi}},Y_{1,0}=\\sqrt{\\frac{3}{4\\pi}}\\cos\\theta,Y_{1,\\pm 1}(\\theta,\\phi)=\\mp\\sqrt{\\frac{3}{8\\pi}}\\sin\\theta e^{\\pm i\\phi}$$\r\n$$Y_{2,0}(\\theta,\\phi)=\\sqrt{\\frac{5}{16\\pi}}(3\\cos^2\\theta-1),Y_{2,\\pm 1}(\\theta,\\phi)=\\mp\\sqrt{\\frac{15}{8\\pi}}\\sin\\theta\\cos\\theta e^{\\pm i\\phi}$$\r\n$$Y_{2,\\pm 2}(\\theta,\\phi)=\\sqrt{\\frac{15}{32\\pi}}\\sin^2\\theta e^{\\pm 2i\\phi}$$\r\n\\subsection{Full Wavefunction of the Hydrogen Atom}\r\nRecall that in spherical polar,\r\n$$\\nabla^2X=\\frac{1}{r}\\frac{\\partial^2(rX)}{\\partial r^2}+\\frac{1}{r^2\\sin^2\\theta}\\left( \\sin\\theta\\frac{\\partial}{\\partial\\theta}\\left( \\sin\\theta\\frac{\\partial X}{\\partial\\theta} \\right)+\\frac{\\partial^2X}{\\partial\\phi^2} \\right)$$\r\nand\r\n$$\\hat{L}^2X=\\frac{\\hbar^2}{\\sin^2\\theta}\\left( \\sin\\theta\\frac{\\partial}{\\partial\\theta}\\left( \\sin\\theta\\frac{\\partial X}{\\partial\\theta} \\right) +\\frac{\\partial^2}{\\partial\\phi^2}\\right)$$\r\nTherefore\r\n$$-\\hbar^2\\nabla^2X=-\\frac{\\hbar^2}{r}\\frac{\\partial^2(rX)}{\\partial r^2}+\\frac{\\hat{L}^2X}{r^2}$$\r\nwhich means that we can rewrite the Hamiltonian as\r\n$$\\hat{H}X=-\\frac{\\hbar^2}{2m}\\left( \\frac{\\partial^2X}{\\partial r^2}+\\frac{2}{r}\\frac{\\partial X}{\\partial r} \\right)+\\frac{\\hat{L}^2X}{2mr^2}-\\frac{e^2}{4\\pi\\epsilon_0r}X$$\r\nAs $\\{\\hat{H},\\hat{L}^2,\\hat{L}_3\\}$ is a set of commuting operators, we look for solutions to $\\hat{H}X=EX$ of the form $X(r,\\theta,\\phi)=g(r)Y_{l,m}(\\theta,\\phi)$, which (after a lot of calculations) yields\r\n$$\\frac{\\mathrm d^2g}{\\mathrm dr^2}+\\frac{2}{r}\\frac{\\mathrm dg}{\\mathrm dr}-\\frac{l(l+1)}{r^2}g+\\frac{\\beta}{r}g-\\nu^2g=0,\\nu=\\sqrt{-\\frac{2mE}{\\hbar^2}},\\beta=\\frac{e^2m}{2\\pi\\epsilon_0\\hbar^2}$$\r\nThe rest is similar to what we did for the spherically symmetrical case.\r\nWe seek solutions of the form $g(r)=f(r)e^{-\\nu r}$ due to its limiting behavour, which gives\r\n$$\\frac{\\mathrm d^2f}{\\mathrm dr^2}+\\frac{2}{r}(1-\\nu r)\\frac{\\mathrm df}{\\mathrm dr}-\\frac{l(l+1)}{r^2}f+\\frac{1}{r}(\\beta-2\\nu)f=0$$\r\nThe same procedure of finding series solution applies.\r\nSince $0$ is a regular singular point, we try solutions of the form $f(r)=r^\\sigma\\sum_na_nr^n$.\r\nBy routine work of substituting we get the indicial equation $\\sigma(\\sigma-1)+2\\sigma-l(l+1)=0$, hence $\\sigma=l$ or $\\sigma=-l-1$.\r\nThe latter case has to be discarded as we don't want singularity at $0$.\r\nTherefore $f(r)=r^l\\sum_na_nr^n$.\r\nAgain routine substitution work yields the recurrence\r\n$$a_n=\\frac{2\\nu(n+l)-\\beta}{n(n+2l+1)}a_{n-1}$$\r\nwhich determines the series completely up to a constant.\r\nThe same trick as before applies:\r\nIf the series does not terminate, then by estimating the order of growth of $(a_n)$ we find that the $g$ that we want will not be normalisable.\r\nTherefore the series must terminate.\r\nThis means that (for nonzero $a_0$) there exists some $n_{\\max{}}$ such that $a_{n_{\\max{}}}=0$ but $a_{n_{\\max{}}-1}\\neq0$ which has to satisfy\r\n$$2\\nu(n_{\\max{}}+l)-\\beta=0\\implies \\nu=\\frac{\\beta}{2N},N=n_{\\max{}}+l$$\r\nby plugging in the respective definition, the energy levels are\r\n$$E=E_N=-\\frac{e^4m}{32\\pi^2\\epsilon_0^2\\hbar^2}\\frac{1}{N^2}$$\r\nSo the spectrum of energy levels is identical to what we obtained in the special case where the eigenfunctions are spherically symmetric.\r\nBut in this more general setting, the eigenvalues can have some other (non-spherically-symmetric) eigenfunctions.\r\nHow many of them?\r\nIt's not hard to see:\r\nFor each $N$, there are exactly\r\n$$D(N)=\\sum_{l=0}^{N-1}\\sum_{n=-l}^l1=\\sum_{l=0}^{N-1}(2l+1)=N^2$$\r\nmany different eigenfunctions.\r\nThis is called the degeneracy of the energy value $E_N$.\r\nSo the full spectrum of the eigenfunctions of the Hydrogen atom is then\r\n$$X_{N,l,m}(r,\\theta,\\phi)=\\xi^lL_{N,l}(\\xi)e^{-\\xi}Y_{l,m}(\\theta,\\phi),\\xi=\\frac{\\beta r}{2N}=\\frac{e^2mr}{4N\\pi\\epsilon_0\\hbar^2}$$\r\nwhere $L_{N,l}$ (whose coefficients are defined by our terminating series earlier) are called the generalised Laguerre polynomials and $Y_{l,m}$ are the spherical harmonics.\\\\\r\n$N=1,2,3,\\ldots$ are called the principal quantum numbers, $l=0,\\ldots,N-1$ are the total angular momentum quantum numbers and $m\\in\\{-l,\\ldots,l\\}$ are the azimuthal quantum numbers.\r\nThe Bohr model captured the case where $m=l\\simeq N>>1$.\r\nIn this case $L_3==m\\hbar\\simeq N\\hbar$ and $L=\\sqrt{L^2}=\\sqrt{l(l+1)\\hbar^2}\\simeq N\\hbar$.\\\\\r\nNote that due to the definition of the spherical harmonics, we have\r\n$$\\int_0^{2\\pi}\\int_{-1}^1\\int_0^\\infty |X_{N,l,m}(r,\\theta,\\phi)|^2r^2\\,\\mathrm dr\\mathrm d(\\cos\\theta)\\mathrm d\\phi=\\int_0^\\infty |g(r)|^2r^2\\,\\mathrm dr$$\r\nSo we define $P(r)|g(r)|^2r^2$ as the radial probability.\r\nAsymptotically,\r\n$$P(r)=r^2|g(r)|^2\\sim r^{2(l+1)}\\exp\\left( -\\frac{\\beta r}{2(l+1)} \\right)$$\r\nwhich, in the Bohr limit, just gives $r^{2N}\\exp(-\\beta r/N)$.\r\nBy differentiating, the stationary points of $P$ (i.e. the modes) are approximately at $r_{\\rm peak}\\simeq 2N^2/\\beta=N^2r_1$ which is the same as what we obtained using Bohr's model.\r\n\\subsection{Towards Periodic Table}\r\nIf we have a nucleus with charge $+ze$ and there are $z$ electrons around it which are treated as independent particles (so ignore any interactions betweem electrons like electromagnetism and gravity), then the eigenfunction can be seperated as $X(\\underline{x}_1,\\ldots,\\underline{x}_z)=X(\\underline{x}_1)\\cdots X(\\underline{x}_z)$ where each $X(\\underline{x}_i)$ is a rescaled solution for the Hydrogen atom.\r\nIts energy level is then the sum of energies of all electrons $E=\\sum_iE_i$.\r\nwhich works for small $z$, but the interaction force between electrons is growing when $z$ is large -- which is why we need to develop more theory in next year's Principle of Quantum Mechanics.", "meta": {"hexsha": "c6cad386bbe4bd4a552e6d7ab3dc0a16e8e7baf6", "size": 15667, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/3d.tex", "max_stars_repo_name": "david-bai-notes/IB-Quantum-Mechanics", "max_stars_repo_head_hexsha": "8689057b154bdd3fbc6c9270e023b87583904427", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/3d.tex", "max_issues_repo_name": "david-bai-notes/IB-Quantum-Mechanics", "max_issues_repo_head_hexsha": "8689057b154bdd3fbc6c9270e023b87583904427", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/3d.tex", "max_forks_repo_name": "david-bai-notes/IB-Quantum-Mechanics", "max_forks_repo_head_hexsha": "8689057b154bdd3fbc6c9270e023b87583904427", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 81.5989583333, "max_line_length": 411, "alphanum_fraction": 0.6677730261, "num_tokens": 5825, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427872638409, "lm_q2_score": 0.8333246035907933, "lm_q1q2_score": 0.7353488571638692}}
{"text": "\\subsubsection{Critically Damped ($\\Delta = 0$)}\r\nThis case isn't much more difficult.\r\nThe only difference is that because both roots $r_1$ and $r_2$ are $\\frac{-b}{2m}$, we need an extra $t$ term in the solution. So, out solution is\r\n\\begin{equation*}\r\n\ty = C_1e^{r_1 t} + C_2te^{r_2 t}.\r\n\\end{equation*}\r\n\\begin{center}\r\n\t\\includegraphics[width=0.5\\textwidth]{./higherOrder/freeVibrs/criticallydamped.png}\r\n\\end{center}\r\nSince both roots are once again negative,\r\n\\begin{equation*}\r\n\\lim\\limits_{t \\to 0}{C_1e^{r_1 t} + C_2te^{r_2 t}} = 0\r\n\\end{equation*}\r\nmeaning the mass's oscillation decays over time.", "meta": {"hexsha": "1f4fd181ad1b9aaf2019d4ccd268178a18a46b11", "size": 608, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/freeVibrs/critically_damped.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/higherOrder/freeVibrs/critically_damped.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/higherOrder/freeVibrs/critically_damped.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 43.4285714286, "max_line_length": 147, "alphanum_fraction": 0.7072368421, "num_tokens": 216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418116217417, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7353009247406992}}
{"text": "\\documentclass[11pt, oneside]{article}\n\n\\usepackage{preamble}\n\\addbibresource{../../shared/references.bib}\n\n\\usepackage{sets}\n\\usepackage{topological-spaces}\n\\usepackage{groups}\n\\usepackage{real-numbers}\n\n\\usepackage{complex-numbers}\n\n\\title{Complex Numbers}\n\\author{Arthur Ryman, {\\tt arthur.ryman@gmail.com}}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\nThis article contains Z Notation type declarations for the complex numbers, $\\C$, and some related objects.\nIt has been type checked by \\fuzz.\n\\end{abstract}\n\n\\section{Introduction}\n\nThe complex numbers, $\\C$, are foundational to many mathematical objects such as vector spaces and manifolds,\nbut are not built-in to Z Notation.\nThis article provides type declarations for $\\C$ and related objects so that they can be used and type checked in formal Z specifications.\n\nNo attempt has been made to provide complete, axiomatic definitions of all these objects since that would only be of use for proof checking.\nAlthough proof checking is highly desirable, it is beyond the scope of this article.\nThe type declarations given here are intended to provide a basis for future axiomatization.\n\n\\section{Complex Numbers}\n\nZ Notation does not predefine the set of complex numbers, so we define\nthem and operations on them here.\n\nAlthough complex number operations are displayed using the same symbols as the \nanalogous real number operations,\nthey are distinct mathematical objects.\nThis distinction is apparent to the \\fuzz\\ type-checker and should not cause confusion to the human reader\nbecause the underlying types of the objects will, as a rule, be clear from the context.\nVisually distinct symbols will be used in cases where confusion is possible.\n\n\\subsection{$COMPLEX$}\n\nA complex number can be thought of a pair of real numbers.\nHowever, it is not correct to view any pair of real numbers as a complex number.\nTherefore to denote a complex number we map a pair of real numbers\ninto the free type $COMPLEX$.\n\n\\begin{zed}\n\tCOMPLEX ::= complex \\ldata \\R \\cross \\R \\rdata\n\\end{zed}\n\nHere the function $complex$ is a constructor that constructs a\ncomplex number from a pair of real numbers.\n\n\\subsection{\\zcmd{C}}\n\nWe introduce the usual notation $\\C = COMPLEX$ for the set of complex numbers.\n\n\\begin{zed}\n\\C == COMPLEX\n\\end{zed}\n\n\\subsection{$Complex$}\n\nGiven real numbers $x$ and $y$, we can construct the complex number\n$z = complex(x,y)$.\nThe real numbers $x$ and $y$ are referred to as the \\textit{real} and \\textit{imaginary} parts of $z$.\nIt's useful to introduce the schema $Complex$ that relates the complex number $z$ to its\nreal and imaginary parts $x$ and $y$.\n\n\\begin{schema}{Complex}\n\tz : \\C \\\\\n\tx, y : \\R\n\\where\n\tz = complex(x, y)\n\\end{schema}\n\n\\subsection{$real\\_complex$}\n\nLet $real\\_complex(z)$ denote the real part $x$ of $z$.\n\n\\begin{zed}\n\treal\\_complex == \\{~ Complex @ z \\mapsto x ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{realC}}\n\nWe introduce the usual notation $x = \\realC(z)$ for the real part of $z$.\n\n\\begin{zed}\n\t\\realC == real\\_complex\n\\end{zed}\n\n\\subsection{$imag\\_complex$}\n\nLet $imag\\_complex(z)$ denote the imaginary part $y$ of $z$.\n\n\\begin{zed}\n\timag\\_complex == \\{~ Complex @ z \\mapsto y ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{imagC}}\n\nWe introduce the usual notation $y = \\imagC(z)$ for the imaginary part of $z$.\n\n\\begin{zed}\n\t\\imagC == imag\\_complex\n\\end{zed}\n\n\\subsection{$AddComplex$}\n\nWe can \\textit{add} the complex numbers $z_1$ and $z_2$ to give their sum $z'$.\nLet the schema $AddComplex$ denote this situation.\n\n\\begin{schema}{AddComplex}\n\tComplex_1 \\\\\n\tComplex_2 \\\\\n\tComplex'\n\\where\n\tx' = x_1 \\addR x_2 \\\\\n\ty' = y_1 \\addR y_2\n\\end{schema}\n\n\\subsection{$add\\_complex$}\n\nLet $add\\_complex(z_1, z_2)$ denote the result of adding $z_1$ and $z_2$.\n\n\\begin{zed}\n\tadd\\_complex == \\{~ AddComplex @ (z_1, z_2) \\mapsto z' ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{addC}}\n\nWe introduce the usual notation $z' = z_1 \\addC z_2$ for addition in $\\C$.\n\n\\begin{zed}\n\t(\\_ \\addC \\_) == add\\_complex\n\\end{zed}\n\n\\subsection{$zero\\_complex$}\n\nLet $zero\\_complex$ denote the \\textit{zero} of $\\C$.\n\n\\begin{zed}\n\tzero\\_complex == complex (\\zeroR, \\zeroR)\n\\end{zed}\n\n\\subsection{\\zcmd{zeroC}}\n\nWe introduce the usual notation $\\zeroC \\in \\C$ for the zero of $\\C$.\n\n\\begin{zed}\n\t\\zeroC == zero\\_complex\n\\end{zed}\n\n\\subsection{$NegComplex$}\n\nWe can \\textit{negate} the complex number $z$ to give its negative $z'$.\nLet the schema $NegComplex$ denote this situation.\n\n\\begin{schema}{NegComplex}\n\tComplex \\\\\n\tComplex'\n\\where\n\tx' = \\negR x\n\\also\n\ty' = \\negR y\n\\end{schema}\n\n\\subsection{$neg\\_complex(z)$}\n\nLet $neg\\_complex(z)$ denote the negative of $z$.\n\n\\begin{zed}\n\tneg\\_complex == \\{~ NegComplex @ z \\mapsto z' ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{negC}}\n\nWe introduce the usual notation $z' = \\negC z$ for the negative of $z$.\n\\begin{zed}\n\t\\negC == neg\\_complex\n\\end{zed}\n\n\\subsection{The Additive Abelian Group $\\C$}\n\n\\begin{theorem}\n\nThe complex numbers $\\C$ form an Abelian group under addition.\n\n\\begin{zed}\n(\\_ \\addC \\_) \\in \\abgroup \\C\n\\also\n\\zeroC = identity\\_element(\\_ \\addC \\_)\n\\also\n\\negC = inverse\\_operation(\\_ \\addC \\_)\n\\end{zed}\n\n\\end{theorem}\n\n\\subsection{$SubComplex$}\n\nWe can \\textit{subtract} the complex number $z_1$ from $z_2$\nto give their difference $z'$.\nLet the schema $SubComplex$ denote this situation.\n\n\\begin{schema}{SubComplex}\n\tComplex_1 \\\\\n\tComplex_2 \\\\\n\tComplex'\n\\where\n\tx' = x_1 \\subR x_2\n\\also\n\ty' = y_1 \\subR y_2\n\\end{schema}\n\n\\subsection{$sub\\_complex$}\n\nLet $sub\\_complex(z_1, z_2)$ denote the difference of $z_1$ and $z_2$.\n\n\\begin{zed}\n\tsub\\_complex == \\{~ SubComplex @ (z_1, z_2) \\mapsto z' ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{subC}}\n\nWe introduce the usual notation $z' = z_1 \\subC z_2$ for subtraction in $\\C$.\n\n\\begin{zed}\n\t(\\_ \\subC \\_) == sub\\_complex\n\\end{zed}\n\n\\subsection{$nonzero\\_complex$}\n\nLet $nonzero\\_complex$ denote the set of nonzero complex numbers.\n\n\\begin{zed}\n\tnonzero\\_complex == \\C \\setminus \\{ \\zeroC \\}\n\\end{zed}\n\n\\subsection{\\zcmd{Cnz}}\n\nWe introduce the usual notation $\\Cnz \\subseteq \\C$ to denote the set of nonzero complex numbers,\nalso referred to as the \\textit{punctured complex number plane}.\n\n\\begin{zed}\n\t\\Cnz == nonzero\\_complex\n\\end{zed}\n\n\\subsection{$MulComplex$}\n\nWe can \\textit{multiply} the complex numbers $z_1$ times $z_2$ to give their product $z'$.\nLet the schema $MulComplex$ denote this situation.\n\n\\begin{schema}{MulComplex}\n\tComplex_1 \\\\\n\tComplex_2 \\\\\n\tComplex'\n\\where\n\tx' = x_1 \\mulR x_2 \\subR y_1 \\mulR y_2\n\\also\n\ty' = x_1 \\mulR y_2 \\addR y_1 \\mulR x_2\n\\end{schema}\n\n\\subsection{$mul\\_complex$}\n\nLet $mul\\_complex(z_1, z_2)$ denote $z_1$ multiplied by $z_2$.\n\n\\begin{zed}\n\tmul\\_complex == \\{~ MulComplex @ (z_1, z_2) \\mapsto z' ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{mulC}}\n\nWe introduce the usual notation $z' = z_1 \\mulC z_2$ for multiplication in $\\C$.\n\n\\begin{zed}\n\t(\\_ \\mulC \\_) == mul\\_complex\n\\end{zed}\n\n\\subsection{$MulNonzeroComplex$}\n\nWe can restrict multiplication in $\\C$ to $\\Cnz$.\nLet the schema $MulNonzeroComplex$ denote this situation.\n\n\\begin{schema}{MulNonzeroComplex}\n\tMulComplex \\\\\n\\where\n\tz_1 \\in \\Cnz\n\\also\n\tz_2 \\in \\Cnz\n\\end{schema}\n\n\\subsection{$mul\\_nonzero\\_complex$}\n\nLet $mul\\_nonzero\\_complex(z_1, z_2)$ denote the product of nonzero complex numbers.\n\n\\begin{zed}\n\tmul\\_nonzero\\_complex == \\{~ MulNonzeroComplex @ (z_1, z_2) \\mapsto z' ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{mulCnz}}\n\nWe introduce the usual notation $z' = z_1 \\mulCnz z_2$ to denote the product.\n\n\\begin{zed}\n\t(\\_ \\mulCnz \\_) == mul\\_nonzero\\_complex\n\\end{zed}\n\n\\subsection{$one\\_complex$}\n\nLet $one\\_complex$ denote the multiplicative unit in $\\C$.\n\n\\begin{zed}\n\tone\\_complex == complex(\\oneR, \\zeroR)\n\\end{zed}\n\n\\subsection{\\zcmd{oneC}}\n\nWe introduce the usual notation $\\oneC \\in \\C$ for the unit of $\\C$.\n\n\\begin{zed}\n\t\\oneC == one\\_complex\n\\end{zed}\n\n\\subsection{$InvNonzeroComplex$}\n\nWe can \\textit{invert}\nthe nonzero complex number $z$ to get its inverse or reciprocal $z'$.\nLet the schema $InvNonzeroComplex$ denote this situation.\n\n\\begin{schema}{InvNonzeroComplex}\n\tz, z' : \\Cnz\n\\where\n\tz \\mulCnz z' = \\oneC\n\\end{schema}\n\n\\subsection{$inv\\_nonzero\\_complex$}\n\nLet $z' = inv\\_nonzero\\_complex(z)$ denote the inverse of $z$.\n\n\\begin{zed}\n\tinv\\_nonzero\\_complex == \\{~ InvNonzeroComplex @ z \\mapsto z' ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{invCnz}}\n\nWe introduce the usual notation $z' = z \\invCnz$ for the inverse.\n\n\\begin{zed}\n\t(\\_ \\invCnz) == inv\\_nonzero\\_complex\n\\end{zed}\n\n\\subsection{$DivNonzeroComplex$}\n\nWe can \\textit{divide} the nonzero complex numbers $z_1$ by $z_2$ to get their quotient $z'$.\nLet the schema $DivNonzeroComplex$ denote this situation.\n\n\\begin{schema}{DivNonzeroComplex}\n\tz_1, z_2, z' : \\Cnz\n\\where\n\tz_1 = z' \\mulCnz z_2\n\\end{schema}\n\n\\subsection{$div\\_nonzero\\_complex$}\n\nLet $z' = div\\_nonzero\\_complex(z_1, z_2)$ denote $z_1$ divided by $z_2$.\n\n\\begin{zed}\n\tdiv\\_nonzero\\_complex == \\{~ DivNonzeroComplex @ (z_1, z_2) \\mapsto z' ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{divCnz}}\n\nWe introduce the usual notation $z_1 \\divCnz z_2$ to denote division.\n\n\\begin{zed}\n\t(\\_ \\divCnz \\_) == div\\_nonzero\\_complex\n\\end{zed}\n\n\\subsection{The Multiplicative Abelian Group $\\Cnz$}\n\n\\begin{theorem}\nThe nonzero complex numbers $\\Cnz$ form an Abelian group under multiplication.\n\n\\begin{zed}\n(\\_ \\mulCnz \\_) \\in \\abgroup \\Cnz\n\\also\n\\oneC = identity\\_element(\\_ \\mulCnz \\_)\n\\also\n(\\_ \\invCnz) = inverse\\_operation(\\_ \\mulCnz \\_)\n\\end{zed}\n\n\\end{theorem}\n\n\\subsection{$NormComplex$}\n\nThe $norm$ of a complex number $z$ is a non-negative real number $r$\nequal to the Euclidean length of its underlying pair of real numbers regarded\nas a vector in the Euclidean plane.\nLet the schema $NormComplex$ denote this situation.\n\n\\begin{schema}{NormComplex}\n\tComplex \\\\\n\tr : \\R\n\\where\n\tr = \\sqrtR(x \\mulR x \\addR y \\mulR y)\n\\end{schema}\n\n\\subsection{$norm\\_complex$}\n\nLet $r = norm\\_complex(z)$ be the norm of $z$.\n\n\\begin{zed}\n\tnorm\\_complex == \\{~ NormComplex @ z \\mapsto r ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{normC}}\n\nWe introduce the usual notation $r = \\normC(z)$ to denote the norm of $z$.\n\n\\begin{zed}\n\t\\normC == norm\\_complex\n\\end{zed}\n\n\\printbibliography\n\n\\end{document}", "meta": {"hexsha": "cdd4ab8805a893496b604c2bf3101df45ab81a8e", "size": 10120, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "articles/complex-numbers/complex-numbers.tex", "max_stars_repo_name": "agryman/mathz", "max_stars_repo_head_hexsha": "a516a20936e1ed7b9f07c546eee7aacf1831de65", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-30T08:06:17.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-30T08:06:17.000Z", "max_issues_repo_path": "articles/complex-numbers/complex-numbers.tex", "max_issues_repo_name": "agryman/mathz", "max_issues_repo_head_hexsha": "a516a20936e1ed7b9f07c546eee7aacf1831de65", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "articles/complex-numbers/complex-numbers.tex", "max_forks_repo_name": "agryman/mathz", "max_forks_repo_head_hexsha": "a516a20936e1ed7b9f07c546eee7aacf1831de65", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.2643678161, "max_line_length": 140, "alphanum_fraction": 0.7102766798, "num_tokens": 3206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070011518829, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7352660213215825}}
{"text": "\\chapter{Metrics}\n\nA metric is a function that measures the distance between two points.\n\nLet \\(S\\) be a space.\n\nLet \\(d : S \\to S \\to \\Real\\) be a metric of \\(S\\).\n\nThus \\(d(x,y)\\) is the distance from \\(x\\) to \\(y\\).\n\nThus \\(d\\) should satisfy \\(d(x,y) = d(y,x)\\).\n\n\\section*{Euclidean metrics of real tuple spaces}\n\nLet \\(d : \\Real^n \\to \\Real^n \\to \\Real\\).\nDefine \\(d(x,y) = \\sqrt{\\sum_{k=1}^n (x_k - y_k)^2}\\).\nThen \\(d\\) we say that \\(d\\) an Euclidean metric of \\(\\Real^n\\).\n\n\\section{Norms and metrics induce each other}\n\nA norm induces a metric.\nA metric induces a norm.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Metric_(mathematics)\\#Metrics_on_vector_spaces}}\n\n\\section{Geodesics}\n\nThe distance between two points is the length of the shortest curve that connects them.\n\n\\section{Measuring distances on curved spaces}\n\nExample: circle\n\nDraw a circle with center \\(C\\).\nDraw two points \\(P\\) and \\(Q\\) on the circle's perimeter.\nThen \\(CPQ\\) forms a sector whose arc is \\(PQ\\).\nThe distance from \\(P\\) to \\(Q\\) is that arc's length.\n\nEvery point the circle can be described by a real number \\(a\\).\nThis real number is the \\enquote{angle} of the point.\n\n\\(d(a,b) = r \\cdot (b-a)\\).\n\nTODO define a metric for a curve described by \\(x : \\Real \\to \\Real^2\\).\n\nA curve is in length-normal formulation (???)\niff \\( L(t,u) = \\abs{t-u} \\).\nThen the metric is \\(d(x,y) = L(f^{-1}(x), f^{-1}(y))\\).\n\nWe can also define.\n\\(d(a,b) = b-a\\).\n\n\\footnote{\\url{https://en.wikipedia.org/wiki/Intrinsic_metric}}\n\nDraw a sphere with center \\(C\\).\nDraw two points \\(P\\) and \\(Q\\) on the sphere.\n\n\\section{Generalizing shortest paths into geodesics}\n\n\\subsection{Understanding the shortest curve connecting two points}\n\nThe concept of geodesic arises naturally when we realize\nthat \\emph{straightness} is defined in terms of \\emph{distance}.\nIf we define a \\emph{straight} line segment as the \\emph{shortest path} connecting its endpoints,\nthen the concept of geodesics arises naturally by redefining what \\emph{shortest} means.\n\nIn Euclidean geometry, the shortest path connecting two points is a line segment.\nRemember that a line is a straight curve.\n\nWe can also write \\emph{shortest} as \\emph{having minimum distance},\nto clarify the connection between straightness and distance.\n\nA curve segment connecting two points is a \\emph{geodesic}\niff the length of the curve segment is the distance between the two points.\n\nIf \\(x\\) is a point on a geodesic,\nthen every point \\(x + h\\) satisfying \\(\\norm{h} = d(x,x+h)\\) is also on the geodesic.\nCan this equation be used to derive the equation of a geodesic?\nThe definitions of the norm \\(\\norm{\\cdot}\\) and the distance \\(d\\) depend on the ambient space.\n\nThus geodesic is a generalization of straightness.\nBy \\emph{straight}, we mean \\emph{shortest} (having minimal length).\nEvery line is a geodesic.\n\nA geodesic is a locally length-minimizing curve.%\n\\footnote{\\url{http://mathworld.wolfram.com/Geodesic.html}}\n\nIn metric geometry, a geodesic is a curve which is everywhere locally a distance minimizer.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Geodesic\\#Metric_geometry}}\n\n\\subsection{Finding the equation of a geodesic}\n\nIf the curve is given by parametric equation,\nthen a geodesic equation can be obtained by minimizing the arc length of the curve?%\n\\footnote{\\url{http://mathworld.wolfram.com/Geodesic.html}}\n\n\\section{Metric tensor}\n\nWe have always implicitly assumed that a space defines distance uniformly,\nthe same everywhere, that is, we have always assumed the isometry \\(d(x+h,y+h) = d(x,y)\\) for all \\(h\\).\n\n\\footnote{\\url{https://en.wikipedia.org/wiki/Metric_tensor}}%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Arc_length\\#Generalization_to_.28pseudo-.29Riemannian_manifolds}}\n\nA metric tensor is a metric in tensor form?\nA rank-\\((a,b)\\) tensor is a function with \\(a+b\\) parameters?\n\nDot product generalizes to inner product.\n\nTyping rule:\nif \\( a, b : V \\), then \\( \\langle a, b \\rangle : \\Real \\).\nAn inner product is a function with type \\( V \\to V \\to \\Real \\).\n\nIn Euclidean vector spaces,\n\\( \\langle x, y \\rangle = x \\cdot y \\).\nThe dot product is the inner product of Euclidean vector spaces.\n\nAn inner product defines orthogonality. Two vectors are orthogonal iff \\( \\langle x, y \\rangle = 0 \\).\nAn inner product also defines the length of a vector.\n\\[\n\\norm{x} = \\sqrt{\\langle x, x \\rangle}\n\\]\n\nTissot's indicatrices visualize a metric tensor by scattering\nmany circles throughout a space\nso that we can see how the space's metric tensor distorts them.\nThis method tells us how much our map is lying to us.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Tissot\\%27s_indicatrix}}\n\\disabled{}%vim indent bug\n\n\\( d(0,x) = \\norm{x} \\) only in Euclidean geometry?\n\nPerhaps we should digress to mapmaking/cartography?\n\nMotivate metric tensor using cartography?\nThe surface of the Earth is a sphere.\nHow do we project its surface to a flat paper?\nHow do we draw a map?\n\nInner product generalizes to metric tensor?\n\nA metric tensor's type is also \\( V \\to V \\to \\Real \\).\n\nMetric on half circle \\( \\{ (r \\cos t, r \\sin t) ~|~ t \\in [0,\\pi] \\} \\).\n\n\\section{Wrong-but-useful is better than right-but-useless}\n\nAncient people believe that the Earth is a plate.\n\nMost people in 2017 believe that the Earth is a ball.\n\nThe Earth is an oblate spheroid.\nIt's a slightly flattened sphere.\nIt's wider on the equator.\n\nThe Earth is irregular.\n\nNote how the statements become more correct, less general, and less applicable.\n\nEarth is a plate, ball, or spheroid, depending on what we are doing.\nIf we're driving a car, the Earth is a plate.\nIf we're trying to introduce differential geometry by analogy with the Earth, it's a ball.\nIf we are comparing the gravitational pull in many places,\nthen the Earth is a spheroid.\nIf we are trying to one-up someone else, then the Earth is irregular;\nit has mountains and lakes.\n\nWe're abusing language.\nWhat do we mean by \\enquote{is}?\n\nWrong-but-useful is better than right-but-useless.\n", "meta": {"hexsha": "bd53af6505fa1f785122811f0a2c16cabec53165", "size": 5987, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/metric.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/physics/metric.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/physics/metric.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 35.0116959064, "max_line_length": 110, "alphanum_fraction": 0.7275764156, "num_tokens": 1610, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7352642606260968}}
{"text": "\\chapter*{Appendix I}\n\\addcontentsline{toc}{chapter}{Appendix I}\n\\label{chapter:appendix1}\n\n\\textbf{Ulceration risk of pressure-time relation}\n\nBased on pressure-time cell death experiment, this equation shows the higher threshold of constant pressure at a certain time T\n\\begin{equation}\n    P(T) = \\frac{P_{max}-P_{min}}{1 + e^{\\lambda(T-T_0)}} + P_{min}\n\\end{equation}\n\nHere,\n\n\\begin{align*}\n    P_{max} &= 31 kPa\\\\\n    P_{min} &= 8 kPa\\\\\n    \\lambda &= 0.15 min^{-1}\\\\\n    T_0     &= 95 min\n\\end{align*}\n\n(These values are based on experiment expect for $T_0$ which is arbitrary)\n\nFollowing equation shows the maximum safe time ($T_{max}$) for particular pressure value.  \n\\begin{equation}\n    T_{max}(P) = \n    \\begin{cases}\n        \\infty & P < P_{min}\\\\\n        0  & P > P_{max}\\\\\n        T_0 + \\frac{1}{\\lambda}\\left( \\frac{P_{max}-P_{min}}{P-P_{min}} - 1 \\right) & P_{min} < P < P_{max}\n    \\end{cases}\n\\end{equation}\n\nThe risk of the particular pressure value is given by this equation\n\\begin{equation}\n    \\delta R = \\frac{\\delta t}{T_{max}(P)}\n\\end{equation}\n\nCumulative risk is calculated in the following way.\n\n\\begin{enumerate}\n    \\item Sum risk when pressure is greater than $P_{min}$.\n    \\item Set total risk to zero when pressure becomes lesser than $P_{min}$.\n\\end{enumerate}\n\n\nAccording to this risk metric it is shown that supine posture has higher risk. It further shows that the supine will generate same risk as left or right postures with half of period.\n\n\\chapter*{Appendix II}\n\\addcontentsline{toc}{chapter}{Appendix II}\n\\label{chapter:appendix2}\n\nSchematic of the pressure mat\n\\input{figs/schematic1.tex}\n\n\n% \\textbf{Mean Field Algorithm} \\\\\n% \\input{figs/algo.tex}\n\n\n% \\chapter*{Appendix III}\n% \\addcontentsline{toc}{chapter}{Appendix III}\n% \\label{chapter:appendix3}\n\n% ATMega code\n\n", "meta": {"hexsha": "31262636cf023c7b9701991913752efb1340687b", "size": 1815, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/Appendix.tex", "max_stars_repo_name": "ThamaluM/PrevelcerDoc", "max_stars_repo_head_hexsha": "62bb85f823b68feca499f3d9c0383c9cc62fea69", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/Appendix.tex", "max_issues_repo_name": "ThamaluM/PrevelcerDoc", "max_issues_repo_head_hexsha": "62bb85f823b68feca499f3d9c0383c9cc62fea69", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/Appendix.tex", "max_forks_repo_name": "ThamaluM/PrevelcerDoc", "max_forks_repo_head_hexsha": "62bb85f823b68feca499f3d9c0383c9cc62fea69", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5, "max_line_length": 182, "alphanum_fraction": 0.6887052342, "num_tokens": 556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7352183834099022}}
{"text": "\\subsubsection{Complex Roots}\r\n\\noindent\r\nAlthough the previous two theorems already cover complex roots, we can simplify solutions that have complex roots into functions we more easily understand.\\\\\r\n\r\n\\begin{theorem}\r\n\tIf an auxiliary equation has roots $\\alpha \\pm \\beta i$, then $C_1e^{\\alpha x}\\cos{(\\beta x)}$ and  $C_2e^{\\alpha x}\\sin{(\\beta x)}$ are fundamental solutions.\r\n\\end{theorem}\r\n\\begin{proof}\r\n\tThe two corresponding fundamental solutions are\r\n\t\\begin{equation*}\r\n\t\tC_1e^{(\\alpha + \\beta i)x} \\text{, } C_2e^{(\\alpha - \\beta i)x}\r\n\t\\end{equation*}\r\n\tso the part of the general solution for these two fundamental solutions are\r\n\t\\begin{equation*}\r\n\t\tC_1e^{(\\alpha + \\beta i)x} + C_2e^{(\\alpha - \\beta i)x}.\r\n\t\\end{equation*}\r\n\tUsing Euler's formula, we can also write this as\r\n\t\\begin{equation*}\r\n\t\tC_1 e^{\\alpha x}\\left( \\cos{(\\beta t)} + i\\sin{(\\beta x)} \\right) + C_2e^{\\alpha x}\\left( \\cos{(-\\beta x)} + i\\sin{(-\\beta x)} \\right).\r\n\t\\end{equation*}\r\n\tUsing the fact that $\\sin{(-x)} = -\\sin{x}$, $\\cos{(-x)} = -\\cos{x}$ and separating into real and imaginary parts,\r\n\t\\begin{equation*}\r\n\t\t = \\left[ C_1e^{\\alpha x}\\cos{(\\beta x)} + C_2e^{\\alpha x}\\cos{(\\beta x)} \\right] + i\\left[ C_1e^{\\alpha x}\\sin{(\\beta x)} - C_2e^{\\alpha x}\\sin{(\\beta x)} \\right].\r\n\t\\end{equation*}\r\n\tSimplifying \\footnote{\\label{note1}In this step the values of $C_1$ and $C_2$ might have changed, but they are still constants.},\r\n\t\\begin{equation*}\r\n\t\t= e^{\\alpha x}\\left(C_1\\cos{(\\beta x)} + iC_2\\sin{(\\beta x)}\\right).\r\n\t\\end{equation*}\r\n\tAt this point, we need to consider if the constants are real or imaginary.\r\n\tWe would then take the real part as a fundamental solution.\\\\\r\n\tIf they are both real, then a fundamental solution is\\footnote{See footnote \\ref{note1}}\r\n\t\\begin{equation*}\r\n\t\tC_1e^{\\alpha x}\\cos{(\\beta x)}\r\n\t\\end{equation*}\r\n\twhere $C_1$ is a real constant.\r\n\tIf they are both imaginary, the a fundamental solution is\\footnote{See footnote \\ref{note1}}\r\n\t\\begin{equation*}\r\n\t\tC_2e^{\\alpha x}\\sin{(\\beta x)}\r\n\t\\end{equation*}\r\n\twhere $C_2$ is a real constant.\r\n\\end{proof}\r\n\r\n\\noindent\r\nIf complex roots are repeated, we just add the appropriate number of powers of $x$ in front of both the $\\sin{(\\beta x)}$ and $\\cos{(\\alpha a)}$ parts.\r\n\\pagebreak % It looked weird having the example start and then the footnote immediately after, so now the example starts on the next page\r\n\r\n\\begin{example}\r\n\tFind the general solution to the following differential equation.\r\n\t\\begin{equation*}\r\n\t\ty^{(4)} + 2y^{\\prime\\prime} + y = 0\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nFirst we extract the auxiliary equation and find its roots.\r\n\\begin{equation*}\r\n\tr^4 + 2r^2 + 1 = 0 \\implies r = i (\\text{double root}), -i (\\text{double root}).\r\n\\end{equation*}\r\nSince we have complex roots $0 \\pm 1i$, we know that the following are fundamental solutions\r\n\\begin{equation*}\r\n\tC_1e^{0x}\\cos{1x} \\to C_1\\cos{x} \\text{ and } C_2e^{0x}\\sin{1x} \\to C_2\\sin{x}.\r\n\\end{equation*}\r\nSince both roots are double roots the following are also fundamental solutions:\r\n\\begin{equation*}\r\n\tC_3x\\cos{x} \\text{ and } C_4x\\sin{x}.\r\n\\end{equation*}\r\nSo, the general solution is\r\n\\begin{equation*}\r\n\ty = C_1\\cos{x} + C_2\\sin{x} + C_3x\\cos{x} + C_4x\\sin{x}.\r\n\\end{equation*}", "meta": {"hexsha": "c16922fb8abc0d050a695e46cc0b69d2ab04cd8e", "size": 3254, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/constCoeffs/complexRoots.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/higherOrder/constCoeffs/complexRoots.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/higherOrder/constCoeffs/complexRoots.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 47.1594202899, "max_line_length": 167, "alphanum_fraction": 0.6742470805, "num_tokens": 1103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7350986894794939}}
{"text": "%!TEX root = ../gfkg.tex\n\\subsection{Chapter 1}\n\\begin{p}\n{Let $\\vec{k}\\in\\R^3$ and lt $\\omega=|\\vec{k}|$. Fix $\\vec{E}\\in\\mathbb{C}^3$ with \n$\\vec{k}\\cdot\\vec{E}=0$ and $\\vec{k}\\times\\vec{E}=i\\omega\\vec{E}$. Show that \n$\\vec{\\mathcal{E}}(t,\\vec{x})=\\vec{E}e^{-i(\\omega t-\\vec{k}\\cdot\\vec{x})}$ satisfies the\nvacuum Maxwell equations.}\n\\end{p}\n{...}\n", "meta": {"hexsha": "f847abdd51f13059503dd3bd0a9ec7fd74c3c640", "size": 350, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/I1.tex", "max_stars_repo_name": "joerenes/Baez-Muniain-solutions", "max_stars_repo_head_hexsha": "e1e38de9acab877bc4200af59c7910d42de748ca", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-04-13T12:10:03.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-19T18:18:34.000Z", "max_issues_repo_path": "src/I1.tex", "max_issues_repo_name": "joerenes/Baez-Muniain-solutions", "max_issues_repo_head_hexsha": "e1e38de9acab877bc4200af59c7910d42de748ca", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-04-13T12:15:30.000Z", "max_issues_repo_issues_event_max_datetime": "2017-04-13T20:19:44.000Z", "max_forks_repo_path": "src/I1.tex", "max_forks_repo_name": "joerenes/Baez-Muniain-solutions", "max_forks_repo_head_hexsha": "e1e38de9acab877bc4200af59c7910d42de748ca", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.0, "max_line_length": 88, "alphanum_fraction": 0.5971428571, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.735098684847711}}
{"text": "\\subsection{$QR$ factorization}\n\nIn this section, a reliable factorization of matrices is studied. Called the $QR$ factorization of a matrix, it \\textit{always} exists. While much can be said about the $QR$ factorization, this section will be limited to real matrices. Therefore we assume the dot product used below is the usual dot product. We begin with a definition.\n\n\\begin{definition}{$QR$ factorization}{qr-factorization}\nLet $A$ be a real $m\\times n$-matrix. Then a $QR$ factorization of $A$ consists\nof two matrices, $Q$ orthogonal and $R$ upper\ntriangular, such that $A=QR$.\\index{QR factorization}\n\\end{definition}\n\nThe following theorem claims that such a factorization exists.\n\n\\begin{theorem}{Existence of $QR$ factorization}{existence-qr}\nLet $A$ be any real $m\\times n$-matrix with linearly independent columns. Then there exists an orthogonal\nmatrix $Q$ and an upper triangular matrix $R$ having non-negative entries\non the main diagonal such that\n\\begin{equation*}\nA=QR\n\\end{equation*}\n\\end{theorem}\n\nThe procedure for obtaining the $QR$ factorization for any matrix $A$ is as follows.\n\n\\begin{procedure}{$QR$ factorization}{qr-factorization}\nLet $A$ be an $m \\times n$-matrix given by $A = \\begin{mymatrix}{cccc}\nA_1 & A_2 & \\cdots & A_n\n\\end{mymatrix}$ where the $A_i$ are the linearly independent columns of $A$.\n\\begin{enumerate}\n\\item\nApply the Gram-Schmidt Process~\\ref{algo:gram-schmidt-algorithm} to the columns of $A$, writing $B_i$ for the resulting columns.\n\n\\item\nNormalize the $B_i$, to find $C_i = \\frac{1}{\\norm{B_i}} B_i$.\n\n\\item\nConstruct the orthogonal matrix $Q$ as $Q=\\begin{mymatrix}{cccc}\nC_1 & C_2 & \\cdots & C_n\n\\end{mymatrix}$.\n\n\\item\nConstruct the upper triangular matrix $R$ as\n\\[ R =\n\\begin{mymatrix}{ccccc}\n\\norm{B_1} & A_2 \\dotprod C_1 & A_3 \\dotprod C_1 & \\cdots & A_n \\dotprod C_1 \\\\\n0 & \\norm{B_2} & A_3 \\dotprod C_2 & \\cdots & A_n \\dotprod C_2 \\\\\n0 & 0 & \\norm{B_3} & \\cdots & A_n \\dotprod C_3 \\\\\n\\vdots & \\vdots & \\vdots & & \\vdots \\\\\n0 & 0 & 0 & \\cdots & \\norm{B_n}\n\\end{mymatrix}\n\\]\n\n\\item\nFinally, write $A=QR$ where $Q$ is the orthogonal matrix and $R$ is the upper triangular matrix obtained above.\n\\end{enumerate}\n\\end{procedure}\n\nNotice that $Q$ is an orthogonal matrix as the $C_i$ form an orthonormal set. Since $\\norm{B_i} > 0$ for all $i$ (since the length of a vector is always positive), it follows that $R$ is an upper triangular matrix with positive entries on the main diagonal.\n\nConsider the following example.\n\n\\begin{example}{Finding a $QR$ factorization}{qr-factorization}\nLet \\[\nA = \\begin{mymatrix}{rr}\n1 & 2 \\\\\n0 & 1 \\\\\n1 & 0\n\\end{mymatrix}\n\\]\nFind an orthogonal matrix $Q$ and upper triangular matrix $R$ such that $A=QR$.\n\\end{example}\n\n\\begin{solution}\nFirst, observe that $A_1$, $A_2$, the columns of $A$, are linearly independent. Therefore we can use the Gram-Schmidt Process to create a corresponding orthogonal set $\\set{B_1, B_2 }$ as follows:\n\\begin{eqnarray*}\nB_1 &=& A_1 = \\begin{mymatrix}{r}\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} \\\\\nB_2 &=& A_2 - \\frac{A_2 \\dotprod B_1}{\\norm{B_1} ^2} B_1 \\\\\n&=& \\begin{mymatrix}{r}\n2 \\\\\n1 \\\\\n0\n\\end{mymatrix}\n- \\frac{2}{2} \\begin{mymatrix}{r}\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} \\\\\n&=&\n\\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n-1\n\\end{mymatrix}\n\\end{eqnarray*}\n\nNormalize each vector to create the set $\\set{C_1, C_2 }$ as follows:\n\\begin{eqnarray*}\nC_1 &=& \\frac{1}{\\norm{B_1}} B_1 = \\frac{1}{\\sqrt{2}}  \\begin{mymatrix}{r}\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} \\\\\nC_2 &=& \\frac{1}{\\norm{B_2}} B_2 = \\frac{1}{\\sqrt{3}} \\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n-1\n\\end{mymatrix}\n\\end{eqnarray*}\n\nNow construct the orthogonal matrix $Q$ as\n\\begin{eqnarray*}\nQ &=& \\begin{mymatrix}{cccc}\nC_1 & C_2 & \\cdots & C_n\n\\end{mymatrix} \\\\\n&=& \\begin{mymatrix}{rr}\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}} & \\vspace{0.05in}\\frac{1}{\\sqrt{3}} \\\\\n0  & \\vspace{0.05in}\\frac{1}{\\sqrt{3}} \\\\\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}} & -\\vspace{0.05in}\\frac{1}{\\sqrt{3}}\n\\end{mymatrix}\n\\end{eqnarray*}\n\nFinally, construct the upper triangular matrix $R$ as\n\\begin{eqnarray*}\nR &=&\n\\begin{mymatrix}{cc}\n\\norm{B_1} & A_2 \\dotprod C_1  \\\\\n0 & \\norm{B_2}\n\\end{mymatrix} \\\\\n&=&\n\\begin{mymatrix}{cc}\n\\sqrt{2} & \\sqrt{2} \\\\\n0 & \\sqrt{3} \\\\\n\\end{mymatrix}\n\\end{eqnarray*}\n\nIt is left to the reader to verify that $A=QR$.\n\\end{solution}\n", "meta": {"hexsha": "00f9ab8a3133b3aa61c2593f572a468ae602b45e", "size": 4267, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryOrthogonalityQRFactorization.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/spectraltheoryOrthogonalityQRFactorization.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/spectraltheoryOrthogonalityQRFactorization.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 30.2624113475, "max_line_length": 336, "alphanum_fraction": 0.6871338177, "num_tokens": 1535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8774767810736693, "lm_q1q2_score": 0.7349920620750419}}
{"text": "\n\\subsection{Boundedness theorem}\n\nIf \\(f(x)\\) is closed and continuous in \\([a,b]\\) then \\(f(x)\\) is bounded by \\(m\\) and \\(M\\). That is:\n\n\\(\\exists m \\in \\mathbb{R} \\exists M\\in \\mathbb{R}\\forall x\\in [a,b](m<f(x)<M\\)\n\n", "meta": {"hexsha": "6c80f75b5436f06af3f7e33145ca3beb1c6164f1", "size": 221, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/propertiesFunctionsLimits/02-03-bounded.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/propertiesFunctionsLimits/02-03-bounded.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/propertiesFunctionsLimits/02-03-bounded.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.625, "max_line_length": 103, "alphanum_fraction": 0.5972850679, "num_tokens": 84, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896671963206, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.734962141855801}}
{"text": "\\section{Neural Networks}\n\\begin{frame}{\\insertsec}\n\t\\input{drawings/neural_network.tikz.tex}\n\\end{frame}\n\n\\subsection{Parameters}\n\\begin{frame}{\\insertsubsec}\n    \\begin{columns}[t]\n        \\column{.6\\textwidth}\n        \\begin{itemize}\n            \\item $l$: Current layer\n            \\item $w_{i, j}^{[l]}$: Weight from unit $j$ to $i$ at layer $l$\n            \\item $b_{i}^{[l]}$: Bias for unit $i$ at layer $l$\n            \\item $n^{[l]}$: Number of units in layer $l$\n            \\item $W^{[l]} \\in \\mathbb{R}^{n^{[l]} \\times n^{[l - 1]}}$: Weight matrix\n            \\item $\\bm{b}^{[l]} \\in \\mathbb{R}^{n^{[l]}}$: Bias\n            \\item $\n            \\begin{aligned}[t]\n                \\bm{a}^{[l]} &= g(W^{[l]}\\cdot \\bm{a}^{[l - 1]} + \\bm{b}^{[l]}) \\\\\n                \\bm{a}^{[l]} &\\in \\mathbb{R}^{n^{[l]}}\n            \\end{aligned}\n            $ Activations for layer $l$\n            \\item $g(x)$: Activation function\n        \\end{itemize}\n        \\column{.5\\textwidth}\n        \\centering\n        \\input{drawings/neural_activations.tikz.tex}\n    \\end{columns}\n\\end{frame}\n\\begin{frame}\n    \\begin{columns}\n        \\column{.6\\textwidth}\n        \\begin{block}{Cost function}\n            $$\n            J(\\bm{W}, \\bm{b}, \\hat{\\bm{y}}, \\bm{y}) = \n            \\frac{1}{m} \\sum_{i=1}^{m} \\mathcal{L}(\\hat{\\bm{y}}^{(i)}, \\bm{y}^{(i)})\n            $$\n        \\end{block}\n        \\begin{block}{Loss function}\n            $$\n            \\mathcal{L}(\\hat{\\bm{y}}, \\bm{y}) = ||\\hat{\\bm{y}} - \\bm{y}||^2\n            $$\n        \\end{block}\n        \\begin{block}{Parameters update}\n            \\begin{align*}\n            W^{[l]} &:= W^{[l]} - \\alpha \\cdot \\frac{\\partial J}{\\partial W^{[l]}} \\\\\n            \\bm{b}^{[l]} &:= \\bm{b}^{[l]} - \\alpha \\cdot \\frac{\\partial J}{\\partial \\bm{b}^{[l]}}\n            \\end{align*}\n        \\end{block}\n        \\column{.4\\textwidth}\n        To achieve better results at predicting $\\hat{\\bm{y}}$ \n        we have to minimize the cost function $J(\\bm{W}, \\bm{b}, \\hat{\\bm{y}}, \\bm{y})$.\n    \\end{columns}\n\\end{frame}\n\n\\subsection{Regularization}\n\\begin{frame}{\\insertsubsec}\n    To prevent overfitting add the weights to the cost function so we also try to minimize\n    big weights.\n\n    \\begin{align*}\n        J(\\bm{W}, \\bm{b}, \\hat{\\bm{y}}, \\bm{y}) &= \n        \\frac{1}{m} \\sum_{i = 1}^m \\mathcal{L}(\\hat{\\bm{y}}, \\bm{y}) + \n        \\frac{\\lambda}{2m} \\sum_{l=1}^L ||W^{[l]}||^2_F \\\\ \n        \\underbrace{||W^{[l]}||^2_F}_{\\text{Frobenius Norm}} &= \\sum_i \\sum_j (w_{ij}^{[l]}) \\\\ \n        dW^{[l]} &= \\text{from backprop } + \\frac{\\lambda}{m} \\cdot W^{[l]} \\\\\n        \\lambda &\\rightarrow \\text{Regularization parameter}\n    \\end{align*}\n\n    It cancels some effects from some units creating a simple model.\n\\end{frame}\n\\begin{frame}[fragile]{Dropout Regularization}\n    Go through each layer of the network and set some probability of elimination for each unit. \n    This is done for \\textbf{each sample}.\n\n    \\begin{figure}\n        \\begin{verbatim}\ndrop = np.random.randn(*a_prev.shape) < keep_prob\na_next = np.multiply(a_prev, drop)\na_next /= keep_prob\n        \\end{verbatim}\n        \\caption{Example using \\texttt{numpy}}\n    \\end{figure}\n\n    \\begin{alertblock}{Predictions during test time}\n        No dropout is used during test time since it wouldn't make sense.\n    \\end{alertblock}\n\\end{frame}\n\n\\begin{frame}{Adam optimization algorithm}\n    Training a NN is a minimization problem. In this case we always use gradient descent\n    to find the minimum. Sometimes the gradient can go too fast.\n\n    \\begin{onlyenv}<1>\n        \\begin{align*}\n            V_{dW} &= \\beta_1 V_{dW} + (1 - \\beta_1) \\cdot dW \\\\\n            S_{dW} &= \\beta_2 S_{dW} + (1 - \\beta_2) \\cdot dW^2 \\\\\n            W &:= W - \\alpha \\cdot \\frac{V_{dW}}{\\sqrt{S_{dW}} + \\varepsilon}\n        \\end{align*}\n    \\end{onlyenv}\n    \\begin{onlyenv}<2>\n        \\input{drawings/momentum.tikz.tex}\n    \\end{onlyenv}\n\\end{frame}\n\n\\subsection{Hyper-parameters}\n\\begin{frame}{\\insertsubsec}\n    \\begin{itemize}\n        \\item $m$: Mini-batch size\n        \\begin{itemize}\n            \\item $m = 1$: Stochastic gradient descent\n            \\item $m = $ set size: Batch gradient descent\n        \\end{itemize}\n        \\item $\\alpha$: Learning rate\n        \\begin{itemize}\n            \\item Learning rate decay \n            $\\alpha = \\frac{1}{1 + \\text{decay-rate}\\times \\text{epoch}} \\cdot \\alpha_0$\n            \\item Exponential decay\n            $\\alpha = 0.95^{\\alpha_0}$\n\n        \\end{itemize}\n        \\item $L$: Number of layers\n        \\item Number of iterations\n        \\item Number of hidden units\n    \\end{itemize}\n\\end{frame}\n", "meta": {"hexsha": "68808c39ebae1107ef5217437f8debfce743f809", "size": 4624, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LATEX/CNN Presentation/sections/02_neural_networks.tex", "max_stars_repo_name": "jmigual/FIB-TFG", "max_stars_repo_head_hexsha": "7551a3c13a985ee7eecf7a4f38a6ee4803b05ff1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-02T15:17:51.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-02T15:17:51.000Z", "max_issues_repo_path": "LATEX/CNN Presentation/sections/02_neural_networks.tex", "max_issues_repo_name": "jmigual/FIB-TFG", "max_issues_repo_head_hexsha": "7551a3c13a985ee7eecf7a4f38a6ee4803b05ff1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LATEX/CNN Presentation/sections/02_neural_networks.tex", "max_forks_repo_name": "jmigual/FIB-TFG", "max_forks_repo_head_hexsha": "7551a3c13a985ee7eecf7a4f38a6ee4803b05ff1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-10-23T08:11:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-23T08:11:28.000Z", "avg_line_length": 36.4094488189, "max_line_length": 97, "alphanum_fraction": 0.5395761246, "num_tokens": 1529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7348305329796518}}
{"text": "\\subsection{Row picture}\n\nInvolves viewing matrix as linear equations graphed on a line or plane. Take the example $A\\tb{x}=\\tb{b}$ below:\n\n\\[\\begin{bmatrix}\n        1&2&3\\\\\n        3&4&5\\\\\n        4&5&6\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        x\\\\y\\\\z\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n        8\\\\9\\\\10\n    \\end{bmatrix}\n\\]\n\nThis can be viewed as the following system:\n\n\\[\n    \\spalignsys{\n    1x + 2y + 3z = 8 ;\n    3x + 4y + 5z = 9 ;\n     4 + 5y + 6z = 10\n    }\n\\]\n\n\\subsection{Column picture}\n\nInvolves viewing this setup as a linear combination of column vectors. Take $A\\tb{x}=\\tb{b}$ again:\n\n\\[\n    x\\begin{bmatrix}\n        1\\\\3\\\\4\n    \\end{bmatrix}\n    +y\\begin{bmatrix}\n        2\\\\4\\\\5\n    \\end{bmatrix}\n    +z\\begin{bmatrix}\n        3\\\\5\\\\6\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n        8\\\\9\\\\10\n    \\end{bmatrix}.\n\\]\n\n\\subsection{Visualization in Space and Solutions}\n\n\\subsubsection{2D space}\n\nIn $\\R^2$, the equations form a line. Independent column vectors means infinite linear combinations of these to get\na set of $\\tb{b}$ in $\\R^2$. If one column vector is dependent on another, they are parallel and various\ncombinations of $\\tb{b}$ are on a line.\n\n\\subsubsection{3D space}\n\nThe equations form a plane in $\\R^3$. If column vectors independent, infinite linear combination of $\\tb{b}$\nexist in 3D space. If one vector is a scaled combination of another and the third is independent, then solutions lie\non a line. If all three are interdependent, the solution is on a line.\n", "meta": {"hexsha": "c681a56905f8217e9b5246d310984f07cf1ab02e", "size": 1512, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/1_row-col.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "linear-algebra/tex/1_row-col.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "linear-algebra/tex/1_row-col.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.3870967742, "max_line_length": 116, "alphanum_fraction": 0.6355820106, "num_tokens": 487, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7348305326797298}}
{"text": "\\section{Results}\n\n\\subsection{Step-by-step Example with OR}\nRecall the two bit function OR which returns $1$ if there\nis at least a single $1$ in the input and returns $0$ otherwise.\nTo understand Reichardt's formulation and the conversion\nto Boyd's standard form, consider as inputs to our tool\nthe case with function $f: D \\rightarrow E$ where\n$D \\subseteq {\\{0,1\\}}^2$ and $E =\\{OR(x): x \\in D \\}$.\nLet $F$ be the set of $(y,z)$ such that $f(y) \\neq f(z)$. In this\ncase, $F = \\{(00,01), (00,10), (00,11), (01,00), (10,00), (11,00)\\}$\n\nLet\n\\begin{align}\n\\X = \\begin{blockarray}{ccccc}\n\\qquad & 00 & 01 & 10 & 11 \\\\\n\\begin{block}{c[cccc]}\n  00 & X_{(00,00)} & X_{(00,01)} & X_{(00,10)} & X_{(00,11)}\\\\\n  01 & X_{(01,00)} & X_{(01,01)} & X_{(01,10)} & X_{(01,11)}\\\\\n  10 & X_{(10,00)} & X_{(10,01)} & X_{(10,10)} & X_{(10,11)}\\\\\n  11 & X_{(11,00)} & X_{(11,01)} & X_{(11,10)} & X_{(11,11)}\\\\\n\\end{block}\n\\end{blockarray}. \\nonumber \n\\end{align}\n\n\nThe objective function of the SDP is\n\\begin{align} \\label{eq:reichardtObj} \n    &\\max_{y \\in D} \\sum_{j \\in [n]}\n    \\bra{y,j}\\X\\ket{y,j} \\\\\n    &= \\max\\{ \\tr{X_{(00,00)}}, \\tr{X_{(01,01)}}, \\tr{X_{(10,10)}}, \\tr{X_{(11,11)}} \\} \\nonumber\n\\end{align}\nsubject to constraints\n\\begin{align}\n    \\X \\succcurlyeq 0  \\nonumber \n\\end{align}\nand\n\\begin{align}\\label{specific_constraint}\n    \\forall (y,z) \\in F \\sum_{j \\in [n]: y_j \\ne z_j} \n    \\bra{y,j} \\X \\ket{z, j} = 1.\n\\end{align}\nObserve that \\cref{specific_constraint}\nis equivalent to\n\\begin{align}\n    \\tr{X_{(00,01)}} &= \\tr{X_{(00,10)}} = \\tr{X_{(00,11)}} = 1 \\nonumber \\\\\n    \\tr{X_{(01,00)}} &= \\tr{X_{(10,00)}} = \\tr{X_{(11,00)}} = 1. \\nonumber\n\\end{align}\n\nOur goal is to minimize $M$, \nand thus $f_{\\text{bound}}$ by \nfinding the optimal value of $\\X$. \nBy running our SDP solver, we obtain \n$\\X$ with an objective function value of $\\sqrt{2}$.\n\\begin{align}\n    \\X = \\left[ \\begin{array}{cc|cc|cc|cc}\n    0.7 & 0 & 0 & 0 & 1 & 0 & 0.5 & 0\\\\\n    0 & 0.7 & 0 & 1 & 0 & 0 & 0 & 0.5\\\\\n    \\hline\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\n    0 & 1 & 0 & \\sqrt{2} & 0 & 0 & 0 & 0.7\\\\\n    \\hline\n    1 & 0 & 0 & 0 & \\sqrt{2} & 0 & 0.7 & 0\\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\n    \\hline\n    0.5 & 0 & 0 & 0 & 0.7 & 0 & 0.6 & 0\\\\\n    0 & 0.5 & 0 & 0.7 & 0 & 0 & 0 & 0.6\\\\\n    \\end{array}\n\\right] \\nonumber\n\\end{align}\nWe use our solution to construct the input\nvectors to the span program.\nConsider $L$ such that $L^\\dagger L = \\X$.\nThen construct $\\bra{v_{x,i}}$\nfor all $x \\in D$, $i \\in [n]$.\nWith \\cref{input_vectors},\n\\begin{align}\nI &= \\left[\\begin{array}{cc}\n    \\bra{1}\\bra{v_{00,1}} & \\bra{1}\\bra{v_{00,2}} \\\\\n    \\bra{1}\\bra{v_{01,1}} & \\bra{0}\\bra{v_{01,2}} \\\\\n    \\bra{0}\\bra{v_{10,1}} & \\bra{1}\\bra{v_{10,2}}\\\\\n    \\bra{0}\\bra{v_{11,1}} & \\bra{0}\\bra{v_{11,2}}\\\\\n\\end{array} \\right] \\nonumber \\\\\n&= \\left[\\begin{array}{c|c|c|c}\n    0 \\cdots 0 & \\bra{v_{00,1}} & 0 \\cdots 0 & \\bra{v_{00,2}} \\\\\n    0 \\cdots 0 & \\bra{v_{01,1}} & \\bra{v_{01,2}} & 0 \\cdots 0\\\\\n    \\bra{v_{10,1}} & 0 \\cdots 0 & 0 \\cdots 0 & \\bra{v_{10,2}}\\\\\n    \\bra{v_{11,1}} & 0 \\cdots 0 & \\bra{v_{11,2}} & 0 \\cdots 0\\\\\n\\end{array} \\right] \\nonumber\n\\end{align}\nThe columns of $I$ are the columns\nused in the span program. \nIf we remove rows of $I$ corresponding to elements \n$ x \\in D$ such that $f(x) = 1$\nand columns of $I$ that are the \nall zero vector, we obtain an equivalent span program where\n\\begin{align}\nI &= \\left[\\begin{array}{cccc}\n   0 & 1 & 0 & 1 \\\\\n\\end{array} \\right] \\nonumber\n\\end{align}\nand $\\tau = 1$.\nThe left two partitions\ncorrespond to the first bit in the\ninput, and the right two partitions correspond \nto the second bit of the input. For each\ninput bit, the relevant block of $I$ \nis broken into left and right halves, corresponding\nto whether the bit is $0$ (left) or $1$ (right). \nIt is clear from this matrix that if either input bit is\n$1$ the function will return true and otherwise\nwill return false.\n\n\\subsection{Accuracy with OR and Parity}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=.5]{or_complexity}\n\\caption{The proven analytical optimal query complexity\nand calculated empirical optimal query complexity by \nsize of input bitstring for OR.}\n\\label{fig:or_complexity}\n\\end{figure}\n\nWe verify that the implementation works correctly\nwith results for OR on various input sizes.\nThe optimal quantum query complexity of OR\nis $\\sqrt{n}$ and, as demonstrated in\n\\cref{fig:or_complexity}, the empirical results match the analytical\nto the thousandth place.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=.5]{parity_complexity}\n\\caption{The proven analytical optimal query complexity\nand calculated empirical optimal query complexity by \nsize of input bitstring for parity.}\n\\label{fig:parity_complexity}\n\\end{figure}\n\nThe parity function, determining whether\nthere are an even number of 1's an input\nbitstring, is known to have optimal\nquantum query complexity linear to the number of bits.\nThe implementation also correctly\ncalculates the complexity of parity to the thousandth\nplace as demonstrated in \\cref{fig:parity_complexity}.\n\nThe results for OR and parity demonstrate\nthat the implementation accurately calculates\noptimal quantum query complexity.\n\n\\subsection{Runtime with OR}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=.5]{or_runtime}\n\\caption{Runtime of SDP solver by size of input strings.}\n\\label{fig:or_runtime}\n\\end{figure}\n\nRecall that the size of the input to the implementation\ndoes not have to be all $2^n$ input bitstrings\nfor input size $n$. In fact,\nby choosing different and smaller inputs,\nwe can improve runtime while maintaining accuracy.\n\nIn \\cref{fig:or_runtime}, observe that the\nruntime of the implementation on OR with all\ninputs increases exponentially\nwith the input size $n$.\n(Since the number of inputs grows exponentially,\nit follows that the size of the problem grows\nexponentially, too.) As a note, our\nruntime results are presented as the\nresult of timing our program once. If we\nwere trying to make an argument about the\nabsolute runtime of our algorithm, it\nwould've been better to show a\ndistribution. We want to highlight the\nasymptotic behavior of runtime which is\npresented here and consistent between\nruns of our program.\nThe bottleneck in the implementation is\nthe eigenvalue decomposition of the current\nsolution at each step of the iteration.\n\n\nIf we limit the inputs to the `worst-case`\nbitstrings we observe much lower runtime, as shown in \\ref{fig:or_runtime}.\nIt is in general very difficult to find the worst-case\ninputs and OR is a special case.\nWhen searching for at least one 1, the most\ndifficult bitstrings to search are those with a single 1.\nSo, by supplying only the worst-case inputs that\nhave at most one 1, we can maintain the same level of accuracy while\ngreatly reducing runtime.\nWe know of no other Boolean functions with\nsimilarly intuitive worst-case sets of inputs.\n", "meta": {"hexsha": "3b325575c0d30e702596830508f0b5b65232c3bb", "size": 6873, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sec/3_results.tex", "max_stars_repo_name": "rtealwitter/QuantumQueryOptimizer", "max_stars_repo_head_hexsha": "64f68110ab088c271fad96976f2fa06af88d5a2e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/sec/3_results.tex", "max_issues_repo_name": "rtealwitter/QuantumQueryOptimizer", "max_issues_repo_head_hexsha": "64f68110ab088c271fad96976f2fa06af88d5a2e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/sec/3_results.tex", "max_forks_repo_name": "rtealwitter/QuantumQueryOptimizer", "max_forks_repo_head_hexsha": "64f68110ab088c271fad96976f2fa06af88d5a2e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.5376884422, "max_line_length": 97, "alphanum_fraction": 0.6769969446, "num_tokens": 2368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.8198933381139646, "lm_q1q2_score": 0.7348305301077483}}
{"text": "% declare document class and geometry\n\\documentclass[12pt]{article} % use larger type; default would be 10pt\n\\usepackage[margin=1in]{geometry} % handle page geometry\n\n% import packages and commands\n\\input{../header2.tex}\n\n\n\\title{Phys 220A -- Classical Mechanics -- HW05}\n\\author{UCLA, Fall 2014}\n\\date{\\formatdate{7}{11}{2014}} % Activate to display a given date or no date (if empty),\n         % otherwise the current date is printed \n\n\\begin{document}\n\\maketitle\n\n\n\\section*{Problem 1 (15 pts)}\n\\textit{\nThis problem concerns the Runge-Lanz vector and its algebra under Poisson brackets. The Runge-Lenz vector is defined as\n\\begin{eqn}\n\\v{K} = \\frac{1}{m} \\v p \\times \\v L - \\frac{\\v r}{r}.\n\\end{eqn}\n}\n\n\\begin{enumproblem}\n\n% part A\n\\item \\textit{\nShow that the following Poisson bracket is given by\n\\begin{eqn}\n\\cbr{L_i, K_j} = \\epsilon_{ijk} K_k.\n\\end{eqn}\n}\n\n\n% part B\n\\item \\textit{\nShow that\n\\begin{eqn}\n\\cbr{K_i, K_j} = - \\frac{2}{m} \\left( \\frac{p^2}{2m} - \\frac{1}{r} \\right) \\epsilon_{ijk} L_k.\n\\end{eqn}\n}\n\n\n% part C\n\\item \\textit{\nShow that for a Hamiltonian of the form\n\\begin{eqn}\nH = \\frac{p^2}{2m} + V(r)\n\\end{eqn}\none has \n\\begin{eqn}\n[\\v K, H] = \\frac{\\v r \\times (\\v p \\times \\v r)}{m} \\left( \\frac{-1 + r^2 V'(r)}{r^3} \\right).\n\\end{eqn}\n}\n\n\n\\end{enumproblem}\n\n\n\n\n\\section*{Problem 2 (15 pts)}\n\\textit{\nConsider a mass point which moves on a wire which rotates with constant angular velocity.\n}\n\n\\begin{enumproblem}\n\n% part A\n\\item \\textit{\nBy transforming to general coordinates which rotate with the wire show that the Lagrangian of the system is given by\n\\begin{eqn}\nL = \\frac{m}{2} (\\dot r^2 + \\omega^2 r^2).\n\\end{eqn}\n}\n\n\n% part B\n\\item \\textit{\nCalculate the Hamiltonian of the system. Does it change with time ?\n}\n\n\n% part C\n\\item \\textit{\nCalculate the kinetic energy (which is the total energy) of the mass point in terms of the generalized coordinate $r$. Is it the same as the Hamiltonian and is it conserved ?\n}\n\n\n\\end{enumproblem}\n\n\n\n\n\\section*{Problem 3 (15 pts)}\n\\textit{\nConsider a transformation of a Lagrangian to an equivalent Lagrangian, i.e.\n\\begin{eqn}\nL(q, \\dot q, t) \\rightarrow L(q, \\dot q, t) + \\od{}{t} \\Lambda(q,t).\n\\end{eqn}\n}\n\n\\begin{enumproblem}\n\n% part A\n\\item \\textit{\nHow do the coordinates and canonical momenta change ? \n}\n\n\n% part B\n\\item \\textit{\nHow does the Hamiltonian change\n}\n\n\n% part C\n\\item \\textit{\nConsider this change as a generalized coordinate change $(q, p) \\rightarrow (q', p')$. Show that the Poisson braced for the new coordinates will have the same form as the old one.\n}\n\n\n\\end{enumproblem}\n\n\n\n\n\\section*{Problem 4 (10 pts)}\n\\textit{\nConsider a dynamical flow which is defined on $\\R^n$ with $\\v x = (x_1, \\dots x_n)$ and a vector field $\\v v(\\v x)$ as follows\n\\begin{eqn}\n\\od{}{t} \\v x(t) = \\v v(\\v x(t)).\n\\end{eqn}\n}\n\n\\begin{enumproblem}\n\n% part A\n\\item \\textit{\nSolving the differential equations and finding $\\v x(t)$ defines a map from $\\R^n \\rightarrow \\R^n$. Show that this map is volume preserving if the vector field $\\v v$ is divergence free, i.e.\n\\begin{eqn}\n\\sum_i \\pd{v_i}{x_i} = 0.\n\\end{eqn}\n}\n\n\n% part B\n\\item \\textit{\nShow that by setting $\\v x = \\set{q_1, \\dots, q_n, p_1, \\dots, p_n}$ and \n\\begin{eqn}\nv^i = \\sum_j J^i_j \\pd{H}{{x^j}}, \\qquad\nJ = \\pmat{0 & 1_n \\\\ -1_n & 0},\n\\end{eqn}\nthe vector field $\\v v$ is divergence free if Hamilton's equations hold. Hence you have proved Liouville's theorem.\n}\n\n\n\\end{enumproblem}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "b04ec768646cf6daa2dd12b9cb84906e7210e529", "size": 3438, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "classical/hw05.tex", "max_stars_repo_name": "paulinearriaga/phys-ucla", "max_stars_repo_head_hexsha": "48084dbbac2f8a4748c1fdaaf63a4cebaae16809", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "classical/hw05.tex", "max_issues_repo_name": "paulinearriaga/phys-ucla", "max_issues_repo_head_hexsha": "48084dbbac2f8a4748c1fdaaf63a4cebaae16809", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "classical/hw05.tex", "max_forks_repo_name": "paulinearriaga/phys-ucla", "max_forks_repo_head_hexsha": "48084dbbac2f8a4748c1fdaaf63a4cebaae16809", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.8363636364, "max_line_length": 192, "alphanum_fraction": 0.6777196044, "num_tokens": 1156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201267, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7348305272358442}}
{"text": "\\chapter{Dynamic Programming}\n\nSo far we have considered two major strategies in algorithms design:\ngreedy, in which we repeatedly take the local optimum choice; and\ndivide and conquer, in which we divide the greater problem into\nsimilar subproblems and recurse.\n\nThere may be problems for which these strategies are suboptimal.  In\nwhich case, we have a third strategy which may be of use: dynamic\nprogramming.  This strategy divides the problem into sub problems, but\nrather than recursing on each sub problem individually, we identify\neasy to compute base cases from which we can build towards the\nsolution to the larger problem, storing the results of previous\ncomputations to use in later computations.  This technique differs\nfrom a similar technique called ``memoization'' which computes\nrecursively top-down, whereas dynamic programming begins at the base\ncase(s) and works up.\n\nDynamic programming has these important steps:\n\n\\begin{enumerate}\n\\item Determine structure of optimal solution\n\\item Set up recurrences for optimal solution\n\\item Solve recurrences bottom-up\n\\item Construct the optimal solution\n\\end{enumerate}\n\nAnd the final step is most often neglected since we can typically add\nsome small amount of information to the process so we can trivially\nreconstruct the optimal solution.\n\n\\section{Matrix Chain Multiplication}\n\nAssuming knowledge of matrices and how they are multiplied.\n\nThe problem is to find the way to multiply $n$ matrices $A_1,...,A_n$\nwith dimensions $p_0,...,p_n$ (e.g. $A_i$ has dimensions $p_{i-1}\n\\cross p_i$) using the least number of calculations.  Notice that\nmultiplying $A_iA_{i+1}$ takes $p_{i-1}p_ip_{i+1}$ calculations.\n\nWe start by determining the structure of the optimal solution.\nObserve that the optimal solution will necessarily involve splitting\n$A_1A_2...A_n$ into two subproblems at some optimally chosen\n$A_kA_{k+1}$ so we multiply $A_1...A_k$ then $A_k...A_n$ and then\nmultiply the results together.  If we define the function $m(i,j)$ to\nbe the minimum cost of multiplying $A_i...A_j$, then the cost of the\noptimal solution is $m(1,n) = m(1,k) + m(k+1,n) + p_0p_kp_n$.\n\nWe then define the recurrence $m(i,i) = 0$ and $m(i,j) = min \\{ m(i,k) +\nm(k+1,j) + p_{i-1}p_kp_j \\}$ for all $k$ such that $i < k \\leq j$.\n\nWe then compute all $m(i,i)$ for $1 \\leq i \\leq n$, then all\n$m(i,i+1)$, $m(i,i+2)$, ... until we have calculated $m(1,n)$.\n\nThe time complexity of this solution is\n\n\\[\n  \\summ{l=2}{n}\\summ{i=1}{n-l+1}\\summ{k=i}{i+l+2}\\BigOh{1} = \\BigOh{n^3}\n\\]\n\n\\section{Longest Common Subsequence}\n\nFor a string $S = (s_1,s_2,\\dots,s_n)$, a subsequence of $S$ is string $S'$ such that every element of $S'$ is in $S$, and if an element $a \\in S'$ comes before $b \\in S'$, this also holds for $S$. The longest common subsequence of two strings $A=(a_1,a_2,\\dots,a_n)$ and $B = (b_1,b_2,\\dots,b_m)$, is the longest string $C = (c_1,c_2,\\dots,c_k)$, such that $C$ is a subsequence of $A$ and $B$.\n\nLet the substring $(s_i,s_{i+1},\\dots,s_j)$ be denoted as $S(i,j)$. Further, let $LCS(i,j)$ to be the length of the LCS of $A(0,i)$ and $B(0,j)$. Assume that we have computed $C(1,k)$, and that it is unique. Then if we remove $c_k$ and everything after it from $B$ and $A$, $C(1,k-1)$ is now the LCS of our modified $A$ and $B$. \n\nIn general \n$LCS(i,j) =$\n\n\\begin{math}\n   \\left\\{\n    \\begin{array}{l l}\n      \\emptyset \t\t& \\text{if $i=0$ or $j=0$}\\\\\n      LCS(i-1,j)+1 \t& \\text{if $a_i=b_j$}\\\\\n      \t\t\t\t\t& \\text{and $LCS(i-1,j)>LCS(i,j-1)$}\\\\\n      LCS(i,j-1)+1 \t& \\text{if $a_i=b_j$}\\\\\n      \t\t\t\t\t& \\text{and $LCS(i-1,j)<LCS(i,j-1)$}\\\\\n      \n    \\end{array} \\right.\n\\end{math}\n\nTo compute this, we compute $LCS(0,0)$, $LCS(0,1)$,\\dots,$LCS(0,m)$; then $LCS(1,0)$,\\dots,$LCS(1,m)$; \\dots;$LCS(n,0)$,\\dots,$LCS(n,m)$. At which point we have our solution, which is $LCS(n,m)$.\n\n\\section{Optimal Triangulation of a Convex Polygon}\n\n% page 91 in John's notes\n\nFirst some definitions.  A \\emph{polygon} is a list of vertices\n$(v_1,...,v_n)$ such that for any $v_i$, there exists an edge\n$(v_i,v_{i+1})$ and also there exists an edge $(v_1,v_n)$.  A polygon\nis said to be \\emph{convex} if any line passing through the polygon\ncrosses the edges of the polygon at most twice.  A \\emph{chord} is an\nedge between two non-adjacent vertices in a polygon.  A\n\\emph{triangulation} is a set of chords which divide a polygon into\ntriangles.\n\nThe problem is to build a triangulation of a given convex polygon\nwhich minimizes total edge length.  We define the function $w(a,b,c)$\nto be the weight of the triangle $(v_a,v_b,v_c)$, which in this case\nwill be the length of the edges $(v_a,v_b)$, $(v_b,v_c)$, and\n$(v_c,v_a)$.  We also define the function $t(a,b)$ to be the optimal\ntriangulation of points $(v_a,...,v_b)$.  We would like to solve\n$t(1,n)$.\n\nWe start by defining the structure of an optimal solution.  Notice\nthat the optimal triangulation contains the triangle $(v_1,v_k,v_n)$\nfor some $k$.  The cost of this triangulation is $t(1,k) + t(k,n) +\nw(1,k,n)$.\n\nWe then define the recurrence $t(i,i+1) = 0$ for all $i$, and $t(i,j)\n= min \\{ t(i,k) + t(k,j) + w(i,k,j) \\}$ for all $k$ such that $i < k < j$.\n\nWe then compute all $t(i,i+1)$, then all $t(i,i+2)$, $t(i,i+3)$,\n... until we have calculated $t(1,n)$.\n\n\\hypertarget{sec:floyd_warshall}{\\section{All-Pairs Shortest Path\n    (Floyd-Warshall)}}\n\nGiven a graph $G=(V,E)$ where edges have an associated weight $w(e)$\nfor $e \\in E$, compute the shortest path between $u$ and $v$ for all\n$u,v \\in V$.\n\nWe start by defining the structure of an optimal solution.  Let us\ndecompose the problem into finding the optimal path between $v_i$ and\n$v_j$.  All of the vertices on this path are contained in $\\{\nv_1,...,v_k \\}$ except perhaps $v_i,v_j$.  Notice that if $k=0$ then\nif there is an edge $(v_i,v_j) \\in E$ then the distance is the weight\nof that edge, and if there is no such edge then the weight is\ninfinite.  Otherwise, we take the minimum of either including or\nexcluding $v_k$ on the path.  This gives the recurrence:\n\n\\begin{math}\n  d^k_{i,j} = \\left\\{\n    \\begin{array}{l l}\n      weight((v_i,v_j)) & \\text{if $k=0$ and} \\\\\n                        & (v_i,v_j) \\in E \\\\\n      \\infty            & \\text{if $k=0$ and} \\\\\n                        & (v_i,v_j) \\not \\in E \\\\\n      min \\{ d^{k-1}_{i,j},d^{k-1}_{i,k} + d^{k-1}_{k,j} \\} & \\text{if $k>0$}\n    \\end{array} \\right.\n\\end{math}\n\nWe then compute $d^0_{i,j}$ for all $v_i,v_j \\in V$, then all\n$d^1_{i,j}$, $d^2_{i,j}$, ... until we have computed $d^{n-2}_{i,j}$.\n\nRunning time: $\\BigOh{n^3}$.  Analysis is left as an exercise to the\nreader.\n\n\\section{Knapsack}\n\nGiven a knapsack (or bag) which can carry $W$ units of weight, and $n$\nitems where item $i$ has weight $w_i$ and value $v_i$, what is the\nmost valuable list of items which can fit in the given bag?  Notice\nthat this may include multiples of a particular item.\n\nWe start by defining the structure of an optimal solution.  Let $p(w)$\nbe the value of the optimal packing of a bag which can carry $w$ units\nof weight, and let $p_i(w)$ be the same but necessarily including item\n$i$.\n\n\\begin{align*}\n  p_i(w) &= p(w - w_i) + v_i & \\\\\n  p(0)   &= 0 & \\\\\n  p(w)   &= max \\{ p(w - w_i) + v_i \\} & \\text{where $i : w_i \\leq w$} \\\\\n\\end{align*}\n\nWe then calculate $p(0), p(1), ..., p(W)$.\n\nThe running time for this algorithm is $\\BigOh{nW}$.  Notice that $W$\nrequires $\\BigOh{logW}$ bits to represent.  Since the input to the\nproblem is $\\BigOh{n + logW}$, and $W = 2^{logW}$, the time complexity\nis $\\BigOh{n2^{logW}}$ so this solution is exponential with respect to\nthe input.\n\n\\section{String Edit Distance}\n\nWe define the edit distance between two strings as the minimum number\nof edits necessary to transform one string into another, where edits\nare insertions, deletions, or replacements of a single character.\n\nThe problem is to compute this edit distance, given strings $X$ of\nlength $m$ and $Y$ of length $n$.\n\nWe start by defining the structure of an optimal solution.  Let us\ndefine $E[i,j]$ as the minimal edit distance between $X[1..i]$ and\n$Y[1..j]$.  We would like to know $E[m,n]$.\n\nIt should be easy to see that $E[0,0] = 0$ and $E[1,1]$ is either $0$\nif $X[1] = Y[1]$ or $1$ otherwise.  $E[0,j] = j$ and $E[i,0] = i$.\n\nThis gives the recurrence:\n\n\\begin{math}\n  E[i,j] = \\left\\{\n    \\begin{array}{l l}\n      0 & \\text{if } i=0,j=0 \\\\\n      i & \\text{if } j=0 \\\\\n      j & \\text{if } i=0 \\\\\n      min \\{ 1 + E[i-1,j], 1 + E[i,j-1], 1 + E[i-1,j-1] \\} & \\text{if } X[i] \\neq Y[j] \\\\\n      min \\{ 1 + E[i-1,j], 1 + E[i,j-1], E[i-1,j-1] \\} & \\text{otherwise} \\\\\n    \\end{array} \\right.\n\\end{math}\n\nThen we calculate $E[i,j]$ from $i=0,j=0$ to $i=m,j=n$.\n\n\n", "meta": {"hexsha": "dfb719442003e9ea22977e4d5986a2910b7de78a", "size": 8685, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "dynamic_programming.tex", "max_stars_repo_name": "SteamedPears/AllTheAlgorithms", "max_stars_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-10-12T19:16:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-01T03:13:05.000Z", "max_issues_repo_path": "dynamic_programming.tex", "max_issues_repo_name": "SteamedPears/AllTheAlgorithms", "max_issues_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dynamic_programming.tex", "max_forks_repo_name": "SteamedPears/AllTheAlgorithms", "max_forks_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.9565217391, "max_line_length": 394, "alphanum_fraction": 0.6668969488, "num_tokens": 2856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.831143031127974, "lm_q2_score": 0.8840392771633079, "lm_q1q2_score": 0.7347630844576949}}
{"text": "\n\\subsection{Connected and separated sets}\n\nTwo subsets of \\(X\\) in topological space \\(T\\) are separated if each subset is disjoint from the other's closure.\n\nSo \\([-1,0)\\) and \\((0,1)\\) are separated.\n\n\\([-1,0]\\) and \\((0,1)\\) are not separated.\n\nSets which are not separated are connected.\n\n", "meta": {"hexsha": "a8d608bcf658ddbd90e8d1cbb756f53cd223e706", "size": 294, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/topologyFinite/04-01-connected.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/topologyFinite/04-01-connected.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/topologyFinite/04-01-connected.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.5, "max_line_length": 114, "alphanum_fraction": 0.6802721088, "num_tokens": 81, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404116305638, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.734750822497375}}
{"text": "\\subsection{Boolean functions}\\label{subsec:boolean_functions}\n\n\\begin{definition}\\label{def:boolean_value}\n  Fix a two-element set \\( \\set{ T, F } \\). We can think of \\( T \\) as a value denoting truth and \\( F \\) as denoting falsity. See \\fullref{rem:mathematical_logic_conventions/propositional_constants} for notation conventions.\n\n  There is a natural \\hyperref[def:boolean_algebra]{Boolean algebra} structure on \\( \\set{ T, F } \\) where \\( T \\) is the \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{top} and \\( F \\) is the \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bottom} and the operations are defined in an obvious way.\n\n  By \\fullref{thm:binary_boolean_algebra}, all two-element Boolean algebras are isomorphic, so our choice of symbols does not matter much. We do sometimes identify \\( T \\) with \\( 1 \\) and \\( F \\) with \\( 0 \\) in the \\hyperref[thm:finite_fields]{prime field} \\( \\BbbF_2 \\). The latter is a Boolean algebra as discussed in \\fullref{thm:f2_is_boolean_algebra}.\n\\end{definition}\n\n\\begin{definition}\\label{def:boolean_function}\n  We call functions from any set to \\( \\set{ T, F } \\) (Boolean-valued) \\term{predicates} and functions from \\( \\set{ T, F }^n \\) to \\( \\set{ T, F } \\) \\term{Boolean functions}.\n\\end{definition}\n\n\\begin{remark}\\label{rem:boolean_valued_functions_and_predicates}\n  \\hyperref[def:boolean_function]{Boolean-valued functions} and \\hyperref[def:relation]{relations} represent the same concept. In particular, the relation \\( R \\subseteq A_1 \\times \\cdots \\times A_n \\) corresponds to a unique Boolean-valued function\n  \\begin{equation*}\n    \\begin{aligned}\n      &f: X_1 \\times \\cdots \\times X_n \\to \\set{ T, F } \\\\\n      &f(x_1, \\ldots, x_n) = \\begin{cases}\n        T, &(x_1, \\ldots, x_n) \\in R, \\\\\n        F, &\\T{otherwise}\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n  and vice versa.\n\\end{remark}\n\n\\begin{definition}\\label{def:boolean_closure}\n  Fix a set \\( B \\) of Boolean functions of arbitrary arities.\n\n  The \\term{closure} \\( \\cl{B} \\) of \\( B \\) is defined \\hyperref[rem:structural_recursion_and_induction]{recursively} as follows:\n  \\begin{itemize}\n    \\item If \\( f \\in B \\), then \\( f \\in \\cl{B} \\)\n    \\item If \\( f_k(x_1, \\ldots, x_n) \\in \\cl{B} \\) for \\( k = 1, \\ldots, m \\) and if \\( g(x_1, \\ldots, x_m) \\in \\cl{B} \\), then their \\hyperref[def:multi_valued_function/superposition]{superposition}\n    \\begin{equation*}\n      h(x_1, \\ldots, x_n) \\coloneqq g(f_1(x_1, \\ldots, x_n), \\ldots, f_m(x_1, \\ldots, x_n))\n    \\end{equation*}\n    is also in \\( \\cl{B} \\).\n  \\end{itemize}\n\n  We say that \\( B \\) is \\term{closed} if \\( \\cl{B} = B \\) and \\term{complete} if \\( \\cl{B} \\) is the set of all Boolean functions of arbitrary arity.\n\n  If \\( B \\) is complete, then from \\fullref{thm:functions_over_model_form_model} it follows that \\( B \\) is a Boolean algebra. This is used in \\fullref{thm:lindenmaum_tarski_algebra_of_full_propositional_logic/bijection}.\n\\end{definition}\n\n\\begin{definition}\\label{def:zhegalkin_polynomial}\n  A \\term{Zhegalkin polynomial} is a \\hyperref[def:polynomial_algebra]{polynomial} in the \\hyperref[thm:finite_fields]{prime field} \\( \\BbbF_2 \\). Due to \\fullref{thm:functions_over_prime_fields}, however, we restrict ourselves to polynomials with \\hyperref[def:square_free]{square-free} monomials.\n\n  For example, for every binary Boolean function there exist coefficients \\( a, b, c, d \\in \\BbbF_2 \\) such that\n  \\begin{equation}\\label{eq:def:zhegalkin_polynomial/binary_polynomial}\n    f(x, y) = axy \\oplus bx \\oplus cy \\oplus d.\n  \\end{equation}\n\\end{definition}\n\n\\begin{definition}\\label{def:standard_boolean_operators}\n  Unlike \\hyperref[def:function]{arbitrary functions}, \\hyperref[def:boolean_function]{Boolean functions} only have a small finite number of possible values that can easily be enumerated.\n\n  Out of the following binary operations, \\( \\vee \\), \\( \\wedge \\) and \\( \\overline{\\anon} \\) form the \\hyperref[def:boolean_algebra]{Boolean algebra} structure on \\( \\BbbF_2 \\) and \\( \\oplus \\) and \\( \\wedge \\) form the \\hyperref[def:field]{field} structure on \\( \\BbbF_2 \\). The operations \\( \\rightarrow \\) and \\( \\leftrightarrow \\) are also defined in any \\hyperref[def:boolean_algebra]{Boolean algebra}.\n\n  \\begin{center}\n    \\begin{tabular}{c | c || c c | c c c c c c}\n      \\( x \\) & \\( \\overline{x} \\) & \\( x \\) & \\( y \\) & \\( x \\vee y \\)             & \\( x \\oplus y \\)    & \\( x \\wedge y \\)        & \\( x \\rightarrow y \\)   & \\( x \\leftrightarrow y \\) \\\\\n      \\hline\n              & not \\( x \\)        &         &         & \\( x \\) or \\( y \\)         & \\( x \\) xor \\( y \\) & \\( x \\) and \\( y \\)     & \\( x \\) implies \\( y \\) & \\( x \\) iff \\( y \\)       \\\\\n      \\hline\n      \\( F \\) & \\( T \\)            & \\( F \\) & \\( F \\) & \\( F \\)                    & \\( F \\)             & \\( F \\)                 & \\( T \\)                 & \\( T \\)                   \\\\\n      \\( T \\) & \\( F \\)            & \\( F \\) & \\( T \\) & \\( F \\)                    & \\( T \\)             & \\( F \\)                 & \\( T \\)                 & \\( F \\)                   \\\\\n              &                    & \\( T \\) & \\( F \\) & \\( F \\)                    & \\( T \\)             & \\( F \\)                 & \\( F \\)                 & \\( F \\)                   \\\\\n              &                    & \\( T \\) & \\( T \\) & \\( T \\)                    & \\( F \\)             & \\( T \\)                 & \\( T \\)                 & \\( T \\)                   \\\\\n      \\hline\n              & \\( x \\oplus 1 \\)   &         &         & \\( xy \\oplus x \\oplus y \\) & \\( x \\oplus y \\)    & \\( xy \\)            & \\( xy \\oplus x \\oplus 1 \\) & \\( x \\oplus y \\oplus 1 \\)\n    \\end{tabular}\n  \\end{center}\n\n  See \\fullref{thm:boolean_equivalences} for direct consequences of these definitions.\n\\end{definition}\n\n\\begin{definition}\\label{def:boolean_functions_in_f2}\\mcite[I.1.\\S6]{Яблонский1986}\n  Fix a \\hyperref[def:boolean_function]{Boolean function} \\( f(x_1, \\ldots, x_n) \\) in the \\hyperref[thm:finite_fields]{prime field} \\( \\BbbF_2 \\).\n\n  \\begin{thmenum}\n    \\thmitem{def:boolean_function_in_f2/dual} Its \\term{dual function} is\n    \\begin{equation*}\n      \\overline{f}(x_1, \\ldots, x_n) \\coloneqq \\overline{f(\\overline{x_1}, \\ldots, \\overline{x_n})}.\n    \\end{equation*}\n\n    \\thmitem{def:boolean_functions_in_f2/self_dual} \\( f \\) is \\term{self-dual} if it is its own \\hyperref[def:boolean_function_in_f2/dual]{dual}.\n\n    \\thmitem{def:boolean_functions_in_f2/truth_preserving} \\( f \\) is \\term{truth-preserving} if \\( f(T, \\ldots, T) = T \\).\n\n    \\thmitem{def:boolean_functions_in_f2/falsity_preserving} \\( f \\) is \\term{falsity-preserving} if \\( f(F, \\ldots, F) = F \\).\n\n    \\thmitem{def:boolean_functions_in_f2/monotone} \\( f \\) is \\term{monotone} if, for any two tuples of arguments \\( x_1, \\ldots, x_n \\in \\BbbF_2 \\) and \\( y_1, \\ldots, y_n \\in \\BbbF_2 \\), the inequalities \\( x_k \\leq y_k \\) for all \\( k \\in \\set{ 1, \\ldots, n } \\) imply that\n    \\begin{equation*}\n      f(x_1, \\ldots, x_n) \\leq f(y_1, \\ldots, y_n).\n    \\end{equation*}\n\n    \\thmitem{def:boolean_functions_in_f2/linear} \\( f \\) is \\term{linear} if its \\hyperref[def:zhegalkin_polynomial]{Zhegalkin polynomial} is linear, i.e. has only monomials of degree \\( 0 \\) or \\( 1 \\). In the case of binary Boolean functions, this means that the coefficient \\( a \\) in \\eqref{eq:def:zhegalkin_polynomial/binary_polynomial} is zero.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{theorem}[Post-Yablonsky completeness theorem]\\label{thm:posts_completeness_theorem}\\mcite[thm. I.1.7]{Яблонский1986}\n  The family \\( B \\) of Boolean functions is \\hyperref[def:boolean_closure]{complete} if and only if all of the following conditions are satisfied:\n  \\begin{thmenum}\n    \\thmitem{thm:posts_completeness_theorem/truth_preserving} \\( B \\) contains a function that is not \\hyperref[def:boolean_functions_in_f2/truth_preserving]{truth-preserving}.\n    \\thmitem{thm:posts_completeness_theorem/falsity_preserving} \\( B \\) contains a function that is not \\hyperref[def:boolean_functions_in_f2/falsity_preserving]{falsity-preserving}.\n    \\thmitem{thm:posts_completeness_theorem/self_dual} \\( B \\) contains a function that is not \\hyperref[def:boolean_functions_in_f2/self_dual]{self-dual}.\n    \\thmitem{thm:posts_completeness_theorem/monotone} \\( B \\) contains a function that is not \\hyperref[def:boolean_functions_in_f2/monotone]{monotone}.\n    \\thmitem{thm:posts_completeness_theorem/linear} \\( B \\) contains a function that is not \\hyperref[def:boolean_functions_in_f2/linear]{linear}.\n  \\end{thmenum}\n\\end{theorem}\n\n\\begin{example}\\label{ex:thm:posts_completeness_theorem}\n  We give examples of complete sets of Boolean functions in \\( \\BbbF_2 \\).\n\n  \\begin{thmenum}\n    \\thmitem{ex:thm:posts_completeness_theorem/and_or} The archetypic example of a complete set of Boolean functions is the triple \\( \\vee, \\wedge, \\overline{\\anon} \\) that forms the Boolean algebra structure on \\( \\BbbF_2 \\).\n\n    We verify that the conditions of \\fullref{thm:posts_completeness_theorem} are satisfied:\n    \\begin{refenum}\n      \\refitem{thm:posts_completeness_theorem/truth_preserving} \\( \\overline{\\anon} \\) is not truth-preserving.\n      \\refitem{thm:posts_completeness_theorem/falsity_preserving} \\( \\overline{\\anon} \\) is not falsity-preserving.\n      \\refitem{thm:posts_completeness_theorem/self_dual} Neither \\( \\vee \\) nor \\( \\wedge \\) are self-dual. In fact, due to \\fullref{thm:de_morgans_laws}, \\( \\wedge \\) is the dual of \\( \\vee \\) and vice versa.\n      \\refitem{thm:posts_completeness_theorem/monotone} \\( \\overline{\\anon} \\) is not monotone.\n      \\refitem{thm:posts_completeness_theorem/linear} Neither \\( \\vee \\) nor \\( \\wedge \\) have linear Zhegalkin polynomials.\n    \\end{refenum}\n\n    Thus, \\( \\set{ \\wedge, \\vee, \\overline{\\anon} } \\) is indeed a complete set of Boolean functions. Note that having both \\( \\vee \\) and \\( \\wedge \\) is redundant and we usually include both for symmetry. The families \\( \\set{ \\wedge, \\overline{\\anon} } \\) and \\( \\set{ \\vee, \\overline{\\anon} } \\) are both complete.\n\n    This is utilized for \\hyperref[def:cnf_and_dnf]{conjunctive and disjunctive normal forms}.\n\n    \\thmitem{ex:thm:posts_completeness_theorem/nand} We can go even further and have a single binary Boolean function generate all others. We will use the function\n    \\begin{equation}\\label{eq:ex:thm:posts_completeness_theorem/nand}\n      (x \\uparrow y) \\coloneqq \\overline{x \\wedge y} = xy \\oplus 1.\n    \\end{equation}\n\n    This operation is called \\term{Sheffer's stroke} or \\term{nand} (\\enquote{not and}).\n\n    We have\n    \\begin{equation*}\n      \\begin{array}{ccc}\n        \\overline{x} = (x \\uparrow 1)\n        &\n        \\T{and}\n        &\n        (x \\wedge y) = \\overline{x \\uparrow y},\n      \\end{array}\n    \\end{equation*}\n    which allows us to reduce the case to \\fullref{ex:thm:posts_completeness_theorem/and_or}. We conclude that the singleton set \\( \\set{ \\uparrow } \\) is a complete set of Boolean operations.\n\n    \\thmitem{ex:thm:posts_completeness_theorem/conditional_negation} Another commonly used complete family is \\( \\set{ \\rightarrow, \\overline{\\anon} } \\).\n    We verify that the conditions of \\fullref{thm:posts_completeness_theorem} are satisfied:\n    \\begin{refenum}\n      \\refitem{thm:posts_completeness_theorem/truth_preserving} \\( \\overline{\\anon} \\) is not truth-preserving.\n      \\refitem{thm:posts_completeness_theorem/falsity_preserving} \\( \\rightarrow \\) is not falsity-preserving because \\( (F \\rightarrow F) = T \\).\n      \\refitem{thm:posts_completeness_theorem/self_dual} \\( \\rightarrow \\) is not self-dual because \\( \\overline{\\overline{x} \\rightarrow \\overline{y}} \\reloset {\\eqref{eq:thm:boolean_equivalences/contrapositive}} = (y \\rightarrow x) \\neq (x \\rightarrow y) \\).\n      \\refitem{thm:posts_completeness_theorem/monotone} \\( \\rightarrow \\) is not monotone because \\( F \\rightarrow T = F \\).\n      \\refitem{thm:posts_completeness_theorem/linear} \\( \\rightarrow \\) doesn't have a linear Zhegalkin polynomial.\n    \\end{refenum}\n\n    \\thmitem{ex:thm:posts_completeness_theorem/conditional_bottom} Given the family \\( \\set{ \\rightarrow, F } \\), we can define\n    \\begin{equation*}\n      \\overline{x} \\coloneqq (x \\rightarrow F),\n    \\end{equation*}\n    which shows that \\( \\set{ \\rightarrow, F } \\) is also a complete family.\n  \\end{thmenum}\n\\end{example}\n", "meta": {"hexsha": "0e4213841caaf0746e4c3ad56acf5866d0c5b25d", "size": 12378, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/boolean_functions.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/boolean_functions.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/boolean_functions.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.2426035503, "max_line_length": 408, "alphanum_fraction": 0.6498626596, "num_tokens": 3935, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7347473896636256}}
{"text": "%\\chapter{Multigrid Methods}\\label{chap:introMG}\nIn this chapter, we will introduce the multigrid \nmethods for numerical partial differential equations with\nsome notation in convolutional neural networks as discussed in \nprevious sections. \nThe main purpose of this section is to give three different \nversion of multigrid methods: recursion form, method of subspace\ncorrection form and expansion form.\n\n\n\\input{4MSC/4ChTri-tenmatrix}\n\n\\input{4MSC/4ChLocality}\n\n\\section{Some basic components for multigrid methods}\\label{sec:mg}\nLet us first briefly describe a geometric multigrid method used to solve the \nfollowing boundary value problem\n\\begin{equation}\n\\label{laplace}\n-\\Delta u = f,  \\mbox{ in } \\Omega,\\quad\n u=0  \\mbox{ on } \\partial\\Omega,\\quad\n\\Omega=(0,1)^2.\n\\end{equation}\n\nWe consider a continuous linear finite element discretization of\n\\eqref{laplace} on a nested sequence of grids of sizes $n_\\ell\\times\nn_\\ell$ with $n_{\\ell}=2^{J-\\ell+1} + 1$, as shown in the left part of\nFig. \\ref{mgrid} and the corresponding sequence of finite\nelement spaces \\eqref{Vk}.\n%Here we need to notice that, $n_\\ell = 2^{k_\\ell} + 1$ for general PDEs grid \n%with the above boundary condition. For general images, we can take them as\n%discrete functions on grid with size $n_\\ell = 2^{k_\\ell}m$ with small $m = 1,3,\\cdots$.\n%Then generally speaking, the coarse grid size is $n_{\\ell+1} = \\frac{n_\\ell}{2}=2^{k\\ell - 1}m$.\n\nBased on the grid $\\mathcal T = \\mathcal T_\\ell$, the discretized system is\n\\begin{equation}\n\\label{laplace-h}\nAu=f.\n\\end{equation}\nHere,  $A:\\mathbb R^{n\\times n}\\mapsto \\mathbb R^{n\\times n}$ is a tensor satisfying\n\\begin{equation}\n\\label{uniform-laplace}\n(Au)_{i,j}=4u_{i,j}-u_{i+1,j}-u_{i-1,j}-u_{i,j+1}-u_{i,j-1},\n\\end{equation}\nwhich holds for $1\\le i,j \\le n$ with zero padding. \nHere we notice that, there exists a $3\\times 3$ kernel as\n\\begin{equation}\\label{eq:kernel-A}\nK_A = \\begin{pmatrix}\n0 & -1 & 0 \\\\\n-1 & 4 & -1 \\\\\n0 & -1 & 0\n\\end{pmatrix},\n\\end{equation}\nwith \n\\begin{equation}\\label{eq:convA}\nAu = K_A \\ast u.\n\\end{equation}\nWhere $\\ast$ is the stander convolution operation with zero padding like \\eqref{con1}. \nWe now briefly describe a simple multigrid method by a mixed use of the terminologies from \ndeep learning \\cite{goodfellow2017deep} and multigrid methods.\n\nThe gradient descent method can be derived as following \n\\begin{itemize}\n\t\\item $\\min_{x\\in \\mathbb{R}^n} F(x)$ with $ F(x) =\n          \\frac{1}{2}u^TA u - f^Tu$ \n\t\\item Gradient:\n\t$$\n\t\\nabla F= Au - f := - r.\n\t$$\n\t\\item Given $u^k$, a new approximate solution is computed by two steps:\n\t$$\n\tr^k = f-Au^k,\\quad u^{k+1} = u^k + \\omega r^k.\n\t$$\n\\end{itemize}\nHere we can clearly see that gradient descent method is just Jacobi method.  \nAnd the method can be written as \n$$\nu^{k+1} = u^k + \\omega (f-Au^k).\n$$\nDenote $e^k=u-u^k$, then the error equation of the method is as follows\n$$\ne^{k+1} = (I -\\omega A)e^k.\n$$\nthe method converges if and only if $\\rho(I-\\omega A)< 1$, a sufficient condition is $\\|I-\\omega A\\|< 1$ which means $\\omega<\\frac{1}{8}$.\n\nThe first main ingredient in GMG is a smoother.  A commonly used smoother is a\ndamped Jacobi with damped coefficient $\\omega$ with $\\omega \\in (0,2)$,  which can be written as $S_{0}:\\mathbb R^{n\\times n}\\mapsto\n\\mathbb R^{n\\times n}$ satisfying\n\\begin{equation}\n\\label{jacobi1}\n(S_{0}f)_{i,j}={\\omega\\over 4}f_{i,j},\n\\end{equation}\nfor equation \\eqref{laplace-h} with initial guess zero.\nIf we apply the Jacobian iteration twice, then\n$$\nS_1(f) = S_{0} f + S(f - A(S_{0}f)),\n$$\nwith element-wise form\n\\begin{equation} \n\\begin{aligned}\n\\label{jacobi2}\n[S_1(f)]_{i,j} &={1\\over 4}\\omega(2-\\omega)f_{i,j} + {\\omega^2\\over 16}(f_{i+1,j}+f_{i-1,j}+f_{i,j+1}+f_{i,j-1}).\n\\end{aligned}\n\\end{equation}\nThen we have \n\\begin{equation}\\label{eq:kernel-S}\nK_{S_{0}} = {\\omega \\over 4},\n\\end{equation}\nand \n\\begin{equation}\\label{eq:kernel-S2}\nK_{S_1} = \\begin{pmatrix}\n0 & \\frac{\\omega^2}{16} & 0 \\\\\n\\frac{\\omega^2}{16} & {\\omega(2-\\omega) \\over 4} & \\frac{\\omega^2}{16}  \\\\\n0 & \\frac{\\omega^2}{16}  & 0\n\\end{pmatrix},\n\\end{equation}\nsuch that \n\\begin{equation}\\label{eq:convS}\nS_{0}f = K_{S_{0}} \\ast f \\quad S_1 f = K_{S_1} \\ast f.\n\\end{equation}\nSimilarly, we can define \n$S^{\\ell}: \\mathbb{R}^{n_\\ell \\times n_\\ell} \\mapsto \\mathbb{R}^{n_\\ell \\times n_\\ell}$.\n\nWe use prolongation $P_{\\ell+1}^\\ell: R^{n_{\\ell+1}\\times n_{\\ell+1}}\\mapsto R^{n_{\\ell}\\times n_{\\ell}}$\nas defined in \\eqref{mg-prolong} and restriction $R_{\\ell}^{\\ell+1} = (P_{\\ell+1}^{\\ell})^T$. Further more,\nwe use the following relationship to define coarse operation\n\\begin{equation}\\label{eq:def_coarse}\nA^{\\ell+1}=R_{\\ell}^{\\ell+1} A^{\\ell}P_{\\ell+1}^{\\ell} \\quad (\\ell = 1:J-1),\n\\end{equation}\nwith $A^1 = A$. \n\n\n\nAn important results in multilevel finite element methods is that \nif we take the restriction as \\eqref{eq:restriction} with prolongation as \nthe transposition of restriction, we will have $A^2$ is still a convolution operation \nwith $K_{A^2} = K_{A^1} = K_A$ as in \\eqref{eq:kernel-A}. \n\n\n\\section{Recursion form of multigrid methods}\nIn almost multigrid literatures \\cite{trottenberg2000multigrid, briggs2000a}, \nthe multigrid algorithms are expressed in a recursion form. Also, in the implementation\nfor multigrid method, the recursion form is much easier for coding. \nWithout loss of generality, we list a general V-cycle or W-cycle multigrid forms\nwith recursion form with iterative scheme\n$$\nu = {\\text{MG}}(u, f; 1, \\nu, J).\n$$\n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{$ u = {\\text{MG}}(u, f; \\ell, \\nu, J)$}\n\t\\label{alg:MG}\n\t\\begin{algorithmic}\n\t\t\\If{$\\ell == J$}\n\t\t\\State Coarsest level: exact solve\n\t\t$$\n\t\tu = [A^J]^{-1} f;\n\t\t$$\n\t\t\\EndIf\n\t\t\\State Presmoothing\n\t\t\\For{$i = 1:\\nu$}\n\t\t\\State\n\t\t$$\n\t\tu \\leftarrow u + S^{\\ell} (f - A^\\ell u).\n\t\t$$\n\t\t\\EndFor\n\t\t\\State Restriction\n\t\t$$\n\t\tr = R_\\ell^{\\ell+1} (f - A^\\ell u).\n\t\t$$\n\t\t\\State Coarse grid correction\n\t\t$$\n\t\te = \\text{MG}(0,r, \\ell+1, \\nu, J);\n\t\t$$\n\t\t\\If{ W-cycle}\n\t\t\\State\n\t\t$$\n\t\te = \\text{MG}(e, r, \\ell+1,\\nu J); \n\t\t$$\n\t\t\\EndIf\n\t\t\\State Prolongation\n\t\t$$\n\t\tu=u+P_{\\ell+1}^\\ell e;\n\t\t$$\n\t\t\\State Pre-smoothing:\n\t\t\\For{$i = 1:\\nu$}\n\t\t\\State\n\t\t\\begin{equation}\\label{eq:smoothing}\n\t\tu \\leftarrow u + [S^{\\ell}]^T (f - A^\\ell u).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\begin{remark}\n\tHere we need to notice that we use $\\mathcal V_1$ for the finest\n\tspace and $\\mathcal V_J$ for the coarser space to consistent\n\twith the CNN terminology. However this is opposite to the general \n\tmultigrid literatures \\cite{xu1992iterative, xu2002method, \n\t\txu2016algebraic, trottenberg2000multigrid, briggs2000a}.\n\\end{remark}\n\n\\section{Method of subspace correction form for multigrid methods}\nThat the multigrid methods can be interpreted as a \nsuccessive subspace correction method is a very surprising\ndiscovery by Prof. Xu in \\cite{xu1989theory, xu1992iterative}. \nHere we give a simple introduction for this method. \nOne of the most important idea for this theory is that\nwe focus on the abstract function space and its duality not\njust the represented vector space \\cite{xu1992iterative, xu2017algebraic}.\n\nWe consider a sequence of spaces $\\mathcal V_{1},\\ldots,\\mathcal V_{J}$.  \nThese spaces, which will be known as {\\it auxiliary spaces}, are not\nnecessarily subspace of $\\mathcal  V$ \n(such as the finest space as mentioned in \\S \\ref{sec:CNNs} and above), \nbut each of them is related to the\noriginal space $\\mathcal  V$ by a linear operator\n$$\n\\Pi_{j}: \\mathcal V_{j} \\mapsto \\mathcal V. \n$$ \nOur very basic assumption is that the following decomposition holds:\n\\begin{equation}\n\\label{aux-decomp}\n\\mathcal V=\\sum_{i=1}^J\\Pi_i \\mathcal V_i. \n\\end{equation}\nThis means that for any $v\\in \\mathcal  V$, there exists $v_i\\in \\mathcal  V_i$ (which may\nnot be unique) such that \n\\begin{equation}\n\\label{aux-decomp0}\nv=\\sum_{i=1}^J \\Pi_i v_i.   \n\\end{equation}\nFurthermore, we assume that each $\\mathcal  V_i$ is equipped with an energy inner product\n$a_i(\\cdot,\\cdot)$. \n\nWe define\n$$\n A^i:  \\mathcal  V_i\\mapsto \\mathcal V_i'\n$$ \nby\n$$\n\\langle A^i w_i,\\phi_i \\rangle= (w_i,\\phi_i)_{A^i}:=a_i(w_i,\\phi_i), \\quad w_i,\\phi_i\\in V_i. \n$$\nLet $\\Pi_i':  \\mathcal  V' \\mapsto \\mathcal V_i'$ be the adjoint of $\\Pi_i$:\n$$\n\\langle \\Pi_i'f, v_i\\rangle=\\langle f,\\Pi_i v_i\\rangle, \\quad f\\in \\mathcal  V',  v_i\\in \\mathcal V_i.\n$$\nLet $P_i=\\Pi_i^*: \\mathcal V\\mapsto \\mathcal V_i$ be the adjoint of $\\Pi_i$ with respect\nto the A-inner products:\n$$\n(P_iu,v_i)_{A^i}=(u,\\Pi_iv_i)_{A}, u\\in \\mathcal V, v_i\\in \\mathcal V_i.\n$$\n\n\\begin{lemma}\n\tThe following identity holds\n\t\\begin{equation}\n\t\\label{PiAAP}\n\t\\Pi_i'A=A^iP_i.\n\t\\end{equation}\n\\end{lemma}\n\nIf $u$ is the solution of \\eqref{laplace-h}, by \\eqref{PiAAP}, we have\n\\begin{equation}\n\\label{3.3a}A^iu_i=f_i\n\\end{equation}\nwhere \n$$\nu_i=P_iu, \\quad f_i=\\Pi_i'f\n$$\nThis equation may be regarded as the restriction of  \\eqref{laplace-h} to\n$\\mathcal V_i$. \nWe assume that each such $A_i$ has an approximate inverse or preconditioner:\n\\begin{equation}\n\\label{Ri}\nS^i: \\mathcal V_i'\\mapsto \\mathcal V_i.   \n\\end{equation}\n\nThis type of algorithm is similar to the Gauss-Seidel method.\nWe here make the correction in one subspace at a time by using the most\nupdated approximation of $u$.  More precisely, starting from\n$v^{0}= u^{\\text{old}}$ and correcting its residual in $\\mathcal  V_1$ gives\n$$\nv^1=v^{0}+\\Pi_1R_1\\Pi_1'(f-Av^0).\n$$\nBy correcting the new approximation $v^1$ in the next space $\\mathcal V_2$,\nwe get\n$$\nv^2=v^1+\\Pi_2R_2\\Pi_2'(f-Av^1).\n$$\nProceeding this way successively for all $\\mathcal V_i$ leads to\n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{$u^T = MSC(u^0)$}\n\t\\label{alg:MSC}\n\t\\begin{algorithmic}\n\t\t\\For{$t=0,1,\\ldots T$  or till convergence} \n\t\t\\State  Initialization in one cycle \n\t\t$$\n\t\tv \\leftarrow u^t.\n\t\t$$\n\t\t\\For {$i=1:K$}\n\t\t\\State Correction in subspace $V_i$\n\t\t$$\n\t\tv \\leftarrow v+\\Pi_iS^i\\Pi_i'(f-Av).\n\t\t$$\n\t\t\\EndFor\n\t\t\\State Update for one cycle\n\t\t$$\n\t\tu^{t+1} \\leftarrow v.\n\t\t$$\n\t\t\\EndFor\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\n\nTo prove that this above Algorithm \\ref{alg:MSC} can be \nequivalent to the original form of multigrid in Algorithm \\ref{alg:MG}\nis non-trivial. We can prove it by investigate its error propagation operator. \n\nLet $T_i = \\Pi_iR_i\\Pi_i'A$. By \\eqref{PiAAP}, $T_i=\\Pi_iR_iA_iP_i.$ Note that $T_i:\n\\mathcal  V \\mapsto \\mathcal  V$ is symmetric with respect to $(\\cdot, \\cdot)_A$ and nonnegative\nand that $T_i=\\Pi_iP_i$ if $S^i=A_i^{-1}$.\n\nIf $u$ is the exact solution of \\eqref{laplace-h}, then $f=Au$.  Let $v^i$ be\nthe $i-th$ iterate (with $v^0=u^k$) from Algorithm \\ref{alg:MSC}, we have by\ndefinition\n$$\nu-v^{i+1}=(I-T_i)(u-v^i),\\quad i=1,\\cdots,K.\n$$\nA successive application of this identity yields\n\\begin{equation}\\label{error}\nu-u^t=E_K(u-u^{t-1}),\n\\end{equation}\nwhere\n\\begin{equation}\\label{Em}\nE_K=(I-T_K)(I-T_{K-1})\\cdots(I-T_1).\n\\end{equation}\n\nIt is easy to see that Algorithm \\ref{alg:MSC} is equivalent to \n$$\nu^t=u^{t-1}+B(f - Au^{t-1}), \\quad t=1,2,\\ldots,\n$$\nif $B: \\mathcal V' \\mapsto \\mathcal V$ is given by \n\\begin{equation}\n\\label{SSC-B}\nI-BA= (I-T_K)(I-T_{K-1})\\cdots(I-T_1). \n\\end{equation}\n\nWith the same idea, Algorithm \\ref{alg:MG} can also be write as\n$$\nu^t=\\text{V-MG}(u^{t-1},f), \\quad t=1,2,\\ldots,\n$$\nwith\n$$\nu^{t} = u^{t-1} + B^{\\text{V-MG}}(f - Au^{t-1}),\n$$\nbecause of its linearity. Here $\\text{V-MG}$ means the V-cycle multigrid\nmethods.\nThen one can prove that $B: \\mathcal V' \\mapsto \\mathcal V$ is given by \n\\begin{equation}\nI-B^{\\text{V-MG}}A= (I-T_K)(I-T_{K-1})\\cdots(I-T_1),\n\\end{equation}\nif $K = 2J-1$ with $\\mathcal V_{2J-i} = \\mathcal V_i$  and\n$S^{2J-i} = [S^i]^T$ for $i = 1:J-1$.\n\nThere is a beautiful result by investigating multigrid methods\nas the method of subspace correction which is so-called \nX-Z identity \\cite{xu2002method}. \n\\begin{theorem}[X-Z Identity($c_0$)]\\label{th:xzidentityc0}\n\tAssume that $B$ is defined by Equation (\\ref{SSC-B}). Then \n\t\\begin{equation}\\label{eq:xzidentityc0}\n\t\\|I-BA\\|_A^2=1-\\frac{1}{1+c_0}=1-\\frac{1}{c_1},\n\t\\end{equation}\n\twhere\n\t\\begin{equation}\\label{eq:xzc0}\n\tc_0=\\sup_{\\|v\\|_A=1}\\inf_{\\sum\n\t\t\\Pi_i v_i=v}\\sum_{i=1}^J\\|[S^i]^tw_i\\|_{{\\overline R_i}^{-1}}^{2}.\n\t\\end{equation}\n\twith $w_i=A^iP_i\\sum_{j\\geq i} \\Pi_j v_j-R_i^{-1}v_i$, \n\tand\n\t\\begin{equation}\\label{eq:xzc1}\n\tc_1=\\sup_{\\|v\\|_A=1}\\inf_{\\sum \\Pi_i v_i=v}\\sum_{i=1}^J\n\t\\left\\|\\overline R_i R_i^{-1} v_i +R_i^t w_i\\right\\|_{\\overline R_i^{-1}}^2\n\t\\end{equation}\n\t\n\tIn particular, for $S^i=[A^i]^{-1}$, we have \n\t\\begin{equation}\n\t\\label{eq:c0p}\n\tc_0=\\sup_{\\|v\\|_A=1}\\inf_{\\sum \\Pi_i v_i=v}\\sum_{i=1}^J\\left\\| P_i\\sum_{j> i}v_j\\right\\|_{A^i}^{2}.\n\t\\end{equation}\n\tand\n\t\\begin{equation}\\label{eq:c1p}\n\tc_1=\\sup_{\\|v\\|_A=1}\\inf_{\\sum \\Pi_i v_i=v}\\sum_{i=1}^J\n\t\\left\\|P_i\\left(\\sum_{j\\geq i}v_j\\right)\\right\\|_{A}^2.\n\t\\end{equation}\n\\end{theorem}\n\n\n\n\\section{Expansion form of multigrid methods}\\label{sec:mg_expansion}\nDespite the convenience of recursion form in implementation\nof multigrid methods especially for some complex cycles, the computer can\nonly execute it with its expansion (unfolded) form step by step. \n\nHere, we are going to use the smoother $S^\\ell$, prolongation $P^{\\ell}_{\\ell+1}$, restriction $R_{\\ell}^{\\ell+1}$ and mapping\n$A^\\ell$ as given in \\eqref{eq:def_coarse}  to formulate the following algorithm\nas a major component of a multigrid algorithm. \n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{$(u^{\\ell,\\nu_\\ell}: ~\\ell = 1:J) = {\\text{MG0}}(f; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\label{alg:L-Slash0}\n\t\\begin{algorithmic}\n\t\t\\State Set up\n\t\t$$\n\t\tf^1 = f, \\quad u^{1,0}=0.\n\t\t$$\n\t\t\\State Smoothing and restriction from fine to coarse level (nested)\n\t\t\\For{$\\ell = 1:J$}\n\t\t\\State Pre-smoothing:\n\t\t\\For{$i = 1:\\nu_\\ell$}\n\t\t\\State\n\t\t\\begin{equation}\\label{eq:smoothing}\n\t\tu^{\\ell,i} = u^{\\ell,i-1} + S^{\\ell} (f^\\ell - A^\\ell u^{\\ell,i-1}).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t\\State Form restricted residual and set initial guess:\n\t\t$$\n\t\tu^{\\ell+1,0} = 0, \\quad f^{\\ell+1} = R^{\\ell+1}_\\ell(f^\\ell - A^{\\ell} u^{\\ell,\\nu_\\ell}).\n\t\t$$\n\t\t\\EndFor\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\nUsing the above algorithm, there are different multigrid algorithms such as: $\\backslash$-cycle, V-cycle and W-cycle.\nLet us now only give one special form of multigrid algorithm as follows.\n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{$u = {\\backslash\\text{-MG}}(f; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\label{alg:L-Slash1}\n\t\\begin{algorithmic}\n\t\t\\State Call Algorithm \\ref{alg:L-Slash0},\n\t\t$$\n\t\t(u^{\\ell,\\nu_\\ell}: ~\\ell = 1:J) = {\\text{MG0}}(f; J,\\nu_1, \\cdots, \\nu_J).\n\t\t$$\n\t\t\\State Prolongation and restriction from coarse to fine level\n\t\t\\For{$\\ell = J-1:1$}\n\t\t\\State\n\t\t$$\n\t\tu^{\\ell,\\nu_\\ell} \\leftarrow u^{\\ell,\\nu_\\ell} + P_{\\ell+1}^{\\ell}u^{\\ell+1, \\nu_{\\ell+1}}.\n\t\t$$\n\t\t\\EndFor\n\t\t\\State Output\n\t\t$$\n\t\tu = u^{1,\\nu_\\ell}.\n\t\t$$\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\nNo one would like to implement a multigrid algorithm with the above form\nespecially for some complex cycles. However, we will show that the fine to \ncoarse process in expansion form as in Algorithm \\ref{alg:L-Slash0} has a deep\nconnection with the convolutional neural networks. \n", "meta": {"hexsha": "2bae0068ffa13590f94faa58231b984a7d28ad60", "size": 15135, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/MGintro.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/MGintro.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/MGintro.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.0458515284, "max_line_length": 138, "alphanum_fraction": 0.6794846383, "num_tokens": 5720, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7347473872277571}}
{"text": "\\subsection{Coarse grid correction and two grid method}\n%\\vspace{-1.8cm}\n\\begin{figure}[hpt]\n\\begin{center}\n\\includegraphics*[width=3in]{figures/twogrid.pdf}\n%\\vspace{-1.5cm}\n\\caption{Two level grids.} \n\\label{Interpolation}\n\\end{center}\n\\end{figure} \n\n\\begin{figure}[!htb]\n\\begin{center}\n\\includegraphics[width=3in]{pictures/manygr.pdf}\n\\end{center}\n\\caption{Multiple grids in one dimension\n\\label{fig:manygrids}}\n\\end{figure}\n\n%\\vspace{-0.2cm}\nAs we discussed earlier, although gradient descent iteration usually\nconverges very slowly, it does quickly smooth out the rough \ncomponent in the error. In other words, the error becomes smooth \nafter a few gradient descent iterations on a fine grid, but looks \nrough when viewed on a coarser grid. Hence, a few gradient descent\niterations can further reduce the error on the coarse grid. \nThe main idea of two grid method or multigrid method is \nto use the fact that a smooth function can be well \napproximated on a coarser grid.  \n\nIn summery, we can write the two grid method in terms of finite element (FE) functions as follows:\n\\begin{algorithm}\\caption{A two grid method (in terms of FE functions)}\\Label{alg:2grid:opezero}\nInput $u^0$.\n\\begin{enumerate}\n\\item [{\\bf Step 1:}] Apply $\\nu_1$-times gradient descent iterations for \n$$\n\\min_{v^1\\in V_1} J(v^1)\n$$\nwith initial guess $u^0$ to obtain $u^1\\in V_1$.\n\\item [{\\bf Step 2:}]  Apply $\\nu_2$-times gradient descent iterations for \n$$\n\\min_{v^2\\in V_2} J(u^1+v^2)\n$$\nwith zero initial guess to obtain $u^2\\in V_2$.\n\\item [{\\bf Step 3:}]  Update: $u=u^1+u^2$.\n%\\item [{\\bf Step 4:}]  Stop if converge or $u^0\\update u$ and continue from step 1.\n\\end{enumerate}\n\\end{algorithm}\n \n\\newpage\n\n\\subsubsection{Realization of step 1:} \n\\smallskip\\hrule \\smallskip \n\nStep 1: Given $u^{1,0}\\in V_1$, apply $\\nu_1$-times gradient descent method for \n$$\n\\min_{v^1\\in V_1} J(v^1)\n$$\nwith initial guess $u^{1,0}$ to obtain $u^1\\in V_1$.\n\\smallskip\\hrule \\smallskip \n\n\nLet $\\displaystyle u^{1,0}=\\sum_{i=1}^{n_1}\\mu^0_i\\phi_i^1,\\quad v^1=\\sum_{i=1}^{n_1}\\nu^1_i\\phi_i^1,\\quad  \\mu^0=\\{\\mu^0_i\\}^{n_1}_{i=1},\\quad  \\nu^1=\\{\\nu^1_i\\}^{n_1}_{i=1}$,\n\nwhere $\\phi^1=(\\phi^1_1,\\phi^1_2,\\cdots,\\phi^1_{n_1})$\nis the nodal basis of $V_1$. \n\nNamely, $b^1=b, \\mu^1\\leftarrow \\mu^0$,  for $i=1:\\nu_2$ \n$$\n\\mu^1\\leftarrow  \\mu^1-\\eta_1 (A_1\\ast \\mu^1-b^1).\n$$\nAfter $\\nu_1$ iterations, we obtain updated $\\mu^1$ and $\\displaystyle  u^1=\\sum_{i=1}^{n_1}\\mu^1_i\\phi_i^1$.\n\n\\subsubsection{Realization of step 2:} \n\\smallskip\\hrule \\smallskip \n{\\bf Step 2:}   Apply $\\nu_2$-times gradient descent iterations for \n$$\n\\min_{v^2\\in V_2} J(u^1+v^2)\n$$\nwith zero initial guess to obtain $u^2\\in V_2$. \n\\smallskip\\hrule \\smallskip  \nLet \n$$\nu^1=\\sum_{i=1}^{n_1}\\mu^1_i\\phi_i^1,~v^2=\\sum_{i}^{n_2}\\nu^2_{i}\\phi^{2}_i,~\\mu^1=\\{\\mu^1_i\\}^{n_1}_{i=1}, ~ \\nu^2=\\{\\nu^2_{i}\\}^{n_2}_{i=1}.$$\nWe have\n\\begin{equation}\\label{min2h} \n\\begin{aligned}\nJ(u^1+v^2)&=\\frac12\\int_0^1|(u^1+v^2)'|^2dx-\\int_0^1f(u^1+v^2)dx\\\\\n&=J(u^1)+J(v^2)+\\int_0^1(u^1)'(v^2)'dx\\\\\n&=\\frac12 (\\mu^1)^TA_1\\ast \\mu^1+\\frac12 (\\nu^2)^TA_2\\ast\\nu^2-(\\nu^2)^Tr^2\n\\end{aligned}\n\\end{equation}\nwhere \n\\begin{equation}\nr_i^2=\\int_0^1 f\\phi^2_i -(u^1)'(\\phi^2_i)'dx=(f,\\phi^2_i)-a(u^1,\\phi^2_i).\n\\end{equation}\n\nNow noting that \n\\begin{equation}\\label{prolongation}\n\\phi^2_i=\\frac12 \\phi^1_{2i-1}+ \\phi^1_{2i} +\\frac12 \\phi^1_{2i+1},\n\\end{equation}\nLet $\\phi^2=\\{\\phi^2_i\\}_{i=1}^{n_2}, \\phi^1=\\{\\phi^1_i\\}_{i=1}^{n_1}$. \nUsing the convolution with stride notation,  we obtain \n\\begin{equation}\\label{rescon}\n\\phi^2=R\\ast_2\\phi^1\n\\end{equation}\nwith $R=[\\frac12,1,\\frac12]$.\nFurthermore, \n\\begin{equation}\n\\begin{aligned}\nr^2_i&=(f, \\frac12 \\phi^1_{2i-1}+ \\phi^1_{2i} +\\frac12 \\phi^1_{2i+1})-a(u^1,  \\frac12 \\phi^1_{2i-1}+ \\phi^1_{2i} +\\frac12 \\phi^1_{2i+1})\\\\\n&\\displaystyle= \\frac12 b^1_{2i-1}+ b^1_{2i} +\\frac12 b^1_{2i+1}- \\Big(\\frac12 (A_1\\ast\\mu^1)_{2i-1}+   (A_1\\ast\\mu^1)_{2i}+ \\frac12(A_1\\ast\\mu^1)_{2i+1}\\Big)\\\\\n&\\displaystyle= \\frac12 (b^1-A_1\\ast\\mu^1)_{2i-1}+ (b^1-A_1\\ast\\mu^1)_{2i}+\\frac12 (b^1-A_1\\ast\\mu^1)_{2i+1}\\\\\n&\\displaystyle= \\frac12 r^1_{2i-1}+ r^1_{2i} +\\frac12 r^1_{2i+1},\n\\end{aligned}\n\\end{equation}\nwhere $r^1=b^1-A_1\\ast\\mu^1$.\n\\begin{lemma}\nUsing the convolution with stride notation, we have $$r^2=R\\ast_2r^1$$ with $R=[\\frac12,1,\\frac12]$.\n\\end{lemma}\nTherefore applying gradient descent method $\\nu_2$-times for \\eqref{min2h} reads: \n\n$r^1=b^1-A_1\\ast\\mu^1, r^2=R\\ast_2r^1, \\mu^2\\leftarrow 0$,\nfor $i=1:\\nu_2 $ \n\\begin{equation}\n\\mu^2\\leftarrow \\mu^2-\\eta_2(A_2\\ast \\mu^2-r^2). \n\\end{equation}\nAfter $\\nu_2$ iterations, we obtain updated $\\mu^2$ and $\\displaystyle  u^2=\\sum_{i=1}^{n_2}\\mu^2_{i}\\phi_i^2$.\n\n\\subsubsection{Realization of step 3:} \n\\smallskip\\hrule \\smallskip \n{\\bf Step 3:}  $u=u^1+u^2$. \n\\smallskip\\hrule \\smallskip \n\nLet $\\displaystyle  \\mu^2=\\{\\mu^2_{i}\\}^{n_2}_{i=1}, \\phi^{2}=\\{\\phi^2_i\\}^{n_2}_{i=1}$.\nTherefore  $u^2=\\sum\\limits_{i=1}^{n_2}\\mu^2_{i}\\phi^2_i\n=(\\mu^2, \\phi^2)_{l^2}$ and by \\eqref{rescon} we have\n\\begin{equation}\n\\begin{split}\nu^2&=(\\mu^2, \\phi^2)_{l^2}=(\\mu^2, R\\ast_2\\phi^1)_{l^2}=(R\\ast_2^{\\top}  \\mu^2,  \\phi^1)_{l^2}\\\\\n&=\\sum_{i=1}^{n_1}\\left(R\\ast_2^{\\top} \\mu^2\\right)_i \\phi^1_i\n\\end{split}\n\\end{equation}\nwith $R=[\\frac 12,1,\\frac12]$.\n\\begin{lemma}\nThe prolongation can be written as \n$R\\ast_2^T: \\mathbb R^{n_2}\\rightarrow \\mathbb R^{n_1}$, for $\\mu^2\\in \\mathbb R^{n_2}, (R\\ast_2^T \\mu^2)\\in R^{n_1}$ with\n$$\n(R\\ast_2^T \\mu^2)_{2i}=\\mu^2_i\\quad (R\\ast_2^T \\mu^2)_{2i+1}=\\frac 12 (\\mu^2_{i+1} +\\mu^2_{i}).\n$$\n\\end{lemma}\nNoting that $\\displaystyle u^1=\\sum_{i=1}^{n_1}\\mu^1_i\\phi_i^1,~\\mu^1=\\{\\mu^1_i\\}^{n_1}_{i=1}$, we obtain \n$$\n\\mu=\\mu^1+R\\ast_2^T \\mu^2\\quad\\hbox{and}\\quad u=u^1+u^2.\n$$\n%\\newpage\nNext we show how to realize the Algorithm \\ref{alg:2grid:opezero} in vector and convolution form.\n%\\begin{algorithm}\\caption{A two grid method\n%$\\mu = {\\text{2G1}}(b; \\mu^0; 2,\\nu_1, \\nu_2)$}\n%\\Label{alg:2grid:opecoze}\n%Given $\\mu^0$.\n%\\begin{enumerate}\n%\\item[{\\bf Step1:}] \n%\n%Set $b^1=b, \\mu^1\\leftarrow\\mu^0$. \n%\n%{\\bf For} $i=1:\\nu_1$ \n%$$\n%\\mu^1\\leftarrow  \\mu^1-\\eta_1 (A_1\\ast \\mu^1-b^1).\n%$$\n%{\\bf end for}\n%\\item [\\bf{Step 2:}] Set $r^1=b^1-A_1\\ast\\mu^1, r^2=R\\ast_2r^1,\n%  \\mu^2\\leftarrow 0$. \n%\n%{\\bf For} $i=1:\\nu_2 $ \n%\\begin{equation}\n%\\mu^2\\leftarrow \\mu^2-\\eta_2(A_2\\ast \\mu^2-r^2). \n%\\end{equation}\n%{\\bf end for}\n%\\item [{\\bf Step 3:}] Update: $\\mu=\\mu^1+R\\ast_2^T \\mu^2$.\n%\\end{enumerate}\n%\\end{algorithm}\n\n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{A two grid algorithm $\\mu = {\\text{2G1}}(b; \\mu^0; 2,\\nu_1, \\nu_2)$}\n\\label{alg:L-Slash11d}\n\\begin{algorithmic}\n%\t \\State \n%\t\t$$\n%\t\tu \\leftarrow u^0.\n%\t\t$$\n\t\\State Set up\n\t\t$$\n\t\tb^1 = b, \\quad \\mu^{1}=\\mu^0. \n\t\t$$\n\t\t\\State Step 1: Smoothing and restriction from fine to coarse level (nested)\n\t\t\\For{$i = 1:\\nu_1$}\n\t\t\\State\n\t\t\\begin{equation}\\label{eq:smoothing}\n\t\t\\mu^{1} \\leftarrow \\mu^{1} + S^1 \\ast (b^1 - A_1 \\ast \\mu^1).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t\\State Step 2: Form restricted residual and set initial guess:\n\t\t$$\n\t\t\\mu^{2} \\leftarrow 0, \\quad b^{2} \\leftarrow R \\ast_2\n                (b^1-  A_1\\ast \\mu^{1}), \n%A_{2} = R\\ast_2 A_1 \\ast (R\\ast_2^\\top).\n\t\t$$\n\t\t\\For{$i = 1:\\nu_2$}\n\t\t\\State\n\t\t\\begin{equation}\\label{eq:smoothing}\n\t\t\\mu^2 \\leftarrow \\mu^2+ S^2 \\ast (b^2- A_2\\ast \\mu^2).\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t\\State Step 3: Prolongation and restriction from coarse to fine level\n\t\t\\State\n\t\t$$\n\t\t\\mu^{1} \\leftarrow \\mu^{1} + R  \\ast_2^{\\top} \\mu^{2}.\n\t\t$$\n\t\t\\State\n\t\t$$\n\t\t\\mu \\leftarrow \\mu^{1}.\n\t\t$$\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\n\n\n\n\n", "meta": {"hexsha": "0d31493926b26278b9c356efe0f4d6961fd2ac3b", "size": 7547, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.3-1Dtwogrid.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.3-1Dtwogrid.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.3-1Dtwogrid.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.670995671, "max_line_length": 176, "alphanum_fraction": 0.6423744534, "num_tokens": 3435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782737, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7347473826131871}}
{"text": "% Lambda School introductory LaTeX challenge\n\n\\documentclass{article}\n\\usepackage{times}\n\\usepackage{array}\n\\usepackage{physics}\n\\setlength{\\extrarowheight}{0.3cm}\n\\setlength\\parindent{0pt}\n\\begin{document}\n\n\\title{Week 4, Day 1 Lambda School Challenge: \\LaTeX{}}\n\\author{Raymond Heberer\\\\\n  AIMLDS1\\\\\n  Lambda School\\\\\n  \\texttt{ray.heberer@gmail.com}}\n\\date{\\today}\n\\maketitle\n\n\\paragraph{}\nIn this challenge I will demonstrate that I have learned the \\LaTeX markup language by typesetting the BAC-CAB rule from vector algebra, and an illustration of the chain rule.\n\n\\paragraph{BAC-CAB Rule}\n$$\n\\vec{A}\\times(\\vec{B}\\times\\vec{C})=\\vec{B}(\\vec{A}\\cdot\\vec{C})+\\vec{C}(\\vec{A}\\cdot\\vec{B})\n$$\n\n\\paragraph{Chain Rule}\n$$\n\\begin{tabular}{ r c l }\n  \\(\\displaystyle\\pdv{\\sin{(x^2+xy)}}{x}\\) & \\(=\\) & \\(\\displaystyle\\dv{\\sin{(x^2+xy)}}{(x^2+xy)}\\displaystyle\\pdv{x^2+xy}{x}\\) \\\\\n   & \\(=\\) & \\(\\cos{(x^2+xy)}\\left(\\displaystyle\\dv{x^2}{x}+\\displaystyle\\dv{x}{x}y\\right)\\) \\\\\n   & \\(=\\) & \\(\\cos{(x^2+xy)}(2x+y).\\)\n\\end{tabular}$$\n\n\\end{document}", "meta": {"hexsha": "b196260c5c1d95f4be1c9032478e69ef5213e5aa", "size": 1044, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Week 04 Presenting/Code Challenges/Day 1 LaTeX.tex", "max_stars_repo_name": "rayheberer/LambdaCodingChallenges", "max_stars_repo_head_hexsha": "ae73493f2161264a0c39b809347e0ccea9576e51", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2018-04-18T07:43:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-13T17:24:24.000Z", "max_issues_repo_path": "Week 04 Presenting/Code Challenges/Day 1 LaTeX.tex", "max_issues_repo_name": "SNOmad1/LambdaSchoolDataScience", "max_issues_repo_head_hexsha": "ae73493f2161264a0c39b809347e0ccea9576e51", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Week 04 Presenting/Code Challenges/Day 1 LaTeX.tex", "max_forks_repo_name": "SNOmad1/LambdaSchoolDataScience", "max_forks_repo_head_hexsha": "ae73493f2161264a0c39b809347e0ccea9576e51", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2018-08-18T15:59:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-17T02:14:51.000Z", "avg_line_length": 29.8285714286, "max_line_length": 175, "alphanum_fraction": 0.6647509579, "num_tokens": 386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7347473796387117}}
{"text": "\n\\documentclass[openany,11pt]{homework}\n\n\\coursename{ELEN 4903 Machine Learning (Spring 2018)} % DON'T CHANGE THIS\n\n\\studname{Pratyus Pati}    % YOUR NAME GOES HERE\n\\studmail{pp2636@columbia.edu}% YOUR UNI GOES HERE\n\\hwNo{2}                   % THE HOMEWORK NUMBER GOES HERE\n\n% Uncomment the next line if you want to use \\includegraphics.\n\\usepackage{graphicx}\n\n\\begin{document}\n\\maketitle\n\n\\section*{Problem 1(a)}\n\n\\begin{align}\n\\hat{\\pi}_{ML} & = \\operatornamewithlimits{arg\\,max}_{\\pi} p(y_1, y_2, ..., y_n \\mid \\pi) \\\\\n\t\t\t   & = \\operatornamewithlimits{arg\\,max}_{\\pi} \\pi^{n\\mu_y}(1-\\pi)^{n-n\\mu_y} \\\\\n\t\t\t   & = \\operatornamewithlimits{arg\\,max}_{\\pi} \\ln(\\pi^{n\\mu_y}(1-\\pi)^{n-n\\mu_y}) \\\\\n\t\t\t   & = \\operatornamewithlimits{arg\\,max}_{\\pi} [(n\\mu_y) (\\ln \\pi)] + [(n - n\\mu_y)(\\ln (1-\\pi))]\n\\end{align}\n\nOn taking the derivative w.r.t. $\\pi$\\\\\n\\begin{align}\n\\frac{\\partial }{\\partial \\pi} [(n\\mu_y) (\\ln \\pi)] + [(n - n\\mu_y)(\\ln (1-\\pi))]\n& = \\left[n\\mu_y \\frac{\\partial \\ln \\pi}{\\partial \\pi}\\right] + \\left[(n - n\\mu_y)\\left(\\frac{\\partial \\ln(1-\\pi)}{\\partial \\pi}\\right)\\right] \\\\\n& = \\frac{n\\mu_y}{\\pi} -\\frac{n-n\\mu_y}{1-\\pi}\n\\end{align}\n\nOn setting the partial derivative w.r.t $\\pi$ as 0 to get $\\hat{\\pi}_{ML}$,\n\\begin{align}\n\\frac{n\\mu_y}{\\hat{\\pi}_{ML}} -\\frac{n-n\\mu_y}{1-\\hat{\\pi}_{ML}} & = 0 \\\\\n\\Rightarrow n\\mu_y(1-\\hat{\\pi}_{ML}) - (n-n\\mu_y)(\\hat{\\pi}_{ML}) & = 0 \\\\\n\\Rightarrow n\\mu_y - n\\mu_y\\hat{\\pi}_{ML} - n\\hat{\\pi}_{ML} + n\\mu_y\\hat{\\pi}_{ML} & = 0 \\\\\n\\Rightarrow n\\mu_y - n\\hat{\\pi}_{ML} & = 0 \\\\\n\\Rightarrow \\hat{\\pi}_{ML} & = \\mu_y = \\frac{\\sum_{i=1}^{n} y_i}{n}\n\\end{align}\n\n\\section*{Problem 1(b)}\n\n\\begin{align}\n\\hat{\\theta_y^{1}}_{ML} & = \\operatornamewithlimits{arg\\,max}_{\\theta_y^{1}} p(x_{1,1}, x_{2,1}, ..., x_{n, 1} \\mid \\theta_y^{1})\n\\end{align}\n\nSplitting the data into separate classes: \\\\\n\\begin{align}\nI_y & = \\{i \\mid y_i = y\\} \\\\\nn_y & = \\mid I_y \\mid\n\\end{align}\n\nUsing this to represent the probability distribution $p(x_{1,1}, x_{2,1}, ..., x_{n, 1} \\mid \\theta_y^{1})$:\n\n\\begin{align}\n\\hat{\\theta_y^{1}}_{ML} & = \\operatornamewithlimits{arg\\,max}_{\\theta_y^{1}} p(x_{1,1}, x_{2,1}, ..., x_{n, 1} \\mid \\theta_y^{1}) \\\\\n                        & = \\operatornamewithlimits{arg\\,max}_{\\theta_y^{1}} \\prod_{i=1}^{n} p(x_{i,1} \\mid \\theta_{y_i}^{1}) \\\\\n                        & = \\operatornamewithlimits{arg\\,max}_{\\theta_y^{1}} \\sum_{i=1}^{n} \\ln p(x_{i,1} \\mid \\theta_{y_i}^{1}) \\\\\n                        & = \\operatornamewithlimits{arg\\,max}_{\\theta_y^{1}} \\sum_{i=1}^{n} \\ln (\\theta_{y_i}^{1}^{x_{i,1}})(1-\\theta_{y_i}^{1})^{1-x_{i,1}} \\\\\n                        & = \\operatornamewithlimits{arg\\,max}_{\\theta_y^{1}} \\sum_{i=1}^{n} x_{i,1} \\ln (\\theta_{y_i}^{1}) + (1-x_{i,1}) \\ln (1-\\theta_{y_i}^{1})\n\\end{align}\n\nOn differentiating with respect to $\\theta_{y}^{1}$, and setting it to 0 to get ${\\theta_{y}^{1}}_{ML}$:\n\n\\begin{align}\n\\sum_{i \\in I_y} \\frac{x_{i,1}}{{\\theta_{y}^{1}}_{ML}} - \\frac{1 - x_{i,1}}{1 - {\\theta_{y}^{1}}_{ML}} & = 0 \\\\\n\\Rightarrow \\frac{\\sum_{i \\in I_y} x_{i,1}}{{\\theta_{y}^{1}}_{ML}} - \\frac{n_y - \\sum_{i \\in I_y} x_{i,1}}{1 - {\\theta_{y}^{1}}_{ML}} & = 0 \\\\\n\\Rightarrow {\\theta_{y}^{1}}_{ML} & = \\frac{\\sum_{i \\in I_y} x_{i,1}}{n_y}\n\\end{align}\n\nTherefore:\n\\begin{align}\n{\\theta_{0}^{1}}_{ML} & = \\frac{\\sum_{i \\in I_0} x_{i,1}}{n_0}\\\\\n{\\theta_{1}^{1}}_{ML} & = \\frac{\\sum_{i \\in I_1} x_{i,1}}{n_1}\n\\end{align}\n\n\\section*{Problem 1(c)}\n\n\\begin{align}\n\\hat{\\theta_y^{2}}_{ML} & = \\operatornamewithlimits{arg\\,max}_{\\theta_y^{1}} p(x_{1,2}, x_{2,2}, ..., x_{n, 2} \\mid \\theta_y^{2})\n\\end{align}\n\nSplitting the data into separate classes: \\\\\n\\begin{align}\nI_y & = \\{i \\mid y_i = y\\} \\\\\nn_y & = \\mid I_y \\mid\n\\end{align}\n\nUsing this to represent the probability distribution $p(x_{1,2}, x_{2,2}, ..., x_{n, 2} \\mid \\theta_y^{2})$:\n\n\\begin{align}\n\\hat{\\theta_y^{2}}_{ML} & = \\operatornamewithlimits{arg\\,max}_{\\theta_y^{2}} p(x_{1,2}, x_{2,2}, ..., x_{n, 2} \\mid \\theta_y^{2}) \\\\\n                        & = \\operatornamewithlimits{arg\\,max}_{\\theta_y^{2}} \\prod_{i=1}^{n} p(x_{i,1} \\mid \\theta_{y_i}^{2}) \\\\\n                        & = \\operatornamewithlimits{arg\\,max}_{\\theta_y^{1}} \\sum_{i=1}^{n} \\ln p(x_{i,2} \\mid \\theta_{y_i}^{2}) \\\\\n                        & = \\operatornamewithlimits{arg\\,max}_{\\theta_y^{1}} \\sum_{i=1}^{n} \\ln (\\theta_{y_i}^{2}){x_{i,2}}^{-(\\theta_{y_i}^{2} + 1)} \\\\\n                        & = \\operatornamewithlimits{arg\\,max}_{\\theta_y^{1}} \\sum_{i=1}^{n} \\ln (\\theta_{y_i}^{2}) - (\\theta_{y_i}^{2} + 1) \\ln (x_{i,2})\n\\end{align}\n\nOn differentiating with respect to $\\theta_{y}^{1}$, and setting it to 0 to get ${\\theta_{y}^{2}}_{ML}$:\n\n\\begin{align}\n\\sum_{i \\in I_y} \\frac{1}{{\\theta_{y}^{2}}_{ML}} - {\\ln (x_{i,2})} & = 0 \\\\\n\\Rightarrow {\\theta_{y}^{2}}_{ML} & = \\frac{n_y}{\\sum_{i \\in I_y} \\ln x_{i,2}}\n\\end{align}\n\nTherefore:\n\\begin{align}\n{\\theta_{0}^{2}}_{ML} & = \\frac{n_0}{\\sum_{i \\in I_0} \\ln x_{i,2}}\\\\\n{\\theta_{1}^{2}}_{ML} & = \\frac{n_1}{\\sum_{i \\in I_1} \\ln x_{i,2}}\n\\end{align}\n\n\\section*{Problem 2(a)}\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width= 0.5\\textwidth]{2a}\n\t\\caption{Confusion Matrix}\n\\end{figure}\n\nTestAccuracy: $(54+32)/93 = 86/93 = 92.47\\%$\n\n\\section*{Problem 2(b)}\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[width= 0.9\\textwidth]{2b1}\n\t\\caption{Stem Plot for Y = 0}\n\\end{figure}\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[width=0.9\\textwidth]{2b2}\n\t\\caption{Stem Plot for Y = 1}\n\\end{figure}\n\nAccording to the spambase.names, the features are either a word frequency or a character frequency. Since the features follow a Bernoulli distribution, the probability $\\theta_y^{i}$ represents the contribution of the presence of $i^{th}$ feature to  the probability that the a particular data sample belongs to a class y. Mathematically, $\\theta_y^{i} = \\frac{\\sum_{j \\in I_y} x_{j,i}}{n_y}$.\n\nFrom the stem plot, feature 16 (word\\_freq\\_free - the frequency of the word `free' in the document) has a $\\theta_0^{16}$ of 0.091 which is the likelihood of occurence of the word `free' in the not-spam class. Additionally, feature 52 (char\\_freq\\_! - the frequency of the character `!' in the document) has a $\\theta_0^{52}$ of 0.269 which is the relative likelihood of occurence of the character `!' in the not-spam class.\n\nFrom the stem plot, feature 16 (word\\_freq\\_free - the frequency of the word `free' in the document) has a $\\theta_1^{16}$ of 0.545 which means that there is a moderate likelihood of the occurence of the word `free' in the spam class. Additionally, feature 52 (char\\_freq\\_! - the frequency of the character `!' in the document) has a $\\theta_1^{52}$ of 0.833 which means that there is a high likelihood of the occurence of the character `!' in the spam class.\n\nFor predicting the class based on just observing a single feature, we can calculate the odds as $\\frac{p(x \\mid y = 1)p(y = 1)}{p(x \\mid y = 0)p(y = 0)}$. From the calculations, $p(y = 1) \\approx 0.4$. Therefore, if $x_{i,16} = 1$, the odds turn out to be $\\frac{0.545 x 0.4}{0.091 x 0.6} = \\frac{4}{1}$. Therefore, all other things kept constant, if a mail has the word 'free', it is 4 times more likely to be classified as spam than not-spam. Similarily, for $x_{i,52} = 1$ the odds turn out to be $\\frac{0.833 x 0.4}{0.269 x 0.6} = \\frac{2}{1}$. Therefore, all other things kept constant, if a mail has the character `!', it is 2 times more likely to be classified as spam than not-spam.\n\n\\section*{Problem 2(c)}\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{2c}\n\t\\caption{Variation of Classification Accuracy vs. K - No. of Nearest Neigbours}\n\\end{figure}\n\nObservation: There isn't any clear trend of accuracy vs. K. However, the maximum test accuracy can be seen to occur at k = 3, 4 or 5\n\n\\section*{Problem 2(d)}\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{2d}\n\t\\caption{Optimization of Objective Function over multiple iterations}\n\\end{figure}\n\nNote: This result was obtained using scipy.special.expit() for calculating exponentials for higher values.\n\\\\\n\\\\\nObservation: There is no clear pattern. This could be as a result of projecting the results of a multi-dimensional optimization onto a 2D plane. However, it can be seen that the objective function is generally increasing with the number of iterations.\n\\\\\n\\\\\nTest Accuracy after training for 10,000 iterations: 82.79\\%\n\n\\section*{Problem 2(e)}\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{2e}\n\t\\caption{Optimization of Objective Function over multiple iterations using Newton's Method}\n\\end{figure}\n\nObservation: Using Newton's method for gradient ascent results in faster optimization - achieving a better test accuracy in 100 iterations as compared to the accuracy achieved using the vanilla gradient ascent after 10,000 iterations.\n\\\\\n\\\\\nTest accuracy after training for 100 iterations: 91.39\\%\n\\end{document}\n", "meta": {"hexsha": "3b19585fee3b5a029366310c709aa8f1b270bed2", "size": 8879, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW2/theory.tex", "max_stars_repo_name": "prtyspt/ml-course", "max_stars_repo_head_hexsha": "8c8dbc446977b5ec635f3a808878ef56710362da", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-28T17:34:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T17:34:02.000Z", "max_issues_repo_path": "HW2/theory.tex", "max_issues_repo_name": "Hubert51/ml-course", "max_issues_repo_head_hexsha": "8c8dbc446977b5ec635f3a808878ef56710362da", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW2/theory.tex", "max_forks_repo_name": "Hubert51/ml-course", "max_forks_repo_head_hexsha": "8c8dbc446977b5ec635f3a808878ef56710362da", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-20T06:12:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-20T06:12:13.000Z", "avg_line_length": 49.8820224719, "max_line_length": 690, "alphanum_fraction": 0.6398243045, "num_tokens": 3212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7347473688180229}}
{"text": "\\documentclass{memoir}\n\\usepackage{linalg}\n\n% Contains notes on 12-02-19 to 12-04-19\n\n\\begin{document}\n\\chapter{Generalized Eigenvectors and Nilpotent Operators}\n\\label{cha:generalized_eigenvectors_and_nilpotent_operators}\n\\section{Null Spaces of Powers of an Operator}\n\\label{sec:null_spaces_of_powers_of_an_operator}\n\\begin{prop}\n\tSuppose \\(T \\in \\mathcal{L}(V)\\). Then\n\t\\begin{align*}\n\t\t\\left\\{ 0 \\right\\} = \\textrm{null} T^{0} \\subset \\textrm{null}T^{1} \\subset \\ldots\\subset \\textrm{null}T^{k} \\subset \\textrm{null}T^{k+1}\\subset \\ldots .\n\t\\end{align*}\n\\end{prop}\n\n\\begin{prop}\n\tSuppose \\(T \\in \\mathcal{L}(V)\\). Suppose \\(m\\) is a nonnegative integer such that \\( \\textrm{null}T^{m} = \\textrm{null}T^{m+1}\\). Then\n\t\\begin{align*}\n\t\t\\textrm{null}T^{m} = \\textrm{null}T^{m+1} = \\ldots .\n\t\\end{align*}\n\\end{prop}\n\\begin{prop}\n\tSuppose \\(T \\in \\mathcal{L}(V)\\), where \\(V\\) is a finite-dimensional vector space. Let \\(n = \\textrm{dim}V\\). Then\n\t\\begin{align*}\n\t\t\\textrm{null}T^{n} = \\textrm{null}T^{n+1} = \\ldots .\n\t\\end{align*}\n\\end{prop}\n\\begin{prop}\n\tSuppose \\(T \\in \\mathcal{L}(V)\\), where \\(V\\) is a finite-dimensional vector space.. Let \\(n = \\textrm{dim}V\\). Then\n\t\\begin{align*}\n\t\tV = \\textrm{null}T^{n} \\oplus \\textrm{range} T^{n}.\n\t\\end{align*}\n\\end{prop}\n\n\\section{Generalized Eigenvectors}\n\\label{sec:generalized_eigenvectors}\nSome operators do not have enough eigenvectors to completely describe it. Thus we introduce a generalized eigenvectors which will allow us to describe operators more fully (no inner product means no guarantee of spectral theorem, hence this expands it).\n\\begin{defn}[Generalized Eigenvector]\n\tSuppose \\(T \\in \\mathcal{L}(V)\\) and \\(\\lambda\\) is an eigenvalue of \\(T\\). A vector \\(v \\in V\\) is called a \\textbf{generalized eigenvector} of \\(T\\) corresponding to \\(\\lambda\\) if \\(v\\neq 0\\) and\n\t\\begin{align*}\n\t\t(T-\\lambda I)^{j}v = 0\n\t\\end{align*}\n\tfor some positive integer \\(j\\).\n\\end{defn}\n\\begin{defn}[Generalized Eigenspace]\n\tSuppose \\(T \\in \\mathcal{L}(V)\\) and \\(\\lambda \\in F\\). The \\textbf{generalized eigenspace} of \\(T\\) corresponding to \\(\\lambda\\), denoted \\(G(\\lambda,T)\\), is defined to be the set of all generalized eigenvectors of \\(T\\) corresponding to \\(\\lambda\\), along with the 0 vector.\n\\end{defn}\n\\begin{prop}\n\tSuppose \\(T \\in \\mathcal{L}(V)\\) where \\(V\\) is a finite-dimensional vector space and \\(\\lambda \\in F\\). Then \\(G(\\lambda,T) = \\textrm{null}(T-\\lambda I)^{ \\textrm{dim}V}\\).\n\\end{prop}\n\n\\begin{prop}\n\tLet \\(T \\in \\mathcal{L}(V)\\). Suppose \\(\\lambda_1,\\ldots,\\lambda_m\\) are distinct eigenvalues of \\(T\\) and \\(v_1,\\ldots,v_m\\) are corresponding generalized eigenvectors. Then \\(v_1,\\ldots,v_m\\) is linearly independent.\n\\end{prop}\n\n\\section{Nilpotent Operators}\n\\label{sec:nilpotent_operators}\n\n\\begin{defn}\n\tAn operator is called \\textbf{nilpotent} if some power of it equals \\(0\\).\n\\end{defn}\n\\begin{prop}\n\tSuppose \\(N \\in \\mathcal{L}(V)\\) is nilpotent. Then \\(N^{ \\textrm{dim}V} = 0\\).\n\\end{prop}\n\\begin{prop}\n\tSuppose \\(N\\) is a nilpotent operator on \\(V\\). Then there is a basis of \\(V\\) with respect to which the matrix of \\(N\\) has the form\n\t\\begin{align*}\n\t\t\\begin{bmatrix} 0 & & * \\\\ & \\ddots & \\\\ 0 & & 0 \\end{bmatrix} \n\t\\end{align*}\nor in other words, all entries on and below the diagonal are \\(0\\).\n\\end{prop}\n\nWe can actually construct a basis that corresponds to a nilpotent operator. This will be important when we get to Jordan form.\n\n\\begin{prop}\n\tSuppose \\(N \\in \\mathcal{L}(V)\\) is nilpotent. Then there exist vectors \\(v_1,\\ldots,v_n \\in V\\) and nonnegative integers \\(m_1,\\ldots,m_n\\) such that\n\t\\begin{itemize}\n\t\t\\item \\(\\left\\{  N^{m_1}v_1,\\ldots,N^2,Nv_1,v_1,N^{m_2}v_2,\\ldots,N^{m_n}v_n,\\ldots,v_n \\right\\}\\) is a basis of \\(V\\) \n\t\t\\item \\(N^{m_1+1}v_1 = \\ldots = N^{m_n+1}v_n = 0\\).\n\t\\end{itemize}\n\\end{prop}\n\n\\section{Decomposition of an Operator}\n\\label{sec:decomposition_of_an_operator}\n\n\\subsection{Description of Operators on Complex Vector Spaces}\n\\label{subsec:description_of_operators_on_complex_vector_spaces}\n\\begin{prop}\n\tSuppose \\(T \\in \\mathcal{L}(V)\\) and \\(p \\in P(F)\\). Then \\( \\textrm{null}p(T)\\) and \\( \\textrm{range}p(T)\\) are invariant under \\(T\\).\n\\end{prop}\n\n\\begin{thm}[Description of operators on complex vector spaces]\n\tSuppose \\(V\\) is a complex vector space and \\(T \\in \\mathcal{L}(V)\\). Let \\(\\lambda_1,\\ldots,\\lambda_m\\) be the distinct eigenvalues of \\(T\\). Then\n\t\\begin{itemize}\n\t\t\\item \\(V = G(\\lambda_1,T) \\oplus \\ldots \\oplus G(\\lambda_m,T)\\) \n\t\t\\item each \\(G(\\lambda_j,T)\\) is invariant under \\(T\\) \n\t\t\\item each \\((T-\\lambda_jI)\\mid_{G(\\lambda_j,T)}\\) is nilpotent\n\t\\end{itemize}\n\\end{thm}\n\\begin{prop}\n\tSuppose \\(V\\) is a complex vector space and \\(T \\in \\mathcal{L}(V)\\). Then there is a basis of \\(V \\) consisting of generalized eigenvectors of \\(T\\).\n\\end{prop}\n\n\\subsection{Multiplicity of an Eigenvalue}\n\\label{subsec:multiplicity_of_an_eigenvalue}\n\\begin{defn}[Multiplicity]\n\tSuppose \\(T \\in \\mathcal{L}(V)\\). The \\textbf{multiplicity} of an eigenvalue \\(\\lambda\\) of \\(T\\) is defined to be the dimension of the corresponding generalized eigenspace \\(G(\\lambda,T)\\).\\\\\n\n\tIn other words, the multipicity of an eigenvalue \\(\\lambda\\) of \\(T\\) equals \\( \\textrm{dim} \\textrm{null}(T-\\lambda I)^{ \\textrm{dim} V}\\).\n\\end{defn}\n\\begin{prop}\n\tSuppose \\(V\\) is a complex vector space and \\(T \\in \\mathcal{L}(V)\\). Then the sum of the multiplicities of all the eigenvalues of \\(T\\) equals \\( \\textrm{dim}V\\).\n\\end{prop}\n\n\\subsection{Block Diagonal Matrices}\n\\label{subsec:block_diagonal_matrices}\n\n\\begin{prop}[First approximation to Jordan Form]\n\tSuppose \\(V\\) is a complex vector space and \\(T \\in \\mathcal{L}(V)\\). Let \\(\\lambda_1,\\ldots,\\lambda_m\\) be the distinct eigenvalues of \\(T\\), with multiplicities \\(d_1,\\ldots,d_m\\). Then there is a basis of \\(V\\) with respect to which \\(T\\) has a block diagonal matrix of the form\n\t\\begin{align*}\n\t\t\\begin{bmatrix} A_1 & & 0 \\\\ & \\ddots & \\\\ 0 & & A_m \\end{bmatrix} \n\t\\end{align*}\nwhere each \\(A_j\\) is a \\(d_j\\)-by-\\(d_j\\) upper-triangular matrix of the form\n\\begin{align*}\n\t\\begin{bmatrix} \\lambda_j & &* \\\\ & \\ddots & \\\\ 0 & & \\lambda_j \\end{bmatrix} \n\\end{align*}\n\\end{prop}\n\n\\section{Jordan Form}\n\\label{sec:jordan_form}\n\n\\begin{defn}[Jordan Basis]\n\tSuppose \\(T \\in \\mathcal{L}(V)\\), where \\(V\\) is a finite-dimensional vector space. A basis of \\(V\\) is called a \\textbf{Jordan basis}for \\(T\\) if with respect to this basis, \\(T\\) has a block diagonal matrix\n\t\\begin{align*}\n\t\t\\begin{bmatrix} A_1 & \\ldots & 0 \\\\ \\vdots & \\ddots & \\vdots \\\\ 0 & \\ldots & A_p \\end{bmatrix} \n\t\\end{align*} \n\twhere each \\(A_j\\) is an upper-triangular matrix of the form\n\\begin{align*}\n\tA_j = \\begin{bmatrix} \\lambda_j & 1 & \\ldots & 0 \\\\ \\vdots &\\lambda_j & \\ddots & \\vdots \\\\ & & \\ddots & 1 \\\\ 0 & \\ldots & & \\lambda_j \\end{bmatrix} \n\\end{align*}\nThe matrix is said to be in \\textbf{Jordan form}, and the \\(A_j\\) are called \\textbf{Jordan blocks}.\n\\end{defn}\nNote: Some define the Jordan blocks with the \\(1\\)'s on the subdiagonal. This corresponds to reversing the order of the basis elements in each Jordan block.\n\n\\end{document}\n", "meta": {"hexsha": "ab129dcf3fb1aca4d4abac07aaac26a4e706eb1c", "size": 7103, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear Algebra/Notes/source/12-02-19-GenEig-JordanForm.tex", "max_stars_repo_name": "gjgress/Libera-Mentis", "max_stars_repo_head_hexsha": "d9f1bfd9e6ea62a9d56292f7890f99c450b54c9b", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-07-16T23:18:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-16T23:18:15.000Z", "max_issues_repo_path": "Linear Algebra/Notes/source/12-02-19-GenEig-JordanForm.tex", "max_issues_repo_name": "gjgress/Libera-Mentis", "max_issues_repo_head_hexsha": "d9f1bfd9e6ea62a9d56292f7890f99c450b54c9b", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2021-05-20T22:09:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-20T23:23:22.000Z", "max_forks_repo_path": "Linear Algebra/Notes/source/12-02-19-GenEig-JordanForm.tex", "max_forks_repo_name": "gjgress/LibreMath", "max_forks_repo_head_hexsha": "d9f1bfd9e6ea62a9d56292f7890f99c450b54c9b", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.9932432432, "max_line_length": 282, "alphanum_fraction": 0.6823877235, "num_tokens": 2497, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8887587868629346, "lm_q1q2_score": 0.7347473635944864}}
{"text": "\\section{Macroscopic pKas for a single ligand species}\n\nWe would like to use the calculated effective energy differences to\ndetermine macroscopic pKas (i.e. the equilibrium constant that\ndescribes the populations of various macrostates). We will use proton\nbinding as an example but note that this derivation can apply to any\nbinding ligand as long as it is the sole binding species.\n\nWe define the macroscopic pKa as:\n\n\\begin{equation}\n  pKa_m \\equiv -\\log \\left(\\frac{[C^-][H^+]}{[CH] c_0} \\right)\n\\end{equation}\n\nWhere $[C^-]$ is the concentration of protonated complexes, $[H^+]$ is\nthe concentration of protons, $[CH]$ is the concentration of\nprotonated complexes, and $c_0$ is the standard state concentration of\nhydrogen. Using the properties of logarithmic functions:\n\n\\begin{align*}\n  pKa_m &\\equiv -\\log \\left(\\frac{[C^-][H^+]}{[CH] c_0} \\right) \\\\\n  &= -\\log \\left( \\frac{[C^-]}{[CH]} \\right) + pH \\\\\n  &= -\\log \\left(\\frac{P(C^-)}{P(CH)} \\right) + pH \\\\\n  &= -\\ln \\left( \\frac{P(C^-)}{P(CH)} \\right)/\\ln(10) + pH \\\\\n  &= -\\frac{\\beta \\Delta G_{C^-,CH}}{\\ln 10} + pH\n\\end{align*}\n\nwhere $\\Delta G_{C^-,CH}$ is the effective free energy difference of\nprotonation, which is: \n\n\\begin{equation}\n\\Delta G_{N-1,N} = \\beta^{-1} \\ln \\left[ \\frac{\\sum_s \\exp(-\\beta\n    \\Delta G_s)\\delta_{N_s,N-1}}{\\sum_s \\exp(-\\beta \\Delta\n    G_s)\\delta_{N_s,N}} \\right]\n\\label{macrostateenergydiff}\n\\end{equation}\n\nwhere the $\\delta_{N_s,N}$ and $\\delta_{N_s,N-1}$ will pick out states\nthat contain the correct number of protonated residues. For sake of\nclarity, we select as a reference energy, the energy any deprotonated\nmicrostate. The motivation for this choice becomes clear when\nconsidering the free energy of (microscopic)\nprotonation/deprotonation. To protonated/deprotonate a residue, the free energy differnce is:\n\n\\begin{equation}\n  \\Delta G_{prot} = -\\Delta G_{dep} = \\beta^{-1} \\ln(10)(pH-pKa)\n\\end{equation}\n\nConsider a system of three protonatable residues. We will represent\nthe protonation state by a string of 1s and 0s. For example, 111\nrepresents that state where all residues are protonated (N=3) while\n000 represents the state where no residues are protonated (N=0). These\ntwo examples, of course are macrostates with no degenerate\nmicrostates. We have two other macrostates of interest, N=1 and\nN=2. The N=1 macrostate has a three fold degeneracy (001,010,100) and\nthe N=2 macrostate has a three fold degeneracy (011,101,110). In order\nto go from 001 to 010, we would be required to deprotonate residue\nthree and then protonate residue two. The energy difference between\nthese two microstates is then:\n\n\\begin{equation}\n  \\Delta G_{001,010} = \\beta^{-1} \\ln(10)\\left[ (-pH + pKa_{000,001}) + (pH - pKa_{000,010}) \\right] = \\beta^{-1} \\ln(10) \\left[ pKa_{000,001} - pKa_{000,010}\\right]\n\\end{equation}\n\nA similar argument can be made for free energy difference between 001\nand 100. Because of this behavior, we see that the energy difference\nbetween two microstates is only dependent on the temperature and the\ndifference of the pKas of each state. In the case of moving between\nmicrostates from different macrostates, there is a first order pH\ndependence, as well as a linear combination of pKas that is a function\nof the connectivity of the graph. We can select any reference state we\nwould like. In our case, we select any $\\Delta G$ from the numerator\nof the argument of the natural logarithm. By doing this, all terms in\nthe numerator have no pH dependence and are all just functions of the\nconnectivity, which we will call $\\eta_i$.\n\nWe then find that (\\ref{macrostateenergydiff}) can be written as:\n\n\\begin{align*}\n  \\Delta G_{N-1,N} &= \\beta^{-1} \\ln \\left[ \\frac{\\sum_s \\exp(-\\eta_s) \\delta_{N_s,N-1}}{\\sum_s \\exp(-\\ln(10)\\,pH)\\exp(-\\eta_s) \\delta_{N_s,N}} \\right] \\\\\n  &= \\beta^{-1} \\ln \\left[ \\frac{\\sum_s \\exp(-\\eta_s) \\delta_{N_s,N-1}}{\\exp(-\\ln(10)\\,pH) \\sum_s \\exp(-\\eta_s) \\delta_{N_s,N}} \\right] \\\\\n  &= \\beta^{-1} \\ln(10) pH + \\beta^{-1} \\ln \\left[ \\frac{\\sum_s \\exp(-\\eta_s) \\delta_{N_s,N-1}}{\\sum_s \\exp(- \\eta_s) \\delta_{N_s,N}} \\right] \n\\end{align*}\n\nPlugging this into our expression for the $pKa_m$, we find that the pH\ndependence drops out and our result is:\n\n\\begin{align*}\n  pKa_m = -\\ln \\left[ \\frac{\\sum_s \\exp(-\\eta_s) \\delta_{N_s,N-1}}{\\sum_s \\exp(- \\eta_s) \\delta_{N_s,N}} \\right] / \\ln(10)\n\\end{align*}\n\nWe conclude that the macroscopic pKas are independent of pH. More\ngenerally, we have shown that the macroscopic equilibrium constants\nare independent of the ligand concentration.\n", "meta": {"hexsha": "b6d656f1265801ed112b3fcdc23db07f6dd0105a", "size": 4529, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/macroscopic_pkas.tex", "max_stars_repo_name": "Becksteinlab/multibind", "max_stars_repo_head_hexsha": "fe6dd2c048c3e734fd32fc293d98c1c8df41baa1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-06T05:40:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T18:54:31.000Z", "max_issues_repo_path": "docs/tex/macroscopic_pkas.tex", "max_issues_repo_name": "Becksteinlab/multibind", "max_issues_repo_head_hexsha": "fe6dd2c048c3e734fd32fc293d98c1c8df41baa1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2021-03-04T15:17:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-22T16:45:56.000Z", "max_forks_repo_path": "docs/tex/macroscopic_pkas.tex", "max_forks_repo_name": "Becksteinlab/multibind", "max_forks_repo_head_hexsha": "fe6dd2c048c3e734fd32fc293d98c1c8df41baa1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.6736842105, "max_line_length": 165, "alphanum_fraction": 0.7158313093, "num_tokens": 1430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7346927858585569}}
{"text": "\\subsection{Floating-Point Comparisons}\\label{sec:Floating-PointComparisons}\n\nFloating-point comparisons are inherently problematic. Testing floating-point numbers for equality, or even inequality, is fraught with problems due to the internal representation of floating-point numbers: floating-point numbers are stored with a fixed number of binary digits, which limits their precision and accuracy. The problems with floating-point comparisons are even more evident if one or both of the numbers being compared are the results of (perhaps several) floating-point operations (rather than comparing constants).\n\nTo avoid the problems associated with floating-point comparisons it is (almost always) better to do any such comparisons with a tolerance rather than an absolute comparison. To this end, a floating-point comparison function has been provided, and (almost all of) the floating-point comparisons in the code have been changed to use that function. The function uses both an absolute tolerance and a relative tolerance, which are both declared in constants.h. Whether the function uses a tolerance or not can be changed by \\#define-ing or \\#undef-ing the COMPARE\\_WITH\\_TOLERANCE flag in constants.h (so the change is a compile-time change, not run-time).\n\nThe compare function is defined in utils.h and is implemented as follows:\n\n\\medskip\n\n\\hfill\n\\begin{minipage}{\\dimexpr\\textwidth-2em}\nstatic int Compare(const double p\\_X, const double p\\_Y)\\ \\lcb \\\\\n\\#ifdef COMPARE\\_WITH\\_TOLERANCE \\\\\n\\tabto{2em}return (fabs(p\\_X -- p\\_Y) $\\leq$ max(\\ \\tabto{15em}FLOAT\\_TOLERANCE\\_ABSOLUTE, \\\\\n\\tabto{15em}FLOAT\\_TOLERANCE\\_RELATIVE * \\\\\n\\tabto{15em}max(\\tabto{17.25em}fabs(p\\_X), \\\\\n\\tabto{17.25em}fabs(p\\_Y)))) ? 0 : (p\\_X $\\mathrm{<}$ p\\_Y ? --1 : 1); \\\\\n\\#else\n\\tabto{2em}return (p\\_X == p\\_Y) ? 0 : (p\\_X $\\mathrm{<}$ p\\_Y ? --1 : 1); \\\\\n\\#endif\n\\end{minipage}\n\n\\medskip\nIf COMPARE\\_WITH\\_TOLERANCE is defined, p\\_X and p\\_Y are compared with tolerance values, whereas if COMPARE\\_WITH\\_TOLERANCE is not defined the comparison is an absolute comparison.\n\nThe function returns an integer indicating the result of the comparison:\n\n\\tabto{2em}--1\\tabto{4em}indicates that p\\_X is considered to be less than p\\_Y \\\\\n\\tabto{2em}\\ 0\\tabto{4em}indicates p\\_X and p\\_Y are considered to be equal \\\\\n\\tabto{2em}+1\\tabto{4em}indicates that p\\_X is considered to be greater than p\\_Y\n\nThe comparison is done using both an absolute tolerance and a relative tolerance. The tolerances can be defined to be the same number, or different numbers. If the relative tolerance is defined as 0.0, the comparison is done using the absolute tolerance only, and if the absolute tolerance is defined as 0.0 the comparison is done with the relative tolerance only.\n\nAbsolute tolerances are generally more effective when the numbers being compared are small -- so using an absolute tolerance of (say) 0.0000005 is generally effective when comparing single-digit numbers (or so), but is less effective when comparing numbers in the thousands or millions. For comparisons of larger numbers a relative tolerance is generally more effective (the actual tolerance is wider because the relative tolerance is multiplied by the larger absolute value of the numbers being compared).\n\nThere is a little overhead in the comparisons even when the tolerance comparison is disabled, but it shouldn't be prohibitive.", "meta": {"hexsha": "756c2094337147e48fe8472d5e6da8a979569cd9", "size": 3379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/COMPAS_LaTeX/sections/DeveloperGuide/FP-Comparisons.tex", "max_stars_repo_name": "FloorBroekgaarden/COMPAS-2", "max_stars_repo_head_hexsha": "afd912157a1a91375d61c81996c8346799a426fb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2020-04-04T01:50:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T08:53:06.000Z", "max_issues_repo_path": "docs/COMPAS_LaTeX/sections/DeveloperGuide/FP-Comparisons.tex", "max_issues_repo_name": "FloorBroekgaarden/COMPAS-2", "max_issues_repo_head_hexsha": "afd912157a1a91375d61c81996c8346799a426fb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 427, "max_issues_repo_issues_event_min_datetime": "2020-04-04T01:54:46.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T08:52:28.000Z", "max_forks_repo_path": "docs/COMPAS_LaTeX/sections/DeveloperGuide/FP-Comparisons.tex", "max_forks_repo_name": "FloorBroekgaarden/COMPAS-2", "max_forks_repo_head_hexsha": "afd912157a1a91375d61c81996c8346799a426fb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 34, "max_forks_repo_forks_event_min_datetime": "2020-04-05T03:36:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T00:50:08.000Z", "avg_line_length": 91.3243243243, "max_line_length": 652, "alphanum_fraction": 0.7818881326, "num_tokens": 828, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7346927699828356}}
{"text": "% file: problems/tree-bfs-depth.tex\n\n\\section{BFS on Tree (UD Problem 4.3)}\n\nWrite algorithms that solve the following problems by performing \\emph{breadth-first traversals} of the given trees. \nYou may assume the availability of a queue $Q$. \nThe operations on $Q$ include adding an item to the rear, \nretrieving and removing an item from the front, and testing $Q$ for emptiness.\n    \n\\begin{enumerate}[(a)]\n  \\item Given a tree $T$ whose nodes contain integers, \n    print a list consisting of the sum of contents of nodes at depth 0, \n    the sum of contents of nodes at depth 1, etc.\n  \\item Given a tree $T$, find the depth $K$ with the maximal number of nodes in $T$. \n    If there are several such $K$s, return their maximum.\n\\end{enumerate}\n\n\\subsection{Solution}\n\n\\input{algs/sum-at-depth}\n\\input{algs/nodes-at-depth}\n\n", "meta": {"hexsha": "9a8f001742e11888c38f8a5ad74cd1f69b249a52", "size": 829, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2017/2017-2nd/2-2-efficiency/problems/tree-bfs-depth.tex", "max_stars_repo_name": "courses-at-nju-by-junma/problem-solving-class-problems", "max_stars_repo_head_hexsha": "79de740506000972b2bec91cc6042fa639cd2e55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2018-03-16T04:33:03.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-11T14:50:38.000Z", "max_issues_repo_path": "2017/2017-2nd/2-2-efficiency/problems/tree-bfs-depth.tex", "max_issues_repo_name": "courses-at-nju-by-junma/problem-solving-class-problems", "max_issues_repo_head_hexsha": "79de740506000972b2bec91cc6042fa639cd2e55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2018-03-19T10:36:11.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-03T04:58:39.000Z", "max_forks_repo_path": "2017/2017-2nd/2-2-efficiency/problems/tree-bfs-depth.tex", "max_forks_repo_name": "courses-at-nju-by-junma/problem-solving-class-problems", "max_forks_repo_head_hexsha": "79de740506000972b2bec91cc6042fa639cd2e55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-03-16T04:26:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-11T11:42:48.000Z", "avg_line_length": 36.0434782609, "max_line_length": 117, "alphanum_fraction": 0.728588661, "num_tokens": 223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7346927699378607}}
{"text": "\\chapter{Transfer and $p-$complements}\r\n\\section{Transfer}\r\n{\\bf Definition 1:}  Suppose $G$ is a finite group and $H$ is a subgroup, $|G:H|=n$.  \r\nLet $ \\langle r_1, \\ldots, r_n \\rangle $ be a right transversal so $G= \\bigcup_{i=1}^n Hr_n$ and\r\n$Hr_i \\cap Hr_j = \\emptyset$ if $i \\ne j$.  Suppose $r_i g= h_i(g) r_j$.\r\nThe \\emph {transfer} map from $G$ to $H$ is defined as \r\n$V_{G \\rightarrow H}(g)= \\prod_{i=1}^n h_i(g) \\jmod {H'}$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition 2:} $Foc_G(H)= \\langle y^{-1} y^g: y, y^g \\in H \\rangle $, \r\nthus $H' \\le Foc_G(H) \\le H \\cap G'$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 1:}\r\nThe map $V_{G \\rightarrow H}$ is well defined and is a homomorphism.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet \r\n$T= \\{ t_1 , t_2 , \\ldots , t_n \\}$ and\r\n$T'= \\{ t_1' , t_2' , \\ldots , t_n' \\}$ be two transversals for $G/H$.\r\n$\\exists k_i \\in H: t_i'= k_i t_i$.  If \r\n$t_i g = h_i(g) t_j$ and\r\n$t_i' g = h_i'(g) t_j'$, $t_i g= k_i^{-1} h_i(g)' k_j^{-1}$ and $k_i^{-1} h_i(g)' k_j = h_i(g)$.\r\nFor each $g$, each $k_i^{-1}, k_j$ occur once when $h_i(g)$ is calculated the cosets.\r\n$\\prod_{i=1}^n h_i(g) = \\prod_{i=1}^n k_i^{-1} h_i(g)' k_j \\jmod{H'}$ but the elements of $H$\r\ncommute $\\jmod{H'}$ and all the $k_i's$ cancel thus\r\n$\\prod_{i=1}^n h_i(g) = \\prod_{i=1}^n  h_i(g)' \\jmod{H'}$ and \r\nthus $V_{G \\rightarrow H}$ is well defined.\r\n\\\\\r\n\\\\\r\nNow \r\n$V_{G \\rightarrow H}(g_1 g_2)= \\prod_{i=1}^n h_i(g_1 g_2) \\jmod {H'}$.\r\n$t_i g_1 g_2 = h_i(g_1 g_2) t_j = h_i(g_1) t_k g_2 = h_i(g_1) h_k(g_2) t_j$. So\r\n$V_{G \\rightarrow H}(g_1 g_2) = $\r\n$\\prod_{i=1}^n h_i(g_1 g_2) =$ $ \\prod_{i=1, k=1}^n h_i(g_1) h_k(g_2) \\jmod{H'} =$\r\n$(\\prod_{i=1}^n h_i(g_1) \\jmod{H'})$ $(\\prod_{k=1}^n h_k(g_2) \\jmod{H'}$ \r\n$= V_{G \\rightarrow H}(g_1) V_{G \\rightarrow H}(g_2)$,\r\nthus, $V_{G \\rightarrow H}$ is a homomorphism.\r\n\\end{quote}\r\n{\\bf Theorem 2:} \r\n$V_{G \\rightarrow H}(g)= \\prod_{i=1}^k  h_j \\jmod {H'}\r\n= \\prod_{i=1}^k  r_i g^{n_i}{r_i}^{-1} \\jmod {H'}$.  Further, $\\sum_{i=1}^h n_i = |G:H|$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nFor fixed $g \\in G$, we can pick the transversal \r\n$Hr_1, H r_1, \\ldots, H r_1 g^{n_1 -1}$,\r\n$Hr_2, H r_2, \\ldots, H r_2 g^{n_2 -1}$, \\ldots,\r\n$Hr_k, H r_k, \\ldots, H r_k g^{n_k -1}$, where $r_j g^{n_j} = h_j r_j$ for\r\nsome, $h_j= r_j g^{n_j}{r_j}^{-1}$. So\r\n$V_{G \\rightarrow H}(g)= \\prod_{i=1}^k  h_j \\jmod {H'}\r\n= \\prod_{i=1}^k  r_i g^{n_i}{r_i}^{-1} \\jmod {H'}$.  Further, $\\sum_{i=1}^h n_i = |G:H|$.\r\n\\end{quote}\r\n{\\bf Theorem 3:} \r\nIf $Z$ is a central subgroup of $G$, $|G:Z|=n$ then\r\n$V_{G \\rightarrow Z}(g)= g^n$\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nChoose a right transversal, $T$ for $Z$ in $G$ and let $g \\in G$.  Choose $T_0 \\subseteq T$\r\nand integers $n_t$ for $t \\in T_0$.  For $t \\in T_0$, we have \r\n$t g^{n_t} t^{-1} \\in Z$\r\nand thus\r\n$t^{-1} t g^{n_t} t^{-1} t= g^{n_t}$ and the product over all these is $g^{\\sum_t n_t}= g^n$.\r\n\\end{quote}\r\n{\\bf Lemma A:} \r\nLet $T$ be a right transversal for $Z={\\mathbb Z}(G)$ in $G$, then every commutator in $G$\r\nis of the form $[s,t], s,t \\in T$.  So if $|G:Z|$ is finite, there are only finitely \r\nmany commutators.\r\n\\begin{quote}\r\n\\emph{Proof:}    The second statement follows from the first since $|T|= |G:{\\mathbb Z}(G)$.\r\nIf $g \\in G, g= xs, x \\in {\\mathbb Z}(G), t \\in T$.  So it suffices to show \r\n$[xs,yt]=[s,t]$  with $x, y \\in {\\mathbb Z}(G)$ and $s, t \\in T$.  So\r\n$[xs,yt]= [x,yt]^s [s,yt]= [s,yt]$.  Also, \r\n$[s,yt]= [yt,s]^{-1}= ([y,s]^t [t,s]^{-1}= [t,s]^{-1}=[s,t]$.\r\n\\end{quote}\r\n{\\bf Theorem 4:} \r\nIf $|G:{\\mathbb Z}(G)|=n$ then $[g,h]^n=1, \\forall g,h \\in G$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nThe map $g \\mapsto g^n$ is a homomorphism from $G$ into ${\\mathbb Z}(G)$ and so $G'$ is\r\nin the kernel.\r\n\\end{quote}\r\n{\\bf Theorem 5:} \r\nLet $X$ be a finite subseteq of $G$ closed under conjugation and \r\nsuppose $\\exists n: x^n = 1, \\forall x \\in X$ then $ \\langle X \\rangle $ is a \r\nfinite subgroup of $G$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $S$ be the subseteq of $G$ of all products of finitely many elements of $X$.  $S$\r\nis closed under multiplication.  Since $x^n=1$, $x^{n-1}= x^{-1} \\in S$ and \r\n$ \\langle X \\rangle = S$.\r\n\\emph{Claim:} Such an expression in $S$ never requires more than $(n-1) |X|$ factors.  The result\r\nfollows from the claim.\r\n\\\\\r\n\\emph {Proof of claim:} Put $g= x_1 x_2 \\ldots x_m$. Suppose an element of $x \\in X$ occurs $k$\r\ntimes.  We now that $g$ can be rewritten with leading factor $x$ with $x$ occuring no more than\r\n$k$ times.  To show this, assume $t$ is the smallest index for which $x=x_t$.  \r\nIf $t=1$, we're done.\r\n$x_1 x_2 \\ldots x_t = x(x_1 \\ldots x_{t-1})^x= x (x_1^x) \\ldots (x_{t-1}^x)$, this is\r\na product of $t$ elements of $X$ since $X$ is closed under conjugation. We can continue and\r\nextract all copies of $x$ to the front.  Since $x^n=1$, the exponent of $x$ is $\\le n-1$.\r\n\\end{quote}\r\n{\\bf Schur's Theorem:} \r\nSuppose $|G:{\\mathbb Z}(G)| < \\infty$ then $|G'|< \\infty$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $X$ be the set of all commutators of $G$ and observe $|X|$ is finite.  Also,\r\n$[x,y]^g= [x^g, y^g]$.  \r\n$x^{|G:{\\mathbb Z }(G)|}=1$ and the result follows from the previous result.\r\n\\end{quote}\r\n{\\bf Theorem 6:} Let $p \\mid |G| < \\infty$ and $p \\mid |G' \\cap {\\mathbb Z}(G)|$, then\r\nthe Sylow $p$-subgroup of $G$ is nonabelian.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSuppose $P \\in S_p(G)$ is abelian and let $T$ be a right transversal.  Put\r\n$v(g)= V_{G \\rightarrow P}(g)$. Let $Z= {\\mathbb Z}(G)$.  \r\n$G' \\cap Z \\cap P > 1$ since $G' \\cap Z \\lhd G$.\r\nFor $t \\in T, z \\in G' \\cap Z \\cap P$, $Ptz=Pzt=Pt$ so $t$ is the element in $Ptz$ and\r\n$t \\cdot z= t$.  Thus, $tz(t \\cdot z)^{-1}= tzt^{-1}=z$ and $v(z)= z^{|T|}=z^{|G:P|}$.\r\nWe know, since $P$ is abelian that $G' \\subseteq ker(v)$. So \r\n$z \\in G'\\rightarrow 1=v(z)=z^{|G:P|}$.  Thus $z=1$.  This contradicts the choice of $z$.\r\n\\end{quote}\r\n{\\bf Theorem 7:} Let $Z < {\\mathbb Z}(\\Gamma)$, $\\Gamma$, finite, then a Sylow $p$-subgroup of\r\n$\\Gamma/Z$ is non-cyclic for all $p \\mid |Z|$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $P \\in S_p( \\Gamma )$, $p \\mid |Z|$ and $Z \\subseteq {\\mathbb Z}( \\Gamma ) \\cap \\Gamma'$\r\nso by the foregoing, $P$ is not abelian.  Since $P \\cap Z \\subseteq {\\mathbb Z}(P)$ and\r\n$P$ is not abelian, $P/(P \\cap Z)$ cannot be cyclic.  \r\nBut $P/(P \\cap Z) \\cong PZ/Z \\in S_p(\\Gamma/Z)$ and so $\\Gamma/Z$ has a \r\nnon-cyclic Sylow $p$-subgroup.\r\n\\end{quote}\r\n{\\bf Observation:} Note that $\\Gamma$ is a central extension of $G$ if $\\Gamma/Z \\cong G$.\r\nIn the case $Z \\cong M(G)$ (the Schur multiplier), $\\Gamma$ is a Schur representation group and\r\nif $G$ is perfect, this representation group is unique.  \r\nIf $G= \\langle x \\rangle , x^4=1$, $|M(G)|=2$.  The\r\ntheorem shows, for example, that $|M(A_5)|=2$\r\n\\\\\r\n\\\\\r\n{\\bf Definition 3:} $A^p(G)$ is the smallest normal subgroup of $G$ such that\r\n$G/A^p(G)$ is an abelian $p$-group.  If $P$ is a Hall $\\pi$ subgroup of $G$,\r\nwe use $G(\\pi)$ to denote the inverse image of $O_{\\pi}(G/G')$.\r\n\\\\\r\n\\\\\r\n{\\bf Focal Subgroup Theorem:}  \r\nIf $P \\in S_p(G)$, $Foc_G(P) = P \\cap G' = P \\cap A^p(G) = ker(V_{G \\rightarrow P})$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$Foc_G(P) \\subseteq  P \\cap G' \\subseteq  P \\cap A^p(G)  \\subseteq ker(V_{G \\rightarrow P})$ is\r\neasy.  So if we prove\r\n$ker(V_{G \\rightarrow P}) \\subseteq Foc_G(P)$, we're done.  Let $x \\in ker(V_{G \\rightarrow P})$, so $x \\in P'$.\r\nSuppose $\\langle Pg_i x, \\ldots , P g_i x^{n_i - 1} \\rangle$ is an orbit of $x$ acting on $Pg_i$ in $G/P$. So $Pg_i = Pg_i x^{n_i}$,\r\n${g_i}^{-1} x^{n_i} g_i \\in P$, and $x^{n_i} \\in P$.  \r\nWe can find a complete set of coset representatives of $P$ in $G$ consisting of such orbits with $g_i \\in G, i = 1,2, \\ldots, h$.\r\nFor each $i$, $x^{n_i} = {g_i}^{-1} x^{n_i} g_i \\jmod{Foc_G(P)}$.  So \r\n$V_{G \\rightarrow P}(x) \\jmod{Foc_G(P)} = \\prod_{i=1}^h {g_i}^{-1} x^{n_i} g_i \\jmod{Foc_G(P)} = x^{|G:P|} \\jmod{Foc_G(H)}$\r\nand  $x^{|G:P|} \\in Foc_G(P)$.  Since $P' \\subseteq Foc_G(P) \\subseteq P$ and $(|x|, |G:P|) =1$, $\\exists k_1, k_2: k_1|G:P| + k_2|x| = 1$\r\nso $x = x^{|G:P| k_1} x^{|x| k_2} \\in Foc_G(H)$ and all the groups are the same.\r\n\\end{quote}\r\n{\\bf Theorem 8:}  \r\nIf $P \\in S_p(G)$ then $ker(V_{G \\rightarrow P})= A^p(G)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nPut $K= ker(V_{G \\rightarrow P})$, $A= A^p(G)$,  $A \\supseteq K$ by the last result.\r\n$|G:K|$ and $|G:A|$ are $p$-powers.  $PK=G=PA$.  By FST, $P \\cap K = P \\cap A$ and\r\n$|G:K|= |P:P \\cap K|= |P: P \\cap A|= |G:A|$.  So $|A|= |K|$ and the result holds.\r\n\\end{quote}\r\n{\\bf Theorem 9:}  \r\nLet $H$ be a Hall $\\pi$ subgroup of $G$ and $v(g)= V_{G \\rightarrow H}(g)$ then\r\n$v(H)=v(G)$ and $|H: H \\cap ker(v)|= |G:ker(v)|$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nWe know $|G:ker(v)| = |v(G)|$ and since\r\n$v(G) \\subseteq H/H'$, we have $|G:ker(v)| \\mid |H|$.  $(|G:ker(v)|, |G:H|)=1$ so\r\n$ker(v)H=G$.\r\n\\end{quote}\r\n{\\bf Theorem 10:}  \r\nIf $P \\in S_p(G)$ then $N_G(P)$ controls $G$-fusion in $C_G(P)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $c_1 , c_2 \\in C_G(P)$ and $c_1^g=c_2$.  Then $c_2 = c_1^g \\in C_G(P^g)$\r\nWe know $c_2 \\in C_G(P)$, so $P, P^g \\in C_G(c_2)$ and since they are both\r\nSylow subgroups of $C_G(c_2)$ by Sylow, $\\exists h \\in C_G(c_2): P^{gh}=P$ and\r\nhence $gh \\in N_G(P)$.  $c_1^{gh}= c_2^h= c_2$ and so $c_1$ and $c_2$ fuse in $N_G(P)$.\r\n\\end{quote}\r\n{\\bf Theorem 11:}  Let  $P$ be a Hall subgroup of $G$ then $Foc_G(H) = P \\cap G(\\pi)=P \\cap G'$ and\r\n$G/Foc_G(H) \\cong G/G(\\pi)$, $ker(V_{G \\rightarrow P}) = G(\\pi)$ and $P/P' = {\\overline P} = {\\overline {Foc_G(P)}} \\times Im(V_{G \\rightarrow P})$.\r\n\\begin{quote}\r\n\\emph{Proof:}  $(|P|,|G:P|) = 1$.  $V_{G \\rightarrow P} {\\overline {Foc_G(P)}} = \\langle {\\overline x} \\rangle {\\overline {Foc_G(P)}}$ as in the\r\nproof of the FST.  Conversely, $G(\\pi) \\subseteq ker(V_{G \\rightarrow P})$ and ${\\overline P}$ is abelian so\r\n$Foc_G(P) \\leq P \\cap G' = P \\cap G(\\pi) \\leq P \\cap ker(V_{G \\rightarrow P})$.  As before, equality holds \r\n$|G/G(\\pi)| \\geq |G/ker(V_{G \\rightarrow P})| = |Im(V_{G\\rightarrow P})|$.\r\nFinally, $P/(P \\cap G') \\cong G/G(\\pi)$,\r\nso $ker(V_{G \\rightarrow P}) = G(\\pi)$ and $Im(V_{G \\rightarrow P}) \\cong P/Foc_G(P)$.\r\n${\\overline P} = {\\overline {Foc_G(P)}} \\times Im(V_{G \\rightarrow P})$.\r\n\\end{quote}\r\n{\\bf Corollary:} If $P$ is a Hall $\\pi$\r\ngroup of $G$, $G/G'= PG'/G' \\times O_{\\pi'}(G/G')$; hence, if $P \\ne Foc_G(P)$,\r\n$G \\ne O^{\\pi'}(G)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nFollows from Theorem 11.\r\n\\end{quote}\r\n{\\bf Burnside's Lemma:}  If $P \\in S_p(G)$, $A_1, A_2 \\subseteq P$ with \r\n$(A_i)^x = A_i, \\forall x \\in P, i= 1, 2$, then\r\nif $A_1^g=A_2$, then $\\exists h \\in N_G(P): A_1^h=A_2$. ($N(P)$ controls fusion in $P$.)\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSame as the earlier proof about $N_G(P)$ controlling fusion on $C_G(P)$.\r\n\\end{quote}\r\n{\\bf Definition 4:}\r\n$Z$ is \\emph {weakly closed} in $P$ with respect to $G$ if $Z^g \\subseteq P \\rightarrow Z^G=Z$.\r\nThe \\emph {weak closure} of $Z$ in $P$ with respect to $G$ is \r\n$wcl_G(Z, P)= \\langle Z^g| Z^g \\subseteq P \\rangle$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 12:}\r\nLet $P \\in S_p(G)$ and $Z \\subseteq {\\mathbb Z}(P)$ \r\nis weakly closed in $P$.  Suppose $x \\in P$ and $g \\in G$ such that\r\n$y^g \\in P$.  The $\\exists n \\in N_G(Z): y^g=y^n$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nNote $y^g \\in P \\cap P^g$ and $ \\langle Z, Z^g \\rangle \\subseteq C_G(y^g )$.  By Sylow,\r\n$\\exists c \\in C_G(y^g )$ such that \r\n$ \\langle Z^g, Z^c \\rangle $ is a $p$-group and $\\exists h \\in G:\r\n\\langle Z^{gh}, Z^{ch} \\rangle \\le P$.  Since $Z$ is weakly closed in $P$, \r\n$Z^{gh}= Z^{ch}= Z$. So\r\n$n= g c^{-1} \\in N_G(Z)$ and since $c \\in C(y^g): y^n= y^g$.\r\n\\end{quote}\r\n{\\bf Grun's Theorem:} If $P \\in S_p(G)$ and $Z \\subseteq {\\mathbb Z}(P)$ \r\nis weakly closed in $P$ then\r\n$P/(P \\cap G') \\approx G/G' (p) \\approx N(Z)/N(Z)'$ and so \r\n$G \\ne O^p(G) \\rightarrow N(Z) \\ne O^p(N(Z))$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nThis follows from Theorem 12 and Theorem 11.\r\n\\end{quote}\r\n{\\bf Theorem 13:} If\r\n$P \\in S_p(G)$ and $Z \\lhd N(P)$ then the following are equivalent:\r\n(1) $Z$ is weakly closed in $P$ with respect to $G$;\r\n(2) $Z \\le R \\in S_p(G) \\rightarrow Z \\lhd R$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n\\\\\r\n(1) implies (2): If $Z \\le R = P^{g^{-1}}, g \\in G$, then $Z^g \\le P$ and $Z=Z^g$.\r\nHence, $Z^R= Z^{P^{g^{-1}}} = Z$.\\\\\r\n(2) implies (1):  Let $Z^g \\le P$ so by (2), $ \\langle Z^g \\rangle \\lhd P$.  \r\nBy Burnside, $\\exists y \\in N_G(P)$\r\nsuch that  $Z^y=Z^g$ and thus $Z^y=Z^g=Z$.\r\n\\end{quote}\r\n{\\bf Theorem 13a:}  (1) Let $P \\in S_p(G)$ then (1) $\\exists K \\lhd G: G/K \\approx P/ P \\cap G'$.\r\n(2) If $K \\lhd G$ such that $G/K$ is an abelian $p$-group then $P \\cap G' \\subseteq K$ \r\nand $G/K$ is isomorphic to a homomorphic image of $P/P \\cap G'$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Assume $K \\lhd G$ and $G/K$ is an abelian $p$-group.  Then $G' \\subseteq K$ and\r\n$G= KP$.  $P \\cap G' \\subseteq K$ and so $P/P \\cap K$ is a homomorphic image of $P/P \\cap G'$ and (2)\r\nholds.  For 1, put ${\\overline G} = G/Foc_G(P)$ and let\r\n$K$ be the inverse image of $O_{p}({\\overline G})$\r\nin $G$.  $P \\cap G' \\in S_p(G')$.  \r\n$P \\cap G' = P \\cap K, K \\lhd G$ and $G/K$ is isomorphic to $P/P \\cap G'$ and (1) holds.\r\n\\end{quote}\r\n{\\bf Burnside's Theorem:} \r\nIf $P \\in S_p(G)$ and $P \\subseteq {\\mathbb Z}(N_G(P))$ then $P$ has a normal\r\n$p$-complement.\r\n\\begin{quote}\r\n\\emph{Proof:}  Put $N=N_G(P)$.  Note that $P$ is abelian so $P \\cap Q'= 1, Q \\in S_p(G)$.\r\n$P$ is a normal Hall subgroup of $N$ so it has a complement $H$ in $N$.  $N= P \\times H$ so\r\n$N' = H'$ so $P \\cap N' = P \\cap H' = 1$ so by Grun, $P \\cap G'=1$.  By previous result, $\\exists K:\r\nG/K \\approx P/P \\cap G'$ thus $K$ is a $p'$-group and $K= O_{p'}(G)$.\r\n\\end{quote}\r\n{\\bf Another statement of Burnside's Theorem:} \r\nIf $P \\in S_p(G)$ and $N_G(P) = C_G(P)$ then $G$ has a normal $p$ complement.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$P \\leq {\\mathbb Z}(N_G(P))$.\r\n\\end{quote}\r\n{\\bf Theorem 13b:} Suppose Sylow $p$-subgroups of $G$ and $G$ is a semidirect product of $N \\lhd G$ and $P$,\r\n$Z \\subseteq P$ wiht $Z^g \\leq P$. $\\exists x \\in P: Z^g = Z^x$ so every normal subgroup of $P$ is weakly\r\nclosed in $P$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$g=yx$, $y \\in N$ and $x \\in P$.\r\n$Z^g \\leq P$ so $Z^y \\leq P$ so $Z^g = Z^x$.\r\nThis shows that $\\forall z \\in Z, [z,y] \\in N \\cap P = 1$ and so\r\n$y \\in C_G(Z)$ and the result follows.\r\n\\end{quote}\r\n{\\bf Baer's Theorem:}\r\n$X$ be a $p$-group of $G$ then either\r\n$X \\le O_p(G)$ or $\\exists g: \\langle X, X^g \\rangle $ is not a $p$-group.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSee the stability section.\r\n\\end{quote}\r\n{\\bf Theorem 14:} If $Q$ is an abelian sylow subgroup in $G$ and if $Q \\subseteq {\\mathbb Z}(G)$ then\r\n$V_{G \\rightarrow Q}(g)= g^{|G:Q|}, \\forall g \\in G$.  \r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $T$ be the transversal \r\n$T= \\{ Qh_1, Qh_1g, \\ldots , Qh_1g^{n_1-1}, Qh_2, Qh_2 g^{n_2-1}, \\ldots, Qh_m g^{n_t-1} \\}$. \r\n$V_{G \\rightarrow Q}(g)= \\prod_{k=0}^t h_i g_{n_i} h_i^{-1} \\jmod{Q'}$.  Since \r\n$g^{n_i}, h_i g^{n_i} h_i^{-1} \\in Q \\subseteq {\\mathbb Z}(G)$, \r\n$V_{G \\rightarrow Q}(g)= g_{\\sum_{i=1}^t n_i} = g^{|G:Q|}$. \r\n\\end{quote}\r\n{\\bf Theorem 15:}\r\nIf $P \\in S_p (G), P'=1$ then $P \\cap G' = P \\cap N_G(P)'$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nAs proved earlier, $N_G(P)$ controls fusion on $C_G(P) \\supseteq P$ (since $P$ is abelian).\r\n\\end{quote}\r\n{\\bf Theorem 16:} If $P \\in S_p(G)$ is cyclic where $p$ is the smallest prime divisor of $|G|$,\r\nthen $G$ has a normal $p$-complement.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$1 \\rightarrow N_G(P)/C_G(P) \\rightarrow Aut(P)$ and since $|P|$ is cyclic it has order\r\n$\\varphi(|P|)$.  If $|P|= p^n$, $\\varphi(|P|)= p^{n-1}p$, this is divisible by no prime\r\nbigger than $p$ and the index is divisible by no prime smaller than $p$.  \r\nSince $p \\nmid |N_G(P):C_G(P)|$ and since $P$ is abelian it has index $1$, $C_G(P)= N_G(P)$;\r\nthus, $P \\subseteq  {\\mathbb Z}(N_G(P))$ and by Burnside, $G$ has a normal $p$-complement.\r\n\\end{quote}\r\n{\\bf Theorem 17:}\r\nIf all Sylow subgroups of $G$ are cyclic, $G$ is solvable.  \r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nInduction on $|G|$.  Let be $p$ be the smallest prime such that $p \\mid |G|$.\r\n$G$ has a normal $p$-complement, $N$, by the previous result.  $N < G$ and all the\r\nSylow subgroups of $N$ are cyclic.  $N$ is solvable by induction. $G/N$ is a $p$-group\r\nso it is solvable.\r\n\\end{quote}\r\n{\\bf Theorem 18:}\r\nSuppose all Sylow subgroups of $G$ are cyclic then $(|G'|, |G/G'|)=1$ and both are cyclic.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$G/G'$ is cyclic.  To show $G'$ is cyclic, we proceed by induction on $|G|$.\r\n$G' < G$ so $G''$ is cyclic (by induction).  $Aut(G'')$ is thus abelian and\r\n$1 \\rightarrow G/C_G(G'') \\rightarrow Aut(G'')$ and $G' \\subseteq G_G(G'')$ and\r\n$G'' \\subseteq {\\mathbb Z}(G') \\rightarrow G'$ is abelian and thus $G'$ is cyclic.\r\n\\end{quote}\r\n{\\bf Theorem 19:}\r\nLet $P$ be a cyclic Sylow subgroup of $G$ then $p$ divides at most one of $|G'|$ and $|G/G'|$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $N=N_G(P)$, $K \\subseteq N$ a complement for $P$ in $N$.  $P= [P,K] \\times C_P(K)$.\r\nIf $[P, K]=1$, $C_P(K)=P$ and $P$ is central in $N=PK$.  By Burnside,\r\n$G$ has a normal $p$-complement, $M$ and $G/M$ is a $p$-group which is cyclic so\r\n$G' \\subseteq M$ and $p \\nmid |G'|$.\r\n\\end{quote}\r\n{\\bf Theorem 20:}\r\nLet $P$ be an abelian Sylow subgroup of $G$ then $G' \\cap P \\cap {\\mathbb Z}(N_G(P))=1$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $v:G \\rightarrow P$ and $x \\in G' \\cap P \\cap {\\mathbb Z}(N_G(P))$ then $x \\in G'$ so\r\n$1=v(x)=\\prod_{t \\in T_0} t x^{n_t} t^{-1} \\in P$.  $x^{n_t} , t x^{n_t} t^{-1} \\in C_G(P)$ and\r\n$x$ is central so self conjugate in $N_G(P)$.  $x^{n_t}= t x^{n_t} t^{-1}, \\forall t \\in T_0$,\r\nso, since $|G:P|= \\sum_t n_t$, $v(x)= x^{|G:P|}$.  $1= x^{|G:P|}$ and since $x \\in P$ then\r\n$x=1$.\r\n\\end{quote}\r\n{\\bf Theorem 21:}\r\nSuppose the Sylow $2$-subgroups of $G$, $G$ is nonabelian, are direct products of cyclic groups\r\none of which is strictly larger than the other then $G$ is not simple.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $P \\in S_2(G)$.  $P= A \\times B$ where $A$ is cyclic of order $a \\ge 2$ and\r\n$x^{a/2}=1, \\forall x \\in B$.  Let $C= \\{ x^{a/2}: x \\in P \\} \\; char \\; P$ so there is\r\nthe unique $t \\in C$ is central in $N_G(P)$.  $t \\notin G'$ so $G' < G$ and the result follows.\r\n\\end{quote}\r\n{\\bf Gaschutz:}  Let $K$ be a normal abelian $p$-subgroup of a finite group $G$ and let\r\n$P \\in S_p(G)$.  Then $K$ has a complement in $G$ iff $K$ has a complement in $P$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $A$ be a complement of $K$ in $U$: $=KA, K \\cap A = 1$.  \r\nLet ${\\cal L}$ be the set of left transversals of $U$ in $G$ and $S_0 \\in {\\cal L}$.\r\nThen $\\forall L \\in {\\cal L}, l \\in L$:\r\n$l=s_l k_l a_l, s_l \\in S_0, k_l \\in K, a_l \\in A$ and $s_l U = lU$ and the factorization is\r\nunique.  Hence\r\n$\\forall l \\in L, \\exists! l_0 \\in S_0 K: lU=l_0 U$ (i.e. - $l_0=s_l k_l$).  So every\r\n$L \\in {\\cal L}$ is associated with $L_0 = \\{ l_0 : l \\in L \\}$ in\r\n${\\cal S} = \\{ L \\in {\\cal L}: L \\subseteq S_0 K \\}$ such that $LA= L_0 A$.  For $x \\in G$ and\r\n$xL \\in {\\cal L}$: $(xL)_0A = xLA = x L_0 A = (xL_0)_0 A$ and thus $(xL)_0 = (x L_0)_0$.\r\nNow define $S^x= (x^{-1} S)_0 = (y^{-1} ( x^{-1} S))_0 = ((xy)^{-1} S)_0 = S^{xy}$.\r\nThis defines an action of $G$ on ${\\cal S}$.  Now write $(xS)_0$ instead of $S^{x^{-1}}$.\r\n$R|S= \\prod_{(r,s) \\in R \\times S, Kr=Ks} (rs^{-1}), R, S \\in {\\cal S}$.  For\r\n$kS \\subseteq k S_0 K= S_0 K$ and thus $kS = (kS)_0 \\in {\\cal S}$.  Further,\r\n$(kS)_0|R = k^{G:K|} (S|R). k \\in K, S,R \\in {\\cal S}$.  As in Schur-Zassnehaus,\r\n$R \\sim S  \\leftrightarrow R|S=1$ thus defines an equivalence relation on ${\\cal S}$\r\nand the existance of a complement follows using the action of $G$ and $K$ on ${\\cal S}/ \\sim$.\r\n\\end{quote}\r\n{\\bf Theorem 22:} \r\nLet $N \\lhd G$ and $G$ be a semidirect product of $N$ with $P$, $g \\in G: Z^g \\le P$.  Then\r\n$\\exists x \\in P: Z^g = Z^x$ so every normal subgroup of $P$ is weakly closed in $P$.\r\n\\begin{quote} \r\n\\emph{Proof:}  \r\n$g=yx, y \\in N, x \\in P$ so $Z^g \\le P \\rightarrow Z^y \\le P$.  Thus, $\\forall z \\in Z:\r\n[z,y] \\in N \\cap P =1$ and $y \\in C(Z)$ so $Z^g=Z^x$.\r\n\\end{quote}\r\n{\\bf Observation:} If $N$ is a $p$-complement in $G$ then $O_{p'}(G)=N=O^{p}(G)$.\r\n\\\\\r\n\\\\\r\n{\\bf Frobenius Normal $p-$complement Theorem:}  Let $P \\in S_p(G)$ if $\\forall U \\in p(G)$,\r\n$N_G(U)$ has a normal $p$-complement then $G$ has a normal $p$ -complement.  Note: There is a\r\nstronger result in which $U$ can be restricted to characteristic $p$-locals and Thompson's\r\n$p$-complement theorem is a further strengthening.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$G$ has a normal $p$-complement if $P = 1$.  If $P > 1, Z={\\mathbb Z}(P) > 1$ and $H= N_G(Z)$ has a normal $p$-complement\r\nby hypothesis.  Thus $O^p(H) \\ne H$.\\\\\r\n\\emph{Claim:} $Z$ is weakly closed in $P$.\r\n\\\\\r\n\\emph{Proof of claim:}  It suffices to show, $Z \\le R \\in S_p(N_G(P)) \\rightarrow\r\nZ \\lhd R$.  Assume this condition does not hold and choose $R$ such that\r\n$S=N_R(Z)$ is maximal.  $S < N_R(S)$ and $S < N_T(S)$.  Put $M= N_G(S)$ and let\r\n$N_T(S) \\le T_1 \\in S_p(M)$.  By the maximality, $Z \\lhd T_1$  Since $M$ has a normal $p$-complement, the\r\nprevious result show $Z$ is normal in every Sylow subgroup of $M$ containing it.  Hence\r\n$Z \\lhd N_R(S)$ which contradicts $S < N_R(S)$.\r\n\\\\\r\nNow Grun's Theorem shows $O^p(G) \\ne G$ and by induction on $|G|$, $O^p(G)$ has a normal $p$-complement, $K$.\r\n$K \\lhd G$ and $G/K$ is a $p$-group, so $K$ is also a normal $p$-complement of $G$.\r\n\\end{quote}\r\n{\\bf Theorem 23:} A finite group $G$ has a normal $p$ complement iff a Sylow $p$-group\r\ncontrols its own fusion.  \r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n\\\\\r\n\\\\\r\n$\\rightarrow$:  Let $P \\in S_p(G)$ and $N$ be a normal $p$ complement so $G=NP$.\r\nSuppose $x, y \\in P$ and $x^g=y$.  Let ${\\overline G}= G/N$ so the isomorphism\r\n$G \\rightarrow {\\overline G}$ induces an isomorphism of $P$ onto ${\\overline G}$.\r\n${\\overline x}$ and\r\n${\\overline y}$ are conjugate in \r\n${\\overline G}$ so by the isomorphism, they are $P$-conjugate and $P$ controls its own\r\nfusion.\r\n\\\\\r\n\\\\\r\n$\\leftarrow$:  Let $N= O^p(G)$, $Q= N \\cap P$ so $Q \\in S_p(N)$.  We show $Q=1$ and hence\r\n$N$ is a normal $p$-complement.\r\n\\\\\r\n\\emph{Claim:} $N= A^p(N)=N$.\r\n\\\\\r\n\\emph{Proof of claim:}\r\n$A^p(N) \\; char \\; N$ so $A^p(N) \\lhd G$.  Further,\r\n$|G:A^p(N)|= |G:N||N:A^p(N)|$, which is a $p$-power.  Thus\r\n$N= O^p(G) \\subseteq A^p(N)$ and $O^p(N)=A^p(N)$ as claimed.\r\n\\\\\r\nBy the focal subgroup theorem,  $Foc_N(Q)= Q \\cap A^p(N)= Q \\cap N = Q$.  Let\r\n$x, y \\in Q$ be $N$-conjugate so $x^{-1}y$ is a typical generator in $Foc_N(Q)$.\r\n$\\exists u \\in P: x^u=y$ so $x^{-1}y = [x,u] \\in [Q, P]$.  So\r\n$Q= Foc_N(Q) \\subseteq [Q, P]$, so $Q \\subseteq [Q, P, P, \\ldots ,P]$ but\r\n$Q \\subseteq P$ and $P$ is nilpotent so $[Q, P, \\ldots , P]= 1$ eventually and so\r\n$Q= 1$.\r\n\\end{quote}\r\n{\\bf Theorem 23a:}  The following are equivalent:\r\n(1) $G$ has a normal $p-$complement, \r\n(2) Each $p-$local subgroup of $G$ has a normal $p-$complement,\r\n(3) $Aut_G(P)$ is a $p-$group $\\forall P \\in p(G)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$1 \\rightarrow 2 \\rightarrow 3$ is easy.\r\n\\\\\r\n\\emph{Claim:} Assume $N_G(X)/C_G(X)$ is a $p$-group for every $p$-group, $X$, of a finite\r\ngroup $G$ and let $P, Q \\in S_p(G)$ then $Q=P^c$ for some $c \\in C_G(P \\cap Q )$.\r\n\\\\\r\n\\emph{Proof of claim:}\r\nAssume (3).  It suffices to show that $P$ controls its own fusion in $G$.  If\r\n$x,y \\in P$ are conjugate in $G$, $x^g=y$, $y \\in P \\cap P^g$ and by the claim,\r\n$\\exists c \\in C_G(P \\cap P^g): (P^G)^c=P$.  Since $N_G(P)/C_G(P)$ is a $p$-group\r\nand $P$ is a Sylow $p$-subgoup of $N_G(P)$,  $N_G(P)= C_G(P)P$.  We have\r\n$gc=tu$, $t \\in C_G(P)$ and $u \\in P$.  Since $x \\in P$ and $[x,t]=1$ and thus\r\n$y=y^c=x^{gc}=x^{tu}=x^u$ so $x$ and $y$ are $P$-conjugate.\r\n\\end{quote}\r\n{\\bf Definition 5:} $G$ is $\\pi$-closed if $G/O_{\\pi}(G)$ is a $\\pi'$ group and thus\r\n$O_{\\pi}(G)=O^{\\pi'}(G)$.\\\\\r\n\\\\\r\n{\\bf Definition 6:} $A^{\\pi}(G)$ is the unique smallest normal subgroup of $G$ such that\r\n$G/A^{\\pi}(G)$ is an abelian $\\pi$-group.  If $P \\subseteq H \\subseteq G$ then\r\n$ |G:A^p(G)| \\le |H:A^p(H)|$ if equality holds we say $H$ \\emph {controls $p$-transfer in $G$}.\r\n\\\\\r\n\\\\\r\n{\\bf Burnside $p$-complement theorem:}  If $C_G(P)= N_G(P)$ then $G$ has a normal $p$-complement.\r\n\\begin{quote}\r\n\\emph{Proof:}  Obviously, $P$ controls its own fusion in this case and the result follows.\r\n\\end{quote}\r\n{\\bf Theorem 24:}  If $P \\in S_p(G)$ and $H$ controls $p$-fusion in $P$ then $H$ controls $p$-transfer\r\nin $G$.  If $P \\in S_p(G)$ is abelian, then $N_G(P)$ controls $p$-transfer.  \r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nWant to show $|G:V_{G \\rightarrow P}| = |H:V_{H \\rightarrow P}|$ this happens iff\r\n$P \\cap ker(V_{G \\rightarrow P}) = Foc_G(P) = P \\cap ker(V_{H \\rightarrow P}) = Foc_H(G)$.\r\n$Foc_G(P) = Foc_G(H)$ since $H$ controls $G$-fusion.\r\n\\end{quote}\r\n{\\bf Theorem 25:} \r\nLet $p \\ne 2$ and suppose every $p$-element is central in\r\n$G$ then $G$ has a normal $p$ complement.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nThis follows from the Frobenius normal $p$-complement theorem.\r\n\\end{quote}\r\n{\\bf Theorem 26:} \r\nLet $G$ be a finite group $H \\le G$, $(p, |G:H|)=1, K \\lhd H$, $H/K$ abelian,\r\n$g$ a $p-$element in $H \\setminus K$: $g^{ma} \\in g^m K, \\forall m$, all $a \\in G$ such that\r\n$g^{ma} \\in H$ then $g \\notin G'$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSee, Stellmacher,  p 73.\r\n\\end{quote}\r\n{\\bf Definition 7:} The action of $A$ on $N \\lhd G$ is \\emph{Frobenius} if $n^a \\neq n$, if $a \\neq 1 \\neq n$.\r\n\\\\\r\n\\\\\r\n{\\bf Lemma:}  Let $A<G$ with the TI property for all $g \\in G-A$ then\r\n$X= \\{x: x \\neq y, y= a^g \\}$, $|X|= |G|/|A|$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nIf $A>1$, $A=N_G(A)$ since $A^x=a$ then $A \\cap A^x=A>1$, $x \\in A$.  So $A$ has exactly $|G:A|$ conjugates\r\nin $G$ all with the same TI property as $A$.  These contain $|G:A|(|A|-1)$ non-identity elements of $G$.\r\n$|X|= |G| - |G:A| (|A|-1) = |G:A|$.\r\n\\end{quote}\r\n{\\bf Theorem 27:}\r\nLet $N \\lhd G$ and $A$ is a complement for $N$ in $G$.  The following are equivalent:\r\n(1) The conjugate action of $A$ on $N$ is Frobenius;\r\n(2) $A \\cap A^g = 1$, $\\forall g \\in G-A$;\r\n(3) $C_G(A) \\subseteq A$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$1 \\rightarrow 2$:\r\nIf $A \\cap A^x \\neq 1$ with $x=an$.  $A^x= A^{an}= A^n$ so $A \\cap A^n \\neq 1$ so\r\n$a=a^n$ and $a^n=a \\in A \\cap A^n= 1$ so $n=1$ and $x \\in A$.\r\n\\\\\r\n$2 \\rightarrow 3$:  Suppose $g \\in C_G(A), g \\notin A$ then $g=an$ and $[A, an]=1$ and\r\n$b= b^{an} \\in A \\cap A^n =1$ so $n=1$ by (1).\r\n\\\\\r\n$3 \\rightarrow 1$:\r\nIf $1 \\neq a  \\in A$ by (3), then $C_N(a)= N \\cap C_G(a)=1$ so $a^n \\neq a$ for $n \\neq 1$.\r\n\\end{quote}\r\n", "meta": {"hexsha": "ab530c780b2e5389a813d7452273cf4996701edd", "size": 26544, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "groups/gtTransfer.tex", "max_stars_repo_name": "jlmucb/class_notes", "max_stars_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "groups/gtTransfer.tex", "max_issues_repo_name": "jlmucb/class_notes", "max_issues_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "groups/gtTransfer.tex", "max_forks_repo_name": "jlmucb/class_notes", "max_forks_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.988700565, "max_line_length": 149, "alphanum_fraction": 0.5809975889, "num_tokens": 11283, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359806, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7346927677341498}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Encode the message $0110$ using the 3-repetition code.  Decode the\n  message $100$ $011$ $000$ $110$ $101$ $110$ after correcting single-bit\n  errors.\n\\end{ex}\n\n\\begin{ex}\n  Use the code of Example~\\ref{exa:code-simple} to encode the message\n  $01~11~10~00~01$. Use the syndrome method to correct all single-bit\n  errors in the message $10100~00001~11001$. What is the decoded message?\n\\end{ex}\n\n\\begin{ex}\n  Consider the code\n  \\begin{equation*}\n    C=\\set{000000,011100,111010,101001,100110,110101,010011,001111}.\n  \\end{equation*}\n  Is this a linear code? What are the message length and block length\n  of this code?  What is its Hamming distance? How many errors per\n  code block can this code detect? How many can it correct?\n\\end{ex}\n\n\\begin{ex}\n  Consider a linear code with check matrix\n  \\begin{equation*}\n    H = \\begin{mymatrix}{cccccc}\n      1 & 1 & 0 & 0 & 0 \\\\\n      1 & 0 & 1 & 1 & 0 \\\\\n      1 & 0 & 1 & 0 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Find a generator matrix for this code (hint: the columns of $G$\n  should form a basis for the null space of $H$). List all possible\n  code blocks. What is the Hamming distance of the code? Make a\n  syndrome table for this code.\n\\end{ex}\n\n\\begin{ex}\n  Use the generator matrix\n  \\begin{equation*}\n    G = \\begin{mymatrix}{ccc}\n      1 & 0 & 0 \\\\\n      1 & 1 & 1 \\\\\n      1 & 0 & 1 \\\\\n      0 & 1 & 0 \\\\\n      1 & 1 & 0 \\\\\n      0 & 0 & 1 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  to encode the message $111~110~101~001$. Find a check matrix for\n  this code and make a syndrome table. Is the code 1-error correcting?\n  Use the syndrome method to correct and decode the message\n  $111000~101111~100111~110100$.\n\\end{ex}\n\n\\begin{ex}\n  Construct check and generator matrices of a Hamming code for $r=4$.\n  What is the block length and message length of this code? Encode the\n  message $00110011000~10100000001$. Decode the message\n  $001000010010000~010000001000001$ after correcting single-bit errors.\n  \\begin{sol}\n    The block length is $n=r-1=15$ and the message length is\n    $k=n-r=11$.  The check matrix and generator matrix are not unique,\n    because there are different ways of ordering the columns of the\n    check matrix. Here is one possible answer:\n    \\begin{equation*}\n      H = \\begin{mysmallmatrix}{ccccccccccc|cccc}\n        1&1&0&1&1&0&1&0&1&0&1&1&0&0&0 \\\\\n        1&0&1&1&0&1&1&0&0&1&1&0&1&0&0 \\\\\n        0&1&1&1&0&0&0&1&1&1&1&0&0&1&0 \\\\\n        0&0&0&0&1&1&1&1&1&1&1&0&0&0&1 \\\\\n      \\end{mysmallmatrix},\n      \\quad\n      G = \\begin{mysmallmatrix}{ccccccccccc}\n        1&0&0&0&0&0&0&0&0&0&0 \\\\\n        0&1&0&0&0&0&0&0&0&0&0 \\\\\n        0&0&1&0&0&0&0&0&0&0&0 \\\\\n        0&0&0&1&0&0&0&0&0&0&0 \\\\\n        0&0&0&0&1&0&0&0&0&0&0 \\\\\n        0&0&0&0&0&1&0&0&0&0&0 \\\\\n        0&0&0&0&0&0&1&0&0&0&0 \\\\\n        0&0&0&0&0&0&0&1&0&0&0 \\\\\n        0&0&0&0&0&0&0&0&1&0&0 \\\\\n        0&0&0&0&0&0&0&0&0&1&0 \\\\\n        0&0&0&0&0&0&0&0&0&0&1 \\\\\\hline\n        1&1&0&1&1&0&1&0&1&0&1 \\\\\n        1&0&1&1&0&1&1&0&0&1&1 \\\\\n        0&1&1&1&0&0&0&1&1&1&1 \\\\\n        0&0&0&0&1&1&1&1&1&1&1 \\\\\n      \\end{mysmallmatrix}.\n    \\end{equation*}\n    With these matrices, the encoding of $00110011000~10100000001$ is\n    $001100110000110~101101110110101$. The error syndrome for\n    $001000010010000$ is $1010$, which corresponds to an error in bit\n    $2$. We find that the corrected code block is $011000010010000$,\n    and the decoding is $01100001001$. The error syndrome for\n    $010000100000001$ is $0110$, which corresponds to an error in bit\n    $3$. The corrected code block is $011000100000001$ and the\n    decoding is $01100010000$.  However, if you have used a different\n    check matrix and/or generator matrix, your answers might differ.\n  \\end{sol}\n\\end{ex}\n\n\n\n", "meta": {"hexsha": "21b272f22222d6dd551d020fb28c177d88038988", "size": 3760, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/VectorSpaces-ErrorCorrectingCodes.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/VectorSpaces-ErrorCorrectingCodes.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/VectorSpaces-ErrorCorrectingCodes.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 34.8148148148, "max_line_length": 73, "alphanum_fraction": 0.6228723404, "num_tokens": 1467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950907764119, "lm_q2_score": 0.8705972616934408, "lm_q1q2_score": 0.7346927551864818}}
{"text": "\\section{Neural Networks}\n% only CNN?\n\\textbf{Activation:} $\\tanh(x)=\\frac{e^x-e^{-x}}{e^x+e^{-x}}$ sigmoid $s(x)= \\frac{1}{1+e^{-x}},s^{'}(x)=s(x)(1-s(x))$, ReLU $\\max(0,x)$\\\\\n\\textbf{Neurons}: $F_\\sigma(\\mathbf{x};\\mathbf{w}) = \\sigma(w_0 + \\sum_{i=1}^M{x_iw_i})$.\\\\ \\textbf{Output}: linear regression $\\mathbf{y} = \\mathbf{W}^L\\mathbf{x}^{L-1}$, binary (logistic) $y_1 = \\text{P}[Y=1|\\mathbf{x}] = \\frac{1}{1 + \\exp(-\\mathbf{w}^T \\mathbf{x}^{L-1})}$, multiclass (soft-max) $y_k = \\text{P}[Y=k|\\mathbf{x}]= \\frac{\\exp( \\mathbf{w}_k^T\\mathbf{x}^{L-1})}{\\sum_{m=1}^{K}{\\exp(\\mathbf{w}^T\\mathbf{x}^{L-1})}}$.\n\\textbf{Loss function} $l(y, \\hat{y})$: squared loss $\\frac{1}{2}(y - \\hat{y})^2$, cross-entropy loss $-y \\log \\hat{y} - (1-y)\\log(1-\\hat{y})$.  \\textbf{Units and Layers}: layer-to-layer fwd. prop. notation: $\\mathbf{x}^{l} = \\sigma^{l}\\left(\\mathbb{W}^{\\left(l\\right)}\\mathbf{x}^{\\left(l-1\\right)}\\right)$. L-layer network: $\\mathbf{y}=\\sigma^{\\left(L\\right)}\\left(\\mathbf{W}^(L)\\sigma^{(L-1)}\\left(\\cdots\\left(\\sigma^{(1)}\\left(\\mathbf{W}^{(1)}\\mathbf{x}\\right)\\cdots\\right)\\right)\\right)$\n\n\\subsection*{Backpropagation}\nLayer-to-layer Jacobian: $\\mathbf{x}$ = prev. layer activation, $\\mathbf{x^+}$ = next layer activation. Jacobian matrix $\\mathbf{J}$ = $J_{ij}$ of mapping $\\mathbf{x}\\rightarrow\\mathbf{x^+}$, $\\mathbf{x_i^+} = \\sigma(\\mathbf{w}_i^\\top\\mathbf{x})$, $J_{ij} = \\frac{\\partial \\mathbf{x_i^+}}{\\partial \\mathbf{x}_j} = w_{ij}\\cdot\\sigma'(\\mathbf{w}_i^\\top\\mathbf{x})$. Across multiple layers: $\\frac{\\partial\\mathbf{x}^{(l)}}{\\partial\\mathbf{x}^{(l-n)}} = \\mathbf{J}^{(l)}\\cdot\\frac{\\partial\\mathbf{x}^{(l-1)}}{\\partial\\mathbf{x}^{(l-n)}}=\\mathbf{J}^{(l)}\\cdot\\mathbf{J}^{(l-1)}\\cdots\\mathbf{J}^{(l-n+1)}$ and then back prop. $ \\nabla_{\\mathbf{x}^{(l)}}^\\top\\ell=\\nabla_{\\mathbf{y}}^\\top\\ell\\cdot\\mathbf{J}^{(L)}\\cdots\\mathbf{J}^{(l+1)}$\\\\\nWeights: $\\frac{\\partial l}{\\partial w_{ij}^{(l)}} = \\frac{\\partial l}{\\partial x_i^{(l)}}\\frac{\\partial x_i^{(l)}}{\\partial w_{ij}^{(l)}}$, $\\frac{\\partial x_i^{l}}{\\partial w_{ij}^{l}} = \\sigma'([\\mathbf{w}_i^{(l)}]^T \\mathbf{x}^{(l-1)})\\cdot x_j^{(l-1)}$ (sensitivity of down-stream unit $\\cdot$ activation of up-stream unit)\n\n\\subsection*{Gradient Descent (or Deepest Descent)}\n\\textbf{Gradient}: $\\nabla f(\\mathbf{x}) := \\left( \\frac{\\partial f(\\mathbf{x})}{\\partial \\mathbf{x}_1}, \\ldots, \\frac{\\partial f(\\mathbf{x})}{\\partial \\mathbf{x}_D} \\right)^\\top$\n\n1. init: $\\mathbf{x}^{(0)} \\in \\mathbb{R}^D$\\\\\n2. for $t = 0 \\ \\text{to} \\ \\mathit{maxIter}$:\\\\\n3. $\\mathbf{x}^{(t+1)} = \\mathbf{x}^{(t)} - \\gamma \\nabla f(\\mathbf{x}^{(t)})$, usually $\\gamma \\approx \\frac{1}{t}$\n\n\\subsection*{Stochastic Gradient Descent (SGD)}\nAssume \\textbf{Additive Objective}:\\\\\n$f(x) = \\frac{1}{N}\\sum_{n=1}^{N}f_n(x)$\\\\\n1. init: $\\mathbf{x}^{(0)} \\in \\mathbb{R}^D$\\\\\n2. for $t = 0 \\ \\text{to} \\ \\mathit{maxIter}$:\\\\\n3. sample $n \\in_{u.a.r.} \\{1, \\ldots, N\\}$\\\\\n4. $\\mathbf{x}^{(t+1)} = \\mathbf{x}^{(t)} - \\gamma \\nabla f_n(\\mathbf{x}^{(t)})$, typically  $\\gamma \\approx \\frac{1}{t}$.\n\n\\subsection*{Neural Networks for Images (CNN)}\nTranslation invariance of images $\\rightarrow$ neurons compute same fct, shift invariant filters; weights defined as filter masks, e.g. convolution: $F_{n,m}(\\mathbf{x};\\mathbf{w}) = \\sigma(b + \\sum_{k=-2}^2\\sum_{l=-2}^{2}{w_{k,l}x_{n+k,m+l}})$. To reduce dimension of convolution, use \\{max, avg\\}-pooling", "meta": {"hexsha": "4fbc1f0bad7e0aca216022daa3e8582252065880", "size": 3391, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "NeuralNetworks.tex", "max_stars_repo_name": "vscherer/eth-cil-exam-cheatsheet", "max_stars_repo_head_hexsha": "9ae156bcf5e2797e65b5495ff520649b43860cdd", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-09-24T20:33:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-21T15:52:46.000Z", "max_issues_repo_path": "NeuralNetworks.tex", "max_issues_repo_name": "vscherer/eth-cil-exam-cheatsheet", "max_issues_repo_head_hexsha": "9ae156bcf5e2797e65b5495ff520649b43860cdd", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NeuralNetworks.tex", "max_forks_repo_name": "vscherer/eth-cil-exam-cheatsheet", "max_forks_repo_head_hexsha": "9ae156bcf5e2797e65b5495ff520649b43860cdd", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-01-14T16:21:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-18T17:17:10.000Z", "avg_line_length": 125.5925925926, "max_line_length": 734, "alphanum_fraction": 0.6071955175, "num_tokens": 1439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947101574299, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7345442521410311}}
{"text": "\\subsection{The Position of the Sound Source}\n\nThe position of the sound source needs to be referenced both in terms of $O$ and in terms of the position of $m$. Given $\\theta_s$ and $d_S$, its position $(x,y)$ can be found through the usual conversion:\n\n\\begin{equation}\n\\begin{bmatrix} x_S \\\\ y_S \\end{bmatrix} = \\begin{bmatrix} \\cos{\\theta_S} \\\\ \\sin{\\theta_S} \\end{bmatrix}\n\\end{equation}\n\nFollowing this, finding the position of the sound source relative to the microphone, $(x,y)_{Sm}$ can be done by shifting the reference origin in terms of the position of $m$:\n\n\\begin{equation}\n\\begin{bmatrix} x_Sm \\\\ y_Sm \\end{bmatrix} = \\begin{bmatrix} x_S \\\\ y_S \\end{bmatrix} + \\begin{bmatrix} x_m \\\\ y_m \\end{bmatrix}\n\\end{equation}\n\n\\subsection{Finding $d_{\\vec{mS}}$}\n\nWith the positions of the sound source and the microphones defined in the virtual space, it becomes important to define their relationships to one another. Since the encoding of the source at each microphone depends on the relationship between the source's location and the location of the microphone. These key parameters can be derived from a vector taken from the microphone to the source, $\\vec{v}_m = \\vec{mS}$.\n\nIf follows that:\n\n\\begin{equation}\\label{distance}\nd_{\\vec{v}} = \\sqrt{\n(x_s - x_m)^2 + (y_s - y_m)^2\n}\n\\end{equation}\n\n\\subsection{Finding $\\theta_{mS}$}\n\nSince a microphone's polar directivity pattern applies an amplitude scalar based on the amount of angular deflection the source is away from the forward-facing axis of the microphone, $\\theta_mS$ should represent this amount of deflection. There are two different methods that can be used to find $\\theta_mS$.\n\n\\subsubsection{Difference in rotations}\n\nThe first method is to find the angular rotation of the position of $S$ around the position of $m$, and then taking the difference of this angular rotation and the amount of rotation of the virtual microphone ($\\theta_m$).\n\n\\begin{equation}\n\\theta_{mS} = \\tan^{-1}\\left(\\frac{y_{Sm}}{x_{Sm}}\\right) - \\theta_m\n\\end{equation}\n\n\\subsubsection{Using linear transformations}\n\nAlternatively, the endpoint of $\\vec{v}$ could be redefined by applying a rotation matrix based on $\\theta_m$\n\n\\begin{equation}\\label{rotationMatrix}\n\\begin{bmatrix} X \\\\ Y \\end{bmatrix} = \\begin{bmatrix} \\cos{\\theta_m} & -\\sin{\\theta_m} \\\\ \\sin{\\theta_m} & \\cos{\\theta_m} \\end{bmatrix} \\cdot \\begin{bmatrix} x_{Sm} \\\\ y_{Sm} \\end{bmatrix}\n\\end{equation}\n\n\\begin{equation}\\label{arctan}\n\\theta_{mS} = \\tan^{-1}\\left(\\frac{Y}{X}\\right)\n\\end{equation}\n\nBy combining (\\ref{rotationMatrix}) and (\\ref{arctan}):\n\n\\begin{equation}\n\t\\theta_{mS} = \\tan^{-1}\\left(\\frac{x_{Sm}\\sin{\\theta_m} + y_{Sm}\\cos{\\theta_m}}{x_{Sm}\\cos{\\theta_m} - y_{Sm}\\sin{\\theta_m}}\\right)\n\\end{equation}\n", "meta": {"hexsha": "5a69c121b8eef1830b5734cdd0d29c6f5ba70c31", "size": 2740, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Technical Documentation/positionalrelationships.tex", "max_stars_repo_name": "jmclark85/StereoPairsEmulator", "max_stars_repo_head_hexsha": "a78161b4b99b50e481c133ba8a5049d548561954", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Technical Documentation/positionalrelationships.tex", "max_issues_repo_name": "jmclark85/StereoPairsEmulator", "max_issues_repo_head_hexsha": "a78161b4b99b50e481c133ba8a5049d548561954", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-26T18:24:14.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-26T18:24:14.000Z", "max_forks_repo_path": "Technical Documentation/positionalrelationships.tex", "max_forks_repo_name": "jmclark85/StereoPairsEmulator", "max_forks_repo_head_hexsha": "a78161b4b99b50e481c133ba8a5049d548561954", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.9285714286, "max_line_length": 416, "alphanum_fraction": 0.7313868613, "num_tokens": 801, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465116437761, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7345356416972887}}
{"text": "\n\\subsection{Difference-in-difference}\n\nConsider the grouped linear model: \n\n\\(y_{ij}=\\mu+\\tau_i+X_{j}\\theta +\\epsilon_{ij}\\)\n\nBy taking differences with another observation in the same group we remove the average terms.\n\n\\(y_{ij}-y_{ik}=(\\mu+\\tau_i+X_{j}\\theta +\\epsilon_{ij})- (\\mu + \\tau_i + X_{k}\\theta + \\epsilon_{ik})\\)\n\n\\(y_{ij}-y_{ik}=(X_{j}\\theta - X_{k})+(\\epsilon_{ij}- \\epsilon_{ik})\\)\n\n\n\ndiff in diff: control group and treated group. page on leakiness? are control affected too? Assumption: in absense of treatment, price would have evolved like control\n\n", "meta": {"hexsha": "c17193c4abe0f23912fdd126fad297f6bc9a84aa", "size": 569, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/time/03-01-DiD.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/time/03-01-DiD.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/time/03-01-DiD.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.6111111111, "max_line_length": 166, "alphanum_fraction": 0.7029876977, "num_tokens": 171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.7344769041451327}}
{"text": "\\section{Learning with SGD}\n\\frame{\\tableofcontents[currentsection, hideothersubsections]}\n\n\\begin{frame}\n\\frametitle{Learning with SGD: Risk Minimization}\n\nRecall, in learning:\\\\\n\\begin{itemize}\n\\item want to minimize the risk function, $L_D(\\mathbf{w}) = \\mathbb{E}_{z \\sim D} [\\ell(\\mathbf{w}, z)]$\n\\item do not know $D$, so cannot simply calculate $\\nabla L_D (\\mathbf{w}^{(t)} )$\n\\item as an estimate to minimizing $L_D(w)$: minimize $L_S(w)$~\\footnote{empirical risk}\n\\end{itemize}\n\\vspace{5mm}\n\nSGD minimizes $L_D(w)$ directly:\\\\\nfind an \\textbf{unbiased estimate} of the gradient of $L_D(\\mathbf{w})$, that is,\\\\\na random vector whose conditional expected value is $\\nabla L_D (\\mathbf{w}^{(t)} )$\n\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitle{Learning with SGD: Risk Minimization}\n\nConstruction of the random vector $\\mathbf{v}_t$ for  a differentiable risk fn $L_D$:\n\\begin{itemize}\n\\item sample $z \\sim D$\n\\item define $\\mathbf{v}_t$ to be the gradient of $\\ell(\\mathbf{w}, z)$ wrt $\\mathbf{w}$, at $\\mathbf{w}^{(t)}$\n\\item by the linearity of the gradient we have:\n    \\begin{figure}\n        \\centering\n        \\includegraphics[scale=0.25]{eq_14_13}\n    \\end{figure}\n\\end{itemize}\n\\vspace{5mm}\n\nThus, the gradient of the loss function $\\ell(w, z)$ at $\\mathbf{w}^{(t)}$ is\n\\begin{itemize}\n\\item unbiased estimate of the gradient of the risk function $L_D( w^{(t)} )$ and\n\\item constructed by sampling a single fresh example $z \\sim D$ at each iteration $t$.\n\\end{itemize}\n\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitle{Learning with SGD: Risk Minimization}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.25]{sgd2}\n\\end{figure}\n\nSame for nondifferentiable loss functions,\\\\\nsimply let $\\mathbf{v}_t$ be a subgradient of $\\ell(\\mathbf{w}, z)$ at $\\mathbf{w}^{(t)}$\n\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Learning with SGD: Convex-Smooth Learning Problems}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.25]{theorem_14_13}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.25]{corollary_14_14}\n\\end{figure}\n\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Learning with SGD: Regularized Loss Minimization}\n\nWHAT:\\\\\nto solve the regularized loss minimization:\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.25]{eq_14_14}\n\\end{figure}\n\nWHY:\\\\\n\\begin{itemize}\n\\item SGD enjoys the same worst-case sample complexity bound as regularized loss minimization\n\\item on some distributions, regularized loss minimization may yield a better solution.\n\\end{itemize}\n\nHOW:\\\\\n...\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Learning with SGD: Regularized Loss Minimization}\n\nWHAT:\\\\\nto solve the regularized loss minimization:\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.25]{eq_14_14}\n\\end{figure}\n\nHOW:\\\\\n\\begin{itemize}\n\\item define $f(\\mathbf{w}) = \\frac{\\lambda}{2} \\parallel w \\parallel^2 + L_S(\\mathbf{w})$.\n    \\begin{itemize}\n        \\item $f$ is a $\\lambda$-strongly convex function;\n        \\item therefore, apply the SGD variant with $\\mathcal{H} = \\mathbb{R}^d$.\n    \\end{itemize}\n\\item construct an unbiased estimate of a subgradient of $f$ at $\\mathbf{w}^{(t)}$\n    \\begin{itemize}\n        \\item pick $z$ uniformly at random from $S$,\n        \\item choose $\\mathbf{v}_t$ in $\\partial \\ell(\\mathbf{w}^{(t)}, z)$\n        \\item (then) the expected value of $\\lambda \\mathbf{w}^{(t)} + \\mathbf{v}t$ is a subgradient of f at $\\mathbf{w}^{(t)}$.\n    \\end{itemize}\n\\end{itemize}\n\n\\end{frame}\n\n", "meta": {"hexsha": "d451a056a2ab08b695f3851ddd2b2d8e141b31b9", "size": 3446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "talk/tor/cvx-sgd-20180316/learning_with_sgd.tex", "max_stars_repo_name": "tttor/robot-foundation", "max_stars_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "talk/tor/cvx-sgd-20180316/learning_with_sgd.tex", "max_issues_repo_name": "tttor/robot-foundation", "max_issues_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "talk/tor/cvx-sgd-20180316/learning_with_sgd.tex", "max_forks_repo_name": "tttor/robot-foundation", "max_forks_repo_head_hexsha": "779b0d9583fe0f4c582f03b808dd2b7027088493", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.479338843, "max_line_length": 128, "alphanum_fraction": 0.6926871735, "num_tokens": 1123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7344692842402023}}
{"text": "\n\\subsection{Lévy distribution}\n\n\\subsubsection{Definition}\n\nThe Lévy distribution is a continuous probability distribution.\n\nThe marginal probability is:\n\n\\(P(X)=\\sqrt {\\dfrac{c}{2\\pi }}\\dfrac{e^{-\\dfrac{c}{2(x-\\mu )}}}{(x-\\mu )^{\\dfrac{3}{2}}}\\)\n\n", "meta": {"hexsha": "11d661f7cadb61a67d81e355cd918fc267014c2e", "size": 249, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/distributionsContinous/01-05-levy.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/distributionsContinous/01-05-levy.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/distributionsContinous/01-05-levy.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.75, "max_line_length": 91, "alphanum_fraction": 0.6787148594, "num_tokens": 82, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9481545304202038, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7344247498180055}}
{"text": "\n\\subsection{The Solow-Swan model}\n\n\\subsubsection{Recap of growth models}\n\nAs with the Harrod-Domar model we have output as a function of capital:\n\n\\(Y=f(K)\\)\n\nCapital dynamics:\n\n\\(\\dot K=I-\\delta K\\)\n\n\\(I=S=sY\\)\n\nThis gives us:\n\n\\(\\dot K = sY-\\delta K\\)\n\n\\subsubsection{Recap of the Harrod-Domar model}\n\nThe production function of the Harrod-Domar model is:\n\n\\(Y=cK\\)\n\nAnd long-term growth of:\n\n\\(\\dfrac{\\dot Y}{Y}=sc-\\delta \\)\n\n\\subsubsection{The Solow-Swan production function}\n\nWe use a new production function:\n\n\\(Y=K^\\alpha (AL)^{1-\\alpha }\\)\n\nWe add dynamics for technology and labour.\n\n\\(A_t=A_0e^{gt}\\)\n\n\\(L_t=L_0e^{nt}\\)\n\n\\(Y_t=K_t^\\alpha (A_0e^{gt}L_0e^{nt})^{1-\\alpha }\\)\n\n\\subsubsection{Effective captial}\n\n\\(k_t=\\dfrac{K_t}{A_tL_t}\\)\n\n\\(Y_t=\\dfrac{Y_t}{A_tL_t}\\)\n\nThe dynamics of effective capital is:\n\n\\(\\dot k_t=sk_t^{\\alpha }-(n+\\delta +g)k_t\\)\n\n\\subsubsection{Steady state}\n\nIn equilibrium effective capital is stable.\n\n\\(\\dot k_t^*=sk_t^{\\alpha }-(n+\\delta +g)k_t^8=0\\)\n\n\\(sk_t^{*\\alpha }=(n+\\delta +g)k_t^8\\)\n\n\\(k_t^*=\\biggr (\\dfrac{s}{n+g+\\delta }\\biggr )^{\\dfrac{1}{1-\\alpha }}\\)\n\n", "meta": {"hexsha": "fb540e5b1c8d7876f80c658472e8f261e47b14e4", "size": 1104, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/neoClassical/03-02-solowSwan.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/neoClassical/03-02-solowSwan.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/neoClassical/03-02-solowSwan.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.25, "max_line_length": 71, "alphanum_fraction": 0.6576086957, "num_tokens": 399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.7956581024858785, "lm_q1q2_score": 0.7344235899902509}}
{"text": "\\chapter{Bonus: Cellular homology}\nWe now introduce cellular homology, which essentially lets us compute\nthe homology groups of any CW complex we like.\n\n\\section{Degrees}\n\\prototype{$z \\mapsto z^d$ has degree $d$.}\nFor any $n > 0$ and map $f : S^n \\to S^n$, consider\n\\[ f_\\ast : \\underbrace{H_n(S^n)}_{\\cong \\ZZ} \\to \\underbrace{H_n(S^n)}_{\\cong \\ZZ} \\]\nwhich must be multiplication by some constant $d$.\nThis $d$ is called the \\vocab{degree} of $f$, denoted $\\deg f$.\n\\begin{ques}\n\tShow that $\\deg(f \\circ g) = \\deg(f) \\deg(g)$.\n\\end{ques}\n\n\\begin{example}\n\t[Degree]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii For $n=1$, the map $z \\mapsto z^k$ (viewing $S^1 \\subseteq \\CC$)\n\t\thas degree $k$.\n\t\t\\ii A reflection map $(x_0, x_1, \\dots, x_n) \\mapsto (-x_0, x_1, \\dots, x_n)$\n\t\thas degree $-1$; we won't prove this, but geometrically this should be clear.\n\t\t\\ii The antipodal map $x \\mapsto -x$ has degree $(-1)^{n+1}$\n\t\tsince it's the composition of $n+1$ reflections as above.\n\t\tWe denote this map by $-\\id$.\n\t\\end{enumerate}\n\\end{example}\n\nObviously, if $f$ and $g$ are homotopic, then $\\deg f = \\deg g$.\nIn fact, a theorem of Hopf says that this is a classifying invariant:\nanytime $\\deg f = \\deg g$, we have that $f$ and $g$ are homotopic.\n\nOne nice application of this:\n\\begin{theorem}\n\t[Hairy ball theorem]\n\tIf $n > 0$ is even, then $S^n$ doesn't have a continuous field\n\tof nonzero tangent vectors.\n\\end{theorem}\n\\begin{proof}\n\tIf the vectors are nonzero then WLOG they have norm $1$;\n\tthat is for every $x$ we have an orthogonal unit vector $v(x)$.\n\tThen we can construct a homotopy map $F : S^n \\times [0,1] \\to S^n$ by\n\t\\[ (x,t) \\mapsto (\\cos \\pi t)x + (\\sin \\pi t) v(x). \\]\n\twhich gives a homotopy from $\\id$ to $-\\id$.\n\tSo $\\deg(\\id) = \\deg(-\\id)$, which means $1 = (-1)^{n+1}$\n\tso $n$ must be odd.\n\\end{proof}\nOf course, the one can construct such a vector field whenever $n$ is odd.\nFor example, when $n=1$ such a vector field is drawn below.\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(5cm);\n\t\tdraw(unitcircle, blue+1);\n\t\tlabel(\"$S^1$\", dir(100), dir(100), blue);\n\t\tvoid arrow(real theta) {\n\t\t\tpair P = dir(theta);\n\t\t\tdot(P);\n\t\t\tpair delta = 0.8*P*dir(90);\n\t\t\tdraw( P--(P+delta), EndArrow );\n\t\t}\n\t\tarrow(0);\n\t\tarrow(50);\n\t\tarrow(140);\n\t\tarrow(210);\n\t\tarrow(300);\n\t\\end{asy}\n\\end{center}\n\n\n\\section{Cellular chain complex}\nBefore starting, we state:\n\\begin{lemma}\n\t[CW homology groups]\n\tLet $X$ be a CW complex. Then\n\t\\begin{align*}\n\t\tH_k(X^n, X^{n-1}) &\\cong\n\t\t\\begin{cases}\n\t\t\t\\ZZ^{\\oplus\\text{\\#$n$-cells of $X$}} & k = n \\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases} \\\\\n\t\t\\intertext{and}\n\t\tH_k(X^n) &\\cong\n\t\t\\begin{cases}\n\t\t\tH_k(X) & k \\le n-1 \\\\\n\t\t\t0 & k \\ge n+1.\n\t\t\\end{cases}\n\t\\end{align*}\n\\end{lemma}\n\\begin{proof}\n\t% I'll prove just the case where $X$ is finite-dimensional as usual.\n\tThe first part is immediate by noting that $(X^n, X^{n-1})$ is a good pair\n\tand $X^n/X^{n-1}$ is a wedge sum of two spheres.\n\tFor the second part, fix $k$ and note that, as long as $n \\le k-1$ or $n \\ge k+2$,\n\t\\[\n\t\t\\underbrace{H_{k+1}(X^n, X^{n-1})}_{=0}\n\t\t\\to H_k(X^{n-1})\n\t\t\\to H_k(X^n)\n\t\t\\to \\underbrace{H_{k}(X^n, X^{n-1})}_{=0}.\n\t\\]\n\tSo we have isomorphisms\n\t\\[ H_k(X^{k-1}) \\cong H_k(X^{k-2}) \\cong \\dots \\cong H_k(X^0) = 0 \\]\n\tand\n\t\\[ H_k(X^{k+1}) \\cong H_k(X^{k+2}) \\cong \\dots \\cong H_k(X). \\qedhere \\]\n\\end{proof}\n\nSo, we know that the groups $H_k(X^k, X^{k-1})$ are super nice:\nthey are free abelian with basis given by the cells of $X$.\nSo, we give them a name:\n\\begin{definition}\n\tFor a CW complex $X$, we define\n\t\\[ \\Cells_k(X) = H_k(X^k, X^{k-1}) \\]\n\twhere $\\Cells_0(X) = H_0(X^0, \\varnothing) = H_0(X^0)$ by convention.\n\tSo $\\Cells_k(X)$ is an abelian group with basis given by\n\tthe $k$-cells of $X$.\n\\end{definition}\n\nNow, using $\\Cells_k = H_k(X^k, X^{k-1})$ let's use\nour long exact sequence and try to string together maps between these.\nConsider the following diagram.\n\n\\begingroup\n\\fontsize{10pt}{12pt}\\selectfont\n\\begin{diagram}\n\t\\small\n\t&& \\underbrace{H_3(X^2)}_{=0} &&&&&&&& \\\\\n\t&& \\dTo~0 &&&&&&&& \\\\\n\t\\boxed{\\Cells_4(X)} & \\rTo^{\\partial_4} & H_3(X^3) & \\rSurj\n\t\t& \\underbrace{H_3(X^4)}_{\\cong H_3(X)} &\n\t\t\\rTo~0 & \\underbrace{H_3(X^4, X^3)}_{= 0} &&&& \\\\\n\t& \\rdDotted~{d_4} & \\dTo~0 &&&&&&&& \\\\\n\t&& \\boxed{\\Cells_3(X)} &&&& \\underbrace{H_1(X^0)}_{=0} &&&& \\\\\n\t&& \\dTo^{\\partial_3} & \\rdDotted~{d_3} &&& \\dTo~0 &&&& \\\\\n\t\\underbrace{H_2(X^1)}_{=0} & \\rTo~0 & H_2(X^2) & \\rInj &\n\t\t\\boxed{\\Cells_2(X)} & \\rTo^{\\partial_2} & H_1(X^1) & \\rSurj &\n\t\t\\underbrace{H_1(X^2)}_{\\cong H_1(X)} & \\rTo~0 &\n\t\t\\underbrace{H_1(X^2, X^1)}_{=0} \\\\\n\t&& \\dSurj &&& \\rdDotted~{d_2} & \\dInj &&&& \\\\\n\t&& \\underbrace{H_2(X^3)}_{\\cong H_2(X)} &&&& \\boxed{\\Cells_1(X)} &&&& \\\\\n\t&& \\dTo~0 &&&& \\dTo^{\\partial_1} & \\rdDotted~{d_1} &&& \\\\\n\t&& \\underbrace{H_2(X^3, X^2)}_{=0} && \\underbrace{H_0(\\varnothing)}_{=0}\n\t\t& \\rTo~0 & H_0(X^0) & \\rInj & \\boxed{\\Cells_0(X)} & \\rTo^{\\partial_0} & \\dots \\\\\n\t&&&&&& \\dSurj &&&& \\\\\n\t&&&&&& \\underbrace{H_0(X^1)}_{\\cong H_0(X)} &&&& \\\\\n\t&&&&&& \\dTo~0 &&&& \\\\\n\t&&&&&& \\underbrace{H_0(X^1, X^0)}_{=0} &&&& \\\\\n\\end{diagram}\n\\endgroup\nThe idea is that we have taken all the exact sequences generated by adjacent\nskeletons, and strung them together at the groups $H_k(X^k)$,\nwith half the exact sequences being laid out vertically\nand the other half horizontally.\n\nIn that case, composition generates a sequence of dotted maps\nbetween the $H_k(X^k, X^{k-1})$ as shown.\n\\begin{ques}\n\tShow that the composition of two adjacent dotted arrows is zero.\n\\end{ques}\n\nSo from the diagram above, we can read off a sequence of arrows\n\\[\n\t\\dots \\taking{d_5} \\Cells_4(X)  \\taking{d_4} \\Cells_3(X)\n\t\\taking{d_3} \\Cells_2(X) \\taking{d_2} \\Cells_1(X)\n\t\\taking{d_1} \\Cells_0(X) \\taking{d_0} 0.\n\\]\nThis is a chain complex, called the \\vocab{cellular chain complex};\nas mentioned before before all the homology groups are free,\nbut these ones are especially nice because for most reasonable CW complexes,\nthey are also finitely generated\n(unlike the massive $C_\\bullet(X)$ that we had earlier).\nIn other words, the $H_k(X^k, X^{k-1})$ are especially nice ``concrete'' free groups\nthat one can actually work with.\n\nThe other reason we care is that in fact:\n\\begin{theorem}[Cellular chain complex gives $H_n(X)$]\n\t\\label{thm:cellular_chase}\n\tThe $k$th homology group of the cellular chain complex\n\tis isomorphic to $H_k(X)$.\n\\end{theorem}\n\\begin{proof}\n\tFollows from the diagram; \\Cref{prob:diagram_chase}.\n\\end{proof}\n\nA nice application of this is to define\nthe \\vocab{Euler characteristic} of a finite CW complex $X$.\nOf course we can write\n\\[ \\chi(X) = \\sum_n (-1)^n \\cdot \\#(\\text{$n$-cells of $X$}) \\]\nwhich generalizes the familiar $V-E+F$ formula.\nHowever, this definition is unsatisfactory because it\ndepends on the choice of CW complex, while we actually\nwant $\\chi(X)$ to only depend on the space $X$ itself\n(and not how it was built). In light of this, we prove that:\n\\begin{theorem}\n\t[Euler characteristic via Betti numbers]\n\tFor any finite CW complex $X$ we have\n\t\\[ \\chi(X) = \\sum_n (-1)^n \\rank H_n(X). \\]\n\\end{theorem}\nThus $\\chi(X)$ does not depend on the choice of CW decomposition.\nThe numbers \n\\[ b_n = \\rank H_n(X) \\]\nare called the \\vocab{Betti numbers} of $X$.\nIn fact, we can use this to define $\\chi(X)$ for any reasonable space;\nwe are happy because in the (frequent) case that $X$ is a CW complex,\n\n\\begin{proof}\n\tWe quote the fact that if $0 \\to A \\to B \\to C \\to D \\to 0$\n\tis exact then $\\rank B + \\rank D = \\rank A + \\rank C$.\n\tThen for example the row\n\t\\begin{diagram}\n\t\t\\underbrace{H_2(X^1)}_{=0} & \\rTo~0 & H_2(X^2) & \\rInj &\n\t\tH_2(X^2, X^1) & \\rTo^{\\partial_2} & H_1(X^1) & \\rSurj &\n\t\t\\underbrace{H_1(X^2)}_{\\cong H_1(X)} & \\rTo~0 &\n\t\t\\underbrace{H_1(X^2, X^1)}_{=0} \\\\\n\t\\end{diagram}\n\tfrom the cellular diagram gives\n\t\\[ \\#(\\text{$2$-cells}) + \\rank H_1(X)\n\t\t= \\rank H_2(X^2) + \\rank H_1(X^1). \\]\n\tMore generally,\n\t\\[ \\#(\\text{$k$-cells}) + \\rank H_{k-1}(X)\n\t\t= \\rank H_k(X^k) + \\rank H_{k-1}(X^{k-1}) \\]\n\twhich holds also for $k=0$ if we drop the $H_{-1}$ terms\n\t(since $\\#\\text{$0$-cells} = \\rank H_0(X^0)$ is obvious).\n\tMultiplying this by $(-1)^k$ and summing across $k \\ge 0$\n\tgives the conclusion.\n\\end{proof}\n\n\\begin{example}\n\t[Examples of Betti numbers]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The Betti numbers of $S^n$ are $b_0 = b_n = 1$,\n\t\tand zero elsewhere. The Euler characteristic is $1 + (-1)^n$.\n\t\t\\ii The Betti numbers of a torus $S^1 \\times S^1$\n\t\tare $b_0 = 1$, $b_1 = 2$, $b_2 = 1$, and zero elsewhere.\n\t\tThus the Euler characteristic is $0$.\n\t\t\\ii The Betti numbers of $\\CP^n$ are $b_0 = b_2 = \\dots = b_{2n} = 1$,\n\t\tand zero elsewhere. Thus the Euler characteristic is $n+1$.\n\t\t\\ii The Betti numbers of the Klein bottle\n\t\tare $b_0 = 1$, $b_1 = 1$ and zero elsewhere. \n\t\tThus the Euler characteristic is $0$, the same as the sphere\n\t\t(also since their CW structures use the same number of cells).\n\t\\end{enumerate}\n\tOne notices that in the ``nice'' spaces $S^n$, $S^1 \\times S^1$ and $\\CP^n$\n\tthere is a nice symmetry in the Betti numbers, namely $b_k = b_{n-k}$.\n\tThis is true more generally; see Poincar\\'e duality and \\Cref{prob:betti}.\n\\end{example}\n\n\\section{The cellular boundary formula}\nIn fact, one can describe explicitly what the maps $d_n$ are.\nRecalling that $H_k(X^k, X^{k-1})$ has a basis the $k$-cells of $X$, we obtain:\n\\begin{theorem}\n\t[Cellular boundary formula for $k=1$]\n\tFor $k=1$, \\[ d_1 : \\Cells_1(X) \\to \\Cells_0(X) \\] is just the boundary map.\n\\end{theorem}\n\\begin{theorem}\n\t[Cellular boundary for $k > 1$]\n\tLet $k > 1$ be a positive integer.\n\tLet $e^k$ be an $k$-cell, and let $\\{e_\\beta^{k-1}\\}_\\beta$\n\tdenote all $(k-1)$-cells of $X$.\n\tThen \\[ d_k : \\Cells_k(X) \\to \\Cells_{k-1}(X) \\]\n\tis given on basis elements by\n\t\\[ d_k(e^k) = \\sum_\\beta d_\\beta e_\\beta^{k-1} \\]\n\twhere $d_\\beta$ is be the degree of the composed map\n\t\\[ S^{k-1} = \\partial D_\\beta^k \\xrightarrow{\\text{attach}}\n\t\tX^{k-1} \\surjto S_\\beta^{k-1}. \\]\n\tHere the first arrow is the attaching map for $e^k$\n\tand the second arrow is the quotient of collapsing\n\t$X^{k-1} \\setminus e^{k-1}_\\beta$ to a point.\n\\end{theorem}\nThis gives us an algorithm for computing homology groups of a CW complex:\n\\begin{itemize}\n\t\\ii Construct the cellular chain complex,\n\twhere $\\Cells_k(X)$ is $\\ZZ^{\\oplus \\# \\text{$k$-cells}}$.\n\t\\ii $d_1 : \\Cells_1(X) \\to \\Cells_0(X)$ is just the boundary map\n\t(so $d_1(e^1)$ is the difference of the two endpoints).\n\t\\ii For any $k > 1$, we compute $d_k : \\Cells_k(X) \\to \\Cells_{k-1}(X)$\n\ton basis elements as follows.\n\tRepeat the following for each $k$-cell $e^k$:\n\t\\begin{itemize}\n\t\t\\ii For every $k-1$ cell $e^{k-1}_\\beta$,\n\t\tcompute the degree of the boundary of $e^k$ welded onto \n\t\tthe boundary of $e^{k-1}_\\beta$, say $d_\\beta$.\n\t\t\\ii Then $d_k(e^k) = \\sum_\\beta d_\\beta e^{k-1}_\\beta$.\n\t\\end{itemize}\n\t\\ii Now we have the maps of the cellular chain complex,\n\tso we can compute the homologies directly\n\t(by taking the quotient of the kernel by the image).\n\\end{itemize}\n\nWe can use this for example to compute the homology groups of the torus again,\nas well as the Klein bottle and other spaces.\n\n\\begin{example}\n\t[Cellular homology of a torus]\n\tConsider the torus built from $e^0$, $e^1_a$, $e^1_b$ and $e^2$ as before,\n\twhere $e^2$ is attached via the word $aba\\inv b\\inv$.\n\tFor example, $X^1$ is\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tunitsize(0.8cm);\n\t\t\tdraw(shift(-1,0)*unitcircle, blue, MidArrow);\n\t\t\tdraw(shift(1,0)*rotate(180)*unitcircle, red, MidArrow);\n\t\t\tlabel(\"$e^1_a$\", 2*dir(180), dir(180), blue);\n\t\t\tlabel(\"$e^1_b$\", 2*dir(0), dir(0), red);\n\t\t\tdotfactor *= 1.4;\n\t\t\tdot(\"$e^0$\", origin, dir(0));\n\t\t\\end{asy}\n\t\\end{center}\n\tThe cellular chain complex is\n\t\\begin{diagram}\n\t\t0 & \\rTo & \\ZZ e^2 & \\rTo^{d_2} & \\ZZ e^1_a \\oplus \\ZZ e^1_b\n\t\t\t& \\rTo^{d_1} & \\ZZ e^0 & \\rTo^{d_0} & 0 \\\\\n\t\\end{diagram}\n\tNow apply the cellular boundary formulas:\n\t\\begin{itemize}\n\t\t\\ii Recall that $d_1$ was the boundary formula.\n\t\tWe have $d_1(e^1_a) = e_0 - e_0 = 0$ and similarly $d_1(e^1_b) = 0$.\n\t\tSo $d_1 = 0$.\n\n\t\t\\ii For $d_2$, consider the image of the boundary $e^2$ on $e^1_a$.\n\t\tAround $X^1$, it wraps once around $e^1_a$, once around $e^1_b$,\n\t\tagain around $e^1_a$ (in the opposite direction),\n\t\tand again around $e^1_b$.\n\t\tOnce we collapse the entire $e^1_b$ to a point,\n\t\twe see that the degree of the map is $0$.\n\t\tSo $d_2(e^2)$ has no $e^1_a$ coefficient.\n\t\tSimilarly, it has no $e^1_b$ coefficient, hence $d_2 = 0$.\n\t\\end{itemize}\n\tThus \\[ d_1=d_2=0. \\]\n\tSo at every map in the complex, the kernel of the map\n\tis the whole space while the image is $\\{0\\}$.\n\tSo the homology groups are $\\ZZ$, $\\ZZ^{\\oplus 2}$, $\\ZZ$.\n\\end{example}\n\\begin{example}\n\t[Cellular homology of the Klein bottle]\n\tLet $X$ be a Klein bottle.\n\tConsider cells $e^0$, $e^1_a$, $e^1_b$ and $e^2$ as before,\n\tbut this time $e^2$ is attached via the word $abab\\inv$.\n\tSo $d_1$ is still zero, but this time we have\n\t$d_2(e^2) = 2e^1_a$ instead (why?).\n\tSo our diagram looks like\n\t\\begin{diagram}\n\t\t0 & \\rTo & \\ZZ e^2 & \\rTo^{d_2} & \\ZZ e^1_a \\oplus \\ZZ e^1_b\n\t\t\t& \\rTo^{d_1} & \\ZZ e^0 & \\rTo^{d_0} & 0 \\\\\n\t\t&& e^2 & \\rMapsto & 2e^1_a && && \\\\\n\t\t&&&& e_1^a & \\rMapsto & 0 && \\\\\n\t\t&&&& e_1^b & \\rMapsto & 0 && \\\\\n\t\\end{diagram}\n\tSo we get that $H_0(X) \\cong \\ZZ$,\n\tbut \\[ H_1(X) \\cong \\ZZ \\oplus \\Zc2 \\] this time\n\t(it is $\\ZZ^{\\oplus 2}$ modulo a copy of $2\\ZZ$).\n\tAlso, $\\ker d_2 = 0$, and so now $H_2(X) = 0$.\n\\end{example}\n\n\\section\\problemhead\n\\begin{dproblem}\n\tLet $n$ be a positive integer.\n\tShow that\n\t\\[\n\t\tH_k(\\CP^n) \\cong\n\t\t\\begin{cases}\n\t\t\t\\ZZ & k=0,2,4,\\dots,2n \\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases}\n\t\\]\n\t\\begin{hint}\n\t\t$\\CP^n$ has no cells in adjacent dimensions,\n\t\tso all $d_k$ maps must be zero.\n\t\\end{hint}\n\\end{dproblem}\n\n\\begin{problem}\n\tShow that a non-surjective map $f : S^n \\to S^n$ has degree zero.\n\t\\begin{hint}\n\t\tThe space $S^n - \\{x_0\\}$ is contractible.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}[Moore spaces]\n\t\\gim\n\tLet $G_1$, $G_2$, \\dots, $G_N$ be a sequence of\n\tfinitely generated abelian groups.\n\tConstruct a space $X$ such that\n\t\\[\n\t\t\\wt H_n(X)\n\t\t\\cong\n\t\t\\begin{cases}\n\t\t\tG_n & 1 \\le n \\le N \\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases}\n\t\\]\n\\end{problem}\n\n\\begin{problem}\n\t\\label{prob:diagram_chase}\n\tProve \\Cref{thm:cellular_chase},\n\tshowing that the homology groups of $X$\n\tcoincide with the homology groups of the cellular chain complex.\n\t\\begin{hint}\n\t\tYou won't need to refer to any elements.\n\t\tStart with \\[ H_2(X) \\cong H_2(X^3) \\cong\n\t\t\tH_2(X^2) / \\ker \\left[ H_2(X^2) \\surjto H_2(X^3) \\right], \\] say.\n\t\tTake note of the marked injective and surjective arrows.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tFor concreteness, let's just look at the homology at $H_2(X^2, X^1)$\n\t\tand show it's isomorphic to $H_2(X)$.\n\t\tAccording to the diagram\n\t\t\\begin{align*}\n\t\t\tH_2(X) &\\cong H_2(X^3) \\\\\n\t\t\t&\\cong H_2(X^2) / \\ker \\left[ H_2(X^2) \\surjto H_2(X^3) \\right] \\\\\n\t\t\t&\\cong H_2(X^2) / \\img \\partial_3 \\\\\n\t\t\t&\\cong \\img\\left[ H_2(X^2) \\injto H_2(X^2, X^1) \\right] / \\img \\partial_3 \\\\\n\t\t\t&\\cong \\ker(\\partial_2) / \\img\\partial_3 \\\\\n\t\t\t&\\cong \\ker d_2 / \\img d_3. \\qedhere\n\t\t\\end{align*}\n\t\\end{sol}\n\\end{problem}\n\n\\begin{dproblem}\n\t\\gim\n\tLet $n$ be a positive integer. Show that\n\t\\[\n\t\tH_k(\\RP^n)\n\t\t\\cong\n\t\t\\begin{cases}\n\t\t\t\\ZZ & \\text{if $k=0$ or $k=n\\equiv 1 \\pmod 2$} \\\\\n\t\t\t\\Zc2 & \\text{if $k$ is odd and $0 < k < n$} \\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases}\n\t\\]\n\t\\begin{hint}\n\t\tThere is one cell of each dimension.\n\t\tShow that the degree of $d_k$ is $\\deg(\\id)+\\deg(-\\id)$,\n\t\thence $d_k$ is zero or $\\cdot 2$ depending\n\t\ton whether $k$ is even or odd.\n\t\\end{hint}\n\\end{dproblem}\n", "meta": {"hexsha": "6188b6c187b2a7b0e34743aac95b04acc7f7a017", "size": 15544, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/homology/cellular.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/homology/cellular.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/homology/cellular.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.4885844749, "max_line_length": 86, "alphanum_fraction": 0.6367730314, "num_tokens": 6061, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.8723473862936942, "lm_q1q2_score": 0.7343643961713696}}
{"text": "\\externaldocument{paper.tex}\r\n\\section{Experimental results} \\label{sec:results}\r\n\r\n\t\\subsection{Simulated data}\r\n\t\r\n\tConsider an intrinsic manifold $\\mathcal{X}$ corresponding to a 2-dimensions square with a cross shaped hole in its center which makes it non-convex. This latent manifold is observed via the following observation function:\r\n\t\\begin{equation} \\label{eq:simulated_data_observation_function}\r\n\t\\mathbf{y\\left(\\mathbf{x}\\right)}=f\\left(\\mathbf{x}\\right)=\\text{\\ensuremath{\\left[\\begin{array}{c}\r\n\t\t\ty_{1}\\left(\\mathbf{x}\\right)\\\\\r\n\t\t\ty_{2}\\left(\\mathbf{x}\\right)\\\\\r\n\t\t\ty_{3}\\left(\\mathbf{x}\\right) \r\n\t\t\t\\end{array}\\right]}=}\r\n\t\t\\left[\\begin{array}{c}\r\n\t\\sin \\left(2.5 \\cdot x_1 \\right)\\cdot \\sin \\left( x_2 \\right)\\\\\r\n\t\\sin \\left(2.5 \\cdot x_1 \\right)\\cdot \\cos \\left( x_2 \\right)\\\\\r\n\t-\\sin \\left( x_2 \\right)\r\n\t\\end{array}\\right]\r\n\t\\end{equation}\r\n\tThe observation function embeds the data in 3-dimensional Euclidean space by partially wrapping it on the unit sphere. The resulting observed manifold $\\mathcal{Y}=\\left\\{ f\\left(\\mathbf{x}\\right) \\mid \\mathbf{x}\\in\\mathcal{X}\\right\\}$ has the shape of a severed ball with a cross shaped hole in it. In order to generate the sample subsets $\\mathcal{X}_{s}$ and $\\mathcal{Y}_{s}$, $N=1000$ points are sampled uniformly with respect to $\\mathcal{X}$. \r\n\t\r\n\t\\subsubsection{Intrinsic isometric embedding} \\label{ssec:simulated_data_Intrinsic_isometric_embedding}\r\n\tFirst we evaluate the validity of the intrinsic Euclidean distance estimation presented in \\cref{eq:int_dist_approx} and the ability of the embedding method suggested in \\cref{sec:Intrinsic-isometric-manifold-learning} to recover the latent geometric structure of the data, given the intrinsic metric over the observed manifold. To do so we analytically calculate $\\frac{df}{dx}\\left(\\mathbf{x}_{i}\\right)\\frac{df}{dx}\\left(\\mathbf{x}_{i}\\right)^{T}$ by taking the derivative of the observation function given in \\cref{eq:simulated_data_observation_function} with respect to the intrinsic latent variable. \r\n\t\r\n\tThe results of applying the suggested intrinsic isometric embedding algorithm on this data set are displayed in \\cref{fig:punctured_severed_sphere}. In \\cref{fig:punctured_severed_sphere_intrinsic} we present the intrinsic latent manifold in the intrinsic space and in \\cref{fig:punctured_severed_sphere_observed} we present the observed manifold embedded in the observation space. In \\cref{fig:punctured_severed_sphere_intrinsic_metric} we visualize the exact intrinsic metric (the push-forward metric) by plotting corresponding ellipses at several sample points. These  ellipses represent the images of circles of equal radius in the intrinsic space according to the estimated metric, this visualizes the amount of local stretch and contraction in each direction that the observed manifold experiences with respect to the latent intrinsic manifold . In \\cref{fig:punctured_severed_sphere_intrinsic_dist_est} we plot the ground truth intrinsic Euclidean inter-point distances against the approximated inter-point distance using \\cref{eq:int_dist_approx}, this results in a scatter plot where the closer a point is to the diagonal red line, the better the distance estimation of the corresponding intrinsic distance between the point pair is. In \\cref{fig:punctured_severed_sphere_intrinsic_dist_est_knn} we plot the same distance estimation scatter plot but restrict the point pairs represented to distances to the selected $k$ nearest neighbors, which are the only distances which are taken into account by our suggested algorithm. For the following results we used $k=30$. \r\n\t\r\n\tIn order to compare different manifold learning methods we plot for each method the resulting embedding and a scatter plot which for each point pair, compares the Euclidean distance in the resulting embedding to the true intrinsic Euclidean distance as measured in the intrinsic space. In general a concentration of point along the diagonal line represents a better embedding. In order to provide a single quantitative measure of the quality of the reconstruction , we also calculate for each embedding the Stress (\\cref{eq:stress}) of the embedding with respect to the true intrinsic structure. These to graphs are plotted for standard Isomap (\\cref{fig:punctured_severed_sphere_standard_isomap_embedding} and \\cref{fig:punctured_severed_sphere_standard_isomap_stress}, intrinsic Isomap (\\cref{fig:punctured_severed_sphere_standard_isomap_embedding} and \\cref{fig:punctured_severed_sphere_intrinsic_isomap_stress}) and finally for our suggested intrinsic-isometric algorithm (\\cref{fig:punctured_severed_sphere_intrinsic_isometric_embedding} and \\cref{fig:punctured_severed_sphere_intrinsic_isometric_stress}).\r\n\t\r\n\tSimilar results on several other synthetic data sets are provided as supplementary material \\cref{ssec:Additional-results-manifold-learning}.\r\n\t\r\n\t\\begin{figure}[h]\t\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[b]{0.3\\linewidth}\r\n\t\t\t\t\\includegraphics[width=1\\linewidth]{figures/Chapter_3/cross_punctured_2d_square_severed_sphere/intrinsic}\r\n\t\t\t\t\\caption{\\label{fig:punctured_severed_sphere_intrinsic}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.3\\linewidth}\r\n\t\t\t\t\\includegraphics[width=1\\linewidth]{figures/Chapter_3/cross_punctured_2d_square_severed_sphere/observed}\r\n\t\t\t\t\\caption{\\label{fig:punctured_severed_sphere_observed}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.3\\linewidth}\r\n\t\t\t\t\\includegraphics[width=1\\linewidth]{figures/Chapter_3/cross_punctured_2d_square_severed_sphere/metric_local_dense}\r\n\t\t\t\t\\caption{\\label{fig:punctured_severed_sphere_intrinsic_metric}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[b]{0.45\\linewidth}\r\n\t\t\t\t\\includegraphics[width=1\\linewidth]{figures/Chapter_3/cross_punctured_2d_square_severed_sphere/dist_local_dense}\r\n\t\t\t\t\\caption{\\label{fig:punctured_severed_sphere_intrinsic_dist_est}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\t\\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.45\\linewidth}\r\n\t\t\t\t\\includegraphics[width=1\\linewidth]{figures/Chapter_3/cross_punctured_2d_square_severed_sphere/dist_local_dense_knn}\r\n\t\t\t\t\\caption{\\label{fig:punctured_severed_sphere_intrinsic_dist_est_knn}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\\includegraphics[width=1\\linewidth]{figures/Chapter_3/cross_punctured_2d_square_severed_sphere/standard_isomap_embedding}\r\n\t\t\t\t\\caption{\\label{fig:punctured_severed_sphere_standard_isomap_embedding}}\r\n\t\t\t\\end{subfigure} \\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\\includegraphics[width=1\\linewidth]{figures/Chapter_3/cross_punctured_2d_square_severed_sphere/embedding_intrinsic_isomap_local_dense}\r\n\t\t\t\t\\caption{\\label{fig:punctured_severed_sphere_intrinsic_isomap_embedding}}\r\n\t\t\t\\end{subfigure} \\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\\includegraphics[width=1\\linewidth]{figures/Chapter_3/cross_punctured_2d_square_severed_sphere/embedding_intrinsic_isometric_local_dense}\r\n\t\t\t\t\\caption{\\label{fig:punctured_severed_sphere_intrinsic_isometric_embedding}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\\includegraphics[width=1\\linewidth]{figures/Chapter_3/cross_punctured_2d_square_severed_sphere/standard_isomap_stress}\r\n\t\t\t\t\\caption{\\label{fig:punctured_severed_sphere_standard_isomap_stress}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\t\\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\\includegraphics[width=1\\linewidth]{figures/Chapter_3/cross_punctured_2d_square_severed_sphere/stress_intrinsic_isomap_local_dense}\r\n\t\t\t\t\\caption{\\label{fig:punctured_severed_sphere_intrinsic_isomap_stress}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\t\\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\\includegraphics[width=1\\linewidth]{figures/Chapter_3/cross_punctured_2d_square_severed_sphere/stress_intrinsic_isometric_local_dense}\r\n\t\t\t\t\\caption{\\label{fig:punctured_severed_sphere_intrinsic_isometric_stress}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\caption{\\label{fig:punctured_severed_sphere} Punctured severed sphere (embedding). \\protect\\subref{fig:punctured_severed_sphere_intrinsic} Intrinsic space. \r\n\t\t\\protect\\subref{fig:punctured_severed_sphere_observed} Observed space. \r\n\t\t\\protect\\subref{fig:punctured_severed_sphere_intrinsic_metric} Intrinsic metric. \r\n\t\t\\protect\\subref{fig:punctured_severed_sphere_intrinsic_dist_est} Intrinsic distance approximation.\r\n\t\t\\protect\\subref{fig:punctured_severed_sphere_intrinsic_dist_est_knn} Intrinsic distance approximation - $k$-NN only.\r\n\t\t\\protect\\subref{fig:punctured_severed_sphere_standard_isomap_embedding} Standard Isomap embedding.\r\n\t\t\\protect\\subref{fig:punctured_severed_sphere_intrinsic_isomap_embedding} Intrinsic Isomap embedding.\r\n\t\t\\protect\\subref{fig:punctured_severed_sphere_intrinsic_isometric_embedding} Intrinsic Isometric embedding.\r\n\t\t\\protect\\subref{fig:punctured_severed_sphere_standard_isomap_stress} Standard Isomap Stress.\r\n\t\t\\protect\\subref{fig:punctured_severed_sphere_intrinsic_isomap_stress} Intrinsic Isomap Stress.\r\n\t\t\\protect\\subref{fig:punctured_severed_sphere_intrinsic_isometric_stress} Intrinsic Isometric Stress.\r\n\t\t}\r\n\t\\end{figure}\r\n\r\n\tAs expected we see that the distance approximation is indeed valid for short distances for which the manifold is approximately linearly distorted, additionally we see that geodesic distance approximation does not suffer from this since geodesics can be calculated using only local distance information. Finally we see that the  non-convexity of the intrinsic dataset does indeed cause a distortion in the intrinsic isometric embedding when compared to the ground truth.\r\n\r\n\t\\subsubsection{Metric estimation}\r\n\t\r\n\tNext we analyze the effect of using an intrinsic metric estimated from the observed data as opposed to using the exact intrinsic metric (as was the case in \\cref{ssec:simulated_data_Intrinsic_isometric_embedding}). To do so we use the same example used in the previous sub-section under the setting described in \\cref{ssec:Intrinsic-isotropic-GMM} with either $N_{i}=5$ or $N_{i}=200$ measurements made at each sample point, sampled from a isotropic Gaussian probability distribution centered at the sample point with intrinsic variance $\\sigma_{int}^{2}=0.03^{2}$ in the intrinsic space. Additionally observation noise is added with variance $\\sigma_{obs}^{2}=0.03^{2}$.\r\n\t\r\n\tIn \\cref{fig:metric_punctured_severed_sphere} we compare the trivial local estimation (as described in \\cref{ssec:Intrinsic-isotropic-GMM}) and the global estimation approach implemented via a \\ac{ANN} which is suggested in this paper (\\cref{sec:Intrinsic-Metric-Estimation}). For each metric estimation method we plot, similarity to the previous sub-section, a visualization of the metric via ellipsis, a scatter plot of the true intrinsic distance against the approximated intrinsic distances, the resulting low-dimensional embedding and the scatter plot of the Euclidean distances in the embedding compared to the true intrinsic distance ,including a calculation of the Stress value. These are produced for the case of local estimation with dense sampling $N_{i}=200$ (\\cref{fig:1a}, \\cref{fig:1d}, \\cref{fig:1g}, \\cref{fig:1j}), for the case of sparse sampling (\\cref{fig:1b}, \\cref{fig:1e}, \\cref{fig:1h}, \\cref{fig:1k}) and finally for our sugestedd global metric estimation method (\\cref{fig:1c}, \\cref{fig:1f}, \\cref{fig:1i}, \\cref{fig:1l}).\r\n\t\r\n\tSimilar results on several other synthetic data sets are provided as supplementary material \\cref{ssec:Additional-results-manifold-learning}.\r\n\t\r\n\t\\begin{figure}[h]\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_4/cross_punctured_2d_square_severed_sphere/metric_local_dense}\r\n\t\t\t\t\t\\caption{\\label{fig:1a}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_4/cross_punctured_2d_square_severed_sphere/metric_local}\r\n\t\t\t\t\t\\caption{\\label{fig:1b}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_4/cross_punctured_2d_square_severed_sphere/metric_net}\r\n\t\t\t\t\t\\caption{\\label{fig:1c}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_4/cross_punctured_2d_square_severed_sphere/dist_local_dense}\r\n\t\t\t\t\t\\caption{\\label{fig:1d}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_4/cross_punctured_2d_square_severed_sphere/dist_local}\r\n\t\t\t\t\t\\caption{\\label{fig:1e}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_4/cross_punctured_2d_square_severed_sphere/dist_net}\r\n\t\t\t\t\t\\caption{\\label{fig:1f}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_4/cross_punctured_2d_square_severed_sphere/embedding_intrinsic_isometric_local_dense}\r\n\t\t\t\t\t\\caption{\\label{fig:1g}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_4/cross_punctured_2d_square_severed_sphere/embedding_intrinsic_isometric_local}\r\n\t\t\t\t\t\\caption{\\label{fig:1h}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_4/cross_punctured_2d_square_severed_sphere/embedding_intrinsic_isometric_net}\r\n\t\t\t\t\t\\caption{\\label{fig:1i}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_4/cross_punctured_2d_square_severed_sphere/stress_intrinsic_isometric_local_dense}\r\n\t\t\t\t\t\\caption{\\label{fig:1j}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_4/cross_punctured_2d_square_severed_sphere/stress_intrinsic_isometric_local}\r\n\t\t\t\t\t\\caption{\\label{fig:1k}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.32\\linewidth}\r\n\t\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_4/cross_punctured_2d_square_severed_sphere/stress_intrinsic_isometric_net}\r\n\t\t\t\t\t\\caption{\\label{fig:1l}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\r\n\t\\caption{Punctured severed sphere (metric estimation).\r\n\t\t\\protect\\subref{fig:1a} True intrinsic metric.\r\n\t\t\\protect\\subref{fig:1b} Locally estimated intrinsic metric.\r\n\t\t\\protect\\subref{fig:1c} Net learned intrinsic metric.\r\n\t\t\\protect\\subref{fig:1d} Distance estimation using true metric.\r\n\t\t\\protect\\subref{fig:1e} Distance estimation using locally estimated metric.\r\n\t\t\\protect\\subref{fig:1f} Distance estimation using net estimated metric.\r\n\t\t\\protect\\subref{fig:1g} Embedding using true intrinsic metric.\r\n\t\t\\protect\\subref{fig:1h} Embedding using locally learned intrinsic metric.\r\n\t\t\\protect\\subref{fig:1i} Embedding using net learned intrinsic metric.\r\n\t\t\\protect\\subref{fig:1j} Embedding stress using true intrinsic metric.\r\n\t\t\\protect\\subref{fig:1k} Embedding stress using locally estimated intrinsic metric.\r\n\t\t\\protect\\subref{fig:1l} Embedding stress using net learned intrinsic metric}\r\n\t\r\n\t\r\n\t\\label{fig:metric_punctured_severed_sphere}\r\n\t\\end{figure}\r\n\r\n\tWe see that the estimations in the sparse case are ``noisy'' and can sometimes change abruptly between similar locations on the manifold. This noisiness in the estimated distances adversely effects the intrinsic distance estimation is the cornerstone of the algorithm suggested in \\cref{sec:Intrinsic-isometric-manifold-learning} this of course damages the results of the intrinsic-isometric learned representation. Similar results on several other synthetic data sets are provided as supplementary material.\r\n\t\r\n\t\\subsection{Localization in sensor networks}\r\n\t\\label{ssec:localization}\r\n\t\r\n\tIn \\cref{sec:motivation} we provided initial motivation for our work through the simple and intuitive example of localization in sensor networks. We now revisit this example and discuss in detail how the manifold learning algorithm proposed in this work can be applied to this problem. \r\n\t\r\n\tIn this experiment, we simulate positioning of an agent using observations with an unknown model, which is intended to represent the setting encountered for indoor positioning. Through this experiment we examine the advantages of intrinsic geometry preservation and demonstrate its relevance to complex, high-dimensional and realistic scenarios.\r\n\t\r\n\t\\subsubsection{Experiment setting}\r\n\t\\label{sssec:Experiment-setting}\r\n\t\r\n\tThe experimental setting is as follows: An agent is allowed to be located within a compact, path-connected subset $\\mathcal{X}$ of $\\mathbb{R}^{2}$ which represents a closed indoor environment. The shape of $\\mathcal{X}$ used in this experiment is depicted in \\cref{fig:Indoor-environment-shape}. At each point $\\mathbf{x}\\in\\text{\\ensuremath{\\mathcal{X}}}$ a number of measurements of different modalities (which will be described later) are observed. These observations are such that they are only effected by the locations where the measurements are made (and possibly some additional noise which is assumed to be uncorrelated with the location). Such observations are made in enough different locations so that $\\mathcal{X}$ is completely covered. The dimension of the intrinsic vector space is $n=2$ corresponding to the two dimensional physical space and the dimension of the observation space depends on the dimensionality of observation function output but is in general high-dimensional. \r\n\t\r\n\t\\begin{figure}[h]\r\n\t\t\\begin{centering}\r\n\t\t\t\\includegraphics[scale=0.5]{figures/Chapter_5/apt_geometry}\r\n\t\t\\end{centering}\r\n\t\t\\caption{Outline of the intrinsic manifold which represents a confined indoor environment \\label{fig:Indoor-environment-shape}}\r\n\t\\end{figure}\r\n\t\r\n\tAs discussed in \\cref{sec:Intrinsic-Metric-Estimation}, in order to uncover the intrinsic metric of the manifold from the observed data, we require the intrinsic data sampling to adhere to some known structure. For this experiment the intrinsic sampling is assumed to be acquired by the use of a rigid sensor array, as described in \\cref{ssec:Rigid-sensor-array}. The sensor array used consists of measurement points with a structure that corresponds to measurements in two orthogonal directions with $15cm$ distance between measurements as illustrated in \\cref{fig:sensor_array_localization} and depicts the points at which measurements were performed for a sub-set of 13 sampling points.\r\n\t\r\n\r\n\t\\subsubsection{Sensor modalities}\r\n\t\r\n\tTo stress the fact that our algorithm is invariant with respect to the sensor modality (i.e to the specific observation function used), we perform simultaneous observations using multiple\r\n\tdifferent modalities. \r\n\t\r\n\tIn what follows we only discuss two vision related modalities, however results for other modalities are included in the supplementary material \\cref{ssec:additional-results-localization}. \r\n\t\r\n\t\r\n\t\\subsubsection*{Color camera}\r\n\t\t\\label{sssec:Color-camera}\r\n\t\r\n\tThis modality simulates a camera mounted on the agent which shows the environment from the point of view of the agent. To accomplish this, we used ``Blender'', a professional, freely available and open-source 3-dimensional graphics software. Using ``Blender'' \\url{www.blender.org}, we constructed a 3-dimensional model mimicking the interior of an apartment. The created model is shown in \\cref{fig:3D-model-in}. The regions of the model in which there are no objects and in which the simulated agent is allowed to move, correspond to the shape of $\\mathcal{X}$ presented in \\cref{fig:Indoor-environment-shape}.\r\n\r\n\t\\begin{figure}[h]\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[b]{0.45\\columnwidth}%\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/blue_print}\r\n\t\t\t\\end{subfigure} \\hfill\r\n\t\t\t\\begin{subfigure}[b]{0.45\\columnwidth}%\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/blue_print_3d}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\caption{3-dimensional model in Blender\\label{fig:3D-model-in}}\r\n\t\\end{figure}\r\n\t\r\n\t``Blender'' allows us to render an image of the model as seen via a virtual camera. Using this ability, we produce a set of 360 degree panoramic color images of size $128\\times256$ pixels, taken from the point of view of the agent as seen in \\cref{fig:Room-from-Agent's}. These images serve as an observation of the location of the agent. Slight variations in the location of the agent cause slight variations in the point of view of the camera and therefore in the produced image, as seen in \\cref{fig:sensor_array_localization}. These slight observed variations, combined with our assumption about the intrinsic structure of the data allow us to infer the local intrinsic metric.\r\n\t\r\n\t\\begin{figure}[h]\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/roomba_view_1}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/roomba_view_2}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/roomba_view_3}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/roomba_view_4}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\caption{Samples of generated panoramic color images}\r\n\t\t\\label{fig:Room-from-Agent's}\r\n\t\\end{figure}\r\n\t\r\n\t\\begin{figure}[h]\r\n\t\t\\begin{centering}\r\n\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/sensor_array/small_var}\r\n\t\t\\end{centering}\r\n\t\t\\caption{Observation points using a rigid sensor array for a subset of 13 sample points. On the right, one can see the effect of slight variations in agents position on the viewed panoramic images \\label{fig:sensor_array_localization}}\r\n\t\\end{figure}\r\n\t\r\n\tOne of the requirements of the algorithm presented in \\cref{sec:Intrinsic-isometric-manifold-learning}, was that the observations need to only be a function of the latent variable, which in this case is the 2-dimensional location of the agent. Panoramic images produced at the same location but starting from different angles would be cyclically rotated with respect to each other, thus violating this requirement. To overcome this, we make these observations invariant to cyclical rotation on the horizontal axis. We implement this in the frequency domain by applying a Fourier transform to each frame and then estimating and removing the linear phase in the horizontal direction. Since cyclical rotations in the horizontal axis are equivalent to an addition of linear phase in the Fourier domain, this makes the observation invariant to the initial cyclical rotation. \r\n\t\r\n\tIn order to reduce the initial dimensionality of the data, \\ac{PCA} was performed and only the first 100 principle components were taken since these practically contained all the energy/power in the data.\r\n\t\r\n\tImages are used as inputs to our algorithm since this represents a possible realistic setting and since it is a non-liner sensor modality which is easy to simulate using 3-dimensional\r\n\tmodeling software. We wish to emphasis however, that after the per-processing stage in which these images are made invariant to cyclical rotations, the input is no longer treated as an image, and our proposed algorithm uses no additional image or computer vision related computation on the input. This invariance of the algorithm to the input type, allows us to perform the additional stage of dimensionality reduction using \\ac{PCA} which would otherwise not be possible since it ``strips'' the input of its image structure.\r\n\t\r\n\t\\subsubsection*{Depth Camera}\r\n\t\r\n\tAn additional sensor modality, which is also produced using ``Blender'', is a gray-scale depth map, where the gray level at each pixel represents the distance, in that pixels direction, from the observing camera to the nearest object. Several examples of such images are shown in \\cref{fig:Panoramic-depth-images}. Since the geometry of the image acquisition model is similar, the need for imposing invariance to cyclical rotation in the horizontal axis arises again and we perform the same per-processing stages described in \\cref{sssec:Color-camera}. The dimensionality of the input is also reduced using \\ac{PCA} to 40 principle component since this accounts for almost all of the observed energy/power in the data.\r\n\r\n\t\\begin{figure}[h]\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/roomba_depth_1}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/roomba_depth_2}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/roomba_depth_3}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/roomba_depth_5}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\caption{Samples of generated panoramic depth maps \\label{fig:Panoramic-depth-images}}\r\n\t\\end{figure}\r\n\t\r\n\t\t\r\n\t\\subsubsection{Results}\r\n\t\r\n\tFor each of the four modalities described above $N=1000$ intrinsic points were sampled, 3 measurement were made around each such location using the sensor array described, a 2-dimensional embedding was constructed using our proposed algorithm and using the standard Isomap methods. Results are presented in \\cref{fig:Color-image-observations}, \\cref{fig:Depth-image-observations}.\r\n\t\t\t\r\n\t\\begin{figure}[h]\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}%\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/color/intrinsic}\r\n\t\t\t\t\\caption{\\label{fig:3a}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}%\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/color/regular_isomap_embedding}\r\n\t\t\t\t\\caption{\\label{fig:3b}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}%\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/color/dist_local}\r\n\t\t\t\t\\caption{\\label{fig:3c}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}%\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/color/dist_local_knn}\r\n\t\t\t\t\\caption{\\label{fig:3d}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}%\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/color/intrinsic_isometric_local}\r\n\t\t\t\t\\caption{\\label{fig:3e} \\label{fig:bend1}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}%\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/color/intrinsic_isometric_local_stress}\r\n\t\t\t\t\\caption{\\label{fig:3f}} \r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\caption{Color image observations\\label{fig:Color-image-observations}. \r\n\t\t\t\\protect\\subref{fig:3a} Intrinsic space. \r\n\t\t\t\\protect\\subref{fig:3b} Embedding using standard Isomap. \r\n\t\t\t\\protect\\subref{fig:3c} Intrinsic Euclidean distance estimation. \r\n\t\t\t\\protect\\subref{fig:3d} Intrinsic Euclidean distance estimation ($k$-NN). \r\n\t\t\t\\protect\\subref{fig:3e} Intrinsic-isometric embedding. \r\n\t\t\t\\protect\\subref{fig:3f} Euclidean distance discrepancy and stress in resulting embedding}\r\n\t\\end{figure}\r\n\t\r\n\t\\begin{figure}[h]\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/depth/intrinsic}\r\n\t\t\t\t\\caption{\\label{fig:4a}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/depth/regular_isomap_embedding}\r\n\t\t\t\t\\caption{\\label{fig:4b}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/depth/dist_local}\r\n\t\t\t\t\\captionsetup{justification=centering}\r\n\t\t\t\t\\caption{\\label{fig:4c}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/depth/dist_local_knn}\r\n\t\t\t\t\\caption{\\label{fig:4d}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\begin{centering}\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}%\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/depth/intrinsic_isometric_local}\r\n\t\t\t\t\\caption{\\label{fig:4e} \\label{fig:bend2}}\r\n\t\t\t\\end{subfigure}\\hfill\r\n\t\t\t\\begin{subfigure}[t]{0.47\\columnwidth}\r\n\t\t\t\t\\includegraphics[width=1\\textwidth]{figures/Chapter_5/depth/intrinsic_isometric_local_stress}\r\n\t\t\t\t\\caption{\\label{fig:4f}}\r\n\t\t\t\\end{subfigure}\r\n\t\t\\end{centering}\r\n\t\t\\caption{Depth image observations \\label{fig:Depth-image-observations}. \r\n\t\t\t\\protect\\subref{fig:4a} Intrinsic space. \r\n\t\t\t\\protect\\subref{fig:4b} Embedding using standard Isomap. \r\n\t\t\t\\protect\\subref{fig:4c} Intrinsic Euclidean distance estimation. \r\n\t\t\t\\protect\\subref{fig:4d} Intrinsic Euclidean distance estimation ($k$-NN). \r\n\t\t\t\\protect\\subref{fig:4e} Intrinsic-isometric embedding. \r\n\t\t\t\\protect\\subref{fig:4f} Euclidean distance discrepancy and stress in resulting embedding}\r\n\t\\end{figure}\r\n\r\n\tOur proposed algorithm accurately retrieves the intrinsic structure for all observation modalities. This is evident by fact that the intrinsic-isometric embedding structure is almost identical to the structure of the sampled points in the intrinsic space (can be observed for both modalities by comparing \\cref{fig:3a} to \\cref{fig:3e} and by comparing \\cref{fig:4a} to \\cref{fig:4e}) and from the fact that most inter-point distances in the final embedding closely approximate the true intrinsic Euclidean distance which also leads to a low stress value for the embedding (as can be observed for both modalities in \\cref{fig:3f} and \\cref{fig:4f}). The success of the embedding stems form the fact that the estimated intrinsic metric allows for a good estimation of short-range intrinsic distances (as can be observed for both the modalities in \\cref{fig:3c}, \\cref{fig:3d}, \\cref{fig:3c} and \\cref{fig:3d}). We notice that since the observation functions used are not locally isometric, standard Isomap fails to retrieve the intrinsic structure of the data or to even provide a 2-dimensional parameterization of the intrinsic space (as can be observed for all the modalities in \\cref{fig:3b} \\cref{fig:4c}). Isomap does, for the most part, preserve proximity on a local scale (can be observed by points with similar colors being embedded close to each other) but global structure is not preserved (as can be observed for all the modalities by comparing \\cref{fig:3a} and \\cref{fig:3b} and \\cref{fig:4a} and \\cref{fig:4b}). Since standard Isomap is non-intrinsic, it is effected by the modality of the observation and we receive a different embeddings for different sensor modalities (as can be observed by comparing \\cref{fig:3b} and \\cref{fig:3d}).\r\n\t\r\n\tOne noticeable weak point of our algorithm, which manifests slightly in these examples, occurs around the coordinate $\\left(9,4\\right)$ in the true intrinsic space (\\cref{fig:3a} and \\cref{fig:4a}). This region corresponds to a narrow area in the apartment model in which there are not a lot of sample points. Errors in distance estimations for these points are not ``balanced'' or ``countered'' by distance constrains in other regions of the apartment since no other distance constraints influence this region. This leads to a slight distortion in the embedding of this region which causes a ``bend'' in the global structure of the embedding (as seen in \\cref{fig:bend1} and \\cref{fig:bend2}).\r\n\t\r\n\tThese results show that our proposed intrinsic-isometric dimensionality reduction algorithm could be successfully applied to the problem of localization and mapping. While this application might fall into the much researched subject of indoor mapping and localization, we wish to remark that we make no claim that this algorithm is superior or even comparable to existing algorithms tailored to specific measurement modalities or to machine learning tools trained on labeled data-sets. Our algorithms advantage that it is completely unsupervised and modality invariant which makes it especially suitable for setting where one wants to use an automatic algorithm for localization or/and when the observation model is unknown; which is often the case with indoor localization.\r\n\r\n\t", "meta": {"hexsha": "3e333941610dfe0a79bb54eb5672470a7b5d09f9", "size": 32641, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ExperimentalResults.tex", "max_stars_repo_name": "sariel85/paper-SIIMS", "max_stars_repo_head_hexsha": "6ffdcf9eed2260fb96b4d197239d69ac553e68c5", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ExperimentalResults.tex", "max_issues_repo_name": "sariel85/paper-SIIMS", "max_issues_repo_head_hexsha": "6ffdcf9eed2260fb96b4d197239d69ac553e68c5", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ExperimentalResults.tex", "max_forks_repo_name": "sariel85/paper-SIIMS", "max_forks_repo_head_hexsha": "6ffdcf9eed2260fb96b4d197239d69ac553e68c5", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 83.6948717949, "max_line_length": 1753, "alphanum_fraction": 0.7815324285, "num_tokens": 8797, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.73436438812404}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage[a4paper, total={6.25in, 8in}]{geometry}\n\\usepackage[section]{placeins}\n\\usepackage{float}\n\n\n\\title{CS 660: Programming Assignment 3}\n\\author{Derek Jones}\n\n\n\\begin{document}\n\\maketitle\n\n\t\\section{Part 1}]\nIn Part 1 of the assignment, a set of 3 dimensional world coordinates and 10 sets of camera coordinates were provided. The task was to estimate a camera projection matrix that maps a 3 dimensional world coordinate to a particular coordinate in a camera's image space. The projection matrices $M$ were found by minimizing the following set of equations:\n\\begin{equation}\nx_i = \\frac{p_{00}X_{i} + p_{01}Y_{i} + p_{02}Z_{i} + p_{03}}{p_{20}X_{i} + p_{21}Y_{i} + p_{22}Z_{i} +p_{23}}\n\\end{equation}\n\\begin{equation}\ny_i = \\frac{p_{10}X_{i} + p_{11}Y_{i} + p_{12}Z_{i} + p_{13}}{p_{20}X_{i} + p_{21}Y_{i} + p_{22}Z_{i} +p_{23}}\n\\end{equation}\t\t\n\n\t\\section{Part 2}\nFor Part 2 of the assignment, using the provided set of matches for each image pair, a fundamental matrix was estimated for each image pair that maps each point in a particular image to an epipolar line in the other image. Given sets of match points, $\\mathbf{x}_{0}$ \\& $\\mathbf{x}_{1}$,the fundamental matrix was estimated by solving the following system of equations:\n\t\\begin{equation}\n\t\t\\mathbf{x}_{1}^{T}\\mathbf{F}\\mathbf{x}_{0} = 0\n\t\\end{equation}\nOnce the fundamental matrix $F$ was computed, RANSAC was implemented in order to choose the matrix $F$ that contained the largest number of \\emph{inlier} matches. Once the optimal $F$ was computed, it was recomputed using its inlier matches. The results for each image pair are given in the subsequent sections.\n\n\n\n\n\t\t\\section{Notre Dame Results}\n\n\n\n\t\tThe fundamental matrix $F$ for the Notre Dame image pair was computed using RANSAC with a maximum of 5000 iterations, a minimum of 300 inliers, and a match error tolerance of $\\epsilon = 0.1$. The results for the Notre Dame images capture a large number of match points and seem to be fairly accurate, although they do not exactly replicate the output of the provided ground truth fundamental matrix.\n\nBased upon the epipolar line estimations, the results for matching the inliers generated a fairly accurate result with few spurrious matches present in the final output. It is assumed that with a greater error tolerance and more iterations, a more accurate fundamental matrix could be computed.\n\n\n\n\\begin{center}\n\\begin{figure}[H]\n  \\centering\n  \\begin{minipage}[b]{0.4\\textwidth}\n    \\includegraphics[scale=0.25]{notre_dame_img1_epipolar_lines.jpg}\n    \\caption{Image 1 epipolar lines.}\n  \\end{minipage}\n  \\hfill\n  \\begin{minipage}[b]{0.4\\textwidth}\n    \\includegraphics[scale=0.25]{notre_dame_img2_epipolar_lines.jpg}\n    \\caption{Image 2 epipolar lines.}\n  \\end{minipage}\n\\end{figure}\n\\end{center}\n\n\\begin{center}\n\\begin{figure}[H]\n\t\t\t\\includegraphics[scale = 0.35]{notre_dame_estimated_matches.jpg}\n\\caption{Notre Dame estimated matches.}\n\\end{figure}\n\\end{center}\n\t\n\n\n\t\t\\section{Episcopal Gaudi Results}\n\n\n\n\tThe results for the Episcopal Gaudi epipolar lines were not as accurate, in terms of captured inliers, as compared to the Notre Dame and Mount Rushmore results. The fundamental matrix for the Episcopal Gaudi image pair was computed using a maximum of 5000 iterations, a minimum of 40 inliers, and an error tolerance of $\\epsilon = 1$.\n\nThe results for the Episcopal Gaudi image pair resulted in fairly accurate matches, however a few spurrious matches remain. To counter this, more iterations of RANSAC could be used to try a larger number of possible estimates and the error tolerance could be decreased to attempt to force more accurate matches. Decreasing the error tolerance may also result in fewer inliers, producing fewer matches in the output. \n\n\n\n\\begin{center}\n\\begin{figure}[H]\n  \\centering\n  \\begin{minipage}[b]{0.4\\textwidth}\n    \\includegraphics[scale=0.2]{episcopal_gaudi_img1_epipolar_lines.jpg}\n    \\caption{Image 1 epipolar lines.}\n  \\end{minipage}\n  \\hfill\n  \\begin{minipage}[b]{0.4\\textwidth}\n    \\includegraphics[scale=0.2]{episcopal_gaudi_img2_epipolar_lines.jpg}\n    \\caption{Image 2 epipolar lines.}\n  \\end{minipage}\n\\end{figure}\n\\end{center}\n\n\n\\begin{center}\n\\begin{figure}[H]\n\t\t\t\\includegraphics[scale = 0.2125]{episcopal_gaudi_estimated_matches.jpg}\n\\caption{Episcopal Gaudi estimated matches.}\n\\end{figure}\n\\end{center}\n\n\n\n\n\t\t\\section{Mount Rushmore Results}\n\nThe fundamental matrix for the Mount Rushmore image pair was computed with RANSAC using a maximum of 5000 iterations, a minimum of 300 matches, and an error tolerance of $\\epsilon = 0.1$. An immediate problem is that the provided set of matches only contains 245 match pairs, meaning that the algorithm will always take 5000 iterations before terminating. Nonetheless, the results for the Mount Rushmore image pair appeared to be the most accurate.\n\nIn particular, the matches for the Mount Rushmore image pair contain few spurrious matches. It is believed that since the algorithm completed 5000 iterations with a relatively low error tolerance, a fairly accurate set of inliers were found, resulting a good estimation of the fundamental matrix.\n\n\n\n\\begin{center}\n\\begin{figure}[H]\n  \\centering\n  \\begin{minipage}[b]{0.4\\textwidth}\n    \\includegraphics[scale=0.2]{mount_rushmore_img1_epipolar_lines.jpg}\n    \\caption{Image 1 epipolar lines.}\n  \\end{minipage}\n  \\hfill\n  \\begin{minipage}[b]{0.4\\textwidth}\n    \\includegraphics[scale=0.2]{mount_rushmore_img2_epipolar_lines.jpg}\n    \\caption{Image 2 epipolar lines.}\n  \\end{minipage}\n\\end{figure}\n\\end{center}\n\n\\begin{center}\n\\begin{figure}[H]\n\t\t\t\\includegraphics[scale = 0.25]{mount_rushmore_estimated_matches.jpg}\n\\caption{Mount Rushmore estimated matches.}\n\\end{figure}\n\\end{center}\n\n\t\\section{Remarks}\n\tEach of the requested outputs are contained within the source code directory, estimations of the camera intrinsic matrices are also included. \n\t\tA notable issue that arose during the implementation was the speed of the RANSAC algorithm. Specifically, the problem of speed occurs in the subroutine in which the pairwise distances between each point and epipolar line are computed. This function requires $\\mathcal{O}(n^{2})$ comparisons FOR EACH iteration of the RANSAC algorithm, requiring RANSAC to have a total worst case execution time proportional to $\\mathcal{O}(mn^{2})$ where $n$ is equivalent to the number of matches and $m$ is equivalent to the number of RANSAC iterations. As a consequence, parameter optimization was less than ideal. It was later discovered that the algorithm primarily had difficulties with the Notre Dame matches as there were a rather large number, but performed quite well on the Episcopal Gaudi and Mount Rushmore match sets with fewer total matches.\n\n\t\tAdditionaly, finding the correct RQ decomposition proved to be challengin when attempting to estimate the intrinsic camera matrix (and rotation matrix). I was not able to spend more time understanding how exactly the RQ decomposition algorithm functions, however I included my results for these items in the code.\n\t\tHelper code for drawing the matches, drawing the epipolar lines, and for computing the RQ decomposition were utilized from outside sources with the references included in each function.\n\n\n\\end{document}", "meta": {"hexsha": "072a2342a6201b994a629ec2da7a390dae3a8ccd", "size": 7336, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/derek_jones_cs660_pa3_report.tex", "max_stars_repo_name": "williamdjones/cv_assignment3", "max_stars_repo_head_hexsha": "329483dbdb1635d5ee783b843e00ecc89806cfe0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Report/derek_jones_cs660_pa3_report.tex", "max_issues_repo_name": "williamdjones/cv_assignment3", "max_issues_repo_head_hexsha": "329483dbdb1635d5ee783b843e00ecc89806cfe0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/derek_jones_cs660_pa3_report.tex", "max_forks_repo_name": "williamdjones/cv_assignment3", "max_forks_repo_head_hexsha": "329483dbdb1635d5ee783b843e00ecc89806cfe0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.5931034483, "max_line_length": 841, "alphanum_fraction": 0.7729007634, "num_tokens": 1950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825635346563, "lm_q2_score": 0.8723473730188543, "lm_q1q2_score": 0.7343643815345022}}
{"text": "\\begin{definition}[Labelled Transistion System]\n\tA \\emph{Labelled Transition System (LTS)} is a tuple\n\t\\[\n\t\t\\left(\\proc,\\act,\\left\\lbrace\\xrightarrow{\\alpha} \\middle\\vert \\alpha\\in\\act\\right\\rbrace\\right)\n\t\\]\n\twhere $ \\proc $ is a set of states, $ \\act $ is a set of actions, for each $ \\alpha\\in\\act $, $ \\xrightarrow{\\alpha} \\subseteq \\proc\\times\\proc $ is a binary relation called \\emph{transition relation}.\n\\end{definition}\n\\subsection*{Notation}\nWe can extend $ \\xrightarrow{\\alpha} $ from labels $ \\alpha\\in\\act $ to words $ w\\in\\act^* $\n\\begin{itemize}\n\t\\item $ p\\xrightarrow{\\varepsilon}p $, for every $ p\\in\\proc $\n\t\\item $ p\\xrightarrow{\\alpha w}p' $, if there is $ p''\\in\\proc $, such that $ p\\xrightarrow{\\alpha}p'' $ and $ p''\\xrightarrow{w}p' $ for every $ p,p'\\in\\proc $, $ \\alpha\\in\\act $, and $ w\\in\\act^* $.\n\\end{itemize}\nOther notation\n\\begin{itemize}\n\t\\item $ \\rightarrow = \\left\\lbrace(p,p')\\middle\\vert \\text{ if } p\\xrightarrow{\\alpha}p'\\text{, for some } \\alpha\\in\\act\\right\\rbrace$\n\t\\item $ \\rightarrow^* $ is the \\emph{reflexive} and \\emph{transitive} closure of $ \\rightarrow $\n\t\\item $ p\\xrightarrow{\\alpha} $~~ if there exist $ p'\\in\\proc $ such that $ p\\xrightarrow{\\alpha}p' $\n\t\\item $ p\\cancel{\\xrightarrow{\\alpha}} $~~ if there is no $ p'\\in\\proc $ such that $ p\\xrightarrow{\\alpha}p' $\n\\end{itemize}", "meta": {"hexsha": "d42fb77cde210c47c088764ec8b476dc66c56287", "size": 1334, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modeling and Verification - Reference/LTS.tex", "max_stars_repo_name": "simwir/notes", "max_stars_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-02-12T22:22:23.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-12T22:22:23.000Z", "max_issues_repo_path": "Modeling and Verification - Reference/LTS.tex", "max_issues_repo_name": "simwir/notes", "max_issues_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modeling and Verification - Reference/LTS.tex", "max_forks_repo_name": "simwir/notes", "max_forks_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-01-17T10:57:21.000Z", "max_forks_repo_forks_event_max_datetime": "2018-01-17T10:57:21.000Z", "avg_line_length": 66.7, "max_line_length": 202, "alphanum_fraction": 0.6724137931, "num_tokens": 460, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7342856512099429}}
{"text": "\n\\subsection{Unconstrained envelope theorem}\n\nConsider a function which takes two parameters:\n\n\\(f(x,\\alpha \\)\n\nWe want to choose \\(x\\) to maximise \\(f\\), given \\(\\alpha \\).\n\n\\(V(\\alpha )=\\sup_{x\\in X}f(x,\\alpha )\\)\n\nThere is a subset of \\(X\\) where \\(f(x,\\alpha )=V(\\alpha )\\).\n\n\\(X^*(\\alpha )=\\{x\\in X|f(x, \\alpha )=V(\\alpha )\\}\\)\n\nThis means that \\(V(\\alpha )=f(x^*,\\alpha )\\) for \\(x^*\\in X^*\\).\n\nLet’s assume that there is only one \\(x^*\\).\n\n\\(V(\\alpha )=f(x^*,\\alpha )\\)\n\nWhat happens to the value function as we relax \\(\\alpha\\)?\n\n\\(V_{\\alpha_i}(\\alpha )=f_{\\alpha_i}(x^*(\\alpha ),\\alpha )\\).\n\n\\(V_{\\alpha_i}(\\alpha )=f_x\\dfrac{\\delta x^*}{\\delta \\alpha }+f_{\\alpha_i}\\).\n\nWe know that \\(f_x=0\\) from first order conditions. So:\n\n\\(V_{\\alpha_i}(\\alpha )= f_{\\alpha_i}\\).\n\nThat is, at the optimum, as the constant is relaxed, we can treat the \\(x^*\\) as fixed, as the first-order movement is \\(0\\).\n\n", "meta": {"hexsha": "ac3053dcf2060fd03750581adef2ef30b57b1363", "size": 906, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/optimisationMulti/07-01-unenvelope.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/optimisationMulti/07-01-unenvelope.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/optimisationMulti/07-01-unenvelope.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6470588235, "max_line_length": 125, "alphanum_fraction": 0.6059602649, "num_tokens": 315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942171172603, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7342583433913477}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc,hyperref}\n\\usepackage{amsmath,amsfonts,amssymb,amsthm,verbatim}\n\\newcommand{\\R}{\\mathbb{R}}\n\n\\title{MM Tensor Decomp progress}\n\\author{Jason Yang}\n\\date{Oct 2021 -}\n\n\\begin{document}\n\n\\maketitle\n\n\\subsection*{Notation}\n\\begin{itemize}\n    \\item $A\\times B$: The outer product of two multidimensional arrays $A,B$, defined as $(A\\times B)_{a_0,\\dots,a_{p-1},b_0,\\dots,b_{q-1}}=A_{a_0,\\dots,a_{p-1}}B_{b_0,\\dots,b_{q-1}}$ for all indices $a_0,\\dots,a_{p-1}$ and $b_0,\\dots,b_{q-1}$;\n    \\item $E(n)_{i,j}$: The $n\\times n$ matrix with a 1 at cell $(i,j)$ and 0s everywhere else; if it is clear from context what $n$ is, the abbreviation $E_{i,j}$ may be used;\n    \\item $\\delta_{i,j}=1$ if $i=j$, 0 otherwise (the Kronecker delta);\n    \\item Commas between indices may be omitted for brevity;\n    \\item $[N]$ denotes the set $\\{0,1,\\dots,N-1\\}$;\n    \\item $S_n$ denotes the set of all permutations over $n$ objects;\n\\end{itemize}\n\n\\section{Goal}\n\nFor a natural number $n$, the \\textit{$<n,n,n>$ matrix multiplication tensor} is defined as\n\\[\\mathcal{M}(n)=\\sum_{0\\le i,j,k<n} E_{ij}\\times E_{jk}\\times E_{ki};\\]\n\nThus, $\\mathcal{M}(n)_{abcdef}=\\delta_{fa}\\delta_{bc}\\delta_{de}$.\n\nWe want to find the minimum $R$ and three lists of matrices $A,B,C$ such that\n\\[\\mathcal{M}(n)=\\sum_{r=0}^{R-1}A_r\\times B_r\\times C_r.\\]\n\n$R$ is known as the rank of $\\mathcal{M}(n)$, and the list $[(A_r,B_r,C_r)]_{r=0\\dots R-1}$ of triplets of matrices satisfying the equation is known as an \\textit{$R$-rank decomposition} of $\\mathcal{M}(n)$. Note that this equation is equivalent to\n\n\\[\\forall abcdef,\\ \\mathcal{M}(n)_{abcdef}=\\sum_{r=0}^{R-1}A_{rab}B_{rcd}C_{ref}.\\]\n\nThe motivation for this problem is that an $R$-rank decomposition of $\\mathcal{M}(n)$ can be directly translated into an algorithm for multiplying two $n\\times n$ matrices while using only $R$ multiplications between elements of the matrices; we exclude multiplications of elements with fixed scalars. Such an algorithm can then be translated into a $O(N^{\\log_n R})$ divide-and-conquer algorithm for multiplying two $N\\times N$ matrices for arbitrarily large $N$, which for $R<n^3$ is asymptotically faster than naive matrix multiplication, which has many applications across numerous fields, such as graph algorithms and machine learning.\n\n\\section{Transformations of Decompositions}\nGiven an $R$-rank decomposition $[(A_r,B_r,C_r)]_{r=0\\dots R-1}$ of $\\mathcal{M}(n)$, we wish to analyze how we can transform it into other valid $R$-rank decompositions.\n\nThere are two trivial transformations we can do: one is to permute the triples of the decomposition: $[(A_{\\sigma(r)},B_{\\sigma(r)},C_{\\sigma(r)})]_{r=0\\dots R-1}$ for any permutation $\\sigma$; the other is to scale elements of each triple with scalars whose product is 1: $[(a_rA_r,b_rB_r,c_rC_r)]_{r=0\\dots R-1}$ for any $a_r,b_r,c_r$ such that $a_r b_r c_r=1$ for all $r$.\n\nThere is another transformation, called the \\textit{trace transformation}, which relies on special properties of $\\mathcal{M}(n)$: \\[[(\\alpha A_r\\beta^{-1},\\beta B_r\\gamma^{-1},\\gamma C_r\\alpha^{-1})]_{r=0\\dots R-1},\\] for invertible $n\\times n$ matrices $\\alpha,\\beta,\\gamma$. The validity of this transformation can be checked with some algebra.\n\n\\subsection{Families of Decompositions}\nTo find nontrivial decomposition transformations, we can first consider the family of all transformations of the form $[(f_A(A_r),f_B(B_r),f_C(C_r))]_{r=0\\dots R-1}$, where $f_A,f_B,f_C:\\R^{n\\times n}\\rightarrow \\R^{n\\times n}$ are linear transformations over matrices, i.e. each element of the output matrix is a linear combination of all the elements of the input matrix. Thus, we can represent $f_A,f_B,f_C$ with tensors $\\alpha,\\beta,\\gamma$ such that $f_A(A)=\\sum_{uv}\\alpha_{abuv}A_{uv}$ and likewise for $f_B,\\beta$ and $f_C,\\gamma$.\n\nPlugging our transformed decomposition into the equation for decompositions of $\\mathcal{M}(n)$ and applying some algebraic manipulation gives\n\n\\[\\forall abcdef,\\ \\mathcal{M}(n)_{abcdef}=\\sum_{r=0}^{R-1}(\\sum_{uv}\\alpha_{abuv}A_{uv})(\\sum_{wx}\\beta_{cdwx}B_{rwx})(\\sum_{yz}\\gamma_{efyz}C_{ryz})\\]\n\\[=\\sum_{r=0}^{R-1}\\sum_{uvwxyz}\\alpha_{abuv}A_{uv}\\beta_{cdwx}B_{rwx}\\gamma_{efyz}C_{ryz}\\]\n\\[=\\sum_{r=0}^{R-1}\\sum_{uvwxyz}A_{uv}B_{rwx}C_{ryz}\\alpha_{abuv}\\beta_{cdwx}\\gamma_{efyz}\\]\n\\[=\\sum_{uvwxyz}(\\sum_{r=0}^{R-1}A_{uv}B_{rwx}C_{ryz})\\alpha_{abuv}\\beta_{cdwx}\\gamma_{efyz}\\]\n\\[=\\sum_{uvwxyz}\\mathcal{M}(n)_{uvwxyz}\\alpha_{abuv}\\beta_{cdwx}\\gamma_{efyz}\\]\n\\[=\\sum_{ijk}\\alpha_{abij}\\beta_{cdjk}\\gamma_{efki}.\\]\n\nThus, any triplet of tensors $\\alpha,\\beta,\\gamma$ satisfying $\\mathcal{M}(n)_{abcdef}=\\sum_{ijk}\\alpha_{abij}\\beta_{cdjk}\\gamma_{efki}\\ \\forall abcdef$ is a valid transformation over $R$-rank decompositions.\n\n\\subsubsection{Rank 1 (incomplete)}\nSuppose we restrict each matrix $\\alpha_{ab},\\beta_{cd},\\gamma_{ef}$ to be rank-1 matrices, i.e. there are tensors $\\alpha^0,\\alpha^1,\\beta^0,\\beta^1,\\gamma^0,\\gamma^1$ such that $\\alpha_{abij}=\\alpha^0_{abi}\\alpha^1_{abj},\\beta_{cdjk}=\\beta^0_{cdj}\\beta^1_{cdk},\\gamma_{efki}=\\gamma^0_{efk}\\gamma^1_{efi}$. Plugging this into the previous equation gives\n\\[\\forall abcdef,\\ \\mathcal{M}(n)_{abcdef}=\\sum_{ijk}\\alpha^0_{abi}\\alpha^1_{abj}\\beta^0_{cdj}\\beta^1_{cdk}\\gamma^0_{efk}\\gamma^1_{efi}\\]\n\\[=\\sum_{ijk}\\gamma^1_{efi}\\alpha^0_{abi}\\alpha^1_{abj}\\beta^0_{cdj}\\beta^1_{cdk}\\gamma^0_{efk}\\]\n\\[=(\\sum_i\\gamma^1_{efi}\\alpha^0_{abi})(\\sum_j\\alpha^1_{abj}\\beta^0_{cdj})(\\sum_k\\beta^1_{cdk}\\gamma^0_{efk})\\]\n\\[=(\\gamma^1_{ef}\\cdot\\alpha^0_{ab})(\\alpha^1_{ab}\\cdot\\beta^0_{cd})(\\beta^1_{cd}\\cdot\\gamma^0_{ef})\\]\n\\[=\\delta_{fa}\\delta_{bc}\\delta_{de}.\\]\n\nSince this equation must be true for all $abcdef$, we can immediately deduce that $\\gamma^1_{ei}\\cdot\\alpha^0_{ib}\\ne 0,\\alpha^1_{aj}\\cdot\\beta^0_{jd}\\ne 0$, and $\\beta^1_{ck}\\cdot\\gamma^0_{kf}\\ne 0$; otherwise if $\\gamma^1_{ei}\\cdot\\alpha^0_{ib}=0$ for some $i$, then when setting $(abcdef)$ to some $(ijjkki)$ will lead to $(\\gamma^1_{ef}\\cdot\\alpha^0_{ab})(\\alpha^1_{ab}\\cdot\\beta^0_{cd})(\\beta^1_{cd}\\cdot\\gamma^0_{ef})=0\\ne \\delta_{fa}\\delta_{bc}\\delta_{de}=1$, and a similar argument applies to the other two inequalities.\n\nWe can then further determine that $\\gamma^1_{ef}\\cdot\\alpha^0_{ab}=0$ for all $a\\ne b$, since $(\\gamma^1_{ef}\\cdot\\alpha^0_{ab})(\\alpha^1_{ab}\\cdot\\beta^0_{cd})(\\beta^1_{cd}\\cdot\\gamma^0_{ef})=0$ when $(abcdef)$ is set to some $(ajjkkf)$, since then $\\alpha^1_{ab}\\cdot\\beta^0_{cd}$ and $\\beta^1_{cd}\\cdot\\gamma^0_{ef}$ would both be equal to 1. Using similar arguments, $\\alpha^1_{ab}\\cdot\\beta^0_{cd}=0$ for all $c\\ne d$ and $\\beta^1_{cd}\\cdot\\gamma^0_{ef}=0$ for all $d\\ne e$.\n\nThus, $[\\gamma^1_{ef}\\cdot\\alpha^0_{ab}]_{f,a}$, $[\\alpha^1_{ab}\\cdot\\beta^0_{cd}]_{b,c}$, and $[\\beta^1_{cd}\\cdot\\gamma^0_{ef}]_{d,e}$ are all diagonal matrices.\n\n\\section{Searching for Symmetric Decompositions}\nFrom this point onward we will focus on the case $n=3$. We will use two symmetries of $\\mathcal{M}(n)$ and force all the decompositions we search for to have these same symmetries:\n\n\\[\\mathcal{M}(n)_{a,b,c,d,e,f}=\\mathcal{M}(n)_{c,d,e,f,a,b}=\\mathcal{M}(n)_{e,f,a,b,c,d}\\ \\forall a,b,c,d,e,f;\\]\n\n\\[\\mathcal{M}(n)_{a,b,c,d,e,f}=\\mathcal{M}(n)_{\\sigma(a),\\sigma(b),\\sigma(c),\\sigma(d),\\sigma(e),\\sigma(f)} \\forall \\sigma\\in S_n.\\]\n\nWe say two decompositions $[[A_{r,t}]_{t\\in[3]}]_{r\\in[R]}$ and $[[B_{r,t}]_{t\\in[3]}]_{r\\in[R]}$ are \\textit{equal} if there exists a permutation $\\sigma\\in S_R$ s.t. $\\forall r, [A_{\\sigma(r),t}]_{t\\in[3]}=[B_{r,t}]_{t\\in[3]}$.\n\nWe want all decompositions we search for to be equal under all the symmetries described above. Formally, for functions\n$h_{\\sigma}(A):=[A_{\\sigma(r),\\sigma(c)}]_{r,c\\in[n]}$ and $T_{s,\\sigma}([A_t]_{t\\in[3]}):=[h_{\\sigma}(A_{(t+s)\\mod 3})]_{t\\in[3]}$, we want decomposition $[[A_{r,t}]_{t\\in[3]}]_{r\\in[R]}$ to be equal to decomposition $[T_{s,\\sigma}([A_{r,t}]_{t\\in[3]})]_{r\\in[R]}$ for all $s,\\sigma$.\n\n\\subsection{First attempt}\nConsider decompositions of the form $\\mathcal{D}=[[P_r]_{t\\in[3]}]_{r\\in[R_p]}\\ ||\\ [T_{s,\\sigma}([A,B,C])]_{\\forall s,\\sigma}$ for $P,A,B,C\\in\\{-1,0,1\\}^{3\\times 3}$, $P$ satisfying $P=h_\\sigma(P)\\ \\forall\\sigma$, and $R_p\\le 5$. Note that the second part of the decomposition consists of 18 matrix triples.\n\nWe will also define the \\textit{error} $e(A,B)$ between two tensors $A,B$ of equal shape to be the number of coordinates $c$ s.t. $A_c\\ne B_c$.\n\nBy brute force search, the minimum possible $e(\\mathcal{M}(3),\\mathcal{D})$ is 9. One possible solution is $R_p=0,\nA=\\begin{bmatrix}\n-1 & 0 & 1\\\\\n0 & 0 & 0\\\\\n-1 & 0 & 0\\\\\n\\end{bmatrix},\nB=\\begin{bmatrix}\n0 & 0 & 1\\\\\n0 & 0 & 0\\\\\n0 & 0 & 0\\\\\n\\end{bmatrix},\nC=\\begin{bmatrix}\n0 & 0 & 0\\\\\n0 & 0 & 0\\\\\n-1 & 0 & 0\\\\\n\\end{bmatrix}$.\n\n\\section{Symmetry Reduction (old)}\nWe will use two symmetries of $\\mathcal{M}(n)$ to force $A,B,C$ to have these same symmetries, in order to reduce the search space. The first is \\textit{cyclic symmetry}, which can be easily verified:\n\n\\[\\mathcal{M}(n)_{a,b,c,d,e,f}=\\mathcal{M}(n)_{c,d,e,f,a,b}=\\mathcal{M}(n)_{e,f,a,b,c,d}\\ \\forall a,b,c,d,e,f.\\]\n\nWe can force our decomposition of $\\mathcal{M}(n)$ to be cyclically symmetric by requiring that for all triplets $(A_r,B_r,C_r)$ in our decomposition, the triplets $(B_r,C_r,A_r)$ and $(C_r,A_r,B_r)$ also appear in the decomposition.\n\nA special case occurs if $(A_r,B_r,C_r)=(\\alpha W,\\beta W,\\gamma W)$ for some matrix $W$ and scalars $\\alpha,\\beta,\\gamma$; in this case $(B_r,C_r,A_r)$ and $(C_r,A_r,B_r)$ do not need to appear as they can be merged with $(A_r,B_r,C_r)$ to yield a single triplet $(3\\alpha\\beta\\gamma W,W,W)$ (note that $(\\alpha W,\\beta W,\\gamma W)$ is equivalent to $(\\alpha\\beta\\gamma W,W,W)$ since the outer product of the matrices in each of the triplets yields the same tensor). We can then adjust the triplet $(3\\alpha\\beta\\gamma W,W,W)$ to $(W',W',W')$ where \n$W'=(3\\alpha\\beta\\gamma)^{\\frac{1}{3}}W$, so that the new triplet's matrices are all the same. Thus, every cyclically symmetric decomposition can be written as the form\n\\[A=W||X||Y||Z,B=W||Y||Z||X,C=W||Z||X||Y\\]\nwhere $W,X,Y,Z$ are lists of matrices and $||$ is list concatenation.\n\nNote that Strassen's 7-rank decomposition of $\\mathcal{M}(2)$ is cyclically symmetric. Also, Grey Ballard found a cyclically symmetric 23-rank decomposition of $\\mathcal{M}(3)$ (\\url{http://perso.ens-lyon.fr/bora.ucar/tensors-cse17/ballard-talk.pdf}). Although the rank is the same as the current record, none of the previously discovered 23-rank decompositions were cyclically symmetric.\n\nThe second symmetry we will use is \\textit{reversal symmetry}:\n\\[\\mathcal{M}(n)_{a,b,c,d,e,f}=\\mathcal{M}(n)_{n-1-a,n-1-b,n-1-c,n-1-d,n-1-e,n-1-f}\\ \\forall a,b,c,d,e,f.\\]\n\nWe will in fact use an extra-restrictive decomposition of $\\mathcal{M}(n)$ when combining both symmetries, namely we will only consider decompositions of the form\n\\[A=W||X||Y||Z||\\overline{X}||\\overline{Y}||\\overline{Z},B=W||Y||Z||X||\\overline{Y}||\\overline{Z}||\\overline{X},C=W||Z||X||Y||\\overline{Z}||\\overline{X}||\\overline{Y},\\]\n\nwhere $\\overline{X}$ denotes the list of matrices $X$ but with each matrix $A$ altered to the matrix $A'=[A_{n-1-i,n-1-j}]_{i,j}$ (i.e. $A$ flipped both horizontally and vertically), and where $W$ satisfies the property $W=\\overline{W}$. Strassen's decomposition also satisfies this restrictive form.\n\n\\subsection{Progress}\nLet $R=|W|$ and $S=|X|=|Y|=|Z|$ represent the length of $W$ and the length of each of $X,Y,Z$ respectively. Our tensor that we want to decompose is $\\mathcal{M}(3)$, and our decomposition of interest is\n\\[A=W||X||Y||Z||\\overline{X}||\\overline{Y}||\\overline{Z},B=W||Y||Z||X||\\overline{Y}||\\overline{Z}||\\overline{X},C=W||Z||X||Y||\\overline{Z}||\\overline{X}||\\overline{Y}.\\]\nThe rank of this decomposition is $R+3S$.\n\nBelow is our search progress:\n\\begin{itemize}\n    \\item $R\\le 5,S\\le 2$, each matrix in $A,B,C$ has at most 2 nonzero elements: no decompositions found\n\\end{itemize}\n\n\\end{document}\n", "meta": {"hexsha": "0a0a83fd78597c4d36c8816ba14631442aaece40", "size": 12016, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MM Tensor Decomp progress.tex", "max_stars_repo_name": "jasonLLyang/Matrix-Multiplication-Tensor-Decomposition", "max_stars_repo_head_hexsha": "b252a1cf39b691cd4b2a87ec07eb36ea7920594b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MM Tensor Decomp progress.tex", "max_issues_repo_name": "jasonLLyang/Matrix-Multiplication-Tensor-Decomposition", "max_issues_repo_head_hexsha": "b252a1cf39b691cd4b2a87ec07eb36ea7920594b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MM Tensor Decomp progress.tex", "max_forks_repo_name": "jasonLLyang/Matrix-Multiplication-Tensor-Decomposition", "max_forks_repo_head_hexsha": "b252a1cf39b691cd4b2a87ec07eb36ea7920594b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.6197183099, "max_line_length": 640, "alphanum_fraction": 0.6891644474, "num_tokens": 4292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7342583347892511}}
{"text": "\n\\subsection{Differentiable functions}\n\n\\subsubsection{Introduction}\n\nA differentiable function is one where the differential is defined at all points on the real line.\n\nAll differentiable functions are continuous. Not all continuous functions are differentiable.\n\n\\subsubsection{Differentiability class}\n\nWe can describe a function with its differentiability class. If a function can be differentiated \\(n\\) times and these differentials are all continous, then the function is class \\(C^n\\).\n\n\\subsubsection{Smooth functions}\n\nIf a function can be differentiated infinitely many times to produce continous functions, it is \\(C^{\\infty }\\), or smooth.\n\n", "meta": {"hexsha": "2915a68eabdfeff9607cf0c70176623b4ebb6ca2", "size": 654, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/calculus/02-01-functions.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/calculus/02-01-functions.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/calculus/02-01-functions.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.3333333333, "max_line_length": 187, "alphanum_fraction": 0.8012232416, "num_tokens": 131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7341411433150629}}
{"text": "\\chapter{Vector Space}\r\n\r\n\\section{Matrix}\r\n\\begin{remind}\r\nA \\textbf{field} is a \\textit{good} algebraic structure, which has the addition and the multiplication. Formally, a field $(F,~+,~\\cdot)$, or simply $F$, is a pair of a set and two operations which is from $F\\times F$ to $F$ satisfying the following:\r\n\\begin{itemize}\r\n\\item $(F,~ +)$ is an \\textbf{abelian group}, that is, $+$ is commutative, associative, and there is an additional identity 0 and the inverse element $-a$ of $a$ for all $a \\in F.$\r\n\\item $(F^{\\times },~\\cdot)$ is also an abelian group, that is, $\\cdot$ is commutative, associative, and there is an multiplicational identity 1 and the inverse element $a^{-1}$ of $a$ for all $a \\in F^{\\times},$ where $F^{\\times} = F - \\{0\\}.$\r\n\\item + and $\\cdot$ are \\textit{compatible}, which means $\\cdot$ is distributing over $+.$\r\n\\end{itemize}\r\nWe simply write $a-b := a+(-b)$ and $a/b=ab^{-1}.$\r\n\r\nA \\textbf{matrix} over a field $F$ is a rectangular arrangement of \\textit{scalars}, elements of the field $F$. The space of $m$ by $n$ matrices is denoted as $\\mathfrak M_{m,n}(F).$\r\n\\end{remind}\r\n\\begin{ex}\\leavevmode\r\n\\begin{itemize}\r\n\\item $\\mathbb Q$, $\\mathbb R$, $\\mathbb C$ are well-known(?) fields.\r\n\\item $\\mathfrak M_{m,n}(F) \\approx F^{mn},$ without the product.\r\n\\item Matrices do not form a field.\r\n\\end{itemize}\r\n\\end{ex}\r\n\r\n\\subsection{Transpose and Trace}\r\n\\begin{defn}\r\nFor every $m$ by $n$ matrix $A \\in \\mathfrak M _{m,n}(F),$ the \\textbf{transpose} of $A$ is defined as follows: $$ A^{\\mathsf T} = (a_{ji})_{n,m}.$$ For every $n$ by $n$ \\textit{square} matrix $A \\in \\mathfrak M_{n,n}(F),$ the \\textbf{trace} of $A$ is defined as follows: $$\\operatorname{tr}A = \\sum_{i=1}^n a_{ii}.$$\r\n\\end{defn}\r\n\r\n\\begin{prop}[Linearity of transpose and trace]\r\nFor every pair of $m$ by $n$ matrices $A$ and $B \\in \\mathfrak M_{m,n}(F)$ and every pair of scalars $a,~b \\in F$, $$(aA + bB)^{\\mathsf T} = a A^{\\mathsf T} + bB^{\\mathsf T}.$$ For every pair of $n$ by $n$ square matrices $A$ and $B \\in \\mathfrak M_{n,n}(F)$ and every pair of scalars $a,~b \\in F$, $$\\operatorname{tr}(aA + bB) = a \\operatorname{tr}A + b \\operatorname{tr}B.$$\r\n\\end{prop}\r\n\\begin{proof}\r\nㅎㅎ.\r\n\\end{proof}\r\n\r\n\\begin{prop}[Behaviour of transpose and trace]\r\n$$(AB)^\\mathsf T = B^\\mathsf T A^\\mathsf T, \\qquad \\operatorname{tr}A = \\operatorname{tr} A^\\mathsf T, \\qquad \\operatorname{tr}(AB) = \\operatorname{tr}(BA).$$\r\n\\end{prop}\r\n\\begin{proof}\r\nTry it!\r\n\\end{proof}\r\n\r\n\r\n\\subsection{Inverse Matrix}\r\n\\begin{defn}\r\nFor a \\textit{square} matrix $A\\in\\mathfrak M_{n,n}(F),$ if there is another square matrix $B\\in\\mathfrak M_{n,n}(F)$ such that $$AB = I = BA,$$ then we call $B=A^{-1}$ the(?) \\textbf{inverse matrix} of $A$.\r\n\\end{defn}\r\n\r\n\\begin{prop}[Uniqueness of inverse matrix] The inverse matrix of a matrix $A$ is unique (if exists). This justifies the occurrence of \\textbf{`the'} above.\r\n\\end{prop}\r\n\\begin{proof}\r\nLet those be $A^{-1}$ and ${\\tilde A }^{-1},$ then $${\\tilde A }^{-1} = (A^{-1}A) {\\tilde A }^{-1} = A^{-1}(A {\\tilde A }^{-1}) = A^{-1}.$$\r\n\\end{proof}\r\n\r\n\\begin{quest} If $AB = I$ for two square matrices $A$ and $B$, what can we say about the invertibility of them? We will solve this problem using a `function,' which is from and to some vector spaces, defined below.\r\n\\end{quest}\r\n\r\n\\newpage\r\n\r\n\\section{Vector Space}\r\n\\begin{defn}\r\nA \\textbf{vector space} $V$ over $F$, or simply an \\textbf{\\textit{F}-vector space} $V$, is a \\textit{good} algebraic structure, which has the addition $+:~V\\times V \\to V$ and the $F$-scalar multiplication $\\mathrm{SM}_F:~F\\times V \\to V$. Formally, a field $(V,~F,~+,~\\mathrm{SM}_F)$, or simply $V$, is a pair of a set, a field and two operations satisfying the following:\r\n\\begin{itemize}\r\n\\item $(V,~ +)$ is an abelian group.\r\n\\item $\\mathrm{SM}_F$ and $\\cdot_F$ are compatible: $(ab)v = a(bv)$ for every $a, ~b \\in F$ and $v\\in V,$ and $1v = v$ for all $v\\in V.$\r\n\\item $+$s and $\\mathrm{SM}_F$ are compatible: $(a+b)v = av + bv,$ $a(v+w) = av + aw$ for every $a,~b\\in F$ and $v,~w \\in V.$\r\n\\end{itemize}\r\nWe simply write $v-w := v+(-w).$\r\n\\end{defn}\r\n\\begin{ex} The following structures are examples of vector space.\r\n\\begin{itemize}\r\n\\item \\textbf{\\{0\\}} is a vector space over \\textit{arbitrary field}, and is called the \\textbf{trivial space.}\r\n\\item $\\mathbb R^n$ and $\\mathbb C^n$ are vector spaces. In fact, for any field $F$, $F^n$ is an $F$-vector space, trivially.\r\n\\item Hence, a matrix space $\\mathfrak M_{m,n}$ of $m$ by $n$ matrices over $F$ is a vector space since is \\textit{the same with} $F^{mn}$, and the polynomial space of $n$-th degree $\\mathbf{P}_n [t] = \\{\\sum_{i=0}^n a_i t^i: ~ a_i \\in F\\}$ is also a vector space, \\textit{the same with} $F^{n+1}.$\r\n\\item (Field extension) If there are two fields which one is a subfield of another, namely $E \\ge F$, then $E$ is a $F$-vector space, with its addition and multiplication (as a scalar multiplication.)\r\n\\item (\\textbf{dual space!}) A \\textbf{linear functional} $f$ on $V$ is a \\textit{linear} map from $V$ to $F$, that is, $$f(av+b) = af(v)+b$$ for every $a,~b\\in F$ and $v\\in V.$ The \\textbf{dual space} of $V$ is the space of linear functionals on $V$, and it forms a $F$-vector space, with the following operations: $$(f+g)(v) = f(v) + g(v),\\qquad (af)(v) = af(v).$$ The dual space is one of the most interesting things not only in linear algebra, but in abstract algebra, or even in \\textit{any} branches which use the term \\textit{dual} (e.g., in projective geometry).\r\n\\end{itemize}\r\n\\end{ex}\r\n\r\n\r\n\\begin{prop}\r\n\\leavevmode\r\n\r\n\\begin{itemize}\r\n\r\n\\item $0v = 0$ and $(-1)v = -v$.\r\n\\begin{proof} $0v=(0+0)v=0v+0v$ implies $0v=0$ and $v+(-v)=0=0v=(1+(-1))v=1v+(-1)v=v+(-1)v$ implies $-v=(-1)v.$\r\n\\end{proof}\r\n\\item Every \\textbf{linear combination} $\\sum_i a_i v_i$ of vectors $v_i \\in V$ is in $V.$\r\n\\begin{proof} Easy induction on the number of summands(terms).\r\n\\end{proof}\r\n\\end{itemize}\r\n\\end{prop}\r\n\r\n\\begin{defn}\r\nA subset $W\\subseteq V$ is called a \\textbf{subspace} of $V$ if it forms a vector space itself with the \\textit{inherited} operations from $V$. We denote it $W\\le V.$\r\n\\end{defn}\r\n\\begin{prop}\\label[prop]{p:subspace}\r\n$$W\\le V~~~\\Longleftrightarrow~~~ \\forall c\\in F,~ \\forall v,~w\\in W,~~~ cv+w \\in W.$$\r\n\\end{prop}\r\n\\begin{proof}\r\n($\\Leftarrow$) The other axioms of vector space is satisfied by the fact that the operations are inherited by $V$, and hence it suffices to show that the operations are closed. First, let $c=-1$ and $v=w.$ Then we have $(-1)w + w = 0 \\in W$ by the proposition above. Then, the addition is closed if we let $c=1$; and so is the scalar multiplication if we let $w=0$, which is in $W$, as we proved. Hence $W$ forms a vector space.\r\n\r\n($\\Rightarrow$) $cv+w$ is a linear combination. ㅋㅋ.\r\n\\end{proof}\r\n\\begin{ex}\r\n\\leavevmode\r\n\\begin{itemize}\r\n\\item Removing a coordinate(\\textbf{projection}): $$F^2 = \\left\\{(a,b):~a,b\\in F\\right\\} \\le \\left\\{(a,b,c):~a,b,c\\in F\\right\\} = F^3.$$\r\n\\item \\textbf{Symmetric}, \\textbf{alternating} matrices over $F$: $$\\mathrm{Sym}_n(F) = \\{A \\in \\mathfrak M_{n,n}(F):~A=A^{\\mathsf T}\\} \\le M_{n,n}(F),$$\r\n$$\\mathrm{Alt}_n(F) = \\{A \\in \\mathfrak M_{n,n}(F):~A=-A^{\\mathsf T}\\} \\le M_{n,n}(F).$$\r\n\\item \\textbf{Hermitian} matrices: $$\\mathrm{Her}_n = \\{A \\in \\mathfrak M_{n,n}(\\mathbb C):~A=\\overline{A^{\\mathsf T}}\\} \\le M_{n,n}(\\mathbb C).$$\r\n\\item The solution space of a system of homogeneous linear (differential) equations.\r\n\\end{itemize}\r\n\\end{ex}\r\n\r\n\r\n\\subsection{Spanned subspace}\r\n\r\n\\begin{defn} For a subset $S$ of a vector space $V$, the \\textbf{subspace spanned by \\textit{S}} is the following set: $$\\left< S \\right> = \\left\\{ \\sum_{\\textrm{finite}} a_i v_i: ~~ a_i\\in F,~v_i \\in S \\right\\},$$ where $\\sum_{\\textrm{finite}} a_i v_i$ means $a_i \\ne 0$ for \\textit{only} some finitely many indices $i$, and $a_i = 0$ for others; i.e., we only add finitely many vectors.\\footnote[2]{We take finitely many vectors since it is not sufficient to define `convergence' of an infinite series with just axioms of vector space.}\r\n\r\nAnd we call a element of $\\left< S \\right>$ a \\textbf{linear combination} of $S$.\r\n\\end{defn}\r\n\r\n\\begin{ex}\r\nLet $\\mathbb R^{\\infty}$ be the space of all sequences which are \\textbf{eventually zero}, that is, there are only \\textit{finitely many} nonzero terms. Then,$$ \\mathcal E^{\\infty} = \\left\\{\\mathbf{e}_i =\\left(0,~\\cdots,~0,~\\underset {i-\\textrm{th}} 1,~0,~\\cdots\\right): ~~~ i\\in \\mathbb {N} \\right\\}$$ spans $\\mathbb R^\\infty.$ Hence, for example, a sequence $$\\left(1,~1,~1,~\\cdots\\right)$$is not a linear combination of $\\mathcal E^{\\infty}.$\r\n\\end{ex}\r\n\\begin{prop}\r\nFor every subset $S \\in V,$ $\\left <S\\right>$ is a subspace of $V$.\r\n\\end{prop}\r\n\\begin{proof}\r\nUse \\cref{p:subspace}.\r\n\\end{proof}\r\n\r\n\\begin{prop}\r\nFor every subset $S \\in V,$ $\\left <S\\right>$ is \\textit{the smallest} subspace of $V$ which contains $S$, namely, $$\\left<S\\right> = \\bigcap_{\\substack{S \\subseteq W \\\\ W:~\\text{vector space}}} W.$$\r\n\\end{prop}\r\n\\begin{proof}\r\n($\\subseteq$) Since $W$ is a vector space containing $S$, it must contain other linear combinations of $S$ also. Therefore $\\left< S \\right> \\subseteq W$ for every $W$ satisfying the condition whence$$\\left<S\\right> \\subseteq \\bigcap_{\\substack{S \\subseteq W \\\\ W:~\\text{vector space}}} W.$$\r\n\r\n($\\supseteq$) $\\left<S\\right>$ is a vector space containing $S$.\r\n\\end{proof}\r\n\r\n\\subsection{Basis}\r\n\r\n\\begin{defn} A subset $S = \\{v_i:~i\\in I\\}$ is \\textbf{linearly independent} if every vector of $S$ cannot be represented by a linear combination other vectors; i.e., $$\\forall i\\in I,~\\forall a_j\\in F,\\quad v_i \\ne \\sum_{\\substack{j\\ne i \\\\ \\textrm{finite}}} a_j v_j.$$ Equivalently, if every linear combination whose coefficients are not all zero is non-zero, the subset is linearly independent. If not, $S$ is \\textbf{linearly dependent}.\r\n\\end{defn}\r\n\r\n\\begin{defn} A \\textbf{(Hamel) basis} $\\mathfrak B$ of $V$ is a subset of $V$ which satisfies the followings: $$\\left<\\mathfrak B \\right>=V$$ and $$\\mathfrak B\\textrm{ is linearly independent.}$$\r\nWe usually fix the order of elements of $\\mathfrak B$, which is called an \\textbf{ordered basis}. Hereafter, \\textit{every basis is an ordered basis.} For example, a basis $\\{(1,0),~(0,1)\\}$ and $\\{(0,1),~(1,0)\\}$ are different bases.\r\n\\end{defn}\r\n\r\n\\begin{ex}\\leavevmode\r\n\\begin{itemize}\r\n\\item (\\textbf{standard basis}) $$\\mathcal E = \\left\\{ \\mathbf e_i = \\left(0,~\\cdots,~0,~\\underset {i-\\textrm{th}} 1,~0,~\\cdots,~0\\right): ~~~ 1\\le i \\le n \\right\\}$$ is a basis for $F^n$, for arbitrary field $F$.\r\n\\item $\\{ (1,0), (1,1)\\}$ is a basis for $\\mathbb R^2$ (over the field $\\mathbb R$).\r\n\\end{itemize}\r\n\\end{ex}\r\n\r\n\\subsection{Dimension}\r\n\\begin{defn} `The' \\textbf{dimension} $\\operatorname{dim} V$ of given vector space $V$ is the \\textbf{cardinality}(the number of elements of given set for finite set) of a basis.\r\n\\end{defn}\r\n\r\n\\begin{defn} A \\textbf{finite dimensional vector space} is a vector space whose bases are all finite.\\footnote[2]{It is the best way for defining finite dimensional vector space since the dimension is \\textit{not} well-defined yet.}\r\n\\end{defn}\r\n\r\nWe consider \\textit{finite dimensional vector spaces only} unless there is an additory description.\r\n\r\n\\begin{lemma}\\label[lemma]{l:span} Let $\\mathfrak B = \\{v_i:~ 1\\le i \\le n\\}$ be a basis, and $\\mathfrak C = \\{w_j:~ 1\\le j \\le m\\}$ span $V$. Then $m\\ge n$.\r\n\\end{lemma}\r\n\\begin{proof}\r\nIf there is a vector $v$ of $\\mathfrak B$ which is not in $\\mathfrak C$, without loss of generality, rename it $v_1 \\ne w_i$. Then $\\mathfrak C \\cup \\{v_1\\}$ is linearly dependent: since $\\mathfrak C$ spans $V$, there is a linear combination of $\\mathfrak B$ represents $-v_1$ whence $\\mathfrak C \\cup \\{v_1\\}$ is linearly dependent. Hence there is at least one vector $w_t$ which is represented by a linear combination of others. Then let $\\mathfrak C_1 = \\mathfrak C \\cup \\{v_1\\} - \\{w_t\\}.$\r\n\r\nRepeat this process. It is possible up to $n$-th stage since $\\mathfrak B$ is linearly independent: if there is a linear dependence, it must contain a $w$-vector. Hence we obtain $$\\mathfrak C_n = \\{v_1,~\\cdots,~v_n,~w_{r_1},~\\cdots,~w_{r_{m-n}} \\}$$ and it is linearly dependent.\r\n\\end{proof}\r\n\r\n\\begin{theorem}[uniqueness of dimension] Let $\\mathfrak B$ and $\\mathfrak C$ be two bases of finite dimensional vector space $V$. Then $|\\mathfrak B| = |\\mathfrak C|.$\r\n\\end{theorem}\r\n\\begin{proof}\r\n$|\\mathfrak B| \\ge  |\\mathfrak C|$ and\r\n$|\\mathfrak C| \\ge  |\\mathfrak B|$ by \\cref{l:span}.\r\n\\end{proof}\r\n\r\nWell... How about the existence? The existence of the dimension needs the existence of the basis of $V$.\r\n\r\n\\begin{theorem}[existence of basis] Every vector space has a basis, if \\textbf{AC}(Axiom of Choice) assumed. In addition, it is equivalent to \\textbf{AC}.\r\n\\end{theorem}\r\n\\begin{proof}\r\n$\\exists \\mathfrak B \\Longleftrightarrow \\mathbf{ZL} \\Longleftrightarrow \\mathbf{AC}.$ See a set theory textbook.\r\n\\end{proof}\r\n\r\n\\subsection{Basis extension}\r\nWe can \\textit{extend} a basis of smaller space to a larger space.\r\n\r\n\\begin{theorem}[basis extension] Let $W\\le V$ be two vector spaces and $\\mathfrak C$ be a basis for $W$. Then there is a basis $\\mathfrak B$ of $V$ which contains $\\mathfrak C.$\r\n\\end{theorem}\r\n\\begin{proof}\r\nInduction on \\textbf{\\textit{n$-$m}}, where $n=\\operatorname{dim}V$ and $m=\\operatorname{dim}W$. If $n-m=0$, just let $\\mathfrak B = \\mathfrak C.$ (Why?) Now, assuming there is a vector in $V - W$, take a vector $v$ in $V-W$. Then $v$ is linearly independent with $\\mathfrak B$ (that is, $\\tilde {\\mathfrak B} = \\mathfrak B \\cup \\{v\\}$ is linearly independent) and hence $\\tilde W = \\left<\\tilde {\\mathfrak B }\\right>$ is a vector space which $\\tilde W \\le V.$ Since $n-m$ decreases, the induction proceeds.\r\n\\end{proof}\r\n\r\n\r\n\\subsection{Sum and direct sum}\r\n\\begin{defn}\r\nFor a set $\\{S_i\\}_{i\\in I}$ of sets with a common addition, we define the \\textbf{sum} of $\\{S_i\\}$ as follows: \\begin{align*}\\sum_{i \\in I}S_i &= \\left\\{ \\sum_{\\textrm{finite}} s_i:~~~ s_i \\in S_i\\right\\} \\\\&= \\left\\{ \\sum_{i \\in I} s_i:~~~ s_i \\in S_i\\textrm{ and all }s_i = 0\\textrm{ but for finitely many }i\\right\\}.\\end{align*}\r\n\\end{defn}\r\n\\begin{defn}\r\nFor a set $\\{W_i\\}_{i\\in I}$ of \\textit{subspaces} of $V$ which is mutually disjoint: $$W_i \\cap W_j = \\{ 0 \\},\\qquad\\textrm{for }i\\ne j,$$ we define the \\textbf{direct sum} of $\\{W_i\\}$ just the sum of them: $$\\bigoplus_{i\\in I}  W_i = \\sum_{i \\in I} W_i.$$\r\n\r\nIf the set is not mutually disjoint, even if it is mutually disjoint itself, we \\textit{make it be} mutually disjoint: isolate the vectors with giving different coordinates for each vector space. For example, if $V\\oplus W \\ne \\{0\\}$, $$V\\oplus W :\\approx \\{(v,~w):~~~v\\in V,~ w\\in W\\}.$$\r\nTrivially the direct sum of some vector spaces is a vector space.\r\n\\end{defn}\r\n\r\n\\begin{ex}\r\n\\leavevmode\r\n\\begin{itemize}\r\n\\item $\\mathbb R \\oplus \\mathbb R \\approx \\mathbb R^2,$\r\n\\item $\\mathbb R \\oplus \\mathbb R \\oplus \\cdots \\approx \\mathbb R^\\infty.$\r\n\\end{itemize}\r\n\\end{ex}\r\n\r\n\\begin{add}\r\n\\leavevmode\r\n\\begin{itemize}\r\n\\item For finite spaces, the direct sum of them is \\textit{the same}(isomorphic) with the cartesian product.\r\n\\item The direct sum can be represented by a commutative diagram: \\begin{center}\r\n\\leavevmode\r\n\\xy\r\n\\xymatrix {\r\nX \\\\\r\n& V\\oplus W \\ar@{.>}[ul]^{f} & V\r\n\\ar[l]^{i_1}\r\n\\ar@/_/[ull]_{f_1} \\\\\r\n& W\r\n\\ar[u]_{i_2}\r\n\\ar@/^/[uul]^{f_2} &\r\n}\r\n\\endxy\r\n\\end{center} where the cartesian product is represented by:\r\n\\begin{center}\r\n\\leavevmode\r\n\\xy\r\n\\xymatrix{\r\nX \\ar@/_/[ddr]_{f_2} \\ar@{.>}[dr]_{f} \\ar@/^/[drr]^{f_1} \\\\\r\n& X \\times Y \\ar[d]^{p_2} \\ar[r]_{p_1}\r\n& X \\\\\r\n& Y  & }\r\n\\endxy\r\n\\end{center}\r\n\r\n\r\n\\end{itemize}\r\n\\end{add}\r\n\r\n\\newpage\r\n\r\n\\section{Linear Transformation}\r\n\\begin{defn}\r\nLet $V$ and $W$ be two $F$-vector spaces, then a map $f:~V\\to W$ is \\textbf{linear} if $$f(cv+dw) = cf(v)+df(w)$$ for every $c,~d \\in F$ and $v,~w\\in V.$\r\n\r\nIn another viewpoint, a linear map is a \\textbf{vector space homomorphism} since it \\textit{preserves} the operations of vector spaces.\r\n\\end{defn}\r\n\\begin{ex}\r\n\\leavevmode\r\n\\begin{itemize}\r\n\\item A map $f:~F\\to F, ~~~ x \\mapsto ax$ is a linear map from and to $F$. It is why maps of this kind are called \\textit{linear}.\r\n\\item Producting a matrix is a linear map. For a matrix $A\\in\\mathfrak M_{m,n}(F),$ $$L_A:~F^m \\to F^n,~~~ X\\mapsto AX$$ is a linear map from $F^m$ to $F^n.$ We will show that every linear map (from and to finite dimensional vector spaces) can be represented in this way, i.e., \\textit{matrices and linear transformations are the same things.}\r\n\\item Another familiar linear maps are differentiation and integration. Let $\\mathcal C^{n}$ be the space of function from and to $\\mathbb R$ which is $n$-th differentiable and has continuous $n$-th derivative. Then for $n\\in\\mathbb N$, the \\textbf{differentiation operator} $$D:~\\mathcal C^{n}\\to \\mathcal C^{n-1}, \\qquad f \\mapsto f'$$ is a linear transformation since $(cf+dg)'=cf'+dg'.$ Similarly, the \\textbf{integration operator} $$J:~\\mathcal C^{n\\ge 0} \\to \\mathcal C^{n+1},\\qquad f \\mapsto \\int_0^x f ~\\mathrm dx$$ is linear. (Here, $F$ is not a field but the antiderivative of $f.$) Similarly, partial differentiation operators are linear.\r\n\\item Transpose and trace are linear.\r\n\\end{itemize}\r\n\\end{ex}\r\n\r\n\\begin{theorem}\r\nIf $f$ is linear, values of $f$ at the basis elements determine $f$. Equivalently, there is an one-to-one correspondence between $f$ and $f(\\mathbf e_i)$'s.\r\n\\end{theorem}\r\n\\begin{proof}\r\n\\leavevmode\r\n\\begin{center}\r\n\\leavevmode\r\n\\xy\r\n\\xymatrix @C=4pc {\r\n  f(v) \\ar@/^/^{v=\\mathbf e_i} [r]\r\n& f(\\mathbf e_i) \\ar@/^/^{v=\\sum_i a_i \\mathbf e_i} [l]\r\n}\r\n\\endxy\r\n\\end{center}\r\n\\end{proof}\r\n\r\n\\begin{prop}\r\nLet denote the space of all linear transformations from $V$ to $W$ as $\\mathfrak L(V,W)$. Then $\\mathfrak L(V,W)$ is a vector space dimension of $mn$.\r\n\\end{prop}\r\n\r\n\r\n\\begin{defn}\r\nFor an $F$-vector space $V$, a linear map $f:~V\\to F$ is called a \\textbf{linear functional}. And it forms a vector space, which is called the \\textbf{dual space} of $V$. $$V^{*} = \\left\\{ f:~V\\to F~|~ f~\\textrm{linear}\\right\\}.$$ Since $V^*$ is an $F$-vector space, we can define the \\textbf{double dual} $V^{**}$ of $V$ as follows: $$V^{**} = (V^*)^* = \\left\\{ \\alpha:~V^*\\to F~|~ \\alpha~\\textrm{linear}\\right\\}.$$\r\nAn example of elements of $V^{**}$ is \\textbf{evaluation}: $$\\alpha_a(f) = f(a),\\qquad f\\in V^*.$$\r\n\\end{defn}\r\n\r\n\\begin{defn}\r\nFor a linear map $f:~V\\to W$, the \\textbf{kernel} or the \\textbf{null space} of $f$ is $$\\ker  f = f^{-1}(0) = \\left\\{v\\in V: ~ f(v) = 0 \\right\\},$$ where $0$ is the zero vector of $W.$ The \\textbf{image} of $f$ is just $\\operatorname{im}f = f(V).$\r\n\\end{defn}\r\n\\begin{prop}\r\nThe kernel and the image of a linear map form subspaces of $V$, respectively.\r\n\\end{prop}\r\n\\begin{theorem}[dimension theorem] \\label[thm]{t:dimthm} For a linear map $f:~V \\to W,$ $$\\operatorname{dim} \\ker  f + \\operatorname{dim} \\operatorname{im} f = \\operatorname{dim}V.$$\r\n\\end{theorem}\r\n\\begin{proof}\r\nProof by basis extension. Let $\\mathfrak B=\\{v_i:~1\\le i \\le n\\}$ be a basis of $\\ker f.$ Then there is a basis $\\mathfrak C = \\mathfrak B \\cup \\{w_j:~1\\le j \\le m\\}$ of $V$ which contains $\\mathfrak B$, and we will show that $f(\\mathfrak C - \\mathfrak B)$ is a basis of $\\operatorname{im}f$.\r\n\r\nFor an arbitrary vector $v = \\sum_{i} a_i v_i + \\sum_j b_j w_j$ of $V$, $$f(v) = f\\left(\\sum_i a_i v_i + \\sum_j b_j w_j \\right) = \\sum_j b_j f(w_j)$$ since $v$'s are in the kernel. Since $v$'s and $w$'s are linearly independent, so are $f(w)$'s. Hence $f(w)$'s form a basis of $\\operatorname{im}f$.\r\n\\end{proof}\r\nWe call $\\operatorname{dim}\\ker f$ the \\textbf{nullity} of $f$ and denote it as $\\operatorname{null}f$.\r\n\r\n\\begin{defn}\r\n\\leavevmode\r\n\\begin{itemize}\r\n\\item A \\textbf{monomorphism} is an injective homomorphism.\r\n\\item An \\textbf{epimorphism} is an surjective homomorphism.\r\n\\item An \\textbf{isomorphism} is an bijective homomorphism.\r\n\\item An \\textbf{automorphism} is an bijective homomorphism from and to itself.\r\n\\end{itemize}\r\n\\end{defn}\r\n\r\n\\begin{theorem}[vector space version of pigeonhole principle] Let $f:~V \\to W$ is linear, and suppose $\\operatorname{dim}V = \\operatorname{dim}W = n < \\infty.$ Then the followings hold:\r\n\\begin{itemize}\r\n\\item if $f$ is a monomorphism, then it is an isomorphism;\r\n\\item if $f$ is an epimorphism, then it is an isomorphism.\r\n\\end{itemize}\r\n\\end{theorem}\r\n\r\n\\begin{figure}\r\n\\centering\r\n\\includegraphics[width=3cm]{dove}\r\n\\caption{A pigeon.}\r\n\\end{figure}\r\n\r\n\r\n\\begin{proof}\r\nLet $f$ be a monomorphism; suppose that $f$ is not surjective. Then there is a vector $w \\in W$ such that $\\forall v\\in V,~w\\ne f(v).$ Since $f(0)=0$, other vectors in $V$ are not mapped to 0 and hence $\\ker f = \\{0\\}.$ And we get $\\operatorname{dim}\\operatorname{im}f = n$ from $\\operatorname{dim}\\ker  f = 0$. Hence $\\operatorname{im}f = W.$\r\n\r\nChanging im and ker proves the rest part of the theorem.\r\n\\end{proof}\r\n\r\nNow we can prove the question in \\textbf{Section 1.2}.\r\n\r\n\\begin{theorem}\\label[thm]{t:matinv}\r\nFor two square matrices $A$ and $B\\in\\mathfrak M_{n,n}(F)$, if $AB=I$, then $A=B^{-1}.$\r\n\\end{theorem}\r\n\\begin{proof}\r\n$AB=I$ implies that $B$ is left-invertible, which is equivalent to that $L_B$ is a monomorphism. Since $L_B:~F^n\\to F^n$, $L_B$ is an isomorphism whence $B$ is invertible: $$B^{-1} = \\begin{pmatrix} | & & | \\\\ L_B^{-1}\\mathbf e_1 &\\cdots & L_B^{-1}\\mathbf e_n \\\\ | & & | \\end{pmatrix}. $$ Multiplying $B^{-1}$ right in the both sides of $AB=I$, we obtain $A=B^{-1}.$ Similarly, $A$ is invertible and $A^{-1} = B.$\r\n\\end{proof}\r\n\r\n\\subsection{Rank}\r\n\\begin{defn}\r\nFor a matrix $A\\in\\mathfrak M_{m,n}(F),$ the \\textbf{row space} is a space which is generated by the row vectors of $A.$ Similarly, the \\textbf{column space} is a space which is generated by the column vectors of $A.$ Then the \\textbf{row}(\\textit{column}) \\textbf{rank} is the dimension of the row(\\textit{column}) space.\r\n\\end{defn}\r\n\\begin{ex}\r\nWe can know the row rank and the column rank in the (R, C)-REF of the matrix; one can do elementary row operations: \\begin{align*}\r\nA &= \\begin{pmatrix}1&0&1\\\\5&6&7\\\\0&3&1\\end{pmatrix}\\\\\r\n&\\sim_r \\begin{pmatrix}1&0&1\\\\0&6&2\\\\0&3&1\\end{pmatrix}\\\\\r\n&\\sim_r \\begin{pmatrix}1&0&1\\\\0&6&2\\\\0&0&0\\end{pmatrix}\\\\\r\n&\\sim_r \\begin{pmatrix}1&0&1\\\\0&1&\\frac 1 3 \\\\0&0&0\\end{pmatrix};\r\n\\end{align*}\r\nhence the row space is $\\{(a,b,a+b/3)^\\mathsf T:~a,b\\in R\\}$ whence the row rank is 2; while the column space is $\\{(a+c,b+c/3,0)^\\mathsf T = (\\tilde a,\\tilde b,0)^\\mathsf T:~\\tilde a,\\tilde b\\in R\\}$ whence the column rank is also 2. Otherwise one can do elementary column operations: \\begin{align*}\r\nA &= \\begin{pmatrix}1&0&1\\\\5&6&7\\\\0&3&1\\end{pmatrix}\\\\\r\n&\\sim_c \\begin{pmatrix}1&0&0\\\\5&6&2\\\\0&3&1\\end{pmatrix}\\\\\r\n&\\sim_c \\begin{pmatrix}1&0&0\\\\5&6&0\\\\0&3&0\\end{pmatrix}\\\\\r\n&\\sim_c \\begin{pmatrix}1&0&0\\\\0&1&0\\\\-\\frac 5 2&\\frac1 2&0\\end{pmatrix};\r\n\\end{align*}\r\nwhich makes the same result.\r\n\\end{ex}\r\n\r\nAre the row rank and the column rank the same? The answer is...\r\n\r\n\\begin{lemma}For a matrix $A\\in\\mathfrak M_{m,n}(F)$ over an \\emph{ordered field} $F$, $$\\operatorname{col~rk}A = \\operatorname{col~rk}A^\\mathsf T.$$\r\n\\end{lemma}\r\n\\begin{proof}\r\nIt is suffices to show that $\\operatorname{col~rk}A \\le \\operatorname{col~rk}A^\\mathsf T,$ since it implies $$\\operatorname{col~rk}A^\\mathsf T \\le \\operatorname{col~rk}(A^\\mathsf T )^\\mathsf T  = \\operatorname{col~rk}A$$which completes the proof of lemma.\r\n\r\nWe will show that $Av = 0$ if and only if $(A^\\mathsf T A)v = 0$ whence $$\\operatorname{col~rk}A = \\operatorname{col~rk}(A^\\mathsf T A) \\le \\operatorname{col~rk}A^\\mathsf T$$; the last inequality follows because each column of $A^\\mathsf T A$ is a linear combination of the columns of $A^\\mathsf T$. First, $Av=0 \\implies A^\\mathsf T Av = 0$ trivially. Conversely, $$A^\\mathsf T Av = 0 \\implies v^\\mathsf T A^\\mathsf T A v = 0 \\implies (Av)^\\mathsf T Av = 0 \\implies Av = 0,$$ by positive-definiteness of the dot product. (More generalized version of proof uses the orthogonal complement, or even \\textbf{Erdős-Kaplansky Theorem}(?). See http://math.stackexchange.com/questions/2315/is-the-rank-of-a-matrix-the-same-of-its-transpose-if-yes-how-can-i-prove-it)\\end{proof}\r\n\\begin{theorem}[rank theorem] The row rank and the column rank are the same, and we call it the \\textbf{rank} of the given matrix.\r\n\\end{theorem}\r\n\\begin{proof}[Proof 1]\r\nCount the number of \\textit{leading 1} in RREF.\r\n\\end{proof}\r\n\\begin{proof}[Proof 2 assuming that $F$ is an ordered field]\r\nIt is trivial that the row rank of $A$ equals the column rank of $A^\\mathsf T.$ Since the column rank of $A^\\mathsf T$ is the same with of $A$, the proof completed.\r\n\\end{proof}\r\n\\begin{theorem}[rank-nullity theorem]\r\nLet $A\\in\\mathfrak M_{m,n}(F)$ be a matrix, then $$\\operatorname{rank}A + \\operatorname{dim}\\ker L_A = m.$$ We call $\\operatorname{dim}\\ker L_A$ the \\textbf{nullity} of $A$, and denote $\\operatorname{null}A$. Hence $$\\operatorname{rank}A + \\operatorname{null}A = m = \\operatorname{dim}\\operatorname{dom}L_A.$$\r\n\\end{theorem}\r\n\\begin{proof}\r\nWe know that $A\\mathbf e_i$ is $i$-th column of $A$. Hence the column space of $A$ is just the image of $L_A:~F^m \\to F^n$, hence $\\operatorname{col~rk} A = \\operatorname{dim}\\operatorname{im}L_A.$ By the dimension theorem(\\cref{t:dimthm}), $$\\operatorname{dim}\\ker L_A  + \\operatorname{col~rk} A = \\operatorname{dim} F^m = m.$$\\end{proof}\r\n\r\n\\begin{defn}\r\nGiven an $m$ by $n$ matrix $A$ of rank $r$, a \\textbf{rank decomposition} of $A$ is a representation by a product $A=PQ$ of two matrices $P\\in\\mathfrak M_{m,r}(F)$ and $Q\\in\\mathfrak M_{r,n}(F).$\r\n\\end{defn}\r\n\\begin{theorem}\r\nA rank decomposition of a matrix exists, but not uniquely.\r\n\\end{theorem}\r\n\\begin{proof}\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5\r\n\\end{proof}\r\n\r\n\r\n\\subsection{Matrix representation and similarity}\r\n\\begin{defn}\r\nFor a finite dimensional vector space $V$ and a basis $\\mathfrak B = \\{v_i\\}_{i\\in I}$ of $V$, every vector $v$ in V can be represented as a linear combination of $\\mathfrak B$ \\textit{uniquely}, namely $$v = \\sum a_i v_i;$$ and we call the row vector $$[v]_{\\mathfrak B} = \\begin{pmatrix}a_1 \\\\ \\vdots \\\\ a_n\\end{pmatrix}$$ the \\textbf{coordinate} vector.\r\n\\end{defn}\r\n\r\n\\begin{theorem}\r\nFor a $F$-vector space homomorphism $f:~V\\to W$ and the bases $\\mathfrak B$ and $\\mathfrak C$ of V and W, respectively, there is a unique matrix $[f]^{\\mathfrak B}_{\\mathfrak C} \\in \\mathfrak M_{\\operatorname{dim}V,~\\operatorname{dim}W}(F)$ such that $$[f]^{\\mathfrak B}_{\\mathfrak C} [v]_{\\mathfrak B} = [fv]_{\\mathfrak C}.$$\r\n\\end{theorem}\r\n\\begin{proof}\r\nLet $n=\\operatorname{dim}V$, $m=\\operatorname{dim}W$, $\\mathfrak B = \\{ v_i\\}_{i=1}^{n}$ and $\\mathfrak C = \\{ w_j\\}_{j=1}^{m}$, then\r\n\\begin{align*}\r\n\\left[f(v)\\right]_\\mathfrak C &= \\left[f\\left(\\sum_i a_i v_i \\right) \\right]_\\mathfrak C\r\n  \\\\ &= \\left[\\sum_i a_i f\\left( v_i \\right)\\right]_\\mathfrak C\r\n  \\\\ &= \\left[\\sum_i a_i \\sum_j b_{ij} w_j\\right]_\\mathfrak C\r\n  \\\\ &= \\left[\\sum_j \\left(\\sum_i a_i b_{ij}\\right) w_j\\right]_\\mathfrak C\r\n  \\\\ &= \\begin{pmatrix}\\sum_i a_i b_{i1} \\\\ \\vdots \\\\ \\sum_i a_i b_{im}\\end{pmatrix}\r\n  \\\\ &= \\begin{pmatrix}b_{11} & \\cdots & b_{n1} \\\\ \\vdots & \\ddots & \\vdots \\\\ b_{1m} & \\cdots & b_{nm} \\\\ \\end{pmatrix}\\begin{pmatrix}a_1 \\\\ \\vdots \\\\ a_n\\end{pmatrix}\r\n  \\\\ &= [f]^{\\mathfrak B}_{\\mathfrak C} [v]_\\mathfrak B,\r\n\\end{align*} where $[f(v_i)]_\\mathfrak C = [b_{i1} ~ \\cdots ~ b_{im}]^\\mathsf T$ whence $$[f]^\\mathfrak B _ \\mathfrak C = \\bigg( [f(v_1)]_\\mathfrak C ~~~ \\cdots ~~~ [f(v_n)]_\\mathfrak C \\bigg).$$ Uniqueness follows from the uniqueness of the coordinate representation.\r\n\\end{proof}\r\n\\begin{prop}[composition and product] \\label[prop]{p:comprod} Let $V \\xrightarrow{f} W \\xrightarrow{g} U$ be two homomorphisms. Then\r\n$$[g\\circ f]^\\mathfrak B _ \\mathfrak D = [g]^\\mathfrak C _ \\mathfrak D [f]^\\mathfrak B _ \\mathfrak C.$$\r\n\\end{prop}\r\n\\begin{proof}\r\nEasy.\r\n\\end{proof}\r\nTherefore, if the bases are fixed, there is a \\textit{one-to-one correspondence} between the space of matrices and the space of linear transformations; where the operations are preserved under the correspondence, as follows: $$f+g \\quad \\longleftrightarrow \\quad [f] + [g]$$ and $$f\\circ g \\quad \\longleftrightarrow \\quad [f][g].$$ We just say that, \\begin{center}``the matrices are the same thing as the linear transformations.''\\end{center}\r\n\r\n\\subsection{Basis transition}\r\n\\begin{theorem} Let $\\mathfrak B$ be a basis of $F^n$ and let $A$ is an $n$ by $n$ square matrix. Then $A\\mathfrak B = \\{Av_i:~v_i\\in\\mathfrak B\\}$ is a basis of $F^n$ if and only if $A$ is invertible.\r\n\\end{theorem}\r\n\\begin{proof}\r\nDenote $\\mathfrak B= \\{v_i:~1\\le i \\le n\\}$ like a column vector, although $F^n$ is not a field, namely, $$\\mathfrak B = \\begin{pmatrix} v_1\\\\ v_2 \\\\ \\vdots \\\\ v_n \\end{pmatrix}.$$ And define $A\\mathfrak B$ as componentwise product: $$A\\mathfrak B = \\begin{pmatrix} Av_1\\\\ Av_2 \\\\ \\vdots \\\\A v_n \\end{pmatrix}.$$\r\n\r\n($\\Rightarrow$) If $Y$ is a basis, then $\\exists C \\in \\mathfrak M_{n,n}(F),\\quad C(A\\mathfrak B) = \\mathfrak B$ since $A\\mathfrak B$ spans $F^n.$ $(CA)\\mathfrak B = \\mathfrak B$ implies that $(CA)v_i = v_i$ for every basis element $v_i \\in \\mathfrak B$ whence $CA = I$ and it implies that $A$ is invertible.\r\n\r\n($\\Leftarrow$) Let $v=\\sum_i a_i v_i$ and $$R = \\begin{pmatrix}a_1&\\cdots&a_n\\end{pmatrix}$$ be the coefficient matrix. Then $$v = \\sum a_i v_i = R\\mathfrak B = (R A^{-1})(A\\mathfrak B) = \\tilde R (A\\mathfrak B)$$ whence $A\\mathfrak B$ is a basis of $F^n$.\r\n\\end{proof}\r\n\\begin{theorem} \\label[thm]{t:trninv}\r\nIf $\\mathfrak B$ and $\\tilde{\\mathfrak B}$ are bases of V and $\\mathfrak C$ and $\\tilde{\\mathfrak C}$ are bases of W, then for linear $f:~V\\to W,$ $$[\\operatorname{id}_W]_{\\tilde{\\mathfrak C }} ^{ \\mathfrak C} [f]^{\\mathfrak B}_{\\mathfrak C} [\\operatorname{id}_V]^{\\tilde{\\mathfrak B}} _{ \\mathfrak B} = [f]^{\\tilde{\\mathfrak B}}_{\\tilde{\\mathfrak C}}.$$ Furthermore, $[\\operatorname{id}]_\\bullet^\\bullet$ are all invertible.\r\n\\end{theorem}\r\n\\begin{proof}\r\nFor the first assertion, just use \\cref{p:comprod}. For the second one, since $$[\\operatorname{id}]_{\\mathfrak B}^{\\tilde{\\mathfrak B}}[\\operatorname{id}]^{\\mathfrak B}_{\\tilde{\\mathfrak B}} = [\\operatorname{id}]_{\\mathfrak B}^{\\mathfrak B} = I_{\\operatorname{dim}\\bullet},$$they are invertible by \\cref{t:matinv}.\r\n\r\n\\end{proof}\r\n\\begin{prop}\r\nFor two bases $\\mathfrak B$ and $\\tilde{\\mathfrak B}$ of $V$, the \\textbf{transition matrix} $[\\operatorname{id}_V]^\\mathfrak B _{\\tilde{ \\mathfrak B}}$ is invertible. Conversely, for a basis $\\mathfrak B$ of $V$ and an invertible square matrix $U$ whose the number of row is the dimension of the space $V$, there is a basis $\\tilde{\\mathfrak B}$ of $V$ such that $$U = [\\operatorname{id}_V]^\\mathfrak B _{\\tilde{ \\mathfrak B}}.$$\r\n\\end{prop}\r\n\\begin{proof}\r\nThe first assertion was proved in \\cref{t:trninv}. For the second, let $$U = \\begin{pmatrix}a_{11}&\\cdots &a_{1n} \\\\ \\vdots &\\ddots &\\vdots \\\\a_{n1}&\\cdots&a_{nn} \\end{pmatrix}$$ and $\\mathfrak B = \\{v_i\\}$. We want another basis $\\tilde{\\mathfrak B} = \\{w_i\\}$ which satisfies $$U = [\\operatorname{id}_V]^\\mathfrak B _{\\tilde{ \\mathfrak B}} = \\begin{pmatrix} | & & | \\\\ [v_1]_{\\tilde{ \\mathfrak B}} & \\cdots & [v_n]_{\\tilde{ \\mathfrak B}} \\\\ | && | \\end{pmatrix},$$ that is, $$v_i = \\sum_{j} a_{ij}w_j, \\qquad \\begin{pmatrix} v_1 \\\\ \\vdots \\\\ v_n \\end{pmatrix} = \\begin{pmatrix}a_{11}&\\cdots &a_{1n} \\\\ \\vdots &\\ddots &\\vdots \\\\a_{n1}&\\cdots&a_{nn} \\end{pmatrix}\\begin{pmatrix} w_1 \\\\ \\vdots \\\\ w_n \\end{pmatrix} = U \\begin{pmatrix} w_1 \\\\ \\vdots \\\\ w_n \\end{pmatrix} \\qquad $$ Hence we have $$\\tilde{\\mathfrak B} = U^{-1}\\mathfrak B.$$\r\n\\end{proof}\r\n\\subsection{Similarity}\r\n\\begin{defn}[similarity]\r\nFor two square matrices $A$ and $\\tilde A$, we say those are \\textbf{similar} if there is an invertible matrix $U$ such that $$\\tilde A = U^{-1}AU,$$and denote $A\\sim \\tilde A$.\r\n\\end{defn}\r\n\\begin{prop}\r\nSimilarity relation is an \\textbf{equivalence relation}, that is, satisfies the following three properties: \\begin{itemize}\r\n\\item (Reflexivity) $A \\sim A,$\r\n\\item (Symmetricity) $A \\sim B \\Longrightarrow B \\sim A,$\r\n\\item (Transitivity) $A\\sim B \\sim C \\implies A\\sim C.$\r\n\\end{itemize}\r\n\\end{prop}\r\n\r\n\\begin{ex}[similarity]\r\nFor two square matrices $A$ and $\\tilde A$, we say those are \\textbf{similar} if there is an invertible matrix $U$ such that $$\\tilde A = U^{-1}AU,$$and denote $A\\sim \\tilde A$.\r\n\\end{ex}\r\n\\begin{prop}\r\n[similarity]\r\nFor a linear operator $f:~V\\to V$ and the bases $\\mathfrak B$, $\\tilde{\\mathfrak B}$ of $V$, two matrix representations of $f$ are similar, that is, $$[f]^{\\mathfrak B} _{\\mathfrak B} \\sim [f]^{\\tilde{\\mathfrak B}} _{\\tilde{\\mathfrak B}}.$$\r\n\\end{prop}\r\n\\begin{proof}\r\n$$[\\operatorname{id}_V] _{\\tilde{\\mathfrak B}} ^{\\mathfrak B} [f]^{\\mathfrak B} _{\\mathfrak B} [\\operatorname{id}_V] ^{\\tilde{\\mathfrak B}} _{\\mathfrak B} = [f]^{\\tilde{\\mathfrak B}} _{\\tilde{\\mathfrak B}}.$$\r\n\\end{proof}\r\n", "meta": {"hexsha": "d11f8c7753fdfcf6deed3dd04c3213cae04ba0ff", "size": 33107, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "vector_space.tex", "max_stars_repo_name": "utophii/LinAlg", "max_stars_repo_head_hexsha": "3d11ab2382a1b7aaeea5c6703ee3f1e860b18f46", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "vector_space.tex", "max_issues_repo_name": "utophii/LinAlg", "max_issues_repo_head_hexsha": "3d11ab2382a1b7aaeea5c6703ee3f1e860b18f46", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vector_space.tex", "max_forks_repo_name": "utophii/LinAlg", "max_forks_repo_head_hexsha": "3d11ab2382a1b7aaeea5c6703ee3f1e860b18f46", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.4067085954, "max_line_length": 838, "alphanum_fraction": 0.6638777298, "num_tokens": 11872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396141, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.7341411346097828}}
{"text": "To fulfill our study we provide an opportunity to verify its results by means of Wolfram Mathematica language.\n\n\\subsection{Mathematica commands} \\label{subsec:mathematica-commands}\nProceeding to the repository~\\cite{PK22Source} reader is able to find there a folder named \\texttt{mathematica}\nthat contains the files\n\\begin{itemize}\n    \\item \\texttt{OnTheBinomialTheoremAndDiscreteConvolution.m} is a package file with definitions\n    \\item \\texttt{OnTheBinomialTheoremAndDiscreteConvolution.nb} is a notebook file with examples.\n\\end{itemize}\nThe following commands may be used to reproduce the results of this manuscript:\n\\begin{itemize}\n    \\item \\texttt{A[m, r]} returns the real coefficient $\\coeffA{m}{r}$ defined by~\\eqref{eq:def_coeff_a}.\n    \\item \\texttt{PrintTriangleOfA[rows]} prints the table of coefficients $\\coeffA{m}{r}$. \\\\\n    Command \\texttt{PrintTriangleOfA[7]} reproduces the table (\\ref{tab:table_of_coefficients_a}).\n    \\item \\texttt{PolynomialL[m, n, k]} returns the polynomial $\\polynomialL{m}{n}{k}$ defined by~\\eqref{eq:def_polynomial_l}.\n    \\item \\texttt{PolynomialP[m, x, b]} returns the polynomial $\\polynomialP{m}{b}{x}$ defined by~\\eqref{eq:def_polynomial_p}.\n    \\item \\texttt{Expand[PolynomialP[m, x + y, x + y]]} verifies the Lemma~\\ref{lemma_polynomial_p_and_odd_power}.\n    \\item \\texttt{PolynomialH[m, t, j]} returns the polynomial $\\coeffH{m}{t}{j}$ defined by~\\eqref{eq:def_coeff_h}.\n    \\item \\texttt{PolynomialX[m, t, k]} returns the polynomial $\\polynomialX{m}{t}{k}$ defined by~\\eqref{eq:def_coeff_x}.\n    \\item \\texttt{Expand[BinomialTheoremAndDiscreteConvolutionTest[m, x + y]]} verifies the Corollary~\\ref{cor_bin_exp_and_macaulay_conv}.\n    \\item \\texttt{Expand[BinomialTheoremAndDiscreteConvolutionStrictTest[m, x + y]]} verifies the Corollary~\\ref{cor_bin_exp_and_macaulay_conv_strict}.\n    \\item \\texttt{DiscreteConvolutionPowerIdentityParametricTest[m, x, a]} verifies an equation~\\eqref{eq:parametric-identity}.\n    Usage \\texttt{Column[Table[DiscreteConvolutionPowerIdentityParametricTest[1, x, 1], {x, 3, 20}], Left]}.\n    \\item \\texttt{DiscreteConvolutionPowerIdentityStrictParametricTest[m, x, a]} verifies an equation~\\eqref{eq:parametric-identity-strict}.\n    Usage \\texttt{Column[Table[DiscreteConvolutionPowerIdentityStrictParametricTest[1, x, 1], {x, 3, 20}], Left]}.\n    \\item \\texttt{Expand[PolynomialIdentityOfP[1, n, b]]} validates an identity\n    \\[\\polynomialP{m}{b}{x} = \\sum_{r=0}^{m} \\coeffA{m}{r} \\sum_{j=0}^{r} (-1)^{j} x^{r-j} \\binom{r}{j} \\sum_{k=0}^{b-1} k^{r+j}\\]\n    \\item \\texttt{PolynomialIdentityInvolvingX[m, x, b]} validates an identity~\\eqref{eq:p_all_forms}\n    \\[\\polynomialP{m}{b}{x} = \\sum_{r=0}^{m} (-1)^{m-r} \\polynomialX{m}{r}{b} \\cdot x^r\\]\n    \\item \\texttt{PolynomialIdentityInvolvingH[m, n, b]} validates an identity~\\eqref{eq:p_all_forms}.\n    \\[\\polynomialP{m}{b}{x} =\\sum_{r=0}^{m} \\sum_{\\ell=1}^{2m-r+1} (-1)^{2m-r} \\coeffH{m}{r}{\\ell} \\cdot b^\\ell \\cdot x^r\\]\n\\end{itemize}\n\n\\subsection{Examples} \\label{subsec:examples}\nFor example, given $m=1$ we have the following values of $\\polynomialL{1}{x}{k}$\n\\begin{table}[H]\n    \\begin{tabular}{c|cccccccc}\n        $x/k$ & 0 & 1  & 2  & 3  & 4  & 5  & 6  & 7 \\\\[3px]\n        \\hline\n        0     & 1 &    &    &    &    &    &    &   \\\\\n        1     & 1 & 1  &    &    &    &    &    &   \\\\\n        2     & 1 & 7  & 1  &    &    &    &    &   \\\\\n        3     & 1 & 13 & 13 & 1  &    &    &    &   \\\\\n        4     & 1 & 19 & 25 & 19 & 1  &    &    &   \\\\\n        5     & 1 & 25 & 37 & 37 & 25 & 1  &    &   \\\\\n        6     & 1 & 31 & 49 & 55 & 49 & 31 & 1  &   \\\\\n        7     & 1 & 37 & 61 & 73 & 73 & 61 & 37 & 1\n    \\end{tabular}\n    \\caption{Values of $\\polynomialL{1}{x}{k}$. See OEIS entry: \\href{https://oeis.org/A300656}{\\texttt{A300656}}.}\n    \\label{tab:tab_3}\n\\end{table}\nTable~\\ref{tab:tab_3} can be reproduced using Mathematica command\n\\begin{center}\n    \\texttt{PrintTriangleOfPolynomialL[1, 7]}\n\\end{center}\ndefined in the~\\cite{PK22Source}.\nFrom Table~\\ref{tab:tab_3} it is seen that\n\\begin{equation*}\n    \\begin{split}\n        \\polynomialP{1}{0}{0} &= 0 = 0^3 \\\\\n        \\polynomialP{1}{1}{1} &= 1 = 1^3 \\\\\n        \\polynomialP{1}{2}{2} &= 1+7 = 2^3 \\\\\n        \\polynomialP{1}{3}{3} &= 1+13+13 = 3^3 \\\\\n        \\polynomialP{1}{4}{4} &= 1+19+25+19 = 4^3 \\\\\n        \\polynomialP{1}{5}{5} &= 1+25+37+37+25 = 5^3\n    \\end{split}\n\\end{equation*}\nAnother case, given $m=2$ we have the following values of $\\polynomialL{2}{x}{k}$\n\\begin{table}[H]\n    \\begin{tabular}{c|cccccccc}\n        $x/k$ & 0 & 1    & 2    & 3    & 4    & 5    & 6    & 7 \\\\ [3px]\n        \\hline\n        0     & 1 &      &      &      &      &      &      &   \\\\\n        1     & 1 & 1    &      &      &      &      &      &   \\\\\n        2     & 1 & 31   & 1    &      &      &      &      &   \\\\\n        3     & 1 & 121  & 121  & 1    &      &      &      &   \\\\\n        4     & 1 & 271  & 481  & 271  & 1    &      &      &   \\\\\n        5     & 1 & 481  & 1081 & 1081 & 481  & 1    &      &   \\\\\n        6     & 1 & 751  & 1921 & 2431 & 1921 & 751  & 1    &   \\\\\n        7     & 1 & 1081 & 3001 & 4321 & 4321 & 3001 & 1081 & 1\n    \\end{tabular}\n    \\caption{Values of $\\polynomialL{2}{x}{k}$. See OEIS entry: \\href{https://oeis.org/A300656}{\\texttt{A300656}}.}\n    \\label{tab:tab_4}\n\\end{table}\nTable~\\ref{tab:tab_4} can be reproduced using Mathematica command\n\\begin{center}\n    \\texttt{PrintTriangleOfPolynomialL[2, 7]}\n\\end{center}\ndefined in the~\\cite{PK22Source}.\nAgain, an odd-power identity~\\ref{lemma_polynomial_p_and_odd_power} holds\n\\begin{equation*}\n    \\begin{split}\n        \\polynomialP{2}{0}{0} &= 0 = 0^5 \\\\\n        \\polynomialP{2}{1}{1} &= 1 = 1^5 \\\\\n        \\polynomialP{2}{2}{2} &= 1+31 = 2^5 \\\\\n        \\polynomialP{2}{3}{3} &= 1+121+121 = 3^5 \\\\\n        \\polynomialP{2}{4}{4} &= 1+271+481+271 = 4^5 \\\\\n        \\polynomialP{2}{5}{5} &= 1+481+1081+1081+481 = 5^5\n    \\end{split}\n\\end{equation*}\n", "meta": {"hexsha": "b90326a887dae6650a48f48ac83f26ff0f4d6e0b", "size": 5949, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/sections/verification-of-results.tex", "max_stars_repo_name": "kolosovpetro/OnTheBinomialTheoremAndDiscreteConvolution", "max_stars_repo_head_hexsha": "14a3facc4759e9b8452b15409e8dcfac4e9add26", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/sections/verification-of-results.tex", "max_issues_repo_name": "kolosovpetro/OnTheBinomialTheoremAndDiscreteConvolution", "max_issues_repo_head_hexsha": "14a3facc4759e9b8452b15409e8dcfac4e9add26", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/sections/verification-of-results.tex", "max_forks_repo_name": "kolosovpetro/OnTheBinomialTheoremAndDiscreteConvolution", "max_forks_repo_head_hexsha": "14a3facc4759e9b8452b15409e8dcfac4e9add26", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.900990099, "max_line_length": 151, "alphanum_fraction": 0.5891746512, "num_tokens": 2272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7341411330536451}}
{"text": "%\\chapter{Image Classification and Convolutional Neural Networks}\\label{chap:introCNN}\nIn this chapter, we will give some basic introduction for supervised \nlearning especially for image classification problems. \nThen, we will introduce and define the data and feature space\nwith related mappings such as convolution and pooling.\nIn addition, we use the  piecewise (bi-)linear functions on multilevel grids to\ninterpret the multi-resolution images in the process of CNN. At last, \nwe define some classical CNN models mathematically with those notation. \n\n\n\\section{Supervised learning on image classification}\\label{sec:MLbasics}\nWe consider a basic machine learning problem for classifying a\ncollection of images into $\\kappa$ distinctive classes.  As an\nexample, we consider a two-dimensional image which is usually\nrepresented by a tensor\n$$\nf\\in \\mathbb  \\FC := \\mathbb{R}^{m\\times n\\times c}.\n$$\nHere \n\\begin{equation}\n\\label{data-c}\nc=\n\\left\\{\n\\begin{array}[rl]{rl}\n1 & \\mbox{for black-white image}\\\\    \n3 & \\mbox{for color image}.\n\\end{array}\n\\right.\n\\end{equation}\n\nA typical supervised machine learning problem begins with a data set (training data)\n$$\nD := \\{(f_i, y_i)\\}_{i=1}^N,\n$$ \nwith\n$$\n\\{f_i\\}_{i=1}^N \\subset \\FC,\n$$\nand $y_i \\in \\mathbb{R}^{\\kappa}$ is the label for data $f_i$, with\n$[y_i]_j$ as the probability for $f_i$ in classes $j$. \n\n\nRoughly speaking, a supervised learning problem can be thought as data fitting\nproblem in a high dimensional space $\\FC$.\nNamely, we need to find a mapping\n$$\n\\classmap:  \\mathbb R^{m\\times n\\times c}\\mapsto \\mathbb R^\\kappa\n$$\nsuch that, for a given $f\\in  \\FC$, \n\\begin{equation}\\label{eq:idealouput}\n\\classmap(f)\\approx e_i\\in \\mathbb R^\\kappa\n\\end{equation}\nif $f$ is in class $i$, for $1\\le i\\le \\kappa$. \nFor the general setting above, we use a probatilistic model for understanding the\noutput $\\classmap(f) \\in \\mathbb{R}^{\\kappa}$ as a discrete \ndistribution on $\\{1, \\cdots,\\kappa\\}$, with $[\\classmap (f)]_i$ as the probability\nfor $f$ in the class $i$, namely\n\\begin{equation}\n\\label{distrib}\n0 \\le [\\classmap(f)]_i \\le 1,\\quad \n\\sum_{i=1}^\\kappa  [\\classmap(f)]_i=1. \n\\end{equation}\nAt last, we finish our model with a simple strategy to choose\n\\begin{equation}\\label{eq:maxchoose}\n\\mathop{\\arg\\max}_{i}\\{[\\classmap(f)]_i~:~ i = 1:\\kappa\\},\n\\end{equation}\nas the label for a test data $f$, which ideally is close to\n\\eqref{eq:idealouput}.  The remaining key issue is the construction of\nthe classification mapping $\\classmap$.\n\n\n%\\subsection{Model construction}\n%In many CNN type models for image classification, there are usually\n%three major steps to construct $\\classmap$.\nThe main step in the construction of $\\classmap$ is to \nconstruct a nonlinear mapping\n\\begin{equation}\n\\label{linearize}\n\\linearize: \\FC \\mapsto V_J\n\\end{equation}\nwith \n%\\begin{equation}\n%  \\label{F}\n%\\FC= \\mathbb R^{m\\times n\\times c}  \n%\\end{equation}\n\\begin{equation}\n\\label{VJ}\nV_J = \\mathbb R^{m_J\\times n_J\\times c_J}. \n\\end{equation}\nTo be consistent with the notation for CNN which will be described below,\nhere the subscript $J$ refers to the number of \ncoarsening girds in CNN. \nRoughly speaking, the map $\\linearize$ plays two roles.  The first role\nis to make a dimension reduction, namely\n$$\nm_Jn_Jc_J\\ll  mnc.\n$$\nThe second role is to map a complicated set of data into a set of data\nthat are linearly separable. As a result, the simple logistic regression \nprocedure can be applied.\n\nThe first step in a logistic regression it to introduce a linear mapping:\n\\begin{equation*}\n\\Theta: \\FC \\to\\mathbb{R}^{\\kappa} ,\n\\end{equation*}as \n\\begin{equation}\\label{thetamap}\n\\Theta(x)=Wx+b,\n\\end{equation}\nwhere $W=(w_{ij})\\in\\mathbb{R}^{(m_J \\times n_J \\times c_J)\\times \\kappa}$, \n$b\\in\\mathbb{R}^{\\kappa}$.\n\n\nWe then use the soft-max function.\n\\begin{equation}\n\\label{softmax}\n[S(z)]_i=[{\\rm Solftmax}(z)]_i= \\frac{e^{z_i}}{\\sum_{j} e^{z_j}},\n\\end{equation}\nto obtain a logistic regression model \n\\begin{equation}\n\\label{eq:log_reg}\nS \\circ \\Theta: \\mathbb R^{m_J\\times n_J\\times c_J}\\mapsto \\mathbb R^\\kappa.\n\\end{equation}\n%\tThis makes $S\\circ \\linearize(f) \\in \\mathbb{R}^\\kappa$ as a distribution on \n%\t$\\{1,\\cdots,\\kappa\\}$. \n\nBy combining the nonlinear mapping $\\classmap$ in \\eqref{linearize}\nand the logistic regression \\eqref{eq:log_reg}, we obtain the following classifier:\n\\begin{equation}\n\\label{classifier}\n\\classmap=  S\\circ \\Theta\\circ \\linearize.\n\\end{equation}\n\n%\\subsection{Loss function and training}  \nGiven the model \\eqref{classifier},\nwe finish the training phase with solving the next optimization \nproblem:\n\\begin{equation}\n\\label{eq:abstractloss}\n\\min \\sum_{j=1}^Nl(\\classmap(f_j),y_j),\n\\end{equation}\nwhere\nHere $l(\\classmap(f_j),y_j)$ is a  loss function that measures the\npredicted result $\\classmap(f_j)$ and the real label $y_j$. \nIn logistic regression, \nthe following cross-entropy loss function is often used\n\\begin{equation}\\label{eq:cross-entropy}\nl(\\classmap(f), y) = \\sum_{i=1}^\\kappa -[y]_i \\log [\\classmap(f)]_i.\n\\end{equation}\n\n\\section{Data space, feature space and relevant mappings}\\label{sec:spaces}\nGiven a data\n\\begin{equation}\n\\label{data-f}\nf \\in \\mathbb{R}^{m \\times n \\times c}, \n\\quad \\text{or}\\quad [f]_i \\in\n\\mathbb{R}^{m\\times n}, \\quad i = 1:c,\n\\end{equation}\nwhere $m\\times n$ is called the spatial dimension and $c$ is the \nchannel dimension.\n\nFor the given data $f$ in \\eqref{data-f}, we look for some\nfeature vector, denoted by $u$,  associated with $f$:\n\\begin{equation}\n\\label{u}\nu \\in \\mathbb{R}^{m \\times n \\times h}.\n\\end{equation}\nWe make an assumption that the data $f$ and feature $u$ are related by a mapping \n(which can be either linear or nonlinear)\n\\begin{equation}\n\\label{u}\nA:  \\mathbb{R}^{m \\times n \\times h}\\mapsto \\mathbb{R}^{m \\times n \\times c}, \n\\end{equation}\nso that\n\\begin{equation}\n\\label{Auf}\nA(u)=f. \n\\end{equation}\nA mapping \n\\begin{equation*}\nB : \\mathbb{R}^{m\\times n\\times c} \\mapsto \\mathbb{R}^{m \\times n\\times h},\n\\end{equation*}\nis called a feature extractor if $B \\approx A^{-1}$ and \n\\begin{equation}\\label{vBf}\nv = B(f),\n\\end{equation}\nis such that $v \\approx u$.\n\nThe data-feature relationship \\eqref{Auf} or \\eqref{vBf} is not\nunique.   Different relationships give rise to different features. \nWe can view the data-feature relationship given in \\eqref{Auf}\nas a model that we propose.  Here the mapping $A$, which can be either\nlinear or nonlinear, is unknown and needs to be trained.  \n\n%\\begin{remark}\nWe point out  that the data space and feature space may have different\nnumbers of channels.\n%\\end{remark}\n\n\\subsection{A special linear mapping: convolution}\n%Firstly, as mentioned before, an image type\n%data with multichannel can be understand as  \n%vector valued functions\n%$$\n%f \\in \\mathbb{R}^{m \\times n \\times c}, \\quad \\text{or}\\quad [f]_i \\in\n%\\mathbb{R}^{m\\times n}, \\quad i = 1:c,\n%$$\nOne important class of linear mapping is the so called convolution:\n%We first consider $\\theta$ a convolution operator (with stride $1$) \n%and padding:\n$$\n\\theta: \\mathbb{R}^{m\\times n\\times c} \\mapsto \\mathbb{R}^{m\\times n \\times h},\n$$\nthat can be defined by \n\\begin{equation}\\label{conv-1}\n[\\theta(f)]_{t} = \\sum_i^{c}K_{i,t} \\ast [f]_i + b_t \n\\bm{1}  \\in \\mathbb{R}^{m\\times n}, \\quad t = 1:h,\n\\end{equation}\nwhere $\\bm{1}  \\in \\mathbb{R}^{m\\times n} $ is a \n$m\\times n$ matrix with all elements being $1$,\nand for $g \\in \\mathbb{R}^{m\\times n}$\n\\begin{equation}\\label{con1}\n[K \\ast g]_{i,j} = \\sum_{p,q=-k}^k K_{k+1+p,k+1+q} g_{i + p, j + q}, \\quad i=1:m, j = 1:n.\n\\end{equation}\nThe coefficients in \\eqref{con1} constitute  a kernel matrix\n\\begin{equation}\nK \\in \\mathbb{R}^{(2k+1) \\times (2k+1)},\n\\end{equation}\nwhere $k$ is often taken as small integers. \nHere padding means how choose $ X_{i+ p, j + q}$ \nwhen $(i+ p, j + q)$ is out of $1:m$ or $1:n$. \nThose next three choices are often used\n\\begin{equation}\\label{eq:padding}\nf_{i + p, j + q} = \\begin{cases}\n0,  \\quad &\\text{zero padding}, \\\\\nf_{(i + p)\\pmod{m}, (s + q)\\pmod{n}},  \\quad &\\text{periodic padding}, \\\\\nf_{|i-1 +p|, |j -1  +q|},  \\quad &\\text{reflected padding}, \\\\\n\\end{cases}\n\\end{equation}\nif \n\\begin{equation}\ni + p \\notin \\{1, 2, \\dots, m\\} ~\\text{or} ~  j+ q \\notin \\{1, 2, \\dots, n\\}.\n\\end{equation}\nHere $ d \\pmod m \\in \\{1, \\cdots, m\\} $  means the remainder when $d$ is divided by $m$.\n\n%Then we remark that, if we take convolution without pooling, there is a \n%shift with \n%$$\n%i+ p  \\rightarrow i + k+ p,\n%$$\n%and also for $j$ such that all index $(i + k+ p, j + k+ p)$ is during\n%$1:n$. \n\nIf we formally write \n\\begin{equation}\nf=\n\\begin{pmatrix}\nf_1\\\\\n\\vdots\\\\\nf_c  \n\\end{pmatrix}\n\\end{equation}\nWe can then write the operation \\eqref{conv-1} as\n\\begin{equation}\n\\label{eq:4}\n\\theta(f)=K\\ast f+b\n\\end{equation}\nwhere \n$$\nK=(K_{ij})\\in \\mathbb R^{[(2k+1)\\times(2k+1)]\\times h\\times c}\n$$\nand \n$$\n\\bm{b}=\\bm{1}_{m\\times n}\\otimes b.\n$$\n\nThe operation \\eqref{eq:4} is also called a convolution with stride 1. More generally, \ngiven an integer $s\\ge1$, a convolution with stride $s$ for $f \\in \\mathbb{R}^{m\\times\n\tn}$ is defined as:\n\\begin{equation}\\label{stride}\n[K \\ast_s f]_{i,j} = \\sum_{p,q=-k}^k K_{p,q} f_{s(i-1)+1 + p, s(j-1)+1 + q},  \n\\quad i = 1: \\lceil  \\frac{m}{s}\\rceil , j = 1: \\lceil  \\frac{n}{s}\\rceil.\n\\end{equation}\nHere $ \\lceil  \\frac{m}{s}\\rceil$ denotes the smallest integer that greater than $\\frac{m}{s}$.\nIn CNN, we often take $s=2$.\n\n\n\\subsection{Some linear and nonlinear mappings and extractors}\nA data-feature map $A$ and feacture extractor $B$ can be either\nlinear or nonlinear.   The nonlinearity can be obtained from\nappropriate application of an activation function\n\\begin{equation}\n\\label{act}\n\\sigma: \\mathbb{R} \\to \\mathbb{R} .\n\\end{equation}\nIn this paper, we mainly consider a special activation function, known \nas the {\\it rectified linear unit} (ReLU), which is defined by\n\\begin{equation}\n\\label{relu}\n\\sigma(x)= {\\rm ReLU}(x) :=\\max(0,x), \\quad x\\in\\mathbb{R}. \n\\end{equation}\nBy applying the function to each component, we can extend this\n\\begin{equation}\n\\label{vector-act}\n\\sigma:\\mathbb R^{m\\times n\\times c}\\mapsto \\mathbb R^{m\\times n\\times c}.  \n\\end{equation}\n\n\nA linear data-feature mapping can simply given by a convolution as in \\eqref{con1}:\n\\begin{equation}\n\\label{linearA}\nA(f)=\\xi\\ast f\n\\end{equation}\nA nonlinear mapping can be given by compositions of convolution and\nactivation functions:\n\\begin{equation}\n\\label{nonlinearA}\nA=\\xi\\circ\\sigma\\circ\\eta ,\n\\end{equation}\n\nand \n\\begin{equation}\n\\label{extractor}\nB=\\sigma\\circ \\gamma \\circ\\sigma  .\n\\end{equation}\nHere $\\xi$, $\\eta$ and $\\gamma$ are all \nappropriate convolution mappings.\n\n\n\\subsection{An iterative feacture extraction scheme}\nOne key idea in this paper is that we use a simple iterative\nprocess to approximately solve \\eqref{Auf} using \\eqref{vBf}. Namely,\nfor $i=1:\\nu$\n\\begin{equation}\\label{eq:smoothB}\nu^{i} = u^{i-1} + B^{i}(f- A(u^{i-1})) \n\\end{equation}\nfor an appropriately chosen $u^0$.  We refer to \\cite{xu1992iterative}\nfor more discussion on iterative scheme in the form of \\eqref{eq:smoothB}.\n\n\n\n\\section{Piecewise (bi-)linear functions on multilevel grids}\\label{sec:functions}\nAn image can be viewed as a function on a grid.  Images\nwith different resolutions can then be viewed as functions on grids of\ndifferent sizes.  The use of such multiple-grids is a main technique\nused in the standard multigrid method for solving discretized partial\ndifferential equations \\cite{xu1992iterative, xu2002method}, \nand it can also be interpreted as a main ingredient used in\nconvolutional neural networks (CNN). \n\nWithout loss of generality, for simplicity, we assume that the initial\ngrid, $\\mathcal T$, is of size\n$$\nm=2^{s}+1, n=2^{t}+1 \n$$\nfor some integers $s, t\\ge 1$.\nStarting from $\\mathcal T_1=\\mathcal T$,  we consider a sequence of\ncoarse grids (as depicted in Fig.~\\ref{mgrid} with $J=4$):\n\\begin{equation}\n\\label{grids}\n\\mathcal T_1, \\mathcal T_2, \\ldots, \\mathcal T_J\n\\end{equation}\nsuch that ${\\mathcal T}_\\ell$ consist of $m_\\ell\\times n_\\ell$ grid\npoints, with \n\\begin{equation}\n\\label{mn-ell}\nm_\\ell=2^{s-\\ell+1}+1, n_\\ell=2^{t-\\ell+1}+1.   \n\\end{equation}\n\\begin{figure}[!htbp]\\label{mgrid}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.15\\textwidth]{grid2.png} \\quad \n\t\t\\includegraphics[width=0.15\\textwidth]{grid1.png} \\quad \n\t\t\\includegraphics[width=0.15\\textwidth]{grid0.png} \\quad \n\t\t\\includegraphics[width=0.15\\textwidth]{grid.png} \n\t\\end{center}\n\t$$ \n\t\\mathcal T_1\\hskip1in \\mathcal T_2\\hskip1in \\mathcal T_3\\hskip1in\\mathcal T_4\n\t$$\n\t\\caption{multilevel grids for piecewise linear functions}\n\\end{figure}\n\nThe grid points of these grids can be given by\n$$\nx_i^{\\ell}=i h_{1,\\ell}, y_j^{\\ell}=j h_{2,\\ell},  i=1, \\ldots, m_\\ell,\nj=1, \\ldots, n_\\ell.\n$$\nHere $h_{1,\\ell} = 2^{-s + \\ell -1}a$ and $h_{2,\\ell} = 2^{-t + \\ell - 1}b$,\nfor some $a,b >0$. The above geometric coordinates $(x_i^\\ell, y_i^\\ell)$\nare usually not used in image precess literatures, but they are relevant\nin the context of multigrid method for numerical solution of PDEs.\nWe now consider piecewise linear functions on the sequence of grids\n\\eqref{grids} and we obtain a nested sequence of linear vector spaces\n\\begin{equation}\n\\label{Vk}\n\\mathcal V_1\\supset\\mathcal V_2\\supset\\ldots\\supset \\mathcal\nV_J.\n\\end{equation}\nHere each $\\mathcal V_\\ell$ consists of all piecewise bilinear (or linear)\nfunctions with respect to the grid \\eqref{grids} and \\eqref{mn-ell}.\nEach $\\mathcal V_\\ell $ has a set of basis functions:\n$\\phi_{ij}^\\ell\\in \\mathcal V_\\ell$ satisfying:\n$$\n\\phi_{ij}^\\ell(x_p,y_q)=\\delta_{(i,j), (p,q)} = \n\\begin{cases}\n1 \\quad &\\text{if} \\quad (p,q) = (i,j), \\\\\n0 \\quad &{\\text{if}} \\quad (p,q)\\neq (i,j).\n\\end{cases}\n$$\nThus, for each $v \\in \\mathcal V_{\\ell}$, we have \n\\begin{equation}\\label{expand}\nv(x,y)=\\sum_{i,j}v^\\ell_{ij}\\phi_{ij}^\\ell(x,y).\n\\end{equation}\n\\subsection{Prolongation}\nGiven a piecewise (bi-)linear function $\\bm v\\in\\mathcal V_{\\ell+1}$, the\nnodal values of $\\bm v$ on $m_{\\ell+1}\\times n_{\\ell+1}$ grids point\nconstitute a tensor\n$$\nv^{\\ell+1}\\in \\mathbb R^{m_{\\ell+1}\\times n_{\\ell+1}}.\n$$\nWe note that $\\bm v\\in\\mathcal V_{\\ell}$ thanks to \\eqref{Vk} and the\nnodal values of $\\bm v$ on $\\mathcal T_\\ell$ \nconstitute a tensor\n$$\nv^{\\ell}\\in \\mathbb R^{m_{\\ell}\\times n_{\\ell}}.\n$$\nUsing the property of piecewise (bi-)linear functions, it is easy to see that \n\\begin{equation}\n\\label{eq:13}\nv^{\\ell}=\\bar P_{\\ell+1}^\\ell v^{\\ell+1}  \n\\end{equation}\nwhere \n\\begin{equation}\n\\label{mg-prolong}\n\\bar P_{\\ell+1}^\\ell: \\mathbb R^{m_{\\ell+1}\\times n_{\\ell+1}}\\mapsto  \\mathbb R^{m_{\\ell}\\times n_{\\ell}}  \n\\end{equation}\nwhich is called a prolongation in multigrid terminology.  More\nspecifically, \n\\begin{equation}\n\\label{eq:7}\nv^{\\ell}_{2i-1,2j-1}=  v^{\\ell+1}_{i,j},\n\\end{equation}\nwith \n\\begin{equation}\n\\label{eq:9}\nv^{\\ell}_{2i-1, 2j} = \\frac{1}{2}(v^{\\ell+1}_{i,j} + v^{\\ell+1}_{i,j+1}), \\quad \nv^{\\ell}_{2i, 2j-1} = \\frac{1}{2}(v^{\\ell+1}_{i,j} + v^{\\ell+1}_{i+1,j}),\n\\end{equation}\nand\n\\begin{equation}\n%\\begin{tiny}\n%{\\scriptsize \nv^{\\ell}_{2i, 2j}  =  \n\\begin{cases}\n\\frac{1}{4}(v^{\\ell+1}_{i,j} + v^{\\ell+1}_{i+1,j} + v^{\\ell+1}_{i,j+1} + v^{\\ell+1}_{i+1,j+1}),  &\\text{if $v^\\ell$ is piecewise bilinear }, \\\\\n\\frac{1}{2}( v^{\\ell+1}_{i+1,j} + v^{\\ell+1}_{i,j+1}), &\\text{if $v^\\ell$ is piecewise linear }.\n\\end{cases}\n%\\end{tiny}\n%}\n\\end{equation}\n%when\n%\\begin{description}\n%\\item[$v^\\ell$ is piecewise bilinear] \n%\\begin{equation}\n%\\label{eq:pro-bilinear}\n%v^{\\ell}_{2i, 2j} = \\frac{1}{4}(v^{\\ell+1}_{i,j} + v^{\\ell+1}_{i+1,j} + v^{\\ell+1}_{i,j+1} + v^{\\ell+1}_{i+1,j+1}),\n%\\end{equation}\n%\\item[$v^\\ell$ is piecewise linear] \n%\\begin{equation}\n%\\label{eq:pro-linear}\n%v^{\\ell}_{2i, 2j} = \\frac{1}{2}( v^{\\ell+1}_{i+1,j} + v^{\\ell+1}_{i,j+1}).\n%\\end{equation}\n%\\end{description}\n\n\\subsection{Pooling, restriction and interpolation}\\label{sec:cnn-restriction}\nThe prolongation given by \\eqref{mg-prolong} can be used to transfer\nfeature from a coarse grid to a fine grid.   \nOn the other hand, we also\nneed a mapping, known as restriction,  that transfer data from fine grid to corse grid:\n\\begin{equation}\n\\label{mg-restrict}\n\\bar R_\\ell^{\\ell+1}: \\mathbb R^{m_{\\ell}\\times n_{\\ell}}  \\mapsto  \\mathbb R^{m_{\\ell+1}\\times n_{\\ell+1}}.\n\\end{equation}\n%This operation can often be obtained by two different steps. \n%First, we carry out a convolution operation $\\tilde R: \\mathbb R^{n_\\ell\\times n_\\ell}\\mapsto \n%\\mathbb R^{n_\\ell\\times n_\\ell}$:\n%\\begin{equation}\n%\\label{linear-restriction}\n%\\begin{aligned}\n%(\\tilde Rr)_{i,j}&=r_{i,j} +{1\\over 2}(r_{i,j-1} + r_{i,j+1} + r_{i-1,j} + r_{i+1,j} + r_{i+1,j-1} + r_{i-1,j+1}) ,\n%\\end{aligned}\n%\\end{equation}\n%Then, we define\n%\\begin{equation}\n%\\label{linear-restriction-stride}\n%(Rr)_{i,j}=(\\tilde R r)_{2i-1,2j-1}, \\quad 1\\le i, j \\le n_{\\ell+1}.\n%\\end{equation}\n%%Using the terminology from deep learning \\cite{goodfellow2017deep}, \n%As the definition in above section,\n%we note that \\eqref{linear-restriction} and \\eqref{linear-restriction-stride} can be written as a\n%convolution with a $3\\times3$ kernel with stride 2:\n%\\begin{equation}\\label{eq:restriction}\n%Rr=K\\ast_2 r,\\quad K=\\left ( \\begin{array}{ccc}\n%0 &\\frac{1}{2}&\\frac{1}{2}\\\\\n%\\frac{1}{2}& 1&\\frac{1}{2}\\\\\n%\\frac{1}{2}&\\frac{1}{2}& 0\n%\\end{array}\\right ).\n%\\end{equation}\nIn multigrid for solving discretized partial differential equation,\nthe restriction is often taken to be transpose of the prolongation\ngiven by \\eqref{mg-prolong}:\n\\begin{equation}\n\\label{mg-RP}\n\\bar R_\\ell^{\\ell+1} = [\\bar P_{\\ell+1}^\\ell]^T.  \n\\end{equation}\n\\begin{lemma}\n\tIf $\\tilde P_{\\ell+1}^\\ell$ takes the form of prolongation\n\tin multigrid methods for linear finite element functions \n\ton the above grids, then $\\tilde R_{\\ell}^{\\ell+1}$ is \n\ta convolution with stride $2$ and a $3\\times3$\n\tkernel as:\n\t\\begin{equation}\\label{restriction}\n\tR_\\ell^{\\ell+1} f=K_R\\ast_2 f,\n\t\\end{equation} \n\twhere, if $\\mathcal V_\\ell$ is piecewise bilinears, \n\t\\begin{equation}\\label{bi-restrict}\n\tK_R=\n\t\\begin{pmatrix}\n\t\\frac{1}{4} &\\frac{1}{2}&\\frac{1}{4}\\\\\n\t\\frac{1}{2}& 1&\\frac{1}{2}\\\\\n\t\\frac{1}{4}&\\frac{1}{2}&  \\frac{1}{4} \n\t\\end{pmatrix},\n\t\\end{equation}\n\tor, if $\\mathcal V_\\ell$ is piecewise linears, \n\t\\begin{equation}\n\t\\label{linear-restrict}\n\tK_R=\n\t\\begin{pmatrix}\n\t0 &\\frac{1}{2}&\\frac{1}{2}\\\\\n\t\\frac{1}{2}& 1&\\frac{1}{2}\\\\\n\t\\frac{1}{2}&\\frac{1}{2}&  0\n\t\\end{pmatrix}.\n\t\\end{equation}\n\\end{lemma} \nIn addition, all these convolutions are applied with zero padding as in \\eqref{eq:padding}\n, which is consistent with the Neumann boundary condition for applying FEM to \nnumerical PDEs. More details will be discussed in \\S \\ref{sec:cnn-restriction}.\n\nIn the deep learning literature, the restriction such as\n\\eqref{mg-restrict} is often known as pooling operation.  One popular\npooling is a convolution with stride $s$, with some small integer $s>1$.  \n\nSome other fixed (or untrained) poolings are also often used.  \nOne popular pooling is the so called average pooling $R_{avr}$ which\ncan be a convolution with stride $2$ or bigger using the  kernel $K$\nin the form of\n\\begin{equation}\n\\label{average-K}\nK=\n\\frac{1}{9}\\begin{pmatrix}\n1 & 1 & 1 \\\\\n1 & 1 & 1 \\\\\n1 & 1 & 1\n\\end{pmatrix}. \n\\end{equation}\nNonlinear pooling operator is also used, for the example the $(2k+1)\n\\times (2k+1)$ max-pooling operator with stride $s$ as follows:\n\\begin{equation}\n[{R}_{\\rm max}(f)]_{i,j} = \\max_{-k\\le p ,q\\le k} \\{f_{s(i-1)+1 + p, s(j-1)+1 +q} \\}.\n\\end{equation}\n\nAnother approach to the construction of restriction of pooling can be \nobtained by using interpolation. \nGiven \n$$\nv^\\ell\\in \\mathbb \\mathbb R^{m_{\\ell}\\times n_{\\ell}}, \n$$\nlet $\\bm v\\in \\mathcal V_\\ell$ be the function whose nodal values are\nprecisely give by $v^\\ell$ as in \\eqref{expand}.  \nAny reasonable linear operator\n\\begin{equation}\n\\label{eq:11}\n\\Pi:  \\mathcal V_\\ell\\mapsto \\mathcal V_{\\ell+1},\n\\end{equation}\nsuch as: \nnodal value interpolation, \nScott-Zhang interpolation and\n$L^2$ projection \\cite{xu2019FEM},\nwould give rise to a mapping\n\\begin{equation}\n\\label{mg-Pi}\n\\Pi_\\ell^{\\ell+1}: \\mathbb R^{m_{\\ell}\\times n_{\\ell}}  \\mapsto\n\\mathbb R^{m_{\\ell+1}\\times n_{\\ell+1}},\n\\end{equation}\nsuch that\n$$\nv^{\\ell+1}=\\Pi_\\ell^{\\ell+1} v^\\ell.\n$$\nAs situations permit, we can use these a priori given restrictions to replace\nunknown pooling operators to reduce the number of parameters.\n\n\n\n\n\n", "meta": {"hexsha": "71447b419f9c6eb42cbd6a7c815104ca50f41186", "size": 20365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/CNNintro.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/CNNintro.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/CNNintro.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7168874172, "max_line_length": 143, "alphanum_fraction": 0.6928553891, "num_tokens": 7229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7341411330536451}}
{"text": "\\section{Derivation of Elasticity Equation}\n\nFor completeness we start our discussing of the governing equations\nwith a derivation of the elasticity equation. Consider domain $\\Omega$\nbounded by boundary $\\Gamma$. Applying a Lagrangian description of the\nconservation of momentum gives\n\\begin{equation}\n\\label{eqn:momentum:vec}\n\\frac{\\partial}{\\partial t}\\int_{\\Omega}\\rho(\\vec{x})\\frac{\\partial\\vec{u}}{\\partial t}\\, d\\Omega=\\int_{\\Omega}\\vec{f}(\\vec{x},t)\\, d\\ + \\int_{\\Gamma}\\vec{\\tau}(\\vec{x},t)\\, d\\Gamma.\n\\end{equation}\nThe traction vector field is related to the stress tensor through\n\\begin{equation}\n\\vec{\\tau}(\\vec{x},t) = \\tensor{\\sigma}(\\vec{u}) \\cdot \\vec{n},\n\\end{equation}\nwhere $\\vec{n}$ is the outward normal vector to $\\Gamma$. Substituting\ninto equation \\vref{eqn:momentum:vec} yields\n\\begin{equation}\n\\frac{\\partial}{\\partial t}\\int_{\\Omega}\\rho(\\vec{x})\\frac{\\partial\\vec{u}}{\\partial t}\\, d\\Omega=\\int_{\\Omega}\\vec{f}(\\vec{x},t)\\, d\\Omega+\\int_{\\Gamma}\\tensor{\\sigma}(\\vec{u})\\cdot\\vec{n}\\, d\\Gamma.\n\\end{equation}\nApplying the divergence theorem,\n\\begin{equation}\n\\int_{\\Omega}\\tensor{\\nabla}\\cdot\\vec{a}\\: d\\Omega=\\int_{\\Gamma}\\vec{a}\\cdot\\vec{n}\\: d\\Gamma,\n\\end{equation}\nto the boundary integral results in\n\\begin{equation}\n\\frac{\\partial}{\\partial t}\\int_{\\Omega}\\rho(\\vec{x})\\frac{\\partial\\vec{u}}{\\partial t}\\, d\\Omega=\\int_{\\Omega}\\vec{f}(\\vec{x},t)\\, d\\Omega+\\int_{\\Omega}\\tensor{\\nabla}\\cdot\\tensor{\\sigma}(\\vec{u})\\, d\\Omega,\n\\end{equation}\nwhich we can rewrite as\n\\begin{equation}\n\\int_{\\Omega}\\left(\\rho(\\vec{x})\\frac{\\partial^{2}\\vec{u}}{\\partial t^{2}}-\\vec{f}(\\vec{x},t)-\\tensor{\\nabla}\\cdot\\tensor{\\sigma}(\\vec{u})\\right)\\, d\\Omega=\\vec{0}.\n\\end{equation}\nBecause the domain $\\Omega$ is arbitrary, the integrand must be the zero\nvector at every location in the domain, so that we end up with\n\\begin{gather}\n\\rho(\\vec{x})\\frac{\\partial^{2}\\vec{u}}{\\partial t^{2}}-\\vec{f}(\\vec{x},t)-\\tensor{\\nabla}\\cdot\\tensor{\\sigma}=\\vec{0}\\text{ in }\\Omega,\\\\\n\\tensor{\\sigma}(\\vec{u})\\cdot\\vec{n}=\\vec{\\tau}(\\vec{x},t)\\text{ on }\\Gamma_{\\tau}\\text{,}\\\\\n\\vec{u}=\\vec{u}_0(\\vec{x},t)\\text{ on }\\Gamma_{u},\\text{ and}\\\\\n\\vec{u}^{+}-\\vec{u}^{-}=\\vec{d}\\text{ on }\\Gamma_{f}.\n\\end{gather}\nWe specify tractions, $\\vec{\\tau}$, on boundary $\\Gamma_{f}$, displacements,\n$\\vec{u^{o}}$, on boundary $\\Gamma_{u}$, and slip, $\\vec{d}$,\non fault interface $\\Gamma_{f}$.\n%(we will consider the case of fault constitutive models in Section \\vref{sec:fault}).\n", "meta": {"hexsha": "aa38b9740ad3122007a4350eae217db1ed1b48ec", "size": 2468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/userguide/governingeqns/elasticity_derivation.tex", "max_stars_repo_name": "Grant-Block/pylith", "max_stars_repo_head_hexsha": "f6338261b17551eba879da998a5aaf2d91f5f658", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 93, "max_stars_repo_stars_event_min_datetime": "2015-01-08T16:41:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T13:40:02.000Z", "max_issues_repo_path": "doc/userguide/governingeqns/elasticity_derivation.tex", "max_issues_repo_name": "Grant-Block/pylith", "max_issues_repo_head_hexsha": "f6338261b17551eba879da998a5aaf2d91f5f658", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 277, "max_issues_repo_issues_event_min_datetime": "2015-02-20T16:27:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T21:13:09.000Z", "max_forks_repo_path": "doc/userguide/governingeqns/elasticity_derivation.tex", "max_forks_repo_name": "Grant-Block/pylith", "max_forks_repo_head_hexsha": "f6338261b17551eba879da998a5aaf2d91f5f658", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 71, "max_forks_repo_forks_event_min_datetime": "2015-03-24T12:11:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T04:26:02.000Z", "avg_line_length": 56.0909090909, "max_line_length": 208, "alphanum_fraction": 0.6803079417, "num_tokens": 868, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.8289388167733099, "lm_q1q2_score": 0.7341343110085676}}
{"text": "\\section{Differentiation}\r\n\\begin{definition}\r\n    Fix $m,n\\in\\mathbb N$, let $L(\\mathbb R^m,\\mathbb R^n)$ be the set of linear maps to $\\mathbb R^m$ to $\\mathbb R^n$.\r\n    Note that this space is isomorphic to $\\mathbb R^{mn}$, both algebraicly and topologically, as we have the metric\r\n    $$\\forall T\\in L(\\mathbb R^m,\\mathbb R^n),\\|T\\|=\\sqrt{\\sum_{i=1}^m\\sum_{j=1}^n|T_{ij}|^2}=\\sqrt{\\sum_{i=1}^m\\|T{e_i}\\|^2}$$\r\n\\end{definition}\r\n\\begin{lemma}\\label{mat_norm}\r\n    (a) Given a linear map $T$, for every $x\\in\\mathbb R^m$, we have $\\forall x\\in\\mathbb R^m,\\|Tx\\|\\le \\|T\\|\\|x\\|$.\r\n    So $T$ is Lipschitz hence continuous.\\\\\r\n    (b) For $S\\in L(\\mathbb R^m,\\mathbb R^n),T\\in L(\\mathbb R^n,\\mathbb R^p)$, $\\|TS\\|\\le \\|T\\|\\|S\\|$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    (a) If $x=\\sum_ix_ie_i$, then\r\n    $$\\|Tx\\|=\\left\\|\\sum_{i=1}^mx_iTe_i\\right\\|\\le \\sum_{i=1}^m|x_i|\\|Te_i\\|\\le \\sqrt{\\sum_{i=1}^m|x_i|^2}\\sqrt{\\sum_{i=1}^m\\|Te_i\\|^2}=\\|x\\|\\|T\\|$$\r\n    (b) We have\r\n    $$\\|TS\\|=\\sqrt{\\sum_{i=1}^m\\|TSe_i\\|^2}\\le \\sqrt{\\sum_{i=1}^m\\|T\\|^2\\|Se_i\\|^2}=\\|T\\|\\|S\\|$$\r\n    As desired.\r\n\\end{proof}\r\nRecall that a function $f:\\mathbb R\\to\\mathbb R$ is differentiable at $a$ if $\\lim_{h\\to 0}(f(a+h)-f(a))/h$ exists.\r\nSo let $\\epsilon(h)=(f(a+h)-f(a))/h-f^\\prime(a)$, then $f(a+h)=f(a)+f^\\prime(a)h+\\epsilon(h)h$ and $\\epsilon\\to 0$ as $h\\to 0$.\r\nWe can think of this as $\\epsilon(0)=0$ and $\\epsilon$ is continuous at $0$.\r\nSo we want to use it to define differentiation in higher dimensions.\r\n\\begin{definition}\r\n    Given $m,n\\in\\mathbb N$ and an open set $U\\subset\\mathbb R^m$, a function $f:U\\to\\mathbb R^n$ and $a\\in U$.\r\n    We say $f$ is differentiable at $a$ if there is a linear map $T:\\mathbb R^m\\to\\mathbb R^n$ and a function $\\epsilon:\\{h\\in\\mathbb R^m:a+h\\in U\\}\\to\\mathbb R^n$ such that\r\n    $$f(a+h)=f(a)+T(h)h+\\epsilon(h)\\|h\\|$$\r\n    where $\\epsilon\\to 0$ as $h\\to 0$. (Or $\\epsilon(0)=0$ and $\\epsilon$ is continuous ar $0$).\r\n\\end{definition}\r\n\\begin{remark}\r\n    $$\\epsilon(h)=\r\n    \\begin{cases}\r\n        0\\text{, if $h=0$}\\\\\r\n        \\frac{f(a+h)-f(a)-T(h)}{\\|h\\|}\\text{, if $h\\neq 0$ and $a+h\\in U$}\r\n    \\end{cases}$$\r\n\\end{remark}\r\nSince $U$ is open, $\\exists r>0, D_r(a)\\subset U$, so $D_r(a)\\subset \\operatorname{Dom}\\epsilon$.\r\nNote also that our condition on $\\epsilon$ is also equivalent to say $\\epsilon(h)\\|h\\|=o(\\|h\\|)$ as $h\\to 0$.\\\\\r\nNext, we observe that $T$ (if it exists) is unique.\r\nIndeed, if both $T,S$ satisfies our condition, then $(S(h)-T(h))/\\|h\\|\\to 0$ as $h\\to 0$, so by choosing $h=x/n$ for $n\\in\\mathbb N$ we have $S=T$.\r\n\\begin{definition}\r\n    This unique $T$ is called the derivative of $f$ at $a$, denoted by $f^\\prime(a)$ or $Df(a)$ or $Df|_a$, so\r\n    $$f(a+h)=f(a)+f^\\prime(a)(h)+o(\\|h\\|)$$\r\n\\end{definition}\r\n\\begin{definition}\r\n    We say $f$ is differentiable at $U$ if it is differentiable at $a$ for every $a\\in U$.\r\n    So the derivative of $f$ on $U$ is the map $f^\\prime:U\\to L(\\mathbb R^m,\\mathbb R^n)$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    When $m=1$, $T$ is a linear map $\\mathbb R\\to\\mathbb R^n$, so for $T\\in L(\\mathbb R^m,\\mathbb R^n)$, so b y setting $v=T(1)$, so $\\forall x\\in\\mathbb R,T(x)=xv$.\r\n    Indeed, $L(\\mathbb R,\\mathbb R^n)\\cong\\mathbb R^n$ by $T\\mapsto T(1)$.\r\n    Hence for open $U\\subset\\mathbb R,f:U\\to\\mathbb R^n,a\\in U$, we have $f$ is differentiable at $a$ if and only if there is some $v\\in\\mathbb R^n$ with $f(a+h)=f(a)+hv+o(h)$.\r\n    So $v=f^\\prime(a)$.\r\n\\end{remark}\r\n\\begin{example}\r\n    1. Every constant function is differentiable as we can take $f^\\prime(a)\\equiv 0\\in L(\\mathbb R^m,\\mathbb R^n)$.\r\n    2. Every linear map $f$ is differentiable by taking $f'(a)=f\\in L(\\mathbb R^m,\\mathbb R^n)$. for every $a$.\\\\\r\n    3. Any bilinear map $f:\\mathbb R^m\\times\\mathbb R^n\\to\\mathbb R^p$ is differentiable.\r\n    Indeed, we have\r\n    $$f((a,b)+(h,k))=f(a+b,h+k)=f(a,b)+f(a,k)+f(h,b)+f(h,k)$$\r\n    Note that $f(a,k)+f(h,b)$ is linear in $(h,k)$, therefore it remains to checl $f(h,k)=o(\\|h\\|)$.\r\n    We see\r\n    \\begin{align*}\r\n        \\|f(h,k)\\|&=\\left\\|f\\left( \\sum_{i=1}^mh_ie_i, \\sum_{j=1}^nk_je_j\\right)\\right\\|\\\\\r\n        &\\le \\sum_{i,j}|h_i||k_j|\\|f(e_i,e_j)\\|\\\\\r\n        &\\le \\|(h,k)\\|^2\\sum_{i,j}\\|f(e_i,e_j)\\|\\\\\r\n        &=O(\\|(h,k)\\|^2)=o(\\|(h,k)\\|)\r\n    \\end{align*}\r\n    4. Take $f:\\mathbb R^n\\to\\mathbb R$ by $f(x)=\\|x\\|^2$, so\r\n    $$f(a+h)=\\|a+h\\|^2=\\|a\\|^2+2\\langle a,h\\rangle+\\|h\\|^2=f(a)+2\\langle a,h\\rangle+o(\\|h\\|)$$\r\n    So we can have $f^\\prime(a)(h)=2\\langle a,h\\rangle$.\\\\\r\n    5. Let $M_n\\cong L(\\mathbb R^n,\\mathbb R^n)$ be the collection of all $n\\times n$ real matrices.\r\n    Consider $f:M_n\\to M_n, A\\mapsto A^2$, so\r\n    $$f(A+H)=A^2+AH+HA+H^2=f(A)+AH+HA+o(\\|H\\|)$$\r\n    due to Lemma \\ref{mat_norm}.\r\n    So $f^\\prime(A)(H)=AH+HA$.\r\n\\end{example}\r\n\\begin{proposition}\r\n    Differentiablility implies continuity.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Write $f(a+h)=f(a)+f^\\prime(a)(h)+\\epsilon(h)\\|h\\|$ where $\\epsilon(0)=0$ and $\\epsilon$ is continuous at $0$.\r\n    $f^\\prime(a)$ is continuous by Lemma \\ref{mat_norm} (which implies every linear map is continuous), so the RHS is continuous in $h$, therefore $h\\mapsto f(a+h)$ is continuous at $h=0$, hence $f$ is continuous at $a$.\r\n\\end{proof}\r\n\\begin{proposition}[Chain Rule]\r\n    Consider open $U\\in\\mathbb R^m,V\\in\\mathbb R^n$ and functions $f:U\\to\\mathbb R^n,g:V\\to\\mathbb R^m$ and $f(U)\\subset V$.\r\n    If $f$ is differentiable at $a$ and $g$ is differentiable at $f(a)$, then $g\\circ f$ is differentiable at $a$ and $(g\\circ f)^\\prime(a)=g^\\prime(f(a))\\circ f^\\prime(a)$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Let $b=f(a)$ and $S=f^\\prime(a),T=g^\\prime(b)$, then\r\n    $$\r\n    \\begin{cases}\r\n        f(a+h)=f(a)+S(h)+\\epsilon(h)\\|h\\|\\\\\r\n        g(b+k)=g(b)+T(k)+\\delta(k)\\|k\\|\r\n    \\end{cases}\r\n    $$\r\n    Where $\\epsilon(0)=0,\\delta(0)=0$ and both of them are continuous at $0$.\r\n    So \r\n    $$(g\\circ f)(a)=g(b+S(h)+\\epsilon(h)\\|h\\|)$$\r\n    Let $k(h)=S(h)+\\epsilon(h)\\|h\\|$, so it equals\r\n    \\begin{align*}\r\n        g(b)+T(k)+\\delta(k)\\|k\\|&=(g\\circ f)(a)+T\\circ S(h)\\\\\r\n        &+\\|h\\|T(\\delta(h))+\\delta(k(h))\\|S(h)+\\delta(h)\\|h\\|\\|\r\n    \\end{align*}\r\n    Due to continuity of $\\epsilon,\\delta$ are continuous at $0$, $\\|h\\|T(\\delta(h))=o(\\|h\\|)$ and $T(\\epsilon(0))=0$, so this term is fine.\\\\\r\n    Also, $\\delta(k(0))=0$ and $\\delta\\circ k$ is continuous at $0$.\r\n    In addition,\r\n    $$0\\le \\frac{\\|S(h)+\\delta(h)\\|h\\|\\|}{\\|h\\|}\\le\\frac{\\|S(h)\\|+\\|\\epsilon(h)\\|\\|h\\|}{\\|h\\|}\\le \\|S\\|+\\|h\\|$$\r\n    by Lemma \\ref{mat_norm}.\r\n    So\r\n    $$\\lim_{h\\to 0}\\frac{\\delta(k(h))\\|S(h)+\\delta(h)\\|h\\|\\|}{\\|h\\|}=0\\implies \\delta(k(h))\\|S(h)+\\delta(h)\\|h\\|\\|=o(\\|h\\|)$$\r\n    Hence $g\\circ f$ is differentiable and its derivative is $T\\circ S=g^\\prime (b)\\circ f^\\prime(a)=g^\\prime (f(a))\\circ f^\\prime(a)$.\r\n\\end{proof}\r\n\\begin{proposition}\\label{component_diff}\r\n    $f:U\\to\\mathbb R^n$ ($U\\in\\mathbb R^m$ is open) is differentiable if and only if each components $f_j=\\pi_j\\circ f$ is differentiable at $a$.\r\n    Also,\r\n    $$f^\\prime(a)(h)=\\sum_{j=1}^nf_j^\\prime(a)(h)e_j'$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Note that $\\pi_j(x)=\\langle x,e_j'\\rangle$ is linear hence differentiable, thus by chain rule the $\\implies$ direction is done.\r\n    For $\\impliedby$, we have for every $j$,\r\n    $$f_j(a+h)=f_j(a)+f^\\prime(a)(h)+\\epsilon_j(h)\\|h\\|$$\r\n    So\r\n    \\begin{align*}\r\n        f(a+h)&=\\sum_{j=1}^nf_j(a+h)e_j'\\\\\r\n        &=\\sum_{j=1}^n(f_j(a)+f^\\prime(a)(h)+\\epsilon_j(h)\\|h\\|)e_j'\\\\\r\n        &=f(a)+\\left( \\sum_{j=1}^nf_j^\\prime(a)(h)e_j' \\right)+\\left( \\sum_{j=1}^n\\epsilon_j(h)e_j' \\right)\\|h\\|\r\n    \\end{align*}\r\n    Since $\\epsilon(h)=\\sum_{j=1}^n\\epsilon_j(h)e_j'$ has $\\epsilon(0)=0$ and is continuous at $0$, hence the result.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Let $f,g:U\\to\\mathbb R^n$ where $U\\subset\\mathbb R^m$ is open and $\\phi:U\\to\\mathbb R$ is differentiable at $a\\in U$, then so are $f+g$ and $\\phi f:x\\mapsto \\phi(x)f(x)$, and\r\n    $$(f+g)^\\prime(a)=f^\\prime(a)+g^\\prime(a)$$\r\n    $$(\\phi f)^\\prime(a)(h)=\\phi^\\prime(a)(h)f(a)+\\phi(a)f^\\prime(a)(h)$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    We have\r\n    $$f(a+h)=f(a)+f^\\prime(a)(h)+\\epsilon(h)\\|h\\|$$\r\n    $$g(a+h)=g(a)+g^\\prime(a)(h)+\\delta(h)\\|h\\|$$\r\n    $$\\phi(a+h)=\\phi(a)+\\phi^\\prime(a)(h)+\\eta(h)\\|h\\|$$\r\n    Hence\r\n    $$(f+g)(a+h)=(f+g)(a)+(f^\\prime(a)+g^\\prime(a))(h)+(\\epsilon(h)+\\delta(h))\\|h\\|$$\r\n    We can do the same thing for products as well which will provide a proof, but we shall give a different proof.\r\n    Let $F:U\\to R\\times R^n=R^{n+1}$ by $f(x)=(\\phi(x),f(x))$ and $G:R\\times R^n\\to\\mathbb R^n$ by $(a,x)\\mapsto ax$.\r\n    $F$ is differentiable by Proposition \\ref{component_diff} and $G$ is differentiable since it is bilinear, therefore $\\phi f=G\\circ F$ is differentiable and we can obtain the form of the derivative from the chain rule which is the formula as claimed.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $U\\subset\\mathbb R^m$ be open and $f:U\\to\\mathbb R^n$.\r\n    Fix $a\\in U$ and a direction (nonzero vector) $u\\in\\mathbb R^m\\setminus\\{0\\}$.\r\n    The limit\r\n    $$\\lim_{t\\to 0}\\frac{f(a+tu)-f(a)}{t}$$\r\n    if exists, is called the directional derivative of $f$ at $a$ to direction $u$ and is denoted by $D_uf(a)$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    1. $f(a+tu)=f(a)+tD_uf(a)+o(t)$.\\\\\r\n    2. Let $\\gamma(t)=a+tu$, then $(f\\circ\\gamma)^\\prime(0)=D_uf(0)$.\r\n\\end{remark}\r\nIn the special case where $u=e_i$, we write $D_if(a)$ to denote $D_{e_i}f(a)$ and it is called the $i^{th}$ partial derivative of $f$ at $a$.\r\n\\begin{proposition}\r\n    If $f$ is differentiable at $a$, then all $D_uf(a)$ exists and we have $D_uf(a)=f^\\prime(a)(u)$, so for $h=\\sum_ih_ie_i$, we have\r\n    $$f^\\prime(a)(h)=\\sum_ih_iD_if(a)$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    We have\r\n    $$f(a+h)=f(a)+f^\\prime(a)(h)+\\epsilon(h)\\|h\\|$$\r\n    Then\r\n    $$\\frac{f(a+tu)-f(a)}{t}=f^\\prime(a)(u)+\\epsilon(tu)\\frac{\\|t\\|}{t}\\to f^\\prime(a)(u)$$\r\n    As $t\\to 0$.\r\n    The rest follows.\r\n\\end{proof}\r\n\\begin{remark}\r\n    1. Assume $f$ is differentiable at $a$, then the matrix of $f^\\prime(a)$ is exactly represented by $(f^\\prime(a))_{ji}=D_if_j(a)=(\\partial f_j/\\partial x_i)(a)$.\r\n    This is called the Jacobian of $f$ at $a$, denoted by $Jf(a)$.\\\\\r\n    2. If all partial derivatives exists, so does $D_uf_j(a),\\forall j$, and we have $D_uf_j(a)=\\pi_j(D_uf(a))$\r\n    So $D_u\\pi_j=\\pi_jD_u$.\\\\\r\n    3. The converse of the proposition fails in general.\r\n\\end{remark}\r\n\\begin{theorem}\r\n    If all partial derivatives of $f$ exists at $a\\in U$.\r\n    Assume $\\exists r>0,D_r(a)\\in U$ and $D_if$ exists in $D_r(a)$ and is continuous at $a$ for all $i$, then $f$ is differentiable at $a$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    WLOG $n=1$ by Proposition \\ref{component_diff} and the second remark above.\r\n    We shall prove the case for $m=2$, and the general case is similar.\r\n    Let $a=(a_1,a_2)$ and consider $h=(h_1,h_2)\\in D_r(0)$.\r\n    Certainly we want the derivative to equal $h_1D_1f(a_1,a_2)+h_2D_2f(a_1,a_2)$, so we will try to prove\r\n    $$f(a_1+h_1,a_2+h_2)-f(a_1,a_2)-h_1D_1f(a_1,a_2)-h_2D_2f(a_1,a_2)=o(\\|h\\|)$$\r\n    Note that we can write it out in two parts\r\n    \\begin{align*}\r\n        &f(a_1+h_1,a_2+h_2)-f(a_1+h_1,a_2)-h_2D_2f(a_1,a_2)\\\\\r\n        &+f(a_1+h_1,a_2)-f(a_1,a_2)-h_1D_1f(a_1,a_2)\r\n    \\end{align*}\r\n    We have $f(a_1+h_1,a_2)-f(a_1,a_2)-h_1D_1f(a_1,a_2)=o(h_1)=o(\\|h\\|)$ as $h\\to 0$.\r\n    As for the first part, let $\\phi(t)=f(a_1+h_1,a_2+t)$ for $t\\in [-|h_2|,|h_2|]$, so we have\r\n    $$f(a_1+h_1,a_2+h_2)-f(a_1+h_1,a_2)-h_2D_2f(a_1,a_2)=\\phi(h_2)-\\phi(0)-h_2D_2f(a_1,a_2)$$\r\n    Note that $\\phi$ is continuous and is differentiable in $(-|h_2|,|h_2|)$.\r\n    Indeed we have $\\phi^\\prime(t)=D_2f(a_1+h_2,a_2+t)$.\r\n    By MVT, there is some $\\theta(h_1,h_2)\\in (0,1)$ such that $\\phi(h_2)-\\phi(0)=\\phi^\\prime(\\theta h_2)h_2$.\r\n    Hence\r\n    \\begin{align*}\r\n        \\phi(h_2)-\\phi(0)-h_2D_2f(a_1,a_2)&=h_2(D_2f(a_1+h_1,a_2+\\theta h_2)-D_2f(a_1,a_2))\\\\\r\n        &=o(h_2)=o(\\|h\\|)\r\n    \\end{align*}\r\n    as $h\\to 0$.\r\n    So the theorem is proved.\r\n\\end{proof}\r\n\\begin{theorem}[Mean Value Inequality]\\label{mean_val_ineq}\r\n    Consider an open $U\\subset \\mathbb R^m$ and a function $f:U\\to\\mathbb R^n$.\r\n    Assume $f$ is differentiable on $U$ and we are given $a,b\\in U$ such that $[a,b]=\\{(1-t)a+tb:t\\in [0,1]\\}\\subset U$ and $\\exists M>0$ such that $\\forall z\\in [a,b],\\|f^\\prime(z)\\|\\le M$, then\r\n    $$\\|f(b)-f(a)\\|\\le M\\|b-a\\|$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $v=f(b)-f(a)$.\r\n    Consider $\\phi:[0,1]\\to\\mathbb R$ defined by $\\phi(t)=\\langle f((1-t)a+tb),v\\rangle$.\r\n    Then $\\phi(1)-\\phi(0)=\\|f(b)-f(a)\\|^2$ and $\\phi$ is differentiable with $\\phi^\\prime(t)=\\langle f^\\prime((1-t)a+tb)(b-a),v\\rangle$.\r\n    By MVT, $\\exists\\theta\\in (0,1)$ with $\\phi(1)-\\phi(0)=\\phi^\\prime(\\theta)$, so we have\r\n    \\begin{align*}\r\n        \\|f(b)-f(a)\\|^2&=\\langle f^\\prime((1-\\theta)a+\\theta b)(b-a),v\\rangle\\\\\r\n        &\\le \\|f^\\prime((1-\\theta)a+\\theta b)(b-a)\\|\\|v\\|\\\\\r\n        &\\le \\|f^\\prime((1-\\theta)a+\\theta b)\\|\\|b-a\\|\\|v\\|\\\\\r\n        &\\le M\\|b-a\\|\\|f(b)-f(a)\\|\r\n    \\end{align*}\r\n    The theorem follows.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Let $U\\subset\\mathbb R^m$ be open and connected, and $f:U\\to\\mathbb R^n$ be differentiable such that $f^\\prime\\equiv 0$, then $f$ is constant.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    We can show that it is locally constant by the preceding theorem, thus it is constant everywhere by connectedness.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Suppose we have open $U\\subset\\mathbb R^m,V\\subset\\mathbb R^n$ and $f:U\\to V$ is a bijection such that $f$ is differentiable at $a\\in U$ and $f^{-1}$ at $f(a)\\in V$.\r\n    Let $S=f^\\prime(a), T=(f^{-1})^\\prime(f(a))$, then $ST=I_n$ and $TS=I_m$.\r\n    $\\operatorname{rank}(I_n)=\\operatorname{rank}(ST)=\\operatorname{rank}(TS)=\\operatorname{rank}(I_m)$, hence $n=m$.\r\n\\end{remark}\r\n\\begin{theorem}[Inverse Function Theorem]\r\n    We have an open set $U\\subset\\mathbb R^n$, a $C^1$ (continuously differentiable) function $f:U\\to\\mathbb R^n$ and a point $a\\in U$ such that $f^\\prime(a)$ is invertible, then there exists open set $V\\subset U,W\\subset\\mathbb R^n$ open such that $a\\in V,f(a)\\in W,f|_{V}:V\\to W$ is a bijection with a $C^1$ inverse $g:W\\to V$ and $\\forall y\\in W,g^\\prime(y)=(f^\\prime(g(y)))^{-1}$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Step 1: WLOG $a=f(a)=0$ and $f^\\prime(a)=I$.\r\n    We can do this because we can consider $h:U-a=\\{x-a:x\\in U\\}\\to\\mathbb R^n$ by $h(x)=(f^\\prime(a))^{-1}(f(x+a)-f(a))$.\r\n    Now we can fix $r>0$ such that $D_r(0)\\subset U$ and $\\forall x\\in D_r(0),\\|f^\\prime(x)-I\\|\\le 1/2$ by continuity.\\\\\r\n    Step 2: $\\forall x,y\\in D_r(0)$, $\\|f(x)-f(y)\\|\\ge \\|x-y\\|/2$, so $f$ is injective.\r\n    To prove this, consider $h(x)=x-f(x)$, then $h^\\prime=I-f^\\prime(x)$, so $\\forall x\\in D_r(0),\\|h^\\prime(x)\\|\\le 1/2$.\r\n    By Theorem \\ref{mean_val_ineq}, $\\|h(x)-h(y)\\|\\le \\|x-y\\|/2$, so\r\n    $$\\frac{\\|x-y\\|}{2}\\ge \\|h(x)-h(y)\\|\\ge \\|x-y\\|-\\|f(x)-f(y)\\|$$\r\n    Step 3: For $0\\le s\\le r/2$, $D_s(0)\\subset f(B_{2s}(0))\\subset f(D_r(0))$.\r\n    Fix $y\\in D_s(0)$, then consider $h:B_{2s}(0)\\to\\mathbb R^n$ by $x\\mapsto y-f(x)+x$.\r\n    We have $h^\\prime(x)=-f^\\prime(x)+I$, so $\\forall x\\in B_{2s}(0),\\|h^\\prime(x)\\|\\le 1/2$, so by Theorem \\ref{mean_val_ineq}, $h$ is $1/2$-Lipschitz.\r\n    Note also that for $x\\in B_{2r}(0)$, then $\\|h(x)\\|=\\|h(x)-h(0)+y\\|\\le \\|x\\|/2+\\|y\\|\\le 2s$, so by Theorem \\ref{banach} there is some $x\\in B_{2r}(0)$ such that $h(x)=x$, which means that $y=f(x)$.\\\\\r\n    Step 4: Fix $0<s<r/2$, then let $W=D_s(0)$ and $V=f^{-1}(D_s(0))\\cap D_r(0)$, so $V$ is open and $f(V)=W$ by step 3 and $f$ is injective by step 2, so $f|_V:V\\to W$ is a bijection.\r\n    Let $f^{-1}=g:W\\to V$ be the inverse, then given $a,b\\in W$, let $x=g(a),y=g(b)$, then $x,y\\in V\\subset D_r(0)$, so by step 2, $\\|f(x)-f(y)\\|\\ge 1/2\\|x-y\\|$, so $g$ is $1/2$-Lipschitz hence continuous.\r\n    Note that if $g$ is differentiable then we have $I=(f\\circ g)^\\prime(y)$ for any $y$, hence by Chain Rule, $g^\\prime(y)=(f^\\prime(g(y)))^{-1}$.\r\n    So we want to show that $g$ has this as derivative.\r\n    Indeed, fix $b\\in W$ and $a=g(b),T=f^\\prime(a)$, we have $f(a+h)=f(a)+T(h)+\\epsilon(h)\\|h\\|$.\r\n    Fix $\\delta>0$ such that $D_\\delta(b)\\in W$ and $k\\in D_\\delta(0)$, by setting $h=h(k)=g(b+k)-g(b)$ we have $k=f(a+h)-f(a)=T(h)+\\epsilon(h)\\|h\\|$, so $h=T^{-1}(k)-T^{-1}(\\epsilon(h))\\|h\\|$, hence\r\n    $$g(b+k)=g(b)+h=g(b)+T^{-1}(k)-T^{-1}(\\epsilon(h))\\|h\\|=g(b)+T^{-1}(k)+o(\\|k\\|)$$\r\n    Hence $g$ is differentiable at $b$ with derivative $T^{-1}=(f^\\prime(g(b)))^{-1}$ which is continuous.\r\n\\end{proof}\r\n\\begin{definition}\r\n    We have open set $U\\subset\\mathbb R^m$, then a function $f:U\\to\\mathbb R^n,a\\in U$ have $f$ twice differentiable at $a$ if there is some open $V$ with $a\\in V\\subset U$ such that $f$ is differentiable in $V$ and the derivative $f^\\prime:V\\to L(\\mathbb R^m,\\mathbb R^n)$ is differentiable.\r\n    $f^{\\prime\\prime}(a)=(f^\\prime)^\\prime(a)$ is called the second derivative of $f$.\r\n\\end{definition}\r\nSo we have $f^{\\prime\\prime}\\in L(\\mathbb R^m,L(\\mathbb R^m,\\mathbb R^n))$ where we have\r\n$$f^\\prime(a+h)=f^\\prime(a)+f^{\\prime\\prime}(a)(h)+\\epsilon(h)\\|h\\|$$\r\nwhere $\\epsilon\\to 0$ as $h\\to 0$.\r\nNote that $\\epsilon(h)\\in L(\\mathbb R^m,\\mathbb R^n)$.\r\nSo $f^\\prime(a+h)(k)=f^\\prime(a)(k)+f^{\\prime\\prime}(a)(h)(k)+\\epsilon(h)(k)\\|h\\|$\r\nfor each fixed $k\\in\\mathbb R^m$.\r\nNote also that $L(\\mathbb R^m,L(\\mathbb R^m,\\mathbb R^n))\\cong \\operatorname{Bil}(\\mathbb R^m\\times\\mathbb R^m,\\mathbb R^n)$ by the correspondence $T\\mapsto B$ with $B(h,k)=T(h)(k)$.\r\nSo we can think of the second derivative at $a$ as a bilinear map $\\mathbb R^m\\times\\mathbb R^m\\to\\mathbb R^n$.\\\\\r\nIn summary, $f$ is twice differentiable at $a$ if and only if there is a bilinear map $B:\\mathbb R^m\\times\\mathbb R^m\\to\\mathbb R^n$ such that for any $k\\in\\mathbb R^m$ we have\r\n$$f^\\prime(a+h)(k)=f^\\prime(a)(h)+B(h,k)+o(\\|h\\|)$$\r\n$B$ here is then the second derivative.\r\n\\begin{example}\r\n    For $f:M_n\\to M_n$ by $A\\mapsto A^3$.\r\n    It is differentiable and $f^\\prime(A)(H)=HA^2+AHA+A^2H$.\r\n    Then to find second derivative by\r\n    \\begin{align*}\r\n        f^\\prime(A+H)(K)&=K(A+H)^2+(A+H)K(A+H)+(A+H)^2K\\\\\r\n        &=f^\\prime(A)(K)\\\\\r\n        &+KAH+KHA+AKH+HKA+AHK+HAK\\\\\r\n        &+o(\\|H\\|^2)\r\n    \\end{align*}\r\n    So the seond derivative is the bilinear map $f^{\\prime\\prime}(A)=B(H,K)=KAH+KHA+AKH+HKA+AHK+HAK$.\r\n\\end{example}\r\nAssume that $f$ has second derivative at $a$ under the usual setup, then\r\n$$f^\\prime(a+h)(k)=f^\\prime(a)(k)+f^{\\prime\\prime}(a)(h,k)+o(\\|h\\|)$$\r\nSo fix $u,v\\in\\mathbb R^m\\setminus\\{0\\}$, by putting $k=v$ we have\r\n$$D_vf(x+h)=D_vf(a)+f^{\\prime\\prime}(h,v)+o(\\|h\\|)$$\r\nSo $D_vf$ is differentiable, therefore we can write\r\n$$D_uD_vf(a)=f^{\\prime\\prime}(a)(u,v)$$\r\n\\begin{theorem}\r\n    Let $U\\subset\\mathbb R^m$ be open and $f:U\\to\\mathbb R^n$ be second differentiable on $U$ with $f^{\\prime\\prime}$ continuous at $a$ for some $a\\in U$, then $f^{\\prime\\prime}(a)$ is a symmetric form, that is, for any $0\\neq u,v\\in\\mathbb R^m$, $D_uD_vf(a)=D_vD_uf(a)$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    WLOG $n=1$ since $(f_j)^{\\prime\\prime}=f^{\\prime\\prime}_j$.\r\n    Define\r\n    \\begin{align*}\r\n        \\phi(s,t)&=f(a+su+tv)-f(a+su)-(f(a+tv)-f(a))\\\\\r\n        &=f(a+su+tv)-f(a+tv)-(f(a+su)-f(a))\r\n    \\end{align*}\r\n    Fix $s,t$, consider $\\Psi(x)=f(a+xu+tv)-f(a+xu)$, so $\\phi(s,t)=\\Psi(s)-\\Psi(0)=s\\Psi^\\prime(\\alpha s)$ where $\\alpha=\\alpha(s,t)\\in (0,1)$.\r\n    So $\\phi(s,t)=(D_uf(a+\\alpha su+tv)-D_uf(a+\\alpha su))s$\r\n    Consider $\\psi(y)=D_uf(a+\\alpha su+yv)$, so $\\phi(s,t)=s(\\psi(t)-\\psi(0))=st\\psi^\\prime(\\beta t),\\beta=\\beta(s,t)\\in (0,1)$.\r\n    So\r\n    \\begin{align*}\r\n        \\frac{\\phi(s,t)}{st}&=D_vD_uf(a+\\alpha su+\\beta tv)\\\\\r\n        &=f^{\\prime\\prime}(a+\\alpha su+\\beta tv)(v,u)\\to f^{\\prime\\prime}(a)(v,u)\r\n    \\end{align*}\r\n    Repeat the process in the other order to get\r\n    $$\\frac{\\phi(s,t)}{st}\\to f^{\\prime\\prime}(a)(u,v)$$\r\n    So they are equal.\r\n\\end{proof}\r\n$U\\subset\\mathbb R^m$ open, $f:U\\to\\mathbb\\mathbb R$, we say $f$ has a local maximum at $a\\in U$ if $\\exists r>0,\\forall b\\in D_r(a),f(b)\\le f(a)$.\r\nSimilarly we can define local minimums.\r\n\\begin{definition}\r\n    We say $f$ has a stationary point at $a$ if $f^\\prime(a)=0$.\r\n\\end{definition}\r\nIt is immediate that $f$ has stationary points in local maxima/minima.\r\n\\begin{theorem}\r\n    Let $U\\subset\\mathbb R^m$ be open and $f:U\\to\\mathbb R$ be twice differentiable in $U$ and $f^{\\prime\\prime}$ is continuous at $a$ and $f^\\prime(a)=0$.\r\n    Then if the symmetric form $f^{\\prime\\prime}$ is positive definite at $a$ then $f$ has a local minimum, and if it is negative definite then it has a local maximum.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    It is a non-examinable fact that\r\n    $$f(a+h)=f(a)+f^\\prime(a)(h)+1/2f^{\\prime\\prime}(a)(h,h)+\\epsilon(h)o(\\|h\\|^2)$$\r\n    Recall that $f^{\\prime\\prime}(a)$ is (real) diagonalizable.\r\n    So there is a base $\\{u_k\\}$ such that\r\n    $$f^{\\prime\\prime}(u_i,u_j)=\\begin{cases}\r\n        0\\text{, if $i\\neq j$}\\\\\r\n        \\lambda_i\\text{, if $i=j$}\r\n    \\end{cases}$$\r\n    Assume that $f^{\\prime\\prime}$ is positive definite, it means that $f^{\\prime\\prime}(a)(h,k)>0$ for any $(h,k)\\neq (0,0)$.\\\\\r\n    So $\\lambda_i=f^{\\prime\\prime}(a)(u_i,u_i)>0$, hence $\\mu=\\min\\{\\lambda_i:1\\le i\\le m\\}>0$.\r\n    For $h\\in\\mathbb R^m$, we have\r\n    $$f^{\\prime\\prime}(a)(h,h)=\\sum_{i,j}h_ih_jf^{\\prime\\prime}(a)(u_i,u_j)=\\sum_ih_i^2\\lambda_i\\ge\\mu\\|h\\|^2$$\r\n    Hence $f(a+h)-f(a)\\ge \\mu\\|h\\|^2/4\\ge 0$, therefore $f$ has a local minimum at $a$.\r\n    Similar for negative definite case.\r\n\\end{proof}", "meta": {"hexsha": "22572f998c690562c9763f582b05423dfbda336e", "size": 21615, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8/diff.tex", "max_stars_repo_name": "david-bai-notes/IB-Analysis-and-Topology", "max_stars_repo_head_hexsha": "9c3a32b907ff14942767e4bbdc9951240d2d7edb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "8/diff.tex", "max_issues_repo_name": "david-bai-notes/IB-Analysis-and-Topology", "max_issues_repo_head_hexsha": "9c3a32b907ff14942767e4bbdc9951240d2d7edb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "8/diff.tex", "max_forks_repo_name": "david-bai-notes/IB-Analysis-and-Topology", "max_forks_repo_head_hexsha": "9c3a32b907ff14942767e4bbdc9951240d2d7edb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.7610619469, "max_line_length": 385, "alphanum_fraction": 0.5867221837, "num_tokens": 8828, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.734134299780672}}
{"text": "\\subsection{Arithmetic}\n\n\\noindent\nNormally Eigenmath uses integer and rational number arithmetic.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\n1/2 + 1/3\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\tfrac{5}{6}$\n\n\\bigskip\n\\noindent\nA floating point value causes Eigenmath to switch to floating point arithmetic.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\n1/2 + 1/3.0\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle 0.833333$\n\n\\bigskip\n\\noindent\nAn integer or rational number result can be converted to a floating\npoint value by entering {\\it float}.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\n212^17\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle 3529471145760275132301897342055866171392$\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nfloat\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle 3.52947\\times10^{39}$\n\n\\bigskip\n\\noindent\nThe following example shows how to enter a floating point value\nusing scientific notation.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nepsilon = 1.0 10^(-6)\nepsilon\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\varepsilon=1.0\\times10^{-6}$\n", "meta": {"hexsha": "dbef0b0ee405b2ff053b4191148236705f838c0d", "size": 1033, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/arithmetic.tex", "max_stars_repo_name": "franko/eigenmath", "max_stars_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2019-09-29T03:15:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T00:57:51.000Z", "max_issues_repo_path": "doc/arithmetic.tex", "max_issues_repo_name": "franko/eigenmath", "max_issues_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2019-11-12T00:57:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T23:46:46.000Z", "max_forks_repo_path": "doc/arithmetic.tex", "max_forks_repo_name": "franko/eigenmath", "max_forks_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2019-10-03T13:23:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T13:28:00.000Z", "avg_line_length": 18.7818181818, "max_line_length": 79, "alphanum_fraction": 0.7657308809, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436728, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.7341342959950171}}
{"text": "\\section{Basic Notions}\r\n\\subsection{Definitions}\r\n\\begin{definition}\r\n    A subset $U\\subset\\mathbb C$ is open if $\\forall u\\in U,\\exists r>0,D_r(u)\\subset U$.\r\n\\end{definition}\r\nIf we identify $\\mathbb C$ with $\\mathbb R^2$ in the obivous way, and give $\\mathbb R^2$ the usual topology, then $U\\subset\\mathbb C$ is open iff it is open in $\\mathbb R^2$.\\\\\r\nWe shall be interested in functions $f:U\\to\\mathbb C$ where $U$ is open.\r\n\\begin{definition}\r\n    Let $U\\subset\\mathbb C$ be open and $f:U\\to\\mathbb C$.\r\n    We say $\\lim_{z\\to c}f(z)=A$ if $\\forall\\epsilon>0,\\exists\\delta>0$,\r\n    $$0<|z-c|<\\delta\\implies |f(z)-f(c)|<\\epsilon$$\r\n    $f$ is continuous at $c\\in U$ if $\\lim_{z\\to c}f(z)=f(c)$.\r\n    $f$ is continuous in $U$ if it is continuous everywhere in $U$.\r\n\\end{definition}\r\nWe can always write $f(x+iy)=u(x,y)+iv(x,y)$ where $u,v:\\mathbb U\\to\\mathbb R$ where $U$ is open in $\\mathbb R^2$.\r\nIt is easy to see that $\\mathbb C$ inherits the continuity condition in $\\mathbb R^2$ since it inherits the topology from it.\r\nSo we have that the continuity of $f$ is equivalent to that of $u,v$.\r\n\\begin{definition}\r\n    Let $f:U\\to\\mathbb C$ be as before, and $w\\in U$.\r\n    We say $f$ is differentiable at $w$ if the limit\r\n    $$\\lim_{z\\to w}\\frac{f(z)-f(w)}{z-w}$$\r\n    exists.\r\n    If it exists, we say $f$ is differentiable at $w$ and has derivative equals the limit.\\\\\r\n    If $f$ is differentiable everywhere in an open neighbourhood of $w$, then we say $f$ is holomorphic at $w$.\r\n    \\footnote{Some authors use the word `analytic'}\\\\\r\n    We say $f$ is holomorphic on $U$ if it is holomorphic everywhere on $U$.\r\n    (Or equivalently it is differentiable everywhere.)\r\n\\end{definition}\r\nRules that can be obtained from real differentiation by first principle mostly extends to complex differentiation.\r\nFor example, polynomials are differentiable everywhere, and rational functions are differentiable in the subset (which is open as the complement of a finite subset) where they are defined.\r\n\\subsection{The Cauchy-Riemann Equation}\r\nAlthough complex differentiation exhibits similar definition as real differentiation, they behave very differently.\r\nA natural question is, is the differentiability of $f$ behave the same as the differentiability of $u,v$?\r\nThe answer is no.\r\n\\begin{theorem}[Cauchy-Riemann Equation]\r\n    $f:U\\to\\mathbb C$ is differentiable at $w=c+id$ iff the functions $u,v$ are differentiable at $(c,d)$ and they satisfies $u_x=v_y,u_y=-v_x$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    By definition, $f$ is differentiable at $w$ with derivative $f^\\prime(w)=p+iq$ if and only if\r\n    $$\\lim_{z\\to w}\\frac{f(z)-f(w)-f^\\prime(z)(z-w)}{|z-w|}=0$$\r\n    which is equivalent to the case where we seperate the real and imaginary part, which is just to say\r\n    $$\r\n    \\begin{cases}\r\n        \\lim_{(x,y)\\to(c,d)}\\frac{u(x,y)-u(c,d)-(p(x-c)-q(y-d))}{\\|(x-c,y-d)\\|}=0\\\\\r\n        \\lim_{(x,y)\\to(c,d)}\\frac{v(x,y)-v(c,d)-(p(x-c)+q(y-d))}{\\|(x-c,y-d)\\|}=0\r\n    \\end{cases}$$\r\n    which happens iff $Du(c,d)=(p,-q)$ and $Dv(c,d)=(p,q)$.\r\n    The theorem follows.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Just because $u,v$ has partial derivatives satisfying Cauchy-Riemann equation does not guarantee the total differentiability.\r\n    A deeper question is what if we require them to be so on an open set, but that goes beyond the scope of the course.\r\n\\end{remark}\r\nFrom the theorem, we have obtained an expression of the complex derivative $f^\\prime=u_x+iv_x$.\r\nIf we just want to show that the differentiability of $f$ at $c+id$ implies the existence of partials of $u,v$ satisfying Cauchy-Riemann equations, then we can just proceed by taking the limit of $z-w\\to 0$ from both axes.\r\n\\begin{example}\r\n    $f(z)=\\bar{z}$ is nowhere differentiable since it does not satisfy the first C-R equation.\r\n\\end{example}\r\n\\begin{remark}\r\n    Complex differentiability is much more restrictive than real ones.\r\n    Of course, we will exhibit examples to justify it.\r\n\\end{remark}\r\n\\begin{theorem}[Liouville Theorem]\\label{holo_bdd_const}\r\n    If $f:\\mathbb C\\to \\mathbb C$ is holomorphic and bounded, then $f$ is constant.\r\n\\end{theorem}\r\n\\begin{theorem}\\label{infinite_holo}\r\n    Let $U$ be an open set in $\\mathbb C$, then if $f:U\\to\\mathbb C$ is holomorphic, so is $f^\\prime$.\r\n\\end{theorem}\r\n\\begin{theorem}\\label{uniform_holo}\r\n    A sequence of holomorphic functions $f_n:U\\to\\mathbb C$ on the same open domain, and $f_n\\to f$ uniformly, then $f$ is holomorphic.\r\n\\end{theorem}\r\nBy Theorem \\ref{infinite_holo}, holomorphic functions are infinite differentiable, so any order of partial derivatives of $u,v$ exists, so we can differentiate the Cauchy-Riemann equation one more time to get $u_{xx}+u_{yy}=0$, so $u$ is a harmonic function, similarly $v$ is harmonic as well.\r\nSo the real and imaginary part of a holomorphic function are harmonic.\r\n\\begin{corollary}\r\n    Let $f=u+iv:U\\to\\mathbb C$, suppose that $u,v$ has continuous partial derivatives in $U$ and $u,v$ satisfy Cauchy-Riemann Equation, then $f$ is holomorphic.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate from what we have got and a result from Analysis and Topology.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Once we know Theorem \\ref{infinite_holo}, the converse of the preceding corollary follows.\r\n\\end{remark}\r\n\\begin{definition}\r\n    A curve is a continuous map $\\gamma:[a,b]\\to\\mathbb C$.\r\n    It is called $C^1$ if $\\gamma^\\prime$ exists and is continuous on $[a,b]$.\\\\\r\n    An open subset $U\\subset\\mathbb C$ is path connected if for any $z,w\\in U$, there is a curve $\\gamma:[a,b]\\to U$ such that $\\gamma(a)=z,\\gamma(b)=w$.\\\\\r\n    A non-empty open path-connected subset of $\\mathbb C$ is called a domain.\r\n\\end{definition}\r\n\\begin{corollary}\r\n    Let $U$ be a domain and $f:U\\to\\mathbb C$ is homomorphic. If $f^\\prime\\equiv 0$, then $f$ is constant.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Proved in Analysis and Topology.\r\n\\end{proof}\r\n\\subsection{Power Series}\r\n\\begin{theorem}\r\n    For any sequence of complex numbers $(c_n)$, there is some $R\\in [0,\\infty]$ such that the power series\r\n    $$\\sum_{n=0}^\\infty c_n(z-a)^n$$\r\n    such that it converges absolutely for $|z-a|<R$ and diverges for $|z-a|>R$.\\\\\r\n    If $R\\in\\mathbb R_{>0}$, and if $0<r<R$, then the convergence is uniform on $B_r(a)$ (or $D_r(a)$, they are equivalent anyways).\r\n\\end{theorem}\r\n\\begin{definition}\r\n    Such an $R$ is called the radius of convergence.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    $R=\\frac{1}{\\lambda}$ where $\\lambda=\\limsup_{n\\to\\infty}\\sqrt[n]{|c_n|}$.\r\n\\end{proposition}\r\n\\begin{theorem}\r\n    Define $f$ on the disk $D_R(a)$ by\r\n    $$f(z)=\\sum_{n=0}^\\infty c_n(z-a)^n$$\r\n    where $R>0$ is the radius of convergence of the series.\r\n    Then\\\\\r\n    1. $f$ is holomorphic on this disk,\\\\\r\n    2. And\r\n    $$\\sum_{n=0}^\\infty (n+1)c_{n+1}(z-a)^n$$\r\n    is convergent on $D_R(a)$ and is the derivative of $f$.\\\\\r\n    3. $f$ has derivatives of all orders on $D_R(a)$ and $f^{(n)}(a)=c_nn!$.\\\\\r\n    4. If $f$ vanished in some open disk $D_r(a)$ with $0<r<R$, then it vanishes on the whole of $D_R(a)$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    3 follows from 2 and 4 follows from 3.\\\\\r\n    WLOG $a=0$.\r\n    To prove 1 and 2, let $|z|<R$ and choose $\\rho$ such that $|x|<\\rho<R$, then we have\r\n    $$\\lim_{n\\to\\infty}\\frac{n|c_n||z|^{n-1}}{|c_n|\\rho^n}=\\lim_{n\\to\\infty}\\frac{n}{\\rho}\\left( \\frac{|z|}{\\rho} \\right)^n\\to 0$$\r\n    so the derived series also converges on $D_R(0)$.\\\\\r\n    To show that $f$ is holomorphic with derivative equals the derived series, we fix some $w\\in D_R(0)$.\r\n    Note that $f$ is differentiable at $w$ with derivative being the derived series $\\sigma$ if and only if the function\r\n    $$g(h)=\r\n    \\begin{cases}\r\n        \\frac{f(z)-f(w)}{z-w}\\text{, if $z\\neq w$}\r\n        \\sigma\\text{, if $z=w$}\r\n    \\end{cases}$$\r\n    is continuous at $w$.\r\n    But $g(z)=\\sum_{n=0}^\\infty h_n(z)$ where\r\n    $$h_n(z)=\\begin{cases}\r\n        c_n(z^{n-1}+z^{n-2}w+\\cdots+w^{n-1})\\text{, for $z\\neq w$}\\\\\r\n        nc_nw^{n-1}\\text{, for $z=w$}\r\n    \\end{cases},n>0;h_0(z)=0$$\r\n    Note that each $h_n$ is continuous.\r\n    So the continuity of $g$ at $w$ follows from the uniform convergence of the series.\r\n    Again we take $0<|w|<r<R$, so for any point $z\\in D_r(0)$, we have\r\n    $$|h_n(z)|=|c_n||z^{n-1}+z^{n-2}w+\\cdots+w^{n-1}|\\le n|c_n||r|^{n-1}$$\r\n    which proves the uniform convergence.\r\n    So 1 and 2 are proved.\r\n\\end{proof}\r\n\\begin{definition}\r\n    The exponential function is defined as\r\n    $$e^z=\\exp(z)=\\sum_{k=0}^\\infty\\frac{z^k}{k!}$$\r\n\\end{definition}\r\n\\begin{definition}\r\n    An entire function is a function that is holomorphic on all of $\\mathbb C$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    1. $\\exp$ is entire with derivative equals to itself.\\\\\r\n    2. $\\exp(z+w)=\\exp(z)\\exp(w)$.\\\\\r\n    3. $\\exp(z)\\neq 0$.\\\\\r\n    4. $\\exp(z)=1\\iff z\\in2\\pi i\\mathbb Z$.\\\\\r\n    5. $\\exp:\\mathbb C\\to\\mathbb C\\setminus\\{0\\}$ is surjective.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Given $z\\in\\mathbb C$, we say $w\\in\\mathbb C$ is a logarithm of $z$ of $e^w=z$.\r\n\\end{definition}\r\nNote that $z$ has a logarithm iff $z\\neq 0$.\r\nIf $w_1,w_2$ are two logrithms of $z$, then we immediately have $w_1-w_2\\in 2\\pi i\\mathbb Z$.\r\n\\begin{definition}\r\n    Let $U\\subset\\mathbb C^\\star=\\mathbb C\\setminus\\{0\\}$.\r\n    A branch of the logarithm on $U$ is a continuous function $\\lambda:U\\to\\mathbb C$ such that $\\exp\\circ\\lambda=\\operatorname{id}$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    1. If such $\\lambda$ does exixt, then $\\lambda$ is holomorphic on $U$ by simply computation.\\\\\r\n    2. From the definition, it follows that $|z|=e^{\\operatorname{Re}\\lambda(z)}$, so it is immediate that any branch $\\lambda$ has $\\operatorname{Re}\\lambda(z)=\\log|z|$.\r\n\\end{remark}\r\n\\begin{definition}\r\n    The principal branch of logarithm is the function $\\operatorname{Log}:U_1=\\mathbb C\\setminus\\{x\\in\\mathbb R:x\\le 0\\}\\to\\mathbb C$ given by $\\operatorname{Log}(z)=\\log|z|+i\\arg z$ where the value of $\\arg$ is taken in the open interval $(-\\pi,\\pi)$. \r\n\\end{definition}\r\nObviously in this open set it is a inverse of $\\exp$.\r\nTo see the continuity, observe that the map $z\\mapsto z/|z|$ is continuous and the map $\\theta\\mapsto e^{i\\theta}$ is a homeomorphism $(-\\pi,\\pi)\\to S\\setminus\\{-1\\}$\r\n\\begin{proposition}\r\n    1. $\\operatorname{Log}$ is holomorphic on $U_1$ with derivative $1/z$.\\\\\r\n    2. For $|z|<1$,\r\n    $$\\operatorname{Log}(z)=\\sum_{n=1}^\\infty\\frac{(-1)^{n+1}z^n}{n}$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{remark}\r\n    There is no way to extend $\\operatorname{Log}$ to the whole of $\\mathbb C^\\star$ and remain a branch since\r\n    $$\\lim_{\\theta\\to \\pi^+}e^{i\\theta}\\neq\\lim_{\\theta\\to \\pi^-}e^{i\\theta}$$\r\n    In fact there is no branch that can be such extended.\r\n\\end{remark}\r\nUsing $\\exp$ and $\\operatorname{Log}$, we can construct the familiar functions we had in real analysis, like the trigonometrics, hypertrigonometrics, etc., in the way we know (like $\\cos(z)=(e^{iz}+e^{-iz})/2$, etc).\r\nWe can also define, for $z\\notin \\mathbb R_{\\le 0}$, $z^\\alpha=\\exp(\\alpha\\operatorname{Log}(z))$.\\\\\r\nLet $f:U\\to\\mathbb C$ be a holomorphic function.\r\nA number $w\\in U$ having $f^\\prime(w)$ is nice in the sense that $f$ is invertible there by Inverse Function Theorem with $(f^{-1})^\\prime(f(w))=1/f^\\prime(w)$.\r\nOne can check that $f^{-1}$ also satisfies the Cauchy-Riemann equation, hence is also holomorphic.\\\\\r\nIt is also nice in a geometric sense as $f$ preserves angles at that point.\r\nLet $\\gamma_1,\\gamma_2:[-1,1]\\to\\mathbb C$ be $C^1$ curves with $\\gamma_1(0)=\\gamma_2(0)=w$ and $\\gamma_1^\\prime(0)\\gamma_2^\\prime(0)\\neq 0$, then since $(f\\circ \\gamma_1)^\\prime(0)=f^\\prime(w)\\gamma^\\prime_1(0)$.\r\nSimilar for $\\gamma_2$.\r\nSince $f^\\prime(w)\\neq 0$, we have\r\n$$\\frac{\\gamma^\\prime_1(0)}{\\gamma_2^\\prime(0)}=\\frac{(f\\circ\\gamma_1)^\\prime(0)}{(f\\circ\\gamma_2)^\\prime(0)}$$\r\nSo $f$ preserves angles.\r\n\\begin{definition}[Conformal Equivalence]\r\n    Let $U$ be an open set.\r\n    A holomorphic function $f:U\\to\\mathbb C$ is called conformal at $w\\in U$ if $f^\\prime(w)\\neq 0$.\\\\\r\n    If for domains $D,D'$ there is a holomorpic bijection $f:D\\to\\tilde{D}$ which is conformal at every point, then we say $D,D'$ are conformal equivalent.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. Any Mobius map $f:\\mathbb C\\cup\\{\\infty\\}\\to\\mathbb C\\cup\\{\\infty\\}$ is a conformal equivalence.\\\\\r\n    2. The map $z\\mapsto z^n$ from $\\{\\mathbb z\\in\\mathbb C^\\star:0\\le\\arg z\\le \\pi/n\\}$ to the upper half plane $\\mathbb H=\\{z\\in\\mathbb C:\\operatorname{Im}z>0\\}$ is conformal.\\\\\r\n    3. The exponential $\\exp:\\{z\\in\\mathbb C:-\\pi<\\operatorname{Im}(z)<\\pi\\}\\to\\mathbb C\\setminus\\mathbb R_{\\le 0}$.\\\\\r\n    4. Consider $g:z\\mapsto (z-i)/(z+i)$ with $g:\\mathbb H\\to D_1(0)$.\r\n    It is also conformal.\r\n\\end{example}\r\n\\begin{theorem}[Riemann Mapping]\r\n    Let $D$ be a domain bounded by a simple closed curve, then it is conformally equivalent to the unit disk.\\\\\r\n    More generally, any simply connected domain that is not the whole complex plane is conformally equivalent to the unit disk.\r\n\\end{theorem}", "meta": {"hexsha": "c9e0e008f10737f2b89bc7add37efb84f3dbe3b9", "size": 13145, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/basics.tex", "max_stars_repo_name": "david-bai-notes/IB-Complex-Analysis", "max_stars_repo_head_hexsha": "d67e2ff022d5fbc22bfdfd377f2414c23be532ed", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1/basics.tex", "max_issues_repo_name": "david-bai-notes/IB-Complex-Analysis", "max_issues_repo_head_hexsha": "d67e2ff022d5fbc22bfdfd377f2414c23be532ed", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1/basics.tex", "max_forks_repo_name": "david-bai-notes/IB-Complex-Analysis", "max_forks_repo_head_hexsha": "d67e2ff022d5fbc22bfdfd377f2414c23be532ed", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.75, "max_line_length": 294, "alphanum_fraction": 0.6635222518, "num_tokens": 4409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8856314662716159, "lm_q1q2_score": 0.7341342922631413}}
{"text": "% https://www.mathworks.com/examples/matlab/mw/matlab-ex13677222-solve-nonstiff-odes\n\n\\PassOptionsToPackage{hyphens}{url}% allow line breaks at hyphens in urls\n\\documentclass[12pt]{matlatex}\n\\usepackage{examples}\n\\usepackage{pgfplots}\n\\usepackage{caption}\n\n\\begin{document}\n\n\\section*{Numerical integration of coupled ODEs}\n\nThis example is based that given in the Mathworks web page%\n\\ \\url{https://www.mathworks.com/examples/matlab/mw/matlab-ex13677222-solve-nonstiff-odes}.\nIt uses the Matlab function {\\tt\\small ODE45} to integrate a coupled pair of ordinary differential equations -- the van der Pol equation with $\\mu=1$.\n\n\\begin{matlab}\n   [t,y] = ode45(@vdp1,[0 20],[2; 0]);\n\n   % Plot of the solution\n   plot(t,y(:,1),'-o',t,y(:,2),'-o')\n   xlabel('Time t')\n   ylabel('Solution y')\n   legend('y_1','y_2')\n\n   print(gcf,'example_02_fig.png','-dpng');\n\n   dlmwrite ('example_02.txt',[t';y(:,1)';y(:,2)']','delimiter',' ','precision','% .8e');\n\n   function dydt = vdp1(t,y)\n   %VDP1  Evaluate the van der Pol ODEs for mu = 1\n   %\n   %   See also ODE113, ODE23, ODE45.\n\n   %   Jacek Kierzenka and Lawrence F. Shampine\n   %   Copyright 1984-2014 The MathWorks, Inc.\n\n   dydt = [y(2); (1-y(1)^2)*y(2)-y(1)];\n   end\n\\end{matlab}\n\n\\clearpage\n\n\\begin{figure}\n   \\centering\n   \\IfFileExists{example_02_fig.png}%\n   {\\includegraphics[width=0.75\\textwidth]{example_02_fig.png}}{Failed to create png plot.}\n   \\caption{Solution of van der Pol equation ($\\mu = 1$) using ODE45.}\n\\end{figure}\n\n\\clearpage\n\n\\pgfplotsset{compat=newest}\n\\pgfplotsset{width=0.60\\textwidth,height=0.40\\textwidth}\n\n\\begin{center}\n   \\begin{tikzpicture}\n      \\begin{axis}\n         [xmin= 0.0, xmax=20.0,\n          ymin=-3.0, ymax=3.0,\n          xlabel=$\\text{Time }t$, ylabel=$\\text{Solution }y$,\n          grid=major, grid style={dashed,gray!30},\n          legend entries = {$y_1$, $y_2$}]\n          \\addplot[blue, mark=o]   table [x index=0, y index=1]{example_02.txt};\n          \\addplot[red, mark=o]    table [x index=0, y index=2]{example_02.txt};\n      \\end{axis}\n   \\end{tikzpicture}\n   \\captionof{figure}{Solution of van der Pol equation ($\\mu = 1$) using ODE45.}\n\\end{center}\n\n\\vfill\n\n\\begin{latex}\n   \\begin{tikzpicture} % requires \\usepackage{pgfplots}\n      \\begin{axis}\n         [xmin= 0.0, xmax=20.0,\n          ymin=-3.0, ymax=3.0,\n          xlabel=$\\text{Time }t$, ylabel=$\\text{Solution }y$,\n          grid=major, grid style={dashed,gray!30},\n          legend entries = {$y_1$, $y_2$}]\n          \\addplot[blue, mark=o]   table [x index=0, y index=1]{example_02.txt};\n          \\addplot[red, mark=o]    table [x index=0, y index=2]{example_02.txt};\n      \\end{axis}\n   \\end{tikzpicture}\n   \\captionof{figure}{Solution of van der Pol equation ($\\mu = 1$) using ODE45.} % requires \\usepackage{caption}\n\\end{latex}\n\n\\end{document}\n", "meta": {"hexsha": "3437ed07c93ffefce0a10aed87a96ef8e11459eb", "size": 2814, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/examples/example_02.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "matlab/examples/example_02.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "matlab/examples/example_02.tex", "max_forks_repo_name": "leo-brewin/hybrid-latex", "max_forks_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-27T03:29:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:17:18.000Z", "avg_line_length": 31.6179775281, "max_line_length": 150, "alphanum_fraction": 0.6421464108, "num_tokens": 961, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.8856314738181876, "lm_q1q2_score": 0.7341342910335235}}
{"text": "\n\\part{Classification Algorithms}\n\\paragraph{Classification} \n\\begin{itemize}\n\t\\item Input: a database $D = {x_1, x_2, \\dots, x_n}$ of tuples, a set of classes $C = {C_1, C_2, \\dots, C_m}$\n\t\\item Output: a \\textbf{mapping} $f: D\\rightarrow C$, where each $x_i$ is assigned to a class. \n\\end{itemize}\n\\section{Generalized Linear Models}\n\\subsection{Component of GLM}\n\\begin{itemize}\n\t\\item Random component: identifies \\textbf{dependent variable $\\mu$} and \\textbf{its probability function}\n\t\\item Systematc component: identifies the set of \\textbf{explanatory variables -- predictors} ($X_1, \\dots, X_k$)\n\t\\item Link function: a \\textbf{linear} function that links the dependent variable and all explanatory variables.\n\t$$g(\\mu) = \\beta_0 + \\beta_1 X_1 + \\beta_2 X_2 + \\dots + \\beta_k X_k$$\n\\end{itemize}\n\\subsection{Common Link Functions}\n\\begin{itemize}\n\t\\item \\textbf{Identity Link: linear regression}\n\t$$g(\\mu) = \\mu = X\\beta$$\n\t\\item \\textbf{Logit Link: logistic regression}\n\t$$g(\\mu) = \\ln(\\frac{\\mu}{1 - \\mu}) = X\\beta $$\n\t\\item \\textbf{Log Link: Poisson regression}\n\t$$g(\\mu) = \\log(\\mu) =  X\\beta$$\n\\end{itemize}\n\\section{Logistic Regression: Binary Classification}\n\\begin{itemize}\n\t\\item Idea:\t\n\t\\begin{itemize}\n\t\t\\item Gauss-Markov assumptions need to be fulfilled to implement an OLS-Estimator\n\t\t\n\t\t$\\rightarrow$ more \\textbf{generalized models} needed to relax the assumptions for OLS\n\t\t\n\t\t\\item Predicting \\textbf{categorical dependent variables}: a \\textbf{classification} problem.\n\t\t\\item Limitation from linear regression in classification:\n\t\t\\begin{itemize}\n\t\t\t\\item prediction values $\\hat{y}$ should range within [0, 1], linear regression model prediction \\textbf{exceeds this range}.\n\t\t\t\\item \\textbf{violation of Homoscedasticity}: residuals $e_i$ doesn't have constant variance since the true Y only takes two values(0/1). The distribution of the residuals is no longer a normal distribution.\n\t\t\t\\item \\textbf{violation of No Autocorrelation}: overall residuals of the model follows a systematic pattern, it's positive on one side and negative on the other side $\\rightarrow$ Autocorrelation\n\t\t\\end{itemize}\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{The Logistic Regression Model}\nThe \\textbf{binary} logistic regression model described in \\textbf{log odds/logit}:\n$$\\text{log odds} = \\ln(\\frac{p(X)}{1 - p(X)}) $$\n$$\\ln(\\frac{p(X)}{1 - p(X)}) = \\beta_0 + \\beta_1 X + \\varepsilon$$\n\\begin{itemize}\n\t\\item Modeling Input: $X_i$, 0/1\n\t\n\t\t  Output: a Logit-model\t  \n\t\\item p(X): probability that Y = 1 given X.\n\t\\item \\textbf{log odds / logit}: range ($-\\infty, +\\infty$), the log-ratio of Y = 1 to Y = 0 given X\n\\end{itemize}\n\nThe logistic regression model described in \\textbf{odds}: \n$$odds = \\frac{p(X)}{1 - p(X)}$$\n$$\\frac{p(X)}{1 - p(X)} = e^{\\beta_0 + \\beta_1 X}$$\n\\begin{itemize}\n\t\\item \\textbf{odds}: range [$0, +\\infty$), the ratio of Y = 1 to Y = 0 given X\n\t\\begin{itemize}\n\t\t\\item p(X) = 0.5, odds = 1\n\t\t\\item p(X) $< 0.5, \\rightarrow 0$, odds $\\rightarrow 0$\n\t\t\\item p(X) $> 0.5, \\rightarrow 1$, odds $\\rightarrow +\\infty$\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{The Logistic Function}\n$$Pr[Y|X] = p(X) = \\dfrac{e^{\\beta_0 + \\beta_1 X}}{1 + e^{\\beta_0 + \\beta_1 X}}$$\n\\begin{itemize}\n\t\\item Prediction Input: $X_i$, $\\beta_i$\n\t\n\t\\textbf{Output: $p(X)$}\t\t \n\t\n\t\\item Range p(X): [0,1]\n\t\\begin{itemize}\n\t\t\\item $\\beta_0 + \\beta_1 X = 0$:  p(X) = 0.5 \n\t\t\\item $\\beta_0 + \\beta_1 X  \\uparrow$:  p(X) $\\rightarrow 1$\n\t\t\\item $\\beta_0 + \\beta_1 X  \\downarrow$:  p(X) $\\rightarrow 0$\n\t\\end{itemize}\n\t\\item $\\beta_0$: regression constant, moves the curve \\textbf{left/right}\n\t\\item $\\beta_1$: regression slope, defines \\textbf{steepness} of the curve. $\\beta_1 \\uparrow$, steepness $\\uparrow$\n\t\\item This can be reformed into the logistic regression model. \n\t\\item Comparison Linear Model \\& Logistic Model(the logistic function):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.6\\textwidth]{logit.png}\n\t\\end{figure}\n\\end{itemize}\nComparison p(X) \\& odds \\& log-odds:\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.25\\textwidth]{logodds_odds.png}\n\\end{figure}\n\n\\subsection{Multiple Logistic Regression Model}\n$$\\ln(\\frac{p(X)}{1 - p(X)}) = \\beta_0 + \\beta_1 X_1 + \\beta_2 X_2 + \\dots + \\beta_k X_k$$\n\\begin{itemize}\n\t\\item Interpretation of Coefficients $\\beta_j$: \n\t\\begin{itemize}\n\t\t\\item \\textbf{while keeping all other $x_j$ constant}, if $x_{ij}$ increase by 1, the \\textbf{log-odds} will increase/decrease by $\\beta_j$, or the \\textbf{odds} will increase/decrease by $\\mathbf{e^{\\beta_j}}$.\n\t\\end{itemize}\n\t\\item Test of Multicollinearity: VIF / correlation coefficient\n\t\\item Test of irrelevant variables: Wald-Test (significance of coefficients) \n\\end{itemize}\n\n\\subsection{Estimation of Coefficients: Maximum Likelihood Estimator}\n\\subsubsection{Intro}\nThe probability of one data point $x_i$ can be modeled as \\textbf{Bernoulli trial}: \n$$p^{y_i}(1-p)^{1-y_i}$$\nThe \\textbf{likelihood function}:  the \\textbf{joint probability} of observing the dependent variable values of random samples. $\\rightarrow$ the product of all Bernoulli trials\n$$L = \\Pi_{i=1} p^{y_i}(1-p)^{1-y_i}$$\nThe logistic function can also be described as a \\textbf{sigmoid function} in form $S(x) = \\frac{e^x}{1 + e^x} = \\sigma(x)$\n$$P(X) = \\sigma(\\beta_0 + \\beta_1 X)$$\n\\subsubsection{The Likelihood Function and Maximum Likelihood Estimator}\nThe \\textbf{likelihood function for Logistic Regression Model}:\n\\begin{align*}\n\tL &= \\Pi_{i=1} p^{y_i}(1-p)^{1-y_i} \\\\\n\t  &= \\Pi_{i=1} \\sigma(\\beta_0 + \\beta_1 X)^{y_i} \\cdot (1 - \\sigma(\\beta_0 + \\beta_1 X))^{1-y_i}\n\\end{align*}\n\nThe \\textbf{Maximum Likelihood Estimator}: \\textbf{maximizes the joint probability} of observing the set of dependent variables of the random samples.\n\\\\ \\ \\\\\nProcess:\n\\begin{itemize}\n\t\\item take the log: $$LL = \\ln(L) = \\Sigma_{i=1} ( y_{i} \\ln(p) + (1 - y_i)\\ln(1-p))$$\n\t\\item \\textbf{maximize} LL: \n\t\\begin{align*}\n\t\t\\beta = \\arg\\max_{\\beta}(LL) &= \\arg\\max_{\\beta} [\\Sigma_{i=1} ( y_{i} \\ln(p) + (1 - y_i)\\ln(1-p))] \\\\\n\t\t\t\t\t\t\t\t\t &= \\arg\\max_{\\beta} [\\Sigma_{i=1} ( y_{i} \\ln(\\sigma(\\beta_0+\\beta_1X)) + (1 - y_i)\\ln(1-\\sigma(\\beta_0 + \\beta_1X)))]\n\t\\end{align*}\n\t\\item Method: \\textbf{Gradient Ascent}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.65\\textwidth]{gradientascent.png}\n\t\\end{figure}\n\t\\begin{itemize}\n\t\t\\item initial start point\n\t\t\\item select a step size $\\alpha$\n\t\t\\item compute \\textbf{partial derivatives} and \\textbf{maximizes the function} $f(x^{(k)} + \\alpha \\bigtriangledown f(x^{(k)}))$\n\t\\end{itemize}\n\t\\item \\textbf{Gradient}(partial derivatives) of the LL-Function: \\textbf{chain rule}\n\t\n\t with $z = \\beta_0+\\beta_1X$\n\t\n\t$$\\frac{\\partial LL}{\\beta_j} = \\Sigma_{i=1} \\frac{\\partial LL}{\\partial p} \\cdot \\frac{\\partial p}{\\partial z} \\cdot \\frac{\\partial z}{\\partial \\beta_j}$$\n\t\\begin{align*}\n\t\t\\frac{\\partial LL}{\\partial p} &= \\frac{y_i}{p} - \\frac{1 - y_i}{1 - p} \\\\\n\t\t \\frac{\\partial p}{\\partial z} &= \\sigma(z) \\cdot(1 - \\sigma(z)) \\\\\n\t\t \\frac{\\partial z}{\\partial \\beta_0} &= 1 \\text{, } \\frac{\\partial z}{\\partial \\beta_j} = x_j\\\\\t\t \n\t\\end{align*}\n\t\\begin{align*}\n\t\t\\frac{\\partial LL}{\\beta_0} &= \\left[ \\frac{y_i}{p} - \\frac{1 - y_i}{1 - p}\\right]  \\sigma(z) \\cdot(1 - \\sigma(z)) = \\left[ y_i - \\sigma(X\\beta) \\right] \\\\\n\t\t\\frac{\\partial LL}{\\beta_j} &= \\left[ \\frac{y_i}{p} - \\frac{1 - y_i}{1 - p}\\right]  \\sigma(z) \\cdot(1 - \\sigma(z))\\cdot x_j = \\left[ y_i - \\sigma(X\\beta) \\right] x_j\n\t\\end{align*}\n\\end{itemize}\n\\subsection{Quality Metrics of the Model}\n\\begin{itemize}\n\t\\item \\textbf{Null Model}: all predictors $x_i$ has no impact. The model is explained only by the intercept.\n\t\\item \\textbf{Fitted Model}: the model is explained by p predictors and 1 intercept.\n\\end{itemize}\n\n\\subsubsection{Null Deviance}\nIt measures how well the response is explained by \\textbf{only the intercept (no predictors)}.\n$$\\text{null deviance} = -2 \\ln(L(null))$$\n\n\\subsubsection{Residual Deviance}\n$$\\text{residual deviance} = -2 \\ln(L(fitted))$$\n\\begin{itemize}\n\t\\item residual deviance $\\downarrow$, model quality $\\uparrow$\n\t\\item difference between null and residual deviance $\\uparrow$, model quality $\\uparrow$\n\\end{itemize}\n\n\\subsubsection{AIC}\nAdditional penalizing term to get a balance between the \\textbf{goodness of fit} and \\textbf{simplicity of model}.\n\n$$AIC = \\text{residual deviance} + 2 \\cdot \\#\\text{parameters in model}$$\n\n\\begin{itemize}\n\t\\item AIC $\\downarrow$, model quality $\\uparrow$\n\\end{itemize}\n\n\\subsubsection{McFadden $\\mathbf{R^2}$} the ratio of improvement from null model to fitted model.\n$$R_{McFadden}^2 = 1 - \\frac{LL(fitted)}{LL(null)} = 1 - \\frac{\\text{residual deviance}}{\\text{null deviance}}$$\n\\begin{itemize}\n\t\\item model quality $\\uparrow$ , LL(fitted) $\\ll$ LL(null), $R^2 \\rightarrow 1$\n\t\\item model quality $\\downarrow$ , LL(fitted) $\\approx$ LL(null), $R^2 \\rightarrow 0$\n\t\\item rule of thumb: > 0.2 acceptable, > 0.4 ok.\n\\end{itemize}\n\n\\subsubsection{Likelihood Ratio Test}\nDoes the fitted model explain significantly more variance than null model?\n\\begin{itemize}\n\t\\item $H_0$: The fitted model explains \\textbf{no more variance} than null model\n\t\n\t$H_1$: The fitted model explains \\textbf{significantly more variance}.\n\t\\item test statistic:\n\t$$D = -2 \\ln (\\frac{L(null)}{L(fitted)})$$\n\t\\item Distribution: $\\chi^2$-Distribution\n\\end{itemize}\n\n\\subsubsection{Significance Test of Coefficients: Wald Test}\n\\begin{itemize}\n\t\\item $H_0$: $\\beta_i = 0$\n\t\n\t$H_1$: $\\beta_i \\neq 0$\n\\end{itemize}\n\n\\subsubsection{Error Rates}\ncomparing the predicted classification and the actual classification:\n\\begin{itemize}\n\t\\item percentage of correct Yes\n\t\\item percentage of correct No\n\t\\item overall percentage of correct predictions\n\\end{itemize}\n\n\\subsection{Model Interpretation}\n\\subsubsection{R-Result Interpretation}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.75\\textwidth]{logit_r.png}\n\\end{figure}\n\\begin{itemize}\n\t\\item significance of coefficients: significant if $p < \\alpha$ in $\\alpha$-level\n\t\\item model: difference between null and residual deviance, AIC\n\\end{itemize}\n\n\\subsubsection{Interpretation of Coefficients}\nEffect of change in $x_{ij}$ in \\textbf{one unit}:\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.9\\textwidth]{logit_interpretation.png}\n\\end{figure}\n\\begin{itemize}\n\t\\item $\\beta_j >0$: \n\t\\begin{itemize}\n\t\t\\item If $x_{ij}$ increase by 1, then the \\textbf{log odds} will \\textbf{increase} by $\\beta_j$, or the \\textbf{odds} will \\textbf{increase} by $\\mathbf{e^{\\beta_j}}$.\n\t\t\\item If $x_{ij}$ increase by 1, then the \\textbf{log odd ratio} is $\\beta_j$, or the \\textbf{odd ratio} is $e^{\\beta_j}$.\n\t\\end{itemize}\n\t\\item $\\beta_j < 0$:\n\t \\begin{itemize}\n\t \t\\item If $x_{ij}$ increase by 1, then the \\textbf{change of log odds} will \\textbf{decrease} by $\\beta_j$, or the \\textbf{change of odds} will \\textbf{decrease by a factor} of $\\mathbf{e^{\\beta_j}}$.\n\t \t\\item If $x_{ij}$ increase by 1, then the \\textbf{log odd ratio} is $\\beta_j$, or the \\textbf{odd ratio} is $e^{\\beta_j}$.\n\t \\end{itemize}\n\\end{itemize}\n\n\n\n\n\\section{Poisson Regression: Binary Classification for Count Data}\n\\begin{itemize}\n\t\\item Idea: \n\t\\begin{itemize}\n\t\t\\item \\textbf{count variables (non-negative integers)} as dependent variables\n\t\t\\item limitation of linear regression / OLS-Estimator\n\t\t\\begin{itemize}\n\t\t\t\\item linear model \\textbf{predicts negative values}\n\t\t\t\\item count data is often \\textbf{highly skewed}: \\#crimes committed -- most are 0.\n\t\t\t\n\t\t\t$\\rightarrow$ violates normality assumption (residuals follows normal distribution) of OLS-Estimator\n\t\t\\end{itemize}\n\t\\end{itemize}\n\t\\item Assumption: observed count follows a \\textbf{Poisson distribution}.\n\t$$Pr(y|\\mu) = \\dfrac{e^{-\\mu} \\mu^y}{y!}$$\n\t\\begin{itemize}\n\t\t\\item $\\mu$: expected count and expected variance $E(Y) = Var(Y) = \\mu$\n\t\t\\item y: observed count\n\t\\end{itemize} \n\n\t\\item Limitation:\n\t\\begin{itemize}\n\t\t\\item \\textbf{Overdispersion}: $E(Y) = Var(Y) = \\mu$ not met in real data. \n\t\t\n\t\t$\\rightarrow$ underestimation of standard errors, potential overconfidence in result. \n\t\t\n\t\t$\\rightarrow$ Alternative: negative binomial regression\n\t\t\n\t\t\\item \\textbf{Zero-inflation}: highly skewed observed data/predictions in 0.\n\t\t\n\t\tthis can't be changed even with negative binomial regression.\n\t\\end{itemize}\n\t\n\\end{itemize}\n\\subsection{Poisson Regression Model}\n$$ln(\\mu(x)) = \\beta_0 + \\beta_1 X_1 + \\dots \\beta_j X_i$$\n\\subsection{Estimation of Coefficients: Maximum Likelihood Estimator}\nThe random component(dependent variable) is:\n$$Pr(Y|X) = p(X) = \\dfrac{e^{-\\mu} \\mu^y}{y!} = \\dfrac{e^{\\beta xy} e^{-e^{\\beta x}}}{y!}$$\n\nThe \\textbf{likelihood function}:\n$$L(\\beta|X,Y) = \\Pi_{i=1} p = \\Pi_{i=1} \\dfrac{e^{\\beta x_iy_i} e^{-e^{\\beta x}}}{y_i!}$$\n\nThe Maximum Likelihood Estimator: \n$$\\log L(\\beta | X,Y) = \\Sigma_{i=1} (\\beta x_iy_i - e^{\\beta x_i} - \\log(y_i!))$$\n\\begin{itemize}\n\t\\item Method: \\textbf{Gradient Ascent}\n\\end{itemize}\n\\subsection{Model Interpretation}\nR-Result interpretation is same as logistic regression.\n\\subsubsection{Interpretation of Coefficients}\nEffect of change in $X_{ij}$ in \\textbf{one unit}:\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.65\\textwidth]{poisson_coeff.png}\n\\end{figure}\n\\begin{itemize}\n\t\\item $\\beta_j > 0$: If $x_{ij}$ increases by 1, then the \\textbf{log-incidence rate} will \\textbf{increase} by $\\beta_j$, or the \\textbf{incidence rate} will \\textbf{increase by a factor} of $e^{\\beta_j}$.\n\t\\item $\\beta_j < 0$: If $x_{ij}$ increases by 1, then the \\textbf{log-incidence rate} will \\textbf{decrease} by $\\beta_j$, or the \\textbf{incidence rate} will \\textbf{decrease by a factor} of $e^{\\beta_j}$.\n\\end{itemize}\n\n", "meta": {"hexsha": "e54cd47c5b5ecb9c0db102d62cc196c93728eb9e", "size": 13654, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Business Analytics/lectures/logit.tex", "max_stars_repo_name": "YourPsychiatrist/TUM", "max_stars_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 225, "max_stars_repo_stars_event_min_datetime": "2019-10-02T10:49:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T22:25:38.000Z", "max_issues_repo_path": "Business Analytics/lectures/logit.tex", "max_issues_repo_name": "YourPsychiatrist/TUM", "max_issues_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-02-16T12:22:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-31T19:35:57.000Z", "max_forks_repo_path": "Business Analytics/lectures/logit.tex", "max_forks_repo_name": "YourPsychiatrist/TUM", "max_forks_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 69, "max_forks_repo_forks_event_min_datetime": "2019-10-02T21:46:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T19:27:50.000Z", "avg_line_length": 44.0451612903, "max_line_length": 213, "alphanum_fraction": 0.6945217519, "num_tokens": 4671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338729, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7341218226274826}}
{"text": "\\section{Parametric and Nonparametric Models}\n\nA statistical model $\\mathfrak{F}$ is a family of functions. \\textit{Parametric models} can be parametrized by a finite number of parameters. For example, the Gaussian Normal distribution $\\mathscr{\\mu,\\sigma^2}$ has the two parameters $\\mu$ and $\\sigma^2$. The general form is:\n\n\\begin{equation}\n\\mathfrak{F} = \\{f(x;\\theta): \\theta \\in \\Theta \\}\n\\end{equation}\n\nWhere $\\theta$ is a vector of parameters and $\\Theta$ is the parameter space. Elements of $\\theta$ that are not of interest are called \\textit{nuisance parameters}. \\textit{Nonparametric models} cannot be described by a finite number of parameters. An example is an interpolating spline.\n\n\n% fundamental concepts\n\\section{Fundamental Concepts in Inference}\n\n\n% point estimations\n\\subsection{Point Estimators}\nPoint estimation refers to providing a single best guess of some quantity of interest. The point estimator is denoted with a had, i.e. $\\hat{\\theta}$. The point estimator for some quantity based on $n$ datapoints:\n\n\\begin{equation}\n\\hat{\\theta}_n = g(X_1,X_2,...,X_n)\n\\end{equation}\n\n\n% bias\n\\subsection{Bias}\nA point estimator $\\hat{\\theta}$ has bias:\n\n\\begin{equation}\n\\mathrm{bias}(\\hat{\\theta}_n) = \\mathbb{E}_\\theta (\\hat{\\theta}) - \\theta\n\\end{equation}\n\nWhere $\\theta$ is the \"true\" value $\\theta_n \\rightarrow \\theta$ as $n \\rightarrow \\infty$. $\\mathbb{E}_{\\theta}(r(X)) = \\int r(x) f(x;\\theta) \\mathrm{d}x$. \n\n% consistency\n\\subsection{Consistency}\n\nA point estimator $\\hat{\\theta}_n$ is consistent if $\\hat{\\theta}_n \\xrightarrow{P}\\theta$. That is, it converges in probability to $\\theta$. $\\hat{\\theta}_n$ is consistent with both bias and standard error approach $0$ as $n\\rightarrow \\infty$.\n\n\n\\subsection{Sampling Distribution, Standard Error}\n\nThe distribution of $\\hat{\\theta}_n$ is the \\textit{sampling distribution}. The standard deviation of the distribution of $\\hat{\\theta}_n$ is the \\textit{standard error}, denoted $\\mathrm{se}$. \n\n\\begin{equation}\n\\mathrm{se}(\\hat{\\theta}_n) = \\sqrt{\\mathbb{V}(\\hat{\\theta}_n)}\n\\end{equation} \n\nThe standard error might depend on the unknown population CDF, in which case it is estimated. The point estimator for the standard error is then $\\hat{\\mathrm{se}}$. \n\n\n\n\\subsubsection{Example: Bernoulli Distribution}\n\nLet $X_1,X_2,X_3 \\sim \\mathrm{Bernoulli}(p)$. The point estimator for $p$ based on $n$ datapoints is $\\hat{p}_n = \\frac{1}{n}\\sum_{i=1}^n X_i$. Then the expected value of the point estimator $\\mathbb{E}(\\hat{p}_n) = \\frac{1}{n}\\sum_{i=1}^n \\mathbb{E}(X_i) = p$, so that $\\hat{p}_n$ is unbiased. The standard error is $\\mathrm{se} = \\sqrt{\\mathbb{V}(\\hat{p}_n)} = \\sqrt{\\frac{p(1-p)}{n}}$. The estimated standard error is $\\hat{\\mathrm{se}} = \\sqrt{\\frac{\\hat{p}(1-\\hat{p})}{n}}$.\n\n\n% MSE\n\\subsection{Mean Squared Error}\nThe quality of a point estimator is often measured using the \\textit{mean squared error}:\n\n\\begin{equation}\n\\mathrm{MSE} = \\mathbb{E}_{\\theta}(\\hat{\\theta}_n - \\theta)^2 = \\mathrm{bias}^2(\\hat{\\theta}_n) + \\mathbb{V}_{\\theta}(\\hat{\\theta}_n)\n\\end{equation}\n\n\n% Asymptotically Normal\n\\subsection{Asymptotically Normal Estimators}\nAn asymptotically normal estimator satisfies:\n\n\\begin{equation}\n\\frac{\\hat{\\theta}_n - \\theta}{\\mathrm{se}} \\xrightarrow{dist} \\mathscr{N}(0,1)\n\\end{equation}\n\n\n% confidence sets\n\\subsection{Confidence Sets}\n\nA confidence set $C_n$ is the subset of parameters $\\theta$ that has a greater than $1-\\alpha$ probability of containing the true value of $\\theta$.\n\n\\begin{equation}\n\\mathbb{P}_{\\theta}(\\theta \\in C_n)\\geq 1-\\alpha\\ \\mathrm{\\ for\\ all\\ }\\theta\\in\\Theta\n\\end{equation}\n\n\\subsubsection{Normal-Based Confidence Intervals}\n\nIf $\\hat{\\theta}_n \\approx \\mathscr{N}(\\theta,\\hat{\\mathrm{se}}^2)$ and $z_{\\frac{\\alpha}{2}} = \\Phi^{-1}(1-\\frac{\\alpha}{2})$ the value of the standard normally distributed random variable $Z$ at which $\\mathbb{P}(-\\frac{\\alpha}{2} < Z < \\frac{\\alpha}{2}) = 1-\\alpha$, then, transforming backwards, $\\mathbb{P}(\\hat{\\theta}_n - z_{\\frac{\\alpha}{2}}\\hat{\\mathrm{se}} < \\theta < \\hat{\\theta}_n + z_{\\frac{\\alpha}{2}}\\hat{\\mathrm{se}} ) = 1-\\alpha$. Hence, the confidence interval for a normally distributed point estimator $\\hat{\\theta}_n$ is: \n\n\\begin{equation}\nC_n = (\\hat{\\theta}_n - z_{\\frac{\\alpha}{2}}\\hat{\\mathrm{se}},\\hat{\\theta}_n + z_{\\frac{\\alpha}{2}}\\hat{\\mathrm{se}})\n\\end{equation}\n\nFor a 95\\% confidence interval $\\alpha=0.05$ and $z_{\\frac{\\alpha}{2}} = 1.96 \\approx 2$, so that the confidence interval is approximately $\\hat{\\theta}_n \\pm 2 \\hat{\\mathrm{se}}$. \n\n\n\\subsubsection{Pointwise and Uniform Asymptotic Confidence Intervals}\n\nA \\textit{pointwise asymptotic} confidence interval requires:\n\n\\begin{equation}\n\\liminf_{n\\rightarrow \\infty} \\mathbb{P}_{\\theta}(\\theta \\in C_n) \\geq 1-\\alpha,\t\\ \\ \\forall \\theta \\in \\Theta\n\\end{equation}   \n\nA \\textit{uniform asymptotic} confidence interval requires:\n\n\\begin{equation}\n\\lim_{n\\rightarrow \\infty}\\inf_{\\theta \\in \\Theta} \\mathbb{P}_{\\theta}(\\theta \\in C_n) \\geq 1-\\alpha\n\\end{equation}\n\n\n\\subsection{Pivots, Pivotal Quantities}\nPivotal quantities are functions of the sample that are independent of the distribution parameters of the sample. For example, if $X=(X_1,X_2,...,X_n)$ is a random sample from a distribution with parameters $\\theta$, then the random variable $g(X,\\theta)$ is a pivot if it has the same distribution regardless of the choice of $\\theta$. An example is the $z$-score $z = \\frac{x-\\mu}{\\sigma}$. The $z$-score may require population parameters to be known (in this case $\\mu$,$\\sigma$) but it's distribution is independent of them. \n\n", "meta": {"hexsha": "7461242ddb01801b7c3ec59f64324c91d728a545", "size": 5600, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/stats_modelsinference.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/stats_modelsinference.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/stats_modelsinference.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.1228070175, "max_line_length": 543, "alphanum_fraction": 0.7133928571, "num_tokens": 1725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7340778444159616}}
{"text": "% !TeX root = ../main.tex\n\n\\chapter{Theory}\\label{theory}\n\n\\section{SVM}\nA \\acrfull{svm} is a machine learning algorithm which tries to separate binary-class training data. The \\gls{svm} achieves this by searching for a hyperplane or a set of hyperplanes to separate the points of training data in a multidimensional space. There might be several possible hyperplanes that sufficiently separate the data but a \\gls{svm} searches for the hyperplane with the biggest perpendicular distance between the hyperplane and the borders of both classes that should be separated. The space between the hyperplane and the closest of the training data points is defined as the margin. If the algorithm finds the maximal margin it has also found the optimal hyperplane. See Figure \\ref{fig:svmHyperplaneSeparation} for an example of possible hyperplane separations.\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.5]{figures/theorySVM_hyperplanes}\n\t\\caption{Separation of two classes by hyperplanes in 2 dimensional space. $H_1$ does not separate, $H_2$ and $H_4$ separate but the margin is very slim, $H_3$ separates with a much better margin.}\n\t\\label{fig:svmHyperplaneSeparation}\n\\end{figure}\n\n\\subsection*{Formal definition}\nSince a \\Gls{svm} is a binary classifier a data point $x$ has to either belong into class A or class B. Let the training dataset of $n$ points be represented as $x_0,\\dots,x_n$ and the target values be $y_0,\\dots,y_n \\in {-1,+1}$. The values of $y_n$ should be \n\\begin{equation}\n\ty_i=\n\t\t\\begin{cases}\n\t\t+1 & \\text{if } x_i \\in \\text{class } {\\color{red}A} \\\\\n\t\t-1 & \\text{if } x_i \\in \\text{class } {\\color{blue}B}\n\t\t\\end{cases}.\t\n\\end{equation}\nThe optimal hyperplane should separate all vectors $x_i$ with a value of $y_i=1$ {(class ${\\color{red}A}$)} and those with a value of $y_i=-1$ {(class ${\\color{blue}B}$)} so that the distance between those two groups is maximal \\cite{Thome2012}. Let the hyperplane be\n\\begin{equation}\n\tD(x)=W \\bullet x+b\n\\end{equation}\n\nwhere $W$ is a vector normal to the hyperplane (see Figure \\ref{fig:svmHyperplaneDistance}) and $b$ is the bias \\cite{Boser1992}. $D(x)$ has to be calculated so that\n\\begin{equation}\n\tx \\in \n\t\\begin{cases}\n\t\\text{class } {\\color{red}A} & \\text{if } D(x) > 0 \\\\\n\t\\text{class } {\\color{blue}B} & \\text{if } D(x) < 0\n\t\\end{cases}\t\n\\end{equation}\nis true. The distance between a point $X$ and the hyperplane $D(x)$ is given as\n\\begin{equation}\n\\frac{D(X)}{\\|W\\|}\n\\end{equation}\nwhich is illustrated in Figure \\ref{fig:svmHyperplaneDistance} \\cite{Thome2012}. Assuming that the data is linear separable {(as in Figure \\ref{fig:svmHyperplaneSeparation})} we can then select two hyperplanes ${\\color{red}D(x)>0}$ and ${\\color{blue}D(x)<0}$ so that there are no points in between them and try to maximize the distance between those two hyperplanes {(in Figure \\ref{fig:svmHyperplaneSeparation} $H_2$ and $H_4$)} which is then given as \n\\begin{equation}\n\\frac{2}{\\|W\\|}.\n\\end{equation}\nTo maximize the distance we must therefore minimize $\\|W\\|$ but with the constraint {(\\ref{eq:svmHyperplaneCondition})} that no data gets between the two hyperplanes {(hard-margin classification)}. Both constraints\n\\begin{equation}\n\t\\begin{split}\n\tx_i \\bullet w+b \\geq +1 \\quad \\text{if } {\\color{red}y_i=+1}\\\\\n\tx_i \\bullet w+b \\leq -1 \\quad \\text{ if } {\\color{blue}y_i=-1}\n\t\\end{split}\n\\label{eq:svmHyperplaneCondition}\n\\end{equation}\ncan be combined to $y_i(x_i\\bullet w + b)\\geq 1\\quad \\forall i, i=1\\dots n$. The solution for a maximum margin can therefore be found by solving\n\\begin{equation}\n\\begin{split}\n\\operatorname*{arg\\,min}_{w, b}\t\\left\\{\\frac{1}{2}\\|W\\|^2\\right\\} \\text{subject to} \\\\\ny_i(x_i\\bullet w + b)-1\\geq 0 \\quad \\forall i, i=1\\dots n\t\n\\end{split}\n\\end{equation}\nwith the Lagrangian multiplier method \\cite{Thome2012}. \n\nIf the data is not linear separable we have to relax the constraints from \\ref{eq:svmHyperplaneCondition} and allow some points in the margin {(soft-margin-classification)}. \n\nClassification of unknown data is now simply done through a calculation of the decision function $D(x)$\n\\begin{equation}\n\\text{prediction}\n\t\\begin{cases}\n\tx \\in \\text{class } {\\color{red}A} & \\text{if } D(x) > 0 \\\\\n\tx \\in \\text{class } {\\color{blue}B} & \\text{if } \\text{otherwise}\n\t\\end{cases}\t\n\\end{equation}\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.4]{figures/theorySVM_distanceToW}\n\t\\caption{Visualization of optimal margin and hyperplane in 2 dimensional space. The distance of Point $X$ to $D(x)$ is $\\frac{D(X)}{\\|W\\|}$. Source Bosner et al. \\cite{Boser1992}.}\n\t\\label{fig:svmHyperplaneDistance}\n\\end{figure}\n\nHowever, there are still cases where the data can not be separated by a linear function as shown in Figure \\ref{fig:svmKernelTrick}. In this case the data is mapped into another higher dimensional feature space {(Kernel trick)} so that it becomes linear separable again.\n\n\\begin{figure}\n\t\\centering\n\t\\subfloat[Data not separable]{\\includegraphics[width=55mm]{figures/theorySVM_kernelTrick1}}\n\t\\subfloat[Data separable]{\\includegraphics[width=55mm]{figures/theorySVM_kernelTrick2}}\n\t\\subfloat[Data separable with hyperplane]{\\includegraphics[width=55mm]{figures/theorySVM_kernelTrick3}}\t\n\t\\caption{Illustration of Kernel trick. Data in {(a)} is not separable but if the data gets mapped into a higher dimensional space {(b)} a linear hyperplane can be fitted {(c)}. Figures plotted with code from \\texttt{http://www.eric-kim.net/eric-kim-net/posts/1/kernel\\_trick.html}}\n\t\\label{fig:svmKernelTrick}\n\\end{figure}\n\n\\subsection*{Multiclass SVMs}\n\\label{subsec:svmMulticlass}\nIn case of a multiclass \\gls{svm} problem the most popular approach is to use several different binary class \\glspl{svm} instead of only one multiclass \\gls{svm} \\cite{Hsu2002, Duan2005, Thome2012}. There are two common solutions for the multiclass problem: One-VS-Rest and One-VS-One.\n\nA One-VS-Rest multiclassifier with $n$ classes consists of $n$ distinct \\glspl{svm}. Each \\gls{svm} is trained on one of the classes as class A and the others as class B. Classification is done in a \"winner-takes-it-all\" fashion meaning that the \\gls{svm} with the highest output function assigns the class label.\n\nIn the One-VS-One approach $n\\frac{n-1}{2}$ \\glspl{svm} are constructed. Each class is paired in a \\gls{svm} with each other class. Classification is done in a \"majority-vote\" fashion so each \\gls{svm} votes for its class and the class with the most votes is assigned as the class label.\n\n\\section{K-Nearest neighbors}\nThe \\gls{knn} algorithm is a lazy classification algorithm which stores the complete training data in the learning phase \\cite{Keller1985}. In the classification phase it searches for the $k$ points in the training data that are nearest to the point that should be classified. The label that gets the majority of votes from the $k$ closest points {(neighbors)} is the result of the classification. See Figure \\ref{fig:knn3} for a three class example and $k=3$. \n\nThe most popular metric to get the distance between the neighbors is the Euclidean distance however the accuracy can greatly be improved by using a learned distance metric such as the Mahanalobis distance which tries to maximize the margin between classes \\cite{Weinberger2005}. \n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/theoryKNN_3}\n\t\\caption{Example for a knn classification with $k=3$. The three nearest elements to the purple pentagon {(point that should be classified)} are marked with a square. Since two of the three neighbors are triangles the new point should also be a triangle.}\n\t\\label{fig:knn3}\n\\end{figure}\n\n\\section{Convolutional Neural Networks}\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.35]{figures/theoryCNN_model}\n\t\\caption{Sample architecture of a \\gls{cnn}. Source: Christodoulidis and Anthimopoulos \\cite{Christodoulidis2015}}\n\t\\label{fig:cnnModel}\n\\end{figure}\nA \\acrfull{cnn} is a multi-layer-feed-forward neural network that emulates the processes in the visual cortex by employing feature detection with small convolutional filters. \\glspl{cnn} generally outperform other gradient based learning techniques \\cite{LeCun1998} and are currently state-of-the-art \\cite{Russakovsky2015} for image recognition.\n\n\\glspl{cnn} usually consist of a succession of trainable convolutional and dense layers and pooling layers. Normally the first layers comprise of several convolutional and pooling layers for feature extraction. For the classifications of features extracted in the previous layers, the network has at least one dense layer of neurons before the last layer. The last layer is usually the output layer and for the standard classification task the number of neurons is equal to the number of classes to classify so that the output of a neuron is the probability of a specific class at the same time. Figure \\ref{fig:cnnModel} shows an example of a \\gls{cnn} architecture with two convolutional and pooling layers and a dense, fully connected layer before the output layer. \n\n\\subsection*{Convolutional layers}\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/theoryCNN_filter}\n\t\\caption{96 convolutional filters of size $3\\times 11\\times 11$ in the first layer. Filters trained on \\gls{ilsvrc}-2010. Source: Krizhevsky et al. \\cite{Krizhevsky2012}}\n\t\\label{fig:cnnFilter}\n\\end{figure}\nConvolutional layers contain multiple convolutional filters or kernels. They convolve the image to extract image features. Each filter convolves the output of the previous layer. In case of the first layer the filters operate directly on the input image. In later layers the collect more complex features from previous layers. Convolution happens by calculating the dot-product of the input matrix with the convolutional filter. Filters in \\glspl{cnn} usually overlap which helps to get a better translation invariance since each pixel is convolved multiple times by the same filter. The main goal of convolution in \\glspl{cnn} is to get distinctive image features. These convolutional filters are not handcrafted like filters in typical feature detectors. They learn the best filters by learning large quantities of data and change over the time and are ultimately able to extract features that are characteristic for the problem. Often these kernels extract simple features like horizontal, vertical or diagonal edges {(figure \\ref{fig:cnnFilter})}. For food prominent first layer kernels typically includes many color kernels that specialize in extracting a range of similar colors \\cite{Christodoulidis2015}. The basic idea behind convolutional filters is that many features like edges or corners appear in multiple locations in images. By using the filters as a sliding window one filter is able to detect the feature in any position.  \n\nTherefore the main befit of using convolutional filters is the reduction of learnable weights. Filters are very small {(7x7 as the maximum size for a current \\gls{cnn} \\cite{Szegedy2014})} but are applied on the whole image in a sliding window approach. This means that a single convolutional filter shares weights for the image which significantly improves learning because it reduces the number of parameters to learn \\cite{LeCun1998}. GoogLeNet, a 22-layer \\gls{cnn}, uses \\gls{rgb} input images with a size of 224x224 \\cite{Szegedy2014}. A normal Neural Net without convolutions would not be able to handle this input size.\n\n\\subsection*{Pooling layers}\nOnce a feature is detected the exact position becomes less important. Only the spatial relation to other features remains valuable. Knowing the exact position of a feature may even be harmful for generalization because the model becomes less invariant to position \\cite{LeCun1998}. One way to solve this problem and reduce the number of weights to learn is subsampling. In \\glspl{cnn} this normally occurs in pooling layers. The most common type pooling layer is currently max-pooling. This filter basically divides the input into $z\\times z$ blocks and extracts the maximum value of each block. A popular max-pooling layer is a $z=2$, stride $s=2$ layer. This layer downsamples the input by two. Recently, overlapping max-pooling layers have become popular \\cite{Szegedy2014}. They do not downsample as much as non-overlapping pooling layers {(in fact $z=3$ and $s=2$ outputs the same dimensions as the input)} but they seem to slightly decrease the error \\cite{Krizhevsky2012}.\n\n\\subsection*{Overfitting and Dropout}\n\\label{subsec:overfittingDropout}\nAlthough \\glspl{cnn} need fewer parameters to train high dimensional inputs than conventional neural nets, they also have the tendency to overfitt. Overfitting is a common problem in machine learning that occurs if models are very complex. An overfitted model is optimized across the training data and describes or \"fits\" this data so well that it can not explain unseen data \\cite{Falkenauer1998}. Figure \\textbf{XX} shows an overifitting neural network. After epoch \\textbf{XX} the error on the training set continues to decrease but the error on the validation set increases which means that although the net gets better at predicting the training data it gets worse for predicting unseen data.\n\nDropout is a novel way for neural nets to reduce the problem of overfitting by randomly dropping out nodes from the model. This forces the net to generalize better \\cite{Srivastava2014}.\n\n\\subsection*{Learning rate and momentum}\n\\label{subsec:learningMomentum}\nNeural networks try to find the global minimum of their cost function by adjusting the network weights. If there is only one minimum this is fairly easy as the network only has to adjust the weights towards the downward gradient. Real world scenarios however, are much more complex and include many local minima as well. \n\nLearning rate and momentum are measurements of how weights are adjusted in backpropagation in search of the global minima. The learning rate denotes the magnitude of the weight change. That means that networks with a high learning rate advance faster along the gradient. Momentum is a term that multiplies a fraction of the previous weight update to the weight adjustment. By applying momentum, the steps the network takes on the gradient towards the minimum get bigger with each iteration. This helps to increase the speed of learning and may also prevent the network get stuck on local minima and saddle points because of the \"momentum\" the network simply \"steps over\" these points.\n\n\\section{Colour features}\n\\label{sec:theory_colour}\nTodo {(maybe)}\n\n\n\n\n\\section{Feature detectors and descriptors}\nA common approach in image classification is the use of feature detectors and feature descriptors. A feature detector detects interest points or keypoints in images. Ideally those keypoints are invariant to image transformations like rotation, scale or illumination changes so that the points can be found even if the image is rotated or taken from another perspective. In most cases keypoints are corners as corners be can be localized quite easily. Knowing that a corner exist however does not help much with recognition. An algorithm also needs to describe the characteristics of an interest point so that it is possible to compare different interest points. The part of describing a keypoint is done by keypoint descriptors.\n\n\\subsection[HOG]{Histograms of oriented gradients (HOG)}\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[scale=0.45]{data/images/theory/theoryHOG_VisualizationGradients}\n\t\\caption{Visualization of HOG descriptor.}\n\t\\label{fig:hogVisualization}\n\\end{figure}\n\n\\acrfull{hog} is a popular image descriptor for human detection by Dalal and Triggs in 2005 \\cite{Dalal2005}. The algorithm makes use of **TODO: WORD MISSING** by describing the distribution local gradients. This approach is believed to be based on biological processes of neurons in the primary visual cortex \\cite{Lowe2004}.\n\nThe first step is to divide the image into small blocks with a size of 16x16 pixels and a 50\\% overlap for better results. Each block is then subdivided by four 8x8 pixel cells. For each of these cells, gradient intensities are computed by applying the 1-D centered point derivative convolution mask horizontally and vertically:\n\\begin{equation}\n\tD_x=\n\t\\begin{bmatrix}\n\t-1 & 0 & 1\n\t\\end{bmatrix} \n\t\\quad\n\tD_y=\n\t\\begin{bmatrix}\n\t-1 \\\\ 0 \\\\ 1\n\t\\end{bmatrix} \n\\end{equation}   \nThe magnitude of the gradients is\n\\begin{equation}\n\tm=\\sqrt{(I\\ast D_x)^2+(I\\ast D_y)^2}\n\\end{equation}\nwhere $I$ is the image cell and the gradient orientation is given as\n\\begin{equation}\n\t\\theta = \\arctan \\left[\\ \\frac{(I\\ast D_y)}{(I\\ast D_x)}\\right]\\text{.}\n\\end{equation}\nTo achieve a better illumination invariance like shadowing it is useful to contrast-normalize each cell. \n\nTo get a feature vector for each cell a 9-bin histogram of the gradient orientations {(0\\degree - 180\\degree)} is calculated. The gradient orientations $\\theta$ are then scaled by the corresponding magnitude $m$. In Figure \\ref{fig:hogVisualization} there is a visualization of gradient histograms. The gradient histogram in the center row on the right, is a single horizontal line meaning that the gradients in this cell are all horizontal which is logical because the original image in this cell is a horizontal edge.\n\nTo get the feature vector for the whole image all histograms are concatenated to form a large gradient histogram.\n\n\\gls{hog} is not rotation invariant which does not matter for human detection as humans tend to always have the same upright orientation. However for food rotation invariance is quite important.\n\n\\subsection[LBP]{Local Binary Pattern (LBP)}\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{figures/theoryLBP_coding}\n\t\\caption{Example for a LBP coding of the center pixel with value 6 (a). The neighboring pixels are thresholded against the center value (b) and multiplied by values in (c) with the result in (d). Source: Ojala et al. \\cite{Ojala1999}}\n\t\\label{fig:lbpCoding}\n\\end{figure}\n\\acrfull{lbp} is a simple texture descriptor which was originally proposed by Ojala et al. in 1994 \\cite{Ojala1994}. For the calculation of the \\gls{lbp} descriptor the 8 neighbors in a 3x3 block for each pixels are taken into account {(Fig \\ref{fig:lbpCoding}a)}. The neighbors of the center pixel are then thresholded by comparing the value {(grayscale intensity)} of the pixel in the center to the intensities of the neighboring pixels. Pixels with a higher or equal value are getting labeled as \"1\" and \"0\" otherwise {(Fig \\ref{fig:lbpCoding}b)}. Each position in the 3x3 block is then assigned a weight of $2^n$ where $n$ is ascending from left-to-right, top-to-bottom {(Fig \\ref{fig:lbpCoding}c)}. In recent publications these weights are labeled clockwise ascending. The binary values are than multiplied by the corresponding weights {(Fig \\ref{fig:lbpCoding}d)}. The values are then summed up and assigned as the new value for this \"texture unit\". The values can then be inserted into a histogram to form a 256-dim feature vector since there are 256 possible LBP values {($2^8=256$)}. Local binary patterns are invariant to grayscale changes because \\gls{lbp} describes spatial texture structure but not contrast intensities \\cite{Ojala1999}.  \n\nIn the following years \\gls{lbp} has been adapted and extended with additional contrast information \\cite{Ojala1999} or different neighborhood sizes to achieve rotation invariance with uniform \\glspl{lbp} \\cite{Ojala2002}.\n\n\n\\subsection[SIFT]{Scale invariant feature transform (SIFT)}\n\\label{subsec:sift}\n\\acrfull{sift} is a very popular local image feature detector, descriptor and matcher by Lowe from 1999 \\cite{Lowe1999}. It is invariant to uniform image scaling, translation and rotation and partially invariant to affine distortions, 3D viewpoint and illumination changes. It is also invariant to noise, partial occlusion and clutter \\cite{Lowe1999}. \n\n\\subsubsection*{Keypoint detection}\n%\\begin{figure}\n%\t\\centering\n%\t\\begin{minipage}{.5\\textwidth}\n%\t\t\\centering\n%\t\t\\includegraphics[width=0.45\\linewidth]{data/images/theory/theorySIFT_gaussianScales}\n%\t\t\\captionof{figure}{Image with different Gaussian scales.}\n%\t\t\\label{fig:gaussianScales}\n%\t\\end{minipage}%\n%\t\\begin{minipage}{.5\\textwidth}\n%\t\t\\centering\n%\t\t\\includegraphics[width=0.45\\linewidth]{data/images/theory/theorySift_dog}\n%\t\t\\captionof{figure}{Example of a Difference of Gaussians with $\\sigma=1$ and $\\sigma=3$.}\n%\t\t\\label{fig:dog}\n%\t\\end{minipage}\n%\\end{figure}\n\n\\begin{figure}\n\t\\centering\n\t\\begin{minipage}{.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=0.45\\linewidth]{figures/theorySIFT_scaleSpaceFiltering}\n\t\t\\captionof{figure}{Sequence of Gaussian smoothings of a 1D graph with $\\sigma$ increasing from bottom to top. Source Witkins \\cite{Witkin1983}}\n\t\t\\label{fig:scaleSpaceFiltering}\n\t\\end{minipage}%\n\t\\begin{minipage}{.5\\textwidth}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.45\\linewidth]{figures/theorySIFT_interestPointDetection}\n\t\t\t\\captionof{figure}{Interest points are detected by searching for minima and maxima. The value of the center pixel {(marked with X)} is compared to its 26 neighbors {(marked with circles)} on the current and adjacent scales. Source: Lowe \\cite{Lowe2004}}\n\t\t\t\\label{fig:interestPointDetection}\n\t\\end{minipage}\t\n\\end{figure}\n\n\nThe basic idea of \\gls{sift}'s keypoint extraction follows Witkins scale-space filtering \\cite{Witkin1983}. Witkins found out that by applying Gaussian smoothings at different scales of $\\sigma$ on a 1D-graph he could find robust edges depending on the scale of $\\sigma$ {(Figure \\ref{fig:gaussianScales})}. Since this process can also be applied to 2D images scale-space filtering is a good way to find scale invariant interest points {(also called \\gls{log})} {(See figure \\ref{fig:gaussianScales} for an example)}. \\gls{sift} however uses a much more computation efficient approximation of \\gls{log} called \\acrfull{dog} \\cite{Lowe2004}. \\gls{dog} can be computed by subtracting two adjacent scales from each other. Figure \\ref{fig:dogScaleFiltering} shows the process of creating \\glspl{dog} at different scales. Figure \\ref{fig:dog} shows the result of a \\gls{dog} operation on an image. \\gls{sift} samples 3 scales per octave. After each octave the image size is halved and \\gls{dog} is applied again on the smaller image {(Figure \\ref{fig:dogScaleFiltering})}.\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.3]{figures/theorySIFT_dogScaleFiltering}\n\t\\caption{For each octaves the image is blurred with Gaussian smoothings at rising scales. A \\gls{dog} is formed by subtracting two adjacent scales. After each octave the image size is halved and the process repeated. Source: Lowe \\cite{Lowe2004}}\n\t\\label{fig:dogScaleFiltering}\n\\end{figure}\n\nTo check if a pixel qualifies as an interest point at a certain scale, \\gls{sift} compares the values of the 3x3 neighboring pixels. If the pixel has the maximum or minimum value \\gls{sift} then compares the neighbors on the scales above and below. If the pixel has indeed the lowest or highest value across all 27 points it is taken as a potential interest point {(figure \\ref{fig:interestPointDetection})}. The cost of this operation is reasonably low because most of the pixels will be eliminated after the first few comparisons \\cite{Lowe2004}. To filter weak interest points, \\gls{sift} tries to eliminate low contrast points and points on edges since edges are not very robust features. After the elimination of weak points, \\gls{sift} computes a 32-bin gradient orientation histogram in the interest point neighborhood. Orientations are weighted by the magnitude of the gradient. Each bin represents 10\\degree of the 360 possible orientations. The bin with the highest peak is then selected as the dominant orientation for this keypoint. Bins with at least 80\\% of the highest bin value are selected to form a additional new keypoint.\n\n\\subsubsection*{Keypoint description}\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.2]{figures/theorySIFT_descriptor}\n\t\\caption{Creation of the \\gls{sift} descriptor. Around the keypoint a 16x16 region {(this image is only half the size)} is taken and gradient orientations are calculated. The region forms 16 4x4 blocks with 8-bin gradient histograms. Source Lowe \\cite{Lowe2004}}\n\t\\label{fig:siftDescriptor}\n\\end{figure}\nThe \\gls{sift} keypoint descriptor relies on gradient orientation histograms. They are more stable features than just raw intensity values and less sensitive to 3D rotation. To calculate a descriptor for a keypoint, a neighborhood region of 16x16 pixels is selected oriented along the dominant orientation of the keypoint. The 16x16 region is then divided into 4x4 blocks and for each of these blocks a 8-bin gradient orientation histogram is calculated {(similar to the keypoint extraction)}. This results in a 128 dimensional feature vector for each keypoint {($16\\text{ blocks}*8\\text{ bins per histogram}=128$)} \\cite{Lowe2004}. Figure \\ref{fig:siftDescriptor} shows the process of the descriptor creation.\n\n\\subsection[SURF]{Speeded up robust features (SURF)}\n\\label{subsec:surf}\n\\gls{surf} is a feature detector and descriptor which was proposed in 2006 \\cite{Bay2006} and later revised in 2008 by Bay et al. \\cite{Bay2008}. It was developed with the goal to provide a faster alternative for the popular \\gls{sift} algorithm without trade offs in recognition performance.\n\n\\subsubsection*{Keypoint detection}\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.2]{figures/theorySURF_boxFilters}\n\t\\caption{Left half: discretized and cropped Gaussian second order partial derivates in $y$-direction and $xy$-direction. Right half: corresponding box filter approximations. Gray ares are equal to zero. Source Bay et al. \\cite{Bay2008}}\n\t\\label{fig:surfBoxFilters}\n\\end{figure}\nLike \\gls{sift}, \\gls{surf} also uses scale spaces to detect interest points. \\gls{surf} however relies on an approximation of the Hessian matrix\n\nThe first step is to compute the integral image. In integral images pixel values are the sum of all pixels within a square between the pixel and the origin. These representations are efficient to compute and allow to find the sum of pixel values for any sized box within the image with only four arithmetic operations. Throughout the algorithm this benefit is leveraged to speed up detection and description.\n\nThey approximate the Hessian matrix by using box filters {(in the right of figure \\ref{fig:surfBoxFilters})}. By using integral images in combination with box filters the process of scale space creation can be sped up significantly. The benefit of box filters contrary to Gaussians which have to be applied iteratively is, that box filters can be applied directly at the original image which makes parallelization possible. In addition \\gls{surf} does not downscale after each octave. It scales the image up which has the advantage of not causing aliasing. To localize interest points across scales \\gls{surf} applies non-maximal suppression on a 3x3x3 neighborhood. \n\n\\subsubsection*{Keypoint description}\nTo achieve rotation invariance \\gls{surf} computes a dominant orientation for each interest point from a circular 6$s$ neighborhood by calculating Haar-wavelet responses in $x$ {(horizontal wavelet response)} and $y$ {(vertical wavelet response)} directions with $s$ being the scale of the interest point. Again the combination of integral images and wavelets helps to calculate Haar-wavelets efficiently. The dominant orientation is calculated by the use of a sliding rotating window with an angle of $\\frac{\\pi}{3}$. The wavelet responses are then represented as vectors weighted with a Gaussian of $\\sigma=2.5s$. Horizontal and vertical vectors are added and the highest sum is the dominant interest point orientation.\n\nTo describe a keypoint, \\gls{surf} forms a square neighborhood region oriented along the dominant orientation with a size of 20$s$ {(so keypoints at higher scales include a bigger neighborhood)}. The region is then divided into 4x4 smaller sub-regions. In each of these sub-regions \\gls{surf} computes features at 5x5 evenly spaced sample points. Contrary to \\gls{sift}, \\gls{surf} does not utilize orientation histograms but again Haar-wavelet responses in horizontal $d_x$ and vertical $d_y$ direction relative to the dominant keypoint orientation. $d_x$ and $d_y$ are then summed up over each subregion. Those two and the sum of absolute response values $|d_x|$ and $|d_y|$ from the four dimensional feature vector for each subregion. Therefore each keypoint has a 64 dimensional feature vector taking into account that there are 16 subregions each with a four dimensional vector. To achieve additional invariance to contrast and illumination changes the feature vector is turned into a unit vector.    \n\n\\subsection[ORB]{Oriented FAST and Rotated BRIEF (ORB)}\n\\gls{orb} is a combination of the corner detection algorithm \\gls{fast} \\cite{Rosten} and the binary descriptor \\gls{brief} \\cite{Calonder2010}. \\gls{orb} was introduced by Rublee and Bradski in 2011 \\cite{Rublee2011} as replacement for \\gls{sift} for low-power devices and real time performance.\n\n\\subsubsection*{FAST keypoint detection}\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.3]{figures/theoryFAST_corners}\n\t\\caption{FAST corner detection. Interest points are selected if at least 12 adjoining pixel values that are either above or below the center pixels intensity {(dashed line)}. Source: Rosten and Drummond \\cite{Rosten}.}\n\t\\label{fig:fastCorners}\n\\end{figure}\n\\gls{fast} is a corner detection algorithm by Rosten and Drummond from 2006 that does not rely on Gaussians or scale spaces. \\gls{fast} compares 16 pixel intensities arranged on a circle with radius 9 around a possible corner point in the center. It is an interest point has at least 12 adjoining pixel values that are either above or below the center pixels intensity {(figure \\ref{fig:fastCorners})}. \\gls{fast} however, is prone to have many responses along edges which are weaker features so \\gls{brief} tries to filter these edge responses by using a Harris corner measure. To achieve scale invariance \\gls{brief} applies \\gls{fast} on different image pyramid scale spaces. To also make the keypoints rotation invariant \\gls{brief} calculates the intensity centroid which assumes that a corner's maximum intesity is offset from the actual center of the corner. This makes it possible to calculate the orientation by creating the vector from the intensity centroid to the actual corner point.\n\n\\subsubsection*{BRIEF keypoint description}\n\\gls{brief} is a binary descriptor from 2010 by Calonder et al. \\cite{Calonder2010}. Unlike \\gls{sift} or gls{surf} a binary descriptor creates the descriptor values by comparing intensity values of pixels in the neighborhood of the keypoint. If the intensity of pixel $a$ is lower than the intensity of pixel $b$ than the test yields \"1\" and \"0\" otherwise. To create the feature vector \\gls{brief}  performs 256 binary tests and concatenates the results. The pixels that are compared are chosen by a Gaussian distribution around the center of the keypoint. Prior to these tests the image is smoothed. Additional in-plane rotation invariance is achieved by the proposed \"steered\" \\gls{brief}. Steered \\gls{brief} rotates the matrix of binary tests by a rotation matrix along the keypoint orientation. A lookup table with precomputed \\gls{orb} features is computed with a 12\\degree interval. However due to the very rotation by steered \\gls{brief}, the binary tests loose most of their variance so the expressiveness of the descriptor suffers. To prevent this, Rublee and Bradski proposed an algorithm to \"learn\" the optimal location of the pixel-pairs that are compared for the binary tests.\n\n\\subsection[CenSurE]{Center surround extremas (CenSurE)}\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[scale=0.2]{figures/theoryCenSurE_filters}\n\t\\caption{Center surround filters. From left to right: decreasing accuracy and computational cost.  Source Agrawal et al. \\cite{Agrawal2008}}\n\t\\label{fig:censureFilters}\n\\end{figure}\nThe \\gls{censure} feature detector was proposed by Agrawal et al. in 2008 as a framework of several bi-level filters for interest point detection \\cite{Agrawal2008}. \\gls{censure} is scale and rotation invariant and similar to the way \\gls{sift} and \\gls{surf} perform interest point detection. Contrary to the aforementioned keypoint detectors, \\gls{censure} does not up- or downscale the image in scale space and therefore does not inherit the disadvantages of up- and downscaling like inaccurate keypoint locations.\n\nTo detect corners \\gls{censure} employs approximations of \\gls{log} with center-surround discrete bi-level filters. The closest approximation of \\gls{log} is a circular bi-level filter as shown in figure \\ref{fig:censureFilters}a. Bi-level means that the filter only contains two values namely $1$ or $-1$. The circular filter is rotation invariant due to its symmetry but it is also expensive to compute. Therefore \\gls{censure} uses octagons and boxes as approximations of the circular filter. Like \\gls{surf}, \\gls{censure} also leverages integral images for box filters and applies them on five scales. Since a major shortcoming of box filters is the lack of rotation invariance Agrawal et al. also proposed an octagon shaped filter which resembles the circle filter much more closely. Integral images however do not work with diagonal edges and thus do not work with octagons. To make computation still possible Agrawal et al. introduced \"slanted\" integral images which are able to construct any trapezoidal area in the same amount of time as rectangular integral images. \n\nTo detect interest points, \\gls{censure} performs non-maximal suppression over scale space across a 3x3x3 neighborhood. Weak interest points are filtered by threshold and edges are filtered the Harris corner measure.\n\n%\\subsection{DAISY}\n\n\\section{Bag of Words}\n\\acrfull{bow} or bag of features, bag of visual words or bag of keypoints is a simple, yet powerful image feature quantization method. The original idea of a \\gls{bow} approach for images came from texture classification \\cite{Leung2001}. Leung and Malik found out that by quantification of small texture patches {(textons)} in histograms they were able to accurately classify different textures. In 2004 Csurka et al. refined this approach and applied it to general image classification \\cite{Csurka2004}.\n\nThe idea behind a \\gls{bow} is very simple: During learning the \\gls{bow} clusters image descriptors using $k$-means clustering. The clustered representation of the image descriptors is called vocabulary. The vocabulary size is $k$, so using $K=1000$ for the k-mean clustering results in a vocabulary of 1000 image features. Choosing $k$ is a trade-off between speed and accuracy and has to be determined during experiments. In an ideal world, a \\gls{bow} clusters image features together that are unique and expressive so that we would have a vocabulary of bread, salad, meat and noodle features.\n\nDuring classification the \\gls{bow} gets a set of image descriptors and matches these features with the previously learned vocabulary. The output of this process is a histogram of vocabulary occurrences. Referring to the ideal world example, the \\gls{bow} would get a set of features including many that look like bread, some that look like meat and a few that are similar to the salad texton. The output would be a histogram with a large value for the bread bin and some smaller values for the salad and meat bins. Giving this occurrence vector to a trained SVM would reveal that the image might be a Hamburger.\n\n%\\subsection{Matchers}\n\n%\\subsubsection*{Brute force}\n\n%\\subsubsection*{Flann Based}\n\n%\\subsubsection*{knnMatch}\n\n%\\section{Size and Volume estimation}\n\n", "meta": {"hexsha": "6cb9bd4cb0d3be82de0515192b54e95e3efbbf95", "size": 35860, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapters/03_theory-Apollo.tex", "max_stars_repo_name": "felixSchober/Deep-Food", "max_stars_repo_head_hexsha": "1cac55e945949cb5a04d742b35c023379a162c34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:46.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-13T19:38:17.000Z", "max_issues_repo_path": "Thesis/chapters/03_theory-Apollo.tex", "max_issues_repo_name": "Jorba123/Deep-Food", "max_issues_repo_head_hexsha": "1cac55e945949cb5a04d742b35c023379a162c34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Thesis/chapters/03_theory-Apollo.tex", "max_forks_repo_name": "Jorba123/Deep-Food", "max_forks_repo_head_hexsha": "1cac55e945949cb5a04d742b35c023379a162c34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-03-25T07:53:09.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-13T14:17:35.000Z", "avg_line_length": 107.0447761194, "max_line_length": 1441, "alphanum_fraction": 0.7878973787, "num_tokens": 8972, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.73407784115707}}
{"text": "\\chapter{}\n\n\\define{1} Let \\(f(\\cdot)\\) be a density. \n\\begin{itemize}\n    \\item The class \\(\\left\\{f(\\cdot-\\mu\\}_{\\mu \\in \\mathbb{R}}\\right.\\) is called the location family with standard density \\(f(\\cdot)\\), and \\(\\mu\\) is called the location parameter for the family. \n    \\item The class \\(\\{(1 / \\sigma) f(\\cdot / \\sigma)\\}_{\\sigma \\in(0, \\infty)}\\) is called the scale family with standard density \\(f(\\cdot)\\), and \\(\\sigma\\) is called the scale parameter for the family. \n    \\item By extension, the class \\(\\{(1 / \\sigma) f((\\cdot-\\mu) / \\sigma)\\}_{(\\mu, \\sigma) \\in \\mathbb{R} \\times(0, \\infty)}\\) is called the location-scale family with standard density \\(f(\\cdot)\\).\n\\end{itemize}\n\n\\begin{ex}\n    \\begin{enumerate}[(a)]\n        \\item Let \\(f(\\cdot)\\) be a density, let \\((\\mu, \\sigma) \\in \\mathbb{R} \\times(0, \\infty)\\). Show that \\(X\\) is a random variable with density\n        \\[\n        \\frac{1}{\\sigma} f\\left(\\frac{\\cdot-\\mu}{\\sigma}\\right)\n        \\]\n        if and only if there exists a random variable \\(Z\\) with density \\(f(\\cdot)\\) such that \\(X=\\sigma Z+\\mu\\).\n        \\item Let \\(X \\sim\\) Cauchy \\((0,1)\\), and recall that its density is given by\n        \\[\n        f(x)=\\frac{1}{\\pi} \\frac{1}{1+x^{2}}, \\quad x \\in \\mathbb{R} .\n        \\]\n        Consider the location-scale family generated by \\(f\\). We know that \\(\\mathbb{E}|X|=\\infty\\), and thus the parameters \\(\\mu\\) and \\(\\sigma^{2}\\) cannot be interpreted as the mean and the variance of \\(X\\). Notwithstanding this, show that\n        \\begin{enumerate}[(i)]\n            \\item \\(\\mathbb{P}(X \\geq \\mu)=\\mathbb{P}(X \\leq \\mu)=\\frac{1}{2} ;\\)\n            \\item \\(\\mathbb{P}(X \\geq \\mu+\\sigma)=\\mathbb{P}(X \\leq \\mu-\\sigma)=\\frac{1}{4}\\). \n        \\end{enumerate}  In other words, \\(\\mu-\\sigma, \\mu\\) and \\(\\mu+\\sigma\\) are the first, second and third quartiles of \\(f\\) (hint: consider first the case \\(\\mu=0\\) and \\(\\sigma=1\\)). \n        \\item We say a family of c.d.f.s \\(\\{F(x \\mid \\theta)\\}_{\\theta \\in \\Theta}\\) is stochastically increasing in \\(\\theta\\) when \\[\\theta_{1}>\\theta_{2}\\Rightarrow F\\left(x \\mid \\theta_{1}\\right)\\text{ is stochastically greater than }F\\left(x \\mid \\theta_{2}\\right), \\]i.e., \\(F\\left(x \\mid \\theta_{1}\\right) \\leq F\\left(x \\mid \\theta_{2}\\right), x \\in \\mathbb{R}\\), and \\(F\\left(x_{0} \\mid \\theta_{1}\\right)<F\\left(x_{0} \\mid \\theta_{2}\\right)\\) for some \\(x_{0}\\). Show that \n        \\begin{enumerate}[(i)]\n            \\item a location family is stochastically increasing in its location parameter; \n            \\item a scale family is stochastically increasing in its scale parameter if its support is \\([0, \\infty)\\).\n        \\end{enumerate}\n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}\n        \\item\n        $\\Rightarrow:$ If $X\\sim\\frac{1}{\\sigma}f\\left(\\frac{\\cdot-\\mu}{\\sigma}\\right)$, Let $Z=\\frac{X-\\mu}{\\sigma}$, \n        \\begin{align*}\n            P(Z\\leqslant z)&=P\\left(\\frac{X-\\mu}{\\sigma}\\leqslant z\\right)\\\\\n            &=P\\left(X\\leqslant\\sigma z+\\mu\\right). \n        \\end{align*}\n        \\[\n            F_Z(z)=F_X(\\sigma z+\\mu), \n        \\]\n        \\begin{align*}\n            f_Z(z)&=\\sigma f_X(\\sigma z+\\mu)\\\\\n            &=\\sigma \\frac{1}{\\sigma}f_X\\left(\\frac{\\sigma z +\\mu-\\mu}{\\sigma}\\right)\\\\\n            &=f_X(z)\n        \\end{align*}\n        Which means $Z$ has density $f(\\cdot)$. \n\n        $\\Leftarrow$: If $Z\\sim f(z)$, $X=\\sigma Z+\\mu$, \n        \\begin{align*}\n            P(X\\leqslant x)&=P(\\sigma Z+\\mu\\leqslant x)\\\\\n            &=P(Z\\leqslant\\frac{x-\\mu}{\\sigma})\\\\\n            &=F_Z\\left(\\frac{x-\\mu}{\\sigma}\\right), \n        \\end{align*}\n        So, \\[\n            f_X(x)=\\frac{1}{\\sigma}f_Z\\left(\\frac{x-\\mu}{\\sigma}\\right). \n        \\]\n        \\item \\begin{enumerate}[(i)]\n            \\item Because for a density function $f(\\cdot)$, $\\int f(x) \\der x=1$, and Cauchy distribution is symmetric about the y-axis. So, \n            \\[\n                P(X\\leqslant0)=P(X\\geqslant0)=1/2. \n            \\]\n            \\item \\[\n                P(X\\leqslant1)=P(X\\geqslant1)=\\int_1^\\infty\\frac{1}{\\pi}\\frac{1}{1+x^2}\\der x=\\frac{1}{\\pi}\\arctan(x)\\big|_1^\\infty=1/4. \n            \\]\n        \\end{enumerate}\n        \\item \\begin{enumerate}[(i)]\n            \\item For a location family: $F(x|\\mu)=F(x-\\mu)$. If $\\mu_1>\\mu_2$, then $x-\\mu_1<x-\\mu_2$, \n            \\[\n                F(x|\\mu_1)<F(x|\\mu_2). \n            \\]\n            So, it is stochastically increasing. \n            \\item For a location family: $F(x|\\sigma)=1/\\sigma F(x/\\sigma)$. If $\\sigma_1>\\sigma_2$, then $1/\\sigma_1<1/\\sigma_2$, \n            \\[\n                F(x|\\sigma_1)<F(x|\\sigma_2). \n            \\]\n            So, it is stochastically increasing, too. \n        \\end{enumerate}\n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    We saw the following result in class (an adaptation of Theorem 1.6.4 in Bickel and Doksum \\((2002)\\), p. 60\\()\\).\n    \n    \\thm{1} Suppose that \\(\\{f(\\boldsymbol{x} \\mid \\eta)\\}_{\\eta \\in \\mathcal{E}}\\) is a canonical exponential family generated by \\(\\left(T_{k \\times 1}, h\\right)\\), where \\(\\mathcal{E} \\subseteq \\mathbb{R}^{k}, \\mathcal{E} \\neq \\emptyset\\), is open. Then, the following are equivalent.\n    \\begin{enumerate}[(i)]\n        \\item For any \\(\\eta \\in \\mathcal{E}\\), the random variables \\(1, T_{1}(\\boldsymbol{X}), \\ldots, T_{k}(\\boldsymbol{X})\\) are not a.s. linearly dependent, i.e.\n        \\[\n            \\left(\\mathbf{a}, a_{k+1}\\right) \\equiv\\left(a_{1}, \\ldots, a_{k}, a_{k+1}\\right) \\neq \\mathbf{0} \\Rightarrow \\mathbb{P}_{\\eta}\\left(\\langle\\mathbf{a}, T(\\boldsymbol{X})\\rangle=a_{k+1}\\right)<1, \n        \\]\n        where \\(T(\\boldsymbol{X}):=\\left(T_{1}(\\boldsymbol{X}), \\ldots, T_{k}(\\boldsymbol{X})\\right)^T\\); \n        \\item \\(\\eta \\in \\mathcal{E}\\) is identifiable;\n        \\item for any \\(\\eta \\in \\mathcal{E}, \\operatorname{Var}_{\\eta}(T)\\) is symmetric positive definite;\n        \\item \\(\\mathcal{E} \\ni \\eta \\mapsto A^{\\prime}(\\eta)\\) is an injective mapping;\n        \\item \\(\\mathcal{E} \\ni \\eta \\mapsto A(\\eta)\\) is a strictly convex mapping. \n    \\end{enumerate}\n    We showed in class that \\((i) \\Leftrightarrow(i i) \\Leftrightarrow(i i i)\\). Finish the theorem.\n    \n    \\rmk{1} Notice that, for a generic function \\(f, f\\) being strictly convex does not imply that \\(f^{\\prime \\prime}(x)\\) is a positive definite matrix.\n\n    \\emph{\\bfseries Suggested route:} \\((v) \\Rightarrow(i v),(i i i) \\Rightarrow(v),(i v) \\Rightarrow(i i)\\). The latter two claims are simpler than the former. So, for \\((v) \\Rightarrow(i v)\\), consider the following definition and propositions. \n\n    \\define{2} Let \\(C\\) be a convex set, and consider \\(F: C \\rightarrow \\mathbb{R}^{k}\\). We say \\(F\\) is monotone on \\(C\\) if\n    \\[\n    \\left\\langle F(x)-F\\left(x^{\\prime}\\right), x-x^{\\prime}\\right\\rangle \\geq 0, \\quad x \\neq x^{\\prime},\n    \\]\n    and strictly monotone if strict inequality holds. Now prove the next two propositions. \n\n    \\prop{1} Let \\(C\\) be a convex set, and consider \\(F: C \\rightarrow \\mathbb{R}^{k}\\). If \\(F\\) is strictly monotone on \\(C\\), then \\(F\\) is injective.\n\n    \\prop{2} Let \\(C\\) be an open, convex set, and consider \\(f: C \\rightarrow \\mathbb{R}\\). If \\(f\\) is strictly convex and differentiable on \\(C\\), then \\(f^{\\prime}\\) is strictly monotone.\n\n    On a related note, it can be shown that the converse to Proposition \\(2.2\\) is also true.\n\\end{ex}\n\n\\begin{solution}\n    \\emph{First, prove propositions 2.1: }\n\n    If $F$ is not injective, then $\\exists\\, x_1\\neq x_2$, s.t. $F(x_1)=F(x_2)$. So, $F$ is not strictly monotone. And we get a contradiction, i.e. $F$ must be injective. \n\n    \\emph{Propositions 2.2 is the definition of convex function. }\n\n    \\emph{$v\\to iv$: }\n\n    Because $\\eta$ is open set, and $f:\\,\\eta\\to A(\\eta)$ is strictly convex, then $A'(\\eta)$ is strictly monotone, and is an injective mapping. \n\n    \\emph{$iii\\to v$: }\n\n    $Var_\\eta(T)>0$, i.e. $A''(\\eta)>0$, then $A(\\eta)$ is strictly convex. \n\n    \\emph{$iv\\to ii$: }\n\n    If $\\exists\\,\\eta_1\\neq\\eta_2$, s.t. $f(x|\\eta_1)=f(x|\\eta_2)$. Then \n    \\[\n        A'(\\eta_1)=E_{\\eta_1}(T(X))=E_{\\eta_2}(T(X))=A'(\\eta_2). \n    \\]\n    So, we ge the contradiction. i.e. $\\eta$ is identifiable. \n\\end{solution}\n\n\\begin{ex}\n    Let \\(X \\sim \\mathcal{N}\\left(\\mu, \\sigma^{2}\\right)\\). Consider any \\(g \\in C^{1}(\\mathbb{R})\\) such that \\(\\mathbb{E}_{\\eta}\\left|g^{\\prime}(X)\\right|<\\infty\\). \n    \\begin{enumerate}[(a)]\n        \\item (Stein's identity) Prove Stein's identity, i.e., that\n        \\[\n        \\mathbb{E}_{\\eta}\\left(\\left(\\frac{h^{\\prime}(X)}{h(X)}+\\sum_{i=1}^{k} \\eta_{i} T_{i}^{\\prime}(X)\\right) g(X)\\right)=-\\mathbb{E}_{\\eta} g^{\\prime}(X)\n        \\]\n        in canonical parametrization. \n        \n        Hint: consider first the case \\(\\mu=0\\) and \\(\\sigma^{2}=1\\). Let \\(\\phi(\\cdot)\\) be the density function. Now use the fact that \\(\\phi^{\\prime}(z)=-z \\phi(z)\\) to rewrite \\(\\phi(x)\\) as an integral from \\(x\\) to \\(\\infty\\) and as another integral from \\(-\\infty\\) to \\(x\\) in the expression\n        \\[\n            -\\mathbb{E} g^{\\prime}(X)=-\\mathbb{E} g^{\\prime}(X)\\left(1_{[0, \\infty)}(X)+1_{(-\\infty, 0)}(X)\\right). \n        \\]\n        \\item By choosing polynomial \\(g(\\cdot)\\) functions, use Stein's identity to calculate the third and fourth moments of the \\(\\mathcal{N}\\left(\\mu, \\sigma^{2}\\right)\\) distribution.\n        \n        \\rmk{2} Stein's identity is one aspect of the so-named Stein's method for establishing limits in distribution and their rates of convergence.\n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item First, $\\mu=0$, $\\sigma^2=1$. Then \n        \\[\n            \\phi(z)=\\frac{1}{\\sqrt{2\\pi}}\\exp\\left(-\\frac{z^2}{2}\\right). \n        \\]\n        \\[\n            \\phi'(z)=-z\\frac{1}{\\sqrt{2\\pi}}\\exp\\left(-\\frac{z^2}{2}\\right)=-z\\phi(z). \n        \\]\n        Then \n        \\[\n            \\begin{aligned}\n                E[g'(Z)]&=\\int_{-\\infty}^\\infty g'(z)\\phi(z)\\der z\\\\\n                &=\\int_{-\\infty}^0 g'(z)\\phi(z)\\der z + \\int_{0}^\\infty g'(z)\\phi(z)\\der z\\\\\n                &=\\int_{-\\infty}^0 g'(z)\\phi(z)\\der z + \\int_{0}^\\infty g'(z)\\int_z^\\infty -\\phi'(t)\\der t \\der z\\\\\n                &=\\int_{-\\infty}^0 g'(z)\\phi(z)\\der z + \\int_{0}^\\infty g'(z)\\int_z^\\infty t\\phi(t)\\der t \\der z\\\\\n                &=\\int_{-\\infty}^0 g'(z)\\phi(z)\\der z + \\int_{0}^\\infty\\int_z^\\infty g'(z) t\\phi(t)\\der t \\der z\\\\\n                &=\\int_{-\\infty}^0 g'(z)\\phi(z)\\der z + \\int_{0}^\\infty\\int_0^t g'(z) t\\phi(t)\\der z \\der t\\\\\n                &=\\int_{-\\infty}^0 g'(z)\\phi(z)\\der z + \\int_{0}^\\infty (g(t)-g(0))t\\phi(t)\\der t\\\\\n                &=\\int_{-\\infty}^0 (g(t)-g(0))t\\phi(t)\\der t + \\int_{0}^\\infty (g(t)-g(0))t\\phi(t)\\der t\\\\\n                &=E[z(g(z)-g(0))]=E[zg(z)-zg(0)]=E[zg(z)]. \n            \\end{aligned}\n        \\]\n        Let $g(x)=\\phi\\left(\\frac{x-\\mu}{\\sigma}\\right)$, then\n        \\[\n            E[g'(x)]=E\\left[\\frac{1}{\\sigma}\\phi'\\left(\\frac{x-\\mu}{\\sigma}\\right)\\right]=\\frac{1}{\\sigma}E\\left[\\frac{x-\\mu}{\\sigma}\\phi\\left(\\frac{x-\\mu}{\\sigma}\\right)\\right]=\\frac{1}{\\sigma}E\\left[\\frac{x-\\mu}{\\sigma}g(x)\\right]\n        \\]\n        For normal distribution: \n        \\[\n            \\begin{aligned}\n            \\phi(x)&=\\frac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left(-\\frac{(x-\\mu)^2}{2\\sigma^2}\\right)\\\\\n            &=\\frac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left(-\\frac{1}{2\\sigma^2}x^2+\\frac{\\mu}{\\sigma^2}x-\\frac{\\mu^2}{2\\sigma^2}\\right)\n            \\end{aligned}\n        \\]\n        $h'(x)=0$, and $T'_1(x)=x$, $T'_2(x)=1$, $\\eta=(-1/\\sigma^2, \\mu/\\sigma^2)$. \n        \\[\n            \\begin{aligned}\n                &\\quad E\\left(\\left(\\frac{h^{\\prime}(X)}{h(X)}+\\sum_{i=1}^{k} \\eta_{i} T_{i}^{\\prime}(X)\\right) g(X)\\right)\\\\\n                &=E\\left(\\left(-\\frac{1}{\\sigma^2}x+\\frac{\\mu}{\\sigma^2}\\right) g(X)\\right)\\\\\n                &=E\\left(\\frac{\\mu-x}{\\sigma^2} g(X)\\right)\\\\\n                &=-\\frac{1}{\\sigma} E\\left(\\frac{x-\\mu}{\\sigma} g(X)\\right)\\\\\n                &=-E(g'(x)). \n            \\end{aligned}\n        \\]\n        \\item We can know that \\[\n            \\frac{1}{\\sigma} E\\left(\\frac{x-\\mu}{\\sigma} g(X)\\right)=E(g'(x)), \n        \\]\n        then let $g(x)=x^2$, \n        \\[\n            E\\left(\\frac{x-\\mu}{\\sigma^2}x^2\\right)=2\\mu, \\Rightarrow E(x^3)=3\\mu\\sigma^2+\\mu^3. \n        \\]\n        Let $g(x)=x^3$, then\n        \\[\n            E\\left(\\frac{x-\\mu}{\\sigma^2}x^3\\right)=3(\\sigma^2+\\mu^2), \\Rightarrow E(x^4)=6\\mu^2\\sigma^2+\\mu^4+3\\sigma^4. \n        \\]\n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Prove that any (measurable) injective function of a minimal sufficient statistic is a minimal sufficient statistic. \n\\end{ex}\n\n\\begin{solution}\n    Let $T(X)$ be a minimal sufficient statistic, $T^*(X)=f(T(X))$, $g(T^*(X))=T(X)$. Because $T(X)$ is minimal, there is another sufficient statistic $G(X)$ and a measurable function $h$, s.t. \n    \\[\n        h(G(X))=T(X), \n    \\]\n    then\n    \\[\n        (f\\circ h)(G(X))=f(T(X))=T^*(X). \n    \\]\n    So, $T^*(X)$ is also minimal. \n\\end{solution}\n\n\\begin{ex}\n    Prove that, for any two statistics \\(T, T^{*}\\),\n    \\[\n    T(\\mathbf{X})=T(\\mathbf{Y}) \\Leftrightarrow T^{*}(\\mathbf{X})=T^{*}(\\mathbf{Y}) \\quad \\mathcal{P}-a.s.\n    \\]\n    if and only if there are functions \\(f\\) and \\(g\\) such that\n    \\[\n    T(\\mathbf{X})=f\\left[T^{*}(\\mathbf{X})\\right], \\quad T^{*}(\\mathbf{X})=g[T(\\mathbf{X})] \\quad \\mathcal{P}-a.s.\n    \\]\n\\end{ex}\n\n\\begin{solution}\n    $\\Leftarrow: $\n\n    If $T^*(X)=T^*(Y)\\Leftrightarrow T(X)=T(Y)$, then\n    \\[\n        T^*(X)=T^*(Y)\\rightarrow f(T^*(X))=f(T^*(Y))\\rightarrow T(X)=T(Y). \n    \\]\n\n    If $T(X)=T(Y)$, then\n    \\[\n        T(X)=T(Y)\\rightarrow g(T(X))=g(T(Y))\\rightarrow T^*(X)=T^*(Y). \n    \\]\n\n    $\\Rightarrow: $\n\\end{solution}\n\n\\begin{ex}\n    Establish the following claims. \n    \\begin{enumerate}[(a)]\n        \\item Let \\(T\\) and \\(T^{*}\\) be two statistics. Then, there are measurable functions \\(f, g\\) such that \n        \\[\n            T=f\\left(T^{*}\\right)\\text{ and }T^{*}=g(T)\n        \\]\n        if and only if \\(\\sigma(T)=\\sigma\\left(T^{*}\\right)\\)\n        (i.e., the \\(\\sigma\\)-algebras generated by \\(T\\) and \\(T^{*}\\) are identical). \n        \n        Hint: recall, from probability theory, that if \\(\\mathbf{X}\\) and \\(\\mathbf{Y}\\) are two random vectors such that \\(\\mathbf{Y}\\) is \\(\\sigma(\\mathbf{X})\\)-measurable, then there exists a measurable function \\(\\varphi\\) such that \\(\\mathbf{Y}=\\varphi(\\mathbf{X})\\). \n        \\item Conclude that if we drop the condition \" \\(\\mathcal{P}\\)-a.s.\" in the definition of equivalent statistics, the slightly stronger notion of equivalence we obtain is identical to the equality of the \\(\\sigma\\)-algebras generated by the statistics in question. \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item We know that $T$ is $\\sigma(T^*)-$measurable and $T^*$ is also $\\sigma(T)-$measurable. So, $\\sigma(T)=\\sigma(T^*)$. \n        \n        On the other hand, because $\\sigma(T)=\\sigma(T^*)$, there are $f$ and $g$, s.t. $T=f(T^*)$, $T^*=g(T)$. \n        \\item \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Let \\(\\mathcal{P}=\\{f(\\mathbf{x} \\mid \\theta)\\}_{\\theta \\in \\Theta}\\) be a parametric family. \n    \\begin{enumerate}[(a)]\n        \\item Prove that \\(\\mathbf{X}\\) is sufficient for \\(\\theta\\). \n        \\item In addition, suppose \\(\\mathcal{P}\\) corresponds to an i.i.d. sample. Prove that \\(\\left(X_{(1)}, \\ldots, X_{(n)}\\right)^T\\) is sufficient for \\(\\theta\\). \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item $\\prod_{i=1}^nf(x_i|\\theta)$, $h(X)=1$, $g(T(X), \\theta)=g(X,\\theta)=\\prod_{i=1}^nf(x_i|\\theta)$. So, $X$ is sufficient. \n        \\item $\\prod_{i=1}^nf(x_{(i)}|\\theta)$, $h(X)=1$, $g(T(X), \\theta)=g((X_{(1)}, \\cdots,X_{(n)})^T,\\theta)=\\prod_{i=1}^nf(x_{(i)}|\\theta)$. So, $(X_{(1)}, \\cdots,X_{(n)})^T$ is sufficient. \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Let \\(f\\) be a positive integrable function over \\((0, \\infty)\\), and let \\(p(x \\mid \\theta)\\) be the probability density function over \\((0, \\theta)\\) the density defined by\n    \\[\n        p(x \\mid \\theta)=\\left\\{\\begin{array}{cl}\n        c(\\theta) f(x), & 0<x<\\theta \\\\\n        0, & \\text { otherwise }\n        \\end{array}\\right.\n    \\]\n    If \\(X_{1}, \\ldots, X_{n}\\) are i.i.d. with density \\(p(\\cdot \\mid \\theta)\\), show that \\(X_{(n)}\\) is sufficient for \\(\\theta\\). \n\\end{ex}\n\n\\begin{solution}\n    \\[\n        \\prod_{i=1}^n c(\\theta)f(x_i)\\mathbf{1}_{x_i<\\theta}=c^n(\\theta)\\prod_{i=1}^nf(x_i)\\mathbf{1}_{x_{(n)}<\\theta}, \n    \\]\n    $h(x)=\\prod_{i=1}^nf(x_i)$, $g(T(X),\\theta)=c^n(\\theta)\\mathbf{1}_{x_{(n)}<\\theta}$. So, $X_{(n)}$ is sufficient. \n\\end{solution}\n\n\\begin{ex}\n    Let \\(f\\) be a positive integrable function over \\(\\mathbb{R}\\), and let \\(p(x \\mid \\xi, \\eta)\\) be the probability density function defined by\n    \\[\n        p(x \\mid \\xi, \\eta)=\\left\\{\\begin{array}{cl}\n        c(\\xi, \\eta) f(x), & \\xi<x<\\eta \\\\\n        0, & \\text { otherwise }\n        \\end{array}\\right.\n    \\]\n    If \\(X_{1}, \\cdots, X_{n}\\) are i.i.d. with density \\(p(\\cdot \\mid \\xi, \\eta)\\), show that \\(\\left(X_{(1)}, X_{(n)}\\right)\\) is sufficient for \\((\\xi, \\eta)\\).\n\\end{ex}\n\n\n\\begin{solution}\n    \\[\n        \\prod_{i=1}^np(x_i|\\xi, \\eta)=\\prod_{i=1}^nc(\\xi, \\eta) f(x_i)\\mathbf{1}_{\\xi<X_{(1)}, X_{(n)}<\\eta}, \n    \\]\n    $h(x)=\\prod_{i=1}^nf(x_i)$, $g(T(X),\\xi,\\eta)=c^n(\\xi,\\eta)\\mathbf{1}_{\\xi<X_{(1)}, X_{(n)}<\\eta}$. So, $X_{(1)}, X_{(n)}$ is sufficient for $\\xi,\\eta$. \n\\end{solution}\n\n\n\\begin{ex}\n    \\begin{enumerate}[(a)]\n        \\item Prove that, if \\(\\mathbf{x}=\\left(x_{1}, \\ldots, x_{n}\\right)\\) and \\(\\mathbf{y}=\\left(y_{1}, \\ldots, y_{n}\\right)\\) have the same elementary symmetric functions\n        \\[\n            \\sum_{i} x_{i}=\\sum_{i} y_{i}, \\quad \\sum_{i \\neq j} x_{i} x_{j}=\\sum_{i \\neq j} y_{i} y_{j}, \\quad \\ldots, \\quad \\prod_{i} x_{i}=\\prod_{i} y_{i}\n        \\]\n        then \\(\\mathbf{y}\\) is a permutation of \\(\\mathbf{x}\\). \n        \\item Consider a family \\(\\mathcal{P}=\\{f(\\cdot \\mid \\theta)\\}_{\\theta \\in \\Theta}\\), where \\(f(\\cdot \\mid \\theta)\\) is an a.c. density for an i.i.d. sample for all \\(\\theta\\), and set\n        \\[\n            T(\\mathbf{X})=\\left(X_{(1)}, \\ldots, X_{(n)}\\right)^T .\n        \\]\n        Now consider \\(U=\\left(U_{1}(X), \\ldots, U_{n}(X)\\right)^T\\), where\n        \\[\n            U_{1}(X)=\\sum_{i} X_{i}, \\quad U_{2}(X)=\\sum_{i \\neq j} X_{i} X_{j}, \\quad \\ldots, \\quad U_{n}(X)=\\prod_{i} X_{i} .\n        \\]\n        Conclude that \\(U\\) and \\(T\\) are equivalent. \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item We know that elementary symmetric function $e_i(\\cdot)$ is the coefficients for the expansion of the following polynomial: \n        \\[\n            \\prod_{i=1}^n(\\lambda-X_i)=\\sum_{j=0}^n(-1)^je_j(X_1,\\cdots,X_n)\\lambda^{n-j}, \n        \\]\n        $e_0(\\cdot)=1$. So, we can get that \n        \\[\n            \\sum_{j=0}^n(-1)^je_j(X_1,\\cdots,X_n)\\lambda^{n-j}=\\sum_{j=0}^n(-1)^je_j(Y_1,\\cdots,Y_n)\\lambda^{n-j}\n        \\]\n        \\[\n            \\Rightarrow \\prod_{i=1}^n(\\lambda-X_i)=\\prod_{i=1}^n(\\lambda-Y_i). \n        \\]\n        From the multiplicative exchange law, we know that \\(\\mathbf{y}\\) is a permutation of \\(\\mathbf{x}\\). \n        \\item \n        \\[\n            f_1(U(X))=\\sum_iX_i=\\sum_iX_{(i)}=g_1(T(X)), \n        \\]\n        \\[\n            f_2(U(X))=\\sum_{i<j}X_iX_j=\\sum_{i<j}X_{(i)}X_{(j)}=g_2(T(X)), \n        \\]\n        \\[\n            \\cdots\\cdots\n        \\]\n        \\[\n            f_n(U(X))=\\prod_{i}X_i=\\prod_{i}X_{(i)}=g_n(T(X)). \n        \\]\n        So, $T(X)=(g_1^{-1}\\circ f_1,\\cdots,g_n^{-1}\\circ f_n)(U(X))$, $U(X)=(f_1^{-1}\\circ g_1,\\cdots,f_n^{-1}\\circ g_n)(T(X))$, they are equivalent. \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Show that the order statistics are minimal sufficient for the location family\n    \\[\n        p(\\mathbf{x} \\mid \\theta)=f\\left(x_{1}-\\theta\\right) \\ldots f\\left(x_{n}-\\theta\\right)\n    \\]\n    when\n    \\[\n        f(x)=\\frac{1}{\\pi} \\frac{1}{1+x^{2}},\n    \\]\n    i.e., Cauchy \\((0,1)\\). \n\\end{ex}\n\n\\begin{solution}\n    \\[\n        P(X|\\theta)=\\prod_{i=1}^nf(x_i-\\theta)=\\pi^{-n}\\prod_{i=1}^n(1+(x_i-\\theta)^2)^{-1}, \n    \\]\n    If $x\\neq y$, \n    \\[\n        \\frac{P(X|\\theta)}{P(Y|\\theta)}=\\frac{\\prod_{i=1}^n(1+(x_i-\\theta)^2)^{-1}}{\\prod_{i=1}^n(1+(y_i-\\theta)^2)^{-1}}, \n    \\]\n    this ratio must be dependent on $\\theta$. So, when $x$ is a permutation of $y$, it is independent on $\\theta$. And in this case, $x_{(1)}=y_{(1)}, \\cdots, y_{(n)}=y_{(n)}$. Then, $(X_{(1)}, \\cdots, X_{(n)})$ is minimal sufficient statistic. \n\\end{solution}\n\n\\begin{ex}\n    Consider the curved exponential family \\(\\{n \\text { i.i.d. } \\mathcal{N}(\\theta, \\theta)\\}_{\\theta>0}\\). Show that the sufficient statistic\n    \\[\n        T(\\mathbf{X})=\\left(\\sum_{i=1}^{n} X_{i}, \\sum_{i=1}^{n} X_{i}^{2}\\right)^T\n    \\]\n    is not minimal. \n\\end{ex}\n\n\\begin{solution}\n    \\[\n        \\begin{aligned} \n            \\prod_{i=1}^{n} f\\left(x_{i} \\mid \\theta\\right) &=\\prod_{i=1}^{n} \\frac{1}{\\sqrt{2 \\pi \\theta}} \\exp^{-\\frac{\\left(x_{i}-\\theta\\right)^{2}}{2 \\theta}} \\\\ &=(2 \\pi \\theta)^{-\\frac{n}{2}} \\prod_{i=1}^{n} \\exp \\left\\{-\\frac{1}{2 \\theta}\\left(x_{i}^{2}-2 \\theta x_{i}+\\theta^{2}\\right)\\right\\} \\\\ &=(2 \\pi \\theta)^{-\\frac{n}{2}} \\exp \\left\\{-\\frac{1}{2 \\theta}\\left(\\sum_{i=1}^{n} x_{i}^{2}-2 \\theta \\sum_{i=1}^{n} x_{i}+n \\theta^{2}\\right)\\right\\} \\\\ &=(2 \\pi \\theta)^{-\\frac{n}{2}} \\exp \\left\\{\\sum_{i=1}^{n} x_{i}\\right\\} \\exp \\left\\{-\\frac{1}{2 \\theta} \\sum_{i=1}^{n} x_{i}^{2}\\right\\} \\exp \\left\\{-\\frac{n \\theta}{2}\\right\\}, \n        \\end{aligned}\n    \\]\n    So, $T^*(X)=\\sum_{i=1}^nx_i^2$ is another sufficient statistic. Let $f(x_1,x_2)=x_2$, then \n    \\[\n        f(T(X))=\\sum_{i=1}^nx_i^2 = T^*(X). \n    \\]\n    But we can not find a function s.t. $g(T^*(X))=T(X)$. Thus, $T(X)$ is not minimal. \n\\end{solution}\n\n\\begin{ex}\n    Let \\(\\{f(\\mathbf{x} \\mid \\theta)\\}_{\\theta \\in \\mathbb{R}}\\) the parametric family corresponding to i.i.d. random variables with joint density function\n    \\[\n        \\begin{aligned}\n            f(\\mathbf{x} \\mid \\theta)&=C \\exp \\left\\{-\\sum_{i=1}^{n}\\left(x_{i}-\\theta\\right)^{4}\\right\\}\\\\\n            &=C \\exp \\left(-n \\theta^{4}\\right) \\exp \\left\\{4 \\theta^{3} \\sum_{i=1}^{n} x_{i}-6 \\theta^{2} \\sum_{i=1}^{n} x_{i}^{2}+4 \\theta \\sum_{i=1}^{n} x_{i}^{3}-\\sum_{i=1}^{n} x_{i}^{4}\\right\\}\n        \\end{aligned}\n    \\]\n    for some \\(C>0\\). Express the parameter space and show that\n    \\[\n        T(\\mathbf{X})=\\left(\\sum_{i=1}^{n} X_{i}, \\sum_{i=1}^{n} X_{i}^{2}, \\sum_{i=1}^{n} X_{i}^{3}\\right)^T\n    \\]\n    is a minimal sufficient statistic. \n\\end{ex}\n\n\\begin{solution}\n    \\begin{align}\n        \\begin{aligned}\n        \\frac{f(\\mathrm{x} \\mid \\theta)}{f(\\mathrm{y} \\mid \\theta)}=& \\exp \\left\\{4 \\theta^{3}\\left(\\sum_{i=1}^{n} x_{i}-\\sum_{i=1}^{n} y_{i}\\right)-6 \\theta^{2}\\left(\\sum_{i=1}^{n} x_{i}^{2}-\\sum_{i=1}^{n} y_{i}^{2}\\right)\\right.\\\\\n        &\\left.+4 \\theta\\left(\\sum_{i=1}^{n} x_{i}^{3}-\\sum_{i=1}^{n} y_{i}^{3}\\right)-\\left(\\sum_{i=1}^{n} x_{i}^{4}-\\sum_{i=1}^{n} y_{i}^{4}\\right)\\right\\}, \n        \\end{aligned}\n    \\end{align}\n    if we want $\\frac{f(\\mathrm{x} \\mid \\theta)}{f(\\mathrm{y} \\mid \\theta)}$ is independent on $\\theta$, then we have\n    \\[\n        \\left\\{\\begin{array} { l } \n            { \\sum _ { i = 1 } ^ { n } x _ { i } - \\sum _ { i = 1 } ^ { n } y _ { i } = 0 } \\\\\n            { \\sum _ { i = 1 } ^ { n } x _ { i } ^ { 2 } - \\sum _ { i = 1 } ^ { n } y _ { i } ^ { 2 } = 0 } \\\\\n            { \\sum _ { i = 1 } ^ { n } x _ { i } ^ { 3 } - \\sum _ { i = 1 } ^ { n } y _ { i } ^ { 3 } = 0 }\n        \\end{array}\\right. \\quad \\Leftrightarrow \\quad \\left\\{\\begin{array}{l}\n            \\sum_{i=1}^{n} x_{i}=\\sum_{i=1}^{n} y_{i} \\\\\n            \\sum_{i=1}^{n} x_{i}^{2}=\\sum_{i=1}^{n} y_{i}^{2} \\\\\n            \\sum_{i=1}^{n} x_{i}^{3}=\\sum_{i=1}^{n} y_{i}^{3}\n        \\end{array}\\right.\n    \\]\n    So, $T(X)$ must be minimal. \n\\end{solution}\n\n\\begin{ex}\n    Consider an i.i.d. Poisson family with parameter \\(\\lambda \\in(0, \\infty)\\), i.e.,\n    \\[\n        f(\\mathbf{x} \\mid \\lambda)=e^{-n \\lambda} e^{(\\log \\lambda) \\sum_{i=1}^{n} x_{i}}\\left(\\prod_{i=1}^{n} x_{i} !\\right)^{-1}\n    \\]\n    \\begin{enumerate}[(a)]\n        \\item Conclude that \\(\\{f(\\mathbf{x} \\mid \\lambda)\\}_{\\lambda>0}\\) is generated by \\((T(\\mathbf{x}), h(\\mathbf{x}))=\\left(\\sum_{i=1}^{n} x_{i},\\left(\\prod_{i=1}^{n} x_{i} !\\right)^{-1}\\right)\\), and that \\(\\mathcal{E}=\\mathbb{R}\\). Also conclude that \\(T(\\mathbf{X})\\) is minimal sufficient for \\(\\lambda\\). \n        \\item Now fix \\(\\alpha \\in \\mathbb{R}\\) and let \\(T_{1}(\\mathbf{X})=\\alpha T(\\mathbf{X}), T_{2}(\\mathbf{X})=(1-\\alpha) T(\\mathbf{X})\\). Conclude that \\(\\{f(\\mathbf{x} \\mid \\lambda)\\}_{\\lambda>0}\\) is generated by \\(\\left(\\left(T_{1}(\\mathbf{x}), T_{2}(\\mathbf{x})\\right) ;\\left(\\prod_{i=1}^{n} x_{i} !\\right)^{-1}\\right)\\). \n        \\item Show that the natural parameter space \\(\\mathcal{E}^{\\prime}\\) generated by \\(\\left(T_{1}(\\mathbf{X}), T_{2}(\\mathbf{X})\\right)\\) is \\(\\mathbb{R}^{2}\\). Conclude that \\(\\left(T_{1}(\\mathbf{X}), T_{2}(\\mathbf{X})\\right)\\) is minimal sufficient for \\(\\lambda\\). \n        \\item Does (c) contradict the minimal sufficiency of \\(T(\\mathbf{X})\\)? \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item \\[\n                f(x|\\lambda)=\\frac{1}{(\\prod_{i=1}^nx_i!)^{-1}}\\exp\\left(\\log{\\lambda} \\sum_{i=1}^nx_i-n\\lambda\\right). \n            \\]\n            So, it is generated by $\\langle \\sum_{i=1}^nx, (\\prod_{i=1}^nx_i!)^{-1} \\rangle$. And \n            \\[\n                \\frac{f(x|\\theta)}{f(y|\\theta)} = \\frac{\\prod_{i=1}^ny_i!}{\\prod_{i=1}^nx_i!}\\exp\\left(\\log\\lambda\\left(\\sum_{i=1}^n x_i-\\sum_{i=1}^n y_i\\right)\\right). \n            \\]\n            So, $\\sum_{i=1}^n x_i=\\sum_{i=1}^n y_i$. $T(x)=\\sum_{i=1}^n x_i$ is minimal statistic. \n        \\item \\[\n            f(x|\\lambda)=\\frac{1}{(\\prod_{i=1}^nx_i!)^{-1}}\\exp\\left(\\log{\\lambda} (\\alpha T_1(X)+(1-\\alpha)T_2(X)) - n\\lambda\\right). \n        \\]\n        So ,let $\\eta=(\\alpha\\log\\lambda, (1-\\alpha)\\log\\lambda)$, then we get the same results. \n        \\item $\\alpha\\in\\mathbb{R}$, $\\log\\lambda\\in\\mathbb{R}$. So, $\\eta\\in\\mathbb{R}^2$. Similarly, $(T_1(X),T_2(X))$ is also minimal statistic. \n        \\item No, $T(X)$ is minimal for $\\lambda$; $(T_1(X), T_2(X))$ is minimal for $(\\lambda, \\alpha)$. \n    \\end{enumerate}\n    \n\\end{solution}\n", "meta": {"hexsha": "35a8c4bbb2863527251be6d1ec4fe146bb06cc1c", "size": 26420, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Statistics/Problem Set/set2.tex", "max_stars_repo_name": "Addasecond86/MS-Stat-Tulane", "max_stars_repo_head_hexsha": "3af55f890c0dedfed7a4614665730002b4c3a370", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Mathematical Statistics/Problem Set/set2.tex", "max_issues_repo_name": "Addasecond86/MS-Stat-Tulane", "max_issues_repo_head_hexsha": "3af55f890c0dedfed7a4614665730002b4c3a370", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mathematical Statistics/Problem Set/set2.tex", "max_forks_repo_name": "Addasecond86/MS-Stat-Tulane", "max_forks_repo_head_hexsha": "3af55f890c0dedfed7a4614665730002b4c3a370", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.5248508946, "max_line_length": 639, "alphanum_fraction": 0.5346328539, "num_tokens": 9975, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236823, "lm_q2_score": 0.853912760387131, "lm_q1q2_score": 0.7340778369921737}}
{"text": "% !TEX root = Main.tex\n\\section{Convolutional Neural Networks}\n\\textbf{Neurons}: $F_\\sigma(\\mathbf{x};\\mathbf{w}) = \\sigma(w_0 + \\sum_{i=1}^M{x_iw_i})$.\\\\\n\\textbf{Activation}: tanh, ReLu, $s(x)=\\frac{1}{1+e^{-x}}$, $s'(x)=s(x)(1-s(x))$\\\\\n\\textbf{Output}: linear regression: $\\hat{\\mathbf{y}} = \\mathbf{W}^L\\mathbf{x}^{L-1}$\\\\\nbinary classification (logistic):\\\\\n$\\hat{y_1} = \\text{P}[Y=1|\\mathbf{x}] = \\frac{1}{1 + \\exp[-\\langle \\mathbf{w}_1^L,\\mathbf{x}^{L-1}\\rangle]}$\\\\\nmulticlass (soft-max):\\\\\n$\\hat{y_k} = \\text{P}[Y=k|\\mathbf{x}]= \\frac{\\exp[\\langle \\mathbf{w}_k^L,\\mathbf{x}^{L-1}\\rangle]}{\\sum_{m=1}^{K}{\\exp[\\langle \\mathbf{w}_m^L, \\mathbf{x}^{L-1}\\rangle]}}$.\\\\\n\\textbf{Loss function} squared loss: $\\frac{1}{2}(y - \\hat{y})^2$\\\\\ncross-entropy loss: $-y \\log \\hat{y} - (1-y)\\log(1-\\hat{y})$.\\\\\n\\textbf{Units and Layers}: layer-to-layer fwd. prop. notation: $\\mathbf{x}^{l} = \\sigma^{l}\\left(\\mathbb{W}^{\\left(l\\right)}\\mathbf{x}^{\\left(l-1\\right)}\\right)$. L-layer network: $\\mathbf{y}=\\sigma^{\\left(L\\right)}\\left(\\mathbf{W}^(L)\\sigma^{(L-1)}\\left(\\cdots\\left(\\sigma^{(1)}\\left(\\mathbf{W}^{(1)}\\mathbf{x}\\right)\\cdots\\right)\\right)\\right)$\n\n\\subsection*{Backpropagation}\nLayer-to-layer Jacobian: $\\mathbf{x}$ = prev. layer activation, $\\mathbf{x^+}$ = next layer activation. Jacobian matrix $\\mathbf{J}$ = $J_{ij}$ of mapping $\\mathbf{x}\\rightarrow\\mathbf{x^+}$, $\\mathbf{x_i^+} = \\sigma(\\mathbf{w}_i^\\top\\mathbf{x})$, $J_{ij} = \\frac{\\partial \\mathbf{x_i^+}}{\\partial \\mathbf{x}_j} = w_{ij}\\cdot\\sigma'(\\mathbf{w}_i^\\top\\mathbf{x})$.\\\\\nAcross multiple layers:\\\\\n$\\frac{\\partial\\mathbf{x}^{(l)}}{\\partial\\mathbf{x}^{(l-n)}} = \\mathbf{J}^{(l)}\\cdot\\frac{\\partial\\mathbf{x}^{(l-1)}}{\\partial\\mathbf{x}^{(l-n)}}=\\mathbf{J}^{(l)}\\cdot\\mathbf{J}^{(l-1)}\\cdots\\mathbf{J}^{(l-n+1)}$ and then back prop. $ \\nabla_{x^{(l)}}^\\top\\ell=\\nabla_{y}^\\top\\ell\\cdot\\mathbf{J}^{(L)}\\cdots\\mathbf{J}^{(l+1)}$\n\n\\subsection*{Neural Networks for Images}\nTranslation invariance of images $\\rightarrow$ neurons compute same fct, shift invariant filters; weights defined as filter masks, e.g. convolution: $F_{n,m}(\\mathbf{x};\\mathbf{w}) = \\sigma(b + \\sum_{k=-2}^2\\sum_{l=-2}^{2}{w_{k,l}x_{n+k,m+l}})$. To reduce dimension of convolution, use \\{max, avg\\}-pooling\n", "meta": {"hexsha": "1e92ad45ac1ec416cd46e27f09e02e33cd3a2d0e", "size": 2250, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ConvolutionalNN.tex", "max_stars_repo_name": "phschaad/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "2352d41e2bc22d8da3bca6465b355edeed4a7c12", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ConvolutionalNN.tex", "max_issues_repo_name": "phschaad/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "2352d41e2bc22d8da3bca6465b355edeed4a7c12", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ConvolutionalNN.tex", "max_forks_repo_name": "phschaad/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "2352d41e2bc22d8da3bca6465b355edeed4a7c12", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-08T22:47:36.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-08T22:47:36.000Z", "avg_line_length": 107.1428571429, "max_line_length": 365, "alphanum_fraction": 0.6288888889, "num_tokens": 936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.957912273285902, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.7340420907656047}}
{"text": "\\subsection{Section 1}\r\n1. Consider the bahaviour of the function $f(x)=|x|$ at $x=0$.\r\n\r\n\\subsection{Section 2}\r\n1.\r\n\\begin{align*}\r\n    \\lim_{h\\to0}\\frac{\\frac{1}{x+h}-\\frac{1}{x}}{h}\r\n    =&\\lim_{h\\to0}\\frac{-h}{hx(x+h)}\\\\\r\n    =&\\lim_{h\\to0}-\\frac{1}{x(x+h)}\\\\\r\n    =&-\\frac{1}{x^2}\r\n\\end{align*}\r\nTherefore,\r\n$$f^\\prime(x)=\\lim_{h\\to0}\\frac{f(x+h)-f(x)}{h}=-\\frac{1}{x^2}$$\r\n2.\r\n\\begin{align*}\r\n    \\lim_{h\\to0}\\frac{\\sqrt{x+h}-\\sqrt{x}}{h}\r\n    =&\\lim_{h\\to0}\\frac{h}{h\\sqrt{x}+\\sqrt{x+h}}\\\\\r\n    =&\\lim_{h\\to0}\\frac{1}{\\sqrt{x}+\\sqrt{x+h}}\\\\\r\n    =&\\frac{1}{2\\sqrt{x}}\r\n\\end{align*}\r\nTherefore,\r\n$$f^\\prime(x)=\\lim_{h\\to0}\\frac{f(x+h)-f(x)}{h}=\\frac{1}{2\\sqrt{x}}$$\r\n3.\r\n\\begin{align*}\r\n    \\lim_{h\\to0}\\frac{e^{ax+ah}-e^{ax}}{h}\r\n    =&\\lim_{h\\to0}ae^{ax}\\frac{e^{ah}-1}{ah}\\\\\r\n    =&(ae^{ax})(1)\\\\\r\n    =&ae^{ax}\r\n\\end{align*}\r\nTherefore,\r\n$$f^\\prime(x)=\\lim_{h\\to0}\\frac{f(x+h)-f(x)}{h}=ae^{ax}$$\r\n4. (a)\r\n\\begin{align*}\r\n    \\lim_{h\\to0}\\frac{\\sin(x+h)-\\sin(x)}{h}\r\n    =&\\lim_{h\\to0}\\frac{2\\cos(x+h/2)\\sin(h/2)}{h}\\\\\r\n    =&\\lim_{h\\to0}\\cos(x+h/2)\\frac{\\sin(h/2)}{h/2}\\\\\r\n    =&\\cos(x)\r\n\\end{align*}\r\nTherefore,\r\n$$f^\\prime(x)=\\lim_{h\\to0}\\frac{f(x+h)-f(x)}{h}=\\cos(x)$$\r\n(b)\r\n\\begin{align*}\r\n    \\lim_{h\\to0}\\frac{\\cos(x+h)-\\cos(x)}{h}\r\n    =&-\\lim_{h\\to0}\\frac{\\sin(x-\\pi/2+h)-\\sin(x-\\pi/2)}{h}\\\\\r\n    =&\\left.\\frac{\\mathrm d\\sin(z)}{\\mathrm dz}\\right|_{z=x-\\pi/2}\\\\\r\n    =&-\\cos(x-\\pi/2)\\\\\r\n    =&-\\sin(x)\r\n\\end{align*}\r\nTherefore,\r\n$$f^\\prime(x)=\\lim_{h\\to0}\\frac{f(x+h)-f(x)}{h}=-\\sin(x)$$\r\n5.\r\n\\begin{align*}\r\n    \\lim_{h\\to0}\\frac{g(x+h)-g(x)}{h}\r\n    =&\\lim_{h\\to0}\\frac{cf(x+h)-cf(x)}{h}\\\\\r\n    =&c\\lim_{h\\to0}\\frac{f(x+h)-f(x)}{h}\\\\\r\n    =&cf^\\prime(x)\r\n\\end{align*}\r\nTherefore,\r\n$$f^\\prime(x)=\\lim_{h\\to0}\\frac{g(x+h)-g(x)}{h}=cf^\\prime(x)$$\r\n\\subsection{Section 3}\r\n1. \r\n$$\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\sqrt{x}}{e^x}=\\frac{\\frac{1}{2\\sqrt{x}}e^x-\\sqrt{x}e^x}{e^{2x}}=\\frac{1-2x}{2\\sqrt{x}e^x}$$\r\n2. (a)\r\n$$\\frac{\\mathrm d}{\\mathrm dx}x^3=(1)x^2+x(2x)=3x^2$$\r\n$$\\frac{\\mathrm d}{\\mathrm dx}x^4=(1)x^3+x(3x^2)=4x^3$$\r\n(b) Let $P(n)$ be the proposition. When $n=1$, $\\mathrm{L.H.S.}=1=\\mathrm{R.H.S.}$, so $P(1)$ is true. Now assume that $P(k)$ is true for some positive integer $k$, then when $n=k+1$,\r\n\\begin{align*}\r\n    \\mathrm{L.H.S.}\r\n    =&\\frac{\\mathrm d}{\\mathrm dx}x^{k+1}\\\\\r\n    =&\\left(\\frac{\\mathrm d}{\\mathrm dx}x\\right)x^k+x\\left(\\frac{\\mathrm d}{\\mathrm dx}x^k\\right)\\\\\r\n    =&x^k+x(kx^{k-1})\\\\\r\n    =&(k+1)x^k=\\mathrm{R.H.S.}\r\n\\end{align*}\r\nSo $P(k+1)$ is true. By the principle of mathematical induction, $P(n)$ is true for all positive integer $n$.\\\\\r\n3. (a)\r\n\\begin{align*}\r\n    \\lim_{h\\to0}\\frac{\\frac{1}{f(x+h)}-\\frac{1}{f(x)}}{h}\r\n    =&-\\lim_{h\\to0}\\frac{1}{f(x)f(x+h)}\\frac{f(x+h)-f(x)}{h}\\\\\r\n    =&-\\frac{f^\\prime(x)}{f(x)^2}\r\n\\end{align*}\r\n(b)\r\n\\begin{align*}\r\n    \\frac{\\mathrm d}{\\mathrm dx}\\frac{f(x)}{g(x)}\r\n    =&\\frac{\\mathrm d}{\\mathrm dx}f(x)\\frac{1}{g(x)}\\\\\r\n    =&\\left(\\frac{\\mathrm d}{\\mathrm dx}f(x)\\right)\\frac{1}{g(x)}+f(x)\\left(\\frac{\\mathrm d}{\\mathrm dx}\\frac{1}{g(x)}\\right)\\\\\r\n    =&\\frac{f^\\prime(x)}{g(x)}-\\frac{f(x)g^\\prime(x)}{g(x)^2}\\\\\r\n    =&\\frac{f^\\prime(x)g(x)-f(x)g^\\prime(x)}{g(x)^2}\r\n\\end{align*}\r\n\r\n\\subsection{Section 4}\r\n1. $x^9e^x+9x^8e^x$.\\\\\r\n2. $5x^4-1$.\r\n\r\n\\subsection{Section 5}\r\n1. $\\frac{e^{\\sqrt{x}}}{2\\sqrt{x}}$\r\n\r\n\\subsection{Section 6}\r\n1. $ex^{e-1}-e^x$\r\n\r\n\\subsection{Section 7}\r\n1. (3)\r\n$$\\frac{\\mathrm d}{\\mathrm dx}\\tan(x)=\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\sin(x)}{\\cos(x)}=\\frac{\\sin^2(x)+\\cos^2(x)}{\\cos^2(x)}=\\frac{1}{\\cos^2(x)}=\\sec^2(x)$$\r\n(4)\r\n$$\\frac{\\mathrm d}{\\mathrm dx}\\sec(x)=\\frac{\\mathrm d}{\\mathrm dx}\\frac{1}{\\cos(x)}=-\\frac{1}{\\cos^2(x)}(-\\sin(x))=\\sec(x)\\tan(x)$$\r\n(5)\r\n$$\\frac{\\mathrm d}{\\mathrm dx}\\cot(x)=\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\cos(x)}{\\sin(x)}=\\frac{-\\sin^2(x)-\\cos^2(x)}{\\sin^2(x)}=-\\frac{1}{\\sin^2(x)}=-\\csc^2(x)$$\r\n(6)\r\n$$\\frac{\\mathrm d}{\\mathrm dx}\\csc(x)=\\frac{\\mathrm d}{\\mathrm dx}\\frac{1}{\\sin(x)}=-\\frac{1}{\\sin^2(x)}(\\cos(x))=-\\csc(x)\\cot(x)$$\r\n2. (3)\r\n\\begin{align*}\r\n    \\lim_{h\\to0}\\frac{\\tan(x+h)-\\tan(x)}{h}\r\n    =&\\lim_{h\\to0}\\frac{\\sin(x+h)\\cos(x)-\\cos(x+h)\\sin(x)}{h\\cos(x)\\cos(x+h)}\\\\\r\n    =&\\lim_{h\\to0}\\frac{\\sin(h)}{h}\\frac{1}{\\cos(x)\\cos(x+h)}\\\\\r\n    =&\\sec^2(x)\r\n\\end{align*}\r\nTherefore,\r\n$$\\frac{\\mathrm d\\tan(x)}{\\mathrm dx}=\\sec^2(x)$$\r\n(4)\r\n\\begin{align*}\r\n    \\lim_{h\\to0}\\frac{\\sec(x+h)-\\sec(x)}{h}\r\n    =&\\lim_{h\\to0}\\frac{\\cos(x)-\\cos(x+h)}{h\\cos(x)\\cos(x+h)}\\\\\r\n    =&\\lim_{h\\to0}\\frac{-2\\sin(x+h/2)\\sin(-h/2)}{h\\cos(x)\\cos(x+h)}\\\\\r\n    =&\\lim_{h\\to0}\\frac{\\sin(x+h/2)}{\\cos(x)\\cos(x+h)}\\frac{\\sin(h/2)}{h/2}\\\\\r\n    =&\\frac{\\sin(x)}{\\cos^2(x)}\\\\\r\n    =&\\sec(x)\\tan(x)\r\n\\end{align*}\r\nTherefore,\r\n$$\\frac{\\mathrm d\\sec(x)}{\\mathrm dx}=\\sec(x)\\tan(x)$$\r\n(5)\r\n\\begin{align*}\r\n    \\lim_{h\\to0}\\frac{\\cot(x+h)-\\cot(x)}{h}\r\n    =&\\lim_{h\\to0}\\frac{\\sin(x)\\cos(x+h)-\\cos(x)\\sin(x+h)}{h\\sin(x)\\sin(x+h)}\\\\\r\n    =&\\lim_{h\\to0}-\\frac{\\sin(h)}{h}\\frac{1}{\\sin(x)\\sin(x+h)}\\\\\r\n    =&-\\csc^2(x)\r\n\\end{align*}\r\nTherefore,\r\n$$\\frac{\\mathrm d\\cot(x)}{\\mathrm dx}=-\\csc^2(x)$$\r\n(6)\r\n\\begin{align*}\r\n    \\lim_{h\\to0}\\frac{\\csc(x+h)-\\csc(x)}{h}\r\n    =&\\lim_{h\\to0}\\frac{\\sin(x)-\\sin(x+h)}{h\\sin(x)\\sin(x+h)}\\\\\r\n    =&\\lim_{h\\to0}\\frac{2\\cos(x+h/2)\\sin(-h/2)}{h\\sin(x)\\sin(x+h)}\\\\\r\n    =&\\lim_{h\\to0}-\\frac{\\cos(x+h/2)}{\\sin(x)\\sin(x+h)}\\frac{\\sin(h/2)}{h/2}\\\\\r\n    =&-\\frac{\\cos(x)}{\\sin^2(x)}\\\\\r\n    =&-\\csc(x)\\cot(x)\r\n\\end{align*}\r\nTherefore,\r\n$$\\frac{\\mathrm d\\csc(x)}{\\mathrm dx}=-\\csc(x)\\cot(x)$$\r\n3.\r\n$$f^\\prime(x)=\\cos(x^2\\cos(e^x))(2x\\cos(e^x)-x^2\\sin(e^x)e^x)$$\r\n\r\n\\subsection{Section 8}\r\n1. We have $x^x=e^{x\\ln x}$, so\r\n$$\\frac{\\mathrm dx^x}{\\mathrm dx}=\\frac{\\mathrm de^{x\\ln x}}{\\mathrm dx}=e^{x\\ln x}(\\ln x+x\\frac{1}{x})=x^x(\\ln x+1)$$\r\n2.\r\n\\begin{align*}\r\n    ye^y=&\\ln x\\\\\r\n    (ye^y+e^y)\\frac{\\mathrm dy}{\\mathrm dx}=&\\frac{1}{x}\\\\\r\n    \\frac{\\mathrm dy}{\\mathrm dx}=&\\frac{1}{xye^y+xe^y}\r\n\\end{align*}\r\nSo when $x=1,y=0$, we have\r\n$$\\left.\\frac{\\mathrm dy}{\\mathrm dx}\\right|_{(1,0)}=1$$\r\n\r\n\\subsection{Section 9}\r\n1. (a) When $f(x)=\\sin(x)$,\r\n$$\\mathrm{L.H.S.}=f^{\\prime\\prime}=\\frac{\\mathrm d}{\\mathrm dx}\\cos(x)=-\\sin(x)=-f=\\mathrm{R.H.S.}$$\r\nWhen $f(x)=\\cos(x)$,\r\n$$\\mathrm{L.H.S.}=f^{\\prime\\prime}=\\frac{\\mathrm d}{\\mathrm dx}-\\sin(x)=-\\cos(x)=-f=\\mathrm{R.H.S.}$$\r\n(b) When $f(x)=A\\cos(x)+B\\sin(x)$,\r\n\\begin{align*}\r\n    \\mathrm{L.H.S.}\r\n    =&f^{\\prime\\prime}\\\\\r\n    =&\\frac{\\mathrm d}{\\mathrm dx}(-A\\sin(x)+B\\cos(x))\\\\\r\n    =&-A\\cos(x)-B\\sin(x)\\\\\r\n    =&-f=\\mathrm{R.H.S.}\r\n\\end{align*}\r\n", "meta": {"hexsha": "212e042f9e8737e6d8c9d53952128c4e6f133aa8", "size": 6467, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "resources/Mathematics EP M2/Notes/Differentiation/ssa/answers.tex", "max_stars_repo_name": "mklprudence/5-triple-star", "max_stars_repo_head_hexsha": "b2cb2543406eb66fb96776b7f072a55e20b48b4f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "resources/Mathematics EP M2/Notes/Differentiation/ssa/answers.tex", "max_issues_repo_name": "mklprudence/5-triple-star", "max_issues_repo_head_hexsha": "b2cb2543406eb66fb96776b7f072a55e20b48b4f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-06-02T03:40:36.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-02T09:20:16.000Z", "max_forks_repo_path": "resources/Mathematics EP M2/Notes/Differentiation/ssa/answers.tex", "max_forks_repo_name": "mklprudence/5-triple-star", "max_forks_repo_head_hexsha": "b2cb2543406eb66fb96776b7f072a55e20b48b4f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.5367231638, "max_line_length": 184, "alphanum_fraction": 0.51476728, "num_tokens": 2986, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942232112239, "lm_q2_score": 0.8244619263765706, "lm_q1q2_score": 0.7340136903106581}}
{"text": "\\section{Dependent function types}\n\\label{ch:pi}\n\nA fundamental concept in dependent type theory is that of a dependent function. A dependent function is a function of which the type of the output may depend on the input. They are a generalization of ordinary functions, because an ordinary function $f:A\\to B$ is a function of which the output $f(x)$ has type $B$ regardless of the value of $x$.\n\n\\subsection{Dependent function types}\nConsider a section $b$ of a family $B$ over $A$ in context $\\Gamma$, i.e.,\n\\begin{equation*}\n  \\Gamma,x:A\\vdash b(x):B(x).\n\\end{equation*}\nFrom one point of view, such a section $b$ is an operation, or a program, that takes as input $x:A$ and produces a term $b(x):B(x)$. From a more mathematical point of view we see $b$ as a choice of an element of each $B(x)$. In other words, we may see $b$ as a function that takes $x:A$ to $b(x):B(x)$. Note that the type $B(x)$ of the output is dependent on $x:A$. In this section we postulate rules for the \\emph{type} of all such dependent functions: whenever $B$ is a family over $A$ in context $\\Gamma$, there is a type\n\\begin{equation*}\n  \\prd{x:A}B(x)\n\\end{equation*}\nin context $\\Gamma$, consisting of all the dependent functions of which the output at $x:A$ has type $B(x)$. There are four principal rules for $\\Pi$-types:\n\\begin{enumerate}\n\\item The formation rule, which tells us how we may form dependent function types.\n\\item The introduction rule, which tells us how to introduce new terms of dependent function types.\n\\item The elimination rule, which tells us how to use arbitrary terms of dependent function types.\n\\item The computation rules, which tell us how the introduction and elimination rules interact. These computation rules guarantee that every term of a dependent function type behaves as expected: as a dependent function.\n\\end{enumerate}\nIn the cases of the formation rule, the introduction rule, and the elimination rule, we will also provide conversion rules that ensure that all the constructions respect judgmental equality.\n\n\\subsubsection{The $\\Pi$-formation rule}\n\\define{Dependent function types}\\index{dependent function type}\\index{pi-type@{$\\Pi$-type}} are formed by the following \\define{$\\Pi$-formation rule}\\index{rule!pi-formation@{$\\Pi$-formation}}:\n\\begin{prooftree}\n\\AxiomC{$\\Gamma,x:A\\vdash B(x)~\\textrm{type}$}\n\\RightLabel{$\\Pi$.}\n\\UnaryInfC{$\\Gamma\\vdash \\prd{x:A}B(x)~\\mathrm{type}$}\n\\end{prooftree}\nWith the following conversion rule we postulate that formation of dependent function types respects judgmental equality:\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash A\\jdeq A'~\\mathrm{type}$}\n\\AxiomC{$\\Gamma,x:A\\vdash B(x)\\jdeq B'(x)~\\textrm{type}$}\n\\RightLabel{$\\Pi$-eq.}\n\\BinaryInfC{$\\Gamma\\vdash \\prd{x:A}B(x)\\jdeq\\prd{x:A'}B'(x)~\\mathrm{type}$}\n\\end{prooftree}\nFurthermore, when $x'$ is a fresh variable, i.e., which does not occur in the context $\\Gamma,x:A$, we also postulate that\n\\begin{prooftree}\n\\AxiomC{$\\Gamma,x:A\\vdash B(x)~\\textrm{type}$}\n\\RightLabel{$\\Pi$-$x'/x$.}\n\\UnaryInfC{$\\Gamma\\vdash \\prd{x:A}B(x)\\jdeq \\prd{x':A}B(x')~\\mathrm{type}$}\n\\end{prooftree}\n\n\\subsubsection{The $\\Pi$-introduction rule}\nThe introduction rule for dependent function types is also called the $\\lambda$-abstraction rule. Recall that dependent functions are formed from terms $b(x)$ of type $B(x)$ in context $\\Gamma,x:A$. Therefore \\define{$\\lambda$-abstraction rule}\\index{lambda-abstraction@{$\\lambda$-abstraction}}\\index{rule!lambda-abstraction@{$\\lambda$-abstraction}} is as follows:\n\\begin{prooftree}\n  \\AxiomC{$\\Gamma,x:A \\vdash b(x) : B(x)$}\n  \\RightLabel{$\\lambda$}\n  \\UnaryInfC{$\\Gamma\\vdash \\lam{x}b(x) : \\prd{x:A}B(x)$}\n\\end{prooftree}\n\nJust like ordinary mathematicians, we will sometimes write $x\\mapsto f(x)$ for a function $f$. The map $n\\mapsto n^2$ is an example. The $\\lambda$-abstraction is also required to respect judgmental equality. Therefore we postulate that\n\\begin{prooftree}\n  \\AxiomC{$\\Gamma,x:A \\vdash b(x)\\jdeq b'(x) : B(x)$}\n  \\RightLabel{$\\lambda$-eq.}\n  \\UnaryInfC{$\\Gamma\\vdash \\lam{x}b(x)\\jdeq \\lam{x}b'(x) : \\prd{x:A}B(x)$}\n\\end{prooftree}\n\n\\subsubsection{The $\\Pi$-elimination rule}\n\nThe elimination rule for dependent function types provides us with a way to \\emph{use} dependent functions. The way to use a dependent function is to apply it to an argument of the domain type. The $\\Pi$-elimination rule is therefore also called the \\define{evaluation rule}\\index{evaluation}\\index{rule!evaluation}. It asserts that given a dependent function $f:\\prd{x:A}B(x)$ in context $\\Gamma$ we obtain a term $f(x)$ of type $B(x)$ in context $\\Gamma,x:A$. More formally:\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:\\prd{x:A}B(x)$}\n\\RightLabel{$ev$}\n\\UnaryInfC{$\\Gamma,x:A\\vdash f(x) : B(x)$}\n\\end{prooftree}\nAgain we require that evaluation respects judgmental equality:\n\\begin{prooftree}\n  \\AxiomC{$\\Gamma\\vdash f\\jdeq f':\\prd{x:A}B(x)$}\n  \\UnaryInfC{$\\Gamma,x:A\\vdash f(x)\\jdeq f'(x):B(x)$}\n\\end{prooftree}\n\n\\subsubsection{The $\\Pi$-computation rules}\nThe computation rules for dependent function types postulate that $\\lambda$-abstraction rule and the evaluation rule are mutual inverses. Thus we have two computation rules.\n\nFirst we postulate the \\define{$\\beta$-rule}\\index{beta-rule@{$\\beta$-rule}}\\index{rule!beta-rule@{$\\beta$-rule}}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma,x:A \\vdash b(x) : B(x)$}\n\\RightLabel{$\\beta$.}\n\\UnaryInfC{$\\Gamma,x:A \\vdash (\\lambda y.b(y))(x)\\jdeq b(x) : B(x)$}\n\\end{prooftree}\nSecond, we postulate the \\define{$\\eta$-rule}\\index{eta-rule@{$\\eta$-rule}}\\index{rule!eta-rule@{$\\eta$-rule}}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:\\prd{x:A}B(x)$}\n\\RightLabel{$\\eta$.}\n\\UnaryInfC{$\\Gamma \\vdash \\lam{x}f(x) \\jdeq f : \\prd{x:A}B(x)$}\n\\end{prooftree}\nThis completes the specification of dependent function types.\n\n\\subsection{Ordinary function types}\nIn the case where both $A$ and $B$ are types in context $\\Gamma$, we may first weaken $B$ by $A$, and then apply the formation rule for the dependent function type:\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash A~\\textrm{type}$}\n\\AxiomC{$\\Gamma\\vdash B~\\textrm{type}$}\n\\BinaryInfC{$\\Gamma,x:A\\vdash B~\\textrm{type}$}\n\\UnaryInfC{$\\Gamma\\vdash \\prd{x:A}B~\\textrm{type}$}\n\\end{prooftree}\nThe result is the type of functions that take an argument of type $A$, and return a term of type $B$. In other words, terms of the type $\\prd{x:A}B$ are \\emph{ordinary} functions from $A$ to $B$. We write $A\\to B$ for the \\define{type of functions}\\index{function type} from $A$ to $B$. Sometimes we will also write $B^A$ for the type $A\\to B$.\n\nWe give a brief summary of the rules specifying ordinary function types, omitting the rules that the asserted operations respect judgmental equality. All of these rules can be derived from the corresponding rules for $\\Pi$-types.\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash A~\\textrm{type}$}\n\\AxiomC{$\\Gamma\\vdash B~\\textrm{type}$}\n\\RightLabel{$\\to$\\index{arrow-formation@{$\\to$-formation}}\\index{rule!arrow-formation@{$\\to$-formation}}}\n\\BinaryInfC{$\\Gamma\\vdash A\\to B~\\textrm{type}$}\n\\end{prooftree}%\n\\begin{center}\n\\begin{minipage}{.45\\textwidth}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash B~\\textrm{type}$}\n\\AxiomC{$\\Gamma,x:A\\vdash b(x):B$}\n\\RightLabel{$\\lambda$\\index{lambda-abstraction@{$\\lambda$-abstraction}}\\index{rule!lambda-abstraction@{$\\lambda$-abstraction}}}\n\\BinaryInfC{$\\Gamma\\vdash \\lam{x}b(x):A\\to B$}\n\\end{prooftree}%\n\\end{minipage}\n\\begin{minipage}{.45\\textwidth}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n\\RightLabel{$ev$\\index{rule!evaluation}\\index{evaluation}}\n\\UnaryInfC{$\\Gamma,x:A\\vdash f(x):B$}\n\\end{prooftree}%\n\\end{minipage}\n\\end{center}\n\\begin{center}\n\\begin{minipage}{.45\\textwidth}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash B~\\textrm{type}$}\n\\AxiomC{$\\Gamma,x:A\\vdash b(x):B$}\n\\RightLabel{$\\beta$\\index{rule!beta-rule@{$\\beta$-rule}}\\index{beta-rule@{$\\beta$-rule}}}\n\\BinaryInfC{$\\Gamma,x:A\\vdash(\\lam{y}b(y))(x)\\jdeq b(x):B$}\n\\end{prooftree}%\n\\end{minipage}\n\\begin{minipage}{.45\\textwidth}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n\\RightLabel{$\\eta$\\index{rule!eta-rule@{$\\eta$-rule}}\\index{eta-rule@{$\\eta$-rule}}}\n\\UnaryInfC{$\\Gamma\\vdash\\lam{x} f(x)\\jdeq f:A\\to B$}\n\\end{prooftree}\n\\end{minipage}\n\\end{center}\n\n\\begin{comment}\n\\begin{rmk}\nSimilar to \\cref{rmk:ev_var}, we can derive\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash A~\\mathrm{type}$}\n\\AxiomC{$\\Gamma\\vdash B~\\mathrm{type}$}\n\\BinaryInfC{$\\Gamma,f:B^A,x:A\\vdash f(x):B$}\n\\end{prooftree}\n\\end{rmk}\n\\end{comment}\n\n\\subsection{The identity function, composition, and their laws}\n\\begin{defn}\nFor any type $A$ in context $\\Gamma$, we define the \\define{identity function}\\index{identity function|textbf} $\\idfunc[A]:A\\to A$ using the variable rule\\index{variable rule}\\index{rule!variable rule}:\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash A~\\textrm{type}$}\n\\UnaryInfC{$\\Gamma,x:A\\vdash x:A$}\n\\UnaryInfC{$\\Gamma\\vdash \\idfunc[A]\\defeq \\lam{x}x:A\\to A$}\n\\end{prooftree}\n\\end{defn}\n\nA judgment of the form $\\Gamma\\vdash a\\defeq b:A$ should be read as \"$b$ is a well-defined term of type $A$ in context $\\Gamma$, and we will refer to it as $a$\".\n\n\\begin{defn}\nFor any three types $A$, $B$, and $C$ in context $\\Gamma$, there is a \\define{composition}\\index{composition!of functions|textbf} operation\n\\begin{equation*}\n\\mathsf{comp}:(B\\to C)\\to ((A\\to B)\\to (A\\to C)),\n\\end{equation*}\ni.e., we can derive\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash A~\\textrm{type}$}\n\\AxiomC{$\\Gamma\\vdash B~\\textrm{type}$}\n\\AxiomC{$\\Gamma\\vdash C~\\textrm{type}$}\n\\TrinaryInfC{$\\Gamma\\vdash\\mathsf{comp}:(B\\to C)\\to ((A\\to B)\\to (A\\to C))$}\n\\end{prooftree}\nWe will write $g\\circ f$ for $\\mathsf{comp}(g,f)$.\n\\end{defn}\n\n\\begin{constr}\n  The idea of the definition is to define $\\mathsf{comp}(g,f)$ to be the function $\\lam{x}g(f(x))$. The derivation we use to construct $\\mathsf{comp}$ is as follows:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma\\vdash A~\\mathrm{type}$}\n    \\AxiomC{$\\Gamma\\vdash B~\\mathrm{type}$}\n    \\BinaryInfC{$\\Gamma,f:B^A,x:A\\vdash f(x):B$}\n    \\UnaryInfC{$\\Gamma,g:C^B,f:B^A,x:A\\vdash f(x):B$}\n    \\AxiomC{$\\Gamma\\vdash B~\\mathrm{type}$}\n    \\AxiomC{$\\Gamma\\vdash C~\\mathrm{type}$}\n    \\BinaryInfC{$\\Gamma,g:C^B,y:B\\vdash g(y):C$}\n    \\UnaryInfC{$\\Gamma,g:C^B,f:B^A,y:B\\vdash g(y):C$}\n    \\UnaryInfC{$\\Gamma,g:C^B,f:B^A,x:A,y:B\\vdash g(y):C$}\n    \\BinaryInfC{$\\Gamma,g:C^B,f:B^A,x:A\\vdash g(f(x)) : C$}\n    \\UnaryInfC{$\\Gamma,g:C^B,f:B^A\\vdash \\lam{x}g(f(x)):C^A$}\n    \\UnaryInfC{$\\Gamma,g:B\\to C\\vdash \\lam{f}{x}g(f(x)):B^A\\to C^A$}\n    \\UnaryInfC{$\\Gamma\\vdash\\mathsf{comp}\\defeq \\lam{g}{f}{x}g(f(x)):C^B\\to (B^A\\to C^A)$}\n  \\end{prooftree}\n\\end{constr}\n\n\\begin{lem}\nComposition of functions is associative\\index{associativity!of function composition}\\index{composition!of functions!associativity}, i.e., we can derive\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n\\AxiomC{$\\Gamma\\vdash g:B\\to C$}\n\\AxiomC{$\\Gamma\\vdash h:C\\to D$}\n\\TrinaryInfC{$\\Gamma \\vdash (h\\circ g)\\circ f\\jdeq h\\circ(g\\circ f):A\\to D$}\n\\end{prooftree}\n\\end{lem}\n\n\\begin{proof}\n  The main idea of the proof is that both $((h\\circ g)\\circ f)(x)$ and $(h\\circ (g\\circ f))(x)$ evaluate to $h(g(f(x))$, and therefore $(h\\circ g)\\circ f$ and $h\\circ(g\\circ f)$ must be judgmentally equal. This idea is made formal in the following derivation:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n    \\UnaryInfC{$\\Gamma,x:A\\vdash f(x):B$}\n    \\AxiomC{$\\Gamma\\vdash g:B\\to C$}\n    \\UnaryInfC{$\\Gamma,y:B\\vdash g(y):C$}\n    \\UnaryInfC{$\\Gamma,x:A,y:B\\vdash g(y):C$}\n    \\BinaryInfC{$\\Gamma,x:A\\vdash g(f(x)):C$}\n    \\AxiomC{$\\Gamma\\vdash h:C\\to D$}\n    \\UnaryInfC{$\\Gamma,z:C\\vdash h(z):D$}\n    \\UnaryInfC{$\\Gamma,x:A,z:C\\vdash h(z):D$}\n    \\BinaryInfC{$\\Gamma,x:A\\vdash h(g(f(x))):D$}\n    \\UnaryInfC{$\\Gamma,x:A\\vdash h(g(f(x)))\\jdeq h(g(f(x))):D$}\n    \\UnaryInfC{$\\Gamma,x:A\\vdash (h\\circ g)(f(x))\\jdeq h((g\\circ f)(x)):D$}\n    \\UnaryInfC{$\\Gamma,x:A\\vdash ((h\\circ g)\\circ f)(x)\\jdeq (h\\circ (g \\circ f))(x):D$}\n    \\UnaryInfC{$\\Gamma\\vdash (h\\circ g)\\circ f\\jdeq h\\circ(g\\circ f):A\\to D$.}\n  \\end{prooftree}\n\\end{proof}\n\n\\begin{lem}\\label{lem:fun_unit}\nComposition of functions satisfies the left and right unit laws\\index{left unit law|see {unit laws}}\\index{right unit law|see {unit laws}}\\index{unit laws!of function composition}, i.e., we can derive\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n\\UnaryInfC{$\\Gamma\\vdash \\idfunc[B]\\circ f\\jdeq f:A\\to B$}\n\\end{prooftree}\nand\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n\\UnaryInfC{$\\Gamma\\vdash f\\circ\\idfunc[A]\\jdeq f:A\\to B$}\n\\end{prooftree}\n\\end{lem}\n\n\\begin{proof}\nThe derivation for the left unit law is\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n\\UnaryInfC{$\\Gamma,x:A\\vdash f(x):B$}\n\\AxiomC{$\\Gamma\\vdash B~\\mathrm{type}$}\n\\UnaryInfC{$\\Gamma,y:B\\vdash \\idfunc[B](y)\\jdeq y:B$}\n\\UnaryInfC{$\\Gamma,x:A,y:B\\vdash \\idfunc[B](y)\\jdeq y:B$}\n\\BinaryInfC{$\\Gamma,x:A\\vdash \\idfunc[B](f(x))\\jdeq f(x):B$}\n\\UnaryInfC{$\\Gamma,x:A\\vdash (\\idfunc[B]\\circ f)(x)\\jdeq f(x):B$}\n\\UnaryInfC{$\\Gamma\\vdash \\idfunc[B]\\circ f\\jdeq f:A\\to B$}\n\\end{prooftree}\nThe right unit law is left as \\cref{ex:fun_right_unit}.\n\\end{proof}\n\n\\begin{exercises}\n\\item \\label{ex:fun_right_unit}Give a derivation for the right unit law of \\cref{lem:fun_unit}.\\index{unit laws!for function composition}\n\\item Show that the rule\n\\begin{prooftree}\n\\AxiomC{$\\Gamma,x:A \\vdash b(x) : B(x)$}\n\\RightLabel{$\\lambda$-$x'/x$}\n\\UnaryInfC{$\\Gamma\\vdash \\lam{x}b(x)\\jdeq \\lam{x'}b(x') : \\prd{x:A}B(x)$}\n\\end{prooftree}\nis admissible for any variable $x'$ that does not occur in the context $\\Gamma,x:A$.\n\\item \n  \\begin{subexenum}\n  \\item Construct the \\define{constant function}\\index{constant function}\\index{function!constant function}\n    \\begin{prooftree}\n      \\AxiomC{$\\Gamma\\vdash A~\\textrm{type}$}\n      \\UnaryInfC{$\\Gamma,y:B\\vdash \\mathsf{const}_y:A\\to B$}\n    \\end{prooftree}\n  \\item Show that\n    \\begin{prooftree}\n      \\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n      \\UnaryInfC{$\\Gamma,z:C\\vdash \\mathsf{const}_z\\circ f\\jdeq\\mathsf{const}_z : A\\to C$}\n    \\end{prooftree}\n  \\item Show that\n    \\begin{prooftree}\n      \\AxiomC{$\\Gamma\\vdash A~\\textrm{type}$}\n      \\AxiomC{$\\Gamma\\vdash g:B\\to C$}\n      \\BinaryInfC{$\\Gamma,y:B\\vdash g\\circ\\mathsf{const}_y\\jdeq \\mathsf{const}_{g(y)}:A\\to C$}\n    \\end{prooftree}\n  \\end{subexenum}\n\\item In this exercise we generalize the composition operation of non-dependent function types\\index{composition!of dependent functions}:\n\\begin{subexenum}\n\\item Define a composition operation for dependent function types\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:\\prd{x:A}B(x)$}\n\\AxiomC{$\\Gamma\\vdash g:\\prd{x:A}{y:B(x)} C(x,y)$}\n\\BinaryInfC{$\\Gamma\\vdash g\\circ' f:\\prd{x:A} C(x,f(x))$}\n\\end{prooftree}\nand show that this operation agrees with ordinary composition when it is specialized to non-dependent function types.\n\\item Show that composition of dependent functions agrees with ordinary composition of functions:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n    \\AxiomC{$\\Gamma\\vdash g:B\\to C$}\n    \\BinaryInfC{$\\Gamma\\vdash (\\lam{x}g)\\circ' f\\jdeq g\\circ f:A \\to C$}\n  \\end{prooftree}\n\\item Show that composition of dependent functions is associative.\\index{associativity!of dependent function composition}\\index{composition!of dependent functions!associativity}\n\\item Show that composition of dependent functions satisfies the right unit law\\index{unit laws!dependent function composition}:\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:\\prd{x:A}B(x)$}\n\\UnaryInfC{$\\Gamma\\vdash (\\lam{x}f)\\circ'\\idfunc[A]\\jdeq f :\\prd{x:A}B(x)$}\n\\end{prooftree}\n\\item Show that composition of dependent functions satisfies the left unit law\\index{unit laws!dependent function composition}:\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:\\prd{x:A}B(x)$}\n\\UnaryInfC{$\\Gamma\\vdash (\\lam{x}\\idfunc[B(x)])\\circ' f\\jdeq f:\\prd{x:A}B(x)$}\n\\end{prooftree}\n\\end{subexenum}\n\\item \\label{ex:swap}\n\\begin{subexenum}\n\\item Given two types $A$ and $B$ in context $\\Gamma$, and a type $C$ in context $\\Gamma,x:A,y:B$, define the \\define{swap function}\\index{function!swap}\\index{swap function}\n\\begin{equation*}\n\\Gamma\\vdash \\sigma:\\Big(\\prd{x:A}{y:B}C(x,y)\\Big)\\to\\Big(\\prd{y:B}{x:A}C(x,y)\\Big)\n\\end{equation*}\nthat swaps the order of the arguments.\n\\item Show that\n\\begin{equation*}\n\\Gamma\\vdash \\sigma\\circ\\sigma\\jdeq\\idfunc:\\Big(\\prd{x:A}{y:B}C(x,y)\\Big)\\to \\Big(\\prd{x:A}{y:B}C(x,y)\\Big).\n\\end{equation*}\n\\end{subexenum}\n\\end{exercises}\n", "meta": {"hexsha": "639c31a934313cfe7b1709dc3d03a0f726516bf1", "size": 16399, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/pi.tex", "max_stars_repo_name": "tadejpetric/HoTT-Intro", "max_stars_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Book/pi.tex", "max_issues_repo_name": "tadejpetric/HoTT-Intro", "max_issues_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Book/pi.tex", "max_forks_repo_name": "tadejpetric/HoTT-Intro", "max_forks_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.3036809816, "max_line_length": 524, "alphanum_fraction": 0.7010183548, "num_tokens": 5885, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.734013686950581}}
{"text": "\\section{Basic Calculus}\r\n\\begin{definition}\r\n    Let $f:U\\to\\mathbb R$ where $U\\subset\\mathbb R$, then if $\\forall\\epsilon>0,\\exists\\delta>0$ such that\r\n    $$|x-x_0|<\\delta\\implies|f(x)-A|<\\epsilon$$\r\n    for some $x_0,A\\in\\mathbb R$, we say\r\n    $$\\lim_{x\\to x_0}f(x)=A$$\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Assume that\r\n    $$\\lim_{x\\to x_0}f(x)=A, \\lim_{x\\to x_0}f(x)=B$$\r\n    Then the followings hold:\r\n    $$\\lim_{x\\to x_0}cf(x)=cA$$\r\n    $$\\lim_{x\\to x_0}f(x)+g(x)=A+B$$\r\n    $$\\lim_{x\\to x_0}f(x)g(x)=AB$$\r\n    $$B\\neq 0\\implies\\lim_{x\\to x_0}f(x)/g(x)=A/B$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Check definitions.\r\n\\end{proof}\r\n\\begin{definition}[One-sided limits]\r\n    If $\\forall\\epsilon>0,\\exists\\delta>0$ such that $0<x-x_0<\\delta\\implies|f(x)-A|<\\epsilon$\r\n    for some $x_0,A\\in\\mathbb R$, we say\r\n    $$\\lim_{x\\to x_0^+}f(x)=A$$\r\n    Simialrly, if it is $0<x_0-x<\\delta\\implies|f(x)-A|<\\epsilon$, then\r\n    $$\\lim_{x\\to x_0^-}f(x)=A$$\r\n\\end{definition}\r\n\\begin{definition}\r\n    If the limit\r\n    $$\\lim_{h\\to0}\\frac{f(x+h)-f(x)}{h}$$\r\n    exists for all $x$ in a given domain, we say that $f$ is differentiable in this domain and its derivative is\r\n    $$f^\\prime(x)=\\frac{\\mathrm df}{\\mathrm dx}=\\lim_{h\\to0}\\frac{f(x+h)-f(x)}{h}$$\r\n\\end{definition}\r\nFor sufficiently smooth functions, we can differentiate it recursively.\r\nWe denote the $n^{th}$ derivative of $f$ as\r\n$$\\frac{d^nf}{dx^n}\\text{ or }f^{(n)}(x)$$\r\nSeveral immediate facts are available from here:\r\n\\begin{theorem}\r\n    1. The differential operator is linear.\\\\\r\n    2. (Chain Rule) Suppose both $F$ and $g$ are differentiable and $f(x)=F(g(x))$,\r\n    then $f$ is differentiable and $f^\\prime(x)=F^\\prime(g(x))g^\\prime(x)$.\\\\\r\n    3. (Leibniz's Rule) Suppose both $u$ and $v$ are differentiable and $f(x)=u(x)v(x)$, then\r\n    $$f^{(n)}(x)=\\sum_{k=0}^n\\binom{n}{k}u^{(k)}(x)v^{(n-k)}(x)$$\r\n    in particular $f^\\prime(x)=u(x)v^\\prime(x)+u^\\prime(x)v(x)$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}", "meta": {"hexsha": "a6947d60ce8ca45f259ea678d5e472300a0336fa", "size": 1994, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "0/calculus.tex", "max_stars_repo_name": "david-bai-notes/IA-Differential-Equations", "max_stars_repo_head_hexsha": "eba1ffe070fce235ce1c9611b23339c35c6d6931", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "0/calculus.tex", "max_issues_repo_name": "david-bai-notes/IA-Differential-Equations", "max_issues_repo_head_hexsha": "eba1ffe070fce235ce1c9611b23339c35c6d6931", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "0/calculus.tex", "max_forks_repo_name": "david-bai-notes/IA-Differential-Equations", "max_forks_repo_head_hexsha": "eba1ffe070fce235ce1c9611b23339c35c6d6931", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.4255319149, "max_line_length": 113, "alphanum_fraction": 0.6043129388, "num_tokens": 790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.7340136778310612}}
{"text": "\\section{Introduction}\n\nAn important area of research in quantum computing is\nto determine the problems for which quantum\ncomputers can outperform classical computers.\nTo avoid technical problems in the comparison of \ncomputers--the largest\nof which is that large-scale quantum computers\ncurrently do not exist--we turn to theoretical\nanalysis to characterize the efficiency of \nquantum and classical algorithms.\n\nWe implement a tool that places an asymptotic lower bound on runtime by calculating the optimal quantum query complexity of a Boolean function.\nThe query complexity of a function \nis the number of times we must examine the\ncontents of the input string to determine the correct\noutput of the function. \nEach query of the given function takes a certain\namount of time, therefore the query\ncomplexity places a lower bound on runtime.\nThe reverse is not true: the runtime\nmay asymptotically exceed query complexity\nif the algorithm performs substantially more\ncomputations than queries.\n\nTo give a concrete example of query complexity,\nrecall the canonical OR function.\nThe $n$-bit OR\nfunction returns $0$ if there are only $0$'s in the input\nstring and $1$ if there are any $1$'s in the input string.\nIn the worst case, a classical algorithm must check that\nevery single bit of the input is a $0$ to return $0$.\nTherefore the classical query complexity of the $n$-bit OR\nfunction is $n$. \nHowever, the quantum algorithm Grover's\nsearch can solve the function OR in $\\sqrt{n}$ queries\n\\cite{grover1996fast}. In the case of OR, we conclude that\nthe quantum algorithm outperforms the classical algorithm.\n\nFor an arbitrary function $f$,\nReichardt presents a semidefinite program (SDP)\nwhose solution corresponds to the optimal quantum query complexity\nof $f$ \\cite{reichardt2009span}.\nIn addition, the solution of the same SDP can\nbe used to construct a span program that, when run\non a quantum computer, meets the optimal quantum query complexity.\n\nOur contribution is an SDP solver\nthat finds the optimal quantum query complexity\nand query optimal quantum algorithm for given Boolean functions.\nWhile the SDP can be solved for arbitrary functions with finite outputs,\nwe limit the scope of our work to Boolean functions.\n\nAlthough there are many SDP solver libraries such as CVXOPT and\nSDPA for convex optimization problems,\nnone easily support solving Reichardt's SDP\n\\cite{cvxopt, SDPA}.\nAs a result, we develop an implementation that solves the SDP\nand includes optimizations specific to our problem formulation.\nWe first convert Reichardt's form into the standard SDP form\nas described by Boyd \\cite{boyd2004convex}, which we verify here.\nTo solve the SDP, we implement Wen et al.'s alternating direction method (ADM)\nalgorithm in order to exploit the sparsity of our SDP.\nWe finally optimize the functions and data structures we use\nto speed up our program \\cite{adm}. \n\nOur program takes as input a set of bitstrings $D$\nand a Boolean function $f: D \\rightarrow \\{0,1\\}$. \nBy solving Reichardt's SDP problem with\nWen et al.'s ADM algorithm,\nwe return the optimal quantum query complexity of $f$\nand a quantum algorithm that meets this query complexity.\nWe hope that our solver proves useful\nfor researchers constructing optimal quantum algorithms.\n", "meta": {"hexsha": "547bbae4421fe34135afc0a10f1dadb0de10255b", "size": 3264, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sec/1_introduction.tex", "max_stars_repo_name": "rtealwitter/QuantumQueryOptimizer", "max_stars_repo_head_hexsha": "64f68110ab088c271fad96976f2fa06af88d5a2e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/sec/1_introduction.tex", "max_issues_repo_name": "rtealwitter/QuantumQueryOptimizer", "max_issues_repo_head_hexsha": "64f68110ab088c271fad96976f2fa06af88d5a2e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/sec/1_introduction.tex", "max_forks_repo_name": "rtealwitter/QuantumQueryOptimizer", "max_forks_repo_head_hexsha": "64f68110ab088c271fad96976f2fa06af88d5a2e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.52, "max_line_length": 143, "alphanum_fraction": 0.8026960784, "num_tokens": 727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7339923499956266}}
{"text": "\\subsection{Lines}\r\n\\begin{itemize}\r\n\t\\item Lines through the origin can be represented as $\\theta = \\tan^{-1}{m}$ where $m$ is the slope of the line.\r\n\t\\item Lines of the form $x = a$ can be represented as $r = a\\sec{\\theta}$.\r\n\t\\item Lines of the form $y = a$ can be represented as $r = a\\csc{\\theta}$.\r\n\t\\item All other lines of the form $y=ax+b$ can be represented as $r = \\frac{b}{\\sin{\\theta} - a\\cos{\\theta}}$. This form also covers the previous 2.\r\n\\end{itemize}", "meta": {"hexsha": "4d6b5a6072396355a117fd4429dd4bdf99d3bb20", "size": 470, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/curvilinearCoordinates/lines_polar.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/curvilinearCoordinates/lines_polar.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/curvilinearCoordinates/lines_polar.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 67.1428571429, "max_line_length": 150, "alphanum_fraction": 0.6638297872, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772417253255, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.7339923432344791}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Cumulative}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises relating to various topics we have studied.\n\\end{abstract}\n\\maketitle\n\n\nA key skill to practice is deciding which of the several techniques we have learned should be applied to a particular problem. In these exercises and questions, you will be responsible for choosing a method which works for you.\n\n\\begin{exercise}\nCompute the indefinite integral.\n\\[ \\int \\ln x \\, dx = \\answer{ x \\ln x - x} + C\\]\n(You should choose an answer which equals $-1$ at $x = 1$; if your answer does not satisfy this, add a constant to make it so.)\n\\begin{hint}\nIntegrate by parts.\n\\end{hint}\n\\begin{hint}\nLet $u = \\ln x$ and $dv = 1$.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nCompute the indefinite integral.\n\\[ \\int \\frac{dx}{(x^2+1)^2} = \\answer{ \\frac{1}{2} \\frac{x}{x^2+1} + \\frac{1}{2} \\arctan x} + C.\\]\n(You should choose an answer which equals $0$ at $x = 0$; if your answer does not satisfy this, add a constant to make it so.)\n\\begin{hint}\nPartial fractions won't help in this case because the expression is already simplified as much as possible.\n\\end{hint}\n\\begin{hint}\nTry a trigonometric substitution\n\\end{hint}\n\\begin{hint}\nMake the substitution $x = \\tan \\theta$.\n\\end{hint}\n\\begin{hint}\nYou should arrive at the integral $\\int \\cos^2 \\theta \\, d \\theta$ after the substitution; here you'll need to use a power-reduction formula to continue.\n\\end{hint}\n\\end{exercise}\n\n\\section*{Sample Quiz Questions}\n\n\\begin{question}%%%%%[shelllogibp001]\n\nThe region in the plane between the  \\(x\\)-axis and the graph\n\\[ y = \\frac{1}{2} \\ln{x} + 1 \\]\n in the range \\(\\frac{1}{5} \\leq x \\leq 1\\) is revolved around the axis \\(x = \\frac{1}{10}\\). Compute the volume of the resulting solid.\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\frac{11}{25} \\pi\\)}\n\\choice{\\(\\displaystyle \\frac{14}{25} \\pi\\)}\n\\choice[correct]{\\(\\displaystyle \\frac{16}{25} \\pi\\)}\n\\choice{\\(\\displaystyle \\frac{19}{25} \\pi\\)}\n\\choice{\\(\\displaystyle \\frac{21}{25} \\pi\\)}\n\\choice{\\(\\displaystyle \\frac{24}{25} \\pi\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nIf the variable \\(x\\) is used for slicing, then slices are parallel to the axis of rotation, which indicates the shell method should be used.\nThe radius of a shell is \\(x - \\frac{1}{10}\\). The height of a shell is exactly \\(\\frac{1}{2} \\ln{x} + 1\\).\nThe volume of the region is therefore given by\n\\[ \\int_{\\frac{1}{5}}^{1} \\frac{\\pi}{10} \\left(10 x - 1\\right) \\left(\\ln{x} + 2\\right)\\, dx. \\]\n To compute the integral, we can use integration by parts. A reasonable strategy is to integrate  \\(x - \\frac{1}{10}\\) and differentiate  \\(\\ln{x} + 2\\).\n This gives the equality\n\\[ \\begin{aligned} \\pi \\int \\left(x - \\frac{1}{10}\\right) \\left(\\ln{x} + 2\\right)\\, dx & = \\pi \\left(\\left(\\frac{x^{2}}{2} - \\frac{x}{10}\\right) \\left(\\ln{x} + 2\\right) - \\int \\frac{1}{x} \\left(\\frac{x^{2}}{2} - \\frac{x}{10}\\right)\\, dx\\right) \\\\\n & = - \\pi \\left(\\frac{x^{2}}{4} - \\frac{x}{10}\\right) + \\pi \\left(\\frac{x^{2}}{2} - \\frac{x}{10}\\right) \\left(\\ln{x} + 2\\right). \\end{aligned} \\]\nTherefore \n\\[ \\begin{aligned} \\pi \\int_{\\frac{1}{5}}^{1} \\left(x - \\frac{1}{10}\\right) \\left(\\ln{x} + 2\\right)\\, dx & = \\left. \\left[- \\pi \\left(\\frac{x^{2}}{4} - \\frac{x}{10}\\right) + \\pi \\left(\\frac{x^{2}}{2} - \\frac{x}{10}\\right) \\left(\\ln{x} + 2\\right) \\right] \\right|_{\\frac{1}{5}}^{1}\\\\ & = \\left(\\frac{13}{20} \\pi \\right) - \\left(\\frac{\\pi}{100} \\right) = \\frac{16}{25} \\pi. \\end{aligned} \\]\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[COMsinibp001]\n\nConsider the region given by \\(2 \\pi \\leq x \\leq \\frac{5}{2} \\pi\\) and \\(0 \\leq y \\leq \\sin {x}\\).\nCompute the \\(x\\)-coordinate of the centroid (i.e., assuming constant density).\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle -1 + \\frac{5}{2} \\pi\\)}\n\\choice[correct]{\\(\\displaystyle 1 + 2 \\pi\\)}\n\\choice{\\(\\displaystyle \\frac{5}{2} \\pi\\)}\n\\choice{\\(\\displaystyle -1 + 3 \\pi\\)}\n\\choice{\\(\\displaystyle 3 \\pi\\)}\n\\choice{\\(\\displaystyle 4 \\pi\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nThe mass  \\(M\\) will be given by the integral\n\\[ \\int_{2 \\pi}^{\\frac{5}{2} \\pi} \\sin {x}\\, dx \\]\n One can check that\n\\[ \\begin{aligned} \\int_{2 \\pi}^{\\frac{5}{2} \\pi} \\sin {x}\\, dx & = 1. \\end{aligned} \\]\nTo compute the  \\(x\\)-coordinate of the centroid, we also need to compute the integral \n\\[ \\int_{2 \\pi}^{\\frac{5}{2} \\pi} x \\sin {x}\\, dx \\]\n To compute the integral, we can use integration by parts. A reasonable strategy is to integrate  \\(\\sin {x}\\) and differentiate  \\(x\\).\n This gives the equality\n\\[ \\begin{aligned} \\int x \\sin {x}\\, dx & = - x \\cos {x} - \\int \\left(- \\cos {x}\\right)\\, dx \\\\\n & = - x \\cos {x} + \\sin {x}. \\end{aligned} \\]\nTherefore \n\\[ \\begin{aligned} \\int_{2 \\pi}^{\\frac{5}{2} \\pi} x \\sin {x}\\, dx & = \\left. \\left[- x \\cos {x} + \\sin {x} \\right] \\right|_{2 \\pi}^{\\frac{5}{2} \\pi}\\\\ & = 1 - \\left(- 2 \\pi \\right) = 1 + 2 \\pi. \\end{aligned} \\]\nThe corret answer is the ratio of the integrals, i.e.,\n\\[ \\begin{aligned} \\overline{x} & = \\frac{1 + 2 \\pi}{1} = 1 + 2 \\pi. \\end{aligned} \\]\n\\end{feedback}\n\n\\end{question}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%%%%%[2015C.09]\n\nAn object moves in such a way that its acceleration at time \\(t\\) seconds is \\((t^2 + 5t + 6)^{-1}\\) meters per second squared. If the initial velocity of the object is \\(2/3\\) meters per second, what is the limit of its velocity as \\(t \\rightarrow \\infty\\)?\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\ln \\frac{3}{2}\\) meters per second}\n\\choice{\\(\\displaystyle \\ln 6\\) meters per second}\n\\choice{\\(1\\) meters per second}\n\\choice{\\(\\displaystyle \\ln \\frac{4}{9}\\) meters per second}\n\\choice{\\(\\displaystyle \\ln \\frac{9}{4}\\) meters per second}\n\\choice[correct]{\\(0\\) meters per second}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2017C.01]\n\nFind the volume of the solid generated by revolving the region bounded above by \\(y = \\sin x\\) and bounded below by \\(y = 0\\) for \\(0 \\leq x \\leq \\pi\\) about the line \\(x = \\pi\\).\n\\begin{multiplechoice}\n\\choice{\\(\\pi^2\\)}\n\\choice[correct]{\\(2\\pi^2\\)}\n\\choice{\\(4\\pi^2\\)}\n\\choice{\\(\\displaystyle\\frac{\\pi^2}{2}\\)}\n\\choice{\\(\\displaystyle\\frac{\\pi^2}{4}\\)}\n\\choice{none of these}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2017C.05]\n\nEvaluate \\(\\displaystyle \\int_1^2 x \\ln (x^2 + 1) dx\\).\n\\begin{multiplechoice}\n\\choice{\\(0\\)}\n\\choice{\\(1\\)}\n\\choice{\\(\\ln 2\\)}\n\\choice{\\(\\displaystyle \\frac{1}{2}\\)}\n\\choice{\\(\\displaystyle \\ln(2) - \\frac{1}{2}\\)}\n\\choice[correct]{none of these}\n\\end{multiplechoice}\n\\begin{feedback}\nThis integral can be computed via integration by parts. If we integrate \\(x\\) and differentiate \\(\\ln (x^2+1)\\), we get\n\\[\\begin{aligned}\n\\int_1^2 x \\ln (x^2+1) dx & = \\left. \\frac{x^2}{2} \\ln (x^2+1) \\right|_{1}^2 - \\int_1^2 \\frac{x^2}{2} \\frac{2x}{x^2+1} dx \\\\\n& = 2 \\ln 5 - \\frac{1}{2} \\ln 2 - \\int_1^2 \\frac{x^3}{x^2+1} dx.\n\\end{aligned}\\]\nThe latter integral can be simplified using polynomial long division: \\(\\displaystyle \\frac{x^3}{x^2+1} = x - \\frac{x}{x^2+1}\\).\nTherefore\n\\[\\begin{aligned}\n\\int_1^2 x \\ln (x^2+1) dx & = 2 \\ln 5 - \\frac{1}{2} \\ln 2 - \\int_1^2 x dx + \\int_1^2 \\frac{x}{x^2+1} dx \\\\\n& = 2 \\ln 5 - \\frac{1}{2} \\ln 2 - \\left. \\frac{x^2}{2} \\right|_1^2 + \\left. \\frac{1}{2} \\ln (x^2+1) \\right|_1^2 \\\\\n& = 2 \\ln 5 - \\frac{1}{2} \\ln 2 - 2 + \\frac{1}{2} + \\frac{1}{2} \\ln 5 - \\frac{1}{2} \\ln 2 \\\\\n& = \\frac{5}{2} \\ln 5 - \\frac{2}{2} \\ln 4 - \\frac{3}{2} - \\frac{3}{2} = \\ln \\left( \\frac{5^5}{4} \\right) - \\frac{3}{2}.\n\\end{aligned}\\]\n\\end{feedback}\n\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "5a06f4f1f6f363edf5b354a10b7b0a492090aa76", "size": 7588, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "techniques/13finalpractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "techniques/13finalpractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "techniques/13finalpractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.4371257485, "max_line_length": 387, "alphanum_fraction": 0.6325777543, "num_tokens": 2787, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938819, "lm_q2_score": 0.874077222043951, "lm_q1q2_score": 0.733992340730431}}
{"text": "\\section{Sets}\n\n\\subsection{Equivalence relations}\n\n\\begin{defn}\\label{defn:eq_rel}\nLet $R:A\\to (A\\to\\prop)$ be a binary relation valued in the propositions. We say that $R$ is an \\define{($0$-)equivalence relation}\\index{equivalence relation|textbf}\\index{0-equivalence relation|see {equivalence relation}} if $R$ comes equipped with\n\\begin{align*}\n\\rho & : \\prd{x:A}R(x,x) \\\\\n\\sigma & : \\prd{x,y:A} R(x,y)\\to R(y,x) \\\\\n\\tau & : \\prd{x,y,z:A} R(x,y)\\to (R(y,z)\\to R(x,z)).\n\\end{align*}\nGiven an equivalence relation $R:A\\to (A\\to\\prop)$, the \\define{equivalence class}\\index{equivalence class|textbf} $[x]_R$ of $x:A$ is defined to be\n\\begin{equation*}\n[x]_R\\defeq R(x).\n\\end{equation*}\n\\end{defn}\n\n\\begin{defn}\nLet $R:A\\to (A\\to\\prop)$ be a $0$-equivalence relation. \nWe define for any $x,y:A$ a map\\index{class_eq@{$\\mathsf{class\\usc{}eq}$}|textbf}\n\\begin{equation*}\n\\mathsf{class\\usc{}eq}:R(x,y)\\to ([x]_R=[y]_R).\n\\end{equation*}\n\\end{defn}\n\n\\begin{proof}[Construction.]\nLet $r:R(x,y)$. By function extensionality, the identity type $R(x)=R(y)$ is equivalent to the type\n\\begin{equation*}\n\\prd{z:A}R(x,z)=R(y,z).\n\\end{equation*}\nLet $z:A$. By the univalence axiom, the type $R(x,z)=R(y,z)$ is equivalent to the type\n\\begin{equation*}\n\\eqv{R(x,z)}{R(y,z)}.\n\\end{equation*}\nWe have the map $\\tau_{y,x,z}(\\sigma(r)):R(x,z)\\to R(y,z)$. Since this is a map between propositions, we only have to construct a map in the converse direction to show that it is an equivalence. The map in the converse direction is just $\\tau_{x,y,z}(r):R(y,z)\\to R(x,z)$. \n\\end{proof}\n\n\\begin{thm}\\label{thm:equivalence_classes}\nLet $R:A\\to (A\\to\\prop)$ be a $0$-equivalence relation. \nThen for any $x,y:A$ the map\n\\begin{equation*}\n\\mathsf{class\\usc{}eq} : R(x,y)\\to ([x]_R=[y]_R)\n\\end{equation*}\nis an equivalence.\n\\end{thm}\n\n\\begin{proof}\nBy the 3-for-2 property of equivalences, it suffices to show that the map\n\\begin{equation*}\n\\lam{r}{z}\\tau_{y,x,z}(\\sigma(r)) : R(x,y)\\to \\prd{z:A} \\eqv{R(x,z)}{R(y,z)}\n\\end{equation*}\nis an equivalence. Since this is a map between propositions, it suffices to construct a map of type\n\\begin{equation*}\n\\Big(\\prd{z:A} \\eqv{R(x,z)}{R(y,z)}\\Big)\\to R(x,y).\n\\end{equation*}\nThis map is simply $\\lam{f} \\sigma_{y,x}(f_x(\\rho(x)))$. \n\\end{proof}\n\n\\begin{rmk}\nBy \\cref{thm:equivalence_classes} we can begin to think of the \\emph{quotient}\\index{quotient} $A/R$ of a type $A$ by an equivalence relation $R$. Classically, the quotient is described as the set of equivalence classes, and \\cref{thm:equivalence_classes} establishes that two equivalence classes $[x]_R$ and $[y]_R$ are equal precisely when $x$ and $y$ are related by $R$.\n\nHowever, the type $A\\to\\prop$ may contain many more terms than just the $R$-equivalence classes. Therefore we are facing the task of finding a type theoretic description of the smallest subtype of $A\\to\\prop$ containing the equivalence classes.\nAnother to think about this is as the \\emph{image}\\index{image} of $R$ in $A\\to \\prop$. \nThe construction of the (homotopy) image of a map can be done with \\emph{higher inductive types}\\index{higher inductive type}, which we will do in \\cref{chap:image}.\n\\end{rmk}\n\nThe notion of $0$-equivalence relation which we defined in \\cref{defn:eq_rel} fits in a hierarchy of `$n$-equivalence relations'\\index{n-equivalence relation@{$n$-equivalence relation}}, the study of which is a research topic on its own. However, we already know an example of a relation that should count as an `$\\infty$-equivalence relation'\\index{infinity-equivalence relation@{$\\infty$-equivalence relation}}: the identity type. Analogous to \\cref{thm:equivalence_classes}, the following theorem shows that the canonical map\n\\begin{equation*}\n(x=y)\\to (\\idtypevar{A}(x)=\\idtypevar{A}(y))\n\\end{equation*}\nis an equivalence, for any $x,y:A$. In other words, $\\idtypevar{A}(x)$ can be thought of as the equivalence class of $x$ with respect to the relation $\\idtypevar{A}$.\n\n\\begin{thm}\nAssuming the univalence axiom on $\\UU$, the map\n\\begin{equation*}\n\\idtypevar{A}:A\\to (A\\to\\UU)\n\\end{equation*}\nis an embedding, for any type $A:\\UU$.\\index{identity type!is an embedding|textit}\n\\end{thm}\n\n\\begin{proof}\nLet $a:A$. By function extensionality it suffices to show that the canonical map\n\\begin{equation*}\n(a=b)\\to \\idtypevar{A}(a)\\htpy\\idtypevar{A}(b)\n\\end{equation*}\nthat sends $\\refl{a}$ to $\\lam{x}\\refl{(a=x)}$ is an equivalence for every $b:A$, and by univalence it therefore suffices to show that the canonical map\n\\begin{equation*}\n(a=b)\\to \\prd{x:A}\\eqv{(a=x)}{(b=x)}\n\\end{equation*}\nthat sends $\\refl{a}$ to $\\lam{x}\\idfunc[(a=x)]$ is an equivalence for every $b:B$. To do this we employ the type theoretic Yoneda lemma, \\cref{thm:yoneda}.\n\nBy the type theoretic Yoneda lemma\\index{Yoneda lemma} we have an equivalence\n\\begin{equation*}\n\\Big(\\prd{x:A} (b=x)\\to (a=x)\\Big)\\to (a=b)\n\\end{equation*}\ngiven by $\\lam{f} f(b,\\refl{b})$, for every $b:A$. Note that any family of maps $\\prd{x:A}(b=x)\\to (a=x)$ induces an equivalence of total spaces by \\cref{ex:contr_equiv}, since their total spaces are are both contractible by \\cref{cor:contr_path}. It follows that we have an equivalence\n\\begin{equation*}\n\\varphi_b:\\Big(\\prd{x:A} \\eqv{(b=x)}{(a=x)}\\Big)\\to (a=b)\n\\end{equation*}\ngiven by $\\lam{f} f(b,\\refl{b})$, for every $b:A$. \n\nNote that $\\varphi_a(\\lam{x}\\idfunc[(a=x)])\\jdeq\\refl{a}$. Therefore it follows by another application of \\cref{thm:yoneda} that the unique family of maps \n\\begin{equation*}\n\\alpha_b:(a=b)\\to \\Big(\\prd{x:A} \\eqv{(b=x)}{(a=x)}\\Big)\n\\end{equation*}\nthat satisfies $\\alpha_a(\\refl{a})=\\lam{x}\\idfunc[(a=x)]$ is a family of sections of $\\varphi$. \nIt follows that $\\alpha$ is a family of equivalences. Now the proof is completed by reverting the direction of the family of equivalences in the codomain.\n\\end{proof}\n", "meta": {"hexsha": "1c479e5c743312e95e244db5671efda662c942e8", "size": 5809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/sets.tex", "max_stars_repo_name": "tadejpetric/HoTT-Intro", "max_stars_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Book/sets.tex", "max_issues_repo_name": "tadejpetric/HoTT-Intro", "max_issues_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Book/sets.tex", "max_forks_repo_name": "tadejpetric/HoTT-Intro", "max_forks_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.2935779817, "max_line_length": 528, "alphanum_fraction": 0.7042520227, "num_tokens": 1964, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7339898943466515}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  For each of the following vector functions $T:\\R^n\\to\\R^n$, show\n  that $T$ is a linear transformation and find the corresponding\n  matrix $A$ such that $T(\\vect{x}) = A\\vect{x}$.\n  \\begin{enumerate}\n  \\item $T$ multiplies the $j\\th$ component of $\\vect{v}$ by a\n    non-zero number $b$.\n  \\item $T$ adds $b$ times the\n    $j\\th$ component of $\\vect{v}$ to the $i\\th$ component.\n  \\item $T$ switches the $i\\th$ and $j\\th$ components.\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item The matrix of $T$ is the elementary matrix that is like the\n      identity matrix, except that the $(j,j)$-entry is $b$.\n    \\item The matrix of $T$ is the elementary matrix that is like the\n      identity matrix, except that the $(i,j)$-entry is $b$.\n    \\item The matrix of $T$ is the elementary matrix that switches the\n      $i\\th$ and the $j\\th$ rows.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\\label{ex:linear-transformation-inconvenient}\n  Assume that $T:\\R^n\\rightarrow \\R^m$ is a linear transformation,\n  and that $\\vect{u}_1,\\ldots,\\vect{u}_n$ is a basis of $\\R^n$. For\n  all $i=1,\\ldots,n$, let $\\vect{v}_i = T(\\vect{u}_i)$. Let $A$ be the\n  matrix that has $\\vect{u}_1,\\ldots,\\vect{u}_n$ as its columns, and\n  let $B$ be the matrix that has $\\vect{v}_1,\\ldots,\\vect{v}_n$ as its\n  columns. Show that $A$ is invertible and the matrix of $T$ is\n  $BA^{-1}$.\n  \\begin{sol}\n    Since $\\vect{u}_1,\\ldots,\\vect{u}_n$ is a basis of $\\R^n$, we know\n    that $A$ is invertible by  Proposition~\\ref{prop:invertible-matrices}.\n    For each $i=1,\\ldots,n$, since $A\\vect{e}_i = \\vect{u}_i$, we have\n    $A^{-1}\\vect{u}_i=\\vect{e}_i$, and therefore\n    \\begin{equation*}\n      BA^{-1}\\vect{u}_i = B\\vect{e}_i = \\vect{v}_i = T(\\vect{u}_i).\n    \\end{equation*}\n    Now let $\\vect{w}$ be some arbitrary vector in $\\R^n$. Since\n    $\\vect{u}_1,\\ldots,\\vect{u}_n$ is a basis, there exists\n    $a_1,\\ldots,a_n$ such that $\\vect{w} =\n    a_1\\vect{u}_1+\\ldots+a_n\\vect{u}_n$. Then\n    \\begin{eqnarray*}\n      BA^{-1}\\vect{w}\n      &=& BA^{-1}(a_1\\vect{u}_1+\\ldots+a_n\\vect{u}_n) \\\\\n      &=& a_1(BA^{-1}\\vect{u}_1) + \\ldots + a_n(BA^{-1}\\vect{u}_n) \\\\\n      &=& a_1T(\\vect{u}_1) + \\ldots + a_nT(\\vect{u}_n) \\\\\n      &=& T(a_1\\vect{u}_1+\\ldots+a_n\\vect{u}_n) ~=~ T(\\vect{w}).\n    \\end{eqnarray*}\n    Therefore, $BA^{-1}$ is the matrix of $T$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $T$ is a linear transformation such that\n  \\begin{equation*}\n    T\\begin{mymatrix}{r} 1 \\\\ 2 \\\\ -6 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r} 5 \\\\ 1 \\\\ 3 \\end{mymatrix},\n    \\quad\n    T\\begin{mymatrix}{r} -1 \\\\ -1 \\\\ 5 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 5 \\end{mymatrix},\n    \\quad\\mbox{and}\\quad\n    T\\begin{mymatrix}{r} 0 \\\\ -1 \\\\ 2 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r} 5 \\\\ 3 \\\\ -2 \\end{mymatrix}.\n  \\end{equation*}\n  Find the matrix of $T$. Hint: use\n  Exercise~\\ref{ex:linear-transformation-inconvenient}.\n  \\begin{sol}\n    \\begin{equation*}\n      \\begin{mymatrix}{rrr}\n        5 & 1 & 5 \\\\\n        1 & 1 & 3 \\\\\n        3 & 5 & -2\n      \\end{mymatrix}\n      \\begin{mymatrix}{rrr}\n        1 & -1 & 0 \\\\\n        2 & -1 & -1 \\\\\n        -6 & 5 & 2\n      \\end{mymatrix}^{-1}\n      = \\begin{mymatrix}{rrr}\n        5 & 1 & 5 \\\\\n        1 & 1 & 3 \\\\\n        3 & 5 & -2\n      \\end{mymatrix}\n      \\begin{mymatrix}{rrr}\n        3 & 2 & 1 \\\\\n        2 & 2 & 1 \\\\\n        4 & 1 & 1\n      \\end{mymatrix}\n      = \\begin{mymatrix}{rrr}\n        37 & 17 & 11 \\\\\n        17 & 7 & 5 \\\\\n        11 & 14 & 6\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $T$ is a linear transformation such that\n  \\begin{equation*}\n    T\\begin{mymatrix}{r} 1 \\\\ 1 \\\\ -8 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ 1 \\end{mymatrix},\n    \\quad\n    T\\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 6 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r} 2 \\\\ 4 \\\\ 1 \\end{mymatrix},\n    \\quad\\mbox{and}\\quad\n    T\\begin{mymatrix}{r} 0 \\\\ -1 \\\\ 3 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r} 6 \\\\ 1 \\\\ -1 \\end{mymatrix}.\n  \\end{equation*}\n  Find the matrix of $T$. Hint: use\n  Exercise~\\ref{ex:linear-transformation-inconvenient}.\n  \\begin{sol}\n    \\begin{equation*}\n      \\begin{mymatrix}{rrr}\n        1 & 2 & 6 \\\\\n        3 & 4 & 1 \\\\\n        1 & 1 & -1\n      \\end{mymatrix}\n      \\begin{mymatrix}{ccc}\n        1 & -1 & 0 \\\\\n        1 & 0 & -1 \\\\\n        -8 & 6 & 3\n      \\end{mymatrix}^{-1}\n      = \\begin{mymatrix}{rrr}\n        1 & 2 & 6 \\\\\n        3 & 4 & 1 \\\\\n        1 & 1 & -1\n      \\end{mymatrix}\n      \\begin{mymatrix}{ccc}\n        6 & 3 & 1 \\\\\n        5 & 3 & 1 \\\\\n        6 & 2 & 1\n      \\end{mymatrix}\n      = \\begin{mymatrix}{ccc}\n        52 & 21 & 9 \\\\\n        44 & 23 & 8 \\\\\n        5 & 4 & 1\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the following linear transformations\n  $T:\\R^3\\rightarrow \\R^2$.  For each, determine the matrix $A$\n  such that $T(\\vect{x})=A\\vect{x}$.\n  \\begin{enumerate}\n  \\item $T\\begin{mymatrix}{c}\n      x \\\\\n      y \\\\\n      z\n    \\end{mymatrix} =\\begin{mymatrix}{c}\n      x+2y+3z \\\\\n      2y-3x+z\n    \\end{mymatrix}$\n\n  \\item $T\\begin{mymatrix}{c}\n      x \\\\\n      y \\\\\n      z\n    \\end{mymatrix} =\\begin{mymatrix}{c}\n      7x+2y+z \\\\\n      3x-11y+2z\n    \\end{mymatrix}$\n\n  \\item $T\\begin{mymatrix}{c}\n      x \\\\\n      y \\\\\n      z\n    \\end{mymatrix} =\\begin{mymatrix}{c}\n      3x+2y+z \\\\\n      x+2y+6z\n    \\end{mymatrix}$\n\n  \\item $T\\begin{mymatrix}{c}\n      x \\\\\n      y \\\\\n      z\n    \\end{mymatrix} =\\begin{mymatrix}{c}\n      2y-5x+z \\\\\n      x+y+z\n    \\end{mymatrix}$\n  \\end{enumerate}\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the matrix for\n  $T(\\vect{w}) = \\proj_{\\vect{v}}(\\vect{w})$, where\n  $\\vect{v}=\\mat{1, -2, 3}^T$.\n  \\begin{sol}\n    Recall that the desired matrix has $i\\th$ column equal to\n    $\\displaystyle\\proj_{\\vect{u}}(\\vect{e}_i) =\n    \\frac{\\vect{u}\\dotprod\\vect{e}_i}{\\norm{\\vect{u}}^2}\\vect{u}$.\n    Therefore, the matrix is\n    \\begin{equation*}\n      \\frac{1}{14}\\begin{mymatrix}{rrr}\n        1 & -2 & 3 \\\\\n        -2 & 4 & -6 \\\\\n        3 & -6 & 9\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the matrix for\n  $T(\\vect{w}) = \\proj_{\\vect{v}}(\\vect{w})$, where\n  $\\vect{v}=\\mat{1,5,3}^T$.\n  \\begin{sol}\n    \\begin{equation*}\n      \\frac{1}{35}\\begin{mymatrix}{rrr}\n        1 & 5 & 3 \\\\\n        5 & 25 & 15 \\\\\n        3 & 15 & 9\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "84fd05ce509d0d967e11737d31b9d5bdb1ad9483", "size": 6508, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/LinearTransformationsRn-Matrix.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/LinearTransformationsRn-Matrix.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/LinearTransformationsRn-Matrix.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 28.0517241379, "max_line_length": 74, "alphanum_fraction": 0.5281192379, "num_tokens": 2664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7339898615199192}}
{"text": "\\chapter{Background}\n\\label{sec:background}\n\nThis chapter presents the supporting concepts and methods that will be used throughout this work.\n\n\\section{Submodular Set Functions}\n\nFunctions over sets are of great interest and can be applied to diverse settings. In particular, submodular set functions have been utilized in multiple domains, such as document summarization and information gathering \\citep{krause14submodular}.\n\nA set function is defined on the powerset $2^{V}$ of a ground set $V$, i.e. $F:2^{V} \\rightarrow \\mathbb{R}$ and it is submodular if it exhibits a \"diminishing returns\" property , namely if it satisfies:\n\n\\begin{equation}\n  \\label{eq:submod-condition}\n  \\forall S,T \\subseteq V : S \\subseteq T, i \\notin T \\mid F(S \\cup i) - F(S) \\geq F(T \\cup i) - F(T)\n\\end{equation}\n\nIntuitively this indicates that adding an element to a smaller set yields a larger gain, i.e. in terms of the set function $F$ value, than adding it to a larger one. This is a natural property in the context of summarization where adding more information to a large summary is less effective than adding it to a smaller one. This property also makes them good candidates for modeling the concept of diversity \\citep{tschiatschek16learning}.\n\nAnalogous to the use of submodular functions to model diversity, supermodular functions can be used to model complementarity or coherence between elements.\n\nA set function is supermodular if it satisfies the condition in \\eqref{eq:submod-condition} with the inequality sign reversed, i.e. a set function $F(S)$ is supermodular iff $-F(S)$ is submodular. Supermodularity is used extensively in economics to model complementarity between strategies in games \\citep{amir2005supermodularity}.\n\nFinally, if a function $F$ is both submodular and supermodular, i.e. it satisfies condition \\eqref{eq:submod-condition} with equality, then it is said to be a modular function. These are the simplest examples of submodular or supermodular functions and are akin to linear functions but in a discrete domain.\n\n\\section{Probabilistic Log-sub/supermodular Models}\n\nSet functions may also express probability distributions, in which case they are known as Probability Set Functions. Formally, a set function $F$ is a probability set function if it satisfies that  $\\forall S \\subseteq V, P: 2^V \\rightarrow \\mathbb{R} \\mid 0 \\leq P(S) \\leq 1$ and $\\sum_{S \\subseteq V} P(S) = 1$ \\citep{bruno99sets}.\n\nIn this work we are interested in a particular class of probability set functions, namely probabilistic log-submodular and log-supermodular models, which are probabilities $P(S)$ of the form \\citep{djolonga14variational}:\n\n\\begin{equation}\n  P(S) = \\frac{1}{Z}\\exp(F(S)),\n\\end{equation}\n\nwhere $F(S)$ is a submodular or supermodular function, respectively. \\citet{djolonga14variational, djolonga15scalable} indicate that these models encompass many practical probabilistic models such as repulsive Ising models, Determinantal Point Processes (DPPs) and binary pairwise Markov Random Fields (MRFs).\n\nThe normalization constant $Z$ is also known as the \\textit{partition function} and it is necessary to fully determine the normalized model and compute quantities such as marginal probabilities, however its exact computation is known to be \\#P-complete in general \\citep{jerrum1990}. This makes it impossible in practice to perform such computations except for special cases of the model.\n\n\\section{Facility Location Diversity Model (FLID)}\n\nEvery modular function can be written as a sum of individual weights for each element $i \\in V$ assuming a normalization such that $F(\\emptyset) = 0$, i.e.\n\n\\begin{equation}\n  F(S) = \\sum_{i \\in S} u(i),\n\\end{equation}\n\nwhere $u(i)$ is some function $u: V \\rightarrow \\mathbb{R}$. For convenience, denote $\\mathbf{u}$ as the vector of modular weights where $u_{i} = u(i)$. Therefore any log-modular function can be written as:\n\n\\begin{equation}\n  \\label{eq:modular}\n  P(S) \\propto \\exp{\\left(\\sum_{i \\in S}u_{i}\\right)}= \\prod_{i \\in S} \\exp{\\left(u_{i}\\right)}\n\\end{equation}\n\nThis is the simplest log-submodular probability function and is the modular part for the FLID model proposed by \\citet{tschiatschek16learning}. In this model, $\\mathbf{u}$ can be thought of as modeling the relevance or utility of each element, for example in the context of spatial summarization this utility could be proportional to the popularity of a location or to how many times it has been photographed.\n\nHowever, these utilities alone can not capture interactions between the elements in a set. To address this, \\citet{tschiatschek16learning} proposed an additional term that models set diversity, its objective is to identify redundant elements and assign lower probabilities to sets that contain them.\n\nThis diversity promoting term is based on representing each element $i$ with an $L$-dimensional vector $\\mathbf{w}^{b} \\in \\mathbb{R}^{L}_{\\geq 0}$, where each dimension $d$, $1 \\leq d \\leq L$ captures a concept related to set diversity and $w^{b}_{i,d}$ quantifies the relevance of each element $i$ for each concept $d$. Hereby, define $\\mathbf{W}^{b} \\in \\mathbb{R}^{|V| \\times L}_{\\geq 0}$ as the matrix where the $i$-th row is the representation $\\mathbf{w}^{b}_{i}$ of element $i$.\n\nFor each dimension $d$, the diversity of a set $S$ is quantified by $\\max_{i \\in S}{w^{b}_{i,d}} - \\sum_{i \\in S}{w^{b}_{i,d}}$. This assigns a negative value for sets that contain more than one element with nonzero weight $w^{b}_{\\cdot,d}$ in that dimension \\citep{tschiatschek16learning}. Equation \\eqref{eq:diversity} shows the complete diversity term, this sums over all $L$ dimensions to account the diversity in each concept.\n\n\\begin{equation}\n  \\label{eq:diversity}\n  \\mathrm{div}(S) = \\sum_{d=1}^{L}\\left(\\max_{i \\in S}{w^{b}_{i, d}} - \\sum_{i \\in S}{w^{b}_{i,d}}\\right)\n\\end{equation}\n\nFinally, the complete FLID model proposed by \\citet{tschiatschek16learning} combines the modular and diversity terms and is given by:\n\n\\begin{equation}\n  \\tag{FLID}\n  P(S) = \\frac{1}{Z}\\exp{\\left(\\sum_{i \\in S}u_{i} + \\sum_{d=1}^{L}\\left(\\max_{i \\in S}{w^{b}_{i, d}} - \\sum_{i \\in S}{w^{b}_{i,d}}\\right)\\right)}\n  \\label{eq:flid}\n\\end{equation}\n\nAs mentioned before, the computation of the partition function is generally intractable for log-submodular models. However, for FLID this can be computed in time $\\mathcal{O}(|V|^{L+1})$ which is polynomial in the size of the ground set and significantly better than the cost of enumerating the powerset of $V$, i.e. $\\mathcal{O}(2^{|V|})$ \\citep{tschiatschek16learning}. Nevertheless, it is worth noting that this complexity is exponential in $L$ which means that the partition function computation is only pratical for a limited range of FLID models, namely those with $L \\ll |V|$.\n\n\\subsection{Example: Two Landmarks}\n\\label{sec:flid-toy}\n\nIn order to better illustrate the model, consider a town with 3 popular locations: A town hall ($h$), a statue ($s$) and a fountain ($f$). Assume that historic data shows that visitors only take photos at either the town hall and the statue, or at the town hall and the fountain. This can be modeled with FLID by introducing a latent dimension representing some concept that is present in both the statue and the fountain but not in the town hall, e.g. \"is not a building\".\n\nConcretely, let $V = \\{h, s, f\\}$ and $\\mathbf{u} = \\left(2, 2, 2\\right)^{\\intercal}$, indicating that all locations are equally popular. A suitable diversity weight matrix would then be $\\mathbf{W}^{b} = \\left(0, 20, 20\\right)^{\\intercal}$. Table \\ref{tab:flid-toy-probs} shows the resulting probabilities of the subsets, accurately representing the example scenario.\n\n\\begin{table}\n  \\centering\n  \\caption{FLID probability distribution for the scenario in Example \\ref{sec:flid-toy}.}\n  \\begin{tabular}{@{}ll@{}}\n    \\toprule\n    $S$ & $P(S)$  \\\\\n    \\midrule\n    $\\{h,s\\}, \\{h,f\\}$ & $\\approx 0.41$ \\\\\n    $\\{h\\}, \\{s\\}, \\{f\\}$ & $\\approx 0.06$ \\\\\n    $\\{\\}, \\{s,f\\}, \\{h,s,f\\}$ & $\\approx 0.00$ \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\label{tab:flid-toy-probs}\n\\end{table}\n\n\\section{Learning from Data}\n\\label{sec:learning}\n\nMuch of the interest in log-submodular models is concentrated on performing inference for known functions. However, \\citet{tschiatschek16learning} explore how to learn such models from data, i.e. estimate the model parameters from observations with an unknown distribution assumed to be of the same family as the models.\n\n\\subsection{Learning Log-modular Models}\n\\label{sec:learning_modular}\n\nA special case of log-submodular models where the parameters can be estimated efficiently using Maximum Likelihood Estimation (MLE) is the log-modular model presented in Equation \\eqref{eq:modular}. For this basic model, it is possible to estimate the utilities $\\mathbf{u}$ through the maximum likelihood estimator for the marginals $\\hat{P}(i \\in S)$. These marginals are given by:\n\n\\begin{equation}\nP(i \\in S) = \\frac{1}{1 + \\exp(-u_{i})}\n\\end{equation}\n\nAnd its maximum likelihood estimator for a dataset $\\mathcal{D}$ is:\n\n\\begin{equation}\n\\hat{P}(i \\in S) = \\frac{N(i \\in S)}{|\\mathcal{D}|},\n\\end{equation}\n\nwhere $N(i \\in S)$ is the number of sets containing element $i$. Therefore, the utilities can be estimated as:\n\n\\begin{equation}\n\\label{eq:modular-mle}\nu_{i} = -\\log{\\left(\\frac{1}{\\hat{P}(i \\in S)} - 1\\right)}\n\\end{equation}\n\nThis model also allows computing the partition function in closed form, i.e.:\n\n\\begin{equation}\n\\label{eq:modular-z}\nZ = \\prod_{i \\in S}(1 + \\exp(u_{i}))\n\\end{equation}\n\nBecause these quantities can be computed in closed form, it is possible to efficiently estimate the parameters of a log-modular model and sample from it. This is useful for producing noise samples and constructing baselines for the experiments.\n\nEven though MLE is the commonly used method for the task of parameter estimation from data, it only works efficiently for normalized models. This makes it intractable for the general class of log-submodular models, and also a wide range of FLID models because the computation of $Z$ is exponential on $L$. \\citet{Gutmann12NCE} propose an alternative method for parameter estimation in unnormalized models known as Noise Contrastive Estimation (NCE) and this is the method used by \\citet{tschiatschek16learning} to learn the FLID model.\n\n\\subsection{NCE Learning}\n\nThe idea behind NCE is to transform the unsupervised learning task of estimating a probability density from data into a supervised classification task. In order to do this, the observed data $\\mathcal{D}$, assumed to be drawn from an unknown distribution $P_{d}$, is compared to an artificially generated set of noise samples $\\mathcal{N}$ drawn from a known distribution $P_{n}$ that can be efficiently normalized. The classification task is to maximize the likelihood of correctly discriminating each sample as either observed data or artificial noise.\n\nFormally, denote $\\mathcal{A}$ as the complete set of labeled samples, i.e. $\\mathcal{A} = \\{(S,Y_{s}) : S \\in \\mathcal{D} \\cup \\mathcal{N}\\}$ where $Y_{s} = 1$ for $S \\in \\mathcal{D}$ and $Y_{s} = 0$ for $S \\in \\mathcal{N}$. Additionally, let $\\nu$ be the noise-to-data ratio, i.e. $\\nu = \\nicefrac{|\\mathcal{N}|}{|\\mathcal{D}|}$.\n\nThe goal is to estimate the posterior probabilities $P(Y_{s} = 1 \\mid S;\\boldsymbol{\\theta})$ and $P(Y_{s} = 0 \\mid S;\\boldsymbol{\\theta})$, in order to discriminate noise from data samples. These probabilities are given by equations \\eqref{eq:posterior-1} and \\eqref{eq:posterior-2}.\n\n\\begin{align}\n  P(Y_{s} &= 1 \\mid S;\\boldsymbol{\\theta}) = \\frac{\\hat{P}_{d}(S;\\boldsymbol{\\theta})}{\\hat{P}_{d}(S;\\boldsymbol{\\theta}) + \\nu P_{n}(S)}\n  \\label{eq:posterior-1} \\\\\n  P(Y_{s} &= 0 \\mid S;\\boldsymbol{\\theta}) = \\frac{\\nu P_{n}(S)}{\\hat{P}_{d}(S;\\boldsymbol{\\theta}) + \\nu P_{n}(S)}\n  \\label{eq:posterior-2}\n\\end{align}\n\nIt is worth noting that $\\hat{P}_{d}$ is used instead of $P_{d}$, because the real density is not known. As indicated by \\citet{Gutmann12NCE}, $\\hat{P}_{d}$ can be an unnormalized distribution for NCE where the partition function $Z$ is included in the set of parameters $\\boldsymbol{\\theta}$ as $\\hat{Z}$, hence resulting in an approximately normalized distribution after the optimization.\n\nIn order to obtain these posterior probabilities, the following conditional log-likelihood objective is maximized \\citep{Gutmann12NCE}:\n\n\\begin{equation}\n\\label{eq:log-likelihood}\ng(\\boldsymbol{\\theta}) = \\sum_{S \\in \\mathcal{D}}{\\log{P(Y_{s} = 1 \\mid S;\\boldsymbol{\\theta})}} + \\sum_{S \\in \\mathcal{N}}{\\log{P(Y_{s} = 0 \\mid S;\\boldsymbol{\\theta})}}\n\\end{equation}\n\nThis maximization can be performed using a gradient-based optimization method such as Stochastic Gradient Descent (SGD).\n\n\\subsubsection{Theoretical Considerations}\n\\label{sec:nce-theoretical}\n\nA couple of theoretical conditions are necessary for obtaining asymptotic convergence with NCE \\citep{Gutmann12NCE}:\n\n\\begin{enumerate}\n  \\item The parameterized probability function $\\hat{P}_{d}(S;\\theta)$ must be of the same family as the real distribution $P_{d}$, i.e. $\\exists \\boldsymbol{\\theta}^{*} \\mid \\hat{P}_{d}(S;\\boldsymbol{\\theta}^{*}) = P_{d}$.\n  \\item The noise distribution $P_{n}$ is nonzero whenever $P_{d}$ is nonzero.\n\\end{enumerate}\n\n\\subsubsection{Practical Considerations}\n\\label{sec:nce-practical}\n\nAdditionally, the following statements must be considered when choosing the noise distribution $P_{n}$ \\citep{Gutmann12NCE}:\n\n\\begin{enumerate}\n  \\item A distribution that can be sampled easily.\n  \\item Noise that is as similar as possible to the data, otherwise the classification problem could be too easy.\n  \\item A noise sample as large as possible.\n\\end{enumerate}\n\n\\subsection{Learning FLID via NCE and SGD}\n\nStochastic Gradient Descent was used by \\citet{tschiatschek16learning} to learn the FLID model through NCE. SGD is a gradient-based method that has been proven effective in large-scale learning tasks due to its efficiency when the computation time is a limiting factor \\citep{Bottou2010, Zhang2004}, hence making it appropriate for the scale of data sourced from the internet, such as public user photos in Flickr.\n\nIn each iteration, the gradient $\\nabla \\log{P(Y_{s} = y \\mid S;\\boldsymbol{\\theta})}$ must be computed. For FLID, the parameter vector $\\boldsymbol{\\theta}$ is composed by $\\mathbf{u}, \\mathbf{W}^{b}$ and $\\hat{Z}$, and the corresponding gradients are given by,\n\n\\begin{align}\n  \\label{eq:gradient-flid-1}\n  \\nabla \\log{P(Y_{s} = y \\mid S;\\boldsymbol{\\theta})} &= \\left(y - \\frac{1}{1 + \\nu \\frac{P_{n}(S)}{\\hat{P}_{d}(S;\\boldsymbol{\\theta})}}\\right) \\nabla \\log{\\hat{P}_{d}(S;\\boldsymbol{\\theta})} \\\\\n  \\label{eq:gradient-flid-2}\n  \\hat{P}_{d}(S;\\boldsymbol{\\theta}) &= \\frac{1}{\\hat{Z}}P(S; \\mathbf{u}, \\mathbf{W}^{b}) \\\\\n  \\left(\\nabla_{\\mathbf{u}}\\log{\\hat{P}_{d}(S; \\hat{Z}, \\mathbf{u}, \\mathbf{W}^{b})}\\right)_{i} &= \\begin{cases}\n    1 &  \\text{if}\\ i \\in S \\\\\n    0 & \\text{otherwise}\n  \\end{cases} \\\\\n  \\label{eq:gradient-flid-3}\n  \\left(\\nabla_{\\mathbf{W}^{b}}\\log{\\hat{P}_{d}(S; \\hat{Z}, \\mathbf{u}, \\mathbf{W}^{b})}\\right)_{i,d} &= \\begin{cases}\n    -1 & \\text{if}\\ i \\in S\\ \\text{and}\\ i \\neq \\argmax_{j \\in S}{w^{b}_{j,d}} \\\\\n    0 & \\text{otherwise}\n  \\end{cases} \\\\\n  \\label{eq:gradient-flid-4}\n  \\nabla_{\\hat{Z}}\\log{\\hat{P}_{d}(S; \\hat{Z}, \\mathbf{u}, \\mathbf{W}^{b})}&= \\frac{-1}{\\hat{Z}},\n\\end{align}\n\nwhere $P(S;\\mathbf{u}, \\mathbf{W}^{b})$ is the unnormalized \\eqref{eq:flid} equation, $\\left(\\nabla_{\\mathbf{u}}\\cdot \\right)_{i}$ represents the $i$-th entry of the gradient with respect to $\\mathbf{u}$ and $\\left(\\nabla_{\\mathbf{W}^{b}}\\cdot\\right)_{i,d}$ represents the $(i,d)$-th entry of the gradient with respect to $\\mathbf{W}^{b}$ \\citep{tschiatschek16learning}.\n\nAfter the gradient is computed, the parameters are updated according to the following equation,\n\n\\begin{equation}\n  \\theta^{t+1} = \\theta^{t} + \\eta(t) \\nabla g(\\theta),\n\\end{equation}\n\nwhere $\\eta(t)$ is the learning rate.\n\n\\subsubsection{Computational Complexity}\n\nAs described by \\citet{tschiatschek16learning}, the running time requirement for calculating the sub-gradient for FLID is $\\mathcal{O}(L|S|)$, therefore a complete pass over data and noise samples is $\\mathcal{O}(|\\mathcal{D}\\cup\\mathcal{N}|\\kappa L)$ where $\\kappa = \\max_{S \\in \\mathcal{D}\\cup\\mathcal{N}}{|S|}$, i.e. the largest subsed in $\\mathcal{D} \\cup \\mathcal{N}$. This shows that learning is efficient as it is only linear on the amount of data and noise.\n\n\\subsection{AdaGrad}\n\\label{sec:adagrad}\n\nA commonly used learning rate function for SGD is $\\eta(t) = \\eta_{0}t^{-p}$, which offers the best theoretical convergence speed for convex functions under certain conditions but often also in practice \\citep{bottou2012stochastic}, however it can lead to poor performance due to slow rates of convergence to the solution \\citep{darken1992towards}. By contrast, choosing a larger $\\eta_{0}$ may not lead to better results due to the instability in the parameters for small $t$ \\citep{Darken1990}. \n\nThis behavior was observed during the experiments with real data presented in later chapters, therefore an alternative for the learning rate was sought. In particular, Adaptive Gradient (AdaGrad) was implemented.\n\nAdaGrad was proposed by \\citet{Duchi2011adagrad}, the idea of this method is to adapt the learning rate for each parameter in $\\boldsymbol{\\theta}$ individually in a way that frequently updated parameters have slower learning rates while infrequent parameters have larger ones. The intuition is that an update to a rare parameter is more informative than one to a parameter that is frequently updated.\n\nConcretely, with AdaGrad the update step for each parameter $\\gamma$ in $\\boldsymbol{\\theta}$ is given by,\n\n\\begin{equation}\n\\theta^{\\tau + 1}_{\\gamma} \\leftarrow \\theta^{\\tau}_{\\gamma} - \\frac{\\eta}{\\sqrt{G_{\\gamma}}} \\nabla g(\\theta)^{\\tau}_{\\gamma},\n\\end{equation}\n\nwhere $\\mathbf{G}^{\\tau}$ is the vector of accumulated gradients at time $\\tau$ and each component $G^{\\tau}_\\gamma$ is given by,\n\n\\begin{equation}\nG^{\\tau}_{\\gamma} = \\sum_{t=1}^{\\tau} \\left(\\nabla g(\\theta)^{t}_{\\gamma}\\right)^{2},\n\\label{eq:adagrad-g}\n\\end{equation}\n\nwhere $\\nabla g(\\theta)^{t}_{\\gamma}$ denotes the gradient of the $\\gamma$ parameter at time step $t$.\n\nIt is worth noting that AdaGrad does not incur in an significant increase in running time or memory requirements for the training which makes it inexpensive to include in the implementation of NCE.\n\n\n", "meta": {"hexsha": "adeff190071bb68647c92039effb072a20719a32", "size": 18494, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/report/chapters/background.tex", "max_stars_repo_name": "dballesteros7/master-thesis-2015", "max_stars_repo_head_hexsha": "8c0bf9a6eef172fc8167a30780ae0666f8ea2d88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/report/chapters/background.tex", "max_issues_repo_name": "dballesteros7/master-thesis-2015", "max_issues_repo_head_hexsha": "8c0bf9a6eef172fc8167a30780ae0666f8ea2d88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/report/chapters/background.tex", "max_forks_repo_name": "dballesteros7/master-thesis-2015", "max_forks_repo_head_hexsha": "8c0bf9a6eef172fc8167a30780ae0666f8ea2d88", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 74.2730923695, "max_line_length": 583, "alphanum_fraction": 0.7347788472, "num_tokens": 5319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7339283729494689}}
{"text": "\\section*{WDA - Wasserstein Discriminant Analysis}\r\n\r\nRémi Flamary, Marco Cuturi, Nicolas Courty, Alain Rakotomamonjy\r\n(Submitted on 29 Aug 2016 (v1), last revised 23 May 2018 (this version, v2))\r\nWasserstein Discriminant Analysis (WDA) is a new supervised method that can improve classification of high-dimensional data by computing a suitable linear map onto a lower dimensional subspace. Following the blueprint of classical Linear Discriminant Analysis (LDA), WDA selects the projection matrix that maximizes the ratio of two quantities: the dispersion of projected points coming from different classes, divided by the dispersion of projected points coming from the same class. To quantify dispersion, WDA uses regularized Wasserstein distances, rather than cross-variance measures which have been usually considered, notably in LDA. Thanks to the underlying principles of optimal transport, WDA is able to capture both global (at distribution scale) and local (at samples scale) interactions between classes. Regularized Wasserstein distances can be computed using the Sinkhorn matrix scaling algorithm; We show that the optimization of WDA can be tackled using automatic differentiation of Sinkhorn iterations. Numerical experiments show promising results both in terms of prediction and visualization on toy examples and real life datasets such as MNIST and on deep features obtained from a subset of the Caltech dataset. ", "meta": {"hexsha": "2028efa792f678da07ad2da82711b20471516efe", "size": 1429, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications.tex", "max_stars_repo_name": "brucebcampbell/machine-learning-notes", "max_stars_repo_head_hexsha": "6c5229ef7b943455a4e890f0ec62764adf9a2c40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications.tex", "max_issues_repo_name": "brucebcampbell/machine-learning-notes", "max_issues_repo_head_hexsha": "6c5229ef7b943455a4e890f0ec62764adf9a2c40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications.tex", "max_forks_repo_name": "brucebcampbell/machine-learning-notes", "max_forks_repo_head_hexsha": "6c5229ef7b943455a4e890f0ec62764adf9a2c40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 285.8, "max_line_length": 1232, "alphanum_fraction": 0.8257522743, "num_tokens": 287, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314624993576758, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.7339283608154125}}
{"text": "\\section{Iterators} % (fold)\n\\label{sec:iterators}\n\\begin{questions}\n\\titledquestion{Collatz sequence} % (fold)\n\\label{sub:collatz_sequence}\n\nWrite a generator that generates the Collatz sequence with initial value $n$.\nUse this to print out the Collatz sequence started at 103\n\nRecall the Collatz sequence problem from last week.\nA Collatz sequence is formed as follows:\nWe start with some number $x_0$, and we find the next number in the sequence by\n\\[\n    x_{i+1} = \\begin{cases}\n        x_i / 2 & \\text{ if $x_i$ is even}\\\\\n        3x_i + 1 & \\text{ if $x_i$ is odd}\n    \\end{cases}\n\\]\nIf $x_i = 1$, we stop iterating and have found the full sequence.\n\n% titledquestion collatz_sequence (end)\n\n\\titledquestion{Collatz array using Numpy} % (fold)\n\\label{sub:collatz_array}\n\nUse the Collatz generator you wrote in the previous exercise to generate a vector\nwith as ellements the Collatz sequence started at 61.\n\nHint: use the \\texttt{np.fromiter} function.\n\n% titledquestion collatz_array (end)\n\n\\titledquestion{Prime numbers} % (fold)\n\\label{sub:prime_numbers}\n\nWrite an iterator that iterates over the first $n$ prime numbers.\nUse this to print out the first 10,000 primes.\n\n% titledquestion prime_numbers (end)\n\n\\end{questions}\n% section iterators (end)\n", "meta": {"hexsha": "b2e6e6a5280f6536d59704e3e73885f10759433c", "size": 1259, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/tex/iterator.tex", "max_stars_repo_name": "naskoch/python_course", "max_stars_repo_head_hexsha": "84adfd3f8d48ca3ad5837f7acc59d2fa051e95d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2015-08-10T17:46:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-18T21:09:03.000Z", "max_issues_repo_path": "exercises/tex/iterator.tex", "max_issues_repo_name": "naskoch/python_course", "max_issues_repo_head_hexsha": "84adfd3f8d48ca3ad5837f7acc59d2fa051e95d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/tex/iterator.tex", "max_forks_repo_name": "naskoch/python_course", "max_forks_repo_head_hexsha": "84adfd3f8d48ca3ad5837f7acc59d2fa051e95d3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-04-24T03:31:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-13T07:36:06.000Z", "avg_line_length": 29.2790697674, "max_line_length": 81, "alphanum_fraction": 0.7410643368, "num_tokens": 346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.733857988344763}}
{"text": "\n\n\n\\chapter{Limit and Continuity}\n%================================================\n%::::::::::::::::::::::::::::::::::::::::::::::::\n\n\nIn the sections below, the capitals with blackboard bold font, such as $\\mathbb A$, denote the normed vector spaces.\n\n\n\\section{O Notations}\n%================================================\n%------------------------------------------------\n\n\n\\begin{definition}\n\t\\label{def: little-o}\n\tLet $f: \\mathbb X \\to \\mathbb Y: \\mathbf x \\mapsto f(\\mathbf x)$ and $g: \\mathbb X \\to \\mathbb S: \\mathbf x \\mapsto g(\\mathbf x)$.\n\t\n\t$f$ is a \\textit{little-o of $g$ as $\\mathbf x \\to \\mathbf p$}, denoted\n\t$$\n\tf(\\mathbf x) = o(g(\\mathbf x)) \\quad \\text{as $\\mathbf x \\to \\mathbf p$},\n\t$$\n\tiff for any $\\varepsilon \\in \\mathbb R_{> 0}$, there exists a neighbourhood $N$ of $\\mathbf p$, such that for any $\\mathbf x \\in N$, $\\| f(\\mathbf x) \\|_{\\mathbb Y} \\le \\varepsilon \\| g (\\mathbf x)\\|_{\\mathbb S}$; equivalently, that is,\n\t$$\n\t\\lim_{\\mathbf x \\to \\mathbf p} \\frac{\\|f(\\mathbf x)\\|_{\\mathbb Y}}{\\| g(\\mathbf x) \\|_{\\mathbb S}} = 0 \\text{ or, equivalently, } \\lim_{\\mathbf x \\to \\mathbf p} \\frac{f(\\mathbf x)}{\\| g(\\mathbf x) \\|_{\\mathbb S}} = \\mathbf 0_{\\mathbb Y}\n\t$$\n\\end{definition}\n\n\n\\begin{lemma}\n\t\\label{lm: little-o: zero limit}\n\tWith the condition in Definition \\ref{def: little-o}, suppose\n\t$$\n\t\\lim_{\\mathbf x \\to \\mathbf p} \\| g(\\mathbf x) \\| \\in \\mathbb R,\n\t$$\n\t\n\tThen\n\t$$\n\tf(\\mathbf x) = o(g(\\mathbf x)) \\quad \\text{as $\\mathbf x \\to \\mathbf p$},\n\t$$\n\timplies\n\t$$\n\t\\lim_{\\mathbf x \\to \\mathbf p} f(\\mathbf x) = \\mathbf 0_{\\mathbb Y}.\n\t$$\n\t\n\t\\begin{proof}\n\t\tAiming for a contradiction, suppose there exists $\\mathbf r \\in \\mathbb Y \\setminus \\{ \\mathbf 0_{\\mathbb Y} \\}$, such that\n\t\t$$\n\t\t\\lim_{\\mathbf x \\to \\mathbf p} f(\\mathbf x) = \\mathbf r,\n\t\t$$\n\t\tthen, we have\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t\\lim_{\\mathbf x \\to \\mathbf p} \\frac{\\| f(\\mathbf x) \\|_{\\mathbb Y}}{\\| g(\\mathbf x) \\|_{\\mathbb S}} = \\lim_{\\mathbf x \\to \\mathbf p} \\frac{\\| \\mathbf r \\|_{\\mathbb Y}}{\\| g(\\mathbf x) \\|_{\\mathbb S}} > 0.\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\tThis contradicts the assumption.\n\t\\end{proof}\n\\end{lemma}\n\n\n\\begin{lemma}\n\t\\label{lm: little-o: negative}\n\tWith the condition in Definition \\ref{def: little-o}, $f$ is a little-o of $g$ iff $-f$ is a little-o of $g$.\n\t\n\t\\begin{proof}\n\t\t$$\n\t\t\\lim_{\\mathbf x \\to \\mathbf p} \\frac{\\| - f(\\mathbf x) \\|_{\\mathbb Y}}{\\| g(\\mathbf x) \\|_{\\mathbb S}} = \\lim_{\\mathbf x \\to \\mathbf p} \\frac{\\| f(\\mathbf x) \\|_{\\mathbb Y}}{\\| g(\\mathbf x) \\|_{\\mathbb S}} = 0.\n\t\t$$\n\t\\end{proof}\n\\end{lemma}\n\n\n\\begin{lemma}\n\t\\label{lm: little-o: finite sum}\n\tLet $f_1, f_2: \\mathbb X \\to \\mathbb Y: \\mathbf x \\mapsto f_1(\\mathbf x), f_2(\\mathbf x)$, and let $g: \\mathbb X \\to \\mathbb S: \\mathbf x \\mapsto g(\\mathbf x)$.\n\t\n\tIf $f_1$ and $f_2$ are both little-o of $g$ as $\\mathbf x \\to \\mathbf p$, i.e.,\n\t$$\n\tf_1(\\mathbf x) = o_1(g(\\mathbf x)) \\text{ and } f_2(\\mathbf x) = o_2(g(\\mathbf x)) \\text{ as $\\mathbf x \\to \\mathbf p$},\n\t$$\n\tthen $f_1 + f_2$ is also a little-o of $g$ as $\\mathbf x \\to \\mathbf p$, i.e.,\n\t$$\n\tf_1(\\mathbf x) + f_2(\\mathbf x) = o_3(g(\\mathbf x))\n\t$$\n\t\n\t\\begin{proof}\n\t\tBy triangle inequality,  we have\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t\\lim_{\\mathbf x \\to \\mathbf p}\\frac{\\| f_1(\\mathbf x) + f_2(\\mathbf x) \\|_{\\mathbb Y}}{\\| g(\\mathbf x) \\|_{\\mathbb S} } &\\le \\lim_{\\mathbf x \\to \\mathbf p} \\frac{\\| f_1(\\mathbf x) \\|_{\\mathbb Y} + \\| f_2(\\mathbf x) \\|_{\\mathbb Y}}{\\| g(\\mathbf x) \\|_{\\mathbb S}} \\\\\n\t\t\t&\\le 2 \\lim_{\\mathbf x \\to \\mathbf p} \\frac{\\max\\{ \\| f_1(\\mathbf x) \\|_{\\mathbb Y} + \\| f_2(\\mathbf x) \\|_{\\mathbb Y} \\}}{\\| g(\\mathbf x) \\|_{\\mathbb S}} \\\\\n\t\t\t&= 0.\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\tBy Definition \\ref{def: little-o}, $f_1 + f_2$ is a little-o of $g$ as $\\mathbf x \\to \\mathbf p$.\n\t\\end{proof}\n\\end{lemma}\n\n\n\n\\begin{note}\n\tIn Lemma \\ref{lm: little-o: finite sum}, consider $A$ be the set of all mappings being little-o of $g$ as $\\mathbf x \\to \\mathbf p$, then Lemma \\ref{lm: little-o: finite sum} tells that $A$ is finitely additive. That is, for any finite $B \\subseteq A$,\n\t$$\n\t\\sum_{o \\in B} o(g(\\mathbf p)) \\in A.\n\t$$\n\\end{note}\n\n\n\n\n\\chapter{Differentiation}\n%================================================\n%::::::::::::::::::::::::::::::::::::::::::::::::\n\n\n\n\\section{Differentiable Mappings}\n%================================================\n%------------------------------------------------\n\n\n\\begin{definition}\n\t\\label{def: differentiable mappings}\n\t\n\tLet $f: \\mathbb X \\to \\mathbb Y$.\n\t\n\t$f$ is said to be \\textit{differentiable at $\\mathbf p \\in \\mathbb X$} iff there exists a linear mapping $\\phi: \\mathbb X \\to \\mathbb Y$ such that for any $\\mathbf t \\in \\mathbb X$,\n\t$$\n\tf(\\mathbf p + \\mathbf t) = f(\\mathbf p) + \\phi(\\mathbf t) + o(\\mathbf t) \\quad \\text{as $\\mathbf t \\to \\mathbf 0_{\\mathbb X}$}.\n\t$$\n\\end{definition}\n\n\n\\begin{lemma}\n\t\\label{lm: uniqueness of phi}\n\t\n\tIn Definition \\ref{def: differentiable mappings}, the linear mapping $\\phi$ is unique.\n\t\n\t\\begin{proof}\n\t\tSuppose there is another linear mapping $\\lambda: \\mathbb X \\to \\mathbb Y$, such that for any $\\mathbf t \\in \\mathbb X$,\n\t\t$$\n\t\tf(\\mathbf p + \\mathbf t) = f(\\mathbf p) + \\lambda(\\mathbf t) + o_\\lambda (\\mathbf t) \\quad \\text{as $\\mathbf t \\to \\mathbf 0_{\\mathbb X}$},\n\t\t$$\n\t\tthen we have\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t& \\phi(\\mathbf{\\hat t}) - \\lambda(\\mathbf{\\hat t}) = \\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}}\\frac{\\phi(\\mathbf t) - \\lambda(\\mathbf t)}{\\| \\mathbf t \\|_{\\mathbb X}} = \\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}} \\frac{o(\\mathbf t) - o_\\lambda(\\mathbf t)}{\\| \\mathbf t\\|_{\\mathbb X}}\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\tBy Lemma \\ref{lm: little-o: negative}, $-o_{\\lambda}(\\mathbf t)$ is also a little-o of $\\mathbf t$ as $\\mathbf t \\to \\mathbf 0_{\\mathbb X}$, thus, by Lemma \\ref{lm: little-o: finite sum}, $o(\\mathbf t) - o_\\lambda(\\mathbf t)$ is a little-o of $\\mathbf t$ as $\\mathbf t \\to \\mathbf 0_{\\mathbb X}$. By Definition \\ref{def: little-o},\n\t\t$$\n\t\t\\phi(\\mathbf{\\hat t}) - \\lambda(\\mathbf{\\hat t}) = \\mathbf 0_{\\mathbb X}.\n\t\t$$\n\t\t\n\t\tAs $\\mathbf t$ is arbitrarily given, $\\mathbf{\\hat t}$ defines all possible directions in $\\mathbb X$. Thus,\n\t\t$$\n\t\t\\phi = \\lambda.\n\t\t$$\n\t\\end{proof}\n\\end{lemma}\n\n\n\n\\begin{lemma}\n\tWith the condition in Definition \\ref{def: differentiable mappings}, $f$ is differentiable at $\\mathbf p \\in \\mathbb X$ iff there exists a linear mapping $\\phi: \\mathbb X \\to \\mathbb Y$ such that for any $\\mathbf t \\in \\mathbb X$,\n\t\\begin{equation}\n\t\t\\tag{i}\n\t\t\\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}} \\frac{\\| f(\\mathbf p + \\mathbf t) - f(\\mathbf p) - \\phi(\\mathbf t) \\|_{\\mathbb Y}}{\\| \\mathbf t \\|_{\\mathbb X}} = 0.\n\t\\end{equation}\n\tEquivalently, that is,\n\t\\begin{equation}\n\t\t\\tag{i'}\n\t\t\\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}} \\frac{ f(\\mathbf p + \\mathbf t) - f(\\mathbf p) - \\phi(\\mathbf t) }{\\| \\mathbf t \\|_{\\mathbb X}} = \\mathbf 0_{\\mathbb Y}.\n\t\\end{equation}\n\t\n\t\\begin{proof}\n\t\tThis can be proved from both sides. Consider the equations in this proposition and in Definition \\ref{def: differentiable mappings}. We observe that the equation in Definition \\ref{def: differentiable mappings} holds iff\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t& \\frac{f(\\mathbf p + \\mathbf t) - f(\\mathbf p) - \\phi(\\mathbf t)}{\\| \\mathbf t \\|_{\\mathbb X}} = \\frac{o(\\mathbf t)}{\\| \\mathbf t \\|_{\\mathbb X}}\\\\\n\t\t\t\\iff & \\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}} \\frac{f(\\mathbf p + \\mathbf t) - f(\\mathbf p) - \\phi(\\mathbf t)}{\\| \\mathbf t \\|_{\\mathbb X}} = \\mathbf 0_{\\mathbb X} & \\text{((i') is proved)} \\\\\n\t\t\t\\iff & \\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}} \\frac{\\| f(\\mathbf p + \\mathbf t) - f(\\mathbf p) - \\phi(\\mathbf t)\\|_{\\mathbb Y}}{\\| \\mathbf t \\|_{\\mathbb X}} = 0. & \\text{((i) is proved)}\n\t\t\\end{aligned}\n\t\t$$\n\t\\end{proof}\n\\end{lemma}\n\n\n\n\\begin{lemma}\n\tWith the condition in Definition \\ref{def: differentiable mappings}, if $f$ is differentiable at $\\mathbf p$, then $f$ is continuous at $\\mathbf p$.\n\t\n\t\\begin{proof}\n\t\tAs $f$ is differentiable at $\\mathbf p$, there exists a linear mapping $\\phi: \\mathbb X \\to \\mathbb Y$, such that for any $\\mathbf t \\in \\mathbb X$,\n\t\t$$\n\t\tf(\\mathbf p + \\mathbf t) = f(\\mathbf p) + \\phi(\\mathbf t) + o(\\mathbf t) \\quad \\text{as $\\mathbf t \\to \\mathbf 0_{\\mathbb R^m}$}.\n\t\t$$\n\t\t\n\t\tAs\n\t\t$$\n\t\t\\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}} \\phi(\\mathbf t) = \\mathbf 0_{\\mathbb Y}\n\t\t$$\n\t\tand, by Lemma \\ref{lm: little-o: zero limit},\n\t\t$$\n\t\t\\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}}o(\\mathbf t) = \\mathbf 0_{\\mathbb Y},\n\t\t$$\n\t\t\n\t\twe have\n\t\t$$\n\t\t\\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}} f(\\mathbf p + \\mathbf t) = f(\\mathbf p),\n\t\t$$\n\t\twhich implies that $f$ is continuous at $\\mathbf p$.\n\t\\end{proof}\n\\end{lemma}\n\n\n\n\\begin{lemma}\n\t\\label{lm: differentiable: composed}\n\t\n\tLet $f: \\mathbb X \\to \\mathbb Y$ and let $g: \\mathbb Y \\to \\mathbb S$. If $f$ is differentiable at a point $\\mathbf p \\in \\mathbb X$, and $g$ is differentiable at $f(\\mathbf x)$, then $g \\circ f$ is differentiable at $\\mathbf p$.\n\t\n\t\\begin{proof}\n\t\tAs $g$ is differentiable at $f(\\mathbf p)$, there exists $\\lambda: \\mathbb Y \\to \\mathbb S$ such that for any $\\mathbf s \\in \\mathbb Y$ with $f(\\mathbf p) + \\mathbf s \\in f[\\mathbb X]$,\n\t\t$$\n\t\tg(f(\\mathbf p) + \\mathbf s) = g(f(\\mathbf p)) + \\lambda(\\mathbf s) + o(\\mathbf s) \\quad \\text{as $\\mathbf s \\to \\mathbf 0_{\\mathbb Y}$}.\n\t\t$$\n\t\t\n\t\tAs $f$ is differentiable at $\\mathbf p$, $f$ is continuous at $\\mathbf p$, thus, there exists $\\mathbf t \\in \\mathbb X$, such that $\\displaystyle\\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}} f(\\mathbf p + \\mathbf t) = f(\\mathbf p) + \\mathbf s$. Since $f$ is differentiable at $\\mathbf p$, there exists a linear mapping $\\phi: \\mathbb X \\to \\mathbb Y$, such that\n\t\t$$\n\t\tf(\\mathbf p + \\mathbf t) = f(\\mathbf p) + \\phi(\\mathbf t) + o_1 (\\mathbf t) \\quad \\text{as $\\mathbf t \\to \\mathbf 0_{\\mathbb X}$}.\n\t\t$$\n\t\t\n\t\tThen we have\n\t\t$$\n\t\tg(f(\\mathbf p + \\mathbf t)) = g(f(\\mathbf t)) + \\lambda(\\Delta f) + o(\\Delta f) \\quad \\text{as $\\mathbf t \\to \\mathbf 0_{\\mathbb X}$},\n\t\t$$\n\t\twhere\n\t\t$$\n\t\t\\Delta f = f(\\mathbf p + \\mathbf t) - f(\\mathbf p) = \\phi(\\mathbf t) + o_1(\\mathbf t) \\quad \\text{as $\\mathbf t \\to \\mathbf 0_{\\mathbb X}$}.\n\t\t$$\n\t\t\n\t\tFirst, find $\\lambda(\\Delta f)$. As $\\lambda$ is linear,\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t\\lambda(\\Delta f) &= \\lambda(\\phi(\\mathbf t) + o_1(\\mathbf t))\n\t\t\t= \\lambda(\\phi(\\mathbf t)) + \\lambda(o_1 (\\mathbf t)) \\quad \\text{as $\\mathbf t \\to \\mathbf 0_{\\mathbb X}$}.\n\t\t\\end{aligned}\n\t\t$$\n\t\tAs $\\lambda$ is linear, $\\lambda \\circ \\phi$ is also linear, and $\\lambda(o_1(\\mathbf t))$ is a little-o of $\\mathbf t$, i.e., $o_2(\\mathbf t) = \\lambda(o_1(\\mathbf t))$ as $\\mathbf t \\to \\mathbf 0_{\\mathbb X}$, for\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t\\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}} \\frac{\\lambda(o_1(\\mathbf t))}{\\| \\mathbf t \\|_{\\mathbb X}} &= \\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}} \\lambda\\left( \\frac{ o_1 (\\mathbf t) }{ \\| \\mathbf t \\|_{\\mathbb X} } \\right) \\\\\n\t\t\t&= \\lambda(\\mathbf 0_{\\mathbb Y}) \\\\\n\t\t\t&= \\mathbf 0_{\\mathbb S}.\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\tLet $\\gamma = \\lambda \\circ \\phi$ for convenience.\n\t\t\n\t\tThen, find $o(\\Delta f)$.\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t\\mathbf 0_{\\mathbb S} &= \\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}} \\frac{o(\\phi(\\mathbf t) + o_1(\\mathbf t))}{\\| \\phi(\\mathbf t) + o_1(\\mathbf t) \\|_{\\mathbb Y}}\n\t\t\t&\\text{(Definition \\ref{def: little-o})} \\\\\n\t\t\t&= \\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}} \\frac{ o(\\phi(\\mathbf t) + o_1(\\mathbf t)) \\| \\mathbf t \\|_{\\mathbb X}^{-1} }{ \\| \\phi(\\mathbf t) + o_1(\\mathbf t) \\|_{\\mathbb Y} \\| \\mathbf t \\|_{\\mathbb X}^{-1} } \\\\\n\t\t\t&= \\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}} \\frac{o(\\phi(\\mathbf t) + o_1(\\mathbf t))}{\\| \\mathbf t \\|_{\\mathbb X} \\| \\phi(\\mathbf{\\hat t})\\| _{\\mathbb Y}}\n\t\t\t&\\text{(as $\\phi$ is linear)} \\\\\n\t\t\t&= \\| \\phi(\\mathbf{\\hat t}) \\|_{\\mathbb Y}^{-1} \\lim_{\\mathbf t \\to \\mathbf 0_{\\mathbb X}} \\frac{o(\\phi(\\mathbf t) - o_1(\\mathbf t))}{\\| \\mathbf t \\|_{\\mathbb X}}.\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\tThus, $o(\\phi(\\mathbf t) - o_1(\\mathbf t)) = o_3(\\mathbf t)$ as $\\mathbf t \\to \\mathbf 0_{\\mathbb X}$.\n\t\t\n\t\tNow, we have\n\t\t$$\n\t\tg(f(\\mathbf p + \\mathbf t)) = g(f(\\mathbf t)) + \\gamma(\\mathbf t) + o_2(\\mathbf t) + o_3(\\mathbf t) \\quad \\text{as $\\mathbf t \\to \\mathbf 0_{\\mathbb X}$}.\n\t\t$$\n\t\t\n\t\tBy Lemma \\ref{lm: little-o: finite sum},\n\t\t$$\n\t\to_2(\\mathbf t) + o_3(\\mathbf t) = o_4(\\mathbf t) \\quad \\text{as $\\mathbf t \\to \\mathbf 0_{\\mathbb X}$}.\n\t\t$$\n\t\t\n\t\tFinally, we have\n\t\t$$\n\t\tg(f(\\mathbf p + \\mathbf t)) = g(f(\\mathbf t)) + \\gamma(\\mathbf t) + o_4(\\mathbf t) \\quad \\text{as $\\mathbf t \\to \\mathbf 0_{\\mathbb X}$},\n\t\t$$\n\t\twhich implies $g \\circ f$ is differentiable at $\\mathbf p$.\n\t\\end{proof}\n\\end{lemma}\n\n\n\\section{Directional Derivatives}\n%================================================\n%------------------------------------------------\n\n\n\\begin{definition}\n\t\\label{def: directional derivatives}\n\t\n\tLet $f: \\mathbb X \\to \\mathbb Y$, and let $\\mathbf u \\in \\mathbb X \\setminus \\{ \\mathbf 0_{\\mathbb X} \\}$.\n\t\n\tThe \\textit{$\\mathbf u$-directional derived mapping}\n\\end{definition}\n\n\n\n---\n\n---\n\n---\n\n---\n\n---\n\n---\n\n---\n\n---\n\n---\n\n---\n\n---\n\n---\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n%", "meta": {"hexsha": "32f06349e889477735d05159b02c00b2d4f32990", "size": 13074, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vector Calculus/content/0-content.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vector Calculus/content/0-content.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vector Calculus/content/0-content.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.8704663212, "max_line_length": 360, "alphanum_fraction": 0.5739635919, "num_tokens": 5166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737807, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7338579867041476}}
{"text": "\\chapter{Depth-First Search}\n\nOne important operation in a graph is search.  A useful kind of search\nis Depth-First, in which we begin as some start node, marking the node\nvisited, then we recurse on the neighbours one by one until no more\nunvisited neighbours exist.\n\nDuring a visit, we label each node with a number before visiting its\nchildren and another number after visiting its children.  This number\n(called the clock) starts at 1, and is incremented every time a node\nreceives a label.  The number a node $v$ receives before its children\nare visited is called its pre-number ($pre(v)$), and the number that\nnode receives after its children are visited is called its post-number\n($post(v)$).\n\n\\begin{theorem}[Parenthesis Theorem]\n\nFor nodes $u,v$, the interval between $pre(u)$ and $post(u)$ and the\nsame interval for $v$ are either:\n\n\\begin{itemize}\n\n\\item Entirely disjoint\n\\item The interval of $u$ is completely within the interval of $v$\n\\item The interval of $v$ is completely within the interval of $u$\n\n\\end{itemize}\n\nThe name comes from the fact that this is just like properly nested\nparentheses.\n\n\\end{theorem}\n\nRunning a DFS on a graph reveals a tree structure where the start node\nis the root and neighbours are parent and child depending on which was\nvisited first.  There are a few interesting classifications of edges\nin a DFS tree:\n\n\\begin{enumerate}\n\n\\item A \\emph{Tree Edge} goes from a parent node to a child node.\n\n\\item A \\emph{Forward Edge} goes from ancestor to descendant (but not\n  parent to child)\n\n\\item A \\emph{Back Edge} goes from descendant to ancestor\n\n\\item A \\emph{Cross Edge} goes to a non-ancestor non-descendant\n\n\\end{enumerate}\n\n\\begin{theorem}\nA digraph has a cycle if and only if a DFS reveals a back edge.\n\\end{theorem}\n\n\\begin{proof}\n\nFirst let us assume there is a back edge.  By definition this is a\ndescendant linking back to an ancestor, which has already been\nvisited.  This gives us a cycle.\n\nNext let us assume there is a cycle.  A DFS will visit each node in\nthe cycle, and as soon as the last edge in the cycle is visited it\nwill link a descendant to ancestor which is the definition of a back\nedge.\n\n\\end{proof}\n\n\\begin{theorem}\n\nAfter running a DFS on a directed acyclic graph (DAG), each edge leads\nto a vertex with a lower post number.\n\n\\end{theorem}\n\nThe proof of this theorem is left up to the reader.\n", "meta": {"hexsha": "fc5e779ebb6a476b2c9fd84ec165918862667be1", "size": 2367, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "dfs.tex", "max_stars_repo_name": "SteamedPears/AllTheAlgorithms", "max_stars_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-10-12T19:16:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-01T03:13:05.000Z", "max_issues_repo_path": "dfs.tex", "max_issues_repo_name": "SteamedPears/AllTheAlgorithms", "max_issues_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dfs.tex", "max_forks_repo_name": "SteamedPears/AllTheAlgorithms", "max_forks_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.7402597403, "max_line_length": 70, "alphanum_fraction": 0.7625686523, "num_tokens": 588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916064587, "lm_q2_score": 0.8499711832583695, "lm_q1q2_score": 0.7338579853570457}}
{"text": "\\chapter{Algorithms for One-Dimensional Optimization}\n\\label{sec:algOneDimOpt}\n\\section{Interval Division Algorithms}\n\\lab{sec:IntDivAlg}\nInterval division algorithm can be used to minimize a function $f \\colon \\Re \\to \\Re$,\n(i.e., the function depends on one independent parameter only,)\nover a user-specified interval.\nThe algorithms do not require derivatives and \nthey require only one function evaluation per interval division, \nexcept for the initialization.\n\nFirst, we explain a master algorithm for the interval division algorithms.\nThe master algorithm is used to implement two commonly used interval division algorithms: \nThe Golden Section search and the Fibonacci Division. \n\n\\begin{figure}\n\\centering\n\\epsfig{file=img/int_div.eps, bb=65 345 245 535}\n\\caption{Interval division.}\n\\label{fig:intDivGen}\n\\end{figure}\n\n% --------\n\\subsection{General Interval Division}\nWe now describe the ideas behind the interval division methods.\nFor given $x_0, x_3 \\in \\Re$, with $x_0 < x_3$,\nlet $\\mathbf X \\triangleq [x_0, x_3]$.\nSuppose we want to minimize $f(\\cdot)$ on $\\mathbf X$,\nand suppose that $f \\colon \\Re \\rightarrow \\Re$ has a unique minimizer \n$x^* \\in \\mathbf X$.\nFor some $s \\in (0, 1)$, let\n\\begin{eqnarray}\n   x_1 & \\triangleq & x_0 + s \\, (x_3 - x_0), \\\\\n   x_2 & \\triangleq & x_1 + s \\, (x_3 - x_1).\n\\end{eqnarray}\nIf $f(x_1) \\le f(x_2)$, then $x^* \\in  [x_0, \\, x_2]$.\nHence, we can eliminate the interval $(x_2, \\, x_3]$ \nand restrict our search to $[x_0, \\, x_2]$.\nSimilarly, if $f(x_1) > f(x_2)$, then $x^* \\in [x_1, \\, x_3]$ \nand we can eliminate $[x_0, \\, x_1)$.\nThus, we reduced the initial interval to a new interval that contains the minimizer $x^*$.\\\\\n\nLet $i \\in \\Na$ be the iteration number.\nWe want to nest the sequence of intervals\n\\begin{equation}\n[x_{0,(i+1)}, \\, x_{3,(i+1)}] \\subset [x_{0,i}, \\, x_{3,i}], \\qquad i \\in \\{0, \\, 1, \\, 2, \\, \\ldots \\},\n\\end{equation}\nsuch that we have to evaluate $f\\depd$ in each step at one new point only.\nTo do so, we assign the new bounds of the interval such that either \n$[x_{0,(i+1)}, \\, x_{3,(i+1)}] = [x_{0,i}, \\, x_{2,i}]$, or $[x_{0, (i+1)}, \\, x_{3, (i+1)}] = [x_{1,i}, \\, x_{3,i}]$, \ndepending on which interval has to be eliminated. \nBy doing so, we have to evaluate only one new point in the interval. \nIt remains to decide where to locate the new point.\nThe Golden Section and Fibonacci Division differ in this decision.\n\n% --------\n\\subsection{Golden Section Interval Division}\nSuppose we have three points $x_0 < x_1 < x_3$ in $\\mathbf X \\subset \\Re$\nsuch that for some $q \\in (0, 1)$, to be determined later,\n\\begin{subequations}\n\\begin{equation}\n   \\frac{ | x_0 - x_1 | }{ | x_0 - x_3 |  } = q.\n   \\label{eq:golSecQDef}\n\\end{equation}\nHence,\n\\begin{equation}\n   \\frac{ | x_1 - x_3 | }{ | x_0 - x_3 |  } = 1-q.\n\\end{equation}\n\\end{subequations}\n\nSuppose that $x_2$ is located somewhere between $x_1$ and $x_3$ and define\nthe ratio\n\\begin{equation}\n  w \\triangleq \\frac{ | x_1 - x_2 | }{ | x_0 - x_3 |  }.\n\\end{equation}\nDepending on which interval is eliminated, the interval in the next iteration step will\neither be of length \n$(q+w) \\, | x_0 - x_3|$, \nor $(1-q)  \\, | x_0 - x_3|$.\nWe select the location of $x_2$ such that the two intervals are of the same length. \nHence,\n\\begin{subequations}\n\\begin{equation}\n   q + w = 1 - q.\n  \\label{eq:golSecqw}\n\\end{equation}\nNow, we determine the fraction $q$.\nSince we apply the process of interval division recursively, we know by scale similarity that\n\\begin{equation}\n   \\frac{ w }{ 1 - q } = q.\n   \\label{eq:golSecq}\n\\end{equation}\n\\end{subequations}\n\\begin{subequations}\nCombining (\\ref{eq:golSecqw}) and (\\ref{eq:golSecq}) leads to\n\\begin{equation}\n   q^2 - 3 q + 1 = 0,\n\\end{equation}\nwith solutions\n\\begin{equation}\n   q_{1,2} = \\frac{3 \\pm \\sqrt{5}}{2}.\n\\end{equation}\nSince $q < 1$ by (\\ref{eq:golSecQDef}), the solution of interest is\n\\begin{equation}\n   q = \\frac{3 - \\sqrt{5}}{2} \\approx 0.382.\n\\end{equation}\n\\end{subequations}\n\nThe fractional distances $q \\approx 0.382$ and $1-q \\approx 0.618$ correspond to the so-called \\emph{Golden Section}, which gives this algorithm its name.\\\\\n\nNote that the interval is reduced in each step by the fraction $1-q$, i.e., we have \\emph{linear convergence}. In the $m$-th iteration, we have\n\\begin{eqnarray}\n   | x_{ 0, \\, m} - x_{ 2, \\, m} | & = &\n   | x_{ 1, \\, m} - x_{ 3, \\, m} | =\n   | x_{ 0, \\, (m+1)} - x_{ 3, \\, (m+1)} | \\nonumber \\\\\n & = &\n   (1-q)^{m+1} \\,    | x_{ 0, \\, 0} - x_{ 3, \\, 0} |.\n\\end{eqnarray}\nHence, the required number of iterations, $m$, to reduce the initial interval of uncertainty $|x_{0, \\,0} - x_{3, \\, 0} |$ to at least a fraction $r$, defined as\n\\begin{equation}\n   r \\triangleq \\frac{ | x_{ 0, \\, m} - x_{ 2, \\, m} | }\n                { | x_{ 0, \\, 0} - x_{ 3, \\, 0} | }\n    = \\frac{ | x_{ 1, \\, m} - x_{ 3, \\, m} | }\n                { | x_{ 0, \\, 0} - x_{ 3, \\, 0} | },\n  \\label{eq:golSecDefR}\n\\end{equation}\nis given by\n\\begin{equation}\n  m = \\frac{\\ln r}{ \\ln (1-q)} - 1.\n\\end{equation}\n\n\n% =======================\n\\subsection{Fibonacci Division}\nAnother way to divide an interval such that we need one function evaluation per iteration can be constructed as follows: Given an initial interval $[x_{0, \\, i}, x_{3, \\, i}]$ , $i=0$, we divide it into three segments symmetrically around its midpoint. Let $d_{1,\\, i} < d_{2,\\, i} < d_{3,\\, i}$ denote the distance of the segment endpoints, measured from $x_{0, \\,i}$. Then we have by symmetry $d_{3,\\, i}=d_{1,\\, i} + d_{2,\\, i}$. By the bracket elimination procedure explained above, we know that we are eliminating a segment of length $d_{1,\\, i}$. Therefore, our new interval is of length $d_{3,\\, (i+1)}= d_{2,\\, i}$. By symmetry we also have $d_{3,\\, (i+1)}= d_{1,\\, (i+1)} + d_{2,\\, (i+1)}$. Hence, if we construct our segment length such that $d_{3,\\, (i+1)} = d_{1,\\, (i+1)} + d_{2,\\, (i+1)}= d_{2,\\, i}$ we can reuse one known point. Such a construction can be done by using \\emph{Fibonacci} numbers, which are defined recursively by\n\\begin{subequations}\n\\begin{eqnarray}\n  F_0 & \\triangleq & F_1 \\triangleq 1, \\\\\n  F_i & \\triangleq & F_{i-1} + F_{i-2}, \\qquad i \\in \\{2, \\, 3, \\, \\ldots \\}.\n\\end{eqnarray}\n\\end{subequations}\nThe first few numbers of the Fibonacci sequence are $\\{1, \\, 1, \\,  2, \\, 3, \\, 5, \\, 8, \\, 13, \\, 21, \\, \\ldots \\}$. The length of the intervals $d_{1,\\, i}$ and $d_{2, \\, i}$, respectively, are then given by\n\\begin{equation}\n   d_{1, \\, i} = \\frac{F_{m-i} }{ F_{m-i+2} }, \\quad\n  d_{2, \\, i} = \\frac{F_{m-i+1} }{ F_{m-i+2} }, \\qquad\n  i \\in \\{0, \\, 1, \\, \\ldots \\, , \\, m \\},\n\\end{equation}\nwhere $m > 0 $ describes how many iterations will be done. Note that $m$ must be known prior to the first interval division. \nHence, the algorithm must be stopped after $m$ iterations.\\\\\n\nThe reduction of the length of the uncertainty interval per iteration is given by\n\\begin{equation}\n  \\frac{ d_{3, \\, (i+1)} }{  d_{3, \\, i}  } =\n  \\frac{ d_{2, \\, i} }{  d_{1, \\, i} + d_{2, \\, i}  } = \n   \\frac{  \\frac{ F_{m-i+1} }{F_{m-i+2}}  }\n     {  \\frac{F_{m-i}}{F_{m-i+2}} +  \\frac{F_{m-i+1}}{F_{m-i+2}}   } = \n        \\frac{ F_{m-i+1}   }{ F_{m-i+2}   }.\n\\end{equation}\nAfter $m$ iterations, we have\n\\begin{eqnarray}\n  \\frac{d_{3, \\, m}}{d_{3, \\, 0}} & = & \n  \\frac{ d_{ 3, \\, m}  }{ d_{ 3, \\, (m-1)}  } \\, \n  \\frac{ d_{ 3, \\, (m-1)}  }{ d_{ 3, \\, (m-2)}  } \\,\n   \\ldots \\,\n   \\frac{ d_{ 3, \\, 2}  }{ d_{ 3, \\, 1}  } \\,\n   \\frac{ d_{ 3, \\, 1}  }{ d_{ 3, \\, 0}  } \\nonumber \\\\\n & = &\n  \\frac{F_{2} }{ F_{3} } \\, \n  \\frac{F_{3} }{ F_{4} } \\, \\ldots \\, \n  \\frac{F_{m} }{ F_{m+1} } \\, \n  \\frac{F_{m+1} }{ F_{m+2} } \n=\n  \\frac{2}{F_{m+2}}.\n\\end{eqnarray}\nThe required number of iterations $m$ to reduce the initial interval $d_{3, \\, 0}$ \nto at least a fraction $r$, defined by (\\ref{eq:golSecDefR}), can again be obtained by expansion from\n\\begin{eqnarray}\n  r & = & \n  \\frac{d_{2, \\, m}}{d_{3, \\, 0}} = \n  \\frac{ d_{ 3, \\, (m+1)}  }{ d_{ 3, \\, 0}  } = \n  \\frac{ d_{ 3, \\, (m+1)}  }{ d_{ 3, \\, m}  } \\,\n  \\frac{ d_{ 3, \\, m}  }{ d_{ 3, \\, (m-1)}  } \\,\n   \\ldots \\,\n   \\frac{ d_{ 3, \\, 2}  }{ d_{ 3, \\, 1}  } \\,\n   \\frac{ d_{ 3, \\, 1}  }{ d_{ 3, \\, 0}  } \\, \\nonumber \\\\\n & = &\n  \\frac{F_{1} }{ F_{2} } \\, \n  \\frac{F_{2} }{ F_{3} } \\, \\ldots \\, \n  \\frac{F_{m} }{ F_{m+1} } \\, \n  \\frac{F_{m+1} }{ F_{m+2} } \n=\n  \\frac{1}{F_{m+2}}.\n\\end{eqnarray}\nHence, $m$ is given by\n\\begin{equation}\n  m = \\argmin_{m \\in \\Na} \\left\\{ m \\ | \\ r \\ge \\frac{1}{F_{m+2}} \\right\\}.\n\\end{equation}\n\n\n% -----------------\n\\subsection{Comparison of Efficiency}\nThe Golden Section is more efficient than the Fibonacci Division. Comparing the reduction of the interval of uncertainty, $| x_{0, \\, m} - x_{3, \\, m}|$, in the limiting case for $m \\rightarrow \\infty$, we obtain\n\\begin{equation}\n   \\lim_{m \\rightarrow \\infty} \\frac{ | x_{0, \\, m} - x_{3, \\, m}  |_{GS} }\n  { | x_{0, \\, m} - x_{3, \\, m}  |_{F} }\n= \\lim_{m \\rightarrow \\infty} \\frac{F_{m+2}}{2} \\, (1-q)^m = 0.95.\n\\end{equation}\n\n% --------------------\n\n\\subsection{Master Algorithm for Interval Division}\nThe following master algorithm explains the steps of \nthe interval division algorithm.\\\\\n\n\\noindent\n\\begin{minipage}[b]{\\textwidth}\n\\begin{algorithm}\n[Model Interval Division Algorithm]\n~\\\\\n{\\em\n\\begin{tabularx}{\\headwidth}{m{2cm}l}\n\\multicolumn{2}{l}{\\hspace{\\textwidth}~} \\\\ \\\\[-8ex]\\\\\n\\hline \\\\[-2ex]\n \\textbf{Data}: \n & $x_0$, $x_3$. \\\\\n & Procedure that returns $r_i$, defined as\\\\\n & $r_i \\triangleq |x_{0, \\, i} - x_{2, \\, i} | / |x_{0, \\, 0} - x_{3, \\, 0}|$. \\\\\n\\textbf{Step 0:} \n & {\\it Initialize }\\\\\n  & $\\Delta x = x_3 - x_0$,\\\\\n  &$ x_2 = x_0 + r_1 \\, \\Delta x$,\\\\\n  & $x_1 = x_0 + r_2 \\, \\Delta x$,\\\\\n  & $f_1 = f(x_1)$, $ f_2 = f(x_2)$, and\\\\\n  & $i = 2$.\\\\\n\\textbf{Step 1:} & {\\it Iterate.}\\\\\n  & Replace $i$ by $i + 1$.\\\\\n  & If  $(f_2 < f_1)$\\\\\n    &  \\hspace{1cm}  Set  $x_0 = x_1$, $x_1 = x_2$,\\\\\n    &   \\hspace{1cm}   $f_1 = f_2$,\\\\\n    &   \\hspace{1cm}   $x_2 = x_3 - r_i \\, \\Delta x$, and\\\\\n    &    \\hspace{1cm}  $f_2 = f(x_2)$.\\\\\n   & else\\\\\n   &    \\hspace{1cm} Set $x_3 = x_2$, $x_2 = x_1$,\\\\\n   &    \\hspace{1cm}  $f_2 = f_1$,\\\\\n   &    \\hspace{1cm}  $x_1 = x_0 + r_i \\,  \\Delta x$,\\\\\n   &    \\hspace{1cm}  $f_1 = f(x_1)$.\\\\\n   \\textbf{Step 2:} & Stop or go to Step 1.\\\\\n   \\hline \\\\\n\\end{tabularx}\n}\n\\lab{al:ModOneDim}\n\\end{algorithm}\n\\end{minipage}\n% ---------------------\n\n\\subsection{Keywords}\nFor the Golden Section and the Fibonacci Division algorithm, the command file (see page~\\pageref{par:comFil}) must contain only one continuous parameter.\\\\\n\nTo invoke the Golden Section or the Fibonacci Division algorithm, the \\texttt{Algorithm} Section of the GenOpt command file must have following form:\n\\begin{lstlisting}\nAlgorithm{\n   Main              = GoldenSection | Fibonacci;\n  [AbsDiffFunction   = Double;  |   // 0 < AbsDiffFunction\n   IntervalReduction = Double;  ]   // 0 < IntervalReduction\n}\n\\end{lstlisting}\n\\pagebreak[2]\n\\noindent The keywords have the following meaning\n\\begin{codedescription}\n\\item[Main]\nThe name of the main algorithm.\n\\end{codedescription}\nThe following two keywords are optional. If none of them is specified, then the algorithm stops after \\texttt{MaxIte} function evaluations (i.e., after \\texttt{MaxIte}$-2$ iterations), where \\texttt{MaxIte} is specified in the section \\texttt{OptimizationSettings}. If both of them are specified, an error occurs.\n\\begin{codedescription}\n\\item[AbsDiffFunction]\nThe absolute difference defined as\n\\begin{equation}\n\\Delta f \\triangleq | \\min \\{ f(x_0),\\, f(x_3) \\} - \\min \\{ f(x_1), \\, f(x_2) \\}|.\n\\end{equation}\nIf $\\Delta f$ is lower than \\texttt{AbsDiffFunction}, the search stops successfully.\\\\\n\\underline{Note:} Since the maximum number of interval reductions must be known for the initialization of the Fibonacci algorithm, this keyword can be used only for the Golden Section algorithm. It must not be specified for the Fibonacci algorithm.\n\\item[IntervalReduction]\nThe required maximum fraction, $r$, of the end interval length relative to the initial interval length (see equation~\\eqref{eq:golSecDefR}).\n\\end{codedescription}\n", "meta": {"hexsha": "1faed87db9d3890f091feb48b3c062883bb451ac", "size": 12076, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/manual/algOneDim.tex", "max_stars_repo_name": "bergsee/GenOpt", "max_stars_repo_head_hexsha": "3925277af881cea6e12e3d1bf0285bd657bbcced", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2015-08-30T09:47:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-06T15:16:18.000Z", "max_issues_repo_path": "src/manual/algOneDim.tex", "max_issues_repo_name": "bergsee/GenOpt", "max_issues_repo_head_hexsha": "3925277af881cea6e12e3d1bf0285bd657bbcced", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2016-01-14T00:01:46.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-21T15:28:52.000Z", "max_forks_repo_path": "src/manual/algOneDim.tex", "max_forks_repo_name": "lbl-srg/GenOpt", "max_forks_repo_head_hexsha": "3925277af881cea6e12e3d1bf0285bd657bbcced", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2015-08-30T09:47:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-01T18:07:07.000Z", "avg_line_length": 42.3719298246, "max_line_length": 944, "alphanum_fraction": 0.6128684995, "num_tokens": 4621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711908591638, "lm_q2_score": 0.8633915976709976, "lm_q1q2_score": 0.7338579844502139}}
{"text": "\n\\documentclass[11pt,letterpaper]{article}\n\\usepackage[hmargin=0.7in,vmargin=1in,landscape]{geometry}\n\\usepackage[T1]{fontenc}\n\\usepackage{url}\n\\usepackage{tabularx,array,varwidth}\n\n\\setlength{\\parindent}{0pt}\n\n\\begin{document}\n{\\LARGE Big-O Cheat Sheet} \\\\\nGenerated \\today. \\\\\nBrandon Amos <\\url{http://bamos.github.io}>\n\n\\newcolumntype{M}{>{\\begin{varwidth}{4.5cm}}l<{\\end{varwidth}}}\n\\section{Searching}\n\\begin{tabularx}{\\textwidth}{ MXXXXX }\nAlgorithm&Data Structure&\\multicolumn{2}{l}{Time Complexity}&Space Complexity\\\\\n\\hline\n&&Average&\\multicolumn{2}{l}{Worst}\\\\\n\\hline\nDepth First Search (DFS) & Graph of $|V|$ vertices and $|E|$ edges & - & $O\\left(|E| + |V|\\right)$ & $O\\left(|V|\\right)$\\\\\nBreadth First Search (BFS) & Graph of $|V|$ vertices and $|E|$ edges & - & $O\\left(|E| + |V|\\right)$ & $O\\left(|V|\\right)$\\\\\nBinary search & Sorted array of n elements & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(1\\right)$\\\\\nLinear (Brute Force) & Array & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(1\\right)$\\\\\nShortest path by Dijkstra, using a Min-heap as priority queue & Graph with $|V|$ vertices and $|E|$ edges & $O\\left((|V| + |E|) \\log |V|\\right)$ & $O\\left((|V| + |E|) \\log |V|\\right)$ & $O\\left(|V|\\right)$\\\\\nShortest path by Dijkstra, using an unsorted array as priority queue & Graph with $|V|$ vertices and $|E|$ edges & $O\\left(|V|^2\\right)$ & $O\\left(|V|^2\\right)$ & $O\\left(|V|\\right)$\\\\\nShortest path by Bellman-Ford & Graph with $|V|$ vertices and $|E|$ edges & $O\\left(|V||E|\\right)$ & $O\\left(|V||E|\\right)$ & $O\\left(|V|\\right)$\\\\\n\n\\end{tabularx}\n\\section{Sorting}\n\\begin{tabularx}{\\textwidth}{ MXXXXXX }\nAlgorithm&Data Structure&\\multicolumn{3}{l}{Time Complexity}&Worst Case Auxiliary Space Complexity\\\\\n\\hline\n&&Best&Average&\\multicolumn{2}{l}{Worst}\\\\\n\\hline\nQuicksort & Array & $O\\left(n \\log(n)\\right)$ & $O\\left(n \\log(n)\\right)$ & $O\\left(n^2\\right)$ & $O\\left(n\\right)$\\\\\nMergesort & Array & $O\\left(n \\log(n)\\right)$ & $O\\left(n \\log(n)\\right)$ & $O\\left(n \\log(n)\\right)$ & $O\\left(n\\right)$\\\\\nHeapsort & Array & $O\\left(n \\log(n)\\right)$ & $O\\left(n \\log(n)\\right)$ & $O\\left(n \\log(n)\\right)$ & $O\\left(1\\right)$\\\\\nBubble Sort & Array & $O\\left(n\\right)$ & $O\\left(n^2\\right)$ & $O\\left(n^2\\right)$ & $O\\left(1\\right)$\\\\\nInsertion Sort & Array & $O\\left(n\\right)$ & $O\\left(n^2\\right)$ & $O\\left(n^2\\right)$ & $O\\left(1\\right)$\\\\\nSelect Sort & Array & $O\\left(n^2\\right)$ & $O\\left(n^2\\right)$ & $O\\left(n^2\\right)$ & $O\\left(1\\right)$\\\\\nBucket Sort & Array & $O\\left(n+k\\right)$ & $O\\left(n+k\\right)$ & $O\\left(n^2\\right)$ & $O\\left(nk\\right)$\\\\\nRadix Sort & Array & $O\\left(nk\\right)$ & $O\\left(nk\\right)$ & $O\\left(nk\\right)$ & $O\\left(n+k\\right)$\\\\\n\n\\end{tabularx}\n\\section{Data Structures}\n\\begin{tabularx}{\\textwidth}{ MXXXXXXXXXX }\nData Structure&\\multicolumn{8}{l}{Time Complexity}&Space Complexity\\\\\n\\hline\n&\\multicolumn{4}{l}{Average}&\\multicolumn{5}{l}{Worst}\\\\\n\\hline\n&Indexing&Search&Insertion&Deletion&Indexing&Search&Insertion&Deletion&\\\\\n\\hline\nBasic Array & $O\\left(1\\right)$ & $O\\left(n\\right)$ & - & - & $O\\left(1\\right)$ & $O\\left(n\\right)$ & - & - & $O\\left(n\\right)$\\\\\nDynamic Array & $O\\left(1\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(1\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$\\\\\nSingly-Linked List & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(1\\right)$ & $O\\left(1\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(1\\right)$ & $O\\left(1\\right)$ & $O\\left(n\\right)$\\\\\nDoubly-Linked List & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(1\\right)$ & $O\\left(1\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(1\\right)$ & $O\\left(1\\right)$ & $O\\left(n\\right)$\\\\\nSkip List & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(n \\log(n)\\right)$\\\\\nHash Table & - & $O\\left(1\\right)$ & $O\\left(1\\right)$ & $O\\left(1\\right)$ & - & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$\\\\\nBinary Search Tree & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$\\\\\nCartresian Tree & - & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & - & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$ & $O\\left(n\\right)$\\\\\nB-Tree & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(n\\right)$\\\\\nRed-Black Tree & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(n\\right)$\\\\\nSplay Tree & - & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & - & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(n\\right)$\\\\\nAVL Tree & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(\\log(n)\\right)$ & $O\\left(n\\right)$\\\\\n\n\\end{tabularx}\n\n\\end{document}\n", "meta": {"hexsha": "4946747a38992d5b775f7861bb5012cd9252bdc1", "size": 5491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "data/2013-12-10/data.tex", "max_stars_repo_name": "dineshresearch/amaradineshkumar.github.io", "max_stars_repo_head_hexsha": "33f9506fdc3f58ee87524c3630c2d40157f685f2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2015-10-14T15:03:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-11T14:27:28.000Z", "max_issues_repo_path": "data/2013-12-10/data.tex", "max_issues_repo_name": "dineshresearch/amaradineshkumar.github.io", "max_issues_repo_head_hexsha": "33f9506fdc3f58ee87524c3630c2d40157f685f2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2015-02-01T17:02:17.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T15:35:31.000Z", "max_forks_repo_path": "data/2013-12-10/data.tex", "max_forks_repo_name": "dineshresearch/amaradineshkumar.github.io", "max_forks_repo_head_hexsha": "33f9506fdc3f58ee87524c3630c2d40157f685f2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 80, "max_forks_repo_forks_event_min_datetime": "2016-01-20T08:23:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-01T06:05:53.000Z", "avg_line_length": 77.338028169, "max_line_length": 244, "alphanum_fraction": 0.6024403569, "num_tokens": 2243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.7336821339193338}}
{"text": "% !TEX root = Main.tex\n\\section{Optimization}\nTo show that an objective is not convex, compute Hessian and show that it's not p.s.d. (det(H) < 0).\n\n\\subsection*{Alternating Least Squares}\nOptimising L(U,V) is not convex, but keeping one of them fixed and optimising the other is.\n$f(U,v_j)=\\sum_{(i,j)\\in I} (a_{i,j} - \\langle u_i, v_j \\rangle)^2 + \\lambda \\sum_i \\lVert\\mathbf{u_i}\\rVert^2 +(...)$\\\\\n$f(u_i,V)=\\sum_{(i,j)\\in I} (a_{i,j} - \\langle u_i, v_j \\rangle)^2 + (...) + \\lambda \\sum_j \\lVert\\mathbf{v_j}\\rVert^2$\\\\\n$u_i = (\\sum_{i,j \\in \\mathcal{I}} v_jv_j^T + \\lambda I_k)^{-1} \\sum_{i,j \\in \\mathcal{I}} a_{ij}v_j$\nDerived by setting up Lagrangian and setting its partial derivative w.r.t $u_i$ to 0.\n\n\\subsection*{Gradient Descent (or Deepest Descent)}\n\\textbf{Gradient}: $\\nabla f(\\mathbf{x}) := \\left( \\frac{\\partial f(\\mathbf{x})}{\\partial \\mathbf{x}_1}, \\ldots, \\frac{\\partial f(\\mathbf{x})}{\\partial \\mathbf{x}_D} \\right)^\\top$\n\n\\begin{inparaenum}[\\color{red}1.]\n\t\\item init: $\\mathbf{x}^{(0)} \\in \\mathbb{R}^D$\n\t\\item for $t = 0 \\ \\text{to} \\ \\mathit{maxIter}$:\n\t\\item $\\mathbf{x}^{(t+1)} = \\mathbf{x}^{(t)} - \\gamma \\nabla f(\\mathbf{x}^{(t)})$, usually $\\gamma \\approx \\frac{1}{t}$\n\\end{inparaenum}\n\n\\subsection*{Stochastic Gradient Descent (SGD)}\nAssume \\textbf{Additive Objective}: $f(x) = \\frac{1}{N}\\sum_{n=1}^{N}f_n(x)$\\\\\n\n\\begin{inparaenum}[\\color{red}1.]\n\t\\item init: $\\mathbf{x}^{(0)} \\in \\mathbb{R}^D$\n\t\\item for $t = 0 \\ \\text{to} \\ \\mathit{maxIter}$:\n\t\\item sample $n \\in_{u.a.r.} \\{1, \\ldots, N\\}$\n\t\\item $\\mathbf{x}^{(t+1)} = \\mathbf{x}^{(t)} - \\gamma \\nabla f_n(\\mathbf{x}^{(t)})$, typically  $\\gamma \\approx \\frac{1}{t}$.\n\\end{inparaenum}\n\n\\subsection*{Projected Gradient Descent (Constrained Opt.)}\nminimize $f(x)$, $x \\in Q$ (constraint).\\\\\n\\textbf{Project} $x$ onto $Q$: $P_Q(\\mathbf{x}) = \\argmin_{y \\in Q} \\|\\mathbf{y} - \\mathbf{x}\\|$,\\\\\n\\textbf{Update}: $\\mathbf{x}^{(t+1)} = P_Q[\\mathbf{x}^{(t)} - \\gamma \\nabla f(\\mathbf{x}^{(t)})]$,\\\\\n$\\mathbf{x}^{(t+1)}$ is unique if $Q$ convex.\n\n\\subsection*{Lagrangian Multipliers}\nMinimize  $f(\\mathbf{x})$ s.t. $g_i(\\mathbf{x}) \\leq 0,\\ i = 1, .., m$ (\\textbf{inequality constr.}) and $h_i(\\mathbf{x}) = \\mathbf{a}_i^\\top \\mathbf{x} - b_i = 0,\\ i = 1, .., p$ (\\textbf{equality constraint}). \n\\textbf{Lagrangian:} $L(\\mathbf{x}, \\boldsymbol{\\lambda}, \\boldsymbol{\\nu}) := f(\\mathbf{x}) + \\sum_{i=1}^m \\lambda_i g_i(\\mathbf{x}) + \\sum_{i=1}^p \\nu_i h_i(\\mathbf{x})$\\\\\n\n\\subsection*{Convex Optimization}\nDef.: $\\{(x,t)|x \\in dom f, f(x) \\leq t\\}$, $f : \\mathbb{R}^D \\rightarrow \\mathbb{R}$ is convex, if $dom\\ f$ is a convex set, and if $\\forall \\mathbf{x}, \\mathbf{y} \\in dom\\ f$, and for $0 \\leq \\alpha \\leq 1$: $f(\\alpha \\mathbf{x} + (1 - \\alpha)\\mathbf{y}) \\leq \\alpha f(\\mathbf{x}) + (1-\\alpha)f(\\mathbf{y})$. local=global min, \\textbf{Convergence}: $f(\\mathbf{x}^{(t)}) - f(\\mathbf{x}^*) \\le \\frac{c}{t}$.\n\\textbf{Subgradient} $g \\in \\mathbb{R}^D$ of $f$ at $\\mathbf{x}$: $f(\\mathbf{y}) \\geq f(\\mathbf{x}) + g^\\top(\\mathbf{y}-\\mathbf{x}) \\ \\forall \\mathbf{y}$\n\n\\subsection*{Convex Relaxation}\nReplace non-convex rank constraints by convex norm constraints.\n$rank(B) \\geq ||B||_*$. Repeat: $B^* = shrink_\\tau(A) = arg min_B(\\frac{1}{2}||A - B||_F^2 + \\tau ||B||_*)$, with $B^*=UD_\\tau V^T, D_\\tau = diag(max(0,\\sigma_i - \\tau))$. Then $B_{t+1} = B_t + \\eta_t \\Pi(A - shrink_\\tau(B_t))$, where $\\Pi$ cuts off $x < 0$. Exact reconstruction of rank k matrix $A^*$ w.h.p, if it is strongly incoherent, if $\\mathcal{I} \\in O(n)$, spread of $\\sigma_i$ large enough. \n", "meta": {"hexsha": "0f9c827420865f123298f7d3055fc04ef6a89ffc", "size": 3544, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Optimization.tex", "max_stars_repo_name": "phil9987/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "6c4986f399ca40c2270b8fc01150a69f89650db7", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Optimization.tex", "max_issues_repo_name": "phil9987/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "6c4986f399ca40c2270b8fc01150a69f89650db7", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Optimization.tex", "max_forks_repo_name": "phil9987/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "6c4986f399ca40c2270b8fc01150a69f89650db7", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.8333333333, "max_line_length": 407, "alphanum_fraction": 0.6137133183, "num_tokens": 1462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.733682132445867}}
{"text": "\n\\subsection{Average Treatment Effects (ATE, ATET, ATEUT)}\n\n\\subsubsection{Average Treatment Effect (ATE)}\n\n\\(ATE=E[y_{i1}-y_{i0}]\\)\n\n\\subsubsection{Average Treatment Effect on the Treated (ATET)}\n\n\\(ATE=E[y_{i1}-y_{i0}|D_i=1]\\)\n\n\\(ATE=E[y_{i1}|D_i=1]-E[y_{i0}|D_i=1]\\)\n\n\\subsubsection{Average Treatment Effect on the Untreated (ATEUT)}\n\n\n", "meta": {"hexsha": "a660f1446ef98636b417a37a79e9bd892f18e8eb", "size": 339, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/treatmentHomo/01-02-treatment.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/treatmentHomo/01-02-treatment.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/treatmentHomo/01-02-treatment.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.9411764706, "max_line_length": 65, "alphanum_fraction": 0.6991150442, "num_tokens": 117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9539660949832345, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.7336764755362639}}
{"text": "\\lab{The Drazin Inverse}{The Drazin Inverse}\n\\label{lab:drazin_inverse}\n% TODO: include more on the Moore-Penrose pseudoinverse and rename the lab \"Pseudoinverses\"?\n\n\\objective{The Drazin inverse of a matrix is a pseudoinverse which preserves certain spectral properties of the matrix.\nIn this lab, we compute the Drazin inverse using the Schur decomposition, then use it to compute the effective resistance of a graph and perform link prediction.}\n\n% TODO: compute Ind(A), effective resistance explanation, algorithm for computing drazin\n\n\\section*{Definition of the Drazin Inverse} % =================================\n\nThe \\emph{index} of an $n \\times n$ matrix $A$ is the smallest nonnegative integer $k$ for which $\\mathscr{N}(A^k) = \\mathscr{N}(A^{k+1})$.\nThe \\emph{Drazin inverse} $A^D$ of $A$ is the unique $n \\times n$ matrix satisfying the following properties.\n\\begin{itemize}\n\\item $ AA^{D} =  A^{D}A$\n\\item $A^{k+1}A^D = A^k$\n\\item $A^DAA^D = A^D$\n\\end{itemize}\nNote that if $A$ is \\emph{invertible}, in which case $k=0$, then $A^D = A^{-1}$.\nOn the other hand, if $A$ is \\emph{nilpotent}, meaning $A^j = \\0$ for some nonnegative integer $j$, then $A^D$ is the zero matrix.\n\n\\begin{problem} % Check for the Drazin inverse.\nWrite a function that accepts an $n \\times n$ matrix $A$, the index $k$ of $A$, and an $n \\times n$ matrix $A^D$.\nUse the criteria described above to determine whether or not $A^D$ is the Drazin inverse of $A$.\nReturn \\li{True} if $A^D$ satisfies all three conditions; otherwise, return \\li{False}.\n\nUse the following matrices as test cases for your function.\n\\[\nA = \\left[\\begin{array}{cccc}\n1 & 3 & 0 & 0 \\\\\n0 & 1 & 3 & 0 \\\\\n0 & 0 & 1 & 3 \\\\\n0 & 0 & 0 & 0\n\\end{array}\\right],\n\\quad\nA^D = \\left[\\begin{array}{cccc}\n1 & -3 & 9 & 81 \\\\\n0 & 1 & -3 & -18 \\\\\n0 & 0 & 1 & 3 \\\\\n0 & 0 & 0 & 0\n\\end{array}\\right],\n\\quad\nk = 1\n\\]\n%\n\\[\nB = \\left[\\begin{array}{ccc}\n 1 &  1 &  3 \\\\\n 5 &  2 &  6 \\\\\n-2 & -1 & -3\n\\end{array}\\right],\n\\quad B^D = \\left[\\begin{array}{ccc}\n0 & 0 & 0 \\\\\n0 & 0 & 0 \\\\\n0 & 0 & 0\n\\end{array}\\right],\n\\quad\nk = 3\n\\]\n(Hint: \\li{np.allclose()} and \\li{np.linalg.matrix_power()} may be useful).\n\\label{prob:test-drazin}\n\\end{problem}\n\n\\subsection*{Computing the Drazin Inverse} % ----------------------------------\n\nThe Drazin inverse is often defined theoretically in terms of the eigenprojections of a matrix.\nHowever, eigenprojections are often costly or unstable to calculate, so we resort to a different method to calculate the Drazin inverse.\n\nTo begin, suppose that the $n \\times n$ matrix $A$ can be written in the form\n\\begin{equation}\nA = S^{-1}\n\\left[\\begin{array}{cc}\nM & \\0 \\\\\n\\0 & N \\\\\n\\end{array}\\right] S,\n\\label{eq:nilpotent-sort-decomposition}\n\\end{equation}\nwhere $S$ is a change of basis matrix, $N$ is nilpotent, and $M$ is the restriction of $A$ onto the range of $I - P_0$, where $P_0$ is the 0-eigenprojection in the spectral decomposition.\nThen the Drazin inverse can be calculated as\n\\begin{equation}\nA^D = S^{-1}\n\\left[\\begin{array}{cc}\nM^{-1} & \\0 \\\\\n\\0 & \\0 \\\\\n\\end{array}\\right] S.\n\\label{eq:nilpotent-sort-compute-drazin}\n\\end{equation}\n\nNext, the \\emph{Schur decomposition} of $A$ is given by\n\\begin{align}\nA = QTQ^{-1},\n\\end{align}\nwhere $Q$ is orthonormal and $T$ is upper triangular.\nSince $T$ is similar to $A$, the eigenvalues of $A$ are listed along the diagonal of $T$.\nThen if $A$ is singular, at least one diagonal entry of $T$ must be $0$.\nThe columns that contain the $0$ eigenvalues of $A$ form the nilpotent matrix $N$ in (\\ref{eq:nilpotent-sort-decomposition}).\nTo compute $M$ and $N$, we sort the Schur decomposition so that the $0$ eigenvalues are listed last along the diagonal of $T$, and then we can use (\\ref{eq:nilpotent-sort-compute-drazin}) to compute $A^D$.\n\nSciPy's \\li{la.schur()} is a routine for computing the Schur decomposition of a matrix, but it does not automatically sort it by eigenvalue.\nHowever, sorting can be accomplished by specifying the \\li{sort} keyword argument.\n\n\\begin{lstlisting}\n>>> from scipy import linalg as la\n\n# The standard Schur decomposition.\n>>> A = np.array([[0,0,2],[-3,2,6],[0,0,1]])\n>>> T,Z = la.schur(A)\n>>> T                       # The eigenvalues (2, 0, and 1) are not sorted.\narray([[ 2., -3.,  6.],\n       [ 0.,  0.,  2.],\n       [ 0.,  0.,  1.]])\n\n# Specify a sorting function to get the desired result.\n>>> f = lambda x: abs(x) > 0\n>>> T1,Z1,k = la.schur(A, sort=f)\n>>> T1\narray([[ 2.        ,  0.        ,  6.70820393],\n       [ 0.        ,  1.        ,  2.        ],\n       [ 0.        ,  0.        ,  0.        ]])\n>>> k                       # k is the number of columns satisfying the sort,\n2                           # which is the number of nonzero eigenvalues.\n\\end{lstlisting}\n\nThe procedure for finding the Drazin inverse using the Schur decomposition and (\\ref{eq:nilpotent-sort-decomposition}) is given in Algorithm \\ref{Alg:Drazin-Inverse}.\nDue to possible floating point arithmetic errors, consider all eigenvalues smaller than a certain tolerance to be $0$.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{Drazin}{$A$, tol}\n    \\State $(n,n) \\gets \\shape{A}$\n    \\State $Q_1,S,k_1 \\gets $ \\text{schur($A, |x| > $ tol)}\n\t   \\Comment{Sort the Schur decomposition.}\n    \\State $Q_2,T,k_2 \\gets $ \\text{schur($A, |x| \\leq $ tol)}\n    \\State $U \\gets [S_{:,:k_1}\\ |\\ T_{:,:n - k_1}]$\n        \\Comment{Concatenate part of $S$ and $T$ column-wise.}\n    \\State $U^{-1} \\gets \\text{inverse(U)}$\n    \\State $V \\gets U^{-1}AU$\n    \\State $Z \\gets \\0_{n\\times n}$\n        \\Comment{The $n\\times n$ zero matrix \\textbf{as floats}, not ints.}\n    \\If {$k_1 \\neq 0$}\n        \\State $M^{-1} \\gets $ \\text{inverse($V_{:k_1,:k_1}$)}\n        \\State $Z_{:k_1,:k_1} \\gets M^{-1}$\n    \\EndIf\n    \\State \\pseudoli{return} $UZU^{-1}$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\label{Alg:Drazin-Inverse}\n\\end{algorithm}\n\n\\begin{problem} % Compute the Drazin Inverse.\nWrite a function that accepts an $n \\times n$ matrix $A$ and a tolerance for rounding eigenvalues to zero.\nUse Algorithm \\ref{Alg:Drazin-Inverse} to compute the Drazin inverse $A^D$.\nUse your function from Problem \\ref{prob:test-drazin} to verify your implementation.\n\\end{problem}\n\n\\begin{warn} % ill-conditioning warning.\nBecause the algorithm for the Drazin inverse requires calculation of the inverse of a matrix, it is unstable when that matrix has a high condition number.\nIf the algorithm does not find the correct Drazin inverse, check the condition number of $V$ from Algorithm \\ref{Alg:Drazin-Inverse}\n%For the matrix where it breaks, the conditions number is 32960398578565896.0000\n\\end{warn}\n\n\\begin{info}\nThe Drazin inverse is called a \\emph{pseudoinverse} because $A^D = A^{-1}$ for invertible $A$, and for noninvertible $A$, $A^D$ always exists and acts similarly to an inverse.\nThere are other matrix pseudoinverses that preserve different qualities of $A$, including the \\emph{Moore-Penrose pseudoinverse} $A^\\dagger$, which can be thought of as the least squares approximation to $A^{-1}$.\n\\end{info}\n\n\\section*{Applications of the Drazin Inverse} % ===============================\n\n\\subsection*{Effective Resistance} % ------------------------------------------\n\nThe \\emph{effective resistance} between two nodes in a undirected graph is a measure of how connected those nodes are.\nThe concept originates from the study of circuits to measure the resistance between two points on the circuit.\nA \\emph{resistor} is a device in a circuit which limits or regulates the flow of electricity.\nTwo points that have more resistors between them have more resistance, while those with fewer resistors between them have less resistance.\nThe entire circuit can be represented by a graph where the nodes are the points of interest and the number of edges connecting two nodes indicates the number of resistors between the corresponding points.\nSee Figure \\ref{fig:resistors} for an example.\n% To apply this concept to a graph, imagine that each edge of the graph is replaced by a resistor with a resistance of 1 unit (See Figure \\ref{fig:resistors})\n\n\\begin{center}\n\\begin{figure}[H]\n\\begin{tikzpicture}[circuit ee IEC,set resistor graphic=var resistor IEC graphic,scale=.75]\n%Set the coordinates and labels\n\\foreach \\x/\\y/\\z/\\t in {-3.5/2/.5/a,0/2/.5/c,3.5/2/.5/e,\n\t\t\t\t\t\t -3.5/-2/-.5/b,0/-2/-.5/d,3.5/-2/-.5/f}{\n\t\\coordinate (\\t) at (\\x,\\y);\n\t\\filldraw (\\t) circle (2pt) node[text depth=.25ex,text height=1.5ex,font=\\Large] at (\\x,\\y+\\z) {$\\t$};}\n%Draw the lines with resistors\n\\foreach \\p/\\q in {a/c,a/d,b/d,c/d,c/f,d/f,e/f} \\draw[every resistor/.style={circuit symbol size=width 4.5 height 0.75}] (\\p) to [resistor] (\\q);\n\\end{tikzpicture}\n\\caption{A graph with a resistor on each edge.}\n\\label{fig:resistors}\n\\end{figure}\n\\end{center}\n\nIn electromagnetism, there are rules for manually calculating the effective resistance between two nodes for relatively simple graphs.\nHowever, this is infeasible for large or complicated graphs.\nInstead, we can use the Drazin inverse to calculate effective resistance for any graph.\n\nFirst, create the \\emph{adjacency matrix}\\footnote{See Problem 1 of Image Segmentation for a refresher on adjacency matrices and the Laplacian.} of the graph, the matrix where the $(ij)$th entry is the number of connections from node $i$ to node $j$.\nNext, calculate the Laplacian $L$ of the adjacency matrix.\n% TODO: must at least briefly state what the Laplacian is.\nThen if $R_{ij}$ be the effective resistance from node $i$ to node $j$,\n\\begin{equation}\nR_{ij} = \\begin{cases}\n(\\widetilde{L}^j)^D_{ii} & \\mbox{if $i \\neq j$} \\\\\n0 & \\mbox{if $i = j$,}\n\\end{cases}\n\\label{eq:effective-resistance-with-Drazin}\n\\end{equation}\nwhere $\\widetilde{L}^j$ is the Laplacian with the $j$th row of the Laplacian replaced by the $j$th row of the identity matrix, and $(\\widetilde{L}^j)^D$ is its Drazin inverse.\n\n\\begin{problem} % Compute effective resistance.\nWrite a function that accepts the $n \\times n$ adjacency matrix of an undirected graph.\nUse (\\ref{eq:effective-resistance-with-Drazin}) to compute the effective resistance from each node to every other node.\nReturn an $n \\times n$ matrix where the $(ij)$th entry is the effective resistance from node $i$ to node $j$.\nKeep the following in mind: % TODO: Rephrase this somehow...\n\\begin{itemize}\n\\item The resulting matrix should be symmetric.\n\\item The effective resistance from a node to itself is $0$.\n\\item Consider creating the matrix column by column instead of entry by entry. Every time you compute the Drazin inverse, the whole diagonal of the matrix can be used.\n\\end{itemize}\nTest your function using the graphs and values from Figure \\ref{fig:eff-res}.\n% Write each graph as an adjacency matrix, run the function and verify that the effective resistance from $a$ to $b$ is as given in the Figure.\n\\label{prob:effective-resistance}\n\\end{problem}\n\n%%%%%% IMAGE %%%%%%%%\n\\begin{center}\n\\begin{figure}[H]\n\\begin{tikzpicture}\n\n%%%3 Line segments\n\\begin{scope}\n%Points, labels a and b\n\\foreach \\x/\\t in {-1.5/a,-.5/,.5/,1.5/b} \\filldraw (\\x,0) circle (2pt) node[anchor=north,yshift=-.25cm,text depth=.25ex,text height=1.5ex] {$\\t$};\n%Line and label R\n\\draw[thick] (-1.5,0) -- (1.5,0);\n\\node[draw=none] at (3,0) {$R_{ab}=3$};\n\\end{scope}\n\n%%%Single line segment\n\\begin{scope}[xshift=6.5cm]\n%Points, labels a and b\n\\foreach \\x/\\t in {-.5/a,.5/b} \\filldraw (\\x,0) circle (2pt) node[anchor=north,yshift=-.25cm,text depth=.25ex,text height=1.5ex] {$\\t$};\n%Line and laebl R\n\\draw[thick] (-.5,0) -- (.5,0);\n\\node[draw=none] at (2.5,0) {$R_{ab}=1$};\n\\end{scope}\n\n%%%Triangle\n\\begin{scope}[yshift=-2.5cm]\n%Points, labels a and b\n\\foreach \\x/\\y/\\t in {-.5/0/a,0/.75/,.5/0/b} \\filldraw (\\x,\\y) circle (2pt) node[anchor=north,yshift=-.25cm,text depth=.25ex,text height=1.5ex] {$\\t$};\n%Triangle and label R\n\\draw[thick] (-.5,0) -- (0,.75) -- (.5,0) -- cycle;\n\\node[draw=none] at (3,0) {$R_{ab}=\\frac{2}{3}$};\n\\end{scope}\n\n%%%Line segment and circle\n\\begin{scope}[xshift=6.5cm,yshift=-2.5cm]\n%Points, labels a and b\n\\foreach \\x/\\t/\\p/\\y in {-.5/a/left/-.4,.5/b/right/.4} \\filldraw (\\x,0) circle (2pt) node[text depth=.25ex,text height=1.5ex] at (\\x+\\y,0) {$\\t$};\n%Line, circle, and laebl R\n\\draw[thick] (-.5,0) -- (.5,0);\n\\draw[thick] (0,0) circle (.5cm);\n\\node[draw=none] at (2.5,0) {$R_{ab}=\\frac{1}{3}$};\n\\end{scope}\n\n%%%Circle\n\\begin{scope}[yshift=-5cm]\n%Points, labels a and b\n\\foreach \\x/\\t/\\p/\\y in {-.5/a/left/-.4,.5/b/right/.4} \\filldraw (\\x,0) circle (2pt) node[text depth=.25ex,text height=1.5ex] at (\\x+\\y,0) {$\\t$};\n%Circle and label R\n\\draw[thick] (0,0) circle (.5cm);\n\\node[draw=none] at (3,0) {$R_{ab}=\\frac{1}{2}$};\n\\end{scope}\n\n%%%Cross circle\n\\begin{scope}[xshift=6.5cm,yshift=-5cm]\n%Points, labels a and b\n\\foreach \\x/\\t/\\p/\\y in {-.5/a/left/-.4,.5/b/right/.4} \\filldraw (\\x,0) circle (2pt) node[text depth=.25ex,text height=1.5ex] at (\\x+\\y,0) {$\\t$};\n%Circle, cross elipse, and label R\n\\draw[thick] (0,0) circle (.5cm);\n\\draw[thick] (0,0) ellipse (.5cm and .1cm);\n\\node[draw=none] at (2.5,0) {$R_{ab}=\\frac{1}{4}$};\n\\end{scope}\n\n\\end{tikzpicture}\n\\caption{The effective resistance between two points for several simple graphs.\nNodes that are farther apart have a larger effective resistance, while nodes that are nearer or better connected have a smaller effective resistance.}\n\\label{fig:eff-res}\n\\end{figure}\n\\end{center}\n%%%%%% END IMAGE %%%%%%%%\n\n\\subsection*{Link Prediction} % -----------------------------------------------\n\n\\emph{Link prediction} is the problem of predicting the likelihood of a future association between two unconnected nodes in a graph.\nLink prediction has application in many fields, but the canonical example is friend suggestions on Facebook.\nThe Facebook network can be represented by a large graph where each user is a node, and two nodes have an edge connecting them if they are ``friends.''\nFacebook aims to predict who you would like to become friends with in the future, based on who you are friends with now, as well as discover which friends you may have in real life that you have not yet connected with online.\nTo do this, Facebook must have some way to measure how closely two users are connected.\n\nWe will compute link prediction using effective resistance as a metric.\nEffective resistance measures how closely two nodes are connected, and nodes that are closely connected at present are more likely to be connected in the future.\nGiven an undirected graph, the next link should connect the two unconnected nodes with the least effective resistance between them.\n\n\\begin{problem}\nWrite a class called \\li{LinkPredictor} for performing link prediction.\nImplement the \\li{\\_\\_init\\_\\_()} method so that it accepts the name of a \\li{csv} file containing information about a social network.\nEach row of the file should contain the names of two nodes which are connected by an (undirected) edge.\n\nStore each of the names of the nodes of the graph as an ordered list.\nNext, create the adjacency matrix for the network where the $i$th row and column of the matrix correspond to the $i$th member of the list of node names.\nFinally, use your function from Problem \\ref{prob:effective-resistance} to compute the effective resistance matrix.\nSave the list of names, the adjacency matrix, and the effective resistance matrix as attributes.\n\\end{problem}\n\n\\begin{problem}\nImplement the following methods in the \\li{LinkPredictor} class:\n\n\\begin{enumerate}\n\\item \\li{predict\\_link()}: Accept a parameter \\li{node} which is either \\li{None} or a string representing a node in the network. If \\li{node} is \\li{None}, return a tuple with the names of the nodes between which the next link should occur. However, if \\li{node} is a string, return the name of the node which should be connected to \\li{node} next out of all other nodes in the network. If \\li{node} is not in the network, raise a \\li{ValueError}. Take the following into consideration:\n\n\\begin{enumerate}\n\\item You want to find the two nodes which have the smallest effective resistance between them which are not yet connected.\nUse information from the adjacency matrix to zero out all entries of the effective resistance matrix that represent connected nodes. The ``\\li{*}\" operator multiplies arrays component-wise, which may be helpful.\n\n\\item Find the next link by finding the minimum value of the array that is nonzero.\nYour array may be the whole matrix or just a column if you are only considering links for a certain node.\nThis can be accomplished by passing \\li{np.<<min>>()} a masked version of your matrix to exclude entries that are $0$.\n\n\\item NumPy's \\li{np.where()} is useful for finding the minimum value in an array:\n\n\\begin{lstlisting}\n>>> A = np.random.randint(-9,9,(3,3))\n>>> A\narray([[ 6, -8, -9],\n       [-2,  1, -1],\n       [ 4,  0, -3]])\n\n# Find the minimum value in the array.\n>>> minval = np.<<min>>(A)\n>>> minval\n-9\n\n# Find the location of the minimum value.\n>>> loc = np.where(A==minval)\n>>> loc\n(array([0], dtype=int64), array([2], dtype=int64))\n\\end{lstlisting}\n\\end{enumerate}\n\n\n\\item \\li{add\\_link()}: Take as input two names of nodes, and add a link between them. If either name is not in the network, raise a \\li{ValueError}. Add the link by updating the adjacency matrix and the effective resistance matrix.\n\\end{enumerate}\n\nFigure \\ref{fig:social-network} visualizes the data in \\texttt{social\\_network.csv}.\nUse this graph to verify that your class is suggesting plausible new links.\nYou should observe the following:\n\\begin{itemize}\n\\item In the entire network, Emily and Oliver are most likely to become friends next.\n\\item Melanie is predicted to become friends with Carol next.\n\\item Alan is expected to become friends with Sonia, then with Piers, and then with Abigail.\n\\end{itemize}\n\\end{problem}\n\n\\begin{figure}[H]\n\\includegraphics[width=.7\\linewidth]{network.png}\n\n\\caption{The social network contained in \\texttt{social\\_network.csv}.\nAdapted from data by Wayne. W Zachary (see \\url{https://en.wikipedia.org/wiki/Zachary\\%27s\\_karate\\_club}).}\n\\label{fig:social-network}\n\n\\begin{multicols}{4}\n\\begin{enumerate}\n    \\item Piers\n    \\item Abigail\n    \\item Oliver\n    \\item Stephanie\n    \\item Carol\n    \\item Melanie\n    \\item Stephen\n    \\item Sally\n    \\item Penelope\n    \\item Alan\n    \\item Trevor\n    \\item Jake\n    \\item Mary\n    \\item Anna\n    \\item Ruth\n    \\item Evan\n    \\item Connor\n    \\item John\n    \\item Max\n    \\item Eric\n    \\item Theresa\n    \\item Paul\n    \\item Alexander\n    \\item Colin\n    \\item Jake\n    \\item Jane\n    \\item Brandon\n    \\item Thomas\n    \\item Christopher\n    \\item Charles\n    \\item Madeleine\n    \\item Tracey\n    \\item Sonia\n    \\item Emily\n\\end{enumerate}\n\\end{multicols}\n\\end{figure}\n", "meta": {"hexsha": "3bff29d01792b7a85543cd6c683445235ebaf3ea", "size": 18668, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume1/DrazinInverse/DrazinInverse.tex", "max_stars_repo_name": "DM561/dm561.github.io", "max_stars_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-13T13:22:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-13T13:22:41.000Z", "max_issues_repo_path": "acme-material/Labs/Volume1/DrazinInverse/DrazinInverse.tex", "max_issues_repo_name": "DM561/dm561.github.io", "max_issues_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-10-18T19:57:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-31T19:00:36.000Z", "max_forks_repo_path": "acme-material/Labs/Volume1/DrazinInverse/DrazinInverse.tex", "max_forks_repo_name": "DM561/dm561.github.io", "max_forks_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.9831325301, "max_line_length": 488, "alphanum_fraction": 0.6932183415, "num_tokens": 5638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.8947894731166139, "lm_q1q2_score": 0.7336319181782148}}
{"text": "\\subsection{Non-Uniform Rational B-Spline (NURBS)}\n\\label{lr_sec:NURBS}\n\\paragraph{}\nIn the proposed approach, the geometry and the unknown fields are represented by the NURBS.\nIn this section, a brief overview is given.\nFor more detailed description and implementation aspects, interested readers can refer to \\citep{Pie1997,NGUYEN201589}.\n\\paragraph{}\n% basis function\nNURBS are the superset of B-spline functions.\nB-spline is short for basis spline and is a generalization of Bézier curves.\nA spline function is a piecewise polynomial function of degree $p$ and the points of intersection of such functions are called knots.\nThe number of knots must be equal to or greater than $p + 1$.\nOne of the salient features of spline functions is that the functions are continuous at the knots, however, the continuity of the functions can be altered by repeating the knots.\nThe B-spline functions are parametric functions of the form $F(\\eta)$ in which the parameter $\\eta$ lies in the parametric space.\nThe key ingredients in the construction of B-spline functions are: the knot vector (a non decreasing sequence of parameter values, $\\eta_i \\leq \\eta_{i+1}$ , $i = 0,1,\\dots,m -1$) and the degree of the curve p. The $i$th B-spline basis function of degree $p$, denoted by $_{i,p}$ is defined as \\citep{Pie1997}:\n\\begin{equation}\n    \\begin{aligned}\n        N_{i,0}(\\eta) &=\n            \\begin{cases}\n                1   & \\eta \\in [\\eta_i, \\eta_{i+1}]   \\\\\n                0   & \\eta \\in (-\\infty, \\eta_i) \\cup (\\eta_{i+1}, \\infty )\n            \\end{cases}\\\\\n        N_{i,p}(\\eta) &= \n            \\frac{\\eta - \\eta_i}{\\eta_{i+p}-\\eta_i}     N_{i,p-1}(\\eta) - \n            \\frac{\\eta_{i+p+1}-\\eta}{\\eta_{i+p+1} - \\eta_{i+1}}     N_{i+1,p-1}(\\eta)\n    \\end{aligned}\n    \\label{lr_nurbs_basis}\n\\end{equation}\n%\nThe first derivative of the B-spline basis function can be computed recursively from lower order basis functions as:\n\\begin{equation}\n    \\frac{d}{d\\eta} N_{i,p}(\\eta) =\n        \\frac{p}{\\eta_{i+p} - \\eta_i} N_{i,p-1}(\\eta) -\n        \\frac{p}{\\eta_{i+p+1} - \\eta_{i+1}} N_{i+1,p-1}(\\eta)\n\\end{equation}\n%\nThe B-spline basis functions has the following properties:\n\\begin{enumerate}\n    \\item Non-negativity\n    \\item Partition of unity, $\\sum_i N_{i,p}=1$\n    \\item Interpolatory at the end points. The last point requires special treatment when imposing non-homogeneous Dirichlet boundary conditions \\citep{NGUYEN201589}.\n\\end{enumerate}\n\n\n\\paragraph{}\n% curves\nMoreover, the spline function has limited support.\nGiven $n + 1$ control points $(P_0 ,P_1,\\dots,P_n )$ and a knot vector \n    $\\Xi$ = $\\left\\{\n        \\eta_0 ,\\eta_1 ,\\dots,\\eta_m \n    \\right\\}$, the piecewise polynomial B-spline curve of degree p is defined as:\n\\begin{equation}\n    C(\\eta) = \\sum_{i=0}^n P_i N_{i,p} (\\eta)\n\\end{equation}\n%\nwhere $P_i$ are the control points.\nA B-spline curve has the following information: $n+1$ control points, $m+1$ knots and a degree $p$.\nIt is noted that $n$,$m$ and $p$ must satisfy $m = n + p + 1$.\nThe B-spline functions also provide a variety of refinement algorithms, which are essential when employing B-spline functions to discretize the unknown fields.\nThe analogous $h$ and $p$ refinement can be done by the process of `knot insertion' and `order elevation'.\nAnother unique feature of the B-spline basis function is that, it is possible to combine the knot insertion and the degree elevation, commonly referred to as ‘k-refinement’ in the literature \\citep{Hug2005b}.\nHere we briefly discuss the knot insertion and the degree elevation.\nFor more details, interested readers are referred to \\citep{Pie1997,Hug2005b} and references therein.\n\n\n\\subsubsection{Knot insertion}\n\\label{lr_sec:nurbs_knot_ins}\n\\paragraph{}\nConsider a B-spline basis functions defined on \n$\\Xi = \\left\\{\n    \\eta_0 ,\\eta_1,\\dots,\\eta_m \n    \\right\\}$,\nlet $\\overline{\\eta} \\in [\\eta_k ,\\eta_{k+1} )$, and insert $\\overline{\\eta}$ into $\\Xi$ to form a new knot vector \n$\\overline{\\Xi} = \\left\\{\n    \\eta_0 ,\\dots, \\overline{\\eta}_k = \\eta_k , \n    \\overline{\\eta}_{k+1} = \\overline{\\eta}, \n    \\overline{\\eta}_{k+2} = \\overline{\\eta}_{k+1} ,\n    \\dots,\\eta_{m+1} = \\eta_m\n    \\right\\}$.\nSimultaneously, the size of the control points is increased by one. Thus $C(\\eta)$ has a representation on $\\overline{\\Xi}$ of the form\n\\begin{equation}\n    \\mathbf{C}(\\eta) = \\sum_{i=0}^{n+1}\n                        \\overline{N}_{i,p} (\\eta)\n                        \\mathbf{Q}_i\n\\end{equation}\nWhere $\\mathbf{Q}_i$ is:\n\\begin{equation}\n    \\mathbf{Q}_i = \\alpha_i \\mathbf{P}_i +\n                    (1-\\alpha_i) \\mathbf{P}_{i-1}\n\\end{equation}\nwhere\n\\begin{equation}\n    \\alpha_i =  \\begin{cases}\n                    1       & i \\leq k-p \\\\\n                    \\frac{ \\overline{\\eta} -\\eta_i }{ \\eta_{i+p} - \\eta_i } & k-p \\leq i \\leq k \\\\\n                    0 & i \\geq k+1                          \n                \\end{cases}\n\\end{equation}\n\n\n\\subsubsection{Order elevation}\n\\label{lr_sec:nurbs_order_ele}\n\\paragraph{}\nLet $\n\\mathbf{C}(\\eta) =  \\sum_{i=0}^n\n                    N_{i,p}(\\eta)\n                    \\mathbf{P}_i\n$\nbe a $p$th-degree B-spline curve on the knot vector $\\Xi$.\nAs a piecewise polynomial curve with $p+1$ order, $\\mathbf{C}(\\eta)$ is expected to be expressed in higher order basis functions.\nIn other words, another set of control points $Q_i$ and knot vector $\\Xi$ should exists such that\n\\begin{equation}\n    \\mathbf{C}(\\eta) =  \\sum_{i=0}^{\\overline{n}}\n                        N_{i, p+1}(\\eta)\n                        \\mathbf{Q}_i\n\\end{equation}\nThe procedure to elevate the order of a B-spline is listed as follows \\citep{Pie1997}:\n\\begin{enumerate}\n    \\item Extract each Bézier segment from the curve\n    \\item Elevate the order of each Bézier segment\n    \\item Remove unnecessary knots separating the ($i-1$)th and $i$th segments\n\\end{enumerate}\nWhen elevating a $p$th Bézier curve, a new set of control points can be determined from:\n\\begin{equation}\n    \\mathbf{Q}_i =  (1-\\alpha_i) \\mathbf{P}_i +\n                    \\alpha_i \\mathbf{P}_{i-1}\n\\end{equation}\nwhere $\\alpha_i=\\frac{i}{p+i}$, $i=0$, $\\dots$, $p+1$.\nFig.~\\ref{lr_fig:nurbs_knotins} and Fig.~\\ref{lr_fig:nurbs_orderele} show an example of basis function when performing a knot insertion and order elevation, respectively.\n\n\\begin{figure}[h!]\n    \\centering\n    \\input{literature/images/lr_nurbs_knotins.tikz}\n    \\caption{B-spline functoins: knot insertion}\n    \\label{lr_fig:nurbs_knotins}\n\\end{figure}\n\n\\begin{figure}[h!]\n    \\centering\n    \\input{literature/images/lr_nurbs_orderele.tikz}\n    \\caption{B-spline functoins: order elevation}\n    \\label{lr_fig:nurbs_orderele}\n\\end{figure}\n\nBesides, it is found that if the order is elevated to $q$ and only then inserted a unique knot value, the basis would have $q-1$ continuous derivatives at the knot we inserted and this process is called $k$-refinement \\citep{Hug2005b}.\nDespite the flexibility offered by the B-splines, they lack the ability to exactly represent some shapes such as circle and ellipsoids.\nTo improve this, non-uniform rational B-splines (NURBS) are formed through rational functions of B-splines.\nThe NURBS thus form the superset of B-splines.\nThe key ingredients in the construction of NURBS basis functions are: the knot vector (a non decreasing sequence of parameter values, $\\eta_i \\leq \\eta_{i+1}$, $i=0,1$,$\\dots$, $m-1$), the degree of the curve $p$ and the weight associated to a control point, $w$.\nA $p$th degree NURBS basis function is defined as follows:\n\\begin{equation}\n    R(\\eta) =   \\frac{ N_{i,p}(\\eta) w_i }{W(\\eta)}\n            =   \\frac{ N_{i,p}(\\eta) w_i }{\n                    \\sum_{i=0}^{n} N_{i,p}(\\eta)w_i\n                }\n\\label{iso_eq:rational_basis_function}\n\\end{equation}\nwhere $w_i$ are the weights for the $i$th basis function $N_{i,p}(\\eta)$.\nFig.~\\ref{lr_fig:nurbs_rational_basis} shows the third order NURBS for an open knot vector.\n\n\\begin{figure}\n    \\centering\n    \\scalebox{0.5}{\n        \\includegraphics{literature/images/lr_nurbs_rational_basis.png}\n    }\n    \\caption[3rd NURBS basis function]{\n        3rd NURBS basis function for an open knot vector $\\Xi$ = \\{ -1, -1, -1, -1, -1/3, -1/3, -1/3, 0, 1/3, 1, 1, 1, 1 \\}.\n        Note that the functions are only interpolatory at the end points\n    }\n    \\label{lr_fig:nurbs_rational_basis}\n\\end{figure}\n\nThe first derivative of a NURBS basis function is computed using the quotient rule and is given by:\n\\begin{equation}\n    \\frac{d}{d\\eta}R_{i,p}(\\eta) =  w_i\\frac{\n        N^\\prime_{i,p}(\\eta)W(\\eta) - N_{i,p}(\\eta) W^\\prime(\\eta)\n    }{W(\\eta)^2}\n\\end{equation}", "meta": {"hexsha": "ead36ac8a5c944ea60d87e9ea01440f8978ab8fe", "size": 8612, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "literature/lr_nurbs.tex", "max_stars_repo_name": "fa93hws/thesis", "max_stars_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-30T12:14:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-30T12:14:47.000Z", "max_issues_repo_path": "literature/lr_nurbs.tex", "max_issues_repo_name": "fa93hws/thesis", "max_issues_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "literature/lr_nurbs.tex", "max_forks_repo_name": "fa93hws/thesis", "max_forks_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.3820224719, "max_line_length": 310, "alphanum_fraction": 0.6663957269, "num_tokens": 2685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899666, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7335766705475053}}
{"text": "\\chapter{m-Reductions}\nIn the proofs of \\Cref{theorem:halting,theorem:undefined-functions}, to prove\nthat a set $S$ is undecidable we proved that $S$ is decidable iff an undecidable\nset $K$ should be also decidable, which lead to the conclusion that $S$ is\nundecidable. This was done using ``reduction'' argument. We constructed a total\ncomputable function $f : \\N \\to \\N$ such that $f(x) \\in S$ iff $x \\in K$ for all\n$x \\in \\N$. In\nthis chapter we will study this method in more details.\n\n\\begin{definition}\n  Let $A, B \\subseteq \\N$. We say that $A$ is \\emph{$m$-reducible} to\n  $B$\\footnote{%\n    The letter ``m'' here stands for ``many-to-one''; however, Sipser's\n    ``Introduction to the Theory of Computation'' suggests to call such\n    reductions ``mapping reductions'' giving another life for the letter $m$ in\n    this notation.\n  }\n  ($A \\le_m B$) if there is a total computable function $f : \\N \\to \\N$ such\n  that $x \\in A$ iff $f(x) \\in B$ for all $x \\in \\N$. We say that $f$\n  \\emph{$m$-reduces} $A$ to $B$.\n\\end{definition}\n\nThis notion allows us to translate properties from one set to another.\n\\begin{theorem}\n\\label{theorem:m-reduction-complexity-preservation}\n  Let $A, B \\subseteq \\N$ such that $A \\le_m B$.\n  \\begin{itemize}\n    \\item If $B$ is decidable, then $A$ is decidable.\n    \\item If $B$ is enumerable, then $A$ is enumerable.\n  \\end{itemize}\n\\end{theorem}\n\n\\begin{exercise}\n  Let $A, B, C \\subseteq \\N$. Show that\n  \\begin{itemize}\n    \\item $A \\le_m A$, and \n    \\item if $A \\le_m B$ and $B \\le_m C$, then $A \\le_m C$.\n  \\end{itemize}\n\\end{exercise}\n\nNotice that the sets $\\emptyset$ and $\\N$ behave differently than other\ndecidable sets with respect to $\\le_m$.\n\\begin{remark}\n  Let $A, B \\subseteq \\N$.\n  \\begin{itemize}\n    \\item $A \\le_m \\emptyset$ iff $A = \\emptyset$, \n    \\item $A \\le_m \\N$ iff $A = \\N$, and\n    \\item $A \\le_m B$ provided that $A$ and $B$ are dicidable and $B \\not\\in\n      \\set{\\emptyset, \\N}$.\n  \\end{itemize}\n\\end{remark}\n\nHowever, in case of enumerable sets, the situation is not that simple.\n\\begin{exercise}\n  Show that there are enumerable sets $A, B \\subseteq \\N$ such that $A \\not\\le_m\n  B$.\n\\end{exercise}\n\nIn other words, enumerable sets form layers of sets increasing with repspect to\n$\\le_m$. So the questions is whether there is the last layer or not, the\nfollowing theorem give an affirmative answer to this question.\n\\begin{theorem}\n  In the class of enumerable sets, there are sets maximal with respect to\n  $m$-reducibility; i.e., there is an enumerable set $B$ sucht that $A \\le_m B$\n  for any enumerable set $A$.\n\\end{theorem}\n\\begin{proof}\n  Let $W$ be a enumerable universal set for the set of all enumerable subsets of\n  $\\N$ (it exists by \\Cref{theorem:universal-set-enumerable}). \n  We claim that the set $B = \\set[(n, x) \\in W]{\\pair{n}{x}}$ satisfies the\n  requirement of the theorem. Indeed, let $A$ be enumerable set. Then there is\n  $n \\in \\N$ such that $W_n = A$. Hence, it is easy to see that $f(x) \\in B$ iff \n  $n \\in A$, where $f(x) = \\pair{n}{x}$.\n\\end{proof}\n\n\\begin{definition}\n  An enumerable set $B$ maximal with respect to $m$-reducibility is called\n  \\emph{$m$-complete for the class of enumerable sets}.\n\\end{definition}\n\n\\begin{theorem}\n\\label{theorem:m-complete-enumerable}\n  Let $U$ be a G\\\"odel universal function. \n  Then $\\set[U(x, x) \\text{ terminates}]{x \\in \\N}$ is $m$-complete for the\n  class of enumerable sets.\n\\end{theorem}\n\\begin{proof}\n  Let $K \\subseteq \\N$ be a enumerable set. Let us consider a computable\n  function $V : \\N^2 \\to \\N$s such that $V(n, x) = 1$ if $n \\in K$ and undefined\n  otherwise. Since $U$ is G\\\"odel universal function, there is a total\n  computable $s : \\N \\to \\N$ such that $V_n = U_{s(n)}$. Hence,  $U_{s(n)}$\n  decides $\\N$ if $n \\in K$ and $U_{s(n)}$ decides $\\emptyset$ if $K \\not\\in K$.\n  Therefore $s(n) \\in D$ iff $n \\in K$.\n\\end{proof}\n\n\\begin{chapterendexercises}\n  \\exercise Prove that the set of all programs that halt on the input $0$ is\n    $m$-complete for the class of enumerable sets.\n  \\exercise Prove that the set of all programs that halt on at least one input\n  is $m$-complete for the class of enumerable sets.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "da344bfbc5265300d65a6c350eeee72ec55d79c1", "size": 4200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_9/chapter_39_m_reductions.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_9/chapter_39_m_reductions.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_9/chapter_39_m_reductions.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 41.1764705882, "max_line_length": 81, "alphanum_fraction": 0.6797619048, "num_tokens": 1360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619959279793, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.7335766642819255}}
{"text": "%\n% Chapter 2.3\n%\n\n\\section*{2.3 Differentiation Formulae}\n\n\\begin{enumerate}\n    \\item \\(\\frac{d}{dx}(c)=0\\) \\quad where \\(c\\) is a constant\n    \\item \\(\\frac{d}{dx}(x)=1\\)\n    \\item \\(\\frac{d}{dx}(x^n)=nx^{n-1}\\) \\quad if \\(n\\) is a positive integer\n    \\item \\(\\frac{d}{dx}[cf(x)]=c\\frac{d}{dx}f(x)\\) \\quad where \\(c\\) is a constant and \\(f(x)\\) is differentiable\n    \\item \\(\\frac{d}{dx}[f(x)+g(x)]=\\frac{d}{dx}f(x)+\\frac{d}{dx}g(x)\\) \\quad if \\(f(x)\\) and \\(g(x)\\) are differentiable\n    \\item \\(\\frac{d}{dx}[f(x)-g(x)]=\\frac{d}{dx}f(x)-\\frac{d}{dx}g(x)\\) \\quad if \\(f(x)\\) and \\(g(x)\\) are differentiable\n    \\item \\(\\frac{d}{dx}[f(x)g(x)]=f(x)\\frac{d}{dx}[g(x)]+g(x)\\frac{d}{dx}[f(x)]\\) \\quad if \\(f\\) and \\(g\\) are differentiable\n    \\item \\(\\frac{d}{dx}[\\frac{f(x)}{g(x)}]=\\frac{g(x)\\frac{d}{dx}[f(x)]-f(x)\\frac{d}{dx}[g(x)]}{g{(x)}^2}\\) \\quad if \\(f\\) and \\(g\\) are differentiable\n\\end{enumerate}\n\\begin{enumerate}\n    \\item The derivative of a constant is 0.\n    \\item The derivative of \\(x\\) is 1.\n    \\item The general power rule\n    \\item The derivative of a constant times a function is the constant times the derivative of the function.\n    \\item The derivative of a sum of functions is the sum of the derivatives.\n    \\item The derivative of the difference is the difference of the derivatives.\n    \\item The product rule\n    \\item The quotient rule\n\\end{enumerate}\n", "meta": {"hexsha": "e4bb8155c8229112e17fdfe79ae1110ba829e16e", "size": 1383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2-3.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/2-3.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/2-3.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.2222222222, "max_line_length": 152, "alphanum_fraction": 0.604483008, "num_tokens": 505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.795658095217705, "lm_q1q2_score": 0.7335345727672493}}
{"text": "\\chapter{Determinant}\nThe goal of this chapter is to give the basis-free\ndefinition of the determinant:\nthat is, we're going to define $\\det T$\nfor $T \\colon V \\to V$ without making reference to the encoding for $T$.\nThis will make it obvious the determinant of a matrix\ndoes not depend on the choice of basis,\nand that several properties are vacuously true\n(e.g.\\ that the determinant is multiplicative).\n\nThe determinant is only defined for finite-dimensional\nvector spaces, so if you want you can restrict\nyour attention to finite-dimensional vector spaces for this chapter.\nOn the other hand we do not need the\nground field to be algebraically closed.\n\n\\section{Wedge product}\n\\prototype{$\\Lambda^2(\\RR^2)$ gives parallelograms.}\nWe're now going to define something called the wedge product.\nIt will look at first like the tensor product $V \\otimes V$,\nbut we'll have one extra relation.\n\nFor simplicity, I'll first define the wedge product $\\Lambda^2(V)$.\nBut we will later replace $2$ with any $n$.\n\n\\begin{definition}\n\tLet $V$ be a $k$-vector space.\n\tThe $2$-wedge product $\\Lambda^2(V)$ is the abelian group\n\tgenerated by elements of the form $v \\wedge w$ (where $v,w \\in V$),\n\tsubject to the same relations\n\t\\begin{align*}\n\t\t(v_1 + v_2) \\wedge w &= v_1 \\wedge w + v_2 \\wedge w \\\\\n\t\tv \\wedge (w_1 + w_2) &= v \\wedge w_1 + v \\wedge w_2 \\\\\n\t\t(c \\cdot v) \\wedge w &= v \\wedge (c \\cdot w)\n\t\\end{align*}\n\tplus two additional relations:\n\t\\[ v \\wedge v = 0 \\quad\\text{and}\\quad\n\t\tv \\wedge w = - w \\wedge v. \\]\n\tAs a vector space, its action is given by\n\t$c \\cdot (v \\wedge w) = (c \\cdot v) \\wedge w = v \\wedge (c \\cdot w)$.\n\\end{definition}\n\\begin{exercise}\n\tShow that the condition $v \\wedge w = - (w \\wedge v)$\n\tis actually extraneous:\n\tyou can derive it from the fact that $v \\wedge v = 0$.\n\t(Hint: expand $(v + w) \\wedge (v + w) = 0$.)\n\\end{exercise}\n\nThis looks almost exactly the same as the definition for a tensor product,\nwith two subtle differences.\nThe first is that we only have $V$ now, rather than $V$ and $W$\nas with the tensor product\\footnote{So maybe the wedge product\n\tmight be more accurately called the ``wedge power''!}\nSecondly, there is a new \\emph{mysterious} relation\n\\[ v \\wedge v = 0 \\implies v \\wedge w = - (w \\wedge v). \\]\nWhat's that doing there?\nIt seems kind of weird.\n\nI'll give you a hint.\n\\begin{example}\n\t[Wedge product explicit computation]\n\tLet $V = \\RR^2$, and let $v = ae_1 + be_2$, $w = ce_1 + de_2$.\n\tNow let's compute $v \\wedge w$ in $\\Lambda^2(V)$.\n\t\\begin{align*}\n\t\tv \\wedge w &= (ae_1 + be_2) \\wedge (ce_1 + de_2) \\\\\n\t\t&= ac (e_1 \\wedge e_1) + bd (e_2 \\wedge e_2)\n\t\t+ ad (e_1 \\wedge e_2) + bc (e_2 \\wedge e_1) \\\\\n\t\t&= ad (e_1 \\wedge e_2) + bc (e_2 \\wedge e_1) \\\\\n\t\t&= (ad-bc) (e_1 \\wedge e_2).\n\t\\end{align*}\n\\end{example}\n\nWhat is $ad-bc$? You might already recognize it:\n\\begin{itemize}\n\t\\ii You might know that the area of the parallelogram\n\tformed by $v$ and $w$ is $ad-bc$.\n\t\\ii You might recognize it as the determinant of\n\t$ \\begin{bmatrix} a & c \\\\ b & d \\end{bmatrix}$.\n\tIn fact, you might even know that the determinant\n\tis meant to interpret hypervolumes.\n\\end{itemize}\n\n\\begin{center}\n\\begin{asy}\n\tpair v = (4,1);\n\tpair w = (2,3);\n\tdot(\"$0$\", origin, dir(225));\n\tdot(\"$v = ae_1 + be_2$\", v, dir(-45), red);\n\tdot(\"$w = ce_1 + de_2$\", w, dir(135), red);\n\tdot(\"$v+w$\", v+w, dir(45));\n\tlabel(\"$ad-bc$\", (v+w)/2, blue);\n\tfill(origin--v--(v+w)--w--cycle, opacity(0.1)+lightcyan);\n\tdraw(origin--v, EndArrow, Margins);\n\tdraw(origin--w, EndArrow, Margins);\n\tdraw(v--(v+w), EndArrow, Margins);\n\tdraw(w--(v+w), EndArrow, Margins);\n\\end{asy}\n\\end{center}\n\nThis is absolutely no coincidence.\nThe wedge product is designed to interpret signed areas.\nThat is, $v \\wedge w$ is meant to interpret the area of the parallelogram\nformed by $v$ and $w$.\nYou can see why the condition $(cv) \\wedge w = v \\wedge (cw)$ would make sense now.\nAnd now of course you know why $v \\wedge v$ ought to be zero:\nit's an area zero parallelogram!\n\nThe \\textbf{miracle of wedge products} is that the only additional condition\nwe need to add to the tensor product axioms is that $v \\wedge w = -(w \\wedge v)$.\nThen suddenly, the wedge will do all our work of interpreting volumes for us.\n\nIn analog to earlier:\n\\begin{proposition}\n\t[Basis of $\\Lambda^2(V)$]\n\tLet $V$ be a vector space\n\twith basis $e_1$, \\dots, $e_n$.\n\tThen a basis of $\\Lambda^2(V)$ is\n\t\\[ e_i \\wedge e_j \\]\n\twhere $i < j$.\n\tHence $\\Lambda^2(V)$ has dimension $\\binom n2$.\n\\end{proposition}\n\\begin{proof}\n\tSurprisingly slippery, and also omitted.\n\t(You can derive it from the corresponding theorem on tensor products.)\n\\end{proof}\n\nNow I have the courage to define a multi-dimensional wedge product.\nIt's just the same thing with more wedges.\n\\begin{definition}\n\tLet $V$ be a vector space and $m$ a positive integer.\n\tThe space $\\Lambda^m(V)$ is generated by wedges of the form\n\t\\[ v_1 \\wedge v_2 \\wedge \\dots \\wedge v_m \\]\n\tsubject to relations\n\t\\begin{align*}\n\t\t\\dots \\wedge (v_1+v_2) \\wedge \\dots\n\t\t\t&= (\\dots \\wedge v_1 \\wedge \\dots)\n\t\t\t + (\\dots \\wedge v_2 \\wedge \\dots) \\\\\n\t\t\\dots \\wedge (cv_1) \\wedge v_2 \\wedge \\dots\n\t\t\t&= \\dots \\wedge v_1 \\wedge (cv_2) \\wedge \\dots  \\\\\n\t\t\\dots \\wedge v \\wedge v \\wedge \\dots &= 0 \\\\\n\t\t\\dots \\wedge v \\wedge w \\wedge \\dots &=\n\t\t\t- (\\dots \\wedge w \\wedge v \\wedge \\dots)\n\t\\end{align*}\n\tAs a vector space\n\t\\[ c \\cdot (v_1 \\wedge v_2 \\wedge \\dots \\wedge v_m)\n\t = (cv_1) \\wedge v_2 \\wedge \\dots \\wedge v_m\n\t = v_1 \\wedge (cv_2) \\wedge \\dots \\wedge v_m\n\t = \\dots .\n\t\\]\n\\end{definition}\nThis definition is pretty wordy, but in English the three conditions say\n\\begin{itemize}\n\t\\ii We should be able to add products like before,\n\t\\ii You can put constants onto any of the $m$ components\n\t(as is directly pointed out in the ``vector space'' action), and\n\t\\ii Switching any two \\emph{adjacent} wedges negates the whole wedge.\n\\end{itemize}\nSo this is the natural generalization of $\\Lambda^2(V)$.\nYou can convince yourself that any element of the form\n\\[ \\dots \\wedge v \\wedge \\dots \\wedge v \\wedge \\dots \\]\nshould still be zero.\n\nJust like $e_1 \\wedge e_2$ was a basis earlier, we can find the basis\nfor general $m$ and $n$.\n\\begin{proposition}[Basis of the wedge product]\n\tLet $V$ be a vector space with basis $e_1, \\dots, e_n$.\n\tA basis for $\\Lambda^m(V)$ consists of the elements\n\t\\[ e_{i_1} \\wedge e_{i_2} \\wedge \\dots \\wedge e_{i_m} \\]\n\twhere\n\t\\[ 1 \\le i_1 < i_2 < \\dots < i_m \\le n. \\]\n\tHence $\\Lambda^m(V)$ has dimension $\\binom nm$.\n\\end{proposition}\n\\begin{proof}[Sketch of proof]\n\tWe knew earlier that $e_{i_1} \\otimes \\dots \\otimes e_{i_m}$\n\twas a basis for the tensor product.\n\tHere we have the additional property that (a)\n\tif two basis elements re-appear then the whole thing becomes zero,\n\tthus we should assume the $i$'s are all distinct;\n\tand (b) we can shuffle around elements,\n\tand so we arbitrarily decide to put the basis elements\n\tin increasing order.\n\\end{proof}\n\n\n\\section{The determinant}\n\\prototype{$(ae_1+be_2)\\wedge(ce_1+de_2) = (ad-bc)(e_1\\wedge e_2)$.}\nNow we're ready to define the determinant.\nSuppose $T \\colon V \\to V$ is a square matrix.\nWe claim that the map $\\Lambda^m(V) \\to \\Lambda^m(V)$ given on wedges by\n\\[ v_1 \\wedge v_2 \\wedge \\dots \\wedge v_m\n\t\\mapsto T(v_1) \\wedge T(v_2) \\wedge \\dots \\wedge T(v_m) \\]\nand extending linearly to all of $\\Lambda^m(V)$ is a linear map.\n(You can check this yourself if you like.)\nWe call that map $\\Lambda^m(T)$.\n\\begin{example}\n\t[Example of $\\Lambda^m(T)$]\n\tIn $V = \\RR^4$ with standard basis $e_1$, $e_2$, $e_3$, $e_4$,\n\tlet $T(e_1) = e_2$, $T(e_2) = 2e_3$, $T(e_3) = e_3$ and $T(e_4) = 2e_2 + e_3$.\n\tThen, for example, $\\Lambda^2(T)$ sends\n\t\\begin{align*}\n\t\te_1 \\wedge e_2 + e_3 \\wedge e_4\n\t\t&\\mapsto T(e_1) \\wedge T(e_2) + T(e_3) \\wedge T(e_4) \\\\\n\t\t&= e_2 \\wedge 2e_3 + e_3 \\wedge (2e_2 + e_3) \\\\\n\t\t&= 2(e_2 \\wedge e_3 + e_3 \\wedge e_2) \\\\\n\t\t&= 0.\n\t\\end{align*}\n\\end{example}\n\nNow here's something interesting.\nSuppose $V$ has dimension $n$, and let $m=n$.\nThen $\\Lambda^n(V)$ has dimension $\\binom nn = 1$ --- it's a one dimensional space!\nHence $\\Lambda^n(V) \\cong k$.\n\nSo $\\Lambda^n(T)$ can be thought of as a linear map from $k$ to $k$.\nBut we know that \\emph{a linear map from $k$ to $k$ is just multiplication by a constant}.\nHence $\\Lambda^n(T)$ is multiplication by some constant.\n\\begin{definition}\n\tLet $T \\colon V \\to V$, where $V$ is an $n$-dimensional vector space.\n\tThen $\\Lambda^n(T)$ is multiplication by a constant $c$;\n\twe define the \\vocab{determinant} of $T$ as $c = \\det T$.\n\\end{definition}\n\n\\begin{example}[The determinant of a $2 \\times 2$ matrix]\n\tLet $V = \\RR^2$ again with basis $e_1$ and $e_2$.\n\tLet\n\t\\[ T = \\begin{bmatrix}\n\t\t\ta & c \\\\ b & d\n\t\t\\end{bmatrix}.\n\t\\]\n\tIn other words, $T(e_1) = ae_1 + be_2$\n\tand $T(e_2) = ce_1 + de_2$.\n\n\tNow let's consider $\\Lambda^2(V)$.\n\tIt has a basis $e_1 \\wedge e_2$.\n\tNow $\\Lambda^2(T)$ sends it to\n\t\\[ e_1 \\wedge e_2 \\xmapsto{\\Lambda^2(T)}\n\t\tT(e_1) \\wedge T(e_2) =\n\t\t(ae_1 + be_2) \\wedge (ce_1 + de_2)\n\t\t= (ad-bc)(e_1 \\wedge e_2).\n\t\\]\n\tSo $\\Lambda^2(T) : \\Lambda^2(V) \\to \\Lambda^2(V)$\n\tis multiplication by $\\det T = ad-bc$,\n\tbecause it sent $e_1 \\wedge e_2$ to\n\t$(ad-bc)(e_1 \\wedge e_2)$.\n\\end{example}\nAnd that is the definition of a determinant.\nOnce again, since we defined it in terms of $\\Lambda^n(T)$,\nthis definition is totally independent of the choice of basis.\nIn other words, the determinant can be defined based on $T \\colon V \\to V$ alone\nwithout any reference to matrices.\n\n\\begin{ques}\n\tWhy does $\\Lambda^n(S \\circ T) = \\Lambda^n(S) \\circ \\Lambda^n(T)$?\n\\end{ques}\nIn this way, we also get \\[ \\det(S \\circ T) = \\det(S) \\det(T) \\] for free.\n\nMore generally if we replace $2$ by $n$,\nan write out the result of expanding\n\\[ \\left( a_{11}e_1 + a_{21}e_2 + \\dots \\right) \\wedge \\dots \\wedge\n\t\\left( a_{1n}e_1 + a_{2n}e_2 + \\dots + a_{nn} e_n \\right) \\]\nthen you will get the formula\n\\[ \\det(A) = \\sum_{\\sigma \\in S_n} \\opname{sgn}(\\sigma)\n\ta_{1, \\sigma(1)} a_{2, \\sigma(2)} \\dots a_{n, \\sigma(n)} \\]\ncalled the \\vocab{Leibniz formula} for determinants.\nAmerican high school students will recognize it;\nthis is (unfortunately) taught as the definition of the determinant,\nrather than a corollary of the better definition using wedge products.\n\n\\begin{exercise}\n\tVerify that expanding the wedge product\n\tyields the Leibniz formula for $n=3$.\n\\end{exercise}\n\n\\section{Characteristic polynomials, and Cayley-Hamilton}\nLet's connect with the theory of eigenvalues.\nTake a map $T \\colon V \\to V$, where $V$ is $n$-dimensional\nover an algebraically closed field,\nand suppose its eigenvalues\nare $\\lambda_1$, $\\lambda_2$, \\dots, $\\lambda_n$ (with repetition).\nThen the \\vocab{characteristic polynomial} is given by\n\\[\n\tp_T(X) = (X-\\lambda_1)(X-\\lambda_2) \\dots (X-\\lambda_n).\n\\]\nNote that if we've written $T$ in Jordan form, that is,\n\\[\n\tT = \\begin{bmatrix}\n\t\t\\lambda_1 & \\ast & 0 & \\dots & 0 \\\\\n\t\t0 & \\lambda_2 & \\ast & \\dots & 0 \\\\\n\t\t0 & 0 & \\lambda_3 & \\dots & 0 \\\\\n\t\t\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\t0 & 0 & 0 & \\dots & \\lambda_n\n\t\\end{bmatrix}\n\\]\n(here each $\\ast$ is either $0$ or $1$),\nthen we can hack together the definition\n\\[\n\tp_T(X) \\defeq\n\t\\det \\left( X \\cdot \\id_n - T \\right)\n\t= \\det \\begin{bmatrix}\n\t\tX - \\lambda_1 & \\ast & 0 & \\dots & 0 \\\\\n\t\t0 & X - \\lambda_2 & \\ast & \\dots & 0 \\\\\n\t\t0 & 0 & X - \\lambda_3 & \\dots & 0 \\\\\n\t\t\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\t0 & 0 & 0 & \\dots & X - \\lambda_n\n\t\\end{bmatrix}.\n\\]\nThe latter definition is what you'll see in most\nlinear algebra books because it lets you define the characteristic polynomial\nwithout mentioning the word ``eigenvalue''\n(i.e.\\ entirely in terms of arrays of numbers).\nI'll admit it does have the merit that it means that given any matrix,\nit's easy to compute the characteristic polynomial and hence\ncompute the eigenvalues;\nbut I still think the definition should be done in terms of\neigenvalues to begin with.\nFor instance the determinant definition obscures the following theorem,\nwhich is actually a complete triviality.\n\\begin{theorem}[Cayley-Hamilton]\n\tLet $T \\colon V \\to V$ be a map of finite-dimensional\n\tvector spaces over an algebraically closed field.\n\tThen for any $T \\colon V \\to V$,\n\tthe map $p_T(T)$ is the zero map.\n\\end{theorem}\nHere, by $p_T(T)$ we mean that if\n\\[ p_T(X) = X^n + c_{n-1} X^{n-1} + \\dots + c_0 \\]\nthen \\[ p_T(T) = T^n + c_{n-1} T^{n-1} + \\dots + c_1 T +  c_0 I \\]\nis the zero map,\nwhere $T^k$ denotes $T$ applied $k$ times.\nWe saw this concept already when we proved\nthat $T$ had at least one nonzero eigenvector.\n\n\\begin{example}[Example of Cayley-Hamilton using determinant definition]\n\tSuppose $T = \\begin{bmatrix} 1 & 2 \\\\ 3 & 4 \\end{bmatrix}$.\n\tUsing the determinant definition of characteristic polynomial,\n\twe find that $p_T(X) = (X-1)(X-4)-(-2)(-3) = X^2 - 5X - 2$.\n\tIndeed, you can verify that\n\t\\[ T^2 - 5T - 2\n\t\t= \\begin{bmatrix}\n\t\t\t7 & 10 \\\\\n\t\t\t15 & 22\n\t\t\\end{bmatrix}\n\t\t- 5 \\cdot \\begin{bmatrix}\n\t\t\t1 & 2 \\\\\n\t\t\t3 & 4\n\t\t\\end{bmatrix}\n\t\t- 2 \\cdot \\begin{bmatrix}\n\t\t\t1 & 0 \\\\\n\t\t\t0 & 1\n\t\t\\end{bmatrix}\n\t\t= \\begin{bmatrix}\n\t\t\t0 & 0 \\\\\n\t\t\t0 & 0\n\t\t\\end{bmatrix}.\n\t\\]\n\\end{example}\nIf you define $p_T$ without the word eigenvalue,\nand adopt the evil view that matrices are arrays of numbers,\nthen this looks like a complete miracle.\n(Indeed, just look at the terrible proofs on Wikipedia.)\n\nBut if you use the abstract viewpoint of $T$ as a linear map,\nthen the theorem is almost obvious:\n\\begin{proof}[Proof of Cayley-Hamilton]\n\tSuppose we write $V$ in Jordan normal form as\n\t\\[ V = J_1 \\oplus \\dots \\oplus J_m \\]\n\twhere $J_i$ has eigenvalue $\\lambda_i$ and dimension $d_i$.\n\tBy definition,\n\t\\[ p_T(T) = (T - \\lambda_1)^{d_1} (T - \\lambda_2)^{d_2}\n\t\t\\dots (T - \\lambda_m)^{d_m}. \\]\n\tBy definition, $(T - \\lambda_1)^{d_1}$ is the zero map on $J_1$.\n\tSo $p_T(T)$ is zero on $J_1$.\n\tSimilarly it's zero on each of the other $J_i$'s --- end of story.\n\\end{proof}\n\\begin{remark}\n\t[Tensoring up]\n\tThe Cayley-Hamilton theorem holds without the hypothesis that\n\t$k$ is algebraically closed:\n\tbecause for example any real matrix can be regarded\n\tas a matrix with complex coefficients\n\t(a trick we've mentioned before).\n\tI'll briefly hint at how you can use tensor products to formalize this idea.\n\n\tLet's take the space $V = \\RR^3$, with basis $e_1$, $e_2$, $e_3$.\n\tThus objects in $V$ are of the form $r_1 e_1 + r_2 e_2 + r_3 e_3$\n\twhere $r_1$, $r_2$, $r_3$ are real numbers.\n\tWe want to consider essentially the same vector space,\n\tbut with complex coefficients $z_i$ rather than real coefficients $r_i$.\n\n\tSo here's what we do: view $\\CC$ as a $\\RR$-vector space\n\t(with basis $\\{1,i\\}$, say)\n\tand consider the \\vocab{complexification}\n\t\\[ V_\\CC \\defeq \\CC \\otimes_\\RR V. \\]\n\tThen you can check that our elements are actually of the form\n\t\\[ z_1 \\otimes e_1 + z_2 \\otimes e_2 + z_3 \\otimes e_3. \\]\n\tHere, the tensor product is over $\\RR$,\n\tso we have $z \\otimes re_i = (zr) \\otimes e_i$ for $r \\in \\RR$.\n\tThen $V_{\\CC}$ can be thought as a three-dimensional vector space over $\\CC$,\n\twith basis $1 \\otimes e_i$ for $i \\in \\{1,2,3\\}$.\n\tIn this way, the tensor product lets us formalize the idea\n\tthat we ``fuse on'' complex coefficients.\n\n\tIf $T \\colon V \\to W$ is a map, then $T_\\CC \\colon V_\\CC \\to W_\\CC$\n\tis just the map $z \\otimes v \\mapsto z \\otimes T(v)$.\n\tYou'll see this written sometimes as $T_\\CC = \\id \\otimes T$.\n\tOne can then apply theorems to $T_\\CC$\n\tand try to deduce the corresponding results on $T$.\n\\end{remark}\n\n\\section\\problemhead\n\\begin{problem}[Column operations]\n\tShow that for any real numbers $x_{ij}$ (here $1 \\le i,j \\le n$) we have\n\t\\[\n\t\t\\det\n\t\t\\begin{bmatrix}\n\t\t\tx_{11} & x_{12} & \\dots & x_{1n} \\\\\n\t\t\tx_{21} & x_{22} & \\dots & x_{2n} \\\\\n\t\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\t\tx_{n1} & x_{n2} & \\dots & x_{nn} \\\\\n\t\t\\end{bmatrix}\n\t\t=\n\t\t\\det\n\t\t\\begin{bmatrix}\n\t\t\tx_{11} + cx_{12} & x_{12} & \\dots & x_{1n} \\\\\n\t\t\tx_{21} + cx_{22} & x_{22} & \\dots & x_{2n} \\\\\n\t\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\t\tx_{n1} + cx_{n2} & x_{n2} & \\dots & x_{nn} \\\\\n\t\t\\end{bmatrix}.\n\t\\]\n\t\\begin{hint}\n\t\tThe point is that\n\t\t\\[\n\t\t\t(v_1+cv_2) \\wedge v_2 \\dots \\wedge v_n\n\t\t\t= v_1 \\wedge v_2 \\dots \\wedge v_n\n\t\t\t+ c(v_2 \\wedge v_2 \\dots \\wedge v_n)\n\t\t\\]\n\t\tand the latter term is zero.\n\t\\end{hint}\n\\end{problem}\n\\begin{problem}\n\t[Determinant is product of eigenvalues]\n\tLet $V$ be an $n$-dimensional vector space\n\tover an algebraically closed field $k$.\n\tLet $T \\colon V \\to V$ be a linear map with\n\teigenvalues $\\lambda_1$, $\\lambda_2$, \\dots, $\\lambda_n$\n\t(counted with algebraic multiplicity).\n\tShow that $\\det T = \\lambda_1 \\dots \\lambda_n$.\n\t\\begin{hint}\n\t\tYou can either do this by writing $T$ in matrix form,\n\t\tor you can use the wedge definition of $\\det T$\n\t\twith the basis given by Jordan form.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\t[Exponential matrix]\n\tLet $X$ be an $n \\times n$ matrix with complex coefficients.\n\tWe define the exponential map by\n\t\\[ \\exp(X) = 1 + X + \\frac{X^2}{2!} + \\frac{X^3}{3!} + \\dots \\]\n\t(take it for granted that this converges to some $n \\times n$ matrix).\n\tProve that\n\t\\[ \\det(\\exp(X)) = e^{\\Tr X}. \\]\n\t\\begin{hint}\n\t\tThis is actually immediate by taking any basis\n\t\tin which $X$ is upper-triangular!\n\t\\end{hint}\n\\end{problem}\n\n\n\\begin{problem}\n\t[Extension to \\Cref{prob:equal_dimension}]\n\tLet $T \\colon V \\to V$ be a map of finite-dimensional vector spaces.\n\tProve that $T$ is an isomorphism\n\tif and only if $\\det T \\ne 0$.\n\t\\begin{hint}\n\t\tYou don't need eigenvalues (though they could work also).\n\t\tIn one direction, recall that (by \\Cref{prob:equal_dimension})\n\t\twe can replace ``isomorphism'' by ``injective''.\n\t\tIn the other, if $T$ is an isomorphism,\n\t\tlet $S$ be the inverse map and look at $\\det(S \\circ T)$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tRecall that (by \\Cref{prob:equal_dimension})\n\t\twe can replace ``isomorphism'' by ``injective''.\n\n\t\tIf $T(v) = 0$ for any nonzero $v$,\n\t\tthen by taking a basis for which $e_1 = v$,\n\t\twe find $\\Lambda^n(T)$ will map $e_1 \\wedge \\dots$\n\t\tto $0 \\wedge T(e_2) \\wedge \\dots = 0$,\n\t\thence is the zero map, so $\\det T = 0$.\n\n\t\tConversely, if $T$ is an isomorphism,\n\t\twe let $S$ denote the inverse map.\n\t\tThen $1 = \\det(\\id) = \\det(S \\circ T) = \\det S \\det T$,\n\t\tso $\\det T \\ne 0$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Based on Sweden 2010]\n\t\\gim\n\tA herd of $1000$ cows of nonzero weight is given.\n\tProve that we can remove one cow such that the\n\tremaining $999$ cows cannot be split\n\tinto two halves of equal weights.\n\t\\begin{hint}\n\t\tConsider $1000 \\times 1000$ matrix $M$\n\t\twith entries $0$ on diagonal and $\\pm 1$ off-diagonal.\n\t\tMod $2$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tWe proceed by contradiction.\n\t\tLet $v$ be a vector of length $1000$\n\t\twhose entries are weight of cows.\n\t\tAssume the existence of a matrix $M$ such that $Mv = 0$,\n\t\twith entries $0$ on diagonal and $\\pm 1$ off-diagonal.\n\t\tBut $\\det M \\pmod 2$ is equal to the number of derangements\n\t\tof $\\{1, \\dots, 1000\\}$, which is odd.\n\t\tThus $\\det M$ is odd and in particular not zero,\n\t\tso $M$ is invertible.\n\t\tThus $Mv = 0 \\implies v = 0$, contradiction.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Putnam 2015]\n\t\\yod\n\tDefine $S$ to be the set of real matrices\n\t$\\left(\\begin{smallmatrix} a & b \\\\ c & d \\end{smallmatrix}\\right)$\n\tsuch that $a$, $b$, $c$, $d$ form\n\tan arithmetic progression in that order.\n\tFind all $M \\in S$ such that for some integer $k > 1$, $M^k \\in S$.\n\t\\begin{hint}\n\t\tThere is a family of solutions other than just $a=b=c=d$.\n\n\t\tOne can solve the problem using Cayley-Hamilton.\n\t\tA more ``bare-hands'' approach is to\n\t\tshow the matrix is invertible (unless $a=b=c=d$)\n\t\tand then diagonalize the matrix as\n\t\t$\n\t\tM =\n\t\t\\begin{bmatrix} s & -q \\\\ -r & p \\end{bmatrix}\n\t\t\\begin{bmatrix} \\lambda_1 & 0 \\\\ 0 & \\lambda_2 \\end{bmatrix}\n\t\t\\begin{bmatrix} p & q \\\\ r & s \\end{bmatrix}\n\t\t=\n\t\t\\begin{bmatrix}\n\t\t\tps\\lambda_1 - qr\\lambda_2 & qs(\\lambda_1-\\lambda_2) \\\\\n\t\t\tpr(\\lambda_2-\\lambda_1) & ps\\lambda_2 - qr\\lambda_1\n\t\t\\end{bmatrix}\n\t\t$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tThe answer is\n\t\t\\[ \\begin{bmatrix} t&t\\\\t&t \\end{bmatrix}\n\t\t\t\\quad\\text{and}\\quad\n\t\t\t\\begin{bmatrix} -3t&-t\\\\t&3t \\end{bmatrix} \\]\n\t\tfor $t \\in \\RR$.\n\t\tThese work by taking $k=3$.\n\n\t\tNow to see these are the only ones, consider an arithmetic matrix\n\t\t\\[ M = \\begin{bmatrix} a & a+e \\\\ a+2e & a+3e \\end{bmatrix}. \\]\n\t\twith $e \\neq 0$.\n\t\tIts characteristic polynomial is $t^2 - (2a+3e)t - 2e^2$,\n\t\twith discriminant $(2a+3e)^2 + 8e^2$,\n\t\tso it has two distinct real roots; moreover, since $-2e^2 \\le 0$\n\t\teither one of the roots is zero or they are of opposite signs.\n\t\tNow we can diagonalize $M$ by writing\n\t\t\\[\n\t\t\tM =\n\t\t\t\\begin{bmatrix} s & -q \\\\ -r & p \\end{bmatrix}\n\t\t\t\\begin{bmatrix} \\lambda_1 & 0 \\\\ 0 & \\lambda_2 \\end{bmatrix}\n\t\t\t\\begin{bmatrix} p & q \\\\ r & s \\end{bmatrix}\n\t\t\t=\n\t\t\t\\begin{bmatrix}\n\t\t\t\tps\\lambda_1 - qr\\lambda_2 & qs(\\lambda_1-\\lambda_2) \\\\\n\t\t\t\tpr(\\lambda_2-\\lambda_1) & ps\\lambda_2 - qr\\lambda_1\n\t\t\t\\end{bmatrix}\n\t\t\\]\n\t\twhere $ps-qr=1$. By using the fact the diagonal entries have sum equalling\n\t\tthe off-diagonal entries, we obtain that\n\t\t\\[ (ps-qr)(\\lambda_1+\\lambda_2) = (qs-pr)(\\lambda_1-\\lambda_2)\n\t\t\t\\implies qs-pr = \\frac{\\lambda_1+\\lambda_2}{\\lambda_1-\\lambda_2}. \\]\n\t\tNow if $M^k \\in S$ too then the same calculation gives\n\t\t\\[ qs-pr = \\frac{\\lambda_1^k+\\lambda_2^k}{\\lambda_1^k-\\lambda_2^k}. \\]\n\t\tLet $x = \\lambda_1/\\lambda_2 < 0$ (since $-2e^2 < 0$). We appropriately get\n\t\t\\[ \\frac{x+1}{x-1} = \\frac{x^k+1}{x^k-1}\n\t\t\t\\implies \\frac{2}{x-1} = \\frac{2}{x^k-1}\n\t\t\t\\implies x = x^k \\implies x = -1 \\text{ or } x = 0 \\]\n\t\tand $k$ odd. If $x=0$ we get $e=0$ and if $x=-1$ we get $2a+3e=0$,\n\t\twhich gives the curve of solutions that we claimed.\n\n\t\tA slicker approach is by Cayley-Hamilton.\n\t\tAssume that $e \\neq 0$, so $M$ has two distinct real eigenvalues as above.\n\t\tWe have $M^k = cM + d\\id$ for some constants $c$ and $d$\n\t\t(since $M$ satisfies some quadratic polynomial).\n\t\tSince $M \\in S$, $M^k \\in S$ we obtain $d=0$.\n\t\tThus $M^k = cM$, so it follows the eigenvalues of $M$ are negatives of each other.\n\t\tThat means $\\Tr M = 0$, and the rest is clear.\n\t\\end{sol}\n\\end{problem}\n\n\n%\\begin{problem}[USAMO 2008, edited]\n%\tAt a certain mathematical conference,\n%\tevery two mathematicians are either friends or strangers.\n%\tAt mealtime, every participant eats in one of two large dining rooms.\n%\tEach mathematician insists upon eating in a room which contains an\n%\teven number of his or her friends.\n%\tAssuming that such a split exists, prove that the number of ways\n%\tthat the mathematicians may be split between the two rooms is a power of two.\n%\t% http://www.artofproblemsolving.com/Forum/viewtopic.php?p=3338962#p3338962\n%\\end{problem}\n\n\n\n\\begin{problem}\n\t\\yod\n\tLet $V$ be a finite-dimensional vector space over $k$ and $T : V \\to V$.\n\tShow that\n\t\\[\n\t\t\\det(a \\cdot \\id_V - T) =\n\t\t\\sum_{n=0}^{\\dim V} a^{\\dim V-n} \\cdot (-1)^n\n\t\t\\Tr\\left( \\Lambda^n(T) \\right)\n\t\\]\n\twhere the trace is taken by viewing $\\Lambda^n(T) : \\Lambda^n(V) \\to \\Lambda^n(V)$.\n\t\\begin{hint}\n\t\tTake bases, and do a fairly long calculation.\n\t\\end{hint}\n\t\\begin{sol}\n\t\t\\newcommand{\\Fix}{\\opname{Fix}}\n\t\t\\newcommand{\\NoFix}{\\opname{NoFix}}\n\t\tPick a basis $e_1, \\dots, e_n$ of $V$.\n\t\tLet $T$ have matrix $(x_{ij})$, and let $m = \\dim V$.\n\t\tLet $\\delta_{ij}$ be the Kronecker delta.\n\t\tAlso, let $\\Fix(\\sigma)$ denote the fixed points of a permutation $\\sigma$\n\t\tand let $\\NoFix(\\sigma)$ denote the non-fixed points.\n\n\t\tExpanding then gives\n\t\t\\begin{align*}\n\t\t\t&\\qquad \\det (a \\cdot \\id - T) \\\\\n\t\t\t&= \\sum_{\\sigma \\in S_m} \\left( \\sign(\\sigma)\n\t\t\t\\cdot \\prod_{i=1}^m \\left( a \\cdot \\delta_{i \\sigma(i)} - x_{i \\sigma(i)} \\right)\\right) \\\\\n\t\t\t% ------------------------\n\t\t\t&=\n\t\t\t\\sum_{s=0}^m\n\t\t\t\\sum_{1 \\le i_1 < \\dots < i_s \\le m}\n\t\t\t\\sum_{\\substack{\\sigma \\in S_m \\\\ \\sigma \\text{ fixes } i_k}}\n\t\t\t\\left( \\sign(\\sigma)\n\t\t\t\\cdot \\prod_{i=1}^m \\left( a \\cdot \\delta_{i \\sigma(i)} - x_{i \\sigma(i)} \\right)\\right) \\\\\n\t\t\t% ------------------------\n\t\t\t&=\n\t\t\t\\sum_{s=0}^m\n\t\t\t\\sum_{1 \\le i_1 < \\dots < i_s \\le m}\n\t\t\t\\sum_{\\substack{\\sigma \\in S_m \\\\ \\sigma \\text{ fixes } (i_k)}}\n\t\t\t\\left( \\sign(\\sigma)\n\t\t\t\\cdot \\prod_{i \\notin (i_k)} -x_{i \\sigma(i)}\n\t\t\t\\prod_{i \\in (i_k)}^n \\left( a \\cdot - x_{ii}\n\t\t\t\\right)\\right) \\\\\n\t\t\t% -----------------------\n\t\t\t&=\n\t\t\t\\sum_{\\sigma \\in S_m}\n\t\t\t\\left( \\sign(\\sigma)\n\t\t\t\\cdot \\prod_{i \\in \\NoFix(\\sigma)} -x_{i \\sigma(i)}\n\t\t\t\\prod_{i \\in \\Fix{\\sigma}} \\left( a - x_{ii}\n\t\t\t\\right)\\right) \\\\\n\t\t\t% -----------------------\n\t\t\t&=\n\t\t\t\\sum_{\\sigma \\in S_m}\n\t\t\t\\left( \\sign(\\sigma)\n\t\t\t\\cdot \\left( \\prod_{i \\in \\NoFix(\\sigma)} -x_{i \\sigma(i)} \\right)\n\t\t\t\\left( \\sum_{t=0}^{\\left\\lvert \\Fix(\\sigma) \\right\\rvert}\n\t\t\ta^{\\left\\lvert \\Fix(\\sigma) \\right\\rvert - t} \\cdot \\sum_{i_1 < \\dots < i_t \\in \\Fix(\\sigma)}\n\t\t\t\\prod_{k=1}^t -x_{i_k i_k} \\right)\n\t\t\t\\right) \\\\\n\t\t\t% -----------------------\n\t\t\t&=\n\t\t\t\\sum_{\\sigma \\in S_m}\n\t\t\t\\left( \\sign(\\sigma)\n\t\t\t\\left( \\sum_{t=0}^{\\left\\lvert \\Fix(\\sigma) \\right\\rvert}\n\t\t\ta^{m-t-\\left\\lvert \\Fix(\\sigma) \\right\\rvert}\n\t\t\t\\sum_{\\substack{X \\subseteq \\{1, \\dots, m\\} \\\\ \\NoFix(\\sigma) \\subseteq X \\\\ X \\text{ has exactly $t$ fixed}}} \\prod_{i \\in X} -x_{i \\sigma(i)}\n\t\t\t\\right) \\right) \\\\\n\t\t\t% -----------------------\n\t\t\t&=\n\t\t\t\\sum_{n=0}^m\n\t\t\ta^{m-n}\n\t\t\t\\left(\n\t\t\t\\sum_{\\sigma \\in S_m}\n\t\t\t\\sign(\\sigma)\n\t\t\t\\sum_{\\substack{X \\subseteq \\{1, \\dots, m\\} \\\\ \\NoFix(\\sigma) \\subseteq X \\\\ \\left\\lvert X \\right\\rvert = n} }\n\t\t\t\\prod_{i \\in X} -x_{i \\sigma(i)}\n\t\t\t\\right) \\\\\n\t\t\t% -----------------------\n\t\t\t&= \\sum_{n=0}^m\n\t\t\ta^{m-n} (-1)^n\n\t\t\t\\left(\n\t\t\t\\sum_{\\substack{X \\subseteq \\{1, \\dots, m\\} \\\\ \\left\\lvert X \\right\\rvert = n} }\n\t\t\t\\sum_{\\substack{\\sigma \\in S_m \\\\ \\NoFix(\\sigma) \\subseteq X}}\n\t\t\t\\sign(\\sigma) \\prod_{i \\in X} x_{i \\sigma(i)}\n\t\t\t\\right).\n\t\t\\end{align*}\n\n\t\tHence it's the same to show that\n\t\t\\[\n\t\t\t\\sum_{\\substack{X \\subseteq \\{1, \\dots, m\\} \\\\ \\left\\lvert X \\right\\rvert = n} }\n\t\t\t\\sum_{\\substack{\\sigma \\in S_m \\\\ \\NoFix(\\sigma) \\subseteq X}}\n\t\t\t\\sign(\\sigma) \\prod_{i \\in X} x_{i \\sigma(i)}\n\t\t\t= \\Tr_{\\Lambda^n(V)} \\left( \\Lambda^n(T) \\right)\n\t\t\\]\n\t\tholds for every $n$.\n\n\t\tWe can expand the definition of trace as using basis elements as\n\t\t\\begin{align*}\n\t\t\t\\Tr\\left( \\Lambda^n(T) \\right)\n\t\t\t&= \\sum_{1 \\le i_1 < \\dots < i_n \\le m}\n\t\t\t\\left( \\bigwedge_{k=1}^n e_{i_k} \\right)^\\vee\n\t\t\t\\left( \\Lambda^n(T) \\left( \\bigwedge_{k=1}^n e_{i_k} \\right) \\right) \\\\\n\t\t\t&= \\sum_{1 \\le i_1 < \\dots < i_n \\le m}\n\t\t\t\\left( \\bigwedge_{k=1}^n e_{i_k} \\right)^\\vee\n\t\t\t\\left(  \\bigwedge_{k=1}^n T(e_{i_k}) \\right) \\\\\n\t\t\t&= \\sum_{1 \\le i_1 < \\dots < i_n \\le m}\n\t\t\t\\left( \\bigwedge_{k=1}^n e_{i_k} \\right)^\\vee\n\t\t\t\\left(  \\bigwedge_{k=1}^n\n\t\t\t\\left( \\sum_{j=1}^m x_{i_k j} e_j \\right)\n\t\t\t\\right) \\\\\n\t\t\t&= \\sum_{1 \\le i_1 < \\dots < i_n \\le m}\n\t\t\t\\sum_{\\pi \\in S_n} \\sign(\\pi) \\prod_{k=1}^n x_{i_{\\pi(k)}k} \\\\\n\t\t\t&= \\sum_{\\substack{X \\subseteq \\{1,\\dots,m\\} \\\\ \\left\\lvert X \\right\\rvert = n}}\n\t\t\t\\sum_{\\pi \\in S_X} \\sign(\\pi) \\prod_{i \\in X} x_{t \\pi(t)}\n\t\t\\end{align*}\n\t\tHence it remains to show that the permutations over $X$\n\t\tare in bijection with the permutations over $S_m$ which fix $\\{1, \\dots, m\\} - X$,\n\t\twhich is clear, and moreover, the signs clearly coincide.\n\t\\end{sol}\n\\end{problem}\n", "meta": {"hexsha": "e81996686db569ed4f79e4ef480c59c27dad137c", "size": 27106, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/linalg/dets.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/linalg/dets.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/linalg/dets.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.8789115646, "max_line_length": 146, "alphanum_fraction": 0.6451708109, "num_tokens": 10019, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8872046056466901, "lm_q1q2_score": 0.7334625112419395}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[pdftex,pagebackref,colorlinks=true,pdfpagemode=none,urlcolor=blue,linkcolor=blue,citecolor=blue,pdfstartview=FitH]{hyperref}\n\n\\usepackage{amsmath,amsfonts}\n\\usepackage{graphicx}\n\\usepackage{color}\n\\usepackage{hyperref}\n\\usepackage{minted}\n\\usemintedstyle{bw}\n\n\\newcommand{\\homedir}{\\string~}\n\n\\setlength{\\oddsidemargin}{0pt}\n\\setlength{\\evensidemargin}{0pt}\n\\setlength{\\textwidth}{6.0in}\n\\setlength{\\topmargin}{0in}\n\\setlength{\\textheight}{8.5in}\n\n\\setlength{\\parindent}{0in}\n\\setlength{\\parskip}{5px}\n\n\\input{\\homedir/Develop/python/gly.fish/latex2wp/macrosblog.tex}\n\n\\title{Inverse CDF Sampling}\n\\author{Troy Stribling}\n\n\n\\begin{document}\n\n% ------------------------------------------------------------------------------------------------\n% Introduction\n% ------------------------------------------------------------------------------------------------\n\\iftex\n\\maketitle\n\\section{Introduction}\n\\fi\n\nInverse \\href{https://en.wikipedia.org/wiki/Cumulative_distribution_function}{CDF} sampling is a method for obtaining samples\nfrom both discrete and continuous probability distributions\nthat requires the CDF to be invertible. The method assumes values of the CDF are Uniform random variables on [0, 1].\nCDF values are generated and used as input into the inverted CDF to obtain samples with the distribution defined by the CDF.\n\n% ------------------------------------------------------------------------------------------------\n% Sampling discrete distributions\n% ------------------------------------------------------------------------------------------------\n\\ifblog\n<h2>Sampling Discrete Distributions</h2>\n\\fi\n\\iftex\n\\section{Sampling Discrete Distributions}\n\\fi\n\nA discrete probability distribution consisting of a finite set of $N$ probability values is defined by,\n$\\{p_i\\}_N = \\{p_1, p_2,\\ldots,p_N\\}$ with $p_i \\geq 0, \\forall i$ and $\\sum_{i=1}^N{p_i} = 1.$ The CDF specifies the probability\nthat $i \\leq n$ and is given by,\n\\begin{equation}\n\\label{eq:discrete_cdf}\nP(i \\leq n)=P(n)=\\sum_{i=1}^n{p_i},\n\\end{equation}\nwhere $P(N)=1.$\n\nFor a given generated CDF value, $U$, Equation (\\ref{eq:discrete_cdf}) can always be inverted by evaluating it for each $n$ and\nsearching for the value of $n$ that satisfies, $P(n) \\geq U.$ It can be seen that the generated samples will have\ndistribution $\\{p_i\\}_N$ since the intervals $P(n)-P(n-1) = p_n$ are Uniformly sampled.\n\nConsider the example distribution,\n\n\\begin{equation} \n\\left\\{\\frac{1}{12}, \\frac{1}{12}, \\frac{1}{6}, \\frac{1}{6}, \\frac{1}{12}, \\frac{5}{12} \\right\\}\n\\label{eq:discrete}\n\\end{equation}\n\nIt is shown in the following plot with its CDF. Note that the CDF is a monotonically increasing function.\n\n\\ifblog\n\\image{width = 600}{https://gly.fish/wp-content/uploads/posts/inverse-cdf-sampling/discrete_cdf.png}{\\homedir/Develop/python/gly.fish/assets/posts/inverse_cdf_sampling/discrete_cdf.png}\n\\fi\n\\iftex\n\\image{width = 400}{https://gly.fish/wp-content/uploads/posts/inverse-cdf-sampling/discrete_cdf.png}{\\homedir/Develop/python/gly.fish/assets/posts/inverse_cdf_sampling/discrete_cdf.png}\n\\fi\n\nA sampler using the Inverse CDF method on the distribution $\\{p_i\\}_N$ implemented in Python is shown below.\nThe program first stores the CDF computed from each of the sums $P(n)$ in an array. Next,\nCDF samples using $U \\sim \\textbf{Uniform}(0, 1)$ are generated. Finally, for each sampled CDF value, $U$, the array containing $P(n)$\nis scanned for the value of $n$ where $P(n) \\geq U$. The resulting values of $n$ will have the distribution $\\{p_i\\}_N$.\n\n% Sampler code examples\n\\ifblog\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\nimport numpy\n\nn = 10000\ndf = numpy.array([1/12, 1/12, 1/6, 1/6, 1/12, 5/12])\ncdf = numpy.cumsum(df)\n\nsamples = [numpy.flatnonzero(cdf >= u)[0] for u in numpy.random.rand(n)]\n</pre>\n\\fi\n\n\\iftex\n\\pagebreak\n\\begin{minted}[mathescape, frame=lines, framesep=2mm, fontsize=\\footnotesize]{python}\nimport numpy\n\nn = 10000\ndf = numpy.array([1/12, 1/12, 1/6, 1/6, 1/12, 5/12])\ncdf = numpy.cumsum(df)\n\nsamples = [numpy.flatnonzero(cdf >= u)[0] for u in numpy.random.rand(n)]\n\\end{minted}\n\\fi\n\nThe figure below favorably compares generated samples and distribution (\\ref{eq:discrete}),\n\\ifblog\n\\image{width = 600}{https://gly.fish/wp-content/uploads/posts/inverse-cdf-sampling/discrete_sampled_distribution.png}{\\homedir/Develop/python/gly.fish/assets/posts/inverse_cdf_sampling/discrete_sampled_distribution.png}\n\\fi\n\\iftex\n\\image{width = 400}{https://gly.fish/wp-content/uploads/posts/inverse-cdf-sampling/discrete_sampled_distribution.png}{\\homedir/Develop/python/gly.fish/assets/posts/inverse_cdf_sampling/discrete_sampled_distribution.png}\n\\fi\n\n\n% multinomial sampling\n\\ifblog\nIt is also possible to directly sample $\\{p_i\\}_N$ using the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">multinomial</code> sampler from\n<code class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">numpy</code>,\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\nimport numpy\n\nn = 10000\ndf = numpy.array([1/12, 1/12, 1/6, 1/6, 1/12, 5/12])\nsamples = numpy.random.multinomial(n, df, size=1)/n\n</pre>\n\\fi\n\n\\iftex\nIt is also possible to directly sample $\\{p_n\\}$ using the \\mintinline{python}{multinomial} sampler from\n\\mintinline{python}{numpy},\n\n\\begin{minted}[mathescape, frame=lines, framesep=2mm,fontsize=\\footnotesize]{python}\nimport numpy\n\nn = 10000\ndf = numpy.array([1/12, 1/12, 1/6, 1/6, 1/12, 5/12])\nsamples = numpy.random.multinomial(n, df, size=1)/n\n\\end{minted}\n\\fi\n\nThe number of operations required for generating samples using Inverse CDF sampling from a discrete\ndistribution will scale $O(N_{samples}N)$ where $N_{samples}$ is the desired number of samples\nand $N$ is the number of terms in the discrete distribution.\n\n% ------------------------------------------------------------------------------------------------\n% Sampling continuous distributions\n% ------------------------------------------------------------------------------------------------\n\\ifblog\n<h2>Sampling Continuous Distributions</h2>\n\\fi\n\\iftex\n\\section{Sampling Continuous Distributions}\n\\fi\n\nA continuous probability distribution is defined by the  \\href{https://en.wikipedia.org/wiki/Probability_density_function}{PDF},\n$f_X(x)$, where $f_X(x) \\geq 0, \\forall x$ and $\\int f_X(x) dx = 1.$ The CDF is a monotonically increasing function\nthat specifies the probability that $X \\leq x$, namely,\n\\begin{equation}\n\\label{eq:continuous_cdf}\nP(X \\leq x) = F_X(x) = \\int^{x} f_X(w) dw.\n\\end{equation}\n\n% ------------------------------------------------------------------------------------------------\n% Proof continuous distribution\n% ------------------------------------------------------------------------------------------------\n\\ifblog\n<h3>Proof the Inverse CD Sampling Works</h3>\n\\fi\n\\iftex\n\\subsection{Proof that Inverse CD Sampling Works}\n\\fi\n\nTo prove that Inverse CDF sampling works for continuous distributions it must be shown that,\n\n\\begin{equation}\n\\label{eq:continuous_proof}\nP[F_X^{-1}(U) \\leq x] = F_X(x),\n\\end{equation}\n\nwhere $F_X^{-1}(x)$ is the inverse of $F_X(x)$ and $U \\sim \\textbf{Uniform}(0, 1)$.\n\nA more general result needed to complete\nthis proof is obtained using a change of variable on a CDF. If $Y=G(X)$ is a monotonically increasing invertible function\nof $X$ then,\n\n\\begin{equation}\n\\label{eq:CDF_invariance}\nP(X \\leq x) = P(Y \\leq y) = P[G(X) \\leq G(x)].\n\\end{equation}\n\nTo prove this note that $G(x)$ is monotonically increasing so the ordering of values is preserved,\n\n$$ X \\le x \\implies G(X) \\le G(x).$$\n\nConsequently, the order of the integration limits is maintained by the transformation. Further, since $G(x)$ is invertible,\n$x = G^{-1}(y)$ and $dx = \\frac{dG^{-1}}{dy} dy$, so\n\n$$\n\\begin{aligned}\nP(X \\leq x) & = \\int^{x} f_X(w) dw \\\\\n& = \\int^{y} f_X(G^{-1}(z)) \\frac{dG^{-1}}{dz} dz \\\\\n& = \\int^{y} f_Y(z) dz \\\\\n& = P(Y \\leq y) \\\\\n& = P[G(X) \\leq G(x)],\n\\end{aligned}\n$$\n\nwhere,\n\n$$ f_Y(y) = f_X(G^{-1}(y)) \\frac{dG^{-1}}{dy} $$\n\nThe desired proof of Equation (\\ref{eq:continuous_proof}) follows from Equation (\\ref{eq:CDF_invariance}) by noting that\n$U \\sim \\textbf{Uniform}(0, 1)$ so $f_U(u) = 1$,\n\n$$\n\\begin{aligned}\nP[F_X^{-1}(U) \\leq x] & = P[F_X(F_X^{-1}(U)) \\leq F_X(x)] \\\\\n& = P[U \\leq F_X(x)] \\\\\n& = \\int_{0}^{F_X(x)} f_U(w) dw \\\\\n& = \\int_{0}^{F_X(x)} dw \\\\\n& = F_X(x).\n\\end{aligned}\n$$\n\n% ------------------------------------------------------------------------------------------------\n% Example continuous distribution\n% ------------------------------------------------------------------------------------------------\n\\ifblog\n<h3>Example</h3>\n\\fi\n\\iftex\n\\subsection{Example}\n\\fi\n\nConsider the \\href{https://en.wikipedia.org/wiki/Weibull_distribution}{Weibull Distribution}, with density\n\n$$\nf_X(x; k, \\lambda) =\n\\begin{cases}\n\\frac{k}{\\lambda}\\left(\\frac{x}{\\lambda} \\right)^{k-1} e^{\\left(\\frac{-x}{\\lambda}\\right)^k} & x \\geq 0 \\\\\n0 & x < 0,\n\\end{cases}\n$$\n\nwhere $k$ is the shape parameter and $\\lambda$ the scale parameter. The CDF is given by,\n\n$$\nF_X(x; k, \\lambda) =\n\\begin{cases}\n1-e^{\\left(\\frac{-x}{\\lambda}\\right)^k\n} & x \\geq 0 \\\\\n0 & x < 0.\n\\end{cases}\n$$\n\nThe CDF can be inverted to yield,\n\n$$\nF_X^{-1}(u; k, \\lambda) =\n\\begin{cases}\n\\lambda\\ln\\left(\\frac{1}{1-u}\\right)^{\\frac{1}{k}} & 0 \\leq u \\leq 1 \\\\\n0 & u < 0 \\text{ or } u > 1.\n\\end{cases}\n$$\n\nIn the example described here it will be assumed that $k=5.0$ and $\\lambda=1.0$. The following plot shows the PDF and CDF using these values.\n\\ifblog\n\\image{width = 600}{https://gly.fish/wp-content/uploads/posts/inverse-cdf-sampling/weibull_cdf.png}{\\homedir/Develop/python/gly.fish/assets/posts/inverse_cdf_sampling/weibull_cdf.png}\n\\fi\n\\iftex\n\\image{width = 400}{https://gly.fish/wp-content/uploads/posts/inverse-cdf-sampling/weibull_cdf.png}{\\homedir/Develop/python/gly.fish/assets/posts/inverse_cdf_sampling/weibull_cdf.png}\n\\fi\n\nThe sampler implementation for the continuous case is simpler than for the discrete case. Just as in the discrete case\nCDF samples with distribution $U \\sim \\textbf{Uniform}(0, 1)$ are generated. The desired samples with\nthe Weibull distribution are then computed using the CDF inverse. Below an implementation of the sampler in Python is listed.\n\n\\ifblog\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\nimport numpy\n\nk = 5.0\nλ = 1.0\nnsamples = 100000\n\ncdf_inv = lambda u: λ * (numpy.log(1.0/(1.0 - u)))**(1.0/k)\nsamples = [cdf_inv(u) for u in numpy.random.rand(nsamples)]\n</pre>\n\\fi\n\n\\iftex\n\\begin{minted}[mathescape, frame=lines, framesep=2mm,fontsize=\\footnotesize]{python}\nimport numpy\n\nk = 5.0\nl = 1.0\nnsamples = 100000\n\ncdf_inv = lambda u: l * (numpy.log(1.0/(1.0 - u)))**(1.0/k)\nsamples = [cdf_inv(u) for u in numpy.random.rand(nsamples)]\n\\end{minted}\n\\fi\n\nThe following plot compares a histogram of the samples generated by the sampler above. The fit is quite good. The subtle\nasymmetry of the Weibull distribution is captured.\n\n\\ifblog\n\\image{width = 600}{https://gly.fish/wp-content/uploads/posts/inverse-cdf-sampling/weibull_sampled_distribution.png}{\\homedir/Develop/python/gly.fish/assets/posts/inverse_cdf_sampling/weibull_sampled_distribution.png}\n\\fi\n\\iftex\n\\image{width = 400}{https://gly.fish/wp-content/uploads/posts/inverse-cdf-sampling/weibull_sampled_distribution.png}{\\homedir/Develop/python/gly.fish/assets/posts/inverse_cdf_sampling/weibull_sampled_distribution.png}\n\\fi\n\nA measure of convergence of the samples to the target distribution can be obtained by comparing the cumulative\nmoments of the distribution computed from the samples with the value computed analytically. For the Weibull distribution\nthe first and second moments are given by,\n\n$$\n\\begin{aligned}\n\\mu & = \\lambda\\Gamma\\left(1+\\frac{1}{k}\\right) \\\\\n\\sigma^2 & = \\lambda^2\\left[\\Gamma\\left(1+\\frac{2}{k}\\right)-\\left(\\Gamma\\left(1+\\frac{1}{k}\\right)\\right)^2\\right],\n\\end{aligned}\n$$\n\nwhere $\\Gamma(x)$ is the \\href{https://en.wikipedia.org/wiki/Gamma_function}{Gamma function}. The following plots\nperform this comparison. The first shows the convergence of $\\mu$ and the second the convergence of\n$\\sigma$. Within only 1000 samples both $\\mu$ and $\\sigma$ computed from samples is comparable to the analytic value.\n\n\\ifblog\n\\image{width = 600}{https://gly.fish/wp-content/uploads/posts/inverse-cdf-sampling/weibull_sampled_mean_convergence.png}{\\homedir/Develop/python/gly.fish/assets/posts/inverse_cdf_sampling/weibull_sampled_mean_convergence.png}\n\\fi\n\\iftex\n\\image{width = 400}{https://gly.fish/wp-content/uploads/posts/inverse-cdf-sampling/weibull_sampled_mean_convergence.png}{\\homedir/Develop/python/gly.fish/assets/posts/inverse_cdf_sampling/weibull_sampled_mean_convergence.png}\n\\fi\n\n\\ifblog\n\\image{width = 600}{https://gly.fish/wp-content/uploads/posts/inverse-cdf-sampling/weibull_sampled_std_convergence.png}{\\homedir/Develop/python/gly.fish/assets/posts/inverse_cdf_sampling/weibull_sampled_std_convergence.png}\n\\fi\n\\iftex\n\\image{width = 400}{https://gly.fish/wp-content/uploads/posts/inverse-cdf-sampling/weibull_sampled_std_convergence.png}{\\homedir/Develop/python/gly.fish/assets/posts/inverse_cdf_sampling/weibull_sampled_std_convergence.png}\n\\fi\n\n%%------------------------------------------------------------------------------------------------\n% Performance continuous distribution\n% ------------------------------------------------------------------------------------------------\n\\ifblog\n<h3>Performance</h3>\n\\fi\n\\iftex\n\\subsection{Performance}\n\\fi\n\nAny continuous distribution, $f_X(x)$, can be approximated by the discrete distribution,\n$\\left\\{f_X(x_i)\\Delta x_i \\right\\}_N$ for $i=1,2,3,\\ldots,N$, where $\\Delta x_i=(x_{max}-x_{min})/(N-1)$ and\n$x_i = x_{min}+(i-1)\\Delta x_i$. This method has a couple of drawbacks compared to using Inverse CDF sampling on the\ncontinuous distribution. First, a bounded range for the samples must be assumed when in general the range\nof the samples can be unbounded. The Inverse CDF method can sample an unbounded range. Second, the performance for\nsampling a discrete distribution scales $O(N_{samples}N)$ while sampling the continuous distribution scales\n$O(N_{samples})$.\n\n\\end{document}\n", "meta": {"hexsha": "c46ed1aa807e197ae69378c2786d8f7e4c9dd355", "size": 14154, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/posts/inverse_cdf_sampling/inverse_cdf_sampling.tex", "max_stars_repo_name": "glyfish/website", "max_stars_repo_head_hexsha": "9fecdbc8573ee8b46c2a7f9c403ae025016a09d1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assets/posts/inverse_cdf_sampling/inverse_cdf_sampling.tex", "max_issues_repo_name": "glyfish/website", "max_issues_repo_head_hexsha": "9fecdbc8573ee8b46c2a7f9c403ae025016a09d1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assets/posts/inverse_cdf_sampling/inverse_cdf_sampling.tex", "max_forks_repo_name": "glyfish/website", "max_forks_repo_head_hexsha": "9fecdbc8573ee8b46c2a7f9c403ae025016a09d1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2540540541, "max_line_length": 225, "alphanum_fraction": 0.6774056804, "num_tokens": 4106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706733, "lm_q2_score": 0.8872046011730964, "lm_q1q2_score": 0.7334625075435667}}
{"text": "\\section{Equation}\n\n\\subsection{Multi-line Formula}\n\nWhen writing about PDEs, we usually need to write the equations and their initial and/or boundary conditions in one equation, i.e., use only one number for the equation and IC/BC\\@. We will show how to write multi-line formula with the example of heat equation and its solution. The main idea of writing multi-line formula are using \\verb|eqnarray| and \\verb|array| environment.\nHeat Equation.\n\\begin{equation}\n    \\left\\{\\begin{array}{l}\n        \\dfrac{\\partial u}{\\partial t} = a^2 \\dfrac{\\partial^2 u}{\\partial t^2}, t\n        > 0, - \\infty < x < + \\infty \\\\\n        u |_{t = 0} = \\varphi (x) |\n    \\end{array}\\right.\n\\end{equation}\nSolution\n\\begin{eqnarray}\n    u (t, x) & = & \\mathcal{F}^{- 1} \\left[ \\hat{\\varphi} (\\lambda) e^{_{- a^2\n                        \\lambda^2 t}} \\right] \\nonumber\\\\\n    & = & \\mathcal{F}^{- 1} [\\hat{\\varphi} (\\lambda)] \\ast \\mathcal{F}^{- 1}\n    \\left[ e^{_{- a^2 \\lambda^2 t}} \\right] \\nonumber\\\\\n    & = & \\varphi (x) \\ast \\dfrac{1}{2 a \\sqrt{\\pi t}} \\exp \\left( -\n    \\dfrac{x^2}{4 a^2 t} \\right) \\nonumber\\\\\n    & = & \\dfrac{1}{2 a \\sqrt{\\pi t}} \\int_{- \\infty}^{+ \\infty} \\varphi (\\xi)\n    \\exp \\left( - \\dfrac{(x - \\xi)^2}{4 a^2 t} \\right) \\mathrm{d} \\xi\n\\end{eqnarray}\n\n\\subsection{Matrix and determinant}\n\nMatrix and determinant are common in dynamics and continuum mechanics. Here we use the relationship of coordinates vector as an example. The main idea of writing matrix and determinant is \\verb|array| and \\verb|&| symbol.\n\\begin{equation}\n    \\textbf{e}_i = \\sum_{i = 1}^n \\dfrac{1}{H_i} \\dfrac{\\partial r_i}{\\partial\n        x_i} \\textbf{i}_i\n\\end{equation}\nDenote \\(\\textbf{e} = \\{ \\textbf{e}_1, \\textbf{e}_2, \\ldots,\n\\textbf{e}_n \\}\\), \\(\\textbf{i} = \\{ \\textbf{i}_1, \\textbf{i}_2, \\ldots,\n\\textbf{i}_n \\}\\), then\n\\begin{equation}\n    \\textbf{e} = A \\textbf{i}\n\\end{equation}\nwhere\n\\begin{eqnarray}\n    A & = & \\left(\\begin{array}{cccc}\n        \\dfrac{1}{H_1} \\dfrac{\\partial r_1}{\\partial x_1} & \\dfrac{1}{H_1}\n        \\dfrac{\\partial r_2}{\\partial x_1}                & \\cdots         & \\dfrac{1}{H_1} \\dfrac{\\partial\n            r_n}{\\partial x_1}                                                                                               \\\\\n        \\dfrac{1}{H_2} \\dfrac{\\partial r_1}{\\partial x_2} & \\dfrac{1}{H_2}\n        \\dfrac{\\partial r_2}{\\partial x_2}                &                &                                                 \\\\\n        \\vdots                                            &                & \\ddots                         &                \\\\\n        \\dfrac{1}{H_n} \\dfrac{\\partial r_1}{\\partial x_n} &                &                                & \\dfrac{1}{H_n}\n        \\dfrac{\\partial r_n}{\\partial x_n}\n    \\end{array}\\right)\n\\end{eqnarray}\nand\n\\begin{eqnarray}\n    \\det A & = & \\left|\\begin{array}{cccc}\n        \\dfrac{1}{H_1} \\dfrac{\\partial r_1}{\\partial x_1} & \\dfrac{1}{H_1}\n        \\dfrac{\\partial r_2}{\\partial x_1}                & \\cdots         & \\dfrac{1}{H_1} \\dfrac{\\partial\n            r_n}{\\partial x_1}                                                                                               \\\\\n        \\dfrac{1}{H_2} \\dfrac{\\partial r_1}{\\partial x_2} & \\dfrac{1}{H_2}\n        \\dfrac{\\partial r_2}{\\partial x_2}                &                &                                                 \\\\\n        \\vdots                                            &                & \\ddots                         &                \\\\\n        \\dfrac{1}{H_n} \\dfrac{\\partial r_1}{\\partial x_n} &                &                                & \\dfrac{1}{H_n}\n        \\dfrac{\\partial r_n}{\\partial x_n}\n    \\end{array}\\right|\n\\end{eqnarray}\n\n\\subsection{Differential Symbol}\n\nIntegral is common in equations and formula. The \\verb|d| symbol is very tricky. It should not be italic and should be separated from the integrand by a space. We can use the command \\verb|\\dif| in package \\verb|commath| to write \\verb|d| correctly.\n\n\\begin{eqnarray}\n    \\int_0^1 x dx = \\frac{1}{2}x^2 \\Bigg|_0^1 = \\frac{1}{2}\\\\\n    \\int_0^1 x \\mathrm{d}x = \\frac{1}{2}x^2 \\Bigg|_0^1 = \\frac{1}{2}\\\\\n    \\int_0^1 x \\dif x = \\frac{1}{2}x^2 \\Bigg|_0^1 = \\frac{1}{2}\n\\end{eqnarray}\n\n\\subsection{Tensor Scripts}\n\nHere are two different approach to write subscript and superscript for a tensor or operator symbol. For general purpose\n\\begin{equation}\n    \\prescript{a}{b}{C}_{d}^{c}\n\\end{equation}\n, or use package \\verb|Tensor|\n\\begin{eqnarray}\n    M\\indices{^a_b^{cd}_e}\\\\\n    \\tensor[^a_b^c_d]{M}{^a_b^c_d}\n\\end{eqnarray}\n", "meta": {"hexsha": "6f125779e958f1b914552aae4c6a4cd3d5999338", "size": 4557, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "zq_latex_workshop/scripts/equation.tex", "max_stars_repo_name": "circlelq/LaTeX-Lecture", "max_stars_repo_head_hexsha": "f0e280e583984e08d4ceb07f7c8769cc5f337289", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-05-04T17:54:03.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-19T04:58:02.000Z", "max_issues_repo_path": "zq_latex_workshop/scripts/equation.tex", "max_issues_repo_name": "circlelq/LaTeX-Lecture", "max_issues_repo_head_hexsha": "f0e280e583984e08d4ceb07f7c8769cc5f337289", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "zq_latex_workshop/scripts/equation.tex", "max_forks_repo_name": "circlelq/LaTeX-Lecture", "max_forks_repo_head_hexsha": "f0e280e583984e08d4ceb07f7c8769cc5f337289", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-05-24T18:06:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T04:58:03.000Z", "avg_line_length": 52.3793103448, "max_line_length": 378, "alphanum_fraction": 0.5233706386, "num_tokens": 1497, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7334624951261431}}
{"text": "\\section{PI in the class}\n\\subsection{}\n\n\\begin{frame}\n\\frametitleTC{Transfer function}\n\\framesubtitleTC{}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item Let us reload our systems theory knowledge:\n       \\begin{displaymath}\n        \\left\\{\\begin{array}{rcl}\n         u_P(k) &=& K_P \\, e(k) \\\\\n         u_I(k) &=& u_I(k-1)+ K_I e(k) \\\\\n         u(k)   &=& u_P(k)+u_I(k)\n        \\end{array}\\right. \\quad\n        {\\Rightarrow} \\quad\n        \\left\\{\\begin{array}{rcl}\n         zu_I(k) &=& u_I(k) + zK_I e(k) \\\\\n         u(k)    &=& u_I(k) + K_P \\, e(k)\n        \\end{array}\\right.\n       \\end{displaymath}\n \\item Hence\n       \\begin{displaymath}\n        u(k) = \\left( \\frac{z}{z-1}K_I + K_P \\right) e(k)\n       \\end{displaymath}\n \\item and finally\n       \\begin{displaymath}\n        C_{PI}(z) = \\frac{u(k)}{e(k)} = \\frac{(K_P+K_I)z-K_P}{z-1},\n       \\end{displaymath}\n       with one zero and one pole in $z=1$, the latter produced by the\\\\\n       integral action.\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Transfer function}\n\\framesubtitleTC{}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item Reformulating we get\n       \\begin{displaymath}\n        C_{PI}(z) = \\frac{(K_P+K_I)z-K_P}{z-1}\n                  = \\left( K_P+K_I \\right) \\frac{z-\\frac{K_P}{K_P+K_I}}{z-1}\n       \\end{displaymath}\n \\item that is, the compact expression\n       \\begin{displaymath}\n        C_{PI}(z) = K \\frac{z-\\zeta}{z-1}, \\qquad\n        K         = K_P+K_I, \\quad\n        \\zeta     = \\frac{K_P}{K_P+K_I}.\n       \\end{displaymath}\n       that is well suited for a cancellation-based tuning policy like direct\\\\\n       synthesis.\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{When is PI control advisable?}\n\\framesubtitleTC{}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item When the process is \\TC{dominantly} first-order, i.e., when its step response is well approximated\n       by $\\mu(1-p^k)$.\n \\item In that case we know that $P(z)=\\mu/(z-p)$ is a good model, and if we want e.g.\n       $G_{yw}^{\\circ}(z)=(1-\\alpha)/(z-\\alpha)$ we can first determine a desired loop transfer function\n       \\begin{displaymath}\n        L^{\\circ}(z) = \\frac{G_{yw}^{\\circ}(z)}{1-G_{yw}^{\\circ}(z)}\n                     = \\frac{\\frac{1-\\alpha}{z-\\alpha}}{1-\\frac{1-\\alpha}{z-\\alpha}}\n                     = \\frac{1-\\alpha}{z-1}\n       \\end{displaymath}\n \\item Then we determine the controller (which we know to be structurally a PI) as\n       \\begin{displaymath}\n        C(z) = \\frac{L^{\\circ}(z)}{P(z)} = \\frac{1-\\alpha}{z-1}\\,\\frac{z-p}{\\mu}\n       \\end{displaymath}\n \\item[] readily obtaining its parameters\n       \\begin{displaymath}\n        \\zeta = p, \\quad\n        K     = \\frac{1-\\alpha}{\\mu}.\n       \\end{displaymath}\n \\end{itemize}\n\\end{frame}\n", "meta": {"hexsha": "2ca8482d2c40e334e845e888341849a328d847f7", "size": 2735, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/Unit-05/sections/06-PS02-PIinClass.tex", "max_stars_repo_name": "albertoleva/PID4CSE", "max_stars_repo_head_hexsha": "66ec14c204e16c97a5792c2e240b2daed4b39e83", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-19T16:38:10.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-19T16:38:10.000Z", "max_issues_repo_path": "slides/Unit-05/sections/06-PS02-PIinClass.tex", "max_issues_repo_name": "albertoleva/PID4CSE", "max_issues_repo_head_hexsha": "66ec14c204e16c97a5792c2e240b2daed4b39e83", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slides/Unit-05/sections/06-PS02-PIinClass.tex", "max_forks_repo_name": "albertoleva/PID4CSE", "max_forks_repo_head_hexsha": "66ec14c204e16c97a5792c2e240b2daed4b39e83", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7654320988, "max_line_length": 105, "alphanum_fraction": 0.5652650823, "num_tokens": 933, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347107, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7334624932321995}}
{"text": "\\section*{Exercises}\n\n\\begin{ex} The following are the cylindrical coordinates of points, $(\nr,\\theta,z)$. Find the Cartesian and spherical coordinates of each point.\n\n\\begin{enumerate}\n\\item $\\paren{5,\\frac{5\\pi }{6},-3} $\n\n\\item $\\paren{3,\\frac{\\pi }{3},4} $\n\n\\item $\\paren{4,\\frac{2\\pi }{3},1} $\n\n\\item $\\paren{2,\\frac{3\\pi }{4},-2} $\n\n\\item $\\paren{3,\\frac{3\\pi }{2},-1} $\n\n\\item $\\paren{8,\\frac{11\\pi }{6},-11} $\n\\end{enumerate}\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} The following are the Cartesian coordinates of points, $(\nx,y,z)$. Find the cylindrical and spherical coordinates of these\npoints.\n\n\\begin{enumerate}\n\\item $\\paren{\\frac{5}{2}\\sqrt{2},\\frac{5}{2}\\sqrt{2},-3} $\n\n\\item $\\paren{\\frac{3}{2},\\frac{3}{2}\\sqrt{3},2} $\n\n\\item $\\paren{-\\frac{5}{2}\\sqrt{2},\\frac{5}{2}\\sqrt{2},11} $\n\n\\item $\\paren{-\\frac{5}{2},\\frac{5}{2}\\sqrt{3},23} $\n\n\\item $(-\\sqrt{3},-1,-5) $\n\n\\item $\\paren{\\frac{3}{2},-\\frac{3}{2}\\sqrt{3},-7} $\n\n\\item $(\\sqrt{2},\\sqrt{6},2\\sqrt{2}) $\n\n\\item $\\paren{-\\frac{1}{2}\\sqrt{3},\\frac{3}{2},1} $\n\n\\item $\\paren{-\\frac{3}{4}\\sqrt{2},\\frac{3}{4}\\sqrt{2},-\\frac{3}{2}\\sqrt{3}} $\n\n\\item $(-\\sqrt{3},1,2\\sqrt{3}) $\n\n\\item $\\paren{-\\frac{1}{4}\\sqrt{2},\\frac{1}{4}\\sqrt{6},-\\frac{1}{2}\\sqrt{2}} $\n\\end{enumerate}\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nThe following are spherical coordinates of points in the form $(\n\\rho,\\phi,\\theta)$. Find the Cartesian and cylindrical\ncoordinates of each point.\n\n\\begin{enumerate}\n\\item $\\paren{4,\\frac{\\pi }{4},\\frac{5\\pi }{6}} $\n\n\\item $\\paren{2,\\frac{\\pi }{3},\\frac{2\\pi }{3}} $\n\n\\item $\\paren{3,\\frac{5\\pi }{6},\\frac{3\\pi }{2}} $\n\n\\item $\\paren{4,\\frac{\\pi }{2},\\frac{7\\pi }{4}} $\n\n\\item $\\paren{4,\\frac{2\\pi }{3},\\frac{\\pi }{6}} $\n\n\\item $\\paren{4,\\frac{3\\pi }{4},\\frac{5\\pi }{3}} $\n\\end{enumerate}\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Describe the surface $\\phi =\\pi\n/4$ in Cartesian coordinates, where $\\phi $ is the polar angle in spherical coordinates.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Describe the surface $\\theta =\\pi /4$ in spherical coordinates, where $\\theta $ is\nthe angle measured from the positive $x$ axis.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Describe the surface $r=5$ in Cartesian coordinates, where\n$r$ is one of the cylindrical coordinates.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Describe the surface $\\rho =4$ in Cartesian coordinates,\nwhere $\\rho $ is the distance to the origin.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Give the cone described by $z=\\sqrt{x^{2}+y^{2}}$ in cylindrical coordinates and\nin spherical coordinates.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} The following are described in Cartesian coordinates. Rewrite them in terms of spherical coordinates.\n\n\\begin{enumerate}\n\\item $z=x^{2}+y^{2}$.\n\n\\item $x^{2}-y^{2}=1$.\n\n\\item $z^{2}+x^{2}+y^{2}=6$.\n\n\\item $z=\\sqrt{x^{2}+y^{2}}$.\n\n\\item $y=x$.\n\n\\item $z=x$.\n\\end{enumerate}\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} The following are described in Cartesian coordinates. Rewrite them in terms of cylindrical coordinates.\n\n\\begin{enumerate}\n\\item $z=x^{2}+y^{2}$.\n\n\\item $x^{2}-y^{2}=1$.\n\n\\item $z^{2}+x^{2}+y^{2}=6$.\n\n\\item $z=\\sqrt{x^{2}+y^{2}}$.\n\n\\item $y=x$.\n\n\\item $z=x$.\n\\end{enumerate}\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "7dcc0f9e96e8c16df571cad2bcddc179547a1fc3", "size": 3235, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/exercises/Curvilinear-CylindricalSpherical.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/exercises/Curvilinear-CylindricalSpherical.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/exercises/Curvilinear-CylindricalSpherical.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 22.4652777778, "max_line_length": 114, "alphanum_fraction": 0.6200927357, "num_tokens": 1230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8872045907347108, "lm_q1q2_score": 0.7334624913382559}}
{"text": "\\chapter{February}\n\n\\section{Standard deviation} \\index{Standard deviation}\n\\textbf{Standard deviation} $\\sigma$ is defined as the square root of \\textbf{variance}. That is,\n\\begin{align}\n\t\\sigma(X) &= \\sqrt{var(X)}\n\\end{align}\nThe definition for variance:\n\\begin{align}\nvar(X) = E[(X - \\mu_X)^2]\n\\end{align}\nThe definition for \\textbf{covariance}:\n\\begin{align}\ncov(X,Y) = E[(X - \\mu_X)(Y- \\mu_Y)]\n\\end{align}\nA property:\n\\begin{align}\n\tcov(X,X) = var(X) = \\sigma(X)^2 \n\\end{align}\nDefinition for \\textbf{correlation}:\n\\begin{align}\n\t\\begin{split}\n\t\\rho(X,Y) & = corr(X, Y) \t\t\\\\\n\t\t\t  & = \\frac{cov(X,Y)}{\\sigma_X \\sigma_Y}\n\t\\end{split}\n\\end{align}\n\n\n\\section{Determinant}\\index{Determinant}\nToday when I try to compute the determinant of the covariance matrix in the multivariate Gaussian, I come across the problem of overflow. In fact, I only\nneed to know the logarithm of the determinant. Therefore, I apply the following solution:\n\\begin{align}\n\t\\begin{split}\n\t\\log(\\det A) &= \\log(\\Pi_{i=1}^{N} \\lambda_i)  \\\\\n\t\t\t\t & = \\sum_{i=1}^{N} \\log(\\lambda_i)\n\t\\end{split}\n\\end{align}\n\n\\section{Matplotlib}\\index{Matplotlib}\nSample code to plot figures with Python:\n\n\\begin{minted}[frame=lines, framesep=2mm,]\n\t       {python}\nx = np.linspace(-10, 4, 500, endpoint=True)\ny = (3 * x + 12) / 4\n\nfig = plt.figure()\nfig.suptitle('Problem 3', fontsize=20, fontweight='bold')\nax = fig.add_subplot(111)\nax.plot(x, y)\n\nax.spines['right'].set_color('none')\nax.spines['top'].set_color('none')\nax.xaxis.set_ticks_position('bottom')\nax.spines['bottom'].set_position(('data',0))\nax.yaxis.set_ticks_position('left')\nax.spines['left'].set_position(('data',0))\n\nplt.annotate(r'$(-4,0)$',\nxy=(-4, 0), xycoords='data',\nxytext=(-20, +60), textcoords='offset points', fontsize=16,\narrowprops=dict(arrowstyle=\"->\", connectionstyle=\"arc3,rad=.2\"))\n\nplt.annotate(r'$(0,3)$',\nxy=(0, 3), xycoords='data',\nxytext=(+10, -30), textcoords='offset points', fontsize=16,\narrowprops=dict(arrowstyle=\"->\", connectionstyle=\"arc3,rad=.2\"))\n\nplt.annotate(r'positive',\nxy=(-6, 2), xycoords='data',\nxytext=(+10, +30), textcoords='offset points', fontsize=16)\n\nax.set_xlabel(\"x\")\nax.set_ylabel(\"y\")\n\nplt.savefig('3.png', dpi = 100)\nplt.show()\n\\end{minted}\n\n\\section{Different types of machine learning methods:}\n\\begin{enumerate}\n\\item \\textbf{Parametric methods}: a family of distributions that can be described using a finite \nnumber of paramters, such as \\textit{GMM, Naive Bayes, SVM}.\n\\item \\textbf{Non-parametric methods}: methods that are not based on parametrized families of\nprobability distributions, such as \\textit{decision trees, KNN}. \n\\end{enumerate}\n\nThe difference between parametric models and non-parametric models is that the former \nhas a fixed number of parameters, while the latter grows the number of parameters with \nthe amount of training data.\n\\begin{remark}\nNote that the non-parametric model does not have no parameters: parameters are determined by the training data, not the model.\n\\end{remark}\n\nParametric models can also be categorized into \\textbf{generative models} and \n\\textbf{discriminative models}.\n\\begin{enumerate}\n\\item Generative models: Fit a probability distribution like a multivariate Gaussian to each class.\n\\item Approximate the boundaries between classes by simple functions.\n\\end{enumerate}\n\n\\section{Representation Learning}\n\n\n\\paragraph{Dimensionality Reduction and Denoising}\nGiven data in high-dimensional Euclidean space, project to a\nlow-dimensional linear subspace while retaining as much of the\nsignal as possible. \n\n\\paragraph{Embedding and manifold learning}\nGiven data that lie in a non-Euclidean space, find an embedding into\nEuclidean space that preserves as much of the geometry as possible.\n\n\\paragraph{Metric learning}\nA metric $d$ should satisfy the following properties:\n\\begin{enumerate}\n\t\\item $d(x, y) \\geq 0$, non-negativity\n\t\\item $d(x, y) = 0$ if and only if $x = y$\n\t\\item $d(x, y) = d(y, x)$, symmetry\n\t\\item $d(x, z) \\leq d(x, y) + d(y, z)$, triangle inequality\n\\end{enumerate}\n\n\\section{Fast Nearest Neighbor Search}\n\\textbf{Locality sensitive hashing.}\\hspace{0.2cm} Grouping points in space into \\textit{buckets} based on some distance metric operating on the points. Points that are close to each other under the chosen metric are mapped to the same bucket with high probability.\n\n\\textbf{K-d tress.}\\hspace{0.2cm} A space-partitioning data structure for organizing points in a k-dimensional space.\n\n\\begin{remark}\n\tNearest neighbor is sensitive to noise.\n\\end{remark}\n\n\\section{Decision Trees}\n\\textbf{Node split.}\\hspace{0.2cm} When to split a node, we need to decide which \nnode to split. We have the following methods to measure the \\textbf{uncertainty in prediction} $u(S)$:\n\\begin{itemize}\n\t\\item \\textit{Misclassification rate}: $min(p, 1-p)$, where $p$ is the fraction of positive points.\n\t\\item \\textit{Gini index}: $2p(1-p)$\n\t\\item \\textit{Entropy}: $-p\\log p - (1-p)\\log(1-p)$\n\\end{itemize}\nWe select the node split that can mostly reduce uncertainty (see Figure~\\ref{fig:feb-dt-split}).\n\\begin{figure}[h]\n\t\\centering{\n\t\t\\includegraphics[width = 0.9\\textwidth]{./images/feb/dt_split.PNG}\n\t}\n\t\\label{fig:feb-dt-split}\n\t\\caption{Benefit of a split.}\n\\end{figure} \n\n\n\\textbf{When to stop?}\\hspace{0.2cm} Keep splitting until leaves are pure. \n\n\\textbf{Pruning.}\\hspace{0.2cm} After split stops, we do pruning to avoid over-fitting. Consider all pairs of leave nodes,\nany pair whose elimination yields a satisfactory (small)\nincrease in impurity is eliminated, and the common\nantecedent node is declared as leaf node.\n\n\\section{Classification with generative models}\n\n\\textbf{Bayes-optimal prediction.}\\hspace{0.2cm}\n\\begin{align}\n\t\\begin{split}\n\tPr(y= j | x) &= \\frac{Pr(y= j) Pr(x|y=j)}{Pr(x)} \\\\\n\t\t&= \\frac{\\pi_j P_j(x)}{\\sum_{i=1}^{k} \\pi_i P_i(x)}\n\t\\end{split}\n\\end{align}\n\n\n\\textbf{Laplace smoothing.}\\hspace{0.2cm}\nWe want to estimate $p_{ji} = Pr(x_i = 1 | y=j)$. Then the maximum likelihood estimate of $p_{ji}$ is $p_{ij} = \\frac{n_{ji}}{n_j}$, where $n_{ji}$ is the number of instances of class $j$ with $x_i = 1$, and $n_j$ is the number of \ninstances of class $j$. \n\\begin{remark}\nThis causes the problem if $n_{ji} = 0$. Instead, we use \\textit{Laplace smoothing}: $p_{ji} = \\frac{n_{ji} + 1}{n_j + 2}$\n\\end{remark} \n\n\n\\textbf{Multinomial naive Bayes.}\\hspace{0.2cm}\nClassify document $x$ as $\\argmax_j \\pi_j \\prod_{i=1}^{N} p_{ji} ^ {x_i}$.\nTo improve the performance, we may adopt the following heuristics:\n\\begin{itemize}\n\t\\item Compensating for burstiness. Problem: once a word has appeared in a document, it has a much higher chance of appearing again.\n\tSolution: Instead of the number of occurrences $f$ of a word, use\n\t$\\log(1 + f )$.\n\t\n\t\\item Downweighting common words. Problem: common words can have a unduly large influence on classification. Solution: weight each word $w$ by \\textit{inverse document frequency}:\n\t\\[\n\t\t\\log\\frac{\\# \\text{docs}}{\\#(\\text{docs containing w})}\n\t\\]\n\\end{itemize}\n\n\\section{Gaussian}\n\\textbf{Multivariate Gaussian.}\\hspace{0.2cm} mean: $\\mu \\in R^p$. covariance $p\\times p$\nmatrix $\\sum$:\n\\begin{align}\n\\begin{split}\n\tp(x) &= \\frac{1}{(2\\pi)^{p/2} |\\sum|^{1/2}} \\exp(-\\frac{1}{2} (x-\\mu)^T \\sum {}^{-1} (x-\\mu))\n\\end{split}\n\\end{align}\n\n\n\\textbf{Spherical Gaussian.}\\hspace{0.2cm} $\\sum = diag(\\sigma^2, ..., \\sigma^2)$\n\nHere we call it \\textit{spherical Gaussian} because the contour of points with equal density is a sphere:\n\\begin{align}\n\\begin{split}\n||x - \\mu||^2 &= r^2\n\\end{split}\n\\end{align}\n\n\\begin{figure}[h]\n\\centering{\n\t\\includegraphics{./images/feb/sg.PNG}\n}\n\\caption{The contour means that points on it have the same density. For spherical Gaussians, density at a point only depends on its distance from $\\mu$.}\n\\end{figure}\n\n\n\n\n\n\\textbf{Diagonal Gaussian.}\\hspace{0.2cm} $\\sum = diag(\\sigma_1^2, ..., \\sigma_p^2)$\n\n\\begin{figure}[h]\n\t\\centering{\n\t\t\\includegraphics[width=0.9\\textwidth]{./images/feb/dg.PNG}\n\t}\n\t\\caption{Diagonal Gaussian: the contours are axis-aligned ellipsoids.}\n\\end{figure}\n\n\\myheader{General Gaussian .}\n\n\\begin{figure}[h]\n\t\\centering{\n\t\t\\includegraphics[width=0.9\\textwidth]{./images/feb/gg.PNG}\n\t}\n\t\\caption{General Gaussian: the contours are ellipsoids, with axis being the eigen-vectors\n\t\tof covariance matrix $\\sum$.}\n\\end{figure}\n\n\\myheader{Binary classifications with Gaussians}\nSuppose we have two Gaussians:\n\\begin{align}\n\\begin{split}\n\tP_1 &= N(\\mu_1, \\sum{}_1) \\\\\n\tP_2 &= N(\\mu_2, \\sum{}_2)\n\\end{split}\n\\end{align}\n\nThe classification boundary is:\n\\begin{align}\n\\begin{split}\n\tx^T M x + 2w^Tx & \\geq \\theta\t\\\\\n\t\\text{where } M & = \\frac{1}{2}(\\sum{}_2^{-1} - \\sum{}_{1}^{-1}) \\\\\n\t\t\t\tw & = \\sum{}_1^{-1} \\mu_1 - \\sum{}_{2}^{-1}\\mu_2\n\\end{split}\n\\end{align}\n\\begin{remark}\n\tFrom this we know that, when $\\sum_1 = \\sum_2$, it has a linear decision boundary. Otherwise, it has quadratic boundary.\n\\end{remark}\n\n\\begin{remark}\n\tWhen calculate the inverse of covariance matrix $\\sum$, to avoid the problem that $\\sum$ \n\tis singular, we need to regularize it: $\\sum = \\sum + \\sigma^2 I$.\n\\end{remark}\n\n\n\\section{New commands in LaTex}\n\\begin{minted}[frame=lines, framesep=2mm,]\n{cpp}\n\\newcommand{\\plusbinomial}[3][2]{(#2 + #3)^#1}\n\nTo save some time when writing too many expressions \nwith exponents is by defining a new command to make simpler:\n\n\\[ \\plusbinomial{x}{y} \\] -> $(x+y)^2$\n\nAnd even the exponent can be changed\n\n\\[ \\plusbinomial[4]{y}{y} \\] -> $(y+y)^4$\n\n\\plusbinomial\nThis is the name of the new command.\n[3]\nThe number of parameters the command will take, in this case 3.\n\n[2]\nIs the default value for the first parameter. This is what makes the first\n parameter optional, if not passed it will use this default value.\n\n(#2 + #3)^#1\nThis is what the command does. In this case it will put the second and third\nparameters in a \"binomial format\" to the power represented by the first\nparameter.\n\\end{minted}\n\n\n\\section{OpenGL}\n\n\\subsection{Window Management in OpenGL .}\nThe OpenGL doesn't specify any API in order to create and manipulate windows. Modern windowing systems that support OpenGL include a sub-system that provides the binding between an OpenGL context and the windowing system. The library we use here is called \\textit{OpenGL utility library}, or \\textit{GLUT}. It provides a simplified API for window mangement as well \nas envent handling, IO control and few other services.\n\n\\myheader{State in OpenGL .}\nRendering is such a complex tas that it cannot be treated as a function call that receives a few paramters,\nand correctly designed functions never receive a lot of parameters. You need to specify a lot of flags that affect\nhow rendering will take place. In addition, you would often want to keep the same piece of configuration across \nseveral rendering operations.  \\textbf{That is why most of the configuration of rendering operations is done by setting\nflags and values in the OpenGL state machine. After calling a state changing function that particular configuration\nremains intact until the next call to the same function with a different value}.\n\n\\myheader{glutMainLoop .}\nThis call passes control to GLUT which now begins its own internal loop. In this loop it listens to events from \nthe windowing system and passes them via callbacks that we configured.\n\n\\subsection{Hello dot}\n\\myheader{GLEW .} GLEW is short for \\textbf{OpenGL Extension Wrangler Library}. GLEW helps you deal with\nheadache that can accompany the management of extensions in OpenGL.\n\t\t\t\n\\myheader{Vertex buffer objects .} VBOs are used to store vertices. They are the most efficient\nway to load vertices into the GPU. The are buffers that can be stored in video memory and provide\nthe shortest access time to the GPU so they are definitely recommended.\n\n\\myheader{Rasterizer .} Rasterizer maps coordinates to screen space. And finally it draws the\nprimitives according to the topology which is specified in the draw call.\n\n\\begin{minted}[frame=lines, framesep=2mm,]\n{cpp}\nVector3f Vertices[1];\nVertices[0] = Vector3f(0.0f, 0.0f, 0.0f);\nGLuint VBO;\nglGenBuffers(1, & VBO);\nglBindBuffer(GL_ARRAY_BUFFER, VBO);\nglBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);\nglEnableVertexAttribArray(0);\n\\end{minted}\n\n\\myheader{glGen* .} \nOpenGL defines serveral \\textit{glGen*} functions for generating objects of various\ntypes. They take two parameters:\n\\begin{itemize}\n\t\\item First parameter: the number of objects you want to create\n\t\\item Second parameter: the address of an array of GLuints to store the handles that the driver\n\tallocates for you (make sure the array is large enough to handle your request). Future calls to this function will not generate the same object handles unless you delete them first with glDeleteBuffers.\n\\end{itemize} \n\n\\myheader{Handles .} \nIn computer programming, a handle is an abstract reference to a resource. Handles are usually \nused when application software references blocks of memory or objects managed by another\nsystem, such as database or an operating system.\n \n\n\n\n\n\\section{Fisher's Linear Discriminant}\n\\myheader{What is Fisher LDA ?} Fisher LAD is a framework for linear classification without Gaussian assumptions. It is a linear classifier projects all data onto a direction $w$.\n\n\\begin{figure}[h]\n\t\\centering{\n\t\t\\includegraphics[width=0.45\\textwidth]{./images/feb/LDA_1.PNG}\n\t\t\\includegraphics[width=0.45\\textwidth]{./images/feb/LDA_2.PNG}\t\n\t}\n\t\\caption{Fisher LDA.}\n\\end{figure}\n\n\\section{Logistic Regression}\n\\myheader{Why Logistic Regression ?} See Figure~\\ref{fig:logistic}.\n\\begin{figure}[t]\n\t\\centering{\n\t\t\\includegraphics[width=0.45\\textwidth]{./images/feb/logistic.PNG}\n\t\t\\includegraphics[width=0.45\\textwidth]{./images/feb/logistic_1.PNG}\t\n\t}\n\t\\caption{Logistic regression.}\n\t\\label{fig:logistic}\n\\end{figure}\n\n\\myheader{How to optimize $L(w)$ ?}\n\\begin{itemize}\n\\item \\myheader{Gradient descent .} Gradient descent is a first-order optimization algorithm. To find a local minimum of a function using gradient descent, one takes steps proportional to the \\textbf{negative} of the gradient (or of the approximate gradient) of the function at the current point. If instead one takes steps proportional to the positive of the gradient, one approaches a local maximum of that function; the procedure is then known as gradient ascent.\n\n\\item \\myheader{Newton's method .} Newton's method is a method for finding successively better approximations to the roots (or zeroes) of a real-valued function: $f(x) = 0$. If the function satisfies the assumptions made in the derivation of the formula and the initial guess is close, then a better approximation $x_1$ is: $x_1 = x_0 - \\frac{f(x_0)}{f'(x_0)}$.\n\nTo apply Newton's method for minimization and maximization problem, considering the fact that the derivative is zero at a minimum or maximum, so minima and maxima can be found by applying Newton's method to the derivative. The iteration becomes:\n\\[\nx_{n+1} = x_n - \\frac{f'(x_n)}{f''(x_n)}\n\\]\n\\end{itemize}\n\n\\myheader{How to determine step size ?} A method like Newton's method chooses a step, but the validity of that step only goes as far as the Newton quadratic model for the function really reflects the function. The idea of a line search is to use the direction of the chosen step, but to control the length, by solving a one-dimensional problem of minimizing\n\\[\n\\phi(\\alpha) = f(\\alpha p_k + x_k)\n\\]\nwhere $p_k$ is is the search direction chosen from the position $x_k$.\n\n\\myheader{Backtracking line search .} \nFirst, fix a parameter $0 < \\beta < 1, 0 < \\alpha < 0.5$, then at each iteration, start with $t = 1$, and while \n\\myequ{\n\tf(x - \\nabla f(x)) &> f(x) -  \\alpha t||\\nabla f(x)||^2\n}\nupdate $t = \\beta t$. \n\n\n\\section{Matrix Calculus}\n\\myheader{First order derivatives}\n\\myequ{\n\t\\frac{\\partial AX}{\\partial X} & = A^T \\\\\n\t\\frac{\\partial X^T a}{\\partial X} &= a \\\\\n\t\\frac{\\partial a^T X b}{\\partial X} &= ab^T \\\\\n\t\\frac{\\partial a^T X^T b}{\\partial X} &= ba^T\n}\n\n\\myheader{Jacobian matrix and Hessian matrix}\nJacobian matrix is the matrix of all \\textbf{first-order partial derivatives} of a vector-valued function.\nHessian matrix is a square matrix of \\textbf{second-order partial derivatives} of a scalar-valued function, or scalar field.\n\n\\section{Feature scaling}\nFeature scaling is a method used to standardize the range of independent variables or features of data. In data processing, it is also known as data normalization and is generally performed during the data preprocessing step.\n\n\\myequ{\n\tx' &= \\frac{x - \\min(x)}{\\max(x) - \\min(x)}\t\n}\n\nSince the range of values of raw data varies widely, in some machine learning algorithms, objective functions will not work properly without normalization. For example, the majority of classifiers calculate the distance between two points by the Euclidean distance. If one of the features has a broad range of values, the distance will be governed by this particular feature. Therefore, the range of all features should be normalized so that each feature contributes approximately proportionately to the final distance.\n\nAnother reason why feature scaling is applied is that gradient descent converges much faster with feature scaling than without it.\n\n\\section{Likelihood function}\nA likelihood function is a function of the parameters of a statistical model. The likelihood\nof a set of parameters values $\\theta$, given outcomes $x$, is equal to the probability of those\noutcomes given those parameter values, that is,\n\\myequ{\n\t\\ell (\\theta | x) &= P(x  | \\theta)\n}\n\nFor many applications, the natural logarithm of the likelihood function, called \n\\textbf{log-likelihood} is more convenient to work with.\n\n\\section{Keyword Static in Programming}\nThe keyword \\verb|static| has multiple uses in programming:\n\\begin{itemize}\n\t\\item Use \\verb|static| inside a function: it means that once the variable\n\thas been initialized, it remains in memory until \\textit{the end of the program}.\n\\begin{minted}[frame=lines, framesep=2mm,tabsize=4]{cpp}\n#include <stdio.h>\t\nvoid func() {\n  \tstatic int x = 0;\n  \tx++;\n  \tprintf(\"%d\\n\", x); \n}\n\nint main() {\n\tfunc(); // prints 1\n\tfunc(); // prints 2\n\tfunc(); // prints 3\n\tfunc(); // prints 4\n\tfunc(); // prints 5\n\treturn 0;\n}\n\\end{minted}\n\n\t\\item Use \\verb|static| inside a loop to prevent it from being reinitialized\n\tinside a loop\n\\begin{minted}[frame=lines, framesep=2mm,tabsize=4]{cpp}\nfor(int x=0; x<10; x++) {\n\tfor(int y=0; y<10; y++) {\n\t\tstatic int number_of_times = 0;\n\t\tnumber_of_times++;\n\t}\n}\n\\end{minted}\n\n\n\t\\item Use \\verb|static| inside a class definition. A static member \n    variable inside a class have the same value in any instance in the class\n    and doesn't even require an instance of the class to exist.\n    \\begin{remark}\n        When debugging or implementing a program using a static class member is that you cannot initialize the static class member inside of the class. In fact, if you decide to put your code in a header file, you cannot even initialize the static variable inside of the header file; do it in a .cpp file instead. Moreover, you are required to initialize the static class member or it will not be in scope. (The syntax is a bit weird: \\verb|type class_name::static_variable = value\"|).\n    \\end{remark}\n    \n   \\item \\verb|static member function|. Static member functions are functions that do not require an instance of the class, and are called the same way you access static member variables -- with the class name rather than a variable name. Static member functions can only operate on static members, as they do not belong to specific instances of a class.\n\\begin{minted}[frame=lines, framesep=2mm,tabsize=4]{cpp}  \nclass user{\nprivate:\n    static int next_id;\npublic:\n    static int next_user_id(){\n        next_id++;\n        return next_id;\n    }\n};\nint user::next_id = 0; // initialize static variable\n\\end{minted}\n\n    \\item \\verb|static function|. Static functions are functions that are only visible to other functions in the same file.L\n\n    \\item Use \\verb|static| to define a global variable inside a file of code.\n    \\begin{remark}\n        In this case, the use of static indicates that source code in other files that are part of the project cannot access the variable. Only code inside the single file can see the variable.\n    \\end{remark}\n\\end{itemize}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "8b96c7a858b7273b71edb7a6716c5f813bfaabf1", "size": 20263, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/feb.tex", "max_stars_repo_name": "soundsilence/DailyNotes", "max_stars_repo_head_hexsha": "561ad833b3d7824699847bc3e933e7da05889463", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-11T08:56:57.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-11T08:56:57.000Z", "max_issues_repo_path": "tex/feb.tex", "max_issues_repo_name": "soundsilence/DailyNotes", "max_issues_repo_head_hexsha": "561ad833b3d7824699847bc3e933e7da05889463", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/feb.tex", "max_forks_repo_name": "soundsilence/DailyNotes", "max_forks_repo_head_hexsha": "561ad833b3d7824699847bc3e933e7da05889463", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9673076923, "max_line_length": 519, "alphanum_fraction": 0.73508365, "num_tokens": 5656, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.831143060406073, "lm_q2_score": 0.8824278710924296, "lm_q1q2_score": 0.7334238013673776}}
{"text": "\\section{Probability}\n\n\\subsection{Exercise 1}\nIf $x \\in B_i$, then $x \\in A_i$ and $x \\notin A_j \\forall j < i$, so $x \\notin B_j \\forall j < i$.\nThus, all of the $B_i$ are disjoint. Furthermore, if $x \\in A_n$, then \n$x \\in A_i$ for some $i \\leq n$, so $x \\in \\cup_{i = 1}^n B_i$. The reverse direction\nis also true by definition of $B_i$, so $\\cup_{i = 1}^n A_i = \\cup_{i = 1}^n B_i$.\n\nTo prove the monotonically decreasing case, we first note that\n$A_n \\setminus A = \\cup_{i = n}^\\infty A_i \\setminus A_{i + 1}$. This can be\nseen from the fact that $x \\in A_n \\setminus A \\implies x \\notin \\cap_{i = n}^\\infty A_i$,\nso there exists $i$ such that $x \\in A_i$ and $x \\notin A_{i + 1}$, which gives\n$x \\in A_i \\setminus A_{i + 1}$. The reverse direction follows from the\ndefinition of monotonically decreasing, so we have equality.\n\nSince all of the $A_i \\setminus A_{i + 1}$ are disjoint, we have\n\\begin{align*}\n        \\lim_{n \\to \\infty} P(A_n) &= P(A) + \\lim_{n \\to \\infty} P(A_n \\setminus A) \\\\\n                                   &= P(A) + \\lim_{n \\to \\infty} \\sum_{i = n}^\\infty P(A_i \\setminus A_{i + 1}) \\\\\n                                   &= P(A)\n\\end{align*}\nas desired.\n\n\\subsection{Exercise 5}\nThe sample space consists of all strings that end in an H and otherwise contain only Ts\nexcept for a single other H (i.e. ``TTTTHTTTH''). If we stop at $k$ tosses, then toss $k$\nmust have been an H and there must also have been exactly one H in the first $k - 1$ tosses.\nSince we have $k - 1$ options for the other H, we have that the probability is\n$\\frac{k - 1}{2^k}$.\n\n\\subsection{Exercise 6}\nConsider the partition of $\\Omega$ into singletons. Assigning any non-zero probability to\nthese singletons would cause the probability of $\\Omega$ (which is the sum of the probabilities\nof the singletons) to diverge.\n\n\\subsection{Exercise 8}\nApplying the results from exercises 4 and 7, we have\n\\begin{align*}\n        P\\big(\\cap_{i = 1}^\\infty A_i\\big) &= P\\bigg(\\big(\\cup_{i = 1}^\\infty A_i^c\\big)^c\\bigg) \\\\\n                                             &= 1 - P\\big(\\cup_{i = 1}^\\infty A_i^c\\big) \\\\\n                                             &\\geq 1 - \\sum_{i = 1}^\\infty P(A_i^c) \\\\\n                                             &= 1\n\\end{align*}\nWhere the last line follows from the fact that $P(A_i) = 1$ was given.\n\n\\subsection{Exercise 10}\nWe define the sample space $\\Omega$ to consist of the doubles $(A, B)$ where\n$A, B \\in \\{1, 2, 3\\}$ and $A, B$ correspond to the door containing the prize\nand the door shown by Monty respectively. We can then define the event that \ndoor $i$ contains the prize as $X_i = \\{(A, B) \\: | \\: A = i\\}$. Similarly,\nwe can define the event that door $i$ is shown as $Y_i = \\{(A, B) \\: | \\: B = i\\}$.\n\nNow we can compute the probability $P(X_2 Y_3)$ using Bayes theorem as\n$P(X_2 Y_3) = P(Y_3 | X_2) P(X_2) = 1 * \\frac{1}{3}$. The calculation for\n$P(X_3 Y_2)$ is identical. Furthermore, $P(X_1 Y_2) = P(X_1 Y_3) = \\frac{1}{6}$, \nso our likelihood of winning is always increased by switching.\n\n\\subsection{Exercise 11}\n\\begin{align*}\n        P(A^c) P(B^c) &= (1 - P(A)) (1 - P(B)) \\\\\n                      &= 1 - P(A) - P(B) + P(A)P(B) \\\\\n                      &= 1 - P(A) - P(B) + P(AB) \\\\\n                      &= 1 - P(A \\cup B) \\\\\n                      &= P(A^c B^c)\n\\end{align*}\n\n\\subsection{Exercise 12}\nLet the sample space $\\Omega$ consist of the doubles $(C, S)$ where $C \\in \\{1, 2, 3\\}$\n(card number) and $S \\in \\{1, 2\\}$ (card side). Let $A$ denote the event that we see\na green side, and let $B$ denote the event that we see the double green card. Then\n$P(B | A) = \\frac{P(AB)}{P(A)} = \\frac{1}{3} / \\frac{1}{2} = \\frac{2}{3}$.\n\n\\subsection{Exercise 14}\nIf $P(A) = 0$, then we have that $P(AB) = 0 = P(A)P(B)$ for all $B$ since $AB \\subset A$.\nIf $P(A) = 1$, then we have $P(A \\cup B) = P(A) + P(B) - P(A \\cap B) = 1 + P(B) - P(A \\cap B)$\nwhich implies $P(A \\cap B) = P(B) = P(A)P(B)$.\nIf $A$ is independent of itself, then $P(A)^2 = P(A)$, which is only possible if\n$P(A) = 1$ or $P(A) = 0$.\n\n\\subsection{Exercise 17}\n$P(ABC) = \\frac{P(ABC)}{P(BC)} \\frac{P(BC)}{P(C)} P(C) = P(A | BC) P(B | C) P(C)$.\n\n\\subsection{Exercise 18}\nWe have that $\\sum_{i} P(B | A_i) P(A_i) = P(B)$. If $P(A_1 | B) < P(A_1)$, then\napplying Bayes' Theorem gives $P(B | A_1) < P(B)$. Now assume $P(B | A_k) \\leq P(B)$\nfor all $k > 1$. Then $\\sum_{i} P(B | A_i) P(A_i) < \\sum_{i} P(B) P(A_i) = P(B)$,\nwhich is a contradiction.\n", "meta": {"hexsha": "c7b3965b25df43b73acc13029b0a670cf7e876e3", "size": 4459, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "All_of_Statistics_Wasserman/chapter_1.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "All_of_Statistics_Wasserman/chapter_1.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "All_of_Statistics_Wasserman/chapter_1.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.6704545455, "max_line_length": 114, "alphanum_fraction": 0.5835389101, "num_tokens": 1605, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8824278757303677, "lm_q1q2_score": 0.7334237941496778}}
{"text": "% !TeX root = ../solution.tex\n\n\\hypertarget{he22.21}{%\n\\chapter{[HE22.21] Textbook}\\label{he22.21}}\n\n\\begin{marginfigure}\n\t\\includegraphics[width=49mm]{level5/challenge21.jpg}\n\\end{marginfigure}\n\\subsection{Intro}\nI've got the source code and the output of a simple cipher.\n\n\\noindent Can you calculate the flag from it?\n\n\\noindent File \\verb+textbook.zip+.\n\n\\subsection{Hint}\n\nAs usual, the flag starts with \\verb+he2022+.\n\n\\section{Solution}\\label{hv22.21solution}\nThe code generator is very simple, each character in the flag is coded as\n\\verb+pow(ord(c), e, n)+ -- take the ASCII value of the character to the power\n$e$ and then store the modulo $n$.  Since we have a crib (``he2022´´) and know\nthe exponent, we can also calculate the real value of \\verb+pow(ord(c),e)+.\nSubtract the coded value, we get a number that is known to be a multiple of\n$n$, so taking two such numbers, we can calculate $n$ as the GCD of the two\nnumbers.  Once $n$ is known, we can calculate a rainbow table for all printable\ncharacters and look-up the flag from the encrypted flag:\n\n\\begin{minted}{python}\nimport math\n\ndef multi_n(c, cr):\n    tmp = pow(ord(c), e)\n    return (tmp - cr)\n\n   \nwith open('output','r') as inF:\n    s = inF.read()[1:-2]\n    crypt = [int(x) for x in s.split(', ')]\n\nn = math.gcd(multi_n(crib[0], crypt[0]),\n            multi_n(crib[1], crypt[1]))\n\nrainbow = {}\nfor i in range(32,128):\n    rainbow[pow(i,e,n)] = chr(i)\n\nres = ''\nfor i in crypt:\n    res += rainbow[i]\n\nprint(res)\n\\end{minted}\nFlag \\verb+he2022{!!t3xtb00k_crypt0!!}+.\n\t\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "92bc65c79f77539dff5dc983e4af2eafdb033ef8", "size": 1552, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HackyEaster/he2022/level5/ch21.tex", "max_stars_repo_name": "tbrup/ctf-writeups", "max_stars_repo_head_hexsha": "dfac11abb3051af657ed3384c3c389c14a40c10e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HackyEaster/he2022/level5/ch21.tex", "max_issues_repo_name": "tbrup/ctf-writeups", "max_issues_repo_head_hexsha": "dfac11abb3051af657ed3384c3c389c14a40c10e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HackyEaster/he2022/level5/ch21.tex", "max_forks_repo_name": "tbrup/ctf-writeups", "max_forks_repo_head_hexsha": "dfac11abb3051af657ed3384c3c389c14a40c10e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5151515152, "max_line_length": 79, "alphanum_fraction": 0.681056701, "num_tokens": 477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9433475746920262, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.7332639291142753}}
{"text": "\\chapter{Automorphisms}\r\n\\section {Specific Groups}\r\n{\\bf Theorem 1:}\r\nIf $G= \\langle a \\rangle $ and $|a|=n$ then $Aut(G)= \\langle \\rho \\rangle $, $|\\rho|= \\phi(n)$.\r\n$Aut(G) \\cong {{\\mathbb Z}_n}^*$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 2:}\r\nIf $G= E(p^n)$ then $Aut(G)= L_n(p)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 3:}\r\nIf $G= S_n$ then $Aut(G)= S_n$ if $n \\ne 6$ and a covering group with factor $2$ of $S_6$ for\r\n$S_6$ (an outer automorphism).\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 4:}\r\nIf $G$ is simple, $1 \\rightarrow G \\rightarrow Aut(G)$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} $Q_8 = \r\n\\langle \r\n\\left(\\begin{array} {cc}\r\ni & 0\\\\\r\n0 & i\\\\\r\n\\end{array}\\right),\r\n\\left(\\begin{array} {cc}\r\n0 & -1\\\\\r\n1 & 0\\\\\r\n\\end{array}\\right),\r\n\\left(\\begin{array} {cc}\r\n0 & 1\\\\\r\n-1 & 0\\\\\r\n\\end{array}\\right)\r\n\\rangle$. $Q_8 \\in S_2(SL_2(5))$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 5:}  The automorphism group of $Q_8$ is $S_4$.\r\n\\\\\r\n\\\\\r\nAutomorphisms of Graphs.\r\n\r\n", "meta": {"hexsha": "d330a4d06a93c3028ad85cd249078f5057e5ecab", "size": 885, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "groups/gtAutomorphism.tex", "max_stars_repo_name": "jlmucb/class_notes", "max_stars_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "groups/gtAutomorphism.tex", "max_issues_repo_name": "jlmucb/class_notes", "max_issues_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "groups/gtAutomorphism.tex", "max_forks_repo_name": "jlmucb/class_notes", "max_forks_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.5813953488, "max_line_length": 96, "alphanum_fraction": 0.5480225989, "num_tokens": 368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397307, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7332373633234704}}
{"text": "\n\\subsection{Riemann manifolds and pseudo-Riemann manifolds}\n\n\\subsubsection{Riemann manifolds}\n\nMetric is positive definite.\n\n\\subsubsection{Pseudo-Riemann manifolds}\n\nThe metric isn't necessarily positive definite.\n\n\n\\subsection{Metric tensor field}\n\nmetric tensor field assigns a metric tensor to each point. metric tensor is defined on the tangent bundle.\nso we have metric on each tangent bundle, but the metric can change thoughout the manifold\n\n\n", "meta": {"hexsha": "05fefa99709ffcedffd3cbda0b43587e58f03183", "size": 453, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/manifoldsRiemann/01-02-riemann.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/manifoldsRiemann/01-02-riemann.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/manifoldsRiemann/01-02-riemann.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.8421052632, "max_line_length": 106, "alphanum_fraction": 0.8101545254, "num_tokens": 102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966702001757, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7332180473171859}}
{"text": "\\section{Sequences and Series of Functions}\n\n\\subsection{Exercise 1}\nWe have that $\\abs{f_n(x)} \\leq M_n$. From uniform convergence, we get that there exists $N$ such that\n\\begin{align*}\n        n, m \\geq N \\implies \\abs{f_n(x) - f_m(x)} < \\epsilon \\implies \\abs{M_n - M_m} < \\epsilon\n\\end{align*}\nSo $\\lim_{n \\to \\infty} M_n = M$ for some $M$. Thus, we can choose $N$ such that $n \\geq N \\implies M_n < M + 1$\n, so we can set $M_u = \\max\\{M_1, M_2, ..., M_{N-1}, M + 1\\}$. By construction, $M_u$ must be a uniform\nbound for all of the $f_n$.\n\n\\subsection{Exercise 2}\nSince $f_n, g_n$ are both uniformly convergent, we can choose $N_1, N_2$ such that \n\\begin{align*}\n        n, m \\geq \\max\\{N_1, N_2\\} \\implies \\abs{f_n(x) - f_m(x)} < \\frac{\\epsilon}{2}, \\: \\abs{g_n(x) - g_m(x)} < \\frac{\\epsilon}{2} \\\\\n        \\abs{f_n(x) + g_n(x) - f_m(x) - g_m(x)} \\leq \\abs{f_n(x) - f_m(x)} + \\abs{g_n(x) - g_m(x)} < \\epsilon\n\\end{align*}\nSo $f_n + g_n$ converges uniformly as well. \n\nSuppose $f_n \\to f$ and $g_n \\to g$, with $f_n(x) \\leq M_f$ and $g_n(x) \\leq M_g$. Then $g(x) f_n(x)$ \nconverges uniformly since $M_g f_n(x)$ converges uniformly, and likewise for $g_n(x) f(x)$. Thus,\n\\begin{align*}\n        \\frac{\\epsilon}{3} &> \\abs{(f_n(x) - f(x))(g_n(x) - g(x))} \\\\\n                 &> \\abs{f_n(x)g_n(x) - f_n(x)g(x) - f(x)g_n(x) + f(x)g(x)} \\\\\n                 &> \\abs{f_n(x)g_n(x) - f(x)g(x)} - \\abs{f(x)g(x) - f_n(x)g(x)} - \\abs{f(x)g(x) - f(x)g_n(x)} \\\\\n                 &> \\abs{f_n(x)g_n(x) - f(x)g(x)} - \\frac{\\epsilon}{3} - \\frac{\\epsilon}{3} \\\\\n        \\implies \\epsilon &> \\abs{f_n(x)g_n(x) - f(x)g(x)}\n\\end{align*}\nSo $f_n g_n \\to fg$ uniformly.\n\n\\subsection{Exercise 3}\nLet $f_n(x) = \\frac{1}{x} + \\frac{1}{n}$ and $g_n(x) = \\frac{1}{x}$ on $E = (0, 1)$. \nBoth $f_n$ and $g_n$ converge uniformly, and $f_n(x) g_n(x)$ converges pointwise to $\\frac{1}{x^2}$. However,\n\\begin{align*}\n        \\abs{f_n(x) g_n(x) - \\frac{1}{x^2}} = \\abs{\\frac{1}{xn}}\n\\end{align*}\nSo the convergence of $f_n(x) g_n(x)$ is not uniform on  $E$.\n\n\\subsection{Exercise 4}\nSince $1 + n^2 x = 0$ whenever $x = -\\frac{1}{n^2}$, $f(x)$ is not defined/does not converge for \n$x = 0, -\\frac{1}{n^2}$. For all other values of  $x$, however, $f(x)$ converges absolutely since \n$\\sum_{n = 1}^\\infty \\frac{1}{n^2}$ converges. $f(x)$ converges uniformly on any intervals of the form \n$(a, -1)$ and $(b, c)$ with $b > 0$, since such intervals do not contain points of the form $-\\frac{1}{n^2}$\nand $\\frac{1}{x}$ is bounded on all such intervals. $f$ fails to converge uniformly on all other intervals.\n$f(x)$ is continuous on the intervals that it converges uniformly on.\n$f$ is not bounded since $\\frac{1}{x}$ can be made arbitrarily large.\n\n\\subsection{Exercise 5}\nFor every positive real number $x$, there exists $N$ such that $\\frac{1}{N} < x$ (Archimedean property). Hence,\nchoosing $n \\geq N \\implies f_n(x) = 0$. Since every non-positive real number is less than $\\frac{1}{n + 1}$ \nfor all $n \\in \\mathbb{N}$, we have that $f_n$ converges pointwise to the function $f(x) = 0$. \nAs such, it is clear that $\\sum_{n = 1}^\\infty \\abs{f_n(x)} = \\sum_{n = 1}^N \\abs{f_n(x)}$ converges for all $x$\n, and yet we do not have uniform convergence.\n\n\\subsection{Exercise 6}\nWe can rewrite the series as\n\\begin{align*}\n        \\sum_{n = 1}^\\infty (-1)^n \\frac{x^2 + n}{n^2} = \\sum_{n = 1}^\\infty (-1)^n \\frac{1}{n} + \\sum_{n = 1}^\\infty (-1)^n \\frac{x^2}{n^2}\n\\end{align*}\nso the series converges uniformly since the alternating harmonic series converges and the series \n$\\sum_{n = 1}^\\infty \\frac{M}{n^2}$ converges (where $x^2 \\leq M$, which is possible on every bounded interval).\nHowever, this series also clearly does not converge absolutely for any value of $x$ since the harmonic\nseries does not converge.\n\n\\subsection{Exercise 7}\nWe posit that $f_n$ converges uniformly to the function $f(x) = 0$. For this to be true, there needs to be a\nsingle $N$ such that $n \\geq N$ gives\n\\begin{align*}\n        \\abs{\\frac{x}{1 + nx^2}} < \\epsilon \\implies \\frac{\\abs{x} - \\epsilon}{\\epsilon x^2} < n\n\\end{align*}\nfor all $x$. In other words, the lefthand side of the last expression above must have a maximum. Since the \nlefthand side is differentiable for all $x \\neq 0$, we can differentiate and equate to 0 to find that \n\\begin{align*}\n        \\dv{x} \\frac{x - \\epsilon}{\\epsilon x^2} = \\frac{2\\epsilon^2 x - \\epsilon x^2}{(\\epsilon x^2)^2} \\\\\n        2\\epsilon^2 x - \\epsilon x^2 = 0 \\implies x = 2 \\epsilon\n\\end{align*}\ngiving that $n > \\frac{1}{4\\epsilon^2}$ is sufficient for all $x$. Additionally, since $f_n(0) = 0$ for all\n$n$, we have that $f_n \\to f$ uniformly. Differentiating $f_n$ also shows that $f_n'(x) \\to 0$ for all\n$x \\neq 0$ and that $f_n'(0) = 1 \\neq f'(0)$.\n\n\\subsection{Exercise 8}\nSince $\\sum \\abs{c_n}$ converges, there exists $N$ such that $n, m \\geq N$ gives\n\\begin{align*}\n        \\epsilon > \\sum_{i = n}^m \\abs{c_i} \\geq \\sum_{i = n}^m \\abs{c_i I(x - x_i)} \\geq \\abs{\\sum_{i = n}^m c_i I(x - x_i)}\n\\end{align*}\nso $f(x)$ converges uniformly as $x$ was arbitrary ($0 \\leq I(x - x_i) \\leq 1$ for all $x$). If $x \\neq x_n$ \nand $x$ is not a limit point of $x_n$, then $f(x)$ is clearly continuous since there is a neighborhood\n$B_{\\delta}(x)$ that contains none of the $x_n$ which implies that $f(x)$ is constant in this neighborhood.\nIf $x$ is a limit point of the sequence $x_n$, then for any $\\epsilon > 0$ we can choose $N$ such that\n$n \\geq N \\implies \\abs{c_n} < \\epsilon$, so $f $ is continuous at $x$. \n\n\\subsection{Exercise 9}\nSince $f_n$ is a sequence of continuous functions that converges uniformly to $f$, $f$ is continuous. By\nuniform convergence of $f_n$, we have that there exists \n$N_1 \\: | \\: n  \\geq N_1 \\implies \\abs{f_n(x) - f(x)} < \\frac{\\epsilon}{2}$. By continuity of $f$, we have that there\nexists $N_2 \\: | \\: n \\geq N_2 \\implies \\abs{f(x_n) - f(x)} < \\frac{\\epsilon}{2}$. \nChoosing $n \\geq \\max(N_1, N_2)$ then gives\n\\begin{align*}\n        \\abs{f_n(x_n) - f(x)} &= \\abs{f_n(x_n) - f(x_n) + f(x_n) - f(x)} \\\\\n                              &\\leq \\abs{f_n(x_n) - f(x_n)} + \\abs{f(x_n) - f(x)} \\\\\n                              &< \\epsilon\n\\end{align*}\nso $\\lim_{n \\to \\infty} f_n(x_n) = f(x)$. The converse need not be true. Consider\n\\begin{align*}\n        f_n(x) = \n        \\begin{cases}\n                \\frac{1}{n} & x = \\frac{1}{n} \\\\\n                0 & x \\neq \\frac{1}{n}\n        \\end{cases} \\\\\n\\end{align*}\nwhich satisfies $\\lim_{n \\to \\infty} f_n(x_n) = 0$ for all sequences $x_n$ despite none of the $f_n$ being\ncontinuous. \n\n\\subsection{Exercise 10}\n$f(x)$ converges uniformly since $0 \\leq (nx) < 1$. Since $(nx)$ is discontinuous only when $nx$ is an integer,\n$f(x)$ is discontinuous only at rational values of $x$ (because we can choose $n = b$ so that \n$n\\frac{a}{b} = a$). The continuity of $f(x)$ at irrational values of $x$ comes from the fact that the partial\nsums are continuous at all such $x$ and converge uniformly to $f(x)$. Since \n$f_n(x) = \\sum_{i = 1}^n \\frac{(ix)}{i^2}$ contains only finitely many discontinuities in any bounded interval\n(there are only finitely many rational $x = \\frac{z}{i}$ such that $z \\in [a, b]$), we have that \n$f_n \\in \\mathscr{R}$. Thus, applying Theorem 7.16, we get that $f \\in \\mathscr{R}$.\n", "meta": {"hexsha": "839f36219a5ad691962620d791981b5990052d67", "size": 7256, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Principles_of_Mathematical_Analysis_Rudin/chapter_7.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "Principles_of_Mathematical_Analysis_Rudin/chapter_7.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Principles_of_Mathematical_Analysis_Rudin/chapter_7.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.4754098361, "max_line_length": 140, "alphanum_fraction": 0.6187982359, "num_tokens": 2675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.9046505440982949, "lm_q1q2_score": 0.7332001857087995}}
{"text": "\t\n\\chapter{CNN test for MNIST}\t\n\t\n\t\\section{Benchmark Dataset}\n\t\\subsection{MNIST}\n\tThe MNIST database of handwritten digits, has a training set of 60,000 examples, and a test set of 10,000 examples. It is a subset of a larger set available from NIST. The digits have been size-normalized and centered in a fixed-size image. Each example is a $28\\times 28$ grey-scale image with a label that show witch number the image is.\n%\t\\subsection{to be continued}\n\n\n\n\n\t\\section{The math representation of data and function}\n\tLet $\\mathcal{M}$ is the number of examples in training data, $\\mathcal{C}$ is the number of the variety of label.\n\t\n\t\\subsection{Label} Each image has a label in $\\{0,1,\\cdots,9\\}$ to show what's the number it is. We transform the label $n$ to a 10-dimension vector which the $n$-th element is $1$ and others are $0$, i.e. \n\t$$\n\tn \\rightarrow \\mathbf y\n\t$$\n\twhere $y_i = 1 $ iff $i=n$.\n\tThen the label data can be present as a matrix $Y = (\\mathbf y_1,\\cdot,\\mathbf{y}_{\\mathcal M})$.\n\t\\subsection{Grey-scale Image}\n\tIn this note, we only focus on the CNN of 2D image. A 2D Grey-scal image can regard as a matrix $X =(x_{m,n})_{M\\times N}$ where $x_{m,n}$ is the grey-level of pixel $(m,n)$.\n\t\\subsection{Image with multiple channels}\n\tIf we put more than one value on each pixel, the image can be think as a 3-rank tensor $\\mathbf X = (x_{m,n,l})_{M\\times N\\times L}$ which $x_{m,n,l}$ is the $l$-th value on pixel $(m,n)$. For example, a colorful image usually has three channels: red, blue and green. More over, we can consider that a channel is a feature of the image, so we usually create more channels in the convolution layer so that we can get more features.\n%\t\\subsection{Data between two layer}\n%\tThe transport data $\\mathbf X$ between two layer can be describe as a 3-rank tensor, i.e. $\\mathbf X = (x_{m,n,l})_{M\\times N\\times L}$. We can regard it as a 2D image with L real number in each pixel.\n\t\\subsection{Convolution Kernel}\n\tA 2D-convolution kernel for a 2D image can be represent as a matrix, i.e. $K = (k_{i,j})_{I\\times J}, i= -I',-I'+1,...,I', j = -J',-J'+1,...,J'$.(Suppose $I$ and $J$ is odd integer and $I' = \\dfrac{I-1}2, J' = \\dfrac{J-1}2 $.) which $K_{i,j}$ is the parameter on pixel $(i,j)$.\n\t\n\tThe effect of a $I\\times J$ kernel $K$ acting on a $M\\times N$  image $X$ is a 2D image \n\t$$\n\tY =\t K ( X) = (y_{m,n})_{M\\times N}\n\t$$\n\twhere \n\t\\begin{equation}\n\ty_{m,n} =\\sum_{\\alpha = - I'}^{I'} \\sum_{\\beta = - J'}^{J'}k_{\\alpha,\\beta} x_{m+\\alpha,n+\\beta}\n\t\\end{equation}\n\t\n\tA 2D-convolution kernel for a 2D image with $L$ channels can be represent as a 3-rank tensor, i.e. $\\mathbf{K} = (k_{i,j,l})_{I\\times J\\times L}, i= -I',-I'+1,...,I', j = -J',-J'+1,...,J'$.(Suppose $I$ and $J$ is odd integer and $I' = \\dfrac{I-1}2, J' = \\dfrac{J-1}2 $.) which $K_{i,j,l}$ is the parameter of $l$-th channel on pixel $(i,j)$.\n\t\n\t The effect of a $I\\times J\\times L$ kernel $\\mathbf K $ acting on a $M\\times N \\times L$ multiple channel image $\\mathbf X$ is also a 2D image \n\t$$\n\t\tY =\t\\mathbf K (\\mathbf X) = (y_{m,n})_{M\\times N}\n\t$$\n\twhere \n\t\\begin{equation}\n\ty_{m,n} =\\sum_{l=1}^L\\sum_{\\alpha = - I'}^{I'} \\sum_{\\beta = - J'}^{J'}k_{\\alpha,\\beta,l} x_{m+\\alpha,n+\\beta,l}\n\t\\end{equation}\n\t\n\t A convolution layer usually has more than one kernels, if we write them together, we can get a 4-rank tensor $\\mathcal{K} = (k_{i,j,l,p})_{I\\times J\\times L\\times P}$ where $\\mathbf K_p = (k_{i,j,l,p})_{I\\times J\\times L}$ is the $p$-th kernel.\n\tThen we can easily get the effect of a $I\\times J\\times L\\times P$ kernel $\\mathcal K $ acting on a $M\\times N \\times L$ multiple channel image $\\mathbf X$ is a 2D image with $P$ channels\n\t$$\n\t\\mathbf Y =\t\\mathcal K (\\mathbf X) = (y_{m,n,p})_{M\\times N\\times P}\n\t$$\n\twhere \n\t\\begin{equation}\n\ty_{m,n,p} =\\sum_{l=1}^L\\sum_{\\alpha = - I'}^{I'} \\sum_{\\beta = - J'}^{J'}k_{\\alpha,\\beta,l,p} x_{m+\\alpha,n+\\beta,l}\n\t\\end{equation}\n\t\\subsection{Pooling function}\n\tSuppose $X$ is a $S \\times T$ matrix, we have pooling function:\n\t\\begin{itemize}\n\t\t\\item max-pooling: \n\t\t$$\n\t\t\tP^{max}_{S\\times T}(X) = \\max x_{s,t}\n\t\t$$\n\t\t\\item mean-pooling:\n\t\t$$\n\t\tP^{mean}_{S\\times T}(X) = \\dfrac 1{ST} \\sum_{s,t}x_{s,t}\n\t\t$$\n\t\\end{itemize}\n\tNow let X is a $M \\times N$ matrix and $M=S\\times A, N=T\\times B$, we write $X$ in block matrix\n\t\\begin{equation}\n\tX=\\left[\n\t\\begin{matrix}\n\tX_{1,1}&\\cdots\t&X_{1,B}\\\\\n\t\\vdots &\t  \t&\\vdots\\\\\n\tX_{A,1}&\\cdots\t&X_{A,B}\n\t\\end{matrix}\n\t\\right]\n\t\\end{equation}. Each block $X_{a,b}$ is a $S\\times T$ matrix.\n\t\n\tAfter we selected a pooling function $P_{S\\times T}$, then \n\t$$\n\t\tY = P_{S\\times T}(X) =(y_{a,b})_{A\\times B}\n\t$$\n\twhere\n\t\\begin{equation}\n\t y_{a,b} = P_{S\\times T}(X_{a,b})\n\t\\end{equation}\n\t\n\t\\subsection{Loss function}\\label{Loss}\n\t\\paragraph{Cross-entropy} Suppose $\\mathbf y$ is the training data transformed by a example's label and $\\hat {\\mathbf {y}}$ is calculate by our model, the cross-entropy loss function is:\n\t\\begin{equation}\n\tL(\\mathbf y,\\hat {\\mathbf {y}}) =- \\sum y_n \\ln \\hat{y}_n\n\t\\end{equation}\n\t\n\tSo the loss function of training data is \n\t\\begin{equation}\n\t\\mathcal L(Y,\\hat Y) = \\sum L(\\mathbf y_i,\\hat {\\mathbf {y}}_i)\n\t\\end{equation}\n\t\n \t\\section{Introduction of several kinds of Layer}\n\t\\subsection{Densely Connect Layer}\\label{Dense}\n\tThis kind of layer is same with DNN. The input is a vector $\\mathbf x$ and the parameter is a matrix $W$ and vector $\\mathbf b$ called bias. After we choose a active function $\\sigma$, the output is\n\t\\begin{equation}\n\t\\mathbf u = \\sigma(W \\mathbf x + \\mathbf b)\n\t\\end{equation}\n\t\\subsection{Convolution Layer}\\label{Convolution}\n\tSuppose input data is a $M \\times N \\times L $ multi-channel image $\\mathbf X$. Parameter of this layer is a $I\\times J\\times L\\times P$ tensor $\\mathcal K$ and a P-dimension vector $\\mathbf b = (b_1,...,b_p)$ called bias. After we choose a active function $\\sigma$. Then the output of this layer is a $M\\times N \\times P$ tensor  \n\t$$\n\t\t\\mathbf U = \\sigma(\\mathcal{K}(\\mathbf X) + \\mathbf B)\n\t$$\n\twhere $\\mathbf B =(B_{m,n,p})_{M\\times N\\times P}$ and $B_{m,n,p} = b_p$ \n\t\\subsection{Pooling Layer}\\label{Pooling}\n\tSuppose input data is a $M \\times N \\times L $ multi-channel image $\\mathbf X$ and $M=S\\times A, N=T\\times B$. The $l$-th channel of $X$ is a $M\\times N$ matrix $X_p$. The output of this layer is a $A\\times B\\times P$ multi-channel image:\n\t\n\t$$\n\t\\mathbf U =P_{S\\times T}(\\mathbf X)=(U_p)_{P}\n\t$$\n\twhere \n\t\\begin{equation}\n\tU_p = P_{S\\times T}(X_p)\n\t\\end{equation}\n\t\\subsection{Dropout Layer}\\label{Dropout}\n\tFor a input $N$-element vector $\\mathbf x$, and a number $\\gamma \\in [0,1]$, the output is \n\t$$\n\t\\mathbf u = (u_n)_N = \\text{dropout}_{\\gamma} (\\mathbf x)\n\t$$\n\twhere \n\t\\begin{equation}\n\tu_n = \\left \\{ \n\t\\begin{split}\n\tx_n &\\ \\text{with probility}\\ \\gamma\\\\\n\t0   &\\ \\text{with probility}\\ 1-\\gamma\n\t\\end{split}\n\t\\right.\n\t\\end{equation}\n\t\\subsection{Classifier Layer}\n\t\\paragraph{Softmax Classifier}\\label{Softmax} For a input vector $x$ and the parameter is a matrix $W$ and vector $\\mathbf b$ called bias. Then \n\t$$\n\t\\mathbf y = W\\mathbf x + \\mathbf b \n\t$$\n\tand the output is \n\t\\begin{equation}\n\t\t\\mathbf u = (u_c)_{\\mathcal C} =\\text{softmax}(\\mathbf y)\n\t\\end{equation}\n\twhere \n\t\\begin{equation}\n\tu_c = \\dfrac{e^{y_c}}{\\sum_{c=1}^{\\mathcal{C}} e^{y_c}}\n\t\\end{equation}\n\\iffalse\n\t\\begin{table}[h]\n\t\t\\begin{tabular}{ccc}\n\t\t\tKind of Layer &\\\\ \\hline\n\t\t\tConvolution Layer \t\t&\\\\\n\t\t\tPooling Layer \t\t\t&\\\\\n\t\t\tDensely Connected Layer &\\\\\n\t\t\tDropout Layer\t\t\t&\\\\\n\t\t\tClassifier Layer\t\t&\\\\\n\t\t\\end{tabular}\n\t\\end{table}\n\\fi\n\t\\section{A Example of CNN}\n\tThis CNN totally contains 7 hidden layers. The describe of each layer is listed in follow table.\n\t\\newpage\n\t\\begin{table}\n\t\t\\begin{tabular}{|c|c|c|}\\hline\n\t\tLayer \t\t\t\t\t\t&Input and\t\t\t&Output\t\\\\\n\t\t\t\t\t\t\t\t\t&Parameter\t\t\t&\\\\ \\hline\n\t\t0 Input Layer    \t\t\t& \t\t\t\t\t& $X[28,28]$\\\\\\hline\n\t\t1 Convolution Layer \t\t&$\\mathbf X[28,28,1] = X$\t\t\t&$\\mathbf U_1[28,28,32]$\\\\\n        &$\\mathcal K_1[5,5,1,32], \\mathbf b_1[32]$\t&$\\mathbf U_1 = \\sigma (\\mathcal K_1(\\mathbf X)+ \\mathbf B_1)$ (\\ref{Convolution})\\\\\\hline\n\t\t2 Pooling Layer \t\t\t&$\\mathbf U_1[28,28,32]$\t&$\\mathbf U_2[14,14,32]$\\\\\n\t\t&\t\t\t\t\t\t\t&$\\mathbf U_2 = P_{2\\times 2}^{\\max}(\\mathbf U_1)$ (\\ref{Pooling})\\\\\\hline\n\t\t3 Convolution Layer\t\t\t&$\\mathbf U_2$[14,14,32]\t\t&$\\mathbf U_3[14,14,64]$\\\\\n\t\t&$\\mathcal K_2[5,5,32,64], \\mathbf b_2[64]$&$\\mathbf U_3 = \\sigma (\\mathcal K_2(\\mathbf U_3)+ \\mathbf B_2)$(\\ref{Convolution})\\\\\t\\hline\n\t\t4 Pooling Layer \t\t\t&$\\mathbf U_3[14,14,64]$\t\t&$\\mathbf U_4[7,7,64]$\\\\\n\t\t& \t\t\t\t\t\t\t&$\\mathbf U_4 = P_{2\\times 2}^{\\max}(\\mathbf U_3)$(\\ref{Pooling})\\\\\\hline\n\t\t5 Densely Connected Layer \t&$\\mathbf x[3136] = \\text{vec}(\\mathbf U_4)$ &$\\mathbf u_1[1024]$\\\\\n\t\t&$W[3136,1024],\\mathbf b[1024]$\t\t&$\\mathbf u_1 = \\sigma (W\\mathbf x +\\mathbf b)$(\\ref{Dense})\\\\\\hline\n\t\t6 Dropout Layer\t\t\t\t&$\\mathbf u_1[1024]$ \t\t\t\t&$\\mathbf u_2[1024]$\\\\\n\t\t(Only be used in training)&\t\t\t\t\t&$\\mathbf u_2 = \\text{dropout}_{0.5}(\\mathbf u_1)$(\\ref{Dropout})\\\\\\hline\n\t\t7 Softmax Layer\t\t\t\t&$\\mathbf u_2[1024]$\t\t\t\t&$\\hat{\\mathbf y}[10]$\\\\\n\t\t&$W_s[1024,10],\\mathbf b_s[10]$\t&$\\hat{\\mathbf y} = \\text{softmax}(W_s\\mathbf x +\\mathbf b_s)$(\\ref{Softmax}) \\\\\\hline\n\t\t8 Output Layer\t\t\t\t&\t\t\t\t\t\t\t\t\t&\\\\ \\hline\n\t\t\\end{tabular}\n\t\\end{table}\n\t\n\tIn this table $\\mathbf X[a,b,c]$ means $\\mathbf X$ is a $a\\times b\\times c$ tensor.\n\\iffalse\n\t\\begin{table}\n\t\\begin{tabular}{ccc}\n\t\tLayer or Output & &Detail\\\\ \\hline\n\tLayer 0 & Input a picture $\\mathbf x$& $\\mathbf x$ is a 28$\\times$28 matrix \\\\\\hline\n\tLayer 1 & Convolution Layer \t\t& \\\\\n\tOutput of Layer 1 &  \t\t&$\\mathbf{u}_1$ is a 28$\\times$28$\\times$32 tensor\\\\ \\hline\n\tLayer 2 & Pooling Layer \t\t\t&\\\\\n\tOutput of Layer 2 &  \t\t&$\\mathbf{u}_2$ is a 14$\\times$14$\\times$32 tensor\\\\ \\hline\n\t\t3 & Convolution Layer\t\t&\\\\\n\tOutput of Layer 3 &  \t\t&$\\mathbf{u}_3$ is a 14$\\times$14$\\times$64 tensor\\\\ \\hline\n\t\t4 & Pooling Layer \t\t\t&\\\\\n\tOutput of Layre 4&&$\\mathbf{u}_4$ is a 7$\\times$7$\\times$64 tensor\\\\\\hline\n\t\t5 & Densely Connected Layer &\\\\\n\tOutput of Layer 5 &  \t\t&$\\mathbf{u}_5$ is a 1024 vector\\\\ \\hline\n\t\t6 & Dropout Layer\t\t\t&\\\\\n\tOutput of Layer 6 &  \t\t&$\\mathbf{u}_6$ is a 1024 vector\\\\ \\hline\n\t\t7 & Softmax Layer\t\t\t&\\\\\n\tOutput of Layer 5 &  \t\t&$\\mathbf{y}$ is a 10 vector\\\\ \\hline\n\t\t8 & Output Layer\t\t\t&output $\\mathbf{y}$\\\\ \n\t\n\t\\end{tabular}\n\\end{table}\n\\fi\n\t\n\t\\section{Optimizer and Numerical Result} \n\tFor a input image $X_m$ in training data, now we can get $\\hat{\\mathbf y}_m = \\hat{\\mathbf y}(X_m,\\bm \\theta)$, where $\\bm \\theta = (\\mathcal K_1, \\mathbf b_1,\\mathcal K_2, \\mathbf b_2,W,\\mathbf b,W_s,\\mathbf b_s)$, Let $\\hat{Y} = (\\hat{\\mathbf y}_1,\\cdots,\\hat{\\mathbf y}_{\\mathcal{M}})$\n\tNow we get the optimize question: Find \n\t$\\bm \\theta$ s.t.\n\t$$\n\t \\min\t\\mathcal{L}(Y,\\hat{Y}) = \\sum_{m=1}^{\\mathcal M} L(\\mathbf y_m, \\hat{\\mathbf{y}}_m)\n\t$$\n\t($L$ is in \\ref{Loss}).\n\t\n\tThe optimizers for this question is the same as optimizers in DNN. The numerical result of this CNN is showing below: The first figure show the accuracy rate, second figure is the value of loss function $\\mathcal L$ and the third figure show the value of $-\\lg \\mathcal{L}$. Besides. \n\t\n\\begin{figure}\n\t\\includegraphics[width = \\textwidth,height=0.5\\textheight]{SGD_relu_200}\n\t\\caption{ Active function is relu, algorithm is SGD, step = 200,learning rate is 0.1}\n\t\\includegraphics[width = \\textwidth,height=0.5\\textheight]{Momentum_relu_200}\n\t\\caption{active function is relu, algorithm is Momentum, step = 200, learning rate is 0.03, momentum rate is 0.9}\n\\end{figure}\n\n\\begin{figure}\n\t\\includegraphics[width = \\textwidth,height=0.5\\textheight]{Adagrad_relu_200}\n\t\\caption{ Active function is relu, algorithm is Adagrad, step = 200,learning rate is 0.1}\n\t\\includegraphics[width = \\textwidth,height=0.5\\textheight]{Adadelta_relu_200}\n\t\\caption{active function is relu, algorithm is Adadelta, step = 200,learning rate is 0.1}\n\\end{figure}\n\\begin{figure}\n\t\n\t\\includegraphics[width = \\textwidth,height=0.5\\textheight]{Adam_relu_200}\n\t\\caption{active function is relu, algorithm is Adam, step = 200,learning rate is 0.0001 }\n\\end{figure}\n\n\\subsection{Logistic regression }\n\\subsubsection{Model}\n\\begin{itemize}\n\\item X: the input image of a handwritten digit\n\\item Y: the true value of the digit\n\\item W,b: weight and bias\n\\item Y$\\_$pred=softmax(Wx+b)\n\\item Loss=cross$\\_$entropy(Y, Y$\\_$pred)+ regularization term\n\\item Optimization method: Adam\n\\end{itemize}\n\n\\subsubsection{Implementation }\n\\begin{itemize}\n\\item Parameter\n\\begin{enumerate}\n\\item learning rate = 0.001\n\\item training epochs=50\n\\item batch size =100\n\\item regularization coefficient =0.0001\n\\end{enumerate}\n\\item Result\n\\begin{enumerate}\n\\item no regularization: training accuracy=93$\\%$; test accuracy =92$\\%$\n\\item regularization coefficient =0.0001: training accuracy=93$\\%$; test accuracy =92$\\%$\n\\item regularization coefficient =0.001: training accuracy=92$\\%$; test accuracy =92$\\%$\n\\item no regularization+SGD: training accuracy= 88$\\%$; test accuracy =89$\\%$\n\\end{enumerate}\n\n\\end{itemize}\n\n\\subsection{One hidden layer }\n\\subsubsection{Model}\n\\begin{itemize}\n\\item X: the input image of a handwritten digit\n\\item Y: the true value of the digit\n\\item Hidden layer size=500\n\\item Loss=cross$\\_$entropy(Y, Y$\\_$pred)+ regularization term\n\\item Optimization method: Adam\n\\end{itemize}\n\n\\subsubsection{Implementation }\n\\begin{itemize}\n\\item Parameter\n\\begin{enumerate}\n\\item learning rate = 0.001\n\\item training epochs=50\n\\item batch size =100\n\\item regularization coefficient =0.0001\n\\end{enumerate}\n\\item Result\n\\begin{enumerate}\n\\item no regularization: training accuracy=100$\\%$; test accuracy =98.36$\\%$\n\\item regularization coefficient =0.0001: training accuracy=99.00$\\%$; test accuracy =98.04$\\%$\n\\item regularization coefficient =0.001: training accuracy=98.00$\\%$; test accuracy =97.67$\\%$\n\\item no regularization+SGD: training accuracy= 90$\\%$; test accuracy =90.54$\\%$\n\\end{enumerate}\n\n\\end{itemize}\n\n\n\\section{MgNet and iResNet results}\n\\subsection{MgNet}\n\\begin{description}\n\t\\item[Model] The hyperparameters:\n\\begin{itemize}\n\t\\item $J$: the number of grids. we choose $J = 4$, that makes $m_4 = n_4 = 5$.\n\t\\item $\\nu_\\ell$:  the number of smoothings in each grids, \n\tjust take $\\nu_\\ell = 2$.\n\t\\item $c_u=c_f = 64$: the number of feature and data channels. \n\t\\item $A^\\ell = \\xi^{\\ell} $ and $B_{\\ell,i} = \\sigma \\circ \\eta^{\\ell,i} \\circ \\sigma $ are all convolution with multichannel with \n\t$\\mathbb{R}^{3\\times3\\times c\\times c}$\n\twhich need to be trained.\n\t\\item $R_{\\ell}^{\\ell+1}$ and $\\Pi_{\\ell}^{\\ell+1}$: the interpolation \n\tand restriction operator in MgNet.  \n\tHere we choose it as a convolution with stride $2$ which need to be trained.\n\\end{itemize}\n\n\\item[Result] The result is: \\\\\nmodel size: 557514, acc: 99.56, acc best: 99.60\n\n\\end{description}\n\n\\subsection{iResNet}\n\\begin{description}\n\t\\item[Model] The hyperparameters:\n\t\\begin{itemize}\n\t\\item $J$: the number of grids. we choose $J = 4$, that makes $m_4 = n_4 = 5$.\n\\item $\\nu_\\ell$:  the number of smoothings in each grids, \nin iResNet, because of the definition of $f^{\\ell+1,0}$, so $(\\nu_1, \\cdots, \\nu_{4}) = (2,1,1,1)$.\n\\item $c_f$: the number of channels.  Some suggestions:\n\\blue{\\begin{itemize}\n\t\t\\item The original iResNet-18: $(c_{f,1}, \\cdots, c_{f,4}) = (64,128,256,512)$, but too many parameters.\n\t\t\\item You can try $(16,32, 64, 128)$, less parameters.\n\t\t\\item You can also try $(64,64,64,64)$, or any set up for channels.\n\\end{itemize}}\n\\item $\\xi^{\\ell,i} $ and $\\eta^{\\ell,i} $ are all convolution with multichannel with \n$\\mathbb{R}^{3\\times3\\times c\\times c}$\nwhich need to be trained.\n\\item $R_{\\ell}^{\\ell+1}$ and $\\eta^{\\ell,0}$: the restriction operator. \nHere we choose it as a convolution with stride $2$ which need to be trained.\n\t\\end{itemize}\n\t\n\t\\item[Result] The result for $(16,32, 64, 128)$ is: \\\\\n\tmodel size: 605898,  acc: 99.52,  acc best : 99.56.\n\t\n\\end{description}", "meta": {"hexsha": "0aa42321abadd414ed42856fb8d5496f9146c882", "size": 15865, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/MNISETCNNTest.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/MNISETCNNTest.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/MNISETCNNTest.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.3285714286, "max_line_length": 431, "alphanum_fraction": 0.6658052316, "num_tokens": 5798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7332001846413189}}
{"text": "%\\input{head.tex}\n%\\begin{document}\n\n\\section{Action and Conjugation}\n\n\\subsection{Action}\n\n\\defn{symmetric group, $S_n$}\n\\defn{\nA group G \\term{acts} on $\\Omega$, if to every pair $(\\alpha,g)\\in\\Omega\\times G$, an element $\\alpha^g\\in\\Omega$ is assigned s.t.\\begin{enumerate}[i.]\n\\item{$\\alpha^1=\\alpha$ for $1=1_G$ and all $\\alpha\\in\\Omega$,}\n\\item{$(\\alpha^x)^y=\\alpha^{xy}$ for all $x,y\\in G$ and all $\\alpha\\in\\Omega$.}\n\\end{enumerate}}\n\nThe mapping\\\\\n\\centerline{\n$g^\\pi:\\Omega\\to\\Omega$ with $\\alpha\\mapsto\\alpha^g$}\ndescribes the action of $g\\in G$ on $\\Omega$. In particular $g^\\pi$ is a bijection and thus a permutation on $\\Omega$. \\\\\n\nNow \\romannumeral2. implies that\\\\\n\\centerline{\n$\\pi:G\\to S_\\Omega$ with $g\\mapsto g^\\pi$}\nis a homomorphism.\n\n\n%\\end{document}", "meta": {"hexsha": "78915b60a6fb3f819ca6d8d7908f52463abac5ff", "size": 774, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ActionAndConjugation.tex", "max_stars_repo_name": "ocbaby/FiniteGroups", "max_stars_repo_head_hexsha": "698c98fa6e01ac3187a94ce6ccb6eece54979949", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ActionAndConjugation.tex", "max_issues_repo_name": "ocbaby/FiniteGroups", "max_issues_repo_head_hexsha": "698c98fa6e01ac3187a94ce6ccb6eece54979949", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ActionAndConjugation.tex", "max_forks_repo_name": "ocbaby/FiniteGroups", "max_forks_repo_head_hexsha": "698c98fa6e01ac3187a94ce6ccb6eece54979949", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.7692307692, "max_line_length": 151, "alphanum_fraction": 0.677002584, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.733200178416593}}
{"text": "\n\\section{Norms and Norm Dependent Linear Regression}\n\n\\subsection{Motivation}\n\n\\begin{frame}\n  \\frametitle{Motivation}\n\n  \\begin{itemize}\n    \\item Different norms and similarity measures play an important role in machine learning and pattern recognition. \\\\[.5cm]\n    \\item In this chapter we summarize important definitions and facts on norms. \\\\[.5cm]\n    \\item We consider the problem of linear regression for different norms. \\\\[.5cm]\n    \\item We will briefly look into associated optimization problems.\n  \\end{itemize}\n\\end{frame}\n\n\n\\subsection{Inner Product}\n\n\\begin{frame}\n  \\frametitle{Inner Product}\n\n  \\begin{citeblock}{Definition}\n\n    The \\structure{\\emph{inner product of vectors}} $\\vec x, \\vec y\\in \\real^d$ is defined by \n    \\begin{displaymath}\n      \\langle\\vec x, \\vec y\\rangle = \\vec x^T \\vec y = \\sum_{i=1}^d x_iy_i \\quad .\n    \\end{displaymath}\n  \\end{citeblock}\n  \\pspread\n  \n  \\begin{ovalblock}{Example}\n    The \\structure{\\emph{Euclidean norm} ($L_2$-norm)} can be written in terms of an inner product:\n    \\begin{displaymath}\n      \\| \\vec x \\|_2 = \\sqrt{\\langle \\vec x, \\vec x \\rangle } = \n      \\sqrt{ \\vec x^T \\vec x} = \n      \\sqrt{\\sum_{i=1}^d x_i^2 }\\quad .\n    \\end{displaymath}\n  \\end{ovalblock}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Inner Product \\cont}\n\n  \\begin{citeblock}{Definition}\n\n    The \\structure{\\emph{inner product of matrices}} $\\mat X, \\mat Y\\in \\real^{m\\times n}$ is defined by \n    \\begin{displaymath}\n       \\langle \\mat X, \\mat Y \\rangle = \n       \\mbox{tr}(\\mat X^T \\mat Y) = \n       \\sum_{i=1}^m \\sum_{j=1}^n x_{i,j} y_{i,j} \\quad .\n    \\end{displaymath}\n  \\end{citeblock}\n  \\pspread\n  \n  \\begin{ovalblock}{Example}\n    The \\structure{\\emph{Frobenius norm}} can be written in terms of an inner product:\n    \\begin{displaymath}\n      \\| \\vec X \\|_F = \n      \\sqrt{ \\langle \\vec X, \\vec X \\rangle } =\n      \\sqrt{ \\mbox{tr}(\\mat X^T \\mat X)} =\n      \\sqrt{ \\sum_{i=1}^m \\sum_{j=1}^n x_{i,j}^2} \\quad .\n    \\end{displaymath}\n  \\end{ovalblock}\n\\end{frame}\n\n\n\\subsection{Norms}\n\n\\begin{frame}\n  \\frametitle{Norms}\n\n  \\begin{citeblock}{Definition}\n\n    The function $\\lVert\\cdot\\rVert$ %: \\real^d\\rightarrow \\real$ \n    is called a \\structure{\\emph{norm}} if it \n    \\pause\n\n    \\begin{enumerate}\n      \\item is \\structure{nonnegative}: $\\forall \\vec x:~ \\lVert\\vec x\\rVert\\geq 0$ \\\\[.3cm] \\pause\n      \\item is \\structure{definite}: $\\|\\vec x\\| =0$ only if $\\vec x=\\vec 0$ \\\\[.3cm] \\pause \n      \\item is \\structure{homogeneous}: $\\| a\\vec x\\|= |a|\\cdot \\|\\vec x\\|$ where $a\\in \\real$ \\\\[.3cm] \\pause\n      \\item fulfills the \\structure{triangle inequality}:\n      \\begin{displaymath}\n        \\forall \\vec x, \\vec y:~\\|\\vec x+\\vec y\\| \\leq \\|\\vec x\\|+ \\|\\vec y\\|\n      \\end{displaymath}\n    \\end{enumerate}\n  \\end{citeblock}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Norms \\cont}\n%  \\begin{citeblock}{Definition}\n    \\begin{itemize}\n      \\item The \\structure{$L_0$-norm} of a $d$-dimensional vector denotes the number of \\\\\n        non-zero entries. Despite its name, the $L_0$-norm is not a norm \\\\\n        because it is not homogeneous. \\pause\n      \\item The \\structure{$L_p$-norm} ($p \\geq 1$) of a $d$-dimensional vector is defined as \n        \\begin{displaymath}\n          \\| \\vec x\\|_p = \\left( \\sum_{i=1}^d  |x_i|^p \\right)^{\\frac{1}{p}}\n        \\end{displaymath}\n    \\end{itemize}\n%  \\end{citeblock} \n\\end{frame}\n \n \n\\begin{frame}\n  \\frametitle{Norms \\cont}\n\n  \\begin{itemize}\n    \\item \\structure{$L_1$-norm:} sum of absolute values\n      \\begin{displaymath}\n        \\| \\vec x\\|_1 = \\sum_{i=1}^d |x_i|\n      \\end{displaymath}\n      \\pause\n    \\item \\structure{$L_2$-norm:} sum of squared values\n      \\begin{displaymath}\n        \\| \\vec x\\|_2 = \\left(\\sum_{i=1}^d x_i^2\\right)^{\\frac{1}{2}}\n      \\end{displaymath}\n      \\pause\n    \\item \\structure{$L_\\infty$-norm:} maximum norm\n      \\begin{displaymath}\n        \\| \\vec x\\|_\\infty = \n        \\lim_{p\\rightarrow \\infty} \\left( \\sum_{i=1}^d  |x_i|^p \\right)^{\\frac{1}{p}} =\n        \\max_i \\{ |x_i| \\ ; \\ i=1,2, \\dots, d \\}\n      \\end{displaymath}\n  \\end{itemize}\n\\end{frame}\n \n \n\\begin{frame}\n  \\frametitle{Norms \\cont}\n\n  \\begin{citeblock}{Definition}\n\n    Let $\\mat P$ be a symmetric positive definite matrix. \\\\\n    The \\structure{\\emph{quadratic $L_{\\mat P}$-norm}} is defined by \n    \\begin{displaymath}\n      \\| \\vec x\\|_{\\mat P} = \n      \\sqrt{ \\vec x^T \\mat P \\vec x} \\pause = \n      \\sqrt{ (\\mat P^\\frac{1}{2} \\vec x)^T \\mat P^\\frac{1}{2} \\vec x} \\pause =\n      \\| \\mat P^\\frac{1}{2} \\vec x\\|_2\n    \\end{displaymath}\n  \\end{citeblock}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Norms \\cont}\n\n  \\structure{Note:} \n\n  \\begin{itemize}\n    \\item The $L_2$-norm is the same as the quadratic $L_{\\mat 1}$-norm. \\\\[.5cm] \\pause\n    \\item The \\structure{Mahalanobis distance} between two vectors $\\vec x$ and $\\vec y$ based on the covariance matrix $\\mat \\Sigma$ is given by the quadratic $L_{\\mat \\Sigma^{-1}}$-norm:\n      \\begin{displaymath}\n        \\| \\vec x - \\vec y\\|_{\\mat \\Sigma^{-1}} = \n        \\sqrt{ (\\vec x - \\vec y)^T \\mat\\Sigma^{-1} (\\vec x - \\vec y)}\n      \\end{displaymath}\n      \\pause\n    \\item A norm is a measure for the length of a vector. It can also be used to measure the distance between two vectors $\\vec x$ and $\\vec y$:\n      \\begin{displaymath}\n        \\mbox{dist}(\\vec x, \\vec y) = \\| \\vec x - \\vec y\\|\n      \\end{displaymath}\n  \\end{itemize}\n\\end{frame}\n \n \n\\begin{frame}\n  \\frametitle{Norms \\cont}\n\n  \\structure{Norms of matrices} can be defined by norms of vectors. \\\\[.25cm]\n  \n  \\begin{citeblock}{Definition}\n\n    \\small\n    Let $\\|.\\|_p$ and $\\|.\\|_q$ be norms for vectors in $\\real^m$ and $\\real^n$. \\\\\n    The \\structure{\\emph{operator norm}} of a matrix $\\mat X\\in \\real^{m\\times n}$  is defined by\n \n    \\begin{displaymath}\n      \\| \\mat X\\|_{p,q} = \\sup\\{ \\| \\mat X \\vec u\\|_p ; \\  \\| \\vec u\\|_q\\leq 1 \\}\n    \\end{displaymath}\n  \\end{citeblock}\n  \\pspread\n  \n  \\begin{ovalblock}{Example}\n    \\small\n    If $p=q=2$, i.\\,e.\\ we use the $L_2$-norm twice, the operator norm of $\\mat X$ \\\\\n    results in the maximum singular value:\n    \n    \\begin{displaymath}\n      \\| \\mat X\\|_{2,2}=   \\| \\mat X\\|_{2} = \\sigma_{\\max}{(\\mat X)}= \\sqrt{\\lambda_{\\max}(\\mat X^T\\mat X)}\n    \\end{displaymath}\n  \\end{ovalblock}\n\\end{frame}\n\n\n\\subsection{Unit Balls}\n\n\\begin{frame}\n  \\frametitle{Unit Balls}\n\n  \\begin{citeblock}{Definition}\n\n    The set\n    \\begin{displaymath}\n      {\\cal B} = \\{ \\vec x; \\|\\vec x\\| \\leq 1\\}\n    \\end{displaymath}\n    of all vectors $\\vec x$ of length less or equal to one according to the norm $\\|.\\|$ \\\\\n    is called the \\structure{\\emph{unit ball}}.\n  \\end{citeblock}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Unit Balls \\cont}\n \n  The unit ball for the $L_1$-norm:\n\n  \\begin{figure}\n    \\resizebox{.4\\linewidth}{!}{\n      \\input{\\texfigdir/unit_ball_L1.pstex_t}\n    }\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Unit Balls \\cont}\n\n  The unit ball for the $L_2$-norm:\n\n  \\begin{figure}\n    \\resizebox{.4\\linewidth}{!}{\n      \\input{\\texfigdir/unit_ball_L2.pstex_t}\n    }\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Unit Balls \\cont}\n\n  The unit ball for the $L_{\\infty}$-norm:\n\n  \\begin{figure}\n    \\resizebox{.4\\linewidth}{!}{\n      \\input{\\texfigdir/unit_ball_Linfinity.pstex_t}\n    }\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Unit Balls \\cont}\n\n  The unit ball for the $L_{\\mat P}$-norm:\n  \\begin{figure}\n    \\resizebox{.4\\linewidth}{!}{\n      \\input{\\texfigdir/unit_ball_LP.pstex_t}\n    }\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Unit Balls \\cont}\n\n  Summary: unit balls for the $L_{\\infty}$-, $L_4$-, $L_2$-, $L_1$-, $L_{0.5}$- and $L_0$-norm\n\n  \\begin{figure}\n    \\resizebox{\\linewidth}{!}{\n      \\input{\\texfigdir/unit_ball_Linfinity.pstex_t} \\hspace{1cm}\n      \\input{\\texfigdir/unit_ball_L4.pstex_t} \\hspace{1cm}\n      \\input{\\texfigdir/unit_ball_L2.pstex_t} \\hspace{1cm}\n      \\input{\\texfigdir/unit_ball_L1.pstex_t} \\hspace{1cm}\n      \\input{\\texfigdir/unit_ball_L0_5.pstex_t} \\hspace{1cm}\n      \\input{\\texfigdir/unit_ball_L0.pstex_t} \\hspace{1cm}\n    }    \n  \\end{figure}\n\n The $L_{0.5}$- and the $L_0$-norm are not norms\n\n\\end{frame}\n\n\\input{nextTime.tex}\n\n\\subsection{Norm Dependent Linear Regression}\n\n\\begin{frame}\n  \\frametitle{Norm Dependent Linear Regression}\n\n  In pattern recognition and pattern analysis (as in many other fields) one of the most important norm dependent linear regression problems is:\n\n  \\begin{displaymath}\n   \\mbox{minimize}\\quad \\| \\mat A \\vec x -\\vec b\\|\n  \\end{displaymath}\n\n  or alternatively\n\n  \\begin{displaymath}\n   \\hat{\\vec x} = \\argmin_{\\vec x} \\| \\mat A \\vec x -\\vec b\\|\n  \\end{displaymath}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Norm Dependent Linear Regression \\cont}\n\n  \\begin{itemize}\n    \\item Different norms will lead to different results. \\\\[.5cm]\\pause \n    \\item The estimation error $\\epsilon\\in \\real$ is defined by $\\epsilon= \\|\\vec x^*-\\hat{\\vec x}\\|$, where $\\vec x^*$ denotes the correct value. \\\\[.5cm] \\pause \n    \\item The \\structure{residual} $\\vec r= (r_1, r_2, \\dots, r_m)^T$ is defined by $\\vec r= \\mat A \\vec x -\\vec b$. \\\\[.5cm] \\pause\n    \\item If $\\vec b$ is in the range of $\\mat A$, the residual will be the zero vector.\n  \\end{itemize}\n\\end{frame}\n\n\n\\subsubsection{Least-Squares Linear Regression}\n\n\\begin{frame}\n  \\frametitle{Least-Squares Linear Regression}\n\n  \\structure{Minimization of the residual using the $L_2$-norm:}\n \n  \\begin{eqnarray*}\n    \\hat{\\vec x} &=& \\argmin_{\\vec x} \\| \\mat A \\vec x -\\vec b\\|_2 \\\\[.15cm] \\pause \n                 &=& \\argmin_{\\vec x} \\sum_{i=1}^m r_i^2 \\\\[.15cm] \\pause \n                 &=& \\argmin_{\\vec x} \\ (\\mat A \\vec x -\\vec b)^T (\\mat A \\vec x -\\vec b) \\\\[.15cm] \\pause \n                 &=& \\argmin_{\\vec x} \\ \\big( \\vec x^T \\mat A^T \\mat A\\vec x - \\vec x^T\\mat A^T \\vec b - \\vec b^T \\mat A\\vec x + \\vec b^T \\vec b \\big) \\\\[.15cm] \\pause \n                 &=& \\argmin_{\\vec x} \\ \\big( \\vec x^T \\mat A^T \\mat A\\vec x - 2 \\vec b^T \\mat A\\vec x + \\vec b^T \\vec b \\big) \\\\\n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Least-Squares Linear Regression \\cont}\n\n  The \\structure{partial derivatives} are:\n\n  \\begin{displaymath}\n    \\frac{\\partial}{\\partial \\vec x} \\ \\left( \\vec x^T \\mat A^T \\mat A\\vec x - 2 \\vec b^T \\mat A\\vec x + \\vec b^T \\vec b \\right)\n    = \\pause 2 \\mat A^T \\mat A \\vec x - 2 \\mat A^T \\vec b = \\vec{0}\n  \\end{displaymath}\n\n  Using the partial derivatives we get a \\structure{closed form solution} for the $L_2$-norm: \\pause \n\n  \\begin{displaymath}\n    \\hat{\\vec x} = (\\mat A^T \\mat A)^{-1}\\mat A^T \\vec b\n  \\end{displaymath}\n\n  if the columns of $\\mat A$ are mutually independent.\n\\end{frame}\n\n\n\\subsubsection{Chebyshev Linear Regression}\n\n\\begin{frame}\n\n  \\frametitle{Chebyshev Linear Regression}\n \n  \\structure{Minimization of the residual using the $L_\\infty$-norm:}\n\n  \\begin{displaymath}\n    \\mbox{minimize}\\quad \\Bigg\\{ \\| \\mat A \\vec x -\\vec b\\|_\\infty = \\max\\ \\{ |r_1|, |r_2|, \\dots, |r_m|\\} \\Bigg\\}\n  \\end{displaymath}\n  \\pause\n\n  This optimization problem can be rewritten in terms of a LP-problem:\n\n  \\begin{eqnarray*}\n    \\begin{array}{lcl}\n     \\mbox{minimize}& & r\\\\\n     \\mbox{subject to} & &   - r\\cdot \\vec 1 \\preceq \\mat A \\vec x - \\vec b \\preceq r\\cdot \\vec 1\n    \\end{array}\n  \\end{eqnarray*}\n\n  where $r\\in \\real$ and $\\vec 1 \\in \\{1\\}^m$.\n\\end{frame}\n\n\n\\subsubsection{Sum of Absolute Residuals}\n\n\\begin{frame}\n  \\frametitle{Sum of Absolute Residuals}\n\n  \\structure{Minimization of the residual using the $L_1$-norm:}\n\n  \\begin{displaymath}\n    \\mbox{minimize}\\quad \\Bigg\\{ \\| \\mat A \\vec x -\\vec b\\|_1 = \\sum_{i=1}^m  |r_i| \\Bigg\\}\n  \\end{displaymath}\n  \\pause\n  \n  This optimization problem can be rewritten in terms of a LP-problem:\n   \n  \\begin{eqnarray*}\n    \\begin{array}{lcl}\n      \\mbox{minimize}   & & \\vec 1^T \\vec r \\\\\n      \\mbox{subject to} & & - \\vec r \\preceq  \\mat A \\vec x -\\vec b\\preceq \\vec  r\n    \\end{array}\n  \\end{eqnarray*}\n  \n  where $\\vec r\\in \\real^m$ and $\\vec 1 \\in \\{1\\}^m$.\n\\end{frame}\n\n\n\\subsubsection{Ridge Regression and Unit Balls}\n\n\\begin{frame}\n  \\frametitle{Ridge Regression and Unit Balls}\n\n  \\structure{Ridge regression} is defined via the optimization problem\n\n  \\begin{displaymath}\n    \\mbox{minimize} \\quad \\mat \\|A\\vec x -\\vec b\\|_2+\\lambda \\cdot\\|\\vec x\\|_2\n  \\end{displaymath}\n  \n  \\begin{center}\n    \\resizebox{.4\\linewidth}{!}{\n      \\alt<7->{\n        \\input{\\texfigdir/ridge_regression7.pstex_t}\n      }{\\alt<6>{\n        \\input{\\texfigdir/ridge_regression6.pstex_t}\n      }{\\alt<5>{\n        \\input{\\texfigdir/ridge_regression5.pstex_t}\n      }{\\alt<4>{\n        \\input{\\texfigdir/ridge_regression4.pstex_t}\n      }{\\alt<3>{\n        \\input{\\texfigdir/ridge_regression3.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/ridge_regression2.pstex_t}\n      }{\n        \\input{\\texfigdir/ridge_regression1.pstex_t}\n      }}}}}}\n    }\n  \\end{center}\n\\end{frame}\n\n\n\\subsubsection{Lasso and Unit Balls}\n\n\\begin{frame}\n  \\frametitle{Lasso and Unit Balls}\n  \n  The \\structure{lasso} (Tibshirani 1996) is defined via the optimization problem\n  \n  \\begin{displaymath}\n    \\mbox{minimize} \\quad \\mat \\|A\\vec x -\\vec b\\|_2+\\lambda \\cdot\\|\\vec x\\|_1\n  \\end{displaymath}\n\n  \\begin{center}\n    \\resizebox{.4\\linewidth}{!}{\n      \\alt<6>{\n        \\input{\\texfigdir/lasso6.pstex_t}\n      }{\\alt<5>{\n        \\input{\\texfigdir/lasso5.pstex_t}\n      }{\\alt<4>{\n        \\input{\\texfigdir/lasso4.pstex_t}\n      }{\\alt<3>{\n        \\input{\\texfigdir/lasso3.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/lasso2.pstex_t}\n      }{\n        \\input{\\texfigdir/lasso1.pstex_t}\n      }}}}}\n    }\n  \\end{center}\n\\end{frame}\n\n\n\\subsubsection{Compressed Sensing}\n\n\\begin{frame}\n  \\frametitle{Compressed Sensing}\n\n  \\begin{itemize}\n    \\item In the previous chapter we motivated regularized linear regression. \\\\[.25cm]\n    \\item Assume we have fewer measurements than required to estimate the parameter vector $\\vec x$. \\\\[.25cm]\n    \\item Solution of the underdetermined case required. \\\\[.25cm]\n    \\item We call a vector $S$-sparse if its support, i.\\,e.\\ the number of non-zero entries, is less or equal to $S$  \\\\[.25cm] \\pause\n    \\item The vector $\\vec x$ can be recovered mostly always by solving the convex optimization problem (quadratic programming):\n      \\begin{eqnarray*}\n        \\mbox{minimize}   & &\\quad \\|\\vec x\\|_1\\\\\n        \\mbox{subject to} & & \\quad \\mat A\\vec x =\\vec b.\n      \\end{eqnarray*}\n  \\end{itemize}\n\\end{frame}\n\n\n\\subsection{Convex and Non-Convex Penalty Functions}\n\n\\begin{frame}\n  \\frametitle{Penalty Function}\n\n  Motivated by the discussion of different norms, we now introduce and study \\structure{penalty functions}.\n  \\spread\n\n  \\begin{citeblock}{Definition}\n\t  \n    The \\structure{\\emph{penalty function approximation problem}} is defined as follows:\n\n    \\begin{eqnarray*}\n      \\mbox{minimize}   & &\\sum_{i=1}^m \\phi(r_i) \\\\\n      \\mbox{subject to} & & \\vec r= (r_1, r_2, \\dots, r_m)^T = \\mat A\\vec x -\\vec b,\n    \\end{eqnarray*}\n    \n    where $\\phi:\\real \\rightarrow \\real$ is the penalty function for the components of the \\\\\n    residual vector.\n  \\end{citeblock}\n \\end{frame}\n \n \n\\begin{frame}\n  \\frametitle{Penalty Function \\cont}\n\n  \\structure{Note:} \\\\[.5cm]\n  \n  \\begin{itemize}\n    \\item The penalty function $\\phi$ assigns \\structure{costs} to residuals. \\\\[.5cm]\n    \\item If $\\phi$ is a convex function, the penalty function approximation problem \\\\\n      is a convex optimization problem.\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Penalty Function \\cont}\n\n  Penalty functions of the $L_1$-,  $L_2$-norms:\n\n  \\begin{displaymath}\n    \\phi_{L_1}(r) = |r|;  \\qquad \\qquad \\qquad \\qquad \\qquad \\phi_{L_2}(r) = r^2\n  \\end{displaymath}\n  \\pause\n  \n  \\vspace{-0.5cm}\n  \\begin{figure}\n    \\resizebox{.4\\linewidth}{!}{\n      \\input{\\texfigdir/penalty_L1.pstex_t} \n    }\n    \\hspace{1cm}\n    \\resizebox{.4\\linewidth}{!}{\n      \\input{\\texfigdir/penalty_L2.pstex_t} \n    }\n  \\end{figure}\n\n  \\begin{itemize}\n    \\item In $L_1$ small deviations are weighted higher than using $L_2$.\n    \\item In $L_1$ large deviations are weighted lower than using $L_2$.\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Penalty Function \\cont}\n\n  \\structure{Log barrier function}\n\n  \\begin{displaymath}\n    \\phi_\\mathsf{barrier}(r) = \n      \\left\\{\n        \\begin{array}{cl}\n          -a^2\\log \\left(1-\\left( \\frac{r}{a}\\right)^2 \\right),  & \\quad \\mbox{if} \\quad |r| < a\\\\\n          \\infty,                                                & \\quad \\mbox{otherwise}\n        \\end{array}\n      \\right.\n  \\end{displaymath}     \n\n  \\begin{figure}\n    \\resizebox{.6\\linewidth}{!}{\n      \\alt<3->{\n        \\input{\\texfigdir/penalty_LogBarrier3.pstex_t} \n      }{\\alt<2>{\n        \\input{\\texfigdir/penalty_LogBarrier2.pstex_t} \n      }{\n        \\input{\\texfigdir/penalty_LogBarrier1.pstex_t} \n      }}\n    }\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Penalty Function \\cont}\n\n  \\structure{Dead zone linear penalty function}\n  \n  \\begin{displaymath}\n    \\phi_\\mathsf{dz}(r) = \n      \\left\\{\n        \\begin{array}{cl}\n          0,     & \\quad \\mbox{if} \\quad |r| \\leq a\\\\\n          |r|-a, & \\quad \\mbox{otherwise}\n        \\end{array}\n      \\right.\n  \\end{displaymath}\n\n  \\begin{figure}\n    \\resizebox{.6\\linewidth}{!}{\n      \\alt<3->{\n        \\input{\\texfigdir/penalty_DeadZoneLinear3.pstex_t} \n      }{\\alt<2>{\n        \\input{\\texfigdir/penalty_DeadZoneLinear2.pstex_t} \n      }{\n        \\input{\\texfigdir/penalty_DeadZoneLinear1.pstex_t} \n      }}\n    }\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Penalty Function \\cont}\n\n  \\structure{Large error penalty function}\n  \n  \\begin{displaymath}\n    \\phi_\\mathsf{e}(r) = \n      \\left\\{\n        \\begin{array}{cl}\n          r^2, & \\quad \\mbox{if} \\quad |r| \\leq a \\\\\n          a^2, & \\quad \\mbox{otherwise}\n        \\end{array}\n      \\right.\n  \\end{displaymath}\n\n  \\begin{figure}\n    \\resizebox{.6\\linewidth}{!}{\n      \\alt<3->{\n        \\input{\\texfigdir/penalty_LargeError3.pstex_t} \n      }{\\alt<2>{\n        \\input{\\texfigdir/penalty_LargeError2.pstex_t} \n      }{\n        \\input{\\texfigdir/penalty_LargeError1.pstex_t} \n      }}\n    }\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Penalty Function \\cont}\n\n  \\structure{Huber function}\n  \n  \\begin{displaymath}\n    \\phi_\\mathsf{Huber}(r) = \n      \\left\\{\n        \\begin{array}{cl}\n          r^2,            & \\quad \\mbox{if} \\quad |r| \\leq a \\\\\n          a\\cdot(2|r|-a), & \\quad \\mbox{otherwise}\n        \\end{array}\n      \\right.\n  \\end{displaymath}\n\n  \\begin{figure}\n    \\resizebox{.6\\linewidth}{!}{\n      \\alt<3->{\n        \\input{\\texfigdir/penalty_Huber3.pstex_t} \n      }{\\alt<2>{\n        \\input{\\texfigdir/penalty_Huber2.pstex_t} \n      }{\n        \\input{\\texfigdir/penalty_Huber1.pstex_t} \n      }}\n    }\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Penalty Functions \\cont}\n\n  \\begin{figure}\n    \\resizebox{1.0\\linewidth}{!}{\n      \\alt<6->{\n        \\input{\\texfigdir/penalty6.pstex_t} \n      }{\\alt<5>{\n        \\input{\\texfigdir/penalty5.pstex_t} \n      }{\\alt<4>{\n        \\input{\\texfigdir/penalty4.pstex_t} \n      }{\\alt<3>{\n        \\input{\\texfigdir/penalty3.pstex_t} \n      }{\\alt<2>{\n        \\input{\\texfigdir/penalty2.pstex_t} \n      }{\n        \\input{\\texfigdir/penalty1.pstex_t} \n      }}}}}\n    }\n  \\end{figure}\n\\end{frame}\n\n\n\\subsection{Lessons Learned}\n\n\\begin{frame}\n  \\frametitle{Lessons Learned}\n\n  \\begin{itemize}\n    \\item We have considered vector and matrix norms in more detail. \\\\[.3cm]\n    \\item Important vector norms: $L_1$, $L_2$, $L_\\infty$, and $L_{\\mat P}$. \\\\[.3cm]\n    \\item Unit balls \\\\[.3cm] \\pause\n    \\item Linear regression for different norms: range from closed form solution to LP-problem. \\\\[.3cm]\n    \\item Regularized linear regression: range from closed form solution through QP-problem up to combinatorial optimization. \\\\[.3cm]\n    \\item We need to know the basics of algorithms for unconstrained and constrained optimization as well as convex optimization.\n  \\end{itemize}\n\\end{frame}\n\n\\input{nextTime.tex}\n\n\\subsection{Further Readings}\n\n\\begin{frame}\n  \\frametitle{Further Readings}\n\n  \\begin{itemize}\n    \\item G.~Golub, C.~F.~Van~Loan: \\\\\n      \\structure{Matrix Computations}, 3rd Edition, \\\\\n      The Johns Hopkins University Press, Baltimore, 1996. \\\\[.15cm]\n    \\item Lloyd N. Trefethen, David Bau III: \\\\\n      \\structure{Numerical Linear Algebra}, \\\\\n      SIAM, Philadelphia, 1997. \\\\[0.15cm]\n    \\item S.~Boyd, L.~Vandenberghe: \\\\\n      \\structure{Convex Optimization}, \\\\\n      Cambridge University Press, 2004. \\\\\n      \\point{\\small \\url{http://www.stanford.edu/~boyd/cvxbook/}} \\\\\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Further Readings \\cont}\n\n  \\begin{itemize}\n    \\item Compressed sensing is one of the most recent hot topics in pattern recognition and image processing. An excellent source is: \\\\[.3cm]\n      \\centerline{\\structure{\\url{http://www.dsp.ece.rice.edu/cs}}}\n      \\vspace{.3cm}\n      or the recent workshop on compressed sensing at Duke University: \\\\[.3cm]\n    \\structure{\\url{http://people.ee.duke.edu/\\%7Elcarin/compressive-sensing-workshop.html}}.\n  \\end{itemize}\n\\end{frame}\n\n\n\\subsection{Comprehensive Questions}\n\n\\begin{frame}\n  \\frametitle{Comprehensive Questions}\n\n  \\begin{itemize}\n    \\item What is the difference between the $L_p$- (p $\\ge$ 1) and the $L_{\\mat P}$-norm? \\\\[1cm]\n    \\item How do the unit balls look like for $L_{\\infty}$-, $L_4$-, $L_2$-, $L_1$- and $L_0$-norm? \\\\[1cm]\n    \\item What is the benefit of using the $L_1$- over the $L_2$-norm for sparse, underdetermined problems? \\\\[1cm]\n    \\item What specific property of penalty functions is of special interest and \\\\\n      why do we need different penalty functions at all? \n  \\end{itemize}\n\\end{frame}\n", "meta": {"hexsha": "a6a8901e3f2ab646bf859106a68b77cd6f964629", "size": 21804, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "08_norms.tex", "max_stars_repo_name": "akmaier/pr-slides", "max_stars_repo_head_hexsha": "c322ad388993ff7891b959764e4481a05a444dff", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-01-11T07:27:09.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-31T19:21:31.000Z", "max_issues_repo_path": "08_norms.tex", "max_issues_repo_name": "akmaier/pr-slides", "max_issues_repo_head_hexsha": "c322ad388993ff7891b959764e4481a05a444dff", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "08_norms.tex", "max_forks_repo_name": "akmaier/pr-slides", "max_forks_repo_head_hexsha": "c322ad388993ff7891b959764e4481a05a444dff", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-21T06:06:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-18T18:47:28.000Z", "avg_line_length": 28.765171504, "max_line_length": 188, "alphanum_fraction": 0.6196110805, "num_tokens": 7538, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267728417086, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7331986619804376}}
{"text": "\\section{Overview}\n\\label{s:overview}\n\nWe start with an overview of how \\sys works by describing\nhow it can prove the equivalence of two functions: a\nrecursive function |sumTo| that adds up the numbers\nfrom |1| to |n|, and a \\emph{tail-recursive} variant\n|sumToTR| that uses a helper |loop| with an accumulator\n|acc| to compute the same result.\n\n\n\\begin{figure*}[t!]\n\\centering\n\\begin{minipage}[t]{0.40\\textwidth}\n% \\begin{minted}[linenos, firstnumber=1,breaklines=true]{ocaml}\n\\begin{ocode}\n(* -- Recursive Summation -- *)\n\nlet rec sumTo n =\n  if n = 0\n    then 0\n    else n + sumTo (n - 1)\n\\end{ocode}\n\\end{minipage}\n\\hspace{0.14in}\n\\begin{minipage}[t]{0.49\\textwidth}\n% \\begin{minted}[linenos, firstnumber=1,breaklines=true]{ocaml}\n\\begin{ocode}\n(* -- Tail-Recursive Summation -- *)\n\nlet sumToTR n =\n  let rec loop n acc =\n    if n = 0\n      then acc\n      else loop (n - 1) (acc + n)\n  in\n    loop n 0\n\\end{ocode}\n\\end{minipage}\n\\caption{\\textbf{(L)} Function that sums the numbers to $n$\n         and \\textbf{(R)} Tail-recursive accumulator based variant.\n}\n\\label{fig:example}\n\\end{figure*}\n", "meta": {"hexsha": "b81c3670fe170e5bf0c0539848b64dc5d7485a28", "size": 1097, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/syn-refinements/overview.tex", "max_stars_repo_name": "qizhou92/icfp", "max_stars_repo_head_hexsha": "2f84c30e8f564f4bec2933a8b736ae58fd91821e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "papers/syn-refinements/overview.tex", "max_issues_repo_name": "qizhou92/icfp", "max_issues_repo_head_hexsha": "2f84c30e8f564f4bec2933a8b736ae58fd91821e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "papers/syn-refinements/overview.tex", "max_forks_repo_name": "qizhou92/icfp", "max_forks_repo_head_hexsha": "2f84c30e8f564f4bec2933a8b736ae58fd91821e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.3777777778, "max_line_length": 67, "alphanum_fraction": 0.6809480401, "num_tokens": 367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522813, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7331986533816297}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS671: Machine Learning\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 1}\n\nDetermine the interior, closure and border of the set $S = \\{x \\in \\mathbb{R}^3 | x_1^2 + x_2^2 + x_3^2 < 1, x_1+x_2+x_3 = a, a > 0\\}$.\nNote that the result depends on the value of $a$.\n\n\\subsection*{Solution}\n\nSet $S$ can be represented as the intersection of two sets $S_{\\text{sub}_1} = \\{x \\in \\mathbb{R}^3 | x_1^2 + x_2^2 + x_3^2 < 1\\}$ and $S_{\\text{sub}_2} = \\{x \\in \\mathbb{R}^3 | x_1 + x_2 + x_3 = a, a > 0\\}$; the former consists of the set of points inside a sphere of radius 1 and the latter consists of the set of points on a plane whose x-,y- and z-intercepts are $a$.\n\nFor clarification, define Point $P = (x_0, y_0, z_0)$ as the point at which the hyperplane $x + y + z = a$ would be tangent to the sphere of radius 1.\nThis point is important in that all choices of $a$ larger than or equal to $x_0 + y_0 + z_0$ will make the plane to pass over the interior of the sphere represented by $S_{\\text{sub}_1}$, resulting in $S_{\\text{sub}_1} \\cap S_{\\text{sub}_2} = \\emptyset$.\nOn the other hand, in cases where $0 \\leq a \\leq x_0+y_0+z_0$, the plane would intersect with $S_{\\text{sub}_1}$, making an open circle in $\\mathbb{R}^3$.\n\nOur objective, is thus to attain coordinates of point $P$.\nSince this point is on the sphere and the hyperplane, we'll have\n\n\\begin{equation}\nx_0^2 + y_0^2 + z_0^2 = 1\n\\label{eq11}\n\\end{equation}\n\n\\begin{equation}\nx_0 + y_0 + z_0 = a\n\\label{eq12}\n\\end{equation}\n\nSubstituting Eq. \\ref{eq11} into Eq. \\ref{eq12}, Eq. \\ref{eq13} can be obtained.\n\n\\begin{equation}\nx_0y_0 + x_0z_0 + y_0z_0 = \\frac{a^2-1}{2}\n\\label{eq13}\n\\end{equation}\n\nHowever, since $x_0 + y_0 = a - z_0$, Eq. \\ref{eq13} will lead to\n\n\\begin{equation}\nz_0 = \\frac{a}{2} \\pm \\sqrt{x_0y_0 + \\frac{1}{2} - \\frac{a^2}{4}}\n\\label{eq14}\n\\end{equation}\n\nSince there is only one point $P$ with unique coordinates, Eq. \\ref{eq15} must hold.\n\n\\begin{equation}\nx_0y_0 + \\frac{1}{2} = \\frac{a^2}{4}\n\\label{eq15}\n\\end{equation}\n\nAnd using $z_0 = \\frac{1}{2}$,\n\n\\begin{equation}\n\\begin{aligned}\na &= \\sqrt{3}\\\\\nP(x_0, y_0, z_0) &= (\\frac{1}{\\sqrt{3}},\\frac{1}{\\sqrt{3}},\\frac{1}{\\sqrt{3}})\n\\end{aligned}\n\\label{eq16}\n\\end{equation}\n\nTherefore, depending on the choice of $a$, two cases exist for the intersection of $S_{\\text{sub}_1}$ and $S_{\\text{sub}_2}$.\n\\begin{itemize}\\itemsep=0pt\n\\item[] If $a \\geq \\sqrt{3}$, the hyperplane would pass over the interior of the sphere and the intersection would be empty, causing $I(S), K(S), \\partial(S) = \\emptyset$.\nNoteworthy that in the case where hyperplane is tangent to the closed sphere of radius 1, $S_{\\text{sub}_1} \\cap S_{\\text{sub}_2} = \\emptyset$ would still hold, since $S_{\\text{sub}_1}$ only contains interior of the sphere of radius 1.\n\\item[] If $0 \\leq a < \\sqrt{3}$, intersection of the hyperplane and interior of the sphere would be a filled but open circle in $\\mathbb{R}^3$.\nIn this case, interior of the set $S$ will be the filled but open circle in $\\mathbb{R}^3$ described by Eq. \\ref{eq17}.\n\n\\begin{equation}\nI(S) = S = \\{x \\in \\mathbb{R}^3 | x_1^2 + x_2^2 + x_3^2 < 1, x_1 + x_2 + x_3 = a\\}\n\\label{eq17}\n\\end{equation}\n\nAs $S$ is an open set, boundary of $S$, $\\partial(S)$ will be the circle resulted as intersection of the plane and the sphere with radius 1.\nTherefore $\\partial(S)$ can be described by Eq. \\ref{eq18}.\n\n\\begin{equation}\n\\partial(S) = \\{x \\in \\mathbb{R}^3 | x_1^2 + x_2^2 + x_3^2 = 1, x_1 + x_2 + x_3 = a\\}\n\\label{eq18}\n\\end{equation}\n\nAnd since closure of any set is the union of its interior and its boundary, $K(S)$ can be expressed as given in Eq. \\ref{eq19}.\n\n\\begin{equation}\nK(S) = I(S) \\cap \\partial(S) = \\{x \\in \\mathbb{R}^3 | x_1^2 + x_2^2 + x_3^2 \\leq 1, x_1 + x_2 + x_3 = a\\}\n\\label{eq19}\n\\end{equation}\n\n\\end{itemize}\n", "meta": {"hexsha": "22aa4e81e41501335f8e5dc422b8b949d0737474", "size": 4089, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs671-2015s/src/tex/f01/f01q01.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs671-2015s/src/tex/f01/f01q01.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs671-2015s/src/tex/f01/f01q01.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 43.9677419355, "max_line_length": 371, "alphanum_fraction": 0.6534605038, "num_tokens": 1520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950868503682, "lm_q2_score": 0.8688267745399466, "lm_q1q2_score": 0.7331986463583136}}
{"text": "If you haven't downloaded and unzipped \\href{https://libaoj.in/courses/2021f/MATH3341/zip/Math.3341.zip}{\\texttt{Math.3341.zip}}. Download and unzip it under \\verb|H:| (H Drive if you are working on the Remote Lab). Change the current working directory by typing \\verb|cd H:\\Math.3341\\Math.3341.Lab.07| in the Command Window, and type \\verb|edit lab_07_script| in the Command Window to edit \\verb|lab_07_script.m|.\n\n%---------------------------------------------\n\\section{Debugging}\n%---------------------------------------------\nIn this lab you will learn how to debug code and develop ways to make code more readable by employing good coding practices.\n\nYour goal is to fix the bugs in \\verb|lab_07_script.m| and \\verb|lab_07_function.m|. These files solve the linear system $A \\mathbf{x} = \\mathbf{b}$ given by\n\\begin{align*}\n    4 x_1 + 3 x_2       & = 24 \\\\\n    3 x_1 + 4 x_2 - x_3 & = 30 \\\\\n    - x_2 + 4 x_3       & = -24 \\\\\n\\end{align*}\nusing the Gauss-Seidel method with Successive Over Relaxation (SOR). This method gives means to speed up the convergence of our iterative method. The only change from the Gauss-Seidel method is the use of a parameter $\\omega$. Depending on the choice of this $\\omega$, the Gauss Seidel method can be performed in significantly less iterations than the original method. The iterative step in this method is now\n$$\nx_i^{(k)} = (1 - \\omega) x_i^{(k-1)} + \\frac{\\omega}{a_{ii}} \\left[ b_i - \\sum_{j=1}^{i-1} a_{ij} x_j^{(k)} - \\sum_{j=i+1}^{n} a_{ij} x_j^{(k - 1)} \\right].\n$$\nThese code files are riddled with various errors. Your task is to look through the code and correct all of the issues you encounter. Methods for doing this efficiently will be explained in the lab. Note that the necessary corrections may involve any of the following:\n\n\\begin{enumerate}[1.]\n    \\item changing variable names,\n    \\item fixing indexing,\n    \\item suppressing output,\n    \\item changing code style,\n    \\item adding proper indentation,\n    \\item adding comments,\n    \\item removing redundant code.\n\\end{enumerate}\n\nOnce you finish debugging, call \\verb|diary('lab_07_output.txt')|, then run the script \\verb|lab_07_script.m|, and call \\verb|diary off| to save the output. The outputs and figures should be exactly same as those on the following pages. You will upload files \\verb|sor_gauss_seidel.tex|, \\verb|lab_07_script.m|, \\verb|lab_07_function.m|, \\verb|lab_07_output.txt|, \\verb|lab_07_plot_1.pdf|, and \\verb|lab_07_plot_2.pdf|. Recompile, and submit the generated \\verb|.pdf| file on WyoCourses.\n\n\\newpage\n\n\\section{Results}\n\n\\subsection{Output}\n\n\\lstinputlisting[style=Plain]{../Math.3341.Lab.07.ans/lab_07_output.txt}\n\n\\subsection{Formatted output}\n\n\\input{../Math.3341.Lab.07.ans/sor_gauss_seidel.tex}\n\n\\newpage\n\n\\subsection{Plots}\n\\begin{figure}[!hbtp]\n    \\centering\n    \\includegraphics[width=0.80\\textwidth]{../Math.3341.Lab.07.ans/lab_07_plot_1.pdf}\n    \\includegraphics[width=0.80\\textwidth]{../Math.3341.Lab.07.ans/lab_07_plot_2.pdf}\n    \\caption{Solution and residual}\n    \\label{fig:sol}\n\\end{figure}\n\n", "meta": {"hexsha": "2018ed6585d38af18010abe5d22bc5f9281cb962", "size": 3054, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/Math.3341.Lab.07/exercise/body.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/Math.3341.Lab.07/exercise/body.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/Math.3341.Lab.07/exercise/body.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.5272727273, "max_line_length": 487, "alphanum_fraction": 0.7082514735, "num_tokens": 897, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.90192067455231, "lm_q1q2_score": 0.7331418396255911}}
{"text": "\\chapter{Gaussian Approximations}\n\n\\section*{5.1. Equal percentages}\n\\addcontentsline{toc}{section}{5.1. Equal percentages}\nIn the last paragraph of Section 2.1, the same percentage\n99.999999975\\%, appeared twice. Explain why you know that \nthese two percentages must be the same, even if you don't\nknow what the common value is.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We've seen that for a high number of flips, the binomial \n    distribution reduces to a Gaussian distribution\n    with the standard deviation $\\sigma = \\sqrt{n/4}$. Since we are dealing with a \n    Gaussian distribution, the probability that the number of Heads\n    obtained differs from the expected number by at most $\\Delta x$ Heads is given\n    by the number of standard deviations needed to reach $\\Delta x$.\n    The two experiments in Section 2.1 were:\n    \\begin{enumerate}[(i)]\n        \\item $n_1 = 10^5$ flips and the probability that the expected number of\n            Heads differs by more than $\\Delta p_1 = 1\\%$ of the expected value\n            is given by our percentage. Hence, the standard deviation is given by\n            $\\sigma_1 = \\sqrt{10^5 / 4} = 50\\sqrt{10}$ and the number of flips\n            that deviate from the expected value is $\\Delta x_1 = n_1 \\Delta p_1 = 10^3$.\n\n        \\item $n_1 = 10^5$ flips and the probability that the expected number of\n            Heads differs by more than $\\Delta p_2 = 0.01\\%$ of the expected value\n            is given by our percentage. Hence, the standard deviation is given by\n            $\\sigma_2 = \\sqrt{10^9 / 4} = 5000\\sqrt{10}$ and the number of flips\n            that deviate from the expected value is $\\Delta x_2 = n_2 \\Delta p_2 = 10^5$.\n    \\end{enumerate}\n\n    Now, since the number of standard deviations to reach the needed $\\Delta x$'s are\n    equal for both cases,\n    \\[\n        \\frac{\\Delta x_1}{\\sigma_1} = \\frac{10^3}{50\\sqrt{10}} = 5 \\sqrt{10}\n        = \\frac{10^5}{5000\\sqrt{10}} \n        = \\frac{\\Delta x_2}{\\sigma_2}\n    \\] \n    we have that the percentage that the number of Heads does not deviate\n    from the expected value more than $\\Delta x$ Heads is the same for both\n    cases, that is 99.999999975.\n\\end{proof}\n\n\\section*{5.2. Rolling sixes}\n\\addcontentsline{toc}{section}{5.2. Rolling sixes}\nIn the solution to Problem 2.13 (known as the Newton-Pepys problem), we\nnoted that the answer to the question, \"If $6n$ dice are rolled, what is the\nprobability of obtaining at least $n$ 6's?\", approaches 1/2 in the $n \\to \\infty$\nlimit. Explain why this is the case.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We know that for $n \\to \\infty$ the Binomial distribution reduces to the \n    Gaussian distribution. Let $X$ denote the number of 6's that are obtained \n    in $6n$ rolls. Assuming that the probability of a dice to be rolled as a 6\n    is 1/6, we get that $E[X] = n$, i.e. the expected number of 6's after $6n$ \n    rolls is $n$. As $n \\to \\infty$, the probability\n    of obtaining exactly $n$ 6's is negligible, so the probability that we \n    get at least $n$ sixes is roughly given by the area of the right half of the \n    Gaussian approximation. Therefore, for $n \\to \\infty$ the sought probability approaches \n    $1/2$ (half of the area of a normalized Gaussian).\n\\end{proof}\n\n\\section*{5.3. Coin flips}\n\\addcontentsline{toc}{section}{5.3. Coin flips}\nIf you flip 10$^4$ coins, how surprised would you be if the observed percentage\nof Heads differs from the expected value of 50\\% by more than 1\\%? Answer\nthe same question for 10$^6$ coins. (These numbers are large enough so that\nthe binomial distribution can be approximated by a Gaussian).\n\n\\vspace{1em}\n\n\\begin{proof}\n    Since the number of flips are large enough, the Binomial distributions are reduced\n    to Gaussians. We analyze the two cases separately:\n    \\begin{enumerate}[(i)]\n        \\item We start by seeing that, the standard deviation is given by $\\sigma_1 = \\sqrt{10^4 / 4} = 50$, and\n            that $\\Delta x_1 = 10^4 \\cdot 1\\% = 100$. Now, we \"shift\" the Gaussian so that\n            $\\mu = 0$. The graph will show us the probabilities of the observed\n            value relative to the expected value. Therefore, the probability\n            that the observed number of Heads differs from the expected value of\n            50\\% by more than 1\\% is given by:\n            \\[\n                p_1 \n                = 1 - \\frac{1}{\\sqrt{2 \\pi {\\sigma_1}^2}} \n                    \\int_{-\\Delta x_1}^{\\Delta x_1} e^{-\\frac{x^2}{2{\\sigma_1}^2}} dx\n                = 1 - \\frac{1}{50\\sqrt{2\\pi}} \n                    \\int_{-100}^{100} e^{-\\frac{x^2}{2 \\cdot 50^2}} dx\n                \\approx 1 - 0.9544 = 0.0455 = 4.55\\%\n            \\] \n\n        As a result, I would be surprised, but not very much so. 4.55\\% is not a big percentage, but \n        certainly not negligible.\n\n    \\item Analogously with the other case, we have that $\\sigma_2 = \\sqrt{10^6/4} = 500$ and \n        $\\Delta x_2 = 10^6 \\cdot 1\\% = 10^3$. By \"shifting\" the Gaussian again such that\n        $\\mu = 0$, the probability that the observed number of Heads differs from\n        the expected value of 50\\% by more than 1\\% is:\n        \\[\n            p_2 \n            = 1 - \\frac{1}{\\sqrt{2 \\pi {\\sigma_2}^2}} \n                \\int_{-\\Delta x_2}^{\\Delta x_2} e^{-\\frac{x^2}{2{\\sigma_2}^2}} dx\n            = 1 - \\frac{1}{500\\sqrt{2}} \n                \\int_{-10^3}^{10^3} e^{-\\frac{x^2}{2 \\cdot 500^2}} dx\n            \\approx 0 \\approx 0\\%\n        \\] \n\n        Therefore, I would be extremely surprised by the result, as this occuring seems \n        very close to impossible.\n    \\end{enumerate}\n\\end{proof}\n\n\\section*{5.4 Identical distributions}\n\\addcontentsline{toc}{section}{5.4. Identical distributions}\nA thousand dice are rolled. Fig. 5.15 shows the probability distribution (given\nby Eq. (5.15)) for the number of 6's that appear, relative to the expected number\n(which is 167). How many $\\emph{coins}$ should you flip if you want the probability\ndistribution for the number of Heads that appear (relative to the expected number)\nto look exactly like the distribution in Fig. 5.15 (at least in the Gaussian\napproximation)?\n\n\\begin{figure}[H]\n    \\center{\\includegraphics[width=0.6\\linewidth]{figure5_15.png}}\n    \\caption*{\\textbf{Figure 5.15}: The probability distribution for the number of 6's in 1000\n    dice rolls, relative to the expected number, 167.}\n\\end{figure}\n\n\\vspace{1em}\n\n\\begin{proof}\n    Both the dice and coin distributions are binomial distributions, so we'll approximate\n    them as Gaussian distributions. A Gaussian distribution is uniquely identified by its\n    mean and standard deviation, so two distributions are identical if they have these\n    two attributes identical. Since we are interested by the distribution \n    for the number of Heads relative to the expected number, we don't care about the mean.\n    Therefore, the standard deviation of the dice distribution must be the same as the one\n    of the coin distribution. Knowing that the standard deviation for a Gaussian approximation\n    of a binomial distribution is given by $\\sqrt{np(1 - p)}$, and by considering fair coins/dice,\n    we notice that the standard deviations of the distributions are equal for:\n    \\[\n        \\sqrt{1000 \\cdot \\frac{1}{6} \\cdot \\frac{5}{6}} = \\sqrt{\\frac{n}{4}} \n        \\iff \\frac{50\\sqrt{2}}{6} = \\frac{\\sqrt{n}}{2}\n        \\iff 50\\sqrt{2} = 3\\sqrt{n} \\iff n = \\frac{5000}{9} \\approx 556\n    \\] \n\n    Therefore, we need to flip 556 coins to obtain a very close Gaussian distribution to\n    Fig. 5.15.\n\\end{proof}\n\n\\section*{5.5. Gambler's fallacy}\n\\addcontentsline{toc}{section}{5.5. Gambler's fallacy}\nAssume that after 20 coin flips, you have obtained only five Heads. The\nprobability of this happening is small (about 1.5\\%, since $\\binom{20}{5} / 2^{20} = 0.0148$),\nbut not negligible. Since the law of large numbers says that the fraction of Heads approaches\n50\\% as the number of flips gets large, should you expect to see more Heads and Tails in\nfuture flips?\n\n\\vspace{1em}\n\n\\begin{proof}\n    Since coin flips are independent events, we can't make any assumption about future flips\n    based on the already done 20 flips. Also, we can't assume anything based on the law of large\n    numbers, since it assumes that the number of trials goes to infinity, so any unusual trends could\n    occur at any time, and their effect will be diminished as the number of trials increases. \n\\end{proof}\n\n\\section*{5.6. Finding the Gaussian}\n\\addcontentsline{toc}{section}{5.6. Finding the Gaussian}\nWhat is the explicit form of the Gaussian function $f(x)$ that matches\nup with the fourth histogram in Fig. 5.11? Assume that $n_t = 10$ is large\nenough so that the Gaussian approximation does indeed hold.\n\n\\begin{figure}[H]\n    \\center{\\includegraphics[width=0.6\\linewidth]{figure5_15_histogram.png}}\n    \\caption*{\\textbf{Figure 5.11}: Fourth Histogram}\n\\end{figure}\n\n\\vspace{1em}\n\n\\begin{proof}\n    We assume that $n_t = 10$ is large enough so the Gaussian approximation holds.\n    Let $X$ denote the outcome of a dice roll and let $Y$ represent the sum of 10 such outcomes,\n    so $Y = X_1 + X_2 + \\ldots X_{10}$, where the $X_i$s are distributed the same as $X$.\n    One can easily show that $\\sigma_X = 1.71$ and $\\mu_X = 3.5$. The mean of $Y$ is easily\n    obtained by using the linearity of expectation:\n    \\[\n        \\mu_Y = E[Y] = E\\bigg[\\sum_{i = 1}^{10}X_i\\bigg] = 10E[X] = 10\\mu_X = 35\n    \\] \n\n    The variance of $Y$ is computed by also using the fact that the $X_i$ variables\n    are independent, so the expectation of their product can be split:\n    \\begin{align*}\n        {\\sigma_Y}^2 \n        = E[Y^2] - {\\mu_Y}^2 \n        &= E\\bigg[\\bigg(\\sum_{i = 1}^{10} X_i\\bigg)^2\\bigg] - 100\\mu_X^2 \n        = 10E[X^2] + 2\\sum_{i = 1}^{10}\\sum_{j = i + 1}^{10} E[X_i X_j] - 100\\mu_X^2 \\\\\n        &= 10E[X]^2 - 110\\mu_X^2 + 10\\mu_X^2 \n        = 10E[X]^2 - 10\\mu_X^2 = 10\\sigma_X^2 \\approx 29.24\n    \\end{align*}\n\n    From the Central Limit Theorem, we know that $Y$ will be the Gaussian approximation \n    of the process described by the histogram. Therefore, since the probabilities\n    represent the number of sums with a specific value (height of the columns), divided\n    by the number of total sums ($n_s$), the Gaussian function associated to the histogram\n    is given by the PDF of $Y$, scaled by $n_s$:\n    \\[\n        f(x) = n_s G(y | \\mu_Y, \\sigma_Y^2) \n        = \\frac{10^5}{29.24\\sqrt{2\\pi}} e^{-\\frac{(y - 35)^2}{2\\cdot 29.24^2}}\n    \\] \n\\end{proof}\n\n\\section*{5.7. Standard deviations}\n\\addcontentsline{toc}{section}{5.7. Standard deviations}\nCalculate the theoretically predicted standard deviations of the histograms in\nFigs. 5.13 and 5.14, and check that your results are consistent with a visual\ninspection of the histograms. You will need the result from Problem 4.3 for\nFig. 5.14.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We analyze the two figures separately:\n\n    \\vspace{1em}\n\n    \\textbf{Fig. 5.13} The histogram shows the result of taking $n_s = 10^5$ averages of\n    $n_t = 100$ numbers chosen from the distribution in Fig. 5.12. Let $X$ be a\n    random variable modeled by the distribution in Fig. 5.12. Then,\n    \\[\n        P(X = 2) = 0.6 \\hspace{2em} P(X = 3.1) = 0.1 \\hspace{2em} P(X = 7) = 0.3\n    \\] \n\n    Therefore, the mean of $X$ is \n     \\[\n         \\mu_X = E[X] = 2 \\cdot 0.6 + 3.1 \\cdot 0.1 + 7 \\cdot 0.3 = 3.61\n    \\] \n    while the variance is given by\n    \\[\n        \\sigma_X^2 = E[(X - \\mu)^2] = (2 - 3.61)^2 \\cdot 0.6 + (3.1 - 3.61)^2 \\cdot 0.1 + (7 - 3.61)^2 \\cdot 0.3 \n        \\approx 5.26\n    \\] \n\n    Now, let $Y$ denote the average of $100$ numbers distributed like $X$ (denoted by $X_i$), so\n    \\[\n        Y = \\frac{1}{100}\\sum_{i = 1}^{100} X_i\n    \\] \n\n    By using the linearity of expectation, the mean of $Y$ is\n    \\[\n        \\mu_Y = E[Y] = \\frac{1}{100}E\\bigg[\\sum_{i = 1}^{100} X_i\\bigg] \n        = \\frac{1}{100}\\sum_{i = 1}^{100} E[X_i] \n        = E[X] = \\mu_X = 3.61\n    \\] \n\n    and the variance is given by:\n    \\[\n        \\text{Var}(Y) = \\text{Var}\\bigg(\\frac{1}{100} \\sum_{i = 1}^{100} X_i\\bigg)\n        = \\frac{1}{10^4} \\text{Var}\\bigg(\\sum_{i = 1}^{100} X_i\\bigg)\n        = \\frac{1}{10^4} \\sum_{i = 1}^{100} \\text{Var}(X_i)\n        = \\frac{1}{100} \\text{Var}(X) = 0.0526\n    \\]\n    which gives the standard deviation:\n    \\[\n        \\sigma_Y \\approx 0.23\n    \\] \n\n    \\begin{figure}[H]%\n        \\centering\n        \\subfloat[\\centering Histogram in Fig 5.13]{{\\includegraphics[width=0.49\\linewidth]{5_7_fig513.png} }}%\n        \\qquad\n        \\subfloat[\\centering Gaussian with $\\mu = 3.61, \\sigma = 0.23$, scaled by $10^5$]{{\\includegraphics[width=0.44\\linewidth]{5_7_gauss2.png} }}%\n    \\end{figure}\n\n    \\vspace{1em}\n\n    \\textbf{Fig. 5.14.} The histogram portrays the results of taking $n_s = 10^5$ averages\n    of $n_t = 50$ numbers chosen from a uniform distribution (from 0 to 1). Let X be\n    distributed by that uniform distribution. The mean of the uniform distribution \n    is just $\\mu_X = 1/2$ and the variance is given by the result from Problem 4.3, i.e.\n    $\\sigma_X^2 = 1/12$. Now, let $Y$ denote the average of 50 numbers chosen from this\n    distribution, so basically\n    \\[\n        Y = \\frac{1}{50} \\sum_{i = 1}^{50} X_i\n    \\] \n    where the $X_i$ variables are distributed like $X$.\n    If we assume that $n_t = 50$ is large enough for the Central Limit Theorem to apply,\n    we find that $Y$ is modeled by a Gaussian distribution. Note that the 1/50 scaler\n    does not change this, because a scaled Gaussian is still a Gaussian. Therefore, by\n    using the linearity of expectation, we get the mean of $Y$:\n    \\[\n        \\mu_Y = E[Y] = \\frac{1}{50}E\\bigg[\\sum_{i = 1}^{50} X_i\\bigg] \n        = \\frac{1}{50}\\sum_{i = 1}^{50} E[X_i] \n        = E[X] = \\mu_X = \\frac{1}{2}\n    \\] \n\n    Similarly, by using the fact that the variance of a sum of random variables is equal\n    to the sum of variances (for independent variables), we have that:\n    \\[\n        \\text{Var}(Y) = \\text{Var}\\bigg(\\frac{1}{50} \\sum_{i = 1}^{50} X_i\\bigg)\n        = \\frac{1}{50^2} \\text{Var}\\bigg(\\sum_{i = 1}^{50} X_i\\bigg)\n        = \\frac{1}{50^2} \\sum_{i = 1}^{50} \\text{Var}(X_i)\n        = \\frac{1}{50} \\text{Var}(X) = \\frac{1}{600}\n    \\] \n    which gives the standard deviation\n    \\[\n        \\sigma_Y = \\frac{1}{10\\sqrt{6}}\n    \\] \n\n    We can confirm that this result is valid by comparing the plot of the corresponding Gaussian \n    function in the figure with the histogram and seeing that they are are very similar: \n    \\begin{figure}[H]%\n        \\centering\n        \\subfloat[\\centering Histogram in Fig 5.14]{{\\includegraphics[width=0.49\\linewidth]{5_7_fig514.png} }}%\n        \\qquad\n        \\subfloat[\\centering Gaussian with $\\mu = 1/2, \\sigma = \\frac{1}{10\\sqrt{6}}$, scaled by $10^5$]{{\\includegraphics[width=0.44\\linewidth]{5_7_gauss1.png} }}%\n    \\end{figure}\n\\end{proof}\n", "meta": {"hexsha": "8823133a221328dcf65f4923344bdfdbcc2253e7", "size": 14866, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter5_gaussian_approximations.tex", "max_stars_repo_name": "thesstefan/morin_solutions", "max_stars_repo_head_hexsha": "0053de71a3743e99c94cee5fad0fd0f75aefa96b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/chapter5_gaussian_approximations.tex", "max_issues_repo_name": "thesstefan/morin_solutions", "max_issues_repo_head_hexsha": "0053de71a3743e99c94cee5fad0fd0f75aefa96b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter5_gaussian_approximations.tex", "max_forks_repo_name": "thesstefan/morin_solutions", "max_forks_repo_head_hexsha": "0053de71a3743e99c94cee5fad0fd0f75aefa96b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.3115264798, "max_line_length": 164, "alphanum_fraction": 0.6462397417, "num_tokens": 4677, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034369, "lm_q2_score": 0.8774767858797979, "lm_q1q2_score": 0.7331174087930087}}
{"text": "%\n% Chapter 1.2\n%\n\n\\section*{1.2 Types of Functions}\n\nA linear function can be written in \\textbf{slope-intercept form} (\\(y=mx+b\\)) where \\(m\\) is the slope of the line and \\(b\\) is the y-intercept.\n\\\\\\\\\nA function \\(P\\) is a \\textbf{polynomial} if \n$$P(x)=a_n{x}^n+a_{n-1}x^{n-1}+ \\cdots +a_2x^2+a_1x+a_0$$\nwhere n is a non-negative integer and the numbers \\(a_0, a_1, a_2, \\ldots ,a_n\\) are constants called the \\textbf{coefficients} of the polynomial. The domain of any polynomial is \\(\\mathbb{R} = (-\\infty, \\infty)\\). If the coefficient \\(a_n \\neq 0\\), then the degree of the polynomial is \\(n\\).\n\\\\\\\\\nA polynomial of degree 2 is of the form \\(P(x)=ax^2+bx+c\\) and is called a \\textbf{quadratic function}. Its graph is always a parabola that opens upward if \\(a > 0\\) and downward if \\(a < 0\\).\n\\\\\\\\\nA polynomial of degree 3 is of the form \n\\[ P(x)=ax^3+bx^2+cx+d \\text{ where } a \\neq 0 \\]\nand is called a \\textbf{cubic function}.\n\\\\\\\\\nA function of the form \\(f(x) = x^a\\), where \\(a\\) is a constant, is called a \\textbf{power function}.\n\\\\\\\\\nA \\textbf{rational function} \\(f\\) is a ratio of two polynomials:\n\\[ f(x)=\\frac{P(x)}{Q(x)} \\]\nwhere \\(P\\) and \\(Q\\) are polynomials. The domain consists of all \\(x\\)-values such that \\( Q(x) \\neq 0 \\).\n\n\\subsection*{Graphs of Basic Trigonometric Functions}\n\n\\begin{center}\n\\begin{tikzpicture}\n\\begin{axis}[\n    %axis lines = bottom,\n    grid=both,\n    ymin=-4,\n    ymax=4,\n    xmax=5,\n    xmin=-5\n]\n\n% Sine function\n\\addplot [\n    domain=-5:5,\n    samples=100\n]\n{sin(deg(x))};\n\\addlegendentry{$sin(x)$}\n\n% Cosine function\n\\addplot [\n    domain=-5:5, \n    samples=100,\n    dashed\n]\n{cos(deg(x))};\n\\addlegendentry{$cos(x)$}\n\n\n% Cosine function\n\\addplot [\n    domain=-5:5, \n    samples=100,\n    dotted\n]\n{tan(deg(x))};\n\\addlegendentry{$tan(x)$}\n\n \n\\end{axis}\n\\end{tikzpicture}\n\\end{center}\nNotice that for both sine and cosine functions the domain is \\((-\\infty, \\infty)\\) and the range is the closed interval \\([-1, 1]\\). In addition, sine and cosine functions are periodic functions with a period of 2\\(\\pi\\). \n$$\\sin(x+2\\pi)=\\sin(x) \\quad \\quad \\cos(x+2\\pi)=\\cos(x)$$\n\\textbf{Exponential functions} are functions of the form \\(f(x)=b^x\\) where the base \\(b\\) is a positive constant.\n\\\\\\\\\n\\textbf{Logarithmic functions} are functions written as \\(f(x)=\\log_b(x)\\), where the base \\(b\\) is a positive constant, are the inverse functions of exponential functions.\n", "meta": {"hexsha": "3dbd9e57d880caa0340dec2f2133f3e3e65fbdc0", "size": 2413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/1-2.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/1-2.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/1-2.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6081081081, "max_line_length": 293, "alphanum_fraction": 0.6535433071, "num_tokens": 809, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.7331087900043337}}
{"text": "\\chapter{Set Theory II}\n\n\\epigraph{Algebra is the offer made by the devil to the mathematician. The devil says: I will give you this powerful machine, it will answer any question you like. All you need to do is give me your soul: give up geometry and you will have this marvelous machine.}{Michael Francis Atiyah}\n\nWatch the Art of Problem Solving: Venn Diagrams with \\href{https://www.youtube.com/watch?v=c8VHzEFVmLA}{two categories} and \\href{https://www.youtube.com/watch?v=LIzIhmKlYPk}{three categories}!\n\nWe will use {\\bf Venn diagrams} to visualise operations between sets. I think they are pretty self explanitory, so I will mostly go through a few examples here and move on. For example, below the left circle represents the $A$ set, and the right circle represents the $B$ set. The coloured portion of the graphic represents the intersection (shared elements) between $A$ and $B$. So for $A \\cap B$:\n\n\\begin{venndiagram2sets}[shade=skyblue,showframe=false]\n\t\\fillACapB\n\\end{venndiagram2sets}\n\n\\begin{boxexample}{}{}\n\tSuppose $A=\\{a,b,c\\}$ and $B=\\{a,b,x,y\\}$, then $A \\cap B=\\{a,b\\}$ is visualised with:\n\n\t\\begin{venndiagram2sets}[shade=skyblue,showframe=false,labelOnlyA={c},labelOnlyB={x,y},labelAB={a,b}]\n\t\t\\fillACapB\n\t\\end{venndiagram2sets}\n\\end{boxexample}\n\nThis time we will visualise the union of two sets. Again, the coloured area represents everything withing the union. So for $A \\cup B$:\n\n\\begin{venndiagram2sets}[shade=skyblue,showframe=false]\n\t\\fillA \\fillB\n\\end{venndiagram2sets}\n\n\\begin{boxexample}{}{}\n\tSuppose $A=\\{a,b,c\\}$ and $B=\\{a,b,x,y\\}$, then $A \\cup B=\\{a,b,c,x,y\\}$  is visualised with:\n\n\t\\begin{venndiagram2sets}[shade=skyblue,showframe=false,labelOnlyA={c},labelOnlyB={x,y},labelAB={a,b}]\n\t\t\\fillA \\fillB\n\t\\end{venndiagram2sets}\n\\end{boxexample}\n\nAnd now we look at the complement of the set. So everything within the \\emph{universe of discourse} that is not in the set is coloured. Consider the Venn Diagram for $A^\\complement$:\n\n\\begin{venndiagram2sets}[shade=skyblue,labelNotAB={$\\mathcal{U}$}]\n\t\\fillNotA\n\\end{venndiagram2sets}\n\n\\begin{boxexample}{}{}\n\tSuppose $A=\\{a,b,c\\}$ and $\\mathcal{U}=\\{a,b,c,d,e,f,g\\}$, then $A^\\complement=\\{d,e,f,g\\}$ can be visualised with:\n\n\t\\begin{venndiagram2sets}[shade=skyblue,labelNotAB={\\quad $d,e,f,g$},labelOnlyA={$a,b,c$}]\n\t\t\\fillNotA\n\t\\end{venndiagram2sets}\n\\end{boxexample}\n\nAnd when we have two disjoint sets (two sets that do not share elements), no elements are coloured in their intersection. So for $A \\cap B = \\varnothing$:\n\n\\begin{venndiagram2sets}[shade=skyblue,showframe=false,overlap=-.5cm]\n\\end{venndiagram2sets}\n\n\\begin{boxexample}{}{}\n\tFor example, given the two sets $A=\\{a,b,c\\}$, and $B=\\{1,2,3\\}$, we can see that they share no elements and are disjoint.\n\n\t\\begin{venndiagram2sets}[shade=skyblue,showframe=false,overlap=-.5cm,labelOnlyA={a,b,c},labelOnlyB={1,2,3}]\n\t\\end{venndiagram2sets}\n\\end{boxexample}\n\nNow for the set-difference. We colour in the area that is in $A$, but not in $B$ So for $A \\setminus B$:\n\n\\begin{venndiagram2sets}[shade=skyblue,showframe=false]\n\t\\fillOnlyA\n\\end{venndiagram2sets}\n\n\\begin{boxexample}{}{}\n\tFor example, if $A=\\{a,b,c,d\\}$ and $B=\\{c,d\\}$, than $A \\setminus B=\\{c,d\\}$.\n\n\t\\begin{venndiagram2sets}[shade=skyblue,showframe=false,labelOnlyA={c,d},labelAB={a,b}]\n\t\t\\fillOnlyA\n\t\\end{venndiagram2sets}\n\\end{boxexample}\n\n\\section{Applications for Venn Diagrams}\n\nWe'll go over some examples of filling out more complicated Venn Diagrams. In general, you can use simpler Venn Diagrams to build more complicated ones. You'll see that in the below examples.\n\n\\begin{boxexample}{}{}\n\tSuppose we want to visualise $(A \\cap B)^\\complement \\cup B$. Thats a little long so lets break it up. Recall what $A \\cap B$ looks like.\n\n\t\\begin{venndiagram2sets}[shade=skyblue,labelNotAB={$\\mathcal{U}$}]\n\t\t\\fillACapB\n\t\\end{venndiagram2sets}\n\n\tNow, we'll invert that to get $(A \\cap B)^\\complement$:\n\n\t\\begin{venndiagram2sets}[shade=skyblue,labelNotAB={$\\mathcal{U}$}]\n\t\t\\fillNotAorNotB\n\t\\end{venndiagram2sets}\n\n\tAnd now lets add $B$. So, $(A \\cap B)^\\complement \\cup B$ is:\n\n\t\\begin{venndiagram2sets}[shade=skyblue,labelNotAB={$\\mathcal{U}$}]\n\t\t\\fillAll\n\t\\end{venndiagram2sets}\n\n\tAnd we see that $(A \\cap B)^\\complement \\cup B$ is acutally the universal set $\\mathcal{U}$!\n\\end{boxexample}\n\n\\begin{boxexample}{}{}\n\tLet's try another one. $(A \\cap B) \\cup (A \\cup B^\\complement)^\\complement$. Again, let's break this down. $A \\cap B$ is simple enough.\n\n\t\\begin{venndiagram2sets}[shade=skyblue,labelNotAB={$\\mathcal{U}$}]\n\t\t\\fillACapB\n\t\\end{venndiagram2sets}\n\n\tThe next one is $A \\cup B^\\complement$, a little bit more tricky. That can be read as the area of A, plus the area of not B. Think about it for a bit, its a logic puzzle.\n\t\\begin{venndiagram2sets}[shade=skyblue,labelNotAB={$\\mathcal{U}$}]\n\t\t\\fillA \\fillNotAorB\n\t\\end{venndiagram2sets}\n\n\tWe take the complement of above (inverting it) to get $(A \\cup B^\\complement)^\\complement$:\n\n\t\\begin{venndiagram2sets}[shade=skyblue,labelNotAB={$\\mathcal{U}$}]\n\t\t\\fillOnlyB\n\t\\end{venndiagram2sets}\n\n\tAnd now we glue them together to get to get our union $(A \\cap B) \\cup (A \\cup B^\\complement)^\\complement$:\n\n\t\\begin{venndiagram2sets}[shade=skyblue,labelNotAB={$\\mathcal{U}$}]\n\t\t\\fillB\n\t\\end{venndiagram2sets}\n\n\tFrom this digram, we can see there is another way of writting $(A \\cap B) \\cup (A \\cup B^\\complement)^\\complement$. It's just the set $B$!\n\\end{boxexample}\n\n\\section{Applications for Sets}\n\nNow we'll look at how sets and Venn Diagrams can be used to solve problems. In this class, we solve these intuitively. Algebra is another way to solve these problem though. These feel like Suduko puzzles to me.\n\n\\begin{boxexample}{}{}\n\tSuppose we surveyed 25 farms. 18 farms had potatoes, and 12 farms had corn. How many farms grow both potatoes and corn?\\\\\n\n\tIf we add the number of farms with potatoes to the number of farms with corn, then the farms that grow both will be counted twice. In other words,\n\n\t\\[\n\t\t|P|+|C|=|P \\cup C| + |P \\cap C|\n\t\\]\n\n\tNow, if we slightly rearrange this equation, we get\n\n\t\\[\n\t\t|P|+|C| - |P \\cup C|=|P \\cap C|\n\t\\]\n\n\tSo, we can find the intercept by plugging in the values that we know.\n\n\t\\[\n\t\t18+12-25=|P \\cap C| \\implies |P \\cap C|=5\n\t\\]\n\n\tOur answer is 5, and this is our Venn Diagram:\n\n\t\\begin{venndiagram2sets}[shade=skyblue,showframe=false,labelA={P},labelB={C},labelOnlyA={13},labelOnlyB={7},labelAB={5}]\n\t\t\\fillACapB\n\t\\end{venndiagram2sets}\n\n\\end{boxexample}\n\n\\begin{boxexample}{}{}\n\tSuppose 150 children were surveyed. It was found that 35 played hockey, 71 played baseball, 30 played soccer, 10 played all three, 3 played only soccer, 17 played only hockey, 6 played only soccer and hockey, 48 played only baseball, and 53 played no sports.\\\\\n\n\tFirst, lets draw the Venn Diagram. Start by drawing the three sets.\n\n\t\\begin{venndiagram3sets}[shade=skyblue,labelA={H},labelB={B},labelC={S},labelNotABC={$\\mathcal{U}$}]\n\t\\end{venndiagram3sets}\n\n\tNow, let's fill some of this in. Since 53 didn't play anything, they are outside of the three sets. 3 Played only soccer, 17 played only hockey and 48 played only baseball. 10 Played all three, and 6 played only soccer and hockey. So we have:\n\n\t\\begin{venndiagram3sets}[shade=skyblue,labelA={H},labelB={B},labelC={S},labelNotABC={\\quad $\\mathcal{U} \\quad 53$},labelOnlyA={17},labelOnlyB={48},labelOnlyC={3},labelABC={10},labelOnlyAC={6}]\n\t\\end{venndiagram3sets}\n\n\tWe'll fill in some more intersections now. How many played only hockey and baseball? There are 35 hockey players, take away 17 who played only hockey, take away 10 who played all three, and take away 6 who played hockey and soccer. So $35-17-10-6=2$. How many played only soccer and baseball? 71 baseball players, take away 48 who played baseball only, take away 10 who played all three, take away 2 who played hockey and baseball. So, $71-48-10-2=11$. The diagram looks like:\n\n\t\\begin{venndiagram3sets}[shade=skyblue,labelA={H},labelB={B},labelC={S},labelNotABC={\\quad $\\mathcal{U} \\quad 53$},labelOnlyA={17},labelOnlyB={48},labelOnlyC={3},labelABC={10},labelOnlyAB={2},labelOnlyBC={11},labelOnlyAC={6}]\n\t\\end{venndiagram3sets}\n\n\tNow we can use this to answer some questions.\n\t\\begin{enumerate}\n\t\t\\item How many played soccer and baseball only? $11$\n\t\t\\item How many played hockey and baseball only? $2$\n\t\t\\item How many played soccer and baseball? $10+11=21$\n\t\t\\item How many played soccer {\\bf or} baseball but not hockey? $48+11+3=62$\n\t\t\\item How many played exactly 2 games? $6+2+11=19$\n\t\t\\item How many played exactly 1 game? $17+48+3=68$\n\t\t\\item How many played only soccer? $3$\n\t\t\\item How many played soccer {\\bf and} baseball but not hockey? $3+48=51$\n\t\\end{enumerate}\n\\end{boxexample}\n\n\\begin{boxexample}{}{}\n\tFourty students who play board games was surveyed.\n\n\t\\medskip\n\t\\begin{tabular}{r|l}\n\t\t\\hline\n\t\tNumber of students & Game(s) played\\\\\n\t\t\\hline\n\t\t18 & Chess\\\\\n\t\t20 & Scrabble\\\\\n\t\t27 & Carrom\\\\\n\t\t7  & Chess \\& Scrabble\\\\\n\t\t12 & Scrabble \\& Carrom\\\\\n\t\t4  & Chess \\& Carrom \\& Scrabble\\\\\n\t\t\\hline\n\t\t\\multicolumn{2}{c}{40 Total}\\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\medskip\n\n\tWhat is the number of people who play both Chess \\& Carrom? What is the number of people who play Chess and Carrom but not Scrabble?\\\\\n\n\tWe begin by drawing our Venn diagram. We are given the Chess \\& Carrom \\& Scrabble intersection as $4$. We can use that to find our Chess \\& Scrabble only ($7-4=3$) and Scrabble \\& Charrom only ($12-4=8$) intersections. Finally, we can calculate our scrabble-only section ($20-3-4-8=5$).\n\n\t\\begin{venndiagram3sets}[shade=skyblue,showframe=false,labelA={Chess},labelB={Scrabble},labelC={Carrom},labelABC={4},labelOnlyAB={3},labelOnlyBC={8},labelOnlyB={5}]\n\t\\end{venndiagram3sets}\n\n\tNow it gets slightly more tricky. Consider the following highlighted section ($\\text{Chess} \\cup \\text{Carrom}$):\n\n\t\\begin{venndiagram3sets}[shade=skyblue,showframe=false,labelA={Chess},labelB={Scrabble},labelC={Carrom},labelABC={4},labelOnlyAB={3},labelOnlyBC={8},labelOnlyB={5}]\n\t\t\\fillA \\fillC\n\t\\end{venndiagram3sets}\n\n\tThere must be $40-5=35$ students in there. We know that $27$ of them play Carrom, and that $18$ of them play chess. So the Chess \\& Carrom intersection must be $27+18-35=10$, and the Chess \\& Carrom intersection is $10-4=6$. Thus the chess-only section is $18-6-4-3=5$, and the carrom-only section is $27-6-4-8=9$.\n\n\t\\begin{venndiagram3sets}[shade=skyblue,showframe=false,labelA={Chess},labelB={Scrabble},labelC={Carrom},labelABC={4},labelOnlyAB={3},labelOnlyBC={8},labelOnlyB={5},labelOnlyAC={6},labelOnlyA={5},labelOnlyC={9}]\n\t\\end{venndiagram3sets}\n\n\tThe number of people who play both Chess \\& Carrom is $6+4=10$, and the number of people who play Chess and Carrom but not Scrabble is $6$.\n\\end{boxexample}\n", "meta": {"hexsha": "5749bbd14fe4257ba5f5be7dbb323a056779d2c4", "size": 10742, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture2.tex", "max_stars_repo_name": "munshaw/math1910-notes", "max_stars_repo_head_hexsha": "d707618aacb3eaee62d83fb94c982fcee989fa8c", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lecture2.tex", "max_issues_repo_name": "munshaw/math1910-notes", "max_issues_repo_head_hexsha": "d707618aacb3eaee62d83fb94c982fcee989fa8c", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture2.tex", "max_forks_repo_name": "munshaw/math1910-notes", "max_forks_repo_head_hexsha": "d707618aacb3eaee62d83fb94c982fcee989fa8c", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.3017241379, "max_line_length": 477, "alphanum_fraction": 0.7244460994, "num_tokens": 3587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324848629214, "lm_q2_score": 0.8991213732152423, "lm_q1q2_score": 0.7329929512796242}}
{"text": "\\section{Random Number Generation}\n\\label{sec:random-number-generation}\n\nThe generation of pseudo-random numbers is a fundamental building-block in any next-event simulation.\n%\nIn fact, a sequence of pseudo-random numbers uniformly distributed in $(0,1)$ can be used to generate stochastic variates, e.g. the exponential distribution, that can be used in turn to generate streams of random events, e.g. requests to the system with random occurrence time and computational demand.\n%\nThere exist many techniques for random number generation, a lot of which are comprehensively presented in \\cite{l1994uniform}.\nThe most notable algorithmic generators are \\textit{linear congruential generators}, \\textit{multiple recursive generators}, \\textit{composite generators}, and \\textit{shift-register generators}.\n\nIn this work we adopted a custom implementation of a multi-stream Lehmer generator $(a,m,s)$, which belongs to the family of linear congruential generators and it is defined by the following equation:\n\n\\begin{equation}\n\\label{eqn:lehmer}\nx_{i+1} = (a^{j} \\mathrm{mod}m) x_{i} \\mathrm{mod}m \\qquad\\forall j=0,...,s-1\n\\end{equation}\n\nwhere $m$ is the modulus, $a$ is the multiplier, $s$ is the number of streams and $(a^{j} \\mathrm{mod}m)$ is the jump multiplier.\n\nWe have chosen this solution because \n(i) it provides a great degree of randomness with the appropriate parameters \n(ii) the multi-streaming is required by simulations with multiple stochastic components,\n(iii) it has a simple implementation and a smaller computational complexity with respect to others, and \n(iv) it is a de-facto standard, hence it is easy to compare our experimental results with the ones provided in literature.\n\nWe propose a generator with the following parameters:\n\n\\begin{itemize}\n\t\\item \\textbf{modulus $\\mathbf{2^{31}-1}$:} the modulus should be the maximum prime number that can be represented in the target system. \n\tAlthough all modern computers have a 64-bit architecture, we considered a 32-bit one because the algorithm to find the right multiplier for a 64-bit modulus can be very slow.\n\tFor this reason we have chosen $2^{31}-1$ as our modulus.\n\t\n\t\\item \\textbf{multiplier $\\mathbf{50812}$:} the multiplier should be \\textit{full-period modulus-compatible} with respect to the chosen modulus. The chosen modulus has 23093 of such multipliers. Among these there are also multipliers such as $16807$, widely used in the past, and $48271$, that is currently the most widely adopted.\n\tWe have chosen $50812$ as our multiplier because we wanted to study a suitable multiplier that is different from the de-facto standard.\n\t\n\t\\item \\textbf{$\\mathbf{256}$ streams:} the original periodic random sequence can be partitioned in different disjoint periodic random sub-sequences, one for each stream. \n\tThe number of streams should be no more than the number of required disjoint sub-sequences, because streams come with the cost of reducing the size of the random sequence.\n\tWe have chosen 256 streams, even if it is a lot more than the strictly required for our simulations, because it is a de-facto standard hence it is useful for comparisons between our evaluation and the one proposed in literature \\cite{leemis2006discrete}. \n\t\n\t\\item \\textbf{jump multiplier $\\mathbf{29872}$:} the jump multiplier is used to partition the random sequence in disjoint sub-sequences, one for each stream, whose length is often called jump size. The jump multiplier should be \\textit{modulus compatible} with the chosen modulus.\n\tWe have chosen $29872$ as our jump multiplier because it is the value that maximizes the jump size.\n\t\n\t\\item \\textbf{initial seed $\\mathbf{123456789}$:} the initial seed is the starting point of the finite sequence of generated values. Even if the initial seed does not impact the randomness degree of a generator in a single run (it only has to be changed in different replication of the same ensemble), we decide to indicate it here for completeness. \n\\end{itemize}\n\nThe randomness degree of such a generator has been assessed by the usage of \\textit{spectral test}, \\textit{test of extremes} and the \\textit{analysis of Kolomogorv-Smirnov}.\n%\nThe experimental results are reported in Section~\\ref{sec:evaluation}.\n", "meta": {"hexsha": "9361b1ec7722b4dd8986d87139349fe8347a6843", "size": 4226, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pydes/sec/random-number-generation.tex", "max_stars_repo_name": "gmarciani/research", "max_stars_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-07-27T13:31:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-20T12:54:12.000Z", "max_issues_repo_path": "pydes/sec/random-number-generation.tex", "max_issues_repo_name": "gmarciani/research", "max_issues_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pydes/sec/random-number-generation.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 86.2448979592, "max_line_length": 351, "alphanum_fraction": 0.7853762423, "num_tokens": 984, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509007, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7328911096017412}}
{"text": "\\section{Line Integrals}\nUnder what circumstances is the line integral\n$\\int_{A}^{B} f(z) \\, dz$\nindependent of the path from $A$ to $B$?\n\n\\begin{theorem}[Cauchy]\n    If $f(z)$ is analytic in a simply connected,\n    bounded domain $D$,\n    for every simple closed path $C$ in $D$,\n    \\begin{align}\n        \\oint_C f(z) \\, dz = 0\n        \\label{eqn:1}\n    \\end{align}\n\\end{theorem}\nTo prove this, consider\n\\begin{align}\n    \\oint f(z)\\, dz\n    &= \\oint_C (u + iv) (dx + i\\, dy)\\\\\n    &= \\oint_C (u\\,dx - v\\,dy) +\n    i \\oint_C (v\\,dx + u\\,dy)\n\\end{align}\nThen use Stokes theorm\n\\begin{align}\n    \\oint\\vec{A}\\cdot d\\vec{r}\n    = \\int(\\vec{\\nabla}\\times\\vec{A})\\cdot d\\vec{s}.\n\\end{align}\nLet the line integral Lie in hte $xy$ plane.\n\\begin{align}\n    d\\vec{r}\n    &= dx \\hat{e}_x + dy\\hat{e}_y\\\\\n    \\vec{A} &= A_x \\hat{e}_x + A_y \\hat{e}_y.\n\\end{align}\nThen\n\\begin{align}\n    \\oint_C \\left(\n        A_x\\,dx + A_y\\,dy\n    \\right)\n    = \\int\\left(\n    \\frac{\\partial A_y}{\\partial x}\n    - \\frac{\\partial A_x}{\\partial y}\n    \\right)\\,dx\\,dy\n\\end{align}\nif we go around the path counterclockwise.\nNotice this is the same form as before.\n\nLet us apply this to the two line integrals in Equation~\\ref{eqn:1}.\nFor the first integral,\nset $A_x = v$ and $A_y = -v$.\nNotice that by the Cauchy-Riemann condition,\n\\begin{align}\n    \\oint\\left(\n        u\\,dx - v\\,dy\n    \\right)\n    =\n    \\int\\left(\n    -\\frac{\\partial v}{\\partial x}\n    - \\frac{\\partial u}{\\partial y}\n    \\right)\\,dx\\,dy\n    =0.\n\\end{align}\nFor the second integral, set\n$A_x = v$ and $A_y = u$.\nThen by the other Cauchy-Riemann condition,\n\\begin{align}\n    \\oint\\left(\n        v\\,dx + u\\,dy\n    \\right)\n    =\n    \\int\\left(\n    \\frac{\\partial u}{\\partial x}\n    - \\frac{\\partial v}{\\partial y}\n    \\right)\\,dx\\,dy\n    =0.\n\\end{align}\nHence\n\\begin{align}\n    \\oint_C f(z)\\,dz = 0\n\\end{align}\nSuppose $C$ is made up of two paths $C_1$ and $C_2$.\n\\begin{align}\n    \\int_{C_1} f(z)\\,dz\n    - \\int_{C_2} f(z)\\,dz\n    = \\oint_C f(z)\\,dz\n    = 0.\n\\end{align}\nHence\n\\begin{align}\n    \\int_{C_1}f(z)\\,dz\n    = \\int_{C_2}f(z)\\,dz\n\\end{align}\nWhat Cauchy is saying is that this integral is actually a function of the final\npoint for fixed $A$\n\\begin{align}\n    \\int_{A}^{P}f(z)\\,dz = F(P).\n\\end{align}\n\n\n\\section{Cauchy's Integral Formula}\nCauchy is saying if I know the values of an analytic function on the boundary of\na simply connected region in $\\mathbf{C}$,\nthen I can tell you the value of the function anywhere inside the region.\n\nI was shocked when I first saw this theorem.\nThere's no analogue of this for real functions.\n\nIf you consider a complex function\n\\begin{align}\n    f(z) = u(x, y) + i v(x, y).\n\\end{align}\nThen you can solve Laplace's equation in 2D if you know the boundary.\n\\begin{align}\n    \\frac{\\partial^2 u}{\\partial x^2}\n     + \\frac{\\partial^2 v}{\\partial y^2}\n     = 0.\n\\end{align}\nThat's the application we're interested in.\n\nCauchy's integral formula states that if $f(z)$ is analytic in a simply\nconnected domain $D$,\nthen for any point $z=a$ in $D$ and any closed path $C$ in $D$ which encloses\nthe point $a$,\nwe have\n\\begin{align}\n    \\oint_C \\frac{f(z)}{z - a} \\, dz = 2\\pi i f(a)\n\\end{align}\nwhere the integration is being taken in the counterclockwise sense.\nIf you know the values on the boundary then you know the value of any point\ninside the region.\nThe reason it's possible is because $f$ is composed of harmonic functions.\nIn principle,\nif you have the values on the boundary for Laplace's equation,\nthen in principle you have enough information to solve Laplace's equation in the\nbulk.\n\nDefine\n\\begin{align}\n    \\phi(z) := \\frac{f(z)}{z - a}.\n\\end{align}\nThis is analytic everywhere in $D$ except at $z=a$.\nWe need to evaluate\n\\begin{align}\n    \\oint_C \\phi(z)\\, dz.\n\\end{align}\nLet us go counterclockwise.\nThen around $a$ draw a small circle,\nand I call that circle $C'$.\nThen I make a cut between $C$ and $C'$.\nLet there be a point $A$ on $C$ and $B$ on $C'$.\nMake a cut along $AB$.\nIntegrate $\\phi(z)$ along the closed path from $A$ to $C$ to $B$\naround $C'$ and then back to $A$.\nThe contribution from the cut vanishes since we integrate first in one\ndirection and then again in the opposite direction.\n\\begin{align}\n    \\oint_C \\phi(z)\\, dz + \\oint_{C'}\\phi(z)\\, dz = 0\n\\end{align}\nwhere we are going counterclockwise in $C$ and clockwise in $C'$.\nThen\n\\begin{align}\n    \\oint_{C}\\phi(z)\\,dz = \\oint_{C'}\\phi(z)\\,dz\n\\end{align}\nwhen both integrals are performed counterclockwise.\nAlong the circle $C'$,\nwe have\n$z=a + \\rho e^{i\\theta}$.\nRemember this is a circle and the differential is\n\\begin{align}\n    dz = i\\rho e^{i\\theta} \\,d\\theta\n\\end{align}\nSo the integral is\n\\begin{align}\n    \\oint_{C}\\phi(z)\\,dz &= \\oint_{C'}\\phi(z)\\,dz\\\\\n    &=\n    \\oint_{C'}\\frac{f(z)}{z - a} \\,dz\\\\\n    &= \\int_{0}^{2\\pi}\\frac{f(z)}{\\rho e^{i\\theta}}\\left( \n        i\\rho e^{i\\theta}\n    \\right) \\,d\\theta\\\\\n    &= i\\int_{0}^{2\\pi} f(z)\\, d\\theta\n\\end{align}\nbut because the circle is so small $f(z)\\to f(a)$ and so\n\\begin{align}\n    \\oint_C \\phi(z)\\, dz\n    = \\oint \\frac{f(z)}{z - a}\\,dz\n    = 2\\pi i f(a).\n\\end{align}\n\nThe following is useful for integer $n$.\n\\begin{align}\n    \\oint \\frac{dz}{{(z - z_0)}^n}\n    =\n    \\begin{cases}\n        2\\pi i & \\text{if } n = 1\\\\\n        0 & \\text{otherwise}\n    \\end{cases}\n\\end{align}\nYou can do this by using $z = z_0 + \\rho e^{i\\theta}$\nand doing the integral explicitly on a circle.\nIf it's not a circle,\nuse the same trick with the cut like how we proved the Cauchy integral formula.\n\n\\section{Liouville's theorem}\nEvery analytic function is either constant or blows up somewhere in the complex\nplane.\n\\begin{theorem}\n    If $f(z)$ is analytic and bounded in absolute value in the entire complex\n    plane,\n    then it must be a constant.\n\\end{theorem}\n\\begin{proof}\n    Assume $|f(z)|$ is bounded,\n    so that $|f(z)| < M$\n    for all $z\\in\\mathbb{C}$.\n    Since $f(z)$ is analytic,\n    it can be expanded like\n    \\begin{align}\n        f(z) &= \\sum_{n=0}^{\\infty} a_n z^{n}.\n    \\end{align}\n    By the Cauchy integral formula,\n    \\begin{align}\n        |a_n|\n        &= \\left|\\frac{1}{2\\pi i} \\oint \\frac{f(z)}{z^{n + 1}}\\, dz\\right|\\\\\n        &=\n        \\left|\n            \\sum_\\gamma \\frac{1}{2\\pi i}\n            \\frac{f(z)}{z_{\\gamma}^{n + 1}}\n            \\Dlta z_\\gamma\n        \\right|\\\\\n        &\\le\n        \\sum_{\\gamma}\n        \\left|\\frac{1}{2\\pi i}\\right|\n        \\left|\\frac{f(z_\\gamma)}{z_\\gamma^{n + 1}}\\right|\n        \\left|\\Delta z_\\gamma \\right|\\\\\n        &\\le\n        \\sum_{\\gamma}\n        \\frac{1}{2\\pi}\n        \\frac{f(z)|_{\\max}}{R^{n + 1}} |\\Delta z_\\gamma|\\\\\n        &\\le \\frac{1}{2\\pi} \\frac{f(z)|_{\\max}}{R^{n + 1}} 2\\pi R\n    \\end{align}\n    where the contour is a circle centred at the origin and\n    we have used the identities\n    \\begin{align}\n        |ab| &= |a||b|\\\\\n        |a + b| &\\le |a| + |b|\n    \\end{align}\n    Hence\n    \\begin{align}\n        |a_n| \\le \\frac{M}{R^n}\n    \\end{align}\n    for some constant $M$.\n    We can take $R$ to be arbitrarily large.\n    As $R\\to\\infty$, $a_n\\to 0$ for $n\\ge 1$.\n    Hence $f(z)=a_0$,\n    which is a constant.\n\\end{proof}\n", "meta": {"hexsha": "a5faa44a6a8dd21a2cecfd071a8bc22524763b50", "size": 7128, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys610/lecture3.tex", "max_stars_repo_name": "ehua7365/umdphysnotes", "max_stars_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-11T12:53:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-11T12:53:46.000Z", "max_issues_repo_path": "phys610/lecture3.tex", "max_issues_repo_name": "ehua7365/umdphysnotes", "max_issues_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "phys610/lecture3.tex", "max_forks_repo_name": "ehua7365/umdphysnotes", "max_forks_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.9529411765, "max_line_length": 80, "alphanum_fraction": 0.6084455668, "num_tokens": 2522, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.8705972583359805, "lm_q1q2_score": 0.7328911074037706}}
{"text": "\\section{ReLU Fourier representation}\\label{sec:error2}\nRather than using general Fourier transform  to represent\n$e^{i\\omega\\cdot x}$ in terms of $\\sigma(\\omega\\cdot x+b)$, \n\\cite{klusowski2016uniform} gave a different method to represent\n$e^{i\\omega\\cdot x}$ in terms of $(\\omega\\cdot x+b)_+^k$  for $k=1$\nand $2$.   The following lemma gives a generalization of this\nrepresentation for all $k\\ge 0$. \n\\begin{lemma}\\label{lm:talorcomplex}\nFor any $k\\ge0$ and $x\\in \\Omega$,\n\\begin{equation}  \ne^{i\\omega\\cdot x} =\\sum_{j=0}^k{(i\\omega\\cdot x)^{j}\\over j!} \n+\n{i^{k+1}\\over k!} \\|\\omega\\|^{k+1}\\int_{0}^T\\left[(\\bar \\omega\\cdot x - t)_+^ke^{i\\|\\omega\\|t}\n+(-1)^{k-1}(-\\bar \\omega\\cdot x - t)_+^ke^{-i\\|\\omega\\|t} \\right]dt.\n\\end{equation} \n\\end{lemma}\n\\begin{proof}  \nFor $|z|\\leq c$, by the Taylor expansion with integral remainder,\n\\begin{equation} \ne^{iz} = \\sum_{j=0}^k {(iz)^j\\over j!} + {i^{k+1}\\over k!} \\int_0^z e^{iu}(z-u)^kdu.\n\\end{equation}\nNote that \n$$\n(z-u)^k=(z-u)^k_+ - (u-z)^k_+.\n$$\nIt follows that\n\\begin{equation}\n\\begin{split}\n\\int_{0}^z (z-u)^ke^{iu} du=&\\int_{0}^z (z-u)_+^ke^{iu} du + \\int_{0}^z (-1)^k(u-z)_+^ke^{iu} du\n\\\\\n=&\\int_{0}^z (z-u)_+^ke^{iu} du + \\int_{0}^{-z} (-1)^{k-1}(-u-z)_+^ke^{-iu} du\n\\\\\n=&\\int_{0}^c (z-u)_+^ke^{iu} du + (-1)^{k-1}(-u-z)_+^ke^{-iu} du.\n\\end{split}\n\\end{equation}\nThus,\n\\begin{equation}  \ne^{iz} - \\sum_{j=0}^k{(iz)^{j}\\over j!} \n= \n{i^{k+1}\\over k!}\\int_{0}^c\\left[(z - u)_+^ke^{iu} + (-1)^{k-1}(-z - u)_+^ke^{-iu} \\right]du.\n\\end{equation}  \nLet \n\\begin{equation}\\label{baromega}\nz=\\omega\\cdot x,\\quad u=\\|\\omega\\|t,\\quad \\bar \\omega={\\omega\\over \\|\\omega\\|}.\n\\end{equation}\nSince $\\|x\\| \\le T$ and $|\\bar \\omega \\cdot x|\\le T$, we obtain\n\\begin{equation}  \ne^{i\\omega\\cdot x} - \\sum_{j=0}^k{(i\\omega\\cdot x)^{j}\\over j!} \n= \n{i^{k+1}\\over k!} \\|\\omega\\|^{k+1}\\int_{0}^T\\left[(\\bar \\omega\\cdot x - t)_+^ke^{i\\|\\omega\\|t}\n+(-1)^{k-1}(-\\bar \\omega\\cdot x - t)_+^ke^{-i\\|\\omega\\|t} \\right]dt,\n\\end{equation} \nwhich completes the proof.\n\\end{proof}\n\nSince $\nu(x) = {1\\over (2\\pi)^d}\\int_{\\mathbb{R}^d} e^{i\\omega\\cdot x}\\hat{u}(\\omega)d\\omega\n$\nand \n$\n \\partial^\\alpha u(x)=\\int_{\\mathbb{R}^d} i^{|\\alpha|}\\omega^\\alpha e^{i\\omega\\cdot x}\\hat{u}(\\omega)d\\omega,\n$\n\\begin{eqnarray}\n \\partial^\\alpha u(0)x^\\alpha=\\int_{\\mathbb{R}^d} i^{|\\alpha|}\\omega^\\alpha x^\\alpha\\hat{u}(\\omega)d\\omega.\n\\end{eqnarray} \nNote that $\\displaystyle (\\omega\\cdot x)^j=\\sum_{|\\alpha|=j}{j!\\over \\alpha !}\\omega^\\alpha x^\\alpha $. It follows that\n\\begin{equation}\n\\sum_{|\\alpha|=j}{1\\over \\alpha!} \\partial^\\alpha u(0) x^\\alpha=i^j\\sum_{|\\alpha|=j}{1\\over \\alpha!} \\int_{\\mathbb{R}^d} \\omega^\\alpha x^\\alpha\\hat{u}(\\omega)d\\omega\n={1\\over j!}  \\int_{\\mathbb{R}^d} (i\\omega\\cdot x)^j \\hat{u}(\\omega)d\\omega.\n\\end{equation} \nLet $\\hat{u}(\\omega)=|\\hat{u}(\\omega)|e^{ib(\\omega)}$. Then, $e^{i\\|\\omega\\|t}\\hat{u}(\\omega) = |\\hat{u}(\\omega)|e^{i(\\|\\omega\\|t + b(\\omega))}$.\nBy Lemma \\ref{lm:talorcomplex},\n\\begin{equation}\\label{eq:fftaylor}\n\\begin{split}\n&u(x) - \\sum_{|\\alpha|\\le k}{1\\over \\alpha!} \\partial^\\alpha u(0) x^\\alpha\n\\\\\n= &\\int_{\\mathbb{R}^d} \\big (e^{i\\omega\\cdot x}-\\sum_{j=0}^k{1\\over j!}(i\\omega\\cdot x)^j\\big )\\hat{u}(\\omega)d\\omega.\n\\\\\n=&{\\rm Re} \\bigg ({i^{k+1}\\over k!}\\int_{\\mathbb{R}^d} \\int_{0}^T\\left[(\\bar \\omega\\cdot x - t)_+^ke^{i\\|\\omega\\|t}\n+(-1)^{k-1}(-\\bar \\omega\\cdot x - t)_+^ke^{-i\\|\\omega\\|_{\\ell_1}t} \\right]\\hat{u}(\\omega)\\|\\omega\\|^{k+1}dt d\\omega\\bigg )\n\\\\\n=& {1\\over k!}\\int_{\\{-1,1\\}}\\int_{\\mathbb{R}^d} \\int_{0}^T (z\\bar \\omega\\cdot x - t)_+^k s(zt,\\omega)  |\\hat{u}(\\omega)|\\|\\omega\\|^{k+1}dtd\\omega dz\n\\end{split}\n\\end{equation}\nwith $\\int_{\\{-1, 1\\}} r(z) dz = r(-1) + r(1)$ and\n\\begin{equation} \ns(zt,\\omega)= \n\\begin{cases}\n(-1)^{k+1\\over 2}\\cos(z\\|\\omega\\|t + b(\\omega)) & k \\text{ is odd},\n\\\\\n(-1)^{k+2\\over 2}\\sin(z\\|\\omega\\|t + b(\\omega)) & k \\text{ is even}.\n\\end{cases}\n\\end{equation} \nDefine $G=\\{-1,1\\}\\times [0,T]\\times \\mathbb{R}^{d}$, $\\theta=(z, t, \\omega)\\in G$,\n\\begin{equation}\\label{eq:straglam}\ng(x,\\theta)= (z\\bar \\omega\\cdot x - t)_+^k {\\rm sgn} s(zt,\\omega),\\qquad  \\rho(\\theta) = {1\\over (2\\pi)^d}|s(zt,\\omega)||\\hat{u}(\\omega)|\\|\\omega\\|^{k+1},\\quad \\lambda(\\theta)={\\rho(\\theta)\\over \n\\|\\rho\\|_{L^1(G)}}.\n\\end{equation} \n\nThen \\eqref{eq:fftaylor} can be written as \n\\begin{equation}\nu(x) = \\sum_{|\\alpha|\\le k}{1\\over \\alpha!}D^\\alpha u(0) x^\\alpha\n+ {\\nu\\over k!}\\int_G  g(x, \\theta)\\lambda(\\theta)d\\theta,  \n\\end{equation}   \nwith $\\nu=\\int_G \\rho(\\theta)d\\theta$. In summary, we have the following lemma.\n \n\n\n\\begin{lemma}\\label{lm:probabilityexpan}\nIt holds that\n\\begin{equation}\\label{ReLUm}\nu(x) = \\sum_{|\\alpha|\\le k}{1\\over \\alpha!} \\partial^\\alpha u(0) x^\\alpha\n+ {\\nu\\over k!}r_k(x),\\qquad x\\in \\Omega\n\\end{equation}  \nwith $\\nu=\\int_G \\rho(\\theta)d\\theta$ and \n\\begin{equation}\\label{ReLUrm}\nr_k(x) = \\int_G  g(x, \\theta)\\lambda(\\theta)d\\theta,\\qquad G=\\{-1,1\\}\\times [0,T]\\times \\mathbb{R}^{d},\n\\end{equation}  \nand  $g(x,\\theta)$, $\\rho(\\theta)$  and $\\lambda(\\theta)$ defined in \\eqref{eq:straglam}.\n\\end{lemma}\n\nAccording to \\eqref{eq:straglam}, the main ingredient $(z\\bar\n\\omega\\cdot x - t)_+^k$ of $g(x,\\theta)$ only includes the direction\n$\\bar\\omega$ of $\\omega$ which belongs to a bounded domain\n$\\mathbb{S}^{d-1}$. Thanks to the continuity of $(z\\bar \\omega\\cdot x\n- t)_+^k$ with respect to $(z, \\bar\\omega, t)$ and the boundedness of\n$\\mathbb{S}^{d-1}$, the application of the stratified sampling to the\nresidual term of the Taylor expansion leads to the \napproximation property in Theorem \\ref{est:stratify}.\n\n\\begin{theorem}\\label{est:stratify}\nAssume $u\\in B^{k+1}(\\Omega)$\n%$$\n% \\int_{\\mathbb{R}^{d}} |\\hat{f}(\\omega)|\\|\\omega\\|^{m+1} d\\omega<\\infty.\n%$$\nThere exist $\\beta_j\\in [-1, 1]$, $\\|\\bar \\omega_j\\|=1$, $t_j\\in [0,T]$ such that \n\\begin{equation}\nu_N(x)= \\sum_{|\\alpha|\\le k}{1\\over \\alpha!} \\partial^\\alpha u(0) x^\\alpha + {2\\nu\\over k!N}\\sum_{j=1}^{N}\\beta_j (\\bar \\omega_j\\cdot x - t_j)_+^k\n\\end{equation} \nwith $\\nu=\\int_G \\rho(\\theta)d\\theta$ and $\\rho(\\theta)$  defined in \\eqref{eq:straglam} \nsatisfies the following estimate\n\\begin{equation}\n\\|u - u_N \\|_{H^m(\\Omega)} \\lesssim  \n\\begin{cases}\n N^{-{1\\over 2}-{1\\over d}}\\|u\\|_{B^{k+1}(\\Omega)},&m< k,\n\\\\\nN^{-{1\\over 2}}\\|u\\|_{B^{k+1}(\\Omega)}& m=k.\n\\end{cases} \n\\end{equation} \n%Especially,\n%\\begin{equation}\n%\\|u - u_N \\|_{L^2(\\Omega)} \\leq {(2T)^k|\\Omega|^{1\\over 2}\\over (k-1)!} N^{-{1\\over 2}-{1\\over d}}\\|u\\|_{\\mathcal B^{k+1, q}(\\Omega)}.\n%\\end{equation} \n%\\begin{equation}\n%\\|D^\\beta (f(x)- f_n(x))\\|_{L^2(\\Omega)}\\le \\sqrt{2^{m-k-2}(2m-k)\\over k!(m-k)!}|\\Omega|^{1/2} n^{-{1\\over 2}-{1\\over d}},\\quad |\\beta|=k\\le m.\n%\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\nLet\n$$\nu_N(x)=  \\sum_{|\\alpha|\\le k}{1\\over \\alpha!} \\partial^\\alpha u(0) x^\\alpha + {\\nu\\over k!} r_{k,N}(x), \\qquad r_{k,N}(x)={1\\over N}\\sum_{j=1}^{N}\\beta_j (\\bar \\omega_j\\cdot x - t_j)_+^k.\n$$\nRecall  the representation  of $u(x)$ in \\eqref{ReLUm} and $r_k(x)$ in \\eqref{ReLUrm}. It holds that\n\\begin{equation}\nu(x) - u_N(x)={2\\nu\\over k!} (r_k(x) - r_{k,N}(x)).\n\\end{equation}\nBy Lemma \\ref{lem:stratifiedapprox}, for any decomposition $\\displaystyle G=\\cup_{i=1}^N G_i$, there exist $\\{\\theta_i\\}_{i=1}^N$ and $\\{\\beta_i\\}_{i=1}^N\\in [0, 1]$ such that \n\\begin{equation}\n\\| \\partial_x^\\alpha (u - u_N)\\|_{L^2(\\Omega)} = {\\nu\\over k!}\\|  \\partial_x^\\alpha (r_k - r_{k,N})\\|_{L^2(\\Omega)} \\leq {1\\over k!N^{1/2}}\\max_{1\\le j\\le n}\\sup_{\\theta_{j},\\theta_{j}'\\in G_j} \\|  \\partial_x^\\alpha \\big(g(x,\\theta_j) - g(x,\\theta_j')\\big)\\|_{L^2(\\Omega)}.\n\\end{equation}\n\\iffalse\nConsider a $\\epsilon$-covering decomposition $G=\\cup_{i=1}^M G_i$ as follows. \nThe variable $z$ is in the set $\\{-1,1\\}$, which can be divided into two subsets $\\{-1\\}$ and $\\{1\\}$. \nGiven a positive integer $N$, for the random variable $t$, the interval  $ [0,T]$ can be divided into $n_t$ subintervals $\\{G_i^t\\}_{i=1}^{n_t}$ such that \n$$\n|t-t'|<{1\\over 2}N^{-{1\\over d}}\\quad t,t'\\in G_i^t,\\quad 1\\leq i\\leq n_t\n$$ \nfor $n_t>2\\lceil T N^{1\\over d}\\rceil$. \nFor variable $\\bar \\omega=\\omega/\\|\\omega\\|\\in \\mathbb{S}^{d-1}$ where $\\mathbb{S}^{d-1}=\\{\\bar \\omega\\in \\mathbb{R}^d: \\|\\bar \\omega\\|=1\\}$. Note that $\\mathbb{S}^{d-1}$ can be divided into $n_\\alpha$ subdomains $\\{G_i^s \\}_{i=1}^{n_s}$ such that\n$$\n\\|\\bar \\omega- \\bar \\omega'\\|\\leq {1\\over 2}N^{-{1\\over d}}\\qquad \\bar \\omega, \\bar \\omega' \\in G_i^s,\\quad 1\\leq i\\leq n_s\n$$\nfor $(2N^{1\\over d})^{d-1}\\leq n_s\\leq \\lceil (5N^{1\\over d})^{d-1}\\rceil$ \\cite{klusowski2016uniform}.\nThen \n$$\nG=\\displaystyle \\cup \\{G_{ijk\\ell}: 1\\leq i\\leq 2,\\ 1\\leq j\\leq n_t,\\ 1\\leq k\\leq n_s,\\ 1\\le \\ell\\le 2\\}\n$$\nwith \n\\begin{equation}\nG_{ijk\\ell} = \\{(z, t, \\omega): z=(-1)^i,\\ t\\in G_j^t, \\bar \\omega \\in G_k^s,\\ {\\rm sgn} s(zt,\\omega)=(-1)^\\ell\\}.\n\\end{equation}\nDenote this decomposition of $G$ by $G=\\cup_{i=1}^{M} G_i$ with $M=4n_sn_t\\le 2^{d}N$. For each $G_i$,\n\\fi\nConsider a $\\epsilon$-covering decomposition $G=\\cup_{i=1}^N G_i$  such that \n\\begin{equation}\nz=z',\\ |t-t'|<\\epsilon,\\ \\|\\bar \\omega  - \\bar \\omega'\\|_{\\ell^1}<\\epsilon\\qquad \\forall \\theta=(z, t, \\omega),\\ \\theta'=(z', t', \\omega')\\in G_i\n\\end{equation}\nwhere $\\bar\\omega$ is defined in \\eqref{baromega}. \nFor any $\\theta_i, \\theta'_i\\in G_i$,  \n$$\n| \\partial_x^\\alpha \\big (g(x,\\theta_i) - g(x,\\theta_i')\\big )| = {k!\\over (k-|\\alpha|)!} | g_\\alpha(x, \\bar\\omega, t) -  g_\\alpha(x, \\bar\\omega', t')| \n$$\nwith \n\\begin{equation}\n g_\\alpha(x, \\bar\\omega, t)  = (z\\bar \\omega\\cdot x-t)^{k-|\\alpha|}_+\\bar \\omega^\\alpha.\n \\end{equation} \n Since\n$$\n|\\partial_{\\bar\\omega_i}  g_\\alpha|\\le (2T)^{m-|\\alpha|-1}\\big ((k-|\\alpha|)x_i + 2T\\alpha_i\\big ), \\qquad |\\partial_t  g_\\alpha|\\le (k-|\\alpha|)(2T)^{k-|\\alpha|-1},\n$$\nit follows that\n\\begin{equation}\n\\big | \\partial_x^\\alpha \\big (g(x,\\theta_i) - g(x,\\theta_i')\\big )\\big | \\le {k!\\over (k-|\\alpha|)!}(2T)^{k-|\\alpha|-1}   \\bigg ( (k-|\\alpha|)(|x|_{\\ell_1}+1) + 2T|\\alpha |\\bigg ) \\epsilon.\n\\end{equation}\nThus, by Lemma \\ref{lem:stratifiedapprox}, if $m=|\\alpha|<k$,\n\\begin{equation}\n\\|  \\partial_x^\\alpha (u - u_N)\\|_{L^2(\\Omega)} \\le {|\\Omega|^{1/2}\\over (k-|\\alpha|)!}(2T)^{k-|\\alpha|-1}   \\bigg ( (k-|\\alpha|)(T+1) + 2T|\\alpha |\\bigg )N^{-{1\\over 2}}\\epsilon.\n\\end{equation}\nNote that $\\epsilon \\sim N^{-{1\\over d}}$. There exist $\\theta_{i,j}$ such that for any $0\\le k< m$,\n\\begin{equation}\n\\| u - u_N\\|_{H^k(\\Omega)} \\le  C(m,k,\\Omega)\\nu N^{-{1\\over 2}-{1\\over d}}\n\\end{equation}\nwith $\\nu\\le \\|u\\|_{B^{k+1}(\\Omega)}$ and\n\\begin{equation}\\label{equ:defcmko}\nC(m,k,\\Omega)=|\\Omega|^{1/2}\\bigg (\\sum_{|\\alpha|\\le k}{1\\over (k-|\\alpha|)!}(2T)^{k-|\\alpha|-1}   \\big ( (k-|\\alpha|)(T+1) + 2T|\\alpha |\\big )\\bigg )^{1/2}.\n\\end{equation} \nIf $m=|\\alpha|=k$,\n$$\n\\max_{1\\le j\\le M}\\sup_{\\theta_{j},\\theta_{j}'\\in G_j} \\| D_x^\\alpha \\big(g(x,\\theta_j) - g(x,\\theta_j')\\big)\\|_{L^2(\\Omega)}\\lesssim 1.\n$$\nThis leads to \n\\begin{equation}\n\\| u - u_N\\|_{H^m(\\Omega)} \\le  C(m,k,\\Omega)\\nu N^{-{1\\over 2}}\\quad \\mbox{for }\\ k=m.\n\\end{equation}\nNote that $u_N$ defined above can be written as\n$$\nu_N(x)=  \\sum_{|\\alpha|\\le k}{1\\over \\alpha!} \\partial^\\alpha u(0) x^\\alpha + {1\\over k!N}\\sum_{j=1}^{N}\\beta_j (\\bar \\omega_j\\cdot x - t_j)_+^k\n$$ \nwith $\\beta_j\\in [-1, 1]$,\nwhich completes the proof.\n\\end{proof}\n\n\\begin{lemma}\nThere exist $\\alpha_i$, $\\omega_i$, $b_i$ and $N\\le 2\\begin{pmatrix} k+d\\\\k\\end{pmatrix}$\nsuch that\n$$\n \\sum_{|\\alpha|\\le m}{1\\over \\alpha!} \\partial^\\alpha u(0) x^\\alpha = \\sum_{i=1}^N\\alpha_i (\\omega_i\\cdot x + b_i)_+^k\n$$ \nwith $\nx^\\alpha = x_1^{\\alpha_1}x_2^{\\alpha_2}\\cdots x_d^{\\alpha_d},\\quad \\alpha!=\\alpha_1!\\alpha_2!\\cdots \\alpha_d!.\n$\n\\end{lemma}\nThe above result can be found in \\cite{he2020preprint}\n\nA combination of Theorem \\ref{est:stratify} and the above the lemma gives the following estimate in Theorem \\ref{th:stra}.\n\\begin{theorem} \\label{th:stra}\nSuppose $u\\in B^{k+1}(\\Omega)$.\nThere exist $\\beta_j, t\\in \\mathbb{R}$, $\\omega_j \\in \\mathbb{R}^d$ such that \n\\begin{equation}\nu_N(x)= \\sum_{j=1}^{N}\\beta_j (\\bar \\omega_j\\cdot x - t_j)_+^k\n\\end{equation} \nsatisfies the following estimate\n\\begin{equation}\\label{d}\n\\|u- u_N \\|_{H^m(\\Omega)} \\lesssim \n\\begin{cases}\nN^{-{1\\over 2}-{1\\over d}}\\|u\\|_{B^{k+1}(\\Omega)},\\qquad k> m,\n\\\\\nN^{-{1\\over 2}}\\|u\\|_{B^{k+1}(\\Omega)},\\qquad k= m,\n\\end{cases}\n\\end{equation} \nwhere $\\bar\\omega$ is defined in \\eqref{baromega}.\n\\end{theorem}\n\n\\begin{remark}\nWe make the following comparisons:\n\\begin{enumerate}\n\\item The results in \\ref{sec:Bsplines} are for activation functions $\\sigma=b_k$, while the results in Section \\ref{sec:error2} are for activation functions $\\sigma={\\rm ReLU}^k$.\n\\item By \\eqref{splinetorelu}, the following relation obviously holds\n$$\nV_N(b_k)\\subset V_{N+k}({\\rm ReLU}^k),\n$$\nwhere \n\\begin{equation}\n\\label{VkN}\nV_{N+k}({\\rm ReLU}^k)=\\left\\{\\sum_{i=1}^Na_i(w_i\\cdot x+b_i)_+^k, a_i, b_i\\in\\mathbb R^1, w_i\\in \\mathbb R^{1\\times d}\\right\\},\n\\end{equation}\nand $V_N(b_k)$ is the one hidden layer neuron network\nfunction class with activation function $b_k$.  Thus, asymptotically\nspeaking, the results that hold for $\\sigma=b_k$ also hold for\n$\\sigma={\\rm ReLU}^k$. \n\\end{enumerate}\n\\end{remark}\n\n\n\n\n\n\n", "meta": {"hexsha": "98d8473a4225498a9dcdeee7894b74cf193b2ff0", "size": 13113, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ReLUFourier.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/ReLUFourier.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/ReLUFourier.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.71, "max_line_length": 273, "alphanum_fraction": 0.6111492412, "num_tokens": 5704, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7328911061469198}}
{"text": "%!TEX root = ../main.tex\n\\documentclass[../main.tex]{subfiles}\n\\begin{document}\n\\subsection{First and Second Order Conditions of the Utility Maximization Problem}\\label{app:foc_soc_utility}\nStarting from the utility function in equation (\\ref{eq:two_task_utility}), this section presents the first and second derivative of the utility function $u_{i,t}$ w.r.t. choice parameter $\\lambda_{i,t}$. Based on these results, the first and second order conditions for a global maximum of the utility function can be identified.\\\\\n\\begin{align}\n\t\\intertext{Starting from the utility function in a setting with $J=2$ tasks.}\n\tu_{i,t} &= \\lambda_{i,t} \\tilde{w}_{i,t} - 2\\theta|b_i - \\lambda_{i,t}|^\\phi \\tag{\\ref{eq:two_task_utility}}\\\\\n\t\\intertext{Calculate the first derivative of utility w.r.t. task choice parameter $\\lambda_{i,t}$ by application of the chain rule.}\n\t\\frac{\\partial u_{i,t}}{\\partial \\lambda_{i,t}} &= \\tilde{w}_{i,t} - 2\\theta \\phi |b_i - \\lambda_{i,t}|^{\\phi-1} \\frac{\\partial}{\\partial \\lambda_{i,t}} [|b_i - \\lambda_{i,t}|^\\phi] \\nonumber \\\\\n\t\\intertext{Applying the derivation rules for absolute value functions:}\n\t{} &= \\tilde{w}_{i,t} + 2\\theta \\phi |b_i - \\lambda_{i,t}|^{\\phi-1} \\frac{b_i - \\lambda_{i,t}}{|b_i - \\lambda_{i,t}|} \\nonumber \\\\\n\t\\intertext{Finally, after some rearrangements:}\n\t{} &= \\tilde{w}_{i,t} + 2\\theta \\phi \\frac{|b_i - \\lambda_{i,t}|^\\phi}{b_i - \\lambda_{i,t}} \\label{eq:first_derivative}\n\t\\intertext{Notice that this derivative is not defined at $b_i = \\lambda_{i,t}$.}\n\t\\intertext{Continuing from equation (\\ref{eq:first_derivative}), now calculate the second derivative of the utility function w.r.t. task choice parameter $\\lambda_{i,t}$ by application of the division rule.}\n\t\\frac{\\partial^2 u_{i,t}}{\\partial \\lambda_{i,t}^2} &= 2\\theta \\phi \\left(\\frac{\\frac{\\partial }{\\partial \\lambda_{i,t}} [|b_i - \\lambda_{t,i}|^\\phi] (b_i - \\lambda_{i,t}) - |b_i - \\lambda_{i,t}|^\\phi \\frac{\\partial}{\\partial \\lambda_{i,t}} [b_i - \\lambda_{i,t}]}{(b_i - \\lambda_{i,t})^2} \\right) \\nonumber \\\\\n\t\\intertext{By application of the chain rule and derivation rules for absolute value functions:}\n\t{} &= 2 \\theta \\phi \\left(\\frac{- \\phi |b_i - \\lambda_{i,t}|^\\phi + |b_i - \\lambda_{i,t}|^\\phi}{(b_i - \\lambda_{i,t})^2} \\right) \\nonumber \\\\\n\t\\intertext{Rearranging:}\n\t{} &= 2 \\theta \\phi (1 - \\phi) \\frac{|b_i- \\lambda_{i,t}|^\\phi}{(b_i - \\lambda_{i,t})^2} \\label{eq:second_derivative}\n\\end{align}\nFrom equation (\\ref{eq:second_derivative}) it can be seen immediately that the second derivative of the utility function w.r.t. task choices $\\lambda_{i,t}$ is (strictly) positive for penalty exponents $\\phi$ (strictly) larger than one, resulting in a (strictly) concave utility function. Analogously, penalty exponents (strictly) smaller than one will result in a (strictly) convex utility function.\\\\\nSimilarly to the first derivative, the second derivative is not defined at $b_i = \\lambda_{i,t}$.\n\n\n\\end{document}", "meta": {"hexsha": "fff72c575b44175e8024f78c04134a268a4d0a48", "size": 2949, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "latex_files/Appendix/foc_soc_utility.tex", "max_stars_repo_name": "DaLueke/estimating_skill_prices", "max_stars_repo_head_hexsha": "bc895c8b0b0439f86c1f2dd53b34108f1eaf69a1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "latex_files/Appendix/foc_soc_utility.tex", "max_issues_repo_name": "DaLueke/estimating_skill_prices", "max_issues_repo_head_hexsha": "bc895c8b0b0439f86c1f2dd53b34108f1eaf69a1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "latex_files/Appendix/foc_soc_utility.tex", "max_forks_repo_name": "DaLueke/estimating_skill_prices", "max_forks_repo_head_hexsha": "bc895c8b0b0439f86c1f2dd53b34108f1eaf69a1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 109.2222222222, "max_line_length": 402, "alphanum_fraction": 0.7002373686, "num_tokens": 926, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.8418256492357359, "lm_q1q2_score": 0.7328911050479345}}
{"text": "\\section{Entropy Regularization of Optimal Transport}\n\\label{sec:3}\n\\subsection{Background and Formulation}\n\\subsubsection{Kantorovich formulation of optimal transport}\n\\cite{COT} introduces the Kantorovich formulation of optimal transport (Kantorovich's relaxation). For two vectors $\\mu\\in\\mbR^m$ and $\\nu\\in\\mbR^n$, which satisfies $\\mbone_n^T\\mu=\\mbone_m^T\\nu$, we consider the following set of coupling matrices\n\\begin{equation}\nU(\\mu, \\nu) \\triangleq \\left\\{\\pi\\in\\mbR^{m\\times n}_+: \\pi\\mbone_n = \\mu, \\pi^T\\mbone_m=\\nu \\right\\}\n\\end{equation}\nwhere we use the following matrix-vector notation\n$$\n\\pi\\mbone_n  = (\\sum_j \\pi_{i,j})_i\\in\\mbR^m, \\quad \\pi\\mbone_m  = (\\sum_i \\pi_{i,j})_j\\in\\mbR^n,\n$$\n\nThe Kantorovich's optimal transport problem reads\n\\begin{equation}\n\\label{equ:kot}\nL_\\mfc(\\mu,\\nu)\\triangleq \\min\\limits_{\\pi\\in U(\\mu, \\nu)}\\la C,\\pi\\ra\\triangleq\\sum_{i,j}C_{i,j}\\pi_{i,j}\n\\end{equation}\nTherefore, problem \\ref{equ:kot} is equivalent to the standard form of LP \\ref{lp}. \n\n\\subsubsection{Entropy regularization}\nFor a coupling matrix $\\pi \\in U(\\mu, \\nu)$, the discrete entropy of $\\pi$ is defined as\n\\begin{equation}\nH(\\pi)\\triangleq-\\sum_{i,j}\\pi_{i,j}(\\log(\\pi_{i,j})-1)\n\\end{equation}\nwith an analogous definition for vectors, with the convention that $H(\\pi) = -\\infty$ if one of the entries $\\pi_{i,j}$ is negative. Although discrete entropy is defined on matrices with positive entry, with $\\lim\\limits_{x\\to0+}x(\\log x-1)=0$, we can extend its definition to  matrices with non-negative entry. And we have\n$$\nH(\\pi)=-\\sum_{\\pi_{i,j}\\geqslant0}\\pi_{i,j}(\\log(\\pi_{i,j})-1)\n$$\nSuppose $M=\\min\\{\\|\\mu\\|_\\infty, \\|\\nu\\|_\\infty\\}$, then we have $\\pi_{i,j}\\leqslant\\min\\{\\mu_i, \\nu_j\\}\\leqslant M$. The function $H(\\pi)$ is then $1/M$-strongly convex, because its Hessian is $\\p^2H(\\pi)=-\\diag(1/\\pi_{i,j})$. \n\nThe idea of entropic regularization of optimal transport is to use $-H$ as a regularizing function to obtain approximate solutions to the Kantorovich's optimal transport problem \\ref{equ:kot}. \n\n\\begin{equation}\n\\label{equ:erot}\nL^\\epsilon_C(\\mu,\\nu)\\triangleq \\min\\limits_{\\pi\\in U(\\mu, \\nu)}\\la C,\\pi\\ra-\\epsilon H(\\pi)\n\\end{equation}\n\nThe convergence of the solution of that regularized problem towards an optimal solution of the original linear program has been studied by \\cite{aaote}. \n\\begin{proposition}[Convergence with $\\epsilon$]\n\\label{sh_cvg}\nThe unique solution $\\pi^\\epsilon$ of \\ref{equ:erot} converges to the optimal solution with maximal entropy within the set of all optimal solutions of the Kantorovich problem, namely\n\\begin{equation}\n\\label{sh_limit}\n\\pi^\\epsilon\\to\\arg\\min\\limits_\\pi\\{-H(\\pi): \\pi\\in U(\\mu,\\nu), \\la\\pi, C\\ra=L_C(\\mu,\\nu)\\}, \\quad \\epsilon\\to0\n\\end{equation}\nso that in particular\n$$\nL^\\epsilon_C(\\mu,\\nu)\\to L_C(\\mu,\\nu), \\quad \\epsilon\\to0\n$$\n\\end{proposition}\n\\begin{proof}\nWe consider a sequence $\\{\\epsilon_l\\}$ such that $\\epsilon_l\\to0$ and $\\epsilon_l>0$. We denote $\\pi^l$ the solution to \\ref{equ:erot} for $\\epsilon=\\epsilon_l$. Since $U(\\mu,\\nu)$ is bounded, we can extract a sequence (that we do not relabel for sake of simplicity) such that $\\pi^l\\to\\pi^*$. Since $U(\\mu, \\nu)$ is closed, $\\pi^*\\in U(\\mu,\\nu)$. We consider any $\\pi$ such that $\\la C,\\pi\\ra=L_C(\\mu,\\nu)$. By the optimality of $\\pi$ and $\\pi^l$ for their respective optimization problem, we have\n\\begin{equation}\n0\\leqslant\\la C, \\pi^l\\ra-\\la C, \\pi\\ra\\leqslant\\epsilon_l(H(\\pi^l)-H(\\pi))\n\\end{equation}\nSince $H$ is continuous, taking the limit $l\\to\\infty$ in this expression shows that $\\la C, \\pi^*\\ra=\\la C, \\pi\\ra$ so that $\\pi^*$ is a feasible point of \\ref{sh_limit}. Furthermore, we have $H(P^*)\\geqslant H(P)$, which shows that $P^*$ is the solution to \\ref{sh_limit}. By strict convexity of $-H$, the solution is unique and the whole sequence is converging. \n\\end{proof}\n\nThe following figures \\ref{gmm1} and \\ref{gmm2} illustrates the impact of $\\epsilon$ on the coupling $\\pi$ between two Gaussian mixture models.\n\\begin{figure}[!htb]\n\\centering\n\\includegraphics[width=12cm]{final/gmm1.png}\n\\caption{The probability distribution function of two Gaussian mixture models $G_1$ and $G_2$. $G_1$ (blue one) has mean $[0.3,0.5]$, variance $[0.05^2, 0.03^2]$ and component proportion $[0.5, 0.5]$; $G_2$ (red one) has mean $[0.6,0.7]$, variance $[0.03^2, 0.05^2]$ and component proportion $[0.6, 0.4]$. }\n\\label{gmm1}\n\\end{figure}\n\n\\begin{figure}[!htb]\n\\centering\n\\includegraphics[width=12cm]{final/gmm2.png}\n\\caption{Impact of $\\epsilon$ on the coupling between two gaussian mixture models \\ref{gmm1}. From left to right, $\\epsilon=1,0.1,0.01,0.001$. The purple one is the solution to the entropy regularized LP. The green one is the solution to the original LP.}\n\\label{gmm2}\n\\end{figure}\n\nDefine the Kullback-Leibler divergence between couplings as\n$$\n\\mathrm{KL}(\\pi|K)\\triangleq\\sum_{i,j}\\pi_{i,j}\\log(\\frac{\\pi_{i,j}}{K_{i,j}})-\\pi_{i,j}+K_{i,j}\n$$\nWe take $K^\\epsilon_{i,j}\\triangleq e^{-\\frac{C_{i,j}}{\\epsilon}}$, the Gibbs kernel associated to the cost matrix $C$. The unique solution $\\pi^\\epsilon$ of \\ref{equ:erot} is a projection onto $U(\\mu,\\nu)$, namely\n$$\n\\pi^\\epsilon\\triangleq\\arg\\min\\limits_{\\pi\\in U(\\mu,\\nu)}\\mathrm{KL}(\\pi|K^\\epsilon)\n$$\n\n\\subsubsection{Formulation of the problem}\nThe optimization problem of the entropic regularization of optimal transport with parameter $\\epsilon$ is given by:\n\\begin{equation}\n\\label{equ:kl}\n\\left\\{\n\\begin{aligned}\n&\\min \\, \\la C,\\pi\\ra-\\epsilon H(\\pi)=\\mathrm{KL}(\\pi|K^\\epsilon)\\\\\n&\\mathrm{s.t.}\\, \\pi\\in U(\\mu, \\nu)\n\\end{aligned}\\right.\n\\end{equation}\nwhere $K^\\epsilon_{i,j}= e^{-\\frac{C_{i,j}}{\\epsilon}}$.\n\n\\subsection{Sinkhorn's Algorithm}\nWe start with the following proposition. \n\n\\begin{proposition}\n\\label{sh_basic}\nThe solution to \\ref{equ:kl} is unique and has the form \n\\begin{equation}\n\\label{equ:para}\n\\forall 1\\leqslant i\\leqslant m, 1\\leqslant j\\leqslant n, \\quad \\pi^\\epsilon_{i,j}=a_iK^\\epsilon_{i,j}b_j\n\\end{equation}\nfor two (unknown) scaling variable $(a,b)\\in \\mbR_+^m\\times\\mbR_+^n$.  \n\\end{proposition}\n\n\\begin{proof}\nIntroducing two dual variable $f\\in\\mbR^m, g\\in\\mbR^n$ for each marginal constraint. The Lagrangian of \\ref{equ:kl} reads\n$$\nL(\\pi,f,g)=\\la\\pi,C\\ra-\\epsilon H(P)-\\la f, \\pi\\mbone_n-\\mu\\ra-\\la g, \\pi^T\\mbone_m-\\nu\\ra\n$$\nThe first order conditions yield\n$$\n\\frac{\\p L}{\\p \\pi_{i,j}}=C_{i,j}+\\epsilon log(P_{i,j})-f_i-g_j=0\n$$\nThis means that an optimal $\\pi$ coupling to the regularized problem can be written as $P_{i,j}=e^{f_i/\\epsilon}e^{-C_{i,j}/\\epsilon}e^{g_j/\\epsilon}$. Let $a=e^{f_i/\\epsilon}, b= e^{g_j/\\epsilon}$, then we have $$\n\\pi_{i,j}=a_iK^\\epsilon_{i,j}b_j\n$$\n\\end{proof}\n\nThis shows that the solution of \\ref{equ:kl} has a specific form, which can be parameterized using $m+n$ variables.\n\nThe parameterization of the optimal solution in equation \\ref{equ:para} can be written in the matrix form $\\pi^\\epsilon = \\diag(a)K^\\epsilon\\diag(b)$. Then, $a,b$ must satisfies:\n\\begin{equation}\n\\diag(a)K^\\epsilon\\diag(b)\\mbone_m=\\mu, \\quad \\diag(a)K^T\\diag(b)\\mbone_n=\\nu\n\\end{equation}\nThese two equations can be further simplified as\n\\begin{equation}\na\\odot (K^\\epsilon b)=\\mu, \\quad b\\odot\\left((K^\\epsilon)^Ta\\right)=\\nu\n\\end{equation}\nwhere $\\odot$ corresponds to entry-wise multiplication of vectors. The Sinkhorn's algorithm iteratively update $a^{(l+1)}$ and $b^{(l+1)}$ by\n\\begin{equation}\n\\label{upd_sh}\na^{(l+1)}=\\frac{\\mu}{K^\\epsilon b^{(l)}}, \\quad b^{l+1}=\\frac{\\nu}{(K^\\epsilon)^Ta^{(l+1)}}\n\\end{equation}\ninitialized with an arbitrary positive vector $b^{(0)}=\\mbone_n$. The division operator used above between two vectors is to be understood entry-wise. The whole algorithm is given by:\n\n\\begin{algorithm}\n\\caption{Sinkhorn's algorithm}\n\\label{alg:sa}\n\\begin{algorithmic}[1]\n\\REQUIRE $\\epsilon$, $C\\in\\mbR^{m\\times n}$, $\\mu\\in\\mbR^m$, $\\nu\\in\\mbR^n$.\n\\STATE Start with $b^{(0)}=\\mbone_n$, $l=0$\n\\STATE Calculate $K^\\epsilon_{i,j}= e^{-\\frac{C_{i,j}}{\\epsilon}}$\n\\WHILE {\\text{not converge}}\n\t\\STATE Update $a^{(l+1)}$ and $b^{(l+1)}$ by \\ref{upd_sh}, $l=l+1$\n\\ENDWHILE\n\\STATE $a=a^{(l)}, b=b^{(l)}$\n\\RETURN $\\pi=\\diag(a)K^\\epsilon \\diag(b)$\n\\end{algorithmic}\n\\end{algorithm}\n\nThis algorithm was originally introduced with a proof of convergence by \\cite{sinkhorn}. For simplicity, we assume $m=n$. \\cite{nltaa} showed that by setting $\\epsilon=\\frac{\\tau}{4\\log(n)}$, $O(\\|C\\|_\\infty^3\\log(n)\\tau^{-3})$ Sinkhorn iterations (with an additional\nrounding step to compute a valid coupling $\\hat\\pi\\in U(\\mu,\\nu)$) are enough to ensure $\\la \\hat \\pi, C\\ra\\leqslant L_C(\\mu,\\nu)+\\tau$. This implies that Sinkhorn computes a $\\tau$-approximate solution of the unregularized OT problem in $O(n^2\\log(n)\\tau^{-3})$ operations. The rounding scheme consists in, given two vectors $a\\in\\mbR^m, \\, b\\in\\mbR^n$ to carry out the following updates:\n$$\na'=a\\odot \\min\\left(\\frac{\\mu}{a\\odot(K^\\epsilon b)},\\mbone_m\\right), \\quad b'=b\\odot \\min \\left(\\frac{\\nu}{b\\odot((K^\\epsilon)^Ta')},\\mbone_n\\right)\n$$\n$$\n\\Delta_\\mu = \\mu-a'\\odot(K^\\epsilon b'), \\quad \\Delta_\\nu=\\nu-b'\\odot\\left((K^\\epsilon)^Ta'\\right)\n$$\n$$\n\\hat \\pi = \\diag(a') K^\\epsilon\\diag (b')+\\Delta_\\mu\\Delta_\\nu^T/\\|\\Delta_\\mu\\|_1\n$$\nThis yields a matrix $\\hat\\pi\\in U(\\mu,\\nu)$ such that the $1$-norm of $\\hat \\pi -\\diag(a) K^\\epsilon\\diag (b) $ is controlled by the marginal violations of $\\diag(a)K^\\epsilon\\diag(b)$, namely\n$$\n\\|\\hat \\pi -\\diag(a) K^\\epsilon\\diag (b')\\|_1\\leqslant\\|\\mu-a\\odot(K^\\epsilon b)\\|_1+\\|\\nu-b\\odot\\left((K^\\epsilon)^Ta\\right)\\|_1\n$$\nIn actual implementation, this step is crucial to decrease the violation of constraints. \n\n\\subsection{Our proposed algorithm}\n\\subsubsection{Sinkhorn's algorithm with numerical stability and continuation strategy}\nWe denote $\\|C\\|_\\infty=\\max\\limits_{i,j}|C_{i,j}|$. In actual implementation of Sinkhorn's algorithm \\ref{alg:sa}, because we have $K^\\epsilon_{i,j}=e^{-\\frac{C_{i,j}}{\\epsilon}}$, when $\\epsilon$ is small, namely $\\epsilon<\\frac{\\|C\\|_\\infty}{806}$, the largest entry of $K$ is smaller than $e^{-806}\\approx 10^{-350}$. Most of the entry of $K^{\\epsilon}$ would be rounded to $0$ because they are smaller than the smallest positive number that the computer can restore. If we want to calculate $K^\\epsilon$, we would have a positive lower bound $\\frac{\\|C\\|_\\infty}{806}$ for $\\epsilon$. This is not desired and it would make the result from proposition \\ref{sh_cvg} meaningless.\n\nWe propose a numerical stable version of Sinkhorn's algorithm with no lower bound of $\\epsilon$. A possible way to remove this lower bound of $\\epsilon$ is to avoid directly calculating $K^\\epsilon$ to update $a^{(l+1)}$ and $b^{(l+1)}$. Therefore, from the proof of proposition \\ref{sh_basic}, we denote $a^{(l)}=e^{f^{(l)}/\\epsilon}$, $b^{(l)}=e^{g^{(l)}/\\epsilon}$, where $f^{(l)}\\in R^m, g^{(l)}\\in R^n$. Then, the update rule for $f^{(l+1)}$ and $g^{(l+1)}$ reads\n\\begin{equation}\n\\label{upd_sh_log}\nf^{(l+1)}=\\epsilon(\\log(\\mu)-\\log(K^\\epsilon e^{g^{(l)}/\\epsilon})), \\quad g^{(l+1)}=\\epsilon(\\log(\\nu)-\\log((K^\\epsilon)^T e^{f^{(l+1)}/\\epsilon})),\n\\end{equation}\nOur motivation is to caculate $\\log(K^\\epsilon e^{g^{(l)}/\\epsilon})$ and $\\log((K^\\epsilon)^T e^{f^{(l+1)}/\\epsilon})$ in update rule \\ref{upd_sh_log} in a numerically stable way. We start with the update of $f^{(l+1)}$. It is easy to verify that\n$$\nf^{(l+1)}_i = \\epsilon \\log(\\mu_i)-\\epsilon \\log(\\sum_{j=1}^ne^{(-C_{i,j}+g^{(l)}_j)/\\epsilon})\n$$\nDirectly calculating $\\sum_{j=1}^ne^{(-C_{i,j}+g^{(l)}_j)/\\epsilon}$ is dangerous because it might be rounded to $0$. Let $\\hat f^{(l+1)}_i=\\max_j\\{-C_{i,j}+g^{(l)}_j\\}$. Then, to update $f$ with numerical stability, we can update $f^{(l+1)}_i$ by\n\\begin{equation}\n\\label{sh_f_upd}\nf^{(l+1)}_i = \\epsilon \\log(\\mu_i)-\\hat f^{(l)}_i-\\epsilon \\log(\\sum_{j=1}^ne^{ (-C_{i,j}+g^{(l)}_j-\\hat f^{(l)}_i)/\\epsilon})\n\\end{equation}\nBecause $\\sum_{j=1}^ne^{ (-C_{i,j}+g^{(l)}_j-\\hat f^{(l)}_i)/\\epsilon}\\geqslant1$, to update $f^{(l+1)}$ in this way is safe. Actually, we use $\\hat f_i^{(l)}/\\epsilon+\\log(\\sum_{j=1}^ne^{ (-C_{i,j}+g^{(l)}_j-\\hat f^{(l)}_i)/\\epsilon})$ to calculate $\\log(K^\\epsilon e^{g^{(l)}/\\epsilon})$.  Similarly, we let $\\hat g^{(l+1)}_j=\\max_i\\{-C_{i,j}+f^{(l+1)}_i\\}$, and update $g^{(l+1)}_j$ by\n\\begin{equation}\n\\label{sh_g_upd}\ng^{(l+1)}_j = \\epsilon \\log(\\nu_j)-\\hat g^{(l+1)}_j-\\epsilon \\log(\\sum_{i=1}^ne^{ (-C_{i,j}+f^{(l+1)}_i-\\hat g^{(l+1)}_j)/\\epsilon})\n\\end{equation}\nIn the end of the algorithm, we also use an additional rounding step to compute a valid coupling $\\hat\\pi$. Given two vectors $f\\in\\mbR^m, g\\in\\mbR^n$ and coupling matrix $\\pi\\in\\mbR^{m\\times n}$ with $\\pi_{i,j}=e^{(f_i-C_{i,j}+g_j)/\\epsilon}$, we compute $\\hat\\pi$ in the following way:\n\\begin{equation}\n\\label{add_coup}\n\\begin{aligned}\n&\\hat f_i=\\max_j\\{-C_{i,j}+g_j\\}, \\quad f'_i=f_i+\\min\\{\\epsilon(\\log(\\mu_i)-\\sum_{j=1}^ne^{ (-C_{i,j}+g_j-\\hat f_i)/\\epsilon})-\\hat f_i-f_i,0\\}\\\\\n&\\hat g_j=\\max_i\\{-C_{i,j}+f'_i\\}, \\quad g'_j=g_j+\\min\\{\\epsilon(\\log(\\nu_j)-\\sum_{i=1}^me^{ (-C_{i,j}+f'_i-\\hat g_j)/\\epsilon})-\\hat g_j-g_j,0\\}\\\\\n&\\hat f'_i=\\max_j\\{-C_{i,j}+g'_j\\}, \\quad (\\Delta_\\mu)_i=\\mu_i-(\\sum_{j=1}^ne^{ (-C_{i,j}+g'_j-\\hat f'_i)/\\epsilon})e^{(f'_i+\\hat f'_i)/\\epsilon}\\\\\n&(\\Delta_\\nu)_j=\\nu_j-(\\sum_{i=1}^ne^{ (-C_{i,j}+f'_i-\\hat g'_j)/\\epsilon})e^{(g'_j+\\hat g'_j)/\\epsilon}, \\quad \\hat\\pi=\\pi+\\Delta_\\mu\\Delta_\\nu^T/\\|\\Delta_\\mu\\|_1\n\\end{aligned}\n\\end{equation}\nThen, we get the following Sinkhorn's algorithm with numerical stability. It shares the same idea with Log-domain Sinkhorn's algorithm \\cite{COT}. \n\\begin{algorithm}\n\\caption{Sinkhorn's algorithm with numerical stability}\n\\label{alg:sans}\n\\begin{algorithmic}[1]\n\\REQUIRE $\\epsilon$, $C\\in\\mbR^{m\\times n}$, $\\mu\\in\\mbR^m$, $\\nu\\in\\mbR^n$.\n\\STATE Start with $g^{(0)}=\\mathbf{0}_n$, $l=0$\n\\WHILE {\\text{not converge}}\n\t\\STATE Calculate $\\hat f^{(l+1)}_i=\\max_j\\{-C_{i,j}+g^{(l)}_j\\}$ and update $f^{(l+1)}$ by \\ref{sh_f_upd}\n\t\\STATE Calculate $\\hat g^{(l+1)}_i=\\max_i\\{-C_{i,j}+f^{(l+1)}_i\\}$ and update $g^{(l+1)}$ by \\ref{sh_g_upd}, $l=l+1$\n\\ENDWHILE\n\\STATE Let $f=f^{(l)}, g=g^{(l)}$, calculate $\\pi_{i,j}=e^{(f_i-C_{i,j}+g_j)/\\epsilon}$, and compute $\\hat\\pi$ by \\ref{add_coup}\n\\RETURN $\\hat \\pi$\n\\end{algorithmic}\n\\end{algorithm}\n\nWe shall point out that $\\epsilon>0$ is vital in the iteration \\ref{sh_f_upd} and \\ref{sh_g_upd} because $f^{(l)}$ and $g^{(l)}$ will converge to the optimal solution to the dual problem of \\ref{equ:kl} by Proposition \\ref{sh_basic}. If we let $\\epsilon\\to 0$ in \\ref{sh_f_upd} and \\ref{sh_g_upd}, we would find that these updates become as follows:\n\\begin{equation}\n\\label{upd_div}\nf_i^{(l+1)}=-\\hat f_i^{(l)}=\\min_j\\{C_{i,j}-g^{(l)}_j\\}, \\quad g_j^{(l+1)}=-\\hat g^{(l+1)}_j = \\max_i\\{C_{i,j}-f^{(l+1)}_i\\}\n\\end{equation}\nNevertheless, $f^{(l)}$ and $g^{(l)}$ in this iteration \\ref{upd_div} will not converge to the solution to the dual problem of \\ref{lp}. With $\\epsilon=0$, we lose the strong convexity of the objective function and, therefore, the solution to the dual problem of \\ref{lp} is not unique. As a result,  $f^{(l)}$ and $g^{(l)}$ may stuck in a plateau. This is also pointed out in Section 3.2 of \\cite{COT}. \n\nWe can also apply continuation strategy in Sinkhorn's algorithm with numerical stability. We have three additional parameters $\\epsilon_0, \\alpha, M$ for continuation. Namely, we start with a large $\\epsilon_0$ and $k=0$. Then, until $\\epsilon_k=\\epsilon$, we gradually decrease the value of $\\epsilon_{k+1}=\\max\\{\\alpha\\epsilon_k,\\epsilon \\}$ and set $k=k+1$ after $M$ iterations. In each iteration, $f_i^{(l+1)}$ and $g_j^{(l+1)}$ are updated as follows:\n\\begin{equation}\n\\label{sh_f_upd_c}\nf^{(l+1)}_i = \\epsilon_k \\log(\\mu_i)-\\hat f^{(l)}_i-\\epsilon_k \\log(\\sum_{j=1}^ne^{ (-C_{i,j}+g^{(l)}_j-\\hat f^{(l)}_i)/\\epsilon_k})\n\\end{equation}\n\\begin{equation}\n\\label{sh_g_upd_c}\ng^{(l+1)}_j = \\epsilon_k \\log(\\nu_j)-\\hat g^{(l+1)}_j-\\epsilon_k \\log(\\sum_{i=1}^ne^{ (-C_{i,j}+f^{(l+1)}_i-\\hat g^{(l+1)}_j)/\\epsilon_k})\n\\end{equation}\nIn the end, we still use an additional rounding step to compute a valid coupling $\\hat\\pi$. The algorithm is given below:\n\n\\begin{algorithm}\n\\caption{Sinkhorn's algorithm with numerical stability and continuation strategy}\n\\label{alg:sansc}\n\\begin{algorithmic}[1]\n\\REQUIRE $\\epsilon$, $C\\in\\mbR^{m\\times n}$, $\\mu\\in\\mbR^m$, $\\nu\\in\\mbR^n$, continuation parameter $\\epsilon_0, \\alpha, M$.\n\\STATE Start with $g^{(0)}=\\mathbf{0}_n$, $k=0$.\n\\WHILE{$\\epsilon_k>\\epsilon$}\n\t\\FOR{$l=0:M-1$}\n\t\\STATE Calculate $\\hat f^{(l+1)}_i=\\max_j\\{-C_{i,j}+g^{(l)}_j\\}$ and update $f^{(l+1)}$ by \\ref{sh_f_upd_c}\n\t\\STATE Calculate $\\hat g^{(l+1)}_i=\\max_i\\{-C_{i,j}+f^{(l+1)}_i\\}$ and update $g^{(l+1)}$ by \\ref{sh_g_upd_c}\n\t\\ENDFOR\n\t\\STATE Set $\\epsilon_{k+1}=\\max\\{\\alpha\\epsilon_k,\\epsilon \\}$, $f^{(0)}=f^{(M)}$, $g^{(0)}=g^{(M)}$ and $k=k+1$\n\\ENDWHILE\n\\FOR{$l=0:M-1$}\n\t\\STATE Calculate $\\hat f^{(l+1)}_i=\\max_j\\{-C_{i,j}+g^{(l)}_j\\}$ and update $f^{(l+1)}$ by \\ref{sh_f_upd_c}\n\t\\STATE Calculate $\\hat g^{(l+1)}_i=\\max_i\\{-C_{i,j}+f^{(l+1)}_i\\}$ and update $g^{(l+1)}$ by \\ref{sh_g_upd_c}\n\\ENDFOR\n\\STATE Let $f=f^{(l)}, g=g^{(l)}$, calculate $\\pi_{i,j}=e^{(f_i-C_{i,j}+g_j)/\\epsilon}$, and compute $\\hat\\pi$ by \\ref{add_coup}\n\\RETURN $\\hat \\pi$\n\\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{First-Order Method: ADMM}\nTo implement a first-order algorithm to solve Entropy Regularization of OT \\ref{equ:kl}, we again choose ADMM. We reformulate the problem as follows, \n\\begin{eqt}\n\\min_{\\pi, \\tilde\\pi}&\\ \\la C, \\pi\\ra - \\epsilon H(\\tilde{\\pi}) \\\\\n\\text{s.t.}&\\ \\pi = \\tilde{\\pi}\\in U(\\mu, \\nu)\n\\end{eqt}\nwhich is, equivalently, \n\\begin{eqt}\n\\min_{\\pi, \\tilde\\pi}\\ &\\sum_{i, j}C_{i, j}\\pi_{i, j} + \\epsilon \\sum_{i, j}\\tilde\\pi_{i, j}(\\log(\\tilde\\pi_{i, j}) - 1) \\\\\n\\text{s.t.}\\ &\\sum_{j}\\pi_{i, j} = \\mu_i,\\ \\sum_{i}\\pi_{i, j} = \\nu_j,\\ \\pi = \\tilde{\\pi}\\geqslant 0.\n\\end{eqt}\nThe augmented Lagrangian function is \n\\begin{eqt}\n& L_t(\\pi, \\tilde\\pi, \\gamma, \\lambda, \\omega) \\\\ \n=& \\sum_{i, j}C_{i, j}\\pi_{i, j} + \\sum_{i}\\gamma_i\\left(\\mu_i - \\sum_j\\pi_{i, j}\\right) + \\sum_j\\lambda_j\\left(\\nu_j-\\sum_i\\pi_{i, j}\\right) + \\sum_{i, j}\\omega_{i, j}(\\tilde\\pi_{i, j} - \\pi_{i, j})\\\\\n& +\\frac{t}{2}\\left(\\sum_i\\left(\\mu_i-\\sum_{j}\\pi_{i, j}\\right)^2+\\sum_j\\left(\\nu_j-\\sum_{i}\\pi_{i, j}\\right)^2+\\sum_{i, j}(\\pi_{i, j}-\\tilde\\pi_{i, j})^2\\right) \\\\\n&+\\epsilon\\sum_{i, j}\\tilde\\pi_{i, j}(\\log(\\tilde\\pi_{i, j})-1)\n\\end{eqt}\n\nFor the update of $\\pi$, which is similar to \\ref{upd_pi} in the previous sections, we have \n\\begin{eqt}\n\\label{piupdate}\n\\pi_{i,j} \\gets x_{i,j} & - \\frac{1}{m+1}\\left(\\sum_kx_{k,j} - \\frac{1}{m+n+1}\\sum_{k, l}x_{k,l}\\right)\n\\\\& - \\frac{1}{n+1}\\left(\\sum_kx_{i,k}-\\frac{1}{m+n+1}\\sum_{k, l}x_{k,l}\\right)\n\\end{eqt}\nwhere\n\\begin{eqt}\n\\label{xcompute}\nx_{i, j} = \\frac{1}{t}(\\gamma_{i}+\\lambda_{j}+\\omega_{i,j}-c_{i,j}) + \\mu_{i} + \\nu_{j} + \\tilde{\\pi}_{i,j}\n\\end{eqt}\n\nFor the update of $\\tilde{\\pi}$, setting $\\frac{\\partial L_t}{\\partial\\tilde\\pi}=0$, we need to solve the following problem for each $\\tilde\\pi_{i, j}$,\n\\begin{eqt}\n\\omega_{i, j} + t(\\tilde\\pi_{i, j} - \\pi_{i, j}) + \\epsilon\\log\\tilde{\\pi}_{i, j} = 0\n\\end{eqt}\nSuch equation has no closed form solution, though the left hand side is strictly increasing with $\\tilde{\\pi}_{i, j}$ and its range is $\\mathbb{R}$($t$ and $\\epsilon$ are both positive numbers). Therefore, we seek to update one step ahead with Newton Method in each iteration as well as sustain the nonnegativity, i.e., \n\\begin{eqt}\n\\label{tildepiupdate}\n\\tilde\\pi_{i, j}\\gets \\max\\left\\{\\tilde\\pi_{i, j} - \\frac{\\omega_{i, j}+t(\\tilde\\pi_{i, j}-\\pi_{i, j})+\\epsilon\\log\\tilde\\pi_{i, j}}{t+\\epsilon/\\tilde\\pi_{i, j}}, 0\\right\\}\n\\end{eqt}\n\nHowever, $\\tilde\\pi_{i, j}$ may possibly be zero, which may lead to numerical explosion in \\ref{tildepiupdate}. Thus, every time before \\ref{tildepiupdate}, we let\n\\begin{eqt}\n\\label{add}\n\\tilde\\pi_{i, j} \\gets \\tilde\\pi_{i, j} + \\tilde\\epsilon,\n\\end{eqt}\nwhere $\\tilde\\epsilon$ is a very small number. In our implementation, we let $\\tilde\\epsilon$ be 1e-16.\n\nUpdate of multipliers are as follows, \n\\begin{eqt}\n\\label{multupdate}\n& \\gamma_{i} \\gets \\gamma_i + t(\\mu_i - \\sum_k\\pi_{i,k}) \\\\\n& \\lambda_{j} \\gets \\lambda_j + t(\\nu_j - \\sum_k\\pi_{k,j}) \\\\\n& \\omega_{i, j} \\gets \\omega_{i, j} + t(\\tilde{\\pi}_{i, j} - \\pi_{i, j})\n\\end{eqt}\n\nWe thus have the following Algorithm \\ref{alg:ADMM-ER}.\n\\begin{algorithm}\n\\caption{ADMM for Entropy Regularization}\n\\label{alg:ADMM-ER}\n\\begin{algorithmic}[1]\n\\REQUIRE {$C\\in\\mbR^{m\\times n}$, $\\mu\\in\\mbR^m$, $\\nu\\in\\mbR^n$, $t, \\epsilon, \\tilde\\epsilon\\in \\mathbb{R}^+$}\n\\STATE $\\pi, \\tilde{\\pi}, \\gamma, \\lambda, \\omega\\gets 0$\n\\WHILE {\\text{not converge}} \n\t\\STATE Update $\\pi$ according to \\ref{piupdate}, \\ref{xcompute}\n\t\\STATE Update $\\tilde\\pi$ according to \\ref{add}, \\ref{tildepiupdate}\n\t\\STATE Update $\\gamma$, $\\lambda$ and $\\omega$ by \\ref{multupdate}\n\\ENDWHILE\n\\RETURN $\\pi$\n\\end{algorithmic}\n\\end{algorithm}\n\n ", "meta": {"hexsha": "22ee534ea3fe44470e9dbac733283547d6047a11", "size": 20927, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Latex/final/entropy_regularization.tex", "max_stars_repo_name": "YiifeiWang/Optimal-Transport", "max_stars_repo_head_hexsha": "2b39683ec19c0c5c81c2150cd0c3f68a9e915214", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-01-17T19:17:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-03T13:04:15.000Z", "max_issues_repo_path": "Latex/final/entropy_regularization.tex", "max_issues_repo_name": "YiifeiWang/Optimal-Transport", "max_issues_repo_head_hexsha": "2b39683ec19c0c5c81c2150cd0c3f68a9e915214", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Latex/final/entropy_regularization.tex", "max_forks_repo_name": "YiifeiWang/Optimal-Transport", "max_forks_repo_head_hexsha": "2b39683ec19c0c5c81c2150cd0c3f68a9e915214", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-01-21T02:55:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-04T02:16:55.000Z", "avg_line_length": 62.8438438438, "max_line_length": 681, "alphanum_fraction": 0.6679409375, "num_tokens": 7921, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.9124361598816667, "lm_q1q2_score": 0.732844814465471}}
{"text": "\\subsection{Step 1}\nLet's start by rewriting our ADI equation for the Step 1 (given in class 13 slide 13), for an staggered mesh for the horizontal velocity $u$:\n\\begin{align*}\n-d_1u_{i-1/2,j}^{n+1/2}+(1+2d_1)u_{i+1/2,j}^{n+1/2}-d_1u_{i+3/2,j}^{n+1/2}=d_2u_{i+1/2,j+1}^{n}+(1-2d_2)u_{i+1/2,j}^{n}+d_2u_{i+1/2,j-1}^{n},\n\\end{align*}\nwhich has the form \n\\begin{align*}\nau_{i-1/2,j}^{n+1/2}+bu_{i+1/2,j}^{n+1/2}+cu_{i+3/2,j}^{n+1/2}=d,\n\\end{align*}\na tridiagonal system. The staggered mesh for $u$ gives us a matrix $u$ that is $(M+1)\\times(N+2)$. We only need to solve the previous equation for the interior with two $for$ loops in \\textsl{Matlab},\n\\begin{verbatim}\nfor j=2:N+1\nfor i=2:M\n\t\t...\n\tend\nend\n\\end{verbatim}.\nWe will now include the boundary conditions for each case.\n\\subsubsection*{Case $j=2$ and $i=2$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_1u_{3/2,2}^{n+1/2}+(1+2d_1)u_{5/2,2}^{n+1/2}-d_1u_{7/2,2}^{n+1/2}=d_2u_{5/2,3}^{n}+(1-2d_2)u_{5/2,2}^{n}+d_2u_{5/2,1}^{n}.\n\\end{align*}\nNote that I will be using \\textsl{Maltab} indices, so the first index is $1$. Since we know that $u_{3/2,2}^{n+1/2}=0$ since it corresponds to the left wall, we can then impose that $a(1)=0$. The value $u_{5/2,1}$ will also be determined by the boundary conditions. Since it is a cell-like boundary conditions in this case, we can impose it by updating the ghost cells. Thus, $d(1)$ is the right hand side of the previous equation.\n\n\\subsubsection*{Case $j=2$ and $i\\in [3,M-1]$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_1u_{i-1/2,2}^{n+1/2}+(1+2d_1)u_{i+1/2,2}^{n+1/2}-d_1u_{i+3/2,2}^{n+1/2}=d_2u_{i+1/2,3}^{n}+(1-2d_2)u_{i+1/2,2}^{n}+d_2u_{i+1/2,1}^{n}.\n\\end{align*}\nLike in the previous case, the value $u_{i+1/2,1}$ will also be determined by the boundary conditions. Since it is a cell-like boundary conditions in this case, we can impose it by updating the ghost cells. Thus, $d$ is the right hand side of the previous equation.\n\n\\subsubsection*{Case $j=2$ and $i=M$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_1u_{M-1/2,2}^{n+1/2}+(1+2d_1)u_{M+1/2,2}^{n+1/2}-d_1u_{M+3/2,2}^{n+1/2}=d_2u_{M+1/2,3}^{n}+(1-2d_2)u_{M+1/2,2}^{n}+d_2u_{M+1/2,1}^{n}.\n\\end{align*}\nIn this case we can see that the value $u_{M+3/2,2}^{n+1/2}$ corresponds to the horizontal velocity at the right wall, hence it is zero and so it is $c$ in this case. Like in the previous case, the value $u_{M+1/2,1}$ will also be determined by the boundary conditions. Since it is a cell-like boundary condition in this case, we can impose it by updating the ghost cells. Thus, $d$ is the right hand side of the previous equation.\n\n\\subsubsection*{Case $j\\in[3,N]$ and $i=2$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_1u_{3/2,j}^{n+1/2}+(1+2d_1)u_{5/2,j}^{n+1/2}-d_1u_{7/2,j}^{n+1/2}=d_2u_{5/2,j+1}^{n}+(1-2d_2)u_{5/2,j}^{n}+d_2u_{5/2,j-1}^{n}.\n\\end{align*}\nIn this case the value $u_{3/2,j}^{n+1/2}$ corresponds to the horizontal velocity at the left wall. Since its value will depend on $j$ because of the inlet 1, it will be moved to the right hand side, getting\n\\begin{align*}\n(1+2d_1)u_{5/2,j}^{n+1/2}-d_1u_{7/2,j}^{n+1/2}=d_2u_{5/2,j+1}^{n}+(1-2d_2)u_{5/2,j}^{n}+d_2u_{5/2,j-1}^{n}+d_1u_{3/2,j}^{n+1/2},\n\\end{align*}\nwhich makes $a=0$ for this case and $d$ being the right hand side of the previous equation.\n\n\\subsubsection*{Case $j\\in[3,N]$ and $i\\in[3,M-1]$}\nIn this case the general equation does not include any boundary conditions, therefore it is unaltered.\n\\subsubsection*{Case $j\\in[3,N]$ and $i=M$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_1u_{M-1/2,j}^{n+1/2}+(1+2d_1)u_{M+1/2,j}^{n+1/2}-d_1u_{M+3/2,j}^{n+1/2}=d_2u_{M+1/2,j+1}^{n}+(1-2d_2)u_{M+1/2,j}^{n}+d_2u_{M+1/2,j-1}^{n}.\n\\end{align*}\nLike before the value of $u_{M+3/2,j}^{n+1/2}$ will depend on the value of $j$ because of the inlet 2. Therefore we will move it to the right hand side and get\n\\begin{align*}\n-d_1u_{M-1/2,j}^{n+1/2}+(1+2d_1)u_{M+1/2,j}^{n+1/2}=d_2u_{M+1/2,j+1}^{n}+(1-2d_2)u_{M+1/2,j}^{n}+d_2u_{M+1/2,j-1}^{n}+d_1u_{M+3/2,j}^{n+1/2},\n\\end{align*}\nwhich gives us, for this case, $c=0$ and $d$ being the right hand side of the previous equation.\n\n\\subsubsection*{Case $j=N+1$ and $i=2$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_1u_{3/2,N+1}^{n+1/2}+(1+2d_1)u_{5/2,N+1}^{n+1/2}-d_1u_{7/2,N+1}^{n+1/2}=d_2u_{5/2,N+2}^{n}+(1-2d_2)u_{5/2,N+1}^{n}+d_2u_{5/2,N}^{n}.\n\\end{align*}\nIn this case the value of $u_{3/2,N+1}^{n+1/2}$ corresponds to the horizontal velocity at the left wall, which is zero imposed by the boundary conditions. This implies that $a=0$ for this case. The value of $u_{5/2,N+2}^{n}$ will be determined by the boundary conditions as well. Since it is a cell-like boundary condition in this case, we can impose it by updating the ghost cells. Thus, $d$ is the right hand side of the previous equation.\n\n\\subsubsection*{Case $j=N+1$ and $i\\in[3,M-1]$}\n\\begin{align*}\n-d_1u_{i-1/2,N+1}^{n+1/2}+(1+2d_1)u_{i+1/2,N+1}^{n+1/2}-d_1u_{i+3/2,N+1}^{n+1/2}=d_2u_{i+1/2,N+2}^{n}&+(1-2d_2)u_{i+1/2,N+1}^{n}\\\\&+d_2u_{i+1/2,N}^{n},\n\\end{align*}\nLike in the previous case, the value of $u_{i+1/2,N+2}^{n}$ will be determined by the boundary conditions as well. Since it is a cell-like boundary condition in this case, we can impose it by updating the ghost cells. Thus, $d$ is the right hand side of the previous equation. We will see how its value does not depend on the value of $i$ since the horizontal velocity in the inlet 3 is zero.\n\n\\subsubsection*{Case $j=N+1$ and $i=M$}\n\\begin{align*}\n-d_1u_{M-1/2,N+1}^{n+1/2}+(1+2d_1)u_{M+1/2,N+1}^{n+1/2}-d_1u_{M+3/2,N+1}^{n+1/2}=d_2u_{M+1/2,N+2}^{n}&+(1-2d_2)u_{M+1/2,N+1}^{n}\\\\&+d_2u_{M+1/2,N}^{n},\n\\end{align*}\nIn this case the value of $u_{M+3/2,N+1}^{n+1/2}$ corresponds to the horizontal velocity at the right wall, imposed to be zero by the boundary conditions. Therefore $c=0$ for this case. The value of $u_{M+1/2,N+2}^{n}$ will be determined by the boundary conditions as well. Since it is a cell-like boundary condition in this case, we can impose it by updating the ghost cells.\n\n\\subsection{Step 2}\nWe start by rewriting our ADI equation for the Step 2 (given in class 13 slide 14), for an staggered mesh for the horizontal velocity $u$:\n\\begin{align*}\n-d_2u_{i+1/2,j-1}^{n+1}+(1+2d_2)u_{i+1/2,j}^{n+1}-d_2u_{i+1/2,j+1}^{n+1}=d_1u_{i+3/2,j}^{n+1/2}+(1-2d_1)u_{i+1/2,j}^{n+1/2}+d_1u_{i-1/2,j}^{n+1/2}\n\\end{align*}\nwhich has the form \n\\begin{align*}\nau_{i+1/2,j-1}^{n+1}+bu_{i+1/2,j}^{n+1}+cu_{i+1/2,j+1}^{n+1}=d\n\\end{align*}\na tridiagonal system. The staggered mesh for $u$ gives us a matrix $u$ that is $(M+1)\\times(N+2)$. We only need to solve the previous equation for the interior with two $for$ loops in \\textsl{Matlab},\n\\begin{verbatim}\nfor j=2:M\nfor i=2:N+1\n\t\t...\n\tend\nend\n\\end{verbatim}.\nWe will now include the boundary conditions for each case.\n\\subsubsection*{Case $i=2$ and $j=2$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2u_{5/2,1}^{n+1}+(1+2d_2)u_{5/2,2}^{n+1}-d_2u_{5/2,3}^{n+1}=d_1u_{7/2,2}^{n+1/2}+(1-2d_1)u_{5/2,2}^{n+1/2}+d_1u_{3/2,2}^{n+1/2}.\n\\end{align*}\nThe value of $u_{5/2,1}^{n+1}$ does not correspond to the interior and will be determined by the boundary conditions to be $-u_{5/2,2}^{n+1}$. Since it is a cell-like boundary condition in this case, we can impose it by updating the ghost cells. The value of $u_{3/2,2}^{n+1/2}$ corresponds to the left wall and it is then imposed to be zero. The previous equation then gives us\n\\begin{align*}\n(1+3d_2)u_{5/2,2}^{n+1}-d_2u_{5/2,3}^{n+1}=d_1u_{7/2,2}^{n+1/2}+(1-2d_1)u_{5/2,2}^{n+1/2}.\n\\end{align*}\n\nThus, for this case $a=0$, $b=1+3d_2$ and $d$ is given by the right hand side. \n\n\\subsubsection*{Case $i=2$ and $j\\in[3,N]$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2u_{5/2,j-1}^{n+1}+(1+2d_2)u_{5/2,j}^{n+1}-d_2u_{5/2,j+1}^{n+1}=d_1u_{7/2,j}^{n+1/2}+(1-2d_1)u_{5/2,j}^{n+1/2}+d_1u_{3/2,j}^{n+1/2}.\n\\end{align*}\nThe value of $u_{3/2,j}^{n+1/2}$ corresponds to the left wall and it is then imposed to be zero and $d$ is given by the right hand side. \n\n\\subsubsection*{Case $i=2$ and $j=N+1$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2u_{5/2,N}^{n+1}+(1+2d_2)u_{5/2,N+1}^{n+1}-d_2u_{5/2,N+2}^{n+1}=d_1u_{7/2,N+1}^{n+1/2}+(1-2d_1)u_{5/2,N+1}^{n+1/2}+d_1u_{3/2,N+1}^{n+1/2}.\n\\end{align*}\nThe value of $u_{3/2,N+1}^{n+1/2}$ corresponds to the left wall and it is then imposed to be zero. The value of $u_{5/2,N+2}^{n+1}=-u_{5/2,N+1}^{n+1}$ by the boundary conditions. Thus, for this case $c=0$, $b=1+3d_2$ and $d$ is given by the right hand side. \n\n\\subsubsection*{Case $i\\in[3,M-1]$ and $j=2$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2u_{i+1/2,1}^{n+1}+(1+2d_2)u_{i+1/2,2}^{n+1}-d_2u_{i+1/2,3}^{n+1}=d_1u_{i+3/2,2}^{n+1/2}+(1-2d_1)u_{i+1/2,2}^{n+1/2}+d_1u_{i-1/2,2}^{n+1/2}.\n\\end{align*}\nBy the boundary conditions, $u_{i+1/2,1}^{n+1}=-u_{i+1/2,2}^{n+1}$ and the previous equation yields\n\\begin{align*}\n(1+3d_2)u_{i+1/2,2}^{n+1}-d_2u_{i+1/2,3}^{n+1}=d_1u_{i+3/2,2}^{n+1/2}+(1-2d_1)u_{i+1/2,2}^{n+1/2}+d_1u_{i-1/2,2}^{n+1/2}.\n\\end{align*}\nThus, for this case $a=0$, $b=1+3d_2$ and $d$ is given by the right hand side.\n\\subsubsection*{Case $i\\in[3,M-1]$ and $j\\in[3,N]$}\nIn this case the general equation does not include any boundary conditions, therefore it is unaltered.\n\n\\subsubsection*{Case $i\\in[3,M-1]$ and $j=N+1$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2u_{i+1/2,N}^{n+1}+(1+2d_2)u_{i+1/2,N+1}^{n+1}-d_2u_{i+1/2,N+2}^{n+1}=d_1u_{i+3/2,N+1}^{n+1/2}&+(1-2d_1)u_{i+1/2,N+1}^{n+1/2}\\\\&+d_1u_{i-1/2,N+1}^{n+1/2}.\n\\end{align*}\nBy the boundary conditions, $u_{i+1/2,N+2}^{n+1}=-u_{i+1/2,N+1}^{n+1}$ and the previous equation yields\n\\begin{align*}\n-d_2u_{i+1/2,N}^{n+1}+(1+3d_2)u_{i+1/2,N+1}^{n+1}=d_1u_{i+3/2,N+1}^{n+1/2}+(1-2d_1)u_{i+1/2,N+1}^{n+1/2}+d_1u_{i-1/2,N+1}^{n+1/2}.\n\\end{align*}\nThus, for this case $c=0$, $b=1+3d_2$ and $d$ is given by the right hand side.\n\n\n\n\\subsubsection*{Case $i=M$ and $j=2$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2u_{M+1/2,1}^{n+1}+(1+2d_2)u_{M+1/2,2}^{n+1}-d_2u_{M+1/2,3}^{n+1}=d_1u_{M+3/2,2}^{n+1/2}+(1-2d_1)u_{M+1/2,2}^{n+1/2}+d_1u_{M-1/2,2}^{n+1/2}.\n\\end{align*}\nBy the boundary conditions, $u_{M+1/2,1}^{n+1}=-u_{M+1/2,2}^{n+1}$ and $u_{M+3/2,2}^{n+1/2}=0$ since it corresponds to the right wall. The previous equation yields\n\\begin{align*}\n(1+3d_2)u_{M+1/2,2}^{n+1}-d_2u_{M+1/2,3}^{n+1}=(1-2d_1)u_{M+1/2,2}^{n+1/2}+d_1u_{M-1/2,2}^{n+1/2}.\n\\end{align*}\nThus, for this case $a=0$, $b=1+3d_2$ and $d$ is given by the right hand side.\n\n\\subsubsection*{Case $i=M$ and $j\\in[3,N]$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2u_{M+1/2,j-1}^{n+1}+(1+2d_2)u_{M+1/2,j}^{n+1}-d_2u_{M+1/2,j+1}^{n+1}=d_1u_{M+3/2,j}^{n+1/2}+(1-2d_1)u_{M+1/2,j}^{n+1/2}+d_1u_{M-1/2,j}^{n+1/2}\n\\end{align*}\nThe value of $u_{M+3/2,j}^{n+1/2}$ depends on $j$ because of inlet 2. It will be imposed by the corresponding boundary condition in the code. In this case, $d$ is given by the right hand side.\n\n\\subsubsection*{Case $i=M$ and $j=N+1$}\nIn this case the general equation becomes\n\\begin{align*}\n-d_2u_{M+1/2,N}^{n+1}+(1+2d_2)u_{M+1/2,N+1}^{n+1}-d_2u_{M+1/2,N+2}^{n+1}=d_1u_{M+3/2,N+1}^{n+1/2}&+(1-2d_1)u_{M+1/2,N+1}^{n+1/2}\\\\&+d_1u_{M-1/2,N+1}^{n+1/2}\n\\end{align*}\nBy the boundary conditions, $u_{M+1/2,N+2}^{n+1}=-u_{M+1/2,N+1}^{n+1}$ and $u_{M+3/2,N+1}^{n+1/2}=0$ since it corresponds to the right wall. The previous equation yields\n\\begin{align*}\n-d_2u_{M+1/2,N}^{n+1}+(1+3d_2)u_{M+1/2,N+1}^{n+1}=(1-2d_1)u_{M+1/2,N+1}^{n+1/2}+d_1u_{M-1/2,N+1}^{n+1/2}.\n\\end{align*}\nThus, for this case $c=0$, $b=1+3d_2$ and $d$ is given by the right hand side.", "meta": {"hexsha": "f2299530d641b5f05c9f8c8ab9b293d521a36d32", "size": 11683, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/CFD/Homework_6/Latex/u_dev.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/CFD/Homework_6/Latex/u_dev.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/CFD/Homework_6/Latex/u_dev.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.9055555556, "max_line_length": 441, "alphanum_fraction": 0.6518017632, "num_tokens": 5584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563335, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.732814473784942}}
{"text": "\\section{Initial Value Problems}\r\n\\noindent\r\nWe can see that since solving a differential equation will mean integrating to get rid of derivatives, the $+ C$ from integration will gives us multiple solutions. We call these sets of solutions that differ only in these constants ``solution families''. If we want to find one specific solution, we need more information about the value of the function and it's derivatives. This type of problem where a differential equation is coupled with function values is called an initial value problem (IVP).\\\\\r\n\r\n\\begin{definition}\r\n\tAn initial value problem has the general form.\r\n\t\\begin{equation*}\r\n\t\t\\begin{cases}\r\n\t\t\ta_ny^{(n)} + a_{n-1}y^{(n-1)} + \\ldots + a_0y = f(x) \\\\\r\n\t\t\ty(x_0) = y_0 \\\\\r\n\t\t\ty'(x_1) = y_1 \\\\\r\n\t\t\t\\vdots \\\\\r\n\t\t\ty^{(n)}(x_n) = y_n\r\n\t\t\\end{cases}.\r\n\t\\end{equation*}\r\n\tOften, each $x_i$ is 0.\r\n\\end{definition}\r\n\r\n\r\n\\begin{example}\r\n\tThe general solution to the IVP\r\n\t\\begin{equation*}\r\n\t\t\\begin{cases}\r\n\t\t\ty^{\\prime\\prime} - 5y^\\prime + 6y = 0 \\\\\r\n\t\t\ty(0) = 3 \\\\\r\n\t\t\ty^\\prime(0) = 1\r\n\t\t\\end{cases}\r\n\t\\end{equation*}\r\n\tis $y = c_1e^{2x} + c_2e^{3x}$. Find the specific solution.\r\n\\end{example}\r\n\\noindent\r\nEvaluating $y$ at $x = 0$,\r\n\\begin{equation*}\r\n\ty(0) = c_1 + c_2 = 3.\r\n\\end{equation*}\r\nEvaluating $y^\\prime$ at $x = 0$,\r\n\\begin{equation*}\r\n\ty^\\prime(0) = 2c_1 + 3c_2 = 1.\r\n\\end{equation*}\r\nTo find $c_1$ and $c_2$, we need to solve the system of linear equations\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\tc_1 + c_2 = 3 \\\\\r\n\t\t2c_1 + 3c_2 = 1\r\n\t\\end{cases} \\implies \\begin{cases}\r\n\t\tc_1 = 8 \\\\\r\n\t\tc_2 = -5\r\n\t\\end{cases}.\r\n\\end{equation*}\r\nSo, our specific solution to the IVP is\r\n\\begin{equation*}\r\n\ty = 8e^{2x} - 5e^{3x}.\r\n\\end{equation*}\r\n\r\n\\begin{theorem}[Existence and Uniqueness of Solutions to 1st Order IVPs]\r\n\tConsider the IVP\r\n\t\\begin{equation*}\r\n\t\t\\begin{cases}\r\n\t\t\t\\dd{x}{y} = f(x,y) \\\\\r\n\t\t\ty(x_0) = y_0\r\n\t\t\\end{cases}.\r\n\t\\end{equation*}\r\n\tIf $f(x,y)$ and $\\frac{\\partial}{\\partial y}f$ are both continuous on some rectangular region containing the point $(x_0, y_0)$, then the IVP has a unique solution $y = y(x)$ on some open interval containing $x_0$.\r\n\\end{theorem}\r\n\r\n\\begin{example}\r\n\tDoes a solution to the following IVP exist? Is it unique?\r\n\t\\begin{equation*}\r\n\t\t\\begin{cases}\r\n\t\t\t\\dd{y}{x} = x^2 - xy^3 \\\\\r\n\t\t\ty(1) = 6\r\n\t\t\\end{cases}\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\n$f(x,y) = x^2 - xy^3$ and $\\frac{\\partial f}{\\partial y} = -3xy^2$ are continuous on all of $\\R^2$. So, the existence and uniqueness theorem tells us that the IVP has a unique solution on an open interval containing $x_0 = 1$.\r\n\r\n\\begin{example}\r\n\tDoes a solution to the following IVP exist? Is it unique?\r\n\t\\begin{equation*}\r\n\t\t\\begin{cases}\r\n\t\t\t\\dd{y}{x} = 3y^{2/3} \\\\\r\n\t\t\ty(2) = 0\r\n\t\t\\end{cases}\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\n$f(x,y) = 3y^{2/3}$ is continuous on $y \\in \\R$, and $\\frac{\\partial f}{\\partial y} = 2y^{-1/3}$ is continuous on $x \\in \\left(-\\infty, 0\\right) \\cup \\left(0, \\infty\\right)$. Since $\\frac{\\partial f}{\\partial y}$ is not continuous on a domain containing $(2,0)$, the existence and uniqueness theorem does not guarantee a solution.", "meta": {"hexsha": "00f95acc7c1fb332d946b7789a4f31d0e9e03bc2", "size": 3137, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/basics/IVPs/IVPs.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/basics/IVPs/IVPs.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/basics/IVPs/IVPs.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 35.6477272727, "max_line_length": 503, "alphanum_fraction": 0.6445648709, "num_tokens": 1136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619436290699, "lm_q2_score": 0.8887587875995482, "lm_q1q2_score": 0.7327477974417392}}
{"text": "\n\n    \\filetitle{movavg}{Moving average pseudofunction}{modellang/movavg}\n\n\t\\paragraph{Syntax}\\label{syntax}\n\n\\begin{verbatim}\nmovavg(Expr)\nmovavg(Expr,K)\n\\end{verbatim}\n\n\\paragraph{Description}\\label{description}\n\nIf the second input argument, \\texttt{K}, is negative, this function\nexpands to the moving average of the last K periods (including the\ncurrent period), i.e.\n\n\\begin{verbatim}\n(((Expr)+(Expr{-1})+ ... +(Expr{-(K-1)})/-K)\n\\end{verbatim}\n\nwhere \\texttt{Expr\\{-N\\}} derives from \\texttt{Expr} and has all its\ntime subscripts shifted by \\texttt{-N} (if specified).\n\nIf the second input argument, \\texttt{K}, is positive, this function\nexpands to the moving average of the next K periods ahead (including the\ncurrent period), i.e.\n\n\\begin{verbatim}\n(((Expr)+(Expr{1})+ ... +(Expr{K-1})/K)\n\\end{verbatim}\n\nIf the second input argument, \\texttt{K}, is not specified, the default\nvalue -4 is used (based on the fact that most of the macroeconomic\nmodels are quarterly).\n\n\\paragraph{Example}\\label{example}\n\nThe following three lines\n\n\\begin{verbatim}\nmovavg(Z)\nmovavg(Z,-3)\nmovavg(X+Y{-1},2)\n\\end{verbatim}\n\nwill expand to\n\n\\begin{verbatim}\n(((Z)+(Z{-1})+(Z{-2})+(Z{-3}))/4)\n(((Z)+(Z{-1})+(Z{-2}))/3)\n(((X+Y{-1})+(X{1}+Y))/2)\n\\end{verbatim}\n\n\n", "meta": {"hexsha": "b69e6ae25b1772d7fe4c1f3e94ae7f2e0d255dc8", "size": 1250, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "-help/modellang/movavg.tex", "max_stars_repo_name": "OGResearch/IRIS-Toolbox-For-Octave", "max_stars_repo_head_hexsha": "682ea1960229dc701e446137623b120688953cef", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-12-06T13:38:38.000Z", "max_stars_repo_stars_event_max_datetime": "2017-12-06T13:38:38.000Z", "max_issues_repo_path": "-help/modellang/movavg.tex", "max_issues_repo_name": "OGResearch/IRIS-Toolbox-For-Octave", "max_issues_repo_head_hexsha": "682ea1960229dc701e446137623b120688953cef", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-03-28T08:13:20.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-02T10:40:25.000Z", "max_forks_repo_path": "-help/modellang/movavg.tex", "max_forks_repo_name": "OGResearch/IRIS-Toolbox-For-Octave", "max_forks_repo_head_hexsha": "682ea1960229dc701e446137623b120688953cef", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-17T07:06:39.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-17T07:06:39.000Z", "avg_line_length": 22.3214285714, "max_line_length": 72, "alphanum_fraction": 0.6912, "num_tokens": 389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7327477923379618}}
{"text": "\n\\subsection{Convolutional layers}\n\nCan connect each  node in first hidden layer to a subset of the input layer, eg one node for each 5x5 pixels\n\nWe also share weights for each of the first layer. Much fewer parameters, and can learn all good stuff\n\nThis also uses windows. Instead of max we multiply the window by a matrix elementwise and sum the values\n\nEach matrix can represent some feature, like a curve.\n\nWe can use multiply convolution matrices to create multiple output matrices.\n\nMatrices are called kernels. they are trained. start off random\n\n\\subsubsection{Training convolutional layers}\n\n\n", "meta": {"hexsha": "89cf54a63ef8b1ff8ac9b03e56a208adef3b5100", "size": 602, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/neuralNetworksConvolution/01-01-convolutional.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/neuralNetworksConvolution/01-01-convolutional.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/neuralNetworksConvolution/01-01-convolutional.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.6842105263, "max_line_length": 108, "alphanum_fraction": 0.7990033223, "num_tokens": 127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896737173119, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.7326337668093273}}
{"text": "\\section{Multiple Synthetic Risky Assets}\nIn this section we present an application of the learning algorithms considered above to a multi-asset allocation problem. Given the difficulties of learning a profitable strategy for historical data, we consider once again synthetic price series that can be traded profitably. To define the generative model, we start from a continuous-time formulation and then derive a discrete-time model using standard discretization techniques. In particular, we assume that the market consists of two risky asset $\\{S_t^1, S_t^2\\}$, whose prices evolve according to the following dynamics\n\\begin{equation}\n\t\\begin{cases}\n\t\t\\frac{dS_t^1}{S_t^1} &= \\sigma_1 dW_t^1\\\\ \n\t\t\\frac{dS_t^2}{S_t^2} &= \\frac{1}{2} \\sigma_\\chi^2 dt + \\sigma_2 dW_t^2 + d\\chi_t\\\\\n\t\td\\chi_t &= -\\lambda \\chi_t dt + \\sigma_\\chi dW_t^\\chi\\\\\n\t\\end{cases}\n\\end{equation}\nwhere $\\{W_t^1, W_t^2, W_t^\\chi\\}$ are standard Brownian motions such that $\\E {dW_t^1 dW_t^2} = \\rho dt$, with $-1 \\leq \\rho \\leq 1$, $W_t^\\chi \\independent (W_t^1, W_t^2)$, \n$\\sigma_1$, $\\sigma_2$, $\\sigma_\\chi$, $\\lambda >0$ and $\\chi_0 = 0$. The Ornstein-Uhlenbeck process $\\chi_t$ represents a mean-reverting spread between the two risky assets. Let $\\widetilde{S}_t^i = \\log S_t^i$, $i \\in \\{1,2\\}$ denote the log-price. A simple application of Itô's lemma yields \n\\begin{equation}\n\t\\label{eq:sde}\n\t\\begin{cases}\n\t\td\\widetilde{S}_t^1 &= -\\frac{1}{2} \\sigma_1^2 dt + \\sigma_1 dW_t^1\\\\ \n\t\td\\widetilde{S}_t^2 &= -\\frac{1}{2} \\sigma_2^2 dt + \\sigma_2 dW_t^2 + d\\chi_t\\\\\n\t\td(e^{\\lambda t} \\chi_t) &= \\sigma_\\chi e^{\\lambda t} dW_t^\\chi\\\\\n\t\\end{cases}\n\\end{equation}\nIntegrating between $0$ and $t$ and rearranging the various terms, we obtain\n\\begin{equation}\n\t\\label{eq:sol_sde}\n\t\\begin{cases}\n\t\tS_t^1 &= S_0^1 e^{-\\frac{1}{2} \\sigma_1^2 t + \\sigma_1 W_t^1}\\\\ \n\t\tS_t^2 &= S_0^2 e^{-\\frac{1}{2} \\sigma_2^2 t + \\sigma_2 W_t^2 + \\chi_t}\\\\\n\t\t\\chi_t &= \\sigma_\\chi \\int_0^t e^{-\\lambda (t-u)} dW_u^\\chi\\\\\n\t\\end{cases}\n\\end{equation}\nWe notice that the spread is a Gaussian process and $\\forall t > 0$\n\\begin{equation} \n\t\\chi_t \\sim \\calN\\left(0, \\frac{\\sigma_\\chi^2}{2\\lambda}\\left(1-e^{-2\\lambda t}\\right) \\right)\n\\end{equation}\nTo better understand the role of the spread, let us remind that $W_t^2$ can be decomposed in the following way \n\\begin{equation}\n\tW_t^2 = \\rho W_t^1 + \\sqrt{1-\\rho^2} W_t^{\\independent}\n\\end{equation}\nwhere $W_t^{\\independent} \\independent W_t^1$ is a standard Brownian motion. Thus, we have \n\\begin{equation}\n\t\\frac{S_t^2}{S_t^1} = \\frac{S_0^2}{S_0^1} e^{-\\frac{1}{2}(\\sigma_2^2 - \\sigma_1^2) t + (\\rho \\sigma_2 - \\sigma_1) W_t^1 + \\sigma_2 \\sqrt{1-\\rho^2} W_t^{\\independent}} e^{\\chi_t} \n\\end{equation} \nTaking the expected value, we obtain \n\\begin{equation}\n\t\\E{\\frac{S_t^2}{S_t^1}} = \\frac{S_0^2}{S_0^1} e^{\\sigma_1 (\\sigma_1 - \\rho \\sigma_2) t} e^{\\frac{\\sigma_\\chi^2}{4\\lambda} (1-e^{-2\\lambda t})} \n\\end{equation} \nThe term coming from the stochastic spread disappears in the long term. In the limit case where $\\sigma_1 = \\sigma_2$ and $\\rho = 1$. Then \n\\begin{equation}\n\t\\E{\\frac{S_t^2}{S_t^1}} = \\frac{S_0^2}{S_0^1} e^{\\frac{\\sigma_\\chi^2}{4\\lambda} (1-e^{-2\\lambda t})} \\underset{t \\to \\infty}{\\to} \\frac{S_0^2}{S_0^1}\n\\end{equation} \nTherefore, the expected value of the ratio between the prices of the two risky assets mean-reverts to the initial ratio. It is easy to understand that this feature can be traded profitably by betting on the convergence of the two assets to their long-term regime.\\\\\nThe solutions of the system (\\ref{eq:sol_sde}) can be easily used to simulate the risky assets prices, which can then be used as inputs of the asset allocation problem. An alternative approach is to obtain the discrete-time dynamics of the system. Let us consider a uniform time-grid $t_k = k \\Delta t$, $k \\in \\mathbb{N}$, and let us integrate the system (\\ref{eq:sde}) between $t_k$ and $t_{k+1}$. After some simple algebraic manipulations, we obtain the following equations \n\\begin{equation}\n\t\\label{eq:dt_dynamics}\n\t\\begin{cases}\n\t\t\\widetilde{S}_{k+1}^1 &= \\widetilde{S}_{k}^1 -\\frac{1}{2} \\sigma_1^2 \\Delta t + \\sigma_1 \\sqrt{t} \\epsilon_k^1\\\\ \n\t\t\\widetilde{S}_{k+1}^2 &= \\widetilde{S}_{k}^2 -\\frac{1}{2} \\sigma_2^2 \\Delta t + \\sigma_2 \\sqrt{t} \\epsilon_k^2 + \\chi_{k+1} - \\chi_k\\\\\n\t\t\\chi_{k+1} &= e^{-\\lambda \\Delta t} \\chi_k + \\sigma_\\chi \\sqrt{\\frac{1-e^{-2\\lambda \\Delta t}}{2\\lambda}} \\epsilon_k^\\chi\n\t\\end{cases}\n\\end{equation}\nwhere the noises are a Gaussain white noise with the following structure\n\\begin{equation}\n\t\\begin{bmatrix}\n\t  \t\\epsilon_k^1\\\\\n\t  \t\\epsilon_k^2\\\\\n\t  \t\\epsilon_k^\\chi\\\\\t  \n\t\\end{bmatrix} \\sim \\calN\\left( \n\t\\begin{bmatrix}\n\t\t  \t0\\\\\n\t\t  \t0\\\\\n\t\t  \t0\\\\\t  \n\t\\end{bmatrix}, \n\t\\begin{bmatrix}\n\t\t  \t1, \\rho, 0\\\\\n\t\t  \t\\rho, 1, 0\\\\\n\t\t  \t0, 0, 1\\\\\t  \n\t\\end{bmatrix}\t\n\t\\right)\n\\end{equation}\nWe expect to be possible to trade the two risky assets profitably using an approach similar to the well-known pairs trading technique for cointegrated assets. Intuitively, because of the mean-reversion of the stochastic spread, we should be able to generate a profit by betting on the convergence of the prices of the two assets when they are far apart by selling the more expensive asset and buying the cheaper one. For these considerations, we expect the RL algorithms discussed in the previous chapters to be able to spot this pattern and exploit it to generate a profit. \n\n\\begin{figure}[t!]\n\t\\centering\n\t\\includegraphics[width=0.8\\textwidth]{Images/8_cointegrated_series}\n\t\\caption[Sample paths for the risky assets with a mean-reverting spread.]{Sample paths for the risky assets with a mean-reverting spread.}\n\t\\label{fig:cointegrated_series}\n\\end{figure}\n\n\\subsection{Specifications of the Learning Algorithms}\nThe parametric policies used in Section \\ref{sec:synthetic_risky_asset} can be directly used in this setting to select the weight of one of the assets. Given the poor results obtained with ARAC, we only focus on the PGPE and NPGPE algorithms. The weight on the first asset is selected using The following controller \n\\begin{equation*}\n\ta^1 = F_\\theta(s) = \\sign(\\theta \\cdot s)\n\\end{equation*}\nwhere in PGPE the parameters are sampled from a multi-variate Gaussian distribution\n\\begin{equation*}\n\t\\theta \\sim \\calN(\\mu, \\diag(\\sigma))\n\\end{equation*}  \nwhile in NPGPE the controller parameters are sampled from a Gaussian distribution parameterized by its mean and Cholesky factor\n\\begin{equation*}\n\t\\theta \\sim \\calN(\\mu, C^T C)\n\\end{equation*}  \nThe long-short strategy is completed by selecting $a^2 = - a^1$. In this case we notice that $a^1 + a^2 = 0$, which means that the long position on one asset is entirely financed by the short position on the other asset. Clearly, this assumption is simplistic as it neglects all the practical constraints on short-selling. Given that we will always be short on one of the two assets, we will also neglect short-selling fees, i.e. $\\delta_s = 0$. ", "meta": {"hexsha": "0c70721044dcbe25aa7f20c0383bd9953b1b409c", "size": 6938, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/Chapters/8_1_Multiple_Assets.tex", "max_stars_repo_name": "AmineAboussalah/Thesis", "max_stars_repo_head_hexsha": "1a3ae97023acff1ee5e2d197a446734117a6fb99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 80, "max_stars_repo_stars_event_min_datetime": "2016-06-13T15:20:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T23:47:13.000Z", "max_issues_repo_path": "Report/Chapters/8_1_Multiple_Assets.tex", "max_issues_repo_name": "pnecchi/Thesis", "max_issues_repo_head_hexsha": "1a3ae97023acff1ee5e2d197a446734117a6fb99", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/Chapters/8_1_Multiple_Assets.tex", "max_forks_repo_name": "pnecchi/Thesis", "max_forks_repo_head_hexsha": "1a3ae97023acff1ee5e2d197a446734117a6fb99", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 34, "max_forks_repo_forks_event_min_datetime": "2017-05-15T07:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-21T21:48:53.000Z", "avg_line_length": 69.38, "max_line_length": 578, "alphanum_fraction": 0.712741424, "num_tokens": 2318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7326146376294318}}
{"text": "\\section{Definition and examples}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Understand the definition of a linear transformation in the\n    context of vector spaces.\n  \\item Determine whether a function is linear or not.\n  \\end{enumerate}\n\\end{outcome}\n\nIn Chapter~\\ref{cha:linear-transformation}, we defined a linear\ntransformation $T:\\R^n\\to\\R^m$ to be a function that preserves\naddition and scalar multiplication. We now revisit this concept in the\nmore general setting of vector spaces $V$ and $W$.\n\n\\begin{definition}{Linear transformation}{linear-transformation-vector-space}\n  Let $V$ and $W$ be vector spaces over some field $K$. A function\n  $T: V \\to W$ is called a \\textbf{linear transformation}%\n  \\index{linear transformation}%\n  \\index{linear transformation!on vector spaces} from $V$ to $W$ if\n  it satisfies the following two conditions:\n  \\begin{enumerate}\n  \\item $T$ preserves addition, i.e., for all\\/\n    $\\vect{v},\\vect{w}\\in V$, we have\n    $T(\\vect{v}+\\vect{w}) = T(\\vect{v}) + T(\\vect{w})$;\n  \\item $T$ preserves scalar multiplication, i.e, for all\\/\n    $\\vect{v}\\in V$ and $k\\in K$, we have\n    $T(k\\vect{v}) = kT(\\vect{v})$.\n  \\end{enumerate}\n  A linear transformation is also sometimes called a \\textbf{linear\n    function} or a \\textbf{linear map}. A linear transformation\n  $T:V\\to V$ (i.e., when $V=W$) is also sometimes called an\n  \\textbf{operator}%\n  \\index{operator}%\n  \\index{operator|seealso{linear transformation}}.\n\\end{definition}\n\nOur first example of a linear transformation is a matrix\ntransformation. We have already seen this in\nSection~\\ref{sec:matrix-of-transformation}.\n\n\\begin{example}{Matrix transformation}{matrix-transformation}\n  Let $A$ be an $m\\times n$-matrix. Then the function $T:\\R^m\\to\\R^n$\n  defined by $T(\\vect{v})=A\\vect{v}$ is a linear transformation,\n  called a \\textbf{matrix transformation}%\n  \\index{matrix transformation}. This was proved in\n  Proposition~\\ref{prop:matrix-are-linear}.\n\\end{example}\n\nThere are many interesting examples of linear transformations on\nvector spaces other than $\\R^n$. We will consider a few such examples.\n\n\\begin{example}{Derivative operator}{derivative-operator}\n  Let $\\Poly_n$ be the vector space of real polynomials of degree at\n  most $n$. The function $D:\\Poly_n\\to\\Poly_{n-1}$ is defined by\n  \\begin{equation*}\n    D(p(x)) = p'(x),\n  \\end{equation*}\n  where $p'(x)$ denotes the derivative of the polynomial $p(x)$. The\n  function $D$ is called the \\textbf{derivative operator}.\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item Compute $D(x^3)$, $D(2x^2+x)$, and $D(ax^3+bx^2+cx+d)$.\n    \\item Show that $D$ is a linear transformation.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{example}\n\n\\begin{solution}\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item In each case, we simply take the derivative:\n      \\begin{eqnarray*}\n        D(x^3) &=& 3x^2, \\\\\n        D(2x^2+x) &=& 4x+1, \\\\\n        D(ax^3+bx^2+cx+d) &=& 3ax^2 + 2bx + c.\n      \\end{eqnarray*}\n    \\item First, we note that if $p(x)$ is a polynomial of degree at\n      most $n$, then its derivative $p'(x)$ is a polynomial of degree\n      at most $n-1$. Therefore, the derivative operator $D$ is a\n      well-defined function from $\\Poly_n$ to $\\Poly_{n-1}$. To show that\n      it preserves addition, consider any two polynomials\n      $p(x),q(x)\\in\\Poly_n$. From calculus, we know that the\n      derivative of $p(x)+q(x)$ is $p'(x)+q'(x)$. Therefore,\n      \\begin{equation*}\n        D(p(x)+q(x)) ~=~ (p(x)+q(x))' ~=~ p'(x)+q'(x) ~=~ D(p(x)) + D(q(x)),\n      \\end{equation*}\n      and so $D$ preserves addition. To show that it preserves scalar\n      multiplication, consider $p(x)\\in\\Poly_n$ and $k\\in\\R$. From\n      calculus, we know that the derivative of $kp(x)$ is $kp'(x)$, and\n      therefore\n      \\begin{equation*}\n        D(kp(x)) ~=~ (kp(x))' ~=~ kp'(x) ~=~ kD(p(x)).\n      \\end{equation*}\n      Hence, $D$ preserves scalar multiplication. It follows that $D$ is a\n      linear transformation.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{solution}\n\nIt is important to understand that we are not claiming that the\nderivative $p'(x)$ of a polynomial $p(x)$ is a linear function. It is\nof course a polynomial. Rather, what the above example shows is that\nthe act of {\\em taking} the derivative is a linear operation, i.e.,\nthe derivative of a sum is the sum of the derivatives, and the\nderivative of a constant times a function is a constant times the\nderivative.\n\n\\begin{example}{A differential equation}{differential-equation-derivative-operator}\n  Solve the equation $p(x) = x^3 + D(p(x))$, where\n  $D:\\Poly_3\\to\\Poly_2$ is the derivative operator of\n  Example~\\ref{exa:derivative-operator}.\n\\end{example}\n\n\\begin{solution}\n  Every element of $P_3$ is of the form $p(x) = ax^3 + bx^2 + cx + d$.\n  We can write the equation $p(x) = x^3 + D(p(x))$ as\n  \\begin{equation*}\n    (ax^3 + bx^2 + cx + d) = x^3 + (3ax^2 + 2bx + c).\n  \\end{equation*}\n  For the left-hand side and right-hand side to be equal, we must have\n  $a=1$, $b=3a$, $c=2b$, and $d=c$. This yields the unique solution\n  $(a,b,c,d) = (1,3,6,6)$, or $p(x) = x^3+3x^2+6x+6$.\n\\end{solution}\n\n\\begin{example}{The shift and unshift operators}{shift-unshift}\n  Consider the vector space $\\Seq_K$ of infinite sequences of elements\n  of $K$. The function $\\shift:\\Seq_K\\to\\Seq_K$ is defined by shifting\n  the entire sequence to the left and dropping the first element:\n  \\begin{equation*}\n    \\shift(a_0,a_1,a_2,a_3,\\ldots) = (a_1,a_2,a_3,a_4,\\ldots).\n  \\end{equation*}\n  The function $\\unshift:\\Seq_K\\to\\Seq_K$ is defined by shifting the\n  entire sequence to the right and adding $0$ as the new first\n  element:\n  \\begin{equation*}\n    \\unshift(a_0,a_1,a_2,a_3,\\ldots) = (0,a_0,a_1,a_2,\\ldots).\n  \\end{equation*}\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item Compute $\\shift(1,2,3,\\ldots)$,\n      $\\unshift(\\shift(1,1,1,\\ldots))$, and\n      $\\shift(\\unshift(1,1,1,\\ldots))$.\n    \\item Show that $\\shift$ and $\\unshift$ are linear transformations.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{example}\n\n\\begin{solution}\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item We have\n      \\begin{eqnarray*}\n        \\shift(1,2,3,4,\\ldots)\n        &=& (2,3,4,5,\\ldots), \\\\\n        \\unshift(\\shift(1,1,1,1,\\ldots))\n        &=& \\unshift(1,1,1,1,\\ldots)\n        ~~=~~ (0,1,1,1,\\ldots), \\\\\n        \\shift(\\unshift(1,1,1,1,\\ldots))\n        &=& \\shift(0,1,1,1,\\ldots)\n        ~~=~~ (1,1,1,1,\\ldots).\n      \\end{eqnarray*}\n    \\item To show that $\\shift$ is a linear transformation, we show\n      that it preserves addition and scalar multiplication. Let\n      $a=(a_0,a_1,a_2,\\ldots)$ and $b=(b_0,b_1,b_2,\\ldots)$. Then\n      \\begin{eqnarray*}\n        \\shift(a+b) &=& \\shift(a_0+b_0,~a_1+b_1,~a_2+b_2,~\\ldots) \\\\\n                    &=& (a_1+b_1,~a_2+b_2,~a_3+b_3,~\\ldots) \\\\\n                    &=& (a_1,~a_2,~a_3,~\\ldots) + (b_1,~b_2,~b_3,~\\ldots) \\\\\n                    &=& \\shift(a) + \\shift(b),~ \\\\\n        \\shift(ka)  &=& \\shift(ka_0,~ka_1,~ka_2,~\\ldots) \\\\\n                    &=& (ka_1,~ka_2,~ka_3,~\\ldots) \\\\\n                    &=& k(a_1,~a_2,~a_3,~\\ldots) \\\\\n                    &=& k\\shift(a).\n      \\end{eqnarray*}\n      Therefore, $\\shift$ is a linear transformation. The proof for\n      $\\unshift$ is similar.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{solution}\n\n\\begin{example}{Properties of shift and unshift}{shift-unshift-properties}\n  Show that for all sequences $a\\in\\Seq_K$, we have\n  $\\shift(\\unshift(a))=a$. On the other hand, show that in general,\n  $\\unshift(\\shift(a))\\neq a$.\n\\end{example}\n\n\\begin{solution}\n  For $a=(a_0,a_1,a_2,\\ldots)$, we have\n  \\begin{equation*}\n    \\shift(\\unshift(a))\n    ~=~ \\shift(\\unshift(a_0,a_1,a_2,\\ldots))\n    ~=~ \\shift(0,a_0,a_1,\\ldots)\n    ~=~ (a_0,a_1,a_2,\\ldots)\n    ~=~ a.\n  \\end{equation*}\n  On the other hand, we have\n  \\begin{equation*}\n    \\unshift(\\shift(a))\n    ~=~ \\unshift(\\shift(a_0,a_1,a_2,\\ldots))\n    ~=~ \\unshift(a_1,a_2,a_3,\\ldots)\n    ~=~ (0,a_1,a_2,\\ldots).\n  \\end{equation*}\n  The latter is not equal to $a$ unless $a_0=0$.\n\\end{solution}\n\n\\begin{example}{Recurrence as a linear equation}{recurrence-as-equation}\n  Find the general solution to the following equation, where\n  $a\\in\\Seq_K$:\n  \\begin{equation*}\n    \\shift(\\shift(a)) = \\shift(a) + a.\n  \\end{equation*}\n  Where have you seen this equation before?\n\\end{example}\n\n\\begin{solution}\n  For $a=(a_0,a_1,a_2,\\ldots)$, we have\n  \\begin{eqnarray*}\n    \\shift(\\shift(a)) &=& (a_2,a_3,a_4,\\ldots), \\\\\n    \\shift(a) &=& (a_1,a_2,a_3,\\ldots), \\\\\n    a &=& (a_0,a_1,a_2,\\ldots).\n  \\end{eqnarray*}\n  Therefore $a$ is a solution of the equation $\\shift(\\shift(a)) =\n  \\shift(a) + a$ if and only if\n  \\begin{eqnarray*}\n    a_2 &=& a_1 + a_0, \\\\\n    a_3 &=& a_2 + a_1, \\\\\n    a_4 &=& a_3 + a_2,\n  \\end{eqnarray*}\n  and so on. In other words, $a$ is a solution if and only if\n  $a_{n+2} = a_{n+1} + a_n$ holds for all $n\\geq 0$. This is nothing\n  but the recurrence relation of\n  Example~\\ref{exa:subspace-recurrence}. We already calculated the\n  general solution in\n  Example~{\\ref{exa:subspace-recurrence-dimension}}. The general\n  solution is\n  \\begin{equation*}\n    a = (x,~y,~x+y,~x+2y,~2x+3y,~3x+5y,~\\ldots),\n  \\end{equation*}\n  and a basis for the solution space is\n  \\begin{equation*}\n    \\set{(1,0,1,1,2,3,\\ldots),~ (0,1,1,2,3,5,\\ldots)}.\n  \\end{equation*}\n\\end{solution}\n\nWe conclude this section by stating some elementary properties of\nlinear transformations. ``Elementary'' means that these properties\nfollow directly from the definition, i.e., from the fact that linear\ntransformations preserve addition and scalar multiplication.\n\n\\begin{proposition}{Properties of linear transformations}{properties-linear-transformations}\n  Let $V$ and $W$ be vector spaces over a field $K$, and let\n  $T:V \\to W$ be a linear transformation.  Then\n  \\begin{itemize}\n  \\item $T$ preserves the zero vector:\n    $T(\\vect{0})=\\vect{0}$.\n  \\item $T$ preserves additive inverses:\n    $T(-\\vect{v})= -T(\\vect{v})$.\n  \\item $T$ preserves linear combinations:\n    \\begin{equation*}\n      T(a_1\\vect{v}_1 + a_2\\vect{v}_2 + \\ldots + a_k\\vect{v}_k)\n      ~=~\n      a_1T(\\vect{v}_1) + a_2T(\\vect{v}_2) + \\ldots + a_kT(\\vect{v}_k).\n    \\end{equation*}\n  \\end{itemize}\n\\end{proposition}\n\n\\begin{proof}\n  To prove the first property, let $k=0$ in the equation\n  $T(k\\vect{v}) = kT(\\vect{v})$. Since $0\\vect{v}=\\vect{0}$ and\n  $0T(\\vect{v})=\\vect{0}$ by\n  Proposition~\\ref{prop:vector-space-elementary}, we therefore have\n  $T(\\vect{0}) = \\vect{0}$.  Similarly, to prove the second property,\n  let $k=-1$ in the equation $T(k\\vect{v}) = kT(\\vect{v})$.\n  Finally, the third property is a direct consequence of the fact that\n  $T$ preserves addition and scalar multiplication:\n  \\begin{eqnarray*}\n    T(a_1\\vect{v}_1 + a_2\\vect{v}_2 + \\ldots + a_k\\vect{v}_k)\n    &=& T(a_1\\vect{v}_1) + T(a_2\\vect{v}_2) + \\ldots + T(a_k\\vect{v}_k) \\\\\n    &=& a_1T(\\vect{v}_1) + a_2T(\\vect{v}_2) + \\ldots + a_kT(\\vect{v}_k).\n  \\end{eqnarray*}\n\\end{proof}\n", "meta": {"hexsha": "110a1d659c1cdab7255aff35b619b7bffc481c66", "size": 11065, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/LinearTransformationsGeneral-Definition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/LinearTransformationsGeneral-Definition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/LinearTransformationsGeneral-Definition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 39.0989399293, "max_line_length": 92, "alphanum_fraction": 0.6419340262, "num_tokens": 3878, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.8791467738423874, "lm_q1q2_score": 0.7326146222538242}}
{"text": "%---------------------------Oddy---------------------------\n\\section{Oddy}\n\nFirst we define the Oddy $O$ in terms of the Jacobian matrices $A_i$ from \\S\\ref{s:hex}:\n\\[\n  O(A_i) = \\frac{\\left| A_i^t A_i \\right|^2 - \\frac {1}{3}\\left|A_i\\right|^4}{\\alpha_i^{\\frac{4}{3}}}.\n\\]\nThe metric value is then the maximum Oddy over all the corners and the element center\n\\[\n  q = \\max_{i\\in\\{0,1,\\ldots,8\\}}\\left\\{ O(A_i) \\right\\}.\n\\]\nThis can be interpreted as the maximum deviation of\nthe metric tensor ($A_i^tA_i$) from the identity matrix, evaluated at the corners and element center.\n\nNote that if $\\alpha_i \\leq DBL\\_MIN$ for any $i$, we set $q = DBL\\_MAX$.\n\n\\hexmetrictable{Oddy}%\n{$1$}%                                        Dimension\n{$[0,0.5]$}%                                  Acceptable range\n{$[0,DBL\\_MAX]$}%                             Normal range\n{$[0,DBL\\_MAX]$}%                             Full range\n{$0$}%                                        Cube\n{Adapted from \\cite{odd:88}}%                 Citation\n{v\\_hex\\_oddy}%                               Verdict function name\n", "meta": {"hexsha": "f2829ff6b0170f5cedb9b357ef47ecbaefbdda8c", "size": 1086, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexOddy.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexOddy.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexOddy.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 43.44, "max_line_length": 102, "alphanum_fraction": 0.5055248619, "num_tokens": 312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067244294588, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.73261034119291}}
{"text": "\n\\subsection{Randomly Controlled Trials (RCTs)}\n\nIf the model is:\n\n\\(y_i=D_i\\theta +g(X) +\\epsilon_i\\)\n\nAnd \\(D\\) is randomly assigned, then we can estimate\n\n\\(y_i=D_i\\theta +\\epsilon_i\\)\n\nTo get an estimate for \\(\\theta \\) without collecting data on \\(X\\).\n\n", "meta": {"hexsha": "0edf641f3ff6ac58f2634feee9f3a20c316a55bc", "size": 259, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/treatmentHomo/02-01-RCT.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/treatmentHomo/02-01-RCT.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/treatmentHomo/02-01-RCT.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.5, "max_line_length": 68, "alphanum_fraction": 0.6872586873, "num_tokens": 78, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9525741281688025, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.732605931277751}}
{"text": "\\section{Maxwell's Equations}\r\nJust a little identity on Laplacian of vector fields\r\n\\begin{proposition}\r\n    We have\r\n    $$\\nabla^2\\underline{F}=\\nabla(\\nabla\\cdot\\underline{F})-\\nabla\\times(\\nabla\\times\\underline{F})$$\r\n    where $(\\nabla^2\\underline{F})_i=\\nabla^2\\underline{F_i}$\r\n\\end{proposition}\r\n\\subsection{Introduction to Electromagnetism}\r\nWe have the electric field $\\underline{E}=\\underline{E}(\\underline{x},t)$, the magnetic field $\\underline{B}=\\underline{B}(\\underline{x},t)$, charge density $\\rho=\\rho(\\underline{x},t)$ and current density $\\underline{J}=\\underline{J}(\\underline{x},t)$.\r\nThe Maxwell's Equations state that\r\n$$\\begin{cases}\r\n    \\nabla\\cdot\\underline{E}=\\epsilon_0^{-1}\\rho\\\\\r\n    \\nabla\\cdot\\underline{B}=0\\\\\r\n    \\nabla\\times\\underline{E}+\\partial\\underline{B}/\\partial t=0\\\\\r\n    \\nabla\\times\\underline{B}-\\mu_0\\epsilon_0\\partial\\underline{E}/\\partial t=\\mu_0\\underline{J}\r\n\\end{cases}$$\r\nwhere $\\epsilon_0$ is the permitivity and $\\mu_0$ is the permeability of free space with $\\mu_0\\epsilon_0=c^{-2}$ where $c$ is the speed of light.\r\nTake the divergence of the fourth equation gives\r\n$$0=\\mu_0\\epsilon_0\\frac{\\partial}{\\partial t}(\\nabla\\cdot\\underline{E})+\\mu_0\\nabla\\cdot\\underline{J}\\implies 0=\\frac{\\partial\\rho}{\\partial t}+\\nabla\\cdot\\underline{J}$$\r\n\\subsection{Integral Forms of Maxwell's Equations}\r\nIf we integrate then first equation and use divergence theorem to integrate the electric field over the flux of the boundary of a volume, we get\r\n$$\\int_{\\partial V}\\underline{E}\\cdot\\mathrm d\\underline{S}=\\int_V\\nabla\\cdot\\underline{E}\\,\\mathrm dV=\\frac{1}{\\epsilon_0}\\int_V\\rho\\,\\mathrm dV=\\frac{Q}{\\epsilon_0}$$\r\nwhere $Q$ is the total charge of the volume $V$.\r\nDo exactly the same thing with th second equation then gives\r\n$$\\int_{\\partial V}\\underline{B}\\cdot\\mathrm d\\underline{S}=\\int_V\\nabla\\cdot\\underline{B}\\,\\mathrm dV=0$$\r\nwhich is saying that there is no magnetic monopoles since we cannot have a singular pole that emit magnetic field out of a volume.\r\nIn fact, if somewhere there exists a magnetic monopole, then charges are necessarily quantized.\\\\\r\nAs for the third equation, we have\r\n$$\\oint_{\\partial S}\\underline{E}\\cdot\\mathrm d\\underline{x}=\\int_S\\nabla\\times\\underline{E}\\cdot\\mathrm d\\underline{S}=-\\frac{\\mathrm d}{\\mathrm dt}\\int_S\\underline{B}\\,\\mathrm d\\underline{S}$$\r\nSo change in magnetic flux induces electric field.\r\nSimilarly, in the fourth equation,\r\n$$\\oint_{\\partial S}\\underline{B}\\cdot\\mathrm d\\underline{x}=\\int_S\\nabla\\times\\underline{B}\\cdot\\mathrm d\\underline{S}=\\mu_0\\epsilon_0\\frac{\\mathrm d}{\\mathrm dt}\\int_S\\underline{E}\\cdot\\mathrm d\\underline{S}+\\mu_0\\int_S\\underline{J}\\cdot\\mathrm d\\underline{S}$$\r\n\\subsection{Electromagnetic Waves}\r\nIn a free space, where $\\rho=\\underline{J}=\\underline{0}$, then\r\n\\begin{align*}\r\n    \\nabla^2\\underline{E}&=\\nabla(\\nabla\\cdot\\underline{E})-\\nabla\\times(\\nabla\\times\\underline{E})\\\\\r\n    &=0-\\nabla\\times\\left(-\\frac{\\partial\\underline{B}}{\\partial t}\\right)\\\\\r\n    &=\\frac{\\partial}{\\partial t}(\\nabla\\times\\underline{B})\\\\\r\n    &=\\mu_0\\epsilon_0\\frac{\\partial^2\\underline{E}}{\\partial t^2}\\\\\r\n    \\implies 0&=\\nabla^2\\underline{E}-\\frac{1}{c^2}\\frac{\\partial^2\\underline{E}}{\\partial t^2}\r\n\\end{align*}\r\nwhich is the wave equation of a wave with speed $c$.\r\nIf we do the same thing to $\\underline{B}$, we obtain\r\n\\begin{align*}\r\n    \\nabla^2\\underline{B}&=\\nabla(\\nabla\\cdot\\underline{B})-\\nabla\\times(\\nabla\\times\\underline{B})\\\\\r\n    &=0-\\nabla\\times\\left(\\frac{1}{c^2}\\frac{\\partial\\underline{E}}{\\partial t}\\right)\\\\\r\n    &=-\\frac{1}{c^2}\\frac{\\partial}{\\partial t}(\\nabla\\times\\underline{E})\\\\\r\n    &=\\frac{1}{c^2}\\frac{\\partial^2\\underline{B}}{\\partial t^2}\\\\\r\n    \\implies 0&=\\nabla^2\\underline{B}-\\frac{1}{c^2}\\frac{\\partial^2\\underline{B}}{\\partial t^2}\r\n\\end{align*}\r\n\\subsection{Electrostatics and Magnitostatics}\r\nAssume that everything is time-independent, then $t$-derivatives are all $0$, which produces\r\n$$\\begin{cases}\r\n    \\nabla\\cdot\\underline{E}=\\epsilon_0^{-1}\\rho\\\\\r\n    \\nabla\\cdot\\underline{B}=0\\\\\r\n    \\nabla\\times\\underline{E}=0\\\\\r\n    \\nabla\\times\\underline{B}=\\mu_0\\underline{J}\r\n\\end{cases}$$\r\nSo if we work in $\\mathbb R^3$ which is $2$-connected, we can write $\\underline{E}=-\\nabla\\phi$ and $\\underline{B}=\\nabla\\times\\underline{A}$ for some $\\phi,\\underline{A}$.\r\n$\\phi$ is called the electric potential and $\\underline{A}$ the magnetic potential.\r\nSo Maxwell's equations reduce to\r\n$$\\begin{cases}\r\n    -\\nabla^2\\phi=\\rho/\\epsilon_0\\\\\r\n    \\nabla\\times(\\nabla\\times\\underline{A})=\\mu_0\\underline{J}\r\n\\end{cases}$$\r\nThe first one is called the Poisson's Equation.\r\n\\subsection{Gauge Invariance}\r\nIn a $2$-connected domain, we can always write $\\underline{B}=\\nabla\\times\\underline{A}$.\r\nBut note that the equation still holds by adding the gradient of some scalar function to $\\underline{A}$, so $\\underline{B}$ is invariant under $\\underline{A}\\mapsto\\underline{A}+\\nabla\\chi$ for $\\chi=\\chi(\\underline{x},t)$.\r\nIf we put the vector potential into the third equation,\r\n$$\\nabla\\times\\left( \\underline{E}+\\frac{\\partial\\underline{B}}{\\partial t} \\right)=0$$\r\nSo we can write $\\underline{E}=-\\nabla\\phi-\\partial\\underline{B}/\\partial t$, so we have\r\n$$-\\nabla^2\\phi-\\frac{\\partial}{\\partial t}(\\nabla\\cdot\\underline{A})=\\frac{\\rho}{\\epsilon_0}$$\r\nAnd\r\n$$\\nabla\\times(\\nabla\\times A)+\\frac{1}{c^2}\\nabla\\left( \\frac{\\partial\\phi}{\\partial t} \\right)+\\frac{1}{c^2}\\frac{\\partial^2\\underline{A}}{\\partial t^2}=\\mu_0\\underline{J}$$\r\nBut by a known identity on curl of curl,\r\n$$-\\nabla^2\\underline{A}+\\frac{1}{c^2}\\frac{\\partial^2\\underline{A}}{\\partial t^2}+\\nabla\\left( \\frac{1}{c^2}\\frac{\\partial\\phi}{\\partial t}+\\nabla\\cdot\\underline{A} \\right)=\\mu_0\\underline{J}$$\r\nWe now choose the scalar field $\\chi$ such that\r\n$$\\frac{1}{c^2}\\frac{\\partial\\phi}{\\partial t}+\\nabla\\cdot\\underline{A}=0$$\r\nunder $\\underline{A}\\mapsto\\underline{A}+\\nabla\\chi$.\r\nSo we can get an equation similar to a wave equation\r\n$$-\\nabla^2\\underline{A}+\\frac{1}{c^2}\\frac{\\partial^2\\underline{A}}{\\partial t^2}=\\mu_0\\underline{J}$$\r\nand\r\n$$-\\nabla^2\\phi+\\frac{1}{c^2}\\frac{\\partial^2\\phi}{\\partial t^2}=\\frac{\\rho}{\\epsilon_0}$$\r\nThis trick is called the Lorenz gauge.", "meta": {"hexsha": "352bc0ec0799e73d676433583228535f76ecf94c", "size": 6214, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6/maxwell.tex", "max_stars_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_stars_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6/maxwell.tex", "max_issues_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_issues_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6/maxwell.tex", "max_forks_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_forks_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.1058823529, "max_line_length": 264, "alphanum_fraction": 0.7021242356, "num_tokens": 2236, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539553, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7325538872976808}}
{"text": "% AReviewofTopology.tex\n% Fund Science! & Help Ernest finish his Physics Research! : quantum super-A-polynomials - a thesis by Ernest Yeung\n%                                               \n% http://igg.me/at/ernestyalumni2014                                                                             \n%                                                              \n% Facebook     : ernestyalumni  \n% github       : ernestyalumni                                                                     \n% gmail        : ernestyalumni                                                                     \n% google       : ernestyalumni                                                                                   \n% linkedin     : ernestyalumni                                                                             \n% tumblr       : ernestyalumni                                                               \n% twitter      : ernestyalumni                                                             \n% youtube      : ernestyalumni                                                                \n% indiegogo    : ernestyalumni                                                                        \n%\n% Ernest Yeung was supported by Mr. and Mrs. C.W. Yeung, Prof. Robert A. Rosenstone, Michael Drown, Arvid Kingl, Mr. and Mrs. Valerie Cheng, and the Foundation for Polish Sciences, Warsaw University.                  \n\n\\section*{Review of Topology}\n\n\\subsection*{Topological Spaces}\n\nLet $X$ set \\\\\ntopology on $X = $ collection $\\tau = \\lbrace U | U \\subseteq X \\rbrace$, $U$ called open subsets s.t.\n\\begin{enumerate}\n\\item[(i)] $X, \\emptyset$ open \n\\item[(ii)] $\\bigcup_{\\alpha} U_{\\alpha}$ is open, $\\forall \\, U_{\\alpha}$ open subset\n\\item[(iii)] $\\bigcap_{i=1}^n U_i$ is open\n\\end{enumerate}\n\n$(X,\\tau)$ topological space\n\n\n\\textbf{Example A.5. (Metric Spaces)}\nmetric space $=$ set $M$ with metric $d: M \\times M \\to \\mathbb{R}$ s.t. $\\forall \\, x, y, z \\in M$\n\\begin{enumerate}\n\\item[(i)] \\textsc{Positivity} $d(x,y) \\geq 0$, $d(x,y) =0$ iff $x=y$ \n\\item[(ii)] \\textsc{Symmetry} $d(x,y) =d(y,x)$\n\\item[(iii)] \\textsc{Triangle inequality} $d(x,z) \\leq d(x,y) + d(y,z)$\n\\end{enumerate}\n\nif $M$ metric space, $x\\in M$, $r>0$ \\\\\n\\phantom{\\quad } \\textbf{open ball of radius $r$ around $x$ } \n\\[\nB_r(x) = \\{ y \\in M | d(x,y) < r \\}\n\\]\n\\phantom{\\quad \\quad } \\textbf{closed ball of radius $r$ }\n\\[\n\\underline{B}_r(x) = \\{ y \\in M | d(x,y) \\leq r \\}\n\\]\n\\textbf{metric topology on $M$ } defined by declaring $S \\subseteq M$ open iff $\\forall \\, x \\in S$, $\\exists \\, r >0$ s.t. $B_r(x) \\subseteq S$\n\n", "meta": {"hexsha": "9bee1dea6f460c83c8345b9dd6cc8c04ad77ab30", "size": 2608, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LeeJM/AReviewofTopology.tex", "max_stars_repo_name": "wacfeldwang333/mathphysics", "max_stars_repo_head_hexsha": "59eb794dfa46e2b80e43df0440bb8ec3c472d973", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2017-01-10T14:24:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T11:19:23.000Z", "max_issues_repo_path": "LeeJM/AReviewofTopology.tex", "max_issues_repo_name": "wacfeldwang333/mathphysics", "max_issues_repo_head_hexsha": "59eb794dfa46e2b80e43df0440bb8ec3c472d973", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-09-29T09:29:53.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-12T03:12:29.000Z", "max_forks_repo_path": "LeeJM/AReviewofTopology.tex", "max_forks_repo_name": "wacfeldwang333/mathphysics", "max_forks_repo_head_hexsha": "59eb794dfa46e2b80e43df0440bb8ec3c472d973", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 25, "max_forks_repo_forks_event_min_datetime": "2018-01-21T05:33:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T20:15:13.000Z", "avg_line_length": 50.1538461538, "max_line_length": 217, "alphanum_fraction": 0.4520705521, "num_tokens": 664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7325538785951734}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{examples}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% ============================================================================================\n\\bgroup\n\\CdbSetup{action=hide}\n\\begin{cadabra}\n   import cdblib\n   checkpoint_file = 'tests/semantic/output/example-10.json'\n   cdblib.create (checkpoint_file)\n   checkpoint = []\n\\end{cadabra}\n\\egroup\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 10 The determinant of the metric}\n\nOur game here is to compute (the leading terms) in $\\det g$ of the metric in RNC form\n\\begin{dgroup*}\n   \\Dmath*{g_{a b}(x) = \\cdb{ex-10.gab.000}+\\cdots}\n\\end{dgroup*}\nFor the sake of simplicity let's assume that we are working in 3-dimensions. The following\nanalysis is easily generalsied to other dimensions (and the final answers for $\\det g$ and\nfriends are unchanged).\n\nDefine $\\eps^{abc}_{ijk}$ by\n\\begin{align}\n   \\eps^{abc}_{ijk} =\n        \\delta^a_i \\delta^b_j \\delta^c_k - \\delta^b_i \\delta^a_j \\delta^c_k\n      + \\delta^c_i \\delta^a_j \\delta^b_k - \\delta^c_i \\delta^b_j \\delta^a_k\n      + \\delta^b_i \\delta^c_j \\delta^a_k - \\delta^a_i \\delta^c_j \\delta^b_k\n\\end{align}\nIt is easy to see that $\\eps^{abc}_{ijk}$ is anti-symmetric in both its upper and lower\nindices. A trivial computation shows that for any $3{}\\times{}3$ square matrix $M_{ab}$,\n\\begin{align}\n   \\eps^{abc}_{123} M_{1a} M_{2b} M_{3c}\n   = \\left(\n          \\delta^a_1 \\delta^b_2 \\delta^c_3 - \\delta^b_1 \\delta^a_2 \\delta^c_3\n        + \\delta^c_1 \\delta^a_2 \\delta^b_3 - \\delta^c_1 \\delta^b_2 \\delta^a_3\n        + \\delta^b_1 \\delta^c_2 \\delta^a_3 - \\delta^a_1 \\delta^c_2 \\delta^b_3\n     \\right)M_{1a} M_{2b} M_{3c}\n   = \\det M\n\\end{align}\nThis can be easily generalised to\n\\begin{align}\n   \\eps^{abc}_{ijk} M_{pa} M_{qb} M_{rc}\n   =\n   \\begin{cases}\n      \\pm \\det M &\\text{when $(ijk)$ and $(pqr)$ are permutations of $(123)$}\\\\\n      0 & \\text{otherwise}\n   \\end{cases}\n\\end{align}\nThe $\\pm$ sign in the above depends on the particular permutations of $(ijk)$ and $(pqr)$. If\nboth permutations are even or both odd then the sign is $+1$ otherwise the sign is $-1$.\nThe same arguments can also be applied to a matrix inverse $N^{-1}$ leading to\n\\begin{align}\n   \\eps^{ijk}_{uvw} N^{pu} N^{qv} M^{rw}\n   =\n   \\begin{cases}\n      \\pm \\det {N^{-1}} &\\text{when $(ijk)$ and $(pqr)$ are permutations of $(123)$}\\\\\n      0 & \\text{otherwise}\n   \\end{cases}\n\\end{align}\nNote that the $\\pm$ in this case will match exactly that for the case of $\\det M$. Thus,\nmultiplying both expressions and summing over all choices for $(ijk)$ and $(pqr)$ leads\nto\n\\begin{align}\n   \\sum_{\\substack{(ijk)\\\\(pqr)}}\\left(\\det N^{-1}\\right) \\det M\n   = \\eps^{ijk}_{uvw} N^{pu} N^{qv} M^{rw} \\eps^{abc}_{ijk} M_{pa} M_{qb} M_{rc}\n\\end{align}\nwhere the sum on the left hand side includes just those $(ijk)$ and $(prq)$ that are\npermutations of $(123)$. There are $3!$ choices for $(ijk)$ and $3!$ choices for\n$(pqr)$ and thus the left hand side is easily reduced to $(3!)^2 \\det M/\\det N$ where\n$\\det N = 1/\\det (N^{-1})$. For the right hand side notice that\n\\begin{align}\n   \\eps^{ijk}_{uvw} \\eps^{abc}_{ijk} = 3! \\eps^{abc}_{uvw}\n\\end{align}\nwhich leads to\n\\begin{align}\n   \\det M = \\frac{1}{3!} \\det N \\eps^{abc}_{uvw} M_{pa} M_{qb} M_{rc} N^{pu} N^{qv} N^{rw}\n\\end{align}\n\nFor our RNC metric we will set $N^{ab} = g^{ab}$ and $M_{ij} = g_{ij}(x)$. Since $g^{ab}$ is\nof the form ${\\rm diag}(-1,1,1,1)$ we have $\\det g = -1$ and thus\n\\begin{align}\n   \\det g(x) = - \\frac{1}{3!} \\eps^{abc}_{ijk}\\, g_{pa}(x)\\, g_{qb}(x)\\, g_{rc}(x)\\, g^{ip} g^{jq} g^{kr}\n\\end{align}\n\nThe $\\eps^{abc}_{ijk}$ can be constructed in Cadabra by applying the \\verb|asym| algorithm\nto the upper indices of $\\delta^a_i \\delta^b_j \\delta^c_k$. Note that \\verb|asym| will\ninclude the $1/3!$ coeffcient as part of its output.\n\nThe following code computes $-\\det g$ rather than $\\det g$.\n\nNote that Calzetta etal. use an opposite sign for $R_{abcd}$ so when comparing the following\nresults against Calzetta do take note of this flipped sign in $R_{abcd}$.\n\n\\clearpage\n\n% ============================================================================================\n\\section*{The determinant of the metric}\n\n\\begin{cadabra}\n   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u#}::Indices(position=independent).\n\n   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u#}::Integer(1..3).\n\n   \\nabla{#}::Derivative.\n\n   d{#}::KroneckerDelta.\n\n   g^{a b}::Symmetric.\n   g_{a b}::Symmetric.\n\n   R_{a b c d}::RiemannTensor.\n\n   x^{a}::Weight(label=num,value=1).\n\n   def truncate (obj,n):\n\n       ans = Ex(\"0\")  # create a Cadabra object with value zero\n\n       for i in range (0,n+1):\n          foo := @(obj).\n          bah  = Ex(\"num = \" + str(i))\n          distribute  (foo)\n          keep_weight (foo, bah)\n          ans = ans + foo\n\n       return ans\n\n   gab := g_{a b}\n          - (1/3)   x^{c} x^{d} R_{a c b d}\n          - (1/6)   x^{c} x^{d} x^{e} \\nabla_{c}{R_{a d b e}}\n          + (1/180) x^{c} x^{d} x^{e} x^{f} ( 8 g^{g h} R_{a c d g} R_{b e f h}\n                                             -9 \\nabla_{c d}{R_{a e b f}} ).          # cdb (ex-10.gab.000,gab)\n\n   iab := g^{a b}\n          + (1/3)  x^{c} x^{d} g^{a e} g^{b f} R_{c e d f}\n          + (1/6)  x^{c} x^{d} x^{e} g^{a f} g^{b g} \\nabla_{c}{R_{d f e g}}\n          + (1/60) x^{c} x^{d} x^{e} x^{f} g^{a g} g^{b h}\n                                 ( 4 g^{i j} R_{c g d i} R_{e h f j}\n                                  +3 \\nabla_{c d}{R_{e g f h}} ).                     # cdb(ex-10.iab.000,iab)\n\n   distribute (gab)\n   distribute (iab)\n\n   gxab := gx_{a b} -> @(gab).\n\n   eps := d^{a}_{i} d^{b}_{j} d^{c}_{k}.   # cdb (ex-10.eps.001,eps) # includes a factor of 1/3!\n   asym (eps,$^{a},^{b},^{c}$)             # cdb (ex-10.eps.002,eps)\n\n   # compute negative detg rather than det g, note 1/3! included in eps\n   Ndetg := @(eps) gx_{p a} gx_{q b} gx_{r c} g^{i p} g^{j q} g^{k r}.   # cdb (ex-10.Ndetg.001,Ndetg)\n\n   substitute       (Ndetg,gxab)                                         # cdb (ex-10.Ndetg.002,Ndetg)\n   distribute       (Ndetg)                                              # cdb (ex-10.Ndetg.003,Ndetg)\n   Ndetg = truncate (Ndetg,4)                                            # cdb (ex-10.Ndetg.004,Ndetg)\n   substitute       (Ndetg,$g^{a b} g_{b c} -> d^{a}_{c}$,repeat=True)   # cdb (ex-10.Ndetg.005,Ndetg)\n   eliminate_kronecker (Ndetg)                                           # cdb (ex-10.Ndetg.006,Ndetg)\n   sort_product     (Ndetg)                                              # cdb (ex-10.Ndetg.007,Ndetg)\n   rename_dummies   (Ndetg)                                              # cdb (ex-10.Ndetg.008,Ndetg)\n   canonicalise     (Ndetg)                                              # cdb (ex-10.Ndetg.009,Ndetg)\n\n   # introduce the Ricci tensor\n\n   substitute (Ndetg,$R_{a b c d} g^{a c}               -> R_{b d}$,repeat=True)               # cdb (ex-10.Ndetg.101,Ndetg)\n   substitute (Ndetg,$\\nabla_{a}{R_{b c d e}} g^{b d}   -> \\nabla_{a}{R_{c e}}$,repeat=True)   # cdb (ex-10.Ndetg.102,Ndetg)\n   substitute (Ndetg,$\\nabla_{a b}{R_{c d e f}} g^{c e} -> \\nabla_{a b}{R_{d f}}$,repeat=True) # cdb (ex-10.Ndetg.103,Ndetg)\n\n   # the following was based on sqrt-Ndetg.tex\n\n   sqrtNdetg := 1/2 + (1/2) @(Ndetg)\n               - (1/8) (1/9) R_{a b} R_{c d} x^{a} x^{b} x^{c} x^{d}\n               - (1/4) (1/18) R_{a b} \\nabla_{c}{R_{d e}} x^{a} x^{b} x^{c} x^{d} x^{e}.\n                                                                         # cdb (ex-10.sqrtNdetg.001,sqrtNdetg)\n\n   sort_product   (sqrtNdetg)                                            # cdb (ex-10.sqrtNdetg.002,sqrtNdetg)\n   rename_dummies (sqrtNdetg)                                            # cdb (ex-10.sqrtNdetg.003,sqrtNdetg)\n   canonicalise   (sqrtNdetg)                                            # cdb (ex-10.sqrtNdetg.004,sqrtNdetg)\n\n   logNdetg := -1 + @(Ndetg)\n              - (1/2) (1/9) R_{a b} R_{c d} x^{a} x^{b} x^{c} x^{d}\n              - (1/18) R_{a b} \\nabla_{c}{R_{d e}} x^{a} x^{b} x^{c} x^{d} x^{e}.\n                                                                         # cdb (ex-10.logNdetg.001,logNdetg)\n\n   sort_product   (logNdetg)                                             # cdb (ex-10.logNdetg.002,logNdetg)\n   rename_dummies (logNdetg)                                             # cdb (ex-10.logNdetg.003,logNdetg)\n   canonicalise   (logNdetg)                                             # cdb (ex-10.logNdetg.004,logNdetg)\n\n   # =================================================================================================\n   # the remaining code is just for pretty printing\n\n   def product_sort (obj):\n       substitute (obj,$ x^{a}                            -> A000^{a}               $)\n       substitute (obj,$ g^{a b}                          -> A001^{a b}             $)\n       substitute (obj,$ \\nabla_{c}{R_{a b}}              -> A004_{a b c}           $)\n       substitute (obj,$ \\nabla_{c d}{R_{a b}}            -> A005_{a b c d}         $)\n       substitute (obj,$ \\nabla_{c d e}{R_{a b}}          -> A006_{a b c d e}       $)\n       substitute (obj,$ \\nabla_{c d e f}{R_{a b}}        -> A007_{a b c d e f}     $)\n       substitute (obj,$ \\nabla_{e}{R_{a b c d}}          -> A008_{a b c d e}       $)\n       substitute (obj,$ \\nabla_{e f}{R_{a b c d}}        -> A009_{a b c d e f}     $)\n       substitute (obj,$ \\nabla_{e f g}{R_{a b c d}}      -> A010_{a b c d e f g}   $)\n       substitute (obj,$ \\nabla_{e f g h}{R_{a b c d}}    -> A011_{a b c d e f g h} $)\n       substitute (obj,$ R_{a b}                          -> A002_{a b}             $)\n       substitute (obj,$ R_{a b c d}                      -> A003_{a b c d}         $)\n       sort_product   (obj)\n       rename_dummies (obj)\n       substitute (obj,$ A000^{a}                 -> x^{a}                          $)\n       substitute (obj,$ A001^{a b}               -> g^{a b}                        $)\n       substitute (obj,$ A002_{a b}               -> R_{a b}                        $)\n       substitute (obj,$ A003_{a b c d}           -> R_{a b c d}                    $)\n       substitute (obj,$ A004_{a b c}             -> \\nabla_{c}{R_{a b}}            $)\n       substitute (obj,$ A005_{a b c d}           -> \\nabla_{c d}{R_{a b}}          $)\n       substitute (obj,$ A006_{a b c d e}         -> \\nabla_{c d e}{R_{a b}}        $)\n       substitute (obj,$ A007_{a b c d e f}       -> \\nabla_{c d e f}{R_{a b}}      $)\n       substitute (obj,$ A008_{a b c d e}         -> \\nabla_{e}{R_{a b c d}}        $)\n       substitute (obj,$ A009_{a b c d e f}       -> \\nabla_{e f}{R_{a b c d}}      $)\n       substitute (obj,$ A010_{a b c d e f g}     -> \\nabla_{e f g}{R_{a b c d}}    $)\n       substitute (obj,$ A011_{a b c d e f g h}   -> \\nabla_{e f g h}{R_{a b c d}}  $)\n\n   def get_term (obj,n):\n\n       x^{a}::Weight(label=xnum).\n\n       foo := @(obj).\n       bah  = Ex(\"xnum = \" + str(n))\n       keep_weight (foo,bah)\n\n       return foo\n\n   def reformat (obj,scale):\n       foo  = Ex(str(scale))\n       bah := @(foo) @(obj).\n       distribute     (bah)\n       product_sort   (bah)\n       rename_dummies (bah)\n       canonicalise   (bah)\n       sort_sum       (bah)\n       factor_out     (bah,$x^{a?}$)\n       ans := @(bah) / @(foo).\n       return ans\n\n   def rescale (obj,scale):\n       foo  = Ex(str(scale))\n       bah := @(foo) @(obj).\n       distribute  (bah)\n       factor_out  (bah,$x^{a?}$)\n       return bah\n\n   # ---------------------------------------------------------------\n   # reformat Ndetg\n\n   Rterm0 = get_term (Ndetg,0)       # cdb (ex-10.Rterm0.701,Rterm0)\n   Rterm1 = get_term (Ndetg,1)       # cdb (ex-10.Rterm1.701,Rterm1)\n   Rterm2 = get_term (Ndetg,2)       # cdb (ex-10.Rterm2.701,Rterm2)\n   Rterm3 = get_term (Ndetg,3)       # cdb (ex-10.Rterm3.701,Rterm3)\n   Rterm4 = get_term (Ndetg,4)       # cdb (ex-10.Rterm4.701,Rterm4)\n\n   Rterm0 = reformat (Rterm0,  1)    # cdb (ex-10.Rterm0.702,Rterm0)\n   Rterm1 = reformat (Rterm1,  1)    # cdb (ex-10.Rterm1.702,Rterm1)\n   Rterm2 = reformat (Rterm2,  3)    # cdb (ex-10.Rterm2.702,Rterm2)\n   Rterm3 = reformat (Rterm3,  6)    # cdb (ex-10.Rterm3.702,Rterm3)\n   Rterm4 = reformat (Rterm4,180)    # cdb (ex-10.Rterm4.702,Rterm4)\n\n   Ndetg := @(Rterm0) + @(Rterm1) + @(Rterm2) + @(Rterm3) + @(Rterm4).  # cdb (ex-10.Ndetg.701,Ndetg)\n\n   # ---------------------------------------------------------------\n   # reformat sqrtNdetg\n\n   Rterm0 = get_term (sqrtNdetg,0)   # cdb (ex-10.Rterm0.801,Rterm0)\n   Rterm1 = get_term (sqrtNdetg,1)   # cdb (ex-10.Rterm1.801,Rterm1)\n   Rterm2 = get_term (sqrtNdetg,2)   # cdb (ex-10.Rterm2.801,Rterm2)\n   Rterm3 = get_term (sqrtNdetg,3)   # cdb (ex-10.Rterm3.801,Rterm3)\n   Rterm4 = get_term (sqrtNdetg,4)   # cdb (ex-10.Rterm4.801,Rterm4)\n\n   Rterm0 = reformat (Rterm0,  1)    # cdb (ex-10.Rterm0.802,Rterm0)\n   Rterm1 = reformat (Rterm1,  1)    # cdb (ex-10.Rterm1.802,Rterm1)\n   Rterm2 = reformat (Rterm2,  6)    # cdb (ex-10.Rterm2.802,Rterm2)\n   Rterm3 = reformat (Rterm3, 12)    # cdb (ex-10.Rterm3.802,Rterm3)\n   Rterm4 = reformat (Rterm4,360)    # cdb (ex-10.Rterm4.802,Rterm4)\n\n   sqrtNdetg := @(Rterm0) + @(Rterm1) + @(Rterm2) + @(Rterm3) + @(Rterm4).  # cdb (ex-10.sqrtNdetg.801,sqrtNdetg)\n\n   # ---------------------------------------------------------------\n   # reformat logNdetg\n\n   Rterm0 = get_term (logNdetg,0)    # cdb (ex-10.Rterm0.801,Rterm0)\n   Rterm1 = get_term (logNdetg,1)    # cdb (ex-10.Rterm1.801,Rterm1)\n   Rterm2 = get_term (logNdetg,2)    # cdb (ex-10.Rterm2.801,Rterm2)\n   Rterm3 = get_term (logNdetg,3)    # cdb (ex-10.Rterm3.801,Rterm3)\n   Rterm4 = get_term (logNdetg,4)    # cdb (ex-10.Rterm4.801,Rterm4)\n\n   Rterm0 = reformat (Rterm0,  1)    # cdb (ex-10.Rterm0.802,Rterm0)\n   Rterm1 = reformat (Rterm1,  1)    # cdb (ex-10.Rterm1.802,Rterm1)\n   Rterm2 = reformat (Rterm2,  3)    # cdb (ex-10.Rterm2.802,Rterm2)\n   Rterm3 = reformat (Rterm3,  6)    # cdb (ex-10.Rterm3.802,Rterm3)\n   Rterm4 = reformat (Rterm4,180)    # cdb (ex-10.Rterm4.802,Rterm4)\n\n   logNdetg := @(Rterm0) + @(Rterm1) + @(Rterm2) + @(Rterm3) + @(Rterm4).  # cdb (ex-10.logNdetg.901,logNdetg)\n\n   checkpoint.append (Ndetg)\n   checkpoint.append (sqrtNdetg)\n   checkpoint.append (logNdetg)\n\n\\end{cadabra}\n\n\\clearpage\n\n% =================================================================================================\n\\section*{The metric determinant in Riemann normal coordinates}\n\n\\def\\Vert{\\vrule height 10pt depth 3pt width 0.5pt}\n\\def\\LVert{\\Vert\\hskip 1.75pt}\n\\def\\RVert{\\hskip 1pt\\Vert}\n\n\\begin{dgroup*}\n   \\Dmath*{-\\det g(x) = \\cdb{ex-10.Ndetg.701}+\\cdots}\n\\end{dgroup*}\n\n% =================================================================================================\n\\section*{The volume element in RNC}\n\nIf $-\\det g(x)$ is non-negative then we also have\n%\n\\begin{dgroup*}\n   \\Dmath*{\\sqrt{-\\det g(x)} = \\cdb{ex-10.sqrtNdetg.801}+\\cdots}\n\\end{dgroup*}\n\n% =================================================================================================\n\\section*{The log of -detg in RNC}\n%\n\\begin{dgroup*}\n   \\Dmath*{\\log\\left(-\\det g(x)\\right) = \\cdb{ex-10.logNdetg.901}+\\cdots}\n\\end{dgroup*}\n\nApart from the signs, this matches exactly the expression given by Calzetta etal. (eq. A14)\n\n\\clearpage\n\n% ============================================================================================\n% export to json format\n\n\\bgroup\n\\CdbSetup{action=hide}\n\\begin{cadabra}\n   for i in range( len(checkpoint) ):\n      cdblib.put ('check{:03d}'.format(i),checkpoint[i],checkpoint_file)\n\\end{cadabra}\n\\egroup\n\n\\end{document}\n", "meta": {"hexsha": "3f1942c3c5ed5655bd3bc6a57251778801df9ef7", "size": 15682, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/example-10.tex", "max_stars_repo_name": "leo-brewin/cadabra-tutorial", "max_stars_repo_head_hexsha": "5b428ae158b5346315ab6c975dee9de933e5c3d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2019-12-20T07:49:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T22:55:47.000Z", "max_issues_repo_path": "source/cadabra/example-10.tex", "max_issues_repo_name": "leo-brewin/cadabra-tutorial", "max_issues_repo_head_hexsha": "5b428ae158b5346315ab6c975dee9de933e5c3d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/cadabra/example-10.tex", "max_forks_repo_name": "leo-brewin/cadabra-tutorial", "max_forks_repo_head_hexsha": "5b428ae158b5346315ab6c975dee9de933e5c3d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-22T13:52:19.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-22T13:52:19.000Z", "avg_line_length": 43.6824512535, "max_line_length": 124, "alphanum_fraction": 0.5023593929, "num_tokens": 5488, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7324811873385321}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: The Integral Test}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises relating to the integral test.\n\\end{abstract}\n\\maketitle\n\n\n\n\\begin{exercise}\nThe function\n\\[ \\frac{\\cos \\pi x}{x} \\]\nis decreasing for $x \\geq \\answer{N/A}$ (if the function is not ultimately decreasing, enter N/A). The integral test \\wordChoice{\\choice{does}\\choice[correct]{does not}} apply to the series\n\\[ \\sum_{n=1}^\\infty \\frac{\\cos \\pi n}{n}. \\]\nThe series \\wordChoice{\\choice{converges}\\choice{diverges}\\choice[correct]{can't be determined using this test}}.\n\\end{exercise}\n\n\\begin{exercise}\nThe function \\[ \\frac{\\ln x}{x} \\]\nis decreasing for $x \\geq \\answer{e}$ (if the function is not ultimately decreasing, enter N/A). The integral test \\wordChoice{\\choice[correct]{does}\\choice{does not}} apply to the series\n\\[ \\sum_{n=3}^\\infty \\frac{\\ln n}{n}. \\]\nWe have\n\\[ \\int_3^\\infty \\frac{\\ln x}{x} dx = \\answer{\\infty}, \\]\nso the series \\wordChoice{\\choice{converges}\\choice[correct]{diverges}\\choice{can't be determined using this test}}.\n\\end{exercise}\n\n\\begin{exercise}\nThe function \\[ \\frac{1}{x^2+1} \\]\nis decreasing for $x \\geq \\answer{0}$ (if the function is not ultimately decreasing, enter N/A). The integral test \\wordChoice{\\choice[correct]{does}\\choice{does not}} apply to the series\n\\[ \\sum_{n=1}^\\infty \\frac{1}{n^2+1}. \\]\nWe have that\n\\[ \\int_1^\\infty \\frac{dx}{x^2 + 1} = \\answer{\\frac{\\pi}{4}}, \\]\nso the series \\wordChoice{\\choice[correct]{converges}\\choice{diverges}\\choice{can't be determined using this test}}.\n\\end{exercise}\n\n\\begin{exercise}\nThe integral test \n\\wordChoice{\\choice[correct]{does}\\choice{does not}} apply to the series\n\\[ \\sum_{n=2}^\\infty \\frac{1}{n (\\ln n)^2}. \\]\nThe series \\wordChoice{\\choice[correct]{converges}\\choice{diverges}\\choice{can't be determined using this test}}.\n\\begin{hint}\nMake a substitution $u = \\ln x$.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nThe integral test \n\\wordChoice{\\choice[correct]{does}\\choice{does not}} apply to the series\n\\[ \\sum_{n=2}^\\infty \\frac{1}{n (\\ln n)}. \\]\nThe series \\wordChoice{\\choice{converges}\\choice[correct]{diverges}\\choice{can't be determined using this test}}.\n\\begin{hint}\nMake a substitution $u = \\ln x$.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nThe integral test \n\\wordChoice{\\choice{does}\\choice[correct]{does not}} apply to the series\n\\[ \\sum_{n=2}^\\infty e^{-n^2} \\cos n \\pi . \\]\nThe series \\wordChoice{\\choice{converges}\\choice{diverges}\\choice[correct]{can't be determined using this test}}.\n\\end{exercise}\n\n\\begin{exercise}\nThe integral test \n\\wordChoice{\\choice[correct]{does}\\choice{does not}} apply to the series\n\\[ \\sum_{n=2}^\\infty n^3 e^{-n^2}. \\]\nThe series \\wordChoice{\\choice[correct]{converges}\\choice{diverges}\\choice{can't be determined using this test}}.\n\\begin{hint}\nMake a substitution $u = x^2$ and then integrate by parts.\n\\end{hint}\n\\end{exercise}\n\n\n\\begin{exercise}\nThe function \n\\[ \\frac{x}{(x^2+3)^2} \\]\nis decreasing for $x \\geq \\answer{1}$.\nBy the integral test,  \n\\[ \\int_{\\answer{8}}^\\infty \\frac{x}{(x^2+3)^2} dx \\leq \\sum_{n=8}^\\infty \\frac{n}{(n^2+3)^2} \\leq \\int_{\\answer{7}}^\\infty \\frac{x}{(x^2+3)^2} dx. \\]\nWe can approximate the infinite series by the sum of the first seven terms with what bounds on the error?\n\\[ \\frac{1}{\\answer{134}} + \\sum_{n=1}^7 \\frac{n}{(n^2+3)^2} \\leq \\sum_{n=1}^\\infty \\frac{n}{(n^2+3)^2} \\leq \\frac{1}{\\answer{104}} + \\sum_{n=1}^7 \\frac{n}{(n^2+3)^2}. \\]\n\\begin{hint}\nWrite\n\\[ \\sum_{n=1}^\\infty \\frac{n}{(n^2+3)^2} = \\sum_{n=1}^7 + \\sum_{n=8}^\\infty \\frac{n}{(n^2+3)^2}  \\]\nand then use the bounds we know for the ``tail'' (i.e., the sum over $n \\geq 8$).\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nUsing the integral test, we can determine that the sum of the series\n\\[ \\sum_{n=1}^\\infty \\frac{1}{n^2} \\]\nis \\wordChoice{\\choice{equal to}\\choice{greater than}\\choice[correct]{less than}} $2$.\n\\begin{hint}\nCompare the series to the partial sum of the first three terms. Don't forget to include an estimate of the remainder.\n\\begin{hint}\n\\[ \\sum_{n=1}^\\infty \\frac{1}{n^2} \\leq \\sum_{n=1}^3 \\frac{1}{n^2} + \\int_{3}^\\infty \\frac{dx}{x^2}. \\]\n\\end{hint}\n\\end{hint}\n\\end{exercise}\n\n\\section*{Sample Quiz Questions}\n\n\\begin{question}%%%%%[2019IntegTestErr1]\n\nWhen approximating the sum of the infinite series\n\\[ \\sum_{n=1}^\\infty \\frac{1}{n^3} \\]\nby the sum of the first \\(N\\) terms, how large must \\(N\\) be to ensure that the approximation error is less than \\(1/200\\)? Choose the smallest correct bound among those listed.\n\\begin{multiplechoice}\n\\choice{\\(N > 5\\)}\n\\choice[correct]{\\(N > 10\\)}\n\\choice{\\(N > 20\\)}\n\\choice{\\(N > 400\\)}\n\\choice{\\(N > 8000\\)}\n\\choice{\\(N > 160000\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nBecause the terms \\(n^{-3}\\) are positive and decreasing, we know that the partial sums are always less than or equal to the sum of the series. By the Integral Test, we can further say that\n\\[ \\sum_{n=1}^\\infty \\frac{1}{n^3} - \\sum_{n=1}^N \\frac{1}{n^3} \\leq \\int_N^\\infty \\frac{1}{x^3} dx  = \\frac{1}{2N^2}.\\]\nTo be certain that the error is less than \\(1/200\\), we set \\((2 N^2)^{-1} < 1/200\\), which gives \\(N > 10\\).\n\\end{feedback}\n\n\\end{question}\n\n\\end{document}\n", "meta": {"hexsha": "ffcf75db02ce4851cc7b43c08176cf61077e9dce", "size": 5222, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "series/22integralpractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "series/22integralpractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "series/22integralpractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.480620155, "max_line_length": 189, "alphanum_fraction": 0.6792416699, "num_tokens": 1822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.8539127455162774, "lm_q1q2_score": 0.7324591299675037}}
{"text": "\n{\\bf\\large Names:}\n\n\n\\subsection*{Scale Dependent Parametrizations}\n\nConsider a steady flow of 10 cm s$^{-1}$ over a flat bottom in a turbulent ocean.  We will neglect impacts of stratification and rotation.  In a large scale ocean model we would parametrize the drag of the bottom using an nonlinear, quadratic drag law of the form:\n\n\\begin{equation}\n\\tau = C_D \\rho u^2\n\\label{eq:drag}\n\\end{equation}\nwhere $\\tau$ is bottom drag or stress, $\\rho \\approx 1000$ kg m$^{-3}$ is the density of water, $u$ is the flow speed above the bottom and $C_D$ is the drag coefficient.  The drag coefficient is a bit of a fudge factor and depends on your problem.  Here we will use 0.01.  In SalishSeaCast I tune it to get the tides accurate.\n\n\\begin{question}\nWhat is the drag? \\\\\n$\\tau = $\\\\[24pt]\n\\end{question}\n\nLet's look a little closer, below is a grid diagram\n(Figure~\\ref{plt:grid}).  Given the flow of 10 cm s$^{^-1}$ at the\nlowest grid cell $u_1$, the drag on that velocity is the value given above.\n\n\\begin{figure}[h]\n\\resizebox{3in}{!}{\\includegraphics{grid.png}}\n\\caption{\\protect\\it{Typical grid near the bottom. $w$ is the vertical\n    velocity, the black line is the bottom. No flow through the bottom\n    implies $w_0 = 0$.} Lowest horizontal velocity grid point $u_1$ is\n  $dz/2$ from the bottom.}\n\\label{plt:grid}\n\\end{figure}\n\n\\clearpage\n\nIn the ``real world'' we would expect a log layer profile (Figure~\\ref{plt:loglayer}):\n\n\\begin{equation}\nu = \\max \\left[ \\frac {u_*}{\\kappa} \\log \\left( \\frac z z_* \\right), U \\right]\n\\end{equation}\nwhere $u_* = (\\tau/\\rho)^{1/2}$ is the friction velocity, $\\kappa =\n0.41$ is von Karman's constant, $z$ is height above the bottom, $z_*$\nis the roughness length, here 20 cm, and $U$ is the free stream (above boundary layer) velocity.\n\n\\begin{figure}[ht]\n\\resizebox{5.5in}{!}{\\includegraphics{loglayer.png}}\n\\caption{\\protect\\it{Log layer velocity profile.}}\n\\label{plt:loglayer}\n\\end{figure}\n\nTo match the log-layer to the bottom stress parametrization above we\nfind that \n\\begin{equation}\nu_* = \\frac U {C_D^{1/2}}\n\\end{equation}\n\nLet's assume that the model velocity at each grid point is exactly the log\nlayer value at the appropriate height above the bottom.  That is, you can\nfind $u_1$ from Figure~\\ref{plt:loglayer} by reading off the graph the\nvalue at $dz/2$.\n\nFor a large scale model a  typical bottom layer box thickness, $dz =\n30$~m.  In coastal models we usually have better resolution.  What\nhappens if we use the parametrization (\\ref{eq:drag}) but have better resolution?\n\n\\clearpage\n\n\\begin{question}\nWhat is the drag using the quadratic drag law  (\\ref{eq:drag}) for the\nflow shown in Figure~\\ref{plt:loglayer} for bottom grid resolutions of\n$dz = $10, 5 and 2 m?\\\\\nWith $dz=10$m , $\\tau  = $\\\\[24pt]\nWith $dz=5$m , $\\tau  = $\\\\[24pt]\nWith $dz=2$m , $\\tau  = $\\\\[12pt]\n\\end{question}\n\n\\begin{question}\nShould the drag change in this way? Why or why not?\n\\end{question}\n\n\\vspace{1in}\n\n\\begin{question}\nNoting that our bottom grid cells are not always the same size, in\nshallower water they are often smaller, how should we parametrize the\nbottom drag?\\\\[24pt]\n\\end{question}", "meta": {"hexsha": "e65d5c93ee8d5c5849011c233114c8fbd8b07fee", "size": 3139, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WS-MEOPAR/worksheet_loglayer.tex", "max_stars_repo_name": "SusanEAllen/uqar-winter-school", "max_stars_repo_head_hexsha": "f46bfdba69216ff6fa8ef178e1740d946f77f8e3", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WS-MEOPAR/worksheet_loglayer.tex", "max_issues_repo_name": "SusanEAllen/uqar-winter-school", "max_issues_repo_head_hexsha": "f46bfdba69216ff6fa8ef178e1740d946f77f8e3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WS-MEOPAR/worksheet_loglayer.tex", "max_forks_repo_name": "SusanEAllen/uqar-winter-school", "max_forks_repo_head_hexsha": "f46bfdba69216ff6fa8ef178e1740d946f77f8e3", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-06T17:52:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-06T17:52:57.000Z", "avg_line_length": 36.5, "max_line_length": 326, "alphanum_fraction": 0.7174259318, "num_tokens": 956, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048444, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7324591288359072}}
{"text": "\n\\subsection{Pruning decision trees}\n\nTraining a decision tree until there is only one entry from the training set will result in overfitting.\n\nWe can use pruning to regularise trees.\n\n\\subsubsection{Pruning}\n\n\\subsubsection{Reduced error pruning}\n\nFrom bottom, replace each node with a leaf of the most popular class. Accept if no reduction in accuracy.\n\n\\subsubsection{Cost complexity pruning}\n\nTake full tree \\(T_0\\)\n\nIteratively find a subtree to replace with a leaf. Cost function is accuracy and number of leaves.\n\nRemove this generating \\(T_{i+1}\\)\n\nWhen we have just the root, choose a single tree using CV.\n\n\\subsubsection{Growing and pruning}\n\nGenerally we would split the data up. Grow the tree with one set and then prune with the other.\n\nWe can split our data up and iterate between growing and pruning.\n\nWhen pruning, for each pair of leaves we test to see if they should be merged.\n\nIf our two sets are \\(A\\) and \\(B\\) we can do:\n\n\\begin{itemize}\n\\item \\(A\\): Grow\n\\item \\(B\\): Prune\n\\item \\(B\\): Grow\n\\item \\(A\\): Prune\n\\end{itemize}\n\nAnd repeat this process.\n\n\\subsubsection{Partial regression trees}\n\nOnce we have built a tree, we keep a single leaf and disard the rest.\n\n", "meta": {"hexsha": "30b4c017b5f0f68b199364415ee2c07c8a132a7b", "size": 1190, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/trees/01-04-treeRegular.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/trees/01-04-treeRegular.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/trees/01-04-treeRegular.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3191489362, "max_line_length": 105, "alphanum_fraction": 0.7529411765, "num_tokens": 292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.732459128541353}}
{"text": "\\section{Vector Space}\n\n\\subsection{Field}\n\n\\begin{definition}\n    For $0$ and $1$ of a field $F$, the smallest $n$ that $\\displaystyle \\sum_{i=1}^n 1 = 0$ is called the \\cindex{characteristic} of $F$. If no such $n$ exists, $F$ is called \\cindex{characteristic zero}.\n    \\qed\n\\end{definition}\n\n\\begin{definition}\n    The field $Z_2$ has characteristic of $2$ which consists of two elements $0$ and $1$:\n    \\begin{itemize}\n        \\item $0 + 0 = 0$\n        \\item $0 + 1 = 1 + 0 = 1$\n        \\item $1 + 1 = 0$\n        \\item $0 \\times 0 = 0$\n        \\item $0 \\times 1 = 1 \\times 0 = 0$\n        \\item $1 \\times 1 = 1$\n    \\end{itemize}\n\\end{definition}\n\n\\subsection{Vector}\n\nAlgebra is concerned with how to manipulate symbolic combinations of object and how to equate one with another.\n\n\\begin{definition}\nA \\cindex{vector space} vector space $V$ over a \\cindex{field} field $F$ has two operation $\\{+,\\times\\}$ with $\\vec{0}$ and $1$. \\qed\n\\end{definition}\n\n\n\n\\begin{definition}\n\tA \\cindex{subspace} is a subset $W$ of vector space $V$ that is closed under $\\{+,\\times\\}$. When we say a subset is a subspace of a vector space, we mean it is a vector space as well.\n\\end{definition}\n\n\\begin{theorem}\n    $\\{0\\}$ is a subspace of all vector space. \n    \\qed\n\\end{theorem}\n\n\\cindex{matrix} is late Latin for \\emph{womb}. The idea is that a matri is a place for holding numbers.\n\n\n\\begin{definition}\n\ta \\cindex{trace} of an $n \\times n$ matrix $M$, denoted $\\text{tr}(M)$, is the sum of diagonal entries:\n\t\\begin{equation}\n\t\t\\text{tr}(M) = \\sum_{i=1}^n M_{ii}\n\t\\end{equation}\n\\end{definition}\n\n\\begin{definition}\n\tA \\cindex{span} of a nonempty subset $S$ of a vector space $V$ is the set consisting of all linear combinations of the vectors in $S$. If $\\text{span}(S) =V$, $S$ \\cindex{generate} (or span) $V$.\n\t\\qed\n\\end{definition}\n\n\\begin{definition}\n    The span of $\\emptyset$ is $\\{0\\}$, not $\\emptyset$.\n\\end{definition}\n\nA span set is useful because it allow one to describe all vectors in terms of a much smaller space.\n\n\\begin{definition}\n\tA subset $S$ of $V$ is \\cindex{linearly dependent} if there exist a finite number of distinct vector $u_1, u_2, \\dots, u_n$ in $S$ and scalars $a_1, a_2, \\dots, a_n$, not all $0$, that:\n\t\\begin{equation}\n\t\t\\sum_{i=1}^n a_i u_i = 0\n\t\\end{equation}\n\t\n\t$S$ is called \\cindex{linearly independent} if it is not linearly dependent. $\\emptyset$ is linearly independent.\n\t\n\t\\qed\n\\end{definition}\n\n\\begin{theorem}\n\tLet $S$ be linearly independent, $v$ is not in $S$. Then $S \\cup {v} $ is linearly dependent if $v \\in \\text{span}(S)$.\n\\end{theorem}\n\n\n\n% basis\n\\subsection{Basis}\n\nBasis tries to represent a infinite vector space using a finite set of vectors. So a complex structure could be understood using simplified structure. A linearly independent generating set has a very useful property that every vector has one and only one representation using basis.\n\n\\begin{definition}\n\tA \\cindex{basis} $\\beta$ for $V$ is a linearly independent subset of $V$ that generate $V$. \n\t\\qed\n\\end{definition}\n\nA vector space is usually infinite. It is desirable to describe this infinite set using a finite subset, which is  the role of basis.\n\n\\begin{theorem}\n    $\\emptyset$ is a basis for zero vector space $\\{0\\}$, so every vector space has a basis.\n\\end{theorem}\n\n\\begin{definition}\n    The \\cindex{standard basis for $F^n$} is $e_1=(1,0,0,\\dots,0)$, $e_2=(0,1,0,\\dots,0)$, $e_n=(0,0,\\dots,1)$.\n\\end{definition}\n\n\\begin{definition}\n    The \\cindex{standard basis for $P_n(F)$} is $\\{1,x,x^2,\\dots,x^n\\}$.\n\\end{definition}\n\n\n\\begin{theorem}\n\t$\\beta$ is a basis of $V$ if $\\forall v \\in V $, $v$ has a unique representation as a linear combination of vectors of $\\beta$.\n\\end{theorem}\n\n\\begin{theorem}\n    A finite spanning set for $V$ can be reduced to a basis.    \n\\end{theorem}\n\n\n\\begin{theorem}[\\cindex{Replacement Theorem}]\n\tLet $V$ be generated by a set $G$ with $n$ vectors. Let $L$ be a linearly independent subset of $V$ with $m$ vectors. Then $m < n$ and $\\exists H \\subset G$ with $n-m$ vectors such that $L \\cup H$ generate $V$.\n\t\\qed\n\\end{theorem}\n\n\\begin{theorem}\n    Let $V$ have a finite basis. Then every basis contains the same number of vectors. This number is an intrinsic property of $V$ and called the \\cindex{dimension} of $V$.    \n\\end{theorem}\n\n\\begin{theorem}\n    Let $V$ be a vector space with dimension $n$:\n    \\begin{itemize}\n        \\item any finite generating set for $V$ contains at least $n$ vectors. If they contains exactly $n$ vectors, they are a basis.\n        \\item any linearly independent subset of $n$ vectors is a basis.\n        \\item every linearly independent subset could be extended to a basis.\n    \\end{itemize}    \n\\end{theorem}\n\n\n\n\n\\begin{definition}[\\cindex{Lagrange Interpolation Formula}]\\label{lagrangeinterpolationformula}\nlet ${c_0, c_1, \\dots, c_n}$ be distinct scalars in field $F$. Define  $n+1$ function $\\set{f_i}$ as:\n\t\\begin{equation}\n\tf_i(x) = \\prod_{k=0, k \\neq i}^n \\frac{x - c_k}{c_i - c_k}\n\\end{equation}\nthen $\\beta = \\set{f_i}$ is a basis of $\\mathbb{P}_n(F)$, where \\cindex{$\\mathbb{P}_n(F)$} is a set of all polynomials over $F$. For $\\forall g \\in \\mathbb{P}_n(F)$, we have\n\t\\begin{equation}\n\t\tg = \\sum_{i=0}^n g(c_i) f_i\n\t\\end{equation}\n\t\n\tTo generate a function $g$ of degree $n$ that passes $n+1$ points $(x_i, y_i)$, first use $\\set{x_i}$ to generate $\\set{f_i}$, then $g = \\sum\\limits_{i=0}^n y_i f_i $.\n\\end{definition}\n\n\n\\begin{proof}\n\tsince $\\beta$ is a basis of $\\mathbb{P}_n(F)$, $\\forall g \\in \\mathbb{P}_n(F)$,\n\t\\begin{equation*}\n\t\tg = \\sum_{i=0}^n b_i f_i\n\t\\end{equation*}\n\tit follows that\n\t\\begin{equation*}\n\t\tg(c_j) = \\sum_{i=0}^n b_i f_i(c_j) = b_j\n\t\\end{equation*}\n\n\tso $g = \\sum\\limits_{i=0}^n g(c_i) f_i$.\n\\end{proof}\n\n\n\\begin{theorem}\nfor any two subspace $W_1$ and $W_2$ of $V$, their dimension has a relation:\n\\begin{equation}\n\t\\text{dim}(W_1 + W_2) = \\text{dim}(W_1) + \\text{dim}(W_2) - \\text{dim}(W_1 \\cap W_2)\n\\end{equation}\n\\end{theorem}\n\n\n\\begin{definition}\n    here are the definition of common terms:\n    \\begin{enumerate}\n        \\item \\cindex{square matrix}: a matrix $M_{i \\times j}$ that $i = j$. It is usually denoted as $M$, not $A$.\n        \\item \\cindex{zero vector}: $\\vec{0}$.\n        \\item \\cindex{transpose}: $\\left(A^\\top\\right)_{ij} = A_{ji}$.\n        \\item \\cindex{symmetric matrix}: $A^\\top = A$.\n        \\item \\cindex{diagonal matrix}: for a $n \\times n$ square matrix $M$ that $M_{ij} = 0$ if $i \\neq j$.\n        \\item \\cindex{upper triangular}: $A_{ij} = 0$ if $i > j$.\n    \\end{enumerate}\n    \\qed    \n\\end{definition}\n\n\n\nThe following text discusses the result of infinite basis.\n\n\\begin{definition}\n    Let $F$ be a family of sets. A member $M$ of $F$ is called \\cindex{maximal} if $M$ is contained in no member of $F$ other than $M$ itself.\n\\end{definition}\n\n\\begin{definition}\n    A collection of set $C$ is called a \\cindex{chain} if for each pair of sets $A$ and $B$ in $C$, either $A \\subseteq B$ or $B \\subseteq A$.\n\\end{definition}\n\n\\begin{theorem}\n    Let $F$ be a family of sets. If for each chain $C \\subseteq F$, there exists a member of $F$ that contains each member of $C$, then $F$ contains a maximal member.    \n\\end{theorem}\n\n\\begin{proof}\n    use axiom of choice. Note that the maximal member may not be in $C$.\n\\end{proof}\n\n\\begin{definition}\n    Let $S$ be a subset of a vector space $V$. A \\cindex{maximal linearly independent subset} of $S$ is a subset $B$ of $S$ that:\n    \\begin{enumerate}\n        \\item $B$ is linearly independent.\n        \\item The only linearly independent subset of $S$ that contains $B$ is $B$.\n    \\end{enumerate}\n\\end{definition}\n\n\\begin{theorem}\n    If $V$ has a basis $\\beta$, $\\beta$ is maximal linearly independent.\n\\end{theorem}\n\\begin{proof}\n    A basis is linearly independent. Because a basis generate $V$, nothing could be added to it and still make it linearly independent.\n\\end{proof}\n\n\n\n\\begin{theorem}\n    Let $V$ be a vector space and $S$ a subset that generate $V$. If $\\beta$ is a maximal linearly independent subset of $S$, then $\\beta$ is a basis $V$.    \n\\end{theorem}\n\\begin{proof}\n    $\\beta$ is linearly independent, so only need to prove that $\\beta$ generate $V$. It is easy because $\\beta$ is maximal in $S$ so nothing from $S$ could be added to it.\n\\end{proof}\n\n\\begin{theorem}\n    Let $S$ be a linearly independent subset of a vector space $V$. There exists a maximal linearly independent subset of $V$ that contains $S$.    \n\\end{theorem}\n\\begin{proof}\n    Let $F$ be a family of all linearly independent subsets of $V$ that contains $S$. For a chain $C$ in $F$, let $U$ be the union of all its member. This $U$ is linearly independent and belongs to $F$, so it is a maximal linearly independent subset of $F$, which is a basis of $F$.\n\\end{proof}\n\n\n\\begin{theorem}\n    Every vector space has a basis.    \n\\end{theorem}\n\n\n\n\n", "meta": {"hexsha": "8584147ddbd4e65d2e9272ae594a299a44c3c6a8", "size": 8855, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/linear_algebra/la.1.vector_space.tex", "max_stars_repo_name": "elvisren/machine-learning-notes", "max_stars_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-07T03:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-04T17:28:22.000Z", "max_issues_repo_path": "src/linear_algebra/la.1.vector_space.tex", "max_issues_repo_name": "elvisren/machine-learning-notes", "max_issues_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/linear_algebra/la.1.vector_space.tex", "max_forks_repo_name": "elvisren/machine-learning-notes", "max_forks_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-01T23:34:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-01T23:34:47.000Z", "avg_line_length": 36.5909090909, "max_line_length": 282, "alphanum_fraction": 0.6695652174, "num_tokens": 2860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7324591162905589}}
{"text": "\\section{\\texorpdfstring{RSA}{RSA}}\n\\vspace{5mm}\n\\large\n\nSetup:\n\\begin{itemize}\n\t\\item $p,q$ big random primes.\n\t\\item $n:= pq$\n\t\\item $\\varphi(n) = (q - 1)(p - 1)$\n\t\\item $(e, \\varphi(n)) = 1$ is an encryption exponent\n\t\\item select decryption exponent $d$ s.t $ed = 1 \\mod(\\varphi(n))$\n\t\\item $(e, n)$ is an enc key, $(d, n)$ is an dec key\n\\end{itemize}\n\nThen we encrypt by calculating $E(X) = x^e \\mod n$ and decrypt $E(y) = y^d \\mod n$.\nAssuming $(x, n) = 1$, last equality by the Euler theorem\n\\[ (x^e)^d \\equiv x^{ed} \\equiv x^{1 + k\\varphi(n)} \\equiv x \\cdot x^{k \\varphi(n)} \\equiv x \\cdot (x^{\\varphi(n)})^k \\equiv x \\]\n\nTherefore, encryption using RSA is invertible.\nRelies on the hardness of factorisation.\n\nRSA is slow, but polynomial. Which leads to hybrid ciphers.\nHowever, we can made some adjustments to improve computations:\n\\begin{itemize}\n\t\\item choose small public exponent (3, 17, $65537 = 2^{16} + 1$)\n\t\\item use CRT for private calculations (compute mod p, mod q and combine using CRT)\n\\end{itemize}\n\n\\begin{properties} RSA\n\\begin{itemize}\n\t\\item Commutative: $D_2(D_1(E_2(E_1(x)))) = x$.\n\t\\item Homomorphic: $E(x_1 x_2) = (x_1 x_2)^e = x_1^e x_2^e = E(x_1) E(x_2)$.\n\\end{itemize}\n\\end{properties}\n\n\\begin{example}\n\tRSA usage for \\textbf{Blind signature}:\n\n\tFirstly, Alice signs some text. Bob want to sign message secretely from Alice. Steps:\n\t\\begin{enumerate}\n\t\t\\item Bob generates $b \\in_R \\Z_n^{\\ast}$, sends $x b^d$ to Alice\n\t\t\\item Alice sends back $(x b^d)^e = x^e b$\n\t\t\\item Bob calculates $x^e b b^{-1} = x^e$ and gets the signature done by Alice.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{definition}\n\tSemantic security - any properties of the plain text cannot be efficienlty computed from cipher text.\n\\end{definition}\n\n\\paragraph{Attacks on RSA}\n\\begin{enumerate}\n\t\\item If $x < \\sqrt[e]{n} \\Rightarrow$ decrypt is e-th root in $\\Z_n$, not that hard.\n\t\\item If anybody knows $\\varphi(n) \\Rightarrow$ he can factorise $n$.\n\t\\item If anybody knows $e,d \\Rightarrow$ he can factorise $n$.\n\t\\item Wiener. If $d < \\sqrt[4]{n} \\Rightarrow$ d could be obtained from $e$ probabilistically.\n\t\\item Meet in the meedle: we know $c = m^e$, $e$ is also public. Try random small $u, v$ to get a collision.\n\t\tThen\n\t\t\\[ u^e \\equiv c v^{-e} \\iff u^e v^e = m^e \\iff (uv)^e \\equiv m^e \\Rightarrow ev = m \\]\n\t\\item similar massages: $m, (m + \\delta)$.\n\t\t\\[ c = m^e \\land c^{\\prime} = (m + \\delta)^e \\iff P(m) = m^e - c \\land P^{\\prime}(m) = (m + \\delta)^e - c^{\\prime} \\]\n\t\t\tTherefore, $m$ is the root of 2 polynomials.\n\t\t\tIf $e$ is small $\\Rightarrow P, P^{\\prime}$ have small degree and $m$ is a root of $gcd(P, P^{\\prime})$.\n\t\t\tWhich is a linear polynomial with high probability.\n\n\t\t\tAlternatively, the attacker can guess $\\delta$.\n\t\\item $p$ and $q$ are close to each other $\\Rightarrow$ easier factorisation of $n$.\n\t\\item single message encrypted with the same e but different mod.\n\t\tEx: $e = 3, n_1, n_2, n_3$ are 3 different residuals\n\t\t\\begin{gather*}\n\t\t\tx^3 = y_1 \\mod n_1\\\\\n\t\t\tx^3 = y_2 \\mod n_2\\\\\n\t\t\tx^3 = y_3 \\mod n_3\n\t\t\\end{gather*}\n\t\tSo, \\[x < \\min(n_1, n_2, n_3) \\Rightarrow x^3 < n_1n_2n_3\\] and $x^3$ can be calculated using CRT. Then, cubic root.\n\n\t\tSolutions: high $e$ or randomize messages.\n\t\\item Not 100\\% Semantic secure, as RSA leaks Jacobi Symbol\n\t\t\\[ \\left(\\frac{x}{p}\\right) \\left(\\frac{x}{q}\\right) \\]\n\t\tWhich is approximately 1 bit of information.\n\n\tHowever, computing parity of $x$ from $E(x)$ is equivalent to full decryption.\n\\end{enumerate}\n\nTo avoid many pitfals of RSA design, we can use Padding scheme.\n\\begin{itemize}\n\t\\item PKCS v1.5: mix message and random bits:\n\n\t\t\\includegraphics[scale=0.4]{pkcs_0.eps}\n\n\t\tThere exists a oracle padding attack, Bleichenbacher.\n\t\\item PKCS v2: add 2 hash functions and XORs (2 Feistel networks)\n\n\t\t\\includegraphics[scale=0.4]{pkcs_1.eps}\n\n\t\tProved to be secure against oracle padding attack.\n\\end{itemize}\n\n\\subsection{Diffie-Hellman key exchange protocol}\nParameters:\\\\\n1) $p$ is a prime\\\\\n2) $\\langle g \\rangle = \\Z_p^{\\ast}$ generator\n\n\\includegraphics[scale=0.4]{dh.eps}\n\nProblems:\n\\begin{itemize}\n\t\\item Man-in-the-middle could alter messages. Solution: sign the result\n\t\\item Attack on parameters: replace $g$ by $g^k$ which generates only a subgroup of $H \\leq \\Z_p^{\\ast}$\n\t\tSolution: check the parameters.\n\t\\item Powering attack: Mallory replaces $g^x$ sent by Bob by $g^{kx}$, similarly for Alice.\n\t\tComputed signature on both sides still matches, however we are in the smaller subgroup again.\n\t\tWhick makes finding the generator much easier.\n\n\t\tSolution: sign the whole communication.\n\t\\item D-H leaks whether $g^{xy}$ is a quadratic residue, $<$ 1 bit leak\n\t\\item Common trick to fix subgroup attacks: choose safe prime $p = 2q - 1$.\n\t\tFrom Lagrange theorem, there are only 2 non trivial subgroups, larger of them is subgroup of quadratic residues. Easy to check.\n\\end{itemize}\n\n\\paragraph{El Gamal cipher based on D-H}\n\\includegraphics[scale=0.4]{dh_1.eps}\n\n\\begin{itemize}\n\t\\item Params: prime $p$, $\\langle g \\rangle = \\Z_p^{\\ast}$ generator\n\t\\item Keys: $k \\in_R \\{ 0, ..., p-2 \\}$ secret.\n\t\t$h = g^k \\mod p$ public\n\t\\item Enc: $t \\in_R \\{ 0, ..., p-2 \\}$\n\t\t\\[ s = h^t = g^{kt} \\mod p, y = xs \\]\n\t\tSend $(g^t, y)$.\n\t\\item Dec: Calculate $(g^t)^k$\n\t\t\\[ x = y \\cdot s^{-1} \\mod p \\]\n\\end{itemize}\n\n\\begin{note}\n\tWe can also use different Algebraic structures with even harder descrete log, e.g. Elliptic curves.\n\\end{note}\n", "meta": {"hexsha": "8e31df15f9de1d53472e5e7344d6a8628365574a", "size": 5426, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/prednasky/10_prednaska.tex", "max_stars_repo_name": "karlov/NDMI100", "max_stars_repo_head_hexsha": "8a2c78790212b79c55083663ef0aaf27ef54d596", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/prednasky/10_prednaska.tex", "max_issues_repo_name": "karlov/NDMI100", "max_issues_repo_head_hexsha": "8a2c78790212b79c55083663ef0aaf27ef54d596", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/prednasky/10_prednaska.tex", "max_forks_repo_name": "karlov/NDMI100", "max_forks_repo_head_hexsha": "8a2c78790212b79c55083663ef0aaf27ef54d596", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.3188405797, "max_line_length": 129, "alphanum_fraction": 0.6752672318, "num_tokens": 1869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.8198933271118222, "lm_q1q2_score": 0.7324184303854563}}
{"text": "% Copyright (c) 2019, Betsalel (Saul) Williamson, Jordan Henderson (the Authors)\n% All rights reserved.\n%\n% Redistribution and use in source and binary forms, with or without\n% modification, are permitted provided that the following conditions are met:\n%     * Redistributions of source code must retain the above copyright\n%       notice, this list of conditions and the following disclaimer.\n%     * Redistributions in binary form must reproduce the above copyright\n%       notice, this list of conditions and the following disclaimer in the\n%       documentation and/or other materials provided with the distribution.\n%     * Neither the names of the Authors nor the\n%       names of its contributors may be used to endorse or promote products\n%       derived from this software without specific prior written permission.\n%\n% THIS SOFTWARE IS PROVIDED BY THE Authors ``AS IS'' AND ANY\n% EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n% DISCLAIMED. IN NO EVENT SHALL THE Authors BE LIABLE FOR ANY\n% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\n% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n\\section{Example Math}\n\n\\subsection{Simple equation with a number}\n\nI can reference this equation \\ref{eqn:sample-dmath} by adding a unique label.\n\n\\begin{dmath}\n\\frac{V_{in}-V_x}{R_1}- \\frac{V_x}{Z_1} + \\frac{V_x - V_o}{Z_1} = 0\n\\label{eqn:sample-dmath}\n\\end{dmath}\n\n\\subsection{A dmath group with no align}\n\\begin{dgroup}[noalign]\n\\begin{dmath}\n\\frac{V_{in}-V_x}{R_1}- \\frac{V_x}{Z_1} + \\frac{V_x - V_o}{Z_1} = 0\n\\end{dmath}\n\\begin{dmath}\n\\frac{V_{in}}{R_1} = -\\frac{V_o}{R2} - \\frac{V_o Z_1}{R_2 Z_1} - \\frac{V_o}{Z_1}- \\frac{Z_1 V_o}{R_1 R_2}\n\\end{dmath}\n\\label{eqn:sample-dgroup-noalign}\n\\end{dgroup}\n\n\\subsection{A dmath group with align on}\n\n\\begin{dgroup}\n\\begin{dmath}\n\\frac{V_{in}-V_x}{R_1}- \\frac{V_x}{Z_1} + \\frac{V_x - V_o}{Z_1} = 0\n\\end{dmath}\n\\begin{dmath}\n\\frac{V_{in}}{R_1} = -\\frac{V_o}{R2} - \\frac{V_o Z_1}{R_2 Z_1} - \\frac{V_o}{Z_1}- \\frac{Z_1 V_o}{R_1 R_2}\n\\end{dmath}\n\\label{eqn:sample-dgroup}\n\\end{dgroup}\n\n\\subsection{In-line Math}\nSample with math included in-line with text along with units. $f_0$ at 620 \\si{\\hertz}.\n\n\\subsection{Symbols}\n\n\\begin{dmath}\n\\frac{4.3 \\si{\\volt}}{1 \\si{\\kilo\\ohm}} = 4.3 \\si{\\milli\\ampere}\n\\end{dmath}\n\n\\subsection{Math With Normal Text}\n\n\\begin{dmath}\n\\text{Average rate of speech} = \\frac{\\text{Words spoken}}{\\text{Number of Seconds}}\n\\label{eqn:sample-math-with-regular-text}\n\\end{dmath}", "meta": {"hexsha": "1c8bc5fc85827a25ea917adf2841a32d9058812e", "size": 2901, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "latex-template/examples/math.tex", "max_stars_repo_name": "betsalel-williamson/source-2-pdf", "max_stars_repo_head_hexsha": "e2087df98814a83f1b0810dd7e809b9c2dc47b98", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-08T11:49:16.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-08T11:49:16.000Z", "max_issues_repo_path": "latex-template/examples/math.tex", "max_issues_repo_name": "betsalel-williamson/source-2-pdf", "max_issues_repo_head_hexsha": "e2087df98814a83f1b0810dd7e809b9c2dc47b98", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "latex-template/examples/math.tex", "max_forks_repo_name": "betsalel-williamson/source-2-pdf", "max_forks_repo_head_hexsha": "e2087df98814a83f1b0810dd7e809b9c2dc47b98", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.2027027027, "max_line_length": 105, "alphanum_fraction": 0.7269906929, "num_tokens": 900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7324184301721942}}
{"text": "\\lesson{5}{Oct 18 2021 Mon (11:31:19)}{Completing the Square}{Unit 2}\n\n\\subsubsection*{Intro to the Discriminant}\n\nThe formula for the \\bf{discriminant} is:\n\n\\begin{align}\n    b^2 - 4ac\n\\end{align}\n\nLet's try a quick example:\n\n\\begin{example}\n    \\begin{align}\n        f(x) &= x^2 + 12x + 26 \\\\\n             &= b^2 - 4ac \\\\\n             &= (12)^2 - 4(1)(26) \\\\\n             &= 144 - 104 \\\\\n             &= 40\n    \\end{align}\n    \n    So, the discriminant isn't a perfect square. This tells us that there will be two irrational numbers.\n\\end{example}\n\n\\subsubsection*{Using Vertex Form: Minimum or Maximum}\n\n\\begin{example}\n    \\begin{align}\n        f(x) = (x + 6)^2 - 10\n    \\end{align}\n    \n    From this equation, we get the vertex of the parabola, which is $(-6, -10)$\n    But, it raises the question. Is it the vertex minimum, or the vertex maximum?\n    \n    To solve this, you must look at the value or the leading coefficient to make this determination.\n    \n    In this case, it would be $a = 1$, which is positive, meaning it goes upward.\n\\end{example}\n\n\\newpage\n", "meta": {"hexsha": "35a818d79c93330070fd36b3f0bf72089076f188", "size": 1071, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-2/lesson-5.tex", "max_stars_repo_name": "SingularisArt/notes", "max_stars_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-08-31T12:45:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T07:29:05.000Z", "max_issues_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-2/lesson-5.tex", "max_issues_repo_name": "SingularisArt/notes", "max_issues_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-2/lesson-5.tex", "max_forks_repo_name": "SingularisArt/notes", "max_forks_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.1219512195, "max_line_length": 105, "alphanum_fraction": 0.6097105509, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.7324184117549144}}
{"text": "\\subsection{Functions of integers}\n\n\\subsubsection{Addition}\n\nThen we can define addition as:\n\n\\((a,b)+(c,d)=(a+c,b+d)\\)\n\nInteger addition can then be defined:\n\n\\(a+b=\\{\\{a_1\\},\\{a_1,a_2\\}\\}+\\{\\{b_1\\},\\{b_1,b_2\\}\\}\\)\n\n\\(a+b=\\{\\{a_1+b_1\\},\\{a_1+b_1,a_2+b_2\\}\\}\\)\n\nOr:\n\n\\(a+b=c\\)\n\n\\(c_1=a_1+b_1\\)\n\n\\(c_2=a_2+b_2\\)\n\n\\subsubsection{Multiplication}\n\nSimilarly, multiplication can be defined as:\n\n\\((a,b).(c,d)=(ac+bd, ad+bc)\\)\n\n\\(ab=c\\)\n\n\\(c_1=a_1b_1+a_2b_2\\)\n\n\\(c_2=a_2b_1+a_1b_2\\)\n\n\\subsubsection{Subtraction}\n\n\\(a-b=c\\)\n\n\\(c_1=a_1+b_2\\)\n\n\\(c_2=a_2+b_1\\)\n\n", "meta": {"hexsha": "798ddbed25e7aa38da2035f9cc27d718229aab02", "size": 553, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/integers/01-03-integersFunctions.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/integers/01-03-integersFunctions.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/integers/01-03-integersFunctions.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 12.8604651163, "max_line_length": 55, "alphanum_fraction": 0.5985533454, "num_tokens": 258, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172688214137, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.7324156239270215}}
{"text": "% This file was converted to LaTeX by Writer2LaTeX ver. 1.6.1\n% see http://writer2latex.sourceforge.net for more info\n\\documentclass[letterpaper]{article}\n\\usepackage[latin1]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amssymb,amsfonts,textcomp}\n\\usepackage[T1]{fontenc}\n\\usepackage[english]{babel}\n\\usepackage{color}\n\\usepackage{array}\n\\usepackage{hhline}\n\\usepackage{hyperref}\n\\hypersetup{colorlinks=true, linkcolor=blue, citecolor=blue, filecolor=blue, urlcolor=blue}\n% Outline numbering\n\\setcounter{secnumdepth}{0}\n% Page layout (geometry)\n\\setlength\\voffset{-1in}\n\\setlength\\hoffset{-1in}\n\\setlength\\topmargin{0.7874in}\n\\setlength\\oddsidemargin{0.7874in}\n\\setlength\\textheight{9.4251995in}\n\\setlength\\textwidth{6.9251995in}\n\\setlength\\footskip{0.0cm}\n\\setlength\\headheight{0cm}\n\\setlength\\headsep{0cm}\n% Footnote rule\n\\setlength{\\skip\\footins}{0.0469in}\n\\renewcommand\\footnoterule{\\vspace*{-0.0071in}\\setlength\\leftskip{0pt}\\setlength\\rightskip{0pt plus 1fil}\\noindent\\textcolor{black}{\\rule{0.25\\columnwidth}{0.0071in}}\\vspace*{0.0398in}}\n% Pages styles\n\\makeatletter\n\\newcommand\\ps@Standard{\n  \\renewcommand\\@oddhead{}\n  \\renewcommand\\@evenhead{}\n  \\renewcommand\\@oddfoot{}\n  \\renewcommand\\@evenfoot{}\n  \\renewcommand\\thepage{\\arabic{page}}\n}\n\\makeatother\n\\pagestyle{Standard}\n\\title{}\n\\author{}\n\\date{2021-06-01}\n\\begin{document}\n{\\centering\\sffamily\\bfseries\nDocument Distance\n\\par}\n\n\\section{Problem Definition}\nDefine a document as a sequence of words (alphanumeric characters), removing all the punctuation and stuff from it all.\nIf we have two such documents, how similar are they (how many words do they have overlapping)?\n\n\\section{Solution}\nSince we don't care about the order of the words in each document  $D$, we can think of each document as a vector, with \n$D(w)$ \\ being the number of occurrences of the word  $w$ \\ in  $D$. We can then define distance as:\n\n\\begin{equation*}\nd'(D_{1,}D_2)=D_1\\cdot D_2=\\sum _WD_1[W]\\cdot D_2[W]\n\\end{equation*}\nThis does work as an okay start, but it does not scale well. This formula really counts the number of words we have in\ncommon, so despite two large documents having a high percentage of words in common, this formula would yield a very\nhigh value, because a small percentage of a large document is still a lot of words. So, we need to clamp this to a\nfixed range using an alternate definition of the dot product,  $D_1\\cdot D_2=|D_1||D_2|\\cos (\\theta )$. Defining:\n\n\\begin{equation*}\nd''(D_{1,}D_2)=\\frac{d'(D_{1,}D_2)}{|D_1|\\cdot |D_2|}\n\\end{equation*}\nWe can see that for  $\\theta \\in [0,\\frac{\\pi } 2]$\n\n $\\theta =\\cos ^{-1}\\left(\\frac{d'(D_{1,}D_2)}{|D_1|\\cdot |D_2|}\\right)$, thus clamping it to a value. If  $\\theta $ is\nzero, both documents are exactly the same, and at the other end of the range, we have fully different documents.\n\n\\clearpage\n\\bigskip\n\n\\section{Algorithm}\n\\texttt{Document Distance:}\n\n{\\ttfamily\n/* }\n\n{\\ttfamily\n\\ * 1. Split each document into words}\n\n{\\ttfamily\n\\ * 2. Count word frequencies (document vectors)}\n\n{\\ttfamily\n\\ * 3. Compute dot product}\n\n{\\ttfamily\n\\ */ }\n\n\n\\bigskip\n\n{\\ttfamily\ndef document\\_distance(doc1, doc2):}\n\n{\\ttfamily\n\\ \\ list1 = get\\_list\\_of\\_words(doc1)}\n\n{\\ttfamily\n\\ \\ list2 = get\\_list\\_of\\_words(doc2)}\n\n\n\\bigskip\n\n{\\ttfamily\n\\ \\ d1 = count\\_frequencies(list1)}\n\n{\\ttfamily\n\\ \\ d2 = count\\_frequencies(list2)}\n\n\n\\bigskip\n\n{\\ttfamily\n\\ \\ sum = \\textrm{dot\\_product(d1, d2)}}\n\n\n\\bigskip\n\n{\\ttfamily\n\\textrm{\\ \\ normalized = sum / (len(list1) * len(list2))}}\n\n\n\\bigskip\n\n{\\ttfamily\n\\textrm{\\ \\ return normalized }}\n\n\n\\bigskip\n\n{\\ttfamily\ndef get\\_list\\_of\\_words(doc):}\n\n{\\ttfamily\n\\ \\ start = 0}\n\n{\\ttfamily\n\\ \\ end = 1}\n\n{\\ttfamily\n\\ \\ A = ord(`A')}\n\n{\\ttfamily\n\\ \\ Z = ord(`Z')}\n\n{\\ttfamily\n\\ \\ a = ord(`a')}\n\n{\\ttfamily\n\\ \\ z = ord(`z')}\n\n{\\ttfamily\n\\ \\ zero = ord(`0')}\n\n{\\ttfamily\n\\ \\ nine = ord(`9')}\n\n{\\ttfamily\n\\ \\ space = ` `}\n\n{\\ttfamily\n\\ \\ word\\_list = []}\n\n\n\\bigskip\n\n{\\ttfamily\n\\ \\ for c in doc:}\n\n{\\ttfamily\n\\ \\ \\ \\ val = ord(c)}\n\n{\\ttfamily\n\\ \\ \\ \\ if A {\\textless} val {\\textless} Z or a {\\textless} val {\\textless} z or zero {\\textless} val {\\textless} nine:}\n\n{\\ttfamily\n\\ \\ \\ \\ \\ \\ end += 1}\n\n{\\ttfamily\n\\ \\ \\ \\ elif val == space:}\n\n{\\ttfamily\n\\ \\ \\ \\ \\ \\ word\\_list.append(doc[start:end])}\n\n{\\ttfamily\n\\ \\ \\ \\ \\ \\ start = end}\n\n{\\ttfamily\n\\ \\ \\ \\ \\ \\ end += 1}\n\n{\\ttfamily\n\\ \\ return word\\_list}\n\n\n\\bigskip\n\n{\\ttfamily\ndef count\\_frequencies(word\\_list):}\n\n{\\ttfamily\n\\ \\ count = \\{\\}}\n\n\n\\bigskip\n\n{\\ttfamily\n\\ \\ for word in word\\_list:}\n\n{\\ttfamily\n\\ \\ \\ \\ if word in count:}\n\n{\\ttfamily\n\\ \\ \\ \\ \\ \\ count[word] += 1}\n\n{\\ttfamily\n\\ \\ \\ \\ else:}\n\n{\\ttfamily\n\\ \\ \\ \\ \\ \\ count[word] = 1}\n\n\n\\bigskip\n\n{\\ttfamily\n\\ \\ return count}\n\n\n\\bigskip\n\ndef dot\\_product(d1, d2):\n\n\\ \\ sum = 0\n\n\\ \\ for key in d1:\n\n\\ \\ \\ \\ if key in d2:\n\n\\ \\ \\ \\ \\ \\ sum += d1[key] * d2[key]\n\n\n\\bigskip\n\n\\ \\ return sum\n\n\n\\bigskip\n\\end{document}\n", "meta": {"hexsha": "7663c700ed872b0bb8050ea329df28fa4060e229", "size": 4857, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6.006_Algorithms/Document20Distance.tex", "max_stars_repo_name": "rahulsanjay18/Notes", "max_stars_repo_head_hexsha": "5306c2ba9584221b1738a1d12a200294413b0558", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6.006_Algorithms/Document20Distance.tex", "max_issues_repo_name": "rahulsanjay18/Notes", "max_issues_repo_head_hexsha": "5306c2ba9584221b1738a1d12a200294413b0558", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6.006_Algorithms/Document20Distance.tex", "max_forks_repo_name": "rahulsanjay18/Notes", "max_forks_repo_head_hexsha": "5306c2ba9584221b1738a1d12a200294413b0558", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.2738095238, "max_line_length": 185, "alphanum_fraction": 0.6773728639, "num_tokens": 1666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7323929426132241}}
{"text": "\\section{Induction}\n\n\\frame{\n{Part 2: Induction}\n\n\\tableofcontents[currentsection,hideallsubsections, firstsection=2, sections={2-4}]\n}\n\n\\subsection{Introductory Examples}\n\n\n\n\\begin{frame}{An initial induction (1/2)}\n  Imagine that I want to color the natural numbers ($\\mathbb{N} \\geq 0$), using the following rules:\\bigskip\n\n  \\begin{itemize}\n    \\item Number $0$ is \\alert{red}\n    \\item Any integer next to a \\alert{red} number is also \\alert{red}\n  \\end{itemize}\\bigskip\n\n  Using these rules, can you imagine how the set $\\mathbb{N}$ looks like?\n\\end{frame}\n\n\\begin{frame}{An initial induction (2/2)}\n\n  \\begin{center}\n    Result: \\alert{0,1,2,3,4,...}\n  \\end{center}\\bigskip\n\n  The \"rule of reds\" gives us a general idea of induction:\n\n  \\begin{itemize}\n  \\item $R(0)$ is True\n  \\item $R(0) \\rightarrow R(1); R(1) \\rightarrow R(2); R(2) \\rightarrow R(3); \\ldots$\n  \\item $R(n) \\rightarrow R(n+1)$ for every $n \\in \\mathbb{N}$\n  \\end{itemize}\\bigskip\n\n  Induction can be used to prove a predicate that depends on some $n \\in \\mathbb{N}$ by modus ponens.\n  \\begin{equation*}\n    \\frac{R(0), R(n)\\rightarrow R(n+1), n\\in\\mathbb{N}}{\\forall n, R(n)}\n  \\end{equation*}\n\\end{frame}\n\n\\begin{frame}{Example of proof by Induction}\n\n  Let's prove that:\n  \\begin{equation*}\n    P(n): 1 + r + r^2 + r^3 + \\ldots + r^n = \\frac{r^{n+1}-1}{r-1}, r \\neq 1, \\forall n \\in \\mathbb{N}\n  \\end{equation*}\\bigskip\n\n  Remember the modus ponens rule for induction:\n  \\begin{equation*}\n    \\frac{P(0), P(n)\\rightarrow P(n+1), n\\in\\mathbb{N}}{\\forall n, P(n)}\n  \\end{equation*}\\bigskip\n\n  To prove the bottom part by induction, we need to prove the top part.\n\n  \\begin{itemize}\n  \\item First Step: Prove $P(0)$\n  \\item Second Step: Prove $P(n) \\rightarrow P(n+1)$\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Example of proof by Induction}\n\n  \\begin{proof}\n    Proof by induction on $n$\n\n    {\\bf First Step:} Prove $P(0)$\n    \\begin{itemize}\n    \\item $P(0)$, left side: $r^0 = 1$\n    \\item $P(0)$, right side: $\\frac{r^{0+1}-1}{r-1} = \\frac{r-1}{r-1} = 1$\n    \\end{itemize}\\medskip\n\n    {\\bf Second Step:} Prove $P(n) \\rightarrow P(n+1)$\n    \\begin{itemize}\n    \\item $P(n+1)$, left side: $1 + r + r^2 + \\ldots + r^n + r^{n+1}$, which is equal to $P(n)+r^{n+1}$\n    \\item Because $P(n)$ is True, $P(n)+r^{n+1} = \\frac{r^{n+1}-1}{r-1} + r^{n+1} = \\frac{(r^{n+1}-1)}{r-1} + \\frac{(r^{n+1}(r-1))}{r-1}$\n    \\item Algebra: $\\frac{(r^{n+1}-1) + (r^{n+1}(r-1))}{r-1} = \\frac{r^{n+1} - 1 + r^{n+2} - r^{n+1}}{r-1} = \\frac{r^{n+2} - 1 + (r^{n+1} - r^{n+1})}{r-1}$\n    \\item $\\frac{r^{n+2} - 1}{r-1} = \\frac{r^{(n+1)+1} - 1}{r-1}$, which is the right side of $P(n+1)$\n    \\end{itemize}\n  \\end{proof}\n\\end{frame}\n\n\\subsection{Proof by Induction}\n\\begin{frame}{Review: Proof Template for Induction}\n\n  {\\larger\n    {\\bf Proof by induction on $n$}\\\\\n    Proof hypothesis: $P(n) = \\ldots$ for all $n \\in \\mathbb{N}. n \\geq 0$\\\\\n\n    \\bigskip\n\n    First we prove $P(0)$.\\\\\n    $\\ldots$ \\emph{(calculate that P(0) is True)}\\\\\n    $\\ldots$\\\\\n\n    \\bigskip\n\n    Second we prove that $\\forall n \\geq 0, P(n) \\rightarrow P(n+1)$\\\\\n    $\\ldots$ \\emph{(calculate P(n+1) using P(n))}\\\\\n    $\\ldots$\\\\\n\n    \\bigskip\n\n    This completes the proof that $P(n)$ for all $n\\in\\mathbb{N}$\\hfill$\\qed$\n  }\n\\end{frame}\n\n\\subsection{The Statue Park}\n\n\\begin{frame}{The Statue Park}{A more complex proof by induction}\n\n  The university is making a new park with the following rules:\n  \\begin{itemize}\n    \\item The park is square, with side $2^n$;\n    \\item In the middle of the park, there is a statue, size $1\\times 1$;\n    \\item Other than that, the park is made of L-shaped tiles, with size $3m^2$;\n  \\end{itemize}\\bigskip\n\n  How can we prove that it is possible to build this park for any $n$?\n\\end{frame}\n\n\\begin{frame}[t]{The Statue Park}{Drawing Proof}\n  Remember the rule of induction:\n  \\begin{itemize}\n    \\item Prove that $P(0)$ is true.\n    \\item Assume that $P(n)$ is true, then prove that $P(n) \\implies P(n+1)$\n  \\end{itemize}\n\\end{frame}\n\n\n\\subsection{BAD induction proof}\n\n\\begin{frame}[t]{BAD Proof by induction: All horses are of the same color}\n\n  $P(n) ::=$ for any \\structure{set} with \\alert{exactly n horses}, all horses have the same color.\\bigskip\n\n  \\begin{itemize}\n\n  \\item<2-> {\\bf Prove P(1)}: For any set with one horse, all horses have the same (one) color.\n\n  \\item<3-> {\\bf Assume P(n) is true:} For any set with $n$ horses, all horses have the same color.\n  \\item<4-> {\\bf Show that $P(n) \\implies P(n+1)$:}\n    \\begin{itemize}\n    \\item <5->Consider the set of n+1 horses: $H = h_1, h_2, \\ldots, h_n, h_{n+1}$\n    \\item <6->Subset A ($h_1, h_2, \\ldots, h_n$): has $n$ horses, so all horses have the same color.\n    \\item <7->Subset B ($h_2, \\ldots, h_n, h_{n+1}$): \\alert{also} has $n$ horses, so all horses have the same color.\n    \\item <8->Horse $h_2$ is in subset $A$ {\\bf and} in subset $B$, so subset $A$ and $B$ have the same color.\n    \\end{itemize}\n  \\item<9-> Since we showed that P(n+1) is true if P(n) is true, then all horses for any group size have the same color.\n  \\end{itemize}\\bigskip\n\n  \\only<10>{\\alert{QUIZ}: What is wrong with this proof?}\n\\end{frame}\n\n\\begin{frame}{What is wrong with the horse proof?}\n\n  The second step, when we show that $P(n) \\implies P(n+1)$ is not valid.\\bigskip\n\n  \\begin{itemize}\n    \\item The implication proof depends on \"$h_i$ belongs to subsets $A$ and $B$\".\n    \\item But is this ALWAYS true?\n    \\begin{itemize}\n      \\item When $n+1 = 2$, The $n+1$ set is $\\{h_1, h_2\\}$, set $A = h_1$, set $B = h_2$;\n      \\item But in this case, {\\bf there is no $h_i$ that is common to $A$ and $B$}!\n    \\end{itemize}\n    \\item So the implication proof is not valid when $P(2)$.\n  \\end{itemize}\\bigskip\n\n  Note that this is the only problem with the proof!\n\\end{frame}\n\n\\subsection{Strong Induction}\n\n\\begin{frame}\n  \\frametitle{Strong Induction}\n\n  {\\larger\n    \\begin{itemize}\n    \\item In regular induction, you assume P(n) to show P(n+1)\n\n      \\bigskip\n\n    \\item In strong induction, you assume P(0), P(1), P(2) \\ldots\n      P(n), and use all of them to show P(n+1)\n    \\end{itemize}\n  }\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Strong Induction Example: Stacking Game}\n  {\\larger\n  \\begin{itemize}\n  \\item Begin with a stack of 10 blocks\n  \\item Divide it in two (a,b): for example, 2 and 8 blocks.\n  \\item You get $a\\times b$ points: 10 points\n  \\item Repeat with the new stacks until all stacks have 1 block.\n  \\end{itemize}\n\n  \\bigskip\n\n  \\alert{What is the best strategy?}\n  \\begin{itemize}\n  \\item Simple strategy: 1+9, 1+8, 1+7, 1+6... \\only<2->{45 points!}\n  \\item CS strategy: 5+5, 2+3 and 2+3, ... \\only<3->{45 points!}\n  \\end{itemize}\n  }\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Proof: All strategies have the same score (Part I)}\n\n  {\\larger\n  Let us prove by strong inductions that all strategies for the stack\n  game with ``n'' blocks have the same score:\n  \\begin{equation*}\n    C(n) = \\frac{n(n-1)}{2}\n  \\end{equation*}\n\n  \\bigskip\n\n  {\\bf Base Cases: 0, 1}\n  \\begin{itemize}\n  \\item When the stack has 0 blocks, I have no moves, so 0 points.\n  \\item When the stack has 1 block, I have no moves, so 0 points.\n  \\end{itemize}\n  \\begin{equation*}\n    C(0) = \\frac{0(0-1)}{2}, C(1) = \\frac{1(1-1)}{2} = 0\n  \\end{equation*}\n  }\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Proof: All strategies have the same score (Part II)}\n\n    {\\bf Inductive Case} $C(n+1)$\\\\\n    By strong induction, we assume that all $C(0)\\ldots C(n)$ are true.\n\n    \\bigskip\n\n    \\begin{enumerate}\n    \\item A stack with $n+1$ blocks can be split into two: $k$ and $n+1-k$\\medskip\n\n    \\item The score is: $C(n+1) = k\\times(n+1-k) + C(k) + C(n+1-k)$\\medskip\n\n    \\item Using the strong inductive assumption: $\\forall m \\leq n, C(m) = \\frac{m(m-1)}{2}$\\medskip\n    \n    \\item Transforming (2): $C(n+1) = \\frac{2k(n+1-k)}{2} + \\frac{k(k-1)}{2} +\n      \\frac{(n+1-k)(n-k)}{2}$\n  \\end{enumerate}\\bigskip\n\n  ... You can finish the calculation from here ;-)\n\\end{frame}\n", "meta": {"hexsha": "c63620123faefc14cefcfb5df77c4b8c2549bc08", "size": 7979, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week02/02_Induction.tex", "max_stars_repo_name": "caranha/MathCS", "max_stars_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-09-13T18:59:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T02:14:56.000Z", "max_issues_repo_path": "week02/02_Induction.tex", "max_issues_repo_name": "caranha/MathCS", "max_issues_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week02/02_Induction.tex", "max_forks_repo_name": "caranha/MathCS", "max_forks_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.2901960784, "max_line_length": 155, "alphanum_fraction": 0.6243890212, "num_tokens": 2949, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683105, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.732392936402829}}
{"text": "\\section{Vectors}\\label{sec:3Dvectors}\n\nA \\dfont{vector}\\index{vector}, denoted $\\vect{v}$, is a quantity consisting of a\nnon-negative magnitude and a direction. We could represent a vector in\ntwo dimensions as $(m,\\theta)$, where $m$ is the magnitude and\n$\\theta$ is the direction, measured as an angle from some agreed upon\ndirection. For example, we might think of the vector $(5,45^\\circ)$\nas representing ``5 km toward the northeast''; that is,\nthis vector might be a \\dfont{displacement vector},\nindicating, say, that your grandfather walked 5 kilometers toward the\nnortheast to school in the snow. On the other hand, the same vector\ncould represent a velocity, indicating that your grandfather walked at\n5 km/hr toward the northeast. What the vector does not indicate is\nwhere this walk occurred: a vector represents a magnitude and a\ndirection, but not a location. Pictorially it is useful to represent a\nvector as an arrow; the direction of the vector, naturally, is the\ndirection in which the arrow points; the magnitude of the vector is\nreflected in the length of the arrow.\n\nIt turns out that many, many quantities behave as vectors, e.g.,\ndisplacement, velocity, acceleration, force. Already we can get some\nidea of their usefulness using displacement vectors. Suppose that your\ngrandfather walked 5 km NE and then 2 km SSE; if the terrain allows,\nand perhaps armed with a compass, how could your grandfather have\nwalked directly to his destination? We can use vectors (and a bit of\ngeometry) to answer this question. We begin by noting that since\nvectors do not include a specification of position, we can ``place''\nthem anywhere that is convenient. So we can picture your grandfather's\njourney as two displacement vectors drawn head to tail:\n\n\\begin{figure}[H]\n$$\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <7truemm,7truemm>\n\\setplotarea x from 0 to 5, y from 0 to 3.6\n\\arrow <4pt> [0.35, 1] from 0 0 to 3.54 3.54\n\\arrow <4pt> [0.35, 1] from 3.54 3.54 to 4.3 1.69\n\\setdashes\n\\arrow <4pt> [0.35, 1] from 0 0 to 4.3 1.69\n\\endpicture}$$\n\\end{figure}\n\nThe displacement vector for the shortcut route is the vector drawn\nwith a dashed line, from the tail of the first to the head of the\nsecond. With a little trigonometry, we can compute that the third\nvector has magnitude approximately 4.62 and direction $21.43^\\circ$,\nso walking 4.62 km in the direction $21.43^\\circ$\nnorth of east (approximately ENE) would get your grandfather to\nschool. This sort of calculation is so common, we dignify it with a\nname: we say that the third vector is the \\dfont{sum}\\index{vector!sum} of the other two vectors. \n\nThere is\nanother common way to picture the sum of two vectors. Put the vectors\ntail to tail and then complete the parallelogram they indicate; the\nsum of the two vectors is the diagonal of the parallelogram:\n\n\\begin{figure}[H]\n$$\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <7truemm,7truemm>\n\\setplotarea x from 0 to 5, y from -2 to 3.6\n\\arrow <4pt> [0.35, 1] from 0 0 to 3.54 3.54\n\\arrow <4pt> [0.35, 1] from 0 0 to 0.77 -1.85\n\\setdashes\n\\arrow <4pt> [0.35, 1] from 0 0 to 4.3 1.69\n\\setdots\n\\plot 3.54 3.54 4.3 1.69 0.77 -1.85 /\n\\endpicture}$$\n\\end{figure}\n\nThis is a more natural representation in some circumstances. For\nexample, if the two original vectors represent forces acting on an\nobject, the sum of the two vectors is the net or effective force on\nthe object, and it is convenient to draw all three with their tails at the\nlocation of the object.\n\nWe also define \\dfont{scalar multiplication}\\index{vector!scalar multiplication} for\nvectors: if $\\vect{v}$ is a vector $(m,\\theta)$ and $a\\ge 0$ is a real\nnumber, the vector $a\\vect{v}$ is $(am,\\theta)$, namely, it points in\nthe same direction but has $a$ times the magnitude. If $a<0$, $a\\vect{v}$ is $(|a|m,\\theta+\\pi)$, with $|a|$ times the magnitude and\npointing in the opposite direction (unless we specify otherwise,\nangles are measured in radians).\n\nNow we can understand subtraction of vectors: \n$\\vect{v}-\\vect{w}=\\vect{v}+(-1)\\vect{w}$:\n\n\\begin{figure}[H]\n$$\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <7truemm,7truemm>\n\\setplotarea x from 0 to 5, y from 0 to 3.6\n\\arrow <4pt> [0.35, 1] from 0 0 to 3.54 3.54\n\\arrow <4pt> [0.35, 1] from 0 0 to 4.3 1.69\n\\arrow <4pt> [0.35, 1] from 4.3 1.69 to 3.54 3.54\n\\put {$\\vect{v}$} [br] <-2pt,2pt> at 1.72 1.72\n\\put {$\\vect{w}$} [tl] <2pt,-2pt> at 2.15 0.84\n\\put {$\\vect{v}-\\vect{w}$} [bl] <2pt,2pt> at 3.92 2.615\n\\setcoordinatesystem units <7truemm,7truemm> point at -6 0\n\\setplotarea x from 0 to 5, y from 0 to 3.6\n\\arrow <4pt> [0.35, 1] from 0 0 to 3.54 3.54\n\\arrow <4pt> [0.35, 1] from 4.3 1.69 to 0 0\n\\arrow <4pt> [0.35, 1] from 4.3 1.69 to 3.54 3.54\n\\put {$\\vect{v}$} [br] <-2pt,2pt> at 1.72 1.72\n\\put {$-\\vect{w}$} [tl] <2pt,-2pt> at 2.15 0.84\n\\put {$\\vect{v}-\\vect{w}$} [bl] <2pt,2pt> at 3.92 2.615\n\\endpicture}$$\n\\end{figure}\n\nNote that as you would expect, $\\vect{w} + (\\vect{v}-\\vect{w}) = \\vect{v}$.\n\nWe can represent a vector in ways other than $(m,\\theta)$, and in fact\n$(m,\\theta)$ is not generally used at all. How else could we describe\na particular vector? Consider again the vector $(5,45^\\circ)$. Let's\ndraw it again, but impose a coordinate system. If we put the tail of\nthe arrow at the origin, the head of the arrow ends up at\nthe point $(5/\\sqrt2,5/\\sqrt2)\\approx(3.54, 3.54)$.\n\n\\begin{figure}[H]\n$$\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <7truemm,7truemm>\n\\setplotarea x from 0 to 5, y from 0 to 4\n\\axis left /\n\\axis bottom /\n\\arrow <4pt> [0.35, 1] from 0 0 to 3.54 3.54\n\\put {$(3.54, 3.54)$} [l] <3pt,0pt> at 3.54 3.54\n\\circulararc 45 degrees from 1 0 center at 0 0\n\\put {$5$} [br] <-2pt,2pt> at 1.72 1.72\n\\put {$45^\\circ$} [bl] <2pt,2pt> at 1 0.3\n\\endpicture}$$\n\\end{figure}\n\nIn this picture the coordinates $(3.54,3.54)$ identify the head of the\narrow, provided we know that the tail of the arrow has been placed at\n$(0,0)$. Then in fact the vector can always be identified as\n$(3.54,3.54)$, no matter where it is placed; we just have to remember\nthat the numbers 3.54 must be interpreted as a \\emph{change} from the\nposition of the tail, not as the actual coordinates of the arrow head;\nto emphasize this we will write $\\langle 3.54,3.54\\rangle$ to mean the\nvector and $(3.54,3.54)$ to mean the point. Then if the vector\n$\\langle 3.54,3.54\\rangle$ is drawn with its tail at $(1,2)$ it looks\nlike this:\n\n\\begin{figure}[H]\n$$\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <7truemm,7truemm>\n\\setplotarea x from 0 to 5, y from 0 to 6\n\\axis left /\n\\axis bottom /\n\\arrow <4pt> [0.35, 1] from 1 2 to 4.54 5.54\n\\setdashes\n\\plot 1 2 4.54 2 4.54 5.54 /\n\\put {$3.54$} [t] <0pt,-3pt> at 2.72 2\n\\put {$3.54$} [l] <3pt,0pt> at 4.54 3.72\n\\put {$(4.54,5.54)$} [l] <3pt,0pt> at 4.54 5.54\n\\endpicture}$$ \n\\end{figure}\n\nConsider again the two part trip: 5 km NE and then 2 km SSE. The\nvector representing the first part of the trip is $\\ds \\langle\n5/\\sqrt2,5/\\sqrt2\\rangle$, and the second part of the trip is\nrepresented by $\\langle 2\\cos(-3\\pi/8),2\\sin(-3\\pi/8)\\rangle\n\\approx\\langle 0.77,-1.85 \\rangle$.  We can represent the sum of these\nwith the usual head to tail picture:\n\n\\begin{figure}[H]\n$$\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <9truemm,9truemm>\n\\setplotarea x from 0 to 5, y from 0 to 5\n\\axis bottom /\n\\axis left /\n\\arrow <4pt> [0.35, 1] from 0 0 to 3.54 3.54\n\\arrow <4pt> [0.35, 1] from 3.54 3.54 to 4.3 1.69\n\\setdashes\n\\arrow <4pt> [0.35, 1] from 0 0 to 4.3 1.69\n\\put {$3.54$} [b] <0pt,3pt> at 1.7 3.54\n\\put {$0.77$} [b] <0pt,3pt> at 3.9 3.54\n\\put {$-1.85$} [l] <3pt,0pt> at 4.3 2.69\n\\put {$(4.3,1.69)$} [l] <3pt,0pt> at 4.3 1.69\n\\plot 0 3.54 4.3 3.54 4.3 1.69 /\n\\endpicture}$$\n\\end{figure}\n\nIt is clear from the picture that the coordinates of the destination\npoint are $\\ds (5/\\sqrt2+2\\cos(-3\\pi/8),5/\\sqrt2+2\\sin(-3\\pi/8))$ or\napproximately $(4.3,1.69)$, so the sum of the two vectors is $\\ds\n\\langle 5/\\sqrt2+2\\cos(-3\\pi/8),5/\\sqrt2+2\\sin(-3\\pi/8)\\rangle \\approx\n\\langle 4.3,1.69\\rangle$. Adding the two vectors is easier in this\nform than in the $(m,\\theta)$ form, provided that we're willing to\nhave the answer in this form as well.\n\nIt is easy to see that scalar multiplication and vector subtraction\nare also easy to compute in this form: $a\\langle v,w\\rangle=\\langle\nav,aw\\rangle$ and $\\ds \\langle v_1,w_1\\rangle - \\langle v_2,w_2\\rangle\n=\\langle v_1-v_2,w_1-w_2\\rangle$. What about the magnitude? The\nmagnitude of the vector $\\langle v,w\\rangle$ is still the length of\nthe corresponding arrow representation; this is the distance from the\norigin to the point $(v,w)$, namely, the distance from the tail to the\nhead of the arrow. Using the familiar distance formula the magnitude of\nthe vector is simply $\\ds \\sqrt{v^2+w^2}$, which we also denote with\nabsolute value bars: $\\ds |\\langle v,w\\rangle|=\\sqrt{v^2+w^2}$.\n\nIn three dimensions, vectors are still quantities consisting of a\nmagnitude and a direction, but of course there are many more possible\ndirections. It's not clear how we might represent the direction\nexplicitly, but the coordinate version of vectors makes just as much\nsense in three dimensions as in two. By $\\langle 1,2,3\\rangle$ we mean\nthe vector whose head is at $(1,2,3)$ if its tail is at the origin. As\nbefore, we can place the vector anywhere we want; if it has its tail\nat $(4,5,6)$ then its head is at $(5,7,9)$. It remains true that\narithmetic is easy to do with vectors in this form.\n\n\\begin{formulabox}[Arithmetic of Vectors]\n\\textbf{Sum} of vectors:\n\\[ \n \\langle v_1,v_2,v_3\\rangle + \\langle w_1,w_2,w_3\\rangle\n  =\\langle v_1+w_1,v_2+w_2,v_3+w_3\\rangle\n\\]\n\n\\textbf{Scalar Multiplication} of vectors:\n\\[\n a\\langle v_1,v_2,v_3\\rangle=\\langle av_1,av_2,av_3\\rangle\n\\]\n\n\\textbf{Subtraction} of vectors:\n\\[\n  \\langle v_1,v_2,v_3\\rangle - \\langle w_1,w_2,w_3\\rangle\n  =\\langle v_1-w_1,v_2-w_2,v_3-w_3\\rangle\n\\]\n\nThe \\textbf{magnitude} of the vector is the distance from the origin to\nthe head of the vector, or \n$\\ds |\\langle v_1,v_2,v_3\\rangle|=\\sqrt{v_1^2+v_2^2+v_3^2}$.\n\\end{formulabox}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <6truemm,6truemm>\n\\setplotarea x from 0 to 5, y from 0 to 6\n\\axis left /\n\\axis bottom /\n\\plot 0 0 -3 -3 /\n\\arrow <4pt> [0.35, 1] from 0 0 to 3 4\n\\setdashes\n\\plot 4 0 3 -1 /\n\\plot 3 -1 -1 -1 /\n\\plot 3 -1 3 4 /\n\\setdots\n\\plot 0 5 4 5 3 4 -1 4 0 5 /\n\\plot -1 4 -1 -1 /\n\\plot 4 5 4 0 /\n\\put {$\\bullet$} at 3 4\n%\\put {$(2,4,5)$} [tr] <-4pt,-4pt> at 3 4\n\\put {$y$} [l] <4pt,0pt> at 5 0\n\\put {$z$} [b] <0pt,4pt> at 0 6\n\\put {$x$} [tr] <-4pt,-4pt> at -3 -3\n\\put {$4$} [b] <0pt,3pt> at 4 0\n\\put {$2$} [br] <-2pt,2pt> at -1 -1\n\\put {$5$} [r] <-3pt,0pt> at 0 5\n\\endpicture}}\n\\caption{The vector $\\langle 2,4,5\\rangle$ with its tail at the origin. \\label{fig:3d vector}}\n\\end{figure}\n\nThree particularly simple vectors turn out to be quite useful: \n$\\vect{i}=\\langle1,0,0\\rangle$, $\\vect{j}=\\langle0,1,0\\rangle$, and \n$\\vect{k}=\\langle0,0,1\\rangle$. These play much the same role for\nvectors that the axes play for points. In particular, notice that\n\\begin{align*}\n  \\langle v_1,v_2,v_3\\rangle &= \\langle v_1,0,0\\rangle + \\langle\n  0,v_2,0\\rangle + \\langle 0,0,v_3\\rangle\t\\\\\n  &=v_1\\langle1,0,0\\rangle + v_2\\langle0,1,0\\rangle + v_3\\langle0,0,1\\rangle\t\\\\\n  &= v_1\\vect{i} + v_2\\vect{j} + v_3\\vect{k}\n\\end{align*}\n\nThus far, we have focused our discussion on vectors which begin at the origin and end at a point. However we will frequently want to produce a vector that points from one point\nto another. That is, if $P$ and $Q$ are points, we seek the vector\n$\\vect{x}$ such that when the tail of $\\vect{x}$ is placed at $P$, its head\nis at $Q$; we refer to this vector as \n$\\ds \\longvect{\\strut PQ}$. \nIf we know the coordinates of $P$ and $Q$,\nthe coordinates of the vector are easy to find.\n\n\\begin{example}{}{}\nSuppose $P=(1,-2,4)$ and $Q=(-2,1,3)$. The vector\n$\\ds \\longvect{\\strut PQ}$ \nis\n$\\langle -2-1,1--2,3-4\\rangle=\\langle -3,3,-1\\rangle$ and\n$\\ds \\longvect{\\strut QP}=\\langle 3,-3,1\\rangle$.\n\\end{example}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:3Dvectors}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nDraw the vector $\\langle 3,-1\\rangle$ with its tail at the\norigin. \n\\end{ex}\n\n\\begin{ex}\nDraw the vector $\\langle 3,-1,2\\rangle$ with its tail at the\norigin. \n\\end{ex}\n\n\\begin{ex}\nLet $\\vect{v}$ be the vector with tail at the origin and head\nat $(1,2)$; let $\\vect{w}$ be the vector with tail at the origin and head\nat $(3,1)$. Draw $\\vect{v}$ and $\\vect{w}$ and a vector $\\vect{u}$ with \ntail at $(1,2)$ and head at $(3,1)$. Draw $\\vect{u}$ with its tail at the origin.\n\\end{ex}\n\n\\begin{ex}\nLet $\\vect{v}$ be the vector with tail at the origin and head\nat $(-1,2)$; let $\\vect{ w}$ be the vector with tail at the origin and head\nat $(3,3)$. Draw $\\vect{v}$ and $\\vect{w}$ and a vector $\\vect{u}$ with \ntail at $(-1,2)$ and head at $(3,3)$. Draw $\\vect{u}$ with its tail at the origin.\n\\end{ex}\n\n\\begin{ex}\nLet $\\vect{v}$ be the vector with tail at the origin and head\nat $(5,2)$; let $\\vect{w}$ be the vector with tail at the origin and head\nat $(1,5)$. Draw $\\vect{v}$ and $\\vect{w}$ and a vector $\\vect{u}$ with \ntail at $(5,2)$ and head at $(1,5)$. Draw $\\vect{u}$ with its tail at the origin.\n\\end{ex}\n\n\\begin{ex}\nFind $|\\vect{v}|$, $\\vect{v}+\\vect{w}$, $\\vect{v}-\\vect{w}$,\n$|\\vect{v}+\\vect{w}|$, $|\\vect{v}-\\vect{w}|$ and $-2\\vect{v}$ for\n$\\vect{v} = \\langle 1,3\\rangle$ and $\\vect{w} = \\langle -1,-5\\rangle$.\n\\begin{sol}\n$\\ds \\sqrt{10}$, $\\langle 0,-2\\rangle$, $\\langle 2,8\\rangle$\n2, $\\ds 2\\sqrt{17}$, $\\langle -2,-6\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $|\\vect{v}|$, $\\vect{v}+\\vect{w}$, $\\vect{v}-\\vect{w}$,\n$|\\vect{v}+\\vect{w}|$, $|\\vect{v}-\\vect{w}|$ and $-2\\vect{v}$ for\n$\\vect{v} = \\langle 1,2,3\\rangle$ and $\\vect{w} = \\langle -1,2,-3\\rangle$.\n\\begin{sol}\n$\\ds \\sqrt{14}$, $\\langle 0,4,0\\rangle$, $\\langle 2,0,6\\rangle$\n4, $\\ds 2\\sqrt{10}$, $\\langle -2,-4,-6\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $|\\vect{v}|$, $\\vect{v}+\\vect{w}$, $\\vect{v}-\\vect{w}$,\n$|\\vect{v}+\\vect{w}|$, $|\\vect{v}-\\vect{w}|$ and $-2\\vect{v}$ for\n$\\vect{v} = \\langle 1,0,1\\rangle$ and $\\vect{w} = \\langle -1,-2,2 \\rangle$.\n\\begin{sol}\n$\\ds \\sqrt{2}$, $\\langle 0,-2,3\\rangle$, $\\langle 2,2,-1\\rangle$\n$\\ds \\sqrt{13}$, $3$, $\\langle -2, 0, -2\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $|\\vect{v}|$, $\\vect{v}+\\vect{w}$, $\\vect{v}-\\vect{w}$,\n$|\\vect{v}+\\vect{w}|$, $|\\vect{v}-\\vect{w}|$ and $-2\\vect{v}$ for\n$\\vect{v} = \\langle 1,-1,1\\rangle$ and $\\vect{w} = \\langle 0,0,3\\rangle$.\n\\begin{sol}\n$\\ds \\sqrt{3}$, $\\langle 1,-1,4\\rangle$, $\\langle 1,-1,-2\\rangle$\n$\\ds 3\\sqrt{2}$, $\\ds \\sqrt{6}$, $\\langle -2, 2, -2\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $|\\vect{v}|$, $\\vect{v}+\\vect{w}$, $\\vect{v}-\\vect{w}$,\n$|\\vect{v}+\\vect{w}|$, $|\\vect{v}-\\vect{w}|$ and $-2\\vect{v}$ for\n$\\vect{v} = \\langle 3,2,1\\rangle$ and $\\vect{w} = \\langle -1,-1,-1\\rangle$.\n\\begin{sol}\n$\\ds \\sqrt{14}$, $\\langle 2,1,0\\rangle$, $\\langle 4,3,2\\rangle$\n$\\ds \\sqrt{5}$, $\\ds \\sqrt{29}$, $\\langle -6,-4, -2\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $P=(4,5,6)$, $Q=(1,2,-5)$. Find \n$\\ds \\longvect{\\strut PQ}$. Find a vector with\nthe same direction as $\\ds \\longvect{\\strut PQ}$\nbut with length 1. Find a vector with\nthe same direction as $\\ds \\longvect{\\strut PQ}$\nbut with length 4.\n\\begin{sol}\n$\\langle -3, -3, -11\\rangle$,\n$\\langle -3/\\sqrt{139},-3/\\sqrt{139},-11/\\sqrt{139}\\rangle$\n$\\langle -12/\\sqrt{139},-12/\\sqrt{139},-44/\\sqrt{139}\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nIf $A, B$, and $C$ are three points, find\n$\\ds \\longvect{\\strut AB}+\n\\longvect{\\strut BC}+\n\\longvect{\\strut CA}$.\n\\begin{sol}\n$\\langle 0,0,0\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nConsider the 12 vectors that have their tails at the center of a\nclock and their respective heads at each of the 12 digits.  What is\nthe sum of these vectors?  What if we remove the vector corresponding\nto 4 o'clock?  What if, instead, all vectors have their\ntails at 12 o'clock, and their heads on the remaining digits?\n\\begin{sol}\n$\\vect{0}$; $\\langle -r\\sqrt3/2,r/2\\rangle$; $\\langle\n0,-12r\\rangle$; where $r$ is the radius of the clock\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $\\vect{a}$ and $\\vect{b}$ be nonzero vectors in two dimensions\nthat are not parallel or anti-parallel.  Show, algebraically, that if\n$\\vect{c}$ is any two dimensional vector, there are scalars $s$ and $t$\nsuch that $\\vect{c}=s\\vect{a}+t\\vect{b}$.\n\\end{ex}\n\n\\begin{ex}\nDoes the statement in the previous exercise hold if the vectors\n$\\vect{a}$, $\\vect{b}$, and $\\vect{c}$ are three dimensional vectors? Explain.\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "6b2e2377a4498bea93189cdfac75fa1e99655d9f", "size": 16702, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "12-three-dimensions/12-2-vectors.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "12-three-dimensions/12-2-vectors.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "12-three-dimensions/12-2-vectors.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.5727482679, "max_line_length": 176, "alphanum_fraction": 0.6787211112, "num_tokens": 6285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.9294403999037784, "lm_q1q2_score": 0.7323350855749942}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{float}\n\\usepackage{amsmath}\n\n\n\\usepackage[hmargin=3cm,vmargin=6.0cm]{geometry}\n%\\topmargin=0cm\n\\topmargin=-2cm\n\\addtolength{\\textheight}{6.5cm}\n\\addtolength{\\textwidth}{2.0cm}\n%\\setlength{\\leftmargin}{-5cm}\n\\setlength{\\oddsidemargin}{0.0cm}\n\\setlength{\\evensidemargin}{0.0cm}\n\n\n\n\\begin{document}\n\n\\section*{Student Information } \n%Write your full name and id number between the colon and newline\n%Put one empty space character after colon and before newline\nFull Name : Zeynep Özalp \\\\\nId Number : 2237691 \\\\\n\n% Write your answers below the section tags\n\\section*{Answer 1}\n\\subsection*{1.1}\n$$a_n=a_{n-1}+n^2$$\n$$a_n=(a_{n-2}+(n-1)^2)+n^2$$\n$$a_n=a_{n-3}+(n-2)^2+(n-1)^2+n^2$$\n$$\\vdots$$\n$$a_n=a_1+\\sum_{i=2}^n i^2=a_1+(\\sum_{i=1}^n i^2)-1=\\sum_{i=1}^n i^2$$\n$$a_n=\\frac{n(n+1)(2n+1)}{6}=\\frac{2n^3+3n^2+n}{6}$$\n\n\\subsection*{1.2}\n$$a_n=2a_{n-1}+2^n$$\n$$a_n=2^2a_{n-2}+2(2^n)$$\n$$a_n=2^3a_{n-3}+3(2^n)$$\n$$\\vdots$$\n$$a_n=2^na_0+n2^n=2^n(n+1)$$\n\\section*{Answer 2}\nFirst, put $n=1$, $f(n)=21$ and $g(n)=21$. So $f(n)\\leq g(n)$ is true for $n=1$. Now assume that $f(n)\\leq g(n)$ is true for $n=k$ where k is an arbitary positive integer. So, for $n=k$,\n$$f(n)\\leq g(n)$$\n$$k^2+15k+5 \\leq 21k^2$$\nWith this assumption, we must show that the rule is true for its successor, n = (k + 1). For $n=k+1$, we have \n$$f(k+1)=k^2+17k+21=f(k)+2k+16$$\n$$g(k+1)=21k^2+42k+21=g(k)+42k+21$$\nSince $f(k)\\leq g(k)$ from our assumption and $2k+16\\leq 42k+21$ for all positive integers,\n$$f(k+1)\\leq g(k+1)$$\nSo, we have shown that if the rule is true for any specific natural number k, then it is also true for its successor, k + 1. With this information, since the rule is true for $n=1$, $f(n) \\leq g(n)$ is true for all n where n is a positive integers. \n\\section*{Answer 3}\n\\subsection*{3.1}\n\\subsubsection*{a)}\nDefine a function $\\theta:N^+\\rightarrow \\Sigma^*$ for simplicity.\n$$\\theta (1)=(.p_1.)$$ \nwhere . operator means the concenation of strings. Recursive steps for theta\n$$\\theta (2)=(.p_2.\\wedge .\\theta(1).)$$\n$$\\theta (3)=(.p_3.\\wedge .\\theta(2).)$$\n$$\\vdots$$\n$$\\theta (i)=(.p_i.\\wedge .\\theta(i-1).)$$\nThen $\\phi (i)$ is the concatenation of $\\theta (i)$ and the string \"$\\rightarrow q$\".\n$$\\phi (i)=\\theta (i).\\rightarrow .q$$\n\\\\\nBase step is\n$$\\psi (1) = (.p_1.\\rightarrow . q.)$$\nRecursive steps for psi\n$$\\psi (2) = (.p_2.\\rightarrow .\\psi (1).)$$\n$$\\psi (3) = (.p_3.\\rightarrow .\\psi (2).)$$\n$$\\vdots$$\n$$\\psi (i) = (.p_i.\\rightarrow .\\psi (i-1).)$$\n\\subsubsection*{b)}\n\\textbf{Base:} \n$$\\phi (1)\\vdash \\psi (1)$$\n$$p_1\\rightarrow q \\vdash p_1\\rightarrow q$$\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{lllllll}\n\t\t1. & & & $p_1\\rightarrow q$ & premise & & \\\\\n\t\t2. & & & $p_1\\rightarrow q$ & copy 1 & & \\\\  \t\t\n\t\\end{tabular}\n\\end{table}\nSo, $\\phi (1)\\vdash \\phi (1)$ for n=1.\\\\\n\\textbf{Inductive Hypothesis:}\nAssume that $$\\phi (k)\\vdash \\psi (k)$$\n\\textbf{Inductive Step:} We need to prove\n$$\\phi (k+1)\\vdash \\psi (k+1)$$\n$$p_{k+1}\\wedge \\phi (k)\\vdash p_{k+1}\\rightarrow \\psi (k)$$\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{lllllll}\n\t\t1. & & & $p_{k+1}\\wedge \\phi (k)$ & premise & & \\\\ \\cline{3-7}\n\t\t2. & \\multicolumn{1}{c|}{} & & $p_{k+1}$ & assumed & & \\multicolumn{1}{c|}{}\\\\ \n\t\t3. & \\multicolumn{1}{c|}{} & & $\\phi (k)$ & $\\wedge e,1$ & & \\multicolumn{1}{c|}{}\\\\ \n\t\t4. & \\multicolumn{1}{c|}{} & & $\\psi (k)$ & inductive hypothesis, 3& & \\multicolumn{1}{c|}{}\\\\ \\cline{3-7}\n\t\t5. &  & & $p_{k+1}\\rightarrow \\psi (k)$ & $\\rightarrow i, 2-4$ & & \\\\\t\t\n\t\\end{tabular}\n\\end{table}\n\n\\subsection*{3.2}\n\\subsubsection*{a)}\nLet $H(x)$ be a function which returns the height of the binary tree $x$. Then, base case is $H(emptyTree)=-1$. Then, we can define $H(x)$ recursively as\n$$H(x)=1+max(H(leftChild), H(rightChild))$$\n\\subsubsection*{b)}\n\\textbf{Definition:} A binary tree is a 223-tree if for each vertex it holds that the number of vetices in the left subtree and the number of vertices in the right subtree differ by at most 2.\\\\\n\nWe can find the number of nodes in a 223-tree by summing the number of vertices in the left subtree, in the right subtree and 1 for the root. \\\\\n\n\\textbf{$f:N\\rightarrow N$}\\\\\nTo find the maximum number, the height of left and right subtree should be equal which is the (h-1) to get the height=h in total.\n$$f(0)=1$$\n$$f(h)=1+f(h-1)+f(h-1)\\ for\\ h>0$$\n\n\\textbf{$g:N\\rightarrow N$}\\\\\nOne of left or right subtree should have height (h-1) and to find the minimum, other must have the minimum height whic is (h-3).\n$$g(0)=1,\\ g(1)=2,\\ g(2)=3$$\n$$g(h)=1+g(h-1)+g(h-3)\\ for\\ h>2$$\n\n\\subsubsection*{c) f}\n\\textbf{Basis Step:} Assume T is a 223-tree of h=1. Then the maximum number of vertices in T must be 3 with one root, one left vertex and one right vertex.\n$$f(1)=1+f(0)+f(0)=1+1+1=3$$\n\\textbf{Inductive hypothesis:} Assume T's left subtree is $T_1$ and right subtree is $T_2$ with the same heights, h-1, to get the maximum number of vertices. Assume that the number of vertices in left and right subtree is\n$$f(h-1)=1+f(h-2)+f(h-2)$$\n\\textbf{Inductive Step:} The maximum number of vertices occurs when vertices except the most bottom ones, which have the height 0, have exactly 2 child. A full binary tree of height h has maximum $2^{h+1}-1$ number of vertices as stated in theorem 2 on page 356 in our textbook. Show that $f(h)=2^{h+1}-1$.\n$$f(h)=1+2f(h-1)$$\n$$f(h)=1+2(1+2f(h-2))$$\n$$f(h)=1+2+2^2(1+2f(h-3))$$\n$$f(h)=1+2+4+2^3(1+2f(h-4))$$\n$$\\vdots$$\n$$f(h)=\\sum^{h-1}_{i=0}2^{i}+2^hf(0)$$\n$$f(h)=2^h-1+2^h=2^{h+1}-1$$\n\\subsubsection*{c) g}\n\\textbf{Basis Step:} Assume T is a 223-tree of h=3. Then the minimum number of vertices in T must be 5 with one root, one left vertex and one right subtree with one root and one right subtree with one root and one right vertex.\n$$g(3)=1+g(2)+g(0)=1+3+1=5$$\n\\textbf{Inductive hypothesis:} Assume T's left subtree is $T_1$ and right subtree is $T_2$ with the heights h-1 and h-3, respectively. Assume that the numbers of vertices in left and right subtree are\n$$g(h-1)=1+g(h-2)+g(h-4)$$\n$$g(h-3)=1+g(h-4)+g(h-6)$$\nTherefore,\n$$g(h-1)+g(h-3)=1+g(h-2)+g(h-4)+1+g(h-4)+g(h-6)$$\n$$g(h-1)+g(h-3)=g(h-2)+2+2(h-4)+g(h-6)$$\n\\textbf{Inductive Step:}\n\\section*{Answer 4}\n\\subsection*{4.1}\n\\subsubsection*{a)}\nThe initial values of a,b are 0 and 1 is added to b each time the nested loop is traversed with a sequence of integers i, j, k such that $1\\leq k\\leq j\\leq i\\leq n$. The number of such sequences of integers is the number of ways to choose 3 integers from \\{1,2,3,...,n\\} with repetition allowed. Therefore, by theorem 2 on page 425 in our textbook, b=C(n+3-1,3)=C(n+2,3) and a=2C(n+2-1,2)=2C(n+1,2) by the same approach (since 2 is added to a in each time, combination is multiplied by 2).\n\\subsubsection*{b)}\nIf a=b then C(n+2,3)=2.C(n+1,2).\n$$\\dfrac{(n+2)!}{3!(n-1)!}=\\dfrac{2(n+1)!}{2!(n-1)!}$$\n$$\\dfrac{(n+2)}{6}=1$$\n$$n=4$$\n\n\\subsection*{4.2}\n\\subsubsection*{a)}\nFor first plate, we need to choose 2 fruits from 10 fruits. For second plate, we need to choose 2 fruits from 8 fruits. For third plate, we need to choose 2 fruits from 6 fruits.\n$$C(10,2).C(8,2).C(6,2)=45.28.15=18900$$\n\\subsubsection*{b)}\nFor first plate, we need to choose 1 fruits from 10 fruits. For second plate, we need to choose 2 fruits from 9 fruits. For third plate, we need to choose 3 fruits from 7 fruits. For fourth plate, we need to chose 4 fruits from 4 fruits.\n$$C(10,1).C(9,2).C(7,3).C(4,4)=10.36.35.1=12600$$\n\\subsubsection*{c)}\nTo compute this, I will use the sum of \\textbf{Stirling numbers of second kind} as it is used in the example 10 on page 430 in our textbook.\n$$\\sum^4_{j=1}S(6,j)=1+31+90+65=187$$\n\\subsubsection*{d)}\nWe need to separate fruits into four groups. So, we need three separation operators. Let us denote the separator as \"-\" and fruits as \"d\". So, we have 6 fruits and 3 separators.\n$$dddddd---$$\nFor instance, two distributions can be like,\n$$dd-d-dd-d$$\n$$dd--ddd-d$$\nwhere the second plate is empty.\nSo, we can find all possible distributions of 6 fruits in 4 plates by putting 6 fruits and 3 separators in order. We can put them order in 9! way but there are repetitions, so we have divide it by the factorials of the number of repeating elements. If we do not have to use all the fruits, there are 7 cases:\\\\\n1. 6 fruits are used.\n$$\\dfrac{9!}{3!6!}=84$$\n2. 5 fruits are used.\n$$\\dfrac{8!}{3!5!}=56$$\n3. 4 fruits are used.\n$$\\dfrac{7!}{3!4!}=35$$\n4. 3 fruits are used.\n$$\\dfrac{6!}{3!3!}=20$$\n5. 2 fruits are used.\n$$\\dfrac{5!}{3!2!}=10$$\n6. 1 fruit is used.\n$$\\dfrac{4!}{3!1!}=4$$\n2. 0 fruit is used.\n$$\\dfrac{3!}{3!0!}=1$$\nSum all the independent cases: 84+56+35+20+10+4+1=210 ways.\n\n\n\\end{document}\n\n​\n\n", "meta": {"hexsha": "1d8b4977faa6622f411aa4c329a8acc951eaa770", "size": 8672, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ceng223/hw3/hw3.tex", "max_stars_repo_name": "zeynepozalp/Coursework", "max_stars_repo_head_hexsha": "d2526229a757a926c311e49c7ffec995ebb9f365", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ceng223/hw3/hw3.tex", "max_issues_repo_name": "zeynepozalp/Coursework", "max_issues_repo_head_hexsha": "d2526229a757a926c311e49c7ffec995ebb9f365", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ceng223/hw3/hw3.tex", "max_forks_repo_name": "zeynepozalp/Coursework", "max_forks_repo_head_hexsha": "d2526229a757a926c311e49c7ffec995ebb9f365", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.4031413613, "max_line_length": 489, "alphanum_fraction": 0.6512915129, "num_tokens": 3419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867681382279, "lm_q2_score": 0.9173026561945815, "lm_q1q2_score": 0.7321788425525649}}
{"text": "% !TEX root = hott_intro.tex\n\n\\section{Connected types and maps}\n\nIn this section we introduce the concept of $k$-connected types and maps. We define $k$-connected types to be types with contractible $k$-truncation, and a $k$-connected map is just a map of which the fibers are $k$-connected. The idea is that a type is $k$-connected if and only if its homotopy groups $\\pi_i(X)$ are trivial for all $i\\leq k$.\n\nOne of the main theorems in this section is a characterization of $k$-connected maps in terms of their action on homotopy groups: A map $f:X\\to Y$ is $k$-connected if and only if it induces isomorphisms\n\\begin{equation*}\n  \\pi_i(f,x):\\pi_i(X,x)\\to\\pi_i(Y,f(x))\n\\end{equation*}\nof homotopy groups, for each $i\\leq k$ and each $x:X$, and a \\emph{surjective} group homomorphism\n\\begin{equation*}\n  \\pi_{k+1}(f,x):\\pi_{k+1}(X,x)\\to\\pi_{k+1}(Y,f(x))\n\\end{equation*}\non the $(k+1)$-st homotopy group, for each $x:X$. If one drops the condition that $f$ induces a surjective group homomorphism on the $(k+1)$-st homotopy group, then the map is only a $k$-equivalence, i.e., a map of which $\\trunc{k}{f}$ is an equivalence. We see from the above characterization that any $k$-connected map is a $k$-equivalence, and also that any $(k+1)$-equivalence is a $k$-connected map. Nevertheless, the difference between the classes of $k$-equivalences and $k$-connected maps is somewhat subtle.\n\nWe will study $k$-equivalences and $k$-connected maps synchronously, because understanding the subtle differences between the results about either of them will increase the understanding of both classes of maps. For instance, we will show that the $k$-connected maps enjoy a dependent elimination property, while the $k$-equivalences only satisfy a non-dependent elimination property. We will see that the $k$-equivalences satisfy the 3-for-2 property, while one of the cases of the 3-for-2 property fails for $k$-connected maps.\n\nThe $k$-connected maps can be characterized as the class of maps that is left orthogonal to the class of $k$-truncated maps, where a map $f:A\\to B$ is said to be left orthogonal to a map $g:X\\to Y$ if the type of diagonal fillers of any commuting square of the form\n\\begin{equation*}\n  \\begin{tikzcd}\n    A \\arrow[d,swap,\"f\"] \\arrow[r] & X \\arrow[d,\"g\"] \\\\\n    B \\arrow[r] \\arrow[ur,densely dotted] & Y\n  \\end{tikzcd}\n\\end{equation*}\nis contractible. Similarly, the class of $k$-equivalences is the class of maps that is left orthogonal to any map between $k$-truncated types. However, this result is not entirely sharp, because there are more maps that the $k$-equivalences are left orthogonal to. It turns out that a map is a $k$-equivalence if and only if it is left orthogonal to any map $g:X\\to Y$ for which the naturality square\n\\begin{equation*}\n  \\begin{tikzcd}[column sep=large]\n    X \\arrow[r,\"g\"] \\arrow[d,swap,\"\\eta\"] & Y \\arrow[d] \\\\\n    \\trunc{k}{X} \\arrow[r,swap,\"\\trunc{k}{g}\"] & \\trunc{k}{Y}\n  \\end{tikzcd}\n\\end{equation*}\nis a pullback square. Such maps are called $k$-\\'etale, and they induce isomorphisms\n\\begin{equation*}\n  \\pi_i(g,x):\\pi_i(X,x)\\to\\pi_i(Y,g(x))\n\\end{equation*}\non homotopy groups for $i>k$.\n\nIn the final part of this section we will use the results about $k$-equivalences to show that the $n$-sphere is $(n-1)$-connected, for each $n:\\N$, and that the join $\\join{A}{B}$ is $(k+l+2)$-connected if $A$ is $k$-connected and $B$ is $l$-connected.\n\n\\subsection{Connected types}\n\n\\begin{defn}\n  A type $X$ is said to be \\define{$k$-connected} if its $k$-truncation $\\trunc{k}{X}$ is contractible. We define\n  \\begin{equation*}\n    \\isconn_k(X)\\defeq\\iscontr\\trunc{k}{X}.\n  \\end{equation*}\n\\end{defn}\n\n\\begin{rmk}\n  Since the $(-2)$-truncation of any type is just $\\unit$, it follows that every type is $(-2)$-connected. Furthermore, since any proposition is contractible as soon as it comes equipped with a term, it follows that any type is $(-1)$-connected as soon as it is inhabited.\n\n    In \\cref{thm:conn-succ} below, we will see that a type $X$ is $0$-connected if and only if it is inhabited and every two points are connected by an unspecified path. In this sense $0$-connected types are also called \\define{path connected}, or just \\define{connected}. Thus, it is immediate that the circle is an example of a connected type.\n\n  Similarly, in the case where $k\\jdeq 0$ the theorem states that a type $X$ is $1$-conneced if and only if it is inhabited and for every $x,y:X$ the identity type $x=y$ is path connected. In other words, a type is \\define{simply connected} if it is $1$-connected! The $2$-sphere is an example of a simply connected type. This fact is shown in \\cref{cor:conn-sphere} below, where we will show more generally that the $n$-sphere is $(n-1)$-connected, for each $n:\\N$.\n\\end{rmk}\n\n\\begin{lem}\n  If a type is $(k+1)$-connected, then it is also $k$-connected.\n\\end{lem}\n\n\\begin{proof}\n  This follows from the fact that $\\trunc{k}{\\trunc{k+1}{X}}\\simeq\\trunc{k}{X}$. Indeed, if $\\trunc{k+1}{X}$ is contractible, then its $k$-truncation is also contractible, so it follows that $\\trunc{k}{X}$ is contractible.\n\\end{proof}\n\nFor the following theorem, recall that a type $X$ is said to be inhabited if it comes equipped with a term $\\trunc{-1}{X}$.\n\n\\begin{thm}\\label{thm:conn-succ}\n  Consider a type $X$. Then the following are equivalent:\n  \\begin{enumerate}\n  \\item The type $X$ is $(k+1)$-connected.\n  \\item The type $X$ is inhabited, and the type $x=y$ is $k$-connected for each $x,y:X$.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  Suppose first that $X$ is $(k+1)$-connected. It is immediate that $X$ is inhabited in this case. Moreover, since we have equivalences\n  \\begin{equation*}\n    (\\eta(x)=\\eta(y))\\simeq \\trunc{k}{x=y}\n  \\end{equation*}\n  for each $x,y:X$, it follows from the assumption that $\\trunc{k+1}{X}$ is contractible that the type $\\trunc{k}{x=y}$ is equivalent to a contractible type. This proves that (i) implies (ii).\n\n  To see that (ii) implies (i), suppose that $X$ is inhabited and that its identity types are $k$-connected. Our goal is to construct a term of type\n  \\begin{equation*}\n    \\iscontr\\trunc{k+1}{X},\n  \\end{equation*}\n  which is a proposition, so we may eliminate the assumption that $X$ is inhabited and assume to have $x:X$. Now we simply take $\\eta(x)$ for the center of contraction of $\\trunc{k+1}{X}$. To construct the contraction, note that by the dependent universal property of $(k+1)$-truncation we have an equivalence\n  \\begin{equation*}\n    \\Big(\\prd{y:\\trunc{k+1}{X}}\\eta(x)=y\\Big)\\simeq\\Big(\\prd{y:X}\\eta(x)=\\eta(y)\\Big).\n  \\end{equation*}\n  Therefore it suffices to construct an identification $\\eta(x)=\\eta(y)$ for every $y:X$. However, this type is contractible, since it is equivalent to the contractible type $\\trunc{k}{x=y}$. This completes the proof of (ii) implies (i).\n\\end{proof}\n\nIn the case where $k\\geq -1$ we can improve \\cref{thm:conn-succ} and characterize a high degree of connectedness entirely in terms of the triviality of homotopy groups. This is what connectedness is all about.\n\n\\begin{thm}\\label{thm:conn-htpy-groups}\n  Consider a type $X$, and suppose that $k\\geq 0$. Then the following are equivalent:\n  \\begin{enumerate}\n  \\item The type $X$ is $k$-connected.\n  \\item The type $X$ is connected, and for every $x:X$ the loop space\n    \\begin{equation*}\n      \\loopspace{X,x}\n    \\end{equation*}\n    is $(k-1)$-connected.\n  \\item For each $i\\leq k$ and each $x:X$, the $i$-th homotopy group $\\pi_i(X,x)$ is trivial.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  If $X$ is $k$-connected for $k\\geq 0$, then it is certainly connected, and $\\loopspace{X,x}$ is $(k-1)$-connected by \\cref{thm:conn-succ}. Thus, the fact that (i) implies (ii) is immediate.\n\n  To see that (ii) implies (i), note that if $X$ is connected and its loop spaces are $(k-1)$-connected, then all its identity types are $(k-1)$-connected, since we have\n  \\begin{align*}\n    \\prd{x,y:X}\\iscontr(\\trunc{k-1}{x=y}) & \\simeq \\prd{x,y:X}\\trunc{-1}{x=y}\\to\\iscontr(\\trunc{k-1}{x=y}) \\\\\n    & \\simeq \\prd{x,y:X}(x=y)\\to\\iscontr(\\trunc{k-1}{x=y}) \\\\\n    & \\simeq \\prd{x:X}\\iscontr(\\trunc{k-1}{x=x}).\n  \\end{align*}\n  In the first step of this calculation we use that $X$ is connected, so $\\trunc{-1}{x=y}$ is contractible; then we use that $\\iscontr(\\trunc{k-1}{x=y})$ is a proposition; and finally we use the universal property of identity types to arrive at our assumption that the loop spaces of $X$ are $(k-1)$-connected. Since we have shown that the identity types are $(k-1)$-connected, it follows by \\cref{thm:conn-succ} that $X$ is $k$-connected, which concludes the proof that (ii) implies (i).\n\n  It is easy to see by induction on $k\\geq 0$ that (ii) holds if and only if (iii) holds, since we have\n  \\begin{equation*}\n    \\pi_{i+1}(X,x)=\\pi_i(\\loopspace{X,x}).\\qedhere\n  \\end{equation*}\n\\end{proof}\n\n\\begin{rmk}\n  If $X$ is assumed to be a pointed type in \\cref{thm:conn-htpy-groups}, then conditions (ii) and (iii) only have to be checked at the base point.\n\\end{rmk}\n\n\\subsection{\\texorpdfstring{$k$}{k}-Equivalences and \\texorpdfstring{$k$}{k}-connected maps}\n\nWe now study two classes of maps that differ only slightly: the $k$-equivalences and the $k$-connected maps. \n\n\\begin{defn}\n  ~\n  \\begin{enumerate}\n  \\item A map $f:X\\to Y$ is said to be \\define{$k$-connected} if its fibers are $k$-connected. We will write\n  \\begin{equation*}\n    \\isconn_k(f)\\defeq\\prd{y:Y}\\isconn_k(\\fib{f}{y}).\n  \\end{equation*}\n  \\item A map $f:X\\to Y$ is said to be a \\define{$k$-equivalence} if\n    \\begin{equation*}\n      \\trunc{k}{f}:\\trunc{k}{X}\\to\\trunc{k}{Y}\n    \\end{equation*}\n    is an equivalence. We will write\n    \\begin{equation*}\n      \\isequiv_k(f)\\defeq\\isequiv(\\trunc{k}{f}).\n    \\end{equation*}\n  \\end{enumerate}\n\\end{defn}\n\n\\begin{eg}\n  Any equivalence is a $k$-connected map, as well as a $k$-equivalence. Moreover, for any $k$-connected type $X$ the map $\\const_\\ttt:X\\to\\unit$ is $k$-connected. It is also immediate that \\emph{any} map between $k$-connected types is a $k$-equivalence.\n\\end{eg}\n\n\\begin{eg}\n  A $(-1)$-connected map is a map $f:X\\to Y$ for which the propositionally truncated fibers\n  \\begin{equation*}\n    \\trunc{-1}{\\fib{f}{y}}\n  \\end{equation*}\n  are contractible. Since propositions are contractible as soon as they are inhabited, we see that a map is $(-1)$-connected if and only if it is surjective.\n\n  A $(-1)$-equivalence, on the other hand, is just a map $f:X\\to Y$ that induces an equivalence $\\trunc{-1}{X}\\simeq\\trunc{-1}{Y}$. The map $\\const_\\btrue : \\unit\\to\\bool$ is an example of such a map, showing that $(-1)$-equivalences don't need to be surjective.\n\n  However, it is the case that every surjective map $f:X\\to Y$ is in fact $(-1)$-equivalence. To see this, we need to show that\n  \\begin{equation*}\n    \\trunc{-1}{Y}\\to\\trunc{-1}{X}.\n  \\end{equation*}\n  Such a map is constructed by the universal property of $(-1)$-truncation. Thus, it suffices to construct a function $Y\\to\\trunc{-1}{X}$. Since we have assumed that $f$ is surjective, we have for every $y:Y$ a term\n  \\begin{equation*}\n    s(y):\\trunc{-1}{\\fib{f}{y}}.\n  \\end{equation*}\n  Thus, we define a function $Y\\to\\trunc{-1}{X}$ by\n  \\begin{equation*}\n    y\\mapsto\\trunc{-1}{\\proj 1}(s(y)).\n  \\end{equation*}\n  This concludes the proof that $f$ is a $(-1)$-equivalence, since we have shown that $\\trunc{-1}{X}\\leftrightarrow\\trunc{-1}{Y}$. \n\\end{eg}\n\n\\begin{rmk}\n  An immediate difference between the classes of $k$-equivalences and $k$-connected maps is that the $k$-connected maps are stable under base change, while the $k$-equivalences are not. By this, we mean that for any pullback square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      E' \\arrow[d,swap,\"{p'}\"] \\arrow[r,\"g\"] & E \\arrow[d,\"p\"] \\\\\n      B' \\arrow[r,swap,\"f\"] & B,\n    \\end{tikzcd}\n  \\end{equation*}\n  if the map $p$ is $k$-connected, then the map $p'$ is also $k$-connected. In such a pullback diagram, the map $p'$ is sometimes called the \\define{base change} of $p$ along $f$. By \\cref{cor:pb_fibequiv} we have an equivalence\n  \\begin{equation*}\n    \\fib{p'}{b'}\\simeq\\fib{p}{f(b')}\n  \\end{equation*}\n  for any $b':B'$, so it is indeed the case that if the fibers of $p$ are $k$-connected, then so are the fibers of $p'$.\n\n  An example showing that the $k$-equivalences are not stable under base change is given by the pullback square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\loopspace{\\sphere{k+1}} \\arrow[r] \\arrow[d] & \\unit \\arrow[d] \\\\\n      \\unit \\arrow[r] & \\sphere{k+1}\n    \\end{tikzcd}\n  \\end{equation*}\n  We will show in \\cref{cor:conn-sphere} that the $(k+1)$-sphere is $k$-connected, so the map $\\unit\\to\\sphere{k+1}$ is a $k$-equivalence. However, its loop space is only $(k-1)$-connected, and indeed we will show in \\cref{far-future} that\n  $\\pi_{k+1}(\\sphere{k+1})=\\Z$ for $k\\geq 0$, showing that $\\loopspace{\\sphere{k+1}}$ is \\emph{not} $k$-connected. Thus, the map $\\loopspace{\\sphere{k+1}}\\to\\unit$ is not a $k$-equivalence.\n\\end{rmk}\n\n\\subsubsection{Elimination properties}\nWe will show that a map $f:X\\to Y$ is a $k$-equivalence if and only if the precomposition function\n\\begin{equation*}\n  \\blank\\circ f : (Y\\to Z)\\to (X\\to Z)\n\\end{equation*}\nis an equivalence for every $k$-type $Z$. On the other hand, we will show that $f$ is $k$-connected if and only if the precomposition function\n\\begin{equation*}\n  \\blank\\circ f : \\Big(\\prd{y:Y}P(y)\\Big)\\to\\Big(\\prd{x:X}P(f(x))\\Big)\n\\end{equation*}\nis an equivalence for every family $P$ of $k$-types over $Y$. In other words, the $k$-connected maps satisfy a \\emph{dependent} unique elimination property, while the $k$-equivalences only satisfy a \\emph{non-dependent} unique elimination property.\n\n\\begin{thm}\\label{thm:k-equiv-precomp}\n  Consider a function $f:X\\to Y$. Then the following are equivalent\n  \\begin{enumerate}\n  \\item The map $f$ is a $k$-equivalence.\n  \\item For every $k$-type $Z$, the precomposition function\n    \\begin{equation*}\n      \\blank\\circ f:(Y\\to Z)\\to(X\\to Z)\n    \\end{equation*}\n    is an equivalence.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{thm}\\label{thm:conn-dup}\n  Let $f:X\\to Y$ be a map. The following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ is $k$-connected.\n  \\item For every family $P$ of $k$-truncated types over $Y$, the precomposition map\n    \\begin{equation*}\n      \\blank\\circ f : \\Big(\\prd{y:Y}P(y)\\Big)\\to\\Big(\\prd{x:X}P(f(x))\\Big)\n    \\end{equation*}\n    is an equivalence.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  Suppose $f$ is $k$-connected and let $P$ be a family of $k$-types over $Y$. Now we may consider the following commuting diagram\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=-10em]\n      \\phantom{\\prd{x:X}{y:Y}{p:f(x)=y}P(y)} & \\prd{y:Y}P(y) \\arrow[r,\"\\blank\\circ f\"] \\arrow[dl] &[10em] \\prd{x:X}P(f(x)) \\\\\n      \\prd{y:Y}\\trunc{k}{\\fib{f}{y}}\\to P(y) \\arrow[dr] & \\phantom{\\prd{y:Y}{x:X}{p:f(x)=y}P(y)} & & \\prd{x:X}{y:Y}{p:f(x)=y}P(y) \\arrow[ul] \\\\\n      & \\prd{y:Y}\\fib{f}{y}\\to P(y) \\arrow[r] & \\prd{y:Y}{x:X}{p:f(x)=y}P(y) \\arrow[ur]\n    \\end{tikzcd}\n  \\end{equation*}\n  which commutes by $\\reflhtpy$. In this diagram, the five maps going around counter clockwise are all equivalences for obvious reasons, so it follows that the top map is an equivalence.\n\n  Now suppose that $f$ satisfies the dependent elimination property stated in (ii). In order to construct a center of contraction of $\\trunc{k}{\\fib{f}{y}}$ for every $y:Y$, we use the dependent elimination property with respect to the family $P$ given by $P(y)\\defeq\\trunc{k}{\\fib{f}{y}}$. \n\\end{proof}\n\n\\begin{cor}\n  For any type $X$, the unit $\\eta:X\\to\\trunc{k}{X}$ of the $k$-truncation is a $k$-connected map. \n\\end{cor}\n\n\\subsubsection{The inclusions}\n\nWe will prove the following implications\n\\begin{equation*}\n  \\begin{tikzcd}[column sep=8em]\n    \\isequiv_{k+1}(f) \\arrow[r,\"\\text{\\cref{prp:is-k-equiv-is-k-conn}}\"] & \\isconn_k(f) \\arrow[r,\"\\text{\\cref{prp:is-k-conn-is-succk-equiv}}\"] & \\isequiv_k(f)\n  \\end{tikzcd}\n\\end{equation*}\nshowing that the class of $k$-connected maps is contained in the class of $k$-equivalences, and that the class of $(k+1)$-equivalences is contained in the class of $k$-connected maps. Neither of these implications reverses.\n\n\\begin{prp}\\label{prp:is-k-equiv-is-k-conn}\n  Any $k$-connected map is a $k$-equivalence.\n\\end{prp}\n\n\\begin{prp}\\label{prp:is-k-conn-is-succk-equiv}\n  Any $(k+1)$-equivalence is $k$-connected.\n\\end{prp}\n\n\\begin{proof}\n  Consider a $(k+1)$-equivalence $f:X\\to Y$. Recall that the map $\\trunc{k+1}{f}$ comes equipped with a homotopy $H:\\trunc{k+1}{f}\\circ\\eta\\htpy\\eta\\circ f$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=large]\n      X \\arrow[r,\"f\"] \\arrow[d,swap,\"\\eta\"] & Y \\arrow[d,\"\\eta\"] \\\\\n      \\trunc{k+1}{X} \\arrow[r,swap,\"\\trunc{k+1}{f}\"] & \\trunc{k+1}{Y}\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. We be using this homotopy, and we will use \\cref{thm:conn-dup} to show that $f$ is $k$-connected. Thus, our goal is to show that\n  \\begin{equation*}\n    \\blank\\circ f:\\Big(\\prd{y:Y}P(y)\\Big)\\to\\Big(\\prd{x:X}P(f(x))\\Big)\n  \\end{equation*}\n  is an equivalence for any family $P$ of $k$-types over $Y$.\n\n  Note that any family $P$ of $k$-types over $Y$ extends to a family $\\tilde{P}$ of $k$-types over $\\trunc{k+1}{Y}$, since any univalent universe of $k$-types that contains $P$ is itself a $(k+1)$-type by \\cref{ex:istrunc_UUtrunc}. The extended family $\\tilde{P}$ of $k$-types over $\\trunc{k+1}{Y}$ comes equipped with a family of equivalences\n  \\begin{equation*}\n    e:\\prd{y:Y}\\tilde{P}(\\eta(y))\\simeq P(y).\n  \\end{equation*}\n  Now consider the commuting diagram\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=-9em]\n      \\phantom{\\prd{x:X}\\tilde{P}(\\trunc{k+1}{f}(\\eta(x)))} & \\phantom{\\prd{x:X}\\tilde{P}(\\trunc{k+1}{f}(\\eta(x)))} & \\prd{y:\\trunc{k+1}{Y}}\\tilde{P}(y) \\arrow[r,\"\\blank\\circ\\trunc{k+1}{f}\"] \\arrow[ddll,swap,\"\\blank\\circ\\eta\"] &[11em] \\prd{x:\\trunc{k+1}{X}}\\tilde{P}(\\trunc{k+1}{f}(x)) \\arrow[dr,\"\\blank\\circ\\eta\" near end] & & \\phantom{\\prd{x:X}\\tilde{P}(\\trunc{k+1}{f}(\\eta(x)))} \\\\\n      & & \\phantom{\\prd{x:\\trunc{k+1}{X}}\\tilde{P}(\\trunc{k+1}{f}(x))} & & \\prd{x:X}\\tilde{P}(\\trunc{k+1}{f}(\\eta(x))) \\arrow[dr,\"{h\\mapsto\\lam{x}\\tr_{\\tilde{P}}(H(x),h(x))}\" near end] \\\\\n      \\prd{y:Y}\\tilde{P}(\\eta(y)) \\arrow[drr,swap,\"{h\\mapsto\\lam{y}e_y(h(y))}\" near start] & & & & & \\prd{x:X}\\tilde{P}(\\eta(f(x))) \\arrow[dll,\"{h\\mapsto\\lam{x}e_{f(x)}(h(x))}\" near start] \\\\\n      & & \\prd{y:Y}P(y) \\arrow[r,swap,\"\\blank\\circ f\"] & \\prd{x:X}P(f(x)).\n    \\end{tikzcd}\n  \\end{equation*}\n  This diagram commutes by the homotopy\n  \\begin{equation*}\n    \\lam{h}\\eqhtpy(\\lam{x}\\ap{e(f(x))}{\\apd{h}{H(x)}}^{-1}).\n  \\end{equation*}\n  In this diagrams all the maps pointing downwards are equivalences for obvious reasons: the two maps $\\blank\\circ\\eta$ are equivalences since $\\tilde{P}$ is a family of $k$-types, and the remaining three maps pointing downwards are all postcomposing with an equivalence. The top map is an equivalence since $\\trunc{k+1}{f}$ is assumed to be an equivalence. Thus we conclude that the bottom map $\\blank\\circ f$ is an equivalence.\n\\end{proof}\n\n\\subsubsection{The 3-for-2 property}\nAn important distinction between the class of $k$-equivalences and the class of $k$-connected maps is that the $k$-equivalences satisfy the 3-for-2 property, while the $k$-connected maps do not.\n\n\\begin{rmk}\\label{rmk:conn-3-for-2}\n  It is not hard to see that the $k$-connected maps don't satisfy the 3-for-2 property. For example, consider the following commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      \\sphere{1} \\arrow[rr,\"d_2\"] \\arrow[dr] & & \\sphere{1} \\arrow[dl] \\\\\n      & \\unit,\n    \\end{tikzcd}\n  \\end{equation*}\n  where $d_2:\\sphere{1}\\to\\sphere{1}$ is the degree $2$ map. Since the circle is a $0$-connected type, it follows that the maps $\\sphere{1}\\to\\unit$ are $0$-connected. However, the fiber of $d_2$ at the base point is equivalent to the booleans, which is a non-contractible set so it is certainly not $0$-connected.\n  \\end{rmk}\n\n\\begin{lem}\n  The $k$-equivalences satisfy the 3-for-2 property, i.e., for any commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      A \\arrow[rr,\"h\"] \\arrow[dr,swap,\"f\"] & & B \\arrow[dl,\"g\"] \\\\\n      & X,\n    \\end{tikzcd}   \n  \\end{equation*}\n  if any two of the three maps are $k$-equivalences, then so is the third.\n\\end{lem}\n\n\\begin{proof}\n  This follows immediately from the fact that equivalences satisfy the 3-for-2 property.\n\\end{proof}\n\n\\begin{prp}\n  Consider a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      A \\arrow[rr,\"h\"] \\arrow[dr,swap,\"f\"] & & B \\arrow[dl,\"g\"] \\\\\n      & X\n    \\end{tikzcd}\n  \\end{equation*}\n  with $H:f\\htpy g\\circ h$. The following three statements hold:\n  \\begin{enumerate}\n  \\item If $f$ and $h$ are $k$-connected, then $g$ is $k$-connected.\n  \\item If $g$ and $h$ are $k$-connected, then $f$ is $k$-connected.\n  \\item If $f$ and $g$ are $k$-connected, then $h$ is a $k$-equivalence.\n  \\end{enumerate}\n\\end{prp}\n\n\\begin{proof}\n  The first two statements combined assert that if $h$ is $k$-connected, then $f$ is $k$-connected if and only if $g$ is $k$-connected. To see that this equivalence holds, consider for any family $P$ of $k$-truncated types over $X$ the commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=10em]\n      \\prd{x:X}P(x) \\arrow[r,\"\\blank\\circ g\"] \\arrow[d,swap,\"\\blank\\circ f\"] & \\prd{b:B}P(g(b)) \\arrow[d,\"\\blank\\circ h\"] \\\\\n      \\prd{a:A}P(f(a)) \\arrow[r,swap,\"{\\lam{s}{a}\\tr_P(H(a),s(a))}\"] & \\prd{a:A}P(g(h(a)))\n    \\end{tikzcd}\n  \\end{equation*}\n  In this square, the bottom map is given by postcomposing with the family of equivalences $\\tr_P(H(a))$ indexed by $a:A$, so it is an equivalence. The map on the right is an equivalence by \\cref{thm:conn-dup}, using the assumption that $h$ is a $k$-connected map. The square commutes by the homotopy\n  \\begin{equation*}\n    \\lam{s}\\eqhtpy\\big(\\lam{a}\\apd{s}{H(a)}\\big).\n  \\end{equation*}\n  Therefore it follows that the precomposition map $\\blank\\circ f$ is an equivalence if and only if the precomposition map $\\blank\\circ g$ is. By \\cref{thm:conn-dup} we conclude that $f$ is connected if and only if $g$ is. This proves statements (i) and (ii).\n\n  Statement (iii) follows from the facts that any $k$-connected map is a $k$-equivalence by \\cref{cor:k-equiv-k-conn} and that the $k$-equivalences satisfy the 3-for-2 property \\cref{lem:3-for-2-k-equiv}.\n\\end{proof}\n\n\\subsubsection{The action on homotopy groups}\n\n\\begin{thm}\n  Consider a map $f:X\\to Y$, and suppose that $k\\geq -1$. The following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ is a $k$-equivalence.\n  \\item The map $f$ is a $(-1)$-equivalence, and for every $0\\leq i\\leq k$ and every $x:X$, the induced group homomorphism\n    \\begin{equation*}\n      \\pi_i(f,x):\\pi_i(X,x)\\to\\pi_i(Y,f(x))\n    \\end{equation*}\n    is an isomorphism.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{defn}\n  A map $f:X\\to Y$ is said to be a \\define{weak equivalence} if it is a $0$-equivalence, and it induces an isomorphism\n  \\begin{equation*}\n    \\pi_i(f,x):\\pi_i(X,x)\\cong\\pi_i(Y,f(x))\n  \\end{equation*}\n  on homotopy groups, for every $x:X$ and every $i\\geq 1$. \n\\end{defn}\n\nThe following corollary is an instance of Whitehead's principle, which asserts that a map between any two spaces is a homotopy equivalence if and only if it is a weak equivalence. Thus, by the following corollary, Whitehead's principle holds for $k$-types.\n\n\\begin{cor}\n  Consider two $k$-types $X$ and $Y$, and consider a map $f:X\\to Y$ between them. Then the following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ is an equivalence.\n  \\item The map $f$ is a weak equivalence.\n  \\end{enumerate}\n\\end{cor}\n\n\\begin{thm}\n  Consider a map $f:X\\to Y$. The following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ is $(k+1)$-connected.\n  \\item The map $f$ is surjective, and for each $x,x':X$ the action on paths\n    \\begin{equation*}\n      \\apfunc{f} : (x=x')\\to (f(x)=f(x'))\n    \\end{equation*}\n    is $k$-connected.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{thm}\n  Consider a surjective map $f:X\\to Y$. The following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ is $k$-connected.\n  \\item The induced maps on loop spaces\n    \\begin{equation*}\n      \\loopspace{f,x}:\\loopspace{X,x}\\to\\loopspace{Y,f(x)}\n    \\end{equation*}\n    is $(k-1)$-connected for every $x:X$.\n  \\item The induced maps on homotopy groups\n    \\begin{equation*}\n      \\pi_i(f,x):\\pi_i(X,x)\\to\\pi_i(Y,f(x))\n    \\end{equation*}\n    are isomorphisms for $0\\leq i\\leq k$, and it is surjective for $i=k+1$. \n  \\end{enumerate}\n\\end{thm}\n\n\\begin{rmk}\n  If $f:X\\to Y$ is a pointed map between connected types, then conditions (ii) and (iii) in \\cref{thm:htpy-groups-conn-map} only have to be checked at the base point.\n\\end{rmk}\n\n\\subsection{Orthogonality}\n\nThe idea of orthogonality is that a map $f:A\\to B$ is left orthogonal to a map $g:X\\to Y$ if for every commuting square of the form\n\\begin{equation*}\n  \\begin{tikzcd}\n    A \\arrow[d,swap,\"f\"] \\arrow[r,\"h\"] & X \\arrow[d,\"g\"] \\\\\n    B \\arrow[r,swap,\"i\"] & Y,\n  \\end{tikzcd}\n\\end{equation*}\nwith $H:(i\\circ f)\\htpy (g\\circ h)$, the type of diagonal fillers is contractible. The type of diagonal fillers is the type of maps $j:B\\to X$ equipped with homotopies\n\\begin{align*}\n  K & : j\\circ f\\htpy h \\\\\n  L & : g\\circ j\\htpy i\n\\end{align*}\nand a homotopy $M$ witnessing that the triangle\n\\begin{equation*}\n  \\begin{tikzcd}[column sep=small]\n    g\\circ j\\circ f \\arrow[rr,\"g\\cdot K\"] \\arrow[dr,swap,\"L\\cdot f\"] & & h\\circ g \\\\\n    & i\\circ f \\arrow[ur,swap,\"H\"]\n  \\end{tikzcd}\n\\end{equation*}\ncommutes. A slicker way to express this condition is to assert that the map\n\\begin{equation*}\n   (B\\to X)\\to \\sm{h:A\\to X}{i:B\\to Y} i\\circ f\\htpy g\\circ h\n\\end{equation*}\ngiven by $j\\mapsto(j\\circ f,g\\circ j,\\reflhtpy)$ is an equivalence. Indeed, the type of triples $(h,i,H)$ in the codomain is the type of commuting squares with respect to which we stated the orthogonality condition. Now we may even recognize the above map as a gap map of a commuting square, and we arrive at our actual definition of orthogonality.\n\n\\begin{defn}\n  A map $f:A\\to B$ is said to be \\define{left orthogonal} to a map $g:X\\to Y$, or equivalently the map $g$ is said to be \\define{right orthogonal} to $f$, if the commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=large]\n      X^B \\arrow[r,\"\\blank\\circ f\"] \\arrow[d,swap,\"g\\circ\\blank\"] & X^A \\arrow[d,\"g\\circ\\blank\"] \\\\\n      Y^B \\arrow[r,swap,\"\\blank\\circ f\"] & Y^A\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pullback square.\n\\end{defn}\n\n\\begin{thm}\nLet $f:A\\to B$ be a map. The following are equivalent:\n\\begin{enumerate}\n\\item The map $f$ is $k$-connected.\n\\item The map $f$ is left orthogonal to every $k$-truncated map.\nis a pullback square.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{thm}\n  Let $f:A\\to B$ be a map. The following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ is a $k$-equivalence.\n  \\item The map $f$ is left orthogonal to every map between $k$-truncated types.\n  \\item The map $f$ is left orthogonal to every map $g:X\\to Y$ for which the naturality square\n    \\begin{equation*}\n      \\begin{tikzcd}\n        X \\arrow[r,\"g\"] \\arrow[d,swap,\"\\eta\"] & Y \\arrow[d,\"\\eta\"] \\\\\n        \\trunc{k}{X} \\arrow[r,swap,\"\\trunc{k}{g}\"] & \\trunc{k}{Y}\n      \\end{tikzcd}\n    \\end{equation*}\n    is a pullback square. Such maps are called \\define{$k$-\\'etale}.\n  \\end{enumerate}\n\\end{thm}\n\n\\subsection{The connectedness of suspensions}\n\nWe will use connected maps to prove the connectedness of suspensions.\n\n\\begin{prp}\\label{prp:conn-pushout}\n  Consider a pushout square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      S \\arrow[d,swap,\"f\"] \\arrow[r,\"g\"] & B \\arrow[d,\"j\"] \\\\\n      A \\arrow[r,swap,\"i\"] & X.\n    \\end{tikzcd}\n  \\end{equation*}\n  If the map $f:S\\to A$ is $k$-connected, then so is the map $j:B\\to X$.\n\\end{prp}\n\n\\begin{proof}\n  We claim that the map $j:B\\to X$ is left orthogonal to any $k$-truncated map $p:Y\\to Z$, which is equivalent to the property that $j$ is $k$-connected. To see that $j$ is left orthogonal to $p$, consider the commuting cube\n  \\begin{equation*}\n    \\begin{tikzcd}\n      & Y^X \\arrow[dl] \\arrow[d] \\arrow[dr] & \\\\\n      Y^A \\arrow[d] & Y^B \\arrow[dl] \\arrow[dr] & Z^X \\arrow[dl,crossing over] \\arrow[d] \\\\\n      Y^S \\arrow[dr] & Z^A \\arrow[d] \\arrow[from=ul,crossing over] & Z^B \\arrow[dl] \\\\\n      & Z^S.\n    \\end{tikzcd}\n  \\end{equation*}\n  In this cube, the front left square is a pullback square because the map $f:S\\to A$ is assumed to be $k$-connected, and therefore it is left orthogonal to the $k$-truncated map $p$. The back left and front right squares are pullback squares by the pullback property of pushouts. Therefore it follows that the back right square is a pullback square. This shows that $j$ is left orthogonal to $p$.\n\\end{proof}\n\n\\begin{lem}\\label{lem:conn-mismatch}\n  A pointed type $X$ is $(k+1)$-connected if and only if the point inclusion\n  \\begin{equation*}\n    \\unit\\to X\n  \\end{equation*}\n  is a $k$-connected map.\n\\end{lem}\n\n\\begin{proof}\n  Since $X$ is assumed to have a base point $x_0:X$, it follows that $X$ is $(k+1)$-connected if and only if its identity types $(x=y)$ are $k$-connected. Now the claim follows from the fact that there is an equivalence\n  \\begin{equation*}\n    \\fib{\\const_{x_0}}{y}\\simeq (x_0=y).\\qedhere\n  \\end{equation*}\n\\end{proof}\n\n\\begin{thm}\\label{thm:conn-suspension}\n  If $X$ is an $k$-connected type, then its suspension $\\susp X$ is $(k+1)$-connected.\n\\end{thm}\n\n\\begin{proof}\n  The type $X$ is $k$-connected if and only if the map $\\const_\\ttt:X\\to\\unit$ is a $k$-connected map. Recall that the suspension of $X$ is a pushout\n  \\begin{equation*}\n    \\begin{tikzcd}\n      X \\arrow[d,swap,\"\\const_\\ttt\"] \\arrow[r,\"\\const_\\ttt\"] & \\unit \\arrow[d,\"\\south\"] \\\\\n      \\unit \\arrow[r,swap,\"\\north\"] & \\susp X.\n    \\end{tikzcd}\n  \\end{equation*}\n  Therefore we see by \\cref{prp:conn-pushout} that the point inclusions $\\north,\\south:\\unit\\to\\susp X$ are both $k$-connected maps. By \\cref{lem:conn-mismatch} it follows that $\\susp X$ is a $(k+1)$-connected type.\n\\end{proof}\n\n\\begin{cor}\\label{cor:conn-sphere}\n  The $n$-sphere is $(n-1)$-connected.\n\\end{cor}\n\n\\begin{proof}\n  The $0$-sphere is $(-1)$-connected, since it contains a point. Thus the claim follows by induction on $n:\\N$, using \\cref{thm:conn-suspension}.\n\\end{proof}\n\n\\subsection{The join connectivity theorem}\n\n\\begin{thm}\n  If $X$ is $k$-connected and $Y$ is $l$-connected, then their join $\\join{X}{Y}$ is $(k+l+2)$-connected.\n\\end{thm}\n\n\\begin{thm}\nConsider a pullback square\n\\begin{equation*}\n\\begin{tikzcd}\nC \\arrow[r] \\arrow[d] & B \\arrow[d] \\\\\nA \\arrow[r] & X.\n\\end{tikzcd}\n\\end{equation*}\nIf the maps $A\\to X$ and $B\\to X$ are $k$- and $l$-connected, respectively, then the map $A\\sqcup^C B\\to X$ is $(k+l+2)$-connected.\n\\end{thm}\n\n\\begin{thm}\n  The connected maps contain the equivalences, are closed under coproducts, pushouts, retracts, and transfinite compositions.\n\\end{thm}\n\n\\begin{exercises}\n  \\exercise Show that every type is equivalent to a disjoint union of connected components, i.e., show that for every type $X$ there is a family of connected types $B_i$ by a set $I$, with an equivalence\n  \\begin{equation*}\n    X \\eqvsym \\sm{i:I}B_i.\n  \\end{equation*}\n\\exercise Let $f:A\\to_\\ast B$ be a pointed map between pointed $n$-connected types, for $n\\geq -1$. Show that the following are equivalent:\n\\begin{enumerate}\n\\item $f$ is an equivalence.\n\\item $\\loopspace[n+1]{f}$ is an equivalence. \n\\end{enumerate}\n\\exercise Show that if\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[r] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"g\"] \\\\\nX \\arrow[r] & Y\n\\end{tikzcd}\n\\end{equation*}\nis \\define{$k$-cocartesian} in the sense that the cogap map is $k$-connected, then the map $\\mathsf{cofib}(f)\\to \\mathsf{cofib}(g)$ is $k$-connected.\n\\exercise Show that if $f:X\\to Y$ is a $k$-connected map, then so is\n\\begin{equation*}\n  \\begin{tikzcd}\n    \\trunc{l}{f}:\\trunc{l}{X}\\to\\trunc{l}{Y}\n  \\end{tikzcd}\n\\end{equation*}\nfor any $l\\geq-2$.\n\\exercise Consider a commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[d,swap,\"f\"] \\arrow[r] & B \\arrow[d,\"g\"] \\\\\nX \\arrow[r] & Y\n\\end{tikzcd}\n\\end{equation*}\n\\begin{subexenum}\n\\item Show that if the square is $k$-cartesian and $g$ is $k$-connected, then so is $f$.\n\\item Show that if $f$ is $k$-connected and $g$ is $(k+1)$-connected, then the square is $k$-cartesian. \n\\end{subexenum}\n\\exercise\n\\begin{subexenum}\n\\item Show that any sequential colimit of $k$-connected types is again $k$-connected.\n\\item Show that if every map in a type sequence\n  \\begin{equation*}\n    \\begin{tikzcd}\n      A_0\\arrow[r] & A_1 \\arrow[r] & A_2 \\arrow[r] & \\cdots\n    \\end{tikzcd}\n  \\end{equation*}\n  is $k$-connected, then so is the transfinite composition $A_0\\to A_\\infty$.\n\\end{subexenum}\n\\exercise Recall that a commuting square is called $k$-cartesian, if its gap map is $k$-connected. Show that $(k+1)$-truncation preserves $l$-cartesian squares for any $l\\leq k$, i.e., show that for any $l\\leq k$, if a square\n\\begin{equation*}\n  \\begin{tikzcd}\n    C \\arrow[r,\"q\"] \\arrow[d,swap,\"p\"] & B \\arrow[d,\"g\"] \\\\\n    A \\arrow[r,swap,\"f\"] & X.\n  \\end{tikzcd}\n\\end{equation*}\nis $l$-cartesian, then the square\n\\begin{equation*}\n  \\begin{tikzcd}[column sep=large]\n    \\trunc{k+1}{C} \\arrow[r,\"\\trunc{k+1}{q}\"] \\arrow[d,swap,\"\\trunc{k+1}{p}\"] & \\trunc{k+1}{B} \\arrow[d,\"\\trunc{k+1}{g}\"] \\\\\n    \\trunc{k+1}{A} \\arrow[r,swap,\"\\trunc{k+1}{f}\"] & \\trunc{k+1}{X}\n  \\end{tikzcd}\n\\end{equation*}\nis $l$-cartesian.\n\\exercise Generalize \\cref{rmk:conn-3-for-2} to show that for every $k\\geq-1$, the $k$-connected maps do not satisfy the 3-for-2 property.\n\\exercise Consider a commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[d,swap,\"f\"] \\arrow[r] & B \\arrow[d,\"g\"] \\\\\nX \\arrow[r] & Y\n\\end{tikzcd}\n\\end{equation*}\nShow that the following are equivalent:\n\\begin{enumerate}\n\\item The map $A\\to X\\times_Y B$ is $n$-connected. In this case the square is called \\define{$n$-cartesian}.\n\\item For each $x:X$ the map\n\\begin{equation*}\n\\fib{f}{x}\\to \\fib{g}{f(x)}\n\\end{equation*}\nis $n$-connected.\n\\end{enumerate}\n\\exercise Consider a map $f:A\\to B$. Show that the following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ is a weak equivalence.\n  \\item The map $f$ is $\\infty$-connected, in the sense that $f$ is $k$-connected for each $k$.\n  \\item The map $f$ is left orthogonal to any map between truncated types of any truncation level.\n  \\item The map $f$ is left orthogonal to any truncated map, for any truncation level.\n  \\end{enumerate}\n  Thus we see that, while the classes of $k$-connected maps and $k$-equivalences differ for finite $k\\geq-1$, they come to agree at $\\infty$.\n  \\exercise Consider a pointed $(k+1)$-connected type $X$. Show that every $k$-truncated map $f:A\\to X$ trivializes, in the sense that there is a $k$-type $B$ and an equivalence $e:\\eqv{A}{X\\times B}$ for which the triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=0]\n      A \\arrow[rr,\"e\"] \\arrow[dr,swap,\"f\"] & & X\\times B \\arrow[dl,\"\\proj 1\"] \\\\\n      \\phantom{X\\times B} & X\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes.\n  \\exercise Consider a $k$-equivalence $f:B'\\to B$. Show that the base-change functor induces an equivalence\n  \\begin{equation*}\n    \\Big(\\sm{E:\\UU}{p:E\\to B}\\isetale_k(p)\\Big)\\simeq\\Big(\\sm{E':\\UU}{p':E'\\to B'}\\isetale_k(p')\\Big).\n  \\end{equation*}\n  In other words, for every $k$-\\'etale map $p':E'\\to B'$ there is a unique $k$-\\'etale map $p:E\\to B$ equipped with a map $q:E'\\to E$ such that the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      E' \\arrow[d,swap,\"{p'}\"] \\arrow[r,densely dotted,\"q\"] & E \\arrow[d,densely dotted,\"p\"] \\\\\n      B' \\arrow[r,swap,\"f\"] & B\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes and is a pullback square. In this sense $k$-\\'etale maps descend along $k$-equivalences.\n\\end{exercises}\n", "meta": {"hexsha": "1926aca84bbdd4a15d4ed47c577465a38b0e13c0", "size": 35949, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/connected.tex", "max_stars_repo_name": "hemangandhi/HoTT-Intro", "max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 333, "max_stars_repo_stars_event_min_datetime": "2018-09-26T08:33:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:50:15.000Z", "max_issues_repo_path": "Book/connected.tex", "max_issues_repo_name": "hemangandhi/HoTT-Intro", "max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-06-18T04:16:04.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-16T15:27:01.000Z", "max_forks_repo_path": "Book/connected.tex", "max_forks_repo_name": "hemangandhi/HoTT-Intro", "max_forks_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2018-09-26T09:08:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T00:33:50.000Z", "avg_line_length": 51.7251798561, "max_line_length": 529, "alphanum_fraction": 0.6740382208, "num_tokens": 12505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7321619752284954}}
{"text": "\\problemname{Distance}\n\nThe City of Manhattan is organized as a grid of streets and avenues,\nwith streets running in the North-South direction and avenues running\nin the East-West direction.  Streets are numbered from East to West\nstarting from 1, and avenues are numbered from North to South starting\nfrom 1.  Each intersection is labelled by the street and avenue number\n$(s, a)$.  The distance between two intersections $(s_1, a_1)$ and\n$(s_2, a_2)$ is $|s_1-s_2| + |a_1-a_2|$.\n\nYour company operates several food trucks at different intersections in\nManhattan and you want to have them spread out so they do not compete\nwith each other.  To estimate how spread out they are, you have\ndecided to compute the total distance between every distinct pair of\nyour food trucks.  A small total distance would mean that on average,\na pair of food truck is too close together.\n\nWhat is the total distance between every distinct pair of food trucks?\n\n\\section*{Input}\n\nThe first line of input contains an integer $N$\n($2 \\leq N \\leq 200\\,000$), which is the number of food trucks.\n\nThe next $n$ lines describe the food trucks' locations. Each of\nthese lines contains two integers $s$ ($1 \\leq s \\leq 1\\,000\\,000$),\nwhich is the street number of this food truck, and $a$\n($1 \\leq a \\leq 1\\,000\\,000$), which is the avenue number of this\nfood truck.\n\n\\section*{Output}\n\nDisplay the total distance between every distinct pair of food trucks.\n", "meta": {"hexsha": "114e9bcf9d205c4d1ba3007ac2a4c1c07def9e5f", "size": 1432, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems/distance/problem_statement/problem.tex", "max_stars_repo_name": "icpc/na-rocky-mountain-2020-public", "max_stars_repo_head_hexsha": "d77cd0dfd9bd707f34497977251c4cc583647fef", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-11T21:49:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-19T22:31:57.000Z", "max_issues_repo_path": "problems/distance/problem_statement/problem.tex", "max_issues_repo_name": "icpc/na-rocky-mountain-2020-public", "max_issues_repo_head_hexsha": "d77cd0dfd9bd707f34497977251c4cc583647fef", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "problems/distance/problem_statement/problem.tex", "max_forks_repo_name": "icpc/na-rocky-mountain-2020-public", "max_forks_repo_head_hexsha": "d77cd0dfd9bd707f34497977251c4cc583647fef", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-03-11T18:15:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-24T00:15:32.000Z", "avg_line_length": 42.1176470588, "max_line_length": 71, "alphanum_fraction": 0.7604748603, "num_tokens": 371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857831, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7321445508880655}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{tikz}\n\\setlength{\\parindent}{0pt}\n\n\\newtheorem*{theorem}{Theorem}\n\\newtheorem*{definition}{Definition}\n\\newtheorem*{lemma}{Lemma}\n\\newtheorem*{corollary}{Corollary}\n\\newtheorem{example}{Example}\n\\newtheorem*{trick}{Trick}\n\\newtheorem*{question}{Question}\n\n\\title{Lecture 17: Polar Coordinates, Application of Double Integrals}\n\\author{}\n\\date{}\n\n\\begin{document}\n    \n\\maketitle\n\n\\section{Double Integrals in Polar Coordinates}\n\nRecall that in polar coordinates, the position is described by two independent \nvariables $r$ and $\\theta$, instead of $x$ and $y$. The relation between two \ncoordinate systems is\n\\begin{gather*}\n  x = r\\cos\\theta \\\\\n  y = r\\sin\\theta \\\\\n\\end{gather*}\n\nSince the polar coordinate system is only another way of describing positions of \ntwo-dimentional points, we can also do double integrals in polar coordinates.\n\n\\begin{example}\n  Calculate the double integral $\\iint_R (1 - x^2 - y^2) dA$ in polar \n  coordinates, where $R = $\n  \\begin{equation*}\n    \\begin{cases}\n      x^2 + y^2 \\leq 1 \\\\\n      x \\geq 0 \\\\\n      y \\geq 0 \\\\  \n    \\end{cases}\n  \\end{equation*}\n\n  First, we need to figure out how to express $dA$ in polar coordinates. If we \n  look at a small region formed by two small changes $\\Delta r$ and \n  $\\Delta \\theta$, the area of the small region is\n  \\begin{equation*}\n    \\begin{split}\n      \\Delta A &= \\frac{1}{2}(r + \\Delta r)^2 \\Delta \\theta - \\frac{1}{2}r^2 \\Delta \\theta \\\\\n               &= r \\Delta r \\Delta \\theta + \\frac{1}{2}(\\Delta r)^2 \\Delta \\theta \\\\\n    \\end{split}\n  \\end{equation*}\n  With the variable changes approaching 0, the limit of the area of the corresponding region is\n  \\begin{equation*}\n    dA = r dr d\\theta\n  \\end{equation*}\n\n  \\begin{question}\n    Why in the above limitation we ignore the term \n    $\\frac{1}{2}(\\Delta r)^2 \\Delta \\theta$? Is it because this term doesn't \n    have any non-differential factors? Is it because this term has higher order \n    of differential factors?\n  \\end{question}\n\n  Second, we need to determine the order of integral, i.e. whether we integrate \n  $dr$ first, or we integrate $d\\theta$ first. In theory, both orders of \n  integrals work, but in most cases, we choose integrating $dr$ first, and then \n  $d\\theta$.\n\n  Third, we need to determine the bounds of the inner and outer integrals, by \n  looking at the region in polar coordinates. Since the order of integral we \n  choose is $dr d\\theta$, we need to look at the bounds of the variable $r$ with \n  each possible value of the variable $\\theta$, and then look at the range of \n  the variable $\\theta$. In this case, the range of $r$ is $[0, 1]$ for any \n  value of $\\theta$, and the range of $\\theta$ is $[0, \\frac{\\pi}{2}]$.\n\n  Fourth, we need to figure out the function expression in polar coordinates. We \n  do this by utilizing the definition of the polar coordinates. In this example,\n  \\begin{equation*}\n    \\begin{split}\n      f(x, y) &= 1 - x^2 - y^2 \\\\\n              &= 1 - (r\\cos\\theta)^2 - (r\\sin\\theta)^2 \\\\\n              &= 1 - r^2 \\\\\n    \\end{split}\n  \\end{equation*}\n\n  Combining the above together,\n  \\begin{equation*}\n    \\begin{split}\n      \\iint_R (1 - x^2 - y^2) dA &= \\int_0^\\frac{\\pi}{2} \\int_0^1 (1 - r^2) r dr d\\theta \\\\\n                                 &= \\int_0^\\frac{\\pi}{2} ((\\frac{r^2}{2} - \\frac{r^4}{4})|_0^1) d\\theta \\\\\n                                 &= \\int_0^\\frac{\\pi}{2} \\frac{1}{4} d\\theta \\\\\n                                 &= (\\frac{\\theta}{4})|_0^{\\frac{\\pi}{2}} \\\\\n                                 &= \\frac{\\pi}{8} \\\\\n    \\end{split}\n  \\end{equation*}\n\\end{example}\n\nThe reasons why we choose to calculate double integrals in the polar coordinates:\n\\begin{itemize}\n  \\item The function expression is easier in the polar coordinates.\n  \\item The bounds of integrals are easier to express in the polar coordinates.\n\\end{itemize}\n\nIt is not often that we can achieve advantage in both aspects. Usually we get \nbenefits in one aspect, with the price of sacrificing the other aspect.\n\n\\section{Applications of Double Integrals}\n\n\\subsection{Application 1: Summing Function Values over a Region}\n\nTo find the area of a region $R$, though we can probably do it by setting up a \nsingle-variable integral, sometimes it is easier to do it with double integrals.\n\n\\begin{equation*}\n  S = \\iint_R 1 dA\n\\end{equation*}\n\nTo find the mass of a planar object with density $\\delta$, which is the mass per \nunit area.\n\\begin{gather*}\n  dm = \\delta dA \\\\\n  m = \\iint_R \\delta dA \\\\\n\\end{gather*}\n\n\\subsection{Application 2: Find the Average Value of a Function over a Region}\n\nTo find the average value of a multivariable function $f$ over a region $R$,\n\\begin{equation*}\n  \\bar{f} = \\frac{1}{\\iint_R 1 dA} \\iint_R f \\cdot dA\n\\end{equation*}\n\nTo find the weighted average value of a multivariable function $f$ over a region \n$R$ with the weight function $w$,\n\\begin{equation*}\n  \\bar{f} = \\frac{1}{\\iint_R w dA} \\iint_R w \\cdot f \\cdot dA\n\\end{equation*}\n\nTo find the center of mass of a planar object with density $\\delta$, supposing \nthe position of the center of mass is $(\\bar{x}, \\bar{y})$,\n\\begin{gather*}\n  \\bar{x} = \\frac{1}{\\iint_R \\delta dA}\\iint_R x \\cdot \\delta \\cdot dA \\\\\n  \\bar{y} = \\frac{1}{\\iint_R \\delta dA}\\iint_R y \\cdot \\delta \\cdot dA \\\\\n\\end{gather*}\n\n\\begin{question}\n  Why do the above formulas make sense?\n\\end{question}\n\n\\begin{question}\n  Can we calculate the center of mass in the polar coordinates as \n  $(\\bar{r}, \\bar{\\theta})$ using the same way as above?\n\n  It doesn't work. \n  \n  Counterexample: A planar disk with the center lies in the origin. You can see \n  the center of mass is $r = 0$, but you can never get this result using the \n  similar calculation as above. The result with the above calculation will be \n  $r > 0$.\n\\end{question}\n\n\\subsection{Application 3: Calculate the Moment of Inertia}\n\nMoment of inertia plays a similar role to mass when it comes to rotational \nmotion. Mass indicates how hard it is for an object to impart translation \nmotion. Moment of inertia indicates how hard it is for an object to rotate \naround an axis.\n\nMoment of inertia for a point mass:\n\nWe know that when a point mass $m$ moves at the velocity $v$, it has kinetic \nenergy $E_k = \\frac{1}{2}mv^2$. Then for a point mass $m$ at distance $r$ to its \naxis and having angular velocity $\\omega$:\n\\begin{gather*}\n  v = \\omega r \\\\\n  \\begin{split}\n    E_k &= \\frac{1}{2}mv^2 \\\\\n        &= \\frac{1}{2}m(\\omega r)^2 \\\\\n        &= \\frac{1}{2}mr^2 \\omega^2 \\\\\n        &= \\frac{1}{2}I \\omega^2 \\\\\n  \\end{split} \\\\\n  I = mr^2 \\\\\n\\end{gather*}\n\nTherefore, for such a point mass, its moment of inertia is $mr^2$.\n\nMoment of inertia for an object with the density $\\delta$:\n\nFor a small area $dA$ of the object, its moment of inertia is:\n\\begin{gather*}\n  dm = \\delta dA \\\\\n  dI = dm r^2 = \\delta r^2 dA \\\\\n\\end{gather*}\n\nThe moment of inertia of the object is the sum of the moment of inertia for \nevery area of the object:\n\\begin{equation*}\n  \\begin{split}\n    I &= \\iint_R dI \\\\\n      &= \\iint_R \\delta r^2 dA \\\\\n  \\end{split}\n\\end{equation*}\n\n\\begin{question}\n  Why the moment of inertia of an object is the sum of the moment of inertia of \n  every point on the object?\n\\end{question}\n\n\\begin{example}\n  Calculate the moment of inertia for a disk of radius $a$ with even density \n  rotating around the origin.\n\n  \\begin{tikzpicture}\n    [help line/.style={dashed}]\n    \\draw[->] (-3, 0) -- (3, 0) node[right] {x};\n    \\draw[->] (0, -3) -- (0, 3) node[right] {y};\n    \\draw (0, 0) node[below right] {O};\n    \\draw (0, 0) circle (2);\n    \\draw (2, 0) node[below right] {a};\n  \\end{tikzpicture}\n\n  Since the object has even density, we can suppose that its density \n  $\\delta = 1$. Then\n  \\begin{equation*}\n    \\begin{split}\n      I_O &= \\iint_R \\delta r^2 dA \\\\\n          &= \\int_0^{2\\pi} \\int_0^a r^2 r dr d\\theta \\\\\n          &= \\int_0^{2\\pi} ((\\frac{r^4}{4})|_0^a) d\\theta \\\\\n          &= \\int_0^{2\\pi} \\frac{a^4}{4} d\\theta \\\\\n          &= \\frac{a^4\\theta}{4}|_0^{2\\pi} \\\\\n          &= \\frac{\\pi a^4}{2} \\\\\n    \\end{split}\n  \\end{equation*}\n\\end{example}\n\n\\begin{example}\n  Calculate the moment of inertia for a disk of radius $a$ with even density \n  rotating around a point on the circumference.\n\n  \\begin{tikzpicture}\n    [help line/.style={dashed}]\n    \\draw[->] (-1, 0) -- (3, 0) node[right] {x};\n    \\draw[->] (0, -2) -- (0, 2) node[right] {y};\n    \\draw (0, 0) node[below right] {O};\n    \\draw (1, 0) circle (1);\n    \\draw (2, 0) node[below right] {2a};\n    \\draw[help line] (0, 0) -- (1.5, 0.866) -- (2, 0);\n    \\draw (0.2, 0) arc [start angle=0, end angle=30, radius=0.2] node[right] \n      {$\\theta$};\n  \\end{tikzpicture}\n\n  Since the object has even density, we can suppose that its density \n  $\\delta = 1$.\n\n  For each possible value of $\\theta$, according to the geometric relationship, \n  the bounds of the variable $r$ is $[0, 2a\\cos\\theta]$. Then\n  \\begin{equation*}\n    \\begin{split}\n      I_O &= \\iint_R \\delta r^2 dA \\\\\n          &= \\int_{-\\frac{\\pi}{2}}^{\\frac{\\pi}{2}} \\int_0^{2a\\cos\\theta} r^2 r dr d\\theta \\\\\n          &= \\int_{-\\frac{\\pi}{2}}^{\\frac{\\pi}{2}} ((\\frac{r^4}{4})|_0^{2a\\cos\\theta}) d\\theta \\\\\n          &= \\int_{-\\frac{\\pi}{2}}^{\\frac{\\pi}{2}} 4a^4\\cos^4\\theta d\\theta \\\\\n          &= 4a^4 \\int_{-\\frac{\\pi}{2}}^{\\frac{\\pi}{2}} \\cos^4\\theta d\\theta \\\\\n          &= 4a^4 (\\frac{3 + 4\\cos 2\\theta + \\cos 4\\theta}{8})|_{-\\frac{\\pi}{2}}^{\\frac{\\pi}{2}} \\\\\n          &= 4a^4 \\frac{3\\pi}{8} \\\\\n          &= \\frac{3\\pi a^4}{2} \\\\\n    \\end{split}\n  \\end{equation*}\n\n\n\\end{example}\n\n\\end{document}", "meta": {"hexsha": "146e55b34ae44239eafbfbc2de4af75eea7e11cc", "size": 9670, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture17.tex", "max_stars_repo_name": "jinxinwangstd/multivariable-calculus-mit", "max_stars_repo_head_hexsha": "d165ef6ff085fafd0fb89b8027fc5f5e0dbfa1e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lecture17.tex", "max_issues_repo_name": "jinxinwangstd/multivariable-calculus-mit", "max_issues_repo_head_hexsha": "d165ef6ff085fafd0fb89b8027fc5f5e0dbfa1e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture17.tex", "max_forks_repo_name": "jinxinwangstd/multivariable-calculus-mit", "max_forks_repo_head_hexsha": "d165ef6ff085fafd0fb89b8027fc5f5e0dbfa1e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.7841726619, "max_line_length": 106, "alphanum_fraction": 0.6349534643, "num_tokens": 3138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8740772417253256, "lm_q1q2_score": 0.7321445471644298}}
{"text": "\n\\section{Modeling diffusion problems}\n\n\\begin{intro}\n  Diffusion problems arise when a balance law, for instance for mass\n  in ground water flow or for energy in temperature conduction is\n  coupled with a constitutive equation relating the direction of\n  movement to the gradient of the quantity of interest.\n\\end{intro}\n\n\\begin{intro}\n  Let $\\rho$ be the density of a conserved quantity. Then, for any given\n  volume we have the ``mass''\n  \\begin{gather*}\n    m = \\int_V \\rho\\dx.\n  \\end{gather*}\n  Changes of this mass can be due to two processes:\n  \\begin{enumerate}\n  \\item Generation of additional mass by a source $g$,\n  \\item Flow of mass over the boundary of $V$ at a velocity $v$.\n  \\end{enumerate}\n  In formulas, we have\n  \\begin{gather*}\n    \\tfrac{d}{d t} m = \\int_V g\\dx - \\oint_{\\d V} J\\cdot \\n \\ds,\n  \\end{gather*}\n  also known as \\define{Reynolds transport theorem}. Here, $J$ is the\n  \\define{flux}. The exact form of the flux will be modeled later.\n  The formula above is somewhat unwieldy, since it combines volume and\n  surface integrals. Therefore, we apply the \\putindex{Gauss theorem}\n  to obtain\n  \\begin{gather}\n    \\label{eq:darcy:2}\n    \\frac{d}{dt} \\int_V \\rho\\dx = \\int_V g\\dx - \\int_V \\div J \\dx.\n  \\end{gather}\n  Concentrating and assuming sufficient regularity, we arrive at the\n  equation\n  \\begin{gather}\n    \\label{eq:darcy:3}\n    \\d_t \\rho + \\div J = g.\n  \\end{gather}\n  As before in these notes, we ignore the time dependence and only\n  look at stationary limits. In this case, this reduces to\n  \\begin{gather}\n    \\label{eq:darcy:4}\n    \\div J = g.\n  \\end{gather}\n\\end{intro}\n\n\\begin{example}\n  Next we consider constitutive relations between $\\rho$ and $J$ such\n  that we can complement equation~\\eqref{eq:darcy:4} by a second\n  equation and obtain a solvable system. To this end, we consider\n  thermal diffusion and ground water flow.\n\n  \\begin{description}\n  \\item[Heat conduction:] Here, the conserved quantity is not the\n    density $\\rho$, but the temperature $T$. \\define{Fourier's law}\n    states that the flux is proportional to the gradient of the\n    temperature, pointing in opposite direction:\n    \\begin{gather*}\n      J = -k\\nabla T.\n    \\end{gather*}\n    The constant of proportionality $k$ is the heat conductivity.\n  \\item[Porous media flow:] The conserved quantity is the amount of\n    fluid, represented by the hydraulic head or pressure\n    $p$. \\define{Darcy's law} says that the flux is the product of the\n    hydraulic \\define{permeability} of the media and the gradient of the\n    pressure:\n    \\begin{gather*}\n      J = -K\\nabla p.\n    \\end{gather*}\n    Here, the permeability $K$ is either a positive scalar function or\n    a symmetric, positive definite matrix. Note that in the latter\n    case, $J$ and $\\nabla p$ do not point in the same direction.\n    \\item[General diffusion processes:] \\define{Fick's law} states,\n      that the flux of a diffusion process is determined by the\n      gradient of the diffusing quantity $p$ by the relation\n    \\begin{gather*}\n      J = -D\\nabla p.\n    \\end{gather*}\n    $D$ is the symmetric, positive definite \\define{diffusion tensor}.\n  \\end{description}\n\\end{example}\n\n\\begin{intro}\n  From the two equations for $J$, we derive the following system of\n  PDE, where we replace the letter $J$ by the more familiar $u$:\n  \\begin{gather}\n    \\label{eq:darcy:5}\n    \\arraycolsep2pt\n    \\begin{matrix}\n      K^{-1} u &+& \\nabla p &=& 0 \\\\\n      \\div u &&&=& f.\n    \\end{matrix}\n  \\end{gather}\n  This system is closed by boundary conditions. Let $\\Gamma_D$ be the\n  Dirichlet boundary and $\\Gamma_N$ be the Neumann boundary such that\n  $\\Gamma_D \\cap \\Gamma_N = \\emptyset$ and\n  $\\Gamma_D\\cup\\Gamma_N = \\d\\domain$. Then, we let\n  \\begin{gather}\n    \\label{eq:darcy:6}\n    \\begin{aligned}\n      p(x) &= p^D(x) & x & \\in \\Gamma_D, \\\\\n      u(x)\\cdot\\n &= u^N(x)\\cdot n & x & \\in \\Gamma_N.\n    \\end{aligned}\n  \\end{gather}\n\n  Following the concept of finding spaces such that we have an inf-sup\n  condition, we are looking for a pair with minimal regularity, such\n  that we have a stable and bounded inf-sup condition. We begin the\n  usual way by multiplying with a test function and integrating:\n  \\begin{gather}\n    \\label{eq:darcy:7}\n    \\arraycolsep2pt\n    \\begin{matrix}\n      \\displaystyle\\int_\\domain K^{-1} u\\cdot v\\dx\n      &+&\n      \\displaystyle\\int_\\domain \\nabla p \\cdot v\\dx\n      &=& 0 \\\\\n      \\displaystyle\\int_\\domain \\div u q\\dx\n      &&&=&\n      \\displaystyle\\int_\\domain f q\\dx.\n    \\end{matrix}\n  \\end{gather}\n  It turns out, we have two immediate options: first, we can integrate\n  the first equation by parts, having all derivatives on $u$ and $v$.\n  On the other hand, we can integrate by parts in the second equation,\n  leaving all derivatives on $p$ and $q$. In the second case,\n  we obtain the equation\n  \\begin{gather*}\n    -\\int_\\domain u\\cdot\\nabla q\\dx + \\int_{\\d\\domain} u\\cdot\\n q \\ds\n    = \\int_\\domain f q\\dx.\n  \\end{gather*}\n  Applying the boundary condition, we first follow the recipe of\n  elliptic partial differential equations and implement $p=p^D$ as an\n  \\putindex{essential boundary condition}, that is, the test function\n  space has zero trace on $\\Gamma_D$. Then, we can swap in $u^N$ for\n  $u$ on $\\Gamma_N$, such that the boundary term ends up on the right\n  hand side.\n\\end{intro}\n\n\\begin{Definition}{primal-mixed}\n  The \\define{primal mixed formulation} of the mixed diffusion\n  problem~\\eqref{eq:darcy:5} reads: find $(u,p)\\in V\\times Q$ such\n  that for all $v\\in V$ and $q\\in Q$ holds\n  \\begin{gather}\n    \\label{eq:darcy:8}\n    \\arraycolsep2pt\n    \\begin{array}{rcccl}\n      \\form(K^{-1} u, v) &+& \\form( \\nabla p, v)\n      &=& 0 \\\\\n      -\\form(u,\\nabla q)\n      &&&=& \\form(f,q) - \\forme(u^N\\cdot\\n, q)_{\\Gamma_N}.\n    \\end{array}\n  \\end{gather}\n  The spaces are\n  \\begin{gather}\n    \\label{eq:darcy:9}\n    \\begin{split}\n      V &= L^2(\\domain;\\R^d), \\\\\n      Q &= H^1_{\\Gamma_D}(\\domain) = \\bigl\\{\n      q\\in H^1(\\domain) \\big| \\;q_{|\\Gamma_D} = 0\n      \\bigr\\}.\n    \\end{split}\n  \\end{gather}\n\\end{Definition}\n\n\\begin{remark}\n  Since the first equation is tested with the test function $v$ itself\n  in all terms, we can eliminate this equation and there holds\n  $u= K\\nabla p$ in $L^2(\\domain;\\R^d)$. Entering this into the second\n  equation, we obtain the well-known \\putindex{primal formulation}\n  \\begin{gather*}\n    \\form(K \\nabla p,\\nabla q) = \\form(f,q)\n    - \\forme(u^N\\cdot\\n, q)_{\\Gamma_N}.\n  \\end{gather*}\n  Just keep in mind that the ``\\putindex{natural boundary condition}''\n  in this case is\n  \\begin{gather*}\n    K\\nabla p\\cdot n = 0.\n  \\end{gather*}\n  Hence, the primal mixed formulation does not provide any advantages\n  compared to the primal formulation, and we are not going to pursue\n  it further.\n\\end{remark}\n\n\\begin{intro}\n  Now we return to the first alternative, namely integrating by parts\n  in the first equation of~\\eqref{eq:darcy:7}:\n  \\begin{gather*}\n    \\int_\\domain K^{-1} u \\cdot v \\dx - \\int_\\domain p \\div v\\dx\n    + \\int_{\\d\\domain} v\\cdot \\n p\\ds = 0.\n  \\end{gather*}\n  Ensuing is a formulation multiplying and integrating the divergences\n  of $u$ and $v$, respectively, with functions in $Q$. In order to fit\n  this into our standard framework, we have to introduce a new Sobolev\n  space. In addition, since $u\\cdot\\n$ does not appear as a boundary\n  integral, we must make this an \\putindex{essential boundary\n    condition}. Thus, we require that the test functions have zero\n  normal trace on $\\Gamma_N$ (and justify this below). Note that now\n  the Dirichlet condition $p=0$ has become a ``\\putindex{natural\n    boundary condition}''!\n\\end{intro}\n\n\\begin{Definition}{hdiv}\n  Let $\\domain \\subset \\R^d$ be a domain.  We define the\n  Sobolev space\n  \\begin{gather}\n    \\Hdiv(\\domain) = \\bigl\\{\n    v\\in L^2(\\domain;\\R^d) \\big\\vert\n    \\div v\\in L^2(\\domain)\\bigr\\},\n  \\end{gather}\n  and its inner product\n  \\begin{gather}\n    \\scal(u,v)_{\\Hdiv} = \\form(u,v)_0 + \\form(\\div u,\\div v)_0.\n  \\end{gather}\n  Furthermore, let $C^\\infty_{00}(\\domain)$ be the space of smooth\n  functions with compact support in $\\domain$. Then, we define its\n  closure in $\\Hdiv(\\domain)$:\n  \\begin{gather}\n    \\Hdiv_0(\\domain) = \\overline{C^\\infty_{00}(\\domain)}.\n  \\end{gather}\n  For subset $\\Gamma\\subset\\d\\domain$, the space\n  $\\Hdiv_\\Gamma(\\domain)$ is defined accordingly (compare to\n  $H^1_\\Gamma(\\domain)$)\n\\end{Definition}\n\nUsing the space $\\Hdiv$ and for the moment the assumption, that\n$\\Hdiv_0$ and $\\Hdiv_\\Gamma$ serve to set boundary conditions, we can\nwrite down our second weak formulation of the mixed diffusion problem:\n\n\\begin{Definition}{dual-mixed}\n  The \\define{dual mixed formulation} of the mixed diffusion\n  problem~\\eqref{eq:darcy:5} reads: find $(u,p) \\in V\\times Q$ such\n  that for all $v\\in V$ and $q\\in Q$ holds\n  \\begin{gather}\n    \\label{eq:darcy:10}\n    \\arraycolsep2pt\n    \\begin{array}{rcccl}\n      \\form(K^{-1} u, v) &-& \\form(p, \\div v)\n      &=& \\forme(p^D,v\\cdot \\n)_{\\Gamma_D} \\\\\n      \\form(\\div u, q)\n      &&&=& \\form(f,q).\n    \\end{array}\n  \\end{gather}\n  The spaces are\n  \\begin{gather}\n    \\label{eq:darcy:11}\n    V = \\Hdiv_{\\Gamma_N}(\\domain),\n    \\qquad\n    Q = L^2(\\domain).\n  \\end{gather}\n\\end{Definition}\n\n\\subsection{Properties of $\\Hdiv(\\domain)$}\n\n\\begin{Theorem}{Hdiv-separable}\n  Let $\\domain$ be a bounded Lipschitz domain. Then, the space\n  $C^\\infty(\\overline\\domain;\\R^d)$ is dense in $\\Hdiv(\\domain)$.\n\\end{Theorem}\n\n\\begin{proof}\n  % We use the statement, that a subspace $W$ is dense in a space $V$ if\n  % and only if all linear functionals vanishing on $W$ also vanish on\n  % $V$. Therefore, let $L \\in \\Hdiv(\\domain)^*$. By the\n  % \\putindex{Riesz representation theorem}, there is\n  % $u\\in\\Hdiv(\\domain)$ such that\n  % \\begin{gather*}\n  %   L(v) = \\scal(u,v)_{\\Hdiv} = \\sum_{i=1}^d \\scal(u_i,v_i)_0\n  %   + \\scal(\\div u,\\div v)_0\n  %   \\quad\\forall v\\in \\Hdiv(\\domain).\n  % \\end{gather*}\n  % Now assume $L(\\phi) = 0$ for all $\\phi\\in\n  % C^\\infty(\\overline\\domain;\\R^d)$. Let us extend $u$ and $\\div u$ outside\n  % of the domain $\\domain$ by zero. Then, there holds\n  % \\begin{gather*}\n  %   \\int_{\\R^d} u\\cdot \\phi \\dx + \\int_{\\R^d}\n  % \\end{gather*}\n  Either by a standard mollifier argument~\\cite{AdamsFournier03} or\n  following~\\cite[Theorem 2.4]{GiraultRaviart86}\n\\end{proof}\n\n\\begin{remark}\n  The condition of boundedness entered the assumptions since we use\n  the space $C^\\infty(\\overline\\domain)$. It could be dropped, if we\n  used a more appropriate space (cf.~\\cite[Theorem\n  2.4]{GiraultRaviart86}).\n\\end{remark}\n\n\\begin{Theorem}{Hdiv-trace}\n  The \\putindex{trace operator}\n  $\\gamma_n\\colon C^\\infty(\\overline\\domain;\\R^d) \\to\n  C^\\infty(\\overline{\\d\\domain})$\n  which maps $v\\mapsto v\\cdot\\n_{|\\d\\domain}$ can be extended to a\n  continuous, linear mapping\n  \\begin{gather}\n    \\gamma_n\\colon \\Hdiv(\\domain) \\to H^{-1/2}(\\d\\domain),\n  \\end{gather}\n  where $H^{-1/2}(\\d\\domain)$ is the dual of $H^{1/2}(\\d\\domain)$.\n\\end{Theorem}\n\n\\begin{proof}\n  Let $q\\in C^\\infty(\\overline\\domain)$ and\n  $v\\in C^\\infty(\\overline\\domain;\\R^d)$. Then, there holds\n  \\putindex{Green's formula}\n  \\begin{gather*}\n    \\form(v,\\nabla q)_\\domain\n    + \\form(\\div v,q)_\\domain\n    = \\forme(v\\cdot\\n,q)_{\\d\\domain}.\n  \\end{gather*}\n  Hence,\n  \\begin{gather*}\n    \\left\\vert\\int_{\\d\\domain} v\\cdot \\n q \\ds \\right\\vert\n    \\le \\norm{v}_{\\Hdiv} \\norm{q}_{H^1}.\n  \\end{gather*}\n  Applying the density of $C^\\infty(\\overline\\domain)$ in\n  $H^1(\\domain)$ and of $C^\\infty(\\overline\\domain;\\R^d)$ in\n  $\\Hdiv(\\domain)$, we can let $q$ and $v$ pass to a limit, but the\n  inequality holds uniformly.\n\n  Now apply that $H^{1/2}(\\d\\domain)$ is the trace space of\n  $H^1(\\domain)$. Therefore, for any $g\\in H^{1/2}(\\d\\domain)$, there\n  is a $q\\in H^1(\\domain)$ such that $q_{|\\d\\domain} = g$ and\n  $\\norm{q}_{1;\\domain} \\le \\norm{g}_{1/2;\\d\\domain}$. We obtain\n  \\begin{gather*}\n    \\left\\vert\\int_{\\d\\domain} v\\cdot \\n g \\ds \\right\\vert\n    \\le \\norm{v}_{\\Hdiv(\\domain)} \\norm{g}_{H^{1/2}(\\d\\domain)}\n    \\qquad\\forall v\\in \\Hdiv(\\domain), g\\in H^{1/2}(\\d\\domain).\n  \\end{gather*}\n  Hence,\n  \\begin{gather*}\n    \\norm{v\\cdot\\n}_{H^{-1/2}(\\d\\domain)} \\le\n    \\norm{v}_{\\Hdiv(\\domain)}\n    \\qquad\\forall v\\in \\Hdiv(\\domain).\n  \\end{gather*}\n  Thus, we have proven the continuity of the extension of $\\gamma_n$\n  to $\\Hdiv(\\domain)$.\n\\end{proof}\n\n\\begin{remark}\n  The trace theorem tells us that our interpretation of the spaces\n  $\\Hdiv_0(\\domain)$ and $\\Hdiv_\\Gamma(\\domain)$ as spaces with zero\n  boundary condition of the normal component is justified. This notion\n  will be fortified by the two theorems below. Therefore, we will\n  later avoid the notational overhead of using $\\gamma_n$ and will\n  simply write $v\\cdot\\n_{|\\d\\domain}$.\n\\end{remark}\n\n\\begin{Problem}{trace-dnu}\n  Show the following result. Let $p\\in H^1(\\domain)$ and\n  $\\Delta p \\in L^2(\\domain)$. Then, $\\d_n p\\in H^{-1/2}(\\d\\domain)$\n  and\n  \\begin{gather*}\n    \\form(\\nabla p,\\nabla q) = -\\form(\\Delta p,q) + \\forme(\\d_n\n    p,q)_{\\d\\domain} \\quad\\forall q\\in H^1(\\domain).\n  \\end{gather*}\n\\begin{solution}\nSince $p, q \\in H^1(\\domain)$ we can perform integration by parts to obtain\n\\begin{align*}\n (\\Delta p,q)=-(\\nabla p,\\nabla q)+\\forme(\\d_n p, q)_{\\d\\domain}.\n\\end{align*}\nNow, we can use the continuity of the trace operator as follows\n\\begin{align*}\n \\norm{\\d_n p}_{-1/2,\\d\\domain}\n &=\\sup_{q\\in H^{1/2}(\\domain)\\setminus\\{0\\}}\\frac{\\langle\\d_n p,q\\rangle_{\\d\\domain}}{\\norm{q}_{H^{1/2}(\\d\\domain)}}\\\\\n &\\leq\n  \\sup_{q\\in H^{1/2}(\\domain)\\setminus\\{0\\}}\\frac{\\norm{\\nabla p}_0 \\norm{\\nabla q}_0 +\\norm{\\Delta p}_0\\norm{q}_0}\n  {\\norm{q}_{1/2,\\d\\domain}}\\\\\n  &\\leq C (\\norm{\\nabla p}_0+\\norm{\\Delta p}_0).\n\\end{align*}\nTherefore, $\\d_n p\\in H^{-1/2}(\\d\\domain)$.\n\\end{solution}\n\\end{Problem}\n\n\\begin{Theorem}{Hdiv-trace-surjective}\n  The trace theorem is optimal in the sense that\n  $\\gamma_n\\colon \\Hdiv(\\domain) \\to H^{-1/2}(\\d\\domain)$ is\n  surjective.\n\\end{Theorem}\n\n\\begin{proof}\n  Let $\\mu \\in H^{-1/2}(\\d\\domain)$. We have to show that there exists\n  $v\\in \\Hdiv(\\domain)$ such that\n  \\begin{gather*}\n    v\\cdot\\n = \\mu \\quad\\text{on } \\d\\domain\n    \\qquad\\text{and}\\qquad\n    \\norm{v}_{\\Hdiv(\\domain)} \\le \\norm{\\mu}_{H^{-1/2}(\\d\\domain)}.\n  \\end{gather*}\n\n  We know that the problem\n  \\begin{xalignat*}2\n    -\\Delta \\phi + \\phi &= 0 &\\text{in }&\\domain, \\\\\n    \\d_n \\phi &= \\mu &\\text{on }&\\d\\domain,\n  \\end{xalignat*}\n  has a unique solution $\\phi\\in H^1(\\domain)$ with\n  \\begin{gather*}\n    \\norm{\\phi}_{H^1(\\domain)}^2 = \\forme(\\mu,\\phi)_{\\d\\domain}\n    \\le \\norm{\\mu}_{H^{-1/2}(\\d\\domain)}\\norm{\\phi}_{H^1(\\domain)}.\n  \\end{gather*}\n  The first equation then implies $\\Delta\\phi\\in L^2(\\domain)$ and\n  thus $v=\\nabla \\phi\\in \\Hdiv(\\domain)$. Since from this equation\n  there even holds $\\div v=\\phi$, we obtain\n  \\begin{gather*}\n    \\norm{v}_{\\Hdiv(\\domain)} \\le \\norm{\\mu}_{H^{-1/2}(\\d\\domain)}.\n  \\end{gather*}\n\\end{proof}\n\n\\begin{Theorem}{Hdiv-trace-kernel}\n  There holds\n  \\begin{gather}\n    \\ker{\\gamma_n} = \\Hdiv_0(\\domain).\n  \\end{gather}\n\\end{Theorem}\n\n\\begin{proof}\n  The inclusion $\\Hdiv_0(\\domain) \\subset \\ker{\\gamma_n}$ follows\n  immediately from the definition and continuity of $\\gamma_n$. For\n  the opposite inclusion, we have to show that the traces of functions\n  in $C^\\infty_{00}(\\domain)$ are dense in $\\ker{\\gamma_n}$. We do\n  this by using, that a subspace $W$ is dense in a space $V$ if and\n  only if all linear functionals vanishing on $W$ also vanish on\n  $V$. Choose $u\\in\\ker{\\gamma_n}$ and use the \\putindex{Riesz\n    representation theorem} to associate with it\n  $L\\in \\ker{\\gamma_n}^*$ by\n  \\begin{gather*}\n    L(v) = \\scal(u,v)_{\\Hdiv} \\qquad\\forall v\\in \\ker{\\gamma_n}.\n  \\end{gather*}\n  Assume now that $L(\\phi) = 0$ for all $\\phi\\in\n  C^\\infty_{00}(\\domain;\\R^d)$. This implies by\n  \\begin{gather*}\n    0 = L(\\phi) = \\form(u,\\phi)_{L^2} + \\form(\\div u, \\div \\phi),\n  \\end{gather*}\n  that $u=\\nabla \\div u$ in distributional sense, and by taking limits\n  of $\\phi$ in $H^1$ that $\\div u\\in H^1(\\domain)$. Hence, Green's\n  formula yields\n  \\begin{gather*}\n    L(v) = \\form(\\nabla\\div u,v)+\\form(\\div u,\\div v)\n    = \\forme(v\\cdot\\n,\\div u)_{\\d\\domain} = 0\n    \\qquad\\forall v\\in \\ker{\\gamma_n}.\n  \\end{gather*}\n  Thus, $L$ vanishes on all elements of $\\ker{\\gamma_n}$ and the\n  theorem is proven.\n\\end{proof}\n\n% \\begin{example}\n%   The trace theorem involves the space $H^{-1/2}(\\d\\domain)$, which\n%   requires a short discussion. On one dimensional boundaries, elements\n%   in $H^{1/2}(\\d\\domain)$ have continuous representatives. The\n%   situation in three dimensions is similar, where no jumps across a\n%   line, for instance between two faces is allowed. Therefore,\n%   functions in $H^{-1/2}(\\d\\domain)$ cannot be localized to parts of\n%   the boundary, for instance the edge of a cell.\n\n%   We give an example (modified from \\cite[Section\n%   2.5.1]{BoffiBrezziFortin13}) of this phenomenon.  On the disc\n%   $\\mathcal D$ around the origin of radius $e^{-1}$ consider the\n%   function\n%   \\begin{gather*}\n%     u(x,y) = \\ln\\Bigl(-\\ln\\bigl(\\sqrt{x^2+y^2}\\bigr)\\Bigr).\n%   \\end{gather*}\n%   There holds $u\\in H^1_0(\\mathcal D)$.\\marginpar{Volunteers computing\n%     the derivative?} Now, consider the domain $\\domain$ consisting\n%   only of the upper half circle:\n%   \\begin{align*}\n%     \\domain &= \\bigl\\{(x,y)\\in \\R^2 \\big\\vert\n%               x^2+y^2<e^{-2} \\text{ and } y>0 \\bigr\\}\n%     \\\\\n%     \\d\\domain &= [-e^{-1},e^{-1}]\n%                 \\cup \\bigl\\{ (x,\\sqrt{e^{-2}-x^2}) \\big\\vert\n%                 x\\in (-e^{-1},e^{-1}) \\bigr\\}\n%   \\end{align*}\n%   Thus, the trace of $u$ on the boundary is in\n%   $H^{1/2}(\\d\\domain)$. We now define $\\mu\\in H^{-1/2}(\\d\\domain)$ as\n%   the distributional derivative in tangential direction, say\n%   counter-clockwise,\n%   \\begin{gather*}\n%     \\scal(\\mu,\\phi) = - \\int_{\\d\\domain} u \\d_{\\tau} \\phi\n%     \\qquad\\forall \\phi\\in C^1(\\d\\domain).\n%   \\end{gather*}\n\n%   Computation yields\n%   \\begin{gather*}\n%     \\mu(x) = \\frac1{x\\ln \\abs{x}} \\times\n%     \\begin{cases}\n%       1 & x\\in (-e^{-1},0) \\\\\n%       -1& x\\in (0,e^{-1}).\n%     \\end{cases}\n%   \\end{gather*}\n%   Both integrals\n%   \\begin{gather*}\n%     \\int_{-e^{-1}}^0 \\mu(x)\\dx\n%     \\qquad\n%     \\int^{e^{-1}}_0 \\mu(x)\\dx,\n%   \\end{gather*}\n%   are not bounded, such that on these parts of the boundary, $\\mu$\n%   cannot even be tested with a constant function.\n%   Now, we consider the integral\n%   \\begin{gather*}\n%     \\forme(\\mu,\\phi) = \\int_{-e^{-1}}^{e^{-1}} \\ln(-\\ln\\abs x) \\d_\\tau \\phi \\dx.\n%   \\end{gather*}\n%   If we split $\\phi$ into an odd and an even part, the intgral with\n%   the even part vanishes, since $\\ln(-\\ln\\abs x)$ is even and the\n%   derivative is odd. Therefore,\n%   \\begin{gather*}\n%     \\forme(\\mu,\\phi)\n%     = \\int_{-e^{-1}}^{e^{-1}}\n%     \\frac{\\phi_{\\text{odd}}(x)}{x\\ln\\abs x} \\dx\n%   \\end{gather*}\n%   Finally, we use the fact that $\\phi_{\\text{odd}}(0) = 0$ and that\n%   it's growth is limited by its regularity. In order to be square\n%   integrable, the groth of $\\phi_{\\text{odd}}$ must be limited by a\n%   positive, fractional power,\n%   \\begin{gather*}\n%     \\abs{\\phi_{\\text{odd}}(x)} \\le c \\abs x^\\alpha,\n%     \\qquad \\alpha>0.\n%   \\end{gather*}\n%   Then,\n%   \\begin{gather*}\n%     \\int_0^{e^{-1}} \\frac{\\abs{\\phi_{\\text{odd}}(x)}}{x\\ln\\abs x} \\dx\n%     \\le \\frac{x^{\\alpha-1}}{\\ln\\abs x} \\dx < \\infty.\n%   \\end{gather*}\n% \\end{example}\n\n\\begin{Theorem}{Hdiv-helmholtz}\n  Let $\\domain$ be connected. Let\n  \\begin{gather}\n    \\label{eq:darcy:1}\n    V_0 = \\bigl\\{ v\\in \\Hdiv_0(\\domain) \\big\\vert\n    \\div v = 0 \\bigr\\}.\n  \\end{gather}\n  Then,\n  \\begin{gather}\n    L^2(\\domain;\\R^d) = V_0 \\oplus \\ortho V,\n  \\end{gather}\n  and\n  \\begin{gather}\n    \\ortho V = \\bigl\\{ v = \\nabla q \\big\\vert\n    q\\in H^1(\\domain) \\bigr\\}.\n  \\end{gather}\n\\end{Theorem}\n\n\\begin{proof}\n  Let $X=\\{ v= \\nabla q \\vert q\\in H^1(\\domain)\\}$. we have to show\n  $\\ortho V = X$. Observe that $X$ is closed in $L^2$ since $H^1$ is\n  complete. We show that $V_0 = \\ortho X$ and thus\n  \\begin{gather*}\n    \\ortho {V_0} = \\ortho{(\\ortho{V_0})} = \\overline X = X.\n  \\end{gather*}\n  First, let $u\\in V_0$. Then, Green's formula reduces to\n  \\begin{gather*}\n    \\form(u,\\nabla q) = 0 \\qquad\\forall q\\in H^1(\\domain).\n  \\end{gather*}\n  Hence, $V_0\\subset \\ortho X$. Let now conversely\n  $u\\in L^2(\\domain;\\R^d)$ such that the previous identity\n  holds. Choosing $q\\in C^\\infty_{00}(\\domain)$ yields $\\div u=0$,\n  which in turn means $u\\in\\Hdiv(\\domain)$. Therefore, we can use\n  Green's formula to obtain $u\\cdot\\n=0$ on $\\d\\domain$. This together\n  implies $u\\in V_0$, proving $\\ortho X \\subset V_0$.\n\\end{proof}\n\n\\subsection{Well-posedness of the dual mixed formulation}\n\n\\begin{intro}\n  In order to apply the theory from\n  Chapter~\\ref{sec:mixed-wellposedness}, we have to define the\n  abstract bilinear forms $a(.,.)$ and $b(.,.)$. We read from the dual\n  mixed formulation\n  \\begin{align*}\n    a(u,v) &= \\form(K^{-1}u,v) \\\\\n    b(v,q) &= \\form(\\div v,q).\n  \\end{align*}\n\\end{intro}\n\n\n\\begin{Problem}{mixed-inhomogeneous-bc}\n  In both the primal and the dual mixed formulation, we ignored\n  inhomogeneous essential boundary conditions. Show that the usual\n  lifting method applies. Determine the modified equations and the\n  spaces needed for the liftings.\n\\begin{solution}\nThe inhomogeneous problem reads in strong form:\\\\\n\\begin{align*}\nK^{-1} {\\mathbf u} + \\nabla p &= 0 && \\textrm{ in } \\Omega,\\\\\n-{\\textrm{div}}\\ {\\mathbf u} &= -f && \\textrm{ in } \\Omega,\\\\\np &= p^D && \\textrm{ on } \\Gamma_D, \\\\\nu\\cdot n &=  u^N \\cdot n && \\textrm{ on } \\Gamma_N.\n\\end{align*}\n\nThe corresponding primal weak form is then given as: \\\\\nFind $(u,q)\\in V\\times Q=L^2(\\domain)\\times H_{\\Gamma_D}^1(\\domain)$ such that\n\\begin{align*}\nA(\\{{\\mathbf u},p\\},\\{{\\mathbf v},q\\}) &= F(\\{{\\mathbf v},q\\}), \\\\\nA(\\{{\\mathbf u},p\\},\\{{\\mathbf v},q\\}) &= ({\\mathbf v}, K^{-1}{\\mathbf u})_\\Omega +({\\mathbf v}, \\nabla p)_\\Omega + (\\nabla q,{\\mathbf u})_\\Omega \\\\\nF(\\{{\\mathbf v},q\\}) &= (q, {\\mathbf u}^N\\cdot {\\mathbf n})_{\\Gamma_N} - (f,q)_\\Omega.\n\\end{align*}\nTreating the Dirichlet boundary condition $p = p^D$ strongly requires us to\nsplit into $p=p_{hom} + p_{inhom}$ where $p_{inhom}$ fulfills the inhomogeneous\nboundary conditions. Provided $g\\in H^{1/2}(\\Omega)$ the trace operator acts\nas a lifting operator here to construct $p_{inhom}$.\nFor $p_{hom}$ we then have to solve\n\\begin{align*}\nA(\\{{\\mathbf u},p_{hom}\\},\\{{\\mathbf v},q\\}) &= F(\\{{\\mathbf v},q\\}), \\\\\nA(\\{{\\mathbf u},p_{hom}\\},\\{{\\mathbf v},q\\})\n  &= ({\\mathbf v}, K^{-1}{\\mathbf u})_\\Omega +({\\mathbf v}, \\nabla p_{hom})_\\Omega\n     + (\\nabla q,{\\mathbf u})_\\Omega \\\\\nF(\\{{\\mathbf v},q\\})\n  &= (q, {\\mathbf u}^N\\cdot {\\mathbf n})_{\\Gamma_N}-\n     ({\\mathbf v}, \\nabla p_{inhom})_\\Omega - (f,q)_\\Omega.\n\\end{align*}\n\nThere doesn't exist a continuous trace operator\n\\begin{align*}\n \\Vert T f \\Vert_{L^2(\\partial \\Omega)}\\le C \\Vert f \\Vert_{L^2(\\Omega)}\n\\end{align*}\nin $L^2(\\Omega)$.\n\n\nThe corresponding dual weak form is then given as: \\\\\nFind $(u,q)\\in V\\times Q=H^\\textrm{div}(\\domain)\\times L^2(\\domain)$ such that\n\\begin{align*}\nA(\\{{\\mathbf u},p\\},\\{{\\mathbf v},q\\}) &= F(\\{{\\mathbf v},q\\}), \\\\\nA(\\{{\\mathbf u},p\\},\\{{\\mathbf v},q\\}) &=\n  ({\\mathbf v}, K^{-1}{\\mathbf u})_\\Omega - ({\\textrm{div}}\\ {\\mathbf v}, p)_\\Omega\n  - (q,{\\textrm{div}}\\ {\\mathbf u})_\\Omega \\\\\nF(\\{{\\mathbf v},q\\}) &= -(p^D,{\\mathbf v}\\cdot {\\mathbf n})_{\\partial\\Omega} -(f,q)_\\Omega\n\\end{align*}\nwhere $V_0$ and $Q_0$ are the homogeneous spaces corresponding to $V$ and $Q$.\nHere, we are enforcing $u\\cdot n = u^N \\cdot n$ strongly. Again, the trace operator can be used\nfor the lifting and the equations for the homogeneous part read\n\\begin{align*}\nA(\\{{\\mathbf u}_{hom},\\},\\{{\\mathbf v},q\\}) &= F(\\{{\\mathbf v},q\\}), \\\\\nA(\\{{\\mathbf u}_{hom},p\\},\\{{\\mathbf v},q\\})\n  &= ({\\mathbf v}, K^{-1}{\\mathbf u}_{hom})_\\Omega\n  - ({\\textrm{div}}\\ {\\mathbf v}, p)_\\Omega - (q,{\\textrm{div}}\\ {\\mathbf u}_{hom})_\\Omega \\\\\nF(\\{{\\mathbf v},q\\})\n  &= -(p^D,{\\mathbf v}\\cdot {\\mathbf n})_{\\partial\\Omega}\n     -({\\mathbf v}, K^{-1}{\\mathbf u}_{inhom})_\\Omega\\\\\n     &\\quad+ (q,{\\textrm{div}}\\ {\\mathbf u}_{inhom})_\\Omega - (f,q)_\\Omega\n\\end{align*}\n\\end{solution}\n\\end{Problem}\n\n\n\\begin{Lemma}{darcy-reduced-wellposed}\n  Let $V=\\Hdiv(\\domain)$ and $Q=L^2(\\domain)$ with their norms. Let\n  \\begin{gather}\n    \\label{eq:darcy:12}\n    V_0 = \\ker{B} = \\bigl\\{v\\in V\\big\\vert\n    \\form(\\div v,q) =0 \\;\\forall q\\in Q\\bigr\\}.\n  \\end{gather}\n  Assume there exist constants $\\ellipa$ and $\\norm a$ such that\n  \\begin{gather}\n    \\label{eq:darcy:13}\n    \\ellipa \\abs{\\xi}^2\n    \\le \\xi^T K^{-1} \\xi \\le \\norm a \\abs{\\xi}^2\n    \\qquad\\forall \\xi\\in\\R^d.\n  \\end{gather}\n  Then, there holds\n  \\begin{xalignat}2\n    \\label{eq:darcy:14}\n    a(u,v) & \\le \\norm a \\norm{u}_V \\norm{v}_V\n    & \\forall u,v&\\in V\\\\\n    \\label{eq:darcy:15}\n    a(u,u) & \\ge \\ellipa \\norm{u}_V^2\n    & \\forall u &\\in \\ker B.\n  \\end{xalignat}\n\\end{Lemma}\n\n\\begin{remark}\n  Differing from the Stokes problem, ellipticity of $a(.,.)$ cannot be\n  extended to the whole space $V$. This is going to be the major\n  difference between this chapter and the previous.\n\\end{remark}\n\n\\begin{Lemma}{darcy-infsup}\n  Let $V=\\Hdiv(\\domain)$ and $Q=L^2(\\domain)$ with their norms.  Then,\n  the inf-sup condition\n  \\begin{gather}\n    \\inf_{q\\in Q} \\sup_{v\\in V} \\frac{b(v,q)}{\\norm{v}_V\\norm{q}_Q}\n    \\ge \\beta\n  \\end{gather}\n  holds with a constant $\\beta$ depending on the domain.\n\\end{Lemma}\n\n\\begin{proof}\n  We can use the construction leading to\n  \\slideref{Corollary}{stokes-iso}. In fact, since the norm of $\\Hdiv$\n  is weaker than the one of $H^1$, the same function $v$ can be chosen\n  in the Stokes inf-sup condition~\\eqref{eq:stokes:1}, yielding a\n  constant $\\beta$ not worse than for Stokes.\n\\end{proof}\n\nCombining these lemmas yields the assumptions of\n\\slideref{Theorem}{infsup-mixed2}. Thus, we have proven:\n\n\\begin{Theorem}{darcy-well-posed}\n  Under the assumptions on \\slideref{Lemma}{darcy-reduced-wellposed},\n  the \\putindex{dual mixed formulation} is well-posed.\n\\end{Theorem}\n\n\\section{Discretization of dual mixed problems}\n\n\\subsection{Conforming subspaces of $\\Hdiv(\\domain)$}\n\n\\begin{intro}\n  Our goal in this section is the derivation of general criteria\n  applying to the approximation of $\\Hdiv(\\domain)$ by piecewise\n  polynomial functions. This affects in particular continuity\n  conditions and the properties of $\\ker{B_h}$.\n\n  As be before, we will assume that all families of meshes $\\mesh_h$\n  for $h\\to 0$ are shape-regular. We will also assume that meshes are\n  regular, unless otherwise stated.\n\\end{intro}\n\n\\begin{Lemma}{normal-continuity}\n  Let $\\mesh_h$ be a subdivision of the domain $\\domain$. Let the\n  space $V_h$ be cell-wise polynomial. We have $V_h \\subset\n  \\Hdiv(\\domain)$ if and only if on each interior face $\\face$\n  between two cells $\\cell_1$ and $\\cell_2$ holds\n  \\begin{gather}\n    v_1 \\cdot \\n_1 + v_2 \\cdot\\n_2 = 0.\n  \\end{gather}\n  Here, $v_1$ and $v_2$ are the traces of the functions on $\\face$\n  from each cell.\n\\end{Lemma}\n\n\\begin{proof}\n  Since $V_h$ is by definition finite dimensional, all norms are\n  bounded. It remains to show that the distributional divergence is\n  in $L^2(\\domain)$, that is, all its contributions which are Borel\n  measures of faces vanish. To this end, let $\\phi\\in\n  C^\\infty_{00}(\\domain)$ be a test function such that its support\n  does not have a nonempty intersection with any face except\n  $\\face$. Then, we have by Green's formula for $u\\in V_h$\n  \\begin{gather*}\n    \\form(\\div u,\\phi) = -\\form(u,\\nabla \\phi)\n    + \\forme(u_1 \\cdot \\n_1 + u_2 \\cdot\\n_2, \\phi)_F\n  \\end{gather*}\n  We have $\\div u \\in L^2(\\domain)$ if and only if the face term\n  vanishes.\n\\end{proof}\n\n\\begin{Problem}{h1-continuity}\n  Show that the corresponding condition for $H^1$-conforming finite elements\n  is continuity of the function. In particular, this implies continuity at\n  vertices.\n\\begin{solution}\n  Let $\\phi\\in (C^\\infty_{00}(\\domain))^d$ be a test function such that its support\n  does not have a nonempty intersection with any face except\n  $\\face$. Then, we have by Green's formula for $u\\in V_h$\n  \\begin{gather*}\n    \\form(\\nabla u,\\phi) = -\\form(u,\\nabla \\cdot \\phi)\n    + \\forme(u_1 - u_2,n_1 \\cdot \\phi)_F\n  \\end{gather*}\n  and thus require $\\forme(u_1 - u_2, \\phi)_F = 0$ for all $\\phi\\in C^\\infty_{00}(\\domain)$.\n  This implies $u_1=u_2$ and in particular continuity at the vertices.\n\\end{solution}\n\\end{Problem}\n\n\\begin{remark}\n  The continuity of the normal component over faces does not imply\n  continuity at vertices, since it is not transferred in tangential\n  direction.\n\n  As a consequence of this remark, part of the construction of\n  $\\Hdiv$-conforming finite element spaces consists of defining a\n  polynomial trace space on each face, such that continuity of normal\n  traces can be established by this space.\n\\end{remark}\n\n\\begin{intro}\n  In \\slideref{Lemma}{darcy-reduced-wellposed}, we saw that the\n  bilinear form $a(.,.)$ is elliptic only on the kernel of\n  $B$. Indeed, for the simplest case with $K\\equiv 1$, we conclude\n  that the uniform estimate for $v_h\\in \\ker{B_h}$\n  \\begin{gather*}\n    \\norm{v_h}^2_{L^2}\n    \\ge \\ellipa \\norm{v_h}^2_{\\Hdiv}\n    = \\ellipa \\bigl(\\norm{v_h}^2_{L^2} + \\norm{\\div v_h}^2_{L^2}\\bigr),\n  \\end{gather*}\n  necessary for quasi-bestapproximation requires a constant $c$\n  independent of $h$ such that\n  \\begin{gather*}\n    \\norm{\\div v_h}^2_{L^2} \\le c \\norm{v_h}^2_{L^2}\n    \\qquad\\forall v_h\\in\\ker{B_h}.\n  \\end{gather*}\n  The inverse estimate is insufficient by two powers of $h$, such that\n  this is actually a hard condition. Therefore, we focus on\n  methods where\n  \\begin{gather}\n    \\label{eq:darcy:16}\n    \\ker{B_h} \\subset \\ker B.\n  \\end{gather}\n\\end{intro}\n\n\\begin{remark}\n  A particularly elegant way to achieve~\\eqref{eq:darcy:16} is the\n  choice\n  \\begin{gather}\n    \\label{eq:darcy:17}\n    \\div V_h = Q_h.\n  \\end{gather}\n  We will indeed focus on methods with this property.\n\\end{remark}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Finite elements on simplices}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{intro}\n  Simplicial elements based on the polynomial spaces $\\P_k$ of\n  polynomials of total degree less or equal $k$ can be defined on the\n  actual mesh cell. We present here the two most common families.\n\\end{intro}\n\n\\begin{Definition}{rt-simplex}\n  The \\define{Raviart-Thomas element} of degree $k \\ge 0$ on simplices\n  consists of the polynomial space\n  \\begin{gather}\n    \\label{eq:darcy:18}\n    RT_k = \\P_k^d + x\\P_k.\n  \\end{gather}\n  Its \\putindex{node functionals} are\n  \\begin{xalignat}3\n    \\label{eq:darcy:19}\n    \\nodal_{1,i,j}(v) &= \\int_{\\face_i} v\\cdot\\n \\,q_j\\ds\n    & q_j&\\in \\P_k(\\face_i)\n    & \\face_i &\\subset \\d\\cell, \\\\\n    \\label{eq:darcy:20}\n    \\nodal_{2,i}(v) &= \\int_\\cell v\\cdot w_i \\dx\n    & w_i &\\in \\P_{k-1}^d(\\cell).\n  \\end{xalignat}\n  Here, and in further definitions of this kind, the notation $q_j$\n  and $w_i$ indicate that we choose a basis for the polynomial spaces.\n\\end{Definition}\n\n\\begin{remark}\n  In equation~\\eqref{eq:darcy:19}, the $\\face_i$ are all faces of the\n  simplex, that is, three edges in two dimensions and four triangular\n  faces in three dimensions.\n\n  If the simplex $\\cell$ is obtained by affine transformation from the\n  reference simplex $\\refcell$, the definitions of the space $RT_k$\n  directly on the cell $\\cell$ and by mapping from $\\refcell$\n  coincide. Therefore, we can use arguments by mapping or without at\n  our convenience.\n\n  For $k=0$ there are no nodal values of type $\\nodal_{2,i}$ since all\n  gradients of functions in $\\P_0$ are zero.\n\n  The unisolvence will be shown in\n  \\slideref{Lemma}{rt-simplex-unisolvence}. But first, we have to look\n  at some important properties.\n\\end{remark}\n\n\\begin{Example}{rt-simplex}\n  The first members of the Raviart-Thomas family on triangles are\n  \\begin{center}\n    \\begin{tabular}{c@{\\hspace{.05\\textwidth}}c@{\\hspace{.05\\textwidth}}c}\n      \\includegraphics[width=.25\\textwidth]{./fig/rt0-tri.tikz}\n      &\n      \\includegraphics[width=.25\\textwidth]{./fig/rt1-tri.tikz}\n      &\n      \\includegraphics[width=.25\\textwidth]{./fig/rt2-tri.tikz}\n      \\\\[5mm]\n      \\includegraphics[width=.25\\textwidth]{./fig/p0-p.tikz}\n      &\n      \\includegraphics[width=.25\\textwidth]{./fig/dgp1-p-tri.tikz}\n      &\n      \\includegraphics[width=.25\\textwidth]{./fig/dgp2-p-tri.tikz}\n    \\end{tabular}\n  \\end{center}\n\\end{Example}\n\n\\begin{Lemma}{rt-simplex-1}\n  For any simplex $\\cell\\in\\R^d$ we have for\n  any $v\\in RT_k$ and any $\\face\\subset\\d\\cell$\n  \\begin{align}\n    \\label{eq:darcy:21}\n    \\div v &\\in \\P_k(\\cell), \\\\\n    \\label{eq:darcy:26}\n    v\\cdot\\n_{|\\face} &\\in \\P_k(\\face).\n  \\end{align}\n  The divergence operator is surjective from $RT_k$ to\n  $\\P_k$, hence\n  \\begin{gather}\n    \\label{eq:darcy:22}\n    \\div RT_k = \\P_k.\n  \\end{gather}\n  For the divergence free functions holds\n  \\begin{gather}\n    \\label{eq:darcy:24}\n    RT_{k,0} = \\bigl\\{v\\in RT_k \\big\\vert\n    \\div  v=0\\bigr\\} \\subset \\P_k^d.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  We write an arbitrary element $v\\in RT_k$ as $v=v_0+x p_k$ where\n  $v_0\\in \\P_k^d$ and $p_k\\in \\P_k$. Clearly, $\\div v_0 \\in\n  \\P_{k-1}$. On the other hand,\n  \\begin{gather*}\n    \\div (x p_k) = \\div x p_k + x\\nabla p_k = d p_k + x q,\n  \\end{gather*}\n  where $q\\in \\P_{k-1}^d$. Therefore, $\\div(x p_k) \\in \\P_k$ and so is\n  $\\div v$.\n\n  For a given face $\\face$, choose $x_0\\in\\face$. Every other point\n  $x\\in \\F$ can be represented as $x=x_0+ \\tau$, where $\\tau$ is a\n  vector tangential to $\\face$. Therefore, using the same splitting of\n  $v$ as above\n  \\begin{gather*}\n    v\\cdot\\n = v_0\\cdot\\n + p_k (x\\cdot\\n)\n    = v_0\\cdot\\n + p_k (x_0\\cdot\\n + \\tau\\cdot\\n).\n  \\end{gather*}\n  The last term vanishes by definition of $\\tau$ and $\\n$ and the two\n  other terms are both in $\\P_k$.\n\n  Finally, we show surjectivity of the divergence operator. We show\n  indeed that the divergence is surjective from\n  $\\tilde V = (x-x_c)\\P_k$ to $\\P_k$, where $x_c$ is the center of\n  $\\cell$. Note that $x_c\\P_k\\in \\P_k^d$ such that\n  $\\tilde V\\subset RT_k$. Furthermore, $\\tilde V$ and $\\P_k$ have the\n  same dimension. Therefore, it is sufficient to show that the\n  divergence is injective. For simplicity, we assume $x_c=0$. Then,\n  for any $p\\in \\P_k$\n  \\begin{align*}\n    \\int_\\cell \\div (x p)p \\dx\n    &= d \\int_\\cell p^2\\dx + \\int_\\cell x \\cdot\\nabla p p\\dx\n    \\\\\n    &= d \\int_\\cell p^2 + \\frac12 \\int_\\cell x \\cdot\\nabla(p^2)\\dx\n    \\\\\n    &= \\frac d2 \\int_\\cell p^2 + \\frac12 \\int_{\\d\\cell} (x\\cdot\\n) p^2\\ds.\n  \\end{align*}\n  Thus, $\\div(x p) = 0$ implies $p=0$ and thus $x p=0$, which proves the\n  injectivity. Using the same idea, we see that $\\div v=0$ for\n  $v=v_0+x p$ implies $x p=0$ and thus $v=v_0\\in\\P_k^d$.\n\\end{proof}\n\n\\begin{Lemma}{rt-simplex-dimension}\n  There for the simplicial Raviart-Thomas element in $\\R^d$ there\n  holds\n  \\begin{gather}\n    \\label{eq:darcy:25}\n    \\begin{split}\n      \\dim RT_k &= (d+1)\\dim\\P_k - \\dim \\P_{k-1}\n      \\\\\n      &= (d^2+k d+d)\\frac{(k+d-1)!}{d!k!}.\n    \\end{split}\n  \\end{gather}\n  In particular,\n  \\begin{gather}\n    \\label{eq:darcy:23}\n    \\dim RT_k =\n    \\begin{cases}\n      (k+1)(k+3) & d=2,\n      \\\\\n      \\tfrac12 (k+1)(k+2)(k+4) & d=3.\n    \\end{cases}\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  First, we observe that\n  \\begin{gather*}\n    RT_k = \\P_k^d \\oplus x\\breve\\P_k,\n  \\end{gather*}\n  where $\\breve \\P_k$ is the space of \\putindex{homogeneous\n    polynomials} of degree $k$, that is, those strictly of degree\n  $k$. There also holds\n  \\begin{gather*}\n    \\P_{k} = \\P_{k-1} \\oplus \\breve \\P_k.\n  \\end{gather*}\n  Hence,\n  \\begin{gather*}\n    \\dim RT_k = d \\dim \\P_k + \\dim\\breve\\P_k = d \\dim \\P_k + \\dim \\P_k\n    - \\dim \\P_{k-1},\n  \\end{gather*}\n  which proves the general formula. Using\n  \\begin{gather}\n    \\dim\\P_k\n    =\\frac1{d!} \\frac{(k+d)!}{k!}\n    =\n    \\begin{cases}\n      \\frac{(k+1)(k+2)}{2} & d=2,\\\\\n      \\frac{(k+1)(k+2)(k+3)}{6} & d=3,\n    \\end{cases}\n  \\end{gather}\n  proves the explicit formulas.\n\\end{proof}\n\n\\begin{Lemma}{rt-simplex-unisolvence}\n  The Raviart-Thomas element with the nodal values in\n  \\slideref{Definition}{rt-simplex} is unisolvent.\n\\end{Lemma}\n\n\\begin{proof}\n  As usual, the proof consists of two parts: first, we prove that the\n  number of node functionals equals the dimension of $RT_k$. To this\n  end, we observe that\n  \\begin{gather}\n    \\label{eq:darcy:32}\n    \\dim \\P_k(\\R^d) = \\frac1{d!} \\frac{(k+d)!}{k!}\n%    = \\frac{k+d}d \\frac1{(d-1)!} \\frac{(k+d-1)!}{k!}\n    = \\frac{k+d}d \\dim \\P_k(\\R^{d-1}).\n  \\end{gather}\n  The number of node functionals is\n  \\begin{align*}\n    N &= (d+1) \\dim \\P_k(\\R^{d-1}) + d \\dim \\P_{k-1}(\\R^d)\n    \\\\\n    &= (d+1)\\frac{(k+d-1)!}{(d-1)!k!}\n      + d\\frac{(k+d-1)!}{d! (k-1)!}\\\\\n    &= (d^2+d+k d)\\frac{(k+d-1)!}{d!k!}\n  \\end{align*}\n  Thus, the number of node functionals is equal to the dimension of\n  $RT_k$. Therefore, every element in $RT_k$ is uniquely determined\n  by the node functionals if and only if for $v\\in RT_k$\n  \\begin{gather*}\n    \\left\\{\n      \\begin{array}{r@{\\,}ll}\n        \\nodal_{1,i,j}(v) &=0 &\\forall i,j\n        \\\\\n        \\nodal_{2,i}(v) &=0 &\\forall i\n      \\end{array}\n      \\right\\}\n      \\quad\\Longrightarrow\\quad\n      v=0.\n  \\end{gather*}\n  To this end, we first observe that due to~\\eqref{eq:darcy:26} the\n  node functionals $\\nodal_{1,i,j}$ for $j=1,\\dots,\\dim \\P_k(\\face_i)$\n uniquely determine $v$ on each face $\\face_i$. Therefore,\n \\begin{gather*}\n   \\bigl\\{\\nodal_{1,i,j}(v) =0 \\quad\\forall i,j\\bigr\\}\n   \\quad\\Longrightarrow\\quad\n   v\\in \\Hdiv_0(\\cell).\n \\end{gather*}\n Next, we test~\\eqref{eq:darcy:20} with $w=\\nabla q$ and $q\\in\n \\P_k$ arbitrary. After integration by parts, this implies $v\\in\n RT_{k,0} \\cap \\Hdiv_0(\\cell) \\subset \\P_k^d$.\n\n For the remaining part of the proof, we need a result which will be\n presented later in full generality. At this point, we only mention\n that in two dimensions, the space $V_0$ of divergence free functions\n in $L^2(\\cell)$ has the representation\n \\begin{gather}\n   \\label{eq:darcy:34}\n   V_0 = \\left\\{ \\vcurl \\phi\n     \\big\\vert \\; \\phi\\in H^1(\\cell) \\right\\},\n   \\qquad\n   \\vcurl \\phi = \\begin{pmatrix}\n     \\d_2 \\phi \\\\ -\\d_1 \\phi\n   \\end{pmatrix}\n \\end{gather}\n\n We also notice that $v\\cdot n = \\d_{\\tau} \\phi$, where $\\tau$ is the\n tangential vector with the domain $\\cell$ on the right. Thus,\n $v\\in \\Hdiv_0(\\cell)$ implies $\\phi$ is constant on the\n boundary. Since moreover we only use derivatives of $\\phi$, we can\n choose $\\phi \\in H^1_0(\\cell)$. Finally, since $v\\in RT_{k,0}$, we\n have $\\phi\\in\\P_{k+1}$. Any function $\\phi$ with these properties can\n be expressed by the cubic bubble function as\n \\begin{gather*}\n   \\phi = b_\\cell \\psi \\qquad\\psi\\in \\P_{k-2}.\n \\end{gather*}\nWe conclude the proof with\n\\begin{gather*}\n  0 = \\int_\\cell v\\cdot w \\dx = \\int_\\cell\n  \\curl\\phi \\cdot w\\dx\n  = \\int_\\cell b_\\cell \\psi (\\d_2 w - \\d_1 w)\\dx.\n\\end{gather*}\nChoose $w$ such that $\\d_2 w-\\d_1 w = \\psi$ to obtain $\\psi=0$.\n\\end{proof}\n\n\\begin{Definition}{bdm-simplex}\n  The \\define{BDM element} (Brezzi-Douglas-Marini) of degree $k \\ge 1$\n  on simplices consists of the polynomial space\n  \\begin{gather}\n    \\label{eq:darcy:27}\n    BDM_k = \\P_k^d.\n  \\end{gather}\n  Its \\putindex{node functionals} are\n  \\begin{xalignat}3\n    \\label{eq:darcy:28}\n    \\nodal_{1,i,j}(v) &= \\int_{\\face_i} v\\cdot\\n \\,q_j\\ds\n    & q_j&\\in \\P_k(\\face_i)\n    & \\face_i &\\subset \\d\\cell,\n    \\\\\n    \\label{eq:darcy:29}\n    \\nodal_{2,i}(v) &= \\int_\\cell v\\cdot \\nabla q_i \\dx\n    & q_i &\\in \\P_{k-1}(\\cell).\n    \\\\\n    \\label{eq:darcy:30}\n    \\nodal_{3,i}(v) &= \\int_\\cell v\\cdot w_i \\dx\n    & w_i &\\in V_{k,0}(\\cell),\n  \\end{xalignat}\n  where\n  \\begin{gather}\n    \\label{eq:darcy:31}\n    V_{k,0}(\\cell) = \\bigl\\{\n    v\\in \\P_k^d(\\cell)\\cap \\Hdiv_0(\\cell) \\big\\vert\n    \\;\\div v=0 \\bigr\\}.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Example}{bdm-simplex}\n  The first members of the BDM family on triangles are\n  \\begin{center}\n    \\begin{tabular}{c@{\\hspace{.2\\textwidth}}c}\n      \\includegraphics[width=.25\\textwidth]{./fig/bdm1-tri.tikz}\n      &\n      \\includegraphics[width=.25\\textwidth]{./fig/bdm2-tri.tikz}\n      \\\\[5mm]\n      \\includegraphics[width=.25\\textwidth]{./fig/p0-p.tikz}\n      &\n      \\includegraphics[width=.25\\textwidth]{./fig/dgp1-p-tri.tikz}\n    \\end{tabular}\n  \\end{center}\n\\end{Example}\n\n\\begin{Lemma}{bdm-simplex-unisolvence}\n  The BDM element with the nodal values in\n  \\slideref{Definition}{bdm-simplex} is unisolvent.\n\\end{Lemma}\n\n\\begin{proof}\n  % Again, we begin by counting the shape functions, which,\n  % using~\\eqref{eq:darcy:32} yields\n  % \\begin{gather}\n  %   \\label{eq:darcy:33}\n  %   \\dim BDM_k(\\cell) = d\\dim \\P_k(\\R^d)\n  %   = \\frac1{(d-1)!} \\frac{(k+d)!}{k!}.\n  % \\end{gather}\n  Let $v\\in BDM_k(\\cell)$.\n  First, we note that $\\div BDM_k \\subset \\P_{k-1}$. Therefore,\n  setting the\n  node functionals in~\\eqref{eq:darcy:28} and~\\eqref{eq:darcy:29} to\n  zero implies $v\\in V_{0,k}$. But then, the remaining node\n  functionals are an inner product on $V_{0,k}$ and thus $v=0$.\n\\end{proof}\n\n\\begin{remark}\n  What is missing here is a characterization of the space\n  $V_{0,k}$. Thus, we cannot really implement the method\n  yet. Furthermore, we cannot verify that the node functionals form a\n  dual basis for $BDM_k(\\cell)$. The answer to these questions will be\n  given in Chapter~\\ref{cha:derham}.\n\\end{remark}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Stability by commuting diagrams}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{intro}\n  Again, we show stability by constructing a \\putindex{Fortin\n    projection}. To this end, we show that the nodal interpolation of\n  the Raviart-Thomas and BDM families indeed commute with the\n  divergence operator. We first show that this holds for smooth\n  functions and then discuss the extension to functions in\n  $\\Hdiv(\\domain)$.\n\\end{intro}\n\n\\begin{Definition}{canonical-interpolation}\n  Let a finite element be defined by its shape function space\n  $\\mathcal P_\\cell$ and the \\putindex{node functionals} $\\nodal_i$\n  for $i=1,\\dots,n$ where $n=\\dim\\mathcal P_\\cell$. Let $\\{\\phi_j\\}$\n  be the basis of $\\mathcal P_\\cell$ such that\n  \\begin{gather*}\n    \\nodal_i(\\phi_j) = \\delta_{ij}\n    \\qquad i,j=1,\\dots,n.\n  \\end{gather*}\n  Then, the operator $I_h\\colon C^\\infty(\\cell)\\to \\mathcal P_\\cell$\n  defined for any $f\\in C^\\infty(\\cell)$ by\n  \\begin{gather}\n    I_h(f) = \\sum_{i=1}^n \\nodal_i(f) \\phi_i,\n  \\end{gather}\n  is called the \\define{canonical interpolation} operator. The\n  definition applies to vector valued elements replacing\n  $C^\\infty(\\cell)$ by $C^\\infty(\\cell;\\R^d)$.\n\\end{Definition}\n\n\\begin{remark}\n  For a vector polynomial space $\\mathcal V_\\cell$, we define its\n  divergence space\n  \\begin{gather*}\n    \\mathcal P_\\cell = \\div \\mathcal V_\\cell.\n  \\end{gather*}\n  From \\slideref{Lemma}{rt-simplex-1}, we obtain\n  \\begin{gather}\n    \\label{eq:darcy:37}\n    \\div RT_k = \\P_k.\n  \\end{gather}\n  For the BDM family, it is easy to verify\n  \\begin{gather*}\n    \\div BDM_k = \\P_{k-1}.\n  \\end{gather*}\n\\end{remark}\n\n\\begin{Lemma}{commuting-diagram-hdiv}\n  Let $I_h\\colon C^\\infty(\\cell;\\R^d)\\to \\mathcal V_\\cell$ be the\n  canonical interpolation onto the space $\\mathcal V_\\cell$, which is\n  either $RT_k(\\cell)$ or $BDM_{k+1}(\\cell)$. Let $\\mathcal P_\\cell = \\div\n  \\mathcal V_\\cell = \\P_k$ and $\\Pi_h\\colon C^\\infty(\\cell)\\to \\mathcal\n  P_\\cell$ be the $L^2$-projection onto $\\mathcal P_\\cell$. Then, the\n  diagram\n  \\begin{gather}\n    \\label{eq:darcy:35}\n    \\begin{CD}\n      C^\\infty(\\cell;\\R^d) @>\\div>> C^\\infty(\\cell) \\\\\n      @V{I_h}VV @VV{\\Pi_h}V\\\\\n      \\mathcal V_\\cell @>\\div>> \\mathcal P_\\cell\n    \\end{CD}\n  \\end{gather}\n  commutes, that is, for any $v\\in C^\\infty(\\cell;\\R^d)$, there holds\n  \\begin{gather}\n    \\label{eq:darcy:36}\n    \\div (I_h v) = \\Pi_h(\\div v).\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  Let $v\\in C^\\infty(\\cell;\\R^d)$ and $q\\in C^\\infty(\\domain)$ be\n  chosen arbitrarily. Then,\n  \\begin{gather*}\n    \\int_\\cell q(\\div (I_h v) - \\div v)\\dx\n    = \\int_\\cell(v-I_h v) \\cdot \\nabla q\\dx\n    - \\int_{\\d\\cell} (v-I_h v)\\cdot\\n q \\ds\n  \\end{gather*}\n  Let now $q\\in \\mathcal P_\\cell$ chosen as\n  \\begin{gather*}\n    q = \\Pi_h (\\div (I_h v) - \\div v).\n  \\end{gather*}\n  Then, the left hand side of the equation above becomes\n  $\\norm{\\div(I_h v) - \\Pi_h(\\div v)}_\\cell^2$. The first integral on\n  the right vanishes by testing~\\eqref{eq:darcy:20} with\n  $\\nabla q$ and by testing~\\eqref{eq:darcy:29} with $q$,\n  respectively.\n  The same holds for the second integral using the node values in\n  equations~\\eqref{eq:darcy:19} and~\\eqref{eq:darcy:28},\n  respectively. Thus, we have proven $\\div (I_h v) = \\Pi_h(\\div v)$.\n\\end{proof}\n\n\\begin{remark}\n  The next natural step is the extension of $I_h$ to\n  $\\Hdiv(\\domain)$. Then, $I_h$ would be our Fortin\n  projection. Unfortunately, this is not possible, as the following\n  example shows. Meanwhile, we note that the operator $I_h$ is\n  well-defined on the space $\\tilde V=\\Hdiv(\\domain) \\cap H^s(\\domain;\\R^d)$\n  for any $s>0$. Thus, if the domain allows for an inf-sup condition\n  of the form\n  \\begin{gather*}\n    \\inf_{q\\in Q}\\sup_{v\\in \\tilde V} \\frac{(\\div\n      v,q)}{\\norm{v}_{\\tilde V}\\norm{q}_Q} \\ge \\beta > 0,\n  \\end{gather*}\n  then we are done here. The case of minimal regularity will require\n  us to extend the ideas of the Clément interpolant to commuting\n  interpolation operators, which will be done in\n  Chapter~\\ref{cha:derham}.\n\\end{remark}\n\n\\begin{example}\n  The trace theorem involves the space $H^{-1/2}(\\d\\domain)$, which\n  requires a short discussion. On one dimensional boundaries, elements\n  in $H^{1/2}(\\d\\domain)$ have continuous representatives. The\n  situation in three dimensions is similar, where no jumps across a\n  line, for instance between two faces is allowed. Therefore,\n  functions in $H^{-1/2}(\\d\\domain)$ cannot be localized to parts of\n  the boundary, for instance the edge of a cell.\n\n  We give an example (modified from \\cite[Section\n  2.5.1]{BoffiBrezziFortin13}) of this phenomenon.  On the disc\n  $\\mathcal D$ around the origin of radius $e^{-1}$ consider the\n  function\n  \\begin{gather*}\n    u(x,y) = \\ln\\Bigl(-\\ln\\bigl(\\sqrt{x^2+y^2}\\bigr)\\Bigr).\n  \\end{gather*}\n  There holds $u\\in H^1_0(\\mathcal D)$. Now, consider the domain\n  $\\domain$ consisting only of the upper half circle:\n  \\begin{align*}\n    \\domain &= \\bigl\\{(x,y)\\in \\R^2 \\big\\vert\n              x^2+y^2<e^{-2} \\text{ and } y>0 \\bigr\\}\n    \\\\\n    \\d\\domain &= [-e^{-1},e^{-1}] \\times \\{0\\}\n                \\cup \\bigl\\{ (x,\\sqrt{e^{-2}-x^2}) \\big\\vert\n                x\\in (-e^{-1},e^{-1}) \\bigr\\}\n  \\end{align*}\n  Thus, the trace of $u$ on the boundary is in\n  $H^{1/2}(\\d\\domain)$. We now define $\\mu\\in H^{-1/2}(\\d\\domain)$ as\n  the distributional derivative in tangential direction, say\n  counter-clockwise,\n  \\begin{gather*}\n    \\scal(\\mu,\\phi) = - \\int_{\\d\\domain} u \\d_{\\tau} \\phi\n    \\qquad\\forall \\phi\\in C^1(\\d\\domain).\n  \\end{gather*}\n\n  Computation yields\n  \\begin{gather*}\n    \\mu(x) = \\frac1{x\\ln \\abs{x}} \\times\n    \\begin{cases}\n      1 & x\\in (-e^{-1},0) \\\\\n      -1& x\\in (0,e^{-1})\\\\\n       0& x\\not\\in (-e^{-1},e^{-1}).\n    \\end{cases}\n  \\end{gather*}\n  Both integrals\n  \\begin{gather*}\n    \\int_{-e^{-1}}^0 \\mu(x)\\dx\n    \\qquad\n    \\int^{e^{-1}}_0 \\mu(x)\\dx,\n  \\end{gather*}\n  are not bounded, such that on these parts of the boundary, $\\mu$\n  cannot even be tested with a constant function.\n  Now, we consider the integral\n  \\begin{gather*}\n    \\forme(\\mu,\\phi) = \\int_{-e^{-1}}^{e^{-1}} \\ln(-\\ln\\abs x) \\d_\\tau \\phi \\dx.\n  \\end{gather*}\n  If we split $\\phi$ into an odd and an even part, the integral with\n  the even part vanishes, since $\\ln(-\\ln\\abs x)$ is even and the\n  derivative is odd. Therefore,\n  \\begin{gather*}\n    \\forme(\\mu,\\phi)\n    = \\int_{-e^{-1}}^{e^{-1}}\n    \\frac{\\phi_{\\text{odd}}(x)}{x\\ln\\abs x} \\dx\n  \\end{gather*}\n  Finally, we use the fact that $\\phi_{\\text{odd}}(0) = 0$ and that\n  it's growth is limited by its regularity. In order to be square\n  integrable, the growth of $\\phi_{\\text{odd}}$ must be limited by a\n  positive, fractional power,\n  \\begin{gather*}\n    \\abs{\\phi_{\\text{odd}}(x)} \\le c \\abs x^\\alpha,\n    \\qquad \\alpha>0.\n  \\end{gather*}\n  Then,\n  \\begin{gather*}\n    \\int_0^{e^{-1}} \\frac{\\abs{\\phi_{\\text{odd}}(x)}}{x\\ln\\abs x} \\dx\n    \\le \\frac{x^{\\alpha-1}}{\\ln\\abs x} \\dx < \\infty.\n  \\end{gather*}\n\\end{example}\n\n\\begin{intro}\n  Very much like the construction of Clément for $H^1(\\domain)$, we\n  define interpolation operators stable on $\\Hdiv(\\domain)$ by\n  replacing the face integrals by volume integrals. We only have to\n  make sure we do not destroy conformity with $\\Hdiv(\\domain)$, in\n  particular continuity of normal components. But, this can be\n  achieved by integrating over both cells adjacent to a face and using\n  this integral for interpolation.\n\\end{intro}\n\n\\begin{Definition}{hdiv-clement}\n  An $\\Hdiv$-stable interpolation operator is obtained from\n  \\slideref{Definition}{canonical-interpolation} of the\n  \\putindex{canonical interpolation}\n  \\begin{enumerate}\n  \\item by choosing the standard degrees of freedom for every cell\n    integral as in~\\eqref{eq:darcy:20}, ~\\eqref{eq:darcy:29},\n    and~\\eqref{eq:darcy:30}, and\n  \\item by replacing every face integral as in~\\eqref{eq:darcy:19}\n    and~\\eqref{eq:darcy:28} by integrals of the form\n    \\begin{gather}\n      \\int_{\\face} f\\cdot\\n \\,q \\ds\n      \\to\n      c_q \\int_{\\domain_\\face} f\\cdot \\n \\,q \\dx,\n    \\end{gather}\n    where $\\domain_\\face$ consists of the cells sharing $\\face$ and\n    $c_q$ is a normalization constant.\n  \\end{enumerate}\n\\end{Definition}\n\nSummarizing the results from this section and applying the general\ntheory, in particular \\slideref{Corollary}{galerkin-mixed-u-kerb} and\n\\slideref{Theorem}{galerkin-mixed-p}, we obtain\n\n\\begin{Theorem}{darcy-quasi-best}\n  Let $V_h\\subset V\\subset \\Hdiv(\\domain)$ and $Q_h\\subset Q$ be\n  chosen such that an $\\Hdiv$-stable commuting interpolation operator\n  exists. Then, the solutions $(u,p) \\in V\\times Q$ and\n  $(u_h,p_h) \\in V_h\\times Q_h$ admit the \\putindex{quasi-optimality}\n  estimates\n  \\begin{align}\n    \\norm{u-u_h}_{\\Hdiv} & \\le c_1 \\inf_{v\\in V_h} \\norm{u-v_h}_{\\Hdiv} \\\\\n    \\norm{p-p_h}_{L^2} & \\le c_2 \\inf_{v\\in V_h} \\norm{u-v_h}_{\\Hdiv}\n                         + c_3 \\inf_{q\\in Q_h} \\norm{p-q_h}_{L^2}.\n  \\end{align}\n\\end{Theorem}\n\n\\begin{Corollary}{darcy-convergence}\n  The elements $RT_k$ and $BDM_{k+1}$ with their matching pressure\n  space $\\P_k$ admit the error estimates\n  \\begin{align}\n    \\norm{u-u_h}_{L^2} &\\le c h^{k+1} \\snorm{u}_{H^{k+1,\\text{div}}} \\\\\n    \\norm{\\div u-\\div u_h}_{L^2} &\\le c h^{k+1} \\snorm{u}_{H^{k+1,\\text{div}}} \\\\\n    \\norm{p-p_h}_{L^2} &\\le c h^{k+1}\n                         \\bigl(\\snorm{u}_{H^{k+1,\\text{div}}}\n    + \\snorm{p}_{H^{k+1}} \\bigr),\n  \\end{align}\n  where\n  \\begin{gather}\n    \\snorm{u}_{H^{k+1,\\text{div}}}^2 = \\snorm{u}_{H^{k+1}}^2\n    + \\snorm{\\div u}_{H^{k+1}}^2.\n  \\end{gather}\n\\end{Corollary}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Finite elements on quadrilaterals and hexahedra}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{intro}\n  Shape functions for quadrilaterals and hexahedra can only be defined\n  on a reference cell. But, when mapping from a reference cell\n  $\\refcell$ to the actual mesh cell $\\cell$, we have to preserve the\n  information whether a vector field is normal or tangential to a\n  face. To this end, we recapitulate the basic notation and properties\n  of the transformation of scalar fields and then add the definition\n  for vector fields in $\\Hdiv(\\domain)$.\n\\end{intro}\n\n\\begin{Notation}{recap-reference-transform}\n  Let $\\refcell$ be a reference cell, either the reference\n  simplex spanned by $\\{0,e_1,\\dots,e_d\\}$ or the reference hypercube\n  $[-1,1]^d$. Then, a mesh cell $\\cell\\in\\mesh_h$ is defined as the\n  image of $\\widehat \\cell$ under a mapping $\\Phi$ (we suppress the\n  index $\\cell$ and understand that $\\Phi$ is different for every\n  cell). We define the Jacobi matrix, the Jacobi determinant, and the\n  face Jacobian\n  \\begin{gather}\n    \\mathrm D\\Phi(\\widehat x) = \\Bigl(\\d_j\\Phi_i\\Bigr),\n    \\qquad\n    \\mathrm J(\\widehat x) = \\det \\mathrm D\\Phi(\\widehat x),\n    \\qquad\n    \\mathrm J_n(\\widehat x) = J\n    \\abs{\\mathrm D\\Phi^{-T}(\\widehat x) \\widehat\\n},\n  \\end{gather}\n\n The basic relations are for $\\widehat x\\in\\widehat \\cell$ and\n  shape functions $\\widehat p$:\n  \\begin{gather}\n    x = \\Phi(\\widehat x),\n    \\qquad p(x) = \\widehat p(\\widehat x)\n    \\qquad \\nabla p(x) = \\mathrm D\\Phi^{-T}(\\widehat x)\n    \\widehat\\nabla\\widehat p(\\widehat x).\n  \\end{gather}\n  Integrals transform as\n  \\begin{xalignat*}2\n    \\int_\\cell p \\dx &= \\int_{\\refcell} \\widehat p J \\dxref\n    &\n    \\int_{\\d\\cell} p \\ds &= \\int_{\\d\\refcell} \\widehat p J_n \\dsref.\n  \\end{xalignat*}\n\\end{Notation}\n\n\\begin{Definition}{Piola-transform}\n  The \\define{Piola transform} or \\putindex{contravariant}\n    transformation of a vector field under the mapping\n  $\\Phi\\colon\\refcell\\to\\cell$ is the mapping\n  \\begin{gather}\n    v(x) = \\tfrac1{\\mathrm J} \\mathrm D\\Phi \\widehat v(\\widehat x).\n  \\end{gather}\n  There holds\n  \\begin{gather}\n    \\nabla v(x) = \\tfrac1{\\mathrm J} \\mathrm D\\Phi\n    \\bigl[\\widehat\\nabla \\widehat v(\\widehat x)\\bigr] \\mathrm D\\Phi^{-1},\n    \\qquad\n    \\div v(x) = \\tfrac1{\\mathrm J} \\widehat\\nabla\\!\\cdot\\!\n    \\widehat v(\\widehat x).\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Lemma}{Piola-transform-integrals}\n  Let $q$ be a scalar function and $v$ be a \\putindex{contravariant}\n  vector field mapped by the \\putindex{Piola transform}. Then, cell\n  and surface integrals are transformed according to the rules\n  \\begin{gather}\n    \\begin{split}\n      \\int_{\\cell} v \\cdot \\nabla q \\dx\n      &= \\int_{\\refcell} \\widehat v \\cdot \\widehat \\nabla \\widehat q \\dxref,\n      \\\\\n      \\int_{\\cell} q \\div v \\dx\n      &= \\int_{\\refcell} \\widehat q \\widehat \\nabla\\!\\cdot\\! \\widehat v \\dxref,\n      \\\\\n      \\int_{\\d\\cell} q v\\cdot\\n \\ds\n      &= \\int_{\\d\\refcell} \\widehat q \\widehat v\\cdot\\widehat \\n \\dsref.\n    \\end{split}\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Problem}{Piola-transform-integrals}\n  Verify \\slideref{Lemma}{Piola-transform-integrals}.\n\\begin{solution}\n  We use the definitions\n  \\begin{align*}\n    p(x) &= \\widehat p(\\widehat x),&\n    \\nabla p(x) &= \\mathrm D\\Phi^{-T}\n    \\bigl[\\widehat\\nabla\\widehat p(\\widehat x)\\bigr], \\\\\n    v(x) &= \\tfrac1{\\mathrm J} \\mathrm D\\Phi \\widehat v(\\widehat x), &\n    \\nabla v(x) &= \\tfrac1{\\mathrm J} \\mathrm D\\Phi\n    \\bigl[\\widehat\\nabla \\widehat v(\\widehat x)\\bigr] \\mathrm D\\Phi^{-1}, &\n    \\div v(x) &= \\tfrac1{\\mathrm J} \\widehat\\nabla \\cdot\n    \\widehat v(\\widehat x).\n  \\end{align*}\nFor the first claim we compute\n  \\begin{align*}\n    \\int_{\\cell} v \\cdot \\nabla q \\dx\n    &= \\int_{\\refcell}\n       \\tfrac1{\\mathrm J} \\mathrm D\\Phi \\widehat v(\\widehat x) \\cdot\n       \\mathrm D\\Phi^{-T}\\bigl[\\widehat\\nabla\\widehat q(\\widehat x)\\bigr]\n       J \\dxref\n    = \\int_{\\refcell} \\widehat v \\cdot \\widehat \\nabla \\widehat q \\dxref.\n  \\end{align*}\n  For the second we get\n  \\begin{align*}\n    \\int_{\\cell} q \\div v \\dx\n    &= \\int_{\\refcell}\n       \\widehat q(\\widehat x)\n       \\tfrac1{\\mathrm J} \\widehat\\nabla \\cdot \\widehat v(\\widehat x)\n       J \\dxref\n    = \\int_{\\refcell} \\widehat q \\widehat \\nabla\\!\\cdot\\! \\widehat v \\dxref,\n  \\end{align*}\n  Finally, the last equality holds due to\n  \\begin{align*}\n    \\int_{\\d\\cell} q v\\cdot\\n \\ds\n    &= \\int_{\\cell} \\nabla \\cdot(q v) \\dx\n    = \\int_{\\cell} v\\cdot \\nabla q + q\\nabla \\cdot v \\dx \\\\\n    &= \\int_{\\refcell} \\widehat v\\cdot \\widehat \\nabla \\widehat q\n                      + \\widehat q \\widehat \\nabla \\cdot \\widehat v \\dxref\n    = \\int_{\\refcell}\\widehat \\nabla \\cdot(\\widehat q \\widehat v) \\dxref\n    = \\int_{\\d\\refcell} \\widehat q \\widehat v\\cdot\\widehat \\n \\dsref.\n  \\end{align*}\n\n\\end{solution}\n\\end{Problem}\n\n\\begin{remark}\n  The last equation of the previous lemma indicates, that the\n  \\putindex{Piola transform} preserves normal components of a vector\n  field. Thus, it can be used to define shape functions for normal\n  continuity on a reference cell.\n\\end{remark}\n\n\\begin{Notation}{tensor-product-polynomials}\n  The space of \\putindex{tensor product polynomials} $\\Q_k$ in $d$ space\n  dimensions is\n  \\begin{gather}\n    \\label{eq:darcy:39}\n    \\begin{split}\n    \\Q_k(\\R^d) &= \\underbrace{\\P_k(\\R) \\otimes \\dots\\otimes \\P_k(\\R)\n    }_{d\\text{ factors}},\n    \\\\\n    q(x_1,\\dots,x_d) &= \\prod_{i=1}^d p_i(x_i)\n    \\qquad p_i\\in \\P_k(\\R).\n    \\end{split}\n  \\end{gather}\n  Similarly, we define \\putindex{anisotropic tensor product} polynomials\n  \\begin{gather}\n    \\label{eq:darcy:40}\n    \\begin{split}\n    \\Q_{k1,\\dots,k_d}(\\R^d)\n    &= \\underbrace{\\P_{k_1}(\\R) \\otimes \\dots\\otimes \\P_{k_d}(\\R)\n    }_{d\\text{ factors}},\n    \\\\\n    q(x_1,\\dots,x_d) &= \\prod_{i=1}^d p_i(x_i)\n    \\qquad p_i\\in \\P_{k_i}(\\R).\n    \\end{split}\n  \\end{gather}\n\\end{Notation}\n\n\\begin{Definition}{rt-quad}\n  The \\define{Raviart-Thomas element} of degree $k \\ge 0$ on the\n  reference cell $\\refcell = [-1,1]^d$\n  consists of the polynomial space\n  \\begin{gather}\n    \\label{eq:darcy:38}\n    RT_{[k]}(\\refcell) = \\Q_k^d(\\refcell) + x\\Q_k(\\refcell).\n  \\end{gather}\n  Its \\putindex{node functionals} are\n  \\begin{xalignat}2\n    %\\label{eq:darcy:19}\n    \\nodal_{1,i,j}(v) &= \\int_{\\face_i} v\\cdot\\n \\,q_j\\ds\n    & q_j&\\in \\Q_k(\\face_i)\n    \\qquad\\face_i \\subset \\d\\refcell, \\\\\n    %\\label{eq:darcy:20}\n    \\nodal_{2,i}(v) &= \\int_{\\refcell} v\\cdot w_i \\dx\n    & w_i &\\in \\Q_{k-1,k\\ldots k}\\times\\cdots\\times\\Q_{k\\ldots k,k-1}.\n  \\end{xalignat}\n\\end{Definition}\n\n\\begin{Lemma}{rt-quad-1}\n  There holds\n  \\begin{gather}\n    \\dim RT_{[k]} = d(k+1)^{d-1}(k+2),\n  \\end{gather}\n  and\n  \\begin{gather}\n    \\label{eq:darcy:41}\n    \\div RT_{[k]} = \\Q_k.\n  \\end{gather}\n  Furthermore, for each $\\face \\subset\\widehat\\cell$ and each\n  $v\\in RT_{[k]}(\\refcell)$there holds\n  \\begin{gather}\n    \\label{eq:darcy:42}\n    v\\cdot \\n|_{\\face} \\in \\Q_k.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  The proof of this lemma is exactly the same as the one of \\slideref{Lemma}{rt-simplex-1}.\n\\end{proof}\n\n\\begin{Example}{rt-quad}\n  The first members of the Raviart-Thomas family on quadrilaterals are\n  \\begin{center}\n    \\begin{tabular}{c@{\\hspace{.05\\textwidth}}c@{\\hspace{.05\\textwidth}}c}\n      \\includegraphics[width=.22\\textwidth]{./fig/rt0-quad.tikz}\n      &\n      \\includegraphics[width=.22\\textwidth]{./fig/rt1-quad.tikz}\n      &\n      \\includegraphics[width=.22\\textwidth]{./fig/rt2-quad.tikz}\n      \\\\[5mm]\n      \\includegraphics[width=.22\\textwidth]{./fig/q0-p.tikz}\n      &\n      \\includegraphics[width=.22\\textwidth]{./fig/dgq1-p.tikz}\n      &\n      \\includegraphics[width=.22\\textwidth]{./fig/dgq2-p.tikz}\n    \\end{tabular}\n  \\end{center}\n\\end{Example}\n\nThe construction principle of the Raviart-Thomas element on simplices\nas well as on rectangles and cubes can be seen as adding vector\npolynomials to the velocity space until its divergence is equal to\n$\\P_k$ or $\\Q_k$. The principle of the BDM elements is the opposite:\nStarting from the polynomial spaces for triangles, we add divergence\nfree shape functions until we achieve continuity of the normal\ncomponent over all edges. We give their definitions on squares and\ncubes.\n\n\\begin{Definition}{bdm-quad}\n  The \\putindex{BDM element} of degree $k\\ge 1$ on the reference cell\n  $\\refcell = [-1,1]^2$ consists of the polynomial space\n  \\begin{gather}\n    BDM_{[k]} = \\P_k^2 \\oplus\n    \\operatorname{span}\\bigl\\{\\curl(x^{k+1}y),\\curl(x y^{k+1}\\bigr\\}.\n  \\end{gather}\n  Its \\putindex{node functionals} are\n  \\begin{xalignat}2\n    %\\label{eq:darcy:19}\n    \\nodal_{1,i,j}(v) &= \\int_{\\face_i} v\\cdot\\n \\,q_j\\ds\n    & q_j&\\in \\P_k(\\face_i)\n    \\qquad\\face_i \\subset \\d\\refcell, \\\\\n    %\\label{eq:darcy:20}\n    \\nodal_{2,i}(v) &= \\int_{\\refcell} v\\cdot w_i \\dx\n    & w_i &\\in \\P_{k-2}^2.\n  \\end{xalignat}\n\\end{Definition}\n\n\\begin{Example}{bdm-quad}\n  The first members of the Brezzi-Douglas-Marini family on\n  quadrilaterals are\n  \\begin{center}\n    \\begin{tabular}{c@{\\hspace{.05\\textwidth}}c@{\\hspace{.05\\textwidth}}c}\n      \\includegraphics[width=.22\\textwidth]{./fig/bdm1-quad.tikz}\n      &\n      \\includegraphics[width=.22\\textwidth]{./fig/bdm2-quad.tikz}\n      &\n      \\includegraphics[width=.22\\textwidth]{./fig/bdm3-quad.tikz}\n      \\\\[5mm]\n      \\includegraphics[width=.22\\textwidth]{./fig/q0-p.tikz}\n      &\n      \\includegraphics[width=.22\\textwidth]{./fig/q-p1-p.tikz}\n      &\n      \\includegraphics[width=.22\\textwidth]{./fig/q-p2-p.tikz}\n    \\end{tabular}\n  \\end{center}\n\\end{Example}\n\n\\begin{Lemma}{bdm-quad}\n  The dimension of the space $BDM_{[k]}$ is\n  \\begin{gather}\n    \\dim BDM_{[k]} = (k+1)(k+2)+2.\n  \\end{gather}\n  The element in \\slideref{Definition}{bdm-quad} is unisolvent.  \n\\end{Lemma}\n\n\\begin{Problem}{bdm-quad}\n  Prove \\slideref{Lemma}{bdm-quad}.\n\\begin{solution}\n The dimension of the space is by definition\n \\begin{align*}\n    \\dim BDM_{[k]} = d\\binom{k+d}{d}+2=2\\frac{(k+2)(k+1)}{2}+2=(k+1)(k+2)+2.\n \\end{align*}\n The number of functionals is\n \\begin{align*}\n  2^d \\binom{k+d-1}{d-1}+d \\binom{k+d-2}{d} &= 4 \\frac{k+1}{1}+2\\frac{k(k-1)}{2}\n  = 4k+4+k^2-k+4\\\\\n  &= k^2-3k+4 = (k+2)(k+1)+2.\n \\end{align*}\n Now we only have to check the unisolvence, i.e.\n \\begin{align*}\np\\in BDM_{[k]}, \\nodal_* (p) = 0 \\Rightarrow p \\equiv 0.\n\\end{align*}\n An arbitrary element $p\\in BDM_{[k]}$ can be written as\n \\begin{align*}\n  p_1 (x,y) &= a x^{k+1} +b (k+1) x y^k+ q_{k,1}(x,y) \\\\\n  p_2 (x,y) &= -a (k+1) y x^k-b y^{k+1}+ q_{k,2}(x,y)\n \\end{align*}\n where $q_{k,1},q_{k,2}\\in \\mathbb{P}_k$. Now consider the evaluation of the first component for $x=\\pm1$:\n \\begin{align*}\n  p_1 (\\pm1,y) &= a (\\pm1)^{k+1} \\pm b (k+1) y^k+ q_{k,1}(\\pm1,y)\\in \\mathbb{P}_k(e_i)\n \\end{align*}\n and the first condition requires $p_1 (\\pm1,y)\\equiv 0$ which implies $\\pm b(k+1)+c_{0,k}=0$ and hence $b=0$.\n Similarly, evaluating the second component for $y=\\pm1$ gives\n \\begin{align*}\n  p_2 (x,\\pm1) &= \\pm a (k+1) x^k+ q_{k,2}(x,\\pm1)\\in \\mathbb{P}_k(e_i)\n \\end{align*}\n and the first condition requires $p_3 (x,\\pm1)\\equiv 0$ which implies $\\pm a(k+1)+c_{k,0}=0$ and hence $a=0$.\n In combination, the first condition requires $p_1,p_2\\in \\mathbb{P}_k$. Furthermore, the first component vanishes\n at $x=\\pm1$ and the second component at $y=\\pm1$ implying $p_1=(1-x^2) \\hat{p}_1, p_2=(1-y^2) \\hat{p}_2$\n where $\\hat{p}_1, \\hat{p}_2 \\in \\mathbb{P}_{k-2}$. Thus, the second condition implies $p_1, p_2\\equiv 0$.\n\\end{solution}\n\n\\end{Problem}\n\n\\begin{Corollary}{darcy-convergence-affine}\n  Let the mesh be such that each cell is obtained by affine\n  transformation from the reference cell $\\refcell$. Then,\n  \\slideref{Theorem}{darcy-quasi-best} applies and we obtain\n  quasi-bestapproximation.\n\\end{Corollary}\n\n\\begin{remark}\n  If the mapping of the cells is not affine, we do not have\n  \\begin{gather*}\n    \\div V_h = Q_h.\n  \\end{gather*}\n  Indeed, on each cell, we have\n  \\begin{gather}\n    \\div V_h = \\tfrac1{J} Q_h,\n  \\end{gather}\n  where the \\putindex{Jacobi determinant} $J$ is not constant. As a\n  consequence, \\slideref{Lemma}{commuting-diagram-hdiv} about the\n  commuting diagram property does not apply directly anymore and\n  indeed, approximation may\n  suffer~\\cite{ArnoldBoffiFalk05}. In particular, it\n  is shown there that for the $RT_{[k]}$ on general\n  quadrilateral meshes, which do \\emph{not} converge to affine meshes\n  as $h\\to0$, there holds\n  \\begin{align*}\n    \\inf_{v_h\\in V_h}\\norm{u-v_h} &= \\mathcal O(h^{k+1}), \\\\\n    \\inf_{v_h\\in V_h}\\norm{\\div u-\\div v_h} &= \\mathcal O(h^{k}).\n  \\end{align*}\n  The optimal approximation of the divergence can be recovered by\n  enriching the space like the Arnold-Boffi-Falk element below.\n\\end{remark}\n\n\\begin{Definition}{abf-quad}\n  The \\define{Arnold-Boffi-Falk element} of degree $k \\ge 0$ on the\n  reference cell $\\refcell = [-1,1]^2$\n  consists of the polynomial space\n  \\begin{gather}\n    %\\label{eq:darcy:38}\n    ABF_k(\\refcell) = \\Q_{k+2,k}\\times \\Q_{k,k+2}\n  \\end{gather}\n  Its \\putindex{node functionals} are\n  \\begin{xalignat}2\n    %\\label{eq:darcy:19}\n    \\nodal_{1,i,j}(v) &= \\int_{\\face_i} v\\cdot\\n \\,q_j\\ds\n    & q_j&\\in \\Q_k(\\face_i)\n    \\qquad\\face_i \\subset \\d\\refcell, \\\\\n    %\\label{eq:darcy:20}\n    \\nodal_{2,i}(v) &= \\int_{\\refcell} v\\cdot w_i \\dx\n    & w_i &\\in \\Q_{k-1,k}\\times\\cdots\\times\\Q_{k,k-1}, \\\\\n    \\nodal_{3,x,i}(v) &= \\int_{\\refcell} \\div v (x^iy^{k+1})\n    & i&=1,\\dots,k,\\\\\n    \\nodal_{3,y,i}(v) &= \\int_{\\refcell} \\div v (x^{k+1}y^i)\n    & i&=1,\\dots,k.\n  \\end{xalignat}\n\\end{Definition}\n\n\n\\begin{remark}\n  Degrees of freedom in this section have been written as moments with\n  respect to polynomials in $\\P_k$ or $\\Q_k$, which is natural in this\n  context and allows for an easy proof of the commutating diagram\n  property of the \\putindex{Fortin projection}. On the other hand,\n  degrees of freedom based on point interpolation are sometimes more\n  natural for the implementation.\n\n  In one dimension, for instance for the integration over edges, we\n  realize that\n  \\begin{gather*}\n    \\nodal_{1,i,j} (v) = \\int_{\\face} v\\cdot\\n \\,q_j \\ds\n    = \\sum_{\\ell=1}^{k+1} \\omega_\\ell v(x_\\ell)\\cdot\\n\\,q(x_\\ell),\n  \\end{gather*}\n  for any Gauss-Legendre or Gauss-Lobatto quadrature rule on\n  $\\face$. What was left unspecified in the definition of the element\n  was the choice of a basis $\\{q_j\\}$ for $\\P_k$. From the point of\n  view of moments, it is natural to choose Legendre polynomials as a\n  basis. But, we can also choose the basis which is orthogonal with\n  respect to the quadrature rule, which is up to the weights a\n  Lagrange basis. Thus, we can transform the moment degrees of freedom\n  back to interpolating degrees of freedom easily.\n\n  This construction extends automatically to tensor product space\n  $\\Q_k$. For polynomials space $\\P_k$, suitable quadrature sets on\n  triangles and quadrilaterals must be constructed.\n\\end{remark}\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "4168139f477651b1944e8704b516083972e6e7d8", "size": 66721, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mixed/darcy.tex", "max_stars_repo_name": "ahumanita/notes", "max_stars_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mixed/darcy.tex", "max_issues_repo_name": "ahumanita/notes", "max_issues_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mixed/darcy.tex", "max_forks_repo_name": "ahumanita/notes", "max_forks_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6800439802, "max_line_length": 148, "alphanum_fraction": 0.638344749, "num_tokens": 23557, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.8376199694135333, "lm_q1q2_score": 0.7321445469838622}}
{"text": "\\lab{Predator-Prey and Weight Change Models}{Weight change and Predator-Prey Models}\n\\label{lab:Weightchange}\n\\objective{We introduce built-in methods for solving Initial Value Problems and apply the methods to two dynamical systems.\nThe first  system looks at the relationship between a predator and its prey. \nThe second model is a weight change model based on thermodynamics and kinematics.}\n\n% \\section*{ODE Solvers}\n% Initial Value Problems (IVPs) are a systems of one or more ordinary differential equations (ODEs) with defined initial conditions. In some cases, these can be solved by hand, but in real life it is more practical to use numerical solvers. For this lab you will use the  \\li{solve_ivp} solver from the \\li{scipy.integrate} library.\n\n% \\li{solve_ivp} solves a system of ODEs given by $dy/dt = f(t, y),\\quad y(t_0)=y_0$, where $y$ can be a vector. The solver takes as parameters the callable function $f$, the time boundaries \\li{(t0,tf)}, the initial condition \\li{y_0}, and an optional keyword argument \\li{t_eval} that designates the times at which the solver will store the solution. Then \\li{solve_ivp} returns a bunch object containing an array \\li{y} with shape \\li{(len(y_0), len(t))}, where each column gives the \\li{y} values for one time point. The syntax for \\li{solve_ivp} is shown below.\n% \\begin{lstlisting}\n% from scipy.integrate import solve_ivp\n% sol = solve_ivp(f, (t0,tf), y0, t_eval=t)\n% \\end{lstlisting}\n% Assuming that $f$, $y0$, $t_0$, $t_f$, and $t$ are previously defined as explained above, \\li{sol.y} is a vector containing the solution to the IVP and can be visualized by plotting each row of \\li{sol.y} against the time domain or by plotting the rows against each other.\n\n\\section*{Predator-Prey Model} \nODEs are commonly used to model relationships between predator and prey populations. For example, consider the populations of wolves, the predator, and rabbits, the prey, in Yellowstone National Park. Let $r(t)$ and $w(t)$ represent the rabbit and wolf populations respectively at time $t$, measured in years. \nWe will make a few assumptions to simplify our model:\n\n\\begin{itemize}\n\\item In the absence of wolves, the rabbit population grows at a positive rate proportional to the current population. Thus when $w(t) = 0$, $dr/dt = \\alpha r(t)$, where $\\alpha > 0$.\n\\item In the absence of rabbits, the wolves die out. Thus when $r(t) = 0$, $dw/dt = -\\delta w(t)$, where $\\delta > 0$.\n\\item The number of encounters between rabbits and wolves is proportional to the product of their populations. The wolf population grows proportional to the number of encounters by $\\beta r(t)w(t)$ (where $\\beta > 0$), and the rabbit population decreases proportional to the number of encounters by $-\\gamma r(t)w(t)$ (where $\\gamma > 0$). \n\\end{itemize}\n\nThis leads to the following system of ODEs: \n\\begin{align}\n\t\\begin{split}\n\t&\\frac{dr}{dt} = \\alpha r - \\beta r w = r(\\alpha - \\beta w)\\\\\n\t&\\frac{dw}{dt} = -\\delta w + \\gamma r w = w(-\\delta + \\gamma r)\n\t\\end{split}\\label{eqn: Pred-Prey}\n\\end{align}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\textwidth]{figures/Predator_Prey.png}\n\\caption{The solution to the system found in \\eqref{eqn: Pred-Prey}}\n\\label{fig: Pred-Prey}\n\\end{figure}\n\n\n\\begin{problem}\nDefine the function \\li{predator_prey()} that accepts the current $r(t)$ and $w(t)$ values as a 1d array $y$, and the current time $t$, \n%a 1d array $y$ representing the current rabbit and wolf populations and a float $t$ representing the current time. \nand returns the right hand side of \\eqref{eqn: Pred-Prey} as an ndarray. \nUse $\\alpha=1.0$, $\\beta=0.5$, $\\delta=0.75$, and $\\gamma=0.25$ as your growth parameters.\\\\\nHint: you will want to use \\li{solve_ivp}.\n%\\begin{lstlisting}\n%def predator_prey(y, t):\n%\t'''\n%\tParameters:\n%\t--------------\n%\tt:\ttime variable.\n%\ty:\tan array of length len(y0) representing current wolf and rabbit populations at time t.\n%\t\n%\tReturn:\n%\t--------\n%\tReturn a tuple corresponding to the Predator-Prey model.\n%\t'''\n%\tpass\n%\\end{lstlisting}\n\n\\end{problem}\n\n%Import the \\li{odeint} method and define the initial conditions and time array for the predator-prey model using the following code:\n%\\begin{lstlisting}\n%# Initialize populations\n%r0 = 5\n%w0 = 3\n%y0 = [r0, w0]\n\n%# Initialize time array\n%t = np.linspace(0, 20, 100)\n%\\end{lstlisting}\n\n\\begin{problem}\nUse \\li{solve_ivp} to solve \\eqref{eqn: Pred-Prey} with initial conditions $(r_0, w_0) = (5, 3)$ and time ranging from $0$ to $20$ years.\nDisplay the resulting rabbit and wolf populations over time (stored as rows in the attribute \\li{y} of the output of \\li{solve_ivp}) on the same plot. Your graph should match the graph in figure \\ref{fig: Pred-Prey}.\n\\end{problem}\n\n\\begin{comment}\n\\objective{We use IVP methods to study two dynamical systems. \nThe first  system is a weight change model based on thermodynamics and kinematics. \nThe second model looks at the relationship between a predator and its prey. }\n\n\\section*{ODE solvers}\nInitial Value Problems, or IVPs, are a system of one or more ordinary differential equations (ODEs) with initial values.\nIn more basic math courses, these problems can be solved by hand, but in real life that is very much not the case.\nFor more complicated IVPs, numerical solvers are required.\n\nIn the previous lab, you built your own numerical solvers. For this lab you will use two built in solvers from the \\li{scipy.integrate} library, \\li{ode} and \\li{odeint}. The \\li{ode} solver solves a single equation of the form $u'(t)=f(t,u)$ and takes the function $f$ as a parameter. This solver can be implemented with various numerical approximations. We will use the \\li{dopri5} method, which runs RK4 iterative ODE solver (Runge-Kutta method of order 4). The \\li{odeint} solver is similar but solves a system of ODEs rather than a single equation.\n\nIn later labs we will build our own numerical solvers but for this lab you will learn how to use two methods built in to Python. You will be expected to use these methods to solve ODEs in future labs.\n\nThe solvers used in this lab are contained in the \\li{scipy.integrate} library. The first solver, \\li{scipy.integrate.ode}, solves the equation $u'(t)=f(t,u)$ and takes the function $f$ as a parameter. \n\nThe \\li{ode} method can use many numerical approximations to solve.\nWe will use the \\li{dopri5} method, which runs the RK4 (Runge-Kutta method of order 4) iterative ODE solver.\n\nAt the end of this lab you will see a similar method, \\li{scipy.integrate.odeint} which solves a system of ODEs rather than a single ODE.\n\nThe \\li{scipy.integrate} library contains two solvers that we will use in this lab. We will first introduce the basic numerical solver \\li{scipy.integrate.ode}. \nWe will introduce basic numerical s \\li{ode} method in \\li{scipy.integrate} and work through an example so you can understand how ODE solvers work to solve IVP problems.\nAt the end of this lab you will see a similar method, \\li{odeint}, in the same package.\n\nThe \\li{ode} method can use many numerical approximations to solve.\nWe will use the \\li{dopri5} method, which runs the RK4 (Runge-Kutta method of order 4) iterative ODE solver.\n\nBelow you will see sample code for solving a differential equation.\n\n\\section*{ODE solvers}\nInital Value Problems, or IVPs, are a system of one or more ordinary differential equations (ODEs) with initial values.\nIn more basic math courses, these problems could be solved by hand, but in real life that is very much not the case.\nFor more complicated IVPs, numerical solvers are required.\nWe will introduce the basic \\li{ode} method in \\li{scipy.integrate} and work through an example so you can understand how ODE solvers work to solve IVP problems.\nAt the end of this lab you will see a similar method, \\li{odeint}, in the same package.\n\nThe \\li{ode} method can use many numerical approximations to solve.\nWe will use the \\li{dopri5} method, which runs the RK4 (Runge-Kutta method of order 4) iterative ODE solver.\n\nBelow you will see sample code for solving a differential equation.\n\n\\subsection*{Predator-Prey Model}\nOne common problem to solve is the predator-prey model which involves two species, where one species (the prey) is the food source of the other species (the predator).\nFor this example we will consider the predator to be wolves and the prey to be rabbits in Yellowstone National Park.\nLet \\li{t} represent time, \\li{r(t)} represents the rabbit population at time \\li{t}, and \\li{w(t)} represents the wolf population at time \\li{t}.\n\nWe need to make a few assumptions in this model:\n\\begin{itemize}\n\\item In the absence of wolves, the rabbit population grows at a positive rate proportional to the current population.\nThus $dr/dt = ar(t)$ when $w(t) = 0$, where $a>0$.\n\\item In the absence of rabbits, the wolves die out.\nThus $dw/dt = -cw(t)$ when $r(t) = 0$, where $c>0$.\n\\item The number of encounters between rabbits and wolves is proportional to the product of their populations.\nEncounters encourage the growth of the wolf population and a decrease in the rabbit population.\nThe growth rate of rabbits is decreased by some $-\\alpha r(t) w(t)$ and the growth rate of wolves is increased by $\\gamma r(t) w(t)$\n\\end{itemize}\n\nThis leads us to the following system of ODEs (for simplicity of notation we will drop off \\li{t}:\n\\begin{align}\n\t\\begin{split}\n\t&dr/dt = ar - \\alpha r w = r(a - \\alpha w)\\\\\n\t&dw/dt = -cw + \\gamma r w = w(-c + \\gamma r)\n\t\\end{split}\\label{eqn: Pred-Prey}\n\\end{align}\n\nNow we will run through this example.\nStart with the necessary imports.\n\n\\begin{lstlisting}\nfrom scipy.integrate import ode\nimport numpy as np\nimport matplotlib.pyplot as plt\n\\end{lstlisting}\n\nEstablish our initial conditions\n\n\\begin{lstlisting}\nr0 = 5 # Initial rabbit population\nw0 = 3 # Initial wolf population\n\n# Define rabbit growth paramters\na = 1.0\nalpha = 0.5\n\n# Define wolf growth parameters\nc = 0.75\ngamma = 0.25\n\nt_f = 20 # How long we want to run the model\ny0 = [r0, w0]\n\n# Initialize time and output arrays needed for the ode solver\nt = np.linspace(0, t_f, 5*t_f)\ny = np.zeros((len(t), len(y0)))\ny[0,:] = y0\n\\end{lstlisting}\n\n\\begin{problem}\nFinish the following code box. You will create the function that takes as input the time, current \\li{r} and \\li{w} values, and all growth parameters.\n\\begin{lstlisting}\ndef predator_prey(t, y, a, alpha, c, gamma):\n\t'''\n\tParameters:\n\t--------------\n\tt:\ttime variable.\n\ty:\tan array of length len(y0) representing current wolf and rabbit populations at time t.\n\ta, alpha, c, gamma:\tgrowth parameters. These are keyword arguments and can be of any length.\n\t\n\tReturn:\n\t--------\n\tReturn a list corresponding to the Predator-Prey model.\n\t'''\n\tpass\n\\end{lstlisting}\n\\end{problem}\n\nWe need to set up our ODE solver to use the RK4 numerical integrator and give it the correct initial values.\nAlso note that the \\li{predator_prey} function above must be turned into a \\li{lambda} function.\n\n\\begin{lstlisting}\npredator_prey_ode = lambda t, y:predator_prey(t, y, a, alpha, c, gamma)\np_p_solver = ode(predator_prey_ode).set_integrator('dopri5') # set the numerical integrator\np_p_solver.set_initial_value(y0, 0) # Set the initial values. The second argument is the initial time, which we set to 0\n\\end{lstlisting}\n\nThe \\li{ode} solver has an \\li{integrate} method which solves one time step at a time.\nIterate through the time array and update the \\li{y} values at each step.\n\\begin{lstlisting}\nfor j in range(1, len(t)):\n\ty[j,:] = p_p_solver.integrate((t[j]))\n\\end{lstlisting}\n\nThe following code can be used to graph the resulting system. See Figure \\ref{fig: Pred-Prey}.\n\n\\begin{lstlisting}\nplt.plot(t, y[:,0], label='rabbit')\nplt.plot(t, y[:,1], label='wolf')\nplt.legend()\nplt.xlabel('Time')\nplt.ylabel('Population')\nplt.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{Predator_Prey.pdf}\n\\caption{The solution to the system found in \\eqref{eqn: Pred-Prey}}\n\\label{fig: Pred-Prey}\n\\end{figure}\n\n\\begin{problem}\nGraph the wolf-rabbit model given in \\eqref{eqn: Pred-Prey}.\nIt should look like Figure \\ref{fig: Pred-Prey}.\n\\end{problem}\n\\end{comment}\n\n\\section*{Variations on the Predator-Prey}\n\\subsection*{The Lotka-Volterra model}\nThe representation of the predator-prey relationship found in \\eqref{eqn: Pred-Prey} is called the Lotka-Volterra predator-prey model and is typically given by %. This well-known system of ODEs is typically given by\n%This type of problem has a special name.\n%The Lotka-Volterra predator-prey model is a well-known\n%system of ODEs given by\n\\begin{align*}\n\t\\frac{du}{dt} &= \\alpha u - \\beta uv,\\\\\n\t\\frac{dv}{dt} &= -\\delta v + \\gamma uv.\n\\end{align*}\nwhere $u$ and $v$ represent the prey and predator populations, respectively. Here $\\alpha$, $\\beta$, $\\delta$, and $\\gamma$ are the same as before but now for an arbitrary prey and predator.% represents the rate of growth of the prey, and $bu$ the amount of prey being eaten.\n%Similarly, $c$ represents the rate of natural predator death, and $du$ the growth of the predator population due to the quantity of prey eaten.\n\nThe equlibria (fixed points) of a system occur when the derivatives are zero.\nIn this example, that occurs at $(u,v)=(0,0)$ and $(u,v)=(\\frac{c}{d},\\frac{a}{b})$.\n%Notice also that if $v=0$ (there are no predators), the population of prey will grow exponentially.\nVisualizing the phase portrait helps to give more insight into the dynamics of a system. We will do this by first nondimensionalzing our system to reduce the number of parameters.\n\\begin{comment}\nFirst we note that there are exactly two equilibria (fixed points): either $(u,v) = (0,0)$ corresponding to the extinction of both species, or $(u,v) = (\\frac{\\delta}{\\gamma},\\frac{\\alpha}{\\beta})$.\nFurthermore, from the ODEs we can see that if $v=0$ (there is an absence of any predators) then the population of prey will grow exponentially.\n\nTo get a better idea of the dynamics of this system we will graph its phase portrait.\nWe begin by nondimensionalizing the system to reduce the number of parameters:\\end{comment}\nLet $U = \\frac{\\gamma}{\\delta}u,$ $V = \\frac{\\beta}{\\alpha}v$, $\\bar{t} = \\alpha t,$ and $\\eta = \\frac{\\gamma}{\\alpha}$.\nSubstituting into the original ODEs we obtain the nondimensional system of equations\n\\begin{align}\n\t\\begin{split}\n\t\\frac{dU}{d\\bar{t}} &= U(1-V),\\\\\n\t\\frac{dV}{d\\bar{t}} &= \\eta V (U-1).\n\t\\end{split}\\label{lotka_volterra}\n\\end{align}\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{figures/LV_Phase_Portrait.png}\n\\caption{The phase portrait for the nondimensionalized Lotka-Volterra predator-prey equations with parameters $\\eta = 1/3$.\n%The portrait includes the direction field, the two equilibrium points, and the graph of the solution with initial conditions $(U,V) = (3/4, 3/4)$.\n }\n\\label{fig: lotka-phase}\n\\end{figure}\n\n\n%\\begin{figure}\n%\\centering\n%\\includegraphics[width=\\textwidth]{Lotka_Volterra.pdf}\n%\\caption{The solution of the nondimensionalized Lotka-Volterra predator-prey equations with parameter $\\alpha = 1/3$.\n%This solution has initial conditions $(U,V) = (3/4, 3/4)$.}\n%\\label{fig: lotka-phase}\n%\\end{figure}\n\n\n\\begin{problem}\nSimilar to problem 1, define the function \\li{Lotka_volterra()} that takes in the current predator and prey populations as a 1d array $y$ and the current time as a float $t$ and returns the right hand side of the system \\eqref{lotka_volterra} with $\\eta=1/3$.\n%\\begin{lstlisting}\n%def Lotka_Volterra(y, t):\n%    \"\"\"\n%    Parameters:\n%    _______________\n%    y:    an array of length len(Y0) representing current (nondimensionalized) predator and prey populations at time t.\n%    t:    time variable.\n\n%    Return:\n%    _______________\n%    Return a tuple corresponding the the Lotka Volterra Predator-Prey model.\n%    \"\"\"\n%    pass\n%\\end{lstlisting}\nThe following three lines of code plot the phase portrait of \\eqref{lotka_volterra}. \nFor more documentation on quiver plots see \\href{https://matplotlib.org/api/_as_gen/matplotlib.pyplot.quiver.html}{the documentation}.\n\\begin{lstlisting}\nY1, Y2 = np.meshgrid(np.linspace(0, 4.5, 25), np.linspace(0, 4.5, 25))\ndU, dV = Lotka_Volterra(0, (Y1, Y2))\nQ = plt.quiver(Y1[::3, ::3], Y2[::3, ::3], U[::3, ::3], V[::3, ::3])\n\\end{lstlisting}\nUsing \\li{solve_ivp}, solve \\eqref{lotka_volterra} with three different initial conditions $y_0 = (1/2, 1/3)$, $y_0=(1/2, 3/4)$, and $y_0=(1/16, 3/4)$ and time domain $t = [0,13]$. Plot these three solutions on the same graph as the phase portrait and the equilibria $(0,0)$ and $(1,1)$.\n\nSince your solutions are being plotted with the phase portrait, plot the two populations against each other (instead of both individually against time). Your plot should match \\ref{fig: lotka-phase}.\n\\end{problem}\n\\begin{comment}\nIn the following code we plot the phase portrait of \\eqref{lotka_volterra} along with a example trajectory, see Figures  \\ref{fig:pred-prey_Lotka_Voterra} and \\ref{fig:pred-prey_Lotka_Voterra_Phase_Portrait}.\nWe will use \\li{scipy.integrate.odeint} which acts similar to the \\li{ode} function used earlier but integrates over all the time steps at once.\nTo plot the direction field for the equations we use \\li{numpy}'s \\li{meshgrid} function and \\li{matplotlib}'s \\li{quiver} function.\n\n\\begin{lstlisting}\nfrom scipy.integrate import odeint\na, b = 0., 13.                    # (Nondimensional) Time interval for one 'period'\nalpha = 1. / 3                    # Nondimensional parameter\ndim = 2                           # dimension of the system\ny0 = np.array([1 / 2., 1 / 3.])   # initial conditions\n\n# Note: swapping order of arguments to match the calling convention\n# used in the built in IVP solver.\ndef Lotka_Volterra(y, x):\n    return np.array([y[0] * (1. - y[1]), alpha * y[1] * (y[0] - 1.)])\n\nsubintervals = 200\n# Using the built in ode solver\nY = odeint(Lotka_Volterra, y0, np.linspace(a, b, subintervals))\n\n# Plot the direction field\nY1, Y2 = np.meshgrid(np.arange(0, 4.5, .2), np.arange(0, 4.5, .2), sparse=True, copy=False)\nU, V = Lotka_Volterra((Y1, Y2), 0)\nQ = plt.quiver(Y1[::3, ::3], Y2[::3, ::3],  U[::3, ::3],  V[::3, ::3], pivot='mid', color='b', units='dots',width=3.)\n# Plot the 2 Equilibrium points\nplt.plot(1, 1, 'ok', markersize=8)\nplt.plot(0, 0, 'ok', markersize=8)\n# Plot the solution in phase space\nplt.plot(Y[:,0], Y[:,1], '-k', linewidth=2.0)\nplt.plot(Y[::10,0], Y[::10,1], '*b')\n\nplt.axis([-.5, 4.5, -.5, 4.5])\nplt.title(\"Phase Portrait of the Lotka-Volterra Predator-Prey Model\")\nplt.xlabel('Prey',fontsize=15)\nplt.ylabel('Predators',fontsize=15)\nplt.show()\n\\end{lstlisting}\n\n\\begin{problem}\nCompute the solutions $(U,V)$ of \\eqref{lotka_volterra} \n% \\begin{align*}\n% \t\\frac{dU}{d\\bar{t}} &= U(1-V),\\\\\n% \t\\frac{dV}{d\\bar{t}} &= \\alpha V (U-1).\n% \\end{align*}\nfor initial conditions $(1/2, 3/4)$, $(1/16, 3/4)$, and $(1/40, 3/4)$.\nAdd these solutions to the phase portrait of the Lotka-Volterra model.\nCan you see any limitations of this model?\n\\end{problem}\n\\end{comment}\n%\\begin{figure}\n%\\centering\n%\\includegraphics[width=\\textwidth]{LV_Phase_Portrait.png}\n%\\caption{The phase portrait for the nondimensionalized Lotka-Volterra predator-prey equations with parameters $\\alpha = 1/3$.\n%The portrait includes the direction field, the two equilibrium points, and the graph of the solution with initial conditions $(U,V) = (3/4, 3/4)$.\n% }\n%\\label{fig:pred-prey_Lotka_Voterra_Phase_Portrait}\n%\\end{figure}\n\n\\subsection*{The Logistic model}\nNotice that the Lotka-Volterra equations predict prey populations will grow exponentially in the absence of predators. The logistic predator-prey equations change this dynamic by adding a carrying capacity $K$ to the prey population:%term to give the prey population a carrying capacity $K$:\n\\begin{comment}\nWe have already noticed that in the absence of predators, the Lotka-Volterra equations predict that the prey population will grow exponentially.\nThe logistic predator-prey equations change this dynamic by adding a term to give the prey population a carrying capacity $K$:\n\\end{comment}\n\\begin{align*}\n\t\\frac{du}{dt} &= \\alpha u\\left(1 -\\frac{u}{K}\\right) - \\beta uv,\\\\\n\t\\frac{dv}{dt} &= -\\delta v + \\gamma uv.\n\\end{align*}\nWe can again do dimensional analysis on this system to simplify parameters. Let $U = \\frac{u}{K},$ $V = \\frac{\\beta}{\\alpha}v$, $\\bar{t} = \\alpha t,$  $\\eta = \\frac{\\gamma K}{\\alpha}$, and $\\rho = \\frac{\\delta}{\\gamma K}$.\nThen the nondimensional logistic equations are\n\\begin{align}\n\t\\begin{split}\n\t\\frac{dU}{d\\bar{t}} &= U(1-U-V),\\\\\n\t\\frac{dV}{d\\bar{t}} &= \\eta V (U-\\rho).\n\t\\end{split} \\label{logistic_pred_prey}\n\\end{align}\n\n\\begin{problem}\nDefine a new function \\li{Logistic_Model()} that takes in the current predator and prey populations $y$ and the current time $t$ and returns the right hand side of \\eqref{logistic_pred_prey} as a tuple. Use \\li{solve_ivp} to compute solutions $(U,V)$ of \\eqref{logistic_pred_prey}\nfor initial conditions $(1/3, 1/3)$ and $(1/2, 1/5)$ with $(t0,tf)=(0,13)$.\nDo this for parameter values $\\eta$, $\\rho = 1$, $0.3$ and also for values $\\eta$, $\\rho = 1$, $1.1$.\n\nCreate a phase portrait for the logistic equations using both sets of parameter values.\nPlot the direction field, all equilibrium points, and both solution orbits on the same plot for each set of parameter values.\n\\end{problem} \n\n\\section*{A Weight Change Model}\nThe main idea behind weight change is simple. If a person takes in more energy than they expend, they gain weight. If they take in less than they expend, they lose weight. Let \\emph{energy balance} $EB$ be the difference between \\emph{energy intake} $EI$ and \\emph{energy expenditure} $EE$, so that $$EB = EI - EE.$$\nIf the balance is positive, weight is gained and similarly if the balance is negative, weight is lost. \n\nA person's body weight at a time $t$ can be expressed as the sum of the weight of their fat tissue $F(t)$ and the weight of their lean tissue $L(t)$; that is, $BW(t) = F(t) + L(t)$. Using this, the change in body weight can be expressed as the following system of ODEs:\n\\begin{align}\n        \\begin{split}\n                \\dfrac{dF}{dt} &= \\frac{(1-p(t)) EB(t)}{\\rho_F},\\\\\n                \\dfrac{dL}{dt} &= \\frac{p(t) EB(t)}{\\rho_L},\n        \\end{split}\\label{eqn:compartment}\n\\end{align}\nwhere $(1-p(t))$ and $p(t)$ represent the proportion of the energy balance ($EB(t)$) that results in a change in the quantity of fatty or lean tissue, respectively. The constants $\\rho_F$ and $\\rho_L$ represent the energy density of fatty and lean tissue, approximated as $\\rho_F=9400$ kcal/kg and $\\rho_L=1800$ kcal/kg.\n\nTo solve this system, we first need to express $p(t)$ and $EB(t)$ in terms of $F$ and $L$. These functions will also depend on physical activity level, $PAL$, and energy intake, $EI$, which vary among individuals.% along with other constant parameters. \n\nWe will find an expression for $p(t)$ using Forbes' Law% \\cite{Fo.2}\n \\footnote{\\emph{Lean body mass-body fat interrelationships in humans}, Forbes, G.B.; \\emph{ Nutrition reviews}, pgs 225-231, 1987.}\nwhich states that $$\\frac{dF}{dL}=\\frac{F}{10.4}.$$ Notice\n\\[\n\\dfrac{F}{10.4} = \\dfrac{dF}{dL} = \\dfrac{dF/dt}{dL/dt} = \\dfrac{\\dfrac{(1-p(t)) EB(t)}{\\rho_F}}{\\dfrac{p(t) EB(t)}{\\rho_L}} = \\dfrac{\\rho_L}{\\rho_F} \\dfrac{1-p(t)}{p(t)}.\n\\]\nSolving for $p(t)$ gives Forbes' equation\n\\begin{equation}\n\\label{eqn:Forbes2}\np(t) = \\dfrac{C}{C+F(t)}\\quad\\mbox{where}\\quad C=10.4\\dfrac{\\rho_L}{\\rho_F}.\n\\end{equation}\nWe will now find an expression for $EB(t)$. Recall $EB(t)=EI-EE$. We will use the following expression for energy expenditure ($EE$) to define $EB(t)$. \n\\begin{equation}\n\\label{eqn:EE1}\nEE=PAL \\times RMR\n\\end{equation}\n%\\begin{equation}\n%\\label{eqn:EE}\n%EE = \\underbrace{\\delta BW}_\\text{\\parbox{1cm}{physical\\\\activity}} + \\underbrace{\\beta_{tef} EI}_\\text{\\parbox{1cm}{thermic\\\\effect of\\\\eating}} + \\underbrace{\\beta_{at} EI + \\gamma_F F + \\gamma_L L + \\eta_F \\dfrac{dF}{dt} + \\eta_L \\dfrac{dL}{dt}  + K}_\\text{resting metabolic rate (RMR)},\n%EE = \\delta BW + \\beta_{tef}EI + RMR\n%\\end{equation}\nwhere $PAL$ is physical activity level (as previously mentioned) and $RMR$ is resting metabolic rate. \nPhysical activity level can be determined using the table above.\n\\begin{table}[h]\n\\begin{center}\n\\begin{tabular}{|l|l|}\n\\hline\n1.40--1.69 & People who are sedentary and do not exercise regularly, spend \\\\\n& most of their time sitting, standing, with little body displacement\n\\\\\n\\hline\n1.70--1.99 & People who are active, with frequent body displacement throughout  \\\\\n& the day or who exercise frequently\\\\\n\\hline\n2.00--2.40 & People who engage regularly in strenuous work or exercise for \\\\\n& several hours each day\\\\\n\\hline\n\\end{tabular}\n\\caption{This is a rough guide for physical activity level (PAL).\n% For more detailed estimates, see \\cite{Heym} and Appendix \\ref{PAL_appendix}.\n}\n\\end{center}\\label{tab:PAL_table}\n\\end{table}\n\nWe will use the following equation for computing $RMR$,\n\\begin{equation}\nRMR = K + \\gamma_F F(t) + \\gamma_L L(t) + \\eta_F \\dfrac{dF}{dt} + \\eta_L \\dfrac{dL}{dt}  + \\beta_{at} EI ,\n\\label{eqn:RMR}\n\\end{equation}\nwhere $\\gamma_F = 3.2$ kcal/kg/d, $\\gamma_L = 22$ kcal/kg/d, $\\eta_F = 180$ kcal/kg, and $\\eta_L = 230$ kcal/kg\n\\footnote{\\emph{Modeling weight-loss maintenance to help prevent body weight regain}; Hall, K.D. and Jordan, P.N.; \\emph{The American journal of clinical nutrition}, pg 1495, 2008}\n\\footnote{\\emph{Quantification of the effect of energy imbalance on bodyweight}; Hall, K.D. et al.; \\emph{The Lancet}, pgs 826-837, 2011}.\n% \\cite{Hall.2, Hall.4}.\nFurther, we let $\\beta_{at}=0.14$ denote the coefficient for adaptive thermogenesis.\n%The parameter $\\delta$ is the coefficient representing the amount of energy expended from physical activity per kilogram of body mass.\n%Notice that $\\gamma_L$ is significantly larger than $\\gamma_F$.\n%This means that lean tissue metabolizes energy much faster than fatty tissue.\n%As a result, there are instances where one may want to increase their lean body mass through resistance training so that they are better able to support a higher caloric intake without significant weight gain.\nFinally, we remark that the constant $K$ can be tuned to an individual's body type directly through RMR and fat measurement, and is assumed to remain constant over time.\n \n\\begin{comment}\nThe main idea behind weight change is simple.\nIf a person's energy intake is more than their energy expended, then they gain weight.\nIf their intake is less, then they lose weight.\nLet the \\emph{energy balance} $EB$ be the difference between \\emph{energy intake} $EI$ and \\emph{energy expenditure} $EE$, so that\n\\begin{equation}\n\\label{eqn:EB}\nEB = EI - EE.\n\\end{equation}\nWhen the energy intake is greater than the energy expended, the balance is positive and weight is gained.\nSimilarly, the balance is negative and weight is lost if the energy intake is less than the energy expended.\n\nBody weight at time $t$ is the sum of the weight of fat and lean tissue; that is,  $BW(t) = F(t) + L(t).$\nThese quantities can be described by the compartmental model\n% \\begin{subequations}\n% \\label{eqn:compartment}\n% \\begin{align}\n% \\rho_F \\dfrac{dF(t)}{dt} &= (1-p(t)) EB(t),\\label{eqn:compartment:a}\\\\\n% \\rho_L \\dfrac{dL(t)}{dt} &= p(t) EB(t),\\label{eqn:compartment:b}\n% \\end{align}\n% \\end{subequations}\n\n\n\n\\begin{align}\n\t\\begin{split}\n\t\t\\rho_F \\dfrac{dF(t)}{dt} &= (1-p(t)) EB(t),\\\\\n\t\t\\rho_L \\dfrac{dL(t)}{dt} &= p(t) EB(t),\n\t\\end{split}\\label{eqn:compartment}\n\\end{align}\nwhere $p(t)$ and $1-p(t)$ represent the proportion of the energy balance ($EB(t)$) that results in a change in the quantity of lean or fatty tissue, respectively.\nConstants $\\rho_L$ and $\\rho_F$ represent the energy density of lean and fatty tissue (about $1800$ and $9400$ kcal/kg).\n\nNext we need to find expressions for $p(t)$ and $EB(t)$ in terms of $L$ and $F$ (the dependent variables), $PAL$ and $EI$ (possibly varying parameters), and other constant parameters.\n\n The proportion $p(t)$ will vary with $F$ and $L$; from Forbes' Law \n % \\cite{Fo.2}\n \\footnote{\\emph{Lean body mass-body fat interrelationships in humans}, Forbes, G.B.; \\emph{ Nutrition reviews}, pgs 225-231, 1987.}\n we have that\n\\begin{equation}\n\\label{eqn:forbes}\n\\dfrac{dF}{dL} = \\dfrac{F}{10.4}.\n\\end{equation}\nHence,\n\\[\n\\dfrac{F}{10.4} = \\dfrac{dF}{dL} = \\dfrac{dF/dt}{dL/dt} = \\dfrac{\\dfrac{(1-p(t)) EB(t)}{\\rho_F}}{\\dfrac{p(t) EB(t)}{\\rho_L}} = \\dfrac{\\rho_L}{\\rho_F} \\dfrac{1-p(t)}{p(t)}.\n\\]\nSolving for $p(t)$ gives Forbes' equation\n\\begin{equation}\n\\label{eqn:Forbes2}\np(t) = \\dfrac{C}{C+F(t)}\\quad\\mbox{where}\\quad C=10.4\\dfrac{\\rho_L}{\\rho_F}.\n\\end{equation}\nWe will use two expressions for energy expenditure (EE).\nFirst, we have the formula\n\\begin{equation}\n\\label{eqn:EE0}\nEE = PAL \\times RMR,\n\\end{equation}\nwhere $PAL$ is your physical activity level and $RMR$ your resting metabolic rate.\nYour resting metabolic rate can be determined by using the Mifflin equation.\nThis equation is an estimate based on a population study and is widely used in the literature.\nIt takes into account your gender, age (A) in years, and height (H) in meters:\n\\begin{equation}\n\\label{eqn:RMR}\nRMR = \\begin{cases} 9.99 W + 625 H + 5 A + 5 & \\mbox{if male}\\\\ 9.99 W + 625 H + 5 A -161 & \\mbox{if female.}\\end{cases}\n\\end{equation}\nYour physical activity level can be determined by using the table below.\n\\begin{table}[h]\n\\begin{center}\n\\begin{tabular}{|l|l|}\n\\hline\n1.40--1.69 & People who are sedentary and do not exercise regularly, spend \\\\\n& most of their time sitting, standing, with little body displacement\n\\\\\n\\hline\n1.70--1.99 & People who are active, with frequent body displacement throughout  \\\\\n& the day or who exercise frequently\\\\\n\\hline\n2.00--2.40 & People who engage regularly in strenuous work or exercise for \\\\\n& several hours each day\\\\\n\\hline\n\\end{tabular}\n\\caption{This is a rough guide for physical activity level (PAL).\n% For more detailed estimates, see \\cite{Heym} and Appendix \\ref{PAL_appendix}.\n}\n\\end{center}\\label{tab:PAL_table}\n\\end{table}\n\nThe second expression for energy expenditure comes from decomposing more precisely the different ways that energy is expended:\n\\begin{equation}\n\\label{eqn:EE}\nEE = \\underbrace{\\delta BW}_\\text{\\parbox{1cm}{physical\\\\activity}} + \\underbrace{\\beta_{tef} EI}_\\text{\\parbox{1cm}{thermic\\\\effect of\\\\eating}} + \\underbrace{\\beta_{at} EI + \\gamma_F F + \\gamma_L L + \\eta_F \\dfrac{dF}{dt} + \\eta_L \\dfrac{dL}{dt}  + K}_\\text{resting metabolic rate (RMR)},\n\\end{equation}\nwhere $\\gamma_F = 3.2$ kcal/kg/d, $\\gamma_L = 22$ kcal/kg/d, $\\eta_F = 180$ kcal/kg, and $\\eta_L = 230$ kcal/kg\n\\footnote{\\emph{Modeling weight-loss maintenance to help prevent body weight regain}; Hall, K.D. and Jordan, P.N.; \\emph{The American journal of clinical nutrition}, pg 1495, 2008}\n\\footnote{\\emph{Quantification of the effect of energy imbalance on bodyweight}; Hall, K.D. et al.; \\emph{The Lancet}, pgs 826-837, 2011}.\n% \\cite{Hall.2, Hall.4}.\nFurther, we let $\\beta_{tef}=0.10$ and $\\beta_{at}=0.14$ denote the coefficients for the thermic effect of feeding and adaptive thermogenesis, respectively.\nThe parameter $\\delta$ is the coefficient representing the amount of energy expended from physical activity per kilogram of body mass.\nNotice that $\\gamma_L$ is significantly larger than $\\gamma_F$.\nThis means that lean tissue metabolizes energy much faster than fatty tissue.\nAs a result, there are instances where one may want to increase their lean body mass through resistance training so that they are better able to support a higher caloric intake without significant weight gain.\nFinally, we remark that the constant $K$ can be tuned to an individual's body type directly through RMR and fat measurement, and is assumed to remain constant over time.\n\\end{comment}\n% Assumptions made/Areas to improve:\n% include more accurate approximation of PAL (given in appendix), BMI (show to vary with race), account for variation in body type.\n\nThus, since the input $EI$ is assumed to be known, we can use \\eqref{eqn:EE1}, \\eqref{eqn:RMR} and \\eqref{eqn:Forbes2} to write \\eqref{eqn:compartment} in terms of $F$ and $L$, thus allowing us to close the system of ODEs.\n\nSpecifically, we have\n\\begin{align*}\nRMR = \\frac{EE}{PAL}&= K + \\gamma_F F(t) + \\gamma_L L(t) + \\eta_F \\dfrac{dF}{dt} + \\eta_L \\dfrac{dL}{dt}  + \\beta_{at} EI\\\\\n% &= K + \\gamma_F F(t) + \\gamma_L L(t) + \\dfrac{\\eta_F}{\\rho_F} (1-p(t)) EB(t) + \\dfrac{\\eta_L}{\\rho_L} p(t) EB(t)  + \\beta_{at} EI,\\\\\n\\dfrac{1}{PAL}\\left(EE - EI + EI \\right) &= K + \\gamma_F F(t) + \\gamma_L L(t) \\\\\n&\\quad+ \\left(\\dfrac{\\eta_F}{\\rho_F} (1-p(t)) + \\dfrac{\\eta_L}{\\rho_L} p(t) \\right) EB(t) + \\beta_{at} EI.\\\\\n\\left(\\dfrac{1}{PAL}-\\beta_{at}\\right) EI &= K + \\gamma_F F(t) + \\gamma_L L(t) \\\\\n&\\quad+ \\left(\\dfrac{\\eta_F}{\\rho_F} (1-p(t)) + \\dfrac{\\eta_L}{\\rho_L} p(t) + \\dfrac{1}{PAL}\\right) EB(t).\n\\end{align*}\n% Thus,\n% \\[\n% \\left(\\dfrac{1}{PAL}-\\beta_{at}\\right) EI = K + \\gamma_F F(t) + \\gamma_L L(t) + \\left(\\dfrac{\\eta_F}{\\rho_F} (1-p(t)) + \\dfrac{\\eta_L}{\\rho_L} p(t) + \\dfrac{1}{PAL}\\right) EB(t).\n% \\]\nSolving for $EB(t)$ in the last equation yields\n\\begin{equation}\n\\label{eqn:EB2}\nEB(t) = \\dfrac{\\left( \\dfrac{1}{PAL} - \\beta_{at} \\right) EI - K - \\gamma_F F(t) - \\gamma_L L(t)}{\\dfrac{\\eta_F}{\\rho_F} (1-p(t)) + \\dfrac{\\eta_L}{\\rho_L} p(t) + \\dfrac{1}{PAL}}.\n\\end{equation}\n% To find $K$, we note that\n% \\begin{equation}\n% \\label{eqn:K}\n% K = \\left(\\dfrac{1}{PAL}-\\beta_{at}\\right) EI - \\gamma_F F(t) - \\gamma_L L(t) - \\eta_F \\dfrac{dF}{dt} - \\eta_L \\dfrac{dL}{dt}  - \\dfrac{1}{PAL} EB.\n% \\end{equation}\nIn equilibrium ($EB = 0$), this gives us\n\\begin{equation}\n\\label{eqn:K2}\nK = \\left(\\dfrac{1}{PAL}-\\beta_{at}\\right) EI - \\gamma_F F - \\gamma_L L.\n\\end{equation}\nThus, for a subject who has maintained the same weight for a while, one can determine $K$ by using \\eqref{eqn:K2}, if they know their average caloric intake and amount of fat (assume $L=BW-F$).\n%The function \\li{weight_odesystem} in the following code implements \\eqref{eqn:compartment}.\n\n%The following code defines the constants as given above and defines functions representing \\eqref{eqn:Forbes2} and \\eqref{eqn:EB2} respectively. \n\n\\begin{problem}\nWrite a function \\li{forbes()} which takes as input \\li{F}, the weight of fat tissue at a given time (i.e. the function $F(t)$ evaluated at a certain time), and returns Forbe's equation given in \\eqref{eqn:Forbes2}.\nAlso write the function \\li{energy_balance()} which takes as input \\li{F}, \\li{L}, \\li{PAL}, and \\li{EI} and returns the energy balance as given in \\eqref{eqn:EB2}.\nIn \\li{energy_balance()} we also have that \\li{F} is the fat tissue weight at a given time, and \\li{L} is the lean tissue weight at a given time.\n\nUsing \\li{forbes()} and \\li{energy_balance()}, define the function \\li{weight_odesystem()} which takes as input the current time as a float $t$ and the current fat and lean weights as an array $y$ and returns the right hand side of \\eqref{eqn:compartment} as a tuple.\n\nUse $\\rho_F = 9400$, $\\rho_L = 1800$, $\\gamma_F = 3.2$, $\\gamma_L = 22$, $\\eta_F = 180$, $\\eta_L = 230$, $K=0$ and $\\beta_{AT} = 0.14$.\n%These constants should be implemented using keyword arguments in the functions that need them.\n\nHint: The functions \\li{forbes()} and \\li{energy_balance()} are not time dependent in the same way equations \\eqref{eqn:Forbes2} and \\eqref{eqn:EB2} are.\nThe time dependent portions of these functions, $F(t)$ and $L(t)$, are determined by what will be input from the \\li{y} argument of \\li{weight_odesystem()}.\n\\end{problem}\n%\\begin{lstlisting}\n%# Fixed Constants:\n%rho_F, rho_L = 9400., 1800.\n%gamma_F, gamma_L = 3.2, 22.\n%eta_F, eta_L = 180., 230.\n%C = 10.4                         # Forbes constant\n%beta_AT = 0.14                   # Adaptive Thermogenesis\n\n%def forbes(F):\n%    C1 = C * rho_L / rho_F\n%    return C1 / (C1 + F)\n\n%def energy_balance(F, L, EI, PAL):\n%    p = forbes(F)\n%    a1 = (1. / PAL - beta_AT) * EI - K - gamma_F * F - gamma_L * L\n%    a2 = (1 - p) * eta_F / rho_F + p * eta_L / rho_L + 1. / PAL\n%    return a1 / a2\n\n%\\end{lstlisting}\n\\begin{comment}\ndef weight_odesystem(t, y, EI, PAL):\n    F, L = y[0], y[1]\n    p, EB = forbes(F), energy_balance(F, L, EI, PAL)\n    return np.array([(1 - p) * EB / rho_F , p * EB / rho_L])\n\ndef fat_mass(BW, age, H, sex):\n    BMI = BW / H**2.\n    if sex == 'male':\n        return BW * (-103.91 + 37.31 * log(BMI) + 0.14 * age) / 100\n    else:\n        return BW * (-102.01 + 39.96 * log(BMI) + 0.14 * age) / 100\n\\end{comment}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{figures/weightloss_graph.png}\n\\caption{The solution of the weight change model for problem 6.}\n\\label{fig:weightloss}\n\\end{figure}\n\n\\begin{problem}\n%Define the function \\li{weight_odesystem()} as given in \\eqref{eqn:compartment} using the functions \\li{forbes()} and \\li{energy_balance()} provided. \n\nConsider the initial value problem corresponding to \\eqref{eqn:compartment}.\nThe following function returns the fat mass of an individual based on body weight (kg), age (years), height (meters), and sex. Use this function to define initial conditions $F_0$ and $L_0$ for the IVP above: $F_0= fat\\_mass(args^*)$, $L_0 = BW - F_0$.%Using the result of this function and the provided body weight, you can define initial conditions $F_0$ and $L_0$ for the IVP above, with $F_0 =$\\li{fat_mass(args^*)} and $L_0 = BW - F_0$.\n\\begin{lstlisting}\ndef fat_mass(BW, age, H, sex):\n    BMI = BW / H**2.\n    if sex == 'male':\n        return BW * (-103.91 + 37.31 * log(BMI) + 0.14 * age) / 100\n    else:\n        return BW * (-102.01 + 39.96 * log(BMI) + 0.14 * age) / 100\n\\end{lstlisting}\n%To solve this IVP for a specific individual we need initial conditions $F_0$ and $L_0.$\n%The function \\li{fat_mass} given earlier calculates $F_0$ based on an individual's body weight (kg), age, height (meters), and gender.\n%$L_0$ is then given by $L_0 = BW - F_0$.\n\nSuppose a 38 year old female, standing 5'8'' and weighing 160 lbs, reduces her intake from 2143 to 2025 calories/day, and increases her physical activity from little to no exercise (PAL=1.4) to exercising to 2-3 days per week (PAL=1.5).\n\nUse \\eqref{eqn:K2} and the original intake and phyical activity levels to compute $K$ for this system. Then use \\li{solve_ivp} to solve the IVP. Graph the solution curve for this single-stage weightloss intervention over a period of 5 years. Your plot should match figure \\ref{fig:weightloss}.\n%Using \\li{scipy.integrate.ode}, find and graph the solution curve for this single-stage weightloss intervention over a period of 5 years. \n\nNote the provided code requires quantities in metric units (kilograms, meters, days) while our graph is converted to units of pounds and days.\nUse the conversions $1$ lb $=2.204$ kg, $1$ ft $=0.305$ m, and $1$ yr $=365$ days.\n\\end{problem}\n\n\\begin{problem}\nModify the preceding problem to handle a two stage weightloss intervention:\nSuppose for the first 16 weeks intake is reduced from 2143 to 1600 calories/day and physical activity is increased from little to no exercise (PAL=1.4) to an hour of exercise 5 days per week (PAL=1.7).\nThe following 16 weeks intake is increased from 1600 to 2025 calories/day, and exercise is limited to only 2-3 days per week (PAL=1.5).\n\nYou will need to recompute $F_0$, and $L_0$ at the end of the first 16 weeks, but $K$ will stay the same. \nFind and graph the solution curve over the 32 week period.\n\\end{problem}\n\n\\begin{comment}\n\\section*{Variations on the Predator-Prey}\n\\subsection*{The Lotka-Volterra model}\nReconsider \\eqref{eqn: Pred-Prey}. This representation of the predator-prey relationship is called the Lotka-Volterra predator-prey model. This well-known system of ODEs is typically given by\n%This type of problem has a special name.\n%The Lotka-Volterra predator-prey model is a well-known\n%system of ODEs given by\n\\begin{align*}\n\t\\frac{du}{dt} &= au - buv,\\\\\n\t\\frac{dv}{dt} &= -cv + duv.\n\\end{align*}\nwhere $u$ and $v$ represent the prey and predator populations, respectively. Here $a$ represents the rate of growth of the prey, and $bu$ the amount of prey being eaten.\nSimilarly, $c$ represents the rate of natural predator death, and $du$ the growth of the predator population due to the quantity of prey eaten.\n\nLet us look at the dynamics of this system. The equlibria (fixed points) of a system occur when the derivatives are zero, for our system this occurs at $(u,v)=(0,0)$ and $(u,v)=(\\frac{c}{d},\\frac{a}{b})$.\n%Notice also that if $v=0$ (there are no predators), the population of prey will grow exponentially.\nVisualizing the phase portrait helps to give more insight into the dynamics of a system. We will do this by first nondimensionalzing our system to reduce the number of parameters.\nFirst we note that there are exactly two equilibria (fixed points): either $(u,v) = (0,0)$ corresponding to the extinction of both species, or $(u,v) = (\\frac{c}{d},\\frac{a}{b})$.\nFurthermore, from the ODEs we can see that if $v=0$ (there is an absence of any predators) then the population of prey will grow exponentially.\n\nTo get a better idea of the dynamics of this system we will graph its phase portrait.\nWe begin by nondimensionalizing the system to reduce the number of parameters:\nLet $U = \\frac{d}{c}u,$ $V = \\frac{b}{a}v$, $\\bar{t} = at,$ and $\\alpha = \\frac{d}{a}$.\nSubstituting into the original ODEs we obtain the nondimensional system of equations\n\\begin{align}\n\t\\begin{split}\n\t\\frac{dU}{d\\bar{t}} &= U(1-V),\\\\\n\t\\frac{dV}{d\\bar{t}} &= \\alpha V (U-1).\n\t\\end{split}\\label{lotka_volterra}\n\\end{align}\nIn the following code we plot the phase portrait of \\eqref{lotka_volterra} along with a example trajectory, see Figures  \\ref{fig:pred-prey_Lotka_Voterra} and \\ref{fig:pred-prey_Lotka_Voterra_Phase_Portrait}.\nWe will use \\li{scipy.integrate.odeint} which acts similar to the \\li{ode} function used earlier but integrates over all the time steps at once.\nTo plot the direction field for the equations we use \\li{numpy}'s \\li{meshgrid} function and \\li{matplotlib}'s \\li{quiver} function.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{Lotka_Volterra.pdf}\n\\caption{The solution of the nondimensionalized Lotka-Volterra predator-prey equations with parameter $\\alpha = 1/3$.\nThis solution has initial conditions $(U,V) = (3/4, 3/4)$.}\n\\label{fig:pred-prey_Lotka_Voterra}\n\\end{figure}\n\n\\begin{lstlisting}\nfrom scipy.integrate import odeint\na, b = 0., 13.                    # (Nondimensional) Time interval for one 'period'\nalpha = 1. / 3                    # Nondimensional parameter\ndim = 2                           # dimension of the system\ny0 = np.array([1 / 2., 1 / 3.])   # initial conditions\n\n# Note: swapping order of arguments to match the calling convention\n# used in the built in IVP solver.\ndef Lotka_Volterra(y, x):\n    return np.array([y[0] * (1. - y[1]), alpha * y[1] * (y[0] - 1.)])\n\nsubintervals = 200\n# Using the built in ode solver\nY = odeint(Lotka_Volterra, y0, np.linspace(a, b, subintervals))\n\n# Plot the direction field\nY1, Y2 = np.meshgrid(np.arange(0, 4.5, .2), np.arange(0, 4.5, .2), sparse=True, copy=False)\nU, V = Lotka_Volterra((Y1, Y2), 0)\nQ = plt.quiver(Y1[::3, ::3], Y2[::3, ::3],  U[::3, ::3],  V[::3, ::3], pivot='mid', color='b', units='dots',width=3.)\n# Plot the 2 Equilibrium points\nplt.plot(1, 1, 'ok', markersize=8)\nplt.plot(0, 0, 'ok', markersize=8)\n# Plot the solution in phase space\nplt.plot(Y[:,0], Y[:,1], '-k', linewidth=2.0)\nplt.plot(Y[::10,0], Y[::10,1], '*b')\n\nplt.axis([-.5, 4.5, -.5, 4.5])\nplt.title(\"Phase Portrait of the Lotka-Volterra Predator-Prey Model\")\nplt.xlabel('Prey',fontsize=15)\nplt.ylabel('Predators',fontsize=15)\nplt.show()\n\\end{lstlisting}\n\n\\begin{problem}\nCompute the solutions $(U,V)$ of \\eqref{lotka_volterra} \n% \\begin{align*}\n% \t\\frac{dU}{d\\bar{t}} &= U(1-V),\\\\\n% \t\\frac{dV}{d\\bar{t}} &= \\alpha V (U-1).\n% \\end{align*}\nfor initial conditions $(1/2, 3/4)$, $(1/16, 3/4)$, and $(1/40, 3/4)$.\nAdd these solutions to the phase portrait of the Lotka-Volterra model.\nCan you see any limitations of this model?\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{Lotka_Volterra_Phase_Portrait.pdf}\n\\caption{The phase portrait for the nondimensionalized Lotka-Volterra predator-prey equations with parameters $\\alpha = 1/3$.\nThe portrait includes the direction field, the two equilibrium points, and the graph of the solution with initial conditions $(U,V) = (3/4, 3/4)$. }\n\\label{fig:pred-prey_Lotka_Voterra_Phase_Portrait}\n\\end{figure}\n\n\\subsection*{The Logistic model}\nWe have already noticed that in the absence of predators, the Lotka-Volterra equations predict that the prey population will grow exponentially.\nThe logistic predator-prey equations change this dynamic by adding a term to give the prey population a carrying capacity $K$:\n\\begin{align*}\n\t\\frac{du}{dt} &= au\\left(1 -\\frac{u}{K}\\right) - buv,\\\\\n\t\\frac{dv}{dt} &= -cv + duv.\n\\end{align*}\nLet $U = \\frac{u}{K},$ $V = \\frac{b}{a}v$, $\\bar{t} = at,$  $\\alpha = \\frac{dK}{a}$, and $\\beta = \\frac{c}{dK}$.\nThen the nondimensional logistic equations are\n\\begin{align}\n\t\\begin{split}\n\t\\frac{dU}{d\\bar{t}} &= U(1-U-V),\\\\\n\t\\frac{dV}{d\\bar{t}} &= \\alpha V (U-\\beta).\n\t\\end{split} \\label{logistic_pred_prey}\n\\end{align}\n\n\\begin{problem}\nCompute the solutions $(U,V)$ of \\eqref{logistic_pred_prey}\nfor initial conditions $(1/3, 1/3)$ and $(1/2, 1/5)$.\nDo this for parameter values $\\alpha, \\beta = 1, .3$ and also for values $\\alpha, \\beta = 1, 1.1$.\nCreate a phase portrait for the logistic equations using both sets of parameter values.\nRemember to plot the direction field, all equilibrium points, and the orbits of the solutions.\n\\end{problem} \n\\end{comment}\n", "meta": {"hexsha": "a0184e90a07b03a68b6ea88845d76ae2342a34f1", "size": 45602, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume4/WeightLoss/Weightloss.tex", "max_stars_repo_name": "chrismmuir/Labs-1", "max_stars_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 190, "max_stars_repo_stars_event_min_datetime": "2015-07-17T01:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T19:16:19.000Z", "max_issues_repo_path": "Volume4/WeightLoss/Weightloss.tex", "max_issues_repo_name": "chrismmuir/Labs-1", "max_issues_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 184, "max_issues_repo_issues_event_min_datetime": "2015-07-16T17:56:06.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T23:47:14.000Z", "max_forks_repo_path": "Volume4/WeightLoss/Weightloss.tex", "max_forks_repo_name": "chrismmuir/Labs-1", "max_forks_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 76, "max_forks_repo_forks_event_min_datetime": "2015-08-06T02:53:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T11:08:57.000Z", "avg_line_length": 55.1414752116, "max_line_length": 566, "alphanum_fraction": 0.7143107758, "num_tokens": 13902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8376199511728003, "lm_q2_score": 0.8740772466456689, "lm_q1q2_score": 0.732144540656601}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Initial and Terminal}\n\n\\objective{Simplify angles and their coterminal synonyms, and apply them to the three basic trigonometric functions}\n\n\nAngles are a measure of turning.  Since Babylonian times, it has been customary to divide\nthe circle into 360 parts, beginning directly off to the right, and proceeding counter-clockwise.\nThe beginning ray pointing right is known as the \\textbf{initial side}, whereas the ray pointing\noff where the angle has turned to is called the \\textbf{terminal side}.\n\nBecause one direction of spin has been designated as positive, it is therefore true that\nthere exist negative angles.  These also begin at the initial side of $0^\\circ$, but proceed\n\\emph{clockwise}.  Very quickly, there will be multiple names for the same angle.\nAngle that end in the same place are called \\textbf{coterminal}, after the Latin for the same.\nFinding coterminal angles which are the same as a given angle is simply a matter of\nadding or subtracting $360^\\circ$ as many or as few times as desired.\n\nSome processes in mathematic produce very large angle measures, which can become\ncumbersome if dealt with by hand.  While it might be easy in some cases to simply\nadd or subtract $360^\\circ$ until the angle is reasonable, this can become time prohibitive.\nIt is most efficient to find the remainder when an angle is divided by 360.\n\nDegree/Minutes/Seconds will be dealt with in section §16.3, on sexigesimal numbers.\n\n\\subsection{Reference Angles}\nEvery angle can be thought of as a turn from the closest horizontal axis.  In the \nfirst quadrant, this is the angle itself, without modification.  In the fourth quadrant,\nthis is reversed, a certain distance down from $0^\\circ$, or better, back from \n$360^\\circ$.  For example, $330^\\circ$ is an upside-down version of a $30^\\circ$\nangle, which is to say, the reference angle for $330^\\circ$ is $30^\\circ$.\n\nIn the second quadrant, things are not upside down, but mirrored.  What is the reference\nangle for $150^\\circ$?  Well the closest horizontal axis is not $0^\\circ/360^\\circ$, but\n$180^\\circ$.  The reference angle for $150^\\circ$ is also $30^\\circ$.  The third quadrant\nis the hardest, being both flipped left-right, and up-down.  But $30^\\circ$ past\n$180^\\circ$ is $210^\\circ$.\n\n\\begin{figure}[h]\n\\begin{center}\n\\includegraphics{\\chapdir/pics/reference}\n\\caption{Reference angles, sometimes call $\\theta'$ (nothing to do with derivatives!)}\n\\end{center}\n\\end{figure}\n\n\n\\subsection{Trigonometric functions}\nAlso since ancient times, it has been exceedingly helpful to reference the ratios of\nvarious components of an angle.  On a right triangle, these ratios are often memorized with\nthe helpful acronym S.O.H.C.A.H.T.O.A., short for sine = opposite/hypotenuse , cosine = \nadjacent/hypotenuse, tangent = opposite over adjacent.\n\n\\begin{figure}[h]\n\\includegraphics[scale=0.5]{\\chapdir/pics/TrigonometryTriangle.png}\n\\caption{The names of the sides of a right triangle}\n\\end{figure}\n\nThese definitions can be extended via reference angles to the other quadrants.  In \nsuch a context, the sine of an angle \nbecomes the signed vertical displacement over the exact distance, cosine of an\nangle becomes the signed horizontal displacement over the exact distance,\nand tangent of the angle becomes its slope.\n\nWhile no longer of much use or interest, there are names for the reciprocals of\nthe three main trigonometric functions.  The reciprocal of cosine is called\nsecant, the reciprocal of sine is called cosecant, and the reciprocal of tangent\nis called cotangent.  Of these, only secant is commonly used (outside of math\nclassrooms!).\n\n", "meta": {"hexsha": "8a70de1e7a2c9aebeda9d76145649f8353334387", "size": 3640, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch09/0901.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch09/0901.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch09/0901.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.2676056338, "max_line_length": 116, "alphanum_fraction": 0.7752747253, "num_tokens": 877, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888614, "lm_q2_score": 0.8479677583778257, "lm_q1q2_score": 0.7321282510923639}}
{"text": "\\subsection{Belief functions and exchangeability}\n\\begin{frame}{Belief functions}\nLet $F, G$ and $H \\in \\mathcal{S}$ be three (possibly overlapping) statements about the world.\nFor example, consider the following statements about a person:\n\\begin{itemize}\n \\item [F] = \\{votes for a left-wing candidate\\} ;\n \\item [G] = \\{is in the 10\\% lower income bracket\\} ;\n \\item [H] = \\{lives in a large\\} ;\n\\end{itemize}\n\n \\begin{defn}[Belief function]\n \\label{def:belief_function} \n For $A, B \\in \\mathcal{S}$, a belief function $\\be : \\mathcal{S} \\to \\mathbb{R}$ assigns numbers to statements such that $\\be(A) < \\be(B)$ implies one is more confident in $B$ than in $A$.\n \\end{defn}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Belief functions: properties}\nIt is useful to think of $\\be$ as~\\textbf{preferences over bets}:\n \\begin{itemize}\n  \\item $\\be(F) > \\be(G)$ means we would bet on $F$ being true over $G$ being true;\n  \\item $\\be(F\\mid H) > \\be(G \\mid H)$ means that, \\textbf{conditional} on knowing $H$ to be true, we would bet on $F$ over $G$;\n  \\item $\\be(F\\mid G) > \\be(F \\mid H)$ means that if we were forced to be on $F$, we would be prefer doing so if $G$ were true than $H$.\n \\end{itemize}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Belief functions: axioms}\n In order for $\\be$ to be \\textbf{coherent}, it must adhere to a certain set of properties/axioms.\n A self-sufficient collection is:\n \\begin{itemize}\n  \\item [A1]  (boundedness of complete [dis]belief): $$\\be(\\lnot H \\mid H) \\leq \\be(F \\mid H) \\leq \\be(H \\mid H),\\, \\forall\\: F \\in \\mathcal{S};$$\n  \\item [A2]  (monotonicity):\n  $$\\be(F \\, \\text{or} \\, G \\mid H) \\geq \\max \\left\\{ \\be(F \\mid H), \\be(G \\mid H) \\right\\};$$\n  \\item [A3] (sequentiality): There exists $f: \\mathbb{R}^2 \\to \\mathbb{R}$ such that\n  $$ \\be(F\\, \\text{and} \\, G \\mid H) = f\\left(\\be(G\\mid H), \\be(F \\mid G\\, \\text{and} \\, H) \\right).$$\n \\end{itemize}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Probabilities can be beliefs!}\n \\begin{exercise}[Probabilities and beliefs]\n  Show that the axioms of belief functions map one-to-one to the axioms of probability:\n  \\begin{itemize}\n   \\item[P1.] $0 \\leq \\pr(E), \\forall E \\in \\mathcal{S}$;\n   \\item[P2.] $\\pr(\\mathcal{S}) = 1$;\n   \\item[P3.] For any countable sequence of disjoint statements $E_1, E_2, \\ldots \\in \\mathcal{S}$ we have\n   $$ \\pr \\left(\\bigcup_{i=1}^\\infty E_i \\right) = \\sum_{i=1}^\\infty \\pr(E_i).$$\n  \\end{itemize}\n \\end{exercise}\nHint: derive the consequences (e.g. monotonicity) of these axioms and compare them with the axioms of belief functions.\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Useful probability laws}\n\\begin{defn}[Partition]\n \\label{def:partition}\n If $H = \\{H_1, H_2, \\ldots, H_k\\}$, $H_i \\in \\mathcal{S}$, such that $H_i \\cap H_j = \\emptyset$  for all $i \\neq j$ and $\\bigcup_{k=1}^K = \\mathcal{S}$, we say $H$ is a partition of $\\mathcal{S}$.\n\\end{defn}\nFor any $H \\in \\mathcal{D}(\\mathcal{S})$:\n \\begin{itemize}\n  \\item \\textbf{Total probability}: $\\sum_{k=1}^K \\pr(H_k) = 1$;\n  \\item \\textbf{Marginal probability}: $$\\pr(E) = \\sum_{k=1}^K = \\pr(E \\cap H_k) =  \\sum_{k=1}^K \\pr(E \\mid H_k)\\pr(H_k),$$\n  for all $E \\in \\mathcal{S}$;\n  \\item Consequence $\\implies$ Bayes's rule:\n$$ \\pr(H_j \\mid E) = \\frac{\\pr(E \\mid H_j)\\pr(H_j)}{\\sum_{k=1}^K \\pr(E \\mid H_k)\\pr(H_k)}.$$\n  \\end{itemize}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Independence}\nWe will now state a central concept in probability theory and Statistics.\n \\begin{defn}[ (Conditional) Independence]\n  For any $F, G \\in \\mathcal{S}$, we say $F$ and $G$ are~\\textbf{conditionally independent} given $A$ if \n  $$ \\pr(F \\cap G \\mid A) = \\pr(F\\mid A)\\pr(G\\mid A).$$  \n \\end{defn}\n\\begin{remark}\n \\label{rmk:conditional_indep}\n If $F$ and $G$ are conditionally independent given $A$, then\n $$ \\pr(F \\mid A \\cap G) = \\pr(F \\mid A).$$\n\\end{remark}\n\\begin{proof}\n First, notice that the axioms P1-P3 imply $\\pr(F \\cap G \\mid A) = \\pr(G\\mid A)\\pr(F \\mid A \\cap G)$.\n Now use conditional independence to write\n \\begin{align*}\n  \\pr(G \\mid A) \\pr(F \\mid A \\cap G) &= \\pr(F \\cap G \\mid A) = \\pr(F\\mid A)\\pr(G\\mid A),\\\\\n  \\pr(G\\mid A) \\pr(F \\mid A \\cap G) &= \\pr(F\\mid A) \\pr(G \\mid A).\n \\end{align*} \n\\end{proof} \n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Exchangeability} \n\\begin{defn}[Exchangeable]\n \\label{def:exchangeable}\nWe say a sequence of random variables $\\boldsymbol{Y} = \\{ Y_1, Y_2, \\ldots, Y_n \\}$ are \\textbf{exchangeable} if \n$$ \\pr(Y_1, Y_2, \\ldots Y_n) = \\pr(Y_{\\xi_1}, Y_{\\xi_2}, \\ldots Y_{\\xi_n}),$$\nfor all \\textbf{permutations} $\\boldsymbol{\\xi}$ of the labels of $\\boldsymbol{Y}$.\n\\end{defn}\n\\begin{example}[Uma vez Flamengo... continued]\n Suppose we survey 12 people and record whether they cheer for Flamengo $Y_i = 1$ or not $Y_i = 0$, $i=1, 2,\\ldots, 12$.\n What value shoud we assign to :\n \\begin{itemize}\n  \\item $p_1 := \\pr(1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1)$;\n  \\item $p_2 :=\\pr(1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1)$;\n  \\item $p_3 := \\pr(1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0)$?\n \\end{itemize}\nIf your answer is $p_1 = p_2 = p_3$ then you are saying the $Y_i$ are (at least partially) exchangeable!\n\\end{example}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{An application of conditional independence}\nFor $\\theta \\in (0, 1)$, consider the following sequence of probability statements:\n\\begin{align*}\n\\pr(Y_{12} = 1 \\mid \\theta) &= \\theta,\\\\\n\\pr(Y_{12} = 1 \\mid Y_1, \\ldots Y_{11}, \\theta) & = \\theta,\\\\\n\\pr(Y_{11} = 1 \\mid Y_1, \\ldots Y_{10}, Y_{12}, \\theta) &= \\theta.\n\\end{align*}\nThese imply that the $Y_i$ are conditionally independent and identically distributed (iid), and in particular:\n\\begin{align*}\n \\pr(Y_1 = y_1, \\ldots, Y_{12} = y_{12} \\mid \\theta) &= \\prod_{i=1}^{12} \\theta^{y_i} (1-\\theta)^{1-y_i},\\\\\n &= \\theta^{S} (1-\\theta)^{12-S},\n\\end{align*}\nwith $S := \\sum_{i=1}^{12} y_i$.\nAlso, under a uniform prior, \n$$ \\pr(Y_1, \\ldots Y_{12}) = \\int_{0}^1 t^{S} (1-t)^{12-S} \\pi(t)\\,dt = \\frac{(S + 1)!(12-S +1)!}{13!} = \\binom{13}{S + 1}^{-1}.$$\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Relaxing exchangeability (a bit)}\n Sometimes total symmetry can be a burden. \n We can relax this slightly by introducing the concept of \\textbf{partial exchangeability}:\n \\begin{defn}[Partially exchangeable]\n  \\label{def:partially_exchangeable}\n  Let $\\boldsymbol{X} = \\{ X_1, \\ldots, X_n\\}$ and $\\boldsymbol{X} = \\{ Y_1, \\ldots, Y_m\\}$ be two sets of random variables.\n  We say $\\boldsymbol{X}$ and $\\boldsymbol{Y}$ are \\textbf{partially} exchangeable if\n  $$ \\pr\\left(X_1, \\ldots, X_n ; Y_1, \\ldots, Y_m\\right) = \\pr\\left(X_{\\xi_1}, \\ldots, X_{\\xi_n} ; Y_{\\sigma_1}, \\ldots, Y_{\\sigma_m}\\right),$$\n \\end{defn}\n for any two permutations $\\boldsymbol{\\xi}$ and $\\boldsymbol{\\sigma}$ of $1, \\ldots, n$ and $1, \\ldots, m$, respectively.\n \\begin{example}[Uma vez Flamengo...continued]\n  To see how exchangeability can be relaxed into partial exchangeability, consider $\\boldsymbol{X}$ and $\\boldsymbol{Y}$ as observations coming from populations from Rio de Janeiro and Ceará, respectively.\n  If the covariate ``state'' were deemed to not matter, then we would have complete exchangeability.\n \\end{example}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A statistically useful remark}\n \\begin{remark}[Exchangeability from conditional independence]\n  \\label{rmk:pre_deFinetti}\n  Take $\\theta \\sim \\pi(\\theta)$, i.e., represent uncertainty about $\\theta$ using a probability distribution. \n  If $ \\pr(Y_1 = y_1, \\ldots, Y_{n} = y_n \\mid \\theta) = \\prod_{i=1}^{n} \\pr(Y_i = y_i \\mid \\theta)$, then $Y_1, \\ldots, Y_{n}$ are exchangeable.\n \\end{remark}\n \\begin{proof}\n  Sketch:\n  Use\n  \\begin{itemize}\n   \\item Marginalisation;\n   \\item Conditional independence;\n   \\item Commutativity of products in $\\mathbb{R}$;\n   \\item Definition of exchangeability.\n  \\end{itemize}\n \\end{proof}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A fabulous theorem!}\n \\begin{theo}[De Finetti's theorem\\footnote{Technically, the theorem stated here is more general than the representation theorem proven by De Finetti in his seminal memoir, which concerned binary variables only.}]\n  If $\\pr\\left(Y_1, \\ldots, Y_n\\right) = \\pr\\left(Y_{\\xi_1}, \\ldots, Y_{\\xi_n}\\right)$ for all permutations $\\boldsymbol{\\xi}$ of $1, \\ldots, n$, then\n  \\begin{equation}\n   \\pr\\left(Y_1, \\ldots, Y_n\\right) = \\pr\\left(Y_{\\xi_1}, \\ldots, Y_{\\xi_n}\\right) = \\int_{\\boldsymbol{\\Theta}} \\pr\\left(Y_1, \\ldots, Y_n \\mid t\\right) \\pi(t)\\,dt,\n  \\end{equation}\nfor some choice of triplet $\\{ \\theta,  \\pi(\\theta), f(y_i \\mid \\theta) \\}$, i.e., a parameter, a prior and a sampling model.\n \\end{theo}\n See Proposition 4.3 in \\cite{Bernardo2000} for a proof outline.\n Here we shall prove the version from~\\cite{DeFinetti1931}.\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Consequences}\n  This theorem has a few important implications, namely:\n \\begin{itemize}\n  \\item $\\pi(\\theta)$ represents our beliefs about $\\lim_{n\\to\\infty} \\sum_i (Y_i \\leq c)/n$ for all $c \\in \\mathcal{Y}$;\n  \\item \\{ $Y_1, \\ldots, Y_n \\mid \\theta $ are i.i.d \\} + \\{ $\\theta \\sim \\pi(\\theta)$ \\} $\\iff$ \\{ $Y_1, \\ldots, Y_n$ are exchangeable for all $n$ \\};\n  \\item If $Y_i \\in \\{0, 1\\}$, we can also claim that:\n  \\begin{itemize}\n   \\item If the $Y_i$ are assumed to be independent, then they are distributed Bernoulli conditional on a random quantity $\\theta$;\n   \\item $\\theta$ has a prior measure $\\Pi \\in \\mathcal{P}( (0, 1) )$;\n   \\item By the strong law of large numbers (SLLN), $\\theta = \\lim_{n \\to \\infty} (\\frac{1}{n}\\sum_{i=1}^n Y_i)$, so $\\Pi$ can be interpreted as a ``belief about the limiting relative frequency of 1's''.\n  \\end{itemize}\n \\end{itemize}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{The soul of Statistics}\n As the exchangeability results above clearly demonstrate, being able to use conditional independence is a handy tool.\n More specifically, knowing on what to condition so as to make things exchangeable is key to statistical analysis.\n \\begin{idea}[Conditioning is the soul of Statistics\\footnote{This idea is due to Joe Blitzstein, who did his PhD under no other than the great Persi Diaconis.}] \n Knowing on what to condition can be the difference between an unsolvable problem and a trivial one.\n When confronted with a statistical problem, always ask yourself ``What do I know for sure?'' and then ``How can I create a conditional structure to include this information?''.\n \\end{idea}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Recommended reading}\n\\begin{itemize}\n  \\item[\\faBook] \\cite{Hoff2009} Ch. 2 and $^\\ast$\\cite{Schervish2012} Ch.1;\n \\item $^\\ast$Paper: \\cite{Diaconis1980} explains why if $n$ samples are taken from an exchangeable population of size $N \\gg n$ without replacement, then the sample $Y_1, \\ldots Y_n$ can be modelled as approximately exchangeable;\n \\item[\\faForward] Next lecture: \\cite{Robert2007} Ch. 3.\n \\end{itemize} \n\\end{frame}\n", "meta": {"hexsha": "7741474f6be0b13a5f993c0c0cbd07e2dc5e3848", "size": 11056, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/lecture_3.tex", "max_stars_repo_name": "lucasmoschen/BayesianStatisticsCourse", "max_stars_repo_head_hexsha": "79fe17dd71fa9638ae4865c8e75eeb0f814d2ccb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-03-17T17:39:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T23:40:56.000Z", "max_issues_repo_path": "slides/lecture_3.tex", "max_issues_repo_name": "anhnguyendepocen/BayesianStatisticsCourse", "max_issues_repo_head_hexsha": "79fe17dd71fa9638ae4865c8e75eeb0f814d2ccb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-24T01:28:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T20:49:10.000Z", "max_forks_repo_path": "slides/lecture_3.tex", "max_forks_repo_name": "anhnguyendepocen/BayesianStatisticsCourse", "max_forks_repo_head_hexsha": "79fe17dd71fa9638ae4865c8e75eeb0f814d2ccb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-05-26T16:28:02.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T12:33:26.000Z", "avg_line_length": 55.5577889447, "max_line_length": 230, "alphanum_fraction": 0.640918958, "num_tokens": 3808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677468516188, "lm_q2_score": 0.8633916047011595, "lm_q1q2_score": 0.7321282336890458}}
{"text": "%\\chapter{Differential Equations}\nMany physical phenomena can be modeled using the\nlanguage of calculus. For example, observational evidence suggests\nthat the temperature of a cup of tea (or some other liquid) in a\nroom of constant temperature will cool over time at a rate\nproportional to the difference between the room temperature  and the\ntemperature of the tea.\n\nIn symbols, if $t$ is the time, $M$ is the room temperature,\nand $f(t)$ is the temperature of the tea at time $t$ then $f'(t) =\nk(M-f(t))$ where $k>0$ is a constant which will depend on the kind of tea\n(or more generally the kind of liquid) but not on the room temperature\nor the temperature of the tea. This is \\dfont{Newton's law of\n  cooling} and the equation that we\njust wrote down is an example of a \\dfont{differential\n  equation}.  Ideally we would like to\nsolve this equation, namely, find the function $f(t)$ that describes\nthe temperature over time, though this often turns out to be\nimpossible, in which case various approximation techniques must be\nused.  The use and solution of differential equations is an important\nfield of mathematics; here we see how to solve some simple but useful\ntypes of differential equation.\n\nInformally, a differential equation is an equation in which one or\nmore of the derivatives of some function appears. Typically, a\nscientific theory will produce a differential equation (or a system of\ndifferential equations) that describes or governs some physical\nprocess, but the theory will not produce the desired function or\nfunctions directly.\n", "meta": {"hexsha": "ed2bb0ef68f9e06d18fedee95614b00c10509952", "size": 1553, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10-differential-equations/10-0-intro.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "10-differential-equations/10-0-intro.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "10-differential-equations/10-0-intro.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.7666666667, "max_line_length": 73, "alphanum_fraction": 0.7894397939, "num_tokens": 352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942145139149, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7321009153899979}}
{"text": "\\section{The Gradient}\r\n\\noindent\r\nIf you have a surface $f: \\mathbb{R}^2 \\to \\mathbb{R}$, what direction $\\langle \\Delta x, \\Delta y \\rangle$ should I go to maximize the change if $f$?\\\\\r\nWe saw earlier that $\\Delta z\\approx \\langle f_x, f_y \\rangle \\cdot \\langle \\Delta x, \\Delta y \\rangle$. To maximize a dot product, $\\langle \\Delta x, \\Delta y \\rangle$ should be in the same direction as $\\langle f_x, f_y \\rangle$. This directional vector is called the gradient: the direction of steepest ascent.\\\\\r\nNotated mathematically,\r\n\\begin{equation*}\r\n\t\\nabla f(x,y) = \\langle f_x, f_y \\rangle\r\n\\end{equation*}\r\n\r\n[INSERT IMAGE]\r\n\r\n\\input{./differentialMultivariableCalculus/gradientProperties}\r\n\\input{./differentialMultivariableCalculus/linearApproximationsGradient}\r\n\\input{./differentialMultivariableCalculus/gradientCLevelCurves}", "meta": {"hexsha": "c849b04995113fab3d669c0d19e38efe0a5da76a", "size": 832, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/theGradient.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/theGradient.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/theGradient.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.4285714286, "max_line_length": 316, "alphanum_fraction": 0.75, "num_tokens": 241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7321008986376707}}
{"text": "\\section{Hamming Distance}\n\\subsection{Theory}\nHamming distance of two integers, each 32 bits, is the number of changes that are necessary to change one integer to another. In other words, if A and B are two 32 bits integer, the hamming distance between the two, denoted by $hamdist(A,B)$ is defined as follows:\n\\begin{equation}\\label{hammingdist}\n\t\thamdist(A,B) = \\sum_{i=0}^{31}\\left[A(i) \\neq B(i)\\right],\n\\end{equation}\nwhere $A(i)$ represents the $i^{th}$ bit of A. Hamming distance is bounded between 0 (in the case that $\\forall i, A(i)==B(i)$) and 32 (in the case that $\\forall i, A(i)\\neq B(i)$). Hamming distance has the following properties:\n\\begin{itemize}\n\n\\item{}\nHamming distance is a symmetric operator as the hamming distance of A and B is the same as hamming distance of B and A:\n\\begin{equation}\\label{symmetry}\n\t\thamdist(A, B) == hamdist(B,A)\n\\end{equation}\n\n\\item{}\nThe hamming distance of a 32 bit integer is bounded between 0 and 32. In general, the hamming distance of two n-bit numbers is bounded between 0 and n:\n\\begin{equation}\\label{bounded}\n\t\\forall A,B \\in \\left[0, 2^n-1 \\right], \\mbox{where}\\ A, B \\in \\mathbb{N}, 0 \\leq hamdist(A, B) \\leq n\n\\end{equation}\n\n\\item{}\nThe hamming distance of any integer with it self is zero.  \n\n\\begin{equation}\\label{ZReflect}\n\t\thamdist(A, A) == 0\n\\end{equation}\n\\end{itemize}\n\nIn the following section, we use the above-mentioned properties to compute the minimum hamming distance of an array of integers.\n\n\\subsection{Minimum Hamming Distance of an array of 32-bit integers}\nThe minimum hamming distance of an array is the minimum hamming distance of any two distinct integers of the array. The minimum hamming distance of array $A$ is defined as follows:\n\\begin{equation}\\label{HammingDistArray}\n\t\\begin{gathered}\n         i, j, n \\in \\mathbb{N}\\\\\n        \\forall i \\in \\left[0, n\\right]\\\\\n        \\forall j \\in \\left[0, n\\right]\\\\\n        d = min(hamdist(A(i), A(j)))\n\t\\end{gathered}\n\\end{equation}\n\nHere, we use the properties of hamming distance operator in order to further improve the algorithm.\n\n\\begin{equation}\\label{HammingDistArrayOpt}\n\t\\begin{gathered}\n         i, j, n \\in \\mathbb{N}\\\\\n        \\forall i \\in \\left[0, n\\right]\\\\\n        \\forall j \\in \\left[i+1, n\\right]\\\\\n        d = min(hamdist(A(i), A(j)))\n\t\\end{gathered}\n\\end{equation}\n\nThe above algorithm reduces the number of iterations required for finding the minimum distance. We used \\ref{symmetry} to avoid computing hamming distance of $hamdist(A(i), A(j))$ when $hamdist(A(j), A(i))$ has already been computed. We used \\ref{ZReflect} to avoid computing hamming distance when $i==j$. These two improvements were achieved by starting $j$ from $i+1$. Since we are looking for minimum hamming distance, we used \\ref{bounded} to exit the loop as soon as a minimum distance of 0 is computed. \n\n\\subsection{Source Code And Results}\nWith the algorithm defined in the previous section, we have attempted to implement it using C++. The source code for this project can be founded in this github repository: \\href{https://github.com/hossein1387/random_sw_experiments/tree/master/hamming_distance}{GitHub Repository For Min Hamming Distance}. \n\\markdownInput{Hamming.md}\n", "meta": {"hexsha": "2651d7320e2f99a9e55892fb88b74d410235dd21", "size": 3204, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hamming_distance/docs/Hamming.tex", "max_stars_repo_name": "hossein1387/random_sw_experiments", "max_stars_repo_head_hexsha": "9b5163e2e67b7f3d89f67e57e1c7aa3b8b40011c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-05-04T03:21:06.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-04T03:21:06.000Z", "max_issues_repo_path": "hamming_distance/docs/Hamming.tex", "max_issues_repo_name": "hossein1387/random_sw_experiments", "max_issues_repo_head_hexsha": "9b5163e2e67b7f3d89f67e57e1c7aa3b8b40011c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hamming_distance/docs/Hamming.tex", "max_forks_repo_name": "hossein1387/random_sw_experiments", "max_forks_repo_head_hexsha": "9b5163e2e67b7f3d89f67e57e1c7aa3b8b40011c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.3050847458, "max_line_length": 509, "alphanum_fraction": 0.7256554307, "num_tokens": 916, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.9032941988938413, "lm_q1q2_score": 0.7321008965277137}}
{"text": "% Section 4: Algorithms\n\\section{Algorithms}\n\n\n\n\n\\subsection{ADMM method for dual problem}\nFor convenience, introducing relaxation variables, we reformulate the dual problem as:\n\n\\begin{equation}\n  \\begin{array}{rl}\n    {\\mathrm{(dual)}} & {\\min -_{u,v} \\sum_{i=1}^{m} \\mu_{i} u_{i}-\\sum_{j=1}^{n} \\nu_{j} v_{j}} + I_{\\mathbb{R}_+^{m\\times n}}(\\xi)\\\\\n    {\\text { subject to }} & {c_{ij} - u_i - v_j -\\xi_{ij}= 0\\qquad\\forall i=1, \\ldots, m \\quad j = 1,\\cdots,n}\n    \\end{array}\n\\end{equation}\n\nThen we have the augmented Lagrangian:\n\n\\begin{equation}\n  \\begin{aligned}L(u, v, \\xi, w)=&-\\sum_{i=1}^{m} \\mu_{i} u_{i}-\\sum_{j=1}^{n} \\nu_{j} v_{j} + I_{\\mathbb{R}_+^{m\\times n}}(\\xi)\\\\&+\\sum_{i=1}^{m} \\sum_{j=1}^{n} w_{i j}\\left(c_{i j}-u_{i}-v_{j}-\\xi_{i j}\\right)+\\frac{\\rho}{2} \\sum_{i=1}^{m} \\sum_{j=1}^{n}\\left(c_{i j}-u_{i}-v_{j}-\\xi_{i j}\\right)^{2}\\end{aligned}\n\\end{equation}\n\n$\\partial_{\\xi_{ij}} L = 0$ gives:\n\n\\begin{equation}\n  \\xi_{ij} = (c_{ij} - u_i - v_j + \\frac{w_{ij}}{\\rho})_+\n\\end{equation}\n\n$\\partial_{u_i}L = 0$ gives:\n\n\\begin{equation}\n  u_i = \\frac{1}{n}\\left(\\frac{\\mu_{i}+\\sum_{j=1}^{n} w_{i j}}{\\rho}+\\sum_{j=1}^{n}\\left(c_{i j}-v_{j}-\\xi_{i j}\\right)\\right)\n\\end{equation}\n\n$\\partial_{v_j} L = 0$ gives:\n\\begin{equation}\n  v_j = \\frac{1}{n}\\left(\\frac{\\nu_{j}+\\sum_{i=1}^{m} w_{i j}}{\\rho}+\\sum_{i=1}^{m}\\left(c_{i j}-u_{j}-\\xi_{i j}\\right)\\right)\n\\end{equation}\n\n\\vspace{2ex}\n    \\begin{algorithm}[htbp]\n        \\SetAlgoNoLine\n        \\caption{ADMM method for dual problem} \n        \\KwIn{parameters $\\mu$, $\\nu$, $c$}\n        \\KwIn{step size $\\alpha$, penalty $\\rho$}\n        Initialize variables $u, v = \\boldsymbol{0}$\\\\\n        Initialize variables $\\xi, w = \\boldsymbol{0}$\\\\\n        \\While{ stopping criterion not met } \n        {  \n            Update $u$: $\\boldsymbol{u} \\leftarrow \\operatorname{argmin}_{u} L(u, v, \\xi, w)$\\\\\n            Update $\\pi^{\\dagger}$: $\\boldsymbol{\\pi}^{\\dagger} \\leftarrow \\operatorname{argmin}_{u} L(u, v, \\xi, w)$\\\\\n            Update $\\xi$: $\\boldsymbol{\\xi} \\leftarrow \\operatorname{argmin}_{\\xi} L(u, v, \\xi, w)$\\\\\n            Update $w$: $\\boldsymbol{w} \\leftarrow w + \\rho\\cdot \\alpha (\\pi - \\pi^{\\dagger})$\\\\\n        }\n    \\end{algorithm}\n\n\\subsection{Entropic Regularization Methods}\nThe Kullback-Leibler divergence is defined as \n\n\\begin{equation}\n  \\mathbf{K L}(\\mathbf{P} | \\mathbf{Q}) \\stackrel{\\text { def. }}{=} \\sum_{i, j} \\mathbf{P}_{i, j} \\log \\left(\\frac{\\mathbf{P}_{i, j}}{\\mathbf{Q}_{i, j}}\\right)-\\mathbf{P}_{i, j}+\\mathbf{Q}_{i, j}\n\\end{equation}\n\nwith the convention $0 \\log(0) = 0$ and $\\mathbf{K L}(\\mathbf{P} | \\mathbf{Q}) = +\\infty$ if there exists some $(i, j)$ such that $\\mathbf{Q}_{i,j} = 0$ but $\\mathbf{P}_{i,j} \\neq 0$. The special case $\\mathbf{K L}(\\mathbf{P} | \\mathbf{1})$ corresponds to minus the Shannon-Boltzmann entropy. The function $\\mathbf{K L}(\\cdot | \\mathbf{Q})$ is strongly convex, because its hessian is $\\partial^{2} \\mathbf{K L}(\\mathbf{P} | \\mathbf{Q})=\\operatorname{diag}\\left(1 / \\mathbf{P}_{i, j}\\right)$ and $\\mathbf{P}_{i,j} \\leq 1$.\n\nThe idea of the entropic regularization of optimal transport is to use $\\mathbf{KL}$ as a regularizing function to obtain approximate solutions to the original transport problem:\n\n\\begin{equation}\n  \\label{eq:entropy_regularization}\n  \\mathrm{L}_{\\mathbf{C}}^{\\varepsilon}(\\mathbf{\\mu}, \\mathbf{\\nu}) \\stackrel{\\text { def. }}{=} \\min _{\\mathbf{P} \\in \\mathbf{U}(\\mathbf{\\mu}, \\mathbf{\\nu})}\\langle\\mathbf{P}, \\mathbf{C}\\rangle+\\varepsilon \\mathbf{K L}(\\mathbf{P} | \\mathbf{\\mu} \\otimes \\mathbf{\\nu})\n\\end{equation}\n\nHere we used as a reference measure for the relative entropy $\\mathbf{\\mu} \\otimes \\mathbf{\\nu}=\\left(\\mathbf{\\mu}_{i} \\mathbf{\\nu}_{j}\\right)_{i, j}$. This choice of normalization, specially in this discrete setting, has no importance for the selection of the optimal $\\mathbf{P}$ since it only affects the objective by a constant, indeed for $\\mathbf{P} \\in \\mathbf{U}(\\mathbf{\\mu}, \\mathbf{\\nu})$, one has \n\n\\begin{equation}\n  \\mathbf{K L}(\\mathbf{P} | \\mathbf{\\mu} \\otimes \\mathbf{\\nu})=\\mathbf{K} \\mathbf{L}\\left(\\mathbf{P} | \\mathbf{\\mu}^{\\prime} \\otimes \\mathbf{\\nu}^{\\prime}\\right)+\\mathbf{K} \\mathbf{L}\\left(\\mathbf{\\mu}^{\\prime} \\otimes \\mathbf{\\nu}^{\\prime} | \\mathbf{\\mu} \\otimes \\mathbf{\\nu}\\right)\n\\end{equation}\n\nAt this time, the approximate optimal transport problem has the $\\epsilon$-strongly convex objective function, so it has a unique solution. Theoretically, As $\\epsilon$ approaches 0, the optimal solution of the approximate optimal transport problem $\\mathbf{P}_{\\epsilon}$ converges to the optimal solution of the Kantorovich optimal transport problem. At this time, we can use the Sinkhorn algorithm to solve this problem with entropy regularization.\n\n\\begin{figure}[htbp]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{img/regularized}\n  \\label{fig:regularized}\n  \\caption{Impact of $\\epsilon$ on the optimization of a linear function on the simplex}\n\\end{figure}\n\n\\subsection{Sinkhorn Algorithm}\nThe following theorem [4] shows that the solution of \\ref{eq:entropy_regularization} has a specific form, which can be parameterized\nusing $m + n$ variables. That parameterization is therefore essentially dual, in the sense that a coupling $\\mathbf{P}$ in\n$\\mathbf{U}(a, b)$ has $nm$ variables but $n + m$ constraints.\n\n\\paragraph{Theorem}\n  $\\mathbf{P}$ is the unique solution to \\ref{eq:entropy_regularization} if and only if there exists $(u, v) \\in R$ such that\n  \n  \\begin{equation}\n    \\label{eq:thm1}\n    \\forall(i, j) \\in [m] \\times [n], \\quad \\mathbf{P}_{i, j}=\\mathbf{u}_{i} \\mathbf{K}_{i, j} \\mathbf{v}_{j}\n  \\end{equation}\n  and $\\mathbf{P} \\in \\mathcal{U}(\\mathbf{\\mu}, \\mathbf{\\nu})$.\n\nThis can be proved by introducing two dual variables $\\mathbf{f} \\in \\mathbb{R}^{m}, \\mathbf{g} \\in \\mathbb{R}^{n}$ for each marginal constraint, the Lagrangian of \\ref{eq:entropy_regularization}\nreads\n\n\\begin{equation}\n  \\mathcal{E}(\\mathbf{P}, \\mathbf{f}, \\mathbf{g})=\\langle\\mathbf{P}, \\mathbf{C}\\rangle+\\varepsilon \\mathbf{K} \\mathbf{L}(\\mathbf{P} | \\mathbf{\\mu} \\otimes \\mathbf{\\nu})+\\left\\langle\\mathbf{f}, \\mathbf{\\mu}-\\mathbf{P} \\mathbf{1}_{m}\\right\\rangle+\\left\\langle\\mathbf{g}, \\mathbf{\\nu}-\\mathbf{P}^{\\mathrm{T}} \\mathbf{1}_{n}\\right\\rangle\n\\end{equation}\n\nConsidering first order conditions (where we ignore the positivity constraint, which can be made rigorous by\nshowing the associated multiplier vanishes), we have\n\n\\begin{equation}\n  \\label{eq:partial}\n  \\frac{\\partial \\mathcal{E}(\\mathbf{P}, \\mathbf{f}, \\mathbf{g})}{\\partial \\mathbf{P}_{i, j}}=\\mathbf{C}_{i, j}+\\varepsilon \\log \\left(\\frac{\\mathbf{P}_{i, j}}{\\mathbf{\\mu}_{i} \\mathbf{\\nu}_{j}}\\right)-\\mathbf{f}_{i}-\\mathbf{g}_{j}=0\n\\end{equation}\n\nwhich results, for an optimal $\\mathbf{P}$ coupling to the regularized problem, in the expression $\\mathbf{P}_{i, j}=\\mathbf{\\mu}_{i} \\mathbf{\\nu}_{j} e^{\\frac{\\mathbf{f}_{i}+\\mathbf{g}_{j}-\\mathbf{C}_{i, j}}{\\varepsilon}}$ \nwhich can be rewritten in the form provided in the proposition using non-negative vectors\n\\begin{equation}\n  \\mathbf{u} \\stackrel{\\text { def. }}{=}\\left(\\mathbf{\\mu}_{i} e^{\\mathbf{f}_{i} / \\varepsilon}\\right)_{i}, \\qquad \\text{and} \\qquad \\mathbf{v} \\stackrel{\\text { def. }}{=}\\left(\\mathbf{\\nu}_{j} e^{\\mathbf{g}_{j} / \\varepsilon}\\right)_{j}\n\\end{equation}\n\nThe factorization of the optimal solution exhibited in Equation \\ref{eq:thm1} can be conveniently rewritten in\nmatrix form as $P = diag(u)K diag(v)$. $\\mathbf{u}, \\mathbf{v}$ must therefore satisfy the following non-linear equations which\ncorrespond to the mass conservation constraints inherent to $\\mathbf{U}(a, b)$,\n\n\\begin{equation}\n\\operatorname{diag}(\\mathbf{u}) \\mathbf{K} \\operatorname{diag}(\\mathbf{v}) \\mathbf{1}_{n}=\\mathbf{\\mu}, \\quad \\text { and } \\quad \\operatorname{diag}(\\mathbf{v}) \\mathbf{K}^{\\top} \\operatorname{diag}(\\mathbf{u}) \\mathbf{1}_{m}=\\mathbf{\\nu}\n\\end{equation}\n\nThese two equations can be further simplified, since $\\operatorname{diag}(v) \\mathbf{1}_n$ is $v$, and the multiplication of $\\operatorname{diag}(u)$ times $\\mathbf{Kv}$ is\n\n\\begin{equation}\n  \\label{eq:2}\n  \\mathbf{u} \\odot(\\mathbf{K} \\mathbf{v})=\\mathbf{\\mu} \\quad \\text { and } \\quad \\mathbf{v} \\odot\\left(\\mathbf{K}^{\\mathrm{T}} \\mathbf{u}\\right)=\\mathbf{\\nu}\n\\end{equation}\n\nwhere $\\odot$ corresponds to entry-wise multiplication of vectors. That problem is known in the numerical analysis\ncommunity as the matrix scaling problem. An intuitive way to try to solve these equations is to solve them iteratively, by modifying first $u$ so that it satisfies the left-hand side of\nEquation \\ref{eq:2} and then $\\mathbf{v}$ to satisfy its right-hand side. These two updates define Sinkhorn's algorithm\n\n\\begin{equation}\n  \\label{eq:sinkhorn}\n  \\mathbf{u}^{(\\ell+1)} \\stackrel{\\text { def. }}{=} \\frac{\\mathbf{\\mu}}{\\mathbf{K} \\mathbf{v}^{(\\ell)}} \\quad \\text { and } \\quad \\mathbf{v}^{(\\ell+1)} \\stackrel{\\text { def. }}{=} \\frac{\\mathbf{\\nu}}{\\mathbf{K}^{\\mathrm{T}} \\mathbf{u}^{(\\ell+1)}}\n\\end{equation}\n\n\\vspace{2ex}\n    \\begin{algorithm}[htbp]\n        \\SetAlgoNoLine\n        \\caption{Sinkhorn algorithm} \n        \\KwIn{parameters $\\mu$, $\\nu$, $c$}\n        \\KwIn{epsilon $\\epsilon$}\n        Initialize variables $u, v = \\boldsymbol{1}$\\\\\n        Initialize  $\\mathbf{K} = \\exp^{-c/\\epsilon}$\\\\\n        \\While{ stopping criterion not met } \n        {  \n          Update $u$: $\\boldsymbol{u} \\leftarrow \\frac{\\mathbf{\\mu}}{\\mathbf{K} \\mathbf{v}}$\\\\\n          Update $v$: $\\boldsymbol{v} \\leftarrow \\frac{\\mathbf{\\nu}}{\\mathbf{K}^T \\mathbf{u}}$\\\\\n\n        }\n        Calculate $\\mathbf{P} = (\\operatorname{diag}{\\mathbf{u}}) \\mathbf{K} (\\operatorname{diag}{\\mathbf{v}})$\\\\\n    \\end{algorithm}\n\n\n\\subsection{Block Coordinate Ascent Method}\nIn practice, the Sinkhorn algorithm suffers from numerical\noverflow when the regularization parameter $\\epsilon$ is small compared to the entries of the cost\nmatrix $\\mathbf{C}$. This concern can be alleviated to some extent by carrying out computations\nin the log domain. The relevance of this approach is made more clear by considering\nthe dual problem associated to \\ref{eq:entropy_regularization}, in which these log-domain computations arise\nnaturally.\n\nFrom equation \\ref{eq:partial} we have\n\\begin{equation}\n  \\mathbf{P}_{i, j}=e^{\\mathbf{f}_{i} / \\varepsilon} e^{-\\mathbf{C}_{i, j} / \\varepsilon} e^{\\mathbf{g}_{j} / \\varepsilon}\n\\end{equation}\n\nSubstituting the optimal $\\mathbf{P}$ in the Lagrangian $E(P,f, g)$ of Equation \\ref{eq:entropy_regularization} as a function of $\\mathbf{f}$ and $\\mathbf{g}$, we obtain that the Lagrangian dual function equals\n\n\\begin{equation}\n  \\label{eq:fg}\n  \\mathbf{f}, \\mathbf{g} \\mapsto\\left\\langle e^{\\mathbf{f} / \\varepsilon},(\\mathbf{K} \\odot \\mathbf{C}) e^{\\mathbf{g} / \\varepsilon}\\right\\rangle-\\varepsilon \\mathbf{H}\\left(\\operatorname{diag}\\left(e^{\\mathbf{f} / \\varepsilon}\\right) \\mathbf{K} \\operatorname{diag}\\left(e^{\\mathbf{g} / \\varepsilon}\\right)\\right)\n\\end{equation}\n\nThe neg-entropy of $\\mathbf{P}$ scaled by $\\epsilon$, namely $\\varepsilon\\left\\langle\\mathbf{P}, \\log \\mathbf{P}-\\mathbf{1}_{n \\times m}\\right\\rangle$, can be stated explicitly as a function as $\\mathbf{f}$, $\\mathbf{g}$, $\\mathbf{C}$, \n\n\\begin{equation}\n  \\begin{aligned}\n    &\\left\\langle\\operatorname{diag}\\left(e^{\\mathbf{f} / \\varepsilon}\\right) \\mathbf{K} \\operatorname{diag}\\left(e^{\\mathbf{g} / \\varepsilon}\\right), \\mathbf{f} \\mathbf{1}_{m}^{\\mathrm{T}}+\\mathbf{1}_{n} \\mathbf{g}^{\\mathrm{T}}-\\mathbf{C}-\\varepsilon \\mathbf{1}_{n \\times m}\\right\\rangle\\\\\n    &=-\\left\\langle e^{\\mathbf{f} / \\varepsilon},(\\mathbf{K} \\odot \\mathbf{C}) e^{\\mathbf{g} / \\varepsilon}\\right\\rangle+\\langle\\mathbf{f}, \\mathbf{\\mu}\\rangle+\\langle\\mathbf{g}, \\mathbf{\\nu}\\rangle-\\varepsilon\\left\\langle e^{\\mathbf{f} / \\varepsilon}, \\mathbf{K} e^{\\mathbf{g} / \\varepsilon}\\right\\rangle\n    \\end{aligned}\n\\end{equation}\n\ntherefore, the first term in \\label{eq:fg} cancels out with the first term in the entropy above, then we have\n\n\\begin{equation}\n  \\label{eq:problem4.4}\n  \\mathrm{L}_{\\mathrm{C}}^{\\varepsilon}(\\mathbf{\\mu}, \\mathbf{\\nu})=\\max _{\\mathbf{f} \\in \\mathbb{R}^{n} \\mathbf{g} \\in \\mathbb{R}^{m}}\\langle\\mathbf{f}, \\mathbf{\\mu}\\rangle+\\langle\\mathbf{g}, \\mathbf{\\nu}\\rangle-\\varepsilon\\left\\langle e^{\\mathbf{f} / \\varepsilon}, \\mathbf{K} e^{\\mathbf{g} / \\varepsilon}\\right\\rangle\n\\end{equation}\n\nThe optimal ($\\mathbf{f}$, $\\mathbf{g}$) are linked to scalings ($\\mathbf{u}$, $\\mathbf{v}$) through\n\n\\begin{equation}\n  (\\mathbf{u}, \\mathbf{v})=\\left(e^{\\mathbf{f} / \\varepsilon}, e^{\\mathbf{g} / \\varepsilon}\\right)\n\\end{equation}\n\nA simple approach to solving the unconstrained maximization problem \\ref{eq:problem4.4} is to use an exact \n\\textbf{block coordinate ascent} strategy, namely to update alternatively $\\mathbf{f}$ and $\\mathbf{g}$ to cancel the\nrespective gradients in these variables of the objective of \\ref{eq:problem4.4}. Indeed, one can notice\nafter a few elementary computations that, writing Q(f, g) for the objective of \\ref{eq:problem4.4}\n\n\\begin{equation}\n  \\begin{array}{l}\n    {\\left.\\nabla\\right|_{\\mathbf{f}} Q(\\mathbf{f}, \\mathbf{g})=\\mathbf{\\mu}-e^{\\mathbf{f} / \\varepsilon} \\odot\\left(\\mathbf{K} e^{\\mathbf{g} / \\varepsilon}\\right)} \\\\\n    {\\left.\\nabla\\right|_{\\mathbf{g}} Q(\\mathbf{f}, \\mathbf{g})=\\mathbf{\\nu}-e^{\\mathbf{g} / \\varepsilon} \\odot\\left(\\mathbf{K}^{\\mathrm{T}} e^{\\mathbf{f} / \\varepsilon}\\right)}\n    \\end{array}\n\\end{equation}\n\nBlock coordinate ascent can therefore be implemented in a closed form by applying\nsuccessively the following updates, starting from any arbitrary $\\mathbf{g}^{(0)}$, for $l \\geq 0$:\n\n\\begin{equation}\n  \\begin{array}{l}\n    {\\mathbf{f}^{(\\ell+1)}=\\varepsilon \\log \\mathbf{\\mu}-\\varepsilon \\log \\left(\\mathbf{K} e^{\\mathbf{g}^{(\\ell)} / \\varepsilon}\\right)} \\\\\n    {\\mathbf{g}^{(\\ell+1)}=\\varepsilon \\log \\mathbf{\\nu}-\\varepsilon \\log \\left(\\mathbf{K}^{\\mathrm{T}} e^{\\mathbf{f}^{(\\ell+1)} / \\varepsilon}\\right)}\n    \\end{array}\n\\end{equation}\n\nSuch iterations are mathematically equivalent to the Sinkhorn iterations \\ref{eq:sinkhorn}. Indeed, we recover that at\nany iteration\n\n\\begin{equation}\n  \\left(\\mathbf{f}^{(\\ell)}, \\mathbf{g}^{(\\ell)}\\right)=\\varepsilon\\left(\\log \\left(\\mathbf{u}^{(\\ell)}\\right), \\log \\left(\\mathbf{v}^{(\\ell)}\\right)\\right)\n\\end{equation}\n\nGiven a vector $\\mathbf{z}$ of real numbers we write $min_{\\epsilon} \\mathbf{z}$ for the soft-minimum of its coordinates, namely\n\n\\begin{equation}\n  \\min _{\\varepsilon} \\mathbf{z}=-\\varepsilon \\log \\sum_{i} e^{-\\mathbf{z}_{i} / \\varepsilon}\n\\end{equation}\n\n\\begin{figure}[htbp]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{img/min_eps}\n  \\label{fig:ot}\n  \\caption{Soft-minimum}\n\\end{figure}\n\nUsing this notation,\n\n\\begin{equation}\n  \\begin{array}{l}\n    {\\left(\\mathbf{f}^{(\\ell+1)}\\right)_{i}=\\min _{\\varepsilon}\\left(\\mathbf{C}_{i j}-\\mathbf{g}_{j}^{(\\ell)}\\right)_{j}+\\varepsilon \\log \\mathbf{\\mu}_{i}} \\\\\n    {\\left(\\mathbf{g}^{(\\ell+1)}\\right)_{j}=\\min _{\\varepsilon}\\left(\\mathbf{C}_{i j}-\\mathbf{f}_{i}^{(\\ell)}\\right)_{i}+\\varepsilon \\log \\mathbf{\\nu}_{j}}\n    \\end{array}\n\\end{equation}\n\nTo simplify notations, we introduce an operator that\ntakes a matrix as input and outputs now a column vector of the soft-minimum values\nof its columns or rows. Namely, for any matrix $\\mathbf{A} \\in \\mathbb{R}^{m \\times n}$, we define\n\n\\begin{equation}\n  \\begin{array}{l}\n    {\\operatorname{Min}_{\\varepsilon}^{\\mathrm{row}}(\\mathbf{A}) \\stackrel{\\text { def. }}{=}\\left(\\min _{\\varepsilon}\\left(\\mathbf{\\mu}_{i, j}\\right)_{j}\\right)_{i} \\in \\mathbb{R}^{m}} \\\\\n    {\\operatorname{Min}_{\\varepsilon}^{\\mathrm{col}}(\\mathbf{A}) \\stackrel{\\mathrm{def}}{=}\\left(\\min _{\\varepsilon}\\left(\\mathbf{\\nu}_{i, j}\\right)_{i}\\right)_{j} \\in \\mathbb{R}^{n}}\n    \\end{array}\n\\end{equation}\n\nUsing this notation, Sinkhorn's iterates read\n\n\\begin{equation}\n  \\begin{array}{l}\n    {\\mathbf{f}^{(\\ell+1)}=\\operatorname{Min}_{\\varepsilon}^{\\mathrm{row}}\\left(\\mathbf{C}-\\mathbf{1}_{m} \\mathbf{g}^{(\\ell)^{\\mathrm{T}}}\\right)+\\varepsilon \\log \\mathbf{\\mu}} \\\\\n    {\\mathbf{g}^{(\\ell+1)}=\\operatorname{Min}_{\\varepsilon}^{\\mathrm{col}}\\left(\\mathbf{C}-\\mathbf{f}^{(\\ell)} \\mathbf{1}_{n}^{\\mathrm{T}}\\right)+\\varepsilon \\log \\mathbf{\\nu}}\n    \\end{array}\n\\end{equation}\n\nWhile mathematically equivalent to the Sinkhorn\nupdates \\ref{eq:sinkhorn}, iterations above suggest using the log-sum-exp stabilization\ntrick to avoid underflow for small values of $\\epsilon$. Writing $\\underline{z}=\\min \\mathbf{z}$, that trick suggests\nevaluating $\\min_{\\varepsilon} z$ as\n\n\\begin{equation}\n  \\operatorname{min}_{\\varepsilon} \\mathbf{z}=\\underline{z}-\\varepsilon \\log \\sum e^{-\\left(\\mathbf{z}_{i}-\\underline{Z}\\right) / \\varepsilon}\n\\end{equation}\n\nInstead of substracting $\\mathbf{z}$ to stabilize the log-domain iterations as above, one can actually substract the previously computed scalings. This leads to the stabilized iteration\n\n\\begin{equation}\n  \\begin{array}{l}\n    {\\mathbf{f}^{(\\ell+1)}=\\operatorname{Min}_{\\varepsilon}^{\\mathrm{row}}\\left(\\mathbf{S}\\left(\\mathbf{f}^{(\\ell)}, \\mathbf{g}^{(\\ell)}\\right)\\right)-\\mathbf{f}^{(\\ell)}+\\varepsilon \\log (\\mathbf{\\mu})} \\\\\n    {\\mathbf{g}^{(\\ell+1)}=\\operatorname{Min}_{\\varepsilon}^{\\mathrm{col}}\\left(\\mathbf{S}\\left(\\mathbf{f}^{(\\ell+1)}, \\mathbf{g}^{(\\ell)}\\right)\\right)-\\mathbf{g}^{(\\ell)}+\\varepsilon \\log (\\mathbf{\\nu})}\n    \\end{array}\n\\end{equation}\n\nwhere we defined \n\n\\begin{equation}\n  \\mathbf{S}(\\mathbf{f}, \\mathbf{g})=\\left(\\mathbf{C}_{i, j}-\\mathbf{f}_{i}-\\mathbf{g}_{j}\\right)_{i, j}\n\\end{equation}\n\nIn contrast to the original iterations \\ref{eq:sinkhorn}, these log-domain iterations\nare stable for arbitrary $\\epsilon$, because the quantity $\\mathbf{S}(\\mathbf{f}, \\mathbf{g})$ stays bounded during the\niterations. The downside is that it requires nm computations of exp at each step. Computing a $\\mathrm{Min}_{\\varepsilon}^{\\mathrm{row}}$ is typically substantially slower than matrix multiplications\nand requires computing line by line soft-minima of matrices $\\mathbf{S}$. There is therefore no\nefficient way to parallelize the application of Sinkhorn maps for several marginals simultaneously. In Euclidean domains of small dimension, it is possible to develop efficient\nmultiscale solvers with a decaying $\\epsilon$ strategy to significantly speed up the computation\nusing sparse grids.\n\n\\vspace{2ex}\n    \\begin{algorithm}[htbp]\n        \\SetAlgoNoLine\n        \\caption{Block Coordinate Ascent algorithm for regularized problem} \n        \\KwIn{parameters $\\mu$, $\\nu$, $c$}\n        \\KwIn{epsilon $\\epsilon$}\n        Initialize variables $\\mathbf{f}, \\mathbf{g} = \\boldsymbol{1}$\\\\\n        Initialize  $\\mathbf{K} = \\exp^{-c/\\epsilon}$\\\\\n        \\While{ stopping criterion not met } \n        {  \n          Update $\\mathbf{S}$: $\\mathbf{S}(\\mathbf{f}, \\mathbf{g})=\\left(\\mathbf{C}_{i, j}-\\mathbf{f}_{i}-\\mathbf{g}_{j}\\right)_{i, j}$\\\\\n          Update $\\mathbf{f}$: ${\\mathbf{f}^{(\\ell+1)}=\\operatorname{Min}_{\\varepsilon}^{\\mathrm{row}}\\left(\\mathbf{S}\\left(\\mathbf{f}^{(\\ell)}, \\mathbf{g}^{(\\ell)}\\right)\\right)-\\mathbf{f}^{(\\ell)}+\\varepsilon \\log (\\mathbf{\\mu})}$\\\\\n          Update $\\mathbf{S}$: $\\mathbf{S}(\\mathbf{f}, \\mathbf{g})=\\left(\\mathbf{C}_{i, j}-\\mathbf{f}_{i}-\\mathbf{g}_{j}\\right)_{i, j}$\\\\\n          Update $\\mathbf{g}$: ${\\mathbf{g}^{(\\ell+1)}=\\operatorname{Min}_{\\varepsilon}^{\\mathrm{col}}\\left(\\mathbf{S}\\left(\\mathbf{f}^{(\\ell+1)}, \\mathbf{g}^{(\\ell)}\\right)\\right)-\\mathbf{g}^{(\\ell)}+\\varepsilon \\log (\\mathbf{\\nu})}$\\\\\n        }\n        Calculate $\\mathbf{u} = \\exp(\\mathbf{f}/\\epsilon)$\\\\\n        Calculate $\\mathbf{v} = \\exp(\\mathbf{g}/\\epsilon)$\\\\\n        Calculate $\\mathbf{P} = (\\operatorname{diag}{\\mathbf{u}}) \\mathbf{K} (\\operatorname{diag}{\\mathbf{v}})$\\\\\n    \\end{algorithm}", "meta": {"hexsha": "797e69e3360158c37ce4806c3094cd36819c1ae2", "size": 19778, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/content-4.tex", "max_stars_repo_name": "CrazyIvanPro/Optimal_Transport", "max_stars_repo_head_hexsha": "aa782820a5ca5a01909ed3c32acbada43f6cfa0f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-09T10:37:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-06T09:24:30.000Z", "max_issues_repo_path": "doc/content-4.tex", "max_issues_repo_name": "CrazyIvanPro/Optimal_Transport", "max_issues_repo_head_hexsha": "aa782820a5ca5a01909ed3c32acbada43f6cfa0f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/content-4.tex", "max_forks_repo_name": "CrazyIvanPro/Optimal_Transport", "max_forks_repo_head_hexsha": "aa782820a5ca5a01909ed3c32acbada43f6cfa0f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-03T17:07:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-03T17:07:01.000Z", "avg_line_length": 60.2987804878, "max_line_length": 521, "alphanum_fraction": 0.6663464455, "num_tokens": 7063, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7320683630584882}}
{"text": "\\subsection{Row Reduction}\r\n\\noindent\r\nRow reduction is a way of solving a system of linear equations by representing the system as a matrix and altering the rows of the matrix until we get as close as possible to an identity matrix.\\\\\r\n\r\n\\noindent\r\nBelow is a list of legal row operations. Doing these does not change the solution to the system of equations.\r\n\\begin{enumerate}[label=]\r\n\t\\item Multiplying or dividing each item in a row by a scalar.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\begin{bmatrix}\r\n\t\t\t\t1 & 3 & 7 \\\\\r\n\t\t\t\t0 & 2 & -1 \\\\\r\n\t\t\t\t2 & 7 & 9\r\n\t\t\t\\end{bmatrix}\r\n\t\t\t\\stackrel{R_2 = R_2/2}{\\to}\r\n\t\t\t\\begin{bmatrix}\r\n\t\t\t\t1 & 3 & 7 \\\\\r\n\t\t\t\t0 & 1 & -1/2 \\\\\r\n\t\t\t\t2 & 7 & 9\r\n\t\t\t\\end{bmatrix}\r\n\t\t\\end{equation*}\r\n\t\\item Adding a multiple of one row to another row.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\begin{bmatrix}\r\n\t\t\t\t1 & 3 & 7 \\\\\r\n\t\t\t\t0 & 2 & -1 \\\\\r\n\t\t\t\t2 & 7 & 9\r\n\t\t\t\\end{bmatrix}\r\n\t\t\t\\stackrel{R_3 = R_3 - 2R_1}{\\to}\r\n\t\t\t\\begin{bmatrix}\r\n\t\t\t\t1 & 3 & 7 \\\\\r\n\t\t\t\t0 & 2 & -1 \\\\\r\n\t\t\t\t0 & 1 & -5\r\n\t\t\t\\end{bmatrix}\r\n\t\t\\end{equation*}\r\n\t\\item Swapping two rows.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\begin{bmatrix}\r\n\t\t\t\t1 & 3 & 7 \\\\\r\n\t\t\t\t0 & 2 & -1 \\\\\r\n\t\t\t\t0 & 1 & -5\r\n\t\t\t\\end{bmatrix}\r\n\t\t\t\\stackrel{\\text{swap } R_2 \\text{, } R_3}{\\to}\r\n\t\t\t\\begin{bmatrix}\r\n\t\t\t\t1 & 3 & 7 \\\\\r\n\t\t\t\t0 & 1 & -5 \\\\\r\n\t\t\t\t0 & 2 & -1\r\n\t\t\t\\end{bmatrix}\r\n\t\t\\end{equation*}\r\n\\end{enumerate}\r\n\r\n\\noindent\r\nUsing these rules, we solve a system of linear equations using a process called Gauss-Jordan Elimination.\\\\\r\n\r\n\\noindent\r\nA system may have a contradiction, meaning no solution exists. This will look like a row of 0's on the left and a non-zero term on the far right of the row.\r\n\\begin{equation*}\r\n\t\\left[\r\n\t\t\\begin{array}{cc|c}\r\n\t\t1 & 0 & 1 \\\\\r\n\t\t0 & 1 & 0\r\n\t\t\\end{array}\r\n\t\\right]\r\n\t\\implies\r\n\t\\text{No solution}\r\n\\end{equation*}\r\n\r\n\\noindent\r\nA system may be underdetermined, meaning one or more variables can be any number. This will look a non-zero column on the left without a leading 1 (bolded).\r\n\\begin{equation*}\r\n\t\\left[\r\n\t\t\\begin{array}{ccccc|c}\r\n\t\t\t1 & \\textbf{-2} & 0 & 0 & \\textbf{-3} & 2 \\\\\r\n\t\t\t0 & \\textbf{0} & 1 & 0 & \\textbf{1} & 5 \\\\\r\n\t\t\t0 & \\textbf{0} & 0 & 1 & \\textbf{2} & 4 \\\\\r\n\t\t\t0 & \\textbf{0} & 0 & 0 & \\textbf{0} & 0\r\n\t\t\\end{array}\r\n\t\\right]\r\n\t\\implies\r\n\t\\begin{bmatrix}\r\n\t\tx_1 \\\\\r\n\t\tx_2 \\\\\r\n\t\tx_3 \\\\\r\n\t\tx_4 \\\\\r\n\t\tx_5 \\\\\r\n\t\\end{bmatrix} = \\begin{bmatrix}\r\n\t\t2 \\\\\r\n\t\t0 \\\\\r\n\t\t5 \\\\\r\n\t\t4 \\\\\r\n\t\t0\r\n\t\\end{bmatrix} + \\alpha \\begin{bmatrix}\r\n\t\t2 \\\\\r\n\t\t1 \\\\\r\n\t\t0 \\\\\r\n\t\t0 \\\\\r\n\t\t0\r\n\t\\end{bmatrix} + \\beta \\begin{bmatrix}\r\n\t\t3 \\\\\r\n\t\t0 \\\\\r\n\t\t-4 \\\\\r\n\t\t-2 \\\\\r\n\t\t1\r\n\t\\end{bmatrix} \\text{, }\\alpha\\text{, }\\beta \\in \\R\r\n\\end{equation*}\r\n\r\n\\ifodd\\includeBackgroundReviewExamples\\input{./backgroundReview/matrices/rowReduction_example.tex}\\fi", "meta": {"hexsha": "bee685053ac3f43034eaaad86cfbdeaf61c423a7", "size": 2698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/backgroundReview/matrices/rowReduction.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/backgroundReview/matrices/rowReduction.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/backgroundReview/matrices/rowReduction.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.214953271, "max_line_length": 197, "alphanum_fraction": 0.5752409192, "num_tokens": 1084, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616712, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7320683612164839}}
{"text": "%---------------------------Taper-----------------------------\n\\section{Taper}\n\nTaper is the maximum ratio of cross derivative magnitude to principal axis magnitude:\n\\[\nq = \\frac {\\normvec{X_{12}}} {\\min \\left\\{ \\normvec{X_1}, \\normvec{X_2} \\right\\}}\n\\]\n\nNote that if $\\normvec{X_1}$ or $\\normvec{X_2} < DBL\\_MIN$, we set $q = DBL\\_MAX$.\n\n\\quadmetrictable{taper}%\n{$1$}%                                      Dimension\n{$[0,0.7]$}%                                Acceptable range\n{$[0,DBL\\_MAX]$}%                           Normal range\n{$[0,DBL\\_MAX]$}%                           Full range\n{$0$}%                                      Unit square\n{Adapted from \\cite{rob:87}}%               Citation\n{v\\_quad\\_taper}%                           Verdict function name\n\n", "meta": {"hexsha": "31b49766403e98a0116d811632a8a9e35dd7a025", "size": 767, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadTaper.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadTaper.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadTaper.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 38.35, "max_line_length": 85, "alphanum_fraction": 0.4471968709, "num_tokens": 202, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465080392797, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7320606119203205}}
{"text": "\\ \n% This seems to work.\n\\paragraph{Better Solution: }\nLet the key be ${\\bf k}= k_0k_1\\dots k_{127}$.\nNote since $F$ has only $10$ inputs, it is possible to calculate a full truth\ntable for $F$. Also note that there is a fixed linear transformation $L_m$ taking\nthe vector ${\\bf s_0}$ to the $m$-th input vector of $F$, ${\\bf y_m}$. Our goal is to determine\n$128$ linear equations in $k_0,k_1,\\dots,k_{127}$ and then Gauss reduce. For each\nbit of keystream, we determine $10$ such equations, so we expect to use $13$ bits\nof keystream (more if some of these equations turn out to be degenerate). \nSwitching a bit in the IV will switch a bit in some easily calculable\nsubset of the entries in the input vector of $F$, since the input vector is a\nlinear map of ${\\bf s_0}$. Also, for a fixed IV and value $\\alpha$\nof the $m$-th keystream bit, we know that the input vector of $F$ for this bit\nlies in $F^{-1}(\\alpha)$, and, if the IV is ${\\bf v}$, then $L_m{\\bf k}$ lies in\nthe set $F^{-1}(\\alpha_v)-L_m{\\bf v}$ (since ${\\bf s_0} ={\\bf k} \\oplus {\\bf v}$).\nBy intersecting these sets over several IVs, we can determine a unique value of\n$L_m{\\bf k}$, which gives $10$ linear equations in the $k_i$. Repeating for different\nvalues of $m$ will give a complete set of linear equations, which can then be solved\nfor ${\\bf k}$. In general, computing $L_m$ will take about $128^3$ steps (and this\nmust be done about $128/10$ times), trying each\ninitialization vector will take about $128^2$ steps, and intersecting the sets of\npossible values for $L_m{\\bf k}$ will take about $2^{10}$ steps. Solving a set of\n$128$ linear equations will take about $128^3$ steps. The dominating factor is \n$128^4/10 \\approx 25\\,000\\,000 \\ll 2^{128}$.\n(More generally, computing a $2^N$ bit key with an $M$-tap filter\nfunction will take about $\\mathcal{O}(2^{4N}/M+2^{3N}+M(2^M+2^{2N}))$, which\nis exponentially better than the brute force $\\mathcal{O}(2^{2^N})$.\n\n\\paragraph{Our first stab at a solution. Simpler and slower:}\nStart by setting the IV to $00\\dots 0$. Then the initial state $s_0s_1\\dots s_{127}$\nis just the key. Now, note that there are \n\\[ \\sum_{i=0}^{10} {\\binom{128}{i}} <2^{34}\\] monomials in $s_0,s_1, \\dots, s_{127}$\nwhich are linear in each variable and of total degree at most $10$. Running\nthe filter generator for $2^{34}$ iterations will yield $2^{34}$ linear equations\nin these monomials. Gauss reduction on these equations will take approximately\n$(2^{34})^3 = 2^{102}$ steps. This will solve for $s_0,s_1,\\dots, s_{127}$, which\ngives the key. This is an improvement by a factor of $2^{26}$ on the brute force.\n", "meta": {"hexsha": "32be400e6a0616822154fc6624739fba97f68d87", "size": 2615, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tut2/q6.tex", "max_stars_repo_name": "h4tguy/crypto-hons", "max_stars_repo_head_hexsha": "3724eaf090f32e101504d8a73f94fddeebe2ddd9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tut2/q6.tex", "max_issues_repo_name": "h4tguy/crypto-hons", "max_issues_repo_head_hexsha": "3724eaf090f32e101504d8a73f94fddeebe2ddd9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tut2/q6.tex", "max_forks_repo_name": "h4tguy/crypto-hons", "max_forks_repo_head_hexsha": "3724eaf090f32e101504d8a73f94fddeebe2ddd9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.0512820513, "max_line_length": 95, "alphanum_fraction": 0.7070745698, "num_tokens": 827, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874624, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7320112381269193}}
{"text": "\\subsection{Distortion (PSNR) of Data}\n%distortion of data\n\nPeask Signal-to-Noise Ratio (PSNR) is a common metric used in graphics domain to evaluate the overall statistical distortion between the original data and the reconstructed/decompressed data. It is defined as follows. \n\\begin{equation}\nPSNR = 20\\cdot \\log_{10}{(value\\_range)} - 10\\cdot \\log_{10}{(MSE)}. \n\\end{equation}  \nwhere value\\_range and MSE refer to data value range and the mean squared compression error respectively.\n\nThe compression factor in the rate-distortion is evaluated by \\emph{bit rate}, i.e., the number of bits used to represent a data point on average after the compression. Bit rate is equal to the number of full bits used to represent each original data point divided by the overall compression factor, for example, $bit rate = \\frac{64}{compression factor}$ for double-precision data.\n\n%plot psnr\n", "meta": {"hexsha": "97c88f17eaaeb5b2f46234a08707d97437889ff3", "size": 885, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "template/tex/resultsTex/psnr.tex", "max_stars_repo_name": "CODARcode/Z-checker", "max_stars_repo_head_hexsha": "249fb901bba9e786a1cb093b4174b724df0c7db8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2017-06-18T15:43:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:00:10.000Z", "max_issues_repo_path": "template/tex/resultsTex/psnr.tex", "max_issues_repo_name": "CODARcode/Z-checker", "max_issues_repo_head_hexsha": "249fb901bba9e786a1cb093b4174b724df0c7db8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-06-19T12:44:56.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-30T12:55:52.000Z", "max_forks_repo_path": "template/tex/resultsTex/psnr.tex", "max_forks_repo_name": "CODARcode/Z-checker", "max_forks_repo_head_hexsha": "249fb901bba9e786a1cb093b4174b724df0c7db8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2017-06-18T15:39:31.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T22:36:05.000Z", "avg_line_length": 68.0769230769, "max_line_length": 382, "alphanum_fraction": 0.7796610169, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297887874624, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.732011234044501}}
{"text": "\\section{Setting}\n\\label{sec:setting}\n% In this section, \nIn this section, we introduce our setting and notation.\n\n\\spara{Markov Chain:}\nConsider a weighted directed graph \n$G=(V,E,p)$ with $|V|=n$ and $|E|=m$.\nWe use $\\pi(v)\\subseteq V$ and $\\children(v)\\subseteq V$ to \ndenote the set of parent and child nodes of node $v$, respectively.\n\\begin{align*}\n\\pi(v) & = \\{u\\mid u\\in V, e(u\\rightarrow v)\\in E\\} \\\\\n\\kappa(v) & = \\{u\\mid u\\in V, e(v\\rightarrow u)\\in E\\}\n\\end{align*}\nEdges $e(u\\rightarrow v)\\in E$ are associated with \nreal-valued weights $p(u\\rightarrow v)\\in [0,1]$\nsuch that $\\forall u\\in V$: \n$\n  \\sum_{v\\in V} p(u\\rightarrow v) = 1$.\n\nThese weights give rise to a \\markovchain\\\nwith transition matrix $\\transition$ --\nwhere $\\transition(u,v) = p(u,v)$ denotes\nthe probability of a transition from node $u$ to node $v$. \n% Since \n% $\\transition$ is the transition matrix of a \\markovchain, it has the property\n% that $\\sum_{v\\in V}\\transition(u,v)=1$.\nMoreover, we assume that a set of items\nare distributed among the nodes of $G$. \nWe use the row vector $\\initial$ to denote the \nthe {\\it initial} number of items per node; \nthat is, $\\initial(u)$ is the number of items {initially}\nat node $u$.\nFor the entirety of this paper, \ntransition matrix $\\transition$ and distribution $\\initial$ are \nassumed known and part of the input.\n\n\\note[MM]{For consistency, let's use 'position' instead of 'location' of items.}\nConsider now a single step of the \\markovchain. During this step, each and\nevery item transitions from the node $u$ where it resides originally\nto another node $v$, according to transition probabilities \n$\\transition(u,v)$.\nAt the end of this step, items are \nredistributed among the nodes - and we are no longer certain about their\nposition. We use $\\rvFinal$ to denote the random vector with the number\nof items at each node after one transition.\nThe \\emph{expected number of items} at each node is given by: \n%\\[\n$\\final = E[\\rvFinal] = \\initial{\\transition}$.\n%\\]\n\n%% MM: Do we need this?\n% More generally, \n% if the \\markovchain\\ takes $t$ steps, then the expected number of items\n% per node at the end of these steps is given by:\n% \\[\n% \\final = \\initial{\\transition}^t.\n% \\]\n\n\n\\spara{Quantifying uncertainty:} \nWe wish to have \n% an accurate estimate of the distribution of items over nodes $V$ \n% -- in other words, we wish to have \ngood point estimates for values $\\final(v)$.\nWe quantify the quality of estimates in terms of the variance\nin the number of items on each node afer the transition step.\nSpecifically, let us consider the number $\\rvFinal(v)$ of items\non node $u$ after the transition step:\nan item previously at node $u$ will transition to\nnode $v$ according to a Bernoulli distribution with \nsuccess probability $\\transition(u,v)$;\nand since items transition from node to node independently from each other,\nthe variance in the number of items $\\rvFinal(v)$ is\n\\begin{align}\n\\variance(\\rvFinal(v))  =\\ & \\variance(\\rvFinal(v) | \\transition, \\initial) \\nonumber \\\\\n =\\ & \\sum_{u\\in V}\\initial(u)\\transition(u,v)\\left(1-\\transition(u,v)\\right).\n\\end{align}\nTo obtain an aggregate measure of uncertainty $\\uncertainty_0$,\nwe opt to sum the aforementioned quantity over all nodes.\n% with simple summation, as follows:\n\\begin{align}\n\\uncertainty_0 & = \\sum_{v\\in V}{\\variance(\\rvFinal(v))} \\nonumber  \\\\\n %& = \\sum_{v\\in V}\\sum_{u\\in V}\\initial(u)\\transition(u,v)\\left(1-\\transition(u,v)\\right) \\nonumber \\\\\n & = \\sum_{u\\in V}\\initial(u)\\sum_{v\\in V}\\transition(u,v)\\left(1-\\transition(u,v)\\right) \n\\label{eq:uncertainty}\n\\end{align}\n% % MM: We have said this earlier.\n% Note that variance \n% $\\variance(\\rvFinal(v)) = \\variance(\\rvFinal(v) | \\transition, \\initial)$ \n% is defined conditionally on the \n% information we are given as input -- in this case, the transition matrix \n% \\transition\\ and the initial distribution of items $\\initial$.\n% In the interest of simplicity, we omit the conditional part of the \n% variance in notation when it is part of\n% the fixed input (such as \\initial\\ and \\transition) \n% -- and in what follows, we always assume that variance is\n% conditional on all available information.\n\n% % MM: Should we skip this part (uncertainty over time?)\n% \\spara{Uncertainty over time} \n% % $\\uncertainty_0$ of \n% Equation~\\eqref{eq:uncertainty} expresses the \n% uncertainty at one transition step. After $t$ steps, uncertainty is given by \n% the same equation with $\\transition^t$ in place of $\\transition$.\n% \\begin{equation}\n% \\uncertainty_0^t = \\sum_{u\\in V}\\initial(u)\\sum_{v\\in V}\\transition^t(u,v)\\left(1-\\transition^t(u,v)\\right)  \n% \\end{equation}\n% If $\\transition^t$ converges for $t\\rightarrow\\infty$, then $\\uncertainty_0^t$\n% converges as well. As a special case, if the Markov chain is well-behaving\n% (specifically: if it is ergodic~\\cite{gallager2012discrete}), then \n% $\\transition^t$ converges to $\\transition^\\infty$ with $|V|$ identical rows\n% \\steadystate, that express a `steady-state' distrbution of items. In that\n% case, the probability that any item is located at node $u$ is equal to\n% \\steadystate(u), regardless of what node it was placed at initially.\n% It follows that the expected number of items that are located at node $u$\n% at time $t\\rightarrow\\infty$ is equal to\n% \\begin{equation}\n%   \\final^{\\infty}(u) = \\steadystate(u) \\sum_u \\initial(u)\n% \\end{equation}\n% and the total uncertainty at time $t\\rightarrow\\infty$ is equal to\n% \\begin{equation}\n%   \\uncertainty_0^\\infty = \\sum_u \\steadystate(u)\\left(1 - \\steadystate(u)\\right)\n% \\end{equation}\n\n% In what follows, we\n% focus on the case of a transition\n% step of the \\markovchain\\ and are interested in\n% inferring the distribution of items over the nodes.\n% % and discuss the setting of multiple steps in Section~\\ref{sec:infinity}.\n\n\n% \\todo[MM]{Let's use this convention: $u$ for parent node, $v$ for child node.}\n\n\\spara{Monitoring:} \nGiven the transition matrix $\\transition$ and the \ninitial distribution of\nitems $\\initial$, we estimate the distribution of items \n$\\rvFinal$ after\none transition step, with\nthe uncertainty given in Equation~\\eqref{eq:uncertainty}.\nAfter one transition step,\nwe are allowed to \nretrieve information about the position of the items\nand thus reduce uncertainty.\nWe do this by performing ``monitoring operations\", i.e. queries on the\nposition of items on the \\markovchain.\nThese operations are  of the following types:\n%\\begin{itemize}\n\\squishlist\n\t\\item{\\bf \\parentstransitions} Retrieve the number of items that transitioned \n  to node $v$ from each  $u\\in\\pi(v)$;\n  \\item{\\bf \\nodeitems} Retrieve the number of items that reside on node \n  $v$ after the transition step;\n\t\\item{\\bf \\edgetransitions} Retrieve the number of items that transitioned \n  from node $u$ to node $v$;\n\t\\item{\\bf \\childrentransitions} Retrieve the number of items that \n  transitioned from node $u$ to each child $v\\in \\children(u)$.\n%\\end{itemize}\n\\squishend\n\nFrom the above four types of monitoring operations, the last one (i.e., {\\childrentransitions}) are both a bit \nunintuitive and they lead to trivial combinatorial problems. Thus, we omit them from the rest of the discussion.\n%%%%%%\n\n\\bpara{Expected uncertainty} \nOnce we retrieve the answer $\\answer$ to a set of monitoring operations,\nwe have more information about the positioning of items over nodes $V$ \n-- and thus an updated (and non-increased) uncertainty \n$\\uncertainty(\\answer) = \\sum_{v\\in V}{\\variance(\\rvFinal(v) | \\answer)}$.\nIn the setting we consider, however, the challenge we face is {\\it not} to compute\nthe uncertainty {\\it given} the information retrieved via a monitoring \noperation, but rather to {\\it select the monitoring operations} \nso that the uncertainty we will face {\\it after} retrieving $\\answer$ is\nminimized {\\it in expectation}. Therefore, the quantity of interest\nis that of \\expecteduncertainty\\ for a set of operations\nthat we choose to perform, expressed as \n$E[\\sum_{v\\in V}{\\variance(\\rvFinal(v) | \\answer)}]$. %,\n% with expectation taken\n% over the possible transitions according to \\transition.\n\nLet us now assume we have chosen to perform a set of operations of \neither one of the aforementioned types. In what follows, we provide \nformulas for the \\expecteduncertainty\\\nin each case.\n\n\n\\spara{Expected uncertainty under \\parentstransitions :} \nWe \nperform monitoring operations for\na subset $S\\subseteq V$ of nodes --\nand obtain an answer \n$A_{_\\shortparentstransitions}(S) = \\{n_{uv}; v\\in S,\\ e(u\\rightarrow v)\\in E\\}$,\nwhere $n_{uv}$ is the number of transitions to $v$ from its parent node $u$. \nThe expected value $\\objective_{_\\shortparentstransitions}(S)$ of the uncertainty \n$\\uncertainty(A_{_\\shortparentstransitions}(S))$ \nafter these operations is given by\n\\begin{align}\n\\label{eq:nodevariance}\n\\objective_{_\\shortparentstransitions}(S) = & E[\\uncertainty(A_{_\\shortparentstransitions}(S))] \\nonumber \\\\ \n= & \\sum_{u\\in V}\\initial^{\\prime}(u)\\sum_{v\\in V\\setminus S}\\transition^{\\prime}(u,v)\\left(1-\\transition^{\\prime}(u,v)\\right) \n\\end{align}\nwhere \n% expectation is taken over the probability of\n% possible transitions and thus\n% possible answers $A_{_\\shortparentstransitions}$ -- and \n% the following notation is used.\n\\begin{align}\n\\rho(u,S) & = \\sum_{v\\in S}\\transition(u,v) \\nonumber \\\\\n \\initial^{\\prime}(u) & = \\initial(u)\\left(1-\\rho(u,S)\\right) \\label{eq:adjustedx}\\\\\n \\transition^{\\prime}(u,v) & = \\frac{\\transition(u,v)}{1-\\rho(u,S)}. \\label{eq:adjustedP}\n\\end{align}\nIntuitively, $\\initial^{\\prime}(u)$ expresses the expected number\nof items that transition from $u$ to nodes $v$ {\\it other than} those in $S$;\nand $\\transition^{\\prime}(u,v)$ expresses the probability an item transitions\nfrom $u$ to $v$ {\\it given} that it does {\\it not} transition to those in $S$.\nWe see, then, that Equation~\\eqref{eq:nodevariance} has the same form as \nEquation~\\eqref{eq:uncertainty} but is evaluated on adjusted values of\n$\\initial$ and $\\transition$, to take into account the\ninformation we obtain via $A_{_\\shortparentstransitions}$.\n\nNote that the expected uncertainty after\nthe monitoring operations is no larger than $\\uncertainty_0$\\footnote{For a proof, see Supplementary Material, Lemma~\\ref{lemma:decreased_uncertainty_pt}.}.\n\n\n\\spara{Expected uncertainty under \\nodeitems:} \nWe \nperform monitoring operations for\na subset $S\\subseteq V$ of the nodes --\nand obtain an answer \n$A_{_\\shortnodeitems}(S) \n= \\{n_v; v\\in S\\}$, where $n_v$ is the number of items at node $v$\nafter the transition.\nFor an instance of answer $A_{_\\shortnodeitems}(S)$,\nlet also $A_{_\\shortparentstransitions}(S) = \\{n_{uv}; v\\in S, \n  e(u\\rightarrow v)\\in E\\}$ \nbe an answer for \\parentstransitions\\ on the same set $S$ of nodes\n-- which by definition\nis {\\it consistent with} $A_{_\\shortnodeitems}(S)$, in the sense that\n\\begin{equation}\nn_v = \\sum_{u\\in V} n_{uv}, \\forall v\\in S.\n\\end{equation}\nIt can be shown that the \\expecteduncertainty\\ is equal for the two cases.\nThat is: \n$\\objective_{_\\shortparentstransitions}(S) = \\objective_{_\\shortnodeitems}(S)$.\n\\footnote{For a proof, see Supplementary Material, \nTheorem~\\ref{theorem:node-equivalence}.}.\n\n%-- i.e., whether we are given $A_{_\\shortnodeitems}(S)$ \n%or $A_{_\\shortparentstransitions}(S)$ -- expressed by\n%Equation~\\eqref{eq:nodevariance}\n\n\\spara{Expected uncertainty under \\edgetransitions:}\nWe perform monitoring operations for\na subset $D\\subseteq E$ of the edges --\nand obtain an answer \n$A_{_\\shortedgetransitions} = A_{_\\shortedgetransitions}(D) = \\{n_e; e\\in D\\}$,\nwhere $n_e$ is the number of transitions over edge $e$. \nThe expected value $\\objective_{_\\shortedgetransitions}(D)$ of the uncertainty \n$\\uncertainty(A_{_\\shortedgetransitions}(D))$ \nafter these operations is given by\n\\begin{align}\n\\objective_{_\\shortedgetransitions}(D) = & E[\\uncertainty(A_{_\\shortedgetransitions})] \\nonumber \\\\\n= & \\sum_{u\\in V}\\initial^{\\prime\\prime}(u)\\sum_{e(u\\rightarrow v)\\in E\\setminus D}\\transition^{\\prime\\prime}(u,v)\\left(1-\\transition^{\\prime\\prime}(u,v)\\right) \\label{eq:edgetransitions}\n\\end{align}\nwhere \n\\begin{align}\n\\rho(u,D) & =\\ \\sum_{e(u\\rightarrow v)\\in D}\\transition(u,v) \\nonumber\\\\\n \\initial^{\\prime\\prime}(u) & =\\ \\initial(u)\\left(1-\\rho(u,D)\\right) \\label{eq:etinit}\\\\\n \\transition^{\\prime\\prime}(u,v) & =\\ \\frac{\\transition(u,v)}{1-\\rho(u,D)} \\label{eq:ettransit}\n\\end{align}\nSimilar to \\parentstransitions\\ and \\nodeitems, expected uncertainty\n$\\objective_{_\\shortedgetransitions}(S)$ is no greater than\n$\\uncertainty_0$.\n\n\\iffalse\n\\spara{Expected uncertainty under \\childrentransitions:}\nAssume that we perform monitoring operations for\na subset $S\\subseteq V$ of the nodes --\nand obtain an answer\n$A_{_\\shortchildrentransitions}(S) \n= \\{n_{uv}; u\\in S, (u, v)\\in E\\}$, where $n_{uv}$ is the number of items that \ntransition over edge $(u,v)$.\nThe expected value $\\objective_{_\\shortchildrentransitions}(S)$ of the uncertainty \n$\\uncertainty(A_{_\\shortchildrentransitions}(S))$ \nafter these operations is given by\n\\begin{align}\n\\label{eq:shortchildrentransitions}\n\\objective_{_\\shortchildrentransitions}(S) & = E[\\uncertainty(A_{_\\shortchildrentransitions})] = \\nonumber \\\\\n& = \\sum_{u\\in V-S}\\initial(u)\\sum_{v\\in V}\\transition(u,v)\\left(1-\\transition(u,v)\\right).\n\\end{align}\nNotice that this quantity is no greater than\n$\\uncertainty_0$ (Equation~\\eqref{eq:uncertainty}), as the outer summation\nis performed for a subset of nodes.\n\\fi\n\n", "meta": {"hexsha": "6a4bf5fef4ef07ed888cab48ae7d782f95dbf7df", "size": 13409, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/SDM-2018/setting.tex", "max_stars_repo_name": "chdhr-harshal/MCMonitor", "max_stars_repo_head_hexsha": "330fc1a8f8cf83620fd6b0e503707c91e97af16d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-04T20:35:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-05T09:06:43.000Z", "max_issues_repo_path": "paper/SDM-2018/setting.tex", "max_issues_repo_name": "chdhr-harshal/MCMonitor", "max_issues_repo_head_hexsha": "330fc1a8f8cf83620fd6b0e503707c91e97af16d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/SDM-2018/setting.tex", "max_forks_repo_name": "chdhr-harshal/MCMonitor", "max_forks_repo_head_hexsha": "330fc1a8f8cf83620fd6b0e503707c91e97af16d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-05T09:10:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-05T09:10:41.000Z", "avg_line_length": 45.1481481481, "max_line_length": 187, "alphanum_fraction": 0.729360877, "num_tokens": 3861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266014, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.732011230219676}}
{"text": "\\subsection{Brackets}\n\nOperators can be shown together, with brackets. For example:\n\n\\((\\alpha \\lor \\beta )\\land \\gamma \\)\n\nIs not the same as:\n\n\\(\\alpha \\lor (\\beta \\land \\gamma )\\)\n\n\n", "meta": {"hexsha": "aaf22226e4e5b867f4d423ba2dfad227903aa7e4", "size": 185, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogic/02-04-brackets.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/propositionalLogic/02-04-brackets.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/propositionalLogic/02-04-brackets.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.4166666667, "max_line_length": 60, "alphanum_fraction": 0.6648648649, "num_tokens": 53, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7320112253644775}}
{"text": "\\section{Constrained linear data-feature mapping from MgNet to interpret ResNet}\nIn this section, we will establish a new understanding of pre-act ResNet  \nby involving the idea that the pre-act ResNet block is an iterative scheme for solving some \nhidden model in each grid, which is also the fundamental assumption in MgNet. \nMore details about this mathematical interpreting model for CNN can be found\nin~\\cite{he2019constrained}.\n\nThe main point here is the introduction of \nthe so-called data and feature space for CNN, which is analogous to the \nfunction space and its duality in the theory of multigrid \nmethods~\\cite{xu2017algebraic}. \nNamely, following~\\cite{he2019mgnet} we introduce \nthe next data-feature mapping model in every grid level follows:\n\\begin{equation}\\label{eq:fmapping}\nA^{\\ell} \\ast u^\\ell = f^{\\ell},\n\\end{equation}\nwhere $f^\\ell$ and $u^\\ell$ belong to the data and feature space at $\\ell$-th grid. \nWe now make the following two important observations for this data-feature mapping:\n\\begin{itemize}\n\t\\item The mapping in \\eqref{eq:fmapping} is linear, more specifically it is just a convolution with multichannel, zero\n\tpadding and stride one as in pre-act ResNet.\n\t\\item In each level, namely between two consecutive pooling, there is only one\n\tdata-feature mapping, or we say that $A^\\ell$ only depends on $\\ell$, but not on number of layers.\n\\end{itemize}\nWe note that the assumption that these linear data-feature mapping\ndepend only on the grid level $\\ell$ is motivated from a basic property of \nmultigrid methods~\\cite{xu1992iterative, hackbusch2013multi, xu2017algebraic}.\n\nBesides \\eqref{eq:fmapping}, we introducing an important constrained condition\nin feature space that\n\\begin{equation}\\label{eq:positive}\nu^{\\ell,i} \\ge 0.\n\\end{equation}\nThe rationality of this constraint in feature space can be interpreted as follows.\nFirst of all, from the real neural system, the real neurons will only be\nactive if the electric signal is greater than certain thresholding value. \nNamely, we can think that human brains can only see features \nwith certain threshold.\nOn the other hand, the ``shift'' invariant property of feature space in CNNs,\nnamely, $u+a$ will not change the classification results. This means that $u+a$ should\nhave the same classification result with $u$. That is to say, we may assume that\n$u \\ge 0$ to reduce some redundancy of $u$.\n\nBased on these assumptions above, what we need to do next is to\nsolve the data-feature mapping equation in \\eqref{eq:fmapping}.\nWe will adopt some classical iterative methods~\\cite{xu1992iterative} in scientific computing\nto solve the system \\eqref{eq:fmapping} and obtain that \n\\begin{equation}\\label{BAmapping}\nu^{\\ell,i} = u^{\\ell,i-1} + B^{\\ell,i} \\ast (f^{\\ell} - A^{\\ell}\\ast u^{\\ell,i-1}),~ i = 1:\\nu_\\ell,\n\\end{equation}\nwhere $u^{\\ell} \\approx u^{\\ell,\\nu_\\ell}$. \nFor more details about iterative methods\nin numerical analysis, we refer to~\\cite{xu1992iterative, hackbusch1994iterative, golub2012matrix}.\nTo preserve \\eqref{eq:positive}, we naturally use the ReLU activation function $\\sigma$\nto modify \\eqref{BAmapping} as follows\n\\begin{equation}\n\\label{eq:uBfAu}\nu^{\\ell,i} = u^{\\ell,i-1} + \\sigma \\circ B^{\\ell,i}\\ast \\sigma  (f^\\ell -  A^\\ell\n\\ast u^{\\ell,i-1}), \\quad i=1:\\nu_\\ell,\n\\end{equation}\nwhich leads the the basic iterative scheme in MgNet.\n\nNow, let us consider the iteration for residual. Because of the linearity of convolution in data-feature mapping,\nif we consider the residual $r^{\\ell,j} = f^{\\ell} - A^{\\ell}\\ast u^{\\ell,j}$, \n\\eqref{eq:uBfAu} leads to the next iterative forms for residuals\n\\begin{equation}\\label{eq:pre-actResNet_residual}\nr^{\\ell, i} = r^{\\ell,i-1} - A^\\ell \\ast \\sigma \\circ B^{\\ell,i}\\ast \\sigma(r^{\\ell,i-1}).\n\\end{equation}\nThis is the same as \\eqref{eq:pre-act ResNet} under the constraint $A^{\\ell,i} = A^{\\ell}$ in pre-act ResNet.\n\nWe summarize the above derivation in the following simple theorem.\n\\begin{theorem}\\label{thm:1} Under the assumption that there is only\n\tone linear data-feature mapping in each grid $\\ell$, i.e. $A^{\\ell,i} = A^{\\ell}$, \n\tthe iterative form in feature space as in \\eqref{BAmapping} is equivalent to \n\t\\eqref{eq:pre-actResNet_residual} if $A^\\ell$ is invertible where $r^{\\ell,i} = f^\\ell - A^{\\ell}\\ast u^{\\ell,i}$.\n\\end{theorem}\n\n", "meta": {"hexsha": "b8158d6834ec0e7581fec5340860a12abc4d0f9d", "size": 4314, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ConstrainedLinearModel.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/ConstrainedLinearModel.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/ConstrainedLinearModel.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.3076923077, "max_line_length": 119, "alphanum_fraction": 0.747566064, "num_tokens": 1247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004185, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7319902328369916}}
{"text": "% !TEX root = ../../main.tex\n\\subsection{The (continuous) master equation for allele frequencies} \\label{sec_master_eq}\n\nOne of the most powerful tools to study stochastic process is the so-called\nmaster equation. Originally devised to study the stochastic time evolution of\nchemical reactions - thereby christened the chemical master equation - this\nequation has found applications in many areas of chemistry, physics and\nbiology. The equation is as statement about the time evolution of the\ntransition probabilities of a Markov process. That is just a fancy way of\nsaying that the master equation describes how the transition probabilities\nbetween states change over time.\n\nLet's derive this powerful equation starting from \\eref{eq_chapman_kolmogorov}.\nFor our case of study we want to understand how the frequency of a particular\nallele evolves over time, that is a stochastic process $X(t)$. Notice again\nthat we distinguish between the stochastic process $X(t)$ formed by the\nensemble of all possible realizations $x(t)$. The Chapman-Kolmogorov equation\nfor this particular case with three time points $t_1 < t_2 < t_3$ takes the\nform\n\\begin{equation}\n  P(x_3, t_3 \\mid x_1, t_1) = \\int_0^1 dx_2\\; P(x_3, t_3 \\mid x_2, t_2)\n                                          P(x_2, t_2 \\mid x_1, t_1),\n  \\label{eq_chapman_freq}\n\\end{equation}\nwhere the integration limits $[0, 1]$ are the domain of values that an allele\nfrequency can take. Now let us assume that we observe the frequency at time $t$\nand it happens to be at a value $x_1$. Then after a very short time $\\Dt$ we\nobserve again the allele frequency which is now at a value $x_2$. Under this\nshort time limit we can approximate the transition probability as\n\\begin{equation}\n  P(x_2, t + \\Dt \\mid x_1, t) = \\delta(x_2 - x_1)\n  \\underbrace{\\left[ 1 - a^{(0)}(x_1, t) \\Dt \\right]}_{\\text{probability\n  of no transition}} +\n  \\underbrace{\\phi_t(x_2 \\mid x_1)\\Dt}_\\text{probability of transition} +\n  \\mathcal{O}(\\Dt^2).\n  \\label{eq_transition_short_time}\n\\end{equation}\nLet's break down this equation. We have split the possible things that can\nhappen on a time window $\\Dt$ into two possible cases. The first one\nrepresented by the first term on the right-hand side is the possibility that on\nthis small time window no transition actually takes place. The\n$\\delta$-function that is equal to 1 if and only if $x_2 = x_1$ is there to\nmake sure that this term is added only when there was no transition during that\ntime and $x_2$ remains the same as $x_1$. Inside the square brackets we wrote\n$1 - a^{(0)}(x_1, t) \\Dt$, the reason for writing the term $a^{(0)}$ will\nbecome clear later on when we derive the so-called Fokker-Planck equation.\nHaving a term of the form 1 - ``something'' hints at the fact that this\n``something'' must be the probability of transitioning somewhere else rather\nthan staying at the same position. For the second term we wrote $\\phi_t(x_2\n\\mid x_1)\\Dt$ as the probability of transitioning outside of $x_1$ during this\ntime window. Our function $\\phi_t(x_2 \\mid x_1)$ represents the transition\nprobability per unit time between $x_1$ and $x_2$ at time $t$. When we multiply\nthis rate in time$^{-1}$ units by a small time window, we obtain the\nprobability of transitioning from $x_1$ to $x_2$.\n\nIn order to understand better the term $a^{(0)}(x_1, t)$ in\n\\eref{eq_transition_short_time} recall that a probability distribution must be\nnormalized. That means that if we integrate both sides of\n\\eref{eq_transition_short_time} over all values of $x_2$ it must be true that\n\\begin{equation}\n  \\int_0^1 dx_2 \\; P(x_2, t + \\Dt \\mid x_1, t) =\n  \\int_0^1 dx_2 \\; \\delta(x_2 - x_1) \\left[ 1 - a^{(0)}(x_1, t) \\Dt \\right]\n  + \\int_0^1 dx_2 \\; \\phi_t(x_2 \\mid x_1)\\Dt\n  = 1.\n\\end{equation}\nIntegrating over the $\\delta$-function implies that we set $x_2 = x_1$,\ntherefore we obtain\n\\begin{equation}\n  1 = \\left[  1 - a^{(0)}(x_1, t) \\Dt\\right] +\n  \\int_0^1 dx_2 \\; \\phi_t(x_2 \\mid x_1)\\Dt.\n\\end{equation}\nSolving for $a^{(0)}(x_1, t)$ results in\n\\begin{equation}\n  a^{(0)}(x_1, t) = \\int_0^1 dx_2 \\; \\phi_t(x_2 \\mid x_1),\n  \\label{eq_a0}\n\\end{equation}\nproving our previous assertion that $a^{(0)}(x_1, t)$ must be the\nprobability of jumping from $x_1$ to somewhere else.\n\nUsing this approximation for short time steps we will now derive the\ndifferential equation that the transition probability between frequencies must\nobey. Specifically for three time points $t_o < t < t + \\Dt$ with corresponding\nallele frequencies $x_o, x', f$ we have that \\eref{eq_chapman_freq} takes the\nform\n\\begin{equation}\n  P(x, t + \\Dt \\mid x_o, t_o) = \\int_0^1 dx' \\; P(x, t + \\Dt \\mid x', t)\n  P(x', t \\mid x_o, t_o).\n\\end{equation}\nSubstituting \\eref{eq_transition_short_time} results in\n\\begin{equation}\n  P(x, t + \\Dt \\mid x_o, t_o) = \\int_0^1 dx' \\;\n  \\left[ \\delta(x - x') \\left( 1 - a^{(0)}(x', t)\\Dt \\right)\n  + \\phi_t(x \\mid x')\\Dt \\right]\n  P(x', t \\mid x_o, t_o).\n\\end{equation}\nEvaluating the integral for the first term on the right-hand side gives\n\\begin{equation}\n  P(x, t + \\Dt \\mid x_o, t_o) = \\left[\\left( 1 - a^{(0)}(x, t)\\Dt \\right)\\right]\n  P(x, t \\mid x_o, t_o) +\n  \\Dt \\int_0^1 dx' \\; \\phi_t(x \\mid x') P(x', t \\mid x_o, t_o).\n\\end{equation}\nWe can then substitute \\eref{eq_a0} and rearrange terms to obtain\n\\begin{equation}\n  P(x, t + \\Dt \\mid x_o, t_o) = P(x, t \\mid x_o, t_o)\n  + \\int_0^1 dx' \\left[ \\phi_t(x \\mid x') P(x', t \\mid x_o, t_o) -\n  \\phi_t(x' \\mid x) P(x, t \\mid x_o, t_o) \\right]\\Dt.\n\\end{equation}\nSending the first term on the right-hand side to the left, dividing both sides\nby $\\Dt$ and taking the limit $\\Dt \\rightarrow 0$ gives the differential\nequation we were looking for\n\\begin{equation}\n  \\dt{P(x, t \\mid x_o, t_o)} = \\int_0^1 dx' \\;\n  \\underbrace{\n  \\left[ \\phi_t(x \\mid x') P(x', t \\mid x_o, t_o) \\right.}\n  _{\\text{gain } x' \\rightarrow f}  -\n  \\underbrace{\n  \\left. \\phi_t(x' \\mid x) P(x, t \\mid x_o, t_o) \\right]}\n  _{\\text{loss } x \\rightarrow x'}.\n  \\label{eq_master_eq_trans}\n\\end{equation}\nThis is the integro-differential equation known as the master equation. This\ncontinuous form of the master equation describes the time evolution of the\ntransition probabilities $P(x, t \\mid x_o, t_o)$, not the evolution of the\nprobability of being at a specific state $P(x, t)$. However we can use the\nrules of probability to obtain such description by the following process:\nSuppose the stochastic process $X(t)$ describes the time evolution of the\nfrequency. Assuming $X(t)$ is a stationary Markov process as described in\n\\secref{sec_stationary_process} means that this process is completely\ncharacterized by two functions - the probability of having a particular value\nfor the allele frequency $P_X(x)$ that does not depend on time, and a\ntransition probability $P(x, t \\mid x_o, t_o)$. We define a new, non-stationary\nprocess $F^*(t)$ for $t \\geq t_o$ by setting\n\\begin{equation}\n  P^*(x, t) = P(x, t\\mid x_o, t_o),\n\\end{equation}\ni.e. forcing the initial condition to be a specific value $x_o$ at time $t_o$.\nThis is a sub-ensemble of the process $X(t)$ since we demanded that $X(t = t_o)\n= x_o$. More generally if instead of setting the initial condition to be a\nsingle specific value $P(x, t_o) = \\delta(x - x_o)$ we define a probability\ndistribution for the initial state $P(x, t_o) = \\rho(x_o)$, we have a\nsub-ensemble of the form\n\\begin{equation}\n  P^*(x, t) = \\int_0^1 dx_o \\; P(x, t\\mid x_o, t_o) \\rho(x_o).\n  \\label{eq_subensemble}\n\\end{equation}\nThe interpretation of this sub ensemble is that the system was initially set on\na non-stationary state. The initial state distribution $\\rho(x_o)$ does not\ndepend on time, therefore if we take the time derivative on both sides of\n\\eref{eq_subensemble} we find that\n\\begin{equation}\n  \\dt{P^*(x, t)} = \\int_0^1 dx_o \\; \\dt{P(x, t\\mid x_o, t_o)}\n                        \\rho(x_o).\n\\label{eq_subensemble_dt}\n\\end{equation}\nNotice that the term with the time derivative on the right-hand side of\n\\eref{eq_subensemble_dt} is the master equation that we derived in\n\\eref{eq_master_eq_trans}. Substituting this results in\n\\begin{equation}\n  \\dt{P^*(x, t)} = \\int_0^1 dx_o \\; \\rho(x_o)\n  \\int_0^1 dx' \\;\n  \\left[ \\phi_t(x \\mid x') P(x', t \\mid x_o, t_o) -\n  \\phi_t(x' \\mid x) P(x, t \\mid x_o, t_o) \\right].\n\\end{equation}\nRedistributing the integrals gives\n\\begin{equation}\n  \\dt{P^*(x, t)} = \\int_0^1 dx' \\; \\phi_t(x \\mid x')\n  \\overbrace{\n  \\int_0^1 dx_o \\; P(x', t \\mid x_o, t_o) \\rho(x_o)}\n  ^{P^*(x', t)\\text{ by definition}} -\n  \\int_0^1 dx' \\; \\phi_t(x' \\mid x)\n  \\overbrace{\n  \\int_0^1 dx_o \\; P(x, t \\mid x_o, t_o) \\rho(x_o)}\n  ^{P^*(x, t)\\text{ by definition}}.\n\\end{equation}\nUsing the definition of the sub-ensembles shown in \\eref{eq_subensemble} we\narrive to a result of the form\n\\begin{equation}\n  \\dt{P^*(x, t)} = \\int_0^1 dx' \\;\n  \\underbrace{\n  \\phi_t(x \\mid x') P^*(x', t)\n  }_{x' \\rightarrow x \\text{ gain}} -\n  \\int_0^1 dx' \\;\n  \\underbrace{\n  \\phi_t(x' \\mid x) P^*(x, t)\n  }_{f \\rightarrow x' \\text{ loss}}.\n  \\label{eq_master_eq_full}\n\\end{equation}\nIn this form we can see that the master equation is a balance between gain and\nloss of probability at each state $f$. Having said that, the truth about the\ncontinuous master equation is that is extremely complicated to work with. In\ngeneral integro-differential equations are challenging mathematical objects to\ndeal with. That is why in the next section we'll use the powerful tool of\nTaylor expansions to simplify the equation. But before that let's discuss some\nhistoric uses of the master equation that might look different to our\nderivation\non \\eref{eq_master_eq_full}.\n\n\\subsubsection{Einstein-Kimura continuous master equations}\n\nIn 1905 during the groundbreaking year of Einstein's scientific career he\npublished a paper in which he attempted to give a molecular explanation to the\nphenomena of Brownian motion. For this he derived Fick's second law from of a\nstatistical argument by Taylor expanding a master equation - more on that in\nthe next section. In this classic paper Einstein had one of the very first uses\nof a continuous master equation applied to a physical problem. The difference\nfrom our approach is that Einstein didn't derive the master equation from the\nChapman-Kolmogorov property of continuous-time continuous-state Markov\nprocesses, but simply proposed its functional form directly.\n\nWhile the problem Einstein was addressing in his paper had to do with a random\nwalker moving in real space, the mathematical tools that he proposed can be\ndirectly mapped to the population genetics setup. As a matter of fact Motoo\nKimura himself used an equivalent approach to Einstein's formulation of the\nmaster equation for his formulation of diffusion theory. Kimura used the same\napproach as Einstein of Taylor expanding the master equation, with the main\ndifference being that for population genetics the transition probability\n$\\phi_t(x \\mid x')$ is a function of the current position $x'$ while in real\nspace free diffusion is independent of the position. For this short section our\nobjective is to show that our derivation of the master equation is equivalent\nto Einstein's and Kimura's proposed functional form. We will focus on Kimura's\nversion of the master equation since population genetics is what concerns us in\nthese notes.\n\nKimura's original derivation of the classic diffusion theory begins stating\nthat the process of allele frequency changes can be stated as\n\\begin{equation}\n  P(x, t + \\Dt) = \\int d\\varepsilon \\;\n  P(x - \\varepsilon, t) \\phi_t(x \\mid x - \\varepsilon) \\Dt,\n  \\label{eq_kimura_master}\n\\end{equation}\nand that is it. While it took us a while to justify \\eref{eq_master_eq_full},\nKimura (and Einstein in the context of Brownian motion) simply stated the\nmaster equation as the starting point. There is nothing intrinsically wrong\nabout having \\eref{eq_kimura_master} as the starting point, but in this set of\nextend notes I thought it would be insightful to start from a more fundamental\nproperty of Markov processes and have the master equation be a consequence of\nsuch property. Also I would like to highlight that in all of the population\ngenetics literature I have come across so far there has never been an explicit\naccount of the integration limits on the equations. This includes Kimura's\noriginal work as well as textbooks. For this particular case the integration\nlimits should go from $f$ to $f - 1$ such that the values of $f - \\varepsilon$\nrange from 0 to 1. So the proper form of this integral is given by\n\\begin{equation}\n  P(x, t + \\Dt) = \\int_{-f}^{f - 1} d\\varepsilon \\;\n  P(x - \\varepsilon, t) \\phi_t(x \\mid x - \\varepsilon) \\Dt.\n  \\label{eq_kimura_master_lim}\n\\end{equation}\n\nNotice that at first glance \\eref{eq_master_eq_full} and\n\\eref{eq_kimura_master_lim} don't seem to be equivalent.\n\\eref{eq_master_eq_full} is a differential equation that describes how the\nprobability distribution changes given gains and losses of probability on state\n$f$, while \\eref{eq_kimura_master_lim} only makes a statement of what would the\nprobability distribution look like a tiny time step into the future by adding\nall the jumps \\textbf{into} state $f$, but it doesn't include a term for all\nthe jumps out of state $f$. To show that these equations are equivalent we have\nto do two things:\n\\begin{enumerate}\n  \\item On \\eref{eq_master_eq_full} we notice that the second term on the\n  right-hand side can be written as\n  \\begin{equation}\n    P^*(x, t)\\int_0^1 dx' \\; \\phi_t(x' \\mid x) = P^*(x, t),\n    \\label{eq_integral_transition}\n  \\end{equation}\n  where we took the term $P^*(x, t)$ outside of the integral and used the fact\n  that the transition probability per unit time $\\phi_t(x' \\mid x)$ should be\n  normalized regardless of the time window. In other words, the probability of\n  transitioning from $f$ to anywhere else (including staying at $f$) should add\n  up to one regardless of the time window we observe.\n  \\mrm{Need to check this statement and that the units make sense}\n  \\item Having this result we can rewrite \\eref{eq_master_eq_full} as\n  \\begin{equation}\n    \\dt{P^*(x, t)} = \\int_0^1 dx' \\;\n    \\phi_t(x \\mid x') P^*(x', t) - P^*(x, t).\n    \\label{eq_master_eq_rearange}\n  \\end{equation}\n  We are almost there! All is left is to notice that if we were to Taylor\n  expand the left-hand side of \\eref{eq_kimura_master_lim} with respect to time\n  up to first order (as it is often done for time derivatives) we would obtain\n  \\begin{equation}\n    P(x, t + \\Dt) = P(x, t) + \\dt{P(x, t)}\\Dt + \\mathcal{O}(\\Dt^2).\n  \\end{equation}\n  That means we can send the second term on the the right-hand side of\n  \\eref{eq_master_eq_rearange} to the left and rewrite the equation as\n  \\begin{equation}\n    {P^*(x, t + \\Dt) \\over \\Dt} = \\int_0^1 dx' \\;\n    \\phi_t(x \\mid x') P^*(x', t),\n  \\end{equation}\n  which is equivalent to \\eref{eq_kimura_master_lim} where instead of having\n  the integration over the jump size $\\varepsilon$ the integration is done over\n  the final position $x'$.\n\\end{enumerate}\n", "meta": {"hexsha": "731635caa4ca712c07f70261e2a1e678e7c3568a", "size": 14989, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/book_draft/chapters/classic_diffusion/02_master_eq.tex", "max_stars_repo_name": "mrazomej/stat_gen", "max_stars_repo_head_hexsha": "abafd9ecc63ae8a804c8df5b9658e47cabf951fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/book_draft/chapters/classic_diffusion/02_master_eq.tex", "max_issues_repo_name": "mrazomej/stat_gen", "max_issues_repo_head_hexsha": "abafd9ecc63ae8a804c8df5b9658e47cabf951fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-03-05T00:17:26.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-05T00:17:26.000Z", "max_forks_repo_path": "doc/book_draft/chapters/classic_diffusion/02_master_eq.tex", "max_forks_repo_name": "mrazomej/pop_gen", "max_forks_repo_head_hexsha": "abafd9ecc63ae8a804c8df5b9658e47cabf951fa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.156996587, "max_line_length": 90, "alphanum_fraction": 0.7274000934, "num_tokens": 4513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328344, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7319902322587977}}
{"text": "\\chapter{Interest}\n\nA day count factor between the dates $t$ and $s$ is denoted by $\\dayc{s,t}$. We assume that the day count factor is a sufficiently smooth function and and that $\\dayc{s,t} = t-s$ when $s$ and $t$ are close.\n\n\\subsection{Zero-coupon bonds}\n\nA $T$-maturity zero-coupon bond is a promise to pay one unit of currency at time $T$. This is instrument is also called as pure discount bond. The price of this bond at time $t$ is denoted by $Z(t,T)$ and $Z(T,T) = 1$ if there is no risk of default. We shall call this a $T$-bond.\n\nIn the following we shall assume that for every $0 \\leq t$ and $t \\leq T$, there exists a frictionless market for $Z(t,T)$ and every zero-coupon bond has no risk of default. We also assume that $Z(t,T)$ is differentiable with respect to the time of maturity $T$.\n\n\\subsection{Riskless simple rate of interest}\n\nWe assume that $0 < t \\leq T < S$. If we enter the following contranct at time $0$. At the time $t$ we shall\n  \\begin{enumerate}\n    \\item sell one $T$-bond with price $Z(t,T)$ and\n    \\item we shall buy $Z(t,T) / Z(t,S)$ $S$-bonds for the price $Z(t,S)$\n  \\end{enumerate}\nAt time $t$ the net payments are $0$. We pay $1$ at time $T$ and receive $Z(t,T) / Z(t,S)$ at time $S$. We netted\n  \\begin{align}\n   1 - \\frac{Z(t,T)}{Z(t,S)}\n  \\end{align}\nbut the payments happened at different instances, so the terms are not of equal value. We say that the simple forward rate for $(T,S)$ contracted at $t$ is $L(t,T,S)$ satisfying the equation\n  \\begin{align}\n   1 + \\dayc{T,S} L(t,T,S) = \\frac{Z(t,T)}{Z(t,S)}\n  \\end{align}\nor equivalently\n  \\begin{align}\n  \\label{simplyinterestrate}\n   L(t,T,S) = \\frac{Z(t,T) - Z(t,S)}{ \\dayc{T,S}  Z(t,S)} .\n  \\end{align}  \nIf $t=T$, then we denote this rate by $L(t,S)$ and call it as the simple spot rate for $(t,S)$ and thus\n  \\begin{align}\n    L(t,S) = \\frac{ 1 - Z(t,S) }{ \\dayc{t,S} Z(t,S) } .\n  \\end{align}\n  \n\\subsection{Riskless continously compounded rate of interest}\n  \nSimilarly to the equation \\ref{simplyinterestrate}, we define the continously compounded forward rate for $(T,S)$ contracted at $t$ as $R(t,T,S)$ satisfying the equation\n  \\begin{align}\n   \\e^{ \\dayc{T,S} R(t,T,S)} = \\frac{Z(t,T)}{Z(t,S)} .\n  \\end{align}\nor equivalently\n  \\begin{align}\n    R(t,T,S) = \\frac{ \\log Z(t,T) - \\log Z(t,S) }{ \\dayc{T,S} }\n  \\end{align}\nIf $t=T$, then we denote this rate by $R(t,S)$ and call it as the continously compounded spot rate for $(t,S)$. Now\n  \\begin{align}\n    R(t,S) = - \\frac{ \\log (Z(t,S)) }{ \\dayc{T,S} } .\n  \\end{align}\nThe motivation for continous compounding comes from the fact that\n  \\begin{align}\n    \\e^x = \\lim_{n \\rightarrow \\infty} \\left( 1 + \\frac{x}{n} \\right)^n,\n  \\end{align}\nwhere the right-side is the limit of the compounding interest. By the power serie representation\n  \\begin{align}\n    \\e^x = 1 + x + \\frac{x^2}{2!} + \\frac{x^3}{3!} + \\ldots\n  \\end{align}\nwe see that $R(t,T,S) \\approx L(t,T,S)$, when $S$ is very close to $T$.\n\n\\subsection{Riskless instantaneous rates}\n  \nThe instantanenous forward rate with maturity $T$ contracted at time $t$ is defined by\n  \\begin{align}\n    f(t,S) &= \\lim_{S \\rightarrow T^+} L(t,T,S) \\\\\n            &= \\lim_{S \\rightarrow T^+} \\frac{Z(t,T) - Z(t,S)}{ \\dayc{T,S}  Z(t,S)} ¸\\\\\n            &= \\lim_{S \\rightarrow T^+} \\frac{1}{ Z(t,S) } \\frac{Z(t,T) - Z(t,S)}{ S-T } \\\\\n            &= - \\frac{1}{ Z(t,T) } \\frac{ \\partial Z(t,T) }{ \\partial T } \\\\\n            &= - \\frac{ \\partial \\log Z(t,T) }{ \\partial T } .\n  \\end{align}\nThus\n  \\begin{align}\n    Z(t,S) = Z(t,T) \\exp \\left( - \\int_T^S f(t,s) \\dx s \\right) \\\\\n  \\end{align}\nand in particulary\n  \\begin{align}\n    Z(t,S) = \\exp \\left( - \\int_t^S f(t,s) \\dx s \\right) \\\\\n  \\end{align}\n\n\\subsection{Short rate $r(t)$ and the bank account}  \n\nThe short rate $r(t)$ at time $t$ is defined by\n  \\begin{align}\n    r(t) = f(t,t).\n  \\end{align}\nThe bank account $B(t)$ is defined by\n  \\begin{align}\n    B(t) = \\exp \\left( \\int_0^T r(s) \\dx s \\right) .\n  \\end{align}\nNote that $B(0) = 1$ and equivalently the dynamics may be given by\n  \\begin{align}\n    &\\dx B(t) = r(t) B(t) \\dx t \\\\\n    &B(0) = 1\n  \\end{align}\n  \n\\section{Short-rate model for interest rates}\n\nThe classical approach to price interest rates derivates is the assume the existance of a short-rate process $r(t)$ which is a solution to a stochastic differential equation\n  \\begin{align}\n    \\dx r(t) &= \\mu(t, r(t)) \\dx t + \\sigma(t, r(t)) \\dx W(t), \\\\\n    r(0) = r_0,\n  \\end{align}\nwhere $r_0$ is a constant and $W_t$ is brownian motion under the physical probability measure $\\Pf$. We assume the existance of risk-free asset $B$ with price process\n  \\begin{align}\n    \\dx B(t) = r(t) B(t) \\dx t .\n  \\end{align}\nWe also assume \n  \\begin{enumerate}[labelindent=\\parindent, leftmargin=*]\n    \\item the market for $T$-bonds exists and is arbitrage free,\n    \\item the price of a $T$-bond is given by\n      \\begin{align}\n        Z(t,T) = F(t,r(t),T) ,\n      \\end{align}\n    where $F$ is a smooth function and\n    \\item $Z(T,T) = 1$ for all $r(T)$.\n  \\end{enumerate}\n\nWe have not assumed that $r(t)$ is a tradable asset, but we have assumed that there are markets for derivates of the short-rate. If $F(t,r(t))$ is a smooth function of $t$ and $r(t)$, then we may use It\\'{o}'s lemma to derive\n  \\begin{align}\n    \\label{interest_rate_derivative_process}\n    \\dx F = \\left( F_t + \\mu F_r + \\frac{1}{2} \\sigma^2 F_{rr} \\right) \\dx t + \\sigma F_r \\dx W ,\n  \\end{align}\nwhere we have supressed arguments and subscripts are partial derivates. We now combine to different short-rate derivates $V_1$ and $V_2$ to a portfolio\n  \\begin{align}\n    V = V_1 - x V_2.\n  \\end{align}\nWe assume that the price process $V_i$ is a function of $t$ and $r(t)$ so that $\\dx V_i = \\mu_i \\dx t + \\sigma_i \\dx W$, where $\\mu_i$ and $\\sigma_i$ can be derived from equation \\ref{interest_rate_derivative_process}. Thus\n  \\begin{align}\n    \\dx V = (\\mu_1 - x \\mu_2) \\dx t + (\\sigma_1 - x \\sigma_2) \\dx W .\n  \\end{align}\nIf\n  \\begin{align}\n    x = \\frac{\\sigma_1}{\\sigma_2} ,\n  \\end{align}\nthen \n  \\begin{align}\n    \\dx V &= (\\mu_1 - \\frac{\\sigma_1}{\\sigma_2} \\mu_2) \\dx t \\\\\n      &= r V \\dx t \\\\\n      &= r ( V_1 - \\frac{\\sigma_1}{\\sigma_2} V_2 ) \\dx t,\n  \\end{align}\nwhere we have assumed that the absense of arbitrage implies that the now risk-free portfolio must have risk-free interest rate as the growth rate. Thus\n  \\begin{align}\n    \\mu_1 - rV_1 = \\frac{\\sigma_1}{\\sigma_2} ( \\mu_2 - rV_2 ) \n  \\end{align}\nand therefore we have a well-defined function\n  \\begin{align}\n    \\lambda(t,r(t)) &= \\frac{\\mu_1(t,r(t)) - r(t)V_1(t,r(t))}{\\sigma_2(t,r(t))} \\\\ &= \\frac{\\mu_2(t,r(t)) - r(t)V_2(t,r(t))}{\\sigma_2(t,r(t))}\n  \\end{align}\nwhich depends only on arguments $t$ and $r(t)$ since the derivates can be arbitralily chosen. We call $\\lambda(t,r(t))$ as the market-price of risk. Thus the price $F$ of an arbitrary interest derivate must satisfy the differential equation\n  \\begin{align}\n     F_t + ( \\mu - \\lambda \\sigma ) F_r + \\frac{1}{2} \\sigma^2 F_{rr} - r F = 0 ,\n  \\end{align}\nwhich is a close cousin to the Black-Scholes differential equation. But is more complicated, because the market price of the risk is present. Since the short-rate is not tradable, it may not be hedged and therefore this market is not complete. Since the function $\\lambda$ is exogenous to the model, the solution and therefore the price will not be unique. In other words, we have multiple martingale measures.\n\n\n\\subsection{Short-rate and the stochastic discount factor}\n\nWe often assume that there is a short-rate $r_t$ that is applied to a bank account continously. It may or may not be stochastic. The bank account evolves according to the differential equation\n  \\begin{align}\n    \\dx B_t = r_t B_t,\n  \\end{align}\nwhere $B_t$ is value of the account at the time $t$. We assume unless otherwise noted that $B_0 = 1$. Thus\n  \\begin{align}\n    B_t = B_0 \\exp \\left( \\int_0^t r_s \\dx s \\right) .\n  \\end{align}\nWe assume that $r_t \\geq 0$ for all $t \\geq 0$ and this means that the bank account is riskless in the sense that no deposited money never loses value.\n\nA related concept is the stochastic discount factor $D(t,T)$ between the dates $t < T$, which is defined by\n  \\begin{align}\n    D(t,T) = \\frac{B_t}{B_T} = \\exp \\left( - \\int_t^T r_s \\dx s \\right) .\n  \\end{align}\nIt is the present value as seen at the time $t$ of one unit of currency payable at time $T$. If the short-rate is stochastic, then the discount factor is non-deterministic. \n\n\\subsection{Zero-coupon bonds}\n\nA $T$-maturity zero-coupon bond is a promise to pay one unit of currency at time $T$. This is instrument is also called as pure discount bond. The price of this bond at time $t$ is denoted by $Z(t,T)$. \n\nIf $r_t$ is deterministic and there is no arbitrage, then $D(t,T) = Z(t,T)$, but this does not hold in general. The zero-coupon bond is a derivate itself and can be replicated with a simple buy-and-hold strategy, we have that\n  \\begin{align}\n    Z(t,T) &= B_t \\E^{\\Pm} \\left( \\frac{1}{B_T} \\ | \\ F_t \\right) \\\\ \n      &= \\E^{\\Pm} \\left( \\exp \\left( - \\int_t^T r_s \\dx s \\right) \\ | \\ F_t \\right) \\\\\n      &= \\E^{\\Pm} \\left( D(t,T) \\ | \\ F_t \\right) .\n  \\end{align}\nA $T$-maturity zero-coupon bond is often a good choise for num\\'{e}raire and the assosiated EMM is called $T$-forward measure. We shall see in Theorem \\ref{expectedforwardrate} why this is a descriptive name. Since $Z(T,T) = 1$, the price of a derivate can be calculated by\n  \\begin{align}\n    h_t = Z(t,T) \\E^T ( H_T \\ | \\ \\F_t ).\n  \\end{align}\n\n\\subsection{Forward rates}\n\nA forward rate $F(t;T,S)$ between the dates $T < S$ is the rate that can be locked at the time $t$ for investment for the future period $[T,S]$. For simple compounding it is defined by\n  \\begin{align}\n    F(t;T,S) = \\frac{1}{\\dayc{T,S}} \\left( \\frac{Z(t,T) - Z(t,S) }{Z(t,S)} \\right)\n  \\end{align}\nIf $\\dayc{T,S} \\approx S-T$, when $T \\approx S$ and the function $S \\mapsto F(t,T,S)$ is smooth, then\n  \\begin{align}\n    \\lim_{S \\rightarrow T^+} F(t;T,S) &= - \\lim_{S \\rightarrow T^+} \\frac{1}{Z(t,S)} \\frac{Z(t,S) - Z(t,T)}{S-T} \\\\\n      &= - \\frac{1}{Z(t,S)} \\frac{\\partial Z(t,T) }{\\partial T} \\\\\n      &= - \\frac{\\partial \\log Z(t,T) }{\\partial T}\n  \\end{align}\nIn practice, the zero curve is constructed so that the smoothness is guarateed and we may define the instantenous forward rate as\n  \\begin{align}\n    f(t,T) &= - \\frac{\\partial \\log Z(t,T) }{\\partial T}\n  \\end{align}\nmeaning that\n  \\begin{align}\n    Z(t,T) &= \\exp \\left( - \\int_t^T f(t,s) \\dx s \\right) .\n  \\end{align}\nThe instantenous forward rate can be seen as the expectation of the future rate.\n\n\\begin{thm}\n  \\label{expectedforwardrate}\nIf there is a derivate $H$ with final payout $H_T = r_T$ at the time $T$ and the short-rate process is smooth, then\n  \\begin{align}\n    \\E^T ( R_T \\ | \\ \\F_t ) = f(t,T) .\n  \\end{align}\n\\end{thm}\n\n\\begin{proof}\nUnder the $T$-forward measure we have that $h_t = Z(t,T) \\E^T ( r_T \\ | \\ \\F_t )$ and risk-neutral valuation gives the price\n  \\begin{align}\n    h_t &= B_t \\E^{\\Pm} \\left( \\frac{r_T}{B_T} \\ | \\ F_t \\right) \\\\\n      &= \\E^{\\Pm} \\left( \\exp \\left( -\\int_t^T r_s \\dx s \\right) r_T \\ | \\ F_t \\right) \\\\\n      &= - \\E^{\\Pm} \\left( \\frac{ \\partial \\exp \\left( -\\int_t^T r_s \\dx s \\right)}{\\partial T} \\ | \\ F_t \\right) \\\\\n      &= - \\frac{\\partial }{\\partial T} \\E^{\\Pm} \\left( \\exp \\left( -\\int_t^T r_s \\dx s \\right) \\ | \\ F_t \\right) \\\\\n      &= - \\frac{\\partial Z(t,T)}{\\partial T},\n  \\end{align}\nwhere we assumed that the smoothness allows us the change the order of differentation and integration. Now\n  \\begin{align}\n    \\E^T ( r_T \\ | \\ \\F_t ) &= -\\frac{1}{Z(t,T)} \\frac{\\partial Z(t,T)}{\\partial T} = f(t,T) .\n  \\end{align}\n\\end{proof}\n\nA forward rate agreement (FRA) is a contract that lock a future interest rate . A FRA with a fixed interest rate $K$, expiry time $T$ and maturity time $S$ pays $K \\dayc(T,S)$ at the maturity $S$. The fixed rate $K$ is set when the contract \n\nA caplet is a call option on interest rate $L(S,T)$ for some $0 \\leq S < T$. With strike $K$, it has pay-off \n  \\begin{align}\n     \\Caplet (T,S,T,K) = (L(S,T) - K)^+ .\n  \\end{align}\nat the time $T$. By definition,\n  \\begin{align}\n    Z(S,T) = \\frac{1}{1+\\tau L(S,T)},\n  \\end{align}\nwhere $\\tau$ is the day-count adjustment between the dates $S$ and $T$. Thus the pay-out of the caplet can be written as\n  \\begin{align}\n    \\Caplet (T, S,T,K) &= \\left( \\frac{1}{\\tau} \\left( \\frac{1}{Z(S,T)} - 1 \\right) - K \\right)^+.\n  \\end{align}\nAs the rate $L(S,T)$ is set at the time $S$, the price of the cap at the time $S$ is\n  \\begin{align}\n     \\Caplet (S,S,T,K) &= Z(S,T) \\Caplet (T,S,T,K) \\\\\n     &= \\frac{1}{\\tau} \\left(  1 - Z(S,T)  - \\tau K Z(S,T) \\right)^+ \\\\\n      &= \\frac{1}{\\tau} \\left(  1 - Z(S,T) ( 1 + \\tau K ) \\right)^+ \\\\\n      &= \\frac{ 1 + \\tau K }{\\tau} \\left( \\frac{1}{1 + \\tau K}  - Z(S,T) \\right)^+\n  \\end{align}\nThe right-side is the price at the time $S$ of $\\frac{ 1 + \\tau K }{\\tau}$ put options with strike $\\frac{1}{1 + \\tau K}$ on a zero-coupons bonds with maturity $T$. Therefore the a caplet can be replicated as put options on a zero-coupon bond.\n\nSimilarly, a floorlet is a put option on interest rate $L(S,T)$ for some $0 \\leq S < T$. With strike $K$, it has pay-off \n  \\begin{align}\n     \\Floorlet (T,S,T,K) = (K - L(S,T))^+\n  \\end{align}\nat the time $T$. Now we can use the same argumentation as earlier with only the signs of $K$ and $L(S,T)$ changed and we see that\n  \\begin{align}\n     \\Floorlet (S,S,T,K) &= \\frac{ 1 + \\tau K }{\\tau} \\left( Z(S,T) - \\frac{1}{1 + \\tau K}  \\right)^+,\n  \\end{align}\nwhere the caplet has been replicated as call option on a zero-coupon bond $Z(S,T)$.\n", "meta": {"hexsha": "232fd135e87a474d95064bd42a23a397201645b1", "size": 13675, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "interest.tex", "max_stars_repo_name": "mrytty/gradu-public", "max_stars_repo_head_hexsha": "537337ab3dc49be9f1f4283706b0f4dcbc8cb059", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "interest.tex", "max_issues_repo_name": "mrytty/gradu-public", "max_issues_repo_head_hexsha": "537337ab3dc49be9f1f4283706b0f4dcbc8cb059", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "interest.tex", "max_forks_repo_name": "mrytty/gradu-public", "max_forks_repo_head_hexsha": "537337ab3dc49be9f1f4283706b0f4dcbc8cb059", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.6037735849, "max_line_length": 410, "alphanum_fraction": 0.6348080439, "num_tokens": 4680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891130942474, "lm_q2_score": 0.8902942166619118, "lm_q1q2_score": 0.7319902123901949}}
{"text": "\\subsection{Semiring ideals}\\label{subsec:semiring_ideals}\n\nWhen regarding \\hyperref[def:semiring]{semirings} as \\hyperref[def:semimodule]{semimodules} over themselves, as per \\fullref{thm:semiring_is_semimodule}, we obtain the important notion of ideals.\n\n\\begin{definition}\\label{def:semiring_ideal}\\mimprovised\n  Fix a semiring \\( R \\). A \\term{left ideal} of \\( R \\) is a \\hyperref[def:semimodule/submodel]{sub-semimodule} of \\( R \\) when regarded as a left semimodule over itself, and a \\term{right ideal} is defined analogously.\n\n  If \\( I \\) is both a left and right ideal of \\( R \\), we say that it is a \\term{two-sided ideal} or simply \\term{ideal}. More explicitly, \\( I \\) is a two-sided ideal of \\( R \\) if it is a \\hyperref[def:monoid/submodel]{submonoid} of the additive monoid of \\( R \\) that is closed under left and right multiplication, i.e. \\( RI = I = IR \\).\n\n  When \\hyperref[def:ring/quotient]{quotient rings} are involved, we will have no choice but to work with two-sided ideals. If multiplication is commutative, every left ideal is a right ideal and there is no distinction between the two. Otherwise, we will usually consider left ideals by default. Right ideals are left ideals in the \\hyperref[def:semiring/opposite]{opposite semiring}, and thus we lose no generality.\n\n  \\begin{thmenum}\n    \\thmitem{def:semiring_ideal/generated} For an arbitrary subset \\( A \\) of \\( R \\), we call the (left) \\hyperref[def:semimodule/submodel]{linear span} of \\( A \\) the left ideal \\term{generated} by \\( A \\). Explicitly, this is the set\n    \\begin{equation*}\n      \\sum_{a \\in A} A a = \\set*{ \\sum_{k=1}^n t_k a_k \\given* n > 0 \\T{and, for} k < n, t_k \\in R \\T{and} a_k \\in A }.\n    \\end{equation*}\n\n    If \\( A = \\set{ a_1, \\ldots, a_n } \\), we say that the ideal is \\term{finitely generated} and write\n    \\begin{equation*}\n      A a_1 + \\cdots + A a_n.\n    \\end{equation*}\n\n    For right ideals, this becomes\n    \\begin{equation*}\n      a_1 A + \\cdots + a_n A.\n    \\end{equation*}\n\n    This is discussed in \\fullref{thm:generators_via_polynomials} for the case of commutative rings, where we use the notation \\( \\braket{ A } \\). In general rings, we are more explicit for the sake of avoiding possible confusion.\n\n    \\thmitem{def:semiring_ideal/principal} An ideal generated by a single element is called a \\term{principal ideal}. In a general ring, there can be left, right and two-sided principal ideals.\n\n    \\thmitem{def:semiring_ideal/product} The \\term{product ideal} \\( IJ \\) of \\( I \\) and \\( J \\) is\n    \\begin{equation*}\n      \\set*{ \\sum_{k=1}^n i_k j_k \\given* n > 0 \\T{and, for} k < n, i_k \\in I \\T{and} j_k \\in J }.\n    \\end{equation*}\n\n    This notation is unfortunately inconsistent with the pointwise product \\( \\set{ ij \\mid i \\in I, j \\in J } \\) from \\fullref{def:magma/power_set}; it is actually the ideal generated by the pointwise product.\n\n    \\begin{figure}[h]\n      \\caption{Some important ideals}\\label{fig:ideal_hierarchy}\n      \\smallskip\n      \\hfill\n      \\begin{forest}\n        for tree=\n          {\n            s sep=2.25cm\n          }\n        [\n          {\\hyperref[def:semiring_ideal]{ideal}}, name=ideal\n            [{\\hyperref[def:semiring_ideal/principal]{principal}}, name=principal]\n            [\n              {\\hyperref[def:semiring_ideal/prime]{prime}}, name=prime\n                [{\\hyperref[def:semiring_ideal/maximal]{maximal}}, name=maximal]\n            ]\n            [{\\hyperref[def:radical_ideal]{radical}}, name=radical]\n        ]\n        \\draw[->, dashed] (prime) to node[below] {\\hyperref[def:semiring/commutative]{commutative}} (radical);\n        \\draw[->, dashed] (prime) to[out=west, in=west] node[left] {\\hyperref[def:principal_ideal_domain]{PID}} (maximal);\n        \\draw[->, dashed] (ideal) to[out=west, in=north] node[above] {\\hyperref[def:principal_ideal_domain]{PID}} (principal);\n      \\end{forest}\n      \\hfill\\hfill\n    \\end{figure}\n\n    \\thmitem{def:semiring_ideal/prime}\\mcite[85]{Golan2010} If \\( P \\) is a proper ideal and if from \\( IJ \\subseteq P \\) it follows that \\( I \\subseteq P \\) or \\( J \\subseteq P \\) (or both), we say that \\( P \\) is a \\term{prime ideal}.\n\n    When working with commutative semirings, \\fullref{thm:def:semiring_ideal/prime_pointwise} is instead sometimes taken as the definition of a prime ideal.\n\n    \\thmitem{def:semiring_ideal/coprime}\\mcite[18]{КоцевСидеров2016} If \\( I + J = R \\) for proper ideals \\( I \\) and \\( J \\), we say that \\( I \\) and \\( J \\) are \\term{coprime}. Equivalently, \\( I \\) and \\( J \\) are coprime if their sum contains a unit.\n\n    \\thmitem{def:semiring_ideal/maximal} A (left) \\term{maximal ideal} is a proper (left) ideal that is maximal with respect to set inclusion. The maximal ideals are the predecessors of \\( R \\) in the lattice of (left) ideals described in \\fullref{thm:semiring_of_ideals}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{remark}\\label{rem:semiring_ideal_as_sub_semiring}\n  A proper semiring ideal is a canonical example of a nonunital sub-semiring. As a consequence of \\fullref{thm:def:semiring_ideal/ideal_containing_unit}, a proper ideal cannot contain the multiplicative identity \\( 1 \\), and is thus not a sub-semiring unless we allow sub-semirings to not contain \\( 1 \\).\n\\end{remark}\n\n\\begin{proposition}\\label{thm:def:semiring_ideal}\n  The left \\hyperref[def:semiring_ideal]{ideals} of a semiring \\( R \\) have the following basic properties:\n  \\begin{thmenum}[series=thm:def:semiring_ideal/properties]\n    \\thmitem{thm:def:semiring_ideal/ideal_containing_unit} An ideal contains a \\hyperref[def:divisibility/unit]{unit} if and only if it is not proper. In particular, \\( R = \\braket{ 1_R } \\).\n\n    \\thmitem{thm:def:semiring_ideal/units} A semiring element is a \\hyperref[def:divisibility/unit]{unit} if and only if it does not belong to any proper ideal.\n\n    \\thmitem{thm:def:semiring_ideal/division} We have \\( \\braket{ x } \\subseteq \\braket{ y } \\) if and only if \\( y \\mid x \\) for two-sided ideals and two-sided divisors.\n\n    More generally, we have \\( Rx \\subseteq Ry \\) if and only if \\( y \\) is a right divisor of \\( x \\). Note how \\( Rx \\) and \\( Ry \\) are \\hi{left} principal ideals but \\( y \\) is a \\hi{right} divisor.\n\n    \\thmitem{thm:def:semiring_ideal/union} The union of a \\hyperref[eq:def:partially_ordered_set/homomorphism/sequence]{monotone sequence}\n    \\begin{equation*}\n      I_1 \\subseteq I_2 \\subseteq \\cdots\n    \\end{equation*}\n    if ideals is again an ideal.\n\n    \\thmitem{thm:def:semiring_ideal/maximal_is_prime} Every (left or right) \\hyperref[def:semiring_ideal/maximal]{maximal ideal} is \\hyperref[def:semiring_ideal/prime]{prime}.\n\n    \\Fullref{thm:def:principal_ideal_domain/prime_ideal_is_maximal} is a converse that holds for \\hyperref[def:principal_ideal_domain]{principal ideal domains}.\n\n    \\thmitem{thm:def:semiring_ideal/coprime_product} We have \\( IJ \\subseteq I \\cap J \\). The converse inclusion holds if \\( R \\) is \\hyperref[def:semiring/commutative]{commutative} and if \\( I \\) and \\( J \\) are \\hyperref[def:semiring_ideal/coprime]{coprime}.\n  \\end{thmenum}\n\n  The following require \\( R \\) to be \\hyperref[def:semiring/commutative]{commutative}:\n  \\begin{thmenum}[resume=thm:def:semiring_ideal/properties]\n    \\thmitem{thm:def:semiring_ideal/product_of_principal_ideals} In a commutative semiring, the product of the principal ideals \\( \\braket{x} \\) and \\( \\braket{y} \\) is \\( \\braket{xy} \\).\n\n    \\thmitem{thm:def:semiring_ideal/prime_pointwise} In a commutative semiring, an equivalent condition to \\( P \\) being \\hyperref[def:semiring_ideal/prime]{prime} is that \\( xy \\in P \\) implies \\( x \\in P \\) or \\( y \\in P \\) (or both).\n\n    \\thmitem{thm:def:semiring_ideal/prime_is_radical} In a commutative semiring, every \\hyperref[def:semiring_ideal/prime]{prime ideal} is \\hyperref[def:radical_ideal]{radical}.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:semiring_ideal/ideal_containing_unit} We will prove that there exists a unit \\( u \\in I \\) if and only if \\( I = R \\).\n\n  \\SufficiencySubProof* Let \\( u \\in I \\) be a unit. Then \\( 1_R = u^{-1} u \\in I \\). It follows that \\( 1_R \\cdot x = x \\) for any \\( x \\in R \\), thus \\( IR = R \\). But \\( I \\) is an ideal, hence we have that \\( IR = I \\). Therefore, \\( I = IR = R \\).\n\n  \\NecessitySubProof* If \\( I = R \\), then obviously \\( 1_R \\in I \\).\n\n  An analogous proof follows for the case when \\( I \\) is a right ideal.\n\n  \\SubProofOf{thm:def:semiring_ideal/units}\n\n  \\SufficiencySubProof* Suppose that \\( x \\) is a unit and that \\( x \\) belongs to some proper ideal \\( I \\). Then \\( Rx = R \\), implying that \\( I = R \\), which is a contradiction.\n\n  \\NecessitySubProof* Suppose that \\( x \\) does not belong to any proper ideal. Then \\( Rx \\) is not a proper ideal, implying that \\( R = Rx \\). There exists some \\( y \\) such that \\( yx = 1_R \\). Hence, \\( x \\) is a unit.\n\n  \\SubProofOf{thm:def:semiring_ideal/division}\n\n  \\SufficiencySubProof* Suppose that \\( Rx \\subseteq Ry \\). Then \\( x \\in Ry \\), and hence there exists an element \\( l \\) of \\( R \\) such that \\( x = ly \\). So \\( y \\) is a right divisor of \\( x \\).\n\n  \\NecessitySubProof* Suppose that \\( y \\) is a right divisor of \\( x \\). Then there exists an element \\( l \\) of \\( R \\) such that \\( x = ly \\). Thus, \\( x \\in Ry \\), and hence \\( Rx \\subseteq Ry \\).\n\n  \\SubProofOf{thm:def:semiring_ideal/union} Follows from \\fullref{thm:def:semimodule/union}.\n\n  \\SubProofOf{thm:def:semiring_ideal/maximal_is_prime} Let \\( M \\) be a maximal left ideal and let \\( IJ \\subseteq M \\). Suppose that both \\( M \\setminus I \\) and \\( M \\setminus J \\) are nonempty.\n\n  Then there exist elements \\( i \\in I \\), \\( j \\in J \\), \\( m_i \\in M \\) and \\( m_j \\in M \\) such that\n  \\begin{equation*}\n    i + m_i = j + m_j = 1_R.\n  \\end{equation*}\n\n  Then\n  \\begin{equation*}\n    1_R = (i + m_i) (j + m_j) = \\underbrace{ij}_{IJ} + \\overbrace{m_i j}^M + \\underbrace{m_j i}_M + \\overbrace{m_i m_j}^M.\n  \\end{equation*}\n\n  Hence,\n  \\begin{equation*}\n    1_R = (i + m_i) (j + m_j) \\in M,\n  \\end{equation*}\n  which contradicts our assumption that \\( M \\) is maximal.\n\n  Therefore, \\( M \\setminus I \\) and \\( M \\setminus J \\) cannot both be nonempty.\n\n  \\SubProofOf{thm:def:semiring_ideal/coprime_product} We will first show that \\( IJ \\subseteq I \\cap J \\). Let\n  \\begin{equation*}\n    \\sum_{k=1}^n x_k y_k \\in IJ.\n  \\end{equation*}\n\n  For each \\( k \\), \\( x_k y_k \\) belongs to both \\( I \\) and to \\( J \\). Hence, the sum over \\( k \\) also belongs to the intersection. Therefore,\n  \\begin{equation*}\n    IJ \\subseteq I \\cap J.\n  \\end{equation*}\n\n  \\SubProofOf{thm:def:semiring_ideal/product_of_principal_ideals}\n  \\SufficiencySubProof* Let \\( z \\in \\braket{x} \\braket{y} \\). Then there exist elements \\( x_z \\) of \\( \\braket{x} \\) and \\( y_z \\) of \\( \\braket{y} \\) such that \\( z = x_z y_z \\), and elements \\( r_x \\) and \\( r_y \\) of \\( R \\) such that \\( x r_x = x_z \\) and \\( y r_y = y_z \\).\n\n  Therefore,\n  \\begin{equation*}\n    z = \\underbrace{(x r_x) (y r_y)}_{(xy) (r_x r_y)} \\in \\braket{xy}.\n  \\end{equation*}\n\n  \\NecessitySubProof* Let \\( z \\in \\braket{xy} \\). Then there exists an element \\( r \\) of \\( R \\) such that \\( z = rxy = (rx)(y) \\), hence \\( z \\in \\braket{x} \\braket{y} \\).\n\n  \\SubProofOf{thm:def:semiring_ideal/prime_pointwise} Suppose that \\( R \\) is commutative.\n  \\SufficiencySubProof* Let \\( P \\) be prime and let \\( xy \\in P \\). Then \\( \\braket{xy} \\subseteq P \\). By \\fullref{thm:def:semiring_ideal/product_of_principal_ideals}, \\( \\braket{x} \\braket{y} \\subseteq P \\), and hence \\( \\braket{x} \\subseteq P \\) or \\( \\braket{y} \\subseteq P \\). Therefore, \\( x \\in P \\) or \\( y \\in P \\).\n\n  \\NecessitySubProof* Let \\( P \\) be an ideal such that \\( xy \\in P \\) implies \\( x \\in P \\) or \\( y \\in P \\). Let \\( IJ \\subseteq P \\) and suppose that there exist \\( i \\in I \\setminus P \\) and \\( j \\in J \\setminus P \\).\n\n  Obviously \\( ij \\in I \\). But since \\( P \\) is prime, it follows that \\( i \\in P \\) or \\( j \\in P \\).\n\n  The obtained contradiction shows that \\( I \\) or \\( J \\) must be a subset of \\( P \\). Therefore, \\( P \\) is prime.\n\n  \\SubProofOf{thm:def:semiring_ideal/prime_is_radical} Suppose that \\( R \\) is commutative, let \\( P \\) be a prime ideal and let \\( x^n \\in P \\) for \\( n > 0 \\). We will show that \\( x \\in P \\).\n\n  We proceed via induction on \\( n \\). The case \\( n = 1 \\) is trivial. Suppose that \\( x^{n-1} \\in P \\) implies \\( x \\in P \\), and let \\( x = x \\cdot x^{n-1} \\in P \\). Since \\( P \\) is prime and \\( R \\) is commutative, by \\fullref{thm:def:semiring_ideal/prime_pointwise}, \\( x \\in P \\) or \\( x^{n-1} \\in P \\). In the latter case, we use the inductive hypothesis to show that \\( x \\in P \\).\n\n  Generalizing on \\( x \\), we conclude that \\( P \\) is a radical ideal.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:semiring_of_ideals}\n  \\hfill\n  \\begin{thmenum}\n    \\thmitem{thm:semiring_of_ideals/semiring} The set \\( \\mscrI \\) of all ideals of a semiring \\( R \\) is itself a semiring with the set addition and multiplication from \\hyperref[def:semiring/power_set]{power set semiring} \\( \\pow(R) \\).\n\n    \\thmitem{thm:semiring_of_ideals/order} Furthermore, \\( \\mscrI \\) is an \\hyperref[def:ordered_semiring]{ordered semiring} with respect to set inclusion.\n\n    \\thmitem{thm:semiring_of_ideals/lattice} The \\hyperref[def:partially_ordered_set_extremal_points/supremum_and_infimum]{supremum} of \\( I \\) and \\( J \\) is their sum \\( I + J \\) and their \\hyperref[def:partially_ordered_set_extremal_points/supremum_and_infimum]{infimum} is their intersection \\( I \\cap J \\). With this, \\( \\mscrI \\) becomes a lattice.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:semiring_of_ideals/semiring} Associativity and commutativity in \\( \\mscrI \\) are inherited from \\( R \\), as well as both left and right distributivity. Distributivity ensures that \\( I + J \\) is an ideal, while associativity of multiplication ensures that \\( IJ \\) is an ideal.\n\n  \\SubProofOf{thm:semiring_of_ideals/order} We must now prove that the partial order \\( \\subseteq \\) is compatible with addition and multiplication. Suppose that \\( I \\subseteq J \\) and let \\( H \\) be any ideal in \\( \\mscrI \\). Then\n  \\begin{equation*}\n    I + H \\subseteq J + H\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    IH \\subseteq JH.\n  \\end{equation*}\n\n  Therefore, \\( \\mscrI \\) is an ordered semiring.\n\n  \\SubProofOf{thm:semiring_of_ideals/lattice} Since \\( 0 \\in I \\), obviously \\( I \\subseteq I + J \\), and thus \\( I + J \\) is an upper bound of \\( I \\) and \\( J \\). If \\( H \\) is any other upper bound, it must contain the sums of all elements of \\( I \\) and all elements of \\( J \\), hence \\( I + J \\subseteq H \\). Therefore, \\( \\sup\\set{I, J} = I + J \\).\n\n  For \\( I \\cap J \\), it is an infimum of \\( I \\) and \\( J \\) as a consequence of \\fullref{thm:boolean_algebra_of_subsets/meet}.\n\\end{proof}\n\n\\begin{example}\\label{ex:def:semiring_ideal}\n  We list several examples of \\hyperref[def:semiring_ideal]{semiring ideals}.\n  \\begin{thmenum}\n    \\thmitem{ex:def:semiring_ideal/not_principal} The simplest example of an ideal that is not principal is the ideal \\( \\braket{ 2, 3 } \\) in \\( \\BbbN \\).\n\n    To see that it is not principal, suppose that \\( \\braket{ n } = \\braket{ 2, 3 } \\) for some natural number \\( n \\). This implies that there exist nonzero numbers \\( a \\) and \\( b \\) such that \\( n = 2a + 3b \\). Hence, \\( n > 2a > a \\) and \\( n > 3b > b \\). But then neither \\( 2 \\) nor \\( 3 \\) belongs to \\( \\braket{ n } \\), contradicting our assumption.\n\n    \\thmitem{ex:def:semiring_ideal/prime_not_maximal} The zero ideal \\( \\braket{ 0 } \\) in \\( \\BbbN \\) is \\hyperref[def:semiring_ideal/prime]{prime} but not \\hyperref[def:semiring_ideal/maximal]{maximal}.\n\n    Indeed, since \\( \\BbbN \\) is entire, \\( \\braket{ 0 } = \\set{ 0 } \\) and thus \\( \\braket{ 0 } \\) is prime. But it is not maximal since it is contained in every other ideal.\n\n    \\thmitem{ex:def:semiring_ideal/natural_numbers_principal_ideals} For natural numbers, \\( \\braket{ n } = \\braket{ m } \\) implies \\( n = m \\).\n\n    Indeed, by \\fullref{thm:def:semiring_ideal/division}, \\( n \\mid m \\) and \\( m \\mid n \\). Thus, there exist numbers \\( a \\) and \\( b \\) such that \\( n = am \\) and \\( m = bn \\), hence \\( n = abn \\). Since the semiring \\( \\BbbN \\) is \\hyperref[def:entire_semiring]{entire}, we can cancel \\( n \\) to obtain \\( ab = 1 \\). Then \\( a = b = 1 \\), and hence \\( n = m \\).\n\n    \\thmitem{ex:def:semiring_ideal/prime_numbers} A natural number \\( n \\) is \\hyperref[def:prime_number]{prime} if and only if \\( \\braket{n} \\) is a \\hyperref[def:semiring_ideal/prime]{prime ideal} in \\( \\BbbN \\).\n\n    Suppose that \\( n \\) is prime and let \\( n \\mid mk \\). From \\fullref{thm:euclids_lemma} it follows that either \\( n \\mid k \\) or \\( n \\mid m \\), hence \\fullref{thm:def:semiring_ideal/prime_pointwise} is satisfied and \\( \\braket{ n } \\) is a prime ideal.\n\n    In the other direction, suppose that \\( \\braket{ n } \\) is a prime ideal and let \\( n = ab \\). By \\fullref{thm:def:semiring_ideal/product_of_principal_ideals}, \\( \\braket{ n } = \\braket{ a } \\braket{ b } \\). Since \\( \\braket{ n } \\) is a prime ideal, \\( \\braket{ a } \\subseteq \\braket{ n } \\) or \\( \\braket{ b } \\subseteq \\braket{ n } \\).\n\n    Therefore, \\( \\braket{ n } = \\braket{ a } \\) or \\( \\braket{ n } = \\braket{ b } \\). By \\fullref{ex:def:semiring_ideal/natural_numbers_principal_ideals}, \\( n = a \\) or \\( n = b \\), which in turn implies that the other is a unit.\n\n    Therefore, \\( n \\) is a prime number.\n    \\thmitem{ex:def:semiring_ideal/matrices} Consider the matrix algebra \\( \\BbbZ^{2 \\times 2} \\). The set\n    \\begin{equation*}\n      \\set[\\Bigg]\n      {\n        \\begin{pmatrix}\n          0 & a \\\\\n          0 & b\n        \\end{pmatrix}\n        \\given*\n        a, b \\in \\BbbZ\n      }.\n    \\end{equation*}\n    is a left ideal. It is not a right ideal, however, because\n    \\begin{equation*}\n      \\begin{pmatrix}\n        1 & 0 \\\\\n        1 & 0\n      \\end{pmatrix}\n      \\begin{pmatrix}\n        0 & 1 \\\\\n        0 & 1\n      \\end{pmatrix}\n      =\n      \\begin{pmatrix}\n        0 & 1 \\\\\n        0 & 1\n      \\end{pmatrix}.\n    \\end{equation*}\n\n    \\thmitem{ex:def:semiring_ideal/polynomial_ideals} Consider the bivariate \\hyperref[def:polynomial_algebra]{polynomial semiring} \\( \\BbbN[X, Y] \\) over natural numbers. Since \\( (X + Y)^2 = X^2 + 2XY + Y^2 \\), we have\n    \\begin{equation*}\n      \\braket{ X^2 + 2XY + Y^2 } \\subseteq \\braket{ X + Y }.\n    \\end{equation*}\n\n    \\thmitem{ex:def:semiring_ideal/ideal_polynomials} Ideals in polynomial semirings are often studied, but we can also study polynomials in ideal semirings, i.e. polynomials over the semiring \\( \\mscrI \\) of ideals of a semiring \\( R \\). For example,\n    \\begin{equation*}\n      I^2 J + K\n    \\end{equation*}\n    is a trivariate polynomial function over \\( \\mscrI \\).\n\n    \\thmitem{ex:def:semiring_ideal/maximal_induced_coprime} If \\( M \\) is a maximal ideal and \\( x \\in R \\setminus M \\), then \\( M \\) and \\( \\braket{ x } \\) are \\hyperref[def:semiring_ideal/coprime]{coprime}.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{theorem}[Maximal ideal theorem]\\label{thm:maximal_ideal_theorem}\\mcite[prop. 6.59]{Golan2010}\n  Every proper \\hyperref[def:semiring_ideal]{semiring ideal} is contained in a \\hyperref[def:semiring_ideal/maximal]{maximal ideal}.\n\n  Within \\hyperref[def:zfc]{\\logic{ZF}}, this theorem is equivalent to the \\hyperref[def:zfc/choice]{axiom of choice} --- see \\fullref{thm:axiom_of_choice_equivalences/maximal_ideal}.\n\\end{theorem}\n\\begin{proof}\n  We will discuss equivalence with \\fullref{thm:zorns_lemma}.\n\n  \\ImplicationSubProof[thm:zorns_lemma]{Zorn's lemma}[thm:maximal_ideal_theorem]{maximal ideal theorem} Let \\( I \\) be a proper ideal in the semiring \\( R \\). Denote by \\( \\mscrH \\) the set of all proper ideals in \\( R \\) that contain \\( I \\). The union of every chain in \\( \\mscrH \\) is again an ideal, and by Zorn's lemma, \\( \\mscrH \\) has a maximal element. That is, there exists a maximal ideal in \\( \\mscrH \\) that contains \\( I \\).\n\n  \\ImplicationSubProof[thm:maximal_ideal_theorem]{maximal ideal theorem}[thm:zorns_lemma]{Zorn's lemma} In \\cite{Hodges1979}, Hodges proves that the statement \\enquote{every \\hyperref[def:unique_factorization_domain]{unique factorization domain} has a maximal ideal} implies Zorn's lemma. We have an even stronger antecedent.\n\\end{proof}\n\n\\begin{definition}\\label{def:radical_ideal}\n  Let \\( I \\) be an \\hyperref[def:semiring_ideal]{ideal} in the \\hyperref[def:ring/commutative]{commutative ring} \\( R \\). The \\term{radical} \\( \\sqrt I \\) of \\( I \\) is a specific ideal containing \\( I \\) that we will define shortly. A \\term{radical ideal} is an ideal that is equal to its radical. The \\term{nilradical} of the ring \\( R \\) is \\hyperref[def:radical_ideal]{radical} \\( \\sqrt {\\braket{ 0_R }} \\) of the zero ideal, whose elements we call \\term{nilpotent elements}.\n\n  The radical of the ideal \\( I \\) is the ideal defined equivalently through any of the following:\n  \\begin{thmenum}\n    \\thmitem{def:radical_ideal/direct}\\mcite[15]{КоцевСидеров2016}\n    \\begin{equation}\\label{eq:def:radical_ideal/direct}\n      \\sqrt I \\coloneqq \\set{ x \\in R \\given \\qexists {n \\in \\BbbZ_{>0}} x^n \\in I }.\n    \\end{equation}\n\n    \\thmitem{def:radical_ideal/intersection} \\( \\sqrt I \\) is the intersection of all \\hyperref[def:semiring_ideal/prime]{prime ideals} of \\( R \\) containing \\( I \\).\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  \\SubProof{Proof of correctness of \\eqref{eq:def:radical_ideal/direct}} We only need to prove that the radical \\( \\sqrt I \\) of the ideal \\( I \\) is an ideal.\n\n  Multiplicative closure is simpler. If \\( x \\) belongs to \\( \\sqrt I \\), then there exists a power \\( x^n \\) that belongs to \\( I \\). Let \\( r \\) be any member of \\( r \\). Then \\( rx = rx^n \\in I \\) since \\( I \\) is closed with respect to multiplication.\n\n  Additive closure is a bit more involved. If \\( x \\) and \\( y \\) both belong to \\( \\sqrt I \\), then there exist powers \\( n \\) and \\( m \\) such that \\( x^n \\in I \\) and \\( y^m \\in I \\). Let \\( u \\coloneqq n + m - 1 \\). By \\fullref{thm:binomial_theorem},\n  \\begin{equation*}\n    (x + y)^u = \\sum_{k=0}^u \\binom u k x^k y^{u-k}.\n  \\end{equation*}\n\n  \\begin{itemize}\n    \\item If \\( k < n \\), then \\( x^k y^{u-k} = (x^k y^{n - k - 1}) y^m \\) and, since \\( y^m \\in I \\), we have \\( x^k y^{u-k} \\in I \\).\n    \\item If \\( k \\geq n \\), then \\( x^k y^{u-k} = x^n (x^{k-n} y^{u-k}) \\) and, since \\( x^n \\in I \\), we have \\( x^k y^{u-k} \\in I \\).\n  \\end{itemize}\n\n  Since \\( I \\) is closed under addition, \\( (x + y)^u \\in I \\).\n\n  \\ImplicationSubProof{def:radical_ideal/direct}{def:radical_ideal/intersection} Let \\( x \\in \\sqrt I \\). That is, there exists a positive integer \\( n \\) such that \\( x^n \\in I \\). Let \\( P \\) be a prime ideal containing \\( I \\). We will show that \\( x \\in P \\).\n\n  Since \\( P \\) is prime, by \\fullref{thm:def:semiring_ideal/prime_pointwise}, \\( x^{n-1} \\in P \\) or \\( x \\in P \\). If \\( x^{n-1} \\in P \\), then \\( x^{n-2} \\in P \\) or \\( x \\in P \\). Proceeding by induction on \\( k \\) in \\( x^{n-k} \\), we eventually obtain that \\( x \\in P \\).\n\n  \\ImplicationSubProof{def:radical_ideal/intersection}{def:radical_ideal/direct} Conversely, let \\( x \\) be a member of every prime ideal containing \\( P \\). We will show that \\( x \\in \\sqrt I \\).\n\n  Suppose that \\( x^n \\not\\in I \\) for every \\( n \\) and consider the following family of ideals:\n  \\begin{equation*}\n    \\mscrH \\coloneqq \\set{ J \\T{is an ideal of} R \\T{containing} I \\given \\qforall {n \\in \\BbbZ_{>0}} x^n \\not\\in J }.\n  \\end{equation*}\n\n  It is nonempty because \\( I \\in \\mscrH \\).\n\n  For every chain of ideals in \\( \\mscrH \\), their union is also an ideal in \\( \\mscrH \\). By \\fullref{thm:zorns_lemma}, \\( \\mscrH \\) has a maximal element \\( H \\). We will show that \\( H \\) is prime.\n\n  From \\( AB \\subseteq H \\) it follows that \\( AB \\in \\mscrH \\). If we suppose that neither \\( A \\) nor \\( B \\) belongs to \\( \\mscrH \\), we obtain that there exist positive integers \\( n \\) and \\( m \\) such that \\( x^n \\in A \\) and \\( x^m \\in B \\). But \\( x^{n + m} \\) must then belong to \\( AB \\), which contradicts \\( AB \\in \\mscrH \\). The obtained contradiction demonstrates that \\( H \\) is a prime ideal. But this is impossible since, by assumption \\( x \\) is contained in every prime ideal, and \\( x \\not\\in H \\). So this must contradict our previous assumption that \\( x^n \\neq 0 \\) for every \\( n \\).\n\n  Therefore, \\( x \\) belongs to \\( \\sqrt I \\).\n\\end{proof}\n\n\\begin{example}\\label{ex:def:radical_ideal}\n  We list examples of \\hyperref[def:radical_ideal]{radical ideal}.\n\n  \\begin{thmenum}\n    \\thmitem{ex:def:radical_ideal/natural_numbers} Suppose that the natural number \\( m \\) has a prime decomposition\n    \\begin{equation*}\n      m = p_1^{k_1} \\cdots p_n^{k_n}.\n    \\end{equation*}\n\n    Then the radical of its principal ideal is\n    \\begin{equation*}\n      \\sqrt{ \\braket{ p_1^{k_1} \\cdots p_n^{k_n} } } = \\braket{ p_1 \\cdots p_n }.\n    \\end{equation*}\n\n    Indeed, for any \\( a p_1 \\cdots p_n \\) from the radical, with \\( k \\coloneqq \\max\\set{ k_1, \\ldots, k_n } \\) we have\n    \\begin{equation*}\n      (a p_1 \\cdots p_n)^k = (a p_1^{k-k_1} \\cdots p_n^{k-k_n}) p_1^{k_1} \\cdots p_n^{k_n}.\n    \\end{equation*}\n\n    To obtain \\( m \\), we can take \\( k = 1 \\) and \\( a = p_1^{k_1-1} \\cdots p_n^{k_1-1} \\):\n    \\begin{equation*}\n      a p_1 \\cdots p_n = p_1^{k_1} \\cdots p_n^{k_n} = m.\n    \\end{equation*}\n\n    Particular examples of this are\n    \\begin{itemize}\n      \\item The ideal \\( { \\braket{ 6 } } \\) is radical. It is not prime since \\( \\braket{ 2 } \\braket{ 3 } = \\braket{ 6 } \\), but neither are subsets.\n\n      \\item For any prime \\( p \\), \\( \\braket{ p } \\) is radical\n\n      \\item For any prime power \\( p^n \\), \\( \\sqrt{\\braket{ p^n }} = \\braket{ p } \\). For example, \\( \\sqrt{\\braket{ 4 }} = \\braket{ 2 } \\).\n    \\end{itemize}\n\n    \\thmitem{ex:def:radical_ideal/matrices} Consider the matrix ring \\( \\BbbN^{2 \\times 2} \\). The matrix\n    \\begin{equation*}\n      A \\coloneqq\n      \\begin{pmatrix}\n        0 & 1 \\\\\n        0 & 0 \\\\\n      \\end{pmatrix}\n    \\end{equation*}\n    is a \\hyperref[thm:def:semiring_ideal/nilradical]{nilpotent element} of \\( \\BbbN^{n \\times n} \\) because \\( A^2 \\) is the zero matrix. We refer to such matrices as \\term{nilpotent matrices}.\n\n    The transposed matrix \\( A^T \\) is also nilpotent. Hence, their linear combinations are also nilpotent.\n  \\end{thmenum}\n\\end{example}\n", "meta": {"hexsha": "7329165c8053b8273ef4b8e6c999050917f9c68a", "size": 26458, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/semiring_ideals.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/semiring_ideals.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/semiring_ideals.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.8131313131, "max_line_length": 607, "alphanum_fraction": 0.6506538665, "num_tokens": 8849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.7319297692332474}}
{"text": "\\chapter{Numerical Time Integration of Partial/Ordinary Differential Equations}\n\n\\section{Introduction}\n\nMany engineering problems are described as either a partial differential equation (PDE) or ordinary differential equation (ODE). A broad class of important problems is called the ``Initial Value Problem'' (IVP). Take for example the continuity equation in semiconductors, which is given as\\begin{IEEEeqnarray}{rCl}\n\\frac{\\partial n}{\\partial t} & = & -\\text{div}\\left(\\bm{J}\\right) + G_\\text{n} - R_\\text{n} \\label{eq:continuityEqn}\n\\end{IEEEeqnarray}where $n$ is the carrier concentration, $\\bm{J}$ is the current density flowing through the semiconductor, $G_\\text{n}$ and $R_\\text{n}$ are the rates of carrier generation and recombination due to generation and recombination processes, respectively. The IVP is as follows. Assume that at time, $t=0$, the carrier concentration is $n(t=0)={0}$ and we want to find the time-dependent profile of the carrier concentration, $n(t)$.\n\nIn general, the PDE is more complicated than that in Equation~(\\ref{eq:continuityEqn}), and the time derivative or slope function is denoted as $\\dot{y}(t)=f(t, y)$, where $y(t)$ is the quantity we are trying to solve for, having the initial condition $y(t=0)=y_{0}$.\n\n\\section{The Forward (Explicit) Euler Method}\\label{sec:forwardEuler}\n\nOne method to obtain $y(t)$ from $f(t,y)$ and $y_{0}$ is to use the forward Euler method. First, the time range over which to determine $y(t)$ is discretized into a uniform grid. The time difference between each grid point, $\\Delta t=h$ is called the \\emph{time step}. The IVP is solved by calculating $y(t_{n})$ iteratively starting at $t_{n}=0$ and $y(t=0)=y_0$ using the formula\\begin{IEEEeqnarray}{rCl}\ny(t_{n}+h) & = & y(t_{n}) + hf(t_{n},y(t_{n})) \\label{eq:compExEuler}\n\\end{IEEEeqnarray}Mathematically, the Equation~(\\ref{eq:compExEuler}) is unwieldy and we simplify the expression using $t_{n+1}=t_{n}+h$, $y_{n+1}=y(t_{n+1})$ and $y_{n}=y(t_{n})$, which gives\\begin{IEEEeqnarray}{rCl}\ny_{n+1} & = & y_{n} + hf(t_{n},y_{n}) \\label{eq:simpExEuler}\n\\end{IEEEeqnarray}\n\n\\subsection{Example 1: Solutions with Persistent Oscillations}\n\nConsider the function $y(t) = \\sin (t)$ and its time derivative, $\\dot{y}(t) = \\cos (t)$. The numerical solution for different time steps are plotted in Fig.~\\ref{fig:IVP1}. As clearly seen, the error reduces with the size of the time step---a smaller time step returns a numerical result that is closer to the ideal solution.\n\n\\subsection{Example 2: Solutions with Damped Relaxations}\n\nAnother commonly observed function is $y(t) = \\exp(-t)$ and its time derivative, $\\dot{y}(t) = -\\exp(-t)$. The numerical solution for different time steps are plotted in Fig.~\\ref{fig:IVP2}. As clearly seen, the error also reduces with the size of the time step.\\afterpage{\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[scale=0.4]{ResearchNotes_TimePDE/figs/eulerTest.eps}\n\\caption{Numerical solution for the IVP with $\\dot{y}(t)=\\cos(t)$ and $y_{0}=0$ for different step sizes as compared to the ideal solution $y(t)=\\sin(t)$.}\n\\label{fig:IVP1}\n\\end{figure}\\begin{figure}[!t]\n\\centering\n\\includegraphics[scale=0.4]{ResearchNotes_TimePDE/figs/eulerTest2.eps}\n\\caption{Numerical solution for the IVP with $\\dot{y}(t)=-\\exp(-t)$ and $y_{0}=1.0$ for different step sizes as compared to the ideal solution $y(t)=\\exp(-t)$.}\n\\label{fig:IVP2}\n\\end{figure}\\clearpage\n}\n\nIn Equation~(\\ref{eq:simpExEuler}), $y_{n+1}$ appears only on the LHS, which means it is \\emph{explicitly} defined. Thus, the forward Euler method is an explicit method. In contrast, the \\emph{backward} (\\emph{implicit}) Euler method is described by\\begin{IEEEeqnarray}{rCl}\ny_{n+1} & = & y_{n} + hf(t_{n+1},y_{n+1}) \\label{eq:compImEuler}\n\\end{IEEEeqnarray}Furthermore, the Euler methods calculate $y_{n+1}$ using only $y_{n}$ and not previous $y$ values (\\emph{i.e.}, $y_{n-1}$, $y_{n-2}$, etc.). Hence, the Euler methods are examples of \\emph{single step methods}. The Adams-Bashforth methods, Adams-Moulton methods and the backward differentiation formulas (BDF) are \\emph{linear multistep methods}. For example, the two-step Adams-Bashforth method is described by the formula\\begin{IEEEeqnarray}{rCl}\ny_{n+2} & = & y_{n+1} + \\frac{3}{2}hf(t_{n+1},y_{n+1}) - \\frac{1}{2}hf(t_{n},y_{n}) \\label{eq:AB12}\n\\end{IEEEeqnarray}where information at $y_{n}$ is used to calculate $y_{n+2}$ from $y_{n+1}$. Consequently, linear multistep methods need to be initialized in order to proceed.\n\n\\section{Higher Order Explicit Methods}\n\nEquation~(\\ref{eq:simpExEuler}) has a similar form as the power series expansion, which is written as\\begin{IEEEeqnarray}{rCl}\ny(t_{n+1}) & = & \\sum^{+\\infty}_{i=0}a_{i}y^{(i)}(t_{n})\n\\end{IEEEeqnarray}where the superscript in $y^{(i)}$ denotes the $i$-th derivative of $y$. Thus, the forward Euler method may be thought of as a first order estimation for $y(t_{n+1})$ and the full expression of Equation~(\\ref{eq:simpExEuler}) is\\begin{IEEEeqnarray}{rCl}\ny_{n+1} & = & y_{n} + hf(t_{n},y_{n}) + \\mathcal{O}(h^{2})\n\\end{IEEEeqnarray}and the error in using Equation~(\\ref{eq:simpExEuler}) to approximate $y(t)$ is $\\mathcal{O}(h^{2})$. By expanding the power series further, we can derive higher order explicit methods for $y_{n+1}$ and reduce the error.\n\n\\subsection{The Heun Method}\n\nThe Heun method is a second order method to approximate $y_{n+1}$ and is given by the expression\\begin{IEEEeqnarray}{rCl}\ny_{n+1} & = & y_{n} + h\\frac{k_{1}+k_{2}}{2},~\\text{where} \\label{eq:heun} \\\\\nk_{1} & = & f(t_{n},y_{n}) \\nonumber \\\\\nk_{2} & = & f(t_{n+1},y_{n}+hk_{1}) \\nonumber\n\\end{IEEEeqnarray}It can be seen that $y_{n+1}$ is determined using two evaluations of $f()$ ($k_{1}$ and $k_{2}$). The evaluation of $k_{1}$ is akin to the explicit Euler method. The evaluation of $k_{2}$ occurs at the point predicted using the Euler method. The average of $k_{1}$ and $k_{2}$ is then used to estimate $y_{n+1}$.\n\n\\subsection{The 4-th Order Runge-Kutta (RK) Method}\n\nGerman mathematicians Carl Runge and Wilhelm Kutta derived methods (also called Runge-Kutta methods or RK methods) to approximate $y_{n+1}$. The 4-th order RK method (RK4) is given by the expression\\begin{IEEEeqnarray}{rCl}\ny_{n+1} & = & y_{n} + \\frac{h}{6}\\left(k_{1}+2k_{2}+2k_{3}+k_{4}\\right),~\\text{where} \\\\\nk_{1} & = & f(t_{n},y_{n}) \\nonumber \\\\\nk_{2} & = & f\\left(t_{n}+\\frac{h}{2}, y_{n}+h\\frac{k_{1}}{2}\\right) \\nonumber \\\\\nk_{3} & = & f\\left(t_{n}+\\frac{h}{2}, y_{n}+h\\frac{k_{2}}{2}\\right) \\nonumber \\\\\nk_{4} & = & f(t_{n+1},y_{n}+hk_{3}) \\nonumber\n\\end{IEEEeqnarray}In this method $f()$ are evaluated at points within the time step to obtain a better approximation of $y_{n+1}$.\n\n\\subsection{The Butcher Tableau}\n\nFrom the methods discussed so far, it can be seen that the general equation for determining $y_{n+1}$ in single step methods is \\begin{IEEEeqnarray}{rCl}\ny_{n+1} & = & y_{n} + h\\sum^{s}_{i=1}b_{i}k_{i},~\\text{where} \\\\\nk_{1} & = & f(t_{n},y_{n}) \\nonumber \\\\\nk_{2} & = & f(t_{n}+c_{2}h,y_{n}+ha_{21}k_{1}) \\nonumber \\\\\nk_{3} & = & f(t_{n}+c_{3}h,y_{n}+ha_{31}k_{1}+ha_{32}k_{2}) \\nonumber \\\\\n& \\vdots & \\\\\nk_{s} & = & f(t_{n}+c_{s}h, y_{n}+h\\sum^{s-1}_{j=1}a_{s,j}k_{j}) \\nonumber\n\\end{IEEEeqnarray}where $k_{i}$ is calculated in the $i$-th stage of the method. The mathematician John C. Butcher proposed a concise way of describing the numerical methods using a tableau called the \\emph{Butcher tableau} (see Fig.~\\ref{fig:butcherTab}).\n\nFrom the earlier examples, we can see that the Butcher tableaus for the Euler method and RK4 method are given by Figs.~\\ref{fig:eulerButcher} and Fig.~\\ref{fig:rk4Butcher}. The Heun method is a special case of a more general method called the \\emph{midpoint method}, which has the Butcher tableau given in Fig.~\\ref{fig:midpointButcher}.\n\n\\begin{figure}[!b]\n\\centering\n\\includegraphics[scale=1.0]{ResearchNotes_TimePDE/figs/ButcherTableau.eps}\n\\caption{The general form of a Butcher Tableau}\n\\label{fig:butcherTab}\n\\end{figure}\n\\begin{figure}[!b]\n\\centering\n\\includegraphics[scale=1.0]{ResearchNotes_TimePDE/figs/eulerButcher.eps}\n\\caption{Butcher Tableau for the Euler method.}\n\\label{fig:eulerButcher}\n\\end{figure}\n\\begin{figure}[!b]\n\\centering\n\\includegraphics[scale=1.0]{ResearchNotes_TimePDE/figs/rk4Butcher.eps}\n\\caption{Butcher Tableau for the RK4 method.}\n\\label{fig:rk4Butcher}are\n\\end{figure}\n\\begin{figure}[!b]\n\\centering\n\\includegraphics[scale=1.0]{ResearchNotes_TimePDE/figs/midpointTableau.eps}\n\\caption{Butcher Tableau for the midpoint method. The Heun method is the case where $\\alpha=1$.}\n\\label{fig:midpointButcher}\n\\end{figure}\n\nThe algorithm for executing the explicit methods is shown in Algorithm~\\ref{algo:algo1}.\n\\begin{algorithm}[H]\n\\caption{Numerical method to solve IVP without adaptive time stepping}\n\\label{algo:algo1}\n\\hspace*{\\algorithmicindent} $\\textbf{Inputs:}~a_{i,j},~b_{i}~\\text{and}~c_{i}~\\text{from Butcher tableau,}~f(t,y),~t_\\text{end},~h_\\text{init},~\\text{and}~y_{0}$ \\\\\n\\hspace*{\\algorithmicindent} $\\textbf{Outputs:}~y~\\text{for all discrete time points,~}t\\in{}[0,~t_\\text{end}] $\n\\begin{algorithmic}[1]\n\\State $n \\gets 0$\n\\State $t_{n} \\gets 0$\n\\State $y_{n} \\gets y_{0}$\n\\State $h_{n} \\gets h_\\text{init}$\n\\While{$t_{n} < t_\\text{end}$}\n  \\If{$t_\\text{end} < t_{n} + h_{n}$}\n    \\State $h_{n} = t_\\text{end} - t_{n}$\n  \\EndIf\n  \\State $k_{1} \\gets f(t_{n}, y_{n})$\n  \\State $\\delta{}y \\gets b_{1}k_{1}$\n  \\For{$i0 \\gets 2$, number of stages defined in the Butcher tableau}\n    \\State $t_\\text{int} \\gets t_{n} + c_{i0}h_{n}$\n    \\State $j \\gets$ number of substeps in stage~$i0$\n    \\State $y_\\text{int} \\gets y_{n} + h_{n}\\sum^{j}_{i1=1}a_{i0,i1}k_{i1}$\n    \\State $k_{i0} \\gets f(t_\\text{int},y_\\text{int})$\n    \\State $\\delta{}y \\gets \\delta{}y + b_{i0}k_{i0}$\n  \\EndFor\n  \\State $h_{n+1} \\gets h_{n}$\n  \\State $y_{n+1} \\gets y_{n} + h_{n}\\cdot\\delta{}y$\n  \\State $t_{n+1} \\gets t_{n} + h_{n}$\n  \\State $n \\gets n+1$\n\\EndWhile\n\\end{algorithmic}\n\\end{algorithm}\n\n\\afterpage{\n\\begin{figure}[H]\n\\centering\n\\begin{minipage}{0.45\\linewidth}\n\\centering\n\\includegraphics[scale=1.0]{ResearchNotes_TimePDE/figs/EmbeddedButcherTableau.eps}\n\\caption{The general Butcher tableau for embedded methods.}\n\\label{fig:embeddedButcher}\n\\end{minipage}\n\\quad\\quad\n\\begin{minipage}{0.45\\linewidth}\n\\centering\n\\includegraphics[scale=1.0]{ResearchNotes_TimePDE/figs/rk23.eps}\n\\caption{The Butcher tableau for the Bogacki-Shampine method. The method has a second order predictor and third order corrector and the LTE is $\\bm{O}(h^{3})$.}\n\\label{fig:rk23}\n\\end{minipage}\n\\end{figure}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.8]{ResearchNotes_TimePDE/figs/fehlberg.eps}\n\\caption{The Butcher tableau for the Fehlberg method. The method has a fourth order predictor and fifth order corrector and the LTE is $\\bm{O}(h^{5})$.}\n\\label{fig:fehlberg}\n\\end{figure}\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.8]{ResearchNotes_TimePDE/figs/rk45ck.eps}\n\\caption{The Butcher tableau for the Cash-Karp method. The method has a fourth order predictor and fifth order corrector and the LTE is $\\bm{O}(h^{5})$.}\n\\label{fig:rk45ck}\n\\end{figure}\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.8]{ResearchNotes_TimePDE/figs/rk45dp.eps}\n\\caption{The Butcher tableau for the Dormand-Prince method. The method has a fourth order predictor and fifth order corrector and the LTE is $\\bm{O}(h^{5})$.}\n\\label{fig:rk45dp}\n\\end{figure}\\clearpage\n}\n\n\\section{Adaptive time stepping}\n\nAs can be seen in Figs.~\\ref{fig:IVP1} and \\ref{fig:IVP2}, there is a dependence of the accuracy of the solution returned by the numerical method and the time step used. In engineering simulations, the simulation runtime may be reduced if the time steps can be optimized. Adaptive time stepping algorithms attempt to optimize the time step used by ensuring that the estimated local truncation error (\\emph{LTE}) is bounded to some tolerance value. The LTE is calculated by subtracting two approximations of $y_{n+1}$---one with order $p$ and another with order $p-1$, which leads to the LTE having order $p$. These methods are sometimes called \\emph{predictor-corrector} methods, since one expression gives a low order predicted value of $y_{n+1}$ and the LTE gives a high order corrector to the predictor.\n\nA family of embedded RK methods exist that is computationally efficient in calculating $y_{n+1}$ and the LTE at the $n$-th step, $\\bm{\\widehat{r}}_{n}$. These methods are computationally efficient because they reduce the number of calls to evaluate $f()$, which is the most computationally intensive portion of the numerical method. Fig.~\\ref{fig:embeddedButcher} shows the general form of the Butcher tableau for an embedded method.\n\nSome commonly used embedded explicit methods are those by Bogacki-Shampine (RK23) \\cite{Bogacki1989} (Fig.~\\ref{fig:rk23}), Fehlberg (RK45F) \\cite{Fehlberg1970} (Fig.~\\ref{fig:fehlberg}), Cash-Karp (RF45CK) \\cite{Cash1990} (Fig.~\\ref{fig:rk45ck}), and Dormand-Prince (RK45DP) \\cite{Dormand1980} (Fig.~\\ref{fig:rk45dp}). A key difference between the RK45 methods is the number of evaluations of $f()$ needed to estimate $y_{n+1}$. Some methods (such as RK23 and RK45DP) have a ``first same as last'' (FSAL) property, which means the predictor is calculated at the last stage.\n\nAdaptive time stepping is performed by calculating the ratio of an error tolerance to the LTE. The next time step in the numerical method is then scaled according to the equation\\begin{IEEEeqnarray}{rCl}\nh_{n+1} & = & 0.9 \\times h_{n} \\times \\min\\left(\\max \\left(\\left(\\frac{\\text{tol}}{|\\bm{\\widehat{r}}_{n}|}\\right)^{1/(p+1)},0.3\\right), 2\\right)\\label{eq:adapH0}\n\\end{IEEEeqnarray}where $p$ is the order of the corrector. The factor of 0.9 is a safety factor to limit the change in $h$ and reduce the risk that $h_{n+1}$ is rejected when calculating $y_{n+2}$. The $\\min$ and $\\max$ further limit $h_{n+1}$ to the range $[0.27h_{n}, 1.8h_{n}]$.\n\nAn alternative scheme was proposed by K. Gustafsson in \\cite{Gustafsson1988}. The work is motivated by control theory and seeks to handle issues that arise when solving stiff problems (see Section~\\ref{subsec:stabilityExp}) and remain useful for both explicit and the implicit methods (to be discussed after Section~\\ref{subsec:stabilityExp}). First, Equation~(\\ref{eq:adapH0}) is rewritten as\\begin{IEEEeqnarray}{rCl}\nh_{n+1} & = & \\theta{}h_{n} \\label{eq:adapH1} \\\\\n\\theta & = & \\gamma\\left(\\frac{\\text{tol}}{|\\bm{\\widehat{r}}_{n}|/h_{n}}\\right)^{1/p} = \\left(\\frac{\\gamma^{p}\\cdot\\text{tol}}{|\\bm{\\widehat{r}}_{n}|/h_{n}}\\right)^{1/p}\n\\end{IEEEeqnarray}where $\\gamma$ is the safety factor ($\\gamma=0.9$ in Equation~(\\ref{eq:adapH0})), and $|\\bm{\\widehat{r}}_{n}|\\propto{}h_{n}$. Taking the $\\log()$ on both sides gives\\begin{IEEEeqnarray}{rCl}\n\\log(h_{n+1}) & = & \\log(h_{n}) + \\frac{1}{p}\\left(\\log(\\gamma^{p}\\cdot\\text{tol}) - \\log\\left(\\frac{|\\bm{\\widehat{r}}_{n}|}{h_{n}}\\right)\\right)\n\\end{IEEEeqnarray}In \\cite{Gustafsson1988}, $\\gamma=1.0$ and,\\begin{IEEEeqnarray}{rCl}\ne_{n} & = &  \\log(\\gamma^{p}\\cdot\\text{tol}) - \\log\\left(\\frac{|\\bm{\\widehat{r}}_{n}|}{h_{n}}\\right) \\\\\nP_{n} & = & K_\\text{P}\\cdot e_{n} \\\\\nI_\\text{temp} & = & I_{n-1} + K_\\text{I}\\cdot{}e_{n} \\\\\nh_\\text{temp} & = & \\exp\\left(P_{n}+I_\\text{temp}\\right) \\\\\nh_{n+1} & = & \\min\\left(h_\\text{temp},\\theta_\\text{max}h_{n}\\right) \\\\\nI_{n} & = & I_\\text{temp} + \\log(h_{n+1}) - \\log(h_{n})\n\\end{IEEEeqnarray}where $\\theta_\\text{max}$ limits the growth of $h$. Then, the time stepping algorithm calculates the following\\begin{IEEEeqnarray}{rCl}\nh_\\text{temp} & = & \\left(\\frac{\\text{tol}}{|\\bm{\\widehat{r}}_{n}|/h_{n}}\\right)^{K_\\text{I}}\\left(\\frac{|\\bm{\\widehat{r}}_{n-1}|/h_{n-1}}{|\\bm{\\widehat{r}}_{n}|/h_{n}}\\right)^{K_\\text{P}}h_{n} \\label{eq:gustafTrack} \\\\\nh_{n+1} & = & \\min\\left(h_\\text{temp},\\theta_\\text{max}h_{n}\\right)\n\\end{IEEEeqnarray}where it is recommended that $\\theta_\\text{max}=2.0$. Equation~(\\ref{eq:gustafTrack}) states that during the execution of the algorithm, $|\\bm{\\widehat{r}}_{n}|/h_{n}$ needs to be saved for the next time step for adaptive time stepping. Furthermore, two sets of parameters are recommended depending on whether the time step is rejected (\\emph{e.g.}, $|\\bm{\\widehat{r}}_{n}|/h_{n}>1.2\\cdot{}\\text{tol}$) or accepted. If the time step is accepted, use $K_\\text{P}=0.13$ and $K_\\text{I}=1/15$. Otherwise, use $K_\\text{P}=0$ and $K_\\text{I}=1/5$.\n\nThe algorithm for executing the explicit methods with adaptive time stepping is shown in Algorithm~\\ref{algo:algo2}, where the function, $adaptH()$, can implement either the conventional method, or the Gustafsson method. \\begin{algorithm}[H]\n\\caption{Numerical method to solve IVP with adaptive time stepping}\n\\label{algo:algo2}\n\\hspace*{\\algorithmicindent} $\\textbf{Inputs:}~p\\text{~(order of embedded corrector)},~a_{i,j},~b_{i},~b^{*}_{i}~\\text{and}~c_{i}~\\text{from Butcher tableau,}~f(t,y),~errTol,$ \\\\\n\\hspace*{\\algorithmicindent}\\hspace*{\\algorithmicindent}$adaptH(),~t_\\text{end},~h_\\text{init},~\\text{and}~y_{0}$ \\\\\n\\hspace*{\\algorithmicindent} $\\textbf{Outputs:}~y~\\text{for all discrete time points,~}t\\in{}[0,~t_\\text{end}] $\n\\begin{algorithmic}[1]\n\\State $n \\gets 0$\n\\State $t_{n} \\gets 0$\n\\State $y_{n} \\gets y_{0}$\n\\State $h_{n} \\gets h_\\text{init}$\n\\While{$t_{n} < t_\\text{end}$}\n  \\If{$t_\\text{end} < t_{n} + h_{n}$}\n    \\State $h_{n} = t_\\text{end} - t_{n}$\n  \\EndIf\n  \\State $rejectH \\gets true$\n  \\While{$rejectH$~is~$true$}\n    \\State $k_{1} \\gets f(t_{n}, y_{n})$\n    \\State $\\delta{}y \\gets b_{1}k_{1}$\n    \\State $LTE_{n} \\gets (b_{1} - b^{*}_{1})k_{1}$\n    \\For{$i0 \\gets 2$, number of stages defined in the Butcher tableau}\n      \\State $t_\\text{int} \\gets t_{n} + c_{i0}h_{n}$\n      \\State $j \\gets$ number of substeps in stage~$i0$\n      \\State $y_\\text{int} \\gets y_{n} + h_{n}\\sum^{j}_{i1=1}a_{i0,i1}k_{i1}$\n      \\State $k_{i0} \\gets f(t_\\text{int},y_\\text{int})$\n      \\State $\\delta{}y \\gets \\delta{}y + b_{i0}k_{i0}$\n      \\State $LTE_{n} \\gets LTE_{n} + (b_{i0} - b^{*}_{i0})k_{i0}$\n    \\EndFor\n    \\State $rejectH, h_\\text{recommend} \\gets adaptH(p, h_{n}, errTol, LTE_{n}, \\delta{}y)$\n    \\If{$rejectH$ is $true$}\n      \\State $h_{n} \\gets h_\\text{recommend}$\n    \\Else\n      \\State $h_{n+1} \\gets h_\\text{recommend}$\n    \\EndIf\n  \\EndWhile\n  \\State $y_{n+1} \\gets y_{n} + h_{n}\\cdot\\delta{}y$\n  \\State $t_{n+1} \\gets t_{n} + h_{n}$\n  \\State $n \\gets n+1$\n\\EndWhile\n\\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{Stability of Explicit Methods and Stiffness of IVP}\\label{subsec:stabilityExp}\n\nA major disadvantage of explicit methods is that the errors introduced when used to solve stiff IVPs can be extremely large. Examples of stiff problems are encountered when critically damped and overdamped systems are studied. Consider the example of a non-ideal voltage source charging a fixed capacitor, $C_\\text{L}$, through an output resistance, $R_\\text{out}$ to a voltage given by $V_\\text{DD}$. The circuit equation to solve is the ODE expressed as\\begin{IEEEeqnarray}{rCl}\n\\frac{d V_\\text{C}}{dt} & = & \\frac{V_\\text{DD}-V_\\text{C}}{R_\\text{out}C_\\text{L}}\n\\end{IEEEeqnarray}The ideal solution for the voltage across the capacitor, $V_\\text{C}(t)$, when the initial condition is 0~V is\\begin{IEEEeqnarray}{rCl}\nV_\\text{C}(t) & = & V_\\text{DD}\\left(1-\\exp\\left(\\frac{-t}{R_\\text{out}C_\\text{L}}\\right)\\right)\n\\end{IEEEeqnarray}Fig.~\\ref{fig:falseOscillation} shows a case where a poorly chosen time step leads to a numerical solution that continually oscillates without converging to the steady-state solution.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.4]{ResearchNotes_TimePDE/figs/forwardOscillations.eps}\n\\caption{Poor numerical solution with oscillations was obtained as the problem is too stiff for the explicit numerical method.}\n\\label{fig:falseOscillation}\n\\end{figure}\n\nAnother problem arises when adaptive time stepping is used. As the solution approaches the final steady-state value, the time step will reduce significantly to manage the error within the error tolerance, which leads to long simulation runtime even though the results are converging to the correct solution. These problems can be overcome by implicit methods.\n\n\\section{The Backward (Implicit) Euler Method}\n\nAs presented in Equation~(\\ref{eq:compImEuler}), the implicit Euler method is described by\\begin{IEEEeqnarray}{rCl}\ny_{n+1} & = & y_{n} + hf(t_{n+1},y_{n+1}) \\nonumber\n\\end{IEEEeqnarray}The solution we are trying to solve for, $y_{n+1}$, appears on both sides of the equation, which makes it cumbersome to solve. The general approach to solve the equation utilizes an educated guess for the solution, $y^{*}_{n+1}$, and a residual function, $R(y^{*}_{n+1})$. If we substitute $y^{*}_{n+1}$ into Equation~(\\ref{eq:compImEuler}), we obtain\\begin{IEEEeqnarray}{rCl}\ny^{*}_{n+1} & = & y_{n} + hf(t_{n+1},y^{*}_{n+1}) + R(y^{*}_{n+1}) \\\\\nR(y^{*}_{n+1}) & = & y^{*}_{n+1} - y_{n} - hf(t_{n+1},y^{*}_{n+1}) \\label{eq:imEulerRes}\n\\end{IEEEeqnarray}We clearly see in Equation~(\\ref{eq:imEulerRes}) that $R(y^{*}_{n+1})$ is the error in Equation~(\\ref{eq:compImEuler}) if the educated guess was used as the solution. The objective now is to search for $y^{*}_{n+1}$ so that $R(y^{*}_{n+1})=0$. This can be achieved using the Newton-Raphson method. We start by assuming $R(y^{*}_{n+1})$ is sufficiently small that\\begin{IEEEeqnarray}{rCl}\nR'(y^{*}_{n+1}) & \\approx & \\frac{R(y^{*}_{n+1})}{y^{*}_{n+1} - y^{**}_{n+1}}\n\\end{IEEEeqnarray}where $R'(y^{*}_{n+1})$ is the derivative of the residual function with respect to $y^{*}_{n+1}$, and $y^{**}_{n+1}$ is our updated guess of $y_{n+1}$. Rearranging the terms, we obtain the equation\\begin{IEEEeqnarray}{rCl}\ny^{**}_{n+1} & = & y^{*}_{n+1} - \\frac{R(y^{*}_{n+1})}{R'(y^{*}_{n+1})} \\label{eq:newtonUpdate0}\n\\end{IEEEeqnarray}We may then check $(y^{**}_{n+1} - y^{*}_{n+1})$ (and possibly $R(y^{**}_{n+1})$) against some convergence criteria. If the criteria is met, $y^{**}_{n+1}$ is accepted as $y_{n+1}$ and we move to calculate the next time step in the implicit Euler method. If the criteria is not met, we substitute $y^{**}_{n+1}$ as $y^{*}_{n+1}$ in Equation~(\\ref{eq:newtonUpdate0}) and update our guess for $y_{n+1}$ to check against the convergence criteria, repeating until the convergence criteria is met.\n\nIn many engineering problems, Equation~(\\ref{eq:compImEuler}) describes a system of equations where $y_{n+1}$ and $y_{n}$ describes values over a spatial grid at a particular time. In many cases, $f()$ is a matrix describing an operator. Consider the 1-D diffusion equation over a uniform spatial grid on the Cartesian axes described by\\begin{IEEEeqnarray}{rCl}\n\\frac{\\partial y}{\\partial t} & = & -D\\overrightarrow{\\nabla}^{2}y \\\\\n& = & -\\frac{D}{dx^{2}}Ay\n\\end{IEEEeqnarray}where $D$is the diffusion coefficient, $dx$ is the spacing between grid points, and $A$ is the tridiagonal matrix representing the Laplacian operator in Cartesian coordinates. Substituting into Equation~(\\ref{eq:compImEuler}), the discretized diffusion IVP is solved by the implicit Euler method by\\begin{IEEEeqnarray}{rCl}\ny_{n+1} & = & y_{n} - h\\frac{D}{dx^{2}}Ay_{n+1} \\\\\n\\left(I + h\\frac{D}{dx^{2}}A\\right)y_{n+1} & = & y_{n} \\\\\ny_{n+1} & = & \\left(I + h\\frac{D}{dx^{2}}A\\right)^{-1}y_{n} \\label{eq:imEulerDiff}\n\\end{IEEEeqnarray}where $I$ is the identity matrix. Equation~(\\ref{eq:imEulerDiff}) shows that $y_{n+1}$ is found by inverting the matrix $\\left(I + h\\frac{D}{dx^{2}}A\\right)$ and pre-multiplying with $y_{n}$.\n\n\\section{Higher Order Implicit Methods}\n\nJust as for explicit methods, a family of higher order implicit methods also exist.\n\n\\subsection{The Theta Method}\n\nThe Theta method combines the explicit Euler step with an implicit Euler step:\\begin{IEEEeqnarray}{rCl}\ny_{n+1} & =  y_{n} + h\\theta{}f(t_{n},y_{n}) + h(1-\\theta)f(t_{n}, y_{n+1})\n\\end{IEEEeqnarray}The Crank-Nicolson or trapezoidal method is obtained if $\\theta=0.5$, and hence\\begin{IEEEeqnarray}{rCl}\ny_{n+1} & =  y_{n} + h\\frac{f(t_{n},y_{n}) + f(t_{n}, y_{n+1})}{2}\n\\end{IEEEeqnarray}Note that due to the implicit nature of the backward Euler step, the Crank-Nicolson method is not an average between the forward and backward Euler steps. Applying the Crank-Nicolson method to the diffusion IVP as before, we obtain\\begin{IEEEeqnarray}{rCl}\ny_{n+1} & = & y_{n} - \\frac{h}{2}\\frac{D}{dx^{2}}Ay_{n} - \\frac{h}{2}\\frac{D}{dx^{2}}Ay_{n+1} \\\\\n\\left(I + \\frac{h}{2}\\frac{D}{dx^{2}}A\\right)y_{n+1} & = & \\left(I - \\frac{h}{2}\\frac{D}{dx^{2}}A\\right)y_{n} \\\\\ny_{n+1} & = & \\left(I + \\frac{h}{2}\\frac{D}{dx^{2}}A\\right)^{-1}\\left(I - \\frac{h}{2}\\frac{D}{dx^{2}}A\\right)y_{n}\n\\end{IEEEeqnarray}", "meta": {"hexsha": "9514682652c7c7d278cc8a8c5f59f4c40f7ddda0", "size": 24652, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TimePDE.tex", "max_stars_repo_name": "seeder-research/ResearchNotes_TimePDE", "max_stars_repo_head_hexsha": "42c6e590ccfe33911390810fff7d13d353dc2ce4", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "TimePDE.tex", "max_issues_repo_name": "seeder-research/ResearchNotes_TimePDE", "max_issues_repo_head_hexsha": "42c6e590ccfe33911390810fff7d13d353dc2ce4", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TimePDE.tex", "max_forks_repo_name": "seeder-research/ResearchNotes_TimePDE", "max_forks_repo_head_hexsha": "42c6e590ccfe33911390810fff7d13d353dc2ce4", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 82.1733333333, "max_line_length": 806, "alphanum_fraction": 0.702620477, "num_tokens": 8528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7319297675530027}}
{"text": "% corrected VD 89\n\n\\subsubsection{Feedforward Neural Network}~\\\\\n\nFeedforward neural networks or multilayer perceptrons (MLPs) are very important\ndeep learning models. The objective of MLPs is to approximate a given function\n$f^{*}$. A feedforward network defines a mapping $\\bm{\\hat{y}} = f(\\bm{x};\n\\bm{\\theta})$ and learns the values of the parameter $\\bm{\\theta}$ with a given\ninput vector $\\bm{x}$ which yields the best approximation of $f^{*}$. This\nfunction can be for example a classifier, $y = f^{*}(\\bm{x})$ which maps an\ninput $\\bm{x}$ to a class $y$.\\\\\n\nThese structures are called \\textbf{feedforward} since there is a progress of\ninformation in one direction: From input to output.\\\\\n\nMLPs are considered \\textbf{networks} because they are made up of composed\nfunctions. Let $f_{1}$, $f_{2}$ and $f_{3}$ be three function forming a chain\n$f(\\bm{x}) = f_{3}(f_{2}(f_{1}(\\bm{x})))$. The chain structures are commonly\nused in ANNs. In this example, $f_{1}$ is called the first layer of the network,\n$f_{2}$ is the second layer, etc. The lenght of the chain represents the depth\nof the network. The final layer is also called the output layer.\\\\\n\nDuring the training of the neural network, we try to find $f(\\bm{x})$ to\napproximate $f^{*}(\\bm{x})$. The training data contains examples of\n$f^{*}(\\bm{x})$ obtained with different training points where every example\n$\\bm{x}$ is referring to a label $y \\approx f^{*}(\\bm{x})$. These examples\ndetermine how the output layer should approximate a value close to $y$ with each\nexample $\\bm{x}$. The other layers are called the \\textbf{hidden layers} because\nthe training examples are not determining their behaviour and it does not\ncontain the desired output of each layer. Therefore, a learning algorithm has to\ndetermine how to utilize the hidden layers to obtain a good approximation of\n$f^{*}(\\bm{x})$.\\\\\n\nThe \\textbf{width} of the feedforward model is defined by the dimensionality of\neach hidden layer which is usually a vector containing values. These vector\nlayers contain many \\textbf{units} which process data in parallel. Each unit\nrefers to a vector-to-scalar function, by taking input from other units and\ncalculating its proper activation value.\\\\\n\nWe will present a simple MLP with one hidden layer which contains hidden units.\nThe hidden layer represents a vector of hidden units $\\bm{h}$ which are\ncalculated by a function $f_{1}(\\bm{x;\\theta})$. $\\bm{\\theta}$ consists of\n$\\bm{W}$ and $\\bm{b}$ which are the $weights$ and $biases$\nrepectively such that:\n\n\\begin{equation}\n  \\begin{split}\n    h & = f_{1}(\\bm{x;W,b}) \\\\\n    \\Leftrightarrow h & = \\bm{W}^{T}\\bm{x}+\\bm{b}\n  \\end{split}\n\\end{equation}\n\n$\\bm{h}$ is then used as input for the second layer which is the output layer;\n$f_{2}(\\bm{h;V,c})$, with $V$ being the weigth matrix and $c$ the bias vector. \n\n\\begin{equation}\n  \\begin{split}\n    y & = f_{2}(\\bm{h;V,c}) \\\\\n    \\Leftrightarrow y & = \\bm{V}^{T}\\bm{h}+\\bm{c}\n  \\end{split}\n\\end{equation}\n\nThe network can be illustrated as a chain of two functions:\n\n\\begin{equation} \n  \\begin{split}\n  f(\\bm{x;W,b,V,c}) \\\\\n  = f_{2}(f_{1}(\\bm{x}))\n  \\end{split}\n\\end{equation}\n\nAfter using an affine transformation, the hidden units are computed by a\nnonlinear function $g$ called an activation function:\n\n\\begin{equation} \n  h = g(\\bm{W}^{T}\\bm{x+b})\n\\end{equation}\n\nThe common activation function in deep learning is the \\textbf{rectified linear\nunit} or ReLU defined as:\n\n\\begin{equation} \n  g(z) = \\max\\{0,z\\}\n\\end{equation}\n\n\\input{sections/scientific/fr2/relu.tex}\n\nThe complete feedforward network looks as follows:\n\\begin{equation} \n  \\begin{split}\n  f(\\bm{x;W,b,V,c}) \\\\\n  = \\bm{V}^{T}\\max\\{0,\\bm{W}^{T}\\bm{x+b}\\}+\\bm{c}\n\\end{split}\n\\end{equation}\n\nA representation of a single perceptron and its position in an MLP is given in\nFigure~\\ref{ff}.\\\\\n\n\\input{sections/scientific/fr2/mlpfigure.tex}\n\n\\textbf{Gradient-Based Learning.} During the training of the model, deep\nlearning algorithms solve an optimization problem. The problem is to minimize\nthe error represented by an objective function (loss).  With the loss function\nthe deep learning model optimizes the approximation of $f^{*}$. An example of a\nloss function for MLP can be the mean squared error (MSE):\\\\\n\n\\begin{equation} \n  \\frac{1}{n}\\sum_{i=1}^n(f^*(\\bm x_i)-f(\\bm x_i;\\bm{\\theta}))^2\n\\end{equation}~\\\\\n\nANNs usually uses gradient-based optimizers to obtain a minimal loss function.\\\\\n\n\n\\textbf{Back-propagation.} Gradient descent is a back-propagation algorithm\nwhich performs a backward pass through the network while adjusting the model's\nparameters which are the weights and biases. It repeatedly modifies the\nparameters of the units in the network to minimize the error between the\npredicted and desired output vector. The algorithm passes information from the\nloss function backwards through the network. It computes the gradient while\npassing back the network. There are three types of gradient descent, namely\nbatch gradient descent, stochastic gradient descent (SGD) and mini-batch\ngradient descent. Compared to batch gradient descent, SGD selects randomly a\ndata sample instead of a whole data batch for each backward iteration.\n", "meta": {"hexsha": "8e77b6987e09d76459f5cdf72df507fb302ef3e9", "size": 5181, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/scientific/fr2/feedforward.tex", "max_stars_repo_name": "Lemswasabi/bsps3-report", "max_stars_repo_head_hexsha": "ca3f7bee2d4740c5c7ad9f586766ab04a0e5f58b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sections/scientific/fr2/feedforward.tex", "max_issues_repo_name": "Lemswasabi/bsps3-report", "max_issues_repo_head_hexsha": "ca3f7bee2d4740c5c7ad9f586766ab04a0e5f58b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/scientific/fr2/feedforward.tex", "max_forks_repo_name": "Lemswasabi/bsps3-report", "max_forks_repo_head_hexsha": "ca3f7bee2d4740c5c7ad9f586766ab04a0e5f58b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.7822580645, "max_line_length": 80, "alphanum_fraction": 0.7313259988, "num_tokens": 1442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7318303547092554}}
{"text": "\\providecommand{\\main}{../..}\n\\documentclass[\\main/thesis.tex]{subfiles}\n\\begin{document}\n\n\\section{The Addition Function}\\label{addition}\n\nThe addition function on \\lstinline|ℕ| can consequently be defined by\nrecursively ``moving'' the successor function \\lstinline|suc| from one number\nto the another.\n\n\\begin{lstlisting}\n_+_ : ℕ → ℕ → ℕ\nzero  + y = y\nsuc x + y = suc (x + y)\n\\end{lstlisting}\n\nWe may attempt to define addition on \\lstinline|Numeral| with the same strategy.\n\n\\begin{lstlisting}\n_+_ : ∀ {b d o}\n    → Numeral b d o\n    → Numeral b d o\n    → Numeral b d o\nx ∙      + ys = ? x ys\n(x ∷ xs) + ys = ? x (xs + ys)\n\\end{lstlisting}\n\nHowever, there is not a corresponding successor function on \\lstinline|Numeral|\nthat allows us to recursively move a digit from one numeral to the another with.\nWhat we need is some sort of ``one-sided'' addition function that takes\n\\textit{a digit} and \\textit{a numeral} instead of two numerals.\n\n\\begin{lstlisting}\nn+ : ∀ {b d o}\n    → Digit d\n    → Numeral b d o\n    → Numeral b d o\n\\end{lstlisting}\n\nMoreover, to ensure that a system is closed under these operations,\nwe require these systems to be \\lstinline|Continuous|.\n\n\\begin{lstlisting}\n∀ {b d o} → True (Continuous? b d o)\n\\end{lstlisting}\n\n\\subsection{Sum of Two Digits}\n\nBefore implementing \\lstinline|n+|, we need to take a step back and figure out\nhow to add \\textit{two digits} together.\nAdding two digits should result in \\textbf{a digit} and\npossibly \\textbf{a carry} when the sum overflows.\n\nThe carry is often a \\textit{fixed digit} in most of the systems that we are\nfamiliar with.\nHowever, when it comes to redundant systems,\nthe carry is often \\textit{indefinite},\nbecause there is more than one way of representing a number.\n\n\\subsubsection{View for the Sum}\n\nWe capture these cases with a view called \\lstinline|Sum|.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\ndata Sum : (b d o : ℕ) (x y : Digit (suc d)) → Set where\n\\end{lstlisting}\n\nWhen the sum of two digits can still be represented by a single digit,\nwe compute the sum as \\lstinline|leftover| and support it with a proof.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\n    NoCarry : ∀ {b d o x y}\n        → (leftover : Digit (suc d))\n        → (property : Digit-toℕ leftover o ≡ sum o x y)\n        → Sum b d o x y\n\\end{lstlisting}\n\nWhen the sum of two digits exceeds the upper bound of a digit,\nwe move the exceeding part to \\lstinline|carry| and leave the remainder to\n\\lstinline|leftover|. \\lstinline|property| ensures the integrity of this\ncomputation.\n\nWe opt for the constructor \\lstinline|Fixed| when the exceeding part that goes\nto \\lstinline|carry| is fixed (equals to \\lstinline|1 ⊔ o|) and\n\\lstinline|Floating| when it is indefinite.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\n    Fixed Floating : ∀ {b d o x y}\n        → (leftover carry : Digit (suc d))\n        → (property : Digit-toℕ leftover o\n                        + (Digit-toℕ carry o) * suc b ≡ sum o x y)\n        → Sum b d o x y\n\\end{lstlisting}\n\nWe dispense with the implementation of the corresponding view function\n\\lstinline|sumView| for brevity.\n\\footnote{about 300 lines of code and reasoning.}\n\n\\begin{lstlisting}\nsumView : ∀ b d o\n    → (¬gapped : ¬ (Gapped#0 b d o))\n    → (proper : 2 ≤ suc d + o)\n    → (x y : Digit (suc d))\n    → Sum b d o x y\n\\end{lstlisting}\n\n\\subsubsection{\\lstinline|n+| on Proper Systems}\n\nImplementing \\lstinline|n+| on proper systems are relatively simple since most\nof the hard work has been done by \\lstinline|sumView|.\nCarries are added back by recursively calling \\lstinline|n+-Proper|.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\nn+-Proper : ∀ {b d o}\n    → (¬gapped : ¬ (Gapped#0 b d o))\n    → (proper : suc d + o ≥ 2)\n    → (x : Digit (suc d))\n    → (xs : Numeral (suc b) (suc d) o)\n    → Numeral (suc b) (suc d) o\nn+-Proper {b} {d} {o} ¬gapped proper x xs\n    with sumView b d o ¬gapped proper x (lsd xs)\nn+-Proper ¬gapped proper x (_ ∙)    | NoCarry leftover property\n    = leftover ∙\nn+-Proper ¬gapped proper x (_ ∷ xs) | NoCarry leftover property\n    = leftover ∷ xs\nn+-Proper ¬gapped proper x (_ ∙)    | Fixed leftover carry property\n    = leftover ∷ carry ∙\nn+-Proper ¬gapped proper x (_ ∷ xs) | Fixed leftover carry property\n    = leftover ∷ n+-Proper ¬gapped proper carry xs\nn+-Proper ¬gapped proper x (_ ∙)    | Floating leftover carry property\n    = leftover ∷ carry ∙\nn+-Proper ¬gapped proper x (_ ∷ xs) | Floating leftover carry property\n    = leftover ∷ n+-Proper ¬gapped proper carry xs\n\\end{lstlisting}\n\n\\subsubsection{Properties of \\lstinline|n+-Proper|}\n\nThe property below verifies the correctness of \\lstinline|n+-Proper|.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\nn+-Proper-toℕ : ∀ {b d o}\n    → (¬gapped : ¬ (Gapped#0 b d o))\n    → (proper : suc d + o ≥ 2)\n    → (x : Digit (suc d))\n    → (xs : Numeral (suc b) (suc d) o)\n    → ⟦ n+-Proper ¬gapped proper x xs ⟧ ≡ Digit-toℕ x o + ⟦ xs ⟧\nn+-Proper-toℕ ¬gapped proper x xs with sumView b d o ¬gapped proper x (lsd xs)\nn+-Proper-toℕ ¬gapped proper x (_ ∙)     | NoCarry _ property = property\nn+-Proper-toℕ ¬gapped proper x (x' ∷ xs) | NoCarry leftover property =\n    begin\n        ⟦ leftover ∷ xs ⟧\n    ≡⟨ ... property ... ⟩\n        Digit-toℕ x o + ⟦ x' ∷ xs ⟧\n    ∎\nn+-Proper-toℕ ¬gapped proper x (_ ∙)     | Fixed _ _ property = property\nn+-Proper-toℕ ¬gapped proper x (x' ∷ xs) | Fixed leftover carry property =\n    begin\n        ⟦ leftover ∷ n+-Proper ¬gapped proper carry xs ⟧\n    ≡⟨ ... n+-Proper-toℕ ... ⟩\n        Digit-toℕ leftover o + (Digit-toℕ carry o + ⟦ xs ⟧) * suc b\n    ≡⟨ ... property ... ⟩\n        Digit-toℕ x o + ⟦ x' ∷ xs ⟧\n    ∎\nn+-Proper-toℕ ¬gapped proper x (_ ∙)     | Floating _ _ property = property\nn+-Proper-toℕ ¬gapped proper x (x' ∷ xs) | Floating leftover carry property =\n    begin\n        ⟦ leftover ∷ n+-Proper ¬gapped proper carry xs ⟧\n    ≡⟨ ... n+-Proper-toℕ ... ⟩\n        Digit-toℕ leftover o + (Digit-toℕ carry o + ⟦ xs ⟧) * suc b\n    ≡⟨ ... property ... ⟩\n        Digit-toℕ x o + ⟦ x' ∷ xs ⟧\n    ∎\n\\end{lstlisting}\n\n\\subsubsection{Generalizing \\lstinline|n+-Proper| to all Systems}\n\nBy imposing the condition of continuity, we exclude systems that are not\nacceptable for \\lstinline|n+-Proper|.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\nn+ : ∀ {b d o}\n    → {cont : True (Continuous? b d o)}\n    → (n : Digit d)\n    → (xs : Numeral b d o)\n    → Numeral b d o\nn+ {b} {d} {o}      n xs with numView b d o\nn+ {_} {_} {_} {()} n xs | NullBase d o\nn+ {_} {_} {_}      n xs | NoDigits b o = NoDigits-explode xs\nn+ {_} {_} {_} {()} n xs | AllZeros b\nn+ {_} {_} {_}      n xs | Proper b d o proper with Gapped#0? b d o\nn+ {_} {_} {_} {()} n xs | Proper b d o proper | yes gapped#0\nn+ {_} {_} {_}      n xs | Proper b d o proper | no ¬gapped#0\n    = n+-Proper ¬gapped#0 proper n xs\n\\end{lstlisting}\n\nThe proof of the correctness of \\lstinline|n+-toℕ| also follows the same pattern.\n\n\\begin{lstlisting}\nn+-toℕ : ∀ {b d o}\n    → {cont : True (Continuous? b d o)}\n    → (n : Digit d)\n    → (xs : Numeral b d o)\n    → ⟦ n+ {cont = cont} n xs ⟧ ≡ Digit-toℕ n o + ⟦ xs ⟧\n\\end{lstlisting}\n\n\\subsubsection{Implmentation of the Addition Function}\n\nFirst, we define the addition function on systems of \\lstinline|Proper| with\nthe one-sided addition function \\lstinline|n+-Proper|.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\n+-Proper : ∀ {b d o}\n    → (¬gapped : ¬ (Gapped#0 b d o))\n    → (proper : suc d + o ≥ 2)\n    → (xs ys : Numeral (suc b) (suc d) o)\n    → Numeral (suc b) (suc d) o\n+-Proper ¬gapped proper (x ∙)    ys       = n+-Proper ¬gapped proper x ys\n+-Proper ¬gapped proper (x ∷ xs) (y ∙)    = n+-Proper ¬gapped proper y (x ∷ xs)\n+-Proper {b} {d} {o} ¬gapped proper (x ∷ xs) (y ∷ ys)\n    with sumView b d o ¬gapped proper x y\n+-Proper ¬gapped proper (x ∷ xs) (y ∷ ys) | NoCarry leftover property\n    = leftover ∷ +-Proper ¬gapped proper xs ys\n+-Proper ¬gapped proper (x ∷ xs) (y ∷ ys) | Fixed leftover carry property\n    = leftover ∷ n+-Proper ¬gapped proper carry (+-Proper ¬gapped proper xs ys)\n+-Proper ¬gapped proper (x ∷ xs) (y ∷ ys) | Floating leftover carry property\n    = leftover ∷ n+-Proper ¬gapped proper carry (+-Proper ¬gapped proper xs ys)\n\\end{lstlisting}\n\nBy generalizing \\lstinline|+-Proper| to all continuous numeral systems,\nthe addition function we have been long for can be implemented as follows.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\n_+_ : ∀ {b d o}\n    → {cont : True (Continuous? b d o)}\n    → (xs ys : Numeral b d o)\n    → Numeral b d o\n_+_ {b} {d} {o}  xs ys with numView b d o\n_+_ {cont = ()}   xs ys | NullBase d o\n_+_ {cont = cont} xs ys | NoDigits b o = NoDigits-explode xs\n_+_ {cont = ()}   xs ys | AllZeros b\n_+_ {cont = cont} xs ys | Proper b d o proper with Gapped#0? b d o\n_+_ {cont = ()}   xs ys | Proper b d o proper | yes ¬gapped#0\n_+_ {cont = cont} xs ys | Proper b d o proper | no ¬gapped#0\n    = +-Proper ¬gapped#0 proper xs ys\n\\end{lstlisting}\n\n\\subsubsection{Properties of the Addition Function}\n\nWe can prove that the evaluation function \\lstinline|⟦_⟧| is a homomorphism\nbetween \\lstinline|Numeral| and \\lstinline|ℕ| that preserves their addition\nfunctions.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\ntoℕ-+-homo : ∀ {b d o}\n    → (cont : True (Continuous? b d o))\n    → (xs ys : Numeral b d o)\n    → ⟦ _+_ {cont = cont} xs ys ⟧ ≡ ⟦ xs ⟧ + ⟦ ys ⟧\n\\end{lstlisting}\n\nThe proofs are skipped for brevity.\n\\footnote{about 100 lines of code and reasoning.}\n\n\\end{document}\n", "meta": {"hexsha": "f507155f9dbc40a8896a552758b73050abd759cf", "size": 9491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/tex/constructions/addition.tex", "max_stars_repo_name": "banacorn/numeral", "max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z", "max_issues_repo_path": "Thesis/tex/constructions/addition.tex", "max_issues_repo_name": "banacorn/numeral", "max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Thesis/tex/constructions/addition.tex", "max_forks_repo_name": "banacorn/numeral", "max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z", "max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z", "avg_line_length": 35.9507575758, "max_line_length": 81, "alphanum_fraction": 0.6501949215, "num_tokens": 3168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.938124016006303, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7317300768405374}}
{"text": "\\subsection{Neuron Dynamics}\n\\label{subsec:neuron_dynamics}\n\n\n\\subsubsection{Current}\n\nThe original paper described the dynamics of neuron \\(\\nu_{i}\\) as the change of its current \\(c_{i}\\) with time:\n\n        \\begin{equation}\n            \\tau \\dot{c}_{i}(t) = - {c}_{i}(t) + \\sum_{j=1}^{N} r_{j}(t) \\cdot W_{i,j} + \\xi_{i}(t)\n        \\label{eq:continuous_dynamics} \\end{equation}\n\n        where:\n\n        \\begin{tabular}{l} \\\\\n            \\(\\tau \\in \\R\\) is the decay time, \\\\\n            \\(c \\in \\R\\) is the synaptic current, \\\\\n            \\(N \\in \\N\\) is the network number of neurons, \\\\\n            \\(W\\) is the weight matrix, \\\\\n            \\(r \\in \\R\\) is the firing rates, \\\\\n            \\(\\xi \\in \\R\\) is the Gaussian noise.\n        \\label{tab:conditions_continuous_dynamics} \\end{tabular}\n\n\n\n    The former equation can be discretized using the Euler method:\n\n        \\begin{equation}\n            c_{i}(t+1) = -c_{i}(t) + \\frac{dt}{\\tau} \\left[-c_{i}(t) + \\sum_{j=1}^{N} r_{j}(t) \\cdot W_{i,j} + \\frac{\\xi_{i}(t)}{\\sqrt{dt}} \\right]\n        \\label{eq:discrete_dynamics} \\end{equation}\n\n        where:\n\n        \\begin{tabular}{l}\n            \\(dt \\in \\R\\) is the integration time step\n        \\label{tab:conditions_discrete_dynamics} \\end{tabular}\n\n\\subsubsection{Firing Rates}\n\nFiring rates \\(r\\) of each neuron are calculated by the gain function \\(g(c)\\), a step function with sublinear behavior or a value of zero:\n\n        \\begin{equation}\n            g(c) =\n            \\begin{cases}\n                (c + \\theta)^{\\gamma}   & \\text{if~} (c + \\theta) > 0 \\\\\n                0                       & \\text{if~} (c + \\theta) \\leq 0\n            \\end{cases}\n        \\label{eq:firing_rates} \\end{equation}\n\n        where:\n\n        \\begin{tabular}{l} \\\\\n            \\(\\theta \\in \\R\\) is the gain function threshold, \\\\\n            \\(\\gamma \\in \\R_{<1}\\) is the gain function exponent. \\\\\n        \\label{tab:conditions_firing_rates} \\end{tabular} \\bigskip\n\n\n\\subsubsection{Memory Patterns}\n\nEvery memory is represented by a binary vector or pattern \\(\\boldsymbol{p}\\) of size \\(N\\).\nEach element of this vector corresponds to the state \\(s\\) of each neuron \\(\\nu\\) for that memory pattern.\nThe value of this state is \\(0\\) if the neuron does not encode for that pattern and \\(1\\) if it does.\n\nThe different states are stored in a \\(M \\times N\\) matrix, with shape:\n\n    \\[\\bordermatrix{\n        ~ & \\nu_1 & \\nu_2 & \\cdots & \\nu_n  \\cr\n        p_1 &  s_{1}^{1} & s_{2}^{1} & \\cdots & s_{n}^{1}  \\cr\n        p_2 &  1 & 0 & \\cdots & 1  \\cr\n        \\vdots &  \\vdots  & \\vdots & \\ddots & \\vdots  \\cr\n        p_m &  s_{1}^{m} & s_{2}^{m} & \\cdots & s_{n}^{m}\n    }\\]\n\n\n\\subsubsection{Inhibition}\n\n\n    The network is subjected to periodic inhibition driven by a sine wave \\(\\phi(t)\\), with the form:\n\n        % \\begin{equation}\n        %      \\begin{gathered}\n        %         A = \\frac{1}{2} (\\phi_{max} - \\phi_{min}) \\\\\n        %         \\phi(t) = A \\left(1 + \\frac{\\phi_{min}}{A} + \\sin\\left[\n        %         2 \\pi \\left(t + \\frac{p_{\\phi}}{dt}\\right) \\frac{1}{t_{\\phi}} dt\n        %         \\right] \\right)\n        %      \\end{gathered}\n        % \\label{eq:sine_wave} \\end{equation}\n\n        \\begin{equation}\n            \\frac{\\phi_{max} - \\phi_{min}}{2} \\left[1 +  \\sin \\left(2 \\pi t + \\frac{\\pi}{2} \\right) \\right]\n        \\end{equation}\n        \n        where:\n\n        \\begin{tabular}{l} \\\\\n            %\\(A \\in \\R_{>0}\\) is the amplitude, \\\\\n            \\(\\phi_{min} \\in \\R\\) is the minimum inhibition hyperparameter, \\\\\n            \\(\\phi_{max} \\in \\R\\) is the maximum inhibition hyperparameter, \\\\\n            %\\(p_{\\phi} \\in \\R\\) is the oscillation phase shift, \\\\\n            %\\(t_{\\phi} \\in \\R\\) is the oscillation time. \\\\\n        \\label{tab:conditions_sine_wave} \\end{tabular} \\bigskip\n\n\n\\subsubsection{Weights}\n\n\n    Each neuron in the network is fully connected to all the other neurons.\n    This gives a \\(N \\times N\\) weight matrix \\(\\boldsymbol{W}_{i, j}\\) representing the strength of connection or weight \\(w\\) between neurons \\(\\nu_{i}\\) and \\(\\textit{}\\nu_{j}\\):\n\n    \\[\\bordermatrix{\n        ~ & \\nu_1 & \\nu_2 & \\cdots & \\nu_n  \\cr\n        \\nu_1 &  w_{1, 1} & w_{1, 2} & \\cdots & w_{1, n}  \\cr\n        \\nu_2 &  w_{2, 1} & w_{2, 2} & \\cdots & w_{2, n}  \\cr\n        \\vdots &  \\vdots  & \\vdots & \\ddots & \\vdots  \\cr\n        \\nu_m &  w_{m, 1} & w_{m, 2} & \\cdots & w_{m, n}\n    }\\] \\bigskip\n\n\n\n    To calculate the weight matrix, the following Hebbian rule is used:\n\n        \\begin{equation}\n            W_{i,j} = \\frac{\\kappa}{N} \\left[ \\sum_{p=1}^{M} (s_{i}^{p} - f) (s_{j}^{p} - f) - \\phi(t) \\right]\n        \\label{eq:weights} \\end{equation}\n\n        where:\n\n        \\begin{tabular}{l} \\\\\n            \\(\\kappa \\in \\R_{\\geqslant 0}\\) is the excitation, \\\\\n            \\(M \\in \\N\\) is the number of memories, \\\\\n            \\(s \\in \\Z_{[0, 1]}\\) is the neuron state for a memory, \\\\\n            \\(p\\) is the memory pattern, \\\\\n            \\(f \\in \\R\\) is the sparsity, \\\\\n            \\(\\phi \\in \\R\\) is the oscillatory inhibition.\n        \\label{tab:conditions_weights} \\end{tabular} \\bigskip\n\n\n    To account for short term associations to the previous and next memories as in the SAM model, a new term \\(\\boldsymbol{W}_{i,j}^{*}\\) is added to the original weight matrix:\n\n        \\begin{equation}\n        W_{i, j}^{SAM} = W_{i, j} + W_{i, j}^{*} = W_{i, j} + \\frac{\\kappa}{N} \\left[ \\kappa_{f} \\sum_{p=1}^{M-1} s_{i}^{p} \\cdot s_{j}^{p+1} + \\kappa_{b} \\sum_{p=2}^{M} s_{i}^{p} \\cdot s_{j}^{p-1} \\right]\n        \\label{eq:weights_sam} \\end{equation}\n\n        where:\n\n        \\begin{tabular}{l} \\\\\n            \\(\\kappa_{f} \\in \\R\\) is the forward contiguity, \\\\\n            \\(\\kappa_{b} \\in \\R\\) is the backward contiguity. \\\\\n        \\label{tab:conditions_weights_sam} \\end{tabular} \\bigskip\n\n\n\\subsubsection{Noise}\n\n\n    Each neuron is subjected to Gaussian noise \\(\\xi\\), following the probability density function:\n\n        \\begin{equation}\n            p(z) = \\frac{1}{\\sigma \\sqrt{ 2 \\pi}} e^{ - \\frac{ (z - \\mu)^2 } {2 \\sigma^2} }\n        \\label{eq:noise} \\end{equation}\n\n        where:\n\n        \\begin{tabular}{l} \\\\\n            \\(\\mu \\in \\R\\) is the noise mean, \\\\\n            \\(\\sigma \\in \\R_{\\geqslant 0}\\) is the noise standard deviation.\n        \\label{tab:conditions_noise} \\end{tabular} \\bigskip\n\n\n\\subsection{Population Dynamics}\n\\label{subsec:population_dynamics}\n\n    Simulating the network with the original parameters is very computationally expensive, with the computation time depending primarily on the number of neurons.\n    The system can be simplified, reducing the number of simulated units.\n    All neurons that present the same activation state for the different memories will be considered that belong to the same population \\(\\pi\\).\n    Moreover, all these neurons have an identical weight matrix \\(\\boldsymbol{W}_{i, j}\\)\\footnote{\\(i j\\) notation refers to the simulated unit, which is from now on a population of neurons instead of the single neuron.}, which will be the weight matrix of the population.\n\n\n\\subsubsection{Current}\n\n    A new term \\(S_{\\pi}\\) is introduced in the calculation:\n\n        \\begin{equation}\n            S_{\\pi} = \\frac{N_{\\pi}}{N}\n        \\label{eq:fraction_neurons_pop} \\end{equation}\n\n        where:\n\n        \\begin{tabular}{l} \\\\\n            \\(N_{\\pi} \\in \\N\\) is the number of neurons in a population. \\\\\n        \\label{tab:fraction_neurons_pop} \\end{tabular} \\bigskip\n\n\n    The change of current of population \\(\\pi_{i}\\) with time is:\n\n        \\begin{equation}\n            \\tau \\dot{c}_{i}(t) = - {c}_{i}(t) + \\sum_{j=1}^{U} r_{j}(t) \\cdot W_{i,j} \\cdot S_{\\pi} + \\xi_{i}(t)\n        \\label{eq:population_current} \\end{equation}\n\n        where:\n\n        \\begin{tabular}{l} \\\\\n            \\(U \\in \\N\\) is the number of unique populations. \\\\\n        \\label{tab:conditions_population_current} \\end{tabular} \\bigskip\n\n\n    \\medskip After discretizing by Euler:\n\n        \\begin{equation}\n            c_{i}(t+1) = -c_{i}(t) + \\frac{dt}{\\tau} \\left[- c_{i}(t) + \\sum_{j=1}^{U} r_{j}(t) \\cdot W_{i,j} \\cdot S_{\\pi} + \\frac{\\xi_{i}(t)}{\\sqrt{dt}} \\right]\n        \\label{eq:discrete_population_currents} \\end{equation}\n\n    % where:\n    % \n    % \\begin{tabular}{l} \\\\\n    %     \\(\\xi \\in \\R\\) is the Gaussian noise adapted to populations.\n    % \\label{tab:conditions_discrete_population_currents} \\end{tabular}\n\n\n\\subsubsection{Firing Rates}\n\n\n    % An extra parameter \\(\\zeta\\) was introduced in the gain function to achieve replication:\n    Firing rates are calculated with the gain function as before. % with the following gain function:\n\n        % \\begin{equation}\n        %     g(c) =\n        %     \\begin{cases}\n        %         (c + \\theta)^{\\gamma}   & \\text{if~} (c + \\theta) > 0 \\\\\n        %         0                       & \\text{if~} (c + \\theta) \\leq 0\n        %     \\end{cases}\n        %     %\\begin{cases}  hopefully no replication param\n        %     %    (c \\cdot \\zeta + \\theta)^{\\gamma}   & \\text{if~} (c + \\theta) > 0 \\\\\n        %     %    0                       & \\text{if~} (c + \\theta) \\leq 0\n        %     %\\end{cases}\n        % \\label{eq:population_firing_rates} \\end{equation}\n        % \n        % where:\n        % \n        % \\begin{tabular}{l} \\\\\n        %     %\\(\\zeta \\in \\R\\) is the current modulation parameter, \\\\  replication param\n        %     \\(\\theta \\in \\R\\) is the gain function threshold, \\\\\n        %     \\(\\gamma \\in \\R_{<1}\\) is the gain function exponent. \\\\\n        % \\label{tab:conditions_population_firing_rates} \\end{tabular} \\bigskip\n\n\n\\subsubsection{Memory Patterns}\n\nThe \\(M \\times N\\) matrix containing \\(s\\) states is now a \\(M \\times U\\) matrix.\nThis second matrix contains fewer elements than the original matrix, allowing for faster computation.\n\n\n\\subsubsection{Inhibition}\n\nInhibition calculation remains unchanged for the simulation with populations.\n\n\n\\subsubsection{Weights}\n\n\n    The population weight matrix \\(\\boldsymbol{W}_{i, j}\\) for neuron populations, with \\(U \\times U\\) shape:\n\n        \\begin{equation}\n            W_{i,j} = \\frac{\\kappa}{N} \\left[\\sum_{p=1}^{M} (u_{i}^{p} - f) (u_{j}^{p} - f) - \\phi(t) \\right]\n        \\label{eq:population_weights} \\end{equation}\n\n        \\begin{equation}\n            W_{i, j}^{SAM} = W_{i, j} + W_{i, j}^{*} = W_{i,j} + \\frac{\\kappa}{N} \\left[ \\kappa_{f} \\sum_{p=1}^{M-1} u_{i}^{p} \\cdot u_{j}^{p + 1} + \\kappa_{b} \\sum_{p=2}^{M} u_{i}^{p} \\cdot u_{j}^{p - 1} \\right]\n        \\label{eq:population_weights_sam} \\end{equation}\n\n        where:\n\n        \\begin{tabular}{l} \\\\\n            \\(u \\in \\Z_{[0, 1]}\\) is the activity state of a population. \\\\\n        \\label{tab:conditions_population_weights} \\end{tabular} \\bigskip\n\n\\subsubsection{Noise}\n\n    Unmodulated Gaussian noise \\(\\xi\\) is computed as before.\n    % Unmodulated Gaussian noise \\(\\xi^{*}\\) is computed with different variance \\(\\sigma_{\\pi}^{2}\\):\n% \n    %     \\begin{equation}\n    %         \\sigma_{\\pi}^{2} = \\frac{\\sigma^{2}}{\\sqrt{N_{\\pi}}}\n    %     \\label{eq:population_noise_sd} \\end{equation}\n% \n    %     where:\n% \n    %     \\begin{tabular}{l} \\\\\n    %         \\(\\mu \\in \\R\\) is the noise mean, \\\\\n    %         \\(\\sigma \\in \\R_{\\geqslant 0}\\) is the noise standard deviation.\n    %     \\label{tab:conditions_noise_sd} \\end{tabular} \\bigskip\n% \n    % Probability density function remains the same as in equation \\ref{eq:noise}, with \\(\\sigma = \\sigma_{\\pi}\\).\n\n\n%         Unmodulated noise values are then scaled using according to \\(N_{\\pi}\\), and an extra parameter \\(\\eta\\) to achieve replication:\n%\n%         \\begin{equation}\n%             \\xi = \\frac{\\xi^{*} \\cdot \\eta}{N_{\\pi}}\n%         \\label{eq:population_noise} \\end{equation}\n%\n%         where:\n%\n%         \\begin{tabular}{l} \\\\\n%             \\(\\xi^{*} \\in \\R\\) is the unmodulated noise, \\\\\n%             \\(\\eta \\in \\R\\) is the noise modulation parameter.\n%         \\label{tab:conditions_population_noise} \\end{tabular} \\bigskip\n\n\n\\subsection{Simulation}\n\nSimulation is carried away with population-level conditions (subsection \\ref{subsec:population_dynamics}).\nCalculations are then based on a \\(M \\times U\\) matrix instead of a much larger \\(M \\times N\\) matrix.\nComputation time now scales with \\(M\\) instead of \\(N\\) but for very large values of \\(N\\), which would also increase the number of populations.\nRecanatesi \\textit{et al.} \\parencite{recanatesi2015} estimated this method to be 99.9\\% faster than simulating individual neurons.\n\nFiring rates are initialized at \\(r_{ini}\\) for populations encoding a randomly chosen memory pattern.\nCurrents are set at \\(r_{ini}^{\\rfrac{1}{\\gamma}}\\).\nAll weights are also defined at this stage.\nValues of noise and inhibition change per time step.\nNeuron currents and firing rates are then calculated at each time step as well.\n\nA memory is considered recalled if the average firing rate of all encoding neurons is above \\(r_{recall}\\).\nThe network is said to recall a certain memory \\(p\\) if the former condition is ever fulfilled for that memory during the simulation time.\n\nTable \\ref{table:hyperparameters} summarizes all hyperparameters used in the simulation.\n\n\\subsection{Recall Analysis}\n\nThe network was simulated first at a smaller scale and for one trial to observe detailed dynamics.\nIt was then scaled to computer clusters, allowing to reach a total of 10,000 simulations for each condition needed for memory recall analysis.\nEach network is simulated for a total of 450 time cycles.\n\nSeveral metrics are computed to assess the recall performance of the model.\nIn particular, inter-retrieval time (IRT) is calculated as the number of time cycles until the recall of a new memory item.\nOther performance metrics such as memory size intersections or the average total recalls are also analyzed.\n\n\\subsection{Computational Tools}\n\nReplication was carried out using Python 3.8.5 with packages NumPy 1.19.1, pandas 1.0.5, matplotlib 3.3.0, SciPy 1.5.2, and tqdm 4.48.0 on Parabola GNU/Linux-libre and CentOS GNU/Linux.", "meta": {"hexsha": "fb7bba6742d789aacc4dd842768a45f7fda8fc35", "size": 14005, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "files/3-methods.tex", "max_stars_repo_name": "rougier/replication-recanatesi-2015-article", "max_stars_repo_head_hexsha": "9200fa3204c69fbc20904c105996413ebe27c3b3", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "files/3-methods.tex", "max_issues_repo_name": "rougier/replication-recanatesi-2015-article", "max_issues_repo_head_hexsha": "9200fa3204c69fbc20904c105996413ebe27c3b3", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "files/3-methods.tex", "max_forks_repo_name": "rougier/replication-recanatesi-2015-article", "max_forks_repo_head_hexsha": "9200fa3204c69fbc20904c105996413ebe27c3b3", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.3126843658, "max_line_length": 273, "alphanum_fraction": 0.594930382, "num_tokens": 4290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.73173006589569}}
{"text": "\\lab{A Pseudospectral method for periodic functions}{A Pseudospectral method for periodic functions}\n\\label{lab:pseudospectral2}\n\n\\objective{\nWe look at a pseudospectral method with a Fourier basis, and numerically solve the advection equation using a pseudospectral discretization in space and a Runge-Kutta integration scheme in time.  }\n\nLet $f$ be a periodic function on $[0,2\\pi]$.\nLet $x_1,\\ldots,x_N$ be $N$ evenly spaced grid points on $[0,2\\pi].\n$Since $f$ is periodic on $[0,2\\pi]$, we can ignore the grid point $x_N = 2\\pi$.\nWe will further assume that $N$ is even; similar formulas can be derived for $N$ odd.\nLet $h = 2\\pi/N$; then $\\{x_0,\\ldots,x_{N-1}\\} = \\{0,h,2h,\\ldots,2\\pi-h\\}$.  \n\nThe discrete Fourier transform (DFT) of $f$, denoted by $\\hat{f}$ or $\\mathcal{F}(f)$, is given by\n\\[\n\\hat{f}(k) = h \\sum_{j=0}^{N-1} e^{-ikx_j}f(x_j) \\quad \\text{ where } k = -N/2+1, \\ldots,0,1,\\ldots, N/2.\n\\]\nThe inverse DFT is then given by\n\\begin{align}\n\\begin{split}\nf(x_j) &= \\frac{1}{2\\pi}\\sum_{k=-N/2}^{N/2}\\frac{e^{ikx_j}}{c_k}\\hat{f}(k), \\quad j = 0,\\ldots, N-1,\n\\end{split}\\label{inverse_dft}\n\\end{align}\nwhere\n\\begin{align}\n\tc_k = \\begin{cases} 2 & \\text{if }k = -N/2 \\text{ or }k = N/2, \\\\ 1 &  \\text{otherwise.}\n\\end{cases}\n\\end{align}\nThe inverse DFT can then be used to define a natural interpolant (sometimes called a band-limited interpolant) by evaluating (\\ref{inverse_dft}) at any $x$ rather than $x_j$:\n\\begin{align}\np(x) = \\frac{1}{2\\pi}\\sum_{k=-N/2}^{N/2} e^{ikx}\\hat{f}(k). \\label{interpolant}\n\\end{align}\nThe interpolant for $f'$ is then given by \n\\begin{align}\np'(x) = \\frac{1}{2\\pi}\\sum_{k=-N/2+1}^{N/2-1} ike^{ikx}\\hat{f}(k). \\label{spectral2:deriv}\n\\end{align}\n\nConsider the function $u(x) = \\sin^2 (x) \\cos(x) +e^{2\\sin(x+1)}$. \nUsing \\eqref{spectral2:deriv}, the derivative $u'$ may be approximated with the following code. \n\\footnote{See \\textit{Spectral Methods in MATLAB} by Lloyd N. Trefethen.\nAnother good reference is \\textit{Chebyshev and Fourier Spectral Methods} by John P. Boyd.}\nWe note that although we only approximate $u'$ at the Fourier grid points, \\eqref{spectral2:deriv} provides an analytic approximation of $u'$ in the form of a trigonometric polynomial.\n\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy.fftpack import fft, ifft\nimport matplotlib.pyplot as plt\n\nN=24\nx1 = (2.*np.pi/N)*np.arange(1,N+1)\nf = np.sin(x1)**2.*np.cos(x1) + np.exp(2.*np.sin(x1+1))\n\n# This array is reordered in Python to\n# accomodate the ordering inside the fft function in scipy.\nk = np.concatenate(( np.arange(0,N/2) ,\n\t\t\t\t\t np.array([0])\t, # Because hat{f}'(k) at k = N/2 is zero.\n\t\t\t\t\t np.arange(-N/2+1,0,1)\t))\n\n# Approximates the derivative using the pseudospectral method\nf_hat = fft(f)\nfp_hat = ((1j*k)*f_hat)\nfp = np.real(ifft(fp_hat))\n\n# Calculates the derivative analytically\nx2 = np.linspace(0,2*np.pi,200)\nderivative = (2.*np.sin(x2)*np.cos(x2)**2. - \n\t\t\t\tnp.sin(x2)**3. + \n\t\t\t\t2*np.cos(x2+1)*np.exp(2*np.sin(x2+1))\n\t\t\t\t)\n\nplt.plot(x2,derivative,'-k',linewidth=2.)\nplt.plot(x1,fp,'*b')\nplt.savefig('spectral2_derivative.pdf')\nplt.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{spectral2_derivative.pdf}\n\\caption{The derivative of $u(x) = \\sin^2 (x) \\cos(x) +e^{2\\sin(x+1)}$.}\n\\label{fig:spectral:spectral2_derivative}\n\\end{figure}\n\n\\begin{problem}\nConsider again the function $u(x) = \\sin^2 (x) \\cos(x) +e^{2\\sin(x+1)}$.\nCreate a function that approximates $\\frac{1}{2}u''-u'$ on the Fourier grid points for $N=24$.\t\n\\end{problem}\n\n\\section*{The advection equation}\nRecall that the advection equation is given by\n\\begin{align}\n&{ }u_t + cu_x = 0\n\\end{align}\nwhere $c$ is the speed of the wave (the wave travels to the right for $c > 0$).\nWe will consider the solution of the advection equation on the circle; this essentially amounts to solving the advection equation on $[0,2\\pi]$ and assuming periodic boundary conditions. \n\nA common method for solving time-dependent PDEs is called the \\textit{method of lines}.\nTo apply the method of lines to our problem, we use our Fourier grid points in $[0,\\pi]$: given an even $N$, let $h = 2\\pi/N$, so that $\\{x_0,\\ldots,x_{N-1}\\} = \\{0,h,2h,\\ldots,2\\pi-h\\}$.\nBy using these grid points we obtain the collection of equations\n\\begin{align}\n&{ }u_t(x_j,t) + cu_x(x_j,t) = 0, \\quad t >0, \\quad j = 0, \\ldots N-1. \\label{spectral2:method_oflines}\n\\end{align}\n\nLet $U(t)$ be the vector valued function given by $U(t) = (u(x_j,t))_{j=0}^{N-1}$.\nLet $\\mathcal{F}(U)(t)$ denote the discrete Fourier transform of $u(x,t)$ (in space), so that \n\\[\n\\mathcal{F}(U)(t) = (\\hat{u}(k,t))_{k=-N/2+1}^{N/2}.\n\\]\nDefine $\\mathcal{F}^{-1}$ similarly.\nUsing the pseudospectral approximation in space leads to the system of ODEs\n\\begin{align}\n\tU_t +  \\vec{c}\\mathcal{F}^{-1}\\left(i\\vec{k}\\mathcal{F}(U) \\right) = 0\n\\end{align}\nwhere $\\vec{k}$ is a vector, and $\\vec{k}\\mathcal{F}(U) $ denotes element-wise multiplication. \nSimilarly $\\vec{c}$ could also be a vector, if the wave speed $c$ is allowed to vary. \n\n\\begin{problem}\n\tUsing a fourth order Runge-Kutta method (RK4), solve the initial value problem \n\t\\begin{align}\n\t\tu_t +c(x) u_x = 0,\n\t\\end{align}\nwhere $c(x) = .2 + \\sin^2(x-1)$, and $u(x,t=0) = e^{-100(x-1)^2}.$ \nPlot your numerical solution from $t = 0$ to $t = 8$ over 150 time steps and 100 $x$ steps. \nNote that the initial data is nearly zero near $x = 0$ and $2 \\pi$, and so we can use the pseudospectral method.\n\\footnote{This problem is solved in \\textit{Spectral Methods in MATLAB} using a leapfrog discretization in time. } \n\\label{spectral2:advection_equation}\nUse the following code to help graph.\n\\begin{lstlisting}\nt_steps = 150    # Time steps\nx_steps = 100     # x steps\n\n'''\nYour code here to set things up\n'''\n\nsol = # RK4 method. Should return a t_steps by x_steps array\n\nX,Y = np.meshgrid(x_domain, t_domain)\nfig = plt.figure()\nax = fig.add_subplot(111, projection=\"3d\")\nax.plot_wireframe(X,Y,sol)\nax.set_zlim(0,3)\nplt.show()\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{advection.png}\n\\caption{The solution of the variable speed advection equation; see Problem \\ref{spectral2:advection_equation}.}\n\\label{fig:spectral:spectral2_advection}\n\\end{figure}", "meta": {"hexsha": "f816b7fc81e79a63f1f2fb861d469ad93551cfe4", "size": 6234, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume4/Spectral2/Spectral2.tex", "max_stars_repo_name": "DM561/dm561.github.io", "max_stars_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-13T13:22:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-13T13:22:41.000Z", "max_issues_repo_path": "acme-material/Labs/Volume4/Spectral2/Spectral2.tex", "max_issues_repo_name": "DM561/dm561.github.io", "max_issues_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-10-18T19:57:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-31T19:00:36.000Z", "max_forks_repo_path": "acme-material/Labs/Volume4/Spectral2/Spectral2.tex", "max_forks_repo_name": "DM561/dm561.github.io", "max_forks_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.2847682119, "max_line_length": 197, "alphanum_fraction": 0.6905678537, "num_tokens": 2152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160258, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7317056297471201}}
{"text": "\\section{Nodal Basis and Nodal Space}\n\\label{sec:21nodalSpaces}\n\n\\minitoc{62mm}{4}\n\n\\mbox{}\\vspace{-14mm}\n\n\n\n\\disableornamentsfornextheadingtrue\n\\subsection{Univariate Case}\n\\label{sec:211nodalUV}\n\n\\paragraph{Grid and basis functions}\n\nIn this thesis, we consider univariate functions\nthat are defined on the unit interval $\\clint{0, 1}$.\n\\usenotation{l}\nWe discretize this domain by splitting it into $2^l$ equally-sized segments,\nwhere $l \\in \\natz$ is the \\term{level.}\n\\usenotation{i}\nThe resulting $2^l + 1$ \\term{grid points} $\\gp{l,i}$ are given by\n\\begin{equation}\n  \\gp{l,i} \\ceq i \\cdot \\ms{l},\\quad\n  i = 0, \\dotsc, 2^l,\n\\end{equation}\nwhere $i$ is the \\term{index} and $\\ms{l} \\ceq 2^{-l}$ is the \\term{mesh size.}%\n\\footnote{%\n  Note that from a strict formal perspective,\n  this equation defined $\\gp{l,i}$ only for $i = 0, \\dotsc, 2^l$,\n  but we will later need $\\gp{l,i}$ also for $i < 0$ or $i > 2^l$.\n  The convention in this thesis is that all definitions are\n  implicitly generalized whenever needed.%\n}\nEvery grid point is associated with a \\term{basis function}\n\\begin{equation}\n  \\basis{l,i}\\colon \\clint{0, 1} \\to \\real.\n\\end{equation}\nWe assume $\\basis{l,i}$ to be arbitrary,\nsatisfying required assumptions when needed and stated.\nHowever, it helps for both the theory and the intuition to have a\nspecific example of basis functions in mind.\n\\usenotation{Ë1}\nThe so-called \\term{hat functions} (linear B-splines)\nare the most common choice for $\\basis{l,i}$:\n\\begin{equation}\n  \\label{eq:hatFunctionUV}\n  \\bspl{l,i}{1}(x)\n  \\ceq \\max(1 - \\abs{\\tfrac{x}{\\ms{l}} - i}, 0).\n\\end{equation}\nHere and in the following,\nthe superscript ``1'' stands for the degree of the linear B-spline and\nis not to be read as an exponent.\nWe generalize this notation to B-splines $\\bspl{l,i}{p}$ of\narbitrary degrees $p$ in \\cref{chap:30BSplines}.\n\n\\paragraph{Nodal space}\n\nThe \\term{nodal space} $\\ns{l}$ of level $l$\nis defined as the linear span of all basis functions\n$\\basis{l,i}$:\n\\begin{equation}\n  \\ns{l} \\ceq \\spn\\{\\basis{l,i} \\mid i = 0, \\dotsc, 2^l\\}.\n\\end{equation}\nWe assume that the functions $\\basis{l,i}$ form a basis of $\\ns{l}$, i.e.,\nthey are linearly independent.\nConsequently, every linear combination of these functions is unique.\nThis ensures that for every objective function $\\objfun\\colon \\clint{0, 1} \\to \\real$,\nthere is a unique function $\\fgintp{l}\\colon \\clint{0, 1} \\to \\real$ such that\n\\begin{equation}\n  \\label{eq:interpFullGridUV}\n  \\fgintp{l}\n  = \\sum_{i=0}^{2^l} \\interpcoeff{l,i} \\basis{l,i},\\quad\n  \\falarge{i = 0, \\dotsc, 2^l}{\\fgintp{l}(\\gp{l,i}) = \\objfun(\\gp{l,i})},\n\\end{equation}\nfor some $\\interpcoeff{l,i} \\in \\real$.\nIn this case, $\\fgintp{l}$ is called \\term{interpolant} of $\\objfun$ in $\\ns{l}$.\nThe nodal space $\\nsbspl{l}{1}$ is defined analogously to $\\ns{l}$\nas the span of the hat functions $\\bspl{l,i}{1}$.\nIt is the space of all linear splines,\nthat is, the space of all continuous functions on $\\clint{0, 1}$ that are\npiecewise linear polynomials on $\\clint{\\gp{l,i}, \\gp{l,i+1}}$ for\n$i = 0, \\dotsc, 2^l - 1$ \\cite{Hoellig13Approximation}.\nThe nodal hat function basis of level~$l = 3$\nand a linear combination are shown in \\cref{fig:nodalHat}.\n\n\\begin{figure}\n  \\subcaptionbox{%\n    Basis functions $\\bspl{l,i}{1}$ ($i = 0, \\dotsc, 2^l$)\n    and grid points $\\gp{l,i}$ \\emph{(dots).}%\n  }[72mm]{%\n    \\includegraphics{hierarchicalBasis_1}%\n  }%\n  \\hfill%\n  \\subcaptionbox{%\n    Piecewise linear interpolant $\\fgintp{l}$\n    of some function data $\\objfun(\\gp{l,i})$\n    as a weighted sum of the nodal hat functions.%\n  }[72mm]{%\n    \\includegraphics{interpolant_1}%\n  }%\n  \\caption[%\n    Univariate nodal hat functions%\n  ]{%\n    Univariate nodal hat functions of level $l = 3$.%\n  }%\n  \\label{fig:nodalHat}%\n\\end{figure}\n\n\n\n\\subsection{Multivariate Case}\n\\label{sec:212nodalMV}\n\n\\paragraph{Cartesian and tensor products}\n\n\\usenotation{d}\nFor the multivariate case with $d \\in \\nat$ dimensions,\nwe employ a tensor product approach,\nfor which we replace all indices, points, and functions with\nmulti-indices, Cartesian products, and tensor products, respectively.\n\\usenotation{@0}\n\\usenotation{@1}\nTherefore, the domain is now $\\clint{\\*0, \\*1} \\ceq \\clint{0, 1}^d$,\nwhich can be partitioned into\n$\\prod_{t=1}^d 2^{l_t} = 2^{\\normone{\\vec{l}}}$ equally-sized hyper-rectangles,\nwhere $\\*l = (l_1, \\dotsc, l_d) \\in \\natz^d$ is the $d$-dimensional level\nand $\\normone{\\vec{l}} \\ceq \\sum_{t=1}^d \\abs{l_t}$ is the level sum.\nThe corners of the hyper-rectangles are given by the grid points\n\\begin{equation}\n  \\label{eq:gridPointMultivariate}\n  \\gp{\\*l,\\*i} \\ceq \\*i \\cdot \\ms{\\*l},\\quad\n  \\*i = \\*0, \\dotsc, \\*2^{\\*l}.\n\\end{equation}\nRelations and operations with vectors in bold face\nare to be read coordinate-wise in this thesis, unless stated otherwise.\nBold-faced numbers like $\\*0$ are defined to be the vector $(0, \\dotsc, 0)$\nin which every entry is equal to that number.\nThis is to allow a somewhat intuitive and suggestive notation.\nFor example, \\eqref{eq:gridPointMultivariate} is equivalent to\nthe much longer formula\n\\begin{equation}\n  \\gp{\\*l,\\*i}\n  \\ceq (i_1 \\ms{l_1},\\; \\dotsc,\\; i_d \\ms{l_d}),\\quad\n  i_t = 0, \\dotsc, 2^{l_t},\\quad\n  t = 1, \\dotsc, d,\n\\end{equation}\nwith the $d$-dimensional mesh size\n$\\ms{\\*l} \\ceq \\*2^{-\\*l} = (\\ms{l_1}, \\dotsc, \\ms{l_d})$.\nAgain, every grid point is associated with a basis function that is defined\nas the tensor product of the univariate functions:%\n\\footnote{%\n  Note that,\n  although \\cref{eq:tensorProduct} does not cover it,\n  one could employ basis functions of different types in\n  each dimension, for example B-splines of different degrees.\n  All remaining considerations in this thesis\n  regarding tensor product basis functions are independent\n  of whether we use the same function type or\n  different types in each dimension.%\n}\n\\begin{equation}\n  \\label{eq:tensorProduct}\n  \\basis{\\*l,\\*i}\\colon \\clint{\\*0, \\*1} \\to \\real,\\quad\n  \\basis{\\*l,\\*i}(\\*x)\n  \\ceq \\prod_{t=1}^d \\basis{l_t,i_t}(x_t).\n\\end{equation}\n\\cref{fig:nodalHat2D} shows an example of a bivariate nodal hat function\n$\\bspl{\\*l,\\*i}{1}$.\n\n\\begin{SCfigure}\n  \\includegraphics{nodalHat2D_1}%\n  \\caption[%\n    Bivariate nodal hat function%\n  ]{%\n    Bivariate nodal hat function of level $\\*l = (2, 1)$ and\n    index $i = (1, 1)$ as the tensor product of two univariate\n    nodal hat functions.%\n  }%\n  \\label{fig:nodalHat2D}%\n\\end{SCfigure}\n\n\\vspace*{\\fill}\n\\pagebreak\n\n\\paragraph{Multivariate nodal space}\n\nThe multivariate nodal space $\\ns{\\*l}$ is defined analogously to\nthe univariate case:\n\\begin{equation}\n  \\ns{\\*l}\n  \\ceq \\spn\\{\\basis{\\*l,\\*i} \\mid \\*i = \\*0, \\dotsc, \\*2^{\\*l}\\}.\n\\end{equation}\nIn the case of hat functions $\\bspl{\\*l,\\*i}{1}$,\nthe nodal space $\\nsbspl{\\*l}{1}$ is the $d$-linear spline space\n\\cite{Hoellig13Approximation}, i.e.,\nthe space of all continuous functions\non $\\clint{\\*0, \\*1}$ that are piecewise $d$-linear polynomials on\nall hyper-rectangles\n\\begin{equation}\n  \\clint{\\gp{\\*l,\\*i}, \\gp{\\*l,\\*i+\\*1}}\n  \\ceq \\clint{\\gp{l_1,i_1}, \\gp{l_1,i_1+1}} \\times \\dotsb \\times\n  \\clint{\\gp{l_d,i_d}, \\gp{l_d,i_d+1}},\\quad\n  \\*i = \\*0, \\dotsc, \\*2^\\*l - \\*1.\n\\end{equation}\nAnalogously to \\eqref{eq:interpFullGridUV},\nwe can interpolate objective functions $\\objfun\\colon \\clint{\\*0, \\*1} \\to \\real$\nin the nodal space $\\ns{\\*l}$ with $\\fgintp{\\*l}\\colon \\clint{\\*0, \\*1} \\to \\real$ satisfying\n\\begin{equation}\n  \\label{eq:interpFullGridMV}\n  \\fgintp{\\*l}\n  = \\sum_{\\*i=\\*0}^{\\*2^\\*l} \\interpcoeff{\\*l,\\*i} \\basis{\\*l,\\*i},\\quad\n  \\falarge{\\*i = \\*0, \\dotsc, \\*2^\\*l}{\\fgintp{\\*l}(\\gp{\\*l,\\*i}) = \\objfun(\\gp{\\*l,\\*i})},\n\\end{equation}\nwhere $\\interpcoeff{\\*l,\\*i} \\in \\real$ and\nthe sum is over all $\\*i = \\*0, \\dotsc, \\*2^\\*l$\n(i.e., $i_t = 0, \\dotsc, 2^{l_t}$, $t = 1, \\dotsc, d$).\nTo ensure that the coefficients $\\interpcoeff{\\*l,\\*i}$\nexist for every objective function $\\objfun$ and are uniquely determined by\nthe values at the grid points\n\\begin{equation}\n\\fgset{\\*l}\n\\ceq \\{\\gp{\\*l,\\*i} \\mid \\*i = \\*0, \\dotsc, \\*2^{\\*l}\\},\n\\end{equation}\nwe prove the following statement:\n\n\\vspace*{\\fill}\n\\pagebreak\n\n\\begin{lemma}[linear independence of tensor products]\n  \\label{lemma:tensorProductLinearIndependence}\n  The functions $\\basis{\\*l,\\*i}$ ($\\*i = \\*0, \\dotsc, \\*2^\\*l$)\n  form a basis of $\\ns{\\*l}$, if the univariate functions\n  $\\basis{l_t,i_t}$ ($i_t = 0, \\dotsc, 2^{l_t}$)\n  form a basis of the univariate nodal space $\\ns{l_t}$\n  for $t = 1, \\dotsc, d$.\n\\end{lemma}\n\\begin{proof}\n  Assume that $\\interpcoeff{\\*l,\\*i} \\in \\real$ are chosen in \\eqref{eq:interpFullGridMV}\n  such that $\\fgintp{\\*l} \\equiv 0$.\n  Then for all $\\*i' = \\*0, \\dotsc, \\*2^\\*l$,\n  we can evaluate \\eqref{eq:interpFullGridMV} at $\\gp{\\*l,\\*i'}$ to obtain\n  \\begin{equation}\n    \\sum_{i_1=0}^{2^{l_1}}\n    \\paren*{\n      \\sum_{i_2=0}^{2^{l_2}} \\dotsb \\paren*{\n        \\sum_{i_d=0}^{2^{l_d}}\n        \\interpcoeff{\\*l,\\*i} \\basis{l_d,i_d}(\\gp{l_d,i_d'})\n      } \\dotsb \\basis{l_2,i_2}(\\gp{l_2,i_2'})\n    } \\basis{l_1,i_1}(\\gp{l_1,i_1'})\n    = 0.\n  \\end{equation}\n  We apply the univariate linear independence ($x_1$ direction) to infer\n  that the sum over $i_2$ must vanish for all $i_1 = 0, \\dotsc, 2^{l_1}$.\n  Repeating this argument for all dimensions, we have\n  $\\interpcoeff{\\*l,\\*i} = 0$ for all~$\\*i = \\*0, \\dotsc, \\*2^\\*l$,\n  implying the linear independence of the functions $\\basis{\\*l,\\*i}$.\n\\end{proof}\n\n\\usenotation{n10}\nA common choice for the level $\\*l$ is $n \\cdot \\*1$ for some $n \\in \\natz$.\n\\usenotation{Vnd}\nIn this case, we replace ``$\\*l$'' in the subscripts with ``$n{,}d$''\n(for example, $\\ns{n,d} \\ceq \\ns{n \\cdot \\*1}$).\nFor the hat function basis $\\bspl{\\*l,\\*i}{1}$,\nit can be shown that the $\\Ltwo$ interpolation error of the interpolant\n$\\fgintp{n,d} \\in \\ns{n,d}$ is given by\n\\begin{equation}\n  \\normLtwo{\\objfun - \\fgintp{n,d}} = \\landauO{\\ms{n}^2},\n\\end{equation}\ni.e., the order of the interpolation error is quadratic in the mesh size\n\\multicite{Hoellig13Approximation,Bungartz04Sparse}.\n", "meta": {"hexsha": "9cadfb7d215215df80060a77e218b29f29e79e77", "size": 10025, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/document/21nodalSpaces.tex", "max_stars_repo_name": "valentjn/thesis", "max_stars_repo_head_hexsha": "65a0eb7d5f7488aac93882959e81ac6b115a9ea8", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2022-01-15T19:50:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-15T20:16:10.000Z", "max_issues_repo_path": "tex/document/21nodalSpaces.tex", "max_issues_repo_name": "valentjn/thesis", "max_issues_repo_head_hexsha": "65a0eb7d5f7488aac93882959e81ac6b115a9ea8", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/document/21nodalSpaces.tex", "max_forks_repo_name": "valentjn/thesis", "max_forks_repo_head_hexsha": "65a0eb7d5f7488aac93882959e81ac6b115a9ea8", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.7216117216, "max_line_length": 93, "alphanum_fraction": 0.6682294264, "num_tokens": 3609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.835483553488848, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.7317056278813344}}
{"text": "%% Draft of probabilistic interpretation of quantization\n\\section{Probabilistic Interpretation of Quantization}\n\\begin{frame}{Probability distribution of the output of a quantizer}\n\\textbf{Question:} what's the probability density function (PDF) $p_{x_Q}(x)$ of the quantizer output $x_Q[n] \\sim p_{x_Q}(x)$ when the input signal $x[n]$ has PDF $x[n] \\sim p_{x}(x)$?\n\\begin{center}\n\t\\resizebox{0.75\\textwidth}{!}{\\input{figs/quantizer_output_pdf.tex}}\n\\end{center}\n\n\\onslide<4|handout:1>{\nThe PDF of $x_Q[n] \\sim p_{x_Q}(x)$ is formed by impulses at the quantization levels. The area of any given impulse is equal to the area under $p_x(x)$ in the quantization interval corresponding to that impulse. In the example of the figure, the area of the impulse at the origin is equal to the highlighted area under $p_x(x)$.\n}\n\\end{frame}\n\n%\n\\begin{frame}{Area sampling}\nWe can view $p_{x_Q}(x)$ as samples of the area of $p_x(x)$ under quantization intervals. This form of sampling is called \\textbf{area sampling}.\n\n\\begin{equation*}\np_{x_Q}(x) = \\underbrace{(p_x(x) \\ast r(x))}_{\\text{\\normalsize area calculation}}\\overbrace{\\cdot s(x)}^{\\text{\\normalsize sampling}},\n\\end{equation*}\nwhere \n\\begin{equation*}\nr(x) = \\begin{cases}\n\\frac{1}{\\Delta}, & -\\frac{\\Delta}{2} \\leq x \\leq \\frac{\\Delta}{2} \\\\\n0, & \\text{otherwise}\n\\end{cases} \\tag{rectangular window of area 1}\n\\end{equation*}\n\n\\begin{equation*}\ns(x) = \\sum_{n = -\\infty}^{\\infty} \\delta(x - n\\Delta) \\tag{impulse train}\n\\end{equation*}\nThe period of the impulse train (\\textit{sampling period}) is $\\Delta$\n\n\\textbf{Interesting:} although quantization is an nonlinear operation on the signal, it is a linear operation on that signal PDF, since area sampling is linear.\n\\end{frame}\n\n%\n\\begin{frame}{Area sampling: graphically}\n\\begin{center}\n\t\\resizebox{0.9\\textwidth}{!}{\\input{figs/area_sampling_graphically.tex}}\n\\end{center}\t\n\\end{frame}\n\n%\n\\begin{frame}{Random variables and convolution}\nThe area sampling interpretation of quantization gives us a simple equation for the PDF of $x_Q[n]$:\n\\begin{equation*}\np_{x_Q}(x) = \\underbrace{(p_x(x) \\ast r(x))}_{\\text{\\normalsize area calculation}}\\overbrace{\\cdot s(x)}^{\\text{\\normalsize sampling}},\n\\end{equation*}\n\n\\pause\n\\textbf{Another interpretation:} in probability theory, we use convolution to calculate the PDF of the \\textbf{sum of two independent random variables}:\n\n\\begin{equation*}\nZ = X + Y \\Longrightarrow p_Z = p_X \\ast p_Y\n\\end{equation*}\n\n\\pause\nApplying to our problem:\n\n\\begin{equation*}\n\\tilde{x}_Q[n] = x[n] + q[n] \\Longrightarrow p_{\\tilde{x}_Q}(x) = \\underbrace{(p_x(x) \\ast r(x))}_{\\text{\\normalsize area calculation}}\n\\end{equation*}\nwhere $q[n]$ is a random variable independent of $x[n]$ and with PDF $p_q(x) = r(x)$. Therefore, $q$ is an \\textbf{uniform random variable} ($q\\sim\\mathcal{U}[-\\Delta/2, \\Delta/2]$).\n\\end{frame}\n\n%\n\\begin{frame}\nComparing with the definition of quantization error:\n\\begin{align*}\nx_Q[n] &= x[n] - e[n] \\tag{from definition of quantization error} \\\\\n\\tilde{x}_Q[n] &= x[n] + q[n] \\tag{from probabilistic interpreation of area sampling}\n\\end{align*}\n\nThe equations for $x_Q[n]$ and $\\tilde{x}_Q[n]$ are very similar, but there's an important difference. The PDF $p_{x_Q}(x)$ is formed by \\textbf{sampling} $p_{\\tilde{x}_Q}(x)$.\n\n\\pause\n\\begin{center}\n\t\\resizebox{0.55\\textwidth}{!}{\\input{figs/sampled_gaussian_pdf.tex}}\n\\end{center}\n\n\\pause\nIf the sampled PDF ($p_{x_Q}(x)$) perfectly describes $p_{\\tilde{x}_Q}(x)$, we can say that quantization error is perfectly described by an uniform random process.\n\n\\pause \n\\textbf{Question:}  under what conditions can we perfectly reconstruct $p_{\\tilde{x}_Q}(x)$ from its samples? \\\\\n\\end{frame}\n\n%\n\\begin{frame}{Revisiting the Shannon-Nyquist theorem}\n\tRecall that the \\textbf{Shannon-Nyquist theorem} guarantees that we can perfectly recover a signal from its samples if two conditions are met:\n\t\\begin{enumerate}\n\t\t\\item \\textbf{No aliasing; spectrum replicas do not overlap}\n\t\t\\item Use ideal reconstruction filter (ideal lowpass filter)\n\t\\end{enumerate}\n\t\\pause\n\t\\begin{block}{Conditions for no aliasing}\n\t\t\\begin{enumerate}\n\t\t\t\\item The \\textbf{characteristic function} (Fourier transform) of the area-sampled input PDF must satisfy: \n\t\t\t\\begin{equation*}\n\t\t\t\t\\Phi_{p_{x_Q}}(j\\theta) = \\mathcal{F}\\{p_{x_Q}(x)\\} = 0, |\\theta| > \\theta_N\n\t\t\t\\end{equation*}\n\t\t\tThis is analogous to the condition of a signal being \\textit{band-limited}.\n\t\t\t\\item\\pause The \\textit{sampling frequency} $\\theta_s$ must be such that $\\theta_s > 2\\theta_N$.\n\t\t\t\n\t\t\tIn this context, $\\theta_s = 2\\pi/\\Delta$, and the quantization interval $\\Delta$ is equivalent to the \\textit{sampling period} (period of the impulse train).\n\t\t\\end{enumerate}\n\t\\end{block}\n\\end{frame}\n\n%\n\\begin{frame}<beamer:0|handout:1>\nAdditional comments\n\\begin{itemize}\n\t\\item When we used the Shannon-Nyquist theorem for sampling a continuous-time signal, we said that we can use an anti-aliasing filter to minimize aliasing, but we could not use the ideal lowpass filter, as it is unfeasible.\n\t\\item In this discussion on quantization, we just want theoretical assurance that we can reconstruct the PDF from its samples. Therefore, for this purpose, we can use the ideal lowpass filter.\n\t\\item On the other hand, we cannot guarantee that there won't be aliasing, as many probability distributions are not \\textit{band-limited}.\n\\end{itemize}\n\\end{frame}\n\n%\n\\begin{frame}\n\t\\textbf{Conclusion:} if the conditions for no aliasing are met, we can perfectly reconstruct the original PDF from its samples, and therefore, quantization noise can be \\underline{perfectly modeled} as an uniform random process.\n\t\n\t\\pause\n\t\\textbf{Bad news:} the conditions for no aliasing are generally not met in practice. \\textbf{Example:} Gaussian distribution. The characteristic function of the Gaussian distribution is a Gaussian function. The Gaussian function is not \\textit{band-limited}, as it is always non-zero.\n\t\n\t\\pause\n\t\\textbf{How can we mitigate aliasing?}\n\t\\begin{enumerate}\n\t\t\\item Anti-aliasing filter? This would be equivalent to modify the PDF of the input signal. But what would it do the signal?\n\t\t\\item Oversampling $\\implies$ shorter sampling period ($\\Delta$) $\\implies$ finer quantization\n\t\\end{enumerate}\n\\end{frame}\n\n% \n\\begin{frame}{Example for the Gaussian input distribution}\n\t\\begin{itemize}\n\t\t\\item A zero-mean Gaussian distributed signal with variance $\\sigma^2$ is quantized with quantization resolution \\tikz[baseline]{\\node[fill=black!10,anchor=base] {$\\Delta = 2.1\\sigma$};}\n\t\t\\item Overlap of spectrum replicas results in \\underline{significant aliasing}\n\t\t\\item The estimated quantization noise PDF differs from the uniform distribution\n\t\\end{itemize}\n\t\n\t\\begin{columns}[t]\n\t\t\\begin{column}{0.5\\textwidth}\n\t\t\tFourier transform of sampled PDF\n\t\t\t\t\\begin{center}\n\t\t\t\t\t\\resizebox{\\textwidth}{!}{\\PlotGaussianCF{figs/aliased_gaussian_cf.tex}{1}{2.9920}{$\\Delta = 2.1\\sigma$}}\n\t\t\t\t\\end{center}\n\t\t\\end{column}\n\t\t\t\\begin{column}{0.5\\textwidth}\n\t\t\tEstimated quantization noise PDF\n\t\t\t\\begin{center}\n\t\t\t\t\t\\resizebox{0.9\\textwidth}{!}{\\input{figs/gaussian_quantiz_delta=2sigma.tex}}\n\t\t\t\\end{center}\n\t\t\t\\end{column}\n\t\\end{columns}\n\\end{frame}\n\n%\n\\begin{frame}{Example for the Gaussian input distribution}\n\\begin{itemize}\n\t\\item A zero-mean Gaussian distributed signal with variance $\\sigma^2$ is quantized with quantization resolution \\tikz[baseline]{\\node[fill=black!10,anchor=base] {$\\Delta = \\sigma$};}\n\t\\item Spectrum replicas are sufficiently apart; \\underline{aliasing is negligible}\n\t\\item The estimated quantization noise PDF agrees well with the uniform distribution\n\\end{itemize}\n\n\\begin{columns}[t]\n\t\\begin{column}{0.5\\textwidth}\n\t\tFourier transform of sampled PDF\n\t\t\\begin{center}\n\t\t\t\\resizebox{\\textwidth}{!}{\\PlotGaussianCF{figs/aliased_gaussian_cf.tex}{1}{6.2832}{$\\Delta = \\sigma$}}\n\t\t\\end{center}\n\t\\end{column}\n\t\\begin{column}{0.5\\textwidth}\n\t\tEstimated quantization noise PDF\n\t\t\\begin{center}\n\t\t\t\\resizebox{0.9\\textwidth}{!}{\\input{figs/gaussian_quantiz_delta=sigma.tex}}\n\t\t\\end{center}\n\t\\end{column}\n\\end{columns}\n\\end{frame}\n\n%\n\\begin{frame}{Summary on the probabilistic interpretation of quantization}\n\t\\begin{itemize}\n\t\t\\item In the probability domain, quantization corresponds to area sampling of the input PDF (a linear operation).\t\t\n\t\t\\item If there's no aliasing (spectrum replicas of area-sampled input PDF do not overlap)\n\t\t\\begin{enumerate}\n\t\t\t\\item Characteristic function of the area-sampled input PDF is \\textit{band-limited} with maximum \\textit{frequency} $\\theta_N$\n\t\t\t\\item Sampling period $\\Delta$ satisfies $\\Delta < \\pi/\\theta_N$\n\t\t\\end{enumerate}\n\t\tthe quantization error is \\underline{perfectly modeled} by an uniform random process.\n\t\t\\item In general aliasing cannot be avoided, but oversampling (finer quantization) makes aliasing negligible and consequently we can still accurately model quantization error as an uniform random process.  \n\t\\end{itemize}\n\\end{frame}", "meta": {"hexsha": "7fd1b9d082394798cace2fe67814f8e79499e0fb", "size": 8975, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/quant_prob_interpretation.tex", "max_stars_repo_name": "jkperin/DSP", "max_stars_repo_head_hexsha": "0ec74b4597fb54800ebdab440cba4892d210343d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2019-05-11T21:48:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-07T08:56:28.000Z", "max_issues_repo_path": "lectures/quant_prob_interpretation.tex", "max_issues_repo_name": "jkperin/DSP", "max_issues_repo_head_hexsha": "0ec74b4597fb54800ebdab440cba4892d210343d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures/quant_prob_interpretation.tex", "max_forks_repo_name": "jkperin/DSP", "max_forks_repo_head_hexsha": "0ec74b4597fb54800ebdab440cba4892d210343d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-04-16T01:11:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-19T07:25:20.000Z", "avg_line_length": 45.7908163265, "max_line_length": 328, "alphanum_fraction": 0.7391643454, "num_tokens": 2655, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.8438951104066295, "lm_q1q2_score": 0.7316872440435794}}
{"text": "\\section{Marciani's Rule}\n\\label{sec:marciani-rule}\n\nIt is well known that Arden's Rule permits the resolution of left-linear and\nright-linear language equations \\cite{Pettorossi13}.\nIn particular, by Arden's Rule, given the language equation $r=ar+s$ in the\nunknown $r$, its least solution is $a^{*}s$. Likewise, given the language\nequation $r=ra+s$ in the unknown $r$, its least solution is $sa^{*}$.\n\nNow, we state and prove a theorem that permits the resolution of both-linear\nlanguage equations.\n\n\\begin{theorem}\n\t\\label{thm:marciani-rule}\n\n\tGiven the language equation $r=ar+rb+s$ in the unknown $r$, its least\n\tsolution is $a^{*}sb^{*}$.\n\n\t\\begin{proof}\n\t\tLet us divide the proof in the following three points.\n\n\t\t\\begin{enumerate}[label=\\alph*]\n\n\t\t\t\\item We will first show that the language equation $r=ar+rb+s$ is\n\t\t\tequivalent to the language equation $r=a^{*}(rb+s)$.\n\n\t\t\t\\item Then, we will show that $a^{*}sb^{*}$ is a solution for $r$ of\n\t\t\tthe language equation $r=a^{*}(rb+s)$.\n\n\t\t\t\\item Finally, we will show that $a^{*}sb^{*}$ is the minimal\n\t\t\tsolution for $r$ of the language equation $r=a^{*}(rb+s)$; that is,\n\t\t\tfor\tany other solution $z$ we have that\n\t\t\t$L(a^{*}sb^{*})\\subseteq L(z)$.\n\n\t\t\\end{enumerate}\n\n\t\t\\begin{description}\n\n\t\t\t\\item [Proof (a)] By the application of Arden's Rule on $r=ar+rb+s$, we obtain $r=a^{*}(rb+s)$.\n\t\t\tSo $ar+rb+s=a^{*}(rb+s)$\\cite{Pettorossi13}.\n\n\t\t\t\\item [Proof (b)] Notice that $a^{*}((a^{*}sb^{*})b+s)=a^{*}a^{*}sb^{*}b+a^{*}s=a^{*}sb^{*}b+a^{*}s$,\n\t\t\tso we have to show that\n\t\t\t(b.1) $a^{*}sb^{*}\\subseteq a^{*}sb^{*}b+a^{*}s$ and\n\t\t\t(b.2) $\\beta.2$ $a^{*}sb^{*}b+a^{*}s\\subseteq a^{*}sb^{*}$.\n\n\t\t\t\\begin{description}\n\n\t\t\t\t\\item [Proof (b.1)] The following inclusion holds\n\t\t\t\t$a^{*}sb^{*}=a^{*}s(b^{+}+\\varepsilon)\\subseteq  a^{*}s(b^{*}b+\\varepsilon)=a^{*}sb^{*}b+a^{*}s$.\n\n\t\t\t\t\\item [Proof (b.2)] The following inclusions hold\n\t\t\t\t$a^{*}sb^{*}b\\subseteq a^{*}sb^{*}$ and $a^{*}s\\subseteq a^{*}sb^{*}$.\n\n\t\t\t\\end{description}\n\n\t\t\t\\item [Proof (c)] We assume that $z$ is a solution of $r=a^{*}(rb+s)$, that is $z=a^{*}(zb+s)$, and we show that $a^{*}sb^{*}\\subseteq z$,\n\t\t\tthat is $\\bigcup_{i,j\\geq0}a^{i}sb^{j}\\subseteq z$. The proof can be done by induction on $i,j\\geq0$.\n\t\t\t\n\t\t\t\\begin{description}\n\t\t\t\t\n\t\t\t\t\\item [(Basis:$i,j=0$)] $s\\subseteq z$ holds because\n\t\t\t\t$z=a^{*}(zb+s)$.\n\t\t\t\t\n\t\t\t\t\\item [(Step:$i\\geq0,j=0$)] We have to show the following implication\n\t\t\t\t$\\bigcup_{i\\geq0}a^{i}s\\subseteq z\\rightarrow\\bigcup_{i\\geq0}a^{i+1}s\\subseteq z$.\n\t\t\t\tThis holds because $\\bigcup_{i\\geq0}a^{i+1}s\\subseteq a\\bigcup_{i\\geq0}a^{i}s\\subseteq az\\subseteq z$.\n\t\t\t\t\n\t\t\t\t\\item [(Step:$i,j\\geq0$)] We have to show the following implication\n\t\t\t\t$\\bigcup_{i,j\\geq0}a^{i}sb^{j}\\subseteq z\\rightarrow\\bigcup_{i,j\\geq0}a^{i}sb^{j+1}\\subseteq z$.\n\t\t\t\tThis holds because $\\bigcup_{i,j\\geq0}a^{i}sb^{j+1}\\subseteq\\bigcup_{i,j\\geq0}a^{i}sb^{j}b\\subseteq zb\\subseteq z$.\n\t\t\t\t\n\t\t\t\\end{description}\n\n\t\t\\end{description}\t\t\n\t\\end{proof}\n\\end{theorem}\n", "meta": {"hexsha": "0800a668c9375541f7671d796f5b3bbb294b8d25", "size": 2990, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "marciani-normal-form/sec/marciani-rule.tex", "max_stars_repo_name": "gmarciani/research", "max_stars_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-07-27T13:31:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-20T12:54:12.000Z", "max_issues_repo_path": "marciani-normal-form/sec/marciani-rule.tex", "max_issues_repo_name": "gmarciani/research", "max_issues_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "marciani-normal-form/sec/marciani-rule.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 38.3333333333, "max_line_length": 141, "alphanum_fraction": 0.6200668896, "num_tokens": 1150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8670357718273068, "lm_q1q2_score": 0.7316872347766217}}
{"text": "\n\n\n\n%\\{Some Properties of Batch-Normalized Networks}\n\\section{Some other normalization methods in deep learning}\nIn this section, we will discuss some other normalization methods in deep neural networks.\nWe will try to propose a general framework for  these normalization methods which also include the batch normalization.\n\n\\subsection{A general framework for normalization in deep neural networks}\nFollowing the idea and notation in the previous section. We consider the data set as\n\\begin{equation}\\label{eq:trainingdata1}\n(X,Y) := \\{x^i, y^i\\}_{i=1}^N.\n\\end{equation}\nFor simplicity, here we just focus on the normalization operator during one hidden layer like:\n\\begin{equation}\n\\begin{cases}\nz &= Wx + b,\\\\\ny &= \\sigma(z) \n\\end{cases}\n\\end{equation}\nwhere \n\\begin{equation}\nx \\in \\mathbb{R}^d, \\quad W \\in \\mathbb{R}^{d\\times n}\n\\end{equation}\nBased on these setup, we give the next general framework for normalization in deep neural network as\n\\begin{equation}\\label{eq:norm-h}\n\\begin{cases}\nz &= Wx + b,\\\\\n\\tilde  z &= h(z),\\\\\ny &= \\sigma(\\tilde z).\n\\end{cases}\n\\end{equation}\nHere $h: \\mathbb{R}^{n} \\mapsto \\mathbb{R}^n$ has a general form as\n$$\nh(z) = \\gamma_N \\frac{z - \\mu_N}{\\sigma_N} + \\beta_N,\n$$\nwhere $\\gamma_N, \\mu_N, \\sigma_N, \\beta_N \\in \\mathbb{R}^n$, and all operation will be applied element-wise.\n\nFor the above formulation, we have the next relation immediately.\n\\begin{itemize}\n\t\\item If $h = {\\rm id}$, it recover the original DNN models.\n\t\\item If $h(z) = {\\rm BN}_{X}(z)$, then it recovers the BN method with the ``modified\" SGD training strategy.\n\\end{itemize}\n\n\n\\subsection{Some example of normalization in DNN}\nThen, we will show that, they are many existing normalization methods which can be formulated with \nspecial choice of $h(\\cdot)$.\n\n\\paragraph{Layer Normalization (LN)}\nThe idea behind layer normalization is quite similar to batch normalization.\nBatch normalization requires to do average or expectation with respect to the data direction.\nFor example, in batch normalization we have\n$$\n\\mu_{BN} = \\mu_X = \\sum_{i=1}^N z(x^i) = \\mathbb{E}_{s \\sim X}[ z(x)].\n$$\nWhat layer normalization does is to take mean, (average, expectation) in the neuron (feature, space) direction.\nThat is to say, we can take those parameters in $h(\\cdot)$ as:\n\\begin{equation}\\label{eq:LN-mu}\n\\mu_{LN} = \\frac{1}{n}\\sum_{k=1}^n z_k, \\quad \\sigma_{LN}=\\sqrt{\\frac{1}{n}\\sum_{k=1}^{n}(z_k-\\mu_{LN})}.\n\\end{equation}\nHere $\\mu_{LN}  ,  \\sigma_{LN} \\in \\mathbb{R}$, so we may put \n$$ \n\\mu_{LN} \\bm 1,  \\sigma_{LN} \\bm 1 \\in \\mathbb{R}^n,\n$$\nwith \n$$\n\\bm 1 = (1, \\cdots, 1) \\in \\mathbb{R}^n,\n$$\nfor rigorous statement. \nWith the similar situation in batch normalization, we can take $\\gamma_{LN}, \\beta_{BN} \\in \\mathbb{R}^n$. This means that\nwe can also remove the bias $b$ in original DNN.\nThus to say, we have the layer normalization transformation as:\n\\begin{equation}\\label{eq:LN-h}\nh_{LN}(z) = \\gamma_{LN} \\frac{z - \\mu_{LN}\\bm 1}{\\sigma_{LN} \\bm 1} + \\beta_{LN}.\n\\end{equation}\nMore details of this normalization can be found in \\cite{ba2016layer} by G. Hinton for RNN models.\n\n\n\\paragraph{Weight Normalization (WN)}\nWeight normalization  normalizes the \nrow norm of the matrix  $W$ in fully connected layer instead of \nthe output $z$.\nTo normalize $W_k$, i.e. keep the 2-norm of $W_k$ to $1$, we may \nhave a weight normalization transformation as\n$$\n[{\\rm WN}(z(x)) ]_k= \\gamma_k \\frac{W_k \\cdot x}{\\|W_k\\|_{2}} + b_k.\n$$\nThis is a little different from the $h(\\cdot)$ above, but we can still recover this\nby choosing those parameters carefully.\nHere, in weight normalization, we can take \n\\begin{equation}\n\\mu_{WN} = b,\\quad  \\sigma_{WN} = \\left( \\|W_1\\|_{2}, \\cdots \\|W_n\\|_{2}\\right),\\quad \\beta_{WN} = b,\n\\end{equation}\nwith $\\gamma_{WN}$ free.\nMore details can be found in \\cite{salimans2016weight}.\n\n\\paragraph{Cosine Normalization (CN)}\nCosine normalization normalizes both $W_k$ and the data $z$. \nIt can be shown as\n$$\n[{\\rm CN}(z(x)) ]_k= \\gamma_k \\frac{(W_k, b_k) \\cdot (x,1) }{\\|(W_k,b_k)\\|_{2} \\|(x,1)\\|_{2}}.\n$$\nWe can also recover this by choosing those parameters carefully.\nHere, in cosine normalization, we can take \n\\begin{equation}\n\\mu_{CN} = 0,\\quad  \\sigma_{WN} =  \\|(x,1)\\|_{2}\\left(\\|(W_1,b_1)\\|_{2}, \\cdots \\|(W_n,b_n)\\|_{2}\\right),\\quad \\beta_{WN} = 0,\n\\end{equation}\nwith $\\gamma_{WN}$ free.\nMore details can be found in \\cite{luo2018cosine}.\n\n\\paragraph{Spectral Normalization (SN)}\nThe original idea in spectral normalization is to control the ``robustness'' of the deep neural networks.\nThus to say, if you have a small perturbation in input data, the output should \nalso keep stable.\nFor ReLU DNN, the ``robustness'' means the Lipschitz  continuity because of the regularity of ReLU.\n\nOne hidden layer as example, \n\\begin{equation}\n\\| \\sigma(Wx + b) - \\sigma(W(x+\\Delta x) + b)\\|_2 \\le \\|W\\Delta x\\|_2,\n\\end{equation}\nthis means that the Lipschitz constant for $\\sigma(Wx+b)$ equals to $\\|W\\|_2 = \\sigma (W)$ where\n\\begin{equation}\n\\sigma(W)=\\max_{x\\neq0}\\frac{\\|Wx\\|_2}{\\|x\\|_2}.\n\\end{equation}\nFor ReLU DNN case,\n$$\n\\|f^J(x;\\Theta)\\|_{\\rm Lip} \\le \\Pi_{\\ell=0}^J \\sigma(W).\n$$\nSpectral normalization devotes to normalize the$ \\|f^J(x;\\Theta)\\|_{\\rm Lip} $ to be 1.\nThis can hold if \n$$\n\\sigma (W^\\ell) = 1, \\quad \\forall \\ell = 0:J.\n$$\nSo, it is natural to add the next normalization \n$$\n{\\rm SN}(z(x)) = \\frac{ Wx }{\\sigma(W)} + b.\n$$\nThen, it can be recovered from $h(\\cdot)$ simply by choosing\n\\begin{equation}\n\\mu_{CN} = b,\\quad  \\sigma_{CN} =  \\sigma(W),\\quad \\gamma_{CN} = 1, \\quad \\beta_{CN} = b.\n\\end{equation}\n\n\\begin{remark}\nGenerally speaking, $\\sigma (W)$ is difficult to take gradient. They use some trick in the paper \\cite{miyato2018spectral}.\n\\end{remark}\n\n\n%The authors of SN argues that an advantage of smaller $\\sigma(W)$ is that $Wx$ is less sensitive to the perturbation $\\xi$ on $x$, because\n%\\begin{equation}\n%\t\\frac{\\|(W(x+\\xi)+b)-(Wx+b)\\|}{\\|\\xi\\|}=\\frac{\\|W\\xi\\|}{\\|\\xi\\|}\\leq\\sigma(W).\n%\\end{equation}\n%$\\sigma(W)$ is thus added to the loss function, and gives\n%\\begin{equation}\n%\tL_\\text{SN}(X)=\\frac{1}{m}\\sum_{i=1}^m\\|f(x_i)-y_i\\|_2^2+\\frac{\\lambda}{2}\\sum_{l=1}^{n_L}\\sigma(W_l)^2.\n%\\end{equation}\n\n\n\\paragraph{Group Normalization (GN)}\nThis method is proposed by Kaiming He, \nfor the limitation of batch normalization with\n\\begin{itemize}\n\t\\item If mini-batch is big, computation coast.\n\t\\item if mini-batch is small, result is poor.\n\\end{itemize}\nThe idea is that, the feature in channel dimension (neuron dimension) should\ngroup each together if they share similar features. That is to say, for example,\n$$\n(z_1, z_2, \\cdots, z_n) = \\left( (z_{1}, \\cdots, z_{g}), (z_{g+1}, \\cdots, z_{2g}), \\cdots, (z_{n-g+1}, z_{n})\\right),\n$$\nand in each group \n$$\n(z_{kg+1}, \\cdots, z_{(k+1)g}), \\quad k = 0:\\frac{n}{g}-1,\n$$\nshould share the similar distribution which means we should take average just in this group.\nThus to say, we have the next formula for $\\mu_{GN}$ and $\\sigma_{GN}$,\n\\begin{equation}\\label{eq:GN-mu}\n\\mu_{GN} = (\\mu_1 \\bm 1_{g}, \\cdots, \\mu_{\\frac{n}{g}} \\bm 1_g), \\quad \\sigma_{GN} = (\\sigma_1 \\bm 1_{g}, \\cdots, \\sigma_{\\frac{n}{g}} \\bm 1_g),\n\\end{equation}\nwith \n$$\n\\mu_{k} = \\frac{1}{g}\\sum_{i = (k-1)g+1}^{kg} z_i, \\quad \\sigma_k = \\sqrt{\\frac{1}{g} \\sum_{i = (k-1)g+1}^{kg}(z_i - \\mu_k)^2}.\n$$\n\n\\begin{figure*}[!htb]\n\t\\centering\n\t\\includegraphics[width=.72\\linewidth]{GN_all_norms}\n\t\\vspace{.5em}\n\t\\caption{\\textbf{Normalization methods}. Each subplot shows a feature map tensor, with $N$ as the batch axis, $C$ as the channel axis, and $(H, W)$ as the spatial axes.\n\t\tThe pixels in blue are normalized by the same mean and variance, computed by aggregating the values of these pixels.\n\t}\n\t\\label{fig:all_norms}\n\t\\vspace{-.5em}\n\\end{figure*}\nMore details can be found in \\cite{wu2018group}.\n\n\n\n\n\\section{Example: numerical results for different normalizations}\nThe methods are tested with a two-hidden-layer fully connected neural network, with Adam optimizer of learning rate 0.01.\n\nThe two hidden layers are both applied the same normalization methods. The first hidden layer has 128 neurons, and the second 64 neurons.\n\nThe dataset is MNIST. The training batch size is 64.\n\n\\begin{figure}[H]\n\t\\center\n\t\\includegraphics[width=0.8\\textwidth]{Normal_res1.png}\n\t\\caption{Comparison between different normalization methods. I means identity, i.e. without any normalization.}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\center\n\t\\includegraphics[width=0.8\\textwidth]{Normal_res2.png}\n\t\\caption{Use ReLU as activation.}\n\\end{figure}", "meta": {"hexsha": "1d04ee78cc196819292f2cd2a351adb781c7c516", "size": 8523, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Normalization_DL.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/Normalization_DL.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/Normalization_DL.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.0963302752, "max_line_length": 169, "alphanum_fraction": 0.6949430952, "num_tokens": 2838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7316872290418978}}
{"text": "\n\\subsection{Mixed regression trees}\n\nIn classical trees all items in a leaf are assigned the same values. In this model, all are given \\(\\theta \\) for a parametric model.\n\nThis makes the resulting trees smoother.\n\nWe have some \\(\\hat y_i = f(\\mathbf x_i, \\theta ) + \\epsilon \\)\n\nThe approach generalises classic regression trees. There the estimate was \\(\\bar y\\). Here it's a regression.\n\n\\subsubsection{Training}\n\nAt each node we do OLS. If the \\(R^2\\) of the model is less than some constant, we find a split which maximises the minimum of the two new \\(R^2\\).\n\n\n", "meta": {"hexsha": "3013e167a0c96db74532f675d6236e4afb9ffe71", "size": 567, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/treesRegression/01-03-treeMixed.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/treesRegression/01-03-treeMixed.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/treesRegression/01-03-treeMixed.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.3529411765, "max_line_length": 147, "alphanum_fraction": 0.7301587302, "num_tokens": 144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7315570221709446}}
{"text": "\\subsection*{Exercise 2 (c)}\n\nEither prove or show a counter example for the following statement. If the same \nprimes divide $m$ and $n$ then\n\\begin{equation}\nm \\phi (n) = n \\phi (m)\n\\end{equation}\n\n%---------------------------------------------------------------------------------------------------\n%\t\t\tSOLUTION 1\n%---------------------------------------------------------------------------------------------------\n\\subsubsection*{Exercise 2 (c) Solution 1}\n\nLet $n=p_1^{a_1}p_2^{a_2}...p_k^{a_k}$ and $m=p_1^{b_1}p_2^{a_2}...p_k^{b_k}$. \nThen, \n\\begin{align} \n\tn \\phi (m) \t&= p_1^{a_1}p_2^{a_2}...p_k^{a_k} \\phi ( p_1^{b_1}p_2^{a_2}...p_k^{b_k} ) \\\\\n\t\t\t\t&= \\Pi p_i^{a_i} \\phi ( \\Pi p_i^{b_i} )\n\\end{align}\n\n%% TODO-Ve: finish this solution\n\n%---------------------------------------------------------------------------------------------------\n%\t\t\tSOLUTION 2\n%---------------------------------------------------------------------------------------------------\n\\subsubsection*{Exercise 2 (c) Solution 2}\n\nSee Greg Hurst's solutions \\cite{hurst14solutions} for a similar approach starting with \n\\begin{equation}\n\t\\frac{\\phi (m)}{m} = \\frac{\\phi (n)}{n}.\n\\end{equation}", "meta": {"hexsha": "6de2a22fc4e25efb53177a2b1366ad7d206d55d0", "size": 1166, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "intro-to-analytic-number-theory/ch2/q2_c.tex", "max_stars_repo_name": "vvveracruz/solutions", "max_stars_repo_head_hexsha": "42d9bf331dafbcb582fb4e863ce854e731177f52", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "intro-to-analytic-number-theory/ch2/q2_c.tex", "max_issues_repo_name": "vvveracruz/solutions", "max_issues_repo_head_hexsha": "42d9bf331dafbcb582fb4e863ce854e731177f52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "intro-to-analytic-number-theory/ch2/q2_c.tex", "max_forks_repo_name": "vvveracruz/solutions", "max_forks_repo_head_hexsha": "42d9bf331dafbcb582fb4e863ce854e731177f52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.6129032258, "max_line_length": 100, "alphanum_fraction": 0.4202401372, "num_tokens": 336, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.7315570184988663}}
{"text": "\\section{Artificial Neural Network}\n\\label{sec:theoretical_background:ann}\n\nAn \\acrlong{ann} is a model used in \\acrshort{ml} which consists of artificial neurons and weighted connections between those neurons.\nThey usually feature an input layer, several hidden layers and an output layer.\nThe individual layers consist of an arbitrary number of artificial neurons, which are connected to one another \\cite[p.~33-36]{nn}.\n\nThe simplest \\acrshort{ann} is the feedforward neural network, where the information propagates in only one direction.\nA common propagation function is the weighted sum of the neurons from the previous layer.\nTherefore, the output of each neuron $i$ is multiplied with the weight $w_{i, j}$ associated to the connection between the two neurons.\nThese values are summed up and added to a bias term.\nIn a last step, an activation function is applied, which results in equation \\ref{eq:artificial_neuron}.\n\n\\begin{equation}\n  y_j = a\\left(\\sum\\limits_{i} x_i \\cdot w_{i, j} + b\\right)\n  \\label{eq:artificial_neuron}\n\\end{equation}\n\nwhere\n\n\\begin{tabular}{lll}\n  $y_j$ & = & output of neuron $j$ \\\\\n  $a(.)$ & = & activation function \\\\\n  $x_i$ & = & output of neuron $i$ from the previous layer \\\\\n  $w_{i, j}$ & = & weight $i, j$ connecting the output of neuron $i$ with the input of neuron $j$ \\\\\n  $b$ & = & bias \\\\\n\\end{tabular}\n\\\\\n\n\n\n\n\\subsection{Activation Function}\n\\label{subsec:theoretical_background:ann:activation_function}\n\nAn activation function is responsible for transforming the input of an artificial neuron to its output.\nThere exists a variety of different linear and non-linear activation functions.\nHowever, non-linear activation functions are preferred due to their ability to learn more complex structures in the data.\nThe sigmoid and hyperbolic tangent activation functions were traditionally very popular, but they both suffer from a saturation problem.\nCurrently, the \\acrfull{relu} is the most commonly used activation function in the field of deep learning.\nIt is a piecewise-defined function, which outputs the input if it positive and zero otherwise.\nThis is shown in equation \\ref{eq:relu}.\nFurthermore, the \\acrshort{relu} activation function requires only a single comparison and is therefore not very computationally expensive \\cite{relu}.\n\n\\begin{equation}\n  a(x) = x^+ = \\max(0, x)\n  \\label{eq:relu}\n\\end{equation}\n", "meta": {"hexsha": "e21740644318721fd0225f59e4a51f6d585b665c", "size": 2372, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/thesis/chapters/theoretical_background/ann.tex", "max_stars_repo_name": "MuellerDominik/AIonFPGA", "max_stars_repo_head_hexsha": "f2379782660d4053a5bb60b9f6c6dea17363f96d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-01-21T09:42:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-22T13:36:12.000Z", "max_issues_repo_path": "doc/thesis/chapters/theoretical_background/ann.tex", "max_issues_repo_name": "MuellerDominik/AIonFPGA", "max_issues_repo_head_hexsha": "f2379782660d4053a5bb60b9f6c6dea17363f96d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/thesis/chapters/theoretical_background/ann.tex", "max_forks_repo_name": "MuellerDominik/AIonFPGA", "max_forks_repo_head_hexsha": "f2379782660d4053a5bb60b9f6c6dea17363f96d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-20T14:17:25.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-20T14:17:25.000Z", "avg_line_length": 48.4081632653, "max_line_length": 151, "alphanum_fraction": 0.7647554806, "num_tokens": 580, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7314854933228203}}
{"text": "\\chapter{The Realization of a Vector Space or: Introduction to the Architecture of Spacetime}\nLet's review\\footnote{At this point, it might be useful to have watched a few of the lessons in the ``What is a Manifold?'' series.} what we have covered so far.\nIf we have a vector space $V$ over a field $F$, we can find a basis $\\{\\vec{e}_\\mu\\}$ for it.\nThe creation of that vector space automatically implies the creation of the dual space $V^*$ and its basis $\\vec{e}^\\nu$, chosen so that $\\langle \\vec{e}^\\nu, \\vec{e}_\\mu \\rangle = \\delta^\\nu_\\mu$.\nIf we promote $V$ to a metric space by the inclusion of an inner product $(\\cdot,\\cdot)$, we automatically get a new object called the metric tensor, $g_{\\mu\\nu} \\in \\tps{T}^0_2$, defined so that\n\\begin{align*}\n    (\\vec{v},\\vec{w}) = g_{\\mu\\nu}(\\vec{v} \\otimes \\vec{w}).\n\\end{align*}\nUp until this point, we've only discussed the vector inner product, which acts on elements of $V$ to produce elements of $\\mathbb{F}$.\nBut as we've already shown, $V^*$ is \\emph{also} a vector space in its own right, so when we promote $V$ to becoming a metric space, we should promote $V^*$ as well.\nThe question then becomes ``how do we define the inner product for $V^*$?''\nWell, in a similar fashion to the definition of the basis vectors, we'll use $V$ as an inspiration.\nIn particular, we'll define the inner product on $V^*$ such that\n\\begin{align*}\n    \\underbrace{(A_\\mu \\vec{e}^\\mu, B_\\nu \\vec{e}^\\nu)}_{\\text{$(\\cdot, \\cdot)$ on $V^*$}} = \\underbrace{(A^\\mu \\vec{e}_\\mu, B^\\nu \\vec{e}_\\nu)}_{\\text{$(\\cdot, \\cdot)$ on $V$}}.\n\\end{align*}\nJust as there is a metric tensor for the vector inner product, we also get to define a metric tensor for the dual space inner product.\nAs you might guess, we call this rank $(2,0)$ tensor\n\\begin{align*}\n    g^{\\mu\\nu} \\vec{e}_\\mu \\otimes \\vec{e}_\\nu &: V \\otimes V \\to \\mathbb{F} \\\\\n               &: \\tps{T}^2_0 \\to \\mathbb{F} \\\\\n               &: \\vb*{\\alpha} \\times \\vb*{\\beta} \\mapsto (\\vb*{\\alpha},\\vb*{\\beta}).\n\\end{align*}\nAll of this, the basis vectors, the tensor product spaces, the dual space, notions of linear mapping, has been created \\emph{de jure}, in a sense, by the creation of a vector space; once we instantiate $V$, everything else pops into existence without any additional work on our part.\nIf we promote $V$ to become an inner product space, we automatically get the metric tensors $g_{\\mu\\nu}$ and $g^{\\mu\\nu}$.\nWe get this because we've asserted that everything plays nicely; since we've created these vector spaces, \\emph{of course} its logical that everything falls into place, because that's how we've defined it.\nThe objects we've been discussing have been the abstract mathematical ideals of what vectors and covectors and tensors are.\nNow, in physics, we're going to look for \\emph{realizations} of a vector space; these are specific objects which act as vector spaces (and are vector spaces in the fullest sense of the word), but which aren't generalized to the degree that we've been discussing.\nA good example of this is the notion of vectors as arrows with magnitude and direction; although that's not what we defined a vector to be in this lesson, they certainly act as vectors in a vector space, since they can be added, have inverses and a zero vector, and are closed under these operations.\nLikewise, the physical notions which we ascribe to these vectors, like forces and acceleration, also form realizations of a vector space.\n\n\\section{The Differential Operator}\nLet's imagine a function $f$ in four variables, denoted $x_0$ through $x^3$, so\n\\[ f(x^0,x^1,x^2,x^3) = f(x^\\mu) = f(x), \\]\nwhere we understand that $x = x^\\mu$.\nThese elements will be known as \\emph{coordinates}.\nWe say that $f$ is differentiable if we can write\n\\begin{align*}\n    \\bm{\\partial}_\\mu f \\equiv \\pdv{f}{x^\\mu}\n\\end{align*}\nwhere $\\bm{\\partial}_\\mu f$ is a symbolic equivalent to the partial derivative of $f$ with respect to $x^\\mu$.\nAs a quick side note, we choose this notation so that we can contract over it just like with tensors; if you think of $x^\\mu$ as the basis and $\\bm{\\partial}_\\mu$ as the component, then something like $\\qty(\\partial_\\mu f)A^\\mu$ could be summed over with Einstein summation.\nBecause derivatives are linear operators, we can write that \n\\[ \\lambda\\bm{\\partial}_\\mu f + \\lambda\\bm{\\partial}_\\nu f = \\lambda\\qty(\\bm{\\partial}_\\mu + \\bm{\\partial}_\\nu) f, \\]\nwhere $\\lambda \\in \\mathbb{F}$ and $\\qty(\\bm{\\partial}_\\mu + \\bm{\\partial}_\\nu)$ is in effect a new differential operator.\nIf we wanted to, we could create an operator $\\mathcal{L} = a\\bm{\\partial}_0 + b\\bm{\\partial}_1 + c\\bm{\\partial}_2 + bm{\\partial}_4$, so $\\mathcal{L}$ is a linear combination of our original four partial differential operators.\nBecause of the linearity of these differential operators, if we created a set $\\{\\mathcal{L}\\}$ of all possible differential (and therefore linear) operators on a function $f$ of four variables $x^\\mu$, this set would be a vector space, with a basis $\\{\\bm{\\partial}_\\mu\\}$.\nLet's stipulate that $\\lambda$ are all elements of $\\mathbb{R}$; then we've just created a realization of a four dimensional, real vector space.\nOne interesting thing of note is that $f$ itself is kind of irrelevant here; it doesn't matter if $f$ is a linear function or not, since the differential operator $\\bm{\\partial}$ is.\nWe care about these operators\\footnote{Notice that we've been writing $\\bm{\\partial}_\\mu$ in \\emph{bold}, to emphasize that the differential operators are ... you guessed it, vectors!} since they are tools which allow us to create a model of spacetime.\n\n\\section{Spacetime}\nThroughout the rest of this lesson, we'll be using the following figure as a graphic model for spacetime.\nThis is a canonical way to represent points in spacetime, such as $P, Q, R, S$, in reference to coordinate lines, like $x^1$ and $x^2$.\n\\begin{figure}[h]\n    \\centering\n    \\begin{tikzpicture}\n        \\node (origin) at (0,0) {}; % Origin node, not shown\n        \n        %% These are the four corners of the \"square\"\n        \\node (a) at (0,0) {};\n        \\node (b) at (1,-0.5) {};\n        \\node (c) at (5.5,1) {};\n        \\node (d) at (4.5,0.5) {};\n        \\node (e) at (5,3.5) {};\n        \\node (f) at (4,4) {};\n        \\node (g) at (1,3.5) {};\n        \\node (h) at (0,3) {};\n        \n        %% Curves\n        \\draw [name path=line-1] (a) to [bend left=10] (f);\n        \\draw [name path=line-2] (b) to [bend left=10] (e);\n        \\draw [name path=line-3] (g) to [bend left=10] (c);\n        \\draw [name path=line-4] (h) to [bend left=10] (d);\n        \n        %% Points\n        \\path [name intersections={of=line-1 and line-3,by=P}];\n        \\node [circle, fill=black,inner sep=1.5pt,label=90:$P$] at (P) {};\n        \n        \\path [name intersections={of=line-2 and line-3,by=Q}];\n        \\node [circle, fill=black,inner sep=1.5pt,label=0:$Q$] at (Q) {};\n        \n        \\path [name intersections={of=line-2 and line-4,by=R}];\n        \\node [circle, fill=black,inner sep=1.5pt,label=-90:$R$] at (R) {};\n        \n        \\path [name intersections={of=line-1 and line-4,by=S}];\n        \\node [circle, fill=black,inner sep=1.5pt,label={[shift={(-0.35,-0.4)}]$S$}] at (S) {};\n        \n        %% Line labels\n        \\node [label={[shift={(0.55,-0.5)}]$x^1$}] at (a) {};\n        \\node [label={[shift={(0.6,0)}]$x^2$}] at (h) {};\n    \\end{tikzpicture}\n    \\caption{Labeled diagram of our spacetime $\\mathcal{S}$.}\n    \\label{fig:spacetime_plain}\n\\end{figure}\n\\noindent\nWe can think of the coordinate lines as being like latitude and longitude, or as $(t,x,y,z)$ coordinates.\nIn the diagram shown above, we're only depicting two coordinate lines, leaving the $x^0$ and $x^3$ coordinates of the points implicit.\nNote that in reality, we would be giving names to an infinite number of points, not just the four shown here.\nFor each of the points shown, there are an associated set of coordinates.\nIf we take point $Q$ as an example, we might say that $Q$ has coordinates $(x^0,x^1,x^2,x^3)$, or more succinctly that $Q$ has coordinates\\footnote{Without rigorously defining it at this point, it's good to recall that we usually think of $x^0$ as being time, while $x^1$ through $x^3$ represent various spatial coordinates. This corresponds nicely with the Minkowsky metric signature.} $x^\\mu$.\nNote that in this case, this doesn't mean that $x^\\mu$ is a member of a vector space, since we haven't talked about what the basis vectors would be; we're just using the superscript notation as a shorthand for each of the separate coordinates.\nIt's also important to note that we're not talking about any particular coordinate systems here, just a generalized one; it could be spherical or Cartesian or what-not, but for now we really don't care.\n\nOnce we've defined a coordinate system, we can start to think of functions on those coordinates.\nWe could imagine such a function being given by\n\\[ f(x^\\mu) = \\mathrm{e}^{x^0}\\sin x^1 + \\frac{(3x^2)^3}{x^3}. \\]\nWe call any such function a \\emph{function on the spacetime}.\n\n\\section{Integrating Spacetime and Vector Spaces}\nIn the past, we've talked about an abstract vector space $V$ with a basis $\\{\\vec{e}_\\mu\\}$.\nWhen discussing spacetime, we'll consider a realization of this vector space;\nthis realized vector space $V$ will be a four-dimensional, real vector space with basis $\\{\\bm{\\partial}_\\mu\\}$.\nImportantly, we won't be creating just one of these vector spaces.\nWe will create a separate vector space \\emph{for each point in spacetime}.\nWe'll label the vector space by the point it's attached to, so the vector space at $Q$ might be $V_P$.\nBecause we're creating vector spaces at each point, we also get for free the dual space $V_P^*$ and the infinite number of tensor product spaces associated with $V_P$ and $V^*_P$.\n", "meta": {"hexsha": "ec3f5570f3319143a7c8401ef9f3139f56053010", "size": 9794, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/realization.tex", "max_stars_repo_name": "jopetty/tensor-notes", "max_stars_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/realization.tex", "max_issues_repo_name": "jopetty/tensor-notes", "max_issues_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/realization.tex", "max_forks_repo_name": "jopetty/tensor-notes", "max_forks_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 83.0, "max_line_length": 395, "alphanum_fraction": 0.6913416377, "num_tokens": 2809, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602593, "lm_q2_score": 0.7853085758631158, "lm_q1q2_score": 0.7314854903345899}}
{"text": "\n\\subsection{Limit of a sequence}\n\nA sequence converges to a limit if\n\nCan converge to a number (1/x)\n\nCan converge to +/- infinity (x)\n\nOtherwise, does not converge (1,-1,1,-1…)\n\nSuperior and inferior limits\n\nA bounded increasing sequence converges to least upper bound\n\n\\subsubsection{Identifying the limit of a sequence}\n\nDirect comparison test\n\nRoot test\n\n", "meta": {"hexsha": "6ce82645ad693a974fd2ba0e7abe766784fcb8f4", "size": 360, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/sequencesInfinite/01-01-limit.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/sequencesInfinite/01-01-limit.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/sequencesInfinite/01-01-limit.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.3636363636, "max_line_length": 60, "alphanum_fraction": 0.7611111111, "num_tokens": 85, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7314787059129421}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Disks and Washers}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises for the disk and washer methods.\n\\end{abstract}\n\\maketitle\n\n\\begin{exercise}\nThe region $0 \\leq y \\leq \\sqrt{x}$ with $x \\leq 1$, shown below, is revolved around the $x$-axis. Use the disk method to find the volume of the solid of revolution.\n\\begin{center}\n\\begin{image}\n\\includegraphics[width=4in]{diskwasher/disk01.png}\n\\end{image}\n\\end{center}\n\\begin{hint}\nThe radius $R(x)$ will be a difference of $y$-values because slices are indexed by the variable $x$.\nEach slice will extend from $y=0$ to $y =  \\sqrt{x}$, and so $R(x)$ must be the larger of these $y$-values minus the smaller of these $y$-values.\n\\end{hint}\n\\begin{prompt}\n\\[ R(x) = \\answer{\\sqrt{x}} \\]\n\\[ V = \\int_{\\answer{0}}^{\\answer{1}} \\pi (R(x))^2 dx =  \\answer{\\frac{\\pi}{2}} \\]\n\\end{prompt}\n\\end{exercise}\n\n\n\\begin{exercise}\nThe region $0 \\leq y \\leq \\sqrt{x}$ with $x \\leq 1$, shown below, is revolved around the axis $x=1$. Use the disk method to find the volume of the solid of revolution.\n\\begin{center}\n\\begin{image}\n\\includegraphics[width=4in]{diskwasher/disk02.png}\n\\end{image}\n\\end{center}\n\\begin{hint}\nThe radius $R(y)$ will be a difference of $x$-values because slices are indexed by the variable $y$.\nEach slice will extend from $x = y^2$ to $x = 1$, and so $R(y)$ must be the larger of these $x$-values minus the smaller of these $x$-values\n\\end{hint}\n\\begin{prompt}\n\\[ R(y) = \\answer{1 - y^2} \\]\n\\[ V = \\int_{\\answer{0}}^{\\answer{1}} \\pi (R(y))^2 dy = \\answer{\\frac{8\\pi}{15}} \\]\n\\end{prompt}\n\\end{exercise}\n\n\n\\begin{exercise}\nThe region $0 \\leq y \\leq \\sqrt{x}$ with $x \\leq 1$, shown below, is revolved around the axis $x=0$. Use the washer method to find the volume of the solid of revolution.\n\\begin{center}\n\\begin{image}\n\\includegraphics[width=4in]{diskwasher/disk04.png}\n\\end{image}\n\\end{center}\n\\begin{hint}\nEach radius will be a difference of $x$-values because slices are indexed by the variable $y$.\nThe distance from the axis $x=0$ to the line $x=1$ is $1$, and the distance from the axis $x=0$ to $x = y^2$ is $y^2$.\n\\end{hint}\n\\begin{prompt}\n\\[ R_{\\mathrm{outer}} (y) = \\answer{1} \\text{ and } r_{\\mathrm{inner}}(y) = \\answer{y^2} \\]\n\\[ V = \\int_{\\answer{0}}^{\\answer{1}} \\pi  \\left[ (R_{\\mathrm{outer}}(y))^2 - (r_{\\mathrm{inner}}(y))^2 \\right] dy =  \\answer{\\frac{4\\pi}{5}} \\]\n\\end{prompt}\n\n\\end{exercise}\n\n\\begin{exercise}\nThe region $0 \\leq y \\leq \\sqrt{x}$ with $x \\leq 1$, shown below, is revolved around the axis $y=1$. Use the washer method to find the volume of the solid of revolution.\n\\begin{center}\n\\begin{image}\n\\includegraphics[width=4in]{diskwasher/disk03.png}\n\\end{image}\n\\end{center}\n\\begin{hint}\nEach radius will be a difference of $y$-values because slices are indexed by the variable $x$.\nThe distance from the axis $y=1$ to the line $y=0$ is $1$, and the distance from the axis $y=1$ to $y = \\sqrt{x}$ is $1 - \\sqrt{x}$.\n\\end{hint}\n\\begin{prompt}\n\\[ R_{\\mathrm{outer}} (x) = \\answer{1} \\text{ and } r_{\\mathrm{inner}}(x) = \\answer{1-\\sqrt{x}} \\]\n\\[ V = \\int_{\\answer{0}}^{\\answer{1}} \\pi  \\left[ (R_{\\mathrm{outer}}(x))^2 - (r_{\\mathrm{inner}}(x))^2 \\right] dx =  \\answer{\\frac{5\\pi}{6}} \\]\n\\end{prompt}\n\\end{exercise}\n\n\n\n\\section*{Sample Quiz Questions}\n\n\\begin{question}%%%%%[WasherQuad001]\n\nThe region in the plane bounded on the left by the curve \\(x=-y^2\\), on the right by the curve \\(x=y^2+2y+2\\), above by the line  \\(y = 0\\), and below by the line \\(y = -2\\) is revolved around the axis \\(x = 2\\). Compute the volume of the resulting solid.\n(Hints won't reveal until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(16\\pi\\)}\n\\choice{\\(20\\pi\\)}\n\\choice[correct]{\\(24\\pi\\)}\n\\choice{\\(28\\pi\\)}\n\\choice{\\(32\\pi\\)}\n\\choice{\\(36\\pi\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nThe axis \\(x = 2\\) is perpendicular to the direction of slices using the integration variable \\(y\\), which indicates the washer method. \n The region lies to the left of the axis. One way to see this is to evaluate \\(x=-y^2\\) at \\(y = -2\\), giving \\(x = -4\\), which is to the left of the axis \\(x = 2\\).\n \\begin{hint}\nThe integral to compute equals \\[ \\begin{aligned} V &= \\int_{-2}^{0}\\pi \\left((2-(-y^2))^2 - (2-(y^2+2y+2))^2\\right)~ dy\\\\\n& = \\pi \\int_{-2}^{0} (-4y^3+4)~ dy\\\\\n& = \\pi \\left. \\left(-y^4+4y\\right) \\right|_{-2}^{0} = 24\\pi. \\end{aligned}\\]\n\\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[WasherQuad008]\n\nThe region in the plane bounded below by the curve \\(y=-2x^2+5x+2\\), above by the curve \\(y=-2x^2+2x+2\\), on the right by the line  \\(x = 0\\), and on the left by the line \\(x = -1\\) is revolved around the axis \\(y = 2\\). Compute the volume of the resulting solid.\n(Hints won't reveal until after you choose a response.)\n\\begin{multiplechoice}\n\\choice[correct]{\\(10\\pi\\)}\n\\choice{\\(14\\pi\\)}\n\\choice{\\(18\\pi\\)}\n\\choice{\\(22\\pi\\)}\n\\choice{\\(26\\pi\\)}\n\\choice{\\(30\\pi\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nThe axis \\(y = 2\\) is perpendicular to the direction of slices using the integration variable \\(x\\), which indicates the washer method. \n The region lies below the axis. One way to see this is to evaluate \\(y=-2x^2+5x+2\\) at \\(x = -1\\), giving \\(y = -5\\), which is below the axis \\(y = 2\\).\n \\begin{hint}\nThe integral to compute equals \\[ \\begin{aligned} V &= \\int_{-1}^{0}\\pi \\left((2-(-2x^2+5x+2))^2 - (2-(-2x^2+2x+2))^2\\right)~ dx\\\\\n& = \\pi \\int_{-1}^{0} (-12x^3+21x^2)~ dx\\\\\n& = \\pi \\left. \\left(-3x^4+7x^3\\right) \\right|_{-1}^{0} = 10\\pi. \\end{aligned}\\]\n\\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[washersqrtsub001]\n\nThe region in the plane given by \\(\\left|{- \\frac{x}{2} + \\frac{1}{2} \\sqrt{9 - 6 x^{2}}}\\right| \\leq y \\leq \\frac{x}{2} + \\frac{1}{2} \\sqrt{9 - 6 x^{2}}\\) and \\(0 \\leq x \\leq \\frac{2}{3} \\sqrt{3}\\) is revolved around the \\(x\\)-axis. Compute the volume of the resulting solid.\n(Hints won't reveal until after you choose a response.)\n\\begin{multiplechoice}\n\\choice[correct]{\\(\\displaystyle \\frac{13}{9} \\pi\\)}\n\\choice{\\(\\displaystyle \\frac{19}{9} \\pi\\)}\n\\choice{\\(\\displaystyle \\frac{26}{9} \\pi\\)}\n\\choice{\\(\\displaystyle \\frac{28}{9} \\pi\\)}\n\\choice{\\(\\displaystyle \\frac{37}{9} \\pi\\)}\n\\choice{\\(\\displaystyle \\frac{49}{9} \\pi\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nIf the variable \\(x\\) is used for slicing, then slices are perpendicular to the axis of rotation, which indicates the washer method should be used.\n\\begin{hint}\nThe inequalities for \\(y\\) give the outer and inner radii, and \\[ \\left(\\frac{x}{2} + \\frac{1}{2} \\sqrt{9 - 6 x^{2}}\\right)^2 - \\left( \\left|{- \\frac{x}{2} + \\frac{1}{2} \\sqrt{9 - 6 x^{2}}}\\right|\\right)^2 = x \\sqrt{9 - 6 x^{2}}. \\](Note that the absolute values go away when the radius is squared.)\n\\begin{hint}\nTo compute the integral \n\\[ \\int_{0}^{\\frac{2}{3} \\sqrt{3}} \\pi x \\sqrt{9 - 6 x^{2}}\\, dx \\]\n we can use the substitution \\(u = 9 - 6 x^{2}\\) which implies the equality \\(du = \\left(- 12 x\\right)dx\\) for the differentials. This gives the equality\n\\[ \\begin{aligned} \\int \\pi x \\sqrt{9 - 6 x^{2}}\\, dx & = \\int \\left(- \\frac{\\pi}{12} \\sqrt{u}\\right)\\, du \\\\\n & = - \\frac{\\pi}{18} u^{\\frac{3}{2}}. \\end{aligned} \\]\nReversing the substitution gives\n\\[ \\begin{aligned} \\int_{0}^{\\frac{2}{3} \\sqrt{3}} \\pi x \\sqrt{9 - 6 x^{2}}\\, dx & = \\left. \\left[- \\frac{\\pi}{18} \\left(9 - 6 x^{2}\\right)^{\\frac{3}{2}} \\right] \\right|_{0}^{\\frac{2}{3} \\sqrt{3}}\\\\ & = \\left(- \\frac{\\pi}{18} \\right) - \\left(- \\frac{3}{2} \\pi \\right) = \\frac{13}{9} \\pi. \\end{aligned} \\]\n\\end{hint}\n\\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "1f07098fe0d519a1b5c4a189d56efce5ca52fe44", "size": 7612, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "volumes/02washerpractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "volumes/02washerpractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "volumes/02washerpractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.5808383234, "max_line_length": 304, "alphanum_fraction": 0.6442459275, "num_tokens": 2766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.731478702651399}}
{"text": "\\Lecture{Jayalal Sarma}{ 16 November, 2020}{32}{Incidence Algebra and Mobius Inversion Over Posets}{Kaushik Arcot}{$\\alpha$}{JS}\n\n\\section{Recall}\n\n\\begin{theorem}[Stronger PIE]\n  \\label{stronger PIE}\n  Let $f,g:2^{[n]}\\longrightarrow \\mathbb{R}$ are functions assigning real numbers to subsets of $[n]$ with the property that for any $A\\subseteq [n]$\n\n  \\[ g(A)=\\sum_{S\\subseteq A} f(S)\\]\n\n  Then,\n  \\[ f(A) = \\sum_{S \\subseteq A} (-1)^{|A|-|S|}g(S)\\]\n\n\\end{theorem}\n\n\\textbf{Mobius Inversion of Functions}\n\n$f,g:\\mathbb{N} \\to \\mathbb{R} ~satisfying,$ $\\forall n ~g(n) = \\sum_{d|n} f(d)  ~~then,$  \n$$\\forall n ~f(n) = \\sum_{d|n} \\mu(d)g(\\frac{n}{d})$$\n\n\t\\[\n\t\\mu(d) = \\begin{cases} \n\t+1 , & ~if~ ~d~ ~is~ ~a~ ~\\href{https://en.wikipedia.org/wiki/Square-free_integer}{square-free} ~positive~ ~integer~ ~with~ ~an~ ~even~ ~number~ ~of~ ~prime~ ~factors~~\\\\\n \t-1 , & ~if~ ~d~ ~is~ ~a~ ~square-free~ ~positive~ ~integer~ ~with~ ~an~ ~odd~ ~number~ ~of~ ~prime~ ~factors~~\\\\\n\t0 , & otherwise\n\t\\end{cases}\n\t\\]\n\nWe can see in both cases that, there is an underlying poset for both the functions. For the first pair of functions, the poset is the Subset Poset, and for the second, it is the divisibilty poset. Our endeavour in this lecture is to further abstract this concept to any poset and acquire tools for algebra within poset functions, and then for Mobius Inversion of functions over posets.\n\n\\section{Incidence Algebra of Posets}\n\nLet $P = (X,\\le)$ be a poset. Let \n\n$$ A(P) = \\{ f: X \\times X \\to \\mathbb{R} | f(x,y) = 0, \\forall x,y \\in X  s.t x || y \\}$$\n\nHere $x || y$, indicates that x is incomparable to y in the Poset P. \\\\\n\nExample functions : \\\\\n\n\\textbf{Zero Function} \n\n$$ O(x,y) = 0 \\forall x,y \\in X $$\n\n\\textbf{Kronecker Delta Function}\n\n$$ \\delta(x,y) =  \\begin{cases} \n\t1 , &  ~if~ ~x~ ~=~ ~y~ \\\\\n\t0 , & otherwise\n\t\\end{cases} $$\n\n\\textbf{Characteristic Function of Poset}\n\n$$ \\zeta(x,y) =  \\begin{cases} \n\t1 , &  ~if~ ~x~ ~\\le~ ~y~ \\\\\n\t0 , & otherwise\n\t\\end{cases} $$\n\n\\medskip\n\n\\textbf{Addition Operator}\n\nGiven $f \\in A(P)$ , $g \\in A(P)$, the '+' operator\n\n$$ (f+g) (x,y) = f(x,y) + g(x,y) $$\n\nIf $x || y$, then $f(x,y) = 0$, $g(x,y) = 0$, and hence $(f+g)(x,y) = 0$.\nThus $(f+g) \\in A(P)$\n\n\\textbf{Remark} : A(P) forms a group with '+' operator as addition.\n\n\\medskip\n\\textbf{Scalar Multiplication}\n\nGiven $f \\in A(P)$ , $c \\in \\mathbb{R}$,\n$$ (cf)(x,y) = c*f(x,y)$$\n\nIf $x||y$, then $f(x,y) = 0$, and so $(cf)(x,y) = 0 $, Hence $(cf) \\in A(P)$\n\n\\textbf{Remark} : $A(P)$ is closed under addition and scalar multiplication. Thus, $A(P)$ forms a vector space.\n\n\\medskip\n\n\\textbf{Convolution Operator}\n\nWe define the operator '*' over $A(P)$. Given two functions, \n$f,g \\in A(P)$, the convolution operator is defined as,\n\n$$ (f*g)(x,y) = \\begin{cases} \n\t\\sum_{z:x\\le z \\le y} f(x,z)g(z,y), &  ~if~ ~x~ ~\\le~ ~y~ \\\\\n\t0 , & otherwise\n\t\\end{cases} $$\n\t\nWe find if  the following properties of the convolution operator hold or not.\n\n\\textbf{Commutative} \\\\\n\nConvolution operator is not commutative. Assume $x,y \\in X$ , such that $x \\le y$ and there exists no such z such that $x \\le z \\le y$. Then,\n\n$$ (f*g)(x,y) = f(x,x)g(x,y) + f(x,y)g(y,y)$$\n\n$$ (g*f)(x,y) = g(x,x)f(x,y) + g(x,y)f(y,y)$$\n\nThese two expressions are not always equal. Assume $f(x,x) = 1$, $g(x,y) = 1$, and $f(x,y) = f(y,y) = 0$, $g(x,x) = g(y,y) = 0$. Then, we have\n\n $(f*g)(x,y) = 1$ and $(g*f)(x,y) = 0$. Therefore, convolution is not commutative.\n \n\\textbf{Associative}\\\\\n\nThe convolution operator is associative. To prove, assume $f,g,h \\in A(P)$. Then,\n\n$$((f*g)*h)(x, y) = \\sum_{z: x \\le z \\le y}(f*g)(x, z) h(z, y)$$\n\n$$ = \\sum_{z: x \\le z \\le y}(\\sum_{w: x \\le w \\le z}f(x, w)g(w, z))h(z, y)$$\n\nBy changing the order of the summations, we get,\n\n$$ \\sum_{w: x \\le w \\le z}f(x, w)(\\sum_{z : w \\le z \\le y}g(w, z)h(z, y))$$\n\n$$ = \\sum_{w: x \\le w \\le z}f(x, w) (g*h)(w,y) $$\n\n$$ = (f*(g*h)) (x,y)$$\n\nHence, convolution is associative.\n\n\n\\textbf{Identity}\n\n\\textbf{Claim} : The Kronecker Delta function is the identity function of A(P)\n\n\\begin{proof}\nFor $f \\in A(P)$, if $x \\le y$,\n$$ (f*\\delta)(x,y) = \\sum_{z:x\\le z \\le y} f(x,z)\\delta(z,y)$$\n$$ =  \\sum_{z:x\\le z < y} f(x,z)\\delta(z,y) + f(x,y)\\delta(y,y)$$\n\nGiven that $z \\ne y$, we have $\\delta(z,y) = 0$. Thus, $(f*\\delta)(x,y)$\n\n$$ = f(x,y)\\delta(y,y)$$\n\n$\\delta(y,y) = 1$, So\n\n$$ = f(x,y) $$ \n\nThus, Kronecker Delta function($\\delta$) is the identity function of A(P).\n\n\\end{proof}\n\n\\section{Inverse of a Function}\n\nThe inverse of a function $f \\in A(P)$, is a function $g$, such that\n\n$$ (f*g)(x,y) = \\delta(x,y)$$\n\nDoes the inverse of any $f \\in A(P)$ exist ? No. In fact, we check for O(x,y). Let us assume there exists an inverse, Q(x,y) for the zero function. Then,\n$$ (O*Q)(x,x) = \\sum_{z:x\\le z \\le x} O(x,z)Q(z,x)$$\n\n$$ = O(x,x)Q(x,x) = 0$$\n\nBut $\\delta(x,x)$ = 1. Thus, O(x) (zero function) does not have an inverse. Can inverse exist for any other functions ? Yes, we see from this argument that for inverse to exist for $f \\in A(P)$, there exists no $x \\in X$, such that $f(x,x) = 0$. Infact, we prove next that for $f \\in A(P)$, such that $\\forall x \\in X, f(x,x) \\ne 0$, then there exists a unique inverse of f.\n\n\\section{Mobius Inversion over Posets}\n\n\n\\begin{lemma}\nFor any $f \\in \\mathbb{A}(P)$ such that $\\forall x \\in X, f(x,x) \\ne 0$, there exists $g \\in \\mathbb{A}(P)$ (which we will call $f^{-1}$) such that $\\forall x,y \\in X, g \\star f = \\delta$ where $\\delta$ is the Kronecker delta function.\n\\end{lemma}\n\\begin{proof}\nWe will directly write down the function $g$ based on $f$. For incomparable pairs $(x,y)$ we can define $g(x,y) = 0$. This ensures that $g \\in \\mathbb{A}(P)$. \n\nFor comparable pairs, the function $g$ on input $(x,y)$ is defined based on an induction on a parameter of $\\ell(x,y) \\in X$. The distance between $x$ and $y$, denoted by $\\ell(x,y)$ is said to be $k$, if $\\exists z_1, z_2, \\ldots z_{k-1}$ such that $x < z_1 < z_2 < \\ldots < z_{k-1} < y$ and $\\not\\exists w_1, w_2, \\ldots w_k$ such that $x < w_1 < w_2 < \\ldots < w_{k-1} < w_k < y$. In other words, this is the length of the longest directed path from $x$ to $y$ (or vice versa).\n\nNow we are ready to describe the definition of $g$ on comparable pairs $(x,y)$. \n\nAs the base case, when $\\ell(x,y) = 0$, we know that, $x=y$, hence we define:\n\n$$g(x,x) = \\frac{1}{f(x,x)}$$\nLet us quickly check that this indeed satisfies the property that we wanted for inputs of the kind $(x,x)$. That is,\n$$(g \\star f) (x,x) = \\sum_{x \\le z \\le y} g(x,z)f(z,y) = g(x,x)f(x,x) = 1 = \\delta(x,x)$$\n\nTo do the definition inductively: let us assume that $g(x,y)$ is defined when $\\ell(x,y) \\le k$, and we consider a pair $(x,y)$ with distance $k+1$. We define :\n$$g(x,y) = \\frac{-1}{f(y,y)}\\sum_{x \\le z < y} g(x,z)f(z,y)$$\nNote that this is well-defined since $g(x,z)$ is used in the RHS only for pairs $(x,z)$ with $\\ell(x,z) \\le k$ and that $f(y,y) \\ne 0$ for every $y \\in X$.\nWith this definition :\n\\begin{eqnarray*}\n(g \\star f) (x,y) & = & \\sum_{x \\le z \\le y} g(x,z)f(z,y)\\\\\n& = & \\sum_{x \\le z < y} g(x,z)f(z,y) + g(x,y)f(y,y)\\\\\n& = & \\sum_{x \\le z < y} g(x,z)f(z,y) + \\left(\\frac{-1}{f(y,y)}\\sum_{x \\le z < y} g(x,z)f(z,y)\\right) f(y,y) \\\\\n& = & 0 = \\delta(x,y)\n\\end{eqnarray*}\nSince $g \\in \\mathbb{A}(P)$ we have completed the proof.\n\\end{proof}\n\n\n\\Lecture{Jayalal Sarma}{ 18 November, 2020}{33}{Mobius Inversion Theorem for Posets and Corollaries}{Abhishek Aladahalli}{$\\alpha$}{JS}\n\n\\noindent In particular the \\textbf{zeta function} ($\\zeta$)\n$$ \\zeta (x, y) =  \n\\begin{cases}\n&1 ~~~~\\textrm{if} ~~x \\le y \\\\\n&0 ~~~~\\textrm{otherwise} \\\\\n\\end{cases}\n$$\nhas an inverse called the \\textbf{Mobius Function} ($\\mu$) of the poset.\\\\\n\n\\noindent From the lemma proved above we define Mobius Function as,\n\n\\noindent \\underline{For $x = y$},\n$$g(x,x) = \\mu(x,x) = \\frac{1}{\\zeta (x,x)} = 1$$\n$$=> \\boxed{\\mu(x,x) = 1 ~~ (\\textrm{Since} ~\\zeta (x,x) = 1)}$$\n\n\\noindent \\underline{For $x ~ || ~ y$}, (i.e. when $x$ and $y$ are incomparable)\n$$g(x,y) = \\mu(x,y) = \\frac{-1}{\\zeta(y,y)}\\sum_{x \\le z < y} \\mu(x,z) \\zeta(z,y)$$\n$$=> \\mu(x,y) = -1\\sum_{x \\le z < y} \\mu(x,z) \\zeta(z,y) $$\n$$=> \\mu(x,y) = -1\\sum_{x \\le z < y} \\mu(x,z) (0) $$\n(Since, zeta function ($\\zeta$) is $0$ for $x$ and $y$ which are incomparable)\n$$=> \\boxed{\\mu(x,y) = 0}$$\n\n\\noindent \\underline{For $x \\le y$},\n$$g(x,y) = \\mu(x,y) = \\frac{-1}{\\zeta(y,y)}\\sum_{x \\le z < y} \\mu(x,z) \\zeta(z,y)$$\n$$=> \\mu(x,y) = -1\\sum_{x \\le z < y} \\mu(x,z) \\zeta(z,y) $$\n$$=> \\mu(x,y) = -1\\sum_{x \\le z < y} \\mu(x,z) (1) ~~~~(\\textrm{Since}~~ \\zeta(z,y) = 1 ~ \\textrm{for} ~z < y)$$\n$$=> \\boxed{\\mu(x,y) = -\\sum_{x \\le z < y} \\mu(x,z)}$$\n\nHence, Mobius Function is defined as\n\n\\begin{equation}\n\\mu (x, y) =  \n    \\begin{cases}\n    &-\\sum\\limits_{x \\le z < y} \\mu(x,z) ~~~~~~~~~~~~~~~~~~~~~\\textrm{if} ~~x < y \\\\\n    &1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\textrm{if} ~~ x=y \\\\\n    &0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\textrm{if x and y are incomparable i.e.} ~~ x ~||~ y\\\\\n    \\end{cases}\n\\end{equation}\n\n\n\\noindent Now, Let's consider an example of Divisibility Poset and apply the mobius function on it, \n\n\\begin{center}\n\n\\begin{tikzpicture}[auto, node distance=2cm, every loop/.style={}, thick,main node/.style={circle,draw,font=\\sffamily\\Large\\bfseries}]\n\n\\node[main node] (1) {90};\n\\node[main node] (2) [below left of=1] {30};\n\\node[main node] (3) [right of=2] {45};\n\\node[main node] (4) [right of=3] {18};\n\\node[main node] (5) [below left of=2] {10};\n\\node[main node] (6) [right of=5] {15};\n\\node[main node] (7) [right of=6] {6};\n\\node[main node] (8) [right of=7] {9};\n\\node[main node] (9) [below right of=5] {5};\n\\node[main node] (10) [right of=9] {2};\n\\node[main node] (11) [right of=10] {3};\n\\node[main node] (12) [below left of=11] {1};\n\n\n\\path[every node/.style={font=\\sffamily\\small}]\n    (1) edge node [] {} (4)\n        edge node [] {} (3)\n        edge node [] {} (2)\n    (2) edge node [] {} (5)\n        edge node [] {} (6)\n        edge node [] {} (7)\n    (3) edge node [] {} (6)\n        edge node [] {} (8)\n    (4) edge node [] {} (7)\n        edge node [] {} (8)\n    (5) edge node [] {} (9)\n        edge node [] {} (10)\n    (6) edge node [] {} (9)\n        edge node [] {} (11)\n    (7) edge node [] {} (10)\n        edge node [] {} (11)\n    (8) edge node [] {} (11)\n    (9) edge node [] {} (12)\n    (10) edge node [] {} (12)\n    (11) edge node [] {} (12);\n\n\\end{tikzpicture}\n    \n\\end{center}\n\n\\begin{align*}\n\\textrm{For} ~~(x,y) = (1,1),\\\\\n    \\mu (x,y) &= \\mu (1,1)\\\\\n=>  \\mu (1,1) &= 1~~~~~~~~~~~(\\because x = y)\\\\\\\\\n\\textrm{For} ~~(x,y) = (1,2),\\\\\n    \\mu (x,y) &= \\mu (1,2)\\\\\n=>  \\mu (1,2) &= -\\sum\\limits_{1 \\le z < 2} \\mu(1,z)    ~~~~~~~\\textrm{(By definition of mobius function)}\\\\\n    &= - \\mu(1,1)\\\\\n=>  \\mu(1,2) &= -1\\\\\\\\\n\\textrm{Similarly for} ~~(x,y) = (1,3),\\\\\n=> \\mu(1,3) &= -1\\\\\\\\\n\\textrm{Similarly for} ~~(x,y) = (1,5),\\\\\n=> \\mu(1,5) &= -1\\\\\n\\end{align*}\n\nThus, In general for a prime number $p$,\n\n$$\\mu(1,p) = -1$$\n\nNow,\n\\begin{align*}\n\\textrm{For} ~~(x,y) = (1,10),\\\\\n    \\mu (x,y) &= \\mu (1,10)\\\\\n=>  \\mu (1,10) &= -\\sum\\limits_{1 \\le z < 10} \\mu(1,z)    ~~~~~~~\\textrm{(By definition of mobius function)}\\\\\n    &= - (\\mu(1,1) + \\mu(1,2) + \\mu(1,5)) \\\\\n=>  \\mu(1,10) &= 1\\\\\\\\\n\\textrm{Similarly for} ~~(x,y) = (1,15),\\\\\n=> \\mu(1,15) &= 1\\\\\\\\\n\\textrm{Similarly for} ~~(x,y) = (1,6),\\\\\n=> \\mu(1,6) &= 1\\\\\n\\end{align*}\n\nThus, In general for prime numbers $p$ and $q$ ,\n\\begin{eqnarray*}\n\\mu(1,p q) & = & -(\\mu(1,1) + \\mu(1,p) + \\mu(1,q)) \\\\\n\\implies \\mu(1,p q) & = & 1  \n\\end{eqnarray*}\n\n\\noindent Now,\n\\begin{align*}\n\\textrm{For} ~~(x,y) = (1,9),\\\\\n    \\mu (x,y) &= \\mu (1,9)\\\\\n=>  \\mu (1,9) &= -\\sum\\limits_{1 \\le z < 9} \\mu(1,z)    ~~~~~~~\\textrm{(By definition of mobius function)}\\\\\n    &= - (\\mu(1,1) + \\mu(1,3)) \\\\\n=>  \\mu(1,9) &= 0\\\\\n\\end{align*}\n\nThus, In general for a prime number $p$,\n$$\\mu(1,p^2) = 0$$\n\n\\noindent Now,\n\\begin{align*}\n\\textrm{For} ~~(x,y) = (1,45),\\\\\n    \\mu (x,y) &= \\mu (1,45)\\\\\n=>  \\mu (1,45) &= -\\sum\\limits_{1 \\le z < 45} \\mu(1,z)    ~~~~~~~\\textrm{(By definition of mobius function)}\\\\\n    &= - (\\mu(1,1) + \\mu(1,3) + \\mu(1,5) + \\mu(1,9) + \\mu(1,15)) \\\\\n=>  \\mu(1,45) &= 0\\\\\\\\\n\\textrm{Similarly for} ~~(x,y) = (1,18),\\\\\n=> \\mu(1,18) &= 0\\\\\n\\end{align*}\n\nThus, In general for prime numbers $p$ and $q$,\n\n\\begin{eqnarray*}\n\\mu(1,p^2 q) & = & -(\\mu(1,1) + \\mu(1,p) + \\mu(1,q) + \\mu(1,p q) + \\mu(1,p^2) ) \\\\\n\\implies \\mu(1,p^2 q) & = & 0\n\\end{eqnarray*}\n\n\\noindent Now,\n\\begin{align*}\n\\textrm{For} ~~(x,y) = (1,30),\\\\\n    \\mu (x,y) &= \\mu (1,30)\\\\\n=>  \\mu (1,30) &= -\\sum\\limits_{1 \\le z < 30} \\mu(1,z)    ~~~~~~~\\textrm{(By definition of mobius function)}\\\\\n    &= - (\\mu(1,1) + \\mu(1,3) + \\mu(1,5) + \\mu(1,2) + \\mu(1,6) + \\mu(1,10) + \\mu(1,15)) \\\\\n=>  \\mu(1,30) &= -1\\\\\n\\end{align*}\n\nThus, In general for prime numbers $p$, $q$ and $r$,\n\n\\begin{eqnarray*}\n\\mu(1,p q r) & = & -(\\mu(1,1) + \\mu(1,p) + \\mu(1,q) + \\mu(1,p q) + \\mu(1,q r) + \\mu (1, p r) ) \\\\\n\\implies \\mu(1,p q r) & = & 1\n\\end{eqnarray*}\n\nTherefore, in general, The mobius function for the divisibility poset turns out to be,\n\n\\begin{eqnarray*}\n\\mu (d)\n    \\begin{cases}\n        &= +1 ~~~~~~~~~~~~\\textrm{If $d$ is a product of even number of primes}\\\\\n        &= -1 ~~~~~~~~~~~~\\textrm{If $d$ is a product of odd number of primes}\\\\\n        &= 0 ~~~~~~~~~~~~~\\textrm{Otherwise}\\\\\n    \\end{cases}\n\\end{eqnarray*}\n\n\\section{Mobius Inversion theorem over Posets}\n\n\\textbf{Assumption :}\n\n\\noindent In the poset $X$, there is a unique $m$ such that $\\forall x \\in X$, $m \\le x$\n\n\\begin{theorem}\n\nFor a poset $X$, if $f$ is a function $f: X \\rightarrow \\mathbb{R}$ and $g$ is a function $g: X \\rightarrow \\mathbb{R}$ such that,\n$$\\forall a \\in X, ~~~~~~~~g(a) = \\sum_{x \\le a} f(x)$$ \nthen\n$$\\boxed{\\forall a \\in X, ~~~~~~~~f(a) = \\sum_{x \\le a} \\mu(x,a) g(x)}$$\nwhere $\\mu$ is the mobius function of the poset.\n\\end{theorem}\n\n\\begin{proof}\n\nAs from the assumption, let $m$ be the unique minimal element of the poset $X$.\n\n\\noindent And let $f$ and $g$ be the functions defined as above such that \n\n$$\\forall a \\in X, ~~g(a) = \\sum\\limits_{x \\le a} f(x)  ~~~~~~~~~(1)$$\n\n\\noindent Now, we define two functions $F(x,y)$ and $G(x,y)$ such that,\n\n\\begin{minipage}{0.48\\linewidth}\n\\begin{align*}\n   & \\forall a \\in X ,\\\\\n   & F(m,a) = f(a)\\\\\n   & G(m,a) = g(a)\\\\\n\\end{align*}\n\\end{minipage}\n\\begin{minipage}{0.48\\linewidth}\n\\begin{align*}\n   & \\textrm{For all other}~ x ~\\textrm{and} ~ y ~ \\textrm{where} ~ x \\ne m,\\\\\n   & F(x,y) = 0\\\\\n   & G(x,y) = 0\\\\\n\\end{align*}\n\\end{minipage}\n\n\\noindent Thus, By Incidence Algebra $F,G \\in A(P)$ for $P(X,\\le)$.\\\\\n\n\\noindent \\textbf{Claim :}\n$$\\boxed{G = F \\star \\zeta ~~\\textrm{where $\\zeta$ is the zeta function.}}$$\n\n\\noindent \\underline{Note:} Through this claim we can show that $F = G \\star \\mu$ (where $\\mu$ is the mobius function) and thus proving the theorem.\\\\\n\n\n\\noindent \\textbf{Proof for the claim :}\n\n\\noindent Consider $G(x,y)$,\n\n\\textbf{Case 1 : $\\forall a \\in X$}\n\\begin{align*}\n    G(m,a) &= g(a)\\\\\n    &= \\sum_{x \\le a} f(x) ~~~~~~~~~~~~~~~~ \\textrm{( $\\because~$ from (1))}\\\\\n    &= \\sum_{m \\le x \\le a} F(m,x) ~~~~~~~~ \\textrm{($\\because~$from definition of $F(x,y)$)}\\\\\n    &= \\sum_{m \\le x \\le a} F(m,x) \\zeta(x,a) ~~~~~~\\textrm{($\\because \\zeta (x,a) = 1, \\forall x \\le a$ )}\n\\end{align*}\n$$=> \\boxed{G(m,a) = F \\star \\zeta (m,a)} ~~~~~~~~~~~~ \\textrm{( $\\because~$ By defintion of convolution ($\\star$))}$$\n\n\\textbf{Case 2 :} For all other $x$ and $y$ where $x \\ne m$\n\\begin{align*}\n    G(x,y) &= 0\\\\\n    &= \\sum_{x \\le z \\le y} F(x,z) \\zeta(z,y) ~~~~~~\\textrm{($\\because F(x,z) = 0, \\forall x \\ne m$ )}\n\\end{align*}\n$$=> \\boxed{G(x,y) = F \\star \\zeta (x,y)} ~~~~~~~~~~~~ \\textrm{($\\because~$By defintion of convolution ($\\star$))}$$\n\n\\noindent Hence, The claim $G = F \\star \\zeta $ is true.\\\\\n\n\\noindent Thus, By definition\n$$\\boxed{F = G \\star \\mu}$$\n\n\\noindent Therefore, $\\forall a \\in X$,\n\\begin{align*}\n    F(m,a) &= \\sum_{m \\le x \\le a} G(m,x) \\mu(x,a) ~~~~~~~~ \\textrm{($\\because~$By defintion of convolution ($\\star$))}\\\\\n => f(a)  &=\\sum_{x \\le a} g(x) \\mu(x,a) ~~~~~~~~ \\textrm{($\\because~$From defintion of $F(m,a) = f(a), G(m,x) = g(x)$)}\n\\end{align*}\n\n\\noindent Thus,\n$$\\forall a \\in X, ~~~~~~~~f(a)  = \\sum\\limits_{x \\le a} \\mu(x,a) g(x)$$\n\nHence Proved.\n\n\\end{proof}\n\n\\subsection{Corollary}\n\n\\noindent \\underline{\\textbf{Application of Mobius Inversion theorem on Subset Poset}}\\\\\n\n\\noindent For the subset poset we will show, if $f$ and $g$ are functions defined from subsets to real numbers (i.e. \n$f: 2^{[n]} \\rightarrow \\R$ , $g: 2^{[n]} \\rightarrow \\R $ ) such that\n$$\\forall A \\subseteq [n], ~~~~~ g(A) = \\sum_{S \\subseteq A} f(S) $$\nthen\n$$\\boxed{\\forall A \\subseteq [n], ~~~~~ f(A) = \\sum_{S \\subseteq A} (-1)^{|A|- |S|}g(S) } $$\n\n\\noindent \\textbf{Claim :} For $X \\subseteq [n]$ and $Y \\subseteq [n]$,\n$$ \\mu (X,Y) = \n\\begin{cases}\n    &0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\textrm{if $~X \\nsubseteq Y$}\\\\\n    &(-1)^{|Y| - |X|} ~~~~~~~~~~\\textrm{if $~X \\subseteq Y$}\\\\\n\\end{cases}\n$$\n\\underline{\\textsf{Note :}} If we prove the claim to be true then the above subset poset can directly be shown as a corollary of the mobius inversion theorem by substituting the value of $\\mu$.\\\\\n\n\\noindent \\textbf{Proof for the claim :} \n\n\\noindent We will apply Induction on $|Y|-|X|$ for $X \\subseteq Y$.\\\\\n\n\\noindent \\underline{Base step}, For $|Y| - |X| = 0$ i.e. $X = Y$\n\\begin{align*}\n    \\mu (X,Y) &= \\mu(X,X)\\\\\n    => \\mu (X,Y) &= 1  ~~~~~~~~~~\\textrm{($\\because X \\subseteq X ~$ and $~\\mu (X,X) = 1$ )}\\\\\n    => \\mu (X,Y) &= (-1)^{0} = (-1)^{|Y| - |X|}\n\\end{align*}\n\n\\noindent \\underline{Induction step}, Assume it's true for $|Y| - |X| \\le k$. Now, we need to prove it's also true for $|Y| - |X| = k + 1$.\\\\\n\n\\noindent Thus, Consider $\\mu (X,Y)$ for $|Y| - |X| = k + 1$,\n\\begin{align*}\n    \\mu (X,Y) &= - \\sum_{X \\subseteq Z \\subset Y} \\mu (X,Z) ~~~~~~~~~~~~~\\textrm{($\\because X < Y~$ and by definition of mobius function )}\\\\\n => \\mu (X,Y) &= - \\sum_{X \\subseteq Z \\subset Y} (-1)^{|Z|-|X|} ~~~~~~~\\textrm{($\\because |Z| - |X| \\le k~$ and it's assumed true for $|Y| - |X| \\le k$)}\\\\\n => \\mu (X,Y) &= - \\sum_{X \\subseteq Z \\subseteq Y} (-1)^{|Z|-|X|} + (-1)^{|Y| - |X|} ~~~~~~~\\textrm{($\\because~$Adding and subtracting the subset $Y$)}\n\\end{align*}\n$$=> \\boxed{\\mu (X,Y) = - \\sum_{X \\subseteq Z \\subseteq Y} (-1)^{|Z|-|X|} + (-1)^{|Y| - |X|}} ~~~~~~\\textrm{(1)}$$\n\n\\noindent Now, we will show that 1st term in the R.H.S goes to 0 by using a combinatorial argument.\\\\\n\n\\noindent So, For given $X, Y \\subseteq [n]$ and $X \\subseteq Y$,\n\\begin{align*}\n    \\sum_{X \\subseteq Z \\subseteq Y} (-1)^{|Z|-|X|} &= \\sum_{k} \\sum_{\\substack{X \\subseteq Z \\subseteq Y\\\\ |Z| - |X| = k}} (-1)^k ~~~~~\\textrm{(By rewriting the summation based on the size of $|Z| - |X|$)}\\\\\n    &= \\sum_{k} (-1)^k {n \\choose k} ~~~~~~~~~\\textrm{($\\because~$ Number of ways of choosing such a subset $|Z|$ is ${n \\choose k}$) }\\\\\n    &= 0 ~~~~~~~~~~~~~~~~~~~~~~~~~~\\textrm{($\\because ~$ Signed summation of binomial coefficients is $0$)}\\\\\n=> \\sum_{X \\subseteq Z \\subseteq Y} (-1)^{|Z|-|X|} &= 0\\\\\n\\end{align*}\nTherefore, Equation (1) becomes,\\\\\n\n$$\\mu (X,Y) = (-1)^{|Y|-|X|}$$\n\nHence Proved.\\\\\n\n\\noindent Thus, from this definition of $\\mu$ and the theorem of Mobius Inversion, the corollary on the subset poset follows that ,\\\\\n\n\\noindent \\textbf{Corollary :} If $f$ and $g$ are functions defined from subsets to real numbers (i.e. \n$f: 2^{[n]} \\rightarrow \\R$ , $g: 2^{[n]} \\rightarrow \\R $ ) such that\n$$\\forall A \\subseteq [n], ~~~~~ g(A) = \\sum_{S \\subseteq A} f(S) $$\nthen\n$$\\forall A \\subseteq [n], ~~~~~ f(A) = \\sum\\limits_{S \\subseteq A} (-1)^{|A|- |S|}g(S)$$\n\n\n\\Lecture{Jayalal Sarma}{ 19 November, 2020}{34}{More Applications of Structure of Partial Orders, Fixed Point Theorems}{Kaushik Arcot, Abhishek Aladahalli}{$\\alpha$}{JS}\n\n\\section{Equinumerous Sets and Bijections}\n\nWe define Cardinality using the concept of Bijections and Equinumerous sets.\n\\begin{theorem}\nTwo sets A, B are equinumerous or equal in cardinality iff there\nexists a bijection $f: A \\to B$. Or,\\\\\n\n$ |A| = |B| \\Leftrightarrow \\exists$ bijection $f:A \\to B $ \\\\\n\n\\end{theorem}\n\n\\textbf{Example of Equinumerous sets and Bijections}\\\\\n\n\\textbf{Even Numbers and $\\mathbb{N}$}\\\\\n\n$f:\\mathbb{E} \\to \\mathbb{N}$,  $f(x) = x/2$\n\nIs a bijection from even numbers to Natural Numbers.\\\\\n\nThe Noton of Cardinality arises from the fact that these Equinumerous sets divide the Subset Partial Order into different equivalence classes and each of those classes correspond to different cardinalities. \\\\\n\nSo to prove that two sets are equinumerous sets, we need to prove there exists a bijection between the two sets. To prove that there exists a bijection between two sets, we can just prove that there exists an injection in both directons.\n\n\\begin{theorem}[Cantor Schroeder Bernstein Theorem]\n$A,B \\subseteq U$ ,$\\exists f:A \\to B, g:B \\to A$ are injections $\\implies \\exists h:A \\to B$ which is a bijection \n\\end{theorem}\n\nThis theorem is intuitive in finite sets, but to prove for infinite sets, we need some more tools that concern posets and cardinality.\n\n\\section{Knaster-Tarski Fixed point theorem}\n\nTo prove this theorem, we need to understand some properties.\n\n\\textbf{Fixed Point of a Function}\\\\\nLet $f: X \\to X$, be a function. Then, a point $x \\in X$, is said to be a fixed point of function $f$ if $f(x) = x$.\n\n\\textbf{Preserving Order of Posets}\n\nLet $P(X,\\le)$ be a poset. Then any function $f: X \\to X$ is said to preserve order if \n$$ \\forall x,y \\in X, x \\le y \\implies f(x)  \\le f(y) $$\n\n\\textbf{Upper Bound of a Set}\n\nLet $P(X,\\le)$ be a poset, and $A \\subseteq X$, then the upper bound of set A is defined as \n\n$$ UB(A) = \\{x \\in X | \\forall y \\in A, y \\le x\\} $$\n\n\\textbf{Least Upper Bound of a Set}\n\nLet $P(X,\\le)$ be a poset, and $A \\subseteq X$, then the least upper bound of set A is defined from the upper bound set, as the least element in the upper bound set of A.\n\n$$ LUB(A) = \\{x  | \\forall y \\in UB(A), x \\le y\\} $$\n\n\\textbf{Complete Partial Order}\n\nA partial order $P(X,\\le)$ is set to be a complete partial order, if $\\forall A \\subseteq X$ , $\\exists LUB(A)$\n\n\\medskip\n\n\nWe can understand the notion of a complete partial order using the subsets partial order. Let $P(X,\\le)$, be the subsets partial order, where $X = 2^{[n]}$. Then, let $A \\subseteq X$, be a subset of X, which is a set of subsets of $[n]$. Assume, $A = \\{A_1,A_2,...A_k\\}$, and S =  $\\bigcup_{i=1}^{k} A_{i}$ forms the LUB of the set A. We know that $\\forall i \\in [k], A_i \\le S$, (because $A_i$ is a subset of S, S is the union of all $A_i$'s). And it is the lowest upper bound, as any element missing from $S$, will be present in one of the $A_i$'s.\n\nNow, we're ready to prove the Knaster-Tarski Theorem.\n\n\\begin{theorem}[Knaster-Tarski Fixed point theorem]\nLet $P(X,\\le)$ be a complete partial order, and let $f: X \\to X$, be a function that preserves the order on the partial order P. Then $f$ has a fixed point.\n\\end{theorem}\n\n\\begin{proof}\nConsider the set $A = \\{x | x \\le f(x)\\}$. Assume that A is non-empty. This is possible when X has a least element in P. Then, for that least element $x \\in X$, $\\forall y \\in X, x \\le y$. And $f(x) \\in X$, thus, $x \\le f(x)$, and therefore $x \\in A$. \\\\\n\n\\textbf{Observation} If $x \\in A$, then $f(x) \\in A$. \\\\\n$x \\in A$. $\\implies x \\le f(x)$. As f preserves order,\\\\\n$ \\implies f(x) \\le f(f(x) $. Let f(x) = z, then \\\\\n$z \\le f(z)$. Thus, $z \\in A$. $\\implies f(x) \\in A$.\\\\\n\nSince the partial order is complete, and $A \\subseteq X$, there exists an LUB(A). Let\n\n$$ y = LUB(A)$$\n\nConsider, $\\forall x \\in A$. As y is LUB,\\\\\n$x \\le y$ , As f preserves order\\\\\n$ f(x) \\le f(y) $. Becasue $x \\in A$, \\\\\n\n$x \\le f(x) \\le f(y), \\forall x \\in A$ \\\\\n\nThis implies that $f(y)$ is an upper bound of A. Since $y$ is the LUB of A,\n$$y \\le f(y) $$\n\nBy the property of A, it is clear that $y \\in A$. And because $y \\in A$, and from the observation proven above, we have that $f(y) \\in A$. \\\\\n\nSince $f(y) \\le A$, and y is LUB(A) of A, we have that\n$$ f(y) \\le y $$\n\nSo, we have,\n$$ f(y) \\le y \\And y \\le f(y) $$.\n\nBy the anti-symmetry of the relation $\\le$ in the partial order, we have \n$$f(y) = y $$\n\nSo, we have $y$ as the fixed point.\\\\\n\nHence proved.\n\n\\end{proof}\n\n\n\\section{Cantor-Schroeder-Bernstein Theorem}\n\n\\begin{theorem}[Cantor Schroeder Bernstein Theorem]\n$A,B \\subseteq U$ ,$\\exists f:A \\to B, g:B \\to A$ that are injections $\\implies \\exists h:A \\to B$ which is a bijection.\n\\end{theorem}\n\n\\begin{proof}\n\nWe find a $H \\subseteq A$, and we build a function h, such that\n$$ h |_H = f \\And h|_{\\bar H} = g $$\n\nThen, we prove that H is a bijection.\n\n\\textbf{Claim} For $H \\subseteq A$, if $g( \\bar{f(H)} ) = \\bar H$ then by  the above definition, h is a bijection. \\\\\n\nOr, we have to find an H such that $H = \\bar{g(\\bar{f(H)})}$ \\\\\n\n\nFirst, we find an H such that this claim is satisfied, and then we prove the claim. \\\\\n\nWe define the following function on the subset partial order of A.\\\\\n\n$\\tau : 2^{[A]} \\to 2^{[A]}$, such that for any $T \\subset A$,\n\n$$ \\tau(T) = \\bar{g(\\bar{f(T)})}$$\n\nWe will prove the properties of preserving order and completeness of this Partial Order. \\\\\n\nWe know that the partial order is complete, as it is a subset poset. \\\\\n\nFor preserving order, assume $S \\subset T$. . By applying f on both sides, we have $f(S) \\subset f(T)$. \\\\\n\nTaking complement, we have $\\bar{f(T)} \\subset \\bar{f(S)}$.\\\\\n\nAs g is a function from B to A, and $f(x) \\in B \\forall x \\in A$, applying g on both sides, we get \\\\\n\n$$ g(\\bar{f(T)}) \\subset g(\\bar{f(S)})$$\n\nAgain taking complement, we get \n\n$$ \\bar{g(\\bar{f(S)})} \\subset \\bar{g(\\bar{f(T)})} $$\n\nSo, $\\tau(S) \\subset \\tau(T)$. Hence $\\tau$ preserves order.\\\\\n\nBecause $\\tau$ preserves order and and $P = ([A],\\le)$ is a complete poset, we have that there exists a fixed point for $\\tau$. Therefore\n\n$$ \\exists H \\subset A, \\bar{g(\\bar{f(H)})} = H $$\n\nNow that we have arrived at an H, we now need to prove that $h$ is a bijection. We need to prove three parts. \\\\\n\n\\textbf{Well-defined} \\\\\nh is well defined. $\\forall x \\in A$, if $x \\in H$, the output of $h$ is f(x). Otherwise, as $g$ is injective, and $\\bar H = g(\\bar{f(H)})$, and so $\\bar H \\subseteq g(B)$, and $g^{-1}(x)$ is defined $\\forall x \\in g(B)$, and subsequently in $\\bar H$. So $\\forall x \\in A$, h(x) is well defined.\n\n\\textbf{Injective}\\\\\nWe need to prove $\\forall x,y \\in A$, $x \\ne y \\implies h(x) \\ne h(y)$.\n\n\\textsf{Case 1} : $x \\in H \\And y \\in H$\\\\\n\n$\\forall x \\in H$, $h(x) = f(x)$. Therefore, $x \\ne y \\implies f(x) \\ne f(y) \\implies h(x) \\ne h(y) $\n\n\n\\textsf{Case 2}: $x \\in \\bar H \\And y \\in \\bar H$\n\n$\\forall x \\in \\bar H$, $h(x) = g^{-1}(x)$.  Since g is injective, $g^{-1}$  is well-defined, and thus $g^{-1}(x) \\ne g^{-1}(y) \\implies h(x) \\ne h(y)$\n\n\\textsf{Case 3} : $x \\in H \\And y \\in \\bar H$\nFor $x \\in H$, $h(x) = f(x)$\\\\\nFor $y \\in \\bar H$, $h(y) = g^{-1}(y)$ \\\\\n\nWe need to prove $h(x) \\ne g^{-1}(y)$ \\\\\n\nWe know, $g(\\bar{f(H)}) = \\bar H $. As $g^{-1}$ is well defined, $\\implies g^{-1}(\\bar H) \\subseteq \\bar{f(H)}$ \\\\. Therefore, $g^{-1}(H) \\nsubseteq f(H)$. Moreover, as $g^{-1}(\\bar H) \\subseteq \\bar{f(H)}$, $ \\nexists u \\in \\bar H$, such that $g^{-1}(u) \\in f(H)$.\nThus, for $x \\in H \\And y \\in \\bar H$, $g^{-1}(y) \\ne f(x)$. Hence proved.\n\n\\textbf{Surjective} \\\\\nTo prove, $range(h) = B$. That is, $\\forall y \\in B, \\exists x \\in A$, such that $h(x) = y$. Assume, $y \\in f(H)$. Given that $\\forall x in H, h(x) = f(x)$, and because $y \\in f(H)$, $\\exists x, f(x) = y$.\n\nNow, for $x \\in \\bar{f(H)}$. We know,\n\n\\begin{equation} \\label{eqn:1} \\bar H = g(\\bar{f(H)}) \\end{equation}\n\nAnd that $g^{-1}(x)$ is defined $\\forall x \\in \\bar H$ (already proved). Since $g^{-1}$ is obviously injective ( if $x \\ne y$ and  $g^{-1}(x) = g^{-1}(y) = a$, then $g(a)$ is not defined), we can apply $g^{-1}$ on both sides of \\ref{eqn:1}, to get \n\n$$ g^{-1}(\\bar{H}) \\subseteq \\bar{f(H)}$$\n\nAs $g{-1}$ is injective, and we know that $|\\bar H| = g(\\bar{f(H)})$, both the sets are of the same size, thus,\n$$ g^{-1}(\\bar H) = \\bar{f(H)}$$.\n\n$\\forall x \\in \\bar{f(H)}$, we have a pre-image in $g^{-1}(\\bar H)$. Hence, h is surjective.\n\nFrom the three parts, we have proven that $h : A \\to B$, is a bijective function, constructed from $f : A \\to B$ and $g : B \\to A$, two injective functions.\n\n\\end{proof}\n", "meta": {"hexsha": "5c1a9db8da8cb1fa48848203caf5b8b9570bec3e", "size": 28347, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week11.tex", "max_stars_repo_name": "jayalalsarma/theory-toolkit", "max_stars_repo_head_hexsha": "41d72c3bbe6bfdb0720801d220e210b9c77a1300", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week11.tex", "max_issues_repo_name": "jayalalsarma/theory-toolkit", "max_issues_repo_head_hexsha": "41d72c3bbe6bfdb0720801d220e210b9c77a1300", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-10-08T07:34:26.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-30T06:06:12.000Z", "max_forks_repo_path": "week11.tex", "max_forks_repo_name": "jayalalsarma/theory-toolkit", "max_forks_repo_head_hexsha": "41d72c3bbe6bfdb0720801d220e210b9c77a1300", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2020-09-25T01:35:07.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-28T11:22:06.000Z", "avg_line_length": 38.8847736626, "max_line_length": 550, "alphanum_fraction": 0.578967792, "num_tokens": 10905, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7314787003193014}}
{"text": "\\subsection{T-Hat $\\left(\\hat{T}\\right)$}\r\nArc length parameterization gives us another way to find $\\hat{T}$.\\\\\r\n\\begin{equation*}\r\n\t\\hat{T} = \\frac{\\vec{r^\\prime}(t)}{\\norm{\\vec{r^\\prime}(t)}} = \\frac{\\mathrm{d}\\vec{r}/\\mathrm{d}t}{\\mathrm{d}s/\\mathrm{d}t} = \\frac{\\mathrm{d}\\vec{r}}{\\mathrm{d}s}\r\n\\end{equation*}", "meta": {"hexsha": "a3e7b3d9930a0417ce999b7a5a485b9a9fdaf4ee", "size": 315, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorValuedFunctions/tHat.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorValuedFunctions/tHat.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorValuedFunctions/tHat.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 63.0, "max_line_length": 166, "alphanum_fraction": 0.6253968254, "num_tokens": 122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8289388062084421, "lm_q1q2_score": 0.7314786970577588}}
{"text": "\\section{DT LTI -- transfer function and block diagrams}\n\n\\subsection{}\n\n\\begin{frame}\n\\frametitleTC{Preliminary}\n\\framesubtitleTC{for an alternative system representation, particularly useful for control}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item Let us introduce the \\TC{one-step advance operator} $z$:\n       \\begin{displaymath}\n        z\\nu(k) := \\nu(k+1) \\qquad\\qquad \\text{whatever $\\nu$ is}.\n       \\end{displaymath}\n \\item This allows for a compact way to write LTI systems without evidencing the state (but it is there!).\n \\item Suppose for example that we have a system with input $u$ and output $y$, ruled by\n       \\begin{displaymath}\n        y(k) = ay(k-1)+bu(k-1),\n       \\end{displaymath}\n       where clearly the state is the previous value of $y$;\n \\item we can re-write $y(k+1)=ay(k)+bu(k)$ in the form\n       \\begin{displaymath}\n        (z-a)y(k) = bu(k).\n       \\end{displaymath}\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Preliminary}\n\\framesubtitleTC{introducing the transfer function}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item Rearranging -- remember the \\emph{operatorial} meaning of $z$ -- we get\n       \\begin{displaymath}\n        y(k) = \\frac{b}{z-a}u(k)\n       \\end{displaymath}\n\\item[] and we can define the \\TC{Transfer Function (TF)} notation, that expresses the system\\\\\n        as a compound operator built upon the elementary one $z$:\n       \\begin{itemize}[<+-| alert@+>]\n       \\item we write the system's transfer function $G(z)$ as\n             \\begin{displaymath}\n               G(z) = \\frac{b}{z-a},\n             \\end{displaymath}\n       \\item[] and in force of this\n             \\begin{displaymath}\n              y(k) = G(z)u(k) \\quad \\text{means} \\quad y(k) = ay(k-1)+bu(k-1).\n             \\end{displaymath}\n       \\end{itemize}\n \\item \\vfill May not look so useful at the moment, but you will see later on\\\\\n       how handy transfer functions are to determine controllers.\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{State space representation and transfer function}\n\\framesubtitleTC{}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item Given the SS representation we saw, shift all times by one (which is legit as the system is TI):\n       \\begin{displaymath}\n        \\left\\{\n         \\begin{array}{rlll}\n          x(k+1) &= A x(k)   + b u(k)\\\\\n          y(k+1) &= c x(k+1) + d u(k+1) \n         \\end{array}\n        \\right.\n       \\end{displaymath} \n \\item Apply the advance operator:\n       \\begin{displaymath}\n        \\left\\{\n         \\begin{array}{rl}\n          \\textcolor{red}{z}x(k) &= A x(k) + b u(k)\\\\\n          \\textcolor{red}{z}y(k) &= c \\textcolor{red}{z}x(k) + d\\textcolor{red}{z} u(k)\n         \\end{array}\n        \\right.\n       \\end{displaymath} \n \\item Drop useless $z$'s and rearrange ($I$ is identity matrix of dimension $n$):\n       \\begin{displaymath}\n        \\left\\{\n         \\begin{array}{rl}\n          (zI-A)x(k) &= b u(k)\\\\\n          y(k)       &= c x(k) + d u(k)\n         \\end{array}\n        \\right.\n       \\end{displaymath} \n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{State space representation and transfer function}\n\\framesubtitleTC{once again, sticking to the SISO case}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item Solve state equation for $x(k)$:\n       \\begin{displaymath}\n        x(k) = (zI-A)^{-1} b u(k)\n       \\end{displaymath} \n \\item Substitute into output equation and rearrange:\n       \\begin{displaymath}\n        y(k) = \\textcolor{red}\n                         {\\underbrace{\\left[c(zI-A)^{-1} b +d \\right]}\n                                    _{\\text{Transfer function } G(z)}\n                         } \\; u(k)\n       \\end{displaymath} \n \\item We then define the transfer function of the generic SISO DT LTI\\\\\n       system $(A,b,c,d)$ as\n       \\begin{displaymath}\n        G(z) = c(zI-A)^{-1} b +d.\n       \\end{displaymath} \n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Block diagrams}\n\\framesubtitleTC{Preliminaries}\n\\myPause\n\\begin{itemize}[<+-| alert@+>]\n\\item Block diagrams (BDs) are a graphical formalism to represent dynamic systems, that we see here limited to the\n      DT LTI class.\n\\item They are useful to study \\TC{interconnected} systems, i.e., compounds of \\TC{subsystems} (e.g., a controller\n      and the controlled object).\n\\item Important \\emph{caveat}, that we state right from the beginning:\n      \\begin{itemize}[<+-| alert@+>]\n      \\item    a BD MUST NOT BE CONFUSED with a flow diagram;\n      \\item [] although subsystems have inputs and outputs,\n      \\item [] their compound comes from assembling \\TC{equations}.\n      \\end{itemize}\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Block diagram components}\n\\framesubtitleTC{Block and summation node}\n\\myPause\n\\begin{center}\n \\input{./Unit-02/img/BlockTF.tex}\n\\end{center} \\myPause\n\\begin{itemize}[<+-| alert@+>]\n\\item \\TC{Block} (left):\\\\\n      an LTI SISO system with the indicated transfer function -- in the shown\\\\\n      example, the \\TC{equation} $G(z)u(k)-y(k)=0$.\n\\item \\TC{Summation node} (right):\\\\\n      a summation expression -- in the shown example, the \\TC{equation}\n      $u_1(k)-u_2(k)+u_3(k)-y(k)=0$.\n\\end{itemize}\n\\end{frame}\n\n", "meta": {"hexsha": "817edaa85f7a26387d8efdebb7c369583a6d5664", "size": 5174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/Unit-02/sections/04-DTLTI-TF-BD.tex", "max_stars_repo_name": "albertoleva/PID4CSE", "max_stars_repo_head_hexsha": "66ec14c204e16c97a5792c2e240b2daed4b39e83", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-19T16:38:10.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-19T16:38:10.000Z", "max_issues_repo_path": "slides/Unit-02/sections/04-DTLTI-TF-BD.tex", "max_issues_repo_name": "albertoleva/PID4CSE", "max_issues_repo_head_hexsha": "66ec14c204e16c97a5792c2e240b2daed4b39e83", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slides/Unit-02/sections/04-DTLTI-TF-BD.tex", "max_forks_repo_name": "albertoleva/PID4CSE", "max_forks_repo_head_hexsha": "66ec14c204e16c97a5792c2e240b2daed4b39e83", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.1972789116, "max_line_length": 114, "alphanum_fraction": 0.6119056823, "num_tokens": 1575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7314786965902078}}
{"text": "\\documentclass{article} \n\n% include some useful things\n\\usepackage{verbatim}  % for printing unformatted text\n\\usepackage{float}         % for controlling the location of figure and graphics on the page\n\\usepackage{blindtext}\n\\usepackage{graphicx}\\usepackage{amsmath}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n%  Begin writing content below this line\n\\begin{document}\n\n%  Print your name and the assignment number\n\\begin{center}{\\huge  Deepayan Bhadra - hmwk2 Solutions}\\end{center}\n\n\\section*{Solution to Q1(a) to create a classification}\n% The verbatim environment is good for reproducing text without having latex try to format it for you.\n\\begin{verbatim}\n\ndef create_classification_problem(Nd,Nf,kappa):\n    D = buildmat(Nd,Nf,kappa)\n    w = np.random.randn(Nf,1);\n    c = np.sign(D.dot(w));\n    flipper = np.ones((Nd,1)) - 2*(np.random.rand(Nd,1)>.9);\n    c = c*flipper;\n    return D,c\n\t    \n[ D,c ] = create_classification_problem(100, 2, 1)\nvalid1 = D[np.where(c==1)[0]]\nvalid2 = D[np.where(c==-1)[0]]\nplt.scatter(valid1[:, 0], valid1[:, 1])\nplt.scatter(valid2[:, 0], valid2[:, 1])\nplt.title(\"Scatter plot with condition no = 1\")\nplt.show()\n\n[ D,c ] = create_classification_problem(100, 2, 10)\nvalid1 = D[np.where(c==1)[0]]\nvalid2 = D[np.where(c==-1)[0]]\nplt.scatter(valid1[:, 0], valid1[:, 1])\nplt.scatter(valid2[:, 0], valid2[:, 1])\nplt.title(\"Scatter plot with condition no = 10\")\nplt.show()\n\n\\end{verbatim}\n\n\\section*{Solution to Q1(b) to evaluate logistic regression}\n\\begin{verbatim}\n\ndef logreg_objective(x,D,c):\n    z = np.diagflat(c).dot(D).dot(x)\n    idxN, idxP = z<0, z>=0\n    y1 = np.sum(-z[idxN]) + np.sum([math.log(np.exp(x)+1) for x in z[idxN]])\n    y2 = np.sum([math.log(1+np.exp(-x)) for x in z[idxP]])\n    y = y1+y2\n    return y\n\nNd, Nf, kappa = 1000,100,10\n[D,c] = create_classification_problem(Nd,Nf,kappa)\nx = np.random.randn(Nf,1);\n\nprint(\"The logistic regression objective is\")\ny = logreg_objective(x,D,c)\nprint(y)\n\ninput(\"Press Enter to continue...\")\n\nprint(\"The logistic regression objective for a large x is\");\nx = 10000*np.random.randn(Nf,1) \n#Calling on a large input to verify that we don't get any NaNs\ny = logreg_objective(x,D,c)\nprint(y)\n\ninput(\"Press Enter to continue...\")    \n\n\n\\end{verbatim}\n\n\\section*{Solution to Q2(a): to load the dataset}\n\\begin{verbatim}\n\ndef load_mnist():\n    import h5py\n    f = h5py.File(\"mnist.h5\")\n    x_test = f[\"x_test\"]\n    x_train = f[\"x_train\"]\n    y_test = f[\"y_test\"]\n    y_train = f[\"y_train\"]\n\n    with x_test.astype(\"float\"):\n        x_test = x_test[:]\n    with y_test.astype(\"float\"):\n        y_test = y_test[:]\n    with x_train.astype(\"float\"):\n        x_train = x_train[:]\n    with y_train.astype(\"float\"):\n        y_train = y_train[:]\n    return x_test,x_train,y_test,y_train\n\nx_test,x_train,y_test,y_train = load_mnist()\n\n\\end{verbatim}\n\n\\section*{Solution to Q2(b):to implement SoftPlus}\n\\begin{verbatim}\n\ndef softplus(X):\n    y = np.zeros(X.shape)\n    idxN, idxP = X<0, X>=0\n    xn,xp = X[idxN],X[idxP]\n    y[X<0] = [math.log(1+np.exp(x)) for x in xn]\n    y[X>=0] = xp+[math.log(np.exp(-x)+1) for x in xp];\n    return y\n\n\\end{verbatim}\n\\section*{Solution to Q2(c):to implement cross-entropy}\n\\begin{verbatim}\n\ndef cross_entropy(X,Y):\n    Xm = X - np.max(X,axis = 1, keepdims = True)\n    softmax = np.divide(np.exp(Xm),np.sum(np.exp(Xm),axis = 1,keepdims = True))\n    y = -math.log(np.mean(np.sum(softmax*Y,axis=1,keepdims = True)))\n    return y\n\n\\end{verbatim}\n\n\\section*{Solution to Q2(d): to implement neural  loss}\n\\begin{verbatim}\n\ndef net_objective(W,D,L):\n    temp = D\n    for i in range(0,len(W)):\n        temp = softplus(np.dot(temp,W[i]))\n    y = cross_entropy(temp,L);\n    return y\n\n\\end{verbatim}\n\n\\section*{Solution to Q2(e): to evaluate objective function on MNIST data}\n\n\\begin{verbatim}\n\nD = x_train \nW = [None] * 2\nW[0] = np.random.randn(784,100)\nW[1] = np.random.randn(100,10)\ny_train += np.ones((60000,))\n\n# One HOT Encoding \ns = pd.Series(y_train)\nL = pd.get_dummies(s).values\n\nprint(\"\"\"The objective value using the random weights and MNIST \n      training data is {r:5.3f}\"\"\".format(r=net_objective(W,D,L)))\n\ninput(\"Press Enter to continue...\")\n\n\\end{verbatim}\n\n\\section*{Solution to Q3(a): to compute image gradient}\n\n\\begin{verbatim}\ndef grad2d(X):\n    \n    # Computing the x-differences\n    kernel = np.zeros(X.shape)\n    kernel[0,0] = 1\n    kernel[0,1] = -1\n    Dx = np.fft.fft2(kernel)\n    Gx = np.fft.ifft2(Dx*np.fft.fft2(X))\n    \n    #Computing the y-differences\n    kernel = np.zeros(X.shape)\n    kernel[0,0] = 1\n    kernel[1,0] = -1\n    Dy = np.fft.fft2(kernel)\n    Gy = np.fft.ifft2(Dy*np.fft.fft2(X))\n    \n    return np.stack([Gx, Gy], axis=2)\n\\end{verbatim}\n\n\\section*{Solution to Q3(b): to compute (-ve) divergence}\n\n\\begin{verbatim}\ndef div2d(G):\n    # Computing the x-differences\n    #  extract the x- and y- derivatives\n    Gx = G[:,:,0]\n    Gy = G[:,:,1]\n    \n# We must convolve with the FLIPPED stencil to get the linear filtering we want \n    kernel = np.zeros(Gx.shape)\n    kernel[0,0]=1\n    kernel[0][-1] =-1\n    \n#  create diagonal matrix in decomposition K=F'DF\n    Dx = np.fft.fft2(kernel)\n    \n#  Use the eigen-decomposition to convolve the stencil with X, and get the\n#  differences in the horizontal direction.\n    Divx = np.fft.ifft2(Dx*np.fft.fft2(Gx))\n    \n    kernel = np.zeros(Gy.shape)\n    kernel[0,0]=1\n    kernel[-1][0]=-1\n    \n    Dy = np.fft.fft2(kernel)\n\n    Divy = np.fft.ifft2(Dy*np.fft.fft2(Gy))\n        \n    return Divx+Divy\n\\end{verbatim}\n\\section*{Solution to Q3(c): to verify adjointness using $<x,Ay> \\quad = \\quad <A'x,y>$ where A = G or d}\n\n\\begin{verbatim}\n\nprint('\\nTesting adjoints\\n')\n# random inputs\nx = np.random.randn(100,100);\ny = np.random.randn(100,100,2)\nAy = grad2d(y)\nx_Ay = np.sum(np.conj(x)*Ay)\n#  Compute Ax, where A is the gradient operator\nAx = grad2d(x)\n#  Compute Aty, where A is the gradient operator\nAty = div2d(y)\n\nleft = np.inner(Ax.flatten(),y.flatten(1))\nright = np.inner(x.flatten(),Aty.flatten(1))\nprint('first inner product = \\t',left,'\\n')\nprint('second inner product = \\t',right)\n\n\\end{verbatim}\n\n\\end{document}\n", "meta": {"hexsha": "21252d15982867031b3a5b48f7fbd11614b32e1e", "size": 6100, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework-2/hmwk2_results.tex", "max_stars_repo_name": "dbhadra/CMSC764-Advanced-Numerical-Optimization", "max_stars_repo_head_hexsha": "c2ba0ffc58fbb00df370bb03998277977cade1a4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Homework-2/hmwk2_results.tex", "max_issues_repo_name": "dbhadra/CMSC764-Advanced-Numerical-Optimization", "max_issues_repo_head_hexsha": "c2ba0ffc58fbb00df370bb03998277977cade1a4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework-2/hmwk2_results.tex", "max_forks_repo_name": "dbhadra/CMSC764-Advanced-Numerical-Optimization", "max_forks_repo_head_hexsha": "c2ba0ffc58fbb00df370bb03998277977cade1a4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.9574468085, "max_line_length": 105, "alphanum_fraction": 0.6514754098, "num_tokens": 1921, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.7314664045995243}}
{"text": "%!TEX root = kPtx_paper.tex\n\\section*{Theory}\n\n\\subsection*{k-Space-Domain Subproblems}\nWe propose to compute a sparse \ndesign matrix $\\bm{W}$ that directly maps the Fourier transform of a desired spatial \nexcitation pattern to a vector of RF pulses that together produce the pattern, as:\n\\begin{equation}\n\\bm{b} = \\bm{W} \\mathcal{F}(\\bm{d}),\n\\end{equation}\nwhere $\\bm{b}$ is a vector of concatenated multi-channel RF pulses with length $N_t  N_c$, \nwhere $N_t$ and $N_c$ are the numbers of time points and channels, respectively,\nand $\\mathcal{F}(\\bm{d})$ is a length-$N_s$ vector containing the \nFourier transform of the complex-valued target k-space excitation pattern $\\bm{d}$.\n$\\bm{W}$ has dimensions $N_t  N_c \\times N_s$.\nOnce the entries of $\\bm{W}$ are computed, \nthe RF design problem can be instantaneously solved by a sparse matrix multiplication. \n%without a full matrix inversion or an iterative algorithm. \nHere we describe how to break down the problem of constructing $\\bm{W}$ \ninto a set of smaller independent subproblems that can be solved in parallel. \n\n%Furthermore, in design problems involved iterative procedures, such as the phase updates in magnitude-least-squares pulse designs \\cite{setsompop2008magnitude} and the regularization factor updates in power/roughness constrained pulse design, the sparsity of the $\\bm{W}$ matrix makes the iterative process much more efficient in terms of memory and speed. In the work of Katscher et al \\cite{katscher2003transmit}, parallel transmit pulse design was also formulated in the k-space domain. However, in Ref \\cite{katscher2003transmit}, the matrix $\\bm{W}$ was solved as a whole, which required constructing and inverting a large $\\bm{S}^H\\bm{S}$ matrix, which will be explained in the following text. Our proposed method finely divides the process of finding $\\bm{W}$ into many independent instances, which allows the use of parallel computing to largely accelerate the computation. Furthermore, the $\\bm{S}^H\\bm{S}$ matrices of different instances are each small, and our proposed method efficiently constructs these matrices, which further accelerates the computation. \n\n\\par The columns of $\\bm{W}$ can be solved independently, \nbased on the observation that if the desired k-space pattern is a delta function at a k-space location \n$\\vec{k}_j$ ($1\\leq j \\leq N_s$), \nthen only the $j$-th column $\\bm{w}_j$ of $\\bm{W}$ is required to relate \nthe desired k-space pattern to the desired RF pulse. \nIn this case, the vector $\\bm{w}_j$ is identical to the desired RF. \nTherefore, the problem of finding the $j$-th column $\\bm{w}_j$ of $\\bm{W}$ can be stated as: \nwhat should the RF pulse samples be to generate a unit delta function at $\\vec{k}_j$, \nand zeros elsewhere? \nMathematically, the relationship that should be satisfied by the weights in column $\\bm{w}_j$  can be expressed as:   \n\\begin{equation}\\label{eq:ScalerForm}\n\\delta(\\vec{k}-\\vec{k}_j)=\\sum_{i=1}^{N_t}\\sum_{c=1}^{N_c} w_c(\\vec{k}_i) s_c(\\vec{k}-\\vec{k}_i),\n\\end{equation}\nwhere $i$ indexes time points in the pulses' excitation k-space trajectory, \nand $c$ indexes channels. \n$w_c(\\vec{k}_i)$ is the $((c-1)N_t+i)$-th element of the $\\bm{w}_j$ vector,\nand $s_c(\\vec{k}-\\vec{k}_i)$ is the Fourier transform of channel-$c$'s $B_1^+$ map, \nshifted to be centered at excitation k-space location $\\vec{k}_i$. \nEquation \\ref{eq:ScalerForm} can be restated in matrix-vector form as:                                       \n\\begin{equation}\\label{eq:MatrixForm}\n\\bm{Sw}_j=\\bm{e}_j,\n\\end{equation}\nwhere $\\bm{S}$ is a $N_s \\times N_c  N_t$ \nmatrix containing values of $s_c(\\vec{k}-\\vec{k}_i)$ for all $c$ and $i$,\nand $\\bm{e}_j$ is a vector containing a one in the entry corresponding to excitation k-space location\n$\\vec{k}_j$, and zeros in all other entries. \nThe regularized pseudoinverse solution for $\\bm{w}_j$ is:                      \n\\begin{equation}\\label{eq:Solution}\n\\bm{w}_j=\\left( \\bm{S}^{H} \\bm{S} + \\lambda \\bm{I} \\right) ^{-1} \\bm{s}_j^{H}\n\\end{equation}\nwhere $\\bm{s}_j^{H}$ is the conjugate transpose of the $j$-th row of $\\bm{S}$. \n\n\\par If all points on the excitation k-space trajectory are considered in Equation \\ref{eq:ScalerForm},\nthen there is no reduction in computation compared to a conventional pseudoinverse-based pulse design.\nHowever, because $B_1^+$ maps are localized near $\\vec{k} = 0$ in excitation k-space,\nonly a small number ($\\ll N_t$) of trajectory points near the target location $\\vec{k}_j$ can contribute significantly\nto the excitation pattern at $\\vec{k}_j$ or its neighbors, \nand therefore need to be considered in the subproblem;\nall other trajectory points can be ignored.\nThis means Equation \\ref{eq:ScalerForm} can be modified to:\n\\begin{equation}\n\\delta(\\vec{k}-\\vec{k}_j) = \\sum_{\\vec{k}_i \\in \\mathbb{N}}\\sum_{c=1}^{N_c} w_c(\\vec{k}_i) s_c(\\vec{k}-\\vec{k}_i),\n\\end{equation} \nwhere $\\mathbb{N}$ is the set of trajectory points in the vicinity of $\\vec{k}_j$. \nIn this work `inclusion width' is defined as the distance, \nin phase cycles over the excitation field-of-view (cycles/FOV), \nfrom each target location $\\vec{k}_j$ within which all trajectory points are accrued into $\\mathbb{N}$.\nThis reduced set of trajectory points reduces the column dimension of $\\bm{S}$\nand both dimensions of $\\bm{S}^H\\bm{S}$,\nand implies that the design matrix $\\bm{W}$ is sparse.\nFigure \\ref{fig:Patch}a illustrates a target point $\\vec{k}_j$ for a two-dimensional pulse design, \nand the nearby points on the trajectory that need to be included in the solution for $\\bm{w}_j$\nfor an inclusion width of 4 cycles/FOV.\n\n%\\par A key advantage of the proposed pulse design formalism is that it can be finely parallelized\n%across the columns of the $\\bm{W}$ matrix. \n\\par The $\\bm{W}$ matrix columns $\\bm{w}_j$ can be solved in parallel one-at-a-time or patch-wise, \nwherein all target points in a patch share the same $\\bm{S}^{H}\\bm{S}$ matrix,\nand their $\\bm{s}_j^H$ vectors are concatenated in the column dimension\nto form a matrix in Equation \\ref{eq:Solution}. \nAn illustration of a $4 \\times 4$ patch and its included trajectory points is shown in Figure \\ref{fig:Patch}b,\nfor a two-dimensional spiral pulse design. \nThe inclusion width is also 4 cycles/FOV from any target point in the patch, \n%we truncate the $B_1^+$ map Fourier transforms to zero outside a 4 by 4 cycle/FOV square centered at DC. \nso all the excitation trajectory points within a $12 \\times 12$ cycles/FOV square are included in the calculation. \n\n%Since target locations that are distant to $\\vec{k}_j$ can also be ignored,\n%the row dimension of $\\bm{S}$ is also reduced to the size of a smaller neighborhood immediately surrounding $\\vec{k}_j$. \n%These reduced problem dimensions further imply that the design matrix $\\bm{W}$ is sparse. \n%Figure \\ref{fig:Patch}a illustrates a target point $\\vec{k}_j$, \n%the nearby points on a spiral trajectory that need to be included in the solution for $\\bm{w}_j$,\n%and the neighboring target location points where a zero excitation must be enforced. \n%In the following, we define target and trajectory neighborhood sizes, \n%and describe an efficient method to construct the $\\bm{S}^{H}\\bm{S}$ matrices.\n\n\n\n\\subsection*{Efficient $\\bm{S}^H\\bm{S}$ matrix construction}\n%%which is 4 cycle/FOV extended outside of the patch width 4 square, since they may contribute energy to the target locations corresponding to the 16 $\\bm{W}$ matrix columns. \n%For the patch illustrated in Figure \\ref{fig:Patch}, \n%the 46 green points on the excitation trajectory may contribute significant energy and are considered in the weight design. \n%Furthermore, we must constrain the total excitation to zero at all k-space locations within a 20 by 20 cycle/FOV red patch in Figure \\ref{fig:Patch}. \n%This is because any energy deposited at each considered excitation trajectory points will affect not only the target points in the yellow square, but also the whole 2$\\times$4 wide patch around that trajectory point. And the 20 by 20 cycle/FOV red patch is the total of the points that can be affected by all the excitation trajectory points considered in this instance. Therefore, in the solution for this instance, $\\bm{w}$ is a 46$N_c\\times$16 matrix, $\\bm{S}$ is a 400$N_c\\times$46$N_c$ matrix, $\\bm{S}^{H}\\bm{S}$ is a 46$N_c\\times$46$N_c$ matrix, and $\\bm{s}_i^{H}$ is a 46$N_c\\times$16 matrix. \n%%Since $\\bm{s}_i^{H}$ is no longer related to the $i$th row of $\\bm{S}$ and $i$th column of $\\bm{W}$ only, it will be denoted as $\\bm{S_{targ}}$ in later discussions. \n%In the next instance, another 16 columns centered around another 4 points by 4 points patch will be solved. It should be noted that in different instances, the number of neighboring excitation trajectory points (the 46 green points in the previous instance) can vary. We will denote this number of points by $N_n$. $N_n$ can be zero when a patch is at the corners where no excitation trajectory point is adjacent. \n%%For patches near edges of the excitation k-space FOV, the solution neighborhood and area may wrap back in a circulant shift fashion, depending on the resolution of the final spatial grid on which the user will evaluate the pulse. In Figure \\ref{fig:Patch}), denoted by the red area to the right of Figure \\ref{fig:Patch}).\n\n%\\par The patch width determines the total number of instances to be solved. The inclusion width determines the accuracy of $B_1^+$ information utilized in the design. Together, the patch width and the inclusion width determine how many excitation trajectory points are included in each instance, which further determines the size of $\\bm{S}^{H}\\bm{S}$ whose construction is most computationally burdensome within an instance. Therefore, increasing patch width reduces the number of $\\bm{S}^{H}\\bm{S}$ matrices to be constructed but increases the burden of constructing each of them. An optimal patch width should be decided case by case for different excitation trajectories. \n\n%\\subsection*{Efficient construction of $\\bm{S}^{H}\\bm{S}$ matrix}\n\\par Constructing the $\\bm{S}^{H}\\bm{S}$ matrix by first constructing $\\bm{S}$ is computationally expensive \nbecause it requires each channel's $B_1^+$ map to be shifted to each trajectory location $\\vec{k}_i$\nby phase modulation followed by Fourier transform, or by Fourier transform followed by interpolation. \nFurthermore, \nthe matrix multiplication between $\\bm{S}^{H}$ and $\\bm{S}$ is also computationally intensive due to the potentially \nlarge row dimension of $\\bm{S}$, if the zero excitation condition is enforced on a large grid of points around each $\\vec{k}_j$.\nThe computational costs can be reduced by truncating the $B_1^+$ maps in k-space, \nbut this introduces large errors. \nInstead, inspired by the non-Cartesian GRAPPA method of Ref \\cite{luo2019grappa}, \nwe propose to construct the Hermitian $\\bm{S}^{H}\\bm{S}$ matrix directly via interpolation of the Fourier transforms\nof inner products of pairs of $B_1^+$ maps. \nThe $\\bm{S}^H\\bm{S}$ matrix can be written in block form as:\n\\begin{equation}\\label{eq:SHS_blocks}\n\\bm{S}^{H}\\bm{S} = \n\\begin{pmatrix}\n\\bm{S}_1^{H}\\bm{S}_1 & \\cdots & \\bm{S}_1^{H}\\bm{S}_{N_c} \\\\\n\\vdots  &  \\ddots & \\vdots  \\\\\n\\bm{S}_{N_c}^{H}\\bm{S}_1 & \\cdots & \\bm{S}_{N_c}^{H}\\bm{S}_{N_c} \n\\end{pmatrix}, \n\\end{equation}\nwhere each sub-matrix $\\bm{S}_i^H\\bm{S}_j$ contains inner products of the Fourier transforms of channel $i$ and channel $j$'s \n$B_1^+$ maps, after they are shifted to be centered different points on the excitation trajectory corresponding to the row \nand column indices of the sub-matrix.\nThese inner products can be calculated by interpolating the Fourier transform of the product of \nchannel $i$ and channel $j$'s $B_1^+$ maps. \nIn other words, each element in the Hermitian matrix $\\bm{S}_i^{H}\\bm{S}_j$ \nis the vector sum of channel $i$ and channel $j$'s shifted k-space $B_1^+$ maps, \nwhich is also a single point of their k-space convolution. \nVia the multiplication property of the Fourier transform, \nthis convolution in k-space can be calculated from the Fourier transform of the product of the two spatial domain $B_1^+$ maps. \nFor further details, please refer to Ref. \\cite{luo2019grappa}.\n%In practice, $\\bm{S}^{H}\\bm{S}$ is constructed in the following way. \n%We first represent the $\\bm{S}^{H}\\bm{S}$ matrix with block matrices. Each block matrix $\\bm{S}_i^{H}\\bm{S}_j$ is of size $N_n$ by $N_n$, and $\\bm{S}_i$ and $\\bm{S}_j$ are the columns of $\\bm{S}$ related to the k-space sensitivity maps of the $i$-th and $j$-th coils respectively.\n\n\\par Since $\\bm{S}^{H}\\bm{S}$ is Hermitian, \nwe only need to find the values within the lower triangle of the matrix, \nwhich are the sub-matrices $\\bm{S}_i^{H}\\bm{S}_j$ with $i>j$. % that are themselves lower triangular. \nThe elements of a given sub-matrix $\\bm{S}_i^{H}\\bm{S}_j$ \nare interpolated from a densely sampled Fourier transform of the product of the spatial domain $B_1^+$ maps of the $i$-th and $j$-th channels. \nThe $(m,n)$-th element is the value interpolated at a position $\\vec{k}_m-\\vec{k}_n$ away from DC,\nwhere $\\vec{k}_m$ and $\\vec{k}_n$ are the excitation k-space trajectory locations corresponding to row $m$ and column $n$.\nCompared to phase-modulating and Fourier transforming each channel's $B_1^+$ map for each point \non the trajectory which would require $N_t  N_c$ Fourier transforms,\nto solve all the columns of $\\bm{W}$ the total number of Fourier transforms needed in this efficient method is $N_c(N_c+1)/2$. \nThe storage size is also much smaller, \nand the matrix multiplication between $\\bm{S}^H$ and $\\bm{S}$ is avoided.\n%An alternative strategy would be to construct $\\bm{S}$ by Fourier transforming each channel's $B_1^+$ map \n%and then interpolating it to be centered at each trajectory location, \n%but this again requires multiplication of the $\\bm{S}^{H}$ and $\\bm{S}$ matrices,\n%which further involves the multiplication of interpolated values. \n%We have found empirically that this strategy introduces higher error\n%than interpolating the inner product values. \n%Furthermore, to calculate each element of $\\bm{S}^{H}\\bm{S}$, there are $2N_s$ number of interpolations involved with this sub-optimal strategy. While with the efficient algorithm there is only one interpolation from the densely sampled Fourier Transform of the dot product of two spatial domain $B_1^+$ maps needed. The extra interpolations involved in the sub-optimal strategy would introduce a larger error to $\\bm{S}^{H}\\bm{S}$.  \n\n\\subsection*{Off-Resonance Compensation}\n% In order to model the off-resonance into our k-space domain design, we adapted a fast implementation of the off-resonance compensation with time segmentation approximation and weighted least-squares interpolators \\cite{fessler2005toeplitz}. \nOff-resonance compensation is common in spatial-domain parallel pulse designs \\cite{Grissom:2006:MRM}, \nbut has not been previously implemented in a k-space-domain design.\nSpatial domain designs based on NUFFTs make use of an approximate time-segmented\nmodel for the off-resonance term \\cite{fessler2005toeplitz},\nwhich decouples the space- and time-dependence of off-resonant phase accrual into the product of \nspace- and time-dependent terms, which are applied on either side of the NUFFT operator. \nHere we show how a time-segmented off-resonance model can be incorporated in the proposed k-space-domain algorithm. \nMathematically, the time-segmented model is given by:\n\\begin{equation}\ne^{\\imath \\Delta\\omega(\\vec{x}_j) (t_i-T) }\\approx\\sum_{l=1}^{L} b_l(t_i) h_{l}(\\vec{x}_j) ,\n\\end{equation}\nwhere $\\Delta\\omega(\\vec{x}_j)$ is the off-resonance frequency at $\\vec{x}_j$, \n$i$ indexes time points in the pulse, \n$T$ is the pulse duration,\nand $l$ indexes the $L$ time segments, where $L$ is typically between 4 and 8. \nThe $b_{l}(t_i)$ functions are temporal interpolators that multiply into the RF samples and are determined by\nnumerical optimization as described in Ref. \\cite{fessler2005toeplitz},\nand $h_{l}(\\vec{x}_j) = e^{\\imath \\Delta\\omega(\\vec{x}_j)\\breve{t}_l}$ are the off-resonance phase shifts \napplied to the excitation patterns produced by the RF pulse time segments centered at time points $\\{\\breve{t}_l: l = 1, \\dots, L\\}$.\nThe time-segmented off-resonance model can be incorporated into Equation \\ref{eq:ScalerForm} as:\n\\begin{equation}\n\t\\delta(\\vec{k}-\\vec{k}_j)=\\sum_{l = 1}^L \\sum_{i=1}^{N_t}\\sum_{c=1}^{N_c} w_c(\\vec{k}_i) b_l(t_i) \\tilde{s}_{cl} (\\vec{k}-\\vec{k}_i), \n\\end{equation}\nwhere $\\tilde{s}_{cl}(\\vec{k})$ is the Fourier transform of the product of channel $c$'s $B_1^+$ map and time segment $l$'s \noff-resonance phase shift $h_l(\\vec{x}_j)$. \nWe can then write the equivalent of Equation \\ref{eq:MatrixForm} with the off-resonance model:\n\\begin{equation}\n\t\\sum_{l=1}^L \\bm{S}_l \\textrm{diag}(b_{l}(t_i)) \\bm{w}_j = \\bm{e}_j,\n\\end{equation} \nwhere the matrix $\\bm{S}_l$ is now formed from the $N_c  L$ Fourier transforms of the $B_1^+$ map and $h_l(\\vec{x}_j)$ products.  \nEfficient construction of the $\\bm{S}^{H}\\bm{S}$ matrix follows much the same procedure as without\noff-resonance except that with off-resonance,\nthe elements of each sub-matrix $\\bm{S}_i^{H}\\bm{S}_j$ in Equation \\ref{eq:SHS_blocks}\nare interpolated from $L(L+1)/2$ Fourier transformed maps,\nand the interpolated values are weighted by the temporal interpolators for each pair of multiplied time segments before they \nare summed.\nCompared to constructing $\\bm{S}^H\\bm{S}$ without off-resonance, \ntaking off-resonance into account increases the total number of FFT operations form $N_c(N_c+1)/2$ to $N_cL(N_cL+1)/2$, \nand increases the number of interpolations needed for each sub-matrix element from 1 to $L(L+1)/2$.  \nHowever, we note that only adjacent time segments with overlapping temporal interpolators at a given time point\nneed to be considered when calculating the elements of $\\bm{S}^H\\bm{S}$ corresponding to that time point. \n\n\n\n", "meta": {"hexsha": "9ff7adf3369c9a6d730412ca8ad94cfa97669d2a", "size": 17913, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/Manuscript_r2/Theory.tex", "max_stars_repo_name": "wgrissom/kpTx", "max_stars_repo_head_hexsha": "b0f89ad298c8814570fa6df758d97ea3832b28d5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-17T21:17:42.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-04T20:54:24.000Z", "max_issues_repo_path": "manuscript/Manuscript_r2/Theory.tex", "max_issues_repo_name": "wgrissom/kpTx", "max_issues_repo_head_hexsha": "b0f89ad298c8814570fa6df758d97ea3832b28d5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-01T10:38:17.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-03T11:18:22.000Z", "max_forks_repo_path": "manuscript/Manuscript_r2/Theory.tex", "max_forks_repo_name": "wgrissom/kpTx", "max_forks_repo_head_hexsha": "b0f89ad298c8814570fa6df758d97ea3832b28d5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 83.7056074766, "max_line_length": 1071, "alphanum_fraction": 0.745827053, "num_tokens": 4990, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7314223302161864}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\section{Sheet 3}\n\n\\subsection{Changes of coordinate system}\n\nWe denote by \\(x^{\\mu } = (x, y)\\) and \\(x^{\\prime \\mu } = (r, \\theta)\\). Then, we have the following Jacobian matrices: \n%\n\\begin{subequations}\n\\begin{align}\n  \\pdv{x^{\\mu }}{x^{\\prime \\nu }}  &= \\left[\\begin{array}{cc}\n  \\cos(\\theta )  & -r \\sin(\\theta )  \\\\ \n  \\sin(\\theta )  & r \\cos(\\theta ) \n  \\end{array}\\right]  \\\\\n  \\pdv{x^{\\prime \\nu }}{x^{\\rho }} &= \\left[\\begin{array}{cc}\n  \\displaystyle\\frac{x}{\\sqrt{x^2+y^2} } &\\displaystyle \\frac{y}{\\sqrt{x^2+y^2} } \\\\ \n  \\displaystyle -\\frac{y}{x^2+y^2} &\\displaystyle \\frac{x}{x^2+y^2}\n  \\end{array}\\right] \n  =\n  \\left[\\begin{array}{cc}\n  \\cos(\\theta )  & \\sin(\\theta )  \\\\ \n  \\displaystyle- \\frac{\\sin( \\theta ) }{r} & \\displaystyle \\frac{\\cos(\\theta ) }{r}\n  \\end{array}\\right]\n\\,,\n\\end{align}\n\\end{subequations}\n%\nwhich can be found by plain differentiation of the change of coordinates, recalling \\((\\arctan x)' = 1/ (1+x^2)\\). Then, we can compute the product of these two matrices: it comes out to be \n%\n\\begin{equation} \\label{eq:inverse-jacobian-matrix-relation} \n  \\pdv{x^{\\mu }}{x^{\\prime \\nu }} \\pdv{x^{\\prime \\nu }}{x^{\\rho }} = \\delta^{\\mu }_{\\nu }\n\\,,\n\\end{equation}\n%\nsince on the diagonal we get \\(\\cos^2(\\theta ) + \\sin^2(\\theta ) = 1\\), while on the off-diagonal terms we get a multiple of \\(\\sin(\\theta ) \\cos(\\theta ) - \\sin(\\theta ) \\cos(\\theta ) =0\\).\n\nNote that relation \\eqref{eq:inverse-jacobian-matrix-relation} is just the chain rule written in more generality: substituting the explicit coordinates for \\(x^{\\mu }\\) and \\(x^{\\prime \\mu }\\) we get the desired expression.\n\n\\subsection{Properties of covariant differentiation}\n\n\\subsubsection{Metric compatibility of the connection}\n\nWe wish to show that \\(\\nabla_{\\alpha } g_{\\mu \\nu } = 0\\).\nA very simple way to prove this is by going in the LIF: there, the equation reads \\(\\partial_{\\alpha }\\eta_{\\mu \\nu } = 0\\), which is immediately satisfied since the components of the Minkowski metric are constants.\nThen, since the equation is tensorial, the result extends to any frame.\n\nThis was not the spirit of the exercise, however: let us prove it in a different generic frame.\nTo this end, we define the \\emph{Christoffel symbols of the first kind} (while the regular ones are of the second kind): \n%\n\\begin{equation}\n  \\Gamma_{\\mu \\nu \\rho } = g_{\\mu \\sigma }\\Gamma^{\\sigma }_{\\nu \\rho } = \\frac{1}{2} \\qty(g_{\\mu \\nu, \\rho } + g_{\\mu \\rho , \\nu } - g_{\\nu \\rho, \\mu })\n\\,.\n\\end{equation}\n\nThese are useful since, as all their indices are down, it is easier to study their symmetry properties.\n\nNote that if we symmetrize the first and last index, we get \\(\\Gamma_{(\\mu | \\nu | \\rho)} = \\frac[i]{1}{2} g_{\\mu \\rho, \\nu }\\) since the first and last terms in the sum cancel (in the latter we must invert the indices \\(\\nu \\) and \\(\\rho \\) in order to see this, but this can always be done by the symmetry of the metric).\n\nThen, we write the expression for the covariant derivative of the metric: \n%\n\\begin{equation}\n  \\nabla_{\\alpha }g_{\\mu \\nu }= \\partial_\\alpha g_{\\mu \\nu }\n  - \\Gamma^{\\rho }_{\\mu \\alpha }g_{\\rho \\nu } \n  - \\Gamma^{\\rho }_{\\nu \\alpha  }g_{\\mu \\rho  } \n  = g_{\\mu \\nu , \\alpha } \n  - \\Gamma_{\\nu \\alpha \\mu }\n  - \\Gamma_{\\mu \\alpha \\nu }\n\\,,\n\\end{equation}\n%\nwhich is just \\(g_{\\mu \\nu , \\alpha } - 2 \\Gamma_{(\\nu | \\alpha | \\mu )} = g_{\\mu \\nu , \\alpha } - g_{\\nu \\mu , \\alpha } = 0\\), again by the symmetry of the metric.\n\nOne could argue that this is the opposite way round: we should \\emph{assume} \\(\\nabla_{\\mu } g_{\\rho \\sigma } = 0   \\) and derive from it the formula that was given for the Christoffel symbols in terms of the partial derivatives of the metric.\n\n\\subsubsection{Leibniz rule}\n\nAs before, this can be proved in the LIF from the Leibniz rule of regular partial derivatives.\n\nAs before, we like to calculate therefore we show this explicitly in any frame.\n\nThe derivative of the tensor product looks like: \n%\n\\begin{equation}\n    \\nabla_{\\mu } \\qty(A_{\\nu \\lambda } B_{ \\rho }) = \n    \\partial_{\\mu }\\qty(A_{\\nu \\lambda }B_{\\rho }) \n    -\\Gamma_{\\mu \\nu }^{\\sigma }A_{\\sigma \\lambda }B_{\\rho }\n    -\\Gamma_{\\mu \\lambda  }^{\\sigma }A_{\\nu \\sigma }B_{\\rho }\n    -\\Gamma_{\\mu \\rho }^{\\sigma }A_{\\nu \\lambda }B_{\\sigma }\n\\,,\n\\end{equation}\n%\nwhile the sum of derivatives looks like: \n%\n\\begin{equation}\n  \\begin{split}\n  B_{\\rho }\\nabla_{\\mu }A_{\\nu \\lambda } \n  + A_{\\nu \\lambda }\\nabla_{\\mu }B_{\\rho }=\n  &B_{\\rho }\\partial_{\\mu }A_{\\nu \\lambda }\n  -\\Gamma_{\\mu \\nu }^{\\sigma }A_{\\sigma \\lambda }B_{\\rho }\n  -\\Gamma_{\\mu \\lambda  }^{\\sigma }A_{\\nu \\sigma }B_{\\rho } \\\\\n  + & A_{\\nu \\lambda }\\partial_{\\mu }B_{\\rho }\n  -\\Gamma_{\\mu \\rho }^{\\sigma }A_{\\nu \\lambda }B_{\\sigma }\n  \\end{split}\n  \\,,\n\\end{equation}\n%\nso we can see that the Christoffel terms are equal, and the partial derivative terms also are since we have the Leibniz rule for partial derivatives.\n\n\\subsection{2D Christoffel symbols}\n\n\\subsubsection{Polar coordinates}\n\nThe metric and inverse metric are respectively given by \\(g_{\\mu \\nu } = \\diag{1, r^2}\\) and \\(g^{\\mu \\nu }= \\diag{1, r^{-2}}\\). We only care about the partial derivatives of the lower-indices one, and the only nonvanishing derivative is \\(g_{11,0} = 2r\\), where we mean \\((x^{0}, x^{1}) = (r, \\theta )\\).\n\nThen it is tedious but straightforward to perform the direct computation.\nThings that make it faster are discarding immediately terms which cannot contribute (such as \\(g_{\\alpha \\beta ,\\gamma }\\) where at least one of \\(\\alpha \\) and \\(\\beta \\) is not 1 or \\(\\gamma \\) is not \\(0\\), and only looking at the six independent symbols instead of the eight total ones (since \\(\\Gamma^{\\alpha }_{01} = \\Gamma^{\\alpha }_{10}\\) for any \\(\\alpha \\)).\n\nThen one can see that the nonvanishing symbols are\n%\n\\begin{subequations}\n\\begin{align}\n  \\Gamma^{0}_{11} &= \\frac{1}{2} g^{0\\alpha}\\qty(g_{\\alpha 1, 1}  + g_{\\alpha 1, 1} - g_{11, \\alpha }) \n  = \\frac{1}{2} g^{00}(-g_{11, 0}) = - \\frac{2r}{2} = -r  \\\\\n  \\Gamma^{1}_{01} &= \\frac{1}{2} g^{1 \\alpha }\\qty(g_{\\alpha 0, 1} + g_{\\alpha 1, 0} - g_{01, \\alpha })\n  = \\frac{1}{2} g^{11} g_{11, 0} = \\frac{1}{2} \\frac{1}{r^2} 2r = \\frac{1}{r}\n\\,.\n\\end{align}\n\\end{subequations}\n%\n\n\\subsubsection{Spherical surface} \\label{sec:spherical-surface-curvature}\n\nNow we have the following metric and inverse metric: \n%\n\\begin{equation} \\label{eq:spherical-metric} \n  g_{\\mu \\nu } = \\left[\\begin{array}{cc}\n  R^2 & 0 \\\\ \n  0 & R^2 \\sin^2(\\theta ) \n  \\end{array}\\right]\\,,\n  \\qquad\n  g^{\\mu \\nu } = \\left[\\begin{array}{cc}\n  R^{-2} & 0 \\\\ \n  0 & R^{-2}\\sin^{-2}(\\theta ) \n  \\end{array}\\right]\n\\,,\n\\end{equation}\n%\nbut do note that \\(R\\) is a constant: given \\((x^{0}, x^{1}) = (\\theta, \\varphi)\\), we have as before that the only nontrivial derivative is \\(g_{11,0} = 2 R^2  \\sin(\\theta ) \\cos(\\theta) \\).\n\nThen this case is exactly analogous to the previous one: the same symbols are zero, so we can skip almost all of the computation and jump straight to: \n%\n\\begin{subequations} \\label{eq:spherical-christoffel}\n\\begin{align}\n  \\Gamma^{0}_{11} &= -\\frac{1}{2} g^{00}g_{11,0} = - \\sin(\\theta ) \\cos(\\theta ) \\\\\n  \\Gamma^{1}_{01} &= \\frac{1}{2} g^{11}g_{11,0} = \\frac{\\cos(\\theta ) } {\\sin(\\theta ) }\n\\,.\n\\end{align}\n\\end{subequations}\n\n\\subsection{Parallel transport}\n\nWe know from the last exercise the metric and Christoffel symbols of 2D space and of the surface of a sphere.\n\n\n\nThe equations of parallel transport are in general \\(u^{\\mu }\\nabla_{\\mu }V^{\\nu } = 0\\).\n\n\\subsubsection{Flat space}\n\nWe want to determine the behaviour of a vector field \\(V^{\\mu }(\\theta )\\) defined on a curve \\(x^{\\mu }(\\theta ) = (R, \\theta)\\) with fixed \\(R\\), such that \\(V^{ \\mu } (\\theta = 0 ) = (0,1/R)\\) (a unit vector: \\(V^{\\mu } (0) V^{\\nu }(0) g_{\\mu \\nu }(0) = 1\\)).\n\nIn our case the tangent vector of the curve is \\(u^{\\mu }= (0,1)\\). Therefore the equations simplify to: \n%\n\\begin{equation}\n  \\nabla_{1}V^{\\mu }= \\partial_{1}V^{\\mu }+\\Gamma^{\\mu }_{1 \\alpha }V^{\\alpha } = 0\n\\,,\n\\end{equation}\n%\nwhich are two coupled differential equations; we can make them explicit and substitute the Christoffel symbols found earlier. \n%\n\\begin{subequations}\n\\begin{align}\n  \\nabla_{1}V^{0} &= \\partial_1 V^{0} + \\cancelto{}{\\Gamma^{0}_{10}V^{0}} + \\Gamma^{0}_{11}V^{1}\n  = \\partial_1 V^{0} - r V^{1}  \\\\\n  \\nabla_{1}V^{1} &= \\partial_1 V^{1} + \\Gamma^{1}_{10}V^{0} + \\cancelto{}{\\Gamma^{1}_{11}V^{1}} \n  = \\partial_{1}V^{1} + \\frac{1}{r} V^{0}\n\\,,\n\\end{align}\n\\end{subequations}\n%\nso we can write this linear system like: \n%\n\\begin{equation}\\label{diffeqes3}\n  \\partial_{1} \\left[\\begin{array}{c}\n  V^{0} \\\\ \n  V^{1}\n  \\end{array}\\right]\n  =\n  \\left[\\begin{array}{cc}\n  0 & r \\\\ \n  -r^{-1} & 0\n  \\end{array}\\right]\n  \\left[\\begin{array}{c}\n  V^{0} \\\\ \n  V^{1}\n  \\end{array}\\right]\n\\,.\n\\end{equation}\n%\n\nThe eigenvalues of this matrix are \\(\\pm i\\), so its exponential is a pure rotation matrix: \n%\n\\begin{equation}\n  \\exp(\\theta \\left[\\begin{array}{cc}\n  0 & r \\\\ \n  -r^{-1} & 0\n  \\end{array}\\right]) =\n  \\left[\\begin{array}{cc}\n  \\cos(\\theta )  & \\sin(\\theta )  \\\\ \n  -\\sin(\\theta )  & \\cos(\\theta ) \n  \\end{array}\\right] = R(-\\theta )\n\\,,\n\\end{equation}\n%\nso the solution is \n%\n\\begin{equation}\n  V^{\\mu }(\\theta ) = R(-\\theta )V^{\\mu }(0)\n\\,.\n\\end{equation}\n\nThis means that our vector is rotating clockwise with unit angular velocity in the \\((r, \\theta )\\) plane, just as the point it is defined at moves counterclockwise with unit angular velocity: therefore, if we look at the vector in Cartesian coordinates, we will see it always aligned with its initial direction and the same modulus.\n\nSpecifically, when \\(\\theta = \\pi /2\\) we get \\(V^{\\mu }=(1, 0)\\): this has the same modulus as \\((0,1/R)\\) since we compute lengths with respect to the metric of our space, as \\(\\norm{V}^2 = V^{\\mu } V^{\\nu } g_{\\mu \\nu }\\).\n\nAnother way to solve \\eqref{diffeqes3} is to explicit from the second equation $V^0=-r\\partial_1V^1$ and plug it into the second, so that it becomes\n\\begin{equation}\n\\frac{1}{r} \\partial_1(-r\\partial_1V^1)=V^1,\n\\end{equation}\nwhich leads to the same result.\n\\subsubsection{Curved space: spherical surface}\n\nNow our curve is \\(x^{\\mu } (\\theta ) = (\\theta , 0)\\) in the spherical coordinates \\(x^{\\mu } = (\\theta, \\varphi )\\). The metric is the one given in \\eqref{eq:spherical-metric}, the Christoffel symbols are the ones given in \\eqref{eq:spherical-christoffel}.\n\nThe parallel transport equations are now: \n%\n\\begin{subequations}\n\\begin{align}\n  \\nabla_{0}V^{0} &= \\partial_0 V^{0} + \\cancelto{}{\\Gamma^{0}_{00}V^{0}} + \\cancelto{}{\\Gamma^{0}_{01}V^{1} }  \\\\\n  \\nabla_{0}V^{1} &= \\partial_0 V^{1} + \\cancelto{}{\\Gamma^{1}_{00}V^{0}} + \\Gamma^{1}_{01}V^{1}\n  = \\partial_0 V^{1} + \\frac{V^{1}}{\\tan(\\theta )}\n\\,.\n\\end{align}\n\\end{subequations}\n\nThe first equation gives us \\(V^{1} = \\const\\), while we do not need to actually solve the second one: our initial condition is \\(V^{\\mu}(\\theta = 0) = (R^{-1}, 0)\\), and \\(V^{1} \\equiv 0\\) is a solution to that first-order equation, so by the uniqueness we have found the whole solution.\n\nTherefore the vector is constant in these coordinates.\n\nSpecifically, at \\(\\theta = \\pi /2\\) we get \\(V^{\\mu } = (1/R, 0)\\).\n\n\\end{document}\n\n", "meta": {"hexsha": "336fad1c69d92586478b8d84d18672c76970060b", "size": 11244, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_first_semester/gr_exercises/sheet3.tex", "max_stars_repo_name": "jacopok/notes", "max_stars_repo_head_hexsha": "805ebe1be49bbd14c6b46b24055f9fc7d1cd2586", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-10-10T13:10:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T14:52:50.000Z", "max_issues_repo_path": "ap_first_semester/gr_exercises/sheet3.tex", "max_issues_repo_name": "jacopok/notes", "max_issues_repo_head_hexsha": "805ebe1be49bbd14c6b46b24055f9fc7d1cd2586", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ap_first_semester/gr_exercises/sheet3.tex", "max_forks_repo_name": "jacopok/notes", "max_forks_repo_head_hexsha": "805ebe1be49bbd14c6b46b24055f9fc7d1cd2586", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-10-03T16:20:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-06T16:11:07.000Z", "avg_line_length": 42.4301886792, "max_line_length": 368, "alphanum_fraction": 0.6386517254, "num_tokens": 3942, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.8688267813328976, "lm_q1q2_score": 0.7314006744406546}}
{"text": "$k$-nearest Neighbor was put forward by Cover and Hart in 1968\\cite{knn}, is a classification algorithm, which is supervised and non-parametric. The problem, which K-NN solves, can be described as follows.\n\n\t  Given a labeled set $T=\\{(x_i,y_i)|x_i\\in\\mathbb{R}^n, y_i\\in C, i=1,2,\\dots,N\\}$, where $C$ is the set of categories, $C=\\{c_1,c_2,\\dots,c_s\\}$. We need to find out the category of the new instance, $x$. We will denote $y$ as the category of $x$.\n\n%\tWe will define ``neighbor\" i.\n\n\\section{How to Define ``Neighbor\"}\n\tTo define ``neighbor\", we introduce the definition of distance metrics in $\\mathbb{R}^n$ firstly.\n%\tBecause the labeled data instance $x_i\\in\\mathbb{R}^n$, here we only introduce the distance metrics in European space, $\\mathbb{R}^n$.\n\n\t\\begin{definition}\n\tAssume that $x_i, x_j\\in\\mathbb{R}^n$, and note that\n\t$$x_i=(x_i^{(1)},x_i^{(2)},\\dots,x_i^{(n)})$$\n\t\t$$x_j=(x_j^{(1)},x_j^{(2)},\\dots,x_j^{(n)})$$\n\t\tThen we define $L_p$ distance\n\t\t\\begin{equation}\n\t\tL_p(x_i, x_j):=(\\sum_{l=1}^{n} |x_i^{(l)}-x_j^{(l)}|^p)^{\\cfrac{1}{p}}, p\\geq 1\n\t\t\\end{equation}\n\n\t\ti.e. when $p=2$, this distance is Euclidean distance,\n\t\t\\begin{equation}\n\t\tL_2(x_i, x_j):=(\\sum_{l=1}^{n} |x_i^{(l)}-x_j^{(l)}|^2)^{\\cfrac{1}{2}}\n\t\t\\end{equation}\n\n\t%\tIf $p=1$, it is Manhattan distance,\n\t%\t\\begin{equation}\n\t%\tL_1(x_i, x_j):=\\sum_{l=1}^{n} |x_i^{(l)}-x_j^{(l)}|\n\t%\t\\end{equation}\n\n\t%\tIf $p=\\infty$, it is The maximum value of each coordinate distance,\n\t%\t\\begin{equation}\n\t%\tL_{\\infty}(x_i,x_j):=\\max_{l} |x_i^{(l)}-x_j^{(l)}|\n\t%\t\\end{equation}\n         \\end{definition}\n\n\t    The figure \\ref{alo:distance} shows that the points whose distance from the origin is 1 in $\\mathbb{R}^n$.\n\t    \\begin{figure}[htbp]\n\t    \t\\centering{\\includegraphics[width=10cm]{distance.png}}\n\t    \t\\caption{Relationship between the different $L_p$ distance}\n\t    \t\\label{alo:distance}\n\t    \\end{figure}\n\n    Now we can define ``neighbor\", i.e., given $p$, the nearest neighbor of $x_i$ is the point that has the minimal $L_p$ distance to $x_i$. It is worthy to note that the nearest neighbor determined under different distance metrics are generally different.\n\n\\section{$k$-NN Algorithm}\n\n       $k$-NN predicts category of $x$ via the following Algorithm.\n\n\t\\begin{algorithm}\n    \t\\caption{$k$-NN}\n    \t\\label{alo:K-NN}\n    \t\\textbf{Input:}  Set $T=\\{(x_i, y_i)|x_i\\in\\mathbb{R}^n, y_i\\in C, i=1,2,\\dots,N\\}$, $x$ and $k$, where $C = \\{c_{1}, c_{2}, \\dots, c_{s}\\}$. \\\\\n    \t\\textbf{Output:} $y$ (the category of $x$)\n\n    \t\\begin{algorithmic}[1]\n         \\State Find $k$ neighbors $x_j\\in T, j=i_1,\\dots,i_k$, i.e.\n    \t \\begin{align*}\n    \t x_{i_1}&={\\arg\\min}_{x_i\\in T} \\|x-x_i\\|_2,\\\\\n    \t x_{i_m}&={\\arg\\min}_{x_i\\in T\\setminus \\{\\cup_{n<m}x_{i_n}\\}} \\|x-x_i\\|_2, 1<m\\leq k\n    \t \\end{align*}\n    \t \\State Define $y$ is the category of $x$,and find out it. $$y={\\arg\\max}_{c_l}\\sum_{j=i_1,\\cdots,i_k}I(y_j=c_l), l=1,2,\\dots,s$$ where I is instruction function, that is, if $y_j=c_l$, then $I=1$, or $I=0$.\n    \t\\end{algorithmic}\n    \\end{algorithm}\n\n\t\\textbf{Shortcomings of $k$-NN}:\n\t  \\begin{enumerate}\n\t  \t\\item It is sensitive to the local structure of the data, easy to over-fit the data.\n\t  \t\\item It is expensive to calculate the distance each time. \n\t  \\end{enumerate}\n\t  \n\t  To cut down the expense of computation, one classical method is the $\\textbf{$k$-d tree}$(short for $k$-dimensional tree), where the $k$ is different with the $k$ used by above $k$-NN. In computer science, a $k$-d tree is a space-partitioning data structure for organizing points in a $k$-dimensional space. Next we introduce how to construct one $k$-d tree, which can represent and store the distance relation between points.\n\t  \n\t \\begin{algorithm}\n    \t\\caption{Construct Balanced $k$-d Tree}\n    \t\\label{alo:kdtree}\n    \t\\textbf{Input:} Set $T=\\{x_i | x_i\\in\\mathbb{R}^k, i=1,2,\\dots,N\\}$, where $x_{i} = (x_{i}^{(1)}, x_{i}^{(2)}, \\dots, x_{i}^{(k)})$. \\\\\n    \t\\textbf{Output:} $k$-d Tree\n\n    \t\\begin{algorithmic}[1]\n\t\\State Find one rectangle region $\\mathscr{R}_{0}$ to cover set $T$, i.e.\n\t\\[\\mathscr{R}_{0} = \\{x| \\min_{i} x_{i}^{(j)} < x^{(j)} < \\max_{i} x_{i}^{(j)}\\}\\]\n         Define $\\mathscr{R}_{0}$ as the root node with $0$-depth. \n\n    \t \\State \\textbf{Repeat}: for $m$-th $j$-depth node and $l = (j \\ mod \\ k) + 1$, \n\t \n\t \\begin{enumerate}[a]\n\t \\item If $\\# (T \\cap  \\mathscr{R}_{j}^{m}) \\nmid 2$,  \n\t $$ i_{0} = \\arg median_{i}\\{ x_{i}^{(l)}\\}$$\n\t \n\t use the hyperplane $x^{(l)} = x_{i_{0}}^{(l)}$ to divide $\\mathscr{R}_{j}^{m}$ into two subregions as $\\mathscr{R}_{j + 1}^{2m-1}$ and $\\mathscr{R}_{j + 1}^{2m}$. Then store $x_{i_{0}}$ in the node $\\mathscr{R}_{j}^{m}$.\n\t \n\t \\item If $\\# (T \\cap  \\mathscr{R}_{j}^{m}) \\mid 2$ and $\\# (T \\cap  \\mathscr{R}_{j}^{m}) \\neq 0$, \n\t $$ \\hat{x}^{(l)} = median_{i}\\{ x_{i}^{(l)}\\}$$\n\t \n\t similarly, the hyperplane $x^{(l)} = \\hat{x}^{(l)}$ to divide $\\mathscr{R}_{j}^{m}$ into two subregions as $\\mathscr{R}_{j + 1}^{2m-1}$ and $\\mathscr{R}_{j + 1}^{2m}$.\n\t \n\t \\item If $\\# (T \\cap  \\mathscr{R}_{j}^{m}) \\mid 2$ and $\\# (T \\cap  \\mathscr{R}_{j}^{m}) = 0$, no partition will be exceeded.\n\t \n\t Collect all $\\mathscr{R}_{j + 1}^{l}$ to get (j + 1)-depth nodes.\n  \t \\end{enumerate}\n\t \\textbf{Stop} until \n\t \\[ \\sum_{m} \\# (T \\cap  \\mathscr{R}_{j + 1}^{m}) = 0 \\]\n    \t\\end{algorithmic}\n    \\end{algorithm}\n    \n    Now we import an example using $k$-d tree on 2-d set to show the specific details of $\\textbf{Algorithm} \\  \\ref{alo:kdtree}$. \n    \n    Given the set $T = \\{x_{i}| i = 1: 7\\} = \\{(1, 1), (1, 5), (2, 9), (3, 3), (5, 2), (6, 7), (8, 4)\\}$(Fig $\\ref{alo:kdtree}$) as following. At the very beginning, we choose the 1-th coordinate to get the first partition plane $x_{1} = 3$ for the reason that the median of $\\{1, 1, 2, 3, 5, 6, 8\\}$ is 3. Here we left the following details to our reader to complete the whole algorithm. The $k$-d tree can be drown as one visual tree%(Fig $\\ref {alo:kdtree}$).\n    \n    %%%\n    \n\t\\begin{figure}[htbp]\n\t\\centering{\\includegraphics[width=10cm]{kdtree.png}}\n\t\\caption{Result of $k$-d Tree}\n\t\\label{alo:kdtree}\n\t\\end{figure}\n    %%%%%%%%%%%%\n\n\n%%%%%%%%%%%\n\\begin{tikzpicture}[line width = 1pt,\n                    solid/.style = {circle, draw, fill = black, minimum size = 0.3cm},\n                    empty/.style = {circle, draw, fill = white, minimum size = 0.3cm}]\n%%%%%\n\n\\node [empty, label = right:$x_4$] (A) at (4,2) {};\n\\node [empty, label = right:$x_{2}$] (B) at (2,1) {};\n\\node [solid, label = right:$x_{7}$] (C) at (6,1) {};\n\\node [empty, label = right:$x_{1}$] (D) at (1,0) {};\n\\node [solid, label = right:$x_{3}$] (E) at (3,0) {};\n\\node [empty, label = right:$x_{4}$] (F) at (5,0) {};\n\\node [solid, label = right:$x_{6}$] (G) at (7,0) {};\n\n\\draw (A) -- (B);\n\\draw (A) -- (C);\n\\draw (B) -- (D);\n\\draw (B) -- (E);\n\\draw (C) -- (F);\n\\draw (C) -- (G);\n\n\n\\end{tikzpicture}\n\n\n\n\n\n    \n    $k$-d tree can save lots of computation in $k$-NN. We briefly give the recipe of $k$-d tree method of finding the nearest neighbor of one new instance, $x$.\n    \n    \t \\begin{algorithm}\n    \t\\caption{Using $k$-d Tree to Find the Nearest Neighbor}\n    \t\\label{alo:kdtree}\n    \t\\textbf{Input:} $k$-d tree of data set and new instance, $x$ \\\\\n    \t\\textbf{Output:} Nearest neighbor\n\n    \t\\begin{algorithmic}[1]\n\t\\State Find the leaf node that contains $x$.\n\t\n\t\\textbf{Downward retrieval}: from the root node, according to information stored in the nodes, such as the corresponding partition hyperplane, to move our searching road to next depth right or left child node. Repeat the above process until arriving one leaf node, say $x^{*}$, which named as the current nearest neighbor.\n\t\n\t\\State{\\textbf{Upward check and Repeat}}: for one current nearest neighbor, $x^{*}$, whose depth is j,\n\t\n\t\\begin{enumerate}[(1)]\n\t\\item Compute \n\t$$d(x^{*}, x) = ||x^{*} - x||$$\n\t\\item Backward to $x^{*}$'s parent node, say $x_{j - 1}$. \n\t\\item Check the other child node of $x_{j - 1}$, say $x^{**}$, if $d(x^{**}, x) \\leq d(x^{*}, x) $, let $x^{*} = x^{**}$.\n\t\\end{enumerate}\n\t \n         \\textbf{Stop}: j = 0. \n    \t\\end{algorithmic}\n    \\end{algorithm}\n    \n\t   \n\n\\section{The Choice of Parameter $k$}\n    The choice of $k$ has significant impact on the results of $k$-NN.\n\n    If we choose a smaller $k$, the forecast results are usually very sensitive to the neighboring instance points. In particular, the neighboring instance points may be noise. For one exact example, we have one labeled set in $\\mathbb{R}^{2}$, which has two categories drawn in colors, `green' and `blue', and one red instance waiting its category. It's obvious that the red instance should better be grouped into the green class. When choosing a small $k$, we will get the bad result, `blue'.  By contrast, choosing a larger $k$, the labeled instances, which are distant from the target, will make unnecessary contribution. Then $k$-NN will be fail again. As the figure $\\ref{alo: large k}$ shows, if we select the whole labeled points, then we will get category `blue' instead of `green'.\n\n\t\\begin{figure}[htbp]\n\t    \\centering{\\includegraphics[width=10cm]{small_k.png}}\n\t    \\caption{One example of choosing a smaller $k$}\n\t    \\label{alo:small k}\n        \\end{figure}\n\n\n   \n\n       \\begin{figure}[htbp]\n\t\\centering{\\includegraphics[width=10cm]{large_k.png}}\n\t\\caption{One example of choosing a larger $k$}\n\t\\label{alo: large k}\n       \\end{figure}\n\n\n\n    In general, the choice of $k$ depends on the data. One can use Cross-Validation method to find an optimal $k$.\n\n    \\begin{algorithm}\n    \t\\caption{Find the Optimal $k$}\n    \t\\label{alo:find the optimal k}\n    \t\\textbf{Input:}  labeled set $D=\\{(x, y)|x \\in\\mathbb{R}^n, y \\in C, i=1,2,\\dots, N\\}$, where $C = \\{c_{1}, c_{2}, \\dots, c_{s}\\}$.\\\\\n    \t\\textbf{Output:} $k$\n\n    \t\\begin{algorithmic}[1]\n         \\State Divide data from $D$ into two parts: labeled set $T$ and validation set $Y$, i.e., which are noted as follows,   \t $$T = \\{(x_{i}, y_{i})|x_{i} \\in\\mathbb{R}^{n}, y_{i} \\in C, i = 1, 2, \\dots, N_{1}\\}$$\n         $$Y = \\{(\\hat{x}_{j}, \\hat{y}_{j})|\\hat{x}_{j} \\in\\mathbb{R}^{n}, \\hat{y}_{j} \\in C, j = 1, 2, \\dots, N_{2}\\}$$\n    \t \\State Initialize $k = 2$. For $j = 1, 2, \\dots, N_{2}$, use the Algorithm $k$-NN on labeled set $T$, then get category label $\\tilde{y}_{j}$.\\\\\n\t Define $O^{k}$,\n\t $$O^{k} = \\sum_{j = 1}^{N_{2}} I(\\tilde{y}_{j} = \\hat{y}_{j})$$\n\t Update $k = k + 1$\n    \t \\State Stop until $k = N$,\n\t $$k = {\\arg\\max}_{k} O^{k}$$\n    \t\\end{algorithmic}\n    \\end{algorithm}\n\n", "meta": {"hexsha": "262239b4d4e6067bb1f84776cd6d9aa67df74b25", "size": 10498, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/KNN.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/KNN.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/KNN.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.9360730594, "max_line_length": 791, "alphanum_fraction": 0.6076395504, "num_tokens": 3853, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.8688267796346599, "lm_q1q2_score": 0.7314006730110346}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Orders of Growth}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nVarious exercises relating to orders of growth.\n\\end{abstract}\n\\maketitle\n\n\\begin{exercise}\nUse orders of growth to identify dominant terms and compute limits.\n\\begin{itemize}\n\\item Compute the limit:\n\\[ \\lim_{x \\rightarrow \\infty} \\frac{e^x + x^2}{3 e^x + x^3} = \\answer{\\frac{1}{3}} \\]\nThe dominant terms are\n\\begin{multipleChoice}\n\\choice[correct]{$e^x$ in the numerator and $3 e^x$ in the denominator}\n\\choice{$e^x$ in the numerator and $x^3$ in the denominator}\n\\choice{$x^2$ in the numerator and $3 e^x$ in the denominator}\n\\choice{$x^2$ in the numerator and $x^3$ in the denominator}\n\\end{multipleChoice}\n\\item Compute the limit:\n\\[ \\lim_{x \\rightarrow 0} \\frac{e^x + x^2}{3 e^x + x^3} = \\answer{\\frac{1}{3}} \\]\nThe dominant terms are\n\\begin{multipleChoice}\n\\choice[correct]{$e^x$ in the numerator and $3 e^x$ in the denominator}\n\\choice{$e^x$ in the numerator and $x^3$ in the denominator}\n\\choice{$x^2$ in the numerator and $3 e^x$ in the denominator}\n\\choice{$x^2$ in the numerator and $x^3$ in the denominator}\n\\end{multipleChoice}\n\\item Compute the limit:\n\\[ \\lim_{x \\rightarrow \\infty} \\frac{x + x^2}{3 x^4 + x^3} = \\answer{0} \\]\nThe dominant terms are\n\\begin{multipleChoice}\n\\choice{$x$ in the numerator and $3 x^4$ in the denominator}\n\\choice{$x$ in the numerator and $x^3$ in the denominator}\n\\choice[correct]{$x^2$ in the numerator and $3 x^4$ in the denominator}\n\\choice{$x^2$ in the numerator and $x^3$ in the denominator}\n\\end{multipleChoice}\n\\item Compute the limit:\n\\[ \\lim_{x \\rightarrow 0} \\frac{x + x^2}{3 x^4 + x^3} = \\answer{\\infty} \\]\nThe dominant terms are\n\\begin{multipleChoice}\n\\choice{$x$ in the numerator and $3 x^4$ in the denominator}\n\\choice[correct]{$x$ in the numerator and $x^3$ in the denominator}\n\\choice{$x^2$ in the numerator and $3 x^4$ in the denominator}\n\\choice{$x^2$ in the numerator and $x^3$ in the denominator}\n\\end{multipleChoice}\n\\item Compute the limit:\n\\[ \\lim_{x \\rightarrow \\infty} \\frac{\\sqrt{x^3 + 9} - x}{\\sqrt{x^3 + 9} + x} = \\answer{1} \\]\n\\begin{multipleChoice}\n\\choice[correct]{$\\sqrt{x^3+9}$ dominates $x$}\n\\choice{$x$ dominates $\\sqrt{x^3+9}$}\n\\end{multipleChoice}\n\\item Compute the limit:\n\\[ \\lim_{x \\rightarrow \\infty} \\frac{\\sqrt{x^3 + 9x^2} - x}{\\sqrt{x^3 - 9x^2} + x} = \\answer{1} \\]\n(First identify whether the square-root term is dominant or not; when it is dominant, identify the dominant term \\textit{inside} the square root and neglect the non-dominant term.)\n\\item Compute the limit:\n\\[ \\lim_{x \\rightarrow \\infty} \\frac{ 2 x^3 + \\sin x^5}{ 3 x^4 + \\sin x^6} = \\answer{0}. \\]\n\\item Compute the limit\n\\[ \\lim_{x \\rightarrow 0} \\frac{\\sqrt{x + 1}}{\\sqrt{x}} = \\answer{\\infty}. \\]\n\\begin{multipleChoice}\n\\choice{$x$ dominantes $1$ as $x \\rightarrow 0$}\n\\choice[correct]{$1$ dominates $x$ as $x \\rightarrow 0$}\n\\end{multipleChoice}\n\\item Compute the limit:\n\\[ \\lim_{x \\rightarrow \\infty} \\frac{ (\\ln x)^{100}}{x^{0.01}} = \\answer{0}. \\]\n\\begin{multipleChoice}\n\\choice[correct]{$x^{0.01}$ dominates $(\\ln x)^{100}$ as $x \\rightarrow \\infty$}\n\\choice{$(\\ln x)^{100}$ dominates $x^{0.01}$ as $x \\rightarrow \\infty$}\n\\end{multipleChoice}\n\\item Compute the limit:\n\\[ \\lim_{x \\rightarrow 0^+} x^{0.01} (\\ln x)^{100} = \\answer{\\infty} \\]\n\\begin{multipleChoice}\n\\choice[correct]{$x^{-0.01}$ dominates $(\\ln x)^{100}$ as $x \\rightarrow 0^+$}\n\\choice{$(\\ln x)^{100}$ dominates $x^{-0.01}$ as $x \\rightarrow 0^+$}\n\\end{multipleChoice}\n\\item Compute the limit:\n\\[ \\lim_{x \\rightarrow \\infty} \\frac{e^{\\ln \\ln x}+1}{x^2} = \\answer{0} \\]\n(Use the laws of exponents to write $x^2 = e^{2 \\ln x}$.)\n\\end{itemize}\n\\end{exercise}\n\n\n\n\\section*{Sample Quiz Questions}\n\n\\begin{question}%%%%%[GrowthOrdINF001]\n\nArrange the functions \n\\[ x^{x} \\qquad \\frac{e^{x}}{\\ln{x}} \\qquad \\ln{x} \\]\nin order from least rate of growth to greatest rate of growth as \\(x \\rightarrow \\infty\\). Compare on the basis of magnitude rather than sign, i.e., if a function is negative, take its absolute value first.\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle x^{x} < \\! \\! < \\frac{e^{x}}{\\ln{x}} < \\! \\! < \\ln{x}\\)}\n\\choice{\\(\\displaystyle \\ln{x} < \\! \\! < x^{x} < \\! \\! < \\frac{e^{x}}{\\ln{x}}\\)}\n\\choice{\\(\\displaystyle \\frac{e^{x}}{\\ln{x}} < \\! \\! < \\ln{x} < \\! \\! < x^{x}\\)} \n\\choice{\\(\\displaystyle x^{x} < \\! \\! < \\ln{x} < \\! \\! < \\frac{e^{x}}{\\ln{x}}\\)}\n\\choice{\\(\\displaystyle \\frac{e^{x}}{\\ln{x}} < \\! \\! < x^{x} < \\! \\! < \\ln{x}\\)}\n\\choice[correct]{\\(\\displaystyle \\ln{x} < \\! \\! < \\frac{e^{x}}{\\ln{x}} < \\! \\! < x^{x}\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nGeneral Remarks:\n\\begin{itemize} \\item Higher powers of \\(x\\) grow faster at infinity than lower powers of \\(x\\).\n\\item As \\(x \\rightarrow \\infty\\), \\(\\ln x\\) goes to infinity slower than \\(x^p\\) for any (presumably small) positive constant \\(p\\).\n\\item As \\(x \\rightarrow \\infty\\), \\(e^x\\) goes to infinity faster than \\(x^n\\) for any (presumably large) positive constant \\(n\\).\n\\item As \\(x \\rightarrow \\infty\\), \\(x^x\\) goes to infinity faster than any exponential of the form \\(e^{cx}\\) for any constant \\(c\\).\n\\end{itemize}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[GrowthOrdINF002]\n\nArrange the functions \n\\[ \\frac{e^{- x}}{\\ln{x}} \\qquad x^{3} \\ln{x} \\qquad e^{x} \\]\nin order from least rate of growth to greatest rate of growth as \\(x \\rightarrow \\infty\\). Compare on the basis of magnitude rather than sign, i.e., if a function is negative, take its absolute value first.\n\\begin{multiplechoice}\n\\choice[correct]{\\(\\displaystyle \\frac{e^{- x}}{\\ln{x}} < \\! \\! < x^{3} \\ln{x} < \\! \\! < e^{x}\\)}\n\\choice{\\(\\displaystyle e^{x} < \\! \\! < \\frac{e^{- x}}{\\ln{x}} < \\! \\! < x^{3} \\ln{x}\\)}\n\\choice{\\(\\displaystyle x^{3} \\ln{x} < \\! \\! < e^{x} < \\! \\! < \\frac{e^{- x}}{\\ln{x}}\\)} \n\\choice{\\(\\displaystyle \\frac{e^{- x}}{\\ln{x}} < \\! \\! < e^{x} < \\! \\! < x^{3} \\ln{x}\\)}\n\\choice{\\(\\displaystyle x^{3} \\ln{x} < \\! \\! < \\frac{e^{- x}}{\\ln{x}} < \\! \\! < e^{x}\\)}\n\\choice{\\(\\displaystyle e^{x} < \\! \\! < x^{3} \\ln{x} < \\! \\! < \\frac{e^{- x}}{\\ln{x}}\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nGeneral Remarks:\n\\begin{itemize} \\item Higher powers of \\(x\\) grow faster at infinity than lower powers of \\(x\\).\n\\item As \\(x \\rightarrow \\infty\\), \\(\\ln x\\) goes to infinity slower than \\(x^p\\) for any (presumably small) positive constant \\(p\\).\n\\item As \\(x \\rightarrow \\infty\\), \\(e^x\\) goes to infinity faster than \\(x^n\\) for any (presumably large) positive constant \\(n\\).\n\\end{itemize}\n\\end{feedback}\n\n\\end{question}\n\n\n\\begin{question}%%%%%[GrowthOrdZERO001]\n\nArrange the functions \n\\[ \\left( \\ln \\frac{1}{x} \\right)^2 \\qquad \\frac{e^{- x}}{x^{3}} \\ln{x} \\qquad x^{3} e^{x} \\]\nin order from least rate of growth to greatest rate of growth as \\(x \\rightarrow 0^+\\). Compare on the basis of magnitude rather than sign, i.e., if a function is negative, take its absolute value first.\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\left( \\ln \\frac{1}{x} \\right)^2 < \\! \\! < \\frac{e^{- x}}{x^{3}} \\ln{x} < \\! \\! < x^{3} e^{x}\\)}\n\\choice[correct]{\\(\\displaystyle x^{3} e^{x} < \\! \\! < \\left( \\ln \\frac{1}{x} \\right)^2 < \\! \\! < \\frac{e^{- x}}{x^{3}} \\ln{x}\\)}\n\\choice{\\(\\displaystyle \\frac{e^{- x}}{x^{3}} \\ln{x} < \\! \\! < x^{3} e^{x} < \\! \\! < \\left( \\ln \\frac{1}{x} \\right)^2\\)} \n\\choice{\\(\\displaystyle \\left( \\ln \\frac{1}{x} \\right)^2 < \\! \\! < x^{3} e^{x} < \\! \\! < \\frac{e^{- x}}{x^{3}} \\ln{x}\\)}\n\\choice{\\(\\displaystyle \\frac{e^{- x}}{x^{3}} \\ln{x} < \\! \\! < \\left( \\ln \\frac{1}{x} \\right)^2 < \\! \\! < x^{3} e^{x}\\)}\n\\choice{\\(\\displaystyle x^{3} e^{x} < \\! \\! < \\frac{e^{- x}}{x^{3}} \\ln{x} < \\! \\! < \\left( \\ln \\frac{1}{x} \\right)^2\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nGeneral Remarks:\n\\begin{itemize} \\item Lower powers of \\(x\\) grow faster as \\(x \\rightarrow 0^+\\) than higher powers of \\(x\\).\n\\item As \\(x \\rightarrow 0^+\\), \\(-\\ln x = \\ln x^{-1}\\) goes to \\(\\infty\\) slower than \\(x^{-p}\\) for any (presumably small) positive \\(p\\).\n\\item As \\(x \\rightarrow 0^+\\), \\(e^{x} \\rightarrow 1\\) and so does not influence the growth rate.\n\\item As \\(x \\rightarrow 0^+\\), \\(e^{-x} \\rightarrow 1\\) and so does not influence the growth rate.\n\\end{itemize}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[GrowthOrdZERO005]\n\nArrange the functions \n\\[ \\frac{x^{3} e^{x}}{\\ln{x}} \\qquad \\frac{e^{- x}}{x^{3}} \\qquad \\frac{e^{- x}}{x^{3} \\ln{x}} \\]\nin order from least rate of growth to greatest rate of growth as \\(x \\rightarrow 0^+\\). Compare on the basis of magnitude rather than sign, i.e., if a function is negative, take its absolute value first.\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\frac{x^{3} e^{x}}{\\ln{x}} < \\! \\! < \\frac{e^{- x}}{x^{3}} < \\! \\! < \\frac{e^{- x}}{x^{3} \\ln{x}}\\)}\n\\choice{\\(\\displaystyle \\frac{e^{- x}}{x^{3} \\ln{x}} < \\! \\! < \\frac{x^{3} e^{x}}{\\ln{x}} < \\! \\! < \\frac{e^{- x}}{x^{3}}\\)}\n\\choice{\\(\\displaystyle \\frac{e^{- x}}{x^{3}} < \\! \\! < \\frac{e^{- x}}{x^{3} \\ln{x}} < \\! \\! < \\frac{x^{3} e^{x}}{\\ln{x}}\\)} \n\\choice[correct]{\\(\\displaystyle \\frac{x^{3} e^{x}}{\\ln{x}} < \\! \\! < \\frac{e^{- x}}{x^{3} \\ln{x}} < \\! \\! < \\frac{e^{- x}}{x^{3}}\\)}\n\\choice{\\(\\displaystyle \\frac{e^{- x}}{x^{3}} < \\! \\! < \\frac{x^{3} e^{x}}{\\ln{x}} < \\! \\! < \\frac{e^{- x}}{x^{3} \\ln{x}}\\)}\n\\choice{\\(\\displaystyle \\frac{e^{- x}}{x^{3} \\ln{x}} < \\! \\! < \\frac{e^{- x}}{x^{3}} < \\! \\! < \\frac{x^{3} e^{x}}{\\ln{x}}\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nGeneral Remarks:\n\\begin{itemize} \\item Lower powers of \\(x\\) grow faster as \\(x \\rightarrow 0^+\\) than higher powers of \\(x\\).\n\\item As \\(x \\rightarrow 0^+\\), \\(-\\ln x = \\ln x^{-1}\\) goes to \\(\\infty\\) slower than \\(x^{-p}\\) for any (presumably small) positive \\(p\\).\n\\item As \\(x \\rightarrow 0^+\\), \\(e^{x} \\rightarrow 1\\) and so does not influence the growth rate.\n\\item As \\(x \\rightarrow 0^+\\), \\(e^{-x} \\rightarrow 1\\) and so does not influence the growth rate.\n\\end{itemize}\n\\end{feedback}\n\n\\end{question}\n\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "c0b8f53e510ab205f40a1a3a9a8e02fd4eca0d51", "size": 9965, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "applications/15ordergrowthpractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/15ordergrowthpractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/15ordergrowthpractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.9010416667, "max_line_length": 206, "alphanum_fraction": 0.6057200201, "num_tokens": 3656, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267728417087, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7314006621208605}}
{"text": "\n\\subsection{Kolmogorov space}\n\nIn a Kolmogorov (or \\(T_0\\)) space, for every pair of points there is a neighbourhood containing one but not the other.\n\n", "meta": {"hexsha": "5f56672fdd4e79d3d79231ac2b9e5abc7b148d7d", "size": 153, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/topologyFinite/07-02-kolmogorov.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/topologyFinite/07-02-kolmogorov.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/topologyFinite/07-02-kolmogorov.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.5, "max_line_length": 119, "alphanum_fraction": 0.7581699346, "num_tokens": 45, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897509188343, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7312757379303187}}
{"text": "\\section*{Background}\n\n\\subsection*{Neural Radiance Fields}\n\nNeural Radiance Fields (NeRF)~\\cite{mildenhall2020nerf} are a recent technique for novel view synthesis. In order to represent a highly-detailed scene, NeRF models a scene as a continuous, volumetric field of varying density, which refracts light at varying degrees. This is based on traditional volumetric rendering techniques, based on the rendering equation:\n\\[\n  I(r) = \\int_{t_n}^{t_f} T(t, r) \\sigma(r(t)) c(r(t), r_d)dt\n\\]\nWhere \n\\[\n    T(t, r) = \\exp{-\\int_{t_n}^{t} \\sigma(r(s))ds}\n\\].\n\nWhere $I(r)$ is the illumination along camera ray $r(t) = r_o + t r_d$. Neural radiance fields are able to accurately reconstruct high-frequency features by recovering $\\sigma$, the density at a given point, and $c$, the view-dependent color at a given point by modelling them as MLPs with an additional encoding scheme that allows for differentiation between extremely close points. We evaluate the above equations by performing ray-marching and computing $T(j,r) = \\Sigma -\\exp\\sigma_i c_i$, by partitioning the ray into evenly spaced bins and sampling randomly from within each bin.\n\nThere have been a significant number of extensions to NeRF, including optimizations on the encoding for differentiating positions in space~\\cite{tancik2020fourfeat}, better sampling approaches~\\cite{barron2021mipnerf}, and faster training~\\cite{yu2021plenoxels}. This is only a small subset of NeRF variants, and a plethora exist which we do not list.\n\n\\subsection*{Dynamic Neural Radiance Fields}\n\nNeural Radiance Fields were designed to only handle static scenes, and thus cannot accurately reconstruct scenes which contain movement, alternative lighting conditions, or other variations.\nIn order to model dynamic scenes, there have been two diverging approaches. \n\nOne subset of approaches directly model the transformation in the time domain, by directly modelling the function $\\sigma(x,t)=f(x\\in\\mathbb{R}^3, t\\in[0,1])$, which include works such as HyperNeRF~\\cite{park2021hypernerf}, NeRFies~\\cite{park2021nerfies}, and Space-Time Invariant Irradiance Fields~\\cite{xian2021space}. By directly modelling the variation of the density, these methods are able to reconstruct large deformations in latent spaces and reconstruct a wide variety of transformations from a single radiance field, often allowing for transformations in some latent space that permit for deformation.\n\nThe other subset of approaches models dynamics directly as a form of translation. In this case, we are not able to directly move the objects inside the scene since we can only evaluate the NeRF at a given $x$, so instead we invert the translation, instead bending the rays as a function of time, which acts to warp the space being rendered. This allows for effective simulation, and can be post-processed to compute object translation if so desired. The formulation for density is thus better described as $\\sigma(x,t)=f(x+\\Delta(x,t))$. This formulation enforces a coherent canonical representation, while directly modelling movement, and has been shown to be able to reconstruct both synthetic with D-NeRF~\\cite{pumarola2020dnerf} and real scenes in NR-NeRF~\\cite{tretschk2021nonrigid}.\n\nThe pros of directly including time as a function in the MLP are that we are able to represent a much broader class of functions, in theory every frame may be fully distinct from the previous, but the canonical formulation lends itself to smoothness between frames. Our approach falls into the canonization category, since we are interested in accurately reconstructing smooth movement as opposed to generalizing over many classes of movement.\n\n\\subsection*{Bezier Curves}\n\nBezier curves refer to a class of functions defined as a polynomial parametrized by a set of\ncontrol points. They are most commonly used as cubic polynomials: $f(x) = ax^3 + bx^2 + cx + d$,\nwhere x is the variable we are interested in interpolating over. The general formulation for\nthe Bezier basis functions is defined as $B^n(t) = \\Sigma^n_{i=0}\n{n \\choose i} (1-t)^{n-i} t^i$ where n\nis the degree of the Bezier polynomial. In order to give control of the Bezier curve, we\nintroduce \"control points\", which weighs different points along the curve differently:\n$B^n(t) = \\Sigma^n_{i=0} P_i {n \\choose i} (1-t)^{n-i} t^i$, where $P_i\\in\\mathbb{R}^3$ for 3D\nmovement. For a more comprehensive guide on Bezier splines, we refer the reader to a more\n\\href{https://pomax.github.io/bezierinfo/index.html}{complete reference}.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{bezier_curve.png}\n    \\caption{\n        Bezier Curves are a low dimensional representation of smooth interpolation between a few control points. We leverage them to represent smooth movement and produce a prior over movement. Credit to Wikipedia~\\cite{bezier_diagram} for diagram.\n    }\n    \\label{fig:my_label}\n\\end{figure}\n\n", "meta": {"hexsha": "57f25a43a2637a94fbb8f14f31ba12612c0f3943", "size": 4911, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "c0_paper/background.tex", "max_stars_repo_name": "princeton-computational-imaging/nerf_atlas", "max_stars_repo_head_hexsha": "f66ba284ea440cd816b303cdb7312288901da97e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2021-05-17T13:17:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T00:44:44.000Z", "max_issues_repo_path": "c0_paper/background.tex", "max_issues_repo_name": "princeton-computational-imaging/nerf_atlas", "max_issues_repo_head_hexsha": "f66ba284ea440cd816b303cdb7312288901da97e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-07T08:31:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-28T06:55:40.000Z", "max_forks_repo_path": "c0_paper/background.tex", "max_forks_repo_name": "princeton-computational-imaging/nerf_atlas", "max_forks_repo_head_hexsha": "f66ba284ea440cd816b303cdb7312288901da97e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2021-05-16T01:06:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-26T01:48:09.000Z", "avg_line_length": 96.2941176471, "max_line_length": 788, "alphanum_fraction": 0.7825290165, "num_tokens": 1186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7312265907804955}}
{"text": "\n\\chapter{Linear equations}\n\n\\section{Introduction}\n\nThe numerical solution of systems of linear equations can be a rather\ntaxing problem.    Solving a system like\n%\n\\begin{align*}\n  \\left\\{\n    \\begin{aligned}\n      2 x + 3 y & = 7, \\\\\n      x - y & = 1,\n    \\end{aligned} \\right.\n\\end{align*}\n%\nis easy.  Subtract twice the second equation from the first and obtain\n$y=1$ and $x=2$.  This procedure is fine  for a small system of linear\nequations.  However,  there are many  numerical  problems that require\nthe solution of linear systems with many equations.  For example, when\nintegrating numerically a Partial Differential  Equation it is typical\nto have to solve a $10000 \\times 10000$ system of linear equations.\n\nThere are other, less obvious, snags in solving a linear system of\nequations.     Consider the linear system\n%\n\\begin{align*}\n  \\left\\{\n    \\begin{aligned}\n      x + y & = 1, \\\\\n      2 x + 2 y & = 3.\n    \\end{aligned} \\right.\n\\end{align*}\n%\nThe second equation is incompatible with the first one and, therefore,\nthe system has no solution.    However, if the coefficients stored in\nthe computer are ever so slightly altered, for example to\n%\n\\begin{align*}\n  \\left\\{\n    \\begin{aligned}\n      0.999999 \\, x + y & = 0.999999, \\\\\n      2 x + 2 y &= 2.9999999 ,\n    \\end{aligned} \\right.\n\\end{align*}\n%\nthen the system will have a solution.    This is an example of an\nill-conditioned system: a very small change in the matrix of the\ncoefficients induces an enormous change in the solutions (from\nnon-existence to existence in this case).\n\nFrom these two examples, we can see the problems that have to\nbe solved in   devising  algorithms  for  solving systems  of   linear\nequations.  The algorithms  should be fast, so   that huge systems  of\nequations can be solved in a reasonable length of time and they should\nbe accurate, i.e.\\ they  should not introduce approximation errors that\ngrow out of  bounds.  Moreover, if a linear  system cannot be  solved\naccurately (second example), we must be  able to find functions of the\nmatrix coefficients that  can  be used as   an health warning  against\nputting too much trust in the solutions.\n\nIf we want to know how close the  numerical solution is to the correct\nsolution we  must    first define  the   concept  of  ``length''   and\n``distance'' for vectors  and matrices.  Once this is  done we will be\nable to find appropriate functions of  the matrix coefficients that we\ncan use to  check the accuracy of  the numerical results.   Only after\nthis ground work has been  carried out we will be  able to discuss how\nto solve a linear system of equations.\n\n\\section{Some definitions}\n\n\\subsection{Introduction}\n\nUnless otherwise stated, we plan to solve\n%\n\\begin{equation*}\n  A \\bx = \\bb ,\n\\end{equation*}\n%\nwhere $A$ is a $n \\times n$ real  matrix, $\\bx = (x_1, \\ldots, x_n)^T$\nis the vector of unknowns and $\\bb = (b_1, \\ldots,  b_n)^T$ is a given\nreal vector.  Moreover,  we indicate with $I$  the identity matrix and\nwith $0$ the zero matrix.\n\nThe basic theory of systems of linear equations states that the\nequations $A \\bx = \\bb $ have a unique solution if and only if\n$\\det(A) \\ne 0$, that solution being $\\bx = A^{-1} \\bb$.  For the case\n$\\det(A) = 0$, the equations either have no solutions (inconsistent\nset) or an infinite number of solutions (undetermined set).\n\n\\smallskip\n\n\\noindent {\\bf Remark} - Numerically, finding $\\bx$ using $\\bx =\nA^{-1} \\bb$ is invariably bad: there are faster and more accurate\nmethods to solve a linear system of equations.\n\n\\subsection{Vector and matrix norms}\n\n\\subsubsection{Vector norms}\n\nLet   $\\bRn$ be  the   set of all    $n$-dimensional vectors with real\ncomponents.   A \\textit{norm}  on $\\bRn$ is  a function  $\\norm{\\cdot}$\nwhich assigns a real value to each vector in $\\bRn$ (the ``length'' of\nthe vector) and satisfies\n%\n\\begin{enumerate}\n\\item $\\norm{\\bx} \\ge 0 \\, \\, \\forall \\bx \\in \\bRn$, with $\\norm{\\bx} = 0$\nif and only if $\\bx = 0$.\n\\item $\\norm{\\alpha \\bx} = | \\alpha| \\norm{\\bx} \\, \\, \\forall \\bx \\in \\bRn,\n\\, \\forall \\alpha \\in \\bR$.\n\\item $\\norm{\\bx + \\by} \\le \\norm{\\bx} + \\norm{\\by}, \\, \\, \\forall \\bx, \\by\n\\in \\bRn$.\n\\end{enumerate}\n\nSome common norms are:\n%\n\\begin{center}\n  \\begin{tabular}{ll@{\\hspace{5mm}}l}\n    $\\displaystyle \\norm{\\bx}_1 \\equiv \\sum_{j=1}^n |x_j|$ ,\n    & & $\\displaystyle \\norm{\\bx}_2 \\equiv \\left [ \\sum_{j=1}^n (x_j)^2 \\right ]^{1/2}$, \\\\\n    $\\displaystyle \\norm{\\bx}_p \\equiv \\left [ \\sum_{j=1}^n (x_j)^p \\right ]^{1/p}\n    \\, p>0$,\n    & & $\\displaystyle \\norm{\\bx}_\\infty = \\max_j |x_j|$ .\n  \\end{tabular}\n\\end{center}\n\n\\noindent {\\bf Remark} - $\\norm{\\cdot}_2$ is called the\n\\textit{Euclidean norm}: it is the generalisation to $n$-dimensional\nspaces of the distance between two points in the coordinate plane.\n\n\n\\subsubsection{Matrix norms}\n\nLet $M_n$ denote the set of all real $n \\times n$ matrices.   A\n\\textit{norm} on $M_n$ is a function $\\norm{ \\cdot }$ which assigns a\nreal value to each matrix in $M_n$ and that satisfies\n%\n\\begin{enumerate}\n\\item $\\norm{ A } \\ge 0 \\, \\, \\, \\forall A \\in M_n$.  Moreover $\\norm{ A } =\n  0$ if and only if $A = 0$.\n\\item $\\norm{ \\alpha A } = | \\alpha | \\norm{ A } \\, \\, \\, \\forall A \\in M_n\n  \\, \\, \\, \\forall \\alpha \\in \\bR$.\n\\item $\\norm{A + B} \\le \\norm{A} + \\norm{ B } \\, \\, \\, \\forall A,B \\in\n  M_n$.\n\\item $ \\norm{ A B } \\le \\norm{ A } \\norm{ B } $\n\\end{enumerate}\n\n\\smallskip\n\nVector norms can be used to define a family of matrix norms, called\n\\textit{induced norms}: these are the only ones used in this unit. The norm\nof a vector $\\norm{ \\bx }$ measures its length; therefore, $\\norm{ A \\bx }$\nis the length of the vector $\\bx$ transformed by the matrix $A$.  We\ncan define a matrix norm as the maximum relative ``stretching''\ninduced by the matrix $A$.  More formally, if $\\norm{ \\cdot }$ is a norm\ndefined in $\\bRn$ then we a define a function (norm) $\\norm{ \\cdot }$ on\nthe matrix space $M_n$ as\n%\n\\begin{equation*}\n\\norm{ A } \\equiv \\max_{\\norm{ \\bx } = 1} \\norm{ A \\bx } .\n\\end{equation*}\n\n\n\\smallskip\n\nThese norms are said to be \\textit{induced} by the corresponding\nvector norm and we use the same symbol for the matrix and the vector\nnorm.   For example,\n%\n\\begin{align*}\n  \\norm{ A }_1 & \\equiv \\max_{\\norm{ \\bx }_1 = 1} \\norm{ A \\bx }_1 , \\\\\n  \\norm{ A }_p & \\equiv \\max_{\\norm{ \\bx }_p = 1} \\norm{ A \\bx }_p , \\\\\n  \\norm{ A }_\\infty & \\equiv \\max_{\\norm{ \\bx }_\\infty = 1} \\norm{ A \\bx }_\\infty .\n\\end{align*}\n%\n\\smallskip\n\n\\noindent {\\bf Remark 1} - The vector and matrix norms are compatible:\n%\n\\begin{equation*}\n  \\norm{ A \\bx }_p \\le \\norm{ A }_p \\norm{ \\bx }_p .\n\\end{equation*}\n%\nHowever, we cannot mix norms.  For example, it is \\textbf{not} true in\ngeneral that $\\norm{ A \\bx }_1 \\le \\norm{ A }_2 \\norm{ \\bx }_2$.\n\n\\smallskip\n\n\\noindent {\\bf Remark 2} - The value of the matrix 1-norm is the\nmaximum of the 1-norms of the column vectors of the matrix:\n%\n\\begin{equation*}\n \\norm{ A }_1 = \\max_{1 \\le k \\le n} \\sum_{j=1}^n | a_{j k} | .\n\\end{equation*}\n%\n\n\\smallskip\n\n\\noindent {\\bf Remark 3} - The value of the matrix infinity-norm is\nthe maximum of the 1-norms of the row vectors of the matrix:\n%\n\\begin{equation*}\n  \\norm{ A }_\\infty = \\max_{1 \\le k \\le n} \\sum_{j=1}^n | a_{k j} | .\n\\end{equation*}\n\n\\subsection{The condition number}\n\nWe  now  have the   tools  to assess  the reliability  of  a numerical\nsolution of  a system of linear equations.    Given a system  $A \\bx =\n\\bb$ call $\\bx_c$ the computed solution and $\\bx_t$ the true solution.\nDefine an additional vector $\\br$ (\\textit{residual}) as,\n%\n\\begin{equation*}\n \\br = A \\bx_c - \\bb .\n\\end{equation*}\n%\nAny numerical    method that attempts  to solve   the linear system of\nequations tries to  minimise the  vector $\\br$: if  $\\br =  0$ the\nproblem is solved exactly.  We can rewrite $\\br$ as\n%\n\\begin{equation*}\n  \\br = A \\bx_c - A \\bx_t \\implies \\bx_c - \\bx_t = A^{-1} \\br .\n\\end{equation*}\n%\nWe can  see from this expression  that if $A^{-1}$  is ``ill behaved''\nthen  even   though $\\br$  is very  small   the difference between the\ncomputed and the true solution  can be very  large.  The\n\\textit{condition number of the matrix}, $K(A)$, is the\nquantity\n%\n\\begin{equation*}\n  K(A) = \\norm{ A } \\, \\norm{ A^{-1} },\n\\end{equation*}\n%\nand we call ${\\cal E}$ the \\textit{weighted residual},\n%\n\\begin{equation*}\n  {\\cal E} = \\frac{\\norm{ \\br }}{\\norm{ \\bb }} =\n  \\frac{\\norm{ A \\bx_c - \\bb }}{\\norm{ \\bb }} .\n\\end{equation*}\n%\nOne can show that\n%\n\\begin{equation}\n \\frac{1}{K(A)} {\\cal E} \\le\n      \\frac{ \\norm{ \\bx_c - \\bx_t }}{\\norm{ \\bx_t }} \\le\n      K(A) {\\cal E} .\n \\label{cond_and_res}\n\\end{equation}\n%\nThe condition number is always greater or equal to one, $K(A) \\ge 1$.\nIf $K(A) \\simeq 1$ then the relative error is of the same order of the\nweighted residual: if the numerical method we have used has converged\nto a solution with small weighted residual we can be confident of the\naccuracy of the solution.  However, if the condition number is big,\n$K(A) \\gg 1$, then, even though the weighted residual may be very\nsmall, the relative error in the solution may be extremely large.\n\n\\subsection{Ill-conditioned systems}\n\nThe condition number gives us a warning that the solution may not be\naccurate.     We must discuss a little bit more at length what this\nimplies.     Consider the linear system\n%\n\\begin{align}\n  \\left\\{\n    \\begin{aligned}\n      x + 2 y & = 3 , \\\\\n      0.499 x + 1.001 y & = 1.5 .\n    \\end{aligned} \\right.\n \\label{ill_cond_1}\n\\end{align}\n%\nThe solution is $x = y = 1$.       Consider now a system with the same\nfirst equation and a slightly different second equation:\n%\n\\begin{align}\n  \\left\\{\n    \\begin{aligned}\n      x + 2 y & = 3 , \\\\\n      0.5 x + 1.001 y & = 1.5 .\n    \\end{aligned} \\right.\n \\label{ill_cond_2}\n\\end{align}\n%\nThe solution of this second system is $x = 3$ and $y=0$.    In other\nwords, an extremely small change in one of the coefficients has\nproduced an enormous change in the solution.\n\nWe can analyse this result in terms of the condition number.   The\nmatrix of the coefficients and its inverse are\n%\n\\begin{equation*}\n  A =\n  \\begin{pmatrix}\n    1 & 2 \\\\\n    \\dfrac{499}{1000} & \\dfrac{1001}{1000} \\\\\n  \\end{pmatrix}\n  \\qquad\n  A^{-1} =\n  \\begin{pmatrix}\n   \\dfrac{1001}{3} & \\dfrac{-2000}{3} \\\\\n   \\dfrac{-499}{3} & \\dfrac{1000}{3} \\\\\n  \\end{pmatrix}\n\\end{equation*}\n%\nwith infinity norms (maximum of the 1-norm of the rows)\n%\n\\begin{equation*}\n  \\norm{ A }_\\infty = 3 , \\quad \\norm{ A^{-1} }_\\infty = \\frac{3001}{3}\n  \\implies K(A) = 3001 .\n\\end{equation*}\n%\nThe condition number is big, as expected. To summarise this example,\nthe following statements are roughly equivalent:\n%\n\\begin{itemize}\n%\n\\item The linear system is such that a small change in specification of\nthe problem can lead to a large change in relative error; \\par\n%\n\\item The condition number is large, $K(A) \\gg 1$; \\par\n%\n\\item The system is ill conditioned; \\par\n%\n\\item As for all ill-conditioned problems, the relative error may be\ndisastrous even if the residual is very small.\n%\n\\end{itemize}\n\nBeing or not being ill-conditioned is a property of the linear system\nunder study and cannot be eliminated by some cunning numerical\nalgorithm. The best we can hope for is to have some warning that\nthings may go horribly wrong: this is the purpose of the condition\nnumber.\n\nWhile there are techniques based on the Singular Value Decomposition\nthat try to extract as much information as possible from an\nill-conditioned system, they are well beyond the scope of this unit\nand from now on we will assume that the linear system we intend to\nsolve is perfectly well behaved, i.e.\\ has a condition number of the\norder of unity.\n\n\\section{Direct methods}\n\n\\subsection{Introduction}\n\nIt is not  possible to  dwell  on all  the  techniques that have  been\ndeveloped to  solve  linear  systems of  equations.    The most recent\nmethods    can be  very  involved    and their  implementation may  be\nconsidered skilled craftsmanship.  Instead,  we introduce the simplest\nexamples  of  the two  main  categories  of  methods to  solve  linear\nsystems.  While it is  true that no present  day linear system  solver\nuses these methods as we describe them, it is also true that most\nof the present day techniques are deeply rooted in these methods.\n\nThere are two big families of algorithms for solving linear systems:\nthe first, the \\textit{direct methods}, consist of a finite list of\ntransformations of the original matrix of the coefficients that reduce\nthe linear systems to one that is easily solved.  The second family,\nthe \\textit{indirect or iterative methods}, consists of algorithms\nthat specify a series of steps that lead closer and closer to the\nsolution without, however, ever exactly reaching it.  This may not\nseem a very desirable feature until we remember that we cannot in any\ncase represent an exact solution: most iterative methods provide us\nwith a highly accurate solution in relatively few iterations.\n\n\\subsection{Gaussian elimination}\n\nThe idea behind Gaussian elimination (and all direct methods) is that\nsome linear systems of equations are very easy to solve.   Suppose for\nexample, that we wish to solve the problem $A \\bx = \\bb$ where $A$ is\nan upper triangular matrix, i.e.\\ $a_{i j} = 0$ if $j < i$.    This\nequation can be solved by simple back-substitution.   Consider, for\nexample, the system\n%\n\\begin{equation*}\n  A \\bx =\n  \\begin{pmatrix}\n    3 & 2 & 1 \\\\ 0 & 5 & 4 \\\\ 0 & 0 & 6\n  \\end{pmatrix}\n  \\begin{pmatrix}\n    x_1 \\\\ x_2 \\\\ x_3\n  \\end{pmatrix}\n =\n \\begin{pmatrix}\n   1 \\\\ 2 \\\\ 3\n \\end{pmatrix}\n = \\bb .\n\\end{equation*}\n%\nThe last equation is trivial and we can easily obtain $x_3$.  Once\n$x_3$ is known it can be substituted in the second equation\n(back-substitution) and so on:\n%\n\\begin{align*}\n 6 x_3               & = 3 && \\implies & x_3                 & = \\frac{1}{2} , \\\\\n 5 x_2 + 4 x_3       & = 2 && \\implies & 5 x_2 + 2           & = 2 \\\\\n                     &     && \\implies & x_2                 & = 0 , \\\\\n 3 x_1 + 2 x_2 + x_3 & = 1 && \\implies & 3 x_1 + \\frac{1}{2} & = 1 \\\\\n                     &     && \\implies & x_1                 & = \\frac{1}{6} .\n\\end{align*}\n\nThe Gauss elimination algorithm consists of a series of steps that\ntransform a generic $n \\times n$ matrix $A$ with elements $a_{i j}$\ninto an upper triangular matrix so that the ensuing linear system can\nbe solved by back substitution.  The algorithm is as follows:\n\n\\begin{enumerate}\n\n\\item Replace the $j$-th equation with\n%\n  \\begin{equation*}\n    -\\frac{a_{j 1}}{a_{1 1}} \\times ( 1^{\\rm st} \\text{equation} ) +\n    ( j\\text{-th equation} ) ,\n  \\end{equation*}\n%\nwhere $j$ is an index that runs from 2 to $n$.  In implementing this\nalgorithm by hand it is convenient to write $A$ and $\\bb$ as a single\n$n \\times (n+1)$ matrix called the \\textit{augmented matrix}.\nConsider for example\n%\n\\begin{equation*}\n  A =\n  \\begin{pmatrix}\n    1 & 2 & 3 \\\\ 4 & 5 & 6 \\\\ 7 & 8 & 0\n  \\end{pmatrix}\n , \\quad\n  \\bb =\n  \\begin{pmatrix}\n    10 \\\\ 11 \\\\ 12\n  \\end{pmatrix},\n\\end{equation*}\n%\nand write them as\n%\n\\begin{equation*}\n\\left (\n  \\begin{array}{c c c|c}\n   1 & 2 & 3 & 10 \\\\ 4 & 5 & 6 & 11 \\\\ 7 & 8 & 0 & 12 \\\\\n  \\end{array}\n \\right ) .\n\\end{equation*}\n%\nBy applying the first step of the algorithm to this matrix we obtain\n%\n\\begin{equation*}\n  \\left (\n  \\begin{array}{c c c|c}\n   1 & 2 & 3 & 10 \\\\\n   0 & 5 - 4 \\times 2 & 6 - 4 \\times 3 & 11 - 4 \\times 10 \\\\\n   0 & 8 - 7 \\times 2 & 0 - 7  \\times 3 & 12 - 7 \\times 10\n  \\end{array}\n \\right ) =\n \\left (\n  \\begin{array}{c c c|c}\n   1 & 2 & 3 & 10 \\\\\n   0 & -3 & -6 & -29 \\\\\n   0 & -6 & -21 & -58\n  \\end{array}\n \\right )\n\\end{equation*}\n%\n{\\bf Remark} - If $a_{1 1}=0$ swap the first row with one whose first\nelement is non zero.\n\n\\item Repeat the previous step, but starting with the next row down\nand with $j$ greater than the row number.   If the current row is row\n$k$ then we must replace row $j$, $j > k$, with\n%\n%\n\\begin{equation*}\n   -\\frac{a_{j k}}{a_{k k}} \\times ( k^{\\rm th} \\text{ equation} ) +\n   ( j^{\\rm th}\\text{ equation} ) ,\n \\end{equation*}\n%\nwhere $j$ is an index, $k < j \\le n$.    The coefficient $a_{k k}$ is\ncalled the \\textit{pivot}. In the case of our example system we have:\n%\n\\begin{equation*}\n  \\left (\n  \\begin{array}{c c c|c}\n   1 & 2 & 3 & 10 \\\\\n   0 & -3 & -6 & -29 \\\\\n   0 & -6 - 2 (-3) & -21 - 2 (-6) & -58 - 2 (-29)\n  \\end{array}\n \\right ) =\n \\left (\n  \\begin{array}{c c c|c}\n   1 & 2 & 3 & 10 \\\\\n   0 & -3 & -6 & -29 \\\\\n   0 & 0 & -9 & 0\n  \\end{array}\n \\right ) .\n\\end{equation*}\n\n\n\\item When all the rows have been reduced, the matrix has been\ntransformed in an upper triangular matrix and the linear system can be\nsolved by back-substitution.\n\n\\end{enumerate}\n\n\\noindent {\\bf Remark} - When designing an algorithm it is important\nto keep track of the number of operations required to solve the\nproblem.   For example, an algorithm which involves a number of\noperations that increases exponentially with the problem size becomes\nvery quickly useless (such problems are called non-polynomial and are\nsome of toughest nuts to crack in numerical analysis.  The most famous\nexample is the travelling salesman problem).    The Gauss elimination\nalgorithm is an $n^3$ algorithm, i.e.\\ it requires a number of floating\npoint operations that grows with the cube of the problem size.\n\n\\subsection{Pivoting strategies}\n\nThe Gauss elimination method just outlined suffers from poor accuracy\nif the matrix coefficients are of very different size.   Consider, for\nexample, the system\n%\n\\begin{equation*}\n  \\begin{cases}\n    10^{-5} x_1 + x_2 &= 1 , \\\\ x_1 + x_2 &= 2 .\n  \\end{cases}\n\\end{equation*}\n%\nThe 1-norm of the matrix of coefficients, $A$, is $\\norm{ A }_1 =\n2$.  The inverse of $A$ is\n%\n\\begin{equation*}\n  A^{-1} = \\frac{1}{10^{-5}-1}\n  \\begin{pmatrix}\n    1 & -1 \\\\ -1 & 10^{-5}\n  \\end{pmatrix} ,\n\\end{equation*}\n%\nand has 1-norm $\\norm{A^{-1}}_1 = 2/(1-10^{-5}) \\simeq 2$ so that the\nmatrix condition number is a most benign $K(A) \\simeq 4$.   The problem\nis not ill-conditioned and we should not expect any problem in finding\nan accurate solution.\n\nWe can solve the problem exactly using Gauss elimination.   By\nsubtracting $10^5$ times the first equation from the second  we obtain\nthe following augmented matrix and solution:\n%\n\\begin{equation*}\n  \\left (\n   \\begin{array}{c c|c}\n    10^{-5} & 1 & 1 \\\\\n    0 & -99999 & -99998\n   \\end{array}\n  \\right )\n  \\implies\n  \\begin{aligned}\n    x_2 &=  \\dfrac{-99998}{-99999} &&= 0.9999899\\ldots && \\simeq 1 , \\\\*[2mm]\n    x_1 &=  \\dfrac{10^5}{99999} &&= 1.00001000\\ldots && \\simeq 1 .\n  \\end{aligned}\n\\end{equation*}\n%\nIf, however, we now solve the same problem using floating point\nnotation and only four significant figures, i.e.\\ $m=4$, we obtain a\nrather different result.    The augmented matrix is now\n%\n\\begin{align}\n   \\left (\n    \\begin{array}{c c|c}\n      0.1000 \\times 10^{-4} & 0.1000 \\times 10 & 0.1000 \\times 10 \\\\\n      0.1000 \\times 10 & 0.1000 \\times 10 & 0.2000 \\times 10\n    \\end{array}\n  \\right ) & \\implies \\\\\n   \\left (\n    \\begin{array}{c c|c}\n      0.1000 \\times 10^{-4} & 0.1000 \\times 10 & 0.1000 \\times 10 \\\\\n      0.0000 \\times 10^{0} & -0.1000 \\times 10^6 & -0.1000 \\times 10^6\n    \\end{array}\n  \\right ) & \\implies\n  \\begin{cases}\n    x_2 &= 1, \\\\ x_1 &= 0 .\n  \\end{cases}\n\\end{align}\n%\nThis is an example of \\textit{poor scaling}: whenever the coefficients\nof a linear system are of greatly varying sizes, we may expect that\nrounding errors may build up due to loss of significant figures.\nWhile ill-conditioning is an incurable ``illness'' because it is\nintrinsic to the matrix of coefficients, poor scaling is related\nto the algorithm and can be eliminated by suitably modifying the\nprocedure to solve the linear system.     In the case of this example,\neverything works fine if we first exchange the two rows so that the\nfirst row is the one with the biggest coefficient.    In this case,\nthe second row is transformed during Gaussian elimination by\nsubtracting from it the first row multiplied by $10^{-5}$ and no\nrounding errors occur:\n%\n\\begin{align}\n  \\left (\n    \\begin{array}{c c|c}\n      0.1000 \\times 10 & 0.1000 \\times 10 & 0.2000 \\times 10 \\\\\n      0.1000 \\times 10^{-4} & 0.1000 \\times 10 & 0.1000 \\times 10\n    \\end{array}\n  \\right ) & \\implies \\\\\n  \\left (\n    \\begin{array}{c c|c}\n      0.1000 \\times 10 & 0.1000 \\times 10 & 0.2000 \\times 10 \\\\\n      0.0000 \\times 10^{0} & 0.1000 \\times 10 & 0.1000 \\times 10\n    \\end{array}\n  \\right ) & \\implies\n  \\begin{cases}\n    x_2 &= 1, \\\\ x_1 &= 1 .\n  \\end{cases}\n\\end{align}\n%\nThe solutions are very close to the exact solution as we would have\nexpected from the analysis of the condition number.\n\nThe procedure of  exchanging rows  (or columns) in  order  to have the\nbiggest pivot  (i.e.\\ the first  coefficient of the  row that is  to be\nsubtracted from all the  subsequent rows) is called \\textit{pivoting}.\nFrom the above example we can conclude that, in the $k$-th step of the\nGauss elimination algorithm, we want to replace row $j$ with\n%\n\\begin{equation*}\n  \\text{Row}_j \\rightarrow \\text{Row}_j - \\varepsilon \\, \\text{Row}_k,\n\\end{equation*}\n%\nwhere $\\varepsilon$ is a small number, ideally as small as possible.\nThis can be easily arranged: at each step of the algorithm we\nrearrange the set of equations so that we are eliminating using the\nlargest pivot in modulus.\n\nNotice that the factors that multiply the rows are always smaller than\nunity.    This procedure is called \\textit{partial pivoting}.\n\nAn algorithm that is similar to the one above, but that exchanges both\nrows and columns in order that the biggest element in the matrix is\nthe pivot is called \\textit{total pivoting}.  However, total pivoting\ninvolves moving around huge chunks of computer memory and also doing\nan exhaustive search for the biggest matrix element.  This practical\nproblems are such that Gaussian elimination with partial pivoting\nis preferred.\n\n\\subsection{Decomposition methods}\n\n\\subsubsection{Introduction}\n\nDecomposition methods attempt to rewrite the matrix of coefficients as\nthe product of two matrices.  The advantage of this approach is that\nthe solution of a linear system of equations is split into smaller and\nconsiderably easier tasks.  There are many decomposition techniques,\nbut we are going to discuss only the simplest scheme, the $LU$\ndecomposition, in order to understand the principles behind this\napproach to finding the solution of a linear system of equations.\n\nSuppose that we are able to write the matrix $A$ of coefficients of\nthe linear system $A \\bx = \\bb$ as\n%\n\\begin{equation*}\n  A = L U ,\n\\end{equation*}\n%\nwhere  $L$ is lower  triangular   and $U$  is  upper triangular.   The\nsolution  of the linear   system of equations becomes straightforward.\nWe can write\n%\n\\begin{equation*}\n  A \\bx = \\bb \\implies ( L \\, U ) \\, \\bx = \\bb \\implies\n  L \\left ( U \\bx \\right ) = \\bb .\n\\end{equation*}\n%\nIf we call $\\by = U \\bx $, then we have transformed the original\nlinear system in two systems,\n%\n\\begin{align}\n  L \\by &= \\bb , \\label{L_eq} \\\\\n  U \\bx &= \\by . \\label{U_eq}\n\\end{align}\n%\nEach of these systems is triangular.  The system~(\\ref{L_eq}) is lower\ntriangular and can be solved by forward substitution while the\nsystem~(\\ref{U_eq}) is upper triangular and can be solved by back\nsubstitution.   Therefore, even though we must solve two linear\nsystems instead of only one, each of the two is very easy to solve.\nThis is an advantage with respect to Gauss elimination especially if\nwe have to solve $A \\bx = \\bb$ for many different values of the vector\n$\\bb$: we need to factorise the matrix $A$ only once and then use the\nfactorisation to find the solution vector $\\bx$ for all the different\nvalues of the known vectors $\\bb$.\n\n\\medskip\n\nThere are two questions that we must now answer: ``How can we\nfactorise a matrix?'' and ``Is the factorisation possible?''  We will\nanswer the first question first and then discuss at more length the\nanswer to the second.\n\n\\subsubsection{Factorisation of a matrix}\n\nA first thing to note is that the $L U$ factorisation as described\nabove is not unique.   $A$ is a $n \\times n$ matrix and has therefore\n$n^2$ coefficients.   $L$ and $U$ are both triangular and thus have\n$n(n+1)/2$ entries each for a total of $n^2 + n$ entries.\nIn other words, $L$ and $U$ have together $n$ coefficients more than the\noriginal matrix $A$.  Therefore we can choose $n$ coefficients of $L$\nand $U$ to our own liking.\n\nTo derive a formula for the $LU$ factorisation we start by writing\nexplicitly in terms of the components the decomposition $A = L U$.\nCall $a_{i j}$, $\\ell_{i j}$ and $u_{i j}$ the elements respectively\nof $A$, $L$ and $U$.    The following relation must hold:\n%\n\\begin{equation}\n  a_{i j} = \\sum_{s=1}^n \\ell_{i s} u_{s j} =\n  \\sum_{s=1}^{\\min(i,j)} \\ell_{i s} u_{s j} ,\n  \\label{LU_fact}\n\\end{equation}\n%\nwhere we have used the fact that $\\ell_{i s} = 0$ for $s>i$ and $u_{s\nj}=0$ for $s > j$.\n\nLet us start with $i=j=1$.   Equation~(\\ref{LU_fact}) reduces to\n%\n\\begin{equation*}\n a_{1 1} = \\ell_{1 1} u_{1 1} .\n\\end{equation*}\n%\nWe can now make use of the freedom of choosing $n$ coefficients of $L$\nand $U$.     The most common choices are:\n%\n\\begin{itemize}\n%\n\\item \\textit{Doolittle's factorisation} - Set $\\ell_{i i} = 1$,\ni.e.\\ the matrix $L$ is \\textit{unit} lower triangular.\n%\n\\item \\textit{Crout's factorisation} - Set $u_{i i} = 1$, i.e.\\ the\nmatrix $U$ is \\textit{unit} upper triangular.\n%\n\\end{itemize}\n\n\\begin{table}\n  \\begin{center}\n    \\fbox{\n      \\parbox[t]{80mm}{\n        \\setlength{\\parindent}{0pt} \\footnotesize\n        \\textbf{for} $k = 1,2,\\ldots,n$ \\textbf{do} \\par\n        \\hspace{5mm}\n        Specify a nonzero value for either $\\ell_{k k}$ (Doolittle) \\par\n        \\hspace{5mm}or $u_{k k}$ (Crout) and compute the other from\n        \\begin{equation*}\n          \\ell_{k k} u_{k k} =\n          a_{k k} - \\sum_{s=1}^{k-1} \\ell_{k s} u_{s k} .\n        \\end{equation*}\n\n        \\hspace{5mm} Build the $k$-th row of $U$:\\par\n        \\hspace{5mm} \\textbf{for} $j=k+1,k+2, \\ldots, n$ \\textbf{do} \\par\n        \\begin{equation*}\n          u_{k j} = \\left( a_{k j} -\n            \\sum_{s=1}^{k-1} \\ell_{k s} u_{s j} \\right) / \\ell_{k k}\n        \\end{equation*}\n        \\hspace{5mm} \\textbf{end}\n\n        \\smallskip\n\n        \\hspace{5mm} Build the $k$-th column of $L$:\\par\n        \\hspace{5mm} \\textbf{for} $i=k+1,k+2, \\ldots, n$ \\textbf{do} \\par\n        \\begin{equation*}\n          \\ell_{i k} = \\left( a_{i k} -\n            \\sum_{s=1}^{k-1} \\ell_{i s} u_{s k} \\right) / u_{k k}\n        \\end{equation*}\n        \\hspace{5mm} \\textbf{end}\n\n        \\smallskip\n\n        \\textbf{end}\n      }\n    }\n  \\end{center}\n  \\caption{\\label{doocrout} \\it Algorithm for the Doolittle and Crout\n    factorisation methods.}\n\\end{table}\n\nFollowing the Doolittle's factorisation we set $\\ell_{1 1} = 1$ and\nobtain\n%\n\\begin{equation*}\n  u_{1 1} = a_{1 1} .\n\\end{equation*}\n%\nWe can now compute all the elements of the first row of $U$ and of the\nfirst column of $L$, by setting either $i=1$ or $j=1$:\n%\n\\begin{align}\n  u_{1 j} & = a_{1 j} , & i & = 1, \\, j > 1 \\\\\n  \\ell_{i 1} &= a_{i 1} / u_{1 1} , & j & = 1, \\, i > 1 .\n\\end{align}\n%\nConsider now $a_{2 2}$.   Equation~(\\ref{LU_fact}) becomes:\n%\n\\begin{equation*}\n  a_{2 2} = \\ell_{2 1} u_{1 2} + \\ell_{2 2} u_{2 2} .\n\\end{equation*}\n%\nIf, according to the Doolittle's scheme, we set $\\ell_{2 2} = 1$ we\nhave:\n%\n\\begin{equation*}\n  u_{2 2} = a_{2 2} - \\ell_{2 1} u_{1 2} ,\n\\end{equation*}\n%\nwhere $\\ell_{2 1}$ and $u_{1 2}$ are known from the previous steps.\nWe can now compute the second row of $U$ and the second column of $L$\nby setting either $i=2$ or $j=2$:\n%\n\\begin{align}\n  u_{2 j} & = a_{2 j} - \\ell_{2 1} u_{1 j}, & i & = 2, \\, j > 2 \\\\\n  \\ell_{i 2} & = \\left ( a_{i 2} - \\ell_{i 1} u_{1 2} \\right )/ u_{2\n    2} & j & = 2, \\, i > 2.\n\\end{align}\n%\nThis procedure can be repeated for all the rows and columns of $U$ and\n$L$.   The compact version of the algorithm for $LU$ decomposition using\neither Doolittle's or Crout's method is listed in\nTable~\\ref{doocrout}.\n\n\n\\smallskip\n\n\\noindent \\textbf{Remark 1} - Notice that for the algorithm to work\n$\\ell_{k k}$ and $u_{k k}$ must be different from zero.  However, this\nshould not be interpreted as a condition for the matrix to have an\n$LU$ decomposition.   The following matrix,\n%\n\\begin{equation*}\n  \\begin{pmatrix}\n    2 & 1 & -2 \\\\ 4 & 2 & -1 \\\\ 6 & 3 & 11\n  \\end{pmatrix}\n\\end{equation*}\n%\nhas $u_{2 2} =0 $, but it can be written as the product of\n%\n\\begin{equation*}\n  L =\n  \\begin{pmatrix}\n    1 & 0 & 0 \\\\ 2 & 1 & 0 \\\\ 3 & 0 & 1\n  \\end{pmatrix}\n  \\quad \\text{and} \\quad\n  U =\n  \\begin{pmatrix}\n    2 & 1 & -2 \\\\ 0 & 0 & 3 \\\\ 0 & 0 & 17\n  \\end{pmatrix} .\n\\end{equation*}\n\n\n\\noindent \\textbf{Remark 2} - The $LU$ decomposition with $L$ unit\ntriangular and  the  Gauss elimination algorithm are  closely related.\nThe matrix $U$ is the matrix of the coefficients reduced to triangular\nform using Gaussian  elimination.  The matrix  $L$ can be obtained  by\nwriting  each multiplier in   the location corresponding  to  the zero\nentry in the matrix it was responsible for creating.   Therefore one\ncan use Gaussian elimination to find the $LU$ decomposition of a\nmatrix.   The advantage of $LU$ decomposition over Gaussian elimination\nis that if we have to solve many linear systems $A \\bx = \\bb$ for many\ndifferent values of $\\bb$, we need to do only one $LU$ decomposition.\n\n\\noindent \\textbf{Remark 3} - Pivoting is essential for the accuracy\nof this algorithm.\n\n\\subsubsection{Conditions for factorisation}\n\nWe must now specify under what conditions a matrix can be decomposed\nas the product of two triangular matrices.  What follows is a list of\nsufficient conditions for the decomposition to be possible.  We start\nwith a theorem that involves the minors of $A$.\n\n\\smallskip\n\n\\begin{theorem}\n\\label{LUexists}\nIf all $n-1$ leading principal minors\\footnote{A principal minor of\norder $k$ is the minor\n%\n\\begin{equation*}\n  \\begin{pmatrix}\n    a_{1 1} & \\cdots & a_{1 k} \\\\\n    \\vdots & \\ddots & \\vdots \\\\\n    a_{k 1} & \\cdots & a_{k k}\n  \\end{pmatrix}\n\\end{equation*}\n%\n} of the   $n \\times n$  matrix  $A$ are nonsingular,  then  $A$ has an\n$LU$ decomposition.   If the $LU$ decomposition exists and $A$ is non\nsingular, then the $LU$ decomposition is unique and $\\det(A)=u_{11}\nu_{22} \\ldots u_{nn}$ (assuming that the matrix has been decomposed\naccording the the Doolittle method).\n\\end{theorem}\n\n\\noindent Proof: Golub \\& Van Loan, \\textit{Matrix computations}, page\n97 (Third edition, 1996)\n\n\\smallskip\n\n\\noindent\n\\textbf{Remark 1} - This theorem is a consequence of the relation\nbetween Gaussian elimination and $LU$ decomposition.   It is possible to\ndecompose the matrix in a lower and a upper triangular form if all the\npivots in the Gaussian elimination are different from zero.   The\nhypotheses in the above theorem ensure that this is the case.\n\n\\smallskip\n\n\\noindent\n\\textbf{Remark 2} - It is not sufficient for a matrix to be\nnon-singular in order for it to have an $LU$ decomposition.  However, if\nthe matrix is non singular then there exists a suitable permutation of\nits rows such that the permuted matrix has a (unique)\n$LU$ decomposition.\n\nA concept that is extremely useful in determining the behaviour and\nconvergence of many algorithms to solve linear system is that of\n\\textit{diagonal dominance}.   A matrix is strictly diagonally dominant if the\nmodulus of each diagonal element is greater than the sum of the moduli\nof all the other elements in its row:\n%\n\\begin{equation*}\n  | a_{i i} | > \\sum_{\\genfrac{}{}{0pt}{}{j=1}{j \\ne i}}^n\n  | a_{i j} |, \\qquad (1 \\le i \\le n) .\n\\end{equation*}\n%\nThis may seem a rather peculiar condition to require on a matrix.   As\na matter of fact, it is not so for many applications of practical\ninterest.   For example, most algorithms that solve numerically\npartial differential equations using finite difference methods involve\nthe solutions of large linear systems whose matrix of coefficients is\ndiagonally dominant.\n\nThe importance of diagonal dominance from the point of view of\ndirect methods to solve linear systems of equations stems from the\nfollowing theorems:\n\n\\begin{theorem}\n\\label{diagdom1}\nEvery strictly diagonally dominant matrix is nonsingular and has an\n$LU$ decomposition.\n\\end{theorem}\n\n\\noindent Proof: Kincaid pages 190\n\n\\begin{theorem}\n\\label{diagdom2}\nGaussian elimination of a diagonally dominant matrix does not require\npivoting provided each row is first scaled with its maximum.\n\\end{theorem}\n\n\\noindent Proof: Kincaid page 190\n\n\\subsection{Cholesky factorisation}\n\nIn the case of a symmetric, positive definite matrix (i.e.\\ such that\n$\\bx^T A \\bx > 0 \\, \\, \\forall \\bx \\ne 0$) then it is possible to\nfactorise the matrix as $A = L L^T$, in which $L$ is lower triangular with\na positive diagonal (\\textit{Cholesky factorisation}).\n\nTo find the Cholesky decomposition of the matrix $A$ we can use an\nalgorithm similar to that developed for the Doolittle and Crout\nmethods and derived from it by assuming $U=L^T$.  Its description is\nin Table~\\ref{cholesky}.\n\n\\begin{table}\n  \\begin{center}\n    \\fbox{\n      \\parbox[t]{80mm}{\n        \\setlength{\\parindent}{0pt}\n        \\small\n        \\textbf{for} $k = 1,2,\\ldots,n$ \\textbf{do} \\par\n        \\hspace{5mm} Compute the diagonal element \\par\n        \\begin{equation*}\n          \\ell_{k k} =\n          \\left ( a_{k k} - \\sum_{s=1}^{k-1} \\ell_{k s}^2 \\right )^{1/2} .\n        \\end{equation*}\n\n        \\hspace{5mm} Build the $k$-th column of $L$:\\par\n        \\hspace{5mm} \\textbf{for} $i=k+1,k+2, \\ldots, n$ \\textbf{do} \\par\n        \\begin{equation*}\n          \\ell_{i k} = \\left ( a_{i k} -\n            \\sum_{s=1}^{k-1} \\ell_{i s} \\ell_{k s} \\right ) / \\ell_{k k}\n        \\end{equation*}\n        \\hspace{5mm} \\textbf{end}\n\n        \\smallskip\n\n        \\textbf{end}\n      }\n    }\n  \\end{center}\n  \\caption{\\label{cholesky} \\it Algorithm for the Cholesky\n    factorisation method}\n\\end{table}\n\n\\subsection{Tridiagonal systems}\n\n\\noindent Consider a $4\\times 4$ system\n%\n\\begin{equation*}\n  \\begin{pmatrix}\n    b_1 & c_1 & 0 & 0 \\\\\n    a_1 & b_2 & c_2 & 0 \\\\\n    0 & a_2 & b_3 & c_3 \\\\\n    0 & 0 & a_3 & b_4\n  \\end{pmatrix}\n  \\begin{pmatrix}\n    x_1 \\\\ x_2 \\\\ x_3 \\\\ x_4\n  \\end{pmatrix}\n  =\n  \\begin{pmatrix}\n    f_1 \\\\ f_2\\\\ f_3 \\\\ f_4\n  \\end{pmatrix}.\n\\end{equation*}\n%\nIt is called a \\textit{tridiagonal system}. Tridiagonal systems give\nrise to particularly simple results when using Gaussian elimination.\nForward elimination at each step yields a system\n%\n\\begin{equation*}\n  \\begin{pmatrix}\n    1 & c_1/d_1 & 0 & 0 \\\\\n    0 & 1 & c_2/d_2 & 0 \\\\\n    0 & 0 & 1 & c_3/d_3 \\\\\n    0 & 0 & 0 & 1\n  \\end{pmatrix}\n  \\begin{pmatrix}\n    x_1 \\\\ x_2 \\\\ x_3 \\\\ x_4\n  \\end{pmatrix}\n  =\n  \\begin{pmatrix}\n    y_1 \\\\ y_2\\\\ y_3 \\\\ y_4\n  \\end{pmatrix},\n\\end{equation*}\n%\nwhere\n%\n\\begin{align*}\n    d_1 &= b_1, & y_1 &= f_1/d_1, \\\\\n    d_2 &= b_2-a_1c_1/d_1, & y_2 &= (f_2-y_1 a_1)/d_2, \\\\\n    d_3 &= b_3-a_2c_2/d_2, & y_3 &= (f_3-y_2 a_2)/d_3, \\\\\n    d_4 &= b_4-a_3c_3/d_3, & y_4 &= (f_4-y_3 a_3)/d_4.\n\\end{align*}\n%\nFinally, the backward substitution procedure gives the answer\n%\n\\begin{equation*}\n  \\left\\{\n    \\begin{aligned}\n      x_4 &= y_4,\\\\\n      x_3 &= y_3-x_4 c_3/d_3,\\\\\n      x_2 &= y_2-x_3 c_2/d_2,\\\\\n      x_1 &= y_1-x_2 c_1/d_1.\n    \\end{aligned} \\right .\n\\end{equation*}\n%\nIt is clear what will happen in general case of $n\\times n$\ntridiagonal system.  The forward elimination procedure is\n\n\\begin{enumerate}\n  %\n\\item At the first step $d_1=b_1$ and $y_1=f_1/d_1$;\n  %\n\\item At the $k$-th step $d_k=b_k-a_{k-1}c_{k-1}/d_{k-1}$ and\n  $y_k=(f_k-y_{k-1} a_{k-1})/d_k$.\n%\n\\item Once all the $y_k$ have been computed, the $x_k$ can be\n  determined using backward substitution: $x_n = y_n$, \\ldots,\n  $x_{k-1}=y_{k-1}-x_k c_{k-1}/d_{k-1}$, \\ldots\n  %\n\\end{enumerate}\n\n\\section{Iterative methods}\n\n\\subsection{Introduction}\n\nThe direct methods for solving linear systems of order $n$ require\nabout $n^3/3$ operations.   In addition in practical computations with\nthese methods, the errors which are necessarily introduced through\nrounding may become quite large for large $n$.   Now we consider\niterative methods in which an approximate solution is sought by using\nfewer operations per iteration.   In general, these may be described\nas methods which proceed from some initial ``guess'', $\\bx^{(0)}$, and\ndefine a sequence of successive approximations $\\bx^{(1)}, \\bx^{(2)},\n\\ldots$ which, in principle, converge to the exact solution.    If the\nconvergence is sufficiently rapid, the procedure may be terminated at\nan early stage in the sequence and will yield a good approximation.\nOne of the intrinsic advantages of such methods is the fact that the\nerrors, due to roundoff or even blunders, may be damped out as the\nprocedure continues.   In fact, special iterative methods are\nfrequently used to improve ``solutions'' obtained by direct methods.\n\nA large class of iterative methods may be defined as follows.   Let\nthe system to be solved be\n%\n\\begin{equation}\n A \\bx = \\bb , \\label{Axb}\n\\end{equation}\n%\nwhere $\\det(A) \\ne 0$.   Then the coefficient matrix can be\nsplit, in an infinite number of ways, into the form\n%\n\\begin{equation*}\n  A = N - P ,\n\\end{equation*}\n%\nwhere $N$ and $P$ are matrices of the same order as $A$.    The\nsystem~(\\ref{Axb}) is then written as\n%\n\\begin{equation}\n  N \\bx = P \\bx + \\bb. \\label{NxPxb}\n\\end{equation}\n%\nStarting from some \\textit{arbitrary} vector $\\bx^{(0)}$, we define a\nsequence of vectors $\\{ \\bx^{(n)}\\}$, by the recursion\n%\n\\begin{equation}\n  N \\bx^{(n)} = P \\bx^{(n-1)} + \\bb, \\quad n=1,2,3,\\ldots\n  \\label{rec1}\n\\end{equation}\n%\nThe different iterative methods are characterised by their choice of\n$N$ and $P$.      By looking at~(\\ref{rec1}) we can already find\nsome restrictions on the choice of $N$:\n%\n\\begin{enumerate}\n  %\n\\item The matrix $N$ should not be singular, i.e.\\ $\\det(N) \\ne 0$.\n  %\n\\item The matrix $N$ should be chosen such that a system of the form\n  $N \\by = \\bz$ is ``easily'' solved.\n  %\n\\end{enumerate}\n%\n\n\\subsection{Iteration schemes}\n\nTo simplify the notation we will assume in what follows that all the\ndiagonal elements of the matrix $A$ are one.   This can be done by\ndividing each row by its diagonal element.   If by chance, one row has\na zero diagonal element we would just need to reorder the rows.\n\n\\subsubsection{Jacobi's method}\n\nIn Jacobi's method the matrix is split into diagonal and off-diagonal\npart:\n%\n\\begin{equation*}\n  A = I - ( A_L + A_U ) , \\implies\n  \\begin{cases}\n    N &= I , \\\\ P &= A_L+A_U\n  \\end{cases}\n\\end{equation*}\n%\nwhere we have written the off-diagonal part as the sum of a lower and\nan upper triangular matrix, $A_L$ and $A_U$ respectively.   The iteration\nscheme is\n%\n\\begin{equation*}\n  \\bx^{(n+1)} = \\bb + ( A_L + A_U ) \\bx^{(n)}\n\\end{equation*}\n\n%\nand the convergence matrix is $M \\equiv N^{-1} P = P$.\n\n\\subsubsection{Gauss-Seidel's method}\n\nIn Jacobi's method the old guess is used to estimate all the\nelements of the new guess.   In Gauss-Seidel's method each new iterate\nis used as soon as it becomes available.    The iteration scheme is as\nfollows:\n%\n\\begin{align}\n  A &= I - (A_L+A_U) , \\nonumber \\\\\n  \\bx^{(n+1)} &= \\bb + A_L \\bx^{(n+1)} + A_U \\bx^{(n)} , \\implies\n  \\begin{cases}\n    N &= I - A_L , \\\\ P &= A_U ,\n  \\end{cases}\n  \\label{seidel}\n\\end{align}\n%\nwhere $A_L$ and $A_U$ are respectively the  lower and upper triangular\nparts of $A$ with diagonal elements  set to zero.   Notice that if we\nstart computing  the   elements   of $\\bx^{(n+1)}$ from     the first,\ni.e.\\ from  $x_1^{(n+1)}$, then all the  terms  on the  right hand side\nof~(\\ref{seidel}) are known by the time they are used.\n\n\\subsubsection{S.O.R. method}\n\nWe can interpret the Gauss-Seidel algorithm as a method that applies\nat each guess $\\bx^{(n)}$ a correction term $\\bc$.  We can rewrite the\nGauss-Seidel iteration scheme as:\n%\n\\begin{align*}\n  && \\bx^{(n+1)} & = \\bb + A_L \\bx^{(n+1)} + A_U \\bx^{(n)} \\\\\n  \\implies && \\bx^{(n+1)} & = \\bx^{(n)} + \\left [ \\bb + A_L \\bx^{(n+1)}\n    + (A_U - I) \\bx^{(n)} \\right ] \\\\\n  &&             & = \\bx^{(n)} + \\bc,\n\\end{align*}\n%\nwhere the correction term is $\\bc = \\bb + A_L \\bx^{(n+1)} + (A_U - I)\n\\bx^{(n)}$.  The idea of the S.O.R. (Successive Over-Relaxation)\nmethod is that the convergence may be pushed to go a bit faster by\nusing a slightly larger correction.  In other words, we introduce a\nparameter $\\omega > 1$ (\\textit{SOR parameter}) that multiplies the\ncorrection term and write the iteration scheme as\n%\n\\begin{align*}\n  \\bx^{(n+1)} & =  \\bx^{(n)} + \\omega \\bc \\\\\n              & =  \\bx^{(n)} + \\omega\n        \\left [ \\bb + A_L \\bx^{(n+1)} + (A_U - I) \\bx^{(n)} \\right ].\n\\end{align*}\n\n\\noindent \\textbf{Remark 1} - The introduction of the relaxation\nparameter $\\omega$ can speed up convergence, but may also promote\ndivergence.    Moreover, it is not clear a priori what is the optimal\nvalue of $\\omega$ to achieve convergence in the smallest number of\niterations.    A typical choice is to set $\\omega$ quite close to one.\n\n\n\\subsection{Analysis of convergence}\n\nWe want to know when an iterative scheme will converge to the correct solution.\nWe can gain some insight from the scalar case.\nHere we have\n%\n\\begin{equation}\n  a x = b\n\\end{equation}\n%\nwith $a, b$ being real numbers, with the solution $x_\\text{exact} = b / a$.\nRe-writing this as an iterative scheme we have\n%\n\\begin{equation}\n  x^{(k+1)} = \\frac{b + p x^{(k)}}{n}\n\\end{equation}\n%\nwhere $n - p = a$.\n\nTo check convergence we want to see what happens when $x$ is near the correct solution.\nWe set $x^{(0)} = b / a + \\epsilon$. We see that\n%\n\\begin{align}\n  && x^{(1)} &= \\frac{b + b (n - a) / a + \\epsilon (n - a)}{n} \\\\\n  \\implies && x^{(1)} - x_\\text{exact} &= \\epsilon \\left( 1 - \\frac{a}{n} \\right) \\\\\n  \\implies && x^{(N)} - x_\\text{exact} &= \\epsilon \\left( 1 - \\frac{a}{n} \\right)^N.\n\\end{align}\n%\nSo we expect this iteration scheme to converge to the exact solution if $|1 - a/n| < 1$.\nMore usefully for our intuition we can write this as $| p / n | < 1$.\n\nIn the general matrix case a similar analysis goes through, except instead of $| p / n|$ we look at $M = N^{-1} P$.\nThis is precisely the convergence matrix mentioned above.\nThe condition $| p / n | < 1$ becomes the condition on the eigenvalues of $M$ instead.\nOne can show that an iterative method converges if and only if the matrix $M = N^{-1} P$ exists and has all eigenvalues $\\lambda_i$ with modulus strictly less than 1:\n%\n\\begin{equation*}\n  \\varrho(M) \\equiv \\max_i | \\lambda_i | < 1 \\Longleftrightarrow\n  \\text{Method converges}\n\\end{equation*}\n%\nwhere the symbol $\\varrho(M)$ is called the \\textit{spectral radius} of $M$.\nIt is sometimes hard to verify whether this condition is satisfied.\nA weaker, but more easily verifiable statement is that the method converges if at least one norm of the matrix $M$ is strictly less than one:\n%\n\\begin{equation*}\n  \\norm{ M } < 1 \\implies \\text{Method converges.}\n\\end{equation*}\n%\nHowever, the reverse is not true: a method may converge but some of the norms of $M$ may be larger than or equal to one.\n\nAs it can be difficult to compute the full spectral radius, approximate conditions for special matrices have been developed.\nA concept that is extremely useful in determining the behaviour and convergence of many algorithms to solve linear system is that of \\textit{diagonal dominance}.\nA matrix is strictly diagonally dominant if the modulus of each diagonal element is greater than the sum of the moduli of all the other elements in its row:\n%\n\\begin{equation*}\n  | a_{i i} | > \\sum_{\\genfrac{}{}{0pt}{}{j=1}{j \\ne i}}^n\n  | a_{i j} |, \\qquad (1 \\le i \\le n) .\n\\end{equation*}\n%\nThis may seem a rather peculiar condition to require on a matrix.\nAs a matter of fact, it is not so for many applications of practical interest.\nFor example, most algorithms that solve numerically partial differential equations using finite difference methods involve the solutions of large linear systems whose matrix of coefficients is diagonally dominant.\n\nThe importance of diagonally dominance from the point of view of direct methods to solve linear systems of equations stems from the following theorems:\n\n\\begin{theorem}\nIf the matrix of the coefficients $A$ is strictly diagonally dominant then the Jacobi method converges.\n\\end{theorem}\n\n\\medskip\n\n\\begin{theorem}\nIf the matrix of the coefficients $A$ is strictly diagonally dominant then the Gauss-Seidel method converges.\n\\end{theorem}\n\n\\noindent\n\\textbf{Remark} - Note that diagonal dominance (i.e.\\ the sum can be equal to the diagonal element) in itself does not ensure convergence.\n\n\\smallskip\n\n\\begin{theorem}\nIf the matrix of the coefficients $A$ is symmetric and positive definite then Gauss-Seidel's method converges.\n\\end{theorem}\n\n\\noindent\n\\textbf{Remark 1} - This theorem does not hold for Jacobi's method.\n\n\\noindent\n\\textbf{Remark 2} - Convergence theorem for the SOR methods are much\nharder to prove.\n\n\\section{Determinants and inverses}\n\nThe entire gist of this section on linear systems has been that we may\nnot wish to know the inverse or the determinant of the matrix of the\ncoefficients in order to solve a linear system of equations.\nHowever, sometimes we need to know these two quantities.  We can use\nthe methods that we have listed to compute them accurately.\n\nThe $LU$ decomposition offers the determinant as an easy to obtain side\nproduct.  If $A = L U$ then\n%\n\\begin{equation*}\n  \\det(A) = \\det(L) \\times \\det(U).\n\\end{equation*}\n%\nIn the case of Doolittle's factorisation we have $\\det(L) = 1$ and\ntherefore\n%\n\\begin{equation*}\n\\det(A) = \\det(U) = \\prod_{i=1}^n u_{i i} .\n\\end{equation*}\n%\nIf partial pivoting has been used for the Gaussian elimination then\n%\n\\begin{equation*}\n  \\det(A) = \\pm \\prod_{i=1}^n u_{i i} ,\n\\end{equation*}\n%\nwhere the sign is positive or negative depending if the number of row\npermutations is even or odd.\n\n\\noindent\n\\textbf{Remark} - To find the determinant using Gaussian elimination\nrequires a number of operations of the order of $n^3$.   The expansion\nin minors requires a number of operations of the order $n!$.\n\n\\medskip\n\nFinally, to find the inverse we can solve $n$ systems of $n$ linear\nequations.  Let $\\be_i$ denote the vector whose components are all\nzero except the $i$-th component that is, instead, equal to 1.   Let\n$\\bc_i$ be the $i$-th column of $A^{-1}$.   Then\n%\n\\begin{equation*}\n  A A^{-1} = I \\implies A \\bc_i = \\be_i , \\quad i=1,2,\\ldots,n.\n\\end{equation*}\n%\nTherefore for each value of $i$ we have to solve a system of $n$\nlinear equations for the $i$-th column of the inverse of $A$.   This\nmethod is much faster than Cramer's rule, that requires the evaluation\nof $n+1$ determinants.\n\n\\section*{Further reading}\n\nTopics covered here are also covered in\n\\begin{itemize}\n\\item Chapters 3 and 8 of Linz \\& Wang, \\textit{Exploring Numerical\n    Methods} (QA297 LIN),\n\\item Chapter 4 (and extended through chapter 5) of Kincaid \\& Cheney,\n  \\textit{Numerical Analysis} (QA297 KIN),\n\\item Chapters 2 and 3 of S{\\\"u}li \\& Mayers, \\textit{An Introduction\n    to Numerical Analysis} (not in library),\n\\item throughout the extremely detailed Golub \\& Van Loan,\n  \\textit{Matrix Computations} (QA263 GOL).\n\\end{itemize}\n", "meta": {"hexsha": "3664dcd9e39fa284773d739fc9a4aced6949171b", "size": 47260, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/tex/Linear_equations.tex", "max_stars_repo_name": "josh-gree/NumericalMethods", "max_stars_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 76, "max_stars_repo_stars_event_min_datetime": "2015-02-12T19:51:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T15:34:11.000Z", "max_issues_repo_path": "Notes/tex/Linear_equations.tex", "max_issues_repo_name": "josh-gree/NumericalMethods", "max_issues_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-05-24T19:49:52.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-23T21:40:42.000Z", "max_forks_repo_path": "Notes/tex/Linear_equations.tex", "max_forks_repo_name": "josh-gree/NumericalMethods", "max_forks_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2015-01-05T13:30:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-15T09:59:39.000Z", "avg_line_length": 34.2712110225, "max_line_length": 213, "alphanum_fraction": 0.6770418959, "num_tokens": 15075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246077301781, "lm_q2_score": 0.8774767906859264, "lm_q1q2_score": 0.7312230023906853}}
{"text": "\\subsection{Ellipsoids}\r\n\\noindent\r\nEllipsoids look like ellipses that have been rotated and extruded about their axis. They are radially symmetric about this axis. They have the general form \r\n\\begin{equation*}\r\n\td = \\frac{x^2}{a^2} + \\frac{y^2}{b^2} + \\frac{z^2}{c^2}\t\r\n\\end{equation*}\r\nNote that the only difference in the equation between an ellipsoid and hyperboloid is the signs are all positive.\r\n\r\n[INSERT IMAGE]", "meta": {"hexsha": "ba120d977df3be59eaab9ea4b973b8044b821605", "size": 420, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/ellipsoids.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/ellipsoids.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/ellipsoids.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.6666666667, "max_line_length": 157, "alphanum_fraction": 0.7404761905, "num_tokens": 123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218262741297, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.7311816959613572}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Definition}\n\n\\objective{Interpret piece-wise functions and their limits}\n\n\nIn human observations, there is almost nothing which follows one equation for the \nentirety of its domain.  The only constant in the universe is change!  For example, \nthe population of the world, the stock market, or even one stock might generally follow one\nequation for a significant stretch of time, but not forever.  So it is that most functions are \ndefined in pieces, and are therefore called piece-wise functions.\n\nFor example, the absolute value function which you have been using for some time now is\nactually a piecewise function.\\index{Absolute Value!piece-wise}\n\n$$\n|x|=\n\\begin{cases}\nx, x\\ge 0\\\\\n-x,x<0\n\\end{cases}\n$$\n\nIn light of this reality, it would behoove us to think more carefully about limits, recognizing that\nwe might be evaluating at the seems between cases.  \nWe should formally define the nomenclature of a ``sided'' limit:\n\n\\begin{derivation}{Right-sided limit}\\index{limit!right-sided}\n``The limit as $x$ approaches $c$ from the right is $L$'' is true if and only if for every $\\epsilon > 0$, there exists a $\\delta > 0$ such that\n$|f(x)-L|<\\epsilon$ whenever $0<x-c<\\delta$.\n\n$$\\lim_{x \\to c^+}f(x) = L$$\n\\end{derivation}\n\n\n\\begin{derivation}{Left-sided limit}\\index{limit!left-sided}\nSimilarly, ``The limit as $x$ approaches $c$ from the left is $L$'' is true if and only if for every $\\epsilon > 0$, there exists a $\\delta > 0$ such that\n$|f(x)-L|<\\epsilon$ whenever $0<c-x<\\delta$.\n\n$$\\lim_{x \\to c^-}f(x) = L$$\n\\end{derivation}\n\n\n\\personfeature[-4in]{\\chapdir/pics/George_Boole_color}{George\n    Boole}{1815-1864, French}{was an English mathematician\n    who said, ``No general method for the solution of questions \n    in the theory of probabilities can be established which does \n    not explicitly recognise, not only the special numerical bases \n    of the science, but also those universal laws of thought which \n    are the basis of all reasoning, and which, whatever they \n    may be as to their essence, are at least mathematical as to their form.''\n    \\href{https://en.wikipedia.org/wiki/George_Boole}{(Wikipedia)}}\n\n\\subsubsection{Boolean Variables}\\index{booleans}\nPerhaps surprisingly, your TI-8* can graph piece-wise functions.  We will start with a simple\npiecewise-function :\n\n$$\nf(x)=\n\\begin{cases}\nx, x<1\\\\\nx^2,x\\ge 1\n\\end{cases}\n$$\n\n\\index{TI-8*!piece-wise}\n\n\nIf we wanted to graph the sections separately, we could make $Y_1=(X^2)/(X\\ge{}1)$ and\n$Y_2=(X)/(X<1)$.  (The equality and inequality signs are under 2ND-MATH --- TEST.)  This will \nallow you to make the different sections different colors or different shading, but that might be\nwhat you want.  To graph everything in $Y_1$, use $(X^2)/(X\\ge{}1)+(X)/(X<1)$.\n\n\n\n\\subsection{Other Discontinuities}\n\\reminder{\\lefthand}{The different TI-8* behave differently around holes.  Newer calculators will attempt to make a hole apparent, while older models do not show it.\n\nOnly the new models draw points visibly, but even then they are very small.  We recommend\nagainst even trying to represent them in the TI-8*s.}\n\n\nAll together, there are five kinds of discontinuities.  We are only responsible to rigorously prove\ninstanes of the first two and the last:\n\n\\subsubsection{Removable}\nHere the limit exist.  The graph has a hole in it, which may or may not be defined as a point somewhere unexpected.\n\n\\inlinefig{\\chapdir/pics/Removable-discontinuity.png}{The limits is removable.  The function jumps to a value.}\n\n\\subsubsection{Jump}\nThe limits does not exist.  The graph is not continuous, but ``leaps'' from one output to another without passing in between, at one or more points.\n\n\\inlinefig{\\chapdir/pics/Discontinuity_jump.png}{The limit does not exist and there is an unavoidable jump.}\n\n\\subsubsection{Infinite} \nThe limit may or may not exist.  The function itself goes up and/or down without limit.  The most common example is a vertical asymptote.\n\n\\inlinefig{\\chapdir/pics/infinite}{At 1, the limit exists, because both sides are going to (positive) infinity.  At -1, the limit does not exist, because the two sides disagree.}\n\n\\subsubsection{Oscillating} \nThe limit does not exist.  The graph varies between outputs in way that never resolves.\n\n\\inlinefig{\\chapdir/pics/The_function_sin1_over_x.png}{No matter how much we zoom in to the function $\\sin{\\frac{1}{x}}$ around (0,0), it will only increase in complexity.}\n\n\\subsubsection{Domain} \nThe limits does not exist because on one side, the function ceases to exist.\n\n\\inlinefig{\\chapdir/pics/CorolarLocalizareRadacina.jpg}{The limit does not exist at $a$ or $b$ because one side of the function there does not exist.}\n", "meta": {"hexsha": "61478452bbb19b2dea125b77c7a8c7033b50067a", "size": 4706, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch02/0203.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch02/0203.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch02/0203.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.3963963964, "max_line_length": 178, "alphanum_fraction": 0.7456438589, "num_tokens": 1261, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339716830606, "lm_q2_score": 0.8705972717658209, "lm_q1q2_score": 0.7310701047563497}}
{"text": "\\section{Vector spaces}\nAs we've seen in \\autoref{chapter:linear algebra intuitive} vectors are found at the heart of linear algebra. We first defined them in a geometric way as objects with magnitude and direction, and later as lists of real numbers, analyzing the connections between these two mostly parallel definitions. We also spoke about vector spaces of the type $\\Rs{n}$ as the structures vectors exist in. However, we haven't defined vectors nor vector spaces formally - which is exactly what we do in this section, by defining the concept of \\emph{vector spaces}.\n\n\\begin{note}{$\\bm{\\Rs{n}}$ as a guide to general vector spaces}{}\n\tWhile reading the definition below, it is worthwhile to reflect on each of the given axioms as it relates to the familiar vector space $\\Rs{n}$.\n\\end{note}\n\n\\begin{definition}{Vector space}{vector space}\n\tA vector space over a field $\\mathbb{F}$ is a set $V$ which, together with two operations described below, fulfils a list of axioms. The two operations are\n\t\\begin{listitemize}\n\t\\item[Vector addition] an operation which takes two elements of $V$ and returns a single element of $V$, i.e. $+:V\\times V\\to V$.\n\t\\item[Scalar multiplication] an operation which takes a single element of $\\mathbb{F}$ and a single element of $V$ and returns a single element of $V$, i.e. $\\cdot:\\mathbb{F},V \\to V$.\n\t\\end{listitemize}\n\n\tThe axioms to be fulfilled are:\n\t\\begin{descitemize}\n\t\t\\item[Commutativity of vector addition] for any $u,v\\in V$,\n\t\t\t\\[\n\t\t\t\tu+v=v+u.\n\t\t\t\\]\n\n\t\t\\item[Associativity of vector addition] for any $u,v,w\\in V$,\n\t\t\t\\[\n\t\t\t\tu+(v+w) = (u+v)+w.\n\t\t\t\\]\n\t\t\n\t\t\\item[Additive identity] there exist an element $0\\in V$ for which, for any $v\\in V$,\n\t\t\t\\[\n\t\t\t\tv+0 = v.\n\t\t\t\\]\n\t\t\n\t\t\\item[Scalar multiplicative identity] for any $v\\in V$\n\t\t\t\\[\n\t\t\t\t1\\cdot v = v,\n\t\t\t\\]\n\t\t\twhere $1$ is the multiplicative identity in $\\mathbb{F}$.\n\n\t\t\\item[Additive inverse] for any $v\\in V$ there exist an element $u\\in V$ for which\n\t\t\t\\[\n\t\t\t\tv+u = 0.\n\t\t\t\\]\n\n\t\t\\item[Associativity of scalar multiplication] for any $\\alpha,\\beta\\in\\mathbb{F}$ and $v\\in V$\n\t\t\t\\[\n\t\t\t\t\\alpha\\cdot(\\beta\\cdot v) = (\\alpha\\beta)\\cdot v,\n\t\t\t\\]\n\t\t\twhere $\\alpha\\beta$ is the multiplication defined for $\\mathbb{F}$.\n\n\t\t\\item[Distributivity of vector addition] for any $\\alpha\\in\\mathbb{F}$ and $u,v\\in V$,\n\t\t\t\\[\n\t\t\t\t\\alpha\\cdot(u+v) = (\\alpha\\cdot u) + (\\alpha\\cdot v).\n\t\t\t\\]\n\t\t\n\t\t\\item[Distributivity of scalar addition] for any $\\alpha,\\beta\\in\\mathbb{F}$ and $v\\in V$,\n\t\t\t\\[\n\t\t\t\t(\\alpha+\\beta)\\cdot v = (\\alpha\\cdot v) + (\\beta\\cdot v).\n\t\t\t\\]\n\t\\end{descitemize}\n\n\tThe elements of $V$ are then called \\emph{vectors}, and the elements of $\\mathbb{F}$ are called \\emph{scalars}.\n\\end{definition}\n\nSince we discussed $\\Rs{n}$ thoroughly in \\autoref{chapter:linear algebra intuitive}, let's prove that it is indeed a vector space under the above definition. First, the claim:\n\n\\begin{theorem}{$\\bm{\\Rs{n}}$ is a vector space}{Rn vector space}\n\tThe set of elements of the form\n\t\\[\n\t\t\\vec{v} = \\colvec{v_{1};v_{2};\\vdots;v_{n}}\n\t\\]\n\twhere $v_{i}\\in\\mathbb{R}$, forms a vector space over $\\mathbb{R}$ together with the following two operations:\n\t\\begin{descitemize}\n\t\t\\item[Vector addition]\n\t\t\t\\[\n\t\t\t\t\\vec{u}+\\vec{v} = \\colvec{u_{1};u_{2};\\vdots;u_{n}} + \\colvec{v_{1};v_{2};\\vdots;v_{n}} = \\colvec{u_{1}+v_{1};u_{2}+v_{2};\\vdots;u_{n}+v_{n}}.\n\t\t\t\\]\n\t\t\\item[Scalar multiplication]\n\t\t\t\\[\n\t\t\t\t\\alpha\\cdot\\vec{v} = \\colvec{\\alpha v_{1};\\alpha v_{2};\\vdots;\\alpha v_{n}}.\n\t\t\t\\]\n\t\\end{descitemize}\n\\end{theorem}\n\nThe proof itself is pretty easy, based on the fact that $\\mathbb{R}$ is a field:\n\n\\begin{proof}{$\\bm{\\Rs{n}}$ is a vector space}{Rn vector space}\n\tSince the results of both operations defined for $\\Rs{n}$ only depend on the respective components of a vector $v\\in\\Rs{n}$, all the axioms of a vector space apply, since they derive directly from the fact that $\\mathbb{R}$ is a field. As an example, we will elaborate on two of the axioms:\n\t\\begin{descitemize}\n\t\\item[Additive inverse] Given a vector $\\vec{v}\\in\\Rs{n}$, each of its components $v_{i}$ has an inverse under $\\mathbb{R}$, namely $-v_{i}$. Therefore,\n\t\t\\[\n\t\t\t\\colvec{v_{1};v_{2};\\vdots;v_{n}} + \\colvec{-v_{1};-v_{2};\\vdots;-v_{n}} = \\colvec{v_{1}-v_{1};v_{2}-v_{2};\\vdots;v_{n}-v_{n}} = \\colvec{0;0;\\vdots;0} = \\vec{0},\n\t\t\\]\n\t\twhich is the additive identity in $\\Rs{n}$.\n\n\t\\item[Distributivity of vector addition] for each component of two vectors $\\vec{u},\\vec{v}\\in\\Rs{n}$, given the rules for vector addition and scalar multiplication, together with the distributivity of numbers in $\\mathbb{R}$:\n\t\t\\begin{align*}\n\t\t\t\\alpha (\\vec{u}+\\vec{v}) &= \\alpha\\left(\\colvec{u_{1};u_{2};\\vdots;u_{n}} + \\colvec{v_{1};v_{2};\\vdots;v_{n}}\\right) = \\alpha\\colvec{u_{1}+v_{1};u_{2}+v_{2};\\vdots;u_{n}+v_{n}}\\\\\n\t\t\t&= \\colvec{\\alpha u_{1}+\\alpha v_{1};\\alpha u_{2} + \\alpha v_{2};\\vdots;\\alpha u_{n} + \\alpha v_{n}} = \\colvec{\\alpha u_{1};\\alpha u_{2};\\vdots;\\alpha u_{n}} + \\colvec{\\alpha v_{1};\\alpha v_{2};\\vdots;\\alpha v_{n}} = \\alpha\\vec{u} + \\alpha\\vec{v}.\n\t\t\\end{align*}\n\t\\end{descitemize}\n\\end{proof}\n(it is adviceable for the reader to go over the rest of the axioms and prove them for $\\Rs{n}$)\n\n\n", "meta": {"hexsha": "873f208724b29baafae363a32813826f9148f860", "size": 5160, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/linear_algebra_rigorous/vectors.tex", "max_stars_repo_name": "JASory/maths_book", "max_stars_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2021-12-25T20:02:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T17:57:59.000Z", "max_issues_repo_path": "chapters/linear_algebra_rigorous/vectors.tex", "max_issues_repo_name": "JASory/maths_book", "max_issues_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2022-01-17T05:01:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-20T06:18:24.000Z", "max_forks_repo_path": "chapters/linear_algebra_rigorous/vectors.tex", "max_forks_repo_name": "JASory/maths_book", "max_forks_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2022-01-17T10:15:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-02T10:45:13.000Z", "avg_line_length": 49.6153846154, "max_line_length": 550, "alphanum_fraction": 0.6691860465, "num_tokens": 1782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8705972700870909, "lm_q1q2_score": 0.7310700998548529}}
{"text": "\\documentclass{article}\n\n\\usepackage{mathrsfs,amssymb,amsmath}\n\n\\begin{document}\n\n\\section{If $S:l_p \\to l_p$ is defined by $S(\\alpha_1, \\alpha_2, ...) =(0, \\alpha_1, \\alpha_2, ...)$ describe the lattice of invariant closed subspaces of S}\n\n$\\mathscr{M}_n=\\{x\\in l^p:x(k)=0 \\text{ for } 1 \\le k \\le n\\}$, then $\\mathscr{M}_n \\in \\text{Lat}S$, if $x \\in \\mathscr{M}_n$, so is $S(x)$, since they both start with at least $n$ 0s.\n\n$\\mathscr{M}_{n+1} \\in \\mathscr{M}_n$ since if a series begins w n+1 0s it will also begin with n zeros.\n\nClaim: These subspaces, together with the zero element and all of $l^p$, represent all of Lat T (which is thus a totally ordered set).\n\nStart with the element $x_1=(1, 0, 0, ...)$. It will be shown that the smallest closed invariant subspace $X$ that contains $x_1$ is fact the whole space.\n\nIf $x_1 \\in X$, so is any element of the form $(\\alpha_1, 0, 0, ...)$, since $X$ is a subspace so should be closed under scalar multiplication. Also, if $x_1 \\in X$, so is $S(x_1) = (0, 1, 0, 0, ...) = x_2$, as well as $(0, \\alpha, 0, 0)$. Since a subspace is closed under vector addition, all elements of the form $(\\alpha_1, \\alpha_2, \\alpha_3, ..., 0, 0, ...)$ are thus in $X$. Call the set of all such points $Y \\subset X$.\n\nNow we must show that $Y$ is dense in $l_p$, hence that $X=l_p$. Given an arbitrary element of $l_p$ and $\\epsilon$, since $l_p -> 0$, we can produce an element $y \\in Y$ such that $|| l_p - y || < \\epsilon$\n\nBy the same argument, any element whose first n entries are 0 will be identical to $\\mathscr{M}_n$, thus proving the claim.\n\n\n\\end{document}\n", "meta": {"hexsha": "7fe1330a09a7c3ddf79d7841e60ee846890d78e0", "size": 1605, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "analysis/6_Linear_Operators_on_Banach_Spaces/invariant_subspaces.tex", "max_stars_repo_name": "lukemassa/math-exercises", "max_stars_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "analysis/6_Linear_Operators_on_Banach_Spaces/invariant_subspaces.tex", "max_issues_repo_name": "lukemassa/math-exercises", "max_issues_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "analysis/6_Linear_Operators_on_Banach_Spaces/invariant_subspaces.tex", "max_forks_repo_name": "lukemassa/math-exercises", "max_forks_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.2, "max_line_length": 427, "alphanum_fraction": 0.6691588785, "num_tokens": 551, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7310700903880779}}
{"text": "%---------------------------Minimum Angle-----------------------------\n\\section{Minimum Angle\\label{s:tet-min-angle}}\n\nThe (nonoriented) dihedral angle of two faces of the\ntetrahedron that are adjacent along edge $i$ ($0\\le{}i\\le5$), is,\nmeasured in degrees,\n\\[\n  \\alpha_i = \\frac{180\\dgr}{\\pi}\n    \\arccos{\\left(\\vec{n_{i1}} \\cdot \\vec{n_{i2}}\\right)},\n\\]\nwhere $\\vec{n_{i1}}$ and $\\vec{n_{i2}}$ are unit vectors normal to the\ntwo tetrahedron faces that are adjacent to edge $i$. Subsequently,\nthe minimum (nonoriented) dihedral angle of the tetrahedron, measured\nin degrees, is\n\\[\n  q =\n    \\min_{i\\in\\{0,1,2,3,4,5\\}}{\\alpha_i}.\n\\]\n\n\\tetmetrictable{minimum dihedral angle}%\n{$A^1$}%                                              Dimension\n{$[40\\dgr,\\frac{180\\dgr}{\\pi}\\arccos\\tfrac{1}{3}]$}%  Acceptable range\n{$[0\\dgr,\\frac{180\\dgr}{\\pi}\\arccos\\tfrac{1}{3}]$}%   Normal range\n{$[0\\dgr,360\\dgr]$}%                                  Full range\n{$\\frac{180\\dgr}{\\pi}\\arccos\\tfrac{1}{3}\\approx70.528779\\dgr$}% Regular tetrahedron value\n{--}%                                                 Reference(s)                   \n{v\\_tet\\_minimum\\_angle}%                             Verdict function name\n\n", "meta": {"hexsha": "5995ec23bd65963944c1363212bd1784f40b4942", "size": 1196, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetMinimumAngle.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetMinimumAngle.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetMinimumAngle.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 41.2413793103, "max_line_length": 89, "alphanum_fraction": 0.5484949833, "num_tokens": 370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8080672112416736, "lm_q1q2_score": 0.7310184392018401}}
{"text": "\\section{Basics}\n\n% ===\n\\emph{Fundamental Assumption}\n\nData is iid for unknown $P$: $(x_i, y_i) \\sim P(X,Y)$\n\n\\textbf{Empirical risk}: $\\hat{R}_D(w) = \\frac{1}{\\abs{D}}\\sum_{(x,y)\\in D} (y-w^\\top x)^2$ \\\\\n\\textbf{True risk}: $R(w) = \\int p(x,y)\\, r_i^2 \\,\\partial x\\partial y = \\mathbb{E}_{x,y}[r_i^2]$\n\n%\\subsection*{True risk and estimated error}\n%True risk: $R(w) = \\int P(x,y) (y-w^\\top x)^2 \\partial x \\partial y = \\mathbb{E}_{x,y}[(y-w^\\top x)^2]$ \\\\\n%%Est. error: $\\hat{R}_D(w) = \\frac{1}{\\abs{D}}\\sum_{(x,y)\\in D} (y-w^\\top x)^2$\n\n% ===\n\\emph{Standardization:} \\enskip\n{\\color{gray} (for $x_k\\!\\in\\! X$, $k=1,\\ldots,d$)}\n\nCentered data with unit variance:\n\\highlight*{$\\!\\widetilde{x}_{i,k} = \\frac{x_{i,k}-\\hat{\\mu}_k}{\\hat{\\sigma}_k}\\!\\!$}\n\n\\vspace{-2pt}$\\hat{\\mu}_k = \\frac{1}{n}\\sum_{i=1}^n x_{i,k}$, \\enskip $\\hat{\\sigma}_k^2 = \\frac{1}{n}\\sum_{i=1}^n {(x_{i,k}-\\hat{\\mu}_k)}^2$ \n\n% ===\n\\emph{Parametric vs. Nonparametric:}\n\n\\textbf{Parametric}: have finite set of parameters. \ne.g. linear regression, linear perceptron\\\\\n\\textbf{Nonparametric}: grow in complexity with the size of the data, more expressive.\ne.g. k-NN\n\n% ===\n\\emph{Gradient Descent:}\n\n\\begin{highlightbox}\n    \\begin{enumerate}\n        \\item Pick arbitrary $w_0 \\in \\mathbb{R}^d$\n        \\item $w_{t+1} = w_t - \\eta_t \\nabla\\!_w \\hat{R}(w_t)$\n    \\end{enumerate}\n    \n    \\vspace*{-25pt}\\hfill\n    \\begin{highlightbox*}<.4>\n    \t\\footnotesize\n    \t$\\nabla\\!_w = \\begin{bmatrix}\n    \t\t\\pderiv{}{w_1} & \\ldots & \\pderiv{}{w_d}\n    \t\\end{bmatrix}$\n    \\end{highlightbox*}\n\\end{highlightbox}\n\n% ===\n\\emph{Stochastic Gradient Descent (SGD):}\n\n\\begin{highlightbox}\n\\begin{enumerate}\n    \\item Pick arbitrary $w_0 \\in \\mathbb{R}^d$\n\t\\item $w_{t+1} = w_t - \\eta_t \\nabla_w \\ell(w_t;x',y')$, with u.a.r.\\\\ (random) data point $(x',y') \\in D$\n\\end{enumerate}\n\\end{highlightbox}\n\nworks if $\\sum\\limits_t \\eta_t=\\infty$ and $\\sum\\limits_t \\eta_t^2 < \\infty$,\ne.g. $\\eta_t \\!=\\! \\frac{1}{t}$\n", "meta": {"hexsha": "46fdc528506012dea57a8d77041c90d2622e6474", "size": 1959, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/IML19/sections/Basics.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/IML19/sections/Basics.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/IML19/sections/Basics.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5967741935, "max_line_length": 141, "alphanum_fraction": 0.6023481368, "num_tokens": 809, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.7309876837733891}}
{"text": "\\documentclass[]{article}\n\\usepackage{amsmath}\n\n\\title{MTH 343 Numerical Analysis Lecture 4: Bisection Method (f(x) = 0)}\n\\author{Sheikh Abdul Raheem Ali}\n\\date{February 3, 2019}\n\n\\begin{document}\n\t\n\t\\maketitle\n\t\n\t\\section*{Strategy/Algorithm}\n\t\n\tAssume $ f(x) $ is continuous.\n\t\n\t\\begin{enumerate}\n\t\t\\item Begin with two values $ x = a \\& x = b $ that bracket the root by finding $ f(a) \\cdot f(b) < 0  $ (i.e they are of opposite signs).\n\t\t\n\t\t\\item The method successfully divides the interval in half \\& replaces one endpoint by the midpoint so that the root is again bracketed.\n\t\t\n\t\\end{enumerate}\n\t\n\t\\[ x^2 - 2 = 0, (\\text{ solution } x = \\sqrt{2}) \\text{ on the interval} \\ [1,2] \\ \\begin{cases}\n\tf(a = 1) = -1 & < 0 \\\\\n\tf(b = 2) = 2 & > 0\n\t\\end{cases}\\]\n\t\n\t\\begin{tabular}{c c c c c}\n\t\t\\# of iterations \\textbf{$ n $} & \\textbf{$ a_n $} & \\textbf{$ b_n $} & midpoint \\textbf{$ P_n $} & f($ P_n $) \\\\\n\t\t\n\t\t0&1&2&1.5&0.25 \\\\\n\t\t1&1&1.5&1.25& -0.4375\\\\\n\t\t2&1.25&1.5&1.375& -0.1094\\\\\n\t\t3&1.375&1.5&1.4375& +0.0664\\\\\n\t\t4&1.4375&1.375&1.40625& -0.0225\\\\\n\t\t5&1.4375&1.40625&1.421875& -0.0217\\\\\n\t\t6&1.40625&1.421895&1.4140625& -0.0004\\\\\n\t\t7&1.4140625&1.421875&1.41796875& -0.0106\n\t\t\n\t\t \n\t\\end{tabular}\n\\section*{Remarks}\n\n\\begin{enumerate}\n\t\n\t\\item The main advantage of the bisection method is that it is guaranteed to work if $ f(x) $ is continuous on $ [a,b] $ and $ a,b $ bracket the root.\n\t\t\n\t \\item Its accuracy after n iterations is known in advance which is $ \\le |\\frac{b-a}{2^n}| $\n\t\n\t\\[ |P_n - P| \\le \\frac{b-a}{2^n} \\]\n\t\n\tWhere $ P $ = exact value, and $ P_n $ = midpoint (approx)\n\t\n\tIn the previous example, find how many iterations are needed to achieve an accuracy for $ 10^{-4}  (x^2 - 2 = 0  \\text{ on }  [1,2])$.\n\t\n\t\n\t\\begin{align*}\n\t |E_n| \\le \\frac{2-1}{2^n} < 0.0001 \\\\\n\t 2^n > 10,000 \\\\\n\t n \\cdot \\ln2 > \\ln(10,000) \\\\\n\t n > \\frac{\\ln(10,000)}{\\ln2} \\approx 13.28 \\\\\n\t n = 14 \\ terms\n\t\\end{align*}\n\t\n\t\\item A minor disadvantage is that it is slow to converge, however with speedy computers available the slowness is of less concern. \n\t\n\t\\item When multiple roots are concerned, the method may not be applicable since it might not change signs. \n\\end{enumerate}\t\n\n\\[ \t0 = x^2 - 6x + 9 = (x-3)^2, \\  x = 3  \\]\n\t\n\\end{document}", "meta": {"hexsha": "a245c933ec59f830d3709173b430aa8d30fd4c2d", "size": 2244, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Numerical/Lecture_4/Lecture_4.tex", "max_stars_repo_name": "sheikheddy/aus-files", "max_stars_repo_head_hexsha": "0c38d15d560ccbb8231c8ef210916ea94a0f004b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Numerical/Lecture_4/Lecture_4.tex", "max_issues_repo_name": "sheikheddy/aus-files", "max_issues_repo_head_hexsha": "0c38d15d560ccbb8231c8ef210916ea94a0f004b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Numerical/Lecture_4/Lecture_4.tex", "max_forks_repo_name": "sheikheddy/aus-files", "max_forks_repo_head_hexsha": "0c38d15d560ccbb8231c8ef210916ea94a0f004b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.1666666667, "max_line_length": 151, "alphanum_fraction": 0.6158645276, "num_tokens": 892, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.9019206811430763, "lm_q1q2_score": 0.7309876811025506}}
{"text": "\\section{Hamiltonian Monte Carlo}\nAs we mention in section \\ref{sec:Metropolis_Hastings}, a significant inefficiency in the Metropolis algorithm, is that it often behaves like a random walk and thus the simulations take a longer road while moving through the target distribution, which gives rise to slow simulation. This is especially a problem when concerning high-dimensional problems, such as Bayesian Neural Networks (\\cite{neal2012bayesian}).\nAnother way to generate proposals with a higher efficiency, is by updating the parameters dynamically by simulating Hamiltonian dynamics and then use the Metropolis algorithm to accept or reject these proposals. Such an algorithm suppress the local random walk behavior and thus allowing it to move much faster and more rapidly through the distribution. This method, which we will present in this chapter, is called Hamilton Monte Carlo (HMC), and is commonly used in computational physics and statistics. The algorithm was originally proposed by \\cite{Duane1987216} for calculations used in lattice quantum chromodynamics, but was later introduced to the field of computation statistics when it was used for Bayesian Neural Networks n \\cite{neal2012bayesian}\\\\\n\\\\\nThe HMC algorithm reduces correlation between successive sampled states, compared to the Metropolis Hastings algorithm in section \\ref{sein tc:Metropolis_Hastings}, by proposing moves to distant states which maintain a high probability of acceptance due to the approximate energy conserving properties of the simulated Hamiltonian dynamic when using a symplectic integrator\\footnote{In mathematics, a symplectic integrator is a numerical integration scheme for Hamiltonian systems.}. The reduced correlation means fewer Markov chain samples are needed to approximate integrals with respect to the target probability distribution for a given Monte Carlo error. For the HMC algorithm we need to construct a differential equation system, that is known to keep the target distribution invariant. If we can achieve this, we can simulate transitions following the solution to this differential equation system and these transitions can be shown to leave the target distribution invariant. Such a differential equations system is often the Hamiltonian dynamics named after William Rowan Hamilton and will be introduced in the next section. \n\n\\subsection{Hamiltonian dynamics}\nBefore we move to the actual HMC algorithm, we need to become familiar with the concept of Hamiltonian dynamics. Hamiltonian dynamics are used to describe how an object move around in a system. The Hamiltonian dynamics are defined by the objects position $\\boldsymbol{\\theta}\\in \\mathbb{R}^d$ and it's momentum $\\boldsymbol{\\rho}\\in \\mathbb{R}^d$, which in the physics are equivalent to an object's mass times it's velocity at some point in time. The object's position is associated with a potential energy $U(\\boldsymbol{\\theta})$ and likewise the momentum is associated with a kinetic energy $K(\\boldsymbol{\\rho})$. The sum of the potential and kinetic energy is regarded as the total energy of the system and often called the Hamiltonian,\n\\begin{equation*}\nH(\\boldsymbol{\\theta},\\boldsymbol{\\rho})=U(\\boldsymbol{\\theta})+K(\\boldsymbol{\\rho})    \n\\end{equation*}       \none important feature of the Hamiltonian is that it is constant over time. Taking the partial derivative with respect to time of the position and momentum, shows us how they evolve over time,\n\\begin{equation}\\label{eq:hamilton_equations}\n\\begin{split}\n\\frac{d \\theta_{i}}{d t}=\\frac{\\partial H}{\\partial \\rho_{i}}=\\frac{\\partial K(,\\boldsymbol{\\rho})}{\\partial \\rho_{i}} \\\\\n\\frac{d \\rho_{i}}{d t}=-\\frac{\\partial H}{\\partial \\theta_{i}}=-\\frac{\\partial U(,\\boldsymbol{\\theta})}{\\partial \\theta_{i}}\n\\end{split}\n\\end{equation}\nwhere $i=1,2, \\ldots,d$. These are named Hamiltonian equations and represents differential equations system. The Hamiltonian equations are very useful, since if we are able to evaluate the partial derivatives from equation \\ref{eq:hamilton_equations}, we are able to predict the position and momentum variable of the object at any point in the future $t^\\prime>t$.\n\\subsection{Properties of the Hamiltonian Dynamics}\nThe Hamiltonian dynamics have several properties, which are very crucial when used in relation to MCMC simulations.\\\\\n\\\\\n\\textit{Property of time reversibility:}\\\\\nThis property is very important for showing that the HMC transitions, generated by the dynamics, leave the target distribution invariant, since the reversibility of the chain transitions requires reversibility of the dynamics. \\\\\n\\\\\n\\textit{Property of conservation:}\\\\\nSecondly we have the property of conservation, that is the dynamics keeps the Hamiltionian invariant. This can easily be verified from equation \\ref{eq:hamilton_equations}\n\\begin{equation}\\label{eq:Hamilton_conservation}\n    \\frac{d \\H}{d t}=\\sum_{i=1}^{d}\\left[\\frac{d \\theta_{i}}{d t} \\frac{\\partial \\H}{\\partial \\theta_{i}}+\\frac{d \\rho_{i}}{d t} \\frac{\\partial \\H}{\\partial \\rho_{i}}\\right]=\\sum_{i=1}^{d}\\left[\\frac{\\partial \\H}{\\partial \\rho_{i}} \\frac{\\partial \\H}{\\partial \\theta_{i}}-\\frac{\\partial \\H}{\\partial \\theta_{i}} \\frac{\\partial \\H}{\\partial \\rho_{i}}\\right]=0\n\\end{equation}\nIn the HMC method, we will use Metropolis updates, with proposals found by the Hamiltonian dynamic. We have that the acceptance probability is one if $\\H$ is kept invariant (see e.g \\cite{neal2012mcmc}). This is however not possible in practise, and we are only able to keep $\\H$ approximately invariant, but we will come back to this issue later. \\\\\n\\\\\n\\textit{Property of volume preservation:}\nThe last crucial property of the Hamiltonian dynamics is the volume preservation property, which gives us that the dynamics preserves volume in the $(q,p)$ space.\n\n\\begin{equation*}\n    \\sum_{i=1}^{d}\\left[\\frac{\\partial}{\\partial \\theta_{i}} \\frac{d \\theta_{i}}{d t}+\\frac{\\partial}{\\partial \\rho_{i}} \\frac{d \\rho_{i}}{d t}\\right]=\\sum_{i=1}^{d}\\left[\\frac{\\partial}{\\partial \\theta_{i}} \\frac{\\partial \\H}{\\partial \\rho_{i}}-\\frac{\\partial}{\\partial \\rho_{i}} \\frac{\\partial \\H}{\\partial \\theta_{i}}\\right]=\\sum_{i=1}^{d}\\left[\\frac{\\partial^{2} \\H}{\\partial \\theta_{i} \\partial \\rho_{i}}-\\frac{\\partial^{2} \\H}{\\partial \\rho_{i} \\partial \\theta_{i}}\\right]=0\n\\end{equation*}\n\n\\subsection{Discretizing Hamiltonian Equations}\nThe Hamiltonian equations describe how an objective evolve in continuous time, but for simulating Hamiltonian dynamics on a computer system, we have to approximate the differential equations numerically in some way, this is done by discretizing time. We do this by splitting the time interval $dt$ into small intervals $\\varepsilon$. We will now present the two most common ways of handling this. The first is the Euler's Method and lastly the Leapfrog Method.\n\\subsubsection*{The Euler’s Method}\nThis is one of the most common methods in computational science for solving a differential equation system. For Hamiltonian equations the Euler methods update the position and momentum variable as follows,\n\n\\begin{equation*}\n\\begin{split}\n\\rho_{i}(t+\\varepsilon)=\\rho_{i}(t)+\\varepsilon \\frac{d \\rho_{i}}{d t}(t)=\\rho_{i}(t)-\\varepsilon \\frac{\\partial U}{\\partial \\theta_{i}(t)} \\\\\n\\theta_{i}(t+\\varepsilon)=\\theta_{i}(t)+\\varepsilon \\frac{d \\theta_{i}}{d t}=\\theta_{i}(t)+\\varepsilon \\frac{\\partial K}{\\partial \\rho_{i}(t)}\n\\end{split}\n\\end{equation*}\nAccording to \\cite{neal2012mcmc} a slightly better result can be obtained by,\n\\begin{equation*}\n\\begin{split}\n\\rho_{i}(t+\\varepsilon) &=\\rho_{i}(t)-\\varepsilon \\frac{\\partial U}{\\partial \\theta_{i}}(\\theta(t)) \\\\\n\\theta_{i}(t+\\varepsilon) &=\\theta_{i}(t)+\\varepsilon \\frac{\\rho_{i}(t+\\varepsilon)}{m_{i}}\n\\end{split}\n\\end{equation*}\n\\subsubsection*{The Leapfrog method}\nAnother discretizing scheme often used for simulation Hamiltonian equations, is the Leapfrog method. Whereas the Euler’s method takes full steps for updating position and momentum, the leapfrog method takes a half steps to update momentum value,\n\\begin{equation*}\n\\begin{split}\n\\rho_{i}(t+\\varepsilon / 2)=\\rho_{i}(t)-(\\varepsilon / 2) \\frac{\\partial U}{\\partial \\theta_{i}(t)} \\\\\n\\theta_{i}(t+\\varepsilon)=\\theta_{i}(t)+\\varepsilon \\frac{\\partial K}{\\partial \\rho_{i}(t+\\varepsilon / 2)} \\\\\n\\rho_{i}(t+\\varepsilon)=\\rho_{i}(t)-(\\varepsilon / 2) \\frac{\\partial U}{\\partial \\theta_{i}(t+\\varepsilon)}\n\\end{split}\n\\end{equation*}\nAccording to \\cite{neal2012mcmc} the Leapfrog method, preserves volume exactly, \\textcolor{red}{which is good??} and it is also reversible. \n\n\\subsection{Hamiltonian and Probability: Canonical Distributions}\nWe now have a slightly better understanding understanding of what is a Hamiltonian and how we can simulate it's dynamics by either the Euler method or the Leapfrog method. We now need to connect this with the MCMC theory from the previous sections. In order to perform this connection, we need to relate the target distribution $\\hat{p}(\\boldsymbol{\\theta})$ and the Hamiltonian, such that we can use the Hamiltonian equations to the target distribution. A way of doing this, proposed by \\cite{neal2012bayesian}, is use a concept from statistical mechanics known as the canonical (Boltzman) distribution. The probability distribution of $\\boldsymbol{\\theta}$ under the canonical distribution can be written as\n\\begin{equation*}\n    \\hat{p}(\\boldsymbol{\\theta})\\propto \\exp(\\frac{-U(\\boldsymbol{\\theta})}{T})\n\\end{equation*}\nwhere $U(\\boldsymbol{\\theta})$ again is the potential energy. $T$ is often called the temperature of the system and usually chosen to be equal to one (\\cite{neal2012bayesian}).\nOne should note that any probability distribution that is nowhere zero can be put into this form by letting $U(\\boldsymbol{\\theta})=-\\log \\hat{p}(\\boldsymbol{\\theta})-\\log Z$, for any convenient choice of $Z$.  Since the Hamiltonian is an energy function for the joint state of both position and momentum, we need a joint distribution, which is given by\n\\begin{equation*}\np(\\boldsymbol{\\theta},\\boldsymbol{\\rho})\\propto \\exp(-\\H(\\boldsymbol{\\theta},\\boldsymbol{\\rho}))   = \\exp(-U(\\boldsymbol{\\theta}))\\exp(-K(\\boldsymbol{\\rho}))=\\hat{p}(\\boldsymbol{\\theta})p(\\boldsymbol{\\rho})\n\\end{equation*}\nwhere the last equality hold since we assume independence between $\\boldsymbol{\\theta}$ and $\\boldsymbol{\\rho}$. We now have a joint distribution, in terms of the Hamiltonian function, which we know how to simulate. But we are in fact only interested in the position variable $\\boldsymbol{\\theta}$ and not the momentum variable $\\boldsymbol{\\rho}$, which we in some way can interpret as a \"helper\" variable that enable us to simulate the joint distribution. In order to obtain marginal samples from the target distribution only, on can simply throw away the samples the momentum distribution, because they are independent anyway. Since we can interpret the momentum variable as a  helper variable, we are allowed freely to decide the marginal distribution $p(\\boldsymbol{\\rho})$. The literature often choose it to be Gaussian, $\\boldsymbol{\\rho}\\sim \\mathcal{N}\\left(0, \\Sigma \\right)$, where $\\Sigma$ is some symmetric, positive-definite mass matrix and often chosen to be diagonal, such that $\\boldsymbol{\\rho}$ is d-dimensional multivariate normal where the variables are independent. \nThe Hamiltonian equations from equation \\ref{eq:hamilton_equations} can now be written as,\n\\begin{equation*}\n\\begin{split}\n\\frac{d \\theta_{i}}{d t}&=\\left[\\Sigma^{-1}\\rho\\right]_i \\\\\n\\frac{d \\rho_{i}}{d t}&=-\\frac{\\partial U}{\\partial \\theta_i}\n\\end{split}\n\\end{equation*}\n\n\n\n\n\n\\subsection{Hamiltonian Monte Carlo}\nWe start the HMC algorithm from an initial state $\\boldsymbol{\\theta}_0$ $\\boldsymbol{\\rho}_0$, and then we simulate the Hamiltonian dynamics for $t+\\varepsilon$ using the Leapfrog method. We choose the Leapfrog method since \\cite{betancourt2017conceptual} shows it to be more effective. The states generated for the position and momentum variable at the end of the Leapfrog simulation is used as proposals for a new state $(\\boldsymbol{\\theta}^\\prime,\\boldsymbol{\\rho}^\\prime)$. The proposed stats are accepted according to the Metropolis acceptance criteria,\n\\begin{equation*}\n\\begin{split}\n    \\alpha\\left((\\boldsymbol{\\theta},\\boldsymbol{\\rho}) \\mapsto (\\boldsymbol{\\theta}^\\prime , \\boldsymbol{\\rho}^\\prime )\\right) &= \\min\\left\\{1, \\frac{p(\\boldsymbol{\\theta}^\\prime,\\boldsymbol{\\rho}^\\prime)}{p(\\boldsymbol{\\theta},\\boldsymbol{\\rho})} \\right\\}\\\\\n    &= \\min\\{1,\\exp\\left(\\log p(\\boldsymbol{\\theta}^\\prime,\\boldsymbol{\\rho}^\\prime)- \\log p(\\boldsymbol{\\theta}, \\boldsymbol{\\rho})  \\right)\\\\\n    &= \\min \\left\\{1,\\exp\\left(-\\H(\\boldsymbol{\\theta}^\\prime,\\boldsymbol{\\rho}^\\prime) +\\H(\\boldsymbol{\\theta},\\boldsymbol{\\rho})\\right) \\right\\}\n\\end{split}\n\\end{equation*}\nIf we could simulate the Hamiltonian dynamics exactly, the Metropolis acceptance criteria would always be equal to one, due to the Hamiltonian conservation criteria in equation \\ref{eq:Hamilton_conservation} which would give $\\min \\{1, \\exp (0)\\}=1$. But since we cannot simulate the Hamilton dynamics exactly and we need to approximate them with the Leapfrog scheme introduced earlier. We can however see that if we choose a proper way of discretize the dynamics, the term  $\\H(\\boldsymbol{\\theta},\\boldsymbol{\\rho})-\\H(\\boldsymbol{\\theta}^\\prime,\\boldsymbol{\\rho}^\\prime)$ in the exponent should be small, thus a high acceptance rate. This is a very clever way of making proposals, since we can make very large and uncorrelated moves in the state space, while keeping a high acceptance of probability. The algorithm is written in pseudo code in algorithm \\ref{alg:HMC}. \\\\\n\\\\\nThe Algorithm relies heavily on choosing values for $\\varepsilon$ and $L$. If we pick a too large value for $\\varepsilon$, then the simulations will be inaccurate and give us a low acceptance rate. If we on the other hand choose $\\varepsilon$ which is too small, we will waste computation by taking small steps. A too small $L$ will give us successive samples that lies close to each other, which gives us the same undesirable random walk behavior as with the Metropolis algorithm from section \\ref{sec:Metropolis_Hastings}. A too large choice for $L$, will produce trajectories that loops back and retrace their steps again and even worse if we choose $L$ such that the samples jumps from one side of the space to the other in each iteration, then accoding to.\n\n\n\\begin{algorithm}[h!]\\label{alg:HMC}\n\n\\SetAlgoLined\n$\\text{Given } \\boldsymbol{\\theta}^{0}, \\varepsilon, L, \\mathcal{L}, M$:\\\\\n\\For{m=1 to M}{\nSample $\\boldsymbol{\\rho}^{0} \\sim \\mathcal{N}(0, I)$ \\\\\nSet $\\boldsymbol{\\theta}^{m} \\leftarrow \\boldsymbol{\\theta}^{m-1}, \\boldsymbol{\\theta}^\\prime \\leftarrow \\boldsymbol{\\theta}^{m-1}, \\boldsymbol{\\rho}^\\prime \\leftarrow \\boldsymbol{\\rho}^{0}$\\\\\n\\For{i = 1 to L}{\nSet $\\boldsymbol{\\theta}^\\prime, \\boldsymbol{\\rho}^\\prime \\leftarrow \\operatorname{Leapfrog}(\\boldsymbol{\\theta}^\\prime, \\boldsymbol{\\rho}^\\prime, \\varepsilon)$\\\\\nWith probability $\\alpha=\\min \\left\\{1, \\frac{\\exp \\left\\{\\mathcal{L}(\\boldsymbol{\\theta}^\\prime)-\\frac{1}{2} \\boldsymbol{\\rho}^\\prime \\cdot \\boldsymbol{\\rho}^\\prime\\right\\}}{\\exp \\left\\{\\mathcal{L}\\left(\\boldsymbol{\\theta}^{m-1}\\right)-\\frac{1}{2} \\boldsymbol{\\rho}^{0} \\cdot \\boldsymbol{\\rho}^{0}\\right\\}}\\right\\}, \\text { set } \\boldsymbol{\\theta}^{m} \\leftarrow \\boldsymbol{\\theta}^\\prime, \\boldsymbol{\\rho}^{m} \\leftarrow-\\boldsymbol{\\rho}^\\prime$\n\n}\n}\n\n\\SetKwFunction{Lepfrog}{Lepfrog}\n\\SetKwProg{Fn}{Function}{:}{\\KwRet{$\\boldsymbol{\\theta}^\\prime,\\boldsymbol{\\rho}^\\prime$}}\n\\Fn{\\Lepfrog{$\\boldsymbol{\\theta}$, $\\boldsymbol{\\rho}$, $\\varepsilon$}}{\n Set $\\boldsymbol{\\rho}^\\prime \\leftarrow r+(\\varepsilon / 2) \\nabla_{\\theta} \\mathcal{L}(\\theta)$\\\\\nSet $\\boldsymbol{\\theta}^\\prime \\leftarrow \\theta+\\varepsilon \\boldsymbol{\\rho}^\\prime$\\\\\nSet  $\\boldsymbol{\\rho}^\\prime \\leftarrow \\boldsymbol{\\rho}^\\prime+(\\varepsilon / 2) \\nabla_{\\theta} \\mathcal{L}(\\boldsymbol{\\theta}^\\prime)$\n  }\n\\caption{Hamiltonian Monte Carlo}\n\\end{algorithm}\n\n\n\n\n\n\n\n\\subsection{No-U-Turn Hamiltonian Monte Carlo}\nNo-U-Turn Sampler (NUTS) introduced by \\cite{hoffman2011nouturn}\nextends the HMC by eliminating the need to specify the trajectory length $L$.\n\n", "meta": {"hexsha": "2f18b4595c0ca322dd2cb7d6b2068c54782860b7", "size": 16237, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Backup_hmc_subsection.tex", "max_stars_repo_name": "mraabo/Dissertation--Bayesian-Neural-Networks", "max_stars_repo_head_hexsha": "629b1c5f4bbdb80ef1d1037b4a0a1b7f95ac710b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Backup_hmc_subsection.tex", "max_issues_repo_name": "mraabo/Dissertation--Bayesian-Neural-Networks", "max_issues_repo_head_hexsha": "629b1c5f4bbdb80ef1d1037b4a0a1b7f95ac710b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Backup_hmc_subsection.tex", "max_forks_repo_name": "mraabo/Dissertation--Bayesian-Neural-Networks", "max_forks_repo_head_hexsha": "629b1c5f4bbdb80ef1d1037b4a0a1b7f95ac710b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 115.9785714286, "max_line_length": 1133, "alphanum_fraction": 0.7551271787, "num_tokens": 4355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543454, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7309599226138149}}
{"text": "\\section{Burke's Theorem}\n\\label{sec:Burke-Theorem}\n\n\\begin{theorem}[Burke]\n\\label{thm:Burke}\n\tFor any $M/M/m$ with arrival rate $\\lambda$, we have that:\n\t\n\t\\begin{enumerate}\n\t\t\\item The departure process is $Poisson(\\lambda)$\n\t\t\\footnote{that is, inter-departure times are Exponentially distributed with rate $\\lambda$.};\n\t\t\n\t\t\\item The number of jobs in the system is independent of the sequence of previous departures\n\t\t\\footnote{that is, independent of times and patterns}.\n\t\\end{enumerate}\n\t\\begin{proof}\n\t\tFor a formal demonstration, see \\cite{harchol2013performance}.\n\t\\end{proof}\n\\end{theorem}\n\nThe Burke's Theorem allows us to instantly analyze a large class of queueing networks.\nLet us start with its application on (i) tandem systems and (ii) acyclic networks with probabilistic routing.\n\n\n\n\n\\subsection{Burke Applications: Tandem Systems}\n\\label{sec:Burke-Application-Tandem-Systems}\n\nBy the Burke's Theorem, for any tandem system made by m $M/M/1$ nodes arrival rate $\\lambda$, we have that:\n\n\\begin{itemize}\n\t\\item the arrival stream to each server is Poisson distributed with rate $\\lambda$;\n\t\n\t\\item the number of jobs in each server is independent of the number of jobs in every other server;\n\t\n\t\\item the order of the sequence of servers are uninfluential for system performance;\n\t\n\t\\item the state probability is\n\t\n\t\\begin{equation}\n\t\\label{eqn:Burke-Application-Tandem-Systems-Probability-State}\n\t\\pi_{n_{1},...,n_{m}} = \\prod_{i=1}^{m} \\varrho_{i}^{n_{i}} (1 - \\varrho_{i})\n\t\\end{equation}\n\t\n\twhere $\\varrho_{i}$ is the utilization of the $i$-th server.\n\t\n\t\\item the probability to have $n_{i}$ jobs in the $i$-th server is\n\t\n\t\\begin{equation}\n\t\\label{eqn:Burke-Application-Tandem-Systems-Probability-Jobs-Server}\n\t\\probability{N_{i}=n_{i}} = \\varrho_{i}^{n_{i}} (1 - \\varrho_{i})\n\t\\end{equation}\n\t\n\twhere $\\varrho_{i}=\\frac{\\lambda}{\\mu_{i}}$ is the utilization of the $i$-th server.\n\t\n\t\\item the mean number of jobs in the $i$-th server is\n\t\n\t\\begin{equation}\n\t\\label{eqn:Burke-Application-Tandem-Systems-Expected-Jobs-Server}\n\t\\expected{N_{i}} = \\frac{\\varrho_{i}}{1-\\varrho_{i}}\n\t\\end{equation}\n\\end{itemize}\n\n%\\begin{figure}[tp]\n%\t\\label{fig:tandem-systems}\t\n%\t\\centering\n%\t\\includegraphics{fig/Tandem-System}\n%\t\\caption{A Tandem system}\n%\\end{figure}\n\n\n\n\n\\subsection{Burke Application: Acyclic Networks with Probabilistic Routing}\n\\label{sec:Burke-Application-Acyclic-Networks-Probabilistic-Routing}\n\nBy the Burke's Theorem, for any acyclic system with probabilistic routing made by $m$ $M/M/1$ nodes with arrival rate $\\lambda$, everything stated in \\Cref{sec:Burke-Application-Tandem-Systems} holds, but the arrival stream to each server is (splitted/merged) Poisson distributed with rate proportional to $\\lambda$.\n\n%\\begin{figure}[tp]\n%\\label{fig:Acyclic-Networks-Probabilistic-Routing}\t\n%\t\\centering\n%\t\\includegraphics{fig/Acyclic-Network-Probabilistic-Routing}\n%\t\\caption{An Acyclic Networks with Probabilistic Routing}\n%\\end{figure}", "meta": {"hexsha": "bfdce327c62460a2d6d9527b162f6f692f017267", "size": 2967, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/burke-theorem.tex", "max_stars_repo_name": "gmarciani/research", "max_stars_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-07-27T13:31:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-20T12:54:12.000Z", "max_issues_repo_path": "performance-modeling/sec/burke-theorem.tex", "max_issues_repo_name": "gmarciani/research", "max_issues_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "performance-modeling/sec/burke-theorem.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 35.3214285714, "max_line_length": 316, "alphanum_fraction": 0.7421638018, "num_tokens": 908, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7308457069413142}}
{"text": "\\chapter{Week 2: The vector space}\n\n\\section{Linear combinations}\n\\begin{definition}\n  An expression\n  \\begin{equation*}\n    \\alpha_1\\vv_1 + \\cdots + \\alpha_n\\vv_n\n  \\end{equation*}\n  is a linear combination of the vectors $\\vv_1, \\ldots, \\vv_n$.\n  The scalars $\\alpha_1, \\ldots, \\alpha_n$ are the coefficients of the linear combination.\n\\end{definition}\n\n% ================================================================\n\n\\section{Span}\n\\begin{definition}[Span]\n  The set of all linear combinations of some vectors $\\vv_1, \\ldots, \\vv_n$ is called the span of these vectors. Written $\\Span\\{\\vv_1,\\ldots,\\vv_n\\}$.\n\\end{definition}\n\n\\begin{definition}\n  Let $\\sV$ be a set of vectors. If $\\vv_1, \\ldots, \\vv_n$ are vectors such that $\\sV = \\Span\\{ \\vv_1, \\ldots, \\vv_n \\}$, then\n  \\begin{itemize}\n  \\item We say $\\{ \\vv_1, \\ldots, \\vv_n \\}$ is a generating set for $\\sV$.\n  \\item We refer to the vectors $\\vv_1, \\ldots, \\vv_n$ as generators for $\\sV$.\n  \\end{itemize}\n\\end{definition}\n\nIf we use the vectors $[1, 0, 0]$, $[0, 1, 0]$, and $[0, 0, 1]$:\n\\begin{equation*}\n  [x, y, z] = x[1, 0, 0] + y[0, 1, 0] + z[0, 0, 1]\n\\end{equation*}\nThese are called \\emph{standard generators} for $\\R^3$.\n\n% ================================================================\n\n\\section{Geometry of sets of vectors}\nSpan of a single nonzero vector $\\vv$:\n\\begin{equation*}\n  \\Span\\{\\vv\\} = \\{ \\alpha\\vv : \\alpha\\in\\R \\}\n\\end{equation*}\nThis is the line through the origin and $\\vv$, One-dimensional. The span of the empty set: just the origin, Zero-dimensional.\n\nOne way to specify a plane can be with:\n\\begin{equation*}\n  \\{ (x, y, z) : ax + by + cz = 0 \\}\n\\end{equation*}\n\nUsing dot-product, we could rewrite as\n\\begin{equation*}\n  \\{ [x, y, z] : [a, b, c] \\cdot [x, y, z] = 0 \\}\n\\end{equation*}\n\nWe can specify a line in three dimensions:\n\\begin{equation*}\n  \\{ [x, y, z] : \\va_1 \\cdot [x, y, z] = 0, \\va_2 \\cdot [x, y, z] = 0 \\}\n\\end{equation*}\n\nTwo ways to represent a geometric object (line, plane, etc.) containing the origin:\n\\begin{itemize}\n\\item Span of some vectors.\n\\item Solution set of some system of linear equations with zero right hand sides.\n\\end{itemize}\n\nWhat is common with these two representations? R: Subset $\\fF^D$ satisfies three properties:\n\\begin{enumerate}\n\\item Subset contains the zero vector $\\vzero$.\n\\item If subset contains $\\vv$ then it contains $\\alpha\\vv$ for every scalar $\\alpha$.\n\\item If subset contains $\\vu$ and $\\vv$ then it contains $\\vu + \\vv$.\n\\end{enumerate}\n\n\\begin{definition}[Vector space]\n  Any subset $\\sV$ of $\\fF^{D}$ satisfying the three properties is called a vector space.\n\\end{definition}\n\n\\begin{definition}\n  If $\\sU$ is also a vector space and $\\sU$ is a subset of $\\sV$ then $\\sU$ is called a subspace of $\\sV$.\n\\end{definition}\n\n\\subsection{Convex hull}\n\\begin{definition}\n  For vectors $\\vv_1, \\ldots, \\vv_n$ over $\\R$, a linear combination\n  \\begin{equation*}\n    \\alpha_1\\vv_1, \\ldots, \\alpha_n\\vv_n\n  \\end{equation*}\n  is a convex combination if the coefficients are all nonnegative and they sum to $1$.\n\\end{definition}\n\n% ================================================================\n\n\\section{Vector spaces}\nTo represent an object that doesn't contain the origin we sum a vector $\\vc$ and redefine the definition as:\n\\begin{equation*}\n  \\{ \\vc + \\vv : \\vv \\in \\sV \\}\n\\end{equation*}\nIt can also be abbreviated as $\\{ \\vc + \\sV \\}$.\n\n\\begin{definition}\n  A linear combination\n  \\begin{equation*}\n    \\alpha_1\\vu_1 + \\alpha_2\\vu_2 + \\cdots + \\alpha_n\\vu_n\n  \\end{equation*}\n  where\n  \\begin{equation*}\n    \\alpha_1 + \\alpha_2 + \\cdots + \\alpha_n = 1\n  \\end{equation*}\n  is an affine combination.\n\\end{definition}\n\n\\begin{definition}\n  The set of all affine combinations of vectors $\\vu_1, \\vu_2, \\ldots, \\vu_n$ is called the \\emph{affine hull} of those vectors.\n\\end{definition}\n\nAffine hull of $\\vu_1, \\vu_2, \\ldots, \\vu_n = \\{ \\vu_1 + \\Span\\{ \\vu_2 - \\vu_1, \\ldots, \\vu_n - \\vu_1 \\} \\}$. This shows that the affine hull is an affine space.\n\nIn general, a geometric object can be expressed as the solution set of a system of linear equations.\n\\begin{equation*}\n  \\{ \\vx : \\va_1\\cdot\\vx = \\beta_1, \\cdots, \\va_m\\cdot\\vx = \\beta_m \\}\n\\end{equation*}\n\nConversely, is the solution set an affine space?\nConsider solution set of a contradictory system of equations, e.g. $1x = 1, 2x = 1$:\n\\begin{itemize}\n\\item Solution set is empty\n\\item but a vector space $\\sV$ always contains the zero vector,\n\\item so an affine space $\\vu_1 + \\sV$ always contains at least one vector.\n\\end{itemize}\nTurns out this is the only exception:\n\\begin{theorem}\n  The solution set of a linear system is either empty or an affine space.\n\\end{theorem}\n\n\\begin{definition}\n  A linear equation $\\va\\cdot\\vx = 0$ with zero right-hand side is a homogeneous linear equation. A system of homogeneous linear equations is called a homogeneous linear system.\n\\end{definition}\n\n\\begin{lemma}\n  Let $\\vu_1$ be a solution to a linear system. Then, for any other vector $\\vu_2$, $\\vu_2$ is also a solution if and only if $\\vu_2-\\vu_1$ is a solution to the corresponding homogeneous linear system.\n\\end{lemma}\n\n", "meta": {"hexsha": "9b7885d1ffba82ad2168bb2721b91e836bf1edae", "size": 5126, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/week2.tex", "max_stars_repo_name": "aanzolaavila/coding-the-matrix-notes", "max_stars_repo_head_hexsha": "b4c0426ed1f1d0aff19a945d92880be0e9a5f69e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/week2.tex", "max_issues_repo_name": "aanzolaavila/coding-the-matrix-notes", "max_issues_repo_head_hexsha": "b4c0426ed1f1d0aff19a945d92880be0e9a5f69e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapters/week2.tex", "max_forks_repo_name": "aanzolaavila/coding-the-matrix-notes", "max_forks_repo_head_hexsha": "b4c0426ed1f1d0aff19a945d92880be0e9a5f69e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6142857143, "max_line_length": 201, "alphanum_fraction": 0.6605540382, "num_tokens": 1649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694178, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7308222137752909}}
{"text": "% !TEX root = ../main.tex\n\\newpage\n\\section{\\theory Network Topologies} \\label{sec:NetworkTopologies}\n\nNetworks consists of \\textsl{nodes} connected by \\textsl{links}. They arise in any context where objects are related to each other. In this section, we will look at the notation that is needed to represent networks, and properties of different network topologies.\n\n\\subsection{Representations and properties}\nWe represent a finite network through the adjacency matrix $A$: if there exists a relation from node $j$ to node $i$ we set $A_{ij} $ = 1, and 0 otherwise. This means that $A_{ij}$ can be \\textsl{undirected} (symmetric) or \\textsl{directed} (asymmetric). If we think of the relations between guests at a party, then the social network is directed: people might not mutually recognise others from previous parties. However, the network of people having shaken hands is symmetric. Self-links and multilinks form edge-cases that depend on the context, as one generally does not shake hands with oneself, nor twice with the same person. Here we will only allow self-links, so that the number of links a node can make is not larger than $N$, the number of nodes in the network.\\\\\n\nThe \\textsl{degree} $\\k$ of a node $n$  is a two-vector of the number of links coming in to and going out of the node, ($\\kin, \\kout$). From $A_{ij}$ we can compute the in- and out-degree vectors, which show how many links a node has coming in and out:\n\\begin{align}\n\\kinbi = \\sum_{j=1}^{N} A_{i j} \\hspace{15mm} \\koutbj = \\sum_{i=1}^{N} A_{i j}  \\hspace{15mm} \\degree(n_j) = \\k_j = (\\boldsymbol{k}_j^{\\bf in}, \\koutbj) \\in \\K \\subset \\mathbb{N} \\label{eq:definekinkoutfromA} \n\\end{align}\nThe average degree of the network is then: \n\\begin{align}\n\\kmean = \\frac{1}{N} \\sum_{i,j=1}^{N} A_{ij} = \\frac{1}{N} \\sum_{i=1}^{N} \\kinbi = \\frac{1}{N} \\sum_{j=1}^{N} \\koutbj \\label{eq:kmean} \n\\end{align}\nThe distribution of $\\kinb$ and $\\koutb$ is the most defining property of the network:\n\\begin{align}\n(\\kinb, \\koutb) \\sim P(\\degree(n) = \\k) \\label{eq:definekinkoutfromP} \n\\end{align}\nThe support of $P$ is the set of unique degrees $\\K$ with cardinality $M_\\k$. For symmetric networks, $\\kinb = \\koutb$, so that $P$ is really a univariate distribution. In this case, much of the coming analysis is heavily simplified, so we will start with univariate distributions. $\\K$ is then in principle always defined on the interval $\\{0, ... ,N \\}$ but in practice we define $\\K = \\{\\kmin, ... , \\kmax \\}$ using the lowest and highest sampled degree. \n\n\\subsection{Fixed-degree networks}\nThe most simple network is one where all the nodes are interconnected: all nodes have degree $N$ and we speak of a \\textsl{fully-connected} network. In general, we can make networks where all nodes have the same degree, which is thus the average degree $\\kmean$:\n\\begin{align}\nP(k) = \\left\\{\\begin{array}{ll}1 & \\text{if } k=\\kmean \\\\0 & \\text{otherwise}\\end{array}\\right. \\hspace{15mm} \\K = \\{ \\kmean \\} \\label{eq:diracpdf}\n\\end{align}\nWe will refer to these networks as \\textsl{fixed-degree} networks. \n\n\n\\subsection{Random / Erd{\\\"o}s-R{\\'e}ny networks}\nIn 1959, Erd{\\\"o}s and R{\\'e}ny published their work on random graphs \\cite{RandomGraphs1959}, where the probability of forming a link is given by $p$, the threshold on sampling links from a uniform distribution. The probability that a node has degree $k$ includes the probability $p^k$ that $k$ links are present, as a combination of $N$ candidate links, which requires $N-k$ links to be missing \\cite{BarabasiNetworkBook2016}. Hence, the degree vectors follow a binomial distribution:\n\\begin{align}\nP(k)=\\left(\\begin{array}{c}N \\\\ k\\end{array}\\right) p^{k}(1-p)^{N-k} \\label{eq:binomialpdf}\n\\end{align}\nwith mean $\\mu = pN$ and standard deviation $\\sigma = \\sqrt{\\mu(1-p)}$. For networks where $\\kmean \\ll N$, the network can be well approximated by a Poisson distribution:\n\\begin{align}\nP(k) = e^{-\\kmean} \\frac{\\kmean^{k}}{k !} \\hspace{15mm} \\label{eq:poissonpdf}\n\\end{align}\nwith mean $\\mu = \\kmean$ and standard deviation $\\sigma = \\sqrt{\\mu}$. Hence, random networks with the same average degree $\\kmean$ are indistinguishable. If we respect the conditions of the Poisson-limit theorem, we can reduce the analytical complexity of $P$. \n\nIn theory, \\eqref{eq:poissonpdf} is defined over the entirety of $\\mathbb{N}$, but in practice the probability of observing degrees not close to $\\kmean$ quickly drops to zero. For large random networks, we can thus assume that 99\\% of the degrees are found in $\\K = \\{ \\left \\lfloor{\\kmean - 2.58 \\sigma}\\right \\rfloor, ...,  \\left \\lceil{\\kmean + 2.58 \\sigma}\\right \\rceil \\}$.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = \\textwidth]{../Figures/Distributions/1D.pdf}\n\\caption{Univariate fixed-degree, random and scale-free distributions with the same average node degree $\\kmean$ = 100. The normalised histogram of $k \\in \\K$ follows $P(k)$ nicely as expected. Over the course of this work the colours used to indicate the different topologies will remain constant.}\n\\label{fig:1Dpdfs}\n\\end{figure}\n\n\n\\subsection{Scale-free networks}\nWhat we can observe in nature is the preferential attachment to nodes with a high degree \\cite{Bullmore2010}: the rich and famous tend to get more rich and famous. This trait is also described as the 80/20 rule by Pareto, who saw that 80\\% of the land in Italy was owned by 20\\% of the population \\cite{BarabasiNetworkBook2016}. Networks with this property consist of a small number of highly connected nodes, the \\textsl{hubs}, and a large number of low degree nodes. We can represent this with a power law distribution:\n\\begin{align}\nP(k) = C k^{-\\gamma} \\label{eq:scalefreepdf}\n\\end{align}\nwith $\\gamma > 1$ and $C$ a constant so that $\\sum_{k=1}^{\\infty} P(k) = 1$. We can see that $C \\cdot \\sum_{k=1}^{\\infty} k^{-\\gamma} = 1$ so that $C = \\sum_{k=1}^{\\infty} k^{\\gamma} = 1/\\zeta(k)$, the Riemann Z{\\`e}ta function \\cite{BarabasiNetworkBook2016}. As \\eqref{eq:scalefreepdf} diverges for $k = 0$, $\\kmin$ is usually fixed at 1.\\\\\n\nTo understand the scale of a distribution like \\eqref{eq:scalefreepdf} we first ask ourselves how the size of the network affects the degree of the hubs. We can easily calculate the \\textit{natural cutoff} $k_{\\text{max}}$, the highest degree in the network. We only expect the largest hub to be the only hub in the domain $[k_{\\text{max}}, +\\infty[$:\n\\begin{align*}\n\\int_{k_{\\text{max}}}^{\\infty} P(k) dk=\\frac{1}{N}\n\\end{align*}\nFollowing \\cite{BarabasiNetworkBook2016} for \\eqref{eq:scalefreepdf} this results in:\n\\begin{align}\n\\kmax = \\kmin \\cdot N^{\\frac{1}{\\gamma-1}} \\label{eq:scalefreecutoff}\n\\end{align}\nSo: larger networks yield larger hubs, and we can see there might be very large differences between the node degrees. This is one indication that a sense of \\textsl{scale} is missing. In practice, it is better to choose $\\kmin$ and $\\kmax$ and set $P$ to zero outside of $\\K$. \\\\\n\nThe term \\textsl{scale-free} can be even better understood from the moments of the degree distribution. Computing the $n^{\\text{th}}$ moment of \\eqref{eq:scalefreepdf} yields:\n\\begin{align}\n\\left\\langle k^{n}\\right\\rangle=\\int_{\\kmin}^{\\kmax} k^{n} P(k) d k=C \\frac{\\kmax^{n-\\gamma+1} - \\kmin^{n-\\gamma+1}}{n-\\gamma+1}\n\\end{align}\nThe degree exponent $\\gamma$ constrains the properties of the network as follows:\n\\begin{list}{$\\bullet$}{}  \n\\item 1 $< \\gamma <$ 2: $\\kmean$ diverges as the largest hub grows faster than $N$. Once $\\kmax$ exceeds $N$ there are no more new nodes to connect to and the network is not able to continue to grow. Therefore, these networks can not exist \\cite{Bassler2011, BarabasiNetworkBook2016}.\n\\item $\\gamma =$ 2: all nodes are connected to the same node, as the largest hub grows linearly with $N$.\n\\item 2 $< \\gamma < $ 3: $\\kmean$ is finite and positive, though the variance $\\left\\langle k^{2}\\right\\rangle$ is still divergent. This means that the node degrees can be arbitrarily far away from the average: when choosing a random node there is no limit on its degree. Hence, we call these networks \\textsl{scale-free}.\n\\item $ \\gamma = $ 3: the variance $\\left\\langle k^{2}\\right\\rangle$ stops diverging, and network properties like the average distance between nodes start converging towards those of a random network \\cite{BarabasiNetworkBook2016}.\n\\item 3 $< \\gamma$: as the degree distribution decays quickly, the hubs are not sufficiently large and numerous to have much influence on the network. \n\\end{list}\n\n%$\\kmean$ is thus only finite and positive for $\\gamma > 2$. When $0 < \\gamma < 2$, the largest hub grows faster than $N$, so once its degree exceeds $N-1$ there are no more new nodes to connect to and the network will not be able to grow according to \\eqref{eq:scalefreepdf}. A rigorous proof is given in \\cite{Bassler2011}. For $\\gamma = 2$, the system grows linearly, as we can see in \\eqref{eq:scalefreecutoff}. The variance $\\left\\langle k^{2}\\right\\rangle$ is only finite and positive for $\\gamma > 2$. For $\\gamma > 3$ hubs are not sufficiently large and numerous to have much influence on the network \\cite{BarabasiNetworkBook2016}.\n\n%We can observe \\eqref{eq:scalefreepdf} on different scales like the probability of two Hollywood actors appearing in a movie, or the connections between web pages on the internet \\cite{Barabasi2003}.\n\n\n\\subsection{Networks of theta neurons}\nThe human brain can be seen as a graph, with neurons as graph nodes, where the pre- to postsynaptic relation models a directional edge in the network. These edges are usually unidirectional though it can happen that the post- reconnects to the presynaptic neuron. Using this knowledge, we can easily extend the model to networks of neurons:\n\\begin{align}\n\\dot{\\theta}_{i} &=\\left(1-\\cos \\theta_{i}\\right)+\\left(1+\\cos \\theta_{i}\\right) \\cdot \\left[\\eta_{i} + I_{i}(t)\\right] \\qquad \\theta_i \\in \\T^N  \\label{eq:thetaneuronnetwork} \\\\\nI_{i}(t) &=\\frac{\\kappa}{\\kmean} \\sum_{j=1}^{N} A_{i j} \\cdot \\mathcal{P}_{s}(\\theta_{j}) \\label{eq:thetaneuronnetworkcurrent}\n\\end{align}\nThe excitability $\\eta_i \\sim g(\\eta \\rvert \\k)$ allows each neuron to attain an excitable or periodic regime. The interneuronal communication is modelled by the synaptic strength $\\kappa$ and modulated by $\\mathcal{P}_s(\\theta)$, a pulse-shaped signal that is emitted when a neuron fires. When $\\kappa$ is negative or positive, we say that the neurons \\textsl{inhibit} or \\textsl{excite} each another. As discussed in Chapter \\ref{sec:Introduction}, there are conversions from the action potential to neurotransmitters and back, but this process will be captured by using only $\\mathcal{P}$ as the action potential and $\\kappa$ as the \"efficiency\" of the conversions. \n\n$s$ models the sharpness of the pulse $\\mathcal{P}_s = a_s(1 - \\cos \\theta)^s$, with $a_s$ a normalisation constant so that $\\int_{\\T} \\mathcal{P}_{s} d \\theta=2 \\pi$. We will take $s=2$ from here, as in\\cite{Luke2013, OttAntonsen2017, Martens2020}. \n%Note that for a fully connected network, $A_{ij} = 1$ so that \\eqref{eq:thetaneuronnetworkcurrent} reduces to the work in \\cite{Luke2013} and \\cite{Martens2020}. \\\\\n\nIn \\eqref{eq:thetaneuronnetwork} we can see everything come together: changes to the phase $\\theta_i$ are induced by $\\dtheta_i$ which in turn depends on the bifurcation of $\\theta$ with magnitude $I_i$ which depends on all neurons in the network.\\\\\n\n%We can also understand why a fixed time-step solver is useful here: the memory demand of storing \\eqref{eq:thetaneuronnetworkcurrent} as double precision floating point numbers is about $ \\frac{t_b - t_a}{h+1} \\cdot N \\cdot 8 $ for $\\theta$, $N^2 \\cdot 8$ for $A_ij$. For 10.000 neurons integrated over 100 seconds at a time-step $h$ of 0.005 that is and 762.9 Mb respectively.\n\nStudying a set of differential equations like \\eqref{eq:thetaneuronnetworkcurrent} analytically is not feasible, as we are quickly approaching thousands of neurons. And in the end, the dynamics of a single neuron are not of interest. Instead, we wish to capture and study how the network behaves as a whole. When events are experienced by the neurons in unison we say that they are \\textsl{synchronised}. This concept can be captured by the Kuramoto order parameter:\n\\begin{align}\nZ(t) = \\frac{1}{N} \\sum_{j=1}^N e^{\\ic\\theta_j}  \\qquad Z \\in \\C \\label{eq:orderparameter}\n\\end{align}\n$Z$ is a complex variable, consisting of a radius $r = \\rvert Z \\rvert$ and argument $\\psi = \\arg \\left( Z \\right)$, so that $Z(t) = r(t) e^{\\ic \\psi(t)}$. When all phases are uniformly distributed across the unit circle $\\T$, then $\\rvert Z \\rvert = 0$, resulting in a network with no synchronisation. When all phases are exactly the same, $\\rvert Z \\rvert = 1$ and the network is fully scynchronised. \\eqref{eq:orderparameter} describes the \\textsl{mean-field} of the network, a simpler model that describes the average behaviour of the whole network. Analysis is simply conducted either on $ \\rvert Z(t) \\rvert$ versus time, or in the complex unit circle as $\\Re (Z(t))$ versus $\\Im (Z(t))$.\n\nDifferent works on the dynamics of \\eqref{eq:orderparameter} have been published \\cite{Luke2013, Martens2020}, and we will build on that analysis in the following chapters.\n\n\n", "meta": {"hexsha": "85197c696ac61d535cdde930705a59b2e55896d6", "size": 13223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Writing/Mainmatter/Networks.tex", "max_stars_repo_name": "simonaertssen/AdaptiveNeuronalNetworks", "max_stars_repo_head_hexsha": "506a4e8aba392330f8a6ecc6b229e2c8322b8e83", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Writing/Mainmatter/Networks.tex", "max_issues_repo_name": "simonaertssen/AdaptiveNeuronalNetworks", "max_issues_repo_head_hexsha": "506a4e8aba392330f8a6ecc6b229e2c8322b8e83", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Writing/Mainmatter/Networks.tex", "max_forks_repo_name": "simonaertssen/AdaptiveNeuronalNetworks", "max_forks_repo_head_hexsha": "506a4e8aba392330f8a6ecc6b229e2c8322b8e83", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 118.0625, "max_line_length": 774, "alphanum_fraction": 0.7365953263, "num_tokens": 3863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7308222010902721}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Linear and Separable ODEs}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises related to solving linear and separable ODEs.\n\\end{abstract}\n\\maketitle\n\n\nRemember: several of these exercises involve logarithms. Use absolute value signs inside the logarithm when they're needed.\n\n\\begin{exercise}%[APEX2002SEPODE06]\nFind the general solution of the ODE below. \n\\[ y' = y - 2 \\]\n\\[ \\text{General Solution: } \\ \\ y = C \\answer{e^x} + \\answer{2} \\]\n(For definiteness, the expression you enter in the second blank should equal $2$ when $x = 0$.)\n\\begin{hint}\nThis ODE is both linear and separable, so either approach will work.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}%[APEX2003LINODE02]\nFind the general solution of the ODE below.\n\\[ x^2 y' + xy = 1 \\]\n\\[ \\text{General Solution: } \\ \\  y = \\answer{\\frac{\\ln |x|}{x}} + \\frac{C}{x} \\]\n(For definiteness, the function you enter for your answer should equal $0$ at $x=1$. If that's not the case, you might need to rewrite your solution and redefine the constant $C$.)\n\\begin{hint}\nThis is a linear ODE.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}%[APEX2002SEPODE08]\nFind the general solution of the ODE below.\n\\[ y y' = 4x \\]\n\\[ \\text{General Solution: } \\ \\  y^2 =  \\answer{4 x^2} + C \\]\n(For definiteness, the function you enter for your answer should equal $0$ at $x=0$. If that's not the case, you might need to rewrite your solution and redefine the constant $C$.)\n\\begin{hint}\nThis is a separable ODE. In the form written, it's \\textit{already} separated.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}%[APEX2003LINODE07]\n\\[ y'-3y=xe^{2x} \\]\n\\[ \\text{General Solution: } \\ \\  y = C\\answer{e^{3x}}-(x+1)\\answer{e^{2x}} \\]\n\\begin{hint}\nThis is a linear ODE.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}%[APEX2002SEPODE10]\n\\[ (x^2+1) y' = \\frac{x}{y-1} \\]\n\\[ \\text{General Solution: } \\ \\  (y-1)^2 = \\answer{\\ln (x^2 + 1)} + C \\]\n(For definiteness, the function you enter for your answer should equal $0$ at $x=0$. If that's not the case, you might need to rewrite your solution and redefine the constant $C$.)\n\\begin{hint}\nThis is a separable ODE.\n\\end{hint}\n\\end{exercise}\n\n\n\\begin{exercise}%[APEX2002SEPODE19]\nSolve the initial value problem\n\\[ y' = \\cos^2 x \\cos^2 2y \\text{ with } y(0) = 0. \\]\n%\\[ 2 \\tan 2y = 2x + sin 2x \\]\n\\[ \\text{Solution: } \\ \\ y = \\answer{\\frac{1}{2} \\arctan \\left( x + \\frac{1}{2} \\sin 2x \\right)} \\]\n\\begin{hint}\nThis is a separable ODE.\n\\end{hint}\n\\end{exercise}\n\n\n\\begin{exercise}%[APEX2003LINODE14]\nSolve the initial value problem\n\\[  y' + (\\tan x) y = \\sec x \\text{ with } y(0) = -3.\\]\n\\[\\text{Solution: } \\ \\ y = \\answer{\\sin x - 3\\cos x}\\]\n\\begin{hint}\nThis is a linear ODE. The integral of $\\tan x$ is $-\\ln |\\cos x|$.\n\\end{hint}\n\\end{exercise}\n\n\\section*{Sample Quiz Questions}\n\n\\begin{question}%%%%%[SepIVP001]\n\nLet \\(y(x)\\) be the solution to the initial value problem \\[  \\frac{dy}{dx}  = -(1 + 3 x^2)y^2\\] and \\(y(0) = 1/2\\).  What is the value of \\(y(1)\\)?\n\\begin{multiplechoice}\n\\choice{\\( \\displaystyle \\frac{1}{6}\\)}\n\\choice[correct]{\\( \\displaystyle \\frac{1}{4}\\)}\n\\choice{\\( \\displaystyle \\frac{1}{3}\\)}\n\\choice{\\( \\displaystyle \\frac{1}{2}\\)}\n\\choice{\\( \\displaystyle \\frac{\\pi}{4}\\)}\n\\choice{\\( \\displaystyle 1\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nThis is a separable ODE. Moving all functions of \\(y\\) to the left-hand side and all functions of \\(x\\) to the right-hand side and integrating gives \\[\\int  \\frac{ -1  }{ y^2} ~ dy = \\int (1 + 3 x^2) ~ dx, \\] which yields \\[\\frac{1}{y} = x^3 + x + C.\\] Evaluating at \\(x = 0\\) and \\(y = 1/2\\) gives \\(2 = 0 + C\\), so \\[\\frac{1}{y} = x^3 + x + 2,\\] i.e., \\[y = \\frac{1}{x^3 + x + 2}.\\] Plugging in \\(x = 1\\) gives \\(y = 1/4\\).\n\\end{feedback}\n\n\\end{question}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%%%%%[2015C.06]\n\nThe solution of the initial value problem \\(\\displaystyle x \\frac{dy}{dx} + 3y = 7 x^4\\),  \\(y(1) = 1\\),\nsatisfies \\(y(2) = \\)\n\\begin{multiplechoice}\n\\choice{\\(0\\)}\n\\choice{\\(1\\)}\n\\choice{\\(2\\)}\n\\choice{\\(4\\)}\n\\choice{\\(8\\)}\n\\choice[correct]{\\(16\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2015C.07]\n\nThe solution of the initial value problem \\(\\displaystyle \\frac{dy}{dx} - 20 x^4 e^{-y} = 0\\),  \\(y(0) = 0\\),\nsatisfies \\(y(1) = \\)\n\\begin{multiplechoice}\n\\choice[correct]{\\(\\ln 5\\)}\n\\choice{\\(\\ln 4\\)}\n\\choice{\\(\\ln 3\\)}\n\\choice{\\(\\ln 2\\)}\n\\choice{\\(1\\)}\n\\choice{\\(0\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2016C.13]\n\nLet \\(y(x)\\) be the solution of the initial value problem\n\\[ x \\frac{dy}{dx} = e^x - y \\ \\text{ with } \\ y(\\ln 2) = 0. \\]\nFind \\(y(1)\\).\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\frac{e^2}{2}\\)}\n\\choice{\\(\\displaystyle 2e^2\\)}\n\\choice{\\(\\displaystyle \\frac{e}{2}\\)}\n\\choice{\\(0\\)}\n\\choice[correct]{\\(e-2\\)}\n\\choice{\\(1\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2017C.07]\n\nLet \\(y(x)\\) be the solution of the initial value problem\n\\[ x \\frac{dy}{dx} = y + x^2 \\sin x \\ \\text{ with } \\ y (\\pi) = 0. \\]\nWhat is \\(y(2 \\pi)\\)?\n\\begin{multiplechoice}\n\\choice{\\(-\\pi\\)}\n\\choice{\\(-2\\pi\\)}\n\\choice[correct]{\\(-4\\pi\\)}\n\\choice{\\(0\\)}\n\\choice{\\(2\\pi\\)}\n\\choice{\\(4\\pi\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2017C.08]\n\nConsider the initial value problem\n\\[ (1 + x^2) \\frac{dy}{dx} = 2y \\ \\text{ with } \\ y(0) = 2. \\]\nWhat is \\(\\displaystyle \\lim_{x \\rightarrow \\infty} y(x)\\)?\n\\begin{multiplechoice}\n\\choice[correct]{\\(2e^{\\pi}\\)}\n\\choice{\\(2e^{\\pi/2}\\)}\n\\choice{\\(2e^{\\pi/4}\\)}\n\\choice{\\(1\\)}\n\\choice{\\(0\\)}\n\\choice{\\(e^{\\pi}\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "b565d79ae4dd7d4d06ab748c591528430b17f1b8", "size": 5645, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "odes/30solvepractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "odes/30solvepractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "odes/30solvepractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.6793478261, "max_line_length": 425, "alphanum_fraction": 0.630469442, "num_tokens": 2093, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7308221979506814}}
{"text": "\\documentclass[10pt]{article}\n\n\\usepackage[letter paper, margin=.5in]{geometry}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amsthm}\n\\usepackage{multicol}\n\n\n\\newcommand{\\bd}[1]{\\mathbf{#1}}\t%bolding symbols\n\\newcommand{\\mean}[1]{\\bar{#1}}\n\\newcommand{\\iSum}[2]{\\sum_{i= #1}^{#2}}\n\\newcommand{\\jSum}[2]{\\sum_{j= #1}^{#2}}\n\\newcommand{\\pN}[2]{\\mathcal{N}(#1, #2)}\n\\newcommand{\\abs}[1]{\\lvert#1\\rvert}\n\n\n\\begin{document}\n\\begin{multicols}{2}\n\\section*{One Population t Test}\nTest Statistic:\\\\\n$$t = \\frac{\\mean{x}-\\mu_{0}}{\\frac{S}{\\sqrt{n}}} \\sim \\pN{0}{1}$$\n\\begin{enumerate}\n\t\\item $H_{0}:\\mu\\leq\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}>\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $t > t_{\\alpha, n-1}$\n\t\\item $H_{0}:\\mu\\geq\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}<\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $t < _{\\alpha, n-1}$\n\t\\item $H_{0}:\\mu = \\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}\\neq\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $\\abs{t} > t_{\\frac{\\alpha}{2}, n-1}$\n\\end{enumerate}\n\n\\section*{Two Population t Test}\nTest Statistic:\\\\\n$$t = \\frac{\\mean{x}-\\mean{y}}{S_p\\sqrt{\\frac{1}{n_{1}}+\\frac{1}{n_{2}}}}$$\n\\begin{enumerate}\n\t\\item $H_{0}:\\mu\\leq\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}>\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $t > t_{\\alpha, n_{1}+n_{2}-2}$\n\t\\item $H_{0}:\\mu\\geq\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}<\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $t < _{\\alpha, n_{1}+n_{2}-2}$\n\t\\item $H_{0}:\\mu = \\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}\\neq\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $\\abs{t} > t_{\\frac{\\alpha}{2}, n_{1}+n_{2}-2}$\n\\end{enumerate}\n\n\\section*{NonParametric One Population Test}\nTest Statistic:\\\\\nLet y = \\# of observations that excede $\\eta_{0}$ among the population.\\\\\n$$Z = \\frac{y-\\frac{n}{2}}{\\sqrt{\\frac{n}{4}}}$$\n\\begin{enumerate}\n\t\\item $H_{0}:\\mu=\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}>\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $Z > Z_{\\alpha}$\n\t\\item $H_{0}:\\mu=\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}<\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $Z < -Z_{\\alpha}$\n\t\\item $H_{0}:\\mu=\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}\\neq\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $\\abs{Z} > Z_{\\alpha}$\n\\end{enumerate}\n\n\\section*{NonParametric Two Population Test}\nMethod: Form n differences $d_{i}=x_{i}-y_{i}$ for i = 1, 2, \\ldots, n and rank the absolute differences $\\abs{d_{i}}$ in increasing order.  Write the ranks of $\\abs{d_{i}}$ as 1 to n, then attack the sign of $d_{i}$ to its rank.  The ranks with the appropriate signs attached are called the signed ranks, $R_{i}$.  If a tie occurs, replace tied ranks by their average rank.  Compute the sum of the signed ranks, $T = \\iSum{1}{n}R_{i}$.  If $d_{i} = 0$ remove it from the calculation and reduce n accordingly.\\\\\nTest Statistic:\\\\\n$$Z = \\frac{T}{\\sqrt{\\frac{n(n+1)(2n+1)}{6}}}$$\n\\begin{enumerate}\n\t\\item $H_{0}:\\mu=\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}>\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $Z > Z_{\\alpha}$\n\t\\item $H_{0}:\\mu=\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}<\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $Z < -Z_{\\alpha}$\n\t\\item $H_{0}:\\mu=\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}\\neq\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $\\abs{Z} > Z_{\\alpha}$\n\\end{enumerate}\nExact Test: \n\t\\\\$T_{+}$ = sum of the positive ranks\n\t\\\\$T_{-}$ = sum of the negative ranks\n\t\\\\$T_{min} = Min(T_{+}, T_{-})$\n\\begin{enumerate}\n\t\\item $H_{0}:\\mu=\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}>\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $T_{-} < T_{\\alpha(1), n}$\n\t\\item $H_{0}:\\mu=\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}<\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $T_{+} < T_{\\alpha(1), n}$\n\t\\item $H_{0}:\\mu=\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}\\neq\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $T_{min} > T_{\\alpha(2), n}$\n\\end{enumerate}\n\n\\section*{Mann-Whitney Test}\nUsed to determine if there is a difference between two independent populations.  Let $x_{1}, x_{2}, \\ldots, x_{n_{2}}$ be a random sample of size $n_{2}$ from the first population and $y_{1}, y_{2}, \\ldots, y_{n_{2}}$ be a random sample of size $n_{2}$ from the second population.\\\\\nMethod:\\\\\nRank the combined sample observations from lowest to highest, with tied values assigned as the average of the rankings.\\\\\ncompute $T_{1}$ - the sum of the ranks of the first sample.\\\\\nTest Statistic:\\\\\nLet $\\mu_{T_{1}} = \\frac{1}{2}n_{1}(n_{1}+n_{2}+1)$ and\\\\\n$\\sigma_{T_{1}} = \\sqrt{\\frac{1}{12}n_{1}n_{2}(n_{1}+n_{2}+1)}$\\\\\n$$Z = \\frac{T_{1}-\\mu_{T_{1}}}{\\sigma_{T_{1}}}$$\n\\begin{enumerate}\n\t\\item $H_{0}:\\mu=\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}>\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $Z > Z_{\\alpha}$\n\t\\item $H_{0}:\\mu=\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}<\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $Z < -Z_{\\alpha}$\n\t\\item $H_{0}:\\mu=\\mu_{0}\\quad vs. \\quad H_{I}:\\mu_{0}\\neq\\mu_{0}$\n\t\\\\Reject $H_{0}$ if $\\abs{Z} > Z_{\\alpha}$\n\\end{enumerate}\n\n\\section*{One Way ANOVA}\nTotal number of observations: $$N = n_{1} + n_{2} + \\ldots + n_{k}$$\nGrand total: $$G = T_{1} + T_{2} + \\ldots + T_{k}$$\nCorrection Term: $$CT = \\frac{G^{2}}{N}$$\nTreatment Sum of Squares: $$SS_{TR} = \\left( \\frac{T_{1}^{2}}{n_{1}} + \\frac{T_{2}^{2}}{n_{2}} + \\ldots + \\frac{T_{k}^{2}}{n_{k}} \\right) -CT$$\nTotal Sum of Squares: $$SS_{T} = \\iSum{1}{k}\\jSum{1}{n_{i}}y^{2}_{ij}-CT$$\nError Sum of Squares: $$SS_{E} = SS_{T} - SS_{TR}$$\nANOVA Table:\n\\begin{center}\n\\begin{tabular}{|l|c|c|c|c|}\n\t\\hline\n\tSource & dof & SS & MS & F \\\\\n\t\\hline\n\t\\hline\n\tTreatment & $k-1$ & $SS_{TR}$ & $MS_{TR} = \\frac{SS_{TR}}{k-1}$ & $F = \\frac{MS_{TR}}{MS_{E}}$\\\\\n\t\\hline\n\tError & $N - k$ & $SS_{E}$ & $MS_{E}$ & \\\\\n\t\\hline\n\t\\hline\n\tTotal & $N - 1$ & $SS_{T}$ & & \\\\\n\t\\hline\n\\end{tabular}\n\\end{center}\n$H_{0}: \\mu_{1}=\\mu_{2}=\\ldots=\\mu_{k}$\\\\\nReject $H_{0}$ if $F > F_{\\alpha, k-1, N-k}$\n\n\\section{Hartley's Test}\n$H_{0}$: $\\sigma^{2}_{1} = \\sigma^{2}_{2} = \\ldots \\sigma^{2}_{k}$ vs. $H_{I}$: At least one different\\\\\nTest Statistic:\\\\\nFor $S_{i}^{2}$ = sample variance for ith population.\n$$F_{max} = \\frac{max(S_{i}^{2})}{min(S_{i}^{2})}$$\nReject $H_{0}$ if $F_{max}>F_{max(\\alpha),k,\\nu}$\\\\\nfor k = number of groups \\\\\nand $\\nu$ = $max(n_{1}-1, n_{2}-1, \\ldots, n_{i}-1)$\n\n\\section{Brown-Forsythe-Levene (BFL) Test}\n\n\n\\end{multicols}\t\n\\end{document}", "meta": {"hexsha": "c63cbe17df91a8fd0b071cd0d8cede037ae553e1", "size": 5905, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Statistical Quality Control/STA 5174 Equation Sheet.tex", "max_stars_repo_name": "derek-elliott/homework", "max_stars_repo_head_hexsha": "2731cadcd3617d96e9d582419cf04c623846037c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Statistical Quality Control/STA 5174 Equation Sheet.tex", "max_issues_repo_name": "derek-elliott/homework", "max_issues_repo_head_hexsha": "2731cadcd3617d96e9d582419cf04c623846037c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Statistical Quality Control/STA 5174 Equation Sheet.tex", "max_forks_repo_name": "derek-elliott/homework", "max_forks_repo_head_hexsha": "2731cadcd3617d96e9d582419cf04c623846037c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.4820143885, "max_line_length": 511, "alphanum_fraction": 0.5896697714, "num_tokens": 2612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811306, "lm_q2_score": 0.8031738057795402, "lm_q1q2_score": 0.730813474907266}}
{"text": "\\chapter{Some mathematical results}\n\\section{Green's theorem}\\label{c2sa1}\nWe will prove Green's theorem\n\\begin{equation}\\label{c2sae1}\n\\int\\left(\\phi\\nabla^2\\psi - \\psi\\nabla^2\\phi\\right)dV = \\int\\left(\\phi\\grad{\\psi} - \\psi\\grad{\\phi}\\right)\\cdot\\un dA\n\\end{equation}\nLet $\\vec{A} = \\phi\\grad{\\psi}$ and $\\vec{B} = \\psi\\grad{\\psi}$. Then,\n\\[\n\\int\\left(\\vec{A} - \\vec{B}\\right)\\cdot\\un dA = \\int\\dive{(\\vec{A} - \\vec{B})}dV\n\\]\nNow, $\\dive{\\vec{A}} = \\dive{(\\phi\\grad{\\psi})} = \\grad{\\phi}\\cdot\\grad{\\psi} + \\phi\\nabla^2\\psi$. Similarly, $\\dive{\\vec{B}} = \\grad{\\psi}\\cdot\\grad{\\phi} + \\psi\\nabla^2\\phi$. Therefore,\n\\[\n\\int(\\vec{A} - \\vec{B})\\cdot\\un dA = \\int\\left(\\phi\\nabla^2\\psi - \\psi\\nabla^2\\phi\\right)dV\n\\]\n\n\\section{Solution of Poisson equation}\\label{c2sa2} \nWe will show that the solution of the Poisson's equation $\\nabla^2\\phi = \\Delta$ is\n\\[\n\\phi(\\vec{x}) = -\\frac{1}{4\\pi}\\int\\frac{\\Delta(\\vec{x}^\\op)}{|\\vec{x} - \\vec{x}^\\op|} dV(\\vec{x}^\\op)\n\\]\nWe begin with Fourier transform of $\\nabla^2\\phi = \\Delta(\\vec{x})$. Thus,\n\\[\n\\frac{1}{(2\\pi)^{3/2}}\\int_{-\\infty}^{\\infty} e^{-i\\vec{k}\\cdot\\vec{x}}\\nabla^2\\phi dV = \\frac{1}{(2\\pi)^{3/2}}\\int_{-\\infty}^{\\infty} e^{-i\\vec{k}\\cdot\\vec{x}}\\Delta(\\vec{x}) dV\n\\]\nUse Green's theorem \\eqref{c2sae1} on the left hand side to get,\n\\begin{eqnarray*}\n\\frac{1}{(2\\pi)^{3/2}}\\int_{-\\infty}^{\\infty} \\phi\\nabla^2e^{-i\\vec{k}\\cdot\\vec{x}} dV &=& \\frac{1}{(2\\pi)^{3/2}}\\int_{-\\infty}^{\\infty} e^{-i\\vec{k}\\cdot\\vec{x}}\\Delta(\\vec{x}) dV \\\\\n+ \\frac{1}{(2\\pi)^{3/2}}\\int_{-\\infty}^{\\infty} e^{-i\\vec{k}\\cdot\\vec{x}} \\grad{\\phi}\\cdot\\un dA & & \\\\\n- \\frac{1}{(2\\pi)^{3/2}}\\int_{-\\infty}^{\\infty} \\phi \\grad{e^{-i\\vec{k}\\cdot\\vec{x}}}\\cdot\\un dA\n\\end{eqnarray*}\nThe second and the third term on the left hand side can be written as\n\\[\n\\lim_{R \\rightarrow \\infty} \\frac{R^2}{(2\\pi)^{3/2}}\\int_0^\\pi\\int_0^{2\\pi}\\left(e^{-i\\vec{k}\\cdot\\vec{x}} \\grad{\\phi} - \\phi \\grad{e^{-i\\vec{k}\\cdot\\vec{x}}}\\right)\\sin\\theta \nd\\theta d\\varphi\n\\]\nFor a function $\\phi$ that goes to zero faster than $1/r^2$ as $r \\rightarrow \\infty$, the above expression will be zero. Therefore,\n\\begin{equation}\\label{c2sae2}\n\\frac{1}{(2\\pi)^{3/2}}\\int_{-\\infty}^{\\infty} \\phi\\nabla^2e^{-i\\vec{k}\\cdot\\vec{x}} dV = \\frac{1}{(2\\pi)^{3/2}}\\int_{-\\infty}^{\\infty} e^{-i\\vec{k}\\cdot\\vec{x}}\\Delta(\\vec{x}) dV \n\\end{equation}\nTo calculate $\\nabla^2e^{-i\\vec{k}\\cdot\\vec{x}}$, we assume, without loss of generality, that $\\vec{k}$ is along the positive $z$ axis so that $\\vec{k}\\cdot\\vec{x} = kr\\cos\\theta$.\nTherefore,\n\\begin{eqnarray*}\n\\nabla^2e^{-i\\vec{k}\\cdot\\vec{x}} &=& \\frac{1}{r^2}\\frac{\\partial}{\\partial r}\\left(r^2\\frac{\\partial}{\\partial r} e^{-ikr\\cos\\theta}\\right) + \\\\\n & & \\frac{1}{r^2\\sin\\theta}\\frac{\\partial}{\\partial\\theta}\\left(\\sin\\theta\\frac{\\partial}{\\partial\\theta} e^{-ikr\\cos\\theta}\\right) + \\\\\n & & \\frac{1}{r^2\\sin^2\\theta}\\frac{\\partial^2}{\\partial\\phi^2}e^{-ikr\\cos\\theta}\n\\end{eqnarray*}\nor\n\\[\n\\nabla^2e^{-i\\vec{k}\\cdot\\vec{x}} = -k^2e^{-ikr\\cos\\theta} = -k^2e^{-i\\vec{k}\\cdot\\vec{x}}\n\\]\nTherefore, equation \\eqref{c2sae2} becomes,\n\\[\n-\\frac{k^2}{(2\\pi)^{3/2}}\\int_{-\\infty}^{\\infty} \\phi e^{-i\\vec{k}\\cdot\\vec{x}} dV = \\frac{1}{(2\\pi)^{3/2}}\\int_{-\\infty}^{\\infty} e^{-i\\vec{k}\\cdot\\vec{x}}\\Delta(\\vec{x}) dV \n\\]\nIf $\\hat{f}(\\vec{k})$ denotes the Fourier transform of $f(\\vec{x})$, the above equation means,\n\\[\n-k^2\\hat{\\phi}(\\vec{k}) = \\hat{\\Delta}(\\vec{k}) \\Rightarrow \\hat{\\phi}(\\vec{k}) = -\\frac{\\hat{\\Delta}(\\vec{k})}{k^2}\n\\]\nTherefore,\n\\[\n\\phi(\\vec{x}) = \\phi_h(\\vec{x}) - \\frac{1}{(2\\pi)^{3/2}}\\int_{-\\infty}^{\\infty} \\frac{\\hat{\\Delta}(\\vec{k})}{k^2} e^{i\\vec{k}\\cdot\\vec{x}} dV_k\n\\]\nwhere $dV_k$ denotes the volume element in the $\\vec{k}$-space and $\\phi_h(\\vec{x})$ is any solution of the homogeneous equation $\\nabla^2\\phi = 0$. Using the expression for \n$\\hat{\\Delta}(\\vec{k})$, we get\n\\[\n\\phi(\\vec{x})=\\phi_h(\\vec{x})-\\frac{1}{(2\\pi)^{3}}\\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} \\Delta(\\vec{x}^\\op)\\frac{e^{i\\vec{k}\\cdot(\\vec{x}-\\vec{x}^\\op)}}{k^2}dV^\\op dV_k,\n\\]\nwhere $dV^\\op$ is integration over $\\vec{x}^\\op$. Let,\n\\[\nG(\\vec{x}, \\vec{x}^\\op) = -\\frac{1}{(2\\pi)^{3}}\\int_{-\\infty}^{\\infty}\\frac{e^{i\\vec{k}\\cdot(\\vec{x}-\\vec{x}^\\op)}}{k^2}dV_k\n\\]\nbe the Green function so that,\n\\begin{equation}\\label{c2sae3}\n\\phi(\\vec{x})=\\phi_h(\\vec{x}) + \\int_{-\\infty}^{\\infty}G(\\vec{x}, \\vec{x}^\\op)\\Delta(\\vec{x}^\\op) dV^\\op\n\\end{equation}\nThe Green function is an integral in $\\vec{k}$-space. Therefore, without loss of generality, we can orient the $k_z$ axis parallel \nto the vector $\\vec{x}-\\vec{x}^\\op$ so that\n\\[\nG(\\vec{x}, \\vec{x}^\\op) = -\\frac{1}{(2\\pi)^{3}}\\int_{0}^{\\infty}\\int_0^\\pi\\int_0^{2\\pi}\\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|\\cos\\theta}}{k^2}k^2\\sin\\theta dk d\\theta d\\varphi\n\\]\nor\n\\[\nG(\\vec{x}, \\vec{x}^\\op) = -\\frac{1}{(2\\pi)^{2}}\\int_{0}^{\\infty}\\int_0^\\pi e^{ik|\\vec{x}-\\vec{x}^\\op|\\cos\\theta}\\sin\\theta dk d\\theta\n\\]\nPut $t = \\cos\\theta$ so that,\n\\[\nG(\\vec{x}, \\vec{x}^\\op) = \\frac{1}{(2\\pi)^{2}}\\int_{0}^{\\infty}\\int_1^{-1} e^{ik|\\vec{x}-\\vec{x}^\\op| t} dt dk\n\\]\nor\n\\[\nG(\\vec{x}, \\vec{x}^\\op) = \\frac{1}{(2\\pi)^{2}}\\int_{0}^{\\infty}\\left( \\frac{e^{ik|\\vec{x}-\\vec{x}^\\op| t}}{ik|\\vec{x}-\\vec{x}^\\op|}\\Big|_{1}^{-1}\\right)dk\n\\]\nor\n\\[\nG(\\vec{x}, \\vec{x}^\\op) = \\frac{i}{(2\\pi)^{2}}\\int_{0}^{\\infty} \\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|} - e^{-ik|\\vec{x}-\\vec{x}^\\op|}}{k|\\vec{x}-\\vec{x}^\\op|} dk\n\\]\nor,\n\\[\nG(\\vec{x}, \\vec{x}^\\op) = \\frac{i}{(2\\pi)^{2}}\\frac{1}{|\\vec{x}-\\vec{x}^\\op|}\\int_{0}^{\\infty} \\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|} - e^{-ik|\\vec{x}-\\vec{x}^\\op|}}{k} dk\n\\]\nNow,\n\\begin{eqnarray*}\n\\int_{0}^{\\infty} \\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|} - e^{-ik|\\vec{x}-\\vec{x}^\\op|}}{k} dk &=& \\\\\n\\int_{0}^{\\infty} \\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|}}{k} dk - \\int_{0}^{\\infty} \\frac{e^{-ik|\\vec{x}-\\vec{x}^\\op|}}{k} dk &=& \\\\\n\\int_{0}^{\\infty} \\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|}}{k} dk - \\int_{0}^{-\\infty} \\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|}}{(-k)} d(-k) &=& \\\\\n\\int_{0}^{\\infty} \\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|}}{k} dk + \\int_{-\\infty}^{0} \\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|}}{k} dk &=& \\\\\n\\int_{-\\infty}^{\\infty} \\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|}}{k} dk\n\\end{eqnarray*}\nso that,\n\\begin{equation}\\label{c2sae4}\nG(\\vec{x}, \\vec{x}^\\op) = \\frac{i}{(2\\pi)^{2}}\\frac{1}{|\\vec{x}-\\vec{x}^\\op|}\\int_{-\\infty}^{\\infty} \\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|}}{k} dk\n\\end{equation}\nWe can evaluate the integral using residue theorem. Consider a semi-circular contour with diameter along the real axis, from $-R$ to $R$ and arc in the first two quadrants. Now the\nintegrand has a singularity the origin, a point on the contour. Therefore, we have to take the Cauchy principal value of the integrand. To that end, indent the contour by a small \nsemi-circulararc with diameter along the real axis, from $-a$ to $a$ and arc in the first two quadrants. The indented contour now no longer has the singularity in its interior and\nhence by Cauchy theorem, the integral around it is zero. If $C_1$ denotes the larger arc and $C_2$ the smaller one, then\n\\begin{equation}\\label{c2sae5}\n\\left(\\int_{C_1} + \\int_{-R}^{-a} + \\int_{C_2} + \\int_{a}^R\\right)\\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|}}{k} dk = 0\n\\end{equation}\nIn the limit $R \\rightarrow \\infty$, the integral along $C_1$ vanishes because the integrand itself goes to zero. Along $C_2$, $k = \\rho e^{i\\theta}$, $dk = i\\rho e^{i\\theta}d\\theta$ and\nthe limits of the integral are from $\\pi$ to $0$. Thus,\n\\begin{eqnarray*}\n\\int_{C_2}\\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|}}{k} dk &=& \\int_{\\pi}^0 \\exp\\left(i\\rho|\\vec{x}-\\vec{x}^\\op|(\\cos\\theta+i\\sin\\theta)\\right)\\frac{i\\rho e^{i\\theta}d\\theta}{\\rho e^{i\\theta}} \\\\\n &=& i\\int_{\\pi}^0 \\exp\\left(i\\rho|\\vec{x}-\\vec{x}^\\op|(\\cos\\theta+i\\sin\\theta)\\right) d\\theta\n\\end{eqnarray*}\nIn the limit $\\rho \\rightarrow 0$, we can approximate the integrand by its Maclaurin series so that,\n\\begin{eqnarray*}\n\\int_{C_2}\\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|}}{k} dk &=& i\\int_{\\pi}^0 \\left(1 + i\\rho|\\vec{x}-\\vec{x}^\\op|(\\cos\\theta+i\\sin\\theta)\\right) d\\theta \\\\\n &=& -i\\pi + 2\\rho|\\vec{x}-\\vec{x}^\\op|,\n\\end{eqnarray*}\nwhich, in the limit of vanishing $\\rho$ gives $-i\\pi$. Therefore, equation \\eqref{c2sae5} becomes,\n\\[\n\\int_{-\\infty}^\\infty \\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|}}{k} dk = -\\int_{C_2}\\frac{e^{ik|\\vec{x}-\\vec{x}^\\op|}}{k} dk = i\\pi\n\\]\nTherefore, equation \\eqref{c2sae4} becomes,\n\\[\nG(\\vec{x}, \\vec{x}^\\op) = -\\frac{1}{4\\pi}\\frac{1}{|\\vec{x}-\\vec{x}^\\op|}\n\\]\nTherefore from \\eqref{c2sae3}\n\\[\n\\phi(\\vec{x})=\\phi_h(\\vec{x}) - \\frac{1}{4\\pi}\\int_{-\\infty}^{\\infty}\\frac{\\Delta(\\vec{x}^\\op)}{|\\vec{x}-\\vec{x}^\\op|} dV^\\op\n\\]\nSince $\\phi_h(r) = 0$ is a solution of the Laplace's equation,\n\\[\n\\phi(\\vec{x}) = - \\frac{1}{4\\pi}\\int_{-\\infty}^{\\infty}\\frac{\\Delta(\\vec{x}^\\op)}{|\\vec{x}-\\vec{x}^\\op|} dV^\\op\n\\]\nis a solution of the Poisson's equation $\\nabla^2\\phi = \\Delta(\\vec{x})$.\n\n\\section{Another form of Stokes's theorem}\\label{c2sa3} \nWe will prove an analog of Stokes' theorem for a scalar field,\n\\begin{equation}\\label{c2sae6}\n\\oint f d\\vec{l} = -\\int(\\grad{f} \\vp \\un)dA\n\\end{equation}\nLet $\\vec{F}(\\vec{x}) = \\vec{\\alpha} f(\\vec{x})$, where $\\vec{\\alpha}$ is a constant vector. Therefore, Stokes' theorem for $\\vec{F}$ is\n\\[\n\\oint\\vec{F}\\cdot d\\vec{l} = \\int\\curl{\\vec{F}}\\cdot\\un dA\n\\]\nthat is\n\\[\n\\vec{\\alpha}\\cdot\\oint f(\\vec{x}) d\\vec{l} = \\int \\left(\\grad{f(\\vec{x})} \\vp \\vec{\\alpha}\\right)\\cdot\\un dA,\n\\]\nor,\n\\[\n\\vec{\\alpha}\\cdot\\oint f(\\vec{x}) d\\vec{l} = -\\int \\left(\\vec{\\alpha} \\vp \\grad{f(\\vec{x})}\\right)\\cdot\\un dA,\n\\]\nInterchanging the dot and the cross products on the right hand side,\n\\[\n\\vec{\\alpha}\\cdot\\oint f(\\vec{x}) d\\vec{l} = -\\vec{\\alpha}\\cdot\\int\\left(\\grad{f(\\vec{x})} \\vp \\un\\right)dA\n\\]\nor\n\\[\n\\vec{\\alpha}\\cdot\\left\\{\\oint f(\\vec{x}) d\\vec{l} + \\int\\left(\\grad{f(\\vec{x})} \\vp \\un\\right)dA\\right\\} = 0\n\\]\nSince $\\vec{\\alpha}$ is an arbitrary vector,\n\\[\n\\oint f(\\vec{x}) d\\vec{l} + \\int\\left(\\grad{f(\\vec{x})} \\vp \\un\\right)dA = 0\n\\]\n\n\\section{Multipole expansion}\\label{c2sa4} \nWe will demonstrate the multipole expansion for an electrostatic potential. If $\\rho(\\vec{x})$ is an arbitrary charge distribution then the potential due to it at a \npoint $\\vec{x}$, in gaussian units, is\n\\[\n\\phi(\\vec{x}) = \\int\\frac{\\rho(\\vec{x}^\\op)}{|\\vec{x} - \\vec{x}^\\op|}dV(\\vec{x}^\\op)\n\\]\nIf $\\vec{s} = \\vec{x} - \\vec{x}^\\op$ then the Taylor expansion for $s^{-1}$ is\n\\[\n\\frac{1}{s} = \\frac{1}{r} + x_i^\\op\\frac{\\partial}{\\partial x_i}\\left(\\frac{1}{s}\\right) + \\frac{x_i^\\op x_j^\\op}{2!}\\frac{\\partial^2}{\\partial x_i \\partial x_j}\\left(\\frac{1}{s}\\right)\n+ \\frac{x_i^\\op x_j^\\op x_k^\\op}{3!} \\frac{\\partial^3}{\\partial x_i \\partial x_j \\partial x_k}\\left(\\frac{1}{s}\\right) + \\cdots\n\\]\nTherefore,\n\\[\n\\phi(\\vec{x}) = \\frac{Q^{(0)}}{r} + Q_i^{(1)}\\frac{\\partial}{\\partial x_i}\\left(\\frac{1}{s}\\right) + \n\\frac{Q_{ij}^{(2)}}{2!}\\frac{\\partial^2}{\\partial x_i \\partial x_j}\\left(\\frac{1}{s}\\right) +\n\\frac{Q_{ijk}^{(3)}}{3!}\\frac{\\partial^3}{\\partial x_i \\partial x_j \\partial x_k}\\left(\\frac{1}{s}\\right) + \\cdots\n\\]\nwhere\n\\begin{eqnarray*}\nQ^{(0)} &=& \\int \\rho(\\vec{x}^\\op)dV(\\vec{x}^\\op) \\\\\nQ_i^{(1)} &=& \\int x_i \\rho(\\vec{x}^\\op)dV(\\vec{x}^\\op) \\\\\nQ_{ij}^{(2)} &=& \\int x_i x_j \\rho(\\vec{x}^\\op)dV(\\vec{x}^\\op) \\\\\nQ_{ijk}^{(3)} &=& \\int x_i x_j x_k \\rho(\\vec{x}^\\op)dV(\\vec{x}^\\op) \\\\\n\\end{eqnarray*}\nare the multipoles of charge density. The zeroth order term $Q^{(0)}$ is the total charge, the first order term $Q_i^{(1)}$ is the dipole moment, the second order term $Q_{ij}^{(2)}$ is \nthe quadrupole moment and $Q_{ijk}^{(3)}$ is the octupole moment of the charge distribution. If we write $s^2 = \\sum_{a}(x_a - x_a^\\op)^2$ then we observe that\n\\begin{eqnarray*}\n\\frac{\\partial}{\\partial x_i}\\left(\\frac{1}{s}\\right) &=& -\\frac{x_i - x_i^\\op}{s^3} \\\\\n\\frac{\\partial^2}{\\partial x_i \\partial x_j}\\left(\\frac{1}{s}\\right) &=& 3\\frac{(x_i - x_i^\\op)(x_j - x_j^\\op)}{s^5} -\\frac{\\delta_{ij}}{s^3} \\\\\n\\frac{\\partial^3}{\\partial x_i \\partial x_j \\partial x_k}\\left(\\frac{1}{s}\\right) &=& -15\\frac{(x_i - x_i^\\op)(x_j - x_j^\\op)(x_k - x_k^\\op)}{s^7} + \\\\\n & & \\frac{3}{s^5}\\left[(x_i - x_i^\\op)\\delta_{jk} + (x_j - x_j^\\op)\\delta_{ik} + (x_k - x_k^\\op)\\delta_{ij}\\right]\n\\end{eqnarray*}\nThus,\n\\begin{eqnarray*}\n\\phi(\\vec{x}) &=& \\frac{Q^{(0)}}{r} - \\frac{(x_i - x_i^\\op)Q_i^{(1)}}{s^3} + \\frac{3(x_i - x_i^\\op)(x_j - x_j^\\op)Q_{ij}^{(2)} - Q_{ii}^{(2)}}{s^5} -\\\\\n & & \\frac{15(x_i - x_i^\\op)(x_j - x_j^\\op)(x_k - x_k^\\op)Q_{ijk}^{(3)} + 3(x_i - x_i^\\op)Q_{ijj}^{(3)}}{s^7} + \\\\ \n & & O\\left(\\frac{1}{s^5}\\right),\n\\end{eqnarray*}\nwhere we have used the symmetry of the octupole moment tensor to get\n\\[\n(x_i - x_i^\\op)Q_{ijj}^{(3)} + (x_j - x_j^\\op)Q_{iji}^{(3)} + (x_k - x_k^\\op)Q_{iik}^{(3)} = 3(x_i - x_i^\\op)Q_{ijj}^{(3)}\n\\]\nThe $n$th term of the expansion of $\\phi$ goes as $r^{n}$. We will not get an expression for the field due to an arbitrary charge distribution. Since $\\vec{E} = -\\grad{\\phi}$,\n\\begin{eqnarray*}\nE_a &=& - Q^{(0)}\\pdt{(r^{-1})}{x_a} + Q_i^{(1)}\\frac{\\partial}{\\partial x_a}\\left(\\frac{(x_i - x_i^\\op)}{s^3}\\right) - \\\\\n & & Q_{ij}^{(2)}\\frac{\\partial}{\\partial x_a}\\left(\\frac{3(x_i - x_i^\\op)(x_j - x_j^\\op) - \\delta_{ij}}{s^5}\\right) + \\\\\n & & Q_{ijk}^{(3)}\\frac{\\partial}{\\partial x_a}\\left(\\frac{15(x_i - x_i^\\op)(x_j - x_j^\\op)(x_k - x_k^\\op) + 3(x_i - x_i^\\op)\\delta_{jk}}{s^7}\\right) - \\\\\n & & \\cdots\n\\end{eqnarray*}\nThus, the field due to a monopole goes as $r^{-2}$, that due to a dipole as $r^{-3}$, quadrupole as $r^{-4}$ and so on.\n\n\\section{Solid harmonics}\\label{c2sa5}\nWe consider the solution of Laplace's equation using the method of separation of variables. Let $\\Phi(r, \\varphi, \\theta) = R(r)S(\\varphi, \\theta)$ be the solution of $\\nabla^2\\Phi=0$. \nWriting the Laplacian in spherical polar coordinates,\n\\[\n\\frac{S}{r^2}\\frac{d}{dr}\\left(r^2\\td{R}{r}\\right) + \n\\frac{R}{r^2}\\left[\\frac{1}{\\sin\\theta}\\frac{\\partial}{\\partial\\theta}\\left(\\sin\\theta\\pdt{S}{\\theta}\\right) + \\frac{1}{\\sin^2\\theta}\\frac{\\partial^2S}{\\partial\\varphi^2}\\right] = 0\n\\]\nMultiplying both sides by $r^2/\\Phi$,\n\\[\n\\frac{1}{R}\\frac{d}{dr}\\left(r^2\\td{R}{r}\\right) =\n-\\frac{1}{S}\\left[\\frac{1}{\\sin\\theta}\\frac{\\partial}{\\partial\\theta}\\left(\\sin\\theta\\pdt{S}{\\theta}\\right) + \\frac{1}{\\sin^2\\theta}\\frac{\\partial^2S}{\\partial\\varphi^2}\\right]\n\\]\nSince the left hand side is a function of $r$ alone while the right hand side is a function of $\\varphi$ and $\\theta$, each side is a constant. We write it as $n(n+1)$ in view of the\nfact that the $S$ is a spherical harmonic. Thus, the Laplace's equation splits into\n\\begin{eqnarray*}\n\\frac{1}{R}\\frac{d}{dr}\\left(r^2\\td{R}{r}\\right) &=& n(n+1) \\\\\n\\frac{1}{S}\\left[\\frac{1}{\\sin\\theta}\\frac{\\partial}{\\partial\\theta}\\left(\\sin\\theta\\pdt{S}{\\theta}\\right) + \\frac{1}{\\sin^2\\theta}\\frac{\\partial^2S}{\\partial\\varphi^2}\\right] &=& -n(n+1)\n\\end{eqnarray*}\nThe second equation can be written as\n\\[\n\\frac{1}{\\sin\\theta}\\frac{\\partial}{\\partial\\theta}\\left(\\sin\\theta\\pdt{S_n}{\\theta}\\right) + \\frac{1}{\\sin^2\\theta}\\frac{\\partial^2S_n}{\\partial\\varphi^2} + n(n+1)S_n = 0\n\\]\nwhere we add a subscript $n$ to $S$ following the convention to indicate the eigenvalue. Since $S_n$ is not a function of $r$, we can as well write it as\n\\[\nr^2\\nabla^2S_n + n(n+1)S_n = 0\n\\]\nWe can readily verify that $R(r) = r^n$ is a solution of\n\\[\n\\frac{1}{R}\\frac{d}{dr}\\left(r^2\\td{R}{r}\\right) = n(n+1)\n\\]\nThus, $\\Phi_n(r, \\varphi, \\theta) = r^nS_n(\\varphi, \\theta)$ is a solution of $\\nabla^2\\Phi = 0$. The functions $\\Phi_n$ are called solid harmonics. We will now show that if $\\Phi_n$\nsolves the Laplace's equation then so does $\\Phi_{-n-1}$. To do so, let us find the conditions for $r^m\\Phi_n$ to be a solution of the Laplace's equation, where $n$ is fixed. We\nobserve that\n\\begin{eqnarray*}\n\\nabla^2(r^m\\Phi_n) &=& (m + n)(m + n + 1)r^{m + n - 2}S_n - n(n + 1)r^{m + n - 2}S_n \\\\\n &=& m(m + 2n + 1)r^{m - 2}\\Phi_n,\n\\end{eqnarray*}\nwhere we used the fact that $S_n$ is a spherical harmonic. Clearly, $r^m\\Phi_n$ is a solution of Laplace's equation only if $m = -(2n + 1)$. Thus $r^{-(2n + 1)}\\Phi_n = \nr^{-(2n + 1)}r^nS_n = r^{-n-1}S_n$ is a solution of Laplace's equation.\n\nThe only spherically symmetric solutions which vanish at infinity are the ones with $n = -1$. They are\n\\[\n\\Phi = \\frac{A}{r},\n\\]\nwhere $A$ is a suitably chosen constant. If $\\Phi$ is a solution of Laplace's equation then so are its derivatives. We consider only these solutions in the book.\n\n\\section{Green function of Laplacian}\n\\subsection{Method 1}\\label{c2sa6} \nLet $f(x_1, x_2, \\ldots, x_n) = g(r)$ where $r = \\sqrt{x_1^2 + x_2^2 + \\cdots + x_n^2}$. Therefore,\n\\begin{eqnarray*}\nf_{x_1}    &=& g^\\op(r) r_x \\\\\n\t\t  &=& g^\\op(r)\\frac{x_1}{\\sqrt{x_1^2 + x_2^2 + \\cdots + x_n^2}} \\\\\nf_{x_1x_1} &=& g^\\tp(r)\\frac{x_1^2}{x_1^2 + x_2^2 + \\cdots + x_n^2} + g^\\op(r)\\frac{1}{\\sqrt{x_1^2 + x_2^2 + \\cdots + x_n^2}} - \\\\\n           & & g^\\op(r)\\frac{x_1^2}{(x_1^2 + x_2^2 + \\cdots + x_n^2)^{3/2}} \\\\\nf_{x_1x_1} &=& g^\\tp(r)\\frac{x_1^2}{x_1^2 + x_2^2 + \\cdots + x_n^2} + g^\\op(r)\\frac{x_2^2 + x_3^2 + \\cdots + x_n^2}{(x_1^2 + x_2^2 + \\cdots + x_n^2)^{3/2}} \\\\\n\\end{eqnarray*}\nTherefore,\n\\[\nf_{x_1x_1} + f_{x_2x_2} + \\cdots + f_{x_nx_n} = g^\\tp(r) + (n - 1)\\frac{g^\\op(r)}{\\sqrt{x_1^2 + x_2^2 + \\cdots + x_n^2}} \n\\]\nor,\n\\[\nf_{x_1x_1} + f_{x_2x_2} + \\cdots + f_{x_nx_n} = g^\\tp(r) + (n - 1)\\frac{g^\\op(r)}{r} \n\\]\nIf $f_{x_1x_1} + f_{x_2x_2} + \\cdots + f_{x_nx_n} = 0$ then \n\\[\ng^\\tp(r) = -(n - 1)\\frac{g^\\op(r)}{r} \\Rightarrow \\frac{g^\\tp(r)}{g^\\op(r)} = -(n - 1)\\frac{1}{r}\n\\]\nwhich implies\n\\[\n\\ln g^\\op(r) = -(n - 1)\\ln r + \\ln\\alpha,\n\\]\nwhere $\\alpha$ is a constant of integration. Therefore $g^\\op(r)r^{n - 1} = \\alpha$. We solve this ordinary differential equation for the following three cases\n\\begin{enumerate}\n\\item If $n = 2$, $g(r) = \\alpha\\ln r + \\beta$ and\n\\item If $n \\ne 2$, \n\\[\ng(r) = \\frac{\\alpha}{r^{n - 2}} + \\beta,\n\\]\n\\end{enumerate}\nwhere $\\alpha$ and $\\beta$ are constants of integration. For $n \\ge 2$, the function $g$ is singular at the origin. Therefore, it is also the Green function of Laplacian. If \n$r = |\\vec{x} - \\vec{x}^\\op|$ then\n\\[\nG(\\vec{x}, \\vec{x}^\\op) = \\begin{cases}\n\\alpha\\ln|\\vec{x} - \\vec{x}^\\op| + \\beta & \\text{ if } n = 2 \\\\\n\\alpha|\\vec{x} - \\vec{x}^\\op|^{-(n - 2)} + \\beta & \\text{ if } n \\ne 2\n\\end{cases}\n\\]\n \n\\subsection{Method 2}\\label{c2sa7} \nGreen function of a Laplacian is defined as\n\\[\n\\nabla^2 G(\\vec{x}, \\vec{x}^\\op) = \\begin{cases}\n\\delta(\\vec{x} - \\vec{x}^\\op) & \\text{ on } V \\\\\n0 & \\text{ on } S\n\\end{cases}\n\\]\nwhere $V$ is the volume enclosed by a surface $S$. When Neumann boundary conditions are specified, the second condition is usually $\\grad{G(\\vec{x}, \\vec{x}^\\op)}\\cdot\\un = A^{-1}$, \nwhere $A$ is the area of a \\enquote*{sphere} of unit radius centerd at $\\vec{x}^\\op$. To get the Green function, we will integrate $\\nabla^2 G(\\vec{x}, \\vec{x}^\\op) = \n\\delta(\\vec{x} - \\vec{x}^\\op)$. In each case, the Green function depends only on $|\\vec{x} - \\vec{x}^\\op|$ because of the \\enquote*{spherical} symmetry of the problem.\n\\begin{enumerate}\n\\item In three dimensions,\n\\[\n\\int\\nabla^2 G(\\vec{x}, \\vec{x}^\\op) dV = \\int \\delta(\\vec{x} - \\vec{x}^\\op) dV\n\\]\nor\n\\[\n\\int\\dive{(\\grad{G(\\vec{x}, \\vec{x}^\\op)})}dV = 1\n\\]\nUsing divergence theorem,\n\\[\n\\int \\grad{G(\\vec{x}, \\vec{x}^\\op})\\cdot\\un dS = 1\n\\]\nIf the volume of integration were a sphere of radius $r$, since $G$ is a function of $|\\vec{x} - \\vec{x}^\\op|$ alone, $\\grad{G(\\vec{x}, \\vec{x}^\\op}) = G^\\op(r)\\uvec{r}$. Further, \nsince the unit normal $\\un$ to the sphere is in the radial direction, $\\grad{G(\\vec{x}, \\vec{x}^\\op})\\cdot\\un = G^\\op(r)$. Hence,\n\\begin{equation}\\label{c2sa7e1}\n\\int G^\\op(r) dS = 1\n\\end{equation}\nOn a sphere, $G^\\op(r)$ is constant, Therefore,\n\\[\nG^\\op(r)\\int dS = 1 \\Rightarrow G^\\op 4\\pi r^2 = 1\n\\]\nor\n\\[\nG(r) = -\\frac{1}{4\\pi r} + c,\n\\]\nwhere $c$ is a constant of integration. Since $r = |\\vec{x} - \\vec{x}^\\op|$,\n\\[\nG(|\\vec{x} - \\vec{x}^\\op|) = -\\frac{1}{4\\pi|\\vec{x} - \\vec{x}^\\op|}\n\\]\nif we also choose $c = 0$.\n\n\\item In two dimensions, the treatment up to \\eqref{c2sa7e1} is same as in the case of three dimensions, except that the volume integral is really over a disk and the surface integral is \nover a circle. Therefore,\n\\[\nG^\\op(r)\\int dS = 1 \\Rightarrow G^\\op 2\\pi r = 1\n\\]\nor\n\\[\nG(r) = \\frac{1}{2\\pi}\\ln r + c,\n\\]\nwhere $c$ is a constant of integration. Since $r = |\\vec{x} - \\vec{x}^\\op|$,\n\\[\nG(|\\vec{x} - \\vec{x}^\\op|) = \\frac{1}{2\\pi}\\ln|\\vec{x} - \\vec{x}^\\op|\n\\]\nif we also choose $c = 0$.\n\n\\item For $n \\ge 3$ dimensions, the equation \\eqref{c2sa7e1} evaluates to\n\\[\nG^\\op(r)\\int dS = 1 \\Rightarrow G^\\op \\frac{n \\pi^{n/2} r^{n - 1}}{\\Gamma(1 + n/2)} = 1,\n\\]\nwhere we have used the result that the surface area of a $n$-sphere of radius $r$ is{\\footnote{Equation 18.77 in \\enquote*{Statistical Mechanics} by K. Huang, 2nd edition.}}\n\\[\nS_n(r) = \\frac{n \\pi^{n/2} r^{n - 1}}{\\Gamma(1 + n/2)}\n\\]\nTherefore,\n\\[\nG^\\op(r) = \\Gamma\\left(1 + \\frac{n}{2}\\right)\\frac{1}{n \\pi^{n/2}}\\frac{1}{r^{n-1}}\n\\]\nor\n\\[\nG^\\op(r) = -\\Gamma\\left(1 + \\frac{n}{2}\\right)\\frac{1}{n(n - 2) \\pi^{n/2}}\\frac{1}{r^{n - 2}} + c,\n\\]\nwhere $c$ is a constant of integration. Since $r = |\\vec{x} - \\vec{x}^\\op|$,\n\\begin{equation}\\label{c2sa7e2}\nG(|\\vec{x} - \\vec{x}^\\op|) = -\\Gamma\\left(1 + \\frac{n}{2}\\right)\\frac{1}{n(n - 2) \\pi^{n/2}}\\frac{1}{|\\vec{x} - \\vec{x}^\\op|^{n - 2}}\n\\end{equation}\nif we also choose $c = 0$. If $n = 3$, we get \n\\[\nG(|\\vec{x} - \\vec{x}^\\op|) = -\\frac{1}{4\\pi|\\vec{x} - \\vec{x}^\\op|}\n\\]\n\n\\item Interestingly, the \\eqref{c2sa7e2} is valid even for $n = 1$, when we get\n\\[\n G(|\\vec{x} - \\vec{x}^\\op|) = \\frac{1}{2}|\\vec{x} - \\vec{x}^\\op|\n\\]\n\\end{enumerate}\n\n\\subsection{Method 3}\\label{c2sa8}\nThe definition of Green function is\n\\begin{equation}\\label{c2sa8e1}\n\\nabla^2 G(\\vec{x}, \\vec{x}^\\op) = \\delta^{(n)}(\\vec{x} - \\vec{x}^\\op)\n\\end{equation}\nwhere $n$ could be any dimension. Thus, in general,\n\\[\n\\nabla^2 \\equiv \\sum_{k=1}^n \\frac{\\partial^2}{\\partial x_k^2}\n\\]\nWithout loss of generality, choose $\\vec{x}^\\op = 0$ and take Fourier transform of \\eqref{c2sa8e1} to get\n\\[\nk^2\\tilde{G}(\\vec{k}) = 1\n\\]\nThus, the Fourier transform of Green function of Laplacian of any dimensions, in the momentum space is $1/k^2$. Finding an expression in position space is just a matter of finding an\ninverse Fourier transform suitable for that space. This technique works for all dimensions except $n = 2$. We know that in two dimensions the Green function of a Laplacian is $\\ln r$. \nIt diverges as $r \\rightarrow \\infty$. The theory of Fourier transforms needs the functions to be localized and decaying to zero at infinity. Therefore, the usual techniques of \nintegration do not work in this case. Refer to the \\href{http://math.stackexchange.com/questions/847706/does-the-integral-in-the-formal-2d-fourier-transform-of-the-logarithm-converge}\n{StackExchange} conversation for more details{\\footnote{Dr. Robert E. Hunt of Cambridge University, in a private correspondence, explained this point to me and directed me to the\nStackExchange conversation}}.\n\n\\section{Divergence theorem in a plane}\\label{c2sa9} \nConsider a vector field $\\vec{F}(x, y)$ defined over a closed region $S$ whose boundary is denoted by $\\partial S$. If $ds$ denotes a small displacement along the boundary, the tangent\n$\\ut$ and the normal $\\un$ are defined as\n\\begin{eqnarray*}\n\\ut &=& \\td{x}{s}\\uvec{x} + \\td{y}{s}\\uvec{y} \\\\\n\\un     &=& \\td{y}{s}\\uvec{x} - \\td{x}{s}\\uvec{y}\n\\end{eqnarray*}\nRefer to \\href{http://mathworld.wolfram.com/NormalVector.html}{Mathworld} for more details. The circulation of $\\vec{F} = L\\uvec{x} + M\\uvec{y}$ is defined as\n\\[\n\\oint\\vec{F}\\cdot\\ut ds = \\oint\\left(L\\td{x}{s} + M\\td{y}{s}\\right)ds = \\oint(Ldx + Mdy)\n\\]\nwhile the flux through $\\partial S$ is\n\\[\n\\oint\\vec{F}\\cdot\\un ds = \\oint\\left(L\\td{y}{s} - M\\td{x}{s}\\right)ds = \\oint(Ldy - Mdx)\n\\]\nGreen's theorem in a plane is\n\\[\n\\oint (Ldx + Mdy) = \\iint \\left(\\pdt{M}{x} - \\pdt{L}{y}\\right) dxdy\n\\]\nTherefore,\n\\begin{eqnarray*}\n\\oint\\vec{F}\\cdot\\ut ds &=& \\iint\\left(\\pdt{M}{x} - \\pdt{L}{y}\\right)dxdy \\\\\n\\oint\\vec{F}\\cdot\\un ds     &=& \\iint\\left(\\pdt{L}{x} + \\pdt{M}{y}\\right)dxdy\n\\end{eqnarray*}\nHowever, the circulation is a line integral of the curl while the flux is a \\enquote*{surface} integral of the field. Therefore, the above equations can as well be written as\n\\begin{eqnarray*}\n\\oint\\vec{F}\\cdot\\ut ds &=& \\iint\\left(\\curl{F}\\right)_zdxdy \\\\\n\\oint\\vec{F}\\cdot\\un ds     &=& \\iint(\\dive{\\vec{F}})dxdy\n\\end{eqnarray*}\n\n\\section{Circular harmonics}\\label{c2sa10} \nConsider Laplace's equation in plane polar coordinates for $\\Phi(r, \\theta)$,\n\\[\n\\frac{1}{r}\\frac{\\partial}{\\partial r}\\left(r\\pdt{\\Phi}{r}\\right) + \\frac{1}{r^2}\\pdts{\\Phi}{\\theta} = 0\n\\]\nLet $\\Phi(r, \\theta) = R(r)S(\\theta)$ so that\n\\[\n\\frac{r}{R}\\frac{d}{dr}\\left(r\\td{R}{r}\\right) = -\\frac{1}{S}\\frac{d^2S}{d\\theta^2}\n\\]\nSince the left side depends on $r$ alone while the right hand side depends on $\\theta$, each side is equal to a constant, say $m$. Thus,\n\\[\n-\\frac{1}{S}\\frac{d^2S}{d\\theta^2} = m \\Rightarrow \\frac{d^2S}{d\\theta^2} + mS = 0\n\\]\nSince $S(\\theta) = S(\\theta + 2\\pi)$, we require $m$ to be square of an integer. Let us therefore write $m = n^2$. The $R$ equation is\n\\[\n\\frac{r}{R}\\frac{d}{dr}\\left(r\\td{R}{r}\\right) = m^2\n\\]\nIt is easy to check that if $m^2 \\ne 0$ then $R = r^l$ is a solution while if $m = 0$, $R = \\ln r$ is a solution. Thus, the complete solution of Laplace's equation is\n\\begin{eqnarray*}\n\\Phi(r, \\theta) &=& (a_0 + b_0\\ln r)(c_0 + d_0\\theta) + \\\\\n & & \\sum_{k \\ne 0}\\left(a_k r^k + b_k r^{-k}\\right)\\left(c_ke^{ik\\theta} + d_ke^{-ik\\theta}\\right),\n\\end{eqnarray*}\nwhere $a_k, b_k, c_k, d_k$ are constants. $\\Phi(r, \\theta) = \\Phi(r, \\theta + 2\\pi)$ requires $d_0 = 0$ so that,\n\\[\n\\Phi(r, \\theta) = (a_0 + b_0\\ln r) + \\sum_{k \\ne 0}\\left(a_k r^k + b_k r^{-k}\\right)\\left(c_ke^{ik\\theta} + d_ke^{-ik\\theta}\\right),\n\\]\nIf the solution is required to be \\enquote*{circularly symmetric}, that is independent of polar angle $\\theta$ then we have to choose $a_k, b_k, c_k, d_k = 0$ for all $k \\ne 0$, in\nwhich case,\n\\[\n\\Phi(r, \\theta) = a_0 + b_0\\ln r\n\\]\nSolutions of Laplace's equation in plane polar coordinates are called circular harmonics. In the book considers only those which are \\enquote*{circularly symmetric}.\n\nRecall that if $f(r)$ is a solution of Laplace's equation then so are all derivatives of $f$ with respect to $r$. \n\n\\section{A property of harmonic functions}\\label{c2sa11}\nLet $\\phi_1(\\vec{x})$ and $\\phi_2(\\vec{x})$ be two solution of Laplace's equation. That it, $\\nabla^2\\phi_1 = 0$ and $\\nabla^2\\phi_2 = 0$. Consider\n\\[\n\\dive\\left(\\phi_1\\grad\\phi_2\\right) = \\grad\\phi_1\\cdot\\grad\\phi_2 + \\phi_1\\nabla^2\\phi_2 = \\grad\\phi_1\\cdot\\grad\\phi_2,\n\\]\nbecause $\\nabla^2\\phi_2 = 0$. Similarly,\n\\[\n\\dive\\left(\\phi_2\\grad\\phi_1\\right) = \\grad\\phi_2\\cdot\\grad\\phi_1 + \\phi_2\\nabla^2\\phi_1 = \\grad\\phi_1\\cdot\\grad\\phi_2,\n\\]\nbecause $\\nabla^2\\phi_1 = 0$. Therefore, $\\dive\\left(\\phi_1\\grad\\phi_2\\right) = \\dive\\left(\\phi_2\\grad\\phi_1\\right)$. Taking a volume integral of the equation,\n\\[\n\\int\\dive\\left(\\phi_1\\grad\\phi_2\\right)dV = \\int\\dive\\left(\\phi_2\\grad\\phi_1\\right)dV,\n\\]\nafter using divergence theorem,\n\\begin{equation}\\label{c2sa11e1}\n\\int\\phi_1\\grad\\phi_2\\cdot\\un dA = \\int\\phi_2\\grad\\phi_1\\cdot\\un dA\n\\end{equation}\n\n\\section{Proof of \\texorpdfstring{$\\int n_i n_j d\\Omega = (4\\pi/3)\\delta_{ij}$}{}}\nConsider the integral,\n\\[\nI_{ij} = \\int n_i n_j d\\Omega\n\\]\nwhere $n_i, n_j$ are unit normals and $d\\Omega$ denotes the solid angle. We will evaluate this integral for the following sub-cases, which are all the ones that are possible.\n\\begin{itemize}\n\\item $i = j = x$. In this case, putting $n_i = n_j = \\sin\\theta\\cos\\varphi$,\n\\[\nI_{xx} = \\int_0^\\pi\\int_0^{2\\pi} \\sin^2\\theta \\cos^2\\varphi \\sin\\theta d\\theta d\\varphi\n\\]\nWe observe that\n\\[\n\\int_0^{2\\pi} \\cos^2\\varphi d\\varphi = \\int_0^{2\\pi}\\left(\\frac{1 + \\cos(2\\varphi)}{2}\\right)d\\varphi = \\pi\n\\]\nand\n\\begin{eqnarray*}\n\\int_0^{\\pi}\\sin^3\\theta d\\theta &=& \\int_0^\\pi(1 - \\cos^2\\theta)\\sin\\theta d\\theta \\\\\n &=& -\\int_{1}^{-1} (1 - u^2)(-du) \\\\\n &=& \\int_{-1}^1(1 - u^2)du \\\\\n &=& 2 - \\frac{2}{3} = \\frac{4}{3}\n\\end{eqnarray*}\nTherefore,\n\\[\nI_{xx} = \\frac{4\\pi}{3}\n\\]\n\n\\item $i = j = y$. In this case, put $n_i = n_j = \\sin\\theta\\sin\\varphi$, so that\n\\[\nI_{yy} = \\int_0^\\pi\\int_0^{2\\pi} \\sin^2\\theta \\sin^2\\varphi \\sin\\theta d\\theta d\\varphi\n\\]\nSince\n\\[\n\\int_0^{2\\pi} \\sin^2\\varphi d\\varphi = \\int_0^{2\\pi}\\left(\\frac{1 - \\cos(2\\varphi)}{2}\\right)d\\varphi = \\pi,\n\\]\nwe get\n\\[\nI_{yy} = \\frac{4\\pi}{3}\n\\]\n\n\\item $i = j = z$. In this case, put $n_i = n_j = \\cos\\theta$, so that\n\\[\nI_{zz} = \\int_0^\\pi\\int_0^{2\\pi} \\cos^2\\theta \\sin\\theta d\\theta d\\varphi = 2\\pi\\int_{-1}^1 u^2 (-du) = \\frac{4\\pi}{3}\n\\]\n\n\\item $i = x, j = y$. In this case, put $n_i = \\sin\\theta\\cos\\varphi$ and $n_j = \\sin\\theta\\sin\\varphi$, so that\n\\[\nI_{xy} = \\int_0^{\\pi}\\sin^3\\theta d\\theta \\int_0^{2\\pi} \\sin\\varphi\\cos\\varphi d\\varphi\n\\]\nThe $\\varphi$ integral is zero making $I_{xy} = 0$.\n\n\\item $i = y, j = z$. In this case, put $n_i = \\sin\\theta\\sin\\varphi$ and $n_j = \\cos\\theta$, so that\n\\[\nI_{yz} = \\int_0^{\\pi}\\sin^2\\theta\\cos\\theta d\\theta \\int_0^{2\\pi} \\sin\\varphi d\\varphi\n\\]\nThe $\\varphi$ integral is zero making $I_{yz} = 0$.\n\n\\item $i = z, j = x$. In this case, put $n_i = \\cos\\theta\\sin\\varphi$ and $n_j = \\sin\\theta\\cos\\phi$, so that\n\\[\nI_{zx} = \\int_0^{\\pi}\\sin^2\\theta\\cos\\theta d\\theta \\int_0^{2\\pi} \\cos\\varphi d\\varphi\n\\]\nThe $\\varphi$ integral is zero making $I_{zx} = 0$.\nThe six cases above can be summarized as\n\\begin{equation}\\label{c3sae1}\n\\int n_i n_j d\\Omega = \\frac{4\\pi}{3}\\delta_{ij}\n\\end{equation}\n\\end{itemize}\n\n\\section{Proof of \\texorpdfstring{$\\int n_i n_j n_k n_l d\\Omega = (4\\pi/15)(\\delta_{ij}\\delta_{kl}+\\delta_{ik}\\delta_{jl}+\\delta_{il}\\delta_{jk})$}{}}\nWe will consider the following cases,\n\\begin{itemize}\n\\item All indices are the same. In this case, the integral is one of $x^4$, $y^4$ or $z^4$, where $x = \\sin\\theta\\cos\\varphi$, $y = \\sin\\theta\\sin\\varphi$ and $z = \\cos\\theta$.\nWe first consider,\n\\begin{eqnarray*}\nI_{xxxx} &=& \\int_0^\\pi \\int_0^{2\\pi} \\sin^4\\theta \\cos^4\\varphi \\sin\\theta d\\theta d\\varphi \\\\\n &=& \\int_0^\\pi\\sin^5\\theta d\\theta \\int_0^{2\\pi}\\cos^4\\varphi d\\varphi\n\\end{eqnarray*}\nNow,\n\\begin{eqnarray*}\n\\int_0^\\pi\\sin^5\\theta d\\theta &=& \\int_0^\\pi\\sin^4\\theta \\sin\\theta d\\theta \\\\\n &=& \\int_0^\\pi(1 - \\cos^2\\theta)^5 \\sin\\theta d\\theta \\\\\n &=& -\\int_1^{-1}(1 - 2u^2 + u^4)du \\\\\n &=& \\frac{16}{15}\n\\end{eqnarray*}\nand\n\\begin{eqnarray*}\n\\int_0^{2\\pi}\\cos^4\\varphi d\\varphi &=& \\int_0^{2\\pi}\\left(\\frac{3}{8} + \\frac{\\cos 2\\varphi}{2} + \\frac{\\cos 4\\varphi}{8}\\right)d\\varphi \\\\\n &=& \\frac{3\\pi}{4}\n\\end{eqnarray*}\nTherefore,\n\\[\nI_{xxxx} = \\frac{4\\pi}{5}\n\\]\nNow consider,\n\\begin{eqnarray*}\nI_{yyyy} &=& \\int_0^\\pi \\int_0^{2\\pi} \\sin^4\\theta \\sin^4\\varphi \\sin\\theta d\\theta d\\varphi \\\\\n &=& \\int_0^\\pi\\sin^5\\theta d\\theta \\int_0^{2\\pi}\\sin^4\\varphi d\\varphi\n\\end{eqnarray*}\nWe evaluate\n\\begin{eqnarray*}\n\\int_0^{2\\pi}\\sin^4\\varphi d\\varphi &=& \\int_0^{2\\pi}\\left(\\frac{3}{8} - \\frac{\\cos 2\\varphi}{2} + \\frac{\\cos 4\\varphi}{8}\\right)d\\varphi \\\\\n &=& \\frac{3\\pi}{4}\n\\end{eqnarray*}\nTherefore,\n\\[\nI_{yyyy} = \\frac{4\\pi}{5}\n\\]\nFinally, consider\n\\begin{eqnarray*}\nI_{zzzz} &=& \\int_0^\\pi \\int_0^{2\\pi} \\cos^4\\theta \\sin\\theta d\\theta d\\varphi \\\\\n &=& \\int_0^\\pi \\cos^4\\theta \\sin\\theta \\int_0^{2\\pi}d\\varphi \\\\\n &=& 2\\pi\\int_1^{-1}u^4(-du) \\\\\n &=& \\frac{4\\pi}{5}\n\\end{eqnarray*}\nThus, this point covers $3$ cases.\n\n\\item Three indices are same, one is different. This case includes integrands of the form $xyyy, xzzz, yzzz, yxxx, zyyy, zxxx$. We evaluate each on of them.\n\\begin{eqnarray*}\nI_{xyyy} &=& \\int_0^\\pi\\sin^5\\theta d\\theta \\int_0^{2\\pi}\\sin^3\\varphi\\cos\\varphi d\\varphi \\\\\n &=& \\frac{16}{15} \\times 0 \\\\\n &=& 0 \\\\\nI_{xzzz} &=& \\int_0^\\pi\\cos^3\\theta\\sin^2\\theta d\\theta \\int_0^{2\\pi}\\cos\\varphi d\\varphi \\\\\n &=& \\int_0^\\pi\\cos^3\\theta\\sin^2\\theta d\\theta \\times 0 \\\\\n &=& 0 \\\\\nI_{yzzz} &=& \\int_0^\\pi\\cos^3\\theta\\sin^2\\theta d\\theta \\int_0^{2\\pi}\\sin\\varphi d\\varphi \\\\\n &=& \\int_0^\\pi\\cos^3\\theta\\sin^2\\theta d\\theta \\times 0 \\\\\n &=& 0 \\\\\nI_{yxxx} &=& \\int_0^\\pi\\sin^5\\theta d\\theta \\int_0^{2\\pi}\\sin\\varphi\\cos^3\\varphi d\\varphi \\\\\n &=& \\frac{16}{15} \\times 0 \\\\\n &=& 0 \\\\\nI_{zxxx} &=& \\int_0^\\pi\\sin^3\\theta \\cos\\theta d\\theta \\int_0^{2\\pi}\\sin^3\\varphi d\\varphi \\\\\n &=& 0 \\times \\int_0^{2\\pi}\\sin^3\\varphi d\\varphi \\\\\n &=& 0\\\\\nI_{zyyy} &=& \\int_0^\\pi\\sin^3\\theta \\cos\\theta d\\theta \\int_0^{2\\pi}\\cos^3\\varphi d\\varphi \\\\\n &=& 0 \\times \\int_0^{2\\pi}\\cos^3\\varphi d\\varphi \\\\\n &=& 0\n\\end{eqnarray*}\nNote that \n\\[\nI_{xyyy} = I_{yxyy} = I_{yyxy} = I_{yyyx} = 0\n\\]\nand similarly for other cases. Thus, this point covers $6 \\times 4 = 24$ cases.\n\n\\item Two of them of one kind and two of the other. We therefore, consider the cases\n\\begin{eqnarray*}\nI_{xxyy} &=& \\int_0^\\pi\\sin^5\\theta d\\theta \\int_0^{2\\pi}\\sin^2\\varphi\\cos^2\\varphi d\\varphi \\\\\n &=& \\frac{16}{15}\\int_0^{2\\pi}\\frac{\\cos^2(2\\varphi)}{4}d\\varphi \\\\\n &=& \\frac{16}{15}\\int_0^{2\\pi}\\frac{1 + \\cos(4\\varphi)}{8}d\\varphi \\\\\n &=& \\frac{16}{15}\\times\\frac{\\pi}{4} \\\\\n &=& \\frac{4\\pi}{15} \\\\\nI_{xxzz} &=& \\int_0^\\pi\\sin^3\\theta\\cos^2\\theta d\\theta \\int_0^{2\\pi}\\cos^2\\varphi d\\varphi \\\\\n &=& \\left(\\int_0^\\pi\\sin^3\\theta d\\theta - \\int_0^\\pi\\sin^5\\theta d\\theta\\right)\\int_0^{2\\pi}\\frac{1 + \\cos(2\\varphi)}{2}d\\varphi \\\\\n &=& \\left(\\frac{4}{3} - \\frac{16}{15}\\right)\\pi \\\\\n &=& \\frac{4\\pi}{15} \\\\\nI_{yyzz} &=& \\int_0^\\pi\\sin^3\\theta\\cos^2\\theta d\\theta \\int_0^{2\\pi}\\sin^2\\varphi d\\varphi \\\\\n &=& \\left(\\int_0^\\pi\\sin^3\\theta d\\theta - \\int_0^\\pi\\sin^5\\theta d\\theta\\right)\\int_0^{2\\pi}\\frac{1 - \\cos(2\\varphi)}{2}d\\varphi \\\\\n &=& \\left(\\frac{4}{3} - \\frac{16}{15}\\right)\\pi \\\\\n &=& \\frac{4\\pi}{15} \\\\\n\\end{eqnarray*}\nNote that\n\\[\nI_{xxyy} = I_{xyyx} = I_{yxyx} = I_{xyxy} = I_{yxxy} = I_{yyxx} = \\frac{4\\pi}{15}\n\\]\nand similarly for other cases. Thus, this point covers $3 \\times 6 = 18$ cases.\n\n\\item Two of them of one kind and the remaining of two different kinds. We therefore, consider the cases\n\\begin{eqnarray*}\nI_{xxyz} &=& \\int_0^\\pi\\sin^4\\theta \\cos\\theta d\\theta \\int_0^{2\\pi}\\cos^2\\varphi \\sin\\varphi d\\varphi \\\\\n &=& 0 \\times 0 \\\\\n &=& 0 \\\\\nI_{yyxz} &=& \\int_0^\\pi\\sin^4\\theta \\cos\\theta d\\theta \\int_0^{2\\pi}\\cos\\varphi \\sin^2\\varphi d\\varphi \\\\\n &=& 0 \\times 0 \\\\\n &=& 0 \\\\\nI_{zzxy} &=& \\int_0^\\pi\\sin^2\\theta \\cos^3\\theta d\\theta \\int_0^{2\\pi}\\cos\\varphi\\sin\\varphi d\\varphi \\\\\n &=& \\int_0^\\pi\\sin^2\\theta \\cos^3\\theta d\\theta \\times 0 \\\\\n &=& 0\n\\end{eqnarray*}\nNote that\n\\[\nI_{xxyz} = I_{xyzx} = I_{xyxz} = I_{xzyx} = I_{xzxy} = I_{xxzy} = I_{yzxx} = I_{yxxz} = \n\\]\n\\[\nI_{zxxy} = I_{zxyx} = I_{zyxx} = I_{yxzx}\n\\]\nand similarly for the other cases. Thus, this point covers $3 \\times 12 = 36$ cases.\n\\end{itemize}\nThe four points cover $3 + 24 + 18 + 36 = 81$ cases, which are all the cases possible. We can summarize all of them in the equation,\n\\begin{equation}\\label{c3sae2}\n\\int n_i n_j n_k n_l d\\Omega = \\frac{4\\pi}{15}(\\delta_{ij}\\delta_{kl}+\\delta_{ik}\\delta_{jl}+\\delta_{il}\\delta_{jk})\n\\end{equation}\n\n\\section{Isotropic tensors}\\label{mr12}\nWe will examine the nature of isotropic tensors of orders $0, 1, 2, 3$ and $4$. A tensor is isotropic if it is invariant under a rotation of axes. The treatment in this section follows\nthat in H. Jeffrey's \\enquote*{Cartesian Tensors}\\cite{jeffreys1961cartesian}.\n\n\\begin{itemize}\n\\item A tensor of zero order is a scalar and it is invariant under a rotation of coordinate axes. \n\n\\item We will show that there are no isotropic tensors of order $1$. A rotation of coordinate axes by and angle $\\theta$ about the $z$ axis is represented by a the orthogonal matrix,\n\\[\n\\begin{pmatrix}\n\\cos\\theta & \\sin\\theta & 0 \\\\\n-\\sin\\theta & \\cos\\theta & 0 \\\\\n0 & 0 & 1\n\\end{pmatrix}\n\\]\nFor small angles of rotation, it can be approximated as\n\\[\n\\begin{pmatrix}\n1 & \\theta & 0 \\\\\n-\\theta & 1 & 0 \\\\\n0 & 0 & 1\n\\end{pmatrix}\n\\]\nand decomposed as $\\delta_{ij} + c_{ij}$, where the anti-symmetric matrix $\\{c_{ij}\\}$ is\n\\[\n\\begin{pmatrix}\n0 & \\theta & 0 \\\\\n-\\theta & 0 & 0 \\\\\n0 & 0 & 0\n\\end{pmatrix}\n\\]\nWe have thus shown that any small rotation can be represented by $\\delta_{ij} + c_{ij}$, where $\\{c_{ij}\\}$ is an anti-symmetric matrix. A vector $u_i$ under a small rotation is\ntransformed to\n\\[\nu_j^\\op = (\\delta_{ij} + c_{ij})u_i\n\\]\nIt will remain unvariant under the rotation only if $c_{ij}u_i = 0$. Writing in full,\n\\begin{eqnarray*}\n 0.u_1 + c_{12}u_2 + c_{13}u_3 &=& 0 \\\\\n-c_{12}u_1 + 0.u_2 + c_{23}u_3 &=& 0 \\\\\n-c_{13}u_1 - c_{23}u_2 + 0.u_3 &=& 0\n\\end{eqnarray*}\nSince\n\\[\n\\begin{vmatrix}\n 0 & c_{12} & c_{13} \\\\\n-c_{12} & 0 & c_{23} \\\\\n-c_{13} & -c_{23} & 0\n\\end{vmatrix} = 0\n\\]\nthe only solution to $c_{ij}u_i = 0$ is $u_i = 0$. Thus, the only isotropic vector is the null vector.\n\n\\item Let $u_{ij}$ be a second order tensor. Then $u_{kl}^\\op = (\\delta_{ik} - c_{ik})u_{ij}(\\delta_{jl} - c_{jl})$. Up to first order in $c_{ij}$,\n\\[\nu_{kl}^\\op = u_{kl} - u_{kj}c_{jl} - u_{il}c_{ik}\n\\]\nThe tensor, $u_{ij}$ will be isotropic only if $u_{kj}c_{jl} + u_{il}c_{ik} = 0$. If $k \\ne l$, choose $k = 1$ and $l = 2$ so that $u_{1j}c_{j2} + u_{i2}c_{i1} = 0$ or\n\\[\nu_{11}c_{12} + u_{12}c_{22} + u_{12}c_{32} + u_{12}c_{11} + u_{22}c_{21} + u_{32}c_{31} = 0\n\\]\nUsing symmetry properties of $\\{c_{ij}\\}$,\n\\[\nu_{11}c_{12} - u_{12}c_{23} - u_{22}c_{12} - u_{32}c_{13} = 0\n\\]\nor\n\\[\n(u_{11} - u_{22})c_{12} - u_{12}c_{23} - u_{32}c_{13} = 0\n\\]\nThis can be true, in general, only if $u_{11} = u_{22}$ and $u_{12} = u_{32} = 0$. Similarly, by choosing $k = 1$ and $l = 3$, we get $u_{11} = u_{33}$ and $u_{12} = u_{23} = 0$. \nFurther, choosing $k = 2$ and $l = 3$ gives $u_{22} = u_{33}$ and $u_{21} = u_{13} = 0$.\n\nIf we choose $k = l = 1$, $u_{1j}c_{j1} + u_{i1}c_{i1} = 0$ or\n\\[\nu_{11}c_{11} + u_{12}c_{21} + u_{13}c_{31} + u_{11}c_{11} + u_{21}c_{21} + u_{31}c_{31} = 0\n\\]\nUsing symmetry properties of $\\{c_{ij}\\}$,\n\\[\n(u_{12} + u_{21})c_{21} + (u_{13} + u_{31})c_{31} = 0\n\\]\nwhich can be true, in general, only if $u_{12} = -u_{21}$ and $u_{13} = -u_{31}$. But we have already shown that $u_{12} = 0$ and $u_{13} = 0$. Thus, $u_{21}$ and $u_{31}$ also vanish.\nChoosing $k = l = 3$ we can show that $u_{23} + u_{32} = 0$, which since $u_{23} = 0$ implies vanishing of both. We have thus shown that the only isotropic tensor is a multiple of the\nKronecker delta $\\delta_{ij}$.\n\n\\item Let $u_{ijk}$ be a third order tensor. Then\n\\[\nu_{lmn}^\\op = (\\delta_{il} - c_{il})(\\delta_{jm} - c_{jm})(\\delta_{kn} - c_{kn})u_{ijk}\n\\]\nUp to first order in $c_{ij}$,\n\\[\nu_{lmn}^\\op = u_{lmn} - \\delta_{il}\\delta_{jm}c_{kn}u_{ijk} - \\delta_{il}\\delta_{kn}c_{jm}u_{ijk} - \\delta_{jm}\\delta_{kn}c_{il}u_{ijk},\n\\]\nor\n\\[\nu_{lmn}^\\op = u_{lmn} - c_{kn}u_{lmk} - c_{jm}u_{ljn} - c_{il}u_{imn}\n\\]\nThe tensor $u_{ijk}$ will be isotropic only if $u_{lmn}^\\op = u_{lmn}$ or, if\n\\[\nc_{kn}u_{lmk} + c_{jm}u_{ljn} + c_{il}u_{imn} = 0\n\\]\nIf $l = m = 1$, the above equation becomes $c_{kn}u_{11k} + c_{j1}u_{1jn} + c_{i1}u_{i1n} = 0$. Summing it over all indices, except $n$, we get\n\\begin{eqnarray*}\nc_{1n}u_{111} + c_{2n}u_{112} + c_{3n}u_{113} + c_{11}u_{11n} + c_{21}u_{12n}  + & & \\\\\nc_{31}u_{13n} + c_{11}u_{11n} + c_{21}u_{21n} + c_{31}u_{31n} &=& 0\n\\end{eqnarray*}\nUsing symmetry properties of $\\{c_{ij}\\}$,\n\\[\nc_{1n}u_{111} + c_{2n}u_{112} + c_{3n}u_{113} + c_{21}(u_{12n} + u_{21n}) + c_{31}(u_{13n} + u_{31n})= 0\n\\]\nIn the particular case of $n = 2$, we get\n\\[\nc_{12}(u_{111} - u_{122} - u_{212}) + c_{32}u_{113} + c_{31}(u_{132} + u_{312}) = 0\n\\]\nThis can be true, in general, only of\n\\begin{eqnarray*}\nu_{122} + u_{212} &=& u_{111} \\\\\nu_{132} + u_{312} &=& 0 \\\\\nu_{113} &=& 0\n\\end{eqnarray*}\nFrom the last of the above three equations, $u_{ijk} = 0$ if any two of the three indices are same. This fact, coupled with the first of the three equations tells that $u_{ijk} = 0$\nif all indices are equal. Finally, the second of the above equations tells that $u_{ijk} = -u_{jik}$. Thus, the tensor entry for $(i, j, k)$ changes sign under an odd permutation of\nindices. Thus, the only isotropic tensor of third order is a scalar multiple of Levi-Civita tensor $\\epsilon_{ijk}$.\n\n\\item Let $u_{ijkl}$ be a fourth order tensor and let\n\\[\nu_{pqrs}^\\op = (\\delta_{ip} - c_{ip})(\\delta_{jq} - c_{jq})(\\delta_{kr} - c_{kr})(\\delta_{ls} - c_{ls})u_{ijkl}\n\\]\nThen, up to first order in $c_{ij}$,\n\\begin{eqnarray*}\nu_{pqrs}^\\op &=& \\delta_{ip}\\delta_{jq}\\delta_{kr}\\delta_{ls}u_{ijkl} - c_{ip}\\delta_{jq}\\delta_{kr}\\delta_{ls}u_{ijkl} \\\\\n & & - \\delta_{ip}c_{jq}\\delta_{kr}\\delta_{ls}u_{ijkl} - \\delta_{ip}\\delta_{jq}c_{kr}\\delta_{ls}u_{ijkl} -\\delta_{ip}\\delta_{jq}\\delta_{kr}c_{ls}u_{ijkl} \\\\\n &=& u_{pqrs} - c_{ip}u_{iqrs} - c_{jq}u_{pjrs} - c_{kr}u_{pqks} - c_{ls}u_{pqrl}\n\\end{eqnarray*}\nThe tensor $u_{ijkl}$ will be isotropic only if\n\\begin{equation}\\label{mr12e1}\nc_{ip}u_{iqrs} + c_{jq}u_{pjrs} + c_{kr}u_{pqks} + c_{ls}u_{pqrl} = 0\n\\end{equation}\nThere are three possible values for the four indices $i, j, k, l$. They give rise to four possibilities:\n\\begin{enumerate}\n\\item Two indices are equal and the other two are unequal. Choose $p = q = 1$, $r = 2$ and $s = 3$ so that \\eqref{mr12e1} becomes\n\\[\nc_{i1}u_{i123} + c_{j1}u_{1j23} + c_{k2}u_{11k3} + c_{l3}u_{112l} = 0\n\\]\nwhich is same as\n\\begin{eqnarray*}\nc_{11}u_{1123} + c_{21}u_{2123} + c_{31}u_{3123} + c_{11}u_{1123} &+& = 0 \\\\ \nc_{21}u_{1223} + c_{31}u_{1323} + c_{12}u_{1113} + c_{22}u_{1123} &+& \\\\\nc_{32}u_{1133} + c_{13}u_{1121} + c_{23}u_{1122} + c_{33}u_{1123} & &\n\\end{eqnarray*}\nUsing symmetry properties of $\\{c_{ij}\\}$,\n\\begin{eqnarray*}\nc_{12}(u_{1113} - u_{2123} - u_{1223}) + c_{13}(u_{1121} - u_{3123} - u_{1323}) + &=& 0 \\\\\nc_{23}(u_{1122} - u_{1133}) & &\n\\end{eqnarray*}\nThis equation will be valid for an arbitrary $c_{ij}$ only if\n\\begin{eqnarray}\nu_{1113} - u_{2123} - u_{1223} &=& 0 \\label{mr12e2} \\\\\nu_{1121} - u_{3123} - u_{1323} &=& 0 \\label{mr12e3} \\\\\nu_{1122} - u_{1133} &=& 0 \\label{mr12e4}\n\\end{eqnarray}\nThe last of the above equations gives $u_{1122} = u_{1133}$. Choosing $p = r = 1$, $q = 2$ and $s = 3$ will give $u_{1212} = u_{1313}$. Other combinations will similar identities. In\ngeneral,\n\\begin{equation}\\label{mr12e5}\nu_{1122} = u_{1133} = u_{2211} = u_{2233} = u_{3311} = u_{3322}\n\\end{equation}\n\\begin{equation}\\label{mr12e6}\nu_{1212} = u_{1313} = u_{2121} = u_{2323} = u_{3131} = u_{3232}\n\\end{equation}\n\\begin{equation}\\label{mr12e7}\nu_{1221} = u_{1331} = u_{2112} = u_{2332} = u_{3113} = u_{3223}\n\\end{equation}\nThus, all terms of $u_{ijkl}$ where two indices are of one kind and the remaining two are of the other kind are equal.\n\n\\item Three indices are equal and the remaining one is different from them. Choose $p = q = r = 1$ and $s = 2$ so that \\eqref{mr12e1} becomes\n\\[\nc_{i1}u_{i112} + c_{j1}u_{1j12} + c_{k1}u_{11k2} + c_{l2}u_{111l} = 0\n\\]\nwhich is same as\n\\begin{eqnarray*}\nc_{11}u_{1112} + c_{21}u_{2112} + c_{31}u_{3112} + c_{11}u_{1112} &+& = 0 \\\\\nc_{21}u_{1212} + c_{31}u_{1312} + c_{11}u_{1112} + c_{21}u_{1122} &+& \\\\\nc_{31}u_{1132} + c_{12}u_{1111} + c_{22}u_{1112} + c_{32}u_{1113} & & \n\\end{eqnarray*}\nUsing symmetry properties of $\\{c_{ij}\\}$,\n\\begin{eqnarray*}\nc_{12}(u_{1111} - u_{2112} - u_{1212} - u_{1122}) - &=& 0 \\\\\nc_{13}(u_{3112} + u_{1312} + u_{1132}) - c_{23}u_{1113} & &\n\\end{eqnarray*}\nThis equation can be true for arbitrary $c_{ij}$ only if\n\\begin{eqnarray}\nu_{1111} &=& u_{2112} + u_{1212} + u_{1122} \\label{mr12e8} \\\\\n0 &=& u_{3112} + u_{1312} + u_{1132} \\label{mr12e9} \\\\\n0 &=& u_{1113} \\label{mr12e10}\n\\end{eqnarray}\nThe last of the above equations tells that all terms of $u_{ijkl}$ where three indices are same and one differs from the rest are zero. Using this fact in \\eqref{mr12e2} and \n\\eqref{mr12e3}, we get\n\\begin{eqnarray}\nu_{2123} + u_{1223} &=& 0 \\label{mr12e11} \\\\\nu_{3123} + u_{1323} &=& 0 \\label{mr12e12}\n\\end{eqnarray}\n\\eqref{mr12e11} under the transformation $1 \\mapsto 3, 2\\mapsto 1, 3 \\mapsto 2$ becomes\n\\[\nu_{1312} + u_{3112} = 0,\n\\]\nwhich put with \\eqref{mr12e9} gives $u_{3112} = 0$. By symmetry, all components of $u_{ijkl}$ whose two indices are same and the rest two are different are zero. Further, equation \n\\eqref{mr12e8} tells that all components of $u_{ijkl}$, all whose indices are equal, are written as sums of components two of whose indices are of one value and the rest are of other\nvalue.\n\\end{enumerate}\nTo summarize:\n\\begin{itemize}\n\\item Components of $u_{ijkl}$ where three indices are same and one differs from the rest are zero.\n\\item Components of $u_{ijkl}$ whose two indices are same and the rest two are different are zero.\n\\item Components of $u_{ijkl}$, all whose indices are equal, are written as sums of components, two of whose indices are of one value and the rest are of other value.\n\\item Components of $u_{ijkl}$, two of whose values are equal and rest are of other value satisfy equations \\eqref{mr12e5}, \\eqref{mr12e6} and \\eqref{mr12e7}.\n\\end{itemize}\nLet\n\\[\nu_{1122} = u_{1133} = u_{2211} = u_{2233} = u_{3311} = u_{3322} = \\gamma \n\\]\n\\[\nu_{1212} = u_{1313} = u_{2121} = u_{2323} = u_{3131} = u_{3232} = a\n\\]\n\\[\nu_{1221} = u_{1331} = u_{2112} = u_{2332} = u_{3113} = u_{3223} = b, \n\\]\nwhere $\\gamma, a, b$ are scalars. For sake of convenience, we can introduce two new scalars\n\\begin{eqnarray*}\n\\alpha &=& \\frac{a + b}{2} \\\\\n\\beta &=& \\frac{a - b}{2}\n\\end{eqnarray*}\nso that\n\\begin{equation}\\label{mr12e13}\nu_{1122} = u_{1133} = u_{2211} = u_{2233} = u_{3311} = u_{3322} =  \\gamma\n\\end{equation}\n\\begin{equation}\\label{mr12e14}\nu_{1212} = u_{1313} = u_{2121} = u_{2323} = u_{3131} = u_{3232} = \\alpha + \\beta\n\\end{equation}\n\\begin{equation}\\label{mr12e15}\nu_{1221} = u_{1331} = u_{2112} = u_{2332} = u_{3113} = u_{3223} = \\alpha - \\beta \n\\end{equation}\nFrom \\eqref{mr12e8},\n\\[\nu_{1111} = (\\alpha - \\beta) + (\\alpha + \\beta) + \\gamma = \\gamma + 2\\alpha\n\\]\nBy symmetry, we conclude that\n\\begin{equation}\\label{mr12e16}\nu_{1111} = u_{2222} = u_{3333} = \\gamma + 2\\alpha\n\\end{equation}\n\nFrom \\eqref{mr12e14} and \\eqref{mr12e15}, we observe that $u_{1212} = \\gamma + \\beta$ and $u_{1221} = \\gamma - \\beta$ so that\n\\begin{eqnarray*}\nu_{1212} + u_{1221} &=& 2\\alpha \\\\\nu_{1212} - u_{1221} &=& 2\\beta\n\\end{eqnarray*}\nThus, there are two tensors, $u_{ijij} + u_{ijji}$ contributing $2\\alpha$ and $u_{ijij} - u_{ijji}$ contributing $2\\beta$. Equivalently, we can say that the tensor $w_{ijkl}$ is such that\n$w_{ijij}$ and $w_{ijji}$ each contribute $\\alpha$ and the other choices of indices contribute zero, while the tensor $v_{ijkl}$ is such that $v_{ijij}$ contributes $\\beta$, $v_{ijji}$ \ncontributes $-\\beta$  and the other choices of indices contribute zero.\n\nEquations \\eqref{mr12e13}, \\eqref{mr12e14} and \\eqref{mr12e15} suggest that there are three independent isotropic tensors described as\n\\begin{enumerate}\n\\item $u_{ijkl} = 1$ if $i=j$ and $k=l$ and zero other otherwise. It can be represented as $\\gamma\\delta_{ij}\\delta_{kl}$.\n\\item $u_{ijkl} = 1$ if $i=k$ and $j=l$ or $i=l$ and $j=k$ and $i \\ne j$. $u_{ijkl} = 0$ for all other choices of indices. Further, if all indices are same $u_{ijkl} = 2$. It can be \nrepresented as $\\alpha(\\delta_{ik}\\delta_{jl} + \\delta_{il}\\delta{jk})$.\n\\item $u_{ijkl} = 1$ if $i=k$ and $j=l$, $u_{ijkl} = -1$ if $i=l$ and $j=k$ and $u_{ijkl} = 0$ for all other choices of indices. It can be represented as $\\beta(\\delta_{ik}\\delta_{jl} - \n\\delta_{il}\\delta{jk})$.\n\\end{enumerate}\nTherefore, a general isotropic tensor of 4th order is expressed as\n\\begin{equation}\\label{mr12e17}\nu_{ijkl} = \\gamma\\delta_{ij}\\delta_{kl} + \\alpha(\\delta_{ik}\\delta_{jl} + \\delta_{il}\\delta_{jk}) + \\beta(\\delta_{ik}\\delta_{jl} - \\delta_{il}\\delta_{jk})\n\\end{equation}\nAn equivalent form is\n\\[\nu_{ijkl} = \\mu^\\tp\\delta_{ij}\\delta_{kl} + \\mu\\delta_{ik}\\delta_{jl} + \\mu^\\op\\delta_{il}\\delta_{jk}\n\\]\nor,\n\\begin{equation}\\label{mr12e18}\nu_{ijkl} = \\mu\\delta_{ik}\\delta_{jl} + \\mu^\\op\\delta_{il}\\delta_{jk} + \\mu^\\tp\\delta_{ij}\\delta_{kl}\n\\end{equation}\n\\end{itemize}\n\n\\section{Self-adjoint Operators}\\label{mr13}\nConsider a differential equation of the form\\cite{arfken1999mathematical}\n\\begin{equation}\\label{mr13e1}\np_0(x)u^\\tp + p_1(x)u^\\op + p_2(x)u(x) = 0,\n\\end{equation}\nwhere $p_0, p_1$ and $p_2$ are given functions of $x$ and $u$ is the unknown function. The differential equation is defined over a neighbourhood $[a, b]$ and the functions $p_0, p_1$ and $p_2$ are \nassumed to be defined on it. We further assume that the function $p_i$ has at least $2 - i$ continuous derivatives on $[a, b]$. The function $y$ will also have certain boundary conditions to be\nsatisfied. The equation can be written as $Lu = 0$ where the linear operator $L$ is defined as\n\\begin{equation}\\label{mr13e2}\nL = p_0D^2 + p_1D + p_2,\n\\end{equation}\nwhere $D$ denotes the differential operator $d/dx$. The inner product of functions $u$ and $v$ is defined as\n\\begin{equation}\\label{mr13e3}\n(u, v) = \\int_a^b uv dx,\n\\end{equation}\nso that\n\\begin{equation}\\label{mr13e4}\n(u, Lu) = \\int_a^b u(x)\\left(p_0(x)u^\\tp + p_1(x)u^\\op + p_2(x)u(x)\\right)dx.\n\\end{equation}\nIntegrating by parts leads us to an equivalent representation\n\\begin{equation}\\label{mr13e5}\n(u, Lu) = \\left[u(p_1 - p_0^\\op)u\\right]_a^b + \\int_a^b\\left(\\frac{d^2}{dx^2}(p_0 u) - \\frac{d}{dx}(p_1 u) + p_2 u\\right) u dx.\n\\end{equation}\nThe integrals in the two preceeding equations are identical if their integrands are the same. That is, when,\n\\[\n\\left(\\frac{d^2}{dx^2}(p_0 u) - \\frac{d}{dx}(p_1 u) + p_2 u\\right)u = u(p_0 u^\\tp + p_1 u^\\op + p_2 u).\n\\]\nThis equation is satisfied when $p_0^\\op = p_1$, in which case the boundary terms in \\eqref{mr13e5} vanishes. We now define the adjoint\noperator\n\\begin{equation}\\label{mr13e6}\nL^\\ast = p_0\\frac{d^2}{dx^2} + (2p_0^\\op - p_1)\\frac{d}{dx} + (p_0^\\tp - p_1^\\op + p_2).\n\\end{equation}\nIt can be equivalently defined as\n\\begin{equation}\\label{mr13e7}\n(L^\\ast u, u) = (u, Lu).\n\\end{equation}\n\nAn operator $L$ is said to be self adjoint if $L = L^\\ast$. An equation of the form $Lu = 0$ is said to be in self-adjoint form if $L^\\ast = L$.\n\nIt is easy to check that the Bessel equation in the form $x^2u^\\tp + xu^\\op + (x^2 - n^2)u = 0$ is not self-adjoint form. However, if we rewrite it\nas \n\\begin{equation}\\label{mr13e8}\nxu^\\tp + u^\\op + \\left(x - \\frac{n^2}{x}\\right)u = 0\n\\end{equation}\nthen we get it in a self-adjoint form.\n\nWe will now prove Lagrange's identity,\n\\begin{equation}\\label{mr13e9}\nvL(u) - uL^\\ast(v) = \\frac{d}{dx}\\left[p_0(u^\\op v - uv^\\op) - (p_0^\\op - p_1)uv\\right].\n\\end{equation}\nThe proof is quite straight-forward when begun from the right hand side when we add and subtract the term $p_2uv$.\n\n\\section{Sturm-Liouville theory}\\label{mr14}\nConsider the differential equation of the form\n\\begin{equation}\\label{mr14e1}\n\\frac{d}{dx}\\left(p(x)\\frac{du}{dx}\\right) + \\left(\\lambda\\rho(x) - q(x)\\right)u(x) = 0,\n\\end{equation}\nwhere the functions $p, q$ and $\\rho$ are real-valued over an interval $[a, b]$. It is easy to confirm that the operator $L$ defined by\n\\begin{equation}\\label{mr14e2}\nL = D[pD] - q\n\\end{equation}\nis self-adjoint. If we write the differential equation \\eqref{mr14e1} as $L(u) - \\lambda\\rho(x)u(x)$ then $p_0 = p, p_1 = p^\\op$ and $p_2 = \\lambda\\rho - q$.\nLagrange's identity \\eqref{mr13e9} then becomes\n\\begin{equation}\\label{mr14e3}\nvL(u) - uL(v) = \\frac{d}{dx}\\left[p(u^\\op v - uv^\\op)\\right].\n\\end{equation}\nThe equation \\eqref{mr14e1} is frequently accompanied by boundary conditions of the form\n\\begin{eqnarray}\n\\alpha u(a) + \\alpha^\\op u^\\op(a) &=& 0 \\label{mr14e4} \\\\\n\\beta u(b) + \\beta^\\op u^\\op(b) &=& 0, \\label{mr14e5} \n\\end{eqnarray}\nwhere none of the constants $\\alpha, \\alpha^\\op, \\beta$ and $\\beta^\\op$ are zero. It is then easy to check that if $u$ and $v$ are\ntwo solutions of \\eqref{mr14e1} then\n\\begin{eqnarray}\nu(a)v^\\op(a) - u^\\op(a)v(a) &=& 0 \\label{mr14e6} \\\\\nu(b)v^\\op(b) - u^\\op(b)v(b) &=& 0 \\label{mr14e7}.\n\\end{eqnarray}\nIf $u$ and $v$ are such that\n\\begin{eqnarray*}\nL(u) - \\lambda\\rho(x)u(x) &=& 0 \\\\\nL(v) - \\mu\\rho(x)v(x) &=& 0 \n\\end{eqnarray*}\nthen\n\\[\nvL(u) - uL(v) = (\\lambda - \\mu)\\rho(x)u(x)v(x)\n\\]\nand hence,\n\\[\n(\\lambda - \\mu)\\int_a^b u(x)v(x)\\rho(x)dx = \\int_a^b \\left(vL(u) - uL(v)\\right)dx\n\\]\nUsing equation \\eqref{mr14e3}, we readily get\n\\[\n(\\lambda - \\mu)\\int_a^b u(x)v(x)\\rho(x)dx = \\left[p(u^\\op v - uv^\\op)\\right]_a^b.\n\\]\nFrom equations \\eqref{mr14e6} and \\eqref{mr14e7} we readily get\n\\[\n(\\lambda - \\mu)\\int_a^b u(x)v(x)\\rho(x)dx = 0.\n\\]\nSince $\\lambda \\ne \\mu$, we get the Sturm-Liouville orthogonality condition,\n\\begin{equation}\\label{mr14e8}\n\\int_a^b u(x)v(x)\\rho(x)dx = 0.\n\\end{equation}\n\n\\section{Bessel functions}\\label{mr15}\nBessel equation is \n\\begin{equation}\\label{mr15e1}\nx^2y^\\tp + xy^\\op + (x^2 - \\nu^2)y = 0,\n\\end{equation}\nwhere $y$ is a function of $x$ and $\\nu$ is a complex number. We will try to solve this equation by Frobenius method. Let\n\\begin{equation}\\label{mr15e2}\ny(x) = \\sum_{n=0}^\\infty a_nx^{n+k}\n\\end{equation}\nwhere $a_0 \\ne 0$. Substituting it in equation \\eqref{mr15e1} we get\n\\[\n\\sum_{n=0}^\\infty a_n\\left[(n+k)(n+k-1) + (n+k) - \\nu^2\\right]x^{n+k} + \\sum_{n=0}^\\infty a_nx^{n+k+2} = 0.\n\\]\nIf we put $n=0$, we get the lowest order term\n\\[\na_0[k(k-1) + k + \\nu^2]x^k.\n\\]\nNote that there is no contribution from the last term because its power is $x^{k+2}$. If the equation has to be satisfied and $a_0 \\ne 0$ then we must have\n\\begin{equation}\\label{mr15e3}\nk^2 - \\nu^2 = 0.\n\\end{equation}\nThis is the indicial equation of Bessel equation and its solution is $k = \\pm\\nu$. The recurrence relation is found by investigating the coefficients of a power of $x$. A general term of the series is\n\\[\n\\left(a_{n+2}\\left[(n+k+2)(n+k+1) + (n+k+2) - \\nu^2\\right] + a_n\\right)x^{n+k+2}.\n\\]\nSince every term of the series has to be zero, we require that \n\\[\na_{n+2}\\left[(n+k+2)(n+k+1) + (n+k+2) - \\nu^2\\right] + a_n = 0\n\\]\nor, after using the indicial equation \\eqref{mr15e3}, we get the recurrence relation\n\\begin{equation}\\label{mr15e4}\na_{n+2} = \\frac{-a_n}{(n+2)(n+2k+2)}.\n\\end{equation}\nWe examine the first few coefficients,\n\\begin{eqnarray*}\na_2 = \\frac{-a_0}{2(2k+2)} &=& \\frac{-a_0 k!}{2^2 1! (k+1)!} \\\\\na_4 = \\frac{-a_2}{4(2k+4)} &=& \\frac{+a_0 k!}{2^4 2! (k+2)!} \\\\\na_6 = \\frac{-a_4}{6(2k+6)} &=& \\frac{-a_0 k!}{2^6 3! (k+3)!} \n\\end{eqnarray*}\nso that the general term can be written as\n\\begin{equation}\\label{mr15e5}\na_{2n} = (-1)^n\\frac{a_0 n!}{2^{2n}n!(n+k)!}.\n\\end{equation}\nThe solution of the equation is thus,\n\\begin{eqnarray*}\ny(x) &=& a_0\\sum_{n=0}^\\infty (-1)^n\\frac{n!x^{2n+k}}{2^{2n}n!(n+k)!} \\\\\n     &=& a_02^k k!\\sum_{n=0}^\\infty (-1)^n \\frac{1}{n!(n+k)!}\\left(\\frac{x}{2}\\right)^{2n+k} \n\\end{eqnarray*}\nUsing one solution of the indicial equation, namely $k = \\nu$ and denoting the solution by its conventional name, we get\n\\begin{equation}\\label{mr15e6}\nJ_\\nu(x) = \\sum_{n=0}^\\infty (-1)^n\\frac{1}{n!(n+\\nu)!}\\left(\\frac{x}{2}\\right)^{2n+\\nu},\n\\end{equation}\nwhere we have chosen $a_0 = (2^\\nu \\nu!)^{-1}$. $J_\\nu$ is called the Bessel function of the first kind of order $\\nu$. Recall that $\\nu$ is an arbitrary complex number. \nTherefore, it is appropriate to wtite $(n + \\nu)!$ as $\\Gamma$-function. Thus,\n\\begin{equation}\\label{mr15e7}\nJ_\\nu(z) = \\sum_{n=0}^\\infty (-1)^n\\frac{1}{n!\\Gamma(n+\\nu+1)}\\left(\\frac{z}{2}\\right)^{2n+\\nu}.\n\\end{equation}\nBefore closing this section we justify the orthogonality relation for Bessel functions. Recall that Bessel equation in Sturm-Lioville form is\n\\[\nxy^\\op + y^\\op + \\left(x - \\frac{\\nu^2}{x}\\right)y  = 0.\n\\]\nComparing it with the standard form \\eqref{mr14e1} we observe that $p(x) = x, \\lambda = 1, \\rho(x) = x$ and $q(x) = -\\nu^2/x$. Therefore, equation \\eqref{mr14e8} becomes\n\\begin{equation}\\label{mr15e8}\n\\int_0^1 J_n(x)J_m(x)xdx = C\\delta_{mn},\n\\end{equation}\nwhere $C$ is a normalization constant.\n", "meta": {"hexsha": "dd1c38a5e6a97310a3543fcd466a3df512b8071b", "size": 55680, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "gkb/mres.tex", "max_stars_repo_name": "amey-joshi/physics", "max_stars_repo_head_hexsha": "66ae9bf4a363bd32b09df22a049e281953adb39b", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "gkb/mres.tex", "max_issues_repo_name": "amey-joshi/physics", "max_issues_repo_head_hexsha": "66ae9bf4a363bd32b09df22a049e281953adb39b", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gkb/mres.tex", "max_forks_repo_name": "amey-joshi/physics", "max_forks_repo_head_hexsha": "66ae9bf4a363bd32b09df22a049e281953adb39b", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.4173913043, "max_line_length": 200, "alphanum_fraction": 0.6308189655, "num_tokens": 23334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.8031737869342624, "lm_q1q2_score": 0.7308134616842553}}
{"text": "% ***********************************************************************************\n% Pure LaTeX part to be inserted in a document (be careful of depencies of packages & commands\n% Prepared by Xin Peng and Hongbei Chen under the supervision of Arnaud de La Fortelle\n% Fall 2017\n% weak formulation Dirichlet of the modeling part\n% ***********************************************************************************\n\\subgroup{3} {Xin Peng and Hongbei Chen}\n\n\n\\paragraph{Objective}\n\nWeak formulations are important tools for the analysis of mathematical equations that permit the transfer of concepts of linear algebra to solve problems in other fields such as partial differential equations. In a weak formulation, an equation is no longer required to hold absolutely and has instead weak solutions only with respect to certain \"test vectors\" or \"test functions\". This is equivalent to formulating the problem to require a solution in the sense of a distribution.\n\nTake Poisson's equation as a example. Our aim is to solve this Poisson's equation\n$$-\\Delta u= f\\eqno(1.1)$$\non a domain $\\Omega \\subset R^d$,$u=0$ on its boundary.\\\\\nSuppose $u$ is continuously differentiable in continental space $R^{2}$, test it with differentiable functions $v$ and integral, we get\n\n$$\\int_\\Omega \\left ( \\nabla^2u \\right )v\\ud x=\\int_\\Omega fv\\ud x\\eqno(1.2)$$\nWe can make the left side of this equation more symmetric by integration by parts using Green's identity and assuming that $v=0$ on $\\partial \\Omega $\n$$-\\int _\\Omega \\left ( \\nabla^2u \\right )v\\ud x= -\\int _{\\partial\\Omega }\\left ( \\nabla u \\right )v\\ud s+\\int _\\Omega \\nabla u \\nabla v\\ud x\\eqno(1.3)$$\n\n$$-\\int _\\Omega \\left ( \\nabla^2u \\right )v\\ud x=\\int _\\Omega \\nabla u \\nabla v\\ud x\\eqno(1.4)$$\nThe equation 1.4 is what is usually called the weak formulation of Poisson's equation. As we can see, weak formulations are partial differential equations testing with \"test vectors\" or \"test functions\" and then integral both side of equations. This transformation sacrifices the smoothness of solution. Since a large number of differential equations used to describe the phenomena in the real world do not have enough smooth solutions to solve such equations can only use weak formulation.\\\\\n\n\\paragraph{Demonstration}\n\nA Dirichlet problem is the problem of finding a function which solves a specified partial differential equation in the interior of a given region that takes prescribed values on the boundary of the region. We take a PDE for example.\\\\\n\n\nWe consider $f$ a continuous function on $\\Omega$ of sumtable square and $u$ the solution of the following partial derivative equation on $\\Omega$\n$$-\\Delta u+k^{2} u=f\\eqno(2.1)$$\nWith the condition at the edge $u=0$ on $\\partial\\Omega$. This can also be rewritten $u\\subset V _{0}$. This condition at the edge is called the Dirichlet condition. We prove that there exists a unique solution to this PDE problem using the Lax-Milgram theorem.\\\\\n\nLet $u\\subset V _{0}$ be arbitrary. Multiply the two parts of the previous equation by $v$ then sum to the domain $\\Omega$, since $v$ and $f$ are both summable square on this domain. Equation:\n$$-\\int _\\Omega \\Delta uv\\ud w + k^2\\int _\\Omega uv\\ud w = \\int _\\Omega vf\\ud w\\eqno(2.2)$$\nWe can make the left side of this equation more symmetric by integration by parts using Green's identity:\n$$-\\int _\\Omega v\\Delta u\\ud w=-\\int _{\\partial \\Omega }v\\nabla u\\ud s+\\int _\\Omega \\left ( \\nabla u \\nabla v \\right )\\ud w\\eqno(2.3)$$\nIn this formulation, $v=0$ on $\\partial \\Omega $ $(v\\subset V _{0})$.Thus $\\int _{\\partial \\Omega }v\\nabla u\\ud s=0$.\n$$\\int _\\Omega \\left ( \\nabla u \\nabla v \\right )\\ud w+ k^2\\int _\\Omega uv\\ud w = \\int _\\Omega vf\\ud w\\eqno(2.4)$$\nIf u is twice differentiable, there is equivalence between this formulation and that of the initial problem given in the hypothesis section(Because we used to integral both side of equation). Then the solution of the weak formulation is the same as the initial solution. We can therefore solve the weak formulation instead of solving the initial problem.\n\n\n\n", "meta": {"hexsha": "668999990ef19d113d6eb417dbdc5c3e4effc4d4", "size": 4073, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modeling-weakformulationDirichlet.tex", "max_stars_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_stars_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-08T02:54:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-29T06:19:28.000Z", "max_issues_repo_path": "modeling-weakformulationDirichlet.tex", "max_issues_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_issues_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "modeling-weakformulationDirichlet.tex", "max_forks_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_forks_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-16T17:29:03.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-16T17:29:03.000Z", "avg_line_length": 90.5111111111, "max_line_length": 492, "alphanum_fraction": 0.7191259514, "num_tokens": 1075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7307779434563672}}
{"text": "\\subsection{Introduction}\n\n\\begin{frame}\n  \\frametitle{Intro}\n\n\\scriptsize\n\nSatisfiability Modulo Theories, SMT, studies {\\bf practical methods} \nto {\\bf solve} logical \\formulae \n\n\\vfill\n\\pause\nThese \\formulae are defined/interpreted modulo a {\\bf background theory},\nsuch as Linear Real Arithmetic (\\Lra), Arrays (\\Arrays), Bit-Vectors (\\Bitvectors), etc.\n\n\\vfill\n\\pause\nFor instance, we want to determine the satisfiability modulo \\Lra of\n\\begin{eqnarray}\n\\label{eq:example1}\n(x + y \\leq 0) \\swedge (x = 0) \\swedge (\\neg a \\svee (x = 1) \\svee (y \\geq 0))\n\\end{eqnarray}\nwhere $x, y$ are arithmetic variables, while $a$ is a Boolean variable. \\pause\nIntuitively, (\\ref{eq:example1}) is satisfiable iff we can find values\nfor $x$ and $y$ in \\Rea and for $a$ in \\Boo such that it evaluates to $\\top$\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Definitions (syntax)}\n\n  In SMT a theory \\T is defined over a {\\bf signature} $\\Sigma$, which\n  is a set of function and predicate symbols such as $\\{ 0, 1, \\ldots, +,-, \\ldots, \\leq \\}$.\n  The equality symbol $=$ is assumed to be included in every signature. \n  \\pause\n  \\vfill\n  Variables and function symbols in $\\Sigma$ can be used to build {\\bf theory-terms}\n  (\\tterm): a \\tterm is either a variable or, recursively, an application\n  of a function symbol in $\\Sigma$ to terms\n  \\pause\n  \\vfill\n  Predicate symbols in $\\Sigma$ can be used to build {\\bf theory-atom}s\n  (\\tatom): a \\tatom is the application of a predicate symbol in $\\Sigma$ \n  to \\tterms\n  \\pause\n  \\vfill\n  A {\\bf theory-literal} (\\tlit) is either a \\tatom or its negation\n  \\pause\n  \\vfill\n  A formula is any Boolean combination of \\tatoms and Boolean variables\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Definitions (semantic)}\n\n  \\scriptsize\n\n  In SMT the {\\bf interpretation} of the symbols in $\\Sigma$\n  is fixed, and it corresponds to the usual semantic of the operators.\n  For instance, in \\Lia (Linear Integer Arithmetic):\n  \\begin{itemize}\n  \\item numerals are mapped to the corresponding value in $\\Int$\n  \\item $+$ is interpreted as the function\n        $$\n        \\begin{array}{l}\n          (0,0) \\mapsto 0 \\\\\n          (0,1) \\mapsto 1 \\\\\n          \\ldots\n        \\end{array}\n        $$  \n  \\end{itemize}\n\n  \\pause\n  \\vfill\n\n  The only unspecified entities are variables, for which we have to build \n  an {\\bf assignment}, a mapping from variables to concrete values in $\\Int$\n\n  \\vfill\n  \\pause\n\n  Now everything is specified and we can evaluate \\tterms, \\tatoms and \n  \\formulae. For instance, the \\tatom \n  $$\n    (x + y \\leq 0) \\swedge (x = 0) \\swedge (\\neg a \\svee (x = 1) \\svee (y \\geq 0))\n  $$\n  evaluates to $\\top$ under the assignment $\\{ x \\mapsto 0, y \\mapsto 0, a \\mapsto \\bot \\}$, and it\n  evaluates to $\\bot$ under the assignment $\\{ x \\mapsto 5, y \\mapsto -10, a \\mapsto \\bot \\}$\n\n  \\vfill\n  \\pause\n\n  We say that a formula $\\varphi$ is satisfiable modulo \\T, if there is an\n  assignment $M$ that evaluates $\\varphi$ to $\\top$. In that case we say that\n  $M$ is a {\\bf model} \n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Solving SMT \\formulae by reduction to SAT}\n\n  \\scriptsize\n\n  Approaches to solve SMT \\formulae are based on the observation\n  that SMT can be {\\bf reduced} to SAT, i.e., the purely Boolean\n  Satisfiability Problem\n  \\vfill\n  \\pause\n  Consider for instance the \\Lia formula\n  $$\n  \\varphi \\equiv (x - y \\leq 0) \\wedge (y - z \\leq 0) \\wedge ((z - x \\leq -1) \\vee (z - x \\leq -2))\n  $$\n  We may use a Boolean variable $a$ to mean ``$x - y \\leq 0$'' evaluates to $\\top$\n  in the model. Similarly we could use $b, c, d$ for the other \\tatoms.\n  \\vfill\n  \\pause\n  First of all, we notice that it {\\bf does not} hold in \\Lia that\n  $$ x - y \\leq 0\\quad\\quad  y - z \\leq 0\\quad\\quad z - x \\leq -1 $$\n  evaluate to $\\top$ {\\bf at the same time}, because this is not possible in \\Lia. \\pause\n  This translates to the Boolean relation \n  $$ \\neg( a \\wedge b \\wedge c )$$ \\pause\n  Similarly we may derive \n  $$ \\neg( a \\wedge b \\wedge d )\\quad\\quad \\neg( \\neg a \\wedge \\neg b \\wedge \\neg c )\\quad\\quad \\neg( \\neg a \\wedge \\neg b \\wedge \\neg d )$$ \\pause\n  \\vfill\n  Moreover, because of the ``structure'' of $\\varphi$, it holds that \n  $$ a \\wedge b \\wedge (c \\vee d)$$\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Solving SMT \\formulae by reduction to SAT}\n\n  \\scriptsize\n\n  $$\n  \\varphi \\equiv (x - y \\leq 0) \\wedge (y - z \\leq 0) \\wedge ((z - x \\leq -1) \\vee (z - x \\leq -2))\n  $$\n\n  $$\n  \\begin{array}{l}\n  a \\ \\ \\mbox{ represents } \\ \\ x - y \\leq 0 \\\\\n  b \\ \\ \\mbox{ represents } \\ \\ y - z \\leq 0 \\\\\n  c \\ \\ \\mbox{ represents } \\ \\ z - x \\leq -1 \\\\\n  d \\ \\ \\mbox{ represents } \\ \\ z - x \\leq -2\n  \\end{array}\n  $$\n  \\vfill\n  \\pause\n  Putting all the conditions together we get the Boolean formula\n  $$ \n  \\psi \\equiv\\ a \\wedge b \\wedge (c \\vee d)\\ \\wedge\\ \\neg( a \\wedge b \\wedge c )\\ \\wedge\\ \\neg( a \\wedge b \\wedge d )\\ \\wedge\\\n  \\neg( \\neg a \\wedge \\neg b \\wedge \\neg c )\\ \\wedge\\ \\neg( \\neg a \\wedge \\neg b \\wedge \\neg d )\n  $$ \\pause\n  Because of our translation, we have that $\\varphi$ is \\Lia-satisfiable if and only if $\\psi$ is\n  satisfiable. This is true because\n  \\begin{enumerate}\n    \\item we have {\\bf exhaustively} encoded incompatible relations between \\tatoms \n    \\item we have encoded the structure of $\\varphi$\n  \\end{enumerate} \\pause\n  Therefore we may run any off-the-shelf \\satsolver to determine the satisfiability of $\\psi$ \n  (and therefore that of $\\varphi$)\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Exercizes}\n\n  \\begin{enumerate}\n    \\item Check that $\\varphi$ is \\Lia-unsatisfiable, and that $\\psi$ is also unsatisfiable\n\n    \\vfill\n\n    \\item Check that \n\t  $\\neg( \\neg a \\wedge \\neg b \\wedge \\neg c )$ and $\\neg( \\neg a \\wedge \\neg b \\wedge \\neg d )$\n\t  are actually redundant in $\\psi$. Why it is so ?\n\n    \\vfill\n\n    \\item Substitute $z - x \\leq -2$ with $z - x \\leq 2$ into $\\varphi$, recompute\n\t  the correct $\\psi$, and check that $\\varphi$ is \\Lia-satisfiable and that\n\t  $\\psi$ is also satisfiable\n\n    \\vfill\n\n    \\item Prove that the encoding into SAT is correct and complete, i.e., that if\n    \\begin{enumerate}[$(i)$]\n      \\item we have {\\bf exhaustively} encoded incompatible relations between \\tatoms \n      \\item we have encoded the structure of $\\varphi$\n    \\end{enumerate} \n\t  then $\\varphi$ is \\T-satisfiable if and only if $\\psi$ is satisfiable\n\n  \\end{enumerate}\n\n\\end{frame}\n", "meta": {"hexsha": "b71de396a61e538fbd526cbe8fd0b55125a09b8c", "size": 6379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture1/intro.tex", "max_stars_repo_name": "formalmethods/smtlectures", "max_stars_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-11-07T19:34:12.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-24T08:05:50.000Z", "max_issues_repo_path": "lecture1/intro.tex", "max_issues_repo_name": "formalmethods/smtlectures", "max_issues_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture1/intro.tex", "max_forks_repo_name": "formalmethods/smtlectures", "max_forks_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-06T00:40:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-06T00:40:41.000Z", "avg_line_length": 32.881443299, "max_line_length": 147, "alphanum_fraction": 0.6508857188, "num_tokens": 2140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541613, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7307779422241686}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Taylor Series Applications}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nVarious exercises relating to the application of Taylor Series to other problems of interest.\n\\end{abstract}\n\\maketitle\n\n\\begin{exercise}\nCompute the limit \n\\[ \\lim_{n \\rightarrow \\infty} n^3 \\left[ \\arctan \\frac{1}{n} - \\frac{1}{n} \\right]. \\]\n\\begin{itemize}\n\\item The first few terms of the Maclaurin series for $\\arctan x$ are\n\\[ \\cos x = \\answer{x} - \\answer{\\frac{x^3}{3}} + \\answer{\\frac{x^5}{5}} + \\cdots \\]\n\\item Plug in $x = \\frac{1}{n}$ and subtract $1/n$:\n\\[ \\arctan \\frac{1}{n} - \\frac{1}{n} = - \\frac{1}{3n^3} + \\answer{\\frac{1}{5n^5}} + \\cdots \\]\n\\item Multiply by $n^3$, neglect all but the dominant term, and conclude\n\\[ \\lim_{n \\rightarrow \\infty} n^3 \\left[ \\arctan \\frac{1}{n} - \\frac{1}{n} \\right] = \\answer{-\\frac{1}{3}} \\]\n\\end{itemize}\n\\end{exercise}\n\n\\begin{exercise}\nCompute the limit\n\\[ \\lim_{n \\rightarrow \\infty} \\frac{\\ln (n+3) - \\ln n}{\\ln (n+1) - \\ln n}. \\]\n\\begin{itemize}\n\\item First combine logarithms to simplify a bit:\n\\[  \\ln (n+3) - \\ln n  =  \\ln \\answer{1 + \\frac{3}{n}} \\ \\ \\text{ and } \\ \\ \\ln (n+1) - \\ln n  =  \\ln \\answer{1 + \\frac{1}{n}}. \\]\n\\item Write out the first few terms of the Maclaurin series for $\\ln (1+x)$ and substitute in the appropriate expression involving $n$:\n\\[ \\ln (1 + x) = \\answer{x} - \\answer{\\frac{x^2}{2}} + \\answer{\\frac{x^3}{3}} - \\cdots \\]\n\\[ \\ln (n+3) - \\ln n = \\answer{ \\frac{3}{n}} - \\answer{\\frac{9}{2n^2}} + \\answer{\\frac{9}{n^3}} - \\cdots \\]\n\\[ \\ln (n+1) - \\ln n = \\answer{\\frac{1}{n}} - \\answer{\\frac{1}{2n^2}} + \\answer{\\frac{1}{3n^3}} - \\cdots \\]\n\\item Multiply by $n$, neglect all but the dominant term (as $n \\rightarrow \\infty)$ to conclude\n\\[ \\lim_{n \\rightarrow \\infty} \\frac{\\ln (n+3) - \\ln n}{\\ln (n+1) - \\ln n} = \\answer{3}. \\]\n\\end{itemize}\n\\end{exercise}\n\n\\begin{exercise}\nCompute the limit\n\\[ \\lim_{x \\rightarrow 1}  \\frac{\\ln x - x + 1}{\\sin \\pi x}. \\]\n\\begin{itemize}\n\\item Compute the first few terms of the Taylor series of numerator and denominator centered at $x = 1$:\n\\[ \\ln x - x + 1 = \\answer{0} + \\answer{0} (x-1) + \\answer{-\\frac{1}{2}} (x-1)^2 + \\answer{\\frac{1}{3}} (x-1)^3 + \\cdots \\]\n\\[ \\sin \\pi x = \\answer{0} + \\answer{-\\pi}(x-1) + \\answer{0} (x-1)^2 + \\answer{\\frac{\\pi^3}{6}}(x-1)^3 + \\cdots \\]\n\\item Neglect all but the dominant terms in numerator and denominator. Note that dominant here means as $x \\rightarrow 1$. Then take the limit $x \\rightarrow 1$:\n\\[ \\lim_{x \\rightarrow 1}  \\frac{\\ln x - x + 1}{\\sin \\pi x} = \\answer{0}. \\]\n\\end{itemize}\n\\end{exercise}\n\n\n\\begin{exercise}\nUse the remainder formula for Taylor series to determine which partial sums of the series \n\\[ \\sum_{n=0}^\\infty \\frac{1}{n!} \\]\ndiffer from $e$ by at most $1/100$?\n\\begin{itemize}\n\\item The remainder formula says that\n\\[ e^1 - \\sum_{n=0}^{N} \\frac{1}{n!} = \\frac{e^{\\xi}}{(N+1)!} (1-0)^{N+1} \\]\nfor some point $\\xi$ which depends on $N$ and is somewhere in the interval $(\\answer{0},\\answer{1})$. The upper bound for the magnitude of $e^\\xi$ on this interval is $M = \\answer{e}$.\n\\item For which values of $N$ do we have\n\\[  \\frac{M}{(N+1)!} \\leq \\frac{1}{50}? \\]\n(Check manually for small values of $N$; use the fact that $e$ is between $2$ and $3$.)\n\\[ N \\geq \\answer{4}. \\]\n\\end{itemize}\n\\end{exercise}\n\n\n\n\\begin{exercise}\nIn this exercise, we will investigate two different ways of numerically approximating the value of $\\ln 2$ using infinite series.\n\\begin{itemize}\n\\item The Maclaurin series of the function $\\ln 1 + x$ converges conditionally at $x = 1$ to $\\ln 2$. Compute the Maclaurin series: \n\\[ \\ln (1 + x) = \\sum_{n=0}^\\infty \\answer{\\frac{(-1)^n}{n+1}} x^{n+1} \\]\n(Reindex your answer to match the template above if your answer doesn't work as-is.)\n\\item  What degree Taylor polynomial would you need to use to approximate the value of $\\ln 2$ to an error strictly less than $10^{-3}$? Answer: Taylor polynomial used should have degree $N = \\answer{1000}$ or greater.\n\\item A similar but distinct strategy would be to compute $\\ln (1/2)$ instead because we know $- \\ln (1/2)  = \\ln 2$. Evaluating the Maclaurin series at $x=-1/2$ and doing a little simplification, we see from the above series that\n\\[ \\ln 2 = \\sum_{n=1}^\\infty \\answer{\\frac{1}{n 2^n}}. \\]\n(Once again, reindex if your answer does not already start at $n=1$.)\n\\item The presence of a factor exponential in $n$ suggests that this second series converges to $\\ln 2$ \\wordChoice{\\choice{much slower}\\choice{slightly slower}\\choice{slightly faster}\\choice[correct]{much faster}} than the first series. Of the two series, then, the \\wordChoice{\\choice{first}\\choice[correct]{second}} series presents a more efficient way to compute $\\ln 2$ numerically.\n\\end{itemize}\n\\begin{hint}\nFor the first estimation, use the series estimation features of the Alternating Series Test.\n\\begin{hint}\nFor an alternating series, the error of approximating the series by a partial sum is never greater than the magnitude of the \\textit{first term omitted}.\n\\end{hint}\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nUse the remainder formula for Taylor series to determine which partial sums of the series\n\\[ \\sum_{n=1}^\\infty \\frac{1}{n 3^n} \\]\ndiffer from $\\ln (3/2)$ by at most $10^{-2}$?\n\\begin{itemize}\n\\item Guided by the example above, we will use the Maclaurin series \n\\[ - \\ln (1-x) = \\sum_{n=1}^\\infty \\frac{x^n}{n}. \\]\nFirst, compute the derivatives of $- \\ln (1-x)$. Find a pattern which holds for all $N$:\n\\[ \\frac{d^{N+1}}{dx^{N+1}} \\left( - \\ln (1 - x) \\right)  = \\answer{ \\frac{N!}{(1-x)^{N+1}}}. \\]\nWhen $x$ is between $0$ and $1/3$, the largest value of the $(N+1)$-st derivative is what?\n\\[ \\left| \\frac{d^{N+1}}{dx^{N+1}} \\left( - \\ln (1 - x) \\right) \\right| \\leq \\answer{N! 3^{N+1}/2^{N+1}}. \\]\n\\item Using this upper bound for the $(N+1)$-st derivative, we know that\n\\[ \\left| \\ln \\frac{3}{2} - \\sum_{n=0}^N \\frac{1}{n 3^n} \\right| \\leq \\answer{ \\frac{1}{(N+1) 2^{N+1}}} \\]\n(use the upper bound and the remainder formula.)\n\\item For which values of $N$ is the expression you just found less than $1/100$? Check by hand for smallish values of $N$ to find the smallest one which works.\n\\[ N \\geq \\answer{4}. \\]\n\\end{itemize}\n\\end{exercise}\n\n\n\n\\section*{Sample Quiz Questions}\n\n\n\n\\begin{question}%%%%%[TAp0]\n\nUse Taylor series to estimate the value of\n\\[\\sqrt[3]{\\frac{11}{10}}\\] to within an error of at most \\(1/900\\).\n(Hints will not be revealed until you choose a response.)\n\\begin{multiplechoice}\n\\choice[correct]{\\(\\displaystyle \\frac{31}{30}\\)}\n\\choice{\\(\\displaystyle \\frac{47}{45}\\)}\n\\choice{\\(\\displaystyle \\frac{19}{18}\\)}\n\\choice{\\(\\displaystyle \\frac{16}{15}\\)}\n\\choice{\\(\\displaystyle \\frac{97}{90}\\)}\n\\choice{\\(\\displaystyle \\frac{49}{45}\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nWe may use the remainder formula for Taylor series to approach this problem.\nSuppose \\(p_n(x)\\) is the degree \\(n\\) Taylor polynomial of the function\n\\[ f(x) = \\sqrt[3]{1+x}\\]\nwith center \\(a=0\\). Then the error \\(E_n(x)\\), i.e., the difference between the polynomial and the function, does not exceed \\(\\frac{f^{(n+1)}(\\xi)}{(n+1)!}x^{n+1}\\), where \\(\\xi\\) is some unknown point  in the range \\(0 \\leq \\xi \\leq x\\). \\begin{hint} In this case one should take \\(x = 1/10\\) and determine how many derivatives are required to make this error estimate less than the given threshold. \\begin{hint} This means checking by hand for small numbers of derivatives. For the specific problem at hand, if we approximate \\(f(x)\\) by the Taylor polynomial of degree \\( n = 1\\), we have \n\\[ \\left| \\frac{x^{n+1} }{(n+1)!} f^{(n+1)}(\\xi) \\right| = \\left| \\frac{x^{n+1}}{(n+1)!} \\left( -\\frac{2}{9} (\\xi+1)^{-5/3} \\right) \\right| \\leq \\left| \\frac{x^{n+1}}{(n+1)!} \\left( \\frac{2}{9} \\right) \\right| = \\frac{1}{900} \\] when \\(x = 1/10\\). \\begin{hint}\nWe conclude that the correct Taylor approximation is\n\\[ p_n \\left( \\frac{1}{10}\\right) =  \\left(\\frac{1}{10}\\right)^{0} + \\frac{1}{3}\\left(\\frac{1}{10}\\right)^{1} =  1 + \\frac{1}{30} = \\frac{31}{30}.\\]\n\\end{hint} \\end{hint} \\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[TAp1]\n\nUse Taylor series to estimate the value of\n\\[e^{-\\frac{1}{3}}\\] to within an error of at most \\(1/162\\).\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\frac{5}{9}\\)}\n\\choice[correct]{\\(\\displaystyle \\frac{13}{18}\\)}\n\\choice{\\(\\displaystyle \\frac{8}{9}\\)}\n\\choice{\\(\\displaystyle \\frac{19}{18}\\)}\n\\choice{\\(\\displaystyle \\frac{11}{9}\\)}\n\\choice{\\(\\displaystyle \\frac{25}{18}\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nWe may use the remainder formula for Taylor series to approach this problem.\nSuppose \\(p_n(x)\\) is the degree \\(n\\) Taylor polynomial of the function\n\\[ f(x) = e^{-x}\\]\nwith center \\(a=0\\). Then the error \\(E_n(x)\\), i.e., the difference between the polynomial and the function, does not exceed \\(\\frac{f^{(n+1)}(\\xi)}{(n+1)!}x^{n+1}\\), where \\(\\xi\\) is some unknown point  in the range \\(0 \\leq \\xi \\leq x\\). \\begin{hint}  In this case one should take \\(x = 1/3\\) and determine how many derivatives are required to make this error estimate less than the given threshold. \\begin{hint} This means checking by hand for small numbers of derivatives. For the specific problem at hand, if we approximate \\(f(x)\\) by the Taylor polynomial of degree \\( n = 2\\), we have \n\\[ \\left| \\frac{x^{n+1} }{(n+1)!} f^{(n+1)}(\\xi) \\right| = \\left| \\frac{x^{n+1}}{(n+1)!} \\left( e^{-\\xi} \\right) \\right| \\leq \\left| \\frac{x^{n+1}}{(n+1)!} \\left( 1 \\right) \\right| = \\frac{1}{162} \\] when \\(x = 1/3\\). \\begin{hint}\nWe conclude that the correct Taylor approximation is\n\\[ p_n \\left( \\frac{1}{3}\\right) =  \\left(\\frac{1}{3}\\right)^{0} -1\\left(\\frac{1}{3}\\right)^{1} + \\frac{1}{2}\\left(\\frac{1}{3}\\right)^{2} =  1 -\\frac{1}{3} + \\frac{1}{18} = \\frac{13}{18}.\\] \\end{hint} \\end{hint} \\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "5108977b75b1aa259f3d8cc977129739bb3c7cac", "size": 9884, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "powerseries/27taylorseries2practice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "powerseries/27taylorseries2practice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "powerseries/27taylorseries2practice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.1856287425, "max_line_length": 594, "alphanum_fraction": 0.6491299069, "num_tokens": 3475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.7307779308124601}}
{"text": "\\chapter{Operations}\n\\label{ch:operations}\n%% FIXME: \\vskip -4em \\citep[chapter 2]{pinter_2016}\n\n\\begin{enumerate}[label={\\Alph*.},font={\\bfseries}]\n\\item {\\bf Examples of Operations}\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item $a * b = \\sqrt{\\abs{ab}}$ is not an operation on $\\mathbb{Q}$, because\n    $2 * 1 = \\sqrt{\\abs{2}}$, but $\\sqrt{\\abs{2}} \\not\\in \\mathbb{Q}$.\n  \\item $a * b = a \\ln b$ is not an operation on $\\mathbb{R}_{>0}$, because\n    $\\forall a,b\\in\\mathbb{R}_{>0} (b \\le 1 \\to a \\ln b \\not\\in \\mathbb{R}_{>0})$\n  \\item If $a * b$ is a root of the equation $x^2 - a^2b^2=0$,\n    $*$ is not an operation on $\\mathbb{R}$, because\n    $\\forall a,b \\in \\mathbb{R} (a \\ne 0 \\land b \\ne 0 \\to x = \\pm ab)$\n  \\item Subtraction is an operation on $\\mathbb{Z}$, because\n    $\\forall a,b \\in \\mathbb{Z} (a-b \\in \\mathbb{Z})$.\n  \\item Subtraction is not an operation on $\\mathbb{Z}_{\\ge 0}$, because\n    e.g. $0-1 \\not\\in \\mathbb{Z}_{\\ge 0}$.\n  \\item $a * b = \\abs{a-b}$ is an operation on $\\mathbb{Z}_{\\ge 0}$,\n    because $\\forall a,b \\in \\mathbb{Z}_{\\ge 0} (\\abs{a-b} \\in\n    \\mathbb{Z}_{\\ge 0})$.\n  \\end{enumerate}\n\\item {\\bf Properties of Operations}\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item $x*y=x+2y+4$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is not commutative.\n      \\begin{align*}\n        x*y &= x+2y+4 \\\\\n        y*x &= y+2x+4 \\\\\n        x*y &\\neq y*x\n      \\end{align*}\n    \\item $*$ is not associative.\n      \\begin{align*}\n        x*(y*z) &= x*(y+2z+4) \\\\\n        &= x+2(y+2z+4)+4 \\\\\n        &= x+2y+4z+12 \\\\\n        (x*y)*z &= (x+2y+4)*z \\\\\n        &= x+2y+4+2z+4 \\\\\n        &= x+2y+2z+8 \\\\\n        x+2y+4z+12 &\\neq x+2y+2z+8\n      \\end{align*}\n    \\item $\\mathbb{R}$ does not have an identity element with respect to $*$.\n      \\begin{align*}\n        x*e &= x \\\\\n        x+2e+4 &= x \\\\\n        2e+4 &= 0 \\\\\n        e &= -2 \\\\\n        e*x &= x \\\\\n        e+2x+4 &= x \\\\\n        e &= -x-4 \\neq -2\n      \\end{align*}\n    \\item Since there is no identity element, there can be no inverses.\n    \\end{enumerate}\n  \\item $x*y=x+2y-xy$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is not commutative.\n      \\begin{align*}\n        x*y &= x+2y-xy \\\\\n        y*x &= y+2x-yx \\\\\n        x*y &\\neq y*x\n      \\end{align*}\n    \\item $*$ is not associative.\n      \\begin{align*}\n        x*(y*z) &= x*(y+2z-yz) \\\\\n        &= x+2(y+2z-yz)-x(y+2z-yz) \\\\\n        &= x+2y+4z-2yz-xy-2xz+xyz \\\\\n        (x*y)*z &= (x+2y-xy)*z \\\\\n        &=(x+2y-xy)+2z-(x+2y-xy)z \\\\\n        &=x+2y+2z-2yz-xy-xz+xyz \\\\\n        x*(y*z) &\\neq (x*y)*z\n      \\end{align*}\n    \\item $\\mathbb{R}$ does not have an identity element with respect to $*$.\n      \\begin{align*}\n        x*e &= x \\\\\n        x+2e-xe &= x \\\\\n        2e-xe &= 0 \\\\\n        e(2-x) &= 0 \\\\\n        e &=0 \\\\\n        e*x &= x \\\\\n        e+2x-ex &= x \\\\\n        e+x-ex &= 0 \\\\\n        e(1-x) &= -x \\\\\n        e &= -x(1-x) \\neq 0\n      \\end{align*}\n    \\item Since there is no identity element, there can be no inverses.\n    \\end{enumerate}\n  \\item $x*y=\\abs{x+y}$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is commutative.\n      \\begin{align*}\n        x*y &= \\abs{x+y} \\\\\n        y*x &= \\abs{y+x} = \\abs{x+y} \\\\\n        x*y &= y*x\n      \\end{align*}\n    \\item $*$ is not associative.\n      \\begin{align*}\n        x*(y*z) &= x*\\abs{y+z} = \\abs{x+\\abs{y+z}} \\\\\n        (x*y)*z &= \\abs{x+y}*z = \\abs{\\abs{x+y}+z} \\\\\n        x=0,y<0 \\to x*(y*z) &= \\abs{y+z} \\\\\n        (x*y)*z &= \\abs{\\abs{y}+z} \\\\\n        y<0 \\to y \\neq \\abs{y} \\to \\abs{y+z} &\\neq \\abs{\\abs{y}+z}\\\\\n        x*(y*z) &\\neq (x*y)*z\n      \\end{align*}\n    \\item $\\mathbb{R}$ has an identity element with respect to $*$.\n      \\begin{align*}\n        x*e &= x \\\\\n        \\abs{x+e} &= x \\\\\n        e &= 0 \\\\\n        e*x &= x \\\\\n        \\abs{e+x} &= x \\\\\n        e &= 0\n      \\end{align*}\n    \\item Every $x\\in\\mathbb{R}$ has an inverse with respect to $*$.\n      \\begin{align*}\n        x*x^\\prime &= 0 \\\\\n        \\abs{x+x^\\prime} &= 0 \\\\\n        x^\\prime = -x \\\\\n        x*(-x) &= \\abs{x-x} = 0 \\\\\n        (-x)*x &= \\abs{-x+x} = 0 \\\\\n        x*x^\\prime &= x^\\prime*x\n      \\end{align*}\n    \\end{enumerate}\n  \\item $x*y=\\abs{x-y}$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is commutative.\n      \\begin{align*}\n        x*y &= \\abs{x-y} \\\\\n        y*x &= \\abs{y-x} \\\\\n        x=y \\to x*y &= 0 \\\\\n        y*x &= 0 \\\\\n      \\end{align*}\n      If $x<y$ then $x=y+k$, and:\n      \\begin{align*}\n        x*y &= \\abs{(y+k)-y} = \\abs{k} \\\\\n        y*x &= \\abs{y-(y+k)} = \\abs{-k} = \\abs{k} \\\\\n        x*y &= y*x\n      \\end{align*}\n      If $x=y$:\n      \\begin{align*}\n        x*y &= \\abs{y-y} = 0 \\\\\n        y*x &= \\abs{y-y} = 0 \\\\\n        x*y &= y*x\n      \\end{align*}\n      If $x>y$ then $y=x+k$, and:\n      \\begin{align*}\n        x*y &= \\abs{x-(x+k)} = \\abs{-k} = \\abs{k}\\\\\n        y*x &= \\abs{(x+k)-x} = \\abs{k} \\\\\n        x*y &= y*x\n      \\end{align*}\n    \\item $*$ is not associative.\n      \\begin{align*}\n        x*(y*z) &= x*\\abs{y-z} \\\\\n        &= \\abs{x-\\abs{y-z}} \\\\\n        (x*y)*z &= \\abs{x-y}*z \\\\\n        &= \\abs{\\abs{x-y}-z} \\\\\n      \\end{align*}\n      If $x=0$ and $y<0$:\n      \\begin{align*}\n        x*(y*z) = \\abs{-\\abs{y-z}} = \\abs{y-z} &= \\sqrt{(y-z)^2} \\\\\n        (x*y)*z = \\abs{\\abs{-y}-z} = \\abs{\\abs{y}-z} &= \\sqrt{(\\abs{y}-z)^2} \\\\\n        \\abs{y} &\\neq y \\\\\n        x*(y*z) &\\neq (x*y)*z\n      \\end{align*}\n    \\item $\\mathbb{R}$ does not have an identity element with respect to $*$.\n      \\begin{align*}\n        x*e &= x \\\\\n        \\abs{x-e} &= x \\\\\n        e &= 2x\n      \\end{align*}\n    \\item Since there is no identity element, there can be no inverses.\n    \\end{enumerate}\n  \\item $x*y=xy+1$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is commutative.\n      \\begin{align*}\n        x*y &= xy+1 \\\\\n        y*x &= yx+1 = xy+1 \\\\\n        x*y &= y*x\n      \\end{align*}\n    \\item $*$ is not associative.\n      \\begin{align*}\n        x*(y*z) &= x*(yz+1) \\\\\n        &= x(yz+1)+1 = xyz+x +1 \\\\\n        (x*y)*z &= (xy+1)*z \\\\\n        &= (xy+1)z+1 = xyz+z+1 \\\\\n        x*(y*z) &\\neq (x*y)*z\n      \\end{align*}\n    \\item $\\mathbb{R}$ does not have an identity element with respect to $*$.\n      \\begin{align*}\n        x*e &= x \\\\\n        xe+1 &= x \\\\\n        xe &= x-1 \\\\\n        x &= 1-\\frac{1}{x}\n      \\end{align*}\n    \\item Since there is no identity element, there can be no inverses.\n    \\end{enumerate}\n  \\item $x*y=\\text{max}\\Set{x,y}=\\text{the larger of the two numbers $x$ and $y$}$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is commutative.\n      \\begin{align*}\n        x*y &= \\text{max}\\Set{x,y} \\\\\n        y*x &= \\text{max}\\Set{y,x} = \\text{max}\\Set{x,y} \\\\\n        x*y &= y*x\n      \\end{align*}\n    \\item $*$ is associative.\n      \\begin{align*}\n        x*(y*z) &= x*\\text{max}\\Set{y,z} \\\\\n        &= \\text{max}\\Set{x,\\text{max}\\Set{y,z}} = \\text{max}\\Set{x,y,z} \\\\\n        (x*y)*z &= (\\text{max}\\Set{x,y})*z \\\\\n        &= \\text{max}\\Set{\\text{max}\\Set{x,y},z} = \\text{max}\\Set{x,y,z} \\\\\n        x*(y*z) &= (x*y)*z\n      \\end{align*}\n    \\item $\\mathbb{R}$ does not have an identity element with respect to $*$.\n      \\begin{align*}\n        x*e &= x \\\\\n        \\text{max}\\Set{x,e} &= x \\\\\n        e &= \\{ n\\in\\mathbb{R} : n \\leq x \\}\n      \\end{align*}\n    \\item Since there is no identity element, there can be no inverses.\n    \\end{enumerate}\n  \\item $x*y=\\frac{xy}{x+y+1}$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is commutative.\n      \\begin{align*}\n        x*y &= \\frac{xy}{x+y+1} \\\\\n        y*x &= \\frac{yx}{y+x+1} = \\frac{xy}{x+y+1} \\\\\n        x*y &= y*x\n      \\end{align*}\n    \\item $*$ is associative.\n      \\begin{align*}\n        x*(y*z) &= x*(\\frac{yz}{y+z+1}) \\\\\n        &= \\frac{\\frac{xyz}{y+z+1}}{x+\\frac{yz}{y+z+1}+1} \\\\\n        &= \\frac{xyz}{x(y+z+1)+yz+(y+z+1)} \\\\\n        &= \\frac{xyz}{xy+xz+yz+x+y+z+1} \\\\\n        (x*y)*z &= \\left(\\frac{xy}{x+y+1}\\right)*z \\\\\n        &= \\frac{\\frac{xyz}{x+y+1}}{\\frac{xy}{x+y+1}+z+1} \\\\\n        &= \\frac{xyz}{xy+z(x+y+1)+z+(x+y+1)} \\\\\n        &= \\frac{xyz}{xy+xz+yz+x+y+z+1} \\\\\n        x*(y*z) &= (x*y)*z\n      \\end{align*}\n    \\item $\\mathbb{R}$ does not have an identity element with respect to $*$.\n      \\begin{align*}\n        x*e &= x \\\\\n        \\frac{xe}{x+e+1} &= x \\\\\n        xe &= x(x+e+1) \\\\\n        e &= e+x+1\n      \\end{align*}\n    \\item Since there is no identity element, there can be no inverses.\n    \\end{enumerate}\n  \\end{enumerate}\n\\item {\\bf Operations on a Two-Element Set} \\\\\n  Let $A$ be the two-element set $A=\\Set{a,b}$.\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_1$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $a$ \\\\\n        $(a,b)$ & $a$ \\\\\n        $(b,a)$ & $a$ \\\\\n        $(b,b)$ & $a$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_2$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $a$ \\\\\n        $(a,b)$ & $a$ \\\\\n        $(b,a)$ & $a$ \\\\\n        $(b,b)$ & $b$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_3$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $a$ \\\\\n        $(a,b)$ & $a$ \\\\\n        $(b,a)$ & $b$ \\\\\n        $(b,b)$ & $a$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_4$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $a$ \\\\\n        $(a,b)$ & $a$ \\\\\n        $(b,a)$ & $b$ \\\\\n        $(b,b)$ & $b$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_5$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $a$ \\\\\n        $(a,b)$ & $b$ \\\\\n        $(b,a)$ & $a$ \\\\\n        $(b,b)$ & $a$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_6$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $a$ \\\\\n        $(a,b)$ & $b$ \\\\\n        $(b,a)$ & $a$ \\\\\n        $(b,b)$ & $b$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_7$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $a$ \\\\\n        $(a,b)$ & $b$ \\\\\n        $(b,a)$ & $b$ \\\\\n        $(b,b)$ & $a$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_8$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $a$ \\\\\n        $(a,b)$ & $b$ \\\\\n        $(b,a)$ & $b$ \\\\\n        $(b,b)$ & $b$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_9$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $b$ \\\\\n        $(a,b)$ & $a$ \\\\\n        $(b,a)$ & $a$ \\\\\n        $(b,b)$ & $a$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_{10}$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $b$ \\\\\n        $(a,b)$ & $a$ \\\\\n        $(b,a)$ & $a$ \\\\\n        $(b,b)$ & $b$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_{11}$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $b$ \\\\\n        $(a,b)$ & $a$ \\\\\n        $(b,a)$ & $b$ \\\\\n        $(b,b)$ & $a$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_{12}$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $b$ \\\\\n        $(a,b)$ & $a$ \\\\\n        $(b,a)$ & $b$ \\\\\n        $(b,b)$ & $b$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_{13}$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $b$ \\\\\n        $(a,b)$ & $b$ \\\\\n        $(b,a)$ & $a$ \\\\\n        $(b,b)$ & $a$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_{14}$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $b$ \\\\\n        $(a,b)$ & $b$ \\\\\n        $(b,a)$ & $a$ \\\\\n        $(b,b)$ & $b$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_{15}$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $b$ \\\\\n        $(a,b)$ & $b$ \\\\\n        $(b,a)$ & $b$ \\\\\n        $(b,b)$ & $a$\n      \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}[h]{.25\\textwidth}\n      \\captionof{table}{$0_{16}$}\n      \\begin{tabular}{ r | l }\n        $(x,y)$ & $x*y$ \\\\\n        \\hline\n        $(a,a)$ & $b$ \\\\\n        $(a,b)$ & $b$ \\\\\n        $(b,a)$ & $b$ \\\\\n        $(b,b)$ & $b$\n      \\end{tabular}\n    \\end{minipage}\n  \\item Commutativity\n    \\begin{itemize}\n    \\item $0_1$ is commutative: $a*b=a=b*a$\n    \\item $0_2$ is commutative: $a*b=a=b*a$\n    \\item $0_3$ is not commutative: $a*b=a \\neq b=b*a$\n    \\item $0_4$ is not commutative: $a*b=a \\neq b=b*a$\n    \\item $0_5$ is not commutative: $a*b=b \\neq a=b*a$\n    \\item $0_6$ is not commutative: $a*b=b \\neq a=b*a$\n    \\item $0_7$ is commutative: $a*b=b=b*a$\n    \\item $0_8$ is commutative: $a*b=b=b*a$\n    \\item $0_9$ is commutative: $a*b=a=b*a$\n    \\item $0_{10}$ is commutative: $a*b=a=b*a$\n    \\item $0_{11}$ is not commutative: $a*b=a \\neq b=b*a$\n    \\item $0_{12}$ is not commutative: $a*b=a \\neq b=b*a$\n    \\item $0_{13}$ is not commutative: $a*b=b \\neq a=b*a$\n    \\item $0_{14}$ is not commutative: $a*b=b \\neq a=b*a$\n    \\item $0_{15}$ is commutative: $a*b=b=b*a$\n    \\item $0_{16}$ is commutative: $a*b=b=b*a$\n    \\end{itemize}\n  \\item Associativity\n    \\begin{itemize}\n    \\item $0_1$ is associative:\n      $$\\forall x,y \\in A (x*y=a \\to x*(y*z)=x*a=a=a*z=(x*y)*z)$$\n    \\item $0_2$ is associative.\n      \\begin{align*}\n        a*(a*a) = a*a &= (a*a)*a \\\\\n        a*(a*b) = a*a &= a*b = (a*a)*b \\\\\n        a*(b*a) = a*a &= (a*b)*a \\\\\n        a*(b*b) = a*b &= (a*b)*b \\\\\n        b*(a*a) = b*a &= a*a = (b*a)*a \\\\\n        b*(a*b) = b*a &= a*b = (b*a)*b \\\\\n        b*(b*a) = b*a &= (b*b)*a \\\\\n        b*(b*b) = b*b &= (b*b)*b\n      \\end{align*}\n    \\item $0_3$ is not associative: $b*(a*b)=b*a=b \\neq a=b*b=(b*a)*b$\n    \\item $0_4$ is associative.\n      \\begin{align*}\n        a*(a*a) = a*a &= (a*a)*a \\\\\n        a*(a*b) = a*a &= a*b = (a*a)*b \\\\\n        a*(b*a) = a*b &= a*a = (a*b)*a \\\\\n        a*(b*b) = a*b &= (a*b)*b \\\\\n        b*(a*a) = b*a &= (b*a)*a \\\\\n        b*(a*b) = b*a &= b*b = (b*a)*b \\\\\n        b*(b*a) = b*b &= b*a = (b*b)*a \\\\\n        b*(b*b) = b*b &= (b*b)*b\n      \\end{align*}\n    \\item $0_5$ is not associative: $b*(a*b)=b*b=a \\neq b=a*b=(b*a)*b$\n    \\item $0_6$ is associative.\n      \\begin{align*}\n        a*(a*a) = a*a &= (a*a)*a\\\\\n        a*(a*b) = a*b &= (a*a)*b\\\\\n        a*(b*a) = a*a &= b*a = (a*b)*a \\\\\n        a*(b*b) = a*b &= (a*b)*b \\\\\n        b*(a*a) = b*a &= (b*a)*a \\\\\n        b*(a*b) = b*b &= (b*a)*b \\\\\n        b*(b*a) = b*a &= (b*b)*a \\\\\n        b*(b*b) = b*b &= (b*b)*b\n      \\end{align*}\n    \\item $0_7$ is associative.\n      \\begin{align*}\n        a*(a*a) = a*a &= (a*a)*a \\\\\n        a*(a*b) = a*b &= (a*a)*b \\\\\n        a*(b*a) = a*b &= b*a = (a*b)*a \\\\\n        a*(b*b) = a*a &= b*b = (a*b)*b \\\\\n        b*(a*a) = b*a &= (b*a)*a \\\\\n        b*(a*b) = b*b &= (b*a)*b \\\\\n        b*(b*a) = b*b &= a*a = (b*b)*a \\\\\n        b*(b*b) = b*a &= a*b = (b*b)*b\n      \\end{align*}\n    \\item $0_8$ is associative.\n      \\begin{align*}\n        a*(a*a) = a*a &= (a*a)*a \\\\\n        a*(a*b) = a*b &= (a*a)*b \\\\\n        a*(b*a) = a*b &= b*a = (a*b)*a \\\\\n        a*(b*b) = a*b &= b*b = (a*b)*b \\\\\n        b*(a*a) = b*a &= (b*a)*a \\\\\n        b*(a*b) = b*b &= (b*a)*b \\\\\n        b*(b*a) = b*b &= b*a = (b*b)*a \\\\\n        b*(b*b) = b*b &= (b*b)*b\n      \\end{align*}\n    \\item $0_9$ is not associative: $a*(a*b)=a*a=b \\neq a=b*b=(a*a)*b$\n    \\item $0_{10}$ is associative.\n      \\begin{align*}\n        a*(a*a) = a*b &= b*a = (a*a)*a \\\\\n        a*(a*b) = a*a &= b*b = (a*a)*b \\\\\n        a*(b*a) = a*a &= (a*b)*a \\\\\n        a*(b*b) = a*b &= (a*b)*b \\\\\n        b*(a*a) = b*b &= a*a = (b*a)*a \\\\\n        b*(a*b) = b*a &= a*b = (b*a)*b \\\\\n        b*(b*a) = b*a &= (b*b)*a \\\\\n        b*(b*b) = b*b &= (b*b)*b\n      \\end{align*}\n    \\item $0_{11}$ is not associative: $a*(a*a)=a*b=a \\neq b=b*a=(a*a)*a$\n    \\item $0_{12}$ is not associative: $a*(b*a)=a*b=a \\neq b=a*a=(a*b)*a$\n    \\item $0_{13}$ is not associative: $a*(a*a)=a*b=b \\neq a=b*a=(a*a)*a$\n    \\item $0_{14}$ is not associative: $a*(b*a)=a*a=b \\neq a=b*a=(a*b)*a$\n    \\item $0_{15}$ is not associative: $a*(a*a)=a*b=b \\neq a=b*b=(a*a)*b$\n    \\item $0_{16}$ is associative:\n      $$\\forall x,y \\in A (x*y=b \\to x*(y*z)=x*b=b=b*z=(x*y)*z)$$\n    \\end{itemize}\n  \\item Identity\n    \\begin{itemize}\n    \\item $A$ does not have an identity element with respect to $0_1$.\n    \\item $A$ has an identity element with respect to $0_2$.\n      \\begin{align*}\n        x*e &= x \\\\\n        a*b &= a \\\\\n        b*b &= b \\\\\n        e &= b \\\\\n        e*x &= x \\\\\n        b*a &= a \\\\\n        b*b &= b \\\\\n        e &= b\n      \\end{align*}\n    \\item $A$ does not have an identity element with respect to $0_3$.\n    \\item $A$ does not have an identity element with respect to $0_4$.\n    \\item $A$ does not have an identity element with respect to $0_5$.\n    \\item $A$ does not have an identity element with respect to $0_6$.\n    \\item $A$ does not have an identity element with respect to $0_7$.\n    \\item $A$ has an identity element with respect to $0_8$.\n      \\begin{align*}\n        x*e &= x \\\\\n        a*a &= a \\\\\n        b*a &= b \\\\\n        e &= a \\\\\n        e*x &= x \\\\\n        a*a &= a \\\\\n        a*b &= b \\\\\n        e &= a\n      \\end{align*}\n    \\item $A$ does not have an identity element with respect to $0_9$.\n    \\item $A$ has an identity element with respect to $0_{10}$.\n      \\begin{align*}\n        x*e &= x \\\\\n        a*b &= a \\\\\n        b*b &= b \\\\\n        e &= b \\\\\n        e*x &= x \\\\\n        b*a &= a \\\\\n        b*b &= b \\\\\n        e &= b\n      \\end{align*}\n    \\item $A$ does not have an identity element with respect to $0_{11}$.\n    \\item $A$ does not have an identity element with respect to $0_{12}$.\n    \\item $A$ does not have an identity element with respect to $0_{13}$.\n    \\item $A$ does not have an identity element with respect to $0_{14}$.\n    \\item $A$ does not have an identity element with respect to $0_{15}$.\n    \\item $A$ does not have an identity element with respect to $0_{16}$.\n    \\end{itemize}\n  \\item Since $A$ only has identity elements with respect to $0_2$, $0_8$,\n    and $0_{10}$, the rest cannot have inverses. As it turns out, with\n    respect to those three operations, it is not the case that every $x \\in\n    A$ has an inverse.\n  \\end{enumerate}\n\\item {\\bf Automata: The Algebra of Input/Output Sequences} \\\\\n  Let $A$ be an alphabet and $A^*$ be the set of all sequences of symbols in the alphabet $A$. There is an operation on $A^*$ called {\\em concatenation}: If {\\bf a} and {\\bf b} are in $A^*$, say $\\textbf{a} = a_1a_2...a_n$ and $\\textbf{b} = b_1b_2...b_m$, then $$\\textbf{ab} = a_1a_2...a_nb_1b_2...b_m$$\n  The symbol $\\lambda$ denotes the empty sequence.\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item Concatenation is associative.\n    %% $$a = a_1a_2...a_n; b = b_1b_2...b_m; c = c_1c_2...c_k$$\n    \\begin{align*}\n      a(bc) &= a(b_1b_2...b_mc_1c_2...c_k) = a_1a_2...a_nb_1b_2...b_mc_1c_2...c_k \\\\\n      (ab)c &= (a_1a_2...a_nb_1b_2...b_m)c = a_1a_2...a_nb_1b_2...b_mc_1c_2...c_k \\\\\n      a(bc) &= (ab)c\n    \\end{align*}\n  \\item Concatenation is not commutative.\n    %% $$a = a_1a_2...a_n; b = b_1b_2...b_m$$\n    \\begin{align*}\n      ab &= a_1a_2...a_nb_1b_2...b_m \\\\\n      ba &= b_1b_2...b_ma_1a_2...a_n \\\\\n      ab &\\neq ba\n    \\end{align*}\n  \\item $\\lambda$ is the identity element for concatenation:\n    $x\\lambda = \\lambda{}x = x$\n  \\end{enumerate}\n\\end{enumerate}\n", "meta": {"hexsha": "5f3de93d57aadacdc47b6117d502cd65614033cd", "size": 20245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/ch2.tex", "max_stars_repo_name": "yurrriq/abstract-algebra-pinter", "max_stars_repo_head_hexsha": "58eed44088f29e2ddae9d7782f603562c04b0e37", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-09-24T23:35:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-08T20:26:03.000Z", "max_issues_repo_path": "src/ch2.tex", "max_issues_repo_name": "yurrriq/abstract-algebra-pinter", "max_issues_repo_head_hexsha": "58eed44088f29e2ddae9d7782f603562c04b0e37", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-01T07:16:00.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-19T06:01:56.000Z", "max_forks_repo_path": "src/ch2.tex", "max_forks_repo_name": "yurrriq/abstract-algebra-pinter", "max_forks_repo_head_hexsha": "58eed44088f29e2ddae9d7782f603562c04b0e37", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-24T23:35:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-24T23:35:51.000Z", "avg_line_length": 33.2976973684, "max_line_length": 303, "alphanum_fraction": 0.4369473944, "num_tokens": 7893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7307278186924714}}
{"text": "\\section{Statistic: Statistics}\n\\subsection*{describe}\nThis analysis follows from NR92, pp 610--613.  However, the basic definitions\nare common to all statistics books.  The key insight from NR92 (and not\noriginal there), is the 2-pass corrected calculation of variance.\n\nTo rehearse the equations:\n\\begin{eqnarray}\n  \\mbox{mean} & = & \\mbox{avg} = \\overline{x} = \n                    \\frac{1}{N}\\sum_{j=1}^{N}x_j\\\\\n  \\mbox{avg dev} & = & \\frac{1}{N}\\sum_{j=1}^{N}|x_j-\\overline{x}|\\\\\n  \\mbox{var} & = & \\frac{1}{N}\\left [ \\sum_{j=1}^{N}(x_j-\\overline{x})^2\n                   - \\frac{1}{N} \\left [ \\sum_{j=1}^{N}(x_j\n                       -\\overline{x})\\right]^2\\right]\\\\\n  \\mbox{std dev} & =& \\sigma  =  \\sqrt{\\mbox{var}}\\\\\n  \\mbox{skew} & = & \\frac{1}{N}\\sum_{j=1}^{N} \n                    \\left [\\frac{x_j-\\overline{x}}{\\sigma}\\right]^3\\\\\n  \\mbox{kurt} & = & \\left\\{\\frac{1}{N}\\sum_{j=1}^{N} \n                    \\left [\\frac{x_j-\\overline{x}}{\\sigma}\\right]^4\n                    \\right\\} - 3\n\\end{eqnarray}\nWe also pick up min and max values during the first pass.\n\n\\subsection*{ttest}\nThis is Student's t-test.  The idea is to find if the means of \ntwo samples are the same and how likely that is to be due to chance.\n\nAgain, we follow NR92, pg 616, but the formula\nis common:\n\\begin{eqnarray}\ns_D & =  & \\sqrt{\\frac{\\sum_{i\\in A}(x_i-\\overline{x_A})^2 \n                      +\\sum_{i\\in B}(x_i-\\overline{x_B})^2}\n                      {N_A+N_B-2}\n                 \\left(\\frac{1}{N_A}+\\frac{1}{N_B}\\right)\n                }\\\\\nt & = & \\frac{\\overline{x_A}-\\overline{x_B}}{s_D}\n\\end{eqnarray}\n\nThere are a number of ways \nto compute the probability that this was due to chance.  Following\nNR92, we use:\n\\begin{eqnarray}\n    I_x(a,b) & = & \\mbox{incomplete Beta function} \n               = \\frac{B_x(a,b)}{B(a,b)}\n               = \\frac{1}{B(a,b)}\\int_0^xt^{a-1}(1-t)^{b-1}dt\\\\\n    \\nu & = & \\mbox{degrees of freedom}\\\\\n    A(t|\\nu) & = & \\mbox{probability that t could be that small by chance}\\\\\n             & = & 1- I_{\\frac{\\nu}{\\nu_t^2}}(\\frac{\\nu}{2},\\frac{1}{2})\n\\end{eqnarray}\n\n\\subsection*{ftest}\nThis is the F-test.  The idea is to find if the variances of two\nsamples are the same, and how likely that is to be due to chance.\n\\begin{equation}\n F = \\mbox{var1} / \\mbox{var2}\n\\end{equation}\nvar1 and var2 are chosen so the ratio comes out  $>1$.  There are a number of ways \nto compute the probability that this was due to chance.  Following\nNR92, we use:\n\\begin{eqnarray}\n    \\nu_1,\\nu_2 & = & \\mbox{degrees of freedom}\\\\\n    Q(F|\\nu_1,\\nu_2) & = & \\mbox{probability that F could be that small by chance}\\\\\n             & = & I_{\\frac{\\nu_2}{\\nu_2+\\nu_1F}}\n                     (\\frac{\\nu_2}{2},\\frac{\\nu_1}{2})\n\\end{eqnarray}\n\n\n\\subsection*{chi\\_sqr1}\n$\\chi^2$ tests whether or not a binned distribution is as expected.\nNR92 (pg 621, eqn 14.3.1 and pg 221, eqn 6.2.19) gives:\n\\begin{eqnarray}\n  N_i & = & \\mbox{number of items in bin i}\\\\\n  n_i & = & \\mbox{number of items expected in bin i}\\\\\n  \\chi^2 & = & \\sum_i\\frac{(N_i-n_i)^2}{n_i}\\\\\n  Q(\\chi^2|\\nu) & = & Q(\\frac{\\nu}{2},\\frac{\\chi^2}{2})\n         = \\mbox{incomplete gamma function P}\n\\end{eqnarray}\n\nKrey88, pg 1280 says the bins should have $\\ge 5$ items each.  We'll\nraise an exception if that is not met.\n\n\\subsection*{chi\\_sqr2}\nThis version of $\\chi^2$ checks similarlity between two actual\ncollecitons of bins (not just an actual and an expected).\nNR92, pg 622, give sthe equaiton eqn 14.3.2:\n\\begin{eqnarray}\n  R_i & = & \\mbox{number of items in R's bin i}\\\\\n  S_i & = & \\mbox{number of items in S's bin i}\\\\\n  \\chi^2 & = & \\sum_i\\frac{(R_i-S_i)^2}{R_i+S_i}\\\\\n  Q(\\chi^2|\\nu) & = & Q(\\frac{\\nu}{2},\\frac{\\chi^2}{2})\n         = \\mbox{incomplete gamma function P}\n\\end{eqnarray}\n\n", "meta": {"hexsha": "9c9f9505221550409547afbb656306d6980a9da6", "size": 3760, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "m3-libs/arithmetic/doc/statistic.tex", "max_stars_repo_name": "jaykrell/cm3", "max_stars_repo_head_hexsha": "2aae7d9342b8e26680f6419f9296450fae8cbd4b", "max_stars_repo_licenses": ["BSD-4-Clause-UC", "BSD-4-Clause", "BSD-3-Clause"], "max_stars_count": 105, "max_stars_repo_stars_event_min_datetime": "2015-03-02T16:58:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T07:17:49.000Z", "max_issues_repo_path": "m3-libs/arithmetic/doc/statistic.tex", "max_issues_repo_name": "jaykrell/cm3", "max_issues_repo_head_hexsha": "2aae7d9342b8e26680f6419f9296450fae8cbd4b", "max_issues_repo_licenses": ["BSD-4-Clause-UC", "BSD-4-Clause", "BSD-3-Clause"], "max_issues_count": 145, "max_issues_repo_issues_event_min_datetime": "2015-03-18T10:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T01:27:08.000Z", "max_forks_repo_path": "m3-libs/arithmetic/doc/statistic.tex", "max_forks_repo_name": "jaykrell/cm3", "max_forks_repo_head_hexsha": "2aae7d9342b8e26680f6419f9296450fae8cbd4b", "max_forks_repo_licenses": ["BSD-4-Clause-UC", "BSD-4-Clause", "BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-10T09:37:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T02:02:05.000Z", "avg_line_length": 40.0, "max_line_length": 84, "alphanum_fraction": 0.5944148936, "num_tokens": 1365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.7307278167658741}}
{"text": "\\subsection{Motivation}\nThe paradigmatic problem of Fast Multipole Methods (\\textbf{\\gls{FMM}})\n\\footnote{The first usage of a technical term or abbreviation listed in the\nglossary is highlighted throughout the text for ease of reference.} is the so\ncalled $N$-Body problem. This classic problem refers to the calculation of the pairwise\ninteractions between $N$ particles over a potentially long-range, for example in\ngravitational or electrostatic problems. The straightforward calculation can be\nwritten in the form of the following sum,\n\n\\begin{equation}\n\\Phi(x_j) = \\sum_{i=1}^N w_i K(x_i, x_j)\n\\label{eq:n_body_problem}\n\\end{equation}\n\nWhere $i, j \\in [1,N]$ and $K(x, y)$ is called the Green's function, or equivalently\na `kernel function', where one is generally concerned with coordinates of particles in an\n$n=2 \\> \\> \\text{or} \\> \\> 3$ dimensional Hilbert space taking  $\\ x_i \\in \\mathbb{R}^n$.\nAdditionally, each summand is weighted by $w_i$. For solving for electrostatic\npotential in three dimensions, which is used as the model problem throughout this\nthesis, this goes to,\n\n\\begin{equation}\n\\Phi(x_j) = \\sum_{i=1}^N q_iK(x_i, x_j)\n\\label{eq:electrostatic_paradigm}\n\\end{equation}\n\nwhere $q_i$ refers to a charge density with the kernel function,\n\n\\begin{equation}\n    K(x, y) = \\frac{1}{4\\pi \\epsilon_0}\\frac{1}{| x - y |}\n\\label{eq:laplace_kernel}\n\\end{equation}\n\nthe constant $\\epsilon_0$ is the permittivity of free space. For practical\npurposes, we define $K(x,x) = 0$. It's easy to see\nhow a naive direct application of this equation over $N$ particles\nresults in an algorithm of $O(N^2)$ complexity, therefore it's only practicable\nfor systems of moderate size, whereas in realistic systems, one may be interested in\ninteractions involving $10^{6}$ to $10^8$ particles.\n\nThis chapter introduces the analytic \\gls{FMM}, the kernel-independent\nversion, which is the main focus of this thesis, is presented later.\nThough substantially different in implementation, the analytic FMM will provide the opportunity\nto exposit many of the key ideas behind all FMM-based algorithms, and provides\na good starting point for understanding and developing upon these algorithms.\nFirst presented by Greengard \\cite{Greengard:1987:JCP},\nthe analytic \\gls{FMM} represented a sea change for $N$-Body simulation. By\ntrading off computations for error, it manages to achieve an asymptotic complexity\n of just $O(N)$. Additionally, it comes equipped with rigorous error bounds,\nmaking fast and accurate massive $N$-Body simulations feasible on available\ncomputing hardware. It's success has been such that it is regarded as one of\nthe key developments in numerical algorithms in the twentieth century \\cite{Cipra:2000:SN}.\n\nThe original analytic FMM solves the electrostatic problem\nin two and three dimensions, this is equivalently known as the Poisson problem,\nrepresented by the differential equation,\n\n\\begin{equation}\n    \\nabla^2 \\phi =f\n\\label{eq:poisson}\n\\end{equation}\n\nWhere $\\phi$ is some scalar potential to be determined, and $f$ is a scalar source\nterm which is usually known. For electrostatics the corresponding formulation\ncan be derived from Gauss' law as \\cite{Griffiths:2017:CUP},\n\n\\begin{equation}\n  \\nabla^2 \\phi = - \\frac{q}{\\epsilon_0}\n\\label{eq:electrostatic_poisson}\n\\end{equation}\n\nwhere $\\phi$ is the electrostatic potential, $q$ is the charge density and\n$\\epsilon_0$ is the permittivity of free space. It can therefore be seen that\nthe \\gls{FMM} is actually solving the Poisson problem by reformulating it as an\nintegral equation \\cite{Epton:1995:SIAM}. The ubiquity of problems of the form (\\ref{eq:n_body_problem})\nin computational science has lead to diverse applications of the FMM. For example,\nin the modeling the electrostatic interactions of charged particles in complex\nbiological molecules at biologically relevant length scales \\cite{Board:1992:CPL}.\nThe extension of FMMs to Helmholtz equations \\cite{Rokhlin:1990:JCP}, has lead\nto even more applications, such as in seismic and acoustic scattering\n\\cite{Hwu:2011:MKP}. Though as the focus of this thesis is on solving the Poisson\nmodel problem for electrostatics, this is mentioned only for completeness.\n\nThe key insight that leads to the \\gls{FMM}'s asymptotic complexity is the idea\nthat if the field created by a distribution of charge (or mass) density is approximated\nto be relatively smooth in the \\textbf{\\gls{far-field}}, then it should be possible to apply\nsome form of compression for the evaluation of contribution to local potentials due\nto particles in the \\gls{far-field}. The FMM performs this compression by encoding\nthe field contributions of particles in the \\gls{far-field} using a multipole\nexpansion.\n\nFor simple kernel functions and charge distributions, such as the model problem\nof this thesis, one can easily derive the expression for this multipole expansion\nby finding an series expansion of the system's Green's function.\nIn order to generalise the discussion, an arbitrary continuous\ndistribution of charge is considered as shown in figure \\ref{fig:1_1_continuous_charge_distribution},\nfor which the potential is evaluated at some other evaluation point outside of\nthe distribution. This can be written as follows \\cite{Griffiths:2017:CUP},\n\n\\begin{flalign}\n    \\Phi(\\mathbf{r}) = \\frac{1}{4 \\pi \\epsilon_0} \\int \\frac{1}{d}\\rho(\\mathbf{r}')d\\tau'\n    \\label{eq:1_1_continuous_integral_formulation}\n\\end{flalign}\n\nwhere $\\rho(\\mathbf{r}')$ is a charge density, and the other symbols take their\nmeanings from figure (\\ref{fig:1_1_continuous_charge_distribution}).\n\n\n\\begin{figure}[!h]\n    \\centering\n    {\\includegraphics[width=0.45\\textwidth]{introduction/continuous_charge.png}}\n  \\vspace{0pt}\n  \\caption{An arbitrary charge distribution, with an orange point to mark a point\n  where the potential is being evaluated. Here, $\\mathbf{r}$ is the the vector\n  between the centre of the multipole expansion and the evaluation point, $\\mathbf{r}'$\n  is the vector between the centre of expansion and a given volume element $d\\tau'$, and\n  $d$ is a vector between the volume element $d\\tau'$ and the evaluation point.}\n  \\label{fig:1_1_continuous_charge_distribution}\n\\end{figure}\n\nFrom law of the cosines,\n\n\\begin{flalign}\n    d^2 &= r^2 + (r')^2 - 2rr'\\cos \\alpha = r^2 \\left [ 1 + \\left ( \\frac{r'}{r} \\right)^2 - 2 \\left (\\frac{r'}{r} \\right)\\cos \\alpha \\right]\\\\\n    d &= r \\sqrt{1+\\epsilon},\n    \\label{eq:1_1_law_of_cosines}\n\\end{flalign}\n\nwhere,\n\n\\begin{flalign}\n    \\epsilon \\equiv \\left ( \\frac{r'}{r} \\right) \\left (\\frac{r'}{r} - 2 \\cos \\alpha \\right)\n\\end{flalign}\n\nAs $\\epsilon$ is small far away from charge distribution one can expand $1/d$ binomially,\n\n\\begin{flalign}\n    \\frac{1}{d} &= \\frac{1}{r}(1+\\epsilon)^{-1/2} = \\frac{1}{r}\\left (1 - \\frac{1}{2}\\epsilon + \\frac{3}{8}\\epsilon^2 - ... \\right) \\\\\n    \\frac{1}{d} &= \\frac{1}{r} \\sum_{n=0}^{\\infty} \\left(\\frac{r'}{r} \\right)^n P_n(\\cos \\alpha),\n\\end{flalign}\n\nwhere $P_n(\\cos \\alpha)$ are Legendre polynomials. Using this, the exact multipole\nexpansion for this charge distribution is,\n\n\\begin{flalign}\n    \\Phi(\\mathbf{r}) = \\frac{1}{4 \\pi \\epsilon_0}\\sum_{n=0}^{\\infty}\\frac{1}{r^{n+1}}\\int (r')^nP_n(\\cos \\alpha)\\rho(\\mathbf{r'}) d \\tau'\n\\end{flalign}\n\nIf instead one considers a charge distribution composed of $N$ discrete charges\n$q_i$ at positions $r_i$, this goes to,\n\n\\begin{flalign}\n    \\Phi(\\mathbf{r}) = \\frac{1}{4 \\pi \\epsilon_0}\\sum_{i=1}^N\\sum_{n=0}^{\\infty}\\frac{(r_i)^n q_i}{r^{n+1}}P_n(\\cos \\alpha)\n\\end{flalign}\n\nUsing the addition theorem for Legendre polynomials \\cite{Greengard:1987:Yale},\n\n\\begin{flalign}\n    P_n(\\cos \\gamma) = \\sum_{m=-n}^n Y_n^{-m}(\\alpha, \\beta) Y_n^m(\\theta, \\phi),\n\\end{flalign}\n\nwhere the Legendre polynomial is written in terms of spherical harmonics,\nwhere $(r, \\theta, \\phi)$ and $(\\rho, \\alpha, \\beta)$ define two spherical coordinates,\nand $\\gamma$ is the angle subtended between them. The multipole expansion goes to,\n\n\\begin{flalign}\n    \\Phi(\\mathbf{r}) &= \\frac{1}{4 \\pi \\epsilon_0}\\sum_{i=1}^N\\sum_{n=0}^{\\infty}\\frac{(r_i)^n q_i}{r^{n+1}}P_n(\\cos \\alpha)\\\\\n    & = \\frac{1}{4 \\pi \\epsilon_0}\\sum_{i=1}^N\\sum_{n=0}^{\\infty}\\sum_{m=-n}^n \\frac{(r_i)^n q_i Y_n^{-m}(\\alpha_i, \\beta_i) }{r^{n+1}}Y_n^m(\\theta, \\phi)\\\\\n    & = \\frac{1}{4 \\pi \\epsilon_0}\\sum_{n=0}^{\\infty}\\sum_{m=-n}^n M_n^m \\cdot \\frac{Y_n^m(\\theta, \\phi)}{r^{n+1}}  ,\n    \\label{eq:1_1_multipole_expansion}\n\\end{flalign}\n\nwhere,\n\n\\begin{equation}\n    M_n^m = \\sum_{i=1}^N (r_i)^n q_i Y_n^{-m}(\\alpha_i, \\beta_i)\n\\end{equation}\n\nThis is an exact expansion, and it converges for $\\frac{r_i}{r} < 1$. This convergence\ncondition means that estimating the potential at a given evaluation point\nusing the multipole expansion is only possible in the far-field, the\nboundary of which is often tuned empirically for different systems as it's user\ndefined. If instead the expansion is taken centered at the evaluation point,\none can rewrite as the multipole expansion as a `local' expansion,\n\n\\begin{flalign}\n    \\Phi(\\mathbf{r}) & = \\frac{1}{4 \\pi \\epsilon_0}\\sum_{i=1}^N\\sum_{n=0}^{\\infty}\\sum_{m=-n}^n \\frac{(r)^n q_i Y_n^{-m}(\\alpha_i, \\beta_i) }{(r_i)^{n+1}}Y_n^m(\\theta, \\phi)\\\\\n    & = \\frac{1}{4 \\pi \\epsilon_0} \\sum_{n=0}^{\\infty} \\sum_{m=-n}^n L_n^m \\cdot  Y_n^m(\\theta, \\phi) \\cdot r^n,\n    \\label{eq:1_1_local_expansion}\n\\end{flalign}\n\nwhere,\n\n\\begin{equation}\n    L^m_n = \\sum_{i=1}^N \\frac{q_i Y^{-m}_n(\\alpha_i, \\beta_i)}{(r_i)^{n+1}},\n\\end{equation}\n\nwhich converges when $\\frac{r}{r_i} < 1$. The region of convergence for both types\nof expansions are shown in figure (\\ref{fig:1_1_multipole_local_expansions}).\n\nThe key point to note is that the multipole and local expansions are exact, and\ncan be truncated as required to ensure that the asymptotic complexity of evaluating\na multipole or local expansion at an evaluation point is bounded by $O(N)$. A\nrigorous error analysis of the analytic FMM is outside the scope of this thesis, and\nwe defer to the literature for exact expressions for these truncation errors \\cite{Greengard:1987:JCP},\nFurthermore, there exist exact operations for shifting the center of these expansions,\nas well as for translating multipole expansion coefficients into equivalent local expansion\ncoefficients. These are crucial in providing the improvements to asymptotic complexity\\footnote{\n    Expressions for these shift operators for the three dimensional Laplace kernel\n    considered as our model problem are provided in Appendix \\ref{app:3d_laplace}.\n}.\n\n\\begin{figure}[!h]\n    \\centering\n    {\\includegraphics[width=0.33\\textwidth]{introduction/multipole_expansion.png}}\n    \\hfill\n  {\\includegraphics[width=0.4\\textwidth]{introduction/local_expansion.png}}\n  \\vspace{0pt}\n  \\caption{(A) A multipole expansion centered on charge distribution. (B) A local\n  expansion, centered around a point of evaluation. Regions in which the expansions\n  converge are shaded in grey. For the multipole expansion this is the entire domain\n  outside of the region for $r>r_i, \\> \\forall i \\in [1, N]$, and for the local expansion this is the region\n  for which $r < r_i, \\>  \\forall i \\in [1, N]$}\n\n  \\label{fig:1_1_multipole_local_expansions}\n\\end{figure}\n\n\\hspace{10pt}\n\n\\subsection{Algorithm Structure \\& Analysis}\n\nThe convergence condition of the multipole expansion prohibits the compression\nof charges from particles in the \\textbf{\\gls{near-field}}. Therefore the FMM\nmakes use of a tree structure in a recursive algorithm, this structure is known\nas an Octree in three dimensions and a Quadtree in two dimensions\\footnote{The usage\nof trees naturally leads to biological adjectives to describe their structure, for example\nthe coarsest level of a tree is referred to as the `root' level, and the finest\nlevel as the `leaf' level. Confusingly these are often combined with familial adjectives\nto describe the relationship between tree nodes, for example parent and child nodes to describe\nthe relationship between a given node and the nodes that occupy the same domain\na level deeper in the tree. Each node has exactly one parent, except the root node which\nhas no parents.}. This structure\nhierarchically partitions space such that each level, $l$, of the tree is equally partioned into\n$(2^d)^l$ boxes\\footnote{Regardless of the spatial dimension, partitions of a domain are invariably\nreferred to as boxes.} over the domain of the tree, where $d$ is the dimension,\ni.e. $d=3$ in three dimensions. If one were to simply traverse the tree from\nthe coarsest, or `root', level to the finest, or `leaf', level and find the multipole expansion of source\nparticles in each box of each level, one could then evaluate these multipole expansions\nat each particle to solve the $N$-Body problem. As there are $O(\\log(N))$\nboxes in the tree, and $N$ particles, this results in a $O(N\\log(N))$ asymptotic\ncomplexity.\n\nHowever the FMM reduces computational complexity further by making use of local\nexpansions. Using the exact expressions to shift the multipole expansion\ncoefficients\\footnote{Expressions for these shift operators for the three dimensional\nLaplace kernel considered as our model problem are provided in Appendix \\ref{app:3d_laplace}.}\n$M_n^m$ to local expansion coefficients $L_n^m$ one can approximate the the interaction\nbetween two boxes in the tree. Roughly speaking, because of the hierarchical\nnature of the tree, each box only needs to consider the interaction with a\nconstant number of neighbouring boxes. Because the number of boxes is $O(N)$,\nthe FMM is bound by an $O(N)$ asymptotic complexity \\cite{Hwu:2011:MKP}.\n\nUsing the above analysis, one can then describe the FMM algorithm in terms of\ntwo basic steps,\n\n\\begin{enumerate}\n    \\item \\textbf{\\textit{Upward Pass}}: The tree is traversed \\textbf{\\gls{post-order}}.\n    Beginning at the leaf boxes, a multipole expansion is computed for each box\n    due to the \\textbf{\\gls{source-particles}} it contains. This is also referred to as the particle-to-multipole\n    operation, or \\textbf{\\gls{P2M}}. Then as one moves up the tree hierarchy, the\n    multipole expansions of a each box's parent box is computed by shifting the\n    expansion centers of the multipole expansion of a given child box, to the center\n    of the parent box, in a multipole-to-multipole operation or \\textbf{\\gls{M2M}},\n    and summing together all the coefficients. Following the upward pass, one\n    obtains the multipole expansion for each box containing source particles at\n    all levels of the hierarchical tree.\n    \\item \\textbf{\\textit{Downward Pass}}: The tree is now traversed in\n    \\textbf{\\gls{pre-order}}, and the local expansion of each box is computed.\n    This local expansion is the sum of two parts: (1) the local expansion of the\n    parent box of a given box, if it exists, which is a compression of the potential due to boxes\n    non-adjacent to a given box's parent. The parent box's local expansion centre\n    is shifted to the center of the child box, this is also known as the local-to-local\n    operation or \\textbf{\\gls{L2L}}. (2) The multipole expansion of boxes which\n    are the children of the \\textbf{\\gls{near-neighbours}} of a given box's\n    parent but are not adjacent to the box itself. Such `source' boxes are described\n    as being in the \\textbf{\\gls{interaction-list}} of a given box. These multipole\n    expansions for each source box in a given box's interaction list are translated into local expansions centered at\n    the given box, this is also known as\n    the multipole-to-local operation, or \\textbf{\\gls{M2L}}. Notice that the\n    \\gls{M2L} operation is only available from $l=2$ of the tree, as in coarser\n    levels the \\gls{interaction-list} for all boxes is empty. The coefficients found\n    from (1) and (2) are summed for each box. Operations (1) and (2) are repeated for each\n    box until the leaf level. At this point, the local expansion\n    of each leaf box is evaluated at all the \\textbf{\\gls{target-particles}} it contains.\n    This local-to-particle, or \\textbf{\\gls{L2P}}, operation encodes all the \\gls{far-field}\n    interaction of the target particles in this leaf box. This is then combined with\n    a \\gls{near-field} interaction, due to the source particles in the leaf box,\n    as well as in the \\gls{near-neighbours}, which are computed directly. As the\n    tree is refined to the point where the leaf levels contain only a small constant\n    number of particles, this final direct computation is of low cost.\n\\end{enumerate}\n\n\nWith this specification, a more detailed analysis of the algorithm is possible,\nthough we defer to \\cite{Greengard:1987:JCP} for a rigorous discussion.\nFirstly, as mentioned above, the tree must be refined such that the leaf boxes\ncontain only a small constant number of particles, $\\kappa$. The level of refinement $n$\nis therefore approximately taken to be $n \\approx \\log(N)$, where $N$ is the number\nof \\gls{source-particles} in the tree. Beginning with upward pass, at the leaf level each particle contributes to one\nmultipole expansion. If this expansion is truncated to contain $p$ multipole terms, the\n\\gls{P2M} operation has a complexity of $O(Np^2)$, which can be seen from\n(\\ref{eq:1_1_multipole_expansion}), as well as the fact that the nature of a\nhierarchical tree means that are $O(N)$ boxes at the leaf level. The shift operators\\footnote{\n    Expressions for these shift operators for the three dimensional Laplace kernel\n    considered as our model problem are provided in Appendix \\ref{app:3d_laplace}\n} \\gls{M2L}, \\gls{L2L} and \\gls{M2M} require $p^4$ operations with this truncation,\nso the computation of all of these are bounded by\\footnote{A more precise\nbound depends on the size of a given box's \\gls{interaction-list}.} $O(Np^4)$. Finally,\nevaluating the $p^{th}$ degree local expansions at each target particle in the\n\\gls{L2P} operation, is bounded by $O(Np^2)$. The choice for level of refinement\n$n$, leads to $O(\\kappa N)$ complexity for direct calculations at the\nleaf level. The whole algorithm is therefore bounded by $O(N)$.\nIn practice, the number of expansion terms $p$ is chosen for a prescribed relative error $\\epsilon$, using\n\\footnote{There are optimal choices for $c$, with the authors of \\cite{Ying:2004:JCP}\nspecifying $c=\\frac{4-\\sqrt{3}}{\\sqrt{3}}$ for three dimensional problems.}\n$p=\\log_c \\epsilon$. The algorithm is illustrated in figure (\\ref{fig:1_1_main_loop})\nin the two dimensional case, which is direct analogue of the three dimensional case\nwhich is the focus of this thesis, and a full pseudo-code specification is\nprovided in Appendix \\ref{app:analytic_fmm}.\n\n\\begin{figure}[!h]\n    \\centering\n    {\\includegraphics[width=1.1\\textwidth]{introduction/main_loop.png}}\n  \\caption{\n      The main FMM loop in two dimensions, encapsulating the upward and downward\n      pass. The same set of particles are used for the sources and targets, and\n      are shown in green. Local expansions are illustrated with red stars, and\n      multipole expansions are illustrated with blue stars. For the P2M step the\n      grey region indicates the \\gls{near-field}, where this multipole expansion\n      does not converge. For the M2L and P2P steps the grey region indicates\n      box interactions already compressed and available via the translation or\n      direct usage of local expansions. The larger and smaller stars in the M2M and\n      L2L steps correspond to the parent and child expansions respectively.\n  }\n  \\label{fig:1_1_main_loop}\n\\end{figure}\n\n\\subsection{Summary}\n\nThe main practical challenge in implementing software to solve the analytic FMM\nis the requirement of kernel-specific code to calculate the expansion coefficients of\n(\\ref{eq:1_1_multipole_expansion}) and (\\ref{eq:1_1_local_expansion}). For example,\nmultiple different implementations already exist for Poison problems alone \\cite{Greengard:1996:JCP, Etheridge:2001:SIAM}.\nIn software engineering terms this is inconvenient for the purposes of studying\nthe applications of the FMM in multiple different problem settings, as it leads to the requirement\nto implement problem-specific solvers for each kernel one may encounter. This\nleads to a productivity overhead in either creating a single, extensible\nlibrary, which by definition will be complex to design. Or to otherwise\nmaintain multiple problem-specific libraries.\n\nThe algorithm thus far described referred to as the analytic FMM is more correctly\ncalled the non-adaptive analytic FMM. The non-adaptivity refers to the assumption that\nall boxes at the leaf level are refined to the same degree, however as mentioned\nin the above analysis of the algorithm, the degree of refinement is chosen such\nthat the number of particles in a leaf box is \\textit{constant}. Therefore, If\nthe distribution of the particles of interest is not uniform over the computational\ndomain, one may be needlessly refining the boxes in some regions which may even be\nempty. Therefore, although the asymptotic complexity of\nthe FMM is $O(N)$, it is clear that practical implementations will suffer unless\ncare is taken to use efficient vectorised data structures for the creation of an\nappropriate hierarchical tree as required by the algorithm.\n\nAdditionally, there is significant scope for multiple levels of\nparallelism in practical implementations. For example, the computations\nfor the local and multipole coefficients as well as the application of M2L, L2L\nand M2M operators at a given level, are candidates for an implementation of\n\\textbf{\\gls{task-level-parallelism}}. In addition to parallelising of each operator\napplication as a task, there is scope for implementing\n\\textbf{\\gls{data-level-parallelism}} to find the expansion coefficients. For example,\nYokota and Barba \\cite{Hwu:2011:MKP} demonstrate how the calculation of the P2P,\nand M2L operators can be transferred to \\textbf{\\gls{GPU}}s using \\textbf{\\gls{CUDA}}.\nThe M2L, and P2P operators represent the largest computational bottlenecks due to\nthe number of such interactions in the FMM algorithm, therefore are a priority for\nacceleration. For example, in three dimensions each target box has potentially\nup to 189 source boxes in its \\gls{interaction-list} with which to compute the\nM2L operation, and for any particularly deep tree there will be roughly $O(N)$\nleaf boxes, for which interactions are calculated directly. This leads to both of\nthese operations dominating the run-time of any \\gls{FMM} implementation.\n\nIn summary, the implementation of the analytical FMM is complicated by the\nfact that it is problem specific - which will also apply to any parallel\noptimisation code. This in itself provides the main motivation for developing\nan implementation that does not rely on explicit kernel expansions. Furthermore,\nthe desire for developer productivity, at the expense of hyper-optimised\nimplementations, is realised in this thesis by making use of Python,\na \\textbf{\\gls{high-level-interpreted-language}}, for our software implementation.\n", "meta": {"hexsha": "3d200dff27f3540a8aec66dc941fdac84f34036f", "size": 22978, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/introduction/fmm_overview.tex", "max_stars_repo_name": "skailasa/msc_thesis", "max_stars_repo_head_hexsha": "c9cad2703b6263e82fa32b025c8c3ab942367fd6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/introduction/fmm_overview.tex", "max_issues_repo_name": "skailasa/msc_thesis", "max_issues_repo_head_hexsha": "c9cad2703b6263e82fa32b025c8c3ab942367fd6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/introduction/fmm_overview.tex", "max_forks_repo_name": "skailasa/msc_thesis", "max_forks_repo_head_hexsha": "c9cad2703b6263e82fa32b025c8c3ab942367fd6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.879093199, "max_line_length": 175, "alphanum_fraction": 0.7597266951, "num_tokens": 6167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475762847495, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7307013531736125}}
{"text": "\\chapter{The Informal Notions of Algorithms}\n\n\\emph{“形式语言与自动机课程速成。”}\n\n\\section{Algorithms}\n\n\\begin{definition}[Algorithms (Informal)]\n    \\label{def:Algorithm}\n    An algorithm is a \\textbf{finite ordered list} of instructions.\n\\end{definition}\n\nPossible outcomes of running an algorithm\n\\begin{itemize}\n    \\item The algorithm does not halt\n    \\item The algorithm halts\n    \\begin{itemize}\n        \\item In an erroneous state (fails)\n        \\item Gives valid outputs\n    \\end{itemize}\n\\end{itemize}\nCases other than the algorithm giving valid outputs are collectively identified as ``no output''.\n\n\\subsection{Algorithms for Determining Membership}\n\\label{sub:AlgoForDeterminingMembership}\n\n\\begin{definition}[Algorithms for Determining Membership]\n    \\label{def:AlgoForDeterminingMembership}\n    An algorithm for \\emph{determining membership} in a set $A \\subseteq \\mathbb{N}$ has an input, and two possible outputs ``yes'' and ``no''. If the algorithm is run on input $n$, it will halt in finite steps with output ``yes'' if $n \\in A$ and ``no'' if $n \\notin A$.\n\\end{definition}\n\n\\begin{definition}[Effectively Decidable Sets]\n    \\label{def:EffectivelyDecidableSet}\n    Let $A$ be a subset of $\\mathbb{N}$. $A$ is \\textbf{effectively decidable} if there is an algorithm for determining membership of $A$.\n\\end{definition}\n\n\\begin{itemize}\n    \\item $\\mathbb{N}$ is effectively decidable. (Always ``yes'')\n    \\item $\\emptyset$ is effectively decidable. (Always ``no'')\n\\end{itemize}\n\n\\begin{theorem}\n    If $A$ and $B$ are effectively decidable subsets of $\\mathbb{N}$, then $\\mathbb{N}\\backslash A$, $A \\cap B$ and $A \\cup B$ are all effectively decidable.\n\\end{theorem}\n\nAlgorithms can have different kinds of outputs and inputs.\n\n\\begin{definition}[Diophantine Equations]\n    Consider polynomials with integer coefficients (and any number of variables), a \\textbf{diophantine equation} is an equation of the form $p=0$, where $p$ is sunch a polynomial. (e.g., $3x^2 + 5xy - 2z^4 +3 = 0$)\n\\end{definition}\n\n\\paragraph{Hilbert's 10th Problem.} Is there an algorithm for determining whether or not diophantine equations have integer solutions?\n\n\\subsection{Algorithm for Listing Members of Sets}\n\\label{sub:AlgoForListingMembersOfSets}\n\n\\begin{definition}[Algorithm for Listing Members of Sets]\n    \\label{def:AlgoForListingMembersOfSets}\n    Let $A \\subseteq \\mathbb{N}$. An algorithm for \\textbf{listing the members of $A$} prints (or enumerates) a list of numbers $a_0,a_1,\\dots$ s.t.\n    \\begin{itemize}\n        \\item $a_n \\in A$ for all $n \\in \\mathbb{N}$\n        \\item If $a \\in A$, then $a = a_n$ for some $n$\n    \\end{itemize}\n\\end{definition}\n\\begin{remark} ~{}\n    \\begin{itemize}\n        \\item No input.\n        \\item Repetitions in the listing are permitted.\n        \\item If $A$ is finite, the algorithm may terminate or run forever (by iterating endlessly over the finite set).\n        \\item If $A$ is infinite, the algorithm should run forever.\n    \\end{itemize}\n\\end{remark}\n\n\\begin{definition}[Effectively Enumerable Sets]\n    \\label{def:EffectivelyEnumerableSet}\n    A set $A \\subseteq \\mathbb{N}$ is \\textbf{effectively enumerable} if there is an algorithm for listing its members.\n\\end{definition}\n\n\\subsection{Effectively Computable Functions}\n\\label{sub:EffectivelyComputableFunction}\n\n\\begin{definition}[Partial Functions]\n    \\label{def:PartialFunction}\n    A function $f:\\mathbb{N}\\mapsto\\mathbb{N}$ is a \\textbf{partial number-theoretic function} if its domain is a subset of $\\mathbb{N}$.\n\\end{definition}\n\\begin{definition}[Total Functions]\n    \\label{def:TotalFunction}\n    A partial function whose domain is all of $\\mathbb{N}$ is a total function.\n\\end{definition}\n\n\\begin{definition}[Notation for Definability]\n    For a partial function $f$\n    \\begin{itemize}\n        \\item $n \\in \\textrm{dom}(f)$, then $f(n)\\downarrow$\n        \\item $n \\notin \\textrm{dom}(f)$, then $f(n)\\uparrow$\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[Effectively Computable Functions]\n    \\label{def:EffectivelyComputableFunction}\n    The partial function $f$ is \\textbf{effectively computable} if there is an algorithm $\\mathcal{A}$ s.t. on input $n$\n    \\begin{itemize}\n        \\item Prints output $f(n)$ if $f(n)\\downarrow$\n        \\item No output if $f(n)\\uparrow$\n    \\end{itemize}\n    $\\mathcal{A}$ is called an algorithm for computing $f$.\n\\end{definition}\n\n\\begin{remark}\n    The definition of effectively decidable and enumerable sets, and effectively computable functions can be extended to $\\mathbb{N}^k$.\n\\end{remark}\n\n\\subsection{Relations among Effectively Decidable Sets, Effectively Enumerable Sets and Effectively Computable Functions}\n\n\\begin{proposition}\n    Let $A \\subseteq \\mathbb{N}$. If $A$ is effectively decidable then $A$ is effectively enumerable.\n\\end{proposition}\n\n\\begin{proposition}\n    Let $A \\subseteq \\mathbb{N}$. $A$ is effectively decidable iff the characteristic function (\\ref{def:CharacteristicFunctions}) $C_A$ is effectively computable.\n\\end{proposition}\n\n\\begin{proposition}\n    Let $f:\\mathbb{N}\\mapsto\\mathbb{N}$. If $f$ is an effectively computable function, then $\\textrm{rng}(f)$ is an effectively enumerable set.\n\\end{proposition}\n\n\\begin{proposition}\n    Combining the above two propositions, we have: Let $A$ be a non-empty subsect of $\\mathbb{N}$, $A$ is effectively enumerable iff there is an effectively computable function whose range is $A$.\n\\end{proposition}\n\n\\begin{proposition}\n    If $A\\neq\\emptyset$ is an effectively enumerable subset of $\\mathbb{N}$, then there is an effectively computable function $f$ with $\\range(f)=A$.\n\\end{proposition}\n\n\\section{Enumerability of Algorithms}\n\\label{sec:EnumerabilityOfAlgos}\n\n\\begin{theorem}\n    There are only \\emph{enumerably many} algorithms.\n\\end{theorem}\n\\begin{corollary}\n    There are only enumerably many partial effectively computable functoins. Since there are uncountably many total number-theoretic functions, there must exist total number-theoretic functions that are not effectively computable.\n\\end{corollary}\n\\begin{corollary}\n    There are only enumerably many effectively enumerable subsets of $\\mathbb{N}$. Since there are uncountably many subsets of $\\mathbb{N}$, there must exist subsets of $\\mathbb{N}$ that are not effectively enumerable.\n\\end{corollary}\n\n\\subsubsection{Listing of Effectively Computable Total Function}\n\nSuppose $f_0,\\dots$ is a listing of all effectively computable total function (this listing is unknown, we only know a listing of all computable partial functions). Let $g$ be a function such that\n\n\\[ g(m,n) = f_m(n) \\]\n\n$g$ is not effectively computable.\n\n\\begin{proof}\n    By diagonal argument. Let $h(n) = g(n,n) + 1$. If $g$ is effectively computable, then so is $h$. Then $h$ must be in the listing $\\{f_n\\}$. Suppose $f_k = h$. Then\n    \\[ f_k(k) = h(k) = g(k,k)+1 = f_k(k) + 1 \\]\n    噔噔咚。\n\\end{proof}\n\n\\section{The Halting Problem}\n\nIs there an algorithm for deciding whether any algorithm halts on given input or not?\n\n\\begin{theorem}\n    \\label{thm:HaltingProblem}\n    Let $\\mathcal{A}_0,\\dots,\\mathcal{A}_n,\\dots$ be a listing of algorithm with space for only one input. There does not exist an algorithm $\\mathcal{H}$ with space for two number inputs s.t. on input $(m,n)$\n    \\begin{itemize}\n        \\item Halts with output ``yes'' if $\\mathcal{A}_m$ halts on input $n$.\n        \\item Halts with output ``no'' if $\\mathcal{A}_m$ does not halt on input $n$\n    \\end{itemize}\n\\end{theorem}\n\\begin{proof}\n    Construct $\\mathcal{C}(n)$ by:\n    \\begin{itemize}\n        \\item Run $\\mathcal{H}(n,n)$\n        \\item If ``yes'' then loop forever\n        \\item If ``no'' then print ``yes'' and return\n    \\end{itemize}\n\n    Then $\\mathcal{C}$ must be in the listing $\\{\\mathcal{A}_n\\}$. Suppose $\\mathcal{A}_k = \\mathcal{C}$.\n    \\begin{itemize}\n        \\item $\\mathcal{C}(k)$ halts $\\Leftrightarrow$ $\\mathcal{H}(k,k)$ prints ``no'' $\\Leftrightarrow$ $\\mathcal{A}_k(k) = \\mathcal{C}(k)$ does not halt.\n    \\end{itemize}\n    噔噔咚。\n\\end{proof}", "meta": {"hexsha": "2e743c6ee1a27e5aee86a619234714f2019f3a75", "size": 8019, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Logic/InformalNotionsOfAlgorithms.tex", "max_stars_repo_name": "YBRua/CourseNotes", "max_stars_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-20T10:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T08:15:15.000Z", "max_issues_repo_path": "Mathematical Logic/InformalNotionsOfAlgorithms.tex", "max_issues_repo_name": "YBRua/CourseNotes", "max_issues_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mathematical Logic/InformalNotionsOfAlgorithms.tex", "max_forks_repo_name": "YBRua/CourseNotes", "max_forks_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T11:31:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T11:31:00.000Z", "avg_line_length": 43.1129032258, "max_line_length": 271, "alphanum_fraction": 0.7134306023, "num_tokens": 2317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7306967149220396}}
{"text": "%!TEX root=report.tex\n\n\\subsection{OLS with autocorrelated residuals}\n\nIn OLS it is assumed that the residuals between different observations are uncorrelated. However since our data is a time series this assumption does most likely not hold. This can also be confirmed with the Durbin-Watson test statistic \\cite[p.~173]{autocorrelation-kousgaard}. This test statistic is calculated using\n\\begin{equation}\nd = \\frac{\\sum_{i=2}^n \\left( \\hat{\\epsilon}_i - \\hat{\\epsilon}_{i-1} \\right)^2}{ \\sum_{i=1}^n\\hat{\\epsilon}_i^2 }\n\\end{equation}\n\nwhich lies between 0 and 4. If $d$ is close to 0 the residuals $\\hat{\\epsilon}_i$ and $\\hat{\\epsilon}_{i-1}$ are correlated positively, if close to 4 the residuals are negatively correlated. The purpose of this method is to reduce the correlation between the residuals, the Durbin-Watson test statistic should then become 2.\n\nWhen the residuals are correlated, one gets bad estimation of the variance of the residuals $\\hat{\\sigma}_\\epsilon^2$. This in turn leads to bad interference statistics, such as misleading p-values.\n\nTo correct for the correlated residuals, one can use a general least squares (GLS) regression. This uses a $\\Sigma$ matrix there will correct for the correlated residuals\n\\begin{equation}\n\\min_{\\beta, \\rho}\\ (Y-X\\beta)^T \\Sigma^{-1}(Y-X\\beta),\n\\label{eq:theory-olsar-min}\n\\end{equation}\n\nwhere $ \\Sigma^{-1}$ is given as\n\\begin{equation}\n\\Sigma^{-1}  = \\begin{bmatrix}\n1         & -\\rho         & 0               & \\cdots & 0              & 0         \\\\\n-\\rho   & 1+\\rho^2 & -\\rho         & \\cdots & 0               & 0         \\\\\n0         & -\\rho         & 1+\\rho^2 & \\cdots &0                & 0         \\\\\n\\vdots & \\vdots      & \\vdots       & \\ddots & \\vdots      & \\vdots \\\\\n0         & 0               &0                & \\cdots & 1+\\rho^2 & -\\rho    \\\\\n0         & 0               &0                & \\cdots &-\\rho          & 1\n\\end{bmatrix}\n\\end{equation}\n\nThe optimization problem \\eqref{eq:theory-olsar-min} is nonlinear and there is no closed form solution to this problem. However when keeping $\\rho$ constant the $\\beta$ parameters can be estimated using  General Least Squared, which is similar to OLS but with a constant $\\Sigma$ matrix and have the solution \\cite[p.~38]{time-series-analysis}\n\\begin{equation}\n\\hat{\\beta} = (X^T \\Sigma^{-1} X)^{-1} X^T \\Sigma^{-1} Y.\n\\end{equation}\n\nThis should then be rewritten using SVD, to account for a near singular $X^T \\Sigma^{-1} X$ matrix.\n\nSimilarly when $\\beta$ is kept constant, $\\rho$ can be estimated with  \\cite[p.~178]{autocorrelation-kousgaard}\n\\begin{equation}\n\\hat{\\rho} = \\frac{ \\sum_{i=2}^n \\hat{\\epsilon_i}\\hat{\\epsilon}_{i-1} }{ \\sum_{i=2}^{n-1} \\hat{\\epsilon_i}^2 }.\n\\label{eq:theory-olsar-rho}\n\\end{equation}\n\nA practical way of solving the problem with respect to both $\\beta$ and $\\rho$, looks as follows:\n\\begin{enumerate}\n\\item initialize by letting $\\rho=0$\n\\item Iterate: \\begin{enumerate}\n\t\\item Keep $\\hat{\\rho}$ constant and estimate $\\beta$ using as a WLS problem.\n\t\n\t\\item Keep $\\hat{\\beta}$ constant and estimate $\\rho$ using \\eqref{eq:theory-olsar-rho}.\n\t\n\t\\item Repeat until convergence of $\\rho$ or until some predetermined upper iteration boundary is met.\n\\end{enumerate}\n\\end{enumerate}\n", "meta": {"hexsha": "df40c7547c0d490e2c1d33dd26d565f749c6adb0", "size": 3245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rapport/theory-ols-ar.tex", "max_stars_repo_name": "AndreasMadsen/grace", "max_stars_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-17T22:52:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-17T22:52:19.000Z", "max_issues_repo_path": "Rapport/theory-ols-ar.tex", "max_issues_repo_name": "AndreasMadsen/grace", "max_issues_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Rapport/theory-ols-ar.tex", "max_forks_repo_name": "AndreasMadsen/grace", "max_forks_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.9464285714, "max_line_length": 343, "alphanum_fraction": 0.6640986133, "num_tokens": 942, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7306955648725809}}
{"text": "\\chapter{Expectation}\n\n\\begin{ex}\n  Let $X_i$ take on the values $\\left\\{\\frac{1}{2}, 2\\right\\}$ depending on\n  whether the $i$th turn of the game resulted in a halving or a doubling\n  respectively. Since both outcomes occur with equal probability,\n  \\[\n    \\E{X_i} = \\frac{1}{2}\\cdot \\frac{1}{2} + 2\\cdot \\frac{1}{2}=\\frac{5}{4}.\n  \\]\n\n  Let $Y_n$ be the amount of money we have after the $n$th turn, and note that\n  \\[\n    Y_n = c\\prod_{i=1}^nX_i,\n  \\]\n  where $X_i$ is independent of $X_j$ whenever $i\\neq j$. Therefore,\n  \\begin{align*}\n    \\E{Y_n}\n    =\\E{c\\prod_{i=1}^nX_i}\n    =c\\prod_{i=1}^n\\E{X_i}\n    =c\\left(\\frac{5}{4} \\right)^{n}.\n  \\end{align*}\n\\end{ex}\n\n\\begin{ex}\n  Suppose that there is a constant $c$ such that $\\P{X=c}=1$. It follows that\n  $X$ is a discrete random variable, and therefore\n  \\[\n    \\E{X}=\\sum_{x\\in \\supp(X)} x\\P{X=x}=c,\n  \\]\n  since $\\P{X=x}=0$ for $x\\neq c$. Likewise,\n  \\[\n    \\E{X^2}=\\sum_{x\\in \\supp(X)} x^2\\P{X=x}=c^2,\n  \\]\n  and so\n  \\[\n    \\var{X}=\\E{X^2}-\\E{X}^2=c^2-c^2=0.\n  \\]\n\n  For the converse, we begin by proving a lemma. Let $Y$ be a non-negative\n  random variable such that $\\E{Y}=0$. We want to prove that $\\P{Y=0}=1$.\n\n  Let $B_n=[1/n,\\infty)$ and note that\n  \\[\n    0=\\E{Y}\\geq \\frac{1}{n}\\P{X\\in B_n},\n  \\]\n  and hence $\\P{B_n}=0$. However,\n  \\[\n    1 = \\P{X\\in \\{0\\}\\cup\\bigcup_{n=1}^\\infty B_n}=\\P{X=0}+\\lim_{n\\to\\infty}\n    \\P{X\\in B_m}= \\P{X=0}.\n  \\]\n\n  For the converse of the original claim, suppose we are given a random variable\n  $X$ such that $\\var{X}=0$. Note that we assume that $X$ has a mean in our\n  definition of variance, and therefore can let $\\E{X}=c$. Hence,\n  \\[\n    \\E{(X-c)^2}=0,\n  \\]\n  or, by our previous lemma,\n  \\[\n    \\P{(X-c)^2= 0}=1.\n  \\]\n  But this is equivalent to $\\P{X=c}=1$.\n\\end{ex}\n\n\\begin{ex}\n  Let $X_1,\\ldots,X_n\\sim\\text{Uniform}(0, 1)$ and let\n  $Y_n=\\max\\{X_1,\\ldots,X_n\\}$. Then\n  \\[\n    \\P{Y_n\\leq y}y\n    =\\P{X_1\\leq y}\\cdots \\P{X_n\\leq y}\n    =\\begin{cases}\n      0   & y<0,          \\\\\n      y^n & 0\\leq y\\leq1, \\\\\n      1   & y>1,\n    \\end{cases}\n  \\]\n  and therefore\n  \\[\n    f_{Y_n}(y)=\\begin{cases}\n      ny^{n-1} & 0\\leq y\\leq1      \\\\\n      0        & \\text{otherwise}.\n    \\end{cases}\n  \\]\n\n  Hence,\n  \\[\n    \\E{Y_n}\n    =\\int_0^1\\! ny^n\\,\\d{y}\n    =\\frac{n y^{n+1}}{n+1}\\,\\bigg\\rvert_{y=0}^1\n    =\\frac{n}{n+1}.\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  Let $J_i$ be the outcome of the $i$th jump: $-1$ if it is a jump to the left\n  and $1$ if it is a jump to the right. Note that\n  \\begin{align*}\n    \\E{J_i}   & =-1\\cdot p+1\\cdot (1-p)=1-2p,        \\\\\n    \\E{J_i^2} & =1\\cdot p+1\\cdot (1-p)=1\\text{, and} \\\\\n    \\var{J_i} & =1-(1-2p)^2=4p-4p^2.\n  \\end{align*}\n\n  Let $X_n$ be the position of the particle after $n$ time units. Note that\n  $X_n=\\sum_{i=1}^n J_i$, where all the $J_i$'s are independent. Therefore,\n  \\[\n    \\E{X_n}\n    = \\E{\\sum_{i=1}^n J_i}\n    = \\sum_{i=1}^n \\E{J_i}\n    = n(1-2p) \\text{, and}\n  \\]\n  \\[\n    \\var{X_n}\n    = \\var{\\sum_{i=1}^n J_i}\n    = \\sum_{i=1}^n \\var{J_i}\n    = n(4p-4p^2).\n  \\]\n\\end{ex}\n\n% 5\n\\begin{ex}\n  Let $X$ be the number of fair coin tosses until a head is obtained. Note that\n  since the only way to obtain the first head in $n$ tosses is to toss tails\n  $n-1$ times and then toss a head, it follows that\n  $\\P{X=n}=\\left(\\frac{1}{2}\\right)^n$.\n  Hence,\n  \\[\n    \\E{X}\n    = \\sum_{n=1}^\\infty n\\cdot \\left(\\frac{1}{2}\\right)^n\n    = 2\n  \\]\n  by comparison to the Taylor series of $x/(1-x)^2$.\n\\end{ex}\n\n\\begin{ex}\n  Note that\n  \\[\n    \\E{r(X)}\n    =\\sum_{y\\in\\supp{Y}}y\\P{r(X)=y}\n    =\\sum_{y\\in\\supp{Y}}y\\sum_{\\{x\\in\\supp{X}\\mid r(x)=y\\}}\\P{X=x},\n  \\]\n  where the double summation $\\sum_y\\sum_{\\{x\\mid r(x)=y\\}}$ is equivalent to\n  the single summation $\\sum_{x}$ by replacing $y$ with $r(x)$. Hence,\n  \\[\n    \\E{r(X)}\n    =\\sum_{x\\in\\supp{X}}r(x)f_X(x).\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  Let $X$ be a continuous random variable with CDF $F$, such that $\\P{X>0}=1$\n  and $\\E{X}$ exists. Note that then $\\P{X\\leq 0}=1-\\P{X>0}=0$. Then\n  \\begin{align*}\n    \\int_{0}^\\infty\\! \\P{X>x}\\,\\d{x}\n     & =\\int_{0}^\\infty\\! 1-F(x)\\,\\d{x}                                                                                \\\\\n     & =x(1-F(x))\\,\\bigg\\rvert_{x=0}^\\infty+\\int_{0}^\\infty\\! xF'(x)\\,\\d{x} &  & (\\text{integration by parts})         \\\\\n     & =\\int_{0}^\\infty\\! xF'(x)\\,\\d{x}                                                                                \\\\\n     & =\\int_{-\\infty}^\\infty\\! xF'(x)\\,\\d{x}                               &  & (\\text{since $F(x)=0$ for $x\\leq 0$}) \\\\\n     & =\\E{X}.\n  \\end{align*}\n\n\\end{ex}\n\n\\begin{ex}\n  Let $X_1,\\ldots,X_n$ be \\iid with $\\mu=\\E{X_i}$ and $\\sigma^2=\\var{X_i}$. Then\n  \\begin{align*}\n    \\E{\\overline{X}_n}\n     & =\\E{\\frac{\\sum_{i=1}^nX_i}{n}}                                      \\\\\n     & =\\frac{1}{n}\\sum_{i=1}^n\\E{X_i} & \\text{(linearity of expectation)} \\\\\n     & =\\frac{n\\mu}{n}                                                     \\\\\n     & =\\mu.\n  \\end{align*}\n\n  Likewise,\n  \\begin{align*}\n    \\var{\\overline{X}^2_n}\n     & =\\var{\\frac{\\sum_{i=1}^nX_i}{n}}           \\\\\n     & =\\frac{1}{n^2}\\sum_{i=1}^n\\var{X_i}        \\\\\n     & =\\frac{n\\sigma^2}{n^2}=\\frac{\\sigma^2}{n}.\n  \\end{align*}\n\n  Finally, observe that\n  \\[\n    \\E{X_i^2}\n    =\\var{X_i}+\\E{X_i}^2\n    =\\sigma^2+\\mu^2,\n  \\]\n  \\[\n    \\E{\\overline{X}^2_n}\n    =\\var{\\overline{X}_n}+\\E{\\overline{X}_n}^2\n    =\\frac{\\sigma^2}{n}+\\mu^2,\n  \\]\n  and\n  \\begin{align*}\n    \\E{X_i\\overline{X}_n}\n     & =\\frac{1}{n}\\E{X_i\\sum_{j=1}^nX_j}                                           \\\\\n     & =\\frac{1}{n}\\E{X^2_i+\\sum_{\\substack{j=1                                     \\\\ j\\neq i}}^n X_iX_j} \\\\\n     & =\\frac{1}{n}\\left(\\sigma^2+\\mu^2+(n-1)\\mu^2\\right)=\\frac{\\sigma^2}{n}+\\mu^2,\n  \\end{align*}\n  and that therefore\n  \\begin{align*}\n    \\E{S^2_n}\n     & =\\E{\\frac{1}{n-1}\\sum_{i=1}^n\\left(X_i-\\overline{X}_n)^2\\right)}                               \\\\\n     & =\\frac{1}{n-1}\\sum_{i=1}^n\\E{\\left(X_i-\\overline{X}_n)^2\\right)}                               \\\\\n     & =\\frac{1}{n-1}\\sum_{i=1}^n\\E{X_i^2-2X_i\\overline{X_n}+\\overline{X}_n^2}                        \\\\\n     & =\\frac{n}{n-1}\\left(\\sigma^2+\\mu^2-\\frac{2\\sigma^2}{n}-2\\mu^2+\\frac{\\sigma^2}{n}+\\mu^2 \\right) \\\\\n     & =\\frac{n}{n-1}\\left(\\sigma^2-\\frac{\\sigma^2}{n}\\right)                                         \\\\\n     & =\\sigma^2.\n  \\end{align*}\n\\end{ex}\n\n\\begin{ex}\n  We use the following Python code to graph the sample means:\n\n  \\inputminted{python}{../code/03-09a.py}\n\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.9]{../images/03-09a}\n    \\caption{Graph of $\\overline{X}_n$ for a standard normal distribution.}\n  \\end{figure}\n\n  \\inputminted{python}{../code/03-09b.py}\n\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.9]{../images/03-09b}\n    \\caption{Graph of $\\overline{X}_n$ for a Cauchy distribution.}\n  \\end{figure}\n\n  The standard normal distribution has a defined mean of $0$ and, as expected,\n  the sample mean seems to be converging to it. The Cauchy distribution does not\n  have a mean, and that is why the sample mean is not converging to a particular\n  value.\n\\end{ex}\n\n% 10\n\\begin{ex}\n  Let $X\\sim N(0, 1)$ and let $Y=e^X$. Then\n  \\begin{align*}\n    \\E{Y}\n     & =\\int_{-\\infty}^\\infty\\!\\frac{e^x}{\\sqrt{2\\pi}}e^{-\\frac{1}{2}x^2}\\,\\d{x}                    \\\\\n     & =\\int_{-\\infty}^\\infty\\!\\frac{1}{\\sqrt{2\\pi}}e^{-\\frac{1}{2}(x^2-2x)}\\,\\d{x}                 \\\\\n     & =\\int_{-\\infty}^\\infty\\!\\frac{e^{\\frac{1}{2}}}{\\sqrt{2\\pi}}e^{-\\frac{1}{2}(x^2-2x+1)}\\,\\d{x} \\\\\n     & =e^{\\frac{1}{2}}\\int_{-\\infty}^\\infty\\!\\frac{1}{\\sqrt{2\\pi}}e^{-\\frac{1}{2}(x-1)^2}\\,\\d{x}   \\\\\n     & =e^{\\frac{1}{2}}.\n  \\end{align*}\n\n  Recall that $\\var{Y}=\\E{Y^2}-\\E{Y}^2$, and note that\n  \\begin{align*}\n    \\E{Y^2}\n     & =\\int_{-\\infty}^\\infty\\!\\frac{e^{2x}}{\\sqrt{2\\pi}}e^{-\\frac{1}{2}x^2}\\,\\d{x}     \\\\\n     & =\\int_{-\\infty}^\\infty\\!\\frac{1}{\\sqrt{2\\pi}}e^{-\\frac{1}{2}(x^2-4x)}\\,\\d{x}     \\\\\n     & =\\int_{-\\infty}^\\infty\\!\\frac{e^2}{\\sqrt{2\\pi}}e^{-\\frac{1}{2}(x^2-4x+4)}\\,\\d{x} \\\\\n     & =e^2\\int_{-\\infty}^\\infty\\!\\frac{1}{\\sqrt{2\\pi}}e^{-\\frac{1}{2}(x-2)^2}\\,\\d{x}   \\\\\n     & =e^2.\n  \\end{align*}\n  Therefore,\n  \\[\n    \\var{Y}=e^2-e.\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  \\begin{enumerate}[(a)]\n    \\item Note that $X_n$ is identical to the $X_n$ of Exercise 3.4 with\n          $p=\\frac{1}{2}$. Therefore, $\\E{X_n}=0$ and $\\var{X_n}=n$.\n    \\item We use the following Python code.\n          \\inputminted{python}{../code/03-11.py}\n\n          \\begin{figure}[H]\n            \\centering\n            \\includegraphics[scale=0.8]{../images/03-11a}\n            \\caption{First simulation of $X_n$.}\n          \\end{figure}\n\n          \\begin{figure}[H]\n            \\centering\n            \\includegraphics[scale=0.8]{../images/03-11b}\n            \\caption{Second simulation of $X_n$.}\n          \\end{figure}\n\n          \\begin{figure}[H]\n            \\centering\n            \\includegraphics[scale=0.8]{../images/03-11c}\n            \\caption{Third simulation of $X_n$.}\n          \\end{figure}\n\n          The expected value of $X_n$ is $0$, but none of the simulations show\n          $X_n$ converging to $0$. This is explainable by the fact that the\n          variance is increasing with $n$.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  % Bernoulli\n  Let $B$ be a $\\text{Bernoulli}(p)$ random variable. Then\n  \\begin{align*}\n    \\E{B}   & =(1-p)\\cdot 0 + p\\cdot 1 = p,     \\\\\n    \\E{B^2} & =(1-p)\\cdot 0^2 + p\\cdot 1^2 = p, \\\\\n    \\var{B} & = \\E{B^2}-\\E{B}^2=p-p^2=p(1-p).\n  \\end{align*}\n\n  % Poisson\n  Let $P$ be a $\\text{Poisson}(\\lambda)$ random variable. Then\n  \\begin{align*}\n    \\E{P}\n     & =\\sum_{k=1}^\\infty k\\frac{e^{-\\lambda}\\lambda^{k}}{k!}              \\\\\n     & =e^{-\\lambda}\\lambda \\sum_{k=1}^\\infty \\frac{\\lambda^{k-1}}{(k-1)!} \\\\\n     & =e^{-\\lambda}\\lambda \\sum_{k=0}^\\infty \\frac{\\lambda^{k}}{k!}       \\\\\n     & = \\lambda,\n  \\end{align*}\n  \\begin{align*}\n    \\E{P^2}\n     & =\\sum_{k=1}^\\infty k^2\\frac{e^{-\\lambda}\\lambda^{k}}{k!}                                                        \\\\\n     & =e^{-\\lambda}\\lambda\\sum_{k=1}^\\infty k\\frac{\\lambda^{k-1}}{(k-1)!}                                             \\\\\n     & =e^{-\\lambda}\\lambda\\sum_{k=0}^\\infty (k+1)\\frac{\\lambda^k}{k!}                                                 \\\\\n     & =e^{-\\lambda}\\lambda\\left[\\sum_{k=0}^\\infty k\\frac{\\lambda^k}{k!}+\\sum_{k=0}^\\infty \\frac{\\lambda^k}{k!}\\right] \\\\\n     & =e^{-\\lambda}\\lambda\\left[\\lambda e^{\\lambda} + e^{\\lambda}\\right]                                              \\\\\n     & =\\lambda^2+\\lambda,\n  \\end{align*}\n  and therefore\n  \\[\n    \\var{P}\n    =\\E{P^2}-\\E{P}^2\n    =\\lambda^2+\\lambda-\\lambda=\\lambda.\n  \\]\n\n  % Uniform\n  Let $U$ be a $\\text{Uniform}(a, b)$ random variable. Then\n  \\begin{align*}\n    \\E{U}   & = \\int_a^b\\!\\frac{x}{b - a}\\,\\d{x}\n    =\\frac{1}{2}\\frac{b^2-a^2}{b-a}\n    =\\frac{a + b}{2},                              \\\\\n    \\E{U^2} & = \\int_a^b\\!\\frac{x^2}{b - a}\\,\\d{x}\n    =\\frac{1}{3}\\frac{b^3-a^3}{b-a}\n    =\\frac{a^2+ab+b^2}{3},\\text{ and hence}        \\\\\n    \\var{U} & = \\E{U^2}-\\E{U}^2\n    =\\frac{a^2+ab+b^2}{3}-\\frac{a^2+2ab+b^2}{4}\n    =\\frac{(b-a)^2}{12}.\n  \\end{align*}\n\n  % Exponential\n  Let $X$ be an $\\text{Exponential}(\\beta)$ random variable. Then\n  \\begin{align*}\n    \\E{X}\n     & =\\int_0^\\infty\\!\\frac{x}{\\beta}e^{-x/\\beta}\\,\\d{x}                                            \\\\\n     & =\\beta\\int_0^\\infty\\!ue^{-u}\\,\\d{u}                                             & (u=x/\\beta) \\\\\n     & =\\beta\\left[-ue^{-u}\\bigg\\rvert_{u=0}^\\infty-\\int_0^\\infty e^{-u}\\,\\d{u}\\right]               \\\\\n     & =\\beta,\n  \\end{align*}\n  \\begin{align*}\n    \\E{X^2}\n     & =\\int_0^\\infty\\!\\frac{x^2}{\\beta}e^{-x/\\beta}\\,\\d{x}                                  \\\\\n     & =\\beta^2\\int_0^\\infty\\!u^2e^{-u}\\,\\d{u}                                               \\\\\n     & =\\beta^2\\left[u^2e^{-u}\\bigg\\rvert_{u=0}^\\infty-2\\int_0^\\infty ue^{-u}\\,\\d{u} \\right] \\\\\n     & =2\\beta^2,\n  \\end{align*}\n  and hence\n  \\[\n    \\var{X}\n    =\\E{X^2}-\\E{X}^2\n    =2\\beta^2-\\beta^2=\\beta^2.\n  \\]\n\n  % Gamma\n  Let $G$ be an $\\text{Gamma}(\\alpha, \\beta)$ random variable. Then\n  \\begin{align*}\n    \\E{G}\n     & =\\int_0^\\infty\\!\\frac{x}{\\beta^\\alpha\\Gamma(\\alpha)}x^{\\alpha-1}e^{-x/\\beta}\\,\\d{x}                                                 \\\\\n     & =\\frac{\\beta\\Gamma(\\alpha+1)}{\\Gamma(\\alpha)}\\int_0^\\infty\\!\\frac{1}{\\beta^{\\alpha+1}\\Gamma(\\alpha+1)}x^{\\alpha}e^{-x/\\beta}\\,\\d{x} \\\\\n     & =\\alpha\\beta,\n  \\end{align*}\n  \\begin{align*}\n    \\E{G^2}\n     & =\\int_0^\\infty\\!\\frac{x^2}{\\beta^\\alpha\\Gamma(\\alpha)}x^{\\alpha-1}e^{-x/\\beta}\\,\\d{x}                                                   \\\\\n     & =\\frac{\\beta^2\\Gamma(\\alpha+2)}{\\Gamma(\\alpha)}\\int_0^\\infty\\!\\frac{1}{\\beta^{\\alpha+2}\\Gamma(\\alpha+2)}x^{\\alpha+1}e^{-x/\\beta}\\,\\d{x} \\\\\n     & =\\alpha(\\alpha+1)\\beta^2,\n  \\end{align*}\n  and thus\n  \\[\n    \\var{G}\n    =\\E{G^2}-\\E{G}^2\n    =\\alpha(\\alpha+1)\\beta^2-\\alpha^2\\beta^2\n    =\\alpha\\beta^2.\n  \\]\n\n  % Beta\n  Finally, let $Y$ be a $\\text{Beta}(\\alpha, \\beta)$ random variable. Then\n  \\begin{align*}\n    \\E{Y}\n     & =\\int_0^\\infty\\!x\\cdot\\frac{\\Gamma(\\alpha+\\beta)}{\\Gamma(\\alpha)\\Gamma(\\beta)}x^{\\alpha-1}(1-x)^{\\beta-1} \\,\\d{x}                                                                             \\\\\n     & =\\frac{\\Gamma(\\alpha+\\beta)\\Gamma(\\alpha+1)}{\\Gamma(\\alpha)\\Gamma(\\alpha+\\beta+1)}\\int_0^\\infty\\!\\frac{\\Gamma(\\alpha+\\beta+1)}{\\Gamma(\\alpha+1)\\Gamma(\\beta)}x^{\\alpha}(1-x)^{\\beta-1}\\,\\d{x} \\\\\n     & =\\frac{\\alpha}{\\alpha+\\beta},\n  \\end{align*}\n  \\begin{align*}\n    \\E{Y^2}\n     & =\\int_0^\\infty\\!x^2\\cdot\\frac{\\Gamma(\\alpha+\\beta)}{\\Gamma(\\alpha)\\Gamma(\\beta)}x^{\\alpha-1}(1-x)^{\\beta-1} \\,\\d{x}                                                                             \\\\\n     & =\\frac{\\Gamma(\\alpha+\\beta)\\Gamma(\\alpha+2)}{\\Gamma(\\alpha)\\Gamma(\\alpha+\\beta+2)}\\int_0^\\infty\\!\\frac{\\Gamma(\\alpha+\\beta+2)}{\\Gamma(\\alpha+2)\\Gamma(\\beta)}x^{\\alpha+1}(1-x)^{\\beta-1}\\,\\d{x} \\\\\n     & =\\frac{\\alpha(\\alpha+1)}{(\\alpha+\\beta+1)(\\alpha+\\beta)},\n  \\end{align*}\n  and so\n  \\begin{align*}\n    \\var{Y}\n     & =\\E{Y^2}-\\E{Y}^2                                         \\\\\n     & =\\frac{\\alpha(\\alpha+1)}{(\\alpha+\\beta+1)(\\alpha+\\beta)}\n    -\\frac{\\alpha^2}{(\\alpha+\\beta)^2}                          \\\\\n     & =\\frac{\\alpha\\beta}{(a+\\beta)^2(\\alpha+\\beta+1)}.\n  \\end{align*}\n\\end{ex}\n\n\\begin{ex}\n  Let $Z$ be a uniform discrete random variable on $\\{0, 1\\}$,\n  $X_1\\sim\\text{Uniform}(0, 1)$ and $X_2\\sim\\text{Uniform}(3, 4)$. Then\n  $X=ZX_1 + (1-Z)X_2$.\n  \\begin{itemize}[(a)]\n    \\item We have\n          \\begin{align*}\n            \\E{X} & =\\E{ZX_1 + (1-Z)X_2}           \\\\\n                  & =\\E{ZX_1} + \\E{(1-Z)X_2}       \\\\\n                  & =\\E{Z}\\E{X_1} + \\E{1-Z}\\E{X_2} \\\\\n                  & =\\frac{1}{4}+\\frac{7}{4}       \\\\\n                  & =2.\n          \\end{align*}\n    \\item[(b)] We begin by finding the variance:\n          \\begin{align*}\n            \\var{X}\n             & =\\var{ZX_1 + (1-Z)X_2}                           \\\\\n             & =\\var{ZX_1}+\\var{(1-Z)X_2}+2\\cov{ZX_1, (1-Z)X_2} \\\\\n             & =\\frac{5}{48}+\\frac{149}{48}-\\frac{7}{8}         \\\\\n             & =\\frac{7}{3},\n          \\end{align*}\n          since\n          \\begin{align*}\n            \\var{ZX_1}\n             & =\\E{Z^2}\\E{X_1^2}-\\frac{1}{16}\n            =\\frac{1}{2}\\cdot\\frac{1}{3}-\\frac{1}{16}\n            =\\frac{5}{48},                            \\\\\n            \\var{(1-Z)X_2}\n             & =\\E{(1-Z)^2}\\E{X_2^2}-\\frac{49}{16}\n            =\\frac{1}{2}\\cdot\\frac{37}{3}-\\frac{49}{16}\n            =\\frac{149}{48},\\text{ and}               \\\\\n            \\cov{ZX_1, (1-Z)X_2}\n             & =\\E{Z(1-Z)X_1X_2}-\\E{ZX_1}\\E{(1-Z)X_2}\n            =-\\frac{1}{4}\\cdot\\frac{7}{4}\n            =-\\frac{7}{16}.\n          \\end{align*}\n          Therefore, the standard deviation is $\\sqrt{7/3}$.\n  \\end{itemize}\n\\end{ex}\n\n\\begin{ex}\n  Let $X_1,\\ldots, X_m$ and $Y_1,\\ldots,Y_n$ be random variables and\n  $a_1,\\ldots,a_m,b_1,\\ldots,b_n$ be constants. Then\n  \\begin{align*}\n    \\cov{\\sum_{i=1}^m a_iX_i, \\sum_{j=1}^nb_jY_j }\n     & =\\E{\\left(\\sum_{i=1}^m a_iX_i\\right)\\left(\\sum_{j=1}^nb_jY_j\\right)}\n    -\\E{\\sum_{i=1}^m a_iX_i}\\E{\\sum_{j=1}^nb_jY_j}                             \\\\\n     & =\\E{\\sum_{i=1}^m \\sum_{j=1}^n a_ib_jX_iY_j}\n    -\\left[\\sum_{i=1}^m a_i\\E{X_i}\\right] \\left[\\sum_{j=1}^n b_j\\E{Y_j}\\right] \\\\\n     & =\\sum_{i=1}^m\\sum_{j=1}^n a_ib_j \\E{X_iY_j}\n    -\\sum_{i=1}^m\\sum_{j=1}^n a_ib_j \\E{X_i}\\E{Y_j}                            \\\\\n     & =\\sum_{i=1}^m\\sum_{j=1}^n a_ib_j\\left[\\E{X_iY_j}-\\E{X_i}\\E{Y_j}\\right]  \\\\\n     & =\\sum_{i=1}^m\\sum_{j=1}^n a_ib_j\\cov{X_i, Y_j}.\n  \\end{align*}\n\\end{ex}\n\n% 15\n\\begin{ex}\n  Let $X,Y$ be random variables with joint PDF\n  \\[\n    f_{X, Y}(x,y)\n    =\\begin{cases}\n      \\frac{1}{3}\\left(x+y\\right) & 0\\leq x\\leq 1, 0\\leq y\\leq 2 \\\\\n      0                           & \\text{otherwise}.\n    \\end{cases}\n  \\]\n\n  Note that\n  \\begin{align*}\n    f_X(x)\n     & =\\int_0^2\\! f_{X,Y}(x,y)\\,\\d{y}                      \\\\\n     & =\\int_0^2\\! \\frac{1}{3}x+\\frac{1}{3}y\\,\\d{y}         \\\\\n     & =\\left[ \\frac{1}{3}xy+\\frac{1}{6}y^2 \\right]_{y=0}^2 \\\\\n     & =\\frac{2}{3}\\left(x+1\\right),\n  \\end{align*}\n  and that therefore\n  \\[\n    \\E{X}\n    =\\int_0^1\\!x\\cdot\\frac{2}{3}\\left(x+1\\right)\\,\\d{x}\n    =\\left[ \\frac{2}{9}x^3+\\frac{1}{3}x^2 \\right]_{x=0}^1\n    =\\frac{5}{9},\n  \\]\n  \\[\n    \\E{X^2}\n    =\\int_0^1\\!x^2\\cdot\\frac{2}{3}\\left(x+1\\right)\\,\\d{x}\n    =\\left[ \\frac{2}{12}x^4+\\frac{2}{9}x^3 \\right]_{x=0}^1\n    =\\frac{7}{18},\n  \\]\n  and\n  \\begin{align*}\n    \\var{X}=\\E{X^2}-\\E{X}^2=\\frac{7}{18}-\\frac{25}{81}=\\frac{13}{162}.\n  \\end{align*}\n\n  Similarly,\n  \\begin{align*}\n    f_Y(y)\n     & =\\int_0^1\\! f_{X,Y}(x,y)\\,\\d{x}                    \\\\\n     & =\\int_0^1\\! \\frac{1}{3}x+\\frac{1}{3}y\\,\\d{x}       \\\\\n     & =\\left[\\frac{1}{6}x^2+\\frac{1}{3}xy\\right]_{x=0}^1 \\\\\n     & =\\frac{1}{6}+\\frac{1}{3}y,\n  \\end{align*}\n  and so\n  \\begin{align*}\n    \\E{Y}\n    =\\int_0^2\\!y\\left(\\frac{1}{6}+\\frac{1}{3}y\\right)\\,\\d{y}\n    =\\left[ \\frac{1}{12}y^2+\\frac{1}{9}y^3 \\right]_{y=0}^2\n    =\\frac{11}{9},\n  \\end{align*}\n  \\begin{align*}\n    \\E{Y^2}\n    =\\int_0^2\\!y^2\\left(\\frac{1}{6}+\\frac{1}{3}y\\right)\\,\\d{y}\n    =\\left[ \\frac{1}{18}y^3+\\frac{1}{12}y^4 \\right]_{y=0}^2\n    =\\frac{16}{9},\n  \\end{align*}\n  and\n  \\begin{align*}\n    \\var{Y}=\\E{Y^2}-\\E{Y}^2=\\frac{16}{9}-\\frac{121}{81}=\\frac{23}{81}.\n  \\end{align*}\n\n  Note that\n  \\begin{align*}\n    \\E{XY}\n    =\\int_0^2\\!\\int_0^1\\!\\frac{1}{3}x^2y+\\frac{1}{3}xy^2\\,\\d{x}\\,\\d{y}\n    =\\int_0^2\\!\\frac{1}{6}y^2+\\frac{1}{9}y\\,\\d{y}\n    =\\frac{2}{3},\n  \\end{align*}\n  and so\n  \\begin{align*}\n    \\cov{X,Y}=\\E{XY}-\\E{X}\\E{Y}=\\frac{2}{3} - \\frac{55}{81}=-\\frac{1}{81}.\n  \\end{align*}\n\n  Therefore,\n  \\begin{align*}\n    \\var{2X-3Y+8}\n    =4\\var{X}+9\\var{Y}-12\\cov{X,Y}\n    =\\frac{26}{81}+\\frac{207}{81} +\\frac{12}{81}\n    =\\frac{245}{81}.\n  \\end{align*}\n\n\\end{ex}\n\n\\begin{ex}\n  We will assume that $X$ and $Y$ are continuous random variables and note that\n  the proof in the discrete case proceeds similarly. Then\n  \\begin{align*}\n    \\cE{r(X)s(Y)}{X=x}\n     & =\\int_\\R\\!r(x)s(y)f_{X|Y}(x|y)\\,\\d{y} \\\\\n     & =r(x)\\int_\\R\\!s(y)f_{X|Y}(x|y)\\,\\d{y} \\\\\n     & =r(x)\\cE{s(y)}{X=x},\n  \\end{align*}\n  and we note that if we let $g(y)=1$,\n  \\[\n    \\cE{r(X)s(Y)}{X=x}\n    =\\cE{r(X)}{X=x}\n    =r(x)\\cE{1}{X=x}=r(x).\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  We have\n  \\begin{align*}\n    \\var{Y}\n     & =\\E{Y^2}-\\E{Y}^2                                   \\\\\n     & =\\E{\\cE{Y^2}{X}}-\\E{\\cE{Y}{X}}^2                   \\\\\n     & =\\E{\\var{Y\\,|\\,X}}+\\E{\\cE{Y^2}{X}}-\\E{\\cE{Y}{X}}^2 \\\\\n     & =\\E{\\var{Y\\,|\\,X}}+\\E{\\cE{Y^2}{X}-\\cE{Y}{X}^2}     \\\\\n     & =\\E{\\var{Y\\,|\\,X}}+\\var{\\cE{Y}{X}}.\n  \\end{align*}\n\\end{ex}\n\n\\begin{ex}\n  Note that\n  \\[\n    \\E{XY}\n    =\\E{\\cE{XY}{Y}}\n    =\\E{Y\\cE{X}{Y}}\n    =c\\E{Y},\n  \\]\n  \\[\n    \\E{X}\n    =\\E{\\cE{X}{Y}}\n    =c,\n  \\]\n  and that therefore\n  \\[\n    \\cov{X,Y}\n    =\\E{XY}-\\E{X}\\E{Y}\n    =c\\E{Y}-c\\E{Y}\n    =0.\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  Note that $f_X(x)=I_{[0,1]}(x)$.\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.8]{../images/03-19a}\n    \\caption{Graph of $f_X$.}\n  \\end{figure}\n\n  We have\n  \\[\n    \\E{\\overline{X}_n}\n    =\\E{\\frac{1}{n}\\sum_{i=1}^n X_i}\n    =\\E{X_1}=\\frac{1}{2}, \\text{ and}\n  \\]\n  \\[\n    \\var{\\overline{X}_n}\n    =\\frac{n}{n^2}\\var{X_1}\n    =\\frac{1}{12n}.\n  \\]\n\n  \\inputminted{python}{../code/03-19b.py}\n\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.8]{../images/03-19b}\n    \\caption{Graph of $\\E{\\overline{X}_n}$ as a function of $n$.}\n  \\end{figure}\n\n  \\inputminted{python}{../code/03-19c.py}\n\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.95]{../images/03-19c}\n    \\caption{Graph of $\\var{\\overline{X}_n}$ as a function of $n$.}\n  \\end{figure}\n\n  \\inputminted{python}{../code/03-19d.py}\n  \\inputminted{text}{../output/03-19d.txt}\n\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.535]{../images/03-19d}\n    \\caption{Sampling distribution of $\\overline{X}_n$ for different $n$.}\n  \\end{figure}\n\n  Notice that as $n$ increases, the variance of the sampling distribution of\n  $\\overline{X}_n$ decreases, i.e.\\ it becomes more narrow and sharply peaked\n  around the true mean of the underlying distribution.\n\\end{ex}\n\n% 20\n\\begin{ex}\n  We begin by extending the definition of expectation to a random matrix, by\n  defining the expected value of a random $m\\times n$ matrix $X$ to be the\n  $m\\times n$ matrix whose $(i, j)$th entry is the expected value of $X_{i,j}$.\n\n  Suppose that $X$ is a random matrix of dimension $m\\times n$ with mean $\\mu$,\n  and let $A$ be a $p\\times m$ matrix. Then\n  \\[\n    \\E{AX}_{i,j}\n    =\\E{\\sum_{k=1}^m A_{i,k} X_{k,j}}\n    =\\sum_{i=1}^m A_{i,k}\\E{X_{k,j}}\n    =\\sum_{i=1}^m A_{i,k}\\mu_{k,j}\n    =A\\mu,\n  \\]\n  and, likewise, if we let $B$ be an $n\\times p$ matrix,\n  \\[\n    \\E{XB}_{i,j}\n    =\\E{\\sum_{k=1}^n X_{i,k} B_{k,j}}\n    =\\sum_{i=1}^n \\E{X_{i,k}}B_{k,j}\n    =\\sum_{i=1}^n \\mu_{i,k}B_{k,j}\n    =\\mu B.\n  \\]\n\n  The two claims about the expected value of $\\E{a^TX}$ and $\\E{AX}$ in Lemma\n  3.21 are then special cases of this property for $X$ an $n\\times 1$ random\n  matrix.\n\n  For the rest of the exercise we restrict $X$ to a random vector with mean\n  $\\mu$ and variance-covariance matrix $\\Sigma$, and continue by noting that\n  \\begin{align*}\n     & \\E{(X-\\mu)(X-\\mu)^T}            \\\\\n     & =\\E{\\begin{pmatrix}\n        (X_1-\\mu_1)^2          & (X_1-\\mu_1)(X_2-\\mu_2) & \\cdots & (X_1-\\mu_1)(X_n-\\mu_n) \\\\\n        (X_2-\\mu_2)(X_1-\\mu_1) & (X_2-\\mu_2)^2          & \\cdots & (X_2-\\mu_2)(X_n-\\mu_n) \\\\\n        \\vdots                 & \\vdots                 & \\ddots & \\vdots                 \\\\\n        (X_n-\\mu_n)(X_1-\\mu_1) & (X_n-\\mu_n)(X_2-\\mu_2) & \\cdots & (X_n-\\mu_n)^2          \\\\\n      \\end{pmatrix}} \\\\\n     & =\\begin{pmatrix}\n      \\var{X_1}      & \\cov{X_1, X_2} & \\cdots & \\cov{X_1,X_n} \\\\\n      \\cov{X_2,X_1}  & \\var{X_2}      & \\cdots & \\cov{X_2,X_n} \\\\\n      \\vdots         & \\vdots         & \\ddots & \\vdots        \\\\\n      \\cov{X_n, X_1} & \\cov{X_n, X_2} & \\cdots & \\var{X_n}     \\\\\n    \\end{pmatrix}     \\\\\n     & =\\var{X},\n  \\end{align*}\n  and that therefore,\n  \\begin{align*}\n    \\var{AX}\n     & =\\E{(AX-A\\mu)(AX-A\\mu)^T} \\\\\n     & =\\E{A(X-\\mu)(A(X-\\mu))^T} \\\\\n     & =\\E{A(X-\\mu)(X-\\mu)^TA^T} \\\\\n     & =A\\E{(X-\\mu)(X-\\mu)^T}A^T \\\\\n     & =A\\Sigma A^T.\n  \\end{align*}\n\n  This is the second claim about variances of random vectors in Lemma 3.21, but\n  we conclude by noting that the first one is a special case of the second for\n  matrices of the form $1\\times n$.\n\\end{ex}\n\n\\begin{ex}\n  Recall that by the rule of iterated expectations,\n  \\[\n    \\E{\\cE{Y}{X}}=\\E{Y},\n  \\]\n  and therefore we have $\\E{X}=\\E{Y}$.\n\n  Therefore,\n  \\begin{align*}\n    \\cov{X, Y}\n     & =\\E{XY} - \\E{X}\\E{Y} \\\\\n  \\end{align*}\n\n  Likewise,\n  \\begin{align*}\n    \\E{XY}\n     & =\\E{\\cE{XY}{X}}                     \\\\\n     & =\\int\\! \\cE{XY}{X=x} f_X(x) \\,\\d{x} \\\\\n     & =\\int\\! \\cE{Y}{X=x} xf_X(x) \\,\\d{x} \\\\\n     & =\\int\\! x^2f_X(x) \\,\\d{x}           \\\\\n     & =\\E{X^2},\n  \\end{align*}\n  and thus\n  \\begin{align*}\n    \\cov{X, Y}\n     & =\\E{XY} - \\E{X}\\E{Y} \\\\\n     & =\\E{X^2} - \\E{X}^2   \\\\\n     & = \\var{X}.\n  \\end{align*}\n\\end{ex}\n\n\\begin{ex}\n  \\begin{enumerate}[(a)]\n    \\item[]\n    \\item No, since $\\P{(Y, Z)=(1, 1)}=b-a$, while\n          $\\P{Y=1}=b$ and $\\P{Z=1}=1-a$.\n    \\item We have\n          \\[\n            \\cE{Y}{Z=0}\n            =\\cP{Y=1}{Z=0}\n            =\\cP{Y=1}{X<a}\n            =1,\n          \\]\n          \\[\n            \\cE{Y}{Z=1}\n            =\\cP{Y=1}{Z=1}\n            =\\cP{Y=1}{X>a}\n            =\\frac{b-a}{1-a}.\n          \\]\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Suppose that $X\\sim\\text{Poisson}(\\lambda)$. Then\n  $f_X(x)=e^{-\\lambda}\\frac{\\lambda^x}{x!}$ and thus\n  \\begin{align*}\n    \\psi_X(t)\n     & =\\E{e^{tX}}                                               \\\\\n     & =\\sum_{n=0}^\\infty e^{tn}e^{-\\lambda}\\frac{\\lambda^n}{n!} \\\\\n     & =e^{-\\lambda}\\sum_{n=0}^\\infty \\frac{(\\lambda e^t)^n}{n!} \\\\\n     & =e^{\\lambda(e^t-1)}.\n  \\end{align*}\n\n  Suppose that $Y\\sim N(\\mu, \\sigma^2)$. Then\n  $f_Y=\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\n    \\exp\\left(-\\frac{1}{2}\\frac{(x-\\mu)^2}{\\sigma^2}\\right)$,\n  and therefore\n  \\begin{align*}\n    \\psi_Y(t)\n     & =\\E{e^{tY}}                                                  \\\\\n     & =\\int_{-\\infty}^\\infty\\! e^{ty}\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\n    \\exp\\left(-\\frac{1}{2}\\frac{(y-\\mu)^2}{\\sigma^2}\\right)\\,\\d{y}  \\\\\n     & =\\int_{-\\infty}^\\infty\\! \\frac{1}{\\sqrt{2\\pi\\sigma^2}}\n    \\exp\\left(-\\frac{1}{2}\\frac{(y-\\mu)^2+ty\\sigma^2}{\\sigma^2}\\right)\\,\\d{y}.\n  \\end{align*}\n  However, since\n  \\begin{align*}\n    -\\frac{1}{2}(y-\\mu)^2+ty\\sigma^2\n     & =-\\frac{1}{2}(y^2-2y\\mu+\\mu^2-2ty\\sigma^2)                                 \\\\\n     & =-\\frac{1}{2}(y^2-2y(\\mu+t\\sigma^2)+(\\mu+t\\sigma)^2-(\\mu+t\\sigma)^2+\\mu^2) \\\\\n     & =-\\frac{1}{2}(y-\\mu-t\\sigma^2)^2+\\frac{1}{2}((\\mu+t\\sigma^2)^2-\\mu^2)      \\\\\n     & =-\\frac{1}{2}(y-\\mu-t\\sigma^2)^2+(t\\mu\\sigma^2+t^2\\sigma^4/2),\n  \\end{align*}\n  it follows that\n  \\begin{align*}\n    \\psi_Y(t)\n     & =\\exp(t\\mu+t^2\\sigma^2/2)\\int_{-\\infty}^\\infty\\! \\frac{1}{\\sqrt{2\\pi\\sigma^2}}\n    \\exp\\left(-\\frac{1}{2}\\frac{(y-\\mu-t\\sigma^2)^2}{\\sigma^2}\\right)\\,\\d{y}          \\\\\n     & =\\exp(t\\mu+t^2\\sigma^2/2),\n  \\end{align*}\n  since the integrand is the PDF for an $N(m+t\\sigma^2, \\sigma^2)$ distribution\n  being integrated over its support.\n\n  Suppose that $Z\\sim\\text{Gamma}(\\alpha, \\beta)$. Then\n  \\[\n    f_Z(z)=\\frac{1}{\\beta^\\alpha \\Gamma(\\alpha)}z^{\\alpha-1}e^{-z/\\beta}\n  \\]\n  and so\n  \\begin{align*}\n    \\psi_Z(t)\n     & =\\E{e^{tZ}}                                                                                                                                   \\\\\n     & =\\int_{-\\infty}^\\infty e^{tz}\\frac{1}{\\beta^\\alpha \\Gamma(\\alpha)}z^{\\alpha-1}e^{-z/\\beta}\\,\\d{z}                                             \\\\\n     & =\\int_{-\\infty}^\\infty \\frac{1}{\\beta^\\alpha \\Gamma(\\alpha)}z^{\\alpha-1}e^{-z(1/\\beta-t)}\\,\\d{z}                                              \\\\\n     & =\\int_{-\\infty}^\\infty \\frac{(1/\\beta-t)^\\alpha}{(1/\\beta-t)^\\alpha}\\frac{1}{\\beta^\\alpha \\Gamma(\\alpha)}z^{\\alpha-1}e^{-z(1/\\beta-t)}\\,\\d{z} \\\\\n     & =\\frac{1}{(1/\\beta-t)^\\alpha\\beta^\\alpha}\n    \\int_{-\\infty}^\\infty \\frac{1}{(1/\\beta-t)^{-\\alpha}\\Gamma(\\alpha)}z^{\\alpha-1}e^{-z(1/\\beta-t)}\\,\\d{z}                                          \\\\\n     & =(1-\\beta t)^{-\\alpha},\n  \\end{align*}\n  since the integrand is the PDF for a $\\text{Gamma}(\\alpha, (1/\\beta-t)^{-1})$\n  distribution integrated over its support.\n\\end{ex}\n\n\\begin{ex}\n  Note that $f_{X_i}(x)=\\frac{1}{\\beta} e^{-x/\\beta}$ and that therefore\n  \\begin{align*}\n    \\psi_{X_i}(t)\n     & =\\E{e^{tX_i}}                                                                                           \\\\\n     & =\\int_{0}^\\infty e^{tx}\\frac{1}{\\beta} e^{-x/\\beta}\\,\\d{x}                                              \\\\\n     & =\\int_0^\\infty\\!\\frac{1}{\\beta}\\exp\\left(-x/(\\beta/(1-\\beta t))\\right)\\,\\d{t}                           \\\\\n     & =(1-\\beta t)^{-1}\\int_0^\\infty\\! \\frac{1-\\beta t}{\\beta} \\exp\\left(-x/(\\beta/(1-\\beta t))\\right)\\,\\d{t} \\\\\n     & =(1-\\beta t)^{-1}\n  \\end{align*}\n  since the integrand is the PDF for an exponential distribution integrated over\n  its support.\n\n  Let $Y=\\sum_{i=1}^n X_i$. Then\n  \\[\n    \\psi_Y(t)\n    =\\prod_{i=1}^n \\psi_{X_i}(t)\n    =\\left(1-\\beta t\\right)^{-n},\n  \\]\n  which by the previous problem is the MGF of a $\\text{Gamma}(n,\\beta)$\n  distribution.\n\\end{ex}\n", "meta": {"hexsha": "56096d32e7b80605b09d10aba074921bd0d63296", "size": 28460, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/ch03.tex", "max_stars_repo_name": "dtrifuno/all-of-stats-solutions", "max_stars_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/tex/ch03.tex", "max_issues_repo_name": "dtrifuno/all-of-stats-solutions", "max_issues_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tex/ch03.tex", "max_forks_repo_name": "dtrifuno/all-of-stats-solutions", "max_forks_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.5613207547, "max_line_length": 201, "alphanum_fraction": 0.4723120169, "num_tokens": 11894, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7306894099025102}}
{"text": "\n\\section{The A* Algorithm}\n\nThe A* algorithm is a solution to the single source shortest path problem. It is applied on a graph (directed or undirected) with various costs for all the edges of the graph. A* finds the path of edges from a given source and goal node that minimizes the total sum of the edge costs.\n\\newline\\newline\nIt improves on algorithms like Dijkstra's algorithm by using a heuristic to help guide the search for the end goal. Every node $n$ in the set of vertices $V$ has a distance $g(n)$ from the source node that was discovered by exploring the different paths from the start to $n$. There is also a heuristic function $h$ such that $h(n)$ represents an estimate of the remaining distance to the goal node. Nodes on the frontier of the search are placed on a priority queue. They are then picked to be explored from the frontier based on a combination of the cost and heuristic functions: \n$$f(n) = g(n) + h(n)$$\nBy using $f(n)$ to prioritize nodes that we believe are more likely to reach the goal faster, we are able to expand fewer nodes and find the least cost path more efficiently then Dijkstra's algorithm.\n\\newline\\newline\nIn order to ensure that we have an accurate estimate of the priority of a node, we need our heuristic to be consistent in order for the A* algorithm to generate a provably correct output. A heuristic is consistent if for a node $s$ and any of its neighbors $s'$, it satisfies the following inequality:\n$$f(s) \\le d(s, s') + f(s')$$\nwhere $d(s, s')$ is the distance between the two nodes.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{figures/astar.png}\n    \\caption{A* workflow}\n    \\label{fig:astar}\n\\end{figure}\n\n\\section{Algorithm (GA*)\\cite{paper}}\n\nThe A* algorithm as described above is \\textbf{not amenable to parallelization}. The priority queue requires that only the topmost entry in the priority queue be used for exploration. As a result, it is not possible to create a parallel version of the algorithm described above without changing the data structures.\\newline\\newline\nGA* is a general version of A* that can be run in a parallel setting. We present the pseudocode of our algorithm below:\n\n\\begin{verbatim}\nlet GA start target =\n    let Q = {q1, q2, ..., qk}       // set of priority queues (open list)\n    let H = {}                      // global hash table (close list)\n    let m = None                    // state pointer (found goal)\n    \n    q1.push(start)\n    while not all q in Q empty do\n        let S = []                  // global list (expanded states)\n        \n        parallel for i in [0, k] do\n            if qi empty then break\n            \n            // every thread expands one state\n            let si = qi.pop()\n            \n            // update goal state if found state is shorter path to goal\n            if si = t then\n                if m = None or si.total_cost < m.total_cost then\n                    m <- si\n                break\n            \n            // add neighbors\n            S.extend(s' for s' in s.next)\n        done\n        \n        // check if found goal state is closer than all other states\n        if m != None and m.total_cost <= min si.total_cost then return m.path\n        \n        // remove expanded states that have already been seen cheaper\n        parallel for i in [0, s.length] do\n            if si in H and H[si] < si.path_cost then s.pop(i)\n        done\n        \n        parallel for i in [0, s.length] do\n            // push si to some q in Q evenly\n            Q.push(si)\n            \n            // store seen expanded paths\n            H[si] <- si.path_cost\n        done\n    done\n    return m\n\n\\end{verbatim}\nAt a high level, this algorithm uses \\textbf{multiple priority queues} to generate a path between the start state and goal state. An explicit graph data structure is unnecessary in this scenario as we can determine neighbor states from the current state (and anyways, an explicit graph structure would be very much too large in scenarios that would motivate parallelization on this scale).\\newline\\newline\nThe pseudocode is commented at each step, but the high level idea is that each thread has its own priority queue of states. Each thread expands the top node of its own priority queue, checks if it has reached a goal state and if it has been visited already and expands the neighbors of this state.\\newline\\newline\nWhen states are expanded, the number of states grows exponentially, resulting in a smoothing of the states distribution across all of the threads. This results in \\textbf{state duplication} among independent threads that may separately want to push the same state onto the frontier. To handle this, we need to keep track of which nodes have been explored and/or will be on the frontier. We utilize the global hash table (described below) for this purpose.\n\n\\section{Data Structures}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{figures/gastar_ds.png}\n    \\caption{GA* workflow with relevant data structures (based on \\cite{paper})}\n    \\label{fig:gastar_ds}\n\\end{figure}\n\n\\subsection{Serial}\nStandard libraries cannot be used in CUDA code due to GPU memory working differently than CPU memory. Thus, certain serial data structures need to be re-implemented to accommodate for this.\n\\subsubsection{Unbounded Array}\nThis structure is used to generate the path to the goal state once the algorithm terminates. Thus, unlike a standard unbounded array, it only requires a \\texttt{push} operation. It has a growth factor of $2$ (resize to double its original size).\n\\subsubsection{Priority Queue (Heap)}\nEvery thread contains their own priority queue for expanding states. These are min-heaps (for retrieving closest perceived state) that operate on top of an unbounded array structure (same as above, but with a shrinkage factor of $2$ as well). In accordance with the above algorithm, they have \\texttt{pop}, \\texttt{push}, and \\texttt{is\\_empty} operations.\n\\subsection{Parallel}\n\\subsubsection{Hash Table (Parallel Hashing with Replacement)\\cite{paper}}\nThis structure is used to keep a global collection of visited states and their path costs. Because of this global attribute, this is the bottleneck in the algorithm. A standard hash table contains an unbounded array of linked lists, but the structure's dynamic nature (on item inserts) makes it extremely difficult to parallelize. To tackle this problem, we implement parallel hashing with replacement\\cite{paper} which uses a static list and multiple hash functions. The second hash function can search for new locations in the table for a node if another element collides with it in the first hash function. Our rationale for choosing this structure is explored in the Approach chapter. As in a standard hash table, this has assignment, existence, and modification operations. These operations are allowed to run in parallel with one another and must be thread-safe.\n\n\\section{Workload}\nIn the sequential algorithm for A*, a single priority queue is used to determine the next state to extract. Since node neighbors are fully dependent on the nodes within the priority queue, this data structure becomes the bottleneck if we were to parallelize the algorithm. If instead (as demonstrated in the pseudocode), we allow for states to be expanded independently of one another using multiple independent priority queues, we will allow for duplicate expansions. Thus, especially for large problem spaces, the approach is massively parallel.\\newline\\newline\nSince each thread operates independently in the sense that they expand nodes without dependencies on nodes held by other threads, \\textbf{this program is task parallel}. Locality and vector instructions are not as relevant due to this.", "meta": {"hexsha": "037a7a67e4a23b5380b0437cc9573b18bf2d8e20", "size": 7738, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "latex_files/Chapters/Background.tex", "max_stars_repo_name": "parallel-search/a-star", "max_stars_repo_head_hexsha": "0d8f940d9826b8abac5944c65845cb8e96f63f1e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "latex_files/Chapters/Background.tex", "max_issues_repo_name": "parallel-search/a-star", "max_issues_repo_head_hexsha": "0d8f940d9826b8abac5944c65845cb8e96f63f1e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "latex_files/Chapters/Background.tex", "max_forks_repo_name": "parallel-search/a-star", "max_forks_repo_head_hexsha": "0d8f940d9826b8abac5944c65845cb8e96f63f1e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 80.6041666667, "max_line_length": 868, "alphanum_fraction": 0.7321013182, "num_tokens": 1684, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579722, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.7306894089021818}}
{"text": "\\lstset{language=Matlab,%\n%basicstyle=\\color{red},\nbreaklines=true,%\nmorekeywords={matlab2tikz},\nkeywordstyle=\\color{blue},%\nmorekeywords=[2]{1}, keywordstyle=[2]{\\color{black}},\nidentifierstyle=\\color{black},%\nstringstyle=\\color{mylilas},\ncommentstyle=\\color{mygreen},%\nshowstringspaces=false,%without this there will be a symbol in the places where there is a space\nnumbers=left,%\nnumberstyle={\\tiny \\color{black}},% size of the numbers\nnumbersep=9pt, % this defines how far the numbers are from the text\nemph=[1]{for,end,break},emphstyle=[1]\\color{blue}, %some words to emphasise\n%emph=[2]{word1,word2}, emphstyle=[2]{style},    \n}\n\n\\begin{appendices}\n    \\section{Matlab code}\n        \\subsection{MinOver algorithm}\n        \\begin{lstlisting}[language=Matlab]\n            function [w, n_updates] = minover(X, y, n_max)\n                % TRAIN_PERCEPTRON Train a perceptron on the dataset X, y for at most\n                % (n_max * P) epochs using the MinOver algorithm.\n            \n                % stop the training unless at least one component of the weights\n                % vector does not change significantly\n                min_update = 0.001;\n                \n                % extract the number of examples P and number of dimensions (N)\n                P = size(X, 1);\n                N = size(X, 2);\n                \n                % initialize the weights to zero\n                w = zeros(N, 1);\n            \n                % repeat training for any epochs\n                epochs = n_max * P;\n                for epoch = 1:epochs\n                    \n                    % compute stabilities k^{v(t)}\n                    % NB: we do NOT divide by |w| since it is a constant for all\n                    % examples and we only want to take the examples with the lowest\n                    % stability\n                    stabilities = (X * w) .* y;\n                    \n                    % keep track of the old weight we use this to stop the training\n                    % if the weights do not change significantly for a training step\n                    old_w = w;\n                    \n                    % extract the example with lowest stability\n                    [~, index] = min(stabilities);\n                    \n                    % perform a Hebbian update step of the weights\n                    example = X(index, :);\n                    label = y(index);\n                    w = old_w + (example' * label) / N;\n                    \n                    % stopping criteria: stop if there is no significant update\n                    if all(norm(old_w - w) / norm(w) < min_update)\n                        break\n                    end\n                end\n                \n                % we return the effective number of updates to complete the training\n                n_updates = epoch;\n            end\n        \\end{lstlisting}\n\n        \\newpage\n        \\subsection{Dataset generation basic implementation}\n        \\begin{lstlisting}[language=Matlab]\n            function [X, y] = generate_dataset(P, N, w_star)\n               X = randn(P, N);\n               y = sign(X * w_star);\n            end\n        \\end{lstlisting}\n\n        \\subsection{Dataset generation noisy data}\n        \\begin{lstlisting}[language=Matlab,label={code:dataset_noise}]\n            function [X, y] = generate_dataset(P, N, w_star, lambda)\n                prob = rand(P, 1);\n                noise = iff(prob < lambda, -1, +1);\n                X = randn(P, N);\n                y = sign(X * w_star) .* noise;\n            end\n        \\end{lstlisting}\n\n\\end{appendices}\n", "meta": {"hexsha": "227524ddf720194b41daa691ab46994b5f787a78", "size": 3587, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_2/report/07_appendix.tex", "max_stars_repo_name": "davidepedranz/neural_networks_assignments", "max_stars_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_2/report/07_appendix.tex", "max_issues_repo_name": "davidepedranz/neural_networks_assignments", "max_issues_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_2/report/07_appendix.tex", "max_forks_repo_name": "davidepedranz/neural_networks_assignments", "max_forks_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.8555555556, "max_line_length": 96, "alphanum_fraction": 0.5154725397, "num_tokens": 798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7306532445348273}}
{"text": "If you haven't downloaded and unzipped \\href{https://libaoj.in/courses/2021f/MATH3341/zip/Math.3341.zip}{\\texttt{Math.3341.zip}}. Download and unzip it under \\verb|H:| (H Drive if you are working on the Remote Lab). Change the current working directory by typing \\verb|cd H:\\Math.3341\\Math.3341.Lab.08| in the Command Window, and type \\verb|edit lab_08_script| in the Command Window to edit \\verb|lab_08_script.m|.\n\n%---------------------------------------------\n\\section{Polynomial Interpolation Routines}\n%---------------------------------------------\n\\begin{enumerate}[(a)]\n    \\item Fit \\verb|xdata| and \\verb|ydata| by an \\verb|n|th order polynomial using \\verb|polyfit|. Then use \\verb|polyval| to evaluate the polynomial at \\verb|x|.\n    \\item Evaluate the cubic spline of \\verb|xdata| and \\verb|ydata| at \\verb|x| using \\verb|spline| command.\n    \\item Now use the \\verb|pchip| command to find the values of the piecewise cubic Hermite interpolating polynomial at \\verb|x|.\n    \\item Make a copy of your implementation of Lagrange interpolation for Homework 5. Use your function to find the function values of the Lagrange interpolation polynomial at \\verb|x|.\n    \\item Uncomment ``3 Plot interpolation polynomials\" section, which will create the figure comparing each of the polynomial interpolations. If you cannot get your Lagrange interpolation polynomial to work, comment in the relevant lines of code that plot that figure. Expected plot is shown in Figure \\ref{fig:1}.\n\\end{enumerate}\n\\section{Derivatives of Interpolation Polynomials}\n\\begin{enumerate}[(a)]\n\\item \\label{enum:II1} Use \\verb|polyder| to calculate the coefficients of the first derivative of the interpolation polynomial given by \\verb|polyfit| that you constructed, and evaluate it at \\verb|x| using \\verb|polyval|.\n\\item Repeat \\eqref{enum:II1} to find the second derivative of the interpoation polynomial.\n    \\item Fit \\verb|xdata| and \\verb|ydata| using cubic spline and store the structure of the cubic spline interpolation polynomial to \\verb|cs_struct|.\n    \\item Using slicing technique to extract the columns of \\verb|cs_struct.coefs| which correspond to each coefficient of the piecewise cubic spline, and store each of these columns in \\verb|b|, \\verb|c|, \\verb|d|, respectively.\n    \\item Use these coefficients along with \\verb|xdata|, \\verb|x| to evaluate the first and second derivatives of the spline using \\verb|cubic_spline_der.m|. Use \\verb|help cubic_spline_der| to get details of the function.\n    \\item Uncomment ``4 Plot derivatives\" section to generate corresponding plots. Expected plot is shown in Figure \\ref{fig:2}.\n\\end{enumerate}\n\nAt the end of the day, upload \\verb|lab_08_script.m|, \\verb|lab_08_figure_01.pdf| and \\verb|lab_08_figure_02.pdf| to Overleaf (make sure you change the caption for the figures), then recompile, and submit the generated .pdf file on WyoCourses.\n\n\\begin{figure}[!hbtp]\n    \\centering\n    \\includegraphics[width=\\textwidth]{../Math.3341.Lab.08.ans/lab_08_figure_01.pdf}\n    \\caption{Polynomial Interpolation using different routines}\n    \\label{fig:1}\n\\end{figure}\n\\begin{figure}[!hbtp]\n    \\centering\n    \\includegraphics[width=\\textwidth]{../Math.3341.Lab.08.ans/lab_08_figure_02.pdf}\n    \\caption{Derivatives of Interpolation Polynomials}\n    \\label{fig:2}\n\\end{figure}\n", "meta": {"hexsha": "0a389d27abda38c1bb8d0667a32649b6b6561c9d", "size": 3314, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/Math.3341.Lab.08/exercise/body.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/Math.3341.Lab.08/exercise/body.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/Math.3341.Lab.08/exercise/body.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 89.5675675676, "max_line_length": 414, "alphanum_fraction": 0.7450211225, "num_tokens": 865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936879, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7305566221098467}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[english]{babel}\n\\usepackage{graphicx, amsmath, mathtools, listings, color, caption, rotating, subfigure, fullpage, textcomp, enumerate, float}\n\n\\begin{document}\n\\section*{Problem 1}\n\\begin{enumerate}[(a)]\n\\item Calculate sample mean $\\bar Y$, standard deviation $s$ and median $\\hat\\theta$.\n\\[ \\bar{y}=3.06, sd=2.257, \\hat{\\theta}=2.375 \\]\n\n\\item Carry out a t-test of the hypothesis $H_0: \\mu=3$ vs $H_a: \\mu<3$.\nFind the p-value and state your conclusions at $\\alpha=0.05$.\n\\[ t^*=\\frac{\\bar{y}-\\mu}{sd/\\sqrt{n}}=\\frac{3.06-3}{2.257/\\sqrt{20}}=0.1189 > -t(0.95,19)=-1.73 \\]\n\\[ \\text{p-value} = 0.5467 \\Rightarrow \\text{Do NOT reject } H_0 \\] \n\n\\item Calculate the 95\\% t-interval for $\\mu$.\n\\[ \\text{CI: } \\bar{Y} \\pm t(0.975,19) \\frac{sd}{\\sqrt{n}} = 3.06 \\pm 2.093 \\frac{2.257}{\\sqrt{20}} = (2.0036,4.116) \\]\n\n\\item Test the hypothesis $H_0: \\theta=3$ vs $H_a:\\theta<3$ using the binomial test at\n$\\alpha=0.05$. State your conclusion.\n\n\\emph{Let T be the number of observations that are less than $3.0$, so that $T = 14$}\n\\begin{align*}\nZ_B &= \\frac{14-10}{\\sqrt{0.25(20)}} = 1.788 > 1.645 = Z(0.95) \\\\\n&\\Rightarrow \\text{Reject } H_0 (\\text{p-value } \\approx 0.05)\n\\end{align*}\n\n\\emph{Or calculate an exact p-value based on the Binomial Distribution: }\n\\[ P \\left. \\left(T \\geq 15 \\right| T \\sim Bin(20, .5) \\right) = \\sum_{i=15}^{20} \\binom{20}{i}0.5^i0.5^{20-i} = 0.021\\]\n\n\\item Find a 95\\% confidence interval for $\\theta$ using the normal approximation\nto the binomial distribution.\n\\begin{align*}\n& \\frac{a-0.5(20)}{\\sqrt{0.25(20)}}=-Z_{0.975}, \\qquad \\frac{b-1-0.5(20)}{\\sqrt{0.25(20)}}=Z_{0.975} \\\\\n& \\Rightarrow a = 5.617 \\text{ and } b = 15.382 \\\\\n& \\Rightarrow 95\\% \\text{ CI: } (X_{(6)}, X_{(15)})=(1.8, 3.0) \\tag*{(With the common rounding method)}\\\\\n& \\text{Or: } (X_{(5)}, X_{(16)})=(1.65, 3.2) \\tag*{(With floor lower bound the ceiling upper bound)}\n\\end{align*}\n\n\\item When should you use a nonparametric test and does this apply to the data in this problem?\n\n\\emph{Non-parametric is used when assumptions of parametric test are not met (i.e normal distribution and homogeneity of variances across groups) \\\\\nIn this problem, our data set is nor large neither normal, so non-parametric test is suitable.}\n\\end{enumerate}\n\n\\section*{Problem 2}\nThe data in the following table compare reaction times (in seconds) of participants in front\nof a computer screen. Participants in sample 1 have been given decaffeinated coffee while sample\n2 has been given regular coffee.\n\n\\begin{enumerate}[(a)]\n\\item Calculate sample means $\\bar X$ and $\\bar Y$ as well as sample medians $\\hat\\theta_X$ and $\\hat\\theta_y$ where $X_1,..,X_8$ refer to sample 1 data and $Y_1,..,Y_4$ to sample 2 data.\n\n\\[ \\bar{X}=11.75, \\bar{Y}=8.75, \\hat{\\theta_x}=10, \\hat{\\theta_y}=9 \\]\n\n\\item Carry out a two-sample t-test for the hypothesis $H_0:\\mu_Y=\\mu_X$ vs $H_a:\\mu_Y>\\mu_X$ at $\\alpha=0.05$. State your conclusions.\n\n\\[t^*=\\frac{\\bar{Y}-\\bar{X}}{\\sqrt{\\frac{s_x^2}{8}}+\\frac{s_y^2}{4}}=\\frac{8.75-11.75}{\\sqrt{66.21/8+8.916/4}}=-0.9256 \\]\n\n\\[ df= \\frac{(\\frac{s_x^2}{n_1}+\\frac{s_y^2}{n_2})^2}{(\\frac{s_x^2}{n_1})^2/(n_1-1)+(\\frac{s_y^2}{n_2})^2/(n_2-1)}=9.646 \\]\n\nSince $t^* = -0.9256 < t(0.95,9.646) = 1.81923$, we do NOT reject $H_0$, and its p-value  is 0.8114.\n\n\\textbf{NOTE: } There is a simpler way of calculating the degrees of freedom in an unpooled $t$-test. Instead of this crazy calculation, one method that will always give you a lower bound on the degrees of freedom is $df = \\min(n, m) - 1$. This is less powerful than the approximate df above, but is far easier to calculate.\n\n\\item Calculate a 95\\% CI for $\\mu_Y-\\mu_X$ based on the t-distribution. Assume unequal variances.\n\n\\[ \\text{CI: } (\\bar{Y}-\\bar{X}) \\pm t(0.975,9.646) \\sqrt{ \\frac{s_x^2}{8} + \\frac{s_y^2}{4} } = (-10.258, 4.258) \\]\n\n\\item Carry out the Wilcoxon test at $\\alpha=0.05$ for the hypothesis in (b).\n\\begin{align*}\n& W(\\text{sum of Rank } S_1)=1+3+4+6+8+10+11+12=55 \\\\\n& \\text{From table A3 } (m=4, n=8), 5\\% \\text{ Upper } = 63\\\\\n& \\text{Since } 55<63 \\Rightarrow \\text{ do NOT reject } H_0\\\\\n\\end{align*}\n\\vspace{-3em}\n\n\\item Find the Hodges-Lehmann estimate of $\\theta_Y-\\theta_X$ and a 90\\% CI.\n\nOrdered pairwise differences of $(Y_j-X_i)$ : \n\\begin{table}[H] \\center\n\\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|} \\hline\n-25 &-22& -20 &-18  &-9&  -8 & -6  &-6 & -5 & -4  &-4 & -3 \\\\ \\hline\n -3 & -2 & -2& -1 & -1  &-1 & -1  & 1  & 1  & 1  & 1 &  2 \\\\ \\hline\n 3 & 3 &  4  & 4  & 5  & 6&6&8&&&&\\\\ \\hline\n\\end{tabular}\n\\end{table}\nFrom Table A4, $l_{0.05}=5, U_{0.05}=27$\\\\\n$k_a=6, k_b=27 \\Rightarrow 90\\%$ CI : $(-8,4)$\n\n\\item Calculate the exponential scores and find the p-value for the hypothesis in (b).\n\n\\emph{Observed Exponential Scores: }\n\\begin{table}[H] \\center \\footnotesize\n\\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|} \\hline\nSample:\t\t\t& S1 & S1 & S1 & S1 & S1 & S1 & S1 & S1 & S2 & S2 & S2 & S2 \\\\ \\hline \nValue:\t\t\t& 4 &  6 &  7 &  9 & 11 & 13 & 14 & 30 &  5 &  8 & 10 & 12 \\\\ \\hline\nSavage Score:\t& -0.917 & -0.726 & -0.615 & -0.347 &  0.020 &  0.603 &  1.103 &  2.103 & -0.826 & -0.490 & -0.180 &  0.270 \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\n\\vspace{-3em}\n\\begin{align*}\n& D_{obs} \\text{(sum exponential scores of S1) } = 1.224 \\\\\n& p\\text{-value} = 0.7657 \\Rightarrow \\text{do NOT reject } H_0\n\\end{align*}\n\n\\item Test the hypothesis $H_0:\\sigma_1=\\sigma_2$ vs $H_a:\\sigma_1>\\sigma_2$ using the the Siegel-Tukey test at $\\alpha=.05$.\n\\emph{Note that our estimates of $\\sigma_1$ and $\\sigma_2$ are $8.137$, and $2.986$.}\n\\begin{align*}\n& W(\\text{Sum of Siegel-Tukey Rank}) = 1+5+8+12+10+6+3+2 = 47 \\\\\n& \\text{From Table A3}, 5\\% \\text{ lower} = 41 \\Rightarrow \\text{Do NOT reject } H_0. \\\\\n\\end{align*}\n\n\\item Use the Kolomogorov-Smirnov statistic to test $H_0: F_X(x) = F_Y(x)$ vs $H_a: F_X(x) \\neq F_Y(x)$ at $\\alpha=0.05$.\n\\begin{table}[H] \\center\n\\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|} \\hline\nData&4&5 &6& 7& 8& 9 &10& 11 &12&13&14&30\\\\ \\hline\n$\\hat{F_x}$&1/8&1/8&1/4&3/8& 3/8&1/2&1/2&5/8&5/8&6/8&7/8&1\\\\ \\hline\n$\\hat{F_y}$&0&1/4&1/4&1/4& 1/2&1/2&3/4&3/4&1&1&1&1\\\\ \\hline\n$|\\hat{F_x}-\\hat{F_y}|$ &1/8&1/8&0&1/8&1/8&0&1/4&1/8&\\textbf{3/8}&1/4&1/8&0\\\\ \\hline\n\\end{tabular}\n\\end{table}\n\\emph{ Therefore, $\\text{(K-S)}_{obs}=\\frac{3}{8}$ and $p\\text{-value } = 0.8364 \\Rightarrow$ Do NOT reject $H_0$. }\n\\end{enumerate}\n\n\\newpage\n\\section*{Problem 3}\n\\begin{enumerate}[(a)]\n\\item Restate the hypothesis $H_0: \\mu_1 = \\mu_2$ vs. $H_a: \\mu_1 < \\mu_2$ in terms of $F_1(x)$ and $F_2(x)$. Be precise in your statement.\n\n\\emph{If two populations have the same family of distribution and the same parameters, it should be clear that the CDFs will also be the same. This means that the null hypothesis may be equivalently re-written $H_0: F_1(x) = F_2(x)$. However, consider the alternative hypothesis, where $\\mu_1 < \\mu_2$. This means that the average for population 1 is less than the average of population 2. For at least point $x$, this means that there was less``mass'' of the distribution in population 1 to the right of $x$ in population 1 than population 2 (because the mean is smaller in population 1). Since there is less mass to the right in population 1, this means that there is more mass to the left, and thus, a higher probability of a value being less than $x$ than in population 2. Translated to math, this means for at least one point $x$, $H_a: F_1(x) > F_2(x)$.}\n\n\\item Suppose in part (a) the alternative hypothesis is two-sided. How can this alternative be expressed in terms of $F_1(x)$ and $F_2(x)$?\n\n\\emph{A two-sided alternative is expressed as a combination of two one-sided alternatives, allowing one distribution to dominate the other, or vice versa, but not allowing the distributions to alternate which one dominates the other. $H_a: F_1(x) > F_2(x)$ for at least one $x$ (and equal for everything else), {\\bf or} $F_1(x) > F_2(x)$ for at least one $x$, (and all other points equal).}\n\n\\item Explain the difference between a skewed distribution and a heavy-tailed distribution.\n\n\\emph{A skewed distribution is one in which the mean and median do not equal each other. This happens in distributions that are not symmetric, like the $\\chi^2$ or Exponential.}\n\n\\emph{A heavy-tailed distribution is one in which the tails of the distribution (the parts of the distribution that are far away from the mean or median) do not drop quickly. Formally, this means that there is still a significant amount of probability for extreme values of the random variable. Practically, this means there is a higher chance of seeing very large values than similar thin-tailed distributions.}\n\n\n\\item Calculate the power for a normal test with known variance when testing $H_0: \\mu = 0$ vs. $H_a: \\mu < 0$ when the true mean is $\\mu=-5$ and the variance is $\\sigma^2 =9$ for a sample of size $n = 15$ from a normal distribution. Use $\\alpha = .05$. Calculate the power of the binomial test for this problem.\n\n\\emph{Recall that power is the probability that we correctly reject the null hypothesis when the alternative hypothesis is true. In this problem, we would reject the null hypothesis if $\\sqrt{n} (\\bar{x} - \\mu_0) / \\sigma < -z_{1-\\alpha}$. We would need to find the probability that this happened, given that the true mean was $\\mu=-5$.}\n\n\\begin{align*}\n&P \\left. \\left(\\frac{\\sqrt{n} (\\bar{x} - \\mu_0)}{\\sigma} < -z_{1-\\alpha} \\right| \\mu=-5 \\right) \n= P\\left. \\left(\\frac{\\sqrt{15} (\\bar{x})}{3} < -z_{1-\\alpha} \\right| \\mu=-5 \\right) \\\\\n&= P \\left. \\left(\\frac{\\sqrt{15} (\\bar{x})}{3} - \\frac{\\sqrt{15} \\cdot (-5)}{3} < -z_{1-\\alpha} - \\frac{\\sqrt{15} \\cdot (-5)}{3} \\right| \\mu=-5 \\right) \\\\\n&= P \\left. \\left(\\frac{\\sqrt{15} (\\bar{x} + 5)}{3} < -z_{1-\\alpha} - \\frac{\\sqrt{15} \\cdot (-5)}{3} \\right| \\mu=-5 \\right)\n\\end{align*}\n\\emph{At this point, note that under the alternative hypothesis, the left side is now a standard normal, and we can use a Z table.}\n\\begin{align*}\nP \\left(Z < -z_{1-\\alpha} + \\frac{5 \\sqrt{15}}{3} \\right) = \\Phi \\left(-z_{1-\\alpha} + \\frac{5 \\sqrt{15}}{3} \\right)\n\\end{align*}\n\\emph{For $\\alpha=.05$, this probability is $\\Phi\\left( 4.81 \\right) \\approx 1$.}\n\n\\emph{For the binomial test, we must find the probability of observing a value less than the null hypothesis median, given that the true median is determined by the alternative, with given variance. That is, if $p$ is the probability of seeing a value greater than the median of $0$,}\n\\begin{align*}\np &= P \\left. \\left( X < 0 \\right| \\mu=-5 \\right) \\\\\n& = P \\left. \\left( \\frac{X+5}{3} < \\frac{5}{3} \\right| \\mu=-5 \\right) \\\\\n& = P \\left( Z < \\frac{5}{3} \\right) = 0.952.\n\\end{align*}\n\\emph{Plugging into the power equation for a binomial test from Page 20, }\n\\begin{align*}\n\\mbox{Power of Binomial Test} \n& = 1-\\Phi \\left( 1.645 \\sqrt{\\frac{.25}{p(1-p)}} - \\frac{p-.5}{\\sqrt{p(1-p)/n}} \\right)\\\\\n& = 1-\\Phi \\left( -4.342 \\right) \\approx 1.\n\\end{align*}\n\n\\item Calculate the power for a Binomial test with known variance when testing $H_0: \\mu = 0$ vs. $H_a: \\mu < 0$ when the true mean is $\\mu=−5$ and the variance is $\\sigma^2 =9$ for a sample of size $n = 15$ from a Laplace distribution. Use $\\alpha = .05$. \n\n\\emph{First we need to find the probability that a single observation is less than the mean under the null hypothesis, using the Laplace distribution with mean $-5$ and variance $9$.}\n\\begin{align*}\np &= P \\left. \\left( X < 0 \\right| X \\sim Laplace(\\mbox{mean}=-5, \\mbox{var} = 9) \\right) \\\\\n&= P \\left. \\left( \\frac{X+5}{3} < \\frac{5}{3} \\, \\right| X \\sim Laplace(\\mbox{mean}=-5, \\mbox{var} = 9) \\right) \\\\\n& = 1 - \\frac{1}{2} \\exp \\left( - \\sqrt{2} \\frac{\\frac{5}{3}-\\mu} {\\sigma} \\right) \\tag*{(Found this CDF on Wikipedia's Laplace page)}\\\\\n& = 1 - \\frac{1}{2} \\exp \\left( - \\sqrt{2} \\frac{\\frac{5}{3}+5}{3} \\right) = 0.978\n\\end{align*}\n\\emph{The power of the binomial test is then an exercise in plugging in the right values from the formula on Page 20.}\n\\begin{align*}\n\\mbox{Power of Binomial Test} \n& = 1-\\Phi \\left( 1.645 \\sqrt{\\frac{.25}{p(1-p)}} - \\frac{p-.5}{\\sqrt{p(1-p)/n}} \\right)\\\\\n& = 1-\\Phi \\left( -7.014 \\right) \\approx 1.\n\\end{align*}\n\\emph{A final table to illustrate the Power, under Normality and under (...ahem...) Laplace-ality. Notice that the Z-test is superior if the data is truly normal, but the Binomial Test does much better than the usual Z-test if the data is not normal (Laplace).}\n\\begin{table}[H] \\center\n\\begin{tabular}{|c|c|c|} \\hline \n\\multicolumn{3}{|c|}{Power of Tests under Different Distributions} \\\\ \\hline \n• & Normal & Laplace \\\\ \\hline \nCLT & $\\Phi\\left( 4.81 \\right)$ & $\\Phi\\left( 4.81 \\right)$ \\\\ \\hline \nBinomial Test & $\\Phi \\left( 4.34 \\right)$ & $\\Phi \\left( 7.01 \\right)$ \\\\ \\hline \n\\end{tabular} \n\\end{table}\n\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "d6ece9035872fe1e969627819cd8fcba9e167527", "size": 12755, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Primers and Walkthroughs/SampleMidtermSOLN.tex", "max_stars_repo_name": "christopheraden/Nonparametric-Statistics", "max_stars_repo_head_hexsha": "15fb5ec1cbae0e00649237a944602932f6ebaedf", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Primers and Walkthroughs/SampleMidtermSOLN.tex", "max_issues_repo_name": "christopheraden/Nonparametric-Statistics", "max_issues_repo_head_hexsha": "15fb5ec1cbae0e00649237a944602932f6ebaedf", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Primers and Walkthroughs/SampleMidtermSOLN.tex", "max_forks_repo_name": "christopheraden/Nonparametric-Statistics", "max_forks_repo_head_hexsha": "15fb5ec1cbae0e00649237a944602932f6ebaedf", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.0954773869, "max_line_length": 860, "alphanum_fraction": 0.6590356723, "num_tokens": 4785, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7305566184742815}}
{"text": "\\chapter{Basic Operations in Riemannian Space}\n\\pagebreak[4]\n\n\\section{p27-exercise}\n\n\\begin{tcolorbox}\nTake polar coordinates $r, \\theta$ in a plane. Draw the infinitesimal triangle with vertices $(r,\\theta)$, $(r+dr,\\theta)$, $(r,\\theta + d\\theta)$. Evaluate the square on the hypotenuse of this infinitesimal triangle, and so obtain the metric tensor for the plan for the coordinates$(r, \\theta)$.\\end{tcolorbox}\n\\begin{figure}[htp] \n    \\centering\n%\\includegraphics[scale=.5]{polar.jpg}\n\\input{D:/MathLatex/images/fig_p27_21_a.tex}\n\\caption{Metric tensor in polar coordinate system}\n\\label{fig:fig_p27_21_a}\n\\end{figure}\n\\begin{align} \n\\ ds^2 &= |AB|^2\\\\\n\\ &= dr^2 +|CA|^2\\\\\n\\ |CA| &= r\\sin(d\\theta)\\approx rd\\theta\\\\\n\\Rightarrow ds^2 &= dr^2 + r^2d\\theta^2\\\\\n\\Rightarrow (a_{mn}) &= \\begin{pmatrix}\n 1& 0 \\\\\n0 & r^2 \\\\\n\\end{pmatrix}\n\\end{align}\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p27-exercise}\n\n\\begin{tcolorbox}\nShow that if $x^1 = r, x^2 = \\theta, x^3 = \\phi$, in the usual notation of spherical polar coordinates, then $$ a_{11} =1, a_{22} = r^2, a_{33} = r^2\\sin^2\\theta$$ and the other components vanish.\n\\end{tcolorbox}\nOne can choose to start from $ds^2 = dx^2+dy^2+dz^2$ and then expanding the $dx^i$ along $(r,\\theta,\\phi)$ but this a rather tedious way. So we use a more geometrical way of deriving the metric\\\\\n\\begin{figure}[htp] \n    \\centering\n\\input{D:/MathLatex/images/fig_p27_22_a.tex}\n\\caption{Metric tensor in spherical coordinate system}\n\\label{fig:fig_p27_22_a}\n\\end{figure}\n%\\includegraphics[scale=.6]{sphericalmetric.jpg}\\\\\\\\\nConsider an infinitesimal displacement of point E to J with $(dr,d\\theta, d\\phi )$.\n\\begin{align}\n\\ ds^2 &= |EJ|^2\n\\end{align}\nAs we use infinitesimal displacements we can assume that $$|ES|\\perp|GK|\\perp|JK|\\perp|ES|$$. Hence,\n\\begin{align}\n\\ ds^2 = |ES|^2+|SK|^2+|KJ|^2\n\\end{align}\nWe have the following relationships\n\\begin{align}\n\\left.\n\\begin{array}{c}\n\\ |GE| = |GS| = r\\sin\\theta\\\\\\\\\n\\ |ES| = |GE|d\\phi = r\\sin\\theta d\\phi\\\\\\\\\n\\ |GK| = |RJ| = (r+dr)\\sin(\\theta+d\\theta) \\\\\n\\ =(r+dr)(\\cos(\\theta)\\sin(d\\theta)+\\sin(\\theta)\\cos(d\\theta) )\\\\\n\\ = (r+dr)(\\cos(\\theta)d\\theta+\\sin(\\theta))\\\\\n\\ = r\\cos(\\theta)d\\theta+r\\sin(\\theta)+\\sin(\\theta)dr\\\\\\\\\n\\ |OR| =  (r+dr)\\cos(\\theta+d\\theta)\\\\\n\\ = (r+dr)(\\cos(\\theta)\\cos(d\\theta)-\\sin(\\theta)\\sin(d\\theta))\\\\\n\\ = (r+dr)(\\cos(\\theta)-\\sin(\\theta)d\\theta)\\\\\n\\ = r\\cos(\\theta)-r\\sin(\\theta)d\\theta + \\cos(\\theta)dr\\\\\\\\\n\\ |OG| = r\\cos(\\theta)\\\\\\\\\n\\ |JK| = |OR|-|OG| = \\cos(\\theta)dr-r\\sin(\\theta)d\\theta\\\\\\\\\n\\ |SK| = |GK|-|GS| = r\\cos(\\theta)d\\theta+\\sin(\\theta)dr\\\\\\\\\n\\end{array}\n\\right\\}\n\\end{align}\n\\begin{align}\n\\left.\n\\begin{array}{c}\n\\ |ES|^2 = r^2\\sin^2(\\theta)d\\phi^2\\\\\n\\ |SK|^2 = r^2\\cos^2(\\theta)d\\theta^2+\\sin^2(\\theta)dr^2 +2r\\cos(\\theta)\\sin(\\theta)drd\\theta \\\\\n\\ |JK|^2 = \\cos^2(\\theta)dr^2+r^2\\sin^2(\\theta)d\\theta^2 -2r\\cos(\\theta)\\sin(\\theta)drd\\theta\\\\\n\\end{array}\n\\right\\}\n\\end{align}\nHence,\n\\begin{align}\n\\ ds^2 &= |ES|^2+|SK|^2+|KJ|^2\\\\\n&= \\left\\{ \\begin{array}{c} r^2\\sin^2(\\theta)d\\phi^2 \\\\ +r^2\\cos^2(\\theta)d\\theta^2+\\sin^2(\\theta)dr^2 +2r\\cos(\\theta)\\sin(\\theta)drd\\theta\\\\+r^2\\sin^2(\\theta)d\\theta^2+\\cos^2(\\theta)dr^2 -2r\\cos(\\theta)\\sin(\\theta)drd\\theta\\\\\n\\end{array}\n\\right.\\\\\n\\ &\\Rightarrow ds^2= dr^2 + r^2d\\theta^2 + r^2\\sin^2(\\theta)d\\phi^2\\\\\n\\ & \\Rightarrow (a_{mn}) = \\begin{pmatrix}\n 1& 0 & 0\\\\\n0 & r^2 & 0 \\\\\n0 & 0 & r^2\\sin^2\\theta \\\\\n\\end{pmatrix}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p27-exercise}\n\n\\begin{tcolorbox}\nStarting from 3.103, show that $$a_{mn} = \\pdv{y^1}{x^m}\\pdv{y^1}{x^n}+\\pdv{y^2}{x^m}\\pdv{y^2}{x^n}+\\pdv{y^3}{x^m}\\pdv{y^3}{x^n}$$ and calculate the quantities for a sphere, taking as curvilinear coordinates on he sphere $$x^1 = y^1 , x^2 = y^2$$\n\\end{tcolorbox}\nWe have\n\\begin{align}\n\\text{(2.103)}\\quad &\\Rightarrow y^1 = x^1 , y^2 = x^2, y^3 = f^3(x^1,x^2)\\\\\n\\text{surface = sphere}\\quad &\\Rightarrow y^3 = \\pm \\sqrt{R^2 -(x^1)^2-(x^2)^2}\\\\\n\\ ds^2 &= (dx^1)^2+(dx^2)^2+(dx^3)^2\\\\\n\\ \\text{(1) and (2)}\\quad& \\Rightarrow \\left\\{ \\begin{array}{c} \n\\ dy^1 = dx^1\\\\\\\\\n\\ dy^2 = dx^2\\\\\\\\\n\\ dy^3 = \\pm \\frac{1}{2} \\frac{-2x^1dx^1 - 2x^2dx^2}{\\sqrt{R^2 -(x^1)^2-(x^2)^2}}\\\\\\\\\n\\end{array}\n\\right.\\\\\n\\Rightarrow ds^2 & = (dx^1)^2 +  (dx^2)^2 + \\frac{(x^1)^2(dx^1)^2 + (x^2)^2(dx^2)^2  + 2 x^1x^2dx^1dx^2}{R^2 -(x^1)^2-(x^2)^2}\n\\end{align}\n\\begin{align}\n\\Leftrightarrow ds^2 & = \\frac{(R^2 - (x^2)^2) (dx^1)^2 + (R^2 -(x^1)^2) (dx^2)^2  + 2 x^1x^2dx^1dx^2}{R^2 -(x^1)^2-(x^2)^2}\n\\end{align}\\\\\n\\begin{align}\n\\Rightarrow (a_{mn}) &= \\frac{1}{R^2 -(x^1)^2-(x^2)^2}\\begin{pmatrix}\n R^2 - (x^2)^2&x^1x^2 \\\\\nx^1x^2 & R^2 - (x^1)^2 \\\\\n\\end{pmatrix}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p30-clarification 2.202}\n\n\\begin{tcolorbox}\n           $$\\quad\\quad a_{mr}\\Delta^{ms} = a_{rm}\\Delta^{sm} = \\delta^s_r a$$\n\\end{tcolorbox}\nCase 1: $r =s$\\\\\nWe have, $a_{Rm}\\Delta^{Rm}$ (no summation on R) is the definition of the determinant of A developed along the row R: OK.\\\\\\\\\nCase 2: $r \\neq s$\\\\\nConsider\n\\begin{align}\n\\ A &= \\begin{pmatrix}\n a_{11} & a_{12}&\\dots&a_{1N} \\\\\na_{21} & a_{22}&\\dots&a_{2N} \\\\\n\\vdots & \\vdots &\\vdots & \\vdots \\\\\na_{N1} & a_{N2}&\\dots&a_{NN} \\\\\n\\end{pmatrix}\n\\end{align}\nand consider the matrix $A^,$\n\\begin{align}\n\\ A^, &= \\begin{pmatrix}\n a_{11} & a_{12}&\\dots&a_{1N} \\\\\n \\vdots & \\vdots &\\vdots & \\vdots \\\\\na_{R1} & a_{R2}&\\dots&a_{RN} \\\\\n\\vdots & \\vdots &\\vdots & \\vdots \\\\\na_{R1} & a_{R2}&\\dots&a_{RN} \\\\\n\\vdots & \\vdots &\\vdots & \\vdots \\\\\na_{N1} & a_{N2}&\\dots&a_{NN} \\\\\n\\end{pmatrix}\n\\begin{array}{c}\n\\ \\vdots\\\\\n\\ \\vdots\\\\\n\\leftarrow S^{th}\\text{ row}\\\\\n\\vdots\\\\\n\\leftarrow R^{th}\\text{ row}\\\\\n\\ \\vdots\\\\\n\\ \\vdots\\\\\n\\end{array}\n\\end{align}\nThis matrix corresponds to the way $a_{Rm}\\Delta^{Sm}$ is computed. Indeed with the factor $a_{Rm}$ is not associated it's own cofactor $\\Delta^{Rm}$ but the cofactor of the $m^{th}$ column in row $S$. Replacing the $S^{th}$ row with the row $R$ and calculating it's determinant is the same as calculating $a_{Rm}\\Delta^{Sm}$\\\\\nBut, $|A^,| = 0$ as we have two identical rows. So, $a_{Rm}\\Delta^{Sm} = 0$\\\\\\\\\nConclusion : The same reasoning can be applied when expanding the determinant along the columns instead of the rows we have indeed $\\quad\\quad a_{mr}\\Delta^{ms} = a_{rm}\\Delta^{sm} = \\delta^s_r a$.\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p31-exercise}\n\n\\begin{tcolorbox}\nShow that if $a{mn} = 0$ for $m\\neq n$, then $$a^{11} = \\frac{1}{a_{11}}, a^{22} = \\frac{1}{a_{22}}, \\dots, a¨{12} = 0, \\dots$$\n\\end{tcolorbox}\nWe have to prove that:\n\\begin{align}\n\\ a^{ij} = \\left\\{\\begin{array}{cc}\n\\frac{1}{a_{ij}} & \\text{: }i=j\\\\\n\\ 0 & \\text{: }i \\neq j\n\\end{array}\\right.\n\\end{align}\nFrom 2.204:\n\\begin{align}\na_{mR}a_{mS} = \\delta^S_R\n\\end{align}\ni) Be $R \\neq S$\n\\begin{align}\n\\text{(2) }\\quad \\Rightarrow a_{mR}a_{mS} &= 0\\\\\n\\text{but } \\quad a_{mR} &=0\\quad \\forall m \\neq R\\\\\n\\Rightarrow a_{RR}a^{RS} = 0\n\\end{align}\nbut $a_{RR} \\neq 0$ ($a_{RR}$ can't be $0$ as the metric tensor would degenerate  if $a_{mn} = 0\\quad \\forall m \\neq n$\n\\begin{align}\n\\Rightarrow a^{Rs} = 0\\\\\\\\\n\\end{align}\n\ni) Be $R = S$\n\\begin{align}\n\\text{(2) }\\quad \\Rightarrow a_{mR}a_{mR} &= 1\\\\\n\\text{but } \\quad a_{mR} &=0\\quad \\forall m \\neq R\\\\\n\\Rightarrow a_{RR}a^{RR} = 1\\\\\n\\Rightarrow a^{RR} = \\frac{1}{a_{RR}}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p31-exercise}\n\n\\begin{tcolorbox}\nFind the components of $a^{mn}$ for spherical polar coordinates in Eulidean 3-space.\n\\end{tcolorbox}\nWe have (see exercise page 27):\n\\begin{align}\n\\ (a_{mn}) = \\begin{pmatrix}\n 1& 0 & 0\\\\\n0 & r^2 & 0 \\\\\n0 & 0 & r^2\\sin^2\\theta \\\\\n\\end{pmatrix}\n\\end{align}\nAs $a_{mn} = 0 \\quad \\forall m \\neq n$ we deduce (see previous exercise p31)\n\\begin{align}\n\\ (a^{mn}) = \\begin{pmatrix}\n 1& 0 & 0\\\\\n0 & \\frac{1}{r^2} & 0 \\\\\n0 & 0 & \\frac{1}{r^2\\sin^2\\theta)}\\\\\n\\end{pmatrix}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p32-exercise}\n\n\\begin{tcolorbox}\nFind the mixed metric tensor  $a^{.n}_m$ obtained from $a_{mn}$ by raising the second subscript\n\\end{tcolorbox}\nWe have :\n\\begin{align}\n\\ a_{i}^{.j} &=  a_{in}a^{nj}\\\\\n\\ &=  a_{in}a^{jn}\\quad a^{jn} \\text{  is symmetric}\\\\\n\\ &= \\delta^j_i \\quad \\text{ (see 2.205 pg. 30)}\\\\\n\\ &\\Rightarrow a_{i}^{.j} = \\delta^j_i \n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p32-clarification 2.214}\n\\begin{tcolorbox}\n          $$ \\pdv{a}{a_{mn}} = a a^{mn}$$\n\\end{tcolorbox}\nPut $a_{MN}\\equiv a_{mn}$. By definition, we have\n\\begin{align}\n\\  a\\equiv |a_{mn}|  &= a_{Mk}\\Delta^{Mk}\\quad\\text{(develop determinant along row M)}\\\\\n\\ &\\Rightarrow \\pdv{a}{a_{mn}} = \\pdv{a_{Mk}}{a_{mn}}\\Delta^{Mk} + a_{Mk}\\pdv{\\Delta^{Mk}}{a_{mn}}\\\\\n\\text{but}\\quad &\\pdv{a_{Mk}}{a_{mn}} = \\left\\{\\begin{array}{c}\n\\ 1\\quad\\text{if} \\quad k = N\\\\\n\\ 0\\quad\\text{if} \\quad k \\neq N\\\\\n\\end{array}\\right.\\\\\n\\text{and}\\quad &\\pdv{\\Delta^{Mk}}{a_{mn}} = 0 \\quad \\forall k \\text{ as } \\Delta^{Mk} \\text{does not contain the row with } a_{mn} \\text{ as element.}\\\\\n\\ & \\text{(3) and (4)}\\quad  \\Rightarrow \\pdv{a}{a_{mn}} = \\Delta^{MN}\\\\ \n\\ &  a^{mn} = \\frac{\\Delta^{mn}}{a}\\quad\\text{by definition (see 2.203 page 30)}\\\\\n\\ & \\Rightarrow \\pdv{a}{a_{mn}} = aa^{mn}\n\\end{align} \n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p32-exercise}\n\\begin{tcolorbox}\nProve that $a_{mn}a^{mn} = N$.\n\\end{tcolorbox}\nFrom 2.204, we have\n\\begin{align}\n\\ a_{mr}a^{ms} &= \\delta^s_r\\\\\n\\text{Consider} \\quad a_{mR}a^{mR} &= 1\\\\\n\\text{We can repeat (2) for R = 1,2,...,N} \\quad \\Rightarrow a_{mr}a^{mr} &= N\\\\\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p33-exercise}\n\\begin{tcolorbox}\nShow that in Euclidean 3-space with rectangular Cartesian coordinates, the definition 2.301 coincides with the usual definition of the magnitude of a vector.\n\\end{tcolorbox}\nThe length of an arbitrary vector in Euclidean 3-space with rectangular Cartesian coordinates, is\n\\begin{align}\n\\ ds^2 = (dy^1)^2 + (dy^2)^2 (dy^2)^2\n\\end {align}\nFrom 2.301, it is obvious that the metrixc tensor can be expressed as,\n\\begin{align}\n\\begin{pmatrix}1 & 0 &0 \\\\ 0 & 1 &0\\\\0 & 0 &1  \\\\ \\end{pmatrix} \n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p34-exercise}\n\\begin{tcolorbox}\nA curve in Euclidean 3-space has the equations $$ x^1 =  a \\cos(u), x^2 = a\\sin(u), x^3 = bu$$ where $x^1, x^2,x^3$ are rectangular Cartesian coordinates,$u$ is a parameter, and $a, b$ are positive constants. Find the length of this curve between the point $u = 0$ and $u = 2\\pi$.\n\\end{tcolorbox}\nThe metric tensor has the following form,\n\\begin{align}\n\\ (a_{ij}) &= \\begin{pmatrix}1 & 0 &0 \\\\ 0 &1 &0\\\\0 & 0 &1  \\\\ \\end{pmatrix} \\\\\n\\text {and  (2.306)  }\\quad s &= \\int^{2\\pi}_0[\\epsilon a_{mn}p^mp^n]^{\\frac{1}{2}}du\n\\end{align}\nwith\n\\begin{align}\n\\ p^1 = \\dv{x^1}{u} = -a\\sin(u), \\quad p^2 = \\dv{x^2}{u} = a\\cos(u), \\quad p^3 = \\dv{x^3}{u} = b\n\\end{align}\nHence (2) becomes\n\\begin{align}\ns &= \\int^{2\\pi}_0\\epsilon[a^2 \\sin^2(u) + a^2\\cos^2(u) + b^2]^{\\frac{1}{2}}du\\\\\n\\ &= \\int^{2\\pi}_0\\epsilon[a^2+  b^2]^{\\frac{1}{2}}du\\\\\n\\ &= [a^2+  b^2]^{\\frac{1}{2}} \\left. u\\right|^{2\\pi}_0\\\\\n\\ &= 2\\pi[a^2+  b^2]^{\\frac{1}{2}} \n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p36-clarification 2.314}\n\\begin{tcolorbox}\nGoing from 2.313 to 2.314 yields because both $X^m$ and $Y^m$ are unit vectors and by definition of the magnitude (see 2.301) both  $a_{mn}X^mX^n$ and $a_{mn}Y^mY^n$ are 1 (also due to the fact that only a positive definite metric tensor is considered, $\\epsilon = 1$).\n\\end{tcolorbox}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p37-exercise}\n\n\\begin{tcolorbox}\nShow that the small angle between unit vectors $X^r$ and $X^r + dX^r$ (these increments being infenitesimal) is given by $$ \\theta^2 = a_{mn}X^mX^n$$\n\\end{tcolorbox}\n\\begin{figure}[htp]  \n\n    \\centering\n \n%\\includegraphics[scale=.5]{Exp37_1.jpg}\n\\input{D:/MathLatex/images/fig_p37_213_a.tex}\n\\caption{Small angle expression}\n\\end{figure}\nBy definition (2.302 page 33)\n\\begin{align} \n\\ |BC|^2 =\\epsilon a_{mn}dX^mdX^n\\\\\n\\end{align}\nWe can drop $\\epsilon = 1$ as the considered space is positive definite.\\\\\nAs $\\theta$ is infinitesimal, we can state\n\\begin{align}\n\\ |BC| &\\approx |AC|\\theta\\\\\n\\text{ and } \\quad |AC| &= X^r = 1\\quad  \\text{(as } X^r \\text{ is a unit vector)}\\\\\n\\Rightarrow \\theta^2 &= a_{mn}dX^mdX^n\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p39-clarification 2.409}\n\n\\begin{tcolorbox}\nWe clarify the integration by parts in the derivation of the general  geodesic equation.\n\\end{tcolorbox}\nWe have \n\\begin{align}\n\\int d(A.B) &= \\int AdB + \\int BdA\\\\\n\\Rightarrow  \\int AdB &= \\int BdA -  \\int d(A.B)\\\n\\end{align}\nNow, substitute 2.407 in 2.406, we get\n\\begin{align}\n\\dv{L}{v} &= \\int \\pdv{(\\epsilon w)^{\\frac{1}{2}}}{x^r} \\pdv{x^r}{v} du +  \\int \\pdv{(\\epsilon w)^{\\frac{1}{2}}}{p^r} \\pdv{p^r}{v} du\\\\\n\\ &= \\int \\pdv{(\\epsilon w)^{\\frac{1}{2}}}{x^r} \\pdv{x^r}{v} du +  \\int \\pdv{(\\epsilon w)^{\\frac{1}{2}}}{p^r} \\pdv{\\pdv{x^r}{v}}{u} du\\\\\n&= \\int \\pdv{(\\epsilon w)^{\\frac{1}{2}}}{x^r} \\pdv{x^r}{v} du +  \\int \\pdv{(\\epsilon w)^{\\frac{1}{2}}}{p^r} d(\\pdv{x^r}{v})\n\\end{align}\nTo integrate by parts the second term in (5) we put in (2)\n$$A= \\pdv{(\\epsilon w)^{\\frac{1}{2}}}{p^r} \\quad \\text{and } B = \\pdv{x^r}{v}$$\n\\begin{align}\n\\int \\pdv{(\\epsilon w)^{\\frac{1}{2}}}{p^r} d(\\pdv{x^r}{v}) &= \\int AdB \\\\\n\\ & = \\int BdA -  \\int d(A.B)\\\\\n\\ &= \\pdv{(\\epsilon w)^{\\frac{1}{2}}}{p^r}\\left.\\pdv{x^r}{v}\\right|_{u_0}^{u_1} - \\int \\pdv{x^r}{v}d(\\pdv{(\\epsilon w)^{\\frac{1}{2}}}{p^r} )\\\\\n\\ &= \\pdv{(\\epsilon w)^{\\frac{1}{2}}}{p^r}\\left.\\pdv{x^r}{v}\\right|_{u_0}^{u_1} - \\int \\pdv{x^r}{v}\\pdv{\\pdv{(\\epsilon w)^{\\frac{1}{2}}}{p^r} )}{u}du\n\\end{align}\nReplacing (9) in (5) gives the formulea 2.409.\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p41-exercise}\n\\begin{tcolorbox}\nProve the following identities: $$ [mn,r] = [nm,r], \\quad [rm,n]+[rn,m] = \\partial_r a_{mn}$$\n\\end{tcolorbox}\n\\begin{align}\n\\ [mn,r] &= \\frac{1}{2}(\\partial_{n} a_{mr}+ \\partial_{m} a_{nr} - \\partial_{r} a_{mn})\\\\\n\\ &= \\frac{1}{2}(\\partial_{m} a_{nr} + \\partial_{n} a_{mr}  - \\partial_{r} a_{nm})\\\\\n\\ &=[nm,r] \n\\end{align}\nand \n\\begin{align}\n\\ [rm,n] + [rn,m]&= \\frac{1}{2}(\\partial_{r} a_{mn}+ \\partial_{m} a_{rn} - \\partial_{n} a_{rm} + \\partial_{n} a_{rm}+ \\partial_{r} a_{mn} - \\partial_{m} a_{rn})\\\\\n\\ &= \\frac{1}{2}(\\partial_{r} a_{mn}+\\partial_{r} a_{mn})\\\\\n\\ &=\\partial_{r} a_{mn}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p42-exercise}\n\\begin{tcolorbox}\nProve that  $$ [mn,r] = a_{rs}\\Gamma^s_{mn}$$\n\\end{tcolorbox}\n\\begin{align}\n\\ a_{rs}\\Gamma^s_{mn} & = a_{rs}a^{sk}[mn,k]\\\\\n\\ & = \\delta^k_r[mn,k]\\\\\n\\ &= [mn,r]\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p42-clarification on 2.430}\n\\begin{tcolorbox}\n... This may proved without difficulty by starting with 2.427, in which $\\lambda$ is a known function of $u$ , and defining $s$ by the relation$$ s = \\int^u_{u_0}(exp\\int^v_{v_0} \\lambda(w)dw)dv$$ $u_0, v_0$ being constants....\n\\end{tcolorbox}\n\\begin{align}\n\\text{see 2.428 :} \\quad  \\lambda (u)=-\\frac{\\dv[2]{u}{s}}{(\\dv{u}{s})^2}\\\\\n\\end{align}\nWe suppose $u(s)$ continuous by parts with continuous inverse.\n\\begin{align}\n\\Rightarrow \\dv{s}{u} &= \\frac{1}{\\dv{u}{s}}\\\\\n\\Rightarrow \\dv[2]{s}{u}&= \\dv{(\\frac{1}{\\dv{u}{s}})}{s}\\dv{s}{u}\\\\\n\\ & = -\\frac{\\dv[2]{u}{s}}{(\\dv{u}{s})^2}\\dv{s}{u}\\\\\n\\Rightarrow \\frac{\\dv[2]{s}{u}}{\\dv{s}{u}} &= - \\frac{\\dv[2]{u}{s}}{(\\dv{u}{s})^2}  \n\\end{align}\nBy definition (2.428)\n\\begin{align}\n\\ \\lambda (u) &= - \\frac{\\dv[2]{u}{s}}{(\\dv{u}{s})^2}\\\\\n\\text{hence by (6) and (7):}\\quad  \\lambda (u) &= \\frac{\\dv[2]{s}{u}}{\\dv{s}{u}}\\\\\n\\text{in (8) put}\\quad y &= \\dv{s}{u} \\\\\n\\text{ and so} \\quad \\lambda (w)  &= \\frac{y^,}{y}\\\\\n\\Rightarrow \\int \\frac{y^,}{y}dw &= \\int \\lambda (w)dw\\\\\n\\Leftrightarrow \\int d(lny) &= \\int \\lambda (w)dw\\\\\n\\Rightarrow \\left. ln(y) \\right|^v_{v_0} &= \\int^v_{v_0} \\lambda (w)dw\\\\\n\\Rightarrow y  &= exp(\\int^v_{v_0} \\lambda (w)dw) + C\n\\end{align}\nTaking into account (9), we get:\n\\begin{align}\n\\dv{s}{v}  &= exp(\\int^v_{v_0} \\lambda (w)dw) + C\\\\\n\\Rightarrow \\left. s \\right|^u_{u_0} &=\\int^u_{u_0}  exp(\\int^v_{v_0} \\lambda (w)dw)dv +Cu + B^,\\\\\n\\Leftrightarrow  s  &=\\int^u_{u_0}  exp(\\int^v_{v_0} \\lambda (w)dw)dv +Cu + B\n\\end{align}\nWe show tha we have to put $C=0$ and can drop the constant $B$. Remember by (8)\n\\begin{align}\n\\lambda (u) &= \\frac{\\dv[2]{s}{u}}{\\dv{s}{u}}\\\\\n\\text{by (17)} \\quad \\dv{s}{u}  &=exp(\\int^u_{u_0} \\lambda (w)dw) +C\\\\\n\\text{and}\\quad \\dv[2]{s}{u}  &= \\lambda (u) exp(\\int^u_{u_0} \\lambda (w)dw) \\\\\n\\text{hence by (18), (19) and (20):} \\quad \\lambda (u)&= \\frac{\\lambda (u) exp(\\int^u_{u_0} \\lambda (w)dw)}{exp(\\int^u_{u_0} \\lambda (w)dw) +C}\n\\end{align}\nSo, whatever the constant B, the relation (18) is correct on the condition that C=0. \nSo, indeed, we can choose the independent variable $s$ as\n$$s  =\\int^u_{u_0}  exp(\\int^v_{v_0} \\lambda (w)dw)dv $$ \n$$\\blacklozenge$$\n\\newpage\n\n\\section{p42-clarification on 2.430}\n\\begin{tcolorbox}\nAfter 2.430 it is stated:\\\\\n\\it{\"No matter what values these constants have, 2.424 is satisfied, and by adjusting the constant $v_0$, we can ensure that $a_{mn}\\dv{x^m}{s}\\dv{x^n}{s} = \\pm1$ along $C$, so that $s$ is actually the arc length.\"}\n\\end{tcolorbox}\nWe first prove that 2.4.24 is satisfied, no matter what values the constants take. We have\n\\begin{align}\n\\text{(2.430) } \\quad  &s =\\int_{u_0}^u(exp\\int_{v_0}^v \\lambda (w)dw)dv\\\\\n\\text{and (2.427)} \\quad &\\dv[2]{x^r}{u} + \\Gamma^r_{mn}\\dv{x^m}{u}\\dv{x^n}{u} =  \\lambda \\dv{x^r}{u}\n\\end{align}\nIn (2) we can write the first term as\n\\begin{align}\n\\quad \\dv[2]{x^r}{u} &= \\dv{(\\dv{x^r}{u})}{s}\\dv{s}{u} \\\\\n\\text{with } \\quad \\dv{(\\dv{x^r}{u})}{s} &=  \\dv{(\\dv{x^r}{s}\\dv{s}{u})}{s} = \\dv[2]{x^r}{s}\\dv{s}{u}+\\dv{x^r}{s}\\dv{(\\dv{s}{u})}{s} \n\\end{align}\nAssuming the curve smooth, we have\n\\begin{align}\n\\dv{(\\dv{s}{u})}{s} & = \\dv{(\\frac{1}{\\dv{u}{s}})}{s} = -\\frac{\\dv[2]{u}{s}}{(\\dv{u}{s})^2}= \\lambda\n\\end{align}\nPutting (4) and (5) in (3) we get\n\\begin{align}\n\\dv[2]{x^r}{u} &= \\dv[2]{x^r}{s} \\left ( \\dv{s}{u}\\right )^2 + \\lambda\\dv{x^r}{s}\\dv{s}{u}\n\\end{align}\nPlugging (6) in 2.427 gives:\n\\begin{align}\n\\dv[2]{x^r}{s} \\left (\\dv{s}{u}\\right )^2 + \\lambda\\dv{x^r}{s}\\dv{s}{u} +\\Gamma^r_{mn}\\dv{x^m}{s}\\dv{x^n}{s}\\left (\\dv{s}{u}\\right )^2  &=  \\lambda \\dv{x^r}{s}\\dv{s}{u}\\\\\n\\Leftrightarrow \\dv[2]{x^r}{s} \\left (\\dv{s}{u}\\right )^2 +\\Gamma^r_{mn}\\dv{x^m}{s}\\dv{x^n}{s}\\left (\\dv{s}{u}\\right )^2  &=  0\n\\end{align}\nWe can assume that $\\dv{s}{u} $ does not become $0$ or $\\pm \\infty$ along the curve by choosing an adequate constant $v_0$. Indeed, from (2.430) we get\n\\begin{align}\n\\dv{s}{u}  &= exp(\\int_{u_0}^u \\lambda (w)dw)\\\\\n\\ &= \\frac{\\phi (u)}{\\phi (u_0)}\n\\end{align}\nwith $\\phi (u_0) =  e^{\\theta(u_0)}$, $\\theta(u)$ being the indefinite integral $\\int \\lambda (w)dw $.\\\\\nSo, it is sufficient to choose $v_0$ so that $\\theta(u_0)$ does not become  $\\pm \\infty$ to ensure that $\\dv{s}{u} \\ne 0$ or $ \\ne \\pm \\infty$ along the curve and so we have from (8)\n\\begin{align}\n\\dv[2]{x^r}{s} +\\Gamma^r_{mn}\\dv{x^m}{s}\\dv{x^n}{s}  &=  0\\end{align}\nwhich is the definition (2.424) of a geodesic.\\\\\\\\\nThe same reasoning about $\\dv{s}{u} \\ne 0$ can be made to prove that $a_{mn}\\dv{x^m}{s}\\dv{x^n}{s} = \\pm1$ along $C$. Indeed, by definition (2.305):\n\\begin{align}\n\\ ds = &\\left[ \\epsilon a_{mn}\\dv{x^m}{u}\\dv{x^n}{u}\\right]^\\frac{1}{2}\\\\\n\\text{ equating with (9)} \\quad   &\\left[ \\epsilon a_{mn}\\dv{x^m}{u}\\dv{x^n}{u}\\right]^\\frac{1}{2} =                 exp(\\int_{u_0}^u \\lambda (w)dw)\\\\\n\\Rightarrow \\quad &\\epsilon a_{mn}\\dv{x^m}{s}\\dv{x^n}{s}\\left (\\dv{s}{u}\\right )^2 =  \\left[ exp(\\int_{u_0}^u \\lambda (w)dw) \\right]^2\\\\\n\\text{but} \\quad &\\dv{s}{u} = exp(\\int_{u_0}^u \\lambda (w)dw)\\\\\n\\text{ and so, (9) becomes} \\quad &\\epsilon a_{mn}\\dv{x^m}{s}\\dv{x^n}{s}\\left (\\dv{s}{u}\\right )^2 =  \\left (\\dv{s}{u}\\right )^2\\\\\n\\Rightarrow \\quad & a_{mn}\\dv{x^m}{s}\\dv{x^n}{s}=\\epsilon\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p43-clarification }\n\\begin{tcolorbox}\n$$\\lambda = \\Gamma^N_{\\mu \\nu}\\dv{x^{\\mu}}{x^N} \\dv{x^{\\nu}}{x^N} + 2\\Gamma^N_{\\mu N}\\dv{x^{\\mu}}{x^N}+\\Gamma^N_{N N} $$\n\\end{tcolorbox}\nWe start with 2.427 with $r=N$\n\\begin{align}\n\\ &\\dv[2]{x^N}{{x^{N}}} + \\Gamma^N_{\\mu\\nu}\\dv{x^{\\mu}}{x^N} \\dv{x^{\\nu}}{x^N} = \\lambda \\dv{x^N}{x^N}\\\\\n\\Rightarrow\\quad &\\Gamma^N_{\\mu\\nu}\\dv{x^{\\mu}}{x^N} \\dv{x^{\\nu}}{x^N} = \\lambda \\quad \\text{(as}\\quad \\dv[2]{x^N}{{x^{N}}} = 0 \\quad \\dv{x^N}{x^N} = 1 \\text{)}\n\\end{align}\nBut (2) is only valid with the dummy indices $\\mu$ and $\\nu$ spanning the whole dimension $(1,2,\\dots N)$, but by choice $\\mu,\\nu \\quad \\epsilon \\quad (1,2, \\dots, N-1)$. We have thus to add in the left term of (2) the cases\n\\begin{align}\n\\left\\{ \\begin{array}{cc}\n\\Gamma^N_{N\\nu}& \\nu = (1,2,\\dots ,N-1)\\\\\\\\\n\\Gamma^N_{\\mu N}& \\mu = (1,2,\\dots ,N-1)\\\\\\\\\n\\Gamma^N_{NN}& \\\\\n\\end{array} \\right.\\\\\n\\text{(2) becomes } \\quad \\Gamma^N_{\\mu\\nu}\\dv{x^{\\mu}}{x^N} \\dv{x^{\\nu}}{x^N} + \\Gamma^N_{N \\nu}\\dv{x^N}{x^N} \\dv{x^{\\nu}}{x^N} + \\Gamma^N_{\\mu N}\\dv{x^{\\mu}}{x^N} \\dv{x^{N}}{x^N} + \\Gamma^N_{NN}\\dv{x^{N}}{x^N} \\dv{x^{N}}{x^N}= \\lambda\\\\\n\\Rightarrow   \\quad \\Gamma^N_{\\mu\\nu}\\dv{x^{\\mu}}{x^N} \\dv{x^{\\nu}}{x^N} + \\Gamma^N_{N \\nu}\\dv{x^{\\nu}}{x^N} + \\Gamma^N_{\\mu N}\\dv{x^{\\mu}}{x^N}+ \\Gamma^N_{NN} = \\lambda\n\\end{align}\nAs $\\Gamma^N_{\\mu N}$ is symmetric on the lower indices and $\\mu$, $\\nu$ being dummy indices:\n\\begin{align}\n\\lambda  =\\Gamma^N_{\\mu\\nu}\\dv{x^{\\mu}}{x^N} \\dv{x^{\\nu}}{x^N} + 2\\Gamma^N_{N \\nu}\\dv{x^{\\nu}}{x^N} +\\Gamma^N_{NN}\n\\end{align}\nThe other $N-1$ equation for $r= 1,\\dots, N-1$ can be deduced following the same reasoning.\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p45-clarification }\n\\begin{tcolorbox}\n$ f_r \\equiv a_{rm}\\dv[2]{x^m}{u} +[mn,r]\\dv{x^m}{u}\\dv{x^n}{u}$ is covariant and \n$ f^r \\equiv \\dv[2]{x^m}{u} +\\Gamma^r_{mn}\\dv{x^m}{u}\\dv{x^n}{u}$ is contravariant.\n\\end{tcolorbox}\n\\begin{align}\n\\ &f_r \\equiv a_{rm}\\dv[2]{x^m}{u} +[mn,r]\\dv{x^m}{u}\\dv{x^n}{u}\\\\\n\\text{multiply with}\\quad a^{sr}\\quad \\Rightarrow\\quad &f_r a^{sr} = a^{sr}a_{rm}\\dv[2]{x^m}{u} +a^{sr}[mn,r]\\dv{x^m}{u}\\dv{x^n}{u}\\\\\n\\Rightarrow\\quad &f^{s} = \\delta^s_m \\dv[2]{x^m}{u} +\\underbrace{a^{sr}[mn,r]}_{\\Gamma^s_{mn}}\\dv{x^m}{u}\\dv{x^n}{u}\\\\\n\\Rightarrow \\quad &f^{s} = \\dv[2]{x^s}{u} +\\Gamma^s_{mn}\\dv{x^m}{u}\\dv{x^n}{u}\n\\end{align}\nBy lifting the index of $f_r$ we get a contravariant vector confirming that (4) is contravariant.\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p45-clarification }\n\\begin{tcolorbox}\n(2.443) and (2.444)\n$$ p^r\\pdv{w}{p^r} - w = C^t \\quad \\Rightarrow\\quad w = C^t $$ \n\\end{tcolorbox}\nBy definition \n\\begin{align}\n\\ w &= a_{mn}p^mp^n\\\\\n\\Rightarrow\\quad \\pdv{w}{p^r} &= a_{mn}(\\pdv{p^m}{p^r}p^n + p^m \\pdv{p^n}{p^r})\\\\\n\\ &= a_{mn}(\\delta^m_rp^n + p^m \\delta^n_r)\\\\\n\\ &= a_{rn}p^n + a_{mr}p^m \\\\\n\\ &= 2a_{mr}p^m \\quad\\text{(as } a_{mn} \\quad \\text{is symmetric)}\\\\\n\\text{(4)}\\quad \\Rightarrow \\quad p^r\\pdv{w}{p^r} &= 2a_{mr}p^rp^m \\\\\n\\ &= 2w\\\\\n\\text{(2.443)} \\quad\\Rightarrow\\quad p^r\\pdv{w}{p^r} -w &= 2w-w = w = C^t\\\\\n\\Rightarrow\\quad w &\\equiv a_{mn}p^mp^n = C^t\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p47-exercise }\n\\begin{tcolorbox}\nThe class of all parameters $u$, for which the equations of a geodesic null line assume the simple form 2.445, are obtained from any one such parameter by linear transformation $$ \\overline{u} = au + b$$ $a$ and $b$ being constants.\n\\end{tcolorbox}\nThe simple form 2.445 is :\n\\begin{align}\n\\  \\dv[2]{x^r}{u} +\\Gamma^r_{mn}\\dv{x^m}{u}\\dv{x^n}{u} = 0\\\\\n\\end{align}\nThe general form of a geodesic is (2.447) \n\\begin{align}\n\\  \\dv[2]{x^r}{\\overline{u}} +\\Gamma^r_{mn}\\dv{x^m}{\\overline{u}}\\dv{x^n}{\\overline{u}} = \\lambda \\dv{x^r}{\\overline{u}}\\\\\n\\end{align}\nSo (2.447) can only of the form (2.445) if $\\lambda = 0$\n\\begin{align}\n\\   \\lambda  = - \\frac{\\dv[2]{\\overline{u}}{u}}{\\left( \\dv{\\overline{u}}{u}\\right)^2} = 0\\\\\n\\end{align}\nWe can state that $\\dv{\\overline{u}}{u}\\ne 0$ as $\\overline{u}$ can't be a constant (being a parameter of a curve). So,\n\\begin{align}\n\\dv[2]{\\overline{u}}{u}&=0\\\\\n\\Rightarrow \\quad \\dv{\\overline{u}}{u}&=a\\\\\n\\Rightarrow \\quad \\overline{u}&=au +b\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p47-exercise }\n\\begin{tcolorbox}\nConsider a 3-space with coordinates $x,y,z$ and a metric form $\\Phi = (dx)^2+(dy)^2 - (dz)^2$. prove that the geodesic null lines may be represented by the equations\n$$x = au + a^,\\quad y = bu + b^, \\quad z = cu + c^,$$\nwhere $u$ is a parameter and $a, a^,,b,b^,,c,c^,$ are constants which are arbitrary except for the relation $a^2+b^2-c^2 =0$.\n\\end{tcolorbox}\nGiven is \n\\begin{align}\n\\Phi = (dx)^2+(dy)^2 - (dz)^2\n\\end{align}\nFrom the previous exercise we have already proven that $x,y,z$ are of the form\n\\begin{align}\n\\ x^i = q_i u + q_i^,\n\\end{align}\nTo be a null geodesic null line we need to have (2.448)\n\\begin{align}\n\\ a_{mn}\\dv{x^m}{u}\\dv{x^n}{u} &=0\\\\\n\\text{from (1) we deduce}  \\quad (a_{mn}) &= \\begin{pmatrix}\n1& 0 & 0 \\\\\n 0&1  & 0 \\\\\n 0&  0& -1 \\\\\n\\end{pmatrix}\\\\\n\\text{(3)}\\quad\\Rightarrow\\quad (dx)^2+(dy)^2 - (dz)^2 &=0\\\\\n\\text{(2)}\\quad\\Rightarrow\\quad (q_1)^2+(q_2)^2 - (q_3)^2 &=0\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p48-exercise }\n\\begin{tcolorbox}\nProve that the Christoffel symbols of the first kind transform according the equation \n$$[mn,r]^, =  [pq,s]\\pdv{x^p}{x^{,m}} \\pdv{x^q}{x^{,n}}\\pdv{x^s}{x^{,r}}+ a_{pq}\\pdv{x^p}{x^{,r}}\\pdv{x^q}{x^{,m}}{x^{,n}}$$\n\\end{tcolorbox}\nFrom 2.438 page 45, we have\n\\begin{align}\n\\ f_r &\\equiv a_{rm}\\dv[2]{x^m}{u} +[mn,r]\\dv{x^m}{u}\\dv{x^n}{u} \\quad\\text{is covariant} \\\\\n\\Rightarrow\\quad f_r^, &= f_s\\pdv{x^s}{x^{,r}}\\\\\n\\text{with}\\quad f_r^, &= a^,_{rm}\\dv[2]{x^{,m}}{u} +[mn,r]^, \\dv{x^{,m}}{u}\\dv{x^{,n}}{u}\n\\end{align}\nCombining (1), (2) and (3) gives \n\\begin{align}\n\\ a^,_{rm}\\dv[2]{x^{,m}}{u} +[mn,r]^, \\dv{x^{,m}}{u}\\dv{x^{,n}}{u} = ( a_{sm}\\dv[2]{x^m}{u} +[mn,s]\\dv{x^m}{u}\\dv{x^n}{u})\\pdv{x^s}{x^{,r}}\n\\end{align}\nWe rewrite (4) as \n\\begin{align}\n\\ [mn,r]^, \\dv{x^{,m}}{u}\\dv{x^{,n}}{u} &= -\\underbrace{a^,_{rm}\\dv[2]{x^{,m}}{u}}_\\text{(*)} +\\underbrace{ a_{sm}\\dv[2]{x^m}{u}\\pdv{x^s}{x^{,r}}}_\\text{(**)} +\\underbrace{[mn,s]\\dv{x^m}{u}\\dv{x^n}{u}\\pdv{x^s}{x^{,r}}}_\\text{(***)}\\\\\n\\text{(***)} &\\Leftrightarrow [mn,s]\\pdv{x^m}{x^{,p}}\\dv{x^{,p}}{u}\\pdv{x^n}{x^{,q}}\\dv{x^{,q}}{u}\\pdv{x^s}{x^{,r}}\n\\end{align}\nIn (6) renaming the dummy indices $m,n,p,q$ gives\n\\begin{align}\n\\text{(***)} &\\Leftrightarrow [pq,s]\\pdv{x^p}{x^{,m}}\\dv{x^{,m}}{u}\\pdv{x^q}{x^{,n}}\\dv{x^{,n}}{u}\\pdv{x^s}{x^{,r}}\\\\\n&\\Leftrightarrow [pq,s]\\pdv{x^p}{x^{,m}}\\pdv{x^q}{x^{,n}}\\pdv{x^s}{x^{,r}}\\left(\\dv{x^{,m}}{u}\\dv{x^{,n}}{u}\\right)\n\\end{align}\nAlso,\n\\begin{align}\n\\text{(**)} &\\Leftrightarrow  a_{sm}\\dv[2]{x^m}{u}\\pdv{x^s}{x^{,r}}\\\\\n\\text{As we have also}\\quad \\dv[2]{x^m}{u} &= \\dv{(\\pdv{x^m}{x^{,p}}\\dv{x^{,p}}{u})}{u}\\\\\n&= \\pdv{x^m}{x^{,p}}\\dv[2]{x^{,p}}{u}+\\dv{x^{,p}}{u}\\pdv{x^m}{x^{,p}}{x^{,q}}\\dv{x^{,q}}{u} \n\\end{align}\n(11) and (9) gives by changing the dummy indices ( $m\\rightarrow t$, $p\\rightarrow m$, $q\\rightarrow n$)\n\\begin{align}\n\\text{(**)}&= \\underbrace{a_{st}\\pdv{x^t}{x^{,p}}\\dv[2]{x^{,p}}{u}\\pdv{x^s}{x^{,r}}}_\\text{(****)}+a_{pq}\\pdv{x^q}{x^{,m}}{x^{,n}}\\pdv{x^{p}}{x^{,r}}\\left(\\dv{x^{,m}}{u}\\dv{x^{,m}}{u}\\right) \\\\\n\\text{with (****)}\\quad &= a_{st}\\left(\\pdv{x^t}{x^{,m}}\\pdv{x^s}{x^{,r}}\\right)\\dv[2]{x^{,m}}{u}\n\\end{align}\nBut $a_{st}$  is a covariant tensor, so\n\\begin{align}\n\\ a^{,}_{rm} &= a_{st}\\pdv{x^t}{x^{,m}}\\pdv{x^s}{x^{,r}}\\\\\n\\text{(13) becomes}\\quad \\text{(****)} &= a^{,}_{rm}\\dv[2]{x^{,m}}{u}\\\\\n\\text{and from (5) we have }\\quad \\text{(*)} &= -a^{,}_{rm}\\dv[2]{x^{,m}}{u}\\\\\n\\end{align}\nand both terms cancel each other in equation (5). So adding $(*), (**)$ and $(***)$ in (5) , we get \n\\begin{align}\n\\ [mn,r]^, \\dv{x^{,m}}{u}\\dv{x^{,n}}{u} &= a_{pq}\\pdv{x^q}{x^{,m}}{x^{,n}}\\pdv{x^{p}}{x^{,r}}\\left(\\dv{x^{,m}}{u}\\dv{x^{,m}}{u}\\right)+[pq,s]\\pdv{x^p}{x^{,m}}\\pdv{x^q}{x^{,n}}\\pdv{x^s}{x^{,r}}\\left(\\dv{x^{,m}}{u}\\dv{x^{,n}}{u}\\right)\\\\\n\\Rightarrow \\ &[mn,r]^, =[pq,s]\\pdv{x^p}{x^{,m}}\\pdv{x^q}{x^{,n}}\\pdv{x^s}{x^{,r}}+  a_{pq}\\pdv{x^{p}}{x^{,r}}\\pdv{x^q}{x^{,m}}{x^{,n}}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p50-clarification 2.515 }\n\\begin{tcolorbox}\n$$\\dv{\\left(T_rS^r\\right)}{u} = \\dv{T_r}{u}S^r + T_r\\dv{S^r}{u} = \\left(\\dv{T_r}{u} - \\Gamma^m_{rn}T_m\\dv{x^n}{u}\\right)S^r$$ with $$\\frac{\\delta T_r}{\\delta u} = \\dv{T_r}{u} -\\Gamma^m_{rn}\\dv{x^n}{u} T_m$$ a covariant vector.\n\\end{tcolorbox}\nIt is given that $S^r$ is a tensor propagated parallelly along the curve. The by (2.5212) we have\n\\begin{align}\n\\dv{S^r}{u} &+ \\Gamma^r_{mn}S^m\\dv{x^n}{u}= 0\\\\\n\\dv{S^r}{u} &= - \\Gamma^r_{mn}S^m\\dv{x^n}{u}\\\\\n\\text{and}\\quad \\dv{\\left(T_rS^r\\right)}{u} &= \\dv{T_r}{u}S^r + T_r\\dv{S^r}{u} \\\\\n\\ &= \\dv{T_r}{u}S^r -\\Gamma^r_{mn}S^m\\dv{x^n}{u} T_r\\\\\n\\end{align}\nSwap dummy indices $r$ and $m$ in the second term:\n\\begin{align}\n\\dv{\\left(T_rS^r\\right)}{u} &= \\dv{T_r}{u}S^r -\\Gamma^m_{rn}S^r\\dv{x^n}{u} T_m\\\\\n\\ &= \\left(\\dv{T_r}{u} -\\Gamma^m_{rn}\\dv{x^n}{u} T_m\\right)S^r\\\\\n\\end{align}\nAs $T_rS^r$ is an invariant and thus is also $\\dv{\\left(T_rS^r\\right)}{u}$ and as $S^r$ can be chosen arbitrarily (as long it is a contravariant tensor), implies that $$\\dv{T_r}{u} -\\Gamma^m_{rn}\\dv{x^n}{u} T_m$$ is covariant and thus also $$\\frac{\\delta T_r}{\\delta u} = \\dv{T_r}{u} -\\Gamma^m_{rn}\\dv{x^n}{u} T_m$$\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p50-clarification 2.516}\n\\begin{tcolorbox}\n$$\\frac{\\delta T_{rs}}{\\delta u} \\equiv \\dv{T_{rs}}{u}  - \\Gamma^m_{rn}T_{ms}\\dv{x^n}{u} - \\Gamma^m_{sn}T_{rm}\\dv{x^n}{u}$$ is a covariant vector.\n\\end{tcolorbox}\nWe build an invariant $ T_{rs} S^rU^s$ with $S^r$ and $U^s$ arbitrary contravariant tensors. The we know that $\\dv{\\left( T_{rs} S^r U^s\\right)}{u}$ is also an invariant. We have \n\\begin{align}\n\\dv{\\left( T_{rs} S^r U^s\\right)}{u} = \\dv{T_{rs}}{u} S^r U^s + T_{rs} \\dv{S^r}{u} U^s + T_{rs} S^r \\dv{U^s}{u}\n\\end{align} \nwith with $S^r$ and $U^s$ propagated parallelly along the curve. Then,\n\\begin{align}\n\\dv{S^r}{u} = - \\Gamma^r_{mn}S^m\\dv{x^n}{u}\\\\\n\\dv{U^s}{u} = - \\Gamma^s_{mn}Y^m\\dv{x^n}{u}\n\\end{align} \n(2), (3) in (1) gives \n\\begin{align}\n\\dv{\\left( T_{rs} S^r U^s\\right)}{u} = \\dv{T_{rs}}{u} S^r U^s - T_{rs}U^s\\Gamma^r_{mn}S^m\\dv{x^n}{u} - T_{rs} S^r \\Gamma^s_{mn}U^m\\dv{x^n}{u}\n\\end{align} \nChanging the dummy indices in the second and third term gives:\n\\begin{align}\n\\dv{\\left( T_{rs} S^r U^s\\right)}{u} = (\\dv{T_{rs}}{u}  - \\Gamma^m_{rn}T_{ms}\\dv{x^n}{u} - \\Gamma^m_{sn}T_{rm}\\dv{x^n}{u})S^r U^s\n\\end{align} \nAs the left term is an invariant and $S^r$ and $U^s$ are arbitrary contravariant tensors, means that the expression in the brackets in the right part of the equation, is a covariant tensor.\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p51-exercise}\n\\begin{tcolorbox}\nFind the absolute derivative of $T^r_{st}$.\n\\end{tcolorbox}\nDefine the invariant $ I = D^r_{st}R^rS_sT_t$ \n\\begin{align}\n\\ I &= D^r_{st}R^rS_sT_t\\\\\n\\Rightarrow A &= \\dv{I}{u}= \n\\dv{\\left(D^r_{st}\\right)}{u}R^rS_sT_t+\n\\ D^r_{st}S_sT_t\\dv{\\left(R^r\\right)}{u}+\n\\ D^r_{st}R_rT_t\\dv{\\left(S^s\\right)}{u}+\n\\ D^r_{st}R_rS_s\\dv{\\left(T^t\\right)}{u}\n\\end{align} \nReminder, performing a parallel propagation of a covariant and contravariant vector gives as equations\n\\begin{align}\n\\dv{V^v}{u} = - \\Gamma^v_{mn}V^m\\dv{x^n}{u}\\\\\n\\dv{W_w}{u} = + \\Gamma^m_{wn}W^m\\dv{x^n}{u}\n\\end{align}\nSo (2) becomes:\n\\begin{align}\n\\ A = \\left\\{ \\begin{array}{c}\n\\dv{\\left(D^r_{st}\\right)}{u}R^rS_sT_t\\\\\\\\\n\\ -D^r_{st}S_sT_t\\Gamma^r_{mn}R^m\\dv{x^n}{u}\\\\\\\\\n\\ +D^r_{st}R_rT_t \\Gamma^m_{sn}S^m\\dv{x^n}{u}\\\\\\\\\n\\ +D^r_{st}R_rS_s\\Gamma^m_{tn}T^m\\dv{x^n}{u}\n\\end{array} \\right.\n\\end{align}\nIn (5) apply the following renaming of dummy variables \n$$\\left\\{\\begin{array}{c}\n2^{nd} line: \\quad r\\rightarrow m, m \\rightarrow r\\\\\n3^{rd} line: \\quad s\\rightarrow m, m \\rightarrow s\\\\\n4^{th} line: \\quad t\\rightarrow m, m \\rightarrow t\\\\\n\\end{array}  \\right. $$\nand regrouping terms with $R^rS_sT_t$,(5) becomes then\n\\begin{align}\n\\ A = \\left[\\dv{\\left(D^r_{st}\\right)}{u}+(\\ D^r_{mt}\\Gamma^s_{mn}+\\ D^r_{sm}\\Gamma^t_{mn}-\\ D^m_{st}\\Gamma^m_{rn})\\dv{x^n}{u}\\right]R^rS_sT_t\n\\end{align}\nBut $A$ is an invariant, so the expression in the square parenthesis is a tensor of the form $T^r_{st}$ and we define the absolute derivative of $T^r_{st}$ as:\n$$ \\frac{\\delta T^r_{st}}{\\delta u} = \\dv{\\left(T^r_{st}\\right)}{u}+\\Gamma^s_{mn} T^r_{mt}\\dv{x^n}{u}+\\Gamma^t_{mn}T^r_{sm}\\dv{x^n}{u}-\\Gamma^m_{rn} T^m_{st}\\dv{x^n}{u}$$\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p53-exercise}\n\\begin{tcolorbox}\nProve that $$\\delta^r_{s|t} = 0, \\quad a^{rs}_{|t} = 0$$\n\\end{tcolorbox}\n\ni)$\\delta^t_{s|t} = 0$\n\\begin{align}\n\\text{(2.524) gives:}\\quad \\delta^r_{s|t} &= \\underbrace{\\pdv{\\delta^r_{s}}{x^t}}_\\text{=0} + \\Gamma^r_{mt}\\delta^m_{s}- \\Gamma^m_{st}\\delta^r_{m}\\\\\n&= \\Gamma^r_{st}- \\Gamma^r_{st} = 0\n\\end{align}\n\nii)$ a^{rs}_{|t} = 0$\nWe know that \n\\begin{align}\n\\delta^r_{s|t} &= a_{sk}a^{kr}|_{t}\\\\\n\\Rightarrow \\delta^r_{s|t} &= \\pdv{a_{sk}}{x^t}a^{kr}+ a_{sk}\\pdv{a^{kr} }{x^t} + \\Gamma^r_{mt}a_{sk}a^{km}- \\Gamma^m_{st}a_{mk}a^{kr}\n\\end{align}\nRearrange (4) and add $\\Gamma^k_{mt}a_{ks}a^{mr}$ and subtract $\\Gamma^m_{kt}a_{ms}a^{kr}$ (as $\\Gamma^k_{mt}a_{ks}a^{mr} - \\Gamma^m_{kt}a_{ms}a^{kr}  =0 $)\n\\begin{align}\n\\delta^r_{s|t} &= (\\pdv{a_{sk}}{x^t}- \\Gamma^m_{st}a_{mk}-\\Gamma^m_{kt}a_{ms} )a^{kr}+ (\\pdv{a^{kr} }{x^t} + \\Gamma^r_{mt}a^{km}+ \\Gamma^k_{mt}a^{mr})a_{sk}\\\\\n\\text{but} \\quad  a_{sk|t} &= (\\pdv{a_{sk}}{x^t}- \\Gamma^m_{st}a_{mk}-\\Gamma^m_{kt}a_{ms})\\\\\n\\text{and as (2.526)}\\quad a_{sk|t} = 0\\\\\n\\text{(5) becomes}\\quad \\delta^r_{s|t} &= \\underbrace{(\\pdv{a^{kr} }{x^t} + \\Gamma^r_{mt}a^{km}+ \\Gamma^k_{mt}a^{mr})}_{\\begin{huge}a^{kr}_{|t}\\end{huge}}a_{sk}\\\\\n\\ &= a^{kr}_{|t}a_{sk}\\\\\n\\ &= 0 \\quad \\text{as}\\quad \\delta^r_{s|t}=0  \\quad \\text{(see first  part of this exercise)}\n\\end{align}\nAs all $a_{ks}$ can't be zero and as we didn't choose any special Riemannian space, we can conclude from $ a^{kr}_{|t}a_{sk} = 0$ that $$ a^{rs}_{|t} = 0$$ \n$$\\blacklozenge$$\n\\newpage\n\n\\section{p54-exercise}\n\\begin{tcolorbox}\nProve that $$\\dv{(a_{mn}\\lambda^m\\lambda^n)}{s} = 2 a_{mn}\\lambda^m \\frac{\\delta\\lambda^n}{\\delta s}$$\n\\end{tcolorbox}\n\\begin{align} \\dv{(a_{mn}\\lambda^m\\lambda^n)}{s}= \\dv{a_{mn}}{s}\\lambda^m\\lambda^n+2a_{mn}\\lambda^m \\dv{\\lambda^n}{s}\n\\end{align}\nBy definition of the absolute derivative, we have:\n\\begin{align}\n\\frac{\\delta \\lambda^n}{\\delta s}& =\\dv{\\lambda ^n}{s}  + \\Gamma^n_{pk}\\lambda^p\\dv{x^k}{s} \\\\\n\\text{(2) in (1)}\\quad \\dv{(a_{mn}\\lambda^m\\lambda^n)}{s}&= \\dv{a_{mn}}{s}\\lambda^m\\lambda^n+2a_{mn}\\lambda^m (\\frac{\\delta \\lambda^n}{\\delta s} - \\Gamma^n_{pk}\\lambda^p\\dv{x^k}{s})\\\\\n\\ &= \\dv{a_{mn}}{s}\\lambda^m\\lambda^n+2a_{mn}\\lambda^m \\frac{\\delta \\lambda^n}{\\delta s} - 2a_{mn}\\lambda^m \\Gamma^n_{pk}\\lambda^p\\dv{x^k}{s}\\\\\n\\text{we have} \\quad \\Gamma^n_{pk} &= a^{ns}[pk,s]\\\\\n\\text{so,} \\quad \\dv{(a_{mn}\\lambda^m\\lambda^n)}{s}&= \\dv{a_{mn}}{s}\\lambda^m\\lambda^n+2a_{mn}\\lambda^m \\frac{\\delta \\lambda^n}{\\delta s} - 2\\underbrace{a_{mn}a^{ns}}_{=\\delta^s_m}[pk,s]\\lambda^m \\lambda^p\\dv{x^k}{s}\\\\\n&= \\dv{a_{mn}}{s}\\lambda^m\\lambda^n+2a_{mn}\\lambda^m \\frac{\\delta \\lambda^n}{\\delta s} - 2[pk,m]\\lambda^m \\lambda^p\\dv{x^k}{s}\\\\\n\\text{but} \\quad 2[pk,m]\\lambda^m\\lambda^p &= [pk,m]\\lambda^m\\lambda^p+[pk,m]\\lambda^m\\lambda^p\\\\\n&= [pk,m]\\lambda^m\\lambda^p+[mk,p]\\lambda^m\\lambda^p\\\\\n\\text{we have also }\\quad &\\left \\{ \\begin{array}{c}\n\\ [pk,m] = \\frac{1}{2}(\\partial _k a_{pm} + \\partial _p a_{km}-\\partial _m a_{pk})\\\\\n\\ [mk,p] = \\frac{1}{2}(\\partial _k a_{pm} + \\partial _m a_{pk}-\\partial _p a_{mk})\\\\\n\\end{array}\\right.\\\\\n\\ &\\Rightarrow 2[pk,m] = \\partial _k a_{pm}\\\\\n\\text{so} \\quad \\dv{(a_{mn}\\lambda^m\\lambda^n)}{s} &= \\dv{a_{mn}}{s}\\lambda^m\\lambda^n - \\underbrace{ \\partial _k a_{pm}\\dv{x^k}{s}}_{=\\dv{a_{mn}}{s}} \\lambda^m \\lambda^p +2a_{mn}\\lambda^m \\frac{\\delta \\lambda^n}{\\delta s} \\\\\n\\ & \\Rightarrow \\quad  \\dv{(a_{mn}\\lambda^m\\lambda^n)}{s} = 2a_{mn}\\lambda^m \\frac{\\delta \\lambda^n}{\\delta s} \n\\end{align} \n$$\\blacklozenge$$\n\\newpage\n\n\\section{p54-exercise}\n\\begin{tcolorbox}\nProve that $$(T^rS_s)_{|n} = T^r_{|n}S_s+T^rS_{|n}$$\n\\end{tcolorbox}\n\\begin{align} (T^rS_s)_{|n} &=  \\partial_n(T^rS_s) + \\Gamma^r_{nm}T^mS_s - \\Gamma^m_{sn}T^rS_m\\\\\n\\ &=  \\partial_n(T^r)S_s+ T^r\\partial_n(S_s) + S_s\\Gamma^r_{nm}T^m - T^r\\Gamma^m_{sn}S_m\\\\\n\\ &=  T^r\\underbrace{(\\partial_n(S_s) - \\Gamma^m_{sn}S_m)}_{S_{s|n}}+S_s\\underbrace{(\\partial_n(T^r)+ \\Gamma^r_{nm}T^m)}_{T^r_{|n}}\\\\\n\\ &=  T^rS_{s|n}+S_sT^r_{|n}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p57-exercise}\n\\begin{tcolorbox}\nCompute the Christoffel symbols in 2.540 directly from the definitions 2.421 and 2.422. Check that all Christoffels symbols not shown explicitly in 2.540 vanish.\n\\end{tcolorbox}\n\\textit{Easy but very tedious, not reproduced yet, later perhaps}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p57-exercise}\n\\begin{tcolorbox}\nShow that for the spherical polar metric 2.532, we have $ln\\sqrt{a} = 2 ln(x^1)+ln(sin(x^2))$ and \n$$\\textbf{2.544}\\quad \\Gamma^n_{1n} = \\frac{2}{x^1},\\quad \\Gamma^n_{2n} = \\cot (x^2),\\quad\\Gamma^n_{3n} =0$$\n\\end{tcolorbox}\nThe spherical polar metric 2.532 is,\n\\begin{align}\n\\ (a_{mn})&= \\begin{pmatrix}\n 1& 0 & 0 \\\\\n 0& (x^1)^2 & 0 \\\\\n 0& 0 & (x^1 \\sin (x^2))^2 \\\\\n\\end{pmatrix}\\\\\n\\Rightarrow |a_{mn}| &= \\left[(x^1)^2 \\sin (x^2)\\right]^2\\\\\n\\Rightarrow ln(\\sqrt{|a_{mn}|}) &= 2ln(x^1)+ln(\\sin (x^2))\\\\\n\\Rightarrow\\quad\\quad &\\left \\{\\begin{array}{c}\n\\Gamma^n_{1n} = \\partial_1(ln(\\sqrt{a})) = \\frac{2}{x^1}\\\\\\\\\n\\Gamma^n_{2n} = \\partial_2(ln(\\sqrt{a})) = \\frac{\\cos(x^2)}{\\sin(x^2)} =  \\cot (x^2)\\\\\\\\\n\\Gamma^n_{3n} = 0\\\\\n\\end{array}\\right.\n\\end{align} \n$$\\blacklozenge$$\n\\newpage\n\n\\section{p58-exercise}\n\\begin{tcolorbox}\nShow that for the spherical polar metric \n$$\\textbf{2.546}\\quad T^n_{\\ |n} = \\frac{1}{r^2}\\partial_r(r^2 \\ T^1) + \\frac{1}{\\sin \\theta }\\partial_{\\theta}(\\sin \\theta\\  T^2) + \\partial_{\\phi}T^3 $$\nObtain a similar expression for the \"Laplacian\" $\\Delta V$ of an invariant $V$ defined as $$\\textbf{2.547}\\quad\\Delta V = \\left( a^{mn}\\partial_m V\\right)_{|n}$$\n\\end{tcolorbox}\nWe have\n\\begin{align}\n\\textbf{(2.545)}\\quad T^n_{\\ |n} &= \\frac{1}{\\sqrt{a}}\\partial_n(\\sqrt{a} \\ T^n)\\\\\n\\text{and from the previous exercise p.58:}\\quad \\sqrt{a} &= (x^1)^2\\sin(x^2)\n\\end{align}\n\\begin{align}\n\\Rightarrow \\quad T^n_{\\ |n} &= \\frac{1}{\\sqrt{a}}\\left(\\sin(x^2) \\partial_1[(x^1)^2 T^1]  + (x^1)^2\\partial_2 [ \\sin (x^2)T^2] + (x^1)^2 \\sin (x^2)\\partial_3 T^3 \\right)\\\\\n&= \\frac{1}{x^1} \\partial_1[(x^1)^2 T^1]  + \\frac{1}{\\sin (x^2)}\\partial_2 [ \\sin (x^2)T^2] + \\partial_3 T^3 \n\\end{align}\nReplace in (4) $\\quad x^1 =r$, $x^2 =  \\theta$ and $x^3 = \\phi$\n\\begin{align}\n\\ T^n_{\\ |n} = \\frac{1}{r^2} \\partial_r [r^2 \\ T^r]  + \\frac{1}{\\sin \\theta}\\partial_{\\theta} [ \\sin \\theta \\ T^{\\theta}] + \\partial_{\\phi} T^{\\phi} \n\\end{align}\nLet's calculate the Laplacian.\n\\begin{align}\n\\Delta V &= \\left( a^{mn}\\partial_m V\\right)_{|n}\\\\\n\\text{be}\\quad \\quad \\quad G^n &= a^{mn}\\partial_m V\\\\\n\\text{then (see exercise p.32) } \\quad \\quad \\left\\{ \\begin{array}{c}\n\\ G^1 = \\partial_r V\\\\\n\\ G^2 = \\frac{1}{r^2}\\partial_{\\theta} V\\\\\n\\ G^1 = \\frac{1}{r^2 \\sin ^2 \\theta}\\partial_{\\phi} V\\\\\n\\end{array}\\right.\n\\end{align}\nand by the previous result of this exercise\n\\begin{align}\n\\Delta V &= G^n_{|n} = \\frac{1}{r^2} \\partial_r [r^2 \\ G^1]  + \\frac{1}{\\sin \\theta}\\partial_{\\theta} [ \\sin \\theta \\ G^{2}] + \\partial_{\\phi} G^{3} \\\\\n\\ &= \\frac{1}{r^2} \\partial_r [r^2 \\partial_r V]  + \\frac{1}{r^2 \\sin \\theta}\\partial_{\\theta} [ \\sin \\theta \\ \\partial_{\\theta} V] + \\frac{1}{r^2 \\sin ^2 \\theta}\\partial^2_{\\phi} V\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p60 - clarification for 2.609}\n\\begin{tcolorbox}\n$$A^r_{.mns} = - \\partial_s \\Gamma^r_{mn} + 2 \\Gamma^r_{sp}\\Gamma^p_{mn}$$\n\\end{tcolorbox}\nWe have (2.608):\n\\begin{align}\n\\dv[2] {x^r}{s} &= - \\Gamma^r_{mn}p^m p^n\\\\\n\\RAr \\dv[3] {x^r}{s} &= - \\dv{\\Gamma^r_{mn}}{s}p^m p^n- \\Gamma^r_{mn}\\left(p^m \\dv{p^n}{s}+p^n \\dv{p^m}{s} \\right)\\\\\n\\ & = - \\partial_k \\Gamma^r_{mn}\\underbrace{\\dv{x^k}{u}}_{= p^k}p^m p^n- \\Gamma^r_{mn}\\left(p^m \\dv{p^n}{s}+p^n \\dv{p^m}{s} \\right)\\\\\n\\text{as}\\quad \\dv{p^g}{s} = \\dv[2] {x^g}{s} = - \\Gamma^g_{ik}p^i p^k \\RAr  & = - \\partial_k \\Gamma^r_{mn}\\underbrace{\\dv{x^k}{s}}_{= p^k}p^m p^n + \\Gamma^r_{mn}p^m \\Gamma^n_{ik}p^i p^k+ \\Gamma^r_{mn}p^n \\Gamma^m_{ki}p^k p^i \n\\end{align}\nIn the second and third terms, rename the dummy indices : $ m \\leftrightarrow k,  n \\leftrightarrow i\\ $  and $ m \\leftrightarrow i,  n \\leftrightarrow k\\ $.\\\\\nSo (4) becomes\n\\begin{align}\n\\dv[3] {x^r}{s} &=  - \\partial_k \\Gamma^r_{mn} p^m p^np^k +\\Gamma^r_{ki}p^k \\Gamma^i_{nm}p^n p^m+ \\Gamma^r_{ik}p^k \\Gamma^i_{nm}p^n p^m\\\\\n\\ &=  \\left( - \\partial_k \\Gamma^r_{mn}  +\\Gamma^r_{ik} \\Gamma^i_{mn}+ \\Gamma^r_{ik} \\Gamma^i_{nm} \\right)p^m p^np^k\\\\\n\\ &=  \\left( - \\partial_k \\Gamma^r_{mn}  +2\\Gamma^r_{ik} \\Gamma^i_{mn}\\right)p^m p^np^k\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p62-exercise}\n\\begin{tcolorbox}\nProve that if a pair of vectors are unit orthogonal vectors at a point on a curve, and if they are both propagated parallelly along the curve, then they remain unit orthogonal vectors along the curve.\n\\end{tcolorbox}\nGiven is, a pair of vectors $U^m$ and $V^m$ which are unit orthogonal vectors at a point on a curve. So,\n\\begin{align}\n\\begin{array}{cc}\n\\text{U is a unit vector (2.302)}& a_{mn}U^m U^n = \\epsilon\\\\\n\\text{V is a unit vector (2.302)}& a_{mn}V^m V^n = \\epsilon\\\\\n\\text{U, V are orthogonal (2.317)}& a_{mn}U^m V^n = 0\\\\\n\\end{array}\n\\end{align}\nat one point on the curve.\\\\\nWe have to prove that the above properties are valid along the curve (i.e. $\\forall$ points on the curve) provided that the vectors are propagated // along the curve, which means\n\\begin{align}\n\\textbf{(2.512)}\\quad\\quad \\frac{\\delta U^r}{\\delta u} &= \\dv{U^r}{u} + \\Gamma^r_{mn}U^m \\dv{x^n}{u} = 0\n\\end{align}\nfor both vectors $U, V$. Thus,\n\\begin{align}\n\\dv{U^r}{u} = - \\Gamma^r_{mn}U^m \\dv{x^n}{u}\n\\end{align}\\\\\ni) Consider the magnitude M at a random point on the curve\n\\begin{align}\n\\ M &= a_{mn}U^m U^n \\\\\n\\Rightarrow \\quad\\quad \\dv{M}{s} &= \\dv{a_{mn}}{u}U^m U^n + 2a_{mn}U^m \\dv{U^n}{u} \n\\end{align}\\\\\nObviously $M$ and $\\dv{M}{s}$ are invariants. Also, we can choose at any point on the curve a Riemannian coordinate system (RCS) for which the Christoffel symbols vanish at that point. Hence, $\\dv{U^r}{u} = 0 $ at that point and the second term in the right part of (5) vanish. (5) becomes then,\n\\begin{align}\n \\dv{M}{s} = \\pdv{a^,_{mn}}{x^{,k}}\\dv{x^{,k}}{s}U^{,m} U^{,n}  \n\\end{align}\nWe also know \\textbf{(2.425. page 41)} that $[km,n]^, + [kn,m]^, = \\pdv{a^,_{mn}}{x^{,k}}$. But in the chosen coordinate system, $[km,n] = 0$ at the origin of this coordinate system. So by (6) we get $\\dv{M}{s} = 0$.\\\\\nSo the magnitude is constant along the curve and as we know that a certain point $M =1$:\\\\\n$$\\textbf{ U,V are unit vectors along the curve}$$\\newpage\nii) Consider now the angle between the vectors $U,V$. Be $A = \\cos \\ \\theta$.By definition \n\\begin{align}\n\\ A &= a_{mn}U ^mV^n\\\\\n\\Rightarrow \\quad\\quad \\dv{A}{s} &= \\dv{a_{mn}}{u}U^m V^n + a_{mn}(V^m \\dv{U^n}{u} +U^m \\dv{V^n}{u} )\n\\end{align}\nWe follow the same reasoning as in i) and so\n$$\\dv{A}{s} = 0$$\nSo, the angle is constant and we know is is $\\frac{\\pi}{2}$ at a certain point. So,:\n$$\\textbf{ U,V are orthogonal along the curve}$$\n\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p62-exercise}\n\\begin{tcolorbox}\nGiven that $\\lambda^r$ is a unit vector field, prove that $$\\lambda^r_{\\ |s}\\lambda_r = 0 \\quad \\text{and}\\quad \\lambda^r\\lambda_{r|s} = 0 $$\nIs the relation $\\lambda^r_{\\ |s}\\lambda_s = 0$ true for a general unit vector field?\n\\end{tcolorbox}\nTo simplify the calculation, we choose a random element in the unit vector field and use at that point a Riemannian coordinate system (RCS). So, we have\n\\begin{align}\n\\lambda^r_{\\ |s} = \\partial_s \\lambda^r \\quad & \\text{and}\\quad \\lambda_{r|s} = \\partial_s \\lambda_r\\\\\n\\text{as we have a unit vector fields:}\\quad\\quad a_{mn}\\lambda^m\\lambda^n &= 1\\\\\n\\Leftrightarrow \\lambda_n\\lambda^n &= 1\\quad\\quad\\text{(by lowering the index m)}\\\\\n\\Rightarrow \\quad\\quad \\lambda^n\\partial_s \\lambda_n + \\lambda_n\\partial_s \\lambda^n &= 0\n\\end{align}\nWe prove that $$\\lambda^n\\partial_s\\lambda_n = \\lambda_n\\partial_s\\lambda^n\\quad \\forall\\text{ vector fields}$$\nWe have the trivial identity\n\\begin{align}\n\\partial_s(\\lambda^r\\lambda_r) &= \\partial_s(\\lambda^r\\lambda_r)\\\\\n\\Leftrightarrow \\quad\\quad \\partial_s(a^{rm}\\lambda_m\\lambda_r) &= \\partial_s(a_{rm}\\lambda^m\\lambda^r)\n\\end{align}\n\\begin{lemma}: $\\partial_sa^{rm} = 0$ in a Riemannian coordinate system (i.e. at the origin)\\\\\\\\\nWe have\n\\begin{align}\n\\ a^{rm}a_{ms} &= \\delta^r_s\\\\\n\\Rightarrow a_{ms}\\partial_k a^{rm}  & +a^{rm}\\partial_k a_{ms} = 0\\\\\n\\text{we know (2.618)}\\quad\\quad \\partial_r a_{mn} &= 0\\quad\\quad\\text{at the origin of a RCS}\\\\\n\\text{so (8) becomes}\\quad\\quad a_{ms}\\partial_k a^{rm} & = 0\\\\\n\\text{multiply (10) by}\\quad a^{ns}\\quad\\Rightarrow \\underbrace{a^{ns}a_{ms}}_{= \\delta^n_m}\\partial_k a^{rm}& = 0\\\\\n\\Rightarrow\\quad\\quad \\partial_k a^{rn}& = 0\n\\end{align}\n\\end{lemma}\n$$\\diamond$$\nNow, expanding (6) and using $\\textbf{2.618}$ and the lemma:\n\\begin{align}\n\\ a^{rm}\\lambda_m\\partial_s \\lambda_r+ a^{rm} \\lambda_r \\partial_s \\lambda_m &= a_{rm} \\lambda^m \\partial_s \\lambda^r + a_{rm} \\lambda^r \\partial_s \\lambda^m\\\\\n\\text{renaming dummy indices:}\\quad\\quad   a^{rm} \\lambda_r \\partial_s \\lambda_m &= a_{rm} \\lambda^r \\partial_s \\lambda^m \\\\\n\\Rightarrow\\quad\\quad \\lambda^m \\partial_s \\lambda_m &= \\lambda_m \\partial_s \\lambda^m\n\\end{align}\nConsidering (5) and (15) we conclude:\n\\begin{align}\n\\lambda^n \\partial_s \\lambda_n &= \\lambda_n \\partial_s \\lambda^n = 0\n\\end{align}\nand as $\\partial_s \\lambda_n = \\lambda_{n|s} $ and $\\partial_s \\lambda^n = \\lambda^n_{\\ |s} $ at the origin of the considered coordinate system, we have:\n\\begin{align}\n\\lambda^m \\lambda_{n|s} &= \\lambda_m \\lambda^n_{\\ |s} = 0\n\\end{align}\n$$\\diamond$$\nIs the relation $\\lambda^r_{|s}\\lambda_s = 0$ true for a general unit vector field?\\\\\nThe answer is NO. Let's consider the following unit vector field in a Cartesian Coordinate system:\n\\begin{figure}[H]\n\n\\centering\n\\begin{minipage}[H]{.4\\textwidth}\n\n%\\centering\n\\vspace{0pt}\n\\input{D:/MathLatex/images/fig_p62_236_a.tex}\n%\\includegraphics[scale=.3]{unitvectorfield1.jpg}\n\\end{minipage}\\hfill\n\\begin{minipage}[H]{0.4\\textwidth}\n%\\centering\n\\vspace{50pt}\n$$V:\\mathbb{R}_*^2\\rightarrow \\mathbb{R}^2|V(x,y) = \\left< \\frac{x}{\\sqrt{x^2+y^2}},-\\frac{y}{\\sqrt{x^2+y^2}} \\right>$$\n\\end{minipage}\n\\caption{Vector field for which $\\lambda^r_{|s}\\lambda_s = 0$ does not hold}\n\\label{fig:fig_p62_236_a}\n\\end{figure}\nPut $ r = \\sqrt{x^2+y^2}$, we get (as we have a Cartesian Coordinate system, the  Christoffel symbols vanish and the covariant components of the vectors are equal to their contravariant part):\n\\newpage\n\\begin{align}\n\\ & \\left \\{ \\begin{array}{c}\n\\ V^1 = V_1 = +\\frac{x}{r}\\\\\n\\ V^2 = V_2 = -\\frac{y}{r}\\\\\n\\end{array}\\right.\\\\\n\\ & \\left \\{ \\begin{array}{cc}\n\\ V^1_{\\ |1} =  V_{1|1} = \\frac{y^2}{r^3}&V^1_{\\ |2} =  V_{1|2} = -\\frac{xy}{r^3}\\\\A\n\\ V^2_{\\ |1} =  V_{2|1} = \\frac{xy}{r^3}&V^2_{\\ |2} =  V_{2|2} = -\\frac{x^2}{r^3}\\\\\n\\end{array}\\right.\\\\\n\\Rightarrow \\quad\\quad &\\left \\{ \\begin{array}{c} \\  V^1_{\\ |s}V_s = V^1_{\\ |1}V_1+V^1_{\\ |2}V_2 = \\frac{y^2}{r^3}\\frac{x}{r}+ (-\\frac{xy}{r^3})(-\\frac{y}{r}) = \\frac{xy^2}{r^4} \\ne 0\\\\\n\\ V^2_{\\ |s}V_s = V^2_{\\ |1}V_1+V^2_{\\ |2}V_2 = \\frac{xy}{r^3}\\frac{x}{r}+ (-\\frac{y}{r})(-\\frac{y}{r}) = \\frac{x^2 y}{r^4} \\ne 0\n\\end{array} \\right.\n\\end{align}\nJust as a check, we calculate $V^r_{|s}V_r$ which should be zero:\n\\begin{align}\n\\Rightarrow \\quad\\quad &\\left \\{ \\begin{array}{c}V^s_{\\ |1}V_s = V^1_{\\ |1}V_1+V^2_{\\ |1}V_2 = (+\\frac{y^2}{r^3})\\frac{x}{r}+ (+\\frac{xy}{r^3})(-\\frac{y}{r}) =0\\\\\n\\ V^s_{\\ |2}V_s = V^1_{\\ |2}V_1+V^2_{\\ |2}V_2 = (-\\frac{xy}{r^3})\\frac{x}{r}+ (-\\frac{y}{r})(-\\frac{x^2}{r^3}) = 0\n\\end{array} \\right.\n\\end{align}\\\\\\\\\nNow, let's consider another unit vector field in a Cartesian Coordinate system:\n\\begin{figure}[H]\n\n\\centering\n\\begin{minipage}[H]{.4\\textwidth}\n%\\centering\n\\vspace{0pt}\n%\\includegraphics[scale=.3]{unitvectorfield2.jpg}\n\\input{D:/MathLatex/images/fig_p62_236_b.tex}\n\\end{minipage}\\hfill\n\\begin{minipage}[H]{0.4\\textwidth}\n%\\centering\n\\vspace{50pt}\n$$V:\\mathbb{R}_*^2\\rightarrow \\mathbb{R}^2|V(x,y) = \\left< \\frac{x}{\\sqrt{x^2+y^2}},\\frac{y}{\\sqrt{x^2+y^2}} \\right>$$\n\\end{minipage}\n\\caption{Vector field for which $\\lambda^r_{|s}\\lambda_s = 0$ hold}\n\\label{fig:fig_p62_236_b}\n\\end{figure}\n\\begin{align}\n\\ & \\left \\{ \\begin{array}{c}\n\\ V^1 = V_1 = +\\frac{x}{r}\\\\\n\\ V^2 = V_2 = +\\frac{y}{r}\\\\\n\\end{array}\\right.\\\\\n\\ & \\left \\{ \\begin{array}{cc}\n\\ V^1_{\\ |1} =  V_{1|1} = \\frac{y^2}{r^3}&V^1_{\\ |2} =  V_{1|2} = -\\frac{xy}{r^3}\\\\\n\\ V^2_{\\ |1} =  V_{2|1} = -\\frac{xy}{r^3}&V^2_{\\ |2} =  V_{2|2} = +\\frac{x^2}{r^3}\\\\\n\\end{array}\\right.\\\\\n\\Rightarrow \\quad\\quad &\\left \\{ \\begin{array}{c} \\  V^1_{\\ |s}V_s = V^1_{\\ |1}V_1+V^1_{\\ |2}V_2 = (+\\frac{y^2}{r^3})\\frac{x}{r}+ (-\\frac{xy}{r^3})(+\\frac{y}{r}) =  0\\\\\n\\ V^2_{\\ |s}V_s = V^2_{\\ |1}V_1+V^2_{\\ |2}V_2 = (-\\frac{xy}{r^3})\\frac{x}{r}+ (+\\frac{y}{r})(+\\frac{y}{r}) =  0\n\\end{array} \\right.\n\\end{align}\nJust as a check, we calculate $V^r_{|s}V_r$ which should be zero:\n\\begin{align}\n\\Rightarrow \\quad\\quad &\\left \\{ \\begin{array}{c}V^s_{\\ |1}V_s = V^1_{\\ |1}V_1+V^2_{\\ |1}V_2 = (+\\frac{y^2}{r^3})(+\\frac{x}{r})+ (-\\frac{xy}{r^3})(+\\frac{y}{r}) =0\\\\\n\\ V^s_{\\ |2}V_s = V^1_{\\ |2}V_1+V^2_{\\ |2}V_2 = (-\\frac{xy}{r^3})(+\\frac{x}{r})+ (+\\frac{y}{r})+\\frac{x^2}{r^3}) = 0\n\\end{array} \\right.\n\\end{align}\\\\\nSo, in the second example the relationship $\\lambda^r_{|s}\\lambda_s = 0$ holds.\nQuestion (to investigate further and later) : does the fact that in the first case $\\grad \\maal \\overline{V}  \\ne 0$ and in the second case $\\grad \\maal \\overline{V}= 0$, means that there is some relation with this expression?\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p64-clarification 2.625}\n\\begin{tcolorbox}\n$\\textbf{2.625} \\quad\\quad\\quad\\quad\\quad\\quad \\dv{ x^r}{x^N} = \\frac{X^r}{X^N}$\n\\end{tcolorbox}\nBe $C$ a surface defined by the function $F(x^1,\\dots, x^{N-1}) = C$ and  $c_{\\perp}$ the curve intersecting the surface $C$ perpendicularly at a point $p$.\\\\\nAlong the curve at that point $p$ we have\n\\begin{align}\n\\text{as}\\quad\\quad & \\left \\{ \\begin{array}{cc}\n\\dv{ x^r}{s}& \\text{is the tangent vector along}\\quad c_{\\perp}\\\\\n\\ X^r = a^{rn}\\pdv{F}{x^n}& \\text{ is orthogonal on the surface (2.623)}\\quad C\\\\\n\\end{array}\\right.\\\\\n\\Rightarrow \\quad\\quad & \\dv{ x^r}{s} = kX^r\n\\end{align}\nSo, $\\dv{ x^r}{s}$ is proportional to $X^r$ (as the curve intersects the surface orthogonally). This means that also all the components (coordinates) of both quantities are proportional. And so,\n\\begin{align}\n\\frac{\\dv{ x^r}{s}}{\\dv{ x^N}{s}} &= \\frac{kX^r}{kX^N}\\\\\n\\Rightarrow\\quad\\quad \\dv{ x^r}{x^N} &= \\frac{X^r}{X^N}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p65-exercise}\n\\begin{tcolorbox}\nDeduce from $\\textbf{2.629}$ that $$a^{N \\rho} = 0  \\quad\\quad a^{NN} = \\frac{1}{a_{NN}}$$\n\\end{tcolorbox}\nWe have (see 2.629):\n\\begin{align}\n\\ a_{N\\rho} =0\\\\\n\\text{and also}\\quad\\quad a_{Nm}a^{ms} = \\delta^s_N\n\\end{align}\nIn (2) split the $m$ index in the subspace and the remaining coordinate $N$\n\\begin{align}\n\\ a_{N\\rho}a^{\\rho s} +  a_{NN}a^{N s} &= \\delta^s_N\\\\\n\\text{as}\\quad a_{N\\rho} =0 \\Rightarrow \\quad\\quad a_{NN}a^{N s} &= \\delta^s_N\n\\end{align}\\\\\nCase 1: $s\\ne N$\n\\begin{align}\n\\  a_{NN}a^{N s} =0 \\quad \\Leftrightarrow \\quad a_{NN}a^{N \\rho} =0 \\quad\\quad \\text{(as}\\quad s\\ne N \\text{)}\\\\\n\\text{as we suppose}\\quad a_{NN}\\ne 0 \\quad \\Rightarrow \\quad a^{N \\rho} =0\n\\end{align}\\\\\n\nCase 2: $s= N$\n\\begin{align}\n\\  a_{NN}a^{N N} &=1 \\\\\n\\Rightarrow \\quad a^{N N} &=\\frac{1}{a_{NN}}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p69-clarification on 2.645}\n\\begin{tcolorbox}\nIn 2.645 we have $$T_{\\alpha | \\beta} =T_{\\alpha || \\beta}  +\\frac{1}{2}\\frac{1}{a_{NN}}\\partial_N  a_{\\alpha\\beta}T_{N}$$ and $$T_{\\alpha | \\beta} =T_{\\alpha || \\beta}  +\\frac{1}{2}\\partial_N  a_{\\alpha\\beta}T^{N}$$\n\\end{tcolorbox}\nIndeed,\n\\begin{align}\n\\ T^N &= a^{mN}T_m\\\\\n\\ & = a^{\\alpha N}T_{\\alpha}+a^{N N}T_{N}\\\\\n\\text{but (2.631)}\\quad\\quad a^{\\alpha N} &= 0\\\\\n\\Rightarrow \\quad\\quad T^N &= a^{NN} T_N\\\\\n\\text{as}\\quad a^{NN}= \\frac{1}{a_{NN}} \\quad \\Rightarrow \\quad\\quad  T_{\\alpha | \\beta} &= T_{\\alpha || \\beta}  + \\frac{1}{2}\\partial_N  a_{\\alpha\\beta}T^{N}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\\section{p69-exercise}\n\\begin{tcolorbox}\nShow that\n$$\\textbf{2.648}\\quad\\quad T^{\\alpha}_{\\ |\\beta} = T^{\\alpha}_{\\ ||\\beta} + \\half a^{\\alpha \\mu} \\partial_N a_{\\mu\\beta}T^N$$\n$$\\textbf{2.649}\\quad\\quad T^{N}_{\\ |\\alpha} = \\partial_{\\alpha}T^{N} - \\frac{1}{2 a_{NN}} \\partial_N a_{\\alpha\\mu}T^{\\mu} + \\frac{1}{2 a_{NN}} \\partial_{\\alpha} a_{NN}T^{N}$$\n$$\\textbf{2.650}\\quad\\quad T^{\\alpha}_{\\ |N} = \\partial_{N}T^{\\alpha}  + \\half a^{\\alpha\\mu} \\partial_N a_{\\mu\\sigma}T^{\\sigma} - \\half a^{\\alpha\\mu}  \\partial_{\\mu} a_{NN}T^{N}$$\n\\end{tcolorbox}\ni) $T^{\\alpha}_{\\ |\\beta} = T^{\\alpha}_{\\ ||\\beta} + \\half a^{\\alpha \\mu} \\partial_N a_{\\mu\\beta}T^N$\\\\\n\\begin{align}\n\\textbf{(2.520)}\\quad\\quad \\Rightarrow \\quad\\quad T^{\\alpha}_{\\ |\\beta} &= \\partial_{\\beta}T^{\\alpha}+\\Gamma^{\\alpha}_{m\\beta}T^m \\quad\\quad\\text{(}m = 1,\\dots,N \\text{)}\\\\\n\\Leftrightarrow \\quad\\quad T^{\\alpha}_{\\ |\\beta} &= \\underbrace{ \\partial_{\\beta}T^{\\alpha}+ \\Gamma^{\\alpha}_{\\mu \\beta} T^{\\mu}}_{T^{\\alpha}_{ \\ || \\beta}} +\\Gamma^{\\alpha}_{N \\beta}T^{N}\\\\\n\\textbf{(2.639)}\\quad\\quad \\Gamma^{\\alpha}_{N\\beta} &= \\half a^{\\alpha \\mu}\\partial_N a^{\\mu \\beta}\\\\\n\\text{(2) and (3): }\\quad\\quad T^{\\alpha}_{\\ |\\beta} &= T^{\\alpha}_{\\ ||\\beta} + \\half a^{\\alpha \\mu} \\partial_N a_{\\mu\\beta}T^N\n\\end{align}\n$$\\diamond$$\nRemark: We also use $\\textbf{(2.639)}$ for the two other identities.\\\\\\\\\nii) $T^{N}_{\\ |\\alpha} = \\partial_{\\alpha}T^{N} - \\frac{1}{2 a_{NN}} \\partial_N a_{\\alpha\\mu}T^{\\mu} + \\frac{1}{2 a_{NN}} \\partial_{\\alpha} a_{NN}T^{N}$\\\\\n\\begin{align}\n\\textbf{(2.520)}\\quad\\quad \\Rightarrow \\quad\\quad T^{N}_{\\ |\\alpha} &= \\partial_{\\alpha}T^{N}+\\Gamma^{N}_{m\\alpha}T^m \\quad\\quad\\text{(}m = 1,\\dots,N \\text{)}\\\\\n\\Leftrightarrow \\quad\\quad T^{N}_{\\ |\\alpha} &=  \\partial_{\\beta}T^{\\alpha}+ \\underbrace{\\Gamma^{N}_{\\sigma \\alpha}}_{ - \\frac{1}{2a_{NN}}\\partial_N a_{\\sigma\\alpha}} T^{\\sigma } +\\underbrace{\\Gamma^{N}_{N \\alpha}}_{ \\frac{1}{2a_{NN}}\\partial_{\\alpha} a_{NN}}T^{N}\\\\\n\\Rightarrow \\quad\\quad T^{N}_{\\ |\\alpha} &=  \\partial_{\\beta}T^{\\alpha} - \\frac{1}{2a_{NN}}\\partial_N a_{\\sigma\\alpha}T^{\\sigma } +\\frac{1}{2a_{NN}}\\partial_{\\alpha} a_{NN}T^{N}\n\\end{align}\\\\\niii) $T^{\\alpha}_{\\ |N} = \\partial_{N}T^{\\alpha}  + \\half a^{\\alpha\\mu} \\partial_N a_{\\mu\\sigma}T^{\\sigma} - \\half a^{\\alpha\\mu}  \\partial_{\\mu} a_{NN}T^{N}$\\\\\n\\begin{align}\n\\textbf{(2.520)}\\quad\\quad \\Rightarrow \\quad\\quad T^{\\alpha}_{\\ |N} &= \\partial_{N}T^{\\alpha}+\\Gamma^{\\alpha}_{mN}T^m \\quad\\quad\\text{(}m = 1,\\dots,N \\text{)}\\\\\n\\Leftrightarrow \\quad\\quad T^{\\alpha}_{\\ |N} &=  \\partial_{N}T^{\\alpha}+ \\underbrace{\\Gamma^{\\alpha}_{\\sigma N }}_{ \\half a^{\\alpha \\mu}\\partial_N a_{\\mu\\sigma}}  T^{\\sigma }+\\underbrace{\\Gamma^{\\alpha}_{N N}}_{ -\\half a^{\\alpha\\mu}\\partial_{\\mu} a_{NN}}T^{N}\\\\\n\\Rightarrow \\quad\\quad T^{\\alpha}_{\\ |N} &=  \\partial_{N}T^{\\alpha}+ \\half a^{\\alpha \\mu}\\partial_N a_{\\mu\\sigma}T^{\\sigma } -\\half a^{\\alpha\\mu}\\partial_{\\mu} a_{NN}T^{N}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p71-exercise}\n\\begin{tcolorbox}\nWrite down equation 2.643 tot 2.650 for the special cae of a geodesic normal coordinate system.\n\\end{tcolorbox}\n\\begin{align}\n\\ \\textbf{(2.643)}\\quad \\quad T_{\\alpha || \\beta} &= \\partial_{\\beta}T_{\\alpha} - \\Gamma^{\\gamma}_{\\alpha\\beta}T_{\\gamma}\\quad\\quad \\text{(does not change)}\\\\\n\\textbf{(2.644)}\\quad \\quad T_{\\alpha | \\beta} &=T_{\\alpha || \\beta}  - \\underbrace{\\Gamma^{N}_{\\alpha\\beta}}_{=\\frac{1}{2} \\frac{1}{a_{NN}}\\partial_N  a_{\\alpha\\beta}}T_{N}\\\\\n&=T_{\\alpha || \\beta}  +\\frac{1}{2} \\epsilon\\partial_N  a_{\\alpha\\beta}T_{N}\\\\\n\\textbf{(2.645)}\\quad \\quad T_{\\alpha | \\beta} &=T_{\\alpha || \\beta}  +\\frac{1}{2}\\partial_N  a_{\\alpha\\beta}T^{N}\\quad\\quad \\text{(does not change)}\\\\\n\\textbf{(2.646)}\\quad \\quad T_{N| \\alpha } &=\\partial_{\\alpha}T_N  -\\frac{1}{2}\\partial_N  a_{\\mu\\alpha}T^{\\mu} -\\frac{1}{2}\\underbrace{\\partial_{\\alpha}  a_{NN}}_{=0}T^{N}\\\\\n&=\\partial_{\\alpha}T_N  -\\frac{1}{2}\\partial_N  a_{\\mu\\alpha}T^{\\mu} \\\\\n\\textbf{(2.647)}\\quad \\quad T_{ \\alpha |N } &=\\partial_N T_{\\alpha}  -\\frac{1}{2}\\partial_N  a_{\\mu\\alpha}T^{\\mu} -\\frac{1}{2}\\underbrace{\\partial_{\\alpha}  a_{NN}}_{=0}T^{N}\\\\\n&=\\partial_N T_{\\alpha}  -\\frac{1}{2}\\partial_N  a_{\\mu\\alpha}T^{\\mu} \\\\\n\\textbf{(2.648)}\\quad \\quad T^{\\alpha}_{ \\  | \\beta} &=T^{\\alpha}_{ || \\beta}  + \\frac{1}{2}a^{\\alpha\\mu}\\partial_N  a_{\\mu\\beta}T_{N}\\quad\\quad\\text{(does not change)}\\\\\n\\textbf{(2.649)}\\quad \\quad T^N_{ \\ | \\alpha} &=\\partial_{\\alpha}T^N  -\\frac{1}{2}\\frac{1}{a_{NN}}\\partial_N  a_{\\mu\\alpha}T^{\\mu} -\\frac{1}{2}\\frac{1}{a_{NN}}\\underbrace{\\partial_{\\alpha}  a_{NN}}_{=0}T^{N}\\\\\n\\ &= \\partial_{\\alpha}T^N  -\\frac{1}{2}\\epsilon\\partial_N  a_{\\mu\\alpha}T^{\\mu} \\\\\n\\textbf{(2.650)}\\quad \\quad T^{\\alpha}_{\\ |N} &=\\partial_N T^{\\alpha}  +\\frac{1}{2}a^ {\\alpha\\mu}\\partial_N  a_{\\mu\\sigma}T^{\\sigma} -\\frac{1}{2}a^{\\alpha\\mu}\\underbrace{\\partial_{\\mu}  a_{NN}}_{=0}T^{N}\\\\\n\\ &=\\partial_N T^{\\alpha}  +\\frac{1}{2}a^ {\\alpha\\mu}\\partial_N  a_{\\mu\\sigma}T^{\\sigma} \n\\end{align}\n\\\\\\\\\nTo investigate: note (3) and (4) which suggest that $\\epsilon T_{N} = T^{N}$. Prove formally?\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p73-Clarification 2.706}\n\\begin{tcolorbox}\n... Let us now define a unit vector $\\lambda^r_{(2)}$ and a positive invariant $\\kappa_{(2)}$ by the equation \\\\\n\\begin{align}\n\\left \\{ \\begin{array}{c}\n\\frac{\\delta\\lambda_{(1)}^r}{\\delta s} = \\kappa_{(2)}\\lambda^r_{(2)} - \\epsilon\\epsilon_{(1)}\\kappa_{(1)}\\lambda^r\\\\\n\\epsilon_{(2)}\\lambda^n_{(2)}\\lambda_{(2)n} = 1\n\\end{array} \\right.\n\\end{align}  \n\\end{tcolorbox}\nWe can state that $\\kappa_{(2)}$ is an invariant but one has to check whether the expression $(1)$ implies that $\\kappa_{(2)}$ is indeed invariant.\\\\\nWhat we know is that $\\lambda^r, \\frac{\\delta \\lambda^r}{\\delta s},\\frac{\\delta\\lambda_{(1)}^r}{\\delta s},  \\lambda^r_{(2)}$ are contravariant vectors. Also $\\kappa_{(1)}$ is an invariant as $\\frac{\\delta\\lambda^r}{\\delta s} = \\kappa_{(1)}\\lambda^r_{(1)}$ and the magnitude of $\\frac{\\delta\\lambda^r}{\\delta s}$ does not depend on the coordinate system. So,\n\\begin{align}\n\\text{(1)}\\times \\lambda_{(2)r} \\quad\\Rightarrow \\quad\\quad \\frac{\\delta\\lambda_{(1)}^r}{\\delta s}\\lambda_{(2)r} &= \\kappa_{(2)}\\lambda^r_{(2)}\\lambda_{(2)r} - \\epsilon\\epsilon_{(1)}\\kappa_{(1)}\\lambda^r\\lambda_{(2)r}\\\\\n\\Rightarrow \\quad\\quad \\kappa_{(2)}\\underbrace{\\lambda^r_{(2)}\\lambda_{(2)r}}_{\\text{invariant}} &= \\underbrace{\\frac{\\delta\\lambda_{(1)}^r}{\\delta s}\\lambda_{(2)r}}_{\\text{invariant}}  + \\underbrace{\\epsilon\\epsilon_{(1)}}_{\\text{invariant}} \\underbrace{\\kappa_{(1)}}_{\\text{invariant}} \\underbrace{\\lambda^r \\lambda_{(2)r}}_{\\text{invariant}} \\\\\n\\Rightarrow \\quad\\quad \\kappa_{(2)}&= \\text{invariant} \n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p74-Clarification 2.710}\n\\begin{tcolorbox}\n\\begin{align}\n\\textbf{2.710}\\quad\\quad\\left \\{ \\begin{array}{c}\n\\frac{\\delta\\lambda_{(M-1)}^r}{\\delta s} = \\kappa_{(M)}\\lambda^r_{(M)} - \\epsilon_{(M-2)}\\epsilon_{(M-1)}\\kappa_{(M-1)}\\lambda^r_{(M-2)}\\\\\n\\epsilon_{(M-1)}\\lambda^n_{(M-1)}\\lambda_{(M-1)n} = 1\\quad\\quad \\text{(M=1,2,...,N)}\n\\end{array} \\right.\n\\end{align}\n... It is easily proved by mathematical induction that the whole sequence of vectors defined by 2.710 are perpendicular to the tangent and to one another ...\n\\end{tcolorbox}\nWe already know from 2.703 to 2.709 that $\\lambda^r, \\lambda_{(1)}^r,\\lambda_{(2)}^r,\\lambda_{(3)}^r$, satisfying equations (1), are all mutually perpendicular. Let us assume that the orthogonality for the set $\\{\\lambda_{(k)}^r:k= 0,1,2,3,..., M-1\\}$ has been verified. We prove by induction that then, $\\lambda_{(M)}^r$ will be orthogonal to all elements of the set.\\\\\ni) Consider the set $\\{\\lambda_{(k)}^r:k= 0,1,2,3,..., M-3\\}$ where we already know that $\\lambda_{(k)}^r$ are mutually perpendicular and also $\\lambda_{(k)}^r \\perp \\lambda_{(M-1)}^r $, $\\lambda_{(k)}^r \\perp \\lambda_{(M-2)}^r$ and $\\lambda_{(M-1)}^r \\perp \\lambda_{(M-1)}^r \\quad \\forall k$.\n\\begin{align}\n\\text{(1)}\\times \\lambda_{(k)r}\\quad\\Rightarrow\\quad\\quad \\frac{\\delta\\lambda_{(M-1)}^r}{\\delta s}\\lambda_{(k)r} &= \\kappa_{(M)}\\lambda^r_{(M)}\\lambda_{(k)r} - \\epsilon_{(M-2)}\\epsilon_{(M-1)}\\kappa_{(M-1)}\\underbrace{\\lambda^r_{(M-2)}\\lambda_{(k)r}}_{=0}\\\\\n\\text{We have}  \\quad \\quad\\quad\\quad\\quad\\lambda_{(k)r}\\lambda^r_{(M-1)} &=0\\\\\n\\Rightarrow \\quad \\quad\\quad\\quad\\quad\\ \\frac{\\delta\\lambda_{(k)r}\\lambda_{(M-1)}^r}{\\delta s} &= \\lambda_{(M-1)}^r\\frac{\\delta\\lambda_{(k)r}}{\\delta s}+\\lambda_{(k)r}\\delta\\frac{\\lambda_{(M-1)}^r}{\\delta s}=0\\\\\n\\Rightarrow \\quad \\quad\\quad\\quad\\quad\\ \\lambda_{(k)r}\\delta\\frac{\\lambda_{(M-1)}^r}{\\delta s} &= - \\lambda_{(M-1)}^r\\frac{\\delta\\lambda_{(k)r}}{\\delta s}\\\\\n\\text{We have}\\quad \\quad\\quad\\quad\\quad\\frac{\\delta\\lambda_{(k)r}}{\\delta s} &= \\kappa_{(k+1)}\\lambda_{(k+1)r} - \\epsilon_{(k)}\\epsilon_{(k-1)}\\kappa_{(k)}\\lambda_{(k-1)r}\\\\\n\\text{(5) and (6)}\\Rightarrow \\quad \\quad\\quad\\quad\\quad\\ \\lambda_{(k)r}\\delta\\frac{\\lambda_{(M-1)}^r}{\\delta s} &= -\\kappa_{(k+1)}\\underbrace{\\lambda_{(k+1)r} \\lambda_{(M-1)}^r}_{=0} - \\epsilon_{(k)}\\epsilon_{(k-1)}\\kappa_{(k)}\\underbrace{\\lambda_{(k-1)r}\\lambda_{(M-1)}^r}_{=0}\\\\\n\\text{From (2)}\\Rightarrow \\quad \\quad\\quad\\quad\\quad\\ \\kappa_{(M)}\\lambda^r_{(M)}\\lambda_{(k)r}&=0\\\\\n\\Rightarrow \\quad \\quad\\quad\\quad\\quad\\ \\lambda^r_{(M)}& \\perp\\lambda_{(k)r}\\quad\\quad \\forall k= 0,1,2,3,..., M-3 \n\\end{align}\\\\\\\\\nii) Consider the case $k = M-1$\\\\\\begin{align}\n\\text{(1)}\\times \\lambda_{(M-1)r}\\quad \\frac{\\delta\\lambda_{(M-1)}^r}{\\delta s}\\lambda_{(M-1)r} &= \\kappa_{(M)}\\lambda^r_{(M)}\\lambda_{(M-1)r} - \\epsilon_{(M-2)}\\epsilon_{(M-1)}\\kappa_{(M-1)}\\underbrace{\\lambda^r_{(M-2)}\\lambda_{(M-1)r}}_{=0}\\\\\n\\text{from (2.530):}\\quad\\quad \\frac{\\delta\\lambda_{(M-1)}^r}{\\delta s}\\lambda_{(M-1)r}  &= \\half\\underbrace{\\frac{\\delta\\lambda_{(M-1)r}\\lambda_{(M-1)}^r}{\\delta s}}_{=0\\text{ as }\\lambda_{(M-1)r}\\lambda_{(M-1)}^r =  \\epsilon_{(M-1)}}\\\\\n\\Rightarrow \\quad \\quad\\quad\\quad\\quad \\kappa_{(M)}\\lambda^r_{(M)}\\lambda_{(M-1)r}&=0\\\\\n\\Rightarrow \\quad \\quad\\quad\\quad\\quad \\lambda_{(M-1)r} & \\perp\\lambda_{(M)r}\n\\end{align}\n\niii) Consider the case $k = M-2$\\\\\\begin{align}\n\\text{(1)}\\times \\lambda_{(M-2)r}\\quad \\frac{\\delta\\lambda_{(M-1)}^r}{\\delta s}\\lambda_{(M-2)r} &= \\kappa_{(M)}\\lambda^r_{(M)}\\lambda_{(M-2)r} - \\epsilon_{(M-2)}\\epsilon_{(M-1)}\\kappa_{(M-1)}\\underbrace{\\lambda^r_{(M-2)}\\lambda_{(M-2)r}}_{=\\epsilon_{(M-2)}}\\\\\n\\Rightarrow \\quad \\quad\\quad\\quad\\quad\\frac{\\delta\\lambda_{(M-1)}^r}{\\delta s}\\lambda_{(M-2)r} &= \\kappa_{(M)}\\lambda^r_{(M)}\\lambda_{(M-2)r} - \\epsilon_{(M-1)}\\kappa_{(M-1)}\\underbrace{\\epsilon_{(M-2)}\\epsilon_{(M-2)}}_{=1}\\\\\n\\Rightarrow \\quad \\quad\\quad\\quad\\quad\\frac{\\delta\\lambda_{(M-1)}^r}{\\delta s}\\lambda_{(M-2)r} &= \\kappa_{(M)}\\lambda^r_{(M)}\\lambda_{(M-2)r} - \\epsilon_{(M-1)}\\kappa_{(M-1)}\\\\\n\\text{We have}  \\quad \\quad\\quad\\quad\\quad\\lambda_{(M-1)}^r\\lambda_{(M-2)r} &=0\\\\\n\\Rightarrow \\quad \\quad\\quad\\quad\\quad\\ \\lambda_{(M-2)r}\\frac{\\delta\\lambda_{(M-1)}^r}{\\delta s} &= -\\lambda_{(M-1)}^r\\frac{\\delta\\lambda_{(M-2)r}}{\\delta s}\\\\\n\\text{We have also }  \\quad\\frac{\\delta\\lambda_{(M-2)r}}{\\delta s} &= \\kappa_{(M-1)}\\lambda_{(M-1)r} - \\epsilon_{(M-3)}\\epsilon_{(M-2)}\\kappa_{(M-2)}\\lambda_{(M-3)r}\\\\\n\\text{(19)}\\times \\lambda^r_{(M-1)} \\text{ and (18): }  \\lambda_{(M-2)r}\\frac{\\delta\\lambda_{(M-1)}^r}{\\delta s} &= -\\kappa_{(M-1)}\\underbrace{\\lambda^r_{(M-1)}\\lambda_{(M-1)r}}_{=\\epsilon_{(M-1)}} - \\epsilon_{(M-3)}\\epsilon_{(M-2)}\\kappa_{(M-2)}\\underbrace{\\lambda^r_{(M-3)}\\lambda_{(M-1)r}}_{=0}\\\\\n\\Rightarrow \\quad \\quad\\quad\\quad\\quad\\ \\lambda_{(M-2)r}\\frac{\\delta\\lambda_{(M-1)}^r}{\\delta s} &= -\\kappa_{(M-1)}\\epsilon_{(M-1)}\\\\\n\\text{(16) and (21):}\\quad \\quad\\quad\\quad\\quad -\\kappa_{(M-1)}\\epsilon_{(M-1)} &= \\kappa_{(M)}\\lambda^r_{(M)}\\lambda_{(M-2)r} - \\epsilon_{(M-1)}\\kappa_{(M-1)}\\\\\n\\Rightarrow \\quad \\quad\\quad\\quad\\quad \\kappa_{(M)}\\lambda^r_{(M)}\\lambda_{(M-2)r}&=0\\\\\n\\Rightarrow \\quad \\quad\\quad\\quad\\quad \\lambda_{(M-2)r}\\perp\\lambda_{(M)r}\n\\end{align}\nWith, i), ii), iii) all possible cases are covered which makes the proof complete.\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p75-Clarification 2.714}\n\\begin{tcolorbox}\n$\\textbf{2.714} \\quad \\quad (\\kappa_{(1)})^2 = \\epsilon_{(1)} a_{mn} \\frac{\\delta \\lambda^{m}}{\\delta s} \\frac{\\delta \\lambda^{n}}{\\delta s}$,   $\\quad \\quad \\epsilon_{(1)} = \\pm 1$\n\\end{tcolorbox}\n\\begin{align}\n\\ \\frac{\\delta \\lambda^{n}}{\\delta s} &= \\kappa_{(1)}\\lambda_{(1)}^{n}\\\\\n\\text{(1)}\\times \\text{(1)}\\quad\\Rightarrow \\quad\\quad \\frac{\\delta \\lambda^{m}}{\\delta s}\\frac{\\delta \\lambda^{n}}{\\delta s} &= (\\kappa_{(1)})^2 \\lambda_{(1)}^{m}\\lambda_{(1)}^{n}\\\\\n\\text{(2)}\\times a_{mn} \\Rightarrow\\quad\\quad a_{mn}\\frac{\\delta \\lambda^{m}}{\\delta s}\\frac{\\delta \\lambda^{n}}{\\delta s} &= a_{mn}(\\kappa_{(1)})^2 \\lambda_{(1)}^{m}\\lambda_{(1)}^{n}\\\\\n\\ &= (\\kappa_{(1)})^2 \\underbrace{\\lambda_{(1)m} \\lambda_{(1)}^{n}}_{=\\epsilon_{(1)}}\\\\\n\\ &= (\\kappa_{(1)})^2 \n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p75-exercise}\n\\begin{tcolorbox}\nFor positive definite metric forms, write out explicitly the Frenet formulae for the case N=2, 3 and 4.\n\\end{tcolorbox}\nThe general Frenet formulae are \n\\begin{align}\n\\left \\{ \\begin{array}{c}\n\\frac{\\delta\\lambda_{(M-1)}^r}{\\delta s} = \\kappa_{(M)}\\lambda^r_{(M)} - \\epsilon_{(M-2)}\\epsilon_{(M-1)}\\kappa_{(M-1)}\\lambda^r_{(M-2)}\\\\\n\\epsilon_{(M-1)}\\lambda^n_{(M-1)}\\lambda_{(M-1)n} = 1\\quad\\quad \\text{(M=1,2,...,N)}\n\\end{array} \\right.\n\\end{align}\nAs $\\Phi$ is positive definite, we have $\\epsilon_{(k)} = 1\\quad \\forall k$\n\\begin{center}\n\\begin{tabular}{ |c|c|c|c| } \n\\hline\nN=2 & N=3 & N=4 \\\\\n\\hline\n& &\\\\\n$\\frac{\\delta\\lambda^r}{\\delta s} = \\kappa_{(1)}\\lambda^r_{(1)} $ & $\\frac{\\delta\\lambda^r}{\\delta s} = \\kappa_{(1)}\\lambda^r_{(1)} $& $\\frac{\\delta\\lambda^r}{\\delta s} = \\kappa_{(1)}\\lambda^r_{(1)} $ \\\\ \n$\\frac{\\delta\\lambda_{(1)}^r}{\\delta s} = \\kappa_{(2)}\\lambda^r_{(2)} - \\kappa_{(1)}\\lambda^r$& $\\frac{\\delta\\lambda_{(1)}^r}{\\delta s} = \\kappa_{(2)}\\lambda^r_{(2)} - \\kappa_{(1)}\\lambda^r$ & $\\frac{\\delta\\lambda_{(1)}^r}{\\delta s} = \\kappa_{(2)}\\lambda^r_{(2)} - \\kappa_{(1)}\\lambda^r$ \\\\ \n& $\\frac{\\delta\\lambda_{(2)}^r}{\\delta s} = \\kappa_{(3)}\\lambda^r_{(3)} - \\kappa_{(2)}\\lambda^r_{(1)}$ & $\\frac{\\delta\\lambda_{(2)}^r}{\\delta s} = \\kappa_{(3)}\\lambda^r_{(3)} - \\kappa_{(2)}\\lambda^r_{(1)}$ \\\\\n& & $\\frac{\\delta\\lambda_{(3)}^r}{\\delta s} = \\kappa_{(4)}\\lambda^r_{(4)} - \\kappa_{(3)}\\lambda^r_{(2)}$ \\\\\n$\\lambda^n\\lambda_n= 1$&$\\lambda^n\\lambda_n= 1$&$\\lambda^n\\lambda_n= 1$\\\\\n$\\lambda_{(1)}^n\\lambda_{(1)n}= 1$&$\\lambda_{(1)}^n\\lambda_{(1)n}= 1$&$\\lambda_{(1)}^n\\lambda_{(1)n}= 1$\\\\\n&$\\lambda_{(2)}^n\\lambda_{(2)n}= 1$&$\\lambda_{(2)}^n\\lambda_{(2)n}= 1$\\\\\n&&$\\lambda_{(3)}^n\\lambda_{(3)n}= 1$\\\\\n\\hline\n\\end{tabular}\n\\end{center}\nTaking into account that $\\kappa_{(N)} = 0$ for a space $V_N$, we get,\n\\begin{center}\n\\begin{tabular}{ |c|c|c|c| } \n\\hline\nN=2 & N=3 & N=4 \\\\\n\\hline\n& &\\\\\n$\\frac{\\delta\\lambda^r}{\\delta s} = \\kappa_{(1)}\\lambda^r_{(1)} $ & $\\frac{\\delta\\lambda^r}{\\delta s} = \\kappa_{(1)}\\lambda^r_{(1)} $& $\\frac{\\delta\\lambda^r}{\\delta s} = \\kappa_{(1)}\\lambda^r_{(1)} $ \\\\ \n& &\\\\\n$\\frac{\\delta\\lambda_{(1)}^r}{\\delta s} =  - \\kappa_{(1)}\\lambda^r$& $\\frac{\\delta\\lambda_{(1)}^r}{\\delta s} = \\kappa_{(2)}\\lambda^r_{(2)} - \\kappa_{(1)}\\lambda^r$ & $\\frac{\\delta\\lambda_{(1)}^r}{\\delta s} = \\kappa_{(2)}\\lambda^r_{(2)} - \\kappa_{(1)}\\lambda^r$ \\\\ \n& &\\\\\n& $\\frac{\\delta\\lambda_{(2)}^r}{\\delta s} =  - \\kappa_{(2)}\\lambda^r_{(1)}$ & $\\frac{\\delta\\lambda_{(2)}^r}{\\delta s} = \\kappa_{(3)}\\lambda^r_{(3)} - \\kappa_{(2)}\\lambda^r_{(1)}$ \\\\\n& &\\\\\n& & $\\frac{\\delta\\lambda_{(3)}^r}{\\delta s} =  - \\kappa_{(3)}\\lambda^r_{(2)}$ \\\\\n& &\\\\\n$\\lambda^n\\lambda_n= 1$&$\\lambda^n\\lambda_n= 1$&$\\lambda^n\\lambda_n= 1$\\\\\n& &\\\\\n$\\lambda_{(1)}^n\\lambda_{(1)n}= 1$&$\\lambda_{(1)}^n\\lambda_{(1)n}= 1$&$\\lambda_{(1)}^n\\lambda_{(1)n}= 1$\\\\\n& &\\\\\n&$\\lambda_{(2)}^n\\lambda_{(2)n}= 1$&$\\lambda_{(2)}^n\\lambda_{(2)n}= 1$\\\\\n& &\\\\\n&&$\\lambda_{(3)}^n\\lambda_{(3)n}= 1$\\\\\n& &\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p76-exercise}\n\\begin{tcolorbox}\nIn an Euclidean space $V_N$, the fundamental form is given as $\\Phi = dx^n dx^n$. Show that a curve which has $\\kappa_{(2)} = 0$ and $\\kappa_{(1)} = \\text{constant}$ satisfies equations of the form\n$$x^r = A^r\\cos\\kappa_{(1)}s + B^r\\sin\\kappa_{(1)}s + C^r$$ where $A^r, B^r, C^r$ are constants satisfying $$ A^rA^R = B^rB^r = \\frac{1}{\\kappa_{(1)}^2},\\quad A^rB^r = 0$$\nso that $A^r$ and $B^r$ are vectors of equal magnitude and perpendicular to one another. (This curve is a circle in the N-space)\n\\end{tcolorbox}\n\\begin{align}\n\\text{What we know}\\quad\\quad\\quad\\quad \\Phi &= dx^n dx^n\\\\\n\\Rightarrow \\quad\\quad\\quad\\quad \\left(a_{mn}\\right) &= \\left(\\delta^m_n\\right)\\\\\n\\text{and given } \\spatie \\kappa_{(1)} = \\text{constant}& \\quad \\kappa_{(2)} = 0\\quad \\epsilon_{(1)}=\\epsilon_{(2)}, \\dots = 1\\\\\n\\text{we have (2.705) }\\quad\\quad\\quad\\quad \\frac{\\delta\\lambda^r}{\\delta s}&=  \\kappa_{(1)} \\frac{\\delta\\lambda_{(1)}^r}{\\delta s} \\quad \\quad \\text{with }\\quad \\lambda^r = \\dv{x^r}{s}\\\\\n\\text{but}\\quad\\left(a_{mn}\\right) = \\left(\\delta^m_n\\right)\\quad\\Rightarrow\\spatie \\frac{\\delta\\lambda^r}{\\delta s} &= \\dv{\\lambda^r}{s}\\\\\n\\text{(4) and (5)}\\quad\\Rightarrow\\spatie \\dv{\\lambda^r}{s} &= \\kappa_{(1)} \\frac{\\delta\\lambda_{(1)}^r}{\\delta s}\\\\\n\\text{also}\\spatie \\frac{\\delta\\lambda_{(1)}^r}{\\delta s} &= \\underbrace{\\kappa_{(1)}}_{=0} \\frac{\\delta\\lambda_{(1)}^r}{\\delta s}-  \\kappa_{(1)} \\frac{\\delta\\lambda_{(1)}^r}{\\delta s}\n\\end{align}\nHence we get the following set of equations\n\\begin{align}\n\\left \\{ \\begin{array}{c}\n\\dv{x^r}{s} = \\lambda^r \\\\\\\\\n\\dv{\\lambda^r}{s} = \\kappa_{(1)} \\lambda_{(1)}^r\\\\\\\\\n\\dv{\\lambda_{(1)}^r}{ s} = -  \\kappa_{(1)} \\lambda_{(1)}^r\\\\\\\\\n\\kappa_{(1)} = \\kappa\\quad \\text{(=constant)}\\\\\\\\\n\\kappa_{(2)} = 0\\\\\\\\\n\\lambda^n\\lambda_n = 1\\\\\\\\\n\\lambda_{(1)}^n\\lambda_{(1)n} = 1\\\\\n\\end{array} \\right.\\\\\n\\text{(8)}\\quad \\Rightarrow \\spatie \\dv[2]{\\lambda_{(1)}^r}{s} + \\kappa ^2 \\lambda_{(1)}^r = 0\n\\end{align}\nSolving the ODE (9). Put $ e^{rs} = \\lambda_{(1)}^k$\n\\begin{align}\n\\text{(9):}\\spatie&  r^2 + \\kappa^2 = 0\\\\\n\\Rightarrow \\spatie & r = \\pm \\imath \\kappa\\\\\n\\text{Hence, a general solution of (9) is of the form:} \\spatie & \\lambda_{(1)}^r = p^r e^{ \\imath \\kappa s}  + q^r e^{ -\\imath \\kappa s}\\\\\n\\text{put}\\quad  p^r+q^r = A^{,r}\\quad &\\text{and}\\quad p^r-q^r = B^{,r}\\\\\n\\Leftrightarrow \\spatie p^r = \\frac{A^{,r}+B^{,r}}{2} &\\text{and}\\quad p^r=\\frac{A^{,r}-B^{,r}}{2}\\\\\n\\text{(12) can then be written as }\\quad  \\lambda_{(1)}^r = A^{,r}\\frac{ e^{ \\imath \\kappa s}+  e^{ -\\imath \\kappa s}}{2} & + B^{,r}\\frac{ e^{ \\imath \\kappa s}- e^{ -\\imath \\kappa s}}{2}\\\\\n\\text{or}\\quad  \\lambda_{(1)}^r = A^{,r}\\cos \\kappa s & + B^{,r}\\sin \\kappa s\\\\\n\\text{We have (8)}\\spatie \\spatie  \\lambda^r =  & -  \\kappa_{(1)} \\dv{\\lambda_{(1)}^r}{ s} \\\\\n\\dv{(16)}{s}\\quad\\text{and (17)}\\Rightarrow\\spatie \\lambda^r =  A^{,r}\\sin \\kappa s & - B^{,r}\\cos \\kappa s\\\\\n\\text{as}\\quad \\lambda^r = \\dv{x^r}{s}\\quad\\text{ with (18)}\\quad \\Rightarrow \\spatie x^r = - \\frac{A^{,r}}{\\kappa}\\cos \\kappa s &  - \\frac{B^{,r}}{\\kappa}\\sin \\kappa s + C^r\\\\\n\\end{align}\nReplace $- \\frac{A^{,r}}{\\kappa}$ with $A^{r}$ and $- \\frac{B^{,r}}{\\kappa}$ with $B^{r}$, we get then the following set of equations,\n\n\\begin{align}\n\\left \\{ \\begin{array}{c}\nx^r = A^{r}\\cos \\kappa s   + B^{,r}\\sin \\kappa s + C^r\\\\\n\\lambda^r =  -\\kappa A^{r}\\sin \\kappa s  +\\kappa B^{r}\\cos \\kappa s\\\\\n\\lambda_{(1)}^r = - \\kappa A^{r}\\cos \\kappa s  - \\kappa B^{r}\\sin \\kappa s\\\\\n\\end{array} \\right.\\\\\n\\text{with the following constraints}\\spatie \\lambda^n\\lambda_n = 1\\spatie \n\\lambda_{(1)}^n\\lambda_{(1)n} &= 1\\\\\n\\lambda^n\\lambda_n = 1\\quad\\Rightarrow \\kappa^2 A^r A^r \\sin ^2 \\kappa s+ \\kappa^2 B^r B^r \\cos ^2 \\kappa s - 2 \\kappa^2 A^rB^r\\sin\\kappa s\\cos \\kappa s &= 1\\\\\n\\text{or} \\spatie A^r A^r \\sin ^2 \\kappa s+  B^r B^r \\cos ^2 \\kappa s - 2 A^rB^r\\sin\\kappa s\\cos \\kappa s &= \\frac{1}{\\kappa^2 }\\\\\n\\lambda_{(1)}^n\\lambda_{(1)n} = 1\\quad\\Rightarrow \\kappa^2 A^r A^r \\cos ^2 \\kappa s+ \\kappa^2 B^r B^r \\sin ^2 \\kappa s + 2 \\kappa^2 A^rB^r\\sin\\kappa s\\cos \\kappa s &= 1\\\\\n\\text{or} \\spatie A^r A^r \\cos ^2 \\kappa s+  B^r B^r \\sin ^2 \\kappa s + 2 A^rB^r\\sin\\kappa s\\cos \\kappa s &= \\frac{1}{\\kappa^2 }\\\\\n\\text{Choose }\\quad \\kappa s = \\frac{\\pi}{2}\\quad\\text{and} \\quad \\kappa s = 0\\\\\n\\Rightarrow \\spatie A^r A^r =  \\frac{1}{\\kappa^2 }\\quad\\text{and}\\quad B^r B^r =  \\frac{1}{\\kappa^2 }\\\\\n\\text{Morover considering (26)-(24) and (28)}\\quad \\Rightarrow \\spatie 2A^rB^r\\sin \\kappa s \\cos \\kappa s =0 \\quad \\forall \\kappa s\\\\\n\\Rightarrow \\spatie A^rB^r=0\n\\end{align}\nNote: when deriving expressions $(23)$ and $(26)$ we use the fact that $\\left(a_{mn}\\right) =  \\left(a^{mn}\\right) = \\left(\\delta^m_n\\right) $\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p78-exercise 1}\n\\begin{tcolorbox}\nFor cylindrical coordinates in Euclidean 3-space, write down the metric form by inspection of a diagram showing a general infinitesimal displacement, and calculate all the Christoffel symbols of both kinds.\n\\end{tcolorbox}\n\\begin{figure}[h]\n\n%\\includegraphics[scale=.4]{polar3d.jpg}\n\\input{D:/MathLatex/images/fig_p78_247_a.tex}\n\\label{fig:fig_p78_247_a}\n\\end{figure}\nFrom the figure we may (assuming an infinitesimal displacement), we may approximate $\\left| \\overrightarrow{SS^{,}} \\right|$ with the arclength $r d\\theta$ and assume $\\left|  \\overrightarrow{S°S^{,,}} \\right| \\perp \\left|  \\overrightarrow{GS^{,}} \\right|$) Hence, the infinitesimal displacement from S\n\\begin{align}\n\\ ds^2 &= \\left| \\overrightarrow{SS^{,}} \\right|^2 + \\left| \\overrightarrow{S^{,,}P^{,}} \\right|^2+\\left| \\overrightarrow{P^{,}J} \\right|^2\\\\\n\\ &= dr^2 + ((r+dr)d\\theta)^2 + dz^2\\\\\n\\ &= dr^2 + r^2d\\theta^2 + dz^2\\\\\n\\text{Hence} \\spatie &\\left(a_{mn}\\right) = \\begin{pmatrix}\n 1& 0 & 0 \\\\\n 0&  r^2&0  \\\\\n 0&0  &1  \\\\\n\\end{pmatrix}\\quad\\text{and}\\quad \\left(a_{mn}\\right) = \\begin{pmatrix}\n 1& 0 & 0 \\\\\n 0&  ^\\frac{1}{r^2}&0  \\\\\n 0&0  &1  \\\\\n\\end{pmatrix}\n\\end{align}\nNote that all $a_{mn} = 0 \\quad \\forall m\\ne n$. So,\n\\begin{align}\n\\left \\{ \\begin{array}{c}\n\\ [r \\ r,r]=[\\theta \\  \\theta, \\theta] = [z \\ z,z] = 0\\\\\n\\ [r \\ \\theta,r]=[r \\ r, \\theta] = [r \\ r,z] = 0\\\\\n\\ [r \\ z,\\theta]=[z \\  \\theta, r] = [z \\ \\theta,z] = 0\\\\\n\\end{array}\\right.\\\\\n\\text{But:}\\spatie [\\theta \\ \\theta,r]= -r \\quad\\text{and}\\quad [r \\  \\theta, \\theta] = r\\\\\n\\text{Hence}\\spatie \\left \\{ \\begin{array}{c}\n\\Gamma^m_{nk} = 0 \\quad\\forall\\quad (nk) \\ne (r, \\theta), (\\theta, \\theta)\\\\\\\\\n\\Gamma^{\\theta}_{r\\theta} = \\frac{1}{r} \\quad\\text{and}\\quad \\Gamma^r_{\\theta\\theta} = -r\n\\end{array}\\right.\\\n\\end{align}\n\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p78-exercise 2}\n\\begin{tcolorbox}\nIf $a_{rs}$ and $b_{rs}$ are covariant tensors, show that the roots of the determinant equation $$\\left|Xa_{rs} - b_{rs}\\right |= 0$$ are invariants.\n\\end{tcolorbox}\n\\begin{align}\n\\text{Be}\\spatie c_{rs} &= Xa_{rs} - b_{rs}\\\\\n\\text{Given }\\spatie a_{rs} &= a^{,}_{mk}\\pdv{x^{,m}}{x^r} \\pdv{x^{,k}}{x^s}\\\\\n\\text{and }\\spatie b_{rs} &= b^{,}_{mk}\\pdv{x^{,m}}{x^r} \\pdv{x^{,k}}{x^s}\\\\\n\\text{(1) }\\quad\\Rightarrow\\spatie c_{rs} &= \\underbrace{(Xa^{,}_{mk}-b^{,}_{mk})}_{=c^{,}_{km}} \\pdv{x^{,m}}{x^r} \\pdv{x^{,k}}{x^s}\\\\\n\\ &= c^{,}_{km} \\pdv{x^{,m}}{x^r} \\pdv{x^{,k}}{x^s}\\\\\n\\text{Be}\\spatie J &= \\left |\\pdv{x^{,m}}{x^r}\\right |= \\left |\\pdv{x^{,k}}{x^s}\\right |\\\\\n\\text{In (5) put  }\\spatie d_{kr} &= c^{,}_{km} \\pdv{x^{,m}}{x^r} \\\\\n\\Rightarrow\\spatie c_{rs} &= d^{,}_{kr} \\pdv{x^{,k}}{x^s}\\\\\n\\text{or in matrix form  } \\spatie C &= D^T J\\quad \\text{with}\\quad D = C^{,}J\\\\\n\\Rightarrow\\spatie \\left |C \\right| &= \\left | (C^{,}J)^T J\\right |\\\\\n\\Leftrightarrow\\spatie \\left |C \\right| &= \\left | C^{,}\\right | \\left |J\\right |\\left |J\\right |\n\\end{align}\nAs $ \\left |J\\right | \\ne 0$ ( $J$ is the Jacobian of the transformation, and thus can't be zero), then $$\\left |C \\right| = 0 \\Rightarrow \\left |C^{,} \\right| = 0$$.\\\\\nSo, the root of $\\left |C \\right| = 0 $ is also a root of $\\left |C^{,} \\right| = 0$ and is as a consequence, invariant.\n\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p78-exercise 3}\n\\begin{tcolorbox}\nIs the form $dx^2+3dxdy+4dy^2+dz^2$ positive definite?\n\\end{tcolorbox}\n\\begin{align}\n\\Phi &= dx^2+3dxdy+4dy^2+dz^2\\\\\n\\text{Put (1) in the form}\\spatie  \\Phi &= X^2+3XY+4Y^2+Z^2\\\\\n\\text{Z has only a positive contribution: so put }\\quad Z=0\\quad\\Rightarrow \\quad \\Phi &= X^2+3XY+4Y^2\\\\\n\\text{(3) can only be zero or negative if }\\quad XY < 0\\quad\\text{:put}\\quad Y & =-aX\\quad (a>0)\\\\\n\\Rightarrow \\Phi &= X^2-3aX^2 +4a^2X^2\\\\\n\\text{The roots of (5) are }\\quad a_{1,2} &= \\frac{3\\pm \\sqrt{9-16}}{8}\n\\end{align}\nSo, by (6) we can't get a $a \\in \\mathbb{R}_*$, so that (1) can be $0$ or negative. Hence,\n$$\\text{The form}\\quad \\Phi \\quad \\text{is positive definite}$$\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p78-exercise 4}\n\\begin{tcolorbox}\nIf $X^r, Y^r$ are unit vectors inclined at an angle $\\theta$, prove that $$\\sin^2 \\theta = (a_{rm}a_{sn}- a_{rs}a_{mn})X^r Y^s X^m Y^n$$\n\\end{tcolorbox}\n$X^r Y^s$ are unit vectors. So,\n\\begin{align}\n\\ a_{rm}X^rX^m = 1 \\quad &\\text{and}\\quad a_{sn}Y^sY^n = 1\\\\\n\\text{We have}\\spatie \\sin^2\\theta &= 1 - \\cos^2\\theta\\\\\n\\text{and (2.312)}\\spatie \\cos\\theta &= a_{mn}X^mY^n\\\\\n\\Rightarrow\\spatie \\sin^2 \\theta &= a_{rm}X^rX^m a_{sn}Y^sY^n - a_{mn}X^mY^na_{rs}X^rY^s\\\\\n\\ &= (a_{rm} a_{sn} - a_{mn}a_{rs})X^rY^sX^mY^n\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p78-exercise 5}\n\\begin{tcolorbox}\nShow that, if $\\theta$ is the angle between the normals to the surfaces $x^1 = C^{st}, x^2 = C^{st}$, then $$ \\cos \\theta = \\frac{a^{12}}{\\sqrt{a^{11}a^{22}}}$$\n\\end{tcolorbox}\n\\begin{align}\n\\text{be}\\spatie \\phi^{,}_1(x^1,x^2,\\dots,x^N) = C^{st} \\quad \\phi^{,}_2(x^1,x^2,\\dots,x^N) = C^{st}\n\\end{align}\nthe two equations representing $S_1, S_2$ (see page 63). We can rewrite (1) as:\n\\begin{align}\n\\ x^1 &= \\phi^{,}_1(x^1,x^2,\\dots,x^N) = C^{st} \\\\\n\\ x^2 &= \\phi^{,}_2(x^1,x^2,\\dots,x^N) = C^{st}\\\\\n\\text{From (2.622) we know that}\\quad X^m = a^{mn}\\partial_n \\phi_{1} & ,\\ Y^m = a^{mn}\\partial_n \\phi_{2} \\ \\text{are}\\perp\\text{vectors to the surfaces}\\  \\phi_{1},\\phi_{2}\\\\\n\\text{We know also} \\spatie \\left|X^m\\right |^2 &= a^{mk}X^mX^k\\\\\n\\ & = a_{mk}a^{mn}\\partial_n \\phi_{1}a^{kp}\\partial_p \\phi_{1}\\\\\n\\ & = \\delta^k_k a^{kp}\\partial_n \\phi_{1}\\partial_p \\phi_{1}\\\\\n\\ & = a^{np}\\partial_n \\phi_{1}\\partial_p \\phi_{1}\\\\\n\\text{as} \\ \\phi_1 = x^1 = C^{st} \\ \\Rightarrow \\ &= a^{np}\\delta^1_n \\delta^1_p\\\\\n\\ &= \\epsilon a^{11}\\\\\n\\text{Analog, we have}\\spatie \\left|Y^m\\right |^2 &= \\epsilon a^{22}\\\\\n\\text{By definition:}\\spatie \\cos\\theta &= \\frac{a_{mn}X^mY^n}{ \\left|X^r\\right | \\left|Y^s\\right |}\\\\\n\\text{and }\\spatie a_{mn}X^mY^n &= a_{mn} a^{mk}\\partial_k \\phi_{1} \\  a^{np}\\partial_p \\phi_{2}\\\\\n\\ &=\\delta^k_n a^{np}\\partial_k \\phi_{1} \\ \\partial_p \\phi_{2}\\\\\n\\ &=a^{kp}\\partial_k \\phi_{1} \\ \\partial_p \\phi_{2}\\\\\n\\text{as} \\ \\phi_1 = x^1 = C^{st},  \\ \\phi_2 = x^2 = C^{st} \\ \\Rightarrow \\ &= a^{kp}\\delta^1_k\\delta^2_p\\\\\n\\ &= a^{12}\\\\\n\\text{So (12) becomes with (10), (11) and (17)} \\spatie \\cos\\theta &= \\frac{a_{12}}{ \\sqrt{\\epsilon a^{11}\\epsilon a^{22}}}\\\\\n&= \\frac{a_{12}}{ \\sqrt{ a^{11} a^{22}}}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p78-exercise 6}\n\\begin{tcolorbox}\nLet $x^1, \\ x^2,\\ x^3$ be rectangular Cartesian coordinates in Euclidean 3-space, and let $x^1, \\ x^2$ be taken as coordinates on a surface $x^3 = f(x^1, \\ x^2)$. Show that the Christoffel symbols of the second kind for the surface are $$ \\Gamma^r_{mn} = \\frac{f_r f_{mn}}{1+ f_n f_p}$$ the suffixes taking the values $1, \\ 2$ and the subscripts indicating partial derivatives.\n\\end{tcolorbox}\nWe have (rectangular Cartesian coordinates in Euclidean 3-space)\n\\begin{align}\n\\ ds^2 &= (dx^1)^2 + (dx^2)^2+(dx^3)^2\\\\\n\\text{with} \\spatie x^3 &= f(x^1, \\ x^2)\\\\\n\\text{and thus } \\spatie dx^3 &= \\partial_1 f \\ dx^1 + \\partial_2 f \\  dx^2\\\\\n\\Rightarrow \\spatie ds^2 &= (1+ (\\partial_1 f)^2) (dx^1)^2 + (1+ (\\partial_2 f)^2) (dx^2)^2+ 2\\partial_1 f \\ \\partial_2 f \\ dx^1 dx^2\\\\\n\\text{put}\\spatie & \\left \\{ \\begin{array}{c}\n\\ f_1 = \\partial_1 f\\\\\n\\ f_2 = \\partial_2 f\\\\\n\\ f_{11} = \\partial_{11} f\\\\\n\\ f_{22} = \\partial_{22} f\\\\\n\\ f_{12} = f_{21 } = \\partial_{12} f\\\\\n\\end{array}\\right.\\\\\n\\text{from (4)}\\spatie \\left(a_{mn}\\right) =& \\begin{pmatrix}\n 1+f_1 ^2& f_1f_2 \\\\\n f_1f_2& 1+f_2 ^2 \\\\\n\\end{pmatrix}\\\\\n\\Rightarrow\\spatie \\left|a_{mn}\\right| &= (1+f_1 ^2)(1+f_2 ^2) - (f_1f_2)^2\\\\\n\\ & = 1 + f_1 ^2+f_2 ^2\\\\\n\\text{also} \\spatie \\left(a^{mn}\\right) =& \\frac{1}{1 + f_1 ^2+f_2 ^2}\\begin{pmatrix}\n 1+f_2 ^2& -f_1f_2 \\\\\n -f_1f_2& 1+f_1 ^2 \\\\\n\\end{pmatrix}\n\\end{align}\n\\begin{align}\n\\textbf{Calculating the Christoffels symbols:}\\quad [mn,\\ k] &= \\half (\\partial_m a_{nk}+\\partial_n a_{mk}-\\partial_k a_{mn})\\\\\n\\Rightarrow\\spatie & \\left \\{ \\begin{array}{c}\n\\ [11,\\ 1] =  f_1 f_{11}\\\\\n\\ [11,\\ 2] =  f_2 f_{11}\\\\\n\\ [12,\\ 1] =  f_1 f_{12}\\\\\n\\ [12,\\ 2] =  f_2 f_{21}\\\\\n\\ [22,\\ 2] =  f_2 f_{22}\\\\\n\\end{array}\\right.\\\\\n\\text{From (11) we can see that the general form is:}\\quad [mn,s] &= f_{mn}f_s\\\\\n\\textbf{Calculating the Christoffels symbols:}\\quad \\Gamma^r_{mn} &= a_{rs}[mn,s]\\\\ \n\\text{(13) with (12):}\\quad \\Gamma^r_{mn} &= a_{rs}f_{mn}f_s = f_{mn}(a^{rs}f_s)\\\\\n\\text{put } \\Delta &= \\frac{1}{1 + f_1 ^2+f_2 ^2}=\\frac{1}{1 + f_p f_p} \\\\\n\\Rightarrow\\spatie  \\left \\{ \\begin{array}{ll}\n\\Gamma^1_{mn} & = (a_{11} f_1 + a_{12} f_2)f_{mn}\\\\\n\\ & =  \\Delta(f_1  + f_2^2f_1 - f_1f_2^2)f_{mn}\\\\\n\\ & =  \\Delta f_1 f_{mn}\\\\\\\\\n\\Gamma^2_{mn} & = (a_{21} f_1 + a_{22} f_2)f_{mn}\\\\\n\\ & =  \\Delta(- f_1^2f_2+f_2   + f_2f_1^2)f_{mn}\\\\\n\\ & =  \\Delta f_2 f_{mn}\\\\\n\\end{array}\\right. & \n\\end{align}\n$$\\Rightarrow\\quad \\Gamma^r_{mn} = \\frac{f_r f_{mn}}{1 + f_p f_p}$$\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p78-exercise 7}\n\\begin{tcolorbox}\nWrite down the differential equations of the geodesics on a sphere, using colatitude $\\theta$ and the azimuth $\\phi$ as coordinates. Integrate the differential equations and obtain a finite equation $$ A\\sin \\theta \\cos \\phi + B \\sin \\theta \\sin \\phi + C\\cos\\theta = 0$$\nwhere $A,B,C$ are arbitrary constants.\n\\end{tcolorbox}\n$$\\textbf{We will use two different approaches to determine the relation and finally use a geometrical reasoning }$$ $$\\textbf{allowing us to avoid solving the ODE's resulting from the above mentioned approaches.}$$\\\\\nWe will first find the solution, starting from the variational principle , defining a geodesic.\nIn spherical coordinates we have (see exercise page 27) $ds^2 = dr^2 +  r^2\\sin^2(\\theta)d\\phi^2+ r^2d\\theta^2$.\\\\\nAs $r=R= C^{st}$ this reduces to\n\\begin{align}\n\\ ds^2 = R^2\\sin^2(\\theta)d\\phi^2+ R^2d\\theta^2\n\\end{align}\nSo the length of a curve on the sphere from a point $P_1$ to another point $P_2$ , the curve being determined by $\\theta = \\theta(u)\\quad \\phi = \\phi(u)$ is:\\\\\n\\begin{align}\n\\ L &= R\\int_{P_1}^{P_2} = \\sqrt{\\sin^2(\\theta)d\\phi^2+ d\\theta^2}du\\\\\n\\text{Be}\\quad \\theta &= u \\quad \\phi = \\phi(\\theta)\\\\\n\\Rightarrow \\quad  L &= R\\int_{\\theta_1}^{\\theta_2} = \\sqrt{1+\\sin^2(\\theta)(\\dv{\\phi}{\\theta})^2}d\\theta\n\\end{align}\nApplying the variational principle on L and using the Euler-Langrange equations:\n\\begin{align}\n \\dv{\\pdv{\\mathcal{L}}{\\dot{\\phi}}}{\\theta} - \\pdv{\\mathcal{L}}{\\phi}&=0 \\quad \n \\text{with}\\quad \\mathcal{L} = \\sqrt{1+\\sin^2(\\theta)(\\dot{\\phi})^2}\\\\\n \\text{as}\\quad  \\pdv{\\mathcal{L}}{\\phi}&=0\\\\\n \\text{(5) becomes:} \\quad \\dv{\\pdv{\\mathcal{L}}{\\dot{\\phi}}}{\\theta} &=0\\\\\n \\Leftrightarrow \\quad \\pdv{\\mathcal{L}}{\\dot{\\phi}} &= C\\quad \\ \\text{(= constant)}\\\\\n\\text{with}\\quad \\pdv{\\mathcal{L}}{\\dot{\\phi}} &= \\pdv{\\sqrt{1+\\sin^2 \\theta   \\  \\dot{\\phi}^2 }}{\\dot{\\phi}}= \\frac{\\sin^2 \\theta \\  \\dot{\\phi}}{ \\sqrt{1+\\sin^2 \\theta \\ \\dot{\\phi}^2 }}\\\\\n\\text{(9) and (10):}\\quad C^2 &= \\frac{\\sin^2 \\theta \\  \\dot{\\phi}}{ \\sqrt{1+\\sin^2 \\theta \\ \\dot{\\phi}^2 }} \\\\\n\\text{or}\\quad \\dot{\\phi} &= \\frac{C}{\\sin \\theta \\sqrt{\\sin^2 \\theta - C^2}}\n\\end{align}\nSolving the ODE (12). Put $u = \\cot \\theta \\quad \\Rightarrow \\quad du = - \\csc^2 d\\theta = -\\frac{1}{\\sin^2\\theta} d\\theta$. So,  \n\\begin{align}\n\\phi &= -C\\int \\frac{\\sin \\theta}{ \\sqrt{\\sin^2 \\theta - C^2}}du\\\\\n&= -C\\int \\frac{du}{ \\sqrt{1- \\frac{C^2 }{\\sin^2 \\theta}}}\\\\\n&= -C\\int \\frac{du}{ \\sqrt{1- C^2 - C^2 \\cot^2 \\theta}}\\\\\n&= -C\\int \\frac{du}{ \\sqrt{1- C^2 - C^2 u^2}}\\\\\n\\text{be}\\quad a&= \\frac{\\sqrt{1-C^2}}{C}\\\\\n\\text{(15) becomes}\\quad \\phi &= -\\int \\frac{1}{ \\sqrt{a^2 -  u^2}}du\\\\\n\\text{put }\\quad u &= av\\\\\n\\text{(18) becomes}\\quad \\phi &= -\\int \\frac{1}{ \\sqrt{1 -  v^2}}dv\\\\\n\\ &= -\\arccos v + C^{st}\\\\\n\\ &= -\\arccos \\frac{u}{a}  + \\phi_0\\\\\n\\text{or:}\\quad \\frac{u}{a} &= \\cos (\\phi - \\phi_0)  \\ \\text{(by choosing an adequate}\\ \\phi_0\\text{)}\\\\\n\\text{so :}\\quad \\cot\\theta &= a \\cos (\\phi - \\phi_0)  \\\\\n\\text{expanding} \\  \\cos (\\phi - \\phi_0)\\  \\text{gives:} \\quad  \\frac{\\cos\\theta}{\\sin\\theta} &= \\ A\\cos\\phi + B\\sin\\phi\\\\\n\\text{or:} \\quad  A\\cos\\phi \\sin\\theta &+ B\\sin\\phi\\sin\\theta -\\cos\\theta=0\n\\end{align}\n$$\\diamond$$\n\\newpage\nFinding the geodesics from the tensorial formula's.\\\\\nNote: For ease of notation we put $R=1$ without losing any general solutions.\n\n\\begin{align}\n\\text{from (1) we get:}\\quad (a_{mn}) &= \\begin{pmatrix}\n 1&  0\\\\\n0 & \\sin^2\\theta \\\\\n\\end{pmatrix}\\\\\n\\text{and}\\quad (a^{mn}) &= \\begin{pmatrix}\n \\frac{1}{\\sin^2\\theta}&  0\\\\\n0 & 1 \\\\\n\\end{pmatrix}\\\\\n\\text{hence:}\\quad & \\left \\{ \\begin{array}{ll}\n\\Gamma^1_{11}  = 0&\\Gamma^2_{11}  = 0\\\\\n\\Gamma^1_{12}  = 0&\\Gamma^2_{12}  = \\cot\\theta\\\\\n\\Gamma^1_{22}  = -\\cos\\theta\\sin\\theta&\\Gamma^2_{22}  = 0\\\\\n\\end{array}\\right.\n\\end{align}\nFinding the geodesics from the tensorial formula's, implies solving $2^{nd}$ order ODE's. In order to find the simpliest form to solve , we write down three possible forms of the geodesic equations:\n\\begin{align}\n\\text{arc-length s as independent variable}\\quad& \\left \\{ \\begin{array}{ll}\n\\ (a)&\\dv[2]{\\phi}{s} + 2 \\cot\\theta\\dv{\\phi}{s} \\dv{\\theta}{s} = 0\\\\\\\\\n\\ (b)&\\dv[2]{\\theta}{s} - \\sin\\theta\\cos\\theta(\\dv{\\phi}{s})^2  = 0\\\\\\\\\n\\ (c)&\\ (\\dv{\\theta}{s})^2+\\sin^2\\theta(\\dv{\\phi}{s})^2 = 1\\\\\\\\\n\\end{array}\\right.\\\\\n\\theta \\text{ as independent variable}\\quad& \\left \\{ \\begin{array}{l}\n\\lambda =  - \\sin\\theta\\cos\\theta(\\dv{\\phi}{\\theta})^2\\\\\\\\\n\\dv[2]{\\phi}{\\theta}  = \\lambda \\dv{\\phi}{\\theta}- 2 \\cot\\theta\\dv{\\phi}{\\theta}  \\\\\\\\\n\\end{array}\\right.\\\\\n\\Rightarrow \\quad \\dv[2]{\\phi}{\\theta}  &= - \\sin\\theta\\cos\\theta(\\dv{\\phi}{\\theta})^3- 2 \\cot\\theta\\dv{\\phi}{\\theta}  \\\\\n\\phi \\text{ as independent variable}\\quad& \\left \\{ \\begin{array}{l}\n\\lambda =  2 \\cot\\theta\\dv{\\theta}{\\phi}\\\\\\\\\n\\dv[2]{\\theta}{\\phi}  = \\lambda \\dv{\\theta}{\\phi} + \\sin\\theta\\cos\\theta(\\dv{\\theta}{\\phi})^2 \\\\\\\\\n\\end{array}\\right.\\\\\n\\Rightarrow \\quad \\dv[2]{\\theta}{\\phi}  &= 2 \\cot\\theta(\\dv{\\theta}{\\phi})^2 + \\sin\\theta\\cos\\theta(\\dv{\\theta}{\\phi})^2 \\\\\n\\\n\\end{align}\nInspection shows hat the expression (32) and (34) are quite complicated while using (30b) and (30c) we can get an expression of the form\n\\begin{align}\n\\ddot{\\theta} - \\sin\\theta\\cos\\theta\\left(\\frac{1 - \\dot{\\theta}^2}{\\sin^2\\theta}\\right)&= 0\\\\\n\\text{or:}\\quad \\ddot{\\theta} - \\cot\\theta\\left( 1-\\dot{\\theta}^2\\right) &= 0\\\\\n\\text{Put }\\ u(\\theta)= \\dot{\\theta}\\quad\\Rightarrow\\quad \\ddot{\\theta} &= \\dot{u}u\\\\\n\\text{(37) can be written as:}\\quad \\dot{u}u - \\cot\\theta\\left( 1-u^2\\right) &= 0\\\\\n\\text{or}\\quad \\frac{\\dot{u}u}{\\left( 1-u^2\\right)} &= \\cot\\theta\\\\\n\\text{or}\\quad \\frac{u}{\\left( 1-u^2\\right)}du &= \\frac{\\cos\\theta}{\\sin\\theta} d\\theta\\\\\n\\text{or}\\quad -\\half\\frac{1}{\\left( 1-u^2\\right)}d(1-u^2) &= \\frac{1}{\\sin \\theta} d(\\sin\\theta)\\\\\n\\text{hence}\\quad -d(\\log (\\sqrt{1-u^2})) &= d(\\log(\\sin\\theta))\\\\\n\\Rightarrow \\quad d(\\log \\sqrt{1-u^2} +\\log(\\sin\\theta))&=0\\\\\n\\Leftrightarrow \\quad d(\\log( \\sqrt{1-u^2}\\sin\\theta))&=0\\\\\n\\Rightarrow \\quad (1-\\dot{\\theta}^2)\\sin^2\\theta &= C^2\\\\\n\\Rightarrow \\quad \\dot{\\theta}^2&= 1-\\frac{C^2}{\\sin^2\\theta}\\\\\n\\text{we have (30c)}\\quad \\dot{\\theta}^2+\\dot{\\phi}^2\\sin^2\\theta &= 1\\\\\n\\text{and so (47):}\\quad 1-\\frac{C^2}{\\sin^2\\theta}+\\dot{\\phi}^2\\sin^2\\theta &= 1\\\\\n\\Rightarrow \\quad \\dot{\\phi}^2 &= \\frac{C^2}{\\sin^4\\theta}\\\\\n\\Rightarrow \\quad \\dot{\\phi} &= \\frac{C}{\\sin^2\\theta}\\\\\n\\text{we have} \\quad \\dot{\\phi}=\\dv{\\phi}{\\theta}\\dot{\\theta}\\\\\n\\text{so} \\quad d\\phi  &= \\frac{C}{\\sin^2\\theta\\sqrt{1-\\frac{C^2}{\\sin^2\\theta}}}d\\theta\\\\\n\\text{so} \\quad d\\phi  &= \\frac{C}{\\sin\\theta\\sqrt{\\sin^2\\theta-C^2}}d\\theta\n\\end{align}\nNote that expression (54) is exactly the expression (12) we found by applying directly the variational principle to find the general expression. So applying steps (13) to (26) gives us the same expression.\n$$\\diamond$$\n\\newpage\nInstead of solving the ODE's (46) and (53) we can use geometrical considerations to get the asked expression.\\\\ Due to the invariance of a sphere regarding rotation of the axes, we can choose a reference axis system $XYZ$ (from which $\\theta, \\phi$ are measured) so that at $s=0$ of the geodesic,  corresponds the point $r=1, \\ \\theta = 0$. As  from (45),  $\\left.(1-\\dot{\\theta}^2)\\sin^2\\theta \\right |_{s=0} = C^2$ follows that $C=0 \\ (\\text{because} \\ \\left.\\theta \\right |_{s=0} = 0)$. So we get $(1-\\dot{\\theta}^2)\\sin^2\\theta  = 0 \\ \\forall \\ \\theta : \\ \\Rightarrow \\ \\dot{\\theta} = 1$ and  $\\theta =s$. Then from (37) $\\dot{\\theta}^2+\\dot{\\phi}^2\\sin^2\\theta = 1$  follows that $\\dot{\\phi}= 0$ and thus $\\phi = C^{st}$. Again, considering symmetry we can choose the axis system so that $\\phi = 0$. The set of equations $ \\theta =s, \\ \\phi = 0$ represents a circle on the sphere generated by the intersection of the sphere with the $XZ$ plane. Again, considering symmetry, we can conclude that any circle on the sphere generated by the intersection a plane going through the origin of the axis system, is also a geodesic curve. So, be $\\widehat{n} = (A,B,C)$ the normal vector defining a plane going through the origin and $\\widehat{p} = (\\cos\\phi \\sin\\theta,\\sin\\phi \\sin\\theta,\\cos\\theta)$ a point on the sphere, then the intersection of the plane and the sphere is given by $$\\left<\\widehat{n} | \\widehat{p}\\right> = A\\cos\\phi \\sin\\theta+ B\\sin\\phi \\sin\\theta+ C\\cos\\theta = 0$$\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p79-exercise 8}\n\\begin{tcolorbox}\nFind in integrated form the geodesic null lines in a $V_3$ for which the metric form $$(dx^1)^2 -R^2[(dx^2)^2+(dx^3)^2]$$\nR being a function of $x^1$ only.\n\\end{tcolorbox}\nWe have,\n\\begin{align}\n\\Phi &= (dx^1)^2 -R^2[(dx^2)^2+(dx^3)^2]\\\\\n\\text{Hence,}\\quad (a_{mn}) &= \\begin{pmatrix}\n 1&0  & 0 \\\\\n 0& -R^2 & 0 \\\\\n 0& 0 &  -R^2 \\\\\n\\end{pmatrix}\\\\\n\\text{and,}\\quad (a^{mn}) &= \\begin{pmatrix}\n 1&0  & 0 \\\\\n 0& -\\frac{1}{R^2} & 0 \\\\\n 0& 0 &  -\\frac{1}{R^2} \\\\\n\\end{pmatrix}\\\\\n\\text{Hence,}\\quad & \\left \\{ \\begin{array}{ll}\n\\ [22,1] = R \\ \\partial_1 R &[12,2] = -R \\ \\partial_1 R\\\\\n\\ [33,1] = R \\ \\partial_1 R & [13,3] = -R \\ \\partial_1 R\n\\end{array} \\right.\\\\\n\\text{and,}\\quad & \\left \\{ \\begin{array}{ll}\n\\Gamma^1_{22}  = R \\ \\partial_1 R &\\Gamma^2_{12}  = \\frac{1}{R}\\partial_1 R \\\\\n\\Gamma^1_{33}  = R \\ \\partial_1 R &\\Gamma^3_{13}  = \\frac{1}{R}\\partial_1 R \\\\\n\\end{array} \\right.\\\\\n\\text{ with all other} \\ [mn,s] \\ \\text{and}\\ \\Gamma^s_{mn} \\ \\text{being zero.}\n\\end{align}\nThe equations of null geodesics give:\n\\begin{align}\n\\left \\{ \\begin{array}{l}\n\\dv[2] {x^r}{u} + \\Gamma^r_{mn}\\dv{x^m}{u}\\dv{x^n}{u} = 0\\\\\n\\ a_{mn}\\dv{x^m}{u}\\dv{x^n}{u} = 0 \\end{array}\\right.\n\\end{align}\n$\\boldsymbol{x^r = x^1}$ gives:\n\\begin{align}\\dv[2] {x^1}{u} +R\\partial_1R(\\dv{x^2}{u})^2+R \\partial_1  R(\\dv{x^3}{u})^2 &= 0\n\\end{align}\nPut $ u = x^1$\n\\begin{align}\n\\text{from (8):}\\quad R \\ \\partial_1 R \\left[ (\\dv{x^2}{u})^2+(\\dv{x^3}{u})^2 \\right] &= 0\n\\end{align}\nIf, $R= R(x^1) \\ne C^{st}$, the form (9) can only be zero if $(\\dv{x^2}{u})^2+(\\dv{x^3}{u})^2 = 0$ and thus $\\dv{x^2}{u}=\\dv{x^3}{u} = 0$ and hence $x^2, \\ x^3 $ are constant.\\\\\n$\\textbf{Conclusion:}$ the null geodesics are the bundle of rays parallel with the $x^1$ axis with vector equation $\\widehat{p} = (s,A,B), s \\in (-\\infty, +\\infty)$ and $A,B$ arbitrary constants.\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p79-exercise 9}\n\\begin{tcolorbox}\nShow that, for normal coordinate system, the Christoffel symbols $$ \\ [ \\rho N, \\  \\sigma], \\ [\\rho \\sigma, \\ N  ], \\ [\\rho N, \\ N], \\ [N N, \\  N]$$\n$$\\Gamma^{\\rho}_{N \\sigma},\\ \\Gamma^{N}_{\\rho \\sigma},\\ \\Gamma^{\\rho}_{N N}, \\ \\Gamma^{N}_{N \\rho}, \\ \\Gamma^{N}_{N N}$$ have tensor character with respect to the transformation of the coordinates $x^1, \\dots , x^{N-1}$\n\\end{tcolorbox}\nWe know that $a_{\\rho \\sigma} = a^{,}_{mn}\\partial_{\\rho}x^{,m}\\partial_{\\sigma}x^{,n}$ with $\\rho , \\sigma = 1, \\dots, N-1$ and $m , n = 1, \\dots, N$. We have also $x^N = x^{,N}$.\\\\\n$\\boldsymbol{[ \\rho N, \\  \\sigma]}$\n\\begin{align}\n\\ [ \\rho N, \\  \\sigma] &= \\half \\partial_N a_{\\rho \\sigma}\\quad \\text{see (2.639)}\\\\\n\\ &= \\half \\partial_N (a^{,}_{mn}\\partial_{\\rho}x^{,m}\\partial_{\\sigma}x^{,n})\\\\\n\\ & = \\left\\{ \\begin{array}{l}\n\\half (\\partial_N a^{,}_{mn}\\partial_{\\rho}x^{,m}\\partial_{\\sigma}x^{,n}\\\\\n\\ + a^{,}_{mn} \\partial_{\\sigma}x^{,n} \\partial_{N \\rho}x^{,m}\\\\\n\\ + a^{,}_{mn} \\partial_{\\rho}x^{,m} \\partial_{N \\sigma}x^{,n})\n\\end{array} \\right.\\\\\n\\text{We have  }\\quad \\partial_{N }x^{,m} = \\delta^m_N & \\Rightarrow \\ \\partial_{N \\rho}x^{,m}= \\partial_{N \\sigma}x^{,n} = 0\\\\\n\\Rightarrow \\quad [ \\rho N, \\  \\sigma] &= \\half \\partial_N a^{,}_{mn}\\partial_{\\rho}x^{,m}\\partial_{\\sigma}x^{,n}\\\\\n\\ &= \\left\\{ \\begin{array}{l}\n\\half (\\partial_N a^{,}_{\\alpha\\beta}\\partial_{\\rho}x^{,\\alpha}\\partial_{\\sigma}x^{,\\beta}\\\\\\\\\n\\ +\\partial_N a^{,}_{NN}\\underbrace{\\partial_{\\rho}x^{,N}}_{=0}\\underbrace{\\partial_{\\sigma}x^{,N}}_{=0}\\\\\\\\\n\\ +\\partial_N a^{,}_{\\alpha N}\\partial_{\\rho}x^{,\\alpha}\\underbrace{\\partial_{\\sigma}x^{,N}}_{=0}\\\\\\\\\n\\ +\\partial_N a^{,}_{\\beta N}\\partial_{\\rho}x^{,\\alpha}\\underbrace{\\partial_{\\sigma}x^{,N}}_{=0})\\\\\n\\end{array} \\right.\\\\\n\\Rightarrow \\quad [ \\rho N, \\  \\sigma] &=  \\underbrace{\\half \\partial_N a^{,}_{\\alpha\\beta}}_{= [\\alpha N, \\ \\beta]^{,}}\\partial_{\\rho}x^{,\\alpha}\\partial_{\\sigma}x^{,\\beta}\\\\\n&= [\\alpha N, \\ \\beta]^{,}\\partial_{\\rho}x^{,\\alpha}\\partial_{\\sigma}x^{,\\beta}\n\\end{align}\nThis confirms the tensor character of $[ \\rho N, \\  \\sigma] $\n$$\\diamond$$\n$\\boldsymbol{[ \\rho \\sigma, \\  N]}$ this follows immediately from the previous and considering $[ \\rho \\sigma, \\  N] = - [ \\rho N, \\  \\sigma]$ see(2.639) \\\\\n$$\\diamond$$\n$\\boldsymbol{[\\rho N, \\ N ] }$\\\\\nWe prove the case for $\\boldsymbol{[ NN, \\ \\rho ]}$  as $[\\rho N, \\ N ] = -[ NN, \\ \\rho ] $\n\\begin{align}\n\\ [ NN, \\ \\rho ] &= \\half \\partial_{\\rho} a_{NN}\\quad \\text{see (2.639)}\\\\\n\\ &= \\half \\partial_{\\rho} (a^{,}_{mn}\\partial_{N}x^{,m}\\partial_{N}x^{,n})\\\\\n\\ & = \\left\\{ \\begin{array}{l}\n\\half (\\partial_{\\rho} a^{,}_{mn}\\partial_{N}x^{,m}\\partial_{N}x^{,n}\\\\\\\\\n\\ + a^{,}_{mn} \\partial_{\\rho}x^{,n} \\underbrace{\\partial_{N \\rho}x^{,m}}_{=0}\\\\\\\\\n\\ + a^{,}_{mn} \\partial_{\\rho}x^{,m} \\underbrace{\\partial_{N \\rho}x^{,n}}_{=0})\n\\end{array} \\right.\\\\\n\\ &= \\half \\partial_{\\rho} a^{,}_{mn}\\partial_{N}x^{,m}\\partial_{N}x^{,n}\\\\\n\\ &= \\left\\{ \\begin{array}{l}\n\\half (\\partial_{\\rho} a^{,}_{\\alpha\\beta}\\underbrace{\\partial_{N}x^{,\\alpha}}_{=0}\\underbrace{\\partial_{N}x^{,\\beta}}_{=0}\\\\\\\\\n\\ +\\partial_{\\rho} a^{,}_{NN}\\underbrace{\\partial_{N}x^{,N}}_{=1}\\underbrace{\\partial_{N}x^{,N}}_{=1}\\\\\\\\\n\\ +\\partial_{\\rho} a^{,}_{\\alpha N}\\underbrace{\\partial_{N}x^{,\\alpha}}_{=0}\\underbrace{\\partial_{N}x^{,N}}_{=1}\\\\\\\\\n\\ +\\partial_{\\rho} a^{,}_{\\beta N}\\underbrace{\\partial_{N}x^{,\\alpha}}_{=0}\\underbrace{\\partial_{N}x^{,N}}_{=1})\\\\\n\\end{array} \\right.\\\\\n\\Rightarrow \\quad [ NN, \\ \\rho ] &= \\half \\partial_{\\rho} a^{,}_{NN}\\\\\n\\Leftrightarrow \\quad [ NN, \\ \\rho ] &=  \\underbrace{\\half \\partial_{\\alpha} a^{,}_{NN}}_{=[NN, \\ \\alpha]^,}\\partial_{\\rho}x^{,\\alpha}\\\\\n\\Rightarrow \\quad [ NN, \\ \\rho ] &=  [NN, \\ \\alpha]^, \\partial_{\\rho}x^{,\\alpha}\n\\end{align}\nThis confirms the tensor character of $[ NN, \\ \\rho ] $ and consequently of $[\\rho N, \\ N ]$\n$$\\diamond$$\n\\newpage\n$\\boldsymbol{[NN, \\ N ] }$\\\\\n\\begin{align}\n\\ [ NN, \\ N ] &= \\half \\partial_{N} a_{NN}\\quad \\text{see (2.639)}\\\\\n\\ &= \\half \\partial_{N} (a^{,}_{mn}\\partial_{N}x^{,m}\\partial_{N}x^{,n})\\\\\n\\ & = \\left\\{ \\begin{array}{l}\n\\half (\\partial_{N} a^{,}_{mn}\\underbrace{\\partial_{N}x^{,m}}_{\\delta^m_N}\\underbrace{\\partial_{N}x^{,n}}_{\\delta^n_N}\\\\\\\\\n\\ + a^{,}_{mn} \\partial_{N}x^{,n} \\underbrace{\\partial_{N N}x^{,m}}_{=0}\\\\\\\\\n\\ + a^{,}_{mn} \\partial_{N}x^{,m} \\underbrace{\\partial_{N N}x^{,n}}_{=0})\n\\end{array} \\right.\\\\\n\\ &= \\half \\partial_{N} a^{,}_{mn}\\delta^m_N\\delta^n_N\\\\\n\\ &=  \\underbrace{\\half \\partial_{N} a^{,}_{NN}}_{=[ NN, \\ N ]^,} \\\\\n\\Rightarrow \\quad [ NN, \\ N ] &=  [ NN, \\ N ]^,\n\\end{align}\nThis confirms the tensor character of $[ NN, \\ N ] $ as an invariant under transformation of the coordinates $x^1, \\dots , x^{N-1}$\n$$\\diamond$$\n$$\\Gamma^{\\rho}_{N \\sigma},\\ \\Gamma^{N}_{\\rho \\sigma},\\ \\Gamma^{\\rho}_{N N}, \\ \\Gamma^{N}_{N \\rho}, \\ \\Gamma^{N}_{N N}$$\nFor the Christoffel symbols of the second kind we use:\n\\begin{align}\n\\Gamma^r_{st} &= a^{rk}[st,\\ k]\\\\\n\\ a^{rk} &= a^{,mn}\\pdv{x^r}{x^{,m}}\\pdv{x^k}{x^{,n}}\\\\\n \\text{(2.631) page 65:}\\spatie a^{N \\rho} &= 0 \n\\end{align}\n\\newpage\n$\\boldsymbol{\\Gamma^{\\rho}_{N \\sigma}}$\\\\\n\\begin{align}\n\\Gamma^{\\rho}_{N \\sigma} &= a^{\\rho k}[N \\sigma,\\ k]\\\\\n\\ & = a^{\\rho \\tau}[N \\sigma,\\ \\tau]+ \\underbrace{a^{\\rho N}}_{=0}[N \\sigma,\\ N]\\\\\n\\text{(24):}\\quad &= a^{,mn}\\pdv{x^{\\rho}}{x^{,m}}\\pdv{x^{\\tau}}{x^{,n}}[N \\sigma,\\ \\tau]\\\\\n\\text{also (see previous results):}\\quad \\ [N \\sigma,\\ \\tau] &= [ N \\mu, \\ \\nu]^{,}\\partial_{\\sigma}x^{,\\mu}\\partial_{\\tau}x^{,\\nu}\n\\end{align}\nAnd so,\n\\begin{align}\n \\Gamma^{\\rho}_{N \\sigma} &=a^{,mn}\\pdv{x^{\\rho}}{x^{,m}}\\pdv{x^{\\tau}}{x^{,n}}[ N \\mu, \\ \\nu]^{,}\\partial_{\\sigma}x^{,\\mu}\\partial_{\\tau}x^{,\\nu}\\\\\n\\ &=a^{,mn}\\pdv{x^{\\rho}}{x^{,m}}\\underbrace{\\pdv{x^{,\\nu}}{x^{,n}}}_{= \\delta^{\\nu}_{n}}[ N \\mu, \\ \\nu]^{,}\\partial_{\\sigma}x^{,\\mu}\\\\\n\\ &=a^{,\\theta \\nu }[ N \\mu, \\ \\nu]^{,}\\pdv{x^{\\rho}}{x^{,\\theta}}\\pdv{x^{,\\mu}}{x^{\\sigma}}+ \\underbrace{a^{,N \\nu }}_{=0}[ N \\mu, \\ \\nu]^{,}\\pdv{x^{\\rho}}{x^{,N}}\\pdv{x^{,\\mu}}{x^{\\sigma}}\\\\\n\\ &=\\underbrace{a^{,\\theta \\nu }[ N \\mu, \\ \\nu]^{,}}_{ = \\Gamma^{,\\theta}_{N\\mu}}\\pdv{x^{\\rho}}{x^{,\\theta}}\\pdv{x^{,\\mu}}{x^{\\sigma}}\\\\\n\\Rightarrow \\quad \\Gamma^{\\rho}_{N \\sigma} &=  \\Gamma^{,\\theta}_{N\\mu}\\pdv{x^{\\rho}}{x^{,\\theta}}\\pdv{x^{,\\mu}}{x^{\\sigma}}\n\\end{align}\nSo, $\\Gamma^{\\rho}_{N \\sigma}$ is a $2^{nd}$ order mixed tensor (contravariant in $\\rho$, covariant in $\\sigma$.)\n$$\\diamond$$\n$\\boldsymbol{\\Gamma^{N }_{\\rho \\sigma}}$\\\\\n\\begin{align}\n\\Gamma^{N }_{\\rho \\sigma} &= a^{N  k}[\\rho \\sigma,\\ k]\\\\\n\\ & = \\underbrace{a^{N \\tau}}_{=0}[\\rho \\sigma,\\ \\tau]+ a^{N N}[\\rho \\sigma,\\ N]\\\\\n\\text{(8):}\\quad &= a^{,NN}[\\alpha \\beta, \\ N]^{,}\\partial_{\\rho}x^{,\\alpha}\\partial_{\\sigma}x^{,\\beta}\\\\\n\\text{considering :}\\quad \\ a^{,N \\tau} & =0 \\quad \\text{we can write this as:}\\\\\n\\Gamma^{N }_{\\rho \\sigma} &=a^{,N \\tau}[\\alpha \\beta, \\ \\tau]^{,}\\partial_{\\rho}x^{,\\alpha}\\partial_{\\sigma}x^{,\\beta}+ a^{,NN}[\\alpha \\beta, \\ N]^{,}\\partial_{\\rho}x^{,\\alpha}\\partial_{\\sigma}x^{,\\beta}\\\\\n\\ &=\\underbrace{a^{,N k}[\\alpha \\beta, \\ k]^{,}}_{= \\Gamma^{,N}_{\\alpha \\beta}}\\partial_{\\rho}x^{,\\alpha}\\partial_{\\sigma}x^{,\\beta}\\\\\n\\Rightarrow \\quad \\Gamma^{N }_{\\rho \\sigma} &= \\Gamma^{,N}_{\\alpha \\beta}\\partial_{\\rho}x^{,\\alpha}\\partial_{\\sigma}x^{,\\beta}\n\\end{align}\nSo, $\\Gamma^{N }_{\\rho \\sigma}$ is a $2^{nd}$ order mixed tensor (covariant in both indices)\n$$\\diamond$$\n\n$\\boldsymbol{\\Gamma^{\\rho}_{N N}}$\\\\\n\\begin{align}\n\\Gamma^{\\rho }_{N N} &= a^{\\rho  k}[N N,\\ k]\\\\\n\\ & = a^{\\rho \\tau}[N N,\\ \\tau]+ \\underbrace{a^{\\rho N}}_{=0}[N N,\\ N]\\\\\n\\text{(16):}\\quad &= a^{,mn}\\pdv{x^\\rho}{x^{,m}}\\pdv{x^\\tau}{x^{,n}}[NN, \\ \\alpha]^, \\partial_{\\tau}x^{,\\alpha}\\\\\n\\ &= a^{,mn}\\pdv{x^\\rho}{x^{,m}} \\underbrace{\\pdv{x^{\\alpha}}{x^{,n}}}_{= \\delta^{\\alpha}_{n}}[NN, \\ \\alpha]^, \\\\\n\\ &= a^{, \\tau \\alpha}[NN, \\ \\alpha]^,\\pdv{x^\\rho}{x^{, \\tau}}+  \\underbrace{a^{,N \\alpha}}_{=0}[NN, \\ \\alpha]^,\\pdv{x^\\rho}{x^{,N}} \\\\\n\\ &= \\underbrace{a^{, \\tau \\alpha}[NN, \\ \\alpha]^,}_{= \\Gamma^{, \\tau}_{NN}}\\pdv{x^\\rho}{x^{, \\tau}}  \\\\\n\\Rightarrow \\quad \\Gamma^{\\rho }_{N N} &= \\Gamma^{, \\tau}_{NN}\\pdv{x^\\rho}{x^{, \\tau}}  \n\\end{align}\nSo, $\\Gamma^{\\rho }_{N N}$ is a $1^{st}$ order contravariant tensor.\n$$\\diamond$$\n\n$\\boldsymbol{\\Gamma^{N}_{N \\rho}}$\\\\\n\\begin{align}\n\\Gamma^{N}_{N \\rho} &= a^{N  k}[N \\rho,\\ k]\\\\\n\\ & = a^{N N}[N \\rho,\\ N]+ \\underbrace{a^{N \\tau}}_{=0}[N \\rho,\\ \\tau]\\\\\n\\text{(16):}\\quad &= a^{,NN}[N\\alpha, \\ N ]^, \\partial_{\\rho}x^{,\\alpha}\\\\\n\\text{considering :}\\quad \\ a^{,N \\tau} & =0 \\quad \\text{we can write this as:}\\\\\n\\ &= a^{,N\\tau}[N\\alpha, \\ \\tau ]^, \\partial_{\\rho}x^{,\\alpha}+ a^{,NN}[N\\alpha, \\ N ]^, \\partial_{\\rho}x^{,\\alpha}\\\\\n\\ &= \\underbrace{a^{,N k}[N \\alpha, \\ k ]^,}_{= \\Gamma^{,N}_{N \\alpha}} \\partial_{\\rho}x^{,\\alpha}\\\\\n\\Rightarrow \\quad \\Gamma^{N}_{N \\rho} &= \\Gamma^{,N}_{N \\alpha} \\partial_{\\rho}x^{,\\alpha}\n\\end{align}\nSo, $\\Gamma^{N}_{N \\rho}$ is a $1^{st}$ order covariant tensor.\n$$\\diamond$$\n\\newpage\n$\\boldsymbol{\\Gamma^{N}_{N N}}$\\\\\n\\begin{align}\n\\Gamma^{N}_{N N} &= a^{N  k}[N N,\\ k]\\\\\n\\ & = a^{N N}[N N,\\ N]+ \\underbrace{a^{N \\tau}}_{=0}[N N,\\ \\tau]\\\\\n\\ & = a^{,N N}[N N,\\ N]\\\\\n\\text{(22):}\\quad &= a^{,N N}[N N,\\ N]^,\\\\\n\\Rightarrow \\quad \\Gamma^{N}_{N N} &= \\Gamma^{,N}_{N N}\n\\end{align}\nSo, $\\Gamma^{N}_{N N}$ is an invariant.\n$$\\blacklozenge$$\n\\newpage\n\\section{p79-exercise 10}\n\\begin{tcolorbox}\nIf $\\theta, \\phi$ are colatitude and azimuth on a sphere, and we take\n$$x^1 = \\theta \\cos \\phi, \\ x^2=\\theta\\sin \\phi$$\nCalculate the Christoffels symbols for the coordinate system $x^1, x^2$ and show that they vanish at the point $\\theta = 0$\n\\end{tcolorbox}\n\\begin{align}\n\\text{We have, page 48  (2.507) :}\\spatie\\Gamma_{mn}^{,r} =\\Gamma_{pq}^{s}\\pdv{x^{,r}}{x^s}\\pdv{x^{p}}{x^{,m}}\\pdv{x^{q}}{x^{,n}}+\\pdv{x^{,r}}{x^s}\\pdv{x^s}{x^{,m}}{x^{,n}}\n\\end{align}\nThe calculations are really basic but lengthy and only train your skills in basic calculus. So I will only calculate $\\Gamma_{11}^{,1}$.\\\\\nWe know that in a spherical coordinate system all $\\Gamma_{pq}^{,s}$ vanish except for $\\Gamma_{\\phi\\phi}^{\\theta} = -\\sin\\theta\\cos\\theta$ and $\n\\Gamma_{\\phi\\theta}^{\\phi} =  \\cot\\theta$.\n\\begin{align}\n\\boldsymbol{\\Gamma_{11}^{,1}} &=\\boldsymbol{\\Gamma_{\\phi\\phi}^{\\theta}\\partial_{\\theta}{x^{1}}\\partial_{1}\\phi\\partial_{1}\\phi+ 2\\Gamma_{\\phi\\theta}^{\\phi}\\partial_{\\phi}{x^{1}}\\partial_{1}\\theta\\partial_{1}\\phi+\\partial_{\\theta}{x^{1}}\\partial^2_{11}{\\theta}+\\partial_{\\phi}{x^{1}}\\partial^2_{11}{\\phi}}\\\\\n\\text{we have}\\quad & \\left \\{ \\begin{array}{l}\n\\ x^1 = \\theta\\cos\\phi\\\\\n\\ x^2 = \\theta\\sin\\phi\\\n\\end{array}\\right. \\quad \\Rightarrow \\quad \\left \\{ \\begin{array}{l}\n\\theta = \\sqrt{(x^1)^2+(x^2)^2}\\\\\n\\phi = \\arctan \\frac{x^2}{x^1}\n\\end{array}\\right.\\\\\n\\text{so}\\ &\\left \\{ \\begin{array}{ll}\n\\partial_{1} \\theta = \\frac{x^1}{\\theta} = \\cos\\phi & \\partial_{1} \\phi = -\\frac{x^2}{\\theta^2} = -\\frac{\\sin\\phi}{\\theta}  \\\\\\\\\n\\partial_{\\theta} x^1 = \\cos\\phi & \\partial_{\\phi} x^1 = -\\theta\\sin\\phi\\\\\\\\\n\\partial^2_{11} \\theta = \\frac{\\theta^2 -(x^1)^2}{\\theta ^3} = \\frac{\\sin^2\\phi}{\\theta} & \\partial^2_{11} \\phi =2\\frac{x^1 x^2}{\\theta^4}= 2\\frac{\\cos\\phi \\sin\\phi}{\\theta^2}\n\\end{array}\\right.\\\\\n\\Gamma_{11}^{,1} &=\\Gamma_{\\phi\\phi}^{\\theta}\\cos\\phi\\frac{\\sin^2\\phi}{\\theta^2}+ 2\\Gamma_{\\phi\\theta}^{\\phi}(-\\theta\\sin\\phi)\\cos\\phi(-\\frac{\\sin\\phi}{\\theta} )+\\cos\\phi\\frac{\\sin^2\\phi}{\\theta}+(-\\theta\\sin\\phi)(2\\frac{\\cos\\phi \\sin\\phi}{\\theta^2})\\\\\n\\ &= -\\sin\\theta\\cos\\theta\\frac{\\cos\\phi \\sin^2\\phi}{\\theta^2}+ 2\\cot\\theta\\cos\\phi\\sin^2\\phi+\\frac{\\cos\\phi\\sin^2\\phi}{\\theta}-2\\frac{\\cos\\phi \\sin^2\\phi}{\\theta}\\\\\n\\ &= (2\\cot\\theta -\\frac{1}{\\theta}-\\frac{\\sin\\theta\\cos\\theta}{\\theta^2})\\cos\\phi\\sin^2\\phi\n\\end{align}\n$$\\diamond$$\n\\newpage\nDoes $\\boldsymbol{\\Gamma_{11}^{,1}}$ vanish for $\\theta \\rightarrow0$ ? \\\\The problematic term in (7) is $2\\cot\\theta -\\frac{1}{\\theta}-\\frac{\\sin\\theta\\cos\\theta}{\\theta^2}$ for which $\\lim_{\\theta \\to 0 }= \\pm \\infty \\mp \\infty \\mp \\infty$ is undefined. \n\\begin{align}\n\\text{Consider}\\quad L_{+}& = \\lim_{\\theta \\to 0_{+}}2\\cot\\theta -\\frac{1}{\\theta}-\\frac{\\sin\\theta\\cos\\theta}{\\theta^2} \\\\\n\\text{We have}\\quad &\\begin{array}{lllll}\n\\sin\\theta , \\theta \\ge 0&\\sin\\theta \\leq \\theta&\\frac{1}{\\theta}\\leq \\frac{1}{\\sin \\theta}& 0 \\ge \\cos \\theta \\leq 1\\end{array}\\\\\n\\text{so} \\quad L_{+}&= \\lim_{\\theta \\to 0_{+}}2\\frac{\\cos\\theta}{\\sin\\theta} -\\frac{1}{\\theta}-\\frac{\\sin\\theta\\cos\\theta}{\\theta^2} \\\\\n\\ &\\geq \\lim_{\\theta \\to 0_{+}}2\\frac{\\cos\\theta}{\\theta} -\\frac{1}{\\theta}-\\frac{\\sin\\theta\\cos\\theta}{\\theta^2} \\\\\n\\ &\\geq \\lim_{\\theta \\to 0_{+}}2\\frac{\\cos\\theta}{\\theta} -\\frac{1}{\\theta}-\\frac{\\cancel{\\theta}\\cos\\theta}{\\theta^{\\cancel{2} }}\\\\\n\\ &\\geq \\lim_{\\theta \\to 0_{+}}\\frac{\\cos\\theta-1}{\\theta}\\\\\n\\text{(l'Hospitale rule)}\\Rightarrow\\quad L_{+}&\\geq 0\\\\\n\\text{also} \\quad L_{+}&= \\lim_{\\theta \\to 0_{+}}2\\frac{\\cos\\theta}{\\sin\\theta} -\\frac{1}{\\theta}-\\frac{\\sin\\theta\\cos\\theta}{\\theta^2} \\\\\n\\ &\\leq \\lim_{\\theta \\to 0_{+}}2\\frac{\\cos\\theta}{\\sin\\theta} -\\frac{\\cos\\theta}{\\theta}-\\frac{\\sin\\theta\\cos\\theta}{\\theta^2} \\\\\n\\ &\\leq \\lim_{\\theta \\to 0_{+}}\\cos\\theta(\\frac{2}{\\sin\\theta} -\\frac{1}{\\theta}-\\frac{\\sin\\theta}{\\theta^2})\\\\\n\\frac{\\sin\\theta}{\\theta} \\leq 1 \\quad\\Rightarrow\\quad &\\leq\\lim_{\\theta \\to 0_{+}} \\cos\\theta(\\frac{2}{\\sin\\theta} -\\frac{1}{\\theta}-\\frac{1}{\\theta})\\\\\n\\frac{1}{\\sin\\theta} \\geq \\frac{1}{\\theta} \\quad\\Rightarrow\\quad &\\leq\\lim_{\\theta \\to 0_{+}} \\cos\\theta(\\frac{2}{\\theta} -\\frac{1}{\\theta}-\\frac{1}{\\theta})\\\\\n\\ & \\leq 0\\\\\n\\text{(14) and ((20)}\\quad \\Rightarrow L_{+}& =0\n\\end{align} \nConsidering that $$L_{-} = \\lim_{\\theta \\to 0_{-}}2\\cot\\theta -\\frac{1}{\\theta}-\\frac{\\sin\\theta\\cos\\theta}{\\theta^2}$$ is equivalent to  $$L_{+}^{\\alpha} = \\lim_{\\alpha \\to 0_{+}}-(2\\cot\\alpha -\\frac{1}{\\alpha}-\\frac{\\sin\\alpha\\cos\\alpha}{\\alpha^2})$$ (substitute $\\theta = -\\alpha$) we conclude that   $$L_{-} =  -L_{+}=0$$. And so $$\\left.\\Gamma_{11}^{,1}\\right|_{\\theta=0} =\\left.(2\\cot\\theta -\\frac{1}{\\theta}-\\frac{\\sin\\theta\\cos\\theta}{\\theta^2})\\cos\\phi\\sin^2\\phi\\right|_{\\theta=0} = 0$$\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p79-exercise 11}\n\\begin{tcolorbox}\nIf vectors $T^r$ and $S_r$ undergo parallel propagation along a curve, show that $T^nS_n$ is constant along the curve.\n\\end{tcolorbox}\nParallel propagation of $T^r$ and $S_r$  along a curve means\n\\begin{align}\n\\frac{\\delta T^r}{\\delta u} &\\equiv \\dv{T^r}{u} + \\Gamma^r_{mn}T^m \\dv{x^n}{u} = 0\\\\\n\\frac{\\delta S_r}{\\delta u} &\\equiv \\dv{S_r}{u} - \\Gamma^m_{rn}S_m \\dv{x^n}{u} = 0\\\\\n\\text{Hence}\\quad \\dv{T^rS_r}{u} &= S_r\\left(-\\Gamma^r_{mn}T^m\\dv{x^n}{u}\\right) + T^r\\left(\\Gamma^m_{rn}S_m \\dv{x^n}{u} \\right)\\\\\n\\ &= \\dv{x^n}{u}\\left(\\Gamma^m_{rn}S_mT^r -  \\Gamma^m_{rn}T^rS_m\\right)\\\\\n\\ &=0\\\\\n\\Rightarrow \\spatie T^rS_r &= C^{st}\n\\end{align} \n$$\\blacklozenge$$\n\\newpage\n\n\\section{p79-exercise 12}\n\\begin{tcolorbox}\nDeduce from 2.201 that the determinant $a= \\left | a_{mn} \\right |$ transforms according to $$a^, = aJ^2 \\quad , \\quad J = \\left | \\pdv{x^r}{x^{,s}}\\right|$$\n\\end{tcolorbox}\n\\begin{align}\n\\ a^,_{rs} &= a_{mk} \\pdv{x^{m}}{x^{,r}} \\pdv{x^{k}}{x^{,s}}\\\\\n\\text{Be}\\spatie \\left(J_{mr} \\right )&= \\left (\\pdv{x^{m}}{x^{,r}}\\right )\\\\\n\\text{In (1) put  }\\spatie c_{kr} &= a_{mk} \\pdv{x^{m}}{x^{,r}}= a_{km} \\pdv{x^{m}}{x^{,r}} \\\\\n\\Rightarrow\\spatie a^,_{rs} &= c_{kr} \\pdv{x^{k}}{x^{,s}}\\\\\n\\text{or in matrix form  } \\spatie A^, &= C^T J\\quad \\text{with}\\quad C = AJ\\\\\n\\Rightarrow\\spatie \\left |A^, \\right| &= \\left | (AJ)^T J\\right |\\\\\n\\Leftrightarrow\\spatie \\left |A^, \\right| &= \\left | J^T A^T J\\right |\\\\\n\\Leftrightarrow\\spatie \\left |A^, \\right| &= \\left | A\\right | \\left |J\\right |\\left |J\\right |\\\\\n\\Leftrightarrow\\spatie \\left |A^, \\right| &= \\left | A\\right | \\left |J\\right | ^2\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p79-exercise 13}\n\\begin{tcolorbox}\nUsing local Cartesians and applying the result of the previous exercise (N° 12), prove that, if the metric form is positive-definite, then the determinant $a= \\left | a_{mn} \\right |$ is always positive.\n\\end{tcolorbox}\nUsing local Cartesian coordinates we have:\n\\begin{align}\n\\Phi &= \\epsilon_i (dy^i)^2 \\quad \\text{with} \\quad \\Phi > 0\\\\\n\\text{so}\\quad \\left | a_{mn} \\right |  &= \\left | \\begin{array}{cccc}  \n\\epsilon_1&0&\\dots & 0\\\\\n\\ 0&\\epsilon_2&\\dots & 0\\\\\n\\vdots&\\vdots&\\vdots & \\vdots\\\\\n\\ 0&0&\\dots & \\epsilon_N\\\\\n\\end{array} \\right | = \\prod_{i=1}^{N}\\epsilon_i >0\\\\\n\\end{align}\nGoing from $\\left( a_{mn} \\right)$ to any arbitrary coordinate system, we have (see exercise 12 page 79) \n\\begin{align}\n\\left | a^,_{mn} \\right | &= \\underbrace{\\left | a_{mn} \\right |}_{>0}\\underbrace{J^2}_{>0}\\\\\n\\Rightarrow \\quad\\left | a^,_{mn} \\right | &>0\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p79-exercise 14}\n\\begin{tcolorbox}\nIn a plane, let $x^1, \\  x^2$ be the distances of a general point from the point with rectangular coordinates $(1,0)$, $(-1,0)$, respectively. (These are bipolar coordinates.) Find the line element for these coordinates, and find the conjugate tensor $a^{mn}$.\n\\end{tcolorbox}\n\\begin{figure}[h]\n%\\includegraphics[scale=.4]{Bipolar.jpg}\n\\input{D:/MathLatex/images/fig_p79_260_a.tex}\n\\caption{Bipolar coordinates}\n\\label{fig:fig_p79_260_a}\n\\end{figure}\n\\begin{align}\n\\ (x^1)^2 &= \\left( y^1-1\\right) ^2 + \\left(y^2\\right)^2\\\\\n\\ (x^2)^2 &= \\left( y^1+1\\right) ^2 + \\left(y^2\\right)^2\\\\\n\\partial_1 (1) \\quad\\Rightarrow \\quad x^1 &= \\left( y^1-1\\right)\\partial_1 y^1  + \\left(y^2\\right)\\partial_1 y^2\\\\\n\\partial_2 (2) \\quad\\Rightarrow \\quad\\ x^2 &= \\left( y^1+1\\right)\\partial_2 y^1  + \\left(y^2\\right)\\partial_2 y^2\\\\\n\\partial_2 (1) \\quad\\Rightarrow \\quad 0 &= \\left( y^1-1\\right)\\partial_2 y^1  + \\left(y^2\\right)\\partial_2 y^2\\\\\n\\partial_1 (2) \\quad\\Rightarrow \\quad\\ 0 &= \\left( y^1+1\\right)\\partial_1 y^1  + \\left(y^2\\right)\\partial_1 y^2\\\\\n\\Rightarrow \\quad & \\left\\{\\begin{array}{ll}\n\\text{(3)-(6):}& \\partial_1 y^1 = -\\frac{x^1}{2}\\\\\\\\\n\\text{(4)-(5):}& \\partial_2 y^1 = \\frac{x^2}{2}\\\\\\\\\n\\text{(6):}& \\partial_1 y^2 = \\frac{y^1+1}{2y^2}x^1\\\\\\\\\n\\text{(5):}& \\partial_2 y^2 = -\\frac{y^1-1}{2y^2}x^2\\\\\n\\end{array}\\right.\\\\\n\\text{Hence,}\\quad J &= \\left(\\pdv{y^m}{x^n} \\right) = \\begin{pmatrix}\n-\\frac{x^1}{2} &\\frac{x^2}{2}  \\\\\n\\frac{y^1+1}{2y^2}x^1 & -\\frac{y^1-1}{2y^2}x^2 \\\\\n\\end{pmatrix}\n\\end{align}\n\\newpage\nBe $A$ the metric tensor in Cartesian coordinate system. Then, going to a arbitrary coordinate system gives a metric tensor according to  \n\\begin{align}\n\\ & A^, = J^TAJ =J^TJ \\quad \\text{as}\\quad A = \\begin{pmatrix}\n1 &0 \\\\\n0& 1 \\\\\n\\end{pmatrix}\\\\\n\\Rightarrow\\quad & A^, = \\begin{pmatrix}\n-\\frac{x^1}{2} & \\frac{y^1+1}{2y^2}x^1 \\\\\n\\frac{x^2}{2} & -\\frac{y^1-1}{2y^2}x^2 \\\\\n\\end{pmatrix}\\begin{pmatrix}\n-\\frac{x^1}{2} &\\frac{x^2}{2}  \\\\\n\\frac{y^1+1}{2y^2}x^1 & -\\frac{y^1-1}{2y^2}x^2 \\\\\n\\end{pmatrix}\\\\\n\\Rightarrow\\quad & A^, =\\frac{x^1x^2}{4(y^2)^2} \\begin{pmatrix}\n\\ & \\\\\nx^1x^2 &-\\left[(y^1)^2 +(y^2)^2-1)\\right] \\\\\\\\\n-\\left[(y^1)^2 +(y^2)^2-1)\\right]  &x^1x^2\\\\\n\\ & \n\\end{pmatrix}\n\\end{align}\nWe use plane geometry to express expression (11) as  a function of only $(x^1,x^2)$. For the triangle $APB$ in the figure below, we have\n\\begin{figure}[h]\n%\\includegraphics[scale=.4]{Bipolar2.jpg}\n\\input{D:/MathLatex/images/fig_p79_260_b.tex}\n\\caption{Bipolar coordinates versus Cartesian coordinates}\n\\label{fig:fig_p79_260_b}\n\\end{figure}\n\\begin{align}\n\\ \\left |  OP \\right |^2 &= \\frac{(x^1)^2+(x^2)^2}{2} - \\underbrace{\\frac{\\left | AB \\right|^2}{4}}_{=1}\\\\\n\\Rightarrow\\quad (y^1)^2 +(y^2)^2 &= \\frac{(x^1)^2+(x^2)^2}{2} - 1\n\\end{align}\nThe area $K$ of the triangle can be expressed in two ways\n\\begin{align}\n\\ K &= \\half y^2\\left | AB \\right| = y^2\\\\\n\\text{and} \\quad K &= \\sqrt{s(s-x^1)(s-x^2)(s-2)}\\\\\n\\text{with}\\quad s &= \\half (x^1+x^2+2)\\\\\n\\text{hence}\\quad (y^2)^2 &= \\frac{1}{16}(x^1+x^2+2)(x^1+2)(x^2+2)(x^1+x^2)\n\\end{align}\nSo we get from (11):\n\\begin{align}\nA^, =\\frac{4x^1x^2}{(x^1+x^2+2)(x^1+2)(x^2+2)(x^1+x^2)} \\begin{pmatrix}\n\\ & \\\\\nx^1x^2 &2-\\frac{(x^1)^2+(x^2)^2}{2} \\\\\\\\\n2-\\frac{(x^1)^2+(x^2)^2}{2}  &x^1x^2\\\\\n\\ & \n\\end{pmatrix}\n\\end{align}\nFor the conjugate metric tensor we start from expression (11) and invert the metric tensor\n\\begin{align}\n\\left| A^,\\right| &= \\left[ \\frac{x^1x^2}{4(y^2)^2}\\right]^2\\left[(x^1x^2)^2 -\\left((y^1)^2 +(y^2)^2-1\\right)^2\\right]\\\\\n\\text{hence}\\quad \\left(a^{,mn}\\right) &= \\frac{1}{\\left| A^,\\right|}\\frac{x^1x^2}{4(y^2)^2} \\begin{pmatrix}\n\\ & \\\\\nx^1x^2 &\\left[(y^1)^2 +(y^2)^2-1\\right] \\\\\\\\\n\\left[(y^1)^2 +(y^2)^2-1\\right]  &x^1x^2\\\\\n\\ & \n\\end{pmatrix}\\\\\n\\ &= \\frac{4(y^2)^2\\begin{pmatrix}\n\\ & \\\\\nx^1x^2 &\\left[(y^1)^2 +(y^2)^2-1\\right] \\\\\\\\\n\\left[(y^1)^2 +(y^2)^2-1\\right]  &x^1x^2\\\\\n\\ & \n\\end{pmatrix}}{x^1x^2\\left[(x^1x^2)^2 -\\left((y^1)^2 +(y^2)^2-1\\right)^2\\right]} \\\\\n\\text{with} \\quad x^1x^2&= \\sqrt{\\left[(y^1-1)^2 +(y^2)^2\\right]\\left[(y^1+1)^2 +(y^2)^2\\right]}\n\\end{align}\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p79-exercise 15}\n\\begin{tcolorbox}\nGiven $\\Phi = a_{mn}dx^m dx^n$, with $a_{11} = a_{22}= 0$ but $a_{12} \\ne 0$, show that $\\Phi$ may be written in the form $$ \\Phi = \\epsilon\\Psi^2_1- \\epsilon\\Psi^2_2 + \\Phi_2$$ where $\\Phi_2$ is a homogeneous quadratic form in $ dx^3, dx^4, \\dots ,dx^N $, $\\epsilon = \\pm 1$ , and where \n$$\\Psi_1 = \\frac{1}{\\sqrt(2 \\epsilon a_{12})}\\left[ a_{12}(dx^1+dx^2) + (a_{13}+a_{23})dx^3+ \\dots +(a_{1N}+a_{2N})dx^N \\right]$$\n$$\\Psi_2 = \\frac{1}{\\sqrt(2 \\epsilon a_{12})}\\left[ a_{12}(-dx^1+dx^2) + (a_{13}-a_{23})dx^3+ \\dots +(a_{1N}-a_{2N})dx^N \\right]$$\n\\end{tcolorbox}\nUsing local Cartesian coordinates we have:\nBe \n\\begin{align}\n\\Phi &= a_{mn}dx^mdx^n\\\\ \n\\end{align}\nand consider the following sequences of terms: \n\\begin{align}\n\\Psi_1 =  b_{11}dx^1+b_{12}dx^2 + b_{13}dx^3+ \\dots +b_{1N}dx^N \\\\\n\\Psi_2 =  b_{21}dx^1+b_{22}dx^2 + b_{23}dx^3+ \\dots +b_{2N}dx^N \n\\end{align}\nThe expressions (3) and (4) contain all the terms of $\\Phi$ with $(dx^1)^2,(dx^2)^2$ and $dx^1dx^2$. So, $\\Phi$ can be expressed as \n\\begin{align}\n\\Phi =\\Psi_1^2 -\\Psi_2^2 + \\Phi_2 \n\\end{align}\nWith $\\Phi_2 $ being a homogeneous form containing only terms in $dx^i dx^j \\quad i,j > 2$.\\\\\nWe can express $\\Psi_1^2 - \\Psi_2^2$ as\n\\begin{align}\n\\Psi_1^2 - \\Psi_2^2 &= \\left \\{ \\begin{array}{l}(b_{11}^2 - b_{21}^2)(dx^1)^2 +(b_{12}^2 - b_{22}^2)(dx^2)^2 +(b_{13}^2 - b_{23}^2)(dx^3 )^2 + \\dots +(b_{1N}^2 - b_{2N}^2)(dx^N)^2 +\\\\\n 2( b_{11} b_{12}-b_{21} b_{22})dx^1dx^2+2( b_{11} b_{13}-b_{21} b_{23})dx^1dx^3+\\dots + 2( b_{11} b_{1N}-b_{21} b_{2N})dx^1dx^N+\\\\\n 2( b_{12} b_{13}-b_{22} b_{23})dx^2dx^3+2( b_{12} b_{14}-b_{22} b_{24})dx^2dx^4+\\dots + 2( b_{12} b_{1N}-b_{21} b_{2N})dx^2dx^N+\\\\\n + \\dots 2( b_{1j} b_{1k}-b_{2j} b_{2k})dx^kdx^j+\\dots\\quad j>2, \\ k\\ne j\n\\end{array} \\right.\n\\end{align}\nEquating the terms in (1) and (6) and taking into account (=given) $a_{11}=a_{22}=0$ and $a_{12} \\ne0$ \n\\begin{align}\n\\ &\\left \\{ \\begin{array}{l}\n b_{11}^2 - b_{21}^2 =0\\\\\n b_{12}^2 - b_{22}^2 =0\\\\\n 2\\left(b_{11}b_{12} - b_{21}b_{22} \\right) = a_{12}+a_{21}\n\\end{array}\\right.\\\\\n\\Rightarrow \\quad \\ &\\left \\{ \\begin{array}{l}\n b_{11}^2 = b_{21}^2 \\\\\n b_{12}^2 = b_{22}^2 \\\\\n \\left(b_{11}b_{12} - b_{21}b_{22} \\right) =a_{12}\n\\end{array}\\right.\\\\\n\\Rightarrow\\quad b_{11} = \\pm b_{21}  &\\quad b_{22} =\\pm b_{12}\\\\ \n\\Rightarrow\\quad  &\\left \\{ \\begin{array}{l} \n \\pm b_{11}b_{22} \\mp b_{11}b_{22}  =a_{12}\\\\ \n\\text{or}\\\\\n\\pm b_{12}b_{21} \\mp b_{12}b_{21}  =a_{12}\n\\end{array}\\right.\\\\\n\\end{align}\nAs $a_{12} \\ne0$, the signs in the above expressions must be the same. Hence,\n\\begin{align}\n&\\left \\{ \\begin{array}{c} \n 2b_{11}b_{22} =\\pm a_{12}\\\\ \n2 b_{12}b_{21} =\\pm a_{12} \n\\end{array}\\right.\n\\end{align}\n(12) can be satisfied with an infinite combination of $b_{11},b_{12},b_{21}, b_{22}$. Choose,\n\\begin{align} \n\\ b_{11} = \\sqrt{\\frac{\\epsilon a_{12}}{2 }}\\quad b_{22} = \\sqrt{\\frac{\\epsilon a_{12}}{2 }}\\quad & b_{12} = \\sqrt{\\frac{\\epsilon a_{12}}{2 }}\\quad b_{21} = - \\sqrt{\\frac{\\epsilon a_{12}}{2 }}\\\\\n\\text{with} \\quad  \\epsilon &= \\pm 1\\quad\\text{so that}\\quad \\epsilon a_{12} \\geq 0\n\\end{align}\nPut $\\xi = \\sqrt{\\frac{\\epsilon a_{12}}{2 }}$. Then, (3) and (4) can be expressed as \n\\begin{align}\n\\Psi_1 =  \\xi dx^1+\\xi dx^2 + b_{13}dx^3+ \\dots +b_{1N}dx^1dx^N \\\\\n\\Psi_2 =  -\\xi dx^1+\\xi dx^2 + b_{23}dx^3+ \\dots +b_{2N}dx^1dx^N \n\\end{align}\nWhat are the $b_{.j}\\quad (j>2)$? \\\\From (6), e.g. for $j=3$,  identifying the terms in $dx^1dx^3$ and $dx^2dx^3$ we see that\n\\begin{align}\n&\\left \\{ \\begin{array}{l} \n \\xi b_{13}+\\xi b_{23} =a_{13}\\\\ \n\\xi b_{13}-\\xi b_{23} =a_{23}\\\\ \n\\end{array}\\right.\\\\\n\\Rightarrow \\quad &\\left \\{ \\begin{array}{l} \n b_{13}=\\frac{a_{13}+a_{23}}{2\\xi}\\\\ \n b_{23}=\\frac{a_{13}-a_{23}}{2\\xi}\n\\end{array}\\right.\\\\\n\\text{or, in general} \\quad &\\left \\{ \\begin{array}{ll} \n b_{1j}=\\frac{a_{1j}+a_{2j}}{2\\xi}\\\\\n \\ &\\ (j>2)\\\\ \n b_{2j}=\\frac{a_{1j}-a_{2j}}{2\\xi}\n\\end{array}\\right.\n\\end{align}\nBring $\\frac{1}{\\xi}$ out in $\\Psi_1, \\Psi_2$. This gives\n\\begin{align}\n\\Psi_1 &= \\frac{1}{\\xi}\\left( \\xi^2( dx^1+ dx^2) + \\frac{a_{13}+a_{23}}{2}dx^3+ \\dots +\\frac{a_{1N}+a_{2N}}{2}dx^N \\right) \\\\\n\\Psi_2 &= \\frac{1}{\\xi}\\left( \\xi^2(- dx^1+ dx^2) + \\frac{a_{13}-a_{23}}{2}dx^3+ \\dots +\\frac{a_{1N}-a_{2N}}{2}dx^N \\right) \\\\\n\\Rightarrow \\quad &\\left \\{ \\begin{array}{l} \n\\Psi_1 = \\frac{\\sqrt{2}}{\\sqrt{\\epsilon a_{12}}}\\left( \\frac{\\epsilon a_{12}}{2 } (dx^1+ dx^2) + \\frac{a_{13}+a_{23}}{2}dx^3+ \\dots +\\frac{a_{1N}+a_{2N}}{2}dx^N \\right) \\\\\\\\\n\\Psi_2 = \\frac{\\sqrt{2}}{\\epsilon\\sqrt{\\epsilon a_{12}}}\\left( \\frac{\\epsilon a_{12}}{2 } (-dx^1+ dx^2) + \\frac{a_{13}-a_{23}}{2}dx^3+ \\dots +\\frac{a_{1N}-a_{2N}}{2}dx^N \\right) \\\\\n\\end{array}\\right.\\\\\n\\Leftrightarrow \\quad &\\left \\{ \\begin{array}{l} \\\\\n\\Psi_1 = \\frac{1}{\\sqrt{2 \\epsilon a_{12}}}\\left(\\epsilon a_{12}(dx^1+ dx^2) + (a_{13}+a_{23})dx^3+ \\dots +(a_{1N}+a_{2N})dx^N \\right) \\\\\\\\\n\\Psi_2 = \\frac{1}{\\sqrt{2 \\epsilon a_{12}}}\\left( \\epsilon a_{12}(- dx^1+ dx^2) + (a_{13}-a_{23})dx^3+ \\dots +(a_{1N}-a_{2N})dx^N \\right) \\\\\n\\end{array}\\right.\n\\end{align}\nWhat about the factor $\\epsilon = \\pm1$ in the terms $\\epsilon a_{12}(dx^1+ dx^2)$ and $\\epsilon a_{12}(-dx^1+ dx^2)$ ? Consider the alternate form\n\\begin{align}\n\\ &\\left \\{ \\begin{array}{l} \\\\\n\\Psi^,_1 = \\frac{1}{\\sqrt{2 \\epsilon a_{12}}}\\left( a_{12}(dx^1+ dx^2) + (a_{13}+a_{23})dx^3+ \\dots +(a_{1N}+a_{2N})dx^N \\right) \\\\\\\\\n\\Psi^,_2 = \\frac{1}{\\sqrt{2 \\epsilon a_{12}}}\\left(  a_{12}(- dx^1+ dx^2) + (a_{13}-a_{23})dx^3+ \\dots +(a_{1N}-a_{2N})dx^N \\right) \\\\\n\\end{array}\\right.\n\\end{align}\nLet's have a look at the terms in $dx^idx^j$ in $\\Psi_1^{,2}-\\Psi^{,2}_2$\\\\\n\\begin{align}\n\\ x_{11}(dx^1)^2+ 2x_{12}dx^1dx^2+x_{22}(dx^2)^2&= \\frac{1}{2 \\epsilon a_{12}}\\left(( a_{12})^2(dx^1 + dx^2)^2 - ( a_{12})^2(-dx^1 + dx^2)^2\\right)  \\\\\n&= \\frac{\\epsilon a_{12}}{2}\\left((dx^1 +  dx^2)^2 - (- dx^1 + dx^2)^2\\right)  \\\\\n&= \\frac{\\epsilon a_{12}}{2}\\left((dx^1)^2 + 2 dx^1dx^2+  (dx^2)^2 - (dx^1)^2 + 2 dx^1dx^2-  (dx^2)^2\\right)  \\\\\n&= 2 \\epsilon a_{12}dx^1dx^2 \\\\\n\\ 2x_{13}dx^1dx^3&= \\frac{1}{2 \\epsilon a_{12}}(2 a_{12}(a_{13}+a_{23})dx^1dx^3 - 2a_{12}(a_{13}-a_{23})dx^1dx^3) \\\\\n\\ &= \\frac{1}{2 \\epsilon a_{12}}(4 a_{12}a_{23})dx^1dx^3 \\\\\n & =  2\\epsilon a_{23}dx^1dx^3\\\\\n \\ 2x_{23}dx^2dx^3&= \\frac{1}{2 \\epsilon a_{12}}(2 a_{12}(a_{13}+a_{23})dx^1dx^3 - 2 a_{12}(a_{13}-a_{23})dx^1dx^3) \\\\\n\\ &= \\frac{1}{2 \\epsilon a_{12}}(4 a_{12}a_{23})dx^1dx^3 \\\\\n & =  2\\epsilon a_{23}dx^1dx^3\\\\\n\\ 2x_{34}dx^3dx^4&=  \\frac{1}{2 \\epsilon a_{12}}\\left(\\begin{array}{l} 2 (a_{13}+ a_{23})(a_{14}+ a_{24}\\\\ - 2 (a_{13}- a_{23})(a_{14}- a_{24}) \\end{array} \\right)dx^3dx^4 \\\\\n\\ &= \\frac{2\\epsilon}{ a_{12}}\\left(a_{23}a_{14}+a_{13}a_{24}\\right)\n\\end{align}\nWe rewrite now the metric form $\\Phi$ as \n$$\\Phi =\\epsilon \\Psi_1^{,2}- \\epsilon \\Psi^{,2}_2 + \\Phi_2 $$\nFrom (28), (31) and (34) we see that the terms in $dx^1, dx^2$ in $\\Phi =\\epsilon \\Psi_1^{,2}- \\epsilon \\Psi^{,2}_2 + \\Phi_2$ correspond to the expected  metric form and that the other terms in $dx^j, dx^k, \\ j,k \\neq 1,2$ can be corrected in the remaining term $\\Phi_2$.\n\\newpage\n\n\\section{p80-exercise 16}\n\\begin{tcolorbox}\nFind the null geodesics of a 4-space with line element\n$$ds^2=\\epsilon \\gamma\\left(dx^2 +dy^2+dz^2-dt^2\\right)$$ where $\\gamma$ is an arbitrary function of $x,\\ y,\\ z,\\ t$.\n\\end{tcolorbox}\nWe have:\n\\begin{align}\n\\left(a_{mn}\\right) = \\gamma\\begin{pmatrix}\n 1&0  & 0 & 0 \\\\\n 0&  1& 0 & 0 \\\\\n 0&0  & 1 &  0\\\\\n 0& 0 & 0 & -1 \\\\\n\\end{pmatrix} \\quad \\left(a^{mn}\\right) = \\frac{1}{\\gamma}\\begin{pmatrix}\n 1&0  & 0 & 0 \\\\\n 0&  1& 0 & 0 \\\\\n 0&0  & 1 &  0\\\\\n 0& 0 & 0 & -1 \\\\\n\\end{pmatrix}\\\\\n\\end{align}\nBe $(x^1,x^2,x^3,x4) \\equiv (x,y,z,t)$.\\\\\nThe general conditions for a null geodesic are\n\\begin{align}\n\\left \\{ \\begin {array}{l}\n\\dv[2]{x^r}{v} + \\Gamma^r_{mn}\\dv{x^m}{v}\\dv{x^n}{v} = 0\\\\\\\\\n\\ a_{mn}dx^mdx^n =0\n\\end{array}\\right.\n\\end{align}\nWhen calculating $[mn,r] = \\half\\left(\\partial_n a_{mr}+\\partial_m a_{nr}-\\partial_r a_{mn} \\right) $ we note that $\\left(a_{mn}\\right)$ is a diagonal matrix, ans so is also $\\left(a^{mn}\\right)$. Hence $\\Gamma^r_{mn}$ will contain only one term:\n\\begin{align}\n\\ & \\Gamma^r_{mn} = a^{RR}[mn,R]\\\\\n\\Rightarrow \\quad & \\left \\{ \\begin{array}{llll}\n\\ i)& m,n \\neq R \\ \\wedge \\ m \\neq n&:& [mn,R]=0\\\\\\\\\n\\ ii)& m \\neq n = R \\ \\vee \\  n \\neq m = R&:& [mn,R]=\\half \\partial_m a_{RR}\\\\\\\\\n\\ iii)& m =n \\neq R &:& [mn,R]=-\\half \\partial_R a_{mn}\\\\\\\\\n\\ iv)& m =n= R &:& [mn,R]=\\half \\partial_R a_{RR}\\\\\\\\\n\\end{array}\\right.\n\\end{align}\\\\\nand for the $\\Gamma^r_{mn}$:\\\\\n\\begin{align}\n\\Rightarrow \\quad & \\left \\{ \\begin{array}{llll}\n\\ i)& m,n \\neq R \\ \\wedge \\ m \\neq n &:& \\Gamma^R_{mn}=0\\\\\\\\\n\\ ii)& m \\neq n = R \\ \\vee \\  n \\neq m = R &:& \\Gamma^R_{nR}=\\frac{1}{2 \\gamma} \\partial_n \\gamma \\\\\\\\\n\\ iii)& m =n \\neq R = \\ 1,2,3 &:& \\Gamma^R_{kk}=-\\frac{1}{2 \\gamma}  \\partial_R \\gamma\\\\\n\\ & m =n \\neq R =4 &:& \\Gamma^4_{kk}=\\frac{1}{2 \\gamma}  \\partial_R \\gamma\\\\\\\\\n\\ iv)& m =n= R &:& \\Gamma^R_{RR}=\\frac{1}{2 \\gamma}  \\partial_R \\gamma\\\\\\\\\n\\end{array}\\right.\n\\end{align}\nLet's compute \n\\begin{align}\n\\ A_r \\equiv \\dv[2]{x^r}{v} + \\Gamma^r_{mn}\\dv{x^m}{v}\\dv{x^n}{v}\n\\end{align}\nand take $v = x^4$, so $x^1, \\  x^2,  \\ x^3 = f(x^4)$. (In the following $d_kx^j \\equiv \\dv{x^j}{{(x^{k})}}\\ , \\ d^2_kx^j \\equiv \\dv[2]{x^j}{{(x^{k})}}$)\n\\begin{align}\n\\left \\{ \\begin{array}{ll}\n\\ A_1 = &  d^2_4x^1+ \\Gamma^1_{mn}d_4x^md_4x^n\\\\\n\\ A_2 = &  d^2_4x^2+ \\Gamma^2_{mn}d_4x^md_4x^n\\\\\n\\ A_3 = &  d^2_4x^3+ \\Gamma^3_{mn}d_4x^md_4x^n\\\\\n\\ A_4 = &   \\Gamma^4_{mn}d_4x^md_4x^n\n\\end{array} \\right.\n\\end{align}\nand get from (8) and (6):\n\\begin{align}\n\\ A_1 -d^2_4x^1 &= \\left \\{ \\begin{array}{l}\\frac{1}{\\gamma}  \\partial_2 \\gamma \\ d_4x^1d_4x^2  + \\frac{1}{\\gamma}  \\partial_3 \\gamma \\ d_4x^1 d_4x^3+\\frac{1}{\\gamma}  \\partial_4 \\gamma \\ d_4x^1 d_4x^4\\\\\\\\\n\\ + \\underbrace{\\frac{1}{2\\gamma}\\partial_1 \\gamma (d_4x^1)^2}_{= \\left \\{ \\begin{array}{l} \\frac{1}{\\gamma} \\partial_1 \\gamma (d_4x^1) (d_4x^1)\\\\\n\\  - \\frac{1}{2\\gamma} \\partial_1 \\gamma (d_4x^1)^2 \\end{array} \\right.} - \\frac{1}{2\\gamma}\\partial_1 \\gamma (d_4x^2)^2- \\frac{1}{2\\gamma}\\partial_1 \\gamma (d_4x^3)^2+ \\frac{1}{2\\gamma}\\partial_1 \\gamma (d_4x^4)^2\n \\end{array} \\right.\\\\\n &= \\left \\{ \\begin{array}{l}\\frac{1}{\\gamma} \\partial_1 \\gamma d_4x^1 d_4x^1 + \\frac{1}{\\gamma}  \\partial_2 \\gamma \\ d_4x^1d_4x^2  + \\frac{1}{\\gamma}  \\partial_3 \\gamma \\ d_4x^1 d_4x^3+\\frac{1}{\\gamma}  \\partial_4 \\gamma \\ d_4x^1 d_4x^4\\\\\\\\\n\\ - \\frac{1}{2\\gamma}\\partial_1 \\gamma (d_4x^1)^2 - \\frac{1}{2\\gamma}\\partial_1 \\gamma (d_4x^2)^2- \\frac{1}{2\\gamma}\\partial_1 \\gamma (d_4x^3)^2+ \\frac{1}{2\\gamma}\\partial_1 \\gamma (d_4x^4)^2\n \\end{array} \\right.\\\\\\\\\n  &= \\left \\{ \\begin{array}{l}\\frac{1}{\\gamma}d_4x^1 \\left(\\partial_1 \\gamma  d_4x^1  + \\partial_2 \\gamma \\ d_4x^2  + \\partial_3 \\gamma \\  d_4x^3+ \\partial_4 \\gamma \\ d_4x^4 \\right)\\\\\\\\\n\\ - \\frac{1}{2\\gamma}\\partial_1 \\gamma \\left(\\underbrace{(d_4x^1)^2 +(d_4x^2)^2+(d_4x^3)^2- (d_4x^4)^2}_{= a_{mn}dx^m dx^n = 0 }\\right)\n \\end{array} \\right.\\\\\n \\Rightarrow \\quad A_1 &= d^2_4x^1+ \\frac{1}{\\gamma}d_4x^1 < \\grad \\gamma|\\partial_4 \\overline{x} >\n\\end{align}\nwith $\\grad \\gamma =  (\\partial_x \\gamma,\\ \\partial_y \\gamma, \\ \\partial_z \\gamma, \\ \\partial_t \\gamma)$ and $ \\partial_4 \\overline{x} =  (\\partial_t x, \\ \\partial_t y , \\ \\partial_t z, \\ \\partial_t t)$.\\\\\nSo for the geodesic with get for the first coordinate $$d^2_4x^1+ \\frac{1}{\\gamma}d_4x^1 < \\grad \\gamma|\\partial_4 \\overline{x} > = 0 $$\nDoing analogous calculations give the following set of equations\n\\begin{align}\n\\ d^2_4x^k+ \\frac{1}{\\gamma}d_4x^k < \\grad \\gamma|\\partial_4 \\overline{x} > = 0 \n\\end{align}\nNote that for $k=4$ we have as $\\ d_4x^4 = 1$ and $\\ d^2_4x^4 = 0$:\n\\begin{align}\n \\frac{1}{\\gamma}< \\grad \\gamma|\\partial_4 \\overline{x} > = 0 \\\\\n \\Rightarrow \\quad < \\grad \\gamma|\\partial_4 \\overline{x} > = 0 \n\\end{align}\nNote that this means that $\\grad \\gamma$ and $\\partial_4 \\overline{x}$ are orthogonal 4-vectors.\\\\\nSo the set of equations in (14) reduce to the following set of $2^{nd}$ order differential equations:\n\\begin{align}\n\\ & \\left  \\{ \\begin{array}{l}\n\\ x^{,,} = 0\\\\\n\\ y^{,,} = 0\\\\\n\\ z^{,,} = 0\\\\\n\\ t = t\\\\\n\\end{array} \\right.\n\\Rightarrow  \\left  \\{ \\begin{array}{l}\n\\ x = x_1t+x_0\\\\\n\\ y =y_1t+y_0\\\\\n\\ z = z_1t+z_0\\\\\n\\ t = t\\\\\n\\end{array} \\right.\n\\end{align}\nThis is the equations of 4-space cone, which was expected as the metric is localy a Minkowksi-like metric. \n$$\\blacklozenge$$\n\\newpage\n\n\\section{p80-exercise 17}\n\\begin{tcolorbox}\nIn a space $V_N$ the metric tensor is $a_{mn}$. Show that the null geodesics are unchanged if the metric tensor is changed to $b_{mn} = \\gamma a_{mn} $, $\\gamma$ being a function of the coordinates.\n\\end{tcolorbox}\nNull geodesics are determined by the following set of equations\n\\begin{align}\n\\ & \\left \\{  \\begin {array}{l}\n\\dv[2]{x^r}{v} + \\Gamma^r_{mn}\\dv{x^m}{v}\\dv{x^n}{v} = 0\\\\\\\\\n\\ a_{mn}dx^mdx^n =0\n\\end{array}\\right.\\\\\n\\text{We have}\\quad  \\Gamma^r_{mn} & = a^{rs}[mn,s]\\\\\n\\ & = \\frac{1}{\\gamma}a^{rs}\\gamma[mn,s]\\\\\n\\text{We have also }\\quad  b^{rs} & = \\frac{1}{\\gamma}a^{rs}\\\\\n\\text{Indeed }\\quad  a^{rs}a_{rs}&= \\delta^r_t\\\\\n\\Rightarrow\\quad  \\frac{1}{\\gamma}a^{rs}\\gamma a_{rs}&= \\delta^r_t\\\\\n\\Rightarrow\\quad  \\frac{1}{\\gamma}a^{rs}b_{rs}&= \\delta^r_t\\\\\n\\Rightarrow\\quad  \\frac{1}{\\gamma}a^{rs} &= b_{rs}\\\\\n\\text{So (3) becomes}\\quad  \\Gamma^r_{mn} & =b^{rs}\\gamma[mn,s]\n\\end{align}\nBe $ [mn,s]^{'} $ the Christoffel symbol associated with the metric $b_{mn}= \\gamma a_{mn}$. Then with  $$[mn,s]^, = \\half \\left(\\partial_n \\gamma a_{ms}+\\partial_m \\gamma a_{ns}-\\partial_s \\gamma a_{mn} \\right)$$ we get\n\\begin{align}\n\\ [mn,s]^{'} &= \\gamma [mn,s] + \\half\\left( a_{ms}\\partial_n \\gamma+a_{ns}\\partial_m \\gamma-a_{mn}\\partial_s \\gamma \\right)\n\\end{align}\nSubstitute $\\gamma [mn,s]$ from (10) in (9) we get\n\\begin{align}\n\\Gamma^r_{mn} & =\\underbrace{b^{rs}\\gamma[mn,s]^,}_{=\\Gamma^{'r}_{mn}}  - \\underbrace{\\half b^{rs}\\left( a_{ms}\\partial_n \\gamma+a_{ns}\\partial_m \\gamma-a_{mn}\\partial_s \\gamma \\right)}_{\\coloneqq Q}\\\\\n\\text{with}\\quad Q &= \\half b^{rs}\\left( a_{ms}\\partial_n \\gamma+a_{ns}\\partial_m \\gamma-a_{mn}\\partial_s \\gamma \\right)\\\\\n&= \\half \\gamma \\left( \\underbrace{a^{rs}a_{ms}}_{ = \\delta^r_m}\\partial_n \\gamma+\\underbrace{a^{rs}a_{ns}}_{ = \\delta^r_n}\\partial_m \\gamma-a^{rs}a_{mn}\\partial_s \\gamma \\right)\\\\\n\\ Q \\times \\dv{x^m}{v}\\dv{x^n}{v} &= \\half \\gamma \\left( \\underbrace{\\delta^r_m\\dv{x^m}{v}}_{=\\dv{x^r}{v}} \\underbrace{\\partial_n \\gamma \\dv{x^n}{v}}_{= \\dv{\\gamma}{v}}+\\underbrace{\\delta^r_n\\dv{x^n}{v}}_{=\\dv{x^r}{v}}\\underbrace{\\partial_m \\gamma\\dv{x^m}{v}}_{= \\dv{\\gamma}{v}}-a^{rs}\\partial_s \\gamma \\underbrace{a_{mn}\\dv{x^m}{v}\\dv{x^n}{v}}_{ = 0 \\ \\text{by(1)}} \\right)\\\\\n&= \\half \\gamma \\left( \\dv{x^r}{v}\\dv{\\gamma}{v} +\\dv{x^r}{v}\\dv{\\gamma}{v} \\right)\\\\\n&= \\left(\\gamma\\dv{\\gamma}{v} \\right)  \\dv{x^r}{v}\n\\end{align}\nSo from (11) and (16), (1) can be expressed as \n\\begin{align}\n\\dv[2]{x^r}{v} + \\Gamma^{'r}_{mn}\\dv{x^m}{v}\\dv{x^n}{v} = \\left(\\gamma\\dv{\\gamma}{v} \\right)  \\dv{x^r}{v}\n\\end{align}\nBy (2.449) page 46 we see that the vector \n$\\dv[2]{x^r}{v} + \\Gamma^{'r}_{mn}\\dv{x^m}{v}\\dv{x^n}{v}$ is collinear to $\\dv{x^r}{v}$. Also $b_{mn}\\dv{x^m}{v}\\dv{x^n}{v} = 0$. And hence (17) determines the geodesic null lines. So both expressions (1) and (17) are equivalent to determine the same geodesic null lines in the space $V_N$ equipped with the metric $a_{mn}$ or  $b_{mn}$\n$$\\blacklozenge$$\n\\newpage\n\n\n\\section{p80-exercise 18}\n\\begin{tcolorbox}\nAre the relations $$T_{|rs} =T_{|sr} $$ $$T_{r|sk} =T_{r|ks} $$ true (a) in curvilinear coordinates in Euclidean space, (b) in a general Riemannian space?\n\\end{tcolorbox}\n$$\\boldsymbol{T_{|rs} \\questeq  T_{|sr}}$$\nWe have $T|_r = \\partial_rT$ (see (2.528) page 53) \\\\\n\\begin{equation}\n  \\begin{split}\n  \\ & \\boldsymbol{T_{|rs}}\\\\\\\\\n   \\ & T|_{rs} = \\partial^2_{rs}T - \\Gamma^m_{rs}T|_m\n  \\end{split}\n\\quad\\leftrightarrow\\quad\n  \\begin{split}\n \\ & \\boldsymbol{T_{|sr}}\\\\\\\\\n   \\ & T|_{sr} = \\partial^2_{sr}T - \\Gamma^m_{sr}T|_m\n  \\end{split}\n\\end{equation}\nAs $\\partial^2_{rs} =\\partial^2_{sr}$ and $\\Gamma^m_{rs} =\\Gamma^m_{sr}$ we can conclude that $\\boldsymbol{T_{|rs} =T_{|sr}}$ in both cases (a) and (b).\\\\\\\\\n$$\\boldsymbol{\\diamond}$$\\\\\\\\\n$$\\boldsymbol{T_{r|sk} \\questeq  T_{r|ks}}$$\n\\begin{equation}\n  \\begin{split}\n  \\ & \\boldsymbol{T_{r|sk}}\\\\\\\\\n  \\ & A_{rs} \\coloneqq T_{r|s} = \\partial_{s}T_r - \\Gamma^m_{rs}T_m\\\\\n  \\ & A_{rs|k}= \\partial_k A_{rs} - \\Gamma^m_{rk}A_{ms} -  \\Gamma^m_{sk}A_{rm}\\\\\n  \\ & A_{ms}=  \\partial_{s}T_m - \\Gamma^n_{ms}T_n\\\\\n  \\ & A_{rm} = \\partial_{m}T_r - \\Gamma^n_{rm}T_n\\\\\n  \\ & A_{rs|k}= \\left \\{\\begin{array}{l}\n   \\underbrace{\\partial^2_{sk}T_r}_{*} - T_m\\partial_{k}\\Gamma^m_{rs} - \\underbrace{\\Gamma^m_{rs}\\partial_{k}T_m}_{**} \\\\\\\\\n   \\ -\\underbrace{\\Gamma^m_{rk}\\partial_{s}T_m}_{***} +\\Gamma^m_{rk} \\Gamma^n_{ms}T_n \\\\\\\\\n   \\ - \\underbrace{\\Gamma^m_{sk}\\partial_{m}T_r}_{****} +\\underbrace{\\Gamma^m_{sk} \\Gamma^n_{rm}T_n}_{*****}\n  \\end{array}\\right.\n  \\end{split}\n\\quad\\leftrightarrow\\quad\n  \\begin{split}\n \\ & \\boldsymbol{T_{r|sk}}\\\\\\\\\n  \\ & B_{rk} \\coloneqq T_{r|k} = \\partial_{k}T_r - \\Gamma^m_{rk}T_m\\\\\n  \\ & B_{rk|s}= \\partial_s B_{rk} - \\Gamma^m_{rs}B_{mk} -  \\Gamma^m_{ks}B_{rm}\\\\\n  \\ & B_{mk}=  \\partial_{k}T_m - \\Gamma^n_{mk}T_n\\\\\n  \\ & B_{rm}=  \\partial_{m}T_r - \\Gamma^n_{rm}T_n\\\\\n  \\ & B_{rk|s}= \\left \\{\\begin{array}{l}\n  \\underbrace{\\partial^2_{ks}T_r}_{*} - T_m\\partial_{s}\\Gamma^m_{rk} - \\underbrace{\\Gamma^m_{rk}\\partial_{s}T_m}_{***} \\\\\\\\\n   \\ -\\underbrace{\\Gamma^m_{rs}\\partial_{k}T_m}_{**} +\\Gamma^m_{rs} \\Gamma^n_{mk}T_n \\\\\\\\\n   \\ - \\underbrace{\\Gamma^m_{ks}\\partial_{m}T_r}_{****} +\\underbrace{\\Gamma^m_{ks} \\Gamma^n_{rm}T_n}_{*****}\n  \\end{array}\\right.\n  \\end{split}\n\\end{equation}\\begin{align}\n\\Rightarrow\\quad A_{rs|k} - B_{rk|s} &= T_m\\left( \\underbrace{\\partial_{s}\\Gamma^m_{rk}-\\partial_{k}\\Gamma^m_{rs}+\\Gamma^n_{rk} \\Gamma^m_{ns}- \\Gamma^n_{rs} \\Gamma^m_{nk} }_{\\coloneqq R^s{.rmn}}\\right) \n\\end{align}\nSo, $T_{r|sk} =  T_{r|ks}$ only if $T_m R^s_{.rmn} = 0$ and as $T_m$ is an arbitrary tensor, $R^s_{.rmn}$ must vanish for $T_{r|sk} =  T_{r|ks}$.\\\\\\\\\n$\\textbf{Note:}$\\\\\nAlthough $\\Gamma^n_{rk}$ is not a tensor, the quantity $R^s_{.rmn}$ is. Indeed, as both $A_{rs|k} - B_{rk|s}$ and $ T_m$ have the tensor character, this implies that $R^s_{.rmn}$ is a tensor.\nNow, for an Euclidean space equipped with Cartesian coordinates all $\\Gamma^n_{rk} $ are constant and vanish. So, $R^s_{.rmn}$ = 0. Let's consider a change of coordinate system from Cartesian to curvilinear coordinate system. Then, by the tensor character of $R^{'a}_{\\ .bcd}$ we have,\n\\begin{align}\n\\ R^{'a}_{\\ .bcd} = R^s_{.rmn}\\partial_s x^{'a} \\partial_{('b)} x^{r} \\partial_{('c)} x^{m} \\partial_{('d)} x^{n}\n\\end{align}\nbut $R^s_{.rmn} =0$ in the Cartesian coordinate system and so is $R^{'a}_{\\ .bcd}$\\\\\n$\\textbf{Conclusion:}$\\\\\nIn a general Riemannian space $T_{r|sk} \\neq  T_{r|ks}$ but $T_{r|sk} =  T_{r|ks}$ in a curvilinear Euclidean space.\n$$\\blacklozenge$$\n\\newpage\n\n\\section{p80-exercise 19}\n\\begin{tcolorbox}\nConsider a $V_N$ with indefinite metric form. For all points $P$ lying on the cone of  geodesic null lines drawn from  $O$, the definition 2.611 for Riemannian coordinates apparently breaks down. Revise the definition of Riemannian coordinates so as to include such points.\n\\end{tcolorbox}\nFor geodesic null lines we have (2.445 page 46)\n\\begin{align}\n\\left \\{ \\begin{array}{l}\n\\dv[2]{x^r}{u} + \\Gamma^r_{mn}\\dv{x^m}{u}\\dv{x^n}{u} = 0\\\\\n\\ a_{mn}\\dv{x^m}{u}\\dv{x^n}{u} = 0\n\\end{array}\\right.\n\\end{align}\nor (2.448 page 46)\n\\begin{align}\n\\left \\{ \\begin{array}{l}\n\\dv[2]{x^r}{v} + \\Gamma^r_{mn}\\dv{x^m}{v}\\dv{x^n}{v} = \\lambda(v) \\dv{x^r}{v}\\\\\n\\ a_{mn}\\dv{x^m}{v}\\dv{x^n}{v} = 0\n\\end{array}\\right.\n\\end{align}\nwhere by suitable choice of the parameter $v$ , $\\lambda(v) $ can be made any preassigned function of $v$.\n\\begin{align}\n\\text{(2)} \\RAr \\dv[2]{x^r}{v} &=   \\lambda \\dv{x^r}{v}-\\Gamma^r_{mn}\\dv{x^m}{v}\\dv{x^n}{v} \\\\\n\\RAr \\dv[3]{x^r}{v} &=   \\dv{\\lambda }{v}\\dv{x^r}{v}+ \\lambda \\dv[2]{x^r}{v}+ A^r_{.mns}\\dv{x^m}{v}\\dv{x^n}{v}\\dv{x^s}{v} \\\\\n\\text{with}\\RAr A^r_{.mns} &= - \\partial_s \\Gamma^r_{mn} + 2 \\Gamma^r_{sp}\\Gamma^p_{mn}\n\\end{align}\nExpanding $x^r$ in a Taylor series around a point $O(a^r)$ we get (for ease of notation we put $p^r \\coloneqq \\dv{x^r}{v}$)\n\\begin{align}\n\\ x^r &= a^r + v p^r + \\half v^2\\lambda  p^r -  \\half v^2\\Gamma^r_{mn}p^mp^n+\\frac{1}{6}v^3\\dv{\\lambda  }{v}p^r + \\frac{1}{6}v^3\\lambda  \\dv{p^r}{v} + \\frac{1}{6}v^3A^r_{.mns}p^mp^np^s+\\dots\\\\\n&= a^r + \\left(v  + \\half v^2\\lambda  +\\frac{1}{6}v^3\\dv{\\lambda  }{v}\\right)p^r -  \\half v^2\\Gamma^r_{mn}p^mp^n + \\frac{1}{6}v^3\\lambda  \\dv{p^r}{v} + \\frac{1}{6}v^3A^r_{.mns}p^mp^np^s+\\dots\n\\end{align}\nPut $x^{'r} \\coloneqq   v\\xi(v) p^r$ with $\\xi(v) = \\left(1  + \\half v\\lambda  +\\frac{1}{6}v^2\\dv{\\lambda  }{v}\\right)$. Hence (7) becomes\n\\begin{align}\n\\ x^r &= a^r + x^{'r} + \\frac{\\lambda v^3}{6}  \\left( \\frac{p^{'r}}{v\\xi} - \\frac{\\xi + v\\xi^{'}}{v^2\\xi^2}x^{'r}\\right)  -  \\frac{\\Gamma^r_{mn}}{2\\xi ^2}x^{'m}x^{'n} + \\frac{A^r_{.mns}}{6\\xi ^3}x^{'m}x^{'n}x^{'s}+\\dots\\\\\n\\ & = a^r + \\tau(v) x^{'r}+ \\frac{\\lambda v^2 }{6\\xi}p^{'r} -  \\frac{\\Gamma^r_{mn}}{2\\xi ^2}x^{'m}x^{'n}   + \\frac{A^r_{.mns}}{6\\xi ^3}x^{'m}x^{'n}x^{'s}+\\dots\\\\\n\\text{with}\\spatie & \\tau(v)  \\coloneqq 1-\\frac{\\lambda v}{6\\xi^2}\\left( \\xi + v\\xi^{,}\\right)\n\\end{align}\\\\\nIs the Jacobian non-zero?\n\\begin{align}\n\\pdv{x^r}{x^{'q}}  & = \\tau\\delta^r_q+ \\frac{\\lambda  v^2}{6\\xi}\\dv{\\delta^r_q}{v} -  \\frac{\\Gamma^r_{mq}}{\\xi ^2}x^{'m}   + \\frac{A^r_{.mnq}}{2\\xi ^3}x^{'m}x^{'n}+\\dots\n\\end{align}\nIn the infinitesimal neighbourhood of $O$ we have \\\\\n\\begin{align}\\left \\{ \\begin{array}{l} \nv \\rightarrow 0\\\\  \n\\xi \\rightarrow 1\\\\\n\\xi^{'} \\rightarrow \\frac{\\lambda }{2}\\\\ \nx^{'m} \\rightarrow 0\\\\\n\\tau \\rightarrow 1 \n\\end{array} \\right.\\\\\n\\end{align}\nso that the Jacobian determinant becomes\n\\begin{align}\n\\left| \\pdv{x^r}{x^{'q}} \\right| &= \\left| \\tau\\delta^r_q \\right| =\\tau ^N = 1\n\\end{align}\n$\\textbf{Conclusion:}$\\\\\nSo in order to define a Riemannian coordinates system which is still valid on the null geodesics, it is sufficient to define the Riemannian coordinates around $O$ as $$ x^{'r} \\coloneqq   v\\xi p^r$$ with $$\\xi(v) = \\left(1  + \\frac{\\lambda}{2} v +\\frac{1}{6}\\dv{\\lambda }{v} v^2\\right) $$\nand $\\lambda $, by suitable choice of $v$, being any pre-defined function of $v$.\n$$\\blacklozenge$$\n\\newpage\n", "meta": {"hexsha": "022e2a41784f1370bad69c186e3207154129b49f", "size": 135235, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter2.tex", "max_stars_repo_name": "Niohori/Synge-Tensor-Calculus", "max_stars_repo_head_hexsha": "a11e45d9d8c4f78b9e9504391b532bb4f0d0587f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter2.tex", "max_issues_repo_name": "Niohori/Synge-Tensor-Calculus", "max_issues_repo_head_hexsha": "a11e45d9d8c4f78b9e9504391b532bb4f0d0587f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter2.tex", "max_forks_repo_name": "Niohori/Synge-Tensor-Calculus", "max_forks_repo_head_hexsha": "a11e45d9d8c4f78b9e9504391b532bb4f0d0587f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.1589907889, "max_line_length": 1487, "alphanum_fraction": 0.6027137945, "num_tokens": 59542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.7305566135091479}}
{"text": "\\documentclass{tufte-handout}\n\n\\usepackage{xcolor}\n\\usepackage{graphicx}\n\n% set hyperlink attributes\n\\hypersetup{colorlinks}\n\n\\usepackage{amsmath}\n\n% set image attributes:\n\\usepackage{graphicx}\n\\graphicspath{ {images/} }\n\n% create environment for bottom paragraph:\n\\newenvironment{bottompar}{\\par\\vspace*{\\fill}}{\\clearpage}\n\n% ============================================================\n\n% define the title\n\\title{SOC 4930/5050: Week 06 Equations Quick \\\\Reference}\n\\author{Christopher Prener, Ph.D.}\n\\date{October 2\\textsuperscript{nd}, 2017}\n% ============================================================\n\\begin{document}\n% ============================================================\n\\maketitle % generates the title\n% ============================================================\n\n\\vspace{5mm}\n\\section{Standard Error}\n\\begin{equation}\n\\scalebox{2} {$ { \\sigma }_{ \\bar{ X } } = \\frac{ {\\sigma}_{x} }{ \\sqrt{ n } } $}\n\\end{equation}\n\n\\vspace{5mm}\n\\section{Z-Score for Sample Means}\n\\begin{equation}\n\\scalebox{2} {$ z = \\frac{\\bar{x}-\\mu}{\\frac{\\sigma}{\\sqrt{n}}} $}\n\\end{equation}\n\n\\vspace{5mm}\n\\section{Simple Power Analysis}\\marginnote{Use any of the two-tailed critical values' z-scores depending on how wide you want your interval.}\n\\begin{equation}\n\\scalebox{2} {$ \\left( \\frac{1.96\\sigma}{\\Delta} \\right)^{2} $}\n\\end{equation}\n\n\\vspace{5mm}\n\\section{Predictive Interval}\\marginnote{Use any of the two-tailed critical values' z-scores depending on how wide you want your interval.}\n\\begin{equation}\n\\scalebox{2} {$ \\left(\\mu-1.96\\sigma, \\mu+1.96\\sigma \\right)  $}\n\\end{equation}\n\n\\vspace{5mm}\n\\section{Predictive Interval for Sample Mean}\\marginnote{Use any of the two-tailed critical values' z-scores depending on how wide you want your interval.}\n\\begin{equation}\n\\scalebox{2} {$ \\left(\\mu-1.96\\frac{\\sigma}{\\sqrt{n}}, \\mu+1.96\\frac{\\sigma}{\\sqrt{n}}  \\right) $}\n\\end{equation}\n\n\n\\vspace{5mm}\n\\section{Confidence Interval for Sample Mean}\\marginnote{Use any of the two-tailed critical values' z-scores depending on how wide you want your interval.}\n\\begin{equation}\n\\scalebox{2} {$ \\left(\\bar{x}-1.96\\frac{\\sigma}{\\sqrt{n}}, \\bar{x}+1.96\\frac{\\sigma}{\\sqrt{n}}  \\right) $}\n\\end{equation}\n\n\n% ============================================================\n\\end{document}", "meta": {"hexsha": "d3282232cc36028cf744313ebf0d1fc3ce0e220f", "size": 2279, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week-06-equations.tex", "max_stars_repo_name": "slu-soc5050/Equations", "max_stars_repo_head_hexsha": "6398ba3a3d351d95a37d3245fcc6eabb91fdd032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week-06-equations.tex", "max_issues_repo_name": "slu-soc5050/Equations", "max_issues_repo_head_hexsha": "6398ba3a3d351d95a37d3245fcc6eabb91fdd032", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week-06-equations.tex", "max_forks_repo_name": "slu-soc5050/Equations", "max_forks_repo_head_hexsha": "6398ba3a3d351d95a37d3245fcc6eabb91fdd032", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.0289855072, "max_line_length": 155, "alphanum_fraction": 0.6156208864, "num_tokens": 664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424528443251, "lm_q2_score": 0.8633916064587, "lm_q1q2_score": 0.7303796133328749}}
{"text": "\\chapter{Growth of Functions}\n\n\\section{Asymptotic notation}\n\n\\begin{enumerate}\n\n\\item[3.1{-}1]{Let $f(n)$ and $g(n)$ be asymptotically nonnegative functions.\n  Using the basic definition of $\\Theta$-notation, prove that\n  $\\max(f(n), g(n)) = \\Theta(f(n) + g(n))$.}\n\n\\begin{framed}\nSince $f(n)$ and $g(n)$ are both asymptotically nonnegative,\n\\[\n\\Exists n_0 \\mid f(n) \\ge 0\\;g(n) \\ge 0\\;\\Forall n \\ge n_0.\n\\]\n\nFrom the definition of $\\Theta(\\cdot)$, we have\n\\[\n\\Exists c_1\\;c_2\\;n_0\\in\\mathbb{R}^+ \\mid\nc_1 f(n) + c_1 g(n) \\le \\max(f(n), g(n)) \\le c_2 f(n) + c_2 g(n)\\;\n\\Forall n \\ge n_0.\n\\]\n\nIf $f(n) \\ge g(n)$, we have\n\\[\nc_1 f(n) + c_1 g(n) \\le f(n) \\le c_2 f(n) + c_2 g(n).\n\\]\n\n\nThe right-hand-side inequality is trivially satisfied with $c_2 = 1$. To find\n\\(c_1\\), we notice that,\n\\[\nf(n) + g(n) \\le 2f(n),\n\\]\n\nand say,\n\\[\nc_1 = \\frac{1}{2}.\n\\]\n\nThe demonstration is similar for $g(n) > f(n)$, with $c_1 = 1/2$ and $c_2 = 1$.\n\\end{framed}\n\n\\item[3.1{-}2]{Show that for any real constants $a$ and $b$, where\n$b > 0$, $(n + a)^b = \\Theta(n^b)$.}\n\n\\begin{framed}\nFrom the definition of \\(\\Theta(\\cdot)\\), we have\n\\[\n\\Exists c_1\\;c_2\\;n_0\\in\\mathbb{R}^+ \\mid c_1 n^b \\leq (n+a)^b \\leq c_2 n^b\\;\n\\Forall n \\ge n_0,\n\\]\n\nand from the binomial theorem, we have\n\\[\n(n + a)^b = \\binom{b}{0} n^b a^0 + \\binom{b}{1} n^{b - 1} a^1 + \\cdots +\n            \\binom{b}{b - 1} n^1 a^{b - 1} + \\binom{b}{b} n^0 a^b.\n\\]\n\nTo find \\(c_1\\), we notice that for $n$ big enough,\n\\[\n\\binom{b}{i} n^{b - i} a^i + \\binom{b}{i + 1} n^{b - (i + 1)} a^{i + 1} \\ge 0\n\\quad \\forall\\ i \\in 0, 2, \\dots ,b,\n\\]\n\nwhich implies\n\\[\n\\binom{b}{0} n^b a^0 + \\binom{b}{1} n^{b - 1} a^1 \\le (n + a)^b,\n\\]\n\nand also for $n$ big enough,\n\n\\[\n\\frac{n^b}{2} \\le n^b + \\binom{b}{1} n^{b - 1} a^1,\n\\]\n\nwhich implies\n\\[\n\\frac{n^b}{2} \\le (n + a)^b,\n\\]\n\nand say\n\\[\nc_2 = \\frac{1}{2}.\n\\]\n\nTo find \\(c_2\\), we notice that for $n$ big enough,\n\\[\nn^b = \\binom{b}{0} n^b a^0\n\\geq \\binom{b}{i} n^{b - i} a^i \\quad \\forall\\ i \\in 1, \\dots ,b,\n\\]\nwhich implies\n\\[\n(n + a)^b \\leq (b + 1) n^b,\n\\]\n\nand say\n\\[\nc_2 = b + 1.\n\\]\n\\end{framed}\n\n\\item[3.1{-}3]{Explain why the statement, ``The running time of algorithm $A$ is\n  at least $O(n^2)$,'' is meaningless.}\n\n\\begin{framed}\nBecause the $O$-notation only bounds from the top, not from the bottom.\n\\end{framed}\n\n\\item[3.1{-}4]{Is $2^{n+1} = O(2^n)$? Is $2^{2n} = O(2^n)$?}\n\n\\begin{framed}\nFrom the definition of $O(\\cdot)$, we have\n\\[\n\\Exists c\\;n_0\\in\\mathbb{R}^+ \\mid 0 \\leq 2^{n+1} \\leq c \\cdot 2^n\\;\n\\Forall n \\ge n_0.\n\\]\n\nTo find $c$, we notice that,\n\\[\n2^{n+1} = 2 \\cdot 2^n,\n\\]\n\nand say $c = 2$ and $n_0 = 0$.\n\nFrom the definition of $O(\\cdot)$, we have\n\\[\n\\Exists c\\;n_0\\in\\mathbb{R}^+ \\mid 0 \\leq 2^{2n} \\leq c \\cdot 2^n\\;\n\\Forall n \\ge n_0.\n\\]\n\nTo show that $2^{2n} \\neq O(2^n)$, we notice that,\n\\[\n2^{2n} = 2^n \\cdot 2^n,\n\\]\n\nwhich implies\n\\[\nc \\ge 2^n,\n\\]\nwhich is not possible, since $c$ is a constant and $n$ is not.\n\\end{framed}\n\n\\item[3.1{-}5]{Prove Theorem 3.1.}\n\n\\begin{framed}\nTo prove\n\\[\nf(n) = \\Theta(g(n)) \\iff f(n) = O(g(n)) \\wedge f(n) = \\Omega(g(n)).\n\\]\n\nwe need to show\n\\[\nf(n) = O(g(n)) \\wedge f(n) = \\Omega(g(n)) \\rightarrow f(n) = \\Theta(g(n)),\n\\]\n\nand\n\\[\nf(n) = \\Theta(g(n)) \\rightarrow f(n) = O(g(n)) \\wedge f(n) = \\Omega(g(n)).\n\\]\n\nFrom the definition of $O(\\cdot)$, we have\n\\[\n\\Exists c_1\\;n_1\\in\\mathbb{R}^+ \\mid 0 \\le f(n) \\le c_1g(n)\\;\\Forall n \\ge n_1,\n\\]\n\nand from the definition of $\\Omega(\\cdot)$, we have\n\\[\n\\Exists c_2\\;n_2\\in\\mathbb{R}^+ \\mid 0 \\le c_2g(n) \\le f(n)\\;\\Forall n \\ge n_2,\n\\]\n\nwhich implies\n\\[\n\\Exists c_1\\;c_2\\in\\mathbb{R}^+\\;n_0 = \\max(n_1, n_2) \\mid\nc_2g(n) \\leq f(n) \\leq c_1g(n)\\;\\Forall n \\ge n_0 \\iff f(n) = \\Theta(g(n)).\n\\]\n\nFrom the definition of $\\Theta(\\cdot)$, we have\n\\[\n\\Exists c_1\\;c_2\\;n_0\\in\\mathbb{R}^+ \\mid c_2g(n) \\leq f(n) \\leq c_1g(n)\\;\n\\Forall n \\ge n_0,\n\\]\n\nwhich implies\n\\[\n\\Exists c_1\\;n_0\\in\\mathbb{R}^+ \\mid 0 \\leq f(n) \\leq c_1 g(n)\\;\n\\Forall n \\ge n_0 \\iff f(n) = O(g(n)),\n\\]\n\n\\[\n\\Exists c_2\\;n_0\\in\\mathbb{R}^+ \\mid c_2 g(n) \\leq f(n) \\leq 0\\;\n\\Forall n \\ge n_0 \\iff f(n) = \\Omega(g(n)).\n\\]\n\n\\end{framed}\n\n\\newpage\n\n\\item[3.1{-}6]{Prove that the running time of an algorithm is $\\Theta(g(n))$ if\n  and only if its worst-case running time is $O(g(n))$ and its best-case running\n  time is $\\Omega(g(n))$.}\n\n\\begin{framed}\nLet $f_b(n)$ and $f_w(n)$ be the best and worst-case running times of algorithm\n$A$, respectivelly.\n\nIf the running time of $A$ is $\\Theta(g(n))$, we have\n\\[\nf_b(n) = \\Theta(g(n)),\n\\]\n\nand\n\\[\nf_w(n) = \\Theta(g(n)).\n\\]\n\nFrom Theorem 3.1,\n\\[\nf_b(n) = \\Theta(g(n)) \\iff f_b(n) = O(g(n)) \\wedge f_b(n) = \\Omega(g(n)),\n\\]\n\nand\n\\[\nf_w(n) = \\Theta(g(n)) \\iff f_w(n) = O(g(n)) \\wedge f_w(n) = \\Omega(g(n)).\n\\]\n\n\\end{framed}\n\n\\item[3.1{-}7]{Prove that $o(g(n)) \\cap \\omega(g(n))$ is the empty set.}\n\n\\begin{framed}\nFrom the definition of $o(\\cdot)$, we have\n\\[\no(g(n)) = \\{ f(n) : \\Forall c_1 > 0\\;\\Exists n_1 \\in \\mathbb{R}^+ \\mid\n             0 \\le f(n) < c_1g(n)\\;\\Forall n \\ge n_1 \\},\n\\]\n\nand from the definition of $\\omega(\\cdot)$, we have\n\\[\n\\omega(g(n)) = \\{ f(n) : \\Forall c_2 > 0\\;\\Exists n_2\\in\\mathbb{R}^+ \\mid\n                  0 \\le c_2g(n) < f(n)\\;\\Forall n \\ge n_2 \\}.\n\\]\n\nThus,\n\\[\no(g(n)) \\cap \\omega(g(n)) =\n\\{ f(n) : \\Forall c_1 > 0\\;\\Forall c_2>0\\;\\Exists n_0\\in\\mathbb{R}^+\\mid\n   0 \\le c_2g(n) < f(n) < c_1g(n)\\;\\Forall n \\ge n_2 \\},\n\\]\nwhich is the empty set since, for very large $n$, $f(n)$ cannot be less than\n$c_1 g(n)$ and greater than $c_2 g(n)$ for all $c_1, c_2 > 0$.\n\n\\end{framed}\n\n\\item[3.1{-}8]{We can extend our notation to the case of two parameters $n$ and\n$m$ that can go to infinity independently at different rates. For a given\n$g(n, m)$, we denote by $O(g(n, m))$ the set of functions\n\\[\nO(g(n, m)) = \\{{f(n, m) : \\text{there exist positive constants } c, n_0,\n\\text{and\\ } m_0 \\text{\\ such that\\ } 0 \\le f(n, m) \\le c g(n, m)\n\\text{\\ for all\\ } n \\ge n_0 \\text{\\ and\\ } m \\ge m_0}\\}.\n\\]\n\nGive corresponding definitions for $\\Omega(g(n, m))$ and $\\Theta(g(n, m))$.\n}\n\n\\begin{framed}\nWe denote by $\\Omega(g(n, m))$ the set of functions\n\\[\n\\Omega(g(n, m)) = \\{f(n, m) : \\Exists c\\;n_0\\;m_0 \\in \\mathbb{R}^+ \\mid\n                    0 \\le cg(n, m)) \\le f(n, m)\\;\n                    \\Forall n \\ge n_0\\;\\Forall m \\ge m_0\\}.\n\\]\n\nWe denote by $\\Theta(g(n, m))$ the set of functions\n\\[\n\\Theta(g(n, m)) = \\{f(n, m) : \\Exists c_1\\;c_2\\;n_0\\;m_0\\in\\mathbb{R}^+\\mid\n                    0 \\le c_1g(n, m) \\le f(n, m) \\le c_2g(n, m)\\;\n                    \\Forall n \\ge n_0\\;\\Forall m \\ge m_0\\}.\n\\]\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section{Standard notations and common functions}\n\n\\begin{enumerate}\n\n\\item[3.2{-}1]{Show that if $f(n)$ and $g(n)$ are monotonically increasing\nfunctions, then so are the functions $f(n) + g(n)$ and $f(g(n))$, and if\n$f(n)$ and $g(n)$ are in addition nonnegative, then $f(n) \\cdot g(n)$ is\nmonotonically increasing.}\n\n\\begin{framed}\nIf $f(n)$ and $g(n)$ are both monitonically increasing and $n \\le m$, we have\n\\[\nf(n) \\le f(m) \\quad \\text{and} \\quad g(n) \\le g(m),\n\\]\n\nwhich implies that\n\\[\nf(n) - f(m) \\le 0 \\quad \\text{and} \\quad g(n) - g(m) \\le 0.\n\\]\n\nAdding the above inequalities together, we have\n\\[\nf(n) - f(m) + g(n) - g(m) \\le 0 \\rightarrow\nf(n) + g(n) \\le f(m) + g(m),\n\\]\n\nwhich shows that $f(n) + g(n)$ is monitonically increasing.\n\nAlso, let $g(n) = p$ and $g(m) = q$.\nSince $f(n) \\le f(m)$ and $g(n) \\le g(m)$, we have\n\\[\nf(p) \\le f(q) \\rightarrow f(g(n)) \\le f(g(m)),\n\\]\nwhich shows that $f(g(n))$ is monitonically increasing.\n\nIf in addition, $f(\\cdot) \\ge 0$ and $g(\\cdot) \\ge 0$, we have\n\\[\nf(n) \\le f(m) \\rightarrow f(n) g(n) \\le f(m) g(n) \\rightarrow f(n) g(n) \\le f(m) g(m),\n\\]\nwhich shows that $f(n) \\cdot g(n)$ is monitonically increasing.\n\\end{framed}\n\n\\item[3.2{-}2]{Prove equation (3.16).}\n\n\\begin{framed}\nFor all real $a > 0, b > 0, c > 0$,\n\\[\na^{\\log_b c} = a^{\\frac{\\log_a c}{\\log_a b}}\n             = \\left(a^{\\log_a c}\\right)^{\\frac{1}{\\log_a b}}\n             = c^{\\frac{1}{\\log_a b}}\n             = c^{\\log_b a}.\n\\]\n\\end{framed}\n\n\\item[3.2{-}3]{Prove equation (3.19).\nAlso prove that $n! = \\omega(2^n)$ and $n! = o(n^n)$.}\n\n\\begin{framed}\nUsing the Stirling's approximation, we have\n\\begin{equation*}\n\\begin{split}\n  \\lg(n!) & \\approx \\lg\\left(\\sqrt{2 \\pi n} \\binom{n}{e}^n \\left(1 + \\Theta\\left(\\frac{1}{n}\\right)\\right)\\right)\\\\\n          & = \\lg{(\\sqrt{2 \\pi n})} + \\lg(\\sqrt{n}) + \\lg(n^n) - \\lg(e^n) + \\Theta(\\lg(1/n))\\\\\n          & = \\Theta(1) + 1/2 \\lg(n) + n \\lg n - n \\lg e + \\Theta(\\lg(1/n))\\\\\n          & = \\Theta(1) + \\Theta(\\lg n) + \\Theta(n \\lg n) - \\Theta(n) + \\Theta(\\lg(1/n))\\\\\n          & = \\Theta(n \\lg n),\n\\end{split}\n\\end{equation*}\nwhich proves Equation (3.19).\n\nWe have\n\\[\n  n! = n \\cdot (n - 1) \\cdot (n - 2) \\cdots 2 \\cdot 1\n     < \\underbrace{n \\cdot n \\cdot n \\cdots}_\\text{n times}\n     = n^n\\;\\Forall n \\ge 2,\n\\]\nwhich implies\n\\[\n  n! = o(n^n).\n\\]\n\nWe have\n\\[\n  n! = n \\cdot (n - 1) \\cdot (n - 2) \\cdots 2 \\cdot 1\n     > \\underbrace{2 \\cdot 2 \\cdot 2 \\cdots}_\\text{n times}\n     = 2^n\\;\\Forall n \\ge 4,\n\\]\nwhich implies\n\\[\n  n! = w(2^n).\n\\]\n\n\\end{framed}\n\n\\newpage\n\n\\item[3.2{-}4]{($\\star$) Is the function $\\ceil{\\lg n}{!}$ polynomially bounded?\nIs the function $\\ceil{\\lg \\lg n}{!}$ polynomially bounded?}\n\n\\begin{framed}\nA function $f(n)$ is polynomially bounded if there are constants $c, k, n_0$\nsuch that for all $n \\ge n_0$, $f(n) \\le c n^k$. Thus, $\\lg(f(n)) \\le c k \\lg{n}$.\n\nWe have\n\\[\n\\lg(\\ceil{\\lg{n}}!) = \\Theta(\\ceil{\\lg{n}} \\lg(\\ceil{\\lg{n}})) = \\Theta(\\lg{n} \\lg{\\lg{n}}) = w(\\lg{n}),\n\\]\n\nwhich implies that $\\lg(\\ceil{\\lg{n}}!) > c k \\lg{n}$, i.e., $\\ceil{\\lg{n}}{!}$\nis not polynomially bounded.\n\nWe have\n\\[\n\\lg(\\ceil{\\lg{\\lg{n}}}!) = \\Theta(\\ceil{\\lg{\\lg{n}}}\\lg{\\ceil{\\lg{\\lg{n}}}})\n                          = \\Theta(\\lg{\\lg{n}} \\lg{\\lg{\\lg{n}}})\n                          = o(\\lg^2{\\lg{n}})\n                          = o(\\lg^2{n})\n                          = o(\\lg{n}),\n\\]\nwhich implies that $\\lg(\\ceil{\\lg{\\lg{n}}}!) \\le c k \\lg{n}, i.e.,\n\\ceil{\\lg{\\lg{n}}}{!}$ is polynomially bounded.\n\n\\end{framed}\n\n\\item[3.2{-}5]{($\\star$) Which is asymptotically larger:\n$\\lg(\\lg^\\star n)$ or $\\lg^\\star(\\lg n)$}?\n\n\\begin{framed}\nLet's assume that $\\lg^*(x) = k$.\n\nWe have\n\\[\n\\lg(\\lg^*{x}) = \\lg{k},\n\\]\nand\n\\[\n\\lg^*(\\lg{x}) = k - 1,\n\\]\nsince the inner logarithm that is applied to $x$ will reduce the number of\niterations of the iterative logarithm by 1.\n\nThus, since $(k - 1)$ is asymptotically larger than $\\lg(k)$, $\\lg^*(\\lg{x})$ is\nalso asymptotically larger than $\\lg(\\lg^*{x})$.\n\\end{framed}\n\n\\item[3.2{-}6]{Show that the golden ration $\\phi$ and its conjugate $\\hat\\phi$}\nboth satisfy the equation $x^2 = x + 1$.\n\n\\begin{framed}\nThe demonstration follows directly from the formulas of $\\phi$ and $\\hat\\phi$.\n\\[\n\\phi^2 = \\left(\\frac{1 + \\sqrt{5}}{2}\\right)^2 = \\frac{1 + 2 \\sqrt{5} + 5}{4}\n       = \\frac{2 \\sqrt{5} + 6}{4} = \\frac{\\sqrt{5} + 3}{2}\n       = \\frac{1 + \\sqrt{5}}{2} + 1 = \\phi + 1.\n\\]\n\n\\[\n\\hat\\phi^2 = \\left(\\frac{1 - \\sqrt{5}}{2}\\right)^2 = \\frac{1 - 2 \\sqrt{5} + 5}{4}\n           = \\frac{6 - 2 \\sqrt{5}}{4} = \\frac{3 - \\sqrt{5}}{2}\n           = \\frac{1 - \\sqrt{5}}{2} + 1 = \\hat\\phi + 1.\n\\]\n\\end{framed}\n\n\\item[3.2{-}7]{Prove by induction that the $i$th Fibonacci number satisfies the\nequality\n\\[\nF_i = \\frac{\\phi^i - \\hat\\phi^i}{\\sqrt{5}},\n\\]\nwhere $\\phi$ is the golden ratio and $\\hat\\phi$ is its conjugate.\n}\n\n\\begin{framed}\nWe have that\n\\[\nF_0 = \\frac{\\phi^0 - \\hat\\phi^0}{\\sqrt{5}} = \\frac{1 - 1}{\\sqrt{5}} = 0,\n\\]\nand\n\\[\nF_1 = \\frac{\\phi^1 - \\hat\\phi^1}{\\sqrt{5}}\n    = \\frac{1 + \\sqrt{5} - 1 + \\sqrt{5}}{2 \\sqrt{5}}\n    = \\frac{2 \\sqrt{5}}{2 \\sqrt{5}} = 1.\n\\]\n\nwhich are the correct Fibonacci values for $i = 0$ and $i = 1$. Then we have the inductive step:\n\\begin{equation*}\n\\begin{split}\nF_i + F_{i + 1} &= \\frac{\\phi^i + \\hat\\phi^i}{\\sqrt{5}} +\n                   \\frac{\\phi^{i + 1} + \\hat\\phi^{i + 1}}{\\sqrt{5}}\\\\\n                &= \\frac{\\phi^i + \\phi^{i + 1} - (\\hat\\phi^i + \\hat\\phi^{i + 1})}{\\sqrt{5}}\\\\\n                &= \\frac{\\phi^i (1 + \\phi) - \\hat\\phi^i (1 + \\phi)}{\\sqrt{5}}\\\\\n                &= \\frac{\\phi^i \\phi^2 - \\hat\\phi^i \\hat\\phi^2}{\\sqrt{5}}\\\\\n                &= \\frac{\\phi^{i + 2} - \\hat\\phi^{i + 2}}{\\sqrt{5}} = F_{i + 2}.\n\\end{split}\n\\end{equation*}\n\\end{framed}\n\n\\item[3.2{-}8]{Show that $k \\ln k = \\Theta(n)$ implies $k = \\Theta(n / \\ln n)$.}\n\n\\begin{framed}\nFrom the symmetry of $\\Theta$, we have\n\\[\nk \\ln k = \\Theta(n) \\rightarrow n = \\Theta(k \\ln k),\n\\]\nand\n\\[\n\\ln n = \\Theta(\\ln(k \\ln k)) = \\Theta(\\ln k \\ln \\ln k) = \\Theta(\\ln k).\n\\]\nThus,\n\\[\n\\frac{n}{\\ln n} = \\frac{\\Theta(k \\ln k)}{\\Theta(\\ln k \\ln \\ln k)}\n                = \\Theta\\left(\\frac{k \\ln k}{\\ln k \\ln \\ln k}\\right)\n                = \\Theta(k),\n\\]\nwhich implies\n\\[\nk = \\Theta\\left(\\frac{n}{\\ln n}\\right).\n\\]\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section*{Problems}\n\\addcontentsline{toc}{section}{\\protect\\numberline{}Problems}%\n\nSkipped for later.\n", "meta": {"hexsha": "72f90fb92784bc0f3d011593606518c41e014ddd", "size": 12905, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/C3.tex", "max_stars_repo_name": "danielmoraes/clrs", "max_stars_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-07-08T17:39:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-07-08T17:39:19.000Z", "max_issues_repo_path": "chapters/C3.tex", "max_issues_repo_name": "danielmoraes/clrs", "max_issues_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-31T20:41:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-31T20:41:48.000Z", "max_forks_repo_path": "chapters/C3.tex", "max_forks_repo_name": "danielmoraes/clrs", "max_forks_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-03-12T04:51:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-12T04:51:51.000Z", "avg_line_length": 25.1070038911, "max_line_length": 115, "alphanum_fraction": 0.5462223944, "num_tokens": 5515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7303796079230007}}
{"text": "% This document was created while following the amzaing LaTeX beginner tutorial (https://www.youtube.com/playlist?list=PL542920k_cOoSTC23aG3jhczwHtrRKb9q) of the YouTube channel DorFuchs (https://www.youtube.com/channel/UC97dp7op_ZjSCNp3DRLGymQ)\n\n\\documentclass{article}\n\n\n% packages to import:\n\\usepackage[ngerman]{babel} % Language package for usign for example umlauts\n\\usepackage[utf8]{inputenc} % Input encoding - rendering of for example umlauts\n\\usepackage[T1]{fontenc} % Font encoding to find later words with for example umlauts\n\\usepackage{amsmath} % Use advanced math in \\begin{align}\\end{align} sections\n\\usepackage{amssymb} % Use math symbols like the symbol for the real numbers\n\\usepackage{amsthm} % Create your own sections and use for example a proof section\n\n\n% create a section named satz\n\\newtheorem{satz}{Satz}\n\n% create custom commands ([#] is the number of arguments)\n\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\vektor}[1]{\\begin{pmatrix}#1\\end{pmatrix}}\n\n% remove indent\n\\setlength{\\parindent}{0px}\n\n\n\\begin{document}\n\t\n\n\\title{Testdokument}\n\\author{DorFuchs}\n\\maketitle\n\t\n\n% add table of contents to the document\n\\tableofcontents\n\n% show text on the next side\n\\newpage\n\n\n\\section{Satz des Pythagoras}\n\t\n\\begin{satz}\n\tIn einem rechtwinkligen Dreieck mit Katheten $a$ und $b$ und Hyphotenuse $c$ gilt\n\t\\[ a^2 + b^2 = c^2 . \\]\n\\end{satz}\n\\begin{proof}\n\t... \\\\\n\t... \\\\\n\t...\n\\end{proof}\n\n\n\\section{p-q-Formel}\n\nFür die Gleichung $x^2 + px + q = 0$, wobei $p, q \\in \\mathbb{R}$ mit $\\frac{p}{2}^2 - q > 0$, lautet die Lösungsformel\n\\begin{align}\n\tx &= \\frac{p}{2} \\pm \\sqrt{ \\left( \\frac{p}{2} \\right)^2 - q} \\\\\n\t&= - \\frac{p}{2} \\pm \\sqrt{\\frac{p^2}{4} - q}\n\\end{align}\n\n\n\\section{Euklidische Geometrie}\n\n\\subsection{Matrizen}\n\n\\begin{satz}\n\tDie Einheitsmatrix im $\\R^3$ lautet\n\t\\[ \\begin{pmatrix}\n\t1 & 0 & 0 \\\\\n\t0 & 1 & 0 \\\\\n\t0 & 0 & 1\n\t\\end{pmatrix} . \\]\n\\end{satz}\n\n\\subsection{Vektoren}\n\n\\begin{satz}\n\tDer Betrag eines Vektors ist im $\\R^3$ ist definiert durch\n\t\\[ \\left| \\vektor{x\\\\y\\\\z} \\right| = \\sqrt{x^2 + y^2 + z^2} . \\]\n\\end{satz}\n\n\n\\end{document}", "meta": {"hexsha": "1a3dbe6f4d1ac6ed0459660f73fc3cd3d7a0556a", "size": 2075, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "basic-equations.tex", "max_stars_repo_name": "AnonymerNiklasistanonym/LatexExamples", "max_stars_repo_head_hexsha": "08b577ed7b948800d1456546bd792c20cfd24f77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-06T17:01:27.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-06T17:01:27.000Z", "max_issues_repo_path": "basic-equations.tex", "max_issues_repo_name": "AnonymerNiklasistanonym/LatexExamples", "max_issues_repo_head_hexsha": "08b577ed7b948800d1456546bd792c20cfd24f77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "basic-equations.tex", "max_forks_repo_name": "AnonymerNiklasistanonym/LatexExamples", "max_forks_repo_head_hexsha": "08b577ed7b948800d1456546bd792c20cfd24f77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.7023809524, "max_line_length": 245, "alphanum_fraction": 0.694939759, "num_tokens": 742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245617, "lm_q2_score": 0.8633916134888613, "lm_q1q2_score": 0.730379602513126}}
{"text": "\\section{Basis, Dimension and Direct Sum}\r\n\\begin{definition}\r\n    This cardinality is called the dimenion $\\dim V$ of $V$.\r\n\\end{definition}\r\nThis is well-defined due to Corollary \\ref{dim_well_defined}.\r\n\\begin{proposition}\r\n    Let $U,W$ be subspaces of $V$.\r\n    If they are finite dimensional, then so is $U+W$ and\r\n    $$\\dim(U+W)=\\dim U+\\dim V-\\dim(U\\cap W)$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Pick a basis $v_1,\\ldots,v_l$ of $U\\cap W$.\r\n    Extend it to a basis $v_1,\\ldots,v_l,u_1,\\ldots,u_m$ of $U$ and a basis $v_1,\\ldots,v_l,w_1,\\ldots,w_n$ of $W$, then $\\{v_i\\}\\cup\\{u_i\\}\\cup\\{w_i\\}$ is easily a basis of $U+W$.\r\n    The equality follows.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    If $V$ is a finite dimensional vectyor space and $U\\le V$, then $U,V/U$ are both finite dimensional and $\\dim V=\\dim U+\\dim V/U$.\r\n    Furthermore,\r\n    $$\\dim V=\\dim U+\\dim V/U$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    It is obvious that $U$ is finite dimensional.\r\n    Choose a basis $u_1,\\ldots,u_l$ and extend it to a basis $u_1,\\ldots,u_l,w_{l+1},\\ldots,w_n$ of $V$, then $w_{l+1}+U,\\ldots,w_n+U$ can be verified to be a basis of $V/U$.\r\n    The statement is immediate.\r\n\\end{proof}\r\n\\begin{remark}\r\n    If $U$ is a proper subspace of $V$, written $U<V$ (meaning that $U\\le V$ and $U\\neq V$), then the proposition gives us $\\dim V/U\\neq 0$, so $\\dim U<\\dim V$.\r\n\\end{remark}\r\n\\begin{definition}\r\n    Let $V$ be a vector space and $U,W\\le V$.\r\n    We say $V$ is the direct sum of $U,W$, written $V=U\\oplus W$, if every element $v\\in V$ can be written uniquely as $v=u+w$ for $u\\in U,w\\in W$.\\\\\r\n    If this happens, then we say $W$ is a direct complement of $U$ in $V$.\r\n\\end{definition}\r\nNote that direct complement is not unique in general.\r\n\\begin{example}\r\n    Take $U=\\mathbb R\\times \\{0\\}$, then both $W=\\{0\\}\\times \\mathbb R$ and $W'=\\langle\\{(1,1)^\\top\\}\\rangle$ are direct complements of $U$.\r\n\\end{example}\r\n\\begin{lemma}\r\n    Let $U,W\\le V$, then the followings are equivalent:\\\\\r\n    1. $V=U\\oplus W$.\\\\\r\n    2., $V=U+W$ and $U\\cap W=\\{0\\}$.\\\\\r\n    3. For any basis $B_1$ of $U$ and $B_2$ of $W$, the union $B=B_1\\cup B_2$ is a basis of $V$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $V_1,\\ldots,V_l\\le V$, then we define\r\n    $$\\sum_{i=1}^lV_i=\\{v_1+\\cdots+v_l:v_j\\in V_j,1\\le j\\le l\\}$$\r\n    The sum is direct, i.e.\r\n    $$\\sum_{i=1}^lV_i=\\bigoplus_{i=1}^lV_i$$\r\n    iff $v_1+\\cdots +v_l=v_1'+\\cdots +v_l'$ implies $v_j=v_j'$ for any $1\\le j\\le l$ and $v_j\\in V_j$.\r\n    Equivalently,\r\n    $$V=\\bigoplus_{i=1}^lV_i\\iff \\forall v\\in V,\\exists!(v_1,\\ldots,v_l)\\in V_1\\times\\cdots\\times V_l,v=\\sum_{i=1}^lv_i$$\r\n\\end{definition}\r\n\\begin{proposition}\r\n    The followings are equivalent:\\\\\r\n    1.\r\n    $$\\sum_{i=1}^lV_i=\\bigoplus_{i=1}^lV_i$$\r\n    2. For any $i$,\r\n    $$V_i\\cap\\left( \\sum_{j\\neq i}V_j \\right)=\\{0\\}$$\r\n    3. For any bases $B_i$ of $V_i$, the union $\\bigcup_iB_i$ is a basis of $\\sum_iV_i$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}", "meta": {"hexsha": "078135bdf733790ecc89f47b93b9b29ccbf50051", "size": 3022, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/dim.tex", "max_stars_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_stars_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3/dim.tex", "max_issues_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_issues_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3/dim.tex", "max_forks_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_forks_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.7878787879, "max_line_length": 181, "alphanum_fraction": 0.6221045665, "num_tokens": 1171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245617, "lm_q2_score": 0.863391599428538, "lm_q1q2_score": 0.7303795906189019}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{Sweave}\n% \\SweaveOpts{echo=T,pdf=T,eps=F,eval=T,keep.source=T}\n\\usepackage{mathpazo}\n\\usepackage{hyperref,url}\n\\usepackage[a4paper,margin=1.5cm]{geometry}\n\n\\begin{document}\n\n\n\\title{Example Sweave document: estimating $\\pi$}\n\\author{Stephen J Eglen}\n\n\\date{\\today}\n\\maketitle\n\n\\section{Introduction}\n\nThis is an example document created using the Sweave system\n(\\url{http://www.statistik.lmu.de/~leisch/Sweave/}).  Sweave is a\ntool for combining both \\LaTeX\\ documentation and R code within the\nsame file.  For this document, the master file is \\url{estimate.Rnw}.\nThis is processed by the Sweave system in R, which runs the R code to\ngenerate textual/graphical output, and also creates a \\LaTeX\\ document.\nThe \\LaTeX\\ document is then typeset to create the pdf document.  On\nunix/macintosh, the following commands should recreate the pdf file:\n\n\\begin{verbatim}\n$ R CMD Sweave estimate.Rnw\n$ pdflatex estimate.tex\n\\end{verbatim}\n\n\\section{Task: estimate the value of $\\pi$}\n\nOur task is to estimate the value of $\\pi$ by simulating darts being\nthrown at a dartboard.  Imagine that the person throwing the darts is\nnot very good, and randomly throws each dart so that it falls\nuniformly within a square of side length $2r$, with the dartboard of\nradius $r$ centred within that square.  If the player throws $n$\ndarts, and $d$ of them hit the dartboard, then for large enough $n$,\nthe ratio $d/n$ should approximate the ratio of the area of the\ndartboard to the enclosing square, $ \\pi r^2 / 4 r^2 \\equiv \\pi/4$.\nFrom this, we can estimate $\\pi \\approx 4d/n$.\n\nWe start with an example, using R to draw both the dartboard and the\nsurrounding square, together with $n=50$ darts.  The radius of the\ndartboard here is 1 unit, although the value is not important.\n\n\\setkeys{Gin}{width=0.6\\textwidth}\n\\begin{center}\n<<fig=TRUE>>=\nr <- 1\nn <- 50\npar(las=1)\nplot(NA, xlim=c(-r,r), ylim=c(-r,r), asp=1, bty='n',\n     xaxt='n', yaxt='n', xlab='', ylab='')\naxis(1, at=c(-r,0,r)); axis(2, at=c(-r,0,r))\nsymbols(x=0, y=0, circles=r, inch=F, add=T)\nx <- runif(n, -r, r);  y <- runif(n, -r, r)\ninside <- x^2 + y^2 < r^2\nd <- length(which(inside))\npoints(x, y, pch=ifelse(inside, 19, 4))\nrect(-r, -r, r, r, border='blue', lwd=2)\n@ \n\\end{center}\n\nA dart is drawn as a filled circle if it falls within the dartboard,\nelse it is drawn as a cross.  In this case the number of darts within\nthe circle is \\Sexpr{d}, and so the estimated value is $\\pi \\approx\n\\Sexpr{4*d/n}$.\n\n\nThe estimate of $\\pi$ should improve as we increase the number of darts\nthrown at the dartboard.  To verify this, we write a short function\nthat, given the number of darts to throw, $n$, returns an estimate of\n$\\pi$.  \n\n<<>>=\nestimate.pi <- function(n=1000) {\n  ## Return an estimate of PI using dartboard method\n  ## with N trials.\n  r <- 1                                # radius of dartboard\n  x <- runif(n, min=-r, max=r)\n  y <- runif(n, min=-r, max=r)\n  l <- sqrt(x^2 + y^2)\n  d <- length(which(l<r))\n  4*d/n\n}\n@ \n\nWe can then test the procedure a few times, using the default number\nof darts, 1000:\n\n<<>>=\nreplicate(9, estimate.pi())\n@ \n\nFinally, for a given value of $n$, we can show 99 estimates of $\\pi$,\nas clearly the estimate will vary from run to run.  In the following\nplot, we compare the estimates of $\\pi$ for three different values of $n$:\n\n\\begin{center}\n<<fig=TRUE>>=\nns <- 10^c(2,3,4)\nres <- lapply(ns, function(n) replicate(99, estimate.pi(n)))\npar(las=1, bty='n')\nstripchart(res, method=\"jitter\", group.names=ns, \n           xlab=\"number of darts\",\n           ylab=expression(paste('estimate of ', pi)),\n           vert=T, pch=20, cex=0.5)\nabline(h=pi, col='red')\n@ \n\\end{center}\n\nAs the number of darts increases, the estimate of $\\pi$ gradually\nconverges onto the actual value of $\\pi$ (shown by the solid red line).\n\n\\end{document}\n\n", "meta": {"hexsha": "861d429fc12b5f7f4f15debddd48f8b8ef6588df", "size": 3856, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/code/Latex/SweaveExample.tex", "max_stars_repo_name": "nesbitm/VBiTE_2021", "max_stars_repo_head_hexsha": "3c8e54d4878ff3f9b9272da73c3c8700902ddb21", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-10-03T08:48:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T21:26:35.000Z", "max_issues_repo_path": "content/code/Latex/SweaveExample.tex", "max_issues_repo_name": "nesbitm/VBiTE_2021", "max_issues_repo_head_hexsha": "3c8e54d4878ff3f9b9272da73c3c8700902ddb21", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 52, "max_issues_repo_issues_event_min_datetime": "2020-10-02T05:33:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-11T11:44:01.000Z", "max_forks_repo_path": "content/code/Latex/SweaveExample.tex", "max_forks_repo_name": "nesbitm/VBiTE_2021", "max_forks_repo_head_hexsha": "3c8e54d4878ff3f9b9272da73c3c8700902ddb21", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2017-12-04T14:08:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-09T11:37:36.000Z", "avg_line_length": 32.1333333333, "max_line_length": 74, "alphanum_fraction": 0.6903526971, "num_tokens": 1202, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105951184112, "lm_q2_score": 0.9207896753475597, "lm_q1q2_score": 0.730283771307036}}
{"text": "\\subsubsection{Secondary model}\n\\label{sec:methods_pipeline_secondary_model}\n\nThe metalabelling process allows to algorithmically determine the positiveness\nof the labels. Note that metalabels should not be included as input features\nof the model because they belong to the future of the label and one model doing\nthat will not be plausible to implement on a real time system.\nInitially, all features in the feature engineering section \\ref{sec:methods_features}\nwill be used to build this model.\n\nThis research project will use bagging trees. In chapter 6 of \\cite{lopez_de_prado}\nthere is a discussion about ensemble models and three are compared: bagging\ntrees, random forests and boosting. Boosting is generally superior in terms of\nbias and variance results with respect to the others but it comes with, in my\nopinion, an important penalty: the training process should be done sequentially whereas\nbagging can be parallelized. The author is explicit about the other positive and\nnegative aspects such as tendency to over-fitting or under-fitting, by stating\nthat those claims are relative to how careful the researcher is when developing \nthe training pipeline and curating data.\n\nThe focus of this research is not to get into the details of one machine\nlearning model or the other, but to explain the most relevant characteristics of\nthe one to be used and how its characteristics are used in favor of the research\nproblem at hand. Bagging ensembles rely on multiple, $B$, decision (or\nregression but in this case we need decision) trees whose outcome is averaged \nto reduce the high variance of each tree. Decision trees tend to be deep, in\nfavor of bias reduction, but each tree variance is high. Increasing the number\nof $B$ trees does not imply an immediate shift towards over-fitting what makes\nit an appropriate hyperparameter to adjust in favor of variance reduction. See\nsection 8.2.1 of \\cite{intro_to_statistical_learning} for a better\ndescription of how bagging ensembles work.\n\nProvided that only one dataset is available, a bootstrap sample method is used.\nBootstrapping consists of sampling the base dataset with replacement to generate\nnew datasets that will be used to train each decision trees. Each new dataset is\nexpected to be biased and the variance between datasets will be diminished when\naveraging, or bagging, the results of the trees. Bootstrapping can also be done\nwith the features of the dataset. See section 5.2 of \\cite{intro_to_statistical_learning}\nfor a concise but comprehensive description to bootstrapping.\n\nThe general bootstrapping method for samples assumes that all samples are IID.\nThis is not our case when using the triple barrier method.\nNote that some samples might co-occur when time windows expand from the label\ntimestamp to $h$ sample periods ahead. In high volatility events, or with high\nvalues of $h$, we should expect events, or labels, to happen while another one\nis being evaluated. Weighing these labels with respect to unique and without any\noverlap events is important to get the most out of the bootstrapping sampling\nprocedure. Following Lopez de Prado's analysis, concurrent labels are defined as\nthose that share at least one return attribution in the triple barrier method. \nLet the concurrency $c_t$ at time $t$ be defined as:\n\n\\[c_t = \\sum_{i=1}^I l_{t,i}\\]\n\nWhere $l_{t,i}$ is the i-th label value that occurs at $t$ and $I$ is the number of\nlabel which co-occur at $t$. Labels start at a certain time $t$ but span a\nnumber of sampling periods that could be $h$ or the time difference with respect\nto one of the horizontal (price) barriers crossing events. Consequently, a label\nwill contribute to at least two different and consecutive timestamps and up to\n$h$ consecutive timestamps.\n\nLet the uniqueness of a label $i$ at time $t$ be defined as:\n\n\\[u_{t,i} = \\frac{l_{t_i}}{c_t}\\]\n\nAnd the average uniqueness will be defined as the averaged uniqueness over the\nlabel's lifespan:\n\n\\[\\bar{u}_{t,i} = \\frac{\\sum_{t=1}^{T} u_{t,i}}{\\sum_{t=1}^{T} l_{t,i}}\\]\n\nLabel's average uniqueness allows a smarter bootstrap sampling method because it\ncan be used to prioritize events with higher uniqueness over the ones with less\nuniqueness because the sole fact that they are weird in the dataset.\n\nLopez de Prado proposes a change to the above uniqueness sample weight. He\nintroduces the bet return also to account for an average of all the bets\nsimultaneously running. To do so, a new weight $w_i$ for label $i$ is proposed:\n\n\\[ \\tilde{w}_i =\\big| \\sum_{t=t_{i,0}}^{t_{i,1}} \\frac{r_{t-1,t}}{c_t} \\big|\\]\n\n\\[ w_i = \\frac{\\tilde{w}_i I}{\\sum_{j=1}^{I} \\tilde{w}_j}\\]\n\nMoving from $\\tilde{w}_i$ to $w_i$ involves a scale factor to assure:\n$\\sum_{i=1}^{I} w_j = I$. When training the model, the training set / fold (when\nusing cross validation) will incorporate the weight with combined return and\nuniqueness attribution to differentiate rare as well as rare high-return events\nfrom the other concurrent and low-return events. Lopez de Prado also proposes a\nsequential bootstrap method which updates the probability of each sample in the \nseries every time a row is drawn. This process yields train sets closer to IID\nbut this is not part of this research pipeline.", "meta": {"hexsha": "8069e606d241569161da22826fdd9f32a13e9580", "size": 5226, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/methods/pipeline/secondary_model.tex", "max_stars_repo_name": "agalbachicar/swing_for_the_fences", "max_stars_repo_head_hexsha": "3871e88884a90e5c9dd80d71b20b811485007273", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/methods/pipeline/secondary_model.tex", "max_issues_repo_name": "agalbachicar/swing_for_the_fences", "max_issues_repo_head_hexsha": "3871e88884a90e5c9dd80d71b20b811485007273", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/methods/pipeline/secondary_model.tex", "max_forks_repo_name": "agalbachicar/swing_for_the_fences", "max_forks_repo_head_hexsha": "3871e88884a90e5c9dd80d71b20b811485007273", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.7191011236, "max_line_length": 89, "alphanum_fraction": 0.7872177574, "num_tokens": 1242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909757, "lm_q2_score": 0.7931059487389966, "lm_q1q2_score": 0.7302837694865855}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS630: Database Management Systems\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 1}\n\nSuppose you are given a relation $R$ with four attribute $ABCD$ and the set of functional dependencies as follows.\n\n\\begin{enumerate}\n\\item FD = \\{ $AB\\rightarrow C$, $BC\\rightarrow D$ \\}\n\\item FD = \\{ $BC\\rightarrow A$, $AB\\rightarrow C$, $C\\rightarrow DA$ \\}\n\\end{enumerate}\n\nFor each set of functional dependencies,\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item Identify the candidate key(s) for R (recall that keys must be \\textit{minimal})\n\\item Determine if $R$ is in $BCNF$, $3NF$, or none of the above.\nIf it is not in $BCNF$, decompose it into a set of $BCNF$ relations.\nDoes the decomposition you obtained preserve all initial dependencies?\n\\end{enumerate}\n\nRecall that it is not sufficient to consider the set of functional dependencies that are given but also it's closure.\n\n\\subsection*{Solution}\n\nTables \\ref{table1} (a) and \\ref{table1} (b) are constructed to find candidate key(s) of first and second set of functional dependencies, respectively.\nBased on attribute closures of each attribute combination, combinations whose closure is equivalent to relation $R$ are underlined as minimal candidate keys.\n\n\\begin{table}[H]\n\\centering\\caption{Candidate keys of relation $R$ under different set of functional dependencies}\\label{table1}\n\\begin{subtable}{.5\\linewidth}\n\\centering\\caption{FD = \\{ $AB\\rightarrow C$, $BC\\rightarrow D$ \\}}\\label{table1a}\n\\begin{tabular}{|c|c||c|c|}\n\\hline\n$X$ & $X^+$ & $X$ & $X^+$\\\\\n\\hline\nA & A & BC & BCD\\\\\nB & B & BD & BD\\\\\nC & C & CD & CD\\\\\nD & D & ABC & ABCD\\\\\n\\underline{\\bf AB} & ABCD & ABD & ABCD\\\\\nAC & AC & ACD & ACD\\\\\nAD & AD & BCD & BCD\\\\\n\\hline\n\\end{tabular}\n\\end{subtable}%\n\\begin{subtable}{.5\\linewidth}\n\\centering\\caption{FD = \\{ $BC\\rightarrow A$, $AB\\rightarrow C$, $C\\rightarrow DA$ \\}}\\label{table1b}\n\\begin{tabular}{|c|c||c|c|}\n\\hline\n$X$ & $X^+$ & $X$ & $X^+$\\\\\n\\hline\nA & A & \\underline{\\bf BC} & ABCD\\\\\nB & B & BD & BD\\\\\nC & ACD & CD & ACD\\\\\nD & D & ABC & ABCD\\\\\n\\underline{\\bf AB} & ABCD & ABD & ABCD\\\\\nAC & ACD & ACD & ACD\\\\\nAD & AD & BCD & ABCD\\\\\n\\hline\n\\end{tabular}\n\\end{subtable}\n\\end{table}\n\n\\begin{enumerate}\n\n\\item $FD = \\{ AB\\rightarrow C, BC\\rightarrow D \\}$\n\n\t\\begin{enumerate}[label=(\\alph*)]\n\t\\item As shown in Table \\ref{table1}(a), set of minimal candidate keys are $\\{AB\\}$.\n\t\\item To check if $R$ is in \\textit{BCNF} or \\textit{3NF}, closure of functional dependencies are constructed in Equation \\ref{equation1}.\n\t\\begin{equation}\\label{equation1}\n\tF^+ = \\{AB\\rightarrow C, BC\\rightarrow D\\} \\cup \\{AB\\rightarrow D\\}\n\t\\end{equation}\n\tEach functional dependency (FD) is now verified to conform to $BCNF$ and $3NF$ form, as given in Table \\ref{table2}.\n\t\n\t\\begin{table}[H]\n\t\\centering\\caption{Conformance verification of relation $R$}\\label{table2}\n\t\\begin{tabular}{|r||c|c|c|}\n\t\\hline\n\t & $AB\\rightarrow C$ & $BC\\rightarrow D$ & $AB \\rightarrow D$\\\\\n\t\\hline\n\t$BCNF$ & \\checkmark & $\\times$ & \\checkmark \\\\\n\t$3NF$ & \\checkmark & $\\times$ & \\checkmark \\\\\n\t\\hline\n\t\\end{tabular}\n\t\\end{table}\n\t\n\tAs shown in Table \\ref{table2}, relation $R$ is not \\textit{BCNF} since functional dependency $BC\\rightarrow D$ violates \\textit{BCNF} condition.\nTo resolve the violation, $R$ is decomposed into $ABC$ and $BCD$ whose closures are respectively $\\{AB\\rightarrow C, AB\\rightarrow D\\}$ and $\\{BC\\rightarrow D\\}$ both conforming to \\textit{BCNF} form.\nClearly, the decomposition preserves all initial functional dependencies.\n\n\t\\end{enumerate}\n\n\\item FD = \\{ $BC\\rightarrow A$, $AB\\rightarrow C$, $C\\rightarrow DA$ \\}\n\n\t\\begin{enumerate}[label=(\\alph*)]\n\t\\item As shown in Table \\ref{table1}(a), set of minimal candidate keys are $\\{AB, BC\\}$.\n\t\\item To check if $R$ is in \\textit{BCNF} or \\textit{3NF}, closure of functional dependencies are constructed in Equation \\ref{equation2}.\n\t\\begin{equation}\\label{equation2}\n\tF^+ = \\{BC\\rightarrow A, AB\\rightarrow C, C\\rightarrow DA\\} \\cup \\{AB\\rightarrow D, BC\\rightarrow D\\}\n\t\\end{equation}\n\tEach functional dependency (FD) is now verified to conform to $BCNF$ and $3NF$ form, as given in Table \\ref{table3}.\n\t\\begin{table}[H]\n\t\\centering\\caption{Conformance verification of relation $R$}\\label{table3}\n\t\\begin{tabular}{|r||c|c|c|c|c|}\n\t\\hline\n\t & $BC\\rightarrow A$ & $AB\\rightarrow C$ & $C\\rightarrow DA$ & $AB\\rightarrow D$ & $BC\\rightarrow D$ \\\\\n\t\\hline\n\t$BCNF$ & \\checkmark & \\checkmark & $\\times$ & \\checkmark & \\checkmark \\\\\n\t$3NF$ & \\checkmark & \\checkmark & $\\times$ & \\checkmark & \\checkmark \\\\\n\t\\hline\n\t\\end{tabular}\n\t\\end{table}\n\tAs shown in Table \\ref{table3}, relation $R$ is not \\textit{BCNF} since functional dependency $C\\rightarrow DA$ violates \\textit{BCNF} condition ($C$ is not a minimal key).\n\tTo resolve the violation, $R$ is decomposed into $BC$ and $CDA$.\n\tAs neither of the decomposed sets have violations, new relations conform \\textit{BCNF} form.\nIn this case, the decomposition does not preserves initial functional dependencies.\n\t\\end{enumerate}\n\n\\end{enumerate}\n", "meta": {"hexsha": "44d24c2772c5b7fb228e694fd41db575d0734c11", "size": 5291, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs630-2014f/src/tex/hw06/hw06q01.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs630-2014f/src/tex/hw06/hw06q01.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs630-2014f/src/tex/hw06/hw06q01.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 41.9920634921, "max_line_length": 200, "alphanum_fraction": 0.6786996787, "num_tokens": 1688, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8856314647623016, "lm_q1q2_score": 0.7301694234976311}}
{"text": "\\section{Kernel smoothers}\nOne of the reasons why the previous smoothers is wiggly is because\nwhen we move from $x_i$ to $x_{i+1}$ two points are usually changed in\nthe group we average. If the new two points\nare very different then  $s(x_i)$ and $s(x_{i+1})$ may be quite\ndifferent. One way to try and fix this is by making the transition\nsmoother. That's the idea behind kernel smoothers.\n\nGenerally speaking a kernel smoother defines a set of weights\n$\\{W_i(x)\\}_{i=1}^{n}$ for each $x$ and defines \n\\[\ns(x) = \\sum_{i=1}^n W_i(x) y_i.\n\\]\n\nWe will see that most scatter plot smoothers can be considered to be\nkernel smoothers in this very general definition. \n\nWhat is called a kernel smoother in practice has a simple approach to\nrepresent the weight sequence $\\{W_i(x)\\}_{i=1}^{n}$ by describing the\nshape of the weight function $W_i(x)$ by a density function with a\nscale parameter that adjusts the size and the form of the weights near\n$x$. It is common to refer to this shape function as a {\\it kernel}\n$K$. The kernel is a continuous, bounded, and symmetric real function\n$K$ which integrates to one,\n\n\\[\n\\int K(u)\\,du = 1.\n\\]\n\nFor a given scale parameter $h$, the weight sequence is then defined\nby\n\\[\nW_{hi}(x) = \\frac{K\\left( \\frac{x - x_i}{h} \\right) }{ \\sum_{i=1}^n K\\left\n  ( \\frac{ x - x_i }{h} \\right)}\n\\]\n\nNotice: $\\sum_{i=1}^n W_{hi} (x_i) = 1$\n\n\nThe kernel smoother is then defined for any $x$ as before by\n\\[\ns(x) = \\sum_{i=1}^n W_{hi}(x) Y_i.\n\\]\n\nNotice: if we consider $x$ and $y$ to be observations of random\nvariables $X$ and $Y$ then one can get an intuition for why this would\nwork because\n\\[\nE[ Y | X ] = \\int y f_{X,Y}(x,y) \\, dy / f_X(x),\n\\]\nwith $f_X(x)$ the marginal distribution of $X$ and $f_{X,Y}(x,y)$ the joint\ndistribution of $(X,Y)$, and \n\\[\ns(x) = \\frac{ n^{-1}\\sum_{i=1}^n K\\left( \\frac{x - x_i}{h} \\right) y_i }\n  { n^{-1}\\sum_{i=1}^n K\\left   ( \\frac{ x - x_i }{h} \\right)}\n\\]\n\nBecause we think points that are close together are similar, a kernel\nsmoother usually defines weights that decrease in  \na smooth fashion as one moves away from the target point. \n\nRunning mean smoothers are kernel smoothers that use a ``box'' kernel. A\nnatural candidate for $K$ is the standard Gaussian density. (This is \nvery inconvenient computationally because its never 0).  This smooth\nis shown in Figure \\ref{f2.5} for $h=1$ year.\n\n\n\\begin{figure}[htp]\n\\caption{\\label{f2.5} CD4 cell count since seroconversion for HIV infected men.}\n\\centerline{\\epsfig{figure=Plots/plot-02-05.ps,angle=270,width=.8\\textwidth}}\n\\end{figure}\n\nIn Figure \\ref{f2.6} we can see the weight sequence for the box and Gaussian\nkernels for three values of $x$.\n\n\\begin{figure}[htp]\n\\caption{\\label{f2.6} CD4 cell count since seroconversion for HIV infected men.}\n\\centerline{\\epsfig{figure=Plots/plot-02-06.ps,angle=270,width=.8\\textwidth}}\n\\end{figure}\n\n\n\\newpage\n\n\\subsection{An Asymptotic result}\nFor the asymptotic theory presneted here we will assume the stochastic\ndesign model with a one-dimensional covariate. \n\nFor the first time in this Chapter we will set down a specific\nstochastic model. Assume we have $n$ IID observations of the random\nvariables $(X,Y)$ \nand that  \n\\begin{equation}\n\\label{simplemodel}\nY_i = f(X_i) + \\varepsilon_i, i=1,\\dots,n\n\\end{equation}\nwhere $X$ has marginal distribution $f_X(x)$ and the $\\varepsilon_i$ IID\nerrors independent of the $X$. A common extra assumption is that the\nerrors are normally distributed.\nWe are now going to\nlet $n$ go to infinity... What does that mean?\n\nFor each $n$ we define an estimate for $f(x)$ using the kernel\nsmoother with scale parameter $h_n$.\n\n\\begin{theorem}\n\\label{t2.1}\nUnder the following assumptions\n\\begin{enumerate}\n\\item $\\int |K(u)| \\, du < \\infty$\n\\item $\\lim_{|u| \\rightarrow \\infty} uK(u) = 0$\n\\item $\\E(Y^2) \\leq \\infty$\n\\item $n \\rightarrow \\infty, h_n \\rightarrow 0, nh_n \\rightarrow\n  \\infty$\n\\end{enumerate}\n\nThen, at every point of continuity of $f(x)$ and  $f_X(x)$ we have\n\\[\n \\frac{ \\sum_{i=1}^n K\\left( \\frac{x - x_i}{h} \\right) y_i }\n  { \\sum_{i=1}^n K\\left   ( \\frac{ x - x_i }{h} \\right)}\n  \\rightarrow f(x) \\mbox{ in probability.}\n\\]\n\\end{theorem}\n\n{\\bf Proof:} Homework. Hint: Start by proving the fixed design model.\n\n", "meta": {"hexsha": "39f85b39303132698d85aa0f54cf54b65d5e4d56", "size": 4225, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-02-04.tex", "max_stars_repo_name": "igrabski/rafalab.github.io", "max_stars_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2016-08-17T23:04:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T19:21:02.000Z", "max_issues_repo_path": "pages/754/section-02-04.tex", "max_issues_repo_name": "igrabski/rafalab.github.io", "max_issues_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-18T00:41:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-21T22:35:40.000Z", "max_forks_repo_path": "pages/754/section-02-04.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 33.5317460317, "max_line_length": 80, "alphanum_fraction": 0.7039053254, "num_tokens": 1351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951143326727, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.7301583775561257}}
{"text": "\\section{Classifying Differential Equations}\r\n\\noindent\r\nBelow is a list of differential equations\r\n\\begin{enumerate}\r\n\t\\item \\begin{equation*}\r\n\t\tt = 7\\frac{\\mathrm{d}^2 x}{\\mathrm{d} t^2} + x\\frac{\\mathrm{d} x}{\\mathrm{d} t}\r\n\t\\end{equation*}\r\n\t\\item \\begin{equation*}\r\n\t\t\\frac{\\mathrm{d}y}{\\mathrm{d}x} = x^2 + 3xy -7y\r\n\t\\end{equation*}\r\n\t\\item \\begin{equation*}\r\n\t\t\\frac{\\partial^2 u}{\\partial x^2} + \\frac{\\partial^2 u}{\\partial y^2} = 0\r\n\t\\end{equation*}\r\n\t\\item \\begin{equation*}\r\n\t\t\\frac{\\partial^2 y}{\\partial t^2} = 4\\frac{\\partial^2 y}{\\partial x^2} + e^{t-x}\r\n\t\\end{equation*}\r\n\t\\item \\begin{equation*}\r\n\t\t\\frac{\\mathrm{d} y}{\\mathrm{d} x} + 5y = e^x\r\n\t\\end{equation*}\r\n\t\\item \\begin{equation*}\r\n\t\t\\frac{\\mathrm{d} y}{\\mathrm{d} x} = 3x^2 + y^2\r\n\t\\end{equation*}\r\n\t\\item \\begin{equation*}\r\n\t\t\\frac{\\mathrm{d}^2 x}{\\mathrm{d} t^2} = \\frac{\\mathrm{d}x}{\\mathrm{d}t} + \\cos{x}\r\n\t\\end{equation*}\r\n\t\\item \\begin{equation*}\r\n\t\t\\frac{\\mathrm{d}^2 y}{\\mathrm{d} x^2} - 2x\\frac{\\mathrm{d} y}{\\mathrm{d} x} + 2y = 0\r\n\t\\end{equation*}\r\n\t\\item \\begin{equation*}\r\n\t\t\\frac{\\partial^2 x}{\\partial t \\partial z} + xt = 5\r\n\t\\end{equation*}\r\n\t\\item \\begin{equation*}\r\n\t\t\\frac{\\mathrm{d} x}{\\mathrm{d}y} + xy + ty = \\ln{y}\r\n\t\\end{equation*}\r\n\\end{enumerate}\r\nLet's think about some of the ways we can classify these equations.\r\n% Order\r\n\\input{./basics/classification/order.tex}\r\n% Linearity\r\n\\input{./basics/classification/linearity.tex}\r\n% Ordinary / Partial\r\n\\input{./basics/classification/type.tex}\r\n% Homogeneity\r\n\\input{./basics/classification/homogeneity.tex}\r\n", "meta": {"hexsha": "79a8ddb21a8775c7567d65e1d2b9ddc3d434ffa8", "size": 1561, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/basics/classification/classification.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/basics/classification/classification.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/basics/classification/classification.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 34.6888888889, "max_line_length": 87, "alphanum_fraction": 0.6335682255, "num_tokens": 637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587159, "lm_q2_score": 0.8652240756264639, "lm_q1q2_score": 0.7301583736210828}}
{"text": "%&LaTeX\n\n\\section{Let's Catch Some Z's}\n\nThis lab covers the z-transform, used to convert arbitrary digital\nsignals to the frequency domain. It also exercises the relationship\nbetween a filter's transfer function and impulse response and how the\noperations of multiplication and convolution, respectively, can be\nused to compute a filter's output.\n\n\\subsection{The z-transform, Transfer Function, \\& Impulse Response}\n\nA discrete signal $x[n]$ has a z-transform $X(z)$ defined by the\nfollowing equation:\n\\[\nX(z)=\\sum_{n=0}^{\\infty}x[n]z^{-n}\n\\]\nWith this definition lets investigate a feed forward filter with ten\ncoefficients, $\\{b_0, b_1,\\cdots, b_9\\}$.  Recall that the Matlab\n\\verb|filter| function allows us to specify a filter in terms of its\n\\emph{coefficients}, but we can also think of it as being defined in\nterms of its \\emph{transfer function}. Considering the $b_k$\ncoefficients of the above feed forward filter, the \\verb|filter|\nfunction implements the transfer function:\n\\begin{equation}\n  H(z) = \\sum_{k=0}^{9} b_k z^{-k}\n\\end{equation}\nIn previous labs we have computed the transfer function using the\ndelays of the \\emph{defining function}.  Mathematically, we were\nactually taking the z-transform of the \\emph{impulse response}!  In\nthis example, the impulse response is:\n\\begin{equation}\n  h[n] = \\sum_{k=0}^{9} b_k \\delta[n-k]\n\\end{equation}\nwhere $\\delta[k]$ is the unit impulse and only has a non-zero value at\n$k=n$. $H(z)$ and $h[n]$ form a z-transform pair,\n$h[n]\\xleftrightarrow{z} H(z)$. It should now be obvious why\nfeedforward filters are also known as finite impulse response filters\n--- their impulse response only has a \\emph{finite} number of\nvalues. To compute the output, $y[n]$, using the impulse response we\nuse \\emph{convolution}. Namely, we \\emph{convolve} the input, $x[n]$,\nby the impulse response, $h[n]$,\n\\begin{equation}\n  y[n] = x[n] \\ast h[n]  = \\sum_{k=0}^{9}x[k]h[n-k]\n\\end{equation}\nAnd, indeed, Matlab has a \\verb|conv| function to do this convolution.\nAlternatively, we can compute a filter's output by multiplying the\ntransfer function by the z-transform of the input to yield the\nz-transform of the output:\n\\begin{equation}\n  Y(z) = H(z) X(z)\n\\end{equation}\nFrom a practical point of view, of course, it makes more sense to\nimplement a filter in terms of its impulse response. However, for\nfilters with long impulse responses, it is sometimes more convenient\nto represent them mathematically using the transfer function (which we\nnow know is just the z-transform of the impulse response!).\n\n\\subsection{Z-Transforms}\n\n\\paragraph{Step 1.1} On paper, compute the z-transform, $X(z)$, of\n\t\\begin{equation}\n\t\tx[n] = \\left\\{\n\t\t\\begin{array}{ll}\n\t\t\t(-1)^n & n \\ge 0 \\\\\n\t\t\t0 & n < 0\n\t\t\\end{array}\\right.\n\t\\end{equation}\n\tNote that this is an infinite geometric series.  What are the\n        locations of any pole(s) (roots of the denominator polynomial)\n        or zero(s) (roots of the numerator polynomial)?\n\n\n\\paragraph{Step 1.2} Evaluate the frequency response of $X(z)$\n        from step~1.1, $X(z)\\big{|}_{z=e^{j\\hat{\\omega}}}$, by\n        sketching it by hand.  What kind of filter is this?\n\n\n\\paragraph{Step 1.3} Consider the z-transform:\n\t\\begin{equation}\n\t  X(z) = 1 - 2z^{-1} + 3z^{-3} - z^{-5}  \n\t\\end{equation}\n\tWrite the inverse z-transform, $x[n]$, as a table of values for\n\tcorresponding $n$ values.\n\n\n\\subsection{Impulse Response}\n\n\\paragraph{Step 2.1} Consider a filter with a transfer function\n\t\\begin{equation}\n\tH(z) = 1 + 5z^{-1} - 3z^{-2} + 2.5z^{-3} + 4z^{-8}  \n\t\\end{equation}\n\tWhat is the defining equation for this filter, $y[n] = F(x[n])$?\n\n\n\\paragraph{Step 2.2} What is the output sequence of the filter of\n\tStep~2.1 when the input is $x[n] = \\delta[n]$? Verify this\n        using Matlab.\n\n\n\\paragraph{Step 2.3} The impulse response of a filter is $h[n]\n        = \\delta[n] + 2\\delta[n-1] + \\delta[n-2] - \\delta[n-3]$, or equivalently,\n        $h[n]=\\{1,2,1,-1\\}$, $n=\\{0, 1, 2, 3\\}$. Determine the\n        response of the system to the input signal $x[n]=\\{1,2,3,1\\}$,\n        $n=\\{0, 1,2,3\\}$ by hand. Use Matlab to check your\n        results. Include a figure that shows both the input and output\n        signals; make sure the reader can clearly see what the signal\n        values are (the \\verb|stem| plot function should help to\n        ensure this is the case).\n\n\\paragraph{Step 2.4} Change the input to the filter of\n        Step~2.3 to be $\\delta[n]$. What are the output values? How do\n        they compare to the impulse response? Include plots of the\n        filter input and output values in your report.\n\n\n\\paragraph{Step 2.5} Use Matlab to determine the output of the\n        filter \\{1/3,1/3,1/3\\}, $n=\\{0,1,2\\}$ for the input:\n\t\\begin{equation}\n\t  x[n] = 4 + \\sin[0.25\\pi(n-1)] - 3 \\sin[(2\\pi/3)n]  \n\t\\end{equation}\n        Include a listing of your Matlab code and a figure with\n        plots of the filter input and output in your report. Is the\n        result expected? Why or why not?\n\t\n\t\n\n\\paragraph{Step 2.6} Create your own Matlab \\emph{function},\n        \\verb|convolution|, to implement a convolution function.  To\n        test your function, make sure it works exactly like the Matlab\n        \\verb|conv| and \\verb|filter| functions by providing the same\n        input to each and subtracting their outputs. Use the filter\n        $\\{1/3,1/3,1/3\\}$, $n=\\{0,1,2\\}$ from step 2.5.\n\t\n\n\\subsection{Canceling Sinusoidal Components}\n\nFilters can be designed to cancel sinusoids.  Implement a filter in\nMatlab with the following impulse response:\n\\begin{equation}\nh[n] = \\delta[n] - 2\\cos(\\pi/4) \\delta[n-1] + \\delta[n-2]\n\\end{equation}\n\n\\paragraph{Step 3.1} Plot the frequency response for this filter. What\n\tare the zero locations?\n\n\n\\paragraph{Step 3.2} Use as an input to this filter the signal\n        $x[n] = \\sin\\hat{\\omega}n$, using the two frequencies\n        $\\hat{\\omega} = \\pi/2$ and $\\hat{\\omega} = \\pi/4$. You will\n        need to choose appropriate analog signals, with convenient\n        frequencies and durations, and then sample them appropriately\n        so they have the correct digital frequencies. Make sure to\n        verify that you get the correct digital frequencies and that\n        plots you make are convenient for the reader (for example,\n        neither too many nor too few cycles)! Compute the filter in\n        Matlab for each of these two inputs, plotting the input and\n        output of each. When do you get cancellation?\n\n\\paragraph{Step 3.3} Can you modify the filter coefficients to cancel\n\tthe other sinusoid? If so, show your work.\n\n\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: t\n%%% End: \n", "meta": {"hexsha": "546044e320a2865f29f9f71dea79decd62ad07fb", "size": 6640, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Matlab Labs/lab5/lab5.tex", "max_stars_repo_name": "stiber/Signal-Computing", "max_stars_repo_head_hexsha": "cb5c7825e0cc80ca2ecd3e324fcf6231c320a721", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-09-10T16:54:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T15:48:26.000Z", "max_issues_repo_path": "Matlab Labs/lab5/lab5.tex", "max_issues_repo_name": "stiber/Signal-Computing", "max_issues_repo_head_hexsha": "cb5c7825e0cc80ca2ecd3e324fcf6231c320a721", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2015-08-18T18:16:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-29T17:19:16.000Z", "max_forks_repo_path": "Matlab Labs/lab5/lab5.tex", "max_forks_repo_name": "stiber/Signal-Computing", "max_forks_repo_head_hexsha": "cb5c7825e0cc80ca2ecd3e324fcf6231c320a721", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.0588235294, "max_line_length": 81, "alphanum_fraction": 0.6897590361, "num_tokens": 1945, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.73015836713334}}
{"text": "\n\\section{The \\iotai algorithm}\n\\Label{sec:iotai}\n\nThe \\iotai algorithm in the \\cxx Standard Library \\cite[\\S 29.8.12]{cxx-17-draft} assigns sequentially\nincreasing values to a range,\nwhere the initial value is user-defined.\n%\nOur version of the original signature\nreads:\n\n\\begin{lstlisting}[style=acsl-block]\n\n  void iota(value_type* a, size_type n, value_type v);\n\\end{lstlisting} \n\n\nStarting at \\inl{v}, the function assigns consecutive\nintegers to the elements of the range \\inl{a}.\nWhen specifying \\iotai we must be careful to deal with possible overflows of the argument~\\inl{v}.\n\n\n\\subsection{Formal specification of \\iotai}\n\nThe specification of \\iotai relies on the logic function \\logicref{IotaGenerate}\nthat is defined in the following listing.\n\n\\input{Listings/IotaGenerate.acsl.tex}\n\nThe specification of \\iotai is shown in the following listing.\nIt uses the logic function \\logicref{IotaGenerate} in order to express the\npostcondition~\\inl{increment}.\n\n\\input{Listings/iota.h.tex}\n\nThe specification of \\iotai refers to \\inl{VALUE_TYPE_MAX} which is\nthe maximum value of the underlying integer type (see Listing~\\ref{lst:value-type-limits}).\nIn order to avoid integer overflows \nthe sum  \\inl{v+n} must not be greater than the constant \\inl{VALUE_TYPE_MAX}.\n\n\\clearpage\n\n\\subsection{Implementation of \\iotai}\n\nThe following listing shows an implementation of the \\iotai function.\n\n\\input{Listings/iota.c.tex}\n\nThe loop invariant \\inl{increment} describes that in each iteration of the loop the current \nvalue~\\inl{v} is equal to the sum of the value \\inl{v} in state of function\nentry and the loop index \\inl{i}.\nWe have to refer here to \\inl{\\\\at(v,Pre)} which is the value on entering \\iotai.\n\n\\clearpage\n\n", "meta": {"hexsha": "dded93c63013ef75d11bd2e71cd1685febd406e8", "size": 1722, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/numeric/iota.tex", "max_stars_repo_name": "fraunhoferfokus/acsl-by-example", "max_stars_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2017-06-14T04:17:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T06:07:36.000Z", "max_issues_repo_path": "Informal/numeric/iota.tex", "max_issues_repo_name": "fraunhoferfokus/acsl-by-example", "max_issues_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-10-18T13:30:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T07:10:16.000Z", "max_forks_repo_path": "Informal/numeric/iota.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 30.75, "max_line_length": 102, "alphanum_fraction": 0.7729384437, "num_tokens": 462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.7301583517732492}}
{"text": "\\Lecture{Jayalal Sarma}{Oct 19, 2020}{18}{Introduction to Ramsey Numbers}{Shivlal Gangesh}{$\\alpha$}{JS}\n\\section{Introduction}\nTill now we have seen advanced versions of the discrete mathematics topics we already know. Now we are going to get into Extremal combinatorics. Here we are interested in questions of the form \n\\begin{itemize}\n\\item \\textit{If this structure appears, then what is the minimum/maximum size of the object?}\n\\item \\textit{If the size is at least this much , then what kind of structures appear in the object?}\n\\item \\textit{What is the minimum size of the collection such that it is guaranteed to have certain property?}\n\\end{itemize}\nIn general we are interested in the extreme behaviors in combinatorics. The classic example we start with is an extension to an example that we have done in the beginning of the course as an Application of Pigeon Hole Principle.\n\\section{Starting Point} \\label{R(3,3)}\n\\begin{theorem}\nSix people meet in a party. Then either there exist three people who are friends with each other or there exist three people who are strangers with each other.(Note : Any two people can either be friends or strangers)\n\\end{theorem}\nWe are interested in proving the above statement. Lets look into two different approaches\n\\subsection{Model 1 (Using Cliques and Independent Sets)}\n\\begin{description}\n   \\item[Model] Let us represent the problem as a $6$ vertex graph $G(V,E) $with each person corresponding to a vertex. $(u,v) \\in E$ if and only if person $u$ is a friend of person $v$.\nIn this Model the original statement can be reformulated as\n\\item[Statement]\n\\textit{Any graph on $6$ vertices must either have a clique on $3$ vertices or an independent set on $3$ vertices.\n\\item}\n\\begin{proof}\n Consider any vertex $v$ in the graph G, without loss of generality we can assume that the degree of $v$ is greater than or equal to $3$  because suppose it is not the case then consider $\\overline{G}$ ; as $\\textrm{Cliques in }G \\leftrightarrow \\textrm{Independent Sets in } \\overline{G} $.\\\\\n Let the $3$ neighbours of $v$ be $a$, $b$ and $c$. Consider the two exhaustive cases :\n \\begin{description}\n    \\item[Case 1 : There are no edges among $a$, $b$ and $c$]\n    $ $ \\newline\n    Here we have $\\{a, b, c\\}$ as the 3-Independent Set\n    \\item[Case 2 : There is at least one edge among $a$, $b$ and $c$ ]\n    $ $ \\newline\n    Let $(a,b) \\in E$ be that edge, then we have $\\{v, a, b\\}$ as the 3-clique\n \\end{description}\nTherefore the given statement holds true.\n\\end{proof}\n\\item[Proof for tightness]\nTo prove that this is tight we need to show there is a graph with $5$ vertices such that it does not have 3-clique and 3-Independent Set. Given below is one such  example\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.2\\linewidth]{images/r33counter_example.png}\n    \\caption{5-vertex graph with no 3-clique and no 3-Independent Set}\n\\end{figure}\n\\end{description}\n\\subsection{Model 2 (Using Graph Edge colouring)}\n\\begin{description}\n   \\item[Model]\n   Let us represent the problem as 2-edge coloring of a $K_6$ graph with each vertex corresponding to a person. Color the edge $(u,v)$ with \\textit{red} if $u$ and $v$ are friends, color it with \\textit{blue} if $u$ and $v$ are strangers.\nIn this Model the original statement can be reformulated as\n\\item[Statement]\n\\textit{For any 2-edge colouring of $K_6$, there must exist either  a red $K_3$  or a blue $K_3$ }\n\\item\n\\begin{proof}\n Consider any Red,Blue-edge coloring of $K_6$. Consider any vertex $v$, the degree of $v$ is $5$ as the graph is a complete graph. By Pigeon Hole Principle , $v$ must have either $3$ red edges incident on it or $3$ blue edges incident on it. Consider the case when $v$ is incident on with $3$ red edges. Let the 3 neighbours of $v$ be $a$, $b$ and $c$.  Now there are 2 cases :\n \\begin{description}\n    \\item[Case 1 : There is no red colored edge among $(a,b)$, $(b,c)$ and $(c,a)$ ]\n    $ $ \\newline\n    Then all the three edges $(a,b)$, $(b,c)$ and $(c,a)$ are colored blue. Therefore $\\{a, b, c\\}$ forms a blue $K_3$\n    \\item[Case 2 : There is at least one red colored edge among $(a,b)$, $(b,c)$ and $(c,a)$ ]\n    $ $ \\newline\n    Let $(a,b)$ be the red colored edge, then $\\{v, a, b\\}$ forms a red $K_3$\n \\end{description}\n Therefore the given statement holds true.\n\\end{proof}\n\\item[Proof for tightness]\nTo prove that this is tight we need to show there is a 2-edge coloring of $K_5$ Such that it does not have red $K_3$ and blue $K_3$. Given below is one such  example\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.2\\linewidth]{images/k5counter_example.png}\n    \\caption{2-edge coloring of $K_5$ with no red $K_3$ and no blue $K_3$}\n\\end{figure}\n\\end{description}\n\nGeneralizing the above problem with arbitrary red $k_p$ and blue $k_q$ has been extensively studied by Ramsey and has led to the definition of Ramsey numbers.\n\\section{Ramsey numbers}\n\\begin{definition}[Ramsey number]\nThe Ramsey number denoted by $R(p,q)$ is the minimum number of vertices say $n$ such that any 2-edge coloring of $K_n$ must have either a red $K_p$ or a blue $K_q$.\\\\\n(\\textbf{Or equivalently as})\\\\\nThe minimum number of vertices ($n$) such that any graph on $n$ vertices must either have a clique on $p$ vertices or an independent set on $q$ vertices.\n\\end{definition}\n\n\\subsection{Some Observations}\n\\begin{property}\n$R(3,3)=6$\n\\end{property}\nThis is the direct formulation of the example we have done previously in \\ref{R(3,3)}\n\\begin{property}\n$R(p,q) = R(q,p)$\n\\end{property}\nThe colors \\textit{red} and \\textit{blue} are just placeholders for two colors, thus swapping the colors will still preserve the Ramsey number property. Therefore $R(p,q) = R(q,p)$.\n\\begin{property}\n$\\forall l \\geq 1 \\quad R(l,1) = 1$\n\\end{property}\nThe existence of a blue $K_1$ is nothing but the presence of single vertex and any graph with a single vertex satisfies this property. Therefore $R(l,1) = 1$\n\n\n\\section{Existence of R(p,q)}\nThe Proof for the existence of $R(p,q)$ is due to Erdős–Szekeres. The existence was proved by providing an upper bound as a recurrence relation as follows :\n\\begin{theorem}\n$$\\forall p,q \\geq 2 \\quad R(p,q) \\; \\leq \\; R(p,q-1) + R(p-1,q) $$\n\\end{theorem}\n\\begin{proof}\n Let us prove this by mathematical induction on $n$ where $n=p+q$.\n \\begin{description}\n    \\item[Idea] To show the upper bound for $R(p,q) \\leq n$ , we must argue that for any 2-edge coloring of $K_n$ there exist a red $K_p$ or blue $K_q$\n\n   \\item[Base case] $p=q=2$\n$$R(2,2) \\leq  R(2,1) + R(1,2)  $$\n$$2 \\leq 1+1$$\nHence it holds true for the base case.\n   \\item[Induction Hypothesis]\nAssume the recurrence relation is true for $n<l$. Then we need to prove it for $n=l$. Let $n=R(p-1,q)+R(p,q-1)$. Let $w$ be any vertex in $G$ ($K_n$) and consider any $2$ -edge coloring of $G$. Let $H_1$ be the subgraph of $G$ formed from the vertices sharing a red-edge with $v$ and $H_2$ be the the subgraph of $G$ formed from the vertices sharing a blue-edge with $v$.\n\\begin{description}\n   \\item[Case 1 : There are at least $R(p-1,q)$ many red edges incident on vertex $w$]\n   $ $ \\newline\n   $H_1$ is a complete graph on $R(p-1,q)$ vertices with 2-edge coloring. By definition and Induction Hypothesis we have that there exist a red $K_{p-1}$ or blue $K_q$ in $H_1$. So in graph $G$ (along with vertex $w$) there exist a red $K_p$ or blue $K_q$\n   \\item[Case 2 : There are at least $R(p,q-1)$ blue edges incident on vertex $w$]\n      $ $ \\newline\n      $H_2$ is a complete graph on $R(p,q-1)$ vertices with 2-edge coloring. By definition and Induction Hypothesis we have that there exist a red $K_p$ or blue  $K_{q-1}$ in $H_2$. So in graph $G$ (along with vertex $w$) there exist a red $K_p$ or blue $K_q$.\n\\end{description}\n   \\end{description}\n   \n\\end{proof} \n   \n\\Lecture{Jayalal Sarma}{Oct 21, 2020}{19}{Computing Ramsey Numbers and Multidimensional Ramsey numbers}{Shivlal Gangesh \\& Reetwik Das}{$\\alpha$}{JS}\n\\section{Generalizing Ramsey numbers}\n\\begin{definition}[3-dimensional Ramsey numbers]\n$R_3(p,q,r)$ is the minimum number $n$, such that any 3-edge coloring $K_n$ must have either a red $K_p$ or a blue $K_q$ or a green $K_r$\n\\end{definition}\n\\begin{definition}[$k$-dimensional Ramsey numbers]\n$R_k(s_1,s_2,\\cdots ,s_k)$ is the minimum number of vertices $n$ such that for any $k$-edge coloring of $K_n$  there must exist an $i$ such that there is a $K_{s_i}$ of colour $i$\n\\end{definition}\n\n\\section{Some Observations}\n\\begin{property}\n$R(2,p)=p$\n\\end{property}\n\\begin{proof}\n$ $ \n \\begin{description}\n    \\item[Case1 : $R(2,p) \\leq p$]\n    $ $ \\newline\n    Any 2-coloring of $K_p$ must have either a red $K_2$ or blue $K_p$. This is true because either there can exist a red edge (red $K_2$) or no red edge (blue $K_p$) in $K_p$\n    \\item[Case 2 : $R(2,p) \\geq p$]\n    $ $ \\newline\n    There exist a 2-coloring of edges of $K_{p-1}$ such that no red $K_2$ exists and no blue $K_p$ exists. Coloring all the edges of $K_{p-1}$ with blue will result in no red $K_2$ and no blue $K_p$ in $K_{p-1}$\n \\end{description}\n\\end{proof}\n\\begin{claim}\n$$ R(p,q) \\leq {p+q-2 \\choose p-1} $$\n\\end{claim}\n\\begin{proof}\n \\begin{align*}\n     R(p,q) &\\leq  R(p,q-1) + R(p-1,q) && \\textrm{(Erdos-Szekeres recurrence relation)} \\\\\n     &\\leq {p+(q-1)-2 \\choose p-1} + {p-1+q-2 \\choose p-2} \\\\\n     &\\leq {p+q-3 \\choose p-1} + {p+q-3 \\choose p-2} \\\\\n     &\\leq {p+q-2 \\choose p-1}  && ({n+1 \\choose k+1} = {n \\choose k+1} +{n \\choose k})\n \\end{align*}\n\n\\end{proof}\n\\section{Explicit Computation of R(3,4)}\nWe don't know the exact values of Ramsey numbers for higher values as their computation becomes very hard. There is this famous saying by Paul Erdos on the difficulty of computing Ramsey numbers that\n\\begin{description}\n   \\item[Paul Erdos on Ramsey numbers] \n   $ $ \\newline\n\\textit{   \"Suppose aliens invade the earth and threaten to obliterate it in a year's time unless human beings can find the Ramsey number for red five and blue five. We could marshal the world's best minds and fastest computers, and within a year we could probably calculate the value. If the aliens demanded the Ramsey number for red six and blue six, however, we would have no choice but to launch a preemptive attack.\"}\n\\end{description}\n So let us now try to calculate the value of $R(3,4)$. \n \\begin{claim}\n $$ R(3,4) = 9 $$\n \\end{claim}\n \\begin{proof}\n $ $\n Consider any 2-coloring of $K_9$ and call it as $G$. We need to prove that $G$ has either a red $K_3$ or a blue $K_4$. Any vertex in $G$ can have it's incident edges as one of the three cases below\n  \\begin{itemize}\n  \\item \\textbf{Case 1 : }There are at least $4$ red edges going out of the vertex\n  \\item \\textbf{Case 2 : }There are at least $6$ blue edges going out of the vertex\n  \\item \\textbf{Case 3 : }There are exactly $3$ red edges and $5$ blue edges going out of the vertex\n  \\end{itemize}\n However note that not all vertices in $G$ come under \\textbf{Case 3} because, if so then the total sum of degrees of all vertices becomes odd which is not possible. So let $v$ be a vertex in $G$ which does not fall under \\textbf{Case 3}. Then\n \\begin{description}\n    \\item[Case 1 : There are at least 4 red edges going out of $v$ ]\n    $ $ \\newline\n    Let $H_1$ be the subgraph of $G$ formed from the four vertices which are sharing the red edge with $v$.  Since we know that $R(2,4)=4$, $H_1$ with 4 vertices must have a red $K_2$ or a blue $K4$, So along with vertex $v$, $G$ must have a red $K_3$ or a blue $K_4$.\n    \\item[Case 2 :There are at least 6 blue edges going out of $v$]\n    $ $ \\newline\n    Let $H_2$ be the subgraph of $G$ formed from the six vertices which are sharing the blue edge with $v$. Since we know that $R(3,3)=6$, $H_2$ with 6 vertices must have a red $K_3$ or a blue $K3$, So along with vertex $v$, $G$ must have a red $K_3$ or a blue $K_4$.\n    \\item[Proof for tightness]\n    $ $ \\newline\n    To prove that $9$ is tight, we need to show that there is a 2-coloring of $K_8$ such that it does not have red $K_3$ or blue $K_4$. Given below is one such  example\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.5\\linewidth]{images/R34counter_example.png}\n    \\caption{2-coloring of $K_8$ with no red $K_3$ and no blue $K_4$}\n\\end{figure}\n \\end{description}\n  \n \\end{proof}\n As the values $p$, $q$ increases we can only calculate the range of the Ramsey number. The following is a table with value or range of Ramsey numbers for the first few natural numbers.\n \\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=1\\linewidth]{images/RamseyTable.png}\n    \\caption{Table for $R(p,q)$}\n\\end{figure}\n\n% Reetwik Started from here\n\n\\section{Multidimentional Ramsey numbers}\n\\begin{definition}\n$R_k(S_1,S_2,..S_k)$ is mininum number $n$ such that any $k$-edge coloring of $K_n$ must have $K_{S_i}$ of color $i$ for some $i \\in \\{1,2..k\\}$\n\\end{definition}\nWe need to show that why should exist $R_k(S_1,S_2,..S_k)$.\n\\begin{claim}\n$$R_k(S_1,S_2,..S_k) \\leq R_{k/2}(R(S_1,S_2), R(S_3,S_4).... R(S_{k-1},S_k))$$\n\\end{claim}\n\\begin{proof}\nLet $n =  R_{k/2}(R(S_1,S_2), R(S_3,S_4).... R(S_{k-1},S_k))$\\\\\nConsider $K_n$ and any K-edge coloring of the edges of $K_n$\\\\\n\nWe need to show that $\\exists S_1$ clique of color 1 or $S_2$ clique of color 2.\\\\\nConsider colors paired up and rename them $\\{1,2\\} = 1, \\{3,4\\} = 2, ... \\{k-1,k\\} = k/2$ \\\\\nBy the definition of $R_{k/2}$ we are guaranteed $\\exists i$ such that $\\exists$ a clique of size $R(S_{2i-1},S_{2i})$ of color $i$.\\\\\n\nAfter we uninterpret the color $i$ as the original pair of colors we get a 2-coloring of the clique that we have $R(S_{2i-1},S_{2i})$\\\\\nBy the definition of $R_2$ we know that $\\exists$ a $S_{2i-1}$ clique of color $2i-1$ or $S_{2i}$ clique of color $2i$.\n\\end{proof}\n\n\\section{Fermat's last theorem}\nWe know from Pythagoras theorem that $x^2 +y^2 = z^2$ has integral solutions. But we want to know if this equation has any integral solutions for any power greater than $2$.\n\\begin{theorem}\n$x^n +y^n = z^n$ doesn't have any integral solutions $\\forall n>2$.\n\\end{theorem}\n\n\\Lecture{Jayalal Sarma}{Oct 22, 2020}{20}{Finite fields}{Reetwik Das}{$\\alpha$}{JS}\n\n\\subsection{Finite fields}\n$x^n +y^n = z^n$ does have integeral solutions for finite fields such as for $Z_p$.\\\\\n$Z_p = \\{0,1,....p-1\\}$ and addition and multiplication are $modulo$ $p$ within this field.\\\\\n\n\\begin{definition}\n$Z_p^*$ is a cyclic group $\\{1,2,3....p-1\\}$\n\\end{definition}\n\n\\begin{claim}\nIf $p$ is a prime then $Z_p^*$ is generated by a single element, and the element is known as the generator.\n\\end{claim}\n\nFermat's last theorem is completely algebraic to connect it to coloring we need a tool.\n\\begin{theorem}\n\\textbf{Schur's theorem :} If $r \\geq 0$ positive integer then. $\\exists$ integer $S(r)$ such that if we color $\\{1,2,....S(r)\\}$ vertices with $r$ colors then $\\exists x,y,z$ in the set and $x+y =z$\n\\end{theorem}\n\\begin{proof}\nGiven an $r$, Let $S(r) = R_r(3,3,3,...3)$\\\\\nConsider $K_n$, $n = S(r)$ by the definition if we color the edges of $K_n$ using $r$ colors then we are guaranteed a monochromatic $K_3$.\\\\\nWe are given a coloring $\\{1,2,...S(r)\\}$\\\\\nDefine a coloring for edges in $K_n$.\\\\\nAssociate vertices of $K_n$ with elements in $\\{1,2,...S(r)\\}$ \\\\\n$\\forall a,b\\in V$ the color of edge $(a,b) $ = color of $|a-b|$\\\\\n\nLet $\\{\\alpha, \\beta,\\gamma\\}$ be the vertices of the monochromatic triangle.\nLet $x = \\alpha - \\beta$, $y = \\beta - \\gamma$ and $z = \\alpha - \\gamma$ then $x,y,z$ have the same color.\nIt also satifies the equation $x+y =z$.\n \n\\end{proof}\n\n\\begin{theorem}\n$\\forall m \\exists q$ such that $\\forall p\\geq q$ in $Z_p$ ($p$ is a prime) \\\\\n$x^m +y^m = z^m$ has a solution.\n\\end{theorem}\n\\begin{proof}\nGiven $m$ from $ x^m +y^m = z^m$\\\\\n$p=q=S(m)+1$ by Schur's theorem any coloring of $\\{1,2...q\\}$ must have a triplet $a+b = c$.\\\\\n$Z_p = {0,1,2...q-1}$\\\\\nLet $g$ be the generator of $Z_p$ then every non-zero element in $Z_p = g^k$ for some $k$.\\\\\n\nAssign the coloring $\\{1,2...q\\}$ as follows :\\\\\n$\\forall x \\in Z_p^*,  x=g^{mi+j}$ and $color(x)= j = k (mod m)$\\\\\n\nBy Schur's theorem, $\\exists a,b,c$ such that $a+b=c$ and all have the same color.\\\\\n$$g^{mi_a+j} + g^{mi_b+j} = g^{mi_c+j}$$\n$$(g^{i_a})^m + (g^{i_b})^m = (g^{i_c})^m$$\nand we have the solution for $x^m +y^m = z^m$. \n\\end{proof}\n\n\\subsection{Lower bounds for Ramsey numbers}\n\\begin{claim}\n$$\\forall k, R(k,k) > 2^{k/2}$$\n\\end{claim}\n\\begin{proof}\nSuffices to show that $n = 2^{k/2}$, $\\exists$ a 2-coloring of the edges of $K_n$ such that there is no monochromatic $K_k$ in it.\\\\\n\nFix $m = 2^{k/2}$ there are $n\\choose 2$ many edges.\\\\\nA coloring is said to be bad if $\\exists$ no monochromatic $K_k$ in it.\\\\\n\n\\textbf{Probabilistic method :}\\\\\nFor every edge, assign red/blue color with probability 1/2 each.\\\\\nif we show that the probability[coloring is bad]$ > 0$ then this means $\\exists$ a bad coloring.\\\\\n\nSuffices to show that the Pr[coloring is good] $<1$\\\\\nPr[$\\exists K_k$ which is monochromatic] $\\leq \\Sigma_{S \\subseteq K_k,|S|=k}$ Pr[S is monochromatic]\\\\\n$ = {n\\choose k}$ Pr[S is monochromatic]\n$$ = {n\\choose k} \\frac{2}{2^{k\\choose 2}}$$\n$$= {n\\choose k} 2^{1-{k\\choose2}}$$\n$$ =\\frac{n(n-1)...(n-k+1)}{k!} \\frac{2^{1+k/2}}{2^{k^2/2}}$$\n$$ \\leq \\frac{n^k}{k!} \\frac{2^{1+k/2}}{2^{k^2/2}}$$\n$$= \\frac{2^{1+k/2}}{k!} < 1$$\n\\end{proof}\n", "meta": {"hexsha": "84a876f8709a1be38738fbec41da97a4ae1589eb", "size": 17338, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week07.tex", "max_stars_repo_name": "Achyuth-Prakash/theory-toolkit", "max_stars_repo_head_hexsha": "a717e5fecdb6a52689fadd6e64baa23182f15435", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week07.tex", "max_issues_repo_name": "Achyuth-Prakash/theory-toolkit", "max_issues_repo_head_hexsha": "a717e5fecdb6a52689fadd6e64baa23182f15435", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-10-08T07:34:26.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-30T06:06:12.000Z", "max_forks_repo_path": "week07.tex", "max_forks_repo_name": "Achyuth-Prakash/theory-toolkit", "max_forks_repo_head_hexsha": "a717e5fecdb6a52689fadd6e64baa23182f15435", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2020-09-25T01:35:07.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-28T11:22:06.000Z", "avg_line_length": 56.660130719, "max_line_length": 422, "alphanum_fraction": 0.6843926635, "num_tokens": 5721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388040954683, "lm_q2_score": 0.8807970842359877, "lm_q1q2_score": 0.7301268816573551}}
{"text": "\\lab{Convolution and Filtering}{Convolution and Filtering}\n\\objective{The Fourier transform reveals information in the frequency domain about signals and images that might not be apparent in the usual time (sound) or spatial (image) domain.\n% It provides an extremely powerful tool to analyze difficult problems simply.\nIn this lab, we use the discrete Fourier transform to efficiently convolve sound signals and filter out some types of unwanted noise from both sounds and images.\nThis lab is a continuation of the Discrete Fourier Transform lab and should be completed in the same Jupyter Notebook.}\n\n\\section*{Convolution} % ======================================================\n\nMixing two sounds signals---a common procedure in signal processing and analysis---is usually done through a \\emph{discrete convolution}.\n% Recall that sound is modeled with discrete samples of a sound wave in rapid succession.\nGiven two periodic sound sample vectors $\\f$ and $\\g$ of length $n$, the discrete convolution of $\\f$ and $\\g$ is a vector of length $n$ where the $k$th component is given by\n\\begin{align}\n(\\f \\ast \\g)_k = \\sum_{j=0}^{n-1} f_{k-j}g_j,\\qquad k = 0,1,2,\\dots,n-1.\n\\label{eq:naive-convolve}\n\\end{align}\n\nSince audio needs to be sampled frequently to create smooth playback, a recording of a song can contain tens of millions of samples; even a one-minute signal has $2,646,000$ samples if it is recorded at the standard rate of $44,100$ samples per second ($44,100$ Hz).\nThe na\\\"ive method of using the sum in \\eqref{eq:naive-convolve} $n$ times is $O(n^2)$, which is often too computationally expensive for convolutions of this size.\n\nFortunately, the discrete Fourier transform (DFT) can be used compute convolutions efficiently.\nThe \\emph{finite convolution theorem} states that the Fourier transform of a convolution is the element-wise product of Fourier transforms:\n\\begin{align}\nF_n(\\f \\ast \\g) = n(F_n\\f)\\odot (F_n\\g).\n\\label{eq:convolution-theorem}\n\\end{align}\nIn other words, convolution in the time domain is equivalent to component-wise multiplication in the frequency domain.\nHere $F_n$ is the DFT on $\\mathbb{R}^n$, $\\ast$ is discrete convolution, and $\\odot$ is component-wise multiplication. % (the \\emph{Hadamard product}).\nThus, the convolution of $\\f$ and $\\g$ can be computed by\n\\begin{align}\n\\f \\ast \\g = nF_n^{-1}((F_n\\f)\\odot (F_n\\g)),\n\\label{eq:fft-convolution}\n\\end{align}\nwhere $F_n^{-1}$ is the \\emph{inverse discrete Fourier transform} (IDFT).\nThe fast Fourier transform (FFT) puts the cost of \\eqref{eq:fft-convolution} at $O(n\\log{n})$, a huge improvement over the na\\\"ive method.\n\n\\begin{info} % Discard imaginaries after IDFT\nAlthough individual samples are real numbers, results of the IDFT may have small complex components due to rounding errors.\nThese complex components can be safely discarded by taking only the real part of the output of the IDFT.\n\n\\begin{lstlisting}\n>>> import numpy\n>>> from scipy.fftpack import fft, ifft # Fast DFT and IDFT functions.\n\n>>> f = np.random.random(2048)\n>>> f_dft_idft = ifft(fft(f)).real      # Keep only the real part.\n>>> np.allclose(f, f_dft_idft)          # Check that IDFT(DFT(f)) = f.\n<<True>>\n\\end{lstlisting}\n\\end{info}\n\n\\begin{warn} % SciPy conventions\nSciPy uses a different convention to define the DFT and IDFT than this and the previous lab, resulting in a slightly different form of the convolution theorem.\nWriting SciPy's DFT as $\\hat{F}_n$ and its IDFT as $\\hat{F}_n^{-1}$, we have $\\hat{F}_n = n F_n$, so \\eqref{eq:fft-convolution} becomes\n\\begin{align}\n\\f \\ast \\g = \\hat{F}_n^{-1}((\\hat{F}_n\\f)\\odot (\\hat{F}_n\\g)),\n\\label{eq:fft-convolution-scipy}\n\\end{align}\nwithout a factor of $n$.\nUse \\eqref{eq:fft-convolution-scipy}, not \\eqref{eq:fft-convolution}, when using \\li{fft()} and \\li{ifft()} from \\li{scipy.fftpack}.\n\\end{warn}\n\n\\subsection*{Circular Convolution} % ------------------------------------------\n\nThe definition \\eqref{eq:naive-convolve} and the identity \\eqref{eq:fft-convolution} require $\\f$ and $\\g$ to be periodic vectors.\nHowever, the convolution $\\f \\ast \\g$ can always be computed by simply treating each vector as periodic.\nThe convolution of two raw sample vectors is therefore called the \\emph{periodic} or \\emph{circular convolution}.\nThis strategy mixes sounds from the end of each signal with sounds at the beginning of each signal.\n\n\\begin{problem} % Circular convolution.\n\\item Implement the \\li{__mul__()} magic method for the \\li{SoundWave} class so that if \\li{A} and \\li{B} are \\li{SoundWave} instances, \\li{A * B} creates a new \\li{SoundWave} object whose samples are the circular convolution of the samples from \\li{A} and \\li{B}.\nIf the samples from \\li{A} and \\li{B} are not the same length, append zeros to the shorter array to make them the same length before convolving.\nUse \\li{scipy.fftpack} and \\eqref{eq:fft-convolution-scipy} to compute the convolution, and raise a \\li{ValueError} if the sample rates from \\li{A} and \\li{B} are not equal.\n\nA circular convolution creates an interesting effect on a signal when convolved with a segment of white noise: the sound loops seamlessly from the end back to the beginning.\nTo see this, generate two seconds of white noise (at the same sample rate as \\texttt{tada.wav}) with the following code.\n\\begin{lstlisting}\n>>> rate = 22050        # Create 2 seconds of white noise at a given rate.\n>>> white_noise = np.random.randint(-32767, 32767, rate*2, dtype=np.int16)\n\\end{lstlisting}\nNext, convolve \\texttt{tada.wav} with the white noise.\nFinally, use the \\li{>>} operator to append the convolution result to itself.\nThis final signal sounds the same from beginning to end, even though it is the concatenation of two signals.\n\\end{problem}\n\n\\subsection*{Linear Convolution} % --------------------------------------------\n\nAlthough circular convolutions can give interesting results, most common sound mixtures do not combine sounds at the beginning of one signal with sounds at the end of another.\nWhereas circular convolution assumes that the samples represent a full period of a periodic function, \\emph{linear convolution} aims to combine non-periodic discrete signals in a way that prevents the beginnings and endings from interacting.\nGiven two samples with lengths $n$ and $m$, the simplest way to achieve this is to pad both samples with zeros so that they each have length $n+m-1$, compute the convolution of these larger arrays, and take the first $n+m-1$ entries of that convolution.\n\n\\begin{problem} % Linear convolution.\n\\item Implement the \\li{__pow__()} magic method for the \\li{SoundWave} class so that if \\li{A} and \\li{B} are \\li{SoundWave} instances, \\li{A ** B} creates a new \\li{SoundWave} object whose samples are the linear convolution of the samples from \\li{A} and \\li{B}.\nRaise a \\li{ValueError} if the sample rates from \\li{A} and \\li{B} are not equal.\n\nBecause \\li{scipy.fftpack} performs best when the length of the inputs is a power of $2$, start by computing the smallest $2^a$ such that $2^a \\ge n + m - 1$, where $a\\in\\mathbb{N}$ and $n$ and $m$ are the number of samples from \\li{A} and \\li{B}, respectively.\nAppend zeros to each sample so that they each have $2^a$ entries, then compute the convolution of these padded samples using \\eqref{eq:fft-convolution-scipy}.\nUse only the first $n + m - 1$ entries of this convolution as the samples of the returned \\li{SoundWave} object.\n\nTo test your method, read \\texttt{CGC.wav} and \\texttt{GCG.wav}.\nTime (separately) the convolution of these signals with \\li{SoundWave.__pow__()} and with \\li{scipy.signal.fftconvolve()}.\nCompare the results by listening to the original and convolved signals.\n\\label{prob:fft-linear-convolution}\n\\end{problem}\n\n\\begin{problem} % Convolve the balloon pop with Chopin.\nClapping in a large room with an echo produces a sound that resonates in the room for up to several seconds.\nThis echoing sound is referred to as the \\emph{impulse response} of the room, and is a way of approximating the acoustics of a room.\nWhen the sound of a single instrument in a carpeted room is convolved with the impulse response from a concert hall, the new signal sounds as if the instrument is being played in the concert hall.\n\nThe file \\texttt{chopin.wav} contains a short clip of a piano being played in a room with little or no echo, and \\texttt{balloon.wav} is a recording of a balloon being popped in a room with a substantial echo (the impulse).\nUse your method from Problem \\ref{prob:fft-linear-convolution} or \\li{scipy.signal.fftconvolve()} to compute the linear convolution of \\texttt{chopin.wav} and \\texttt{balloon.wav}.\n% Listen to the new signal; there should be echo in the piano recording.\n\\end{problem}\n\n\\section*{Filtering Frequencies with the DFT} % ===============================\n\nThe DFT also provides a way to clean a signal by altering some of its frequencies.\nConsider \\texttt{noisy1.wav}, a noisy recording of a short voice clip.\nThe time-domain plot of the signal only shows that the signal has a lot of static.\nOn the other hand, the signal's DFT suggests that the static may be the result of some concentrated noise between about $1250$--$2600$ Hz.\nRemoving these frequencies could result in a much cleaner signal.\n\n\\begin{figure}[H]\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.53\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/noisy1.pdf}\n\\end{subfigure}%\n\\begin{subfigure}{.47\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/noisy1_dft.pdf}\n\\end{subfigure}\n\\caption{The time-domain plot (left) and DFT (right) of \\texttt{noisy1.wav}.}\n\\label{fig:fft-noisy-signal}\n\\end{figure}\n\nTo implement this idea, recall that the $k$th entry of the DFT array $\\c = F_n \\f$ corresponds to the frequency $v = k r / n$ in Hertz, where $r$ is the sample rate and $n$ is the number of samples.\nHence, the DFT entry $c_k$ corresponding to a given frequency $v$ in Hertz has index $k = v n / r$, rounded to an integer if needed.\nIn addition, since the DFT is symmetric, $c_{n-k}$ also corresponds to this frequency. %; any changes to $c_k$ must also be done to $c_{n-k}$ in order to alter the signal.\nThis suggests a strategy for filtering out an unwanted interval of frequencies $[v_\\text{low},v_\\text{high}]$ from a signal:\n\\begin{enumerate}\n\\item Compute the integer indices $k_\\text{low}$ and $k_\\text{high}$ corresponding to $v_\\text{low}$ and $v_\\text{high}$, respectively.\n\\item Set the entries of the signal's DFT from $k_\\text{low}$ to $k_\\text{high}$ and from $n-k_\\text{high}$ to $n-k_{low}$ to zero, effectively removing those frequencies from the signal.\n\\item Take the IDFT of the modified DFT to obtain the cleaned signal.\n\\end{enumerate}\nUsing this strategy to filter \\texttt{noisy1.wav} results in a much cleaner signal. %, shown in Figure \\ref{fig:fft-noisy-cleaned}.\nHowever, any ``good'' frequencies in the affected range are also removed, which may decrease the overall sound quality.\nThe goal, then, is to remove only as many frequencies as necessary.\n\n\\begin{figure}[H]\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.53\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/noisy1_clean.pdf}\n\\end{subfigure}%\n\\begin{subfigure}{.47\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/noisy1_clean_dft.pdf}\n\\end{subfigure}\n\\caption{The time-domain plot (left) and DFT (right) of \\texttt{noisy1.wav} after being cleaned.}\n\\label{fig:fft-noisy-cleaned}\n\\end{figure}\n\n\\begin{problem} % Clean up a noisy signal (The only thing we have to fear...)\n\\label{prob:fft-filter-frequencies}\nAdd a method to the \\li{SoundWave} class that accepts two frequencies $v_\\text{low}$ and $v_\\text{high}$ in Hertz.\nCompute the DFT of the stored samples and zero out the frequencies in the range $[v_\\text{low}, v_\\text{high}]$ (remember to account for the symmetry DFT).\nTake the IDFT of the altered array and store it as the sample array.\n% \\\\(Hint: be sure to sure the indices of the DFT array are integers.)\n\nTest your method by cleaning \\texttt{noisy1.wav}, then clean \\texttt{noisy2.wav}, which also has some artificial noise that obscures the intended sound.\n\\\\(Hint: plot the DFT of \\texttt{noisy2.wav} to determine which frequencies to eliminate.)\n\\end{problem}\n\nA digital audio signal made of a single sample vector with is called \\emph{monoaural} or \\emph{mono}.\nWhen several sample vectors with the same sample rate and number of samples are combined into a matrix, the overall signal is called \\emph{stereophonic} or \\emph{stereo}.\nThis allows multiple speakers to each play one \\emph{channel}---one of the original sample vectors---simultaneously.\n``Stereo'' usually means there are two channels, but there may be any number of channels ($5.1$ surround sound, for instance, has five).\n\n% \\begin{warn}\nMost stereo sounds are read as $n\\times m$ matrices, where $n$ is the number of samples and $m$ is the number of channels (i.e., each column is a channel).\nHowever, some functions, including Jupyter's embedding tool \\li{IPython.display.Audio()}, receive stereo signals as $m\\times n$ matrices (each row is a channel).\nBe aware that both conventions are common.\n% \\end{warn}\n\n% When a digital audio signal is played on a computer, the signal is sent to a speaker, which vibrates, producing sound waves.\n% When multiple speakers are used, they can all produce the same signal or they can produce different signals.\n% When there is only one signal, the sound is \\emph{monoaural}, or \\emph{mono}.  When speakers produce more than one signal, the overall signal is \\emph{stereophonic}, or \\emph{stereo}.\n% Usually stereo means two, but there may be any number of signals ($5.1$ surround sound, for instance, has $5$).\n\n% Most sounds are multi-dimensional, but can be treated similarly to mono sounds.\n% The first and second columns of the array sample correspond to the signals for the left and right speaker respectively.\n\n\\begin{problem}\n\\label{prob:fft-vuvuzelas}\nDuring the 2010 World Cup in South Africa, large plastic horns called vuvuzelas were blown excessively throughout the games.\nBroadcasting organizations faced difficulties with their programs due to the incessant noise level.\nEventually, audio filtering techniques were used to cancel out the sound of the vuvuzela, which has a frequency of around $200$--$500$ Hz.\n\nThe file \\li{vuvuzela.wav}\\footnote{See \\url{https://www.youtube.com/watch?v=g_0NoBKWCT8}.} is a stereo sound with two channels.\nUse your function from Problem \\ref{prob:fft-filter-frequencies} to clean the sound clip by filtering out the vuvuzela frequencies in each channel.\nRecombine the two cleaned samples.\n\\end{problem}\n\n% \\begin{info} % Notch filtering and other filters\n% The cleaning strategy of Problems \\ref{prob:fft-filter-frequencies} and \\ref{prob:fft-vuvuzelas} is called \\emph{notch filtering} and is a special case of \\emph{band-stop filtering}.\n% \\end{info}\n\n\\subsection*{The Two-dimensional Discrete Fourier Transform} % ----------------\n\nThe DFT can be easily extended to any number of dimensions.\nComputationally, the problem reduces to performing the usual one-dimensional DFT iteratively along each of the dimensions.\nFor example, to compute the two-dimensional DFT of an $m \\times n$ matrix, calculate the usual DFT of each of the $n$ columns, then take the DFT of each of the $m$ rows of the resulting matrix.\nCalculating the two-dimensional IDFT is done in a similar fashion, but in reverse order: first calculate the IDFT of the rows, then the IDFT of the resulting columns.\n\n\\begin{lstlisting}\n>>> from scipy.fftpack import fft2, ifft2\n\n>>> A = np.random.random((10,10))\n>>> A_dft = fft2(A)                 # Calculate the 2d DFT of A.\n>>> A_dft_ifft = ifft2(A_dft).real  # Calculate the 2d IDFT.\n>>> np.allclose(A, A_dft_ifft)\n<<True>>\n\\end{lstlisting}\n\n% The DFT for matrices is useful for a variety of image applications, including cleaning, compression, enhancement, and edge detection.\nJust as the one-dimensional DFT can be used to remove noise in sounds, its two-dimensional counterpart can be used to remove ``noise'' in images.\nThe procedure is similar to the filtering technique in Problems \\ref{prob:fft-filter-frequencies} and \\ref{prob:fft-vuvuzelas}: take the two-dimensional DFT of the image matrix, modify certain entries of the DFT matrix to remove unwanted frequencies, then take the IDFT to get a cleaner version of the original image.\nThis strategy makes the fairly strong assumption that the noise in the image is periodic and corresponds to certain frequencies.\nWhile this may seem like an unlikely scenario, it does actually occur in many digital images---for an example, try taking a picture of a computer screen with a digital camera.\n\n\\begin{figure}[H]\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.4\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/blurry_face.png}\n    \\caption{The original blurry image.}\n    \\label{fig:blurry_face}\n\\end{subfigure}\n\\begin{subfigure}{.4\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/blurry_fft.png}\n    \\caption{The DFT of the original image.}\n    \\label{fig:blurry_fft}\n\\end{subfigure}\n\\begin{subfigure}{.4\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/improved_face.png}\n    \\caption{The improved image.}\n    \\label{fig:improved_face}\n\\end{subfigure}\n\\begin{subfigure}{.4\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/covered_fft.png}\n    \\caption{The DFT of the improved image.}\n    \\label{fig:covered_fft}\n\\end{subfigure}\n\\caption{To remove noise from an image, take the DFT of the image and replace the abnormalities with values more consistent with the rest of the DFT.\nNotice that the new image is less noisy, but only slightly.\nThis is because only some of the abnormalities in the DFT were changed; in order to further decrease the noise, we would need to further alter the DFT.}\n\\label{fig:image_fft}\n\\end{figure}\n\nTo begin cleaning an image with the DFT, take the two-dimensional DFT of the image matrix.\nIdentify \\emph{spikes}---abnormally high frequency values that may be causing the noise---in the image DFT by plotting the log of the magnitudes of the Fourier coefficients.\nWith \\li{cmap=\"gray\"}, spikes show up as bright spots.\nSee Figures \\ref{fig:blurry_face}--\\ref{fig:blurry_fft}.\n\n\\begin{lstlisting}\n# Read the image.\n>>> import imageio\n>>> im = imageio.read(\"noisy_face.png\")\n\n# Plot the log magnitude of the image's DFT.\n>>> im_dft = fft2(image)\n>>> plt.imshow(np.log(np.<<abs>>(im_dft)), cmap=\"gray\")\n>>> plt.show()\n\\end{lstlisting}\n\nInstead of setting spike frequencies to zero (as was the case for sounds), replace them with values that are similar to those around them.\nThere are many ways to do this, but one convention is to simply ``patch'' each spike by setting portions of the DFT matrix to some set value, such as the mean of the DFT array.\nSee Figure \\ref{fig:covered_fft}.\n\nOnce the spikes have been covered, take the IDFT of the modified DFT to get a (hopefully cleaner) image.\nNotice that Figure \\ref{fig:improved_face} still has noise present, but it is a slight improvement over the original.\nHowever, it often suffices to remove some of the noise, even if it is not possible to remove it all with this method.\n\n\\begin{problem} % Clean an image.\nThe file \\texttt{license\\_plate.png} contains a noisy image of a license plate.\nThe bottom right corner of the plate has is a sticker with information about the month and year that the vehicle registration was renewed.\nHowever, in its current state, the year is not clearly legible.\n\nUse the two-dimensional DFT to clean up the image enough so that the year in the bottom right corner is legible.\nThis may require a little trial and error.\n\\end{problem}\n\n\\begin{comment}\n\\newpage\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Other Convolution Functions} % -----------------------------------\n\nTalk about the options in \\li{np.covolve()}, etc. (circular by default).\nUse \\li{scipy.ndimage.convolve()} to do circular convolution if needed (but the results must be shifted to match what we do).\n\n\\subsection*{Other Sound Filters} % -------------------------------------------\n\nWhat we did is called a notch filter, blah blah blah...\n\n\\subsection{Other Image Filters} % --------------------------------------------\n\nOverview of the following comment?\n\n\\end{comment}\n\n\\begin{comment} % VERY OLD (and bad) image filtering section ==================\n\n\\section*{Image Filters}\n\nRecall that a computer stores an image as a 2-D array of pixel values (i.e., a matrix of intensities).\nAn image filter is a function that transforms an image by operating on it locally.\nThat is, to compute the $(ij)$th pixel value in the new image, an image filter uses only the pixels in a small neighborhood around the $(ij)$th pixel in the original image.\n\nIn this lab, we use a filter derived from the gradient of an image to find edges in an image.\n\n\\subsection*{Convolutions}\n\nOne example of an image filter is to \\emph{convolve} an image with a filter matrix.\nA filter matrix is a matrix whose height and width are relatively small odd numbers.\nIf the filter matrix is\n\\[\nF = \\begin{pmatrix}\nf_{-1,-1}&f_{-1,0}&f_{-1,1}\\\\\nf_{0,-1}&f_{0,0}&f_{0,1}\\\\\nf_{1,-1}&f_{1,0}&f_{1,1}\n\\end{pmatrix},\n\\]\nthen the convolution of an image $A$ with $F$ is $A \\ast F = (C_{ij})$ where\n\\begin{equation}\\label{equ:convolve}\nC_{ij} = \\sum_{k=-1}^1 \\sum_{\\ell=-1}^1 f_{k\\ell}A_{i+k,j+\\ell}.\n\\end{equation}\nSay $A$ is an $m \\times n$ matrix. Here, we take $A_{ij}=0$ when $i \\not \\in \\{1, \\ldots m\\}$ or $j \\not \\in \\{1, \\ldots, n\\}$.\nThe value of $C_{ij}$ is a linear combination of the nearby pixel values, with coefficients given by $F$ (see Figure \\ref{fig:convolution}).\nIn fact, $C_{ij}$ equals the Frobenius inner product of $F$ with the $3 \\times 3$ submatrix of $A$ centered at $ij$.\n\n\\begin{figure}\n\\centering\n\\begin{tikzpicture}\n\\node[draw, minimum width=12cm, minimum height=\n    7cm, ultra thick](outer_rec)[]{};\n\\node[draw, minimum width=10cm, minimum height=\n    5cm, ultra thick, fill=black!10!](inner_rec)[]{};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick, fill=black!30!](square1)at(-4.75,2.25){\\textbullet};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick,fill=black!30!](square2)at(-1.75,-.75){\\textbullet};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick, fill=black!30!](square3)at(4.75,.75){\\textbullet};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick, fill=black!30!](square4)at(3.25,-1.25){\\textbullet};\n\\draw[step=.5, ultra thin, color=black!50!](-6,-3.5)grid(6,3.5);\n\n\\node[draw, minimum width=10cm, minimum height=\n    5cm, ultra thick, ][]{};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick]at(-4.75,2.25){};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick]at(-1.75,-.75){};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick]at(4.75,.75){};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick]at(3.25,-1.25){};\n\\end{tikzpicture}\n\\caption{This diagram illustrates how to convolve an image with a filter.\nThe light grey rectangle represents the original image $A$, and the dark grey squares are the filter $F$.\nThe larger rectangle is the image padded with zeros; i.e., all pixel values in the outer white band are 0.\nTo compute the entry of the convolution matrix $C$ located at a black dot, take the inner product of $F$ with the submatrix of the padded image centered at the dot.}\n\\label{fig:convolution}\n\\end{figure}\n\n\\subsubsection*{Implementation in NumPy}\n\nLet us write a function that convolves an image with a filter.\nYou can test this function on the image \\li{cameraman.jpg}, which appears in Figure \\ref{fig:cameraman}.\nThe following code loads this image and plots it with matplotlib.\n\n\\begin{lstlisting}\n>>> image = plt.imread('cameraman.jpg')\n>>> plt.imshow(image, cmap = 'gray')\n>>> plt.show()\n\\end{lstlisting}\n\nHere is the function definition and some setup.\n\n\\begin{lstlisting}\n1. def Filter(image, F):\n2.     m, n = image.shape\n3.     h, k = F.shape\n\\end{lstlisting}\n\nTo convolve \\li{image} with the filter \\li{F}, we must first \\emph{pad} the array \\li{image} with zeros around the edges.\nThis is because in \\eqref{equ:convolve}, entries $A_{ij}$ are set to zero when $i$ or $j$ is out of bounds.\nWe do this by creating a larger array of zeros, and then making the interior part of the array equal to the original image (see Figure \\ref{fig:convolution}).\n\nFor example, if the filter is a $3 \\times 3$ matrix, then the following code pads the matrix with the appropriate number of zeros.\n\n\\begin{lstlisting}\n # Create a larger matrix of zeros\nimage_pad = np.zeros((m+2, n+2))\n# Make the interior of image_pad equal to the original image\nimage_pad[1:1+m, 1:1+n] = image\n\\end{lstlisting}\n\nWe want to do this in general in our function.  Note that the number of zeros we need to pad our array depends on the size of the filter \\li{F}.\n\n\\begin{lstlisting}\n5.    image_pad = # Create an array of zeros of the appropriate size\n6.   # Make the interior of image_pad equal to image\n\\end{lstlisting}\n\nFinally, we iterate through the image to compute each entry of the convolution matrix.\n\n\\begin{lstlisting}\n7.    C = np.zeros(image.shape)\n8.    for i in range(m):\n9.        for j in range(n):\n10.            C[i,j] = # Compute C[i, j]\n\\end{lstlisting}\n\n\\subsubsection*{Gaussian Blur}\n\nA \\emph{Gaussian blur} is an image filter that operates on an image by convolving with the matrix\n\\[\nG = \\frac{1}{159}\\begin{pmatrix}\n2&4&5&4&2\\\\\n4&9&12&9&4\\\\\n5&12&15&12&5\\\\\n4&9&12&9&4\\\\\n2&4&5&4&2\n\\end{pmatrix}.\n\\]\n\nBlurring an image can remove ``noise'', or random variation that is the visual analog of static in a radio signal (and equally undesirable).\n\n\\begin{problem}\\label{prob:filter}\n\\leavevmode\nFinish writing the function \\li{Filter} by filling in lines 5, 6, and 10.  Hint: Note in \\ref{equ:convolve}, $C_{ij}$ was calculated by summing from -1 to 1.  This is only the case if the filter \\li{F} is $3 \\times 3$. A slight modification is needed in the general case.  Test your function on the image \\li{cameraman.jpg} using the Gaussian Blur. The result is in Figure \\ref{fig:cameraman_blur}.\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n% \\includegraphics[width=\\textwidth]{figures/cameraman.jpg}\n\\caption{Unfiltered image.}\n\\label{fig:cameraman}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n% \\includegraphics[width=\\textwidth]{figures/cameramanBlur.pdf}\n\\caption{Image after Gaussian blur is applied.}\n\\label{fig:cameraman_blur}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n% \\includegraphics[width=\\textwidth]{figures/edges.pdf}\n\\caption{Image after the Sobel filter is applied.}\n\\label{fig:cameraman_edges}\n\\end{subfigure}\n\\caption{Here is an example of a Gaussian blur and the Sobel filter applied to an image.\nThis photo, known as ``cameraman,'' is a standard test image in image processing.\nA database of such images can be downloaded from \\url{http://www.imageprocessingplace.com/root_files_V3/image_databases.htm}.}\n\\label{fig:cameraman1}\n\\end{figure}\n\n\\subsection*{Edge Detection}\n\nAutomatic detection of edges in an image can be used to segment or sharpen the image.\nWe find edges with the Sobel filter, which computes the gradient of the image at each pixel.\nThe magnitude of the gradient tells us the rate of change of the pixel values, and so large magnitudes should\ncorrespond to edges within the image.\nThe Sobel filter is not a convolution, although it does use convolutions.\n\nWe can think of an image as a function from a $2 \\times 2$ grid of points to $\\mathbb{R}$.\nThe image maps a pixel location to an intensity.\nIt does not make sense to define the derivative of this function as a limit because the domain is discrete---a step size $h$ cannot take on arbitrarily small values.\nInstead, we \\emph{define} the derivative to be the centered difference quotient of the previous section.\nThat is, we define the derivative in the $x$-direction at the $ij$th pixel to be\n\\[\n\\frac{1}{2}A_{i+1, j} - \\frac{1}{2}A_{i-1, j}.\n\\]\n\nWe can use a convolution to create a matrix $A_x$ whose $ij$th entry is the derivative of $A$ at the $ij$th entry, in the $x$-direction.\nIn fact, $A_x = A \\ast S$, where\n\\[\nS = \\frac{1}{8}\n\\left[\\begin{array}{ccc}\n-1 & 0 & 1\\\\\n-2 & 0 & 2\\\\\n-1 & 0 & 1\n\\end{array}\\right].\n\\]\n\nNote that this convolution takes a weighted average of the $x$-derivatives at $(i, j)$, $(i, j+1)$, and $(i, j-1)$.\nThe derivative at $(i, j)$ is weighted by 2.\nUsing a weighted average instead of just the derivative at $(i, j)$ makes the derivative less affected by noise.\n\nNow we can define the Sobel filter.\nA Sobel filter applied to an image $A$ results in an array $B = (B_{ij})$ of 0's and 1's, where the 1's trace out the edges in the image.\nBy definition,\n\\[\nB_{ij} = \\left\\{\n     \\begin{array}{ll}\n       1 & \\text{if}\\; \\;\\|\\nabla A(ij)\\|_2 > M \\\\\n       0 & \\text{otherwise}.\n     \\end{array}\n   \\right.\n\\]\nHere, $\\nabla A(ij) = ((A \\ast S)_{ij}, (A\\ast S^T)_{ij})$ is the gradient of $A$ at the $ij$th pixel.\nThe constant $M$ should be ``sufficiently large'' enough to pick out those pixels with the largest gradient (i.e., those pixels that are part of an edge).\nA good choice for $M$ is 4 times the average value of $\\|\\nabla A(ij)\\|_2$ over the whole image $A$.\n\nWhen the Sobel filter is applied to \\li{cameraman.jpg}, we get the image in Figure \\ref{fig:cameraman_edges}.\nHere, the 1's in $B$ were mapped to ``white'' and the 0's were mapped to ``black.''\n\n\\begin{problem}\nWrite a function that accepts an image as input and applies the Sobel filter to the image.  Test your function on \\li{cameraman.jpg}.  Hint: If you want to find the average of a matrix \\li{A}, use the function \\li{A.mean()}.\n\\end{problem}\n\n\\end{comment}\n", "meta": {"hexsha": "40241395234c4bb1951acfc1ddee9a98180c657d", "size": 30069, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume2/FourierTransform/ConvolutionFiltering.tex", "max_stars_repo_name": "frigusgulo/Labs", "max_stars_repo_head_hexsha": "58faeab611e2d54bf2debded58d6e13db40f4146", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-27T06:20:37.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-27T06:20:37.000Z", "max_issues_repo_path": "Volume2/FourierTransform/ConvolutionFiltering.tex", "max_issues_repo_name": "frigusgulo/Labs", "max_issues_repo_head_hexsha": "58faeab611e2d54bf2debded58d6e13db40f4146", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-10-18T19:57:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-31T19:00:36.000Z", "max_forks_repo_path": "Volume2/FourierTransform/ConvolutionFiltering.tex", "max_forks_repo_name": "frigusgulo/Labs", "max_forks_repo_head_hexsha": "58faeab611e2d54bf2debded58d6e13db40f4146", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.308988764, "max_line_length": 398, "alphanum_fraction": 0.7353753035, "num_tokens": 8243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8807970764133561, "lm_q1q2_score": 0.7301268788950743}}
{"text": "\\section{Spans, Linear Independence and Steinitz Exchange Lemma}\r\nIn this section, we shall characterise the properties of the dimension and basis of a vector space.\r\n\\begin{definition}[Span of a Family of Vectors]\r\n    Let $V$ be a vector space over $F$ and $S\\subset V$.\r\n    We define the span of $S$ to be\r\n    $$\\langle S\\rangle=\\operatorname{span}(S)=\\left\\{\\sum_{i=1}^n\\lambda_is_i:n\\in\\mathbb N,\\lambda_i\\in F,s_i\\in S\\right\\}$$\r\n\\end{definition}\r\nThat is, $\\langle S\\rangle$ consists of all possible (finite) linear combination of elements of $S$.\r\nBy convention, we say $\\langle \\varnothing\\rangle=\\{0\\}$.\r\nNote also that the span of $S$ is essentially the minimal subspace of $V$ containing $S$.\r\n\\begin{example}\r\n    1. Take $V=\\mathbb R^3$ and\r\n    $$S=\\left\\{\\begin{pmatrix}\r\n        1\\\\\r\n        0\\\\\r\n        0\r\n    \\end{pmatrix},\\begin{pmatrix}\r\n        0\\\\\r\n        1\\\\\r\n        2\\\\\r\n    \\end{pmatrix},\\begin{pmatrix}\r\n        3\\\\\r\n        -2\\\\\r\n        -4\r\n    \\end{pmatrix}\\right\\}$$\r\n    then\r\n    $$\\langle S\\rangle=\\left\\{\\begin{pmatrix}\r\n        a\\\\\r\n        b\\\\\r\n        2b\r\n    \\end{pmatrix}:a,b\\in\\mathbb R\\right\\}$$\r\n    2. Take $V=\\mathbb R^n$ and let $e_i$ be the vector in $V$ that only has $1$ at the $i^{th}$ entry and zero elsewhere, then $\\langle \\{e_i\\}_{i=1}^n\\rangle=V$.\\\\\r\n    3. Let $V=\\mathbb R^X$ and $S_x:X\\to\\mathbb R$ be such that $S_x(y)=1_{x=y}$.\r\n    Then $\\langle \\{S_x\\}_{x\\in\\mathbb R}\\rangle$ are the set of functions $f\\in\\mathbb R^X$ that has finite support.\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $V$ be a vector space over $F$ and $S\\subset V$.\r\n    We say $S$ spans $V$ if $\\langle S\\rangle =V$.\r\n\\end{definition}\r\n\\begin{example}\r\n    Take $V=\\mathbb R^2$, then any set of two non-parallel vectors would span $V$.\r\n\\end{example}\r\n\\begin{definition}\r\n    A vector space $V$ over a field $F$ is finite dimensional if there is a finite $S\\subset V$ that spans $V$.\r\n\\end{definition}\r\n\\begin{example}\r\n    The space $V=\\mathbb P[x]$ be the set of polynomials in $\\mathbb R$ and $V_n=\\mathbb P_n[x]$ be the set of real polynomials with degree at most $n$.\r\n    Then $V_n=\\langle\\{1,x,\\ldots,x^n\\}\\rangle$ is finite dimensional, but $V$ is not finite dimensional as any finite set of polynomials must be contained in $V_n$ where $n$ is the maximal degree of polynomials in that set.\r\n\\end{example}\r\nAs $\\mathbb N$ is well-ordered, there must be a minimum number of vectors that can possibly span $V$.\r\nWe then focus on how to capture this minimality.\r\n\\begin{definition}[(Linear) Independence]\r\n    Let $V$ be a vector space over $F$.\r\n    We say $\\{v_1,\\ldots,v_n\\}\\subset V$ are (linearly) independent (or is a free family) if for any $\\lambda_1,\\ldots,\\lambda_n\\in F$\r\n    $$\\sum_{i=1}^n\\lambda_iv_i=0\\implies\\forall i,\\lambda_i=0$$\r\n    On the other hand, this set is not linearly independent if there exists $\\lambda_1,\\ldots,\\lambda_n\\in F$ not all zero such that $\\sum_{i=1}^n\\lambda_iv_i=0$.\r\n\\end{definition}\r\n\\begin{example}\r\n    Let $V=\\mathbb R^3$ and\r\n    $$v_1=(1,0,0)^\\top,v_2=(0,1,0)^\\top,v_3=(1,1,0)^\\top,v_4=(0,1,1)^\\top$$\r\n    Then $\\{v_1,v_2\\}$ is linearly independent.\r\n    Note that $v_3\\in\\langle\\{v_1,v_2\\}\\rangle$, so $\\{v_1,v_2,v_3\\}$ is not linearly independent.\r\n    On the other hand, $v_4\\notin\\langle\\{v_1,v_2\\}\\rangle$, which as one can verify means that $\\{v_1,v_2,v_4\\}$ is linearly independent.\r\n\\end{example}\r\n\\begin{remark}\r\n    If the family $\\{v_i\\}_{1\\le i\\le n}$ is linearly independent, then none of $v_i$ is zero.\r\n\\end{remark}\r\n\\begin{definition}[Basis]\r\n    A subset $S\\subset V$ is a basis if it is linearly independent and $\\langle S\\rangle=V$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    When $S$ spans $V$, we say that $S$ is a generating family of $V$.\r\n    So a basis is just a linearly independent generating family.\r\n\\end{remark}\r\n\\begin{example}\r\n    1. Take $V=\\mathbb R^n$, then the family $\\{e_i\\}_{1\\le i\\le n}$ where $e_i$ is the vector having $1$ at $i^{th}$ entry and zero otherwise is a basis.\\\\\r\n    2. Take $V=\\mathbb C$ over $\\mathbb C$, then $\\{a\\}$ is a basis for any $a\\neq 0$.\\\\\r\n    3. Take also $V=\\mathbb C$ but over $\\mathbb R$, then $\\{1,i\\}$ is a basis.\\\\\r\n    4. Take $V=\\mathbb P[x]$ be the set of polynomials in $\\mathbb R$ and $S=\\{x^n:n\\ge 0\\}$.\r\n    Then $S$ is a basis.\r\n    Worth noting that $|S|=\\infty$ in this case.\r\n\\end{example}\r\n\\begin{lemma}\r\n    If $V$ is a vector space over $F$, then $\\{v_1,\\ldots,v_n\\}$ is a basis of $V$ if and only if for any vector $v\\in V$, there is a unique decomposition\r\n    $$v=\\sum_{i=1}^n\\lambda_iv_i$$\r\n\\end{lemma}\r\n\\begin{remark}\r\n    If the conditions are true, then the tuple $(\\lambda_1,\\ldots,\\lambda_n)$ (ordered via the ordering one chose on $v_i$) is called the coordinate of $v$ in the basis $(v_i)$.\r\n\\end{remark}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    If $S$ is a finite set that spans $V$, then a subset of $S$ is a basis of $V$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    If $S$ is independent, then we are done.\r\n    Otherwise, there is some $\\lambda\\neq 0$ and $\\lambda_w$ such that there is $v\\in S$ with\r\n    $$\\lambda v+\\sum_{w\\in S\\setminus\\{v\\}}\\lambda_ww=0\\implies v=\\frac{1}{\\lambda}\\sum_{w\\in S\\setminus\\{v\\}}\\lambda_ww\\in\\langle S\\setminus\\{v\\}\\rangle$$\r\n    Therefore $S\\setminus\\{v\\}$ also spans $V$.\r\n    We can repeat this process and, by the well-ordering of $\\mathbb N$, will reach a basis.\r\n\\end{proof}\r\n\\begin{theorem}[Steinitz Exchange Lemma]\\label{steinitz}\r\n    Let $V$ be a finite dimensional vector space over $F$, $\\{v_1,\\ldots,v_m\\}\\subset V$ linearly independent, $\\{w_1,\\ldots,w_n\\}\\subset V$ a generating set, then:\\\\\r\n    1. $m\\le n$.\\\\\r\n    2. Up to relabeling, $\\{v_1,\\ldots,v_m,w_{m+1},\\ldots,w_n\\}$ spans $V$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Suppose $\\{v_1,\\ldots,v_l,w_{l+1},\\ldots,w_n\\}$ spans $V$ for some $l<m$, then\r\n    $$\\exists\\alpha_i,\\beta_i\\in F, v_{l+1}=\\sum_{i\\le l}\\alpha_iv_i+\\sum_{i>l}\\beta_iw_i$$\r\n    But $\\{v_i\\}$ is linearly independent, so one of the $\\beta_i$ is nonzero.\r\n    By relabelling $\\beta_{l+1}\\neq 0$, then $w_{l+1}\\in\\langle\\{v_1,\\ldots,v_l,v_{l+1},w_{l+2}\\ldots,w_n\\}\\rangle$, therefore the set of vectors $\\{v_1,\\ldots,v_l,v_{l+1},w_{l+2}\\ldots,w_n\\}$ also spans $V$.\r\n    The theorem is then obvious by induction.\r\n\\end{proof}\r\n\\begin{corollary}\\label{dim_well_defined}\r\n    Let $V$ be a finite dimensional vector space, then any two bases of $V$ have the same cardinality.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\nThis corollary allows us to give a proper definition of the dimension of a vector space.\r\nBefore we step right into that, another corollary of Theorem \\ref{steinitz} can help us to capture important properties of a finite dimensional vector space that will come in handy in further discussions of basis.\r\n\\begin{corollary}\r\n    Let $V$ be a vector space with $\\dim V=n$, then:\\\\\r\n    1. Any independent set of vectors has size at most $n$.\r\n    The size is exactly $n$ iff this set is a basis.\\\\\r\n    2. Any spanning set has size at least $n$.\r\n    The size is exactly $n$ iff this set is a basis.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}", "meta": {"hexsha": "bbb9b0276b60216006065764a874fac3ae921baa", "size": 7165, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/span.tex", "max_stars_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_stars_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2/span.tex", "max_issues_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_issues_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2/span.tex", "max_forks_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_forks_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.2803030303, "max_line_length": 225, "alphanum_fraction": 0.6517794836, "num_tokens": 2443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.8807970654616711, "lm_q1q2_score": 0.7301268772612014}}
{"text": "\n\\subsection{Cosine functions as activation function}\nLet us use a simple example to motivate the spectral Barron space. Consider a bounded domain $\\Omega\\subset \\mathbb\nR^d$ and a real function $u\\in L^1(\\Omega)$.\nRecall the Fourier transform of $u\\in L^1(\\mathbb{R})$ in Definition~\\ref{def:fourier1} and \\ref{def:fourier2}. \nThis gives the following integral representation of $u$ in terms of the cosine function\n\\begin{equation}\n \\label{eq:reint}\nu(x)=Re\\int_{\\mathbb{R}^d} e^{2\\pi i\\omega\\cdot x} \\hat u(\\omega)d\\omega\n= \\int_{\\mathbb{R}^d}\\cos (2\\pi (\\omega\\cdot x + b(\\omega))) |\\hat u(\\omega)|d\\omega,\n\\end{equation}\nwhere $ \\hat u(\\omega)= e^{2\\pi ib(\\omega)}|\\hat u(\\omega)|$. Let \n\\begin{equation}\n \\label{eq:2}\ng(x, \\omega) = \\cos(2\\pi (\\omega\\cdot x + b(\\omega)))\\quad \\mbox{ and }\\quad \n\\rho(\\omega)= |\\hat u(\\omega)| . \n\\end{equation}\nThus, \n\\begin{equation}\n\\label{int-rep}\nu(x)= \\int_{\\mathbb{R}^d}g(x,\\omega) \\rho(\\omega)d\\omega,   \n\\end{equation}\nIf\n$$\n\\int_{\\mathbb R^d} |\\hat u(\\omega)|d\\omega <\\infty,\n$$\nthen $\\|\\rho\\|_{L^1}<\\infty$. By applying the Lemma \\ref{lem:sample},\nthere exist $\\omega_i\\in \\mathbb R^d$\nsuch that\n\\begin{equation}\n  \\label{eq:3}\n\\|u-u_N\\|_{0,\\Omega}\\le N^{-1/2}\\|\\hat u\\|_{L^1(\\mathbb R^d)}.  \n\\end{equation}\nwhere\n\\begin{equation}\\label{cosfn}\nu_N(x) = {\\|\\hat u\\|_{L^1(\\mathbb R^d)}\\over N} \\sum_{i=1}^N \\cos (2\\pi(\\omega_i\\cdot x + b(\\omega_i)))\n\\end{equation}\nMore generally, we consider the approximation property in $H^m$-norm.\nBy \\eqref{eq:reint},\n\\begin{equation} \n\\partial^\\alpha u(x)= \\int_{\\mathbb{R}^d} \\cos^{|\\alpha|}(2\\pi (\\omega\\cdot x + b(\\omega)))\\omega^\\alpha |\\hat u(\\omega)|d\\omega,  \\quad \\forall\\ |\\alpha|\\le m.\n\\end{equation}\nFor any positive integer $m$, let \n\\begin{equation} \\label{eq:gm}\ng_m(x,\\omega)= {\\cos (2\\pi (\\omega\\cdot x + b(\\omega)))\\over  (1+ \\|\\omega\\|)^m}\\quad \\mbox{and}\\quad \\rho_m(\\omega)= (1+ \\|\\omega\\|)^m|\\hat u(\\omega) |,\n\\end{equation}\nwhere\n$$\n\\| \\rho_m\\|_{L^1(\\mathbb R^d)}=\\int_{\\mathbb R^d} (1+ \\|\\omega\\|)^m|\\hat u(\\omega) | d\\omega<\\infty.\n$$\nThen, $\\displaystyle u(x)=\\int_{\\mathbb R^d} g_m(x,\\omega)\\rho_m d\\omega = \\| \\rho_m\\|_{L^1(\\mathbb R^d)}\\mathbb{E}g_m(x,\\omega)$. Define\n\\begin{equation}\nu_N(x) = {\\|\\rho_m\\|_{L^1(\\mathbb R^d)}\\over N} \\sum_{i=1}^N g_m(x,\\omega_i)\n= {\\|\\rho_m\\|_{L^1(\\mathbb R^d)}\\over N} \\sum_{i=1}^N {\\cos (2\\pi(\\omega_i\\cdot x + b(\\omega_i)))\\over (1+\\|\\omega_i\\|)^m}.\n\\end{equation}\nIt holds that \n$$\n\\partial^\\alpha (u(x) - u_N(x))={\\|\\rho_m\\|_{L^1(\\mathbb R^d)}\\over N}\\sum_{i=1}^N \\mathbb{E} \\partial^\\alpha (g_m(x,\\omega) -  g_m(x,\\omega_i)).\n$$\nBy Lemma \\ref{MC},\n\\begin{align}\n\\mathbb{E}_N \\sum_{|\\alpha|\\le m}\\|\\partial^\\alpha (u(x) - u_N(x))\\|_{0, \\Omega}^2 \n&\\le \n\\|\\rho_m \\|_{L^1(\\mathbb R^d)}^2\\mathbb{E}_N \\sum_{|\\alpha|\\le m}\\frac{1}{N^2}\\sum_{i=1}^N \\left (\\mathbb{E} \\partial^\\alpha (g_m(x,\\omega) -  g_m(x,\\omega_i))\\right )^2\n\\\\\n&\\le \n{\\|\\rho_m \\|_{L^1(\\mathbb R^d)}^2\\over N}  \\sum_{|\\alpha|\\le m}\\mathbb{E} \\left (\\partial^\\alpha g_m(x,\\omega)\\right)^2\n\\end{align}\nNote that the definitions of $g_m$ and $\\rho_m$ in \\eqref{eq:gm} guarantee that \n$$\n|\\partial^\\alpha g_m(x,\\omega)|\\le 1.\n$$\nThus,\n$$\n\\mathbb{E}_N \\sum_{|\\alpha|\\le m}\\|\\partial^\\alpha (u(x) - u_N(x))\\|_{0, \\Omega}^2 \\lesssim {\\|\\rho_m \\|_{L^1(\\mathbb R^d)}^2\\over N}.\n$$\nThis implies that there exist\n$\\omega_i\\in \\mathbb R^d$ such that\n\\begin{equation}\n\\label{cosHm}\n\\|u-u_N\\|_{H^m(\\Omega)}\\lesssim N^{-1/2}\\int_{\\mathbb{R}^d} (1+ \\|\\omega\\|)^m|\\hat u(\\omega) | d\\omega.  \n\\end{equation}\n\n\nGiven $v\\in L^2(\\Omega)$,   consider all the possible extension $v_E:\n\\mathbb{R}^d \\mapsto \\mathbb{R}$ with $v_E |_{\\Omega} = v$ and define\nthe spectral  Barron norm for any $s\\ge 1$:\n\t\\begin{equation}\\label{barron-norm0}\n\t\\|v\\|_{B^{s}(\\Omega)} = \\inf_{v_E |_{\\Omega} = v} \\int_{\\mathbb{R}^d}(1+\\|\\omega\\|)^s|\\hat{v}_E(\\omega)|d\\omega\n\t\\end{equation}\nand  spectral  Barron space\n\\begin{equation}\n  \\label{Barron}\n\tB^{s}(\\Omega) = \\{v\\in L^2(\\Omega): \\|v\\|_{B^{s}(\\Omega)}<\\infty\\}.  \n\\end{equation}\n\nIn summary, we have \n\\begin{equation} \n\\|u-u_N\\|_{H^m(\\Omega)}\\lesssim N^{-1/2}  \\|u\\|_{B^{m}(\\Omega)},\n\\end{equation}\nwhere $u_N$ is defined in \\eqref{cosfn}.\n\n\nSpecifically, we will consider the problem of approximating a function with bounded Barron norm \\eqref{barron-norm0} in the Sobolev space $H^m(\\Omega)$. Our first step will be to prove a lemma showing that the Sobolev norm is bounded by the Barron norm.\n\n\\begin{lemma}\\label{smoothness-lemma}\n Let $m \\geq 0$ be an integer and $\\Omega\\subset \\mathbb{R}^d$ a bounded domain. Then for any Schwartz function $v$, we have\n \\begin{equation}\\label{embend}\n \\|v\\|_{W^{m,\\infty}(\\Omega)} \\lesssim \\|v\\|_{{B}^m(\\Omega)} \\lesssim  \\|v\\|_{H^{m + {d\\over 2}+\\epsilon}(\\Omega)},\n \\end{equation}\n where $\\epsilon$ is positive.\n\\end{lemma}\n\\begin{proof}\nRecall the inverse Fourier transform in Definition \\ref{def:fourier1}\n$$\nv(x)=\\int \\hat{v}(\\omega) e^{2 \\pi i\\omega \\cdot x} d \\omega.\n$$\nFor any $|\\alpha|\\le m$,\n$$\n|\\partial^\\alpha v|=|(2\\pi)^{|\\alpha|}\\int \\hat{v}(\\omega) \\omega^\\alpha e^{2 \\pi i\\omega \\cdot x} d \\omega|\\le |(2\\pi)^{|\\alpha|}\\int \\hat{v}(\\omega) \\|\\omega\\|^\\alpha e^{2 \\pi i\\omega \\cdot x} d \\omega| \\lesssim \\|v\\|_{B^m(\\Omega)},\n$$ \nwhich proves $ \\|v\\|_{W^{m,\\infty}(\\Omega)} \\lesssim \\|v\\|_{{B}^m(\\Omega)}$.\n\n\\iffalse\n Let $\\chi$ be a Schwartz function satisfying $\\chi(x) = 1$ for $x\\in \\Omega$. Such a function exists because $\\Omega$ is bounded. Let $\\alpha$ be any multi-index with $|\\alpha|\\leq m$. Then we have\n \\begin{equation}\n  \\|D^\\alpha v\\|_{L^2(\\Omega)} \\leq \\|\\chi D^\\alpha u\\|_{L^2(\\mathbb{R}^d)} \\leq \\|\\hat\\chi * \\widehat{D^\\alpha v}\\|_{L^2(\\mathbb{R}^d)}\n \\end{equation}\n Now we use Young's inequality to obtain\n \\begin{equation}\n  \\|\\hat\\chi * \\widehat{D^\\alpha v}\\|_{L^2(\\mathbb{R}^d)} \\leq \\|\\hat\\chi\\|_{L^2(\\mathbb{R}^d)}\\|\\widehat{D^\\alpha v}\\|_{L^1(\\mathbb{R}^d)} \\leq \\|\\hat\\chi\\|_{L^2(\\mathbb{R}^d)}\\|v\\|_{\\mathcal{B}^m(\\Omega)}.\n \\end{equation}\n Combining this over all multi-indices $\\alpha$, we get\n \\begin{equation}\n  \\|u\\|_{H^m(\\Omega)} \\lesssim \\|v\\|_{\\mathcal{B}^m(\\Omega)},\n \\end{equation}\n as desired. \\fi\n \n A version of the second inequality\n  in \\eqref{embend} and its proof \ncan be found in \\cite{barron1993universal}. Below is a proof, by \ndefinition and Cauchy-Schwarz\n  inequality, \n\\begin{align}\n\\|v\\|_{B^m(\\Omega)} =& \\inf_{v_E |_{\\Omega} = v} \\left(\\int_{\\mathbb{R}^d}(1+\\|\\omega\\|)^m|\\hat{v}_E(\\omega)|d\\omega \\right)^2\n\\\\\n\\le &  \\int_{\\mathbb{R}^d}(1+\\|\\omega\\|)^{-d - 2\\epsilon}d\\omega  \\inf_{v_E |_{\\Omega} = v} \n\\int_{\\mathbb{R}^d}(1+\\|\\omega\\|)^{d + 2m + 2\\epsilon} |\\hat{v}_E(\\omega)|^2d\\omega  \n\\\\\n\\lesssim &  \\inf_{v_E |_{\\Omega} = v} \n\\int_{\\mathbb{R}^d}(1+\\|\\omega\\|)^{d + 2m + 2\\epsilon} |\\hat{v}_E(\\omega)|^2d\\omega  \n\\lesssim \\|v\\|_{H^{m + {d\\over 2}+\\epsilon}(\\Omega)}.\n\\end{align}\n\n\n\\end{proof}\n\n\n", "meta": {"hexsha": "c602b06ded5eb7b05a9c2565a4aec9a0866068e7", "size": 6841, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/BarronSpace.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/BarronSpace.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/BarronSpace.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.0251572327, "max_line_length": 253, "alphanum_fraction": 0.6259318813, "num_tokens": 2870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7299463121184285}}
{"text": "\\newpage\n\\chapter*{Summary of Probability Theory I}\n\\addcontentsline{toc}{chapter}{Summary of Probability Theory I}\n\n{\\scriptsize\n\n\\begin{framed}\n\\begin{tabular}{rcl}\nSET SUMMARY\\\\ \\\\\n$\\{a_1,a_2,\\dots,a_n\\}$& $-$& a set containing the elements, $a_1,a_2,\\dots,a_n$.\\\\\n$a\\in A$ &$-$& $a$ is an element of the set $A$.\\\\\n$A\\subseteq B$ &$-$& the set $A$ is a subset of $B$.\\\\\n$A\\cup B$ &$-$& ``union'', meaning the set of all elements which are in $A$ or $B$, \\\\\n& & \\ \\ or both.\\\\\n$A\\cap B$ &$-$& ``intersection'', meaning the set of all elements in both $A$ and $B$.\\\\\n$\\{\\}$ or $\\emptyset$ &$-$& empty set.\\\\\n$\\Omega $ &$-$& universal set.  \\\\\n$A^c $ &$-$& the complement of $A$, meaning the set of all elements in $\\Omega$,\\\\\n& & \\ \\ the universal set, which are not in $A$.\\\\\n\\end{tabular}\n\\end{framed}\n\n\n\\begin{framed}\nEXPERIMENT SUMMARY\\\\\n\n\\begin{tabular}{rcl}\nExperiment &$-$& an activity producing distinct outcomes.\\\\\n$\\Omega$ &$-$& set of all outcomes of the experiment.\\\\\n$\\omega$ &$-$& an individual outcome in $\\Omega$, called a simple event.\\\\\n$A\\subseteq \\Omega$ &$-$& a subset $A$ of $\\Omega$ is an event.\\\\\nTrial &$-$& one performance of an experiment resulting in 1 outcome.\\\\\n\\end{tabular}\n\\end{framed}\n\n\\begin{framed}\nPROBABILITY SUMMARY\n\n\\medskip\n\nAxioms:\n\\begin{enumerate}\n\\item If $A\\subseteq \\Omega$ then $0\\leq P(A)\\leq 1$ and $P(\\Omega)=1$.\n\\item If $A$, $B$ are disjoint events, then $P(A\\cup B)=P(A)+P(B)$.\n\n[This is true only when $A$ and $B$ are disjoint.]\n\\item If $A_1,A_2,\\dots$ are disjoint then $P(A_1\\cup A_2\n\\cup\\dots)=P(A_1)+P(A_2)+\\dots$\n\\end{enumerate}\nRules:\n$$P(A^c)\\;=\\;1-P(A)$$\n$$P(A\\cup B)\\;=\\;P(A)+P(B)-P(A\\cap B) \\qquad [\\textrm{always true}]$$\n\\end{framed}\n\n\\newpage\n\\begin{framed}\nCONDITIONAL PROBABILITY SUMMARY\\\\\n\n$P(A|B)$ means the probability that $A$ occurs given that $B$ has\noccurred.\n\n$$P(A|B)\\;=\\;\\frac{P(A\\cap B)}{P(B)}\\;=\\;\\frac{P(A)P(B|A)}{P(B)}\\quad \\textrm{if}\\quad P(B)\\neq0$$\n\n$$P(B|A)\\;=\\;\\frac{P(A\\cap B)}{P(A)}\\;=\\;\\frac{P(B)P(A|B)}{P(A)}\\quad \\textrm{if}\\quad P(A)\\neq 0$$\n\nConditional probabilities obey the 4 axioms of probability.\n\\end{framed}\n\n\\begin{framed}\nDISCRETE RANDOM VARIABLE SUMMARY\\\\\n\nProbability mass function $$f(x)=P(X=x_i)$$\nDistribution function $$F(x)=\\sum_{x_i\\leq x}f(x_i)$$\n\n\\begin{center}\n{\\small\n{\\renewcommand{\\arraystretch}{1.25}\n\\begin{tabular}{|c|c|p{3.0cm}|p{5.0cm}|}\n\\multicolumn{1}{c}{\\bf Random  Variable} & \\multicolumn{1}{c}{\\bf Possible  Values}\n&\\multicolumn{1}{c}{\\bf Probabilities} &\\multicolumn{1}{c}{\\bf Modeled situations} \\\\\\hline\nDiscrete  uniform&$\\{x_1,x_2,\\dots,x_k\\}$&$P(X=x_i)=\\frac{1}{k}$&Situations with $k$ equally likely values.  Parameter: $k$.\\\\\\hline\n$\\bernoulli(\\theta)$&$\\{0,1\\}$&$P(X=0)=1-\\theta$\\newline$P(X=1)=\\theta$&Situations with only 2 outcomes, coded 1 for success and 0 for failure.\\newline Parameter:\\newline $\\theta=P(\\textrm{success}) \\in (0, 1)$.\\\\\\hline\nGeometric($\\theta$)&$\\{1,2,3,\\dots\\}$&$P(X=x)\\newline=(1-\\theta)^{x-1}\\theta$& Situations where you count the number of trials until the first success in a sequence of independent trails with a constant probability of success. \\newline Parameter:\\newline $\\theta=P(\\textrm{success}) \\in (0, 1)$.\\\\\\hline\nBinomial($n,\\theta$)&$\\{0,1,2,\\dots,n\\}$&$P(X=x)$\\newline $=\\displaystyle\\binom{n}{x}\\theta^x(1-\\theta)^{n-x}$&Situations where you count the number of success in $n$ trials where each trial is independent and there is a constant probability of success.\\newline Parameters: $n \\in \\{1,2,\\ldots\\}$;\\newline $\\theta=P(\\textrm{success}) \\in (0, 1)$.\\\\\\hline\nPoisson($\\lambda$)&$\\{0,1,2,\\dots\\}$&$P(X=x)\\newline=\\displaystyle \\frac{\\lambda^xe^{-\\lambda}}{x!}$&Situations where you count the number of events in a continuum where the events occur one at a time and are independent of one another.\\newline Parameter: $\\lambda$= rate $\\in (0,\\infty)$.\\\\\\hline\n\\end{tabular}}\n}\n\\end{center}\n\\end{framed}\n\n\\begin{framed}\nCONTINUOUS RANDOM VARIABLES: NOTATION\\\\\n\n$f(x)$: Probability density function (PDF)\n\\begin{itemize}\n\\item$f(x)\\;\\geq\\;0$\n\\item Areas underneath $f(x)$ measure probabilities.\n\\end{itemize}\n\n$F(x)$: Distribution function (DF)\n\\begin{itemize}\n\\item $0\\;\\leq\\;\\ F(x)\\;\\leq \\;1$\n\\item $F(x)\\;= \\;P(X\\leq x)$ is a probability\n\\item $F^{\\prime}(x)\\;=\\;f(x)$ for every $x$ where $f(x)$ is continuous\n\\item $F(x)\\;=\\;\\displaystyle\\int^x_{-\\infty}f(v)dv$\n\\item $P(a<X\\leq b)\\;=\\;F(b)-F(a)\\;=\\;\\displaystyle \\int^b_af(v)dv$\n\\end{itemize}\n\\end{framed}\n\n\\begin{framed}\n\\textbf{Expectation} of a function $g(X)$ of a random variable $X$ is defined as:\n\\[\nE(g(X))\\; =\\;\n\\begin{cases}\n\\displaystyle \\sum_x g(x) f(x) & \\text{if $X$ is a discrete RV}\\\\[12pt]\n\\displaystyle \\int_{-\\infty}^{\\infty} g(x) f(x) dx & \\text{if $X$ is a continuous RV}\n\\end{cases}\n\\]\n\\begin{center}\nSome Common Expectations\n{\\renewcommand{\\arraystretch}{1.75}\n%\\begin{tabular}{|c|c|p{3.0cm}|p{5.0cm}|}\n\\begin{tabular}{|c|p{6.0cm}|p{6.0cm}|}\n\\hline\n$g(x)$ & definition & also known as \\\\\n\\hline\n$x$    & $E(X)$     & Expectation, Population Mean or First Moment of $X$\\\\\n%       &            & or First Moment of $X$\\\\\n\\hline\n$(x-E(X))^2$ & $V(X):=E((X-E(X))^2)$ \\newline $\\quad =E(X^2)-(E(X))^2$ & Variance or Population Variance of $X$\\\\\n\\hline\n$e^{\\imath t x}$ & $\\phi_X(t) := E\\left( e^{\\imath t X}\\right)$ & Characteristic Function (CF) of $X$\\\\\n\\hline\n$x^k$  & $E(X^k) =\\frac{1}{\\imath^k} \\left[\\frac{d^k \\phi_X(t)}{dt^k}\\right]_{t=0} $  & $k$-th Moment of $X$\\\\\n\\hline\n\\end{tabular}\n}\n\\end{center}\n\\end{framed}\n\n\\begin{table}[htb]\n\\centering\n{\\small\n\\begin{tabular}{| l | l |}\n\\hline\nSymbol & Meaning\\\\ \\hline\n$\\BB{1}_{A}(x)$ & Indicator or set membership function that returns $1$ if $x \\in A$ and $0$ otherwise\\\\\n$\\Rz^d := (-\\infty,\\infty)^d$ & $d$-dimensional Real Space \\\\\n\\hline\n\\end{tabular}\n}\n\\caption{Symbol Table: Probability and Statistics \\label{T:SymbTableProbStats}}\n\\end{table}\n\n%\\section*{Summary of Random Variables}\\label{S:SummaryRVs}\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{|c|c|c|c|}%|c}\n\\hline\nModel &PDF or PMF&Mean&Variance\\\\ \\hline%&{\\tt MGF}\\\\\n%$\\pointmass(\\theta)$&$\\BB{1}_{\\{\\theta\\}}(x)$&$\\theta$&$0$\\\\%&$e^{\\theta t}$\\\\\n$\\bernoulli(\\theta)$ &$\\theta^x(1-\\theta)^{1-x} \\BB{1}_{\\{0,1\\}}(x)$&$\\theta$&$\\theta(1-\\theta)$\\\\%&$\\theta e^t+(1-\\theta)$\\\\\n$\\binomial(n,\\theta)$&$(^n_{\\theta})\\theta^x(1-\\theta)^{n-x} \\BB{1}_{\\{0,1,\\ldots,n\\}}(x)$&$n \\theta$&$n \\theta(1-\\theta)$\\\\%&$(\\theta e^t+(1-\\theta))^n$\\\\\n$\\geometric(\\theta)$ &$\\theta(1-\\theta)^{x} \\BB{1}_{\\Zz_+}(x)$&$ \\frac{1}{\\theta}-1$&$\\frac{1-\\theta}{\\theta^2}$\\\\%&$\\frac{\\theta e^t}{1-(1-\\theta)e^t}(t<-log(1-\\theta))$\\\\\n$\\poisson(\\lambda)$&$\\frac{\\lambda^xe^{-\\lambda}}{x!} \\BB{1}_{\\Zz_+}(x)$&$\\lambda$&$\\lambda$\\\\%&$e^{\\lambda(e^t-1)}$\\\\\n$\\uniform(\\theta_1,\\theta_2)$&$\\BB{1}_{[\\theta_1,\\theta_2]}(x)/(\\theta_2-\\theta_1)$&$\\frac{\\theta_1+\\theta_2}{2}$&$\\frac{(\\theta_2-\\theta_1)^2}{12}$\\\\%&$\\frac{e^{\\theta_2 t}-e^{\\theta_1 t}}{(\\theta_2-\\theta_1)t}$\\\\\n$\\exponential(\\lambda)$&$\\lambda e^{-\\lambda x}$&$\\lambda^{-1}$&$\\lambda^{-2}$\\\\%&$\\frac{1}{1-\\frac{1}{\\lambda} t}(t<\\lambda)$\\\\\n$\\normal(\\mu,\\sigma^2)$&$\\frac{1}{\\sigma\\sqrt{2\\pi}}e^{(x-\\mu)^2/(2\\sigma^2)}$&$\\mu$&$\\sigma^2$\\\\%&$exp\\{ut+\\frac{\\sigma^2t^2}{2}\\}$\\\\\n%$\\gammA(\\alpha,\\beta)$&$\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)}{x^{\\alpha-1}e^{-\\beta x}}$&$\\alpha/\\beta$&$\\alpha/\\beta^2$\\\\%&$(\\frac{1}{1-\\beta t})^{\\alpha}(t<1/\\beta)$\\\\\n%$\\betA(\\alpha,\\beta)$ & $\\frac{\\Gamma(\\alpha+\\beta)}{\\Gamma(\\alpha)\\Gamma(\\beta)}x^{\\alpha-1}(1-x)^{\\beta-1}$ & $\\frac{\\alpha}{\\alpha+\\beta}$ & $\\frac{\\alpha\\beta}{(\\alpha+\\beta)^2 (\\alpha+\\beta+1)} $ \\\\%& $ 1+\\Sigma^\\infty_{k+1}(\\Pi^{k-1}_{r=0}\\frac{\\alpha+r}{\\alpha+\\beta+r})\\frac{t^k}{k\\!}$\\\\\n%$t_v$ & $\\frac{\\Gamma((v+1)/2)}{\\Gamma(v/2)}  \\frac{1}{(1+x^2/v)^{(v+1)/2}$ &0 (if $v>1$ ) & $\\frac{v}{v-2}$  (if $v>2$) & does not exist \\\\\n% $\\chi^2_p$&$\\frac{1}{\\Gamma(p/2)2^{p/2}}x^{(p-2)-1}e^{-x/2}$&$p$&$2p$\\\\ \\hline%&$(\\frac{1}{1-2t})^{p/2}(t<1/2)$\\\\\n\\hline\n\\end{tabular}\n\\caption{Random Variables with PDF and PMF (using indicator function), Mean and Variance}\n%\\label{tab:}\n\\end{table}\n\n\\begin{table}[htb]\n\\centering\n{\\small\n\\begin{tabular}{| l | l |}\n\\hline\nSymbol & Meaning\\\\ \\hline\n$A = \\{ \\star, \\circ, \\bullet \\}$& $A$ is a set containing the elements $\\star$, $\\circ$ and $\\bullet$ \\\\\n$\\circ \\in A$ & $\\circ$ belongs to $A$ or $\\circ$ is an element of $A$\\\\\n$A \\ni \\circ$ & $\\circ$ belongs to $A$ or $\\circ$ is an element of $A$\\\\\n$\\odot \\notin A$& $\\odot$ does not belong to $A$ \\\\\n$\\# A$& Size of the set $A$, for e.g.~$\\#\\{ \\star, \\circ, \\bullet, \\odot \\}=4$\\\\\n$\\Nz$& The set of natural numbers $\\{1,2,3,\\ldots\\}$\\\\\n$\\Zz$&The set of integers $\\{\\ldots,-3,-2,-1,0,1,2,3,\\ldots\\}$\\\\\n$\\Zz_+$& The set of non-negative integers $\\{0,1,2,3,\\ldots\\}$\\\\\n%$\\Rz$& The set of real numbers\\\\\n$\\emptyset$&Empty set or the collection of nothing or $\\{\\}$\\\\\n$A \\subset B$ & $A$ is a subset of $B$ or $A$ is contained by $B$, e.g.~$A=\\{\\circ\\}, B=\\{\\bullet\\}$\\\\\n$A \\supset B$& $A$ is a superset of $B$ or $A$ contains $B$ e.g.~$A=\\{\\circ, \\star,\\bullet\\}, B=\\{\\circ, \\bullet\\}$ \\\\\n$A=B$ & $A$ equals $B$, i.e.~$A \\subset B$ and  $B \\subset A$\\\\\n$Q \\implies R$ & Statement $Q$ implies statement $R$ or If $Q$ then $R$ \\\\\n$Q \\iff R$ & $Q \\implies R$ and $R \\implies Q$ \\\\\n$\\{x: x \\text{ satisfies property } R \\}$& The set of all $x$ such that $x$ satisfies property $R$\\\\\n$A \\cup B$& $A$ union $B$, i.e.~$\\{x: x\\in A \\text{ or } x \\in B\\}$\\\\\n$A \\cap B$& $A$ intersection $B$, i.e.~$\\{x: x\\in A \\text{ and } x \\in B\\}$\\\\\n$A \\setminus B $& $A$ minus $B$, i.e.~$\\{x: x\\in A \\text{ and } x \\notin B\\}$\\\\\n$A:=B$& $A$ is equal to $B$ by definition\\\\\n$A=:B$& $B$ is equal to $A$ by definition\\\\\n$A^c$& $A$ complement, i.e.~$\\{x: x\\in U, \\text{ the universal set, but } x \\notin A\\}$\\\\ \n$A_1 \\times A_2 \\times \\cdots \\times A_m$ & The $m$-product set $\\{(a_1,a_2,\\ldots,a_{m}): a_1 \\in A_1, a_2 \\in A_2, \\ldots, a_{m} \\in A_m \\}$ \\\\\n$A^m$ & The $m$-product set $\\{(a_1,a_2,\\ldots,a_{m}): a_1 \\in A, a_2 \\in A, \\ldots, a_{m} \\in A \\}$ \\\\ \n$f := f(x)=y:\\Xz \\to \\Yz$ & A function $f$ from domain $\\Xz$ to range $\\Yz$ \\\\\n$f^{[-1]}(y)$ & Inverse image of $y$ \\\\ \n$f^{[-1]} := f^{[-1]}(y \\in \\Yz) = X \\subset \\Xz$ & Inverse of $f$ \\\\ \n%$\\Zz:=\\{\\ldots,-2,-1,0,1,2,\\ldots\\}$ & Integers \\\\\n$a<b$ or $a \\leq b$ & $a$ is less than $b$ or $a$ is less than or equal to $b$ \\\\\n$a>b$ or $a \\geq b$ & $a$ is greater than $b$ or $a$ is greater than or equal to $b$ \\\\ \n$\\Qz$ & Rational numbers \\\\ \n$(x,y)$ & the open interval $(x,y)$, i.e.~$\\{r: x < r < y\\}$ \\\\ \n$[x,y]$ & the closed interval $(x,y)$, i.e.~$\\{r: x \\leq r \\leq y\\}$ \\\\ \n$(x,y]$ & the half-open interval $(x,y]$, i.e.~$\\{r: x < r \\leq y\\}$ \\\\ \n$[x,y)$ & the half-open interval $[x,y)$, i.e.~$\\{r: x \\leq r < y\\}$ \\\\ \n$\\Rz := (-\\infty,\\infty)$ & Real numbers, i.e.~$\\{r: -\\infty < r <  \\infty \\}$ \\\\\n$\\Rz_+ := [0,\\infty)$ & Real numbers, i.e.~$\\{r: 0 \\leq r <  \\infty \\}$ \\\\\n$\\Rz_{>0} := (0,\\infty)$ & Real numbers, i.e.~$\\{r: 0 < r <  \\infty \\}$ \\\\\n\\hline\n\\end{tabular}\n}\n\\caption{Symbol Table: Sets and Numbers \\label{T:SummarySymbTableSets}}\n\\end{table}\n\n\n\\begin{table}[htb]\n\\centering\n{\\small\n{\\renewcommand{\\arraystretch}{1.75}\n\\begin{tabular}{| p{6.0cm}| p{10.0cm}|}\n\\hline\nSymbol & Meaning\\\\ \\hline\n$\\BB{1}_{A}(x)$ & Indicator or set membership function that returns $1$ if $x \\in A$ and $0$ otherwise\\\\\n$\\Rz^d := (-\\infty,\\infty)^d$ & $d$-dimensional Real Space \\\\\n\\rv~ & random vector\\\\ \n$F_{X,Y}(x,y)$ & Joint distribution function (JDF) of the \\rv~ $(X,Y)$\\\\\n$F_{X,Y}(x,y)$ & Joint cumulative distribution function (JCDF) of the \\rv~ $(X,Y)$ --- same as JDF \\\\\n$f_{X,Y}(x,y)$ & Joint probability mass function (JPMF) of the discrete \\rv~ $(X,Y)$\\\\\n$\\mathcal{S}_{X,Y}$\\newline$=\\{(x_i,y_j): f_{X,Y}(x_i,x_j)>0\\}$ & The support set of the discrete \\rv~ $(X,Y)$\\\\\n$f_{X,Y}(x,y)$ & Joint probability density function (JPDF) of the continuous \\rv~ $(X,Y)$\\\\\n$f_{X}(x)=\\int_{-\\infty}^{\\infty}f_{X,Y}(x,y)dy$ & Marginal probability density/mass function (MPDF/MPMF) of $X$\\\\\n$f_{Y}(y)$\\newline$=\\int_{-\\infty}^{\\infty}f_{X,Y}(x,y)dx$ & Marginal probability density/mass function (MPDF/MPMF) of $Y$\\\\\n$E(g(X,Y))$\\newline$=\\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty}g(x,y)f_{X,Y}(x,y)dxdy$ & Expectation of a function $g(x,y)$ for continuous \\rv \\\\\n$E(g(X,Y))$\\newline$=\\sum_{(x,y)\\in\\mathcal{S}_{X,Y}}g(x,y)f_{X,Y}(x,y)$ & Expectation of a function $g(x,y)$ for discrete \\rv \\\\\n$E(X^rY^s)$ & Joint moment \\\\\n$\\cv(X,Y) = E(XY)-E(X)E(Y)$ & Covariance of $X$ and $Y$, provided $E(X^2)<\\infty$ and $E(Y^2)>\\infty$\\\\\n$F_{X,Y}(x,y)=F_X(x)F_Y(y)$,\\newline for every $(x,y)$ & if and only if $X$ and $Y$ are said to be independent\\\\ \n$f_{X,Y}(x,y)=f_X(x)f_Y(y)$,\\newline for every $(x,y)$ & if and only if $X$ and $Y$ are said to be independent\\\\ \n$F_{X_1,X_2,\\ldots,X_n}(x_1,x_2,\\ldots,x_n)$ & Joint (cumulative) distribution function (JDF/JCDF) of the discrete or continuous \\rv~ $(X_1,X_2,\\ldots,X_n)$\\\\\n$f_{X_1,X_2,\\ldots,X_n}(x_1,x_2,\\ldots,x_n)$ & Joint probability mass/density function (JPMF/JPDF) of the discrete/continuous \\rv~ $(X_1,X_2,\\ldots,X_n)$\\\\\n$f_{X_1,X_2,\\ldots,X_n}(x_1,x_2,\\ldots,x_n)$\\newline$=\\prod_{i=1}^n f_{X_i}(x_i)$,\\newline for every $(x_1,x_2,\\ldots,x_n)$ & if and only if $X_1,X_2,\\ldots,X_n$ are (mutually/jointly) independent\\\\\n\\hline\n\\end{tabular}\n}\n}\n\\caption{Symbol Table: Probability and Statistics \\label{T:FullSymbTableProbStats}}\n\\end{table}\n}\n", "meta": {"hexsha": "b169e91f4e7c79b292e58bf7cd9e5165afac07d1", "size": 13373, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/ProbabilityISummary.tex", "max_stars_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_stars_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-19T07:54:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T13:55:18.000Z", "max_issues_repo_path": "matlab/csebook/ProbabilityISummary.tex", "max_issues_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_issues_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "matlab/csebook/ProbabilityISummary.tex", "max_forks_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_forks_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-07-18T07:47:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T11:28:24.000Z", "avg_line_length": 50.8479087452, "max_line_length": 354, "alphanum_fraction": 0.6030808345, "num_tokens": 5493, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8902942253943279, "lm_q1q2_score": 0.7299463024031131}}
{"text": "\\section{Compactness}\r\nRecall that a continuous, real-valued function on a closed bounded interval is bounded and attains its bound.\r\nThe question is, for which topological space $X$ is it true that every continuous real functions is bounded.\r\n\\begin{example}\r\n    1. For finite $X$, every function $X\\to\\mathbb R$ is bounded.\\\\\r\n    2. If for all continuous $f:X\\to\\mathbb R,\\exists n\\in\\mathbb N,\\exists A_1,A_2,\\ldots,A_n\\subset X$ such that $X=\\bigcup_iA_i$ and $f$ is bounded on each $A_i$, then $f$ is bounded on $X$.\r\n\\end{example}\r\nNote that given continuous $f:X\\to\\mathbb R$, for $x\\in X$, $U_x=f^{-1}((f(x)-1,f(x)+1))$ is open and $f$ is bounded there.\r\nSo if there is some finite subset of $\\{U_x:x\\in X\\}$ that still covers $X$, then $f$ must be bounded.\r\n\\begin{definition}\r\n    An open cover of a topological space $X$ is a family of open sets $\\mathscr U=\\{U_i\\}_{i\\in I}$ in $X$ such that $X=\\bigcup_{i\\in I}U_i$.\\\\\r\n    A subcover of $\\mathscr U$ is a subset $\\mathscr V\\subset \\mathscr U$ that is also an open cover of $X$.\r\n    $\\mathscr V$ is called a finite subcover if it is finite.\\\\\r\n    $X$ is compact if every open cover of $X$ has a finite subcover.\r\n\\end{definition}\r\n\\begin{theorem}\r\n    If $X\\neq\\varnothing$ is compact and $f:X\\to\\mathbb R$ is continuous, then $f$ is bounded and attains its bound.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    By continuity of $f$ and compactness of $X$, there is a finite subset of $\\{f^{-1}((f(x)-1,f(x)+1)):x\\in X\\}$ that covers $X$, which means that $f$ is bounded on any set in a finite family, so $f$ is bounded in the union of that family, which is $X$.\r\n    To show that $f$ attains its bound, let $m=\\{f(x):x\\in X\\}$ which exists since $X\\neq\\varnothing$ and $f$ is bounded.\r\n    Suppose that there is not an $x$ with $f(x)=m$, so for any $x\\in X,f(x)>m$ so $\\exists m_x$ such that $f(x)>m_x>m$.\r\n    Let $U_x=f^{-1}((m_x,\\infty))$ which is open and contains $x$, and $\\inf_{U_x}f\\ge m_x>x$.\r\n    Note that the family of all $U_x$ is an open cover of $X$, so there is a finite subcover $\\{U_x\\}_{x\\in F}$, so $\\forall y\\in X,f(y)\\ge \\min_{x\\in F}m_x>m$, contradiction.\r\n\\end{proof}\r\nNote that for a subspace $Y\\subset X$, $Y$ is compact iff whenever $\\mathscr U$ is a family of open set in $X$ whose union contains $Y$, there is a finite subset $\\mathscr V\\subset \\mathscr U$ such that the union of elements in $\\mathscr V$ contains $Y$.\r\n\\begin{theorem}\\label{01compact}\r\n    $[0,1]$ is compact.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $\\mathscr U$ be a set of open sets in $\\mathbb R$ thar contains $[0,1]$, assume that there does not exist finite subcover that contains $[0,1]$, then if $0\\le a<b\\le 1$ and $[a,b]$ cannot be covered by any finite $\\mathscr V\\subset\\mathscr U$, then let $C=(a+b)/2$, then one of $[a,c],[c,b]$ cannot be covered by finite $\\mathscr V\\subset\\mathscr U$.\\\\\r\n    Therefore, inductively we can find intervals $I_n=[a_n,b_n]$ such that $$I_0=[0,1],I_{n+1}\\subset I_n,|b_n-a_n|=1/2^n$$\r\n    thus $a_n\\to x,b_n=a_n+(b_n-a_n)\\to x$ for some $x\\in [0,1]$.\r\n    Now there is $U\\subset \\mathscr U$ such that $x\\in U$, but then there is some $\\epsilon$ with $(x-\\epsilon,x+\\epsilon)\\subset U$, therefore for sufficiently large $n$, $I_n\\subset U$, which is a contradiction.\r\n\\end{proof}\r\n\\begin{proposition}\\label{compact_haus_closed}\r\n    Let $X$ be a topological space and $Y\\subset X$ a subspace, then\\\\\r\n    1. If $X$ is compact and $Y$ is closed in $X$, then $Y$ is compact.\\\\\r\n    2. If $X$ is Hausdorff and $Y$ is compact, then $Y$ is closed.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    1. Let $\\mathscr U$ covers $Y$, then $\\mathscr U\\cup \\{X\\setminus Y\\}$ is an open cover of $X$.\r\n    Since $X$ is compact, there is a finite subcover $\\mathscr V\\subset \\mathscr U\\cup \\{X\\setminus Y\\}$ that covers $X$, hence $\\mathscr V\\setminus\\{X\\setminus Y\\}\\subset \\mathscr U$ is finite and covers $Y$.\\\\\r\n    2. We want to show that its complement is open.\r\n    Indeed, for any $x\\in X\\setminus Y$, and for any $y\\in Y$, there are disjoint $U_y,V_y$ such that $x\\in U_y,y\\in V_y$, then $\\{V_y\\}_{y\\in Y}$ is an open cover of $Y$, thus there is some finite set $F\\subset Y$ such that $Y\\subset\\bigcup_{y\\in F}V_y$, so $U=\\cap_{y\\in F}U_y$ is open, and by definition it is disjoint from $Y$, hence $x\\in U\\subset X\\setminus Y$, which shows that $X\\setminus Y$ is open.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    If $X$ is compact and $f:X\\to Y$ is continuous, then $f(X)$ is compact.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    For any open $\\{U_i\\}_{i\\in I}$ that covers $f(X)$, $\\{f^{-1}(U_i)\\}_{i\\in I}$ is an open cover of $X$, therefore there is some finite $F\\subset I$ such that $\\{f^{-1}(U_i)\\}_{i\\in F}$ covers $X$, hence $\\{U_i\\}_{i\\in F}$ covers $f(X)$.\r\n\\end{proof}\r\n\\begin{remark}\r\n    1. Compactness is a topological property.\\\\\r\n    2. Let $f:X\\to Y$ and $A\\subset X$.\r\n    Suppose $A$ is compact, then $f(A)$ is compact.\r\n\\end{remark}\r\n\\begin{example}\r\n    For $a<b$, $[a,b]=f([0,1])$ where $f(x)=(b-a)x+a$ which is continuous, thus every closed bounded interval is compact.\r\n\\end{example}\r\n\\begin{corollary}\r\n    If $X$ is compact and $R$ is an equivalence relation on $X$, then $X/R$ is compact.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    The quotient map is continuous and surjective.\r\n\\end{proof}\r\n\\begin{theorem}[Topological Inverse Function Theorem]\r\n    If $f:X\\to Y$ is a continuous bijection and $X$ is compact and $Y$ is Hausdorff, then $f$ is a homeomorphism.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    It suffices to check that $f$ is an open map, which, since $f$ is a bijection, is equivalent to say that $f$ is a closed map.\\\\\r\n    Fix any closed $V\\subset X$, then $V$ is compact since $X$ is compact, thus $f(V)$ is compact since $f$ is continuous, therefore $f(V)$ is closed since $Y$ is hausfdorff.\r\n    The result follows.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider $f:\\mathbb R\\to S^1$ by $f(t)=e^{2\\pi it}$ induces a continuous bijection $\\tilde{f}:\\mathbb R/\\mathbb Z\\to S^1$.\r\n    Now $\\mathbb R/\\mathbb Z=q([0,1])$ (where $q$ is the quotient map) is compact and $S^1$ is Hausdorff since it is a metric space, therefore $\\tilde{f}$ is a homeomorphism.\r\n\\end{example}\r\n\\begin{theorem}[Tychonorff's Theorem on Finite Products\r\n    \\footnote{It works for arbitrary products, but that case is much much harder}\r\n    ]\\label{tycho_finite}\r\n    Finite products of compact spaces are compact.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    It suffices to show for $2$.\\\\\r\n    Assume $X,Y$ are compact.\r\n    Fix $x\\in X$, $\\exists W_y\\in\\mathscr U$ with $x,y\\in W_y$, so there is some $U_y$ open in $X$ and $V_y$ open in $Y$ such that $(x,y)\\in U_y\\times V_y\\subset W_y$, so there is a finite $F_Y\\subset Y$ with $\\bigcup_{y\\in F_Y}V_y=Y$.\r\n    Let $T_x=\\bigcup_{y\\in F_Y}U_y$ is open and contains $x$ and note that $T_x\\times Y\\subset \\bigcup_{y\\in F_Y}W_y$.\r\n    But then $\\{T_x\\}_{x\\in X}$ covers $X$, so there is a finite $F_X\\subset X$ such that $\\{T_x\\}_{x\\in F_X}$ covers $X$, hence\r\n    $$X\\times Y\\subset \\bigcup_{x\\in F_X}T_x\\times Y=\\bigcup_{x\\in F_X}\\bigcup_{y\\in F_Y}W_y$$\r\n    The last term is the required finite subcover. \r\n\\end{proof}\r\n\\begin{theorem}[Heine-Borel Theorem]\r\n    A subset $K\\subset\\mathbb R^n$ if and only if it is closed and bounded.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    If $K$ is compact, note that $f:\\mathbb R^n\\to\\mathbb R$ by $x\\mapsto \\|x\\|$, thus it is bounded.\r\n    $K$ is also closed by Proposition \\ref{compact_haus_closed}.\\\\\r\n    Conversely, if $K$ is closed and bounded, there is some $M>0$ such that $K\\subset [-M,M]^n$ which is compact by Theorem \\ref{01compact} and \\ref{tycho_finite}.\r\n    Since $K$ is closed in $[-M,M]^n$, it is compact by Proposition \\ref{compact_haus_closed}.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Given an open set $U\\subset\\mathbb R^n$, a sequence of functions $f_k:U\\to\\mathbb R$ converges locally uniformly on $U$ to some function $f:U\\to\\mathbb R$ if $\\forall x\\in U, \\exists r>0, D_r(x)\\subset U$ and $f_k\\to f$ uniformly on $D_r(x)$.\r\n\\end{definition}\r\nThus this happens if and only if $f_n\\to f$ uniformly on any compact subset of $U$.\r\n\\begin{definition}\r\n    A topological space $X$ is called sequentially compact if and only if every sequence in $X$ has a convergent subsequence.\r\n\\end{definition}\r\n\\begin{example}\r\n    Any closed bounded subset of $\\mathbb R^n$ is sequentially compact by Bolzano-Weierstrass.\r\n\\end{example}\r\n\\begin{definition}\r\n    Fix a metric space $(M,d)$.\r\n    For $\\epsilon>0$ and $F\\subset M$.\r\n    We say $F$ is an $\\epsilon$-net for $M$ if $\\forall x\\in M,\\exists y\\in F,d(x,y)\\le \\epsilon$.\r\n    That is,\r\n    $$M=\\bigcup_{y\\in F} B_\\epsilon(y)$$\r\n    We say $M$ is totally bounded if for any $\\epsilon>0$, there is a finite $\\epsilon$-net for $M$.\r\n\\end{definition}\r\nNote that any compact space is totally bounded, but the converse is not true by taking $[0,1)$, but the only thing missing here is completeness.\r\n\\begin{theorem}\r\n    The followings are equivalent:\\\\\r\n    (1) $M$ is compact.\\\\\r\n    (2) $M$ is sequentially compact.\\\\\r\n    (3) $M$ is totally bounded and complete.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    $1\\implies 2$: Let $(x_n)$ be a sequence in $M$, so for $n\\in\\mathbb N$, let $A_n=\\{x_k:k>n\\}$.\r\n    We shall show that $\\bigcap_{n\\in\\mathbb N}\\bar{A}$ is nonempty.\r\n    Assume not, then\r\n    $$\\bigcup_{n\\in\\mathbb N}M\\setminus\\bar{A}=M$$\r\n    But $M$ is compact and all $M\\setminus\\bar{A}$ are closed, there is finite subcover, hence there is some $N\\in\\mathbb N$ such that $\\bigcup_{n\\le N}M\\setminus\\bar{A}=M$.\r\n    Also $A_m\\supset A_n,\\forall m\\le n$, so we have the complement of the closure of $A_{N}$ would be $M$, so that closure is empty, contradiction.\\\\\r\n    So we can fix $x\\in \\bigcap_{n\\in\\mathbb N}\\bar{A}$.\r\n    It is then trivial to construct a subsequence of $x_n$ that converges to $x$.\\\\\r\n    $2\\implies 3$: $M$ is complete since a Cauchy sequence with convergent subsequence is convergent.\r\n    To see it is totally bounded, assume it is not, then there is some $\\epsilon>0$ such that every $\\epsilon$-net is infinite.\r\n    Pick $x_1\\in M$, then if we have already picked $x_1,\\ldots,x_n$, we can pick $x_{n+1}\\notin \\bigcup_{k=1}^nB_\\epsilon(x_k)$, which we can do since $M$ has no finite $\\epsilon$-net.\r\n    But this $(x_n)$ does not have any Cauchy subsequence, so it has no converging subsequence.\\\\\r\n    $3\\implies 1$: Assume $M$ is not compact, so there is an open cover $\\mathscr U$ without any finite subcover.\r\n    We say $A\\subset M$ is ``bad'' if there is no finite subcover of $A$ in $\\mathscr U$.\r\n    So $M$ is bad but $\\varnothing$ is not.\r\n    Note if $A=\\bigcup_{i=1}^nB_i$ is bad, then there is some $i$ such that $B_i$ is bad.\\\\\r\n    Next, we want to show that if $A$ is bad and $\\epsilon>0$, then $\\exists B\\subset A$ such that $B$ is bad and $\\operatorname{diam}B=\\sup_{x,y\\in B}d(x,y)<\\epsilon$.\r\n    Indeed, since $M$ is bounded, we have a finite $\\epsilon/2$-net $F$, that is,\r\n    $$\\bigcup_{x\\in F}B_{\\epsilon/2}(x)=M\\implies \\bigcup_{x\\in F}(B_{\\epsilon/2}(x)\\cap A)=A$$\r\n    But this would mean that there is some $x\\in F$ such that $B_{\\epsilon/2}(x)\\cap A$ is bad, and by triangle inequality its diameter is less than $\\epsilon$.\r\n    Using this we can construct a sequence $M\\supset A_1\\supset A_2\\supset\\cdots$ such that $A_n$ is bad for any $n$ and $\\operatorname{diam}A<1/n$.\r\n    So we can pick $x_n\\in A_n$, then $x_n$ is Cauchy, thus it tends to a limit $x\\in M$ by completeness, so there is some $U\\in\\mathscr U$ such that $x\\in U$, so $\\exists r>0$ such that $D_r(x)\\subset U$, which provides a finite subcover for $A_n$ where $n$ is large enough.\r\n\\end{proof}\r\n\\begin{remark}\r\n    We have a new proof of Bolzano-Weierstrass now!\r\n    We can also have a new proof of Theorem \\ref{tycho_finite} for metric spaces.\\\\\r\n    However, the equivalence of sequentially compactness and compactness fails in both directions in general topological spaces.\r\n\\end{remark}", "meta": {"hexsha": "1f41c1a0600e364cc6dcf5fc722a449e3d6bdb03", "size": 11922, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7/compact.tex", "max_stars_repo_name": "david-bai-notes/IB-Analysis-and-Topology", "max_stars_repo_head_hexsha": "9c3a32b907ff14942767e4bbdc9951240d2d7edb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "7/compact.tex", "max_issues_repo_name": "david-bai-notes/IB-Analysis-and-Topology", "max_issues_repo_head_hexsha": "9c3a32b907ff14942767e4bbdc9951240d2d7edb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "7/compact.tex", "max_forks_repo_name": "david-bai-notes/IB-Analysis-and-Topology", "max_forks_repo_head_hexsha": "9c3a32b907ff14942767e4bbdc9951240d2d7edb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 76.9161290323, "max_line_length": 409, "alphanum_fraction": 0.6686797517, "num_tokens": 3994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.9032942112597332, "lm_q1q2_score": 0.7299224363109936}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\begin{document}\n\n\\section{Formuals}\n\nPermutations, $k$ objects from a sequence of $n$, or $_{n}P_{k}$.\n\n\\begin{equation}\n   _{n}P_{k} = \\frac{n!}{(n - k)!} = n(n-1)(n-2)\\ldots\\ (n-k+1)\n\\end{equation}\n\nPermutations with repetition, same as Permutation except you can choose the same object multiple times.\n\n\\begin{equation}\n   _{n}P^r_{k} = k^n\n\\end{equation}\n\nCombinations, $k$ objects from a set $n$ to form a new set, or $\\binom{n}{k}$ (pronounced $n$ choose $k$).\n\n\\begin{equation}\n   \\binom{n}{k} = \\frac{n!}{k!(n-k)!}\n\\end{equation}\n\nCombinations with repetition, $k$ objects from a set $n$ to form a new \\textit{multi}set, or $\\left(\\binom{n}{k}\\right)$.\n\n\\begin{equation}\n   \\left(\\binom{n}{k}\\right) = \\binom{n + k - 1}{k}\n\\end{equation}\n\nCombination identities,\n\n\\begin{gather}\n   \\binom{n}{k} = \\binom{n}{n - k} \\\\\n   \\binom{n}{k} = \\binom{n - 1}{k} + \\binom{n - 1}{k - 1} \\\\\n   \\binom{n}{m} \\binom{m}{k} = \\binom{n}{k} \\binom{n - k}{m - k}\n\\end{gather}\n\nSums,\n\n\\begin{gather}\n   \\sum^n_{i=1} i = \\frac{n(n+1)}{2} \\\\\n   \\sum^n_{i=1} i^2 = \\frac{n(n+1)(2n+1)}{6} \\\\\n   \\sum^n_{i=1} i^3 = \\frac{n^2(n+1)^2}{4} \\\\\n   \\sum^n_{k=0} \\binom{n}{k} = 2^n\n\\end{gather}\n\nLogarithm identities,\n\n\\begin{gather}\n   \\log_b x = \\frac{\\log_a x}{\\log_a b} \\\\\n   \\log x^y = y \\log x \\\\\n   \\log(xy) = \\log x + \\log y\n\\end{gather}\n\nTrigonometry identities,\n\n\\begin{gather}\n   \\tan x = \\frac{\\sin x}{\\cos x} \\\\\n   \\sin^2 x + \\cos^2 x = 1 \\\\\n   \\sin x = \\cos (\\frac{\\pi}{2} - x) \\\\\n   \\sin (x \\pm y) = \\sin x \\cos y \\pm \\cos x \\sin y \\\\\n   \\pi = 4 \\arctan(1) \\\\\n   e^{ix} = \\cos x + i \\sin x\n\\end{gather}\n\n\\end{document}\n", "meta": {"hexsha": "9efb7ea6468ed9a0eb0553de5816901924176cd3", "size": 1676, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/formulas.tex", "max_stars_repo_name": "amarmaduke/sigcomp-binder", "max_stars_repo_head_hexsha": "ca2dc020ed9ea47bed71b2b687eaf40340a58f8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/formulas.tex", "max_issues_repo_name": "amarmaduke/sigcomp-binder", "max_issues_repo_head_hexsha": "ca2dc020ed9ea47bed71b2b687eaf40340a58f8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/formulas.tex", "max_forks_repo_name": "amarmaduke/sigcomp-binder", "max_forks_repo_head_hexsha": "ca2dc020ed9ea47bed71b2b687eaf40340a58f8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.9428571429, "max_line_length": 121, "alphanum_fraction": 0.576372315, "num_tokens": 701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.729922434733235}}
{"text": "\\section{Real inner product spaces}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Check whether an operation is an inner product.\n  \\item Give an example of a vector space on which more than one inner\n    product can be defined.\n  \\item Calculate the inner product of vectors in various examples\n    of inner product spaces.\n  \\item Calculate the norm of a vector and the angle between two vectors.\n  \\item Use the Cauchy-Schwarz inequality and the triangle inequality\n    to reason about the size of inner products and norms of vectors.\n  \\end{enumerate}\n\\end{outcome}\n\nIn this section, we fix $K$ to be the field of real numbers.\n\n\\begin{definition}{Real inner product space}{real-inner-product-space}\n  A \\textbf{(real) inner product space}%\n  \\index{inner product space!real}%\n  \\index{real inner product space} is a real vector space $V$ equipped\n  with an operation that assigns to any pair of vectors\n  $\\vect{u},\\vect{v}\\in V$ a real number $\\iprod{\\vect{u},\\vect{v}}$,\n  called the \\textbf{inner product}%\n  \\index{inner product}%\n  \\index{multiplication!inner product} of $\\vect{u}$ and\n  $\\vect{v}$. This operation must satisfy the following properties:\n  \\begin{enumerate}\n  \\item Symmetry:%\n    \\index{symmetry!of inner product}\n    $\\iprod{\\vect{u},\\vect{v}} = \\iprod{\\vect{v},\\vect{u}}$.\n  \\item Linearity:%\n    \\index{linearity!of inner product}\n    $\\iprod{\\vect{u},k\\vect{v}+\\ell\\vect{w}}\n    = k\\iprod{\\vect{u},\\vect{v}}+\\ell\\iprod{\\vect{u},\\vect{w}}$.\n  \\item The positive definite property:%\n    \\index{positive definite property}\n    $\\iprod{\\vect{u},\\vect{u}} \\geq 0$, and moreover,\n    $\\iprod{\\vect{u},\\vect{u}}=0$ if and only if\n    $\\vect{u} = \\vect{0}$.\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{example}{$\\R^n$ with the usual dot product}{rn-with-dot-product}\n  $V=\\R^n$, with the usual dot product\n  \\begin{equation*}\n    \\iprod{\\vect{u},\\vect{v}} = \\vect{u}\\dotprod\\vect{v} =\n    u_1v_1 + \\ldots + u_nv_n\n  \\end{equation*}\n  is an inner product space.%\n  \\index{inner product space!Rn@$R^n$}\n\\end{example}\n\n\\begin{proof}\n  The relevant properties were shown in\n  Proposition~\\ref{prop:properties-dot-product}.\n\\end{proof}\n\nThere exist other inner product operations on $\\R^n$ besides the dot\nproduct. The following is an example.\n\n\\begin{example}{$\\R^2$ with a non-standard inner product}{rn-with-inner-product}\n  Let $V=\\R^2$, and consider the matrix\n  $A=\\begin{mymatrix}{cc} 1 & 1 \\\\ 1 & 2 \\end{mymatrix}$.\n  Define an operation $\\iprod{-,-}$ by\n  \\begin{equation*}\n    \\iprod{\\vect{u},\\vect{v}} = \\vect{u}^T A \\vect{v} =\n    \\begin{mymatrix}{cc} u_1 & u_2 \\end{mymatrix}\n    \\begin{mymatrix}{cc} 1 & 1 \\\\ 1 & 2 \\end{mymatrix}\n    \\begin{mymatrix}{c} v_1 \\\\ v_2 \\end{mymatrix}\n    = u_1v_1 + u_1v_2 + u_2v_1 + 2u_2v_2.\n  \\end{equation*}\n  Then $\\R^2$, with this operation, is an inner product space.\n\\end{example}\n\n\\begin{proof}\n  We must show the three properties are satisfied. For symmetry, note\n  that a scalar is equal to its own transpose. Therefore\n  \\begin{equation*}\n    \\iprod{\\vect{u},\\vect{v}}\n    ~=~ \\vect{u}^T A \\vect{v}\n    ~=~ (\\vect{u}^T A \\vect{v})^T\n    ~=~ \\vect{v}^T A^T \\vect{u}.\n  \\end{equation*}\n  But this is equal to $\\iprod{\\vect{v},\\vect{u}}$ because $A$ is a\n  symmetric matrix, i.e., $A^T=A$.\n  For linearity, note that, by properties of matrix multiplication,\n  \\begin{equation*}\n    \\iprod{\\vect{u},k\\vect{v}+\\ell\\vect{w}}\n    ~=~ \\vect{u}^T A(k\\vect{v}+\\ell\\vect{w})\n    ~=~ k\\vect{u}^T A\\vect{v} + \\ell\\vect{u}^T A\\vect{w}\n    ~=~ k\\iprod{\\vect{u},\\vect{v}} + \\ell\\iprod{\\vect{u},\\vect{w}}.\n  \\end{equation*}\n  For the positive definite property, we have\n  \\begin{equation*}\n    \\iprod{\\vect{u},\\vect{u}}\n    ~=~ u_1^2 + 2u_1u_2 + 2u_2^2\n    ~=~ (u_1^2 + 2u_1u_2 + u_2^2) + u_2^2\n    ~=~ (u_1+u_2)^2 + u_2^2\n    ~\\geq~ 0,\n  \\end{equation*}\n  because the sum of two squares is always non-negative. Moreover, if\n  equality holds in the last equation, then we must have $u_1+u_2=0$\n  and $u_2=0$, and this is only possible if $\\vect{u}=\\vect{0}$.\n\\end{proof}\n\n\\begin{example}{Continuous functions on an interval}{continuous-interval}\n  Let $a<b$ be real numbers, and let\n  \\begin{equation*}\n    [a,b] = \\set{x \\mid a \\leq x \\leq b}\n  \\end{equation*}\n  be the closed interval. Let $V=C[a,b]$%\n  \\index{Cab@$C[a,b]$} be the vector space of all continuous\n  functions%\n  \\index{continuous function}%\n  \\index{function!continuous}%\n  \\index{inner product space!of continuous functions}\n  $f:[a,b]\\to\\R$. Given two functions $f,g\\in C[a,b]$, define\n  \\begin{equation*}\n    \\iprod{f,g} = \\int_{a}^{b} f(x)g(x)\\,dx.\n  \\end{equation*}\n  This is an inner product.\n\\end{example}\n\n\\begin{proof}\n  This follows from well-known properties of integrals. For symmetry,\n  we have\n  \\begin{equation*}\n    \\iprod{f,g}\n    ~=~ \\int_{a}^{b} f(x)g(x)\\,dx\n    ~=~ \\int_{a}^{b} g(x)f(x)\\,dx\n    ~=~ \\iprod{g,f}.\n  \\end{equation*}\n  For linearity, we have\n  \\begin{equation*}\n    \\iprod{f,kg+\\ell h}\n    ~=~ \\int_{a}^{b} f(x)(kg(x)+\\ell h(x))\\,dx\n    ~=~ k\\int_{a}^{b} f(x)g(x)\\,dx+\\ell\\int_{a}^{b} f(x)h(x)\\,dx\n    ~=~ k\\iprod{f,g}+\\ell\\iprod{f,h}.\n  \\end{equation*}\n  For the positive definite property, we have\n  \\begin{equation*}\n    \\iprod{f,f}\n    = \\int_{a}^{b} f(x)^2\\,dx\n    \\geq 0.\n  \\end{equation*}\n  This is $\\geq 0$ because $a<b$ and the integral over a non-negative\n  function is non-negative. Moreover, since $f$ is continuous, we know\n  from calculus that the last integral can only be equal to $0$ if $f$\n  is the constant zero function.\n\\end{proof}\n\n\\begin{example}{Polynomials}{inner-product-polynomials}\n  Let $\\Poly$ be the vector space of polynomials (of any degree) with\n  real coefficients. Let $a<b$ be real numbers, and consider the inner\n  product defined by\n  \\begin{equation*}\n    \\iprod{p,q} = \\int_{a}^{b} p(x)q(x)\\,dx.\n  \\end{equation*}\n  This is an inner product space.%\n  \\index{inner product space!of polynomials}\n\\end{example}\n\n\\begin{proof}\n  The proof is the same as for $C[a,b]$.\n\\end{proof}\n\n\\begin{example}{Real Hilbert space}{hilbert-space}\n  Let $\\Hilb_{\\R}$ be the vector space of all infinite sequences of\n  real numbers $a=(a_0,a_1,a_2,\\ldots)$ satisfying\n  \\begin{equation*}\n    a_0^2 + a_1^2 + a_2^2 + \\ldots < \\infty.\n  \\end{equation*}\n  These are called the \\textbf{square summable} sequences%\n  \\index{sequence!square summable}%\n  \\index{square summable sequence}. (One needs\n  to do a little bit of work to show that it is indeed a vector space;\n  in particular, to show that the sum of two square summable sequences\n  is square summable.) On this space, we can\n  define an inner product as follows:\n  \\begin{equation*}\n    \\iprod{a,b} = a_0b_0 + a_1b_1 + a_2b_2 + \\ldots.\n  \\end{equation*}\n  The details will be worked out in Exercise~\\ref{ex:hilbert-space}.\n  This inner product space is called \\textbf{(real) Hilbert space}%\n  \\index{Hilbert space}%\n  \\index{inner product space!Hilbert space}.\n\\end{example}\n\nWe now look at some properties of inner products. The first thing to\nnote is that while the axioms require linearity in the right\ncomponent, symmetry ensures that linearity in the left component also\nholds.\n\n\\begin{proposition}{Left linearity}{inner-product-left-linearity}\n  Let $V$ be an inner product space. Then\n  $\\iprod{k\\vect{u}+\\ell\\vect{v},\\vect{w}}\n  = k\\iprod{\\vect{u},\\vect{w}} + \\ell\\iprod{\\vect{v},\\vect{w}}$.\n\\end{proposition}\n\n\\begin{proof}\n  This follows directly from symmetry. We have\n  \\begin{equation*}\n    \\iprod{k\\vect{u}+\\ell\\vect{v},\\vect{w}}\n    = \\iprod{\\vect{w},k\\vect{u}+\\ell\\vect{v}}\n    = k\\iprod{\\vect{w},\\vect{u}}\n    + \\ell\\iprod{\\vect{w},\\vect{v}}\n    = k\\iprod{\\vect{u},\\vect{w}}\n    + \\ell\\iprod{\\vect{v},\\vect{w}}.\n  \\end{equation*}\n\\end{proof}\n\nAnother important property of inner products is the Cauchy-Schwarz\ninequality. We have already encountered this in the context of the dot\nproduct in Section~\\ref{sec:dot-product}.\n\n\\begin{theorem}{Cauchy-Schwarz inequality}{inner-product-cauchy-schwarz}\n  Let $\\vect{u},\\vect{v}$ be vectors in an inner product space. Then%\n  \\index{Cauchy-Schwarz inequality!in inner product space}%\n  \\index{inner product space!Cauchy-Schwarz inequality}\n  \\begin{equation}\\label{cauchy-inner}\n    \\iprod{\\vect{u},\\vect{v}}^2\n    \\leq \\iprod{\\vect{u},\\vect{u}} \\cdot \\iprod{\\vect{v},\\vect{v}}.\n  \\end{equation}\n\\end{theorem}\n\n\\begin{proof}\n  The proof is almost identical to that of\n  Proposition~\\ref{prop:cauchy-schwarz-inequality}.  First note that if\n  $\\vect{u}=\\vect{0}$, then both sides of {\\eqref{cauchy-inner}} are\n  equal to zero, and so there is nothing to show. Therefore, we will\n  assume in what follows that $\\vect{u}\\neq \\vect{0}$.  Define a\n  function of $t\\in \\R$ by\n  \\begin{equation*}\n    f(t) = \\iprod{t\\vect{u}+\\vect{v}, t\\vect{u}+\\vect{v}}.\n  \\end{equation*}\n  Then by the positive definite property, we know that $f(t)\\geq 0$\n  for all $t\\in \\R$.  Also from linearity and symmetry, we have\n  \\begin{eqnarray*}\n    f(t) &=& \\iprod{t\\vect{u}, t\\vect{u}+\\vect{v}} +\n             \\iprod{\\vect{v}, t\\vect{u}+\\vect{v}} \\\\\n         &=& t^2\\iprod{\\vect{u}, \\vect{u}}+t\\iprod{\\vect{u}, \\vect{v}} + t\\iprod{\\vect{v}, \\vect{u}}+\n             \\iprod{\\vect{v}, \\vect{v}} \\\\\n         &=&t^2\\iprod{\\vect{u},\\vect{u}}+2t\\iprod{\\vect{u}, \\vect{v}}\n             + \\iprod{\\vect{v}, \\vect{v}}.\n  \\end{eqnarray*}\n  This means the graph of $y=f(t)$ is a parabola which opens upwards\n  and is never negative. It follows that this function has at most one\n  root. From the quadratic formula, we know that a quadratic function\n  $at^2+bt+c$ has one or zero roots if and only if $b^2-4ac\\leq\n  0$. Applying this reasoning to the function $f(t)$, we obtain\n  \\begin{equation*}\n    (2\\iprod{\\vect{u}, \\vect{v}})^2\n    - 4\\iprod{\\vect{u},\\vect{u}}\\iprod{\\vect{v},\\vect{v}} < 0,\n  \\end{equation*}\n  which is equivalent to\n  $\\iprod{\\vect{u},\\vect{v}}^2 \\leq \\iprod{\\vect{u},\\vect{u}} \\cdot\n  \\iprod{\\vect{v},\\vect{v}}$.\n\\end{proof}\n\nFinally, we can use the inner product to define the norm of a vector.\n\n\\begin{definition}{Norm}{inner-product-norm}\n  Let $\\vect{u}$ be a vector in an inner product space. Then the\n  \\textbf{norm}%\n  \\index{norm!in inner product space}%\n  \\index{vector!norm}%\n  \\index{inner product space!norm} of $\\vect{u}$ is defined as\n  \\begin{equation*}\n    \\norm{\\vect{u}} = \\sqrt{\\iprod{\\vect{u},\\vect{u}}}.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{example}{Norm in $C[-1,1]$}{norm-in-continuous-functions}\n  Calculate the norm of $f(x) = x^2$ in $C[-1,1]$.\n\\end{example}\n\n\\begin{solution}\n  In the vector space $C[-1,1]$, the inner product is defined as\n  \\begin{equation*}\n    \\iprod{f,g} = \\int_{-1}^{1} f(x)g(x)\\,dx.\n  \\end{equation*}\n  We therefore have\n  \\begin{equation*}\n    \\iprod{f,f}\n    = \\int_{-1}^{1} f(x)^2\\, dx\n    = \\int_{-1}^{1} x^4\\, dx\n    = \\bigbracket{\\frac{1}{5}x^5}_{-1}^{1}\n    = \\frac{2}{5}.\n  \\end{equation*}\n  Therefore, $\\norm{f} = \\sqrt{\\iprod{f,f}} = \\sqrt{\\frac{2}{5}}$.\n\\end{solution}\n\nA vector $\\vect{u}$ in an inner product space is called\n\\textbf{normalized}%\n\\index{vector!normalized}%\n\\index{normalized vector} or a \\textbf{unit vector}%\n\\index{vector!unit vector}%\n\\index{unit vector} if $\\norm{\\vect{u}} = 1$.\nWe note that if $\\vect{v}$ is any non-zero vector in an inner product\nspace, then\n\\begin{equation*}\n  \\vect{u} = \\frac{1}{\\norm{\\vect{v}}} \\vect{v}\n\\end{equation*}\nis normalized.\n\nBy the Cauchy-Schwarz inequality, we have the following properties:\n\n\\begin{proposition}{Inner product and norm}{inner-product-and-norm}\n  Let $\\vect{u},\\vect{v}$ be vectors in an inner product space. Then\n  \\begin{equation*}\n    \\abs{\\iprod{\\vect{u},\\vect{v}}} \\leq \\norm{\\vect{u}}\\norm{\\vect{v}}.\n  \\end{equation*}\n\\end{proposition}\n\n\\begin{proof}\n  The Cauchy-Schwarz inequality states that\n  $\\iprod{\\vect{u},\\vect{v}}^2 \\leq\n  \\norm{\\vect{u}}^2\\norm{\\vect{v}}^2$. The claim follows by taking the\n  square root of both sides of the equation.\n\\end{proof}\n\n\\begin{proposition}{Triangle inequality}{inner-product-triangle-inequality}\n  Let $\\vect{u},\\vect{v}$ be vectors in an inner product space. Then\n  \\begin{equation*}\n    \\norm{\\vect{u}+\\vect{v}} \\leq \\norm{\\vect{u}} + \\norm{\\vect{v}}.\n  \\end{equation*}\n  This is called the \\textbf{triangle inequality}%\n  \\index{triangle inequality!in inner product space}%\n  \\index{inner product space!triangle inequality}.\n\\end{proposition}\n\n\\begin{proof}\n  The proof is essentially the same as that of\n  Proposition~\\ref{prop:triangle-inequality-dot-product}. We have\n  \\begin{eqnarray*}\n    \\norm{\\vect{u}+\\vect{v}}^2\n    &=& \\iprod{\\vect{u}+\\vect{v},\\vect{u}+\\vect{v}} \\\\\n    &=& \\iprod{\\vect{u},\\vect{u}}+\\iprod{\\vect{u},\\vect{v}}+\\iprod{\\vect{v},\\vect{u}}+\\iprod{\\vect{v},\\vect{v}} \\\\\n    &=&\\norm{\\vect{u}}^2+2\\iprod{\\vect{u},\\vect{v}}+\\norm{\\vect{v}}^2 \\\\\n    &\\leq& \\norm{\\vect{u}}^2+2\\abs{\\iprod{\\vect{u},\\vect{v}}}+\\norm{\\vect{v}}^2 \\\\\n    &\\leq& \\norm{\\vect{u}}^2+2\\norm{\\vect{u}}\\norm{\\vect{v}}+\\norm{\\vect{v}}^2 \\\\\n    &=& (\\norm{\\vect{u}}+\\norm{\\vect{v}})^2.\n  \\end{eqnarray*}\n  The triangle inequality follows by taking square roots of both sides.\n\\end{proof}\n\nGeneralizing the situation in $\\R^n$, we can define the angle\nbetween any two vectors in an inner product space. Note that by the\nCauchy-Schwarz inequality,\n\\begin{equation*}\n  \\frac{\\abs{\\iprod{\\vect{u},\\vect{v}}}}{\\norm{\\vect{u}}\\norm{\\vect{v}}}\n  \\leq 1,\n\\end{equation*}\nand therefore,\n\\begin{equation*}\n  -1 \\leq \\frac{\\iprod{\\vect{u},\\vect{v}}}{\\norm{\\vect{u}}\\norm{\\vect{v}}}\n  \\leq 1.\n\\end{equation*}\nThis ensures that the following definition is well-defined.\n\n\\begin{definition}{Angle between two vectors}{inner-product-angle}\n  Let $\\vect{u},\\vect{v}$ be vectors in an inner product space.\n  The \\textbf{angle}%\n  \\index{angle!in inner product space}%\n  \\index{angle!between vectors} between $\\vect{u}$ and\n  $\\vect{v}$ is, by definition, the unique $\\theta$ such that\n  $0\\leq\\theta\\leq\\pi$ and\n  \\begin{equation*}\n    \\cos\\theta = \\frac{\\iprod{\\vect{u},\\vect{v}}}{\\norm{\\vect{u}}\\norm{\\vect{v}}}.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{example}{Find the angle between two vectors}{inner-product-angle}\n  Find the angle between $1$ and $x^2$ in $C[-1,1]$.\n\\end{example}\n\n\\begin{solution}\n  We have\n  \\begin{eqnarray*}\n    \\iprod{1,1} &=& \\int_{-1}^1 1\\cdot 1\\,dx ~=~ 2, \\\\\n    \\iprod{x^2,x^2} &=& \\int_{-1}^1 x^2\\cdot x^2\\,dx ~=~ \\frac{2}{5}, \\\\\n    \\iprod{1, x^2} &=& \\int_{-1}^1 1\\cdot x^2\\,dx ~=~ \\frac{2}{3}.\n  \\end{eqnarray*}\n  Therefore\n  \\begin{equation*}\n    \\cos\\theta\n    ~=~ \\frac{\\iprod{1,x^2}}{\\norm{1}\\norm{x^2}}\n    ~=~ \\frac{\\frac{2}{3}}{\\sqrt{2}\\sqrt{\\frac{2}{5}}}\n    ~=~ \\frac{\\sqrt{5}}{3}.\n  \\end{equation*}\n  The angle $\\theta$ is $\\cos^{-1}(\\frac{\\sqrt{5}}{3})$, which is\n  approximately $0.7297$ radians or $41.81$ degrees.\n\n\\end{solution}\n", "meta": {"hexsha": "62cf7d3f5bd32fc39a3671986808929f16154158", "size": 14724, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/InnerProductSpaces-Definition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/InnerProductSpaces-Definition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/InnerProductSpaces-Definition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 37.1818181818, "max_line_length": 114, "alphanum_fraction": 0.6507063298, "num_tokens": 5361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321936479701, "lm_q2_score": 0.9059898184796793, "lm_q1q2_score": 0.7298945648845103}}
{"text": "\\subsubsection{Magnetic Fields}\r\n\\noindent\r\nGauss's Law for magnetism says that that magnetic flux through a closed surface is 0. Rewritten more formally, \r\n\\begin{equation*}\r\n\t\\oint\\limits_{S}\\oint{\\vec{B} \\cdot \\mathrm{d}\\vec{s}} = 0\t\r\n\\end{equation*}\r\nSo, \r\n\\begin{equation*}\r\n\t\\iiint\\limits_{V}{\\nabla \\cdot \\vec{B}\\mathrm{d}V} = \\iiint\\limits_{V}{0\\mathrm{d}V}\r\n\\end{equation*}\r\nIf we let $V \\to 0$, \r\n\\begin{equation*}\r\n\t\\nabla \\cdot \\vec{B} = 0\t\r\n\\end{equation*}\r\nThis means that there are no lone sources or sinks in magnetic fields. You may also hear this law summarized as \"There are no magnetic monopoles.\" This is the 2nd of Maxwell's Equations.", "meta": {"hexsha": "06cfc79ce1ce9361e5cef474d33014e297fa7a3e", "size": 657, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorAnalysis/magneticFields.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/vectorAnalysis/magneticFields.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/vectorAnalysis/magneticFields.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.8, "max_line_length": 186, "alphanum_fraction": 0.7062404871, "num_tokens": 223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.8056321819811829, "lm_q1q2_score": 0.7298945538032794}}
{"text": "\\chapter{Counting and Probability}\n\n\\section{Counting}\n\n\\begin{enumerate}\n\n\\item[C.1{-}1] {How many $k$-substrings does an $n$-string have? (Consider\nidentical $k$-substrings at different positions to be different.) How many\nsubstrings does an $n$-string have in total?}\n\n\\begin{framed}\nFor every position $i$ of the $n$-string, $i = 1, \\dots, n - k + 1$, there is\none $k$-substring the starts at $i$ and ends at $i + k - 1$. Thus, the number of\n$k$-substrings in a $n$-string is\n\\[\n  \\sum_{i = 1}^{n - k + 1} 1 = n - k + 1.\n\\]\n\nThus, the number of substrings (of all sizes) in an $n$-string is\n\\begin{equation*}\n\\begin{aligned}\n  \\sum_{k = 1}^{n} n - k + 1 &= n^2 + n - \\sum_{k = 1}^{n} {k}\\\\\n                             &= n^2 + n - \\frac{n (n + 1)}{2}\\\\\n                             &= n (n + 1) - \\frac{n (n + 1)}{2}\\\\\n                             &= \\frac{n (n + 1)}{2}.\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[C.1{-}2] {An $n$-input, $m$-output \\textbf{\\emph{boolean function}} is\na function from $\\{\\texttt{TRUE}, \\texttt{FALSE}\\}^n$ to\n$\\{\\texttt{TRUE}, \\texttt{FALSE}\\}^m$. How many $n$-input, $1$-output boolean\nfunctions are there? How many $n$-input, $m$-output boolean functions are\nthere?}\n\n\\begin{framed}\nWe can view the number of possible inputs of size $n$ as the number of binary\n$n$-strings, which is $2^n$.\n\nNow, consider a single-valued function from $\\{\\texttt{TRUE},\n\\texttt{FALSE}\\}^n$ to $\\{\\texttt{TRUE}\\}$. In this case, the number of\npossible functions is the number of possible inputs, which is $2^n$. Since an\n$1$-output boolean function has two possible output values, each of the $2^n$\nfunctions we referred in the case of a single-valued function now has two ways\nto pick the output value. We can view this number as the number of binary\n$2^n$-strings, which is $2^{2^n}$. As for an $n$-output function, each of the\n$2^n$ functions we referred in the case of a single-valued function now has\n$2^m$ ways to pick the output value. Thus, there are $({2^m})^{2^n}$ of those.\n\\end{framed}\n\n\\item[C.1{-}3] {In how many ways can $n$ professors sit around a circular\nconference table? Consider two seatings to be the same if one can be rotated to\nform the other.}\n\n\\begin{framed}\nFor two seatings to be different from each other, the ordering of professors in\neach seating needs to be different. This number can be viewed as the number\nof permutations of a set $n$ elements, which is $n!$. However, note that for\neach permutation that starts with professor $k$, $1 \\le k \\le n$, there are\n$n - 1$ other permutations that are just a rotation of it. For instance, the\nseatings $\\{2, 3, 1\\}$ and $\\{3, 1, 2\\}$ are a rotation of $\\{1, 2, 3\\}$. Thus,\nthe number of different seatings can be viewed as fixing the seat of the first\nprofessor and computing the number of permutations of the remaining $n - 1$\nprofessors, which is $(n - 1)!$.\n\\end{framed}\n\n\\item[C.1{-}4] {In how many ways can we choose three distinct numbers from the\nset $\\{1, 2, \\dots, 99\\}$ so that their sum is even?}\n\n\\begin{framed}\nThe set has $50$ odd numbers and $49$ even numbers. For the sum be even, we have\nto choose three even numbers or one even and two odds. For the case with three\neven numbers, there are $49!/(3! \\cdot (49 - 3)!) = 18424$ ways of choosing $3$\ndistincts numbers among the 49 even numbers. As for the case with one even and\ntwo odds, there are 49 ways to choose one even number and\n$50!/(2! \\cdot (50 - 2)!) = 1225$ ways of choosing $2$ distincts numbers among the\n50 odd numbers. Thus, there are $18424 + 49 \\cdot 1225 = 78449$ ways to get an\neven sum.\n\\end{framed}\n\n\\newpage\n\n\\item[C.1{-}5] {Prove the identity\n\\[\n  \\binom{n}{k} = \\frac{n}{k} \\binom{n - 1}{k - 1}\n\\]\nfor $0 < k \\le n$.\n}\n\n\\begin{framed}\n\\begin{equation*}\n\\begin{aligned}\n  \\binom{n}{k} &= \\frac{n!}{k! \\cdot (n - k)!}\\\\\n               &= \\frac{n \\cdot (n - 1)!}{k \\cdot (k - 1)! \\cdot (n - k)!}\\\\\n               &= \\frac{n}{k} \\frac{(n - 1)!}{(k - 1)! \\cdot ((n - 1) - (k - 1))!}\\\\\n               &= \\frac{n}{k} \\binom{n - 1}{k - 1}.\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[C.1{-}6] {Prove the identity\n\\[\n  \\binom{n}{k} = \\frac{n}{n - k} \\binom{n - 1}{k}\n\\]\nfor $0 \\le k < n$.\n}\n\n\\begin{framed}\n\\begin{equation*}\n\\begin{aligned}\n  \\binom{n}{k} &= \\frac{n!}{k! \\cdot (n - k)!}\\\\\n               &= \\frac{n \\cdot (n - 1)!}{k! \\cdot (n - k) \\cdot (n - k - 1)!}\\\\\n               &= \\frac{n}{n - k} \\frac{(n - 1)!}{k! \\cdot ((n - 1) - k)!}\\\\\n               &= \\frac{n}{n - k} \\binom{n - 1}{k}.\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[C.1{-}7] {To choose $k$ objects from $n$, you can make one of the objects\ndistinguished and consider whether the distinguished object is chosen. Use this\napproach to prove that\n\\[\n  \\binom{n}{k} = \\binom{n - 1}{k} + \\binom{n - 1}{k - 1}.\n\\]\n}\n\n\\begin{framed}\nLet $S = \\{s_1, s_2, \\dots, s_{n - 1}\\}$ and $s_0$ the\ndistinguished element. To choose $k$ from the $n$ elements, we have to consider\ntwo cases:\n\\begin{enumerate}\n  \\item If $s_0$ is selected, it will be necessary to choose the $k - 1$\n    remaining elements from $S$. There are $\\binom{n - 1}{k - 1}$ combinations.\n  \\item If $s_0$ is not selected, it will be necessary to choose the $k$\n    remaining elements from $S$. There are $\\binom{n - 1}{k}$ combinations.\n\\end{enumerate}\nAdding the above together, we have\n\\begin{equation*}\n\\begin{aligned}\n  \\binom{n - 1}{k - 1} + \\binom{n - 1}{k}\n  &= \\frac{(n - 1)!}{(k - 1)! \\cdot (n - k)!} + \\frac{(n - 1)!}{k! \\cdot (n - k - 1)!}\\\\\n  &= \\frac{k \\cdot (n - 1)!}{k! \\cdot (n - k)!} + \\frac{(n - k) \\cdot (n - 1)!}{k! \\cdot (n - k)!}\\\\\n  &= \\frac{(k + n - k) \\cdot (n - 1)!}{k! \\cdot (n - k)!}\\\\\n  &= \\frac{n!}{k! \\cdot (n - k)!}\\\\\n  &= \\binom{n}{k}.\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[C.1{-}8] {Using the result of Exercise C.1-7, make a table for\n$n = 0, 1, \\dots, 6$ and $0 \\le k \\le n$ of the binomial coefficients\n$\\binom{n}{k}$ with $\\binom{0}{0}$ at the top, $\\binom{1}{0}$ and $\\binom{1}{1}$\non the next line, and so forth. Such a table of binomial coefficients is called\n\\textbf{\\emph{Pascal's triangle}}.}\n\n\\begin{framed}\nThe table with binomials\n\\begin{gather*}\n  \\binom{0}{0}\\\\\n  \\binom{1}{0} \\quad \\binom{1}{1}\\\\\n  \\binom{2}{0} \\quad \\binom{2}{1} \\quad \\binom{2}{2}\\\\\n  \\binom{3}{0} \\quad \\binom{3}{1} \\quad \\binom{3}{2} \\quad \\binom{3}{3}\\\\\n  \\binom{4}{0} \\quad \\binom{4}{1} \\quad \\binom{4}{2} \\quad \\binom{4}{3} \\quad \\binom{4}{4}\\\\\n  \\binom{5}{0} \\quad \\binom{5}{1} \\quad \\binom{5}{2} \\quad \\binom{5}{3} \\quad \\binom{5}{4} \\quad \\binom{5}{5}\\\\\n  \\binom{6}{0} \\quad \\binom{6}{1} \\quad \\binom{6}{2} \\quad \\binom{6}{3} \\quad \\binom{6}{4} \\quad \\binom{6}{5} \\quad \\binom{6}{6}\n\\end{gather*}\nUsing the above table and the result of C.1-7, we have the Pascal's triangle\n\\begin{gather*}\n  1\\\\\n  1 \\quad 1\\\\\n  1 \\quad 2 \\quad 1\\\\\n  1 \\quad 3 \\quad 3 \\quad 1\\\\\n  1 \\quad 4 \\quad 6 \\quad 4 \\quad 1\\\\\n  1 \\quad 5 \\quad 10 \\quad 10 \\quad 5 \\quad 1\\\\\n  1 \\quad 6 \\quad 15 \\quad 20 \\quad 15 \\quad 6 \\quad 1\n\\end{gather*}\n\\end{framed}\n\n\\item[C.1{-}9] {Prove that\n\\[\n  \\sum_{i = 1}^{n} i = \\binom{n + 1}{2}.\n\\]\n}\n\n\\begin{framed}\nWe have\n\\begin{equation*}\n\\begin{aligned}\n  \\binom{n + 1}{2} &= \\frac{(n + 1)!}{2! \\cdot ((n + 1) - 2)!}\\\\\n                   &= \\frac{(n + 1) \\cdot n \\cdot (n - 1)!}{2 \\cdot (n - 1)!}\\\\\n                   &= \\frac{n (n + 1)}{2}\\\\\n                   &= \\sum_{i = 1}^{n} i,\n\\end{aligned}\n\\end{equation*}\nwhich also shows that the third Pascal's diagonal has the triangular numbers.\n\\end{framed}\n\n\\newpage\n\n\\item[C.1{-}10] {Show that for any integers $n \\ge 0$ and $0 \\le k \\le n$, the\nexpression $\\binom{n}{k}$ achieves its maximum value when $k = \\floor{n/2}$ or\n$k = \\ceil{n/2}$.}\n\n\\begin{framed}\nIt follows from the Pascal's triangle\n\\begin{gather*}\n  1\\\\\n  1 \\quad 1\\\\\n  1 \\quad 2 \\quad 1\\\\\n  1 \\quad 3 \\quad 3 \\quad 1\\\\\n  1 \\quad 4 \\quad 6 \\quad 4 \\quad 1\\\\\n  1 \\quad 5 \\quad 10 \\quad 10 \\quad 5 \\quad 1\\\\\n  1 \\quad 6 \\quad 15 \\quad 20 \\quad 15 \\quad 6 \\quad 1\\\\\n  \\quad \\quad \\vdots \\quad \\quad\n\\end{gather*}\n\nWe can prove by induction. The base case, which occurs when $n = 0$,\nholds since\n\\[\n  \\binom{n}{\\floor{n/2}} = \\binom{n}{\\ceil{n/2}} = \\binom{0}{0} = 1\n\\]\nis maximum on row 0.  Now, assume it holds for $n$. Then, if $n + 1$ is even,\nfrom Equation (C.3) we have\n\\begin{equation*}\n\\begin{aligned}\n  \\binom{n + 1}{\\floor{\\frac{n + 1}{2}}} = \\binom{n + 1}{\\ceil{\\frac{n + 1}{2}}}\n  &= \\binom{n}{\\left(\\frac{n + 1}{2} - 1\\right)} + \\binom{n}{\\left(\\frac{n + 1}{2}\\right)}\\\\\n  &= \\binom{n}{\\left(\\frac{n}{2} - \\frac{1}{2}\\right)} + \\binom{n}{\\left(\\frac{n}{2} + \\frac{1}{2}\\right)} & \\text{(since $n$ is odd)}\\\\\n  &= \\binom{n}{\\floor{\\frac{n}{2}}} + \\binom{n}{\\ceil{\\frac{n}{2}}},\n\\end{aligned}\n\\end{equation*}\nwhich shows that is also holds for $n + 1$ since\n\\[\n  \\binom{n}{\\floor{\\frac{n}{2}}} \\text{ and } \\binom{n}{\\ceil{\\frac{n}{2}}}\n\\]\nare both maximum on row $n$. The proof is similar when $n + 1$ is odd.\n\\end{framed}\n\n\\newpage\n\n\\item[C.1{-}11] {($\\star$) Argue that for any integers $n \\ge 0$, $j \\ge 0$,\n$k \\ge 0$, and $j + k \\le n$,\n\\[\n  \\binom{n}{j + k} \\le \\binom{n}{j} \\binom{n - j}{k}.\n\\]\n\nProvide both an algebraic proof and an argument based on a method for choosing\n$j + k$ items out of $n$. Give an example in which equality does not hold.\n}\n\n\\begin{framed}\nFor any integers $a \\ge 0, b \\ge 0,$ and $a \\ge b$, we have\n\\begin{equation*}\n\\begin{aligned}\n  (a + b)! &=   \\underbrace{(a + b) \\cdot (a + b - 1) \\cdot (a + b - 2) \\cdots}_\\text{$b$ times} a!\\\\\n           &\\ge \\underbrace{b \\cdot (b - 1) \\cdot (b - 2) \\cdots}_\\text{$b$ times} a!\\\\\n           &=   a! \\cdot b!.\n\\end{aligned}\n\\end{equation*}\n\nUsing the above result, we have\n\\begin{equation*}\n\\begin{aligned}\n  \\binom{n}{j} \\binom{n - j}{k} &=   \\frac{n!}{j! \\cdot (n - j)!} \\frac{(n - j)!}{k! \\cdot ((n - j) - k)!}\\\\\n                                &=   \\frac{n!}{j! \\cdot k! \\cdot ((n - j) - k)!}\\\\\n                                &\\ge \\frac{n!}{(j + k)! \\cdot (n - (j + k))!}\\\\\n                                &=   \\binom{n}{j + k}.\n\\end{aligned}\n\\end{equation*}\n\nThe expression on the left is the number of ways to choose an $(j + k)$-subset\nof an $n$-set (which leaves the reamining $n - (j + k)$ elements). Thus, it is\na partition of the original $n$-set into subsets of cardinalities $(j + k)$ and\n$n - (j + k)$. The right hand side has two factors: the first binomial\ncoefficient is the number of ways to choose a $j$-subset of an $n$-set (which\nleaves the reamining $n - j$ elements); the second is the number of ways to\nchoose a $k$-subset from the remaining $n - j$ elements. Thus, it is a partition\nof the original $n$-set into subsets of cardinalities $j, k$, and $n - (j + k)$.\nConsider now that we choose the $n - (j + k)$ first, leaving behind the\nremaining $j + k$ elements. There is precisely one way to choose an\n$(j + k)$-subset out of the remaining $j + k$ elements. On the other hand, when\nwe first choose $j$ and then we choose $k$, if $j < j + k$, there are\n\\emph{at least} two ways to choose a $j$-subset from the $(j + k)$-subset and\nprecisely one way to choose a $k$-subset from the remaining $k$ elements. This\nnotion also applies to the algebraic proof, since\n$(j + k)! = j! \\cdot k \\iff j = 0$ or $k = 0$.\nAlso note that while the left expression does not count any permutation of the\n$(j + k)$-subsets (since it normalizes by $(j + k)!$), the right\nexpression, despite not counting permutations of each of the subsets\nindepentently (since it normalizes by $j! \\cdot k!$), it counts permutations of\ntwo subsets together. For instance, let $A = \\{a, b\\}$. There is only one way to\nchoose 2 elements from $A$, which is $ab$. However, there are two ways to choose\none element and then another element from $A$, which are $ab$ and $ba$.\n\n\\end{framed}\n\n\\item[C.1{-}12] {($\\star$) Use induction on all integers $k$ such that\n$0 \\le k \\le n/2$ to prove inequality (C.6), and use equation (C.3) to extend it\nto all integers $k$ such that $0 \\le k \\le n$.}\n\n\\begin{framed}\nSkipped.\n\\end{framed}\n\n\\item[C.1{-}13] {($\\star$) Use Stirling's approximation to prove that\n\\[\n  \\binom{2n}{n} = \\frac{2^{2n}}{\\sqrt{\\pi n}} (1 + O(1/n)).\n\\]\n}\n\n\\begin{framed}\nSkipped.\n% \\begin{equation*}\n% \\begin{aligned}\n%   \\binom{2n}{n} &= \\frac{(2n)!}{n! \\cdot (2n - n)!}\\\\\n%                 &= \\frac{(2n)!}{(n!)^2}\\\\\n%                 &= \\frac{\\sqrt{2 \\pi 2n} \\left(\\frac{2n}{e}\\right)^{2n} \\left( 1 + \\Theta\\left(\\frac{1}{2n}\\right) \\right)}\n%                         {(\\sqrt{2 \\pi n} \\left(\\frac{n}{e}\\right)^{n} \\left( 1 + \\Theta\\left(\\frac{1}{n}\\right) \\right))^2}\\\\\n%                 &= \\frac{\\sqrt{2 \\pi 2n} \\left(\\frac{2n}{e}\\right)^{2n} \\left( 1 + O\\left(\\frac{1}{n}\\right) \\right)}\n%                         {2 \\pi n \\left(\\frac{n}{e}\\right)^{2n} \\left( 1 + O\\left(\\frac{1}{n}\\right) \\right)^2}\n% \\end{aligned}\n% \\end{equation*}\n\\end{framed}\n\n\\item[C.1{-}14] {($\\star$) By differentiating the entropy function $H(\\lambda)$,\nshow that it achieves its maximum value at $\\lambda = 1/2$. What is $H(1/2)$?}\n\n\\begin{framed}\nSkipped.\n\\end{framed}\n\n\\item[C.1{-}15] {($\\star$) Show that for any integer $n \\ge 0$,\n\\[\n  \\sum_{k = 0}^{n} \\binom{n}{k} k = n 2^{n - 1}.\n\\]\n}\n\n\\begin{framed}\nSkipped.\n% \\begin{equation*}\n% \\begin{aligned}\n%   \\sum_{k = 0}^{n} \\binom{n}{k} k\n%   &= \\sum_{k = 1}^{n} \\binom{n}{k} k\\\\\n%   &= \\sum_{k = 1}^{n} \\frac{n!}{k! \\cdot (n - k)!}\\\\\n%   &= \\sum_{k = 1}^{n} \\frac{n \\cdot (n - 1)!}{k \\cdot (k - 1)! (n - k) \\cdot (n - k - 1)!}\n% \\end{aligned}\n% \\end{equation*}\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section{Probability}\n\n\\begin{enumerate}\n\n\\item[C.2{-}1] {Professor Rosencrantz flips a fair coin once. Professor\nGuildenstern flips a fair coin twice. What is the probability that Professor\nRosencrantz obtains more heads than Professor Guildenstern?}\n\n\\begin{framed}\nThe sample space $\\{\\text{H}, \\text{T}\\}^3$ has size $2^3 = 8$. Since the only\nevent that satisfies the condition is $\\{\\text{HTT}\\}$, the probability is $1/8$.\n\\end{framed}\n\n\\item[C.2{-}2] {Prove the \\textbf{\\emph{Boole's inequality}}: For any finite or\ncountably infinite sequence of events $A_1, A_2, \\dots$,\n\\[\n  \\text{Pr}\\{A_1 \\cup A_2 \\cup \\cdots\\} \\le \\text{Pr}\\{A_1\\} + \\text{Pr}\\{A_2\\} + \\cdots.\n\\]\n}\n\n\\begin{framed}\nFrom (C.13) we have\n\\[\n\\text{Pr}\\{A_1 \\cup A_2\\} \\le \\text{Pr}\\{A_1\\} + \\text{Pr}\\{A_2\\},\n\\]\nwhich implies\n\\begin{equation*}\n\\begin{aligned}\n  \\text{Pr}\\{A_1 \\cup A_2 \\cup \\cdots\\} &=   \\text{Pr}\\{A_1 \\cup (A_2 \\cup \\cdots)\\}\\\\\n                                        &\\le \\text{Pr}\\{A_1\\} + \\text{Pr}\\{A_2 \\cup (A_3 \\cup \\cdots)\\}\\\\\n                                        &\\le \\text{Pr}\\{A_1\\} + \\text{Pr}\\{A_2\\} + \\text{Pr}\\{A_3 \\cup (A_4 \\cup \\cdots)\\}\\\\\n                                        &\\le \\text{Pr}\\{A_1\\} + \\text{Pr}\\{A_2\\} + \\text{Pr}\\{A_3\\} \\cdots.\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[C.2{-}3] {Suppose we shuffle a deck of 10 cards, each bearing a distinct\nnumber from 1 to 10, to mix the cards thoroughly. We then remove three cards,\none at a time, from the deck. What is the probability that we select the three\ncards in sorted (increasing) order?}\n\n\\begin{framed}\nLet $a < b < c$ denote the number of the three selected cards. There are $3!$\npermutations of $\\{a, b, c\\}$ and $abc$ is the only one which is in sorted\norder. Thus, the probability is $1/3! = 1/6$.\n\\end{framed}\n\n\\item[C.2{-}4] {Prove that\n\\[\n  \\text{Pr}\\{A\\;|\\;B\\} + \\text{Pr}\\{\\overline{A}\\;|\\;B\\} = 1.\n\\]\n}\n\n\\begin{framed}\nWe have\n\\begin{equation*}\n\\begin{aligned}\n  \\text{Pr}\\{B\\} &= \\text{Pr}\\{(B \\cap A) \\cup (B \\cap \\overline{A})\\}\\\\\n                 &= \\text{Pr}\\{B \\cap A\\} + \\text{Pr}\\{B \\cap \\overline{A}\\}\\\\\n                 &= \\text{Pr}\\{A\\} \\text{Pr}\\{B\\;|\\;A\\} + \\text{Pr}\\{\\overline{A}\\} \\text{Pr}\\{B\\;|\\;\\overline{A}\\}.\n\\end{aligned}\n\\end{equation*}\nSubstituting into (C.17) yields\n\\begin{equation*}\n\\begin{aligned}\n  \\text{Pr}\\{A\\;|\\;B\\} + \\text{Pr}\\{\\overline{A}\\;|\\;B\\}\n  &= \\frac{\\text{Pr}\\{A\\} \\text{Pr}\\{B\\;|\\;A\\}}{\\text{Pr}\\{B\\}} +\n     \\frac{\\text{Pr}\\{\\overline{A}\\} \\text{Pr}\\{B\\;|\\;\\overline{A}\\}}{\\text{Pr}\\{B\\}}\\\\\n  &= \\frac{\\text{Pr}\\{A\\} \\text{Pr}\\{B\\;|\\;A\\} + \\text{Pr}\\{\\overline{A}\\} \\text{Pr}\\{B\\;|\\;\\overline{A}\\}}\n          {\\text{Pr}\\{B\\}}\\\\\n  &= \\frac{\\text{Pr}\\{A\\} \\text{Pr}\\{B\\;|\\;A\\} + \\text{Pr}\\{\\overline{A}\\} \\text{Pr}\\{B\\;|\\;\\overline{A}\\}}\n          {\\text{Pr}\\{A\\} \\text{Pr}\\{B\\;|\\;A\\} + \\text{Pr}\\{\\overline{A}\\} \\text{Pr}\\{B\\;|\\;\\overline{A}\\}}\\\\\n  &= 1.\n\\end{aligned}\n\\end{equation*}\n\n\\end{framed}\n\n\\item[C.2{-}5] {Prove that for any collection of events $A_1, A_2, \\dots, A_n$,\n\\[\n  \\text{Pr}\\{A_1 \\cap A_2 \\cap \\cdots \\cap A_n\\} =\n    \\text{Pr}\\{A_1\\} \\cdot \\text{Pr}\\{A_2\\;|\\;A_1\\} \\cdot \\text{Pr}\\{A_3\\;|\\;A_1 \\cap A_2\\} \\cdots\n    \\text{Pr}\\{A_n\\;|\\;A_1 \\cap A_2 \\cap \\cdots \\cap A_{n - 1}\\}.\n\\]\n}\n\n\\begin{framed}\nIt is trivially valid for $n = 1$. As our base case, consider $n = 2$. From (C.16) we have\n\\[\n  \\text{Pr}\\{A_1 \\cap A_2\\} = \\text{Pr}\\{A_1\\} \\text{Pr}\\{A_2\\;|\\;A_1\\}.\n\\]\nNow assume it holds for $n$. For $n + 1$, we have\n\\begin{equation*}\n\\begin{aligned}\n  \\text{Pr}\\{A_1 \\cap A_2 \\cap \\cdots \\cap A_{n + 1}\\}\n  &= \\text{Pr}\\{(A_1 \\cap A_2 \\cap \\cdots \\cap A_n) \\cap A_{n + 1}\\}\\\\\n  &= \\text{Pr}\\{A_1 \\cap A_2 \\cap \\cdots \\cap A_n\\} \\text{Pr}\\{A_{n + 1}\\;|\\;A_1 \\cap A_2 \\cap \\cdots \\cap A_n\\}\\\\\n  &= \\text{Pr}\\{A_1\\} \\cdot \\text{Pr}\\{A_2\\;|\\;A_1\\} \\cdot \\text{Pr}\\{A_3\\;|\\;A_1 \\cap A_2\\} \\cdots\n     \\text{Pr}\\{A_{n + 1}\\;|\\;A_1 \\cap A_2 \\cap \\cdots \\cap A_{n}\\}.\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[C.2{-}6] {($\\star$) Describe a procedure that takes as input two integers\n  $a$ and $b$ such that $0 < a < b$ and, using fair coin flips, produces as\n  output heads with probability $a/b$ and tails with probability $(b - a)/b$.\n  Give a bound on the expected number of coin flips, which should be $O(1)$.\n  (Hint: Represent $a/b$ in binary.)}\n\n\\begin{framed}\nConsider a continuous uniform probability distribution on\n$\\interval[open right]{0}{1}$, such that $\\text{Pr}\\{\\interval[open right]{0}{1}\\} = 1$. We have\n\\[\n  \\text{Pr}\\left\\{\\interval[open right, scaled]{0}{\\frac{a}{b}}\\right\\} = \\frac{a}{b},\n\\]\nand\n\\[\n  \\text{Pr}\\left\\{\\interval[open right, scaled]{\\frac{a}{b}}{1}\\right\\} = 1 - \\frac{a}{b} = \\frac{b - a}{b}.\n\\]\n\nWith this notion, we can write a procedure that sorts a real number from\n$\\interval[open right]{0}{1}$ and return heads if it is lower than $a/b$ or\nreturn tails, otherwise. Using fair coin flips and representing numbers in\nbinary, for each flip we have a new decimal place from a random number on\n$\\interval[open right]{0}{1}$ (consider an ``0'' if the coin flip is head and\n``1'', otherwise). Then,\n\\begin{itemize}\n\\item if the $i$-th flip is 1 and the $i$-th decimal place\nof $a/b$ is 0, the sorted number is larger than $a/b$ and we return tails;\n\\item if the $i$-th flip is 0 and the $i$-th decimal place\nof $a/b$ is 1, the sorted number is smaller than $a/b$ and we return head;\n\\item if the $i$-th flip and the $i$-th decimal place are equal, we sort a new\ndecimal place.\n\\end{itemize}\n\nSince we do not know how many decimal places $a/b$ has (if periodic, this number\nis infinite), the above procedure does not have a maximum number of iterations.\nHowever, since for each flip we have a probability of 1/2 of returning head or\ntails, the probability of terminating at flip $i$, for $i \\ge 1$, is\n\\[\n  \\underbrace{1/2 \\cdot 1/2 \\cdots}_\\text{$i$ times} = \\frac{1}{2^i}.\n\\]\nThus, by using the notion of expected value and the result (A.8), the expected number of\nflips is\n\\[\n  \\sum_{i = 1}^{\\infty} i \\cdot \\frac{1}{2^i}\n  = \\sum_{i = 0}^{\\infty} i \\cdot \\left(\\frac{1}{2}\\right)^{i}\n  = \\frac{1/2}{(1 - 1/2)^2} = 2.\n\\]\n\n\\end{framed}\n\n\\item[C.2{-}7] {($\\star$) Show how to construct a set of $n$ events that are\n  paiwise independent but such that no subset of $k > 2$ of them is mutually\n  independent.}\n\n\\begin{framed}\nSkipped.\n\\end{framed}\n\n\\item[C.2{-}8] {($\\star$) Two events $A$ and $B$ are \\textbf{\\emph{conditionally\n  independent}}, given $C$, if\n  \\[\n    \\text{Pr}\\{A \\cap B\\;|\\;C\\} = \\text{Pr}\\{A\\;|\\;C\\} \\cdot \\text{Pr}\\{B\\;|\\;C\\}.\n  \\]\n  Give a simple but nontrivial example of two events that are not independent\n  but are conditionally independent given a third event.\n}\n\n\\begin{framed}\nSkipped.\n\\end{framed}\n\n\\newpage\n\n\\item[C.2{-}9] {($\\star$) You are a contestant in a game show in which a prize\n  is hidden behind one of three curtains. You will win the prize if you select\n  the correct curtain. After you have picked one curtain but before the curtain\n  is lifted, the emcee lifts one of the other curtains, knowing that it will\n  reveal an empty stage, and asks if you would like to switch from your current\n  selection to the remaining curtain. How would your chances change if you\n  switch? (This question is the celebrated \\textbf{\\emph{Monty Hall problem}},\n  named after a game-show host who often presented contestants with just this\n  dilemma.)}\n\n\\begin{framed}\nIf you never switch, the only way to win is to choose the right curtain at the\nbeginning (before the emcee lifts one of the others). In this case, your chance\nto win are $1/3$. If you always switch, the only way to loose is to choose the\nright curtain at the beginning. In this case, when you choose a curtain without\nthe prize, the emcee will reveal the other empty curtain and you will\ntherefore change to the correct one. Thus, your chance to win are $(1\n- 1/3) = 2/3$.\n\\end{framed}\n\n\\item[C.2{-}10] {($\\star$) A prison warden has randomly picked one prisoner\n  among three to go free. The other two will be executed. The guard knows which\n  one will go free but is forbidden to give any prisoner information regarding\n  his status. Let us call the prisoners $X, Y$, and $Z$. Prisoner $X$ asks the\n  guard privately which of $Y$ or $Z$ will be executed, arguing that since he\n  already knows that at least one of them must die, the guard won't be revealing\n  any information about his own status. The guard tells $X$ that $Y$ is to be\n  executed.  Prisoner $X$ feels happier now, since he figures that either he or\n  prisoner $Z$ will go free, which means that his probability of going free is\n  now $1/2$. Is he right, or are his chances still $1/3$? Explain.}\n\\begin{framed}\n  His chances are still $1/3$. Let $A$ be the event of prisoner $X$ going free\n  and $B$ the event that the guard tells $X$ that $Y$ is to be executed. We have\n  \\[\n    \\text{Pr}(A\\;|\\;B) = \\frac{\\text{Pr}(A) \\text{Pr}(B\\;|\\;A)}{\\text{Pr}(B)} = \\frac{1/3 \\cdot 1/2}{1/2} = \\frac{1}{3}.\n  \\]\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section{Discrete random variables}\n\n\\begin{enumerate}\n\n\\item[C.3{-}1]{Suppose we roll two ordinary, 6-sided dice. What is the\nexpectation of the sum of the two values showing? What is the expectation of\nthe maximum of the two values showing?}\n\n\\begin{framed}\nThere are $36$ elementary events in the sample space. Since they are\nordinary dices, the probability distribution is uniform.\n\nLet $X$ be the random variable of the sum of the two values. The possible\noutcomes of $X$ are\n\\begin{center}\n\\begin{tabular}{rrrrrrr}\n  & \\textbf{1} & \\textbf{2} & \\textbf{3} & \\textbf{4} & \\textbf{5} & \\textbf{6}\\\\\n  \\textbf{1} & 2 & 3 & 4 & 5  & 6  & 7\\\\\n  \\textbf{2} & 3 & 4 & 5 & 6  & 7  & 8\\\\\n  \\textbf{3} & 4 & 5 & 6 & 7  & 8  & 9\\\\\n  \\textbf{4} & 5 & 6 & 7 & 8  & 9  & 10\\\\\n  \\textbf{5} & 6 & 7 & 8 & 9  & 10 & 11\\\\\n  \\textbf{6} & 7 & 8 & 9 & 10 & 11 & 12\n\\end{tabular}\n\\end{center}\n\nThus, we have\n\\begin{equation*}\n\\begin{aligned}\n  \\text{E}[X] &= \\sum_{x = 2}^{12} x \\cdot \\text{Pr}(X = x)\\\\\n              &= 2 \\cdot \\frac{1}{36} + 3 \\cdot \\frac{2}{36} + 4 \\cdot \\frac{3}{36} + 5 \\cdot \\frac{4}{36}\n               + 6 \\cdot \\frac{5}{36} + 7 \\cdot \\frac{6}{36} + 8 \\cdot \\frac{5}{36} + 9 \\cdot \\frac{4}{36}\n               + 10 \\cdot \\frac{3}{36} + 11 \\cdot \\frac{2}{36} + 12 \\cdot \\frac{1}{36}\\\\\n              &= 7.\n\\end{aligned}\n\\end{equation*}\n\nLet $Y$ be the random variable of the maximum of the two values. The possible\noutcomes of $Y$ are\n\n\\begin{center}\n\\begin{tabular}{rrrrrrr}\n  & \\textbf{1} & \\textbf{2} & \\textbf{3} & \\textbf{4} & \\textbf{5} & \\textbf{6}\\\\\n  \\textbf{1} & 1 & 2 & 3 & 4 & 5 & 6\\\\\n  \\textbf{2} & 2 & 2 & 3 & 4 & 5 & 6\\\\\n  \\textbf{3} & 3 & 3 & 3 & 4 & 5 & 6\\\\\n  \\textbf{4} & 4 & 4 & 4 & 4 & 5 & 6\\\\\n  \\textbf{5} & 5 & 5 & 5 & 5 & 5 & 6\\\\\n  \\textbf{6} & 6 & 6 & 6 & 6 & 6 & 6\n\\end{tabular}\n\\end{center}\n\nThus, we have\n\\begin{equation*}\n\\begin{aligned}\n  \\text{E}[Y] &= \\sum_{x = 1}^{6} x \\cdot \\text{Pr}(X = x)\\\\\n              &= 1 \\cdot \\frac{1}{36} + 2 \\cdot \\frac{3}{36} + 3 \\cdot \\frac{5}{36} + 4 \\cdot \\frac{7}{36}\n               + 5 \\cdot \\frac{9}{36} + 6 \\cdot \\frac{11}{36}\\\\\n              &\\approx 4.47.\n\\end{aligned}\n\\end{equation*}\n\n\\end{framed}\n\n\\item[C.3{-}2]{An array $A[1 \\dots n]$ contains $n$ distinct numbers that are\nrandomly ordered, with each permutation of the $n$ numbers being equally\nlikely. what is the expectation of the index of the maximum element in the\narray? What is the expectation of the index of the minimum element in the\narray?}\n\n\\begin{framed}\nLet $X$ and $Y$ be random variables of the index of the maximum and minimum\nelements, respectivelly. Since each permutation is equaly likely,\n\\[\n  \\text{E}[X] = \\text{E}[Y] = \\sum_{i = 1}^{n} i \\cdot \\frac{1}{n} = \\frac{1}{n} \\frac{n (n + 1)}{2} = \\frac{n + 1}{2}.\n\\]\n\\end{framed}\n\n\\newpage\n\n\\item[C.3{-}3]{A carnival game consists of three dice in a cage. A player can\nbet a dollar on any of the numbers $1$ through $6$. The cage is shaken, and\nthe payoff is as follows. If the player's number doesn't appear on any of\nthe dice, he loses his dollar. Otherwise, if his number appears on exactly\n$k$ of the three dice, for $k = 1, 2, 3$, he keeps his dollar and wins $k$\nmore dollars. What is his expected gain from playing the carnival game\nonce?}\n\n\\begin{framed}\nLet $X$ be a random variable of the total gain. The possible outcomes are\n$-1, 1, 2, 3$. We have\n\\begin{equation*}\n\\begin{aligned}\n  & \\text{Pr}\\{X = -1\\} &&= (5/6 \\cdot 5/6 \\cdot 5/6)         &&= 125/216,\\\\\n  & \\text{Pr}\\{X = 1\\}  &&= (1/6 \\cdot 5/6 \\cdot 5/6) \\cdot 3 &&= 75/216,\\\\\n  & \\text{Pr}\\{X = 2\\}  &&= (1/6 \\cdot 1/6 \\cdot 5/6) \\cdot 3 &&= 15/216,\\\\\n  & \\text{Pr}\\{X = 3\\}  &&= (1/6 \\cdot 1/6 \\cdot 1/6)         &&= 1/216.\n\\end{aligned}\n\\end{equation*}\nThus, we have\n\\[\n  \\text{E}[X] = -1 \\cdot \\frac{125}{216} + 1 \\cdot \\frac{75}{216} + 2 \\cdot \\frac{15}{216} + 3 \\cdot \\frac{1}{216} \\approx -0.0787.\n\\]\n\\end{framed}\n\n\\item[C.3{-}4]{Argue that if $X$ and $Y$ are nonnegative random variables, then\n\\[\n  \\text{E}[\\max(X, Y)] \\le \\text{E}[X] + \\text{E}[Y].\n\\]\n}\n\n\\begin{framed}\nThe expectation of nonnegative random variables is a summation of nonnegative\nnumbers. Thus, since $\\text{E}[\\max(X, Y)]$ is either $\\text{E}[X]$ or\n$\\text{E}[Y]$, it must be equal or lower than $\\text{E}[X] + \\text{E}[Y]$.\n\\end{framed}\n\n\\item[C.3{-}5]{($\\star$) Let $X$ and $Y$ be independent random variables. Prove\nthat $f(X)$ and $g(Y)$ are independent for any functions $f$ and $g$.}\n\n\\begin{framed}\nSkipped.\n\n% \\begin{equation*}\n% \\begin{aligned}\n%   \\text{Pr}\\{f(X) = f(x) \\text{ and } g(Y) = g(y)\\}\n%   &= \\text{Pr}\\{X = x \\text{ and } Y = y\\}\\\\\n%   &= \\text{Pr}\\{X = x\\} \\text{Pr}\\{Y = y\\}\\\\\n%   &= \\text{Pr}\\{f(X) = f(x)\\} \\text{Pr}\\{g(Y) = g(y)\\}.\n% \\end{aligned}\n% \\end{equation*}\n\n% Since $X$ and $Y$ are (discrete) independent random variables, we have\n% \\begin{equation*}\n% \\begin{aligned}\n% \\sum_{x} \\sum_{y} \\text{Pr}\\{X = x \\text{ and } Y = y\\}\n% &= \\sum_{x} \\sum_{y} \\text{Pr}\\{X = x\\} \\text{Pr}\\{Y = y\\}\\\\\n% &= \\sum_{x} \\text{Pr}\\{X = x\\} \\sum_{y} \\text{Pr}\\{Y = y\\}.\n% \\end{aligned}\n% \\end{equation*}\n\\end{framed}\n\n\\item[C.3{-}6]{($\\star$) Let $X$ be a nonnegative random variable, and suppose\nthat $\\text{E}[X]$ is well defined. Prove \\textbf{\\emph{Markov's inequality}}:\n\\[\n  \\text{Pr}\\{X \\ge t\\} \\le \\text{E}[X]/t\n\\]\nfor all $t > 0$.\n}\n\n\\begin{framed}\nWe have\n\\begin{equation*}\n\\begin{aligned}\n  \\text{E}[X] &=   \\sum_{x}{x \\cdot \\text{Pr}\\{X = x\\}}\\\\\n              &\\ge \\sum_{x \\ge t}{x \\cdot \\text{Pr}\\{X = x\\}}\\\\\n              &\\ge \\sum_{x \\ge t}{t \\cdot \\text{Pr}\\{X = x\\}}\\\\\n              &= t \\cdot \\sum_{x \\ge t}{\\text{Pr}\\{X = x\\}}\\\\\n              &= t \\cdot \\text{Pr}\\{X \\ge t\\},\n\\end{aligned}\n\\end{equation*}\nwhich implies\n\\[\n  \\text{Pr}\\{X \\ge t\\} \\le \\text{E}[X]/t.\n\\]\n\\end{framed}\n\n\\newpage\n\n\\item[C.3{-}7]{($\\star$) Let $S$ be a sample space, and let $X$ and $X'$ be\nrandom variables such that $X(s) \\ge X'(s)$ for all $s \\in S$. Prove that for\nany real constant $t$,\n\\[\n  \\text{Pr}\\{X \\ge t\\} \\ge \\text{Pr}\\{X' \\ge t\\}.\n\\]\n}\n\n\\begin{framed}\nAssuming that the domain of $X$ and $X'$ are the sample space $S$, we have\n\\begin{equation*}\n\\begin{aligned}\n  \\text{Pr}\\{X \\ge t\\} &=   \\sum_{s \\in S:X(s) \\ge t}{\\text{Pr}\\{X = s\\}}\\\\\n                       &=   \\sum_{s \\in S:X'(s) \\ge t}{\\text{Pr}\\{X' = s\\}} + \\sum_{s \\in S:X(s) \\ge t > X'(s)}{\\text{Pr}\\{X' = s\\}}\\\\\n                       &\\ge \\sum_{s \\in S:X'(s) \\ge t}{\\text{Pr}\\{X' = s\\}}\\\\\n                       &=   \\text{Pr}\\{X' \\ge t\\}.\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[C.3{-}8]{Which is larger: the expectation of the square of a random\nvariable, or the square of its expectation?}\n\n\\begin{framed}\nWe have from (C.28)\n\\[\n  \\text{E}[X^2] = \\text{Var}[X] + \\text{E}^2[X],\n\\]\nwhich implies\n\\[\n  \\text{E}[X^2] \\ge \\text{E}^2[X],\n\\]\nsince both $\\text{Var}[X]$ and $\\text{E}^2[X]$ are nonnegative numbers.\n\n\\end{framed}\n\n\\item[C.3{-}9]{Show that for any random variable X that takes on only the values\n0 and 1, we have\n\\[\n  \\text{Var}[X] = \\text{E}[X] \\text{E}[1 - X].\n\\]\n}\n\n\\begin{framed}\nWe have\n\\[\n  \\text{E}[X] = 0 \\cdot \\text{Pr}\\{X = 0\\} + 1 \\cdot \\text{Pr}\\{X = 1\\} = \\text{Pr}\\{X = 1\\},\n\\]\nand\n\\[\n  \\text{E}[1 - X] = 1 \\cdot \\text{Pr}\\{X = 0\\} + 0 \\cdot \\text{Pr}\\{X = 1\\} = \\text{Pr}\\{X = 0\\},\n\\]\nwhich implies\n\\begin{equation*}\n\\begin{aligned}\n  \\text{Var}[X] &= \\text{E}[X^2] - \\text{E}^2[X] & \\text{(since $X^2 = X$)}\\\\\n                &= \\text{E}[X] - \\text{E}[X] \\text{E}[X]\\\\\n                &= \\text{E}[X] (1 - \\text{E}[X])\\\\\n                &= \\text{E}[X] (1 - \\text{Pr}\\{X = 1\\})\\\\\n                &= \\text{E}[X] \\text{Pr}\\{X = 0\\}\\\\\n                &= \\text{E}[X] \\text{E}[1 - X].\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[C.3{-}10]{Prove that $\\text{Var}[aX] = a^2 \\text{Var}[X]$ from the\ndefinition (C.27) of variance.}\n\n\\begin{framed}\nAssuming that $X$ is a random variable and $a$ is a constant, from (C.27) and\n(C.22) we have\n\\begin{equation*}\n\\begin{aligned}\n  \\text{Var}[a X] &= \\text{E}[(a X - \\text{E}[a X])^2]\\\\\n                  &= \\text{E}[(a X - a \\text{E}[X])^2]\\\\\n                  &= \\text{E}[a^2 (X - \\text{E}[X])^2]\\\\\n                  &= a^2 \\text{E}[(X - \\text{E}[X])^2]\\\\\n                  &= a^2 \\text{Var}[X].\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\end{enumerate}\n", "meta": {"hexsha": "ccb8fcbd289ab1dffd68def54f2b8ad386c5e176", "size": 30810, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/AC.tex", "max_stars_repo_name": "danielmoraes/clrs", "max_stars_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-07-08T17:39:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-07-08T17:39:19.000Z", "max_issues_repo_path": "chapters/AC.tex", "max_issues_repo_name": "danielmoraes/clrs", "max_issues_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-31T20:41:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-31T20:41:48.000Z", "max_forks_repo_path": "chapters/AC.tex", "max_forks_repo_name": "danielmoraes/clrs", "max_forks_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-03-12T04:51:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-12T04:51:51.000Z", "avg_line_length": 37.4362089915, "max_line_length": 136, "alphanum_fraction": 0.5918532944, "num_tokens": 11996, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.9059898153067649, "lm_q1q2_score": 0.7298945496443199}}
{"text": "\\section{Some Counting and Stirling's Formula}\r\n\\subsection{Some Counting}\r\nIf we have a finite set $\\Omega$, and let $M$ be the number of ways of partition $\\Omega$ into $k$ subsets $S_1,S_2,\\ldots,S_k$ with $|S_j|=n_j$ with $n_1+n_2+\\cdots +n_k=|\\Omega|$, then\r\n$$M=\\binom{|\\Omega|}{n_1,n_2,\\ldots,n_k}=\\frac{|\\Omega|}{n_1!n_2!\\cdots n_k!}$$\r\nWe suddenly want to count the number of strictly increasing and nondecreasing functions from the set $\\{1,2,\\ldots,k\\}$ to $\\{1,2,\\ldots,n\\}$.\r\nNote that each strictly increasing function in this way are uniquely identified by their image, so the number of such functions equals $\\binom{n}{k}$.\r\n\\footnote{$\\binom{n}{k}=0$ for $k>n$}\r\nTo count nondecreasing functions, however, we cannot use this trick.\r\nNonetheless, we can consider the bijection\r\n$$\\{f\\text{ nondecreasing}:\\{1,2,\\ldots,k\\}\\to\\{1,2,\\ldots,n\\}\\}\\to$$\r\n$$\\{f\\text{ strictly increasing}:\\{1,2,\\ldots,k\\}\\to\\{1,2,\\ldots,n+k-1\\}\\}$$\r\nby assigning a function $f$ in the previous set to the function $g(i)=f(i)+i-1$.\r\nSo that number is $\\binom{n+k-1}{k}$.\r\n\\subsection{Stirling's Formula}\r\n\\begin{definition}\r\n    Let $(a_n),(b_n)$ be two positive sequences, we say $a_n\\sim b_n$ if $a_n/b_n\\to 1$ as $n\\to\\infty$.\r\n\\end{definition}\r\n\\begin{theorem}[Stirling]\r\n    $$n!\\sim n^n\\sqrt{2\\pi n}e^{-n}$$\r\n\\end{theorem}\r\n\\begin{proposition}[Weaker Statement of Stirling's Formula]\r\n    $\\log(n!)\\sim n\\log n$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Let $\\ell_n=\\log(n!)$.\r\n    So we have\r\n    $$\\ell(n)=\\log 2+\\log 3+\\cdots+\\log n$$\r\n    Note that we have the trivial bound $\\log\\lfloor x\\rfloor\\le \\log x\\le \\log\\lfloor x+1\\rfloor$, hence\r\n    $$\\ell_{n-1}\\le\\int_1^n\\log x\\,\\mathrm dx\\le \\ell_n$$\r\n    So\r\n    $$n\\log(n)-n+1\\le \\ell_n\\le (n+1)\\log(n+1)-n$$\r\n    The proposition follows.\r\n\\end{proof}\r\n\\begin{proof}[Proof of Stirling's Formula]\r\n    Note that\r\n    $$\\int_a^bf(x)\\,\\mathrm dx=\\frac{f(a)+f(b)}{2}(b-a)-\\frac{1}{2}\\int_a^b(x-a)(b-x)f^{\\prime\\prime}(x)\\,\\mathrm dx$$\r\n    We take $f=\\log$ we have\r\n    $$\\int_k^{k+1}\\log x\\,\\mathrm dx=\\frac{\\log(k)+\\log(k+1)}{2}+\\frac{1}{2}\\int_0^1\\frac{x(1-x)}{(x+k)^2}\\,\\mathrm dx$$\r\n    Summing over $k=1,2,\\ldots,n-1$ we have\r\n    $$n\\log n-n+1=\\log(n!)-\\frac{\\log n}{2}+\\sum_{k=1}^{n-1}a_k$$\r\n    where\r\n    $$a_k=\\frac{1}{2}\\int_0^1\\frac{x(1-x)}{(x+k)^2}\\,\\mathrm dx$$\r\n    Note that it is easy to see the partial sum of $a_k$ converges, so we define $A=\\exp(1-\\sum_{k\\in\\mathbb N}a_k)$ to have\r\n    $$n!=n^n\\sqrt{n}e^{-n}A\\exp\\left(\\sum_{k=n}^\\infty a_k\\right)$$\r\n    Note that the last part goes to $1$ as $n\\to\\infty$, so it remains to show $A=\\sqrt{2\\pi}$.\\\\\r\n    We claim that\r\n    $$2^{-2n}\\binom{2n}{n}\\sim\\frac{1}{\\sqrt{\\pi n}}$$\r\n    since $2^{-2n}\\binom{2n}{n}\\sim\\sqrt 2/(A\\sqrt{n})$, it will prove what we want.\r\n    Consider\r\n    $$I_n=\\int_0^{\\pi/2}\\cos^n\\theta\\,\\mathrm d\\theta$$\r\n    It is trivial to see that it equals $I_{2n}=\\binom{2n}{n}\\pi/2^{2n+1}$ and $I_{2n+1}=2^{2n}\\binom{2n}{n}^{-1}/(2n+1)$.\r\n    We want to show that $I_{2n}/I_{2n+1}\\to 1$ which will prove the result, but this is obvious since $I_{n+2}/I_n\\to 1$ and $I_n$ is decreasing.\r\n\\end{proof}", "meta": {"hexsha": "ec650c6b4190447319cc29d2f1556bed419dfeb3", "size": 3133, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/count.tex", "max_stars_repo_name": "david-bai-notes/IA-Probability", "max_stars_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2/count.tex", "max_issues_repo_name": "david-bai-notes/IA-Probability", "max_issues_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2/count.tex", "max_forks_repo_name": "david-bai-notes/IA-Probability", "max_forks_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.1132075472, "max_line_length": 187, "alphanum_fraction": 0.6230450048, "num_tokens": 1235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.867035763237924, "lm_q1q2_score": 0.7298929288152688}}
{"text": "\\subsection{Absolute Cartesian Method}\n\n\\begin{frame}{Definition}\n    \\begin{itemize}\n        \\item Use a fixed reference frame which has $x,y,z$-axes (as opposed to $r,\\theta,z$-axes or $\\rho,\\theta,z$-axes).\n        \\item In a planar kinematic chain, the position of every link is defined by:\n        \\begin{itemize}\n            \\item Joint positions\n            \\item Center of gravity $g$\n            \\item Angle $\\theta$ with respect to $x$-axis\n       \\end{itemize}\n    \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\nFor planar mechanisms, the following relations are considered:\n\t\\begin{itemize}\n\t    \\item[] $\\displaystyle (x_A-x_B)^2+(y_A-y_B)^2=AB^2=l_{AB}^2$\n\t    \\item[] $\\displaystyle k=\\tan{\\theta}=\\frac{y_B-y_A}{x_B-x_A}$\n\t    \\item[] $\\displaystyle\\Rightarrow y=ax+b$\n\t\\end{itemize}\nwhere:\n\t\\begin{itemize}\n\t    \\item[-] $A(x_A,y_A)$, $B(x_B,y_B)$ are joint coordinates\n\t    \\item[-] $l_{AB}$ is the length of link $AB$\n\t    \\item[-] $\\theta$ is the angle of link $AB$ with respect to $x$-axis\n\t    \\item[-] $a,b$ are coefficients ($a$ is slope of link $AB$, $b$ is intercept)\n\t\\end{itemize}\nSolving these equations often yields 2 position coordinates. Depending on positions of other links, choose the correct solution.\n\\end{frame}", "meta": {"hexsha": "ca4beed6ee7e5e3e735ae49fe0da1e9f75179087", "size": 1243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Finished/position_analysis_pdf/Sections/Introduction/absolute_cartesian_method.tex", "max_stars_repo_name": "HungNguyenDang/literate-meme", "max_stars_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Finished/position_analysis_pdf/Sections/Introduction/absolute_cartesian_method.tex", "max_issues_repo_name": "HungNguyenDang/literate-meme", "max_issues_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Finished/position_analysis_pdf/Sections/Introduction/absolute_cartesian_method.tex", "max_forks_repo_name": "HungNguyenDang/literate-meme", "max_forks_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.4333333333, "max_line_length": 128, "alphanum_fraction": 0.6508447305, "num_tokens": 377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961706, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7298604007489055}}
{"text": "\\chapter{Conclusion and Outlook}\n\n\\section{Summary}\nWe defined an algebraic graph structure that expresses the Collatz sequences in the form of a tree. Next, the vertex reachability properties were unveiled by examining the relationship between successive nodes in $H_C$. Moreover, we dealt with graphs that represent other variants of Collatz sequences, for instance $5x+1$ or $181x+1$. The interesting part of both variants is that for these sequences the existence of cycles is known. They serve as the basis for further investigations of the problem.\n\n\\section{Further Research}\nIn subsequent studies, the properties of vertices in $H_C$ might be elaborated upon more closely by taking into account a vertex's label as well as its properties. Moreover we will investigate on the structure of a pruned trees $T_{\\ge j}$ including questions on calculating a left-child or right-child within any of these trees.", "meta": {"hexsha": "9d1484b817ca41c4fa2120ff12b6eda828b6f0ec", "size": 912, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01 Graph Theory/TeX/v6.0/chapter/06_conclusion_update_COX_EDIT.tex", "max_stars_repo_name": "Sultanow/collatz", "max_stars_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-01T15:12:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T15:54:55.000Z", "max_issues_repo_path": "01 Graph Theory/TeX/v6.0/chapter/06_conclusion_update_COX_EDIT.tex", "max_issues_repo_name": "Sultanow/collatz", "max_issues_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01 Graph Theory/TeX/v6.0/chapter/06_conclusion_update_COX_EDIT.tex", "max_forks_repo_name": "Sultanow/collatz", "max_forks_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-06T20:44:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-06T20:44:07.000Z", "avg_line_length": 130.2857142857, "max_line_length": 502, "alphanum_fraction": 0.8070175439, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297754396141, "lm_q2_score": 0.8104789178257653, "lm_q1q2_score": 0.7298603978681779}}
{"text": "\n\\subsection{The jackknife}\n\nWe have a statistic:\n\n\\(S(x_1, x_2,...,x_n)\\)\n\nWe may want to estimate moments for this statistic, but are unable to do so.\n\n\\subsubsection{The jackknife estimator}\n\nThe jackknife is an approach for getting moments for statistics.\n\nWe start by creating \\(n\\) statistics each leaving out one observation. \n\n\\(\\bar S_i(x_1,x_2,...x_{i-1},x_{i+1},...,x_n)\\)\n\nWe define:\n\n\\(\\bar S=\\dfrac{1}{n}\\sum_i\\bar S_i\\)\n\n\\subsubsection{Moments of the jackknife estimator}\n\nWe want to know the variance.\n\n\\(Var \\bar S=\\dfrac{n-1}{n}\\sum_i(\\bar S_i-\\bar S)^2\\).\n\n", "meta": {"hexsha": "a675db8450fcda2868018ed362aa9ee8a408ed2f", "size": 576, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/jackknife/01-01-jackknife.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/jackknife/01-01-jackknife.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/jackknife/01-01-jackknife.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.5714285714, "max_line_length": 76, "alphanum_fraction": 0.6979166667, "num_tokens": 179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7298592922604831}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Conditional distributions}\\label{sec:cond_dist}\n\nRecall that for any two events $A$ and $B$ with $\\prob(A)>0$, the \\emph{conditional probability} of $B$ given $A$ is \n\\[\n\\prob(B|A) = \\frac{\\prob(A\\cap B)}{\\prob(A)}.\n\\]\nThis notion extends to random variables: if $C$ and $D$ are subsets of $\\R$, the conditional probability of $\\{Y\\in D\\}$ given $\\{X\\in C\\}$ is\n\\[\n\\prob(Y\\in D|X\\in C) = \\frac{\\prob(X\\in C,Y\\in D)}{\\prob(X\\in C)}.\n\\]\n\n%-----------------------------\n\\subsection{Conditioning on events}\nLet $A$ be an event and let $Y$ be a random variable.\n\n\\begin{definition}\\label{def:conditional_on_events}\n\\ben\n\\it The \\emph{conditional distribution} of $Y|A$ is the function $\\prob_{Y|A}$ defined on subsets of $\\R$ by\n\\[\n\\prob_{Y|A}(D) = \\prob(Y\\in D|A) = \\frac{\\prob\\big(\\{Y\\in D\\}\\cap A\\big)}{\\prob(A)}\\qquad\\text{for all $D\\subseteq\\R$}.\n\\]\n\\it The \\emph{conditional CDF} of $Y|A$ is the function $F_{Y|A}$ defined on $\\R$ by\n\\[\nF_{Y|A}(y) = \\prob(Y\\leq y|A) = \\frac{\\prob\\big(\\{Y\\leq y\\}\\cap A\\big)}{\\prob(A)}\\qquad\\text{for all $y\\in\\R$}.\n\\]\n\\it If $Y$ is discrete the, \\emph{conditional PMF of $Y|A$} is the function \n\\[\nf_{Y|A}(y) = \\prob(Y=y|A) = \\frac{\\prob\\big(\\{Y=y\\}\\cap A\\big)}{\\prob(A)}.\n\\]\n\\it If $Y$ is continuous the \\emph{conditional PDF of $Y|A$} is the function \n\\[\nf_{Y|A}(y) = F'_{Y|A}(y).\n\\]\n\\it The \\emph{conditional expectation of $Y|A$} is taken with respect to the conditional distribution of $Y|A$:\n\\[\n\\expe\\big(Y|X) = \\begin{cases}\n\t\\ \\displaystyle\\sum_{i=1}^{\\infty} y_i f_{Y|A}(y_i)\t\t& \\text{if $Y$ is discrete;} \\\\[3ex]\n\t\\ \\displaystyle\\int_{-\\infty}^{\\infty} y f_{Y|A}(y)\\,dy\t& \\text{if $Y$ is continuous.} \n\\end{cases}\n\\]\n\\een\n\\end{definition}\n\n% example\n\\begin{example}\\label{example:cond_pmf}\nA fair coin is tossed repeatedly until a head occurs. Find the conditional PMF of the number of times the coin is tossed, given that the coin is tossed an odd number of times.\n\\begin{solution}\nLet $A$ be the event that the coin is tossed an odd number of times and let $Y$ be the number of times the coin is tossed. \nThe sample space is $\\Omega=\\{H,TH,TTH,TTTH,\\ldots\\}$ and $A=\\{H,TTH, TTTTH,\\ldots\\}$, and because the coin is fair, $\\prob(Y=k)=1/2^k$ so\n\\[\n\\prob(A) = \\frac{1}{2} + \\frac{1}{8} + \\frac{1}{32} + \\frac{1}{128} + \\ldots = \\frac{2}{3}.\n\\]\nHence the conditional PMF of $Y|A$ is \n\\[\nf_{Y|A}(k)\n\t= \\frac{\\prob(\\{Y=k\\}\\cap A)}{\\prob(A)}\n\t= \\begin{cases}\n\t3/2^{k+1}\t& \\text{if $k$ is odd,} \\\\\n\t0\t\t\t& \\text{if $k$ is even.} \n\t\\end{cases}\n\\]\nNote that the denominator acts as a \\emph{scale factor} to ensure that the conditional probabilities $f_{Y|A}(k)$ sum to $1$.\nThe conditional expectation of $Y|A$ is\n\\[\n\\expe(Y|A) \n\t= \\sum_{k=1}^{\\infty} k f_{Y|A}(y)\n\t= \\sum_{\\stackss{k=1}{k\\text{ odd}}}^{\\infty} \\frac{3k}{2^{k+1}}\n\t= \\sum_{\\ell=1}^{\\infty} \\frac{3(l+1)/2}{2^{(\\ell+1)/2+1}}\n\t= \\sum_{\\ell=1}^{\\infty} \\frac{3(l+1)}{4\\sqrt{2^{\\ell+1}}}\n\\]\n\\end{solution}\n\\end{example}\n\n% example\n\\begin{example}\nLet $Y\\sim\\text{Uniform}[0,1]$. Find the conditional expectation of $Y$ given that $1/2\\leq Y\\leq 3/4$.\n\\begin{solution}\nThe CDF of the standard uniform distribution is\n\\[\nF_Y(y) = \\begin{cases}\n\t0\t& \\text{if $y < 0$} \\\\\n\ty\t& \\text{if $0 \\leq y \\leq 1$} \\\\\n\t1\t& \\text{if $y > 1$.}\n\\end{cases}\n\\]\nLet $A=\\{1/2\\leq Y\\leq 3/4\\}$. Then the conditional CDF of $Y|A$ is\n\\begin{align*}\nF_{Y|A}(y) = \\prob(Y\\leq y|A)\n%\t& = \\frac{\\prob(Y\\leq y, A)}{\\prob(A)} \\\\\n\t& = \\frac{\\prob(Y\\leq y\\text{ and }1/2\\leq Y\\leq 3/4)}{\\prob(1/2\\leq Y\\leq 3/4)} \\\\\n\t& = \\frac{\\prob(Y\\leq y)-\\prob(Y\\leq 1/2)}{\\prob(Y\\leq 3/4)-\\prob(Y\\leq 1/2)} \\\\\n\t& = \\frac{F_Y(y)-F_Y(1/2)}{F_Y(3/4)-F_Y(1/2)} \n\t= \\begin{cases}\n    \t0\t& \\text{if $y < 1/2$} \\\\\n    \t4y\t& \\text{if $1/2 \\leq y \\leq 3/4$} \\\\\n    \t1\t& \\text{if $y > 3/4$.}\n    \\end{cases}\n\\end{align*}\nThe conditional PDF of $Y|A$ is therefore equal to $f_{Y|A}(y) = F'_{Y|X}(y) = 4$ if $1/2\\leq y\\leq 3/4$ and zero otherwise, which shows that $Y|A\\sim\\text{Uniform}[1/2,3/4]$. The conditional expectation of $Y|A$ is \n\\[\n\\expe(Y|A) \n\t= \\int_{-\\infty}^{\\infty} y f_{Y|A}(y)\\,dy\n\t= \\int_{1/2}^{3/4} 4y \\,dy\n\t= 5/8,\n\\]\nwhich is the mid-point of the interval $[1/2,3/4]$ as expected.\n\\end{solution}\n\\end{example}\n\n%-----------------------------\n\\subsection{Conditioning on random variables}\nLet $X$ and $Y$ be two random variables defined on the same probability space.\n\n\\begin{definition}\n\\ben\n\\it The conditional distribution of $Y|X$ is the function $\\prob_{Y|X}$ defined on pairs of subsets of $\\R$ by\n\\[\n\\prob_{Y|X}(C,D) = \\prob(Y\\in D|X\\in C) = \\frac{\\prob(X\\in C, Y\\in D)}{\\prob(X\\in C)}\\qquad\\text{for all $C,D\\subseteq\\R$}.\n\\]\nThis is completely determined by the following.\n\\it The conditional CDF of $Y|X$ is the function $F_{Y|X}$ defined on $\\R^2$ by\n\\[\nF_{Y|X}(x,y) = \\prob(Y\\leq y|X\\leq x) = \\frac{\\prob(X\\leq x, Y\\leq y)}{\\prob(X\\leq x)}\\qquad\\text{for all $x,y\\in\\R$}.\n\\]\n\\een\n\\end{definition}\n\n% lemma: cond CDF formula\n\\begin{lemma}\nThe conditional CDF of $Y|X$ satisfies \n\\[\nF_{Y|X}(x,y) = \\frac{F_{X,Y}(x,y)}{F_X(x)}\n\\]\nwhere $F_{X,Y}$ is the joint CDF of $X$ and $Y$, and $F_X$ is the marginal CDF of $X$.\n\\end{lemma}\n\\begin{proof}\n\\[\nF_{Y|X}(x,y) \n\t= \\prob(Y\\leq y\\,|\\,X\\leq x)\n\t= \\frac{\\prob(X\\leq x, Y\\leq y)}{\\prob(X\\leq x)}\n\t= \\frac{F_{X,Y}(x,y)}{F_X(x)}.\n\\]\n\\end{proof}\n\n%% def: cond PMF/PDF\n%Suppose we observe the event $\\{X=x\\}$ where $x$ is a fixed value. If the marginal PMF/PDF of $X$ satisfies $f_X(x)>0$, we write the conditional PMF/PDF of $Y|X=x$ as\n%\\begin{definition}\n%Let $x$ be a fixed value. If $f_X(x)>0$ the \\emph{conditional PMF/PDF of $Y|X=x$} is\n%\\[\n%f_{Y|X}(y|x) = \\frac{f_{X,Y}(x,y)}{f_X(x)}\n%\\]\n%where $f_{X,Y}$ is the joint PMF/PDF of $X$ and $Y$.\n%\\end{definition}\n%\n%\\bigskip\n%Recall the partition theorem for random events: if $\\{A_1,A_2,\\ldots\\}$ is a partition of $B$ then\n%\\[\n%\\prob(B) = \\sum_{i=1}^{\\infty} \\prob(B|A_i)\\prob(A_i).\n%\\]\n%We have the following version of the partition theorem for random variables. \n%\n%% partition theorem\n%\\begin{theorem}\\label{thm:partition_for_rvs}\n%The marginal PMF/PDF of $Y$ satisfies\n%\\[\\begin{array}{lll}\n%f_Y(y) & = \\displaystyle\n%\t\\sum_{i=1}^{\\infty} \t\tf_{Y|X}(y|x_i)f_X(x_i)\t\t& \\quad\\text{if $X$ is discrete, and} \\\\[4ex]\n%f_Y(y) & = \\displaystyle\n%\t\\int_{-\\infty}^{\\infty} \tf_{Y|X}(y|x)f_X(x)\\,dx\t\t& \\quad\\text{if $X$ is continuous.} \n%\\end{array}\n%\\]\n%\\end{theorem}\n%\\begin{proof}\n%For the continuous case (the discrete case is similar),\n%\\[\n%\\int f_{X|Y}(x|y) f_Y(y)\\,dy \n%\t= \\int \\left(\\frac{f_{X,Y}(x,y)}{f_Y(y)}\\right) f_Y(y)\\,dy\n%\t= \\int f_{X,Y}(x,y)\\,dy\n%\t= f_X(x).\n%\\]\n%\\end{proof}\n%\n%%-----------------------------\n%\\subsubsection{Change notation}\n%\n%%-----------------------------\n\n% def: cond PMF/PDF\n%Let $x$ be a fixed value and suppose we observe that $X=x$. If $X$ is a continuous random variable, we cannot define the conditional PMF/PDF of $Y|X=x$ using definition~\\ref{def:conditional_on_events}, because it might be that $\\prob(X=x)=0$, and division by zero is undefined. Instead we use the following.\n% where $x$ is a fixed value. If the marginal PMF/PDF of $X$ satisfies $f_X(x)>0$, we write the conditional PMF/PDF of $Y|X=x$ as\n\\begin{definition}\nIf $f_X(x)>0$ the \\emph{conditional PMF/PDF of $Y|X=x$} is \n\\[\nf_{Y|X=x}(y) = \\frac{f_{X,Y}(x,y)}{f_X(x)}\n\\]\nwhere $f_{X,Y}$ is the joint PMF/PDF of $X$ and $Y$.\n\\end{definition}\n\n\\bigskip\nRecall the partition theorem for random events: if $\\{A_1,A_2,\\ldots\\}$ is a partition of $B$ then\n\\[\n\\prob(B) = \\sum_{i=1}^{\\infty} \\prob(B|A_i)\\prob(A_i).\n\\]\nWe have the following version of the partition theorem for random variables. \n\n% partition theorem\n\\begin{theorem}\\label{thm:partition_for_rvs}\nThe marginal PMF/PDF of $Y$ satisfies\n\\[\\begin{array}{lll}\nf_Y(y) & = \\displaystyle\n\t\\sum_{i=1}^{\\infty} \t\tf_{Y|X=x_i}(y)f_X(x_i)\t\t& \\quad\\text{if $X$ is discrete, and} \\\\[4ex]\nf_Y(y) & = \\displaystyle\n\t\\int_{-\\infty}^{\\infty} \tf_{Y|X=x}(y)f_X(x)\\,dx\t\t& \\quad\\text{if $X$ is continuous.} \n\\end{array}\n\\]\n\\end{theorem}\n\\begin{proof}\nFor the continuous case (the discrete case is similar),\n\\[\n\\int f_{Y|X=x}(y) f_Y(y)\\,dx \n\t= \\int \\left(\\frac{f_{X,Y}(x,y)}{f_Y(y)}\\right) f_Y(y)\\,dx\n\t= \\int f_{X,Y}(x,y)\\,dx\n\t= f_Y(y).\n\\]\n\\end{proof}\n\n\\begin{definition}\\label{def:cond_expe_x}\nLet $x$ be a fixed value. The \\emph{conditional expectation of $Y|X=x$} is \n\\[\n\\begin{array}{lll}\n\\expe(Y|X=x) & = \\displaystyle\\sum_{j=1}^{\\infty} y_j\\,f_{Y|X=x}(y_j)\t\t& \\quad\\text{if $Y$ is discrete, or} \\\\[4ex]\n\\expe(Y|X=x) & = \\displaystyle\\int_{-\\infty}^{\\infty} y\\,f_{Y|X=x}(y)\\,dy\t& \\quad\\text{if $Y$ is continuous.} \n\\end{array}\n\\]\n\\end{definition}\n\n%-----------------------------\n\\subsection{Conditional expectation}\n\n\nFor any fixed value of $x$ the conditional expectation $\\expe(Y|X=x)$ is just a number. Let us now think of $x$ as a variable quantity, and consider the transformation\n\\[\n\\begin{array}{rccl}\n\tg:\t& \\R\t& \\to\t\t& \\R \\\\\n\t\t& x\t\t& \\mapsto\t& \\expe(Y|X=x)\n\\end{array}\n\\]\nThis transformation of $X$ yields a new random variable.\n\\begin{definition}\\label{def:cond_expe}\nThe \\emph{conditional expectation of $Y|X$} is the random variable\n\\[\\begin{array}{llll}\n\\expe(Y|X):\t& \\Omega \t& \\to \t\t& \\R \\\\\n\t\t\t& \\omega\t& \\mapsto \t& \\expe\\big[Y|X=X(\\omega)\\big].\n\\end{array}\\]\n\\end{definition}\n\nThe distribution of $\\expe(Y|X)$ depends only on the distribution of $X$ and its expectation is given by\n\\[\n\\begin{array}{lll}\n\\expe\\big[\\expe(Y|X)\\big] & = \\displaystyle\\sum_{i=1}^{\\infty}\\expe(Y|X=x_i)f_X(x_i)\t\t& \\quad\\text{if $X$ is discrete, or} \\\\[3ex]\n\\expe\\big[\\expe(Y|X)\\big] & = \\displaystyle\\int_{-\\infty}^{\\infty} \\expe(Y|X=x)f_X(x)\\,dx\t& \\quad\\text{if $X$ is continuous.} \n\\end{array}\n\\]\n\n% LTE\n\\begin{theorem}[Law of total expectation]\nLet $X$ and $Y$ be random variables defined on the same probability space. Then\n\\[\n\\expe(Y) = \\expe\\big[\\expe(Y|X)\\big].\n\\]\n\\end{theorem}\n\\begin{proof}\nFor discrete random variables (the continuous case is similar):\n\\begin{align*}\n\\expe\\big[\\expe(Y|X)\\big] \n\t= \\sum_x \\expe(Y|X=x) f_X(x) \n\t& = \\sum_x\\left(\\sum_y y\\,f_{Y|X}(y|x)\\right) f_X(x) \\\\\n\t& = \\sum_x\\left(\\sum_y y\\,\\frac{f_{X,Y}(x,y)}{f_X(x)}\\right) f_X(x) \\\\\n\t& = \\sum_x\\left(\\sum_y y f_{X,Y}(x,y)\\right) \\\\\n\t& = \\sum_x y \\left(\\sum_y f_{X,Y}(x,y)\\right) \\\\\n\t& = \\sum_x y f_Y(y)  \n\t= \\expe(Y).\n\\end{align*}\n\\end{proof}\n\n% LTV\n\\begin{theorem}[Law of total variance]\nIf $X$ and $Y$ are random variables defined on the same probability space,\n\\[\n\\var(Y) = \\expe\\big[\\var(Y|X)\\big] + \\var\\big[\\expe(Y|X)\\big] \n\\]\nwhere $\\var(Y|X)=\\expe(Y^2|X) - \\expe(Y|X)^2$.\n\\end{theorem}\n\\begin{proof}\nBy the law of total expectation,\n\\begin{align*}\n\\var(Y)\n\t& = \\expe(Y^2) - \\expe(Y)^2 \\\\\n\t& = \\expe\\big[\\expe(Y^2|X)\\big] - \\expe\\big[\\expe(Y|X)\\big]^2\n\\end{align*}\nBecause $\\var(Y|X)=\\expe(Y^2|X) - \\expe(Y|X)^2$,\n\\[\n\\var(Y) = \\expe\\big[\\var(Y|X) + \\expe(Y|X)^2\\big] - \\expe\\big[\\expe(Y|X)\\big]^2\n\\]\nHence, by the linearity of expectation,\n\\begin{align*}\n\\var(Y)\n\t& = \\expe\\big[\\var(Y|X)\\big] + \\Big(\\expe\\big[\\expe(Y|X)^2\\big] - \\expe\\big[\\expe(Y|X)\\big]^2\\Big) \\\\\n\t& = \\expe\\big[\\var(Y|X)\\big] + \\var[\\expe(Y|X)\\big].\n\\end{align*}\n\\end{proof}\n\n% example\n\\begin{example}\nLet the joint PDF of the continuous random variables $X$ and $Y$ be \n\\[\nf_{X,Y}(x,y) = \\begin{cases}\n\tcxy & \\quad\\text{for $x,y\\geq 0$ with $x+y\\leq 1$}, \\\\\n\t0\t& \\quad\\text{otherwise.}\n\\end{cases}\n\\]\n\\ben\n\\it Sketch the support of $f_{X,Y}$\n\\it Show that $c=24$.\n\\it Compute the conditional expectation $\\expe(Y|X)$.\n\\it Verify the identity $\\expe\\big[\\expe(Y|X)\\big]=\\expe(Y)$.\n\\een \n\n\\begin{solution}\n\\ben\n\n\\it % << (a)\n$\\supp(f_{X,Y})$ is the lower-left half of the unit square.\n\n\\it % << (b)\nThe marginal PDF of $X$ is\n\\[\nf_X(x) = c\\int_{0}^{1-x} xy\\,dy = \\frac{cx(1-x)^2}{2}\n\\]\nand similarly for $Y$. To find $c$,\n\\[\n\\int_{0}^{1} f_X(x)\\,dx = 1, \\qquad\\text{so}\\quad c=24.\n\\]\nThus\n\\begin{align*}\nf_X(x)\t& = 12x(1-x)^2 \\qquad 0\\leq x\\leq 1 \\\\\nf_Y(y)\t& = 12y(1-y)^2 \\qquad 0\\leq y\\leq 1 \\\\\n\\end{align*}\nand\n\\begin{align*}\n\\expe(X) & = 12\\int_0^1 x(1-x)^2\\,dx = 2/5 \\\\\n\\expe(Y) & = 12\\int_0^1 y(1-y)^2\\,dy = 2/5 \\\\\n\\end{align*}\n\n\\it % << (c)\nTo compute $\\expe(Y|X)$,\n\\begin{align*}\n\\expe(Y|X=x)\n\t= \\int_0^1 y\\left(\\frac{f_{X,Y}(x,y)}{f_X(x)}\\right)\\,dy\n\t& = \\int_0^{1-x} y\\left(\\frac{24xy}{12x(1-x)^2}\\right)\\,dy \\\\\n\t& = \\frac{24x}{12x(1-x)^2}\\int_0^{1-x} y^2\\,dy \\\\\n\t& =  \\frac{24x}{12x(1-x)^2}\\left[\\frac{(1-x)^3}{3}\\right]\n\t= \\frac{2}{3}(1-x)\t\n\\end{align*}\nso $\\expe(Y|X) = 2(1-X)/3$.\n\n\\it % << (d)\n\\begin{align*}\n\\expe\\big(\\expe(Y|X)\\big)\n\t& = \\int_0^1 \\expe(Y|X=x) f_X(x)\\,dx \\\\\n\t& = \\frac{2}{3}\\int_0^1 (1-x) f_X(x)\\,dx \\\\\n\t& = \\frac{2}{3}\\big(1-\\expe(X)\\big) = \\frac{2}{3}\\left(1-\\frac{2}{5}\\right) = \\frac{2}{5}\n\t= \\expe(Y).\n\\end{align*}\n\\een\n\\mbox{}\n\\end{solution}\n\\end{example}\n\n% exercises\n\\begin{exercise}\n\\begin{questions}\n\\question\nLet $X$ and $Y$ be jointly continuous random variables having the following joint PDF,\n\\[\nf_{X,Y}(x,y) = \n\\begin{cases}\n\t\\frac{21}{4}x^2y\t\t& \\quad x^2<y<1, \\\\\n\t0\t\t\t\t\t\t& \\quad\\text{otherwise.}\n\\end{cases}\n\\]\n\\ben\n\\it Sketch the support of $f_{X,Y}$.\n\\it Find the marginal PDFs of $X$ and $Y$.\n\\it Find the mean and variance of $Y$.\n\\it Find the conditional PDF of $Y$ given $X=x$. \n\\it Are $X$ and $Y$ independent? \n\\it Find the conditional expectation of $Y$ given $X=x$. \n\\it Find the conditional expectation of $Y$ given $X$. \n\\it Verify that $\\expe(Y)=\\expe\\big[\\expe(Y|X)\\big]$.\n\\een\n\n\\begin{answer}\n\\ben\n\\it % << (a)\nThe support of the joint PDF $f(x,y)$ is the set $\\{(x,y): x^2 < y < 1\\}$.  This is the region of the plane between the vertical lines $x=-1$ and $x=+1$, bounded above by the horizontal line $y=1$ and below by parabola $y=x^2$. In particular,\n\\bit\n\\it For fixed $x\\in[-1,1]$, $f_{X,Y}(x,y)\\neq 0$ only for $y\\in[x^2,1]$.\n\\it For fixed $y\\in[0,1]$, $f_{X,Y}(x,y)\\neq 0$ only for $x\\in[-\\sqrt{y},+\\sqrt{y}]$.\n\\eit\n\n\\it % << (b)\nThe marginal distributions are computed as follows:\n\\begin{align*}\nf_X(x) \t\n\t& = \\int_{-\\infty}^{\\infty} f(x,y)\\,dy \n\t= \\int_{x^2}^1 \\frac{21}{4}x^2y\\,dy \n\t= \\frac{21}{4}x^2\\left[\\frac{y^2}{2}\\right]_{x^2}^1 \n\t= \\begin{cases} \\frac{21}{8}x^2(1-x^4)\t& -1<x<1, \\\\ 0 & \\text{ otherwise.}\\end{cases} \\\\ [2ex]\nf_Y(y) \t\n\t& = \\int_{-\\infty}^{\\infty} f(x,y)\\,dx \n\t= \\int_{-\\sqrt{y}}^{\\sqrt{y}} \\frac{21}{4}x^2y\\,dx \n\t= \\frac{21}{4}y\\left[\\frac{x^3}{3}\\right]_{-\\sqrt{y}}^{\\sqrt{y}}\n\t= \\begin{cases} \\frac{7}{2}y^{5/2} & 0< y< 1, \\\\ 0 & \\text{ otherwise.}\\end{cases} \\\\\n\\end{align*}\n\n\\it % << (c)\nThe expected value and variance of $Y$ are computed as follows:\n\\begin{align*}\n\\expe(Y)\n\t& = \\int_{-\\infty}^{\\infty} y\\,f_Y(y)\\,dy \t= \\int_0^1 y\\left(\\frac{7y^{5/2}}{2}\\right)\\,dy = \\frac{7}{9}, \\\\\n\\expe(Y^2)\n\t& = \\int_{-\\infty}^{\\infty} y^2\\,f_Y(y)\\,dy = \\int_0^1 y^2\\left(\\frac{7y^{5/2}}{2}\\right)\\,dy = \\frac{7}{11}, \\\\\n\\var(Y)\n\t& = \\expe(Y^2) - \\expe(Y)^2 = \\frac{7}{11} - \\frac{49}{81} = \\frac{28}{891}.\n\\end{align*}\n\n\\it % << (d)\nThe conditional PDF of $Y$ given $X=x$ is\n\\[\nf_{Y|X=x}(y) \t\n\t= \\frac{f_{X,Y}(x,y)}{f_X(x)} \n\t= \\frac{(21/4)x^2y}{(21/8)x^2(1-x^4)} \t\n\t= \\begin{cases} \n\t\t\\displaystyle\\frac{2y}{1-x^4} \t& x^2\\leq y\\leq 1, \\\\\n\t \t0 \t\t\t\t\t\t\t\t& \\text{ otherwise}.\n\t \\end{cases}\n\\]\t \n\n\\it % << (e)\n$X$ and $Y$ are clearly not independent, because the support of $f_{X,Y}$ is not a rectangular region, and moreover, the conditional PDF of $Y$ given $X=x$ depends on $x$.\n\n\\it % << (f)\nThe conditional expected value of $Y$ given that $X=x$ is\n\\begin{align*}\n\\expe(Y|X=x) \n\t& = \\int_{-\\infty}^{\\infty} y f_{Y|X=x}(y\\,|\\,x)\\,dy \\\\\n\t& = \\int_{x^2}^1 y \\left(\\frac{2y}{1-x^4}\\right)\\,dy \n\t= \\frac{2}{1-x^4}\\left[\\frac{y^3}{3}\\right]_{x^2}^1\n\t= \\frac{2(1-x^6)}{3(1-x^4)} \n\\end{align*}\t\n\n\\it % << (g)\nThe conditional expectation of $Y$ given $X$ is the random variable \n\\[\n\\expe(Y|X)=\\displaystyle\\frac{2(1-X^6)}{3(1-X^4)}\n\\]\n\n\\it % << (h)\nThe expected value of $\\expe(Y|X)$ is\n\\begin{align*}\n\\expe\\big[\\expe(Y|X)\\big] \n\t& = \\int_{-\\infty}^{\\infty} \\expe(Y|X=x)f_X(x)\\,dx \\\\\n\t& = \\frac{2}{3}\\int_{-1}^{1} \\left(\\frac{1-x^6}{1-x^4}\\right)\\left(\\frac{21}{8}x^2(1-x^4)\\right)\\,dx \\\\\n\t& = \\frac{7}{4}\\int_{-1}^{1} x^2(1-x^6)\\,dx \n\t= \\frac{7}{9}.\n\\end{align*}\t\nThus $\\expe\\big[\\expe(Y|X)\\big]=\\expe(Y)$ as required.\n\\een\n\\end{answer}\n\n% house for sale\n\\question\nA man puts his house for sale and decides to accept the first offer that exceeds the reserve price of $r$. Let $Y_1,Y_2,\\ldots$ represent the sequence of offers received, and suppose that the $Y_i$ are independent and identically distributed random variables, each having exponential distribution with rate parameter $\\lambda$. \n\\begin{parts}\n\\part\nShow that the expected number of offers received before the house is sold is $e^{\\lambda r}$.\n\\begin{answer}\nLet $N$ be the number of offers received before the house is sold. Then $\\{N=k\\}$ is the event that the first $k-1$ offers are at most $r$, each occurring independently with probability $F(r)$, and the $k$th offer exceeds $r$, which occurs with probability $1-F(r)$. Thus $N$ has \\emph{geometric} distribution, with `probability of success' equal to $1-F(r)$ (where `success' corresponds to the sale of the house). Hence the expected number of offers received before the house is sold is\n\\[\n\\expe(N) = \\frac{1}{1-F(r)} = e^{\\lambda r}.\n\\]\n\\end{answer}\n\\part \nShow that the expected the expected selling price of the house is $r+1/\\lambda$.\n\\begin{answer}\nLet $Y\\sim\\text{Exponential}(\\lambda)$ and let $A=\\{Y>r\\}$. The con\nLet $F_S$ be the conditional CDF of $Y_i$ given that $X_i>r$:\n\\[\nF_Y|A(y)  \n\t= \\frac{\\prob(r < Y \\leq y)}{\\prob(Y > r)}\n\t= \\frac{F(y)-F(r)}{1-F(r)}\n\t= \\begin{cases}\n\t\t1 - e^{-\\lambda(y-r)} \t& y > r, \\\\\n\t\t0\t\t\t\t\t\t& \\text{otherwise.}\n\t\\end{cases}\n\\]\nA straightforward calculation yields $\\expe(Y|Y>r) = r + 1/\\lambda$.\n\\end{answer}\n\\end{parts}\n\n\\question\n\\textbf{Compound distributions}. If $Y\\sim\\text{Poisson}(\\lambda)$ then $\\expe(Y)=\\lambda$ and $\\var(Y)=\\lambda$. The Poisson distribution has only a single parameter so we cannot shift and scale the distribution by different ammounts, which limits its usefulness in certain practical applications. This problem can be addressed by allowing the parameter itself to be a random variable.\n\n\\begin{parts}\n\\part % exp\nLet $Y\\sim\\text{Poisson}(X)$ where $X\\sim\\text{Exponential}(\\theta)$ and $\\theta>0$ is a fixed scale parameter. Use the laws of total expectation and total variance, and the fact that $\\expe(X)=\\theta$ and $\\var(X)=\\theta^2$, to show that $\\expe(Y)=\\theta$ and $\\var(Y)=\\theta(1+\\theta)$.\n\\begin{answer}\nThe conditional expectation and conditional variance of $Y$ are\n\\[\n\\expe(Y|X) = X \\quad\\text{and}\\quad \\var(Y|X) = X.\n\\]\nBy the law of total expectation\n\\[\n\\expe(Y) = \\expe\\big[\\expe(Y|X)\\big] = \\expe(X) = \\theta,\n\\]\nand by the law of total variance,\n\\begin{align*}\n\\var(Y)\t\n\t& = \\expe\\big[\\var(Y|X)\\big] + \\var\\big[\\expe(Y|X)\\big] \\\\\n\t& = \\expe(X) + \\var(X) \\\\\n\t& = \\theta + \\theta^2 \n\t= \\theta(1+\\theta)\n\\end{align*}\t\nbecause $\\expe(X)=\\theta$ and $\\var(X)=\\theta^2$ for $X\\sim\\text{Exponential}(\\theta)$.\n\\end{answer}\n\n\\part % gamma\nLet $Y\\sim\\text{Poisson}(X)$ where $X\\sim\\text{Gamma}(\\alpha,\\beta)$ for some fixed parameters $\\alpha,\\beta>0$. Find values for $\\alpha$ and $\\beta$ such that $\\expe(Y)=2$ and $\\var(Y)=9$.\n\\begin{answer}\nBecause $Y\\sim\\text{Poisson}(X)$ we have $\\expe(Y|X)=X$ and $\\var(Y|X)=X$, so both are distributed according to the $\\text{Gamma}(\\alpha,\\beta)$ distribution, whose mean and variance are $\\alpha/\\beta$ and $\\alpha/\\beta^2$ respectively. \n\nBy the laws of total expectation and total variance,\n\\begin{align*}\n\\expe(Y)\n\t& = \\expe\\big[\\expe(Y|X)\\big] = \\expe(X) = \\alpha/\\beta \\\\\n\\var(Y)\t\n\t& = \\expe\\big[\\var(Y|X)\\big] + \\var\\big[\\expe(Y|X)\\big] = \\expe(X) + \\var(X) = \\alpha(\\beta+1)/\\beta^2.\n\\end{align*}\nSolving $\\alpha/\\beta=2$ and $\\alpha(\\beta+1)/\\beta^2=9$ yields $\\alpha=4/7$ and $\\beta=2/7$. \n\n\\bigskip\nIf $\\alpha$ is an integer, $Y$ has the so-called $\\text{NegativeBinomial}(r,p)$ distribution with $r=\\alpha$ and $p=1/(1+\\beta)$. This is the distribution of the number of successes up to the $r$th failure in a sequence of independent Bernoulli trials where each trial has probability of success $p$. \n\\end{answer}\n\\end{parts}\n\\end{questions}\n\\end{exercise}\n\n", "meta": {"hexsha": "631e416927782f68fa30833602808b6fa336f423", "size": 20155, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/05C_conditional_distributions.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/05C_conditional_distributions.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/05C_conditional_distributions.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 35.8629893238, "max_line_length": 487, "alphanum_fraction": 0.6157281072, "num_tokens": 8179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.8757869884059267, "lm_q1q2_score": 0.7298148521937823}}
{"text": "\\section{Limit Theorems}\r\n\\subsection{Law(s) of Large Numbers}\r\n\\begin{theorem}[Weak Law of Large Numbers]\r\n    Let $(X_n:n\\in\\mathbb N)$ be an iid sequence of random variables with finite expectation $\\mu$.\r\n    Set $S_n=X_1+\\cdots+X_n$, then for any $\\epsilon>0$, we have\r\n    $$\\mathbb P\\left( \\left|\\frac{S_n}{n}-\\mu\\right|>\\epsilon \\right)\\to 0$$\r\n    as $n\\to\\infty$.\r\n\\end{theorem}\r\nWe shall prove this assuming $\\operatorname{X_1}=\\sigma^2<\\infty$.\r\n\\begin{proof}\r\n    We have $\\mathbb E[S_n/n]=\\mu$ and $\\operatorname{Var}(S_n/n)=\\sigma^2/n$, then by Chebyshev's Inequality,\r\n    $$\\mathbb P\\left(\\left|\\frac{S_n}{n}-\\mu\\right|>\\epsilon\\right)\\le\\frac{\\operatorname{Var}(S_n/n)}{\\epsilon^2}=\\frac{\\sigma^2}{\\epsilon^2n}\\to 0$$\r\n    As $n\\to\\infty$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A sequence $(X_n)$ converges to $X$ in probability, written as\r\n    $$X_n\\xrightarrow{\\mathbb P}X,n\\to\\infty$$\r\n    if $\\forall\\epsilon>0,\\mathbb P(|X_n-X|>\\epsilon)\\to 0$ as $n\\to\\infty$.\r\n\\end{definition}\r\nSo the weak law of large numbers says that $S_n/n\\xrightarrow{\\mathbb P}\\mu$ as $n\\to\\infty$.\r\n\\begin{definition}\r\n    $(X_n)$ converges to $X$ with probability $1$ (or ``almost surely'', a.s.) if\r\n    $$\\mathbb P\\left(\\lim_{n\\to\\infty}X_n=X\\right)=1$$\r\n\\end{definition}\r\n\\begin{theorem}[Strong Law of Large Numbers]\r\n    Let the setting be as before, then\r\n    $$\\mathbb P\\left(\\lim_{n\\to\\infty}\\frac{S_n}{n}\\to\\mu\\right)=1$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Assume further that the $4^{th}$ moment is finite.\r\n    BY considering $Y_i=X_i-\\mu$, WLOG $\\mu=0$.\r\n    We have\r\n    $$S_n^4=\\left( \\sum_{i=1}^nX_i \\right)^4=\\sum_{i=1}^nX_i^4+6\\sum_{1\\le i<j\\le n}X_i^2X_j^2+R$$\r\n    where $R$ is a sum of terms of the form $X_i^3X_j,X_i^2X_jX_k,X_iX_jX_kX_l$ for $i,j,k,l$ all distinct.\r\n    Since $X_i$ are independent with zero mean, $\\mathbb E[R]=0$, so\r\n    \\begin{align*}\r\n        \\mathbb E[S_n^4]&=n\\mathbb E[X_1^4]+3n(n-1)\\mathbb E[X_1^2]^2\\\\\r\n        &\\le (n+3n(n-1))\\mathbb E[X_1^4]\\\\\r\n        &\\le 3n^2\\mathbb E[X_1^4]\r\n    \\end{align*}\r\n    Hence\r\n    $$\\mathbb E\\left[ \\sum_{n=1}^\\infty\\left( \\frac{S_n}{n} \\right)^4 \\right]=\\sum_{n=1}^\\infty\\mathbb E\\left[ \\left( \\frac{S_n}{n} \\right)^4 \\right]\\le 3\\mathbb E[X_1^4]\\sum_{n=1}^\\infty\\frac{1}{n^2}<\\infty$$\r\n    So\r\n    $$\\mathbb P\\left(\\sum_{n=1}^\\infty\\left( \\frac{S_n}{n} \\right)^4<\\infty\\right)=1\\implies\\mathbb P\\left(\\lim_{n\\to\\infty}\\frac{S_n}{n}=0\\right)=1$$\r\n    as claimed.\r\n\\end{proof}\r\nAs the name suggests, he strong law of large numbers implies the weak law of large numbers.\r\n\\begin{proposition}\r\n    Suppose $X_n\\to\\mu$ almost surely, then $X_n\\xrightarrow{\\mathbb P}\\mu$\r\n\\end{proposition}\r\nBy shifting, it suffices to consider the case where $\\mu=0$.\r\n\\begin{proof}\r\n    Assuming $X_n\\to 0$ almost surely, then we have\r\n    $$\\mathbb P(|X_n|\\le\\epsilon)\\ge\\mathbb P\\left( \\bigcap_{m=n}^\\infty\\{|X_m|\\le\\epsilon\\} \\right)$$\r\n    write the event in the right hand side as $A_n$, then $A_n\\subset A_{n+1}$ and $\\bigcup_nA_n$ is the event that $|X_m|\\le\\epsilon$ for any sufficiently large $m$.\r\n    So\r\n    $$\\lim_{n\\to\\infty}\\mathbb P(|X_n|\\le\\epsilon)\\ge\\mathbb P\\left( \\bigcup_{n\\in\\mathbb N}A_n \\right)\\ge\\mathbb P(X_n\\to 0)=1$$\r\n    So $\\mathbb P(|X_n|<\\epsilon)=0$.\r\n\\end{proof}\r\n\\subsection{Central Limit Theorem}\r\nWe saw $S_n/n-\\mu\\to 0$ a.s. from the law of large numbers.\r\nWe know also that $\\operatorname{Var}(S_n/n)=\\sigma^2/n$ where $\\sigma^2$ is the variance of $X_1$.\r\nSo if we want to normalize,\r\n$$\\frac{S_n/n-\\mu}{\\sqrt{\\operatorname{Var}(S_n/n)}}=\\frac{S_n-n\\mu}{\\sigma\\sqrt{n}}$$\r\nfrom which we will expect\r\n\\begin{theorem}[Central Limit Theorem]\r\n    Let $(X_n:n\\in\\mathbb N)$ be a sequence of i.i.d. random variables with mean $\\mu$ and variance $\\sigma^2$, then set $S_n=X_1+\\cdots+X_n$ as before, we have\r\n    $$\\mathbb P\\left( \\frac{S_n-n\\mu}{\\sigma\\sqrt{n}}\\le x \\right)\\to\\Phi(x)=\\int_{-\\infty}^x\\frac{e^{-y^2/2}}{\\sqrt{2\\pi}}\\,\\mathrm dy$$\r\n    for all $x\\in\\mathbb R$.\r\n\\end{theorem}\r\nIn other words, $(S_n-n\\mu)/(\\sigma\\sqrt{n})\\to\\mathcal N(0,1)$ in distribution.\r\nWhat this means is that for $n$ large enough, $S_n\\approx n\\mu+\\sigma\\sqrt{n}\\mathcal N(0,1)=\\mathcal N(\\mu n,\\sigma^2n)$.\r\nIn fact, not only does it converge, we can also estimate the rate of convergence, which is sadly beyond the course.\r\n\\begin{proof}\r\n    WLOG $\\mu=0,\\sigma=1$ by considering $(X_i-\\mu)/\\sigma$.\r\n    Assume further that $\\exists\\delta>0,\\mathbb E[e^{\\pm\\delta X_1}]<\\infty$.\r\n    By continuity of MGFs, it suffices to show that, for $Z\\sim\\mathcal N(0,1)$,\r\n    $$\\mathbb E[e^{\\theta S_n/\\sqrt{n}}]\\to\\mathbb E[e^{\\theta Z}]=e^{\\theta^2/2}$$\r\n    So if let $m$ be the MGF of $X_1$,\r\n    $$\\mathbb E[e^{\\theta S_n/\\sqrt{n}}]=\\mathbb E[e^{\\theta X_n/\\sqrt{n}}]^n=m(\\theta/\\sqrt{n})^n$$\r\n    Note that when $|\\theta|<\\delta/2$,\r\n    $$m(\\theta)=\\mathbb E\\left[ \\sum_{n=0}^\\infty\\frac{1}{n!}\\theta^nX_1^n \\right]=1+\\frac{\\theta^2}{2}+\\mathbb E\\left[  \\sum_{n=3}^\\infty\\frac{1}{n!}\\theta^nX_1^n \\right]$$\r\n    We will prove that the last term is $o(\\theta^2)$ as $\\theta\\to 0$, which immediately implies the result.\\\\\r\n    We have\r\n    \\begin{align*}\r\n        \\sum_{n=3}^\\infty\\frac{1}{n!}|\\theta|^n|X_1|^n&=|\\theta X_1|^3\\sum_{k=0}^\\infty\\frac{|\\theta X_1|^k}{(k+3)!}\\\\\r\n        &\\le|\\theta X_1|^3e^{\\delta|X_1|/2}\\\\\r\n        &\\le 3!\\left( \\frac{2\\theta}{\\delta} \\right)^3e^{\\delta|X_1|}\r\n    \\end{align*}\r\n    Now by Jensen's Inequality\r\n    \\begin{align*}\r\n        \\left|\\mathbb E\\left[  \\sum_{n=3}^\\infty\\frac{1}{n!}\\theta^nX_1^n \\right]\\right|&\\le\\mathbb E\\left[ \\sum_{n=3}^\\infty\\frac{1}{n!}|\\theta|^n|X_1|^n \\right]\\\\\r\n        &\\le 3!\\left( \\frac{2\\theta}{\\delta} \\right)^3\\mathbb E[e^{\\delta|X_1|}]\\\\\r\n        &\\le 3!\\left( \\frac{2\\theta}{\\delta} \\right)^3(\\mathbb E[e^{\\delta|X_1|}]+\\mathbb E[e^{-\\delta X_1}])\\\\\r\n        &=o(|\\theta|^2)\r\n    \\end{align*}\r\n    As desired.\r\n\\end{proof}\r\nThere are few important application of central limit theorem.\r\n\\begin{example}\r\n    1. Let $(X_n)$ be i.i.d. $\\operatorname{Bern}(p)$ and hence $S_n\\sim\\operatorname{Bin}(n,p)$.\r\n    Recall that $\\mathbb E[S_n]=np$ and $\\operatorname{Var}(S_n)=np(1-p)$, so\r\n    $$\\frac{S_n-np}{\\sqrt{np(1-p)}}\\to\\mathcal N(0,1)$$\r\n    in distribution.\r\n    So for $n$ large, $S_n\\approx\\mathcal N(np,np(1-p))$ for $n$ large.\r\n    In the Poisson approximation of the binomial, we scaled $p$ to $\\lambda/n$, while in this approximation, we kept $p$ constant.\\\\\r\n    2. We now want $S_n\\sim\\operatorname{Pois}(n)$, and to accomplish this we can write $S_n=X_1+\\cdots+X_n$ where $(X_n)$ are i.i.d. $\\operatorname{Pois}(1)$.\r\n    So $(S_n-n)/\\sqrt{n}\\approx \\mathcal N(0,1)$.\r\n\\end{example}\r\n\\subsection{Sampling Error by Central Limit Theorem}\r\nA proportion $p$ of the population votes ``yes'' and $1-p$ votes ``no'' in a referendum.\r\nWe want to estimate $p$ with error at most $\\pm 4\\%$ in probability at least $0.99$.\r\nWe pick $N$ individuals at random.\r\nLet $S_N$ be the number of people who voted ``yes'', so we want to estimate $p$ by $\\hat{p}_N=S_N/N$, so what we want is\r\n$$\\mathbb P(|\\hat{p}_N-p|\\le 4\\%)\\ge 0.99$$\r\nNow $S_N\\sim\\operatorname{Bin}(N,p)$, so by previous,\r\n$$\\hat{p}_N=\\frac{S_N}{N}\\approx p+\\sqrt{\\frac{p(1-p)}{N}}Z,Z\\sim\\mathcal N(0,1)$$\r\nfor $N$ large.\r\nSo what we want is\r\n$$\\mathbb P\\left( \\sqrt{\\frac{p(1-p)}{N}}|Z|\\le 4\\% \\right)\\ge 0.99$$\r\nNow $\\mathbb P(Z\\ge z)=2(1-\\Phi(z))$, then $\\mathbb P(|Z|\\ge 2.58)=0.01$.\r\nSo in the worse case where $p=1/2$ gives $N\\ge 1040$.", "meta": {"hexsha": "afbe120439a04e22387b769182342f6dd065c67e", "size": 7465, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "13/limit.tex", "max_stars_repo_name": "david-bai-notes/IA-Probability", "max_stars_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "13/limit.tex", "max_issues_repo_name": "david-bai-notes/IA-Probability", "max_issues_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "13/limit.tex", "max_forks_repo_name": "david-bai-notes/IA-Probability", "max_forks_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.1885245902, "max_line_length": 210, "alphanum_fraction": 0.6283991962, "num_tokens": 2916, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245828938678, "lm_q2_score": 0.8757870029950159, "lm_q1q2_score": 0.7298148389746921}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\section{Lecture 16}\n\\subsection{Lecture Notes - Focault Pendulum}\n\\subsubsection{Rotating Coordinate System EOM}\n\\[\n\\begin{array}{c}\n\\left(\\frac{d \\v{Q}}{d t}\\right)_{S_{0}}=\\left(\\frac{d \\v{Q}}{d t}\\right)_{S}+\\vec{\\omega} \\times \\v{Q} \\\\\nm \\ddot{\\v{r}}=\\vec{F}+2 m \\dot{\\v{r}} \\times \\v{\\Omega}+m(\\v{\\Omega} \\times \\v{r}) \\times \\v{\\Omega}+m \\v{r} \\times \\dot{\\vec{\\Omega}}=\\v{F}+\\v{F}_{\\text {coriolis }}+\\v{F}_{\\text {centrifugal }}+\\v{F}_{\\text {Euler }}\n\\end{array}\n\\]\n\n\\subsubsection{Review Questions}\nA bead rests on a wire that extends from the origin at an angle $\\theta$ to the vertical. The wire rotates with angular velocity $\\Omega$ about the vertical. In the frame rotating with the wire, what is the magnitude and direction of the centrifugal force when the bead is a distance $r$ from the origin?\n\\begin{s}\nBy trigonometry, the bead is $r\\sin\\theta$ away from the rotation axis, so there is a centrifugal force of $m\\Omega^2r\\sin\\theta$ away from the rotation axis.\n\\end{s}\n\nA bucket of water spins about its central axis. After a relaxation time, the shape of the water surface reaches a steady state. Where is the water surface highest?\n\\begin{s}\nAt the edge of the bucket, as the centrifugal force pulls the water towards the edge. The surface of the water is a parabola.\n\\end{s}\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-16/l16-img1.png}\n\\end{center}\nA puck slides from the center towards the edge of a frictionless, rotating merry-go-round. The merry-go-round has angular velocity $\\Omega$ and rotates CCW when viewed from above. In the rotating frame, the initial velocity is in the positive $y$ direction. What effect does the Coriolis force have on the velocity of the puck?\n\\begin{s}\nThe coriolis force changes the direction of the velocity (deflected left) but does not change the magnitude (we can see from the $\\v{v} \\times \\v{\\Omega}$ form that the force does no work).\n\\end{s}\n\nConsider the same scenario as the previous question. How many rotations does the merry-go-round make before the puck slides off of the edge?\n\n\\begin{s}\n$\\# \\text{rotations} = \\frac{a\\Omega}{2\\pi v}$. First consider that the time to reach the edge is simply the distance $a$ (radius) divided by the velocity $v$ of the puck. Then, we may divide this time by the time per rotation (the period), which is $T = \\frac{2\\pi}{\\Omega}$. This yields:\n\\[\\# \\text{rotations} = \\frac{\\Delta t}{T} = \\frac{a\\Omega}{2\\pi v}\\]\n\\end{s}\n\nAt which of these points will a person's measured weight be the largest (equator, 30, 40, 60 degrees latitude, or north pole)\n\\begin{s}\nAt the north pole; there we have no centrifugal force there (which acts against the gravitational force and decreases the weight of the person). \n\\end{s}\n\nIn the northern hemisphere, which directions are winds from the north and south deflected by the Coriolis force?\n\\begin{s}\nWinds from the N are deflected E and winds from the S are deflected W.\n\\end{s}\n\nWhere are these low pressure areas?\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-16/l16-img2.png}\n\\end{center}\n\\begin{s}\nThe left image rotates clockwise, the right one rotates counterclockwise. For a low pressure system, we have air coming in, and in the northern hemisphere, we have right deflection (and vise versa for the southern hemisphere) so we would expect a counterclockwise motion for the northern hemisphere and clockwise for the southern hemisphere.\n\\end{s}\n\n\\subsubsection{The Foucault Pendulum}\nWe start with our general expression:\n\\[m\\ddot{\\v{r}} = \\v{F} + 2m\\dot{\\v{r}}\\times \\v{\\Omega} + m(\\v{\\Omega} \\times \\v{r})\\times \\v{\\Omega} + m\\v{r}\\times \\dot{\\v{\\Omega}}\\]\nThe third term can be neglected as the Earth spins at a constant rate, and the second term can be neglected as $\\Omega$ is small. Define $x$ to be north south, $y$ to be east west. $\\v{F}$ is the sum of the tension and the gravitational force, that is:\n\\[\\v{F} = \\v{T} + m\\v{g}\\]\nNow we consider the given picture:\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-16/l16-img4.png}\n\\end{center}\nBy similar triangles:\n\\[T_x = -T\\frac{x}{L}\\]\n\\[T_y = -T\\frac{y}{L}\\]\n\\[T_z = -T\\frac{z-L}{L}\\]\nBut for the $T_z$, we can consider that we do small amplitudes, so $z \\approx 0$, and $\\dot{z} \\approx 0$. Hence, $T_z \\approx T \\approx mg$. Hence, we have dealt with the tension. Now, we think about $\\v{\\Omega}$.\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-16/l16-img3.png}\n\\end{center}\nIf our latitude is $\\lambda$ and we use coordinates such that $x$ points towards the equator, $y$ points parallel to the latitude line, and $z$ points away from the center of the earth, what is the rotation vector in this coordinate system?\n\\begin{s}\nWe know that $\\v{\\Omega}_{earth}$ points straight upwards. Projecting this, we get:\n\\[\\v{\\Omega} = \\omega\\m{-\\cos\\lambda \\\\ 0 \\\\ \\sin\\lambda}\\]\n\\end{s}\nNext, what is $\\v{\\Omega} \\times \\v{v}$?\n\\begin{s}\nUsing that $\\v{v} = \\m{\\dot{x} \\\\ \\dot{y} \\\\ 0}$ (Assume $\\dot{z}$ is negligible) and $\\v{\\Omega}$ from above, we get:\n\\[\\v{\\Omega} \\times \\v{v} = \\m{-\\dot{y}\\Omega \\sin\\lambda \\\\ \\dot{x}\\Omega\\sin\\lambda \\\\ -\\dot{y}\\Omega\\cos\\lambda}\\]\n\\end{s}\nNow, putting together the equations of motion for $x$ and $y$ we get:\n\\[m\\ddot{x} = -mg\\frac{x}{L} + 2m\\Omega\\sin\\lambda \\dot{y}\\]\n\\[m\\ddot{y} = -mg\\frac{y}{L} - 2m\\Omega\\sin\\lambda\\dot{x}\\]\nWe have a system of coupled equations. As a trick, multiply both equations by $i$ and add them together, and define $s = x + iy$. We then have:\n\\[\\ddot{s} + 2i\\alpha \\dot{s} + k^2\\dot{s} = 0\\]\nWhere $\\alpha = \\Omega\\sin\\lambda$, $k^2 = \\frac{g}{L}$. To solve this differential equation, we guess $s(t) = c\\exp(\\gamma t)$. This yields a characteristic equation:\n\\[\\gamma^2 + 2i\\alpha\\gamma + k^2 = 0\\]\nSolving this, we get:\n\\[\\gamma_{1/2} = -i\\alpha \\pm i\\sqrt{\\alpha^2 + k^2}\\]\nThe general solution is the sum of these two:\n\\[s(t) = C_1\\exp(\\gamma_1 t) + C_2\\exp(\\gamma_2 t)\\]\nWe assume initial conditions of $s(0) = \\xhat, \\dot{s}(0) = 0$ (elongation along $x$, with no initial velocity). We may then solve for the coefficients $C_1, C_2$ (homework!). Then, taking the real part of the complex solution, we get the final result:\n\\[\\m{x(t) \\\\ y(t)} = \\m{\\cos(\\alpha t) & \\sin(\\alpha t) \\\\ -\\sin(\\alpha t) & \\cos(\\alpha t)}\\m{\\xhat \\cos(\\sqrt{\\alpha^2 + k^2} t) \\\\ \\xhat\\frac{\\sin(\\sqrt{\\alpha^2 + k^2}t)\\alpha }{\\sqrt{\\alpha^2 + k^2}}}\\]\nQuestion: We have this result. What is the effect of multiplying through by this matrix? \n\\begin{s}\nWe recognize this just as a rotation matrix, rotating by a time dependent angle $\\Omega_zt = \\alpha t$.\n\\end{s}\nThis is a characteristic feature of the Focault pendulum, indeed that it precesses. \n\\end{document}", "meta": {"hexsha": "bfe83599ca40fe1b8580e77d752459bd62a58ae8", "size": 6732, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-16/Lecture-Notes-16.tex", "max_stars_repo_name": "RioWeil/PHYS306-notes", "max_stars_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture-16/Lecture-Notes-16.tex", "max_issues_repo_name": "RioWeil/PHYS306-notes", "max_issues_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture-16/Lecture-Notes-16.tex", "max_forks_repo_name": "RioWeil/PHYS306-notes", "max_forks_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.0, "max_line_length": 341, "alphanum_fraction": 0.7015745692, "num_tokens": 2111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245911726382, "lm_q2_score": 0.8757869867849166, "lm_q1q2_score": 0.7298148327168573}}
{"text": "\\section{Algorithms}\n\\label{title}\nAlgorithsm are a process or rules to follow. They should:\n\\begin{itemize}\n\t\\item take an input, give an output. For example \\ldots \n\t\\item be deterministic, i.e. for the same input the output will always be the same, cf functional programming  \n\t\\item and finite, cf computability. \n\\end{itemize}\n\nThey could be recursive, then they need a base case and recursive step. Typically the recursive step makes the problem smaller, converging on the base case. \n\nAn algorithm could:\n\\begin{itemize}\n\t\\item involve \\textbf{heuristics}, finding decent solutions quickly, but not sure to be optimal \n\t\\item be greedy, so exploit strong local solutions, with no regard to the bigger picture, e.g. hill-climbing \n\t\\item ad-hoc, an impromptu strategy, unique to a particular problem, hard to generalise.  \n\\end{itemize}\n\n\\subsection{Flowcharts}\n\nShapes\n\n\\subsection{Orders of Growth}\n\nOrder of growth - worst case, proportional to some function of the input size \n\nComparison is done in extreme cases, e.g. n log n vs n2 \n\nOffline vs online problems \n\nBubble sort, then shuttle \nQuick sort \n\nPacking : next fit, first fit, first fit decreasing, full bin \n\nBin Packing - as a decision problem - is NP Complete \n\nKnapsack problem  - portfolio management, \n\n", "meta": {"hexsha": "eedd721204b0d076f71e07ca4a82e3a77eed9c5f", "size": 1278, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "dm5-algorithms-content.tex", "max_stars_repo_name": "st-pauls-school/discrete-mathematics", "max_stars_repo_head_hexsha": "5b979a11b1161b0612cf964d93363c5896dce39e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dm5-algorithms-content.tex", "max_issues_repo_name": "st-pauls-school/discrete-mathematics", "max_issues_repo_head_hexsha": "5b979a11b1161b0612cf964d93363c5896dce39e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dm5-algorithms-content.tex", "max_forks_repo_name": "st-pauls-school/discrete-mathematics", "max_forks_repo_head_hexsha": "5b979a11b1161b0612cf964d93363c5896dce39e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.95, "max_line_length": 157, "alphanum_fraction": 0.7636932707, "num_tokens": 315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7298148295534201}}
{"text": "\n\\chapter[Nonlinear equations]{Nonlinear equations}\n\n\\section{Introduction}\n\nVery few nonlinear equations can be solved analytically.  For example,\nit is easy to solve the  equation $x^2+2 x  + 1=0$: the left hand side\nis   $(x+1)^2$ and  therefore there  is   a  single  root $x=-1$  with\nmultiplicity two.  There are other equations whose  solution is not so\neasily found, like, for example,\n%\n\\begin{equation*}\n e^x + x = 2 .\n\\end{equation*}\n%\nFrom the graph of this equation it is clear that there is one and only\none solution.  However, there is no formula to obtain its exact value.\nThe   purpose of  numerical   methods  for  the solution of  nonlinear\nequations is to  fill in this gap: to  give approximate, but accurate,\nsolutions of nonlinear equations that cannot be solved analytically.\n\nIn this unit we give an introduction to this area of numerical\nanalysis by discussing some simple algorithms.  It should be made\nclear that the algorithms currently used in commercial packages and in\nresearch laboratories are far more advanced than anything that we will\ndiscuss.  However, they are based on the same ideas and differ mainly\nin details of the implementation and in using various tricks to\nguarantee a fast and global convergence.\n\nWe will  focus   our attention  mainly  on  the solution  of  a single\nnonlinear equation in one variable.  However, the methods that we will\ndiscuss can be extended to systems of nonlinear equations in more than\none  variable: we will discuss  briefly how to do this  at  the end of\nthis chapter.\n\nIn all that follows we assume that we have to solve the nonlinear\nequation $f(x) = 0$, where $x$ is a real number and $f(x)$ is a real\ndifferentiable function.\n\n\\section{A simple example: The bisection method}\n\nThe bisection method is by far the simplest method and, even though it\nis not used very much in practice, it is sturdy and reliable.\nMoreover, we can use it to introduce some general comments on the\npractical implementation of root finding algorithms.\n\nVery briefly, the method assumes that by suitable inspired guesses two\npoints $x_0^{(L)}$ and $x_0^{(R)}$ have been chosen such that\n%\n\\begin{equation}\n  f(x_0^{(L)}) f(x_0^{(R)}) \\le 0 ,\n  \\label{eq:14}\n\\end{equation}\n%\ni.e.\\ the function $f(x)$ changes sign in the interval $[x_0^{(L)},\nx_0^{(R)}]$.   If the product is zero then one of the two factors is\nzero and the problem is solved.   We therefore assume that the\ninequality in~(\\ref{eq:14}) is strict.   Since the\nfunction $f(x)$ is continuous, by the intermediate value theorem there\nexists a point $s \\in (x_0^{(L)},x_0^{(R)})$ such that $f(s)=0$,\ni.e.\\ $s$ is a root of the equation $f(x)=0$.  The idea behind this\nmethod is that the mid point between $x_0^{(L)}$ and $x_0^{(R)}$,\n$x_0^{(M)}$, is an approximation of the root $s$.  If a more accurate\nestimate is needed we can refine the approximation by checking in\nwhich half interval $(x_0^{(L)},x_0^{(M)})$ or $(x_0^{(M)},x_0^{(R)})$\nthe function $f(x)$ changes sign.  We then discard the other\nhalf-interval and repeat the procedure.\n\nMore formally, the iteration procedure involves first constructing a\nnew point, the centre of the interval and estimate of the root,\n%\n\\begin{equation*}\n  x_n^{(M)} = \\frac{x_n^{(L)} + x_n^{(R)}}{2} , \\quad\n  n = 0,1,2, \\ldots\n\\end{equation*}\n%\nand evaluating $f(x_n^{(M)})$.    If this estimate of the root is not\nsufficiently accurate a new set of left and right points are chosen\naccording to the sign of $f(x_n^{(M)})$:\n%\n\\begin{align}\n  \\begin{cases}\n    x_{n+1}^{(L)} & = x_n^{(L)}, \\\\ x_{n+1}^{(R)} & = x_n^{(M)}\n  \\end{cases}\n  \\hspace{7mm} \\text{if $f(x_n^{(L)}) f(x_n^{(M)}) < 0$} ,\n  \\label{bisp} \\\\*[5mm]\n  \\begin{cases}\n    x_{n+1}^{(L)} &= x_n^{(M)}, \\\\ x_{n+1}^{(R)} & = x_n^{(R)}\n  \\end{cases}\n  \\hspace{7mm} \\text{if $f(x_n^{(L)}) f(x_n^{(M)}) > 0$} . \\label{bisn}\n\\end{align}\n%\nThe procedure is repeated until a stopping condition is reached.\nThere are three conditions that must be checked by any iteration\nprocedure: if any of them is satisfied the iteration must stop.\n%\n\\begin{enumerate}\n%\n\\item The number of iterations has exceeded a predetermined value:\n  this is used to avoid cases where the convergence is exceedingly\n  slow or, for any reason, the algorithm is going in an infinite loop.\n%\n\\item The absolute value of the function at the estimated root,\n  $f(x_n^{(M)})$ is smaller than a predetermined number $\\varepsilon$\n  (usually fixed by the number of significant digits of the floating\n  point representation).\n%\n\\item The difference between two successive values of the estimated\n  root (or the difference between $x_n^{(R)}$ and $x_n^{(L)}$ in the\n  case of the bisection method) is smaller that a predetermined number\n  $\\delta$, the requested accuracy of the roots.\n%\n\\end{enumerate}\n%\nFigure~\\ref{bisec_stop} shows two pathological cases where one of the\nlast two criteria is satisfied, but not the other.  In the left hand\ncase there is a multiple root (a bane of root finding algorithms): the\nvalue of the function is very small, but the the left and right hand\npoint are not close.  For many numerical methods the speed of\nconvergence is proportional to the slope of $f(x)$ at its root.\nTherefore their convergence is extremely slow at multiple roots where\n$f(x)$ is flat.  This is not the case of the bisection method because\nits rate of convergence is independent of the slope of the function.\nHowever, if the value of the function is very close to zero then\nnumerical errors may introduce spurious zeros and force the algorithm\nto converge to a spurious root.\n\nIn the right hand case the bisection interval is very small so that\n$\\abs{x^{(R)} - x^{(L)}} < \\delta$ but the function is not small.  While\nit is true that in this case the function is not continuous, it is\nalso true that it may not be easy to determine whether the function\nwhose zeros we wish to compute is continuous and so we must make a\nroot finding algorithm capable of handling cases as pathological as\nthese examples.\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=120mm]{figures/bisec_stop}}\n  \\caption{\\label{bisec_stop} \\it In the left hand case the criterion\n    $\\abs{x_n^{(R)}-x_n^{(L)}} < \\delta$ fails, in the right hand case the\n    criterion $\\abs{f(x_n^{(M)})} < \\varepsilon$ fails.}\n\\end{figure}\n\n\\noindent\n\\textbf{Remark 1} - The error in the location of the root at the\n$n$-th step is smaller than $(x_0^{(R)}-x_0^{(L)})/2^n$.\n\n\\noindent\n\\textbf{Remark 2} - This method is easy to code and it\nalways converges.   However, it is rather slow.\n\n\\section{Contraction mappings}\n\n\\subsection{Introduction}\n\nMany of the methods that we will discuss for solving nonlinear\nequations like\n%\n\\begin{equation}\n  f(x)=0 \\label{nonlin}\n\\end{equation}\n%\nare \\textit{iterative} and can be written in the form\n%\n\\begin{equation}\n  x_{n+1} = g(x_n), \\label{picard}\n\\end{equation}\n%\nfor some suitable function $g(x)$ and initial approximation $x_0$.\nThe aim of the method is to find a suitable function $g(x)$ such that\nthe sequence has a limit and that the limit is a root of $f(x)$:\n%\n\\begin{equation*}\n  \\lim_{n \\to \\infty} x_n = s \\quad \\text{and} \\quad f(s)=0.\n\\end{equation*}\n%\nNote that if the limit exists then it is also a fixed point of the map\n$g(x)$:\n%\n\\begin{equation*}\n  s = \\lim_{n \\to \\infty} x_{n+1} =\n  \\lim_{n \\to \\infty} g(x_n) =\n  g \\left ( \\lim_{n \\to \\infty} x_n \\right ) = g(s) .\n\\end{equation*}\n%\nFor example, in the case of the nonlinear problem $f(x) = 0$ we can\ndefine the function $g(x)$ to be\n%\n\\begin{equation*}\n  g(x) = x - f(x)\n\\end{equation*}\n%\nand use the mapping~(\\ref{picard}) to attempt finding the roots of\n$f(x)$.  Methods of this kind are called \\textit{functional iterations\n  methods} or \\textit{fixed point methods}.\n\nGraphically, the solutions of~(\\ref{nonlin}) or the fixed points\nof~(\\ref{picard}) are the intersections between the graph of $g(x)$\nand the line $y=x$ (see Figure~\\ref{fig:picard}).  The iteration of\nthe map~(\\ref{picard}) can be represented on the same graph (see\nFigure~\\ref{fig:picard}): in the case of the solid line path the\nmethod is converging to the fixed point, while for the dashed line\npath the method is diverging.\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=100mm]{figures/picard}}\n  \\caption{\\label{fig:picard} \\it Graphical representation of the\n    functional iteration.  The straight line paths are the graphical\n    representation of the mapping~(\\ref{picard}).}\n\\end{figure}\n\nThere are some general theorems that state under what condition the\nmapping~(\\ref{picard}) converges.   Before studying them, however, it\nis worthwhile to make some general remarks.\n\n\\begin{itemize}\n%\n\\item Usually iterative methods are valid for real and complex roots.\n  However, in the latter case complex arithmetic must be incorporated\n  into the appropriate computer codes and the initial estimate of the\n  root must usually be complex.\n%\n\\item The iterative methods require at least one initial estimate or\n  guess at the location of the root being sought. If this initial\n  estimate is ``sufficiently close'' to a root, then, in general, the\n  procedure will converge.  The problem of how to obtain such a\n  ``good'' estimate is unsolved in general.\n%\n\\item As a general empirical rule, the schemes which converge more\n  rapidly (i.e.\\ higher order methods) require closer estimates.  In\n  practice, these higher order schemes may require the use of more\n  significant digits in order that they converge as theoretically\n  predicted.  Thus, it is frequently a good idea to use a simple\n  method to start with and then, when fairly close to the root, to use\n  some higher order method for just a few iterations.\n%\n\\end{itemize}\n\n\\subsection{Geometrical interpretation of fixed point schemes}\n\nBefore discussing formally what properties a map must have in order\nfor the iteration scheme~(\\ref{picard}) to converge, we can obtain an\napproximate idea by considering the four maps in\nFigure~\\ref{fig:contract_examples}.    From the top two maps it is\nclear that in order to have a fixed point we must require $g(x)$ to be\ncontinuous (top left) and, moreover, that the range is contained in\nthe domain (top right).    These requirements are not enough to have a\nunique fixed point as it is shown in the bottom left corner: if the\nslope of the map is too high there may be two or more fixed points.\nIt is only if the slope is smaller than unity that there can be only\none fixed point (bottom right corner).   Note than we do not require\nthat map to be differentiable: it can have as many corners as it wish.\nThe case of the two bottom maps is illustrated pictorially in\nFigure~\\ref{fig:contraction}: at each iteration the image of\nthe starting set $I$ gets smaller and smaller until it reduces to a\npoint (see Figure~\\ref{fig:contraction}).\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=90mm]{figures/contract_examples}}\n  \\caption{\\label{fig:contract_examples} \\it Examples of maps and\n    their convergence properties.}\n\\end{figure}\n\n\\subsection{Definitions}\n\nWe must now phrase these intuitive results in more formal terms.   We\nstart by defining a contracting map.\n\n\\noindent\n\\textbf{Definition} - A continuous map $g(x)$ from an interval\n$I=[a,b] \\subseteq \\bR$ into $\\bR$ is \\textit{contracting} if\n%\n\\begin{enumerate}\n  %\n\\item the image of $I$ is contained in $I$:\n  %\n  \\begin{equation*}\n    g(I) \\subseteq I \\quad \\Leftrightarrow \\quad\n    g(x) \\in I \\, \\forall x \\in I .\n  \\end{equation*}\n  %\n\\item the function $g(x)$ is Lipschitz continuous in $I$ with\n  Lipschitz constant $L < 1$:\n  %\n  \\begin{equation*}\n    \\abs{ g(x) - g(y) } \\le L \\abs{ x - y } \\quad \\forall x,y \\in I .\n  \\end{equation*}\n  %\n  In other words, the distance between the images is smaller than the\n  distance between the two starting points.\n  %\n\\end{enumerate}\n\n\\noindent\n\\textbf{Remark 1} - A function that is Lipschitz continuous is\n``more'' than continuous, but ``less'' than differentiable.  For\nexample, the function $f_1(x)=\\sqrt{x}$ is continuous in the interval\n$[0,1]$, but it is not Lipschitz.  On the other hand, the function\n$f_2(x)=\\abs{x}$ is Lipschitz in the interval $[-1,1]$, but it is not\ndifferentiable at $x=0$.\n\n\\noindent\n\\textbf{Remark 2} - If the function $g(x)$ is differentiable and\nLipschitz continuous with constant $L$ then\n%\n\\begin{equation*}\n   \\abs{\\dv{g}{x}}  \\le L.\n\\end{equation*}\n\n\\subsection{Convergence theorems}\n\nA map that is contracting is also called a \\textit{contraction\nmapping}.  From the definition and Figures~\\ref{fig:contract_examples}\nand~\\ref{fig:contraction} we can intuitively understand that if\nthe map $g(x)$ in~(\\ref{picard}) is contracting, then we are\nguaranteed convergence.  All this is expressed more\nformally (and more clearly) in the following sets of theorems.\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=90mm]{figures/contraction_col}}\n  \\caption{\\label{fig:contraction} \\it Graphical representation of the\n    contraction mapping principle.  At each iteration the image of the\n    interval gets smaller and the iterations of the contraction map\n    converge towards its fixed point(s).}\n\\end{figure}\n\nFirst of all, we prove that if the image of  the interval is contained\nin the interval (without any requirement of Lipschitz continuity) then\nthere is at least one fixed point (but there may be many).\n\n\\smallskip\n\n\\begin{theorem}\n\\label{contract1}\nIf the function $g(x)$ is continuous in $I=[a,b]$ and $g(I) \\subseteq\nI$, then $g(x)$ has at least one fixed point in $I$.\n\\end{theorem}\n\n\\noindent\n\\textbf{Proof} - Since $g(I) \\subseteq I$ we must have\n%\n\\begin{equation*}\n   a \\le g(a) \\le b \\quad \\text{and} \\quad a \\le g(b) \\le b .\n\\end{equation*}\n%\nIf either $g(a)=a$ or $g(b)=b$ then there is one fixed point and the\ntheorem is proved.   Otherwise, the following inequalities must hold:\n%\n\\begin{equation*}\n  g(a) - a \\ge 0 \\quad \\text{and} \\quad g(b) - b \\le 0 .\n\\end{equation*}\n%\nDefine the function $F(x) = g(x) - x$.   $F(x)$ is continuous and\n$F(a) \\ge 0$, while $F(b) \\le 0$.   Therefore, by the intermediate\nvalue theorem there exists a point $c \\in [a,b]$ such that\n%\n\\begin{equation*}\n  F(c)=0 \\implies c = g(c) .\n\\end{equation*}\n\n\\hfill \\rule{3mm}{3mm}\n\n\\smallskip\n\n\\noindent\n\\textbf{Exercise} - Give a graphical representation of this theorem.\nIn particular show that the contraction map that would produce a graph\nsimilar to the bottom part of Figure~\\ref{fig:contraction} must have a\njump discontinuity in $[a,b]$.\n\n\\smallskip\n\nTheorem~\\ref{contract1} provides us with an important result, but not\nwith enough.  Ideally we would like the zero to be unique.  In order\nfor this to be true, we must have more stringent requirements on\n$g(x)$: it must not vary too rapidly.  This is assured if $g(x)$ is\nLipschitz continuous with a sufficiently small Lipschitz constant.\n\n\\begin{theorem}[Contraction mapping theorem]\n\\label{contract2}\nIf $g(x)$ is a contraction mapping in an interval\n$I=[a,b]$ then there exists one and only one fixed point of the map in\n$[a,b]$.\n\\end{theorem}\n\nWe will prove a slightly less strong version of this theorem: we\nrequire that the map $g(x)$ is differentiable in $I$ and that $\\abs{g'(x)}\n\\le L < 1$.   Such a function is Lipschitz continuous of Lipschitz\nconstant $L$: therefore it is a contraction mapping.\n\n\\begin{theorem}\n\\label{contract3}\nIf $g(x)$ is a differentiable contraction mapping\nin an interval $I=[a,b]$, i.e.\n%\n\\begin{equation*}\n  \\abs{g'(x)} \\le L < 1, \\qquad \\forall x \\in [a,b] ,\n\\end{equation*}\n%\nthen there exists one and only one fixed point of the map in $[a,b]$.\n\\end{theorem}\n\n\\noindent\n\\textbf{Proof} - The existence of the derivative implies that the\nfunction $g(x)$ is continuous.  Since, by hypothesis $g(I) \\subseteq\nI$, then by Theorem~\\ref{contract1} there is at least one fixed point,\n$s_1$.  Suppose that there is another one $s_2 : s_2 = g(s_2)$ and\n$s_1 \\ne s_2$.  We can use the mean value\ntheorem\\footnote{\\textbf{Mean value theorem} - For any differentiable\n$F(x)$ in $I \\subseteq \\bR$ and any $c, d \\in I$ there exists a point\n$\\xi \\in [c,d]$ such that\n%\n\\begin{equation*}\n  F'(\\xi) = \\frac{F(d)-F(c)}{d-c} .\n\\end{equation*}\n}\nto prove that this is impossible:\n%\n\\begin{equation*}\n  \\abs{s_2 - s_1} = \\abs{g(s_2) - g(s_1)} =\n  \\abs{g'(\\xi) (s_2 - s_1)}  \\le L \\abs{s_2 - s_1} < \\abs{|s_2 - s_1} .\n\\end{equation*}\n%\nThis inequality cannot be true and therefore there can be no other\nfixed point. (The proof assuming Lipschitz continuity only is\nessentially identical.) \\hfill \\rule{3mm}{3mm}\n\n\\smallskip\n\nThe consequence of this theorem is that the algorithm represented by\nthe mapping~(\\ref{picard}) is guaranteed to have a root in an interval\n$[a,b]$ if the map is a contraction mapping in this interval.  The\nfollowing theorem tells us how to find it.\n\n\\smallskip\n\n\\begin{theorem}\n\\label{contract4}\nLet $I=[a,b]$ and suppose that $g(x)$ is a contraction mapping in $I$.\nThen for arbitrary $x_0 \\in I$, the sequence $x_n = g(x_{n-1})$,\n$n=1,2,\\ldots$ converges to the unique fixed point, $s$, of the map.\nMoreover, if the error $e_n$ at the $n$-th stage is defined by $e_n =\nx_n - s$ then\n%\n\\begin{equation*}\n  \\abs{e_n} \\le \\frac{L^n}{1-L} \\abs{ x_1 - x_0 } .\n\\end{equation*}\n\\end{theorem}\n\n\\noindent\n\\textbf{Proof} - To prove the convergence to the fixed point, whatever\nthe arbitrary guess $x_0 \\in I$, we use the Lipschitz property of the\nmap and the fact that $s=g(s$) to bound $\\abs{e_n}$ from above\nwith a bound that tends to zero as $n$ tends to infinity.  As a first step\nwe have:\n%\n\\begin{align}\n  \\abs{e_n} & = \\abs{ x_n - s} \\\\\n  & = \\abs{ g(x_{n-1}) - g(s) } \\\\\n  & \\le L \\abs{ x_{n-1} - s } \\\\\n  & = L \\abs{ e_{n-1} } .\n\\end{align}\n%\nBy applying this inequality over and over again we obtain\n%\n\\begin{align}\n  \\abs{ e_n } & \\le L \\abs{ e_{n-1} } \\\\\n  & \\le L^2 \\abs{ e_{n-2} } \\\\\n  & \\le \\ldots \\\\\n  & \\le L^n \\abs{ e_0 } \\label{ineq_conv}\n\\end{align}\n%\nBy the definition of contraction mapping $L < 1$ and therefore\n%\n\\begin{equation*}\n  \\lim_{n \\to \\infty} L^n = 0 \\implies \\lim_{n \\to \\infty} x_n = s .\n\\end{equation*}\n%\nEquation~(\\ref{ineq_conv}) provides a bound on the error of the $n$-th\nestimate in terms of the initial error.   Unfortunately this quantity\nis not know, because we do not know the root $s$ of the equation.   We\ntherefore must replace $\\abs{e_0}$ in~(\\ref{ineq_conv}) with an expression\nthat we can compute, namely $\\abs{x_0 - x_1}$:\n%\n\\begin{align}\n  &&  \\abs{ x_0 - s } & = \\abs{ x_0 - x_1 + x_1 - s } \\\\\n  &&  & \\le \\abs{ x_0 - x_1 } + \\abs{ x_1  - s} \\\\\n  &&  & \\le \\abs{ x_0 - x_1 } + L \\abs{ x_0 - s } \\\\\n  \\implies && \\abs{e_0} & = \\abs{ x_0 - s } \\\\\n  && & \\le \\frac{\\abs{ x_0 - x_1 }}{1-L}.\n\\end{align}\n%\nUsing~(\\ref{ineq_conv}) we obtain\n%\n\\begin{equation}\n  \\abs{ e_n } \\le L^n \\abs{ e_0 } \\le \\frac{L^n}{1-L} \\abs{ x_0 - x_1 } .\n  \\label{err_boundL}\n\\end{equation}\n\\hfill \\rule{3mm}{3mm}\n\nThese four theorems are represented graphically in\nFigure~\\ref{fig:contract}.  Since the slope of the function $g(x)$ is\nsmaller than unity successive iterations of the map get closer and\ncloser to its fixed point.\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=80mm]{figures/contract}}\n  \\caption{\\label{fig:contract} \\it Graphical representation of the\n    contracting mapping theorems.  The map $g(x)$ is a contraction\n    mapping in $[a,b]$: the image of the interval is smaller than the\n    original interval.  Each iteration of a starting guess $x_0$ gets\n    closer and closer to the fixed point.}\n\\end{figure}\n\n\\subsection{Speed of convergence}\n\nThe bound~(\\ref{err_boundL}) on the error provided by\nTheorem~\\ref{contract4} depends, through the Lipschitz constant $L$,\non the interval chosen to estimate the map.  Moreover, it is\nreasonable to assume that the rate of convergence of the map, i.e.\\ the\nrate of decrease of the error $e_n$ depends only on the properties of\nthe map in a neighbourhood of the root.  We can show that this is\nindeed the case if the map is differentiable, so that it is possible\nto expand it in a Taylor polynomial: call $g(x)$ a suitably\ndifferentiable contraction mapping in $I=[a,b]$, $s$ its fixed point,\n$x_0 \\in I$ the starting point of the iteration and $e_n = x_n - s$\nthe error at the $n$-th iteration.  Using the definition of the map\nand Taylor's expansion we can write:\n%\n\\begin{align*}\n  e_{n+1} & = x_{n+1} - s \\\\\n          & = g(x_n) - g(s) \\\\\n          & = g'(s)(x_n-s) + \\frac{g''(s)}{2!}(x_n-s)^2 + \\ldots +\n          \\frac{g^{(k)}(s)}{k!}(x_n-s)^k + R_{n,k} \\\\\n          & = g'(s) e_n + \\frac{g''(s)}{2!} e_n^2 + \\ldots +\n          \\frac{g^{(k)}(s)}{k!} e_n^k + R_{n,k} ,\n\\end{align*}\n%\nwhere $R_{n,k}$ is the remainder of the expansion:\n%\n\\begin{equation*}\n  R_{n,k} = \\frac{g^{(k)}(\\xi)}{k!}(x_n-s)^{k+1}, \\quad\n  \\xi \\in [x_n,s].\n\\end{equation*}\n%\nAssuming that $g'(s) \\ne 0$ then\n%\n\\begin{equation*}\n  e_{n+1} \\sim g'(s) e_n,\n\\end{equation*}\n%\ni.e.\\ the error decreases at a constant rate at each iteration: such a\nmethod is called \\textit{linear} or \\textit{first order}.  If,\ninstead, $g'(s)=0$, but $g''(s) \\ne 0$ then\n%\n\\begin{equation*}\n  e_{n+1} \\sim g''(s) e_n^2,\n\\end{equation*}\n%\ni.e.\\ the error at each iteration is proportional to the square of the\nprevious error: such a method is called a \\textit{quadratic} or\n\\textit{second order} method.  The more derivatives of $g(s)$ vanish\nthe higher the order of the method and the faster the convergence.\nHowever, it may well be that the method will converge only if the\nstarting point is very close to the root.\n\n\\subsection{Error propagation}\n\nThe final question that we must answer before discussing practical\nimplementations of the theory we have just studied is ``Are these\ntheorems numerically stable?''  In other words, what is the effect of\nthe numerical error on the convergence properties of a contraction\nmap?  In actual computations it may not be possible, or practical, to\nevaluate the function $g(x)$ exactly (i.e.\\ only a finite number of\ndecimals may be retained after rounding or $g(x)$ may be given as the\nnumerical solution of a differential equation, etc.).  For any value\nof $x$ we may then represent our approximation to $g(x)$ by $G(x) =\ng(x) + \\delta(x)$ where $\\delta(x)$ is the error committed in\nevaluating $g(x)$.  Frequently we may know a bound for $\\delta(x)$,\ni.e.\\ $\\delta(x) < \\delta$.  Thus the actual iteration scheme which is\nused may be represented as\n%\n\\begin{equation}\n  X_{n+1} \\equiv G(X_n) = g(X_n) + \\delta_n, \\quad\n  n = 0,1,2, \\ldots, \\label{Xn}\n\\end{equation}\n%\nwhere the $X_n$ are the numbers obtained from the calculations and the\n$\\delta_n \\equiv \\delta(X_n)$ satisfy\n%\n\\begin{equation}\n  \\abs{\\delta_n} \\le \\delta, \\quad n= 0,1,2, \\ldots \\label{deltabound}\n\\end{equation}\n%\nWe cannot expect the computed iterates $X_n$ of~(\\ref{Xn}) to\nconverge.   However, under proper conditions, it should be possible to\napproximate a root to an accuracy determined essentially by the\naccuracy of the computations, $\\delta$.\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=120mm]{figures/contract_error}}\n  \\caption{\\label{fig:contract_error} \\it The width of the numerical\n    error band around the fixed point of the iteration map.}\n\\end{figure}\n\nFor example, from Figure~\\ref{fig:contract_error} we can see that for\nthe special case of $g(x) = \\alpha + L (x-\\alpha)$, the uncertainty in\nthe root $\\alpha$ is bounded by $\\pm \\delta/(1 - L)$.  We note that if\nthe slope $L$ is close to unity the problem is not ``properly posed''.\nThe following theorem states quite generally that when the functional\niteration scheme is convergent, the presence of errors in computing\n$g(x)$, of magnitudes bounded by $\\delta$, causes the scheme to\nestimate the root $\\alpha$ with an uncertainty bounded by $\\pm\n\\delta/(1-L)$, where $L$ is the Lipschitz constant of the contraction\nmapping.  The phrasing of this theorem is slightly different from the\nprevious ones because the numerical error $\\delta$ forces us to define\nquite strictly the interval we want to work in: we know that $g(I)\n\\subseteq I$, but it is not generally true that $G(I) \\subseteq I$.\n\n\\begin{theorem}\n\\label{contract5}\nLet $g(x)$ be a contraction mapping with fixed point $s$ and let $L$\nbe its Lipschitz constant in the interval $I(s,r_0) \\equiv\n[s-r_0,s+r_0]$.  Let $\\delta$ be the bound on the numerical errors of\nthe iterates of the numerical map~(\\ref{Xn}) as defined\nin~(\\ref{deltabound}).  Finally, assume that the starting point of the\niteration of~(\\ref{Xn}) is a point $X_0$ in the smaller interval\n%\n\\begin{equation}\n  X_0 \\in I(s,R_0) \\equiv [s - R_0, s + R_0] ,  \\label{X0}\n\\end{equation}\n%\nwhere\n%\n\\begin{equation*}\n  0 < R_0 \\le r_0 - \\frac{\\delta}{1-L} .\n\\end{equation*}\n%\nThen the iterates $X_n$ of~(\\ref{Xn}) with the errors bounded\nby~(\\ref{deltabound}), lie in the interval $I(s,r_0)$,\nand\n%\n\\begin{equation}\n  \\abs{ s - X_n } \\le\n  \\frac{\\delta}{1 - L} +\n  L^n \\left ( R_0 - \\frac{\\delta}{1-L} \\right ), \\label{bound_err}\n\\end{equation}\n%\nwhere $L^n \\to 0$ as $n \\to \\infty$.\n\\end{theorem}\n\n\\noindent\n\\textbf{Proof} - The proof of this theorem involves showing that the\nnumerical error does not push the iteration outside the interval\n$I(s,r_0)$ where it is defined.  In the process of doing so we also\nderive the bound~(\\ref{bound_err}) on the error of the numerical\nestimate.  The proof that the iterations are always in the interval\n$I(s,r_0)$ is by induction.\n\nThe point $X_0$ is, by hypothesis, inside the interval $I(s,R_0)\n\\subseteq I(s,r_0)$.  We now suppose that the iterations $X_0, X_1,\n\\ldots, X_{n-1}$ are in $I(s,r_0)$ and proceed to show that also $X_n\n\\in I(s,r_0)$.  By~(\\ref{Xn}) and~(\\ref{deltabound}) we have\n%\n\\begin{equation*}\n  \\abs{ s - X_n } \\le\n    \\abs{ [g(s) - g(X_{n-1}) ] - \\delta_{n-1}  } \\le\n  \\abs{ [g(s) - g(X_{n-1}) ]  } + \\delta .\n\\end{equation*}\n%\nSince $g(x)$ is a contraction mapping of Lipschitz constant $L$  we\ncan write\n%\n\\begin{align*}\n  \\abs{ s - X_n } & \\le L \\abs{ s - X_{n-1} } + \\delta \\\\\n  & \\le L^2 \\abs{ s - X_{n-2} } + L \\delta + \\delta \\\\\n  & \\le L^n \\abs{ s - X_0} + ( L^{n-1} + \\ldots 1 ) \\delta \\\\\n  & =  L^n \\abs{ s - X_0} + \\frac{1-L^n}{1-L} \\delta .\n\\end{align*}\n%\nHypothesis~(\\ref{X0}) implies that $\\abs{s - X_0} \\le R_0$ so that\n%\n\\begin{align}\n  \\abs{ s - X_n } & \\le L^n R_0 + \\frac{1-L^n}{1-L} \\delta  \\label{be1} \\\\\n  & = L^n R_0 + \\frac{\\delta}{1-L} - L^n \\frac{\\delta}{1-L} \\nonumber \\\\\n  & \\le R_0  + \\frac{\\delta}{1-L} \\nonumber \\\\\n  & \\le r_0. \\nonumber\n\\end{align}\nThus all the iterates are in the interval $I(s,r_0)$ and the iteration\nprocess is defined.   Moreover~(\\ref{be1}) can be rewritten\nas~(\\ref{bound_err}), thus completing the proof. \\hfill \\rule{3mm}{3mm}\n\n\\smallskip\n\n\\noindent\n\\textbf{Remark} - Theorem~\\ref{contract5} shows that the method is\n``as convergent as possible'', that is, the computational errors which\narise from the evaluation of $g(x)$ may cumulatively produce an error\nof magnitude at most $\\delta/(1-L)$.  Moreover, such errors limit the\nsize of the error bound \\textit{independently of the number of\niterations}.  Therefore, it is pointless to iterate the map until $L^n\nr_0 \\ll \\delta/(1-L)$.\n\n\\section{Examples of iteration procedures}\n\n\\subsection{Introduction}\n\nWe  have completed the  theoretical  introduction to the\nnumerical solution of nonlinear  equations.  We must now discuss  some\nof the  algorithms  that apply  the   theory that  we have  developed.\n\n\\subsection{The chord method (first order)}\n\nThe chord method and Newton's methods are examples of the application\nof the contraction mapping theorems.  Both these methods can be\nintroduced using a general and elegant framework.  As usual we suppose\nthat we have to solve the nonlinear equation\n%\n\\begin{equation*}\n  f(x) = 0,\n\\end{equation*}\n%\nin some interval $a \\le x \\le b$.  To define the different methods to\nsolve this problem we introduce a function $\\varphi(x)$ such that\n%\n\\begin{equation}\n  0 < \\varphi(x) < \\infty, \\quad x \\in [a,b] ,\n \\label{phibound}\n\\end{equation}\n%\nand we use it to construct a contraction mapping $x_{n+1} =\ng(x_n)$, where\n%\n\\begin{equation}\n  g(x) = x - \\varphi(x) f(x).   \\label{gphi}\n\\end{equation}\n%\nThe fixed points of the map $g(x)$ are the roots of the function\n$f(x)$.\n\n\\smallskip\n\nThe simplest choice for $\\varphi(x)$ in~(\\ref{gphi}) is to take\n%\n\\begin{align}\n  && \\varphi(x) & \\equiv m \\ne 0, \\\\\n  \\implies && g(x) & = x - m f(x) \\\\\n  \\implies && x_{n+1} & = x_n - m f(x_n)\n  \\label{phichord}\n\\end{align}\n%\nwhere $m$ is a number that we must choose appropriately in order for\n$g(x)$ to be a contraction mapping in $[a,b]$.   The range of $m$\ndepends on the slope of $f(x)$ in the interval $[a,b]$.   From\nTheorem~\\ref{contract3} we know that $g(x)$ is a contraction mapping if\n%\n\\begin{align}\n  & &  \\abs{ g'(x) } & < 1 &  \\forall x &\\in [a,b] \\nonumber\n  \\\\\n  \\implies &&\n  \\abs{ 1 - m f'(x) } & < 1 & \\forall x &\\in [a,b] \\nonumber\n  \\\\\n  \\implies && 0 < m f'(x) & < 2 & \\forall x &\\in [a,b] . \\label{ineq_chord}\n\\end{align}\n%\nThus $m$ must have the same sign as $f'(x)$, while if $f'(x)=0$ the\ninequality cannot be satisfied.\n\nThe iterates of~(\\ref{phichord}) have a geometrical realisation in\nwhich the value $x_{n+1}$ is the $x$ intercept of the line with slope\n$1/m$ through $(x_n,f(x_n))$ (see Figure~\\ref{fig:chord}).   The\ninequality~(\\ref{ineq_chord}) implies that this slope should be\nbetween $\\infty$ (i.e.\\ vertical) and $f'(x)/2$ (i.e.\\ half the slope of\nthe tangent to the curve $y=f(x)$).   It is from this geometric\ndescription that the name chord method is derived - the next iterate\nis determined by a chord of constant slope joining a point on the\ncurve to the $x$-axis.\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=60mm]{figures/chord}}\n  \\caption{\\label{fig:chord} \\it Geometrical representation of the\n    chord method: each new iterate is determined by a chord of\n    constant slope joining a point on the curve to the $x$-axis.}\n\\end{figure}\n\n\\medskip\n\n\\subsection{Newton's method (second order)}\n\nThe idea behind Newton's method is to chose the function $\\varphi(x)$\nin order that the derivative of the iteration mapping $g(x)$ is zero\nat the root $x=s$.  This is ensured by the choice\n%\n\\begin{equation}\n  \\varphi(x) = \\frac{1}{f'(x)} \\implies\n  g(x) = x - \\frac{f(x)}{f'(x)} , \\label{gnewt}\n\\end{equation}\n%\nso that the iteration procedure is\n%\n\\begin{equation}\n  x_{n+1} = x_n - \\frac{f(x_n)}{f'(x_n)} .\n  \\label{Newton}\n\\end{equation}\n%\nThis root finding algorithm is called Newton's method.\nTheorem~\\ref{contract3} guarantees that the method converges in an\ninterval $[a,b]$ containing the root provided that $\\abs{g'(x)} < 1$ in\nthe interval.  It is at least second order at the root $s$ of the\nequation $f(x) = 0$, if $f'(s) \\ne 0$ and $f''(x)$ exists, since\n%\n\\begin{equation}\n  g'(s) = \\frac{f(s) f''(s)}{[f'(s)]^2} = 0 .\n  \\label{gpalpha}\n\\end{equation}\n%\nThe geometrical interpretation of this scheme simply replaces the\nchord in Figure~\\ref{fig:chord} by the tangent to the line to $y=f(x)$\nat $x_n,f(x_{n+1})$ (see Figure~\\ref{fig:Newton}).\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=80mm]{figures/Newton}}\n  \\caption{\\label{fig:Newton} \\it Geometrical representation of\n    Newton's method: each new iterate is intersection of the tangent\n    to the graph of $f(x)$ with the $x$-axis.}\n\\end{figure}\n\n\\noindent\n\\textbf{Remark 1} - It should be noted that Newton's method may be\nundefined and the condition~(\\ref{phibound}) violated if $f'(x)=0$ for\nsome $x \\in [a,b]$.  In particular, if at the root $x=s$, $f'(s) = 0$,\nthe procedure may no longer be of second order since the hypotheses\nthat lead to~(\\ref{gpalpha}) are not satisfied.  To examine this case\nwe assume that $f(x)$ has a root of multiplicity $p$ at $x=s$.  In\nother words we can write,\n%\n\\begin{equation*}\n  f(x) = (x-s)^p h(x), \\quad p > 1 ,\n\\end{equation*}\n%\nwhere the function $h(x)$ has a second derivative and $h(s) \\ne 0$.\nIf we substitute this expression in the definition of $g(x)$\nin~(\\ref{gnewt}) we find that\n%\n\\begin{equation*}\n  \\abs{g'(s)} = 1 - \\frac{1}{p} .\n\\end{equation*}\n%\nSo only in the case of a linear root, i.e.\\ $p=1$ is Newton's method\nsecond order, but it will converge as a first order method in the\ngeneral case $p \\ne 1$.\n\n\\noindent\n\\textbf{Remark 2} - Convergence is quadratic only if we are close to\nthe root $s$.\n\n\\noindent\n\\textbf{Remark 3} - The advantage of Newton's method with respect to\nthe bisection (and chord) method is the faster convergence.  The main\ndisadvantage with respect to the bisection method is that we need to\nstart relatively close to the root in order to be sure that the method\nwill converge.\n\n\\subsection{Secant method (fractional order)}\n\nNewton's method requires the evaluation of the derivative of the\nfunction $f(x)$ whose root we want to find.  To do this may be very\ncomplicated and time consuming: the secant method obviates this\nproblem by approximating the derivative of $f'(x)$ with the quotient\n%\n\\begin{equation}\n  f'(x_n) \\simeq\n  \\frac{f \\left (x_n \\right ) - f \\left ( x_{n-1} \\right )}\n  {x_n - x_{n-1}} .\n  \\label{approx_der}\n\\end{equation}\n%\nThis approximation comes directly from the definition of the derivative\nof $f(x)$ as the limit\n%\n\\begin{equation*}\n  f'(x) = \\lim_{u \\to x} \\frac{f(u)-f(x)}{u-x} .\n\\end{equation*}\n%\nSubstituting~(\\ref{approx_der}) into the algorithm~(\\ref{Newton}) for\nNewton's method we obtain the secant method, namely:\n%\n\\begin{equation}\n  x_{n+1} = x_n -\n  f(x_n) \\frac{x_n - x_{n-1}}{f(x_n) - f (x_{n-1})} .\n  \\label{secant}\n\\end{equation}\n%\nThe graphical interpretation of the secant method is similar to that\nof Newton's method.  The tangent line to the curve is replaced by the\nsecant line (see Figure~\\ref{fig:secant}).\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=90mm]{figures/secant}}\n  \\caption{\\label{fig:secant} \\it Geometrical representation of the\n    secant method: each new iterate is intersection of the secant to\n    the graph of $f(x)$ with the $x$-axis.}\n\\end{figure}\n\n\\noindent\n\\textbf{Remark 1} - This method requires two initial guesses:\n$x_0$ and $x_1$.\n\n\\noindent\n\\textbf{Remark 2} - The convergence of the secant method cannot be\nanalysed using the contraction mapping theorems that we have studied\nbecause the method cannot be put in the form $x_{n+1} = g(x_n)$: each\nnew iterate is a function of the previous \\textbf{two}: $x_{n+1} =\ng(x_n, x_{n-1})$.\n\n\\noindent\n\\textbf{Remark 3} - It is possible to show that the\nerror in the approximation decreases asymptotically as\n%\n\\begin{equation*}\n  \\abs{e_{n+1}} \\sim \\abs{e_n}^{(1+\\sqrt{5})/2} .\n\\end{equation*}\n%\nSince $(1+\\sqrt{5})/2 \\simeq 1.62$ the secant method is a super-linear\n(i.e.\\ faster than linear), but slower than quadratic convergence.\nThis would suggests that the secant method is slower than Newton's\nmethod in reaching a given accuracy.  However, Newton's method\nrequires two function evaluations per iteration step, while the secant\nmethod requires only one.  Therefore, when comparing the execution\nspeed of the two methods we should/could compare \\textit{two} steps of\nthe secant methods with one step of Newton's method.  The rate of\ndecrease of the error in two steps of the secant method is $1.62^2\n\\simeq 2.6$ which is better than the convergence rate of Newton's\nmethod.\n\n\\section{Systems of nonlinear equations}\n\n\\subsection{Introduction}\n\nFinding the solutions of a systems of nonlinear equations,\n%\n\\begin{equation*}\n  \\begin{cases}\n    f_1(x_1, x_2, \\ldots, x_n) = 0 , \\\\\n    f_2(x_1, x_2, \\ldots, x_n) = 0 , \\\\\n    \\vdots \\\\\n    f_n(x_1, x_2, \\ldots, x_n) = 0 ,\n  \\end{cases}\n \\quad \\Leftrightarrow \\quad\n \\bff(\\bx) = 0 ,\n\\end{equation*}\n%\nis considerably more difficult that solving a single nonlinear\nequation or solving a system of linear equations:\n\n\\begin{enumerate}\n  %\n\\item The system may have \\textit{no solution}, like for example\n  %\n  \\begin{align*}\n    \\left\\{\n      \\begin{aligned}\n        x_1^2 + 2 x_1 x_2 + x_2^2 & = 3, \\\\\n        x_1^3 + 3 x_1^2 x_2 + 3 x_1 x_2^2 + x_2^3 & = 4,\n      \\end{aligned}\n    \\right. &  \\Longleftrightarrow \\left\\{\n      \\begin{aligned}\n        (x_1 + x_2)^2 & = 3, \\\\\n        (x_1 + x_2)^3 & = 4,\n      \\end{aligned}\n    \\right. \\\\\n  \\intertext{or have \\textit{no real solutions}, like for example,}\n    \\left\\{\n      \\begin{aligned}\n        x_1^2 + x_2^2 & = -5, \\\\\n        x_1^2 - 3 \\, x_2^2 & = 11,\n      \\end{aligned}\n    \\right. &  \\Longleftrightarrow \\left\\{\n      \\begin{aligned}\n        x_1 & = \\pm \\tj , \\\\\n        x_2 & = \\pm 2 \\tj ,\n      \\end{aligned}\n    \\right. \\\\\n  \\intertext{or have a \\textit{unique solution}}\n    \\left\\{\n      \\begin{aligned}\n        x_1^2 + x_2^2 & = 0, \\\\\n        \\cos(x_1 x_2) & = 1,\n      \\end{aligned}\n    \\right. &  \\Longleftrightarrow \\left\\{\n      \\begin{aligned}\n        x_1 = 0 , \\\\\n        x_2 = 0 ,\n      \\end{aligned}\n    \\right. \\\\\n  \\intertext{or have \\textit{many solutions}}\n    \\left\\{\n      \\begin{aligned}\n        x_1^2 + x_2^2 & = 1, \\\\\n        \\cos[\\pi(x_1^2 + x_2^2)] + x_1^2 + x_2^2 & = 0,\n      \\end{aligned}\n    \\right. &  \\Longleftrightarrow\n    \\parbox{50mm}{all $x_1$ and $x_2$ that belong to the circle $x_1^2 +\n      x_2^2 = 1$.}\n  \\end{align*}\n  %\n\\item If the system is large, even the existence of a solution is\n  quite unclear.\n  %\n\\item For many real world problems the methods used to find the\n  solutions can be rather ad hoc.\n  %\n\\end{enumerate}\n\n\\subsection{Contraction mapping}\n\nOne can extend to more than one dimension the theorems on contraction\nmapping that have been discussed so far.  The contraction map is now a\nset of $n$ nonlinear functions in $n$ variables,\n%\n\\begin{equation*}\n  \\bx_{n+1} = \\bg(\\bx_n) .\n\\end{equation*}\n%\nEssentially everything carries over by replacing scalars with vectors\nand absolute values with norms.\n\nWe define an \\textit{interval} in $\\bRn$ as a set $I = \\{ \\bx \\in \\bRn\n| \\, a_j < x_j < b_j, \\, j=1,2,\\ldots, n \\}$ where $a_j$ and $b_j$ are\ngiven constants.  A \\textit{contraction map} in $\\bRn$ is defined as:\n\n\\noindent\n\\textbf{Definition} - A continuous map $\\bg(\\bx)$ from an interval\n$I \\subseteq \\bRn$ into $\\bRn$ is \\textit{contracting} if\n%\n\\begin{enumerate}\n  %\n\\item the image of $I$ is contained in $I$:\n  %\n  \\begin{equation*}\n    \\bg(I) \\subseteq I \\quad \\Leftrightarrow \\quad\n    \\bg(x) \\in I \\quad \\forall \\bx \\in I .\n  \\end{equation*}\n  %\n\\item the function $\\bg(\\bx)$ is Lipschitz continuous in $I$ with\n  Lipschitz constant $L < 1$:\n  %\n  \\begin{equation*}\n    \\norm{ \\bg(\\bx) - \\bg(\\by) } \\le L \\norm{ \\bx - \\by } \\quad\n    \\forall \\bx,\\by \\in I .\n  \\end{equation*}\n%\n\\end{enumerate}\n\nThe convergence theorems are modified as follows:\n\n\\smallskip\n\n\\begin{theorem}\n\\label{contract1Rn}\nIf the function $\\bg(\\bx)$ is continuous in $I \\subseteq \\bRn$ and\n$\\bg(I) \\subseteq I$, then $\\bg(\\bx)$ has at least one fixed point in\n$I$.\n\\end{theorem}\n\n\\begin{theorem}[Contraction mapping theorem in $\\bRn$]\n\\label{contract2Rn}\nIf $\\bg(\\bx)$ is a contraction mapping in an interval $I \\subseteq\n\\bRn$ then there exists one and only one fixed point of the map in\n$I$.\n\\end{theorem}\n\n\\begin{theorem}\n\\label{contract3Rn}\nIf $\\bg(\\bx)$ is a differentiable contraction mapping\nin an interval $I \\subseteq \\bRn$, i.e.\n%\n\\begin{equation*}\n  \\abs{\\pdv{g_i}{x_j}} \\le \\frac{L}{n}, \\quad\n  \\forall \\bx \\in I, \\quad \\forall i,j \\quad L < 1 ,\n\\end{equation*}\n%\nthen there exists one and only one fixed point of the map in $I$.\n\\end{theorem}\n\n\\noindent\n\\textbf{Remark} - The condition on the derivative can be relaxed\nsomewhat.   For example the theorem holds if $\\norm{J(\\bx)}_\\infty \\le\nL$, where $J(\\bx)$ is the Jacobian matrix of the map $\\bg(\\bx)$.\n\n\\smallskip\n\n\\begin{theorem}\n\\label{contract4Rn}\nLet $I \\subseteq \\bRn$ be an interval in $\\bRn$ and suppose that\n$\\bg(\\bx)$ is a contraction mapping in $I$ with Lipschitz constant $L\n< 1$..  Then for arbitrary $\\bx_0 \\in I$, the sequence $\\bx_n =\n\\bg(\\bx_{n-1})$, $n=1,2,\\ldots$ converges to the unique fixed point,\n$\\bs$, of the map.  Moreover, if the error $\\be_n$ at the $n$-th stage\nis defined by $\\be_n = \\bx_n - \\bs$ then\n%\n\\begin{equation*}\n  \\norm{ \\be_n }_\\infty \\le \\frac{L^n}{1-L} \\norm{ \\bx_1 - \\bx_0 }_\\infty .\n\\end{equation*}\n%\n\\end{theorem}\n\n\\smallskip\n\n\\noindent\n\\textbf{Exercise} - Show that\n%\n\\begin{equation}\n  \\label{eq:contRnex}\n  \\bg(\\bx) = \\left\\{\n    \\begin{aligned}\n      g_1(x_1,x_2,x_3) & = \\dfrac{1}{3} \\cos(x_2 x_3) + \\dfrac{1}{6} , \\\\\n      g_2(x_1,x_2,x_3) & =\n      \\dfrac{1}{9} \\sqrt{x_1^2 + \\sin(x_3) + 1.06} - 0.1, \\\\\n      g_3(x_1,x_2,x_3) & =\n      -\\dfrac{1}{20} e^{-x_1 x_2} - \\left ( \\dfrac{10 \\pi -3}{60} \\right ),\n    \\end{aligned}\n    \\right.\n\\end{equation}\n%\nsatisfies all the conditions of theorem~\\ref{contract3Rn} in $-1 < x_i <\n1$.\n\n\\smallskip\n\n\\noindent\n\\textbf{Remark 1} - In practice it may be rather tough to prove that\n$g(I) \\subseteq I$.\n\n\\noindent\n\\textbf{Remark 2} - There is a ``Gauss-Seidel'' version of this\nmethod, where each iterate is used as soon as it becomes available.\n\n\\noindent\n\\textbf{Remark 3} - The analogy with linear systems extends to the\nS.O.R. method.  It is often hard to get the direct iteration to\nconverge.  However, the convergence can be helped by using\n``relaxation'' (the opposite of S.O.R.).  This method introduces an\n``under-relaxation'' parameter $\\omega < 1$ in the iteration.\nAssuming that we know the iterate $\\bx_n$ we compute a first estimate\nof the iterate $n+1$, $\\hat \\bx_{n+1}$ using the iteration map\n$\\bg(\\bx)$:\n%\n\\begin{equation*}\n  \\hat \\bx_{n+1} = \\bg(\\bx_n) .\n\\end{equation*}\n%\nUse this estimate to obtain $\\bx_{n+1}$ according to\n%\n\\begin{equation*}\n  \\bx_{n+1} = \\bx_n + \\omega ( \\hat \\bx_{n+1} - \\bx_n ) .\n\\end{equation*}\n%\nThis procedure effectively multiplies the derivatives of the map\n$\\bg(\\bx)$ by $\\omega < 1$.  If $\\omega = 1$ this procedure reduces to\nthe standard contraction mapping.\n\nThe drawback of this method is that sometimes $\\omega$ has to be made\nso small that convergence is slow and too many iterations are needed.\n\n\n\\subsection{Newton's method}\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=150mm]{figures/Newt2}}\n  \\caption{\\label{fig:Newt2} \\it Geometrical meaning of Newton's\n    method to solve a system of two nonlinear equations in two\n    variables.  The solutions of the system are the intersections of\n    the two surfaces with the $xy$-plane.}\n\\end{figure}\n\nIn discussing Newton's method we shall use only $2 \\times 2$ systems,\nbut most of what we say generalises immediately to $n \\times n$\nsystems.   The model problem that we wish to solve is\n%\n\\begin{equation*}\n  \\begin{cases}\n    f_1(x,y) = 0, \\\\ f_2(x,y) = 0 ,\n  \\end{cases}\n  \\quad \\Longleftrightarrow \\quad\n  \\bff(\\bx) = 0 .\n\\end{equation*}\n%\nThe easiest way to obtain an expression for Newton's method in two\ndimensions is based on the its geometrical interpretation.   We start\nby recapping the one dimension case: suppose that we wish to solve the\nequation $f(x) = 0$ and that we have evaluated the function at $x_n$.\nThe next iterate, $x_{n+1}$ is the intersection of the straight line\ntangent to the graph of $f(x)$ at $(x_n, f(x_n))$ with the $x$ axis.\nThe equation of this line is given by the first two terms of the\nTaylor expansion of the function $f(x)$ around $x_n$:\n%\n\\begin{equation*}\n  y = f(x_n) + f'(x_n) (x - x_n) .\n\\end{equation*}\n%\nIt intersects the $x$ axis at the point $x_{n+1}$ such that $y=0$, i.e.\n%\n\\begin{equation*}\n  0 = f(x_n) + f'(x_n) (x_{n+1} - x_n) \\implies\n  x_{n+1} =  x_n - \\frac{f(x_n)}{f'(x_n)} .\n\\end{equation*}\n%\nThe geometrical interpretation of Newton's method in two dimensions is\nthat the iterate $(x_{n+1},y_{n+1})$ is the common point where\nthe planes tangent to the graph of $f_1(x,y)$ and $f_2(x,y)$ at\n$(x_n,y_n)$ intersect the $xy$-plane, i.e.\\ the plane $z=0$ (see\nFigure~\\ref{fig:Newt2}).  The plane tangent to the two surfaces are\n%\n\\begin{align*}\n  z &= f_1(x_n,y_n) + (x - x_n) \\pdv{f_1}{x}(x_n,y_n) +\n  (y - y_n) \\pdv{f_1}{y}(x_n,y_n) , \\\\\n  z &= f_2(x_n,y_n) + (x - x_n) \\pdv{f_2}{x}(x_n,y_n) +\n           (y - y_n) \\pdv{f_2}{y}(x_n,y_n) .\n\\end{align*}\n%\nAt the intersection with the $xy$-plane we have $z=0$.\nTherefore the equations for the next iterate are\n%\n\\begin{align}\n  f_1(x_n,y_n) + (x_{n+1} - x_n) \\pdv{f_1}{x}(x_n,y_n) +\n  (y_{n+1} - y_n) \\pdv{f_1}{y}(x_n,y_n) &= 0 ,\n  \\label{eq:f1} \\\\\n  f_2(x_n,y_n) + (x_{n+1} - x_n) \\pdv{f_2}{x}(x_n,y_n) +\n  (y_{n+1} - y_n) \\pdv{f_2}{y}(x_n,y_n) &= 0 .\n  \\label{eq:f2}\n\\end{align}\n%\nWe introduce the Jacobian of the function $\\bff(\\bx)$ at $(x_n,y_n)$,\n%\n\\begin{equation*}\n  J(x_n,y_n) =\n  \\begin{pmatrix}\n    \\partial_x f_1(x_n,y_n) & \\partial_y f_1(x_n,y_n) \\\\\n    \\partial_x f_2(x_n,y_n) & \\partial_y f_2(x_n,y_n)\n  \\end{pmatrix}\n\\end{equation*}\n%\nand write~(\\ref{eq:f1}) and~(\\ref{eq:f2}) in matrix notation as\n%\n\\begin{equation*}\n  J(x_n,y_n)\n  \\begin{pmatrix}\n    x_{n+1} - x_n \\\\ y_{n+1} - y_n\n  \\end{pmatrix}\n  =\n  \\begin{pmatrix}\n    - f_1(x_n,y_n) \\\\ - f_2(x_n,y_n)\n  \\end{pmatrix}\n  ,\n\\end{equation*}\n%\nso that the next iterate of Newton's method is\n%\n\\begin{equation}\n  \\begin{pmatrix}\n    x_{n+1} \\\\ y_{n+1}\n  \\end{pmatrix}\n =\n \\begin{pmatrix}\n   x_n \\\\ y_n\n \\end{pmatrix}\n - J^{-1}\n \\begin{pmatrix}\n   -f_1(x_n,y_n) \\\\ -f_2(x_n,y_n)\n \\end{pmatrix}\n . \\label{Newtontwo}\n\\end{equation}\n%\nEquation~(\\ref{Newtontwo}) generalises to $n$-dimensions as\n%\n\\begin{equation}\n  \\bx_{n+1} = \\bx_{n} -\n  \\left [ J(\\bx_n) \\right ]^{-1} \\bff(\\bx_n) . \\label{NewtonRn}\n\\end{equation}\n%\nThe scheme~(\\ref{NewtonRn}) is numerically not convenient, because it\nrequires the computation of the inverse of the Jacobian.  Therefore,\none normally defines an additional variable\n%\n\\begin{equation*}\n  \\bz = \\bx_{n+1} - \\bx_n \\implies J \\bz = - \\bff(\\bx_n) ,\n\\end{equation*}\n%\nand solves the linear problem for $\\bz$ using, for example, Gauss\nelimination with pivoting.  Once $\\bz$ is known we can obtain\n%\n\\begin{equation*}\n  \\bx_{n+1} = \\bx_n + \\bz .\n\\end{equation*}\n\n\\noindent\n\\textbf{Remark 1} - The initial guess is absolutely crucial and the\nmethod can be very ``touchy''.  However, if we are close enough to the\nroot and the Jacobian is non singular the convergence is quadratic.\n\n\\noindent\n\\textbf{Remark 2} - Newton's method is very computationally intensive:\nit requires the evaluation of $n^2$ derivatives and the solution of an\n$n \\times n$ linear problem at each iteration.  A multidimensional\nversion of the secant method has been developed to reduce the number\nof computations per step (Broyden algorithm).\n\n\n\\section*{Further reading}\n\nTopics covered here are also covered in\n\\begin{itemize}\n\\item Chapter 7 of Linz \\& Wang, \\textit{Exploring Numerical Methods}\n  (QA297 LIN),\n\\item Chapter 3 of Kincaid \\& Cheney, \\textit{Numerical Analysis}\n  (QA297 KIN),\n\\item Chapters 1 and 4 of S{\\\"u}li \\& Mayers, \\textit{An Introduction\n    to Numerical Analysis} (not in library -- includes considerably\n  more analysis of the convergence issues).\n\\end{itemize}\n", "meta": {"hexsha": "68f98f1b76e81957cb5d893a526ee0b33f0c23fd", "size": 46810, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/tex/Nonlinear_equations.tex", "max_stars_repo_name": "josh-gree/NumericalMethods", "max_stars_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 76, "max_stars_repo_stars_event_min_datetime": "2015-02-12T19:51:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T15:34:11.000Z", "max_issues_repo_path": "Notes/tex/Nonlinear_equations.tex", "max_issues_repo_name": "josh-gree/NumericalMethods", "max_issues_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-05-24T19:49:52.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-23T21:40:42.000Z", "max_forks_repo_path": "Notes/tex/Nonlinear_equations.tex", "max_forks_repo_name": "josh-gree/NumericalMethods", "max_forks_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2015-01-05T13:30:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-15T09:59:39.000Z", "avg_line_length": 35.4352763058, "max_line_length": 75, "alphanum_fraction": 0.6905148473, "num_tokens": 15078, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.782662489091802, "lm_q2_score": 0.9324533027598817, "lm_q1q2_score": 0.7297962228999206}}
{"text": "%!TEX root = ceres-solver.tex\n\\chapter{Modeling}\n\\label{chapter:api}\n\\section{\\texttt{CostFunction}}\nGiven parameter blocks $\\left[x_{i_1}, \\hdots , x_{i_k}\\right]$, a \\texttt{CostFunction} is responsible for computing \na vector of residuals and if asked a vector of Jacobian matrices, i.e., given $\\left[x_{i_1}, \\hdots , x_{i_k}\\right]$, compute the vector $f_i\\left(x_{i_1},\\hdots,x_{k_i}\\right)$ and the matrices \n\\begin{equation}\nJ_{ij} = \\frac{\\partial}{\\partial x_{i_j}}f_i\\left(x_{i_1},\\hdots,x_{k_i}\\right),\\quad \\forall j = i_1,\\hdots, i_k\n\\end{equation}\n\\begin{minted}{c++}\nclass CostFunction {\n public:\n  virtual bool Evaluate(double const* const* parameters,\n                        double* residuals,\n                        double** jacobians) = 0;\n  const vector<int16>& parameter_block_sizes(); \n  int num_residuals() const;\n\n protected:\n  vector<int16>* mutable_parameter_block_sizes();\n  void set_num_residuals(int num_residuals);\n};\n\\end{minted}\n\nThe signature of the function (number and sizes of input parameter blocks and number of outputs)\nis stored in \\texttt{parameter\\_block\\_sizes\\_} and \\texttt{num\\_residuals\\_} respectively. User\ncode inheriting from this class is expected to set these two members with the\ncorresponding accessors. This information will be verified by the Problem\nwhen added with \\texttt{Problem::AddResidualBlock}. \n\nThe most important method here is \\texttt{Evaluate}. It implements the residual and Jacobian computation.\n\n\\texttt{parameters}  is an array of pointers to arrays containing the various parameter blocks. parameters has the same number of elements as parameter\\_block\\_sizes\\_.  Parameter blocks are in the same order as parameter\\_block\\_sizes\\_. \n\n\n\\texttt{residuals} is an array of size \\texttt{num\\_residuals\\_}. \n\n\n\\texttt{jacobians} is an array of size \\texttt{parameter\\_block\\_sizes\\_} containing pointers to storage for Jacobian matrices corresponding to each parameter block. The Jacobian matrices are in the same order as \\texttt{parameter\\_block\\_sizes\\_}. \\texttt{jacobians[i]} is an array that contains \\texttt{num\\_residuals\\_} $\\times$ \\texttt{parameter\\_block\\_sizes\\_[i]} elements. Each Jacobian matrix is stored in row-major order, i.e., \n \n\\begin{equation}\n\\texttt{jacobians[i][r * parameter\\_block\\_size\\_[i] + c]} =\n%\\frac{\\partial}{\\partial x_{ic}}  f_{r}\\left(x_{1},\\hdots, x_{k}\\right)\n\\frac{\\partial \\texttt{residual[r]}}{\\partial \\texttt{parameters[i][c]}}\n\\end{equation}\n\nIf \\texttt{jacobians} is \\texttt{NULL}, then no derivatives are returned; this is the case when computing cost only. If \\texttt{jacobians[i]} is \\texttt{NULL}, then the Jacobian matrix corresponding to the $i^{\\textrm{th}}$ parameter block must not be returned, this is the case when the a parameter block is marked constant.\n\n\\section{\\texttt{SizedCostFunction}}\nIf the size of the parameter blocks and the size of the residual vector is known at compile time (this is the common case), Ceres provides \\texttt{SizedCostFunction}, where these values can be specified as template parameters.\n\\begin{minted}{c++}\ntemplate<int kNumResiduals,\n         int N0 = 0, int N1 = 0, int N2 = 0, int N3 = 0, int N4 = 0, int N5 = 0>\nclass SizedCostFunction : public CostFunction {\n public:\n  virtual bool Evaluate(double const* const* parameters,\n                        double* residuals,\n                        double** jacobians) = 0;\n};\n\\end{minted}\nIn this case the user only needs to implement the \\texttt{Evaluate} method.\n\n\\section{\\texttt{AutoDiffCostFunction}}\nBut even defining the \\texttt{SizedCostFunction} can be a tedious affair if complicated derivative computations are involved. To this end Ceres provides automatic differentiation.\n\nTo get an auto differentiated cost function, you must define a class with a\n templated \\texttt{operator()} (a functor) that computes the cost function in terms of\n the template parameter \\texttt{T}. The autodiff framework substitutes appropriate\n \\texttt{Jet} objects for T in order to compute the derivative when necessary, but\n this is hidden, and you should write the function as if T were a scalar type\n (e.g. a double-precision floating point number).\n\n The function must write the computed value in the last argument (the only\n non-\\texttt{const} one) and return true to indicate success.\n\n For example, consider a scalar error $e = k - x^\\top y$, where both $x$ and $y$ are\n two-dimensional vector parameters  and $k$ is a constant. The form of this error, which is the\n difference between a constant and an expression, is a common pattern in least\n squares problems. For example, the value $x^\\top y$ might be the model expectation\n for a series of measurements, where there is an instance of the cost function\n for each measurement $k$.\n\n The actual cost added to the total problem is $e^2$, or $(k - x^\\top y)^2$; however,\n the squaring is implicitly done by the optimization framework.\n\n To write an auto-differentiable cost function for the above model, first\n define the object\n\\begin{minted}{c++}\nclass MyScalarCostFunction {\n  MyScalarCostFunction(double k): k_(k) {}\n  template <typename T>\n  bool operator()(const T* const x , const T* const y, T* e) const {\n    e[0] = T(k_) - x[0] * y[0] + x[1] * y[1]\n     return true;\n  }\n\n private:\n  double k_;\n};\n\\end{minted}\n \nNote that in the declaration of \\texttt{operator()} the input parameters \\texttt{x} and \\texttt{y} come\n first, and are passed as const pointers to arrays of \\texttt{T}. If there were three\n input parameters, then the third input parameter would come after \\texttt{y}. The\n output is always the last parameter, and is also a pointer to an array. In\n the example above, \\texttt{e} is a scalar, so only \\texttt{e[0]} is set.\n\n Then given this class definition, the auto differentiated cost function for\n it can be constructed as follows.\n\n\\begin{minted}{c++}\nCostFunction* cost_function\n    = new AutoDiffCostFunction<MyScalarCostFunction, 1, 2, 2>(\n        new MyScalarCostFunction(1.0));              ^  ^  ^\n                                                     |  |  |\n                         Dimension of residual ------+  |  |\n                         Dimension of x ----------------+  |\n                         Dimension of y -------------------+\n\\end{minted}\n\nIn this example, there is usually an instance for each measurement of k.\n\nIn the instantiation above, the template parameters following\n \\texttt{MyScalarCostFunction}, \\texttt{<1, 2, 2>} describe the functor as computing a\n 1-dimensional output from two arguments, both 2-dimensional.\n\n The framework can currently accommodate cost functions of up to 6 independent\n variables, and there is no limit on the dimensionality of each of them.\n\n \\textbf{WARNING 1} Since the functor will get instantiated with different types for\n \\texttt{T}, you must convert from other numeric types to \\texttt{T} before mixing\n computations with other variables of type \\texttt{T}. In the example above, this is\n seen where instead of using \\texttt{k\\_} directly, \\texttt{k\\_} is wrapped with \\texttt{T(k\\_)}.\n\n \\textbf{WARNING 2} A common beginner's error when first using \\texttt{AutoDiffCostFunction} is to get the sizing wrong. In particular, there is a tendency to\n set the template parameters to (dimension of residual, number of parameters)\n instead of passing a dimension parameter for {\\em every parameter block}. In the\n example above, that would be \\texttt{<MyScalarCostFunction, 1, 2>}, which is missing\n the 2 as the last template argument. \n\n\\subsection{Theory \\& Implementation}\nTBD\n\n\\section{\\texttt{NumericDiffCostFunction}}\nTo get a numerically differentiated cost function, define a subclass of\n\\texttt{CostFunction} such that the \\texttt{Evaluate} function ignores the jacobian\nparameter. The numeric differentiation wrapper will fill in the jacobians array\n if necessary by repeatedly calling the \\texttt{Evaluate} method with\nsmall changes to the appropriate parameters, and computing the slope. For\nperformance, the numeric differentiation wrapper class is templated on the\nconcrete cost function, even though it could be implemented only in terms of\nthe virtual \\texttt{CostFunction} interface.\n\\begin{minted}{c++}\ntemplate <typename CostFunctionNoJacobian,\n          NumericDiffMethod method = CENTRAL, int M = 0,\n          int N0 = 0, int N1 = 0, int N2 = 0, int N3 = 0, int N4 = 0, int N5 = 0>\nclass NumericDiffCostFunction\n    : public SizedCostFunction<M, N0, N1, N2, N3, N4, N5> {\n};\n\\end{minted}\n\nThe numerically differentiated version of a cost function for a cost function\ncan be constructed as follows:\n\\begin{minted}{c++}\nCostFunction* cost_function\n    = new NumericDiffCostFunction<MyCostFunction, CENTRAL, 1, 4, 8>(\n        new MyCostFunction(...), TAKE_OWNERSHIP);\n\\end{minted}\nwhere \\texttt{MyCostFunction} has 1 residual and 2 parameter blocks with sizes 4 and 8\nrespectively. Look at the tests for a more detailed example.\n\nThe central difference method is considerably more accurate at the cost of\ntwice as many function evaluations than forward difference. Consider using\ncentral differences begin with, and only after that works, trying forward\ndifference to improve performance.\n\n\\section{\\texttt{LossFunction}}\n For least squares problems where the minimization may encounter\n input terms that contain outliers, that is, completely bogus\n measurements, it is important to use a loss function that reduces\n their influence.\n\n Consider a structure from motion problem. The unknowns are 3D\n points and camera parameters, and the measurements are image\n coordinates describing the expected reprojected position for a\n point in a camera. For example, we want to model the geometry of a\n street scene with fire hydrants and cars, observed by a moving\n camera with unknown parameters, and the only 3D points we care\n about are the pointy tippy-tops of the fire hydrants. Our magic\n image processing algorithm, which is responsible for producing the\n measurements that are input to Ceres, has found and matched all\n such tippy-tops in all image frames, except that in one of the\n frame it mistook a car's headlight for a hydrant. If we didn't do\n anything special  the\n residual for the erroneous measurement will result in the\n entire solution getting pulled away from the optimum to reduce\n the large error that would otherwise be attributed to the wrong\n measurement.\n\n Using a robust loss function, the cost for large residuals is\n reduced. In the example above, this leads to outlier terms getting\n down-weighted so they do not overly influence the final solution.\n\n\\begin{minted}{c++}\nclass LossFunction {\n public:\n  virtual void Evaluate(double s, double out[3]) const = 0;\n};\n\\end{minted}\t\n\nThe key method is \\texttt{Evaluate}, which given a non-negative scalar \\texttt{s}, computes\n\\begin{align}\n\t\\texttt{out} = \\begin{bmatrix}\\rho(s), & \\rho'(s), & \\rho''(s)\\end{bmatrix}\n\\end{align}\n\nHere the convention is that the contribution of a term to the cost function is given by $\\frac{1}{2}\\rho(s)$,  where $s = \\|f_i\\|^2$. Calling the method with a negative value of $s$ is an error and the implementations are not required to handle that case.\n\nMost sane choices of $\\rho$ satisfy:\n\\begin{align}\n   \\rho(0) &= 0\\\\\n   \\rho'(0) &= 1\\\\\n   \\rho'(s) &< 1 \\text{ in the outlier region}\\\\\n   \\rho''(s) &< 0 \\text{ in the outlier region}\n\\end{align}\nso that they mimic the squared cost for small residuals.\n\n\\subsection{Scaling}\nGiven one robustifier $\\rho(s)$\n one can change the length scale at which robustification takes\n place, by adding a scale factor $a > 0$ which gives us $\\rho(s,a) = a^2 \\rho(s / a^2)$ and the first and second derivatives as $\\rho'(s / a^2)$ and   $(1 / a^2) \\rho''(s / a^2)$ respectively. \n\n\n\\begin{figure}[hbt]\n\\includegraphics[width=\\textwidth]{loss.pdf}\n\\caption{Shape of the various common loss functions.}\n\\label{fig:loss}\n\\end{figure}\n\n\nThe reason for the appearance of squaring is that $a$ is in the units of the residual vector norm whereas $s$ is a squared norm. For applications it is more convenient to specify $a$ than\nits square. \n\nHere are some common loss functions implemented in Ceres. For simplicity we described their unscaled versions. Figure~\\ref{fig:loss} illustrates their shape graphically.\n\n\\begin{align}\n\t\t\\rho(s)&=s \\tag{\\texttt{NullLoss}}\\\\\n\t\t\\rho(s) &= \\begin{cases}\n\t\t       s & s \\le 1\\\\\n\t\t       2 \\sqrt{s} - 1 & s > 1\n\t           \\end{cases} \\tag{\\texttt{HuberLoss}}\\\\\n\t\t\\rho(s) &= 2 (\\sqrt{1+s} - 1) \\tag{\\texttt{SoftLOneLoss}}\\\\\n\t\t\\rho(s) &= \\log(1 + s) \\tag{\\texttt{CauchyLoss}}\n\\end{align}\n\n\\subsection{Theory \\& Implementation}\nTBD\n\n\\section{\\texttt{LocalParameterization}}\nSometimes the parameters $x$ can overparameterize a problem. In\nthat case it is desirable to choose a parameterization to remove\nthe null directions of the cost. More generally, if $x$ lies on a\nmanifold of a smaller dimension than the ambient space that it is\nembedded in, then it is numerically and computationally more\neffective to optimize it using a parameterization that lives in\nthe tangent space of that manifold at each point.\n\nFor example, a sphere in three dimensions is a two dimensional\nmanifold, embedded in a three dimensional space. At each point on\nthe sphere, the plane tangent to it defines a two dimensional\ntangent space. For a cost function defined on this sphere, given a\npoint $x$, moving in the direction normal to the sphere at that\npoint is not useful. Thus a better way to parameterize a point on\na sphere is to optimize over two dimensional vector $\\Delta x$ in the\ntangent space at the point on the sphere point and then \"move\" to\nthe point $x + \\Delta x$, where the move operation involves projecting\nback onto the sphere. Doing so removes a redundant dimension from\nthe optimization, making it numerically more robust and efficient.\n\nMore generally we can define a function\n\\begin{equation}\n  x' = \\boxplus(x, \\Delta x),\n\\end{equation}\nwhere $x'$ has the same size as $x$, and $\\Delta x$ is of size less\nthan or equal to $x$. The function $\\boxplus$, generalizes the\ndefinition of vector addition. Thus it satisfies the identity\n\\begin{equation}\n  \\boxplus(x, 0) = x,\\quad \\forall x.\n\\end{equation}\n\nInstances of \\texttt{LocalParameterization} implement the $\\boxplus$ operation and its derivative with respect to $\\Delta x$ at $\\Delta x = 0$.\n\n\\begin{minted}{c++}\nclass LocalParameterization {\n public:\n  virtual ~LocalParameterization() {}\n  virtual bool Plus(const double* x,\n                    const double* delta,\n                    double* x_plus_delta) const = 0;\n  virtual bool ComputeJacobian(const double* x, double* jacobian) const = 0;\n  virtual int GlobalSize() const = 0;\n  virtual int LocalSize() const = 0;\n};\n\\end{minted}\n\n\\texttt{GlobalSize} is the dimension of the ambient space in which the parameter block $x$ lives. \\texttt{LocalSize} is the size of the tangent space that $\\Delta x$ lives in. \\texttt{Plus} implements $\\boxplus(x,\\Delta x)$ and $\\texttt{ComputeJacobian}$ computes the Jacobian matrix \n\\begin{equation}\n\tJ = \\left . \\frac{\\partial }{\\partial \\Delta x} \\boxplus(x,\\Delta x)\\right|_{\\Delta x = 0}\n\\end{equation}\nin row major form.\n\nA trivial version of $\\boxplus$ is when delta is of the same size as $x$\nand\n\n\\begin{equation}\n  \\boxplus(x, \\Delta x) = x + \\Delta x\n\\end{equation}\n\nA more interesting case if $x$ is a two dimensional vector, and the\nuser wishes to hold the first coordinate constant. Then, $\\Delta x$ is a\nscalar and $\\boxplus$ is defined as\n\n\\begin{equation}\n  \\boxplus(x, \\Delta x) = x + \\left[ \\begin{array}{c} 0 \\\\ 1\n                                  \\end{array} \\right]        \\Delta x\n\\end{equation}\n\n\\texttt{SubsetParameterization} generalizes this construction to hold any part of a parameter block constant.\n\n\nAnother example that occurs commonly in Structure from Motion problems\nis when camera rotations are parameterized using a quaternion. There,\nit is useful only to make updates orthogonal to that 4-vector defining\nthe quaternion. One way to do this is to let $\\Delta x$ be a 3\ndimensional vector and define $\\boxplus$ to be\n\n\\begin{equation}\n  \\boxplus(x, \\Delta x) = \n\\left[\n\\cos(|\\Delta x|), \\frac{\\sin\\left(|\\Delta x|\\right)}{|\\Delta x|} \\Delta x \n\\right] * x\n\\label{eq:quaternion}\n\\end{equation}\nThe multiplication between the two 4-vectors on the right hand\nside is the standard quaternion product. \\texttt{QuaternionParameterization} is an implementation of~\\eqref{eq:quaternion}.\n\n\\clearpage\n\n\\section{\\texttt{Problem}}\n\\begin{minted}{c++}\nclass Problem {\n public:\n  struct Options {\n    Options();\n    Ownership cost_function_ownership;\n    Ownership loss_function_ownership;\n    Ownership local_parameterization_ownership;\n  };\n\n  Problem();\n  explicit Problem(const Options& options);\n  ~Problem();\n\n  ResidualBlockId AddResidualBlock(CostFunction* cost_function,\n                                   LossFunction* loss_function,\n                                   const vector<double*>& parameter_blocks);\n\n  void AddParameterBlock(double* values, int size);\n  void AddParameterBlock(double* values,\n                         int size,\n                         LocalParameterization* local_parameterization);\n\n  void SetParameterBlockConstant(double* values);\n  void SetParameterBlockVariable(double* values);\n  void SetParameterization(double* values,\n                           LocalParameterization* local_parameterization);\n\n  int NumParameterBlocks() const;\n  int NumParameters() const;\n  int NumResidualBlocks() const;\n  int NumResiduals() const;\n};\n\\end{minted}\n\nThe \\texttt{Problem} objects holds the robustified non-linear least squares problem~\\eqref{eq:ceresproblem}. To create a least squares problem, use the \\texttt{Problem::AddResidualBlock} and \\texttt{Problem::AddParameterBlock} methods.\n\nFor example a problem containing 3 parameter blocks of sizes 3, 4 and 5\nrespectively and two residual blocks  of size 2 and 6:\n\n\\begin{minted}{c++}\ndouble x1[] = { 1.0, 2.0, 3.0 };\ndouble x2[] = { 1.0, 2.0, 3.0, 5.0 };\ndouble x3[] = { 1.0, 2.0, 3.0, 6.0, 7.0 };\n\nProblem problem;\nproblem.AddResidualBlock(new MyUnaryCostFunction(...), x1);\nproblem.AddResidualBlock(new MyBinaryCostFunction(...), x2, x3);\n\\end{minted}\n\n\n\\texttt{AddResidualBlock} as the name implies, adds a residual block to the problem. It adds a cost function, an optional loss function, and connects the cost function to a set of parameter blocks.\n\nThe cost\n   function carries with it information about the sizes of the\n   parameter blocks it expects. The function checks that these match\n   the sizes of the parameter blocks listed in \\texttt{parameter\\_blocks}. The\n   program aborts if a mismatch is detected. \\texttt{loss\\_function} can be\n   \\texttt{NULL}, in which case the cost of the term is just the squared norm\n   of the residuals.\n\n  The user has the option of explicitly adding the parameter blocks\n  using \\texttt{AddParameterBlock}. This causes additional correctness\n  checking; however, \\texttt{AddResidualBlock} implicitly adds the parameter\n   blocks if they are not present, so calling \\texttt{AddParameterBlock}\n   explicitly is not required.\n\n  \n   \\texttt{Problem} by default takes ownership of the\n  \\texttt{cost\\_function} and \\texttt{loss\\_function pointers}. These objects remain\n   live for the life of the \\texttt{Problem} object. If the user wishes to\n  keep control over the destruction of these objects, then they can\n  do this by setting the corresponding enums in the \\texttt{Options} struct.\n  \n\n  Note that even though the Problem takes ownership of \\texttt{cost\\_function}\n  and \\texttt{loss\\_function}, it does not preclude the user from re-using\n  them in another residual block. The destructor takes care to call\n  delete on each \\texttt{cost\\_function} or \\texttt{loss\\_function} pointer only once,\n  regardless of how many residual blocks refer to them.\n\n\\texttt{AddParameterBlock} explicitly adds a parameter block to the \\texttt{Problem}. Optionally it allows the user to associate a LocalParameterization object with the parameter block too. Repeated calls with the same arguments are ignored. Repeated\ncalls with the same double pointer but a different size results in undefined behaviour.\n\nYou can set any parameter block to be constant using \n\n\\texttt{Problem::SetParameterBlockConstant} \n\nand undo this using\n\n\\texttt{Problem::SetParameterBlockVariable}.\n\nIn fact you can set any number of parameter blocks to be constant, and Ceres is smart enough to figure out what part of the problem you have constructed depends on the parameter blocks that are free to change and only spends time solving it. So for example if you constructed a problem with a million parameter blocks and 2 million residual blocks, but then set all but one parameter blocks to be constant and say only 10 residual blocks depend on this one non-constant parameter block. Then the computational effort Ceres spends in solving this problem will be the same if you had defined a problem with one parameter block and 10 residual blocks.\n\n  \\texttt{Problem} by default takes ownership of the\n  \\texttt{cost\\_function}, \\texttt{loss\\_function} and \\\\ \\texttt{local\\_parameterization} pointers. These objects remain\n   live for the life of the \\texttt{Problem} object. If the user wishes to\n  keep control over the destruction of these objects, then they can\n  do this by setting the corresponding enums in the \\texttt{Options} struct. Even though \\texttt{Problem} takes ownership of these pointers,  it does not preclude the user from re-using them in another residual or parameter block. The destructor takes care to call\n  delete on each  pointer only once.", "meta": {"hexsha": "5cd199c0a72b8fe265be806c75c49c70a987f9d3", "size": 21581, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/modeling.tex", "max_stars_repo_name": "pritasam/ceres-solver", "max_stars_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/modeling.tex", "max_issues_repo_name": "pritasam/ceres-solver", "max_issues_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/modeling.tex", "max_forks_repo_name": "pritasam/ceres-solver", "max_forks_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.171875, "max_line_length": 648, "alphanum_fraction": 0.7387516797, "num_tokens": 5493, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7296904457714505}}
{"text": "\n\\subsection{Axioms for measures}\n\n\n\\subsubsection{Measures are non-negative}\n\n\\(\\forall E \\in \\Sigma : \\mu (E)\\ge 0\\)\n\n\\subsubsection{The measure for the null set is \\(0\\).}\n\n\\(\\mu (\\null )=0\\)\n\n\\subsubsection{Disjoint sets are additive}\n\n\\(\\mu (\\lor_{k=1}^{\\infty} E_k)=\\sum \\mu (E_k)\\)\n\nWhere all elements \\(E_k\\) are disjoint. That is, they have no elements in common.\n\n", "meta": {"hexsha": "e469e87e3f8747ce2f53eef7ba4543ec8987997b", "size": 374, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/measures/01-02-axioms.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/measures/01-02-axioms.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/measures/01-02-axioms.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.6842105263, "max_line_length": 82, "alphanum_fraction": 0.6684491979, "num_tokens": 122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465062370312, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.7295636245752751}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\subsection{Worksheet - Lagrangian Mechanics with Dissipative Forces \\& Constrained Systems}\n\\begin{p}Write down Newton’sequation of motion for a mass $m$ hanging on a spring with spring constant $k$, equilibrium length $x_0$, and damping coefficient $b$,and subject to a vertical forcing function $F(t)$.\n\\end{p}\n\\begin{s}\nIn one dimension, we have:\n\\[\\sum F = -k(x-x_0) - b\\dot{x} - mg + F(t) = m\\ddot{x}\\]\nWhere the first term is the spring force, the second term is the air friction, the third term is the gravitational force, and the fourth term is the forcing function. We may rearrange this to say:\n\\[m\\ddot{x} + b\\dot{x} + k(x-x_0) = F(t)\\]\n\n\\end{s}\n\\begin{p}\nIn the previous problem, there were nonconservative forces that are not included in our Lagrange formalism. Compare the equation of motion above to the Langrange equation for a mass on a spring without damping and forcing, and suggest how the Lagrange equations should be modified to include friction.\n\\end{p}\n\\begin{s}\nWe consider that Lagrange's equation of motion $\\dpd{\\LL}{x} = \\dod{}{t}\\dpd{\\LL}{\\dot{x}}$ does \\textbf{not} account for the nonconservative forces (i.e. the forcing function $F(t)$ and the air friction term $-b\\dot{x}$), as the Lagrangian is given by $\\LL = T - U = \\frac{1}{2}m\\dot{x}^2 + mgx + \\frac{1}{2}k(x-x_0)^2$ and clearly this does not account for the damping or forcing terms. Without these terms, we have that:\n\\[\\dpd{\\LL}{x} = -k(x - x_0) = \\dod{}{t}\\dpd{\\LL}{\\dot{x}} = m\\ddot{x}\\]\nBut with these terms, we have that:\n\\[\\dpd{\\LL}{x} = k(x - x_0) - b\\dot{x} + F(t)\\]\nSo the \"fix\" for nonconservative forces to the Lagrange equations of motion are:\n\\[\\dpd{\\LL}{x} + F_{noncons} = \\dod{}{t}\\dpd{\\LL}{\\dot{x}}\\]\nYou have to add these in manually because there is no principle of least action for dissipative forces.\n\n\\end{s}\n\n\\begin{p}\nWrite down the Lagrangian for the Atwood machine. How many degrees of freedom are there? Pick a generalized coordinate, find the Lagrange equation of motion, and solve it for the acceleration.\n\\begin{center}\n    \\includegraphics[scale=0.6]{Lecture-4/W4-img1.png}\n\\end{center}\n\\end{p}\n\\begin{s}\nThere is only one degree of freedom as the motion of one of the masses is completely determined by the other. Let our generalized coordinate be $x$, and we can define the height of the other mass as $y = l - x$ where $l$ is some constant representing the length of the string. The potential energy of the system is given by:\n\\[U = -m_1gx - m_2g(l-x) = xg(m_2-m_1) - m_2lg\\]\nThe kinetic energy of the system is given by:\n\\[T = \\frac{1}{2}m_1\\dot{x}^2 + \\frac{1}{2}m_2(-\\dot{x})^2 = \\frac{1}{2}(m_1 + m_2)\\dot{x}^2\\]\nHence the Lagrangian of our system is given by:\n\\[\\LL = T - U = \\frac{1}{2}(m_1 + m_2)\\dot{x}^2 - xg(m_2-m_1) + m_2lg\\]\nSolving for the equation of motion:\n\\[\\dpd{\\LL}{x} = \\dod{}{t}\\dpd{\\LL}{\\dot{x}}\\]\n\\[g(m_1 - m_2) = \\dod{}{t}(m_1 + m_2)\\dot{x}\\]\n\\[g(m_1 - m_2) = (m_1 + m_2)\\ddot{x}\\]\nHence solving for the acceleration, we get:\n\\[\\ddot{x} = g\\frac{m_1 - m_2}{m_1 + m_2}\\]\nThe beauty here is that we really can ignore the constraint forces; if we want to know the motion of the particles, we can use directly the Euler-Lagrange equations of motion. With Newton's laws, we have to keep track of them explicitly; this is why the Lagrangian formulation is often easier.\n\\end{s}\n\n\\begin{p}\nA particle of mass $m$ is constrained to move on a frictionless  cylinder of radius $R$, given by the equation $\\rho = R$ in cylindrical polar coordinates ($\\rho$, $\\phi$, $z$). Besides the force of constraint (the normal force of the cylinder), the only force on the mass is a force $F = -kr$ directed toward the origin. Using $z$ and $\\phi$ as generalized coordinates, find the Lagrangian $\\LL$ Write down and solve Lagrange's equations and describe the motion. \n\\end{p}\n\\begin{s}\nThe \"spring\" potential energy from the force directed towards the origin is given by $U_{spr} = \\frac{1}{2}k(R^2 + z^2)$. The kinetic energy of the particle is given as $T = \\frac{1}{2}m\\dot{\\v{r}}^2 = \\frac{1}{2}m(\\dot{z}^2 + R^2\\dot{\\phi}^2)$. The Lagrangian is therefore given by:\n\\[\\LL = T - U = \\frac{1}{2}m(\\dot{z}^2 + R^2\\dot{\\phi}^2) - \\frac{1}{2}k(R^2 + z^2)\\]\nNow we use the EL equations to find the equations of motion for $z$ and $phi$. Starting with $z$:\n\\[\\dpd{\\LL}{z} = \\dod{}{t}\\dpd{\\LL}{\\dot{z}}\\]\n\\[- kz = m\\ddot{z}\\]\nThe solution to this differential equation is simple harmonic motion with frequency $\\omega = \\sqrt{\\frac{k}{m}}$:\n\\[z(t) = A\\cos(\\omega t) + B\\sin(\\omega t)\\]\nNext for $\\phi$:\n\\[\\dpd{\\LL}{\\phi} = \\dod{}{t}\\dpd{\\LL}{\\dot{\\phi}}\\]\n\\[0 = \\dod{}{t}\\left(mR^2\\dot{\\phi}\\right)\\]\n\\[0 = mR^2\\ddot{\\phi}\\]\nHence (as we knew already from angular momentum conservation) we find that $\\ddot{\\phi}$ is conserved and hence $\\dot{\\phi}$ is constant. \n\\end{s}\n\n\\end{document}", "meta": {"hexsha": "ddd5462b3a4142421999522bb431b2d9a5e04805", "size": 4878, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-4/Worksheet-4.tex", "max_stars_repo_name": "RioWeil/PHYS306-notes", "max_stars_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture-4/Worksheet-4.tex", "max_issues_repo_name": "RioWeil/PHYS306-notes", "max_issues_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture-4/Worksheet-4.tex", "max_forks_repo_name": "RioWeil/PHYS306-notes", "max_forks_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 71.7352941176, "max_line_length": 464, "alphanum_fraction": 0.6875768758, "num_tokens": 1613, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.8824278757303677, "lm_q1q2_score": 0.7295135398180116}}
{"text": "\\chapter{Statistical Decision Theory}\n\n\\begin{ex}\n  \\begin{enumerate}[(a)]\n    \\item Let $X\\sim\\text{Binomial}(n,p)$ and take the prior\n          $p\\sim\\text{Beta}(\\alpha,\\beta)$.\n          \\begin{align*}\n            f(x\\,|\\,p)f(p)\n             & \\propto\n            p^x(1-p)^{n-x}p^{\\alpha-1}(1-p)^{\\beta-1} \\\\\n             & =p^{x+\\alpha-1}(1-p)^{n+\\beta-x-1},\n          \\end{align*}\n          which normalizes to the PDF of a $\\text{Beta}(\\alpha+x,\\beta+n-x)$\n          distribution.\n\n          By Theorem 12.8, the Bayes estimator is the mean of the posterior, and\n          therefore\n          \\[\n            \\phat=\\frac{\\alpha+X}{\\alpha+\\beta+n}.\n          \\]\n\n          Recall that\n          \\begin{align*}\n            R(p,\\phat)\n             & =\\mathbb{V}_p\\left(\\frac{\\alpha+X}{\\alpha+\\beta+n}\\right)\n            +\\left[\\textsf{bias}_p\\left(\\frac{\\alpha+X}{\\alpha+\\beta+n}\\right)\\right]^2       \\\\\n             & =\\frac{\\mathbb{V}_p(X)}{(\\alpha+\\beta+n)^2}\n            +\\left[\\frac{\\alpha+np}{\\alpha+\\beta+n}-p\\right]^2                                \\\\\n             & =\\frac{\\mathbb{V}_p(X)}{(\\alpha+\\beta+n)^2}\n            +\\left[\\frac{\\alpha+np}{\\alpha+\\beta+n}-p\\right]^2                                \\\\\n             & =\\frac{np(1-p)}{(\\alpha+\\beta+n)^2}\n            +\\left[\\frac{\\alpha-\\alpha p-\\beta p}{\\alpha+\\beta+n}\\right]^2                    \\\\\n             & =\\frac{np(1-p)+(\\beta p - \\alpha(1-p))^2}{(\\alpha+\\beta+n)^2}                  \\\\\n             & =\\frac{\\beta^2p^2+(n-2\\alpha\\beta)p(1-p)+\\alpha^2(1-p)^2}{(\\alpha+\\beta+n)^2},\n          \\end{align*}\n          and that therefore the Bayes risk is\n          \\begin{align*}\n            r(f,\\phat)\n             & =\\int_0^1\\!R(p,\\phat)f(p)\\,\\d{p}                                                    \\\\\n             & =\\frac{\\beta^2B(\\alpha+2,\\beta)\n              +(n-2\\alpha\\beta)B(\\alpha+1,\\beta+1)\n              +\\alpha^2B(\\alpha,\\beta+2)}{(\\alpha+\\beta+n)^2B(\\alpha, \\beta)}                      \\\\\n             & =\\frac{\\beta^2\\alpha(\\alpha+1)+(n-2\\alpha\\beta)\\alpha\\beta+\\alpha^2\\beta(\\beta+1)}{\n              (\\alpha+\\beta+n)^2(\\alpha+\\beta)(\\alpha+\\beta+1)}                                    \\\\\n             & =\\frac{\\alpha\\beta}{\n              (\\alpha+\\beta+n)(\\alpha+\\beta)(\\alpha+\\beta+1)},                                     \\\\\n          \\end{align*}\n          since\n          \\begin{align*}\n             & \\int_0^1\\!\n            \\beta^2p^{\\alpha+2-1}(1-p)^{\\beta-1}\n            +(n-2\\alpha\\beta)p^{\\alpha+1-1}(1-p)^{\\beta+1-1}\n            +\\alpha^2p^{\\alpha-1}(1-p)^{\\beta+2-1}\\,\\d{p} \\\\\n             & \\quad=\\beta^2B(\\alpha+2,\\beta)\n            +(n-2\\alpha\\beta)B(\\alpha+1,\\beta+1)\n            +\\alpha^2B(\\alpha,\\beta+2).\n          \\end{align*}\n    \\item Let $X\\sim\\text{Poisson}(\\lambda)$ and take the prior\n          $\\lambda\\sim\\text{Gamma}(\\alpha,\\beta)$. By Exercise 11.6, the\n          posterior distribution of $\\lambda$ is a\n          $\\text{Gamma}(\\alpha',\\beta')$ distribution with\n          \\[\n            \\alpha'=\\alpha+x,\\text{ and }\n            \\beta'=\\frac{\\beta}{\\beta +1},\n          \\]\n          and posterior mean (and therefore Bayes estimator),\n          \\[\n            \\widehat{\\lambda}=\\left(\\alpha+x\\right)\n            \\left(\\frac{\\beta}{\\beta +1}\\right).\n          \\]\n          We have\n          \\[\n            \\mathbb{V}_\\lambda\\left(\n            \\widehat{\\lambda}\n            \\right)\n            =\\mathbb{V}_\\lambda\\left(\n            \\left(\\alpha+X\\right)\n            \\left(\\frac{\\beta}{\\beta +1}\\right)\n            \\right)\n            =\\frac{\\lambda\\beta^2}{(\\beta+1)^2},\n          \\]\n          and\n          \\[\n            \\mathbb{E}_\\lambda\\left(\n            \\widehat{\\lambda}\n            \\right)\n            =\\frac{(\\alpha+\\lambda)\\beta}{\\beta+1},\n          \\]\n          and therefore\n          \\begin{align*}\n            R(\\lambda,\\widehat{\\lambda})\n             & =\\mathbb{V}_\\lambda(\\widehat{\\lambda})\n            +\\left(\\textsf{bias}_\\lambda(\\widehat{\\lambda})\\right)^2                       \\\\\n             & =\\frac{\\lambda\\beta^2}{(\\beta+1)^2}\n            +\\left(\\frac{\\alpha\\beta-\\lambda}{\\beta+1}\\right)^2                            \\\\\n             & =\\frac{\\lambda^2+\\lambda\\beta(\\beta-2\\alpha)+\\alpha^2\\beta^2}{(\\beta+1)^2}.\n          \\end{align*}\n\n          Since\n          \\begin{align*}\n            \\int_0^\\infty\\!\n            \\frac{1}{\\beta^\\alpha\\Gamma(\\alpha)}\\lambda^{\\alpha+2-1}e^{-\\lambda/\\beta}\\,\\d{\\lambda}\n             & =\\alpha(\\alpha+1)\\beta^2\\int_0^\\infty\\!\n            \\frac{1}{\\beta^{\\alpha+2}\\Gamma(\\alpha+2)}\\lambda^{\\alpha+2-1}e^{-\\lambda/\\beta}\\,\\d{\\lambda}\n            =\\alpha(\\alpha+1)\\beta^2,                  \\\\\n            \\int_0^\\infty\\!\n            \\frac{1}{\\beta^\\alpha\\Gamma(\\alpha)}\\lambda^{\\alpha+1-1}e^{-\\lambda/\\beta}\\,\\d{\\lambda}\n             & =\\alpha\\beta\\int_0^\\infty\\!\n            \\frac{1}{\\beta^{\\alpha+1}\\Gamma(\\alpha+1)}\\lambda^{\\alpha+2-1}e^{-\\lambda/\\beta}\\,\\d{\\lambda}\n            =\\alpha\\beta,\n          \\end{align*}\n          it follows that\n          \\begin{align*}\n            r(f,\\widehat{\\lambda})\n             & =\\int_0^\\infty\\!R(\\lambda,\\widehat{\\lambda})f(\\lambda)\\,\\d{\\lambda}                         \\\\\n             & =\\frac{\\alpha(\\alpha+1)\\beta^2+\\alpha\\beta^2(\\beta-2\\alpha)+\\alpha^2\\beta^2}{(\\beta+1)^2}   \\\\\n             & =\\frac{\\alpha\\beta^2}{\\beta+1}                                                            .\n          \\end{align*}\n    \\item Let $X\\sim N(\\theta,\\sigma^2)$, with $\\sigma^2$ known and the prior\n          $\\theta\\sim N(a,b^2)$. By Exercise 11.1, we have\n          \\[\n            \\theta\\,|\\,X\\sim N\\left(\\frac{b^2X+\\sigma^2a}{\\sigma^2+b^2},\n            \\frac{\\sigma^2b^2}{\\sigma^2+b^2} \\right),\n          \\]\n          and therefore the Bayes estimator is\n          \\[\n            \\thetahat=\\frac{b^2X+\\sigma^2a}{\\sigma^2+b^2}.\n          \\]\n\n          We have\n          \\[\n            \\mathbb{V}_\\theta(\\thetahat)\n            =\\mathbb{V}_\\theta\\left(\\frac{b^2X+\\sigma^2a}{\\sigma^2+b^2}\\right)\n            =\\left(\\frac{\\sigma b^2}{\\sigma^2+b^2}\\right)^2,\\text{ and}\n          \\]\n          \\[\n            \\mathbb{E}_\\theta(\\thetahat)\n            =\\mathbb{E}_\\theta\\left(\\frac{b^2X+\\sigma^2a}{\\sigma^2+b^2}\\right)\n            =\\frac{b^2\\theta+\\sigma^2a}{\\sigma^2+b^2},\n          \\]\n          and therefore\n          \\begin{align*}\n            R(\\theta,\\thetahat)\n             & =\\mathbb{V}_\\theta(\\thetahat)\n            +\\left(\\textsf{bias}_\\theta(\\thetahat)\\right)^2                                         \\\\\n             & =\\frac{\\sigma^2b^4+\\sigma^4a^2-2\\sigma^4a\\theta+\\sigma^4\\theta^2}{(\\sigma^2+b^2)^2}.\n          \\end{align*}\n\n          Since\n          \\[\n            \\int_{-\\infty}^\\infty\\!\n            \\frac{\\theta}{\\sqrt{2\\pi b^2}}\n            \\exp\\left\\{-\\frac{(\\theta-a)^2}{2b^2}\\right\\}\\,\\d{\\theta}\n            =0,\\text{ and }\n          \\]\n          \\begin{align*}\n             & \\int_{-\\infty}^\\infty\\!\n            \\frac{\\theta^2}{\\sqrt{2\\pi b^2}}\n            \\exp\\left\\{-\\frac{(\\theta-a)^2}{2b^2}\\right\\}\\,\\d{\\theta} \\\\\n             & \\quad = \\int_{-\\infty}^\\infty\\!\n            \\frac{(\\theta+a)^2}{\\sqrt{2\\pi b^2}}\n            \\exp\\left\\{-\\frac{\\theta^2}{2b^2}\\right\\}\\,\\d{\\theta}     \\\\\n             & \\quad =b\\int_{-\\infty}^\\infty\\!\n            \\frac{(bu+a)^2}{\\sqrt{2\\pi b^2}}\n            \\exp\\left\\{-\\frac{u^2b^2}{2b^2}\\right\\}\\,\\d{u}            \\\\\n             & \\quad =b^2\\int_{-\\infty}^\\infty\\!\n            \\frac{(u+a/b)^2}{\\sqrt{2\\pi}}\n            \\exp\\left\\{-\\frac{u^2}{2}\\right\\}\\,\\d{u}                  \\\\\n             & \\quad =b^2\\int_{-\\infty}^\\infty\\!\n            \\frac{u^2}{\\sqrt{2\\pi}}\n            \\exp\\left\\{-\\frac{u^2}{2}\\right\\}\\,\\d{u}\n            +a^2\\int_{-\\infty}^\\infty\\!\n            \\frac{1}{\\sqrt{2\\pi}}\n            \\exp\\left\\{-\\frac{u^2}{2}\\right\\}\\,\\d{u}                  \\\\\n             & \\quad=a^2+b^2,\n          \\end{align*}\n          it follows that\n          \\[\n            r(f,\\thetahat)\n            =\\int_{-\\infty}^\\infty\\!R(\\theta,\\thetahat)f(\\theta)\\,\\d{\\theta}\n            =\\frac{\\sigma^2(b^4+2\\sigma^2a^2+\\sigma^2b^2)}{(\\sigma^2+b^2)^2}.\n          \\]\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Recall that the risk of an estimator $\\thetahat$ with respect to a loss\n  function $L(\\theta,\\thetahat)$ is given by\n  \\[\n    R(\\theta,\\thetahat)=\\mathbb{E}_\\theta(L(\\theta,\\thetahat))\n  \\]\n  and that therefore if $L(\\theta,\\thetahat)=(\\theta-\\thetahat)^2/\\sigma^2$\n  and $L_\\text{SL}$ is the ordinary square loss we have\n  \\[\n    R(\\theta,\\thetahat)=\\mathbb{E}_\\theta(L(\\theta,\\thetahat))\n    =\\mathbb{E}_\\theta\\left(\\frac{1}{\\sigma^2}L_\\text{SL}(\\theta,\\thetahat)\\right)\n    =\\frac{1}{\\sigma^2}\\mathbb{E}_\\theta\\left(L_\\text{SL}(\\theta,\\thetahat)\\right),\n  \\]\n  which is a constant multiple of the squared error risk. Hence, since $\\Xbar$\n  is admissible under the squared error loss by Theorem 12.20, it is also\n  admissible under the loss $L$.\n\n  We have\n  \\begin{align*}\n    \\mathbb{E}_{\\theta}\\left(\\frac{(\\theta-\\Xbar)^2}{\\sigma^2}\\right)\n     & =\\frac{\\theta^2-2\\theta\\mathbb{E}_\\theta(\\Xbar)+\\mathbb{E}_\\theta(\\Xbar^2)}{\\sigma^2}    \\\\\n     & =\\frac{\\theta^2-2\\theta^2+\\mathbb{V}_\\theta(\\Xbar)+\\mathbb{E}_\\theta(\\Xbar)^2}{\\sigma^2} \\\\\n     & =\\frac{\\theta^2-2\\theta^2+\\sigma^2/n+\\theta^2}{\\sigma^2}                                 \\\\\n     & =\\frac{1}{n},\n  \\end{align*}\n  and therefore, by Theorem 12.21, since $\\Xbar$ has constant risk and is\n  admissible, it follows that it is also minimax.\n\\end{ex}\n\n\\begin{ex}\n  Recall that the Bayes estimator is the one that minimizes the posterior risk\n  $r(\\thetahat\\,|\\, x)$. We have\n  \\begin{align*}\n    r(\\thetahat\\,|\\, x)\n     & =\\sum_{i=1}^k L(\\theta_k,\\thetahat)f(\\theta_k\\,|\\,x)           \\\\\n     & =\\sum_{i=1}^k I_{\\{\\theta_k\\}^c}(\\thetahat)f(\\theta_k\\,|\\,x)   \\\\\n     & =\\sum_{i=1}^k (1-I_{\\{\\theta_k\\}}(\\thetahat))f(\\theta_k\\,|\\,x) \\\\\n     & =k-f(\\thetahat\\,|\\,x),\n  \\end{align*}\n  which is minimized by the choice of $\\thetahat$ that maximizes the posterior\n  likelihood. But this is precisely the posterior mode.\n\\end{ex}\n\n\\begin{ex}\n  Let $\\sigmahat^2=bS^2$ where $S^2$ is the sample variance. We then have\n  \\begin{align*}\n    R(\\sigma^2,\\sigmahat^2)\n     & =\\mathbb{E}_{\\sigma^2}\\left(\\frac{\\sigmahat^2}{\\sigma^2}-1-\\log\\left(\\frac{\\sigmahat^2}{\\sigma^2}\\right) \\right) \\\\\n     & =\\mathbb{E}_{\\sigma^2}\\left(\\frac{bS^2}{\\sigma^2}-1-\\log\\left(\\frac{bS^2}{\\sigma^2}\\right) \\right)               \\\\\n     & =\\mathbb{E}_{\\sigma^2}\\left(\\frac{bS^2}{\\sigma^2}-1-\\log(b)-\\log(S^2)+\\log(\\sigma^2) \\right)                     \\\\\n     & =\\frac{b\\mathbb{E}_{\\sigma^2}(S^2)}{\\sigma^2}-\\log(b)\n    -1+\\log(\\sigma^2)\n    -\\mathbb{E}_{\\sigma^2}(\\log(S^2))                                                                                   \\\\\n     & =b-\\log(b)\n    -1+\\log(\\sigma^2)\n    -\\mathbb{E}_{\\sigma^2}(\\log(S^2)).\n  \\end{align*}\n  Consider this expression as a function of $b$ and note that it goes to\n  infinity as $b$ goes to $0$ or $b$ goes to infinity. Differentiating with\n  respect to $b$ and setting the result equal to zero, we get $1-1/b=0$, which\n  implies that $b=1$ is the only critical point of the risk function. By the\n  second derivative test it follows that the absolute minimum value is obtained\n  at $b=1$.\n\\end{ex}\n\n\\begin{ex}\n  Let $\\phat(X)=0$. Note that this estimator has a constant risk of $1$. Let\n  $\\ptilde$ be another estimator and note that then\n  \\begin{align*}\n    R(p,\\ptilde)\n     & =\\mathbb{E}_p\\left[\\left(1-\\frac{\\ptilde}{p}\\right)^2\\right]         \\\\\n     & =\\mathbb{E}_p\\left[1-2\\frac{\\ptilde}{p}+\\frac{\\ptilde^2}{p^2}\\right] \\\\\n     & =1-2\\frac{\\mu}{p}+\\frac{b}{p^2},\n  \\end{align*}\n  where $\\mu=\\mathbb{E}_p\\left(\\ptilde\\right)$ and\n  $b=\\mathbb{E}_p\\left(\\ptilde^2\\right)$. Note that\n  \\[\n    b\n    =\\mathbb{E}_p\\left(\\ptilde^2\\right)\n    =\\var{\\ptilde}+\\mu^2,\n  \\]\n  and therefore unless $\\ptilde$ is the constant zero estimator $\\phat$, $b>0$.\n  Then\n  \\begin{align*}\n    1-2\\frac{\\mu}{p}+\\frac{b}{p^2}> 1\n    \\implies\n    2p\\mu-b<0\n    \\implies\n    p<\\frac{b}{2\\mu},\n    \\text{ or }\n    \\mu=0, b>0,\n  \\end{align*}\n  and therefore for any such choice of $\\ptilde$, there exists a $p\\in (0, 1)$\n  such that $R(p,\\phat)=1<R(p,\\ptilde)$. In particular, we may conclude that\n  $\\phat$ is minimax and that no other estimator is minimax since their maximum\n  risk is greater than $1$, the maximum risk of $\\phat$.\n\\end{ex}\n\n\\begin{ex}\n  \\inputminted{python}{../code/12-06.py}\n\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.545]{../images/12-06a}\n    \\caption{Comparison of the mean squared error of the maximum likelihood\n      estimator and the James-Stein estimator for different choices of $k$ under\n      a true mean $\\theta=(1,1,\\ldots,1)$.}\n  \\end{figure}\n\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.54]{../images/12-06b}\n    \\caption{Comparison of the mean squared error of the maximum likelihood\n      and James-Stein estimators for different choices of $k$ under\n      a true mean $\\theta=(1,2,\\ldots,k)$.}\n  \\end{figure}\n\\end{ex}", "meta": {"hexsha": "7834e1fca6e35833c8c3d277ea90b6bf067d5ee4", "size": 13027, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/ch12.tex", "max_stars_repo_name": "dtrifuno/all-of-stats-solutions", "max_stars_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/tex/ch12.tex", "max_issues_repo_name": "dtrifuno/all-of-stats-solutions", "max_issues_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tex/ch12.tex", "max_forks_repo_name": "dtrifuno/all-of-stats-solutions", "max_forks_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.1357615894, "max_line_length": 122, "alphanum_fraction": 0.492438781, "num_tokens": 4538, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7294614487500513}}
{"text": "\\lab{Numerical Derivatives}{Numerical Derivatives}\n\\label{lab:NumericalDerivatives}\n\\objective{Understand and implement finite difference approximations of the derivative in single and multiple dimensions. Evaluate the accuracy of these approximations.  Then use finite difference quotients to find edges in images via the Sobel filter.}\n\n\\section*{Derivative Approximations in One Dimension} % =======================\n\nThe derivative of a function $f$ at a point $x_0$ is\n\n\\begin{equation}\n\\label{eqn:deriv}\nf'(x_0) = \\lim_{h\\rightarrow 0} \\frac{f(x_0 + h)-f(x_0)}{h}.\n\\end{equation}\n%\nIn this lab, we will investigate one way a computer can calculate $f'(x_0)$.\n\n\\subsection*{Forward Difference Quotient} % -----------------------------------\n\nSuppose that in Equation \\eqref{eqn:deriv}, instead of taking a limit, we just pick a small value for $h$.\nThen we would expect $f'(x_0)$ to be close to the quantity\n%\n\\begin{equation}\\label{equ:forward_diff}\n\\frac{f(x_0 + h)-f(x_0)}{h}.\n\\end{equation}\n%\nThis quotient is called the \\emph{first order forward difference approximation} of the derivative.\nBecause $f'(x_0)$ is the limit of such quotients, we expect that when $h$ is small, this quotient is close to $f'(x_0)$.\nWe can use Taylor's formula to find just how close.\n\nBy Taylor's formula,\n\\[\nf(x_0+h) = f(x_0) + f'(x_0)h + R_2(h),\n\\]\nwhere $R_2(h) = \\left( \\int_0^1 (1-t) f''(x_0+th) dt \\right) h^2$.\n(This is called the \\emph{integral form} of the remainder for Taylor's Theorem; see Volume 1 Chapter 6). When we solve this equation for $f'(x_0)$, we get\n%\n\\begin{equation}\\label{equ:forward_diff_with_remainder}\nf'(x_0) = \\frac{f(x_0+h)-f(x_0)}{h} - \\frac{R_2(h)}{h}.\n\\end{equation}\n%\nThus, the error in using the first order forward difference quotient to approximate $f'(x_0)$ is\n\\[\n\\left | \\frac{R_2(h)}{h} \\right | \\leq |h| \\int_0^1 |1 - t||f''(x_0+th)|dt.\n\\]\nIf we assume $f''$ is continuous, then for any $\\delta$, set $M = \\sup_{x \\in (x_0-\\delta, x_0+\\delta)} f''(x)$. Then if $|h| < \\delta$, we have\n\\[\n\\left | \\frac{R_2(h)}{h} \\right | \\leq |h|\\int_0^1 M dt = M|h|  {\\in}  O(h).\n\\]\nTherefore, the error in using \\eqref{equ:forward_diff} to approximate $f'(x_0)$ grows like $h$.\n\n\\subsection*{Centered Difference Quotient} % ----------------------------------\n\nIn fact, we can approximate $f'(x_0)$ to the second order with another difference quotient, called the \\emph{centered difference quotient}.  We begin by trying to find the \\emph{backward difference quotient}.\nEvaluate Taylor's formula at $x_0-h$ to derive\n%\n\\begin{equation}\\label{equ:backwards_diff_with_remainder}\nf'(x_0) = \\frac{f(x_0)-f(x_0-h)}{h} + \\frac{R_2(-h)}{h}.\n\\end{equation}\n%\nThe first term on the right hand side of \\eqref{equ:backwards_diff_with_remainder} is called the \\emph{backward difference quotient.}\nThis quotient also approximates $f'(x_0)$ to first order, so it is not the quotient we are looking for.\nWhen we add \\eqref{equ:forward_diff_with_remainder} and \\eqref{equ:backwards_diff_with_remainder} and solve for $f'(x_0)$ (by dividing by 2), we get\n%\n\\begin{equation}\\label{equ:centered_diff}\nf'(x_0) = \\frac{\\frac{1}{2}f(x_0+h) - \\frac{1}{2}f(x_0-h)}{h} + \\frac{R_2(-h) - R_2(h)}{2h}\n\\end{equation}\n%\nThe \\emph{centered difference quotient} is the first term of the right hand side of \\eqref{equ:centered_diff}.\nLet us investigate the remainder term to see how accurate this approximation is.\nRecall from the proof of Taylor's theorem that $R_k = \\frac{f^{(k)}(x_0)}{k!}h^k + R_{k+1}$. Therefore,\n%\n\\begin{align*}\n\\frac{R_2(-h) - R_2(h)}{2h} &= \\frac{1}{2h}\\left(\\frac{f''(x_0)}{2}h^2 + R_{3}(-h) - \\frac{f''(x_0)}{2}h^2 - R_{3}(h) \\right)\\\\\n&= \\frac{1}{2h} ( R_3(-h)-R_3(h))\\\\\n&= \\frac{1}{2h}\\left(  \\left( \\int_0^1 \\frac{(1-t)^2}{2} f'''(x_0+th) dt \\right) h^3  -  \\left(\\int_0^1 \\frac{(1-t)^2}{2} f'''(x_0-th) dt \\right) h^3  \\right)\\\\\n&= \\left(  \\int_0^1 \\frac{(1-t)^2}{4}( f'''(x_0+th)-f'''(x_0-th)) \\right)h^2\\\\\n&{\\in}   O(h^2)\n\\end{align*}\n%\nonce we restrict $h$ to some $\\delta$-neighborhood of 0.\nSo the error in using the centered difference quotient to approximate $f'(x_0)$ grows like $h^2$, which is smaller than $h$ when $|h|<1$.\n\n\\subsection*{Accuracy of Approximations} % ------------------------------------\n\nLet us discuss what step size $h$ we should plug into the difference quotients to get the best approximation to $f'(x_0)$.\nSince $f'$ is defined as a limit as $h \\rightarrow 0$, you may think that it is best to choose $h$ as small as possible, but this is not the case.\nIn fact, dividing by very small numbers causes errors in floating point arithmetic.\nThis means that as we decrease $|h|$, the error between $f'(x_0)$ and the difference quotient will first decrease, but then increase when $|h|$ gets too small because of floating point arithmetic.\n\nHere is an example with the function $f(x) = e^x$. A quick way to write $f$ as a function in Python is with the \\li{lambda} keyword.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from matplotlib import pyplot as plt\n>>> f = lambda x: np.exp(x)\n\\end{lstlisting}\n\nIn general, the line \\li{f = lambda <params> : <expression>} is equivalent to defining a function \\li{f} that accepts the parameters \\li{params} and returns \\li{expression}.\n\nNext we fix a step size \\li{h} and define an approximation to the derivative of \\li{f} using the \\emph{centered difference quotient}.\n\n\\begin{lstlisting}\n>>> h = 1e-1\n>>> Df_app = lambda x: .5*(f(x+h)-f(x-h))/h\n\\end{lstlisting}\n\nFinally, we check the accuracy of this approximation at $x_0=1$ by computing the difference between \\li{Df_app(1)} and the actual derivative evaluated at 1.\n\n\\begin{lstlisting}\n# Since f(x) = e^x, the derivative of f(x) is f(x)\n>>> np.abs( f(1)-Df_app(1) )\n0.0045327354883726301\n\\end{lstlisting}\n\nWe note that our functions \\li{f} and \\li{Df_app} behave as expected when they are passed a NumPy array.\n\n\\begin{lstlisting}\n>>> h = np.array([1e-1, 1e-3, 1e-5, 1e-7, 1e-9, 1e-11])\n>>> np.abs( f(1)-Df_app(1) )\narray([  4.53273549e-03,   4.53046679e-07,   5.85869131e-11,\n         5.85873572e-11,   6.60275079e-09,   1.04294937e-05])\n\\end{lstlisting}\n\nThese results are summarized in Table \\ref{table:approx_errors}.\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|c|c|c|c|c|c|c|}\n    \\hline\n    $h$     & 1e-1 & 1e-3 & 1e-5  & 1e-7  & 1e-9 & 1e-11 \\\\ \\hline\n    Error   & 5e-3 & 5e-7 & 6e-11 & 6e-11 & 7e-9 & 1e-5  \\\\ \\hline\n\\end{tabular}\n\\caption{This table shows that it is best not to choose $h$ too small when you approximate derivatives with difference quotients.\nHere, ``Error'' equals the absolute value of $f'(1)-f_{app}(1)$ where $f(x) = e^x$ and $f_{app}$ is the centered difference approximation to $f'$.}\n\\label{table:approx_errors}\n\\end{center}\n\\end{table}\n\nThus, the optimal value of $h$ is one that is small, but not too small. A good choice is \\li{h = 1e-5}.\n\n\\begin{problem}\nWrite a function that accepts as input a callable function object \\li{f}, an array of points \\li{pts}, and\na keyword argument \\li{h} that defaults to \\li{1e-5}.\nReturn an array of the \\emph{centered difference quotients} of \\li{f} at each point in \\li{pts} with the specified value of \\li{h}.\n\\end{problem}\n\n\\begin{comment}\n\\begin{problem}\nWrite a function that accepts as input a callable function object \\li{f}, an array of points \\li{pts}, and\na keyword argument \\li{h} that defaults to \\li{1e-5}.  Return an array of the errors for the \\emph{centered difference quotients} at each point in \\li{pts} with the specified value of \\li{h}.\n\\end{problem}\n\\end{comment}\n\nYou may wonder if the forward or backward difference quotients are ever used, since the centered difference quotient is a more accurate approximation of the derivative.\nIn fact, there are some functions that in practice do not behave well under centered difference quotients.\nIn these cases, one must use the forward or backward difference quotient.\n\nFinally, we remark that forward, backward, and centered difference quotients can be used to approximate higher-order derivatives of $f$.\nHowever, taking derivatives is an \\emph{unstable} operation.\nThis means that taking a derivative can amplify the arithmetic error in your computation.\nFor this reason, difference quotients are not generally used  to approximate derivatives higher than second order.\n\n\\begin{comment}\nThe derivative of a function at a point is formally defined as\n\n\\begin{equation}\n\\label{eqn:deriv}\nf'(x) = \\lim_{h\\rightarrow 0} \\frac{f(x + h)-f(x)}{h}.\n\\end{equation}\n\nIn most real world applications we will be solving problems using computers. How does a computer calculate a limit? In short it can't. Computers can only approximate functions at specific points, and the notion of a limit graces infinity in a way that a computer never can.\n\nSo how can we use a computer to find the derivative of a function, particularly when we can't differentiate the function by hand? We use methods known as finite difference methods. For example suppose that in equation \\ref{eqn:deriv}, instead of taking a limit we just pick a particularly small value for h. Then we have\n\n\\begin{equation*}\nf'(x) \\approx \\frac{f(x + h)-f(x)}{h}\n\\end{equation*}\n\nThis is known as the first order forward difference approximation of the derivative.\n\nHow do we know the quality of this approximation? We can use Taylor's formula to find\n\n\\begin{equation*}\nf(x_0 + h) = f(x_0) + hf'(x_0) + h^2/2 f''(\\xi),\\hspace{5mm} \\xi \\in (x_0,x_0 + h)\n\\end{equation*}\n\nWhich can be also expressed as\n\n\\begin{equation*}\nf'(x_0) = \\frac{f(x_0 + h) - f(x)}{h} + \\frac{h}{2}f''(\\xi) = \\frac{f(x_0 + h) - f(x)}{h} + O(h)\n\\end{equation*}\n\nHere we use the big-O notation to denote that the errors are bounded by some constant multiplied by $h$.\n\nWe can use Taylor expansions to find approximations that have different big-O error bounds, up to any polynomial of arbitrary degree. Tables \\ref{Table:CDiff} and \\ref{Table:FDiff} offer the coefficients for centered and forward difference schemes.\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|c|c|c|c|c|c|c|c|c|}\n\\hline\nDerivative & Accuracy & -3 & -2 & -1 & 0 & 1 & 2 & 3 \\\\ \\hline\n & 2 & & & -1/2 & 0 & 1/2 & & \\\\ \\cline{2-9}\n 1 & 4 & & 1/12 & -2/3 &  0 & 2/3 & -1/12 & \\\\ \\cline{2-9}\n  & 6 & -1/60 & 3/20 & -3/4 & 0 & 3/4 & -3/20 & 1/60 \\\\ \\hline\n  & 2 & & & 1 & -2 & 1 & & \\\\ \\cline{2-9}\n 2 & 4 & & -1/12 & 4/3 &  -5/2 & 4/3 & -1/12 & \\\\ \\cline{2-9}\n  & 6 & 1/90 & -3/20 & 3/2 & -49/18 & 3/2 & -3/20 & 1/90 \\\\ \\hline\n\\end{tabular}\n\\caption{Centered Difference Coefficients}\n\\label{Table:CDiff}\n\\end{center}\n\\end{table}\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|c|c|c|c|c|c|c|}\n\\hline\nDerivative & Accuracy & 0 & 1 & 2 & 3 & 4 \\\\ \\hline\n & 1 & -1 & 1 &  & &  \\\\ \\cline{2-7}\n 1 & 2 & -3/2 & 2 & -1/2 & &  \\\\ \\cline{2-7}\n  & 3 & -11/6 & 3 & -3/2 & 1/3 &  \\\\ \\hline\n  & 1 & 1 & -2 & 1 &  & \\\\ \\cline{2-7}\n 2 & 2 & 2 & -5 & 4 &  -1 &  \\\\ \\cline{2-7}\n  & 3 & 35/12 & -26/3 & 19/2 & -14/3 & 11/12 \\\\ \\hline\n\\end{tabular}\n\\caption{Forward Difference Coefficients}\n\\label{Table:FDiff}\n\\end{center}\n\\end{table}\n\nThese tables can be used by simply summing the function evaluations (the number at the top represents how many times $h$ is added to $x$), and then dividing by $h^n$, where $n$ is the degree of the derivative.\n\nSo, for example, the centered difference estimate of the second derivative that is $O(h^4)$ is\n\\begin{equation*}\nf''(x) \\approx \\frac{-1/12(f(x-2h) + f(x+2h)) + 4/3(f(x-h) + f(x+h)) -5/2f(x)}{h^2}\n\\end{equation*}\n\nOr, the forward difference estimate for the first derivative that is $O(h^2)$ is\n\n\\begin{equation*}\nf'(x) \\approx \\frac{-3/2f(x) + 2f(x+h) - 1/2 f(x+2h)}{h}\n\\end{equation*}\n\nIt should be noted that we can convert a forward difference estimate to a backwards difference estimate by using $-h$. So the backwards difference estimate for the first derivative that is $O(h^2)$ is\n\n\\begin{equation*}\nf'(x) \\approx \\frac{3/2f(x) - 2f(x-h) + 1/2 f(x-2h)}{h}\n\\end{equation*}\n\nThere are two important observations that you should make about these tables. First, in order to get higher order approximations we need to evaluate the function at more points. This should not be surprising. Second, you should notice that centered difference formulas require less function evaluations to get higher order approximations. However, in certain applications it is not possible to use centered difference formulas, so the backwards and forwards formulas are still very applicable.\n\nOne important aspect of this method is selecting an appropriate $h$. The natural temptation is to pick a very very small value. However, this is not always advisable. Note the values in table \\ref{Table:FloatingError}, which approximates the derivative of $e(x)$ at $x = 1$:\n\n\\begin{table}[h!]\n\\begin{center}\n\\begin{tabular}{|cc|}\n\\hline\nh & Error  = $|f'(1)-f'_{app}(1)|$ \\\\ \\hline\n1e-1 & 4.5e-3 \\\\\n1e-3 & 4.5305e-7 \\\\\n1e-7 & 5.8587e-11 \\\\\n1e-10 & 6.7274e-7 \\\\ \\hline\n\\end{tabular}\n\\caption{Error in numerical derivative, using double precision floating point arithmetic}\n\\label{Table:FloatingError}\n\\end{center}\n\\end{table}\n\nAs you can see, the error actually increases as $h$ becomes very small. Why is this? Division by small numbers causes errors in floating point arithmetic. So, be aware that usually the optimal $h$ is of moderately small size. However, in the framework of double floating point arithmetic, this is usually less of a concern.\n\nAs a matter of reference, calculating numerical derivatives is an unstable operation. An unstable operation, informally, is one where errors are magnified by the operation. This usually is not an issue, but it's important to know that taking derivatives can amplify errors.\n\n\\begin{problem}\nWrite a function \\li{numDer1} that accepts as inputs: a callable function object \\li{f} and\na keyword argument \\li{h} giving the step size (default \\li{h = 1e-5}). Have the function return an array of the approximate 1st order derivative with accuracy 1 of \\li{f} at each of the points in \\li{pts}, using the centered  coefficients.\n\\end{problem}\n\n\\begin{problem}\nWrite a function \\li{numDer2} that accepts as inputs: a callable function object \\li{f} and\na keyword argument \\li{h} giving the step size (default \\li{h = 1e-5}). Have the function return an array of the approximate 2nd order derivative with accuracy 1 of \\li{f} at each of the points in \\li{pts}, using the centered  coefficients.\n\\end{problem}\n\n\n\\begin{problem}\nWrite a function \\li{numDer} that accepts as inputs: a callable function object \\li{f}, an\narray of numbers \\li{pts}, a keyword argument \\li{mode} (taking one of the values\n\\li{'centered'}, \\li{'forward'}, or \\li{'backward'}), a keyword argument \\li{d} (taking one of\nthe values \\li{1} or \\li{2}), a keyword argument \\li{o} (taking an integer value in\n\\li{[2, 4, 6]} if \\li{mode = 'centered'}, and otherwise taking a value in \\li{[1, 2, 3]}), and\na keyword argument \\li{h} giving the step size. The default settings of the keyword\narguments should be \\li{mode = 'centered', d = 1, o = 2, h = 1e-5}.\n\nHave the function return an array of the approximate derivative of order \\li{d} with accuracy\n \\li{o} of \\li{f} at each of the points in \\li{pts}, using the coefficients indicated by \\li{mode}.\n\\end{problem}\n\n\nWe note that higher order approximations of the derivative can be derived using the Taylor series and Lagrange polynomials, but generally higher-order approximations are not practically useful as they can often be ill-conditioned.\n\nFor any numerical approximation method, it is important to be able to empirically calculate\nthe order of convergence. We will do so for our numerical derivative approximation.\nFor an $m$-th order approximation of the first derivative, we have that the error is in\n$O(h^m)$, so that\n$$\nerr(h) \\approx Ch^m\n$$\nfor some constant $C$.\nHence, taking the log of both sides, we obtain\n$$\n\\log err(h) \\approx \\log C + m\\log h,\n$$\nwhich means that if we plot the log of the errors against the log of the $h$ values, we\nought to see a linear relationship whose slope gives the rate of convergence.\n\nWe do this in python as follows (The \\li{numDer} function in this code can use any of the coefficients from \\ref{Table:CDiff} and \\ref{Table:FDiff}):\n\n\\begin{lstlisting}\n# assume that the function numDer has already been written\nimport numpy as np\nfrom matplotlib import pyplot as plt\n\n# approximate the derivative of cosine at x = 3\n# create a callable function object\ndef myCosine(x):\n    return np.cos(x)\nf = myCosine\n\n# calculate the actual derivative\nactual = -np.sin(3.0)\n\n# initialize array of h values at which to calculate the error\nhvals = np.linspace(1e-5, 1e-1)\nerr1 = np.zeros(hvals.shape)\nerr2 = np.zeros(hvals.shape)\n\n# calculate the errors for order 1 and order 2 approximations for the forward coeffiects\nfor i in xrange(len(hvals)):\n    err1[i] = np.abs(actual - numDer(f, np.array([3.0]), mode = 'forward', h = hvals[i], o=1))\n    err2[i] = np.abs(actual - numDer(f, np.array([3.0]), mode = 'forward', h = hvals[i], o=2))\n\n# plot the log of the h values against the log of the errors\nplt.subplot(121)\nplt.loglog(hvals, err1)\nplt.ylim((1e-11, 1e-1))\nplt.subplot(122)\nplt.loglog(hvals, err2)\nplt.ylim((1e-11, 1e-1))\nplt.show()\n\\end{lstlisting}\n\nThe generated plot is shown in Figure \\ref{fig:convergence}. Note that the slope\nof the line in the left plot is about 1, and the slope of the line in the right\nplot is about 2. Further, the log of the errors for the order 2 approximations\nare much lower than the log of the errors of the order 1 approximations.\n\n\\begin{figure}[t]\n    \\includegraphics[width=0.8\\textwidth]{figures/convergence.pdf}\n    \\caption{Convergence plots for our numerical derivative approximations.\n    The left plot shows the convergence for order 1 approximations.\n    The right plot shows the convergence for order 2 approximations.}\n    \\label{fig:convergence}\n\\end{figure}\n\n\n\\begin{problem}\nExplore the convergence properties for different orders of approximation,\nand for the second derivative as well. You may need to adjust your $h$\nvalues, as they may be too small for some of the calculations.\n\\end{problem}\n\n\\end{comment}\n\n\\section*{Derivative Approximations in Multiple Dimensions} % =================\n\nFinite difference methods can also be used to calculate derivatives in higher dimensions.\nRecall that the Jacobian of a function $f:\\mathbb{R}^n \\rightarrow \\mathbb{R}^m$ at a point $x_0 \\in \\mathbb{R}^n$ is the $m \\times n$ matrix $J = (J_{ij})$ defined component-wise by\n\\begin{equation*}\nJ_{ij} = \\frac{\\partial f_i}{\\partial x_j}(x_0).\n\\end{equation*}\nFor example, the Jacobian for a function $f:\\mathbb{R}^3 \\rightarrow \\mathbb{R}^2$ is defined by\n\n\\[\nJ = \\begin{pmatrix}\n\\frac{\\partial f}{\\partial x_1}&\\frac{\\partial f}{\\partial x_2}&\\frac{\\partial f}{\\partial x_3}\n\\end{pmatrix}\n= \\begin{pmatrix}\n\\frac{\\partial f_1}{\\partial x_1}&\\frac{\\partial f_1}{\\partial x_2}&\\frac{\\partial f_1}{\\partial x_3}\\\\\n\\frac{\\partial f_2}{\\partial x_1}&\\frac{\\partial f_2}{\\partial x_2}&\\frac{\\partial f_2}{\\partial x_3}\n\\end{pmatrix}.\n\\]\n\nThe Jacobian is useful in many applications.  For example, the Jacobian can be used to find zeros of functions in multiple variables.\n\nThe forward difference quotient for approximating a partial derivative is\n\\begin{equation*}\n\\frac{\\partial f}{\\partial x_j} (x_0) \\approx \\frac{f(x_0+h e_j)-f(x_0)}{h},\n\\end{equation*}\nwhere $e_j$ is the $j^{th}$ standard basis vector.\nSimilarly, the centered difference approximation is\n\\begin{equation*}\n\\frac{\\partial f}{\\partial x_j} (x_0) \\approx \\frac{\\frac{1}{2}f(x_0+h e_j)-\\frac{1}{2}f(x_0-h e_j)}{h}.\n\\end{equation*}\n\n\\begin{problem}\n\\leavevmode\nWrite a function that accepts\n\\begin{enumerate}\n\\item a function handle \\li{f},\n\\item an integer \\li{n} that is the dimension of the domain of \\li{f},\n\\item an integer \\li{m} that is the dimension of the range of \\li{f},\n\\item an \\li{1 x n}-dimensional NumPy array \\li{pt} representing a point in $\\mathbb{R}^n$, and\n\\item a keyword argument \\li{h} that defaults to \\li{1e-5}.\n\\end{enumerate}\nReturn the approximate Jacobian matrix of \\li{f} at \\li{pt} using the centered difference quotient.\n\\end{problem}\n\\begin{problem}\n\\item Let $f: \\mathbb{R}^2 \\to \\mathbb{R}^2$ be defined by\n%\n\\begin{equation*}\nf(x, y) =\n\\left[\\begin{array}{c}\ne^{x} \\sin(y) + y^3 \\\\\n3y - \\cos(x)\n\\end{array}\\right]\n\\end{equation*}\n%\nFind the error between your Jacobian function and the analytically computed derivative on the square $[-1,1] \\times [-1,1]$ using ten thousand grid points (100 per side).\nYou may apply your Jacobian function to the points one at a time using a double \\li{for} loop.  Once you get the error matrix for a given point, calculate the Frobenius norm of this matrix (\\li{la.norm} defaults to the Frobenius norm).  This norm will be your total error for that point.\nWhat is the maximum error of your Jacobian function over all points in the square?\n\nHint: The following code defines the function\n$f(x,y) = \\left[\\begin{array}{c} x^2 \\\\ x+y \\end{array}\\right]$.\n\n\\begin{lstlisting}\n# f accepts a length-2 NumPy array\n>>> f = lambda x: np.array([x[0]**2, x[0]+x[1]])\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{comment}\nGiven a function from $\\mathbb{R}^n \\to \\mathbb{R}$, sometimes the mixed partial derivatives are useful. In particular, the mixed partials will be useful when we study optimization in Volume 2. This information is contained in the Hessian matrix, which is defined as\n\n\\begin{equation*}\nH_{ij} = \\frac{\\partial^2 f}{\\partial x_i \\partial x_j}\n\\end{equation*}\n\nWe can use the following formula to approximate mixed partial derivatives\n\\small\n\\begin{equation*}\n\\frac{\\partial^2 f}{\\partial x_i \\partial x_j} = \\frac{f(x + (e_i + e_j)h) - f(x + (e_i-e_j)h) -f(x + (e_j-e_i)h) + f(x - (e_i + e_j)h)}{4h^2}\n\\end{equation*}\n\\normalsize\n\n\\begin{problem}\nWrite a Python function that numerically calculates the Hessian of a given function.\nThe function should be named \\li{Hessian}, and should accept as inputs a function handle,\nan integer giving the dimension of the domain of the function, a NumPy\narray giving the point at which to approximate the Hessian, and an optional argument giving the\nstep size.\nReturn the approximated Hessian matrix at the given point.\n\nTest it on the following function\n\\begin{equation*}\nf(x,y) = (1-x)^2 + 100(y-x^2)^2\n\\end{equation*}\nThis function is known as the Rosenbrock Banana function, or Rosenbrock's Valley. It is a common test function for optimization algorithms because it is non-convex and the global minimum is hard to find from certain starting points. A graph is shown in figure \\ref{Fig:Rosenbrock}. Compare the output of your function with the analytic solution on the region $[-2,2] \\times [0,2]$, using ten thousand points. What is the maximum error of your function?\n\\end{problem}\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width = \\textwidth]{figures/Rosenbrock.pdf}\n\\caption{The Rosenbrock Banana Function, a common test function in optimization algorithms}\n\\label{Fig:Rosenbrock}\n\\end{center}\n\\end{figure}\n\\end{comment}\n\n\\section*{Image Filters} % ====================================================\n\nRecall that a computer stores an image as a 2-D array of pixel values (i.e., a matrix of intensities).\nAn image filter is a function that transforms an image by operating on it locally.\nThat is, to compute the $ij^{th}$ pixel value in the new image, an image filter uses only the pixels in a small neighborhood around the $ij^{th}$ pixel in the original image.\n\nIn this lab, we will use a filter derived from the gradient of an image to find edges in an image.\n\n\\subsection*{Convolutions} % --------------------------------------------------\n\nOne example of an image filter is to \\emph{convolve} an image with a filter matrix.\nA filter matrix is a matrix whose height and width are relatively small odd numbers.\nIf the filter matrix is\n\\[\nF = \\begin{pmatrix}\nf_{-1,-1}&f_{-1,0}&f_{-1,1}\\\\\nf_{0,-1}&f_{0,0}&f_{0,1}\\\\\nf_{1,-1}&f_{1,0}&f_{1,1}\n\\end{pmatrix},\n\\]\nthen the convolution of an image $A$ with $F$ is $A \\ast F = (C_{ij})$ where\n\\begin{equation}\\label{equ:convolve}\nC_{ij} = \\sum_{k=-1}^1 \\sum_{\\ell=-1}^1 f_{k\\ell}A_{i+k,j+\\ell}.\n\\end{equation}\nSay $A$ is an $m \\times n$ matrix. Here, we take $A_{ij}=0$ when $i \\not \\in \\{1, \\ldots m\\}$ or $j \\not \\in \\{1, \\ldots, n\\}$.\nThe value of $C_{ij}$ is a linear combination of the nearby pixel values, with coefficients given by $F$ (see Figure \\ref{fig:convolution}).\nIn fact, $C_{ij}$ equals the Frobenius inner product of $F$ with the $3 \\times 3$ submatrix of $A$ centered at $ij$.\n\n\\begin{figure}\n\\centering\n\\begin{tikzpicture}\n\\node[draw, minimum width=12cm, minimum height=\n    7cm, ultra thick](outer_rec)[]{};\n\\node[draw, minimum width=10cm, minimum height=\n    5cm, ultra thick, fill=black!10!](inner_rec)[]{};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick, fill=black!30!](square1)at(-4.75,2.25){\\textbullet};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick,fill=black!30!](square2)at(-1.75,-.75){\\textbullet};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick, fill=black!30!](square3)at(4.75,.75){\\textbullet};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick, fill=black!30!](square4)at(3.25,-1.25){\\textbullet};\n\\draw[step=.5, ultra thin, color=black!50!](-6,-3.5)grid(6,3.5);\n\n%redraw borders\n\\node[draw, minimum width=10cm, minimum height=\n    5cm, ultra thick, ][]{};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick]at(-4.75,2.25){};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick]at(-1.75,-.75){};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick]at(4.75,.75){};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick]at(3.25,-1.25){};\n\\end{tikzpicture}\n\\caption{This diagram illustrates how to convolve an image with a filter.\nThe light grey rectangle represents the original image $A$, and the dark grey squares are the filter $F$.\nThe larger rectangle is the image padded with zeros; i.e., all pixel values in the outer white band are 0.\nTo compute the entry of the convolution matrix $C$ located at a black dot, take the inner product of $F$ with the submatrix of the padded image centered at the dot.}\n\\label{fig:convolution}\n\\end{figure}\n\n\\subsubsection*{Implementation in NumPy} % - - - - - - - - - - - - - - - - - -\n\nLet us write a function that convolves an image with a filter.\nYou can test this function on the image \\li{cameraman.jpg}, which appears in Figure \\ref{fig:cameraman}.\nThe following code loads this image and plots it with matplotlib.\n\n\\begin{lstlisting}\n>>> image = plt.imread('cameraman.jpg')\n>>> plt.imshow(image, cmap = 'gray')\n>>> plt.show()\n\\end{lstlisting}\n\nHere is the function definition and some setup.\n\n\\begin{lstlisting}\n1. def Filter(image, F):\n2.     m, n = image.shape\n3.     h, k = F.shape\n\\end{lstlisting}\n\nTo convolve \\li{image} with the filter \\li{F}, we must first \\emph{pad} the array \\li{image} with zeros around the edges.\nThis is because in \\eqref{equ:convolve}, entries $A_{ij}$ are set to zero when $i$ or $j$ is out of bounds.\nWe do this by creating a larger array of zeros, and then making the interior part of the array equal to the original image (see Figure \\ref{fig:convolution}).\n\nFor example, if the filter is a $3 \\times 3$ matrix, then the following code will pad the matrix with the appropriate number of zeros.\n\n\\begin{lstlisting}\n # Create a larger matrix of zeros\nimage_pad = np.zeros((m+2, n+2))\n# Make the interior of image_pad equal to the original image\nimage_pad[1:1+m, 1:1+n] = image\n\\end{lstlisting}\n\nWe want to do this in general in our function.  Note that the number of zeros we need to pad our array depends on the size of the filter \\li{F}.\n\n\\begin{lstlisting}\n5.    image_pad = # Create an array of zeros of the appropriate size\n6.   # Make the interior of image_pad equal to image\n\\end{lstlisting}\n\nFinally, we iterate through the image to compute each entry of the convolution matrix.\n\n\\begin{lstlisting}\n7.    C = np.zeros(image.shape)\n8.    for i in range(m):\n9.        for j in range(n):\n10.            C[i,j] = # Compute C[i, j]\n\\end{lstlisting}\n\n\\subsubsection*{Gaussian Blur} % - - - - - - - - - - - - - - - - - - - - - - -\n\nA \\emph{Gaussian blur} is an image filter that operates on an image by convolving with the matrix\n\\[\nG = \\frac{1}{159}\\begin{pmatrix}\n2&4&5&4&2\\\\\n4&9&12&9&4\\\\\n5&12&15&12&5\\\\\n4&9&12&9&4\\\\\n2&4&5&4&2\n\\end{pmatrix}.\n\\]\n\nBlurring an image can remove ``noise'', or random variation that is the visual analog of static in a radio signal (and equally undesirable).\n\n\\begin{problem}\\label{prob:filter}\n\\leavevmode\nFinish writing the function \\li{Filter} by filling in lines 5, 6, and 10.  Hint: Note in \\ref{equ:convolve}, $C_{ij}$ was calculated by summing from -1 to 1.  This is only the case if the filter \\li{F} is $3 \\times 3$. A slight modification is needed in the general case.  Test your function on the image \\li{cameraman.jpg} using the Gaussian Blur. The result is in Figure \\ref{fig:cameraman_blur}.\n\\end{problem}\n\n% TODO: make pictures that aren't pdfs\n\\begin{figure}\n\\centering\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{figures/cameraman.jpg}\n\\caption{Unfiltered image.}\n\\label{fig:cameraman}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{figures/cameramanBlur.pdf}\n\\caption{Image after Gaussian blur is applied.}\n\\label{fig:cameraman_blur}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{figures/edges.pdf}\n\\caption{Image after the Sobel filter is applied.}\n\\label{fig:cameraman_edges}\n\\end{subfigure}\n\\caption{Here is an example of a Gaussian blur and the Sobel filter applied to an image.\nThis photo, known as ``cameraman,'' is a standard test image in image processing.\nA database of such images can be downloaded from \\url{http://www.imageprocessingplace.com/root_files_V3/image_databases.htm}.}\n\\label{fig:cameraman1}\n\\end{figure}\n\n\\subsection*{Edge Detection} % ------------------------------------------------\n\nAutomatic detection of edges in an image can be used to segment or sharpen the image.\nWe will find edges with the Sobel filter, which computes the gradient of the image at each pixel.\nThe magnitude of the gradient tells us the rate of change of the pixel values, and so large magnitudes should\ncorrespond to edges within the image.\nThe Sobel filter is not a convolution, although it does use convolutions.\n\nWe can think of an image as a function from a $2 \\times 2$ grid of points to $\\mathbb{R}$.\nThe image maps a pixel location to an intensity.\nIt does not make sense to define the derivative of this function as a limit because the domain is discrete---a step size $h$ cannot take on arbitrarily small values.\nInstead, we \\emph{define} the derivative to be the centered difference quotient of the previous section.\nThat is, we define the derivative in the $x$-direction at the $ij^{th}$ pixel to be\n\\[\n\\frac{1}{2}A_{i+1, j} - \\frac{1}{2}A_{i-1, j}.\n\\]\n\nWe can use a convolution to create a matrix $A_x$ whose $ij^{th}$ entry is the derivative of $A$ at the $ij^{th}$ entry, in the $x$-direction.\nIn fact, $A_x = A \\ast S$, where\n\\[\nS = \\frac{1}{8}\n\\left[\\begin{array}{ccc}\n-1 & 0 & 1\\\\\n-2 & 0 & 2\\\\\n-1 & 0 & 1\n\\end{array}\\right].\n\\]\n\nNote that this convolution takes a weighted average of the $x$-derivatives at $(i, j)$, $(i, j+1)$, and $(i, j-1)$.\nThe derivative at $(i, j)$ is weighted by 2.\nUsing a weighted average instead of just the derivative at $(i, j)$ makes the derivative less affected by noise.\n\nNow we can define the Sobel filter.\nA Sobel filter applied to an image $A$ results in an array $B = (B_{ij})$ of 0's and 1's, where the 1's trace out the edges in the image.\nBy definition,\n\\[\nB_{ij} = \\left\\{\n     \\begin{array}{ll}\n       1 & \\text{if}\\; \\;\\|\\nabla A(ij)\\|_2 > M \\\\\n       0 & \\text{otherwise}.\n     \\end{array}\n   \\right.\n\\]\nHere, $\\nabla A(ij) = ((A \\ast S)_{ij}, (A\\ast S^T)_{ij})$ is the gradient of $A$ at the $ij^{th}$ pixel.\nThe constant $M$ should be ``sufficiently large'' enough to pick out those pixels with the largest gradient (i.e., those pixels that are part of an edge).\nA good choice for $M$ is 4 times the average value of $\\|\\nabla A(ij)\\|_2$ over the whole image $A$.\n\nWhen the Sobel filter is applied to \\li{cameraman.jpg}, we get the image in Figure \\ref{fig:cameraman_edges}.\nHere, the 1's in $B$ were mapped to ``white'' and the 0's were mapped to ``black.''\n\n\\begin{problem}\nWrite a function that accepts an image as input and applies the Sobel filter to the image.  Test your function on \\li{cameraman.jpg}.  Hint: If you want to find the average of a matrix \\li{A}, use the function \\li{A.mean()}.\n\\end{problem}\n", "meta": {"hexsha": "75445aa660b33cfce8f3f3152d5c2f374cabe8bb", "size": 32719, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol1B/Differentiation/Differentiation.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol1B/Differentiation/Differentiation.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol1B/Differentiation/Differentiation.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 47.4876632801, "max_line_length": 493, "alphanum_fraction": 0.7059506709, "num_tokens": 10225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.894789468908171, "lm_q1q2_score": 0.7294614461839622}}
{"text": "\\chapter{Proof of Lemma~\\ref{lem:measuresets}}\\label{app:measuresets}\n\\begin{proof}\nLet\n\\begin{equation}\nf_\\nsamps (\\param) = \\sum_{\\iparam=1}^{\\nsamps} \\frac{\\eta_\\nsamps (\\VV^{(\\iparam)}) }{\\mu (\\VV^{(\\iparam)})} \\Chi_{\\VV^{(\\iparam)}} (\\param).\n\\end{equation}\nThen, for any $A\\in\\BB_\\pspace$, define\n\\begin{equation}\n\\eta (A) = \\int_A f_\\nsamps (\\param) \\, d\\mu.\n\\end{equation}\nWe verify that $\\eta$ is a probability measure on $(\\pspace, \\BB_\\pspace)$ and that $\\eta(A) = \\eta_\\nsamps(A) \\; \\forall \\; A\\in\\BB_{\\pspace, \\nsamps}$ below:\n\\begin{itemize}\n\\item[(i)][Positive]\nLet $A\\in \\BB_{\\pspace}$.\n\\begin{equation*}\n\\begin{split}\n\\eta (A) &= \\int_A f_\\nsamps (\\param) \\, d\\mu \\\\\n&=  \\int \\Chi_A \\sum_{\\iparam=1}^{\\nsamps} \\frac{\\eta_\\nsamps (\\VV^{(\\iparam)}) }{\\mu (\\VV^{(\\iparam)})} \\Chi_{\\VV^{(\\iparam)}} (\\param) \\, d\\mu \\\\\n&= \\sum_{\\iparam=1}^{\\nsamps} \\left ( \\frac{\\eta_\\nsamps (\\VV^{(\\iparam)}) }{\\mu (\\VV^{(\\iparam)})} \\int \\Chi_{A\\cap\\VV^{(\\iparam)}} (\\param) \\, d\\mu \\right ) \\\\\n&= \\sum_{\\iparam=1}^{\\nsamps} \\left ( \\frac{\\eta_\\nsamps (\\VV^{(\\iparam)}) }{\\mu (\\VV^{(\\iparam)})} \\mu\\left (A\\cap\\VV^{(\\iparam)}\\right ) \\right ) \\geq 0\n\\end{split}\n\\end{equation*}\n\n\\item[(ii)][Definite]\n\\begin{equation*}\n\\eta (\\nullset) = \\int_\\nullset f_\\nsamps (\\param) \\, d\\mu =\\int \\Chi_\\nullset f_\\nsamps (\\param) \\, d\\mu = \\mu(\\nullset) = 0\n\\end{equation*}\n\n\\item[(iii)][Countably Additive]\nLet $\\set{A_k}_{k=1}^{\\infty} \\subset \\BB_{\\pspace}$.\n\\begin{equation*}\n\\begin{split}\n\\eta (\\cup_k A_k) &= \\int_{\\cup_k A_k} f_\\nsamps (\\param) \\, d\\mu\n= \\int \\Chi_{\\cup_k A_k} f_\\nsamps (\\param) \\, d\\mu \\\\\n&= \\int \\left( \\sum_k \\Chi_{A_k} \\right ) f_\\nsamps (\\param) \\, d\\mu\n=   \\sum_k \\int \\Chi_{A_k} f_\\nsamps (\\param) \\, d\\mu \\\\\n&=   \\sum_k \\int_{A_k} f_\\nsamps (\\param) \\, d\\mu = \\sum_k \\eta(A_k)\n\\end{split}\n\\end{equation*}\n\n\n\\noindent Finally, let $A\\in\\BB_{\\pspace, \\nsamps}\\subset \\BB_\\pspace$.\nThen there exists some $\\iparam^* \\in \\set{1,2, \\cdots, \\nsamps}$ such that $\\VV^{(\\iparam^*)} = A$.\nWe have that\n\\begin{equation*}\n\\begin{split}\n\\eta (A) &= \\int_A f_\\nsamps (\\param) \\, d\\mu\n=  \\int \\sum_{\\iparam=1}^{\\nsamps} \\left ( \\frac{\\eta_\\nsamps (\\VV^{(\\iparam)}) }{\\mu (\\VV^{(\\iparam)})} \\Chi_{\\VV^{(\\iparam)}}\\right ) \\Chi_{\\VV^{(\\iparam^*)}} \\, d\\mu \\\\\n&= \\int \\frac{\\eta_\\nsamps (\\VV^{(\\iparam^*)}) }{\\mu (\\VV^{(\\iparam^*)})} \\Chi_{\\VV^{(\\iparam^*)}} \\, d\\mu\n= \\frac{\\eta_\\nsamps (\\VV^{(\\iparam^*)}) }{\\mu (\\VV^{(\\iparam^*)})} \\mu (\\VV^{(\\iparam^*)}) \\\\\n&= \\eta_\\nsamps (\\VV^{(\\iparam^*)}) = \\eta_\\nsamps (A).\n\\end{split}\n\\end{equation*}\n\n\\end{itemize}\n\\end{proof}\n", "meta": {"hexsha": "39df720d9ff7c119c3c90bf2f4fe9a4bd67ff545", "size": 2576, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "set-based/measuresets.tex", "max_stars_repo_name": "mathematicalmichael/thesis", "max_stars_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-24T08:05:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-28T20:34:29.000Z", "max_issues_repo_path": "set-based/measuresets.tex", "max_issues_repo_name": "mathematicalmichael/thesis", "max_issues_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 59, "max_issues_repo_issues_event_min_datetime": "2019-12-27T23:15:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T17:52:57.000Z", "max_forks_repo_path": "set-based/measuresets.tex", "max_forks_repo_name": "mathematicalmichael/thesis", "max_forks_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.1929824561, "max_line_length": 171, "alphanum_fraction": 0.5877329193, "num_tokens": 1102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969136, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7294614456262629}}
{"text": "\\lab{Conditioning and Stability}{Conditioning and Stability}\n\\objective{Explore the condition of problems and the stability of algorithms.}\n\\label{lab:conditioning_stability}\n\n\n%\\begin{equation*}\n%\\mathlarger{ \\mathlarger{ \\mathlarger{f:X \\rightarrow Y}}}\n%\\end{equation*}\n%\\begin{center} vs. \\end{center}\n%\\begin{equation*}\n%\\mathlarger{ \\mathlarger{ \\mathlarger{\\hat{f}:\\hat{X} \\rightarrow \\hat{Y}}}}\n%\\end{equation*}\n\n%\\begin{eqnarray}\n%\\mathlarger{\\mathlarger{\\mathlarger{f:X \\rightarrow Y}}}\\\\ \\mathlarger{\\mathlarger{\\mathlarger{ f:\\hat{X} \\rightarrow \\hat{Y} }}}\\\\\n%\\mathlarger{\\mathlarger{\\mathlarger{ \\hat{f}:X \\rightarrow Y }}}%\\\\\n%%\\mathlarger{\\mathlarger{\\mathlarger{ \\hat{f}:\\hat{X} \\rightarrow \\hat{Y} }}}\n% \\end{eqnarray}\n%\n\nThe \\emph{condition number} of a function measures how sensitive that function is to changes in the input.\nOn the other hand, the \\emph{stability} of an algorithm measures how well that algorithm computes the value of a function from exact input.\n\n\\section*{Condition Number of a Function}\n\nThe (absolute) condition number of a function $f: \\mathbb{R}^m \\rightarrow \\mathbb{R}^n$ is\n \\begin{equation}\\label{equ:abs_cond}\nJ(\\x) = \\lim_{\\delta \\rightarrow 0} \\sup_{\\norm{\\delta \\x} \\leq \\delta} { \\frac{\\norm{\\delta f}}{\\norm{\\delta \\x}} }\n\\end{equation}\nwhere $\\delta f = f(\\x+\\delta\\x)-f(\\x)$.\nIn other words, the condition number of $f$ is (the limit of) the change in output over the change of input.\n\nSimilarly, the \\emph{relative condition number} of $f$ is the limit of the relative change in output over the relative change in input, i.e.,\n\\begin{equation}\\label{equ:rel_cond}\n\\kappa(\\x) = \\lim_{\\delta \\rightarrow 0} \\sup_{\\norm{\\delta \\x} \\leq \\delta} \\left({ \\frac{\\norm{\\delta f}}{\\norm{f(\\x)}} } \\middle/ { \\frac{\\norm{\\delta \\x}}{\\norm{\\x}} }\\right).\n\\end{equation}\nIn fact,\n\\[\n\\kappa(\\x) = \\frac{\\norm{\\x}}{\\norm{f(\\x)}} J(\\x)\n\\]\nA function is \\emph{ill-conditioned} if its condition number is large.\n\n\nSmall changes to the input of an ill-conditioned function produce large changes in output.\nIn applications, it is important to know if a function is ill-conditioned because there is usually some error in the parameters passed to the function.\n\n\\subsection*{Example: the Wilkinson Polynomial}\n\nLet $f:\\mathbb{C}^{n+1} \\rightarrow \\mathbb{C}^n$ be the function that sends $(a_1, \\ldots, a_{m+1})$ to the roots of $a_1x^n+a_2x^{n-1}+\\ldots+a_nx+a_{n+1}$.\nIn other words, this function describes the problem of finding the roots of a polynomial.\nUnfortunately, root finding is extremely ill-conditioned.\n\nA classic example is the Wilkinson polynomial\n\\[\nw(x) = \\prod_{r=1}^{20}(x-r) = x^{20}-210x^{19}+20615x^{18}-\\ldots.\n\\]\nWe will use NumPy to explore the condition number of $f$ at the coefficients of $w(x)$.\nThese coefficients are contained in the NumPy array \\li{w_coeffs} below.\nWe also create an array \\li{w_roots} containing the roots of $w(x)$.\\footnote{\nIt is possible to create this array in NumPy by expanding the product $\\prod_{r=1}^{20}(x-r)$, for example using \\li{np.poly()}.\nHowever, this approach is \\emph{unstable} and will give you the wrong coefficients!}\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import linalg as la\n>>> w_coeffs = np.array([1, -210, 20615, -1256850, 53327946, -1672280820,\n                    40171771630, -756111184500, 11310276995381,\n                    -135585182899530, 1307535010540395,\n                    -10142299865511450, 63030812099294896,\n                    -311333643161390640, 1206647803780373360,\n                    -3599979517947607200, 8037811822645051776,\n                    -12870931245150988800, 13803759753640704000,\n                    -8752948036761600000, 2432902008176640000])\n>>> w_roots = np.arange(1, 21)\n\\end{lstlisting}\n\nNext we perturb the polynomial by changing the $x^{19}$-coefficient from $-210$ to $-210.0000001$.\n\\begin{lstlisting}\n>>> perturb = np.zeros(21)\n>>> perturb[1]=1e-7\n>>> perturbed_coeffs = w_coeffs - perturb\n\\end{lstlisting}\n\nNow we find the roots of the perturbed polynomial.\nThe function \\li{np.poly1d()} creates a polynomial object using the array passed to it as coefficients, and \\li{np.roots()} finds the roots of a polynomial.\n\\begin{lstlisting}\n>>> perturbed_roots = np.roots(np.poly1d(perturbed_coeffs))\n\\end{lstlisting}\nThe new roots are plotted with the original roots in Figure \\ref{fig:wilkinsonpolynomial}.\n\nFinally we compute an approximation to the condition number.\nWe sort the roots before we compare them to ensure that they are in the same order.\n\\begin{lstlisting}\n>>> w_roots = np.sort(w_roots)\n>>> perturbed_roots = np.sort(perturbed_roots)\n>>> la.norm(perturbed_roots-w_roots)/la.norm(perturb)\n68214100.15878984\n\\end{lstlisting}\nThus, the condition number of this problem is something like $10^7$.\n\nWhen we try to estimate the relative condition number, NumPy will not compute the 2-norm of \\li{w_coeffs} because it is so large.\nNumPy will not compute the square root of a very large number.\nOne easy solution is to use a different norm that does not require the square root.\n\\begin{lstlisting}\n>>> # Estimate the absolute condition number in the infinity norm\n>>> k = la.norm(perturbed_roots-w_roots, np.inf)/la.norm(perturb, np.inf)\n>>> k\n28260604.34345689\n>>> # Estimate the relative condition number in the infinity norm\n>>> k*la.norm(w_coeffs, np.inf)/la.norm(w_roots, np.inf)\n1.9505129642488696e+25\n\\end{lstlisting}\nAs you can see, the order of magnitude of the absolute condition number is the same as when we computed it with the 2-norm.\nThe relative condition number for this problem is approximately $10^{24}$.\n\n\nThere are some caveats to this example.\nFirst, when we compute the quotients in \\eqref{equ:abs_cond} and \\eqref{equ:rel_cond} for a fixed $\\delta \\x$, we are only \\emph{approximating} the condition number.\nThe actual condition number is a limit of such quotients.\nWe hope that when $||\\delta \\x||$ is small, a random quotient is at least the same order of magnitude as the limit, but we have no way to be sure.\n\nSecond, this example assumes that NumPy's root-finding algorithm is \\emph{stable}, so that the difference between the roots of \\li{w_coeffs} and \\li{perturbed_coeffs} is due to the difference in coefficients, and not the difference in roots.\nWe will return to this issue in the next section.\n\n\\begin{figure}\n\\centering\n\\includegraphics[height=2.25in]{figures/wilk2.png}\n\\caption{In these images, blue is associated with $w(x)$ and red is associated with $w(x)$ perturbed by 1e-7 in the $x^{19}$-coefficient. On the left is a plot of the two polynomials. On the right is a graphical representation of the roots of the polynomials. The blue dots are the roots of $w(x)$. The red x's are the roots of the perturbed polynomial. }\n\\label{fig:wilkinsonpolynomial}\n\\end{figure}\n\n\\begin{problem}\\label{prob:wilk}\nWrite a Python function that investigates the condition number of the Wilkinson polynomial by doing the following.\n\\begin{enumerate}\n\\item Perform this experiment:\n\n\\begin{quote}\nRandomly perturb $w(x)$ by replacing each coefficient $a_i$ with $a_i*r_i$, where $r_i$ is drawn from a normal distribution centered at 1 with standard deviation $1e-10$.\n\\end{quote}\n\nPlot the results of 100 such experiments in a single graphic, along with the roots of the unperturbed polynomial $w(x)$. The plot should look something like Figure \\ref{fig:wilkinsonpolynomial_many}. This exercise reproduces Figure 12.1 on p. 93 of \\emph{Numerical Linear Algebra} by Lloyd N. Trefethen and David Bau III.\n\\item Using the final experiment only, estimate the relative and absolute condition number (in any norm you prefer). Print these numbers to the screen.\n\\end{enumerate}\n\n\\begin{figure}[H]\n\\includegraphics[height=3in]{figures/wilkinsonpolynomial_many.pdf}\n\\caption{Sample result of Problem \\ref{prob:wilk}.\nThe blue dots are the roots of $w(x)$ and the black dots are roots of random perturbations.\nThis figure replicates Figure 12.1 on p. 93 of \\emph{Numerical Linear Algebra} by Lloyd N. Trefethen and David Bau III.}\n\\label{fig:wilkinsonpolynomial_many}\n\\end{figure}\n\n\\end{problem}\n\n%Notes on Problem 1:\n% - Make something to copy-paste with the polynomial coefficients\n% - You MUST copy paste the exact coefficients!!! Multiplying out the polynomial is not stable!!!\n% - Also \"compute\" the roots of the wilkinson poly. They are close but not quite right. The difference is not visible on the graph. See that is probably useful.\n\n% In introductory discussion, compute the condition number of the problem. Explain why we use the infinity norm.\n\n\\subsection*{Example: Calculating Eigenvalues}\n\nLet $f:\\mathbb{C}^{n^2} \\rightarrow \\mathbb{C}^n$ be the function that sends an $n \\times n$ matrix to its $n$ eigenvalues.\nThis problem is well-conditioned for symmetric matrices, but can be extremely ill-conditioned for non-symmetric matrices.\n\nLet us use NumPy to calculate the condition number of the eigenvalue problem at the identity matrix.\nFirst we check that the eigenvalue solver is stable here.\n\\begin{lstlisting}\n>>> M = np.array([[1,0],[0,1]])\n>>> eigs = la.eig(M)[0]\n>>> eigs\narray([ 1.+0.j,  1.+0.j])\n\\end{lstlisting}\nNow we perturb $M$ by adding a matrix drawn from a random normal distribution over the complex numbers.\nWe calculate the eigenvalues of the perturbed matrix.\n\\begin{lstlisting}\n>>> perturb = np.random.normal(0, 1e-10, M.shape) + np.random.normal(0,1e-10, M.shape)*1j\n>>> eigsp = la.eig(M+perturb)[0]\n\\end{lstlisting}\nFinally we use this data to approximate the condition number.\n\\begin{lstlisting}\n>>> k = la.norm(eigs-eigsp)/la.norm(perturb)\t# Absolute condition number\n0.62957336119253127\n>>> k*la.norm(M)/la.norm(eigs)\t# Relative condition number\n0.62957336119253127\n\\end{lstlisting}\nThe absolute and relative condition number are the same because \\li{la.norm(M)} and \\li{la.norm(eigs)} are both $\\sqrt{2}$.\n\n\n\\begin{problem}[Optional]\\label{prob:eigenvalue}\nLet us explore the condition number of the eigenvalue problem.\n\\begin{enumerate}\n\\item \\begin{enumerate}\n\\item Write the following function.\n\\begin{lstlisting}\ndef eig_condit(M):\n    '''\n    Approximate the condition number of the eigenvalue problem at M.\n\n    INPUT:\n    M  - A 2-D NumPy array, representing a matrix.\n\n    RETURN:\n    A tuple containing approximations to the absolute and relative condition numbers of the eigenvalue problem at M.\n    '''\n\\end{lstlisting}\n\\item Find an example of a $2\\times2$ matrix with a very large condition number.\n(Hint: Look at matrices whose off-diagonal entries are very different in magnitude.)\n\\item What is the order of magnitude of the condition number of a symmetric $2\\times 2$ matrix?\n\\end{enumerate}\n\\item Write the following function.\n\\begin{lstlisting}\ndef plot_eig_condit(x0=-100, x1=100, y0=-100, y1=100, res=10):\n    '''\n    Plot the condition number of the eigenvalue problem on [x0, x1]x[y0,y1].\n\n    Specifically, use plt.pcolormesh to plot the relative condition number of the eigenvalue problem at [[1,x],[y,1]] on this domain.\n    The variable `res' should be the number of sample points taken along each axis, for a total of `res'**2 points in the plot.\n    '''\n\\end{lstlisting}\n\\item Call your function for \\li{res}=10, 50, 100, 200 and 400 (output for $res=200$ is pictured below). Recall that matplotlib scales the colorbar of the output to fit the largest and smallest output values.\nWhat can you conclude about the condition number of the eigenvalue problem at a ``random'' $2\\times2$ matrix?\n\\end{enumerate}\n\\begin{figure}[H]\n\\includegraphics[height=3in]{figures/eigenvalue_conditioning.png}\n\\caption{Output of \\li{plot_eig_condit(res=200)}.}\n\\end{figure}\n\\end{problem}\n\n%\\begin{example}[Condition of a System of Equations]\n%Consider the system of equations\n%\\[ Ax = b \\]\n%for an $n \\times n$ matrix $A$ and $n \\times 1$ vectors $x$ and $b$. If we hold $A$ fixed, consider the problem of computing $b$ with respect to small changes in $x$. Alternatively, hold $A$ fixed and consider the problem of computing $x = A^{-1} b$ with respect to small changes in $b$. Finally, we may hold $b$ fixed and consider the problem of computing $x = A^{-1}b$ with respect to small changes in $A$.\n%\n%It turns out that each of these problems has the \\emph{same} relative condition number. This number is\n%\\[\n%\\mathcal{K} (A) = \\norm{A}_2 \\norm{A^{-1}}_2\n%\\]\n%\n%This is called the \\emph{condition number of $A$}.\n%The condition number of a matrix can be computed using \\li{numpy.linalg.cond()}.\n%\n%Notice that the condition number of a matrix cannot be less that $1$.\n%It is almost always best to work with orthonormal matrices (or operations that can be mathematically represented by orthonormal matrices).\n%Since orthonormal matrices have a norm of $1$, as do their inverses, these transformations have the best possible condition number.\n%The low condition number of orthonormal matrices is one of the primary reasons that Householder reflections and Givens rotations are used in so many algorithms.\n%\\end{example}\n\n\\section*{Stability of an Algorithm}\n\nThe stability of an algorithm is measured by the error in its output.\nSuppose we have some algorithm to compute $f: \\mathbb{R}^m \\rightarrow \\mathbb{R}^n$.\nLet $\\tilde f(\\x)$ represent the value computed by the algorithm at $\\x$.\nThen the \\emph{forward error} of $f$ at $\\x$ is $||f(\\x)-\\tilde f(\\x)||$, and the \\emph{relative forward error} of $f$ at $\\x$ is\n\\[\n\\frac{||f(\\x)-\\tilde f(\\x)||}{||f(\\x)||}.\n\\]\nAn algorithm is \\emph{stable} if this relative forward error is small.\n\nAs an example, let us examine the stability of NumPy's root finding algorithm that we used to investigate the Wilkinson polynomial.\nWe know the exact roots of $w(x)$, and we can also compute these roots using NumPy's \\li{np.roots()} function.\n\n\\begin{lstlisting}\n>>> roots = np.arange(1,21)\n>>> w_coeffs = np.array([1, -210, 20615, -1256850, 53327946, -1672280820,\n                    40171771630, -756111184500, 11310276995381,\n                    -135585182899530, 1307535010540395,\n                    -10142299865511450, 63030812099294896,\n                    -311333643161390640, 1206647803780373360,\n                    -3599979517947607200, 8037811822645051776,\n                    -12870931245150988800, 13803759753640704000,\n                    -8752948036761600000, 2432902008176640000])\n>>> computed_roots = np.roots(np.poly1d(w_coeffs))\n\\end{lstlisting}\n\nWe sort the roots to ensure they are in the same order, then compute the absolute and relative forward error.\n\n\\begin{lstlisting}\n>>> roots = np.sort(roots)\n>>> computed_roots = np.sort(computed_roots)\n>>> la.norm(roots-computed_roots)\t# Forward error\n0.020612653126379665\n>>> la.norm(roots-computed_roots)/la.norm(roots)\t# Relative forward error\n0.00038476268486104599\n\\end{lstlisting}\n\nThis analysis gives us hope that questions of stability did not interfere too much with our experiments in Problem \\ref{prob:wilk}.\n\n\\subsection*{Catastrophic Cancellation}\n\\emph{Catastrophic Cancellation} is a term for when a computer takes the difference of two very similar numbers, and the result is stored with a small number of significant digits.\nBecause of the way computers store and perform arithmetic on numbers, future computations can amplify a catastrophic cancellation into a huge error.\n\nYou are at risk for catastrophic cancellation whenever you subtract floats or large integers that are very close to each other.\nYou can avoid the problem either by rewriting your program to not use subtraction, or by increasing the number of significant digits that your computer tracks.\n\nHere is an example of catastrophic cancellation.\nSuppose we wish to compute $\\sqrt{a}-\\sqrt{b}$. We can either do this subtraction directly or perform the equivalent division\n\\[\n\\sqrt{a}-\\sqrt{b} = (\\sqrt{a}-\\sqrt{b})\\frac{\\sqrt{a}+\\sqrt{b}}{\\sqrt{a}+\\sqrt{b}} = \\frac{a-b}{\\sqrt{a}+\\sqrt{b}}.\n\\]\n\nLet us perform this computation both ways in NumPy with $a=10^{20}+1$ and $b=10^{20}$.\n\\begin{lstlisting}\n>>> np.sqrt(1e20+1)-np.sqrt(1e20)\n0.0\n>>> 1/(np.sqrt(1e20+1)+np.sqrt(1e20))\n5.0000000000000002e-11\n\\end{lstlisting}\nSince $a \\neq b$, clearly $\\sqrt{a}-\\sqrt{b}$ should be nonzero.\n\n\n\\begin{problem}\nLet $I(n) = \\int_0^1 x^n e^{x - 1} dx$.\n\\begin{enumerate}\n\\item Prove that $0 \\leq I(n) \\leq 1$ for all $n$.\n\\item It can be shown that for $n>1$,\n\\[\nI(n) = \\left(-1\\right)^{n} !n + \\left(-1\\right)^{n + 1} \\frac{n!}{e}\n\\]\nwhere $!n$ is the \\emph{subfactorial} of $n$.\nUse this formula to write the following function.\n\\begin{lstlisting}\ndef integral(n):\n    '''Return I(n).'''\n\\end{lstlisting}\nHint: The subfactorial function can be imported from SymPy with the line \\li{from sympy import subfactorial}.\n\\item The actual values of $I(n)$ for many values of $n$ are listed in the table below.\nUse your function \\li{integral()} to compute $I(n)$ for these same values of $n$, and create a table comparing the data.\nHow can you explain what is happening?\n\\end{enumerate}\n\n\\begin{center}\n\\begin{tabular}{|l|l|}\n\\hline\n$n$  & Actual value of $I(n)$ \\\\\n\\hline\n$1$  & $0.367879441171$ \\\\\n$5$  & $0.145532940573$ \\\\\n$10$ & $0.0838770701034$ \\\\\n$15$ & $0.0590175408793$ \\\\\n$20$ & $0.0455448840758$ \\\\\n$25$ & $0.0370862144237$ \\\\\n$30$ & $0.0312796739322$ \\\\\n$35$ & $0.0270462894091$ \\\\\n$40$& $0.023822728669$ \\\\\n$45$& $0.0212860390856$ \\\\\n$50$ & $0.0192377544343$ \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\end{problem}\n\n%\\begin{table}\n%\\centering\n%\\begin{tabular}{|l|l|l|}\n%\\hline\n%Integrand & Computed Value & Actual Value \\\\\n%\\hline\n%$x^{1}e^{x}$: & $0.367879441171$ & $0.367879441171$ \\\\\n%$x^{5}e^{x}$: & $0.145532940573$ & $0.145532940573$ \\\\\n%$x^{10}e^{x}$: & $0.0838770701084$ & $0.0838770701034$ \\\\\n%$x^{15}e^{x}$: & $0.0590209960938$ & $0.0590175408793$ \\\\\n%$x^{20}e^{x}$: & $0.0$ & $0.0455448840758$ \\\\\n%$x^{25}e^{x}$: & $1073741824.0$ & $0.0370862144237$ \\\\\n%$x^{30}e^{x}$: & $-1.80143985095 \\cdot 10^{16}$ & $0.0312796739322$ \\\\\n%$x^{35}e^{x}$: & $6.04462909807 \\cdot 10^{23}$ & $0.0270462894091$ \\\\\n%$x^{40}e^{x}$: & $0.0$ & $0.023822728669$ \\\\\n%$x^{45}e^{x}$: & $0.0$ & $0.0212860390856$ \\\\\n%$x^{50}e^{x}$: & $1.46150163733 \\cdot 10^{48}$ & $0.0192377544343$ \\\\\n%\\hline\n%\\end{tabular}\n%\\caption{Inaccuracy of values computed using an unstable algorithm.}\n%\\label{table:unstable_computation}\n%\\end{table}\n\n% For this section to be meaningful, it needs more explanation of when each algorithm is stable.\n\\begin{comment}\nThe algorithms that we have studied to solve linear systems have different levels of stability.\nLU decomposition (with pivoting) is usually good enough, but there are some pathological examples of matrices that cause it to break down.\nQR decomposition (with pivoting) is generally considered to be a better option than the LU decomposition.\nSolving a linear system using the SVD is even more stable than the QR decomposition.\n(Pivoting is a modification that is commonly made to the LU decomposition and QR decomposition algorithms we have discussed in earlier labs to make them more stable.)\nUnfortunately, in this case, the algorithms that are more stable are also slower.\nThe LU decomposition is used by \\li{scipy.linalg.solve()}.\nThe SVD is used by \\li{scipy.linalg.lstsq()}.\nHere is some code that uses the QR decomposition of a matrix $A$ to solve the linear system $A x = b$ for $x$.\nIt uses a lower-level function included in SciPy to perform the back substitution required to solve this system.\n\\begin{lstlisting}\nfrom scipy import linalg as la\nfrom scipy.linalg.flapack import dtrtrs\ndef qr_solve(A, b):\n    Q, R = la.qr(A)\n    return dtrtrs(R.T, Q.T.dot(b), lower=1, trans=1)[0]\n\\end{lstlisting}\nA solution using a pivoted QR decomposition would be better, but this will be good enough for demonstration purposes.\n\nThe following are routines that generate matrices designed to show the relative benefits of each of these algorithms.\n\\begin{lstlisting}\nfrom numpy.random import rand\n\ndef bad_arr_1(n):\n    \"\"\" Construct a specific pathological example\n    that breaks LU decomposition. These examples\n    are very rare, but they do exist.\n    Strictly speaking, the condition number\n    for this matrix isn't terribly bad. \"\"\"\n    A = - np.ones((n, n))\n    A[:,:-1] = np.tril(A[:,:-1])\n    np.fill_diagonal(A, 1)\n    A[:,-1] = 1\n    return A\n\ndef bad_arr_2(n, peturbation = 1E-8):\n    \"\"\" Construct another matrix that is nearly singular\n    by computing A.dot(A.T) for a matrix A that is\n    not square and then adding some small changes\n    so it is not exactly singular. \"\"\"\n    A = rand(n, n // 2)\n    return A.dot(A.T) + peturbation * rand(n, n)\n\\end{lstlisting}\n\\end{example}\n\n\\begin{problem}\nFor each of the array creation routines above, plot the error $\\norm{\\text{solve}\\left(A, A b\\right) - b}$ of each of the methods mentioned above for solving a linear system.\nUse a log-scaled $y$-axis.\nWhat do you observe?\n\\end{problem}\n\\end{comment}\n%\\subsection*{Stable vs. Backward Stable Algorithms}\n\n%\\subsection*{Table}\n%\n%\\begin{table}[h]\n%\\begin{tabular}{|l|l|l|}\n%\\hline \\textbf{Well-Conditioned} & \\textbf{Ill-Conditioned} & \\textbf{Systems of Equations} \\\\\n%{\\parbox{0.3\\textwidth}{\\raggedleft\n%            \\begin{itemize}[leftmargin=*]\n%                \\item finding eigenvalues of a symmetric (or normal) matrix\n%                \\item calculating $e^x$ for relatively small values of $x$\n%                \\item calculating $\\ln(x)$ for $x$ not close to $1$\n%            \\end{itemize} }}           &\n%\n%{\\parbox{0.3\\textwidth}{\\raggedleft\n%            \\begin{itemize}[leftmargin=*]\n%                \\item calculating $x_1 - x_2$ when $x_1 \\approx x_2$\n%                \\item computing roots of a polynomial, given the coefficients\n%                \\item computing eigenvalues of a non-symmetric matrix\n%            \\end{itemize} }}              &\n%\n%{\\parbox{0.3\\textwidth}{\n%            \\begin{itemize}[leftmargin=*]\n%                 \\item relative condition number is \\[ \\mathcal{K} = ||A|| ||A^{-1}|| \\]\n%            \\end{itemize} }}   \\\\ \\hline\n%\\end{tabular}\n%\\end{table}\n%\n%\n%\\begin{table}[h]\n%\\begin{tabular}{|l|l|}\n%\\hline \\textbf{Stable} & \\textbf{Unstable} \\\\\n%{\\parbox{0.45\\textwidth}{\\raggedleft\n%            \\begin{itemize}[leftmargin=*]\n%                \\item finding eigenvalues of a symmetric (or normal) matrix\n%                \\item calculating $e^x$ for relatively small values of $x$\n%                \\item calculating $\\ln(x)$ for $x$ not close to $1$\n%            \\end{itemize} }}           &\n%\n%{\\parbox{0.45\\textwidth}{\\raggedleft\n%            \\begin{itemize}[leftmargin=*]\n%                \\item calculating $x_1 - x_2$ when $x_1 \\approx x_2$\n%                \\item computing roots of a polynomial, given the coefficients\n%                \\item computing eigenvalues of a non-symmetric matrix\n%            \\end{itemize} }}    \\\\ \\hline\n%\\end{tabular}\n%\\end{table}\n%\n", "meta": {"hexsha": "1375230f15986e9129305a7cdd87cf47cd655bb7", "size": 22772, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol1B/ConditioningStability/ConditioningStability.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol1B/ConditioningStability/ConditioningStability.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol1B/ConditioningStability/ConditioningStability.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 47.640167364, "max_line_length": 409, "alphanum_fraction": 0.7106095205, "num_tokens": 6639, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.8872045966995027, "lm_q1q2_score": 0.7294499836864106}}
{"text": "% ------------------------------------------------------------------\n\\chapter{Implementation details}\\label{s:impl}\n% ------------------------------------------------------------------\n\nThis chapter contains calculations and details.\n\n% ------------------------------------------------------------------\n\\section{Convolution}\\label{s:impl-convolution}\n% ------------------------------------------------------------------\n\nIt is often convenient to express the convolution operation in matrix form. To this end, let $\\phi(\\bx)$ the \\verb!im2row! operator, extracting all $W' \\times H'$ patches from the map $\\bx$ and storing them as rows of a $(H''W'') \\times (H'W'D)$ matrix. Formally, this operator is given by:\n\\[\n   [\\phi(\\bx)]_{pq} \\underset{(i,j,d)=t(p,q)}{=} x_{ijd}\n\\]\nwhere the index mapping $(i,j,d) = t(p,q)$ is\n\\[\n i = i''+i'-1, \\quad\n j = j''+j'-1, \\quad\n p = i'' + H'' (j''-1), \\quad\n q = i' + H'(j'-1) + H'W' (d-1).\n\\]\nIt is also useful to define the ``transposed'' operator \\verb!row2im!:\n\\[\n   [\\phi^*(M)]_{ijd}\n   =\n   \\sum_{(p,q) \\in t^{-1}(i,j,d)}\n   M_{pq}.\n\\]\nNote that $\\phi$ and $\\phi^*$ are linear operators. Both can be expressed by a matrix $H\\in\\real^{(H''W''H'W'D) \\times(HWD)}$ such that\n\\[\n  \\vv(\\phi(\\bx)) = H \\vv(\\bx), \\qquad \n  \\vv(\\phi^*(M)) = H^\\top \\vv(M).\n\\]\nHence we obtain the following expression for the vectorized output (see~\\cite{kinghorn96integrals}):\n\\[\n \\vv\\by = \n \\vv\\left(\\phi(\\bx) F\\right)\n =\n \\begin{cases}\n (I \\otimes \\phi(\\bx)) \\vv F, & \\text{or, equivalently,} \\\\\n (F^\\top \\otimes I) \\vv \\phi(\\bx),\n \\end{cases}\n\\]\nwhere $F\\in\\mathbb{R}^{(H'W'D)\\times K}$ is the matrix obtained by reshaping the array $\\bff$ and $I$ is an identity matrix of suitable dimensions. This allows obtaining the following formulas for the derivatives:\n\\[\n\\frac{dz}{d(\\vv F)^\\top}\n=\n\\frac{dz}{d(\\vv\\by)^\\top}\n(I \\otimes \\phi(\\bx))\n= \\vv\\left[ \n\\phi(\\bx)^\\top \n\\frac{dz}{dY}\n\\right]^\\top\n\\]\nwhere $Y\\in\\real^{(H''W'')\\times K}$ is the matrix obtained by reshaping the array $\\by$. Likewise:\n\\[\n\\frac{dz}{d(\\vv \\bx)^\\top}\n=\n\\frac{dz}{d(\\vv\\by)^\\top}\n(F^\\top \\otimes I)\n\\frac{d\\vv \\phi(\\bx)}{d(\\vv \\bx)^\\top}\n=\n\\vv\\left[ \n\\frac{dz}{dY}\nF^\\top\n\\right]^\\top\nH\n\\]\nIn summary, after reshaping these terms we obtain the formulas:\n\\[\n\\boxed{\n\\vv\\by = \n \\vv\\left(\\phi(\\bx) F\\right),\n\\qquad\n\\frac{dz}{dF}\n=\n\\phi(\\bx)^\\top\\frac{d z}{d Y},\n\\qquad\n\\frac{d z}{d X}\n=\n\\phi^*\\left(\n\\frac{d z}{d Y}F^\\top\n\\right)\n}\n\\]\nwhere $X\\in\\real^{(H'W')\\times D}$ is the matrix obtained by reshaping $\\bx$. Notably, these expressions are used to implement the convolutional operator; while this may seem inefficient, it is instead a fast approach when the number of filters is large and it allows leveraging fast BLAS and GPU BLAS implementations.\n\n% ------------------------------------------------------------------\n\\section{Convolution transpose}\\label{s:impl-convolution-transpose}\n% ------------------------------------------------------------------\n\nIn order to understand the definition of convolution transpose, let $\\by$ obtained from $\\bx$ by the convolution operator as defined in Section~\\ref{s:convolution} (including padding and downsampling).  Since this is a linear operation, it can be rewritten as $\\vv \\by = M \\vv\\bx$ for a suitable matrix $M$; convolution transpose computes instead $\\vv \\bx = M^\\top \\vv \\by$.  While this is simple to describe in term of matrices, what happens in term of indexes is tricky. In order to derive a formula for the convolution transpose, start from standard convolution (for a 1D signal):\n\\[\n   y_{i''} = \\sum_{i'=1}^{H'} f_{i'} x_{S (i''-1) + i' - P_h^-}, \n   \\quad\n    1 \\leq i'' \\leq 1 + \\left\\lfloor \\frac{H - H' + P_h^- + P_h^+}{S} \\right\\rfloor,\n\\]\nwhere $S$ is the downsampling factor, $P_h^-$ and $P_h^+$ the padding, $H$ the length of the input signal, $\\bx$ and $H'$ the length of the filter $\\bff$. Due to padding, the index of the input data $\\bx$ may exceed the range $[1,H]$; we implicitly assume that the signal is zero padded outside this range.\n\nIn order to derive an expression of the convolution transpose,  we make use of the identity $\\vv \\by^\\top (M \\vv \\bx) = (\\vv \\by^\\top M) \\vv\\bx = \\vv\\bx^\\top (M^\\top \\vv\\by)$. Expanding this in formulas:\n\\begin{align*}\n\\sum_{i''=1}^b y_{i''} \n\\sum_{i'=1}^{W'} f_{i'} x_{S (i''-1) + i'  -P_h^-}\n&=\n\\sum_{i''=-\\infty}^{+\\infty}\n\\sum_{i'=-\\infty}^{+\\infty} \ny_{i''}\\ f_{i'}\\ x_{S (i''-1) + i'  -P_h^-}\n\\\\\n&=\n\\sum_{i''=-\\infty}^{+\\infty}\n\\sum_{k=-\\infty}^{+\\infty} \ny_{i''}\\ f_{k-S(i'' -1) + P_h^-}\\ x_{k}\n\\\\\n&=\n\\sum_{i''=-\\infty}^{+\\infty}\n\\sum_{k=-\\infty}^{+\\infty} \ny_{i''}%\n\\ %\nf_{%\n(k-1+ P_h^-) \\bmod S +\nS \\left(1 -i''  + \\left\\lfloor \\frac{k-1+ P_h^-}{S} \\right\\rfloor\\right)+1\n}\\ x_{k}\n\\\\\n&=\n\\sum_{k=-\\infty}^{+\\infty} \nx_{k}\n\\sum_{q=-\\infty}^{+\\infty}\ny_{\\left\\lfloor \\frac{k-1+ P_h^-}{S} \\right\\rfloor + 2 - q}\n\\ %\nf_{(k-1+ P_h^-)\\bmod S +S(q - 1)+1}.\n\\end{align*}\nSummation ranges have been extended to infinity by assuming that all signals are zero padded as needed. In order to recover such ranges, note that $k \\in [1,H]$ (since this is the range of elements of $\\bx$ involved in the original convolution). Furthermore, $q\\geq 1$ is the minimum value of $q$ for which the filter $\\bff$ is non zero; likewise, $q\\leq \\lfloor (H'-1)/2\\rfloor +1$ is a fairly tight upper bound on the maximum value (although, depending on $k$, there could be an element less). Hence\n\\begin{equation}\\label{e:convt-step}\n x_k = \n \\sum_{q=1}^{1 + \\lfloor \\frac{H'-1}{S} \\rfloor}\ny_{\\left\\lfloor \\frac{k-1+ P_h^-}{S} \\right\\rfloor + 2 - q}\\ %\nf_{(k-1+ P_h^-)\\bmod S +S(q - 1)+1},\n\\qquad k=1,\\dots, H.\n\\end{equation}\nHere $H$, $H'$ and $H''$ are related by:\n\\[\nH'' = 1+ \\left\\lfloor \\frac{H - H' + P_h^- + P_h^+}{S} \\right\\rfloor.\n\\]\nIf $H''$ is now given as input, it is not possible to recover $H$ uniquely; instead, all the following values are possible\n\\[\n   S_h (H''-1) +H' -  P_h^- - P_h^+ \\leq H < S_h H'' +H' -  P_h^- - P_h^+.\n\\]\nWe use the tighter definition and set $H =  S_h (H''-1) +H' -  P_h^- - P_h^+$.\nNote that the summation extrema in \\eqref{e:convt-step} can be refined slightly to account for the finite size of $\\by$ and $\\bw$:\n\\begin{multline*}\n\\max\\left\\{\n1, \n\\left\\lfloor \\frac{k-1 + P_h^-}{S} \\right\\rfloor + 2 - H''\n\\right\\}\n\\leq q \\\\\n\\leq\n1 +\\min\\left\\{\n\\left\\lfloor \\frac{H'-1-(k-1+ P_h^-)\\bmod S}{S} \\right\\rfloor, \n\\left\\lfloor \\frac{k-1 + P_h^-}{S} \\right\\rfloor\n\\right\\}.\n\\end{multline*}\n\n% ------------------------------------------------------------------\n\\section{Spatial pooling}\\label{s:impl-pooling}\n% ------------------------------------------------------------------\n\nSince max pooling simply select for each output element an input element, the relation can be expressed in matrix form as\n$\n    \\vv\\by = S(\\bx) \\vv \\bx\n$\nfor a suitable selector matrix $S(\\bx)\\in\\{0,1\\}^{(H''W''D) \\times (HWD)}$. The derivatives can the be written as:\n$\n\\frac{d z}{d (\\vv \\bx)^\\top}\n=\n\\frac{d z}{d (\\vv \\by)^\\top}\nS(\\bx),\n$\nfor all but a null set of points, where the operator is not differentiable (this usually does not pose problems in optimization by stochastic gradient). For max-pooling, similar relations exists with two differences: $S$ does not depend on the input $\\bx$ and it is not binary, in order to account for the normalization factors. In summary, we have the expressions:\n\\begin{equation}\\label{e:max-mat}\n\\boxed{\n\\vv\\by = S(\\bx) \\vv \\bx,\n\\qquad\n\\frac{d z}{d \\vv \\bx}\n=\nS(\\bx)^\\top\n\\frac{d z}{d \\vv \\by}.\n}\n\\end{equation}\n\n\n\n% ------------------------------------------------------------------\n\\section{Activation functions}\\label{s:impl-activation}\n% ------------------------------------------------------------------\n\n% ------------------------------------------------------------------\n\\subsection{ReLU}\\label{s:impl-relu}\n% ------------------------------------------------------------------\n\nThe ReLU operator can be expressed in matrix notation as\n\\[\n\\vv\\by = \\diag\\bfs \\vv \\bx,\n\\qquad\n\\frac{d z}{d \\vv \\bx}\n=\n\\diag\\bfs\n\\frac{d z}{d \\vv \\by}\n\\]\nwhere $\\bfs = [\\vv \\bx > 0] \\in\\{0,1\\}^{HWD}$ is an indicator vector.\n\n% ------------------------------------------------------------------\n\\subsection{Sigmoid}\\label{s:impl-sigmoid}\n% ------------------------------------------------------------------\n\nThe derivative of the sigmoid function is given by\n\\begin{align*}\n\\frac{dz}{dx_{ijk}}\n&= \n\\frac{dz}{d y_{ijd}} \n\\frac{d y_{ijd}}{d x_{ijd}}\n=\n\\frac{dz}{d y_{ijd}} \n\\frac{-1}{(1+e^{-x_{ijd}})^2} ( - e^{-x_{ijd}})\n\\\\\n&=\n\\frac{dz}{d y_{ijd}} \ny_{ijd} (1 - y_{ijd}).\n\\end{align*}\nIn matrix notation:\n\\[\n\\frac{dz}{d\\bx} = \\frac{dz}{d\\by} \\odot \n\\by \\odot \n(\\mathbf{1}\\mathbf{1}^\\top - \\by).\n\\]\n\n% ------------------------------------------------------------------\n\\section{Normalization}\\label{s:normalization}\n% ------------------------------------------------------------------\n\n% ------------------------------------------------------------------\n\\subsection{Cross-channel normalization}\\label{s:impl-ccnormalization}\n% ------------------------------------------------------------------\n\nThe derivative is easily computed as:\n\\[\n\\frac{dz}{d x_{ijd}}\n=\n\\frac{dz}{d y_{ijd}}\nL(i,j,d|\\bx)^{-\\beta}\n-2\\alpha\\beta x_{ijd}\n\\sum_{k:d\\in G(k)}\n\\frac{dz}{d y_{ijk}}\nL(i,j,k|\\bx)^{-\\beta-1} x_{ijk} \n\\]\nwhere\n\\[\n L(i,j,k|\\bx) = \\kappa + \\alpha \\sum_{t\\in G(k)} x_{ijt}^2.\n\\]\n\n% ------------------------------------------------------------------\n\\subsection{Batch normalization}\\label{s:impl-bnorm}\n% ------------------------------------------------------------------\n\nThe derivative of the input with respect to the network output is computed as follows:\n\\[\n\\frac{dz}{dx_{ijkt}} = \\sum_{i''j''k''t''}\n\\frac{dz}{d y_{i''j''k''t''}} \n\\frac{d y_{i''j''k''t''}}{d x_{ijkt}}.\n\\]\nSince feature channels are processed independently, all terms with $k''\\not=k$ are null. Hence\n\\[\n\\frac{dz}{dx_{ijkt}} = \\sum_{i''j''t''}\n\\frac{dz}{d y_{i''j''kt''}} \n\\frac{d y_{i''j''kt''}}{d x_{ijkt}},\n\\]\nwhere\n\\[\n\\frac{d y_{i''j''kt''}}{d x_{ijkt}} \n=\nw_k\n\\left(\\delta_{i=i'',j=j'',t=t''} - \\frac{d \\mu_k}{d x_{ijkt}}\\right)\n\\frac{1}{\\sqrt{\\sigma^2_k + \\epsilon}}\n-\n\\frac{w_k}{2}\n\\left(x_{i''j''kt''} - \\mu_k\\right)\n\\left(\\sigma_k^2 + \\epsilon \\right)^{-\\frac{3}{2}}\n\\frac{d \\sigma_k^2}{d x_{ijkt}},\n\\]\nthe derivatives with respect to the mean and variance are computed as follows:\n\\begin{align*}\n\\frac{d \\mu_k}{d x_{ijkt}} &= \\frac{1}{HWT},\n\\\\\n\\frac{d \\sigma_k^2}{d x_{i'j'kt'}}\n&=\n\\frac{2}{HWT}\n\\sum_{ijt}\n\\left(x_{ijkt} - \\mu_k \\right)\n\\left(\\delta_{i=i',j=j',t=t'} - \\frac{1}{HWT} \\right)\n=\n\\frac{2}{HWT} \\left(x_{i'j'kt'} - \\mu_k \\right),\n\\end{align*}\nand $\\delta_E$ is the indicator function of the event $E$. Hence\n\\begin{align*}\n\\frac{dz}{dx_{ijkt}}\n&=\n\\frac{w_k}{\\sqrt{\\sigma^2_k + \\epsilon}}\n\\left(\n\\frac{dz}{d y_{ijkt}} \n-\n\\frac{1}{HWT}\\sum_{i''j''kt''}\n\\frac{dz}{d y_{i''j''kt''}} \n\\right)\n\\\\\n&-\n\\frac{w_k}{2(\\sigma^2_k + \\epsilon)^{\\frac{3}{2}}}\n\\sum_{i''j''kt''}\n\\frac{dz}{d y_{i''j''kt''}} \n\\left(x_{i''j''kt''} - \\mu_k\\right)\n\\frac{2}{HWT} \\left(x_{ijkt} - \\mu_k \\right)\n\\end{align*}\ni.e.\n\\begin{align*}\n\\frac{dz}{dx_{ijkt}}\n&=\n\\frac{w_k}{\\sqrt{\\sigma^2_k + \\epsilon}}\n\\left(\n\\frac{dz}{d y_{ijkt}} \n-\n\\frac{1}{HWT}\\sum_{i''j''kt''}\n\\frac{dz}{d y_{i''j''kt''}} \n\\right)\n\\\\\n&-\n\\frac{w_k}{\\sigma^2_k + \\epsilon}\n\\,\n\\frac{x_{ijkt} - \\mu_k}{\\sqrt{\\sigma^2_k + \\epsilon}}\n\\,\n\\frac{1}{HWT}\n\\sum_{i''j''kt''}\n\\frac{dz}{d y_{i''j''kt''}} \n\\left(x_{i''j''kt''} - \\mu_k\\right).\n\\end{align*}\n\n% ------------------------------------------------------------------\n\\subsection{Spatial normalization}\\label{s:impl-spnorm}\n% ------------------------------------------------------------------\n\nThe neighborhood norm $n^2_{i''j''d}$ can be computed by applying average pooling to $x_{ijd}^2$ using \\verb!vl_nnpool! with a $W'\\times H'$ pooling region, top padding $\\lfloor \\frac{H'-1}{2}\\rfloor$, bottom padding $H'-\\lfloor \\frac{H-1}{2}\\rfloor-1$, and similarly for the horizontal padding.\n\nThe derivative of spatial normalization can be obtained as follows:\n\\begin{align*}\n\\frac{dz}{dx_{ijd}} \n&= \\sum_{i''j''d}\n\\frac{dz}{d y_{i''j''d}} \n\\frac{d y_{i''j''d}}{d x_{ijd}}\n\\\\\n&=\n\\sum_{i''j''d}\n\\frac{dz}{d y_{i''j''d}} \n(1 + \\alpha n_{i''j''d}^2)^{-\\beta}\n\\frac{dx_{i''j''d}}{d x_{ijd}} \n-\\alpha\\beta\n\\frac{dz}{d y_{i''j''d}} \n(1 + \\alpha n_{i''j''d}^2)^{-\\beta-1}\nx_{i''j''d}\n\\frac{dn_{i''j''d}^2}{d (x^2_{ijd})} \n\\frac{dx^2_{ijd}}{d x_{ijd}}\n\\\\\n&=\n\\frac{dz}{d y_{ijd}} \n(1 + \\alpha n_{ijd}^2)^{-\\beta}\n-2\\alpha\\beta x_{ijd}\n\\left[\n\\sum_{i''j''d}\n\\frac{dz}{d y_{i''j''d}} \n(1 + \\alpha n_{i''j''d}^2)^{-\\beta-1}\nx_{i''j''d}\n\\frac{dn_{i''j''d}^2}{d (x_{ijd}^2)}\n\\right]\n\\\\\n&=\n\\frac{dz}{d y_{ijd}} \n(1 + \\alpha n_{ijd}^2)^{-\\beta}\n-2\\alpha\\beta x_{ijd}\n\\left[\n\\sum_{i''j''d}\n\\eta_{i''j''d}\n\\frac{dn_{i''j''d}^2}{d (x_{ijd}^2)}\n\\right],\n\\quad\n\\eta_{i''j''d}=\n\\frac{dz}{d y_{i''j''d}} \n(1 + \\alpha n_{i''j''d}^2)^{-\\beta-1}\nx_{i''j''d}\n\\end{align*}\nNote that the summation can be computed as the derivative of the\n\\verb!vl_nnpool! block.\n\n% ------------------------------------------------------------------\n\\subsection{Softmax}\\label{s:impl-softmax}\n% ------------------------------------------------------------------\n\nCare must be taken in evaluating the exponential in order to avoid underflow or overflow. The simplest way to do so is to divide from numerator and denominator by the maximum value:\n\\[\n y_{ijk} = \\frac{e^{x_{ijk} - \\max_d x_{ijd}}}{\\sum_{t=1}^D e^{x_{ijt}- \\max_d x_{ijd}}}.\n\\]\nThe derivative is given by:\n\\[\n\\frac{dz}{d x_{ijd}}\n=\n\\sum_{k}\n\\frac{dz}{d y_{ijk}}\n\\left(\ne^{x_{ijd}} L(\\bx)^{-1} \\delta_{\\{k=d\\}}\n-\ne^{x_{ijd}}\ne^{x_{ijk}} L(\\bx)^{-2}\n\\right),\n\\quad\nL(\\bx) = \\sum_{t=1}^D e^{x_{ijt}}.\n\\]\nSimplifying:\n\\[\n\\frac{dz}{d x_{ijd}}\n=\ny_{ijd} \n\\left(\n\\frac{dz}{d y_{ijd}}\n-\n\\sum_{k=1}^K\n\\frac{dz}{d y_{ijk}} y_{ijk}.\n\\right).\n\\]\nIn matrix for:\n\\[\n  \\frac{dz}{dX} = Y \\odot \\left(\\frac{dz}{dY} \n  - \\left(\\frac{dz}{dY} \\odot Y\\right) \\bone\\bone^\\top\\right)\n\\]\nwhere $X,Y\\in\\real^{HW\\times D}$ are the matrices obtained by reshaping the arrays\n$\\bx$ and $\\by$. Note that the numerical implementation of this expression is straightforward once the output $Y$ has been computed with the caveats above.\n\n% ------------------------------------------------------------------\n\\section{Losses and comparisons}\\label{s:impl-losses}\n% ------------------------------------------------------------------\n\n% ------------------------------------------------------------------\n\\subsection{Log-loss}\\label{s:impl-loss}\n% ------------------------------------------------------------------\n\nThe derivative is\n\\[\n\\frac{dz}{dx_{ijd}} = - \\frac{dz}{dy} \\frac{1}{x_{ijc}} \\delta_{\\{d = c\\}}.\n\\]\n\n% ------------------------------------------------------------------\n\\subsection{Softmax log-loss}\\label{s:impl-sfloss}\n% ------------------------------------------------------------------\n\nThe derivative is given by\n\\[\n\\frac{dz}{dx_{ijd}} \n= - \\frac{dz}{dy} \\left(\\delta_{d=c} - y_{ijc}\\right)\n\\]\nwhere $y_{ijc}$ is the output of the softmax layer. In matrix form:\n\\[\n\\frac{dz}{dX} \n= - \\frac{dz}{dy} \\left(\\bone^\\top \\bfe_c - Y\\right)\n\\]\nwhere $X,Y\\in\\real^{HW\\times D}$ are the matrices obtained by reshaping the arrays\n$\\bx$ and $\\by$ and $\\bfe_c$ is the indicator vector of class $c$.\n\n% ------------------------------------------------------------------\n\\subsection{$p$-distance}\\label{s:impl-pdistance}\n% ------------------------------------------------------------------\n\nThe derivative of the operator without root is given by:\n\\begin{align*}\n\\frac{dz}{dx_{ijd}}\n&=\n\\frac{dz}{dy_{ij}}\np |x_{ijd} - \\bar x_{ijd}|^{p-1} \\operatorname{sign} (x_{ijd} - \\bar x_{ijd}).\n\\end{align*}\nThe derivative of the operator with root is given by:\n\\begin{align*}\n\\frac{dz}{dx_{ijd}}\n&=\n\\frac{dz}{dy_{ij}}\n\\frac{1}{p}\n\\left(\\sum_{d'} |x_{ijd'} - \\bar x_{ijd'}|^p \\right)^{\\frac{1}{p}-1}\np |x_{ijd} - \\bar x_{ijd}|^{p-1} \\sign(x_{ijd} - \\bar x_{ijd})\n\\\\\n&= \n\\frac{dz}{dy_{ij}}\n\\frac{|x_{ijd} - \\bar x_{ijd}|^{p-1} \\sign(x_{ijd} - \\bar x_{ijd})}{y_{ij}^{p-1}}.\n\\end{align*}\nThe formulas simplify a little for $p=1,2$ which are therefore implemented as special cases.\n\n", "meta": {"hexsha": "5bf974823d16eb13adec730e5fc3356f807b0d7b", "size": 16059, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/impl.tex", "max_stars_repo_name": "Yijunmaverick/DeepJointFilter", "max_stars_repo_head_hexsha": "e6f2c8206937e8bd502749d026d688e62867f34a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 88, "max_stars_repo_stars_event_min_datetime": "2016-09-05T20:11:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T14:03:53.000Z", "max_issues_repo_path": "doc/impl.tex", "max_issues_repo_name": "Yijunmaverick/DeepJointFilter", "max_issues_repo_head_hexsha": "e6f2c8206937e8bd502749d026d688e62867f34a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-10-24T00:50:50.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-07T07:11:04.000Z", "max_forks_repo_path": "doc/impl.tex", "max_forks_repo_name": "Yijunmaverick/DeepJointFilter", "max_forks_repo_head_hexsha": "e6f2c8206937e8bd502749d026d688e62867f34a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 31, "max_forks_repo_forks_event_min_datetime": "2016-10-11T09:10:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-13T12:25:17.000Z", "avg_line_length": 32.2469879518, "max_line_length": 583, "alphanum_fraction": 0.5382651473, "num_tokens": 5513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7294499701572151}}
{"text": "\\section{M/G/1 Queues}\n\\label{sec:M-G-1-queues}\n\nA $M/G/1$ is a queue where \n(i) the arrival process is Poissonian with rate $\\lambda$,\n(ii) the service process is generically distributed,\n(iii) there is one servers,\n(iv) the buffer has infinite capacity,\n(v) the scheduling policy is FCFS.\n\n%\\begin{figure}[tp]\n%\\label{fig:M-G-1-queue}\t\n%\t\\centering\n%\t\\includegraphics{fig/M-G-1-Queue}\n%\t\\caption{M/G/1 queue}\n%\\end{figure}\n\nIn general, we have that\n\n\\begin{equation}\n\\label{sec:M-G-1-Mean-Queue-Excess-Time}\n\\expected{T_{Q}}=\\frac{\\varrho}{1-\\varrho}\\expected{S_{e}}\n\\end{equation}\n\nwhere $\\expected{T_{e}}$ is the \\textit{excess of service time}, that is the remaining service time of the job in service, given that there is some job in service.\n\n\n\n\\subsection{P-K Formula}\n\\label{sec:PK-Formula}\nThe Pollaczek-Khinchin (P-K Formula) \\cite{pollaczek1930aufgabe,khinchin1967mathematical} is written in several equivalent forms:\n\n\\begin{equation}\n\\expected{T_{Q}}=\\frac{\\varrho}{1-\\varrho}\\cdot\\frac{\\expected{S^{2}}}{2\\expected{S}}\n\\end{equation}\n\n\\begin{equation}\n\\expected{T_{Q}}=\\frac{\\varrho}{1-\\varrho}\\cdot\\frac{\\expected{S}}{2}\\cdot(C_{S}^{2}+1)\n\\end{equation}\n\n\\begin{equation}\n\\expected{T_{Q}}=\\frac{\\lambda\\expected{S^{2}}}{2(1-\\varrho)}\n\\end{equation}", "meta": {"hexsha": "2605cb95ac2d3bfdffcf80118c8e0c63b1e438d5", "size": 1264, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/m-g-1-queues.tex", "max_stars_repo_name": "gmarciani/research", "max_stars_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-07-27T13:31:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-20T12:54:12.000Z", "max_issues_repo_path": "performance-modeling/sec/m-g-1-queues.tex", "max_issues_repo_name": "gmarciani/research", "max_issues_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "performance-modeling/sec/m-g-1-queues.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 29.3953488372, "max_line_length": 163, "alphanum_fraction": 0.7159810127, "num_tokens": 428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7294499647336766}}
{"text": "\\section{Homework}\n\n\\subsection{Non-Linear Case}\n\nGiven the conditions $x(0) = 0.5$ and $F(t) = F$, we \nevaluate the Laplace transform of \\ref{eq: system equation} \nand obtain\n\n\\begin{equation}\n  s \\mathcal{X} - 0.5 + \\frac{k}{b} \\mathcal{X} = \n\\frac{1}{b} \\frac{F}{s}\n\\end{equation}\n\nSolving for $\\mathcal{X}$.\n\n\\begin{equation}\n \\mathcal{X} = \\frac{F}{b}\n\\frac{1}{s(s+\\frac{k}{b})} + \\frac{0.5}{s+\\frac{k}{b}} \n\\label{eq: non-linear system equation laplace}\n\\end{equation}\n\nUsing partial fractions, find an equivalent expression for \n\\ref{eq: non-linear system equation laplace} .\n\n\\begin{equation*}\n \\begin{split}\n  \\frac{1}{s(s+\\frac{k}{b})}  & = \\frac{A}{s} + \n\\frac{B}{s+\\frac{k}{b}}\\\\\nA & = \\frac{b}{k}\\\\\nB &= -\\frac{b}{k}\\\\\n \\end{split}\n\\end{equation*}\n\n\\begin{equation}\n \\frac{1}{s(s+\\frac{k}{b})}   = \\frac{1}{s} \\frac{b}{k} - \n\\frac{b}{k}\n\\frac{1}{s+\\frac{k}{b}}\n\\label{eq: partial fractions}\n\\end{equation}\n\nSubstitute \\ref{eq: partial fractions} in \\ref{eq: \nnon-linear system equation laplace} and then obtain the \ninverse Laplace transform of the equation.\n\n\\begin{equation*}\n \\begin{split}\n   \\mathcal{X} & = \\frac{F}{b}\n\\Bigl ( \\frac{1}{s} \\frac{b}{k} - \n\\frac{b}{k}\n\\frac{1}{s+\\frac{k}{b}} \\Bigr) + \\frac{0.5}{s+\\frac{k}{b}} \n\\\\\n& = \\frac{F}{k} \\frac{1}{s}  - \n\\frac{F}{k}\n\\frac{1}{s+\\frac{k}{b}} + \\frac{0.5}{s+\\frac{k}{b}} \n\\\\\n \\end{split}\n\\end{equation*}\n\n\\begin{equation}\n \\mathfrak{L}^{-1} \\Bigl \\{ \\mathcal{X} \\Bigr \\} \n\\xrightarrow{} x(t) = \\frac{F}{k} - \\frac{F}{k} \n\\mathrm{e}^{-\\frac{k}{b}t} + 0.5 \\mathrm{e}^{-\\frac{k}{b}t}\n\\label{eq: non-linear system equation}\n\\end{equation}\n\nTest the principles of proportionality and superposition on \n\\ref{eq: non-linear system equation}.\n\n\\begin{equation*}\n \\begin{split}\n x(\\alpha t) & = \\frac{F}{k} - \\frac{F}{k} \n\\mathrm{e}^{-\\alpha \\frac{k}{b}t} + 0.5 \n\\mathrm{e}^{-\\alpha \\frac{k}{b}t}\\\\\n \\alpha x(t) &= \\alpha \\frac{F}{k} - \\alpha \\frac{F}{k} \n\\mathrm{e}^{-\\frac{k}{b}t} + 0.5 \\alpha \n\\mathrm{e}^{-\\frac{k}{b}t}\\\\\nx(\\alpha t) & \\neq \\alpha x(t)\\\\\n  x( t_1 + t_2) & = \\frac{F}{k} - \\frac{F}{k} \n\\mathrm{e}^{-\\frac{k}{b}(t_1+t_2)} + 0.5 \n\\mathrm{e}^{-\\frac{k}{b}(t_1+t_2)}\\\\\nx(t_1) +  x(t_2) & = 2 \\frac{F}{k} - \n\\frac{F}{k} \\Bigl ( \n\\mathrm{e}^{- \\frac{k}{b}t_1} -\\mathrm{e}^{- \\frac{k}{b}t_2} \n\\Bigr ) + 0.5 \n\\Bigl (\\mathrm{e}^{- \\frac{k}{b}t_1}\n +\n\\mathrm{e}^{- \\frac{k}{b}t_2} \\Bigr) \\\\\nx(t_1 + t_2) & \\neq x(t_1) + x(t_2)\\\\\n \\end{split}\n\\end{equation*}\n\nWe conclude that the system in Non-linear for the given \ninitial conditions.\n", "meta": {"hexsha": "f6dcf4a729a5df620362eef6d285e765407403c4", "size": 2509, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/tex/homework01.tex", "max_stars_repo_name": "der-coder/Cinvestav-Dynamic-Systems-2019", "max_stars_repo_head_hexsha": "e30ded5312a2734eb542368de69c40a9d3af9989", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Notes/tex/homework01.tex", "max_issues_repo_name": "der-coder/Cinvestav-Dynamic-Systems-2019", "max_issues_repo_head_hexsha": "e30ded5312a2734eb542368de69c40a9d3af9989", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/tex/homework01.tex", "max_forks_repo_name": "der-coder/Cinvestav-Dynamic-Systems-2019", "max_forks_repo_head_hexsha": "e30ded5312a2734eb542368de69c40a9d3af9989", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6914893617, "max_line_length": 61, "alphanum_fraction": 0.5882821841, "num_tokens": 1093, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7293087397408177}}
{"text": "\\section{Gaussian elimination}\n\\label{sec:gaussian-elimination}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find the {\\ef} of a matrix.\n  \\item Determine whether a system of linear equations has no\n    solution, a unique solution or an infinite number of solutions\n    from its {\\ef}.\n  \\item Solve a system of linear equations using Gaussian elimination\n    and back substitution.\n  \\item Find the rank of a matrix.\n  \\item Determine whether a consistent system of linear equations has\n    a unique solution or an infinite number of solutions from its\n    rank.\n  \\end{enumerate}\n\\end{outcome}\n\nIn the previous section, we saw examples of how to solve a system of\nequations using elementary row operations (and sometimes back\nsubstitution). But it is not clear whether every system of equations\ncan be solved this way. How do we know which elementary row operation\nto apply next? In this section, you will learn a procedure called {\\em\n  Gaussian elimination} by which every system of linear equations can\nbe solved systematically.\n\nBefore we start, let's figure out what it means to be ``done''. At\nwhat point should we stop performing row operations? The answer is\nthat we will stop performing row operations when the system of\nequations is in a special form called {\\em {\\ef}}, which we now define.\n\n\\begin{definition}{\\Ef}{echelon-form}\n  An entry of an augmented matrix is called a \\textbf{leading entry}%\n  \\index{leading entry} or \\textbf{pivot entry}%\n  \\index{pivot entry} if it is the leftmost non-zero entry of a row.\n  An augmented matrix is in \\textbf{\\ef}%\n  \\eindex{\\ef} (also called \\textbf{row echelon form}%\n  \\index{row echelon form|see {\\ef}}) if\n  \\begin{enumerate}\n  \\item All rows of zeros are below all non-zero rows.\n\n  \\item Each leading entry of a row is in a column to the right of the\n    leading entry of any row above it.\n  \\end{enumerate}\n  A column containing a pivot entry is also called a \\textbf{pivot\n    column}%\n  \\index{pivot column}.\n\\end{definition}\n\nThe word {\\em echelon} comes from French {\\em \\'echelle}, which means\nladder. This is because an {\\ef} looks a bit like a ladder or\nstaircase. Here are some examples of {\\ef}s.\n\n\\begin{example}{Matrices in {\\ef}}{matrices-not-rref}\n  The following augmented matrices are in {\\ef}. We have circled the\n  pivot entries for clarity.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrrr|r}\n      0 & \\circled{5} & 2 & 1 & 3 & 5 \\\\\n      0 & 0 & 0 & 0 & \\circled{1} & 6 \\\\\n      0 & 0 & 0 & 0 & 0 & 0 \\\\\n      0 & 0 & 0 & 0 & 0 & 0\n    \\end{mymatrix}, \\quad \\begin{mymatrix}{rrrrr|r}\n      \\circled{1} & 4 & 0 & 0 & 5 & 0 \\\\\n      0 & 0 & \\circled{1} & 0 & 2 & 0 \\\\\n      0 & 0 & 0 & \\circled{1} & 4 & 0 \\\\\n      0 & 0 & 0 & 0 & 0 & \\circled{1}\n    \\end{mymatrix}, \\quad \\begin{mymatrix}{rrr|r}\n      \\circled{3} & 0 & 6 & 2 \\\\\n      0 & \\circled{1} & 4 & 0 \\\\\n      0 & 0 & \\circled{2} & 1 \\\\\n      0 &  0 & 0 & 0\n    \\end{mymatrix}\n  \\end{equation*}\n\\end{example}\n\n\\begin{example}{Not in {\\ef}}{matrices-not-echelon}\n  The following augmented matrices are not in {\\ef}.\n\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      0 & 0 & 0 & 0 \\\\\n      \\circled{1} & 2 & 3 & 3 \\\\\n      0 & \\circled{1} & 0 & 2 \\\\\n      0 & 0 & 0 & \\circled{1} \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix}, \\quad \\begin{mymatrix}{rr|r}\n      \\circled{1} & 2 & 3 \\\\\n      \\circled{2} & 4 & -6 \\\\\n      \\circled{4} & 0 & 7\n    \\end{mymatrix}, \\quad \\begin{mymatrix}{rrr|r}\n      0 & \\circled{2} & 3 & 3 \\\\\n      \\circled{1} & 5 & 0 & 2 \\\\\n      0 & 0 & \\circled{1} & 0 \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix}\n  \\end{equation*}\n  In the first matrix, a row of zeros is above a non-zero row. In the\n  second and third matrix, the leading entries of some rows are not to\n  the right of the leading entries of previous rows.\n\\end{example}\n\nAn augmented matrix can always be converted to {\\ef} by using\nelementary row operations. The following algorithm shows how to do\nthis.\n\n\\begin{algorithm}{Gaussian elimination}{gaussian-elimination}\n  This algorithm provides a method for using row operations to take a\n  matrix to its {\\ef}%\n  \\eindex{\\ef!algorithm}%\n  \\index{Gaussian elimination}.  We begin with the matrix in its\n  original form.\n\n  \\begin{enumerate}\n  \\item Starting from the left, find the first non-zero column. This is\n    the first pivot column, and the position at the top of this column\n    will be the position of the first pivot entry. Switch rows if\n    necessary to place a non-zero number in the first pivot position.\n\n  \\item Use row operations to make the entries below the first pivot\n    entry (in the first pivot column) equal to zero.\n\n  \\item Ignoring the row containing the first pivot entry, repeat\n    steps 1 and 2 with the remaining rows.  Repeat the process until\n    there are no more non-zero rows left.\n\n  \\end{enumerate}\n\\end{algorithm}\n\nMost often we will apply this algorithm in order to solve a system of\nlinear equations. This works by first converting the system to {\\ef},\nthen using back substitution to find the solutions. The next few\nexamples show how to do this.\n\n\\begin{example}{Solving a system of equations: one solution}{system-with-one-solution}\n  Solve the following system of equations:\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x + 4y + 3z &=& 11 \\\\\n      2x + 10y + 7z &=& 27 \\\\\n      x + y + 2z &=& 5.\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution} The augmented matrix for this system is\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      1 & 4 & 3 & 11 \\\\\n      2 & 10 & 7 & 27 \\\\\n      1 & 1 & 2 & 5\n    \\end{mymatrix}.\n  \\end{equation*}\n  In order to find the solution(s) to this system, we first use\n  Algorithm~\\ref{algo:gaussian-elimination} to carry the augmented\n  matrix to {\\ef}. Notice that the first column is non-zero, so this is\n  our first pivot column. The first entry in the first row, $1$, is\n  the first pivot entry. We will use row operations to create zeros in\n  the entries below the $1$.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 4 & 3 & 11 \\\\\n      2 & 10 & 7 & 27 \\\\\n      1 & 1 & 2 & 5\n    \\end{mymatrix}\n    \\stackrel{R_2\\rowop R_2-2R_1}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 4 & 3 & 11 \\\\\n      0 & 2 & 1 & 5 \\\\\n      1 & 1 & 2 & 5\n    \\end{mymatrix}\n    \\stackrel{R_3\\rowop R_3-R_1}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 4 & 3 & 11 \\\\\n      0 & 2 & 1 & 5 \\\\\n      0 & -3 & -1 & -6\n    \\end{mymatrix}\n  \\end{equation*}\n  Now the entries in the first column below the pivot position are\n  zeros. We now look for the second pivot column, which in this case\n  is column two.  Here, the $2$ in the second row and second column is\n  in the pivot entry. We could create a zero below the $2$ with a\n  single row operation by adding $\\frac{3}{2}$ times the second row\n  from the third row. But it is sometimes more convenient not to work\n  with fractions, and therefore we start instead by multiplying the\n  third row by $2$.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 4 & 3 & 11 \\\\\n      0 & \\circled{2} & 1 & 5 \\\\\n      0 & -3 & -1 & -6\n    \\end{mymatrix}\n    \\stackrel{R_3\\rowop 2R_3}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 4 & 3 & 11 \\\\\n      0 & \\circled{2} & 1 & 5 \\\\\n      0 & -6 & -2 & -12\n    \\end{mymatrix}\n    \\stackrel{R_3\\rowop R_3+3R_2}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 4 & 3 & 11 \\\\\n      0 & \\circled{2} & 1 & 5 \\\\\n      0 & 0 & 1 & 3\n    \\end{mymatrix}\n  \\end{equation*}\n  The final matrix is our desired {\\ef}.\n  \\begin{equation}\\label{eqn:system-with-one-solution-1}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 4 & 3 & 11 \\\\\n      0 & \\circled{2} & 1 & 5 \\\\\n      0 & 0 & \\circled{1} & 3\n    \\end{mymatrix}\n  \\end{equation}\n  Now we do back substitution to solve for $z$, $y$, and then $x$. The\n  last equation of the {\\ef} gives us $z=3$. Substituting this into\n  the second equation, we get $2y+3=5$, which we can solve for $y$ to\n  get $y=1$. Finally, substituting $y=1$ and $z=3$ into the first\n  equation, we have $x+4(1)+3(3)=11$, which we can solve to get\n  $x=-2$. Therefore we have the solution $(x,y,z)=(-2,1,3)$.\n\n  At this point, it is a good idea to double-check this solution using\n  the original equations\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x+4y+3z &=& 11 \\\\\n      2x+10y+7z &=& 27 \\\\\n      x+y+2z &=& 5.\n    \\end{array}\n  \\end{equation*}\n  For example, we can double-check that $(-2)+4(1)+3(3)$ is indeed\n  equal to $11$, and similarly for the other two equations.\n  Double-checking the solution against the original equations is an\n  excellent way to guard against any errors that might have happened\n  during the row operations or back substitution.\n\n  Finally, we note that $(x,y,z)=(-2,1,3)$ is the {\\em only} solution\n  to this system of equations. There cannot be any other solutions,\n  because by Theorem~\\ref{thm:elementary-operations-and-solutions}, any\n  solution of the original system of equations would also have to be a\n  solution of {\\eqref{eqn:system-with-one-solution-1}}, and the back\n  substitution leaves us no choice except $z=3$, $y=1$, and $x=-2$.\n\\end{solution}\n\n\\begin{example}{Solving a system of equations: no solution}{system-with-no-solution}\n  Solve the following system of equations:\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      y + 2z &=& 2 \\\\\n      2x + y - 2z &=& 3 \\\\\n      4x - y - 10z &=& 4.\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution} The augmented matrix for this system is\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      0 &  1 &   2 & 2 \\\\\n      2 &  1 &  -2 & 3 \\\\\n      4 & -1 & -10 & 4\n    \\end{mymatrix}.\n  \\end{equation*}\n  We use Algorithm~\\ref{algo:gaussian-elimination} to carry the\n  augmented matrix to {\\ef}. The first column is non-zero and will be the\n  first pivot column. We switch the first two rows to move a non-zero\n  number into the pivot position:\n  \\begin{equation*}\n    \\stackrel{R_2\\rowswap R_1}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{2} &  1 &  -2 & 3 \\\\\n      0 &  1 &   2 & 2 \\\\\n      4 & -1 & -10 & 4\n    \\end{mymatrix}.\n  \\end{equation*}\n  To create zeros below the pivot entry, we subtract $2$ times the\n  first row from the third row:\n  \\begin{equation*}\n    \\stackrel{R_3\\rowop R_3-2R_1}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{2} &  1 &  -2 & 3 \\\\\n      0 &  1 &   2 & 2 \\\\\n      0 & -3 & -6 & -2\n    \\end{mymatrix}.\n  \\end{equation*}\n  This finishes the first column. The second pivot column will be\n  column two, with the $1$ in the second row and column as the pivot\n  entry. We add $3$ times the second row to the third row to create a\n  zero below the pivot:\n  \\begin{equation*}\n    \\stackrel{R_3\\rowop R_3+3R_2}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{2} &  1 &  -2 & 3 \\\\\n      0 &  \\circled{1} &   2 & 2 \\\\\n      0 & 0 & 0 & \\circled{4}\n    \\end{mymatrix}.\n  \\end{equation*}\n  This matrix is in {\\ef}. Note that the final pivot entry is on the\n  right-hand side. The last row corresponds to the equation\n  \\begin{equation*}\n    0x + 0y + 0z = 4.\n  \\end{equation*}\n  This equation has no solution, because for all $x,y,z$, the\n  left-hand size will equal $0$ and not $4$. Therefore, there is no\n  solution to the given system of equations. In other words, the\n  system is inconsistent.\n\\end{solution}\n\n\\begin{example}{Solving a system of equations: an infinite set of solutions}{infinite-set-of-solution}\n  Solve the following system of equations:\n  \\begin{equation}\n    \\begin{array}{r@{~}c@{~}l}\n      3x  -y + 5z  &=& 8 \\\\\n      y - 10z &=& 1 \\\\\n      6x  -y       &=& 17.\n    \\end{array}\n  \\end{equation}\n\\end{example}\n\n\\begin{solution} The augmented matrix of this system is\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      3 &  -1  &  5 & 8 \\\\\n      0 &   1 & -10 & 1 \\\\\n      6 &  -1  &  0 & 17\n    \\end{mymatrix}.\n  \\end{equation*}\n  We use Gaussian elimination to carry the augmented matrix to\n  {\\ef}. The first column is the first pivot column, and $3$ is the\n  pivot entry. We use row operating to create zeros beneath the pivot\n  entry. We subtract $2$ times the first row from the third row and get:\n  \\begin{equation*}\n    \\stackrel{R_3\\rowop R_3-2R_1}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{3} &  -1  &  5 & 8 \\\\\n      0 &   1 & -10 & 1 \\\\\n      0 &   1 & -10 & 1\n    \\end{mymatrix}\n  \\end{equation*}\n  Now, we have created zeros beneath the pivot entry in the first\n  column, so we move on to the second pivot column (which is the\n  second column) and repeat the procedure. Subtracting the second row\n  from the third row, we get:\n  \\begin{equation*}\n    \\stackrel{R_3\\rowop R_3-R_2}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{3} &  -1  &  5 & 8 \\\\\n      0 &   \\circled{1} & -10 & 1 \\\\\n      0 &   0 & 0 & 0\n    \\end{mymatrix}\n  \\end{equation*}\n  This matrix is now in {\\ef}. Observe that the first two columns are\n  pivot columns, and the third column is not. We call the\n  corresponding variables $x$ and $y$ \\textbf{pivot variables}%\n  \\index{pivot variable}%\n  \\index{variable!pivot}, and the variable $z$ is a \\textbf{free\n    variable}%\n  \\index{free variable}%\n  \\index{variable!free}.  The equations corresponding to this {\\ef}\n  are\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      3x - y + 5z &=& 8 \\\\\n      y - 10z &=& 1.\n    \\end{array}\n  \\end{equation*}\n  Observe that the free variable $z$ is not constrained by any\n  equation. In fact, $z$ can equal any number. We choose $t$ to be any\n  number and let $z = t$.  In this context $t$ is called a\n  \\textbf{parameter}%\n  \\index{parameter}. We then use back substitution to solve for the\n  pivot variables $y$ and $x$. From the second equation, we have\n  $y = 1+10z = 1+10t$. From the first equation, we have\n  $3x = 8+y-5z = 8+(1+10t)-5t = 9+5t$, and therefore\n  $x=3+\\frac{5}{3}t$. Therefore, the general solution of this system\n  is\n  \\begin{equation*}\n    \\begin{array}{l}\n      x=3+\\frac{5}{3}t \\\\\n      y=1+10t \\\\\n      z=t,\n    \\end{array}\n  \\end{equation*}\n  where $t$ is arbitrary. The system has an infinite set of solutions\n  which are given by these equations. For any value of the parameter\n  $t$ we select, $x$, $y$, and $z$ will be given by the above\n  equations. For example, if we choose $t=4$ then the corresponding\n  solution would be\n  \\begin{equation*}\n    \\begin{array}{l}\n      x = 3 + \\frac{5}{3}(4) = \\frac{29}{3} \\\\\n      y = 1+10(4) = 41 \\\\\n      z = 4.\n    \\end{array}\n  \\end{equation*}\n\\end{solution}\n\nIn Example~\\ref{exa:infinite-set-of-solution} the solution involved a\nparameter. It may happen that the solution to a system involves more\nthan one parameter, as shown in the following example.\n\n\\begin{example}{Solving a system of equations: a two parameter set of solutions}{two-parameter-set-of-solution}\n  Solve the following system of equations:\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x + 2y - 2z + 2w &=& 3 \\\\\n      x + 2y - z  + 3w &=& 5 \\\\\n      x + 2y - 3z + w &=& 1.\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution} The augmented matrix is\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrr|r}\n      1 & 2 & -2 & 2 & 3 \\\\\n      1 & 2 & -1 & 3 & 5 \\\\\n      1 & 2 & -3 & 1 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n  We carry this matrix to {\\ef} using row operations.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrr|r}\n      1 & 2 & -2 & 2 & 3 \\\\\n      1 & 2 & -1 & 3 & 5 \\\\\n      1 & 2 & -3 & 1 & 1\n    \\end{mymatrix}\n    \\stackrel{R_2\\rowop R_2-R_1}{\\stackrel{R_3\\rowop R_3-R_1}{\\roweq}}\n    \\begin{mymatrix}{rrrr|r}\n      \\circled{1} & 2 & -2 & 2 & 3 \\\\\n      0 & 0 & 1 & 1 & 2 \\\\\n      0 & 0 & -1 & -1 & -2\n    \\end{mymatrix}\n    \\stackrel{R_3\\rowop R_3+R_2}{\\roweq}\n    \\begin{mymatrix}{rrrr|r}\n      \\circled{1} & 2 & -2 & 2 & 3 \\\\\n      0 & 0 & \\circled{1} & 1 & 2 \\\\\n      0 & 0 & 0 & 0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  This matrix is in {\\ef} and we can see that the first and third\n  columns are pivot columns, whereas the second and fourth columns are\n  not. Therefore, $x$ and $z$ are pivot variables and $y$ and $w$ are\n  free variables. We assign parameters $y=s$ and $w=t$ to the free\n  variables. Then we do back substitution to solve for $z$ and $x$.\n  From the second equation, we have $z=2-w=2-t$. From the first\n  equation, we have $x=3-2y+2z-2w = 3-2s+2(2-t)-2t =\n  7-2s-4t$. Therefore, the general solution is given by\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x &=& 7-2s-4t \\\\\n      y &=& s \\\\\n      z &=& 2-t \\\\\n      w &=& t.\n    \\end{array}\n  \\end{equation*}\n  It is customary to write this solution in the form\n  \\begin{equation}\\label{two-parameters-2}\n    \\begin{mymatrix}{c}\n      x \\\\\n      y \\\\\n      z \\\\\n      w\n    \\end{mymatrix} =\\begin{mymatrix}{c}\n      7-2s-4t \\\\\n      s \\\\\n      2-t \\\\\n      t\n    \\end{mymatrix}.\n  \\end{equation}\n\\end{solution}\n\nIn\nExamples~\\ref{exa:system-with-one-solution}--\\ref{exa:two-parameter-set-of-solution},\nwe have seem systems of equations with one solution, no solution, and\ninfinitely many solutions with one parameter as well as two\nparameters. Moreover, in each case, we have been able to determine the\nnumber of solutions by looking at the {\\ef} of the augmented matrix.\nTo summarize, we have the following possibilities for a system of equations:\n\n\\begin{enumerate}\n\\item {\\em No solution:} If the {\\ef} has a row of the form\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      0 & 0 & 0 & b\n    \\end{mymatrix},\n  \\end{equation*}\n  where $b\\neq 0$, then the system is inconsistent and has no\n  solution.\n\n\\item {\\em One solution:} For a consistent system of equations: If\n  every column of the coefficient matrix of the {\\ef} is a pivot\n  column, the system has exactly one solution. The following is an\n  example of an augmented matrix in {\\ef} for a system of equations\n  with one solution.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 1 & -2 & 5 \\\\\n      0 & \\circled{2} & 3 & 0 \\\\\n      0 & 0 & \\circled{1} & 2 \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n\n\\item {\\em Infinitely many solutions:} For a consistent system of\n  equations: If not all columns of the coefficient matrix of the {\\ef}\n  are pivot columns, then the system has infinitely many solutions.\n  In this case, each variable corresponding to a non-pivot column is a\n  {\\em free variable}%\n  \\index{free variable}%\n  \\index{variable!free} and can be assigned a {\\em parameter}%\n  \\index{parameter}. The remaining variables are {\\em pivot\n    variables}%\n  \\index{pivot variable}%\n  \\index{variable!pivot} and can be expressed in terms of the\n  parameters. Therefore, the number of parameters in the general\n  solution is equal to the number of non-pivot columns.  The following\n  are examples of {\\ef}s for systems of equations with infinitely many\n  solutions.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 0 & 1 & 5 \\\\\n      0 & \\circled{1} & 2 & -3 \\\\\n      0 & 0 & 0 & 0 \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix}\n  \\end{equation*}\n  or\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 2 & 3 & 5 \\\\\n      0 & 0 & \\circled{4} & 6\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{enumerate}\n\nThere is a special name for the number of pivot variables in a system\nof equations. It is called the {\\em rank} of the system.\n\n\\begin{definition}{Rank of a matrix}{rank}\n  Let $A$ be a matrix and consider any {\\ef} of $A$.  Then, the number\n  $r$ of pivot entries of $A$ does not depend on the {\\ef} we choose,\n  and is called the \\textbf{rank}%\n  \\index{matrix!rank}%\n  \\index{rank} of $A$. We denote it by $\\rank(A)$.\n\n  The rank of a system of linear equations is the rank of its\n  coefficient matrix (i.e., the matrix on the left-hand side).\n  It is equal to the number of pivot variables.\n\\end{definition}\n\n\\begin{example}{Finding the rank of a matrix}{rank-of-a-matrix}\n  Consider the matrix\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      1 & 5 & 9 \\\\\n      2 & 4 & 6\n    \\end{mymatrix}\n  \\end{equation*}\n  What is its rank?\n\\end{example}\n\n\\begin{solution}\n  First, we need to find an {\\ef} of $A$. Through the usual algorithm,\n  we find that this is\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      \\circled{1} & 0 & -1 \\\\\n      0 & \\circled{3} & 6 \\\\\n      0 & 0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  Here we have two pivot entries, and therefore the rank of $A$ is\n  $r=2$.\n\\end{solution}\n\nSuppose we have a system of $m$ equations in $n$ variables, and\nsuppose that $n>m$. Further assume that the system is consistent. From\nour above discussion, we know that this system will have infinitely\nmany solutions. This is because there can be at most one pivot entry\nper row, and therefore at most $m$ variables can be pivot\nvariables. It follows that there are at least $n-m$ free variables.\nTherefore, the general solution of this system has at least $n-m$\nparameters.\n\nNotice that if $n=m$ or $n<m$, it is possible for the system to have a\nunique solution or infinitely many solutions. In all cases ($n>m$,\n$n=m$, or $n<m$), it is also possible for the system to be\ninconsistent (have no solutions).\n\nBy refining the above argument, we get the following theorem:\n\n\\begin{theorem}{Rank and solutions of consistent system of equations}{rank-consistent-solutions}\n  Consider a system of $m$ equations in $n$ variables, and assume that\n  the coefficient matrix has rank $r$. Assume further that the system\n  is consistent.\n  \\begin{enumerate}\n  \\item If $r=n$, then the system has a unique solution.\n  \\item If $r<n$, then the system has infinitely many solutions, with $n-r$ parameters.\n  \\end{enumerate}\n\\end{theorem}\n\nHere is a final summary of how the rank affects the number of\nsolutions:\n\n\\begin{enumerate}\n\\item {\\em No solution.} If the system of equations is inconsistent,\n  then it has no solution, regardless of the rank.\n\n\\item {\\em Unique solution.} For a consistent system, suppose\n  $r=n$. Then there is a pivot position in every column of the\n  coefficient matrix of $A$. Hence, there is a unique solution.\n\n\\item {\\em Infinitely many solutions.} For a consistent system, suppose\n  $r<n$. Then there are less pivot positions than columns in the\n  coefficient matrix, meaning that not every column is a pivot\n  column. The columns which are {\\em not} pivot columns correspond to\n  parameters. In fact, in this case we have $n-r$ parameters. The\n  system has infinitely many solutions.\n\\end{enumerate}\n", "meta": {"hexsha": "58fa443509c7eea685343cfb94116f2ea1b415b5", "size": 22389, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/SystemsofEquations-GaussianElimination.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/SystemsofEquations-GaussianElimination.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/SystemsofEquations-GaussianElimination.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 36.0531400966, "max_line_length": 111, "alphanum_fraction": 0.6410290768, "num_tokens": 7529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234877, "lm_q2_score": 0.8774767858797979, "lm_q1q2_score": 0.7293087375812982}}
{"text": "\\section{Calculus}\n\n\\formdesc{Tangent and Secant Lines}\n\n\\begin{itemize}\n  \\item Tangent line is the line on $f(x)$ at point $x = a$ that just touches the\n\tgraph of the function\n\t    \\begin{itemize}\n\t        \\item The slope of a non-linear function at one point\n\t    \\end{itemize} \n\t    \n\t    \\begin{center}\n\t        \\includegraphics{tangent_line}\n\t    \\end{center}\n\t    \n  \\item Secant line is the line between $A$ and $B$ on a curve\n      \\begin{center}\n          \\includegraphics{secant_line}\n      \\end{center}\n\\end{itemize}\n\n\\textit{Note}: As $A$ gets\tcloser to $B$ the secant slope approaches the tangent line\n\\hformbar\n\n\n\n\\formdesc{Average Rate of Change}\n\n\\begin{equation}\n    ARC = f(a, a + \\Delta) = \\frac{\\Delta y}{\\Delta x} = \\frac{f(a + \\Delta x) - f(a)}{\\Delta x}\n\\end{equation}\n\nover interval $[a, a + \\Delta x]$\n\\hformbar\n\n\n\n\\formdesc{Derivative}\n\nThe instantaneous rate of change of a function $f(x)$ at point $x = a$\n\n\\begin{equation}\n    f'(a) = \\lim_{\\Delta x \\to 0} \\frac{\\Delta y}{\\Delta x} = \\lim_{\\Delta x \\to 0} \\frac{f(a + \\Delta x) - f(a)}{\\Delta x}\n\\end{equation}\n\n``the derivative of $y$ w.r.t. $x$'' $\\equiv \\frac{dy}{dx} \\equiv \\lim_{\\delta \\rightarrow 0} \\frac{\\delta y}{\\delta x}$\n\n\\hformbar\n\n\n\n\n\n\n\n\\formdesc{Simple Derivatives}\n\n\\begin{center}\n\\[\n\\def\\arraystretch{2.5}\n \\begin{array}{cc}\n  \\textit{y}   &      \\textit{y'}             \\\\\n  \\midrule\n  k            & 0                             \\\\\n  x            & 1                             \\\\ \n  x^n          & nx^{n-1}                      \\\\\n  \\sqrt{x}     & \\dfrac{1}{2\\sqrt{x}}          \\\\\n  \\sqrt[n]{x}  & \\dfrac{1}{n\\sqrt[n]{x^{n-1}}} \\\\\n  \\dfrac{1}{x} & \\dfrac{-1}{x^2}               \\\\ \n  e^x          & e^x                           \\\\\n  a^x          & a^x\\ln(a)                     \\\\\n  x^x          & xx^{x-1}+x^x\\ln(x)            \\\\\n  \\ln(x)       & \\dfrac{1}{x}                  \\\\\n  \\log_a(x)    & \\dfrac{1}{x}\\log_a(e)         \n \\end{array}\n\\]\n\\end{center}\n\\hformbar\n\n\n\n\\formdesc{Composite Derivatives}\n\n\\begin{center}\n\\[\n\\def\\arraystretch{2.5}\n \\begin{array}{cc}\n  \\textit{y}   &      \\textit{y'}               \\\\\n  \\midrule\n  u^n          & nu^{n-1}u'                     \\\\\n  \\sqrt{u}     & \\dfrac{u'}{2\\sqrt{u}}          \\\\\n  \\sqrt[n]{u}  & \\dfrac{u'}{n\\sqrt[n]{u^{n-1}}} \\\\\n  \\dfrac{1}{u} & \\dfrac{-u'}{u^2}               \\\\\n  e^u          & e^u u'                         \\\\\n  a^u          & a^u\\ln(a)u'                    \\\\\n  u^v          & vu^{v-1}u'+u^v\\ln(u) v'        \\\\\n  \\ln(u)        & \\dfrac{u'}{u}                 \\\\\n  \\log_a(u)    & \\dfrac{u'}{u}\\log_a(e)\n \\end{array}\n\\]\n\\end{center}\n\\hformbar\n\n\n\n\\formdesc{Derivative Operations}\n\n\\begin{center}\n  \\begin{tabular}{ll}\n  Sum         & $(f(x)+g(x))' = f'(x) + g'(x)$    \\\\\n  Difference  & $(f-g)'(x) = f'(x) - g'(x)$        \\\\\n  Product     & $(fg)'(x) = f'(x)g(x) + f(x)g'(x)$ \\\\\n  Quotient    & $ \\left(\\frac{f(x)}{g(x)}\\right)' = \\frac{f'(x)g(x) - f(x)g'(x)}{g(x)^2}$ \\\\\n  Chain rule  & $(f(g))'(x) = f'(g(x))g'(x)$        \\\\\n  Inverse     & $(f^{-1})'(x) = \\frac{1}{f'(x)}$  \n  \\end{tabular}\n\\end{center}\n\\hformbar\n\n\n\n\n\n\n\\formdesc{Limits}\n\n\\begin{equation}\n    \\lim_{x \\rightarrow C} f(x) = L\n\\end{equation}\n\nor, ``the limit of $f(x)$, as $x$ approaches $c$, is $L$.'' $\\lim_{x \\rightarrow C} f(x)$ is a \\textit{single number} that describes the behavior of the function $f(x)$ \\textit{near} but not \\textit{at} the point $x = c$.\n\nIntroduced to make calculating rate of change at 0 feasible, by making the $\\Delta$ so infinitesimal the difference is between it and 0 is negligible---``allows'' division by 0\n\n\\subsection*{Example}\n\n\\begin{center}\n    \\includegraphics{linear_limits2}\n\\end{center}\n\nwhere hollow points are undefined and solid points are defined\n\n\\begin{enumerate}\n    \\item $\\lim_{x \\rightarrow 6} f(x) = 1$\n    \\item $\\lim_{x \\rightarrow 4} f(x) = 3$\n        \\begin{itemize}\n            \\item \\textit{Note}: even though $x=4$ is undefined, we're only concerned with the area \\textit{around} 4, so we can still find the limit\n        \\end{itemize}\n    \\item $\\lim_{x \\rightarrow 2} f(x) = 5$\n\\end{enumerate}\n\n\\subsection*{Example: Determining Limits of Non-Linear Functions}\n\n\\begin{center}\n    \\includegraphics{limits_ex2}\n\\end{center}\n\nwhere hollow points are undefined and solid points are defined\n\n\\begin{enumerate}\n    \\item $\\lim_{x \\rightarrow 1} f(x) = 2$---values where $x$ is close to but not equal to 1 are near 2\n    \\item $\\lim_{x \\rightarrow 2} f(x) = 3$---even though $f(2)$ is undefined, only values \\textit{near} $f(2)$ are important\n    \\item $\\lim_{x \\rightarrow 3} f(x) = 1$---even though $f(3)$ is actually 2\n    \\item $\\lim_{x \\rightarrow 4} f(x) =$ \\textit{does not exist}: Can't determine a single number because $f(4)$ from the right is about 2, and from the left about 3\n\\end{enumerate}\n\n\n\\subsection*{Example: Determining Limits Using Algebra}\n\nFactor equation to simplest form and plug in $c$ (assuming function at $c$ is defined):\n\n\\begin{equation}\n    \\lim_{x \\rightarrow 5} \\frac{x^2 - 6x + 8}{x - 4} = \\frac{25 - 30 + 8}{1} = 3\n\\end{equation}\n\\hformbar\n\n\n\n\\formdesc{Limits of Broken Functions}\n\nSome functions are continuous but in an unusual way---they appear ``broken'' when graphed---and so there is a \\textit{left} and \\textit{right} limit\n\n\\begin{description}\n    \\item[Left] ``The limit coming from the left''; values of $f(x)$ as $f(x)$ nears $x$ and left of $c$, $x < c$\n        \\begin{equation}\n            \\lim_{x \\rightarrow c^-} f(x) = L\n        \\end{equation}\n    \\item[Right] ``This limit coming from the right''; values of $f(x)$ as $f(x)$ nears $x$ and right of $c$, $x > c$\n        \\begin{equation}\n            \\lim_{x \\rightarrow c^+} f(x) = L\n        \\end{equation}\n    \n\\end{description}\n\n\\textit{Note}: If left and rights limits are not the same, limit \\textit{doesn't exist}.\n\\hformbar\n\n\n\n\\formdesc{Continuity}\n\nA function $f$ is continuous at $x = a$ iff $\\lim_{x \\rightarrow a} f(x) = f(a)$,\ni.e., if the limit of $x$ at $a$ is equals $f(a)$, i.e., no breaks or jumps\n\n\\subsection*{Example}\n\n\\begin{center}\n    \\includegraphics{continuity}\n\\end{center}\n\nwhere $H$ indicates a hole---where the graph is defined but could be made continuous by changing the point---and $J$ a jump---where the left and right limits are not the same.\n\n\\begin{itemize}\n    \\item Continuous at 1 since $\\lim_{x \\rightarrow 1} f(x) = f(1) = 2$\n    \\item Not continuous at 2, 3, or 4\n        \\begin{itemize}\n            \\item $\\lim_{x \\rightarrow 2} f(x) =2 \\neq f(2) = 1$\n            \\item $\\lim_{x \\rightarrow 3} f(x) =$ doesn't exist $\\neq f(3) = 2$\n            \\item $\\lim_{x \\rightarrow 4} f(x) = 2 \\neq f(4) =$ undefined\n        \\end{itemize}\n\n\\end{itemize}\n\\hformbar\n\n\n\n\\formdesc{Calculating Derivatives}\n\n\\subsection*{Example: Using Formal Definition}\n\nFind derivative of $f(x) = 2x^2 - 16x + 35$.\n\n\\begin{enumerate}\n    \\item Assemble using the formal definition\n        \\begin{equation}\n            \\frac{\\left[ 2(x - h)^2 - 16(x + h) + 35 \\right] - \n                \\left[ 2x^2 - 16x - 35 \\right] }{h}\n        \\end{equation}\n        \n    \\item Factor---\\textit{cannot plug $h=0$ because no division by zero!}\n        \\begin{eqnarray}\n            &=& \\frac{2x^2 + 4xh + 2h^2 - 16x - 16h + 35 - 2x^2 + 16x - 35}{h} \\\\\n            &=& \\lim_{h \\rightarrow 0} \\frac{4xh + 2h^2 - 16h}{h}\n        \\end{eqnarray}\n        \n    \\item Factor out $h$ in numerator to cancel $h$ in denominator\n        \\begin{eqnarray}\n            f'(x) &=& \\lim_{h \\rightarrow 0} \\frac{h(4x + 2h - 16)}{h} \\\\\n            &=& \\lim_{h \\rightarrow 0} 4x + 2h - 16 \\\\\n            &=& 4x - 16\n        \\end{eqnarray}\n\n\\end{enumerate}\n\\hformbar\n\n\n\n\\formdesc{Implicit Differentiation}\n\nThe process to find $y' = f'(x)$ when $f(x)$ is difficult or impossible to use with explicit differentiation, by assuming $y$ is a function of $x$:\n\n\\subsection*{Example}\n\nImplicitly differentiate $x^2 + y^2 = 25$\n\n\\begin{enumerate}\n    \\item Differentiate each side, treating $y$ as a function\n    \\begin{eqnarray}\n        \\frac{d}{dx} \\left( x^2 + y^2 \\right) = \\frac{d}{dx} 25 \\\\\n        &\\Rightarrow& \\frac{d}{dx} x^2 + \\frac{d}{dx} y^2 = 0 \\\\\n        &\\Rightarrow& 2x + 2y \\frac{dy}{dx} = 0 \\\\\n        &\\Rightarrow& 2x + 2yy' = 0\n    \\end{eqnarray}\n    \n    \\item Algebraically solve for $y'$\n    \\begin{eqnarray}\n    \t2yy' = -2x \\\\\n\t    &\\Rightarrow& y' = \\frac{-2x}{2y} \\\\\n\t    &\\Rightarrow& y' = -\\frac{x}{y}    \n    \\end{eqnarray}\n\\end{enumerate}\n\\hformbar\n\n\n\n\\formdesc{Definite Integral}\n\nThe definite integral of a positive function $f(x)$ over an interval $[a, b]$ is the area between $f$, the $x$-axis, $x = a$, and $x = b$.\n\n\\begin{equation}\n    \\int_a^b f(x)\\, dx\n\\end{equation}\n\nwhere $a$ and $b$ are the ``limits of integration'' and $f(x)$ is the integrand\n\n    \\begin{eqnarray}\n        \\int_a^a f(x)\\, dx &=& 0                   \\\\\n        \\int_a^b f(x)\\, dx &=& -\\int_b^a f(x)\\, dx  \\\\\n        \\int_a^b f(x)\\, dx &=& \\int_a^c f(x)\\, dx + \\int_c^b f(x)\\, dx\n    \\end{eqnarray}\n\nwhere $a<c<b$\n\\hformbar\n\n\n\n\\formdesc{Integration Operations}\n\n\\begin{center}\n  \\begin{tabular}{ll}\n  Sum           & $\\int u+v\\,dx = \\int u\\,dx + \\int v\\,dx$  \\\\\n  Difference    & $\\int u-v\\,dx = \\int u\\,dx - \\int v\\,dx$  \\\\\n  Product       & $\\int af(x)\\,dx = a\\int f(x)\\,dx$         \\\\\n  Parts         & $\\int u\\,dv = uv - \\int v\\,du$            \\\\\n  Substitution  & $\\int f(u)u'\\,dx = \\int f(u)\\,du$\n  \\end{tabular}\n\\end{center}\n\\hformbar\n\n\n\n\\formdesc{Growth, Concavity, and Extrema}\n\n\\flushleft\n\t\t\t\\begin{description}\n\t\t\t\t\\item[Growth]\n\t\t\t\t      \\begin{itemize}\n\t\t\t\t\t      \\item[]\n\t\t\t\t\t      \\item $\\forall x\\in I\\ f'(x)\\geq 0$ $\\Rightarrow$ $f$ is increasing in $I$.\n\t\t\t\t\t      \\item $\\forall x\\in I\\ f'(x)\\leq 0$ $\\Rightarrow$ $f$ is decreasing in $I$.\n\t\t\t\t      \\end{itemize}\n\t\t\t\t\\item[Concavity]\n\t\t\t\t      \\begin{itemize}\n\t\t\t\t\t      \\item[]\n\t\t\t\t\t      \\item $\\forall x\\in I\\ f''(x)\\geq 0$ $\\Rightarrow$ $f$ is concave up in $I$.\n\t\t\t\t\t      \\item $\\forall x\\in I\\ f''(x)\\leq 0$ $\\Rightarrow$ $f$ is concave down in $I$.\n\t\t\t\t      \\end{itemize}\n\t\t\t\t\\item[Extrema] If $f'(a)=0$ (critical point)\n\t\t\t\t      \\begin{itemize}\n\t\t\t\t\t      \\item $f''(a)<0$ $\\Rightarrow$ $f$ has a local maximum at $x=a$.\n\t\t\t\t\t      \\item $f''(a)>0$ $\\Rightarrow$ $f$ has a local minimum at $x=a$.\n\t\t\t\t      \\end{itemize}\n\t\t\t\\end{description}\n\n\\begin{figure}[h]\n\\centering\n\\begin{minipage}{.5\\linewidth}\n  \\centering\n  \\includegraphics[trim={0 45pt 0 0},clip,width=.8\\linewidth]{concave_up}\n\\end{minipage}%\n\\begin{minipage}{.5\\linewidth}\n  \\centering\n  \\includegraphics[trim={0 45pt 0 0},clip,width=.8\\linewidth]{concave_down}\n\\end{minipage}\n\\caption{Concave up (left) and concave down (right)}\n\\end{figure}\n\\hformbar\n\n\n\n\\formdesc{Increasing and Decreasing Functions}\n\n\\begin{itemize}\n    \\item $f(x)$ is \\textit{increasing} iff $\\forall~ x_1, x_2$ in interval $I$ is such that $x_1 < x_2$ and $f(x_1) < f(x_2)$\n    \\item $f(x)$ is \\textit{decreasing} iff $\\forall~ x_1, x_2$ in interval $I$ is such that $x_1 > x_2$ and $f(x_1) > f(x_2)$\n    \\item Determine all intervals where $f(x)$ is in/decreasing:\n    \\begin{enumerate}\n        \\item Find all critical points (via first deriative)\n        \\item For each critical point, select a number $a$ in that range and see if $f'(a)$ is positive or negative\n    \\end{enumerate}\n\\end{itemize}\n\n\n\\hformbar\n\n\n\n\\formdesc{Inflection Points}\n\n\\begin{itemize}\n    \\item Where the second derivative changes signs\n    \\item The point(s) on a graph where the concavity of a function changes from up to down\n    \\item functions can be increasing (positive derivative) or decreasing (negative derivative) regardless of concavity,\n\\end{itemize}\n\\hformbar\n\n\n\n\n\n\n\\formdesc{Maxima And Minima}\n\nA \\textit{critical point} is a point where either $f'(a) = 0$ or $f'(a)$ is undefined, and is a \\textit{candidate} of being a local or global extreme\n\n\\subsection*{Local}\n\n\\begin{description}\n    \\item[maximum] at $a$ if $f(a) \\geq f(x)~ \\forall x$ near $a$\n    \\item[minimum] at $a$ if $f(a) \\leq f(x)~ \\forall x$ near $a$\n    \\item[extreme] at $a$ if $f(a)$ is a local maximum or minimum\n\\end{description}\n    \n\\subsection*{Global}\n\n\\begin{description}\n    \\item[maximum] at $a$ if $f(a) \\geq f(x)~ \\forall x$ in domain of $f$\n    \\item[minimum] at $a$ if $f(a) \\leq f(x)~ \\forall x$ in domain of $f$\n    \\item[extreme] at $a$ if $f(a)$ is a global maximum or minimum\n\\end{description}\n\n\\subsection*{Example}\n\nFind the critical point of $f(x) = x^3 - 6x^2 + 9x + 2$\n\n\\begin{enumerate}\n    \\item Find $f'(x)$\n        \\begin{eqnarray}\n            f'(x)  =  3x^2 - 12x + 9  \\\\\n                  &=& 3(x^2 - 4x + 3) \\\\\n                  &=& 3(x - 1)(x - 3) \\\\\n         \\end{eqnarray}\n     \\item Find where $f'(x) = 0$, which is 1 and 3\n     \\item Put $x=1$ and $x=3$ into $f(x)$ to find the critical points\n         \\begin{eqnarray}\n             (1, f(1)) &=& (1, 6) \\\\\n             (3, f(2)) &=& (3, 2)         \n         \\end{eqnarray}\n\\end{enumerate}\n\\hformbar\n\n\n\n\\formdesc{Antiderivatives}\n\n\\begin{itemize}\n    \\item \\textit{An} antiderivative of a function $f(x)$ is any function $F(x)$ such that $F'(x) = f(x)$\n    \\item \\textit{The} antiderivative is an entire family of functions, written $F(x) + c$\n    \\item Also known as the \\textit{indefinite integral} (with no limit markers):\n    \n    \\begin{equation}\n        \\int f(x)~ dx\n    \\end{equation}\n\\end{itemize}\n\n\\subsection*{Example}\n\n\\textit{An} antiderivative of $\\int 2x~ dx$ is $x^2 - 5.2$; \\textit{the} antiderative is $x^2 + C$\n\\hformbar\n\n\n\n\\formdesc{Definite v. Indefinite Integrals}\n\nIndefinite integrals do not have limits to integration where definite integrals do\n\\hformbar\n\n\n\n\\formdesc{Integration by Substitution}\n\nA method to algebraically manipulate an integrand so it is amenable to antiderivative rules; especially useful when there is a product in the integral.\n\nSubstitute $u$ for $g(x)$ where necessary, making $\\frac{du}{dx} = g'(x)$, so $du = g'(x)~ dx$. Since\n\n\\begin{equation}\n    \\frac{du}{dx} = g'(x) \\equiv du = g'(x)~ dx\n\\end{equation}\n\nwe can substitute so that\n\n\\begin{equation}\n    \\int f'(g(x)) g'(x)~ dx \\equiv \\int f'(u)~ du\n\\end{equation}\n\nNow integrate $f'(u)~ du$. (Note that $g(x) \\equiv u$ and $g'(x)~ dx \\equiv du$.)\n\n\\begin{enumerate}\n    \\item Set one part of the integrand to $u$, one ``level'' into the integral\n    \\item Compute $du = \\frac{du}{dx} ~dx$ (the derivative of $u$)\n    \\item Convert $x$'s to $u$'s in original integral, even including in $dx$\n    \\item Integrate new $u$ integral\n    \\item Substitute $u$'s back to $x$'s in integral\n\\end{enumerate}\n\n\\subsection*{Example}\n\nIntegrate $\\int (x + 1)^3~ dx$\n\n\\begin{enumerate}\n\t\\item Rearrange so that $u = x + 1$ and $du = 1~ dx$\n\t\t\\begin{equation}\n\t\t\t= \\int (x + 1)^3 \\cdot 1 ~ dx\n\t\t\\end{equation}\n\t\\item Substitute in $u$ and $du$\n\t\t\\begin{equation}\n\t\t\t\\int u^3 ~ du\n\t\t\\end{equation}\n\t\\item Integrate\n\t\t\\begin{equation}\n\t\t\t= \\frac{u^4}{4} + C\n\t\t\\end{equation}\n\t\\item Add $u$ back in\n\t\t\\begin{equation}\n\t\t\t= \\frac{(x + 1)^4}{4} + C\n\t\t\\end{equation}\n\\end{enumerate}\n\n\\hformbar\n\n\n\n\\formdesc{Integration by Parts}\n\nIntegrate a complex function by rewriting it as a product of two simpler functions $u$ and $du$, using two possible forms:\n\n\\begin{eqnarray}\n  \\int u ~dv     &=& uv - \\int v ~du \\\\\n  \\int_a^b u ~dv &=& uv |_a^b - \\int_a^b v ~du\n\\end{eqnarray}\n\n\\subsection{Example: First Form}\n\nIntegrate $\\int xe^x ~dx$:\n\n\\begin{enumerate}\n  \\item Break into two parts: $u = x$ and $dv = e^x ~dx$\n  \\item Calculate the derivative of $u$, $~du$, and $v$, the integral of $dv$\n\t\\begin{eqnarray}\n\t  du &=& \\left( \\frac{d}{dx} x \\right) ~dx = 1 ~dx \\\\\n\t  v &=& \\int dv = \\int e^x ~dx = e^x\n\t\\end{eqnarray}\n  \\item Using the first formula, noting the prior forms from 1 and 2\n\t\\begin{eqnarray}\n      \\int u ~dv &=& \\int x e^x ~dx \\\\\n\t             &=& xe^x - \\int e^x ~dv \\\\\n\t\t\t\t &=& xe^x - e^x + C\n     \\end{eqnarray}\n\\end{enumerate}\n\n\\subsection{Example: Second Form}\n\nIntegrate $\\int_1^4 6x^2 ln x ~dx$:\n\n\\begin{enumerate}\n\t\\item Break into two parts: $u = ln x$ and $dv = 6x^2$\n\t\\item Calculate the derivative of $u$, $du$, and the integral of $dv$, $v$:\n\t  \\begin{eqnarray}\n\t    du &=& \\frac{d}{dx} ln x = \\frac{1}{x} ~dx \\\\\n\t\tv  &=& \\int 6x^2 ~dx = 6 \\int x^2 ~dx = 6 \\cdot \\frac{x^3}{3} = 2x^3\n\t  \\end{eqnarray}\n\t\\item Use the second formula\n\t  \\begin{eqnarray}\n\t    \\int_1^4 6x^2 ln x ~dx &=& 2x^3 ln x |_1^4 - \\int_1^4 2x^3 \\frac{1}{x} ~dx \\\\\n\t\t&=& 2x^3 ln x |_1^4 - 3x^2 |_1^4\n\t  \\end{eqnarray}\n\t\\item Find the integral the usual way:\n\t  \\begin{eqnarray}\n\t    \\left[ (2 \\cdot 4^3 ln(4)) - (2 \\cdot 1^3 ln(1)\\right] - \\left[ (3 \\cdot 4^2) - (3 \\cdot 1^2)  \\right] \\\\\n\t\t  = 128 \\cdot ln(4) - 45 \\\\\n\t\t  \\approx 132.446\n\t  \\end{eqnarray}\n\\end{enumerate}\n\n\n\n\n\n\\hformbar\n\n\n\n\n\n\n\n\n\n\n\n\n\\formdesc{Antiderivative Rules}\n\n\\begin{center}\n\\[\n\\def\\arraystretch{2.5}\n \\begin{array}{cc}\n  \\int a\\,dx              & ax+C                   \\\\\n  \\int x^n\\,dx            & \\dfrac{u'}{2\\sqrt{u}}  \\\\\n  \\int e^x\\,dx            & e^x+C                  \\\\\n  \\int a^x\\,dx           & \\dfrac{a^x}{\\ln(a)}+C  \\\\\n  \\int \\dfrac{1}{x}\\, dx  &  \\ln|x|+C\n \\end{array}\n\\]\n\\end{center}\n\\hformbar\n\n\n\n\n\n\n\n\n\n\n\\newpage\n", "meta": {"hexsha": "d5b100fa94a25ec1ad3bfd142c92490a0fcaf54f", "size": 17128, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/calculus.tex", "max_stars_repo_name": "benhorvath/math_notes", "max_stars_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/calculus.tex", "max_issues_repo_name": "benhorvath/math_notes", "max_issues_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/calculus.tex", "max_forks_repo_name": "benhorvath/math_notes", "max_forks_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1710526316, "max_line_length": 221, "alphanum_fraction": 0.5749065857, "num_tokens": 6133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8774767906859264, "lm_q1q2_score": 0.7293087342356352}}
{"text": "\\documentclass{subfile}\n\n\\begin{document}\n\t\\section{Introduction}\\label{sec:intro}% power mean, cauchy schwarz\n\tLet us start with the most fundamental inequality.\n\t\t\\begin{align}\n\t\t\tx^2\n\t\t\t\t& \\geq0\\label{ineq:mother}\n\t\t\\end{align}\n\tThe first author calls it the \\index{mother of all inequality}mother of all inequality. Equality occurs if and only if $x=0$. We can extend it for $n$ variables.\n\t\t\\begin{align}\n\t\t\tx_1^2+\\ldots+x_n^2\n\t\t\t\t& \\geq0\\label{ineq:extendedmother}\n\t\t\\end{align}\n\tEquality occurs if $x_i=0$ for all $1\\leq i\\leq n$. We immediately get some useful results substituting $x$ with appropriate expressions. Substituting $x$ with $a-b$, we get\n\t\t\\begin{align*}\n\t\t\t(a-b)^2\n\t\t\t\t& \\geq0\\\\\n\t\t\ta^2+b^2\n\t\t\t\t& \\geq2ab\n\t\t\\end{align*}\n\tThis is true for any real numbers $a,b$ and equality occurs if $a=b$. If $a,b$ are positive, then replacing $a$ and $b$ by $\\sqrt{a}$ and $\\sqrt{b}$ respectively, we get\n\t\t\\begin{align*}\n\t\t\ta+b\n\t\t\t\t& \\geq2\\sqrt{ab}\\\\\n\t\t\t\\iff\\sqrt{\\dfrac{a}{b}}+\\sqrt{\\dfrac{b}{a}}\n\t\t\t\t& \\geq2\\\\\n\t\t\t\\iff x+\\dfrac{1}{x}\n\t\t\t\t& \\geq2\n\t\t\\end{align*}\n\twhere $x=\\dfrac{a}{b}$. This can be generalized to the following result.\n\t\t\\begin{theorem}[\\itshape \\index{Arithmetic-Geometric Inequality}Arithmetic-Geometric Inequality]\\label{thm:amgm}\n\t\t\tLet $a_1,\\ldots,a_n$ be positive real numbers. Then\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{a_1+\\ldots+a_n}{n}\n\t\t\t\t\t\t& \\geq\\sqrt[n]{a_1\\cdots a_n}\\\\\n\t\t\t\t\t\\iff a_1+\\ldots+a_n\n\t\t\t\t\t\t& \\geq n\\sqrt[n]{a_1\\cdots a_n}\\\\\n\t\t\t\t\t\\iff \\left(\\dfrac{a_1+\\ldots+a_n}{n}\\right)^n\n\t\t\t\t\t\t& \\geq a_1\\cdots a_n\n\t\t\t\t\\end{align*}\n\t\t\\end{theorem}\n\tWe will show a classical proof of this result here. The proof is due to \\textcite{cauchy_1821}. Later in \\autoref{sec:powermean}, \\autoref{sec:mazorization} we will show more proofs.\n\t\t\\begin{proof}\n\n\t\t\\end{proof}\n\tNote the following.\n\t\t\\begin{align*}\n\t\t\t\\dfrac{a+b}{2}\n\t\t\t\t& \\geq\\sqrt{ab}\n\t\t\\end{align*}\n\tNow, $\\frac{a+b}{2}$ is the \\index{arithmetic mean}\\textit{arithmetic mean} of $a$ and $b$. On the right side, $\\sqrt{ab}$ is the \\index{geometric mean}\\textit{geometric mean} of $a$ and $b$. So the inequality states that the arithmetic mean of two positive real numbers is greater than or equal to their geometric mean. We can also rewrite it as the following.\n\t\t\\begin{align*}\n\t\t\t\\sqrt{ab}\\left(\\dfrac{a+b}{2}\\right)\n\t\t\t\t& \\geq ab\\\\\n\t\t\t\\sqrt{ab}\n\t\t\t\t& \\geq\\dfrac{2ab}{a+b}\\\\\n\t\t\t\\sqrt{ab}\n\t\t\t\t& \\geq\\dfrac{2}{\\frac{1}{a}+\\frac{1}{b}}\n\t\t\\end{align*}\n\t$\\dfrac{2ab}{a+b}$ is the \\index{harmonic mean}\\textit{harmonic mean} of $a$ and $b$. So, this form of the inequality states that the geometric mean is larger than the harmonic mean. This can be extended for three variables.\n\t\t\\begin{align*}\n\t\t\t\\dfrac{a+b+c}{3}\n\t\t\t\t& \\geq\\dfrac{3}{\\dfrac{1}{a}+\\dfrac{1}{b}+\\dfrac{1}{c}}\n\t\t\\end{align*}\n\tIn fact, this result can be extensively generalized. First, we can consider $n$ variables $a_1,\\ldots,a_n$ instead of just $a$ and $b$. Second, we can generalize the fact that $AM\\geq GM\\geq HM$. We will talk about this generalization in \\autoref{sec:powermean}.\n\t\t\\begin{problem}\n\t\t\tIf $a$ is a real number greater than one, prove that $\\log{a}+\\log_{a}{e}\\geq2$.\n\t\t\\end{problem}\n\tThroughout the book, if the base of logarithm is unspecified, then $\\log{a}$ shall mean $\\log_{e}{a}$. Also, try the next problem in a similar manner.\n\t\t\\begin{problem}\n\t\t\tProve the inequality\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{x^2}{1+x^4}\n\t\t\t\t\t\t& \\leq\\dfrac{1}{2}\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\tRecall from the definition of $e$ that\n\t\t\\begin{align*}\n\t\t\te^x\n\t\t\t\t& = 1+x+\\dfrac{x^2}{2!}+\\dfrac{x^3}{3!}+\\ldots\\\\\n\t\t\t\t& = \\sum\\limits_{i\\geq0}\\dfrac{x^i}{i!}\n\t\t\\end{align*}\n\tYou may also know from elementary differentiation that\n\t\t\\begin{align*}\n\t\t\t\\lim\\limits_{n\\to\\infty}\\left(1+\\dfrac{1}{n}\\right)^n\n\t\t\t\t& = e\n\t\t\\end{align*}\n\tIn other words, if $x_n=\\left(1+\\frac{1}{n}\\right)^n$, then $x_n$ converges to $e$. However, we also have the relation that $x_n\\leq x_{n+1}$. While we can prove this using induction, we will show a better proof with arithmetic-geometric mean inequality here.\n\t\t\\begin{problem}\n\t\t\tLet $x_n=\\left(1+\\frac{1}{n}\\right)^n$. Prove that $x_n\\leq x_{n+1}$.\n\t\t\t\t\\begin{solution}\n\t\t\t\t\tApply the arithmetic-geometric mean inequality for $a_1=1,a_2=1+\\frac{1}{n},\\ldots,a_{n+1}=1+\\frac{1}{n}$,\n\t\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\t1+\\left(1+\\dfrac{1}{n}\\right)+\\ldots+\\left(1+\\dfrac{1}{n}\\right)\n\t\t\t\t\t\t\t\t& \\geq(n+1)\\sqrt[n+1]{1\\cdot\\left(1+\\dfrac{1}{n}\\right)\\cdots\\left(1+\\dfrac{1}{n}\\right)}\\\\\n\t\t\t\t\t\t\tn+2\n\t\t\t\t\t\t\t\t& \\geq(n+1)\\sqrt[n+1]{\\left(1+\\dfrac{1}{n}\\right)^n}\\\\\n\t\t\t\t\t\t\t1+\\dfrac{1}{n+1}\n\t\t\t\t\t\t\t\t& \\geq\\sqrt[n+1]{\\left(1+\\dfrac{1}{n}\\right)^n}\\\\\n\t\t\t\t\t\t\t\\left(1+\\dfrac{1}{n+1}\\right)^{n+1}\n\t\t\t\t\t\t\t\t& \\geq\\left(1+\\dfrac{1}{n}\\right)^n\n\t\t\t\t\t\t\\end{align*}\n\t\t\t\t\\end{solution}\n\t\t\\end{problem}\n\tNote that we can generalize the idea used in this problem.\n\t\t\\begin{problem}\n\t\t\tFor positive real numbers $x,y$ show that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\left(\\dfrac{x+ny}{n+1}\\right)^{n+1}\n\t\t\t\t\t\t& \\geq xy^n\n\t\t\t\t\\end{align*}\n\t\t\tEquality occurs only for $x=y$.\n\t\t\\end{problem}\n\tSimilarly, we can show the following.\n\t\t\\begin{problem}\n\t\t\tLet $y_n=\\left(1+\\frac{1}{n}\\right)^{n+1}$. Show that $y_n\\geq y_{n+1}$.\n\t\t\\end{problem}\n\tSo $y_n$ is decreasing. Using the two problems above, show that $2<e<4$. In fact, we can prove the following using elementary means\n\t\t\\begin{align*}\n\t\t\t\\lim\\limits_{n\\to\\infty}y_{n}\n\t\t\t\t& = \\lim\\limits_{n\\to\\infty}x_{n}=e\n\t\t\\end{align*}\n\n\t\t\\begin{problem}\n\t\t\tFor a positive integer $n$, show that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\left(\\dfrac{n+1}{2}\\right)^{n}\n\t\t\t\t\t\t& \\geq n!\n\t\t\t\t\\end{align*}\n\t\t\tEquality occurs only for $n=1$.\n\t\t\t\t\\begin{solution}\n\t\t\t\t\tWe use arithmetic-geometric inequality for $1,2,\\ldots,n$.\n\t\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\t1+\\ldots+n\n\t\t\t\t\t\t\t\t& \\geq n\\sqrt[n]{1\\cdots n}\\\\\n\t\t\t\t\t\t\t\\dfrac{n(n+1)}{2}\n\t\t\t\t\t\t\t\t& \\geq n\\sqrt[n]{n!}\\\\\n\t\t\t\t\t\t\t\\dfrac{n+1}{2}\n\t\t\t\t\t\t\t\t& \\geq\\sqrt[n]{n!}\n\t\t\t\t\t\t\\end{align*}\n\t\t\t\t\tEquality occurs if and only if $1=\\ldots=n$ which is possible only when $n=1$.\n\t\t\t\t\\end{solution}\n\t\t\\end{problem}\n\tLet us again go back to the mother of inequality. Setting $x_1=a-b,x_2=b-c,x_3=c-a$ in \\ref{ineq:extendedmother},\n\t\t\\begin{align*}\n\t\t\t(a-b)^2+(b-c)^2+(c-a)^2\n\t\t\t\t& \\geq0\\\\\n\t\t\t\\iff a^2+b^2+c^2-ab-bc-ca\n\t\t\t\t& \\geq0\\\\\n\t\t\t\\iff a^2+b^2+c^2\n\t\t\t\t& \\geq ab+bc+ca\n\t\t\\end{align*}\n\tWe could prove this using $a^2+b^2\\geq2ab$ repeatedly.\n\t\t\\begin{align*}\n\t\t\ta^2+b^2\n\t\t\t\t& \\geq2ab\\\\\n\t\t\tb^2+c^2\n\t\t\t\t& \\geq2bc\\\\\n\t\t\tc^2+a^2\n\t\t\t\t& \\geq2ca\\\\\n\t\t\t2(a^2+b^2+c^2)\n\t\t\t\t& \\geq2(ab+bc+ca)\\\\\n\t\t\ta^2+b^2+c^2-ab-bc-ca\n\t\t\t\t& \\geq0\n\t\t\\end{align*}\n\tMultiplying both sides by $(a+b+c)$ and using the fact $a^3+b^3+c^3-3abc=(a+b+c)(a^2+b^2+c^2-ab-bc-ca)$,\n\t\t\\begin{align*}\n\t\t\ta^3+b^3+c^3-3abc\n\t\t\t\t& \\geq0\\\\\n\t\t\ta^3+b^3+c^3\n\t\t\t\t& \\geq3abc\n\t\t\\end{align*}\n\tReplacing $a^3,b^3,c^3$ by $u,v,w$,\n\t\t\\begin{align}\n\t\t\tu+v+w\n\t\t\t\t& \\geq3\\sqrt[3]{uvw}\\label{ineq:amgm3}\n\t\t\\end{align}\n\tBefore we go into any theory or method of solving problems, here are some basic tactics which are used very often for solving problems. Let $x,y,z>0$ be real numbers.\n\t\t\\begin{enumerate}[\\itshape (i)]\n\t\t\t\\item If $\\dfrac{1}{x}\\geq\\dfrac{1}{y}$, then $\\dfrac{1}{x-a}\\geq\\dfrac{1}{y}$ for $a\\geq0$. Similarly, $\\dfrac{1}{x}\\geq\\dfrac{1}{y-b}$ for $b\\geq0$. They are true because $x-a\\leq x$ implies $\\dfrac{1}{x-a}\\geq\\dfrac{1}{x}$ and $y+b\\geq y$ implies $\\dfrac{1}{y+b}\\leq\\dfrac{1}{y}$.\n\t\t\t\\item Check if you can assume an ordering on the variables. For example, if the inequality is symmetric or cyclic on $x,y,z$, you may possibly assume without loss of generality that $x\\geq y\\geq z$ or $x\\leq y\\leq z$. We will discuss more on this in \\autoref{sec:buffalo}.\n\t\t\t\\item If you cannot assume an ordering on the variables e.g. $a\\geq b\\geq c$, can you assume that it has a \\textit{maximal element} e.g. $a=\\max(a,b,c)$? Sometimes this helps in unexpected ways. See the example below.\n\t\t\t\\item See if you can get an \\textit{if and only if} way of proving an inequality. We will do this very often. If we can use if and only if (or \\textit{iff}), then we are free to prove either the if part or the only if part.\n\t\t\t\\item Check if you can get some familiar expressions with some basic manipulations such as making the numerator or denominator equal. For example, see the transformation in \\ref{eqn:nesbittf}. This often helps us get a clue on what to do with the inequality.\n\t\t\t\\item Does some substitutions such as $x=a+b,y=b+c,z=c+a$ or $x=a-b,y=b-c,z=c-a$ help? One could say we used substitution in our first proof of Nesbitt's inequality (see \\ref{eqn:nesbittsub}). Also, see the transformation $a-c=a-b+b-c$ used in the example below. We will check more on substitutions in \\autoref{sec:subs}.\n\t\t\t\\item Check if the inequality holds even if you put some restrictions on it. For example, you may be allowed to assume that one of the variables is $1$ due to some scaling. We will talk about this in \\autoref{sec:homonorm}.\n\t\t\t\\item Can you reduce the number of variables without any assumption? See that we have already used it to prove $a^2+b^2+c^2\\geq ab+bc+ca$ in a proof above. Also, see a proof of Nesbitt's inequality below where it is enough to prove the inequality for reduced number of variables.\n\t\t\t\\item Induction works great in many cases. We will use induction on many occasions.\n\t\t\\end{enumerate}\n\tFor demonstration purposes, let us prove $a^2+b^2+c^2\\geq ab+bc+ca$ again exploiting symmetry. Note that if we let\n\t\t\\begin{align*}\n\t\t\tf(a,b,c)\n\t\t\t\t& = a^2+b^2+c^2-ab-bc-ca\n\t\t\\end{align*}\n\tthen $f(a,b,c)$ is \\textit{symmetric} on $a,b,c$. We can verify this by the fact that $f(a,b,c)=f(b,a,c)=f(c,a,b)$ and so on. So, without loss of generality, we assume that $a\\geq b\\geq c$. Then see the following.\n\t\t\\begin{align*}\n\t\t\ta^2+b^2+c^2\n\t\t\t\t& \\geq ab+bc+ca\\\\\n\t\t\ta(a-b)+b(b-c)-c(a-c)\n\t\t\t\t& \\geq0\\\\\n\t\t\ta(a-b)+b(b-c)-c(a-b+b-c)\n\t\t\t\t& \\geq0\\\\\n\t\t\ta(a-b)+b(b-c)-c(a-b)-c(b-c)\n\t\t\t\t& \\geq0\\\\\n\t\t\t(a-c)(a-b)+(b-c)^2\n\t\t\t\t& \\geq0\n\t\t\\end{align*}\n\tThe last inequality immediately follows from the assumption that $a-c\\geq0,a-b\\geq0,(b-c)^2\\geq0$. Also, note that we did not actually require the condition $a\\geq b\\geq c$. Just assuming $a=\\max(a,b,c)$ was enough in this case to claim that the inequality holds.\n\t\t\\begin{theorem}[\\itshape \\index{Nesbitt's inequality}Nesbitt's inequality]\\label{thm:nesbitt}\n\t\t\tLet $a,b,c$ be real positive numbers. Then\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{a}{b+c}+\\dfrac{b}{c+a}+\\dfrac{c}{a+b}\n\t\t\t\t\t\t& \\geq\\dfrac{3}{2}\n\t\t\t\t\\end{align*}\n\t\t\tand equality occurs if and only $a=b=c$.\n\t\t\\end{theorem}\n\tThe thing about inequalities is that they can be solved in more than one ways most of the times. We will  prove this inequality along with some other classical results such as \\textit{Cauchy-Schwarz inequality} in more than one ways. Some proofs will be discussed later when we develop some certain techniques. For now, we present some proofs using what we have already developed.\n\tFirst, we will try to \\textit{familiarize} the expression on the left side.\n\t\t\\begin{align}\n\t\t\tS\n\t\t\t\t& = \\dfrac{a}{b+c}+\\dfrac{b}{c+a}+\\dfrac{c}{a+b}\\nonumber\\\\\n\t\t\t\t& = \\dfrac{a+b+c}{b+c}-1+\\dfrac{a+b+c}{c+a}-1+\\dfrac{a+b+c}{a+b}-1\\nonumber\\\\\n\t\t\t\t& = (a+b+c)\\left(\\dfrac{1}{b+c}+\\dfrac{1}{c+a}+\\dfrac{1}{a+b}\\right)-3\\nonumber\\\\\n\t\t\t\t& = \\dfrac{1}{2}(a+b+b+c+c+a)\\left(\\dfrac{1}{b+c}+\\dfrac{1}{c+a}+\\dfrac{1}{a+b}\\right)-3\\label{eqn:nesbittf}\n\t\t\\end{align}\n\n\t\t\\begin{proof}[\\itshape Classical proof]\n\t\t\tSetting\n\t\t\t\t\\begin{align}\n\t\t\t\t\tx=a+b,\n\t\t\t\t\t\t& y=b+c,z=c+a\\label{eqn:nesbittsub}\n\t\t\t\t\\end{align}\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tS\n\t\t\t\t\t\t& = \\dfrac{1}{2}(x+y+z)\\left(\\dfrac{1}{x}+\\dfrac{1}{y}+\\dfrac{1}{z}\\right)-3\\\\\n\t\t\t\t\t\t& = \\dfrac{1}{2}\\left(1+\\dfrac{x}{y}+\\dfrac{x}{z}+\\dfrac{y}{x}+1+\\dfrac{y}{z}+\\dfrac{z}{x}+\\dfrac{z}{y}+1\\right)-3\\\\\n\t\t\t\t\t\t& = \\dfrac{3}{2}+\\dfrac{1}{2}\\left(\\dfrac{x}{y}+\\dfrac{y}{x}+\\dfrac{y}{z}+\\dfrac{z}{y}+\\dfrac{z}{x}+\\dfrac{x}{z}\\right)-3\\\\\n\t\t\t\t\t\t& = \\dfrac{3}{2}+\\dfrac{1}{2}\\left(u+\\dfrac{1}{u}+v+\\dfrac{1}{v}+w+\\dfrac{1}{w}\\right)-3\n\t\t\t\t\\end{align*}\n\t\t\twhere $u=\\dfrac{x}{y},v=\\dfrac{y}{z},w=\\dfrac{z}{x}$. Evidently, $u+\\frac{1}{u}\\geq2,v+\\frac{1}{v}\\geq2,w+\\frac{1}{w}\\geq2$ and we have\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tS\n\t\t\t\t\t\t& \\geq\\dfrac{3}{2}+\\dfrac{1}{2}(2+2+2)-3\n\t\t\t\t\\end{align*}\n\t\t\tThus, $S\\geq\\frac{3}{2}$. Equality occurs if $u=1,v=1,z=1$ or $x=y=z$ or $a=b=c$.\n\t\t\\end{proof}\n\n\t\t\\begin{proof}[\\itshape Proof by arithmetic-harmonic mean inequality]\n\t\t\tWe write the arithmetic-harmonic mean inequality for $u,v,w$ as below.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{u+v+w}{3}\n\t\t\t\t\t\t& \\geq\\dfrac{3}{\\dfrac{1}{u}+\\dfrac{1}{v}+\\dfrac{1}{v}}\\\\\n\t\t\t\t\t\\iff(u+v+w)\\left(\\dfrac{1}{u}+\\dfrac{1}{v}+\\dfrac{1}{w}\\right)\n\t\t\t\t\t\t& \\geq9\n\t\t\t\t\\end{align*}\n\t\t\tUsing this on \\ref{eqn:nesbittf},\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tS\n\t\t\t\t\t\t& \\geq\\dfrac{1}{2}\\cdot9-2\n\t\t\t\t\\end{align*}\n\t\t\\end{proof}\n\n\t\t\\begin{proof}[\\itshape \\index{Variable reduction}Variable reduction proof]\n\t\t\tLet us clear the denominators in the original inequality.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{a}{b+c}+\\dfrac{b}{c+a}+\\dfrac{c}{a+b}\n\t\t\t\t\t\t& \\geq\\dfrac{3}{2}\\\\\n\t\t\t\t\t\\iff2(a^3+b^3+c^3)\n\t\t\t\t\t\t& \\geq a^2b+ab^2+b^2c+bc^2+c^2a+ca^2\n\t\t\t\t\\end{align*}\n\t\t\tNotice the cyclic nature in the expression on the right side. There are $6$ terms on the right side and if we count each of $a^3,b^3,c^3$ twice, there are $6$ terms on the left side as well. So rearranging the inequality above as below\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t(a^3+b^3)+(b^3+c^3)+(c^3+a^3)\n\t\t\t\t\t\t& \\geq (a^2b+ab^2)+(b^2c+bc^2)+(c^2a+ca^2)\n\t\t\t\t\\end{align*}\n\t\t\ttells us that if we can prove $x^3+y^3\\geq x^2y+xy^2$, we will be done if we simply sum them up for $(x,y)=(a,b),(b,c),(c,a)$. Here, we reduced the inequality from $3$ variables to $2$. And fortunately, this inequality is a lot easier to prove.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tx^3+y^3\n\t\t\t\t\t\t& \\geq x^2y+xy^2\\\\\n\t\t\t\t\t\\iff x(x^2-y^2)-y(x^2-y^2)\n\t\t\t\t\t\t& \\geq0\\\\\n\t\t\t\t\t\\iff (x-y)(x^2-y^2)\n\t\t\t\t\t\t& \\geq0\\\\\n\t\t\t\t\t\\iff(x-y)^2(x+y)\n\t\t\t\t\t\t& \\geq0\n\t\t\t\t\\end{align*}\n\t\t\tThe last inequality is evidently true.\n\t\t\\end{proof}\n\n\t\t\\begin{proof}[\\itshape Proof using arithmetic-geometric mean inequality]\n\t\t\tUsing \\ref{ineq:amgm3},\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t(a+b)+(b+c)+(c+a)\n\t\t\t\t\t\t& \\geq3\\sqrt[3]{(a+b)(b+c)(c+a)}\\\\\n\t\t\t\t\t\\dfrac{1}{a+b}+\\dfrac{1}{b+c}+\\dfrac{1}{c+a}\n\t\t\t\t\t\t& \\geq3\\sqrt[3]{\\dfrac{1}{(a+b)(b+c)(c+a)}}\n\t\t\t\t\\end{align*}\n\t\t\tWe can use this observation on \\ref{eqn:nesbittf} and get the following.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tS\n\t\t\t\t\t\t& \\geq\\dfrac{1}{2}\\cdot3\\sqrt[3]{(a+b)(b+c)(c+a)}\\cdot3\\sqrt[3]{\\dfrac{1}{(a+b)(b+c)(c+a)}}-2\\\\\n\t\t\t\t\t\t& \\geq\\dfrac{9}{2}-2=\\dfrac{3}{2}\n\t\t\t\t\\end{align*}\n\t\t\tThis again proves the inequality.\n\t\t\\end{proof}\n\t\\textcite{anovic_pecaric_2011} proves the following generalization of \\nameref{thm:nesbitt}.\n\t\t\\begin{theorem}[Generalization of Nesbitt's inequality]\n\t\t\tLet $x,y,z$ be positive real numbers and\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tM\n\t\t\t\t\t\t& = \\max\\left\\{\\dfrac{x}{y+z}+\\dfrac{2(y+z)}{2x+y+z},\\dfrac{y}{z+x}+\\dfrac{2(z+x)}{2y+z+x},\\dfrac{z}{x+y}+\\dfrac{2(x+y)}{2z+x+y}\\right\\}\\\\\n\t\t\t\t\tm\n\t\t\t\t\t\t& =  \\min\\left\\{\\dfrac{x}{y+z}+\\dfrac{2(y+z)}{2x+y+z},\\dfrac{y}{z+x}+\\dfrac{2(z+x)}{2y+z+x},\\dfrac{z}{x+y}+\\dfrac{2(x+y)}{2z+x+y}\\right\\}\n\t\t\t\t\\end{align*}\n\t\t\tThen\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{x}{y+z}+\\dfrac{y}{z+x}+\\dfrac{z}{x+y}\n\t\t\t\t\t\t& \\geq M\\geq m\\geq \\dfrac{3}{2}\n\t\t\t\t\\end{align*}\n\t\t\\end{theorem}\n\tWe have already showed that $a+b\\geq2\\sqrt{ab}$ which is a special case of the arithmetic-geometric mean inequality. Let us consider the following question. We are given four positive real numbers $a,b,c,d$ such that $S=a+b=c+d$. Which of the products between $ab$ and $cd$ is the smaller one?\n\t\t\\begin{align*}\n\t\t\t4ab\n\t\t\t\t& = (a+b)^2-(a-b)^2\\\\\n\t\t\t\t& = S^2-(a-b)^2\\\\\n\t\t\t4cd\n\t\t\t\t& = (c+d)^2-(c-d)^2\\\\\n\t\t\t\t& = S^2-(c-d)^2\n\t\t\\end{align*}\n\tAs we can see here, the sign in $4ab?4cd$ ($?$ to be replaced by one of $>,<,\\geq,\\leq$) will be dictated by which of the differences $a-b,c-d$ is smaller. Since $x^2\\geq0$, if $(a-b)^2<(c-d)^2$, we have $4ab>4cd$. Now, consider the product $a_1\\cdots a_n$. We want to see how the product changes as $a_i$ varies with respect to $\\bar{a}=\\frac{a_1+\\ldots+a_n}{n}$.\n\n\tIf all the $a_i$ are equal to each other, then we have nothing to check. Otherwise, there are at least two positive integers $i$ and $j$ such that $a_i$ and $a_j$ are not equal to $\\bar{a}$. Moreover, one of them is greater than $\\bar{a}$ and the other is smaller than $\\bar{a}$ because all of them cannot be greater (or smaller) than $\\bar{a}$. Without loss of generality, assume that $a_1,a_2$ are those two numbers and $a_1=\\bar{a}-h,a_2=\\bar{a}+k$. Now, consider two other positive numbers $c$ and $d$ which keeps the sum fixed, for example $c=\\bar{a},d=\\bar{a}+k-h$. We have\n\t\t\\begin{align*}\n\t\t\tcd\n\t\t\t\t& = \\bar{a}(\\bar{a}+k-h)\\\\\n\t\t\t\t& = \\bar{a}^2+\\bar{a}k-\\bar{a}h\\\\\n\t\t\ta_1a_2\n\t\t\t\t& = (\\bar{a}-h)(\\bar{a}+k)\\\\\n\t\t\t\t& = \\bar{a}^2+\\bar{a}k-\\bar{a}h-hk\\\\\n\t\t\t\t& = cd-hk < cd\\\\\n\t\t\ta_1a_2\\cdots a_n\n\t\t\t\t& < cd\\cdots a_n\n\t\t\\end{align*}\n\tThis basically tells us that we can increase the product further if there are other $a_i$ which are not equal to $\\bar{a}$ and the product is maximum when all $a_i$ is equal to $\\bar{a}$.\n\t\t\\begin{problem}\n\t\t\tShow that for a positive integer $n$,\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tn!\n\t\t\t\t\t\t& > \\left(\\dfrac{n}{4}\\right)^n\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\tWe can easily prove this with induction. This can be improved to $n!>\\left(\\dfrac{n}{3}\\right)^n$. In fact, we can prove the following.\n\t\t\\begin{align*}\n\t\t\tn!\n\t\t\t\t& > \\left(\\dfrac{n}{e}\\right)^n\n\t\t\\end{align*}\n\tThis is another nice result. For example, setting $n=2019$,\n\t\t\\begin{align*}\n\t\t\t2019!\n\t\t\t\t& > 673^{2019}\n\t\t\\end{align*}\n\tWe can even bound $n!$ from both sides with the next result.\n\t\t\\begin{problem}\n\t\t\tFor a positive integer $n$, prove the inequality\n\t\t\t\t\\begin{align*}\n\t\t\t\t\te\\left(\\dfrac{n+1}{e}\\right)^{n+1}\n\t\t\t\t\t\t& > n!>\\left(\\dfrac{n}{e}\\right)^n\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\tEquality is not possible because on both sides we have non-integers.\n\t\t\\begin{problem}\n\t\t\tLet $x,y,z$ be positive real numbers. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{2}{x+y}+\\dfrac{2}{y+z}+\\dfrac{2}{z+x}\n\t\t\t\t\t\t& \\geq \\dfrac{9}{x+y+z}\n\t\t\t\t\\end{align*}\n\n\t\t\t\t\\begin{solution}\n\n\t\t\t\t\\end{solution}\n\t\t\\end{problem}\n\tA function $f$ is \\textit{non-decreasing} (resp. \\textit{increasing}) on the interval $I$ if for any $a,b\\in I$, $(a-b)(f(a)-f(b))\\geq0$ (resp. $(a-b)(f(a)-f(b))>0$). Similarly, $f$ is \\textit{non-increasing} (resp. \\textit{decreasing}) on the interval $I$ if for any $a,b\\in I$, $(a-b)(f(a)-f(b))\\leq0$ (resp. $(a-b)(f(a)-f(b))<0$). If either of these two conditions apply for $f$, then $f$ is a \\index{monotone function}\\textit{monotone function}. We say that $f$ is \\textit{monotonic}.\n\tNote that the slope between any two points $(a,f(a))$ and $(b,f(b))$ is $m=\\frac{f(a)-f(b)}{a-b}$ and the quantity we have used for the definition is\n\t\t\\begin{align*}\n\t\t\t(a-b)(f(a)-f(b))\n\t\t\t\t& = (a-b)^2\\dfrac{f(a)-f(b)}{f(a)-f(b)}\\\\\n\t\t\t\t& = (a-b)^2m\n\t\t\\end{align*}\n\tSo, the sign of this quantity is the same as the sign of the slope $m$.\n\n\tA sequence $(a_n)$ is \\textit{non-decreasing} if $a_i\\leq a_{i+1}$ for all $i\\in\\mathbb{N}$. $(a_n)$ is \\textit{strictly increasing} if $a_i<a_{i+1}$. Similarly, $(a_n)$ is \\textit{non-increasing} if $a_i\\geq a_{i+1}$ for all $i$. $(a_n)$ is \\textit{strictly decreasing} if $a_i>a_{i+1}$. If $(a_n)$ is either increasing or decreasing, then $(a_n)$ is a \\textit{monotone sequence}. We say that $(a_n)$ is \\textit{monotonic}.\n\t\t\\begin{theorem}[\\itshape Abel formula]\\label{thm:abelform}\n\t\t\tLet $(a_{n})$ and $(b_{n})$ be two sequences of real numbers. If $c_{k}=b_{1}+\\ldots+b_{k}$ for $1\\leq k\\leq n$, then\n\t\t\t\t\\begin{align*}\n\t\t\t\t\ta_{1}b_{1}+\\ldots+a_{n}b_{n}\n\t\t\t\t\t\t& = (a_{1}-a_{2})c_{1}+(a_{2}-a_{3})c_{2}+\\ldots+(a_{n-1}-a_{n})c_{n}+a_{n}c_{n}\n\t\t\t\t\\end{align*}\n\n\t\t\t\t\\begin{proof}\n\n\t\t\t\t\\end{proof}\n\t\t\\end{theorem}\n\n\t\t\\begin{theorem}[\\itshape Abel's Inequality]\\label{thm:abelineq}\n\t\t\tLet $(a_n)$ and $(b_n)$ be two sequences of real numbers such that $b_1\\geq \\ldots\\geq b_n\\geq0$. For $1\\leq k\\leq n$, define\n\t\t\t\t\\begin{align*}\n\t\t\t\t\ts_k\n\t\t\t\t\t\t& = a_1+\\ldots+a_k\\\\\n\t\t\t\t\tm\n\t\t\t\t\t\t& = \\min_{1\\leq i\\leq n}(s_i)\\\\\n\t\t\t\t\tM\n\t\t\t\t\t\t& = \\max_{1\\leq i\\leq n}(s_i)\n\t\t\t\t\\end{align*}\n\t\t\tThen we have\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tmb_1\n\t\t\t\t\t\t& \\leq a_1b_1+\\ldots+a_nb_n\\leq  Mb_1\n\t\t\t\t\\end{align*}\n\t\t\\end{theorem}\n\n\t\t\\begin{proof}\n\t\t\tWrite the sum $a_1b_1+\\ldots+a_nb_n$ as the following.\n\t\t\t\t\\begin{flalign*}\n\t\t\t\t\ta_1b_1+\\ldots+a_nb_n\n\t\t\t\t\t\t& = s_1b_1+(s_2-s_1)b_2+\\ldots+(s_n-s_{n-1})b_n\\\\\n\t\t\t\t\t\t& = s_1(b_1-b_2)+s_2(b_2-b_3)+\\ldots+s_{n-1}(b_{n-1}-b_n)+s_nb_n\n\t\t\t\t\\end{flalign*}\n\t\t\tUsing $m\\leq s_i\\leq M$,\n\t\t\t\t\\begin{flalign*}\n\t\t\t\t\tm(b_1-b_2)\n\t\t\t\t\t\t& \\leq s_1(b_1-b_2) \\leq M(b_1-b_2)\\\\\n\t\t\t\t\t\t& \\vdots\\\\\n\t\t\t\t\tm(b_{n-1}-b_{n})\n\t\t\t\t\t\t& \\leq s_{n-1}(b_{n-1}-b_n)\\leq M(b_{n-1}-b_n)\n\t\t\t\t\\end{flalign*}\n\t\t\tWe additionally have $mb_n\\leq s_nb_n\\leq Mb_n$. Summing these inequalities together,\n\t\t\t\t\\begin{flalign*}\n\t\t\t\t\tm(b_1-b_2+b_2-b_3+\\ldots+b_{n-1}-b_n)+mb_n\n\t\t\t\t\t\t& \\leq s_1(b_1-b_2)\\\\\n\t\t\t\t\t\t& +\\ldots+s_{n-1}(b_{n-1}-b_n)+s_nb_n\\\\\n\t\t\t\t\t\t& \\leq M(b_1-b_2+b_2-b_3+\\ldots\\\\\n\t\t\t\t\t\t& +b_{n-1}-b_n)+Mb_n\\\\\n\t\t\t\t\tmb_1\n\t\t\t\t\t\t& \\leq a_1b_1+\\ldots+a_nb_n\\leq Mb_1\n\t\t\t\t\\end{flalign*}\n\t\t\tThis proves the inequality.\n\t\t\\end{proof}\n\t% What about Aczel's inequality?\n\t\\section{Warm Up Problems}\n\tTry the following problems as warm up exercises.\n\t\t\\begin{problem}\n\t\t\tFor real numbers $x,y$, prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t|x+y|\n\t\t\t\t\t\t& \\leq|x|+|y|\\\\\n\t\t\t\t\t||x|-|y||\n\t\t\t\t\t\t& \\leq|x+y|\\\\\n\t\t\t\t\t(|x|-|y|)^2\n\t\t\t\t\t\t& \\leq|x^2-y^2|\n\t\t\t\t\\end{align*}\n\t\t\tWhen does equality occur in the last inequality?\n\t\t\\end{problem}\n\tThe first inequality in this problem is also known as the \\index{triangle inequality}\\textit{triangle inequality}.\n\t\t\\begin{problem}\n\t\t\tProve \\index{Jordan's inequality}\\textit{Jordan's inequality}.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{2}{\\pi}\n\t\t\t\t\t\t& \\leq\\dfrac{\\sin{\\theta}}{\\theta}<1\n\t\t\t\t\\end{align*}\n\t\t\tfor $0<|\\theta|<\\frac{\\pi}{2}$.\n\t\t\\end{problem}\n\n\t\t\\begin{problem}\n\t\t\tProve \\index{Redheffer's inequality}\\textit{Redheffer's inequality}.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{\\sin{\\theta}}{\\theta}\n\t\t\t\t\t\t& \\geq\\dfrac{\\pi^2-\\theta^2}{\\pi^2+\\theta^2}\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\tThe two inequalities above are not derived from each other. Also, you may have to put a bit of extra effort to prove them. Use calculus if that gives a faster solution.\n\t\t\\begin{problem}[\\itshape IMO $1960$]\n\t\t\tFor which real value of $x$ does the inequality\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{4x^2}{(1-\\sqrt{1+2x})^2}\n\t\t\t\t\t\t& <2x+9\n\t\t\t\t\\end{align*}\n\t\t\thold?\n\t\t\\end{problem}\n\\end{document}", "meta": {"hexsha": "1673d794e013dc57831c0e27dbc72369822ca515", "size": 22475, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "intro.tex", "max_stars_repo_name": "ineq-tech/inequality", "max_stars_repo_head_hexsha": "ebf89351c843b6a7516e10e2ebf0d64e3f1f3f83", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-06T08:29:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-06T08:29:30.000Z", "max_issues_repo_path": "intro.tex", "max_issues_repo_name": "ineq-tech/inequality", "max_issues_repo_head_hexsha": "ebf89351c843b6a7516e10e2ebf0d64e3f1f3f83", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "intro.tex", "max_forks_repo_name": "ineq-tech/inequality", "max_forks_repo_head_hexsha": "ebf89351c843b6a7516e10e2ebf0d64e3f1f3f83", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.8673469388, "max_line_length": 580, "alphanum_fraction": 0.6224694105, "num_tokens": 8992, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.8774767970940975, "lm_q1q2_score": 0.7293087322214984}}
{"text": "\\chapter{The detal numerics}\r\n\\section{4th order central differnce}\r\n{\r\n\\footnotesize\r\nThe 4th order central difference is given by\r\n\\begin{eqnarray}\r\n&& \\frac{\\partial \\phi}{\\partial x}\r\n=\\frac{-\\phi_{i+2}+8\\phi_{i+1}-8\\phi_{i-1}+\\phi_{i+2}}{12\\Delta x} = 0\r\n\\end{eqnarray}\r\nwhere\r\n\\begin{eqnarray}\r\n&& \\phi_{i+2} = \\phi_{i}\r\n+ 2 \\Delta x \\left(\\frac{\\partial \\phi}{\\partial x}\\right)_{i}\r\n+ 2 \\Delta x^2 \\left(\\frac{\\partial^2 \\phi}{\\partial x^2}\\right)_{i}\r\n+ \\frac{4 \\Delta x^3}{3} \\left(\\frac{\\partial^3 \\phi}{\\partial x^3}\\right)_{i}\r\n+ \\frac{2 \\Delta x^4}{3} \\left(\\frac{\\partial^3 \\phi}{\\partial x^4}\\right)_{i}\r\n+ O(\\Delta x^5)\\\\\r\n&& \\phi_{i+1} = \\phi_{i}\r\n+ \\Delta x \\left(\\frac{\\partial \\phi}{\\partial x}\\right)_{i}\r\n+ \\frac{\\Delta x^2}{2} \\left(\\frac{\\partial^2 \\phi}{\\partial x^2}\\right)_{i}\r\n+ \\frac{\\Delta x^3}{6} \\left(\\frac{\\partial^3 \\phi}{\\partial x^3}\\right)_{i}\r\n+ \\frac{\\Delta x^4}{24} \\left(\\frac{\\partial^3 \\phi}{\\partial x^4}\\right)_{i}\r\n+ O(\\Delta x^5)\\\\\r\n&& \\phi_i = \\phi_i\\\\\r\n&& \\phi_{i-1} = \\phi_{i}\r\n- \\Delta x \\left(\\frac{\\partial \\phi}{\\partial x}\\right)_{i}\r\n+ \\frac{\\Delta x^2}{2} \\left(\\frac{\\partial^2 \\phi}{\\partial x^2}\\right)_{i}\r\n- \\frac{\\Delta x^3}{6} \\left(\\frac{\\partial^3 \\phi}{\\partial x^3}\\right)_{i}\r\n+ \\frac{\\Delta x^4}{24} \\left(\\frac{\\partial^3 \\phi}{\\partial x^4}\\right)_{i}\r\n+ O(\\Delta x^5)\\\\\r\n&& \\phi_{i+2} = \\phi_{i}\r\n- 2 \\Delta x \\left(\\frac{\\partial \\phi}{\\partial x}\\right)_{i}\r\n+ 2 \\Delta x^2 \\left(\\frac{\\partial^2 \\phi}{\\partial x^2}\\right)_{i}\r\n- \\frac{4 \\Delta x^3}{3} \\left(\\frac{\\partial^3 \\phi}{\\partial x^3}\\right)_{i}\r\n+ \\frac{2 \\Delta x^4}{3} \\left(\\frac{\\partial^3 \\phi}{\\partial x^4}\\right)_{i}\r\n+ O(\\Delta x^5)\r\n\\end{eqnarray}\r\nTherefore,\r\n\\begin{eqnarray}\r\n&&\r\n\\frac{-\\phi_{i+2}+8\\phi_{i+1}-8\\phi_{i-1}+\\phi_{i+2}}{12\\Delta x}\r\n= \\left(\\frac{\\partial \\phi}{\\partial x}\\right)_{i}+ O(\\Delta x^4)\\\\\r\n&&\r\n\\frac{(-\\phi_{i+2}+7\\phi_{i+1}+7\\phi_{i}-\\phi_{i-1})-\r\n(-\\phi_{i+1}+7\\phi_{i}+7\\phi_{i-1}-\\phi_{i-2})}{12\\Delta x}\r\n= \\left(\\frac{\\partial \\phi}{\\partial x}\\right)_{i}+ O(\\Delta x^4)\r\n\\end{eqnarray}\r\n\r\n\r\n\\section{Flux Corrected Transport scheme}\r\nEquation (\\ref{eq:tracer_int}) can be written as\r\n\\begin{eqnarray}\r\n%%\r\n\\left(\\rho q\\right)^{n+1}_{i,j,k} \r\n&=& \\left(\\rho q\\right)^{n}_{i,j,k}\r\n- \\frac{1}{\\Delta x \\Delta y \\Delta z}\r\n\\big[ \\nonumber\\\\\r\n&+&\r\n\\left[ C_{i+\\frac{1}{2},j,k} F_{i+\\frac{1}{2},j,k}^{high}\r\n+ \\left( 1 - C_{i+\\frac{1}{2},j,k}\\right) F_{i+\\frac{1}{2},j,k}^{low}\\right]\\nonumber\\\\\r\n&-&\r\n\\left[ C_{i-\\frac{1}{2},j,k} F_{i-\\frac{1}{2},j,k}^{high}\r\n+ \\left( 1 - C_{i-\\frac{1}{2},j,k}\\right) F_{i-\\frac{1}{2},j,k}^{low}\\right]\\nonumber\\\\\r\n&+&\r\n\\left[ C_{i,j+\\frac{1}{2},k} F_{i,j+\\frac{1}{2},k}^{high}\r\n+ \\left( 1 - C_{i,j+\\frac{1}{2},k}\\right) F_{i,j+\\frac{1}{2},k}^{low}\\right]\\nonumber\\\\\r\n&-&\r\n\\left[ C_{i,j-\\frac{1}{2},k} F_{i,j-\\frac{1}{2},k}^{high}\r\n+ \\left( 1 - C_{i,j-\\frac{1}{2},k}\\right) F_{i,j-\\frac{1}{2},k}^{low}\\right]\\nonumber\\\\\r\n&+&\r\n\\left[ C_{i,j,k+\\frac{1}{2}} F_{i,j,k+\\frac{1}{2}}^{high}\r\n+ \\left( 1 - C_{i,j,k+\\frac{1}{2}}\\right) F_{i,j,k+\\frac{1}{2}}^{low}\\right]\\nonumber\\\\\r\n&-&\r\n\\left[ C_{i,j,k-\\frac{1}{2}} F_{i,j,k-\\frac{1}{2}}^{high}\r\n+ \\left( 1 - C_{i,j,k-\\frac{1}{2}}\\right) F_{i,j,k-\\frac{1}{2}}^{low}\\right]\\nonumber\\\\\r\n\\big]\r\n\\label{eq:1step_integ_tracer}\r\n\\end{eqnarray}\r\nwhere\r\n\\begin{eqnarray}\r\n  F_{i+\\frac{1}{2},j,k}^{high,low} &=& \\Delta t \\Delta y \\Delta z (\\rho u)_{i+\\frac{1}{2},j,k} q_{i+\\frac{1}{2},j,k}^{high,low}\\\\\r\n  F_{i,j+\\frac{1}{2},k}^{high,low} &=& \\Delta t \\Delta z \\Delta x (\\rho u)_{i,j+\\frac{1}{2},k} q_{i,j+\\frac{1}{2},k}^{high,low}\\\\\r\n  F_{i,j,k+\\frac{1}{2}}^{high,low} &=& \\Delta t \\Delta x \\Delta y (\\rho u)_{i,j,k+\\frac{1}{2}} q_{i,j,k+\\frac{1}{2}}^{high,low}\r\n\\end{eqnarray}\r\nThe anti-diffusive flux are defined as\r\n\\begin{eqnarray}\r\n  A_{i+\\frac{1}{2},j,k} &=& F_{i+\\frac{1}{2},j,k}^{high}-F_{i+\\frac{1}{2},j,k}^{low}\\\\\r\n  A_{i,j+\\frac{1}{2},k} &=& F_{i,j+\\frac{1}{2},k}^{high}-F_{i,j+\\frac{1}{2},k}^{low}\\\\\r\n  A_{i,j,k+\\frac{1}{2}} &=& F_{i,j,k+\\frac{1}{2}}^{high}-F_{i,j,k+\\frac{1}{2}}^{low}\r\n\\end{eqnarray}\r\n\r\nEquation (\\ref{eq:1step_integ_tracer}) can be rewritten as\r\n\\begin{eqnarray}\r\n%%\r\n\\left(\\rho q\\right)^{n+1}_{i,j,k} \r\n&=& \\left(\\rho q\\right)^{n}_{i,j,k}\r\n- \\frac{1}{\\Delta x \\Delta y \\Delta z}\r\n\\big[ \\nonumber\\\\\r\n&+&\r\n\\left[ F_{i+\\frac{1}{2},j,k}^{low}\r\n+ C_{i+\\frac{1}{2},j,k}  A_{i+\\frac{1}{2},j,k}\\right]\\nonumber\\\\\r\n&-&\r\n\\left[ F_{i-\\frac{1}{2},j,k}^{low}\r\n+ C_{i-\\frac{1}{2},j,k}  A_{i-\\frac{1}{2},j,k}\\right]\\nonumber\\\\\r\n&+&\r\n\\left[ F_{i,j+\\frac{1}{2},k}^{low}\r\n+ C_{i,j+\\frac{1}{2},k}  A_{i,j+\\frac{1}{2},k}\\right]\\nonumber\\\\\r\n&-&\r\n\\left[ F_{i,j-\\frac{1}{2},k}^{low}\r\n+ C_{i,j-\\frac{1}{2},k}  A_{i,j-\\frac{1}{2},k}\\right]\\nonumber\\\\\r\n&+&\r\n\\left[ F_{i,j,k+\\frac{1}{2}}^{low}\r\n+ C_{i,j,k+\\frac{1}{2}}  A_{i,j,k+\\frac{1}{2}}\\right]\\nonumber\\\\\r\n&-&\r\n\\left[ F_{i,j,k-\\frac{1}{2}}^{low}\r\n+ C_{i,j,k-\\frac{1}{2}}  A_{i,j,k-\\frac{1}{2}}\\right]\\nonumber\\\\\r\n\\big]\r\n\\label{eq:1step_integ_tracer2}\r\n\\end{eqnarray}\r\nIn practice, we calculate Eq.(\\ref{eq:1step_integ_tracer2}) by the \r\nfollowing steps:\r\n\\begin{enumerate}\r\n%\r\n\\item The tentative values are calculated by using the low order flux:\r\n\\begin{eqnarray}\r\n\\left(\\rho q\\right)^{\\dagger}_{i,j,k} \r\n&=& \\left(\\rho q\\right)^{n}_{i,j,k}\\nonumber\\\\\r\n&-& \\frac{1}{\\Delta x \\Delta y \\Delta z}\r\n\\left[\r\n+ F_{i+\\frac{1}{2},j,k}^{low}-F_{i-\\frac{1}{2},j,k}^{low}\r\n+ F_{i,j+\\frac{1}{2},k}^{low}-F_{i,j-\\frac{1}{2},k}^{low}\r\n+ F_{i,j,k+\\frac{1}{2}}^{low}-F_{i,j,k-\\frac{1}{2}}^{low}\r\n\\right]\r\n\\end{eqnarray}\r\n%\r\n\\item Allowable maximum and minimum values are calculated:\r\n\\begin{eqnarray}\r\n\\left(\\rho q\\right)^{\\max}_{i,j,k}\r\n&=& \\max [\\nonumber\\\\\r\n&&\\max( \\left(\\rho q\\right)^{\\dagger}_{i,j,k},\\left(\\rho q\\right)^{n}_{i,j,k} ),\\nonumber\\\\\r\n&&\\max( \\left(\\rho q\\right)^{\\dagger}_{i-1,j,k},\\left(\\rho q\\right)^{n}_{i-1,j,k} ),\\nonumber\\\\\r\n&&\\max( \\left(\\rho q\\right)^{\\dagger}_{i+1,j,k},\\left(\\rho q\\right)^{n}_{i+1,j,k} ),\\nonumber\\\\\r\n&&\\max( \\left(\\rho q\\right)^{\\dagger}_{i,j-1,k},\\left(\\rho q\\right)^{n}_{i,j-1,k} ),\\nonumber\\\\\r\n&&\\max( \\left(\\rho q\\right)^{\\dagger}_{i,j+1,k},\\left(\\rho q\\right)^{n}_{i,j+1,k} ),\\nonumber\\\\\r\n&&\\max( \\left(\\rho q\\right)^{\\dagger}_{i,j,k-1},\\left(\\rho q\\right)^{n}_{i,j,k-1} ),\\nonumber\\\\\r\n&&\\max( \\left(\\rho q\\right)^{\\dagger}_{i,j,k+1},\\left(\\rho q\\right)^{n}_{i,j,k+1} ) \\nonumber\\\\\r\n&&]\\\\\r\n\\left(\\rho q\\right)^{\\min}_{i,j,k}\r\n&=& \\min [\\nonumber\\\\\r\n&&\\min( \\left(\\rho q\\right)^{\\dagger}_{i,j,k},\\left(\\rho q\\right)^{n}_{i,j,k} ),\\nonumber\\\\\r\n&&\\min( \\left(\\rho q\\right)^{\\dagger}_{i-1,j,k},\\left(\\rho q\\right)^{n}_{i-1,j,k} ),\\nonumber\\\\\r\n&&\\min( \\left(\\rho q\\right)^{\\dagger}_{i+1,j,k},\\left(\\rho q\\right)^{n}_{i+1,j,k} ),\\nonumber\\\\\r\n&&\\min( \\left(\\rho q\\right)^{\\dagger}_{i,j-1,k},\\left(\\rho q\\right)^{n}_{i,j-1,k} ),\\nonumber\\\\\r\n&&\\min( \\left(\\rho q\\right)^{\\dagger}_{i,j+1,k},\\left(\\rho q\\right)^{n}_{i,j+1,k} ),\\nonumber\\\\\r\n&&\\min( \\left(\\rho q\\right)^{\\dagger}_{i,j,k-1},\\left(\\rho q\\right)^{n}_{i,j,k-1} ),\\nonumber\\\\\r\n&&\\min( \\left(\\rho q\\right)^{\\dagger}_{i,j,k+1},\\left(\\rho q\\right)^{n}_{i,j,k+1} ) \\nonumber\\\\\r\n&&]\r\n\\end{eqnarray}\r\n\\item Several values for the flux limiter are calculated:\r\n\\begin{eqnarray}\r\nP_{i,j,k}^{+} &=& \r\n-\\min ( 0, A_{i+\\frac{1}{2},j,k} ) + \\max( 0, A_{i-\\frac{1}{2},j,k} )\\nonumber\\\\\r\n&&\r\n-\\min ( 0, A_{i,j+\\frac{1}{2},k} ) + \\max( 0, A_{i,j-\\frac{1}{2},k} )\\nonumber\\\\\r\n&&\r\n-\\min ( 0, A_{i,j,k+\\frac{1}{2}} ) + \\max( 0, A_{i,j,k-\\frac{1}{2}} )\\\\\r\nP_{i,j,k}^{-} &=& \r\n-\\max ( 0, A_{i+\\frac{1}{2},j,k} ) + \\min( 0, A_{i-\\frac{1}{2},j,k} )\\nonumber\\\\\r\n&&\r\n-\\max ( 0, A_{i,j+\\frac{1}{2},k} ) + \\min( 0, A_{i,j-\\frac{1}{2},k} )\\nonumber\\\\\r\n&&\r\n-\\max ( 0, A_{i,j,k+\\frac{1}{2}} ) + \\min( 0, A_{i,j,k-\\frac{1}{2}} )\\\\\r\n\\end{eqnarray}\r\n\\begin{eqnarray}\r\nQ_{i,j,k}^{+} &=& \r\n\\left[\\left(\\rho q\\right)^{\\max}_{i,j,k} - \\left(\\rho q\\right)^{\\dagger}_{i,j,k} \\right]\r\n\\Delta x \\Delta y \\Delta z\\\\\r\nQ_{i,j,k}^{-} &=& \r\n\\left[\\left(\\rho q\\right)^{\\dagger}_{i,j,k}-\\left(\\rho q\\right)^{\\min}_{i,j,k} \\right]\r\n\\Delta x \\Delta y \\Delta z\r\n\\end{eqnarray}\r\n\\begin{eqnarray}\r\nR_{i,j,k}^{+} &=& \r\n\\begin{cases}\r\n        \\min( 1, Q_{i,j,k}^{+}/P_{i,j,k}^{+} ) & {\\rm if~} P_{i,j,k}^{+}>0\\\\\r\n        0 & {\\rm if~} P_{i,j,k}^{+}=0\\\\\r\n\\end{cases}\r\n\\\\\r\nR_{i,j,k}^{-} &=& \r\n\\begin{cases}\r\n        \\min( 1, Q_{i,j,k}^{-}/P_{i,j,k}^{-} ) & {\\rm if~} P_{i,j,k}^{-}>0\\\\\r\n        0 & {\\rm if~} P_{i,j,k}^{-}=0\\\\\r\n\\end{cases}\r\n\\end{eqnarray}\r\n\\item The flux limters at the cell wall are calculated:\r\n\\begin{eqnarray}\r\nC_{i+\\frac{1}{2},j,k} &=& \r\n\\begin{cases}\r\n        \\min( R_{i+1,j,k}^{+}, R_{i,j,k}^{-} ) & {\\rm if~} A_{i+\\frac{1}{2},j,k}^{-}\\geq 0\\\\\r\n        \\min( R_{i,j,k}^{+}, R_{i+1,j,k}^{-} ) & {\\rm if~} A_{i+\\frac{1}{2},j,k}^{-}<0\\\\\r\n\\end{cases}\r\n\\\\\r\nC_{i,j+\\frac{1}{2},k} &=& \r\n\\begin{cases}\r\n        \\min( R_{i,j+1,k}^{+}, R_{i,j,k}^{-} ) & {\\rm if~} A_{i,j+\\frac{1}{2},k}^{-}\\geq 0\\\\\r\n        \\min( R_{i,j,k}^{+}, R_{i,j+1,k}^{-} ) & {\\rm if~} A_{i,j+\\frac{1}{2},k}^{-}<0\\\\\r\n\\end{cases}\r\n\\\\\r\nC_{i,j,k+\\frac{1}{2}} &=& \r\n\\begin{cases}\r\n        \\min( R_{i,j,k+1}^{+}, R_{i,j,k}^{-} ) & {\\rm if~} A_{i,j,k+\\frac{1}{2}}^{-}\\geq 0\\\\\r\n        \\min( R_{i,j,k}^{+}, R_{i,j,k+1}^{-} ) & {\\rm if~} A_{i,j,k+\\frac{1}{2}}^{-}<0\\\\\r\n\\end{cases}\r\n\\end{eqnarray}\r\n\\end{enumerate}\r\n\r\n", "meta": {"hexsha": "b447c5d8c129b13b7938696379e652363c67830f", "size": 9237, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "scalelib/doc/descriptions/appendix.tex", "max_stars_repo_name": "Shima-Lab/SCALE-SDM_mixed-phase_Shima2019", "max_stars_repo_head_hexsha": "4eaf4f74aa03d091d9778eff373b816f178a962f", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-08T16:06:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-17T06:05:39.000Z", "max_issues_repo_path": "scalelib/doc/descriptions/appendix.tex", "max_issues_repo_name": "Shima-Lab/SCALE-SDM_mixed-phase_Shima2019", "max_issues_repo_head_hexsha": "4eaf4f74aa03d091d9778eff373b816f178a962f", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "scalelib/doc/descriptions/appendix.tex", "max_forks_repo_name": "Shima-Lab/SCALE-SDM_mixed-phase_Shima2019", "max_forks_repo_head_hexsha": "4eaf4f74aa03d091d9778eff373b816f178a962f", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-07T16:29:20.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-07T16:29:20.000Z", "avg_line_length": 42.5668202765, "max_line_length": 130, "alphanum_fraction": 0.5385947819, "num_tokens": 4275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545377452443, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.7292069216871613}}
{"text": "\\subsection{Partially ordered sets}\\label{subsec:partially_ordered_sets}\n\n\\hyperref[def:preordered_set]{Preordered sets} are simple to define and arise naturally (e.g. \\fullref{def:lindenbaum_tarski_algebra}), but they have uniqueness considerations (see \\fullref{ex:preorder_nonuniqueness}) that we usually want to factor out. \\Fullref{thm:preorder_to_partial_order} shows that the result obtained from this factorization is a partially ordered set, which this section is dedicated to.\n\n\\begin{definition}\\label{def:partially_ordered_set}\n  A \\term{partial order} on a set \\( \\mscrP \\) can be defined in the following equivalent ways:\n  \\begin{thmenum}[series=def:partially_ordered_set]\n    \\thmitem{def:partially_ordered_set/nonstrict} A \\hyperref[def:preordered_set]{preorder} \\( \\leq \\) on \\( \\mscrP \\) such that \\( \\leq \\) is \\hyperref[def:binary_relation/antisymmetric]{antisymmetric} in addition to being \\hyperref[def:binary_relation/reflexive]{reflexive} and \\hyperref[def:binary_relation/transitive]{transitive}. This definition is the more common one. If we wish to distinguish it from the other definition, we call such a relation a \\term{nonstrict partial order}.\n\n    \\thmitem{def:partially_ordered_set/strict} An \\hyperref[def:binary_relation/irreflexive]{irreflexive} and \\hyperref[def:binary_relation/transitive]{transitive} binary relation \\( < \\) on \\( \\mscrP \\). This relation is called a \\term{strict partial order}.\n  \\end{thmenum}\n\n  If both relations are present, in order for them to be equivalent, \\( \\leq \\) must be the union of \\( < \\) and the \\hyperref[def:binary_relation/diagonal]{diagonal} \\( \\Delta \\). This condition corresponds to the following axiom:\n  \\begin{equation}\\label{def:partially_ordered_set/compatibility_nonstrict}\n    (x \\leq y) \\leftrightarrow \\parens[\\Big]{(x < y) \\vee (x = y)}.\n  \\end{equation}\n\n  By adding \\( \\anon \\wedge \\neg (x = y) \\) to both sides of \\eqref{def:partially_ordered_set/compatibility_nonstrict}, using \\fullref{thm:de_morgans_laws} and taking irreflexivity of \\( < \\) into account, we obtain\n  \\begin{equation}\\label{def:partially_ordered_set/compatibility_strict}\n    (x < y) \\leftrightarrow \\parens[\\Big]{(x \\leq y) \\wedge \\neg (x = y)}.\n  \\end{equation}\n\n  A set \\( \\mscrP \\) with any of the two types of partial orders is called a \\term{partially ordered set} or simply a \\term{partially ordered set}.\n\n  The elements \\( x, y \\in \\mscrP \\) are called \\term{comparable} if either \\( x \\leq y \\) or \\( y \\leq x \\). That is, they are comparable if they are related by \\( \\leq \\).\n\n  Partially ordered sets have the following metamathematical properties:\n  \\begin{thmenum}[resume=def:partially_ordered_set]\n    \\thmitem{def:partially_ordered_set/theory} Since we can interdefine nonstrict and strict orders, it makes little sense to study different theories for the two.\n\n    In order to define the theory of partially ordered sets, we extend the language of the \\hyperref[def:preordered_set/theory]{theory of preordered sets} with two binary infix predicate symbol --- \\( < \\) and \\( > \\). We then add to the axioms of the theory \\eqref{def:binary_relation/antisymmetric} for \\( \\leq \\) and either of the compatibility conditions \\eqref{def:partially_ordered_set/compatibility_nonstrict} or \\eqref{def:partially_ordered_set/compatibility_strict} (it is unnecessary to add both).\n\n    We can also add \\eqref{def:binary_relation/irreflexive} and \\eqref{def:binary_relation/transitive} for \\( < \\), but that would be redundant.\n\n    \\thmitem{def:partially_ordered_set/homomorphism} We have two types of \\hyperref[def:first_order_homomorphism]{first-order homomorphisms} between partially ordered sets. The homomorphisms are often called \\term{order homomorphisms} or \\term{monotone maps}.\n\n    A \\term{nonstrict monotone map} from \\( (\\mscrP, \\leq_\\mscrP) \\) to \\( (\\mscrQ, \\leq_\\mscrQ) \\) is a homomorphism for the theory containing only \\( \\leq \\) and \\( \\geq \\):\n    \\begin{equation}\\label{eq:def:partially_ordered_set/homomorphism/nonstrict}\n      x <_\\mscrP y \\T{implies} f(x) \\leq_\\mscrQ f(y).\n    \\end{equation}\n\n    Nonstrict homomorphisms are used extensively in the theory of \\hyperref[subsec:partially_ordered_sets]{partially ordered sets}, in particular in \\hyperref[subsec:lattices]{lattice theory}.\n\n    A \\term{strict monotone map} is instead a homomorphism for the full theory:\n    \\begin{equation}\\label{eq:def:partially_ordered_set/homomorphism/strict}\n      x <_\\mscrP y \\T{implies} f(x) <_\\mscrQ f(y).\n    \\end{equation}\n\n    Strict homomorphisms are used in the theory of \\hyperref[subsec:partially_ordered_sets]{totally ordered sets}, in particular for \\hyperref[subsec:well_ordered_sets]{well-ordered sets} and \\hyperref[subsec:ordinals]{ordinals}.\n\n    See \\fullref{thm:monotone_map_converse} for the converse implications to those in \\eqref{eq:def:partially_ordered_set/homomorphism/nonstrict} and \\eqref{eq:def:partially_ordered_set/homomorphism/strict}.\n\n    In particular, if \\( \\mscrP \\) is the preordered set of \\hyperref[rem:peano_arithmetic_zero/nonnegative]{positive integers}, then we speak of \\term{monotone sequences}\n    \\begin{equation}\\label{eq:def:partially_ordered_set/homomorphism/sequence}\n      \\seq{ x_k }_{k=1}^\\infty,\n    \\end{equation}\n    where \\( x_{k-1} \\leq_Q x_k \\) for all \\( k \\in 1, 2, 3, \\ldots \\).\n\n    To elaborate, order homomorphisms can either be strict or nonstrict depending on whether we include \\( < \\) and \\( > \\) as predicate symbols in the language of the theory. We will use the convention that even when the language does include \\( < \\) and \\( > \\), by \\enquote{order homomorphism} we will understand nonstrict monotone.\n\n    Furthermore, \\fullref{thm:totally_ordered_strong_homomorphism} shows that for totally ordered sets, strict order homomorphisms are precisely the strong order homomorphisms (in the sense of \\fullref{rem:first_order_strong_homomorphism}).\n\n    \\thmitem{def:partially_ordered_set/submodel} As for preordered sets, any subset of a partially ordered set is itself a partially ordered set.\n\n    \\thmitem{def:partially_ordered_set/trivial} The \\hyperref[thm:substructures_form_complete_lattice/bottom]{trivial partially ordered set} is the empty set (see \\fullref{rem:empty_models} regarding allowing empty sets as first-order structures)..\n\n    \\thmitem{def:partially_ordered_set/category} We denote the \\hyperref[def:category_of_small_first_order_models]{category of \\( \\mscrU \\)-small models} by \\( \\ucat{Pos} \\). It is a full subcategory of the category \\hyperref[def:preordered_set/category]{\\( \\ucat{PreOrd} \\)} of \\( \\mscrU \\)-small preordered sets.\n\n    The category \\( \\ucat{Pos} \\) is equivalent to that of \\( \\mscrU \\)-small thin skeletal categories --- see \\fullref{thm:order_category_isomorphism/partially_ordered}.\n\n    \\thmitem{def:partially_ordered_set/duality} The \\hyperref[def:preordered_set/duality]{principle of duality for preordered sets} holds for partially ordered sets if we also swap \\( < \\) and \\( > \\).\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:partially_ordered_set/nonstrict}{def:partially_ordered_set/strict} Let \\( \\leq \\) be a nonstrict partial order. We will show that \\( < \\) is a strict partial order.\n\n  \\begin{itemize}\n    \\item The relation \\( < \\) is \\hyperref[def:binary_relation/transitive]{transitive}. To see this, let \\( x < y \\) and \\( y < z \\). In particular, \\( x \\leq y \\) and \\( y \\leq z \\). From transitivity, we have \\( x \\leq z \\).\n\n    Additionally, \\( x \\neq y \\) and \\( y \\neq z \\). Assume that \\( x = z \\). From reflexivity of \\( \\leq \\) we have \\( z \\leq x \\) and, since \\( y \\leq z \\), from transitivity we obtain \\( y \\leq x \\). But since \\( x \\leq y \\), from the antisymmetry of \\( \\leq \\), we have \\( x = y \\), which contradicts the assumption that \\( x < y \\).\n\n    Therefore, \\( x < z \\).\n\n    \\item \\hyperref[def:binary_relation/irreflexive]{Irreflexivity} of \\( < \\) follows directly from reflexivity of \\( \\leq \\) and the compatibility condition.\n  \\end{itemize}\n\n  Since the right side is false, the left side \\( x < x \\) is also false.\n\n  \\ImplicationSubProof{def:partially_ordered_set/strict}{def:partially_ordered_set/nonstrict} Let \\( < \\) be a strict partial order. We will show that \\( \\leq \\) is a nonstrict partial order.\n\n  \\begin{itemize}\n    \\item To see \\hyperref[def:binary_relation/reflexive]{reflexivity}, fix \\( x \\in \\mscrP \\) and assume that \\( x \\not\\leq x \\). Then \\( x \\neq x \\) which contradicts the reflexivity of equality. Hence, \\( x \\leq x \\).\n\n    \\item To see \\hyperref[def:binary_relation/antisymmetric]{antisymmetry}, let \\( x \\leq y \\) and \\( y \\leq x \\), that is, either \\( x = y \\) or both \\( x < y \\) and \\( y < x \\) hold. Assume the latter. By the transitivity of \\( \\leq \\), we have \\( x < x \\), which contradicts the irreflexivity of \\( < \\). Hence, \\( x = y \\).\n\n    \\item To see \\hyperref[def:binary_relation/transitive]{transitivity}, let \\( x \\leq y \\) and \\( y \\leq z \\). Then we have four cases depending on which of \\( x \\), \\( y \\) and \\( z \\) are equal. Since both relations \\( < \\) and \\( = \\) are transitive, it follows that in all four cases \\( x \\leq z \\).\n  \\end{itemize}\n\\end{proof}\n\n\\begin{definition}\\label{def:hasse_diagram}\n  It is usually easier to define small finite partially ordered sets by drawing graphs than by enumerating all relation pairs. Let \\( (\\mscrP, \\leq) \\) be a finite partially ordered set. The relation \\( \\leq \\) may also be regarded as the set of edges of a \\hyperref[def:quiver/simple]{directed graph}. The graph \\( (\\mscrP, \\red^T(\\leq)) \\), whose edges are the \\hyperref[def:relation_closures/transitive]{transitive reduction} of \\( \\leq \\), is called the \\term{Hasse graph} or \\term{Hasse diagram} of \\( \\mscrP \\).\n\n  The term \\enquote{Hasse diagram} is usually associated with drawings. By convention, no arrowheads for denoting directions are drawn on the Hasse graph despite the graph being directed; instead, edges always point upwards. See \\fullref{ex:def:hasse_diagram}.\n\\end{definition}\n\n\\begin{example}\\label{ex:def:hasse_diagram}\n  Consider the partial order over \\( \\set{ a, b, c, d, e } \\) defined via\n  \\begin{equation}\\label{eq:ex:def:hasse_diagram/partially ordered set}\n    \\underline{a \\leq c},\\quad \\underline{a \\leq d},\\quad a \\leq e,\\quad \\underline{b \\leq d},\\quad b \\leq e,\\quad \\underline{d \\leq e}.\n  \\end{equation}\n\n  The corresponding Hasse graph includes only the underlined edges. The rest of the edges can be restored from transitivity. In this case, the Hasse graph has edges\n  \\begin{equation}\\label{eq:ex:def:hasse_diagram/hasse_graph}\n    \\set{ a \\to c, a \\to d, b \\to d, d \\to e }\n  \\end{equation}\n\n  \\begin{figure}\n    \\centering\n    \\includegraphics[page=1]{output/ex__def__hasse_diagram.pdf}\n    \\caption{A drawing of the Hasse diagram \\eqref{eq:ex:def:hasse_diagram/hasse_graph}}\n    \\label{fig:ex:def:hasse_diagram}\n  \\end{figure}\n\\end{example}\n\n\\begin{example}\\label{ex:preorder_nonuniqueness}\n  Consider the preordered set \\( \\mscrP \\) in \\cref{fig:ex:preorder_nonuniqueness} in which \\( b \\leq c \\) and \\( c \\leq b \\), but \\( b \\neq c \\). We cannot properly draw a \\hyperref[def:hasse_diagram]{Hasse diagram} because we have the restriction that \\( c \\) is drawn (strictly) higher than \\( b \\) if \\( c > b \\) and that \\( c \\) is drawn lower than \\( b \\) if \\( c < b \\). We face a similar problem formally, for example in the definition of a \\hyperref[def:lindenbaum_tarski_algebra]{Lindenbaum-Tarski algebra} of a \\hyperref[def:first_order_theory]{logical theory}, where the preorder \\( \\vdash \\) allows \\( \\varphi \\vdash \\psi \\) and \\( \\psi \\vdash \\varphi \\), but still \\( \\varphi \\neq \\psi \\). Thus, we have nonuniqueness --- every tautology is a largest element with respect to \\( \\vdash \\), while we want to have a single largest element for the sake of building a tidier theory.\n\n  If we are only interested in members of \\( \\mscrP \\) up to the equivalence \\eqref{eq:thm:preorder_to_partial_order/equivalence}, it is easy to factor \\( \\mscrP \\) by the equivalence relation \\eqref{eq:thm:preorder_to_partial_order/equivalence} and obtain a partially ordered set. In the language of graph theory, if we have \\hyperref[def:quiver_path/cycle]{directed cycles} that we may wish to avoid, we can contract each directed cycle into a single vertex, at which point the graph becomes acyclic. This corresponds to \\hyperref[def:quiver_condensation]{graph condensation}.\n\n  The formulation and proof of correctness of this process can be found in \\fullref{thm:preorder_to_partial_order} and an example can be found in \\cref{fig:ex:preorder_nonuniqueness}.\n\n  \\begin{figure}\n    \\hfill\n    \\includegraphics[page=1]{output/ex__preorder_nonuniqueness.pdf}\n    \\hfill\n    \\includegraphics[page=2]{output/ex__preorder_nonuniqueness.pdf}\n    \\hfill\\hfill\n    \\caption{A preordered set and its induced partially ordered set.}\n    \\label{fig:ex:preorder_nonuniqueness}\n  \\end{figure}\n\\end{example}\n\n\\begin{proposition}\\label{thm:preorder_to_partial_order}\n  Let \\( (\\mscrP, \\leq) \\) be a preordered set. Define the relation \\( \\cong \\) by\n  \\begin{equation}\\label{eq:thm:preorder_to_partial_order/equivalence}\n    x \\cong y \\T{if and only if} x \\leq y \\T{and} y \\leq x.\n  \\end{equation}\n\n  That is, \\( \\cong \\) is the intersection of the relation \\( \\leq \\) with its \\hyperref[def:binary_relation/converse]{inverse}.\n\n  Since \\( \\cong \\) is an \\hyperref[def:equivalence_relation]{equivalence relation} we can for the the quotient set \\( \\mscrP / \\cong \\). Define the relation \\( \\preceq \\) on this quotient set by\n  \\begin{equation*}\n    [x] \\preceq [y] \\T{if and only if} x \\leq y.\n  \\end{equation*}\n\n  The pair \\( (\\mscrP / \\cong, \\preceq) \\) is then a \\hyperref[def:partially_ordered_set]{partially ordered set}.\n\\end{proposition}\n\\begin{proof}\n  The relation \\( \\preceq \\) is well-defined. Indeed, let \\( x \\cong x' \\) and \\( y \\cong y' \\), that is, both \\( x \\leq x' \\) and \\( x' \\leq x \\) and similarly for \\( y \\). If \\( x \\leq y \\), from transitivity \\( x \\leq y \\leq y' \\). But \\( x' \\leq x \\), hence \\( x' \\leq y' \\).\n\n  It is then clear that \\( \\preceq \\) is a partial order because it inherits reflexivity and transitivity from \\( \\leq \\) and antisymmetry is imposed by taking quotient sets --- equality in \\( \\mscrP / \\cong \\) holds precisely when \\( \\cong \\) holds in \\( \\mscrP \\).\n\n  Thus, \\( (\\mscrP / \\cong, \\preceq) \\) is indeed a partially ordered set.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:order_embedding_is_strict}\n  For any two \\hyperref[def:preordered_set]{preordered sets} \\( (\\mscrP, \\leq_\\mscrP) \\) and \\( (\\mscrQ, \\leq_\\mscrQ) \\), every \\hyperref[def:partially_ordered_set/homomorphism]{order embedding} of \\( \\mscrP \\) into \\( \\mscrQ \\) is a \\hyperref[def:partially_ordered_set/homomorphism]{strict order embedding}.\n\n  Compare this to \\fullref{thm:total_order_embedding_iff_strict}\n\\end{proposition}\n\\begin{proof}\n  Let \\( f: \\mscrP \\to \\mscrQ \\) be an order embedding.\n\n  Let \\( x <_\\mscrP y \\) for some members \\( x \\) and \\( y \\) of \\( \\mscrP \\). Since \\( f \\) is an order homomorphism, we have \\( f(x) \\leq_\\mscrQ f(y) \\). Since it is also injective, \\( f(x) = f(y) \\) implies \\( x = y \\), which contradicts our previous assumption.\n\n  Therefore, \\( f(x) <_\\mscrQ f(y) \\) and \\( f \\) is a strict order homomorphism.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:monotone_map_converse}\n  For any (even nonstrict) monotone map \\( f: \\mscrP \\to \\mscrQ \\) between partially ordered sets, if \\( x \\) and \\( y \\) are comparable elements of \\( \\mscrP \\) we have\n  \\begin{equation}\\label{eq:thm:monotone_map_converse}\n    x <_\\mscrP y \\T{if and only if} f(x) <_\\mscrQ f(y).\n  \\end{equation}\n\\end{proposition}\n\\begin{proof}\n  Let \\( f(x) <_\\mscrQ f(y) \\) and suppose that \\( x \\geq y \\). Since \\( f \\) is a monotone map, we have \\( f(x) \\geq_\\mscrQ f(y) \\), which is a contradiction.\n\\end{proof}\n\n\\begin{definition}\\label{def:partially_ordered_set_extremal_points}\n  We introduce the following terminology for extremal elements of a partially ordered set \\( \\mscrP \\). Analogous definition can be given for preordered sets, but the nonuniqueness problems outlined in \\fullref{ex:preorder_nonuniqueness} highlight that there are sometimes difficulties in doing, so.\n\n  The notions on the left and on the right are \\hyperref[def:partially_ordered_set/duality]{dual}, but we discuss both nonetheless.\n\n  \\begin{thmenum}\n    \\thmitem{def:partially_ordered_set_extremal_points/upper_and_lower_bounds}\\mcite[2]{Gratzer1978}\n    \\begin{minipage}[t]{0.45\\textwidth}\n      An \\term{upper bound} for the set \\( A \\subseteq \\mscrP \\) is an element \\( x_0 \\in \\mscrP \\) such that \\( x \\leq x_0 \\) for every \\( x \\in A \\). Note that \\( x_0 \\) does not in general belong to \\( A \\). An upper bound is called \\term{strict} if it does not belong to \\( A \\).\n\n      If \\( A \\) has at least one upper bound, it is called \\term{bounded from above}.\n\n      Every element is vacuously an upper bound of \\( A = \\varnothing \\).\n\n      In \\cref{fig:ex:def:hasse_diagram}, the set \\( A = \\set{ a, b } \\) is bounded from above by both \\( d \\) and \\( e \\), but the entire partially ordered set has no upper bound.\n    \\end{minipage}\n    \\hspace{0.02\\textwidth}\n    \\begin{minipage}[t]{0.45\\textwidth}\n      Dually, \\( x_0 \\in \\mscrP \\) is a \\term{lower bound} of \\( A \\) if \\( x_0 \\leq x \\) for every \\( x \\in A \\). A lower bound is called \\term{strict} if it does not belong to \\( A \\). If \\( A \\) has a lower bound, it is called \\term{bounded from below}.\n\n      If \\( A \\) is bounded both from below and from above, we say that \\( A \\) is \\term{bounded}.\n\n      Every element is vacuously a lower bound of \\( A = \\varnothing \\). Hence, the empty set is bounded.\n\n      In \\cref{fig:ex:def:hasse_diagram}, the entire partially ordered set has no lower bound. The set \\( A = \\set{ c, d } \\) is bounded from below by \\( a \\), but not from above, hence \\( A \\) is not bounded.\n    \\end{minipage}\n\n    \\thmitem{def:partially_ordered_set_extremal_points/maximal_and_minimal_element}\n    \\begin{minipage}[t]{0.45\\textwidth}\n      A \\term{maximal element} for the set \\( A \\subseteq \\mscrP \\) is a member \\( x_0 \\) of \\( A \\) such that there is no greater element in \\( A \\) than \\( x_0 \\). More precisely, \\( x_0 \\) is a maximal element of \\( A \\) if for every element \\( x \\in A \\) such that \\( x \\leq x_0 \\) we have \\( x = x_0 \\).\n\n      In \\cref{fig:ex:def:hasse_diagram}, the entire partially ordered set has two incomparable maximal elements --- \\( c \\) and \\( e \\).\n    \\end{minipage}\n    \\hspace{0.02\\textwidth}\n    \\begin{minipage}[t]{0.45\\textwidth}\n      The member \\( x_0 \\in A \\) is a \\term{minimal element} of \\( A \\) if for every \\( x \\in A \\) such that \\( x \\leq x_0 \\) we have \\( x = x_0 \\).\n\n      The empty set cannot have maximal or minimal elements because it has no members.\n\n      In \\cref{fig:ex:def:hasse_diagram}, the entire partially ordered set has two incomparable minimal elements --- \\( a \\) and \\( b \\).\n    \\end{minipage}\n\n    \\thmitem{def:partially_ordered_set_extremal_points/maximum_and_minimum}\n    \\begin{minipage}[t]{0.45\\textwidth}\n      The \\term{maximum} or \\term{greatest element} of \\( A \\subseteq \\mscrP \\), if it exists, is an upper bound of \\( A \\) that belongs to \\( A \\). A maximum is necessarily a maximal element because \\( x_0 \\leq x \\) only holds for \\( x = x_0 \\), which also demonstrates uniqueness of \\( x_0 \\). See \\fullref{ex:unique_maximal_element_that_is_not_maximum} for a unique maximal element that is not a maximum.\n    \\end{minipage}\n    \\hspace{0.02\\textwidth}\n    \\begin{minipage}[t]{0.45\\textwidth}\n      The \\term{minimum} of \\( A \\), also called \\term{smallest element} or \\term{least element}, is a lower bound that belongs to \\( A \\).\n\n      The empty set cannot have a maximum or minimum because it has no members.\n\n      In \\cref{fig:ex:def:hasse_diagram}, the entire partially ordered set has no maximum, but the set \\( A = \\mscrP \\setminus \\set{ b } = \\set{ a, b, d, e } \\) has \\( a \\) as its minimum.\n    \\end{minipage}\n\n    \\thmitem{def:partially_ordered_set_extremal_points/supremum_and_infimum}\\mcite[2]{Gratzer1978}\n    \\begin{minipage}[t]{0.45\\textwidth}\n      The \\term{supremum} \\( \\sup A \\) of \\( A \\subseteq \\mscrP \\), if it exists, is its least upper bound of \\( A \\), i.e. the \\hyperref[def:partially_ordered_set_extremal_points/maximum_and_minimum]{minimum} of the set of its \\hyperref[def:partially_ordered_set_extremal_points/upper_and_lower_bounds]{upper bounds}.\n\n      In \\cref{fig:ex:def:hasse_diagram}, the entire partially ordered set has no upper bound, so it cannot possibly have a supremum. Obviously every supremum is a maximum, but the converse is not true. We already noted that both \\( d \\) and \\( e \\) are upper bounds of the set \\( \\set{ a, b } \\) and since \\( d \\leq e \\), we conclude that \\( d \\) is the supremum of \\( \\set{ a, b } \\), yet the set \\( \\set{ a, b } \\) has no maximum.\n    \\end{minipage}\n    \\hspace{0.02\\textwidth}\n    \\begin{minipage}[t]{0.45\\textwidth}\n      The \\term{infimum} \\( \\inf A \\) of \\( A \\subseteq \\mscrP \\) is its greatest lower bound.\n\n      An infimum may fail to exist because the set of lower bounds is nonempty, but has no maximum. This can happen if, for example, we had \\( b \\leq c \\) in \\cref{fig:ex:def:hasse_diagram}, in which case both \\( a \\) and \\( b \\) would be maximal lower bounds of \\( \\set{ c, d } \\), but none of them would be a greatest lower bound because they are incomparable.\n    \\end{minipage}\n\n    \\thmitem{def:partially_ordered_set_extremal_points/top_and_bottom}\\mcite[2]{Gratzer1978}\n    \\begin{minipage}[t]{0.45\\textwidth}\n      If it exists, the maximum of the entire partially ordered set \\( \\mscrP \\) is usually denoted by \\( \\top \\) and called the \\term{global maximum} or \\term{top} element of \\( \\mscrP \\). Since \\( \\top \\) is the maximum of \\( \\mscrP \\), it is also the supremum of \\( \\mscrP \\).\n\n      Since every member of \\( \\mscrP \\) is a lower bound of \\( \\varnothing \\), the greatest lower bound is the maximum of \\( \\mscrP \\).\n\n      In conclusion,\n      \\begin{equation*}\n        \\top = \\max \\mscrP = \\sup \\mscrP = \\inf \\varnothing.\n      \\end{equation*}\n\n      If \\( \\top \\) exists, we say that the partially ordered set \\( \\mscrP \\) itself is bounded from above.\n    \\end{minipage}\n    \\hspace{0.02\\textwidth}\n    \\begin{minipage}[t]{0.45\\textwidth}\n      Dually, the minimum of \\( \\mscrP \\) is usually denoted by \\( \\bot \\) and called the \\term{global minimum} or \\term{bottom} element of \\( \\mscrP \\).\n\n      The supremum of the empty set is the least of the upper bounds of the empty set, i.e. the minimum of \\( \\mscrP \\), which is \\( \\bot \\).\n\n      In conclusion,\n      \\begin{equation*}\n        \\bot = \\min \\mscrP = \\inf \\mscrP = \\sup \\varnothing.\n      \\end{equation*}\n\n      If \\( \\bot \\) exists, we say that the partially ordered set \\( \\mscrP \\) itself is bounded from below.\n    \\end{minipage}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:unique_maximal_element_that_is_not_maximum}\\mcite{MathSE:unique_maximal_element_that_is_not_maximum}\n  For a more extreme example of the interplay between maximal elements and maxima, adjoin \\( \\BbbZ \\) under the usual order with a new sentinel element \\( \\star \\). Define \\( \\star \\) to satisfy reflexivity, but not be in relation with any integer. Then \\( \\star \\) is a unique maximal element of \\( \\BbbZ \\cup \\set{ \\star } \\), yet the latter set has no largest element.\n\n  This phenomenon is impossible in finite partially ordered sets where a unique maximal element is always a maximum.\n\\end{example}\n\n\\begin{definition}\\label{def:partially_ordered_set_chain_and_antichain}\\mcite[2]{Gratzer1978}\n  A \\term{chain} in a partially ordered set is a subset in which every two elements are comparable. The \\term{length} of a chain \\( A \\) is the \\hyperref[def:cardinal]{cardinal number} \\( \\card(A) - 1 \\). The \\term{length} of a partially ordered set, if it exists, is the maximum among the lengths of all its chains. The length of a partially ordered set is also called its \\term{height} because of how Hasse diagrams are drawn..\n\n  An \\term{antichain} is a subset in which no two elements are comparable. The \\term{width} of a partially ordered set, if it exists, is the maximum among the cardinalities of its antichains.\n\n  The height of the partially ordered set in \\cref{fig:ex:def:hasse_diagram} is \\( 2 \\) and it is reached by the chains \\( \\set{ a, d, e } \\) and \\( \\set{ b, d, e } \\). The width is \\( 2 \\) are is reached by \\( \\set{ a, b } \\), \\( \\set{ b, e } \\), \\( \\set{ c, d } \\) and \\( \\set{ c, e } \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:partially_ordered_set_interval}\n  Fix a \\hyperref[def:partially_ordered_set]{partially ordered set set} \\( (\\mscrP, \\leq) \\). For any \\( a, b \\in P \\) with \\( a \\leq b \\), we define the following related partially ordered sets:\n\n  \\begin{thmenum}\n    \\thmitem{def:partially_ordered_set_interval/ray} The \\term{open rays}, also called the \\term{open initial segment} and \\term{open final segment}, are defined as\n    \\begin{equation*}\n      \\begin{aligned}\n        (a, \\infty) \\coloneqq \\set{ x \\in \\mscrP \\given b > a } \\eqqcolon \\mscrP_{>a},\n        \\\\\n        (-\\infty, b) \\coloneqq \\set{ x \\in \\mscrP \\given x < b } \\eqqcolon \\mscrP_{<b}.\n      \\end{aligned}\n    \\end{equation*}\n\n    The notation on the left assumes that the sentinel symbols \\( \\infty \\) and \\( -\\infty \\) are adjoined to \\( \\mscrP \\) as in the case of the \\hyperref[def:extended_real_numbers]{extended real numbers}. This convention is widespread for unbounded ordered rings representing numbers --- for example \\hyperref[def:set_of_integers]{\\( \\BbbZ \\)}, \\hyperref[def:set_of_rational_numbers]{\\( \\BbbQ \\)} and \\hyperref[def:set_of_real_numbers]{\\( \\BbbR \\)}. The term \\enquote{ray} is used in this context due to the connection with \\hyperref[def:geometric_ray]{geometric rays}.\n\n    The notation on the right is more general and is widespread for abstract partial orders, most notably \\hyperref[def:well_ordered_set]{well-ordered sets}. In the latter context, they are usually referred to as \\enquote{initial/final segments}.\n\n    The \\term{closed rays} and \\term{closed initial/final segments} are defined analogously as\n    \\begin{equation*}\n      \\begin{aligned}\n        [a, \\infty) \\coloneqq \\set{ x \\in \\mscrP \\given x \\geq a } \\eqqcolon \\mscrP_{\\geq a},\n        \\\\\n        (-\\infty, b] \\coloneqq \\set{ x \\in \\mscrP \\given x \\leq b } \\eqqcolon \\mscrP_{\\leq b}.\n      \\end{aligned}\n    \\end{equation*}\n\n    \\thmitem{def:partially_ordered_set_interval/closed} The \\term{closed interval} with endpoints \\( a \\) and \\( b \\) is\n    \\begin{equation*}\n      [a, b] \\coloneqq \\set{ x \\in \\mscrP \\given a \\leq x \\leq b } = \\mscrP_{\\geq a} \\cap \\mscrP_{\\leq b}.\n    \\end{equation*}\n\n    We implicitly assume that \\( a \\leq b \\), but this is not strictly necessary --- \\( [a, b] \\) is an empty set otherwise.\n\n    \\thmitem{def:partially_ordered_set_interval/open} The \\term{open interval} with endpoints \\( a \\) and \\( b \\) is\n    \\begin{equation*}\n      (a, b) \\coloneqq \\set{ x \\in \\mscrP \\given a < x < b } = \\mscrP_{> a} \\cap \\mscrP_{< b}.\n    \\end{equation*}\n\n    We implicitly assume that \\( a < b \\), but this is also not strictly necessary.\n\n    \\thmitem{def:partially_ordered_set_interval/half_open} The \\term{half-open intervals} are\n    \\begin{equation*}\n      \\begin{aligned}\n        (a, b] \\coloneqq \\set{ x \\in \\mscrP \\given a < x \\leq b } = \\mscrP_{> a} \\cap \\mscrP_{\\leq b},\n        \\\\\n        [a, b) \\coloneqq \\set{ x \\in \\mscrP \\given a \\leq x < b } = \\mscrP_{\\geq a} \\cap \\mscrP_{< b}.\n      \\end{aligned}\n    \\end{equation*}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:partially_ordered_cofinal_equivalences}\n  Let \\( (\\mscrP, \\leq) \\) be a \\hyperref[def:partially_ordered_set_extremal_points/upper_and_lower_bounds]{bounded from above} totally ordered set and let \\( A \\subseteq \\mscrP \\). Then \\( A \\) is \\hyperref[def:cofinal_set]{cofinal} if and only if it contains the \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{top element} \\( \\top \\).\n\n  Compare this result with \\Fullref{thm:totally_ordered_cofinal_equivalences}.\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Let \\( A \\) be a cofinal set. Then \\( A \\) must contain an element \\( x \\) such that \\( \\top \\leq x \\). But \\( \\top \\) is a maximum and hence \\( x = \\top \\) and thus \\( \\top \\in A \\).\n\n  \\NecessitySubProof Let \\( A \\) be a set containing \\( \\top \\). Then for any \\( x \\in \\mscrP \\) we have \\( x \\leq \\top \\) and hence \\( A \\) is cofinal.\n\\end{proof}\n\n\\begin{definition}\\label{def:lexicographic_order}\n  Let \\( (\\mscrP, \\leq_\\mscrP) \\) and \\( (\\mscrQ, \\leq_\\mscrQ) \\) be partially ordered sets.\n\n  The \\term{lexicographic order} on \\( \\mscrP \\times \\mscrQ \\), also know as the \\term{dictionary order}, is defined as\n  \\begin{equation}\\label{eq:def:lexicographic_order}\n    (a, b) \\prec (c, d) \\thickspace \\T{if and only if} \\thickspace \\parens[\\Big]{ a <_\\mscrP c \\T{or} \\parens[\\Big]{ a = c \\T{and} b <_\\mscrQ d } }.\n  \\end{equation}\n\n  The \\term{reverse lexicographic order} is\n  \\begin{equation}\\label{eq:def:lexicographic_order/reverse}\n    (a, b) \\prec (c, d) \\thickspace \\T{if and only if} \\thickspace \\parens[\\Big]{ b <_\\mscrQ d \\T{or} \\parens[\\Big]{ b = d \\T{and} a <_\\mscrP c } }.\n  \\end{equation}\n\n  The lexicographic order on \\( \\mscrP \\times \\mscrQ \\) inherits some important properties from \\( (\\mscrP, \\mscrP) \\) and \\( (\\mscrQ, \\leq_\\mscrQ) \\) as can be seen in \\fullref{thm:lexicographic_order_is_partial_order,thm:total_lexicographic_order_is_total_order,thm:well_ordered_lexicographic_order_is_well_ordered}.\n\n  We can use natural number recursion to extend this to arbitrary \\( n \\)-tuples --- see \\fullref{ex:def:lexicographic_order} for an example.\n\\end{definition}\n\n\\begin{example}\\label{ex:def:lexicographic_order}\n  A key example for \\hyperref[def:lexicographic_order]{lexicographic ordering} is real-world dictionary like a thesaurus. It is obvious that \\enquote{homomorphism} should come after \\enquote{axiom} and the lexicographic order on a Cartesian power of Latin alphabets suggests that \\enquote{homeomorphism} should also come after \\enquote{homeomorphic}.\n\n  A slightly more relevant example for mathematics is the lexicographic ordering\n  \\begin{equation*}\n    AB < AD < BC < CD\n  \\end{equation*}\n  of the names of the edges of a rectangle. The reverse lexicographic ordering is\n  \\begin{equation*}\n    AB < BC < AD < CD.\n  \\end{equation*}\n\n  For the sides of a \\hyperref[def:triangle]{triangle}, we have \\( AB < AC < BC \\) for both orderings.\n\n  The edges of the graph in \\fullref{eq:fig:def:quiver} are numbered in lexicographic order, which also happens to be the reverse lexicographic order.\n\n  \\Fullref{thm:ordinal_addition_disjoin_union} and \\fullref{thm:ordinal_multiplication_cartesian_product} contain more interesting applications of lexicographic orders.\n\\end{example}\n\n\\begin{proposition}\\label{thm:lexicographic_order_is_partial_order}\n  The \\hyperref[eq:def:lexicographic_order]{lexicographic} and \\hyperref[eq:def:lexicographic_order/reverse]{reverse lexicographic} orders are \\hyperref[def:partially_ordered_set/strict]{strict partial order} relations.\n\n  Compare this result to \\fullref{thm:total_lexicographic_order_is_total_order} and \\fullref{thm:well_ordered_lexicographic_order_is_well_ordered}.\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf[def:binary_relation/irreflexive]{irreflexivity} Trivial.\n\n  \\SubProofOf[def:binary_relation/transitive]{transitivity} Let \\( \\prec \\) be a lexicographic order on \\( \\mscrP \\times \\mscrQ \\).\n\n  If \\( (a, b) \\prec (c, d) \\) and \\( (c, d) \\prec (e, f) \\), then:\n  \\begin{itemize}\n    \\item If \\( a < c \\), then \\( a < c \\leq e \\) and thus \\( (a, b) \\prec (e, f) \\).\n\n    \\item If \\( a = c \\) and \\( b < d \\), then \\( a \\leq e \\) and \\( b < d \\leq f \\) and thus \\( (a, b) \\prec (e, f) \\).\n  \\end{itemize}\n\n   The proof for the reverse lexicographic order is analogous.\n\\end{proof}\n\n\\begin{definition}\\label{def:inflationary_function}\\mcite{MathOF:closure_operator_on_poset}\n  An \\hyperref[def:multi_valued_function/endofunction]{endofunction} on a \\hyperref[def:partially_ordered_set]{partially ordered set} \\( (\\mscrP, \\leq) \\) is said to be \\term{inflationary} if \\( x \\leq \\cl(x) \\) for every \\( x \\in \\mscrP \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:closure_operator}\\mcite{MathOF:closure_operator_on_poset}\n  Let \\( (\\mscrP, \\leq) \\) be a \\hyperref[def:partially_ordered_set]{partially ordered set}. We say that the function \\( \\cl: \\mscrP \\to \\mscrP \\) is a \\term{closure operator} if it is \\hyperref[def:inflationary_function]{inflationary}, \\hyperref[def:magma/idempotent]{idempotent} and \\hyperref[eq:def:partially_ordered_set/homomorphism/nonstrict]{nonstrictly order-preserving}.\n\n  We say that \\( x \\) is \\term{closed} with respect to \\( \\cl \\) if \\( x = \\cl(x) \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:closure_operator_minimality}\n  For any \\hyperref[def:closure_operator]{closure operator} \\( \\cl: \\mscrP \\to \\mscrP \\) on any \\hyperref[def:partially_ordered_set]{partially ordered set} \\( (\\mscrP, \\leq) \\) and any \\( x \\in \\mscrP \\) it holds that \\( \\cl(x) \\) is the smallest closed element of \\( \\mscrP \\) containing \\( x \\).\n\\end{proposition}\n\\begin{proof}\n  Since \\( f \\) is \\hyperref[def:inflationary_function]{inflationary}, it is clear that \\( x \\leq \\cl(x) \\).\n\n  Let \\( y \\in \\mscrP \\) be a closed element such that \\( x \\leq y \\leq \\cl(x) \\). From the monotonicity of \\( f \\) we have that\n  \\begin{equation*}\n    \\cl(x) \\leq \\underbrace{\\cl(y)}_{y} \\leq \\underbrace{\\cl(\\cl(x))}_{\\cl(x)}.\n  \\end{equation*}\n\n  Therefore, \\( y = \\cl(x) \\).\n\\end{proof}\n\n\\begin{theorem}[Zorn's lemma]\\label{thm:zorns_lemma}\\mcite[63]{Gratzer1978}\n  If every \\hyperref[def:partially_ordered_set_chain_and_antichain]{chain} in a \\hyperref[def:partially_ordered_set]{partially ordered set} has an \\hyperref[def:partially_ordered_set_extremal_points/upper_and_lower_bounds]{upper bound}, then the entire set has a \\hyperref[def:partially_ordered_set_extremal_points/maximal_and_minimal_element]{maximal element}.\n\n  Zorn's lemma is usually stated and used only in a \\hyperref[thm:boolean_algebra_of_subsets]{lattice of sets}, however it is a more general statement in order theory.\n\n  In \\hyperref[def:zfc]{\\logic{ZF}} this theorem is equivalent to the \\hyperref[def:zfc/choice]{axiom of choice} --- see \\fullref{thm:axiom_of_choice_equivalences/zorns_lemma}.\n\\end{theorem}\n\\begin{proof}\n  \\ImplicationSubProof[def:zfc/choice]{the axiom of choice}[thm:zorns_lemma]{Zorn's lemma} Let \\( (\\mscrP, \\leq) \\) be a partially ordered set in which every chain has an upper bound. Aiming at a contradiction, suppose that \\( \\mscrP \\) has no maximal element.\n\n  Denote by \\( \\mscrC \\) the set of all chains of \\( \\mscrP \\) and define the multi-valued map \\( F: \\mscrC \\to \\mscrP \\) that assigns to each chain the set of all strict upper bounds.\n\n  Since \\( \\mscrP \\) has no maximal element, every chain has a strict upper bound. That is, the function \\( F \\) is a total multi-valued map. By \\fullref{thm:existence_of_multi_valued_function_selection}, there exists a single-valued selection \\( f: \\mscrC \\to \\mscrP \\) of \\( F \\). We have indirectly used the axiom of choice via \\fullref{thm:existence_of_multi_valued_function_selection}.\n\n  By \\fullref{thm:hartogs_lemma}, there exists a smallest \\hyperref[def:ordinal]{ordinal} \\( \\gamma \\) such that no function from \\( \\gamma \\) to \\( \\mscrP \\) is injective. Using \\fullref{thm:bounded_transfinite_recursion}, we can define\n  \\begin{equation*}\n    \\begin{aligned}\n      &g: \\gamma \\to A \\\\\n      &g(\\delta) \\coloneqq f(\\set{ g(\\varepsilon) \\given \\varepsilon < \\delta }).\n    \\end{aligned}\n  \\end{equation*}\n\n  By construction, for every \\( \\delta < \\gamma \\) the value \\( g(\\delta) \\) is a strict upper bound of the set \\( \\set{ g(\\varepsilon) \\given \\varepsilon < \\delta } \\). Hence, the function \\( f \\) is injective, which directly contradicts our choice of \\( \\gamma \\).\n\n  The obtained contradiction shows that \\( \\mscrP \\) has a maximal element.\n\n  \\ImplicationSubProof[thm:zorns_lemma]{Zorn's lemma}[def:zfc/choice]{axiom of choice} Let \\( \\mscrA \\) be a family of nonempty sets. Let \\( \\mscrF \\) be the set of all \\hyperref[def:partial_function]{partial single-valued functions} from \\( \\mscrA \\) to \\( \\bigcup \\mscrA \\) with the subset ordering. That is, \\( f \\leq g \\) if \\( \\dom(f) \\subseteq \\dom(g) \\) for \\( f, g \\in \\mscrF \\).\n\n  Clearly every chain has a maximum - a total single-valued function. Then \\( \\mscrF \\) itself has a maximal element by Zorn's lemma. This maximal element is necessarily a total function because otherwise it would not be maximal.\n\n  Then this is the desired choice function for the family \\( \\mscrA \\).\n\\end{proof}\n", "meta": {"hexsha": "181478c6299c8222ecc5ac8e88752ef0ae0e5fb7", "size": 36903, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/partially_ordered_sets.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/partially_ordered_sets.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/partially_ordered_sets.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 77.6905263158, "max_line_length": 891, "alphanum_fraction": 0.7040620004, "num_tokens": 11406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7291669817170504}}
{"text": "\\chapter{Neural Networks}\n\n\\section*{Exercise 5.1 $\\star \\star$}\nConsider a two-layer network function of the form $\\eqref{eq:5.7}$ \nin which the hidden-unit nonlinear activation functions $h(\\cdot)$ \nare given by logistic sigmoid functions of the form\n\\begin{equation}\\label{eq:5.191}\\tag{5.191}\n    \\sigma(a) = \\frac{1}{1 + \\exp(-a)}.\n\\end{equation}\nShow that there exists an equivalent network, which computes \nexactly the same function, but with hidden activation functions\ngiven by $\\tanh(a)$ where the $\\tanh$ function is defined by\n(5.59). Hint: first find the relation between $\\sigma(a)$ \nand $\\tanh(a)$, and then show that the parameters of the two\nnetworks differ by linear transformations.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The considered two-layer network has the form\n    \\begin{equation}\\label{eq:5.7}\\tag{5.7}\n        y_k(\\mathbf{x}, \\mathbf{w}) \n        = \\sigma\\bigg(\\sum_{j=1}^{M} w_{kj}^{(2)} \n        h\\bigg(\\sum_{i=1}^{D} w_{ji}^{(1)}x_i + w_{j0}^{(1)}\\bigg) + w_{k0}^{(2)}\\bigg)\n    \\end{equation}\n    Now, we've proved in Exercise 3.1 that \n    \\[\n        \\sigma(x) = \\frac{1}{2} \\tanh \\frac{x}{2} + \\frac{1}{2}\n    \\] \n    Therefore, we can rewrite $y_k$ as\n    \\begin{align*}\n        y_k(\\mathbf{x}, \\mathbf{w})\n        &= \\sigma\\bigg(\\frac{1}{2}\\sum_{j=1}^{M} w_{kj}^{(2)} \n            \\tanh\\bigg(\\frac{1}{2}\\sum_{i=1}^{D} w_{ji}^{(1)}x_i + \\frac{1}{2} w_{j0}^{(1)}\\bigg)\n            + \\frac{1}{2} \\sum_{j=1}^{M} w_{kj}^{(2)} + w_{k0}^{(2)}\\bigg) \\\\\n        &= \\sigma\\bigg(\\sum_{j=1}^{M} \\omega_{kj}^{(2)} \n        h\\bigg(\\sum_{i=1}^{D} \\omega_{ji}^{(1)}x_i + \\omega_{j0}^{(1)}\\bigg) + \\omega_{k0}^{(2)}\\bigg)\n    \\end{align*}\n    where \n    \\newline\n    \\begin{minipage}[b]{0.25\\textwidth}\n    \\[\n       \\omega_{ji}^{(1)} = \\frac{1}{2} w_{ji}^{(1)}\n    \\]\n    \\end{minipage}\n    \\begin{minipage}[b]{0.25\\textwidth}\n    \\[\n        \\omega_{j0}^{(1)} = \\frac{1}{2} w_{j0}^{(1)}\n    \\] \n    \\end{minipage}\n    \\begin{minipage}[b]{0.25\\textwidth}\n    \\[\n        \\omega_{kj}^{(2)} = \\frac{1}{2} w_{kj}^{(2)}\n    \\]\n    \\end{minipage}\n    \\begin{minipage}[b]{0.25\\textwidth}\n        \\[\n            \\omega_{k0}^{(2)} = \\frac{1}{2}\\sum_{j = 1}^M w_{kj}^{(2)} + w_{k0}^{(2)}\n        \\] \n    \\end{minipage}\n    Both new parameter sets can be obtained as linear transformations of the old ones,\n    so there exists an equivalent two-layer network using $\\tanh$ hidden activation functions,\n    but different parameters.\n\\end{proof}\n\n\\section*{Exercise 5.2 $\\star$}\nShow that maximizing the likelihood function under the conditional \ndistribution \\eqref{eq:5.16} for a multioutput network is equivalent to minimizing\nthe sum-of-squares error function (5.11).\n\n\\vspace{1em}\n\n\\begin{proof}\n    The likelihood function is given by \n    \\[\n        p(\\mathbf{T} | \\mathbf{X}, \\mathbf{w}, \\beta)\n        = \\prod_{n = 1}^N p(\\mathbf{t}_n | \\mathbf{x}_n, \\mathbf{w}, \\beta)\n    \\] \n    The target variables are assumed to be distributed normally\n    \\begin{equation}\\label{eq:5.16}\\tag{5.16}\n        p(\\mathbf{t}_n | \\mathbf{x}_n, \\mathbf{w}, \\beta) \n        = \\mathcal{N}(\\mathbf{t}_n | \\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}), \\beta^{-1}\\mathbf{I})\n    \\end{equation}\n    and since\n    \\[\n        \\ln \\mathcal{N}(\\mathbf{t}_n | y(\\mathbf{x}_n, \\mathbf{w}), \\beta^{-1}\\mathbf{I})\n        = -\\frac{N}{2} \\ln \\beta - \\frac{NK}{2} \\ln(2\\pi) - \\frac{\\beta}{2} \n        ||\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n||^2\n    \\] \n    the negative log-likelihood is given by\n    \\[\n        -\\ln p(\\mathbf{t} | \\mathbf{X}, \\mathbf{w}, \\beta)\n        = \\frac{\\beta}{2}\\sum_{n=1}^{N} \n        ||\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n||^2 + \\text{const}\n    \\] \n    where we grouped the terms that don't depend on $\\mathbf{w}$ under the constant term.\n    Maximization of the likelihood function is equivalent to minimizing the negative \n    log-likelihood.\n    Therefore, one can easily find that this is equivalent to minimizing the error function\n    \\begin{equation}\\label{eq:5.11}\\tag{5.11}\n        E(\\mathbf{w}) = \\frac{1}{2} \\sum_{n=1}^{N} \n        ||\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n||^2\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 5.3 $\\star \\star$}\nConsider a regression problem involving multiple target variables in which\nit is assumed that the distribution of the targets, conditioned on the input\nvector $\\mathbf{x}$, is a Gaussian of the form\n\\begin{equation}\\label{eq:5.192}\\tag{5.192}\n    p(\\mathbf{t} | \\mathbf{x}, \\mathbf{w}) \n    = \\mathcal{N}(\\mathbf{t} | \\mathbf{y}(\\mathbf{x}, \\mathbf{w}), \\mathbf{\\Sigma})\n\\end{equation}\nwhere $\\mathbf{y(x, w)}$ is the output of a neural network with input vector\n$\\mathbf{x}$ and weight vector $\\mathbf{w}$, and $ \\mathbf{\\Sigma}$ is the\ncovariance of the assumed Gaussian noise on the targets. Given a set\nof independent observations of $\\mathbf{x}$ and $\\mathbf{t}$, write down\nthe error function that must be minimized in order to find the maximum\nlikelihood solution for $\\mathbf{w}$, if we assume that $ \\mathbf{\\Sigma}$\nis fixed and known. Now assume that $ \\mathbf{\\Sigma}$ is also to be determined\nfrom the data, and write down an expression for the maximum likelihood\nsolution for $ \\mathbf{\\Sigma}$. Note that the optimizations of\n$\\mathbf{w}$ and $\\mathbf{\\Sigma}$ are now coupled, in contrast to the\ncase of independent target variables discussed in Section 5.2.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The negative log-likelihood is given by\n    \\begin{align*}\n    -\\ln p(\\mathbf{T} | \\mathbf{X}, \\mathbf{w})\n    &= -\\sum_{i=1}^{N} \\ln \\mathcal{N}(\\mathbf{t}_n | \\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}), \\mathbf{\\Sigma}) \\\\\n    &= \\frac{NK}{2} \\ln(2\\pi) + \\frac{N}{2} \\ln|\\mathbf{\\Sigma}| \n    + \\frac{1}{2}  \\sum_{n=1}^{N} \\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big)^T\n    \\mathbf{\\Sigma}^{-1}\\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big)\n    \\end{align*}\n    Maximizing the likelihood is equivalent to minimizing the negative\n    log-likelihood. Therefore, the error function that must be minimized\n    to obtain maximum likelihood is given by\n    \\[\n        E(\\mathbf{w}, \\mathbf{\\Sigma}) \n        = \\frac{N}{2} \\ln|\\mathbf{\\Sigma}|\n        + \\frac{1}{2}  \\sum_{n=1}^{N} \\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big)^T\n        \\mathbf{\\Sigma}^{-1}\\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big)\n    \\] \n    In the case when $\\mathbf{\\Sigma}$ is known, we can simply treat\n    the determinant term as a constant, so minimizing\n    the error function\n    \\[\n        E(\\mathbf{w}) = \n        \\frac{1}{2}  \\sum_{n=1}^{N} \\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big)^T\n        \\mathbf{\\Sigma}^{-1}\\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big)\n    \\] \n    would yield the maximum likelihood solution $\\mathbf{w}_\\text{ML}$.\n    If $ \\mathbf{\\Sigma}$ is unknown, we can't do that and the\n    determination of $\\mathbf{w}_{\\text{ML}}$ would use $\\mathbf{\\Sigma}$,\n    so that's why this time the optimizations of $\\mathbf{w}$\n    and $\\mathbf{\\Sigma}$ are coupled. The MLE for\n    the covariance matrix is obtained by taking the\n    derivative of the negative log-likelihood wrt. $\\mathbf{\\Sigma}^{-1}$, equalizing\n    it to 0 and then solving for $\\mathbf{\\Sigma}$. Taking the\n    derivative of the negative log-likelihood yields\n    \\begin{align*}\n        \\pdv{\\mathbf{\\Sigma}^{-1}} \\ln p(\\mathbf{T} | \\mathbf{X}, \\mathbf{w})\n        &= \\frac{N}{2} \\pdv{\\mathbf{\\Sigma}^{-1}} \\ln |\\mathbf{\\Sigma}| +\n        \\frac{1}{2}  \\sum_{n=1}^{N} \\pdv{\\mathbf{\\Sigma}^{-1}} \n        \\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big)^T\n        \\mathbf{\\Sigma}^{-1}\\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big) \\\\\n        &= -\\frac{N}{2} \\pdv{\\mathbf{\\Sigma}^{-1}} \\ln |\\mathbf{\\Sigma}^{-1}| +\n        \\frac{1}{2}  \\sum_{n=1}^{N} \\pdv{\\mathbf{\\Sigma}^{-1}} \n        \\Trace\\big\\{\\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big)^T\n        \\mathbf{\\Sigma}^{-1}\\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big)\\big\\} \\\\\n        &= -\\frac{N}{2} \\mathbf{\\Sigma} \n        + \\frac{1}{2}  \\sum_{n=1}^{N} \\pdv{\\mathbf{\\Sigma}^{-1}} \n        \\Trace\\big\\{\\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big)^T\n        \\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big) \\mathbf{\\Sigma}^{-1}\\big\\}\\\\\n        &= -\\frac{N}{2} \\mathbf{\\Sigma} + \\frac{1}{2} \\sum_{n=1}^{N} \n        \\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big)^T\n        \\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big)\n    \\end{align*}\n    where we've used the cyclic property of the trace operator and the fact that\n    \\[\n        \\pdv{\\mathbf{A}} \\ln |A| = A^{-T}\n    \\]\n    Now, equalizing\n    the derivative with 0 and solving for $\\mathbf{\\Sigma}$ gives\n    the MLE for the covariance matrix:\n    \\[\n        \\mathbf{\\Sigma}_\\text{ML}\n        = \\frac{1}{N} \\sum_{n=1}^{N} \n        \\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big)^T\n        \\big(\\mathbf{y}(\\mathbf{x}_n, \\mathbf{w}) - \\mathbf{t}_n\\big)\n    \\] \n\\end{proof}\n\n\\section*{Exercise 5.4 $\\star \\star$}\nConsider a binary classification problem where the target values\nare $t \\in \\{0, 1\\}$, with a network output $y(\\mathbf{x}, \\mathbf{w})$\nthat represents $p(t = 1 | \\mathbf{x})$, and suppose that\nthere is a probability $\\epsiilon$ that the class label\non a trainining data point has been incorrectly set.\nAssuming independent and identically distributed data,\nwrite down the error function corresponding to the negative\nlog likelihood. Verify that the error function $\\eqref{eq:5.21}$\nis obtained when $\\epsilon = 0$. Note that this error function\nmakes the model robust to incorrectly labelled data, in contrast\nto the usual error function.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We're going to model the problem similarly with what we've done in\n    Section 4.2.2, but this time taking into account the mislabelled training data\n    probability. As a result, let $r \\in \\{0, 1\\}$ the real target values, considering\n    mislabelling. Therefore, we can find the label probabilities by weighting in the error\n    chance:\n    \\begin{align*}\n        p(r = 1 | \\mathbf{x}, \\mathbf{w}) \n        &= (1 - \\epsilon)p(t = 1 | \\mathbf{x}, \\mathbf{w}) \n        + \\epsilon p(t = 0 | \\mathbf{x}, \\mathbf{w})\n        = (1 - \\epsilon)y(\\mathbf{x}_n, \\mathbf{w}) \n        + \\epsilon \\big(1 - y(\\mathbf{x}_n, \\mathbf{w})\\big)\n    \\end{align*}\n    \\vspace{-2em}\n    \\begin{align*}\n        p(r = 0 | \\mathbf{x}, \\mathbf{w}) \n        &= (1 - \\epsilon)p(t = 0 | \\mathbf{x}, \\mathbf{w}) \n        + \\epsilon p(t = 1 | \\mathbf{x}, \\mathbf{w})\n        = (1 - \\epsilon)\\big(1 - y(\\mathbf{x}_n, \\mathbf{w})\\big) \n        + \\epsilon y(\\mathbf{x}_n, \\mathbf{w})\n    \\end{align*}\n    We can combine both of these into\n    \\begin{align*}\n        p(r | \\mathbf{x}, \\mathbf{w}) \n        &= p(r = 1 | \\mathbf{x}, \\mathbf{w})^r p(r = 0 | \\mathbf{x}, \\mathbf{w})^{1 - r} \\\\\n        &= \\big[(1 - \\epsilon)y(\\mathbf{x}_n, \\mathbf{w}) + \\epsilon \\big(1 - y(\\mathbf{x}_n, \\mathbf{w})\\big)\\big]^r\n        \\big[(1 - \\epsilon)\\big(1 - y(\\mathbf{x}_n, \\mathbf{w})\\big) \n        + \\epsilon y(\\mathbf{x}_n, \\mathbf{w})\\big]^{1 - r}\n    \\end{align*}\n    Therefore, the negative log-likelihood is given by\n    \\begin{align*}\n        - \\ln p(\\mathbf{r} | \\mathbf{\\mathbf{X}}, \\mathbf{w})\n        = - \\ln \\prod_{i=1}^N p(r_n | \\mathbf{x}_n, \\mathbf{w})\n        = - \\sum_{i=1}^{N} \\{r_n \\ln p(r_n = 1 | \\mathbf{x}_n, \\mathbf{w}) \n            + (1 - r_n) \\ln p(r_n = 0 | \\mathbf{x}, \\mathbf{w})\\} \n    \\end{align*}\n    As a result, this is equivalent to minimizing the error function\n    \\[\n        E(\\mathbf{w}) = -\\sum_{i=1}^{N} \n        \\big[r_n \\ln\\big\\{(1 - \\epsilon)y(\\mathbf{x}_n, \\mathbf{w}) \n            + \\epsilon\\big(1 - y(\\mathbf{x}_n, \\mathbf{w})\\big)\\big\\}\n            + (1 - r_n) \\ln\\big\\{(1 - \\epsilon)\\big(1 - y(\\mathbf{x}_n, \\mathbf{w})\\big)\n            + \\epsilon y(\\mathbf{x}_n, \\mathbf{w})\\big]\n    \\] \n    which for $\\epsilon = 0$ is equivalent to $\\eqref{eq:5.21}$.\n\\end{proof}\n\n\\section*{Exercise 5.5 $\\star$}\nShow that maximizing likelihood for a multiclass neural network\nmodel in which the network outputs have the interpretation\n$y_k(\\mathbf{x}, \\mathbf{w}) = p(t_k = 1 | \\mathbf{x})$ is equivalent to minimization\nof the cross-entropy function \\eqref{eq:5.24}.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Let's consider the binary target variables $t_k \\in \\{0, 1\\}$ have a 1-of-$K$ \n    coding scheme indicating the class. If we assume the class labels are independent, \n    given the input vector, the conditional distribution of the targets is\n    \\[\n        p(t_k | \\mathbf{x}) = \\prod_{k=1}^K p(t_k = 1 | \\mathbf{x})^{t_k}\n    \\] \n    As a result, the corresponding negative log likelihood is given by\n    \\[\n        -\\ln p(\\mathbf{T} | \\mathbf{X}, \\mathbf{w})\n        = -\\ln \\prod_{n=1}^N \\prod_{k=1}^K p(t_{nk} = 1 | \\mathbf{x}_n)^{t_{nk}}\n        = -\\ln \\sum_{n=1}^{N} \\sum_{k=1}^{K} t_{nk} \\ln p(t_{nk} = 1 | \\mathbf{x}_n) \n    \\]\n    Therefore, maximizing the likelihood of the model is equivalent to minimization\n    of the cross entropy function\n    \\begin{equation}\\label{eq:5.24}\\tag{5.24}\n        E(\\mathbf{w}) \n        = -\\sum_{n=1}^{N} \\sum_{k=1}^{K} t_{nk} \\ln p(t_{nk} = 1 | \\mathbf{x}_n) \n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 5.6 $\\star$}\nShow the derivative of the error function (5.21) with respect\nto the activation $a_k$ for output units having a softmax activation\nfunction satisfies \\eqref{eq:5.18}.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The general result for the derivative of the softmax function with respect to the \n    activation $a_k$ was proved in Exercise 4.17 and is given by $\\eqref{eq:4.106}$.\n    Therefore, we have that\n    \\[\n        \\pdv{y_k}{a_k} = y_k(1 - y_k)\n    \\] \n    Taking the derivative of \n    \\begin{equation}\\label{eq:5.21}\\tag{5.21}\n        E(\\mathbf{w}) = -\\sum_{n=1}^{N} \\{t_n \\ln y_n + (1 - t_n) \\ln(1 - y_n)\\}\n    \\end{equation}\n    with respect to $a_k$ yields\n    \\begin{align*}\n        \\pdv{a_k} E(\\mathbf{w}) &= -t_k \\pdv{a_k} \\ln y_k - (1 - t_k) \\pdv{a_k} \\ln(1 - y_k) \n        = -t_k(1 - y_k) + y_k(1 - t_k)y_k \n        = y_k - t_k\n    \\end{align*}\n    As a result,\n    \\begin{equation}\\label{eq:5.18}\\tag{5.18}\n        \\pdv{E}{a_k} = y_k - t_k\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 5.7 $\\star$}\nShow the derivative of the error function $\\eqref{eq:5.21}$ with respect\nto the activation $a_k$ for an output unit having a logistic sigmoid activation\nfunction satisfies $\\eqref{eq:5.18}$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We've seen in Exercise 4.12 that\n    \\begin{equation}\\tag{4.88}\n        \\pdv{a} \\sigma(a) = \\sigma(a)(1 - \\sigma(a)\n    \\end{equation}\n    Since the output unit has a logistic sigmoid activation function, then\n    \\[\n        y_k = \\sigma(a_k)\n    \\] \n    Therefore, using $\\eqref{eq:4.88}$ gives\n     \\[\n         \\pdv{y_k}{a_k} = \\sigma(a_k)\\big(1 - \\sigma(a_k)\\big) = y_k(1 - y_k)\n    \\] \n    Analogously to Exercise 5.6, one can quickly reach that $\\eqref{eq:5.18}$ holds.\n\\end{proof}\n\n\\section*{Exercise 5.8 $\\star$}\nWe saw in $\\eqref{eq:4.88}$ that the derivative of the logistic sigmoid\nactivation function can be expressed in terms of the function value itself.\nDerive the corresponding result for the '$\\tanh$' activation function defined\nby (5.59).\n\n\\vspace{1em}\n\n\\begin{proof}\n    Taking the derivative of the '$\\tanh$' function is straightforward:\n    \\[\n        \\pdv{a} \\tanh(a) \n        = \\pdv{a} \\bigg(\\frac{e^a - e^{-a}}{e^a + e^{-a}}\\bigg)\n        = \\frac{\\big(e^a + e^{-a}\\big)^2 - \\big(e^a - e^{-a}\\big)^2}{\\big(e^a + e^{-a}\\big)^2}\n        = 1 - \\bigg(\\frac{e^a - e^{-a}}{e^a + e^{-a}}\\bigg)^2\n        = 1 - \\tanh(a)^2\n    \\] \n    Notice that the derivative of the `$\\tanh$` function can also be expressed\n    as a function of itself.\n\\end{proof}\n\n\\section*{Exercise 5.9 $\\star$}\nThe error function $\\eqref{eq:5.21}$ for binary classification problems\nwas derived for a network having a logistic-sigmoid output activation\nfunction, so that $0 \\leq y(\\mathbf{x}, \\mathbf{w}) \\leq 1$, and data having\ntarget values $t \\in \\{0, 1\\}$. Derive the corresponding error function\nif we consider a network having an output $-1 \\leq y(\\mathbf{x}, \\mathbf{w}) \\leq 1$\nand target values $t = 1$ for class $\\mathcal{C}_1$ and $t = -1$ for\nclass  $\\mathcal{C}_2$. What would be the appropiate choice of output\nunit activation function?\n\n\\vspace{1em}\n\n\\begin{proof}\n    The hyperbolic tangent is the appropiate choice for the ouput unit\n    activation function, because `$\\tanh$` is a sigmoid function and its\n    values range between $-1$ and $1$. Let's consider the case of binary \n    classification in which we interpret the network output $y(\\mathbf{x}, \\mathbf{w})$\n    as the conditional probability $p(\\mathcal{C}_1 | \\mathbf{x})$, with\n    $p(\\mathcal{C}_2 | \\mathbf{x})$ given by $1 - y(\\mathbf{x}, \\mathbf{w})$. The\n    conditional distribution of targets given inputs is then of the form\n    \\[\n        p(t | \\mathbf{x}, \\mathbf{w}) \n        = y(\\mathbf{x}, \\mathbf{w})^{\\frac{1+t}{2}} \n        \\big\\{1 - y(\\mathbf{x}, \\mathbf{w})\\big\\}^{\\frac{1-t}{2}}\n    \\] \n    Taking the negative log-likelihood then yields\n    \\[\n        -\\ln p(\\mathbf{t} | \\mathbf{X}, \\mathbf{w})\n        = -\\ln \\prod_{n = 1}^N p(t_n | \\mathbf{x}_n, \\mathbf{w})\n        = -\\sum_{n=1}^{N} \\bigg\\{\\frac{1+t}{2} \\ln y(\\mathbf{x}, \\mathbf{w}) \n        + \\frac{1-t}{2} \\ln\\big(1 - y(\\mathbf{x}, \\mathbf{w})\\big)\\bigg\\}\n    \\] \n    As a result, maximizing the likelihood is equivalent to minimizing \n    the error function\n    \\[\n        E(\\mathbf{w}) = -\\sum_{n=1}^{N} \\bigg\\{\\frac{1+t}{2} \\ln y_n + \\frac{1-t}{2} \\ln(1 -  y_n)\\bigg\\}\n    \\] \n    where $y_n$ denotes $y(\\mathbf{x}_n, \\mathbf{w})$.\n\\end{proof}\n\n\\section*{Exercise 5.10 $\\star$}\nConsider a Hessian matrix $\\mathbf{H}$ with eigenvector equation $\\eqref{eq:5.33}$. By\nsetting the vector $\\mathbf{v}$ in (5.39) equal to each of the eigenvectors\n$\\mathbf{u}_i$ in turn, show that $\\mathbf{H}$ is positive definite if,\nand only if, all of its eigenvalues are positive.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Consider the eigenvector equation\n    \\begin{equation}\\label{eq:5.33}\\tag{5.33}\n        \\mathbf{H}\\mathbf{u}_i = \\lambda_i \\mathbf{u}_i\n    \\end{equation}\n    \\begin{enumerate}\n        \\item [\\to] Assume that $\\mathbf{H}$ is positive definite. Then,\n    \\[\n        \\mathbf{u}_i^T \\mathbf{H} \\mathbf{u}_i = \\lambda_i ||\\mathbf{u}_i||^2 > 0\n    \\] \n    which happens only if the eigenvalues $\\lambda_i$ are positive.\n    \\vspace{1em}\n    \\item [\\leftarrow] Suppose that the eigenvalues $\\lambda_i$ are positive.\n        Since the eigenvectors form an orthonormal basis, an arbitrary\n        vector $\\mathbf{v}$ can be written in the form\n        \\begin{equation}\\label{eq:5.38}\\tag{5.38}\n            \\mathbf{v} = \\sum_{i} c_i \\mathbf{u}_i \n        \\end{equation}\n        Therefore, \n        \\[\n            \\mathbf{v}^T\\mathbf{H}\\mathbf{v}\n            = \\bigg(\\sum_{i} c_i \\mathbf{u}_i\\bigg)^T \\mathbf{H}\n            \\bigg(\\sum_{i} c_i \\mathbf{u}_i\\bigg)\n            = \\bigg(\\sum_{i} c_i \\mathbf{u}_i\\bigg)^T\n            \\bigg(\\sum_{i} c_i \\lambda_i \\mathbf{u}_i\\bigg)\n            = \\sum_{i} \\sum_{j} \\lambda_j c_i c_j \\mathbf{u}_i^T \\mathbf{u}_j\n            = \\sum_{i} \\lambda_i c_i^2\n        \\] \n        Since the eigenvalues $\\lambda_i$ are positive,\n        \\[\n            \\mathbf{v}^T\\mathbf{H}\\mathbf{v} = \\sum_{i} \\lambda_i c_i^2 > 0\n        \\] \n        for all $\\mathbf{v}$, which proves that $\\mathbf{H}$ is positive definite.\n    \\end{enumerate}\n\\end{proof}\n\n\\section*{Exercise 5.11 $\\star \\star ++++++++++++$}\nConsider a quadratic error function defined by $\\eqref{eq:5.32}$, in which the\nHessian matrix $\\mathbf{H}$ has an eigenvalue equation given by $\\eqref{eq:5.33}$.\nShow that the contours of constant error are ellipses whose axes are aligned\nwith eigenvectors $\\mathbf{u}_i$ with lengths that are inversly proportional\nto the square root of the corresponding eigenvalues $\\lambda_i$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Analogously to what we've seen in Section 5.3.2, we're going\n    to rewrite \n    \\begin{equation}\\label{eq:5.32}\\tag{5.32}\n        E(\\mathbf{w}) \\approxeq E(\\mathbf{w}^\\star) + \n        \\frac{1}{2}(\\mathbf{w} - \\mathbf{w}^\\star)^T\\mathbf{H}(\\mathbf{w} - \\mathbf{w}^\\star)\n    \\end{equation}\n    as \n    \\begin{equation}\\label{eq:5.36}\\tag{5.36}\n        E(\\mathbf{w}) \\approxeq E(\\mathbf{w}^\\star) + \\frac{1}{2} \\sum_{i} \\lambda_i \\alpha_i^2 \n    \\end{equation}\n    where we've expanded $(\\mathbf{w} - \\mathbf{w}^\\star)$ as a linear combination\n    of $\\mathbf{H}$'s eigenvectors:\n    \\begin{equation}\\label{eq:5.35}\\tag{5.35}\n       \\mathbf{w} - \\mathbf{w}^\\star = \\sum_{i} \\alpha_i \\mathbf{u}_i  \n    \\end{equation}\n    Now, since $\\mathbf{w}$ and $\\mathbf{w}^\\star$ are fixed, let \n    $\\xi = 2E(\\mathbf{w}) - 2E(\\mathbf{w}^\\star)$.\n    Therefore, one can rewrite $\\eqref{eq:5.36}$ as\n     \\[\n         \\xi \\approxeq \\sum_{i} \\lambda_i\\alpha_i^2 \n        \\sum_{i} \\frac{\\alpha_i^2}{\\lambda_i^{-1/2}} \n    \\] \n    This equation describes an ellipsoid with axes aligned to\n    the eigenvectors $\\mathbf{u}_i$ (since we use the coordinate system\n    defined in $\\eqref{eq:5.35}$) with axes lengths that are inversly\n    proportional to the square root of the corresponding eigenvalues\n    $\\lambda_i$.\n\\end{proof}\n\n\\section*{Exercise 5.12 $\\star \\star +++++++++++++$}\nBy considering the local Taylor expansion ($\\ref{eq:5.32}$) of\nan error function about a stationary point $\\mathbf{w}^\\star$, show\nthat the necessary and sufficient condition for the stationary point to be \na local minimum of the error function is that the Hessian matrix\n$\\mathbf{H}$, defined by $\\eqref{eq:5.30}$ with $\\widehat{\\mathbf{w}} = \\mathbf{w}^\\star$,\nbe positive definite.\n\n\\vspace{1em}\n\n\\begin{proof}\n    $ $\n    \\begin{enumerate}\n        \\item [\\to] Suppose that $\\mathbf{H}$ is positive definite. From\n            $\\eqref{eq:5.32}$ one could then find that\n             \\[\n                 E(\\mathbf{w}) - E(\\mathbf{w}^\\star) > 0\n            \\] \n            for $\\mathbf{w} \\neq  \\mathbf{w}^\\star$. Therefore, $E(\\mathbf{w}^\\star)$\n            would be the minimum value of E.\n        \\vspace{1em}\n        \\item [\\leftarrow] Assume that $\\mathbf{w}^\\star$\n            is a local minimum of E. Then,\n            \\[\n                E(\\mathbf{w}) -E(\\mathbf{w}^\\star) > 0\n            \\]\n            which would mean that \n            \\[\n                \\frac{1}{2} (\\mathbf{w} - \\mathbf{w}^\\star)^T \\mathbf{H}\n                (\\mathbf{w} - \\mathbf{w}^\\star) > 0\n            \\] \n            for $\\mathbf{w} \\neq \\mathbf{w}^\\star$, i.e.\n            $\\mathbf{H}$ is positive definite, since\n            $\\mathbf{w}$ respectively $\\mathbf{w} - \\mathbf{w}^\\star$\n            can be chosen arbitrarily.\n    \\end{enumerate}\n\\end{proof}\n", "meta": {"hexsha": "c6dac14466ce886d711c5cb1049a8eae9ddfef52", "size": 22863, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter5_neural_networks.tex", "max_stars_repo_name": "thesstefan/bishop_prml", "max_stars_repo_head_hexsha": "22c3e04e54f0ff91fa043d46aa0d760998094d1b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/chapter5_neural_networks.tex", "max_issues_repo_name": "thesstefan/bishop_prml", "max_issues_repo_head_hexsha": "22c3e04e54f0ff91fa043d46aa0d760998094d1b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter5_neural_networks.tex", "max_forks_repo_name": "thesstefan/bishop_prml", "max_forks_repo_head_hexsha": "22c3e04e54f0ff91fa043d46aa0d760998094d1b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.8829174664, "max_line_length": 117, "alphanum_fraction": 0.599527621, "num_tokens": 8244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127417985636, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.7291669737805434}}
{"text": "\\subsection{Algebraic dual spaces}\\label{subsec:algebraic_dual_spaces}\n\n\\begin{definition}\\label{def:dual_vector_space}\\mcite[50]{Knapp2016BasicAlgebra}\n  Let \\( V \\) be a \\hyperref[def:vector_space]{vector space} over the \\hyperref[def:field]{field} \\( \\BbbK \\). By \\fullref{thm:functions_over_algebra}, the set \\( \\hom(V, \\BbbK) \\) of all \\hyperref[def:semimodule/homomorphism]{linear maps} from \\( V \\) to the underlying field \\( \\BbbK \\) also form a vector space over \\( \\BbbK \\).\n\n  We call this space the \\term{algebraic dual space} of \\( V \\) and denote it by \\( V^* \\). We call the functions in \\( V^* \\) \\term{linear functionals}. The prefix \\enquote{algebraic} is important when confusion is possible with \\hyperref[def:continuous_dual_space]{continuous dual spaces}.\n\\end{definition}\n\n\\begin{remark}\\label{rem:functional}\n  The term \\enquote{functional} as a noun has no definite meaning.\n\n  \\begin{itemize}\n    \\item In the context of linear algebra, and in particular \\fullref{def:dual_vector_space}, the term \\enquote{functional} refers to \\enquote{linear functional}, i.e. a \\hyperref[def:semimodule/homomorphism]{linear map} from a \\hyperref[def:vector_space]{vector space} to its base field.\n\n    This terminology can be found, for example, in \\cite[50]{Knapp2016BasicAlgebra} and \\cite[sec. 26.1]{Тыртышников2004Лекции}.\n\n    \\item In the context of functional analysis, \\enquote{linear functional} may refer to either \\hyperref[def:continuous_dual_space]{continuous linear functionals} from some \\hyperref[def:topological_vector_space]{topological vector space} to its base field, or to arbitrary linear functionals.\n\n    This terminology can be found, for example, in \\cite[def. 3.1]{Rudin1991Functional} and \\cite[sec. 1.3]{Clarke2013}.\n\n    An arbitrary map from a topological vector space to its field may also be called a functional --- for example, \\cite[102]{KufnerFucik1980} and \\cite[223]{Deimling1985} refer to \\enquote{nonlinear functionals}. \\hyperref[def:minkowski_functional]{Minkowski functionals} are notoriously nonlinear.\n\n    \\item In the context of recursive functions, for example in \\cite{StanfordPlato:recursive_functions}, functionals are defined as \\enquote{operations which map one or more functions of type \\( \\BbbN^k \\to \\BbbN \\) (possibly of different arities) to other functions}.\n  \\end{itemize}\n\n  The commonality between linear algebra and functional analysis is that \\enquote{functional} refers to a map from a vector space to its base field. The commonality between functional analysis and logic is that \\enquote{functional} refers to a map acting on a set of functions.\n\\end{remark}\n\n\\begin{definition}\\label{def:duality_pairing}\\mimprovised\n  A \\term{duality pairing} \\( \\inprod \\anon \\anon: U \\times V \\to \\BbbK \\) is a \\hyperref[def:multilinear_function]{bilinear function}.\n\n   such that, if \\( \\inprod u v = 0 \\) for all \\( u \\), then \\( v = 0 \\).\n\\end{definition}\n\n\\begin{definition}\\label{thm:natural_duality_pairing}\n  Given a vector space \\( V \\), the following function is \\hyperref[def:multilinear_function]{bilinear}:\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\inprod \\cdot \\cdot: V^* \\times X \\to \\BbbK \\\\\n      &\\inprod {x^*} x \\mapsto x^*(x).\n    \\end{aligned}\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:algebraic_dual_basis}\n  Fix a \\hyperref[def:vector_space]{vector space} \\( V \\) over \\( \\BbbK \\) and a \\hyperref[def:hamel_basis]{basis} \\( B \\) of \\( V \\). For every basis vector \\( e \\), the \\term{projection functional} \\( \\pi_e: V \\to \\BbbK \\), defined in \\fullref{def:basis_decomposition}, maps an arbitrary vector \\( v \\) to its \\( e \\)-th coordinate.\n\n  \\begin{thmenum}\n    \\thmitem{thm:algebraic_dual_basis/independent} Given basis vectors \\( x \\) and \\( y \\) from \\( B \\), \\( \\pi_x \\) and \\( \\pi_y \\) are \\hyperref[def:linear_dependence]{linearly independent} in \\( V^* \\).\n\n    \\thmitem{thm:algebraic_dual_basis/finite} Furthermore, if \\( e_1, \\ldots, e_n \\) is a basis of \\( V \\), then \\( \\pi_{e_1}, \\ldots, \\pi_{e_n} \\) is a basis for the \\hyperref[def:dual_vector_space]{dual space} \\( V^* \\).\n\n    \\thmitem{thm:algebraic_dual_basis/infinite} The set \\( \\set{ \\pi_e \\given e \\in B } \\) spans \\( V^* \\) if and only if \\( V \\) is finite dimensional.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:algebraic_dual_basis/independent} Let \\( t_x \\) and \\( t_y \\) be scalars such that\n  \\begin{equation*}\n    t_x \\pi_x + t_y \\pi_y = 0_V.\n  \\end{equation*}\n\n  Then\n  \\begin{equation*}\n    0 = t_x \\pi_x(x) + t_y \\pi_y(x) = t_x \\cdot 1 + t_y \\cdot 0.\n  \\end{equation*}\n\n  Analogously, \\( t_y = 0 \\). Therefore, the functionals \\( \\pi_x \\) and \\( \\pi_y \\) are linearly independent.\n\n  \\SubProofOf{thm:algebraic_dual_basis/finite} Let \\( l \\) be an arbitrary linear functional. Then\n  \\begin{equation*}\n    l(y)\n  \\end{equation*}\n\n  \\SubProofOf{thm:algebraic_dual_basis/infinite}\n\\end{proof}\n\n\\begin{proposition}\\label{def:double_dual_canonical_embedding}\n  Fix a vector space \\( V \\). We define the canonical embedding into the double dual \\( V^{**} \\) of \\( V \\) by\n  \\begin{balign*}\n     & \\Phi: V \\to V^{**}                              \\\\\n     & \\Phi(x) \\coloneqq (\\varphi \\mapsto \\varphi(x)),\n  \\end{balign*}\n  where \\( \\varphi \\in V^* \\).\n\\end{proposition}\n\n\\begin{proposition}\\label{thm:finite_dimensional_dual_space_is_isomorphic}\n  The dual vector space of a finite-dimensional vector space has the same dimension.\n\\end{proposition}\n\\begin{proof}\n  Let \\( V \\) be an \\( n \\)-dimensional vector space over \\( F \\) and let \\( B \\) be a basis of \\( V \\). For each \\( b \\in B \\), define its dual vector on \\( V^* \\) as the linear \\hyperref[thm:quotient_module_universal_property]{extension} of the functions\n  \\begin{balign*}\n     & \\varphi: B \\to F                               \\\\\n     & \\varphi(x) \\coloneqq \\begin{cases}\n      1, & x = b    \\\\\n      0, & x \\neq b\n    \\end{cases}\n  \\end{balign*}\n  from the basis to the whole space. Denote the dual basis vector of \\( b \\) by \\( b^* \\).\n\n  We will now show that the set \\( B^* \\coloneqq \\{ b^* \\colon b \\in B \\} \\) forms a basis of \\( V^* \\).\n\n  Fix \\( x^* \\in V^* \\). Define\n  \\begin{equation*}\n    y^* \\coloneqq \\sum_{b \\in B} x^*(b) b^*.\n  \\end{equation*}\n\n  The linear functions \\( x^* \\) and \\( y^* \\) evidently agree on the basis \\( B \\). Hence, they agree on the whole space.\n\n  Hence, \\( B^* \\) is a basis of \\( V^* \\). Note that it has the same cardinality as the basis of \\( B \\).\n\\end{proof}\n\n\\begin{remark}\\label{rem:finite_dimensional_dual_space_isomorphism}\n  By \\fullref{thm:finite_dimensional_spaces_are_isomorphic}, the vector space \\( F^n \\) is isomorphic to its dual \\( {F^n}^* \\).\n\n  In practice, it is sometimes useful to distinguish between vectors and functionals. This is why we regard functionals as either\n  \\begin{itemize}\n    \\item functions\n    \\item column vectors\n    \\item row vectors\n  \\end{itemize}\n  depending on what interpretation suits us best.\n\n  This is consistent with \\fullref{thm:matrix_and_linear_function_algebras}, where we regard linear operators as matrices that act on vectors by multiplication.\n\n  For example, if we have the \\hyperref[def:differentiability]{differentiable} function \\( f(x, y) = xy \\), we can regard its gradient at the point \\( (\\overline x, \\overline y) \\) as the row vector\n  \\begin{balign*}\n    f'(\\overline x, \\overline y) =\n    \\begin{pmatrix}\n      \\overline y & \\overline x\n    \\end{pmatrix}.\n  \\end{balign*}\n\n  This is a linear functional that can acts on regular (column) vector by multiplying them from the left.\n\\end{remark}\n\n\\begin{definition}\\label{def:dual_linear_operator}\n  We define the \\term{dual linear operator} of \\( L: U \\to V \\) as\n  \\begin{balign*}\n     & L^*: V^* \\to U^*                \\\\\n     & L^*(v^*) \\coloneqq v^* \\circ L.\n  \\end{balign*}\n\\end{definition}\n\n\\begin{definition}\\label{def:vector_space_annihilator}\\mcite[52]{Knapp2016BasicAlgebra}\n  Fix a subset \\( S \\subseteq V \\) of a vector space \\( V \\) over \\( F \\). We define the \\term{annihilator} of \\( S \\) as the vector space of functionals\n  \\begin{equation*}\n    \\op{ann}(S) \\coloneqq \\{ x^* \\in V^* \\colon x^*(x) = 0_F \\quad\\forall x \\in S \\}.\n  \\end{equation*}\n\\end{definition}\n", "meta": {"hexsha": "f7e7646f0bec64eb29400b7d0c537f40a64bbb6d", "size": 8222, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/algebraic_dual_spaces.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/algebraic_dual_spaces.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/algebraic_dual_spaces.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.8133333333, "max_line_length": 334, "alphanum_fraction": 0.6855996108, "num_tokens": 2587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.7291447857742215}}
{"text": "\\documentclass[a4paper,10pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath,amssymb,amstext,amsthm}\n\\usepackage{xcolor}\n\n\\DeclareMathOperator*{\\E}{\\mathbb{E}_{\\pi}}   % rbp\n\\newcommand{\\Ps}{ P_{ss'}^a}   % rbp\n\\newcommand{\\R}{ R_{ss'}^a}   % rbp\n\n\\begin{document}\n\n\\section*{V and Q recursions}\n\n\\begin{align}\n V^{\\pi}(s)   &= \\E \\left\\{ \\sum\\limits_{k=0}^{\\infty} \\gamma^k r_{t+k+1} | s_t = s \\right\\} \\label{vr-value} \\\\ \n Q^{\\pi}(s,a) &= \\E \\left\\{ \\sum\\limits_{k=0}^{\\infty} \\gamma^k r_{t+k+1} | s_t = s, a_t = a \\right\\} \\label{qr-value}\n\\end{align}\n\nFrom Sutton's book page 70, Equation (3.10), recursive formulation of the value function update is:\n\n\\begin{align}\n V^{\\pi}(s) &= \\sum\\limits_a \\pi(s,a) \\underbrace{\\sum\\limits_{s'} \\Ps \\left[ \\R + \\gamma V^{\\pi}(s')\\right]}_{Q^{\\pi}(s,a)} \\\\\n\t    &= \\sum\\limits_a \\pi(s,a) Q^{\\pi}(s,a) \\label{v-rec}\n\\end{align}\n\nAs an exercise (Exercise 3.8, page 72 in Suttons book), the same recursion has to be derived, but this time for\nthe Q-Value function, Equation \\ref{qr-value}.\n\n\\begin{align*}\n Q^{\\pi}(s,a) &= \\E \\left\\{ \\sum\\limits_{k=0}^{\\infty} \\gamma^k  r_{t+k+1}  | s_t = s, a_t = a \\right\\}  \\\\\n\t      &= \\E \\left\\{ r_{t+1} + \\gamma \\sum\\limits_{k=0}^{\\infty} \\gamma^k r_{t+k+2} | s_t = s, a_t = a \\right\\} \\\\\n\t      &= \\E \\left\\{ r_{t+1} |  s_t = s, a_t = a \\right\\} + \\gamma\\, \\E \\left\\{ \\sum\\limits_{k=0}^{\\infty} \\gamma^k r_{t+k+1} | \\textcolor{red}{s_{t}} = s, a_{t} = a  \\right\\} \\\\\n\t      &= \\sum\\limits_{s'} \\Ps \\R  \t\t + \\gamma \\textcolor{red}{\\sum\\limits_{s'} \\Ps} \\E \\left\\{ \\sum\\limits_{k=0}^{\\infty} \\gamma^k r_{t+k+2} |  \\textcolor{red}{s_{t+1}} = s', \\textcolor{blue}{a_{t}} = a  \\right\\} \\\\\n\t      &= \\sum\\limits_{s'} \\Ps \\R \t\t + \\gamma \\sum\\limits_{s'} \\Ps  \\textcolor{blue}{ \\sum\\limits_{a'} \\pi(s',a')} \\E \\left\\{ \\sum\\limits_{k=0}^{\\infty} \\gamma^k r_{t+k+2}  |  s_{t+1} = s', \\textcolor{blue}{a_{t+1}} = a'  \\right\\} \\\\\n      \t      &= \\sum\\limits_{s'} \\Ps \\R \t\t + \\gamma \\sum\\limits_{s'} \\Ps  \\sum\\limits_{a'} \\pi(s',a') Q(s',a')  \\\\\n      \t      &= \\sum\\limits_{s'} \\Ps \\Big[ \\R\t  \t + \\gamma \\underbrace{ \\sum\\limits_{a'} \\pi(s',a') Q(s',a')}_{V^{\\pi}(s')} \\Big] \n\\end{align*}\n\nWe not that the last term in the expansion of Q, contains Equation \\ref{v-rec}. So we can substitute it back in and get:\n\n\n\\begin{equation}\n  Q^{\\pi}(s,a) = \\sum\\limits_{s'} \\Ps \\Big[ \\R\t + \\gamma V^{\\pi}(s')  \\Big] \n\\end{equation}\n\n\\end{document}\n", "meta": {"hexsha": "249ec76591dfecf7d4e6131480649c6bbd209007", "size": 2416, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_site/ml/docs/RQV.tex", "max_stars_repo_name": "gpldecha/gpldecha.github.io", "max_stars_repo_head_hexsha": "69887252490f6d074ead94959855f2c8f75b24f2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_site/ml/docs/RQV.tex", "max_issues_repo_name": "gpldecha/gpldecha.github.io", "max_issues_repo_head_hexsha": "69887252490f6d074ead94959855f2c8f75b24f2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "_site/ml/docs/RQV.tex", "max_forks_repo_name": "gpldecha/gpldecha.github.io", "max_forks_repo_head_hexsha": "69887252490f6d074ead94959855f2c8f75b24f2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.4042553191, "max_line_length": 233, "alphanum_fraction": 0.5703642384, "num_tokens": 1027, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7291447795094526}}
{"text": "\n\\subsection{Cauchy sequences}\n\n\\subsubsection{Cauchy sequence}\n\nA cauchy sequence is a sequence such that for an any arbitrarily small number \\(\\epsilon\\), there is a point in the sequence where all possible pairs after this are even closer together.\n\n\\((\\forall \\epsilon >0)(\\exists N\\in \\mathbb{N}: \\forall m,n \\in \\mathbb{N} >N)( |a_m - a_n|<\\epsilon)\\)\n\nThis last term gives a distance between two entries. In addition to the number line, this could be used on vectors, where distances are defined.\n\nAs a example, \\(\\dfrac{1}{n}\\) is a cauchy sequence, \\(\\sum_i \\dfrac{1}{n}\\) is not.\n\n\\subsubsection{Completeness}\n\nCauchy sequences can be defined on some given set. For example given all the numbers between \\(0\\) and \\(1\\) there are any number of different cauchy sequences converging at some point.\n\nIf it is possible to define a cauchy sequence on a set where the limit is not in the set, then the set is incomplete.\n\nFor example, the numbers between \\(0\\) and \\(1\\) but not including \\(0\\) and \\(1\\) are not complete. It is possible to define sequences which converge to these missing points.\n\nMore abstractly, you could have all vectors where \\(x^2+y^2<1\\). This is incomplete (or open) as sequences on these vectors can converge to limits not in the set.\n\nCauchy sequences are important when considering real numbers. We could define a sequence converging on \\(\\sqrt 2\\), but as this number is not in the set, it is incomplete.\n\n", "meta": {"hexsha": "c475729f9dc8bc78322244b06ca6b1b298252f3e", "size": 1441, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/reals/01-01-Convergence.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/reals/01-01-Convergence.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/reals/01-01-Convergence.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.4230769231, "max_line_length": 186, "alphanum_fraction": 0.7453157529, "num_tokens": 370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683105, "lm_q2_score": 0.8558511414521922, "lm_q1q2_score": 0.729144778027972}}
{"text": "\\chapter{Unit 5}\n\\section{Area Between Two Curves}\nLet $f(x)$ and $g(x)$ both be curves defined $\\forall{x}\\in[a,b]$. Let $A$ be\nthe area between these two curves.\n\nWe must always assume that $f(x)$ is the larger curve between the two. Should\nthis change, you must split the integral.\n\n\\begin{align}\n  A &= \\int_a^b [f(x)-g(x)] dx \\\\\n    &= \\int_c^d [f(y)-g(y)] dy\n\\end{align}\n\n\\section{Volume: The Disk Method}\n\\subsection{Disks}\n\\begin{align}\n  V &= \\int_a^b A(x) dx \\\\\n    &= \\pi\\int_a^b [r(x)]^2 dx\n\\end{align}\n\n\\subsection{Washers}\n\\begin{align}\n  V &= \\int_a^b A(x) dx \\\\\n    &= \\int_a^b \\pi(R^2-r^2) dx \\\\\n    &= \\pi\\int_a^b (R^2-r^2) dx\n\\end{align}\n\n\\section{Volume: The Shell Method}\nLet $r(x)$ be the distance of the slice to the axis of revolution, and $h(x)$ be\nthe width or height of that slice.\n\n\\begin{equation}\n  V = 2\\pi\\int_a^b r(x)h(x) dx\n\\end{equation}\n\n\\section{Arc Length}\nLet $L$ be the arc-length of a curve defined over an interval $[a,b]$.\n\n\\begin{equation}\n  L_{\\text{arc}} = \\int_a^b \\sqrt{1+[f'(x)]^2} dx\n\\end{equation}\n\n\\subsection{Surfaces}\nLet $r(x)$ be the distance from the rotating arc to the axis of rotation.\n\n\\begin{equation}\n  S_{\\text{rev}} = 2\\pi\\int_a^b r(x)\\sqrt{1+[f'(x)]^2} dx\n\\end{equation}\n\n\\section{Work}\n\\begin{align}\n  W &= \\vec{F}\\cdot{\\vec{D}}=FD\\cos\\theta \\\\\n    &= \\int_a^b F(x) dx\n\\end{align}\n\n\\subsection{Springs}\nSome work has a special definition. For example, springs follow Hooke's Law:\n\\begin{equation}\n  F=kd\n\\end{equation}\n\n\\subsection{Slabs of Liquid}\n\\begin{align}\n  \\Delta F &= \\text{Volume} \\cdot \\text{Density} \\\\\n           &= A\\Delta{y}\\rho \\\\\n  \\Delta W &= \\Delta{F}\\cdot x\n\\end{align}\n\n\\subsection{Chains and Lifting}\n\\begin{align}\n  W &= W_c + W_{nc} \\\\\n    &= (\\text{weight}\\cdot\\text{distance}) + (\\lambda{d}\\Delta{d}) + \\int_a^b\n  \\lambda(h-y) dy\n\\end{align}\n\n\\section{Moments, Centers of Mass}\n\\subsection{Discrete, Linear Systems}\n\\begin{equation}\n  M_O = \\frac{\\sum_{i=1}^{n} m_ix_i}{\\sum_{i=1}^n m_i}\n\\end{equation}\n\n\\subsection{Two-Dimensional Systems}\n\\begin{equation}\n  M_y = \\sum_{i=1}^{n} m_ix_i\n\\end{equation}\n\n\\begin{equation}\n  M_x = \\sum_{i=1}^{n} m_iy_i\n\\end{equation}\n\n\\begin{equation}\n  (\\bar{x}, \\bar{y}) = \\left( \\frac{M_y}{m}, \\frac{M_x}{m} \\right)\n\\end{equation}\n\n\\subsection{Planar Lamina}\n\\begin{align}\n  m &= Da \\\\\n    &= \\int_a^b \\rho(x)[f(x)-g(x)] dx\n\\end{align}\n\n\\begin{equation}\n  M_x = \\int_a^b \\rho(x)\\left[ \\frac{f(x)+g(x)}{2} \\right]\\left[ f(x)-g(x) \\right] dx\n\\end{equation}\n\n\\begin{equation}\n  M_y = \\int_a^b \\rho(x)\\left[ f(x)-g(x) \\right] dx\n\\end{equation}\n\n\\section{Fluid Pressure and Force}\n\\begin{description}\n  \\item[Pressure] $P=wh$\n  \\item[Force] $F=PA=whA$\n  \\item[Pascal's Principle] pressure exerted by a fluid at a depth h is\n    transmitted equally in all directions.\n\\end{description}\n", "meta": {"hexsha": "7c82e405da0473af6520f8a90ea4ccf24b9005ae", "size": 2808, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016/bc_calculus/units/unit_5.tex", "max_stars_repo_name": "ttaylorr/midterms", "max_stars_repo_head_hexsha": "fdde0fd1a66eb5242d0dfa04a5201c3ab6d6b7eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-01-06T06:55:26.000Z", "max_stars_repo_stars_event_max_datetime": "2015-01-06T06:55:26.000Z", "max_issues_repo_path": "2016/bc_calculus/units/unit_5.tex", "max_issues_repo_name": "ttaylorr/midterms", "max_issues_repo_head_hexsha": "fdde0fd1a66eb5242d0dfa04a5201c3ab6d6b7eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2016/bc_calculus/units/unit_5.tex", "max_forks_repo_name": "ttaylorr/midterms", "max_forks_repo_head_hexsha": "fdde0fd1a66eb5242d0dfa04a5201c3ab6d6b7eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.2068965517, "max_line_length": 85, "alphanum_fraction": 0.6428062678, "num_tokens": 1052, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7291219573723156}}
{"text": "\\chapter{Bonus: Fourier analysis}\n\\label{ch:fourier}\nNow that we've worked hard to define abstract inner product spaces,\nI want to give an (optional) application:\nhow to set up Fourier analysis correctly, using this language.\n\nFor fun, I also prove a form of Arrow's Impossibility Theorem\nusing binary Fourier analysis.\n\nIn what follows, we let $\\TT = \\RR/\\ZZ$ denote the ``circle group'',\nthought of as the additive group of ``real numbers modulo $1$''.\nThere is a canonical map $e \\colon \\TT \\to \\CC$ sending $\\TT$ to the\ncomplex unit circle, given by\n\\[ e(\\theta) = \\exp(2\\pi i \\theta). \\]\n\n\\section{Synopsis}\nSuppose we have a domain $Z$ and are interested in functions $f \\colon Z \\to \\CC$.\nNaturally, the set of such functions form a complex vector space.\nWe like to equip the set of such functions\nwith an positive definite \\emph{inner product}.\n% usually something like $\\left< f,g \\right> = \\EE_{x \\in Z} f(x) \\ol{g(x)}$.\n%which makes the set of such functions into a normed vector space.\n%(Here $\\EE$ is an ``average'', which is a finite sum if $|Z| < \\infty$\n%but otherwise is usually an integral.)\n%In particular, $\\left< f,f\\right>$ is the average of $|f(x)|^2$;\n%and thus gives a positive definite inner form.\n\nThe idea of Fourier analysis is to then select an \\emph{orthonormal basis}\nfor this set of functions, say $(e_\\xi)_{\\xi}$,\nwhich we call the \\vocab{characters};\nthe indexing $\\xi$ are called \\vocab{frequencies}.\nIn that case, since we have a basis, every function $f : Z \\to \\CC$\nbecomes a sum\n\\[ f(x) = \\sum_{\\xi} \\wh f(\\xi) e_\\xi \\]\nwhere $\\wh f(\\xi)$ are complex coefficients of the basis;\nappropriately we call $\\wh f$ the \\vocab{Fourier coefficients}.\nThe variable $x \\in Z$ is referred to as the \\vocab{physical} variable.\nThis is generally good because the characters are deliberately chosen\nto be nice ``symmetric'' functions,\nlike sine or cosine waves or other periodic functions.\nThus we decompose an arbitrarily complicated function into a sum of nice ones.\n\n\\section{A reminder on Hilbert spaces}\nFor convenience, we record a few facts about orthonormal bases.\n\\begin{proposition}\n\t[Facts about orthonormal bases]\n\t\\label{prop:orthonormal}\n\tLet $V$ be a complex Hilbert space\n\twith inner form $\\left< -,-\\right>$\n\tand suppose $x = \\sum_\\xi a_\\xi e_\\xi$ and $y = \\sum_\\xi b_\\xi e_\\xi$\n\twhere $e_\\xi$ are an orthonormal basis.\n\tThen\n\t\\begin{align*}\n\t\t\\left< x,x \\right> &= \\sum_\\xi |a_\\xi|^2 \\\\\n\t\ta_\\xi &= \\left< x, e_\\xi \\right> \\\\\n\t\t\\left< x,y \\right> &= \\sum_\\xi a_\\xi \\ol{b_\\xi}.\n\t\\end{align*}\n\\end{proposition}\n\\begin{exercise}\n\tProve all of these.\n\t(You don't need any of the preceding section,\n\tit's only there to motivate the notation with lots of scary $\\xi$'s.)\n\\end{exercise}\n\nIn what follows,\nmost of the examples will be of finite-dimensional inner product spaces\n(which are thus Hilbert spaces),\nbut the example of ``square-integrable functions''\nwill actually be an infinite dimensional example.\nFortunately, as I alluded to earlier,\nthis is no cause for alarm\nand you can mostly close your eyes and not worry about infinity.\n\n\\section{Common examples}\n\\subsection{Binary Fourier analysis on $\\{\\pm1\\}^n$}\nLet $Z = \\{\\pm 1\\}^n$ for some positive integer $n$,\nso we are considering functions $f(x_1, \\dots, x_n)$ accepting binary values.\nThen the functions $Z \\to \\CC$ form a $2^n$-dimensional vector space $\\CC^Z$,\nand we endow it with the inner form\n\\[ \\left< f,g \\right> = \\frac{1}{2^n} \\sum_{x \\in Z} f(x) \\ol{g(x)}. \\]\nIn particular,\n\\[ \\left< f,f \\right>\n\t= \\frac{1}{2^n} \\sum_{x \\in Z} \\left\\lvert f(x) \\right\\rvert^2 \\]\nis the average of the squares;\nthis establishes also that $\\left< -,-\\right>$ is positive definite.\n\nIn that case, the \\vocab{multilinear polynomials} form a basis of $\\CC^Z$,\nthat is the polynomials\n\\[ \\chi_S(x_1, \\dots, x_n) = \\prod_{s \\in S} x_s. \\]\n\\begin{exercise}\n\tShow that they're actually orthonormal under $\\left< -,-\\right>$.\n\tThis proves they form a basis, since there are $2^n$ of them.\n\\end{exercise}\nThus our frequency set is actually the subsets $S \\subseteq \\{1, \\dots, n\\}$.\nThus, we have a decomposition\n\\[ f = \\sum_{S \\subseteq \\{1, \\dots, n\\}} \\wh f(S) \\chi_S. \\]\n\\begin{example}\n\t[An example of binary Fourier analysis]\n\tLet $n = 2$.\n\tThen binary functions $\\{ \\pm 1\\}^2 \\to \\CC$ have a basis\n\tgiven by the four polynomials\n\t\\[ 1, \\quad x_1, \\quad x_2, \\quad x_1x_2. \\]\n\tFor example, consider the function $f$\n\twhich is $1$ at $(1,1)$ and $0$ elsewhere.\n\tThen we can put\n\t\\[ f(x_1, x_2) = \\frac{x_1+1}{2} \\cdot \\frac{x_2+1}{2}\n\t\t= \\frac14 \\left( 1 + x_1 + x_2 + x_1x_2 \\right). \\]\n\tSo the Fourier coefficients are $\\wh f(S) = \\frac 14$\n\tfor each of the four $S$'s.\n\\end{example}\nThis notion is useful in particular for\nbinary functions $f : \\{\\pm1\\}^n \\to \\{\\pm1\\}$;\nfor these functions (and products thereof),\nwe always have $\\left< f,f \\right> = 1$.\n\nIt is worth noting that the frequency $\\varnothing$ plays a special role:\n\\begin{exercise}\n\tShow that\n\t\\[ \\wh f(\\varnothing) = \\frac{1}{|Z|} \\sum_{x \\in Z} f(x). \\]\n\\end{exercise}\n\n\\subsection{Fourier analysis on finite groups $Z$}\nThis time, suppose we have a finite abelian group $Z$,\nand consider functions $Z \\to \\CC$;\nthis is a $|Z|$-dimensional vector space.\nThe inner product is the same as before:\n\\[ \\left< f,g \\right> = \\frac{1}{|Z|} \\sum_{x \\in Z} f(x) \\ol{g(x)}. \\]\n\nTo proceed, we'll need to be able to multiply two elements of $Z$.\nThis is a bit of a nuisance since it actually won't really\nmatter what map I pick, so I'll move briskly;\nfeel free to skip most or all of the remaining paragraph.\n\\begin{definition}\nWe select a \\emph{symmetric non-degenerate bilinear form}\n\\[ \\cdot \\colon Z \\times Z \\to \\TT \\]\nsatisfying the following properties:\n\\begin{itemize}\n\t\\ii $\\xi \\cdot (x_1 + x_2) = \\xi \\cdot x_1 + \\xi \\cdot x_2$\n\tand $(\\xi_1 + \\xi_2) \\cdot x = \\xi_1 \\cdot x + \\xi_2 \\cdot x$\n\t(this is the word ``bilinear'')\n\t\\ii $\\cdot$ is symmetric,\n\t\\ii For any $\\xi \\neq 0$, there is an $x$ with $\\xi \\cdot x \\neq 0$\n\t(this is the word ``nondegenerate'').\n\\end{itemize}\n\\end{definition}\n\\begin{example}\n\t[The form on $\\Zc n$]\n\tIf $Z = \\Zc n$ then $\\xi \\cdot x = (\\xi x)/n$ satisfies the above.\n\\end{example}\nIn general, it turns out finite abelian groups\ndecompose as the sum of cyclic groups (see \\Cref{sec:FTFGAG}),\nwhich makes it relatively easy to find such a $\\cdot$;\nbut as I said the choice won't matter, so let's move on.\n\nNow for the fun part: defining the characters.\n\\begin{proposition}\n\t[$e_\\xi$ are orthonormal]\n\tFor each $\\xi \\in Z$ we define the character\n\t\\[ e_\\xi(x) = e(\\xi \\cdot x). \\]\n\tThe $|Z|$ characters form an orthonormal basis of the\n\tspace of functions $Z \\to \\CC$.\n\\end{proposition}\n\\begin{proof}\n\tI recommend skipping this one, but it is:\n\t\\begin{align*}\n\t\t\\left< e_{\\xi}, e_{\\xi'} \\right>\n\t\t&= \\frac{1}{|Z|} \\sum_{x \\in Z} e(\\xi \\cdot x) \\ol{e(\\xi' \\cdot x)} \\\\\n\t\t&= \\frac{1}{|Z|} \\sum_{x \\in Z} e(\\xi \\cdot x) e(-\\xi' \\cdot x) \\\\\n\t\t&= \\frac{1}{|Z|} \\sum_{x \\in Z} e\\left( (\\xi-\\xi') \\cdot x \\right).\n\t\\end{align*}\n\\end{proof}\n\nIn this way, the set of frequencies is also $Z$,\nbut the $\\xi \\in Z$ play very different roles from the ``physical'' $x \\in Z$.\nHere is an example which might be enlightening.\n\\begin{example}\n\t[Cube roots of unity filter]\n\tSuppose $Z = \\Zc3$, with the inner form given by $\\xi \\cdot x = (\\xi x)/3$.\n\tLet $\\omega = \\exp(\\frac 23 \\pi i)$ be a primitive cube root of unity.\n\tNote that\n\t\\[ e_\\xi(x) = \\begin{cases}\n\t\t\t1 & \\xi = 0 \\\\\n\t\t\t\\omega^x & \\xi = 1 \\\\\n\t\t\t\\omega^{2x} & \\xi = 2.\n\t\t\\end{cases} \\]\n\tThen given $f \\colon Z \\to \\CC$ with $f(0) = a$, $f(1) = b$, $f(2) = c$,\n\twe obtain\n\t\\[ f(x) = \\frac{a+b+c}{3} \\cdot 1\n\t\t+ \\frac{a + \\omega^2 b + \\omega c}{3} \\cdot \\omega^x\n\t\t+ \\frac{a + \\omega b + \\omega^2 c}{3} \\cdot \\omega^{2x}.  \\]\n\tIn this way we derive that the transforms are\n\t\\begin{align*}\n\t\t\\wh f(0) &= \\frac{a+b+c}{3} \\\\\n\t\t\\wh f(1) &= \\frac{a+\\omega^2 b+ \\omega c}{3} \\\\\n\t\t\\wh f(2) &= \\frac{a+\\omega b+\\omega^2c}{3}.\n\t\\end{align*}\n\\end{example}\n\\begin{exercise}\n\tShow that in analogy to $\\wh f(\\varnothing)$\n\tfor binary Fourier analysis, we now have\n\t\\[ \\wh f(0) = \\frac{1}{|Z|} \\sum_{x \\in Z} f(x). \\]\n\\end{exercise}\nOlympiad contestants may recognize the previous example\nas a ``roots of unity filter'', which is exactly the point.\nFor concreteness, suppose one wants to compute\n\\[ \\binom{1000}{0} + \\binom{1000}{3} + \\dots + \\binom{1000}{999}. \\]\nIn that case, we can consider the function\n\\[ w : \\ZZ/3 \\to \\CC. \\]\nsuch that $w(0) = 1$ but $w(1) = w(2) = 0$.\nBy abuse of notation we will also think of $w$\nas a function $w : \\ZZ \\surjto \\ZZ/3 \\to \\CC$.\nThen the sum in question is\n\\begin{align*}\n\t\\sum_n \\binom{1000}{n} w(n)\n\t&= \\sum_n \\binom{1000}{n} \\sum_{k=0,1,2} \\wh w(k) \\omega^{kn} \\\\\n\t&= \\sum_{k=0,1,2} \\wh w(k) \\sum_n \\binom{1000}{n} \\omega^{kn} \\\\\n\t&= \\sum_{k=0,1,2} \\wh w(k) (1+\\omega^k)^n.\n\\end{align*}\nIn our situation, we have $\\wh w(0) = \\wh w(1) = \\wh w(2) = \\frac13$,\nand we have evaluated the desired sum.\nMore generally, we can take any periodic weight $w$\nand use Fourier analysis in order to interchange the order of summation.\n\n\\begin{example}\n\t[Binary Fourier analysis]\n\tSuppose $Z = \\{\\pm 1\\}^n$, viewed as an abelian group\n\tunder pointwise multiplication\n\thence isomorphic to $(\\ZZ/2\\ZZ)^{\\oplus n}$.\n\tAssume we pick the dot product defined by\n\t\\[ \\left< \\xi, x \\right>\n\t\t= \\half \\sum_i \\frac{\\xi_i-1}{2} \\cdot \\frac{x_i-1}{2} \\]\n\twhere $\\xi = (\\xi_1, \\dots, \\xi_n)$ and $x = (x_1, \\dots, x_n)$.\n\n\tWe claim this coincides with the first example we gave.\n\tIndeed, let $S \\subseteq \\{1, \\dots, n\\}$\n\tand let $\\xi \\in \\{\\pm1\\}^n$ which is $-1$ at positions in $S$,\n\tand $+1$ at positions not in $S$.\n\tThen the character $\\chi_S$ from the previous example\n\tcoincides with the character $e_\\xi$ in the new notation.\n\tIn particular, $\\wh f(S) = \\wh f(\\xi)$.\n\n\tThus Fourier analysis on a finite group $Z$ subsumes\n\tbinary Fourier analysis.\n\\end{example}\n\n\\subsection{Fourier series for functions $L^2([-\\pi, \\pi])$}\nThis is the most famous one, and hence the one you've heard of.\n\\begin{definition}\n\tThe space $L^2([-\\pi, \\pi])$ consists of all functions\n\t$f \\colon [-\\pi, \\pi] \\to \\CC$ such that\n\tthe integral\n\t$\\int_{[-\\pi, \\pi]} \\left\\lvert f(x) \\right\\rvert^2 \\; dx$\n\texists and is finite,\n\tmodulo the relation that a function which is zero ``almost everywhere''\n\tis considered to equal zero.\\footnote{We won't define this, yet,\n\t\tas it won't matter to us for now.\n\t\tBut we will elaborate more on this in the parts on measure theory.\n\t\n\t\tThere is one point at which this is relevant.\n\t\tOften we require that the function $f$ satisfies $f(-\\pi) = f(\\pi)$,\n\t\tso that $f$ becomes a periodic function,\n\t\tand we can think of it as $f \\colon \\TT \\to \\CC$.\n\t\tThis makes no essential difference\n\t\tsince we merely change the value at one point.}\n\n\tIt is made into an inner product space according to\n\t\\[ \\left< f,g \\right>\n\t\t= \\frac{1}{2\\pi} \\int_{[-\\pi, \\pi]} f(x) \\ol{g(x)} \\; dx. \\]\n\\end{definition}\nIt turns out (we won't prove) that this is an\n(infinite-dimensional) Hilbert space!\n\nNow, the beauty of Fourier analysis is that\n\\textbf{this space has a great basis}:\n\\begin{theorem}\n\t[The classical Fourier basis]\n\tFor each integer $n$, define\n\t\\[ e_n(x) = \\exp(inx). \\]\n\tThen $e_n$ form an orthonormal basis\n\tof the Hilbert space $L^2([-\\pi, \\pi])$.\n\\end{theorem}\nThus this time the frequency set $\\ZZ$ is infinite, and we have\n\\[ f(x) = \\sum_n \\wh f(n) \\exp(inx)\n\t\\quad\\text{almost everywhere} \\]\nfor coefficients $\\wh f(n)$\nwith $\\sum_n \\left\\lvert \\wh f(n) \\right\\rvert^2 < \\infty$.\nSince the frequency set is indexed by $\\ZZ$,\nwe call this a \\vocab{Fourier series}\nto reflect the fact that the index is $n \\in \\ZZ$.\n\\begin{exercise}\n\tShow once again\n\t\\[ \\wh f(0) = \\frac{1}{2\\pi} \\int_{[-\\pi, \\pi]} f(x) \\; dx. \\]\n\\end{exercise}\n\n\\section{Summary, and another teaser}\nWe summarize our various flavors of Fourier analysis in the following table.\n\\[\n\t\\begin{array}{llll}\n\t\t\\hline\n\t\t\\text{Type} & \\text{Physical var} & \\text{Frequency var}\n\t\t\t& \\text{Basis functions} \\\\ \\hline\n\t\t\\text{Binary} & \\{\\pm1\\}^n\n\t\t\t& \\text{Subsets } S \\subseteq \\left\\{ 1, \\dots, n \\right\\}\n\t\t\t& \\prod_{s \\in S} x_s \\\\\n\t\t\\text{Finite group} & Z & \\xi \\in Z, \\text{ choice of } \\cdot\n\t\t\t& e(\\xi \\cdot x) \\\\\n\t\t\\text{Fourier series} & \\TT \\text{ or } [-\\pi, \\pi] & n \\in \\ZZ\n\t\t\t& \\exp(inx) \\\\\n\t\t\\text{Discrete} & \\Zc n\n\t\t\t& \\xi \\in \\Zc n\n\t\t\t& e(\\xi x / n) \\\\\n\t\\end{array}\n\\]\nI snuck in a fourth row with $Z  = \\Zc n$,\nbut it's a special case of the second row, so no cause for alarm.\n\nAlluding to the future, I want to hint at how \\Cref{ch:pontryagin} starts.\nEach one of these is really a statement\nabout how functions from $G \\to \\CC$\ncan be expressed in terms of functions $\\wh G \\to \\CC$,\nfor some ``dual'' $\\wh G$.\nIn that sense, we could rewrite the above table as:\n\\[\n\t\\begin{array}{llll}\n\t\t\\hline\n\t\t\\text{Name} & \\text{Domain }G & \\text{Dual }\\wh G \n\t\t\t& \\text{Characters} \\\\ \\hline\n\t\t\\text{Binary} & \\{\\pm1\\}^n\n\t\t\t& S \\subseteq \\left\\{ 1, \\dots, n \\right\\}\n\t\t\t& \\prod_{s \\in S} x_s \\\\\n\t\t\\text{Finite group} & Z\n\t\t\t& \\xi \\in \\wh Z \\cong Z & e( i \\xi \\cdot x) \\\\\n\t\t\\text{Fourier series} & \\TT \\cong [-\\pi, \\pi]  & n \\in \\ZZ\n\t\t\t& \\exp(inx) \\\\\n\t\t\\text{Discrete} & \\ZZ/n\\ZZ & \\xi \\in \\ZZ/n\\ZZ\n\t\t\t& e(\\xi x / n) \\\\\n\t\\end{array}\n\\]\nIt will turn out that in general\nwe can say something about many different domains $G$,\nonce we know what it means to integrate a measure.\nThis is the so-called \\emph{Pontryagin duality};\nand it is discussed as a follow-up bonus in \\Cref{ch:pontryagin}.\n\n\\section{Parseval and friends}\nHere is a fun section in which you get to learn a lot of big names quickly.\nBasically, we can take each of the three results\nfrom Proposition~\\ref{prop:orthonormal},\ntranslate it into the context of our Fourier analysis\n(for which we have an orthonormal basis of the Hilbert space),\nand get a big-name result.\n\n\\begin{corollary}\n\t[Parseval theorem]\n\tLet $f \\colon Z \\to \\CC$, where $Z$ is a finite abelian group.\n\tThen \\[ \\sum_\\xi |\\wh f(\\xi)|^2 = \\frac{1}{|Z|} \\sum_{x \\in Z} |f(x)|^2. \\]\n\tSimilarly, if $f \\colon [-\\pi, \\pi] \\to \\CC$ is square-integrable then\n\tits Fourier series satisfies\n\t\\[ \\sum_n |\\wh f(n)|^2 = \\frac{1}{2\\pi} \\int_{[-\\pi, \\pi]} |f(x)|^2 \\; dx. \\]\n\\end{corollary}\n\\begin{proof}\nRecall that $\\left< f,f\\right>$ is equal to the\nsquare sum of the coefficients.\n\\end{proof}\n\n\\begin{corollary}\n\t[Fourier inversion formula]\n\tLet $f : Z \\to \\CC$, where $Z$ is a finite abelian group.\n\tThen \\[ \\wh f(\\xi) = \\frac{1}{|Z|} \\sum_{x \\in Z} f(x) \\ol{e_\\xi(x)}. \\]\n\tSimilarly, if $f : [-\\pi, \\pi] \\to \\CC$ is square-integrable then\n\tits Fourier series is given by\n\t\\[ \\wh f(n) = \\frac{1}{2\\pi} \\int_{[-\\pi, \\pi]} f(x) \\exp(-inx) \\; dx. \\]\n\\end{corollary}\n\\begin{proof}\nRecall that in an orthonormal basis $(e_\\xi)_\\xi$,\nthe coefficient of $e_\\xi$ in $f$ is $\\left< f, e_\\xi\\right>$.\n\\end{proof}\n\\begin{ques}\n\tWhat happens when $\\xi = 0$ above?\n\\end{ques}\n\n\\begin{corollary}\n\t[Plancherel theorem]\n\tLet $f : Z \\to \\CC$, where $Z$ is a finite abelian group.\n\tThen \\[ \\left< f,g \\right> = \\sum_{\\xi \\in Z} \\wh f(\\xi) \\ol{\\wh g(\\xi)}. \\]\n\tSimilarly, if $f : [-\\pi, \\pi] \\to \\CC$ is square-integrable then\n\t\\[ \\left< f,g \\right> = \\sum_n \\wh f(n) \\ol{\\wh g(n)}. \\]\n\\end{corollary}\n\\begin{ques}\n\tProve this one in one line (like before).\n\\end{ques}\n\n\\section{Application: Basel problem}\nOne cute application about Fourier analysis on $L^2([-\\pi, \\pi])$\nis that you can get some otherwise hard-to-compute sums,\nas long as you are willing to use a little calculus.\n\nHere is the classical one:\n\\begin{theorem}\n\t[Basel problem]\n\tWe have\n\t\\[ \\sum_{n \\ge 1} \\frac{1}{n^2} = \\frac{\\pi^2}{6}. \\]\n\\end{theorem}\nThe proof is to consider the identity function $f(x) = x$,\nwhich is certainly square-integrable.\nThen by Parseval, we have\n\\[\n\t\\sum_{n \\in \\ZZ} \\left\\lvert \\wh f(n) \\right\\rvert^2\n\t= \\left< f,f\\right>\n\t= \\frac{1}{2\\pi} \\int_{[-\\pi, \\pi]} \\left\\lvert f(x) \\right\\rvert^2 \\; dx.\n\\]\nA calculus computation gives\n\\[  \\frac{1}{2\\pi} \\int_{[-\\pi, \\pi]} x^2 \\; dx = \\frac{\\pi^2}{3}. \\]\nOn the other hand, we will now compute all Fourier coefficients.\nWe have already that\n\\[ \\wh f(0) = \\frac{1}{2\\pi} \\int_{[-\\pi, \\pi]} f(x) \\; dx\n\t= \\frac{1}{2\\pi} \\int_{[-\\pi, \\pi]} x \\; dx = 0. \\]\nFor $n \\neq 0$, we have by definition\n(or ``Fourier inversion formula'', if you want to use big words)\nthe formula\n\\begin{align*}\n\t\\wh f(n) &= \\left< f, \\exp(inx) \\right> \\\\\n\t&= \\frac{1}{2\\pi} \\int_{[-\\pi, \\pi]} x \\cdot \\ol{\\exp(inx)} \\; dx \\\\\n\t&= \\frac{1}{2\\pi} \\int_{[-\\pi, \\pi]} x \\exp(-inx) \\; dx.\n\\end{align*}\nThe anti-derivative is equal to\n$\\frac{1}{n^2} \\exp(-inx) (1+inx)$,\nwhich thus with some more calculation gives that\n\\[ \\wh f(n) = \\frac{(-1)^n}{n} i. \\]\nSo\n\\[ \\sum_n \\left\\lvert \\wh f(n) \\right\\rvert^2\n\t= 2 \\sum_{n \\ge 1} \\frac{1}{n^2} \\]\nimplying the result.\n\n\\section{Application: Arrow's Impossibility Theorem}\nAs an application of binary Fourier analysis,\nwe now prove a form of\n\\href{https://en.wikipedia.org/wiki/Arrow's_impossibility_theorem}{Arrow's theorem}.\n\nConsider $n$ voters voting among $3$ candidates $A$, $B$, $C$.\nEach voter specifies a tuple $v_i = (x_i, y_i, z_i) \\in \\{\\pm1\\}^3$ as follows:\n\\begin{itemize}\n\t\\ii $x_i = 1$ if person $i$ ranks $A$ ahead of $B$, and $x_i = -1$ otherwise.\n\t\\ii $y_i = 1$ if person $i$ ranks $B$ ahead of $C$, and $y_i = -1$ otherwise.\n\t\\ii $z_i = 1$ if person $i$ ranks $C$ ahead of $A$, and $z_i = -1$ otherwise.\n\\end{itemize}\nTacitly, we only consider $3! = 6$ possibilities for $v_i$:\nwe forbid ``paradoxical'' votes of the form $x_i = y_i = z_i$\nby assuming that people's votes are consistent\n(meaning the preferences are transitive).\n\n\nFor brevity, let $x_\\bullet = (x_1, \\dots, x_n)$\nand define $y_\\bullet$ and $z_\\bullet$ similarly.\nThen, we can consider a voting mechanism\n\\begin{align*}\n\tf \\colon \\{\\pm1\\}^n &\\to \\{\\pm1\\} \\\\\n\tg \\colon \\{\\pm1\\}^n &\\to \\{\\pm1\\} \\\\\n\th \\colon \\{\\pm1\\}^n &\\to \\{\\pm1\\}\n\\end{align*}\nsuch that\n\\begin{itemize}\n\t\\ii $f(x_\\bullet)$ is the global preference of $A$ vs.\\ $B$,\n\t\\ii $g(y_\\bullet)$ is the global preference of $B$ vs.\\ $C$,\n\t\\ii and $h(z_\\bullet)$ is the global preference of $C$ vs.\\ $A$.\n\\end{itemize}\nWe'd like to avoid situations where the global preference\n$(f(x_\\bullet), g(y_\\bullet), h(z_\\bullet))$ is itself paradoxical.\n\nLet $\\EE f$ denote the average value of $f$ across all $2^n$ inputs.\nDefine $\\EE g$ and $\\EE h$ similarly.\nWe'll add an assumption that $\\EE f = \\EE g = \\EE h = 0$,\nwhich provides symmetry\n(and e.g.\\ excludes the possibility that $f$, $g$, $h$\nare constant functions which ignore voter input).\nWith that we will prove the following result:\n\\begin{theorem}\n\t[Arrow Impossibility Theorem]\n\tAssume that $(f,g,h)$ always avoids paradoxical outcomes,\n\tand assume $\\EE f = \\EE g = \\EE h = 0$.\n\tThen $(f,g,h)$ is either a dictatorship or anti-dictatorship:\n\tthere exists a ``dictator'' $k$ such that\n\t\\[ f(x_\\bullet) = \\pm x_k, \\qquad g(y_\\bullet) = \\pm y_k,\n\t\t\\qquad h(z_\\bullet) = \\pm z_k \\]\n\twhere all three signs coincide.\n\\end{theorem}\nUnlike the usual Arrow theorem, we do \\emph{not} assume\nthat $f(+1, \\dots, +1) = +1$ (hence possibility of anti-dictatorship).\n\n\\begin{proof}\n\tSuppose the voters each randomly select one of the $3!=6$\n\tpossible consistent votes.\n\tIn \\Cref{prob:arrow_lemma} it is shown\n\tthat the exact probability of a paradoxical outcome\n\tfor any functions $f$, $g$, $h$ is given exactly by\n\t\\[ \\frac14 + \\frac14 \\sum_{S \\subseteq \\{1, \\dots, n\\}}\n\t\t\\left( -\\frac13 \\right)^{\\left\\lvert S \\right\\rvert} \n\t\t\\left( \\wh f(S) \\wh g(S) + \\wh g(S) \\wh h(S) + \\wh h(S) \\wh f(S) \\right).\n\t\t\\]\n\tAssume that this probability (of a paradoxical outcome) equals $0$.\n\tThen, we derive\n\t\\[ 1 = \\sum_{S \\subseteq \\{1, \\dots, n\\}}\n\t\t-\\left( -\\frac13 \\right)^{\\left\\lvert S \\right\\rvert} \n\t\t\\left( \\wh f(S) \\wh g(S) + \\wh g(S) \\wh h(S) + \\wh h(S) \\wh f(S) \\right). \\]\n\tBut now we can just use weak inequalities.\n\tWe have $\\wh f(\\varnothing) = \\EE f = 0$ and similarly for $\\wh g$ and $\\wh h$,\n\tso we restrict attention to $|S| \\ge 1$.\n\tWe then combine the famous inequality $|ab+bc+ca| \\le a^2+b^2+c^2$\n\t(which is true across all real numbers) to deduce that\n\t\\begin{align*}\n\t\t1 &= \\sum_{S \\subseteq \\{1, \\dots, n\\}}\n\t\t-\\left( -\\frac13 \\right)^{\\left\\lvert S \\right\\rvert} \n\t\t\\left( \\wh f(S) \\wh g(S) + \\wh g(S) \\wh h(S) + \\wh h(S) \\wh f(S) \\right) \\\\\n\t\t&\\le \\sum_{S \\subseteq \\{1, \\dots, n\\}}\n\t\t\\left( \\frac13 \\right)^{\\left\\lvert S \\right\\rvert} \n\t\t\\left( \\wh f(S)^2 + \\wh g(S)^2 + \\wh h(S)^2 \\right) \\\\\n\t\t&\\le \\sum_{S \\subseteq \\{1, \\dots, n\\}} \\left( \\frac13 \\right)^1\n\t\t\\left( \\wh f(S)^2 + \\wh g(S)^2 + \\wh h(S)^2 \\right) \\\\\n\t\t&= \\frac13 (1+1+1) = 1.\n\t\\end{align*}\n\twith the last step by Parseval.\n\tSo all inequalities must be sharp, and in particular $\\wh f$, $\\wh g$, $\\wh h$\n\tare supported on one-element sets, i.e.\\ they are linear in inputs.\n\tAs $f$, $g$, $h$ are $\\pm 1$ valued, each $f$, $g$, $h$ is itself\n\teither a dictator or anti-dictator function.\n\tSince $(f,g,h)$ is always consistent, this implies the final result.\n\\end{proof}\n\n\n\\section{\\problemhead}\n\n\\begin{problem}\n\t[For calculus fans]\n\tProve that\n\t\\[ \\sum_{n \\ge 1} \\frac{1}{n^4} = \\frac{\\pi^4}{90}. \\]\n\t\\begin{hint}\n\t\tUse Parseval again, but this time on $f(x) = x^2$.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\t\\gim\n\t\\label{prob:arrow_lemma}\n\tLet $f,g,h \\colon \\{\\pm1\\}^n \\to \\{\\pm1\\}$\n\tbe any three functions.\n\tFor each $i$, we randomly select $(x_i, y_i, z_i) \\in \\{\\pm1\\}^3$\n\tsubject to the constraint that not all are equal\n\t(hence, choosing among $2^3-2=6$ possibilities).\n\tProve that the probability that\n\t\\[ f(x_1, \\dots, x_n) = g(y_1, \\dots, y_n) = h(z_1, \\dots, z_n) \\]\n\tis given by the formula\n\t\\[ \\frac14 + \\frac14 \\sum_{S \\subseteq \\{1, \\dots, n\\}}\n\t\t\\left( -\\frac13 \\right)^{\\left\\lvert S \\right\\rvert} \n\t\t\\left( \\wh f(S) \\wh g(S) + \\wh g(S) \\wh h(S) + \\wh h(S) \\wh f(S) \\right)\n\t\t\\]\n\t\\begin{hint}\n\t\tDefine the Boolean function $D : \\{\\pm 1\\}^3 \\to \\RR$ by\n\t\t$D(a,b,c) = ab+bc+ca$.\n\t\tWrite out the value of $D(a,b,c)$ for each $(a,b,c)$.\n\t\tThen, evaluate its expected value.\n\t\\end{hint}\n\t\\begin{sol}\n\tDefine the Boolean function $D : \\{\\pm 1\\}^3 \\to \\RR$ by\n\t\\[ D(a,b,c) = ab + bc + ca\n\t\t= \\begin{cases}\n\t\t\t3 & a,b,c \\text{ all equal} \\\\\n\t\t\t-1 & a,b,c \\text{ not all equal}.\n\t\t\\end{cases}.\n\t\\]\n\tThus paradoxical outcomes arise when\n\t$D(f(x_\\bullet), g(y_\\bullet), h(z_\\bullet)) = 3$.\n\tNow, we compute that for randomly selected\n\t$x_\\bullet$, $y_\\bullet$, $z_\\bullet$ that\n\t\\begin{align*}\n\t\t\\EE D(f(x_\\bullet), g(y_\\bullet), h(z_\\bullet))\n\t\t&= \\EE \\sum_S \\sum_T\n\t\t\t\\left( \\wh f(S) \\wh g(T) + \\wh g(S) \\wh h(T) + \\wh h(S) \\wh f(T) \\right)\n\t\t\t\\left( \\chi_S(x_\\bullet)\\chi_T(y_\\bullet) \\right) \\\\\n\t\t&= \\sum_S \\sum_T\n\t\t\t\\left( \\wh f(S) \\wh g(T) + \\wh g(S) \\wh h(T) + \\wh h(S) \\wh f(T) \\right)\n\t\t\t\\EE\\left( \\chi_S(x_\\bullet)\\chi_T(y_\\bullet) \\right).\n\t\\end{align*}\n\tNow we observe that:\n\t\\begin{itemize}\n\t\t\\ii If $S \\neq T$, then $\\EE \\chi_S(x_\\bullet) \\chi_T(y_\\bullet) = 0$,\n\t\tsince if say $s \\in S$, $s \\notin T$ then $x_s$ affects\n\t\tthe parity of the product with 50\\% either way,\n\t\tand is independent of any other variables in the product.\n\t\t\\ii On the other hand, suppose $S = T$.\n\t\tThen \n\t\t\\[ \\chi_S(x_\\bullet) \\chi_T(y_\\bullet)\n\t\t\t= \\prod_{s \\in S} x_sy_s. \\]\n\t\tNote that $x_sy_s$ is equal to $1$ with probability $\\frac13$\n\t\tand $-1$ with probability $\\frac23$\n\t\t(since $(x_s, y_s, z_s)$ is uniform from $3!=6$ choices,\n\t\twhich we can enumerate).\n\t\tFrom this an inductive calculation on $|S|$ gives that\n\t\t\\[\n\t\t\t\\prod_{s \\in S} x_sy_s\n\t\t\t=\n\t\t\t\\begin{cases}\n\t\t\t\t+1 & \\text{ with probability } \\half(1+(-1/3)^{|S|}) \\\\\n\t\t\t\t-1 & \\text{ with probability } \\half(1-(-1/3)^{|S|}).\n\t\t\t\\end{cases}\n\t\t\\]\n\t\tThus\n\t\t\\[ \\EE \\left( \\prod_{s \\in S} x_sy_s \\right) = \\left( -\\frac13 \\right)^{|S|}.  \\]\n\t\\end{itemize}\n\tPiecing this altogether, we now have that\n\t\\[\n\t\t\\EE D(f(x_\\bullet), g(y_\\bullet), h(z_\\bullet))\n\t\t=\n\t\t\\left( \\wh f(S) \\wh g(T) + \\wh g(S) \\wh h(T) + \\wh h(S) \\wh f(T) \\right)\n\t\t\\left( -\\frac13 \\right)^{|S|}.\n\t\\]\n\tThen, we obtain that\n\t\\begin{align*}\n\t\t&\\EE \\frac14 \\left( 1 + D(f(x_\\bullet), g(y_\\bullet), h(z_\\bullet)) \\right) \\\\\n\t\t=& \\frac14 + \\frac14\\sum_S\n\t\t\\left( \\wh f(S) \\wh g(T) + \\wh g(S) \\wh h(T) + \\wh h(S) \\wh f(T) \\right)\n\t\t\\wh f(S)^2 \\left( -\\frac13 \\right)^{|S|}.\n\t\\end{align*}\n\tComparing this with the definition of $D$ gives the desired result.\n\t\\end{sol}\n\\end{problem}\n", "meta": {"hexsha": "d1e88b0f91ff7f905a746be892287498c7c5a6d2", "size": 24357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/linalg/fourier.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/linalg/fourier.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/linalg/fourier.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9089456869, "max_line_length": 84, "alphanum_fraction": 0.6443322248, "num_tokens": 8826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7291219534082951}}
{"text": "%!TEX root =  ../main.tex\n\n\\section{Matrices}   \n\n\\paragraph{Matrix}\nA \\textbf{matrix} (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged in meaningful rows and columns.  The individual items in a matrix are called its elements or entries.\n\n\n\\paragraph{Size, Entries}\nA matrix's size is described by the number of rows, by the number of columns.  If a matrix is given\na name, an entry may be referred to by a subscript of row and column on that letter.  For example,\non matrix \\textbf{[A]}, one might refer to the entry in the second row and third column as\n\\textbf{A}$_{2,3}$\n\n\\begin{example}\n\\exProblem\nGiven that A is 1234 what is $A_{1,4}$?\n\n\\exSolution\n4\n\\end{example}\n\n\\subsection{Addition and Scalars}\nMatrices may be added if and only if they are the exact same size.  A matrix maybe multiplied by\na number (called a \\gls{scalar}), which is simply multiplied against every element in the matrix.\nTwo matrices are added just by adding the for corresponding entries, i.e. $A_{i,j}+B_{i,j}$ \nproduces the new entry at $i,j$.\n\n\\begin{example}\n\\exProblem\nIf A is 1234, what is 2A?\n\n\\exSolution\n2468?\n\\end{example}\n\n\\begin{example}\n\\exProblem\nIf A is 1234 and B is 0102 what is A+B?\n\n\\exSolution\n1336\n\\end{example}\n\n\\subsection{Matrix Multiplication}\nThe product of two matrices is the coming together of rows of the first, with columns of the second.  For example,\nto compute the top left entry in the product of two matrices, one multiplies each entry in the first row of the first matrix,\nagainst the corresponding entry in the first column of the second matrix.  (See below for a helpful visual.)  Naturally,\nthis means that the rows and columns must match up.\n\n\n\n\n\\subsection{Square Matrices}\nidentity, inverses, determinants \n\\subsection{Gaussian Elimination}\naugmented matrices\n\n\n\n", "meta": {"hexsha": "21d08ae06a11d244f5602cc67011d9424e5ae4ce", "size": 1826, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chAA/appendix07ma.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "chAA/appendix07ma.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chAA/appendix07ma.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.9344262295, "max_line_length": 206, "alphanum_fraction": 0.7579408543, "num_tokens": 481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7291219459867262}}
{"text": "\\chapter{Artificial Neural Networks}\n\\label{chap:neuralnetworks}\n\n\\emph{Artificial neural networks} are a class of machine learning algorithms which are loosely inspired by neuroscientific models of how biological neuronal networks operate.\nEarly work in neuroscience by Santiago Ram{\\'o}n y Cajal indicated that the nervous system is composed of complex networks of individual cells, later called neurons~\\cite{cajal1955}.\nThese neurons consist of a soma and axon.\nThe soma is the main part of the cell, and the axon extends from the soma, attaching to one or more somata from other neurons.\nA neuron creates a so called \"action potential\" if it is sufficiently excited by the axons attached to it, which propagates down its own axon to help excite or inhibit other neurons to which it is attached~\\cite{mcculloch1943}.\nIn this way, electrical signals are propagated through a neronal network.\nWork by Hodgkin \\& Huxley described mathematically how action potentials are generated in neurons and propagate from one neuron to another~\\cite{hodgkin1952}.\n\nArtificial neural networks mimic this behavior with a mathematical network of \\emph{artificial} neurons.\nMathematical signals propagate through this network, whereby each neuron performs a simple mathematical operation on its inputs to determine its output.\n\\emph{Feed forward artificial neural networks} are a subclass of artificial neural networks which contain no cycles, that is, there is no sequence of input/output connections that start and end at the same neuron.\nThis class of artificial neural network always contains at least one input neuron with nothing feeding into it, and at least one output neuron which feeds into nothing.\nThey therefore constitute a function, where the input is applied to the input neurons, the signal propagates through the network, and the output is extracted from the output neurons.\nIf the neuron operations are parameterized, then it may be possible to approximate various other functions through the appropriate selection of parameters.\nLet the function defined by a feed forward artificial neural network be denoted by $f(x|\\Theta)$, where $x$ is the input vector and $\\Theta$ is the complete set of parameters.\n\nFor feed forward neural networks, $f$ is computed in a sequence of layers, each consisting of some number of neurons, which perform comparatively simple mathematical operations on their inputs to produce an output.\nA layer's output is either used as input to the subsequent layer, or taken as the network output if there are no subsequent layers.\nBy convention, the input vector $x$ is considered the first layer of a network, with one neuron per input, where each neuron takes the value of the respective input.\nThe last layer in the network produces the function's output, either a scalar or vector of values.\nAll intermediate layers are termed \\emph{hidden layers}, each of which accepts the output of the preceding layer and produces one output per neuron in that layer.\nThe number of layers in a network (besides the first layer) is its \\emph{depth}.\nMathematically, we can express the output for layer $i$ as $h_i(x_i| \\theta_i)$, where $x_i$ is the input to the layer and $\\theta_i$ is the set of parameters for that layer.\n\nSome important notes on terminology: artificial neurons are also called \\emph{units}, which will be the preferred term hereafter to avoid confusion with biological neurons. Also, omitting the \\emph{artificial} from artificial neural networks is common parlance in the literature, and will be done in this thesis for convenience. To avoid possible confusion, biological neuronal networks will always be explicitly referred to as such.\n\nA common form of neural network layer is a \\emph{dense layer}, in which each unit calculates a weighted sum of the layer inputs, where the set of weights is unique to each unit.\nIt is also common to add a scalar bias term and apply a nonlinear activation function to the weighted sum.\nDense layers have a convenient mathematical representation:\n\n\\begin{equation}\nh_i(x_i|W, b)=\\sigma(W x_i + b),\n\\label{eq:denselayer}\n\\end{equation}\n\n\\noindent\nwhere $i$ indexes the layer, $W$ is a matrix of weights, $x_i$ is the layer input, $b$ is a vector of biases, and $\\sigma(\\cdot)$ is a nonlinear activation function.\nIf there are $n$ inputs to a layer and $m$ units in the layer, then $W\\in\\mathbb{R}^{n \\times m}$ and $b\\in\\mathbb{R}^{m}$.\nThe expression $W x + b$ is the \\emph{signal}, and $h$ is the \\emph{activation}.\nFor hidden layers, activations have traditionally taken the form of a sigmoidal, or \"s-shaped\", function such as the logistic function, $\\sigma(x) = 1/(1+e^{-x})$, or hyperbolic tangent, $\\sigma(x) = tanh(x)$.\nThese sigmoidal functions switch from \"off\" (low value) to \"on\" (high value) if the weighted sum in the argument is sufficiently high.\nThis loosely mimics the way that signals from attached axons combine to trigger an action potential in a neuron.\nFigure \\ref{fig:twolayernetwork} shows a graphical depiction of a parameterized, feed forward artificial neural network.\n\n\\begin{figure}\n\t\\centering\n\t%\\begin{center}\n\t\\includegraphics[width=0.8\\textwidth]{simpletwolayernetwork.pdf}\n\t%\\end{center}\n\t\\caption{A two layer neural network with two inputs, three hidden units, and a single output. The hidden layer and output are both dense layers, and arrows depict the weighted sum computed for each unit. Weights for each layer are numbered according to their index in the weight matrix W}\n\t\\label{fig:twolayernetwork}\n\\end{figure}\n\n\nDespite being conceptually simple, this formulation of neural networks is capable of approximating any continuous function on a compact subset in $\\mathbb{R}$ with arbitrarily small error, given enough hidden units~\\cite{cybenko1989}.\nThe challenge of using neural networks for function approximation is in finding the appropriate set of parameters to approximate the true function.\nFor simple feed forward neural networks, this is accomplished by quantifying the error between the true function and the approximation for a given training data set $X=(x_1, x_2, ..., x_N)$, using a differentiable loss function $L(\\Theta | X)$. \nThe weights are updated by differentiating $L$ with respect to $\\Theta$ and \"taking a step\" in parameter space opposite the direction of the gradient. \nThis update step can be repeated iteratively in a process called \\emph{gradient descent}, which was first proposed by Augustin-Louis Cauchy~\\cite{cauchy1847}.\nMathematically, parameters are updated according to:\n\\begin{equation}\n\\Theta_{k+1} = \\Theta_k - \\eta \\nabla L(\\Theta_k | X) = \\Theta_k - \\eta \\sum_{n=1}^{N} \\nabla L(\\Theta_k | x_n),\n\\label{eq:batch_gd}\n\\end{equation}\n\n\\noindent\nwhere $k$ indicates the iteration and $\\eta$ is a tunable step size.\nThe gradient can be efficiently calculated using an algorithm called \\emph{backpropagation}~\\cite{rumelhart1988}.\nWeights are usually initialized by drawing from random distributions that have some empirical or theoretical justification~\\cite{glorot2010}.\nA variant of this algorithm, called \\emph{stochastic gradient descent} (SCG) performs an update using a gradient computed from a random sample of the training data at each iteration.\nThere is also a batched version where the training data are randomly shuffled and divided into a fixed number of equal sized \\emph{mini-batches}, and an update is performed on each one. \nWhen all mini-batches have been used in an update step, this constitutes an \\emph{epoch}.\nTraining can be repeated for a fixed number of epochs or until the parameters sufficiently converge.\nGradient descent is a first order method because it uses only the gradient of the loss function, however various second order methods which incorporate the Hessian have also been used to train neural networks~\\cite{fletcher1964, polak1969, moller1993, marquardt1963}.\n\nLike many machine learning algorithms, neural networks risk \\emph{overfitting}, in which the network learns to approximate the training data (which usually contain noise), rather than the underlying function from which the training data are assumed to be drawn.\nThis hinders the ability of neural networks to generalize to unseen data.\nIn neural networks, overfitting is commonly the result of an overcomplete parameterization coupled with overtraining~\\cite{reed1993, dalianis1993}.\nMany regularization techniques have been introduced to prevent overfitting of neural networks, including early stopping~\\cite{morgan1990}, model pruning~\\cite{reed1993}, weight decay\\cite{krogh1992}, lateral inhibition~\\cite{krizhevsky2012}, induced sparsity~\\cite{ng2011, makhzani2015}, and dropout~\\cite{srivastava2014}, with dropout being one of the most common. \n\nDropout consists of randomly dropping units from the network during the training phase.\nEach time a training example is presented to the network, each unit in the network is dropped with probability $p$, commonly 0.5.\nEach application of dropout can be seen as generating a new network whose units are a subset of the units in the original network.\nGiven $n$ units in a network, there are $2^n$ possible dropout networks which all share weights with each other.\nDuring testing, no dropout is performed, and weights are rescaled by $p$.\nThis is equivalent to averaging the prediction of each dropout network.\nDropout helps prevent overfitting by limiting the effective number of parameters in each dropout network and reducing the amount of co-adaptation among units in the network~\\cite{srivastava2014}.\n\n\nIn recent years, more advanced forms of neural networks under the moniker \\emph{deep learning} have demonstrated success in sophisticated tasks, particularly for image and speech recognition~\\cite{krizhevsky2012, lecun2015, masci2011, hinton2012, he2016}.\nA common task is labeling an image or audio sample according to its content.\nLabeling tasks are commonly decomposed into many binary tasks, where a neural network must indicate whether a particular label is appropriate.\nPositive examples are those where the label is appropriate, and negative examples are those where it is not.\nDeep learning has also been applied in a variety of other applications such as quantitative structure activity relationship (QSAR) prediction~\\cite{ma2015}, particle detection~\\cite{ciodaro2012}, and reinforcement learning\\cite{mnih2015}.\nThese advances were catalyzed by the availability of large volumes of labeled data\\cite{deng2009, krizhevsky2009} and the improvements in computing power from general purpose graphical processing units (GP-GPUs) and distributed systems\\cite{chetlur2014, chu2007}.\nSuch factors allow experimentation with larger networks and more complicated layer operations such as convolution, which are described in the following section.\n\n\\section{Convolutional Neural Networks}\n\nAccurately labeling an image using a neural network often relies on the network's ability to detect low level features in the image such as edges and textures, which collectively indicate the image's content~\\cite{ng2011}.\nThis is accomplished by the appropriate parameter settings, which maximize a unit's activation when presented with a feature of interest, and can be learned through the standard backpropagation algorithm using training images. \nThe challenge, however, is that the relevant features may only occur in certain regions of the training images, so the network may not be able to recognize that feature in a new region.\nConvolutional layers explicitly allow detection of features in a translation invariant way, through a clever weight sharing strategy.\n\nTo illustrate the limitation of dense layers in translation invariant feature detection, consider the following example.\nSuppose the labeling task is to determine if an image does or does not contain a cat.\nSuppose further that no training image contains a cat in the upper left corner of the image.\nTherefore it is possible, even if the network has learned which low level features indicate the presence of a cat, that it will not recognize a cat contained in the upper left corner of the image, since it has not been explicitly shown examples of this.\nThis may seem unlikely, but consider that the network does not incorporate any semantic meaning of the word \"cat\", only that a certain set of example images are positive examples and a certain set are negative examples.\nIndeed, consider the slightly different labeling task where the classes being considered are \"contains a cat anywhere but the top left corner\" and its negation.\nIn this case, the same set of training images are appropriate and the hope is that the network would \\emph{not} classify images with cats in the upper left corner as positive examples.\nIn most cases, the labeling task is more like the former example than the latter, in which case it would be beneficial for the network to learn to detect objects in a \\emph{translation invariant} fashion. \nThis is the primary purpose of convolutional layers.\n\nThe term convolution is inherited from the field of functional analysis, where two functions, $f$ and $g$, are combined in the following way to generate a third function, $(f*g)$:\n\n\\begin{equation}\n(f*g)(t) = \\int_{-\\infty}^{\\infty}f(\\tau)~g(t-\\tau)~d\\tau.\n\\label{eq:math_conv}\n\\end{equation}\n\n\\noindent\nThe convolution involves reflecting one function about the y axis, shifting it with respect to the other function, and integrating the product. \nThe value of $t$ indicates the magnitude of shift.\nIf $f, g \\colon \\mathbb{Z} \\rightarrow \\mathbb{R}$, then the discrete convolution is analogously defined as:\n\n\\begin{equation}\n(f*g)(t) = \\sum_{\\tau = -\\infty}^{\\infty}f(\\tau)~g(t-\\tau).\n\\label{eq:math_conv}\n\\end{equation}\n\n\\noindent\nWhere $t, \\tau \\in \\mathbb{Z}$.\nIf we imagine $f$ and $g$ to be infinite dimensional vectors indexed by $\\tau$, then convolution amounts to reversing $g$, shifting it by $t$ units relative to $f$, and taking the dot product of the two vectors.\nThe same operation can be defined for two finite vectors by making them infinite by appending infinitely many zeros before and after them.\nThe zero portions contribute nothing to the convolution and allow the original finite vectors to be partially overlapping.\nA finite vector can be extracted from the result, since the convolution function is nonzero only when the convolved vectors overlap.\nFigure \\ref{fig:cont_disc_conv} illustrates the analogy between continuous convolution and discrete convolution of finite vectors.\n\n\\begin{figure}\n\t\\centering\n\t%\\begin{center}\n\t\\includegraphics[width=0.8\\textwidth]{discrete_continuous_conv.png}\n\t%\\end{center}\n\t\\caption{The relative position of two functions at four different values of t, for both continuous (left) and discrete (right) convolution. The functions are distinguished by color. In the continuous case, the functions are multiplied and integrated whereas in the discrete case, the dot product of the two arrays is taken (extending either array with zeros when necessary).}\n\t\\label{fig:cont_disc_conv}\n\\end{figure}\n\nConvolution can be extended for functions of two variables:\n\n\\begin{equation}\n(f*g)(t_1, t_2) = \\sum_{\\tau_1 = -\\infty}^{\\infty} ~\\sum_{\\tau_2 = -\\infty}^{\\infty}f(\\tau_1, \\tau_2)~g(t_1-\\tau_1, t_2-\\tau_2), \n\\label{eq:math_conv}\n\\end{equation}\n\n\\noindent\nwhere $t_1, t_2, \\tau_1, \\tau_2 \\in \\mathbb{Z}$.\nHere, $f$ and $g$ can be interpreted as infinite matrices, where convolution involves reversing $g$ in both indices, shifting it in both indices relative to $f$, and taking the dot product with $f$.\nAgain, this may be adapted for two finite matrices using the same infinite extension of zeros as for vectors.\nThis discrete, two dimensional, finite analog to convolution forms the basis of convolutional layers in neural networks.\n\nTo understand convolution of a monochrome pixelated image, consider it as a finite matrix where the matrix entries contain pixel values.\nFurther, consider a smaller matrix called a \\emph{filter} which entries are filter \\emph{weights}.\nBy convolving the filter over the image (as previously described), a new matrix is created where each value is the dot product of the matrices for a given shift of the filter relative to the image.\nTechnically the filter can be assumed reflected already, since the filter weights are trainable parameters anyways.\nThe region of the image covered by the filter is called the \\emph{receptive field}, and the dot product can be understood as taking a weighted sum of values in the receptive field, where the weights are precisely the filter weights.\nAs with dense layers, each weighted sum is typically passed through some nonlinear activation function.\nFigure \\ref{fig:convolutionallayer} depicts the application of a filter to the input of an image in three distinct positions.\nThe dot product between filter and image naturally extends to images with multiple \\emph{channels} (colors), as long as the filter has the same number of channels as the image.\n\n\\begin{figure}\n\t\\centering\n\t%\\begin{center}\n\t\\includegraphics[width=0.8\\textwidth]{conv_grid.png}\n\t%\\end{center}\n\t\\caption{Application of a 3x3 convolution filter to an input image. The dot product is taken between the filter and the receptive field (green) to produce a scalar output (red). Three positions of the filter are shown, each with a unique receptive field and output position.}\n\t\\label{fig:convolutionallayer}\n\\end{figure}\n\nThe result of a convolution in a particular position depends on the values of the input image and the weights, and indeed there exist weights which produce larger outputs only in the presence of particular local features in the input.\nHence convolution can be used in a neural network to detect patterns in the input.\nFurthermore, since a filter is convolved across the whole image, feature detection can be performed in a translation invariant way as desired. \nA filter may only detect a particular local feature, so multiple filters can be used to detect multiple features simultaneously, each producing a different channel in the output.\nNote that the output of a convolution layer resembles the structure of the input, so convolutional layers may be stacked.\n\nConvolutional neural networks often incorporate \\emph{pooling layers}, which reduce a region of the input (e.g. 3x3 pixels for an image) to a single grid element that takes either the maximum or average value (per channel) of the region. \nFor simplicity in this thesis, grid elements will be called pixels, regardless of grid dimensionality.\nPooling allows downsampling of the grid, and is often performed between convolutional layers. \nIt's also common to include a series of dense layers after all convolutional layers which combine the results of convolution in a way relevant to the learning task.\nIn order to do this, the multichannel input must first be flattened into a one dimensional vector.\nFigure \\ref{fig:conv_network} shows an example of a complete convolutional neural network.\n\n\\begin{figure}\n\t\\centering\n\t%\\begin{center}\n\t\\includegraphics[width=0.8\\textwidth]{conv_network.png}\n\t%\\end{center}\n\t\\caption{A convolutional neural network, consisting of alternating convolution and pooling layers, followed by two dense layers, producing a scalar output. Stacked rectangles indicate multiple channels. These convolutional layers increase the number of channels, which is typical but not necessary. Pooling downsamples the image but retains the same number of channels.}\n\t\\label{fig:conv_network}\n\\end{figure}\n\n\nThe design of convolutional layers gives rise to certain properties which prove useful in image related tasks:\n\\begin{itemize}\n\t\\item \\emph{Structural awareness.}\n\tConvolutional filters are constructed so that they exploit the structural characteristics of the input.\n \tRather than treat each pixel as independent of all others, convolution operates on local regions of pixels, allowing filters to detect spatial correlations in a straightforward manner.\n\t\\item \\emph{Locality}. \n\tFilters are typically significantly smaller than the size of the input, so for a given position, they are operating on a local neighborhood (receptive field) of the input image. \n\tAny features learned by a filter will necessarily be local as well. \n \tThe advantage of local features is that they are simpler and more universal than global features, since they can be combined to construct a wide variety of complex patterns (see \\emph{abstraction} below).\n\tFor example, filters which detect edges or textures will be more useful to subsequent layers in the network than a filter which recognizes only a single object or animal.\n \t\\item \\emph{Translation invariance}. \n \tAs discussed, a filter \"inspects\" each part of the image for a particular pattern, regardless of where that pattern occurred in the training images.\n \tThis improves generalizability because during training certain features may be presented in limited regions of the image, but detection of those features can still operate on a global scale.\n \t\\item \\emph{Abstraction}. Whereas a network's first convolutional layer detects patterns in the input, subsequent layers detect patterns in the output of previous layers. \n \tThis promotes a hierarchical abstraction of the input, where early layers detect local features, and subsequent layers combine features into more complex patterns.\n \tFor example, early filters may detect edges of varying orientations, middle filters may detect combinations of edges which indicate curves in space, and latter filters may detect combinations of curves which indicate a particular handwritten letter or digit.\n \t\\item \\emph{Resistence to overfitting}.\n \tOne interpretation of a convolutional layer is that each filter is a series of units, each responsible for a distinct receptive field on the input.\n \tA unit has nonzero weights only for the regions of the input in its receptive field, and all units in the filters share the same weights. \n \tThis combination of weight sharing and sparsity make a convolutional layer less prone to overfitting compared to a dense layer with the same number of units.\n \tBecause of the weight sharing in convolutional layers, the final dense layers often contain the majority of the parameters in the network.\n\\end{itemize}\n\nThe above properties make convolutional neural networks well suited for structured data with a natural hierarchy of abstraction.\nThe structural hierarchy of proteins suggests that convolution might be useful in interface prediction.\nUnfortunately, neither protein residues, nor their constituent atoms are aligned in a regular grid, so the above definition of convolution cannot be directly applied. \nIn Chapter \\ref{chap:methods}, convolutions are introduced which operate on irregular structures, namely graphs, and a graphical representation of proteins is presented which allows use of graph convolution for protein interface prediction.", "meta": {"hexsha": "ca92b90234fe90025b983cc2b9743cb7d411aed0", "size": 22842, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "neuralnetworks.tex", "max_stars_repo_name": "fouticus/msthesis", "max_stars_repo_head_hexsha": "50362de8bb633e7cc3737936b5c4ba2920423e19", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "neuralnetworks.tex", "max_issues_repo_name": "fouticus/msthesis", "max_issues_repo_head_hexsha": "50362de8bb633e7cc3737936b5c4ba2920423e19", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "neuralnetworks.tex", "max_forks_repo_name": "fouticus/msthesis", "max_forks_repo_head_hexsha": "50362de8bb633e7cc3737936b5c4ba2920423e19", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 98.4568965517, "max_line_length": 433, "alphanum_fraction": 0.8004115226, "num_tokens": 5048, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7290873929811963}}
{"text": "\\subsection{Row and Column Swapping}\n\nCan define elementary row operations in the identity matrix.\n\n\\subsubsection{Swapping rows}\n\n\\[\n    \\begin{bmatrix}\n        0&1\\\\\n        1&0\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        a&b\\\\\n        c&d\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n        c&d\\\\\n        a&b\n    \\end{bmatrix}\n\\]\n\nModifier $B$ is always on \\textbf{left}.\n\n\\subsubsection{Swapping columns}\n\n\\[\n    \\begin{bmatrix}\n        a&b\\\\\n        c&d\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        0&1\\\\\n        1&0\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n        b&a\\\\\n        d&c\n    \\end{bmatrix}\n\\]\n\nModifier $B$ is always on \\textbf{right}.\n\n\\subsection{Elimination steps}\n\nPerforming elimination:\n\n\\[E_{2,1}A+E_{3,2}A=(E_{2,1}E_{3,2})A=U\\]\n\nElimination algorithm:\n\\begin{itemize}\n    \\item $E_{2,1}$ is the pivot. Swap with $R_2$ if 0 (and $(2,1)$ is nonzero).\n    \\item $E_{3,2}$ involves getting $(2,2)$ as a pivot assuming nonzero to get $(3,2)$ as 0\n    \\item Result is invertible and non-singular, where $U$ is upper-triangular\n\\end{itemize}\n\nMatrix multiplication is not necessarily commutative but always associative.\n\n\\subsection{Matrix Multiplication Facts}\n\nIf $A$ is an $m\\times n$ matrix and $B$ is $n\\times p$, then $AB=C$ must be $m\\times p$.\nStandard method would be to take dot products by row and column. By column: Columns of $C$ are combinations of columns\nof $A$. By row: Rows of $C$ are combinations of rows of $B$.\n\n\\subsection{Example (Row)}\n\n\\[\n    \\left[\\begin{array}{ll}\n        2 & 7 \\\\\n        3 & 8 \\\\\n        4 & 9\n        \\end{array}\\right]\\left[\\begin{array}{ll}\n        1 & 6 \\\\\n        0 & 0\n        \\end{array}\\right]=\\left[\\begin{array}{l}\n        2 \\\\\n        3 \\\\\n        4\n        \\end{array}\\right]\\left[\\begin{array}{ll}\n        1 & 6\n        \\end{array}\\right]+\\left[\\begin{array}{l}\n        7 \\\\\n        8 \\\\\n        9\n        \\end{array}\\right]\\left[\\begin{array}{ll}\n        0 & 0\n    \\end{array}\\right]\n\\]", "meta": {"hexsha": "0e362d6c8b8364d92cb84e373df227f19c4e4f0b", "size": 1970, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/2_multiplication.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "linear-algebra/tex/2_multiplication.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "linear-algebra/tex/2_multiplication.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.1348314607, "max_line_length": 118, "alphanum_fraction": 0.569035533, "num_tokens": 665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7290781740807606}}
{"text": "%!TEX root = index.tex\n\\section{Symmetry groups}\n\n\\epigraph{Mathematics is the art of giving the same name to different things.}{Henri Poincare}\n\n\n\n\n\n\\subsection{Multiplying permutations}\nLet $ [n]$ denote the set $ \\{1, 2, \\ldots, n \\} $. The \\textbf{symmetry group of $ n$ elements}, $ S_n$, is defined to be the set of all permutations of $ n$ elements. We think of the permutations as \\emph{functions} $ [n] \\rightarrow [n]$.  For example, the element $ \\sigma = (1 \\: 2 \\: 4 \\: 3)$ denotes the function $ \\sigma: [4] \\rightarrow [4]$ which sends $ \\sigma(1) = 1, \\sigma(2) = 2, \\sigma(3) = 4, \\sigma(4) = 3$,\n  \\begin{align*}\n    1 & \\mapsto 1 \\\\\n    2 & \\mapsto 2 \\\\\n    3 & \\mapsto 4 \\\\\n    4 & \\mapsto 3 \n  \\end{align*}\nThis simple change in perspective now allows us to \\textbf{multiply} two permutations, by simply composing the corresponding functions. For example, the element $ \\sigma = (1 \\: 2 \\: 4 \\: 3)$ and $ \\tau = (4 \\: 1 \\: 2 \\: 3)$ the \\emph{product} $ \\sigma \\cdot \\tau = (4 \\: 1 \\: 3 \\: 2)$ \n  \\begin{align*}\n    1 & \\mapsto^\\sigma 1  \\mapsto^\\tau 4 \\\\\n    2 & \\mapsto^\\sigma 2  \\mapsto^\\tau 1 \\\\\n    3 & \\mapsto^\\sigma 4  \\mapsto^\\tau 3 \\\\\n    4 & \\mapsto^\\sigma 3  \\mapsto^\\tau 2\n  \\end{align*}\nNote that this is like \\emph{applying} $ \\sigma$ to $ \\tau$.\n\n\\begin{questions}\n  \\item For $ e = (1 \\: 2), \\tau = (2 \\: 1) \\in S_2$ compute: $ e \\cdot e, e \\cdot \\tau, \\tau \\cdot e, \\tau \\cdot \\tau$\n\\end{questions}\n\n\\begin{questions}[resume]\n  \\item For $ \\sigma = (2 \\: 3 \\: 1), \\tau = (2 \\: 1 \\: 3) \\in S_3$ compute \n  \\begin{enumerate}\n    \\item $ \\sigma \\cdot \\sigma$, $ \\sigma \\cdot \\sigma \\cdot \\sigma$\n    \\item $ \\sigma \\cdot \\tau$, $ (\\sigma \\cdot \\tau) \\cdot (\\sigma \\cdot \\tau)$\n    \\item $ \\tau \\cdot \\sigma$\n    \\item Write all the elements of $ S_3$ in terms of $ \\sigma$ and $ \\tau$.\n  \\end{enumerate}\n  Because $\\sigma \\cdot \\tau \\neq \\tau \\cdot \\sigma$ we say that $ S_3$ is \\textbf{non-abelian}.\n\\end{questions}\n\n\n\n\n\n\\newpage\n\\subsection{Subgroups}\n\\begin{questions}[resume]\n  \\item Let $ e = (1 \\: 2 \\: 3 \\: \\cdots \\: n) \\in S_n$. Let $ \\sigma $ be any permutation in $ S_n$.\n  \\begin{enumerate}\n    \\item Compute $ e \\cdot \\sigma$ and $ \\sigma \\cdot e$.\n    \\item Find an element $ \\tau$ such that $ \\tau \\cdot \\sigma = e$ and $ \\sigma \\cdot \\tau = e$.\n  \\end{enumerate}\n  Hence $ e$ is called the (group) \\textbf{identity} in $ S_n$ and $ \\tau = \\sigma^{-1}$ is called the \\textbf{inverse} of $ \\sigma$.\n  \\begin{enumerate}[resume]\n    \\item Explicitly find the inverses of all the elements of $ S_3$.\n  \\end{enumerate}\n\\end{questions}\nA set with (associative)  multiplication, an identity, and inverses is called a \\textbf{group}.\n\nA subset $ G \\subseteq S_n$ which is itself a group is called a \\textbf{subgroup} of $ S_n$ i.e. $ G$ is a subgroup of $ S_n$ if \n\\begin{itemize}\n  \\item (contains identity) $ e \\in G$\n  \\item (closed under inverses) $ g \\in G \\implies g^{-1} \\in G$\n  \\item (closed under multiplication) $ g,h \\in G \\implies g \\cdot h \\in G$\n\\end{itemize}\n\n\\begin{questions}[resume]\n  \\item Show that $\\{e\\}$ is a subgroup of any $ S_n$. This is called the \\textbf{trivial group}.\n  \\item  Let $ \\sigma = (3 \\: 1 \\: 2), \\tau = (2 \\: 1 \\: 3) \\in S_3$.\n  \\begin{enumerate}\n    \\item Show that $\\{e, \\tau\\}$ is a subgroup of $ S_3$.\n    \\item What element(s) do you need to add to $ \\{ e, \\sigma\\}$ to make it a subgroup  of $ S_3$?\n    \\item What element(s) do you need to add to $ \\{ e, \\tau, \\sigma\\}$ to make it a subgroup of $ S_3$?\n  \\end{enumerate}\n  \\item List all the subgroups of $ S_3$.\n\n  \\item For $ \\sigma = (2 \\: 3 \\: \\cdots \\: n \\: 1) \\in S_n$,\n  \\begin{enumerate}\n    \\item Find $ \\sigma^k$.\n    \\item Find $ \\sigma^{-1}$.\n    \\item What are the elements that needs to be added to the set $ \\{ e , \\sigma \\} \\subseteq S_n$ to make it a subgroup?\n  \\end{enumerate}  \n\\end{questions}\n\n\n\n\n\n\\newpage\n\\subsection{Group Actions}\nGroups naturally occur as symmetries of mathematical objects, $ S_n$ is the symmetry group of a set of $ n$ elements. But the same group can show up as the symmetries of multiple objects. We think of the group as \\textbf{acting} on the object via some self-transformations. \\\\\n\nFor example, $ S_3$ \\emph{acts} an equilateral triangle with vertices labelled $ \\{ 1,2,3 \\}$ via geometrical transformations (rotations and reflections): $ \\sigma = (2 \\: 1 \\: 3)$ \\emph{acts} via rotating the triangle counterclockwise by $ 2\\pi/3$ and $ \\tau = (2 \\: 1 \\: 3)$ \\emph{acts} via reflecting along one of the bisectors. On the other hand $ S_3$ does not act naturally on, say, an isosceles triangle, in this case the natural symmetry group is $ S_2$ which acts by reflecting along \\emph{the} bisector. For a scalene triangle, the natural symmetry group is the trivial group.\n\n\\begin{questions}[resume]\n  \\item \\begin{enumerate}\n    \\item How many geometrical transformations are there of a square?\n    \\item $ S_4$ does not act naturally on a square. What is an example of an element of $ S_4$ which does not correspond to any geometrical transformation?\n    \\item What is the \\emph{subgroup} of $ S_4$ that acts via geometrical transformations?\n  \\end{enumerate}\n  \n  \\item Generalize the above problem to a regular $ n$-gon. These groups are called the \\textbf{dihedral groups}, denoted $ D_{2n}$. (why $ 2n$?)\n\n  \\item If we restrict only to rotations and do not allow reflections, then $ S_4$ does not naturally act on a tetrahedron.\n  \\begin{enumerate}\n    \\item What is an example of an element of $ S_4$ which does not correspond to any rotation of the tetrahedron?\n    \\item Describe how the other elements of $ S_4$ act on the tetrahedron.\n    \\item How many rotational symmetries does the tetrahedron have? What is the rotational symmetry group? \n  \\end{enumerate}\n\\end{questions}\n\nThe rotational symmetry group of a cube is also extremely interesting and easy to understand, try reading about it online.\n\n  \n", "meta": {"hexsha": "7b68e4a410cdb6432511b2c6630be07f70a2ea04", "size": 5905, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Symmetries.tex", "max_stars_repo_name": "apurvnakade/jhu2018-symmetries-and-polynomials", "max_stars_repo_head_hexsha": "1c3e17b80baddd2e5758110ecbc0b63a9e4ef9d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Symmetries.tex", "max_issues_repo_name": "apurvnakade/jhu2018-symmetries-and-polynomials", "max_issues_repo_head_hexsha": "1c3e17b80baddd2e5758110ecbc0b63a9e4ef9d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Symmetries.tex", "max_forks_repo_name": "apurvnakade/jhu2018-symmetries-and-polynomials", "max_forks_repo_head_hexsha": "1c3e17b80baddd2e5758110ecbc0b63a9e4ef9d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.9051724138, "max_line_length": 586, "alphanum_fraction": 0.6570702794, "num_tokens": 1953, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.729078170820901}}
{"text": "\n\\section*{Problem 4}\n\n\\begin{problem}\n\nThe following problem has two parts, writing the algorithm and then programming it.\n\\end{problem}\n\n\n\\begin{subpr}{\\hfill 10 pts.} Using the expression for the force between a charge and a metal sphere. First, write how one can compute the electrostatic force between two metal balls of radius $r_1$ and $r_2$, charged with charges $q_1$ and $q_2$ respectively, in free space, with the distance between their centres being $d$. (The actual computation may be tedious.)\n\nSay this force is $F$ Consider the following dimensionless quantities: \n$$f=\\frac{4 \\pi \\epsilon_0 d^2}{{q_1}^2}\\cdot F$$\n$$u=\\frac{r_1}{d}$$\n$$v=\\frac{r_2}{d}$$\n$$p=\\frac{q_1}{q_2}$$\nExpress all equations in the above procedure in terms of these dimensionless quantities.\n\nWrite a program in any language (Python, C, etc.) to compute $f$ given $u,v,p.$ The maximum uncertainty in $f$ from the calculation must not be more than $\\approx 1\\%$ for $p \\approx 1$ $u  \\approx v \\approx 0.5.$\n\\end{subpr}\n\\clearpage\n\n", "meta": {"hexsha": "24afe2fd5444153e6f9e1faa3a2bc3db046d6108", "size": 1021, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/Round-3/Problems/4.tex", "max_stars_repo_name": "GRAMOLY-ORG/FIZIKA", "max_stars_repo_head_hexsha": "b6f920b15ea598de3777f386aa80edbb49657af8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-04T07:21:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T07:21:50.000Z", "max_issues_repo_path": "tex/Round-3/Problems/4.tex", "max_issues_repo_name": "GRAMOLY-ORG/FIZIKA", "max_issues_repo_head_hexsha": "b6f920b15ea598de3777f386aa80edbb49657af8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/Round-3/Problems/4.tex", "max_forks_repo_name": "GRAMOLY-ORG/FIZIKA", "max_forks_repo_head_hexsha": "b6f920b15ea598de3777f386aa80edbb49657af8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.3913043478, "max_line_length": 367, "alphanum_fraction": 0.7286973555, "num_tokens": 305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.8499711832583696, "lm_q1q2_score": 0.7290781618883887}}
{"text": "%!TEX root = ../Thesis.tex\n\\chapter{Non-Dimensionalization of Hamilton's Equations} \\label{app:non-dimensionalization}\nWe set:\n\\begin{align}\nt &= k_t T \\\\\nx &= k_x X \\\\\ny &= k_y Y \\\\\np_x &= k_{px} P_X \\\\\np_y &= k_{py} P_Y ,\n\\end{align}\nwith\n\\begin{align}\nk_t &= \\dfrac{1}{\\omega} = \\sqrt{\\dfrac{(R+r)^3}{G(M+m)}} \\\\[0.5cm]\nk_x &= k_y = R+r \\\\[0.5cm]\nk_{px} &= k_{py} = m_s \\sqrt{\\dfrac{G(M+m)}{(R+r)}} .\n\\end{align}\n\nSo we get for $\\dot{X}$\n\\begin{align}\n\\dfrac{k_x}{k_t} \\dod{X}{T} &= \\dfrac{k_{px} P_X}{m_s} + \\omega k_y Y \\\\[0.3cm]\n\\Leftrightarrow \\qquad \\dod{X}{T} &= \\dfrac{k_t k_{px}}{k_x} \\dfrac{P_X}{m_s} + \\omega k_t \\dfrac{k_y}{k_x} Y \\\\[0.3cm]\n\\Leftrightarrow \\qquad \\dot{X} &= P_X + Y .\n\\end{align}\n\nAnd for $\\dot{Y}$ by symmetry\n\\begin{align}\n\\dot{Y} = P_Y - X \\ ,\n\\end{align}\n\nFor $\\dot{P}_X$ we get\n\\begin{align}\n\\dod{P_X}{T} &= \\dfrac{k_{py}}{k_{px}} k_t\\omega P_Y - \\dfrac{k_t}{k_{px}}G m_s \\left[\\dfrac{M(k_x X + R)}{\\left(k_x X + R)^2 + k_y^2 Y^2\\right)^{3/2}} + \\dfrac{m (k_x X - r)}{\\left((k_x X - r)^2 + k_y^2 Y^2\\right)^{3/2}} \\right].\n\\end{align}\n\nNow letting some of the $k$s cancel and expanding the rest of the $k$s, we get\n\\begin{align}\n\\notag &= P_Y - \\left(\\sqrt{\\dfrac{(R+r)^3}{G(M+m)}}\\right) \\left(\\dfrac{1}{m_s} \\sqrt{\\dfrac{(R+r)}{G(M+m)}}\\right) G m_s \\cdot \\\\\n&\\left[\\dfrac{M[(R+r) X + R]}{[((R+r) X + R)^2 + (R+r)^2 Y^2]^{3/2}} + \\dfrac{m[(R+r) X - r]}{[((R+r) X - r)^2 + (R+r)^2 Y^2]^{3/2}} \\right].\n\\end{align}\nFirst simplifying and pulling out $(R+r)$, then multiplying everything into the big parenthesis, we get:\n\\begin{align}\n\\notag &= P_Y - \\dfrac{(R+r)^2}{M+m} \\cdot \\\\ \n&\\left[\\dfrac{M(R+r)\\left(X + \\dfrac{R}{R+r}\\right)}{(R+r)^3\\left[\\left(X + \\dfrac{R}{R+r}\\right)^2 + Y^2\\right]^{3/2}} + \\dfrac{m (R+r)\\left(X - \\dfrac{r}{R+r}\\right)}{(R+r)^3\\left[\\left(X - \\dfrac{r}{R+r}\\right)^2 + Y^2\\right]^{3/2}} \\right] \\\\[1cm]\n&= P_Y - \\left[\\dfrac{\\dfrac{M}{M+m}\\left(X + \\dfrac{R}{R+r}\\right)}{\\left(\\left(X + \\dfrac{R}{R+r}\\right)^2 + Y^2\\right)^{3/2}} + \\dfrac{\\dfrac{m}{M+m} \\left(X - \\dfrac{r}{R+r}\\right)}{\\left(\\left(X - \\dfrac{r}{R+r}\\right)^2 + Y^2\\right)^{3/2}} \\right] ,\n\\end{align}\nwhere $\\dfrac{M}{M+m}$ and $\\dfrac{R}{R+r}$ are dimensionless parameters. There is a simple relation between the two given by the equation for the center of mass:\n\\begin{align}\nM\\vec{R} + m\\vec{r} &= \\vec{0} \\\\[0.5cm]\n\\Rightarrow \\qquad \\dfrac{m}{M+m} &= \\dfrac{R}{R+r} = k \\\\[0.5cm]\n\\Leftrightarrow \\qquad \\dfrac{M}{M+m} &= \\dfrac{r}{R+r} = 1-k  \n\\end{align}\nWith that in mind we finally get\n\\begin{align}\n\\dot{P}_X = P_Y - \\dfrac{(1-k)(X+k)}{((X+k)^2+Y^2)^{3/2}} - \\dfrac{k(X-1+k))}{((X-1+k))^2+Y^2)^{3/2}}\n\\end{align}\nby symmetry for $P_Y$ we get\n\\begin{align}\n\\dot{P}_Y = -P_X - \\dfrac{(1-k)Y}{((X+k)^2+Y^2)^{3/2}} - \\dfrac{k Y}{((X-1+k))^2+Y^2)^{3/2}}\n\\end{align}\n\nThe same procedure applies for $H$, which takes us from this:\n\\begin{align}\n    H = \\dfrac{p_x^2 + p_y^2}{2 m_s} + p_x\\omega y - p_y\\omega x - G m_s \\left(\\dfrac{M}{\\sqrt{(x+R)^2+y^2}} + \\dfrac{m}{\\sqrt{(x-r)^2+y^2}}\\right).\n\\end{align}\n\nto this:\n\n\\begin{align}\n    H = \\frac{P_X^2 + P_Y^2}{2} + Y P_X - X P_Y - \\frac{1 -k}{\\sqrt{(X+k)^2 + Y^2 }} - \\frac{k}{\\sqrt{(X-1+k))^2 + Y^2}}\n\\end{align}\n", "meta": {"hexsha": "93071dd9f1455ab2eb39b188a2c20c8b3f6a5202", "size": 3202, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/appendices/Non-Dimensionalization.tex", "max_stars_repo_name": "GandalfSaxe/leto", "max_stars_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/appendices/Non-Dimensionalization.tex", "max_issues_repo_name": "GandalfSaxe/leto", "max_issues_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/appendices/Non-Dimensionalization.tex", "max_forks_repo_name": "GandalfSaxe/leto", "max_forks_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.0985915493, "max_line_length": 255, "alphanum_fraction": 0.5718301062, "num_tokens": 1454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314624993576758, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.7290207582429495}}
{"text": "\\section{Factor Graph}\nOur SLAM is formulated as a bipartite factor graph with two types of nodes:\nthe variables (poses) which are elements of the set $\\Theta$, and the\nfactors, which constrain the variables via the set of measurements  $\\mathcal{Z}$. The\nfactor graph defines a probability $P(\\Theta|\\mathcal{Z})$ that\nassumes its maximum a posteriori (MAP) value for the optimal variable set\n$\\Theta^*$, given the measurements:\n\\begin{equation}\n\\Theta^* = \\argmax_\\Theta P(\\Theta|\\mathcal{Z})\\ .\n\\end{equation}\nThe set of variables $\\mathcal{Z}$ contains:\n\\begin{itemize}\n\\item The camera poses $\\ctrans{\\mathrm{body}(\\mathrm{cam}\\ j)}{T}{\\mathrm{cam}\\ j}$, with respect to the bodies they are attached to.\n\\item The tag poses $\\ctrans{\\mathrm{body}(\\mathrm{tag}\\ k)}{T}{\\mathrm{tag}\\ k}$,  relative to their respective bodies.\n\\item The world poses $\\ctrans{\\mathrm{w}}{T}{\\mathrm{body}\\ l}$, of static bodies.\n\\item The time-dependent world poses $\\ctrans{\\mathrm{w}}{T}{\\mathrm{body}\\ m}(t)$, $t = 1\\dots N_{\\mathrm{t}}$ of dynamic bodies.\n\\end{itemize}\nThe likelihood is expressed \\cite{kaess2011} as a product of factors $p^{(i)}$\nthat connects the variables with each other via measurements to form the desired graph structure:\n\\begin{equation}\n  \\label{eq:totalprob}\n  P(\\Theta|\\mathcal{Z}) = \\prod_ip^{(i)}(\\Theta|\\mathcal{Z})\\ .\n\\end{equation}\nTo make the factors $p^{(i)}$ computationally tractable, we follow the standard\napproach \\cite{kaess2011} and model them as Gaussians:\n\\begin{equation}\n  g(x;\\mu,\\Sigma) = \\exp(-\\frac{1}{2}||x\\ominus\\mu||_\\Sigma^2)\\ .\n\\end{equation}\nHere, $x$ is the variable, $\\mu$ the center of the Gaussian, and $\\Sigma$ defines the Mahalanobis distance.\nNote the use of the $\\ominus$ operator, which reduces to straight subtraction for elements of a vector space,\nbut produces 6-dimensional Lie algebra coordinates when applied to elements on the SE(3) manifold:\n\\begin{equation}\n  \\label{eq:ominus}\n  \\ctrans{}{T}{A} \\ominus \\ctrans{}{T}{B} =\n  \\left[[\\log(\\mathrm{Rot}(\\ctransi{}{T}{B}\\ctrans{}{T}{A}))]_\\vee^\\top,\\mathrm{Trans}(\\ctransi{}{T}{B}\\ctrans{}{T}{A})^\\top\\right]^\\top\\ .\n\\end{equation}\nIn (\\ref{eq:ominus}) Rot() and Trans() refer to the rotational and translational part of the SE(3) transform,\nrespectively, log() is the matrix logarithm, and $\\vee$ denotes the\n{\\em vee} map operator. Equipped with the definition of a Gaussian\non SE(3), we can now introduce the basic factors $p^{(i)}$ from Eq.\\ (\\ref{eq:totalprob}).\n\n{\\em Absolute Pose Prior}. This unary factor can be used to specify a prior pose\n$\\ctrans{}{T}{0}$ with noise $\\Sigma$ for e.g. a tag or a camera:\n\\begin{equation}\n  p_A(\\ctrans{}{T}{}|\\ctrans{}{T}{0},\\Sigma) = g(\\ctrans{}{T}{}; \\ctrans{}{T}{0}, \\Sigma)\\ .\n\\end{equation}\n\n{\\em Relative Pose Prior}. With this binary factor, a known transform $\\Delta \\ctrans{}{T}{}$\nbetween two pose variables can be specified, with noise $\\Sigma$:\n\\begin{equation}\n  p_R(\\ctrans{}{T}{A}, \\ctrans{}{T}{B}|\\Delta\\ctrans{}{T}{},\\Sigma) = g(\\ctransi{}{T}{B}\\ctrans{}{T}{A}; \\Delta\\ctrans{}{T}{}, \\Sigma)\\ .\n\\end{equation}\nIf odometry body pose differences $\\Delta \\ctrans{}{T}{\\mathrm{odom}}(t)$ with noise $\\sigma$\nare available from e.g. a VIO algorithm running\nalongside TagSLAM, a relative pose prior of\n$p_R(\\ctrans{\\mathrm{w}}{T}{\\mathrm{body}}(t),\n\\ctrans{\\mathrm{w}}{T}{\\mathrm{body}}(t-1)|\n\\Delta \\ctrans{}{T}{\\mathrm{odom}}(t),\\sigma)$ can be used to insert\nthe odometry updates into the pose graph.\n\n{\\em Tag Projection Factor}. The output of the tag detection\nlibrary is a list of tag IDs and the corresponding image\ncoordinates $\\mv{u}_c$ (in units of pixels) of the corners\n$c=1\\dots 4$ of every tag. This gives rise to one quaternary\ntag projection factor per tag:\n\\begin{equation}\n  \\begin{split}\n    p_T(\\ctrans{\\mathrm{w}}{T}{\\mathrm{body}},\n    \\ctrans{\\mathrm{rig}}{T}{\\mathrm{cam}},\n    \\ctrans{\\mathrm{body}}{T}{\\mathrm{tag}},\n    \\ctrans{\\mathrm{w}}{T}{\\mathrm{rig}}|\\{\\mv{u}_c\\},\\sigma_p) =\\\\\n    \\prod_{c=1\\dots 4}g(\\Pi(\\ctrans{\\mathrm{cam}}{T}{\\mathrm{rig}}\n    \\ctrans{\\mathrm{rig}}{T}{\\mathrm{w}}\n    \\ctrans{\\mathrm{w}}{T}{\\mathrm{body}}\n    \\ctrans{\\mathrm{body}}{T}{\\mathrm{tag}}\\mv{s}_c);\n    \\mv{u}_c,\\sigma_p)\\ .\n  \\end{split}\n\\end{equation}\nHere, $\\mv{s}$ refers to the corner coordinates in the tag reference frame,\ni.e. $\\mv{s}_1 = [-l/2, -l/2, 0]^\\top$,\n$\\mv{s}_2 = [l/2, -l/2, 0]^\\top$,\n$\\mv{s}_3 = [l/2,  l/2, 0]^\\top$,\n$\\mv{s}_4 = [-l/2, l/2, 0]^\\top$\nfor a tag of side length $l$. A sequence of transforms expresses $\\mv{s}$ in\ncamera coordinates, after which the function $\\Pi$ projects \\cite{ma2003} the point onto the\nsensor plane and converts it to pixel coordinates. The noise parameter $\\sigma_p$\nis a diagonal matrix that reflects the accuracy of the tag library's corner detector,\nwhich is usually assumed to be about one pixel.\n\nWe can visualize the factor structure of Eq.\\ (\\ref{eq:totalprob}) by means of\na graph as shown in Fig.\\ \\ref{fig:sample_graph} for the scene from\nFig.\\ \\ref{fig:scene_with_block}. In Fig.\\ \\ref{fig:sample_graph},\nblack squares represent factors, whereas circles denote pose variables\nto be optimized.\nThe prior factors $p_A$ constrain\nthe static poses  $\\ctrans{l}{T}{2}$, $\\ctrans{\\mathrm{w}}{T}{l}$,\n$\\ctrans{\\mathrm{r}}{T}{\\mathrm{c}}$, and\n$\\ctrans{\\mathrm{b}}{T}{105}$. A tag projection factors $p_T$ arising\nfrom an observation of Tag 2 determines the dynamic rig pose\n$\\ctrans{\\mathrm{w}}{T}{\\mathrm{r}}(t)$, whereas an observation of Tag\n105 likewise yields the block pose\n$\\ctrans{\\mathrm{w}}{T}{\\mathrm{b}}(t)$. Assuming that odometry for\nthe rig is provided by some external algorithm, there is a relative\npose factor $p_R$ connecting the rig poses for $t$ and $t+1$. Two more\ntag observations at $t+1$ generate additional factors that further constrain rig and block poses at $t+1$.\n\n\\begin{figure}[ht]\n  \\vspace{0.25cm}\n  \\newcommand{\\relfacgraphsize}{0.75}\n  \\begin{center}\n    \\begin{tabular}{cc}\n      \\resizebox{\\relfacgraphsize\\columnwidth}{!}{\n      \\input{sections/sample_graph.tex}\n      }\n    \\end{tabular}\n  \\end{center}\n  \\caption{Factor graph of Eq.\\ \\ref{eq:totalprob} for the scene shown in Fig.\\ \\ref{fig:scene_with_block}}\n  \\label{fig:sample_graph}\n\\end{figure}\n\n", "meta": {"hexsha": "9c1255f19d82738f473c7258402d8959b0f0d8e5", "size": 6233, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writeup/sections/factor_graph.tex", "max_stars_repo_name": "berndpfrommer/tagslam_web", "max_stars_repo_head_hexsha": "c7a7c80f8d6472cf57941bab66c83ac8a36e1510", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-10-21T12:26:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-26T09:06:36.000Z", "max_issues_repo_path": "writeup/sections/factor_graph.tex", "max_issues_repo_name": "berndpfrommer/tagslam_web", "max_issues_repo_head_hexsha": "c7a7c80f8d6472cf57941bab66c83ac8a36e1510", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "writeup/sections/factor_graph.tex", "max_forks_repo_name": "berndpfrommer/tagslam_web", "max_forks_repo_head_hexsha": "c7a7c80f8d6472cf57941bab66c83ac8a36e1510", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.5123966942, "max_line_length": 139, "alphanum_fraction": 0.6932456281, "num_tokens": 2017, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7290207515223948}}
{"text": "documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\subsection{Worksheet - Shortest Distance and Variational Principle}\n\\begin{p}\nWe wish to find the shortest path between two points $(x_1,y_1)$ and $(x_2,y_2)$ in the plane. First, write out the distance between these two points in terms of a general function $y(x)$ connecting points $(x_1,y_1)$ and $(x_2,y_2)$, and possibly it’s derivative $y'(x)$, in terms of an independent variable $x$.\n\\begin{center}\n    \\includegraphics[scale=0.6]{Lecture-1/W1-img1.png}\n\\end{center}\n\\end{p}\n\\begin{s}\nWe can define an infinitesimal path element of the trajectory from $(x_1, y_1)$ to $(x_2, y_2)$ as:\n\\[ ds = \\sqrt{dx^2 + dy^2}\\]\nWe can use the identity:\n\\[ dy \\equiv \\dod{y}{x}dx = y'(x)dx\\]\nSubstituting this into the path element equation above, we obtain:\n\\[ds = \\sqrt{dx^2 + \\left(y'(x)dx\\right)^2}\\]\nWe may integrate the path element from the initial state to the final state to obtain the length of the path:\n\\[L(y(x), y'(x)) = \\int_{t_1}^{t_2} ds = \\int_{x_1}^{x_2} \\sqrt{dx^2 + \\left(y'(x)dx\\right)^2} = \\int_{x_1}^{x_2} \\sqrt{1 + y'(x)^2}dx\\]\nNotice here we have the functional $L[y(x), y'(x)]$ (here only depends on $y'(x)$). \n\n\n\\end{s}\n\n\\begin{p}\nIf light were travelling between points $(x_1,y_1)$ and $(x_2,y_2)$, we would expect it to follow a straight line, but if the index of refraction $n = n(x,y)$ is not constant, the speed of light in the medium is $v = c/n$ and the path is not a straight line but follows the trajectory of minimum time (Fermat, 1662).Find an integral expression for the time taken by a trajectory $y(x)$ through a medium $n(x,y)$.\n\\end{p}\n\\begin{s}\nThe infinitesimal time element $dt$ to travel a distance $ds$ is given by:\n\\[dt = \\frac{ds}{v} = \\frac{n(x,y) ds}{c} = \\frac{1}{c} n(x,y)\\sqrt{1 + y'(x)^2}dx \\]\nWhere in the second inequality we use the identity $v = c/n$. Again we can integrate from an initial time to a final time to obtain the total time the light takes to travel along the path:\n\\[T = \\int_{t_1}^{t_2} dt = \\int_{x_1}^{x_2} \\frac{1}{c} n(x,y)\\sqrt{1 + y'(x)^2}dx = \\frac{1}{c}\\int_{x_1}^{x_2} n(x,y) \\sqrt{1+y'(x)^2}dx\\]\nWhere again we have a functional $T[y(x), y'(x)]$.\n\\end{s}\n\n\\begin{p}\nIn our variational treatment, if the “wrong” or “varied” curves from the minimum pass through the points 1 and 2, write the condition on the deviations from the correct curve, $\\eta(x)$.\n\\end{p}\n\\begin{s}\n$\\eta(x_1) = \\eta(x_2) = 0$ as the endpoints of the wrong path must match that of the correct path. \n\\end{s}\n\n\\begin{p}\nIf $S(\\alpha)=\\int_{x_{1}}^{x_{2}} f\\left(y+\\alpha \\eta, y^{\\prime}+\\alpha \\eta^{\\prime}, x\\right) d x,$ use the chain rule to write $d S(\\alpha) / d \\alpha$ in terms of an integral of a function that contains derivatives on $y$ and $y^{\\prime},$ and $\\eta$ and $\\eta^{\\prime}$.\n\\end{p}\n\\begin{s}\nAs the integral is with respect to x, we may interchange the order of integration and differentiation:\n\\[\\left. \\dod{S(\\alpha)}{\\alpha}\\right|_{\\alpha = 0} = \\left.\\dod{}{\\alpha}\\int_{x_{1}}^{x_{2}} f\\left(y+\\alpha \\eta, y^{\\prime}+\\alpha \\eta^{\\prime}, x\\right) dx\\right|_{\\alpha = 0} = \\int_{x_1}^{x_2} \\left(\\left.\\dpd{}{\\alpha}f\\left(y+\\alpha \\eta, y^{\\prime}+\\alpha \\eta^{\\prime}, x\\right)\\right|_{\\alpha = 0}\\right) dx \\]\nThen by the chain rule, we have:\n\\[\\left.\\dod{S(\\alpha)}{\\alpha}\\right|_{\\alpha = 0} = \\int_{x_{1}}^{x_{2}} \\left(\\eta\\dpd{f}{y} + \\eta'\\dpd{f}{y'}\\right)dx = \\int_{x_1}^{x_2} \\eta\\dpd{f}{y} dx + \\int_{x_1}^{x_2} \\eta'\\dpd{f}{y'}dx\\]\n\\end{s}\n\n\\begin{p}\nRewrite the $2^{\\text {nd }}$ term $\\int_{x 1}^{x 2} \\eta^{\\prime} \\frac{\\partial f}{\\partial y^{\\prime}} d x$ by integrating by parts. Note $\\int v d u=[u v]-\\int u d v$ is equivalent to $\\int u^{\\prime} v d x=[u v]-\\int u v^{\\prime} d x$. After simplifying, write the integral expression for $\\frac{\\partial S}{\\partial \\alpha}=0 .$ l.e. $\\frac{\\partial S}{\\partial \\alpha}= \\int_{x 1}^{x 2} \\eta(x)[\\ldots] d x=0 .$ This condition ensures that $S(\\alpha)$ has a minimum at $\\alpha=0$ and $y$ is the curve that extremizes S.\n\\end{p}\n\\begin{s}\nCarrying out integration by parts on the second term, we have:\n\\[\\left. \\dod{S(\\alpha)}{\\alpha}\\right|_{\\alpha = 0} = \\int_{x_1}^{x_2} \\eta \\dpd{f}{y} dx + \\left. \\eta\\dpd{f}{y'}\\right|_{x_1}^{x_2} - \\int_{x_1}^{x_2}\\eta\\left(\\dod{}{x}\\dpd{f}{y'}\\right)dx \\]\nFrom problem 3, we know that $\\eta(x_1) = \\eta(x_2) = 0$ and so the second term evaluates to zero, leaving us with:\n\\[\\left. \\dod{S(\\alpha)}{\\alpha}\\right|_{\\alpha = 0} = \\int_{x_1}^{x_2} \\left(\\eta\\dpd{f}{y} - \\eta\\dod{}{x}\\dpd{f}{y'}\\right)dx\\]\nand we set this to zero:\n\\[\\left. \\dod{S(\\alpha)}{\\alpha}\\right|_{\\alpha = 0} = \\int_{x_1}^{x_2}\\eta\\left(\\dpd{f}{y} - \\dod{}{x}\\dpd{f}{y'}\\right)dx = 0\\]\nWe require that this holds for \\textbf{all} possible deviations $\\eta(x)$. The only way this could hold is if the term in brackets is zero; this is exactly the Euler-Lagrange equation!\n\\end{s}\n\n\\begin{p}\nWrite the general form of the Euler-Lagrange Equation. What is the function $f$ for the distance between two points? What does this say about $\\pd{f}{y}$ in the E-L equation?\n\\end{p}\n\\begin{s}\nThe general form of the Euler-Lagrange equation is given by:\n\\[\\dpd{f}{y}  - \\dod{}{x}\\dpd{f}{y'} = 0\\]\nThe function for the distance between two points is $f = \\sqrt{1+ y'^2}$ as derived above. Hence, $\\dpd{f}{y} = 0$, and therefore by the Euler Lagrange equation:\n\\[\\dpd{f}{y'} = \\text{constant}\\]\n\\end{s}\n\n\\begin{p}\nSolve the above equation for $y'^2$ and hence $y'$ and $y$.\n\\end{p}\n\\begin{s}\nWe have that:\n\\[\\dpd{f}{y'} = \\frac{y'}{\\sqrt{1+y'^2}} = \\text{Constant}\\]\nTherefore:\n\\[y'^2 = c^2(1+y'^2)\\]\nOr alternatively:\n\\[y'^2 = \\frac{c^2}{1-c^2} = c' \\implies y'(x) = \\sqrt{c'} = m\\]\nSo integrating, we have that:\n\\[y(x) = mx + b\\]\nas we knew already!\n\\end{s}\n\\end{document}", "meta": {"hexsha": "ea3fe0e8a765e375fb601e853de859c027f62980", "size": 5793, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-1/Worksheet-1.tex", "max_stars_repo_name": "RioWeil/PHYS306-notes", "max_stars_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture-1/Worksheet-1.tex", "max_issues_repo_name": "RioWeil/PHYS306-notes", "max_issues_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture-1/Worksheet-1.tex", "max_forks_repo_name": "RioWeil/PHYS306-notes", "max_forks_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.3666666667, "max_line_length": 526, "alphanum_fraction": 0.6514759192, "num_tokens": 2148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.728967156181929}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% formulation.tex\n% Formulation to allocation tech report in master.tex\n% This section: David Albrecht\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Formulation}\n\\label{sec:form}\n\nIn this section we show how our allocation problem can be formulated\nas a Convex Programming problem. To do this we will need to make the\nfollowing assumptions:\n\\begin{enumerate}\n\\item The object we are searching for is stationary during the time of\nthe search.\n\\item The probability of detecting the object in a given area is\nproportional to the time searching, $\\delta t$, when $\\delta t$ is\nsmall.\n\\item The probability of detecting the object in a given region for a\ngiven resource is independent of the probability of detecting the\nobject in that region with any other resource.\n\\item The probability of detecting the object at time $t=0$ is zero.\n\\end{enumerate}\n\nLet $D_{a,r}(t)$ be the probability of detecting the object in an area\n$a$ using a resource $r$ by time $t$. Then, by (2), for small $\\delta\nt$ we have:\n$$D_{a,r}(t + \\delta t) = D_{a,r}(t) + w_{a,r}\\delta t(1-D_{a,r}(t)),$$\nwhere $w_{a,r}$ is a measure of the effectiveness of resource $r$ in\narea $a$. Letting $\\delta t\\to 0$, we obtain\n$$D_{a,r}^\\prime(t) = w_{a,r}(1-D_{a,r}(t)),\\quad\\mbox{ and by (4) }\\quad \nD_{a,r}(0) = 0.$$ \nSolving this equation we find:\n$$D_{a,r}(t) = 1-\\exp(-w_{a,r}t), \\quad t\\ge 0.$$\n\nNow, let $\\bar{D}$ be the probability of \\emph{not} detecting the\nobject, $p_a$ the probability the object is in area $a$, $T_r$ the\ntotal amount of time available for searching with resource $r$, and\n$t_{a,r}$ the time spent searching in area $a$ with resource $r$. Then\nby (3),\n\\begin{eqnarray*}\n\\bar{D} &=& \\sum_{a = 1}^A p_a\\prod_{r = 1}^R \\bar{D}_{a,r}(t_{a,r})\\\\\n&=& \\sum_{a = 1}^A p_a \\exp\\left(-\\sum_{r = 1}^R w_{a,r}t_{a,r}\\right), \n\\end{eqnarray*}\nwhere \n$$\n\\sum_{a = 1}^A t_{a,r} \\le T_r, \\qquad r = 1,\\ldots,R.\n$$\n\\newpage\n\nTherefore, since the problem of maximize the probability of detection\nis the same as the problem of minimizing the probability of \\emph{not}\ndetecting we obtain the following Convex Programming {\\bf (CP)} problem\n\n$$\n\\min_{t_{a,r}\\ge 0}\\quad \\sum_{a = 1}^A p_a \\exp\\left(-\\sum_{r = 1}^R\nw_{a,r}t_{a,r}\\right),\n$$\nsuch that\n$$\n\\sum_{a = 1}^A t_{a,r} \\le T_r, \\qquad r = 1,\\ldots,R.\n$$\n\nThe following theorem from Nonlinear Programming gives conditions for \nsolving this problem.\n\n\\begin{theorem} Suppose $f$, $g_1\\ldots,g_m$ are differentiable convex\nfunctions on ${\\cal R}^n$, and there exists $x^*$ and $\\lambda^{*}$\nwhich satisfy:\n\\begin{eqnarray}\n\\frac{\\partial f}{\\partial x_i}(x^{*}) + \\sum_{j=1}^m \\lambda^*_j\\frac{\\partial\ng_j}{\\partial x_i}(x^{*}) &=& 0, \\\\\n\\lambda^{*}_j g_j(x^{*}) &=& 0, \\\\\ng_j(x^{*}) &\\le& 0, \\\\\n\\lambda^{*}_j &\\ge& 0, \n\\end{eqnarray}\nwhere $i = 1,\\ldots, n$ and $j = 1,\\ldots, m$. Then $x^{*}$ is a solution of\n$$\n\\min_{x} f(x)\\qquad\\mbox{s.t.}\\qquad g_j(x)\\le 0,\\quad j=1,\\ldots,m.\n$$\n\n\\end{theorem}\n\nThe conditions (1) - (4) in the above theorem are known as the Karush\nKuhn Tucker (KKT) conditions and for the {\\bf CP} problem these conditions\nare as follows:\n\\begin{eqnarray}\n-p_aw_{a,r}\\exp(-\\sum_{r=1}^R w_{a,r}t_{a,r}) + \\beta_r - \\alpha_{a,r} &=& 0\\\\\n\\beta_r(\\sum_{a = 1}^A t_{a,r} - T_r) &=& 0\\\\\n\\sum_{a = 1}^A t_{a,r} &\\le& T_r\\\\\n\\alpha_{a,r}t_{a,r} &=& 0, \\\\\n\\alpha_{a,r} \\ge 0, \\qquad t_{a,r} \\ge 0, \\qquad \\beta_r &\\ge& 0,\n\\end{eqnarray}\nwhere $a = 1,\\ldots,A$ and $r =1,\\ldots,R$.\n\nTherefore, $\\{t_{a,r}\\}$ is a solution of the problem {\\bf CP} if\nthere exists $\\{t_{a,r}, \\beta_r, \\alpha_{a,r}\\}$ which satisfy\nconditions (5) - (9).\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"master\"\n%%% End: \n", "meta": {"hexsha": "58feb6f60582ea6889d0a570de77faf6f031aace", "size": 3732, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SORAL/Documentation/Latex/formulation.tex", "max_stars_repo_name": "tvrusso/soral", "max_stars_repo_head_hexsha": "bc4a27e4330458934d3224e8bdaf4cfcb189752b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SORAL/Documentation/Latex/formulation.tex", "max_issues_repo_name": "tvrusso/soral", "max_issues_repo_head_hexsha": "bc4a27e4330458934d3224e8bdaf4cfcb189752b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SORAL/Documentation/Latex/formulation.tex", "max_forks_repo_name": "tvrusso/soral", "max_forks_repo_head_hexsha": "bc4a27e4330458934d3224e8bdaf4cfcb189752b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.8846153846, "max_line_length": 79, "alphanum_fraction": 0.6355841372, "num_tokens": 1336, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961506, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7289671526249472}}
{"text": "\n\\chapter{Basics and foundations}\n\\section{Complex numbers}\n\\subsection{Operations}\n\n\\begin{gather}\n\\frac{z_1}{z_2}\n= \\frac{z_1\\overline z_2}{z_2\\overline z_2}\n= \\frac{z_1\\overline z_2}{|z_2|^2},\\\\\n\\frac{1}{z} = \\frac{\\overline z}{z\\overline z}\n= \\frac{\\overline z}{|z|^2}.\n\\end{gather}\n\n\\subsection{Absolut value}\nFor all $z_1,z_2\\in\\mathbb C$:\n\\begin{gather}\n|z_1z_2| = |z_1|\\,|z_2|,\\\\\nz_2\\ne 0\\implies \\Big|\\frac{z_1}{z_2}\\Big|\n= \\frac{|z_1|}{|z_2|},\\\\\nz\\,\\overline z = |z|^2.\n\\end{gather}\n\n\\subsection{Conjugation}\nFor all $z_1,z_2\\in\\mathbb C$:\n\\begin{gather}\n\\overline{z_1+z_2} = \\overline z_1+\\overline z_2,\\qquad\n\\overline{z_1-z_2} = \\overline z_1-\\overline z_2,\\\\\n\\overline{z_1 z_2} = \\overline z_1\\,\\overline z_2,\\qquad\nz_2\\ne 0 \\implies \\overline{\\Big(\\frac{z_1}{z_2}\\Big)}\n= \\frac{\\overline z_1}{\\overline z_2},\\\\\n\\overline{\\overline z}=z,\\qquad\n|\\overline{z}| = |z|,\\qquad\nz\\,\\overline z = |z|^2,\\\\\n\\operatorname{Re}(z) = \\frac{z+\\overline z}{2},\\qquad\n\\operatorname{Im}(z) = \\frac{z-\\overline z}{2\\ui},\\\\\n\\overline{\\cos(z)} = \\cos(\\overline z),\\qquad\n\\overline{\\sin(z)} = \\sin(\\overline z),\\\\\n\\overline{\\exp(z)} = \\exp(\\overline z).\n\\end{gather}\n\n\\begin{table*}[t]\n\\caption{Operations}\n\\bgroup\n\\def\\arraystretch{1.4}\n\\begin{tabular}{|l|r|l|l|}\n\\hline\n  \\thbf{Name}\n& \\thbf{Operation}\n& \\thbf{Polar form}\n& \\thbf{Cartesian form}\\\\\n\\hline\n  Identity\n& $z$ & $=r\\ee^{\\ui\\varphi}$\n& $= a+b\\ui$\\\\\n\\hline\n  Addition\n& $z_1+z_2$ &\n& $= (a_1+a_2)+(b_1+b_2)\\ui$\\\\\n\\hline\n  Subtraction\n& $z_1-z_2$ &\n& $= (a_1-a_2)+(b_1-b_2)\\ui$\\\\\n\\hline\n  Multiplication\n& $z_1 z_2$\n& $= r_1 r_2 \\ee^{\\ui(\\varphi_1+\\varphi_2)}$\n& $= (a_1 a_2 - b_1 b_2)+(a_1 b_2+a_2 b_1)\\ui$\\\\\n\\hline\n  Division\n& $\\displaystyle\\frac{z_1}{z_2}$\n& $\\displaystyle =\\frac{r_1}{r_2}\\ee^{\\ui(\\varphi_1-\\varphi_2)}$\n& $\\displaystyle =\\frac{a_1 a_2 + b_1 b_2}{a_2^2+b_2^2}\n   + \\frac{a_2 b_1 - a_1 b_2}{a_2^2+b_2^2}\\ui$\\\\\n\\hline\n  Reciprocal\n& $\\displaystyle\\frac{1}{z}$\n& $\\displaystyle =\\frac{1}{r}\\ee^{-\\ui\\varphi}$\n& $\\displaystyle =\\frac{a}{a^2+b^2}-\\frac{b}{a^2+b^2}\\ui$\\\\\n\\hline\n  Real part\n& $\\operatorname{Re}(z)$\n& $=\\cos\\varphi$\n& $=a$\\\\\n\\hline\n  Imaginary part\n& $\\operatorname{Im}(z)$\n& $=\\sin\\varphi$\n& $=b$\\\\\n\\hline\n  Conjugation\n& $\\overline{z}$\n& $=r\\ee^{-\\varphi\\ui}$\n& $=a-b\\ui$\\\\\n\\hline\n  Absolut value\n& $|z|$\n& $=r$\n& $=\\sqrt{a^2+b^2}$\\\\\n\\hline\n  Argument\n& $\\arg(z)$\n& $=\\varphi$\n& $\\displaystyle =s(b)\\arccos\\Big(\\frac{a}{r}\\Big)$\\\\\n\\hline\n\\end{tabular}\n\\egroup\\\\\n\\\\\n$s(b):=\\begin{cases}\n+1 & \\text{if}\\;b\\ge 0,\\\\\n-1 & \\text{if}\\;b<0\n\\end{cases}$\n\\end{table*}\n\n\n\n\\section{Logic}\n\\subsection{Propositional logic}\n\\subsubsection{Boolean algebra}\n\\begin{table*}[t]\n\\caption{Boolean algebra}\n\\begin{tabular}{l|l|l}\n\\thbf{Disjunction} & \\thbf{Conjunction} &\\\\\n  $A\\lor A \\Leftrightarrow A$\n& $A\\land A \\Leftrightarrow A$\n& Laws of idempotence\\\\\n  $A\\lor 0 \\Leftrightarrow A$\n& $A\\land 1 \\Leftrightarrow A$\n& Laws of neutrality\\\\\n  $A\\lor 1 \\Leftrightarrow 1$\n& $A\\land 0 = 0$\n& Laws of annihilation\\\\\n  $A\\lor \\overline A \\Leftrightarrow 1$\n& $A\\land \\overline A \\Leftrightarrow 0$\n& Laws of complementation\\\\\n\\noalign{\\vspace{1em}}\n  $A\\lor B \\Leftrightarrow B\\lor A$\n& $A\\land B \\Leftrightarrow B\\land A$\n& Laws of commutativity\\\\\n  $(A\\lor B)\\lor C \\Leftrightarrow A\\lor (B\\lor C)$\n& $(A\\land B)\\land C \\Leftrightarrow A\\land (B\\land C)$\n& Laws of associativity\\\\\n  $\\overline{A\\lor B} \\Leftrightarrow \\overline A\\land\\overline B$\n& $\\overline{A\\land B} \\Leftrightarrow \\overline A\\lor\\overline B$\n& De Morgan's laws\\\\\n  $A\\lor (A\\land B) \\Leftrightarrow A$\n& $A\\land (A\\lor B) \\Leftrightarrow A$\n& Laws of absorption\\\\\n\\end{tabular}\n\\end{table*}\n\n\\noindent\n\\strong{Laws of distributivity}:\n\\begin{gather}\nA\\lor (B\\land C) = (A\\lor B)\\land (A\\lor C),\\\\\nA\\land (B\\lor C) = (A\\land B)\\lor (A\\land C).\n\\end{gather}\n\n\\subsubsection{Functions in two arguments}\nThere are 16 boolean functions in two arguments.\n\n\\begin{tabular}{r|l}\n\\textbf{\\texttt{AB}} & \\thbf{value}\\\\\n\\texttt{00} & \\texttt{a}\\\\\n\\texttt{01} & \\texttt{b}\\\\\n\\texttt{10} & \\texttt{c}\\\\\n\\texttt{11} & \\texttt{d}\n\\end{tabular}\n\n\\begin{tabular}{r|l|l|l}\n\\thbf{No.}& \\textbf{\\texttt{dcba}} & \\thbf{Function} & \\thbf{Name}\\\\\n 0 & \\texttt{0000} & 0 & Contradiction\\\\\n 1 & \\texttt{0001} & $\\overline{A\\lor B}$ & NOR\\\\\n 2 & \\texttt{0010} & $\\overline{B\\Rightarrow A}$\\\\\n 3 & \\texttt{0011} & $\\overline A$\\\\\n 4 & \\texttt{0100} & $\\overline{A\\Rightarrow B}$\\\\\n 5 & \\texttt{0101} & $\\overline{B}$\\\\\n 6 & \\texttt{0110} & $A\\oplus B$ & Contravalence\\\\\n 7 & \\texttt{0111} & $\\overline{A\\land B}$ & NAND\\\\\n 8 & \\texttt{1000} & $A\\land B$ & Conjunction\\\\\n 9 & \\texttt{1001} & $A\\Leftrightarrow B$ & Equivalence\\\\\n10 & \\texttt{1010} & $B$ & Projection\\\\\n11 & \\texttt{1011} & $A\\Rightarrow B$ & Implication\\\\\n12 & \\texttt{1100} & $A$ & Projection\\\\\n13 & \\texttt{1101} & $B\\Rightarrow A$ & Implication\\\\\n14 & \\texttt{1110} & $A\\lor B$ & Disjunction\\\\\n15 & \\texttt{1111} & $1$ & Tautology\n\\end{tabular}\n\n\\subsection{Predicate logic}\n\\subsubsection{Basic laws}\nNegation (De Morgan's laws):\n\\begin{gather}\n\\overline{\\forall x[P(x)]}\\iff \\exists x[\\overline{P(x)}],\\\\\n\\overline{\\exists x[P(x)]}\\iff \\forall x[\\overline{P(x)}].\n\\end{gather}\nGeneralized laws of distributivity:\n\\begin{gather}\nP\\lor\\forall x[Q(x)] \\iff \\forall x[P\\lor Q(x)],\\\\\nP\\land\\exists x[Q(x)] \\iff \\exists x[P\\land Q(x)].\n\\end{gather}\nGeneralized laws of idempotence:\n\\begin{gather}\n\\begin{split}\n\\exists x{\\in}M\\,[P] & \\iff\n(M\\ne\\{\\})\\land P\\\\\n& \\iff\\begin{cases}\nP & \\text{if}\\; M\\ne\\{\\},\\\\\n0 & \\text{if}\\; M=\\{\\}.\n\\end{cases}\n\\end{split}\\\\\n\\begin{split}\n\\forall x{\\in}M\\,[P]& \\iff\n(M=\\{\\})\\lor P\\\\\n&\\iff\\begin{cases}\nP & \\text{if}\\; M\\ne\\{\\},\\\\\n1 & \\text{if}\\; M=\\{\\}.\n\\end{cases}\n\\end{split}\n\\end{gather}\nEquivalences:\n\\begin{gather}\n\\hspace{-2em}\\forall x\\forall y[P(x,y)] \\iff \\forall y\\forall x[P(x,y)],\\\\\n\\hspace{-2em}\\exists x\\exists y[P(x,y)] \\iff \\exists y\\exists x[P(x,y)],\\\\\n\\hspace{-2em}\\forall x[P(x)\\land Q(x)] \\iff \\forall x[P(x)]\\land\\forall x[Q(x)],\\\\\n\\hspace{-2em}\\exists x[P(x)\\lor Q(x)] \\iff \\forall x[P(x)]\\lor\\forall x[Q(x)],\\\\\n\\hspace{-2em}\\forall x[P(x)\\Rightarrow Q] \\iff \\exists x[P(x)]\\Rightarrow Q,\\\\\n\\hspace{-2em}\\forall x[P\\Rightarrow Q(x)] \\iff P\\Rightarrow\\forall x[Q(x)],\\\\\n\\hspace{-2em}\\exists x[P(x)\\Rightarrow Q(x)]\n  \\iff\\forall x[P(x)]\\Rightarrow\\exists x[Q(x)].\n\\end{gather}\nImplications:\n\\begin{gather}\n\\hspace{-2em}\\exists x\\forall y[P(x,y)]\\implies \\forall y\\exists x[P(x,y)],\\\\\n\\hspace{-2em}\\forall x[P(x)]\\lor\\forall x[Q(x)]\\implies\\forall x[P(x)\\lor Q(x)],\\\\\n\\hspace{-2em}\\exists x[P(x)\\land Q(x)]\\implies\n  \\exists x[P(x)]\\land \\exists x[Q(x)],\\\\\n\\hspace{-2em}\\forall x[P(x)\\Rightarrow Q(x)]\\implies\n  (\\forall x[P(x)]\\Rightarrow\\forall x[Q(x)]),\\\\\n\\hspace{-2em}\\forall x[P(x)\\Leftrightarrow Q(x)]\\implies\n  (\\forall x[P(x)]\\Leftrightarrow\\forall x[Q(x)]).\n\\end{gather}\n\n\\subsubsection{Finite sets}\nLet $M=\\{x_1,\\ldots,x_n\\}$. One has:\n\\begin{gather}\n\\forall x{\\in}M\\,[P(x)]\\iff P(x_1)\\land\\ldots\\land P(x_n),\\\\\n\\exists x{\\in}M\\,[P(x)]\\iff P(x_1)\\lor\\ldots\\lor P(x_n).\n\\end{gather}\n\n\\subsubsection{Restricted quantification}\n\\begin{gather}\n\\begin{split}\n& \\forall x{\\in}M\\,[P(x)]\\;:\\Longleftrightarrow\\;\\forall x[x\\notin M\\lor P(x)]\\\\\n& \\quad\\iff\\forall x[x\\in M\\Rightarrow P(x)],\n\\end{split}\\\\\n\\exists x{\\in}M\\,[P(x)]\\;:\\Longleftrightarrow\\;\\exists x[x\\in M\\land P(x)],\\\\\n\\forall x{\\in}M{\\setminus}N\\,[P(x)]\\iff \\forall x[x\\notin N\\Rightarrow P(x)].\n\\end{gather}\n\n\\subsubsection{Product sets as\\\\\ndomains of discourse}\n\\begin{gather}\n\\forall(x,y)\\,[P(x,y)]\\iff \\forall x\\forall y[P(x,y)],\\\\\n\\exists(x,y)\\,[P(x,y)]\\iff \\exists x\\exists y[P(x,y)].\n\\end{gather}\nBy analogy:\n\\begin{gather}\n\\forall(x,y,z)\\,\\iff \\forall x\\forall y\\forall z,\\\\\n\\exists(x,y,z)\\,\\iff \\exists x\\exists y\\exists z\n\\end{gather}\netc.\n\n\\subsubsection{Alternative representation}\nLet $P\\colon G\\to\\{0,1\\}$ and $M\\subseteq G$.\nLet $P(M)$ be the image of $M$ under $P$. One has\n\\begin{equation}\n\\begin{split}\n&\\forall x{\\in}M\\,[P(x)] \\iff P(M)=\\{1\\}\\\\\n& \\iff M\\subseteq\\{x{\\in}G\\mid P(x)\\}\n\\end{split}\n\\end{equation}\nand\n\\begin{equation}\n\\begin{split}\n& \\exists x{\\in}M\\,[P(x)] \\iff \\{1\\}\\subseteq P(M)\\\\\n& \\iff M\\cap\\{x{\\in}G\\mid P(x)\\}\\ne\\{\\}.\n\\end{split}\n\\end{equation}\n\n\\subsubsection{Uniqueness}\nQuantifier of unique existence:\n\\begin{equation}\n\\begin{split}\n&\\exists!x\\,[P(x)]\\\\\n&:\\Longleftrightarrow\\; \\exists x\\,[P(x)\\land \\forall y\\,[P(y)\\Rightarrow x=y]]\\\\\n&\\iff \\exists x\\,[P(x)]\\land \\forall x\\forall y[P(x)\\land P(y)\\Rightarrow x=y].\n\\end{split}\n\\end{equation}\n\n\n\n\\section{Set theory}\n\\subsection{Definitions}\nSubset relation:\n\\begin{equation}\nA\\subseteq B\\;:\\Longleftrightarrow\\; \\forall x\\,[x\\in A\\implies x\\in B].\n\\end{equation}\nEquality:\n\\begin{equation}\nA=B\\;:\\Longleftrightarrow\\; \\forall x\\,[x\\in A\\iff x\\in B].\n\\end{equation}\nUnion:\n\\begin{equation}\nA\\cup B:=\\{x\\mid x\\in A\\lor x\\in B\\}.\n\\end{equation}\nIntersection:\n\\begin{equation}\nA\\cap B:=\\{x\\mid x\\in A\\land x\\in B\\}.\n\\end{equation}\nDifference set:\n\\begin{equation}\nA\\setminus B:=\\{x\\mid x\\in A\\land x\\not\\in B\\}.\n\\end{equation}\nSymmetric difference:\n\\begin{equation}\nA\\triangle B:=\\{x\\mid x\\in A\\oplus x\\in B\\}.\n\\end{equation}\n\n\\subsection{Boolean algebra}\n\\begin{table*}[t]\n\\caption{Boolean algebra}\n\\begin{tabular}{l|l|l}\n\\thbf{Union} & \\thbf{Intersection} &\\\\\n  $A\\cup A = A$\n& $A\\cap A = A$\n& Laws of idempotence\\\\\n  $A\\cup \\{\\} = A$\n& $A\\cap G = A$\n& Laws of neutrality\\\\\n  $A\\cup G = G$\n& $A\\cap \\{\\} = \\{\\}$\n& Laws of annihilation\\\\\n  $A\\cup \\overline A = G$\n& $A\\cap \\overline A = \\{\\}$\n& Laws of complementation\\\\\n\\noalign{\\vspace{1em}}\n  $A\\cup B = B\\cup A$\n& $A\\cap B = B\\cap A$\n& Laws of commutativity\\\\\n  $(A\\cup B)\\cup C = A\\cup (B\\cup C)$\n& $(A\\cap B)\\cap C = A\\cap (B\\cap C)$\n& Laws of associativity\\\\\n  $\\overline{A\\cup B} = \\overline A\\cap\\overline B$\n& $\\overline{A\\cap B} = \\overline A\\cup\\overline B$\n& De Morgan's laws\\\\\n  $A\\cup (A\\cap B) = A$\n& $A\\cap (A\\cup B) = A$\n& Laws of absorption\\\\\n\\end{tabular}\\\\\n\\\\\n$G$: Universe\n\\end{table*}\n\n\\noindent\n\\strong{Laws of distributivity}:\n\\begin{gather}\nM\\cup (A\\cap B) = (M\\cup A)\\cap (M\\cup B),\\\\\nM\\cap (A\\cup B) = (M\\cap A)\\cup (M\\cap B).\n\\end{gather}\n\n\\subsection{Subset relation}\nDecomposition of equality:\n\\begin{equation}\nA=B \\iff A\\subseteq B \\land B\\subseteq A.\n\\end{equation}\nPharaphrasing of subset relations:\n\\begin{equation}\n\\begin{split}\nA\\subseteq B &\\iff A\\cap B=A\\\\\n& \\iff A\\cup B=B\\\\\n& \\iff A\\setminus B=\\{\\}.\n\\end{split}\n\\end{equation}\nLaw of contraposition:\n\\begin{equation}\nA\\subseteq B = \\overline B\\subseteq \\overline A.\n\\end{equation}\n\n\\subsection{Inductive sets}\nSet theoretical model of the natural numbers:\n\\begin{equation}\n\\begin{split}\n& 0:=\\{\\},\\quad 1:=\\{0\\},\\quad 2:=\\{0,1\\},\\\\\n& 3:=\\{0,1,2\\},\\quad \\text{usw.}\n\\end{split}\n\\end{equation}\nSuccessor function:\n\\begin{equation}\nx' := x\\cup\\{x\\}.\n\\end{equation}\nProof by induction: For a predicate $A(n)$ with $n\\in\\mathbb N$\none has:\n\\begin{equation}\n\\begin{split}\n& A(n_0)\\land \\forall n\\ge n_0\\,[A(n)\\Rightarrow A(n+1)]\\\\\n& \\implies \\forall n\\ge n_0\\,[A(n)].\n\\end{split}\n\\end{equation}\n\n", "meta": {"hexsha": "773f7acb46701ede8a193562de5cd620ba8c5b10", "size": 11020, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematics/HM/Basics-foundations.tex", "max_stars_repo_name": "JohnBSmith/JohnBSmith.github.io", "max_stars_repo_head_hexsha": "5bb0fac7ec4d653be6bd71b4c7ab344c9615f1eb", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-15T05:45:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-15T05:45:25.000Z", "max_issues_repo_path": "Mathematics/HM/Basics-foundations.tex", "max_issues_repo_name": "JohnBSmith/JohnBSmith.github.io", "max_issues_repo_head_hexsha": "5bb0fac7ec4d653be6bd71b4c7ab344c9615f1eb", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mathematics/HM/Basics-foundations.tex", "max_forks_repo_name": "JohnBSmith/JohnBSmith.github.io", "max_forks_repo_head_hexsha": "5bb0fac7ec4d653be6bd71b4c7ab344c9615f1eb", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.8780487805, "max_line_length": 82, "alphanum_fraction": 0.6359346642, "num_tokens": 4668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637541053281, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7289671498302488}}
{"text": "% !TEX root = index.tex\n\n\n\\section{Final Remarks}\n\n\n\\setlength{\\epigraphwidth}{0.6\\textwidth}\n\\epigraph{\\it Don't just read it; fight it!\\\\\nAsk your own questions, look for your own examples, discover your own proofs. Is the hypothesis necessary? Is the converse true? What happens in the classical special case? What about the degenerate cases? Where does the proof use the hypothesis? }{Paul Halmos}\n\nOn the last day, we will just tie up some loose ends.\n\n\\subsection{Rank-Nullity theorem}\nThe following is first of the many simple and yet remarkably useful theorems in linear algebra.\n\\begin{theorem}[Rank-Nullity theorem]\n  \\label{theorem:rankNullityTheorem}\n  Let $A$ be a matrix of size $\\ell \\times k$ so that $A$ defines a linear transformation $A: \\bbr^k \\rightarrow \\bbr^\\ell $. Then,\n  \\begin{align*}\n    \\nul A + \\rank A =  k.\n  \\end{align*}\n\\end{theorem}\n\n\n\\begin{qbox}\n  Rank-nullity can be used to detect isomorphisms.\n  Let $A$ be a square matrix of size $k \\times k$ representing a linear operator $A:\\bbr^k \\rightarrow \\bbr^k$.\\\\\n\n  Using the Rank-Nullity theorem, show that the following are equivalent\n      \\begin{enumerate}\n        \\item $A$ is an isomorphism,\n        \\item $\\nul A = 0$,\n        \\item $\\rank A = k$.\\\\\n      \\end{enumerate}\n\\end{qbox}\n\n\\begin{remark}\n  There is one more criterion for detecting isomorphisms\n\n    \\begin{enumerate}\n      \\item[4.] $\\det A \\neq 0$,\n    \\end{enumerate}\n\n  where $\\det A$ is the ``determinant of $A$''. Determinant is the signed volume of the $k$-dimensional cube formed by the columns of $A$, and can be computed very efficiently using Gaussian elimination.\n\\end{remark}\n\n\\begin{qbox}\n  Let $a$, $b$, $c$ be scalars. Assume that at least one of $a$, $b$, $c$ is non-zero.\n  \\begin{enumerate}\n    \\item Show that the matrix $A = \\begin{bmatrix} a & b & c \\end{bmatrix}$ has rank 1.\n    \\item Using the Rank-Nullity Theorem, conclude that $ax + by + cz = 0$ defines a plane in $\\bbr^3$.\n  \\end{enumerate}\n  The same proof can be used to show that a single non-trivial linear equation always defines an $n-1$ dimensional hyperplane in $\\bbr^n$.\n\\end{qbox}\n\n\n\\begin{proof}[Proof of the Rank-Nullity theorem]\n  Let $A: \\bbr^k \\rightarrow \\bbr^\\ell$. Let $$n = \\nul A.$$\n  To prove the theorem, we will construct a basis of $\\im A$ of size $k - n$.\n\n  Let $$\\calb' = \\set{\\vec{v}_1, \\dots, \\vec{v}_n}$$ be a basis of $\\ker A$.\n\n  \\textbf{Case 1:} $n = k$. In this case, we have $\\ker A = \\bbr^k$. By the definition of kernel, $A \\vec{v} = 0$ for all $\\vec{v} \\in \\bbr^k$. Hence, $\\im A = \\{ \\vec{0} \\}$ which implies that $\\rank A = 0$.\n\n  \\textbf{Case 2:} $n < k$. In this case, by repeatedly adding linearly independent vectors as in the proof of Theorem \\ref{theorem:existenceOfBasis}, we can extend $\\calb'$ to a basis $\\calb$ of $\\bbr^k$.\n  \\begin{align*}\n    \\calb=\\{\\underbrace{\\vec{v}_1, \\dots, \\vec{v}_n}_{\\calb'}, \\vec{w}_{n+1}, \\dots, \\vec{w}_k\\}.\n  \\end{align*}\n\n  \\textbf{Claim:} The set $\\calb''  = \\{A\\vec{w}_{n+1}, \\dots, A\\vec{w}_k \\}$ is a basis for $\\im A$.\n\n  We need to show that $\\spn(\\calb'') = \\im A$ and $\\calb''$ is linearly independent.\n  To prove the first part, note that any vector in $V$ can be written as\n  \\begin{align}\n    \\tag{*}\n    \\label{eq:eq1}\n    \\vec{v} = c_1 \\vec{v}_1 + \\dots + c_n \\vec{v}_n + c_{n+1} \\vec{w}_{n+1} + \\dots + c_k \\vec{w}_k\n  \\end{align}\n  for some scalars $c_1, \\dots, c_k$.\n  \\begin{qbox}\n    Apply $A$ to both sides of \\eqref{eq:eq1} to conclude that\n      \\begin{align*}\n        \\im A = \\spn(A\\vec{w}_{n+1}, \\dots, A\\vec{w}_k)\n      \\end{align*}\n  \\end{qbox}\n  It remains to show that $\\calb''$ is linearly independent. Suppose there are scalars $d_{n+1}, \\dots, d_k$ such that\n  \\begin{align*}\n      d_{n+1} A\\vec{w}_{n+1} + \\dots + d_kA \\vec{w}_k &= 0 \\\\\n      \\implies A(d_{n+1} \\vec{w}_{n+1} + \\dots + d_k \\vec{w}_k) &= 0 && \\mbox{by linearity} \\\\\n      \\implies d_{n+1} \\vec{w}_{n+1} + \\dots + d_k \\vec{w}_k &\\in \\ker A && \\mbox{by definition of }\\ker \\\\\n      \\implies d_{n+1} \\vec{w}_{n+1} + \\dots + d_k \\vec{w}_k &\\in \\spn({\\vec{v}_1, \\dots, \\vec{v}_n}) \\\\\n      \\implies d_{n+1} \\vec{w}_{n+1} + \\dots + d_k \\vec{w}_k &= d_1\\vec{v}_1 + \\dots + d_n \\vec{v}_n && \\mbox{by definition of }\\spn\n  \\end{align*}\n  for some scalars $d_1, \\dots, d_n$.\n\n  But the vectors $\\{\\vec{v}_1, \\dots, \\vec{v}_n, \\vec{w}_{n+1}, \\dots, \\vec{w}_k\\}$ form a basis for $V$ and hence are linearly independent. Hence, the only possible $d_i$'s satisfying the last equation are $d_1 = \\dots = d_k = 0$ which proves the linear independence of $\\calb''$.\n\\end{proof}\n\n\\begin{remark}\n  Rank-Nullity theorem is closely related to theorems from other areas of mathematics. For example, vector spaces are abelian groups under the vector addition operation and subspaces are the same as (normal) subgroups. The first isomorphism theorem in group theory then gives us $$\\bbr^k / \\ker A \\cong \\im A.$$\n  The Rank-Nullity theorem is then a version of Lagrange's theorem.\n  \\begin{qbox}[If you know what an exact sequence means]\n    Using the Rank-Nullity theorem, show that if\n    \\begin{align*}\n      0 \\rightarrow V_0 \\rightarrow V_1 \\rightarrow \\dots \\rightarrow V_n \\rightarrow 0\n    \\end{align*}\n    is an exact sequence of vector spaces then\n    \\begin{align*}\n      \\dim V_0 - \\dim V_1 + \\dots + (-1)^i \\dim V_i + \\dots + (-1)^n \\dim V_n = 0\n    \\end{align*}\n    This is saying that the Euler characteristic of an exact sequence is trivial.\n  \\end{qbox}\n\n\\end{remark}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Composition of linear transformations}\nWe saw in Section \\ref{section:linearTransformation} that composition of linear transformations is itself a linear transformation. For Euclidean spaces, this gives rise to products of matrices.\n\n\\begin{equation*}\n  \\begin{tikzcd}\n    \\bbr^k \\ar[rr,\"B\"] \\ar[rrrr,\"AB\"', bend right] && \\bbr^\\ell \\ar[rr,\"A\"] && \\bbr^m\n  \\end{tikzcd}\n\\end{equation*}\n\nBy carefully expanding out $A(B( \\vec{v}))$ one can find the general formula for $AB$, this is quite tedious to derive but easy to use. You should look it up.\n\nHere is the formula for multiplying two $2 \\times 2$ matrices.\n\n\\begin{equation*}\n  \\begin{tikzcd}\n    \\bbr^2 \\ar[rr,\"B\"] \\ar[rrrr,\"AB\"', bend right] && \\bbr^2 \\ar[rr,\"A\"] && \\bbr^2\n  \\end{tikzcd}\n\\end{equation*}\n\\begin{align}\n  \\label{eq:eq2}\n  \\begin{bmatrix} A_{11} & A_{12} \\\\ A_{21} & A_{22} \\end{bmatrix}\n  \\begin{bmatrix} B_{11} & B_{12} \\\\ B_{21} & B_{22} \\end{bmatrix}\n    &=\n  \\begin{bmatrix} A_{11} B_{11} + A_{12} B_{21} & A_{11} B_{12} + A_{12} B_{22} \\\\ A_{21} B_{11} + A_{22} B_{21} & A_{21} B_{12} + A_{22} B_{22} \\end{bmatrix}\n\\end{align}\n\n\\begin{qbox}\n  In Section \\ref{section:linearTransformation}, we computed the identity, rotation, and reflection matrices\n  \\begin{align*}\n    [\\id_{\\bbr^2}] &= \\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix} \\\\\\\\\n    [\\rot] &= \\begin{bmatrix} \\cos \\theta & -\\sin \\theta \\\\ \\sin \\theta & \\cos \\theta \\end{bmatrix}\\\\\\\\\n    [\\refl] &= \\begin{bmatrix} \\cos 2\\theta & \\sin 2\\theta \\\\ \\sin 2\\theta & -\\cos 2\\theta \\end{bmatrix}\n  \\end{align*}\n  Using \\eqref{eq:eq2} compute\n  \\begin{multicols}{2}\n    \\begin{enumerate}\n      \\item $[\\id_{\\bbr^2}] \\begin{bmatrix} A_{11} & A_{12} \\\\ A_{21} & A_{22} \\end{bmatrix}$\n      \\item $ \\begin{bmatrix} A_{11} & A_{12} \\\\ A_{21} & A_{22} \\end{bmatrix} [\\id_{\\bbr^2}]$\n      \\item $ [\\rot] [\\rot[\\varphi]] $\n      \\item $[\\refl] [\\refl]$\n      \\item $[\\refl] [\\refl[\\varphi]]$\n    \\end{enumerate}\n  \\end{multicols}\n  See any old friends? Interpret these geometrically.\n\\end{qbox}\n\n\\begin{qbox}[Optional] Derive the formula for matrix multiplication of $2 \\times 2$ matrices using compositions of linear transformations.\n\\end{qbox}\n\n\\hrule\n\\hrule\n\\hrule\n\nCongratulations on making it this far!!!(Yay!) What we have ``covered'' in the past week is more than what you would do in a month of regular class.\nThere is hardly an area of mathematics that does not use linear algebra, the more math you do the better you'll be able to understand and appreciate it.\nHere are some suggested topics to read from here:\n\\begin{multicols}{2}\n  \\begin{enumerate}\n    \\item Change of basis theorem,\n    \\item Eigenvalues and eigenvectors,\n    \\item Determinants,\n    \\item Gaussian elimination,\n    \\item Inner product spaces,\n    \\item Spectral theorem,\n    \\item Jordan canonical forms,\n    \\item Matrix groups.\n  \\end{enumerate}\n\\end{multicols}\n", "meta": {"hexsha": "f87e7bd208a6559483c0088e1e4fed7d222b5195", "size": 8372, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "05.tex", "max_stars_repo_name": "apurvnakade/mc2019-linear-algebra", "max_stars_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "05.tex", "max_issues_repo_name": "apurvnakade/mc2019-linear-algebra", "max_issues_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "05.tex", "max_forks_repo_name": "apurvnakade/mc2019-linear-algebra", "max_forks_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.86, "max_line_length": 311, "alphanum_fraction": 0.6525322504, "num_tokens": 2892, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.7289671485599466}}
{"text": "\\section{Adaptive Noise Cancellation}\n\n\\begin{enumerate}[label=\\alph*), leftmargin=*]\n\n%% a)\n\\item\n%\n\nLet the pure sine wave $x(n)$, the noisy signal $s(n)$, the noise term $\\eta(n)$ and the ALE filter output $\\hat{x}(n; \\Delta)$, parametrised by the delay parameter $\\Delta$.\nThen the Mean Squared Error (MSE) is given by:\n\n\\begin{align}\n    \\mathtt{MSE} =\n    \\E \\bigg[ \\big( s(n) - \\hat{x}(n; \\Delta) \\big)^{2} \\bigg]  &=  \\E \\bigg[ \\big( x(n) + \\eta(n) - \\hat{x}(n; \\Delta) \\big)^{2} \\bigg] \\\\\n                                                                &=  \\E \\bigg[ \\big( \\eta(n) + (x(n) - \\hat{x}(n; \\Delta)) \\big)^{2} \\bigg] \\\\\n                                                                &=  \\E \\bigg[ \\eta^{2}(n) \\bigg] +\n                                                                    \\E \\bigg[ \\big( x(n) - \\hat{x}(n; \\Delta) \\big)^{2} \\bigg] +\n                                                                   2\\E \\bigg[ \\eta(n) \\big(x(n) - \\hat{x}(n; \\Delta) \\big) \\bigg]\n\\label{eq:ale_mse}\n\\end{align}\n\nThe first term, noise power $\\E [ \\eta^{2}(n) ]$, is independent of $\\Delta$, while the second term, Mean Squared Prediction Error $\\E [ (x(n) - \\hat{x}(n; \\Delta))^{2} ]$ is not\na function of noise $\\eta(n)$. Hence, the last term only involves both the delay $\\Delta$ (through $\\hat{x}(n)$) and the noise term, so we will minimise it:\n\n\\begin{equation}\n    \\underset{\\Delta \\in \\sN}{min}\\ \\E \\bigg[ \\eta(n) \\big(x(n) - \\hat{x}(n; \\Delta) \\big) \\bigg]\n\\end{equation}\n\nUsing the fact that $x(n)$ and $\\eta(n)$ are uncorrelated the term $\\E [ \\eta(n) x(n) ]$ vanished:\n\n\\begin{align}\n    \\underset{\\Delta \\in \\sN}{min}\\ \\E \\bigg[ \\eta(n) \\hat{x}(n; \\Delta) \\bigg] &\\rightarrow\n        \\underset{\\Delta \\in \\sN}{min}\\ \\E \\bigg[ \\big( u(n) + 0.5u(n-2) \\big) \\vw^{T} \\vu(n; \\Delta) \\bigg] \\\\\n                                                                                &\\rightarrow\n        \\underset{\\Delta \\in \\sN}{min}\\ \\E \\bigg[ \\big( u(n) + 0.5u(n-2) \\big) \\sum_{i=0}^{M-1} w_{i} s(n - \\Delta - i) \\bigg] \\\\\n                                                                                &\\rightarrow\n        \\underset{\\Delta \\in \\sN}{min}\\ \\E \\bigg[ \\big( u(n) + 0.5u(n-2) \\big) \\sum_{i=0}^{M-1} w_{i} \\big( x(n - \\Delta - i) + \\eta(n - \\Delta - i) \\big) \\bigg] \\\\\n                                                                                &\\rightarrow\n        \\underset{\\Delta \\in \\sN}{min}\\ \\E \\bigg[ \\big( u(n) + 0.5u(n-2) \\big) \\sum_{i=0}^{M-1} w_{i} \\big( \\eta(n - \\Delta - i) \\big) \\bigg] \\\\\n                                                                                &\\rightarrow\n        \\underset{\\Delta \\in \\sN}{min}\\ \\E \\bigg[ \\big( u(n) + 0.5u(n-2) \\big) \\sum_{i=0}^{M-1} w_{i} \\big( u(n - \\Delta - i) + 0.5 u(n - 2 - \\Delta - i) \\big) \\bigg]\n\\label{con:delta} \\\\\n                                                                                &\\rightarrow\n        0, \\quad \\Delta > 2\n\\end{align}\n\nSince $u(n)$ is identically and \\textbf{independently} distributed white noise:\n\n\\begin{equation}\n    \\E \\bigg[ u(n) u(n - j) \\bigg] = 0, \\quad \\forall j \\neq 0\n\\end{equation}\n\ntherefore the expectation in (\\ref{con:delta}) is zero and thus minimised for $\\Delta > 2$, since the terms are non time-overlapping.\nThis is an expected result, since the colored noise signal $\\eta(n)$ is a second order MA process.\n\nThe theoretical optimal delay range, $\\Delta > 2$ is also verified empirically. In figure \\ref{fig:3_3_a_1} the clean signal $x(n)$ against, $s(n)$ and filter output $\\hat{x}(n)$\nare illustrated for different delay $\\Delta$ values. Moreover, the MPSE as a function of $\\Delta$ is also plotted in figure \\ref{fig:3_3_a_2}, verifying the improved performance $\\Delta > 2$.\nAll experiments are conducted using a fixed model order $M = 5$ LMS filter.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/a/ale_overlay-Delta_1}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/a/ale_overlay-Delta_2}\n    \\end{subfigure}\n    ~\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/a/ale_overlay-Delta_3}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/a/ale_overlay-Delta_4}\n    \\end{subfigure}\n    \\caption{ALE: overlay plots for various $\\Delta$ delays, for fixed $M=5$.}\n    \\label{fig:3_3_a_1}\n\\end{figure}\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/a/ale_mpse}\n    \\end{subfigure}\n    \\caption{ALE: MPSE against $\\Delta$, for fixed $M=5$.}\n    \\label{fig:3_3_a_2}\n\\end{figure}\n\n%% b)\n\\item\n%\n\nThe experiments are repeated varying now both the delay parameter, $\\Delta$, and the model order, $M$, obtaining figures \\ref{fig:3_3_b_1}, \\ref{fig:3_3_b_2}.\nWe notice that the mean squared prediction error (MPSE) is minimised for the hyperparmeters pair $(\\Delta, M) = (3, 6)$.\n\nOver-modelling (large $M$) results in excess degrees of freedom that increase computational complexity and over-fit noise, degrading\nmodel performance. For model order $M=6$ MPSE is minimised, while the model complutational load is still not prohibitive.\n\nIn the previous part we showed theoretically that for $\\Delta > 2$ the noise and the filter output are uncorrelated thus MSE is minimised.\nNonetheless, the second term in (\\ref{eq:ale_mse}) was ignored. The impact of this term on the MPSE is illustrated in figure \\ref{fig:3_3_b_2},\nwhere very large $\\Delta$ (i.e $\\Delta = 25$) inevitably cause a time-shift between the filter output $\\hat{x}(n)$ and the true sine wave $x(n)$.\nHence, $\\Delta = 3$ is the optimal parameter, minimising delay effects between $x(n)$ and $\\hat{x}(n)$, as well as guaranteeing uncorrelation between\n$\\hat{x}(n)$ and $\\eta(n)$.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/b/ale_mpse_vs_Delta}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/b/ale_mpse_vs_M}\n    \\end{subfigure}\n    \\caption{ALE: MPSE against delay $\\Delta$ and model order $M$.}\n    \\label{fig:3_3_b_1}\n\\end{figure}\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/b/ale_overlay-Delta_1}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/b/ale_overlay-Delta_3}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/b/ale_overlay-Delta_25}\n    \\end{subfigure}\n    \\caption{ALE: model deterioration for large delays $\\Delta$.}\n    \\label{fig:3_3_b_2}\n\\end{figure}\n\n%% c)\n\\item\n%\n\nWe compare the performance of the Adaptive Noise Cancellation (ANC) configuration to the Adaptive Line Enchancer (ALE) configuration, used in previous parts.\nThe colored noise $\\epsilon(n)$ is used as input to the LMS filter to perform ANC, such that:\n\n\\begin{equation}\n    \\epsilon(n) = 0.9 \\eta(n) + 0.05 \n\\end{equation}\n\nand as a result $\\epsilon(n)$ is the secondary noise signal, correlated to the $\\eta(n)$, primary noise signal. Note that the relationship between the two signals\nis unknown to the ANC algorithm.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/c/ALE_overlay}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/c/ANC_overlay}\n    \\end{subfigure}\n    \\caption{ALE vs ANC: overlay plots and mean prediction squared error.}\n    \\label{fig:3_3_c_1}\n\\end{figure}\n\nIn figure \\ref{fig:3_3_c_1} the overlay plots for 100 realisations of the process $x(n)$ are provided, along with the denoised versions of both the ALE and ANC configurations.\nANC performs overall better, with MPSE = 0.1374, than the ALE configuration, which scores MPSE = 0.2520. Nonetheless, we highlight the fact that the ANC algorithm\ndoes poorly in the first timesteps, but for $t > 400$, it tracks the true signal $x(n)$ much better. An ensemble of realisations of the process is also simulated and its mean are illustrated in figure \\ref{fig:3_3_c_2}.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/c/comparison}\n    \\end{subfigure}\n    \\caption{ALE vs ANC: ensemble mean comparison.}\n    \\label{fig:3_3_c_2}\n\\end{figure}\n\n%% d)\n\\item\n%\n\nLet a synthetic reference input, $\\epsilon(n)$, composed of a sinusoid of $50\\ Hz$ corrupted by white Gaussian noise. The ANC configuration is used with inputs\n$\\epsilon(n)$ and the \\texttt{POz} EEG time-series, in order to remove the strong $50 Hz$ frequency component due to power-line interference (mains).\n\nFor illustration purposes \\texttt{spectrogram}s are plotted using a rectangular window of length $L=4096$ and $80\\%$ overlap. The obtained spectrograms are provided\nin figures \\ref{fig:3_3_d_1} and \\ref{fig:3_3_d_2}. As expected the original \\texttt{POz} signal has a strong $50\\ Hz$ frequency component.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/d/original}\n    \\end{subfigure}\n    \\caption{EEG: original, reference spectrogram.}\n    \\label{fig:3_3_d_1}\n\\end{figure}\n\nThe LMS filter order $M$ and the step-size $\\mu$ is varied, and the impact on the spectrogram is shown in figure \\ref{fig:3_3_d_2}.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/d/M_1-mu_0.001}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/d/M_1-mu_0.005}.pdf}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/d/M_1-mu_0.100}.pdf}\n    \\end{subfigure}\n    ~\n    ~\n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/d/M_10-mu_0.001}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/d/M_10-mu_0.005}.pdf}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/d/M_10-mu_0.100}.pdf}\n    \\end{subfigure}\n    ~\n    ~\n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/d/M_25-mu_0.001}.pdf}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/d/M_25-mu_0.005}.pdf}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/d/M_25-mu_0.100}.pdf}\n    \\end{subfigure}\n    \\caption{EEG: ANC denoised spectrogram for different model order, $M$, and step-sizes, $\\mu$.}\n    \\label{fig:3_3_d_2}\n\\end{figure}\n\nLarge step-sizes (i.e $\\mu = 0.1$) affect significantly the spectral components around $50\\ Hz$, degrading ANC performance.\nOn the other hand, small step-sizes (i.e $\\mu = 0.001$) take more time to reach steady-state, however provide successful denoising, without disrupting the frequencies close to $50\\ Hz$.\n\nOn the other hand, under-modelling (i.e $M = 1$) leads to poor noise cancellation, since the $50\\ Hz$ power-line interface component has not been attenuated.\nHowever, over-modelling (i.e $M=25$) degrades quality of neighbour frequencies, while a medium size model, such as $M=10$, achieves satisfying performance, by eliminating the\n$50\\ Hz$ component of interest, without affecting any other compoenents.\n\nOverall, an ANC configuration with $(M, \\mu) = (10, 0.001)$ is selected. The corresponding denoised periodogram is also provided at figure \\ref{fig:3_3_d_3}.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/d/periodogram}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-noise-cancellation/assets/d/periodogram-error}\n    \\end{subfigure}\n    \\caption{EGG: periodograms of original and denoised signals.}\n    \\label{fig:3_3_d_3}\n\\end{figure}\n\n%\n\\end{enumerate}", "meta": {"hexsha": "681e94e82adf5408c53278518087f0227d52145a", "size": 14207, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/adaptive-signal-processing/adaptive-noise-cancellation/index.tex", "max_stars_repo_name": "filangel/ASPMI", "max_stars_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-02-20T14:43:34.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-13T21:13:02.000Z", "max_issues_repo_path": "tex/report/adaptive-signal-processing/adaptive-noise-cancellation/index.tex", "max_issues_repo_name": "AmjadHisham/ASPMI", "max_issues_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/report/adaptive-signal-processing/adaptive-noise-cancellation/index.tex", "max_forks_repo_name": "AmjadHisham/ASPMI", "max_forks_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-07-17T08:32:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-12T18:26:18.000Z", "avg_line_length": 49.1591695502, "max_line_length": 219, "alphanum_fraction": 0.6600971352, "num_tokens": 4272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.7289671383971902}}
{"text": "\\lab{Hysteresis}{Bifurcations}\n\\label{lab:Bifurcations}\n\nRecall that any ordinary differential equation can be written as a first order system of DEs, \n\\begin{align}\n\\dot{x} = F(x), \\quad \\dot{x} := \\frac{d}{dt}x(t).\\label{fos}\n\\end{align}\nMany interesting applications and physical phenomena can be modelled using ODEs.\nGiven a mathematical model of the form \\eqref{fos}, it is important to understand geometrically how its solutions behave.\nThis information can then be conveyed in a phase portrait, a graph describing solutions of \\eqref{fos} with differential initial conditions.\nThe first step in constructing a phase portrait is to find the equilibrium solutions of the equation, i.e., the zeros of $F(x)$, and to determine their stability.\n\nIt is often the case that the mathematical model we study depends on some parameter or set of parameters $\\lambda$.\nThus the ODE becomes \n\\begin{align}\n\\dot{x} = F(x,\\lambda).\\label{fos2}\n\\end{align}\nThe parameter $\\lambda$ can then be tuned to better fit the physical application.\nAs $\\lambda$ varies, the equilibrium solutions and other geometric features of \\eqref{fos2} may suddenly change.\nA value of $\\lambda$ where the phase portrait changes is called a \\emph{bifurcation point}; the study of how these changes occur is called \\emph{bifurcation theory}.\nThe parameter values and corresponding equilibrium solutions are often graphed together in a bifurcation diagram. \n\nAs an example, consider the scalar differential equation \n\\begin{eqnarray}\n\\dot{x} &=& x^2 + \\lambda. \\label{snbifurcation}\n\\end{eqnarray}\nFor $\\lambda > 0$ equation (\\ref{snbifurcation}) has no equilibrium solutions.\nAt $\\lambda = 0$ the equilibrium point $x=0$ appears, and for $\\lambda < 0$ it splits into two equilibrium points.\nFor this system, a bifurcation occurs at $\\lambda = 0$.\nThis is an example of a saddle-node bifurcation.\nThe bifurcation diagram is shown in Figure \\ref{bifurcation:sn}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{SaddleNBifurcation.pdf}\n\\caption{Bifurcation diagram for the equation $\\dot{x} = \\lambda + x^2$.}\n\\label{bifurcation:sn}\n\\end{figure}\n\n% The flow of a differential equation \\[\\dot{x} = f(x)\\] is the family of all possible solutions $\\phi(t,x_0)$, where $x_0$ represents the arbitrary initial value, $t \\in \\mathbb{R}.$\n% Here we will mainly consider scalar differential equations (so-called because $x$ is one dimensional).\n% It is often necessary to study a family of differential equations. These will have the form \n% \\[\\dot{x}= F(x,c),\\]\n% where $c$ may be a single parameter or a vector of parameters. \n% \n% Bifurcation theory is the study of how the qualitative structure of the flow of a differential equation varies as parameters in the differential equation are varied. \n% A differential equation has a stable orbit structure if sufficiently small changes in the parameter value do not change the qualitative structure of the flow.\n% A parameter value for which the flow does not have a stable orbit structure is called a bifurcation value.\n% \n% Terminology\n% bifurcation theory: 'the study of possible changes in the structure of orbits of a differential equation depending on variable parameters'\n% 'the study of changes in the qualitative structure of the flow of a differential equation as parameters are varied'\n% phase portrait: \n% bifurcation diagram: \n% number of orbits and their direction of flow of a differential equation = 'orbit structure of the differential equation' or 'the qualitiative structure of the flow'.\n% \n% Hyperbolic equilibrium points\n% $F(x_0,c_0) = 0$ where $\\frac{df}{dx}(x_0,c_0) \\not = 0.$\n% In this case the stability of the equilibrium point $x_0$ for values of $c$ near $c_0$ is determined by the derivative $\\frac{df}{dx}(x_0,c_0)$.\n% Example: $\\dot{x} = x-c.$ Plot $x$\n% \n% Hyperbolic equilibrium - mainly to be used when discussing stability\n% Saddle-Node Bifurcation - \\[\\dot{x} = c + x^2.\\]\n% Transcritical Bifurcation - \\[\\dot{x} = cx + x^2.\\]\n% Hysteresis Loop - \\[\\dot{x} = c + x-x^3.\\]\n% Pitchfork Bifurcation (Supercritical) - \\[\\dot{x} = cx-x^3.\\]\n% For an exercise, do a variation of \\[\\dot{x} = 1+cx-x^3.\\]\n\nSuppose that $F(x_0,\\lambda_0) = 0.$\nWe use a method called natural embedding to find zeros $(x,\\lambda)$ of $F$ for nearby values of $\\lambda$.\nSpecifically, we step forward in $\\lambda$ by letting $\\lambda_1 = \\lambda_0 + \\triangle \\lambda$, and use Newton's method to find the value $x_1$ that satisfies $F(x_1,\\lambda_1) = 0.$\nThis method works well except when $\\lambda$ is near a bifurcation point $\\lambda^*$.\n\nThe following code implements the natural embedding algorithm, and then uses that algorithm to find the curves in the bifurcation diagram for (\\ref{snbifurcation}).\nNotice that this algorithm needs a good initial guess for $x_0$ to get started.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{SaddleNPhasePortrait.pdf}\n\\caption{Phase Portrait for the equation $\\dot{x} = -2 + x^2$.}\n\\label{phaseportrait:sn}\n\\end{figure}\n\n\\begin{lstlisting}\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.optimize import newton\n\ndef EmbeddingAlg(param_list, guess, F):\n    X = []\n    for param in param_list:\n        try:\n            # Solve for x_value making F(x_value, param) = 0.\n            x_value = newton(F, guess, fprime=None, args=(param,), tol=1E-7, maxiter=50)\n            # Record the solution and update guess for the next iteration.\n            X.append(x_value)\n            guess = x_value\n        except RuntimeError:\n            # If Newton's method fails, return a truncated list of parameters\n            # with the corresponding x values.\n            return param_list[:len(X)], X\n    # Return the list of parameters and the corresponding x values.\n    return param_list, X\n\ndef F(x, lmbda):\n    return x**2 + lmbda\n\n# Top curve shown in the bifurcation diagram\nC1, X1 = EmbeddingAlg(np.linspace(-5, 0, 200), np.sqrt(5), F)\n# The bottom curve\nC2, X2 = EmbeddingAlg(np.linspace(-5, 0, 200), -np.sqrt(5), F)\n\\end{lstlisting}\n\n\\begin{problem}\nUse the natural embedding algorithm to create a bifurcation diagram for the differential equation\n\\[\\dot{x} = \\lambda x-x^3.\\]\nThis type of bifurcation is called a pitchfork bifurcation (you should see a pitchfork in your diagram).\n\nHints: Essentially this amounts to running the same code as the example, but with different parameters and function calls so that you are tracing through the right curves for this problem.\nTo make this first problem work, you will want to have your `linspace` run from high to low instead of from low to high.\nThere will be three different lines in this image.\n\\end{problem}\n\n\\begin{problem}\nCreate bifurcation diagrams for the differential equation\n\\[\\dot{x} = \\eta + \\lambda x-x^3,\\]\nwhere $\\eta = -1, -.2, .2$ and $1.$  Notice that when $\\eta = 0$ you can see the pitchfork bifurcation of the previous problem.\nThere should be four different lines in this image.\nThere will be one line for each value of $\\eta$.\n\\end{problem}\n\nAn interesting ODE is given by \n\\begin{align*}\n\tx' &= \\lambda + x - x^3.\n\\end{align*}\nThis system has a bifurcation diagram containing what is known as a hysteresis loop, shown in Figure \\ref{bifurcation:hysteresis}.\nIn the hysteresis loop, when the parameter $\\lambda$ moves beyond the bifurcation point the equilibrium solution makes a sudden jump to the other stable branch.\nWhen this occurs the system cannot reach its previous equilibrium by simply rewinding the parameter slightly. \n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{HysteresisBifurcation.pdf}\n\\caption{Bifurcation diagram for the ODE $x' = \\lambda + x - x^3$. }\n\\label{bifurcation:hysteresis}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{BudwormEquilibria.pdf}\n\\caption{Graphical demonstration of nonzero equilibrium solutions for the budworm population (here $r = .56$).\nNote that as $k$ increases, the number of solutions goes from one to three, and then back to one. }\n\\label{equilibria:budworm}\n\\end{figure}\n\n\\section*{Budworm Population Dynamics}\nHere we study a mathematical model describing the population dynamics of an insect called the spruce budworm.\nIn eastern Canada, an outbreak in the budworm population can destroy most of the trees in a forest of balsam fir trees in about 4 years.\nThe mathematical model is given by \n\\begin{align}\n\\dot{N} = RN\\left(1 - \\frac{N}{K}\\right) - p(N). \\label{budworm1}\n\\end{align}\nThis model was studied by Ludwig et al (1978), and is described well in Strogatz's text \\emph{Nonlinear Dynamics and Chaos}.\nHere $N(t)$ represents the budworm population at time $t$, $R$ is the growth rate of the budworm population and $K$ represents the carrying capacity of the environment.\nWe could interpret $K$ to represent the amount of food available to the budworms. \n$p(N)$ represents the death rate of budworms due to predators (birds); we assume specifically that $p(N)$ has the form $P(N) = \\frac{BN^2}{A^2 + N^2}$.\n\nBefore studying the equilibrium points of \\eqref{budworm1} it is important to reduce the number of parameters in the system by nondimensionalizing.\nThus, we make the coordinate change $x = N/A$, $\\tau = Bt/A$, $r = RA/B$, and $k = K/A$, obtaining finally the system \n\\begin{align}\n\t\\frac{dx}{d \\tau} &= rx(1-x/k) - \\frac{x^2}{1+x^2}.\n\\end{align}\n\nNote that $x = 0$ is always an equilibrium solution.\nTo find other equilibrium solutions we study the equation $r(1-x/k)-x/(1+x^2) = 0$.\nFix $r = .56$, and consider Figure \\eqref{equilibria:budworm}. \n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{BudwormPopulation.pdf}\n\\caption{Bifurcation diagram for the budworm population model.\nThe parameter $r$ is fixed at $0.56.$\nThe lower stable branch is known as the refuge level of the bundworm population, while the upper stable branch is known as the outbreak level.\nOnce the budworm population reaches an outbreak level, the available food (foliage of the balsam fir trees) in the system must be reduced drastically to jump back down to refuge level.\nThus many of the balsam fir trees die before the budworm population returns to refuge level.}\n\\label{bifurcation:budworm}\n\\end{figure}\n\n\\begin{problem}[Budworm Population]\nReproduce the bifurcation diagram for the differential equation\n\\begin{align*}\n\t\\frac{dx}{d \\tau} &= rx(1-x/k) - \\frac{x^2}{1+x^2},\n\\end{align*}\nwhere $r = 0.56$.\n\nHint: Find a value for $k$ that you know is in the middle of the plot (i.e. where there are three possible solutions), then use the code above to expand along each contour till you obtain the desired curve.\nNow find the proper initial guesses that give you the right bifurcation curve.\nThe final plot will look like the one in Figure \\ref{bifurcation:budworm}, but you will probably have to run the embedding algorithm 6 times to get every part of the plot.\n\\end{problem}", "meta": {"hexsha": "bcfc6511e32d3a93a087a91251a3e574cab2c9be", "size": 10850, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/Hysteresis/Hysteresis.tex", "max_stars_repo_name": "rachelwebb/numerical_computing", "max_stars_repo_head_hexsha": "e7416b43b97976060f6875fa46c7dca20a9f635f", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/Hysteresis/Hysteresis.tex", "max_issues_repo_name": "rachelwebb/numerical_computing", "max_issues_repo_head_hexsha": "e7416b43b97976060f6875fa46c7dca20a9f635f", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/Hysteresis/Hysteresis.tex", "max_forks_repo_name": "rachelwebb/numerical_computing", "max_forks_repo_head_hexsha": "e7416b43b97976060f6875fa46c7dca20a9f635f", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-12-08T01:19:23.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T01:19:23.000Z", "avg_line_length": 54.797979798, "max_line_length": 206, "alphanum_fraction": 0.7442396313, "num_tokens": 2894, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.7288318759395689}}
{"text": "\\begin{table*}[tb]\n\t\\tbl{Set operations available in LazySets. The distinction between lazy and concrete functions is explained in Section~\\ref{sec:lazy}. The result of the last three operations is generally not convex even if used with convex operands. For binary operations (marked with \\binary{$\\cdot$}) there is also an $n$-ary lazy version with the suffix \\code{Array}, e.g., \\code{MinkowskiSumArray}. Unicode symbols (as mentioned in the column ``Short form'') are entered in the Julia REPL by typing the \\LaTeX\\ command (e.g.: \\code{\\textbackslash{}oplus} for $\\oplus$) followed by pressing the ``Tab'' key. See Appendix~\\ref{sec:setops} for some central definitions.}{\n\t\\begin{tabular}{l l l l l}\n\t\t\\toprule\n\t\tOperation name & Math form & Lazy function (constructor) & Short form & Concrete function \\\\\n\t\t\\midrule\n\t\t%\n\t\t\\binary{Minkowski sum} & $\\X \\oplus \\Y$ & \\code{MinkowskiSum} & \\code{+},\\code{\\textbackslash{}oplus} & \\code{minkowski$\\_$sum} \\\\\n\t\t%\n\t\t\\binary{Intersection} & $\\X \\cap \\Y$ & \\code{Intersection} & \\code{\\textbackslash{}cap} & \\code{intersection} \\\\\n\t\t%\n\t\t\\binary{Cartesian product} & $\\X \\times \\Y$ & \\code{CartesianProduct} & \\code{*},\\code{\\textbackslash{}times} & \\code{cartesian$\\_$product} \\\\\n\t\t%\n\t\t\\binary{Convex hull} & $\\CH(\\X \\cup \\Y)$ & \\code{ConvexHull} & \\code{CH} & \\code{convex$\\_$hull} \\\\\n\t\t%\n\t\tSymmetric interval hull & $\\boxdot(\\X)$ & \\code{SymmetricIntervalHull} & \\code{\\textbackslash{}boxdot} & \\code{symmetric$\\_$interval$\\_$hull} \\\\\n\t\t%\n\t\tLinear map & $A \\X$ & \\code{LinearMap} & \\code{*} & \\code{linear$\\_$map} \\\\\n\t\t%\n\t\tExponential map & $e^A \\X$ & \\code{ExponentialMap} && \\code{exponential$\\_$map} \\\\\n\t\t%\n\t\tTranslation & $\\X + b$ & \\code{Translation} & \\code{+} & \\code{translate} \\\\\n\t\t%\n\t\tAffine map & $A \\X + b$ & \\code{AffineMap} & \\code{*} and \\code{+} & \\code{affine$\\_$map} \\\\\n\t\t%\n\t\tReset map & $x_i \\mapsto c$ & \\code{ResetMap} && - \\\\\n\t\t%\n\t\tInverse linear map & $A^{-1} \\X$ & \\code{InverseLinearMap} && - \\\\\n\t\t%\n\t\tBloating & $\\X \\oplus \\{x : \\Vert x \\Vert \\leq \\varepsilon\\}$ & \\code{Bloating} && - \\\\\n\t\t%\n\t\t\\midrule\n\t\t%\n\t\t\\binary{Union} & $\\X \\cup \\Y$ & \\code{UnionSet} & \\code{\\textbackslash{}cup} & - \\\\\n\t\t%\n\t\tComplement & $\\X^C$ & \\code{Complement} && \\code{complement} \\\\\n\t\t%\n\t\tRectified linear unit & $x_i \\mapsto \\max(x_i, 0)$ & \\code{Rectification} && \\code{rectify} \\\\\n\t\t\\bottomrule\n\t\\end{tabular}}\n\t\\label{tab:operations}\n\\end{table*}\n\nLazySets offers support for \\emph{convex} and \\emph{non-convex} sets.\n%\nIntuitively, a set $\\X$ is convex if one can draw a straight line segment between any two points in $\\X$ without leaving $\\X$ (see Appendix~\\ref{sec:convexdef} for a formal definition).\nThis explains why optimization over a convex set is efficient.\nConvex sets enjoy several other attractive properties, and many important geometric shapes are convex.\n%\n\n\\subsection{Constructing sets}\n\nTwo basic sets are the \\emph{hyperplane}\n%\n\\[\n\t\\{x \\in \\R^n \\mid a^T x = b\\},\n\\]\n%\nwhich is parametric in a vector $a \\in \\R^n$ and a scalar $b \\in \\R$, and the \\emph{half-space} (or \\emph{linear constraint})\n%\n\\[\n\t\\{x \\in \\R^n \\mid a^T x \\leq b\\},\n\\]\n%\nwhich consists of all points on one side of the corresponding hyperplane.\nIn LazySets these sets are constructed from $a$ and $b$. For example, the two-dimensional hyperplane $x = 1$ (resp. the half-space $x \\leq 1$) are:\n\n\\begin{minipage}{\\linewidth}\n\\vspace{-\\abovedisplayskip}\n\\begin{lstlisting}\njulia> a = [1.0, 0.0]; b = 1.0\n\njulia> Hyperplane(a, b)\nHyperplane{Float64,Vector{Float64}}([1.0, 0.0], 1.0)\n\njulia> HalfSpace(a, b)\nHalfSpace{Float64,Vector{Float64}}([1.0, 0.0], 1.0)\n\\end{lstlisting}\n\\end{minipage}\n%\nHigher-dimensional sets are defined in a similar fashion; for instance, the 100-dimensional half-space $x_1 + \\ldots + x_{100} \\leq 10$ is:\\footnote{Sometimes we abbreviate the output to improve readability.}\n%\n\\begin{minipage}{\\linewidth}\n\\vspace{-\\abovedisplayskip}\n\t\\begin{lstlisting}\njulia> a = fill(1.0, 100); b = 10.0\n\njulia> HalfSpace(a, b)\nHalfSpace([1.0, ..., 1.0], 10.0)\n\t\\end{lstlisting}\n\\end{minipage}\n\n\nThe most widely used convex sets in various disciplines are (convex) \\emph{polyhedra}, which are characterized as the finite intersection of half-spaces.\nThis is also known as the \\emph{H-representation}.\nFor bounded polyhedra, which are called \\emph{polytope}, LazySets also supports a dual way to represent such sets in \\emph{V-representation} as the convex hull of points.\nThe functions \\code{tohrep(X)} and \\code{tovrep(X)} can be used to convert between these representations.\n\nOptimization over a polyhedron with linear objective corresponds to solving a linear program.\nLinear programs can model a wide variety of real-life optimization problems and can be solved efficiently \\cite{dantzig1998linear,kochenderfer2019algorithms}.\nOn the left of Fig.~\\ref{fig:supfunc} we show an example of a polytope in orange, with seven (linear) constraints, and a half-space in blue.\n\n\\smallskip\n\nLazySets contains many (currently: $26$) different structs to represent common classes of sets (such as half-spaces).\nThese set types simply expect and store the corresponding parameters that represent the set.\nFor example, the \\code{HalfSpace} stores the vector \\code{a} and the scalar \\code{b}.\n(There are a few exceptions where the constructor performs normalization by default, e.g., \\code{HPolygon}, representing a two-dimensional polytope, sorts the constraints by the vectors \\code{a} in counter-clockwise order.)\nHence construction is fast and the internal representation is space efficient.\nFor instance, the \\code{BallInf} represents a hypercube specified by the center vector $c \\in \\R^n$ and the radius $r \\in \\R$.\nIn $n$ dimensions, a hypercube has $2^n$ vertices, but creating an $1{,}000$-dimensional \\code{BallInf} is instantaneous.\n\n\\begin{minipage}{\\linewidth}\n\\vspace{-\\abovedisplayskip}\n\\begin{lstlisting}\njulia> @time BallInf(zeros(1000), 1.0)\n0.000005 seconds (2 allocations: 7.969 KiB)\n\\end{lstlisting}\n\\end{minipage}\n\n\n\\subsection{Extracting information from sets}\n\nBeing able to represent sets is not useful by itself because we also want to interact with them.\nFor example, we may want to draw samples from a set.\nA general approach to do that is rejection sampling, which picks a random point $x \\in \\R^n$ and checks whether $x \\in \\X$ holds.\nWe can thus use rejection sampling with any set type that implements a membership test.\n\n\\begin{minipage}{\\linewidth}\n\\vspace{-\\abovedisplayskip}\n\\begin{lstlisting}\njulia> ones(1000) ∈ BallInf(zeros(1000), 1.0)\ntrue\n\\end{lstlisting}\n\\end{minipage}\n\nOther typical properties that can be checked for sets $\\X$ and $\\Y$ are emptiness ($\\X = \\emptyset$; \\code{isempty}), inclusion ($\\X \\subseteq \\Y$; \\code{issubset}), and having no point in common ($\\X \\cap \\Y = \\emptyset$; \\code{isdisjoint}).\nThe complexity of such operations depends on the representation of the set.\nTake for example a polyhedron represented by the list of its linear constraints.\nEmptiness can be checked by formulating a feasibility linear program.\nInclusion and disjointness can be checked using the support function (see Section~\\ref{sec:supfun}).\n\n\\smallskip\n\nWe may also want to obtain information that is encoded in the set representation.\nFor example, we can ask for the list of vertices of a polytope.\nWe have seen that a hypercube is represented by the center and the radius, so the vertices need to be computed on demand.\n\n\\begin{minipage}{\\linewidth}\n\\vspace{-\\abovedisplayskip}\n\\begin{lstlisting}\njulia> vertices_list(BallInf([1.0, 4.0], 1.0))\n4-element Vector{Vector{Float64}}:\n [2.0, 5.0]\n [0.0, 5.0]\n [2.0, 3.0]\n [0.0, 3.0]\n\\end{lstlisting}\n\\end{minipage}\n\nEquality of sets in the mathematical sense can be checked via \\code{isequivalent} (which by default checks mutual inclusion):\n\n\\begin{minipage}{\\linewidth}\n\\vspace{-\\abovedisplayskip}\n\\begin{lstlisting}\njulia> X = Interval(-1, 1) × Interval(-1, 1)\nCartesianProduct{Float64,\n  Interval{...}, Interval{...}}(...)\n\njulia> Y = BallInf(zeros(2), 1.0)\n\njulia> isequivalent(X, Y)\ntrue\n\\end{lstlisting}\n\\end{minipage}\n\n\n\\subsection{Set interfaces}\n\nSometimes the same implementation works for several set types.\nLazySets uses a hierarchy of abstract types (which we call \\emph{interfaces}) to summarize common functionalities.\nFor example, \\code{AbstractHyperrectangle} is a supertype of all hyperrectangular set types such as \\code{BallInf} and provides a default implementation to compute the volume.\nWhen adding a new set type representing a hyperrectangle, it will automatically use this implementation.\n\nThe following list is not exhaustive, but should help as a mental model of how the library is organized. Definitions are given from more specific to more general (i.e., less structured).\n\n\\smallskip\n\n\\code{AbstractHyperrectangle}: Hyperrectangular sets can be represented by a center vector $c \\in \\R^n$ and a radius vector $r \\in \\R^n$. Each $x \\in \\X$ can be written as $x_i = c_i + \\xi_i r_i$ for $i = 1,\\ldots, n$, for some $\\xi_i \\in [-1, 1]$. Implementations include intervals (\\code{Interval}), hypercubes (\\code{BallInf}), and the general \\code{Hyperrectangle}.\n\n\\smallskip\n\n\\code{AbstractZonotope}: Zonotopic sets are those which admit a representation given by a center $c \\in \\R^n$ and a finite set of \\emph{generators} $g_j \\in \\R^n$, $j \\in 1, \\ldots, m$, such that $x \\in \\X$ is can be written as $x = c + \\sum_j \\xi_j g_j$ for some $\\xi_j \\in [-1, 1]$. Hyperrectangular sets are also zonotopic, as well as general zonotopes (\\code{Zonotope}).\n\n\\smallskip\n\n\\code{AbstractPolyhedron}: A set is called polyhedral if it can be expressed as a finite intersection of half-spaces. Special cases include hyperrectangular and zonotopic sets, as well as more general polytopes (\\code{HPolytope}, \\code{VPolytope}) and also possibly unbounded polyhedra (\\code{HPolyhedron}).\n\n\\smallskip\n\n\\code{LazySet}: All convex set types belong to this abstract supertype to prevent type piracy when extending \\code{Base} functions.\nWe are working toward having non-convex sets, such as set unions, in the same type hierarchy as well.\n\n\n\\subsection{Set operations}\n\nWe have seen that we can interact with sets by checking properties.\nImportantly, we can also apply set operations to sets for constructing new sets.\n(By default the result is a new set instance and the original set instance is not manipulated.)\nFor details about the complexity for common set representations we refer to \\cite[Table~1]{althoff2020set}.\nFor example, one common set operation is to translate (or shift) every element in the set by a constant vector.\n\n\\begin{minipage}{\\linewidth}\n\\vspace{-\\abovedisplayskip}\n\\begin{lstlisting}\njulia> B1 = BallInf([1.5, 2.0], 1.0)\njulia> B2 = translate(B1, [1.5, -1.0])\njulia> dump(B2)\nBallInf{Float64, Vector{Float64}}\n  center: Array{Float64}((2,)) [3.0, 1.0]\n  radius: Float64 1.0\n\\end{lstlisting}\n\\end{minipage}\n\nAs seen above, a translation usually preserves the set type.\nFor most operations this is generally not the case.\nFor instance, the intersection of two half-spaces is itself not a half-space but a polyhedron.\n\n\\begin{minipage}{\\linewidth}\n\\vspace{-\\abovedisplayskip}\n\\begin{lstlisting}\n# intersect {x | x <= 1} and {x | x >= 0}\njulia> P = intersection(HalfSpace([1.0], 1.0),\n                        HalfSpace([-1.0], 0.0))\njulia> typeof(P)\nHPolyhedron{Float64, Vector{Float64}}\n\\end{lstlisting}\n\\end{minipage}\n\nFor a complete list of the set operations available in LazySets we refer to Table~\\ref{tab:operations}.\n", "meta": {"hexsha": "5ca70646ff09f1fd120d4654cdfbd7816f3d607e", "size": 11493, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/basic.tex", "max_stars_repo_name": "JuliaReach/LazySets-JuliaCon21", "max_stars_repo_head_hexsha": "033612bd98ef8692195e4860e7eaa7bfbd05e6c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-09-28T20:12:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-27T16:51:11.000Z", "max_issues_repo_path": "paper/basic.tex", "max_issues_repo_name": "JuliaReach/LazySets-JuliaCon21", "max_issues_repo_head_hexsha": "033612bd98ef8692195e4860e7eaa7bfbd05e6c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-11-03T13:31:10.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-16T21:15:45.000Z", "max_forks_repo_path": "paper/basic.tex", "max_forks_repo_name": "JuliaReach/LazySets-JuliaCon21", "max_forks_repo_head_hexsha": "033612bd98ef8692195e4860e7eaa7bfbd05e6c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-27T15:57:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-27T15:57:41.000Z", "avg_line_length": 47.6887966805, "max_line_length": 657, "alphanum_fraction": 0.7266162012, "num_tokens": 3452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.8289388167733099, "lm_q1q2_score": 0.7287588864789812}}
{"text": "If you haven't downloaded and unzipped \\href{https://libaoj.in/courses/2021f/MATH3341/zip/Math.3341.zip}{\\texttt{Math.3341.zip}}. Download and unzip it under \\verb|H:| (H Drive if you are working on the Remote Lab). Change the current working directory by typing \\verb|cd H:\\Math.3341\\Math.3341.Lab.11| in the Command Window, and type \\verb|edit lab_11_script| in the Command Window to edit \\verb|lab_11_script.m|.\n\n\\section{Built-in Integration Functions}\n\\begin{enumerate}[(a)]\n\\item Use both \\verb|polyint| and \\verb|integral| to evaluate $\\displaystyle \\int_{-1}^{3} (x^2 - 2x + 1) \\, dx$.\n    \\begin{enumerate}[(1)]\n        \\item Define the lower bound \\verb|a| and upper bound \\verb|b|.\n        \\item Define the polynomial \\verb|P| as $p(x) = x^{2} - 2x + 1$.\n        \\item Integrate $p(x) = x^{2} - 2x + 1$ using \\verb|polyint| and store the result to \\verb|pI|.\n        \\item By fundamental theorem of calculus, evaluate the integral \\verb|pI| on $[a, b]$ using \\verb|polyval| and store the result to \\verb|pI_value|.\n        \\item Define the anonymous function \\verb|f| by $f(x) = x^2 - 2x + 1$, and then use \\verb|integral| to evaluate $\\displaystyle \\int_{-1}^{3} (x^2 - 2x + 1) \\, dx$ and store it to \\verb|I|.\n    \\end{enumerate}\n\\item Evaluate the previous integral again, now using \\verb|trapz| and \\verb|cumtrapz|.\n\\item Use \\verb|integral2| to evaluate $\\displaystyle \\int_{-\\pi}^{-3\\pi / 2} \\int_{0}^{2 \\pi} (y \\sin{x} + x \\cos{y}) \\, dy \\, dx$.\n\\item Use \\verb|integral3| to evaluate $\\displaystyle \\int_{0}^{1} \\int_{x^2}^{x} \\int_{x-y}^{x+y} y \\, dz \\, dy \\, dx$.\n\\end{enumerate}\n\\section{Gauss Quadrature}\n\\begin{enumerate}[(a)]\n    \\item Implement Gauss quadrature using $n$ Gauss nodes, which is given by Equation \\eqref{eq:gauss}, in the function file \\verb|gauss_quad.m|.\n        \\begin{equation}\n            \\label{eq:gauss}\n            \\int_{-1}^{1} f(x) \\, dx \\approx \\sum_{i=1}^{n} w_i f(x_i).\n        \\end{equation}\n    \\item Use \\verb|gauss_quad| to evaluate the integral\n        $$\n        \\int_{1}^{1.6} \\frac{2x}{x^2 - 4} \\, dx,\n        $$\n        with $n = 1, 2, \\ldots , 15$ Gauss nodes.\n\n        Note: \\verb|legendre_pair.m| is provided to calculate $x_i$ and $w_i$. Use \\verb|help legendre_pair| to check the usage.\n\\end{enumerate}\n\nAt last, call \\verb|diary('lab_11_output.txt')|, run the scripts \\verb|lab_11_script.m|, then call \\verb|diary off|. You will upload the script files \\verb|lab_11_script.m|, \\verb|lab_11_output.txt|, and \\verb|gauss_quad.m| to Overleaf. Then recompile, and submit the generated .pdf file on WyoCourses.\n", "meta": {"hexsha": "aec1625effaa07ca9e3b29a291a81685df5720b8", "size": 2575, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/Math.3341.Lab.11/exercise/body.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/Math.3341.Lab.11/exercise/body.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/Math.3341.Lab.11/exercise/body.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 75.7352941176, "max_line_length": 414, "alphanum_fraction": 0.6582524272, "num_tokens": 881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388040954684, "lm_q2_score": 0.8791467627598856, "lm_q1q2_score": 0.728758866146582}}
{"text": "\\begin{Definition}{a-posteriori}\n  Let $u\\in V$ be the solution to a boundary value in weak form and\n  $u_h\\in V_h$ be its finite element approximation on the mesh\n  $\\mesh_h$. We call a quantity $\\eta_h(u_h)$ \\define{a posteriori\n    error estimator},\n  \\begin{gather}\n    \\norm{u-u_h} \\le c \\eta_h(u_h).\n  \\end{gather}\n  The estimator is \\define{reliable}, if the constant $c$ is\n  computable. It is \\define{efficient}, if the converse estimate holds,\n  namely\n%  with addition of a quantity $\\osc_h(f)$\n  \\begin{gather}\n    \\eta_h(u_h) \\le c \\norm{u-u_h}.\n  \\end{gather}\n\\end{Definition}\n\n\\subsection{Quasi-interpolation in $H^1$}\n\n\\begin{intro}\n  Interpolation in Sobolev spaces in\n  \\slideref{Theorem}{fe-interpolation} relies on the nodal\n  interpolation operator in\n  \\slideref{Definition}{nodal-interpolation}, which in turn requires\n  point values of the interpolated function. Therefore, it is not\n  defined on $H^1(\\domain)$ in dimensions greater than one. Since we\n  need such interpolation operators in the analysis of a posteriori\n  error estimates, we provide them in this section.\n  \n  Most details in this section are from~\\cite{Verfuerth13}. For the\n  ease of presentation, we present the results for Dirichlet problem\n  of the Laplacian, namely $V = H^1_0(\\domain)$ and\n  \\begin{gather*}\n    a(u,v) = \\int_\\domain \\nabla u\\cdot\\nabla v\\dvx.\n  \\end{gather*}\n\\end{intro}\n\n\\begin{Definition}{locally-quasi-uniform}\n  A shape-regular family of meshes $\\{\\mesh_h\\}$ is called\n  \\define{locally quasi-uniform}, if there is a constant $c$ such that\n  for every pair of cells $\\cell_1$ and $\\cell_2$ sharing at least one\n  vertex there holds\n  \\begin{gather}\n    h_{\\cell_1} \\le c h_{\\cell_2}.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Definition}{fem-neighborhood}\n  For a vertex or higher-dimensional boundary facet $F$, we define the\n  set of cells\n  \\begin{gather}\n    \\mesh_{F} = \\bigl\\{ \\cell\\in\\mesh \\big|F \\subset\\d\\cell \\bigr\\}.\n  \\end{gather}\n  Similarly, the set of cells sharing at least one vertex with $\\cell$\n  is called $\\mesh_{\\cell}$. Additionally, we define the subdomains\n  \\begin{gather}\n    \\overline\\domain_{F} = \\bigcup_{\\cell\\in \\mesh_{F}}\\overline\\cell,\n    \\qquad\n    \\overline\\domain_{\\cell} = \\bigcup_{\\cell'\\in \\mesh_{\\cell}}\\overline\\cell'.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Theorem*}{clement}{Clément quasi-interpolation}\n  Let $\\{\\mesh_h\\}$ be a locally quasi-uniform family of meshes with\n  piecewise polynomial finite element spaces\n  $V_h\\subset H^1_0(\\domain)$. Then, there exist bounded operators\n  $\\overline I_h\\colon H^1_0(\\domain) \\to V_h$ such that for every\n  function $u\\in H^1_0(\\domain)$, every mesh cell $\\cell$, every face\n  $F$, and for $m=0,1$ there holds\n  \\begin{align}\n    \\norm{u-\\overline I_h u}_{m;T} &\\le c h_\\cell^{1-m} \\snorm{u}_{1;\\domain_\\cell} \\\\\n    \\norm{u-\\overline I_h u}_{0;F} &\\le c h_\\cell^{\\nicefrac{1}{2}} \\snorm{u}_{1;\\domain_\\cell}\n  \\end{align}\n\\end{Theorem*}\n\n\\begin{proof}\n  We construct the quasi-interpolation operator on a mesh cell $\\cell$\n  into the lowest order space $\\P_1$ or $\\Q_1$ in two steps. First,\n  for each vertex $\\vertex_i$ of $\\cell$, let\n  \\begin{gather}\n    \\overline u_i = \\frac1{\\abs{\\domain_{\\vertex_i}}}\n    \\int_{\\domain_{\\vertex_i}} u \\dvx.\n  \\end{gather}\n  By Poincaré inequality,\n  \\begin{gather}\n    \\label{eq:fem-aposteriori:1}\n    \\norm{u-\\overline u_i}_{\\domain_{\\vertex_i}}\n    \\le c \\diam(\\domain_{\\vertex_i}) \\norm{\\nabla u}_{\\domain_{\\vertex_i}}.\n  \\end{gather}\n  For a vertex $\\vertex_i$ on the boundary, we observe\n  \\begin{gather}\n    \\label{eq:fem-aposteriori:2}\n    \\begin{split}\n      \\norm{\\overline u_i}_{\\domain_{\\vertex_i}}^2\n      &= \\frac1{\\abs{\\domain_{\\vertex_i}}^2}\n      \\int_{\\domain_{\\vertex_i}}\\left(\\int u \\dvy\\right)^2\\dvx\\\\\n      & = \\frac1{\\abs{\\domain_{\\vertex_i}}}\\left(\\int 1 u \\dvy\\right)^2\\\\\n      & \\le \\frac1{\\abs{\\domain_{\\vertex_i}}} \\int 1^2\\dvy \\int u^2\\dvy \\\\\n      & = \\norm{u}^2_{{\\domain_{\\vertex_i}}}\\\\\n      & \\le c \\diam({\\domain_{\\vertex_i}})^2 \\norm{\\nabla u}_{{\\domain_{\\vertex_i}}}^2,\n    \\end{split}\n  \\end{gather}\n  by Friedrichs' inequality, since the subdomain\n  ${\\domain_{\\vertex_i}}$ has at least one face on $\\d\\domain$.\n\n  Now, we define the quasi-interpolation operator\n  $\\overline I_h\\colon H^1_0(\\domain)\\to V_h$ cellwise on simplices by\n  \\begin{gather}\n    \\label{eq:fem-aposteriori:3}\n    \\overline I_h u_{|\\cell}\n    = \\sum_{\\vertex_i\\in\\d\\cell\\cap\\domain} \\lambda_i \\overline u_i.\n  \\end{gather}\n  Note, that zero boundary conditions are enforced by omitting\n  vertices on the boundary.  On quadrilaterals, we use the bilinear\n  shape functions associated with the vertices instead of the\n  \\putindex{barycentric coordinates} $\\lambda_i$. Now, using\n  $\\sum\\lambda_i=1$ and $0\\le \\lambda_i \\le 1$, we estimate\n  \\begin{align*}\n    \\norm{u - \\overline I_h u}_\\cell\n    & \\le \\sum_{\\vertex_i\\in\\d\\cell} \\norm{\\lambda_i(u-\\overline u_i)}_{\\cell}\n      + \\sum_{\\vertex_i\\in\\d\\cell\\cap\\d\\domain}\n      \\norm{\\lambda_u \\overline u_i} \\\\\n    & \\le \\sum_{\\vertex_i\\in\\d\\cell} \\norm{u-\\overline u_i}_{\\cell}\n      + \\sum_{\\vertex_i\\in\\d\\cell\\cap\\d\\domain}\n      \\norm{\\overline u_i} \\\\\n    & \\le \\diam({\\domain_{\\vertex_i}})\\left(\n      \\sum_{\\vertex_i\\in\\d\\cell} \\norm{\\nabla u}_{\\domain_{\\vertex_i}}\n      + \\sum_{\\vertex_i\\in\\d\\cell\\cap\\d\\domain} \\norm{\\nabla u}_{\\domain_{\\vertex_i}}\n      \\right),\n  \\end{align*}\n  where we used~\\eqref{eq:fem-aposteriori:1}\n  and~\\eqref{eq:fem-aposteriori:2} in the end. Observing that both\n  sums extend over finitely many vertices and that by local\n  quasi-uniformity we can bound the diameter of\n  $\\diam({\\domain_{\\vertex_i}})$ by that of $\\cell$, namely\n  $\\diam({\\domain_{\\vertex_i}}) \\le c h_\\cell$, we obtain the estimate\n  in $L^2(\\cell)$. For the estimate in $H^1(\\cell)$, we observe that\n  the mean value calculation is a continuous operation on\n  $H^1_0(\\domain(\\vertex_i))$, and that~\\eqref{eq:fem-aposteriori:3} as a finite\n  sum is continuous, therefore,\n  \\begin{gather}\n    \\snorm{u-\\overline I_h u}_{1;\\cell} \\le \\norm{\\nabla u}_{\\cell} +\n    \\norm{\\nabla \\overline I_h u}_{\\cell}\n    \\le c \\norm{\\nabla u}_{\\domain(\\cell)}.\n  \\end{gather}\n  Finally, we use the trace estimate for $u\\in H^1(\\cell)$\n  \\begin{gather}\n    \\norm{u}_F\n    \\le c \\left(h^{-\\nicefrac12} \\norm{u}_\\cell\n      +h^{\\nicefrac12} \\norm{\\nabla u}_\\cell\\right),\n  \\end{gather}\n  to obtain the estimate on the edge.\n\\end{proof}\n\n\\begin{Theorem*}{scott-zhang}{Scott-Zhang quasi-interpolation}\n  Let $\\{\\mesh_h\\}$ be a locally quasi-uniform family of meshes with\n  piecewise polynomial finite element spaces\n  $V_h\\subset H^1(\\domain)$. Then, there exist bounded operators\n  $\\overline I_h\\colon H^1(\\domain) \\to V_h$ such that for every\n  function $u\\in H^1(\\domain)$, every mesh cell $\\cell$, every face\n  $F$, and for $m=0,1$ there holds\n  \\begin{align}\n    \\norm{u-\\overline I_h u}_{m;T} &\\le c h_\\cell^{1-m} \\snorm{u}_{1;\\domain_\\cell} \\\\\n    \\norm{u-\\overline I_h u}_{0;F} &\\le c h_\\cell^{\\nicefrac{1}{2}} \\snorm{u}_{1;\\domain_\\cell},\n  \\end{align}\n  and $\\overline I_h u$ is a quasi-interpolation on the boundary $\\d\\domain$.\n\\end{Theorem*}\n\n\\begin{Theorem*}{schoeberl-interpolation}{Schöberl quasi-interpolation}\n  Let $\\{\\mesh_h\\}$ be a locally quasi-uniform family of meshes with\n  piecewise polynomial finite element spaces\n  $V_h\\subset H^1(\\domain)$. Then, there exist bounded\n  \\emph{projection} operators\n  $\\overline I_h\\colon H^1(\\domain) \\to V_h$ such that for every\n  function $u\\in H^1(\\domain)$, every mesh cell $\\cell$, every face\n  $F$, and for $m=0,1$ there holds\n  \\begin{align}\n    \\norm{u-\\overline I_h u}_{m;T} &\\le c h_\\cell^{1-m} \\snorm{u}_{1;\\domain_\\cell} \\\\\n    \\norm{u-\\overline I_h u}_{0;F} &\\le c h_\\cell^{\\nicefrac{1}{2}} \\snorm{u}_{1;\\domain_\\cell}.\n  \\end{align}  \n\\end{Theorem*}\n\n\\begin{Definition}{residual}\n  Let $a(u,v) = f(v)$ be the weak formulation of a BVP on the space\n  $V$.  Then, we define the \\define{residual}\n\\begin{gather}\n  \\begin{split}\n    R\\colon V &\\to V^* \\\\\n    w&\\mapsto f(\\cdot) - a(w,\\cdot).\n  \\end{split}\n\\end{gather}\n\\end{Definition}\n\\begin{Lemma}{residual-hm1}\n  For $u\\in V=H^1_0(\\domain)$ solution to Poisson's equation and any\n  other function $w\\in V$, there holds\n  \\begin{gather}\n    \\snorm{u-v}_1 = \\norm{R v}_{-1}\n    := \\sup_{w\\in V} \\frac{\\left<R v,w\\right>}{\\snorm{w}_1}.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  We have\n  \\begin{gather}\n    \\left<Rv,w\\right>\n    = f(w) - a(v,w)\n    = a(u-v,w).\n  \\end{gather}\n  Since $a(.,.)$ is s.p.d., we can apply Cauchy-Schwarz to obtain the result.\n\\end{proof}\n\n\\begin{Definition}{mvl-jmp}\n  Let $u$ be a piecewise continuous function on a mesh $\\mesh$. On a\n  face $F$ between two cells $\\cell_1$ and $\\cell_2$, we define the\n  \\define{mean value operator}\n  \\begin{gather}\n    \\mvl{u}(\\vx) = \\frac{u_1(\\vx) + u_2(\\vx)}2\n    = \\lim_{\\epsilon\\searrow 0}\n    \\frac{u(\\vx-\\epsilon \\n_1) + u(\\vx - \\epsilon\\n_2)}2,\n  \\end{gather}\n  where $\\n_i$ are the outer normal vectors of the two cells. The\n  \\define{jump operator} is\n  \\begin{gather}\n    \\mvl{u\\n} = \\frac{(u_1-u_2)\\n_1}2 = \\frac{(u_2-u_1)\\n_2}2.\n  \\end{gather}\n\\end{Definition}\n\\begin{Definition}{residual-strong}\n  Let $u\\in V=H^1_0(\\domain)$ be the solution to Poisson's equation\n  and let $u_h\\in V_h$ be a finite element function.  The strong form\n  of the residual is\n  \\begin{gather}\n    \\left<Rv,w\\right> = \\sum_{\\cell\\in\\mesh_h}\\int_{\\cell} r_\\cell(u_h) w\\dvx\n    - \\sum_{F\\in \\mathbb F_h^i} 2\\mvl{\\n\\cdot\\nabla u_h} w\\ds,\n  \\end{gather}\n  where\n  \\begin{gather}\n    r_\\cell(u_h) = f + \\Delta u_h.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Lemma}{residual-upper-bound}\n  Let $\\mesh_h$ be a locally quasi-uniform mesh.\n  There is a constant $c>0$ such that the error between the true\n  solution $u\\in V=H^1_0(\\domain)$ and the finite element solution\n  $u_h\\in V_h \\subset V$ is bounded by\n  \\begin{gather}\n    \\label{eq:fem-aposteriori:5}\n    \\snorm{u-u_h}_{1;\\mesh_h} \\le c \\left(\n      \\sum_{\\cell\\in\\mesh_h} h_\\cell^2 \\norm{r_\\cell(u_h)}_\\cell^2\n      + \\sum_{F\\in \\mathbb F_h^i} h_F\n      \\norm{\\mvl{\\n\\cdot\\nabla u_h}}_F^2\n    \\right)^{\\nicefrac12}.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  We begin with the equivalence of error in $V$ and residual in\n  $V^*$. For the residual, there holds Galerkin orthogonality, such\n  that we obtain\n  \\begin{gather}\n    \\label{eq:fem-aposteriori:4}\n    \\snorm{u-u_h}_1\n    = \\sup_{w\\in V}\\frac{\\left<Ru_h,w\\right>}{\\snorm{w}_1}\n    = \\sup_{w\\in V}\\frac{\\left<Ru_h,w- \\overline I_h w\\right>}{\\snorm{w}_1}.\n  \\end{gather}\n  Using the strong form and the quasi-interpolation $\\overline I_h$,\n  we get\n  \\begin{align*}\n    \\left<Ru_h,w\\right>\n    &= \\sum_{\\cell\\in\\mesh_h}\\int_{\\cell} r_\\cell(u_h) (w-\\overline I_h w)\\dvx\n    - \\sum_{F\\in \\mathbb F_h^i} 2\\mvl{\\n\\cdot\\nabla u_h} (w-\\overline I_h w)\\ds\n    \\\\\n    & \\le \\sum_{\\cell\\in\\mesh_h} \\norm{r_\\cell(u_h)}_\\cell\n      \\norm{w-\\overline I_h w}_\\cell\n      + \\sum_{F\\in \\mathbb F_h^i} \\norm{\\mvl{\\n\\cdot\\nabla u_h}}_\\cell\n      \\norm{w-\\overline I_h w}_\\cell\n      \\\\\n    & \\le c_1 \\sum_{\\cell\\in\\mesh_h} h_\\cell\n      \\norm{r_\\cell(u_h)}_\\cell\n      \\norm{\\nabla w}_{\\domain_\\cell}\n      + c_2 \\sum_{F\\in \\mathbb F_h^i} h_E^{\\nicefrac12}\n      \\norm{\\mvl{\\n\\cdot\\nabla u_h}}_\\cell\n      \\norm{\\nabla w}_{\\domain_\\cell}\n  \\end{align*}\n  Applying Hölder inequality, we obtain for the first term\n  \\begin{gather*}\n    \\sum_{\\cell\\in\\mesh_h} h_\\cell\n    \\norm{r_\\cell(u_h)}_\\cell\n    \\norm{\\nabla w}_{\\domain_\\cell}\n    \\le\n    \\left(\\sum_{\\cell\\in\\mesh_h} h_\\cell^2\n    \\norm{r_\\cell(u_h)}_\\cell^2\\right)^{\\nicefrac12}\n  \\left(\\sum_{\\cell\\in\\mesh_h} \\norm{\\nabla w}_{\\domain_\\cell}^2\n  \\right)^{\\nicefrac12},\n  \\end{gather*}\n  and similar for the second term. Both contain a term of the form\n  \\begin{gather*}\n    \\sum_{\\cell\\in\\mesh_h} \\norm{\\nabla w}_{\\domain_\\cell}^2\n    = \\sum_{\\cell\\in\\mesh_h} \\sum_{\\cell'\\in\\mesh_\\cell}\\norm{\\nabla w}_{\\cell'}^2\n    \\le n \\norm{\\nabla w}_{\\domain}^2,\n  \\end{gather*}\n  where $n$ is the maximal number of occurrences of a cell $\\cell'$ in\n  the double sum. This $n$ is bounded uniformly on shape regular\n  family of meshes, since shape regularity prohibits degeneration of\n  cells. Therefore, we conclude\n  \\begin{align*}\n    \\left<Ru_h,w\\right>\n    & \\le c \\left(\\sum_{\\cell\\in\\mesh_h} h_\\cell^2\n      \\norm{r_\\cell(u_h)}_\\cell^2 +\n      \\sum_{F\\in \\mathbb F_h^i} h_E\n      \\norm{\\mvl{\\n\\cdot\\nabla u_h}}_\\cell^2\\right)^{\\nicefrac12}\n      \\snorm{w}_{1;\\domain}.\n  \\end{align*}\n  Entering into~\\eqref{eq:fem-aposteriori:4} yields the proposition.\n\\end{proof}\n\n\\begin{remark}\n  The constant $c$ in the previous theorem depends on the constant in\n  the quasi-interpolation estimate, which in turn was derived using\n  Poincaré and trace inequalities. Traditionally, both are derived\n  using indirect arguments, but a constructive proof with computable\n  bounds is possible. For details, see~\\cite[Chapter\n  3]{Verfuerth13}. There still remains the question, whether these\n  bounds are sufficiently sharp to be applicable in practice.\n\\end{remark}\n\n\\begin{Definition}{osc}\n  For a function $f\\in L^2(\\domain)$, we define the cell-wise average\n  \\begin{gather}\n    \\overline f(\\vx) = \\frac1{\\abs{\\cell}}\\int_\\cell f \\dvx\n    \\qquad\\vx\\in\\cell, \\quad\\cell\\in\\mesh_h,\n  \\end{gather}\n  and the \\define{data oscillation}\n  \\begin{gather}\n    \\operatorname{osc}_\\cell f = \\norm{f-\\overline f}_\\cell.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Definition}{residual-estimator}\n  The residual based error estimator for the finite element method for\n  Poisson's equation on a mesh $\\mesh$ is defined as\n  \\begin{gather}\n    \\eta_{h}(u_h) = \\sum_{\\cell\\in\\mesh} \\eta_{\\cell}(u_h),\n  \\end{gather}\n  where\n  \\begin{gather}\n    \\eta_{\\cell}(u_h)^2 = h_{\\cell}^2 \\norm{\\overline f + \\Delta u_h}_\\cell^2\n    + \\frac12 \\sum_{F\\subset \\d\\cell} h_F\\norm{\\mvl{n\\cdot\\nabla u_h}}_E^2.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Theorem}{residual-estimate}\n  There holds with positive constants $c_1$ and $c_2$\n  \\begin{align}\n    \\label{eq:fem-aposteriori:6}\n    c_1 \\snorm{u-u_h}_1^2\n    &\\le \\eta_{h}(u_h)^2\n      + \\sum_{\\cell\\in\\mesh_h} h^2_\\cell\\operatorname{osc}_\\cell^2 f\n    \\\\\n    \\label{eq:fem-aposteriori:7}\n    c_2 \\,\\eta_\\cell^2(u_h)\n    &\\le \\snorm{u-u_h}_{1;\\domain_{\\cell}}^2\n      + \\sum_{\\cell\\in\\mesh_\\cell} h^2_\\cell\\operatorname{osc}_\\cell^2 f\n  \\end{align}\n\\end{Theorem}\n\n\\begin{proof}\n  Note that the right hand side of the\n  estimate~\\eqref{eq:fem-aposteriori:5} in\n  \\slideref{Lemma}{residual-upper-bound} differs from the estimator\n  $\\eta_h(u_h)$ only by the replacement of $f$ by $\\overline\n  f$. Therefore, we can start the proof of this lemma by\n  changing~\\eqref{eq:fem-aposteriori:4} to\n  \\begin{gather}\n    \\snorm{u-u_h}_1\n    = \\sup_{w\\in V}\\frac{\\left<Ru_h,w\\right>}{\\snorm{w}_1}\n    = \\sup_{w\\in V}\\frac{\\left<\\overline Ru_h,w\\right> + \\form(f-\\overline f, w)}{\\snorm{w}_1},\n  \\end{gather}\n  where we ad hoc defined $\\overline R$ like $R$, but replacing\n  $r_\\cell = f+\\nabla u_h$ by $\\overline f + \\nabla u_h$. Due to\n  equality, we can still subtract the quasi-interpolant of $w$ and\n  continue through the whole proof. What remains is the estimate\n  \\begin{gather}\n    \\label{eq:fem-aposteriori:8}\n    \\form(f-\\overline f, w - \\overline I_h w)\n    \\le c \\sum_{\\cell\\in\\mesh} h_\\cell \\norm{f-\\overline f}_{\\cell} \\norm{\\nabla w}_{\\domain_\\cell}\n    \\le c \\left(\\sum_{\\cell\\in\\mesh} h_\\cell \\norm{f-\\overline f}_{\\cell}\\right)^{\\nicefrac12}\n      \\snorm{w}_{1;\\domain},\n    \\end{gather}\n    which is proven by Hölder inequality and the boundedness of the\n    number of cells in $\\mesh_\\cell$. Thus, the upper\n    bound~\\eqref{eq:fem-aposteriori:6} is an immediate consequence of\n    \\slideref{Lemma}{residual-upper-bound}.\n    \n    Note: the proof for the lower bound is for linear elements\n    only. It can be generalized to higher order by generalizing the\n    bubble functions below, which is mostly technical.\n    \n    We observe that the lower bound is local, that is, the estimate on\n    each cell $\\cell$ is bounded from above by the error on the halo\n    $\\domain_\\cell$. Therefore, we start by constructing test\n    functions with support on a cell. On a simplex, we define the\n    \\define{bubble function} in terms of \\putindex{barycentric coordinates}\n    \\begin{gather}\n      \\label{eq:bubble-simplex}\n      B_\\cell = \\frac1{(d+1)^{d+1}}\\lambda_0\\lambda_1\\dots\\lambda_d,\n    \\end{gather}\n    while on the reference hypercube $(0,1)^d$ we let\n    \\begin{gather}\n      \\label{eq:bubble-tensor}\n      \\reference B_\\cell(\\refvx) = b(\\refx_1)b(\\refx_2)\\dots b(\\refx_d)\n      \\qquad b(x) = 4 x(1-x).\n    \\end{gather}\n    Both share the following properties: they vanish on $\\d\\cell$,\n    they are positive inside $\\cell$, and $\\max B_\\cell=1$. From\n    positivity, we deduce the existence of a constant $c$ depending on\n    shape regularity and the shape function space $\\shapespace(\\cell)$, such that\n    \\begin{gather}\n      \\int_\\cell p^2 B_\\cell \\dvx \\ge c \\norm{p}_\\cell^2\n      \\qquad\\forall p\\in \\shapespace(\\cell).\n    \\end{gather}\n    Furthermore, $B_\\cell$ is polynomial, such that the inverse estimate holds.\n\n    Choose now the test function\n    $w_\\cell = (\\overline f + \\Delta u_h) B_\\cell$. Since it vanishes\n    on the boundary and outside of $\\cell$, the strong and weak form\n    of the residual reduce to\n    \\begin{gather}\n      \\int_\\cell r_\\cell(u_h) w_\\cell \\dvx = \\int_\\cell \\nabla(u-u_h)\\cdot\\nabla w_\\cell \\dvx.\n    \\end{gather}\n    Adding the difference of $f$ and $\\overline f$ on both sides yields\n    \\begin{gather}\n      \\int_\\cell (\\overline f+\\Delta u_h)^2 B_\\cell \\dvx\n      =\\int_\\cell \\nabla(u-u_h)\\cdot\\nabla w_\\cell \\dvx\n      + \\int_\\cell (\\overline f - f) w_\\cell \\dvx.\n    \\end{gather}\n    On the left, we estimate\n    \\begin{gather}\n      c \\norm{\\overline f + \\Delta u_h}_\\cell^2 \\le \\int_\\cell (\\overline f+\\Delta u_h)^2 B_\\cell \\dvx.\n    \\end{gather}\n    On the right, we estimate the residual term by\n    \\begin{align*}\n      \\int_\\cell \\nabla(u-u_h)\\cdot\\nabla w_\\cell \\dvx\n      & \\le \\snorm{u-u_h}_{1;\\cell} \\,\\snorm{w_\\cell}_{1;\\cell}\n      \\\\\n      & \\le c \\snorm{u-u_h}_{1;\\cell} \\, h_\\cell^{-1} \\norm{\\overline f + \\Delta u_h}_\\cell.\n    \\end{align*}\n    The data oscillation is estimated in a straightforward way by\n    \\begin{align*}\n      \\int_\\cell (\\overline f-f) w_\\cell \\dvx\n      &\\le \\operatorname{osc}_\\cell f \\norm{\\overline f+\\Delta u_h}_\\cell\n    \\end{align*}\n    Combining these three estimates yields\n    \\begin{gather}\n      \\label{eq:fem-aposteriori:9}\n      c \\norm{\\overline f+\\Delta u_h}_\\cell\n      \\le h_\\cell^{-1} \\snorm{u-u_h}_{1;\\cell}\n      + \\operatorname{osc}_\\cell f,\n    \\end{gather}\n    which is the desired estimate for the cell term of the estimator\n    $\\eta_{\\cell}(u_h)$ if we multiply by $h_\\cell$.\n\n    The estimate for the face term is similar, using a bubble function\n    for the face. Since this functon is nonzero on the face, its\n    support extends over two mesh cells. On simplicial cells, it is\n    constructed like the cell bubble in\n    equation~\\eqref{eq:bubble-simplex}, but extending the product only\n    over indices of vertices on the face. Therefore, it is a\n    polynomial of degree $d-1$ on the face and also in the interior of\n    each cell. For hypercubes, it is the product of the quadratic\n    polynomials $b(x)$ of variables on the face times a linear\n    function decaying linearly from 1 to zero. Again, we normalize\n    such that the maximum equals 1. Choosing\\footnote{For linear\n      elements, the derivative on the face is constant and thus this\n      definition is obvious. For higher order polynomials, we need a\n      an extension from the face into the interior, which can be\n      obtained from the barycentric coordinates or the tensor product\n      structure.} $w_F = 2\\mvl{\\n\\cdot\\nabla u_h}_F B_F$, we obtain\n    \\begin{align*}\n      c\\norm{\\mvl{\\n\\cdot\\nabla u_h}}_F^2\n      &\\le \\int_F \\mvl{\\n\\cdot\\nabla u_h}^2 B_F \\ds\n      \\\\&= \\int_F \\mvl{\\n\\cdot\\nabla u_h} w_F \\ds\n      \\\\&= \\sum_{\\cell\\in\\mesh_F} \\int_\\cell r_\\cell w_F \\dvx - \\left<R,w_F\\right>\n      \\\\&= \\sum_{\\cell\\in\\mesh_F} \\int_\\cell r_\\cell w_F \\dvx\n      - \\int_{\\domain_F} \\nabla (u-u_h)\\cdot\\nabla w_F \\dvx\n      \\\\&= \\sum_{\\cell\\in\\mesh_F} \\int_\\cell (\\overline f + \\Delta u_h) w_F \\dvx\n      - \\int_{\\domain_F} \\nabla (u-u_h)\\cdot\\nabla w_F \\dvx\n      + \\sum_{\\cell\\in\\mesh_F} \\int_\\cell (\\overline f - f)w_F \\dvx.\n    \\end{align*}\n    Again, we estimate the three terms on the right hand side\n    separately. For the first, we estimate the norm of $w_F$ by its\n    trace on the edge $F$. From the already proven estimate for the\n    cell residual~\\eqref{eq:fem-aposteriori:9}, we obtain\n    \\begin{align*}\n      \\sum_{\\cell\\in\\mesh_F} \\int_\\cell (\\overline f + \\Delta u_h) w_F \\dvx\n      & \\le \\sum_{\\cell\\in\\mesh_F} \\norm{\\overline f + \\Delta u_h}_\\cell\n        \\,\\norm{w_F}_{\\cell}\n      \\\\&\\le \\sum_{\\cell\\in\\mesh_F} \\norm{\\overline f + \\Delta u_h}_\\cell\n      \\,c h_F^{\\nicefrac12} \\norm{\\mvl{\\n\\cdot\\nabla u_h}}_F\n      \\\\&\\le \n      + c  \\sum_{\\cell\\in\\mesh_F} \\left(h_F^{-\\nicefrac12} \\snorm{u-u_h}_{1;\\cell}\n      + h_F^{\\nicefrac12}\\operatorname{osc}_{\\cell} f\\right)\\norm{\\mvl{\\n\\cdot\\nabla u_h}}_F\n    \\end{align*}\n    Similarly, the inverse estimate for $w_F$ yields\n    \\begin{align*}\n      \\int_{\\domain_F} \\nabla (u-u_h)\\cdot\\nabla w_F \\dvx\n      &\\le \\snorm{u-u_h}_{1;\\domain_F} \\norm{\\nabla w_F}_{\\domain_F}\n      \\\\&\\le \\snorm{u-u_h}_{1;\\domain_F}\n      \\,c h_F^{-\\nicefrac12}\\norm{\\mvl{\\n\\cdot\\nabla u_h}}_F.\n    \\end{align*}\n    Finally, the data oscillation terms becomes\n    \\begin{align*}\n      \\sum_{\\cell\\in\\mesh_F} \\int_\\cell (\\overline f - f)w_F \\dvx\n      &\\le \\sum_{\\cell\\in\\mesh_F} \\norm{\\overline f - f}_\\cell \\norm{w_F}_\\cell\n      \\\\&\\le \\sum_{\\cell\\in\\mesh_F} \\norm{\\overline f - f}_\\cell\n      \\,c h_F^{\\nicefrac12}\\norm{\\mvl{\\n\\cdot\\nabla u_h}}_F.\n    \\end{align*}\n    Summing and scaling with $h_F^{\\nicefrac12}$ yields the result.\n\\end{proof}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End: \n", "meta": {"hexsha": "9b4cb43e84714509b69dce805fdd4e7a439cd43f", "size": 22094, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "fem/fem-aposteriori.tex", "max_stars_repo_name": "ahumanita/notes", "max_stars_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fem/fem-aposteriori.tex", "max_issues_repo_name": "ahumanita/notes", "max_issues_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-05-24T07:31:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-31T12:58:14.000Z", "max_forks_repo_path": "fem/fem-aposteriori.tex", "max_forks_repo_name": "ahumanita/notes", "max_forks_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-05-15T19:28:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-05T19:07:29.000Z", "avg_line_length": 42.0838095238, "max_line_length": 103, "alphanum_fraction": 0.66158233, "num_tokens": 7820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387914176259, "lm_q2_score": 0.8791467754256017, "lm_q1q2_score": 0.7287588655000012}}
{"text": "\\lab{Applications}{Applications of the Pseudo-Inverse}{Pseudo-Inverse Applications}\n\n\\objective{This section explains a few applications of the Moore-Penrose inverse, including least squares problems, norm-minimization problems and the condition number.}\n\nThe pseudo-inverse is a useful generalization for a variety of applications. The first we will consider is least squares and norm-minimization problems.\n\nConsider the system\n\\[\nAx = b\n\\]\n\n$A$ need not be full rank. It may be either over or under-determined. How do we come up with a ``good'' solution to this system? In the case where the system is over-determined, we can use least squares to find the solution that minimizes $\\norm{Ax^* - b}_2$. In the case where $A$ is under-determined there may be an infinite number of solutions. Assuming that there is a solution, we will search for the solution that minimizes the norm of the solution, or in other words we will minimize $\\norm{x^*}_2$ subject to $Ax-b = 0$.\n\nAmazingly, the pseudo-inverse solves both of these problems. We will offer a brief proof. First, for ease of notation, let $P = A A^\\dagger$. Note that $PA = A$ and $P = P^*$. We also denote $z = A^\\dagger b$. Using these facts we can show that:\n\\begin{align*}\nA^*(Az-b) &= A^*(A A^\\dagger b - b) \\\\\n&= A^*P b - A^* b \\\\\n&= (PA)^* b - A^* b \\\\\n&= 0\n\\end{align*}\n\nThen we can use the parallelogram law to show that:\n\n\\begin{align*}\n\\norm{Ax-b}_2^2 &= \\norm{Ax + Az-Az-b}_2^2 \\\\\n&= \\norm{Az-b}_2^2 + (A(x-z))^*(Az-b) + \\left((A(x-z))^*(Az-b)\\right)^* + \\norm{A(x-z)}_2^2 \\\\\n&= \\norm{Az-b}_2^2 + ((x-z)^*A^*(Az-b) + \\left(((x-z)^*A^*(Az-b)\\right)^* + \\norm{A(x-z)}_2^2 \\\\\n&= \\norm{Az-b}_2^2 + \\norm{A(x-z)}_2^2 \\\\\n&\\geq \\norm{Az-b}_2^2\n\\end{align*}\n\nThus, $z$ is the least squares solution.\n%I thought I saw this proof somewhere else in the book - is it in here twice?\n\\begin{problem}\nSuppose that $A$ is under-determined and that $Ax = b$ has a solution (i.e. is staisfiable). Use the same steps as we used for the least squares solution to prove that $z = A^\\dagger b$ is the minimum norm solution. For the first step, show that expression $z^*(x-z) = 0$. For the second step use the parallelogram rule on $\\norm{x -z +z}_2^2$.\n\\end{problem}\n\n{\\bf Here a good problem involving finding the minimum-norm solution of something would be perfect. Do you have any suggestions?}\n\n\\subsection*{Condition Number}\n\nSuppose that we have the equation:\n\\[\nAx= b\n\\]\nNow suppose that we have an approximate solution, namely we have $\\tilde{x}$ such that $\\norm{A\\tilde{x} -b}$ is small. Does this imply that $\\norm{x-\\tilde{x}}$ is small? This is not always the case. Consider, for example, the system:\n\\[\n\\begin{pmatrix}\n2 & 1\\\\\n4 & 2.1 \\\\\n\\end{pmatrix} x = \n\\begin{pmatrix}\n3 \\\\\n6.01\\\\\n\\end{pmatrix}\n\\]\n\nThis system has the unique solution $x = [1~1]^T$. However, the vector $\\tilde{x} = [1.5~0]^T$ has a very small solution error since $\\norm{Ax-A\\tilde{x}} = .01$, but the difference betwen $[1~1]$ and $[1.5~0]$ is pretty significant. This is an example of what is called an ill-conditioned matrix. The issue in this case, is that the matrix $A$ maps two vectors that are relatively far apart (namely $x$ and $\\tilde{x}$) to vectors that are close together.\n\nThis issue becomes very important when we're dealing with floating point arithmetic. It isn't hard to imagine that in finite precision arithmetic it might be reasonable to say that $\\tilde{x}$ is a solution to the linear equation above, while it is actually very different from the real solution. We note that in this case rounding errors are not to blame! The matrix itself is to blame.\n\nWe quantify this behavior with what is called the condition number of a matrix. The condition number, informally, represents the amount that the solution $x$ of the equation $Ax = b$ changes with respect to $b$. Therefore a large condition number implies that a small error in $b$ (from either measurement error, or floating point arithmetic) can yield a large error in the solution $x$. We can calculate the condition number of a matrix using the following equality:\n\\[\nk(A) = \\norm{A} \\norm{A^\\dagger}\n\\]\nWhere $k(A)$ represents the condition number of the of matrix $A$. In this case, the choice of norm isn't important. What we are  doing when we change norms is really change the interpretation of the condition number (i.e. what we are using to measure changes in $b$ and $x$)\\footnote{The fact that $A^\\dagger$ is not continuous can be problematic for the calculation above, but we are not going to treat that problem here}.\n\nFor example, in Python we can calculate the condition number of the above matrix using the following code:\n\n\n\\begin{lstlisting}[style=python]\nA = sp.array([[2,1],[4,2.01]])\nla.norm(A)*la.norm(la.pinv(A))\n\\end{lstlisting}\n\nThe error that we had in our example was\n\n\\[\n\\frac{\\norm{[.5, -1]}}{\\norm{[0, .01]}} = 111.8\n\\]\n\nWhich is a whole order of magnitude smaller than the condition number. This implies that the matrix $A$ could give solutions ten times ``worse'' than it did in our example.\n\nNote that Python has a \\li{np.linalg.cond} function to calculate the condition number of a matrix. You can verify that the output is the same for the example that we just showed. Also, Volume II offers a more in-depth discussion of conditioning.\n\n\\begin{problem}\nAn $n \\times n$ Hilbert Matrix is a matrix with the following entries:\n\\[\nH_{ij} = \\frac{1}{i + j -1}\n\\]\n\nThis matrix arises in least-squares polynomial approximation. This matrix is also a canonical example of an ill-conditioned matrix. Write a function that accepts $n$ as an argument and calculates the condition number of the n-th Hilbert Matrix. Plot the growth of the condition number with respect to $n$. What conclusion can you draw about using this type of matrix? %What should be the range of n on our plot?\n\\end{problem}", "meta": {"hexsha": "bf09adc3d8214a83e46051702e1143e454de764c", "size": 5832, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/MoorePenrose/MPApp.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/MoorePenrose/MPApp.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/MoorePenrose/MPApp.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-21T23:06:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-21T23:06:27.000Z", "avg_line_length": 62.7096774194, "max_line_length": 528, "alphanum_fraction": 0.7229080933, "num_tokens": 1615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.9073122301325987, "lm_q1q2_score": 0.7287294083566459}}
{"text": "\\chapter{Relativistic spin-0 particles}\n\\section{The Klein-Gordon equation}\nThe Schr{\\\"o}dinger equation is the quantum mechanical equivalent of the classical $E = p^2/2m$. Now we want a relativistic version. Start from the relationship between energy, momentum, and mass,\n\\begin{equation}\nE^2 - p^2 = m^2.\n\\end{equation}\nReplacing the appropriate values with operators,\n\\begin{equation*}\nE \\rightarrow i \\pdv{t}, \\quad p \\rightarrow -i \\vec{\\nabla}\n\\end{equation*}\nand applying them to some general wavefunction,\n\\begin{equation}\n\\left( -\\pdv[2]{t} + \\nabla^2 \\right)\\psi = m^2 \\psi.\n\\end{equation}\nRearranging and using equation \\eqref{eq:nablaSquared} gives the Klein-Gordon equation\n\\begin{equation}\\boxed{\n\\left( \\partial^2 + m^2 \\right)\\psi = 0\\label{eq:KleinGordon}\n}.\n\\end{equation}\nThis is the fully relativistic equation of motion for spin-0 particles.\n\n\\subsection{4-current density}\nWe now wish to derive the probability 4-current from the Klein-Gordon equation. Taking the complex conjugate of \\eqref{eq:KleinGordon} and multiplying by $\\psi$ gives\n\\begin{equation}\n\\psi \\left( \\partial^2 + m^2 \\right)\\psi^* = 0\\label{eq:KG1}.\n\\end{equation}\nSimilarly, multiplying \\eqref{eq:KleinGordon} by $\\psi^*$ gives\n\\begin{equation}\n\\psi^* \\left( \\partial^2 + m^2 \\right)\\psi = 0\\label{eq:KG2}.\n\\end{equation}\nSubtracting \\eqref{eq:KG1} from \\eqref{eq:KG2} and multiplying by $i$,\n\\begin{align}\ni\\psi^*\\partial^2\\psi - i\\psi\\partial^2\\psi^* = 0 \\\\\n\\Rightarrow\\quad \\pdv{t} \\left( i\\psi^*\\pdv{\\psi}{t} - i\\pdv{\\psi^*}{t}\\psi \\right) - \\vec{\\nabla}\\cdot\\left( i\\psi^* \\vec{\\nabla}\\psi - i(\\vec{\\nabla}\\psi)\\psi^* \\right) = 0\n\\end{align}\nThis result is a continuity equation,\n\\begin{equation}\n\\partial_\\mu j^\\mu = 0\n\\end{equation}\nfor the 4-current density\n\\begin{equation}\nj^\\mu = i\\psi^* \\partial^\\mu \\psi - i\\psi \\partial^\\mu \\psi^*\n\\end{equation}\n\n\\subsection{Application to a plane wave}\nConsider a particle with wavefunction $\\phi = \\mathcal{N}e^{-iPX}$. Applying the above definition of 4-current density gives the values\n\\begin{align}\n\\rho = j^0 = 2\\abs{\\mathcal{N}}^2 \\, E  \\\\\n\\vec{j} = 2\\abs{\\mathcal{N}}^2 \\, \\vec{p}.\n\\end{align}\nThat $\\rho$ is proportional to $E$ is to be expected. Under a Lorentz boost the volume element transforms as\n\\begin{equation*}\n\\dd[3]{\\vec{x}} \\rightarrow \\frac{\\dd[3]{\\vec{x}}}{\\gamma}\n\\end{equation*}\nso in order to preserve $\\rho \\dd[3]{\\vec{x}}$, $\\rho$ must transform as $\\rho\\rightarrow \\gamma\\rho$, in the same way energy does.\n\nIf the covariant nomalization to $2E$ particles per unit volume is used, the result is that $\\rho = 1$.\n\n\\section{Negative energy particles and the Fenyman-Stueckelberg interpretation}\nFor the Klein-Gordon equation to be an accurate description of spin-0 particles, it should be able to describe antiparticles. Indeed, the Klein-Gordon equation does allow for particles with negative energy, i.e.~the negative solution of\n\\begin{equation}\nE_\\pm = \\pm\\sqrt{p^2 + m^2}.\n\\end{equation}\nThere are some problems associated with this. Firstly, the existence of negative energy states means that the energy of a particle can always be lowered. Secondly, the $E_-$ solutions are associated with a negative probability density $\\rho$, which doesn't make sense and is not allowed.\n\nPauli and Weisskopf showed that it is possible to have a negative energy solution of the Klein-Gordon equation if the scalar electron charge $-e$ is included in $j^\\mu$ and it is interpreted as a charge-current density,\n\\begin{equation}\nj^\\mu = -ie\\left(\\psi^* \\partial^\\mu \\psi - i\\psi \\partial^\\mu \\psi^*\\right).\n\\end{equation}\nNow $\\rho=j^0$ represents the charge density which is allowed to be negative.\n\nNow that the theory has been fixed to allow the $E_-$ particles, we need an interpretation for them. The Feynman-Stueckelberg interpretation states that the negative energy states correspond to antiparticles. Consider the 4-charge-current of a scalar electron with a plane wavefunction,\n\\begin{equation}\nj^\\mu (\\Pelectron) = -2e\\abs{\\mathcal{N}}^2\\, \\mqty(E \\\\ \\vec{p}).\n\\end{equation}\nIn the same way, a positron has the current\n\\begin{align}\nj^\\mu (\\Ppositron) &= 2e\\abs{\\mathcal{N}}^2\\, \\mqty(E \\\\ \\vec{p})\\\\\n&= -2e\\abs{\\mathcal{N}}^2\\, \\mqty(-E \\\\ -\\vec{p}).\n\\end{align}\nThis is the same as for an electron with $-E$, $-\\vec{p}$. So far as a system is concerned, the emission of a positron with energy $E$ is the same as the absorption of an electron with energy $-E$. In other words, positive-energy antiparticles travelling forwards in time are negative-energy particles travelling backwards in time. This gives the $E_-$ solutions an interpretation.\n", "meta": {"hexsha": "e2ee615fbf0c8294f810b14684dca3ee94756c14", "size": 4615, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/6_Relativistic_spin-0_particles.tex", "max_stars_repo_name": "adambozson/Standard-Model-I", "max_stars_repo_head_hexsha": "9ea0d388c93f21d1c636ee18c9210a1b91169308", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/6_Relativistic_spin-0_particles.tex", "max_issues_repo_name": "adambozson/Standard-Model-I", "max_issues_repo_head_hexsha": "9ea0d388c93f21d1c636ee18c9210a1b91169308", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/6_Relativistic_spin-0_particles.tex", "max_forks_repo_name": "adambozson/Standard-Model-I", "max_forks_repo_head_hexsha": "9ea0d388c93f21d1c636ee18c9210a1b91169308", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.2804878049, "max_line_length": 381, "alphanum_fraction": 0.7282773564, "num_tokens": 1437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668095, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7287189186529225}}
{"text": "\\documentclass{homework}\n\\course{Math 5522H}\n\\author{Jim Fowler}\n\\input{preamble}\n\n\\begin{document}\n\\maketitle\n\n\\begin{inspiration}\nLe plus court chemin entre deux v\\'erit\\'es dans le domaine r\\'eel passe par le domaine complexe.\n%The shortest path between two truths in the real domain passes through the complex domain.\n\\byline{Jacques Hadamard}\n\\end{inspiration}\n\n\\section{Terminology}\n\n\\begin{problem}\n  Define $\\C$.  (How many ``different'' definitions do you know?)\n\\end{problem}\n\n\\begin{problem}\n  Define $\\conj{z}$ and $\\abs{z}$ for $z \\in \\C$.\n\\end{problem}\n\n\\begin{problem}\n  For complex numbers $z, w \\in \\C$, what do we mean by $z^w$ ?\n\\end{problem}\n\n\\section{Numericals}\n\n\\begin{problem}\n  Apply \\textbf{partial fractions} to write $\\displaystyle\\frac{1}{1-z^4}$ as a sum of terms of the form $\\displaystyle\\frac{A}{Bz + C}$.\n\\end{problem}\n\n\\begin{problem}\n  Find $a, b, z \\in \\C$ so that $\\left(z^a\\right)^b \\neq z^{\\left(ab\\right)}$.\n\\end{problem}\n\n\\begin{problem}\n  We will often see \\textbf{roots of unity}.  To practice computing with such objects, let\n  \\[\n    \\zeta := \\cos \\left( \\frac{2\\pi}{7} \\right) + i \\, \\sin \\left( \\frac{2\\pi}{7} \\right) \\mbox{ and }\n    r := \\zeta + \\zeta^2 - \\zeta^3 + \\zeta^4 - \\zeta^5 - \\zeta^6.\n  \\]\n  Find the integer $r^2$.  (This surprise is a \\textbf{Gauss sum}.)\n\\end{problem}\n\n\\begin{problem}\n  For which $z \\in \\mathbb{C}$ is it the case that $\\log \\left( e^z \\right) = z$?  \\\\ (What do we mean when we write $\\log$ here?)\n\\end{problem}\n\n\\section{Exploration}\n\n\\begin{problem}\\label{tj-versus-jt}\n  Let's review some linear algebra.  Define $J(x,y) = (y,-x)$ so $J$\n  is counter-clockwise rotation by $90^\\circ$, and suppose\n  $T : \\R^2 \\to \\R^2$ is a linear transformation with the property\n  that $T \\circ J = J \\circ T$.  Can you relate $T$ to the complex\n  numbers?\n\\end{problem}\n\n\\begin{problem}\\label{mobius-transformations}Here is another connection to linear algebra.  Suppose we have complex-valued functions\n  \\[\n    f(z) = \\frac{az + b}{cz + d} \\mbox{ and }\n    F(z) = \\frac{Az + B}{Cz + D}.\n  \\]\n  Such functions are \\textbf{M\\\"obius transformations}.  Relate the\n  function $f \\circ F$ to a product of certain matrices.\n\\end{problem}\n\n\\begin{problem}\\label{abels-theorem}Let's review some real analysis.\n  Consider a sequence $(a_n)$ of real numbers so that\n  $\\sum_{n=0}^\\infty a_n$ converges to $L$.  Does the one-sided limit\n  \\[\n    \\lim_{x \\to 1^{-}} \\sum_{n=0}^\\infty a_n x^n\n  \\]\n  also equal $L$?  See \\textbf{Abel's theorem}.\n\\end{problem}\n\n\\begin{problem}\\label{harmonic-function}\n  For an open subset $U \\subset \\R^2$, a \\textbf{harmonic function} $f : U \\to \\R$ is a twice continuously differential function satisfying the Laplace's equation\n  \\[\n    \\frac{\\partial^2 f}{\\partial x^2} + \\frac{\\partial^2 f}{\\partial y^2} = 0.\n  \\]\n  Suppose $f(x,y) = Ax^3 + Bx^2 y + C xy^2 + D y^3$ is harmonic for constants $A, B, C, D \\in \\R$.  Relate $f$ to $z \\cdot (x + iy)^3$.\n\\end{problem}\n\n\\section{Prove or Disprove and Salvage if Possible (PODASIP)}\n\n\\textit{You may not have met these PODASIP-style problems before.\n  What follows are statements which may be ``true'' or ``false.''  If\n  the statement is true, then you should provide a proof.  If the\n  statement is false, find a counterexample and fix the statement and\n  then supply a proof for your repaired statement.  For example,\n  \\ref{blaschke-factors} suffers from the domain of $f$ not being\n  specified, so you can ``salvage'' \\ref{blaschke-factors} by\n  carefully describing the domain.}\n\n\\begin{problem}\\label{blaschke-factors}\n  Suppose $w \\in \\C$ and $\\abs{w} < 1$.  Define a function by the rule\n  \\[\n    f(z) = \\frac{w - z}{1 - \\conj{w}z}.\n  \\]\n  If $\\abs{z} < 1$, then $\\abs{f(z)} < 1$.  (These are \\textbf{Blaschke factors}.)\n\\end{problem}\n\n\\begin{problem} % you may assume R is complete.\n  The field $\\mathbb{C}$ is complete.\n\\end{problem}\n\n\\begin{problem}\n For all $z, w \\in \\C$ it is the case that $\\sqrt{z} \\sqrt{w} = \\sqrt{zw}$.\n\\end{problem}\n\n\\begin{problem} % missing non-empty, compact\n  Suppose $K_1 \\supset K_2 \\supset \\cdots$ be nested subsets of $\\C$ so that $\\diam K_n < 1/2^n$.  Then\n  \\[\n    \\bigcap_{n=1}^\\infty K_n\n  \\]\n  is non-empty and consists of a single point.\n\\end{problem}\n\n\\begin{problem}\n For all $a, b, z \\in \\C$ it is the case that $z^a \\, z^b = z^{a+b}$.\n\\end{problem}\n\n\\begin{problem}\\label{cross-ratio}\n  Define the \\textbf{cross-ratio} of distinct complex numbers $z_1,z_2,z_3,z_4 \\in \\C$ by\n\\[\n\\left(z_1,z_2;z_3,z_4\\right):=\\frac {\\left(z_3-z_1\\right)\\,\\left(z_4-z_2\\right)}{\\left(z_3-z_2\\right)\\,\\left(z_4-z_1\\right)}.\n \\]\n If $f$ is a M\\\"obius transformation (cf.~\\ref{mobius-transformations}), then\n \\[\n   \\left(z_1,z_2;z_3,z_4\\right) =\n   \\left(f(z_1),f(z_2);f(z_3),f(z_4)\\right).\n\\]\n\\end{problem}\n\n\\end{document}\n", "meta": {"hexsha": "60af51093764db299aac710d29c35ead53b1222c", "size": 4799, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem-sets/set01.tex", "max_stars_repo_name": "Alex7Li/math5522h", "max_stars_repo_head_hexsha": "9f1fa070997f40e11e981c49e7d6fb9556e128d6", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "problem-sets/set01.tex", "max_issues_repo_name": "Alex7Li/math5522h", "max_issues_repo_head_hexsha": "9f1fa070997f40e11e981c49e7d6fb9556e128d6", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "problem-sets/set01.tex", "max_forks_repo_name": "Alex7Li/math5522h", "max_forks_repo_head_hexsha": "9f1fa070997f40e11e981c49e7d6fb9556e128d6", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.2785714286, "max_line_length": 162, "alphanum_fraction": 0.6634715566, "num_tokens": 1691, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933491161063, "lm_q2_score": 0.8887587979121383, "lm_q1q2_score": 0.7286874273765878}}
{"text": "\\section{Usage in C++}\n\nA good place to see example usages is the gtest files \\textit{tests/tst\\_dConvolution.cpp} \\\\\nand \\textit{tests/tst\\_dConvolution\\_squares.cpp}.\n\nThere are three global static variables representing different sums:\n\\begin{enumerate}\n    \\item \\(\\it{cnvl}\\) represents the simple sum, ie $R=X+Y$.\n    \\item \\(\\it{cnvlSq}\\) represents the sum of the squares, ie $R=X^2+Y^2$.\n    \\item \\(\\it{cnvlSSqrt}\\) represents the sum of the squares and then take square root, ie $R=\\sqrt{X^2+Y^2}$.\n\\end{enumerate}\n\n\n\\subsection{Simple Sum}\n\n\\subsubsection*{Example 1}\nThe sum of two RVs of standard uniform distributions is a RV of Irwin-Hall distribution.\n\n\\begin{minted}{cpp}\ndisStdUniform su1{}, su2{};\nprobDistr* rsu = cnvl.go(su1, su2);\ndisIrwinHall* rih = dynamic_cast<disIrwinHall*>(rsu);\n\\end{minted}\n\n\\subsubsection*{Example 2}\nThe sum of an array of RVs of standard uniform distributions is a RV of Irwin-Hall distribution.\n\n\\begin{minted}{cpp}\ndisStdUniform su1{}, su2{}, su3{}, su4{};\nprobDistr* rsu = convolve<disStdUniform>({su1, su2, su3, su4});\ndisIrwinHall* rih = dynamic_cast<disIrwinHall*>(rsu);\n\\end{minted}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Sum of the Squares}\n\n\\subsubsection*{Example}\nThe sum of two squares of RVs of normal distributions is a RV of Chi Square distribution.\n\n\\begin{minted}{cpp}\ndisNormal a(0,1);\ndisNormal b(0,1);\ndisChiSq s = *static_cast<disChiSq*>(cnvlSq.go(a,b));\n\\end{minted}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Sum of the Squares, and Then Take Square Root}\n\n\\subsubsection*{Example}\nThe sum of two squares of RVs of normal distribution (with same variance) is a RV of Rician distribution.\n\n\\begin{minted}{cpp}\ndisNormal a(2,9);\ndisNormal b(3,9);\ndisRician s = *static_cast<disRician*>(cnvlSSqrt.go(a,b));\n\\end{minted}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{How to add a new sum of random variables?}\n\nIf you do not find your distributions in currenctly supported list, you can easily add a new sum for your random variables.\n\n... is implemented in the double dispatcher pattern. (See \\textit{Modern C++ Design by Andrei Alexandrescu} for pattern detail.)\n\nTBW\n\n\n\n\\begin{enumerate} \n    \\item Register the pair in \\textit{dConvolution.cpp}.\n    \\item Write a function prototype in \\textit{dConvolution.h}.\n    \\item Implement the sum in \\textit{dConvolution.cpp}.\n\\end{enumerate}\n\n\\begin{minted}{cpp}\n/* dConvolution.cpp */\n\nauto ConvolutionSqDoubleDispatcherInitialization = [](){\n    cnvlSq.add<disNormal,disNormal,convolveSq>();\n    cnvlSq.add<disApple,disBananna,convolveSq>();  // new distribution pair.\n    return true;\n}();\n\nprobDistr* convolve(disApple& l, disBananna& r) {\n    // Implement the sum\n    // Blah, blah, blah \n    probDistr* res = xxxxx;\n    return res;\n};\n\\end{minted}\n\n\n\\begin{minted}{cpp}\n/* dConvolution.h */\n\nprobDistr* convolve(disCauchy& lhs, disCauchy& rhs);\n\\end{minted}", "meta": {"hexsha": "61cab68645d171718bf3b1472f3784a8c85adb5d", "size": 3011, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/Documentation/section_sum_of_RV_usage.tex", "max_stars_repo_name": "AnselGitAccount/StatAnaly", "max_stars_repo_head_hexsha": "93cbffd54d212056e023fce90b0386825af49a88", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/Documentation/section_sum_of_RV_usage.tex", "max_issues_repo_name": "AnselGitAccount/StatAnaly", "max_issues_repo_head_hexsha": "93cbffd54d212056e023fce90b0386825af49a88", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/Documentation/section_sum_of_RV_usage.tex", "max_forks_repo_name": "AnselGitAccount/StatAnaly", "max_forks_repo_head_hexsha": "93cbffd54d212056e023fce90b0386825af49a88", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5196078431, "max_line_length": 128, "alphanum_fraction": 0.6718698107, "num_tokens": 866, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318195, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7286874192663545}}
{"text": "\\documentclass[class=report, float=false, crop=false]{standalone}\n\\usepackage[subpreambles=true]{standalone}\n\n\\input{preamble}\n\n\\graphicspath{{figures/images/}}\n\n% \\begin{cbunit}\n\n\\begin{document}\n\n\\chapter{Quaternions}\n\\label{appendix:quaternions}\n\n\\section{Definition}\n\nQuaternions were introduced by Hamilton as extension of complex numbers \\cite{shoemake}:\n\\begin{equation}\nq = q_0 + \\sum_{i=1}^{3}q_i e_i\\text{, with } \\begin{cases} e_m^2 = -1& \\\\ e_me_n = \\varepsilon_{mnk} e_k&\\text{, } m \\neq n \\end{cases} \\text{ and } q_0,q_1,q_2,q_3 \\in \\mathbb{R}\n\\end{equation}\n\nFor convenience, we will write $q \\equiv [\\vec{q},q_0]$ with $\\vec{q} = (q_1,q_2,q_3) \\in \\mathbb{R}^3$, and $\\mathbb{H}$ the quaternions' space.\\\\\n\nMoreover, we will identify vectors $\\vec{v}$ from $\\mathbb{R}^3$ with $[\\vec{v},0]$ and scalars $w$ from $\\mathbb{R}$ with $[0,w]$. We will assume this identification throughout the document without notification.\n\n\\section{Properties}\n\\label{quat_properties}\n\n\\begin{description}\n\\item[Addition] $\\boxed{q + q' = [\\vec{q} + \\vec{q'},q_0 + q'_0]}$\n\\item[Multiplication] $\\boxed{qq' = [\\vec{q}\\times\\vec{q'} + q_0\\vec{q'} + q'_0\\vec{q},q_0q'_0 - \\vec{q}\\cdot\\vec{q'}]}$\n\\begin{align*}\nqq' &= (q_0 + \\sum_{i=1}^{3}q_i e_i)(q'_0 + \\sum_{i=1}^{3}q'_i e_i) = q_0q'_0 + \\underbrace{q_0\\sum_{i=1}^{3}q'_i e_i}_{q_0\\vec{q'}} + \\underbrace{q'_0\\sum_{i=1}^{3}q_i e_i}_{q'_0\\vec{q}} + \\underbrace{\\sum_{i=1}^{3}q_iq'_i \\underbrace{e_ie_i}_{-1}}_{-\\vec{q}\\cdot\\vec{q'}} + \\underbrace{\\sum_{\\substack{i,j \\\\ i \\neq j}}q_iq'_j\\underbrace{e_ie_j}_{\\varepsilon_{ijk}e_k}}_{\\vec{q}\\times\\vec{q'}}\\\\\n&= [\\vec{q}\\times\\vec{q'} + q_0\\vec{q'} + q'_0\\vec{q},q_0q'_0 - \\vec{q}\\cdot\\vec{q'}]\n\\end{align*}\n\\item[Multiplication by a scalar] $\\boxed{\\lambda q = [\\lambda\\vec{q},\\lambda q_0]}$\n\\item[Bilinearity] $\\boxed{q''(\\lambda q + \\lambda q') = \\lambda q''q + \\lambda q''q'}$\n\\item[Associative property] $\\boxed{(qq')q'' = q(q'q'')}$\n\\item[Conjugate] $\\boxed{q^* = [-\\vec{q},q_0]}$\n\\begin{align*}\nq^* &= (q_0 + \\sum_{i=1}^{3}q_i e_i)^* = q_0 - \\sum_{i=1}^{3}q_i e_i\\\\\n&= [-\\vec{q},q_0]\n\\end{align*}\n\\item[Conjugation property] $\\boxed{(qq')^* = q'^*q^*}$\n\\begin{align*}\n(qq')^* &= ([\\vec{q},q_0][\\vec{q'},q'_0])^*\\\\\n&= ([\\vec{q}\\times\\vec{q'} + q_0\\vec{q'} + q'_0\\vec{q},q_0q'_0 - \\vec{q}\\cdot\\vec{q'}])^*\\\\\n&= [\\underbrace{-\\vec{q}\\times\\vec{q'}}_{(-1)\\vec{q'}\\times(-1)\\vec{q}} + q_0(-\\vec{q'}) + q'_0(-\\vec{q}),q_0q_0' - (-1)\\vec{q}\\cdot(-1)\\vec{q'}]\\\\\n&= [-\\vec{q'},q'_0][-\\vec{q},q_0]\\\\\n&= q'^*q^*\n\\end{align*}\n\\item[Norm] $\\boxed{N^2(q) = \\sum_{i=0}^{3} q_i^2}$\n\\begin{align*}\nN^2(q) &= qq* = [\\vec{q},q_0][-\\vec{q},q_0] = [\\cancel{-q_0 \\vec{q}} + \\cancel{q_0\\vec{q}},q_0q_0 + \\vec{q}\\cdot\\vec{q}]\\\\\n&= [0,\\sum_{i=0}^{3} q_i^2] = \\sum_{i=0}^{3} q_i^2\n\\end{align*}\n\\item[Inverse] $\\boxed{q^{-1} = q^*/N^2(q)}$\n\\begin{align*}\nq\\frac{q*}{N^2(q)} = \\frac{q*}{N^2(q)}q = 1 \\Leftrightarrow q^{-1} = \\frac{q*}{N^2(q)}\n\\end{align*}\n\\item[Action of an unit quaternion] From the property of the inverse of a quaternion, it is trivial that the action of any quaternion $q$\n\\begin{align*}\n\\mathcal{A}_q \\colon &\\mathbb{H} \\to \\mathbb{H}\\\\     &\\phantomarrow{\\mathbb{H}}{p} qpq^{-1}\n\\end{align*}\nwill be the same as the action of the associated unit quaternion $q/N(q)$. Therefore, we will only consider unit quaternion from now on and use $q^*$ instead of $q^{-1}$.\\\\\n\nWe then have that for any $p = [\\vec{v},w]$, $\\boxed{qpq^* = [\\vec{v'},w]}$ with $N(\\vec{v}) = N(\\vec{v'})$\n\\begin{align*}\n&\\text{Indeed, with $S(q) \\equiv \\frac{q+q^*}{2}$ the scalar part of any quaternion $q$ we have}\\\\\n%\\vspace{-30pt}\n&2S(qpq^*)\\\\\n&= qpq^* + (qpq^*)^* = qpq^* + qp*q^*\\\\\n&= q\\underbrace{(p + p^*)}_{2w}q^* = 2w\\cancel{qq^*} = 2w\\\\\n&= 2S(p)\\\\\n&\\text{The conjugation property ensures that the multiplication conserves the}\\\\\n&\\text{norm, then $N(qpq^*)=N(p)$, hence the property.}\n\\end{align*}\nTherefore the action of any quaternion on any vector of $\\mathbb{R}^3$ is a vector of $\\mathbb{R}^3$.\n\\end{description}\n\n\\section{Actions and rotations}\n\\label{action_rotation}\n\nConsider $\\vec{v_0},\\vec{v_1} \\in \\mathbb{R}^3$ with $\\vec{v_0} \\times \\vec{v_1} \\neq 0$ and $N(\\vec{v_0}) = N(\\vec{v_1}) = 1$. We define $q \\equiv \\vec{v_1}\\vec{v_0}^* = [\\vec{v_0}\\times\\vec{v_1},\\vec{v_0}\\cdot\\vec{v_1}]$, $\\theta \\equiv (\\vec{v_0};\\vec{v_1})$ and $\\vec{v} = \\frac{\\vec{v_0} \\times \\vec{v_1}}{||\\vec{v_0} \\times \\vec{v_1}||}$ so that $q = [\\vec{v}\\sin\\theta,\\cos\\theta]$. We want to know what is the action of $q$, $\\mathcal{A}_q$, on any vector of $\\mathbb{R}^3$.\\\\\n\nWe have $(\\vec{v_0},\\vec{v_1},\\vec{v})$  a basis of $\\mathbb{R}^3$. Thanks to the bilinearity of the product of quaternions, we can infer $\\mathcal{A}_q(\\vec{u}) \\forall \\vec{u} \\in \\mathbb{R}^3$ from the action of $q$ on this basis. The following demonstration was originally made in \\cite{shoemake}.\\\\\n\n\\begin{description}\n\\item[Action on $\\vec{v}$\\hspace{20pt}]\n\\begin{align*}\n\\mathcal{A}_q(\\vec{v}) &= q\\vec{v}q^*\\\\\n&= [\\vec{v}\\sin\\theta,\\cos\\theta][\\vec{v},0][-\\vec{v}\\sin\\theta,\\cos\\theta]\\\\\n&= [\\vec{v}\\cos\\theta,-\\underbrace{|\\vec{v}|^2}_{=1}\\sin\\theta][-\\vec{v}\\sin\\theta,\\cos\\theta]\\\\\n&= [\\underbrace{\\vec{v}\\sin^2\\theta + \\vec{v}\\cos^2\\theta}_{=\\vec{v}},\\cancel{-\\sin\\theta\\cos\\theta} + \\underbrace{|\\vec{v}|^2}_{=1}\\cancel{\\sin\\theta\\cos\\theta}]\\\\\n&= [\\vec{v},0]\\\\\n&= \\vec{v}\n\\end{align*}\n\\item[Action on $\\vec{v_0}$\\hspace{20pt}] We define $\\vec{v_2} \\equiv \\mathcal{A}_q(\\vec{v_0}) = q\\vec{v_0}q^*$ and notice that\n\\begin{align*}\n\\vec{v_2}\\vec{v_1}^* &= (q\\vec{v_0}q^*)\\vec{v_1}^*\\\\\n&= (q\\vec{v_0}(\\vec{v_1}\\vec{v_0}^*)^*)\\vec{v_1}^*\\\\\n&= q\\vec{v_0}(\\vec{v_0}\\vec{v_1}^*)\\vec{v_1}^*\\\\\n&=q\\underbrace{(\\vec{v_0}\\vec{v_0})}_{=-1}\\underbrace{(\\vec{v_1}^*\\vec{v_1}^*)}_{=-1}\\\\\n&=q=\\vec{v_1}\\vec{v_0}^*\n\\end{align*}\nso \\(\\begin{cases} \\vec{v_1}\\times\\vec{v_2} &= \\vec{v_0}\\times\\vec{v_1} \\\\ \\vec{v_1}\\cdot\\vec{v_2} &= \\vec{v_0} \\cdot \\vec{v_1} \\end{cases} \\). Therefore, $\\vec{v_0}, \\vec{v_1}$ and $\\vec{v_2}$ belong to the same plane and furthermore, $(\\vec{v_1};\\vec{v_2}) = (\\vec{v_0};\\vec{v_1}) = \\theta$. Then, $\\vec{v_2}$ is the rotation of $\\vec{v_0}$ of an angle $2\\theta$ around $\\vec{v}$.\\\\\n\\item[Action on $\\vec{v_1}$\\hspace{20pt}] We define $\\vec{v_3} \\equiv \\mathcal{A}_q(\\vec{v_1}) = q\\vec{v_1}q^*$ and notice that\n\\begin{align*}\n\\vec{v_3}\\vec{v_2}^* &= (q\\vec{v_1}q^*)(q\\vec{v_0}q^*)^*\\\\\n&= (q(q\\vec{v_0})q^*)(q\\vec{v_0}q^*)^*\\\\\n&=  q(q\\vec{v_0}q^*)(q\\vec{v_0}q^*)^*\\\\\n&=q=\\vec{v_1}\\vec{v_0}^*\n\\end{align*}\nso \\(\\begin{cases} \\vec{v_2}\\times\\vec{v_3} &= \\vec{v_0}\\times\\vec{v_1} \\\\ \\vec{v_3}\\cdot\\vec{v_3} &= \\vec{v_0} \\cdot \\vec{v_1} \\end{cases} \\). Therefore, $\\vec{v_0}, \\vec{v_1}, \\vec{v_2}$ and $\\vec{v_3}$ belong to the same plane and furthermore, $(\\vec{v_2};\\vec{v_3}) = (\\vec{v_0};\\vec{v_1}) = \\theta$. Then, $\\vec{v_3}$ is the rotation of $\\vec{v_1}$ of an angle $2\\theta$ around $\\vec{v}$.\\\\\n\\end{description}\n\nFinally, we have that $\\mathcal{A}_q$ corresponds to the rotation of angle $2\\theta$ around $\\vec{v}$. The corollary to that property is that\n\n\\begin{center}$\\boxed{\\text{\\textbf{every 3D rotation can be expressed as the action of some unit quaternion}}}$.\\end{center}\n\n% \\input{references/biblio}\n\n\\end{document}\n\n% \\end{cbunit}", "meta": {"hexsha": "edc32544f5beceb8317f50c74bcadec92d1f0bf6", "size": 7215, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/appendices/app_quaternions.tex", "max_stars_repo_name": "yketa/Umea_2017_Notes", "max_stars_repo_head_hexsha": "3b0e564e9054383bd91ff46930afe5543e9845ca", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Report/appendices/app_quaternions.tex", "max_issues_repo_name": "yketa/Umea_2017_Notes", "max_issues_repo_head_hexsha": "3b0e564e9054383bd91ff46930afe5543e9845ca", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/appendices/app_quaternions.tex", "max_forks_repo_name": "yketa/Umea_2017_Notes", "max_forks_repo_head_hexsha": "3b0e564e9054383bd91ff46930afe5543e9845ca", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.72, "max_line_length": 484, "alphanum_fraction": 0.6152460152, "num_tokens": 3265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.7286874101785068}}
{"text": "\\section[Linear recurrences]{Linear recurrences - The Fibonacci sequence}\\label{fibonacci} \n\nWe are going to discuss the Fibonacci sequence in the following section.\n\n\\subsection{Fibonacci's rabbit problem}\n\nSuppose we have a pair of rabbits that are adults after one month. In the month after they are fully grown,\nthey give birth to two more rabbits. The newborns are again fully grown after one month and give birth to two more \nrabbits, and so on. Consider the following figure as an example.\n\\\\\n\\\\\n$\n\\begin{array}{l}\n    \\includegraphics[scale=0.1]{pictures/rabbits.jpg}\n\\end{array}\nn=1$\\\\\n$\n\\begin{array}{l}\n    \\includegraphics[scale=0.1]{pictures/rabbits.jpg}\n\\end{array}\nn=2 \\text{ (grown up)}$\n\\\\\n$\n\\begin{array}{l}\n    \\includegraphics[scale=0.1]{pictures/rabbits.jpg}\n    \\includegraphics[scale=0.1]{pictures/rabbits.jpg}\n\\end{array}\nn=3$\n\\\\\n$\n\\begin{array}{l}\n    \\includegraphics[scale=0.1]{pictures/rabbits.jpg}\n    \\includegraphics[scale=0.1]{pictures/rabbits.jpg}\n    \\includegraphics[scale=0.1]{pictures/rabbits.jpg}\n\\end{array}\nn=4$\n\\\\\n\\\\\n\\noindent\n\\textbf{Question:} How many pairs of rabbits will we have after one year?\n\\\\\n\\\\\n\\noindent\nLet us introduce the following notation. Denote the number of pairs of rabbits during\nthe $n$-th month by $F(n)$. Then, we could express $F(n)$ by the number of rabbits in \nthe $(n-1)$-th month and $(n-2)$-th month by the following equation.\n$$\nF(n)=F(n-1)+F(n-2)\n$$\nThus, by setting $F(2)=1$ the following sequence of numbers follows.\n$$\n1,1,2,3,5,8,13,21,36,55,89,144, \\cdots\n$$\n\\noindent\nThe answer follows for $F(12)=144$, hence after $12$ months we have $144$ pairs of rabbits.\n\\\\\n\\\\\nThe above sequence is called the \"Fibonacci sequence\" and we are going to investigate some \nof its fascinating properties in the next sections.\n\n\\newpage\n\n\\subsection[Pascal triangle]{Fibonacci numbers and the Pascal triangle}\n\nWe consider once again the Pascal triangle. Let us sum up its diagonals. This is done in the following figure for \nthe first few diagonals.\n\\\\\n\\\\\n\\begin{tabular}{>{$n=}l<{$\\hspace{12pt}}*{13}{c}}\n    0 &&&&&&&1&&&&&&\\\\\n    1 &&&&&&1&&\\color{red}1\\textsuperscript{\\color{red}=2}&&&&&\\\\\n    2 &&&&&\\color{red}1&&\\color{yellow}2\\textsuperscript{\\color{yellow}=3}&&1&&&&\\\\\n    3 &&&&\\color{yellow}1&&\\color{green}3\\textsuperscript{\\color{green}=4}&&\\color{blue}3\\textsuperscript{\\color{blue}=8}&&\\color{cyan}1\\textsuperscript{\\color{cyan}=13}&&&\\\\\n    4 &&&\\color{green}1&&\\color{blue}4&&\\color{cyan}6&&4&&1&&\\\\\n    5 &&\\color{blue}1&&\\color{cyan}5&&10&&10&&5&&1&\\\\\n    6 &\\color{cyan}1&&6&&15&&20&&15&&6&&1\n\\end{tabular}\n\\\\\n\\\\\n\\noindent\nThe following sequence is the result.\n$$\n1,1,\n\\color{red} 1 \\color{black}+ \\color{red}1\\color{black}=\\color{red}2 \\color{black}, \\color{yellow} 1 \\color{black}+ \\color{yellow}2\\color{black}=\\color{yellow}3 \\color{black}, \n\\color{green} 1 \\color{black}+ \\color{green}3\\color{black}=\\color{green}4 \\color{black}, \n\\color{blue} 1 \\color{black}+ \\color{blue}4\\color{black}+ \\color{blue}3=\\color{blue}8 \\color{black}, \n\\color{cyan} 1 \\color{black}+ \\color{cyan}5\\color{black}+ \\color{cyan}6\\color{black}+ \\color{cyan}1=\\color{cyan}13 \\color{black}, \\cdots \n$$\nThe general formula for the sum of the diagonals in the Pascal triangle is easily derived. It is as follows.\n$$\n\\sum_{k=0}^{\\floor{\\frac{n-1}{2}}} {n-k-1 \\choose k}\n$$\n\n\\subsection{Domino tilings}\n\n\\subsection{Vending machine problem}\n\nSuppose that we only have nickels ($5$), dimes ($10$) and quarters ($25$). In how many ways can we pay $\\$1$ (or any other amount)?\nNotice first that, unlike in the integer composition problem, the sums $5 + 10 + 10 + 25 + 25 + 25$ and $10 + 25 + 10 + 5 + 25 + 25$ are not considered identical.\nLet us denote the number of ways to pay $5n$ cents by $A(n)$ and set $A(0)=1$. Let us make a table with the $n$ ranging to $6$.\n\\bigskip\n\\begin{center}\n    \\begin{tabular}{ |c|c|c|c|c|c|c|c| } \n     \\hline\n     $n$ & $0$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ \\\\ \n     $A(n)$ & $1$ & $1$ & $2$ & $3$ & $5$ & $9$ & $15$ \\\\  \n     \\hline\n    \\end{tabular}\n\\end{center}\n\\bigskip\n\\noindent\nLet us examine $n=5$, the number of ways to pay $25$ cents, in more detail. There is only one way to pay with a quarter. There are three ways \nto pay $25$ cents if we start with a dime, namely $10 + 10 + 5, 10 + 5 + 10, 5 + 10 + 10$, and five ways to pay starting with a nickel.\nIt is not hard to see that this yields the following recurrence relation.\n$$\nA(n) = A(n-1)+A(n-2)+A(n-5)\n$$\n\n\\subsection{Linear recurrence relations}\n\nIn the following section, we are going to introduce the formal definition of a linear recurrence relation.\n\n\\begin{defn}\nA linear recurrence relation of order $k$ is a sequence satisfying \n$$\nA(n)=c_1A(n-1)+c_2A(n-2)+\\cdots+c_kA(n-k)\n$$\nwhere $c_1,\\cdots, c_k \\in \\mathbb{R}$.\n\\label{defn:rec}\n\\end{defn}\n\n\\begin{exmp}\nThe Fibonacci sequence $F(n)=F(n-1)+F(n-2)$ is a linear recurrence relation of order $2$. The sequence\n$A(n)=A(n-1)+A(n-2)+A(n-5)$ from the last section is a linear recurrence relation of order $5$.\n\\end{exmp}\n\n\\begin{remark}\nA sequence defined by a linear recurrence relation is uniquely determined by the first $k$ terms $A(0), A(1), \\cdots, A(k-1)$.\nWhy is that the case? Suppose that $a_0, a_1, a_2, \\cdots$ and $a_0', a_1', a_2', \\cdots$ satisfy the relation $(*)$,\nthen $a_0+a_0', a_1+a_1',a_2+a_2', \\cdots$ also satisfy $(*)$ and so does $c \\cdots a_0, c \\cdot a_1, c \\cdot a_2, \\cdots$.\nIn other words, the solutions of a linear recurrence relation form a vector space.\n\\end{remark}\n\n\\subsection[The characteristic equation]{The characteristic equation}\n\nIn the following section we want to solve the following problem.\\\\\n\\textbf{Problem:} Given a recurrence relation\n$$\n(*)\\ A(n)=c_1A(n-1)+c_2A(n-2)+\\cdots+c_kA(n-k)\n$$\nas in definition \\ref{defn:rec}. Find \\underline{all} the sequences $(a_0, a_1, a_2, \\cdots)$ satisfying this relation.\n\\\\\nFor $k=1$ the linear recurrence relation yields $A(n)=c \\cdot A(n-1)$, and the answer for our problem is just the geometric progression \ngiven by $a_n=c^n a_0$ where $a_0 \\in \\mathbb{R}$.\n\\\\\n\\\\\n\\noindent\n\\textbf{Idea:} Find a geometric progression $(a_0, \\lambda a_0, \\lambda^2 a_0, \\cdots)$ satisfying $(*)$. Suppose $\\lambda \\neq 0$ and $a_0 \\neq 0$.\nThen,\n$$\na_0 \\lambda^n=c_1 a_0 \\lambda^{n-1}+c_2 a_0 \\lambda^{n-2} + \\cdots + c_k a_0 \\lambda^{n-k}, \\forall n \\geq k.\n$$\nDividing the above equation by $a_0 \\lambda^{n-k}$ yields \n$$\n\\lambda^k=c_1 \\lambda^{k-1} + c_2 \\lambda^{k-2} + \\cdots + c_k.\n$$\nThen $\\lambda$ is a root of the so called \\underline{characteristic equation} which is given by\n$$\nt^k=c_1t^{k-1}+c_2 t^{k-2} + \\cdots + c_k.\n$$\nThe coefficients of the characteristic equation are the same as in the original recurrence relation.\n\n\\subsection{Linear recurrence relations of order $2$}\n\nLet $A(n)=c_1 A(n-1) + c_2 A(n-2)\\ (*)$ and $t^2=c_1t +c_2\\ (**)$. Suppose that $\\lambda$ and $\\mu$ are roots of $(**)$ where $\\lambda \\neq \\mu$.\nThen, \n\\begin{align*}\n1, \\lambda, \\lambda^2, \\lambda^3, \\cdots \\\\\n1, \\mu, \\mu^2, \\mu^3, \\cdots\n\\end{align*}\nare solutions of equation $(*)$. Since the solutions of a recurrence relation form a vector space \n$$\na_n=C \\cdot \\lambda^n + D \\cdot \\mu^n \n$$\nis also a solution (the linear combinations of the above solutions).\\\\\\\\\n\\textbf{Question:} Are there any other solutions? \n\\\\\n\\\\\nWell, the answer is \"No\", because for any solution $(a_0, a_1, \\cdots)$ of $(*)$, there exist $C$\n and $D$ such that $a_n=C \\dot \\lambda^n + D \\cdot \\mu^n$ which is called the \\textit{general solution} of $(*)$. But why is that so?\nSince $(*)$ is a linear recurrence relation of order $k=2$, $(a_0, a_1, a_2, \\cdots, a_n, \\cdots)$ is uniquely determined by its first two terms $a_0$ and $a_1$.\nWe need to show that for any $a_0$ and $a_1$ there exist a $C$ and $D$ such that\n\\begin{align*}\n&\\begin{cases}\n    a_0 = C + D\\\\    \n    a_1 = C \\dot \\lambda + D \\cdot \\mu   \n\\end{cases}\\\\\n&\\begin{cases}\n    D = a_0 - C\\\\    \n    a_n = C \\cdot \\lambda + (a_0 - C) \\cdot \\mu   \n\\end{cases}\\\\\n&\nC=\\frac{a_1 - a_0 \\mu}{\\lambda - \\mu},\\ D=\\frac{a_0 \\lambda - \\mu}{\\lambda - \\mu} \n\\end{align*}\n\\noindent\nTherefore, $C$ and $D$ are uniquely determined, hence there are no other solutions then the above.\n\n\\subsection{The Binet formula}\nIn the following section we are going to go over two examples of the characteristic equation. \n\\begin{exmp}\nLet $A(n)=5 A(n-1)-6A(n-2)$. Find a solution for $a_0=3$ and $a_1=7$. First, define the characteristic which is quickly found.\n\\begin{align*}\nt^2=5t-6\\\\\nt^2-5t+6=0\n\\end{align*}\nThe roots are $\\lambda=2$ and $\\mu=3$, thus the general solution of our characteristic equation is given by\n$$\na_n=C \\cdot 2^n + D \\cdot 3^n.\n$$\nSolving the equation for $C$ and $D$ yields the following system of linear equations.\n\\begin{align*}\n    &\\begin{cases}\n        a_0 = 3 = C + D\\\\    \n        a_1 = 7 = 2C + 3D   \n    \\end{cases}\\\\\n    &\\begin{cases}\n        C=2\\\\\n        D=1\n    \\end{cases}\n\\end{align*}\nTherefore, \n$$\na_n=\\underbrace{2^{n+1}}_{2 \\cdot 2^n} + \\underbrace{3^n}_{1 \\cdot 3^n}.\n$$\n\\end{exmp}\n\n\\begin{exmp}\nThe Fibonacci sequence is given by the linear recurrence relation $F(n)=F(n-1)+F(n-2)$ with $f_0=0$ and $f_1=1$. Thus,\nthe characteristic equation is given by\n\\begin{align*}\nt^2=t+1\\\\\nt^2-t-1=0\n\\end{align*}\nand the roots, call them $\\varphi$ and $\\psi$, follow\n\\begin{align*}\n\\varphi &= \\frac{1 + \\sqrt(5)}{2}\\\\\n\\psi &= \\frac{1 - \\sqrt(5)}{2}\n\\end{align*}\nAnd as before\n\\begin{align*}\n    &\\begin{cases}\n        0 = C + D\\\\    \n        1 = C \\cdot \\varphi + D \\cdot \\psi   \n    \\end{cases}\\\\\n    &\\begin{cases}\n        D = -C\\\\    \n        1 = C (\\varphi - \\psi)   \n    \\end{cases}\\\\\n    &\\begin{cases}\n        C = \\frac{1}{\\varphi - \\psi}\\\\    \n        D = \\frac{1}{\\psi - \\varphi}   \n    \\end{cases}\\\\\n    &\\begin{cases}\n        C = \\frac{1}{\\sqrt{5}}\\\\    \n        D = -\\frac{1}{\\sqrt{5}}   \n    \\end{cases}\\\\\n\\end{align*}\nThe solution follows.\n$$\nf_n= \\frac{\\varphi^n - \\psi^n}{\\varphi - \\psi} = \\frac{1}{\\sqrt{5}}\\biggr (\\biggr(\\frac{1 + \\sqrt{5}}{2}\\biggl )^n - \\biggr( \\frac{1- \\sqrt{5}}{2} \\biggr )^n \\biggr )\n$$\nThis formula is called \"The Binet Formula\".\n\\end{exmp}\n\n\\subsection{Linear recurrence relations of arbitrary order}\n\nIt is no surprise that we can generalize the results of the last sections to linear recurrence relations of an arbitrary order $k$.\nGiven a linear recurrence relation\n$$\nA(n)=c_1A(n-1)+c_2A(n-2)+\\cdots+c_kA(n-k)\\ (*)\n$$\nthen $1, \\lambda, \\lambda^2, \\cdots, \\lambda^n, \\cdots$ is a solution of $(*)$ where $\\lambda$ is a root of the characteristic equation\n$$\nt^k=c_1 t^{k-1} + \\cdots + c_k.\n$$\nSuppose it has $k$ distinct roots $\\lambda_1, \\cdots, \\lambda_k$, then \n$$\na_n=c_1 \\lambda_1^n + c_2 \\lambda_2^n + \\cdots + c_k \\lambda_k^n\n$$\nis the general solution. Suppose that we are given $a_0, \\cdots, a_{k-1}$. We want a solution with the following initial solutions.\n$$\n\\begin{cases}\n    a_0 = c_1 + c_2 + \\cdots + c_k\\\\    \n    a_1 = c_1 \\lambda_1 + c_2 \\lambda_2 + \\cdots + c_k \\lambda_k\\\\\n    \\vdots \\text{ } \\cdots\\\\\n    a_{k-1}= c_1 \\lambda_1^{k-1} + c_2 \\lambda_2^{k-2} + \\cdots + c_k \\lambda^{k-1}   \n\\end{cases}\n$$\nThe above system of linear equations has a unique solution if and only if its determinant is equal to \n$$\n\\det\\begin{pmatrix} 1 & 1 & \\cdots & 1 \n    \\\\ \\lambda_1 & \\lambda_2 & \\cdots & \\lambda_k \\\\\n    \\lambda_1^2 & \\lambda_2^2 & \\cdots & \\lambda_k^2 \\\\\n    \\vdots & \\vdots & \\vdots & \\vdots \\\\\n    \\lambda_1^{k-1} & \\cdots & \\cdots & \\lambda_k^{k-1}  \n\\end{pmatrix} \n= \\prod_{k \\geq 1 > j \\geq 1} (\\lambda_i - \\lambda_j)\n$$\nThe above is known as the \"Vandermont determinant\" and since all $\\lambda_i$ and $\\lambda_j$ are distinct, the above has an unique solution.\n\n\\subsection{The case of roots with multiplicities}\n\nWhat happens if some roots of the characteristic equation occur with multiplicities? Given $A(n)=c_1 A(n-1)+ c_2 A(n-2)$ yields $t^2-c_1t -c_2=0$.\nSuppose that $\\lambda$ is a unique (double) root of this equation, then\n$$\n\\begin{cases}\n    -c_2=\\lambda^2\\\\    \n    c_1 = 2 \\lambda   \n\\end{cases}\n$$\nsince $(t-\\lambda)^2=t^2 -c_1t-c_2$ and $1, \\lambda, \\lambda^2, \\cdots, \\lambda^n$ is a solution.\n\n\\begin{claim}\n$0, \\lambda, 2 \\lambda^2, 3 \\lambda^3, \\cdots, n \\lambda^n$ is another solution.\n\\end{claim}\n\\begin{proof}\nThe above yields to\n$$\nn \\lambda^n = c_1 (n-1)\\lambda^{n-1} + c_2 (n-2)\\lambda^{n-2}.\n$$\nThe solution $-c_2=\\lambda^2$ and $c_1=2 \\lambda$ yields in the following.\n$$\nn \\lambda^n = 2 \\lambda(n-1)\\lambda^{n-1} + (-\\lambda^2)(n-2)\\lambda^{n-2}\n$$\nBoth sides are divisible by $\\lambda^n$, thus $n=2(n-1)-(n-2)$ is a solution which is linearly independent of the previous one.\n\\end{proof}\n\nIn general, if $\\lambda$ is a root of the characteristic polynomial of order $r$, then the characteristic polynomial is divisible by $(t- \\lambda)^r$.\nHence, the following are all solutions of the above.\n\\begin{align*}\n1, \\lambda, \\lambda^2, \\cdots, \\lambda^n, \\cdots \\\\\n0, \\lambda, 2 \\lambda^2, \\cdots, n \\lambda^n, \\cdots \\\\\n0, \\lambda, 4 \\lambda^4, 9 \\lambda^3, \\cdots, n^2 \\lambda^n, \\cdots \\\\\n0, \\lambda, 2^{r-1} \\lambda^2, \\cdots, n^{r-1}\\lambda^n, \\cdots\n\\end{align*}\n\n\\subsection{Exercises}\n\n\\begin{enumerate}\n\\item Which of the following is a Fibonacci sequence?\n\\begin{enumerate}\n\\item The number of partitions, i.e. the presentations of a natural number as a sum of positive non-increasing summands (i.e., $3=2+1=1+1+1$)\n\\item The number of sequences of $0$'s and $1$'1 with $n$ digits that contain no two consecutive zeroes\n\\item The number of subsets of $\\{1,2, \\cdots, n\\}$ that contain no consecutive integers\n\\item The number of partitions of a rectangle $2 \\times n$ into rectangles $2 \\times 1$\n\\item The number of compositions of a natural number into positive odd summands (i.e., $4=1+1+1+1=1+3=3+1$)\n\\end{enumerate}\n\\item The Fibonacci sequence can be continues \"backwards\" using the same rule: $F_n=F_{n-1}+F_{n-2}$. For example, $F_0=0, F_{-1}=1$. Find $F_{-10}$.\n\\item Find the maximal common ration of a geometric progression $a_n$ satisfying the following equation: $a_{n+2}=3a_{n+1}-2a_n$.\n\\item The sequence $a_n$ is defined by the recurrence relation $a_{n+3}=3a_{n+2}-3a_{n+1}+a_n$ with initial values $a_0=a_1=0, a_2=1$. Find $a_{100}$.\n\\item The sequence $a_n$ is defined by the recurrence relation $a_{n+4}=a_{n+3}-a_{n+2}+a_{n+1}-a_n$ with initial values $a_0=1607, a_1=1707, a_2=1814, a_3=1914$. Find $a_{100}$.\n\\end{enumerate}", "meta": {"hexsha": "311dd2f14a3a648e8a1d8e853f428de96306ce6e", "size": 14404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/linearRecurrencesFibonacci.tex", "max_stars_repo_name": "pgrepds/Enumerative-Combinatorics", "max_stars_repo_head_hexsha": "ee8fbf2789cc1d17474d8ccbdd9a860788aa54ca", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/linearRecurrencesFibonacci.tex", "max_issues_repo_name": "pgrepds/Enumerative-Combinatorics", "max_issues_repo_head_hexsha": "ee8fbf2789cc1d17474d8ccbdd9a860788aa54ca", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/linearRecurrencesFibonacci.tex", "max_forks_repo_name": "pgrepds/Enumerative-Combinatorics", "max_forks_repo_head_hexsha": "ee8fbf2789cc1d17474d8ccbdd9a860788aa54ca", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7900552486, "max_line_length": 178, "alphanum_fraction": 0.6594695918, "num_tokens": 5188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.888758789809389, "lm_q1q2_score": 0.7286874011766965}}
{"text": "\\section{Support vector machine}\\label{sec:SVMintro}% and the relation with Binary Logistic Regression}\nThere is a lot of work about SVM in literature , see \\cite{drucker1997support,ben2001support,cortes1995support,cristianini2000introduction} for example.\nGiven a binary linearly separable classification dataset ${(x_i,y_i)}_{i = 1}^N$, where $x_i\\in \\mathbb{R}^d, y_i\\in \\left \\{\\begin{pmatrix}1\\\\0\\end{pmatrix}, \\begin{pmatrix}0\\\\1\\end{pmatrix}\\right \\}$. We use $A_1,A_2$ to denote the data with label $\\begin{pmatrix}1\\\\0\\end{pmatrix}, \\begin{pmatrix}0\\\\1\\end{pmatrix}$, respectively. Our goal is to find a $\\theta = (w,b)$ where $w\\in \\mathbb{R}^{1\\times d}, b\\in \\mathbb{R}$ such that the hyperplane $H_{\\theta} = \\{x:wx + b = 0\\}$ can separate $A_1,A_2$.\n\n\\subsection{Binary SVM}\\label{sec:SVM}\nBinary Support Vector Machine (SVM for short hereinafter) wants to find the classifiable hyperplane which has the biggest distance with $A_1$ and $A_2$. Assume that we have the hyperplanes $wx+b=\\pm 1$ with\n$$\nwx_i+b\\ge 1 \\quad \\mbox{for}\\quad x_i\\in A_1,\\quad wx_i+b\\le -1 \\quad \\mbox{for}\\quad x_i\\in A_2,\n$$\nwhich is similar to the definition \\eqref{2classH}.\nLet $y_1=\\begin{pmatrix}1\\\\0\\end{pmatrix}$ for $x_i\\in A_1$ and $y_2=\\begin{pmatrix}0\\\\1\\end{pmatrix}$ for $x_i\\in A_2$. %Then, we have the following inequality\n%$$\n%y_i(wx_i+b)\\ge 1 \\quad \\mbox{for all }\\quad i.\n%$$\nNote that $w$ is normal to the hyperplane and the distance  between the points satisfying \n$$\nwx_i+b=\\pm 1\n$$\nand the hyperplane $wx+b=0$ is $\\displaystyle {1\\over \\|w\\|_2}$. Thus, the width of the margin is $\\displaystyle {2\\over \\|w\\|_2}$ as shown in Figure \\ref{fig:margin}.\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width = 2in]{margin}\n\t\\caption{SVM}\n\t\\label{fig:margin}\n\\end{figure}\nFor any $w$ and $b$, the smallest distance between points and the hyperplane is \n\\begin{equation}\n\\frac{\\min_{i} \\ell_i(wx_i+b)}{\\|w\\|_2},\n\\end{equation} \nwhere $\\ell_i=1-2e_2^Ty_i$.\nNote that \n$$\n\\ell_i=\\begin{cases}\n1 & \\mbox{ if } y_i=\\begin{pmatrix}1\\\\0\\end{pmatrix},\n\\\\\n-1 &\\mbox{ if } y_i=\\begin{pmatrix}0\\\\1\\end{pmatrix}.\n\\end{cases}\n$$\nConsider the problem\n\\begin{equation}\n\t\\max_{w,b} \\frac{\\min_{i} \\ell_i(wx_i+b)}{\\|w\\|_2}.\n\\end{equation}\nIntuitively, the best separating hyperplane $H$ is only determined by those data points who are closest to $H$. Those data points are called {support vector}, and this method are called {support vector machine}.\n\nWithout loss of generality, we may restrict the norm of $\\|w\\|$ to be 1, which leads to a equivalent optimization problem\n\\begin{equation}\n\\max_{\\|w\\|_2 = 1} \\min_{i} \\ell_i(wx_i+b)\n\\end{equation}\nActually, {we can prove $\\displaystyle \\mathop{\\rm argmax}_{\\|w\\|_2 = 1} \\min_{i} \\ell_i(wx_i+b)$ is nonempty, but here we just admit this fact and only prove the uniqueness of the solution.}\n\n\\begin{lemma}\n\tIf $A_1,A_2$ are linearly separable, then\n\t\\begin{equation}\\label{binarySVM}\n\t\\mathop{\\rm argmax}_{\\|w\\|_2 = 1} \\min_{i} \\ell_i(wx_i+b)\n\t\\end{equation}\n\tis nonempty.\n\\end{lemma}\n\n\\begin{proof}\n\tTake $x_{i_1} \\in A_1$ and  $x_{i_2} \\in A_2$,  given $(w,b)\\in \\{(w,b): l_i(wx_i +b)>0, \\forall i\\}$, we have\n\t\\begin{equation}\n\t\t\\begin{cases}\n\t\twx_{i_1} + b > 0,\\\\\n\t\twx_{i_2} + b < 0\n\t\t\\end{cases}\n\t\\end{equation}\n\twhich implies $|b| < \\max_{i} \\|x_i\\|_2$. So we have\n\t\\begin{equation}\n\t\t\\mathop{\\rm argmax}_{\\|w\\|_2 = 1} \\min_{i} \\ell_i(wx_i+b) = \\mathop{\\rm argmax}_{\\|w\\|_2 = 1, ~|b|\\leq \\max_{i} \\|x_i\\|_2} \\min_{i} \\ell_i(wx_i+b) \\neq \\emptyset.\n\t\\end{equation}\n\\end{proof}\n\n\\begin{lemma}\n\tIf $A_1,A_2$ are linearly separable, then\n\t\\begin{equation}\n\t\t\\mathop{\\rm argmax}_{\\|w\\|_2 = 1} \\min_{i} \\ell_i(wx_i+b)\n\t\\end{equation}\n\t is a singleton set.\n\\end{lemma}\n\n\\begin{proof}\n\tDenote $\\displaystyle m(w,b) = \\min_{i} \\ell_i(wx_i+b)$. Notice that $m(w,b)$ is a concave homogeneous function w.r.t $w,b$ and $\\|\\cdot\\|_2$ is a strictly convex norm. Suppose there are two solution $(w_1,b_1)$ and $(w_2,b_2)$ such that $w_1 \\neq w_2$, take $\\overline{w} = \\frac{w_1 + w_2}{2}, \\overline{b} = \\frac{b_1 + b_2}{2}$, we must have\n\t\\begin{equation}\n\t\tm(\\overline{w},\\overline{b}) \\geq \\frac{m(w_1,b_1)+ m(w_2,b_2)}{2} = \\max_{\\|w\\|_2 = 1} m(w,b),\n\t\\end{equation}\n\tand \n\t\\begin{equation}\n\t\t\\|\\overline{w}\\|_2 < 1.\n\t\\end{equation}\n\tSo\n\t\\begin{equation}\n\t\tm(\\frac{\\overline{w}}{\\|\\overline{w}\\|_2},\\frac{\\overline{b}}{\\|\\overline{w}\\|_2}) = \\frac{m(\\overline{w},\\overline{b}) }{\\|\\overline{w}\\|_2} > \\max_{\\|w\\|_2 = 1} m(w,b),\n\t\\end{equation}\n\twhich leads to a contradiction. So all the solutions must have the same $w$, we denote it as $w^*$. Then if $(w^*,b^*)$ is a solution of problem (\\ref{binarySVM}), we must have\n\t\\begin{equation}\n\t\tb^* \\in \\mathop{\\rm argmax}_{b} m(w^*,b)\n\t\\end{equation}\n\tActually,\n\t\\begin{equation}\n\t\tm(w^*,b) = \\min\\{b+\\min_{x\\in A_1} w^*x, -b +\\min_{x\\in A_2} (-w^*x)\\}.\n\t\\end{equation}\n\tIt is easy to observe that $\\displaystyle \\mathop{\\rm argmax}_{b} m(w^*,b)$ is a singleton set and \n\t\\begin{equation}\n\t\tb^* = \\frac{\\min_{x\\in A_2} (-w^*x) - \\min_{x\\in A_1} w^*x}{2}.\n\t\\end{equation}\n\\end{proof}\n\nDenote\n\\begin{equation}\\label{maxSVM}\n\t\\theta^*_{SVM} = (w_{SVM}^*,b_{SVM}^*) = \\mathop{\\rm argmax}_{\\|w\\|_2 = 1} \\min_{i} \\ell_i(wx_i+b).\n\\end{equation}\n\n\n\\begin{theorem}[Representation Theorem]\n\tLet $\\theta^*_{SVM} = (w_{SVM}^*,b_{SVM}^*) $ be the solution of \\eqref{maxSVM}. Then, $w_{SVM}^*$ must be a linear combination of $x_i^T, i = 1,2,\\cdots,N$.\n\\end{theorem}\n\n\\begin{proof}\n\tDenote\n\t\\begin{equation}\n\t\tS = {\\rm span} \\{x_i^T\\}_{i=1}^N.\n\t\\end{equation}\n\tThen we have\n\t\\begin{equation}\n\t\t\\mathbb{R}^{1\\times d} = S \\oplus^{\\perp} S^{\\perp}.\n\t\\end{equation}\n\tSo $w_{SVM}^*$ can be uniquely decomposed as $w_{SVM}^* = w^*_S + w^*_{S^{\\perp}}$ where $w_S\\in S$ and $w^*_{S^{\\perp}}\\in S^{\\perp}$. \n\tWe will prove that $w^*_{S^{\\perp}} = 0$. Suppose not, we have\n\t\\begin{equation}\n\t\t\\|w^*_S\\|_2 < \\|w_{SVM}^*\\|_2 = 1. \n\t\\end{equation}\n\tNotice that\n\t\\begin{equation}\n\t\tw_{SVM}^* x_i = w_S^* x_i,\\ \\forall i = 1,2,\\cdots,N.\n\t\\end{equation}\n\tThus we have\n\t\\begin{equation}\n\t\t\\min_{i} \\ell_i(w_{SVM}^*x_i+b_{SVM}^*) = \\min_{i} \\ell_i(w_S^*x_i+b_{SVM}^*).\n\t\\end{equation}\n\tSo\n\t\\begin{equation}\n\t\\min_{i} \\ell_i(w_{SVM}^*x_i+b_{SVM}^*) < \\frac{\\min_{i} \\ell_i(w_S^*x_i+b_{SVM}^*)}{\\|w_S^*\\|} = \\min_{i} \\ell_i(\\frac{w^*_S}{\\|w_S^*\\|_2}x_i+\\frac{b_{SVM}^*}{\\|w^*_S}\\|_2),\n\t\\end{equation}\n\twhich leads to a contradiction to the definition of $\\theta_{SVM}^*$.\n\\end{proof}\n\n%For any $w$ and $b$, the smallest distance between points and the hyperplane is \n%\\begin{equation}\n%\\frac{\\min_{i} y_i(wx_i+b)}{\\|w\\|_2}.\n%\\end{equation} Consider the problem\n%\\begin{equation}\n%\t\\max_{w,b} \\frac{\\min_{i} y_i(wx_i+b)}{\\|w\\|_2}.\n%\\end{equation}\n%Intuitively, the best separating hyperplane $H$ is only determined by those data points who are closest to $H$. Those data points are called {support vector}, and this method are called {support vector machine}.\n%\n%Without loss of generality, we may restrict the norm of $\\|w\\|$ to be 1, which leads to a equivalent optimization problem\n%\\begin{equation}\n%\\max_{\\|w\\|_2 = 1} \\min_{i} y_i(wx_i+b)\n%\\end{equation}\n%Actually, {we can prove $\\displaystyle \\mathop{\\rm argmax}_{\\|w\\|_2 = 1} \\min_{i} y_i(wx_i+b)$ is nonempty, but here we just admit this fact and only prove the uniqueness of the solution.}\n%\n%\\begin{lemma}\n%\tIf $A_1,A_2$ are linearly separable, then\n%\t\\begin{equation}\\label{binarySVM}\n%\t\t\\mathop{\\rm argmax}_{\\|w\\|_2 = 1} \\min_{i} y_i(wx_i+b)\n%\t\\end{equation}\n%\t is a singleton set.\n%\\end{lemma}\n%\n%\\begin{proof}\n%\tDenote $\\displaystyle m(w,b) = \\min_{i} y_i(wx_i+b)$. Notice that $m(w,b)$ is a concave homogeneous function w.r.t $w,b$ and $\\|\\cdot\\|_2$ is a strictly convex norm. Suppose there are two solution $(w_1,b_1)$ and $(w_2,b_2)$ such that $w_1 \\neq w_2$, take $\\overline{w} = \\frac{w_1 + w_2}{2}, \\overline{b} = \\frac{b_1 + b_2}{2}$, we must have\n%\t\\begin{equation}\n%\t\tm(\\overline{w},\\overline{b}) \\geq \\frac{m(w_1,b_1)+ m(w_2,b_2)}{2} = \\max_{\\|w\\|_2 = 1} m(w,b),\n%\t\\end{equation}\n%\tand \n%\t\\begin{equation}\n%\t\t\\|\\overline{w}\\|_2 < 1.\n%\t\\end{equation}\n%\tSo\n%\t\\begin{equation}\n%\t\tm(\\frac{\\overline{w}}{\\|\\overline{w}\\|_2},\\frac{\\overline{b}}{\\|\\overline{w}\\|_2}) = \\frac{m(\\overline{w},\\overline{b}) }{\\|\\overline{w}\\|_2} > \\max_{\\|w\\|_2 = 1} m(w,b),\n%\t\\end{equation}\n%\twhich leads to a contradiction. So all the solutions must have the same $w$, we denote it as $w^*$. Then if $(w^*,b^*)$ is a solution of problem (\\ref{binarySVM}), we must have\n%\t\\begin{equation}\n%\t\tb^* \\in \\mathop{\\rm argmax}_{b} m(w^*,b)\n%\t\\end{equation}\n%\tActually,\n%\t\\begin{equation}\n%\t\tm(w^*,b) = \\min\\{b+\\min_{x\\in A_1} w^*x, -b +\\min_{x\\in A_2} (-w^*x)\\}.\n%\t\\end{equation}\n%\tIt is easy to observe that $\\displaystyle \\mathop{\\rm argmax}_{b} m(w^*,b)$ is a singleton set and \n%\t\\begin{equation}\n%\t\tb^* = \\frac{\\min_{x\\in A_2} (-w^*x) - \\min_{x\\in A_1} w^*x}{2}.\n%\t\\end{equation}\n%\\end{proof}\n%\n%Denote\n%\\begin{equation}\\label{maxSVM}\n%\t\\theta^*_{SVM} = (w_{SVM}^*,b_{SVM}^*) = \\mathop{\\rm argmax}_{\\|w\\| = 1} \\min_{i} y_i(wx_i+b).\n%\\end{equation}\n%\n%\n%\\begin{theorem}[Representation Theorem]\n%\tLet $\\theta^*_{SVM} = (w_{SVM}^*,b_{SVM}^*) $ be the solution of \\eqref{maxSVM}. Then, $w_{SVM}^*$ must be a linear combination of $x_i^T, i = 1,2,\\cdots,N$.\n%\\end{theorem}\n%\n%\\begin{proof}\n%\tDenote\n%\t\\begin{equation}\n%\t\tS = {\\rm span} \\{x_i^T\\}_{i=1}^N.\n%\t\\end{equation}\n%\tThen we have\n%\t\\begin{equation}\n%\t\t\\mathbb{R}^{1\\times d} = S \\oplus^{\\perp} S^{\\perp}.\n%\t\\end{equation}\n%\tSo $w_{SVM}^*$ can be uniquely decomposed as $w_{SVM}^* = w^*_S + w^*_{S^{\\perp}}$ where $w_S\\in S$ and $w^*_{S^{\\perp}}\\in S^{\\perp}$. \n%\tWe will prove that $w^*_{S^{\\perp}} = 0$. Suppose not, we have\n%\t\\begin{equation}\n%\t\t\\|w^*_S\\|_2 < \\|w_{SVM}^*\\|_2 = 1. \n%\t\\end{equation}\n%\tNotice that\n%\t\\begin{equation}\n%\t\tw_{SVM}^* x_i = w_S^* x_i,\\ \\forall i = 1,2,\\cdots,N.\n%\t\\end{equation}\n%\tThus we have\n%\t\\begin{equation}\n%\t\t\\min_{i} y_i(w_{SVM}^*x_i+b_{SVM}^*) = \\min_{i} y_i(w_S^*x_i+b_{SVM}^*).\n%\t\\end{equation}\n%\tSo\n%\t\\begin{equation}\n%\t\\min_{i} y_i(w_{SVM}^*x_i+b_{SVM}^*) < \\frac{\\min_{i} y_i(w_S^*x_i+b_{SVM}^*)}{\\|w_S^*\\|} = \\min_{i} y_i(\\frac{w^*_S}{\\|w_S^*\\|_2}x_i+\\frac{b_{SVM}^*}{\\|w^*_S}\\|_2),\n%\t\\end{equation}\n%\twhich leads to a contradiction to the definition of $\\theta_{SVM}^*$.\n%\\end{proof}\n\n\\subsection{Soft margin maximization and kernel methods}\n\nWe may rewrite the SVM problem as\n\\begin{align} \n\t\\max_{w,b}&\\ {2\\over \\|w\\|},\\\\\n\ts.t.&\\ \\ell_i(wx_i+b) \\geq 1,\\ \\forall i. \n\\end{align}\nor equivalently,\n\\begin{align}{\\label{SVM_Quad}}\n\t\\min_{w,b}&\\ \\|w\\|^2,\\\\\n\ts.t.&\\ \\ell_i(wx_i+b) \\geq 1,\\ \\forall i. \n\\end{align}\nNotice that the feasible domain of margin maximization is nonempty if and only if dataset is linearly separable. So when the data is linearly nonseparable, this method can't even get a classifier even though it may not be good. One way to handle this problem is to relax the constraint by adding relaxation variables. \n\nDefine soft margin maximization problem\n\\begin{align}{\\label{SVM_Quad_soft}}\n\\min_{w,b,\\xi}&\\ \\|w\\|^2 + \\lambda^{-1} \\sum_{i = 1}^N\\xi_i,\\\\\ns.t.&\\ \\ell_i(wx_i+b) + \\xi_i \\geq 1,\\ \\forall i. \\\\\n     &\\ \\xi_i \\geq 0.\n\\end{align}\nwhere $\\lambda>0$. The above problem is equivalent to\n \\begin{align}\n \\min_{w,b}&\\ \\|w\\|^2 + \\lambda^{-1} \\sum_{i = 1}^N {\\rm ReLU}(1-\\ell_i(wx_i+b)).\n \\end{align}\nThus, soft margin maximization problem \\eqref{SVM_Quad_soft} can be reformulated as\n \\begin{align}{\\label{SVM_soft}}\n\\min_{w,b}&\\  \\sum_{i = 1}^N {\\rm ReLU}(1-\\ell_i(wx_i+b)) + \\lambda \\|w\\|^2.\n\\end{align}\nWe can still prove that the solution of (\\ref{SVM_soft}) satisfies the representation theorem. Thus we can restrict $w$ to be in the set $S$. Assume that  \n\\begin{equation}\n\tw = \\sum_{i = 1}^N \\alpha_i x_i^T, \n\\end{equation}\nDenote $\\alpha = (\\alpha_1,\\cdots,\\alpha_N)^T$. We can rewrite the problem (\\ref{SVM_soft}) as \n\\begin{equation}\n\\min_{\\alpha}\\ \\sum_{i = 1}^N {\\rm ReLU}(1-\\ell_i(\\sum_{j = 1}^N \\langle x_i,x_j\\rangle \\alpha_j+b)) + \\lambda\\alpha^T \\big(\\langle x_i,x_j\\rangle\\big)_{N\\times N} \\alpha\\\\\n\\end{equation}\nWe can see that the whole problem is only determined by the inner product of data points but not the data itself directly. \\\\\n\nUse the above formulation, we can induce nonlinearity in SVM. Denote the input space as $X$ where $\\{x_i\\}_{i=1}^N \\subset X$. We use two steps to obtain a nonlinear classification model. First, we use a nonlinear feature mapping $\\phi: X\\rightarrow \\mathcal{H}$ to map input space $X$ to a feature space $\\mathcal{H}$. Second, we use linear SVM to do classification on $\\{\\phi(x_i)\\}_{i=1}^N\\subset \\mathcal{H}$.\\\\\n\nWe may just asssume dataset after feature mapping $\\phi$ is linearly separable. Then, the SVM problem after doing feature mapping can be formulated as\nproblem (\\ref{SVM_soft}) as \n\\begin{equation}\n\\min_{\\alpha}\\ \\sum_{i = 1}^N {\\rm ReLU}(1-\\ell_i(\\sum_{j = 1}^N \\langle \\phi(x_i),\\phi(x_j)\\rangle \\alpha_j+b)) + \\lambda\\alpha^T \\big(\\langle \\phi(x_i),\\phi(x_j)\\rangle\\big)_{N\\times N} \\alpha\\\\\n\\end{equation}\n\nNotice that to obtain the above problem we don't really need to know what exactly is the nonlinear mapping $\\phi$, but only need to compute the value of $<\\phi(x_i),\\phi(x_j)>$. So we define a kernel function $k: X\\times X\\rightarrow \\mathbb{R}$ such that \n\\begin{equation}\n\tk(x,y) = \\langle\\phi(x),\\phi(y)\\rangle,\\ x,y\\in X.\n\\end{equation}\nThen the kernel SVM can be formulated as\n\\begin{equation}\n\\min_{\\alpha}\\ \\sum_{i = 1}^N {\\rm ReLU}(1-\\ell_i(\\sum_{j = 1}^N  k(x_i,x_j) \\alpha_j+b)) + \\lambda\\alpha^T \\big(k(x_i,x_j)\\big)_{N\\times N} \\alpha\\\\\n\\end{equation}\nIn practice, we just need to find a proper kernel function instead of a good nonlinear feature mapping. Here we list some common used kernel functions:\n\\begin{itemize}\n\t\\item Polynomial kernel: $k(x,y) = (a\\langle x,y\\rangle+ b)^n, a > 0, b\\geq 0, n\\in \\mathbb{N}^+$.\n\t\\item Gaussian kernel: $k(x,y) = e^{-\\gamma\\|x-y\\|^2}, \\gamma > 0$.\n\t\\item Laplacian kernel: $k(x,y) = e^{-\\gamma\\|x-y\\|}, \\gamma > 0$\n\t\\item Tanh kernel: $k(x,y) = \\tanh(a\\langle x,y\\rangle+b), a>0, b\\geq 0.$\n\\end{itemize}\n\n\\subsection{Binary logistic regression}\nIn multi-class Logistic regression, if we use $\\|W\\|$ to replace $\\|\\bm\\theta\\|$ in regularization term,  we can get another version of logistic regression:\n\\begin{equation}\n\t\\mathcal L_\\lambda(\\bm \\theta) = - \\sum_{i=1}^k \\sum_{x\\in A_i} \\log p_{i}(x;\\bm \\theta) + \\lambda R(\\|W\\|),\n\\end{equation}\nwhere $p_i(x;\\bm \\theta)$ and $R(\\cdot)$ share the same definitions as in previous sections of logistic regression.\nLet  \n\\begin{equation}\n\\bm\\Theta_{\\lambda} = \\mathop{{\\arg\\min}}_{\\bm\\theta}  \\mathcal L_\\lambda(\\bm\\theta).\n\\end{equation}\nThe following lemma follows directly from the definition of $p_{i}(x;\\bm \\theta)$.\n\\begin{lemma}\n\tFor any $W\\in \\mathbb{R}^{k\\times d}, b\\in \\mathbb{R}^k, \\alpha \\in \\mathbb{R}$, we have\n\t\\begin{equation}\n\t\t\\mathcal L_\\lambda(W,b) = \\mathcal L_\\lambda(W,b + \\alpha \\bm 1),\n\t\\end{equation}\n\twhere $\\bm 1 = (1,1,\\cdots,1)^T\\in\\mathbb{R}^k.$\n\\end{lemma}\n\nBinary logistic regression refers to the case when $k=2$.\n\\begin{lemma}\n\tIf $k = 2$, given any $\\bm\\theta_\\lambda = \\begin{pmatrix}\n\tw_1 &  b_1\\\\\n\tw_2 & b_2 \n\t\\end{pmatrix} \\in \\bm\\Theta_\\lambda$, we have\n\t\\begin{equation*}\n         w_1 = -w_2.\n\t\\end{equation*}\n\\end{lemma}\n\nAccording to the above two lemmas, we can restrict $\\bm\\theta$ to have the form\n\\begin{equation}\n\t\\bm\\theta = \\begin{pmatrix}\n\t\\frac{w}{2}\\ &\\frac{b}{2}\\\\\n\t-\\frac{w}{2}\\ &-\\frac{b}{2}\n\t\\end{pmatrix},\n\\end{equation}\nso our score mapping can be written as\n\\begin{equation}\\label{key}\n\\bm p(x;\\theta) = \\begin{pmatrix} \n\t\\frac{1}{1+ e^{-(wx+b)}}\\\\\n\t\\frac{1}{1+e^{wx+b}}\n\\end{pmatrix}.\n\\end{equation}\nDenote $\\theta = (w,b)$ where $w\\in \\mathbb{R}^d, b\\in \\mathbb{R}$, correspondingly, we have\n\\begin{equation}\nP(\\theta) = \\prod_{i = 1}^N \\frac{1}{1+ e^{-y_i(wx+b)}}.\n\\end{equation}\nHere we have the new ``label'' $y_i$ defined by\n\\begin{equation}\\label{key}\ny_i = \\begin{cases}\n1, \\quad &\\text{if}  \\quad x_i \\in A_1 \\\\\n-1, \\quad &\\text{if} \\quad x_i \\in A_2\n\\end{cases}.\n\\end{equation}\nThus we have\n\\begin{equation}\nL(\\theta) = -\\log P(\\theta) = \\sum_{i = 1}^N \\log(1+ e^{-y_i(wx+b)}),\n\\end{equation}\nand take $R(t) = t^2$, we have\n\\begin{equation}\n\\mathcal L_{\\lambda}(\\theta)  = L(\\theta) + \\lambda \\|w\\|_2^2 = \\sum_{i = 1}^N \\log(1+ e^{-y_i(wx+b)}) + \\lambda \\|w\\|_2^2.\n\\end{equation}\nHere $L(\\theta)$ is a strictly convex function without any global minima. \n\n\n\\begin{lemma}\nAssume that $A_1,A_2$ are linearly separable, and we follow the same definition\nof linearly classifiable weights:\n\\begin{equation}\n\\bm{\\Theta} = \\left\\{\\bm\\theta: p_i(x; \\bm\\theta)>p_j(x; \\bm\\theta),~\\forall x\\in A_i, j\\neq i, i= 1,2\\right\\},\n\\end{equation}\nwhere \n\\begin{equation}\\label{key}\n\\bm p(x;\\theta) = \\begin{pmatrix} \n\\frac{1}{1+ e^{-(wx+b)}}\\\\\n\\frac{1}{1+e^{wx+b}}\n\\end{pmatrix}.\n\\end{equation}\nThen, we have the following statement:\\\\\n\n\\begin{enumerate}\n\n\\item  $\\theta = (w,b) \\in \\Theta$ if and only if\n\t\t\\begin{equation*}\n\t\t\\frac{1}{1+ e^{-y_i(wx+b)}} > \\frac{1}{2},\\ \\forall i = 1,2\\cdots,N.\n\t\t\\end{equation*} \n\\item  If $P(\\theta) > \\frac{1}{2}$, then $\\theta$ must be classifiable, i.e.\n\\begin{equation*}\n\t\\{\\theta: P(\\theta)>\\frac{1}{2}\\}\\subset \\bm \\Theta.\n\\end{equation*}\n\\item  Prove that\n\\begin{equation*}\n\t\\bm\\Theta = \\{\\theta: \\lim_{\\alpha\\rightarrow +\\infty} P(\\alpha \\theta) = 1\\}.\n\\end{equation*}\n\\end{enumerate}\n\\end{lemma}\n\n \n \n\tIf $A_1,A_2$ are linearly separable, then\n$\\displaystyle \n\\mathop{\\rm argmin}_{w,b} \\mathcal L_{\\lambda}(\\theta)\n$\n\tis nonempty for $\\lambda $ sufficiently small.\n\n\n\\begin{lemma}\n\t\tIf $A_1,A_2$ are linearly separable, then\n\t\\begin{equation}\\label{binaryLR}\n\t\\mathop{\\rm argmin}_{w,b} \\mathcal L_{\\lambda}(\\theta)\n\t\\end{equation}\n\tis a singleton set for $\\lambda $ sufficiently small.\n\\end{lemma}\n\n\\begin{proof}\nBecause $L(\\theta)$ is strictly convex w.r.t. $\\theta$ and $\\|w\\|^2$ is convex w.r.t. $\\theta$, so $\\mathcal L(\\theta,\\lambda)  = L(\\theta) + \\lambda \\|w\\|_2^2$ is stricly convex w.r.t. $\\theta$, which implies our result directly.\n\n\\end{proof}\n\nFor $\\lambda$ sufficiently small, denote\n\\begin{equation}\n\t\\theta_{LR}(\\lambda) = (w_{LR}(\\lambda),b_{LR}(\\lambda)) = \\mathop{\\rm argmin}_{w,b} \\mathcal L_{\\lambda}(\\theta).\n\\end{equation}\n\n\\begin{lemma}\n\tIf $A_1,A_2$ are linearly separable,  \n\t\\begin{enumerate}\n\t\\item $\\mathcal L_{\\lambda}(\\theta) \\rightarrow 0$ as $\\lambda \\rightarrow 0$.\n\t\\item $\\|w_{LR}(\\lambda)\\|\\rightarrow \\infty$ as $\\lambda \\rightarrow 0$.\n\t\\item $\\displaystyle \\min_{i} y_i(w_{LR}(\\lambda) x_i + b_{LR}(\\lambda))\\rightarrow \\infty$ as $\\lambda \\rightarrow 0$.\n\t\\item If $A_1,A_2$ are also nonempty, \n\t\\begin{equation}\n\t\t\\|b_{LR}(\\lambda)\\|\\leq \\max_{i} \\|x_i\\| \\|w_{LR}(\\lambda)\\|\n\t\\end{equation}\n\tfor $\\lambda$ sufficiently small.\n\t\\end{enumerate}\n\\end{lemma}\n\nThe above lemma implies that $\\theta_{LR}(\\lambda)/\\|w_{LR}(\\lambda)\\|$ is bounded for $\\lambda$ sufficiently small.\n\n\\begin{theorem}\n\tIf $A_1,A_2$ are linearly separable, then $\\frac{\\theta_{LR}(\\lambda)}{\\|w_{LR}(\\lambda)\\|}$ converge to $\\theta^*_{SVM}$ as $\\lambda \\rightarrow 0$, i.e.\n\t\\begin{equation}\n\t\t\\theta^*_{SVM} = \\lim_{\\lambda\\rightarrow 0} \\frac{\\theta_{LR}(\\lambda)}{\\|w_{LR}(\\lambda)\\|}.\n\t\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\n\tBecause $\\frac{\\theta_{LR}(\\lambda)}{\\|w_{LR}(\\lambda)\\|}$ is bounded for $\\lambda$ sufficiently small, we only need to prove that it has no convergence points other than $\\theta^*_{SVM}$ as $\\lambda \\rightarrow 0$.\\\\\n\tWe first introduce a soft margin function $m: \\mathbb{R}^n \\rightarrow \\mathbb{R}$ such that \n\t\\begin{equation}\n\t\tm(\\theta) = \\min_{i} y_i(wx_i + b).\n\t\\end{equation}\n\tSuppose that there exist a sequence $\\{\\lambda_n\\}_{n = 1}^\\infty$ and $\\bar{\\theta} = (\\bar{w},\\bar{b}) \\neq \\theta^*_{SVM}$ so that  $\\lambda_n \\downarrow 0$ and $\\frac{\\theta_{LR}(\\lambda_n)}{\\|w_{LR}(\\lambda_n)\\|} \\rightarrow \\bar{\\theta}$ as $n\\rightarrow \\infty$. Obviously $\\|\\bar{w}\\| = 1$, and \n    \\begin{equation}\n    \t0 \\leq m(\\bar{\\theta}) < m(\\theta^*_{SVM}).\n    \\end{equation}\n     Take a positive number $\\epsilon < m(\\theta^*_{SVM}) - m(\\bar{\\theta})$. Then there exists $K_0\\in \\mathbb{N}^+$ such that \n    \\begin{equation}\n    0 < m(\\frac{\\theta_{LR}(\\lambda_n)}{\\|w_{LR}(\\lambda_n)\\|}) <  m(\\theta^*_{SVM})- \\epsilon,\n    \\end{equation}\n    for all $n \\geq K_0$.\\\\\n    \n    Consider $\\theta_n = (w_n,b_n) = \\|w_{LR}(\\lambda_n)\\|\\theta^*_{SVM}$. Then\n    \\begin{equation}\n    \\lim_{n\\rightarrow \\infty} \\frac{\\log(1 + e^{-m(\\theta_n)})}{\\log(1 + e^{-m(\\theta_{LR}(\\lambda_n))}} = \\lim_{n \\rightarrow \\infty} e^{\\|w_{LR}(\\lambda_n)\\| (m(\\frac{\\theta_{LR}(\\lambda_n)}{\\|w_{LR}(\\lambda_n)\\|}) -  m(\\theta^*_{SVM}))} \\leq \\lim_{n \\rightarrow \\infty} e^{-\\|w_{LR}(\\lambda_n)\\| \\epsilon} = 0.\n    \\end{equation}\n    So there exists a $K_1 \\in \\mathbb{N}^+$ such that \n    \\begin{equation}\n    \tN \\log(1 + e^{-m(\\theta_n)}) < \\log(1 + e^{-m(\\theta_{LR}(\\lambda_n))}) \n    \\end{equation}\n    for all $n \\geq K_1$. Take $K  = \\max\\{K_0, K _1\\}$. Then for all $n \\geq K$, we have \n    \\begin{equation}\n    \t\\mathcal{L}(\\theta_n) \\leq N \\log(1 + e^{-m(\\theta_n)}) + \\lambda \\|w_{\\lambda_n}\\|^2 < \\log(1 + e^{-m(\\theta_{LR}(\\lambda_n))})+ \\lambda \\|w_{\\lambda_n}\\|^2 \\leq \\mathcal{L}(\\theta_{LR}(\\lambda_n)),\n    \\end{equation} \n    which contradicts the definition of $\\theta_{LR}(\\lambda)$.\n\\end{proof}\n\n\nFor the proof of the above theorem, you can also refer to the paper by Rosset Saharon, Zhu Ji and Trevor J. Hastie~ \\cite{rosset2004margin}. ", "meta": {"hexsha": "5fcc83657abfea46992473fdf2b060e722ebced5", "size": 21488, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/2 Linear Machine Learning Models/2.4-binaryLRSVM.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/2 Linear Machine Learning Models/2.4-binaryLRSVM.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/2 Linear Machine Learning Models/2.4-binaryLRSVM.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.9539748954, "max_line_length": 506, "alphanum_fraction": 0.6478965004, "num_tokens": 8517, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951064805861, "lm_q2_score": 0.863391624034103, "lm_q1q2_score": 0.7286119664987054}}
{"text": "\\section{Equations of Order One}\n\n\\subsection{Separation of Variables}\n\nWe begin with equations of the form\n\n\\begin{equation}\n    Mdx+Ndy=0\n\\end{equation}\nwhere $M$ and $N$ can be multivariate of $x,y$.\n\nIt is separable iff\n\\begin{equation}\n    A(x)dx+B(y)dy=0.\n\\end{equation}\n\nThen find a function $F$ with total differential being the LHS of above, so $F=c$.\n\n\\subsection{Homogeneity}\n\n\\begin{definition}[Homogeneity of polynomials]\n    Polynomials where all terms are of the same degree are homogeneous.\n\\end{definition}\n\nHomoegeneity of functions is analogous to assigning physical dimensions (e.g. length) to all of the variables.\nIf the function has the length dimension to the $k$th power, then it is homogeneous of degree $k$.\n\n\\begin{example}\n    If $x,y$ are lengths, then the following is homogeneous of degree 3.\n    \\begin{equation}\n        f(x,y)=2y^3\\exp(\\frac{y}{x})-\\frac{x^4}{x+3y}\n    \\end{equation}\n\\end{example}\n\nAlternate definition also suffices for generality.\n\n\\begin{definition}[Homogeneous function]\n    $f(x,y)$ is homogeneous of degree $k$ iff $f(\\lambda x, \\lambda y)=\\lambda^kf(x,y)$.\n\\end{definition}\n\n\\begin{definition}[Alternate definition of homogeneity]\n    If $f(x,y)$ can be rewritten as $f(\\frac{y}{x})$ or $f(\\frac{x}{y})$ then it is homogeneous.\n\\end{definition}\n\n\\subsection{Homogeneous Differential Equations}\n\n\\begin{theorem}[Homogeneous DEs]\n    If $M(x,y)$ and $N(x,y)$ are homogeneous and of same degree, then $M(x,y)dx+N(x,y)dy=0$\n    is a homogeneous DE.\n\\end{theorem}\n    \n\\begin{theorem}[Homogeneous DEs]\n    $M(x,y)/N(x,y)$ is homogeneous of degree 0.\n\n    \\begin{proof}\n        If $M,N$ are homogeneous of some degree $n$, then\n        \\begin{eqnarray}\n            M(x,y)=M(\\lambda x,\\lambda y)=\\lambda ^nM(x,y)\\\\\n            M(x,y)=N(\\lambda x,\\lambda y)=\\lambda ^nN(x,y)\n        \\end{eqnarray}\n        So for $M/N$,\n        \\begin{eqnarray}\n            \\frac{M(x,y)}{N(x,y)}=\\lambda^0\\frac{M(1,v)}{N(1,v)}\n        \\end{eqnarray}\n        which is homogeneous of degree 0.\n    \\end{proof}\n\\end{theorem}\n\n\\begin{theorem}[Homogeneous DEs]\n    If $f(x,y)$ is homogeneous of degree 0 in $x,y$, then $f(x,y)$ is a function of $y/x$ alone.\n    \\begin{proof}\n        Let $y=vx$. Then, $f$ must be proven to be of $v$ alone. Substitute so that\n        \\begin{equation}\n            f(x,y)=f(x,vx)=x^0f(1,v)=f(1,v)\n        \\end{equation}\n    \\end{proof}\n\\end{theorem}\n\n\\subsection{Homogeneous Coefficients}\n\nSuppose coefficients $M,N$ in the equation\n\n\\begin{equation}\n    M(x,y)dx+N(x,y)dy=0\n\\end{equation}\n\nare both homogeneous of same degree. So $M/N$ is a function of $y/x$ alone.\nCan put in form using $y=vx$.\n\\begin{eqnarray}\n    \\frac{dy}{dx}+g(\\frac{y}{x})=0\\\\\n    x\\frac{dv}{dx}+g(v)=0\n\\end{eqnarray}\n\nThis last equation is separable.\n\n\\subsection{Exact Equations}\n\nIf there exists an equation of the form $A(x)dx+B(y)dy=0$, the solution is a function with differential $A(x)dx+B(y)dy$.\nIdea works for equations of form\n\n\\begin{equation}\n    dF=Mdx+Ndy.\n\\end{equation}\n\nSo, $F(x,y)=c\\implies dF=0$ and\n\n\\begin{equation}\n    Mdx+Ndy=0.\n\\end{equation}\n\nIf there's a function $F$ such that $Mdx+Ndy$ is the \\textbf{total differential}\nof $F$, then Eq. 5 is an \\textit{exact equation} by definition. Can rewrite the total differential from the chain rule:\n\n\\begin{equation}\n    dF=\\frac{\\partial F}{\\partial x}dx+\\frac{\\partial F}{\\partial y}dy.\n\\end{equation}\n\nSo $M=\\frac{\\partial F}{\\partial x},N=\\frac{\\partial F}{\\partial y}$. We can take 2nd derivative to show these are equal because the partials are continuous (Clairaut's theorem).\n\n\\begin{eqnarray}\n    \\frac{\\partial M}{\\partial y}=\\frac{\\partial^2 F}{\\partial y\\partial x}\\\\\n    \\frac{\\partial N}{\\partial x}=\\frac{\\partial^2 F}{\\partial y\\partial x}.\n\\end{eqnarray}\n\n\\begin{definition}[Exactness]\n    \\begin{equation}\n        \\frac{\\partial M}{\\partial y}=\\frac{\\partial N}{\\partial x}.\n    \\end{equation}\n\\end{definition}\n\n\\begin{proof}\n    Let $\\phi(x,y)$ be a function where $\\frac{\\partial \\phi}{\\partial x}=M$. $\\phi$ is the function you get from integrating $Mdx$ wrt $x$ and holding $y$. Then\n\n    \\begin{equation}\n        \\frac{\\partial^2\\phi}{\\partial y\\partial x}=\\frac{\\partial M}{\\partial y}=\\frac{\\partial N}{\\partial x}\n    \\end{equation}\n\n    Integrating both sides wrt $x$:\n\n    \\begin{equation}\n        \\frac{\\partial \\phi}{\\partial x}=N+B'(y)\n    \\end{equation}\n\n    where $B'(y)$ is the integration constant. Let\n\n    \\begin{equation}\n        F=\\phi(x,y)-B(y)\n    \\end{equation}\n\n    such that \n\n    \\begin{align}\n        dF&=\\frac{\\partial \\phi}{\\partial x}dx+\\frac{\\partial \\phi}{\\partial y}dy-B'(y)dy\\\\\n        &=Mdx+\\left[N+B'(y)\\right]dy-B'(y)dy\\\\\n        &=Mdx+Ndy\n    \\end{align}\n\\end{proof}\n\n\\begin{example} We have the DE\n    \\begin{equation}\n        3x(xy-2)dx+(x^3+2y)dy=0.\n    \\end{equation}\n\n    Then, \n\n    \\begin{equation}\n        \\frac{\\partial M}{\\partial y}=3x^2,\\frac{\\partial N}{\\partial y}=3x^2\n    \\end{equation}\n\n    The DE is exact, and $F=c$ is the solution.\n\n    \\begin{eqnarray}\n        \\frac{\\partial F}{\\partial x}=M=3x^2y-6x\\\\\n        \\frac{\\partial F}{\\partial y}=N=x^3+2y\n    \\end{eqnarray}\n\n    Try to find $F$ from 18, integrate both sides wrt $x$ with an integration constant $T(y)$.\n\n    \\begin{equation}\n        F=x^3y-3x^2+T(y)\n    \\end{equation}\n\n    Using Eq. 19, can can find $\\frac{\\partial F}{\\partial y}$ from Eq. 20 and equate:\n\n    \\begin{equation}\n        x^3+T'(y)=x^3+2y\\implies T'(y)=2y\n    \\end{equation}\n\n    Because $F=c$ is the I.C., can conclude \n\n    \\begin{equation}\n        T(y)=y^2\n    \\end{equation}\n\n    Thus,\n\n    \\begin{equation}\n        F=x^3y-3x^2+y^2\\Leftrightarrow x^3y-3x^2+y^2=c\n    \\end{equation}\n\\end{example}\n\n\\subsection{Linear Equations of Order 1}\n\nIf an equation is not exact, can attempt to do so by multiplying DE by an integrating factor.\n\n\\begin{definition}[Linear DE of order 1]\n    \\begin{equation}\n        A(x)\\frac{dy}{dx}+B(x)y=C(x)\n    \\end{equation}\n\\end{definition}\n\nDivide each side by $A(x)$ to obtain\n\n\\begin{equation}\n    \\frac{dy}{dx}+P(x)y=Q(x)\n\\end{equation}\n\nSuppose there exists for Eq. 25 a I.F. $v(x)>0$. Then,\n\n\\begin{equation}\n    v(x)\\left[\\frac{dy}{dx}+P(x)y\\right]=v(x)Q(x)\n\\end{equation}\n\nbecomes exact, or of form $Mdx+Ndy=0$. Here,\n\n\\begin{eqnarray}\n    M=vPy-vQ\\\\\n    N=v\n\\end{eqnarray}\n\nBecause the requirement is $\\frac{\\partial M}{\\partial y}=\\frac{\\partial N}{\\partial x}$,\n\n\\begin{align}\n    vP&=\\frac{dv}{dx}\\\\\n    Pdx&=\\frac{dv}{v}\\\\\n    \\ln v&=\\int Pdx\\\\\n    v&=\\exp(\\int Pdx)\n\\end{align}\n\nWe can then multiply both sides of the DE by this I.F. One side of this eqn will be of the product rule form, the derivative of $y\\exp (\\int Pdx)$:\n\n\\begin{equation}\n    \\exp(\\int Pdx)\\frac{dy}{dx}+P\\exp(\\int Pdx)y=Q\\exp(\\int Pdx)\n\\end{equation}\n\n\\subsection{General Solution of a Linear Equation}\n\nGiven the original form\n\n\\begin{equation}\n    \\frac{dy}{dx}+P(x)y=Q(x)\n\\end{equation}\n\nsuppose $P$ and $Q$ are continuous on $x\\in (a,b)$ and $x=x_0$ is such a number. $y=y_0$ satisfies the initial condition.\nThis sol'n satisfies Eq. 34 for all $x$ in the interval. Multiplying Eq. 34 by integrating factor $\\exp(\\int Pdx)$ gives\n\n\\begin{equation}\n    yv=\\int vQ\\:dx + c\n\\end{equation}\n\nBecause $v\\neq 0$,\n\n\\begin{equation}\n    y=v^{-1}\\int vQ\\: dx + cv^{-1}\n\\end{equation}\n\nGiven any $x_0,y_0$ in the interval, can find $c$ s.t. the DE is satisfied.\nEvery eqn of above form will have $P,Q$ with common interval of continuity and a unique set of solutions with one I.C. obtained by using the integrating factor.\nThese solutions are unique, so any other method yields a solution that aligns with the general solution–all possible solutions satisfying the DE on $x\\in (a,b)$.\n\n\\subsection{Application of Mixing Problem}\n\nStrategy is to determine the differential equation describing rate of change of a certain quantity, then finding the particular solution with some trivial IC.\n\n\\begin{example}\n    100 liter tank contains 10 kg salt mixed with 60 liter water. Sol'n with concentration 0.1 $\\frac{\\mathrm{kg}}{\\mathrm{liter}}$ flows in at rate 5 liters/min.\n    Solution is well stirred (asume equal distribution), outflow rate of 3 liters/min. Need to find salt in tank when it is full.\n\n    Note that the tank will become full, as $\\mathrm{in}-\\mathrm{out}>0$. Let $x$ be kg of salt.\n    Then, inflow rate is $0.1 \\frac{\\mathrm{kg}}{\\mathrm{liter}}\\cdot 5\\frac{\\mathrm{liter}}{\\mathrm{min}}=0.5\\frac{\\mathrm{kg}}{\\mathrm{min}}$. Out is\n    $x \\frac{\\mathrm{kg}}{60\\;\\mathrm{liter}}\\cdot 3\\frac{\\mathrm{liter}}{\\mathrm{min}}=\\frac{x}{20}\\frac{\\mathrm{kg}}{\\mathrm{min}}$. We then express the DE as\n\n    \\begin{equation}\n        \\frac{dx}{dt}=0.5-\\frac{x}{20}\n    \\end{equation}\n\n    Then just express in linear form, solve with I.F. method.\n\\end{example}\n\n\\begin{example}\n    Initially 50 gallons of brine, 10 lb dissolved salt. Inflow of 2 lb salt/gal at 5 gal/min, outflow of 3 gal/min, but \\textbf{mixture kept uniform}.\n\n    Inflow is thus 10 lb/min, outflow is $\\frac{3x}{50+2t}$ lb/min. Key here is that mixture concentration on outflow does not change, so the volume dynamically adapts for changing amount of salt.\n    50 gallons initially, influx of 5 gal - 3 gal out $\\implies 50+(5-3)t$.\n    DE is thus\n\n    \\begin{equation}\n        \\frac{dx}{dt}=10-\\frac{3x}{50+2t}\n    \\end{equation}\n\\end{example}\n\n\\subsection{Integrating Factor by Inspection}\n\nBy recognizing differentials in a problem, can find the integrating factor by inspection.\n\n\\begin{example}\n    Given\n    \\begin{equation}\n        ydx+(x+x^3y^2)dy=0\n    \\end{equation}\n    the terms can be grouped by like degree so\n    \\begin{equation}\n        (ydx+xdy)+x^3y^2dy=0.\n    \\end{equation}\n    Can be rewritten as\n    \\begin{equation}\n        d(xy)+x^3y^2dy=0\n    \\end{equation}\n    then divide by $(xy)^3$ for it does not affect integrability of $d(xy)$ term but keeps function of $y$ with $dy$ term,\n    \\begin{equation}\n        \\frac{d(xy)}{(xy)^3}+\\frac{dy}{y}=0.\n    \\end{equation}\n    Integrating:\n    \\begin{align}\n        \\int (xy)^{-3}d(xy)+\\int \\frac{dy}{y}&=0\\\\\n        \\frac{(xy)^{-2}}{-2}+\\ln|y|=C\\\\\n        Cy=\\frac{(xy)^{-2}}{2}\\\\\n        Cy(xy)^2=1\n    \\end{align}\n\\end{example}\n\n\\subsection{Determining Complex Integrating Factors}\n\nLet there be the DE\n\n\\begin{equation}\n    Mdx+Ndy=0.\n\\end{equation}\n\nSuppose $\\exists u$, possibly of both $x,y$ that is an integrating factor such that\n\n\\begin{equation}\n    uMdx+uNdy=0\n\\end{equation}\n\nand for it to be exact,\n\n\\begin{equation}\n    \\frac{\\partial}{\\partial y}(uM)=\\frac{\\partial}{\\partial x}(uN)\n\\end{equation}\n\nso $u$ satisfies\n\n\\begin{eqnarray}\n    u\\frac{\\pr M}{\\pr y}+M\\frac{\\pr u}{\\pr y}=u\\frac{\\partial N}{\\partial x}+N\\frac{\\pr u}{\\pr x}\\\\\n    u(\\frac{\\pr M}{\\pr y}-\\frac{\\pr N}{\\pr x})=N\\frac{\\pr u}{\\pr x}-M\\frac{\\pr u}{\\pr y}.\n\\end{eqnarray}\n\nThis does not lead anywhere, so let $u$ be a function of $x$. Thus, $\\pr u/\\pr y=0,\\pr u/\\pr x=du/dx$.\nSo the above reduces to\n\n\\begin{equation}\n    u(\\frac{\\pr M}{\\pr y}-\\frac{\\pr N}{\\pr x})=N\\frac{du}{dx}\\Leftrightarrow \\frac{1}{N}(\\frac{\\pr M}{\\pr y}-\\frac{\\pr N}{\\pr x})dx=\\frac{du}{u}\n\\end{equation}\n\nand integrating factor is the following, assuming LHS of above is a function of $x$ or $y$ alone\n\\begin{eqnarray}\n    u=\\exp\\left[\\int f(x)dx\\right]\\;(\\text{for $x$})\\\\\n    u=\\exp\\left[\\int -g(y)dy\\right]\\;(\\text{for $y$})\n\\end{eqnarray}", "meta": {"hexsha": "d7818ca6e5ba85be252d9a3e8722cff2bd660233", "size": 11368, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "differential-equations/tex/unit-2.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "differential-equations/tex/unit-2.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "differential-equations/tex/unit-2.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.7243243243, "max_line_length": 196, "alphanum_fraction": 0.6495425757, "num_tokens": 3828, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7286119546332681}}
{"text": "\\section{Addition}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Perform the operations of matrix addition and subtraction.\n  \\item Identify when these operations are not defined.\n  \\item Apply the algebraic properties of matrix addition to\n    manipulate an algebraic expression involving matrices.\n  \\end{enumerate}\n\\end{outcome}\n\nTo add two matrices, the matrices have to be of the same size. The\naddition works by simply adding corresponding entries of the matrices.\n\n\\begin{definition}{Addition of matrices}{addition-of-matrices}\n  Let $A=\\mat{a_{ij}}$ and $B=\\mat{b_{ij}}$ be two\n  $m\\times n$-matrices. Then $A+B=C$%\n  \\index{matrix!addition}%\n  \\index{sum|see{addition}}%\n  \\index{addition!of matrices} where $C$ is the $m\\times n$-matrix\n  $C=\\mat{c_{ij}}$ defined by\n  \\begin{equation*}\n    c_{ij}=a_{ij}+b_{ij}\n  \\end{equation*}\n\\end{definition}\n\n\\begin{example}{Addition of matrices}{same-size-matrix-addition}\n  Add the following matrices.\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      1 & 0 & 4\n    \\end{mymatrix},\\quad\n    B = \\begin{mymatrix}{rrr}\n      5 & 2 & 3 \\\\\n      -6 & 2 & 1\n    \\end{mymatrix}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  Notice that both $A$ and $B$ are of size $2\\times 3$.\n  Since $A$ and $B$ are of the same size, the addition is possible. Using Definition~\\ref{def:addition-of-matrices},\n  the addition is done as follows.\n  \\begin{equation*}\n    A + B = \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      1 & 0 & 4\n    \\end{mymatrix}\n    +\n    \\begin{mymatrix}{rrr}\n      5 & 2 & 3 \\\\\n      -6 & 2 & 1\n    \\end{mymatrix}\n    =\\allowbreak\n    \\begin{mymatrix}{ccc}\n      1+5 & 2+2 & 3+3 \\\\\n      1+(-6) & 0+2 & 4+1\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rrr}\n      6 & 4 & 6 \\\\\n      -5 & 2 & 5\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nOn the other hand, the matrices\n\\begin{equation*}\n  \\begin{mymatrix}{rr}\n    1 & 2 \\\\\n    3 & 4 \\\\\n    5 & 2\n  \\end{mymatrix}\n  \\quad\\mbox{and}\\quad\n  \\begin{mymatrix}{rrr}\n    -1 & 4 & 8 \\\\\n    2 & 8 & 5\n  \\end{mymatrix}\n\\end{equation*}\ncannot be added, because one has size $3\\times 2$ while the other has size $2\\times 3$.\n\n\\begin{definition}{The zero matrix}{zero-matrix}\n  The \\textbf{$m\\times n$ zero matrix}%\n  \\index{zero matrix}%\n  \\index{matrix!zero matrix} is the $m\\times n$-matrix in which all\n  entries are equal to zero. It is denoted by $0$.\n\\end{definition}\n\nNote there is a zero matrix for every size. For example, there is a\n$2\\times 3$ zero matrix, a $3\\times 4$ zero matrix, and so on.\n\n\\begin{example}{The zero matrix}{zero-matrix}\n  The $2\\times 3$ zero matrix is $0= \\begin{mymatrix}{rrr}\n    0 & 0 & 0 \\\\\n    0 & 0 & 0\n  \\end{mymatrix}$.\n\\end{example}\n\n\\begin{definition}{Negative of a matrix and subtraction}{matrix-negative}\n  The \\textbf{negative}%\n  \\index{matrix!negative}%\n  \\index{negative!of a matrix} of a matrix $A=\\mat{a_{ij}}$ is defined\n  to be $-A = [-a_{ij}]$. In other words, it is obtained by negating\n  every entry of $A$. To \\textbf{subtract}%\n  \\index{matrix!subtraction}%\n  \\index{subtraction!of matrices} two matrices, we simply add the\n  negative of the second matrix to the first one, i.e.,\n  $A-B = A+(-B)$. This is just the same as componentwise subtraction.\n\\end{definition}\n\n\\begin{example}{Subtraction}{matrix-subtraction}\n  Subtract the following matrices.\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      1 & 0 & 4\n    \\end{mymatrix},\\quad\n    B = \\begin{mymatrix}{rrr}\n      5 & 2 & 3 \\\\\n      -6 & 2 & 1\n    \\end{mymatrix}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  \\begin{equation*}\n    A-B =\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      1 & 0 & 4\n    \\end{mymatrix}\n    - \\begin{mymatrix}{rrr}\n      5 & 2 & 3 \\\\\n      -6 & 2 & 1\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{ccc}\n      1-5 & 2-2 & 3-3 \\\\\n      1-(-6) & 0-2 & 4-1\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rrr}\n      -4 & 0 & 0 \\\\\n      7 & -2 & 3\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nAddition of matrices obeys the same properties as addition of vectors.\n\n\\begin{proposition}{Properties of matrix addition}{properties-of-addition}\n  Let $A,B$ and $C$ be matrices of the same size. Then, the following\n  properties%\n  \\index{matrix!properties of addition}%\n  \\index{matrix!addition!properties}%\n  \\index{properties of addition!matrices} hold.\n\n  \\begin{itemize}\n  \\item The commutative law of addition\n    \\begin{equation*}\n      A+B=B+A.\n    \\end{equation*}\n  \\item The associative law of addition\n    \\begin{equation*}\n      (A+B)+C=A+(B+C).\n    \\end{equation*}\n  \\item The existence of an additive unit\n    \\begin{equation*}\n      \\begin{array}{c}\n        A+0=A.\n      \\end{array}\n    \\end{equation*}\n  \\item The existence of an additive inverse\n    \\begin{equation*}\n      \\begin{array}{c}\n        A+(-A) = 0.\n      \\end{array}\n    \\end{equation*}\n  \\end{itemize}\n\\end{proposition}\n\n\\begin{proof}\n  To prove the commutative law of addition, let $A$ and $B$ be\n  matrices of the same size. We want to show that $A+B=B+A$. To do so,\n  we use the definition of matrix addition given in Definition~\\ref{def:addition-of-matrices}.  We have\n  \\begin{equation*}\n    A+B = \\mat{a_{ij}+b_{ij}} = \\mat{b_{ij}+a_{ij}} = B+A.\n  \\end{equation*}\n  The proof of the other properties are similar, and are left as an\n  exercise.\n\\end{proof}\n", "meta": {"hexsha": "8aab2828d52b16521bed49512bf39fd6e17f5bfb", "size": 5351, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-Addition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-Addition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-Addition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 27.725388601, "max_line_length": 116, "alphanum_fraction": 0.6264249673, "num_tokens": 1912, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.9099070029841949, "lm_q1q2_score": 0.7285552599405446}}
{"text": "\\section{Magnetism}\n    This is very similar to electricity. Magnetic fields are created by moving electric charges. Magnetic fields are represented as $\\vec{B}$. The force that a $\\vec{B}$ field exerts on a charge is $\\vec{F}=q\\vec{v}\\times\\vec{B}$, where $q$ is the charge, $\\vec{v}$ is the velocity, and $\\vec{B}$ is the field the charge is in.\n    \\subsubsection{Example 1}\n    An electron is moving with speed v to the right. An external field, $\\vec{B}$, points into the page. Find the force on the charge. We are going to be using an x-y axis with z not shown, but it points into the picture. (Figure 6.1)\n    \\begin{align*}\n        \\vec{v}&=v(-\\hat{i})=-v\\hat{i}\\\\\n        \\vec{B}&=B\\hat{k}\\\\\n        \\vec{F}&=-e\\vec{v}\\times\\vec{B}\\\\\n        \\vec{F}&=F(-\\hat{i})\\\\\n        \\shortintertext{Also, let's compute $\\vec{F}$}\\\\\n        \\vec{F}&=q\\vec{v}\\times\\vec{B}\\\\\n        &=(-e)(-\\vec{v}\\hat{i})\\times(B\\hat{k})\\\\\n        &= ev\\hat{i}\\times B\\hat{k}\\\\\n        &=evB(\\hat{i}\\times\\hat{k})\\\\\n        &=evB(-\\hat{j})\\\\\n    \\end{align*}\n    \\subsubsection{Example 2}\n    Find the period of motion of a positive charge Q in an external magnetic field $\\vec{B}$. Let $\\vec{v} = v\\hat{i}$ and $\\vec{B}=B\\hat{k}$. (Figure 6.2)\n    \\begin{align*}\n        \\vec{F}=Q\\vec{v}\\times\\vec{B}\\\\\n        \\shortintertext{Cyclotron motion is the circular motion of a charge particle in a $\\vec{B}$ field. This is \\underline{uniform} circular motion. This means you cannot use a magnetic field to change speed. Magnetic fields do \\underline{no work}.}\n        F&=QvBsin\\theta\\\\\n        F&=QvB\\\\\n        \\shortintertext{Let's equate this force with $\\vec{F}=ma$}\\\\\n        QvB&=ma\\\\\n        QvB&=m\\frac{v^2}{R}\\\\\n        \\frac{Q}{m}&=\\frac{v}{BR}\n        \\shortintertext{The period, $T$, of the field is given by $T=\\frac{2\\pi R}{v}$}\\\\\n        T&=\\frac{2\\pi R}{BR\\frac{Q}{m}}\\\\\n        \\alignedbox{T}{=2\\pi\\frac{m}{BQ}}\\\\\n        f&=\\frac{1}{2\\pi}B\\frac{Q}{m}\\\\\n        \\shortintertext{This is the cyclotron period and the cyclotron frequency.}\\\\\n    \\end{align*}\n\n\n    \\subsection{Creating Magnetic Fields}\n    In the Biot Savart we know that electric chages that are moving create electric fields. In order to determine the direction we still must do the right hand rule. This is easier to visualize with a current (describes electromagnets.) Instead we are going to talk about a piece of charge:\n    \\begin{align*}\n        \\alignedbox{\\vec{B}}{=\\frac{\\mu_0}{4\\pi}\\frac{q\\vec{v}\\times\\hat{r}}{r^2}}\\\\\n        \\alignedbox{d\\vec{B}}{=\\frac{\\mu_0}{4\\pi}\\frac{dq\\vec{v}\\times\\hat{r}}{r^2}}\\\\\n        \\shortintertext{This is the Biot-Savart Law}\n    \\end{align*}\n    \\subsubsection{Example 1}\n    Find magnetic field $\\vec{B}$ a distance d from an infinitely long wire carrying a current I make sure you always place the $d\\vec{l}$ so it creates a triangle.\n    \\begin{align*}\n        d\\vec{B}&=\\frac{\\mu_0}{4\\pi}\\frac{dq\\frac{d\\vec{l}}{dt}\\times\\hat{r}}{r^2}\\\\\n        &=\\frac{\\mu_0}{4\\pi}\\frac{\\frac{dq}{dt}d\\vec{l}\\times\\hat{r}}{r^2}\\\\\n        &=\\frac{\\mu_0}{4\\pi}\\frac{Id\\vec{l}\\times\\hat{r}}{r^2}\\\\\n        \\shortintertext{Because the current changes over time, $\\frac{dq}{dt}=I$. Current is moving charges so current moving on a wire thats dl long in a certain direction creates $d\\vec{B}$. This is analagous to electric fields and solving for the electric field.}\\\\\n        \\vec{B}&=\\frac{\\mu_0}{4\\pi}I\\int_{-\\infty}^\\infty\\frac{d\\vec{l}\\times\\hat{r}}{r^2}\\\\\n        \\shortintertext{We took the right hand rule to find the direction of $\\vec{B}$ but this does not tell us the magnitude of the vectors because $d\\vec{l}$ is changing. We are going to use $sin\\theta$ where theta is the angle between $d\\vec{l}$ and $\\hat{r}$ to make this easier to computate. $\\hat{r}$ is a unit vector so its magnitude is zero. It is only there to help us find the direction.}\\\\\n        \\vec{B}&=\\frac{\\mu_0}{4\\pi}I\\int_{-\\infty}^\\infty\\frac{dlsin(\\theta)}{r^2}\\\\\n        \\shortintertext{Now we are going to take the $sin\\theta$ and change it into the coordinates we are using (xyz). We can figure out that $r^2=x^2+d^2$ and that $sin\\theta=\\frac{d}{r}$}\\\\\n        &=\\frac{\\mu_0}{4\\pi}I\\int_{-\\infty}^\\infty\\frac{dx}{x^2+d^2}\\frac{d}{\\sqrt{x^2+d^2}}\\\\\n        \\shortintertext{d is a constant of integration because the current doesn't change along d at all.}\n        &=\\frac{\\mu_0}{4\\pi}Id\\int_{-\\infty}^\\infty\\frac{dx}{(x^2+d^2)^\\frac{3}{2}}\\\\\n        &=\\frac{\\mu_0}{4\\pi}Id\\left[\\frac{x}{d^2}\\frac{1}{\\sqrt{x^2+d^2}}\\right]_{x=-\\infty}^{x=\\infty}\\text{ out of page}\\\\\n        \\shortintertext{We are going to divide both the top and bottom by x because infinity cannot be at the top of a fraction.}\\\\\n        d\\vec{B}&=\\frac{\\mu_0}{4\\pi}Id\\left[\\frac{1}{d^2}\\frac{1}{\\sqrt{1+\\frac{d^2}{x^2}}}\\right]_{x=-\\infty}^{x=\\infty}\\\\\n        \\shortintertext{This is a problem because if we evaluate it now, we will get 0 as our magnetic field. Because of this we must do the following:}\n        \\vec{B}&=2\\frac{\\mu_0}{4\\pi}\\frac{I}{d}\\frac{1}{\\sqrt{1+\\frac{d^2}{x^2}}}\\Big|_{x=-\\infty}^{x=\\infty}\\\\\n        \\vec{B}&=\\frac{\\mu_0}{2\\pi}\\frac{I}{d}\\left[1-0\\right]\\\\\n        \\alignedbox{\\vec{B}}{=\\frac{\\mu_0I}{2\\pi d}\\text{ out of page}}\\\\\n    \\end{align*}\n    There is an additional right hand rule. Put your thumb in the direction of the current wire, then your wrapped fingers will give the direction of $\\vec{B}$. \n    \\subsubsection{Example 2}\n    Remember that magnetic force is written as $\\vec{F}=q\\vec{v}\\times\\vec{B}$. In scenario 1 we are going to have a positive charge that is going to move initially to the right with some velocity v. It is about to enter a region with a magnetic charge that points into the page. What electric field can we add to the region to prevent the moving charge from deflecting? By the right hand rule, the particle is going to feel a force upward.\n    \\begin{align*}\n        \\vec{F_B}&=q\\vec{v}\\times\\vec{B}\\\\\n        \\vec{F_B}&=qvB \\text{, up}\\\\\n        \\shortintertext{We need $\\vec{E}$ to cause an equal force down so that $\\vec{F}_{net}=0$}\\\\\n        \\vec{F_E}&=q\\vec{E}\\\\\n        \\shortintertext{$\\vec{E}$ must point downward.}\\\\\n        F_E&=F_B\\\\\n        qE&=qvB\\\\\n        E&=vB\\\\\n    \\end{align*}\n    Now in scenario 2 we have a negative charge that is going to move initially to the right with a magnetic region pointing into the charge. With a negative charge and right hand rule, we must flip our hand over because of the negativity.\n    \\begin{align*}\n        \\vec{F_B}&=qvB\\text{, Down. we need}\\\\\n        \\vec{F}&=q\\vec{E} \\text{ to point up.}\\\\\n    \\end{align*}\n    We actually get the same answer as before. This is because they both depend on q, and if the sign on q changes, it changes on both sides of the equation.\\newline\\newline \n    In scenario 3, our charged particle will be positive and heading right, but the magnetic field is in line with the charge's movement.\n    \\begin{align*}\n        \\vec{F_B}&=q\\vec{v}\\times\\vec{B}=0\\\\\n        \\to &=qvBsin(0)=0\\\\\n    \\end{align*}\n    In this case we don't need an $\\vec{E}$ field at all to keep the charge from deflecting.\\newline\\newline\n    With scenario 4, we have a positive charge moving to the right into a magnetic field that has a diagonal vector.\n    \\begin{align*}\n        \\vec{F_B}&=q\\vec{v}\\times\\vec{B}\\\\\n        F_B&=qvB_{\\perp}\\\\\n        \\shortintertext{We must cross with the vertical component of B because the horizontal is parallel and gives 0}\\\\\n        \\vec{F_B}&=qvBsin(\\theta)\\text{, out of page}\\\\\n        \\text{$\\vec{E}$ is into the page}\\\\\n        qE&=qvBsin(\\theta)\\\\\n        \\to E&=vBsin(\\theta)\\\\\n    \\end{align*}\n    \\subsubsection{Example 3}\n    Let $\\vec{B}=B(-\\hat{j})=-B\\hat{j}$ and $\\vec{v}$ that initially looks like $\\vec{v}=v_{0_y}\\hat{j}+v_{0_z}\\hat{k}$. What will the motion of q look like?\n    \\begin{align*}\n        \\vec{F}&=q\\vec{v}\\times\\vec{B}\\\\\n        &=q(v_{0_y)}\\hat{k}+v_{0_z)}\\hat{k})\\times(-B\\hat{j})\\\\\n        &=-q(v_{0_y}B(\\hat{j}\\times\\hat{j})+v_{0_z}B(\\hat{k}\\times\\hat{j}))\\\\\n        &=-qv_{0_z}B(\\hat{k}\\times\\hat{j})\\\\\n        &=-qv_{0_z}B(-\\hat{i})\\\\\n        \\alignedbox{\\vec{F_0}}{=qv_{0_z}B\\hat{i}}\\\\\n    \\end{align*}\n    This will cause a helical motion: linear in $\\hat{j}$ and cyclotron in the $\\hat{i}$ and $\\hat{k}$ directions. Basically it creates a spring.\n    \\subsubsection{Example 4}\n    Force on a current.\n    \\begin{align*}\n        \\vec{F}&=q\\vec{v}\\times\\vec{B}\n        \\shortintertext{Imagine a small amount of charge dq. The force exerted on this small amount of charge dq by an external field $\\vec{B}$ is:}\\\\\n        d\\vec{F}&=dq\\vec{v}\\times\\vec{B}\\\\\n        d\\vec{F}&=dq\\frac{d\\vec{l}}{dt}\\times\\vec{B}\\\\\n        d\\vec{F}&=\\frac{dq}{dt}d\\vec{l}\\times\\vec{B}\\\\\n        \\alignedbox{d\\vec{F}}{=Id\\vec{l}\\times\\vec{B}}\\\\\n        \\shortintertext{If everything is uniform, }\\\\\n        \\int d\\vec{F}&=\\int Id\\vec{l}\\times\\vec{B}\\\\\n        \\vec{F}&=I\\vec{l}\\times\\vec{B}\\\\\n    \\end{align*}\n    \\subsubsection{Example 5}\n    For a uniform external field, $\\vec{B}=4mT$ into the page, which way will a free wire move if the current as shown is $I=2A$ CCW. Let $a=10cm$. The force will be \\underline{to the right.}\n    \\begin{align*}\n        \\vec{F}&=I\\vec{l}\\times\\vec{B}\\\\\n        F&=IlB\\\\\n        &=(2A)(10cm)(4mT)\\\\\n        &=(2A)(0.1m)(4\\times10^{-3}T)\\\\\n        \\alignedbox{\\vec{F}}{=8\\times10^{-4}T}\\\\\n    \\end{align*}\n\n\n    \\subsection{Holl Effect}\n    Consider a metal plate. We will drive a current through this metal plate (figure 6.3). Let's add $\\vec{B}$ into the page. The current will feel a force acting upwards due to the right hand rule. This is because our fingers go to the right and curl to inside the page, the thumb gives us up which is the direction in which the force will move. These two figures are almost the same exact setup, but there is a change in the measured voltage. \\newline\\newline\n    If the measured voltage is positive, the current is made up of positively charged particles. If the measured voltage is negative, the current is made up of negative charged particles. It turns out that the charge carriers are negative (electrons).\n    \\subsubsection{Example 1}\n    This is a Biot Savart example.\n    \\begin{align*}\n        d\\vec{B}&=\\frac{\\mu_0}{4\\pi}\\frac{Id\\vec{l}\\times\\hat{r}}{r^2}\\\\\n        \\shortintertext{Let's find $\\vec{B}$ at the center of an arc of current (figure 6.5). Remember that the cross product of $d\\vec{l}\\times\\vec{B}$. For magnetic field, we put our thumb in the direction of the current and wrap our hands around to the direction of the field. The current is going to be going along the rod clockwise. $\\hat{r}$ is always going to be perpendicular to $d\\vec{l}$ because I is always going to be pointing directly out of the circle, while r always points inward.}\\\\\n        d\\vec{B}&=\\frac{\\mu_0}{4\\pi}I\\frac{dl*1*sin(90)}{r^2}\\text{ into page}\\\\\n        \\int d\\vec{B}&=\\int\\frac{\\mu_0}{4\\pi}I\\frac{dl}{r^2}\\text{ into page}\\\\\n        \\vec{B}&=\\frac{\\mu_0}{4\\pi}I\\int\\frac{dl}{R^2}\\text{ into page}\\\\\n        \\vec{B}&=\\frac{\\mu_0}{4\\pi}\\frac{I}{R^2}\\int dl\\\\\n        \\vec{B}&=\\frac{\\mu_0}{4\\pi}\\frac{I}{R^2}\\int Rd\\theta\\\\\n        &=\\frac{\\mu_0}{4\\pi}\\frac{I}{R}\\int d\\theta\\\\\n        \\alignedbox{\\vec{B}}{=\\frac{\\mu_0I}{4\\pi R}\\theta\\text{ into page}}\\\\\n        \\shortintertext{For a full loop of current, $\\theta=2\\pi$}\\\\\n        \\vec{B}&=\\frac{\\mu_0I}{4\\pi R}2\\pi\\\\\n        \\alignedbox{\\vec{B}}{=\\frac{\\mu_0I}{2R}\\text{ into page}}\\\\\n        \\shortintertext{If I was variable, then we couldn't pull it out of the integral, but the direction would remain the same.}\n    \\end{align*}\n\n\n    \\subsection{Ampere's Law}\n    \\begin{align*}\n        \\shortintertext{Figure 6.6}\\\\\n        \\alignedbox{\\oint\\vec{B}\\cdot d\\vec{l}}{=\\mu_0I_{th}}\\\\\n        \\shortintertext{Very similar to Gauss' law. We must choose a path in which we can nicely handle the expression above.}\\\\\n        \\oint Bdl&=\\mu_0I_{th}\\\\\n        B\\oint dl &=\\mu_0I\\\\\n        B2\\pi r &=\\mu_0 I\\\\\n        \\alignedbox{\\vec{B}}{\\frac{\\mu_0I}{2\\pi r}\\text{ CCW}}\\\\\n        \\shortintertext{If you were to pick $d\\vec{l}$ to go to the wrong direction, the dot product results in zero so you get: $-\\oint Bdl=\\mu_0(-I)$. The minuses cancel and you end up getting the same answer: $\\vec{B}=\\frac{\\mu_0I}{2\\pi r}$}\\\\\n    \\end{align*}\n    A solenoid is a coil of wire in the shape of a slinky (it stays in place) this is shown in figure 6.7. Magnetic field lines never start or stop and they never diverge, meaning they are always parallel. An ideal solenoid has a length much larger than it's radius ($L>>R$). Solenoids are used in MRI machines, hence the name (Magnetic resistance imaging). They are the tube that people are pushed into.\n    \\subsubsection{Example 1}\n    Imagine an infinite perfect solenoid (figure 6.8). Let's find $\\vec{B}$ for an ideal solenoid. The $d\\vec{l}$ loop must encapsulate some form of current in order to be useful with this equation\n    \\begin{align*}\n        \\oint \\vec{B}\\cdot d\\vec{l}&=\\mu_0 I_{th}\\\\\n        \\shortintertext{It is easiest to split this up into multiple loops because there are four sides for the rectangle we chose. We labeled the sides (1, 2, 3, 4) so we could label our integrals.}\\\\\n        \\int\\vec{B}\\cdot d\\vec{l_{1}}+\\int\\vec{B}\\cdot d\\vec{l_{2}}+\\int\\vec{B}\\cdot d\\vec{l_{3}}+\\int\\vec{B}\\cdot d\\vec{l_{4}}&=\\mu_0I_{th}\\\\\n        \\shortintertext{For the first integral, $\\vec{B}\\cdot d\\vec{l_1}$ gives us $bl$. For the second and fourth integrals, the dot product equals zero. For the third segment, $\\vec{B}=0$ so we cannot do anything with that. The amount of current all along the loop is the same throughout. I is the current through each of the wires so the current through one wire is going to be I.}\\\\\n        Bl+0+0+0&=\\mu_02I\\\\\n        \\shortintertext{In a more general case, let's say that $N$ currents pierce throguh the Amperian loop.}\\\\\n        Bl&=\\mu_0NI\\\\\n        \\shortintertext{If for the whole solenoid length L:}\\\\\n        BL_{tot}&=\\mu_0N_{tot}I\\\\\n        B&=\\mu_0\\frac{N_{tot}}{L_{tot}}I\\\\\n        \\alignedbox{B}{=\\mu_0nI}\\text{ Where $n$ is turns per length}\\\\\n    \\end{align*}\n    If you want a bigger field you can either increase the current or put more turns in the current.\n\n\n    \\subsection{Magnetic Inductance}\n    We will first consider Faraday's Law.\n    \\begin{align*}\n        \\Phi_B&=\\vec{B}\\cdot d\\vec{A}\\\\\n        \\shortintertext{Where $\\Phi_B$ is magnetic flux.}\\\\\n        \\alignedbox{E_{ind}}{=-\\frac{d}{dt}\\Phi_B}\\\\\n        \\shortintertext{$E_{ind}$ is also known as E.M.F. which is an induced voltage or potential.}\\\\\n    \\end{align*}\n    \\subsubsection{Example 1}\n    A $\\vec{B}$ field is into the page and increasing linearly in time: $B=b_0\\frac{t}{t_0}$. Find the direction and magnitude of current induced on a circular loop of wire with radius, r, and resistance, R, in plane with the page (figure 6.9). Electricity and magnetism are two different expressions of the same thing (electromagnetism). If a voltage is induced on a wire where we can calculate current we can just use Ohm's Law. We need a magnetic field that fluctuates in time. If the flux doesn't change in time then there is no induced electric field. While magnetic field is into the page everywhere, the resistor only cares about the magnetic field that is on the wire. It is okay that our B value does not have area dependence because we are calculating the flux of the magnetic field. We only need to discuss the area of magnetism when we get the flux.\n    \\begin{align*}\n        \\Phi_B&=\\int\\vec{B}\\cdot d\\vec{A}\\\\\n        &=\\int \\left(B_0\\frac{t}{t_0}\\hat{k}\\right)\\cdot\\left(dA\\hat{k}\\right)\\\\\n        &=B_0\\frac{t}{t_0}\\int dA\\\\\n        &=B_0\\frac{t}{t_0}\\pi r^2\\\\\n        \\shortintertext{Always find the flux before taking the time derivative. Now we are moving on to the time derivative:}\\\\\n        \\to\\frac{t}{dt}\\Phi_B&=\\frac{d}{dt}B_0\\frac{t}{t_0}\\pi r^2\\\\\n        &=B_0\\frac{\\pi r^2}{t_0}\\\\\n        \\shortintertext{Recall that $E_{ind}=-\\frac{d}{dt}\\Phi_B$. The negative sign is because of Lenz's law. This basically just helps determind the direction of the magnitude of $E_{ind}$. \\underline{Lenz's Law:} The induced current $I_{ind}=\\frac{E_ind}{R}$ has a direction such that $B_{ind}$ opposes the change in flux, that is, $\\frac{d}{dt}\\Phi_B$. For this case, $I_{ind}$ must flow counter-clockwise because it must oppose the change in the flux.}\\\\\n        |E_{ind}|=|\\frac{d}{dt}\\Phi_B|=|B_0\\frac{\\pi r^2}{t_0}|\\\\\n        \\alignedbox{I_{ind}}{=\\frac{1}{R}B_0\\frac{\\pi r^2}{t_0}\\text{, ccw}}\\\\\n    \\end{align*}\n    Here are some other Lenz's law cases (figure 6.10). The equation for $\\vec{B}$ in this case is $\\vec{B}=B\\frac{t}{t_0}\\hat{k}$. The flux is \\underline{decreasing} into the page so the $B_{ind}$ is going to point into the page, which would mean that our $I_{ind}$ is going clockwise. You \\underline{oppose the change in the flux}. You do \\underline{not} oppose the direction of the magnetic field.\\newline\\newline\n    Let's now look at figure 6.11. This figure has a square loop in the middle and we know that $I_{int}$ goes clockwise because the magnetic force is going into the page and not out of the page. With $B=B_0e^\\frac{t}{t_0}$, there is no real change in this problem compare to the last. We must also understand that we deal with a square loop the same way we dealt with a circular \n    one.\n\n\n    \\subsection{Eddy Currents}\n    Similar to how if you're rowing a boat. As you pull your oar through the water you get little eddy's around the stick. These are magnetically induced currents that appear when Farade's law results in the slowing down of an object. This is a type of induced current. An example of this is sorting recyclables. You have a platform with a bunch of material heading down a slope. If the box is cardboard, then it will have an induced $E_{mf}$, but won't feel an induced current. If the recyclables are made from aluminum such as cans, then they will continue moving downward.\n    \\subsubsection{Motional Emf (E)}\n    This goes along with figure 6.12. What direction will the force be in?\n    \\begin{align*}\n        \\vec{F}&=I\\vec{l}\\times\\vec{B}\\\\\n        &=I_{ind}\\vec{l}\\times\\vec{B_{ext}}\\\\\n        \\shortintertext{Say we pull such that the speed of the loop is constant. Because we already know the direction we are going to just use the magnitude to determine what $E_{ind}$ is.}\\\\\n        E_{ind}&=-\\frac{d}{dt}\\Phi_B\\\\\n        |E_{ind}|&=|-\\frac{d}{dt}\\Phi_B|\\\\\n        |E_{ind}|&=\\frac{d}{dt}(BA)\\\\\n        |E_{ind}|&=B\\frac{d}{dt}A+A\\frac{d}{dt}B\\\\\n        &=B\\left(L\\frac{dx}{dt}+x\\frac{dL}{dt}\\right)\\\\\n        &=BL\\frac{dx}{dt}\\\\\n        \\shortintertext{We know that the speed is not changing so we can come to the conclusion that:}\\\\\n        \\alignedbox{|E_{ind}|}{=B_{ext}Lv}\\\\\n        \\shortintertext{From Ohm's law:}\\\\\n        E_{ind}&=I_{ind}R\\\\\n        I_{ind}&=\\frac{B_{ext}Lv}{R}\\\\\n        P&=I_{ind}E_{ind}\\\\\n        \\alignedbox{P}{=\\frac{B_{ext}^2L^2v^2}{R}}\\\\\n    \\end{align*}\n\n\n    \\subsection{Induced Electric Field}\n    Farade's Law: $E_{ind}=-\\frac{d}{dt}\\Phi_B$ (Figure 6.13). This means that $E_{ind}$ points the same direction as $I_{ind}$. This gives us that $\\oint\\vec{E_{ind}}\\cdot d\\vec{l}=-\\frac{d}{dt}\\Phi_B$. These charged particles must be in a loop in order to come to this conclusion. Farade's law helps us further relate the previous equation.\n    \\begin{align*}\n        \\oint\\vec{E_{ind}}\\cdot d\\vec{l}&=-\\frac{d}{dt}\\int\\vec{B}\\cdot d\\vec{a}\\\\\n    \\end{align*}\n    A time varying magnetic flux induces an electric field. Electric and magnetic fields are frame dependent. They depend on what inertial frame they are in. An inertial frame is one in which there is no acceleration.\n    \\subsubsection{Induction Applied to Circuits}\n    Let's consider a solenoid. If we apply a current then there will be a magnetic field throughout the inside of the solenoid. The best way to solve for the magnetic field within a solenoid is by using Ampere's law, $B=\\mu_0nI$. The flux through the solenoid is:\n    \\begin{align*}\n        \\Phi_B&=\\int\\vec{B}\\cdot d\\vec{a}\\\\\n        \\Phi_B&=Ba\\\\\n        \\shortintertext{We can say that because the flux is proportional to the magnetic field, the flux is proportional to the current as well. We now introduce inductance L.}\\\\\n        \\Phi_B&=LI\\\\\n        \\shortintertext{L depends on the solenoid's geometry.}\\\\\n        N\\Phi_B&=LI\\\\\n        \\shortintertext{Where N is the number of turns in the solenoid}\\\\\n        \\alignedbox{L}{=N\\frac{\\Phi_B}{I}}\\\\\n        \\shortintertext{Let's find the $E_{ind}$ of the solenoid}\\\\\n        E_{ind}=-\\frac{d}{dt}\\Phi_B&=-\\frac{d}{dt}\\left(\\frac{LI}{N}\\right)\\\\\n        E_{ind}&=-\\frac{L}{N}\\frac{d}{dt}I\n    \\end{align*}\n    For a self induced emf:\n    \\begin{align*}\n        E_{ind}&=-L\\frac{dI}{dt}\n    \\end{align*}\n    \\subsubsection{Example 1}\n    Let's find the amount of energy stored in the magnetic field of a solenoid. First let's find the power.\n    \\begin{align*}\n        |P|&=IV=|-LI\\frac{dI}{dt}|\\\\\n        \\shortintertext{We know that power is the change of energy over the change in time, this is why we are able to jump to the next step.}\\\\\n        U&=\\int Pdt\\\\\n        &=\\int LI\\frac{dI}{dt}dt\\\\\n        &=\\int LIdI\\\\\n        \\alignedbox{U_B}{=\\frac{1}{2}LI}\\\\\n        \\shortintertext{Recall from electricity, $U_E=\\frac{1}{2}CV^2$. In this case the charges are moving. With the magnetic energy equation, we are changing the energy for already moving charges.}\\\\\n    \\end{align*}\n\n\n    \\subsection{List of Maxwell's Equations:}\n    \\begin{align*}\n        \\int\\vec{E}\\cdot d\\vec{a}=\\frac{Q_{enc}}{\\epsilon_0}\\\\\n        \\oint\\vec{B}\\cdot d\\vec{l}=\\mu_0I_{th}\\\\\n        \\text{also }\\oint\\vec{B}\\cdot d\\vec{a}=0\\\\\n        \\shortintertext{There are no magnetic charges/monopoles. Magnetic fields never terminate.}\\\\\n        \\shortintertext{We have recently used Farade's law}\\\\\n        E_{ind}=-\\frac{d}{dt}\\Phi_B\\\\\n        \\oint\\vec{E}\\cdot d\\vec{l}=-\\frac{d}{dt}\\int\\vec{B}\\cdot d\\vec{a}\\\\\n        \\shortintertext{We will update Ampere's law to be:}\\\\\n        \\oint\\vec{B}\\cdot d\\vec{l}=\\mu_0I_{th}+\\mu_0I_{disp}\\\\\n        \\text{or }\\oint\\vec{B}\\cdot d\\vec{l}=\\mu_0\\int\\vec{J}\\cdot d\\vec{a}+\\mu_0\\epsilon_0\\frac{d}{dt}\\Phi_E\\\\\n        \\shortintertext{Where $I_{disp}$ and $\\epsilon_0\\frac{d}{dt}\\Phi_E$ are the displacements of the currents}\n    \\end{align*}\n    Example with the new Ampere's Law:\n    Current changing with a capacitor (figure 6.13). We are allowing a bubble to encapsulate the leftmost plate where there is no loop. There must be a changing electric flux to resolve this issue.\n    \\begin{align*}\n        \\text{Gauss's Law:}\\\\\n        \\oint\\vec{E}\\cdot d\\vec{a}=\\frac{Q_{enc}}{\\epsilon_0}\\\\\n        \\oint\\vec{B}\\cdot d\\vec{a}=0\\\\\n        \\text{Farade's Law:}\\\\\n        \\oint\\vec{E}\\cdot d\\vec{l}=-\\frac{d}{dt}\\int\\vec{B}\\cdot d\\vec{a}\\\\\n        \\text{Ampere-Maxwell:}\\\\\n        \\oint\\vec{B}\\cdot d\\vec{l}=\\mu_0\\int\\vec{J}\\cdot d\\vec{a}+\\mu_0\\epsilon_0\\frac{d}{dt}\\int\\vec{E}\\cdot d\\vec{a}\\\\\n        \\text{Lorenty Force Law:}\\\\\n        \\vec{F}=q\\vec{E}+q\\vec{v}\\times\\vec{B}\n    \\end{align*}\n    Here's the differential form of all of these equations:\n    \\begin{align*}\n        \\vec{\\nabla}&=\\frac{\\partial}{\\partial x}\\hat{i}+\\frac{\\partial}{\\partial y}\\hat{j}+\\frac{\\partial}{\\partial z}\\hat{k}\\\\\n        \\vec{\\nabla}\\cdot\\vec{E}&=\\frac{\\rho}{\\epsilon_0}\\\\\n        \\vec{\\nabla}\\cdot\\vec{B}&=0\\\\\n        \\vec{\\nabla}\\times\\vec{E}&=-\\frac{\\partial}{\\partial t}\\vec{B}\\\\\n        \\vec{\\nabla}\\times\\vec{B}&=\\mu_0\\vec{J}+\\mu_0\\epsilon_0\\frac{\\partial}{\\partial t}\\vec{E}\\\\\n    \\end{align*}\n\\newpage", "meta": {"hexsha": "8ccabe8f89c928cbb5062896f75769ea65c0b348", "size": 23636, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "physics204/Sections/6Magnetism.tex", "max_stars_repo_name": "CameronSWilliamson/GU-MATH", "max_stars_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-18T00:49:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T00:49:14.000Z", "max_issues_repo_path": "physics204/Sections/6Magnetism.tex", "max_issues_repo_name": "therealkeyisme/Math-Notes", "max_issues_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "physics204/Sections/6Magnetism.tex", "max_forks_repo_name": "therealkeyisme/Math-Notes", "max_forks_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 76.0, "max_line_length": 861, "alphanum_fraction": 0.6456253173, "num_tokens": 7788, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7283900710082684}}
{"text": "\n% This LaTeX was auto-generated from an M-file by MATLAB.\n% To make changes, update the M-file and republish this document.\n\n%%% \\documentclass{article}\n%%% \\usepackage{graphicx}\n%%% \\usepackage{color}\n\n%%% \\sloppy\n%%% \\definecolor{lightgray}{gray}{0.5}\n\\setlength{\\parindent}{0pt}\n\n%%% \\begin{document}\n\n    \n    \n\\subsection*{Four parameter sine wave fitting}\n\n\\begin{par}\nExample for algorithm FPNLSF.\n\\end{par} \\vspace{1em}\n\\begin{par}\nFPNLSF is an algorithm for estimating the frequency, amplitude, and phase of the sine waveform. The algorithm use least squares method. Algorithm requires good estimate of frequency.\n\\end{par} \\vspace{1em}\n\n\\subsubsection*{Contents}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item Generate sample data\n   \\item Call algorithm\n   \\item Display results\n\\end{itemize}\n\n\n\\subsubsection*{Generate sample data}\n\n\\begin{par}\nTwo quantities are prepared: \\lstinline{t} and \\lstinline{y}, representing 1 second of sinus waveform of nominal frequency 1 kHz, nominal amplitude 1 V, nominal phase 1 rad and offset 1 V sampled at sampling frequency 10 kHz.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDI = [];\nAnom = 2; fnom = 100; phnom = 1; Onom = 0.2;\nDI.t.v = [0:1/1e4:1-1/1e4];\nDI.y.v = Anom*sin(2*pi*fnom*DI.t.v + phnom) + Onom;\n\\end{lstlisting}\n\\begin{par}\nLets make an estimate of frequency 0.2 percent higher than nominal value:\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDI.fest.v = 100.2;\n\\end{lstlisting}\n\n\n\\subsubsection*{Call algorithm}\n\n\\begin{par}\nUse QWTB to apply algorithm \\lstinline{FPNLSF} to data \\lstinline{DI}.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nCS.verbose = 1;\nDO = qwtb('FPNLSF', DI, CS);\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nQWTB: no uncertainty calculation\nFitting started\n\nLocal minimum found.\n\nOptimization completed because the size of the gradient is less than\nthe default value of the function tolerance.\n\n\n\nFitting finished\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Display results}\n\n\\begin{par}\nResults is the amplitude, frequency and phase of sampled waveform.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nA = DO.A.v\nf = DO.f.v\nph = DO.ph.v\nO = DO.O.v\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\n\nA =\n\n    2.0000\n\n\nf =\n\n   100\n\n\nph =\n\n    1.0000\n\n\nO =\n\n    0.2000\n\n\\end{lstlisting} \\color{black}\n    \\begin{par}\nErrors of estimation in parts per milion:\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nAerrppm = (DO.A.v - Anom)/Anom .* 1e6\nferrppm = (DO.f.v - fnom)/fnom .* 1e6\npherrppm = (DO.ph.v - phnom)/phnom .* 1e6\nOerrppm = (DO.O.v - Onom)/Onom .* 1e6\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\n\nAerrppm =\n\n   4.8894e-07\n\n\nferrppm =\n\n     0\n\n\npherrppm =\n\n   4.8850e-09\n\n\nOerrppm =\n\n  -1.1102e-08\n\n\\end{lstlisting} \\color{black}\n    \n\n\n%%% \\end{document}\n    \n", "meta": {"hexsha": "45856fa6eca4c0d1ebff697459d66a622345ea39", "size": 2858, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/algs_examples_published/doc_FPNLSF.tex", "max_stars_repo_name": "qwtb/qwtb", "max_stars_repo_head_hexsha": "f6c79c7dca4065fd85d6f1c05257c1af34e85e34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-12-09T13:18:54.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-09T13:18:54.000Z", "max_issues_repo_path": "doc/algs_examples_published/doc_FPNLSF.tex", "max_issues_repo_name": "qwtb/qwtb", "max_issues_repo_head_hexsha": "f6c79c7dca4065fd85d6f1c05257c1af34e85e34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2015-12-09T13:08:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-13T11:33:41.000Z", "max_forks_repo_path": "doc/algs_examples_published/doc_FPNLSF.tex", "max_forks_repo_name": "qwtb/qwtb", "max_forks_repo_head_hexsha": "f6c79c7dca4065fd85d6f1c05257c1af34e85e34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-11-11T02:12:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-17T12:59:18.000Z", "avg_line_length": 18.9271523179, "max_line_length": 225, "alphanum_fraction": 0.6966410077, "num_tokens": 946, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.7283678302000617}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{amsmath,amsthm}\n\\usepackage[headings]{fullpage}\n\\usepackage[utopia]{mathdesign}\n\\usepackage{color}\n\n\\pagestyle{myheadings}\n\\markboth{Matrix conditioning}{}\n\n\\input{../../fncextra}\n\n\\begin{document}\n\n\\begin{center}\n  \\bf Terms and conditions\n\\end{center}\n\nPreviously you have seen how to blur an image, represented as an\n$m\\times n$ pixel intensity matrix $\\mX$, through multiplying by a matrix on each side:\n\\begin{equation}\n  \\label{eq:2}\n   \\mZ=\\mV\\, \\mX \\, \\mH,\n\\end{equation}\nwhere $\\mV = (\\mB_m)^k$, $\\mH = (\\mB_n)^k$, \n$B_i$ is the $i\\times i$ matrix made by your function\n\\texttt{blurmatrix}, and $k$ is a positive integer. You have also seen that deblurring can be accomplished by multiplying by matrix inverses on each side of $\\mZ$ (as computed equivalently by solving linear systems). However, while the restoration seems perfect for $k=1$, it fails completely for larger $k$.\n\nMatrix condition numbers explain these observations. The blurred matrix $\\mZ$ is perturbed by an amount comparable to machine precision. For $k=1$, the condition numbers of $\\mV$ and $\\mH$ are not large enough to amplify this error up to the same order of magnitude as $\\mX$ itself, so the noise is not perceived. But at some $k>1$, the condition numbers are so large that the noise is amplified enough to overwhelm the expected result.\n\nLet $\\bfx$ be a single column of $\\mX$. For the case of vertical blurring only, we have $\\bfz=\\mV\\bfx$ as a column of $\\mZ$. We solve $\\mV \\bfy = \\bfz$ for $\\bfy$, which is mathematically the same as $\\bfx$. Due to machine precision, though, the perturbation to $\\bfz$ causes an error satisfying\n\\begin{equation}\n\t\\label{bound}\n\t\\frac{\\|\\bfy-\\bfx\\|}{\\|\\bfx\\|} \\le \\kappa(\\mV)\\macheps,\n\\end{equation}\nwith $\\kappa$ being the matrix condition number. \n\n\\subsection*{Preparation}\n\nRead Section~2.8. Make sure your working \\texttt{blurmatrix.m} is available. \n\n\\subsection*{Goals}\n\nYou will compute condition numbers of blur matrix powers and compare them to the errors of repeated blur/deblur operations. \n\n\\subsection*{Procedure}\n\n\\begin{enumerate}\n\\item The condition number of a matrix has two factors, $\\|\\mA\\|$ and $\\|\\mA^{-1}\\|$. First you will show that the $\\|\\mA\\|$ term makes no trouble. For $n=50,100,150,\\ldots,800$, plot $\\|\\mB_n\\|$ versus $n$. \n\n\\item For the same $n$ as in step 1, plot $\\kappa(\\mB_n)$ versus $n$. You should use a log-log scale for this graph and get essentially a straight line. This implies that $\\log \\kappa \\approx a \\log n + b$, or $\\kappa \\approx C n^p$. \n\n\\item Let $\\mV=\\mB_{100}$. For $k=1,2,\\ldots,8$, plot $\\kappa(\\mV^k)$ as a function of $k$. This time the graph is straight on a semi-log scale, which implies $\\kappa \\approx C q^k$. \n\n\\item Let $\\bfx$ be a random vector of length 100. For $k=1,2,\\ldots,8$, let $\\bfz=\\mV\\bfx$ and then solve $\\mV\\bfy=\\bfz$ for $\\bfy$. Record the relative error in the result. Then make a table showing both sides of the inequality~\\eqref{bound}.\n\n\\end{enumerate}\n\n\\end{document}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: t\n%%% End:\n", "meta": {"hexsha": "5e0ed6ff295435a72bcaabebd5afe98bc9f33f86", "size": 3091, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter02/BlurConditioning/BlurConditioning.tex", "max_stars_repo_name": "snowdj/fnc-extras", "max_stars_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 109, "max_stars_repo_stars_event_min_datetime": "2018-04-21T09:02:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T19:03:54.000Z", "max_issues_repo_path": "labs/chapter02/BlurConditioning/BlurConditioning.tex", "max_issues_repo_name": "snowdj/fnc-extras", "max_issues_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-12-04T22:17:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T21:04:47.000Z", "max_forks_repo_path": "labs/chapter02/BlurConditioning/BlurConditioning.tex", "max_forks_repo_name": "snowdj/fnc-extras", "max_forks_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 49, "max_forks_repo_forks_event_min_datetime": "2017-04-02T17:21:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T17:19:57.000Z", "avg_line_length": 47.5538461538, "max_line_length": 436, "alphanum_fraction": 0.7133613717, "num_tokens": 927, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256512199032, "lm_q2_score": 0.8652240738888188, "lm_q1q2_score": 0.7283678194525925}}
{"text": "\\documentclass{homework}\n\\course{Math 5522H}\n\\author{Alex Li}\n\\input{preamble}\n\n\\begin{document}\n\\maketitle\n\n\\begin{inspiration} % https://frinkiac.com/caption/S01E04/240324\n  As far as anybody knows, we're a nice normal family.\n  \\byline{Homer Simpson in S01E04}\n  \\end{inspiration}\n\n  \\section{Terminology}\n\n  \\begin{problem}\n    What is a \\textbf{normal family} of holomorphic functions on an open set $U$?\n    \\end{problem}\n    \\begin{solution}\n    A normal family $\\mathcal{F}$ of functions $f\\in \\mathcal{F}: U \\to \\C$ is a family of functions where for any subsequence of functions $<f_n\\in\\mathcal{F}>_{n\\in \\N}$, there is a subsequence $<f_{n_k}>$ that converges normally in $U$.\n\n    A sequence of functions is said to converge normally if it converges uniformly on every compact subset of $U$ and pointwise on all of $U$.\n\n    \\end{solution}\n    \\begin{problem}\n      What does it mean to say that the infinite product\n        \\(\n            \\prod_{n=1}^\\infty \\left( 1 + a_n \\right)\n              \\)\n                converges?\n                \\end{problem}\n                \\begin{solution}\n                Let $s_N = \\prod_{n=1}^N \\left(1 + a_n\\right).$ The infinite product converges if the sequence $\\{s_N\\}$ converges, or if there is a value $s_\\infty$ such that for all $\\epsilon> 0$ there exists $N\\in \\N$ such that $\\abs{s_N - s_\\infty} \\leq \\epsilon$.\n\n                \\end{solution}\n                \\section{Numericals}\n\n                \\begin{problem}\n                  For which $z$ does the series\n                    \\[\n                        \\sum_{n=0}^\\infty \\frac{\\cos \\left( nz \\right)}{n!}\n                          \\]\n                            converge?\n\n                              Does it converge to a holomorphic function you recognize?\n                              \\end{problem}\n                              \\begin{solution}\n                              This series converges for every $z\\in \\C$. First note that\n                              \\[\n                              \\abs{\\cos(nz)} = \\abs{\\frac{e^{inz} + e^{-inz}}{2}} \\leq e^{n\\abs{z}}\n                              \\]\n                              Using Stirling's approximation, there is some $c\\in R$ so that $n! \\geq \\frac{1}{c}(\\frac{n}{e})^n$\n                              \\[\n                              \\abs{\\frac{\\cos(nz)}{n!}} \\leq \\frac{e^{n\\abs{z}}}{\\frac{1}{c}(\\frac{n}{e})^n} \\leq \\frac{ce^{n(|z|+1)}}{n^n}\n                              \\]\n                              Thus\n                              \\[\n                              \\abs{\\sum_{n=0}^\\infty \\frac{\\cos(nz)}{n!}} \\leq \\sum_{n=0}^\\infty \\frac{ce^{n(|z|+1)}}{n^n}  = \\sum_{n=0}^\\infty c(\\frac{e^{|z|+1)}}{n})^n\n                              \\]\n                              The series on the right converges by comparison to a geometric series like $\\frac{1}{2}$, and so by the weirstrauss M test, the series converges everywhere.\n\n                              Next we notice that $\\cos(nz) = \\frac{e^{inx} + e^{-inx}}{2}$ and use this to expand the sum\n                              \\begin{align*}\n                              \\sum_{n=0}^\\infty \\frac{\\cos(nx)}{n!} &= \\sum_{n=0}^\\infty \\frac{e^{inx} + e^{-inx}}{n!2}\\\\\n                              &= \\frac{1}{2}\\sum_{n=0}^\\infty \\frac{(e^{ix})^n}{n!} + \\frac{1}{2}\\sum_{n=0}^\\infty \\frac{(e^{-ix})^n}{n!}\\\\\n                              &= \\frac{1}{2}(e^{e^{ix}} + e^{e^{-ix}})\n                              \\end{align*}\n                              \\end{solution}\n                              \\begin{problem}\\label{p4h10}\n                                For which $z$ does the series\n                                  \\[\n                                      \\sum_{0 \\neq n \\in \\Z} \\left( \\frac{1}{z+n} - \\frac{1}{n} \\right)\n                                        \\]\n                                          converge?\n\n                                            Does it converge to a meromorphic function you recognize?\n                                              \\textit{Hint:} \\ref{residues-all-one}.\n                                              \\end{problem}\n                                              \\begin{solution}\n                                              When $z\\in \\Z$, the series doesn't converge since some of it's terms are infinite. Otherwise, it should converge (pointwise).\n                                                \\begin{align*}\n                                                \\abs{\\sum_{0 \\neq n \\in \\Z} \\left( \\frac{1}{z+n} - \\frac{1}{n} \\right) }&= \\abs{ \\sum_{0 \\neq n \\in \\Z} \\left( \\frac{n - (z+n)}{(z+n)n} \\right) }\\\\\n                                                &=  \\abs{\\sum_{0 \\neq n \\in \\Z} \\left( \\frac{-z}{(z+n)n} \\right)}\\\\\n                                                &= \\abs{ z\\left(\\sum_{\\{n: |n|<=|z+n|\\}} \\left( \\frac{-1}{(z+n)n} \\right) + \\sum_{\\{n: |n|>|z+n|\\}} \\left( \\frac{-1}{(z+n)n} \\right)\\right)}\\\\\n                                                &\\leq \\abs{z}\\left(\\sum_{\\{n: |n|<=|z+n|\\}} \\frac{1}{\\abs{n^2}} + \\sum_{\\{n: |n|>|z+n|\\}} \\frac{1}{\\abs{z+n}^2} \\right)\\\\\n                                                &\\leq \\abs{z}\\left(\\sum_{0\\neq n\\in \\Z}  \\frac{1}{\\abs{n^2}}+ \\sum_{\\{0\\neq n \\in \\Z\\}} \\frac{1}{\\abs{z+n}^2} \\right)\n                                                  \\end{align*}\n                                                  And both of these sums are clearly finite (by say comparison to the integral $\\int_{-\\infty}^\\infty \\frac{dn}{(z+n)^2}$.)\n\n\n                                                  Now add $\\frac{1}{z}$ to the sum and let's compare this sum to $\\pi\\cot(\\pi z)$. Both are holomorphic everywhere but the integers, and at those points, both of these functions have simple poles at $\\Z$ with residue $1$. (This was proved for cot in the last assignment, and for the expression, we can just see that there's a single $1/(z-n)$ term plus a holomorphic function at each integer $n$). Also, both are periodic in that $f(z)=f(z+1)$ for all $z$. \n\n                                                  So the function \n                                                  \\[\n                                                  \\pi \\cot(\\pi z) -\\left(\\sum_{n\\in \\Z} \\frac{1}{z+n} - \\frac{1}{n}\\right)\n                                                  \\]\n                                                  is holomorphic and also periodic. We will show that it is bounded for $\\abs{\\Re{(z)}}\\leq .5$. First note that if we also have that $\\abs{\\Im(z)}\\leq 1$, the function is bounded since it is holomorphic and we are considering a bounded region.\n                                                  Otherwise, on this strip,\n                                                  \\[\n                                                  \\abs{\\pi\\cot(\\pi z)} = \\pi\\abs{i\\frac{e^{iz}+e^{-iz}}{e^{iz}-e^{-iz}}}\n                                                  \\leq \\pi \\frac{\\abs{e^{iz}+e^{-iz}}}{\\abs{e^{iz}-e^{-iz}}}\\leq \\frac{\\pi\\abs{e^{-\\Im(z)}+e^{-\\Im(z)}}}{\\abs{e^{-\\Im(z)}-e^{\\Im(z)}}}\n                                                  \\leq \\frac{\\abs{2\\pi e^{-1}}}{\\abs{e-\\frac{1}{e}}}\n                                                  \\]\n                                                  Since the function is 1 periodic, $\\pi\\cot(\\pi z)$ is bounded everywhere.\n\n                                                  Next we look at the infinite sum:\n                                                  \\begin{align*}\n                                                  \\abs{\\sum_{n\\in \\Z} \\frac{1}{z+n} - \\frac{1}{n}} &\\leq \\sum_{0\\neq n\\in \\Z} \\abs{\\frac{1}{z+n} - \\frac{1}{n} }\\\\\n                                                  &\\leq \\sum_{n\\in \\Z} \\frac{\\abs{z}}{\\abs{n}\\abs{z+n}}\\\\\n                                                  &\\leq \\sum_{n\\in \\Z}\\abs{\\frac{z}{(\\abs{n}-.5)^2}}\\leq \\infty\n                                                  \\end{align*}\n                                                  Where the last line comes from the fact that for any point $n\\in \\Z$, $\\abs{n+z-.5} \\geq \\abs{z}$, since $z$ has real part no more than $.5$ in magnitude. Thus this function is finite and hence constant. Since it is 0 at the point 0, it is 0 everywhere so \n                                                  \\[\n                                                  \\pi \\cot(\\pi z) -\\frac{1}{z} = \\left( \\sum_{0\\neq n\\in \\Z} \\frac{1}{z+n} - \\frac{1}{n}\\right).\n                                                  \\]\n                                                  \\end{solution}\n                                                  \\section{Exploration}\n\n                                                  \\begin{problem}\\label{poisson-summation}Describe conditions on $f$ so\n                                                    that, for a suitable $\\gamma_1$ and $\\gamma_2$,\n                                                      \\[\n                                                          \\sum_{n=-\\infty}^\\infty f(n) = \\int_{\\gamma_1} \\frac{f(z)}{e^{2\\pi i z} - 1} \\, dz - \\int_{\\gamma_2} \\frac{f(z)}{e^{2\\pi i z} - 1} \\, dz.\n                                                            \\]\n                                                              Then expand $1/(e^{2\\pi i z} - 1)$ as a geometric series to deduce the \\textbf{Poisson summation formula}\n                                                                \\[\n                                                                    \\sum_{n=-\\infty}^\\infty f(n) = \\sum_{n=-\\infty}^\\infty \\hat{f}(n) \n                                                                      \\]\n                                                                        where $\\hat{f}$ is the Fourier transform, i.e.,\n                                                                          \\[\n                                                                              {\\hat {f}}(\\xi ) := \\int _{-\\infty }^{\\infty} f(x) \\, e^{-2\\pi ix \\xi} \\,dx.\n                                                                                \\]\n                                                                                \\end{problem}\n                                                                                \\begin{solution}\n                                                                                Let's explore! Noting that the (order 1) zeros of $e^{2\\pi i z} - 1$ are the integers, we likely want to use the residue theorem. So let $f$ be holomorphic. The residue of $f(z)$ at $k\\in Z$ is\n                                                                                \\[\n                                                                                \\lim_{z\\to k} \\frac{(z-k)f(z)}{e^{2\\pi i z}-1} = \\lim_{z\\to k}\\frac{(z-k)f'(z)+f(z)}{2\\pi i e^{2\\pi iz}} = \\frac{f(k)}{2\\pi i e^{2\\pi ik}} = \\frac{f(k)}{2\\pi i}\n                                                                                \\]\n                                                                                So if we take a curve around all the zeros, we get the sum. In particular, let $\\gamma$ be the curve around the rectangle centered at $(0,0)$ with height $h$ and width $R\\to \\infty$. Provided that $f$ gets small enough for everything to converge (say $O(\\frac{1}{z^2}$) as $R\\to \\infty$, the two sides of the rectangle will go to zero and so the residue theorem shows us that \n                                                                                \\begin{align*}\n                                                                                \\sum_{k=-\\infty}^\\infty f(k) &= \\int_{-\\infty}^\\infty -\\frac{f(x+ih)}{e^{2\\pi i (x+ih)}-1} dx + \\int_{-\\infty}^\\infty \\frac{f(x-ih)}{e^{2\\pi i (x-ih)}-1} dx\\\\\n                                                                                &= \\lim_{h\\to 0}\\int_{-\\infty}^\\infty -\\frac{f(x+ih)}{e^{2\\pi i (x+ih)}-1} + \\frac{f(x-ih)}{e^{2\\pi i (x-ih)}-1} dx\\\\\n                                                                                &= \\lim_{h\\to 0}\\int_{-\\infty}^\\infty \\frac{f(x)}{1 - e^{2\\pi i (x+ih)}} + \\frac{f(x)}{e^{2\\pi i (x - ih)}-1} dx\\\\\n                                                                                &= \\lim_{h\\to 0}\\int_{-\\infty}^\\infty \\frac{f(x)}{1 - e^{2\\pi i (x+ih)}} + \\frac{f(x)e^{-2\\pi i (x - ih)}}{1 - e^{-2\\pi i(x-ih)}} dz\n                                                                                \\end{align*}\n\n                                                                                We now need to get rid of the denominator, note that\n                                                                                \\begin{gather*}\n                                                                                \\frac{1}{1-e^{2\\pi i (z + ih)}} = \\sum_{k=0}^\\infty e^{2\\pi i (z+ ih)k}\\\\\n                                                                                \\frac{e^{-2\\pi i (z - ih)}}{1-e^{-2\\pi i (z - ih)}} = \\sum_{k=1}^\\infty e^{2\\pi i (z- ih)k} = \\sum_{-\\infty}^{-1} e^{2\\pi i (z-ih)k}\n                                                                                \\end{gather*}\n                                                                                And using these power series, we get the expression\n                                                                                \\begin{align*}\n                                                                                \\sum_{k=-\\infty} ^\\infty f(k) &= \\lim_{h\\to 0}\\int_{-\\infty}^\\infty f(x)\\left(\\sum_{k=0}^{\\infty}e^{2\\pi i (x+ih)k} + \\sum_{k=-\\infty}^{-1} e^{2\\pi i (x-ih)k}\\right) dx\\\\\n                                                                                &= \\lim_{h\\to 0}\\int_{-\\infty}^\\infty f(x)\\left(\\sum_{k=0}^{\\infty}e^{2\\pi i xk}e^{-2\\pi hk} + \\sum_{k=-\\infty}^{-1} e^{2\\pi i xk}e^{2\\pi hk}\\right) dx\n                                                                                \\end{align*}\n                                                                                We would like to get rid of the $e^{\\pm 2\\pi h k}$ term.\n                                                                                Consider the sequence of functions \n                                                                                \\[\n                                                                                f_h(x) = f(x)\\left(\\sum_{k=0}^{\\infty}e^{2\\pi i xk}e^{-2\\pi kh} + \\sum_{k=-\\infty}^{-1} e^{2\\pi i xk}e^{2\\pi kh}\\right)\n                                                                                \\]\n                                                                                indexed by $\\frac{1}{h}\\in \\N$ where and $h$ is sufficiently small so that the function always converges. We can choose $f(x)$ as in the following lemma.\n                                                                                \\begin{lemma}\\label{sum_fh_converges}\n                                                                                If, for any $\\epsilon,C>0$\n                                                                                \\[\\abs{f(x)} <  C\\abs{(1-e^{\\epsilon\\abs{x}})/x^2}\\] \n                                                                                holds for all $x$,\n                                                                                then \n                                                                                \\[ \\lim_{R\\to\\infty} \\int_{-R}^R f_h(x) dx < \\infty\\] converges for small enough $h$.\n                                                                                \\end{lemma}\n                                                                                \\begin{proof}\n                                                                                Each term of the sum in $f_h$ is a bounded value times $f(x)e^{c_1kx}$ with $c_1<1$, so using the geometric series formula\n                                                                                \\[\n                                                                                \\abs{f_h(x)} \\leq f(x)\\frac{1}{1-e^{c_1 hx}}\n                                                                                \\]\n                                                                                Then using the hypothesis of the lemma with $\\epsilon = c_1h$ (we can make $\\epsilon$ arbitrarily small by varying $h$,\n                                                                                \\[\n                                                                                \\int_{-\\infty}^\\infty \\abs{f_h(x)}dx \\leq \\int_{-\\infty}^\\infty Cx^{-2} dx \\leq \\infty\n                                                                                \\]\n                                                                                and thus the integral converges. \n                                                                                \\end{proof}\n                                                                                Now we can consider swapping the order of the limits and integration. We need another lemma.\n                                                                                \\begin{lemma}\\label{fh_converges_normally}\n                                                                                \\[\n                                                                                f_h(x) = f(x)\\left(\\sum_{k=0}^{\\infty}e^{2\\pi i xk}e^{-2\\pi kh} + \\sum_{k=-\\infty}^{-1} e^{2\\pi i xk}e^{2\\pi kh}\\right)\n                                                                                \\]\n                                                                                converges normally to \\[\\sum_{k=-\\infty}^\\infty f(x)e^{2\\pi kh}\\]\n                                                                                \\end{lemma}\n                                                                                \\begin{proof}\n                                                                                To see that this convergence is uniform on compact sets, we show that it is uniform on any interval $[a, b]$. \n                                                                                Choose $N$ so big that \n                                                                                \\[\n                                                                                \\abs{\\sum_{k=N}^\\infty f(x)e^{2\\pi i x k}(1-e^{-2\\pi hk}) + \n                                                                                \\sum_{k=-\\infty}^{-N} f(x)e^{2\\pi i x k}(1-e^{2\\pi hk})} < \\epsilon_1\n                                                                                \\] \n                                                                                this is possible for any $\\epsilon_1>0$ since the sum converges, since $f(x)$ is bounded on the interval $[a, b]$ and the other terms are bounded in magnitude by 1. \n\n                                                                                Next note that, for a fixed $x$, the terms of the sum $e^{2\\pi ix k}e^{2\\pi h k}$ will converge to $e^{2\\pi h k}$ since $\\lim_{h\\to 0} e^{2\\pi h k}\\to 1$. Again using the fact that $f$ is bounded, we can choose $h$ so small that $f(x)e^{2\\pi x i k}(1-e^{2\\pi h k})\\leq \\epsilon_2$ for any $\\epsilon_2>0$.\n\n                                                                                Thus\n                                                                                \\begin{align*}\n                                                                                \\abs{\\sum_{k=-\\infty}^\\infty f(x)e^{2\\pi k h} - f_h(x)} &= \\bigg| \n                                                                                \\sum_{k=N}^\\infty f(x)e^{2\\pi i x k}(1-e^{-2\\pi hk}) \\\\\n                                                                                &+ \\sum_{k=-\\infty}^{-N} f(x)e^{2\\pi i x k}(1-e^{2\\pi hk}) + \\sum_{-N+1}^{N-1} f(x)e^{2\\pi ixk}(1-e^{2\\pi kh})\\bigg| \\\\\n                                                                                &\\leq \\epsilon_1 + \\epsilon_2\n                                                                                \\end{align*}\n\n                                                                                It must converge pointwise everywhere, since any point is in some compact set, where the function converges uniformly.\n                                                                                \\end{proof}\n                                                                                Now, we want to compute\n                                                                                \\[\n                                                                                 \\lim_{h\\to 0}\\lim_{R\\to \\infty} \\int_{-R}^R f_h(x)dx.\n                                                                                 \\]\n                                                                                 For all sufficiently small $h$ and any $\\epsilon>0$, we can find $R_1$ big enough so that\n                                                                                 \\[\n                                                                                 \\abs{\\int_{-\\infty}^\\infty f_h(x)dx - \\int_{-R_1}^{R_1} f_h(x)dx} < \\epsilon\n                                                                                 \\]\n                                                                                 since the absolute vale of $\\int_{-\\infty}^\\infty f_h(x)dx$ is bounded by \\ref{sum_fh_converges}.\n\n\n                                                                                 Now we can use Theorem 1.4 along with lemma \\ref{fh_converges_normally} of Palka (normal convergence + continuous $\\implies$ can swap integral order) to bring the limit inside the integral: \n                                                                                 \\[\n                                                                                  \\lim_{h\\to 0} \\int_{-R_1}^{R_1} f_h(x)dx = \n                                                                                  \\int_{-R_1}^{R_1}\\lim_{h\\to 0} f_h(x)dx = \\int_{-R_1}^{R_1}\\sum_{k=-\\infty}^\\infty e^{2\\pi i k x} f(x)dx \n                                                                                  \\]\n                                                                                  And by increasing $R_1$ to make $\\epsilon$ arbitrarily small we conclude that\n                                                                                  \\[\n                                                                                  \\sum_{k=-\\infty}^\\infty f(k) = \\lim_{h\\to 0} \\lim_{R\\to \\infty} \\int_{-R}^{R} f_h(x)dx = \\int_{-\\infty}^{\\infty}\\sum_{k=-\\infty}^\\infty e^{2\\pi i k x} f(x)dx \n                                                                                  \\]\n\n                                                                                  If we can only interchange the order of the integral and the sum, we will have the correct formula. To do this, we can use Fubini's theorem and it suffices for $f$ to be such that the value of the sum of the integral to be finite- that is, for $\\sum_{k=-\\infty}^\\infty f(k)$ to be finite. Thus we can finally conclude that\n                                                                                  \\begin{align*}\n                                                                                  \\sum_{-\\infty} ^ \\infty f(x) &=  \\sum_{k=-\\infty}^{\\infty}\\int_{-\\infty}^\\infty f(x)e^{2\\pi i xk} dx\\\\\n                                                                                  &=  \\sum_{k=-\\infty}^{\\infty}\\int_{-\\infty}^\\infty f(x)e^{-2\\pi i xk} dx = \\sum_{k=-\\infty}^\\infty \\hat f(k)dx\n                                                                                  \\end{align*}\n                                                                                  Provided that for any $\\epsilon,C>0$\n                                                                                  \\[\\abs{f(x)} <  C\\abs{(1-e^{\\epsilon\\abs{x}})/x^2}\\] \n                                                                                  holds for all $x$, $f$ is holomorphic, and $\\sum_{k\\in \\Z} f(k)$ is finite.\n                                                                                  \\end{solution}\n\n                                                                                  \\begin{problem}\\label{modularity}For $a > 0$ define\n                                                                                    $\\vartheta(a) = \\sum_{n=-\\infty}^\\infty e^{-a \\pi n^2}$.  Recalling\n                                                                                      \\ref{fourier-transform-itself} shows that if $f(z) = e^{-a \\pi z^2}$\n                                                                                        we can compute $\\hat{f}(z)$.  Use $\\hat{f}(z)$ and\n                                                                                          \\ref{poisson-summation} to verify\n                                                                                            \\[\n                                                                                                \\vartheta(a) = \\vartheta(1/a) / \\sqrt{a}.\n                                                                                                  \\]\n                                                                                                  \\end{problem}\n                                                                                                  \\begin{solution}\n\n                                                                                                  \\begin{lemma}\n                                                                                                  \\[\n                                                                                                  \\hat{f}(z) = \\frac{e^{\\frac{-\\pi \\xi}{a}}}{\\sqrt{a}}\n                                                                                                  \\]\n                                                                                                  \\end{lemma}\n                                                                                                  \\begin{proof}\n                                                                                                  Cosider the closed rectangular contour that goes on a straight line between the four points below.\n                                                                                                  \\[\n                                                                                                  R \\mapsto R - i\\xi/a \\mapsto - R - i\\xi/a \\mapsto -R\n                                                                                                  \\]\n                                                                                                  As $R\\to\\infty$, the sides of this rectangle with nonzero imaginary derivative will disappear as\n                                                                                                  \\[\n                                                                                                  \\abs{\\int_{-\\xi/a}^{0} e^{-\\pi((\\pm R+ix) -i\\xi/a)^2} dx} \\leq \\abs{\\xi/a} \\abs{e^{-\\pi R^2}}\\to 0.\n                                                                                                  \\]\n                                                                                                  Since $f$ is holomorphic on the interior of the rectangal, we conclude that the integral of the top and bottom sides of the rectangle are negatives of each other. Let's compute the imaginary one going in the wrong direction:\n                                                                                                  \\begin{align*}\n                                                                                                  {\\hat {f}}(\\xi ) &=\\int_{-\\infty}^\\infty e^{-a\\pi (z- i\\xi/a)^2}e^{-2\\pi i x\\xi}\\\\\n                                                                                                  &=  e^{-\\xi^2\\pi/a}\\int _{-\\infty }^{\\infty} e^{-(x\\sqrt{\\pi a})^2} \\,dx\\\\\n                                                                                                  &=  \\frac{e^{-\\xi^2\\pi/a}}{\\sqrt{\\pi a}}\\int_{-\\infty}^\\infty e^{-u^2} \\,du \\quad \\color{purple} u = \\sqrt{\\pi a}x, du = \\sqrt{\\pi a} dx\\\\\n                                                                                                  &=  \\frac{e^{-\\xi^2\\pi/a}}{\\sqrt{\\pi a}} \\sqrt{\\pi} =  \\frac{e^{-\\xi^2\\pi/a}}{\\sqrt{a}}\n                                                                                                  \\end{align*}\n                                                                                                  \\end{proof}\n                                                                                                  Next, we apply the previous problem's statement. First we must check the conditions, but this is trivial, so we skip that step (Well, I don't really think it's true for my conditions). Anyways, we see that \n                                                                                                  %TODO apply condition\n                                                                                                  \\begin{align*}\n                                                                                                  \\vartheta(x) &= \\sum_{n=-\\infty}^{\\infty} e^{-a\\pi n^2} = \\sum_{n=-\\infty}^{\\infty} f(n) \\\\\n                                                                                                  &= \\sum_{n=-\\infty}^\\infty \\hat f(n) = \\sum_{n=-\\infty}^\\infty \\frac{e^{-n^2\\pi/a}}{\\sqrt{a}}\\\\\n                                                                                                  &= \\frac{\\sum_{n=-\\infty}^\\infty e^{-n^2\\pi(1/a)}}{\\sqrt{a}} = \\vartheta(1/a)/\\sqrt{a}\n                                                                                                  \\end{align*}\n                                                                                                  \\end{solution}\n                                                                                                  \\begin{problem}\n                                                                                                    Having just celebrated $\\pi$-day, some computer calculations revealed\n                                                                                                    \\begin{align*}\n                                                                                                      \\vartheta(1/(4\\pi)) = \\sum_{n=-\\infty}^\\infty e^{-n^2/4} &=\n                                                                                                      3.544907701811032\\textbf{10533931955126186}\\ldots \\\\\n                                                                                                        2\\sqrt{\\pi} &=\n                                                                                                        3.544907701811032\\textbf{05459633496668229}\\ldots\n                                                                                                        \\end{align*}\n                                                                                                        Is my computer broken?  (For more, see \\texttt{https://arxiv.org/abs/1809.10907}.)\n                                                                                                        \\end{problem}\n                                                                                                        \\begin{solution}\n                                                                                                        \\[\n                                                                                                        \\vartheta(1/(4\\pi)) = \\sum_{n=-\\infty}^\\infty e^{-\\frac{\\pi n^2}{4\\pi}} = \\sum_{-\\infty}^\\infty e^{-n^2/4}\n                                                                                                        \\]\n                                                                                                        By the preceding problem, this expression is equal to \n                                                                                                        \\[\n                                                                                                        \\frac{\\vartheta(4\\pi)}{\\sqrt{4\\pi}} = \\frac{1}{2\\sqrt{\\pi}}\\sum_{n=-\\infty}^\\infty e^{-4\\pi^2 n^2} = \\frac{1}{2\\sqrt{\\pi}}\\left(1 + 2\\sum_{n=1}^\\infty e^{-4\\pi^2 n^2}\\right) = \\frac{1}{2\\sqrt{\\pi}} + \\text{tiny}\n                                                                                                        \\]\n                                                                                                        So it makes sense that they are super close\n                                                                                                        \\end{solution}\n\n                                                                                                        \\begin{problem}\n                                                                                                          Define\n                                                                                                            \\[\n                                                                                                                \\wp(z) = \\frac{1}{z^2} + \\sum_{0 \\neq \\lambda \\in \\Z[i]} \\left( \\frac{1}{(z - \\lambda)^2} - \\frac{1}{\\lambda^2} \\right)\n                                                                                                                  \\]\n                                                                                                                    which is \\textbf{Weierstrass' elliptic function} on the square lattice.  Use \\ref{sum-one-over-gaussian-integers} to verify that $\\wp(z)$ converges.\n                                                                                                                    \\end{problem}\n                                                                                                                    \\begin{solution}\n                                                                                                                    \\begin{align*}\n                                                                                                                    \\wp(z) &= \\frac{1}{z^2} + \\sum_{0 \\neq \\lambda \\in \\Z[i]} \\left( \\frac{1}{(z - \\lambda)^2} - \\frac{1}{\\lambda^2} \\right)\\\\\n                                                                                                                    &= \\frac{1}{z^2} + \\sum_{0 \\neq \\lambda \\in \\Z[i]} \\left( \\frac{\\lambda^2 - (z-\\lambda)^2}{\\lambda^2(z-\\lambda)^2} \\right)\\\\\n                                                                                                                    &= \\frac{1}{z^2} + \\sum_{0 \\neq \\lambda \\in \\Z[i]} \\left( \\frac{\\frac{\\lambda}{z-\\lambda}^2 - 1}{\\lambda^2} \\right)\\\\\n                                                                                                                    &= \\frac{1}{z^2} + \\sum_{0 \\neq \\lambda \\in \\Z[i]} \\left( \\frac{\\frac{\\lambda^2 - z^2 + 2z\\lambda - \\lambda^2}{(z-\\lambda)^2}}{\\lambda^2} \\right)\\\\\n                                                                                                                    &= \\frac{1}{z^2} + \\sum_{0 \\neq \\lambda \\in \\Z[i]} \\left( \\frac{z(\\lambda - 2z)}{\\lambda^2(z-\\lambda)^2} \\right)\\\\\n                                                                                                                    \\end{align*}\n                                                                                                                    The interior of the sum is a degree $-3$ polynomial in $\\lambda$ and the constant $z$, so except for finitely many terms where $|\\lambda|\\approx |z|$, there will be some constant $c$ where the terms are less than $c\\lambda^{-3}$. Since $-3 < -2$, the sum converges.\n                                                                                                                    \\end{solution}\n\n                                                                                                                    \\begin{problem}\\label{elliptic-derivative-periodic}Compute $\\wp'(z)$ by differentiating term-by-term to show that $\\wp'(z + \\lambda) = \\wp'(z)$ for $\\lambda \\in \\Z[i]$.\n                                                                                                                    \\end{problem}\n                                                                                                                    \\begin{solution}\n                                                                                                                    We can prove the identity by differentiating term by term,\n                                                                                                                    \\begin{align*}\n                                                                                                                    \\wp'(z) = z^{-3} + \\sum_{0\\neq \\lambda\\in\\Z[i]} (-2(z-\\lambda)^{-3}  + 2\\lambda^{-3})\\\\\n                                                                                                                    = \\sum_{\\lambda\\in\\Z[i]}(-2(z-\\lambda)^{-3}) + \\sum_{0\\neq \\lambda\\in\\Z[i]} 2\\lambda^{-3}\\\\\n                                                                                                                    \\wp'(z-\\lambda_1) = (z-\\lambda_1)^{-3} + \\sum_{0\\neq \\lambda\\in\\Z[i]} (-2(z-\\lambda-\\lambda_1)^{-3}  + 2\\lambda^{-3})\\\\\n                                                                                                                    = \\sum_{\\lambda\\in\\Z[i]}(-2(z-\\lambda)^{-3}) + \\sum_{0\\neq \\lambda\\in\\Z[i]} 2\\lambda^{-3}\n                                                                                                                    \\end{align*}\n                                                                                                                    This also gives us the value of $\\wp'(z)$.\n                                                                                                                    \\end{solution}\n                                                                                                                    \\begin{problem}\n                                                                                                                      Compare $\\wp(z)$ and $\\wp(-z)$.  Use this to relate $\\wp(1/2)$ and $\\wp(-1/2)$ and to relate $\\wp(i/2)$ and $\\wp(-i/2)$ and with \\ref{elliptic-derivative-periodic}, conclude that $\\wp(z + \\lambda) = \\wp(z)$ for $\\lambda \\in \\Z[i]$.\n                                                                                                                      \\end{problem}\n                                                                                                                      \\begin{solution}\n                                                                                                                      It must be that $\\wp(z) = \\wp(-z)$, since\n                                                                                                                      \\begin{align*}\n                                                                                                                      \\wp(-z) &= \\frac{1}{(-z)^2} + \\sum_{0 \\neq \\lambda \\in \\Z[i]} \\left( \\frac{1}{(-z - \\lambda)^2} - \\frac{1}{\\lambda^2} \\right)\\\\\n                                                                                                                      &= \\frac{1}{z^2} + \\sum_{0 \\neq -\\lambda \\in \\Z[i]} \\left( \\frac{1}{(z - \\lambda)^2} - \\frac{1}{\\lambda^2} \\right) = \\wp(z)\n                                                                                                                      \\end{align*}\n                                                                                                                      Therefore $\\wp(\\frac{1}{2})=\\wp(-\\frac{1}{2})$, $\\wp(\\frac{i}{2})=\\wp(-\\frac{i}{2})$. By the fundamental theorem of calculus,\n                                                                                                                      \\[\n                                                                                                                      \\wp(\\frac{1}{2}) - \\wp(-\\frac{1}{2}) = \\int_{-\\frac{1}{2}}^{.\\frac{1}{2}}\\wp'(x)dx = 0 = \\int_{-\\frac{1}{2}}^{\\frac{1}{2}} i\\wp'(ix)dx =\\wp(\\frac{i}{2}) - \\wp(-\\frac{i}{2})\n                                                                                                                      \\]\n                                                                                                                      And since $\\wp'$ is doubly, periodic, we can even conclude that for any $x$,\n                                                                                                                      \\[\n                                                                                                                      \\wp(x+1) - \\wp(x) = \\int_{x}^{x+1}\\wp'(x)dx = 0 = \\int_{x}^{x+1} i\\wp'(ix)dx  = \\wp(x+i) - \\wp(x)\n                                                                                                                      \\]\n                                                                                                                      so $\\wp$ is also doubly periodic.\n\n                                                                                                                      \\end{solution}\n                                                                                                                      \\section{Prove or Disprove and Salvage if Possible}\n\n                                                                                                                      \\begin{problem}\\label{differentiating-taylor-series}If\n                                                                                                                        $f(z) = \\sum_{n=0}^\\infty a_n z^n$ has radius of convergence $r$,\n                                                                                                                          then the series\n                                                                                                                            \\[\n                                                                                                                                g(z) = \\sum_{n=1}^\\infty n a_n z^{n-1} \n                                                                                                                                  \\]\n                                                                                                                                    has radius of convergence $r$ and if $|z| < r$ then $f'(z) = g(z)$.\n                                                                                                                                    \\end{problem}\n                                                                                                                                    \\begin{solution}\n                                                                                                                                    We get the reciprical of the radius of convergence of $g$ with the root test:\n                                                                                                                                    \\[\n                                                                                                                                    \\limsup \\sqrt[n]{n\\abs{a_{n+1}}} =\n                                                                                                                                    \\limsup \\sqrt[n]{n}\\sqrt[n]{\\abs{a_{n+1}}} =\n                                                                                                                                    \\limsup \\sqrt[n]{\\abs{a_{n+1}}}\n                                                                                                                                    \\]\n                                                                                                                                    And this last term is the reciprical of the radius of convergence of the sequence \n                                                                                                                                    \\[\n                                                                                                                                    \\sum_{n=0}^\\infty a_{n+1}z^n = \\frac{1}{z}\\sum_{n=1}^\\infty a_{n+1}z^{n+1} = \\frac{1}{z}f(z)\n                                                                                                                                    \\]\n                                                                                                                                    As this has the same radius of convergence as $f$,\n                                                                                                                                    $g$ has the same radius of convergence as $f$.\n\n                                                                                                                                    Next we need to show that $f'(z)=g(z)$. To start we make a short lemma.\n                                                                                                                                    \\begin{lemma}\\label{difference_of_nths}\n                                                                                                                                    \\[(z+h)^n - z^n = h\\sum_{k=0}^{n-1}(z+h)^{n-1-k}z^{k}\\]\n                                                                                                                                    \\end{lemma}\n                                                                                                                                    \\begin{proof}\n                                                                                                                                    \\[\n                                                                                                                                    (a-b)\\sum_{k=0}^{n-1} a^{n-1-k}b^{k}=\\sum_{k=0}^{n-1} a^{n-k}b^{k}-\\sum_{k=1}^{n}a^{n-k}b^{k} = a^n-b^n\n                                                                                                                                    \\]\n                                                                                                                                    Take $a=z+h, b=z$ to prove the lemma.\n                                                                                                                                    \\end{proof}\n                                                                                                                                    To compute $f'(z)$, let's look at the difference quotient.\n                                                                                                                                    \\begin{align*}\n                                                                                                                                    \\frac{f(z+h)-f(z)}{h}\n                                                                                                                                    &= \\frac{1}{h}\\sum_{n=0}^\\infty a_n((z+h)^n - z^n) \\\\\n                                                                                                                                    &= \\sum_{n=0}^\\infty a_n\\sum_{k=0}^{n-1}(z+h)^{n-1-k}z^{k}\\quad \\text{ Lemma \\eqref{difference_of_nths}}\n                                                                                                                                    \\end{align*}\n                                                                                                                                    We want $f'(z)-g(z)=0$, so let's subtract $g(z)$ from the difference quotient. The coefficient of $a_n$ is then\n                                                                                                                                    \\begin{align*}\n                                                                                                                                    \\left(\\sum_{k=0}^{n-1}(z+h)^{n-1-k}z^{k}\\right) - nz^{n-1} &= \\sum_{k=0}^{n-1}\\left((z+h)^{n-1-k}z^{k} - z^{n-1} \\right)\\\\\n                                                                                                                                    &= \\sum_{k=0}^{n-1}z^k\\left((z+h)^{n-1-k} - z^{n-1-k} \\right)\\\\\n                                                                                                                                    &= \\sum_{k=0}^{n-1}z^k\\left((z+h)^{n-1-k} - z^{n-1-k} \\right)\\\\\n                                                                                                                                    &= h\\sum_{k=0}^{n-1}z^k\\left(\\sum_{l=0}^{n-1-k}(z+h)^{n-1-k-l}z^l\\right)\\quad \\text{ Lemma \\eqref{difference_of_nths}}\n                                                                                                                                    \\end{align*}\n                                                                                                                                    Let $m = max(|z+h|, |z|)$, so that we can bound the magnitude of this difference\n                                                                                                                                    \\begin{align*}\n                                                                                                                                    \\left(\\sum_{k=0}^{n-1}(z+h)^{n-1-k}z^{k}\\right) - nz^{n-1} &\\leq  h\\sum_{k=0}^{n-1}m^k\\left((n-1-k)m^{n-1-k}\\right)\\\\\n                                                                                                                                    &\\leq  h\\binom{n-1}{2}m^{n-1}\n                                                                                                                                    \\end{align*}\n                                                                                                                                    So therefore we can show that the difference between $f'$ and $g$ vanishes.\n                                                                                                                                    \\begin{align*}\n                                                                                                                                    \\abs{f'(z)-g(z)}\\leq \\lim_{h\\to 0}h \\sum_{n=0}^\\infty a_n\\binom{n-1}{2}m^{n-1}\n                                                                                                                                    \\end{align*}\n                                                                                                                                    As $h\\to 0$, $m$ is less than the radius of convergence, so the sum without the $\\binom{n-1}{2}$ term converges. Since $\\lim_{n\\to\\infty} \\sqrt[n]{\\binom{n-1}{2}} = \\lim_{n\\to\\infty} \\sqrt[n]{n^2} = 1$,\n                                                                                                                                    the whole series converges within the same radius of convergence, and thus the two series are equal.\n\n                                                                                                                                    \\end{solution}\n                                                                                                                                    \\begin{problem}\\label{sum-one-over-gaussian-integers}For $n > 2$, the\n                                                                                                                                      series \\( \\displaystyle\\sum_{0 \\neq \\lambda \\in \\Z[i]} \\frac{1}{|\\lambda|^n} \\).\n                                                                                                                                        converges.\n                                                                                                                                        \\end{problem}\n                                                                                                                                        \\begin{solution}\n                                                                                                                                        Each $\\lambda\\in\\Z[i]\\setminus 0$ is contained on the square with corners \\[(n, 0), (0, n), (-n, 0), (0, -n)\\] with $n\\in \\N$. Furthermore, the $nth$ of these squares has $4n$ points in total, and each point is of radius at most $n$ from the origin. We can deduce a formula from these observations:\n                                                                                                                                        \\[\n                                                                                                                                        \\sum_{0 \\neq \\lambda \\in \\Z[i]} \\frac{1}{|\\lambda|^n} < \\sum_{k=1}^\\infty \\frac{\\text{zeros on kth square}}{\\text{furthest zero from origin on kth square}} = \\sum_{k=1}^\\infty \\frac{4k}{\\sqrt{k}^n} = 4\\sum_{k=1}^\\infty k^{1-\\frac{n}{2}}\n                                                                                                                                        \\]\n                                                                                                                                        If $n > 2$, then the term to the right is a geometric series, so it converges. Thus the original series converges as well.\n                                                                                                                                        \\end{solution}\n                                                                                                                                        \\begin{problem}\\label{elliptic-more-than-two-poles}There is no meromorphic function $f : \\C \\to \\hat{\\C}$ having simple poles at $a+bi \\in \\Z[i]$ and satisfying $f(z) = f(z+a+bi)$ for all $z \\in \\C$ and $a+bi \\in \\Z[i]$.\n                                                                                                                                        \\end{problem}\n                                                                                                                                        \\begin{solution}\n                                                                                                                                        TODO this is wrong, we are assuming that there are no extra simple poles\n\n                                                                                                                                        False.  Let $\\gamma$ be the square of side length 1 centered at the origin. Then \n                                                                                                                                        \\[\n                                                                                                                                        \\int_\\gamma f(z)dz = \\int_{-\\frac{1}{2}}^{\\frac{1}{2}}f(z-\\frac{i}{2})dz - \\int_{-\\frac{1}{2}}^{\\frac{1}{2}}f(z+\\frac{i}{2})dz + \\int_{-\\frac{1}{2}}^{\\frac{1}{2}}f(iz+\\frac{1}{2})dz - \\int_{-\\frac{1}{2}}^{\\frac{1}{2}}f(iz-\\frac{i}{2})dz\n                                                                                                                                        \\]\n                                                                                                                                        But since $f$ is doubly-periodic, $f(z-\\frac{i}{2}) = f(z+\\frac{i}{2})$ and $f(z-\\frac{1}{2}) = f(z+\\frac{1}{2})$, so this integral is zero. However, there is a simple pole at zero, so \n                                                                                                                                        \\[\n                                                                                                                                        \\int_\\gamma f(z) dz = 2\\pi i\\Res(f, 0)\\neq 0.\n                                                                                                                                        \\]\n                                                                                                                                        This is a contradiction, so no such $f$ can exist.\n                                                                                                                                        \\end{solution}\n\n                                                                                                                                        \\begin{problem}\\label{infinite-product-sine}For all $z \\in \\C$, we have \n                                                                                                                                          \\(\n                                                                                                                                              \\sin \\left( \\pi z \\right) = \\pi \\displaystyle\\prod_{n=1}^\\infty \\left( 1 - \\frac{z^2}{n^2} \\right)\n                                                                                                                                                \\). % missing factor of z\n                                                                                                                                                \\end{problem}\n                                                                                                                                                \\begin{solution}\n                                                                                                                                                False. At $z=0$, the function on the RHS is 1, while $sin(0)=0$. We prove the following statement:\n\n                                                                                                                                                \\begin{lemma}\n\n                                                                                                                                                Define\n                                                                                                                                                \\[\n                                                                                                                                                S(z) = \\pi z \\displaystyle\\prod_{n=1}^\\infty \\left( 1 - \\frac{z^2}{n^2} \\right)\n                                                                                                                                                \\]\n                                                                                                                                                Then\n                                                                                                                                                \\[\n                                                                                                                                                S(z) = \\sin \\left( \\pi z \\right)\n                                                                                                                                                \\]\n                                                                                                                                                \\end{lemma}\n                                                                                                                                                This function converges everywhere since $\\sum_{n=1}^\\infty\\abs{\\frac{z^2}{n^2}}\\leq\\infty$, so it is well defined.\n                                                                                                                                                Note that \n                                                                                                                                                \\[\n                                                                                                                                                \\frac{\\pfrac{}{z}\\sin(\\pi z)}{\\sin(\\pi z)} = \\frac{\\pi\\cos(\\pi z)}{\\sin(\\pi z)} = \\pi \\cot(\\pi z)\n                                                                                                                                                \\]\n                                                                                                                                                and\n                                                                                                                                                \\[\n                                                                                                                                                \\frac{S'(z)}{S(z)} = \\frac{1}{z}  + \\sum_{n=1}^\\infty \\left(\\frac{\\frac{2z}{n^2}}{1-\\frac{z^2}{n^2}}\\right) = \\frac{1}{z}  + \\sum_{n=1}^\\infty \\left(\\frac{2z}{n^2-z^2}\\right) \n                                                                                                                                                \\]\n                                                                                                                                                By \\ref{p4h10},\n                                                                                                                                                \\[\n                                                                                                                                                \\pi \\cot(\\pi z) -\\frac{1}{z} = \\left( \\sum_{0\\neq n\\in \\Z} \\frac{1}{z+n} - \\frac{1}{n}\\right)\n                                                                                                                                                \\]\n                                                                                                                                                Pairing the terms from $n$ and $-n$,\n                                                                                                                                                \\begin{align*}\n                                                                                                                                                \\frac{S'(z)}{S(z)} = \\frac{1}{z} + \\left( \\sum_{n\\in \\N} \\frac{2z}{z^2-n^2}\\right) = \\pi \\cot(\\pi z) = \\frac{\\pfrac{}{z}\\sin(\\pi z)}{\\sin(\\pi z)}\n                                                                                                                                                \\end{align*}\n                                                                                                                                                Noting that\n                                                                                                                                                \\[\n                                                                                                                                                \\pfrac{}{z}\\frac{S(z)}{\\sin(\\pi z)} = \\frac{\\sin(\\pi z)S'(z) - S(z)\\pi\\cos(\\pi z)}{\\sin^2(\\pi z)} = 0\n                                                                                                                                                \\]\n                                                                                                                                                so the two functions are a constant multiple of each other. Since $\\lim_{z\\to 0 }zS(z) = \\lim_{z\\to 0} z\\sin(\\pi z)= \\pi$, they are the same.\n\n                                                                                                                                                \\end{solution}\n                                                                                                                                                \\begin{problem}\\label{normal-family-example}Define\n                                                                                                                                                  $f_w : B_1(0) \\to \\C$ by $f_w(z) = z/(z-w)$.  The family of\n                                                                                                                                                    functions $\\mathcal{F} := \\{ f_w \\mid w \\in \\C \\}$ is a normal\n                                                                                                                                                      family.\n                                                                                                                                                      \\end{problem}\n                                                                                                                                                      \\begin{solution}\n                                                                                                                                                      No way, not all of these functions are even defined on the ball of radius 1. We will assume additionally that $\\abs{w}\\geq 1$.\n\n                                                                                                                                                      By the Arzel\\`a Ascoli Theorem, this family is normal iff it is both equicontinuous and pointwise bounded on $B_1(0)$. First let's show that this family is equicontinuous: choose a point $z_0\\in B_1(0)$, and consider $z$ very close to $z_0$. We see that\n                                                                                                                                                      \\[\n                                                                                                                                                      f(z)-f(z_0) = \\frac{z}{z-w} - \\frac{z_0}{z_0-w} = \\frac{(z-z_0)w}{(z-w)(z_0-w)}\n                                                                                                                                                      \\]\n                                                                                                                                                      We can choose $\\delta$ small enough so that when $z-z_0<\\delta$, $z < 1$. Then\n                                                                                                                                                      \\[\n                                                                                                                                                      \\abs{\\frac{(z-z_0)w}{(z-w)(z_0-w)}}\\leq \\frac{\\delta \\abs{w}}{\\abs{z-w}\\abs{z_0-w}} \\leq \\frac{\\delta \\abs{w}}{\\abs{w-\\max(z, z_0)}^2}  \\leq \\frac{\\delta \\abs{w}}{\\abs{w-z_0-\\delta}^2}\n                                                                                                                                                      \\]\n                                                                                                                                                      Decreasing $\\delta$ will only make the denominator bigger and hence the value smaller, and since we are also multiplying by $\\delta$, we can make the value arbitrarily small provided that\n                                                                                                                                                      \\[\n                                                                                                                                                      \\frac{\\abs{w}}{\\abs{w-z_0-\\delta}^2}\n                                                                                                                                                      \\]\n                                                                                                                                                      is bounded. Let $x= \\abs{z_0-\\delta} < 1$ and consider this as a real function in $w\\geq 1$.\n                                                                                                                                                      \\[\n                                                                                                                                                      g(w) = \\frac{w}{\\abs{w-x}^2}\n                                                                                                                                                      \\]\n                                                                                                                                                      Since this is a degree $-1$ polynomial, it approaches 0 in the limit, and since it is everywhere continuous with $w\\geq 1$, it must be bounded. Hence by choosing $\\delta$ small enough, we can get the distance of $f(z)-f(z_0)$ arbitrarily small for any function in the family, so the family must be equicontinuous.\n\n                                                                                                                                                      Next we show that $\\mathcal{F}$ is pointwise bounded. For any point $z_0$,\n                                                                                                                                                      \\[\n                                                                                                                                                      \\abs{\\frac{z}{z-w}} \\leq \\frac{\\abs{z}}{\\abs{w}- \\abs{z}} \\leq \\frac{\\abs{z}}{1-\\abs{z}}\n                                                                                                                                                      \\]\n                                                                                                                                                      so it's bounded. Now we can apply Arzela to see that the family is normal.\n                                                                                                                                                      \\end{solution}\n                                                                                                                                                      \\begin{problem}\\label{derivatives-normal-then-not-normal}Suppose $\\mathcal{F}$ is a family of functions defined on the domain $B_1(0)$.  If $\\mathcal{F}' := \\{ f' \\mid f \\in \\mathcal{F} \\}$, the\n                                                                                                                                                        family consisting of derivatives of functions in the family\n                                                                                                                                                          $\\mathcal{F}$, is normal, then the original family $\\mathcal{F}$ is\n                                                                                                                                                            normal. % assume that \\{ f(0) \\mid f \\in \\mathcal{F} \\} is bounded\n                                                                                                                                                            \\end{problem}\n                                                                                                                                                            \\begin{solution}\n                                                                                                                                                            False, define $f_k:\\C\\to\\C, f_k(z)=k$ and let $\\mathcal{F}=\\{f_k: k\\in \\Z\\}$ be a family of all constant functions. The sequence $\\{f_k\\}_{k\\in \\N}$ has no convergence subsequence, so the family is not normal. But the derivative of this family is just the constant function, and being a finite family, it is certainly normal.\n\n                                                                                                                                                            Instead, suppose that $\\mathcal{F}$ is normal, and we will show that $\\mathcal{F'}$ is normal too. We shold also assume that each of the functions have derivatives (and are hence analytic). For $f\\in \\mathcal{F}$, what can we say about $f'$?\n\n                                                                                                                                                            Since $\\mathcal{F}$ is equicontinuous by Arzel\\`a Ascoli, for any point $z_0$, for any function $f\\in\\mathcal{F}$, any $\\epsilon > 0$, $\\exists \\delta$ so that $|z_0 - z|<\\delta\\implies |f(z_0) - f(z)| < \\epsilon$. Thus \n                                                                                                                                                            \\[\n                                                                                                                                                            f'(z) = \\lim_{h\\to 0}\\frac{f(z+h) - f(z)}{h} \\leq \\lim_{\\epsilon\\to 0}\\frac{\\epsilon}{\\delta}\n                                                                                                                                                            \\]\n                                                                                                                                                            And since $f'$ exists, we can find a way of choosing $\\delta$ so that \n                                                                                                                                                            \\[\n                                                                                                                                                            \\lim_{\\epsilon\\to 0}\\frac{\\epsilon}{\\delta}\\leq \\infty\n                                                                                                                                                            \\]\n                                                                                                                                                            this bound holds for all functions $f$ at the point $z$, so the derivatives are locally bounded. Since $f$ is analytic, $f'$ is too, and by Montel's thorem, $\\mathbb{F'}$ is a normal family.\n                                                                                                                                                            \\end{solution}\n                                                                                                                                                            \\end{document}\n", "meta": {"hexsha": "cf78952afc7264f435b1c4dd9acce5757c0c2cb3", "size": 75393, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem-solutions/sol10.tex", "max_stars_repo_name": "Alex7Li/math5522h", "max_stars_repo_head_hexsha": "9f1fa070997f40e11e981c49e7d6fb9556e128d6", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "problem-solutions/sol10.tex", "max_issues_repo_name": "Alex7Li/math5522h", "max_issues_repo_head_hexsha": "9f1fa070997f40e11e981c49e7d6fb9556e128d6", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "problem-solutions/sol10.tex", "max_forks_repo_name": "Alex7Li/math5522h", "max_forks_repo_head_hexsha": "9f1fa070997f40e11e981c49e7d6fb9556e128d6", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 141.1853932584, "max_line_length": 505, "alphanum_fraction": 0.2322629422, "num_tokens": 12111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7281653414814819}}
{"text": "% Estimate: 2 pages\n\\chapter{Tensor Networks}\nIn mathematics, tensors are abstract objects that generalize multilinear relationships between sets of objects in relation to some vector space, i.e., functions of multiple parameters that are linear with respect to each parameter. Tensors can be represented as multidimensional arrays, where the dimensionality is called the order of the tensor. An element (also called component) in the tensor is then denoted by sub- and superscripts, which represent the indices giving their position in the array, where superscripts usually indicate contra-variant components and subscripts indicate co-variant components. \n\nAn order 0 tensor has a single scalar component $a$, which doesn't have any sub- or superscripts, an order 1 tensor is a vector whose components can be described as either $a^i$ or $a_i$, and an order 2 tensor is a matrix whose components can be described as $a^{ij}$, $a_{ij}$, $a^{i\\;}_{\\;j}$, or $a_{i\\;}^{\\;j}$. Notice that while order 2 tensors can be represented by a matrix, they are not the same as the tensor components are not necessarily both co-variant (or contra-variant). To generalize it further to an order $n$ tensor $T$ of type $(p,q)$, where $p + q = n$, an element can be indexed as $T_{j_1,\\dots,j_q}^{i_1,\\dots,i_p}$.\n\nA tensor network is simply a countable collection of tensors that are connected through contractions (\\ccite{biamonte-2017-tensornetworks}). Tensor networks are often used in physics as they can be considered \"stateful\" representations of a full tensor. E.g., Projected Entangled Pair States (PEPS) is a tensor network that has seen use in quantum physics and condensed matter physics as an ansatz for quantum wavefunctions (\\citeauthor*{verstraete_2004-quantum-computation} \\parencite*{verstraete_2004-quantum-computation, verstraete-2004-renormalization-quantum-many-body-systems}), or Matrix Product State (MPS) for pure multipartite quantum states (\\ccite{verstraete-2006-mps}). A more in-depth overview of some tensor networks will be given after a properly introducing the problem.\n\nThe differentiation between contra- and co-variance is mostly important when working with change of basis vectors and is often conveniently (but incorrectly) ignored to only use subscripts for the sake of simplicity. As no transformations or change of basis will be performed in this thesis, the convenient notation with keeping everything in subscript will be utilized from this point on.\n\n\\section*{Tensor Contraction}\nThe most important tensor operator in relation to tensor networks is tensor contraction. Generally, the contraction of a tensor is obtained when setting different indices equal (assuming that they have matching size) and summing over them. This operation lowers the tensor order by 2 as both indices are removed. In the case of an order 2 tensor, we have that\n\n\\begin{equation}\n    \\text{contr}(T_{ij}) \\equiv \\sum_i T_{ii}\n\\end{equation}\n\nIf $T_{ij}$ is interpreted as a matrix, then the contraction is the same as the trace. In the same way we can define the matrix product using tensor contraction. The individual elements from the matrix product $\\bm A \\bm B = \\bm C$, where $A: I\\times K$, $B: K\\times J$ and $C: I\\times J$ can be computed as\n\\begin{align}\n    \\sum_{k} A_{ik} B_{kj} &= C_{ij}\n    \\label{eq:matrixmult}\n\\end{align}\nwhich is equivalent to contracting a higher order tensor. If we let $T = A \\otimes B$, where $\\otimes$ is a tensor product, then $T$ has the size $I\\times K\\times K\\times J$. By contracting over the middle 2 dimensions, we then get $\\bm C$. The form in \\cref{eq:matrixmult} is also considered contraction as the context (shared dummy index $k$) implies that the contraction happens after tensor multiplication.\n\n\\section*{Tensor Notation}\n\\subsection*{Einstein Notation}\nWorking with tensors involves a lot of contracting, which means using a lot of summations. Einstein notation make these summation signs implicit if an index appears more than once (in our case where everything is subscript. Actual Einstein summation convention requires the repeated index to appear in both the upper index of one tensor and the lower index of the other tensor, e.g., $A^i_jB_i^k$).\n\nAssume we have a function $f : \\mathbb{R}^N\\to \\mathbb{R}$ and a function $g: \\mathbb{R}^M\\to\\mathbb{R}^N$ and $\\theta\\in\\mathbb{R}^M$, then calculating the partial derivatives $\\frac{\\partial f(g(\\theta_i))}{\\partial \\theta_i}$ require calculating\n\n\\begin{align*}\n    \\frac{\\partial f}{\\partial \\theta_1} &= \\frac{\\partial f}{\\partial g_1}\\frac{\\partial g_1}{\\partial \\theta_1} + \\frac{\\partial f}{\\partial g_2}\\frac{\\partial g_2}{\\partial \\theta_1} + \\cdots + \\frac{\\partial f}{\\partial g_N}\\frac{\\partial g_N}{\\partial \\theta_1} \\\\\n    \\frac{\\partial f}{\\partial \\theta_2} &= \\frac{\\partial f}{\\partial g_1}\\frac{\\partial g_1}{\\partial \\theta_2} + \\frac{\\partial f}{\\partial g_2}\\frac{\\partial g_2}{\\partial \\theta_2} + \\cdots + \\frac{\\partial f}{\\partial g_N}\\frac{\\partial g_N}{\\partial \\theta_2} \\\\\n    &\\ \\vdots\n    \\\\\n    \\frac{\\partial f}{\\partial \\theta_M} &= \\frac{\\partial f}{\\partial g_1}\\frac{\\partial g_1}{\\partial \\theta_M} + \\frac{\\partial f}{\\partial g_2}\\frac{\\partial g_2}{\\partial \\theta_M} + \\cdots + \\frac{\\partial f}{\\partial g_N}\\frac{\\partial g_N}{\\partial \\theta_M} \\\\\n\\end{align*}\nThis can then be written as \n\\begin{align*}\n    \\frac{\\partial f}{\\partial \\theta_i} = \\sum_j \\frac{\\partial f}{\\partial g_j}\\frac{\\partial g_j}{\\partial \\theta_i} = \\frac{\\partial f}{\\partial g_j}\\frac{\\partial g_j}{\\partial \\theta_i}\n\\end{align*}\nThe multilinearity of the problem is hidden away and all that remains is a single term.\n\n% In this case it is a single summation sign that is saved, however if $\\theta$ was to depend $\\phi$ and $\\phi$ depends on $\\varphi$, then the equation for calculating $\\frac{\\partial f}{\\partial \\varphi}$ would quickly become full of summation signs, when it can be elegantly written as\n\n% \\begin{equation}\n%     \\frac{\\partial f}{\\partial \\varphi_l} = \\frac{\\partial f}{\\partial g_i}\\frac{\\partial g_i}{\\partial \\theta_j}\\frac{\\partial \\theta_j}{\\partial \\phi_k}\\frac{\\partial \\phi_k}{\\partial \\varphi_l}\n% \\end{equation}\n\nOne issue that Einstein notation doesn't solve is when an equation consists of a bunch of contractions with non-trivial indexing, which often is the case with tensor networks, that it quickly becomes unreadable and hard to identify how the different tensors are interacting with each-other and where the contractions are happening, which is why \\ccite{penrose-1971-applications} introduces graphical notation.\n\n\\subsection*{Graphical Notation}\nIn Penrose graphical notation a tensor $\\tau^{a,b,c,\\cdots}_{x,y,z,\\cdots}$ can be represented by a node with \"arms\" for $a,b,c,\\cdots$ and \"legs\" for $x,y,z,\\cdots$ as seen in \\cref{fig:penrosetensor}. In the same way we can represent scalars, vectors, and matrices using graphical notation as seen in \\cref{fig:scalar_vector_matrix}. The strength of Penrose graphical notation comes from how easy it is to represent rather complex tensor operations. \n\nA tensor product is done by \"concatenating\" the tensors involved in the product, and a contraction is done by connecting the indices being contracted, as can be seen in \\cref{fig:tensorprod_contraction}. If we disregard differentiating between contra- and covariance, which is usually the case, then tensor networks can be compactly represented using graphical notation. Using graph notation helps convey the structure of the network, which a formula alone might have trouble with.\n\n\\begin{figure}[!ht]\n    \\centering\n    \\begin{subfigure}[b]{.45\\textwidth}\n      \\centering\n      \\includegraphics[trim=0.5cm 0.1cm 0cm 0.2cm]{reports/figures/penrose_graphical.pdf}\n      \\caption{Generic tensor.}\n      \\label{fig:penrosetensor}\n    \\end{subfigure}%\n    \\hfill\n    \\begin{subfigure}[b]{.45\\textwidth}\n      \\centering\n      {\\includegraphics[trim=1.5cm 0.2cm 0cm 0.2cm, scale=0.5]{reports/figures/graphical_scalar_vector_matrix.pdf}}\n      \\vspace*{5mm}\n      \\caption{Scalar value, vector, and a matrix.}\n      \\label{fig:scalar_vector_matrix}\n    \\end{subfigure}%\n    \\caption{Examples of single tensors in Penrose graphical notation.}\n\\end{figure}\n\n\\begin{figure}[!ht]\n    \\centering\n    \\begin{subfigure}{1\\textwidth}\n      \\centering\n      {\\includegraphics[trim=1cm 0cm 0cm 0cm, scale=0.75]{reports/figures/example_tensor_A_B.pdf}}\n      \\caption{Example tensors of order 4.}\n    \\end{subfigure}\n    \\begin{subfigure}{1\\textwidth}\n      \\centering\n      {\\includegraphics[trim=2cm 0cm 0cm 0cm, scale=0.75]{reports/figures/example_tensor_product.pdf}}\n      \\caption{Tensor product between $A$ and $B$.}\n    \\end{subfigure}\n    \\begin{subfigure}{1\\textwidth}\n      \\centering\n      {\\includegraphics[trim=2cm 0cm 0cm 0cm, scale=0.75]{reports/figures/example_contraction.pdf}}\n      \\caption{Contraction of 2 shared indices.}\n      \\label{fig:tensorcontractionexample}\n    \\end{subfigure}\n    \\caption{Example of key tensor operations using graphical notation. Notice that \\cref{fig:tensorcontractionexample} disregards direction of indices.}\n    \\label{fig:tensorprod_contraction}\n\\end{figure}\n\n\n\\section{Canonical Polyadic Decomposition}\nWhat will be referred to in this thesis as Canonical Polyadic decomposition goes by many different names. The decomposition method was first introduced by \\ccite{hitchcock-1927-expression} as the polyadic form of a tensor, i.e., expressing a tensor as a combination of finite amount of vectors (or order 1 tensors). The concept got popularized way later in 1970 in the psychometrics community in the form of Parallel Factors (PARAFAC) by \\ccite{harshman-1970-foundations} and Canonical Decomposition (CANDECOMP) by \\ccite{carroll-1970-analysis}, which later got renamed to CANDECOMP/PARAFAC (or CP for short) by \\ccite{kiers2000towards}. As the acronym remains the same, the that will be used from this point on will be Canonical Polyadic, as that best describes the use of the decomposition method for density estimation.\n\nAn order $M$ tensor $\\mathcal{T}$ with elements $\\mathcal{T}_{i_1,i_2,\\cdots,i_M}$ can be decomposed as a sum of tensor products between order 1 tensors (vectors),\n\\begin{equation}\n    \\mathcal{T} = \\sum_{r=1}^R \\bm u_{r,1} \\otimes \\bm u_{r,2} \\otimes \\cdots \\otimes \\bm u_{r,M}\n\\end{equation}\nwhere $\\otimes$ is tensor product, $R$ is the rank of $\\mathcal{T}$, and $\\bm u_{i,j}$ are vectors. If the number of terms summed together is the minimal amount the decomposition is considered minimal or canonical and $R$ is the canonical rank.\n\nUtilizing Einstein notation and considering order 2 tensors $U^{(m)}$ for $m\\in[1\\cdots M]$ as canonical factors, the decomposition can be written as\n\\begin{align}\n    \\mathcal{T}_{i_1,i_2,\\cdots,i_M} &= \\sum_{r=1}^R U^{(1)}_{r,i_1}\\ U^{(2)}_{r,i_2}\\ \\cdots\\ U^{(M)}_{r,i_M} \\\\\n    &= \\delta_{j_1,j_2,\\cdots,j_M}\\ U^{(1)}_{j_1,i_1}\\ U^{(2)}_{j_2,i_2}\\ \\cdots\\ U^{(M)}_{j_M,i_M}\n\\end{align}\nwhere $\\delta_{j_1,j_2,\\cdots,j_M}$ is 1 for $j_1 = j_2 = \\cdots = j_M$ and 0 otherwise. Using this result creating a graphical representation is trivial, as it just consists of tensor products and contraction with a core tensor, $\\delta$, which can be seen in \\cref{fig:canonical_polyadic_graph}. $\\delta$ has no body in the graph as it acts like an identity matrix and just connects indices for contraction.\n\\begin{figure}[!ht]\n    \\centering\n    {\\includegraphics[trim=4cm 0cm 0cm 0cm, scale=0.75]{reports/figures/canonical_polyadic_graph.pdf}}\n    \\caption{Graphical notation of Canonical Polyadic Decomposition}\n    \\label{fig:canonical_polyadic_graph}\n\\end{figure}\n\\section{Tucker Decomposition}\nThe Tucker decomposition is a generalization of the Canonical Polyadic decomposition. Instead of limiting the core tensor to being $\\delta$, \\ccite{tucker-1966-some} proposes instead to use a generic core tensor, $\\mathcal{G}$. If $\\mathcal{T}\\in \\mathbb{R}^{I_1\\times I_2\\times \\cdots\\times I_M}$, then the core tensor has to have the same order, but not necessarily the same size: $\\mathcal{G} \\in \\mathbb{R}^{J_1\\times J_2\\times\\cdots\\times J_M}$, where $J_i\\leq I_i, i\\in[1..M]$. $\\mathcal{G}$ can then be combined with $M$ different components $U^{(i)} \\in \\mathbb{R}^{J_i\\times I_i}, i\\in[1..M]$.\n\\begin{align}\n    \\mathcal{T}_{i_1,i_2,\\cdots,i_M} &= \\mathcal{G}_{j_1,j_2,\\cdots,j_M}\\ U^{(1)}_{j_1,i_1}\\ U^{(2)}_{j_2,i_2}\\ \\cdots\\ U^{(M)}_{j_M,i_M}\n\\end{align}\n\nThe graphical representation of the Tucker decomposition is nearly identical \\cref{fig:canonical_polyadic_graph} except the \"connector\" has a body, as $\\mathcal{G}$ is non-trivial.\n\\begin{figure}[!ht]\n    \\centering\n    {\\includegraphics[trim=4cm 0cm 0cm 0cm, scale=0.75]{reports/figures/tucker_graphical.pdf}}\n    \\caption{Graphical notation of Tucker Decomposition}\n    \\label{fig:tucker_graph}\n\\end{figure}\n\\section{Tensor Train Decomposition}\nAs briefly mentioned before, tensor networks are often used in condensed matter physics and quantum physics. \\ccite{oseledets-2011-tensor-train} popularizes Matrix Product States, which was proposed as early as \\cite*{fannes1992finitely} by \\ccite{fannes1992finitely}, for tensor decomposition under the name Tensor-Train Decomposition. \n\n\\citeauthor{oseledets-2011-tensor-train} points out that Canonical Polyadic decomposition suffers from several drawbacks, such as finding the canonical rank being an NP-hard problem, and that even the best algorithms for finding an approximate representation often get stuck in local minima. Meanwhile, the downside to the Tucker decomposition is that it relies on a core tensor, which has same order as the tensor getting approximated. As such it still suffers from the curse of dimensionality as the core tensor scales exponentially in size.\n\nThe proposed composition is on the form \n\\begin{equation}\n    \\mathcal{T}_{i_1,i_2,\\cdots,i_M} = G^{(1)}_{:,i_1,:}\\ G^{(2)}_{:,i_2,:}\\ \\cdots\\ G^{(M)}_{:,i_M,:}\n\\end{equation}\nwhere the factor $G^{(k)}$ is an order 3 tensor with elements $G^{(k)}_{\\alpha_{k-1},i_k,\\alpha_{k}}$, which means $G^{(k)}_{:,i_k,:}$ is an $r_{k-1}\\times r_{k}$ matrix. The product of these index-dependent matrices is a matrix with size $r_0\\times r_M$, which gives the requirement $r_0=r_M=0$. The binding indices $\\alpha_k$ are called the bond dimensions. In index form, using Einstein notation, the decomposition is then written as\n\\begin{equation}\n    \\mathcal{T}_{i_1,i_2,\\cdots,i_M} = G^{(1)}_{i_1,\\alpha_1}\\ G^{(2)}_{\\alpha_1,i_2,\\alpha_2}\\ \\cdots\\ G^{(M)}_{\\alpha_{M-1},i_M}\n\\end{equation}\nwhere $\\alpha_0$ and $\\alpha_M$ are left out as those indices have size 1. The name Tensor Train originates from the linear structure, as seen in \\cref{fig:tensor_train_graph}, created by connecting the components with the help of bond dimensions instead of using vectors as factors.\n\\begin{figure}[!ht]\n    \\centering\n    {\\includegraphics[trim=4cm 0cm 0cm 0cm, scale=0.75]{reports/figures/tensor_train_graph.pdf}}\n    \\caption{Graphical notation of Tensor Train Decomposition}\n    \\label{fig:tensor_train_graph}\n\\end{figure}\n\\section{Tensor Ring Decomposition}\n\n\\section{Tensor Grid Decomposition}\n\n", "meta": {"hexsha": "d511abcb6ac2ccfad5613d4fe59a93dcb085d01f", "size": 15164, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/Chapters/03_Tensor_Networks.tex", "max_stars_repo_name": "msboeg/msc-thesis", "max_stars_repo_head_hexsha": "ceb479a79449ba90b9b5d0342481738695701bf3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "reports/Chapters/03_Tensor_Networks.tex", "max_issues_repo_name": "msboeg/msc-thesis", "max_issues_repo_head_hexsha": "ceb479a79449ba90b9b5d0342481738695701bf3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "reports/Chapters/03_Tensor_Networks.tex", "max_forks_repo_name": "msboeg/msc-thesis", "max_forks_repo_head_hexsha": "ceb479a79449ba90b9b5d0342481738695701bf3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 96.5859872611, "max_line_length": 822, "alphanum_fraction": 0.7482194672, "num_tokens": 4268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7281653339604208}}
{"text": "\t\n\\subsection{Chapter 6}\n\n\\begin{p}%80\n{Show that $\\omega = (x dy-ydx)/(x^2+y^2)$ is closed. Show that $\\int_{\\gamma_0}\\omega=-\\pi$ while $\\int_{\\gamma_1}\\omega=\\pi$. }\n\\end{p}\n\n{Let $r=x^2+y^2$. Then $\\partial_i r=2x_i$. Now $d\\omega=\\partial_x(x/r) dy\\wedge dx-\\partial_y(y/r)dx\\wedge dy=(1/r-2x^2/r^2)dy\\wedge dx+(1/r-2y^2/r^2)dy\\wedge dx\n=(y^2-x^2)/r^2dy\\wedge dx+(x^2-y^2)/r^2 dy\\wedge dx=0.$ Turning to the integrals,\n$\\gamma_0$ is the upper half of the unit circle, traversed from (-1,0) to (1,0). We can\nparameterize this path as $\\gamma_0(t)=(\\cos \\pi(1{-}t),\\sin \\pi(1{-}t))$, and thus\n$\\gamma'_0(t)=\\pi(\\sin\\pi(1{-}t),-\\cos\\pi(1{-}t))$. In these coordinates and on this path $\\omega=(-y/r,x/r)=(-\\sin \\pi(1{-}t),\\cos \\pi(1{-}t))$, so $\\int_{\\gamma_0}\\omega=\\int_0^1 \\omega_{\\gamma_0(t)}(\\gamma'_0(t)) {\\rm d}t=-\\pi$.\nThe other curve is $\\gamma_1(t)=(\\cos \\pi(1{-}t),-\\sin \\pi(1{-}t))$, so $\\gamma'_1(t)=\\pi(\\sin\\pi(1{-}t),\\cos\\pi(1{-}t))$ and $\\omega_{\\gamma_1(t)}=(\\sin \\pi(1{-}t),\\cos \\pi(1{-}t))$, leading to $\\int_{\\gamma_1}\\omega=\\pi$.}\n\n\\begin{p}%81\n{Show that $\\R^n$  is simply connected by exhibiting an explicit formula\nfor a homotopy between any two paths between arbitrary points $p,q\\in\\R^n$.}\n\\end{p}\n{Let\n$f(t)$ and $g(t)$ be paths from $p$ to $q$. Then define $h(s,t)=sf(t)+(1{-}s)g(t)$. Clearly $h(0,t)=f(t)$ and $h(1,t)=g(t)$ and since all the intervening points are elements of $\\R^n$ \nfor all $t$, $h$ is a homotopy between $f$ and $g$.}\n\n\n\\begin{p}%82\n{Show that a 1-form $E$ is exact iff $\\int_\\gamma E=0$ for all loops\n$\\gamma$. (Hint: if $E$ is not exact, show that there are two smooth paths $\\gamma,\\gamma'$ from some point $x\\in M$ to some point $y\\in M$ such that $\\int_\\gamma \\om\\neq \\int_{\\gamma'} E$. Use these paths to form a loop, perhaps only piecewise smooth.}\n\\end{p}\n\n{Start with the `if' statement and let $E=d\\phi$ be an exact form and $\\gamma$ a loop starting and ending at $p$. Then \n$\\oint_\\gamma E=\\int_0^1 d\\phi(\\gamma'(t)){\\rm d}t=\\int_0^1\\gamma'(t)[\\phi]{\\rm d}t=\\int_0^1\\frac{\\rm d}{{\\rm d}s}\\phi(\\gamma(s))_{s=t}{\\rm d}t=\\int_0^1[\\phi(\\gamma(t))]'{\\rm d}t=\\phi(\\gamma(1))-\\phi(\\gamma(0))=\\phi(p)-\\phi(p)=0.$\nNow the `only if' part, which we will show by proving the contrapositive.\nIf $E$ is closed but not exact, then the manifold must not be simply connected. Then choose two points $x$ and $y$ such that the paths $\\gamma,\\gamma'$ have no homotopy between them, i.e.~$\\gamma$ and $\\gamma'$ go on either side of the ``hole'' from $x$ to $y$; together they encircle the hole. Additionally, we must be able to\nfind some points $x,y$ and paths $\\gamma,\\gamma'$ such that $\\int_\\gamma E\\neq \\int_{\\gamma'}E$ or else we could use this integral to define $\\phi$ for which $E=d\\phi$. \nThen defining $\\tilde{\\gamma}$ to be the path taken by following $\\gamma$ forwards and then $\\gamma'$ backwards, we have found a path $\\tilde{\\gamma}$ such that  $\\oint_{\\tilde{\\gamma}} E\\neq 0$.}\n\n\\begin{p}%{83}\n{For any manifold $M$, show the manifold $S^1\\times M$ is not simply connected by finding a 1-form on it that is closed by not exact.}{Picking coordinates $(t,x^j)$ consider the 1-form $\\om=$(1,0,\\dots,0). Clearly $d\\om=0$ so the form is\nclosed, but it is not exact. There is no continuous function $\\phi$ defined on the whole manifold such that $\\om=d\\phi$, since if we try to define it using $\\int_\\gamma \\om$ where\n$\\gamma$ is a path around $S^1$ and fixed on $M$, we obtain $\\phi(t,x^j)=t$, which is multiple-valued.}\n\\end{p}\n\n\\begin{p}%{84}\n{Let the $n$-disk $D^n$ be defined as $D^n=\\{(x_1,\\dots,x_n):x_1^2+\\dots+x_n^2\\leq 1\\}$. Show that $D^n$ is an $n$-manifold with\nboundary in an obvious sort of way.}\n\\end{p}\n{Locally the neighborhood of each point on the unit circle $S^n$ already looks a lot like $H^{n}$ where the half space is defined by the tangent hyperplane. In particular, we can make\nsuitable charts by first using spherical coordinates to describe the points in the disk and then for each point,\nassuming that it lies at the north pole and expanding the coordinates in a Taylor series in $\\theta$ to first order. In two dimensions we then obtain $r(\\cos \\theta,\\sin\\theta)\\rightarrow r(1,\\theta)$ and in three dimensions\n$r(\\cos\\theta,\\sin\\theta\\cos\\varphi,\\sin\\theta\\sin\\varphi)\\rightarrow r(1,\\theta\\cos\\varphi,\\theta\\sin\\varphi)$. We then obtain a cylindrical coordinatization of the neighborhood of the selected point.}\n\n\\begin{p}%{85}\n{Check that the definition of tangent vectors in Chapter 3 really does imply that the tangent space at any point on the boudary of an $n$-dimensional manifold with boundary is an $n$-dimensional vector space.}\n\\end{p}\n{Tangent vectors are simply maps from $C^\\infty$ to $\\R$ obeying linearity and the Leibniz rule. If we first map the point on the boundary to the boundary of $H^n$, where $x^n\\geq 0$ is the special coordinate, \nthen obviously \nwe still have all the derivatives in the directions $x_1,\\dots,x_{n{-}1}$. The derivative in the $x_n$ direction still works as well, since the functions must be smooth to a small region outside the boundary, for which $-\\varepsilon<x_n<0$. }\n\n\\begin{p}%{86}\n{For the mathematically-inclined reader: prove that $\\int_M\\om$ is independent of the \nchoice of charts and partition of unity.}\n\\end{p}\n...\n\n\\begin{p}%{87}\n{Show that $\\partial D^n=S^{n{-}1}$.}\n\\end{p}\n{In exercise 84 we showed a collection of charts in which\nat every point on the surface of the sphere nearby surface points are mapped to points on $\\partial H^n$, thought of as the tangent hyperplane. Thus, surface points are on the boundary. No other points can be on the boundary since they are ``surrounded'' by other points in the manifold. Consider mapping a point in the interior to a point on $\\partial H^n$. Not all open sets containing the point are mapped to open sets of $H^n$, and thus the chart transition function isn't smooth (isn't even continuous).}\n\n\\begin{p}%{88}\n{Let $M=[0,1]$. Show that Stokes' theorem in this case is equivalent to the fundamental theorem\nof calculus $\\int_0^1 {\\rm d}x\\, f'(x)=f(1)-f(0)$.}\n\\end{p}\n{Consider the 1-form $\\om=df$. By Stokes' theorem $\\int_M \\om=\\int_0^1 df=\\int_{\\partial M}f$. The boundary $\\partial M$ is manifestly equal to $\\{0,1\\}$; only the orientation remains to be determined.  $dx$ defines the orientation by defining increasing $x$ to be outward-facing at 1 and inward-facing at 0. Thus $\\int_{\\partial M}f=f(1)-f(0)$.}\n\n\\begin{p}%{89}\n{Let $M=[0,\\infty)$, which is not compact. Show that without the assumption that $f$ vanishes outside a compact set, Stokes' theorem may not apply. (Hint: in this case Stokes' theorem says $\\int_0^\\infty {\\rm d}x\\, f'(x)=-f(0)$.)}\n\\end{p}\n{Choose the function $f'(x)=1$. Then $f(x)=x$. The integral clearly diverges, whereas \nby Stokes' theorem it would be zero. The function $f'(x)=e^{-x}$ works, though.}\n\n\\begin{p}%{90}\n{Show that any submanifold is a manifold in its own right in a natural way.}\n\\end{p}\n{A manifold is defined by having charts $\\varphi_\\alpha$ which smoothly map the open sets $U_\\alpha$ to $\\R^k$, where smooth means that the transition function $\\varphi_\\alpha\\circ\\varphi_\\beta^{-1}$ is smooth \n(infinitely differentiable) where defined. For a submanifold $S\\subset M$ we can define the open sets to \nbe of the form $V_\\alpha=S\\cap U_\\alpha$; this is the induced topology. Charts $\\varphi_\\alpha$ of $M$ are\nguaranteed to satisfy $S\\cap U_\\alpha=\\varphi_\\alpha^{-1}\\R^k$, which means that every open set in $S_\\alpha$ is the preimage of some hyperplane $\\simeq\\R^k$ under the chart $\\varphi_\\alpha$. So we can\njust define $\\vartheta_\\alpha$ to be this map from $S_\\alpha$ to $\\R^k$. The transition functions\n$\\vartheta_\\alpha\\circ\\vartheta_\\beta^{-1}$ are smooth because they are equivalent to the transition\nfunctions $\\varphi_\\alpha\\circ\\varphi_\\beta^{-1}$, restricted to the corresponding input and output \nhyperplanes.}\n\n\\begin{p}%{91}\n{Show that $S^{n{-}1}$ is a compact submanifold of $\\R^n$.}\n\\end{p}\n{Use the maps in exercise 84, fixing $r=1$.}\n\n\n\\begin{p}%{92}\n{Show that any open subset of a manifold is a submanifold.}\n\\end{p}\n{Isn't this just exercise 4?}\n\n\\begin{p}%{93}\n{Show that if $S$ is a $k$-dimensional submanifold \nwith boundary of $M$, then $S$ is a manifold with boundary in a natural way. \nMoreover, show that $\\partial S$ is a $(k{-}1)$-dimensional \nsubmanifold of $M$.}\n\\end{p}\n{Same as exercise 90 except that the hyperplanes have boundaries.\nThat doesn't change the fact that the transition functions will be smooth. $\\partial S$\nis also a manifold using the charts from $S$ with the modification that the image of\nthe chart is now just the boundary of the hyperplane used before. Again, the transition\nfunctions will be smooth, since they are just restrictions of smooth maps. }\n\n\\begin{p}%{94}\n{Show that $D^n$ is a submanifold of $\\R^n$ in this sense.}\n\\end{p}\n{Isn't this just \nexercise 84?}\n\n\\begin{p}%{95}\n{Suppose that $S\\subset \\R^2$ is a 2-dimensional compact orientable submanifold with boundary. Work out what Stokes' theorem says when aplied to a 1-form on $S$. This is sometimes called\nGreen's theorem.}\n\\end{p}\n{Let $\\om=\\alpha dx+\\beta dy$. Then $d\\om=(\\partial_x \\alpha-\\partial_y\\beta)dx\\wedge dy$. Thus $\\int_{\\partial M}\\alpha dx+\\beta dy=\\int_M (\\partial_x \\alpha-\\partial_y\\beta)dx\\wedge dy$. To evaluate the lefthand side one should\nmake a coordinate transformation by regarding $\\partial M$ as a curve $\\gamma(t)$, the\ninverse of which we can regard as a map from $\\partial M$ to $\\R$. This allows us \nto express $dx$ and $dy$ in terms of the coordinate 1-form $dt$: $dx=\\frac{d\\gamma^1}{dt}dt$ and likewise for $dy$.}\n\n\\begin{p}%{96}\n{Suppose that $S\\subset \\R^3$ is a 2-dimensional compact orientable submanifold with boundary. Show that Stokes' theorem aplied to $S$ boils down to the classic Stokes's theorem.}\n\\end{p}\n{Suppose we work in a patch of $S$ with coordinates $x,y,z$ such that $z$ is fixed, so that $z=c$ defines $S$. On this patch let $\\om=v_i dx^i$, where $i=1,2$. Then $d\\om=\\partial_j v_i dx^j\\wedge dx^i$ for $i,j=1,2$. This can \nbe written $d\\om=(\\partial_2 v_1-\\partial_1 v_2)dx^1\\wedge dx^2$; the corresponding integral $\\int_S d\\om=\\int_S (\\nabla\\times \\vec{v})\\cdot \\hat{z}dA$, where $A$ is the area \n(volume) element of $S$. The boundary of $S$ must be specified by a curve $\\gamma(t)=(x^1(t),x^2(t))$. It then follows that $\\om=v_i\\frac{\\partial x^i}{\\partial t}dt$ so that the integral can be written $\\int_{\\partial S}\\om=\\int \\vec{v}\\cdot d\\vec{\\ell}$ with $\\vec{\\ell}=\\frac{\\partial x^i}{\\partial t}\\hat{x}_i$. Thus we have\n $\\int_S (\\nabla\\times \\vec{v})\\cdot d\\vec{A}=\\int \\vec{v}\\cdot d\\vec{\\ell}$, the usual Stokes' theorem.}\n\n\\begin{p}%{97}\n{Suppose that $S\\subset \\R^3$ is a 3-dimensional compact orientable submanifold with boundary. Show that Stokes's theorem aplied to $S$ is equivalent to Gauss's theorem, also known as the divergence theorem.}\n\\end{p}\n{Let $\\om=\\alpha dx\\wedge dy+\\beta dz\\wedge dx+\\gamma dy\\wedge dz$. Then $d\\om=\\partial_z \\alpha dz\\wedge dx\\wedge dy+\\partial_y \\beta dy\\wedge dz\\wedge dx+\\partial_x \\gamma dx\\wedge dy\\wedge dz=(\\partial_z\\alpha+\\partial_y\\beta+\\partial_x \\gamma)dx\\wedge dy\\wedge dz$. Now $\\int_{\\partial M}\\om=\\int_M d\\om$, the righthand side of which is simply $\\int_S(\\partial_z\\alpha+\\partial_y\\beta+\\partial_x \\gamma) dxdydz$. If we define\n$v\\equiv\\star\\om=\\alpha dz+\\beta dy+\\gamma dx$, then this integral is just $\\int \\partial_iv^i dxdydz$, i.e.~the integral of the gradient of the vector $\\vec{v}$. Meanwhile, \nconsider a patch of $\\partial S$ covered by coordinates $(s,t)$; that is, a specification of the points on $\\partial S$: $x(s,t), y(s,t),$ and $z(s,t)$. Letting $dA=ds\\wedge dt$ be the volume element on $\\partial S$, then $dx\\wedge dy=(\\frac{\\partial x}{\\partial s}\\frac{\\partial y}{\\partial t}-\\frac{\\partial x}{\\partial t}\\frac{\\partial y}{\\partial s})dA$, and similarly for the other 2-forms. Then the lefthand integrand can be written as $\\vec{v}\\cdot d\\vec{A}$ where the vector $\\vec{A}=\n\\epsilon_{ijk}\\hat{x}_i(\\frac{\\partial x_j}{\\partial s}\\frac{\\partial x_k}{\\partial t})$.}\n\n\\begin{p}%{98}\n{Show that the pullback of a closed form is closed and the pullback of an exact form is exact.}\n\\end{p}\n{The pullback and exterior derivative commute, so if $\\om$ is closed, $d\\om=0$ and $\\phi^*\\om$ is also closed, since $d\\phi^*\\om=\\phi^* (d\\om)=0$. \nSimilarly, if $\\om$ is exact, then so is $\\phi^*\\om$: $\\phi^*\\om=\\phi^*(d\\alpha)=d(\\phi^*\\alpha)$.}\n\n\\begin{p}%{99}\n{Show that given any map $\\phi:M\\rightarrow M'$ there is a linear map \nfrom $H^p(M')$ to $H^p(M)$ given by $[\\om]\\mapsto[\\phi^*\\om]$, where\n$\\om$ is any closed $p$-form on $M'$. Call this linear map $\\phi^*:H^p(M')\\rightarrow H^p(M)$. Show that if $\\psi:M'\\rightarrow M''$ is another map, then $(\\psi\\phi)^*=\\phi^*\\psi^*$.}\n\\end{p}\n{The linear map is just the pullback:\nsince it preserves closed and exact forms, it preserves equivalence classes of closed forms. If\n$\\om,\\om'$ are closed, so are $\\phi^*\\om$ and $\\phi^*\\om'$ and if $\\om-\\om'=d\\mu$, then $\\phi^*\\om-\\phi^*\\om'=\\phi^*d\\mu=d\\phi^*\\mu$. And the pullback of the composition of maps is the reverse-ordered composition of pullbacks.}\n\n\\begin{p}%{100}\n{Show that $\\star j=f(r)r\\,dr\\wedge d\\theta$ for $j=f(r)dz$ and $d\\theta=\\om$ as in exercise 80.}\n\\end{p}\n{$\\star j=f(r)\\star dz=f(r)dx\\wedge dy$. Now note that $r dr\\wedge d\\theta=(xdx+ydy)(xdy-ydx)/r^2=dx\\wedge dy$ since $r dr=xdx+ydy$.}\n\n\\begin{p}%{101}\n{Show that $\\star d\\theta=\\frac{1}{r}dz\\wedge dr$.}{$\\star d\\theta=(x\\star dy-y\\star dx)/r^2=(xdz\\wedge dx-ydy\\wedge dz)/r^2=(dz\\wedge(xdx+ydy))/r^2=dz\\wedge dr/r$.}\n\\end{p}\n\n\\begin{p}%{102}\n{Check that $d\\star B=\\star j$ holds iff $g'(r)=rf(r)$ for $B=\\frac{g(r)}{r} dz\\wedge dr$.}\n\\end{p}\n{$d\\star B=d(g(r)d\\theta)=g'(r)dr\\wedge d\\theta=\\star j=rf(r)dr\\wedge d\\theta.$ Thus $g'(r)=rf(r)$ is necessary and sufficient.}\n\n\\begin{p}%{103}\nUsing the fact that the $n$-dimensional torus $T^n$ is the product of $n$ copies of $S^1$, construct $n$ closed but not exact $1$-forms $d\\theta_1$, $d\\theta_2$, \\dots, $d\\theta_n$. Hint: define maps $p_i:T^n\\to S^1$ corresponding to projection down to the $i$th coordinate, where $1\\leq i\\leq n$, and let $d\\theta_i=p_i^*d\\theta$.\n\\end{p}\n{Following the hint, what remains to show is that the $d\\theta_1$ (for example) is a closed, non-exact 1-form on $T^n$. Recall from Exercise 80, the 1-form $d\\theta$ on $S^1$ defined in cartesian coordiantes by $d\\theta = \\dfrac{xdy-ydx}{x^2+y^2}$. Integral over this 1-form  was shown to have different values on two different pathes on $S^1$; for a positive half circle $\\gamma_0$, $\\,\\int_{\\gamma_0}d\\theta = \\pi$, and for the negative half-circle, $\\int_{\\gamma_1}d\\theta = -\\pi$.\nNow, consider a path $\\gamma_0^T$ on the $n-$torus $T^n$ given by travelling the path $\\gamma_0$ on the first $S_1$-component and keeping the others at zero:\n$$\n\\gamma_0^T = \\{\\gamma_0, 0, ..., 0\\}.\n$$\nFrom the definition of $d\\theta_i=p_i^*d\\theta$, $d\\theta_1$ is a one-form defined on the projection of the torus on the 1-st $S^1$ component, so \n$$ \n\\int_{\\gamma_i^T}d\\theta_i = \\int_{\\gamma_i}d\\theta, \\qquad i=0,1.\n$$\n}\nThis transfers the fact $d\\theta$ is not exact (different integral values) to the 1-forms on the torus. \n\n\\begin{p}%{104}\n\tIn the space $\\R\\times S^2$ with the metric $g = dr^2+f(r)^2(d\\phi^2+sin^2\\phi d\\theta^2)$ (see page 144 in the book for explanation), let $E$ be the 1-form $E = e(r)dr$. \\\\\nShow that $dE=0$ holds no matter what the function $e(r)$ is, and show that $d\\star E=0$ holds when \n$$\ne(r) = \\dfrac{q}{4\\pi f(r)^2}.\n$$\n\\end{p}\nFirst of all, we establish $dE=0$. This is true as long is $e$ is independent of $\\phi$ or $\\theta$: \n$$ dE =  \\partial_{\\phi}e(r)d\\phi+\\partial_{\\theta}e(r)d\\theta = 0$$\nNow, to compute $\\star E$, notice that the volume form $vol$ in this metric is given by \n$$ vol = \\sqrt{det(g)}dr\\wedge d\\phi \\wedge d\\theta = f^2(r)sin\\phi\\, dr\\wedge d\\phi \\wedge d\\theta $$\n(see p. 85 in the book). Another way to compute it is to find the normalized basis elements. For example, $g^{22} = g_{22}^{-1} = \\dfrac{1}{f(r^2)}$. Then if we write $e_\\phi = h\\,d\\phi$, with $h=h(r,\\phi,\\theta)$, we get \n$$ 1 = <e_\\phi,e_\\phi> = \\dfrac{h^2}{f^2(r)},$$\nwhich implies\n$$e_{\\phi} = f(r)d\\phi$$\nSimilarly, \n$$ e_r = dr,\\quad e_\\theta = f(r)sin\\phi \\,d\\theta,$$\nand the volume element is \n$$ vol = e_r\\wedge e_\\phi \\wedge e_\\theta,$$ \nwhich amounts to the expression above.\\\\\nNow, denote $\\star dr = u\\,d\\phi\\wedge d\\theta$. By definition of the Hodge star,\n\\begin{eqnarray}\n\\begin{aligned}\ndr \\wedge \\star dr & =<dr ,dr >vol\\\\\t\nu\\, dr\\wedge d\\phi\\wedge d\\theta &= 1\\cdot f^2(r)sin\\phi\\, dr\\wedge d\\phi \\wedge d\\theta\\\\\nu &= f^2(r)sin\\phi.\n\\end{aligned}\n\\end{eqnarray}\nThus \n$$\\star E = \\dfrac{q}{4\\pi f^2(r)}\\,f^2(r)sin\\phi\\,d\\phi\\wedge d\\theta = \\dfrac{q\\sin\\phi}{4\\pi}\\,d\\phi\\wedge d\\theta,\n$$ and\n\\begin{eqnarray}\n\\begin{aligned}\nd\\star E &= \\partial_r\\left( \\dfrac{q\\sin\\phi}{2\\pi}\\right) dr \\wedge d\\phi\\wedge d\\theta = 0.\n\\end{aligned}\n\\end{eqnarray}\nQ.E.D.\n\n\n\n\\begin{p}%{105}\n\tFind a function $\\phi$ with $E=-d\\phi$\n\\end{p}\n\\begin{eqnarray}\n\\begin{aligned}\n-d\\phi &= \\partial_r\\phi\\,dr+ \\partial_\\phi\\phi\\,d\\phi+\\partial_\\theta\\phi\\,d\\theta= \\dfrac{q}{4\\pi f^2(r)} dr,\\\\\n\\partial_r\\phi &= -\\dfrac{q}{4\\pi f^2(r)}.\n\\end{aligned}\n\\end{eqnarray}\nSo, set $ \\phi(r) = \\dfrac{q}{4\\pi f(r)}$ to satisfy this expression.\n\n\n\\begin{p}%{106}\n\t\n\tLet $S^2$ denote any of the 2-spheres of the form $\\{r\\}\\times S^2\\subset \\R\\times S^2$, equipped with the volume form $vol = r^2 sin\\phi\\, d\\phi\\wedge d\\theta$ on $S^2$. Show that\n\t$$\n\t\\int_{S^2}\\star E =q\n\t$$\n\\end{p}\nIn exercise (104) we have computed \n$$\\star E = \\dfrac{q\\sin\\phi}{4\\pi}\\,d\\phi\\wedge d\\theta.$$\nTherefore \n\\begin{eqnarray}\n\\begin{aligned}\n\\int_{S^2}\\star E = \\int_{S^2}\\dfrac{q}{4\\pi r^2}\\,r^2 \\sin\\phi\\,d\\phi\\wedge d\\theta =\\\\\n\\dfrac{q}{4\\pi r^2}\\int_{S^2}vol = \\dfrac{q}{4\\pi r^2}4\\pi r^2 = q.\n\\end{aligned}\n\\end{eqnarray}\n\n\\begin{p}\n\\end{p}\n\n\n\\begin{p}\n\\end{p}\n\n\n\\begin{p}\n\\end{p}\n\n\n\\begin{p}\n\\end{p}\n\n\n\\begin{p}%111\n\\end{p}\n\n", "meta": {"hexsha": "d7d3925b3c993bd8732f291ae22ec4cd32987be0", "size": 18031, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/I6.tex", "max_stars_repo_name": "joerenes/Baez-Muniain-solutions", "max_stars_repo_head_hexsha": "e1e38de9acab877bc4200af59c7910d42de748ca", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-04-13T12:10:03.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-19T18:18:34.000Z", "max_issues_repo_path": "src/I6.tex", "max_issues_repo_name": "joerenes/Baez-Muniain-solutions", "max_issues_repo_head_hexsha": "e1e38de9acab877bc4200af59c7910d42de748ca", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-04-13T12:15:30.000Z", "max_issues_repo_issues_event_max_datetime": "2017-04-13T20:19:44.000Z", "max_forks_repo_path": "src/I6.tex", "max_forks_repo_name": "joerenes/Baez-Muniain-solutions", "max_forks_repo_head_hexsha": "e1e38de9acab877bc4200af59c7910d42de748ca", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.3964285714, "max_line_length": 509, "alphanum_fraction": 0.6822139648, "num_tokens": 6312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.880797071719777, "lm_q1q2_score": 0.7281653198525914}}
{"text": "\\subsection{Separation axioms}\\label{subsec:separation_axioms}\n\n\\begin{definition}\\label{def:topological_space_separation}\n  Two subsets \\( A, B \\subseteq X \\) of a topological space \\( (X, \\mscrT) \\) are called \\term{separated} or \\term{separated using neighborhoods} if there exist disjoint open sets \\( U \\supseteq A \\) and \\( V \\supseteq B \\). In particular, two points are separated if their respective singleton sets are separated.\n\n  We say that \\( A \\) and \\( B \\) are \\term{functionally separated} if there exists a continuous function \\( f: X \\to [0, 1] \\) such that \\( f(A) = 0 \\) and \\( f(B) = 1 \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:separation_axioms}\n  We can classify topological spaces using the following separation axioms. Fix a topological space \\( (X, \\mathcal{T}) \\).\n\n  \\begin{thmenum}\n    \\thmitem[def:separation_axioms/T0]{T0} (Kolmogorov) \\( X \\) is \\( T_0 \\) if for every two different points \\( x, y \\in X \\), there exists an open set \\( U \\in \\mathcal{T} \\) such that either \\( x \\in U \\) or \\( y \\in U \\).\n    \\thmitem[def:separation_axioms/T0.5]{T0.5} \\( X \\) is \\( T_{0.5} \\) if every singleton set \\( \\{ x \\} \\) is either open or closed.\n    \\thmitem[def:separation_axioms/T1]{T1} (Frechet) \\( X \\) is \\( T_1 \\) if every singleton set \\( \\{ x \\} \\) is closed.\n    \\thmitem[def:separation_axioms/T2]{T2} (Hausdorff) \\( X \\) is \\( T_2 \\) if every two different points \\( x, y \\in X \\) can be separated using neighborhoods, i.e. there exist disjoint open sets \\( U \\ni x \\) and \\( V \\ni y \\).\n\n    \\thmitem[def:separation_axioms/T3]{T3} \\( X \\) is \\term{regular} if every point and every closed set can be separated using \\hyperref[def:topological_space_separation]{neighborhoods}.\n\n    If in addition to being regular \\( X \\) is \\ref{def:separation_axioms/T0}, we say that \\( X \\) is a \\( T_3 \\) space.\n\n    \\thmitem[def:separation_axioms/T3.5]{T3.5} (Tychonoff) \\( X \\) is \\term{completely regular} if every point and every closed set can be functionally \\hyperref[def:topological_space_separation]{separated}.\n\n    If in addition to being completely regular \\( X \\) is \\ref{def:separation_axioms/T0}, we say that \\( X \\) is a \\( T_{3.5} \\) space.\n\n    \\thmitem[def:separation_axioms/T4]{T4}(Urysohn) \\( X \\) is \\term{normal} every two closed sets \\( F, G \\in \\mathcal{F}_{\\mathcal{T}} \\) can be separated using neighborhoods, i.e. there exist disjoint open sets \\( U \\supseteq F \\) and \\( V \\supseteq G \\).\n\n    If in addition to being normal \\( X \\) is \\ref{def:separation_axioms/T1}, we say that \\( X \\) is a \\( T_4 \\) space.\n\n    \\thmitem[def:separation_axioms/T5]{T5} If every subspace of a \\( T_4 \\) space \\( X \\) is \\ref{def:separation_axioms/T4}, we say that \\( X \\) is a \\( T_5 \\) space or a \\term{completely normal space}.\n\n    \\thmitem[def:separation_axioms/T6]{T6} If every closed set in a \\( T_4 \\) space \\( X \\) is \\( G_\\delta \\) (see \\fullref{def:borel_algebra}), we say that \\( X \\) is a \\( T_6 \\) space or a \\term{perfectly normal space}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:separation_axioms_cascade}\n  Each numbered axiom in \\fullref{def:separation_axioms} implies the previous one.\n\\end{proposition}\n\n\\begin{proposition}\\label{thm:t2_iff_singleton_limits}\n  A topological space is \\hyperref[def:separation_axioms/T2]{Hausdorff} if and only if every \\hyperref[def:topological_net]{net} has at most one \\hyperref[def:net_convergence/limit]{limit}.\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Let \\( X \\) be Hausdorff and assume that there exists a net \\( \\{ x_k \\}_{k \\in \\mscrK} \\) such that \\( y \\) and \\( z \\) are not necessarily distinct limit points.\n\n  Fix neighborhoods \\( U \\) of \\( y \\) and \\( V \\) of \\( z \\). Since both are limit points, there exist indices \\( k_U \\) and \\( k_V \\) such that \\( k \\geq k_U \\) implies \\( x_k \\in U \\) and \\( i \\geq i_k \\) implies \\( x_k \\in V \\).\n\n  Since \\( \\mscrK \\) is a directed set, there exists an upper bound \\( k_0 \\) of \\( k_U \\) and \\( k_V \\). Thus,\n  \\begin{equation*}\n    x_k \\in U \\cap V \\quad\\forall k \\geq k_0.\n  \\end{equation*}\n\n  In particular, the intersection \\( U \\cap V \\) is nonempty and is a neighborhood of both \\( y \\) and \\( z \\).\n\n  If \\( y \\neq z \\), then we have two distinct points such that no two neighborhoods of \\( y \\) and \\( z \\), respectively, are disjoint. This contradicts the assumption that \\( X \\) is Hausdorff. Thus, \\( y = z \\).\n\n  \\NecessitySubProof Conversely, if \\( X \\) is not Hausdorff, then for every two distinct points \\( y \\) and \\( z \\) and every two neighborhoods \\( U \\ni y \\) and \\( V \\ni z \\), their intersection \\( U \\cap V \\) is nonempty.\n\n  Let \\( \\mathcal{U} \\) and \\( \\mathcal{V} \\) be the sets of all neighborhoods of \\( y \\) and \\( z \\), respectively. Since they are both partially ordered by set inclusion \\( \\subseteq \\), define the directed set \\( (\\mathcal{U} \\times \\mathcal{V}, \\leq) \\) with order\n  \\begin{equation*}\n    (U, V) \\leq (U', V') \\iff U \\supset V \\T{and} U' \\supset V'.\n  \\end{equation*}\n\n  For each \\( (U, V) \\in \\mathcal{U} \\times \\mathcal{V} \\), choose a point \\( x_{(U, V)} \\) from \\( U \\cap V \\).\n\n  Thus, the net \\( \\{ x_{(U, V)} \\}_{(U, V) \\in \\mathcal{U} \\cap \\mathcal{V}} \\) has both \\( y \\) and \\( z \\) as its limit points, which contradicts our initial assumption.\n\\end{proof}\n\n\\begin{lemma}[Urysohn's lemma]\\label{thm:urysohns_lemma}\\mcite[1.5.11]{Engelking1989}\n  In a \\hyperref[def:separation_axioms/T4]{normal space}, every pair \\( A, B \\) of disjoint closed sets can be functionally \\hyperref[def:topological_space_separation]{separated}.\n\\end{lemma}\n\n\\begin{theorem}\\label{thm:separation_axioms_of_product}\n  Fix is an indexed family \\( \\{ X_k \\}_{k \\in \\mscrK} \\) of topological spaces. Denote their \\hyperref[def:topological_product]{product} by \\( X \\).\n\n  \\begin{thmenum}\n    \\thmitem{thm:separation_axioms_of_product/direct}\\cite[theorem 2.3.11]{Engelking1989} If each one of \\( X_k \\) is a \\( T_i \\) space for \\ref{def:separation_axioms/T0}-\\ref{def:separation_axioms/T3.5}, then \\( X \\) is also a \\( T_i \\) space.\n\n    \\thmitem{thm:separation_axioms_of_product/inverse}\\cite[theorem 2.3.11]{Engelking1989} If \\( X \\) is a \\( T_i \\) space for \\ref{def:separation_axioms/T0}-\\ref{def:separation_axioms/T6}, then each component \\( X_k \\) is also a \\( T_i \\) space.\n  \\end{thmenum}\n\\end{theorem}\n", "meta": {"hexsha": "ebcd69e1cf9d56728cbbfd479d3bac1c92f06fbe", "size": 6344, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/separation_axioms.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/separation_axioms.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/separation_axioms.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 77.3658536585, "max_line_length": 314, "alphanum_fraction": 0.6691361917, "num_tokens": 2128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8856314783461303, "lm_q1q2_score": 0.7281565751442745}}
{"text": "\\subsection{Linear Approximations with the Gradient}\r\n\\noindent\r\nWe can rewrite our linear approximation of $f$ at $x_0$ using the gradient.\r\n\\begin{equation*}\r\n\tf(x) \\approx f(x_0) + (\\nabla f)(x_0) \\cdot (x - x_0)\r\n\\end{equation*}", "meta": {"hexsha": "c0e9b70f238a430d97f2524ab300674fece2d790", "size": 232, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/linearApproximationsGradient.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/linearApproximationsGradient.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/linearApproximationsGradient.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 38.6666666667, "max_line_length": 76, "alphanum_fraction": 0.7068965517, "num_tokens": 78, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181874, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7281565656335032}}
{"text": "\n\\subsection{Convergence in probability and o-notation}\n\n\\subsubsection{Introduction}\n\nConverges in probability\n\n\\(P(distance(X_n, X)>\\epsilon )\\rightarrow 0\\)\n\nFor all \\(\\epsilon \\).\n\n\\(X_n \\rightarrow^P X\\)\n\n\\subsubsection{Little o notation}\n\nLittle o notation is used to describe convergence in probability.\n\n\\(X_n=o_p(a_n)\\)\n\nmean that\n\n\\(\\dfrac{X_n}{a_n}\\)\n\nConverges to \\(0\\) and \\(n\\) approaches something\n\nCan be wrtiten:\n\n\\(\\dfrac{X_n}{a_n}=o_p(1)\\)\n\n\\subsubsection{Big O notation}\n\nBig O notation is used to describe boundedness.\n\n\\(X_n=O_p(a_n)\\)\n\nmeans that:\n\nIf something is little o, it is big O.\n\n", "meta": {"hexsha": "e9032b1256acce0d32f7fb759cdbef7a0a805cad", "size": 612, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/iidCLT/02-02-convergenceProbability.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/iidCLT/02-02-convergenceProbability.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/iidCLT/02-02-convergenceProbability.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.3, "max_line_length": 65, "alphanum_fraction": 0.7107843137, "num_tokens": 181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475794701961, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.7281167053180957}}
{"text": "\\section{Classes of Distributions}\n\n\\subsection{Stable Distributions}\n\nLet $X_1,X_2,...X_n$ be i.i.d. random variables. Let $S_n = \\sum_i X_i$. $X_s$ has stable distibution if, for sufficiently large $n$, the (properly normalized) sum $S_n$ converges in distribution to the distribution of $X_s$.\n\n\\begin{equation}\n\\frac{S_n-\\alpha_n}{\\beta_n} \\xrightarrow{dist} X_s\n\\end{equation}\n\n\n\\subsection{Sub-exponential}\n\n\\subsection{Exponential}\n\nThe exponential family of distributions includes many of the most commonly encountered (normal, exponential, gamma, chi-squared, beta, Dirichlet, Bernoulli, categorical, Poisson, Wishart, inverse Wishart). They have a number of very useful properties, such as conjugate priors and the \"summarization\" of arbitrary amounts of data in terms of sufficient statistics (for example, to fit a Gaussian, you only need the mean and the variance of an arbitrarily large dataset). \n\n\\begin{equation}\nf_X(x|\\mathbf{\\theta}) = h(x) \\exp{\\mathbf{\\eta(\\theta)} \\cdot \\mathbf{T(x)} - A(\\mathbf{\\theta})}\n\\end{equation} \n\nWhere $\\mathbf{\\theta}$ is a vector of distribution parameters, $\\mathbf{\\eta}$ is the natural parameter (the set of values for which $f(x|\\mathbf{\\theta})$ is finite is the natural parameters space and is always convex), $T(x)$ is the sufficient statistic (it encapsulates all the information that the data $x$ holds with respect to the parameters of the distribution) and $A(\\eta)$ is the log partition function. \n\n\\subsubsection{Example: Normal Distribution}\n\nFor a normal distribution with unknown mean and unknown variance:\n\n\\begin{equation}\nf(x|\\mu,\\sigma) = \\frac{1}{\\sqrt{2\\pi}\\sigma}\\exp{-\\frac{(x-\\mu)^2}{2\\pi \\sigma^2}\t}\n\\end{equation}\n\n\\begin{itemize}\n\\item $\\mathbf{\\theta} = \\left[\\mu, \\theta \\right]$\n\\item $\\mathbf{\\eta(\\theta)} = \\left[ \\frac{\\mu}{\\sigma^2}, -\\frac{1}{2\\sigma^2}\\right]$\n\\item $\\mathbf{T(x)} = \\left[x, x^2 \\right]$\n\\item $A(\\mathbf{\\theta}) = \\frac{\\mu^2}{2\\sigma^2} + \\log|\\sigma|$\n\\item $h(x) = \\frac{1}{\\sqrt{2\\pi} \\sigma} \\exp{-\\frac{x^2}{2\\pi\\sigma^2}}$\n\\end{itemize}\n \n\\subsection{Elliptical}\n\n", "meta": {"hexsha": "98502a95b59a53c8d11b2519a7789d0c50bfe1a4", "size": 2081, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/proba_distributiontypes.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/proba_distributiontypes.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/proba_distributiontypes.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.5476190476, "max_line_length": 471, "alphanum_fraction": 0.7193656896, "num_tokens": 630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.728079382169917}}
{"text": "\\documentclass[10pt]{article}\n\\author{Alex Peyrard}\n\\title{Information and coding theory assignment 2}\n\n\\begin{document}\n\\maketitle\n\n\\section{$H(X,Y|Z)$}\n\n\\[H(X,Y|Z)=-\\sum\\limits_{x,y,z}\\mathcal{P}(x,y,z)\\log(\\mathcal{P}(x,y|z))\\]\n\\[H(X,Y|Z)=-\\sum\\limits_{x,y,z}\\mathcal{P}(x,y,z)\\log(\\frac{\\mathcal{P}(x,y,z)}{\\mathcal{P}(z)})\\]\n\\[H(X,Y|Z)=-(1/4\\log(\\frac{1/4}{1/2})+1/4\\log(\\frac{1/4}{1/2})+1/4\\log(\\frac{1/4}{1/2})+1/4\\log(\\frac{1/4}{1/2})+0+0+0+0)\\]\n\\[H(X,Y|Z)=-\\log(\\frac{1/4}{1/2})\\]\n\\[H(X,Y|Z)=\\log(2)\\]\n\n\\section{$H(X,Y|Z=0)$}\n\n\\[H(X,Y|Z=0)=-\\sum\\limits_{x,y,z=0}\\mathcal{P}(x,y,z=0)\\log(\\mathcal{P}(x,y|z=0))\\]\n\\[H(X,Y|Z=0)=-\\sum\\limits_{x,y,z=0}\\mathcal{P}(x,y,z=0)\\log(\\frac{\\mathcal{P}(x,y,z=0)}{\\mathcal{P}(z=0)})\\]\n\\[H(X,Y|Z=0)=-(1/4\\log(\\frac{1/4}{1/2})+1/4\\log(\\frac{1/4}{1/2})+0+0)\\]\n\\[H(X,Y|Z=0)=-1/2\\log(\\frac{1/4}{1/2})\\]\n\\[H(X,Y|Z=0)=1/2\\log(2)\\]\n\n\\section{$I(X,Y|Z)$}\n\n\\[I(X,Y|Z)=\\sum\\limits_{x,y,z}\\mathcal{P}(x,y,z)\\log(\\frac{\\mathcal{P}(x,y|z)}{\\mathcal{P}(x|z)\\mathcal{P}(y|z)})\\]\n\\[I(X,Y|Z)=4*1/4\\log(\\frac{1/2}{1/4*1/4})\\]\n\\[I(X,Y|Z)=3\\]\n\n\\section{$I(X,Y|Z=0)$}\n\n\\[I(X,Y|Z=0)=\\sum\\limits_{x,y,z=0}\\mathcal{P}(x,y,z=0)\\log(\\frac{\\mathcal{P}(x,y|z=0)}{\\mathcal{P}(x|z=0)\\mathcal{P}(y|z=0)})\\]\n\\[I(X,Y|Z=0)=2*1/4\\log(\\frac{1/2}{1/4*1/4})\\]\n\\[I(X,Y|Z)=3/2\\]\n\n\\section{Proof of $I(X,Y)=0$}\n\n\\[I(X,Y)=\\sum\\limits_{x,y}\\mathcal{P}(x,y)\\log(\\frac{\\mathcal{P}(x,y)}{\\mathcal{P}(x)\\mathcal{P}(y)})\\]\n\\[I(X,Y)=4*1/4\\log(\\frac{1/4}{1/2*1/2})\\]\n\\[I(X,Y)=\\log(1)\\]\n\\[I(X,Y)=0\\]\nQED\n\n\\end{document}", "meta": {"hexsha": "224aa8eb87b0aa08c6d544223d19e107a02f77bc", "size": 1511, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ICT/assignment2.tex", "max_stars_repo_name": "apeyrard/sjtu-work", "max_stars_repo_head_hexsha": "ca98fec3c83b81ed9091bdc968cb5ad8a74d1d6a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-26T10:04:05.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T10:04:05.000Z", "max_issues_repo_path": "ICT/assignment2.tex", "max_issues_repo_name": "apeyrard/sjtu-work", "max_issues_repo_head_hexsha": "ca98fec3c83b81ed9091bdc968cb5ad8a74d1d6a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ICT/assignment2.tex", "max_forks_repo_name": "apeyrard/sjtu-work", "max_forks_repo_head_hexsha": "ca98fec3c83b81ed9091bdc968cb5ad8a74d1d6a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-26T10:04:06.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T10:04:06.000Z", "avg_line_length": 34.3409090909, "max_line_length": 127, "alphanum_fraction": 0.536730642, "num_tokens": 831, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.7279483589176833}}
{"text": "\n\\subsection{Matrix representation}\n\n\\subsubsection{Representing linear maps as matrices}\n\nWe previously discsussed morphisms on vector spaces. We can write these as matrices.\n\nMatrices represents transformations of vector spaces\n\n\\subsubsection{Representing vectors as matrices}\n\nWe can represent vectors as row or column matrices.\n\n\\(v=\\begin{bmatrix}a_{1} & a_{2}&...&a_{n}\\end{bmatrix}\\)\n\n\\(v=\\begin{bmatrix}a_{1}\\\\a_{2}\\\\...\\\\a_{m}\\end{bmatrix}\\)\n\n", "meta": {"hexsha": "2f4c4c01b8d349b78e40b469bd0995d55b578db0", "size": 453, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/endomorphisms/02-01-linearMatrices.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/endomorphisms/02-01-linearMatrices.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/endomorphisms/02-01-linearMatrices.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.1666666667, "max_line_length": 84, "alphanum_fraction": 0.7505518764, "num_tokens": 120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7279483578122325}}
{"text": "\\chapter{Calculations}\\todo{This is not meant to be here, just calculations for the project}\n\n\n\n\\section{12V 5A MOLEX Pin}\n\n\\hspace{3.5mm} $I = \\dfrac{P}{U}$\n\n\\vspace{2mm}\n\n$\\Updownarrow P = U \\cdot I$\n\n\\vspace{4mm}\n\nWe have a 12V MOLEX pin which can deliver 5A\n\n\\vspace{2mm}\n\n$\\mathbf{12V \\cdot 5A = 60W}$\n\n\\vspace{2mm}\n\nThis means that we have 60W in total, on that MOLEX pin\n\n\\vspace{2mm}\n\n\\paragraph{Raspberry PI} - Consumes 5V 3A\n\n\\vspace{2mm}\n\n$\\mathbf{5V \\cdot 3A = 15W}$\n\n\\vspace{2mm}\n\nThis means that the Raspberry PI consumes 15W at peak.\n\n\\vspace{2mm}\n\n$\\mathbf{60W - 15W = 45W}$\n\n\\vspace{4mm}\n\nLeaving 45W left on the MOLEX pin which is equal to\n\n\\vspace{2mm}\n\n$\\mathbf{\\dfrac{45W}{12V} = 3.75A}$\n\n\\section{19V 2A MOLEX Pin}\n\n$I = \\dfrac{P}{U}$, $P = U \\cdot I$\n\n\\vspace{4mm}\n\nWe have a 19V MOLEX pin which can deliver 2A\n\n\\vspace{2mm}\n\n$\\mathbf{19V \\cdot 2A = 38W}$\n ", "meta": {"hexsha": "fc8dd598a72e05ee65e55df29eba8df0f6329ef3", "size": 880, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/02 - Sections/calculations.tex", "max_stars_repo_name": "RiceCurry2/aau", "max_stars_repo_head_hexsha": "777d6c3774e927268d3ba9b9a761d2353a1a782a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/02 - Sections/calculations.tex", "max_issues_repo_name": "RiceCurry2/aau", "max_issues_repo_head_hexsha": "777d6c3774e927268d3ba9b9a761d2353a1a782a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/02 - Sections/calculations.tex", "max_forks_repo_name": "RiceCurry2/aau", "max_forks_repo_head_hexsha": "777d6c3774e927268d3ba9b9a761d2353a1a782a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.6666666667, "max_line_length": 92, "alphanum_fraction": 0.6727272727, "num_tokens": 353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646393, "lm_q2_score": 0.7905303112671295, "lm_q1q2_score": 0.7279121508119992}}
{"text": "\\documentclass[9pt, oneside]{amsart}   \t% use \"amsart\" instead of \"article\" for AMSLaTeX format\n\\usepackage[top=1cm,left=1.2cm, right=1.2cm, bottom=1cm]{geometry}                \t\t% See geometry.pdf to learn the layout options. There are lots.\n\\geometry{letterpaper}                   \t\t% ... or a4paper or a5paper or ... \n%\\geometry{landscape}                \t\t% Activate for rotated page geometry\n%\\usepackage[parfill]{parskip}    \t\t% Activate to begin paragraphs with an empty line rather than an indent\n\\usepackage{graphicx}\t\t\t\t% Use pdf, png, jpg, or eps§ with pdflatex; use eps in DVI mode\n\\usepackage{bm}\t\t\t\t\t\t\t% TeX will automatically convert eps --> pdf in pdflatex\t\t\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage{subcaption}\n\\usepackage{float}\n\\pagenumbering{gobble}\n%SetFonts\n\n%SetFonts\n\n\n\\title{}\n\\author{}\n\\date{}\t\t\t\t\t\t\t% Activate to display a given date or no date\n\n\\begin{document}\n\n\\section{Learning in discrete graphical models}\nLet $(\\mathbf{x}_i ,\\mathbf{z}_i)_{1, ..., n}$ be an i.i.d sample of observations. $p(z)$ can be written as $p(\\mathbf{z}_i|\\bm{\\pi}) = \\prod_{m=1}^{M}\\pi_m^{z_{im}}$ and $p(\\mathbf{x}_i|\\mathbf{z}_i, \\bm{\\Theta}) = \\prod_{m,k}(\\theta_{mk})^{z_{im}x_{ik}}$\nThe log-likelihood of the observations as a function of $\\bm{\\pi}$ and $\\bm{\\Theta} = (\\theta_{mk})$:\n\n\\begin{align*}\n\t\\ell(\\bm{\\pi}, \\bm{\\Theta}) &= \\sum_{i=1}^n \\log p(\\mathbf{x}_i, \\mathbf{z}_i|\\bm{\\pi}, \\bm{\\Theta}) = \\sum_{i=1}^n\\log p(\\mathbf{x}_i|\\mathbf{z}_i, \\bm{\\Theta}) + \\sum_{i=1}^n \\log p(\\mathbf{z}_i|\\bm{\\pi})\n\\end{align*}\nThe maximum likelihood estimator of the right term is given by $\\bm{\\hat{\\pi}} = (\\frac{n_1}{n}, \\frac{n_0}{n}, ..., \\frac{n_M}{n})$ (multinomial distribution and the two terms depend on different parameters). For the left term, with $\\mathcal{A}_m = \\{i | z_{im}=1\\}$ the indexes of the pairs with $z=m$, $n_m = |\\mathcal{A}_m|$ and $n_{mk}$ the number of pairs $(x=k, z=m)$: \n\n\\begin{align*}\n\t\\sum\\log p(\\mathbf{x}_i|\\mathbf{z}_i, \\bm{\\Theta}) = \\sum_i\\sum_{k,m} z_{im}x_{ik}\\log\\theta_{mk} = \\sum_{m=1}^M \\left(\\sum_{i\\in\\mathcal{A}_m}\\sum_{k=1}^K x_{ik}\\log\\theta_{mk}\\right) = \\sum_{m=1}^M  \\sum_{k=1}^Kn_{mk}\\log\\theta_{mk}\n\\end{align*}\nBy analogy with the multinomial distribution maximum likelihood estimator, each term in the sum over $m$ is maximized by $\\bm{\\hat{\\theta}}_m = \\left(\\frac{n_{mk}}{|\\mathcal{A}_m|}\\right)_k$, hence $\\boxed{\\bm{\\hat{\\Theta}}= \\left(\\frac{n_{mk}}{n_m}\\right)_{km}}$ and $\\boxed{\\bm{\\hat{\\pi}} = \\left(\\frac{n_m}{n}\\right)_m}$\n\\newline\n\n\\section{Linear classification - Generative model (LDA) (2.1 (a))}\nLet $(\\mathbf{x}_i , y_i)_{1, ..., n}$ be an i.i.d sample of observations. \n$$p(\\mathbf{x}_i, y_i | \\pi, \\bm{\\bm{\\mu}}, \\bm{\\Sigma}) = p(\\mathbf{x}_i|y_i)\\cdot p(y_i) = \\mathcal{N}(\\mathbf{x}_i | \\bm{\\mu}_1, \\bm{\\Sigma})^{y_i} \\mathcal{N}(\\mathbf{x}_i | \\bm{\\mu}_0, \\bm{\\Sigma})^{1-y_i}\\cdot \\pi^{y_i}(1-\\pi)^{1-y_i}$$\nThe log-likelihood as a function of all parameters is\n\\begin{align*}\n\t\\ell(\\pi, \\bm{\\mu}_1, \\bm{\\mu}_0, \\bm{\\Sigma}) = \\sum_{i}\\left( y_i\\log\\pi+(1-y_i)\\log(1-\\pi) \\right)+ \\sum_i y_i \\log\\mathcal{N}(\\mathbf{x}_i| \\bm{\\mu}_1, \\bm{\\Sigma}) + \\sum_i (1-y_i) \\log\\mathcal{N}(\\mathbf{x}_i| \\bm{\\mu}_0, \\bm{\\Sigma})\n\\end{align*}\nThe first sum depends only on $\\pi$ and is maximized by $\\boxed{\\hat{\\pi} = n_1/n}$. Since we have for the terms depending on $\\bm{\\mu}_1$\n\\begin{align*}\n\t\\sum_i y_i \\log\\mathcal{N}(\\mathbf{x}_i|\\bm{\\mu}_1, \\bm{\\Sigma}) = -1/2 \\sum_i y_i (\\mathbf{x}_i- \\bm{\\mu}_1)^T\\bm{\\Sigma}^{-1}(\\mathbf{x}_i- \\bm{\\mu}_1) + const.\n\\end{align*}\nBy setting the derivatives with respect to $\\bm{\\mu}_1$ to 0 and by symmetry for $\\bm{\\mu}_0$: $\\boxed{\\hat{\\bm{\\mu}}_1= (1/n_1)\\sum y_i\\mathbf{x}_i}$ and $\\boxed{\\hat{\\bm{\\mu}}_0 = (1/n_0)\\sum (1-y_i)\\mathbf{x}_i}$. The terms depending on $\\bm{\\Sigma}$ are \n\n\\begin{align*}\n\t-\\dfrac{1}{2}\\sum_i y_i\\left(\\log|\\bm{\\Sigma}| + (\\mathbf{x}_i - \\bm{\\mu}_1)^T\\bm{\\Sigma}^{-1} (\\mathbf{x}_i - \\bm{\\mu}_1)\\right) - \\dfrac{1}{2}\\sum_i (1-y_i)\\left(\\log|\\bm{\\Sigma}| + (\\mathbf{x}_i - \\bm{\\mu}_0)^T\\bm{\\Sigma}^{-1} (\\mathbf{x}_i - \\bm{\\mu}_0)\\right) =\\\\ -\\dfrac{n}{2}\\log|\\bm{\\Sigma}| -\\dfrac{n}{2}\\text{tr}(\\bm{\\Sigma}^{-1}\\mathbf{S})\n\\end{align*}\nWhere $\\mathbf{S} = \\frac{n_1}{n}\\left(\\frac{1}{n_1}\\sum_{y_i=1} (\\mathbf{x}_i-\\bm{\\mu}_1)(\\mathbf{x}_i - \\bm{\\mu}_1)^T\\right) + \\frac{n_0}{n}\\left(\\frac{1}{n_0}\\sum_{y_i=0} (\\mathbf{x}_i-\\bm{\\mu}_0)(\\mathbf{x}_i - \\bm{\\mu}_0)^T\\right)$ convex sum of the covariances in each class. We can then find that maximum likelihood estimator for $\\bm{\\Sigma}$ is $\\boxed{ \\hat{\\bm{\\Sigma}} = \\mathbf{S}}$ by setting the derivatives to 0 in the above expression.\nWe now study $p(y|\\mathbf{x}) \\propto p(\\mathbf{x}|y)p(y)$\n\\begin{align*}\n\tp(y|\\mathbf{x}) \\propto \\pi^y(1-\\pi)^{1-y}\\mathcal{N}(\\mathbf{x}|\\mu_1, \\bm{\\Sigma})^y \\mathcal{N}(\\mathbf{x}|\\mu_0, \\bm{\\Sigma})^{1-y} \\propto \\exp\\left( y \\left(\\log\\frac{\\pi}{1-\\pi} + \\frac{1}{2}(\\mu_0^T\\bm{\\Sigma}^{-1}\\mu_0 -\\mu_1^T\\bm{\\Sigma}^{-1}\\mu_1 ) \\right) + y(\\mu_1-\\mu_0)^T\\bm{\\Sigma}^{-1}X \\right)\n\\end{align*}\nThus, $p(y=k|\\mathbf{x}) = \\dfrac{\\exp(ya+y\\mathbf{b}^T\\mathbf{x})}{1 + \\exp(a+\\mathbf{b}^T\\mathbf{x} )}$ and $\\boxed{p(y=1|\\mathbf{x}) = \\sigma(a+\\mathbf{b}^T\\mathbf{x})}$ with $a$ and $\\mathbf{b}$ defined in the above formula. It is therefore equivalent to a logistic regression with a closed formula for the coefficients based on the empirical means, covariances and class repartition of the data.\n\\newline\n\n\\section{Linear classification - QDA model (2.5 (a))}\nResults are the same as above for $\\hat{\\pi}$, $\\hat{\\bm{\\mu}}_1$, $\\hat{\\bm{\\mu}}_0$ but $\\hat{\\bm{\\Sigma}}_1$ and $\\hat{\\bm{\\Sigma}}_0$ must be computed separately. The term of the log-likelihood that depends on $\\bm{\\Sigma}_1$ is \n\\begin{align*}\n\t-\\dfrac{1}{2}\\sum_i y_i\\left(\\log|\\bm{\\Sigma}_1| + (\\mathbf{x}_i - \\bm{\\mu}_1)^T\\bm{\\Sigma}_1^{-1} (\\mathbf{x}_i - \\bm{\\mu}_1)\\right) = -\\dfrac{n_1}{2}\\log|\\bm{\\Sigma}_1| -\\dfrac{1}{2}\\text{tr}\\left(\\bm{\\Sigma}_1^{-1}\\sum_{i|y_i=1}(\\mathbf{x}_i - \\bm{\\mu}_1)(\\mathbf{x}_i - \\bm{\\mu}_1)^T\\right)\n\\end{align*}\nHence $\\boxed{\\hat{\\bm{\\Sigma}}_1 = \\frac{1}{n_1}\\sum_{i|y_i=1}(\\mathbf{x}_i - \\bm{\\mu}_1)(\\mathbf{x}_i - \\bm{\\mu}_1)^T}$ and $\\boxed{\\hat{\\bm{\\Sigma}}_0 = \\frac{1}{n_0}\\sum_{i|y_i=0}(\\mathbf{x}_i - \\bm{\\mu}_0)(\\mathbf{x}_i - \\bm{\\mu}_0)^T}$. \n\nWe also have $\\boxed{p(y=1|\\mathbf{x}) = \\sigma\\left(a + \\mathbf{b}^T\\mathbf{x} + \\mathbf{x}^T\\mathbf{C}\\mathbf{x}\\right)}$ with $a= \\log\\frac{\\pi}{1-\\pi} + \\frac{1}{2}(\\mu_0^T\\bm{\\Sigma_0}^{-1}\\mu_0 -\\mu_1^T\\bm{\\Sigma_1}^{-1}\\mu_1)$, $\\mathbf{b}=\\mu_1^T\\bm{\\Sigma_1}^{-1} - \\mu_0^T\\bm{\\Sigma_0}^{-1}$ and $\\mathbf{C} = \\bm{\\Sigma_0}^{-1} - \\bm{\\Sigma_1}^{-1}$. The model can be interpreted as a logistic regression in the space of the features $(\\mathbf{x}_1, \\mathbf{x}_2, \\mathbf{x}_1\\mathbf{x}_2, \\mathbf{x}_1^2, \\mathbf{x}_2^2)$ with closed formula for the coefficients.\n\n\\clearpage\n\\begin{figure}[t!]\n\\centering\n\\begin{subfigure}{.45\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth]{classificationA_lda.pdf}\n % \\caption{Linear Fourier Approximation}\n\\end{subfigure} \\hspace{5pt}\n\\begin{subfigure}{.45\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth]{classificationA_logistic.pdf}\n  %\\caption{Non-linear Fourier Approximation}\n\\end{subfigure}\n\\\\[+5pt]\n\\begin{subfigure}{.45\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth]{classificationA_linear.pdf}\n  %\\caption{Linear Wavelets Approximation}\n\\end{subfigure} \\hspace{5pt}\n\\begin{subfigure}{.45\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth]{classificationA_qda.pdf}\n  %\\caption{Linear Wavelets Approximation}\n\\end{subfigure}\n\\end{figure}\n\n\\hfill\n \\begin{minipage}{.45\\textwidth}\n  \\begin{table}[H]\n   \\centering\n    \\begin{tabular}{c|cccc}\n    Method & LDA & Logistic & Linear & QDA \\\\\n    \\hline\n    Train Error & 0.0134 & 0.0000 & 0.0134 & 0.0067 \\\\\n    \\hline\n    Test Error & 0.0207 & 0.0354 & 0.0207 & 0.0193 \\\\\n    \\end{tabular}\n\\end{table}\n\n \\end{minipage}\\hfill\n \\begin{minipage}{.45\\textwidth}\n\tLinear Regression and LDA give very similar results, with very close decision boundaries.\\\\\n\tThe QDA outperforms the other three methods in terms of classification error on the test set.\\\\\n\tSince the data is linearly separable, the logistic regression is able to find a separating hyperplane, achieving a 100\\% classification score on the train set at the expense of the test error that is higher than for all other methods.\n \\end{minipage}\\hspace{1cm}\n\n\n\\clearpage\n\\begin{figure}[t!]\n\\centering\n\\begin{subfigure}{.45\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth]{classificationB_lda.pdf}\n % \\caption{Linear Fourier Approximation}\n\\end{subfigure} \\hspace{5pt}\n\\begin{subfigure}{.45\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth]{classificationB_logistic.pdf}\n  %\\caption{Non-linear Fourier Approximation}\n\\end{subfigure}\n\\\\[+5pt]\n\\begin{subfigure}{.45\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth]{classificationB_linear.pdf}\n  %\\caption{Linear Wavelets Approximation}\n\\end{subfigure} \\hspace{5pt}\n\\begin{subfigure}{.45\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth]{classificationB_qda.pdf}\n  %\\caption{Linear Wavelets Approximation}\n\\end{subfigure}\n\\end{figure}\n\n\\hfill\n \\begin{minipage}{.45\\textwidth}\n  \\begin{table}[H]\n   \\centering\n    \\begin{tabular}{c|cccc}\n    Method & LDA & Logistic & Linear & QDA \\\\\n    \\hline\n    Train Error & 0.0301 & 0.0201 & 0.0301 & 0.0234 \\\\\n    \\hline\n    Test Error & 0.0415 & 0.0430 & 0.0415 & 0.0235 \\\\\n    \\end{tabular}\n\\end{table}\n\n \\end{minipage}\\hfill\n \\begin{minipage}{.45\\textwidth}\n The results for linear regression and LDA are again very close. Their decision boundaries don't seem very good compared to the others. For the LDA this is in part due to the fact that the two sets have very different covariances, and assuming they are equal harms the performance of the classification. For the linear regression, the points farther to the left of the yellow set have a much higher least square penalty (linear regression penalizes values far from the objective either above or below) than the points of the blue set, leading to a shift of the decision boundary to the left. \n \n Logistic regression performs better than LDA and linear regression but still is limited by the linear nature of the boundary it assumes.\n \n The QDA model performs very well because it can cope with the geometric differences between the two sets by letting the covariances being different in the model. \n \\end{minipage}\\hspace{1cm}\n\n\\clearpage\n\\begin{figure}[t!]\n\\centering\n\\begin{subfigure}{.45\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth]{classificationC_lda.pdf}\n % \\caption{Linear Fourier Approximation}\n\\end{subfigure} \\hspace{5pt}\n\\begin{subfigure}{.45\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth]{classificationC_logistic.pdf}\n  %\\caption{Non-linear Fourier Approximation}\n\\end{subfigure}\n\\\\[+5pt]\n\\begin{subfigure}{.45\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth]{classificationC_linear.pdf}\n  %\\caption{Linear Wavelets Approximation}\n\\end{subfigure} \\hspace{5pt}\n\\begin{subfigure}{.45\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth]{classificationC_qda.pdf}\n  %\\caption{Linear Wavelets Approximation}\n\\end{subfigure}\n\\end{figure}\n\n\\hfill\n\\begin{minipage}{.45\\textwidth}\n  \\begin{table}[H]\n   \\centering\n    \\begin{tabular}{c|cccc}\n    Method & LDA & Logistic & Linear & QDA \\\\\n    \\hline\n    Train Error & 0.0551 & 0.0401 & 0.0551 & 0.0526 \\\\\n    \\hline\n    Test Error & 0.0420 & 0.0227 & 0.0423 & 0.0403 \\\\\n    \\end{tabular}\n\\end{table}\n\n \\end{minipage}\\hfill\n \\begin{minipage}{.45\\textwidth}\n LDA and logistic regression are affected by the variance and mean shift that the blob of data introduces. The least square penalty moves the frontier such that the blob would be classified closer to 1.  The LDA assumes the data is centered in between the two yellow blobs because it cannot deal with separate sets, which affects its performance negatively.\n \n The logistic regression give better results and is able to handle the blob of data because it is robust to a large number of data points localized in a set and tries to optimize an error function which depends on the quality of classification. \n \nThe QDA isn't the most effective model for this data distribution. It is able to handle non linear boundaries that are useful for this kind of complex dataset, but still assumes that data within a class has a Gaussian distribution, which is not the case here.\n \\end{minipage}\\hspace{1cm}\n\n\n\n \\end{document}", "meta": {"hexsha": "49f8cd24f180c3e13486d95d79fc6156dfd1cb13", "size": 12599, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework 1/MVA_DM1_Cisneros.tex", "max_stars_repo_name": "hugcis/Homeworks-PGM", "max_stars_repo_head_hexsha": "fdc392a30809f4ea876261c43587c181ee5d6371", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Homework 1/MVA_DM1_Cisneros.tex", "max_issues_repo_name": "hugcis/Homeworks-PGM", "max_issues_repo_head_hexsha": "fdc392a30809f4ea876261c43587c181ee5d6371", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework 1/MVA_DM1_Cisneros.tex", "max_forks_repo_name": "hugcis/Homeworks-PGM", "max_forks_repo_head_hexsha": "fdc392a30809f4ea876261c43587c181ee5d6371", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.0599078341, "max_line_length": 592, "alphanum_fraction": 0.684974998, "num_tokens": 4441, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8902942246666266, "lm_q1q2_score": 0.7278818343900433}}
{"text": "\\chapter{Adding and Subtracting Polynomials}\n\nWatch Khan Academy's \\textbf{Adding polynomias} video at \\url{https://youtu.be/ahdKdxsTj8E}\n\nWhen adding two monomials of the same degree, you sum their coefficients:\n\\begin{equation*}\n  7x^3 + 4x^3 = 11x^3\n\\end{equation*}\\index{adding!monomials}\n\nUsing this idea, when adding two polynomials, you convert it into one long\npolynomial and then simplify by combining terms with the same degree. For example:\n\\begin{multline*}\n  (10x^3 - 2x + 13) + (-5x^2 + 7x -12) \\\\\n  = 10x^3 + (-2)x + 13 + (-5)x^2 + 7x + (-12) \\\\\n  = 10x^3 + (-5)x^2 + (-2 + 7)x + (13 - 12) \\\\\n  = 10x^3 - 5x^2 + 5x + 1\n\\end{multline*}\\index{adding!polynomials}\n\n\\begin{Exercise}[title=Adding Polynomials Practice, label=addpns]\n  Add the following polynomials:\n  \\Question{$2x^3 - 5x^2 + 3x - 9$ and $x^3 - 2x^2 - 2x - 9$}\n  \\vspace{20mm}\n  \\Question{$3x^5 - 5x^3 + 3x^2 - x - 3$ and $2x^4 - 2x^3 - 2x^2 + x - 9$}\n  \\vspace{20mm}\n\\end{Exercise}\n\\begin{Answer}[ref=addpns]$3x^3 - 7x^2 + x - 18$ and $3x^5 - 7x^3 + x^2 - 12$\\end{Answer}\n\nNotice that in the second question, the degree 1 term disappears completely: $(-x) + x = 0$\n\nOne more tricky thing that can happen: Sometimes the coefficients don't add nicely.  For example:\n\\begin{equation*}\n  \\pi x^2 - 3 x^2 = (\\pi - 3) x^2\n\\end{equation*}\nThat is as far as you can simplify it.\n    \n\\section{Subtraction}\n\nNow watch Khan Academy's \\textbf{Subtracting polynomials} at \\url{https://youtu.be/5ZdxnFspyP8}.\n\nWhen subtracting one polynomial from the other, it is a lot like\nadding two polynomials. The difference: when make the two polynomials\ninto one long polynomial, we multiply each monomial that is being\nsubtracted by -1. For example:\n\\begin{multline*}\n  (2x^2 - 3x + 9) - (5x^2 - 7x + 4) \\\\\n  = 2x^2 + (-3)x + 9 + (-5)x^2 + 7x + (-4) \\\\\n  = (2 - 5)x^2 + (-3 + 7)x + (9-4) \\\\\n  = -3x^2 + 4x + 5\n\\end{multline*}\n\n\\begin{Exercise}[title=Subtracting Polynomials Practice, label=subtractpns]\n  Add the following polynomials:\n  \\Question{$(2x^3 - 5x^2 + 3x - 9) - (x^3 - 2x^2 - 2x - 9)$}\n  \\vspace{20mm}\n  \\Question{$(3x^5 - 5x^3 + 3x^2 - x - 3) - (2x^4 - 2x^3 - 2x^2 + x - 9)$}\n  \\vspace{20mm}\n\\end{Exercise}\n\\begin{Answer}[ref=subtractpns]$x^3 - 3x^2 + 5x$ and $x^5 - 3x^3 + 5x^2 - 2x + 6$\\end{Answer}\n\n\\section{Adding Polynomials in Python}\n\nAs a reminder, in our Python code, we are representing a polynomial\nwith a list of coefficients.  The first coefficient is the constant\nterm. The last coefficient is the leading coefficient. So, we can\nimagine $-5x^3 + 3x^2 - 4x + 9$ and $2x^3 +4x^2 - 9$ would look\nlike this: \\textit{FIXME: Diagram here}\n\nTo add the two polynomials then, we sum the coefficients for each degree.\n\\textit{FIXME: Diagram here}\n\nCreate a file called \\filename{add\\_polynomials.py}, and type in the following: \n\\begin{Verbatim}\ndef add_polynomials(a, b):\n    degree_of_result = len(a)\n    result = []\n    for i in range(degree_of_result):\n        coefficient_a = a[i]\n        coefficient_b = b[i]\n        result.append(coefficient_a + coefficient_b)\n    return result\n\npolynomial1 = [9.0, -4.0, 3.0, -5.0]\npolynomial2 = [-9.0, 0.0, 4.0, 2.0]\npolynomial3 = add_polynomials(polynomial1, polynomial2)\n\nprint('Sum =', polynomial3)\n\\end{Verbatim}\n\nRun the program.\n\nUnfortunately, this code only works if the polynomails are the same length. For\nexample, try making \\pyvar{polynomial1} have a larger degree than\n\\pyvar{polynomial2}:\n\\begin{Verbatim}\n# x**4 - 5x**3 + 3x**2 - 4x + 9\npolynomial1 = [9.0, -4.0, 3.0, -5.0, 1.0]\n  \n# 2x**3 + 4x**2 - 9  \npolynomial2 = [-9.0, 0.0, 4.0, 2.0]\npolynomial3 = add_polynomials(polynomial1, polynomial2)\nprint('Sum =', polynomial3)\n\\end{Verbatim}\n\nSee the problem?\n\n\\begin{Exercise}[title=Dealing with polynomials of different degrees, label=pyaddpolys]\n  \nCan you fix the function \\pyfunction{add\\_polynomials} to handle polynomials of different degrees?\n\nHere is a hint: In Python, there is a \\pyfunction{max} function that returns the largest of the numbers it is passed.\n\\begin{Verbatim}\nbiggest = max(5,7)\n\\end{Verbatim}\nHere \\pyvar{biggest} would be set to 7.\n\nHere is another hint: If you have an array \\pyvar{mylist}, \\pyvar{i},\na non-negative integer, is only a legit index if \\texttt{i <\n  len(mylist)}.\n\\end{Exercise}\n\\begin{Answer}[ref=pyaddpolys]\n\\begin{Verbatim}\ndef add_polynomials(a, b):\n    degree_of_result = max(len(a), len(b))\n    result = []\n    for i in range(degree_of_result):\n        if i < len(a):\n            coefficient_a = a[i]\n        else:\n            coefficient_a = 0.0   \n\n        if i < len(b):\n            coefficient_b = b[i]\n        else:\n            coefficient_b = 0.0\n            \n        result.append(coefficient_a + coefficient_b)\n    return result\n\\end{Verbatim}\n\\end{Answer}\n\n\\section{Scalar multiplication of  polynomials}\n\nIf you multiply a polynomial with a number, the distributive property applies:\n\\begin{equation*}\n  (3.1)(2x^2 + 3x + 1) = (6.2)x^2 + (9.3)x + 3.1\n\\end{equation*}\n(When we are talking about things that are more complicated than a number, we use the word \\emph{scalar} to mean ``Just a number''. So this is the product of a scalar and a polynomial.)\n\nIn \\filename{add\\_polynomials.py}, add a function to that multiplies a scalar and a polynomial:\n\\begin{Verbatim}\ndef scalar_polynomial_multiply(s, pn):\n    result = []\n    for coefficient in pn:\n        result.append(s * coefficient)\n    return result\n\\end{Verbatim}\n\nSomewhere near the end of the program, test this function:\n\\begin{Verbatim}\npolynomial4 = scalar_polynomial_multiply(5.0, polynomial1)\nprint('Scalar product =', polynomial_to_string(polynomial4))\n\\end{Verbatim}\n\n\\begin{Exercise}[title=Subtract polynomials in Python, label=pysubpoly]\nNow implement a function that does subtraction using\n\\pyfunction{scalar\\_polynomial\\_multiply} and\n\\pyfunction{add\\_polynomials}.\n\nIt should look like this:\n\\begin{Verbatim}\ndef subtract_polynomial(a, b):\n    ...Your code here...\n\npolynomial5 = [9.0, -4.0, 3.0, -5.0]\npolynomial6 = [-9.0, 0.0, 4.0, 2.0, 1.0]\npolynomial7 = subtract_polynomial(polynomial5, polynomial6)\nprint('Difference =', polynomial_to_string(polynomial7))\n\\end{Verbatim}\n\\end{Exercise}\n\\begin{Answer}[ref=pysubpoly]\n\\begin{Verbatim}\ndef subtract_polynomial(a, b):\n    neg_b = scalar_polynomial_multiply(-1.0, b)\n    return add_polynomials(a, neg_b)\n\\end{Verbatim}\n\\end{Answer}\n\n\n    \n", "meta": {"hexsha": "ffd45b107351a97d990005b73e896fd9078bf337", "size": 6351, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Polynomials/add_subtract-en_US.tex", "max_stars_repo_name": "rajivjhoomuck/sequence", "max_stars_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/Polynomials/add_subtract-en_US.tex", "max_issues_repo_name": "rajivjhoomuck/sequence", "max_issues_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/Polynomials/add_subtract-en_US.tex", "max_forks_repo_name": "rajivjhoomuck/sequence", "max_forks_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 33.4263157895, "max_line_length": 185, "alphanum_fraction": 0.682254763, "num_tokens": 2172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038221, "lm_q2_score": 0.8902942304882371, "lm_q1q2_score": 0.7278818312350867}}
{"text": "\n\\subsection{The Euler equation}\n\nIf we have exponential discounting we have:\n\n\\(U_T=E[ \\sum_{t=T}^\\infty (1+\\delta )^t U(C_t) ]\\)\n\nThe first-order conditions give us:\n\n\\(u'(x_t)=(1+\\delta)(1+r_t)u'(x_{t+1})\\)\n\n", "meta": {"hexsha": "428b02197980ef1d25bfc9dde63540135ff5b4b7", "size": 211, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/consumerIntertemporal/02-02-Euler.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/consumerIntertemporal/02-02-Euler.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/consumerIntertemporal/02-02-Euler.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.5833333333, "max_line_length": 51, "alphanum_fraction": 0.644549763, "num_tokens": 76, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850110816423, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.7277742091337046}}
{"text": "\\section{Linear transformations}\nIn the previous section we introduced real vectors and their most important properties. In this section we explore a special set of operations that can act on vectors, namely \\emph{linear transformations}.\n\nLinear transformations are a special set of transformations that are relatively easy to analyze. Their use is extremely widespread all throughout different fields of mathematics and its application, e.g. (just to name a few): in computer graphics, machine learning, quantum physics and engineering.\n\n\\subsection{Definition}\nAs mentioned in \\autoref{chapter:intro}, a ``transformation`` is simply another name for a function. Thus in our context, linear transformations are some functions that act on vectors: a linear transformation $T$ takes a vector as an input, and outputs another vector, possibly of a different dimension, i.e.\n\\begin{equation}\n\tT:\\Rs{n}\\to\\Rs{m}.\n\t\\label{eq:linear transformation signature}\n\\end{equation}\n\nWhat makes linear transformations more ``special'' than other functions is their property of \\emph{linearity}, which entails the following two properties:\n\\begin{listitemize}\n\t\\item[Scalability] for any scalar $\\alpha$ and vector $\\vec{v}$,\n\t\t\\[\n\t\t\tT\\left( \\alpha\\vec{v} \\right) = \\alpha T\\left( \\vec{v} \\right).\n\t\t\\]\n\t\\item[Additivity] for any two vectors $\\vec{u},\\vec{v}$\n\t\t\\[\n\t\t\tT\\left( \\vec{u}+\\vec{v} \\right) = T\\left( \\vec{u} \\right) + T\\left( \\vec{v} \\right).\n\t\t\\]\n\\end{listitemize}\n\n\\begin{example}{A linear transformation}{linear transformation}\n\t\\textbf{Claim}: the following $\\Rs{3}\\to\\mathbb{R}$ transformation is linear:\n\t\\[\n\t\tT\\left(\\colvec{x;y;z}\\right) = 2x+3y-z.\n\t\\]\n\n\t\\textbf{Proof}: We can show this using the properties of linear transformations.\n\t\\begin{listitemize}\n\t\\item[Scalability] given a scalar $\\alpha\\in\\mathbb{R}$,\n\t\t\\[\n\t\t\tT\\left(\\colvec{\\alpha x;\\alpha y; \\alpha z}\\right)\n\t\t\t= 2(\\alpha x)+3(\\alpha y)-(\\alpha z) = \\alpha\\left( 2x+3y-z \\right)\n\t\t\t= \\alpha T\\left(\\colvec{x;y;z}\\right).\n\t\t\\]\n\t\\item[Additivity] given two vectors $\\vec{u}=\\colvec{u_{x};u_{y};u_{z}}$ and $\\vec{v}=\\colvec{v_{x};v_{y};v_{z}}$,\n\t\t\\begin{align*}\n\t\t\tT\\left( \\colvec{u_{x};u_{y};u_{z}} + \\colvec{v_{x};v_{y};v_{z}} \\right) &= T\\left( \\colvec{u_{x}+v_{x};u_{y}+v_{y};u_{z}+v_{z}} \\right)\\\\\n\t\t\t&= 2\\left( u_{x}+v_{x} \\right) +3\\left( u_{y}+v_{y} \\right) - \\left( u_{z}+v_{z} \\right)\\\\\n\t\t\t&= T\\left( \\colvec{u_{x};u_{y};u_{z}} \\right) + T\\left( \\colvec{v_{x};v_{y};v_{z}} \\right).\n\t\t\\end{align*}\n\t\\end{listitemize}\n\\end{example}\n\n\\begin{example}{A non-linear transformation}{non-linear transformation}\n\t\\textbf{Claim}: the following $\\Rs{3}\\to\\mathbb{R}$ transformation is \\textbf{not} a linear transformation:\n\t\\[\n\t\tT\\left(\\colvec{x;y;z}\\right) = 2x^{2}+3y-z.\n\t\\]\n\n\t\\textbf{Proof}: this time we only need to show a single case where linearity breaks - let's choose \\textit{scalability}. Given the vector $\\vec{v}=\\colvec{v_{x};v_{y};v_{z}}$, on one hand\n\t\\[\n\t\tT\\left( \\alpha\\colvec{u_{x};u_{y};u_{z}} \\right) = 2\\left(\\alpha u_{x}\\right)^{2}+3\\alpha u_{y}-\\alpha u_{z} = 2\\alpha^{2}u_{x}^{2}+3\\alpha u_{y}-\\alpha u_{z}.\n\t\\]\n\tOn the other hand\n\t\\[\n\t\t\\alpha T\\left( \\colvec{u_{x};u_{y};u_{z}} \\right) = \\alpha\\left( 2u_{x}^{2}+3u_{y}-u_{z} \\right) = 2\\alpha u_{x}^{2}+3\\alpha u_{y}-\\alpha u_{z}.\n\t\\]\n\tFor any $a\\notin\\left\\{ 0,1 \\right\\}$ we get that $T\\left( \\alpha\\vec{v} \\right)\\neq\\alpha T\\left( \\vec{v} \\right)$. Therefore, $T$ is not linear.\n\\end{example}\n\n\\subsection{Developing intuition}\nBefore moving on to explore the algebraic properties of linear transformations, we first shift our focus to gain some intuition about them. Much like in the last section, we do this using graphical representations of linear transformations in $\\Rs{2}$ and $\\Rs{3}$. We start with a single vector under transformation: let $\\vec{u}=\\colvec{2;4}$ and $T:\\Rs{2}\\to\\Rs{2}$ defined by\n\\begin{equation}\n\tT\\left( \\colvec{x;y} \\right) = \\colvec{2x;-y}.\n\\end{equation}\n(to the reader: verify that this transformation is indeed linear)\n\nApplying $T$ to $\\vec{u}$ yields the vector $\\vec{v}=\\colvec{4;-4}$ (see \\autoref{fig:single vector LT}), i.e. it scales the $x$-component of $\\vec{u}$ by $2$ and flips over its $y$-component.\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n\t\t\\begin{tikzpicture}[]\n\t\t\t\\begin{axis}[\n\t\t\t\tvector plane,\n\t\t\t\twidth=7cm, height=7cm,\n\t\t\t\txmin=-7, xmax=7,\n\t\t\t\tymin=-7, ymax=7,\n\t\t\t\txtick={-6,-4,...,6},\n\t\t\t\tytick={-6,-4,...,6},\n\t\t\t]\n\t\t\t\\tikzstyle{every node}=[font=\\Large]\n\t\t\t\\draw[vector, xred] (0,0) -- (2,4) node[pos=1.15] (u) {$\\vec{u}$};\n\t\t\t\\draw[vector, xblue] (0,0) -- (4,-4) node[pos=1.1] (v) {$\\vec{v}$};\n\t\t\t\\draw[vector, dashed, xpurple] (u) to [out=-20, in=70] node[pos=0.35, xshift=9pt] {$T$} (v);\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t\\caption{The vector $\\vec{u}=\\colvec{2;4}$ is transformed by $T$ yielding the vector $\\vec{v}=\\colvec{4;-4}$.}\n\t\t\\label{fig:single vector LT}\n\t\\end{subfigure}\n\t\\hfill\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n\t\t\\centering\n\t\t\\begin{tikzpicture}[]\n\t\t\t\\begin{axis}[\n\t\t\t\tvector plane,\n\t\t\t\twidth=7cm, height=7cm,\n\t\t\t\txmin=-7, xmax=7,\n\t\t\t\tymin=-7, ymax=7,\n\t\t\t\txtick={-6,-4,...,6},\n\t\t\t\tytick={-6,-4,...,6},\n\t\t\t]\n\t\t\t\\tikzstyle{every node}=[font=\\Large]\n\t\t\t\\draw[vector, xred] (0,0) -- (-2,2) node[pos=1.3] (a) {$\\vec{a}$};\n\t\t\t\\draw[vector, xblue] (0,0) -- (1,-6) node[pos=0.95, right] (b) {$\\vec{b}$};\n\t\t\t\\draw[vector, xred, dashed] (0,0) -- (-4,-4) node[pos=1.3] (Ta) {$T\\left(\\vec{a}\\right)$};\n\t\t\t\\draw[vector, xblue, dashed] (0,0) -- (2,6) node[pos=0.95, right] (Tb) {$T\\left(\\vec{b}\\right)$};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t\\caption{The vectors $\\vec{a}=\\colvec{-2;2}$ and $\\vec{b}$ are transformed by the same $T$.}\n\t\t\\label{fig:two vectors LT}\n\t\\end{subfigure}\n\\end{figure}\n\nIf we take other vectors, e.g. $\\vec{a}=\\colvec{-2;-2}$ and $\\vec{b}=\\colvec{1;-6}$ we see that $T$ transforms them in the exact same manner: it scales their $x$-components by $2$ and flipps over their $y$-components (\\autoref{fig:two vectors LT}). This is a fundamental aspect of linear transformations: they always transform all vectors in the exact same manner. We can use this fact to help visualize transformations, by looking at how they transform the entire space. For example, we can draw all grid lines and observe how they are transformed.\n\nIn \\autoref{fig:linear transformation grid} a schematic of $\\Rs{2}$ is shown before and after the application of a linear transformation $T$, by placing a transformed grid (blue) ontop of an untouched grid (gray). In this view, one can see how each point in space is transformed: assuming for example that each two adjacent grid points are 1 unit apart, the gray point at $(-2,2)$ is transformed to where the blue point is, i.e. $(-1,1)$ when measured using the original axes. \n\n\\colorlet{xbefore}{black!40}\n\\colorlet{xafter}{xblue}\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=8cm, height=8cm,\n\t\t\tanchor=center,\n\t\t\tat={(current page.center)},\n\t\t\txtick={-4,-2,...,4},\n\t\t\tytick={-4,-2,...,4},\n\t\t\txticklabels={,,},\n\t\t\tyticklabels={,,},\n\t\t\tgrid style={line width=.1pt, draw=xbefore!35},\n\t\t\tmajor grid style={line width=.2pt, draw=xbefore!50},\n\t\t\tevery tick/.style={xbefore},\n\t\t\taxis line style={xbefore, very thick},\n\t\t]\n\t\t\\addplot[mark=*, mark size=2.5pt] coordinates {(-4,4)};\n\t\t% \\fill[gray!50] (2,-2) rectangle (4,-4);\n\t\t\\coordinate (p) at (-2,2);\n\t\t\\coordinate (xlbl) at (5.5,2.05);\n\t\t\\coordinate (ylbl) at (2.6,4.95);\n\t\t% \\addplot[mark=*, xblue] coordinates {(-2,2)};\n\t\t\\end{axis}\n        \\pgftransformcm{1}{0.4}{0.5}{0.9}{\\pgfpoint{0cm}{0cm}}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=8cm, height=8cm,\n\t\t\tanchor=center,\n\t\t\tat={(current page.center)},\n\t\t\txtick={-4,-2,...,4},\n\t\t\tytick={-4,-2,...,4},\n\t\t\txticklabels={,,},\n\t\t\tyticklabels={,,},\n\t\t\txlabel={},\n\t\t\tylabel={},\n\t\t\tgrid style={line width=.1pt, draw=xafter!35},\n\t\t\tmajor grid style={line width=.2pt, draw=xafter!50},\n\t\t\tevery tick/.style={xafter},\n\t\t\taxis line style={xafter, ultra thick},\n\t\t]\n\t\t% \\fill[xblue!50] (2,-2) rectangle (4,-4);\n\t\t\\end{axis}\n        \\pgftransformreset\n\t\t\\fill[xblue] (p) circle (3pt);\n\t\t\\large\n\t\t\\node[xblue] at (xlbl) {$x$};\n\t\t\\node[xblue] at (ylbl) {$y$};\n\t\\end{tikzpicture}\n\t\\caption{$\\Rs{2}$ after application of a linear transformation (blue), placed ontop of $\\Rs{2}$ before the transformation (gray). Note the black point at the top left at $(-2,2)$ transforming into the blue point at $(-1,1)$.}\n\t\\label{fig:linear transformation grid}\n\\end{figure}\n\nFor comparison, \\autoref{fig:nonlinear transformation grid} shows a non linear transformation applied to $\\Rs{2}$.\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\large\n\t\t\\draw[black!25, step=0.5] (-3,-3) grid (3,3);\n\t\t\\draw[stealth-stealth, very thick] (-3,0) -- (3,0) node[pos=1.1] {$x$};\n\t\t\\draw[stealth-stealth, very thick] (0,-3) -- (0,3) node[pos=1.1] {$y$};\n\t\t\\fill[black!50] (-3,-3) rectangle (-2.5,-2.5);\n\t\t\\fill[black!50] (3,3) rectangle (2.5,2.5);\n\t\t\\begin{scope}\n\t\t\t\\pgftransformnonlinear{\\nltransA}\n\t\t\t\\draw[xblue!25, step=0.5] (-3,-3) grid (3,3);\n\t\t\t\\draw[xblue, stealth-stealth, very thick] (-3,0) -- (3,0) node[pos=1.1] {$x$};\n\t\t\t\\draw[xblue, stealth-stealth, very thick] (0,-3) -- (0,3) node[pos=1.1] {$y$};\n\t\t\t\\fill[xblue!50] (-3,-3) rectangle (-2.5,-2.5);\n\t\t\t\\fill[xblue!50] (3,3) rectangle (2.5,2.5);\n\t\t\\end{scope}\n\t\\end{tikzpicture}\n\t\\caption{A non linear transformation applied to $\\Rs{2}$ for comparison.}\n\t\\label{fig:nonlinear transformation grid}\n\\end{figure}\n\n\\autoref{fig:linear transformation grid} shows some important properties of linear transformation (cf. \\autoref{fig:nonlinear transformation grid}):\n\\begin{enumerate}\n\t\\item The origin stays at the same place after application of the transformation, i.e. $T\\left(\\vec{0}\\right) = \\vec{0}$.\n\t\\item Parallel lines remain parallel after application of the transformation.\n\t\\item All areas are scaled by the same amount.\n\\end{enumerate}\n\nIt is rather easy to prove the first two properties.\n\\begin{proof}{Two properties of linear transformations}{}\n\t\\begin{enumerate}\n\t\t\\item Let $T$ be a transformation that does not perserve the origin, i.e.\n\t\\[\n\t\tT\\left(\\vec{0}\\right) = \\vec{v} \\neq \\vec{0}.\n\t\\]\n\tWe can scale $\\vec{0}$ by a scalar $\\alpha\\neq0$, which would yield\n\t\\[\n\t\tT\\left(\\alpha\\vec{0}\\right) = T\\left(\\vec{0}\\right) = \\vec{v}.\n\t\\]\n\tHowever, for $T$ to be linear we expect (due to scalability)\n\t\\[\n\t\tT\\left(\\alpha\\vec{0}\\right) = \\alpha\\vec{v},\n\t\\]\n\tbut since $\\alpha\\neq0$ and $\\vec{v}\\neq\\vec{0}$ this does not happen. Therefore, $T$ can not be linear - and in turn linear transformations must preserve the origin.\n\n\t\\item A line is defined using a point $\\vec{a}$, and a direction $\\hat{v}$ as the set of all the points $\\left\\{x=\\vec{a}+s\\hat{v}, s\\in\\mathbb{R}\\right\\}$:\n\n\t\\begin{center}\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\tvector plane,\n\t\t\t\twidth=8cm, height=8cm,\n\t\t\t\txticklabels={,,},\n\t\t\t\tyticklabels={,,},\n\t\t\t]\n\t\t\t\\coordinate (a) at (axis cs:2,2);\n\t\t\t\\coordinate (v) at (axis direction cs:1,-0.5);\n\t\t\t\\draw[black!50, dashed] ($(a)-6*(v)$) -- ($(a)+3*(v)$);\n\t\t\t\\draw[vector, xred] (0,0) -- (a) node[midway, above left] {$\\vec{a}$};\n\t\t\t\\draw[vector, xblue] (a) -- ($(a)+(v)$) node[midway, below, xshift=-5pt, yshift=1pt] {$\\hat{v}$};\n\t\t\t\\end{axis}\n\t\t\t\\foreach \\s in {-6,-3.5,-1,0,1,2}{\n\t\t\t\t\\fill ($(a)+\\s*(v)$) circle (0.05) node[above, anchor=west, yshift=2pt] {\\tiny$s=\\s$};\n\t\t\t}\n\t\t\\end{tikzpicture}\n\t\\end{center}\n\tParallel lines have the same direction $\\hat{s}$, i.e. $x_{1}=\\vec{a}_{1}+s_{1}\\hat{v}$ and $x_{2}=\\vec{a}_{2}+s_{2}\\hat{v}$ are parallel lines. Applying a linear transformation $T$ to these lines yields (using the two defining properties of linear transformations)\n\t\\begin{align*}\n\t\tT\\left(x_{1}\\right) &= T\\left(\\vec{a}_{1}\\right) + s_{1}T\\left(\\hat{v}\\right),\\\\\n\t\tT\\left(x_{2}\\right) &= T\\left(\\vec{a}_{2}\\right) + s_{2}T\\left(\\hat{v}\\right).\n\t\\end{align*}\n\tWe can see that the two right-hand side equations represent two new lines with the same direction, i.e. $T\\left(\\hat{v}\\right)$. Therefore parallel lines remain parallel under a linear transformation.\n\t\\end{enumerate}\n\\end{proof}\n\nWe will prove the the third property (all areas are scaled by the same amount) later in the chapter.\n\nAll linear transformations in $\\Rs{2}$ can be created by composing transformations from a set of linear transformation which we will refer to as the \\emph{basic linear transformations}\\footnote{not an official name.}. To visualize these basic transformations we apply them on a figure of a tapir\\footnote{They are here, they are a trans tapir. Get used to it.}:\n\n\\begin{figure}[H]\n\t\\centering\n\t\\tapirTrans{1}{0}{0}{1}{12cm}\n\\end{figure}\n\n\\autoref{fig:basicLinearTrans} shows the basic linear transformations applied to our happy tapir.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[c]{0.29\\textwidth}\n\t\t\\centering\n\t\t\\tapirTrans{1}{0}{0}{1}{5cm}\n\t\t\\caption{Identity - no change.}\n\t\t\\label{fig:}\n\t\\end{subfigure}\n\t\\begin{subfigure}[c]{0.37\\textwidth}\n\t\t\\centering\n\t\t\\tapirTrans{1.4}{0}{0}{1}{5cm}\n\t\t\\caption{Scaling in the $x$-axis.}\n\t\t\\label{fig:}\n\t\\end{subfigure}\n\t\\begin{subfigure}[c]{0.29\\textwidth}\n\t\t\\centering\n\t\t\\tapirTrans{1}{0}{0}{1.3}{5cm}\n\t\t\\caption{Scaling in the $y$-axis.}\n\t\t\\label{fig:}\n\t\\end{subfigure}\n\t\\hfill\n\t\\begin{subfigure}[c]{0.3\\textwidth}\n\t\t\\centering\n\t\t\\tapirTrans{1}{0}{0.25}{1}{5cm}\n\t\t\\caption{Skew in the $x$-axis.}\n\t\t\\label{fig:}\n\t\\end{subfigure}\n\t\\begin{subfigure}[c]{0.3\\textwidth}\n\t\t\\centering\n\t\t\\tapirTrans{1}{0.5}{0}{1}{5cm}\n\t\t\\caption{Skew in the $y$-axis.}\n\t\t\\label{fig:}\n\t\\end{subfigure}\n\t\\begin{subfigure}[c]{0.35\\textwidth}\n\t\t\\centering\n\t\t\\tapirTrans{0.707}{-0.707}{0.707}{0.707}{5cm}\n\t\t\\caption{Rotation around origin.}\n\t\t\\label{fig:}\n\t\\end{subfigure}\n\t\\hfill\n\t\\begin{subfigure}[c]{0.3\\textwidth}\n\t\t\\centering\n\t\t\\tapirTrans{-1}{0}{0}{1}{5cm}\n\t\t\\caption{Reflection about line.}\n\t\t\\label{fig:}\n\t\\end{subfigure}\n\t\\begin{subfigure}[c]{0.3\\textwidth}\n\t\t\\centering\n\t\t\\tapirTrans{-1}{0}{0}{-1}{5cm}\n\t\t\\caption{Reflection through origin.}\n\t\t\\label{fig:}\n\t\\end{subfigure}\n\t\\caption{The basic linear transformations, exemplified using a very happy tapir.}\n\t\\label{fig:basicLinearTrans}\n\\end{figure}\n\n\\begin{example}{Composing basic linear transformations}{ltcomposing}\n\tGiven the following two linear transformations:\n\t\\begin{enumerate}\n\t\t\\item Scale by $1.5$ in the $x$-direction,\n\t\t\\item Rotate by $\\frac{\\pi}{4}$ anti-clockwise around the origin,\n\t\\end{enumerate}\n\ttwo composite linear transformations can be created: first scale then rotate, and first rotate then scale. As can be seen in the figure bellow, changing the order of composition results in a different linear transformations all together:\n\n\t\\begin{center}\n\t\t\\begin{tikzpicture}\n\t\t\t\\tapirTransComp{1}{0}{0}{1}{0}{0}{I}\n\t\t\t\n\t\t\t\\tapirTransComp{0.707}{0.707}{-0.707}{0.707}{1cm}{5cm}{A}\n\t\t\t\\tapirTransComp{0.707}{0.707}{-1.414}{1.414}{7cm}{5cm}{B}\n\t\t\t\\draw[-stealth, thick] (0,1cm) -- ++(0.5cm,2cm) node[midway, above, rotate=75, text width=1.3cm] {first rotate};\n\t\t\t\\draw[-stealth, thick] (2.2cm,4.5cm) -- ++(2.5cm,0cm) node[midway, above, text width=1.5cm] {then scale in $x$};\n\t\t\t\n\t\t\t\\tapirTransComp{2}{0}{0}{1}{1cm}{-5cm}{C}\n\t\t\t\\tapirTransComp{0.707}{1.414}{-0.707}{1.414}{8cm}{-5cm}{D}\n\t\t\t\\draw[-stealth, thick] (0,-1.5cm) -- ++(0.5cm,-2.5cm) node[midway, above, rotate=-80, text width=1.5cm] {first scale in $x$};\n\t\t\t\\draw[-stealth, thick] (3cm,-5.5cm) -- ++(3cm,0cm) node[midway, above, text width=2cm] {then rotate};\n\t\t\\end{tikzpicture}\n\t\\end{center}\n\n\tThis is not a suprising result: in \\autoref{chapter:intro} we learned that function composition is not a commutative operation.\n\\end{example}\n\nSome of the basic linear transformations can be created as compositions of other basic linear transformations. For example, the composition of reflection across the $y$-axis followed by reflection across the $x$-axis results in a $\\ang{180}$ rotation around the origin (see \\autoref{fig:two_reflections_rotation}).\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=10cm, height=10cm,\n\t\t\txticklabels={,},\n\t\t\tyticklabels={,},\n\t\t]\n\t\t\\node[anchor=east] (A) at (-0.5,2) {\\includesvg[scale=0.75]{figures/linear_algebra/tapir_transform2}};\n\t\t\\node[anchor=east, xscale=-1] (B) at (0.5,2) {\\includesvg[scale=0.75]{figures/linear_algebra/tapir_transform2}};\n\t\t\\node[anchor=east, xscale=-1, yscale=-1] (C) at (0.5,-2) {\\includesvg[scale=0.75]{figures/linear_algebra/tapir_transform2}};\n\n\t\t\\draw[vector, xred] (A) -- (B);\n\t\t\\draw[vector, xred] (B) -- (C);\n\t\t\\draw[decoration={\n            text along path,\n\t\t\ttext color=xblue,\n            text={Rotation},\n            text align={center},\n            raise=2mm}, decorate] (A.south) to [out=-90, in=180, looseness=0.75] (C.east);\n\t\t\\draw[vector, xblue] (A.south) to [out=-90, in=180, looseness=0.75] (C.east);\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\t\\caption{Reflection across the $y$-axis (red arrow) followed by a reflection across the $x$-axis (red arrow) results in a rotation by $\\ang{180}$ around the origin (blue arrow).}\n\t\\label{fig:two_reflections_rotation}\n\\end{figure}\n\n\\subsection{3D Linear transformations}\nThe basic linear transformations in $\\Rs{3}$ are very much similar to those in $\\Rs{2}$ with some small differences worth mentioning. For a start, scaling and skewing can be done in three different directions instead of just two directions (namely, $x,y$ and $z$ instead of just $x$ and $y$). In addition, there are infinetly many axes of rotation: in $\\Rs{2}$ there is just a single axis (actually a point) of rotation - the origin. In $\\Rs{3}$ any line that goes through the origin can be an axis of rotation (see \\autoref{fig:rotation_around_axis}). Lastly, there are three types of reflections: about the origin (a point), across a line going through the origin, and across a plane (see fig?).\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}[c]{0.47\\textwidth}\n\t\t\\begin{center}\n\t\t\t\\def\\angThe{75}\n\t\t\t\\def\\angPhi{65}\n\t\t\t\\tdplotsetmaincoords{\\angThe}{\\angPhi}\n\t\t\t\\begin{tikzpicture}[tdplot_main_coords]\n\t\t\t\t\\draw[stealth-stealth, very thick] (-3,0,0) -- (3,0,0) node[pos=1.05] {$x$};\n\t\t\t\t\\draw[stealth-stealth, very thick] (0,-3,0) -- (0,3,0) node[pos=1.05] {$y$};\n\t\t\t\t\\draw[stealth-stealth, very thick] (0,0,-3) -- (0,0,3) node[pos=1.05] {$z$};\n\t\t\t\t\\draw[ultra thick, xpurple, dotted] (-0.6675,-1.335,-2.005) -- (0,0,0);\n\t\t\t\t\\draw[ultra thick, xpurple] (0,0,0) -- (0.267,0.534,0.802);\n\t\t\t\t\\begin{scope}[canvas is plane={O(0.267,0.535,0.802)x(1.231,0.386,0.549)y(0.267,-0.298,1.356)}]\n\t\t\t\t\t\\fill[xpurple!20, opacity=0.2] (-1,-1) rectangle (1,1);\n\t\t\t\t\t\\draw[step=0.5, xdarkpurple!30] (-1,-1) grid (1,1);\n\t\t\t\t\t\\draw[vector, xpurple!80, dotted] (0.5,0) arc (0:177:0.5);\n\t\t\t\t\t\\draw[vector, xpurple!80, dotted] (-0.5,0) arc (180:362:0.5);\n\t\t\t\t\\end{scope}\n\t\t\t\t\\draw[vector, xpurple] (0.267,0.534,0.802) -- (0.534,1.069,1.604) node[pos=1.2] {$\\hat{r}$};\n\t\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\\end{subfigure}%\n\t\\begin{subfigure}[c]{0.47\\textwidth}\n\t\t\\begin{center}\n\t\t\t\\def\\angThe{75}\n\t\t\t\\def\\angPhi{225}\n\t\t\t\\tdplotsetmaincoords{\\angThe}{\\angPhi}\n\t\t\t\\begin{tikzpicture}[tdplot_main_coords]\n\t\t\t\t\\draw[stealth-stealth, very thick] (-3,0,0) -- (3,0,0) node[pos=1.05] {$x$};\n\t\t\t\t\\draw[stealth-stealth, very thick] (0,-3,0) -- (0,3,0) node[pos=1.05] {$y$};\n\t\t\t\t\\draw[stealth-stealth, very thick] (0,0,-3) -- (0,0,3) node[pos=1.05] {$z$};\n\t\t\t\t\\draw[ultra thick, xpurple, dotted] (-0.6675,-1.335,-2.005) -- (0,0,0);\n\t\t\t\t\\draw[ultra thick, xpurple] (0,0,0) -- (0.267,0.534,0.802);\n\t\t\t\t\\begin{scope}[canvas is plane={O(0.267,0.535,0.802)x(1.231,0.386,0.549)y(0.267,-0.298,1.356)}]\n\t\t\t\t\t\\fill[xpurple!20, opacity=0.2] (-1,-1) rectangle (1,1);\n\t\t\t\t\t\\draw[step=0.5, xdarkpurple!30] (-1,-1) grid (1,1);\n\t\t\t\t\t\\draw[vector, xpurple!80, dotted] (0.5,0) arc (0:177:0.5);\n\t\t\t\t\t\\draw[vector, xpurple!80, dotted] (-0.5,0) arc (180:362:0.5);\n\t\t\t\t\\end{scope}\n\t\t\t\t\\draw[vector, xpurple] (0.267,0.534,0.802) -- (0.534,1.069,1.604) node[pos=1.15] {$\\hat{r}$};\n\t\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\\end{subfigure}\n\t\\caption{Rotation around a direction $\\hat{r}$ from two different viewpoints, showing an example of a plane orthogonal to $\\hat{r}$ on which the rotation happens.}\n\n\t\\label{fig:rotation_around_axis}\n\\end{figure}\n", "meta": {"hexsha": "3bd0005386843989bb54d2ca14d97815f0b2e922", "size": 20174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/linear_algebra_intuitive/linear_trans.tex", "max_stars_repo_name": "JASory/maths_book", "max_stars_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/linear_algebra_intuitive/linear_trans.tex", "max_issues_repo_name": "JASory/maths_book", "max_issues_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/linear_algebra_intuitive/linear_trans.tex", "max_forks_repo_name": "JASory/maths_book", "max_forks_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.6990740741, "max_line_length": 697, "alphanum_fraction": 0.6624367998, "num_tokens": 7437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402813, "lm_q2_score": 0.8688267847293731, "lm_q1q2_score": 0.727746666611569}}
{"text": "\\section{Forces}\r\n\\subsection{Force and Potential Energy in One (Spacial) Dimension}\r\nConsider a point mass $m$ moving on a straight line with position given by $x(t)$.\r\nWe assume that the force $F=F(x)$ depends entirely on position, not velocity and time.\r\n\\begin{definition}\r\n    The potential energy $V(x)$ is any function that satisfies $F(x)=-\\mathrm dV/dx$.\r\n\\end{definition}\r\nEquivalently,\r\n$$V(x)=V(0)+\\int_0^xF(x)\\,\\mathrm dx$$\r\nwhere $V(0)$ can be taken arbitrarily.\r\nThe equation of motion is simply $m\\ddot{x}=-\\mathrm dV/dx$ by Newton's Second Law.\r\n\\begin{definition}\r\n    The KInetic energy $T$ is defined by $T=m|\\dot{x}|^2/2$\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Under the assumptions and definitions above, we have $\\mathrm d(T+V)/\\mathrm dt=0$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    $$\\frac{\\mathrm d(T+V)}{\\mathrm dt}=\\frac{2m\\dot{x}\\ddot{x}}{2}+\\frac{\\mathrm dV}{\\mathrm dx}\\frac{\\mathrm dx}{\\mathrm dt}=\\dot{x}(m\\ddot{x}+\\frac{\\mathrm dV}{\\mathrm dx})=0$$\r\n    By Newton's Second Law.\r\n\\end{proof}\r\nNote that if we lost that restriction on the time and velocity independence of the force, we lose the conservation of energy in general.\r\n\\begin{example}\r\n    Consider a harmonic oscillator, so $F(x)=-kx$ where $k$ is a positive constant.\r\n    So $V(x)=kx^2/2$ by choosing the arbitrary constant as $0$.\r\n    We want to calculate all the stuff to verify the conservation of energy.\r\n    \\footnote{Hey, you literally just proved it.}\r\n    We can solve the motion by solving $m\\ddot{x}=-kx$ which solves to $x=A\\sin(\\sqrt{k/m}t)+B\\cos(\\sqrt{k/m}t)$.\r\n    And plugging in gives $\\mathrm dE/\\mathrm dt=0$.\r\n\\end{example}\r\nAs the first instance of Newton's Second Law, the conservation of energy is a useful rule to determine a one dimensional motion.\r\nUsing conservation of energy, we have\r\n$$\\dot{x}=\\pm\\sqrt{\\frac{2}{m}(E-V(x))}$$\r\nwhich is a first order ODE.\r\nSo\r\n$$\\int_{x_0}^x\\frac{\\mathrm du}{\\sqrt{2(E-V(u))/m}}=t-t_0$$\r\nwhere $x(t_0)=x_0$.\r\nIn principle we can solve it to obtain the motion.\\\\\r\nWe can also have some qualitative insight from conservation of energy.\r\nConsider $V(x)=\\lambda(x^3-3\\beta^2x)$ where $\\lambda,\\beta>0$ are constants.\r\nWe can sketch the potential energy to find that $V$ has a local maximum at $-\\beta$, which value happens again at $x=2\\beta$.\r\nAnd it has a local minimum at $\\beta$, where it again obtain the same value at $-2\\beta$.\r\nSo we can find certain properties of the motion from the graph if the motion start at rest, then we must have $V(x)\\le V(x_0)$\\\\\r\nCase 1: $x_0<-\\beta$, it will moves to left so as to reduce the potential and gain speed.\\\\\r\nCase 2: $-\\beta<x_0<2\\beta$, then the particle will be restricted in the region $-\\beta<x_0<2\\beta$ and will oscillate.\\\\\r\nCase 3: $x_0>2\\beta$, then it will move to the right.\\\\\r\nThe case becomes special if we turn to the stationary (or equilibrium) points.\r\nObviously $x_0=-\\beta$ is an unstable fixed point and $x_0=\\beta$ is a stable fixed points.\r\nSo at $x_0=2\\beta$, it will end its notion at the fixed point $x=-\\beta$.\r\nIn this case, we can analyse the behaviour by writing down the integral.\r\nThis can show that the time to reach $x=-\\beta$ is infinite when we approach to $2\\beta$.\r\n\\subsection{Equilibriums}\r\nThe points $x=\\pm\\beta$ in this case are called equilibrium points, at which the particle can always stay at rest.\r\nThe condition for this to happen is $V^\\prime(x_0)=0$.\r\nWe are going to analyze the motion near the equilibrium at $x_0$ by expanding its Taylor series\r\n$$V(x)\\approx V(x_0)+(x-x_0)V^\\prime(x_0)+\\frac{(x-x_0)^2}{2}V^{\\prime\\prime}(x_0)=V(x_0)+\\frac{(x-x_0)^2}{2}V^{\\prime\\prime}(x_0)$$\r\nWe assume for a moment that $V^{\\prime\\prime}(x_0)$ does not vanish.\r\n\\footnote{If it does vanish, we will have to look at higher order terms.}\r\nSo we have $m\\ddot{x}=-(x-x_0)V^{\\prime\\prime}(x_0)$.\\\\\r\nIf $V^{\\prime\\prime}(x_0)>0$, it's a minimum of $V$ which produces the equation of a harmonic oscillator with period $\\sqrt{V^{\\prime\\prime}(x_0)/m}$.\r\nIn this case, we say it is a stable equilibrium.\\\\\r\nIf $V^{\\prime\\prime}(x_0)<0$, it's a maximum of $V$ which produces the equation of an exponentially growing solution.\r\nHence it is an unstable equilibrium with growth rate $\\sqrt{-V^{\\prime\\prime}(x_0)/m}$.\r\n\\begin{example}\r\n    We look back to a pendulum with mass $m$, length $l$ and angle $\\theta$.\r\n    If we think of Newton's Second Law, one can obtain\r\n    $$F=ml\\ddot{\\theta}=-mg\\sin\\theta=-\\frac{\\mathrm d}{\\mathrm d\\theta}(-mg\\cos\\theta)$$\r\n    So we have $E=T+V=ml^2\\dot{\\theta}^2/2-mgl\\cos\\theta$.\r\n    One can check that $\\dot{E}=0$.\r\n    Also the potential $V(\\theta)=-mg\\cos\\theta$ has stable equilibrium at $\\theta=2\\pi k,k\\in\\mathbb Z$ and unstable at $\\theta=\\pi+2\\pi k,k\\in\\mathbb Z$.\r\n    So if the initial value of $\\theta$ is in $(-\\pi,\\pi)$ (or $|V|<mgl$), the pendulum will oscillate.\r\n    If $|V|>mgl$, then it will go round and round.\\\\\r\n    Now we want to analyze the period of oscillations.\r\n    Suppose the original angle is at $\\theta_0\\in (0,\\pi)$, then the oscillation is going to be $\\theta_0\\to 0\\to-\\theta_0\\to0\\to\\theta_0$, so the period is $4$ times the time taken for $\\theta_0$ to $0$, hence\r\n    $$P=4\\int_0^{\\theta_0}\\frac{\\mathrm d\\theta}{\\sqrt{2gl(\\cos\\theta-\\cos\\theta_0)/l^2}}=4\\sqrt{\\frac{l}{g}}\\int_0^{\\theta_0}\\frac{\\mathrm d\\theta}{\\sqrt{2\\cos\\theta-2\\cos\\theta_0}}=\\sqrt{\\frac{l}{g}}F(\\theta_0)$$\r\n    For small $\\theta_0$ we have\r\n    $$F(\\theta_0)\\approx 4\\int_0^{\\theta_0}\\frac{\\mathrm d\\theta}{\\sqrt{\\theta_0^2-\\theta^2}}=2\\pi$$\r\n    Hence $P\\approx 2\\pi\\sqrt{l/g}$.\r\n\\end{example}\r\n\\subsection{Force and Potential in Three Dimensions}\r\nConsider a particle $\\underline{r}$ in motion in three dimensional space.\r\nThen $m\\underline{\\ddot{r}}$ and $T=m|\\underline{\\dot{r}}|^2/2$.\r\nAnd the rate of change of $T$ is then\r\n$$\\frac{\\mathrm dT}{\\mathrm dt}=m\\underline{\\dot{r}}\\cdot\\underline{\\ddot{r}}=\\underline{\\dot{r}}\\cdot\\underline{F}$$\r\nSuppose the particle tranverse a path $C$ from $t_0$ to $t_1$, then\r\n\\begin{definition}\r\n    The work done is\r\n    $$\\int_{t_0}^{t_1}\\underline{F}\\cdot\\underline{\\dot{r}}\\,\\mathrm dt=\\int_C\\underline{F}\\cdot\\mathrm d\\underline{r}$$\r\n\\end{definition}\r\nWe can also write that the total work equals\r\n$$\\int_C\\underline{F}\\cdot\\mathrm d\\underline{r}=\\int_C F_x\\,\\mathrm dx+F_y\\,\\mathrm dy+F_z\\,\\mathrm dz$$\r\nSuppose that the force is a function of the position $\\underline{F}(\\underline{r})$ (also called a force field).\r\n\\begin{definition}\r\n    A force field $\\underline{F}(\\underline{r})$ is called conservative if $\\underline{F}=\\nabla V$ for some $V:\\mathbb R^3\\to\\mathbb R$.\r\n\\end{definition}\r\nIf a force field $\\underline{F}(\\underline{r})$ is conservative, we say $V$ is the potential function.\r\nAlso in this case $E=T+V(\\underline{r})$ conserved.\r\nIndeed,\r\n$$\\frac{\\mathrm dE}{\\mathrm dt}=\\frac{\\mathrm dT}{\\mathrm dt}+\\frac{\\mathrm dV}{\\mathrm dt}=m\\underline{\\dot{r}}\\cdot\\underline{\\ddot{r}}+\\nabla V\\cdot\\underline{\\dot{r}}=\\underline{\\dot{r}}\\cdot(m\\underline{\\ddot{r}}-\\underline{F})=0$$\r\nThe total work done by a conservative force $\\underline{F}$ is\r\n$$\\int_C\\underline{F}\\cdot\\mathrm d\\underline{r}=\\int_C-\\nabla V\\cdot\\mathrm d\\underline{r}=V(\\underline{r}(t_0))-V(\\underline{r}(t_1))$$\r\nSo the work done is independent of the path taken.\\\\\r\nIn particular, if the curve is closed, no work is done.\\\\\r\n$\\underline{F}$ is conservative if $\\nabla\\times\\underline{F}=\\underline{0}$ (given that the domain is simply connected).\r\n\\subsection{Angular Momentum}\r\n\\begin{definition}\r\n    The angular momentum for a particle with mass $m$ and velocity $\\underline{\\dot{r}}$ is defined as\r\n    $$\\underline{L}=\\underline{r}\\times\\underline{p}=m\\underline{r}\\times\\underline{\\dot{r}}$$\r\n    And\r\n    $$\\underline{G}=\\frac{\\mathrm d\\underline{L}}{\\mathrm dt}=m\\underline{\\dot{r}}\\times\\underline{\\dot{r}}+m\\underline{r}\\times\\underline{\\ddot{r}}=\\underline{r}\\times\\underline{F}$$\r\n    is defined as the torque, or moment of force.\r\n\\end{definition}\r\nNote that $\\underline{L},\\underline{G}$ both depend on the choice of origin, so we must specify them when talking about angular stuff.\r\n\\begin{remark}\r\n    If $\\underline{r}\\times\\underline{F}=\\underline{0}$ then $\\underline{G}=0$, thus $\\underline{L}$ is constant.\r\n    In this case, we say the angular momentum is conserved.\r\n\\end{remark}\r\n\\subsection{Central Forces}\r\nA special type of conservative force occurs when the potential $V$ depends entirely on $|\\underline{r}|$, so $V(\\underline{r})=V(|\\underline{r}|)=V(r)$,\r\n\\footnote{It's just a tiny abuse of notation. vErY tInY.}\r\n$$\\underline{F}(\\underline{r})=-\\nabla V(|\\underline{r}|)=-\\frac{\\mathrm dV}{\\mathrm dr}\\underline{\\hat{r}},\\underline{\\hat{r}}=\\frac{\\underline{r}}{|\\underline{r}|}$$\r\nSo $\\underline{F}$ and $\\underline{r}$ are parallel, therefore $\\mathrm d\\underline{L}/\\mathrm dt=\\underline{G}=\\underline{F}\\times\\underline{r}=0$.\r\n\\subsection{Gravity}\r\nRecall that Newton's Gravitational Law states\r\n$$V=-\\frac{GMm}{|\\underline{r}|},\\underline{F}=-\\nabla V=-\\frac{GMm}{|\\underline{r}|^2}\\underline{\\hat{r}}=-\\frac{GMm}{|\\underline{r}|^3}\\underline{r}$$\r\nNote that the $m$ here can be ignored (in the way shown below) if we are only interested in the motion due to Newton's Second law:\r\n\\begin{definition}\r\n    The gravitational potential is defined by $\\Phi_g(\\underline{r})=V/M=-GM/|\\underline{r}|$, and the gravitational field by $\\underline{g}=-\\nabla\\Phi_g(\\underline{r})=-GM\\underline{\\hat{r}}/r^2$.\r\n\\end{definition}\r\nThe gravitational field and its potential, as functions, are dependent of $M$ alone.\r\nWe also have $m\\Phi_g=V,m\\underline{g}=\\underline{F}$.\r\nFor a set of more than one masses, we can simple generalize by adding the corresponding fields and potential together by the superposition principle.\r\nHence for continuous bodies, we can replace the sum by an integral.\r\nIn particular, if the body is spherical with radius $R$ and we have $|\\underline{r}|>R$, then we do have $\\Phi_g(\\underline{r})=-GM/|\\underline{r}|$, thus spherical bodies do behave like a point when measuring from above its surface.\r\n\\begin{note}\r\n    The mass $m$ in Newton's Second Law $m\\underline{\\ddot{r}}=\\underline{F}$ is called the inertial mass, whilist the mass in Newton's Gravitational Law $\\underline{F}=-GMm\\underline{r}/|\\underline{r}|^2$ is the gravitational mass.\r\n    These two definitions of mass are different in relativity but are very closely related (about a difference of $10^{-12}$).\r\n    The precise difference will be discussed in General Relativity.\r\n\\end{note}\r\nThere are a few results about the effect of gravity.\r\n\\begin{example}[Potential Energy near the Surface]\r\n    For a mass $m$ at height $z$ above a spherical mass $M$ with radius $R$, if $z<<R$, then the potential energy is given by\r\n    \\begin{align*}\r\n        V(R+z)&=-\\frac{GMm}{R+z}\\\\\r\n        &=-\\frac{GMm}{R}+\\frac{GMm}{R^2}z+o(R^{-2})\\\\\r\n        &\\approx -\\frac{GMm}{R}+mgz\\\\\r\n        &=\\text{const}+mgz\r\n    \\end{align*}\r\n    For earth, we have the approximation $g\\approx 9.8{\\rm ms^{-2}}$\r\n\\end{example}\r\n\\begin{example}[Escape Velocity]\r\n    We want to find the critical velocity $\\underline{v}$, perpendicular to $\\underline{r}$, to leave a planet.\r\n    Due to the conservation of energy $E=T+V=m|\\underline{v}|^2/2-GMm/R$, the particle can escape (i.e. $\\underline{v}$ is nonnegative at infinity) iff the initial energy has $E_0\\ge 0$, which happens iff\r\n    $$m|\\underline{v}|^2/2\\ge GMm/R\\implies |\\underline{v}|\\ge \\sqrt{\\frac{2GM}{R}}=v_{\\rm esc}$$\r\n\\end{example}\r\n\\subsection{Electromagnetic Forces}\r\nWe have seen previously that for a point charge $q$, the force has the expression $\\underline{F}=q(\\underline{E}+\\underline{\\dot{r}}\\times\\underline{B})$\r\nIn general $\\underline{E},\\underline{B}$ are functions of $\\underline{r}$ and $\\underline{t}$.\r\nThese are known as the Lorentz Force Law.\r\nFor convenience or something, we are going to restrict ourselves to time-independent fields.\r\nSo we want the electric field to be conservative, i.e. $\\underline{E}=-\\nabla\\Phi_e$ where $\\Phi_e$ is called the electrostatic potential.\r\n\\begin{claim}\r\n    In a time-independent electromagnetic field, the energy\r\n    $$E=T+V=\\frac{m|\\underline{\\dot{r}}|^2}{2}+q\\Phi_e(\\underline{r})$$\r\n    is conserved.\r\n\\end{claim}\r\n\\begin{proof}\r\n    \\begin{align*}\r\n        \\frac{\\mathrm dE}{\\mathrm dt}&=\\frac{\\mathrm d}{\\mathrm dt}\\left(\\frac{m|\\underline{\\dot{r}}|^2}{2}+q\\Phi_e(\\underline{r})\\right)\\\\\r\n        &=m\\underline{\\dot{r}}\\cdot\\underline{\\ddot{r}}-q\\underline{\\dot{r}}\\cdot\\underline{E}\\\\\r\n        &=\\underline{\\dot{r}}(m\\underline{\\ddot{r}}-q\\underline{E})\\\\\r\n        &=0\r\n    \\end{align*}\r\n    So $E$ is constant.\r\n\\end{proof}\r\n\\begin{law}\r\n    Now consider a point charge $Q$ located at the origin.\r\n    It generates an electrostatic field\r\n    $$\\Phi_e(\\underline{r})=\\frac{Q}{4\\pi\\epsilon_0|\\underline{r}|},\\underline{E}=\\frac{Q}{4\\pi\\epsilon_0|\\underline{r}|^2}\\underline{\\hat{r}}$$\r\n    where $\\epsilon_0$ is called the electric constant.\r\n\\end{law}\r\nSo the force exerted on our point charge $q$ is\r\n$$\\underline{F}=q\\underline{E}=\\frac{Qq}{4\\pi\\epsilon_0|\\underline{r}|^2}\\underline{\\hat{r}}$$\r\nwhich is called the Coulomb force.\r\nOne observe the similarity of this with the gravitational law (inverse-square law).\r\nAlso, by considering the signs, we find that same signed charges repel, opposite charges attract.\r\n\\subsection{Friction}\r\nThe friction is a contact force, which occurs when two body touches each other (they may not be of the same form though).\r\nIt is a convenient description of complicated molecular-scale physics.\r\nSo friction is not a kind of fundamental forces (gravity, EM, strong force, weak force).\\\\\r\nWe first consider a special kind of friction that is \\textit{dry friction}.\r\nSolids stand on each other exerts an action and reaction pair of normal forces (normal to the surface of contact), which prevents an object from merging with the other.\r\nThere is also a tangential force, which is a tangent to the trajectory on the surface where the solid is moving.\\\\\r\nNow imagine we place a block on a slope.\r\nIf it remains at rest, the tangential force is called the static force, which exists even without relative motion.\r\nIn this case we have\r\n\\begin{law}\r\n    The static force $\\underline{F}$ has $|\\underline{F}|\\le\\mu_s|\\underline{N}|$ where $\\mu_s$ is a constant (depending on the materials) called the coefficient of static friction, and $\\underline{N}$ is the normal force.\r\n\\end{law}\r\nSo the block can rest on the plane provided that $\\alpha\\le\\tan^{-1}(\\mu_s)$ where $\\alpha$ is the inclination.\\\\\r\nThere is a kinetic frictional force as well, which depends on the kinetic motion of the object.\r\n\\begin{law}\r\n    The kinetic frictional force has $\\underline{F}=\\mu_k|\\underline{N}|$ where $\\mu_k$ is also a constant depending on the materials.\r\n\\end{law}\r\nNormally $\\mu_s>\\mu_k>0$.\\\\\r\nThe most complicated type of friction is the \\textit{fluid drag}, which is the friction exerted by a solid moving in fluid medium.\r\nThe model of linear drag says that\r\n$$\\underline{F}=-k_1\\underline{\\underline{u}}$$\r\nwhere $\\underline{u}$ is the velocity along the direction of motion and $k$ is a constant.\r\nThis model is relevent if we are considering a small object moving through a viscous fluid.\r\n\\begin{law}[Stokes' Law]\r\n    Consider a sphere with radius $R$ moving in a viscous fluid with viscosity of $\\eta$, then we have $k_1=6\\pi\\eta R$.\r\n\\end{law}\r\nAnother drag regime is called the quadratic model, which is for large bodies moving in less viscous fluid.\r\n$$\\underline{F}=-k_2|\\underline{u}|\\underline{u}$$\r\nTypically we have $\\rho R^2C_0$ where $\\rho$ is the density of the fluid, $R$ is the radius and $C_0$ is the drag coefficient.\\\\\r\nIn the case of a linear drag, the rate of work done is $\\underline{F}\\cdot\\underline{u}=-k_1|\\underline{u}|^2$ and for quadratic law $\\underline{F}\\cdot\\underline{u}=-k_2|\\underline{u}|^3$.\r\nThe fluid gains energy due to this energy loss by the solid, obviously.\\\\\r\nRecall from differential equations that the damp oscillator $m\\ddot{x}=-kx-\\lambda\\dot{x}$ where the last term is a drag.\r\nWe know how to solve this.\r\n\\begin{example}\r\n    Projectiles moving under uniform gravity and experiencing linear drag force.\r\n    The equation of motion is hence\r\n    $$m\\ddot{x}=m\\underline{g}-k\\underline{\\dot{x}}$$\r\n    Consider the particle start at the origin with some velocity $\\underline{U}$, so the initial conditions are $\\underline{x}(0)=\\underline{0},\\underline{\\dot{x}}(0)=\\underline{U}$.\r\n    We can solve the equation in $\\underline{\\dot{x}}$ and substituting the initial condition gives\r\n    $$\\underline{\\dot{x}}=\\frac{m\\underline{g}}{k}+(\\underline{U}-m\\underline{g}/k)e^{-kt/m}$$\r\n    Integrate it again and plug in the other initial condition,\r\n    $$\\underline{x}=\\frac{m\\underline{g}}{k}t+\\frac{m}{k}(\\underline{U}-m\\underline{g}/k)(1-e^{-kt/m})$$\r\n    Set $\\underline{x}=(x,y,z),\\underline{U}=U(\\cos\\theta,0,\\sin\\theta),\\underline{g}=(0,0,-g)$.\r\n    Hence we have, by simply plugging things in, that $y$ direction is irrelevant at all, while\r\n    $$\\dot{x}=U\\cos\\theta e^{-kt/m},\\dot{y}=0,\\dot{z}=(U\\sin\\theta+mg/k)e^{-kt/m}-mg/k$$\r\n    so the $x$-velocity will eventually go to $0$ and $z$ velocity to a terminal value $mg/k$ (roughly after $t=m/k$).\\\\\r\n    As for displacement, we have\r\n    $$x=mU\\cos\\theta/k(1-e^{-kt/m}),z=-mgt/k+m/k(U\\sin\\theta+mg/k)(1-e^{-kt/m})$$\r\n    so $x$ is bounded but $z$ is eventually moving (linearly as $t$ large).\\\\\r\n    Now we want to turn to analyze the range $R(U,\\theta,m,k,g)$ of the projectile for it to reach its original position (assuming we project it upwards), so by dimensional analysis we get the dimensionless quantity to be $f(\\theta,kU/mg)=f(\\theta,(U/g)/(m/k))$.\r\n    Note that $U/g$ is proportional to the time taken to reduce velocity such that it vanishes; and $m/k$ is the approximate time to achieve the terminal velocity.\r\n    So weak friction means $kU/mg<<1$ and strong firction means $kU/mg>>1$.\\\\\r\n    We have $R=U^2/gf(\\theta,kU/mg)$.\r\n    If $kU/mg<<1$, then $R\\approx U^2/g(2\\sin\\theta\\cos\\theta)$.\r\n    If $kU/mg>>1$, then $R\\approx U^2/g(\\cos\\theta(mg/kU))$.\r\n\\end{example}", "meta": {"hexsha": "773b605554ca092a1c2bcaa7282ded2e2c298d41", "size": 18170, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/forces.tex", "max_stars_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_stars_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3/forces.tex", "max_issues_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_issues_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3/forces.tex", "max_forks_repo_name": "david-bai-notes/IA-Dynamics-and-Relativity", "max_forks_repo_head_hexsha": "9a37539f19e62c795ad837062801e51e7adc75b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 74.7736625514, "max_line_length": 263, "alphanum_fraction": 0.695156852, "num_tokens": 5628, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.868826789824086, "lm_q1q2_score": 0.7277466638354302}}
{"text": "\\chapter{Small oscillations}\n\\section{Potential energy and equilibrium}\nIn order to understand the general theory of oscillations, it is essential to know about the potential energl at the equilibrium configuration. Let us consider a conservative system in which the potential energy is: function of position only. Let the system be specified by $n$ generalized coordinates $q_{1}, q_{2}, \\ldots, q_{n}$, not involve, time explicitly. For such a system, the potential energy is given by\n$$\nV=V\\left(q_{1}, q_{2}, \\ldots, q_{n}\\right)\n$$\nand the generalized forces are given by\n$G_{k}=-\\frac{\\partial V}{\\partial q_{k}}$ where $k=1,2, \\ldots ., n$\\\\\nThe system is said to be in equilibrium, if the generalized forces acting on the system are equal to zero: i.e.,\n$$\nG_{k}=-\\left[\\frac{\\partial V}{\\partial q_{k}}\\right]_{0}=0\n$$\n\\textbf{For small oscillations}\\\\\n\\textbf{Force constant} $k=\\left.\\frac{\\partial^{2} V}{\\partial q_k^{2}}\\right|_{q=q_{0}} \\text { where } q_{0} \\text { is stable equilibrium point. }$\\\\\n\\textbf{Angular frequency} $\\omega=\\sqrt{\\frac{k}{m}}$\n\\subsection{Stable,Unstable and Neutral equilibrium}\n\\subsubsection{Stable equilibrium}\nA system is said to be in stable equilibrium, if a small displacement of the system from the rest position (by giving a little energy to it) results in a small bounded motion about the equilibrium position.\n\\subsubsection{Unstable equilibrium}\nSmall displacement of the system from the equilibrium position results in an unbounded motion, it is in an unstable equilibrium.\n\\subsubsection{Neutral equilibrium}\n Further, if the system on displacement has no tendency to move about or away the equilibrium position, it is said to be in neutral equilibrium.\\\\\n \\begin{minipage}{0.5\\textwidth}\n \\begin{figure}[H]\n \t\\centering\n \t\\includegraphics[height=4cm,width=5cm]{stable}\n \t\\caption{}\n \t\\label{fig1}\n \\end{figure}\n \\end{minipage}\n\\begin{minipage}{0.5\\textwidth}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3cm,width=5cm]{unstable}\n\t\\caption{}\n\t\\label{fig2}\n\\end{figure}\n\\end{minipage}\nA graph drawn between the potential energy of the system and a particular coordinate $q_{k}$ is called potential energy curve and  The positions $A$ and $B$, where the generalized force $F=-\\partial V / \\partial q$ vanishes, are the positions of equilibrium; potential energy $V$ is minimum (say $V_{0}$ ) at $A$ [fig.\\ref{fig1}] and maximum at $B$ [fig.\\ref{fig2} ]. Position $A$ corresponds to the stable equilibrium, because if the system is displaced from $A$ to $Q$ by giving energy $\\left(E-V_{0}\\right)$ and left to itself, the system tries to come in the position of minimum potential energy. Consequently the potential energy will change to kinetic energy and at $A$ the energy $\\left(E-V_{0}\\right)$ will be purely in the kinetic form because of the conservation law. This will change again to potential form, when the system moves towards the position $P$ and hence a bounded motion ensues about the equilibrium position $A$. Obviously the position $B$ of the maximum potential energy represents the unstable equilibrium because any energy given to the system at this position will result more and more kinetic energy when the system moves either left or right to it. In this case, the system moves away from the equilibrium position. In case of neutral equilibrium, the potential energy is independent of the coordinate and equilibrium. occurs at any arbitrary value of that coordinate.\n\\section{Small oscillations}\nIn small oscillation we generalize the harmonic oscillator problem of one degree of freedom in the lagrangian formulation to the case of small amplitude oscillations of a system of seversl degrees of freedom near the position of equilibrium.When we go from a single oscillator to the problem of two coupled oscillators the analysis results in some interesting and surprising new features.We shall see that the motion of the two coupled oscillators in general is much complicated and none of the oscillators in general executes simple harmonic motion.However for small amplitude oscillations ,we may express the general motion as a superposition of two independant simple harmonic motions ,both going on simultaneously.We call thsese two simple harmonic motions as normal modes or simply modes.Further we shall see that a system of N coupled oscillators with N degrees of freedom ,has exactly N independant modes of vibration and general motion can be expressed as the superposition of N normal modes.Each mode has its own frquency and wavelength.\n\\subsection{Matrix method to solve small oscillations}\nWe shall interested in the motion of the system with in the immediate neighbourhood of configuration of stable equilibrium .Since the departure fro the equilibrium is very small ,all functions may be expanded in a Taylor series about the equlibrium ,retaining only the lowest order terms .The deviation of the generalized coordinates from equilibrium will be denoted by $\\eta_i$:\\\\\n$$q_i=q_{oi}+\\eta_i$$\nand these may be taken as the new generalized coordinates of the motion  \n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3cm,width=5cm]{potential}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\nOne can expand potential energy by Taylor series expansion\n$$V\\left(q_{i} \\ldots \\ldots q_{n}\\right)=V\\left(q_{00} \\ldots \\ldots q_{0 n}\\right)+\\left.\\frac{\\partial V}{\\partial q_{i}}\\right|_{q_{i 0}}\\left(q_{i}-q_{0 i}\\right)+\\frac{1}{2} \\frac{\\partial^{2} V}{\\partial q_{i} \\partial q_{j}}\\left(q_{i}-q_{0 i}\\right)\\left(q_{j}-q_{0 j}\\right)+\\ldots .$$\nThe 0 in subscript means $q_{i}=q_{0 i}$\\\\\nSo,\n\\begin{equation}\n\\quad V(q)=V_{0}+0+\\frac{1}{2}\\left(\\frac{\\partial^{2} V}{\\partial q_{i} \\partial q_{j}}\\right)_{0} \\eta_{i} \\eta_{j}+\\ldots \\ldots \\label{ref1}\n\\end{equation}\nbecause at equilibrium,\n$$\n\\left(\\frac{\\partial V}{\\partial q_{i}}\\right)_{q_{i}=q_{0 i}} \\equiv\\left(\\frac{\\partial V}{\\partial q_{i}}\\right)_{0}=-Q_{i}=0\n$$\nwhere $Q_{i}$ is the generalized force. Now,\n\\begin{equation}\nV_{0} \\equiv V\\left(q_{01}, q_{02}, \\ldots \\ldots, q_{0 n}\\right) \\label{ref2}\n\\end{equation}\n is the potential energy of eqilibrium configuration whis is constant.So we set $V_0$ is equal to zero because in equations of motions only derivative of V occur.\\\\\n Neglecting higher order terms (because $\\eta_{i}^{\\prime} s$ are very small)\n \\begin{equation}\n V=\\frac{1}{2}\\left(\\frac{\\partial^{2} V}{\\partial q_{i} \\partial q_{j}}\\right)_{0} \\eta_{i} \\eta_{j}=\\frac{1}{2} V_{i j} \\eta_{i} \\eta_{j} \\label{ref3}\n \\end{equation}\n We see that $V_{i j}=V_{j i}$\n We can write $V$ in matrix form as\n\\begin{align}\n V=\\frac{1}{2}\\left(\\begin{array}{llll}\n\\eta_{1} & \\eta_{2} & \\cdots & \\eta_{n}\n\\end{array}\\right)\\left[\\begin{array}{cccc}\nV_{11} & V_{12} & \\cdots & V_{1 n} \\\\\nV_{21} & V_{22} & \\ldots & V_{2 n} \\\\\n\\vdots & \\vdots & \\ldots & \\vdots \\\\\nV_{n 1} & V_{n 2} & \\ldots & V_{n n}\n\\end{array}\\right]\\left[\\begin{array}{l}\n\\eta_{1} \\\\\n\\eta_{2} \\\\\n\\vdots \\\\\n\\eta_{n}\n\\end{array}\\right]\\label{ref4}\n\\end{align}\nSince the constraints are time independent, hence kinetic energy can be written as\n\\begin{align}\nT=\\frac{1}{2} m_{i j} \\dot{q}_{i} \\dot{q}_{j}=\\frac{1}{2} m_{i j} \\dot{\\eta}_{i} \\dot{\\eta}_{j}\\label{ref5}\n\\end{align}\nSince, $q_{i}=q_{0 i}+\\eta_{i}$, so $\\dot{q}_{i}=\\dot{\\eta}_{i}$\\\\\n$m_{i j}$ can also be expanded similar to $V$\n$$m_{i j}=m_{i j}\\left(q_{01}, q_{02}, \\ldots \\ldots, q_{0 n}\\right)+\\left(\\frac{\\partial m_{i j}}{\\partial q_{k}}\\right)_{0} \\dot{\\eta}_{k}+\\ldots \\ldots \\ldots$$\n$\\text { here we take first term only, because in equation $\\ref{ref5}$ we already has } \\dot{\\eta} \\dot{\\eta}_{j} $.\\\\\nso\n\\begin{equation}\nT=\\frac{1}{2} T_{i j} \\dot{\\eta}_{i} \\dot{\\eta}_{j}\\label{ref6}\n\\end{equation}\n$\\text { where, } \\quad T_{i j}=m_{i j}\\left(q_{01}, q_{02}, \\ldots \\ldots q_{0 n}\\right)$\\\\\n\\text { In matrix form, }\n\\begin{align}\n T=\\frac{1}{2}\\left(\\begin{array}{llll}\n\\dot{\\eta}_{1} & \\dot{\\eta}_{2} & \\ldots & \\dot{\\eta}_{n}\n\\end{array}\\right)\\left[\\begin{array}{cccc}\nT_{11} & T_{12} & \\ldots & T_{1 n} \\\\\nT_{21} & T_{22} & \\ldots & T_{2 n} \\\\\n\\vdots & \\vdots & \\ldots & \\vdots \\\\\nT_{n 1} & T_{n 2} & \\ldots & T_{n n}\n\\end{array}\\right]\\left[\\begin{array}{l}\n\\dot{\\eta}_{1} \\\\\n\\dot{\\eta}_{2} \\\\\n\\vdots \\\\\n\\dot{\\eta}_{n}\n\\end{array}\\right]\\label{ref7}\n\\end{align}\nLike $\\mathbf{V}, \\mathbf{T}$ is also symmetric, i.e. $T_{i j}=T_{j i}$\nThe Lagrangian is, \n\\begin{align}\nL=T-V=\\frac{1}{2}\\left(T_{i j} \\dot{\\eta}_{i} \\dot{\\eta}_{j}-V_{i j} \\eta_{i} \\eta_{j}\\right)\\label{ref8}\n\\end{align}\nThe equation of motion for $\\eta_{i}$\n$$\n\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{\\eta}_{i}}\\right)-\\frac{\\partial L}{\\partial \\eta_{i}}=0\n$$\n\\begin{align}\n&\\frac{d}{d t}\\left(\\frac{\\partial}{\\partial \\dot{\\eta}_{i}}\\left(T_{i j} \\dot{\\eta}_{i} \\dot{\\eta}_{j}-V_{i j} \\eta_{i} \\eta_{j}\\right)\\right)-\\frac{\\partial}{\\partial \\eta_{i}}\\left(T_{i j} \\dot{\\eta}_{i} \\dot{\\eta}_{j}-V_{i j} \\eta_{i} \\eta_{j}\\right)=0 \\notag \\\\\n&\\frac{d}{d t}\\left(T_{i j} \\dot{\\eta}_{j}\\right)-V_{i j} \\eta_{j}=0 \\notag \\\\\n&T_{i j} \\ddot{\\eta}_{j}+V_{i j} \\eta_{j}=0 \\label{ref9}\n\\end{align}\nNote that $T_{i j}$ and $\\mathrm{V}_{i j}$ are constants and $\\dot{\\eta}^{\\prime} s$ and $\\eta^{\\prime} s$ appear only as multiplication with each other. For example the equation for $\\eta_{1}$ is\n\\begin{align*}\n&\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{\\eta}_{1}}\\right)-\\frac{\\partial L}{\\partial \\eta_{1}}=0 \\\\\n&\\frac{d}{d t}\\left[\\frac{\\partial}{\\partial \\dot{\\eta}_{1}}\\left(T_{1 j} \\dot{\\eta}_{1} \\dot{\\eta}_{j}\\right)+\\frac{\\partial}{\\partial \\eta_{1}}\\left(V_{1 j} \\eta_{1} \\eta_{j}\\right)\\right]=0\n\\end{align*}\n[Since $V$ is independent of $\\dot{\\eta}^{\\prime} s$ and $T$ is independent of $\\eta^{\\prime} s$ ]. So,\n\\begin{align*}\n&\\frac{d}{d t}\\left(\\frac{\\partial}{\\partial \\dot{\\eta}_{1}}\\left(T_{11} \\dot{\\eta}_{1} \\dot{\\eta}_{1}+T_{12} \\dot{\\eta}_{1} \\dot{\\eta}_{2}+\\ldots \\ldots \\ldots .+T_{1 n} \\dot{\\eta}_{1} \\dot{\\eta}_{n}+\\ldots \\ldots . .\\right)\\right)\\\\\n&+\\frac{\\partial}{\\partial \\eta_{1}}\\left(V_{11} \\eta_{1} \\eta_{1}+V_{12} \\eta_{1} \\eta_{2}+\\ldots \\ldots . . V_{1 n} \\eta_{1} \\eta_{n}+\\ldots \\ldots\\right)=0 \\\\\n&\\frac{d}{d t}\\left(T_{11} \\dot{\\eta}_{1}+T_{12} \\dot{\\eta}_{2}+\\ldots \\ldots T_{1 n} \\dot{\\eta}_{n}\\right)+\\left(V_{11} \\eta_{1}+V_{12} \\eta_{2}+\\ldots \\ldots+V_{1 n} \\eta_{n}\\right)=0 \\\\\n&T_{11} \\ddot{\\eta}_{1}+T_{12} \\ddot{\\eta}_{2}+\\ldots . .+T_{1 n} \\ddot{\\eta}_{n}+\\left(V_{11} \\eta_{1}+V_{12} \\eta_{2}+\\ldots . .+V_{1 n} \\eta_{n}\\right)=0\n\\end{align*}\nIn summation convention the above equation is\n\\begin{align}\nT_{1 j} \\ddot{\\eta}_{j}+V_{1 j} \\eta_{j}=0\\label{ref10}\n\\end{align}\nThe point is that you should know what any expression means. So, we get $\\eta$ equations in total.\nTo sovle the equation of motion $\\eta$, we put a trial solution.\n\n\\begin{equation}\n\\eta_{j}=C a_{j} e^{-i o t}\\label{ref11}\n\\end{equation}\nNote that in the exponential $i=\\sqrt{-1}$\nWe get,\n\\begin{align}\n&\\dot{\\eta}_{j}=-C a_{j}(i \\omega) e^{-i \\omega t} \\notag \\\\\n&\\ddot{\\eta}_{j}=+C a_{j}(i \\omega)^{2} e^{-i \\omega t}=-\\omega^{2} \\eta_{j}\\label{ref12}\n\\end{align}\n$\\text { putting } \\ddot{\\eta}_{j} \\text { in equation ($\\ref{ref9}$) }$\n\\begin{align}\n&T_{i j} \\ddot{\\eta}_{j}+V_{i j} \\eta_{j}=0 \\notag\\\\\n&T_{i j}\\left(-\\omega^{2} \\eta_{j}\\right)+V_{i j} \\eta_{j}=0 \\notag\\\\\n&\\left(V_{i j}-\\omega^{2} T_{i j}\\right) \\eta_{j}=0\\label{ref13} \\\\\n&V_{i j} a_{j}=\\omega^{2} T_{i j} a_{j}\\label{ref14}\n\\end{align}\n in the matrix form equation ($\\ref{ref13}$), is (equation  $\\ref{ref14}$  also can be written in similar form)\\\\\n $\\left[\\begin{array}{cccc}\n \tV_{11} & V_{12} & \\ldots & V_{1 n} \\\\\n \tV_{21} & V_{22} & \\ldots & V_{2 n} \\\\\n \t\\vdots & \\vdots & & \\vdots \\\\\n \tV_{n 1} & V_{n 2} & \\ldots & V_{n n}\n \\end{array}\\right]\\left[\\begin{array}{l}\n \t\\eta_{1} \\\\\n \t\\eta_{2} \\\\\n \t\\vdots \\\\\n \t\\eta_{n}\n \\end{array}\\right]-\\omega^{2}\\left[\\begin{array}{cccc}\n \tT_{11} & T_{12} & \\ldots & T_{1 n} \\\\\n \tT_{21} & T_{22} & \\ldots & T_{2 n} \\\\\n \t\\vdots & \\vdots & & \\vdots \\\\\n \tT_{n 1} & T_{n 2} & \\ldots & T_{n n}\n \\end{array}\\right]\\left[\\begin{array}{l}\n \t\\eta_{1} \\\\\n \t\\eta_{2} \\\\\n \t\\vdots \\\\\n \t\\eta_{n}\n \\end{array}\\right]=0$\n \\begin{align}\n \\left[\\begin{array}{cccc}\n V_{11}-\\omega^{2} T_{11} & V_{12}-\\omega^{2} T_{12} & \\ldots & V_{1 n}-\\omega^{2} T_{1 n} \\\\\n V_{21}-\\omega^{2} T_{21} & V_{22}-\\omega_{2} T_{22} & \\ldots & V_{2 n}-\\omega^{2} T_{2 n} \\\\\n \\vdots & \\vdots & & \\vdots \\\\\n V_{n 1}-\\omega^{2} T_{n 1} & V_{n 2}-\\omega^{2} T_{n 2} & & V_{n n}-\\omega^{2} T_{n n}\n \\end{array}\\right]\\left[\\begin{array}{l}\n \\eta_{1} \\\\\n \\eta_{2} \\\\\n \\vdots \\\\\n \\eta_{n}\n \\end{array}\\right]=0\\label{ref15}\n \\end{align}\n From properties of matrices we know that for equation ($\\ref{ref15}$) to be satisfied for all $\\eta^{\\prime} s$. The determinant of matrix $\\mathbf{V}-\\omega^{2} \\mathbf{T}$ must be zero i.e.\n $$\n \\left|\\mathbf{V}-\\omega^{2} \\mathbf{T}\\right|=0\n $$\n \\begin{align}\n \\left|\\begin{array}{cccc}\n V_{11}-\\omega^{2} T_{11} & V_{12}-\\omega^{2} T_{12} & \\cdots & V_{1 n}-\\omega^{2} T_{1 n} \\\\\n V_{21}-\\omega^{2} T_{21} & V_{22}-\\omega_{2} T_{22} & \\cdots & V_{2 n}-\\omega^{2} T_{2 n} \\\\\n \\vdots & \\vdots & & \\vdots \\\\\n V_{n 1}-\\omega^{2} T_{n 1} & V_{n 2}-\\omega^{2} T_{n 2} & & V_{n n}-\\omega^{2} T_{n n}\n \\end{array}\\right|=0\\label{ref16}\n \\end{align}\n  This equation ($\\ref*{ref16}$) is called the secular equation.\n  By solving the determinant ($\\ref{ref16}$) we get $n$ values of $\\omega^{2}$. Each value of $\\omega$ represents the frequency of normal mode. The equation ($\\ref{ref14}$) is a type of eigenvalues. $\\mathbf{V}$ acting on eigenvector a gives $\\omega^{2} \\mathbf{T a}$. There are $n$ such eigenvectors. Hence, there are $n$ normal modes. It can be shown that the eigen vector matrix of which is denoted by $\\mathbf{A}$ diagonalizes both $\\mathbf{T}$ and $\\mathbf{V}$ (for detail see section $6.2$ of Goldstein, $3^{\\text {rd }}$ eddition, but it is sufficient for us to rememher the result). A diagonalizes $\\mathbf{V}$ to a matrix whose diagonal elements are the eigen-$\\text { values i.e. } \\omega^{2 \\prime} s \\text { (say } \\lambda^{\\prime} s)$\\\\\n  (Note that in ordinary eigen alue problems, matrix acting on eigenvector produces eigenvalue times the eigenvector i.e. $\\mathbf{M a}=\\lambda \\mathbf{a}$ or $(\\mathbf{M}-\\lambda \\mathbf{1}) \\mathbf{a}=0$, but here it is $(\\mathbf{V}-\\lambda \\mathbf{T}) \\mathbf{a}=0 .)$\\\\\n  ie\n  \\begin{align}\n  \\tilde{\\mathbf{A}} \\mathbf{V} \\mathbf{A}=\\lambda=\\left[\\begin{array}{cccc}\n  \\lambda_{1} & 0 & \\cdots & 0 \\\\\n  0 & \\lambda_{2} & \\cdots & 0 \\\\\n  \\vdots & \\vdots & & \\vdots \\\\\n  0 & 1, & \\cdots & \\lambda_{n}\n  \\end{array}\\right]\\label{ref17}\n  \\end{align}\n  $\\text { where } \\lambda_{1}, \\lambda_{2} \\ldots . . \\text { are eigen values of (i.e. } \\omega^{21} s \\text { ) }$\\\\\n  And $\\mathbf{T}$ is diagonalized to identity i.e.\n  \\begin{align}\n  \\tilde{\\mathbf{A}} \\mathbf{T} \\mathbf{A}=\\mathbf{1}\\label{ref18}\n  \\end{align}\n  To solve a problem, the main thing we need to do is\\\\\n   (1) Solve the determinant (9.16) to find the frequencies of normal modes\\\\\n  (2) Find the eigenvectors a correspoinding to each $\\omega^{2}$ (the eigenvalue), in the equation.\n  $$\n  \\left(\\mathbf{V}-\\omega^{2} \\mathbf{T}\\right) \\mathbf{a}=0\n  $$\n  where the $k^{\\text {th }}$ eigenvector (corrersponding to $k^{\\text {th }} \\omega^{2}$ )\n  \n  \\begin{align}\n  \\mathbf{a}_{k}=\\left[\\begin{array}{c}\n  a_{1 k} \\\\\n  a_{2 k} \\\\\n  \\vdots \\\\\n  a_{n k}\n  \\end{array}\\right]\\label{ref19}\n  \\end{align}\n  (3) The normal mode coordinates are\n  \\begin{align}\n  Q_{k}=f_{k} \\cos \\left(\\omega_{k} t+\\delta_{k}\\right)\\label{ref20}\n  \\end{align}\n  where, $f_{k}$ and $\\delta_{k}$ are amplitude and phase factor respectively. Note that in a normal mode, the hole system oscillates with same frequency.\n  (4) The general solution for\n  \\begin{align}\n  \\eta_{i}=a_{i k} Q_{k}\\label{ref21}\n  \\end{align}\n   The matrix $\\mathbf{A}$ is \n   \\begin{align}\n   \\left[\\begin{array}{llll}a_{11} & a_{12} & \\cdots & a_{1 n} \\\\ a_{21} & a_{22} & \\cdots & a_{2 n} \\\\ \\vdots & \\vdots & & \\vdots \\\\ a_{n 1} & a_{n 2} & \\cdots & a_{n n}\\end{array}\\right]\\label{22}\n   \\end{align}\n  So, the solution of our problem (the equation ($\\ref{ref21}$) is:\n \\begin{align}\n  \\left[\\begin{array}{l}\n \\eta_{1} \\\\\n \\eta_{2} \\\\\n \\vdots \\\\\n \\eta_{n}\n \\end{array}\\right]=\\left[\\begin{array}{llll}\n a_{11} & a_{12} & \\cdots & a_{1 n} \\\\\n a_{21} & a_{22} & \\cdots & a_{2 n} \\\\\n \\vdots & \\vdots & & \\vdots \\\\\n a_{n 1} & a_{n 2} & \\cdots & a_{n n}\n \\end{array}\\right]\\left[\\begin{array}{l}\n Q_{1} \\\\\n Q_{2} \\\\\n \\vdots \\\\\n Q_{n}\n \\end{array}\\right] \n \\end{align}\n One complication may arise when eigenvalues are degenerate. In this case we first choose an eigenvector (corresponding to degenerate eigenvalue) satisfying the eigenvalue equation and remaining eigenvectors (if there is $k$-fold degeneracy, then there are $k$-eigenvectors corresponding to single eigenvalue) are determined such that they satisfy the eigenvalue equation and are orthogonal to each other.\n \\newpage\n \\begin{abox}\n \tPractice set 1\n \t\\end{abox}\n \\begin{enumerate}\n \t\t\\item  A particle of unit mass moves in a potential $V(x)=a x^{2}+\\frac{b}{x^{2}}$, where $a$ and $b$ are positive constants. The angular frequency of small oscillations about the minimum of the potential is\n \t\t{\\exyear{NET JUNE 2011}}\n \t\\begin{tasks}(2)\n \t\t\\task[\\textbf{A.}] $\\sqrt{8 b}$\n \t\t\\task[\\textbf{B.}]$\\sqrt{8 a}$\n \t\t\\task[\\textbf{C.}] $\\sqrt{8 a / b}$\n \t\t\\task[\\textbf{D.}]$\\sqrt{8 b / a}$\n \t\\end{tasks}\n \t\\item Consider the motion of a classical particle in a one dimensional double-well potential $V(x)=\\frac{1}{4}\\left(x^{2}-2\\right)^{2} .$ If the particle is displaced infinitesimally from the minimum on the $x$-axis (and friction is neglected), then\n \t{\\exyear{NET JUNE 2012}}\n \\begin{tasks}(1)\n \t\\task[\\textbf{A.}] the particle will execute simple harmonic motion in the right well with an angular frequency $\\omega=\\sqrt{2}$\n \t\\task[\\textbf{B.}]the particle will execute simple harmonic motion in the right well with an angular frequency $\\omega=2$\n \t\\task[\\textbf{C.}]the particle will switch between the right and left wells\n \t\\task[\\textbf{D.}]the particle will approach the bottom of the right well and settle there\n \\end{tasks}\n\t\\item Three particles of equal mass $(\\mathrm{m})$ are connected by two identical massless springs of stiffness constant $(K)$ as shown in the figure\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=1cm,width=5cm]{problem1}\n\t\\end{figure}\n\tIf $x_{1}, x_{2}$ and $x_{3}$ denote the horizontal displacement of the masses from their respective equilibrium positions the potential energy of the system is\n\t{\\exyear{NET DEC 2012}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{1}{2} K\\left[x_{1}^{2}+x_{2}^{2}+x_{3}^{2}\\right]$\n\t\\task[\\textbf{B.}]$\\frac{1}{2} K\\left[x_{1}^{2}+x_{2}^{2}+x_{3}^{2}-x_{2}\\left(x_{1}+x_{3}\\right)\\right]$\n\t\\task[\\textbf{C.}]$\\frac{1}{2} K\\left[x_{1}^{2}+2 x_{2}^{2}+x_{3}^{2}-2 x_{2}\\left(x_{1}+x_{3}\\right)\\right]$\n\t\\task[\\textbf{D.}]$\\frac{1}{2} K\\left[x_{1}^{2}+2 x_{2}^{2}-2 x_{2}\\left(x_{1}+x_{3}\\right)\\right]$\n\\end{tasks}\n\t\\item The time period of a simple pendulum under the influence of the acceleration due to gravity $g$ is $T$. The bob is subjected to an additional acceleration of magnitude $\\sqrt{3} g$ in the horizontal direction. Assuming small oscillations, the mean position and time period of oscillation, respectively, of the bob will be\n\t{\\exyear{NET JUNE 2014}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $0^{\\circ}$ to the vertical and $\\sqrt{3} T$\n\t\\task[\\textbf{B.}]$30^{\\circ}$ to the vertical and $T / 2$\n\t\\task[\\textbf{C.}]$60^{\\circ}$ to the vertical and $T / \\sqrt{2}$\n\t\\task[\\textbf{D.}]$0^{\\circ}$ to the vertical and $T / \\sqrt{3}$\n\\end{tasks}\n\t\\item A particle of mass $m$ is moving in the potential $V(x)=-\\frac{1}{2} a x^{2}+\\frac{1}{4} b x^{4}$ where $a, b$ are positive constants. The frequency of small oscillations about a point of stable equilibrium is\n\t{\\exyear{NET DEC 2014}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\sqrt{a / m}$\n\t\\task[\\textbf{B.}]$\\sqrt{2 a / m}$\n\t\\task[\\textbf{C.}]$\\sqrt{3 a / m}$\n\t\\task[\\textbf{D.}]$\\sqrt{6 a / m}$\n\\end{tasks}\n\t\\item A particle of mass $m$, kept in potential $V(x)=-\\frac{1}{2} k x^{2}+\\frac{1}{4} \\lambda x^{4}$ (where $k$ and $\\lambda$ are positive constants), undergoes small oscillations about an equilibrium point. The frequency of oscillations is\n\t{\\exyear{NET JUNE 2018}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{1}{2 \\pi} \\sqrt{\\frac{2 \\lambda}{m}}$\n\t\\task[\\textbf{B.}]$\\frac{1}{2 \\pi} \\sqrt{\\frac{k}{m}}$\n\t\\task[\\textbf{C.}]$\\frac{1}{2 \\pi} \\sqrt{\\frac{2 k}{m}}$\n\t\\task[\\textbf{D.}]$\\frac{1}{2 \\pi} \\sqrt{\\frac{\\lambda}{m}}$\n\\end{tasks}\n \\end{enumerate}\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{b}&2&\\textbf{b}\\\\\\hline\n\t\t3&\\textbf{c}&4&\\textbf{c}\\\\\\hline\n\t\t5&\\textbf{b}&6&\\textbf{c}\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\\newpage\n\\begin{abox}\n\tPractice set 2 \n\t\\end{abox}\n\\begin{enumerate}\n\n\t\\item A particle is placed in a region with the potential $V(x)=\\frac{1}{2} k x^{2}-\\frac{\\lambda}{3} x^{3}$, where $k, \\lambda>0$.\n\tThen,\n\t{\\exyear{GATE 2010}}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}] $x=0$ and $x=\\frac{k}{\\lambda}$ are points of stable equilibrium\n\t\\task[\\textbf{B.}]$x=0$ is a point of stable equilibrium and $x=\\frac{k}{\\lambda}$ is a point of unstable equilibrium\n\t\\task[\\textbf{C.}]$x=0$ and $x=\\frac{k}{\\lambda}$ are points of unstable equilibrium\n\t\\task[\\textbf{D.}]There are no points of stable or unstable equilibrium\n\\end{tasks}\n\n\t\\item Two bodies of mass $m$ and $2 m$ are connected by a spring constant $k$. The frequency of the normal mode is\n\t{\\exyear{GATE 2011}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\sqrt{3 k / 2 m}$\n\t\\task[\\textbf{B.}]$\\sqrt{k / m}$\n\t\\task[\\textbf{C.}] $\\sqrt{2 k / 3 m}$\n\t\\task[\\textbf{D.}]$\\sqrt{k / 2 m}$\n\\end{tasks}\n\t\\item A particle of unit mass moves along the $x$-axis under the influence of a potential, $V(x)=x(x-2)^{2}$. The particle is found to be in stable equilibrium at the point $x=2$. The time period of oscillation of the particle is\n\t{\\exyear{GATE 2012}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{\\pi}{2}$\n\t\\task[\\textbf{B.}]$\\pi$\n\t\\task[\\textbf{C.}]$\\frac{3 \\pi}{2}$\n\t\\task[\\textbf{D.}]$2 \\pi$\n\\end{tasks}\n\n\t\\item Consider two small blocks, each of mass $M$, attached to two identical springs. One of the springs is attached to the wall, as shown in the figure. The spring constant of each spring is $k$. The masses slide along the surface and the friction is negligible. The frequency of one of the normal modes of the system is,\n{\t\\exyear{GATE 2013}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{GATE1}\n\t\\end{figure}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\sqrt{\\frac{3+\\sqrt{2}}{2}} \\sqrt{\\frac{k}{M}}$\n\t\\task[\\textbf{B.}]$\\sqrt{\\frac{3+\\sqrt{3}}{2} \\sqrt{\\frac{k}{M}}}$\n\t\\task[\\textbf{C.}]$\\sqrt{\\frac{3+\\sqrt{5}}{2}} \\sqrt{\\frac{k}{M}}$\n\t\\task[\\textbf{D.}]$\\sqrt{\\frac{3+\\sqrt{6}}{2}} \\sqrt{\\frac{k}{M}}$\n\\end{tasks}\n\n\t\\item Two masses $m$ and $3 m$ are attached to the two ends of a massless spring with force constant $K$. If $m=100 \\mathrm{~g}$ and $K=0.3 \\mathrm{~N} / \\mathrm{m}$, then the natural angular frequency of oscillation is $H z$.\n{\t\\exyear{GATE 2014}}\n\n\t\\item A particle of mass $m$ is in a potential given by\n\t$$\n\tV(r)=-\\frac{a}{r}+\\frac{a r_{0}^{2}}{3 r^{3}}\n\t$$\n\twhere $a$ and $r_{0}$ are positive constants. When disturbed slightly from its stable equilibrium position it undergoes a simple harmonic oscillation. The time period of oscillation is\n\t{\\exyear{GATE 2014}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $2 \\pi \\sqrt{\\frac{m r_{0}^{3}}{2 a}}$\n\t\\task[\\textbf{B.}]$2 \\pi \\sqrt{\\frac{m r_{0}{ }^{3}}{a}}$\n\t\\task[\\textbf{C.}]$2 \\pi \\sqrt{\\frac{2 m r_{0}^{3}}{a}}$\n\t\\task[\\textbf{D.}]$4 \\pi \\sqrt{\\frac{m r_{0}^{3}}{a}}$\n\\end{tasks}\n\n\t\\item Two identical masses of $10 \\mathrm{gm}$ each are connected by a massless spring of spring constant $1 \\mathrm{~N} / \\mathrm{m}$. The non-zero angular eigenfrequency of the system is. $. \\mathrm{rad} / \\mathrm{s} .$ (up to two decimal places)\n{\t\\exyear{GATE 2017}}\n\t\\item In the context of small oscillations, which one of the following does NOT apply to the normal coordinates?\n\t{\\exyear{GATE 2018}}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}] Each normal coordinate has an eigen-frequency associated with it\n\t\\task[\\textbf{B.}]The normal coordinates are orthogonal to one another\n\t\\task[\\textbf{C.}]The normal coordinates are all independent\n\t\\task[\\textbf{D.}]The potential energy of the system is a sum of squares of the normal coordinates with constant coefficients\n\\end{tasks}\n\\end{enumerate}\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{b}&2&\\textbf{a}\\\\\\hline\n\t\t3&\\textbf{b}&4&\\textbf{c}\\\\\\hline\n\t\t5&\\textbf{0.318}&6&\\textbf{a}\\\\\\hline\n\t\t7&\\textbf{14.14}&8&\\textbf{b}\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\\newpage\n\\begin{abox}\n\tPractice set 3 \n\t\\end{abox}\n\\begin{enumerate}\n\t\t\\item  A particle of mass $m$ moves in one dimension under the influence of a potential energy\n\t$$\n\tV(x)=-a\\left(\\frac{x}{\\ell}\\right)^{2}+b\\left(\\frac{x}{\\ell}\\right)^{4}\n\t$$\n\twhere $a$ and $b$ are positive constants and $\\ell$ is a characteristic length. The frequency of small oscillations about a point of stable equilibrium is:\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\frac{1}{2 \\pi \\ell} \\sqrt{\\frac{b}{m}}$\n\t\t\\task[\\textbf{b.}]$\\frac{2 b}{\\pi \\ell} \\sqrt{\\frac{1}{m a}}$\n\t\t\\task[\\textbf{c.}]$\\frac{1}{\\pi \\ell} \\sqrt{\\frac{a^{2}}{m b}}$\n\t\t\\task[\\textbf{d.}] $\\frac{1}{\\pi \\ell} \\sqrt{\\frac{a}{m}}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{\tWe have,}\n\t\tV(x)&=-a\\left(\\frac{x}{\\ell}\\right)^{2}+b\\left(\\frac{x}{\\ell}\\right)^{4}\n\t\t\\intertext{Here first we need to find the stable equilibrium. At equilibrium}\n\t\t\\frac{\\partial V(x)}{\\partial x}&=0 \\quad \\Rightarrow \\frac{-2 a x}{\\ell^{2}}+\\frac{4 b x^{3}}{\\ell^{4}}=0 \\quad \\Rightarrow x\\left(\\frac{2 b x^{2}}{\\ell^{2}}-a\\right)=0\\\\\n\t\t\\Rightarrow \\quad x&=0, x=\\pm \\ell \\sqrt{\\frac{a}{2 b}}\\\\\n\t\t\\text{Now, }\\quad \\frac{\\partial^{2} V}{\\partial x^{2}}&=\\frac{-2 a}{\\ell^{2}}+\\frac{12 b x^{2}}{\\ell^{4}}\\\\\n\t\t\\text{We see that for }x&=0, \\frac{\\partial^{2} V}{\\partial x^{2}}<0\n\t\t\\text{hence, here there is unstable equilibrium}\\\\\n\t\t\\text{For}\\qquad x&=\\pm \\ell \\sqrt{\\frac{a}{2 b}},\\left(\\frac{\\partial^{2} V}{\\partial x^{2}}\\right)_{x=\\pm \\ell \\sqrt{\\frac{a}{2 b}}}=-\\frac{2 a}{\\ell^{2}}+\\frac{12 b}{\\ell^{4}} \\ell^{2} \\times \\frac{a}{2 b}=\\frac{4 a}{\\ell^{2}}>0\n\t\t\\intertext{hence, $x=\\pm \\ell \\sqrt{\\frac{a}{2 b}}$ corresponds to stable equilibrium.. Now to find the frequeny, we see that the problemis one dimensional, so matrices $\\mathbf{V}$ and $\\mathbf{T}$ both have one element each, i.e. $V_{11}$ and $T_{11}$ respectively.}\n\t\tV_{11}&=\\left(\\frac{\\partial^{2} V}{\\partial x^{2}}\\right)_{x=\\pm f \\sqrt{\\frac{a}{2 b}}}=\\frac{4 a}{\\ell^{2}}\\\\\n\t\t\\text{Now, the kinetic energy }&=\\frac{1}{2} m \\dot{x}^{2},\\text{ so }T_{11}=m\\\\\n\t\t\\text{\tNow, we have, }V_{11}-\\omega^{2} T_{11}&=0 \\qquad\\Rightarrow \\omega^{2}=\\frac{V_{11}}{T_{11}}=\\frac{4 a}{m \\ell^{2}} \\qquad\\Rightarrow \\omega=\\frac{2}{\\ell} \\sqrt{\\frac{a}{m}}\\\\\n\t\t\\text{So, the frequency }v&=\\frac{\\omega}{2 \\pi}=\\frac{1}{\\pi \\ell} \\sqrt{\\frac{a}{m}}\n\t\t\\intertext{Note: As we have seen in this problem, first we should find the equilibrium configuration of the system then expand potential energy about this configuration in Taylor series.}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item  A particle of mass $m$ is moving in a potential of the form $V(x, y, z)=\\frac{1}{2} m \\omega^{2}\\left(3 x^{2}+3 y^{2}+2 z^{2}+2 x\\right)$. The oscillation frequencies of the three normal modes of the particles are given by\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{The potential is, }V(x, y, z)&=\\frac{1}{2} m \\omega^{2}\\left(3 x^{2}+3 y^{2}+2 z^{2}+2 x y\\right)\\\\\n\t\\text{\tNow, }\\quad \\frac{\\partial V}{\\partial x}&=0 \\quad \\Rightarrow 6 x+2 y=0 \\quad \\Rightarrow y=-3 x\\\\\n\t\\frac{\\partial V}{\\partial y}&=0 \\quad \\Rightarrow 6 y+2 x=0 \\quad \\Rightarrow y=\\frac{-x}{3}\\\\\n\t\\frac{\\partial V}{\\partial z}&=0 \\quad \\Rightarrow z=0\\\\\n\t\\text{Now, }\\quad \\frac{\\partial^{2} V}{\\partial x^{2}}&=3 m \\omega^{2}>0 \\text{for all $x$}\\\\\n\t\\frac{\\partial^{2} V}{\\partial y^{2}}&=3 m \\omega^{2}>0\\text{ for all $y$}\\\\\n\t\\text{and }\\frac{\\partial^{2} V}{\\partial z^{2}}&=4>0\\text{ for all $z$}\n\t\\intertext{All these conditions tell us that equilibrium point is $(0,0,0)$, because $y=-3 x=-\\frac{x}{3}$ satisfies only $x=y=0$ So, the given potential is in the form of expansion about $(0,0,0)$ and the matrix $V_{i j}$ can be written just by inspection.}\n\tV &=\\frac{1}{2} m \\omega^{2}\\left(3 x^{2}+3 y^{2}+2 z^{2}+2 x y\\right) \\\\ &=\\frac{1}{2} m \\omega^{2}\\left[\\begin{array}{lll}x & y & z\\end{array}\\right]\\left[\\begin{array}{lll}3 & 1 & 0 \\\\ 1 & 3 & 0 \\\\ 0 & 0 & 2\\end{array}\\right]\\left[\\begin{array}{l}x \\\\ y \\\\ z\\end{array}\\right]\\\\\n\t\\text{\t\tbecause}\\quad\n\t&V=\\frac{1}{2}\\left(3 m \\omega^{2} x^{2}+3 m \\omega^{2} y^{2}+2 m \\omega^{2} z^{2}+m \\omega^{2} x y+m \\omega^{2} y x\\right) \\\\\n\t\\text{or,}\\quad&V=\\frac{1}{2}\\left(V_{11} x^{2}+V_{22} y^{2}+V_{33} z^{2}+V_{12} x y+V_{21} y x\\right)\\\\\n\t\\text{\tKinetic energy }T&=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}+\\dot{z}^{2}\\right)=\\frac{1}{2}\\left[\\begin{array}{lll}\\dot{x} & \\dot{y} & \\dot{z}\\end{array}\\right]\\left[\\begin{array}{lll}m & 0 & 0 \\\\ 0 & m & 0 \\\\ 0 & 0 & m\\end{array}\\right]\\left[\\begin{array}{l}\\dot{x} \\\\ \\dot{y} \\\\ \\dot{z}\\end{array}\\right]\\\\\n\t\\text{Now,}\n\t\\left|\\mathbf{V}-\\Omega^{2} \\mathbf{T}\\right|&=0\\quad \\text{where $\\Omega$ is normal mode freuency.}\\\\\n\t\\Rightarrow \\quad&\\left|\\begin{array}{ccc}3 m \\omega^{2}-\\Omega^{2} m & m \\omega^{2} & 0 \\\\ m \\omega^{2} & 3 m \\omega^{2}-\\Omega^{2} m & 0 \\\\ 0 & 0 & 2 m \\omega^{2}-\\Omega^{2} m\\end{array}\\right|=0\\\\\n\t\\Rightarrow \\quad\\left(2 \\omega^{2}-\\Omega^{2}\\right)&\\left[\\left(3 \\omega^{2}-\\Omega^{2}\\right)^{2}-\\omega^{4}\\right]=0 \\quad \\Rightarrow \\Omega_{1}^{2}=2 \\omega^{2}\\\\\n\t\\text{\tand }\\quad \\Omega^{2}&=3 \\omega^{2} \\pm \\omega^{2} \\quad \\Rightarrow \\Omega_{2}^{2}=2 \\omega^{2}\\text{ and }\\Omega_{3}^{2}=4 \\omega^{2}\n\t\\intertext{So, the frequencies are $\\omega \\sqrt{2}, \\omega \\sqrt{2}$ and $2 \\omega$}\n\t\\intertext{\tNote that frequencies are always positive, hence we shouldn't write $\\Omega_{1}=\\pm \\omega \\sqrt{2}$ etc.}\n\t\\end{align*}\n\\end{answer}\n\\item  The Lagrangian of a system is given by $L=\\frac{1}{2} m \\dot{q}_{1}^{2}+2 m \\dot{q}_{2}^{2}-k\\left(\\frac{5}{4} q_{1}^{2}+2 q_{2}^{2}-2 q_{1} q_{2}\\right)$ where $m$ and $k$ are positive constants. The frequencies of its normal modes are\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\sqrt{\\frac{k}{2 m}}, \\sqrt{\\frac{3 k}{m}}$\n\t\\task[\\textbf{b.}]$\\sqrt{\\frac{k}{2 m}}(13 \\pm \\sqrt{73})$\n\t\\task[\\textbf{c.}]$\\sqrt{\\frac{5 k}{2 m}}, \\sqrt{\\frac{k}{m}}$\n\t\\task[\\textbf{d.}]  $\\sqrt{\\frac{k}{2 m}}, \\sqrt{\\frac{6 k}{m}}$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\tL &=\\frac{1}{2} m \\dot{q}_{1}^{2}+2 m \\dot{q}_{2}^{2}-k\\left(\\frac{5}{4} q_{1}^{2}+2 q_{2}^{2}-2 q_{1} q_{2}\\right) \\\\ &=\\frac{1}{2} m \\dot{q}_{1}^{2}+\\frac{1}{2} 4 m \\dot{q}_{2}^{2}-\\frac{1}{2} k\\left(\\frac{5}{2} q_{1}^{2}+4 q_{2}^{2}-4 q_{1} q_{2}\\right) \\\\ \\hat{T} &=\\left(\\begin{array}{cc}m & 0 \\\\ 0 & 4 m\\end{array}\\right), \\hat{V}=\\left(\\begin{array}{cc}\\frac{5}{2} k & -2 k \\\\ -2 k & 4 k\\end{array}\\right) \n\t\\intertext{For frequencies of normal modes:}\n\t\\operatorname{det}\\left|\\omega^{2} \\hat{T}-\\hat{V}\\right|&=0\\\\\n\t\\left|\\begin{array}{cc}\\left(m \\omega^{2}-\\frac{5}{2} k\\right) & 2 k \\\\ 2 k & \\left(4 m \\omega^{2}-4 k\\right)\\end{array}\\right|&=0 \\Rightarrow 4\\left(m \\omega^{2}-k\\right) \\frac{\\left(2 m \\omega^{2}-5 k\\right)}{2}-4 k^{2}=0\\\\\n\t\\Rightarrow 2 m^{2} \\omega^{4}+5 k^{2}-7 k m \\omega^{2}-2 k^{2}&=0\\\\\n\t\\Rightarrow 2\\left(m \\omega^{2}\\right)^{2}-7 k\\left(m \\omega^{2}\\right)+3 k^{2}&=0\\\\\n\t\\Rightarrow m \\omega^{2}&=\\frac{7 k \\pm \\sqrt{49 k^{2}-24 k^{2}}}{4}=\\frac{7 k \\pm \\sqrt{49 k^{2}-24 k^{2}}}{4}\\\\&=\\frac{7 k \\pm 5 k}{4}=3 k, \\frac{k}{2}\\\\\n\t\\therefore \\omega&=\\sqrt{\\frac{3 k}{m}}, \\sqrt{\\frac{k}{2 m}}\n\t\\end{align*}\n\tCorrect answer is option \\textbf{(a)}\n\\end{answer}\n\\item Consider two masses m connected to each other and two walls by two springs as shown in figure.The three springs have the same sping constant k.If $x_1$ ,$x_2$ are generalized coordinates and displacement from mean position.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3cm,width=5cm]{problem2}\n\\end{figure}\n(a)Write down lagrangian of the system\\\\\n(b)Write down equation of motion\\\\\n(c)Write down secular equation and solve it for normal frequency.\n\\begin{answer}\n\t\\begin{align*}\n\t&\\text { (a) } L=\\frac{1}{2} m \\dot{x}_{1}^{2}+\\frac{1}{2} m \\dot{x}_{2}^{2}-\\frac{1}{2} k x_{1}^{2}-\\frac{1}{2} k\\left(x_{2}-x_{1}\\right)^{2}-\\frac{1}{2} k x_{2}^{2}\\\\\n\t&\\text { (b) } \\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{x}_{1}}\\right)-\\left(\\frac{\\partial L}{\\partial x_{1}}\\right)=0 \\Rightarrow m \\ddot{x}_{1}+k x_{1}-k\\left(x_{2}-x_{1}\\right)=0\\\\\n\t&\\frac{d}{d t}\\left(\\frac{\\partial L^{*}}{\\partial \\dot{x}_{2}}\\right)-\\left(\\frac{\\partial L}{\\partial x_{2}}\\right)=0 \\Rightarrow m \\ddot{x}_{2}+k x_{2}+k\\left(x_{2}-x_{1}\\right)=0 \\Rightarrow m \\ddot{x}_{2}+k x_{2}+k\\left(x_{2}-x_{1}\\right)\\\\\n\t&\\text { (c) } L=\\frac{1}{2} m \\dot{x}_{1}^{2}+\\frac{1}{2} m \\dot{x}_{2}^{2}-\\frac{1}{2} k x_{1}^{2}-\\frac{1}{2} k\\left(x_{2}-x_{1}\\right)^{2}-\\frac{1}{2} k x_{2}^{2}\\\\\n\t&T=\\frac{1}{2} m \\dot{x}_{1}^{2}+\\frac{1}{2} m \\dot{x}_{2}^{2}\\\\\n\t&T=\\left(\\begin{array}{ll}\n\tm & 0 \\\\\n\t0 & m\n\t\\end{array}\\right)\\\\\n\t&V=\\frac{1}{2} k x_{1}^{2}+\\frac{1}{2} k\\left(x_{2}-x_{1}\\right)^{2}+\\frac{1}{2} k x_{2}^{2}\\\\\n\t&V=\\frac{1}{2} k x_{1}^{2}+\\frac{1}{2} k\\left(x_{2}^{2}+x_{1}^{2}-2 x_{1} x_{2}\\right)+\\frac{1}{2} k x_{2}^{2}\\\\\n\t&V=\\frac{1}{2} k x_{1}^{2}+\\frac{1}{2} k\\left(x_{2}^{2}+x_{1}^{2}-x_{1} x_{2}-x_{2} x_{1}\\right)+\\frac{1}{2} k x_{2}^{2}\\\\\n\t&=k x_{1}^{2}+k x_{2}^{2}+\\frac{1}{2} k\\left(-x_{1} x_{2}-x_{2} x_{1}\\right)=\\left(\\begin{array}{cc}\n\t2 k & -k \\\\\n\t-k & 2 k\n\t\\end{array}\\right)\\\\\n\t&\\text { The secular equation is given by }\\\\\n\t&\\left[V-\\omega^{2} T\\right]=0, \\quad\\left(\\begin{array}{cc}\n\t2 k-\\omega^{2} m & -k \\\\\n\t-k & 2 k-\\omega^{2} m\n\t\\end{array}\\right)=0\\\\\n\t&\\left(2 k-\\omega^{2} m\\right)^{2}-k^{2}=0, \\omega_{1}=\\sqrt{\\frac{k}{m}},\\text{ which is normal frequency for oscillation and another value of}\\\\ &\\omega_{2}=\\sqrt{\\frac{3 k}{m}} \\text{which is first over-tone.}\n\t\\end{align*}\n\\end{answer}\n\\item Two identical particle of masses m are constrained to move on a horizontal loop .Two identical spring with constant k connected the mass and wrap around the loop.If $x_1$ and $x_2$ are displacements of first mass and second mass from equilibrium point.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=5cm]{problem 3}\n\\end{figure}\n(a)Write down lagrangian of the system \\\\\n(b)Write down equation of motion\\\\\n(c)Write down secular equation and solve it for normal frquency\n\\begin{answer}\n\t\\begin{align*}\n\t&\\text {(a) } l=\\frac{1}{2} m x_{1}^{2}+\\frac{1}{2} m \\dot{x}_{2}^{2}-\\left(\\frac{1}{2} k\\left(x_{2}-x_{1}\\right)^{2}+\\frac{1}{2} k\\left(x_{1}-x_{2}\\right)^{2}\\right)\\\\\n\t&\\text { (b) } \\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{x}_{1}}\\right)-\\left(\\frac{\\partial L}{\\partial x_{1}}\\right)=0 \\Rightarrow m \\ddot{x}_{1}+2 \\dot{k}\\left(x_{1}-x_{2}\\right)=0\\\\\n\t&\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial x_{2}}\\right)-\\left(\\frac{\\partial L}{\\partial x_{2}}\\right)=0 \\Rightarrow m \\ddot{x}_{2}+2 k\\left(x_{2}-x_{1}\\right)=0\\\\\n\t&\\text { (c) } L=\\frac{1}{2} m \\dot{x}_{1}^{2}+\\frac{1}{2} m \\dot{x}_{2}^{2}-\\left(\\frac{1}{2} k\\left(x_{2}-x_{1}\\right)^{2}+\\frac{1}{2} k\\left(x_{1}-x_{2}\\right)^{2}\\right)\\\\\n\t&T=\\frac{1}{2} m \\dot{x}_{1}^{2}+\\frac{1}{2} m \\dot{x}_{2}^{2} \\Rightarrow T=\\left(\\begin{array}{cc}\n\tm & 0 \\\\\n\t0 & m\n\t\\end{array}\\right)\\\\\n\t&I(x)=\\left(\\frac{1}{2} k\\left(x_{2}-x_{1}\\right)^{2}+\\frac{1}{2} k\\left(x_{1}-x_{2}\\right)^{2}\\right)=\\frac{1}{2} k\\left(2 x_{1}^{2}+2 x_{2}^{2}-4 x_{1} x_{2}\\right)\\\\\n\t&V=\\left(\\begin{array}{cc}\n\t2 k & -2 k \\\\\n\t-2 k & 2 k\n\t\\end{array}\\right)\\\\\n\t&\\left[V-\\omega^{2} T\\right]=0\\\\\n\t&\\left(\\begin{array}{cc}\n\t2 k-\\omega^{2} m & -2 k \\\\\n\t-2 k & 2 k-\\omega^{2} m\n\t\\end{array}\\right)=0\\\\\n\t&\\left(2 k-\\omega^{2} m\\right)^{2}-(2 k)^{2}=0\\\\\n\t&\\left(\\left(2 k-\\omega^{2} m\\right)+2 k\\right)\\left(\\left(2 k-\\omega^{2} m\\right)-2 k\\right)=0\\\\\n\t&\\omega=\\sqrt{\\frac{4 k}{m l}} \\text{is normal frequency corresponding to oscillation and} \\omega=0 \\text{corresponding\n\t\tto translation motion.}\n\t\\end{align*}\n\\end{answer}\n\\end{enumerate}", "meta": {"hexsha": "28dd8ae28b2979917d9adb3cdda930f46a6ff5dd", "size": 36935, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Classical Mechanics  -CSIR/chapter/small oscillations.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Classical Mechanics  -CSIR/chapter/small oscillations.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Classical Mechanics  -CSIR/chapter/small oscillations.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.2849915683, "max_line_length": 1398, "alphanum_fraction": 0.6449167456, "num_tokens": 14188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7277466616673052}}
{"text": "\\section{Developing Libraries with HOL4}\\label{sec:libraries}\n\nIn the previous section we have looked at a first, self-contained, example of a\nHOL4 proof.\nTo prove the closed form of the gaussian sum, we only needed to define a function\nand perform a straight-forward proof by induction.\nHowever, in larger developments it is common to split proofs into smaller\nlemmas that are used as part of a central, final theorem\\footnote{This is similar to how one would never write larger programs within the \\texttt{main} function. It is desirable to split up functionality into programs instead}.\n\nIn this section we describe how larger developments are performed with HOL4 by\nshowing the theorem that there is an infinite number of prime numbers, called\neuclid's theorem.\n\n\\subsection{Preamble}\nBefore starting a development in HOL4, it is recommended to declare dependencies\nand load theorems that come with the HOL4 theorem prover.\nWe do so by running\n\n\\begin{lstlisting}\nopen BasicProvers Defn HolKernel Parse Conv SatisfySimps Tactic monadsyntax\n     boolTheory bossLib arithmeticTheory;\n\nopen LassieLib arithTacticsLib;\n\nval _ = new_theory \"euclid\";\n\\end{lstlisting}\n\nThe first \\lstinline{open} loads a bunch of theories and tactics from the HOL4\ngit repository, whereas the second loads Lassie and the natural language\ndescriptions required for the proofs that we will perform.\nThe third line, tells HOL4 that we start a new theory, called ``euclid''.\nIn HOL4 speak, this is the analogous to defining an interface in Java, or a\nheader file in C.\nAll definitions and theorems are explicitly part of the interface of a theory.\nTo prevent errors, the file in which we store the theory has to be called\n\\lstinline{euclidScript.sml}.\nIf this correspondance between the file name and theory name is ignored,\nHOL4 will fail to build the theory later.\nAs in the previous section, we recommend implementing file \\lstinline{euclidScript.sml}\nin the directory \\texttt{\\$LASSIEDIR/examples}.\nWe load the jargon with \\lstinline{val _ = LassieLib.loadJargon \"Arithmetic\";}.\n\n\\subsection{Basic Definitions}\nOur overall goal is to prove the HOL4 equivalent of the informal statement that\n``there is an infinite number of prime numbers''.\nThe first concept that we need to define is thus what it means for a (natural)\nnumber to be a prime number.\n\nA number $n$ is called a prime number if it is only divisible by $1$ and $n$\nitself. Thus, we first define a predicate \\lstinline{divides} where\n\\lstinline{a divides b} if and only if \\lstinline{b} can be expressed as a\nmultiple of \\lstinline{a}:\n\n\\begin{lstlisting}\nset_fixity \"divides\" (Infix(NONASSOC, 450));\n\nDefinition divides_def:\n  (a divides b) = (? x. b = a * x)\nEnd\n\\end{lstlisting}\nThe first line declares \\lstinline{divides} as a new infix operator, like $+,-, \\ldots$\nNext, the \\lstinline{Definition}, \\lstinline{End} block defines \\lstinline{divides} as a\nbinary infix relation where \\lstinline{a divides b} is true, if and only if\nthere is an \\lstinline{x} such that \\lstinline{b} is the result of multiplying \\lstinline{a} with \\lstinline{x}.\n\nAlternatively, we could have defined \\lstinline{divides} as a function instead\nof an infix operation, as we did in \\autoref{sec:hol_ex1}.\nUsing it as an infix operation however makes it more obvious which number is\ndivided by which.\n\nHaving defined \\lstinline{divides} we use it to define a predicate\n\\lstinline{prime} which is true, if its argument is a prime number.\n\\begin{lstlisting}\nDefinition prime_def:\n  prime p = (p<>1 /\\ !x . x divides p ==> (x=1) \\/ (x=p))\nEnd\n\\end{lstlisting}\n\nThe left-hand side of the conjunction (\\lstinline{p <> 1}) explicitly excludes\nnumber 1 from being a prime number, and the right-hand side states the HOL4\nversion of \\lstinline{p} being prime if it can only be divided by $1$ and itself.\n\n\\subsection{Proving Infrastructural Lemmas}\n\nBefore proving euclid's theorem itself, we start by proving some infrastructural\nlemmas that will come in handy later.\n\\begin{lstlisting}\n\nTheorem DIVIDES_0:\n  ! x . x divides 0\nProof\n  nltac `[divides_def, MULT_CLAUSES] solves the goal.`\nQED\n\nTheorem DIVIDES_ZERO:\n  ! x . (0 divides x) = (x = 0)\nProof\n  nltac `[divides_def, MULT_CLAUSES] solves the goal.`\nQED\n\nTheorem DIVIDES_ONE:\n  ! x . (x divides 1) = (x = 1)\nProof\n  nltac `[divides_def, MULT_CLAUSES, MULT_EQ_1] solves the goal.`\nQED\n\nTheorem DIVIDES_REFL:\n  ! x . x divides x\nProof\n  nltac `[divides_def, MULT_CLAUSES] solves the goal.`\nQED\n\nTheorem DIVIDES_TRANS:\n  ! a b c . a divides b /\\ b divides c ==> a divides c\nProof\n  nltac `[divides_def, MULT_ASSOC] solves the goal.`\nQED\n\\end{lstlisting}\n\nTheorems \\lstinline{DIVIDES_0, DIVIDES_ZERO}, and \\lstinline{DIVIDES_ONE} show\nsimple base cases for predicate \\lstinline{divides}.\nAs these follow straight-forwardly from the definition, the Lassie proof is just\n\\lstinline{nltac `[divides_def, MULT_CLAUSES] solves the goal.`}, resp.\n\\lstinline{nltac `[divides_def, MULT_CLAUSES, MULT_EQ_-1] solves the goal.`}.\n\nSimilarly, one proves theorems about the relation between $+, *$ and $\\leq$ and\n\\lstinline{divides}:\n\\begin{lstlisting}\n\nTheorem DIVIDES_ADD:\n  ! d a b . d divides a /\\ d divides b ==> d divides (a + b)\nProof\n  nltac `[divides_def, LEFT_ADD_DISTRIB] solves the goal.`\nQED\n\nTheorem DIVIDES_SUB:\n  !d a b . d divides a /\\ d divides b ==> d divides (a - b)\nProof\n  nltac `[divides_def, LEFT_SUB_DISTRIB] solves the goal.`\nQED\n\nTheorem DIVIDES_ADDL:\n  !d a b . d divides a /\\ d divides (a + b) ==> d divides b\nProof\n  nltac `[ADD_SUB, ADD_SYM, DIVIDES_SUB] solves the goal.`\nQED\n\nTheorem DIVIDES_LMUL:\n  !d a x . d divides a ==> d divides (x * a)\nProof\n  nltac `[divides_def, MULT_ASSOC, MULT_SYM] solves the goal.`\nQED\n\nTheorem DIVIDES_RMUL:\n  !d a x . d divides a ==> d divides (a * x)\nProof\n  nltac `[MULT_SYM,DIVIDES_LMUL] solves the goal.`\nQED\n\nTheorem DIVIDES_LE:\n  !m n . m divides n ==> m <= n \\/ (n = 0)\nProof\n  nltac `rewrite [divides_def]. [] solves the goal.`\nQED\n\\end{lstlisting}\n\n\\subsection{Euclid's Theorem}\nHaving defined prime numbers, and after proving simple properties of\n\\lstinline{divides}, we next state euclid's theorem and start\nexploring its proof.\n\n\\begin{lstlisting}\nTheorem euclid:\n  !n . ?p . n < p /\\ prime p\nProof\n\nQED\n\\end{lstlisting}\n\nAfter starting the interactive proof with \\ekey{M-h g}, we can start exploring\nit with Lassie.\nThe textbook version of the proof is done by contradiction, so we perform the\nsame step in HOL4: \\lstinline{nltac `suppose not.`}.\nAfter running the tactic with \\ekey{M-h e} the REPL shows the following goal state:\n%\n\\begin{lstlisting}[frame=single, mathescape=true]\n> OK..\n1 subgoal:\nval it =\n\n    0.  $\\exists$ n. $\\forall$ p. n < p $\\rightarrow$ $\\neg$prime p\n   ------------------------------------\n        F\n\n   : proof\n\\end{lstlisting}\n\nThe first assumption starts with an existential quantifier, from which we can\nobtain the witness. Therefore we next call into the simplifier to automatically\ntake care of this with \\lstinline{nltac `simplify.`} leaving us with\n%\n\\begin{lstlisting}[frame=single, mathescape=true]\n> > > > > # # OK..\n1 subgoal:\nval it =\n\n    0.  $\\forall$ p. n < p $\\rightarrow$ $\\neg$prime p\n   ------------------------------------\n        F\n\n   : proof\n\\end{lstlisting}\n\nThe assumption now tells us that any natural number $p$ which is greater than\n$n$ cannot be prime.\nOn a high level, the goal is to derive a contradiction from this assumption by\nfinding a prime number that is bigger than $n$.\nAn integral part of this step is that every natural number greater than $1$ has\na prime factorization\\footnote{We have to exclude $1$ here because our definition of prime numbers explicitly ruled out $1$.}.\nBefore continuing the proof, we prove a theorem that for an arbitrary natural\nnumber $n$, there is a prime factor of that number.\nTo this end we first drop the current goal with \\ekey{M-h d} and start proving:\n%\n\\begin{lstlisting}\nTheorem PRIME_FACTOR:\n  !n . n <> 1 ==> ?p . prime p /\\ p divides n\nProof\n  LassieLib.nltac `\n    Complete Induction on 'n'.\n    rewrite [].\n    perform a case split for 'prime n'.\n    Goal 1. follows from [DIVIDES_REFL]. End.\n    Goal 1.\n      show '? x. x divides n and x <> 1 and x <> n' using (follows from [prime_def]).\n      follows from [LESS_OR_EQ, PRIME_2, DIVIDES_LE, DIVIDES_TRANS, DIVIDES_0].\n    End.`\n\\end{lstlisting}\n\nThe theorem can be immediately loaded by running \\ekey{M-h M-r} over the complete\ntext.\nHowever, we recommend stepping through the \\lstinline{nltac} steps one-by-one\nwith \\ekey{M-h e} after starting an interactive proof with \\ekey{M-h g}.\n\nOne particular thing to note here is that this is the first proof that\nexplicitly mentions subgoals in Lassie.\nAfter performing a case split on whether $n$ is prime or not\n(\\lstinline{perform a case split for 'prime n'.}) HOL4 leaves us with two\nsubgoals to prove:\n\n\\begin{lstlisting}[frame=single]\n> OK..\n2 subgoals:\nval it =\n\n    0.  $\\forall$ m. m < n $\\rightarrow$ m $\\neq$ 1 $\\rightarrow$ $\\exists$ p. prime p $\\wedge$ p divides m\n    1.  n $\\neq$ 1\n    2.  $\\neg$ prime n\n   ------------------------------------\n        $\\exists$ p. prime p $\\wedge$ p divides n\n\n    0.  $\\forall$ m. m < n $\\rightarrow$ m $\\neq$ 1 $\\rightarrow$ $\\exists$ p. prime p $\\wedge$ p divides m\n    1.  n $\\neq$ 1\n    2.  prime n\n   ------------------------------------\n        $\\exists$ p. prime p $\\wedge$ p divides n\n\n2 subgoals\n   : proof\n\\end{lstlisting}\n\nHere, the first subgoal ($\\exists \\texttt{p}. \\texttt{prime p} \\wedge \\texttt{p divides n}$)\nis solved first, with the natural language command \\lstinline{Goal 1}.\nAlternatively, we can say that we want to prove first the goal where \\texttt{prime n} holds with\n\\lstinline{Goal 'prime n'}.\n\nHaving shown the theorem \\lstinline{PRIME_FACTOR} we can go back to proving\nEuclid's theorem:\n\\begin{lstlisting}\nTheorem euclid:\n  !n . ?p . n < p /\\ prime p\nProof\n  nltac `suppose not. simplify.`\nQED\n\\end{lstlisting}\n\nAs a next step, we will obtain a prime factor of $n! + 1$, called $q$.\nFrom this we know that $q$ is prime and \\lstinline{q divides FACT n + 1}.\nAs $q$ is a prime number, we can derive that $q \\leq n$.\nWe obtain a contradiction by deriving that $q = 1$ from the fact that any number\nsmaller than $n$ is a divisor of $!n$, and theorem \\lstinline{DIVIDES_ADDL}.\nThe full proofscript becomes:\n\\begin{lstlisting}[mathescape=true]\nnltac `\n  suppose not. simplify.\n  we can derive 'FACT n + 1 <> 1' from [FACT_LESS, neq_zero].\n  thus PRIME_FACTOR for 'FACT n + 1'.\n  we further know '?q. prime q and q divides (FACT n + 1)'.\n  show 'q <= n' using [NOT_LESS_EQUAL].\n  show '0 < q' using [PRIME_POS] .\n  show 'q divides FACT n' using [DIVIDES_FACT].\n  show 'q=1' using [DIVIDES_ADDL, DIVIDES_ONE].\n  show 'prime 1' using (simplify).\n  [NOT_PRIME_1] solves the goal.`\n\\end{lstlisting}\n\nWe recommend stepping through each step one by one and observing the changes to\nthe proof.\n\nAfter finishing the proof the theory development is ended by putting\n\\lstinline{val _ = export_theory();} at the end of the file.\nThis directive tells HOL4 to export the defined functions and proven theorems\ninto a file \\texttt{euclidTheory.sml} which can be used by future developments.\nThe file \\texttt{euclidTheory.sig} gives an overview of the included theorems and\ndefinitions in a human readable format.\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"lassie-tutorial\"\n%%% End:\n", "meta": {"hexsha": "e4e9330014d4d6a39afc8645109122c42c31e32d", "size": 11395, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Manual/Lassie-Tutorial/libraries.tex", "max_stars_repo_name": "dwRchyngqxs/HOL", "max_stars_repo_head_hexsha": "3b1931c130fcab243da332adb2c1413c42c59cf9", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 492, "max_stars_repo_stars_event_min_datetime": "2015-01-07T16:36:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T22:18:48.000Z", "max_issues_repo_path": "Manual/Lassie-Tutorial/libraries.tex", "max_issues_repo_name": "dwRchyngqxs/HOL", "max_issues_repo_head_hexsha": "3b1931c130fcab243da332adb2c1413c42c59cf9", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 759, "max_issues_repo_issues_event_min_datetime": "2015-01-01T00:40:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T17:33:39.000Z", "max_forks_repo_path": "Manual/Lassie-Tutorial/libraries.tex", "max_forks_repo_name": "dwRchyngqxs/HOL", "max_forks_repo_head_hexsha": "3b1931c130fcab243da332adb2c1413c42c59cf9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 126, "max_forks_repo_forks_event_min_datetime": "2015-02-17T03:20:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T00:42:55.000Z", "avg_line_length": 35.7210031348, "max_line_length": 227, "alphanum_fraction": 0.7225976305, "num_tokens": 3254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.7277466546237332}}
{"text": "\\documentclass[a4paper,12pt]{article}\n\\usepackage{amsmath, amssymb, amsthm}\n\\usepackage{mathtools}\n\\usepackage{tabulary}\n\\usepackage{multirow}\n\n\\usepackage{polyglossia}\n\n\\title{Project Euler - Problem 6}\n\\date{}\n\\author{DestructHub}\n\n\\begin{document}\n\n\\maketitle\n\n\\section {Statement}\n\nThe sum of the squares of the first ten natural numbers is\n\n$$ 1^2 + 2^2 + \\ldots + 10^2 = 385 $$\n\nThe square of the sum of the first ten natural numbers is,\n\n$$ (1 + 2 + \\ldots + 10)^2 = 55^2 = 3025 $$\n\nHence the difference between the sum of the squares of the first ten natural\nnumbers and the square of the sum is $$ 3025 - 385 = 2640$$.\n\nFind the difference between the sum of the squares of the first one hundred\nnatural numbers and the square of the sum.\n\n\\section{Solution}\n\nWe can use two simple formulae:\n\n\\begin{align*}\n  1+2+\\ldots+n &= \\frac{n(n+1)}{2}\\\\\n  1^2+2^2+\\ldots+n^2 &= \\frac{n(n+1)(2n+1)}{6}\n\\end{align*}\n\n(They can be easily proved by Induction.)\n\nNow it is a matter of simple calculations:\n\n$$\\left(\\frac{n(n+1)}{2})^2\\right) - \\frac{n(n+1)(2n+1)}{6} = 5050^2-338350 = 25164150$$  \n\n\\end{document}\n\n%%% Compile with lualatex\n\n%%% Local Variables:\n%%% mode: latex\n%%% coding: utf-8-unix\n%%% fill-column: 80\n%%% End:\n", "meta": {"hexsha": "12747c5e67ffbbf64b1e88c41c919cd66109e337", "size": 1226, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Problem006/LaTeX/solution_1.tex", "max_stars_repo_name": "drocha87/ProjectEuler", "max_stars_repo_head_hexsha": "c18407448aa4f05484191a0df1380e34f2b8c5d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 167, "max_stars_repo_stars_event_min_datetime": "2015-08-12T19:32:03.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T12:26:43.000Z", "max_issues_repo_path": "Problem006/LaTeX/solution_1.tex", "max_issues_repo_name": "drocha87/ProjectEuler", "max_issues_repo_head_hexsha": "c18407448aa4f05484191a0df1380e34f2b8c5d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 153, "max_issues_repo_issues_event_min_datetime": "2016-02-16T02:05:31.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-06T15:35:51.000Z", "max_forks_repo_path": "Problem006/LaTeX/solution_1.tex", "max_forks_repo_name": "drocha87/ProjectEuler", "max_forks_repo_head_hexsha": "c18407448aa4f05484191a0df1380e34f2b8c5d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 84, "max_forks_repo_forks_event_min_datetime": "2015-08-12T20:54:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T05:14:53.000Z", "avg_line_length": 21.5087719298, "max_line_length": 90, "alphanum_fraction": 0.6827079935, "num_tokens": 418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8688267677469952, "lm_q1q2_score": 0.7277466453432182}}
{"text": "\\documentclass[11pt,a4paper]{report}\n\\usepackage{amsmath,amsfonts,amssymb,amsthm,epsfig,epstopdf,titling,url,array}\n\\usepackage{enumitem}\n\\usepackage{changepage}\n\\usepackage{graphicx}\n\\usepackage{caption}\n\\theoremstyle{plain}\n\\newtheorem{thm}{Theorem}[section]\n\\newtheorem{lem}[thm]{Lemma}\n\\newtheorem{prop}[thm]{Proposition}\n\\newtheorem*{cor}{Corollary}\n\\theoremstyle{definition}\n\\newtheorem{defn}{Definition}[section]\n\\newtheorem{conj}{Conjecture}[section]\n\\newtheorem{exmp}{Example}[section]\n\\newtheorem{exercise}{Exercise}[section]\n\\theoremstyle{remark}\n\\newtheorem*{rem}{Remark}\n\\newtheorem*{note}{Note}\n\\def\\changemargin#1#2{\\list{}{\\rightmargin#2\\leftmargin#1}\\item[]}\n\\let\\endchangemargin=\\endlist \n\\begin{document}\n\n\n\\section*{Socks}\nEvery morning when he wakes up, Moe reaches into his sock drawer and randomly picks two socks to wear. Each sock in the drawer has only one partner - i.e., he does not have multiple copies of any pair.\n\\begin{enumerate}[label=(\\alph*)]\n\\item If there are two pairs of socks in the drawer, what is the probability that his random grab results in a pair?\n\\item Let $n$ be the number of pairs of socks in the drawer.  Find a formula for $p(n)$ = the probability that 2 randomly chosen socks from among the $2n$ in the drawer match.\n\\end{enumerate}\n\\section*{Bonus}\n\\begin{enumerate}[label=(\\alph*)]\\addtocounter{enumi}{2}\n\\item Moe's coworkers get tired of seeing Moe come in with mismatched socks all the time, so they decide to buy him a second pair exactly like each pair that he has. So now he has $2n$ pairs of socks (so a total of $4n$ socks) and each sock now has three possible matches.  What is the formula for $p(n)$ under this assumption?\n\\item Moe's teammates are pleased with the results of the sock augmentation, but they find that most days Moe's socks still don't match.  Joe claims that if they just double down on the strategy of buying more rounds of copies of the original $n$ pairs, they will eventually reach the point where most days Moe's socks will match and in fact for any $p < 1$, there is a number of rounds after which the probability of a match each day is at least $p.$  Is Joe right? \n\\end{enumerate}\n\n\\newpage\n\\section*{Solution (part a)}\nGive a total of 4 socks in the drawer, there are ${4 \\choose 2} = 6$ 2-sock combinations that Moe can pull out. (Imagine you can tell all socks apart. When selecting two of them, Moe has 4 choices for the first one times 3 for the second, assuming the order is significant.  The order is not significant,  so you need to divide by the number of ways the two socks can be ordered, which is 2, so you get $({4 \\times 3})/2 = 6$.  This is how the general formula for ${n \\choose k} =$ the number of $k$ element subsets that can be selected from an $n$-element set is derived.)  Among these 6 combinations, 2 of them are pairs. Since all combinations are equally likely, the probability of Moe selecting a pair is $2/6 = 1/3.$\n\n\\section*{Solution (part b)}\nGiven $n$ pairs, there are $2n$ total socks to choose from, so there are ${2n \\choose 2} = \\frac{2n(2n - 1)}{2} = n(2n - 1)$ possible two-sock combinations that Moe can grab.  Since $n$ of these are pairs and all are again equally likely, it follows that $$p(n) = \\frac{n}{n(2n - 1)} = 1 / (2n - 1).$$\n\n\\section*{Solution (part c)}\nNow Moe has $4n$ total socks, so there are ${4n \\choose 2} = \\frac{4n(4n - 1)}{2}$ possible 2-sock combinations.  Now each of the $n$ duplicated pairs creates ${4 \\choose 2} = 6$ good combinations.  So the probability of a match is now $\\frac{6n}{\\frac{4n(4n - 1)}{2}} = \\frac{3}{4n - 1}.$\n\n\\section*{Solution (part d)}\nJoe is wrong. As the number of copies increases, probability of a match will increase, but it is bounded above by $1/n.$  This is easy to see using a simpler approach to parts a-c. Once Moe has selected one sock, the probability that he will end with a match equals the probability that his next selection is from the same pair. So for example in part c, that probability is (number of socks of the same kind) / (total number of remaining socks) $= 3/(4n-1)$.  So if $k$ is the number of copies, the probability of a match is $(2k - 1) / (2kn - 1).$\n \n\\end{document}\n\n", "meta": {"hexsha": "9f87f1bf212768aae08419d3ece17abffe555f7f", "size": 4186, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "socks/socks.tex", "max_stars_repo_name": "psteitz/problems", "max_stars_repo_head_hexsha": "c231561593ef7de6264c21d2c78d736866c1b341", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "socks/socks.tex", "max_issues_repo_name": "psteitz/problems", "max_issues_repo_head_hexsha": "c231561593ef7de6264c21d2c78d736866c1b341", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-03T21:08:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T21:08:11.000Z", "max_forks_repo_path": "socks/socks.tex", "max_forks_repo_name": "psteitz/problems", "max_forks_repo_head_hexsha": "c231561593ef7de6264c21d2c78d736866c1b341", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 80.5, "max_line_length": 722, "alphanum_fraction": 0.7360248447, "num_tokens": 1224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.9032942132122422, "lm_q1q2_score": 0.7277228858534464}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{tikz}\n\\setlength{\\parindent}{0pt}\n\n\\newtheorem*{theorem}{Theorem}\n\\newtheorem*{definition}{Definition}\n\\newtheorem*{lemma}{Lemma}\n\\newtheorem*{corollary}{Corollary}\n\\newtheorem{example}{Example}\n\\newtheorem*{trick}{Trick}\n\\newtheorem*{question}{Question}\n\n\\title{Lecture 9: Max-Min and Least Squares}\n\\author{}\n\\date{}\n\n\\begin{document}\n    \n\\maketitle\n\n\\section{Application of Partial Derivatives: Optimization Problem}\n\n\\subsection{Max-Min}\n\nOptimization problems refer to the tasks of finding the maximum or minimum point \nof a function. Here we focus on finding the maximum or minimum point of \nmultivariable functions, such as $f(x, y)$.\n\nAnother concept is local max/min point, which means the function value of this \npoint is greater/less than the function values of adjacent points, but it is not \nnecessarily the greatest or leaast function value in the function domain.\n\n\\begin{theorem}\n  If a point in a function $f$ is a local max/min point, then all of the partial \n  derivatives at this point are equal to 0.\n\n  Proof: \\\\\n  We will prove it by contradiction. Suppose there is a local max/min point in a \n  function $f(x_1, x_2, ..., x_n)$, and one of its partial derivative \n  $\\frac{\\partial f}{\\partial x_i}$ is not 0. According to the definition of \n  partial derivatives, in that direction the function values of the two adjacent \n  point are \n  \\begin{gather*}\n    f(x_1, x_2, ..., x_i + \\Delta x_i, ..., x_n) = f(x_1, x_2, ..., x_n) + \\frac{\\partial f}{\\partial x_i} \\Delta x_i \\\\\n    f(x_1, x_2, ..., x_i - \\Delta x_i, ..., x_n) = f(x_1, x_2, ..., x_n) - \\frac{\\partial f}{\\partial x_i} \\Delta x_i \\\\\n  \\end{gather*}\n  Therefore, one of them is less than the local max/min point and the other is \n  greater than the local max/min point. Hence, it is not a local max/min point.\n  There is a contradiction.\n\n  Therefore, it is proved that if a point in a function $f$ is a local max/min \n  point, then all of the partial derivatives at this point are equal to 0.\n\\end{theorem}\n\nTherefore, A point is a local max/min point \\\\\n$\\Rightarrow$ All partial derivatives at that point are 0 \\\\\n$\\iff$ The tangent plane at that point is horizontal \\\\\n$\\iff$ The point is a critical point.\n\n\\subsection{Critical Points}\n\n\\begin{definition}\n  A point is a critical point of a function $f$ if and only if all the partial \n  derivatives on this point are equal to 0.\n\\end{definition}\nFor a multivariable function with two independent variables $f(x, y)$, a point \n$(x_0, y_0)$ is a critical point if \n$\\frac{\\partial f}{\\partial x}(x_0, y_0) = 0$ and \n$\\frac{\\partial f}{\\partial y}(x_0, y_0) = 0$.\n\n\\begin{example}\n  Find all the critical points of the function \n  $f(x, y) = x^2 - 2xy + 3y^2 + 2x - 2y$.\n\n  Solution: \\\\\n  \\begin{gather*}\n    \\frac{\\partial f}{\\partial x} = 2x - 2y + 2 \\\\\n    \\frac{\\partial f}{\\partial y} = -2x + 6y - 2 \\\\\n  \\end{gather*}\n  For critical points, they should satisfy \n  \\begin{equation*}\n    \\begin{cases}\n      \\frac{\\partial f}{\\partial x} = 2x - 2y + 2 = 0 \\\\\n      \\frac{\\partial f}{\\partial y} = -2x + 6y - 2 = 0 \\\\\n    \\end{cases} \\\\\n  \\end{equation*}\n  Solving this linear system, the result is $(-1, 0)$. Therefore, there are only \n  one critical point for this function, which is $(-1, 0)$.\n\\end{example}\n\n\\subsection{Types of Critical Points}\n\nA critical point of a function $f$ can be \n\\begin{itemize}\n  \\item local maximum point\n  \\item local minimum point\n  \\item saddle point: a point on the surface of the graph of a function where \n    the slopes in orthogonal directions are all zero, but not a local extremum \n    of the function.\n\\end{itemize}\n\n\\begin{question}\n  Is there any other possibilities for a critical point of a multivariable \n  function? If not, how to prove it?\n\n  Answer: No, there is not. According to the definition of saddle points, all \n  critical points that are not local max or min points are classified as saddle \n  points.\n\n  The point here is that saddle points can be many different forms. Examples:\n  \\begin{itemize}\n    \\item The point $(0, 0)$ on the graph of the function $z = x^2 - y^2$.\n    \\item The point $(0, 0)$ on the graph of the function $z = x^2 + y^3$.\n  \\end{itemize}\n\\end{question}\n\nHow to determine the type of a critical point?\n\\begin{itemize}\n  \\item Test the second derivative (cover in the next lecture).\n  \\item Find the codomain of the function and compare the function value on the \n  critical point with the codomain.\n\\end{itemize}\n\n\\begin{example}\n  Find the type of the critical point $(-1, 0)$ of the function \n  $f(x, y) = x^2 - 2xy + 3y^2 + 2x - 2y$.\n\n  Solution: \\\\\n  The function value of the critical point $(-1, 0)$ is \n  \\begin{equation*}\n    \\begin{split}\n      f(-1, 0) &= (-1)^2 - 2 \\times (-1) \\times 0 + 3 \\times 0^2 + 2 \\times (-1) - 2 \\times 0 \\\\\n               &= 1 - 2 \\\\\n               &= -1 \\\\\n    \\end{split}\n  \\end{equation*}\n  To find the codomain of the function, we can transform its formula\n  \\begin{equation*}\n    \\begin{split}\n      f(x, y) &= x^2 - 2xy + 3y^2 + 2x - 2y \\\\\n              &= (x - y)^2 + 2y^2 + 2x - 2y \\\\\n              &= ((x - y)^2 + 2(x - y) + 1) + 2y^2 - 1 \\\\\n              &= (x - y + 1)^2 + 2y^2 - 1 \\\\\n    \\end{split}\n  \\end{equation*}\n  Therefore, it is apparent that the codomain of the function is $[-1, \\infty]$. \n  Hence, the critical point $(-1, 0)$ is the minimum point of the function.\n\\end{example}\n\n\\section{Example of Optimization Problems: Least Squares}\n\nGiven a series of discrete points $(x_1, y_1)$, $(x_2, y_2)$, ..., $(x_n, y_n)$, \nfind the \"best fit\" line $y = ax + b$.\n\nThe task is to find the best values of $a$ and $b$ in the line equation \n$y = ax + b$.\n\nWe can define a distance function about the line equation $y = ax + b$, and find \nproper values of $a$ and $b$ to minimize the distance function, in other words, \nfind the minimum point $(a_0, b_0)$.\n\n\\bigskip\n\nOne way to define the distance function about the line equation $y = ax + b$ is \nto use the total square deviation, where deviation means the vertical distance \nbetween an actual point and the line $y = ax + b$, described by the formula \n$y_i - (ax_i + b)$. This method is called \\textbf{least squares}.\n\nTherefore, the distance function is \n\\begin{gather*}\n  \\begin{split}\n    D &= (y_1 - ax_1 - b)^2 + (y_2 - ax_2 - b)^2 + ... + (y_n - ax_n - b)^2 \\\\\n      &= \\sum_{i=1}^{n}(y_i - ax_i - b)^2 \\\\\n  \\end{split} \\\\\n  \\frac{\\partial D}{\\partial a} = \\sum_{i=1}^{n}-2x_i(y_i - ax_i - b) \\\\\n  \\frac{\\partial D}{\\partial b} = \\sum_{i=1}^{n}-2(y_i - ax_i - b) \\\\\n\\end{gather*}\n\nTo find the minimum point, we need to solve the following system of equations:\n\\begin{gather*}\n  \\begin{cases}\n    \\frac{\\partial D}{\\partial a} = \\sum_{i=1}^{n}-2x_i(y_i - ax_i - b) = 0 \\\\\n    \\frac{\\partial D}{\\partial b} = \\sum_{i=1}^{n}-2(y_i - ax_i - b) = 0 \\\\\n  \\end{cases} \\\\\n\\end{gather*}\nwhich is a linear system of $a$ and $b$. After simplified, it becomes\n\\begin{gather*}\n  \\begin{cases}\n    (\\sum_{i=1}^{n}x_i^2)a + (\\sum_{i=1}^{n}x_i)b = \\sum_{i=1}^{n}x_iy_i \\\\\n    (\\sum_{i=1}^{n}x_i)a + nb = \\sum_{i=1}^{n}y_i \\\\\n  \\end{cases}\n\\end{gather*}\nTherefore, we can solve the linear system to get the critical points of the \ndistance function, and hence get the minimum point $(a_0, b_0)$.\n\n\\bigskip\n\nThe least squares method can be more general. First of all, it can be used to \napproximate any polynomial functions, since the deviation is a linear function \nof unknown parameters. For example,\n\\begin{gather*}\n  y = ax^2 + bx + c \\\\\n  d_i = y_i - ax_i^2 - bx_i - c \\\\\n\\end{gather*}\nSecond, for other functions, we can try to transform it into polynomial \nfunctions. A typical example is exponential functions:\n\\begin{gather*}\n  y = ce^{ax} \\\\\n  \\ln y = ax + \\ln c \\\\\n  d_i = \\ln y_i - ax_i - \\ln c \\\\\n\\end{gather*}\n\n\\end{document}", "meta": {"hexsha": "242850aa74af35be1dd11b981b66d06965f6b44a", "size": 7890, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture9.tex", "max_stars_repo_name": "jinxinwangstd/multivariable-calculus-mit", "max_stars_repo_head_hexsha": "d165ef6ff085fafd0fb89b8027fc5f5e0dbfa1e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lecture9.tex", "max_issues_repo_name": "jinxinwangstd/multivariable-calculus-mit", "max_issues_repo_head_hexsha": "d165ef6ff085fafd0fb89b8027fc5f5e0dbfa1e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture9.tex", "max_forks_repo_name": "jinxinwangstd/multivariable-calculus-mit", "max_forks_repo_head_hexsha": "d165ef6ff085fafd0fb89b8027fc5f5e0dbfa1e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.3594470046, "max_line_length": 120, "alphanum_fraction": 0.6600760456, "num_tokens": 2528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.9032941982430049, "lm_q1q2_score": 0.7277228737937471}}
{"text": "% !TEX root = as_grf_sopt.tex\n\n\\newcommand{\\cG}{\\mathcal{G}}\n\\newcommand{\\cH}{\\mathcal{H}}\n\\newcommand{\\bv}{\\mathbf{v}}\n%\\newcommand{\\bk}{\\mathbf{k}}\n%\\newcommand{\\bK}{\\mathbf{K}}\n\\newcommand{\\bc}{\\mathbf{c}}\n\\newcommand{\\bff}{\\mathbf{f}}\n\\newcommand{\\bSigma}{\\boldsymbol{\\Sigma}}\n\\newcommand{\\bomega}{\\boldsymbol{\\omega}}\n\n\n\n\nThe database where active search is performed is given as a graph $\\cG$ with known structure (edge connections). The edge connections are nonnegative and we use $\\bA$ to represent the adjacency matrix of $\\cG$, such that $A_{ij}\\geq0, \\forall i,j$. Let \n$\\mathcal{V}=\\{v_1,\\dotsc,v_n\\}$ denote the set of all nodes in $\\cG$.\nFrom $\\bA$ we can derive a graph Laplacian matrix, \n$\\cLap = \\bD - \\bA$, \nwhere $\\bD=\\diag(\\bA\\cdot\\mathbf{1})=\\diag(\\deg(v_1),\\dotsc,\\deg(v_n))$.  \n%A normalized Laplacian is defined to be $\n%\\widetilde{\\cLap} = \\bD^{-\\frac{1}{2}} \\cLap \\bD^{-\\frac{1}{2}} \n%= \\bI - \\bD^{-\\frac{1}{2}} \\bA \\bD^{-\\frac{1}{2}} .\n%$\n\nEvery node $v$ in our graph holds one reward value\nwe denote as $f(v)$, indicating whether the node is the search target. The reward is unknown at first and can be revealed only when it is queried explicitly. For mathematical benefits, we relax the reward to be a real value and introduce a Gaussian noise to its observation, as\n\\begin{equation}\n\ty(v)=f(v)+\\epsilon, \\;{\\rm where}\\; \\epsilon\\sim\\mathcal{N}(0,\\sigma_n^2).\n\t\\label{eq:observation}\n\\end{equation}\n\n\nSimilar to bandit problems, querying a node also means collecting the true reward of that node.\nOur goal is to design a query strategy, \nwhich interactively generates a query sequence $\\bv_t = (v_1,\\dotsc,v_t)^\\top$ without any repeated selections, in order \nto maximize the cumulative reward \n\\begin{equation}\n\tF_T = \\sum_{t=1}^T f(v_t).\n\\end{equation} \n\nThe cumulative reward is always upper-bounded by the optimal strategy with full knowledge of the true rewards on all the nodes. Let $\\bv^*_t=(v^*_1,\\dotsc,v^*_t)$ to be the optimal query sequence (without repeated selections),\nour analysis in Theorem~\\ref{thm:as_regret} (Section~\\ref{sec:regret}) bounds the cumulative regret between our strategy and the optimal strategy,\n\\begin{equation}\n\tR_T = \\sum_{t=1}^T f(v^*_t) - f(v_t).\n\\end{equation}\n\n\n\nThe above characterizes an active search problem, provided that the values of $f(v)$ are binary and the sequences $\\bv_t$ and $\\bv_t^*$ do not allow repeated selections. \nOtherwise, \nthe above can also model a multi-armed bandit problem\nif we relax $f(v)$ to be real and $\\bv_t$ and $\\bv_t^*$ to allow repeated selections. \nIn fact, our formulation discusses them together, providing analysis to the slightly more rigorous active search modeling except that $f(v)$ is relaxed to real values.\n\n\n% the cumulative reward (or regret), provided that the values of $f(v)$ are binary, resemble active search recalls of the positives (or its sub-optimality in this objective). Also, particular to our active search application, the sequences $\\bv_t$ and $\\bv_t^*$ do not allow duplicated selections. \n% Except for these two differences, $F_T$ and $R_T$ are the same as  in ordinary bandit problems.\n\nIn our notations, bold letters indicate vectors or matrices, while light letters without subscripts mean functions and light letters with subscripts represent scalars or specific elements. $t$, $\\tau$, and $T$ are time indices, which when applied as subscripts, always mean the selection or model at that time step. Other letters as subscripts, such as $i,j,n$, always mean the natural indices. %In case of confusions, brackets and superscripts are applied to time indices.\n\n\n\\subsection{GAUSSIAN RANDOM FIELD PRIOR}\nA key assumption in this work is that the reward values, or the target labels, are constrained \nby the graph structure in a non-trivial way. Otherwise,  \nthe input graph provides little information about the reward function, making active search \nextremely difficult. More specifically,  \nwe assume that the reward values of all the nodes in the graph, \ncollectively denoted as a vector  \n$\\bff\\in\\mathbb{R}^N$, are random variables distributed jointly as  \n%are generated with respect to the graph adjacency matrix, in that there is always a bigger probability for connected nodes to share similar values, as\n\\begin{align}\n\t \\log \n\tp(\\bff) \n\t% &\\propto\n\t& \\simeq\n\t% \\exp\\mathopen{}\\left(\n\t\t-\\sum_{i=1}^N\\sum_{j=1}^N \\frac{A_{ij}(f_i-f_j)^2}{2} -   \\sum_{j=1}^N  \\frac{\\omega_0 (f_j-\\mu_0)^2}{2}\n\t% \\right)\n\t,\n\t\\nonumber\n\t\\\\\n\t\\mbox{i.e., }\\;\n\t\\bff &\\sim \\mathcal{N}\\mathopen{}\\left(\n\t\t\\bmu_0 = \\mu_0\\cdot\\bone,\\; \n\t\t\\bC_0 = \\left(\\cLap + \\omega_0 \\bI\\right)^{-1}\n\t\\right),\n\t\\label{eq:generative}\n\\end{align}\nwhere %is the vector concatenation of the reward values of all the nodes in the graph,\n$\\mu_0$ is a prior mean,\nand\n$\\omega_0 > 0$ is a regularization parameter. \nAccording to this probabilistic model, it is more likely for connected nodes to share similar values than not.\nDefine the initial covariance matrix as, $\\bC_0 = \\left(\\cLap + \\omega_0 I\\right)^{-1}$, and denote $\\widetilde{\\cLap}_0=\\cLap+\\omega_0\\bI$.\nThe above prior model is also known as \\textbf{Gaussian random fields (GRFs)}.\n%Equivalently, we can replace $\\cLap$ with $\\widetilde{\\cLap}$ to assume the generation model, \\eqref{eq:generative}, from a normalized graph Laplacian.%\n%\\todo{many things break.}\n\n\n%%%%%%%%%%\n\\subsection{POSTERIOR INFERENCE}\n\nAssume the nature draws one sample from the prior model, \\eqref{eq:generative}, and we use query observations, \\eqref{eq:observation}, to converge to that particular draw \nby performing posterior inference conditioned on the history, \n\\begin{equation*}\n\t\\cH_t = \\{(v_\\tau, y_\\tau)\\}_{\\tau=1}^t\n\t= \\{\\bv_t, \\by_t\\},\n\\end{equation*}\nwhich allows us to update the posterior distribution as,\n\\begin{equation*}\n\t\\log p(\\bff\\mid\\mathcal{H}_t) \\simeq\n\t - \\frac{1}{2}(\\bff-\\bmu_0)^\\top \\widetilde{\\cLap}_0 (\\bff-\\bmu_0) \n\t- \\sum_{\\tau=1}^t \\frac{(y_\\tau-f_{v_\\tau})^2}{2\\sigma_n^2}.\n\\end{equation*}\nNotice that the prior distribution and likelihood model form Gaussian conjugate pairs. Denote the posterior distribution as, \n$\n\\bff \\mid \\cH_t \\sim \\mathcal{N}(\\bmu_t, \\bC_t).\n$\nTo some readers, it is easier to express $\\bmu_t$ and $\\bC_t$ using the prior \\emph{precision} matrix, as\n\\begin{equation}\n\t\\bmu_t = \\bC_t\n\t\\Bigl(\\widetilde{\\cLap}_0\\bmu_0 +  \\sum_{\\tau=1}^t \\frac{y_\\tau \\be_{v_\\tau} }{\\sigma_n^2}\\Bigr),\n\t\\,\\,\\;\n\t\\bC_t^{-1} = \\widetilde{\\cLap}_0 + \\frac{1}{\\sigma_n^2}\\mathbf{H}_t\n\t\\label{eq:post_prec}\n\\end{equation}\nwhere $\\be_{v_\\tau}=(0,\\dotsc,0,1,0,\\dotsc,0)^\\top$ is an indicator vector of index $v_\\tau$ and $\\mathbf{H}_t$\n% ={\\rm diag}\\bigl(\\mathbf{h}_t=\\sum_{\\tau=1}^t \\be_{v_\\tau}\\bigr)\\in\\mathbb{R}^{n\\times n}$ \nis a diagonal matrix of index counts from $\\bv_t$, whose $k$th diagonal element is $\\sum_{\\tau=1}^t e_{v_\\tau}(v_k)$. \n\n\nHowever, for convenience in later descriptions and to connect to \\textbf{ Gaussian Process (GP) } literature \\citep{gpml}, we also use the prior \\emph{covariance} matrix to express the posterior distribution, as,\n\\begin{align}\n\t\\begin{split}\n\t\t&\\mu_t(v) = \\mu_0(v) + \\bc_{\\bv_t v}^\\top (\\bC_{\\bv_t\\bv_t} + \\sigma_n^2 \\bI)^{-1} (\\by_t - \\bmu_{\\bv_t}),\n\t\t\\\\\n\t\t&\\! C_t(v,v') = C_0(v,v') - \\bc_{\\bv_t v}^\\top (\\bC_{\\bv_t\\bv_t} + \\sigma_n^2 \\bI)^{-1} \\bc_{\\bv_t v'},\n\t\\end{split}\n\t\t\\label{eq:var_update}\n\t% &\\mu_t(v) = \\mu_0(v) + \\bc_{\\bv_t v}^\\top (\\bC_{\\bv_t\\bv_t} + \\sigma_n^2 \\bI)^{-1} (\\by_t - \\bmu_{\\bv_t}),\n\t% \\label{eq:mean_update}\n\t% \\\\\n\t% &\\! C_t(v,v') = C_0(v,v') - \\bc_{\\bv_t v}^\\top (\\bC_{\\bv_t\\bv_t} + \\sigma_n^2 \\bI)^{-1} \\bc_{\\bv_t v'},\n\t% \\label{eq:var_update}\n\\end{align}\nwhere the matrices can all be defined in terms of the prior:\n\\begin{align*}\n\t\\bc_{\\bv_t v} &= (C_0(v_1,v) ,\\cdots, C_0(v_t,v))^\\top\\\\ \n\t\\bC_{\\bv_t \\bv_t} &= \\bigl( C_0(v_\\tau,v_{\\tau'}) \\bigr)_{\\tau,\\tau'=1}^t \\\\\n\t\\bmu_{\\bv_t} &= (\\mu_0(v_1),\\cdots, \\mu_0(v_t))^\\top.\n\\end{align*}\n\nThe above update rules also applies to any time interval that starts with $t_0$, by replacing prior models (variables with subscript ``$0$'') with the model at time $t_0$.\n\nDefine simple notations for correlation coefficients and standard deviations from the covariance matrix, \n$\n\tC_t(v,v') = \\rho_t(v,v')\\sigma_t(v)\\sigma_t(v'),\n$\nwhich implies that $\\sigma_t^2(v) = C_t(v,v)$.\nDefine $\\bc_t(v)$ to be the column of $\\bC_t$ corresponding to node $v$.\n\n\n\n\n%\\subsection{Connection to Spectral Bandits}\n%\n%\\cite{valko2014spectral} gave another interpretation they called spectral bandits. This interpretation uses spectral decomposition of graph Laplacian, $\\cLap$, and works in the eigen-space. We will show that the inference rules are fundamentally similar to what we described above, which establishes connections to conventional linear bandit problems.\n%\n%Let eigen-decomposition of the graph Laplacian to be, \n%$\\cLap=\\bQ\\bLam_\\cLap \\bQ^\\top$, \n%where \n%$\\bQ = \\begin{pmatrix} \\bx_1,\\dotsc,\\bx_n\\end{pmatrix}^\\top$\n% is an orthogonal matrix and \n%$\\bLam$\n%is the diagonal concatenation of eigen-values of $\\cLap$,\n% such that \n%% \\begin{equation}\n%$\t\\bC_0(v,v') = \\bx_v^\\top \\left( \\bLam_\\cLap + \\omega_0 \\bI\\right)^{-1} \\bx_{v'}.\n%$\n%%\t\\label{eq:eigen}\n%%\\end{equation} \n%Define $\\bLam_0 = \\bLam_\\cLap + \\omega_0\\bI$. Notice that $\\bx_j$s are not eigen-vectors, but rather defined for notation simplicity. Nonetheless, $\\{\\bx_j\\in\\mathbb{R}^n : j=1,\\dotsc,n\\}$ are still orthogonal.\n%\n%\n%With the spectral approach, a true loading vector, $\\balpha\\in\\mathbb{R}^n$, is generated with prior, $ \\balpha\\sim\\mathcal{N}(0, \\bLam_0^{-1})$. This is equivalent to $\\bff = \\bQ \\balpha$ and $f(v) = \\bx_v^\\top \\balpha$ with our prior.\n%\n%The observations are still on the nodes, as \n%$\n%y(v) = \\bx_v^\\top \\balpha + \\epsilon, \\epsilon\\sim\\mathcal{N}(0, \\sigma_n^2).\n%$\n%With history $\\cH_t=\\{\\bv_t, \\by_t\\}$, the posterior becomes,\n%%\n%%\\begin{align*}\n%$\t\\balpha_t \\sim \\mathcal{N}(\\bm_t, \\bLam_t^{-1}), \n%$\n%with\n%$\t \\bLam_t = \\frac{1}{\\sigma_n^2}\\bX_t^\\top \\bX_t + \\bLam_0,\n%$\n%$\t\\bm_t = \\frac{1}{\\sigma_n^2} \\bLam_t^{-1}\\bX_t^\\top \\by_t,\n%$\n%%\\end{align*}\n%where \n%$\\bX_t=\\begin{pmatrix}\\bx_{v_1},\\dotsc,\\bx_{v_n}\\end{pmatrix}^\\top$ \n%and \n%$\\by_t = \\begin{pmatrix}y_1,\\dotsc, y_t\\end{pmatrix}^\\top$.\n%\n%The posterior inference is also consistent with our \\textsc{grf} model, \n%by trivial applications of Schur complement to verify that \n%$\n%\t\\bQ \\bLam_t^{-1} \\bQ^\\top \n%\t= \\bC_t \n%$\n%and\n%$\t\\bQ\\bm_t\n%\t=\n%\t\\bmu_t.\n%$\n% (Appendix~\\ref{app:sec:spectral_equivalence}).\n", "meta": {"hexsha": "4a2d5ed35f077cbc01e51d728b302f0728c30499", "size": 10454, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "texts/sec_gp_graph.tex", "max_stars_repo_name": "AutonlabCMU/active-search-gp-sopt", "max_stars_repo_head_hexsha": "45d75dc0fe33d3d68784c30ba7f6ecd7b1718c31", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-10-23T03:53:13.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-23T03:53:13.000Z", "max_issues_repo_path": "texts/sec_gp_graph.tex", "max_issues_repo_name": "AutonlabCMU/active-search-gp-sopt", "max_issues_repo_head_hexsha": "45d75dc0fe33d3d68784c30ba7f6ecd7b1718c31", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "texts/sec_gp_graph.tex", "max_forks_repo_name": "AutonlabCMU/active-search-gp-sopt", "max_forks_repo_head_hexsha": "45d75dc0fe33d3d68784c30ba7f6ecd7b1718c31", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-12-22T23:55:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-14T15:33:27.000Z", "avg_line_length": 47.5181818182, "max_line_length": 473, "alphanum_fraction": 0.6983929596, "num_tokens": 3541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874624, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7276885971467432}}
{"text": "\\paragraph{Skewness} indicates asymmetry. There are 3 cases:\n\\begin{enumerate}[noitemsep,nolistsep]\n  \\item $sk = 0$ the sample is symmetric\n  \\item $sk > 0$ the sample is heavier on the right\n  \\item $sk < 0$ the sample is heavier on the left\n\\end{enumerate}\n\n\\noindent The direction of inequality symbol points where the tail is.\n\n\\paragraph{Kurtosis} or so-called ``peakedness''.\n", "meta": {"hexsha": "4aabc33a971da1675cff0b7c23f1a0b1b651e22e", "size": 383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_2e_measures_shape.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_stars_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs_2e_measures_shape.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_issues_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs_2e_measures_shape.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_forks_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.8181818182, "max_line_length": 70, "alphanum_fraction": 0.7415143603, "num_tokens": 112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7276885970707564}}
{"text": "% -*- root: Main.tex -*-\n\\section{SVD}\n$\\mathbf{A} = \\mathbf{U} \\mathbf{D} \\mathbf{V}^\\top = \\sum_{k=1}^{\\operatorname{rank}(\\mathbf{A})} d_{k,k} u_k (v_k)^\\top$\\\\\n$\\mathbf{A} \\in \\mathbb{R}^{N \\times P}, \\mathbf{U} \\in \\mathbb{R}^{N \\times N}, \\mathbf{D} \\in \\mathbb{R}^{N \\times P}, \\mathbf{V} \\in \\mathbb{R}^{P \\times P}$\\\\\n$\\mathbf{U}^\\top \\mathbf{U} = I = \\mathbf{V}^\\top \\mathbf{V}$ ($\\mathbf{U}, \\mathbf{V}$orthonormal)\\\\\n$\\mathbf{U}$ columns are eigenvectors of $\\mathbf{A} \\mathbf{A}^\\top$, $\\mathbf{V}$ columns are eigenvectors of $\\mathbf{A}^\\top \\mathbf{A}$, $\\mathbf{D}$ diagonal elements are singular values.\\\\\n$(\\mathbf{D}^{-1})_{i,i} = \\frac{1}{\\mathbf{D}_{i, i}}$ (don't forget to transpose)\n\n\\begin{inparaenum}[\\color{red}1.]\n\t\\item calc $\\mathbf{A}^\\top \\mathbf{A}$.\n\t\\item calc EVs of $\\mathbf{A}^\\top \\mathbf{A}$, the $\\sqrt{}$ in desc. order are diag. of $\\mathbf{D}$.\n\t\\item calc eigenvecs of $\\mathbf{A}^\\top \\mathbf{A}$ using EVs resulting in cols of $\\mathbf{V}$.\n    \\item calc missing matrix: $\\mathbf{U} = \\mathbf{A} \\mathbf{V} \\mathbf{D}^{-1}$\n\t\\item normalize each col of $\\mathbf{U}$ and $\\mathbf{V}$.\n\\end{inparaenum}\n\nNb nonzero singular vals = rank(A). First r cols of U basis of C(A), last n - r cols of V basis of N(A). \n$\\lambda_i = \\sigma_i^2$ for square symmetric matrix A.\nSVD construction: $v_i = arg max_w ||Bw|| = \\sigma_i $, s.t. $||w|| = 1$, $u_i = \\frac{1}{\\sigma_i} B_i v_i$. $B_0 = A, B_{i+1} = B_i - \\sigma_i u_i v_i^T$\n\n\n\\subsection*{Low-Rank approximation}\nUsing only $K$ largest eigenvalues and corresponding eigenvectors. $\\tilde{\\mathbf{A}}_{i, j} = \\sum_{k=1}^K \\mathbf{U}_{i, k} \\mathbf{D}_{k,k} \\mathbf{V}_{j, k} = \\sum_{k=1}^K \\mathbf{U}_{i, k} \\mathbf{D}_{k,k} (\\mathbf{V}^\\top)_{k, j}$.\n\n\\subsection*{Eckart-Young Theorem}\n$\\min_{rank(B)=K} ||A-B||_F^2 = ||A-A_k||_F^2 = \\sum_{r=k+1}^{rank(A)} \\sigma_r^2$\n$\\min_{rank(B)=K} ||A-B||_2 = ||A-A_k||_2 = \\sigma_{k+1}$\n\n", "meta": {"hexsha": "a4dd7f6458284ec1b202cd6ccf0b4e30244a5f64", "size": 1926, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SVD.tex", "max_stars_repo_name": "phil9987/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "6c4986f399ca40c2270b8fc01150a69f89650db7", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SVD.tex", "max_issues_repo_name": "phil9987/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "6c4986f399ca40c2270b8fc01150a69f89650db7", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SVD.tex", "max_forks_repo_name": "phil9987/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "6c4986f399ca40c2270b8fc01150a69f89650db7", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.4137931034, "max_line_length": 238, "alphanum_fraction": 0.6147455867, "num_tokens": 824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7276672939781185}}
{"text": "\\section{Numerical integrations}\n\\label{iso_section:numerical_integration}\n\\paragraph{}\nWhen computing the coefficient matrix (Eq.~\\ref{lr_eq:sbfem_coe_matrix}) in SBFEM , numerical integrations tends to be overwhelmingly preferred over the mathematical deduction.\nThe reason behind lies in the flexibility of the numerical method and that deduction of exact integrations scheme to any given shape functions may not be feasible. \nDue to the fact that the polynomials are adopted as the shape function, the numerical integration methods such as Legendre Quadrature or Gauss Quadrature provides possibility for an exact integration numerically.\nAn integration quadrature is normally defined as followed:\n    \\begin{equation}\n        \\int_{-1}^{1}\n        f(x)dx \n        = \\sum_{i=1}^n\n        a_i f(x_i)\n    \\label{iso_eq:numerical_integration}\n    \\end{equation}\n%\nThe integration of any targeted polynomial function defined on $[-1,1]$ can be explicitly expressed as series.\nA set of integration points $\\left\\{ x_1, x_2, \\dots, x_n \\right\\} \\in \\left[-1,1\\right]$ and the corresponding weight $\\left\\{ a_1, a_2, \\dots, a_n \\right\\} \\in \\mathbb{R}$ determined from the integration quadrature can be adopted to perform an exact integration on the given function.\n\\paragraph{}\nAlthough shape functions used in NURBS are not polynomials, they can be separated into several spans within which the basis functions are rational polynomials.\nBased on this property, the numerical integration quadrature on each of these spans can be applied to achieve a reasonably accurate result.\nIn other words, the NURBS curve with a knot vector of \n$[ \n    \\underbrace{-1,-1,\\dots,-1}_{p+1}, \n    u_0,\\dots,u_n, \n    \\underbrace{1,1,\\dots,1 }_{p+1}\n]$\ncan be integrated as\n\\begin{equation}\n    \\int_{-1}^{1} R(u) du = \\int_{-1}^{u_0} R(u)du + \n                            \\int_{u_0}^{u_1} R(u)du + \\dots +\n                            \\int_{u_n}^1 R(u)du\n\\label{iso_eq:numerical_integration_piecewise}\n\\end{equation}\n%\nSince the rational polynomials instead of the non-rational ones are utilized as the shape functions in the NURBS, the difference between the outputs from Eq.~\\ref{iso_eq:numerical_integration_piecewise} and the analytical solution will be so large that can not be regarded as machine error.\nBased on Eq.~\\ref{iso_eq:rational_basis_function} we can conclude that the basis functions constructed by rational polynomials become non-rational if and only if the weight vector is identical i.e. $\\left\\{ w \\right\\} = \\left[ 1,1,\\dots,1 \\right]$ after normalization.\nThat indicates the error of numerical integration will be decreased when the weight vector of the NURBS curve becomes more uniform as the basis functions are more close to the non-rational polynomials.\nIn order to achieve this target, the knot insertion or the order elevation introduced in Section~\\ref{lr_sec:nurbs_knot_ins} and Section~\\ref{lr_sec:nurbs_order_ele} can be used.\n", "meta": {"hexsha": "88b34af7b9c0d8db1adf5b0592e5ca82f90142aa", "size": 2941, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "isogeometric_sbfem/nurbs_numerical_integrations.tex", "max_stars_repo_name": "fa93hws/thesis", "max_stars_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-30T12:14:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-30T12:14:47.000Z", "max_issues_repo_path": "isogeometric_sbfem/nurbs_numerical_integrations.tex", "max_issues_repo_name": "fa93hws/thesis", "max_issues_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "isogeometric_sbfem/nurbs_numerical_integrations.tex", "max_forks_repo_name": "fa93hws/thesis", "max_forks_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 75.4102564103, "max_line_length": 290, "alphanum_fraction": 0.7521251275, "num_tokens": 749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028205, "lm_q2_score": 0.8824278757303677, "lm_q1q2_score": 0.7275281939250874}}
{"text": "\n\\subsection{Differentiable transition maps}\n\n\\subsubsection{Transition map recap}\n\nGiven two charts with an overlap, we have a transition mapping between the two charts of the overlap, where the mapping corresponds to a position on the manifold.\n\n\\subsubsection{Differentiable transition maps}\n\nIf this mapping is differentiable, we have a differentiable manifold.\n\n\\subsubsection{Smooth manifolds}\n\nIf transition maps are smooth (\\(C^\\infty \\)) then the manifold is smooth.\n\n", "meta": {"hexsha": "24c98de9d878288f2b93b917ea320e537cdad740", "size": 477, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/manifoldsDifferentiable/01-01-differentiable.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/manifoldsDifferentiable/01-01-differentiable.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/manifoldsDifferentiable/01-01-differentiable.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.8125, "max_line_length": 162, "alphanum_fraction": 0.8008385744, "num_tokens": 99, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.7931059487389966, "lm_q1q2_score": 0.7275181979045591}}
{"text": "\\section{Quantum gases}\nGrand canonical ensemble.\nSecond quantization. $\\ket{n_1,n_2,\\ldots}$.\n\nUpper sign is for bosons,\nlower sign is for fermions.\nThe grand potential is\n\\begin{align}\n    \\Omega &= \\pm gk_B T V\n    \\int \\frac{d^3k}{(2\\pi)^3}\n    \\ln \\left[ \n    1 \\mp e^{-\\beta\\left( \n    \\frac{\\hbar^2 k^2}{2M} - \\mu\n    \\right)}\n    \\right]\n\\end{align}\nand then the number density is\n\\begin{align}\n    \\frac{N}{V} &= - \\frac{1}{V}\\left.\\frac{\\partial \\Omega}{\\partial\n    \\mu}\\right|_{T,V}\\\\\n    &=\n    g \\int \\frac{d^3k}{(2\\pi)^3}\n    \\frac{1}{e^{\\beta\\left( E_k - \\mu \\right) \\mp 1}}\n\\end{align}\nand the energy density is\n\\begin{align}\n    \\frac{E}{V} &=\n    \\frac{\\Omega - TS - \\mu N}{V}\\\\\n    &=\n    g \\int\\frac{d^3 k}{(2\\pi)^3}\n    \\frac{E_k}{e^{\\beta\\left( E_k - \\mu \\right)} \\mp 1}\n\\end{align}\n\nWe don't know what the chemical potential is if I give you a box of atoms.\nMore likely you know the density and energy.\n\nI adjust $\\mu$ and I know the temperature.\nI can then get a particular values of $N$ for a particular $T$ I know.\nThen I get $\\mu$ to compute the temperature nd anything you want.\n\nThere is no instrument I can stick in a bottle and measure the chemical\npotential.\nMaybe there is but it's not practical.\n\nI need to go through this dance of fixing this and tuning $\\mU$ to get the\nproperty density.\nIf I have this integral calculated,\nI will do this once and I'm done.\nBut I can't.\nSo I compute the integral numerically find the value of $\\mu$.\n\nMaybe I should put it in the homework so you do it once in your life.\n\nI do this to approximate and make the physics explicit.\nTo be sincere,\nit is a stupid tradition that I know no computers and I have to do everything\nwith pen and paper.\nIt's not completely meaningless to do this because it does bring up some physics.\n\nLet's pretend we do not own computes and extract things with pen and paper.\nThe first thing I want to consider is the classical limit.\nThe classical limit may surprise you,\nbecause you think it's getting $\\hbar\\to 0$,\nbut that's fake situation,\nnot even God can change $\\hbar$,\nbecause it's a creation of the human mind.\nIf I use a unit system where $\\hbar=1$,\nit's gone.\nSo the classical limit is actually when\n\\begin{align}\n    e^{\\beta\\mu} \\ll 1\n\\end{align}\nHow can this be small?\nCertainly possible because it's an exponential.\n\nIt's necessary that $\\mu$ is negative,\nvery negative.\nThat is,\n\\begin{align}\n    - \\mu \\gg k_B T\n\\end{align}\nSo then $\\mu$ has to be very negative and in magnitude much larger than\n$k_BT$.\nI claim this is the classical limit,\nbecause it recovers the good old results you recover in kindergarten.\n\nLet's look at the occupation number\n\\begin{align}\n    n(k) &=\n    \\frac{1}{e^{\\beta\\left( E_k - \\mu \\right) \\mp 1}}\n\\end{align}\nThis exponential is always a positive number,\nso some people call this quantity\n$z = e^{\\beta \\mu}$,\ncalled a very poetic name,\nthe fugacity,\nthe property of being temporary,\nsomething that goes away very quickly.\nI have no idea where it's used in any other circumstances.\n\nRichard: I used to hear geochemists use that term often about the exchange of\noxygen and CO2.\n\nIf I consider the limit where the fugacity is small,\nno matter what $e$ is,\nthis is going to be much larger than 1,\nand I can neglect this $\\mp 1$,\nand so approximately,\n\\begin{align}\n    n(k) &=\n    \\frac{1}{e^{\\beta\\left( E_k - \\mu \\right) \\mp 1}}\\\\\n    &\\approx \n    e^{-\\beta E_k} e^{\\beta \\mu}\n\\end{align}\nand this is classical.\nYou see a Boltzmann factor appear here,\nso it's beginning to look lie a classical gas.\nAnd Siri is giving me a band called fugacity.\nWhy is the band called fugacity?\nThat's an optional question in the homework.\n\nI can then do this approximation inside of the integral.\n\\begin{align}\n    \\frac{N}{V} &=\n    g \\int \\frac{d^3k}{(2\\pi)^3}\n    e^{-\\beta \\frac{\\hbar^2 k^2}{2m}} e^{\\beta\\mu}\n\\end{align}\nwhich is a Gaussian integral you've been doing the whole semester,\nand if I'm not mistaken.\n\\begin{align}\n    \\int \\frac{d^3k}{(2\\pi)^3}\n    e^{-\\beta \\frac{\\hbar^2 k^2}{2m}}\n    &=\n    \\frac{1}{8\\pi^2}\n    \\left( \\frac{2mk_B T}{\\hbar^2} \\right)^{3/2}\n    = \n\\end{align}\nwhich you could check out by dimension analysis.\nI wrote it in this particular way because it has a name\nHere $\\lambda_T$ is the thermal length,\n\\begin{align}\n    \\frac{1}{\\lambda_T^2}\n    =\n    \\frac{2mk_B T}{\\hbar^2}\n\\end{align}\nwhich different books may define differently up to factors of $2\\pi$.\n\n\nSerious people wrote papers about how to do dimensional analysis to work out\nfactors of $2\\pi$ in particle physics.\nCompletely insane.\n$2\\pi$ is a big number, like 6,\nso if you miss it you get the number completely wrong.\nIt's not a science,\nit's an art,\nlooking at integrals,\nsquinting and extracting powers of $2\\pi$.\nIt's dark magic, but we're not going to do that,\njust compute the integral.\n\\begin{align}\n    \\frac{N}{V} &=\n    g e^{\\beta N} \\frac{1}{\\lambda_T^3}\n\\end{align}\n\nOne thing I know here,\nif I work in the regime of small fugacity,\nThis is going to be small.\nSmall compared to what?\n\nThen we compute the free energy\n\\begin{align}\n    F &= \\Omega + \\mu N\\\\\n    &=\n    \\pm k_B T V\n    \\int \\frac{d^3k}{(2\\pi)^3}\n    \\ln\\left[ \n    1 \\mp e^{-\\beta \\left( E_k - \\mu \\right)}\n    \\right]\n\\end{align}\n\nStory about the astronaut pen.\n\n\\begin{question}\n    What would I google to dabble the dark arts of $2\\pi$?\n\\end{question}\nPlaces you shouldn't.\nThere's an actual paper called counting powers of $2\\pi$.\nIt's not general,\nonly a very particular context on particle physics.\nIt's based on the absurd statement that the number of $\\pi$'s on the left and\nright have to match.\nIt's hilarious,\nbecause open the textbook and find an exception to this rule.\nIt's an irrational number.\n\nAnyway, then I have to do this approximation.\nLook at the log.\n\\begin{align}\n    F &\\approx\n    k_B T N + \\mu` N\n\\end{align}\nbut which term is larger in magnitude?\n$\\mu$ of course.\nSo my energy is just\n\\begin{align}\n    F &= N\\mu\n\\end{align}\nBut what is $\\mu$?\nWell I can extract it from $N/V$.\n\\begin{align}\n    F &=\n    N\\ln \\left( \\frac{N}{V} \\frac{\\lambda_T^3}{g} \\right) \\frac{1}{\\beta}\n\\end{align}\nThat's what I promised before.\nExplicitly then I get that.\nWriting the thermal wavelength the way it's supposed to be,\nI get\n\\begin{align}\n    F & k_B T N\n    \\ln\\left( \n    \\frac{V}{N} \\left( k_B T \\right)^{3/2} \\cdots\n    \\right)\n\\end{align}\nwhich is what you derived before the hard way.\nWhat's cool about this,\nis that you don't have to stick the fudge factor of $N!$.\n\nThe fact we got $N$ here in the quantum derivation means we really need the $N!$\nin the classical case.\nTrack down the $N!$ in the classical case derivation in our homework,\nand you will find it will not match if you don't have the $N!$.\n\nWe had that fudge factor for 2 months for no good reason,\nbut finally we have a good reason for it.\n\\begin{question}\nWhat's the physical interpretation of the thermal length.\n\\end{question}\nIf I have a particle in a gas,\nthe de Broglie wavelength is the thermal wavelength.\nQM,\nevery particle you can think of as a wave,\nand the wavelength of that wave is the wavelength of a typical particle.\n\nThe approximation was that the fugacity $z=e^{\\beta N}\\ll 1$,\nbut that's the same thing as saying the density times the thermal volume,\nwhich is the de Broglie wavelength cubed is very small\n\\begin{align}\n    \\frac{N}{V} \\lambda_T^3 \\ll 1\n\\end{align}\nand that is what I mean by a dilute gas.\nWhat I'm saying is that to have a classical gas,\nthe de Broglie wavelength of a particle has to be a lot smaller than that.\nIf you think about it that's how quantum mechanics works.\nIf you have a particle moving along obstacles this big,\nit's like rays.\nBut if you have wavelengths similar to distances,\nit's behaving like waves.\n\nTe complicated integral isn't that visible,\nand the trivial thing is not.\n\nBy the way,\nthis is typically how you calculate the free energy,\nyou typically have to solve for $\\mu$ from the formula for the density $N/V$.\n\nIt's a little too fast to say high temperature is classical because $T$ is\nlarger than $\\mu$,\nbecause not really,\nbecause $\\mu$ can also increase with $T$.\n\nIt's more useful to say that you want $z=e^{\\beta N}$ to be large.\nYou want high density and low temperature.\n\nYou want the temperature to be large,\nbut large compared to what.\nThere's nothing large to compare against.\nSo you compare the thermal wavelength with the density.\nThat's the only thing that make sense.\nThere are classical gases that are not that hot,\nas long as the density is smaller.\n\nIt's only the relation.\n\nThe direction is right.\nCold and dense things are quantum mechanical.\nThat's why every day at the physics department,\nyou get a truck with liquid nitrogen,\nbecause no one wants to do high temperature.\nUnless you do plasma physics,\nand you live your life in classical physics.\n", "meta": {"hexsha": "b3a0064f83870377864cd8bfec14872f53387242", "size": 8829, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys612/lecture26.tex", "max_stars_repo_name": "ehua7365/umdphysnotes", "max_stars_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-11T12:53:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-11T12:53:46.000Z", "max_issues_repo_path": "phys612/lecture26.tex", "max_issues_repo_name": "ehua7365/umdphysnotes", "max_issues_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "phys612/lecture26.tex", "max_forks_repo_name": "ehua7365/umdphysnotes", "max_forks_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3402061856, "max_line_length": 81, "alphanum_fraction": 0.7086872806, "num_tokens": 2542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072387, "lm_q2_score": 0.7931059462938814, "lm_q1q2_score": 0.7275181974546701}}
{"text": "% Chapter 2\n\n\\chapter{Background} % Main chapter title\n\\newcommand{\\Mset}[2]{\\ensuremath{\\mathbb{M}_{#1 \\times #2}}}\n\\newcommand{\\reff}[1][e]{\\ensuremath{R_#1^{\\text{eff}}}}\n\\label{Chapter2} % For referencing the chapter elsewhere, use \\ref{Chapter2} \n\n%----------------------------------------------------------------------------------------\n% \\section{Markov Chains}\n% \n% \\subsection{Fundamental theorem of Markov chain}\n% \n% \\subsection{Markov chain tree theorem}\n\nTo make the exposition self contained I have chosen the results which are relevant to understanding the Harvey, Xu algorithm. Most of these results are taken from \\citet{TCS-054}\n\n\\section{Preliminary Linear Algebra}\n\n\\begin{Bf}\n If $A$ is a $n \\times n$ real symmetric matrix, then all it's eigenvalues are real. \n\\end{Bf}\n\n\\begin{Bf}[Eigenvectors of different eigenvalues are orthogonal]\n Let $\\lambda_i$ and $\\lambda_j$ be two eigenvalues of a symmetric matrix $A$ and $\\textbf{u}_i, \\textbf{u}_j$ be it's corresponding eigenvectors. If $\\lambda_i \\neq \\lambda_j$ then $\\langle \\textbf{u}_i, \\textbf{u}_j \\rangle = 0$\n\\end{Bf}\n\n\\begin{Bf}[Min-Max Characterizations of Eigenvalues]\n If $A$ is a $n \\times n$ real symmetric matrix, then the largest eigenvalue of $A$ is \n \n $$ \\lambda_n(A) = \\max_{v \\in \\mathbb{R}^n \\setminus \\{0\\}} \\frac{v^T A v}{v^Tv}$$\n \n $$ \\lambda_1(A) = \\min_{v \\in \\mathbb{R}^n \\setminus \\{0\\}} \\frac{v^T A v}{v^Tv}$$\n\\end{Bf}\n\n% https://tex.stackexchange.com/questions/128508/a-new-line-inside-subscript\n\n\\begin{Bf}[Courant-Weyl-Fisher min-max principle]\n \\[ \\lambda_k(A) = \\min_{\\substack{v \\in \\mathbb{R}^n \\setminus \\{0\\}\\\\ v^Tu_i = 0 \\ \\forall i \\in \\{1, \\dots , k-1\\}}} \\frac{v^T A v}{v^Tv} \\]\n \n \\[ \\lambda_k(A) = \\max_{\\substack{v \\in \\mathbb{R}^n \\setminus \\{0\\}\\\\ v^Tu_i = 0 \\ \\forall i \\in \\{1, \\dots , k-1\\}}} \\frac{v^T A v}{v^Tv} \\]\n\\end{Bf}\n\n\\begin{Bf}[Positive Semi Definite]\n A matrix $A$ is said to be positive semi definite (PSD) if $\\lambda_1(A) \\geq 0$ . $A$ is said to be positive definite if $\\lambda_1(A) > 0$\n\\end{Bf}\n\n\n\\section{Laplacian of a Graph}\n\n\\begin{Bd}[Laplacian]\n For an undirected unweighted graph $G = (V, E)$ the Laplacian $L_G$ is a $|V| \\times |V|$ matrix defined as \n \n  \\[\n    L_G(i, j) = \n\\begin{cases}\n    -1& \\text{if } (i, j) \\ \\in E\\\\\n    deg(i)& \\text{if } i = j\\\\\n    0              & \\text{otherwise}\n\\end{cases}\n\\]\n\nIt can also be seen that \n$$L_G = D - A$$\n\nwhere $D$ is a diagonal matrix with diagonal entries as degree of the corresponding vertex. \n\n \\end{Bd}\n\n \\begin{Bd}[Weighted Laplacian]\n For an undirected weighted graph $G = (V, E)$ and a weight function $\\textbf{w}: E \\rightarrow \\mathbb{R}_{\\geq 0}$ the Laplacian $L_G$ is a $|V| \\times |V|$ matrix defined as \n \n  \\[\n    L_G(i, j) = \n\\begin{cases}\n    -w(i,j)& \\text{if } (i, j) \\ \\in E\\\\\n    \\displaystyle\\sum_{(i,v) \\in E} w(i, v)& \\text{if } i = j\\\\\n    0              & \\text{otherwise}\n\\end{cases}\n\\]\n\n\\end{Bd}\n\n\\subsection{Properties of Laplacian}\n\n\\begin{Bf}\n The Laplacian of a graph is PSD\n\\end{Bf}\n\n\\begin{Bf}\n ker($L$) = span(\\textbf{1})\n\\end{Bf}\n\n\\begin{Bf}\n Let $L$ be the Laplacian of a graph $G= (V,E)$, then\n $$ \\lambda_2(L) > 0 \\iff G \\text{ is connected}$$\n\\end{Bf}\n\n\n\\subsection{Kirchoff Matrix Tree Theorem}\n\n\\begin{Bf}\n The number of spanning trees in a graph $G$ is \\textbf{det}($L_G[i]$) (for any $i$) where $L_G$ denotes the Laplacian of $G$ and $L_G[i]$ denotes the matrix with $i^{th}$ row and column removed. \n\\end{Bf}\n\n\n\\section{Electric Networks}\n\n\\subsection{Unweighted Graph}\n\n\\subsubsection{Incidence Matrix} \n\nGiven an undirected unweighted graph $G=(V,E)$ with arbitrary orientation of edges. Let $B \\in  \\Mset{n}{m}$ \\footnote{I have used a transposed version compared to \\citet{TCS-054} so that it's consistent with the notation used later} called the edge-vertex incidence matrix defined as \n\n\\[\n    B(i, e) = \n\\begin{cases}\n 1 & \\text{if } i \\text{ is tail of } e\\\\\n -1 & \\text{if } i \\text{ is head of } e \\\\\n 0 & \\text{otherwise}\n\\end{cases}\n\\]\n\n\\begin{Bf}\n For a graph $G$ with arbitrarily chosen incidence matrix $B$ and Laplacian $L$, \n $$B \\cdot B^T = L$$\n\\end{Bf}\n\n\nGiven an unweighted graph $G = (V,E)$ we associate a electrical network by replacing each edge with a resistor with resistance $1 \\ \\Omega$. A current source is introduced in each vertex, denoted as $\\textbf{c}_{\\text{ext}} \\in \\mathbb{R}^n$. This induces a voltage at each vertex and current at each edge. Let's denote it as $\\textbf{v} \\in \\mathbb{R}^n, \\textbf{i} \\in \\mathbb{R}^m$\n\n\n\nLet $i_{xy}$ denote the current from vertex $x$ to $y$ for edge $(x,y) \\in E$. And $v_x$ denote the potential at a vertex $x \\in V$.\n\n\\subsubsection{Kirchoff's current law}\n\nKirchoff's current law states that the algebraic sum of current into any vertex equals zero. \n\n$$ B \\cdot \\textbf{i} = \\textbf{c}_{\\text{ext}} $$\n\n\\subsubsection{Ohm's law}\nOhm's law states that electric current through an edge is directly proportional to the potential different across an edge and inversely proportional to the resistance of the edge.\n\n$$ i_{xy} = \\frac{v_x - v_y}{r_{xy}} $$\n\nSince the resistance in the unweighted graph is $1 \\ \\Omega$ we have \n\n$$ \\textbf{i} = B^T \\cdot \\textbf{v} $$ \n\nCombining Ohm's law and Kirchoff's law we get \n\n$$ L \\cdot \\textbf{v} = \\textbf{c}_{\\text{ext}} $$ \n\n\\subsubsection{Laplacian pseudoinverse}\n\n\n\n\\subsubsection{Effective Resistance}\n\nEffective resistance across 2 vertices $x,y$ is the resistance between $x,y$ if we treat the graph as a single resistor connected between $x$ and $y$. \n\nIn our case we are mainly interested in the effective resistance across an edge $e = (x,y) \\in E$.\n\n\\begin{Bd}\n Effective Resistance is the potential difference across an edge $e = (x,y)$ when $1A$ is inducted at $x$ and taken out at $y$. It is denoted as \\reff\n\\end{Bd}\n\nSo we have $\\textbf{c}_{\\text{ext}} = e_x - e_y$ where $e_i$ denotes a vector with 1 in the $i^{th}$ index and 0 elsewhere. By definition of effective resistance we have \n\n\\begin{align*}\n \\reff &= (e_x - e_y)^T \\cdot \\textbf{v} \\\\\n \\reff &= (e_x - e_y)^T \\cdot L^+  \\cdot \\textbf{c}_{\\text{ext}} \\\\\n \\reff &= (e_x - e_y)^T \\cdot L^+  \\cdot (e_x - e_y) \n\\end{align*}\n\n\n\\subsection{Weighted Graph}\n\nThere are a few subtle changes which needs to be incorporated for the weighted graph setting. Suppose $G=(V,E)$ be a undirected weighted graph with weight function $\\textbf{w}: E \\rightarrow \\mathbb{R}_{\\geq 0}$. Now the electric network of $G$ coressponds has edges replaced by a resistor with resistance $r_e = 1 / \\textbf{w}(e) , \\forall e \\in E$. The intuition is that lower weight for an edge in graph $G$ means it's barely there hence it coressponds to higher resistance. And having no edge coressponds to infinite resistance. \n\nFor deriving the other relations let $W \\in \\Mset{m}{m}$ be a diagonal matrix such that $W(e,e) = \\textbf{w}(e)$. Now $L = B \\ W \\ B^T$ and Ohm's law becomes $\\textbf{i} = W \\ B^T \\ \\textbf{v} $. As it can be seen the formula for effective resistance remains the same\n\n\\pagebreak\n\n% https://tex.stackexchange.com/questions/57152/how-to-draw-graphs-in-latex\n\n\\subsection{An Example}\nConsider the following weighted graph $G$ in \\textbf{Figure 2.1}\n\\definecolor {processblue}{cmyk}{0,0,0,0}\n\n\n% https://tex.stackexchange.com/questions/37581/latex-figures-side-by-side\n\n\\begin{figure}[h!]\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n  \\centering\n%   \\includegraphics[width=.4\\linewidth]{image1}\n\n\\begin {tikzpicture}[auto ,node distance =4 cm and 5cm ,on grid ,\nsemithick ,\nstate/.style ={ circle ,top color =white , bottom color = processblue!20 ,\ndraw,black , text=black , minimum width =1 cm}]\n\\node[state] (C){$A$};\n\\node[state] (A) [above =of C] {$D$};\n\\node[state] (B) [above right =of C] {$C$};\n\\node[state] (D) [right =of C] {$B$};\n\\path (C) edge node[below] {$1$} (D);\n\\path (B) edge node[right] {$5$} (D);\n\\path (A) edge node[above] {$10$} (B);\n\\path (C) edge node[left] {$4$} (A);\n\\end{tikzpicture}\n\n  \\caption{The original graph $G$}\n  \\label{fig:sub1}\n\\end{subfigure}%\n\\begin{subfigure}{.5\\textwidth}\n  \\centering\n%   \\includegraphics[width=.4\\linewidth]{image1}\n\n\\begin{circuitikz}[american]\n \\put(0,0){0};\n \\draw (0, -2) to[short, -*, i=$1 A$] (0,0) node[left]{$A$};\n \\draw (0,0) to[R, l=\\mbox{$1 \\  \\Omega$}] (3,0) node[right]{$B$};\n \\draw (0,0) to[R, l=$0.25 \\ \\Omega$] (0,3) node[left]{$D$};\n \\draw (3,0) to[R, l=\\mbox{$0.2 \\ \\Omega$}] (3,3) node[right]{$C$};\n % this works, but it has wrong spacing\n \\draw (0,3) to[R, l=$0.1 \\ \\Omega$] (3,3);\n \\draw (3, 0) to[short, *-, i=$1 A$] (3,-2);\n \\draw (3, -2) to[isource, l=$1 A$] (0, -2);\n \\end{circuitikz}\n\n\\caption{The electric network version of $G$}\n  \\label{fig:sub2}\n\\end{subfigure}\n\\caption{An example of a graph and it's corresponding electric network}\n\\label{fig:test}\n\\end{figure}\n\nFollowing the convention such that current going inside a vertex as negative and out as positive.\n\nBy Ohm's law we have \n\n\\begin{align*}\ni_{AD} &= 4  \\, (v_A - v_D) \\\\ \ni_{DC} &= 10 \\, (v_D - v_C) \\\\\ni_{CB} &= 5  \\, (v_C - v_B) \\\\\ni_{AB} &= 1  \\, (v_A - v_B) \n\\end{align*}\n\nBy Kirchoff's current law we have \n\\begin{align*}\n i_{AD} + i_{AB} &= 1 \\\\\n -i_{AD} + i_{DC} &= 0 \\\\\n -i_{DC} + i_{CB} &= 0 \\\\\n -i_{AB} - i_{CB} &= -1\n\\end{align*}\n\nNow combining these two we get \n\n\\begin{align*}\n 5v_A  - 1 v_B - 0 v_C - 1 v_D &= 1 \\\\\n -1v_A + 6 v_B - 5 v_C - 0 v_D &= -1 \\\\\n 0v_A - 5v_B + 15 v_C - 10 v_D &= 0 \\\\\n -4v_A - 0v_B - 10v_C + 14v_D &= 0\n\\end{align*}\n\nAnd this is exactly what we would have gotten using $L \\cdot \\textbf{v} = \\textbf{c}_{\\text{ext}}$\n\n%----------------------------------------------------------------------------------------\n\n\n\n\n\n", "meta": {"hexsha": "a9c9d9dcc5dc938a1124c1e1668f51cb9c105ef9", "size": 9629, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/Chapters/Chapter2.tex", "max_stars_repo_name": "severus-tux/masters-thesis", "max_stars_repo_head_hexsha": "c6d3856cccda06735a01699c91ad923590f08ab7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "thesis/Chapters/Chapter2.tex", "max_issues_repo_name": "severus-tux/masters-thesis", "max_issues_repo_head_hexsha": "c6d3856cccda06735a01699c91ad923590f08ab7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thesis/Chapters/Chapter2.tex", "max_forks_repo_name": "severus-tux/masters-thesis", "max_forks_repo_head_hexsha": "c6d3856cccda06735a01699c91ad923590f08ab7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-14T15:34:34.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-14T15:34:34.000Z", "avg_line_length": 34.8876811594, "max_line_length": 533, "alphanum_fraction": 0.6446152248, "num_tokens": 3347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7274933783927534}}
{"text": "\\section{Change of Basis}\nIf you get lost just \\emph{insert the identity}.\nMatrix multiplication works like this.\n\\begin{align}\n    \\bra{n}AB\\ket{m} &=\n    \\bra{n} A \\mathbf{1} B \\ket{m}\\\\\n    &= \\sum_i \\bra{n}A\\ket{i} \\bra{i} B\\ket{m}\\\\\n    &= \\sum_i A_{ni} B_{im}\n\\end{align}\nTo change basis from $\\{\\ket{n}\\}$ to $\\{\\ket{\\tilde{n}}\\}$\njust insert the identity.\n\\begin{align}\n    \\ket{\\psi} &=\n    \\sum_n \\underbrace{\\braket{n}{\\psi}}_{\\psi_n}\\ket{n}\\\\\n    &= \\sum_n \\underbrace{\\braket{\\tilde{n}}{\\psi}}_{\\tilde{\\psi}_n}\n    \\ket{\\tilde{n}}\\\\\n    &= \\sum_n\n    \\underbrace{\\braket{\\tilde{n}}{\\psi}}_{\\tilde{\\psi}_n}\n    \\underbrace{\\braket{m}{\\tilde{n}}}_{U_{mn}}\\\\\n    &= \\sum_n \\sum_m U_{mn} \\tilde{\\psi}_n \\ket{m}\n\\end{align}\nThe result I get is the following.\n\\begin{align}\n    \\psi_n &= \n    \\underbrace{U_{mn}}_{\\braket{m}{\\tilde{n}}}\n    \\tilde{\\psi}_m\n\\end{align}\nAlso\n\\begin{align}\n    \\underbrace{\\braket{\\phi}{n}}_{\\varphi_n^*}\n    = \\sum_n\n    \\underbrace{\\braket{\\phi}{\\tilde{n}'}}_{\n    U_{nn'}^* = (U^\\dagger)_{n'n}\n    }\n    = \\sum_{n'} \\tilde{\\phi}_{n'}^* U^\\dagger_{n'n}\n\\end{align}\nLet's do an example.\n\\begin{example}\n    Consider functions f(x) on the real line.\n    The basis of delta functions is\n    $\\{\\delta(x - x_0)\\text{ for all }x_0 \\}$.\n    The basis of plane waves is\n    $\\left\\{\\frac{e^{ikx}}{\\sqrt{2\\pi}}\\text{ for all } k \\right\\}$.\n    Do a change of basis.\n\\end{example}\n\\begin{proof}[Solution]\n    Insert the identity\n    \\begin{align}\n        \\underbrace{\\braket{k}{\\psi}}_{\\mathcal{F}[\\psi](k)} =\n        \\int_{-\\infty}^{\\infty}dx\\,\n        \\braket{k}{x}\n        \\braket{x}{\\psi}\n    \\end{align}\n    where\n    \\begin{align}\n        \\braket{k}{x} &=\n        \\int_{-\\infty}^{\\infty} dy \\frac{e^{-iky}}{\\sqrt{2\\pi}}\\delta(y - x)\\\\\n        &=\n    \\end{align}\n\\end{proof}\n\n\\subsection{Eigenthings and Diagonalisation}\nSometimes, if I have the right $\\ket{\\psi}$ for an operator $A$,\nI can get\n\\begin{align}\n    A\\ket{\\psi} = \\lambda\\ket{\\psi}.\n\\end{align}\nThis has a special name.\n$\\ket{\\psi}$ is called the eivenvector with eigenvalue $\\lambda$.\n\nLet's do an example.\nSuppose I rotate my phone.\nThen I rotate it.\nWhat's the eigenvector?\nIt's the axis of rotation.\nWhat about the eigenvalue?\nIt's 1 because it doesn't change.\n\nSuppose I stretch my phone along an axis.\nWhat are the eigenvectors?\nThere are three of them.\nAlong the axis is an eigenvector, with eigenvalue the scale factor.\nThe other two are perpendicular, with eigenvalues 1, they are degenerate.\n\nIn 2D rotation there are no eigenvectors.\n\nOne way of thinking about the plane is a two-dimensional real space.\nThen no eigenvalues.\n\nBut I can think of it as a one-dimensional complex space,\nthen multiplying by $i$ is a rotation.\nAnd then I have eigenvalues.\n\nI want to build intuition.\n\n\\begin{example}\n    Consider the operator $\\ket{\\phi}\\bra{\\phi}$.\n\\end{example}\n\\begin{proof}[Solution]\n    $\\ket{\\phi}$ is obviously an eigenvector with eigenvalue 1.\n    Any other orthogonal vector is also an eigenvector,\n    but with eigenvalue 0.\n\\end{proof}\n\n\\begin{example}\n    Off diagonal $A=\\sum_{n=1}^{N}\\ket{n + 1}\\bra{n} + \\ket{1}\\bra{N}$.\n\\end{example}\n\\begin{proof}[Solution]\n    This is an eigenvector\n    \\begin{align}\n        \\ket{1} + \\ket{2} + \\cdots + \\ket{N}\n    \\end{align}\n\\end{proof}\nIt has no importance, just practise.\n\n\\subsection{Spectral theorem}\nYou see spectral lines from the energy levels of atoms.\nThat's why it's called the spectral theorem.\n\\begin{theorem}\n    Suppose $A$ is hermitian.\n    If $A\\ket{a} = a\\ket{a}$,\n    then\n    \\begin{enumerate}\n        \\item The $a$'s are all real,\n        \\item (orthonormality) The eigenvectors $\\ket{a}$ can be chosen to be\n            orthonormal\n            $\\braket{a}{b} = \\delta_{ab}$,\n        \\item (completeness) The $a$'s form a complete basis and make a\n            resolution of the identity\n            $\\sum_a \\ket{a}\\bra{a} = 1$.\n    \\end{enumerate}\n\\end{theorem}\n\\begin{proof}\n    Let's see how I can prove it's real.\n    It's very simple.\n    Start from the definition\n    $A\\ket{a} = a\\ket{a}$.\n    Then take\n    $\\bra{a}A\\ket{a} = \\bra{a}a\\ket{a} = a\\braket{a}{a}$\n    and since it's a linear operation and $\\braket{a}{a}$ is real,\n    But since it's hermitian,\n    $\\bra{a}A\\ket{a} = \\bra{a}A\\ket{a}^*$,\n    which means it's real,\n    so $a$ is real.\n\n    To prove orthonormality is slightly more complicated.\n    Suppose we have\n    $A\\ket{a} = a\\ket{a}$\n    and\n    $A\\ket{b} = b\\ket{b}$\n    then take\n    $\\bra{b}A\\ket{a} = \\bra{b}a\\ket{a} = a\\braket{b}{a}$\n    and\n    $\\bra{a}A\\ket{b} = \\bra{a}b\\ket{b} = b \\braket{a}{b}$.\n    Note that $\\braket{a}{b} = \\braket{b}{a}^*$.\n    From this,\n    if $a\\ne b$,\n    then of course\n    $\\braket{a}{b}=0$.\n    But if $a=b$,\n    they are not necessarily orthogonal.\n    The theorem says that we can then choose them to be orthogonal,\n    which is obvious.\n\n    The final one is a bit more difficult to prove.\n    For finite $N$,\n    we want to show\n    \\begin{align}\n        \\sum_{a=1}^{N}\\ket{a}\\bra{a} = \\mathbf{1}.\n    \\end{align}\n    Then\n    \\begin{align}\n        (A - a\\mathbf{1})\\ket{a}\n    \\end{align}\n    which implies that\n    \\begin{align}\n        \\det(A - a\\mathbf{1}) = 0.\n    \\end{align}\n    The determinant is a polynomial in $a$ of degree $N$.\n    The values of $a$ for which the polynomial is zero is $a$.\n    A degree-$N$ polynomial is going to have $N$ zeros,\n    and so we should have $N$ eigenvalues.\n    I know they are linearly independent from one another.\n\n    But what if $N$ is not finite?\n    Or worst continuous?\n    That's not something I cannot prove to you.\n    We haven't defined things well enough,\n    whether the functions are square integrable,\n    or whatever.\n    I'll have to make every statement precise,\n    and we're not doing physics anymore.\n\\end{proof}\n\nIf I see a hunk of metal,\nit's a hunk of metal,\nso we don't care if it's an infinitely differentiable function or a discrete\nsystem.\nIt doesn't help me in the lab.\nThe notes have more examples you may find useful.\n\n\\begin{example}\n    Consider the Hilbert space that is the set of real functions of one variable\n    $f(x)$.\n    We have this basis\n    \\begin{align}\n        \\left\\{\\frac{e^{ikx}}{\\sqrt{2\\pi}}\\text{ for all }k\\right\\}\n    \\end{align}.\n    The operator $-i\\frac{d}{dx}$ is a Hermitian operator and these basis\n    functions are its eigenvectors.\n    You may recognise this as the momentum operator.\n    The eigenvalue equation is\n    \\begin{align}\n        -i \\frac{d}{dx} f(x) = \\lambda f(x)\n    \\end{align}\n    where if you use\n    $f_k(x) = e^{ikx}$\n    it is satisfied.\n    You can instantly recognise that $\\lambda = k$.\n    But this is not normalized,\n    so you have to use\n    $f_k(x) = e^{ikx}/\\sqrt{2\\pi}$.\n\\end{example}\nBy the way, the real momentum operator has a $\\hbar$ in it like\n$\\hat{p} = -i\\hbar d/dx$\nand the functions should be like\n\\begin{align}\n    f_k(x) =\n    \\frac{e^{ikx/\\hbar}}{\\sqrt{2\\pi}}\n\\end{align}\nand $\\lambda = \\hbar k$.\n\nLet's do another example.\n\\begin{example}\n    Consider the space of functions $f(x)$ again.\n    Then consider the operator\n    \\begin{align}\n        H &=\n        - \\frac{\\hbar^2}{2m} \\frac{\\partial}{\\partial x}\n        + \\frac{m\\omega^2}{2}x^2\n    \\end{align}\n\\end{example}\n\\begin{proof}[Solution]\n    The eigenvalues are\n    \\begin{align}\n        \\lambda_n &=\n        \\hbar\\omega\\left( n + \\frac{1}{2} \\right)\n    \\end{align}\n    for $n=0,1,\\ldots$ and the eigen functions are\n    \\begin{align}\n        \\psi_n(x) = \\cdots H_n(\\cdots x) e^{\\cdots -x^2}\n    \\end{align}\n    which you can look up on Wikipedia.\n\\end{proof}\n", "meta": {"hexsha": "52259882d4e9032e2286ab11186ea1620ce57ef5", "size": 7619, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys612/lecture4.tex", "max_stars_repo_name": "ehua7365/umdphysnotes", "max_stars_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-11T12:53:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-11T12:53:46.000Z", "max_issues_repo_path": "phys612/lecture4.tex", "max_issues_repo_name": "ehua7365/umdphysnotes", "max_issues_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "phys612/lecture4.tex", "max_forks_repo_name": "ehua7365/umdphysnotes", "max_forks_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.8784313725, "max_line_length": 80, "alphanum_fraction": 0.6219976375, "num_tokens": 2546, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127417985636, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7274933578264438}}
{"text": "\\newpage\\section{Sequences}\n\n\n\\subsection{Lemmas}\n\n\\theo{https://en.wikipedia.org/wiki/Van_der_Waerden's_theorem}\n{Van der Waerden's Theorem}{\n    For any given positive integers $r$ and $k$, there is some number $ N $ such\n    that if the integers $ \\{1, 2, ..., N\\} $ are colored, each with one of $ r $\n    different colors, then there are at least $ k $ integers in arithmetic\n    progression all of the same color.\n}\n\n\\theo{}\n{Catalan Recursion}{\n    The infinite series defined as following: \\[ a_0 = a_1 = 1,\\ a_n =\n    \\prod_{i=0}^{n} a_ia_{n-i+1} = a_0a_{n-1} + a_1a_{n-2}\\dots + a_{n-1}a_0 \\]\n    has the general term \n    \\[a_n = C_n = \\boxed{\\frac{1}{n+1} \\binom{2n}{n}}\\] \n}\n\n\n\n\\subsection{Problems}\n\n\n\\begin{myitemize}\n    \\item \\href{http://alexanderrem.weebly.com/uploads/7/2/5/6/72566533/sequences.pdf}{Sequences - Alexander Remorov}\n\\end{myitemize}\n\n\\prob{https://artofproblemsolving.com/community/c6h68945p404543}\n{ISL 1990}{E}{\n    Assume that the set of all positive integers is decomposed into $ r $\n    (disjoint) subsets $ A_1 \\cup A_2 \\cup \\dots \\cup A_r = \\mathbb{N}. $\n    Prove that one of them, say $ A_i, $ has the following property: There\n    exists a positive $ m $ such that for any $ k $ one can find numbers $\n    a_1, a_2, \\ldots, a_k $ in $ A_i $ with $ 0 < a_{j+1} - a_j \\leq m, $  $\n    (1 \\leq j \\leq k-1)$.\n    \\index[strat]{Induction!ISL 1990}\n}\n\n\n\\prob{https://mathoverflow.net/questions/25313/finitely-many-arithmetic-progressions}\n{Dividing the integers into arithmetic progressions, Erdos}{E}{\n    Let $ d_1, d_2,\\dots, d_k $ be differences of $ k $ arithmetic\n    progressions that partition $ \\N $. Show that $ d_i=d_j $ for some $i,j$.\n    \\index[strat]{Generating Function!Erdos, Arithmatic Progression}\n    \\index[strat]{Roots of unity filtering!Erdos, Arithmatic Progression}\n}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h79784p456601}\n{APMO 1999 P1}{E}{\n    Find the smallest positive integer $n$ with the following property: there\n    does not exist an arithmetic progression of $1999$ real numbers containing\n    exactly $n$ integers.\n    \\index[strat]{Name things!APMO 1999 P1}\n}\n\n\\begin{solution}\n    If the difference is $\\frac{p}{q}$, then we can arrange the sequence in a\n    way that we can get both exactly $\\left\\lfloor \\frac{1999}{q} \\right\\rfloor$\n    and $\\left\\lceil \\frac{1999}{q} \\right\\rceil$ integers. \\\\\n\n    So what we want is to find smallest integer $n$ for which there is a $k$\n    such that\n    \\[n+1 \\le \\frac{1999}{k} \\quad \\text{ and } \\quad \\frac{1999}{k+1} \\le n-1\\] \n    So that $\\frac{1999}{k}$ skips over $n$. After a bit of calculation, we\n    get $n = 70, k = 28$ are the solutions we want.\n\\end{solution}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h79787p456607}\n{APMO 1999 P2}{E}{\n    Let $a_1, a_2, \\dots$ be a sequence of real numbers satisfying $a_{i+j}\n    \\leq a_i+a_j$ for all $i,j=1,2,\\dots$. Prove that\n    \\[ a_1 + \\frac{a_2}{2} + \\frac{a_3}{3} + \\cdots + \\frac{a_n}{n} \\geq a_n \\]\n    for each positive integer $n$.\n    \\index[strat]{Induction!APMO 1999 P2}\n    \\index[strat]{Sum them up!APMO 1999 P2}\n}\n\n\\begin{solution}[jgnr]\n    We will prove this by induction. Note that the inequality holds for $ n=1$. Assume that the inequality holds for $ n=1,2,\\ldots,k$, that is,\n\\[ a_1\\ge a_1,\\quad a_1+\\frac{a_2}2\\ge a_2,\\quad\n    a_1+\\frac{a_2}{2}+\\frac{a_3}3\\ge a_3, \\quad \\dots \\quad\na_1+\\frac{a_2}{2}+\\frac{a_3}{3}+\\cdots+\\frac{a_k}k\\ge a_k. \\]\nSum them up:\n\\[ ka_1+(k-1)\\frac{a_2}2a_2+\\cdots+\\frac{a_k}{k}\\ge a_1+a_2+\\cdots+a_k. \\]Add $ a_1+\\ldots+a_k$ to both sides:\n\\[ (k+1)\\left(a_1+\\frac{a_2}2+\\cdots+\\frac{a_k}k\\right)\\ge (a_1+a_k)+(a_2+a_{k-1})+\\cdots+(a_k+a_1)\\ge ka_{k+1}. \\]\nDivide both sides by $ k+1$:\n\\[ a_1+\\frac{a_2}2+\\cdots+\\frac{a_k}k\\ge\\frac{ka_{k+1}}{k+1}, \\] i.e.\n\\[ a_1 + \\frac{a_2}{2} + \\frac{a_3}{3} + \\cdots + \\frac{a_n}{n} \\geq a_n. \\]\n\\end{solution}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h125791p713182}\n{ISL 1994 A1}{E}{\n    Let for each nonnegative integer $ n$, \n    \\[ a_{0} = 1994 \\quad a_{n + 1} = \\frac {a_{n}^{2}}{a_{n} + 1}\\] \n    Prove that $ 1994 - n$ is the greatest integer less than or equal to $\n    a_{n}$, $ 0 \\leq n \\leq 998$\n    \\index[strat]{Rearrange!ISL 1994 A1}\n    \\index[strat]{Induction!ISL 1994 A1}\n}\n\n\\solu{[t0rajir0u]\n    Rewrite the condition as\n    \\[a_{n+1} = a_n -1 + \\frac{1}{a_n + 1}\\]\n    Which gives us\n    \\[ a_{k} = 1994 - k + \\frac {1}{a_{k - 1} + 1} + \\frac {1}{a_{k - 2} + 1} +\n    \\dots + \\frac {1}{1994 + 1}\\]\n    So we need to bound the fraction part below $1$ for $a_{998}$. By induction, it is\n    atmost\n    \\[\\frac{1}{997}+ \\frac{1}{998}\\dots + \\frac{1}{1995}\\] \n    Which is trivial to prove.\n}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h214669p1186971}\n{ISL 2007 C4}{M}{\n    Let $ A_0 = (a_1,\\dots,a_n)$ be a finite sequence of real numbers. For\n    each $ k\\geq 0$, from the sequence $ A_k = (x_1,\\dots,x_k)$ we construct a\n    new sequence $ A_{k + 1}$ in the following way.\n    \\begin{enumerate}\n        \\item We choose a partition $ \\{1,\\dots,n\\} = I\\cup J$, where $ I$ and\n            $ J$ are two disjoint sets, possibly empty, such that the expression \n            \\[\\left|\\sum_{i\\in I}x_i - \\sum_{j\\in J}x_j\\right|\\] \n            attains the smallest value. If there are several such partitions,\n            one is chosen arbitrarily.\n        \\item We set $ A_{k + 1} = (y_1,\\dots,y_n)$ where $ y_i = x_i + 1$ if\n            $ i\\in I$, and $ y_i = x_i - 1$ if $ i\\in J$.\n    \\end{enumerate}\n    Prove that for some $ k$, the sequence $ A_k$ contains an element $ x$\n    such that $ |x|\\geq\\dfrac n2$.\n\n    \\index[strat]{Invariant!Sum of Squares!ISL 2007 C4}\n}\\label{problem:invariant_rules_of_thumb_11}\n\n\\solu{\n    Suppose the contrary. Now, since $ A_i $ can only attain finite values, So $\n    A_i = A_j $ for some $ i, j $. Now, we are taking about changes here, so we\n    need to think of some invariants. Firstly the sum, it's not much of an help,\n    because it doesn't give us much control. So kinda sum-ish invariant with a bit\n    more control is the sum of squares. We combine these two ideas.\n}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h288840p1561573}\n{ISL 2009 A6}{EM}{\n    Suppose that $ s_1,s_2,s_3, \\ldots$ is a strictly increasing sequence of\n    positive integers such that the sub-sequences \n    \\[s_{s_1},\\, s_{s_2},\\, s_{s_3},\\, \\ldots\\quad\\text{and}\\quad\n    s_{s_1+1},\\, s_{s_2+1},\\, s_{s_3+1},\\, \\ldots\\] \n    are both arithmetic progressions. Prove that the sequence $ s_1, s_2, s_3,\n    \\ldots$ is itself an arithmetic progression.\n\n    \\index[strat]{Name things!ISL 2009 A6}\n}\n\n\\solu{\n    First notice that the two arithmetic sequences has the same common\n    difference. Then notice that the diffrences of the original sequence is\n    bounded.\\\\\n\n    Another advice, give everything names. After naming the smallest\n    difference and the largest differnce, we get two different inequalities,\n    from where we deduce that the difference is constant.\n}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1181540p5720240}\n{ISL 2013 N2}{E}{\n    Assume that $k$ and $n$ are two positive integers. Prove that there exist\n    positive integers $m_1, \\dots, m_k$ such that\n    \\[1+\\frac{2^k-1}{n}=\\left(1+\\frac1{m_1}\\right)\\cdots \\left(1+\\frac1{m_k}\\right).\\]\n\n    \\index[strat]{Induction!ISL 2013 N2}\n}\n\n\\solu{Just induct, and think wishfully.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6t177f6h145842}\n{USAMO 2007 P1}{E}{\n    $n$ be a positive integer. Define a sequence by setting $a_1=n$ and, for each\n    $k>1$, letting $a_k$ be the unique integer in the range $0\\leq a_k \\leq k-1$\n    for which $a_0+a_1\\dots +a_k$ is divisible by $k$. Prove that for any $n$ the\n    sequence ${a_i}$ eventually becomes constant.\n\n    \\index[strat]{Invariant!Monovariant!USAMO 2007 P1}\n}\n\n\\solu{Investigate and done.}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1071763p4663881}\n{APMO 2015 P3}{E}{\n    A sequence of real numbers $a_0, a_1, . . .$ is said to be good if the\n    following three conditions hold.\n    \\begin{enumerate}[itemsep=5pt]\n        \\item The value of $a_0$ is a positive integer.\n        \\item For each non-negative integer $i$ we have $a_{i+1} = 2a_i + 1 $\n            or $a_{i+1} =\\dfrac{a_i}{a_i + 2} $\n        \\item There exists a positive integer $k$ such that $a_k = 2014$.\n    \\end{enumerate}\n    Find the smallest positive integer $n$ such that there exists a good sequence\n    $a_0, a_1, \\dots$ of real numbers with the property that $a_n = 2014$.\n\n    \\index[strat]{Invariant!Monovariant!APMO 2015 P3}\n    \\index[strat]{Rearrange!APMO 2015 P3}\n    \\index[strat]{Get your hands dirty!APMO 2015 P3}\n}\n\n\\solu{\n    We will rename the sequence and call it $ \\{s_i\\} $, with $ s_0=x\\in \\Z $.\n    Now let, \\[s_i = \\frac{a_ix+b_i}{c_ix+d_i}\\]\n\n    At the beginning we have $ a_0=d_0=1, b_0=c_0=0 $. It is easy to prove\n    that \\[ a_{i+1}+c_{i+1} = 2(a_i+c_i) \\]\\[ b_{i+1}+d_{i+1} = 2(b_i+d_i) \\]\n    So it follows that \\[ a_i+c_i = 2^i = b_i+d_i \\]\n    Also, by induction (which is easy to prove), we have \\[a_i - b_i = d_i - c_i = 1\\]\n\n    Suppose for some $ k $, $ s_k=2014 $. So, \n    \\begin{align}\n        &\\frac{a_kx+b_k}{c_kx+d_k}=2014\\\\[1em]\n        \\implies x&=\\frac{2014d_k-b_k}{a_k-2014c_k}=\\frac{2015d_k-2^k}{2^k-2015c_k}\\\\[1em]\n        &=\\frac{2015(d_k-c_k)}{2^k-2015c_k}-1\n    \\end{align}\n\n    But $ \\gcd(2015, 2^k-2015c_k)=1 $, which implies $ 2^k-2015-c_k=1 $.\n    Solving for $ k $ with CRT gives us $ 60|k $. \n\n    Now we have to prove that there is a sequence with $ s_{60} = 2014 $.\n    Solving (1), $ s_0=2014 $, and,\n    \\[\\begin{aligned}\n        a_{60}&= \\frac{2014\\cdot 2^{60}+1}{2015} &b_{60} &=\\frac{2014\\cdot\n        2^{60}-2014}{2015}\\\\[1em]\n        c_{60}&= \\frac{2^{60}-1}{2015} &d_{60} &=\\frac{2^{60}+2014}{2015}\n    \\end{aligned}\\]\n    \\vspace{1em}\n    We show that we can make $ (a_{60}, c_{60}) $ from $ (a_0, c_0)=(1, 0) $.\n    We prove it by induction, that $(a_k, c_k)$ can take any form $(2^k-i, i)$\n    with $i\\in\\{0, 1, \\dots 2^k-1\\}$.\n}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h287853p1555896}\n{ISL 2008 A4}{EM}{\n    For an integer $ m$, denote by $ t(m)$ the unique number in $ \\{1,    2,\n    3\\}$ such that $ m + t(m)$ is a multiple of $ 3$. A function $    f:\n    \\mathbb{Z}\\to\\mathbb{Z}$ satisfies $ f( - 1) = 0$, $ f(0) = 1$,    $ f(1)\n    = - 1$ and $f\\left(2^{n} + m\\right) = f\\left(2^n -    t(m)\\right) - f(m)$\n    for all integers $ m$, $ n\\ge 0$ with $ 2^n >    m$. Prove that $ f(3p)\\ge\n    0$ holds for all integers $ p\\ge 0$. \n\n    \\index[strat]{Induction!ISL 2008 A4}\n    \\index[strat]{Get your hands dirty!ISL 2008 A4}\n}\n\n\\begin{solution}\n    We begin by listing values of $f(n)$ for $n\\le 16$, and immediately it\n    strikes us that:\n    \\begin{enumerate}\n        \\item  if $ -1\\le x \\le 2^{2m}-1$ then the maximal value is $\n            f(2^{2m}-1)$ the minimal value is $ f(2^{2m}-2)$\n        \\item if $ -1\\le x \\le 2^{2m+1}$ then the maximal value is $ f(2^{2m+1}-2)$\n            the minimal value is $ f(2^{2m+1}-1)$\n    \\end{enumerate}\n    After which we are done by induction.\n\\end{solution}\n", "meta": {"hexsha": "76090165c88cd8710243adb34d6c438b73648719", "size": 11161, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combi/sec8_sequences.tex", "max_stars_repo_name": "M-Ahsan-Al-Mahir/BCS_Question_Bank", "max_stars_repo_head_hexsha": "83ff9b542999386ea182863e4f25f0b488d3984f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 48, "max_stars_repo_stars_event_min_datetime": "2020-10-14T17:15:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T19:47:04.000Z", "max_issues_repo_path": "combi/sec8_sequences.tex", "max_issues_repo_name": "AnglyPascal/BCS_Question_Bank", "max_issues_repo_head_hexsha": "83ff9b542999386ea182863e4f25f0b488d3984f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "combi/sec8_sequences.tex", "max_forks_repo_name": "AnglyPascal/BCS_Question_Bank", "max_forks_repo_head_hexsha": "83ff9b542999386ea182863e4f25f0b488d3984f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-10-15T08:59:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-27T15:19:26.000Z", "avg_line_length": 40.5854545455, "max_line_length": 144, "alphanum_fraction": 0.6332765881, "num_tokens": 4154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7274933576777162}}
{"text": "\\Lecture{Jayalal Sarma}{Sept 19, 2020}{05}{Multichoosing}{Narasimha Sai Vempati}{$\\beta$}{JS}\n\n%\\section{Introduction}\nConsider the definition of \\emph{set}. We know that it's a well defined collection of \\emph{distinct} objects. From a collection of $n$ distinct symbols, the number of ways to form a \\emph{set} of length $k$ is given by $\\binom{n}{k}$. Now let's consider the definition of \\emph{multi-set}. It's similar to that of a \\emph{set}, except that it allows repetition of objects. Now it's natural ask the following question: From a collection of $n$ distinct symbols, what is the number of ways to form a \\emph{multi-set} of length $k$. Multichoosing exactly answers this questions. In this lecture, we explore multichoosing in detail. We discuss several equivalent bijections to this problem and come-up with an algebraic expression for \\mulnom{n}{k} (spelled out as $n$ \\emph{multi-choose} $k$).\n\n\\section{Equivalent Counting Problems - via Bijections} \\label{sec:equi-bij}\n\\subsection{Non-negative solutions}\\label{non-neq-sol-prob}\nFormally, \\mulnom{n}{k} is the number of ways of choosing $k$ objects from a set of $n$ objects where the order is not important but repetitions are allowed. For all $i=1,2,\\cdots,n$, if we denote by $x_i$ the number of copies of $i^{th}$ object we choose, then we have the equation \\begin{equation}\\label{eqn1}\n    x_1+x_2+\\cdots+x_n=k\n\\end{equation} where each $x_i \\geq 0$. Therefore, number of \\emph{non-negative} integral solutions to this equation gives us the required number of ways of choosing $k$ objects from $n$ objects with given conditions. Let's look at an equivalent problem and establish a bijection between these two.\n\n\\subsection{Voting problem}\\label{voting-prob} If $n$ candidates are contesting in an election and there are $k$ voters, how many ways can votes of those $k$ voters be distributed among $n$ candidates? \n\nIf we denote by $x_i$, the number of votes received by $i^{th}$ candidate and there are $k$ voters, we have $x_1+x_2+\\cdots+x_n=k$ and thus, the number of ways of dividing votes among candidates is the number of non-negative solutions to the equation \\ref{eqn1}. Formally, we can define a bijection $f$ from set of solutions to the equation \\ref{eqn1} to set of ways of dividing the votes among $n$ candidates. \n\\begin{description}\n\\item\\underline{Definition:}  $f$ takes the tuple $\\vecx=(x_1,x_2,\\cdots,x_n)$ and assign $x_i$ number of votes to $i^{th}$ candidate where $i=1,2,\\cdots,n$.\n\\item\\underline{Well defined:} $f$ is well defined because for every valid tuple $\\vecx=(x_1,x_2,\\cdots,x_n)$, we have $x_1+\\cdots+x_n=k$ and thus summing over votes received by $i^{th}$ where $i=1,2,\\cdots,n$ will be $k$ votes in total. \n%there is a unique way of dividing the votes among candidates. In other words, for any two distinct way of dividing $k$ votes among $n$ candidates, there must exists an $i$ such that number of votes received $i^{th}$ candidate is different and thus $x_{1_i} \\neq x_{2_i}$. Therefore $\\vecx_1\\neq\\vecx_2$. \n\\item\\underline{Injective:} $f$ is an injection because for every valid way of dividing the votes among candidates, there's a unique solution tuple in which $x_i = $ number of votes received by $i^{th}$ candidate. In other words, for any two $\\vecx_1\\neq\\vecx_2$, there exists an $i\\in[n]$ such that $x_{1_i}\\neq x_{2_i}$ and $i^{th}$ candidate gets different votes. Thus $f(\\vecx_1)\\neq f(\\vecx_2)$.\n\\item\\underline{Surjective:} $f$ is surjective because for every way of dividing $k$ votes among $n$ candidates, there is a pre-image $\\vecx=(x_1,\\cdots,x_n)$ which is a valid solution to the equation \\ref{eqn1} (as there are a total of $k$ voters, sum of number of votes received by each voter must sum up to $k$). \n\\end{description}\nThus $f$ is a bijection from the set of non-negative solutions to $x_1+\\cdots+x_n=k$ to the set of ways of dividing $k$ votes among $n$ candidates.\n\\subsection{Non-decreasing subsequences}\\label{non-dec-subseq-prob} Number of non-decreasing sequences of integers between $1$ and $n$ of length $k$. A non-decreasing sequence is of the form $\\{a_1,a_2,\\cdots,a_k\\}$ where $1\\leq a_1\\leq a_2\\cdots\\leq a_k\\leq n$. Lets define a bijection $f$ from set of non-negative integral solutions to Eqn. \\ref{eqn1} to set of non-decreasing sequences between $1$ and $n$ of length $k$. \n\\begin{description}\n\\item\\underline{Definition:} $f$ takes $\\vecx=(x_1,\\cdots,x_n)$ as input and writes the number $i$ $x_i$ times for all $i=1,2,\\cdots,n$ to obtain a sequence of length $k$.\n\\item\\underline{Well defined:} As $f$ constructs the sequence in increasing order from $1$ to $n$ by writing $i$ $x_i$ times, the resulting sequence will be non-decreasing. Therefore, $f$ is well defined.\n\\item\\underline{Injective:} For every $\\vecx_1\\neq\\vecx_2$, there exists an $i$ such that $x_{1_i} \\neq x_{2_i}$ and thus in the resulting sequences, number $i$ is written different number of times. Therefore, $f$ is injective.\n\\item\\underline{Surjective:} Every non-decreasing sequence of integers between $1$ and $n$ of length $k$ has a pre-image $\\vecx=(x_1,\\cdots,x_n)$  which is a valid solution to equation \\ref{eqn1} (where $x_i$ is the number of times the number $i$ is present in the sequence and as length of sequence is $k$, all $x_i$'s where $i=1,2,\\cdots,n$ sum up to $k$).\n\\end{description}\nThus $f$ is a bijection.\n\\subsection{Stars and bars problem}\\label{star-bar-prob} There are $k$ stars placed horizontally. Find the number of ways to place $n-1$ bars in between those $k$ stars. Lets define a bijection $f$ from set of non-negative integral solutions to Eqn. \\ref{eqn1} to set of ways of placing $n-1$ bars among $k$ stars.\n\\begin{description}\n\\item\\underline{Definition:} $f$ takes $\\vecx=(x_1,\\cdots,x_n)$ as input and place $x_i$ number of stars between $(i-1)^{th}$ bar and $i^{th}$ bar. We leave it as an exercise to prove that $f$ is well-defined, injective and surjective.\n\\end{description}\n\\jsay{Prove that $f$ is a bijection}\n\n\\section{Algebraic expression}\\label{alg-expr}\nSo far in Sec. \\ref{sec:equi-bij}, we have established bijections between \\emph{non-negatives integral} solutions of Eq. \\ref{eqn1} and various other problems and argued that number of ways of solving any particular problem is equal to the number of non-negative integral solutions to Eq. \\ref{eqn1}. In this section, we are interested in coming up with a concrete expression for \\mulnom{n}{k} by solving it's equivalent bijection.\n\n\\paragraph{Method 1} Let's solve the \\emph{stars and bars} problem defined in Sec. \\ref{star-bar-prob}. Let's use the fact that any placement of $n-1$ bars among $k$ stars can be equivalently thought of as a string of length $n+k-1$ over the alphabet $\\{\\star,|\\}$ with $k$ $\\star$'s. Therefore, \\begin{align*}\n    \\textrm{number of ways of placing } n-1 \\textrm{ bars among } k \\textrm{ stars } &= \\textrm{number of such strings}\\\\\n    &= \\binom{n+k-1}{k}\n\\end{align*}\n\n\\paragraph{Method 2} Let's solve the \\emph{Non-decreasing subsequences} problem defined in Sec. \\ref{non-neq-sol-prob}. Let's establish a bijection $f$ from set $\\beta$ of non-decreasing subsequences of integers between $1$ and $n$ of length $k$ to a set $\\Gamma$ of strictly increasing subsequences of integers between $1$ and $n+k-1$ of length $k$. A strictly increasing subsequence is of the form $1\\leq b_1<b_2<\\cdots<b_k\\leq n+k-1$\n\\begin{description}\n\\item{\\underline{Definition:}} $f$ takes as input a non-decreasing subsequence $(a_1,a_2,\\cdots,a_k)$ between $1$ and $n$ and for all $i=1,2,\\cdots,k$ set $b_i = a_i+i-1$ and output the sequence $(b_1,b_2,\\cdots,b_k)$\n\\item{\\underline{Well defined:}} For any $(a_1,a_2,\\cdots,a_k)\\in\\beta$, we have for all $i=1,2,\\cdots,k-1$, \\begin{align*}\n    a_i &\\leq a_{i+1}\\\\\n    a_i+i &\\leq a_{i+1}+i\\\\\n    a_i+i-1 &< a_{i+1}+i\\\\\n    b_i &< b_{i+1}\n\\end{align*}  Therefore, the subsequence $(b_1,\\cdots,b_k)$ is strictly increasing subsequence and thus $f$ is well defined.\n\\item{\\underline{Injective:}} For every non-decreasing subsequence $(a_1,\\cdots,a_k)$, there's a unique strictly increasing subsequence $(b_1,\\cdots,b_k)$ where for all $i=1,\\cdots,k$, $b_i = a_i+i-1$. Therefore $f$ is injective.\n\\item{\\underline{Surjective:}} For every strictly increasing subsequence $(b_1,\\cdots,b_k)$, there's a pre-image $(a_1,\\cdots,a_k)$ which is non-decreasing where for all $i=1,\\cdots,k$, $a_i=b_i-i+1$\n\\end{description}\n\n\nTherefore, $f$ is a bijection. The number of ways of choosing a strictly increasing subsequence $(b_1,\\cdots,b_k)$ between integers $1$ and $n+k-1$ is just choosing $k$ integers from first $n+k-1$ integers and arrange them in one way(increasing order). Therefore number of ways = $\\binom{n+k-1}{k}$. As $f$ is a bijection, therefore, the number of non-decreasing subsequences between $1$ and $n$ of length $k$ are $\\binom{n+k-1}{k}$\n\n\\paragraph{Method 3} Let's solve the \\emph{Voting} problem defined in Sec. \\ref{voting-prob}. Let's ask a slightly modified question. \n\\begin{description}\n\\item \\underline{Question:} How many ways to distribute $m$ votes among $n$ candidates such that each candidate gets at least one vote.\n\\item \\underline{Answer 1:} As every candidate gets at least one vote, let's first distribute one vote each to each of the $n$ candidate and the distribute the remaining $m-n$ votes among $n$ candidates. By the bijection defined in Sec. \\ref{voting-prob}, the number of ways of distributing $m-n$ votes among $n$ candidates is \\mulnom{n}{m-n}  \n\\item \\underline{Answer 2:} Let's interpret votes as $\\star$ s. Then the question essentially reduces to placing $n-1$ bars (since there are $n$ candidates, we divide by placing $n-1$ bars) among $m$ stars (since there are $m$ voters). $i^{th}$ candidate gets votes equal to number of stars between $(i-1)^{th}~|$ and $i^{th}~|$. However, there are two additional constraints \\begin{enumerate}\n    \\item\\label{cond1} A bar cannot be placed in the beginning or in the end (if not then either the first candidate or the last candidate gets $0$ votes)\n    \\item\\label{cond2} We cannot place two $|$ s between same two $\\star$ s (if we place $(i-1)^{th}~|$ and $i^{th}~|$ between same two $\\star$ s, the $i^{th}$ candidate gets $0$ votes)\n\\end{enumerate}\nHence, we have to choose $n-1$ gaps among the $m-1$ gaps (because we have $m+1$ gaps and by cond. \\ref{cond1} we remove two) to place $n-1~|$ s without repetitions (because repeating violates cond. \\ref{cond2}). Therefore, there are $\\binom{m-1}{n-1}$ ways of doing it. Thus \\mulnom{n}{m-n}=$\\binom{m-1}{n-1}$ and by substituting $m=n+k$, we have $$\\textrm{\\mulnom{n}{k}}=\\binom{n+k-1}{n-1}=\\binom{n+k-1}{k}$$\n\\end{description}\n\\section{Identities}\nIn this section, we discuss some identities on \\mulnom{n}{k} and argue their proofs using the idea of either double counting or bijections.\n\\paragraph{Identity 1} $$\\textrm{\\mulnom{n}{k}}=\\textrm{\\mulnom{k+1}{n-1}}$$\n\\begin{proof}\nLet's use the bijection method to prove this. Formally, lets define sets $S_1$ and $S_2$ and count their cardinalities independently and then establish a bijection from $S_1$ to $S_2$ proving that $|S_1|=|S_2|$.\n\\begin{description}\n\\item \\underline{$S_1$:} Configuration of $k~\\star$ s and $n-1~|$ s as described in Sec. \\ref{star-bar-prob}. By the bijection defined in it, $|S_1|=$ \\mulnom{n}{k}\n\\item \\underline{$S_2$:} Configuration of $n-1~\\star$ s and $k~|$ s as described in Sec. \\ref{star-bar-prob}. Again, by the bijection defined in it, $|S_2|=$\\mulnom{k+1}{n-1}\n\\item \\underline{Bijection:} Let's define a bijection $f$ from $S_1$ to $S_2$. $f$ takes a configuration from $S_1$ as input and interpret $\\star$ s as $|$ s and $|$ s as $\\star$ s. Therefore it ends up with a configuration with $n-1~\\star$ s and $k~|$ s which is a configuration is $S_2$. It's easy to observe that $f$ is a bijection.\n\\end{description}\nAs $f$ is a bijection from $S_1$ to $S_2$, we have $|S_1|=|S_2|$. This completes the proof \n\\end{proof}\n\n\\paragraph{Identity 2}\n$$k~\\textrm{\\mulnom{n}{k}}=n~\\textrm{\\mulnom{n+1}{k-1}}$$\n\\begin{proof}\nLet's use the method of double counting to prove this.\n\\begin{description}\n\\item \\underline{Question:} In how many ways can we construct a non-decreasing sequence $1\\leq a_1\\leq a_2\\cdots\\leq a_k\\leq n$ and mark one element?\n\\item \\underline{Asnwer 1:} By the bijection established in Sec. \\ref{non-dec-subseq-prob} we have \\mulnom{n}{k} number of non-decreasing subsequences and for every such subsequence, we can mark any one of the $k$ elements choose. Thus the answer is $k$ \\mulnom{n}{k} \n\\item \\underline{Answer 2:} Firstly, determine the value in $[n]$ which is to be marked. Let $r$ be this value. Now, consider a non-decreasing subsequence between $1$ and $n+1$ with $k-1$ elements. Using $r$ and the non-decreasing sequence chosen, we construct a unique non-decreasing sequence between $1$ and $n$ of length $k$ with $r$ as marked in the following way:\n\nLet $(b_1,b_2,\\cdots,b_{k-1})$ with $1\\leq b_1\\leq b_2\\leq\\cdots\\leq b_{k-1}\\leq n+1$ be the chosen sequence, \n\\begin{itemize}\n    \\item Insert marked-$r$ in the right most position so that the resulting sequence is still sorted.\n    \\item As long as there's an $n+1$ in the sequence, remove it and add it as $r$ to the right of marked-$r$ in the sequence\n\\end{itemize}\nTherefore, number of required sequences \n\\begin{align*}\n    &= \\textrm{ number of ways to choose }r \\times \\substack{\\textrm{ number of non-decreasing sequences of length }\\\\ k-1 \\textrm{ between } 1 \\textrm{ and } n+1}\\\\\n    &= n\\times \\textrm{\\mulnom{n+1}{k-1}}\n\\end{align*}\n\\end{description}\nThis completes the proof\n\\end{proof}\n\n\\begin{ex}\n    \\item Prove the following by combinatorial arguments $$\\textrm{\\mulnom{n}{k}}=\\sum\\limits_{m=1}^{n}\\textrm{\\mulnom{m}{k-1}}$$ \\emph{Hint: Look for bijection to number of non-decreasing subsequences}\n    \\item Prove the following by combinatorial arguments $$\\sum\\limits_{k=0}^{m}\\textrm{\\mulnom{n}{k}}=\\textrm{\\mulnom{n+1}{m}}$$ \\emph{Hint: Look for bijection to Voting problem}\n    \\item Prove the following by combinatorial arguments $$\\textrm{\\mulnom{n}{k}}=\\sum\\limits_{m=0}^{n}\\binom{n}{m}\\textrm{\\mulnom{m}{k-m}}$$\n\\end{ex}\n\n\\Lecture{Jayalal Sarma}{Sept 19, 2020}{06}{Catlan Bijections}{Anshu and Narasimha Sai}{$\\beta$}{JS}\n\n%\\section{Introduction}\nOne of the classic examples to demonstrate the power of bijections is \\emph{Catlan numbers}. The Catlan numbers form a sequence of natural numbers that occur in various counting problems and occurs in several seemingly different contexts. Historically, \\emph{Euler} is the first person to study them. He was interested in counting the number of ways of dividing a polygon into triangles by drawing non-overlapping diagonals. Catlan numbers got their name from \\emph{Eugene Catlan} when he used them to answer the \\emph{Parenthesisation problem} which is the following: Consider a sequence $(a_1,a_2,\\cdots,a_{n+1})$ of $n+1$ numbers, If we have to perform a binary operations $\\odot$ $n$ times among them, how many number of ways are there to parenthesise (or bracket) them using $n$ parenthesis of single type (say $'()'$). In this lecture, we will see a few equivalent problems to this and then arrive at an explicit expression of Catlan numbers.\n\\section{Equivalent Bijections}\nIn this section, we see a few equivalent problems of the \\emph{parenthesisation} problem and argue that answer to each of them is also the \\emph{catlan number}\n\\paragraph{Full binary trees} If we observe the Parenthesisation problem carefully, we notice that every valid parentesisation of those $n+1$ numbers form a \\emph{full binary tree} (a binary tree in which every node have either two children or no children) of $n+1$ leaves and $n$ internal nodes where leaves represents the numbers $a_1,\\cdots,a_{n+1}$ and each internal node corresponds to one operation. Therefore, there's an implicit bijection between the set of valid parenthesisations and full binary trees with $n$ internal nodes. Therefore, \n\\begin{equation}\n    \\substack{\\textrm{number of valid parenthesisations of }\\\\ n+1 \\textrm{ elements }}  = \\substack{\\textrm{number of full binary trees with }\\\\ n \\textrm{ internal nodes}}\n\\end{equation}  \n\n\\paragraph{Balanced parenthesised strings} A balanced parenthesised string of length $2n$ is a string consists of $n$ left brackets $'('$ and $n$ right brackets $')'$ in which every prefix of the string has number of left brackets $'('$ $\\geq$ number of right brackets $')'$. One can easily observe the bijection from set of balanced paranthesised string to valid parenthesisations of $n+1$ numbers\n\n\\paragraph{Euler's problem} Find the number of ways of triangulating a polygon with $n+2$ edges\n\n\\paragraph{Handshaking problem} Consider a scenario where $2n$ people are sitting around a table. How many ways they can shake hands with each other without crossing hands. We leave it as an exercise to establish bijections from \\emph{Euler's} problem to \\emph{Full binary tree} problem and \\emph{handshaking} problem to \\emph{balanced parenthesised strings} problem.\n\\jsay{Establish bijections from \\emph{Euler's} problem to \\emph{Full binary tree} problem and \\emph{handshaking} problem to \\emph{balanced parenthesised strings} problem}\n\n\\section{Algebraic Expression}\nIn this section, we are interested in arriving at a concrete expression of the $n^{th}$ \\emph{catlan number} (denoted by $c_n$). Let's solve another problem and then, by establishing a bijection to one of the above problems, we can arrive at an expression for $c_n$.\n\n\\subsection{Monotone walk on $n\\times n$ grid} Suppose we have a grid of size $n\\times n$. How many ways are there to go from $(0,0)$ to $(n,n)$ by using only downward edges or right edges. A sample path is represented in Fig. \\ref{fig:sample-path}. We observe that each step can increment the value of exactly one of the co-ordinates by $1$. Since we have to move from $(0,0)$ to $(n,n)$, we have to increase the value of both the co-ordinates by $n$ and $n$ and thus irrespective of the path you take, the length of a path from $(0,0)$ to $(n,n)$ must be of length $n+n=2n$.\n\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.4\\linewidth]{images/sample-path.png}\n    \\caption{A path from $(0,0)$ to $(n,n)$ using downward and right edges}\n    \\label{fig:sample-path}\n\\end{figure}\n\nIf we represent each right move as $R$ and each downward move as $D$, one can observe that there's a bijection $f$ from the set of paths to set of strings of length $2n$ over the alphabet $\\{D,R\\}$ with number of $D$'s = number of $R$'s = $n$. Formally, if $(u_0,v_0), (u_1,v_1),\\cdots,(u_{2n},v_{2n})$ represents the path where $(u_0,v_0)=(0,0)$ and $(u_{2n},v_{2n})=(n,n)$, and $b=b_1b_2\\cdots b_{2n}$ represents the string where each $b_i$ is either $D$ or $R$, our bijection $f$ takes a path as input and sets $b_i$ as\n$$b_i=\\begin{cases}\nD &\\mbox{if } u_i = u_{i-1}+1\\\\\nR &\\mbox{if } v_i = v_{i-1}+1\n\\end{cases}$$\n\\begin{description}\n\\item \\underline{Well defined:} As we have exactly $n$ $x$ co-ordinate increments and $n$ $y$ co-ordinate increments, we will have exactly $n$ $D$'s and $n$ $R$'s in our string and thus $f$ is well defined.\n\\item \\underline{Injective:} Two different paths from $(0,0)$ to $(n,n)$ will different in at least one $(u_{i-1},v_{i-1})$ to $(u_i,v_i)$ transition where $i=1,2,\\cdots,2n$, their corresponding strings under $f$ will differ in at least $i^{th}$ position and thus $f$ is injective.\n\\item \\underline{Surjective:} Every string over $\\{D,R\\}$ of length $2n$ with equal number of $D$'s and $R$'s has a pre-image under $f$ which is defined by $(u_0,v_0)=(0,0)$ and $(u_i,v_i)$ is $(u_{i-1}+1,v_{i-1})$ if $b_i=R$ and $(u_{i-1},v_{i-1}+1)$ if $b_i=D$. As there will be $n$ $D$'s and $n$ $R$'s, $(u_{2n},v_{2n})=(n,n)$ and thus $f$ is surjective .\n\\end{description} \nThus $f$ is bijection. As we have number of string over $\\{D,R\\}$ of length $2n$ with equal number of $D$'s and $R$'s equal to $\\binom{2n}{n}$ (select $n$ positions out of $2n$ available and fill them with $D$'s and the rest with $R$'s). Thus the number of paths from $(0,0)$ to $(n,n)$ with only downward and rightward movements is $\\binom{2n}{n}$.\n\nLets ask a slightly question. How many ways are there to go from $(0,0)$ to $(n+1,n-1)$ using only downward or right edges.Using a similar arguments as above, we can come up with a bijection to set of string over $\\{D,R\\}$ of length $2n$ with $n+1$ $D$'s and $n-1$ $R$'s. Therefore number of required paths are $\\binom{2n}{n+1}=\\binom{2n}{n-1}$\n\n%\\Lecture{Jayalal Sharma}{Sept 19, 2020}{07}{Catalan Bijections}{Anshu Yadav}{$\\alpha$}{JS}\n\n\\subsection{Diagonal avoiding paths and Catlan numbers}\n%Path coordinate Notation: \nIn this section we explore the connection  between the above paths that we discussed and the Catalan number. \nLet us ask this question:\nHow many paths are there in the grid from $(0,0)$ to $(n,n)$ that avoids crossing the diagonal? \n\nWe first define what \\textit{crossing the diagonal} means. The diagonal consists of the points of the form $(i,i)$, $i\\in\\{0,\\ldots, n\\}$. A path $((u_0,v_0), \\ldots, (u_{2n},v_{2n}))$ is said to be crossing the diagonal if it \\textit{intersects} through the diagonal and goes to some point below the diagonal. Mathematically, a path is a diagonal crossing path if $\\exists~i$ such that $u_i>v_i$. In particular, $\\exists i: u_i = v_i+1$ (refer fig. \\ref{fig:diagonal-crossing-path} for example. Any diagonal crossing path must necessarily pass through one of the red dots). Equivalently, in a diagonal avoiding path $\\forall i\\in\\{0,\\ldots, 2n\\}, v_i\\ge u_i$. A sample \\emph{diagonal-avoiding path} is shown in the fig. \\ref{fig:diagonal-avoiding-path} %\\anote{explain $u_i = v_i+1$}\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.7\\linewidth]{images/diagonal-crossing.jpeg}\n    \\caption{Diagonal crossing paths. Note that path in (a) is crossing the diagonal at $(0,0)$}\n    \\label{fig:diagonal-crossing-path}\n\\end{figure}\n\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.4\\linewidth]{images/diagonal-avoiding-path.png}\n    \\caption{A diagonal avoiding path. Observe that it can still touch the diagonal}\n    \\label{fig:diagonal-avoiding-path}\n\\end{figure}\n\nBefore computing this number, an obvious question is what is the connection between such restricted paths and Catalan number. It turns out that the set of diagonal avoiding paths from $(0,0)$ to $(n,n)$ is in bijection with the set of balanced paranthesized strings of length $2n$. Hence, to count the number of balanced paranthesized strings of length $2n$, which is also the Catalan number, we only need to count the diagonal avoiding paths from $(0,0)$ to $(n,n)$. Let us first establish the bijection between the two.\n\n\\subsection{Bijection from Diagonal avoiding paths to Balanced parenthesisation problem}\nIntuitively, the bijection can be defined as follows: for any given balanced parenthesized string $w = w_1w_2\\ldots w_{2n}$, the corresponding path from $(0,0)$ to $(n,n)$ is obtained by starting from position $(0,0)$, and scanning the string from left to right. Take  right move whenever $`('$ is encountered and a down move for $`)'$. Formally we define the bijection as follows:\n\\medskip{}\n\n\\noindent\\underline{Defining the bijection:} Let $P$ be the set of diagonal avoiding paths from $(0,0)$ to $(n,n)$  and $B$ be the set of balanced paranthesized  strings of length $2n$ over the alphabets $\\{(,)\\}$. Define the bijection $\\phi:B\\rightarrow P$ as follows:\\\\\nFor $w=w_1 w_2 \\ldots w_{2n}\\in B$, $\\phi(w) = (u_0,v_0), (u_1,v_1), \\ldots, (u_i, v_i), \\ldots, (u_{2n}, v_{2n})$, where \n\\begin{enumerate}\n    \\item $(u_0,v_0)=(0,0)$ \n    \\item $\\forall i\\in\\{1,2,\\ldots, 2n\\}$\\\\\n    \\[\n    (u_i, v_i) = \n    \\begin{cases}  \n    (u_{i-1}+1, v_{i-1})& ~~~~\\text{if }w_i=)\\\\\n    (u_{i-1}, v_{i-1}+1)&~~~~\\text{if }w_i=(\n    \\end{cases}\n    \\]\n    % $(u_i, v_i) = (u_{i-1}+1, v_{i-1})~~~~\\text{if }w_i='('$\\\\\n    % $(u_i, v_i) = (u_{i-1}, v_{i-1}+1)~~~~\\text{if }w_i=')'$\n\\end{enumerate}\n\\underline{Proof of bijection}\n\\begin{description}\n\\item \\textit{Well-defined:} From the above description, given any string $w$, $\\phi(w)$ is uniquely defined. Further, for any string $w\\in B$, since the number of $'('$ is same as  the number of $')' = n$, the corresponding path has $n$ right and $n$ down moves and hence it ends at $(n,n)$. Also, since the number of left brackets is greater than or equal to the number of right brackets in any prefix of $w$, for all $i\\in[2n]$, $v_i\\ge u_i$. This shows that $\\forall w\\in B, \\phi(w)\\in P$. Hence,  $\\phi$ is well-defined.\n\\item \\textit{Injective:} Let $w, w'$ be two different strings in set $B$. Then $\\exists~$ an index $i\\in[2n]$ where $w_i\\ne w'_i$. Hence $\\phi(w)$ and $\\phi(w')$ also differ at the $i$th step, where one of the paths takes one step right while the other takes one step down. \n\\item \\textit{Surjective:} \nGiven any path $((0,0), (u_1, v_1), \\ldots, (u_{2n}, v_{2n}))$ the corresponding string $w\\in B$ is defined as follows:\\\\\n$\\forall i\\in[2n]$\n\\[\nw_i = \n\\begin{cases}\n`(`& ~~~~~\\text{if } (u_i, v_i) = (u_{i-1}, v_{i-1}+1)\\\\\n`)`& ~~~~~\\text{if } (u_i,v_i) = (u_{i-1}+1, v_{i-1})\n\\end{cases}\n\\]\nWe can verify that the string $w$ indeed is in set $B$, because firstly, for any path in $P$, $\\forall i, v_i\\ge u_i$ and hence by definition, number of left brackets $`(`$ in $w$ is greater than or equal to number of right brackets, $`(`$ in any prefix of $w$. Secondly, for any path to reach from $(0,0)$ to $(n,n)$ it must have $n$ right moves (increase in 2nd coordinate) and $n$ down moves (increase in 1st coordinate) and hence $w$ must have $n$ left brackets and $n$ right brackets.\n\\end{description}\n\n\n% Properties:\n% %$\\phi(w_1)=u_1$ and $\\phi(w_2)=u_2$ will be same till $(i-1)$th step, i.e. $(u_{1,(i-1)}, v_{1,(i-1)}=(u_{2,(i-1)}, v_{2,(i-1)}$ for $j=0$ to $i-1$.\n\n\\subsection{Counting the number of diagonal avoiding paths} \nHaving established the bijection between Catalan number and diagonal avoiding paths, we get  \n\\begin{equation}\n\\label{eq:catalan-expr-1}\n    C_n = \\# \\text{ of diagonal avoiding paths from } (0,0) to (n,n) \n\\end{equation}\nSo, our next task is to count the number of diagonal avoiding paths from $(0,0)$ to $(n,n)$. \nTo count this, we take following approach. Let us call the diagonal avoiding paths as \\textit{good} paths and diagonal crossing paths as \\textit{bad} paths. Then,\n\\begin{equation}\n\\label{eq:no-of-good-paths}\n\\Large\n    \\substack{\\text{\\# of diagonal avoiding paths }\\\\ \\text{from } (0,0) \\text{ to } (n,n)}  = \\substack{\\text{\\# of paths }\\\\ \\text{from } (0,0) \\text{ to } (n,n)} - \\substack{\\text{\\# of diagonal crossing paths }\\\\ \\text{from } (0,0) \\text{ to } (n,n)}\n\\end{equation}  \n\nSo, now our revised goal is to count the number of diagonal crossing paths from $(0,0)$ to $(n,n)$. How do we do that? Here again bijection plays an important role. The idea is to translate diagonal crossing paths into  different kind of paths which are easy to count. \n\nLet us define the following path translation:  Let $\\pi=(0,0), (u_1,v_1), \\ldots, (u_{2n}, v_{2n})$ be  a diagonal crossing path. Then there must exist $i$ such that $u_i = v_i+1$. There can be many such indices as the path can cross the diagonal multiple times. Choose $i$ to be the least such index. Let $u_i = \\ell$, then the first co-ordinate after crossing the diagonal is $(\\ell, \\ell-1)$. Let us call this point $P$ (refer fig. \\ref{fig:reflecting-path}(a)). Then to find the translated path we reflect the part of the path $\\pi$ after point $P$ w.r.t. the main diagonal. \n\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.7\\linewidth]{images/reflecting-path.jpeg}\n    \\caption{Point P in a diagonal crossing path and the reflected path after P}\n    \\label{fig:reflecting-path}\n\\end{figure}\n\nMore precisely, we can divide the diagonal crossing path into two stretch $S_1, S_2$, where $S_1$ is the part of the path between $(0,0)$ to $P$ and $S_2$ is the part of the path between $P$  to $(n,n)$. \nThen to translate $\\pi$ into a new path, replace $S_2$ with $S_2'$  to get a new path $\\pi' = S_1S_2'$. The replacement $S_2'$ is defined as follows:\n\\begin{itemize}\n    \\item[-] replace downward edges with right edges and \n    \\item[-] replace right edges with downward edges.\n\\end{itemize} Refer fig. \\ref{fig:reflecting-path}(b)\nWe can observe that the new path $\\pi'$ described in this way is always between $(0,0)$ to $(n+1, n-1)$. The argument for this goes as follows:\n\nOriginally (in $S_2$), $(\\ell, \\ell-1)$ goes to $(n,n)$ which means it takes $(n-\\ell)$ downward moves and $(n-\\ell+1)$ right moves. Since, we are swapping the right and downward moves to get $S_2'$ from $S_2$, there are $(n-\\ell+1)$ downward moves and $(n-\\ell)$ right moves from point $P=(\\ell, \\ell-1)$ in $S_2'$. Thus, $S_2'$ goes from $(\\ell, \\ell-1)$ to $(\\ell+n-\\ell+1, \\ell-1+n-\\ell) = (n+1, n-1)$ and hence, $\\pi' = S_1S_2'$ is a path from $(0,0)$ to $(n+1, n-1)$. \n\nThus we have established that any diagonal crossing path from $(0,0)$ to $(n,n)$ maps to a path from $(0,0)$ to $(n+1,n-1)$ after applying the transformation described above. The converse is also true, i.e., given any path from $(0,0)$ to $(n+1, n-1)$, we can translate it back to a diagonal crossing path from $(0,0)$ to $(n,n)$ by using the same reflection technique.  Thus, we get a bijection between the set of diagonal crossing paths from $(0,0)$ to $(n,n)$ to the set of paths from $(0,0)$ to $(n+1,n-1)$. We formally define the translation and prove that it is indeed a bijection.\n\\begin{description}\n\\item \\underline{Bijection:}\nLet $A$ be the set of diagonal crossing paths from $(0,0)$ to $(n,n)$ and $B$ be the set of paths from $(0,0)$ to $(n+1,n-1)$. Then the mapping $\\phi:A\\rightarrow B$ is formally defined as follows: \n\\\\\nLet $\\pi=(0,0), (u_1,v_1), \\ldots, (u_{2n}, v_{2n})$ and $(u_i, v_i)$ be the first point when $\\pi$ crosses the diagonal. Then $\\phi(\\pi) = \\pi'=(0,0), (u'_1,v'_1), \\ldots, (u'_{2n}, v'_{2n})$ is given by:\n\\begin{enumerate}\n    \\item $\\forall 1\\le j\\le i, (u'_j, v'_j) = (u_j, v_j)$\n    \\item $\\forall i+1\\le j\\le 2n$, \n    \\[\n    (u'_j, v'_j) = \n    \\begin{cases}\n    (u'_{j-1}+1, v'_{j-1})& ~~~~~\\text{if } (u_j, v_j) = (u_{j-1}, v'_{j-1}+1)\\\\\n    (u'_{j-1}, v'_{j-1}+1)& ~~~~~\\text{if } (u_j, v_j) = (u_{j-1}+1, v'_{j-1})\n    \\end{cases}\n    \\]\n\\end{enumerate}\n% We can verify that $\\phi:A\\rightarrow B$ satisfies all the properties of a bijection as follows:\n\\item \\textit{Well-defined:} We already observed that any path $\\pi\\in A$ from $(0,0)$ to $(n,n)$ maps to a path $(0,0)$ to $(n+1,n-1)$. Hence $\\phi$ is well defined.\n\\item \\textit{Injection:} Consider two different diagonal crossing paths $\\pi_1$ and $\\pi_2$. Let $\\pi_1 = S_{1,1}S_{1,2}$ and $\\pi_2 = S_{2,1}S_{2,2}$, where the two components $S_{i,1}$ and $S_{i,2}$ for $i\\in\\{1,2\\}$ are as defined before. Then following two cases are possible:\n\\begin{itemize}\n    \\item Case1: $S_{11}\\ne S_{21}$. Then $\\pi_1'\\ne \\pi_2'$, because the first component is copied as it is in the translation, i.e. $\\pi_1' = S_{1,1}S_{1,2}'$ and $\\pi_2' = S_{2,1}S_{2,2}'$.\n    \\item Case2: $S_{11}= S_{21}$, but $S_{12}\\ne S_{22}$. In this case $S_{12}'\\ne S_{22}'$ because of the way it is defined, i.e. for every right move there is a downwards move and vice-versa. Hence, $\\pi_i'\\ne \\pi_2'$.\n\\end{itemize}\n\\item \\textit{Surjective:} Given any path $\\pi'$ from  $(0,0)$ to $(n+1,n-1)$, we can construct the corresponding path $\\pi$ from $(0,0)$ to $(n,n)$, such that $\\phi(\\pi) = \\pi'$, as follows.\\\\\nLet $\\pi'=(0,0), (u'_1,v'_1), \\ldots, (u'_{2n}, v'_{2n})$. Since $\\pi'$ goes to $(n+1, n-1)$ which is below the diagonal there must exist $i$ such that $(u'_i,v'_i)$ is below the diagonal. Again, there can be many such indices. Take $i$ to be the first such index. Same as before, let $\\pi' = S_1'S_2'$, where $S_1'$ is the path from $(0,0)$ to $(u_i', v_i')$ and  $S_1'$ is the path from $(u_i',v_i')$ to $(u_{2n}', v_{2n}')$. Then $\\pi = S_1'S_2$ where $S_2$ is obtained from $S_2'$ by swapping the right and downwards moves. Mathematically, let $\\pi=(0,0), (u_1,v_1), \\ldots, (u_{2n}, v_{2n})$. Then\n\\begin{enumerate}\n    \\item $\\forall j\\le i$, $(u_j, v_j) = (u_j', v_j')$\n    \\item $\\forall~i+1\\le j\\le 2n$\n    \\[\n    (u_j, v_j) =\n    \\begin{cases}\n    (u_{j-1}+1, v_{j-1}) & ~~~~~\\text{if } (u_j', v_j') = (u_{j-1}', v_{j-1}'+1)\\\\\n    (u_{j-1}, v_{j-1}+1) & ~~~~~\\text{if } (u_j', v_j') = (u_{j-1}'+1, v_{j-1}')\n    \\end{cases}\n    \\]\n\\end{enumerate}\nAgain by the same argument as before it can be verified that $\\pi$ is a diagonal crossing path from $(0,0)$ to $(n,n)$. We write it here for completeness. Let $(\\ell, \\ell-1)$ be the first point when $\\pi'$ crosses the diagonal. Then since the path from $(0,0)$ to $(\\ell, \\ell-1)$ remains as it is in $\\pi$, it is a diagonal crossing path. Further since $\\pi'$ is path from $(0,0)$ to $(n+1, n-1)$, it takes $n+1-\\ell$ downward steps and $n-\\ell$ right steps from $(\\ell, \\ell-1)$. Hence, $\\pi$ takes $n+1-\\ell$ right and $n-\\ell$ downward steps from $(\\ell, \\ell-1)$. Thus, $\\pi$ ends at $(\\ell+n-\\ell, \\ell-1+n+1-\\ell) = (n,n)$. \n\\end{description}\n\nThus, we have established a bijection between the set of diagonal crossing paths from $(0,0)$ to $(n,n)$ and the set of  paths from $(0,0)$ to $(n+1,n-1)$. Hence, \n\\begin{eqnarray*}\n    \\# \\text{of diagonal crossing paths from } (0,0) \\text{ to } (n,n) &=& \\# \\text{of paths from } (0,0) \\text{ to } (n+1,n-1)\\\\\n    &= &{2n\\choose n+1}\n\\end{eqnarray*}\nHence, from~\\eqref{eq:catalan-expr-1},\\eqref{eq:no-of-good-paths},\n\\begin{align*} %\\label{eq:no-of-good-paths-2}\nC_n &= \\# \\text{of diagonal avoiding paths from} (0,0) \\text{ to } (n,n)\\\\\n%\\Large\n %   \\substack{\\text{\\# of diagonal avoiding paths }\\\\ \\text{from } (0,0) \\text{ to } (n,n)} \n     &= \\Large \\substack{\\text{\\# of paths }\\\\ \\text{from } (0,0) \\text{ to } (n,n)} - \\Large\\substack{\\text{\\# of diagonal crossing paths }\\\\ \\text{from } (0,0) \\text{ to } (n,n)}\\\\\n    &= {2n\\choose n} - {2n\\choose n+1}\\\\\n    & = {2n\\choose n} - \\frac{n}{n+1}{2n\\choose n}\\\\\n    &=\\frac{1}{n+1}{2n\\choose n}\n\\end{align*}  \n\nHere, in the second last line, we have used the identity: $${2n\\choose n+1} = \\frac{n}{n+1}{2n\\choose n}.$$\n\n\n\n\n\n\n\n\n\n% Let us define the following path translation: Let $p=(0,0), (u_1,v_1), \\ldots, (u_{2n}, v_{2n})$ be  a diagonal crossing path which goes below the diagonal at point $(u_i, v_i)$ for for the first time. Then, translate the path $p$ to a new path $p' = (u'_0, v'_0), (u'_1,v'_1), \\ldots, (u'_{2n}, v'_{2n})$ by \\textit{reflexing} $p$ between  $(u_i, v_i)$ and $(u_{2n}, v_{2n})$ in the sense that whenever $p$ goes right, $p'$ goes down, and whenever $p$ goes down, $p'$ moves right. Mathematically,\n% \\begin{enumerate}\n%     \\item $\\forall 1\\le j\\le i, (u'_j, v'_j) = (u_j, v_j)$\n%     \\item $\\forall i+1\\le j\\le 2n$, \n%     \\[\n%     (u'_j, v'_j) = \n%     \\begin{cases}\n%     (u'_{j-1}+1, v'_{j-1})& ~~~~~\\text{if } (u_j, v_j) = (u_{j-1}, v'_{j-1}+1)\\\\\n%     (u'_{j-1}, v'_{j-1}+1)& ~~~~~\\text{if } (u_j, v_j) = (u_{j-1}+1, v'_{j-1})\n%     \\end{cases}\n%     \\]\n% \\end{enumerate}\n% In the example, we can see that the translated path ends up at $(n+1, n-1)$. In general, we can prove the following: The above defined translation of any diagonal crossing path $p$ from $(0,0)$ to $(n,n)$ always ends at $(n+1, n-1)$.\n% \\begin{proof}\n% Let $p$ croses the diagonal for the first time at $(u_i, v_i)$. Then \n% $$u_i = v_i+1.$$ \n% From $(u_i, v_i)$, $p$ moves $(n-u_i)$ steps down and $(n-v_i)$ steps in the right to reach $(n,n)$. Hence, the translated path $p'$ takes $(n-u_i)$ steps right and $(n-v_i)$ steps down from $(u_i, v_i)$ and ends at $$ (u_i+n-v_i, v_i+n-u_i) = (n+(u_i-v_i), n+(v_i-u_i)) = (n+1, n-1)$$. \n% \\end{proof}\n\n% Conversely, any path $p'$ from $(0,0)$ to $(n+1, n-1)$ can be mapped to a diagonal crossing path from $(0,0)$ to $(n,n)$. Intuitively, this can be done by again reflecting it  from the point $(u_i, v_i)$, where it crosses the diagonal for the first time. Note that such a point always exist because to reach the point $(n+1, n-1)$ $p'$ must cross the diagonal because $(n+1, n-1)$ is below the diagonal. Using the same argument as above, it can be shown that this translates $p'$ into a diagonal crossing path from $(0,0)$ to $(n,n)$.\n\n% Thus, we get a bijection between the set of diagonal crossing paths from $(0,0)$ to $(n,n)$ and the set of paths from $(0,0)$ to $(n+1,n-1)$ defined formally as follows:\\\\\n\n% Definition: Let $A$ be the set of diagonal crossing paths from $(0,0)$ to $(n,n)$ and $B$ be the set of paths from $(0,0)$ to $(n+1,n-1)$. Then a bijection $\\phi:A\\rightarrow B$ is defined as follows:\n\n% For any path $p = (u_0, v_0), (u_1, v_1), \\ldots, (u_{2n}, v_{2n})\\in A$, let $(u_i, v_i)$ be the point where the path crosses the diagonal for the first time. That is, \n% \\begin{enumerate}\n%     \\item $\\forall j<i, v_j\\ge u_j$, and\n%     \\item $u_i=v_i+1$\n% \\end{enumerate}\n% Then $\\phi(p)=p' = (u'_0, v'_0), (u'_1, v'_1), \\ldots, (u'_{2n}, v'_{2n})$, where\n% \\begin{enumerate}\n%     \\item \n% \\end{enumerate}\n\\begin{exercise}\n\\item Try to establish a bijection between the set of different possible polygon triangulation in a polygon of $n+2$ nodes and the set of binary trees with $n$ internal nodes.\n\n\\textit{Hint: associate each internal node with a triangle in a triangulation. Then, each internal node will have degree three, which is the case for full binary tree, except for the leaves. Leaves will correspond to those triangles whose one of the edge is the boundary of the polygon.}\n\\end{exercise}\n\n\\Lecture{Jayalal Sarma}{Sept 19, 2020}{07}{From Bijections to PIE}{Anshu Yadav}{$\\beta$}{JS}\n\n%\\section{Introduction}\nIn this lecture, we will continue with the use of bijections and use it in formally proving the two identities that we discussed in class and then see their relationship to the Principal of Inclusion and Exclusion. \n\n\\section{The Identities}\nRecall that we proved following two identities in one of the discussion sessions\n\\begin{align}\n     \\sum_{k=0}^n (-1)^k{n\\choose k} &= 0 \\label{REV1}\\\\ \n     \\sum_{k=0}^m (-1)^k{n\\choose k} &= (-1)^m{n-1\\choose m} \\label{REV2}\n\\end{align}\nIn this section, we will see the proofs for the above equations is detail\n\\subsection{Proof for Eqn. \\eqref{REV1}} \\label{subsec:identity-even-odd-1}\n$$\\sum_{k=0}^n (-1)^k{n\\choose k} = 0$$\n\\begin{proof}\n    The LHS counts the number of even sized subsets of $[n]$ with positive sign and odd size subsets with negative sign. Then we proved the result using bijection between even sized and odd sized subsets of $[n]$. Hence, we get 0 on RHS. Let us formally define the bijection here.\n    \n    Let $E$ be the set of all even sized subsets of $[n]$ and $O$ be the set of all odd sized subsets of $[n]$. Then the bijection  $\\phi_i:E\\rightarrow O$ is defined with respect to an element $i\\in[n]$ as follows.\n    \n    Let $X\\subseteq [n]$, such that $|X|$ is even. Then \n    \\[\n        \\phi_i(X) = \n        \\begin{cases}\n            X\\setminus \\{i\\} & ~~~~~\\text{ if } i\\in X\\\\\n            X\\cup\\{i\\} & ~~~~~\\text{ if } i\\not\\in X\n        \\end{cases}\n    \\]\n    \\underline{Proof of bijection:}\n    \\begin{description}\n        \\item \\textit{Well-defined:} Given any even sized subset $X$, there are two possibilities: (i) $i\\in X$, (ii) $i\\not\\in X$. In first case, $i$ is removed from $X$, hence its size reduces by one and becomes odd. In the second case, $i$ is added, hence the size of the subset increases by one and becomes odd. Hence, $\\phi$ is well defined.\n        \\item \\textit{Injective:} Let $X$ and $X'$ be two distinct subsets of $[n]$. Then $\\exists j\\in[n]$ such that $j$ is present in exactly one of the two subsets. Wlog, let $j\\in X$ and $j\\not\\in X'$. Now, if $j\\neq i$, then $j\\in \\phi(X)$ and $j\\not\\in \\phi(X')$ and hence $\\phi(X)\\neq \\phi(X')$. On the other hand, if $j=i$, then $j\\not\\in \\phi(X)$ and $j\\in \\phi(X')$. Hence, $\\phi(X)\\neq \\phi(X')$.  \n        \\item \\textit{Surjective:} Let $Y\\in O$ be an odd sized subset of $[n]$. From $Y$, we can recover $X$ such that $\\phi(X) = Y$ by the same operation as in $\\phi$. That is, \n        \\[\n        X= \\begin{cases}\n            Y\\setminus \\{i\\} & ~~~~~\\text{ if } i\\in Y\\\\\n            Y\\cup\\{i\\} & ~~~~~\\text{ if } i\\not\\in Y\n        \\end{cases}\n        \\]\n        It can easily be verified that in both the cases, $X$ is an even sized subset of $[n]$.\n    \\end{description}\n    This completes the proof.\n\\end{proof}\n%\n%\n\\subsection{Proof for Eqn. \\eqref{REV2}} \\label{subsec:identity-even-odd-2}\n$$\\sum_{k=0}^m (-1)^k{n\\choose k} = {n-1\\choose m}$$\n\\begin{proof}\nNow we look at the second identity which is even more interesting. To prove this identity we use \\emph{almost bijection} where the bijection is between a set and subset of another set.\n\nIn words, the identity to prove, can be described as\n$$\\Large\\substack{\\# \\textrm{ of even sized subsets of  $[n]$}\\\\  \\textrm{of size atmost $m$}} - \\substack{\\# \\textrm{ of odd sized subsets of $[n]$} \\\\ \\textrm{of size atmost $m$}} = (-1)^m{n-1\\choose m}.$$ Clearly, there cannot be a bijection between the two sets (even sized subsets and odd sized subsets) in this case, since their difference is non-zero. This is where we use almost bijection.\n\nWe use following case analysis. \n\\begin{description}\n\\item \\underline{\\textbf{Case1:} $m$ is even:} Then the identity to prove is:\n\\begin{equation} \\label{eq:even-odd}\n    \\sum_{k=0}^m (-1)^k{n\\choose k} = {n-1\\choose m}\n\\end{equation}\nThis can be interpreted as \n\\begin{equation} \\label{eq:even-odd-1}\n    \\sum_{\\substack{k=0,\\\\k\\text{ is even}}}^m {n\\choose k} -  \\sum_{\\substack{k=1,\\\\k\\text{ is odd}}}^{m-1} {n\\choose k} = {n-1\\choose m}\n\\end{equation}\nLet $E$ be the set of all the even sized subsets of $[n]$ of size at most $m$ and $O$ be the set of odd sized subsets of $[n]$ having size at most $m-1$. Then, Eqn.~\\eqref{eq:even-odd-1} can intuitively interpreted as follows: there is a subset $E'\\subseteq E$, such that $E'$ is in bijection with $O$ and $|E\\setminus E'| = {n-1\\choose m}$. Thus, we have three tasks at hand\n\\begin{itemize}\n    \\item identify the set $E'$, and\n    \\item define and prove the bijection between $E'$ and $O$.\n    \\item prove that $|E\\setminus E'| = {n-1\\choose m}$\n\\end{itemize}\n\\underline{Defining the set $E'$:} Set $E'$ is the union of two sets: \n$$E' = \\{X\\subseteq [n]: |X| \\textrm{ is even and } |X|\\le m-2\\}\\cup\\{X\\subseteq [n]: i\\in X \\textrm{ and } |X| = m\\}$$\n\\underline{Defining the bijection:} The bijection $\\phi:E'\\rightarrow B$ is defined in the same way as we defined it for first identity. That is, for $X\\in E'$,\n\\[\n\\phi(X) = \n\\begin{cases}\nX\\setminus \\{i\\} & ~~~~~\\text{ if } i\\in X\\\\\nX\\cup\\{i\\} & ~~~~~\\text{ if } i\\not\\in X\n\\end{cases}\n\\]\n\\underline{Proof of bijection}\n\\begin{description}\n\\item \\textit{Well-defined:} Let $X\\in E'$, then (i) if $|X|\\le m-2$, then $|\\phi(X)|$ is odd and $|\\phi(X)|\\le m-1$, (ii) if $|X| = m$, then $i\\in X$, hence $\\phi(X) = X\\setminus \\{i\\}$. This implies $|\\phi(X)| = m-1$. Thus, in both the cases $\\phi(X)\\in O$.\n\\item \\textit{Injective:} Since, the function is same as in the previous case, the same argument for injectivity works.\n\\item \\textit{Surjective:} Let $Y\\in O$ be an odd sized subset of $[n]$. From $Y$, we can recover $X\\in E'$ such that $\\phi(X) = Y$ by the same operation as in $\\phi$. That is, \n \\[\n X= \n \\begin{cases}\nY\\setminus \\{i\\} & ~~~~~\\text{ if } i\\in Y\\\\\nY\\cup\\{i\\} & ~~~~~\\text{ if } i\\not\\in Y\n \\end{cases}\n \\]\n It can easily be verified that in both the cases, $|X|$ is even. \n In first case, since $|Y|\\le m-1, |X|\\le m-2$, hence $X\\in E'$. In second case, since $i\\not\\in Y$ and $|Y|\\le m-1$, $|X|\\le m$ and $i\\in X$. Hence $X\\in E'$, by definition.\n\\end{description}\nThis proves the bijection between $E'$ and $O$. \n\n\\underline{Proof for: $|E\\setminus E'| = {n-1\\choose m}$}\n\nFrom the above definitions, $E\\setminus E' = \\{X\\subseteq [n]: |X| = m, i\\not\\in X\\}$. This can be interpreted as $E\\setminus E' = \\{X\\subseteq [n]\\setminus \\{i\\}: |X| = m\\}$. Hence, $|E\\setminus E'| = {n-1\\choose m}$.\n\n\\item \\underline{\\textbf{Case2:} $m$ is odd:} In this case the identity to prove is:\n\\begin{equation}\n\\label{eq:even-odd-3}\n    \\sum_{k=0}^m (-1)^k{n\\choose k} = - {n-1\\choose m}\n\\end{equation}\nThis can be interpreted as \n\\begin{equation}\n\\label{eq:even-odd-2}\n    \\sum_{\\substack{k=0,\\\\k\\text{ is even}}}^{m-1} {n\\choose k} -  \\sum_{\\substack{k=1,\\\\k\\text{ is odd}}}^{m} {n\\choose k} = -{n-1\\choose m}\n\\end{equation}\nEquivalently,\n\\begin{equation}\n\\label{eq:odd-even-1}\n    \\sum_{\\substack{k=1,\\\\k\\text{ is odd}}}^{m} {n\\choose k} - \\sum_{\\substack{k=0,\\\\k\\text{ is even}}}^{m-1} {n\\choose k}  = {n-1\\choose m}\n\\end{equation}\nThis time the set of odd sized subsets of $[n]$ of size at most $m$ is bigger than the even sized subsets of $[n]$ of size at most $m$.\nThe proof is same as that for the case of even $m$. \nLet $E$ be the set of all the even sized subsets of $[n]$ of size at most $m-1$ (since $m$ is odd) and $O$ be the set of odd sized subsets of $[n]$ having size at most $m$. Then~\\eqref{eq:odd-even-1} can be interpreted as follows: there is a subset $O'\\subseteq O$, such that $E$ is in bijection with $O'$ and $|O\\setminus O'| = {n-1\\choose m}$.\n  \nThus, we have two task at hand\n\\begin{itemize}\n    \\item identify the set $O'$, and\n    \\item define and prove the bijection between $E$ and $O'$.\n    \\item prove that $|O\\setminus O'| = {n-1\\choose m}$\n\\end{itemize}\n\\underline{Defining the set $O'$:} Set $O'$ to be the union of two sets: \n$$O' = \\{Y\\subseteq [n]: |Y| \\text{ is odd and } |Y|\\le m-2\\}\\cup\\{Y\\subseteq [n]: i\\in Y \\text{ and } |Y| = m\\}$$\n\\underline{Defining the bijection:} The bijection $\\phi:E\\rightarrow O'$ is defined in the same way as we defined it for first identity. That is, for $X\\in E$,\n\\[\n\\phi(X) = \n\\begin{cases}\nX\\setminus \\{i\\} & ~~~~~\\text{ if } i\\in X\\\\\nX\\cup\\{i\\} & ~~~~~\\text{ if } i\\not\\in X\n\\end{cases}\n\\]\n\\underline{Proof of bijection}\n\\begin{description}\n\\item \\textit{Well-defined:} Let $X\\in E$, then $\\phi(X)$ is of odd size because either an element is added or removed from $X$, which is of even size. Now, (i) if $i\\in X$, then $\\phi(X) = X\\setminus\\{i\\}$. Hence, $|\\phi(X)|\\le m-2$ (because $|X|\\le m-1$) which implies $\\phi(X)\\in O'$ (ii) if $i\\not\\in X$, then, $\\phi(X) = X\\cup \\{i\\}$. This implies $|\\phi(X)| \\le m$. But since, $i\\in \\phi(X)$, $\\phi(X)\\in O'$. This proves that $\\phi$ is well- defined.\n\\item \\textit{Injective:} Since, the function is same as in sub section~\\ref{subsec:identity-even-odd-1}, the same argument for injectivity works.\n\\item \\textit{Surjective:} Let $Y\\in O'$ be an odd sized subset of $[n]$. From $Y$, we can recover $X\\in E$ such that $\\phi(X) = Y$ by the same operation as in $\\phi$. That is, \n \\[\n X= \n \\begin{cases}\nY\\setminus \\{i\\} & ~~~~~\\text{ if } i\\in Y\\\\\nY\\cup\\{i\\} & ~~~~~\\text{ if } i\\not\\in Y\n \\end{cases}\n \\]\n It can easily be verified that in both the cases, $|X|$ is even. \n In first case, $|Y|\\le m$ and hence $|X|\\le m-1$. So, $X\\in E$. In second case, since $i\\not\\in Y$, $|Y|\\le m-2$ (by definition) and hence $|X|\\le m-1$. Hence $X\\in E$.\n\\end{description}\nThis proves the bijection between $E$ and $O'$. \n\n\\underline{Proof for: $|O\\setminus O'| = {n-1\\choose m}$}\\\\\nFrom the above definitions, $O\\setminus O' = \\{Y\\subseteq [n]: |Y| = m, i\\not\\in Y\\}$. This can be interpreted as $O\\setminus O' = \\{Y\\subseteq [n]\\setminus \\{i\\}: |Y| = m\\}$. Hence, $|O\\setminus O'| = {n-1\\choose m}$.\n\\end{description}\nThis completes the proof\n\\end{proof}\nThis proves both the identities.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Principle of Inclusion and Exclusion}\nSuppose we are given $n$ sets $A_1, A_2, \\ldots, A_n\\subseteq G$, where $G$ is some ground set. We are interested in finding the size of $A= A_1\\cup A_2\\cup\\ldots\\cup A_n$. This is very abstract scenario and we will see specific examples later, but here we are going to see classic use of the above identities in deriving this number.\n\nSo, we are interested in finding $|A| = |A_1\\cup A_2\\cup\\ldots\\cup A_n|$. \n\nSo, here is a thought process - \nClearly, we can add the size of individual sets as \n$|A| = |A_1|+|A_2|+\\ldots +|A_n|$, but this will over-count if there are some elements present in more than one sets. So, for that we need to subtract the double counting. For e.g. if $x\\in A_1$ and $x\\in A_2$, then it gets counted twice and to compensate for that we need to subtract $|A|=|A_1\\cap A_2|$ and we might attempt $|A| = |A_1|+|A_2|+\\ldots +|A_n| - \\sum_{1\\le i < j\\le n}|A_i\\cap A_j|$. But then, if $x$ is present in $A_1, A_2$ and $A_3$, the it is under-counted (added thrice and subtracted thrice). So, again we need to compensate for that by adding $\\sum_{1\\le i \\le j\\le k\\le n}|A_i\\cap A_j\\cap A_k|$ in the above expression and this sequence goes on for any element being present in $k\\le n$ sets and finally we get the expression for $|A|$  as follows\n\\begin{equation} \\label{eq:pie-1}\n    |A| = |A_1|+\\cdots+|A_n|-\\sum_{1\\le i< j\\le n}|A_i\\cap A_j| +\\sum_{1\\le i<j<k}|A_i\\cap A_j\\cap A_k| -\\cdots + (-1)^{n+1}|A_1\\cap A_2\\cap\\cdots\\cap A_n|\n\\end{equation}\nFor $n=2$, the above expression gives\n$$|A| = |A_1|+|A_2|-|A_1\\cap A_2|$$\nwhich we all must have seen before and can easily prove using Venn diagram. \n\nIn this section, we will formally prove the above expression for general $n$ using the two identities we proved in previous section.\n\\begin{proof}\nConsider any $x\\in A_1\\cup A_2\\cup\\cdots\\cup A_n$. Let $x$ appears in $k$ of the $A_i$'s. Then let us see how $x$ gets counted\n\\begin{itemize}\n    \\item[-] $|A_1|+|A_2|+\\cdots +|A_n|$: counts $x$ $k$ times (added)\n    \\item[-] $\\sum_{1\\le i<j\\le n}|A_i\\cap A_j|$: counts $x$ ${k\\choose 2}$ times (subtracted)\n    \\item[-] $\\sum_{1\\le i<j<k\\le n}|A_i\\cap A_j\\cap A_k|$: counts $x$ ${k\\choose 3}$ times (added) \n    \\item[-] and so on $\\ldots$\n\\end{itemize}\nNotice that in terms involving intersection of more than $k$ sets, $x$ never appears.\n\nThus, \n\\begin{eqnarray*} \n{\\Large\\substack{\\# \\text{of times $x$}\\\\ \\text{gets counted}}} &=& k+{k\\choose 2}-{k\\choose 3}+\\cdots +(-1)^{k+1}{k\\choose k}\\\\\n&=&-{k\\choose 0}+{k\\choose 1}+{k\\choose 2}-{k\\choose 3}+\\cdots +(-1)^{k+1}{k\\choose k}+{k\\choose 0}\\\\\n&=&-\\sum_{i=0}^k(-1)^{i}{k\\choose i}+{k\\choose 0}\\\\\n%&&\\text{from~\\eqref{eq:identity-1}, $\\sum_{i=0}^k(-1)^k{k\\choose i} = 0$}\\\\\n&=&{k\\choose 0} ~~~~~~~~~~~~~~~~~~~~~~~\\text{from ~\\eqref{REV1}}\\\\\n&=& 1\n\\end{eqnarray*}\nThus, irrespective of the value of $k$, any element $x\\in A_1\\cup A_2\\cup\\cdots\\cup A_n$ is counted exactly once. Hence, every $x\\in A_1\\cup A_2\\cup\\cdots\\cup A_n$ is counted exactly once in RHS in~\\eqref{eq:pie-1}.\n\nThis proves the PIE\n\\end{proof}\nNow let us look at the application of second identity that we derived. This identity is used in deriving a version of PIE which appears very naturally in several context. Let us look at one such example.\n\nPIE says that if we want to derive $|A_1\\cup\\A_2\\cup\\cdots\\cup A_n|$, then the following expression does not give the correct count.\n$$|A_1\\cup\\A_2\\cup\\cdots\\cup A_n| = |A_1|+|\\A_2|+\\cdots+|A_n|$$ \nBut we can ask, does this expression gives a lower or an upper bound? As we saw, this does over-counting, hence we can write\n$$|A_1\\cup\\A_2\\cup\\cdots\\cup A_n| \\le |A_1|+|\\A_2|+\\cdots+|A_n|$$\nNow, suppose we include the next component, i.e. $$|A_1|+|\\A_2|+\\cdots+|A_n|-\\sum_{1\\le i<j\\le n}|A_i\\cap A_j|$$\nAgain from PIE we know that this also does not give the correct count. But we ask the same question again - does it give any lower or upper bound. And as we saw that this term can do some over-subtraction and hence we can say that this expression gives the lower bound. That is, \n$$|A_1\\cup\\A_2\\cup\\cdots\\cup A_n| \\ge |A_1|+|\\A_2|+\\cdots+|A_n|-\\sum_{1\\le i<j\\le n}|A_i\\cap A_j|$$\nSimilarly, \n$$|A_1\\cup\\A_2\\cup\\cdots\\cup A_n| \\le |A_1|+|\\A_2|+\\cdots+|A_n|-\\sum_{1\\le i<j\\le n}|A_i\\cap A_j|+\\sum_{1\\le i<j<k\\le n}|A_i\\cap A_j\\cap A_k|$$\nand we continue like this. \n\nLet us now formally establish this observation. We use the same technique that we used in the proof of PIE. \n\nLet $x$ appears in $k$ of the sets in $A_1, A_2, \\ldots, A_n$. Suppose we cut off the PIE after $m\\le n$ sized intersections. Then \n\\begin{eqnarray*} \n{\\Large\\substack{\\# \\text{of times $x$}\\\\ \\text{gets counted}}} &=& {k\\choose 1}-{k\\choose 2}+\\cdots+(-1)^{m+1}{k\\choose m}\\\\\n%&=&-{k\\choose 0}+{k\\choose 1}+{k\\choose 2}-{k\\choose 3}+\\cdots +(-1)^{k+1}{k\\choose k}+{k\\choose 0}\\\\\n&=&-\\sum_{i=0}^m(-1)^{i}{k\\choose i}+{k\\choose 0}\\\\\n%&&\\text{from~\\eqref{eq:identity-1}, $\\sum_{i=0}^k(-1)^k{k\\choose i} = 0$}\\\\\n&=& 1+(-1)^{m+1}{k-1\\choose m} ~~~~~~~~~~~~~~~~~~~~~~~\\text{from ~\\eqref{REV2}}\n\\end{eqnarray*}\nThus, $x$ is over counted or under counted depending on whether the second term on RHS is positive or negative. Let us analyze this for two cases.\n\\begin{description}\n\\item Case1: $k\\le m$\n\nSince, $x$ appears in only $k\\le m$ sets and we are cutting down only after $m$, then this means that all possible intersections of this particular $x$ are added and subtracted and $x$ can not appear in any of the intersections of more than $k$ sets. Hence, $x$ is neither under counted nor over counted. In the expression, ${k-1\\choose m} = 0$ Hence,\n$$\\# \\text{of times $x$ is counted } = 1$$\n\\item Case2: $k>m$\n\nIn this case, $x$ can be under counted or over counted depending upon whether $m$ is even or odd.\nIf $m$ is odd then $x$ is over counted.\n\nIf $m$ is even then $x$ is under counted.\n\\end{description}\nNotice that either all $x\\in A_1\\cup\\A_2\\cup\\cdots\\cup A_n$ are correctly counted or under counted or all $x$ are correctly counted or over counted based on the parity of $m$. Thus, whether a PIE cut down after $m$ intersections gives lower bound or upper bound depends only on the parity of $m$. This principle is also called the \\emph{Bon Ferroni's inequality}. \n\\begin{remark} \n    We used the equality in~\\eqref{eq:even-odd} to prove PIE. We can actually do the other way round as well, i.e. we can use PIE to prove this equality too.\n\\end{remark}\nThis completes this lecture. In the next lecture we will look at some applications of PIE.\n\n%\\Lecture{Jayalal Sharma}{Sept 19, 2020}{08}{Live lecture discussion}{Anshu and Narasimha Sai }{$\\alpha$}{JS}\n\n\\section{Discussions}\n\n\\paragraph{Bijection from Euler's problem to Binary Trees} As we have already established a bijection from set of balanced parenthesisations to set of full binary trees and established that number of full binary trees with $n$ internal nodes is the catlan number $C_n$, in this section, let's establish a bijection from the \\emph{Euler's Problem} to set of full binary trees to establish that the solution to \\emph{Euler's problem} is also catlan number $C_n$.\n\nLets recall \\emph{Euler's problem} first. Consider a convex polygon with $n+2$ edges. Euler's problem is the number of ways of triangulating it (partition the polygon into triangles) by drawing non-crossing diagonals. (Refer fig. \\ref{fig:Euler's-polygon}). We know that number of non-crossing diagonals in a polygon of $n+2$ edges is $n-1$ (proof follows from a simple induction) and from those $n-1$ non-crossing diagonals, we have our polygon partitioned into $n$ triangles. Let's associate each of the triangles with a vertex (green dots in the fig. \\ref{fig:Euler's-polygon}). Observe that if two triangles share an edge, it must be one of the diagonals (no two triangles can share an edge because of non-crossing diagonals). Now, let's connect the vertices whose corresponding triangles share an edge. Any edge connecting two of these vertices crosses a diagonal. \n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.4\\linewidth]{images/polygon.png}\n    \\caption{Partitioning a polygon into triangles by non-crossing diagonals. Observe that green dots in each triangle associates the triangle with a vertex}\n    \\label{fig:Euler's-polygon}\n\\end{figure}\nNow, consider a polygon edge $e$. For every polygon edge surrounding a vertex (other than $e$), add an open-edge originating from that vertex (see fig. \\ref{fig:tree-in-polygon}). We arrive at the following claim.  \n\\begin{claim}\n\tIf we remove the underlying triangles (which are formed with polygon edges and diagonals), from fig. \\ref{fig:tree-in-polygon}, the \t\tresulting graph obtained (see fig. \\ref{fig:tree}) is a full binary tree with the vertices as internal nodes.\n\\end{claim}\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.4\\linewidth]{images/polygon-tree.png}\n    \\caption{Polygon with vertices connected to form a tree}\n    \\label{fig:tree-in-polygon}\n\\end{figure}\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.4\\linewidth]{images/tree.png}\n    \\caption{Tree formed by connecting vertices}\n    \\label{fig:tree}\n\\end{figure}\n\\begin{proof}\n\tWe observe that degree of every vertex other than the vertex surrounded by edge $e$ is 2. This vertex will act as root to our full binary tree. All other vertices have degree 3 because each vertex is surrounded by a triangle and if a side is a diagonal, it will be connected to vertex which is surrounded by triangle that shares the diagonal and if the side is a polygon edge, then there will be an open edge corresponding to it originating from the vertex. Therefore the resulting graph formed is a full binary tree with our vertices as $n$ internal nodes and vertices corresponding to open edges are $n+1$ leaves (because there are $n+2$ edges and one edge is under consideration). This completes the description of bijection.\n\\end{proof}\n\nWe leave it as an exercise to the reader to prove that the mapping defined above is indeed a bijection.\n\n\\paragraph{Bijection from binary trees to full binary trees}\nIn this section we are interested in connection between binary and full binary trees. Recall that a full binary tree is one in which each node has either 0 or two children. On the other hand, when we say binary tree then it only means that each node can have at most two children. We want to find a bijection between set of binary trees with $n$ internal nodes and set of full binary trees with certain number of internal nodes. \n\nFirst of all lets try to see how to convert a given binary tree into a full binary tree so that we can reverse the process, i.e. recover the original (binary) tree back from the full binary tree without ambiguity. \n\nHere is the first attempt:\n\n\\noindent \\underline{Attempt 1:} First natural approach can be to add a leaf node to all non-full (internal nodes having only one child) nodes, as shown in figure~\\ref{fig:bt-fbt-attempt1}\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.7\\linewidth]{images/binary-to-full-binary-1.png}\n    \\caption{Binary to full binary tree attempt1: adding a child node to each non full node}\n    \\label{fig:bt-fbt-attempt1}\n\\end{figure}\n\nBut notice that this transformation is not injective. For example, it can be observed that  both the trees in figure~\\ref{fig:bt-fbt-attempt1-issue} map to same full binary tree.\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.7\\linewidth]{images/binary-to-full-binary-2.png}\n    \\caption{Two different binary trees that map to same full binary tree}\n    \\label{fig:bt-fbt-attempt1-issue}\n\\end{figure}\n\n\\noindent\\underline{Attempt 2(correct)}\nLets try a slightly different approach. Given a binary tree, do the following:\n\\begin{itemize}\n    \\item to each leaf node, add two children\n    \\item to each internal node having only one child, add another child\n\\end{itemize}\nFigure~\\ref{fig:binary-to-full-solution} shows the full binary tree constructed in this way for the same binary tree as in Figure~\\ref{fig:bt-fbt-attempt1}.\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.5\\linewidth]{images/full-binary-3.png}\n    \\caption{Full binary tree for the (non-full) binary tree given in fig~\\ref{fig:bt-fbt-attempt1}. Notice that all the leaf nodes are added during transformation}\n    \\label{fig:binary-to-full-solution}\n\\end{figure}\nWe can see that this solution addresses the issue in the first attempt. Intuitively because of following argument: in the previous attempt the problem was that given a full binary tree, it was hard to decide if a leaf node was originally present in the binary tree or added during transformation. Now, in the current solution, this issue does not arise, because for any leaf node originally present in the binary tree, we add two new leaves as its children. Thus, it can be observed that all the leaf nodes (and only these nodes) are added during transformation.\n\nTo see that this translation is well-defined, we can see that the transformed tree is full binary tree by construction itself. Surjectivity is also easy to prove. To recover a binary tree from any given full binary tree, simply remove all the leaf nodes. We discussed injection informally. To give a formal argument, we first need to identify how to characterize two different binary trees? One of the hint as given during the discussion is to assign address to the nodes in the form of binary string, where 0-1 represents left or right child. \n\nHere we argued the bijection only intuitively and there are many things to be worked out formally. For example, proof for injection is not formally argued. Also, to argue surjection, we need to fix the number of nodes in full binary tree. Once we figure out this number, the argument for transformation being  well-defined also need to take that into account.\n\nWriting a complete formal proof of bijection is left as homework exercise.\n\n\\paragraph{Bijection between plane trees and full binary trees}\nA plane tree is a rooted tree with an ordering among the children. A plane tree can have more than two children. Figure~\\ref{fig:plane-tree-1} shows a plane tree. \n\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.8\\linewidth]{images/plane-tree.png}\n    \\caption{An example of plane trees and its transformation to a binary tree}\n    \\label{fig:plane-tree-1}\n\\end{figure}\n\nWe are interested in studying the connection between plane trees and binary trees. The number of plane trees with $n$ nodes is equal to the number of binary trees with $n$ nodes. Thus, there is bijection between set of plane trees with $n$ nodes and the set of  binary trees with $n$ nodes. \n\nHere we define the bijection function. \n\n\\noindent\\underline{The Bijection:} Given any plane tree, do the following\n\\begin{itemize}\n    \\item For each node in the tree, \n    \\begin{itemize}\n        \\item add its first child in plane tree as its left child in binary tree\n        \\item add its immediate sibling on right as its right child in binary tree.\n    \\end{itemize} child in the binary tree.\n\\end{itemize}\nBy following the above rule, we get a binary tree from given plane tree.\n\nObserve that in the binary tree thus obtained, root node has only one child, while in general, in a binary tree the root can have both its children. Hence, we won't include the root as part of the binary tree.\n\nWriting formal argument for all the properties is left as homework excercise.\n", "meta": {"hexsha": "ef57d20adc777336b3743c6495695348763ccef9", "size": 63100, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week02.tex", "max_stars_repo_name": "pot8ohead/theory-toolkit", "max_stars_repo_head_hexsha": "177249454691f7e264d9ee7d5a354e180a54e095", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week02.tex", "max_issues_repo_name": "pot8ohead/theory-toolkit", "max_issues_repo_head_hexsha": "177249454691f7e264d9ee7d5a354e180a54e095", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week02.tex", "max_forks_repo_name": "pot8ohead/theory-toolkit", "max_forks_repo_head_hexsha": "177249454691f7e264d9ee7d5a354e180a54e095", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 89.1242937853, "max_line_length": 948, "alphanum_fraction": 0.6915847861, "num_tokens": 20498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8872045892435128, "lm_q1q2_score": 0.7274131303126622}}
{"text": "\\section{Introduction}\nWe know from real analysis that is difficult to define inverses of functions, mainly because many functions of interest are not bijective.\nBut inverses \\emph{are} very important.\n\\begin{center}\n  \\begin{tabular}{l | l}\n    Function & Inverse \\\\\\hline\n    $x^2$ & $\\pm \\sqrt{x}$ \\\\\n    $x^n$ & $x^{1/n}$ \\\\\n    $e^x$ & $\\ln x$\n  \\end{tabular}\n\\end{center}\nWe use various tricks to define the inverse. For example, for definiting the inverse of $f(x) = x^2$ we can\n\\begin{enumerate}\n  \\item Restrict the domain of the inverse to non-negative integers and \\emph{choose} $\\sqrt{x}$ to always be positive.\n  \\item Study the graph $y = x^2$ instead, thereby bypassing the need to define an inverse explicitly.\n\\end{enumerate}\nBoth of these methods generalize to (nice) complex functions, with the first giving rise to the notion of branch cuts and branch points and the second giving us Riemann surfaces.\n", "meta": {"hexsha": "9e489c153bddb342d75ef8846f3c0d63df74bf7d", "size": 922, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "00.tex", "max_stars_repo_name": "apurvnakade/mc2019-Riemann-surfaces", "max_stars_repo_head_hexsha": "edebdd1c81027b9cedb264eba1eeaa09dd4e311f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "00.tex", "max_issues_repo_name": "apurvnakade/mc2019-Riemann-surfaces", "max_issues_repo_head_hexsha": "edebdd1c81027b9cedb264eba1eeaa09dd4e311f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "00.tex", "max_forks_repo_name": "apurvnakade/mc2019-Riemann-surfaces", "max_forks_repo_head_hexsha": "edebdd1c81027b9cedb264eba1eeaa09dd4e311f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.2222222222, "max_line_length": 178, "alphanum_fraction": 0.7223427332, "num_tokens": 251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859265, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7273745670549775}}
{"text": "\\section{Naive Bayes : Multinomial Classification with Independence}\n\\subsection{Naive Bayes Classifier}\n\\begin{itemize}\n\t\\item it takes \\textbf{all attributes/predictors} into account\n\t\\item Assumptions:\n\t\\begin{itemize}\n\t\t\\item all attributes are \\textbf{equally important}\n\t\t\\item all attributes are \\textbf{independent} $\\rightarrow$ no correlation\n\t\\end{itemize}\n\t\\item Difference Regression \\& Naive Bayes:\n\t\\begin{itemize}\n\t\t\\item regression models the importance of different attributes (coefficents $\\beta_i$)\n\t\t\\item attributes from regression can be correlated $\\rightarrow$ VIF detection necessary\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{Bayes Theorem}\n\\paragraph{prior / unconditional probability $\\mathbf{Pr(e)}$} the probability of a single event $e$\n\\paragraph{posterior / conditional probability $\\mathbf{Pr(e|h)}$} the probability of a single event $e$ given we know $h$\n\\paragraph{probability distribution $\\mathbf{Pr(E)}$} the probability distribution of the random variable $E$, with all possible values $e_i$\n\n\\paragraph{Bayes Theorem} \n\\subparagraph{single evidence}\n\\begin{itemize}\n\t\\item Input: \n\t\\begin{itemize}\n\t\t\\item $Pr(e)$: prior probability of \\textbf{single evidence} $e$ (eg: weather = windy)\n\t\t\\item $Pr(h)$: prior probability hypothesis (eg: play = true, test = positive)\n\t\t\\item $Pr(e|h)$: conditional probability of hypothesis \n\t\\end{itemize} \n\t\\item Output: posterior conditional probability $Pr(h|e)$\n\t\n\t$$Pr(h|e) = \\frac{Pr(h \\cap e)}{Pr(e)} = \\dfrac{Pr(e|h) \\cdot Pr(h)}{Pr(e)}$$\nor\t\n\t$$Pr(e|h) = \\frac{Pr(h \\cap e)}{Pr(h)} = \\dfrac{Pr(h|e) \\cdot Pr(e)}{Pr(h)}$$\n\t\\item If prior probability $Pr(e)$ \\textbf{unknown}: law of total probability\n\t\n\t$$Pr(e) = Pr(e|h)\\cdot Pr(h) + Pr(e|\\neg h) \\cdot Pr(\\neg h)$$\n\t\n\t$$Pr(h|e) = \\dfrac{Pr(e|h) \\cdot Pr(h)}{Pr(e)} = \\dfrac{Pr(e|h) \\cdot Pr(h)}{Pr(e|h)\\cdot Pr(h) + Pr(e|\\neg h) \\cdot Pr(\\neg h)} $$\n\t\n\\end{itemize}\n\\subparagraph{multiple evidences}\n\\begin{itemize}\n\t\\item Input: \n\t\\begin{itemize}\n\t\t\\item $Pr(e_1, e_2, \\dots, e_k)$: prior probability of \\textbf{multiple evidences} $e_i$\n\t\\end{itemize}\n\t\\item Ouput: posterior conditional probability $Pr(h|e_1, e_2, \\dots, e_k)$\n\n\t\n\t$$Pr(h|e_1, e_2, \\dots, e_k) = \\dfrac{Pr(e_1, e_2, \\dots, e_k | h) \\cdot Pr(h)}{Pr(e_1, e_2, \\dots, e_k)}$$\n\tSince every attribute/evidence $e_i$ is \\textbf{equally important \\& independent}:\n\t\\begin{align*}\n\t\tPr(h|e_1, e_2, \\dots, e_k) &= \\dfrac{Pr(e_1 | h) \\cdot Pr(e_2 | h) \\dots Pr(e_k | h) \\cdot Pr(h)}{Pr(e_1, e_2, \\dots, e_k)} \\\\ \n\t\t&= \\frac{\\Pi_{i=1}^k Pr(e_i|h) \\cdot Pr(h)}{Pr(e_1,e_2, \\dots e_k)}\n\t\\end{align*}\n\t\\item If the prior probability $Pr(e_i)$ is \\textbf{known}: \n\t$$Pr(e_1, e_2, \\dots, e_k) = Pr(e_1)\\cdot Pr(e_2)\\dots Pr(e_k)$$\n\t\\item If the prior probability $Pr(e_i)$ is \\textbf{unknown}: law of total probability\n\t$$Pr(e_1, e_2, \\dots, e_k) = Pr(e_1, e_2, \\dots, e_k|h)\\cdot Pr(h) + Pr(e_1, e_2, \\dots, e_k | \\neg h) \\cdot Pr(\\neg h)$$\n\\end{itemize}\n\n\n\n\\subsection{Possible Problems in Prediction}\n\n\\subsubsection{Zero Frequency Problem in Dataset}\n\\begin{itemize}\n\t\\item Definition: for the prediction of new instance ,there exists a \\textbf{0-frequency} of attribute values \\textbf{from the instance attribute}. \n\t\n\teg: predict whether to play when Outlook = overcast: Pr(Outlook = overcast |$\\neg$ play)=0\n\t\n\tpredict whether to play when Outlook = sunny: \\textbf{no} zero-frequency problem here.\n\t\n\t\\item Solution:\n\t\\begin{itemize}\n\t\t\\item add 1 to the numerator for \\textbf{every attribute value-class combination}.\n\t\t\n\t\t$\\rightarrow$ the prior probability of the result class $Pr(h), Pr(\\neg h)$ \\textbf{remain the same} though adding 1. \n\t\t\n\t\t$\\rightarrow$ for small data, significant bias possible\n\t\t\n\t\t\\item assign equal/unequal weights to the numerator, as long as $\\Sigma w_i = 1$\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsubsection{Missing Value in New Instance}\n\\begin{itemize}\n\t\\item Definition: there exists \\textbf{missing values} for the attributes in the \\textbf{new instance} for prediction.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.45\\textwidth]{missingvalue.png}\n\t\\end{figure}\n\t\\item Solution: \\textbf{omit} the attribute with missing value in prediction calculation.\n\t\n\t$\\rightarrow$ take the \\textbf{maximum} of $Pr(\\text{play} | e_2, e_3,e_4)$ and $Pr(\\neg \\text{play}|e_2,e_3,e_4)$\n\\end{itemize}\n\n\\subsubsection{Numeric Attributes in Dataset}\n\\begin{itemize}\n\t\\item Definition: instead of nominal attributes (eg: Outlook = sunny, overcast, cloudy), \\textbf{attribute is numeric} (eg: Temperature = 87, 90)\n\\end{itemize}\n\n\\paragraph{Assumption: Attribute Follows Normal Distribution}\n\\begin{itemize}\n\t\\item Solution:\n\t\\begin{itemize}\n\t\t\\item Assumption: numeric attributes follows \\textbf{normal distribution} $e_i \\sim N(\\mu,\\sigma^2)$\n\t\t$$f(x) = \\frac{1}{\\sqrt{2\\pi}\\cdot \\sigma}\\cdot e^{-\\frac{(x-\\mu)^2}{2 \\sigma^2}}$$\n\t\t\\item calculate the \\textbf{mean} and \\textbf{standard deviation} for \\textbf{each result class}.\n\t\t\\item conditional probability: \\textbf{insert} the numeric instance into the \\textbf{probability density function} f(x).\n\t\\end{itemize}\n\t\n\t\n\\end{itemize}\n\n\\paragraph{Assumption: Attribute Follows Unknown Distribution}\n\\begin{itemize}\n\t\\item If the numeric data follows a \\textbf{unknown distribution f(x)} (normal distribution not applied) \n\t\n\t$\\rightarrow$ probability density distribution \\textbf{estimation}.\n\t\\item Solution: kernel density estimation \n\t\\begin{itemize}\n\t\t\\item Estimator: Rosenblatt-Parzen Kernel-Density Estimator \n\t\t\\item f(x) is not a normal distribution, but each sample follows a normal distribution.\n\t\t\n\t\t$\\rightarrow$ f(x) is the \\textbf{sum} of normal distribution at each data point $x_i$\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{Prediction using 0-Rule \\& 1-Rule}\n\\begin{itemize}\n\t\\item Input: a dataset $D = x_1, x_2, \\dots, x_n$ tuples (evidence, result class), a set of classes $C = C_1, C_2, \\dots , C_m$, a \\textbf{new instance} with evidence $e_1, \\dots, e_k$\n\t\\item Output: classification prediction result \n\\end{itemize}\n\\subsubsection{0-Rule}\nProcess:\n\\begin{itemize}\n\t\\item count \\textbf{absolute frequency} for each class (classification labels)\n\t\\item Prediction result: class with \\textbf{maximum} absolute frequency\n\\end{itemize}\n\\subsubsection{1-Rule}\nProcess:\n\\begin{itemize}\n\t\\item build \\textbf{frequency tables} for each evidence/attribute $e_i$ $\\rightarrow$ absolute frequency\n\t\\item pick the \\textbf{most frequent class} as classification result for \\textbf{each attribute value}\n\t\\item calculate \\textbf{overall error rate of the evidence/attribute} according to the classification result\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.45\\textwidth]{1-rule.png}\n\t\\end{figure}\n\t\\item Prediction result: choose a \\textbf{single attribute} with \\textbf{smallest overall error rate}, pick the \\textbf{most frequent class} of that evidence/attribute value.\n\\end{itemize}\nEvaluation:\n\\begin{itemize}\n\t\\item uses only a \\textbf{single} attribute for the classification\n\t\\item no prediction result possible if missing value for the attribute found in new instance.\n\t\\item if numeric values in dataset, discretization of the numeric values though possible, but increase the class complexity.\n\\end{itemize}\n\n\\subsection{Prediction using Bayes Theorem: Maximum A Posteriori Classification }\nProcess:\n\\begin{itemize}\n\t\\item \\textbf{sort} the hypothesis/classification labels, get \\textbf{prior probability of hypothesis} $Pr(h), Pr(\\neg h)$\n\t\\item  build \\textbf{frequency tables} for each evidence/attribute $e_i$ $\\rightarrow$ \\textbf{absolute frequency}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.25\\textwidth]{fre_table.png}\n\t\\end{figure}\n\t\\item check if there is \\textbf{zero frequency problem} for the \\textbf{attributes from new instance}, resolve by \\textbf{adding 1}. \n\t\n\tcheck for \\textbf{numeric} attributes, calculate the \\textbf{mean} and \\textbf{standard deviation} for each result class.\n\t\\item build \\textbf{likelihood tables} for each evidence/attribute $e_i$ $\\rightarrow$ \\textbf{relative frequency} $Pr(e_i|h)$\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.25\\textwidth]{like_table.png}\n\t\\end{figure}\n\t\\item find $\\Pi_{i=1}^k Pr(e_i|h) \\cdot Pr(h)$ and $\\Pi_{i=1}^k Pr(e_i|\\neg h) \\cdot Pr(\\neg h)$, \\textbf{omit} the attribute if \\textbf{missing value} in instance.\n\t\\item \\textbf{normalize} the result: \n\t\n\t$$Pr(h|e_1,\\dots, e_k) = \\frac{\\Pi_{i=1}^k Pr(e_i|h) \\cdot Pr(h)}{Pr(e_1, \\dots, e_k)}$$\n\t$$Pr(\\neg h|e_1,\\dots, e_k) = \\frac{\\Pi_{i=1}^k Pr(e_i|\\neg h) \\cdot Pr(\\neg h)}{Pr(e_1, \\dots, e_k)}$$ \n\twith\n\t$$Pr(e_1, \\dots, e_k) = \\Pi_{i=1}^k Pr(e_i|h) \\cdot Pr(h) + \\Pi_{i=1}^k Pr(e_i|\\neg h) \\cdot Pr(\\neg h)$$\n\n\t\\item Prediction result: take the \\textbf{maximum}.\n\t$$\\text{result} = \\max\\left\\lbrace Pr(h|e_1,\\dots, e_k), Pr(\\neg h|e_1,\\dots, e_k)\\right\\rbrace $$\n\\end{itemize}\n\n\n\n\\subsection{Evaluation of Naive Bayes}\n\\begin{itemize}\n\t\\item Complexity: \n\t\\begin{itemize}\n\t\t\\item calculation of conditional probability: $\\mathcal{O}(n)$, \n\t\t\n\t\tn: number of instances\n\t\t\\item calculation of class: $\\mathcal{O}(c\\cdot p)$, \n\t\t\n\t\tc: number of classes, p: number of attributes\n\t\\end{itemize}\n\t\n\t\\item Advantages: \n\t\\begin{itemize}\n\t\t\\item multinomial classification\n\t\t\\item works well, even if independence assumption is sometimes violated.\n\t\\end{itemize}\n\t\\item Disadvantages:\n\t\\begin{itemize}\n\t\t\\item takes all attributes with equal weight, could be \\textbf{redundant}.\n\t\t\\item many numeric attributes are actually \\textbf{not normally distributed}. \n\t\\end{itemize}\n\\end{itemize}\n\n\\section{Bayesian Network: Multinomial Classification with Denpendency}\n\n\\begin{itemize}\n\t\\item Idea: \n\t\\begin{itemize}\n\t\t\\item Naive Bayes assumption too restrictive: \\textbf{all} attributes are conditionally independent and equally important.\n\t\t\\item Attributes are often \\textbf{correlated/dependent with each other}\n\t\t\\item Some attributes are \\textbf{redundant} to the classification result.\n\t\\end{itemize}\t\n\t$\\rightarrow$ conditional independence among \\textbf{subset} of attributes.\n\\end{itemize}\n\n\\subsection{Representation of Bayesian Network: Directed Acyclic Graph}\n\\begin{itemize}\n\t\t\\item nodes: attributes\n\t\t\\item edges: end node is dependent on start node / start node has direct influence on end node.\n\t\t\\begin{itemize}\n\t\t\t\\item start: trigger/cause, evidence node\n\t\t\t\\item end: result/effect. \n\t\t\\end{itemize}\n\t\\end{itemize}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{minipage}{0.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=0.45\\linewidth]{dag_naivebayes.png}\n\t\\end{minipage}%\n\t\\begin{minipage}{.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=0.45\\linewidth]{dag_bayesnet.png}\n\t\\end{minipage}\n\t\\caption{DAG - Naive Bayes(left) vs. Bayesian Network(right)}\n\\end{figure}\n\\subsection{Probability Law in Bayesian Network}\n\\subsubsection{Chain Rule}\nAccording to the \\textbf{directed acyclic graph}, derive the \\textbf{joint probability distribution} \n\t\n\t$$Pr(e_1, e_2, \\dots, e_k) = \\Pi_{i=1} Pr(e_i| e_{i-1}, \\dots, e_1) = \\Pi_{i=1} Pr(e_i| \\text{Parents}(e_i))$$\n\\\\ \\ \\\\\t\neg: $Pr(A,B,C,D,E) = Pr(A)\\cdot Pr(B) \\cdot Pr(C|A,B) \\cdot Pr(D|A,B,C) \\cdot Pr(E|A,C,D)$\n\n\n\\subsubsection{Conditional Independence}\n\\paragraph{conditional independence between hypothesis and evidence} the hypothesis $h$ is only dependent on $e_1, e_2, e_3$, not on $e_4$ (redundant), then \n\t $$Pr(h | e_1, e_2, e_3, e_4) = Pr(h | e_1, e_2, e_3) $$\n\n\\paragraph{conditional independence between hypotheses}\n\n if two hypotheses are \\textbf{independent} from each other, then\n\t$$Pr(h_1, h_2 | e_1, e_2) = Pr(h_1|e_1,e_2) \\cdot Pr(h_2|e_1,e_2)$$\n\n\\subsection{Inference in Bayesian Networks}\n\\begin{itemize}\n\t\\item Idea: infer the probability of an event, given only observation of \\textbf{a subset} of other attributes. \n\t\n\t$\\rightarrow$ explain the \\textbf{away effect} of attributes.\n\t\\item Inference Rules: using \\textbf{d-separation}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.4\\textwidth]{baynet_example.png}\n\t\\end{figure}\n\tExample:\n\t\\begin{itemize}\n\t\t\\item alarm \\textbf{not observed}: Burglary \\& Mary-calls \\textbf{dependent}\n\t\t\t\t\n\t\t$\\rightarrow$ if B, belief M $\\uparrow$. if M, belief B $\\uparrow$.\n\t\t\n\t\t\\item alarm \\textbf{observed}: Burglary \\& Mary-calls \\textbf{conditionally independent}.\n\t\t\t\t\n\t\t$\\rightarrow$ no alarm. if Mary-calls, belief B $-$. if B, belief M $-$. \n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{Evaluation of a Bayesian Network}\n\\begin{itemize}\n\t\\item Quality Metrics:\n\t\\begin{itemize}\n\t\t\\item To maximize the joint probability of training data, the Log-Likelihood of the training data.\n\t\t\\item Akaike Information Criterion (AIC)\n\t\\end{itemize}\n\t\\item Advantages:\n\t\\begin{itemize}\n\t\t\\item can handle dependencies among the attributes\n\t\\end{itemize}\n\t\\item Disadvantages:\n\t\\begin{itemize}\n\t\t\\item computationally expensive, given whether the network structure (DAG) is given, whether the attributes are observable.\n\t\\end{itemize}\n\\end{itemize}\n", "meta": {"hexsha": "38862d823c9ca24ed99dcc114d4ecdfa9852ed2d", "size": 12928, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Business Analytics/lectures/naivebayes.tex", "max_stars_repo_name": "YourPsychiatrist/TUM", "max_stars_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 225, "max_stars_repo_stars_event_min_datetime": "2019-10-02T10:49:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T22:25:38.000Z", "max_issues_repo_path": "Business Analytics/lectures/naivebayes.tex", "max_issues_repo_name": "YourPsychiatrist/TUM", "max_issues_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-02-16T12:22:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-31T19:35:57.000Z", "max_forks_repo_path": "Business Analytics/lectures/naivebayes.tex", "max_forks_repo_name": "YourPsychiatrist/TUM", "max_forks_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 69, "max_forks_repo_forks_event_min_datetime": "2019-10-02T21:46:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T19:27:50.000Z", "avg_line_length": 42.1107491857, "max_line_length": 185, "alphanum_fraction": 0.7231590347, "num_tokens": 4150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7273696806141681}}
{"text": "Compute the solution to the systems for the given initial conditions using \\textbf{rk4.m}. Plot your results in the phase plane (that is,$ y(t)$ vs. $x(t)$).\n\n\\begin{questions}\n\\question{Using initial conditions with $x(0)^2 + y(0)^2$ both smaller and larger than $1$ (inside and outside the unit circle), solve\n\\begin{align}\n& x'(t) = -4y + x(1-x^2-y^2), \\\\\n& y'(t) = 4x + y(1 - x^2 -y^2),\n\\end{align}\nover the interval $0 < t < 10$. What is the final state of the system? Justify your answer with a plot showing the trajectories in the $(x,y)$-plane for a few different initial conditions. Note that you have to supply the initial conditions separately.\n}\n\n\\begin{solution}\n\n\\begin{figure}[H]\n\\center{\\includegraphics[scale=.5]{P1F1.eps}}\n\\caption{Maximum Error of Cubic Spline Interpolation}\n\\end{figure}\n\n\nThe solution for this problem is stable for intital conditions that fall both inside of and outside of the circle of radius 2. The solutions spiral in or out towards the circle and then remain there indefinitely.\n\n\\end{solution}\n\n\n\\question{Using initial conditions with $x(0)^2 + y(0)^2$ both inside and outside circles of radius 1 and 2, solve \n\\begin{align}\n& x'(t) = -4y + x(1-x^2-y^2)(4 - x^2 -y^2), \\\\\n& y,(t) = 4x + y(1 - x^2 -y^2)(4-x^2-y^2),\n\\end{align}\nover the interval $0 < t < 10$. What are the final states of the system? Justify your answer with\na plot showing the trajectories in the $(x,y)$-plane for a few different initial conditions.\n}\n\n\\begin{solution}\n\n\\begin{figure}[H]\n\\center{\\includegraphics[scale=.5]{P1F2.eps}}\n\\caption{Maximum Error of Cubic Spline Interpolation}\n\\end{figure}\n\nThe solution for this problem is stable for initial conditions that  fall within the circle of radius 4. If the initial condition falls on or outside of the outer circle the trajectories blow outwards. The trajectories for initial conditions inside of the outer circle spiral towards the circle of radius 2 and remain there indefinitely.\n\n\\end{solution}\n\n\\subsection*{MATLAB}\n\n\\subsection*{Contents}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item Part 1\n   \\item Part 2\n\\end{itemize}\n\n\n\\subsection*{Part 1}\n\n\\begin{verbatim}\nF = @(t,y) [-4*y(2) + y(1)*(1-y(1)^2-y(2)^2); ...\n            4*y(1) + y(2)*(1-y(1)^2-y(2)^2)];\ntspan = [0 10];\ntheta = pi/4;\nr = 0.25;\ny0 = [r*cos(theta);r*sin(theta)];\nN = 200;\n\n[t,y] = rk4(F,tspan,y0,N);\n\nr = 1.6;\ntheta2 = pi/6;\ny0_2 = [r*cos(theta2);r*sin(theta2)];\n[t,y2] = rk4(F,tspan,y0_2,N);\n\nr = 2;\ny0_3 = [r*cos(theta);r*sin(theta)];\n[t,y3] = rk4(F,tspan,y0_3,N);\n\nfigure\ncomet(y(:,1),y(:,2)) %phase plot\naxis([-1.5 1.5 -1.5 1.5])\nhold on\ncomet(y2(:,1),y2(:,2))\ncomet(y3(:,1),y3(:,2))\np1 = plot(y0(1),y0(2),'r*')\np2 = plot(y0_2(1),y0_2(2),'b*')\np3 = plot(y0_3(1),y0_3(2),'g*')\nplot(cos(0:0.001:2*pi),sin(0:0.001:2*pi), '--m')\npbaspect([1 1 1])\ngrid on\nlegend([p1 p2 p3],{\"r = 0.25,theta = pi/4\",\"r = 1.6,theta = pi/6\",\"r = 2,theta = pi/6\"})\n\\end{verbatim}\n\n\n\\subsection*{Part 2}\n\n\\begin{verbatim}\nF = @(t,y) [-4*y(2) + y(1)*(1-y(1)^2-y(2)^2)*(4-y(1)^2-y(2)^2); ...\n            4*y(1) + y(2)*(1-y(1)^2-y(2)^2)*(4-y(1)^2-y(2)^2)];\n\ntspan = [0 10];\ntheta = pi/4;\nr = 0.25;\ny0 = [r*cos(theta);r*sin(theta)];\nN = 200;\n\n[t,y] = rk4(F,tspan,y0,N);\n\nr = 1.6;\ntheta2 = pi/6;\ny0_2 = [r*cos(theta2);r*sin(theta2)];\n[t,y2] = rk4(F,tspan,y0_2,N);\n\nr = 2;\ny0_3 = [r*cos(theta);r*sin(theta)];\n[t,y3] = rk4(F,tspan,y0_3,N);\ny0_4 = [r*cos(theta*4);r*sin(theta*4)];\n[t,y4] = rk4(F,tspan,y0_4,N);\ny0_5 = [r*cos(theta*2);r*sin(theta*2)];\n[t,y5] = rk4(F,tspan,y0_5,N);\n\nr = 1.99;\ny0_6 = [r*cos(0);r*sin(0)];\n[t,y6] = rk4(F,tspan,y0_6,N);\n\nfigure\ncomet(y(:,1),y(:,2)) %phase plot\naxis([-2.5 2.5 -2.5 2.5])\nhold on\ncomet(y2(:,1),y2(:,2))\ncomet(y3(:,1),y3(:,2))\ncomet(y4(:,1),y4(:,2))\ncomet(y5(:,1),y5(:,2))\ncomet(y6(:,1),y6(:,2))\np1 = plot(y0(1),y0(2),'r*')\np2 = plot(y0_2(1),y0_2(2),'b*')\np3 = plot(y0_3(1),y0_3(2),'g*')\np4 = plot(y0_4(1),y0_4(2),'y*')\np5 = plot(y0_5(1),y0_5(2),'c*')\np6 = plot(y0_6(1),y0_6(2),'k*')\nl7 = plot(cos(0:0.001:2*pi),sin(0:0.001:2*pi), '--m')\nl8 = plot(2*cos(0:0.001:2*pi),2*sin(0:0.001:2*pi), '--m')\nlegend([p1 p2 p3 p4 p5 p6],{\"r = 0.25,theta = pi/4\",\"r = 1.6,theta = pi/6\",\"r = 2,theta = pi/6\",...\n                            \"r = 2,theta = 2pi/3\",\"r = 2,theta = pi/3\",\"r = 1.99,theta = 0\"})\npbaspect([1 1 1])\ngrid on\n\\end{verbatim}\n\n\\end{questions}", "meta": {"hexsha": "3d0bc647614905572e505e2198644e6c4ef6b064", "size": 4316, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/tex_files/problem1.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/tex_files/problem1.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/tex_files/problem1.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.1621621622, "max_line_length": 337, "alphanum_fraction": 0.6174698795, "num_tokens": 1735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681158979306, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.7273597080937414}}
{"text": "\\chapter{Skills from National 5}\n\n\\section{Distance Formula}\nThe Distance Formula allows us to find the distance between two points given their Cartesian coordinates. To do this we treat the line between the two points as though it were the hypotenuse of a right-angled triangle, and use Pythagoras' theorem to find the length of the hypotenuse.\n\nDIAGRAM GOES HERE.\n\nTo find each side we simply take the difference between the two $x$-coordinates $y$-coordinates, and substitute into Pythagoras' theorem.\n\nPythagoras' theorem:\n\\begin{equation*}\n\ta^2 = b^2+c^2\n\\end{equation*}\n\nRearranged, with our method to find the distances:\n\\begin{equation*}\n\td = \\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}\n\\end{equation*}\n\n\n\\section{Factorisation}\nFactorisation is one of the most important skills that must be known at Higher. Though it's possible to pass National 5 maths with an A without knowing how to factorise, this isn't the case with the Higher course. There are three kinds of factorisation which should be able to be done by hand: looking for the greatest common factor, recognising a difference of two squares, and factorising a quadratic.\n\nNote that when reading resources written in American English, factorising and to factorise is often shortened to simply factoring and to factor (and American spelling changes -ise to -ize in general, so it'll be called \"factorizing``).\n\n\\subsection{Greatest Common Factor}\nThe greatest common factor should have been learnt about in primary school when simplifying fractions. For example, the greatest common factor of $12$ and $18$ is $6$.\n\nWhen asked to factorise an expression such as $12 + 18$, it should be recognised that the greatest common factor of all terms is $6$. So the expression can be factorised to look like $6(2 + 3)$. This is incredibly useful when dealing with many large terms, such as $126 - 612 + 531$, which can be factorised to become $9(14 - 68 + 59)$.\n\nThe strategy for algebraic expressions is the same as with normal numbers: look for the greatest value that everything can be divided by. For example, $3x^5 + 9x^2$. Both coefficients can be divided by 3, the variables can both be divided by $x^2$. Factoring this expression gives $3x^2(x^3+3)$. If unsure, the bracket(s) can always be multiplied out again to double-check.\n\n\\subsubsection{Partial Factorisation (\"Grouping``)}\nIt's possible to only partially factorise and take out a common factor. For example, $4x^2+2y+7x+11$ can be partially factorised to $2(2x^2+y)+7x+11$. This works, as shown below.\n\n\\begin{align*}\n\t&4x^2+2y+7x+11\\\\\n\t&=\\frac{4x^2}{2}+\\frac{2y}{2}+\\frac{7x}{2}+\\frac{11}{2}\\\\\n\t&=2x^2+y+3.5x+5.5\\\\\n\t&=2(2x^2+y+3.5x+5.5)\\\\\n\t&=2(2x^2+y+3.5x)+11\\\\\n\t&=2(2x^2+y)+7x+11\\\\\n\\end{align*}\n\nThis is also called factorisation by grouping, as you're essentially grouping a large expression into smaller ones. The above expression can be re-written into two groups like $(4x^2+2y)+(7x+11)$ where it's a bit more obvious that a factor can be taken out. Note that for a final answer any unnecessary brackets must be removed, otherwise marks might not be awarded in an exam.\n\n\\subsection{Difference of Two Squares}\nIt's very common that expressions end up as the difference of two squares. That name is very literal, $16 - 9$ is a difference of two squares, as it can be re-written as $4^2 - 3^2$.\n\nAny expression in the form $a^2 - b^2$ can be re-written as $(a+b)(a-b)$.\n\nFor example, $9x^4-x^2$ can be factorised to give $(3x^2+x)(3x^2-x)$. Note that sometimes you can do this twice, for example, $16x^4-81$ can be factorised to $(4x^2+9)(4x^2-9)$, where the second bracket can be further factorised to give $(4x^2+9)(2x+3)(2x-3)$.\n\n\\subsection{Factorising A Quadratic}\nSome quadratics can be factorised, which is essential when trying to solve them. There are usually two different methods that are taught.\n\n\\subsubsection{Method 1 — St. Andrew's Cross}\nMy friend always called this the St. Andrew's Cross method, even though the table that is built isn't layed out diagonally like the real St. Andrew's Cross is. I liked the name though, which is why I'll call it like so.\n\nA quadratic in the form $ax^2+bx+c$ where $a=1$ can be factorised by looking for factors of $c$, and then checking which of those factors adds to give $b$. Once a suitable pair of factors is found, they are placed in brackets in the form $(x+a)(x+b)$ where $a$ and $b$ are the two factors (which could potentially be negative).\n\nFor example, consider $x^2+6x+9$. The factors of $9$ are $1 \\cdot 9$, and $3 \\cdot 3$, where either both have to be positive or negative. To get $6$, positive $3$ and $3$ have to be added, $1$ and $9$ would give $10$ when added which isn't what is needed. So $x^2+6x+9$ can be factorised to give $(x+3)(x+3)$, which can be simplified to $(x+3)^2$.\n\nThe cross part comes when laying this method out. Suppose $x^2-3x-4$. First, the factors of $4$ should be written out in column of a table, and the sum of the pair should be written in the other column, as shown. In practice, after enough repetitiion, this can be done mentally, many people wouldn't write this table out.\n\n\\medskip\n\n\\begin{tabular}{r | l}\n\tFactors of $-4$ & Sums\\\\\n\t\\hline\n\t$4 \\cdot -1$ & $3$\\\\\n\t$-4 \\cdot 1$ & $-3$\\\\\n\t$2 \\cdot -2$ & $0$\\\\\n\t$-2 \\cdot 2$ & $0$\\\\\n\\end{tabular}\n\nFrom the table, it can be seen that the factors $-4 \\cdot 1$ give $-3$, so when $x^2-3x-4$ is factorised, $(x-4)(x+1)$ is received. Note that in practice, the table can be stopped after $-4 \\cdot 1$ is written out, since continuing is pointless and the table gives no extra marks.\n\nWhen $a \\neq 1$, it gets a little bit more difficult and is where the second method really shines.\n\nFirst, check if the whole quadratic can be simplified by taking out a common factor. For example, $6x^2+72x+120$ might look daunting, but can be simplified to $6(x^2+12x+20)$.\n\nIf $a$ is a prime number, one of the factors of $c$ has to be multiplied by $a$. This will make the table a lot longer.\n\nSuppose $5x^2+11x-12$. Here, the first factor is multiplied by $a$ and then, after the horizontal line, the second factor is multiplied by $a$; so for the first row, instead of $1 \\cdot -12$, $1$ is multiplied by $a$ (in this case $5$) to give $5 \\cdot -12$.\n\n\\medskip\n\n\\begin{tabular}{r | l}\n\tFactors & Sums\\\\\n\t\\hline\n\t$5 \\cdot -12$ & $-7$\\\\\n\t$-5 \\cdot 12$ & $7$\\\\\n\t$10 \\cdot -6$ & $-4$\\\\\n\t$-10 \\cdot 6$ & $4$\\\\\n\t$15 \\cdot -4$ & $11$\\\\\n\t$-15 \\cdot 4$ & $-11$\\\\\n\t\\hline\n\t$1 \\cdot -60$ & $-59$\\\\\n\t$-1 \\cdot 60$ & $59$\\\\\n\t$2 \\cdot -30$ & $-28$\\\\\n\t$-2 \\cdot 30$ & $28$\\\\\n\t$3 \\cdot -20$ & $-17$\\\\\n\t$-3 \\cdot 20$ & $17$\\\\\n\\end{tabular}\n\nAgain, the table can be stopped after $15 \\cdot -4$ is found, as that gives the correct sum of $11$, but for demonstration purposes the complete table is shown.\n\nNow that the factors have been found, they have to be placed in such a way so that when multiplied back out it'll give the correct value for $b$. This means that the factor that has been multiplied by $a$ has to be placed in the bracket that doesn't include $a$. So the factorisation of $5x^2+11x-12$ is $(5x-4)(x+3)$ (note that the unmultiplied factor is placed in the bracket!).\n\nWhen $a$ is not a prime number, all of its factors have to be considered. If $a$ is 4, for example, then the brackets could look like $(4x+a)(x+b)$ or $(2x+a)(2x+b)$. Even more possibilities have to be considered when making a table. A very difficult question might choose a value for $a$ which has many factors, such as $12$.\n\nSuppose $4x^2+8x+3$ had to be factorised. Firstly, it cannot be simplified by taking out a common factor, so all the factors of $c$ (in this case $3$) have to be listed and individually multiplied by $4$ or $2$. In the table, the first factor is multiplied by 4, then the second, then both terms are multiplied by $2$ and $2$. Since it's the same number, this doesn't need to be done twice. Negative numbers can be excluded, as both $b$ and $c$ are positive.\n\n\\medskip\n\n\\begin{tabular}{r | l}\n\tFactors & Sums\\\\\n\t\\hline\n\t$4 \\cdot 3$ & $7$\\\\\n\t\\hline\n\t$1 \\cdot 12$ & $13$\\\\\n\t\\hline\n\t$2 \\cdot 6$ & $8$\\\\\n\\end{tabular}\n\nSo finally, $4x^2+8x-3$ can be factorised to give $(2x+3)(2x+1)$.\n\nIf $a<0$ (if $a$ is negative), take out a common factor of $-1$. Suppose $-4x^2-8x-3$ had to be factorised.\n\n\\begin{align*}\n\t&-4x^2-8x-3\\\\\n\t&=-(4x^2+8x+3)\\\\\n\t&=-(2x+3)(2x+1)\\text{ This has been factorised above already}\\\\\n\t&=(-2x-3)(2x+1)\n\\end{align*}\n\nIt is most likly not necessary to remove the negative outside the bracket, but some might prefer the look of this.\n\n\\subsubsection{Method 2 — Splitting Up $b$}\nAt first, this might seem similar to the St. Andrew's Cross, but the only thing that's similar is that both require a table. This method is good because it doesn't require too many extra steps when $a \\neq 1$.\n\nFirstly, two numbers (later referred to as $p$ and $q$) have to be found such that their product is $ac$ and their sum is $b$. Then, re-write the quadratic $ax^2+bx+c$ in the form $ax^2+px+qx+c$. Partially factorise $ax^2+px$ and $qx+c$, and take out a common factor. As in method 1, if $a<0$, take out a common factor of $-1$ first.\n\nFor example, suppose $9x^2-3x-2$ had to be factorised. First, find $p$ and $q$ such that their product is $9 \\cdot -2$ ($=-18$) and their sum is $-3$.\n\n\\medskip\n\n\\begin{tabular}{r | l}\n\tFactors of -18 & Sums\\\\\n\t\\hline\n\t$1 \\cdot -18$ & $-17$\\\\\n\t$-1 \\cdot 18$ & $17$\\\\\n\t$2 \\cdot -9$ & $-7$\\\\\n\t$-2 \\cdot 9$ & $7$\\\\\n\t$3 \\cdot -6$ & $-3$\\\\\n\t$-3 \\cdot 6$ & $3$\\\\\n\\end{tabular}\n\nThe factors $3 \\cdot -6$ give $-3$, so $p=3$ and $q=-6$.\n\n\\begin{align*}\n\t&9x^2-3x-2\\\\\n\t&=9x^2+3x-6x-2\\\\\n\t&=3x(3x+1)-2(3x+1)\\\\\n\t&=(3x+1)(3x-2)\n\\end{align*}\n\n\n\\section{Completing the Square}\nCompleting the square is turning a quadratic from the form $ax^2 + bx + c$ to the form $p(x + q)^2+r$. There are multiple ways to do this, all of which will use the example quadratic $2x^2-6x+77$.\n\nThe question will always give the completed square form, that is $p(x - q)^2+r$ (though the variables might be different ones, like $a$, $b$, $c$, or so). This can be expanded, as shown.\n\\begin{align*}\n\t&p(x+q)^2+r\\\\\n\t&=p(x^2+2qx+q^2)+r\\\\\n\t&=px^2+2pqx+pq^2+r\n\\end{align*}\nIt can be seen that $a$ became $p$, $b$ became $2pq$, and $c$ became $pq^2+r$. From there, a series of equations can be made and solved (practically this is done from left to right as shown).\n\\begin{align*}\n\tp &= a & 2pq &= b         & pq^2+r &= c\\\\\n\tp &= 2 & 2 \\cdot 2q &=-24 & 2 \\cdot (-6)^2 + r &= 77\\\\\n\t  &    & 4q &= -24        & 2 \\cdot 36 + r &= 77\\\\\n\t  &    & q &= -6          & 72 + r &= 77\\\\\n\t  &    & &                & r &= 77 - 72\\\\\n\t  &    & &                & r &= 5\n\\end{align*}\nNow that $p$, $q$, and $r$ have been found, they can be substituted back into completed square form.\n\\begin{equation*}\n\t2x^2-24x+77 = 2(x-6)^2+5\n\\end{equation*}\n\n\\section{Rationalising the Denominator}\nWhen a fraction uses an irrational number as its denominator it can be difficult to understand what it's actually quantifying (try to imagine 5 $\\sqrt{2}$ pieces of pizza!). Instead, the denominator can be rationalised. This has to be done in the final answer to an exam question, but isn't necessary (and sometimes even unhelpful) to be done mid-question.\n\nWhen the denominator contains a root, the whole fraction should be multiplied by $1$ in the form of this root.\n\n\\begin{align*}\n\t&\\frac{5}{\\sqrt{2}}\\\\\n\t&=\\frac{5}{\\sqrt{2}} \\cdot \\frac{\\sqrt{2}}{\\sqrt{2}}\\\\\n\t&=\\frac{5\\sqrt{2}}{\\sqrt{2}\\sqrt{2}}\\\\\n\t&=\\frac{5\\sqrt{2}}{2}\n\\end{align*}\n\nAnd that is all there is to it, simply multiply the fraction by whatever root the denominator has. Here's another example.\n\n\\begin{align*}\n\t&\\frac{300\\sqrt{2}}{5\\sqrt{40}}\\\\[5pt]\n\t&=\\frac{300\\sqrt{2}}{5\\sqrt{4 \\cdot 10}}\\\\[5pt]\n\t&=\\frac{300\\sqrt{2}}{5 \\cdot 2\\sqrt{10}}\\\\[5pt]\n\t&=\\frac{300\\sqrt{2}}{10\\sqrt{10}}\\\\[5pt]\n\t&=\\frac{30\\sqrt{2}}{\\sqrt{10}}\\\\[5pt]\n\t&=\\frac{30\\sqrt{2}}{\\sqrt{10}} \\cdot \\frac{\\sqrt{10}}{\\sqrt{10}}\\\\[5pt]\n\t&=\\frac{30\\sqrt{2}\\sqrt{10}}{\\sqrt{10}\\sqrt{10}}\\\\[5pt]\n\t&=\\frac{30\\sqrt{2}\\sqrt{10}}{10}\\\\[5pt]\n\t&=3\\sqrt{2}\\sqrt{10}\\\\\n\t&=3\\sqrt{20}\\\\\n\t&=3\\sqrt{4 \\cdot 5}\\\\\n\t&=3 \\cdot 2 \\sqrt{5}\\\\\n\t&=6\\sqrt{5}\n\\end{align*}", "meta": {"hexsha": "6c79946698ab05e703de918435eae5183902b053", "size": 12101, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TeX_files/Skills.tex", "max_stars_repo_name": "TheSheepGuy/Open_Higher_Maths", "max_stars_repo_head_hexsha": "2667a8da00b2cab502a92fd0ec9c9db9c86bea5c", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-12-09T14:56:06.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-09T15:08:38.000Z", "max_issues_repo_path": "TeX_files/Skills.tex", "max_issues_repo_name": "TheSheepGuy/Definitive_Higher_Maths", "max_issues_repo_head_hexsha": "2667a8da00b2cab502a92fd0ec9c9db9c86bea5c", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-12-09T15:22:21.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-11T20:19:01.000Z", "max_forks_repo_path": "TeX_files/Skills.tex", "max_forks_repo_name": "TheSheepGuy/Definitive_Higher_Maths", "max_forks_repo_head_hexsha": "2667a8da00b2cab502a92fd0ec9c9db9c86bea5c", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-09T20:16:01.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-09T20:16:01.000Z", "avg_line_length": 54.7556561086, "max_line_length": 458, "alphanum_fraction": 0.6824229403, "num_tokens": 4058, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.7273596976213377}}
{"text": "\\subsection{Tidal Shear Tensor}\r\n\\label{section:forero-romero}\r\n\r\nThis method \\cite{2009MNRAS.396.1815F} works on density fields grids\r\nobtained either from numerical simulations or reconstructions from\r\nredshift surveys. \r\n\r\nThe method improves on the work by \\citep{2007MNRAS.375..489H}. It\r\nalso uses the Hessian of the gravitational potential \r\n\\begin{equation}\r\nT_{\\alpha\\beta} = \\frac{\\partial^2\\phi}{\\partial x_\\alpha\\partial x_\\beta},\r\n\\end{equation}\r\n%\r\nwhere the physical gravitational potential has been normalized by\r\n$4\\pi G\\bar{\\rho}$ so that $\\phi$ satisfies the Poisson\r\nequation\r\n\\begin{equation}\r\n\\nabla^2\\phi=\\delta,\r\n\\end{equation}\r\n%\r\nwith $\\delta$ the dimensionless matter overdensity, $G$ the\r\ngravitational constant and $\\bar{\\rho}$ the average density of the\r\nUniverse.\r\n\r\nThis tidal tensor can be represented by a real symmetric $3\\times 3$\r\nmatrix with eigenvalues $\\lambda_1>\\lambda_2>\\lambda_3$ and\r\neigenvectors ${\\bf e}_1$, ${\\bf e}_2$ and ${\\bf e}_3$. The eigenvalues\r\nare indicators of orbital stability along the directions defined by\r\nthe eigenvectors. \r\n\r\nThis method introduces a threshold $\\lambda_{\\rm th}$ to gauge the\r\nstrenght of the eigenvalues of the Tidal Shear Tensor. The number of\r\neigenvalues larger than the threshold is used to classify the cosmic\r\nweb into four kinds of environments: voids (3 eigenvalues smaller than\r\n$\\lambda_{\\th}$), sheets (2), filaments (1) and knots (0).\r\n\r\nIn practice the density is interpolated over a grid using the particle\r\ndata and a Cloud-In-Cell scheme. The Poisson equation is solved in\r\nFourier space to obtain the potential over a grid. At each grid cell\r\nthe shear tensor is computed to obtain and store the corresponding\r\neigenvalues and eigenvectors. The grid cell has a size of $\\sim\r\n1$Mpc/h and the threshold is fixed to be $\\lambda_{\\th}=0.2$ as\r\nsuggested by previous studies that aim at capturing the visual\r\nimpression of the cosmic web \\cite{2009MNRAS.396.1815F}. \r\n\r\n\r\n\r\n\r\n%%%%%%%%%%References used\r\n%@ARTICLE{2007MNRAS.375..489H,\r\n%   author = {{Hahn}, O. and {Porciani}, C. and {Carollo}, C.~M. and {Dekel}, A.\r\n%\t},\r\n%    title = \"{Properties of dark matter haloes in clusters, filaments, sheets and voids}\",\r\n%  journal = {\\mnras},\r\n%   eprint = {astro-ph/0610280},\r\n% keywords = {methods: N-body simulations , galaxies: haloes , cosmology: theory , dark matter , large-scale structure of Universe},\r\n%     year = 2007,\r\n%    month = feb,\r\n%   volume = 375,\r\n%    pages = {489-499},\r\n%      doi = {10.1111/j.1365-2966.2006.11318.x},\r\n%   adsurl = {http://adsabs.harvard.edu/abs/2007MNRAS.375..489H},\r\n%  adsnote = {Provided by the SAO/NASA Astrophysics Data System}\r\n%}\r\n\r\n\r\n\r\n%@ARTICLE{2009MNRAS.396.1815F,\r\n%   author = {{Forero-Romero}, J.~E. and {Hoffman}, Y. and {Gottl{\\\"o}ber}, S. and \r\n%\t{Klypin}, A. and {Yepes}, G.},\r\n%    title = \"{A dynamical classification of the cosmic web}\",\r\n%  journal = {\\mnras},\r\n%archivePrefix = \"arXiv\",\r\n%   eprint = {0809.4135},\r\n% keywords = {methods: numerical , cosmology: large-scale structure of Universe},\r\n%     year = 2009,\r\n%    month = jul,\r\n%   volume = 396,\r\n%    pages = {1815-1824},\r\n%      doi = {10.1111/j.1365-2966.2009.14885.x},\r\n%   adsurl = {http://adsabs.harvard.edu/abs/2009MNRAS.396.1815F},\r\n%  adsnote = {Provided by the SAO/NASA Astrophysics Data System}\r\n%}\r\n\r\n\r\n\r\n\r\n\r\n", "meta": {"hexsha": "5ff90afc2cb617651dd9683f8677302faaffb3f1", "size": 3339, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/forero-romero.tex", "max_stars_repo_name": "forero/LorentzComparisonProject", "max_stars_repo_head_hexsha": "bef3197a9a5e07159f8837dd09d12b4086d495e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/forero-romero.tex", "max_issues_repo_name": "forero/LorentzComparisonProject", "max_issues_repo_head_hexsha": "bef3197a9a5e07159f8837dd09d12b4086d495e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/forero-romero.tex", "max_forks_repo_name": "forero/LorentzComparisonProject", "max_forks_repo_head_hexsha": "bef3197a9a5e07159f8837dd09d12b4086d495e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.5168539326, "max_line_length": 133, "alphanum_fraction": 0.6963162624, "num_tokens": 1004, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248140158416, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7273530133689152}}
{"text": "\\section{Modelling with Matrices}\n    \n    \\subsection{Intro to Matrices}\n    A matrix is a rectangular array of numbers that is used to organize data.\n    If you are used to computer programming, you will recognize them as 2D arrays.\n    If you are good with set notation, they are in essence, a set of sets.\n    Matrices follow the format below:\n    \\begin{equation*}\n        X =\n        \\begin{bmatrix}\n            a & b & c \\\\\n            d & e & f\n        \\end{bmatrix}\n    \\end{equation*}\n    Matrices have various properties, and unique terms created to describe them.\n    For instance, looking at the matrix above, we can safely say that $a$ in an entry, as defined below.\n    \\begin{definition}\n        Entry: An entry refers to a number in a matrix.\n    \\end{definition}\n    How did we figure out the number of entries in the matrix? Simple, we can use the matrix's \\emph{dimensions} to figure that out.\n    \\begin{definition}Dimensions:\n        These refer to the size of the matrix, described by the number of rows and columns.\n        The formula below is used to solve for dimensions, where D is the result, $R$ is the rows, and $C$ is the columns.\n        \\begin{equation*}\n                D = R \\cdot C\n        \\end{equation*}\n    \\end{definition}\n    Matrix's entries are numbered in a way so that it is easy to refer to a specific entry.\n    Capital letters are used for the names of matrices, and lowercase characters are used for the names of entries.\n    Shown below are the entries named, with numbers instead of letters.\n    The first character represents the y value, whereas the second represents the x value.\n    In the equation below, $a_{13}$ represents the entry in row 1, column 3.\n    \\begin{equation*}\n        X =\n        \\begin{bmatrix}\n            a_{11} & a_{12} & a_{13} \\\\\n            a_{21} & a_{22} & a_{23}\n        \\end{bmatrix}\n    \\end{equation*}\n        \n    \\subsection{Variations and Classifications of Matrices}\n    Matrices can be transformed, and compared to each other, much like sets.\n    The definitions of the variations and classifications of the matrices are listed below.\n    \\begin{definition}Transpose Matrix: \n        A transpose matrix is a matrix obtained by interchanging the rows and columns. This is written as $X^{+}$. Shown below is Matrix W, and the transposed equivalent.\n        \\begin{equation*}\n            W =\n            \\begin{bmatrix}\n                a & b & c \\\\\n                d & e & f\n            \\end{bmatrix}\n            -> X^{+} =\n            \\begin{bmatrix}\n                a & d \\\\\n                b & e \\\\\n                c & f\n            \\end{bmatrix}\n        \\end{equation*}\n    \\end{definition}\n        \n    \\begin{definition}Column Matrix:\n        A Column Matrix is a matrix that has only one x value. Instead of rows and columns, it is merely a column.\n        For instance, Matrix X in this case would be a Column Matrix.\n        \\begin{equation*}%Column Matrix\n            X =\n            \\begin{bmatrix}\n                a&\\\\\n                b&\\\\\n                c\n            \\end{bmatrix}\n        \\end{equation*}\n    \\end{definition}\n        \n    \\begin{definition}Row Matrix:\n        A Row Matrix is a matrix that has only one y value. It is the transpose of the Column Matrix For instance, Matrix Y in this case would be a Row Matrix.\n        \\begin{equation*}%Row Matrix\n            Y =\n            \\begin{bmatrix}\n                a & b & c\n            \\end{bmatrix}\n        \\end{equation*}\n    \\end{definition}\n        \n    \\begin{definition}Square Matrix:\n        A Square Matrix is a matrix in which the rows and columns are equal.\n        For instance, Matrix Z below is a Square Matrix.\n        \\begin{equation*}%Column Matrix\n            Z =\n            \\begin{bmatrix}\n                a & b & c\\\\\n                d & e & f\\\\\n                g & h & i\n            \\end{bmatrix}\n        \\end{equation*}\n    \\end{definition}\n        \n    \\subsection{Basic Operations with Matrices}\n        Matrices may only be added or subtracted when they have the same dimensions.\n        Adding matrices is done by adding entry by entry to the other matrix.\n        $A_{12}$ will be added with $B_{12}$ and so forth.\n        Shown below is a valid example of adding with matrices in which the entries are labeled to show proper addition:\n        \\begin{equation*}\n            \\begin{bmatrix}\n                a_{11} & a_{12} & a_{13} \\\\\n                a_{21} & a_{22} & a_{23}\n            \\end{bmatrix}\n            +\n            \\begin{bmatrix}\n                b_{11} & b_{12} & b_{13} \\\\\n                b_{21} & b_{22} & b_{23}\n            \\end{bmatrix}\n            =\n            \\begin{bmatrix}\n                (a+b)_{11} & (a+b)_{12} & (a+b)_{13} \\\\\n                (a+b)_{21} & (a+b)_{22} & (a+b)_{23}\n            \\end{bmatrix}\n        \\end{equation*}\n        They may also be multiplied by a coefficient, by multiplying the coefficient with every entry in the matrix.\n        Shown below is a proper solution in which a matrix is multiplied by a coefficient, with entries labeled:\n         \\begin{equation*}\n            x\n            \\begin{bmatrix}\n                y_{11} & y_{12} & y_{13} \\\\\n                y_{21} & y_{22} & y_{23}\n            \\end{bmatrix}\n            =\n            \\begin{bmatrix}\n                xy_{11} & xy_{12} & xy_{13} \\\\\n                xy_{21} & xy_{22} & xy_{23}\n            \\end{bmatrix}\n        \\end{equation*}\n        \n    \\subsection{Multiplying Matrices Together}\n        Matrices may also be multiplied with other matrices, yet to do so we must follow certain rules.\n        Let's say we have Matrix A and Matrix B as shown below.\n        To multiply, we need to make sure the \\emph{inner dimensions} are the same.\n        We know that Matrix A's dimensions are $3 \\cdot 2$, whereas for Matrix B, they are $2 \\cdot 3$.\n        Since we know this, we can find the \\emph{inner dimensions}.\n        The \\emph{inner dimensions}, equals the columns of Matrix A and the rows of Matrix B.\n        In this case, that would work out to be $3$ and $3$.\n        Since they are the same, we are allowed to multiply these matrices. \n        \\begin{equation*}%Demonstrating Matrices. \n            A =\n            \\begin{bmatrix}\n                a & b & c\\\\\n                d & e & f\\\\\n            \\end{bmatrix}\n            B = \n            \\begin{bmatrix}\n                u & v\\\\\n                w & x\\\\\n                y & z\n            \\end{bmatrix}\n        \\end{equation*}\n        Next, the rows of Matrix A times the columns of Matrix B, also known as the \\emph{outer dimensions}, will give us the dimensions of the resultant matrix.\n        Since Matrix A has two rows, and Matrix B has two columns, our resultant Matrix will possess the dimensions $2\\cdot2$.\n        Shown below is the updated equation. \n        \\begin{equation*}\n            \\begin{bmatrix}\n                a & b & c\\\\\n                d & e & f\\\\\n            \\end{bmatrix}\n        \\cdot\n            \\begin{bmatrix}\n                u & v\\\\\n                w & x\\\\\n                y & z\n            \\end{bmatrix}\n            =\n            \\begin{bmatrix}\n                ?&?\\\\\n                ?&?\n            \\end{bmatrix}\n        \\end{equation*}\n        Multiplying them is a bit strange at first, because to do it, we multiply row by row.\n        Starting at the first row in Matrix A, we can see we have $a_{11},b_{12},c_{13}$ as our values, with their locations being labeled for convenience.\n        We must multiply these values each column in Matrix B, starting with the values $u_{11},w_{21},y_{31}$.\n        To find entry (1,1) we can use the formula shown below, where $E$ represents the entry, $r$ represents a row in Matrix A, and c represents a column in Matrix B.\n        \\begin{equation*}\n            E_{11} = r_{11} \\cdot c_{11}  +  r_{12} \\cdot c_{21}  +   r_{13} \\cdot c_{31}\n        \\end{equation*}\n        If you want to do it just by eye, you can multiply $A_{11}$ by $B_{11}$, $A_{12}$ by $B_{21}$, and $A_{13}$ by $B_{31}$, and add them all up.\n        It will seem totally awful at first, but after you do a couple it'll all work out fine.\n        \n    \\subsection{Identity Matrices}\n        An Identity Matrix is a $n\\cdot n$ size matrix in which every number along the main diagonal is a 1, and the rest are zeros.\n        Shown below is Matrix I, a $3\\cdot 3$ Identity Matrix.\n        \\begin{equation*}\n        I =\n            \\begin{bmatrix}\n                1 & 0 & 0\\\\\n                0 & 1 & 0\\\\\n                0 & 0 & 1\n            \\end{bmatrix}\n        \\end{equation*}\n        This matrix is very special, as any square matrix multiplied by its inverse will equal an Identity Matrix.\n        We can further formalize this assumption, by referring to a given matrix as Matrix A.\n        \\begin{equation*}\n            A\\cdot A^{-1} = I\n        \\end{equation*}\n        Its too bad we can't divide matrices, how can we ever solve for I now? Good thing we can use something called an Inverse Matrix.\n        \n    \\subsection{Finding Inverse Matrices}\n        Finding the inverse of large matrices is one of the most mathematically intensive processes out there.\n        Good thing we'll only be finding the inverse of a $2\\cdot2$ matrix instead. To find the inverse of a $2\\cdot 2$ matrix, we must use first define the matrices.\n        \\begin{equation*}\n        A = \n            \\begin{bmatrix}\n                a & b\\\\\n                c & d\n            \\end{bmatrix}\n        \\end{equation*}\n        Now that we have the starting matrix, it is time to find the inverse. To find it, we must multiply the determinant, by the matrix, and swap several spots of numbers. Again, sounds odd, but we just need to follow the formula below.\n        \\begin{equation*}\n        A^{-1} = \\frac{1}{ad-bc}\n            \\begin{bmatrix}\n                d & -b\\\\\n                -c & a\n            \\end{bmatrix}\n        \\end{equation*}\n        After this step, simply multiply the determinant into the matrix, and you have found $A^{-1}$!", "meta": {"hexsha": "58b275dc22590d44cc307eeebd1719741c755655", "size": 10037, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "highschool-projects/MDM4UI/Matrices.tex", "max_stars_repo_name": "johnaoss/dead-projects", "max_stars_repo_head_hexsha": "f8a911a8d08dc34bf52a8d1afd8493a3fcb7f2ca", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "highschool-projects/MDM4UI/Matrices.tex", "max_issues_repo_name": "johnaoss/dead-projects", "max_issues_repo_head_hexsha": "f8a911a8d08dc34bf52a8d1afd8493a3fcb7f2ca", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "highschool-projects/MDM4UI/Matrices.tex", "max_forks_repo_name": "johnaoss/dead-projects", "max_forks_repo_head_hexsha": "f8a911a8d08dc34bf52a8d1afd8493a3fcb7f2ca", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.4162895928, "max_line_length": 238, "alphanum_fraction": 0.5670020923, "num_tokens": 2575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894717137996, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7273451179012955}}
{"text": "\\subsection{Document embedding}\n    \\label{sec:document_embedding}\n\n    \\paragraph{TF-IDF.} Before texts can be fed into machine learning models, they need to become numbers, usually vectors. These vectors are called text embeddings, and, in the case of long documents, document embeddings. There are many document embedding techniques available, but, for the scope of this work, we will use TF-IDF \\cite{robertson2004understanding}.\n\n    Briefly, for each document, and for each word, TF-IDF counts the frequency of this word relative to this document (term frequency - TF). This count is ``normalized'' by the rarity of the word in the entire set of documents (inverse document frequency - IDF). More formally, for a term $t$ inside document $d$ with frequency $f_{t, d}$,\n    \\[\\text{tf-idf}(t, d) = \\text{tf}(t, d) \\times \\text{idf}(t),\\]\n    \\[\\text{tf}(t, d) = \\frac{f_{t, d}}{\\sum_{t' \\in d} f_{t', d}}, \\ \\ \\text{idf}(t) = \\ln \\frac{1+n}{1+\\text{df}(t)}+1,\\]                  \n    where $n$ is the number of documents and $\\text{df}(t)$ is the number of documents that contain $t$. The TF-IDF weights, in the end, construct a vector that represents the document in a very high dimensional space.\n\n    \\paragraph{Dimensionality reduction.} Because vectors' dimensionality is too high, we perform a dimensionality reduction to have the vectors treatable by our models. The vectors will be reduced from dimensionality of thousands to dimensionality 50 using truncated singular value decomposition (SVD). It consists of decomposing our matrix $X$ (with rows being the TF-IDF vectors) in\n    \\[X = U \\Sigma V^\\intercal,\\]                  \n    where $\\Sigma$ is a diagonal matrix of the singular values of $X$. If we take only the $k$ greatest singular values, we will have\n    \\[X_{n \\times p} = U_{n \\times k} \\Sigma_{k \\times k} \\left[V^\\intercal\\right]_{k \\times p},\\]                  \n    and our new data points will be $X_{n \\times p} V_{p \\times k}$, with reduced dimensionality $k$. This is very similar to principal component analysis, and equivalent when data is centered (mean zero in each component).\n\n", "meta": {"hexsha": "004a74fec0ae1e83195b240089b679e6ea6b0571", "size": 2119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "a2_assignment/document_embedding.tex", "max_stars_repo_name": "lucasresck/machine-learning", "max_stars_repo_head_hexsha": "fd038632bf5c5d58a3e7ccf939b27b3d71ae648a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "a2_assignment/document_embedding.tex", "max_issues_repo_name": "lucasresck/machine-learning", "max_issues_repo_head_hexsha": "fd038632bf5c5d58a3e7ccf939b27b3d71ae648a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "a2_assignment/document_embedding.tex", "max_forks_repo_name": "lucasresck/machine-learning", "max_forks_repo_head_hexsha": "fd038632bf5c5d58a3e7ccf939b27b3d71ae648a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 124.6470588235, "max_line_length": 385, "alphanum_fraction": 0.7059933931, "num_tokens": 556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.727345117144077}}
{"text": "\\subsection{Newton's Method}\\label{sec:Newton}\nA well known numeric method is \\ifont{Newton's Method} (also sometimes\nreferred to as \\ifont{Newton-Raphson's Method}), named after Isaac Newton\nand Joseph Raphson.  This method is used to find roots, or\n$x$-intercepts, of a function.  While we may be able to find the roots\nof a polynomial which we can easily factor, we saw in the previous\nchapter on {\\bf Limits}, that for example the function $e^x + x = 0$\nhas a solution ($i.e.$ root, or $x$-intercept) at $x \\approx\n-0.56714$.  By the \\ifont{Intermediate Value Theorem} we know that the\nfunction $e^x + x = 0$ does have a solution. We cannot here simply\nsolve for such a root algebraically, but we can use a numerical method\nsuch as $Newton's$.  Such a process is typically classified as an\n$iterative$ method, a name given to a technique which involves\nrepeating similar steps until the desired accuracy is obtained.   Many\ncomputer $algorithms$ are coded with a for-loop, repeating an\niterative step to converge to a solution.\n\nThe idea is to start with an initial value $x_0$ (approximating the\nroot), and use linear approximation to create values $x_1$, $x_2$, $\\cdots$ getting closer and closer to a root. \n\nThe first value $x_1$ corresponds to the intercept of the tangent line\nof $f(x_0)$ with the $x$-axis, which is:\n\\[ x_1 = x_0 -\\frac{f(x_0)}{f'(x_0)} \\]\n\n\\figure[!ht]\n$$\\includegraphics[width=1.75in]{images/newton_figure_1}$$\n\\caption{First iteration of Newton's Method. \\label{fig:Newton1}} \n\\endfigure\n\nWe can see in Figure~\\ref{fig:Newton1}, that if we compare the point $(x_0,0)$ to\n$(x_1,0)$, we would likely come to the conclusion that $(x_1,0)$ is\ncloser to the actual root of $f(x)$ than our original guess,\n$(x_0,0)$.  As will be discussed, the choice of $x_0$ must be done\ncorrectly, and it may occur that $x_1$ does not yield a better\nestimate of the root.\n\nNewton's method is simply to repeat this process again and again \nin an effort to obtain a more accurate solution.  Thus at the next step we obtain:\n\n\\[ x_2 = x_1 -\\frac{f(x_1)}{f'(x_1)} \\]\n\n\\figure[!ht]\n$$\\includegraphics[width=1.75in]{images/newton_figure_2}$$\n\\caption{Second iteration of Newton's Method. \\label{fig:Newton2}}\n\\endfigure\n\nWe can now clearly see how $(x_2,0)$ is a better estimate of the root\nof $f(x)$, rather than any of the previous points.  Moving forward, we\nwill get:\n\\[ x_3 = x_2 -\\frac{f(x_2)}{f'(x_2)} \\]\nRest assured, $(x_3,0)$ will be an even better estimate of the root!  We express the general iterative step as:\n\\[ x_{n+1} = x_n -\\frac{f(x_n)}{f'(x_n)} \\]\n\nThe idea is to iterate these steps to obtain the desired accuracy. Here is an example. \n\n\\begin{example}{Newton method to approximate roots}{newtonroot}\nUse Newton's method to approximate the roots of $f(x)=x^3-x+1$.\n\\end{example}\n\n\\begin{solution}\nYou can try to find solve the equation algebraically to see that this\nis a difficult task, and thus it make sense to try a numerical method\nsuch as Newton's.\n\nTo find an initial value $x_0$, note that $f(-1)=-5$ and $f(0)=1$,\nand by the Intermediate Value Theorem this $f$ has a root between these two values, and we decide to start with $x_0=-1$ (you can try other values to see what happens).\n\nNote that $f'(x)=3x^2-1$, and thus we get\n\\[ x_{n+1} = x_n -\\frac{f(x_n)}{f'(x_n)} = x+n - \\frac{x^3_n-x_n+1}{3x^2_n-1} \\]\nThus we can produce the following values (try it):\n\\[ \\begin{array}{l}\nx_0 = -1 \\\\\nx_1= -1.5000\\\\\nx_2 = -1.347826.. \\\\\nx_3= -1.325200.. \\\\\nx_4 = -1.324718.. \\\\\nx_5 = -1.324717..  \\\\\nx_6 = -1.324717..  \\\\\n\\cdots\n\\end{array} \\]\nand we can now approximate the root as $-1.324717$.\n\\end{solution}\n\nAs with any numerical method, we need to be aware of the weaknesses of\nany technique we are using.\n\n\\figure[!ht]\n$$\\includegraphics[width=2.5in]{images/newton_figure_4}$$\n\\caption{Function with three distinct solutions. \\label{fig:Newton4}}\n\\endfigure\n\n%% need an easy example here\n\nIf we know our root is somewhere near $a$, we would make our guess\n$x_0=a$.  Generally speaking, a good practice is to make our guess as\nclose to the actual root as possible. In some cases we may have no idea where the root is, so it would be prudent to\nperform the algorithm several times on several different initial\nguesses and analyze the results. \n\nFor example we can see in Figure~\\ref{fig:Newton4} that $f(x)$ in fact has three roots, and depending on our initial\nguess, we may get the algorithm to converge to different roots.  If we\ndid not know where the roots were, we would try the technique several\ntimes.  In one instance, if our initial guess was $x_a$, we'd\nlikely converge to $(a, 0)$.  Then if we were to choose another\nguess, $x_b$, then we'd likely converge to $(b, 0)$.\nEventually, using various initial guesses we'd get one of three roots:\n$a$, $b$, or $c$.  Under these circumstances we can\nclearly see the effectiveness of this numeric method.\n\n\\figure[!ht]\n$$\\includegraphics[width=3.5in]{images/newton_figure_3}$$\n\\caption{Newton's Method applied to $\\sin x$. \\label{fig:Newton3}}\n\\endfigure\n\nAs another example if we attempt to use $Newton's$ $Method$ on $f(x) =\n\\sin x$ using $x_0=\\pi/2$, then $f'(x_0)=0$ so $x_1$ is undefined and we cannot proceed. \nEven in general $x_{n+1}$ is typically nowhere near $x_n$,\nand in general not converging to the root nearest to our initial guess\nof $x_0$.  In effect, the algorithm keeps \"bouncing around\". An example of which is depicted in Figure~\\ref{fig:Newton3}. Based on\nour initial guess for such a function, the algorithm may or may not\nconverge to a root, or it may or may not converge to the root {\\bf\nclosest} to the initial guess.  This gives rise to the more common\nissue: Selection of the initial guess, $x_0$.\n\nHere is a summary.\n\n{\\bf Key Points in using Newton's method to approximate a root of $f(x)$}\n\n\\begin{enumerate}\n\\item Choosing $x_0$ as close as possible to the root we wish to find.\n\\item A guess for $x_0$ which makes the algorithm ``bounce around'' is considered $unstable$.\n\\item Even the smallest changes to $x_0$ can have drastic effects: We may converge to another root, \nwe may converge very slowly (requiring many more iterations), or we may encounter an unstable point.\n\\item We may encounter a $stationary$ $point$ if we choose $x_0$ such that $f'(x)=0$ ($i.e.$ at a critical point!) in which case the algorithm fails.\n\\end{enumerate}\n\nThis is all to say that your initial guess for $x_0$ can be extremely\nimportant.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Newton}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex} \nUse Newton's Method to find all roots of $f(x)=3x^2-9x-11$. (Hint: use Intermediate Value Theorem to choose an appropriate $x_0$)\n\\begin{sol}\n\tNotice that $f(-2)=19$, $f(0)=-11$, and $f(5)=19$ and $f$ is a continuous function. By the\n\tIntermediate Value Theorem there exists a root in $[-2,0]$ and $[0,5]$. Choose $x_0=0$, then $x_4\\approx -0.93242$.\n\tChoose $x_0=5$, then $x_4\\approx 3.93242$.\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex} \nConsider $f(x)=x^3-x^2+x-1$.\n\\begin{enumerate}\n\t\\item\tUsing initial approximation $x_0=2$, find $x_4$.\n\t\\item\tWhat is the exact value of the root of $f$? How does this compare to our approximation $x_4$ in part (a)?\n\t\\item\tWhat would happen if we chose $x_0=0$ as our initial approximation?\n\\end{enumerate}\n\\begin{sol}\n\\begin{enumerate}\n\t\\item\t$x_4\\approx 1.00022\\ldots$\n\t\\item\t$x=1$ is the root of $f$. Our approximation in part (a) was correct to 3 decimal places.\n\t\\item\t$x_1=1$. The root is found in one iteration of Newton's Method.\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex} \nConsider $f(x)=\\sin x$. What happens when we choose $x_0=\\pi/2$? Explain.\n\\begin{sol}\n\t$\\cos (\\pi/2)=0$, so $x_1$ is undefined.\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "b9c24bd101d1f694c7e2c846cb07c66b1ae350cc", "size": 7825, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-4-4-newtons-method.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5-applications-of-derivatives/5-4-4-newtons-method.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5-applications-of-derivatives/5-4-4-newtons-method.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.9945054945, "max_line_length": 168, "alphanum_fraction": 0.7145047923, "num_tokens": 2410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.9111797154386843, "lm_q1q2_score": 0.7272916010077084}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage[margin=1in]{geometry}\n\n\\begin{document}\n\n\\section{Cold Neutrals}\n\nThe number of reactions per unit time per unit volume is given by \n\n\\begin{equation}\n\tR_{12} (\\mathbf{v_i},\\ \\mathbf{v_n}) = \\frac{n_i n_n}{1 + \\delta_{12}} v_r \\sigma(v_r) f_i(\\mathbf{v_i}) f_n(\\mathbf{v_n}) \\mathrm{d}^3 \\mathbf{v_i} \\mathrm{d}^3 \\mathbf{v_n}\n\\end{equation}\n\nWhere $\\delta_{ij} = 1$ only if $i = j$, and it 0 otherwise, is included to avoid double counting when considering intra-species reactions.\n\nWe can plug in the Maxwellian for ions in the rotating plasma with a bulk fluid velocity of $\\mathbf{v_f}$\n\n\\begin{equation}\n\tf_i(\\mathbf{v_i}) = \\left( \\frac{m_i}{2 \\pi T_i} \\right)^{\\frac{3}{2}} \\exp \\left( -\\frac{m_i (\\mathbf{v_i} - \\mathbf{v_f})^2}{2 T_i} \\right)  \n\\end{equation}\n\nAnd the delta function for the cold neutrals\n\n\\begin{equation}\n\tf_n(\\mathbf{v_n}) = \\delta( \\mathbf{v_n} )\n\\end{equation}\n\nAnd we get \n\n\\begin{equation}\n\tR_{12} (\\mathbf{v_i},\\ \\mathbf{v_n}) = \\Lambda v_r \\sigma(v_r) \\exp \\left[ - \\frac{m_i (\\mathbf{v_i} - \\mathbf{v_f})^2}{2 T_i} \\right] \\delta( \\mathbf{v_n} ) \\mathrm{d}^3 \\mathbf{v_i} \\mathrm{d}^3 \\mathbf{v_n}\n\\end{equation}\n\nWhere\n\n\\begin{equation}\n\t\\Lambda = \\frac{n_i n_n}{1 + \\delta_{12}} \\left( \\frac{m_i}{2 \\pi T_i} \\right)^{\\frac{3}{2}} \n\\end{equation}\n\nWe then make the assumption that $v_r \\approx v_i$ and make a transformation into spherical coordinates where the Jacobian is $\\mathrm{d}^3 \\mathbf{v_i} = v_i^2 \\sin \\theta_i \\mathrm{d} v_i \\mathrm{d} \\theta_i \\mathrm{d} \\phi_i$. We also align the z-axis of the transform with the fluid velocity:\n\n\\begin{align*}\n\tv_{ix} &= v_i \\sin \\theta_i \\cos \\phi_i, \\quad &v_{fx} &= 0 \\\\\n\tv_{iy} &= v_i \\sin \\theta_i \\sin \\phi_i, \\quad &v_{fy} &= 0 \\\\\n\tv_{iz} &= v_i \\cos \\theta_i, \\quad &v_{fz} &= v_f\n\\end{align*}\n\nSo that the integrand now becomes\n\n\\begin{equation}\n\tR_{12} (v_i) = \\Lambda v_i^3 \\sigma(v_i) \\sin \\theta_i \\exp \\left[ -\\frac{m_i (v_i^2 + v_f^2 - 2 v_i v_f \\cos \\theta_i)}{2 T_i} \\right] \\delta( \\mathbf{v_n} ) \\mathrm{d} v_i \\mathrm{d} \\theta_i \\mathrm{d} \\phi_i  \\mathrm{d}^3 \\mathbf{v_n}\n\\end{equation}\n\nOnly the delta function is a function of $\\mathbf{v_n}$, so that integrates out to 1. We can then solve the integral up to $v_i$.\n\n\\begin{align}\n\tR_{12} &= \\Lambda \\exp \\left( -\\frac{m_i v_f^2}{2 T_i} \\right)  \\int_0^\\infty \\int_0^{\\pi} \\int_0^{2 \\pi} v_i^3 \\sigma(v_i) \\sin \\theta_i \\exp \\left[ -\\frac{m_i (v_i^2 - 2 v_i v_f \\cos \\theta_i)}{2 T_i} \\right] \\mathrm{d} \\phi_i \\mathrm{d} \\theta_i \\mathrm{d} v_i \\\\\n\t&= 2 \\pi \\Lambda \\exp \\left( -\\frac{m_i v_f^2}{2 T_i} \\right)  \\int_0^\\infty \\int_0^{\\pi} v_i^3 \\sigma(v_i) \\sin \\theta_i \\exp \\left[ - \\frac{m_i (v_i^2 - 2 v_i v_f \\cos \\theta_i)}{2 T_i} \\right] \\mathrm{d} \\theta_i \\mathrm{d} v_i \\\\\n\t&= \\frac{4 \\pi \\Lambda T_i}{m_i v_f} \\exp \\left( -\\frac{m_i v_f^2}{2 T_i} \\right)  \\int_0^\\infty v_i^2 \\sigma(v_i) \\sinh \\left( \\frac{m_i v_i v_f}{T_i} \\right) \\exp \\left( -\\frac{m_i v_i^2}{2 T_i} \\right) \\mathrm{d} v_i \\\\\n\t&= \\frac{2 n_i n_n}{v_f (1 + \\delta_{12})} \\left( \\frac{m_i}{2 \\pi T_i} \\right)^{\\frac{1}{2}} \\exp \\left( -\\frac{m_i v_f^2}{2 T_i} \\right)  \\int_0^\\infty v_i^2 \\sigma(v_i) \\sinh \\left( \\frac{m_i v_i v_f}{T_i} \\right) \\exp \\left( -\\frac{m_i v_i^2}{2 T_i} \\right) \\mathrm{d} v_i\n\\end{align}\n\nWe can then define everything in terms of the mach number normalized to the sound speed, $M = \\frac{v_f}{v_s}$, where $v_s = \\sqrt{\\frac{Z T_e}{m_i}}$ and $Z$ is the ion charge state and $T_e$ the electron temperature. The thermal speed is $v_{th} = \\sqrt{\\frac{2 T_i}{m_i}}$, so we can say that the thermal Mach number is $M_{th} = M \\sqrt{\\frac{Z T_e}{2 T_i}}$. We can also simplify by expanding the $\\sinh$ term.\n\n\\begin{align}\n\tR_{12} &= \\frac{n_i n_n}{\\sqrt{\\pi} (1 + \\delta_{12})} \\frac{1}{v_f v_{th}} \\exp \\left( -\\frac{v_f^2}{v_{th}^2} \\right)  \\int_0^\\infty v_i^2 \\sigma(v_i) \\left[ \\exp \\left( \\frac{2 v_i v_f}{v_{th}^2} \\right) - \\exp \\left( -\\frac{2 v_i v_f}{v_{th}^2} \\right) \\right] \\exp \\left( -\\frac{v_i^2}{v_{th}^2} \\right) \\mathrm{d} v_i\\\\\n\t&= \\frac{n_i n_n}{M_{th} v_{th}^2 \\sqrt{\\pi} (1 + \\delta_{12})} \\int_0^\\infty v_i^2 \\sigma(v_i) \\left\\lbrace \\exp \\left[ -\\left( M_{th} - \\frac{v_i}{v_{th}} \\right)^2 \\right] - \\exp \\left[ -\\left( M_{th} + \\frac{v_i}{v_{th}} \\right)^2 \\right] \\right\\rbrace \\mathrm{d} v_i\n\\end{align}\n\nThen making the substitution that $u = \\frac{v_i}{v_{th}}$ we're left with\n\t\n\\begin{equation}\n\tR_{12} = \\frac{n_i n_n v_{th}}{M_{th} \\sqrt{\\pi} (1 + \\delta_{12})} \\int_0^\\infty u^2 \\sigma(v_{th} u) \\left\\lbrace \\exp \\left[ -\\left( M_{th} -  u \\right)^2 \\right] - \\exp \\left[ -\\left( M_{th} + u \\right)^2 \\right] \\right\\rbrace \\mathrm{d} u\n\\end{equation}\n\nThe same can be applied to electron impact cross sections, where $v_{th} = \\sqrt{\\frac{2 T_e}{m_e}}$ and $M_{th} = M \\sqrt{\\frac{Z}{2}}$\n\n\\begin{equation}\n\tR_{12} = \\frac{n_e n_n v_{th}}{M_{th} \\sqrt{\\pi} (1 + \\delta_{12})} \\int_0^\\infty u^2 \\sigma(v_{th} u) \\left\\lbrace \\exp \\left[ -\\left( M_{th} -  u \\right)^2 \\right] - \\exp \\left[ -\\left( M_{th} + u \\right)^2 \\right] \\right\\rbrace \\mathrm{d} u\n\\end{equation}\n\n\\section{Hot Neutrals}\n\nNow looking at the regime where a charge exchange has occurred, and the neutrals are `hot' and moving at the fluid velocity, $v_f$, with a thermal spread equal to that of the ions, $T_i$. In the rotating frame of reference, there is no fluid velocity offset in the Maxwellian. Therefore, we can look at what the rate reaction is for ion and electon impact. The distribution function for the hot neutrals is Maxwellian.\n\n\\begin{equation}\n\tf_n(\\mathbf{v_n}) = \\left( \\frac{m_n}{2 \\pi T_n} \\right)^{\\frac{3}{2}} \\exp \\left( -\\frac{m_n v_n^2}{2 T_n} \\right)  \n\\end{equation}\n\n\\subsection{Ion Impact}\n\nThe distribution functions for the ions in the rotating reference frame is\n\n\\begin{equation}\n\tf_i(\\mathbf{v_i}) = \\left( \\frac{m_i}{2 \\pi T_i} \\right)^{\\frac{3}{2}} \\exp \\left( -\\frac{m_i v_i^2}{2 T_i} \\right)  \n\\end{equation}\n\nAssuming that the thermal spread is equal for the neutral and ion, we have $T_i = T_n$. The rate coefficient for two Maxwellians in thermal equilibrium is\n\n\\begin{equation}\n\tR_{12} = 4 \\pi \\left( \\frac{\\mu}{2 \\pi T_i} \\right)^{3/2} \\int_0^\\infty \\sigma(v_r) v_r^3 \\exp{ \\left( -\\frac{\\mu v_r^2}{2 T_i} \\right) }\n\\end{equation}\n\nWhere $\\mu = \\frac{m_i m_n}{m_i + m_n}$ is the reduced mass, and $\\mathbf{v_r} = |\\mathbf{v_i} - \\mathbf{v_n}|$ is the relative velocity. We can convert this expression to be in terms of center-of-mass energy, $\\varepsilon = \\frac{1}{2} \\mu v_r^2$.\n\n\\begin{equation}\n\tR_{12} = \\frac{4}{(2 \\pi \\mu)^{\\frac{1}{2}} T_i^{\\frac{3}{2}}} \\int_0^\\infty \\varepsilon \\sigma(\\varepsilon) \\exp{ \\left( -\\frac{\\varepsilon}{T_i} \\right) } \\mathrm{d} \\varepsilon\n\\end{equation}\n\n\\subsection{Electron Impact}\n\nIn a collision between an electron hot neutral and a hot neutral, both are moving at the fluid velocity with a thermal spread of $T_e$ and $T_i$, respectively. However, the electrons have a significantly higher thermal velocity, so the distribution function for the neutrals is again a delta function. The rate coefficient is then\n\n\\begin{equation}\n\tR_{12} (\\mathbf{v_e},\\ \\mathbf{v_n}) = \\Lambda v_r \\sigma(v_r) \\exp \\left[ - \\frac{m_e v_e^2}{2 T_e} \\right] \\delta( \\mathbf{v_n} ) \\mathrm{d}^3 \\mathbf{v_e} \\mathrm{d}^3 \\mathbf{v_n}\n\\end{equation}\n\nWhere $\\Lambda$ is a prefactor\n\n\\begin{equation}\n\t\\Lambda = n_e n_n \\left( \\frac{m_e}{2 \\pi T_e} \\right)^{\\frac{3}{2}} \n\\end{equation}\n\nBecause $m_e \\ll m_i$, and $v_e \\gg v_n$, we can assume that $v_r \\approx v_e$. We can also change to the center-of-mass energy, $\\varepsilon = \\frac{1}{2} \\mu v_r^2 \\approx \\frac{1}{2} m_e v_e^2$\n\n\\begin{equation}\n\tR_{12} = \\frac{n_e n_n}{\\sqrt{\\pi m_e}} \\left( \\frac{2}{T_e} \\right)^{\\frac{3}{2}}  \\int_0^\\infty \\varepsilon \\sigma(\\varepsilon) \\exp{ \\left( -\\frac{\\varepsilon}{T_e} \\right) } \\mathrm{d} \\varepsilon\n\\end{equation}\n\n\n\n\\end{document}", "meta": {"hexsha": "dd7ca47c43d1e918329eb796dc5ab05c356de162", "size": 7947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tools/neutrals/theory/simplified_theory.tex", "max_stars_repo_name": "MylesKelly/MCTrans", "max_stars_repo_head_hexsha": "9d38178d3150d4c1dcde16489a2df3cca2d49c74", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tools/neutrals/theory/simplified_theory.tex", "max_issues_repo_name": "MylesKelly/MCTrans", "max_issues_repo_head_hexsha": "9d38178d3150d4c1dcde16489a2df3cca2d49c74", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tools/neutrals/theory/simplified_theory.tex", "max_forks_repo_name": "MylesKelly/MCTrans", "max_forks_repo_head_hexsha": "9d38178d3150d4c1dcde16489a2df3cca2d49c74", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.3059701493, "max_line_length": 418, "alphanum_fraction": 0.6611299862, "num_tokens": 3128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7272915848630195}}
{"text": "\\section{Radix Sort}\n\\label{sec:200}\n\nRadix Sort is a non-comparative sorting algorithm that works on integer or string keys. The ordering is done by grouping keys into buckets, according to their individual digits.\\\\\n\nThe approach used here is the \\emph{Least Significant Digit} one, which is iterative in nature, running through all the elements once for every digit\n\n\nAs a small example, consider the following list of integers:\n\n\\begin{lstlisting}\n\tarr = [170, 45, 75, 90, 24, 2, 66]\n\\end{lstlisting}\n\nIn the first iteration, the least significant digit is considered. After sending each key into the correct bucket, the result is the following:\n\n\\begin{lstlisting}\n\t0: [170, 90],\n\t2: [2],\n\t4: [24],\n\t5: [45, 75],\n\t6: [66]\n\\end{lstlisting}\n\nAnd after merging all buckets:\n\n\\begin{lstlisting}\n\tarr = [170, 90, 2, 24, 45, 75, 66]\n\\end{lstlisting}\n\nThis completes the first iteration. The process is repeated until there are no more digits do process.", "meta": {"hexsha": "219ee552527d4ab6a97f90775a85f4c767da9771", "size": 952, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/last/report/200-radix.tex", "max_stars_repo_name": "naps62/parallel-sort", "max_stars_repo_head_hexsha": "23ffbc48e06c4ad79d41a103e09a750c5c4eef56", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2015-02-02T00:03:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-14T05:12:23.000Z", "max_issues_repo_path": "doc/last/report/200-radix.tex", "max_issues_repo_name": "naps62/parallel-sort", "max_issues_repo_head_hexsha": "23ffbc48e06c4ad79d41a103e09a750c5c4eef56", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-04-05T16:08:06.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-05T17:02:53.000Z", "max_forks_repo_path": "doc/last/report/200-radix.tex", "max_forks_repo_name": "naps62/parallel-sort", "max_forks_repo_head_hexsha": "23ffbc48e06c4ad79d41a103e09a750c5c4eef56", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2015-07-10T18:32:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-08T18:50:18.000Z", "avg_line_length": 30.7096774194, "max_line_length": 179, "alphanum_fraction": 0.7415966387, "num_tokens": 265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7272260527857131}}
{"text": "% !Mode:: \"TeX:UTF-8\"\n% !TEX program  = xelatex\n\\section{LPPL Model Implement}\nThe formula in 1.4 of LPPL describes a nonlinear function of logarithm asset price about time, involving logarithm, periodic and super-exponential tendency with 7 unknown parameters. We chose the Levenberg-Marquardt algorithm (LM) to find out the global optimal solution about seven unknown parameters in this non-linear least squares problem.\n\nFirstly, we aim to minimize the distance between real price data with the estimated price from the model. We measured the $L_2$-norm distance as aim function for better curve fitting after comparing the consequence with $L_1$-norm.\n\nSecondly, we put several limits and bounds on parameters and fitted the data with MATLAB. The limits on parameters refer to the conclusive analysis of successful experiments by Professor Didier with his group.\n\nThirdly, we tested different time intervals(Start Date to End Date) on three different stocks --- SSE Composite Index, NASDAQ, HK Seng Index. The number of iterations and the limit conditions on parameters, to some extent, did affect the consequences of critical time to get closer to the real historical crush points. The LPPL model is only valid in the super-exponential tendency.\n\nIn our report, we used the  MATLAB to fit seven parameters especially the critical time, which can verify the precision of our model and algorithm.\n\nFinally, the figures of three stocks embody the precise prediction on the critical time of bubbles ending.\n\nDetailed results are in the Appendix.", "meta": {"hexsha": "bab60328447647de6cf0c20b37358940abdb5125", "size": 1546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MA216/sections/project-1/2.tex", "max_stars_repo_name": "iydon/homework", "max_stars_repo_head_hexsha": "253d4746528ef62d33eba1de0b90dcb17ec587ed", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-10-20T08:18:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-11T12:14:56.000Z", "max_issues_repo_path": "MA216/sections/project-1/2.tex", "max_issues_repo_name": "AllenYZB/homework", "max_issues_repo_head_hexsha": "65bd3372df197bec5e152a37cdc1f6f5432b7f3e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2022-01-13T03:04:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T00:49:10.000Z", "max_forks_repo_path": "MA216/sections/project-1/2.tex", "max_forks_repo_name": "AllenYZB/homework", "max_forks_repo_head_hexsha": "65bd3372df197bec5e152a37cdc1f6f5432b7f3e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-11-02T05:46:01.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-12T23:11:28.000Z", "avg_line_length": 96.625, "max_line_length": 382, "alphanum_fraction": 0.8053040103, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624791, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7270333322564024}}
{"text": "\\chapter{Shor's algorithm}\nOK, now for Shor's Algorithm:\nhow to factor $M = pq$ in $O\\left( (\\log M)^2 \\right)$ time.\n\n\\section{The classical (inverse) Fourier transform}\nThe ``crux move'' in Shor's algorithm is the so-called\nquantum Fourier transform.\nThe Fourier transform is used to extract \\emph{periodicity} in data,\nand it turns out the quantum analogue is a lot faster than the classical one.\n\nLet me throw the definition at you first.\nLet $N$ be a positive integer, and let $\\omega_N = \\exp\\left( \\frac{2\\pi i}{N} \\right)$.\n\\begin{definition}\n\tGiven a tuple of complex numbers\n\t\\[ \\left( x_0, x_1, \\dots, x_{N-1} \\right) \\]\n\tits \\vocab{discrete inverse Fourier transform} is\n\tthe sequence $(y_0, y_1, \\dots, y_{N-1})$ defined by\n\t\\[ y_k = \\frac1N \\sum_{j=0}^{N-1} \\omega_N^{jk} x_j. \\]\n\tEquivalently, one is applying the matrix\n\t\\[\n\t\t\\frac 1N\n\t\t\\begin{bmatrix} \n\t\t\t1 & 1 & 1 & \\dots & 1 \\\\\n\t\t\t1 & \\omega_N & \\omega_N^2 & \\dots & \\omega_N^{N-1} \\\\\n\t\t\t1 & \\omega_N^2 & \\omega_N^4 & \\dots & \\omega_N^{2(N-1)} \\\\\n\t\t\t\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\t\t1 & \\omega_N^{N-1} & \\omega_N^{2(N-1)} & \\dots & \\omega_N^{(N-1)^2}\n\t\t\\end{bmatrix}\n\t\t\\begin{bmatrix} x_0 \\\\ x_1 \\\\ \\vdots \\\\ x_{N-1} \\end{bmatrix}\n\t\t=\n\t\t\\begin{bmatrix} y_0 \\\\ y_1 \\\\ \\vdots \\\\ y_{N-1} \\end{bmatrix}.\n\t\\]\n\\end{definition}\nThe reason this operation is important is because it lets\nus detect if the $x_i$ are periodic:\n\\begin{example}\n\t[Example of discrete inverse Fourier transform]\n\tLet $N = 6$, $\\omega = \\omega_6 = \\exp(\\frac{2\\pi i}{6})$\n\tand suppose $(x_0,x_1,x_2,x_3,x_4,x_5)=(0,1,0,1,0,1)$\n\t(hence $x_i$ is periodic modulo $2$).\n\tThus,\n\t\\begin{align*}\n\t\ty_0 &= \\tfrac16\\left(\\omega^0 + \\omega^0+ \\omega^0\\right) = 1/2 \\\\\n\t\ty_1 &= \\tfrac16\\left(\\omega^1 + \\omega^3 + \\omega^5\\right) = 0 \\\\\n\t\ty_2 &= \\tfrac16\\left( \\omega^2 + \\omega^{6} + \\omega^{10} \\right) = 0 \\\\\n\t\ty_3 &= \\tfrac16\\left( \\omega^3 + \\omega^9 + \\omega^{15} \\right) = -1/2 \\\\\n\t\ty_4 &= \\tfrac16\\left( \\omega^4 + \\omega^{12} + \\omega^{20} \\right) = 0 \\\\\n\t\ty_5 &= \\tfrac16\\left( \\omega^5 + \\omega^{15} + \\omega^{25} \\right) = 0.\n\t\\end{align*}\n\tThus, in the inverse transformation the ``amplitudes''\n\tare all concentrated at multiples of $3$;\n\tthus this reveals the periodicity of the original\n\tsequence by $\\frac N3 = 2$.\n\\end{example}\nMore generally, given a sequence of $1$'s appearing with period $r$,\nthe amplitudes will peak at inputs which are divisible by $\\frac{N}{\\gcd(N,r)}$.\n\\begin{remark}\n\tThe fact that this operation is called the ``inverse''\n\tFourier transform is mostly a historical accident\n\t(as my understanding goes).\n\tConfusingly, the corresponding quantum operation is the\n\t(not-inverted) Fourier transform.\n\\end{remark}\nIf we apply the definition as written, computing the transform takes $O(N^2)$ time.\nIt turns out that by an algorithm called the \\vocab{fast Fourier transform}\n(whose details we won't discuss), one can reduce this to $O(N \\log N)$ time.\nHowever, for Shor's algorithm this is also insufficient;\nwe need something like $O\\left( (\\log N)^2 \\right)$ instead.\nThis is where the quantum Fourier transform comes in.\n\n\\section{The quantum Fourier transform}\nNote that to compute a Fourier transform, we need to multiply an $N \\times N$ matrix\nwith an $N$-vector, so this takes $O(N^2)$ multiplications.\nHowever, we are about to show that with a quantum computer,\none can do this using $O( (\\log N)^2 )$ quantum gates when $N = 2^n$,\non a system with $n$ qubits.\n\nFirst, some more notation:\n\\begin{abuse}\n\tIn what follows, $\\ket{x}$ will refer to\n\t$\\ket{x_n} \\otimes \\ket{x_{n-1}} \\otimes \\dots \\otimes \\ket{x_1}$\n\twhere $x = x_n x_{n-1} \\dots x_1$ in binary.\n\tFor example, if $n = 3$\n\tthen $\\ket{6}$ really means $\\ket1 \\otimes \\ket1 \\otimes \\ket 0$.\n\\end{abuse}\nObserve that the $n$-qubit space now has an\northonormal basis $\\ket0$, $\\ket1$, \\dots, $\\ket{N-1}$\n\n\\begin{definition}\n\tConsider an $n$-qubit state\n\t\\[ \\ket\\psi = \\sum_{k=0}^{N-1} x_k \\ket{k}. \\]\n\tThe \\vocab{quantum Fourier transform} is defined by\n\t\\[\n\t\t\\UQFT(\\ket\\psi) = \\frac{1}{\\sqrt N}\\sum_{j=0}^{N-1}\n\t\t\\left( \\sum_{k=0}^{N-1} \\omega_N^{jk} \\right) \\ket{j}.\n\t\\]\n\tIn other words, using the basis $\\ket0$, \\dots, $\\ket{N-1}$,\n\t$\\UQFT$ is given by the matrix\n\t\\[\n\t\t\\UQFT = \\frac{1}{\\sqrt N}\n\t\t\\begin{bmatrix} \n\t\t\t1 & 1 & 1 & \\dots & 1 \\\\\n\t\t\t1 & \\omega_N & \\omega_N^2 & \\dots & \\omega_N^{N-1} \\\\\n\t\t\t1 & \\omega_N^2 & \\omega_N^4 & \\dots & \\omega_N^{2(N-1)} \\\\\n\t\t\t\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\t\t1 & \\omega_N^{N-1} & \\omega_N^{2(N-1)} & \\dots & \\omega_N^{(N-1)^2}\n\t\t\\end{bmatrix}\n\t\\]\n\\end{definition}\nThis is the exactly the same definition as before,\nexcept we have a $\\sqrt N$ factor added so that $\\UQFT$ is unitary.\nBut the trick is that in the quantum setup, the matrix can be rewritten:\n\\begin{proposition}\n\t[Tensor representation]\n\tLet $\\ket x = \\ket{x_n x_{n-1} \\dots x_1}$.\n\tThen\n\t\\begin{align*}\n\t\t\\UQFT( \\ket{x_n x_{n-1} \\dots x_1} )\n\t\t= \\frac{1}{\\sqrt N} &\n\t\t\\left( \\ket0 +\\exp(2\\pi i \\cdot 0.x_1) \\ket 1 \\right) \\\\\n\t\t&\\otimes \\left( \\ket0 +\\exp(2\\pi i \\cdot 0.x_2x_1) \\ket 1 \\right) \\\\\n\t\t&\\otimes \\dots  \\\\\n\t\t&\\otimes \\left( \\ket0 +\\exp(2\\pi i \\cdot 0.x_n\\dots x_1) \\ket 1 \\right)\n\t\\end{align*}\n\\end{proposition}\n\\begin{proof}\n\tDirect (and quite annoying) computation.\n\tIn short, expand everything.\n\\end{proof}\n\nSo by using mixed states, we can deal with the quantum Fourier transform\nusing this ``multiplication by tensor product'' trick that isn't possible classically.\n\nNow, without further ado, here's the circuit.\nDefine the rotation matrices\n\\[ R_k = \\begin{bmatrix} 1 & 0 \\\\ 0 & \\exp(2\\pi i/2^k) \\end{bmatrix}. \\]\nThen, for $n=3$ the circuit is given by by using controlled $R_k$'s as follows:\n\\[\n\t\\Qcircuit @C=1em @R=.7em {\n\t\t\\lstick{\\ket{x_3}} & \\gate{H} & \\gate{R_2} & \\qw & \\gate{R_3}  & \\qw & \\qw & \\rstick{\\ket{y_1}} \\\\\n\t\t\\lstick{\\ket{x_2}} & \\qw & \\ctrl{-1} & \\gate{H} & \\qw & \\gate{R_2} & \\qw & \\rstick{\\ket{y_2}} \\\\\n\t\t\\lstick{\\ket{x_1}} & \\qw & \\qw & \\qw & \\ctrl{-2} & \\ctrl{-1} & \\gate{H} & \\rstick{\\ket{y_3}} \\\\\n\t}\n\\]\n\\begin{exercise}\n\tShow that in this circuit, the image of of $\\ket{x_3x_2x_1}$\n\t(for binary $x_i$) is \n\t\\[\n\t\t\\Big(\\ket0+\\exp(2\\pi i \\cdot 0.x_1) \\ket1\\Big)\n\t\t\\otimes \\Big(\\ket0+\\exp(2\\pi i \\cdot 0.x_2x_1) \\ket1\\Big)\n\t\t\\otimes \\Big(\\ket0+\\exp(2\\pi i \\cdot 0.x_3x_2x_1) \\ket1\\Big)\n\t\\]\n\tas claimed.\n\\end{exercise}\n\nFor general $n$, we can write this as inductively as\n\\[\n \\Qcircuit @C=1em @R=.7em {\n  \\lstick{\\ket{x_n}}     & \\multigate{5}{\\text{QFT}_{n-1}} & \\gate{R_n} & \\qw                    & \\qw & \\cdots & & \\qw                    & \\qw & \\cdots & & \\qw              & \\qw      & \\rstick{\\ket{y_1}} \\qw \\\\\n  \\lstick{\\ket{x_{n-1}}}     & \\ghost{\\text{QFT}_{n-1}}        & \\qw                    & \\gate{R_{n-1}} & \\qw & \\cdots & & \\qw                    & \\qw & \\cdots & & \\qw              & \\qw      & \\rstick{\\ket{y_2}} \\qw \\\\\n  \\lstick{\\vdots\\ \\ }    & \\pureghost{\\text{QFT}_{n-1}}    &                        &                        &     &        & &                        &     &        & &                  &          & \\rstick{\\ \\ \\vdots} \\\\\n  \\lstick{\\ket{x_i}}     & \\ghost{\\text{QFT}_{n-1}}        & \\qw                    & \\qw                    & \\qw & \\cdots & & \\gate{R_i} & \\qw & \\cdots & & \\qw              & \\qw      & \\rstick{\\ket{y_{n-i+1}}} \\qw \\\\\n  \\lstick{\\vdots\\ \\ }    & \\pureghost{\\text{QFT}_{n-1}}    &                        &                        &     &        & &                        &     &        & &                  &          & \\rstick{\\ \\ \\vdots} \\\\\n  \\lstick{\\ket{x_2}} & \\ghost{\\text{QFT}_{n-1}}        & \\qw                    & \\qw                    & \\qw & \\cdots & & \\qw                    & \\qw & \\cdots & & \\gate{R_2} & \\qw      & \\rstick{\\ket{y_{n-1}}} \\qw \\\\\n  \\lstick{\\ket{x_1}}     & \\qw                             & \\ctrl{-6}               & \\ctrl{-5}               & \\qw & \\cdots & & \\ctrl{-3}               & \\qw & \\cdots & & \\ctrl{-1}         & \\gate{H} & \\rstick{\\ket{y_n}} \\qw\n }\n\\]\n\\begin{ques}\n\tConvince yourself that when $n=3$ the two circuits displayed are equivalent.\n\\end{ques}\n\nThus, the quantum Fourier transform is achievable with $O(n^2)$ gates,\nwhich is enormously better than the $O(N \\log N)$ operations achieved by\nthe classical fast Fourier transform (where $N=2^n$).\n\n\\section{Shor's algorithm}\nThe quantum Fourier transform is the key piece of Shor's algorithm.\nNow that we have it, we can solve the factoring problem.\n\nLet $p,q > 3$ be odd primes, and assume $p \\neq q$.\nThe main idea is to turn factoring an integer $M = pq$ into a problem\nabout finding the order of $x \\pmod M$; the latter is a ``periodicity''\nproblem that the quantum Fourier transform will let us solve.\nSpecifically, say that an $x \\pmod M$ is \\emph{good} if\n\\begin{enumerate}[(i)]\n\t\\ii $\\gcd(x,M) = 1$,\n\t\\ii The order $r$ of $x \\pmod M$ is even, and\n\t\\ii Factoring $0 \\equiv (x^{r/2}-1)(x^{r/2}+1) \\pmod M$,\n\tneither of the two factors is $0 \\pmod M$.\n\tThus one of them is divisible by $p$, and the other\n\tis divisible by $q$.\n\\end{enumerate}\n\\begin{exercise}\n\t[For contest number theory practice]\n\tShow that for $M = pq$ at least half of the residues\n\tin $\\Zm M$ are good.\n\\end{exercise}\n\nSo if we can find the order of an arbitrary $x \\in \\Zm M$,\nthen we just keep picking $x$ until we pick a good one\n(this happens more than half the time);\nonce we do, we compute $\\gcd(x^{r/2}-1,M)$ using the Euclidean\nalgorithm to extract one of the prime factors of $M$, and we're home free.\n\nNow how do we do this?  The idea is not so difficult:\nfirst we generate a sequence which is periodic modulo $r$.\n\\begin{example}[Factoring $77$: generating the periodic state]\n\tLet's say we're trying to factor $M = 77$,\n\tand we randomly select $x = 2$, and want to find its order $r$.\n\tLet $n = 13$ and $N = 2^{13}$, and start by initializing the state\n\t\\[ \\ket\\psi = \\frac{1}{\\sqrt N} \\sum_{k=0}^{N-1} \\ket k. \\]\n\tNow, build a circuit $U_x$ (depending on $x=2$!)\n\twhich takes $\\ket k \\ket 0$ to $\\ket k \\ket{2^k \\mod M}$.\n\tApplying this to $\\ket\\psi \\otimes \\ket0$ gives\n\t\\[ U(\\ket\\psi\\ket0) =\n\t\t\\frac{1}{\\sqrt N} \\sum_{k=0}^{N-1} \\ket k \\otimes \\ket{2^k \\mod M}. \\]\n\tNow suppose we measure the second qubit, and get a state of $\\ket{128}$.\n\tThat tells us that the collapsed state now, up to scaling, is\n\t\\[ (\\ket{7} + \\ket{7+r} + \\ket{7+2r} + \\dots) \\otimes \\ket{128}. \\]\n\\end{example}\nThe bottleneck is actually the circuit $U_x$;\none can compute $x^k \\pmod M$ by using repeated squaring,\nbut it's still the clumsy part of the whole operation.\n\nIn general, the operation is:\n\\begin{itemize}\n\t\\ii Pick a sufficiently large $N = 2^n$ (say, $N \\ge M^2$).\n\t\\ii Generate $\\ket\\psi = \\sum_{k=0}^{2^n-1} \\ket{k}$.\n\t\\ii Build a circuit $U_x$ which computes $\\ket{x^k \\mod M}$.\n\t\\ii Apply it to get a state\n\t$\\frac{1}{\\sqrt N} \\sum_{k=0}^{2^n-1} \\ket k \\otimes \\ket{x^k \\mod M}$.\n\t\\ii Measure the second qubit to cause the first qubit to\n\tcollapse to something which is periodic modulo $r$.\n\tLet $\\ket\\phi$ denote the left qubit.\n\\end{itemize}\n\nSuppose we apply the quantum Fourier transform to the left qubit $\\ket\\phi$ now:\nsince the left bit is periodic modulo $r$, we expect the transform\nwill tell us what $r$ is.\nUnfortunately, this doesn't quite work out, since $N$ is a power of two,\nbut we don't expect $r$ to be.\n\nNevertheless, consider a state\n\\[ \\ket\\phi = \\ket{k_0} + \\ket{k_0+r} + \\dots \\]\nso for example previously we had $k_0=7$ if we measured $128$ on $x=2$.\nApplying the quantum Fourier transform, we see that the\ncoefficient of $\\ket j$ in the transformed image is equal to\n\\[\n\t\\omega_N^{k_0j} \\cdot\n\t\\left( \\omega_N^{0} + \\omega_N^{jr} + \\omega_N^{2jr}\n\t+ \\omega_N^{3jr} + \\dots \\right)\n\\]\nAs this is a sum of roots of unity, we realize we have\ndestructive interference unless $\\omega_N^{jr} = 1$ (since $N$ is large).\nIn other words, we approximately have\n\\[\n\t\\UQFT(\\ket\\phi)\n\t\\approx\n\t\\sum_{\\substack{0 \\le j < N \\\\ jr/N \\in \\ZZ}} \\ket j\n\\]\nup to scaling as usual.\nThe bottom line is that\n\\begin{moral}\n\tIf we measure $\\UQFT\\ket\\phi$ we obtain a $\\ket j$ such that\n\t$\\frac{jr}{N}$ is close to an $s \\in \\ZZ$.\n\\end{moral}\nAnd thus given sufficient luck we can use continued fractions\nto extract the value of $r$.\n\n\\begin{example}\n\t[Finishing the factoring of $M = 77$]\n\tAs before, we made an observation to the second qubit,\n\tand thus the first qubit collapses to the state\n\t$\\ket\\phi = \\ket7 + \\ket{7+r} + \\dots$.\n\tNow we make a measurement and obtain $j = 4642$, which means that\n\tfor some integer $s$ we have\n\t\\[ \\frac{4642r}{2^{13}} \\approx s. \\]\n\tNow, we analyze the continued fraction of $\\frac{4642}{2^{13}}$;\n\twe find the first few convergents are\n\t\\[\n\t\t0, \\;\n\t\t1, \\;\n\t\t\\half, \\;\n\t\t\\frac{4}{7}, \\;\n\t\t\\frac{13}{23}, \\;\n\t\t\\frac{17}{30}, \\;\n\t\t\\frac{1152}{2033}, \\;\n\t\t\\dots\n\t\\]\n\tSo $\\frac{17}{30}$ is a very good approximation,\n\thence we deduce $s = 17$ and $r = 30$ as candidates.\n\tAnd indeed, one can check that $r = 30$ is the desired order.\n\\end{example}\n\nThis won't work all the time (for example, we could get unlucky and\nmeasure $j=0$, i.e.\\ $s=0$, which would tell us no information at all).\n\nBut one can show that we succeed any time that \\[ \\gcd(s,r) = 1. \\]\nThis happens at least $\\frac{1}{\\log r}$ of the time,\nand since $r < M$ this means that given sufficiently many trials,\nwe will eventually extract the correct order $r$.\nThis is Shor's algorithm.\n", "meta": {"hexsha": "f013c5689bc57ba64400d6b369b8496d12643b11", "size": 13340, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/quantum/shor.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/quantum/shor.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/quantum/shor.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.0264026403, "max_line_length": 226, "alphanum_fraction": 0.6169415292, "num_tokens": 4748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.7270052952135816}}
{"text": "%&LaTeX\n\n\\section{More Feedforward Filters}\n\nThis lab discusses the different ways in which to express a discrete\nfeedforward filter. When completed you should feel comfortable\nrepresenting a filter in any of its equivalent forms and know the\ndifferent advantages of expressing a filter in these forms.  When you\nget down to it, feedforward filters can be expressed in the following\nequivalent ways:\n\\begin{enumerate}\n\\item Defining equation, $y[n]$ as a (linear) function of $x[n],\n  x[n-1], \\ldots$, or equivalently as this equation's coefficients.\n  % \\item Impulse response, $h[n]$.\n\\item Transfer function, $H(z)$.\n\\item Frequency response (i.e., the expression for $\\mathcal{H}(\\hat{\\omega})$). \n\\item Zero locations, $z_i$, often plotted in the complex plane.\n\\item Amplitude $|\\mathcal{H}(\\hat{\\omega})| = |H(e^{j\\hat{\\omega}})|$ (and phase\n  $\\theta(\\hat{\\omega})$) of the frequency response, often plotted as\n  functions of $\\hat{\\omega}$.\n\\item Block diagram.\n\\end{enumerate}\n\nIn this lab, you will be given a number of filters, each expressed in\none of the above ways, for each, you are asked to generate the other\nrepresentations using pencil and paper. For our purposes here, it will\nonly be necessary to sketch the amplitude of the filter's frequency\nresponse (for item 5 above).  For items 4 and 5, please use J-DSP to\ncheck your answers. If there is disagreement between your answers and\nwhat you get in J-DSP, please spend some time out of class discussing\nthe discrepancy with your classmates or with me to determine its\nsource.\n\n\\paragraph{Step 1: Three-point averager} Yes, we've done some of this already,\n\tso it's a good, familiar place to start. The defining equation is\n\t$y[n] = \\frac{1}{3}x[n] + \\frac{1}{3}x[n-1] + \\frac{1}{3}x[n-2]$;\n\tdetermine the other representations.\n\t\n\n\\paragraph{Step 2: First-difference filter} A \\emph{first-difference} filter is an\n\tapproximation to a discrete derivative operation. Its transfer\n\tfunction is $H(z) = 1 - z^{-1}$. Determine the other representations.\n\n\t\n\\paragraph{Step 3: Second-difference filter} Just as we can compute a discrete\n\tfirst derivative with a first-difference filter, we can compute a\n\tdiscrete second derivative with a \\emph{second difference filter}. Its\n\tblock diagram (in a little trickier format) is:\n\t\n\t\\centerline{\\includegraphics[width=2.5in]{lab5/second-difference-bdiag}}\n\t\n\tAfter you've developed the alternative representations, show that\n\tthis filter can also be implemented as a cascade of two\n\tfirst-difference filters.\n\t\n\\paragraph{Step 4: Complex conjugate zeros} Feedforward filters with real\n\tcoefficients in their defining equations have either real or complex\n\tconjugate zeros. Re-represent the filter with zeros $z_{1,2} = 0.5 \\pm\n\tj 0.5$ and $z_3 = 0.75$.\n\n\\paragraph{Step 5: Symmetric filters} Feedforward filters with\n        symmetric coefficients have interesting properties, such as\n        linear phase terms. Even symmetric filters have a midpoint\n        around which they mirror their coefficients. Re-represent the\n        filter with a coefficients given by $\\{1,2,2,1\\}$ (i.e.,\n        $y[n]=x[n]+2x[n-1]+2x[n-2]+x[n-3]$). In this filter, the\n        coefficients \\{1,2\\} are mirrored.\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: t\n%%% End: \n", "meta": {"hexsha": "bf8623f6c2aa66381e2802216cf087e3f1d21533", "size": 3274, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "J-DSP Labs/lab5/lab5.tex", "max_stars_repo_name": "stiber/Signal-Computing", "max_stars_repo_head_hexsha": "cb5c7825e0cc80ca2ecd3e324fcf6231c320a721", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-09-10T16:54:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T15:48:26.000Z", "max_issues_repo_path": "J-DSP Labs/lab5/lab5.tex", "max_issues_repo_name": "stiber/Signal-Computing", "max_issues_repo_head_hexsha": "cb5c7825e0cc80ca2ecd3e324fcf6231c320a721", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2015-08-18T18:16:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-29T17:19:16.000Z", "max_forks_repo_path": "J-DSP Labs/lab5/lab5.tex", "max_forks_repo_name": "stiber/Signal-Computing", "max_forks_repo_head_hexsha": "cb5c7825e0cc80ca2ecd3e324fcf6231c320a721", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.2432432432, "max_line_length": 82, "alphanum_fraction": 0.7370189371, "num_tokens": 874, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.872347369700144, "lm_q1q2_score": 0.7269485332708066}}
{"text": "\\chapter{Appendix: Incrementally Calculating Partition Functions on Graphs}\n\\label{chap:appendix-partition}\n\n\\paragraph{Problem Definition.}\nConsider a directed graph $G=(V,E)$ endowed with an edge weight\nfunction $w : E \\rightarrow \\mathbb{R}$.\nBetween any two vertices $x,y \\in V$,\nthere exist a (potentially infinite) set of paths $P_{xy}$,\n\\marginnote{Note that we do not restrict consideration\nto only simple paths on $G$.}\nwith the length of any path given by\n$\\mbox{len} : P_{xy} \\rightarrow \\mathbb{R}$ as in\n(\\ref{eqn:lazysp:len-definition}).\nBetween each such pair of vertices $x,y$,\none can compute the \\emph{partition function} denoted $Z_{xy}$,\ndefined as a sum over all possible paths as follows:\n\\begin{equation}\n   Z_{xy} = \\sum_{p_{xy} \\in P_{xy}} \\exp(- \\beta \\, \\mbox{len}(p_{xy})),\n   \\label{eqn:def}\n\\end{equation}\nwith $\\beta$ a fixed real-valued parameter\n(commonly called an inverse temperature in statistical mechanics).\nWe wish to compute and maintain this partition function value\nbetween all pairs of vertices $x$ and $y$ on $G$.\n\n\\paragraph{An Incremental Approach.}\nWe propose an incremental method for calculating $Z$ between all pairs\non a graph.\nWe will proceed by initializing the values $Z_{xy}$ for each pair\non a graph with no edges,\nand then show how we can update these values as edges are added\nor removed.\n\nFirst,\nconsider the graph with no edges $G_0 = (V, \\emptyset)$.\nOn this graph, there exists no paths between each pair of vertices\n$x,y$ with $x \\neq y$.\nOn the other hand,\nfor $x=y$ there exists exactly one path\ncontaining no edges (and therefore with length $0$).\nThus, we can initialize our values $Z_{xy}$ with:\n\\begin{equation}\n   Z_{xy} = \\left\\{ \\begin{array}{cl}\n      1 & \\mbox{if } x = y, \\\\\n      0 & \\mbox{otherwise}.\n   \\end{array}\\right.\n\\end{equation}\n\n\\paragraph{Adding Edges.}\nWe can next establish the inductive step.\nSuppose we compare two directed graphs $G$ and $G'$,\nwhere $V' = V$ and $E' = E \\cup \\{ e_{ab} \\}$,\nand with new edge $e_{ab} : a \\rightarrow b$ having weight $w_{ab}$.\nFor arbitrary vertices $x$ and $y$, we can write $Z'_{xy}$ as follows:\n\\begin{equation}\n   Z'_{xy} = S^{(0)} + S^{(1)} + S^{(2)} + \\dots\n   \\label{eqn:sums}\n\\end{equation}\nwhere $S^{(k)}$ is the sum from (\\ref{eqn:def})\nover only the subset of paths that traverse $e_{ab}$ exactly $k$ times.\nWe note immediately that $S^{(0)} = Z_{xy}$.\n\nNext, we consider the sum $S^{(1)}$,\nthat is, the sum over all paths which use the new edge $e_{ab}$\nexactly once.\nWe note that each path which contributes to this sum consists of\nthree segments:\n(a) a path segment from $x$ to $a$,\nfollowed by (b) the new edge $e_{ab}$,\nfollowed by (c) a path segment from $b$ to $y$.\nSince the sum in question consists exactly of the sum over all unique\npaths which follow this template,\nwe see that we can write $S^{(1)}$ as follows:\n\\begin{equation}\n   S^{(1)} = \\sum_{p_{xa}} \\sum_{p_{by}}\n      \\exp\\left(\n         - \\beta \\left[ \\mbox{len}(p_{xa}) + w_{ab} + \\mbox{len}(p_{by}) \\right]\n         \\right)\n\\end{equation}\nNote that both $p_{xa} \\in P_{xa}$ and $p_{by} \\in P_{by}$\nare over all paths on the original graph $G$.\nWe can then rewrite this simply as:\n\\begin{equation}\n   S^{(1)} = Z_{xa} \\, \\exp(-\\beta \\, w_{ab}) \\, Z_{by}.\n\\end{equation}\nWe can likewise write $S^{(2)}$ as:\n\\begin{equation}\n   S^{(2)} = Z_{xa} \\, \\exp(-\\beta \\, w_{ab}) \\, Z_{ba} \\, \\exp(-\\beta \\,  w_{ab}) \\, Z_{by}.\n\\end{equation}\nThat is,\nthis sum consists of paths which arrive from $x$ to $a$ through $G$,\ntraverse the edge $e_{ab}$ once,\nthen traverse the original $G$ in some way from $b$ back to $a$,\ntraverse the edge $e_{ab}$ a second time,\nand then proceed from $b$ to $y$.\nThis decomposition allows us to rewrite\nthe entire sum from (\\ref{eqn:sums}) as:\n\\begin{equation}\n   Z'_{xy} = Z_{xy} + Z_{xa} \\, \\exp(-\\beta \\, w_{ab}) \\, Z_{by}\n      \\sum_{k=0}^{\\infty} \\left[ Z_{ba} \\, \\exp(-\\beta \\, w_{ab}) \\right]^k. \n\\end{equation}\nAs this is a geometric series, it will converge as long as\n$Z_{ba} < \\exp(\\beta \\, w_{ab})$.\nIn this case,\nwe have:\n\\begin{equation}\n   Z'_{xy} = Z_{xy} + \\frac{Z_{xa} \\, Z_{by}}{\\exp(\\beta \\, w_{ab}) - Z_{ba}}.\n   \\label{eqn:partition:addition}\n\\end{equation}\n\\marginnote{Note that the addition of an undirected edge between\n$a$ and $b$ must entail two successive applications of\n(\\ref{eqn:partition:addition}).}\nThis allows us to accommodate arbitrary edge additions while maintaining\nthe correct values $Z_{xy}$ over all pairs of vertices on $G$.\n\n\\paragraph{Removing Edges.}\nWe can establish a similar result in the case that an existing edge\nis removed from the graph.\nConsider the case that you have a graph $G'$,\nwith partition function values $Z'$ between all pairs of vertices.\nYou then remove some existing edge $e_{ab}$ with weight $w_{ab}$,\nyielding new graph $G$.\nWhat can we say about the new values $Z$?\n\nWe proceed by applying (\\ref{eqn:partition:addition})\nto the edge to be removed $e_{ab}$:\n\\begin{equation}\n   Z'_{ba} - Z_{ba} - \\frac{Z_{ba}^2}{\\exp(\\beta w_{ab}) - Z_{ba}} = 0\n\\end{equation}\n\\begin{equation}\n   \\left[\\exp(\\beta w_{ab}) - Z_{ba} \\right] Z'_{ba} - \\exp(\\beta w_{ab}) Z_{ba} = 0\n\\end{equation}\n\\begin{equation}\n   \\left[ \\exp(\\beta w_{ab}) - Z_{ba} \\right]\n   \\left[ \\exp(\\beta w_{ab}) + Z'_{ba} \\right]\n   = \\exp(2 \\beta w_{ab})\n\\end{equation}\n\\begin{equation}\n   \\exp(\\beta w_{ab}) - Z_{ba}\n   = \\frac{\\exp(2 \\beta w_{ab})}{\\exp(\\beta w_{ab}) + Z'_{ba}}\n   \\label{eqn:zba-convert}\n\\end{equation}\nWe can then use (\\ref{eqn:zba-convert}) to express\n$Z_{xa}$ and $Z_{by}$ in terms of $Z'_{xa}$ and $Z'_{by}$,\nrespectively:\n\\begin{equation}\n   Z_{xa} + \\frac{Z_{xa} \\, Z_{ba}}{\\exp(\\beta w_{ab}) - Z_{ba}} = Z'_{xa}\n   \\longrightarrow\n   Z_{xa} = \\frac{\\exp(\\beta w_{ab})}{\\exp(\\beta w_{ab}) + Z'_{ba}} Z'_{xa}\n\\end{equation}\n\\begin{equation}\n   Z_{by} + \\frac{Z_{ba} \\, Z_{by}}{\\exp(\\beta w_{ab}) - Z_{ba}} = Z'_{by}\n   \\longrightarrow\n   Z_{by} = \\frac{\\exp(\\beta w_{ab})}{\\exp(\\beta w_{ab}) + Z'_{ba}} Z'_{by}\n\\end{equation}\nLastly, we can combine (\\ref{eqn:partition:addition})\nand (\\ref{eqn:zba-convert}) to express the desired value $Z_{xy}$\nonly in terms of values on $G'$:\n\\begin{equation}\n   Z_{xy} = Z'_{xy} -\n   \\frac{\n   \\left[ \\frac{\\exp(\\beta w_{ab})}{\\exp(\\beta w_{ab}) + Z'_{ba}} Z'_{xa} \\right]\n   \\,\n   \\left[ \\frac{\\exp(\\beta w_{ab})}{\\exp(\\beta w_{ab}) + Z'_{ba}} Z'_{by} \\right]\n   }{\n   \\left[ \\frac{\\exp(2 \\beta w_{ab})}{\\exp(\\beta w_{ab}) + Z'_{ba}} \\right]\n   }\n\\end{equation}\n\\begin{equation}\n   Z_{xy} = Z'_{xy} -\n   \\frac{Z'_{xa} Z'_{by}}{\\exp(\\beta w_{ab}) + Z'_{ba}}\n\\end{equation}\nThis allows us to accommodate edge deletions.\n", "meta": {"hexsha": "3470ea2db923475326b990d0e9e58902d6c455bb", "size": 6641, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-ch03-lazysp-partition.tex", "max_stars_repo_name": "siddhss5/phdthesis-dellin", "max_stars_repo_head_hexsha": "62ca559db0ad0a6285012708ef718f4fde4e1dcd", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-09-06T21:45:42.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-06T21:45:42.000Z", "max_issues_repo_path": "thesis-ch03-lazysp-partition.tex", "max_issues_repo_name": "siddhss5/phdthesis-dellin", "max_issues_repo_head_hexsha": "62ca559db0ad0a6285012708ef718f4fde4e1dcd", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thesis-ch03-lazysp-partition.tex", "max_forks_repo_name": "siddhss5/phdthesis-dellin", "max_forks_repo_head_hexsha": "62ca559db0ad0a6285012708ef718f4fde4e1dcd", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.1666666667, "max_line_length": 93, "alphanum_fraction": 0.6559253125, "num_tokens": 2301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220787, "lm_q2_score": 0.8333246015211009, "lm_q1q2_score": 0.7269485200950088}}
{"text": "\\chapter{Optimizing the Neural Network Model}\n{\\color{red}LZ: this chapter can be removed}\n\\section{General Training Procedure}\nWe have discussed the Gradient-based back propagation procedure for vanilla neural networks. In this chapter we will discuss in detail various optimization techniques. Let's start with summarizing the basic procedure of training a neural network model.\n\nThe key elements of training a neural network model can be summarized as follows: \n\\begin{enumerate}\n\\item Model construction: choose hyper-parameters, activation function, loss function.\n\\item Obtain a training data set and a test data set.\n\\item Adjust the parameters with an optimization methods such as gradient descent to reduce the value of the loss function over the training set. The gradient of the loss function is back propagated through each layer.\n\\item Apply the model to the test set to check for overfitting or underfitting.\n\\item Repeat the training and testing step until the model is well-trained.\n\\end{enumerate}\n\n\n\n\n\n\\section{Other Optimization Methods}\n\n\nStochastic Gradient Descent (SGD) is currently the favourite optimization method in deep learning. Its popularity is gained thanks to its ease of implementation and the nonconvexity of the optimization problem.\n\nDespite its popularity and its low cost per step, SGD has well-known \ndeficiencies that can make it inefficient, or at least tedious to use in \npractice. Two main issues are that 1) SGD requires a step size (learning \nrate) that has drastic effect on the algorithm's efficiency, is often \ndifficult to choose well, and virtually never optimal for each individual \ndescent step; 2) SGD is inherently sequential: it is very difficult to \nparallelize them using GPUs or distribute them using computer clusters.\n\nBatch methods, such as Limited memory BFGS (L-BFGS) or Conjugate Gradient \n(CG), with the presence of a line search procedure, are usually much more \nstable to train and easier to check for convergence. These methods also \nenjoy parallelism by computing the gradient on GPUs and/or distributing that \ncomputation across machines. These methods, conventionally considered to be \nslow, can be fast thanks to the availability of large amounts of RAMs, \nmulticore CPUs, GPUs and computer clusters with fast network hardware.\n\nA weakness of batch L-BFGS and CG, which require the computation of the \ngradient on the entire dataset to make an update, is that they do not scale \ngracefully with the number of examples.\n\n\\subsection{Learning with Momentum}\nThe momentum technique is a compromise that can smooth out the erratic behaviour caused by a fixed learning rate in SGD without slowing down the learning process too much. The idea is to update the weights with the moving average of the individual weight changes corresponding to single training patterns.\nIf we label everything by the time $t$, then implementing a moving average can be computed as:\n\n\\begin{equation}\n\\label{emom}\n\\aligned\n\\Delta \\bm W_k(t+1) :=& \\bm{W_k}(t+1) - \\bm{W_k}(t) = r\\frac{\\partial L_{total}}{\\partial \\bm{W_k}}(\\bm{W_1}(t),...,\\bm{W_d}(t),\\bm{\\theta_1}(t),..,\\bm{\\theta_d}(t)) -  \\eta\\Delta\\bm W_k(t)\\\\\n\\Delta \\bm \\theta_k(t+1) :=& \\bm{\\theta_k}(t+1)-\\bm{\\theta_k}(t) = r\\frac{\\partial L_{total}}{\\partial \\bm{\\theta_k}}(\\bm{W_1}(t),...,\\bm{W_d}(t),\\bm{\\theta_1}(t),..,\\bm{\\theta_d}(t)) - \\eta\\Delta \\bm\\theta_k(t)\n\\endaligned\n\\end{equation}\nHere we introduce a new hyper-parameter $\\eta$ and a momentum term $\\eta\\Delta\n\\bm W_k(t)$ or $\\eta\\Delta\\bm \\theta_k(t)$. The momentum simply adds a fraction of the previous update to the current one.  When the gradient keeps pointing in the same direction, this will increase the size of the steps taken towards the minimum. If $\\eta=0$, then it is the same as the gradient descent algorithm used before. When using the momentum method, it is usually necessary to reduce the learning rate $r$ accordingly so that the learning step is not too large.\n\n\n\n\\subsection{Gradient Descent with Line Search}\n\nIn neural network model we are seeking parameter values such that the loss function \n$$L_{total}(\\bm{W_1},...,\\bm{W_d},\\bm{\\theta_1},..,\\bm{\\theta_d})$$\nis minimal. One idea is to consider this as a one-dimensional optimization problem that optimizes one parameter while holding the other parameters fixed. We can do this for each parameter, and repeat the process until all weights are simultaneously at optimal values.\n\nAnother idea about training neural network is to find the optimal learning rate with line search. Instead of a fixed learning rate, let's consider it as another variable $r$. Let $\\bm{W_1}(t)$,...,$\\bm{W_d}(t)$, $\\bm{\\theta_1}(t)$,..., $\\bm{\\theta_1}(t)$ be the value of weight matrices and bias vectors at time $t$. By the update rule \\eqref{ebpup}, the updated value for these parameters are\n\\begin{equation}\n\\aligned\n\\bm{W_k}(t+1) =& \\bm{W_k}(t) - r_k\\frac{\\partial L_{total}}{\\partial \\bm{W_k}}(\\bm{W_1}(t),...,\\bm{W_d}(t),\\bm{\\theta_1}(t),..,\\bm{\\theta_d}(t))\\\\\n\\bm{\\theta_k}(t+1) =& \\bm{\\theta_k}(t) - r_k'\\frac{\\partial L_{total}}{\\partial \\bm{\\theta_k}}(\\bm{W_1}(t),...,\\bm{W_d}(t),\\bm{\\theta_1}(t),..,\\bm{\\theta_d}(t))\n\\endaligned\n\\end{equation}\n\nThe loss function can be treated as a function of one variable \n$$\nL_{total} = L_{total}(r_k) = L_{total}(\\bm{W_k}(t) - r_k\\frac{\\partial L_{total}}{\\partial \\bm{W_k}}).\n$$ \nIts derivative can be computed as\n\\begin{equation}\nL_{total}'(r_k) =\\frac{\\partial L_{total}}{\\partial \\bm{W_k}}(\\bm W_k(t+1))\\circ \\frac{\\partial L_{total}}{\\partial \\bm{W_k}}(\\bm W_k(t)).\n\\end{equation}\n\nTreat the gradient $\\frac{\\partial L_{total}}{\\partial \\bm{W_k}}$ as a vector. If $L_{total}'(r_k) =0$, the direction of the new update $\\frac{\\partial L_{total}}{\\partial \\bm{W_k}}(\\bm W_k(t+1))$ should be orthogonal to the previous update $\\frac{\\partial L_{total}}{\\partial \\bm{W_k}}(\\bm W_k(t))$. Together with one-dimensional optimal search such as the Golden section method and the Brent's method, one can find a small interval for $r$ such that the value corresponding to the minimum of the loss function lies in the interval. Note that during this process multiply forward passes are needed, as the target function needs to be evaluated at several different points. Also for each weight matrix and each bias vector, an optimal learning rate needs to be computed separately. If we want to find a global optimal learning rate that applies to all parameters, we will need to consider to following equation:\n\n\\begin{equation}\n\\aligned\n&L'(r)\\\\ =& \\sum_{k=1}^d \\big(\\frac{\\partial L}{\\partial \\bm{W_k}}\\frac{\\partial \\bm{W_k}}{\\partial r} + \\frac{\\partial L}{\\partial \\bm{\\theta_k}}\\frac{\\partial \\bm{\\theta_k}}{\\partial r}\\big)\\\\\n=& -\\sum_{k=1}^d\\big(\\frac{\\partial L}{\\partial \\bm{W_k}}(\\bm{W_1}(t+1),...,\\bm{W_d}(t+1),\\bm{\\theta_1}(t+1),..,\\bm{\\theta_d}(t+1))\\frac{\\partial L_{total}}{\\partial \\bm{W_k}}(\\bm{W_1}(t),...,\\bm{W_d}(t),\\bm{\\theta_1}(t),..,\\bm{\\theta_d}(t))\\\\\n &+ \\frac{\\partial L}{\\partial \\bm{\\theta_k}}(\\bm{W_1}(t+1),...,\\bm{W_d}(t+1),\\bm{\\theta_1}(t+1),..,\\bm{\\theta_d}(t+1))\\frac{\\partial L_{total}}{\\partial \\bm{\\theta_k}}(\\bm{W_1}(t),...,\\bm{W_d}(t),\\bm{\\theta_1}(t),..,\\bm{\\theta_d}(t))\\big)\n\\endaligned\n\\end{equation}\n\nIn this case the derivative is a polynomial in $r$ of degree $d$. Solving such equation is going to be more costly. Therefore in general gradient descent with line search is not faster than the basic gradient descent method.\n\n \n%----------------------------------------------------------------------------\n\\subsection{Limited Memory BFGS Method}\n\nBesides first-order optimization methods, one can use second-order methods which seek the place where the gradient vanishes. We will start with the classical Newton's method:\n\\begin{equation}\n\\bm{z} \\leftarrow \\bm{z} - \\big[HL(\\bm{z})\\big]^{-1}\\nabla L(\\bm{z}).\n\\end{equation}\nHere, $\\bm{z}$ is a vector representing all parameters of a neural network model, $HL(\\bm{z})$ is the Hessian matrix, which is a square matrix of second-order partial derivatives of the function, and $\\nabla L(\\bm{z})$ is the gradient vector. More precisely, $\\bm{z}$, $HL(\\bm{z})$, and $\\nabla L(\\bm{z})$ are defined as follows:\n\\begin{equation}\n\\aligned\n\\bm{w_j} :=& ((\\textit{1st column of }\\bm{W_j})^T, (\\textit{2nd column of }\\bm{W_j})^T,..., (\\textit{last column of }\\bm{W_j})^T), j=1,...,d\\\\\n\\bm{z} :=& (\\bm{w_1}^T,..., \\bm{w_d}^T, \\bm{\\theta_1}^T,...,\\bm{\\theta_d}^T)^T = (z_1,...,z_N)\\\\\nh_{ij} =& \\frac{\\partial^2 L}{\\partial z_i \\partial z_j}, i,j=1,...,N\\\\\nHL(\\bm{z}) =& \\big(h_{ij}\\big)_{i,j=1}^N\\\\\n\\nabla L(\\bm{z}) =& (\\frac{\\partial L}{\\partial z_1},...,\\frac{\\partial L}{\\partial z_N})\n\\endaligned\n\\end{equation}\n\nIntuitively, the Hessian matrix describes the local curvature of the loss function, which allows us to perform a more efficient update. In particular, multiplying by the inverse Hessian matrix leads the optimization to take more aggressive steps in directions of shallow curvature and shorter steps in directions of steep curvature. However, the update above is impractical if the depth of the neural network model is large, since it requires the inversion of the entire Hessian matrix corresponding to parameters from each layer. In this section we will introduce a \\textit{quasi-Newton} method called the Broyden-Fletcher-Goldfarb-Shanno (BFGS) algorithm that seek to approximate the inverse of the Hessian matrix. \n\nThe derivation starts with the quadratic model\n\\begin{equation}\nm_k(\\bm{p}) = f(\\bm{x_k}) + \\nabla f(\\bm{x_k})\\bm{p} + \\frac{1}{2}\\bm{p}^TB_k\\bm{p},\n\\end{equation}\nwhere $B_k$ is a symmetric positive definite matrix that will be updated in every iteration.\n\nGiven this convex quadratic model, we can write down the minimizer $\\bm{p_k}$ explicitly as\n\\begin{equation}\n\\bm{p_k}=-B_k^{-1}\\nabla f(\\bm{x_k}).\n\\end{equation}\n\nThe key difference compared with the classical Newton's method is that we are using an approximate Hessian $B_k$ that can be obtained by updating the previous $B_{k-1}$ with only a few arithmetic operations. We impose the following condition on each update: $m_{k+1}(\\bm{p})$ must match the gradient of the objective function in $\\bm{x_k}$ and $\\bm{x_{k+1}}$. Thus we have\n\\begin{equation}\n\\aligned\nB_k(\\bm{p_k}) =& -\\nabla f(\\bm{x_k})\\\\\nB_{k+1}(\\bm{p_{k+1}}) =& -\\nabla f(\\bm{x_{k+1}})\\\\\nB_{k+1}(\\bm{x_{k+1}} - \\bm{x_k}) =& \\nabla f(\\bm{x_{k+1}}) - \\nabla f(\\bm{x_k})\\\\\n%\\nabla m_{k+1}(-\\alpha_k\\bm{p_k})=&\\nabla f(\\bm{x_{k+1}}) - \\alpha_k B_{k+1}\\bm{p_k} = \\nabla f(\\bm{x_k})\n\\endaligned\n\\end{equation}\n\n\n%We derive that\n% \\begin{equation}\n% \\label{ebk}\n% \\alpha_k B_{k+1} \\bm{p_k} = \\nabla f(\\bm{x_{k+1}}) - \\nabla f(\\bm{x_k})\n% \\end{equation}\n\n%We clean up the notations by introducing\n\\begin{equation}\n\\aligned\n\\bm{s_k} :=& \\bm{x_{k+1}} - \\bm{x_{k}}\\\\\n\\bm{y_k} :=& \\nabla f(\\bm{x_{k+1}}) - \\nabla f(\\bm{x_{}})\\\\\n\\endaligned\n\\end{equation}\n\nNow the condition on $B_{k+1}$ can be expressed as\n\\begin{equation}\\label{esecant}\n\\bm{B_{k+1}s_k} = \\bm{y_k}.\n\\end{equation}\nThere are infinitely many symmetrical matrices that satisfy equation \\eqref{esecant}. The BFGS method seeks the one that requires fewest changes upon $\\bm B_k$, i.e., the solution to the following problem:\n\\begin{equation}\n\\aligned\n\\min_{\\bm{B_{k+1}}}&\\|B_{k+1} - B_k\\|\\\\\ns.t.&\\bm{B_{k+1}s_k} = \\bm{y_k}\\\\\n&\\bm{B_{k+1}^T} = \\bm {B_{k+1}}\n\\endaligned\n\\end{equation}\nHere we use the \\textit{weighted Frobenous norm} {(\\color{red}definition needed)}. The optimal solution is given by\n\\begin{equation}\n\\label{ebfgs}\n\\bm{B_{k+1}} = \\big(I - \\rho_k\\bm{y_ks_k^T}\\big)\\bm{B_k}\\big(I - \\rho_k\\bm{y_ks_k^T}\\big)+\\rho_k\\bm{s_ks_k^T},\n\\end{equation}\nwhere $\\rho_k = (\\bm{y_ks_k^T})^{-1}.${\\color{red}(proof?)}\n\n{\\bf Limited-memory BFGS method.} By equation \\eqref{ebfgs}, each $\\bm{B_k}$ can be obtained recursively from $(\\bm{s_k, y_k})$, $(\\bm{s_{k-1}, y_{k-1}})$,...,$(\\bm{s_1, y_1})$. This would require the algorithm to maintain a history of all these vectors, which could be a huge burden. The Limited-memory BFGS (L-BFGS) method simply truncates this procedure, using only last $m$ pairs of vectors to construct the matrix $\\bm B_k$. This results in a loss of accuracy in approximation, but it will greatly reduce the momery requirement of this algorithm.\n% In order to ensure that the solution is a local minimum, we will impose the \\textit{strong Wolfe condition} on curvature:\n% \\begin{equation}\n% Wolfe condition.\n% \\end{equation}\n\n% By pre-multiplying equation \\eqref{ebk} by $\\bm{s_k^T}$ we have\n% \\begin{equation}\n% 0 < \\bm{s_k^TB_{k+1}s_k} = \\bm{s_k^T y_k}.\n% \\end{equation}\n\n\n{\\bf Cost and convergence rate.} The cost of the BFGS method per iteration is dominated by matrix-vector multiplication in equation \\eqref{ebfgs} ($O(n^2)$). Other computations include function evaluations and gradient evaluations. The convergence rate is super-linear. Newton's method converges quadratically, but the cost per iteration is higher since it requires the solution of a linear system. In addition, Newton's method requires the calculation of second derivatives whereas the BFGS method does not.\n\n\n\n\n\n\n\n\n\\section{Back-Propagation of Convolutional Neural Networks}\n\nIn general, the convolution operation is a mathematical operation on two functions (f and g); it produces a third function, that is typically viewed as a modified version of one of the original function.\n\n\\begin{itemize}\n\\item\nConvolution\n$(f*g)(x) := \\int_{-\\infty}^{\\infty}f(t)g(x-t)dt$\n\\item\nDiscrete convolution\n$(f*g)[n] := \\sum_{-\\infty}^\\infty f[m]g[n-m]$\n\\item\n2-Dimensional convolution\n$(F*G)[i,j] := \\sum_{s = -\\infty}^\\infty\\sum_{t = -\\infty}^\\infty F[s, t]G[i-s, j-t]$\n\\end{itemize} \n\nIn neural network applications, the input is a multidimensional array (referred to as tensors), and so are the parameters adapted by the algorithm. In CNN terminology, the first function $f(x)$ is referred to as the input, the second function $g(x)$ is referred to as the kernel (or filter), and the output function $(f*g)(x)$ is referred to as the feature map. If we use 2D images $M\\in\\mathbb{R}^{n\\times n}$ as input and use a 2D filter $F\\in\\mathbb{R}^{d\\times d}$ we have\n$$(M*F)[i,j] := \\sum_{s = 0}^{d-1}\\sum_{t=0}^{d-1} F[s, t]G[i+s, j+t], i,j,=0,...,n-d-1$$. Here the output matrix $(M*F)$ is an $(n-d)\\times(n-d)$ matrix, and the kernel is flipped comparing to the previous definition. Convolution in CNN is illustrated as in Figure \\ref{fconv}\n\\begin{figure}[ht]\n\\label{fconv}\n\\centering\n\\includegraphics[scale=0.4]{Convolution1.png}\n\\caption{Convolution in CNN}\n\\end{figure}\n{\\bf Convolutional Neural Network (CNN)} is the most widely-used neural network structure for tasks on image pattern recognition. A CNN mainly comprises three types of layers: fully-connected (FC) layers, convolutional layers, and pooling layers\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.7]{CNN.png}\n\\caption{Convolutional Neural Network}\n\\end{figure}\n\n{\\bf Structure of CNN}\nA convolution layer in CNN is a composition of three functions: $f^{conv}$, $f^{sig}$, and $f^{pool}$\n\n{\\bf Convolutional Layer} consists of a set of filters/feature maps $F_{ij} = \\big(f_{ijkl}\\big)_{k,l}$ (matrices of size $d\\times d$ such as $d=3,5$). During the forward pass, each filter will conduct a 2D convolution with the input matrices $X_i=\\big(x_{ikl}\\big)_{kl}$ across its width and height. In this way local-features can be extracted and fed into subsequent layers to get higher-order features. We use 3-dimensional tensor $\\mathcal{X}=\\big(x_{ikl}\\big)_{i,k,l}$ to represent the set of input matrices, and 4-dimensional tensor $\\mathcal{F}=\\big(f_{ijkl}\\big)_{i,j,k,l}$ to denote the set of filters in a convolutional layer. We have that\n%At a convolution layer, the previous layer’s feature maps are convolved with learnable kernels and put through the activation function to form the output feature map. Each output map may combine convolutions with multiple input maps. In general, we have that\n\\begin{equation}\n\\aligned\nf^{conv}(\\mathcal{X}, \\mathcal{F}) =& \\big(y_{jst}\\big)_{j,s,t}=:\\mathcal{Y}\\\\\ny_{jst} =& \\sum_i\\sum_{k,l} x_{i,s+k, t+l}f_{ijkl}\\\\\nf^{sig}(\\mathcal{Y}) =& \\big(\\sigma(y_{jst})\\big)_{j,s,t}=:\\mathcal{Z}\n\\endaligned\n\\end{equation}\n\n{\\bf Pooling layer}. Pooling layer subsamples statistics to obtain summary statistics that are invariant to shifts and distortions in some degree. Commonly used pooling functions are\n\\begin{enumerate}\n\\item\nMean pooling: $f^{pool}(\\mathcal{Z})=\\big(\\frac{\\sum_{k=1}^m z_k}{m}\\big)$\n\\item\nMax pooling: $f^{pool}(\\mathcal{Z})=\\big(\\max_{1\\le k\\le m}\\{z_k\\}\\big)$\n\\item\n$l^p$ pooling: $f^{pool}(\\mathcal{Z})=\\big(\\|(z_1,...,z_m)\\|_p\\big)$\n\\end{enumerate}\n\n\n\\begin{figure}[ht]\\label{fcnnbp}\n\\includegraphics[scale=0.5]{CNNBP}\n\\caption{Convolutional Layer}\n\\end{figure}\n\nFigure \\ref{ffea} illustrates features extracted the first three convolutional Layers  on a facial recognition task.\n\n\\begin{figure}[ht]\n\\label{ffea}\n\\centering\n\\includegraphics[scale=1]{Features.png}\n\\caption{Features}\n\\end{figure}\n\n{\\bf Backpropagation in CNN}.\nTo back-propagate through one convolutional layer, one need to compute the derivative of three functions:\n\\begin{equation}\n\\aligned\n\\bm\\delta^{conv}_{ikl} =& \\frac{\\partial L}{\\partial x_{ikl}} =\n\\sum_{j,k,l}\\frac{\\partial L}{\\partial y_{jkl}}\\frac{\\partial y_{jkl}}{\\partial x_{ikl}} = \\sum_{k,l=0}^{r-1}\\bm\\delta^{sig}_{ikl}\\\\\n\\bm\\delta^{sig}_{jkl} =& \\frac{\\partial L}{\\partial y_{jkl}} = \\sigma'(y_{jkl})\\\\\n\\bm\\delta^{pool}_{jkl} =& \\frac{\\partial L}{\\partial z_{jkl}} = \\frac{\\partial L}{\\partial x^{next}_{jkl}}\\frac{\\partial x^{next}_{jkl}}{\\partial z_{jkl}} = \\bm\\delta^{next, conv}_{jkl}\\\\\n\\frac{\\partial L}{\\partial f_{ijkl}} =& \\sum_{j,k,l}\\frac{\\partial L}{\\partial y_{jkl}}\\frac{\\partial y_{jkl}}{\\partial f_{ijkl}}=\\sum_{s,t=0}^{d-1}\\bm\\delta^{sig}_{jst}x_{i, s+k, t+l}\n\\endaligned\n\\end{equation}\nThe partial derivative of the pooling function is usually called the \\textit{upsample} function. For example. for the max pooling function, the corresponding upscale function is $\\mathbbm{1}_{z_{jkl} = \\max\\{z_k\\}}$ (distributing the gradient to the entry with maximum value). Also note that the partial derivative of the filer parameters are computed through a discrete convolution.\n\n\n\n\n\n\n\n\n\n\\section{Tensor Computation and Decomposition}\n\n{\\bf Tensor}\n\\begin{itemize}\n\\item\nDefinition of tensor: an element $\\mathcal{F}\\in\\mathbb{R}^{I_1\\times\\cdots\\times I_N}$.\n\\item\nElement-wise: \n$$\n\\mathcal{F}[i_1,...,i_N]\\in\\mathbb{R}, i_j=1,...,I_j, j=1,...,N.\n$$\n\\item\nFiber: mode-1 tensor (vector) obtained by fixing every index but one.\n\\item\nSlice: mode-2 tensor (matrix) obtained by fixing every index but two.\n\\item\nNorm: \n$$\n\\|\\mathcal{F}\\| := \\sqrt{\\sum_{i_1=1}^{I_1}\\cdots\\sum_{i_N=1}^{I_N} \\mathcal{F}[i_1,...,i_N]^2}\n$$\n\\end{itemize}\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.5]{fiber.png}\n\\end{figure}\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.5]{slice.png}\n\\end{figure}\n\n{\\bf Metricization}\nThe mode-$n$ metricization of a tensor $\\mathcal{X}\\in\\mathbb{R}^{I_1\\times\\cdots\\times I_N}$ is denoted by $X_{(n)}$ and arranges the mode-$n$ fibers to be the columns of the resulting matrix.\n\\begin{figure}[ht]\\label{fmat}\n\\centering\n\\includegraphics[scale=0.6]{metricization.png}\n\\caption{Tensor Matricization}\n\\end{figure}\n{\\color{red} Definition of Matricization}. An example is given in Figure \\ref{fmat}.\n\n{\\bf CP Decomposition}\nThe CANDECOMP/PARAFAC (CP) decomposition attempts to decompose a tensor as a sum of rank-1 tensors:\n\n\\begin{equation}\n\\mathcal{X}[i_1,...,i_N] = \\sum_{k=1}^r a^{(1)}_{i_1k}a^{(2)}_{i_2k}\\cdots a^{(N)}_{i_Nk}\n\\end{equation}\nThe number of summation is call the CP-rank of tensor $\\mathcal{X}$.\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.6]{CP_decomposition.png}\n\\end{figure}\n\n{\\bf Challenges about CP Decomposition}\n\\begin{itemize}\n\\item\nThe problem of finding the CP-rank of a tensor is NP-hard.\n\\item\nFor a general 3-mode tensor $\\mathcal{X}\\in\\mathbb{R}^{I\\times J\\times K}$, its maximal attainable rank is bounded by\n$$\nrank(\\mathcal{X})\\le \\min\\{IJ, JK, KI\\}\n$$\n\\item\nUnlike matrices, the low-rank approximation problem for tensors is not well-defined: \\textit{any rank-3 tensor can be infinitely approximated by a rank-2 tensor}.\n\\end{itemize}\n\n{\\bf Tucker Decomposition}\n\nThe \\textit{Tucker-decomposition} is a form of higher-order PCA. It decomposes a tensor into a core tensor multiplied by a matrix along each mode.\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.6]{Tucker.png}\n\\end{figure}\n\\begin{equation}\n\\mathcal{X}[i,j,k] = \\sum_{p=1}^P\\sum_{q=1}^Q\\sum_{r=1}^R\ng_{pqr}a_{ip}b_{jq}c_{kr}, i=1,...,I, j=1,...,J, k=1,...,K.\n\\end{equation}\n\n{\\bf Tensor-Matrix Multiplication}\nTucker decomposition is best illustrated through \\textit{tensor-matrix multiplication}. A product of a tensor $\\mathcal{X}$ and a matrix $\\bm M=\\big(m_{ij}\\big)_{i,j}$ on the $k$-th mode is a tensor defined as:\n\\begin{equation}\n    \\big(\\mathcal{X}\\times_kM\\big)[i_1,...,i_n] = \n    \\sum_j \\mathcal{X}[i_1,...,i_{k-1},j,i_{k+1},...,i_n]m_{ji_k}.\n\\end{equation}\n$M\\times_k\\mathcal{X}$ can be defined similarly as\n\\begin{equation}\n    \\big(M\\times_k\\mathcal{X}\\big)[i_1,...,i_n] = \n    \\sum_j m_{i_kj}\\mathcal{X}[i_1,...,i_{k-1},j,i_{k+1},...,i_n]m_{i_kj}.\n\\end{equation}\nThe following properties are easily provable:\n\\begin{lemma}\n[Tensor-Matrix Multiplication]\n\\begin{equation}\n\\aligned\n&(\\mathcal{X}\\times_k M)\\times_l N = (\\mathcal{X}\\times_l N)\\times_k M =: \\mathcal{X}\\times_k M\\times_l N\\\\\n&(\\mathcal{X}\\times_k M)\\times_k N = \\mathcal{X}\\times_k(M\\cdot N)\n\\endaligned\n\\end{equation}\n\\end{lemma}\n{\\color{red}proof?}\n\nWith the notation above, the Tucker decomposition can be written as\n\\begin{equation}\n\\label{etucker}\n\\mathcal{X} = \\bm P\\times_1 \\bm Q\\times_2 \\bm R\\times_3 \\mathcal{G}\n\\end{equation}\n{Tucker Rank}\nTucker rank (P, Q, R) is defined through the matricization:\n\\begin{align*}\nP = rank(\\mathcal{X}_{(1)})\\\\\nQ = rank(\\mathcal{X}_{(2)})\\\\\nR = rank(\\mathcal{X}_{(3)})\\\\\n\\end{align*}\n\nAs a result, matrix SVD and low-rank approximation can be extended to the computation of Tucker ranks (HOSVD). \n\n{\\bf Tensor-Train Decomposition}\nThe need for storing the $I_1\\times\\cdots\\times I_n$ core tensor makes the Tucker decomposition increasingly unattractive as $N$ gets larger. The following definition of Tensor Train decomposition solves the problem, while preserving the possibility of SVD-based compression and low-rank approximation:\n\\begin{definition}\nA tensor $\\mathcal{X}\\in\\mathbb{R}^{I_1\\times\\cdots\\times I_n}$ is said to have \\textit{tensor train rank (TT)} $(r_1, r_2,...,r_{N-1}, r_N)$ with $r_1 = r_N = 1$ if there exists matrices $G_\\mu(i_\\mu)$ for $\\mu=2,...,N$ and $i_\\mu=1,2,...,I_\\mu$ such that \n\\begin{equation}\n\\mathcal{X}[i_1,...,i_N] = G_2(i_2) G_3(i_3)\\cdots G_N(i_N), G_\\mu(i_\\mu)\\in\\mathbb{R}^{r_{\\mu-1}\\times r_\\mu}\n\\end{equation}\n\\end{definition}\n", "meta": {"hexsha": "34802acd6e24cb17cf7156404d7821c59d720ffb", "size": 22862, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Optimization.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/Optimization.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/Optimization.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.5891089109, "max_line_length": 911, "alphanum_fraction": 0.7159041204, "num_tokens": 7203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737807, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7268252008977516}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{PMFs and PDFs}\\label{sec:pmfs_pdfs}\n\n\\begin{definition}\nA random variable is called\n\\ben\n\\it \\emph{simple} if it takes only finitely many values;\n\\it \\emph{discrete} if it takes only countably many values;\n\\it \\emph{continous} if it takes uncountably many values (and satisfies some other conditions).\n\\een\n\\end{definition}\nBecause finte sets are countable, simple random variables are also discrete random variables.\n%-----------------------------\n\\subsection{Discrete distributions}\n\nDiscrete random variables are completely described by their PMFs.\n\\begin{definition}\\label{def:pmf}\nThe \\emph{probability mass function} (PMF) of a discrete random variable $X$ is a function\n\\[\n\\begin{array}{rccl}\nf:\t& \\R\t& \\to \t\t& [0,1] \\\\\n\t& x\t\t& \\mapsto \t& \\prob (X=x),\n\\end{array}\n\\]\nwith the property that $\\sum_{i=1}^{\\infty}x_i f(x_i) = 1$, where $\\{x_1,x_2,\\ldots\\}$ is the range of $X$.\n\\end{definition}\n\n\\begin{example}\\label{example:coloured_dice_game}\nTwo fair dice are rolled independently. Each die has two faces coloured red, two coloured blue and two coloured green. Suppose we win \\pounds 10 if both dice show the same colour but lose \\pounds 5 if they show different colours. Let $X$ be the amount won.\n%\\begin{blankbox}\n\\bit\n\\it The sample space can be expressed as $\\Omega=\\{RR,RB,RG,BR,BB,BG,GR,GB,GG\\}$.\n\\it The random variable $X:\\Omega\\to\\R$ can then be defined by\n\\[\nX(\\omega) = \\begin{cases}\n\t-5\t& \\text{if $\\omega\\in\\{RB,RG,BR,BG,GR,GB\\}$,} \\\\\n\t10\t& \\text{if $\\omega\\in\\{RR,BB,GG\\}$.}\n\\end{cases}\n\\]\n\\it The range of $X$ is the set $\\{-5,10\\}$.\n\\it The PMF and CDF of $X$ are the functions\n\\[\nf(x) = \\begin{cases}\n\t2/3\t& \\text{if $x = -5$} \\\\\n\t1/3\t& \\text{if $x = 10$} \\\\\n\t0\t& \\text{otherwise}\n\\end{cases}\n\\quad\\text{and}\\quad\n%\\]\n%\\it The CDF of $X$ is the function\n%\\[\nF(x) = \\begin{cases}\n\t0\t& \\text{if $x < -5$} \\\\\n\t2/3\t& \\text{if $-5 \\leq x < 10$} \\\\\n\t1\t& \\text{if $x \\geq 10$}\n\\end{cases}\n\\quad\\text{respectively}.\n\\]\n\\eit\n%\\end{blankbox}\n\\end{example}\n\n\\subsubsection*{Fundamental discrete distributions}\nA simple random variable taking all values in its range with equal probability is said to have a (discrete) \\emph{uniform} distribution. For example, if $X$ represents the score on a fair die, we say that $X$ is uniformly distributed over the set $\\{1,2,3,4,5,6\\}$. \n\nThe \\emph{Bernoulli} distribution is the distribution of an indicator variable. For example, suppose a coin has probability $p$ of landing on heads. If $X$ is the indicator variable of this event we say that $X$ has the $\\text{Bernoullii}(p)$ distribution.\n\nThree other fundamental discrete distributions are derived from the following convergent series,\n\\[\n\\begin{array}{ll}\n\\displaystyle\\sum_{k=0}^n p^k(1-p)^{n-k} \t\t= 1  \t\t\t\t\t\t& \\text{(binomial theorem)}, \\\\\n\\displaystyle\\sum_{k=0}^{\\infty} (1-p)^k \t\t= 1/p \\quad\\text{for $|p|<1$} \t& \\text{(geometric series)}, \\\\\n\\displaystyle\\sum_{k=0}^{\\infty} \\lambda^k/k!\t= e^{\\lambda}\t \t\t\t& \\text{(exponential function)}.\n\\end{array}\n\\]\nwhich yield the binomial, geometric, and Poisson distributions respectively. \n\n\\begin{table}[h]\n\\[\\begin{array}{lclcl}\\hline\n\\text{Distribution} \t\t\t& & \\text{PMF}\t\t\t\t\t& & \\text{Range}\t\\\\ \\hline\nX\\sim\\text{Uniform}(n)\t\t\t& & 1/n \t\t\t\t\t\t& & \\{1,2,\\ldots,n\\}\\\\\nX\\sim\\text{Bernoulli}(p)\t\t& & p^x(1-p)^{1-x} \t\t\t\t& & \\{0,1\\}\t\t\t\\\\\nX\\sim\\text{Binomial}(n,p)\t\t& & \\binom{n}{x}p^x(1-p)^{n-x} \t& & \\{0,1,\\ldots,n\\}\\\\\nX\\sim\\text{Geometric}(p)\t\t& & (1-p)^{x}p \t\t\t\t\t& & \\{0,1,\\ldots\\}\t\\\\\nX\\sim\\text{Poisson}(\\lambda)\t& & \\lambda^x e^{-\\lambda}/x! \t& & \\{0,1,\\ldots\\} \t\\\\ \\hline\n\\end{array}\\]\n\\caption{Fundamental discrete distributions\\label{tab:basic_discrete}}\n\\end{table}\n\n\\begin{exercise}\nFor each distribution shown in the Table~\\ref{tab:basic_discrete} verify that the expressions given for their PMFs are indeed PMFs.\n\\end{exercise}\n\n%-----------------------------\n\\subsection{Continuous distributions}\n\nConsider a random experiment which involves measuring the lifetime of a lightbulb. Let $X$ be the time elapsed between the start of the experiment and the point at which the lightbulb fails. Then $X$ can take any value in the non-negative real numbers $[0,\\infty)$, which is an \\emph{uncountable} set. The distribution of $X$ cannot therefore be specified by a probability mass function. Subject to a condition on its CDF however, the distribution of $X$ can be specified by a \\emph{probability density function}.\n\n\\begin{definition}\\label{def:cts_rvs}\nLet $X$ be a random variable and let $F$ denote its CDF. If there exists an integrable function $f:\\R\\to [0,\\infty)$ such that \n\\[\nF(x) = \\int_{-\\infty}^x f(t)\\,dt \\text{\\quad for all\\quad} x\\in\\R,\n\\]\nthen $X$ is called a \\emph{continuous random variable} and $f$ is called its \\emph{probability density function} (PDF).\n\\end{definition}\nBy the second fundamental theorem of calculus, $f(x) = F'(x)$. Note also that if $X$ is a continuous random variable then $\\prob(X=x)=0$ for any $x\\in\\R$ (this is analagous to saying that the length of a point is zero). The following result is sometimes called the \\emph{law of total probability}.\n\\begin{proposition}\nFor any PDF,\n\\[\n\\displaystyle\\int_{-\\infty}^{\\infty} f(x)\\,dx = 1.\n\\]\n\\begin{proof}\nBy Theorem~\\ref{thm:props_cdfs},\n\\[\n\\int_{-\\infty}^{\\infty} f(x)\\,dx \n\t= \\lim_{x\\to\\infty}\\int_{-\\infty}^{x} f(t)\\,dt\n\t= \\lim_{x\\to\\infty}F(x)\n\t= 1.\n\\]\n\\end{proof}\n\\end{proposition}\n\n\n%\\begin{remark}\n%To say that $X$ is a continuous random variable refers to the (absolute) continuity of its CDF, rather than to the continuity (or otherwise) of $X$ as a function on $\\Omega$. In fact, the idea of a continuous function on $\\Omega$ might not even make sense (because $\\Omega$ is just a set and the notion of distance between its elements may not be defined).\n%\\end{remark}\n\n\\subsubsection*{Fundamental continuous distributions}\n\nThe fundamental continuous distributions are derived from the following definite inegrals,\n\\[\n\\int_0^1\\,dx = 1,\\qquad \\int_0^{\\infty} e^{-x}\\,dx = 1, \\qquad \\int_{-\\infty}^{\\infty} e^{-x^2} = \\sqrt{\\pi},\n\\]\nwhich yield the standard uniform, exponential and normal distributions respectively. These standard distributions can be scaled and shifted to yield the parameterized families of distributions shown in Table~\\ref{tab:basic_cts}.\n\\begin{table}[ht]\n\\[\\begin{array}{lclcl}\\hline\n\\text{Distribution} \t\t& & \\text{PDF}\t\t\t\t\t\t\t\t\t\t\t& & \\text{Range}\t\\\\ \\hline\n\\text{Uniform}(a,b)\t\t\t& & 1/(b-a)\t\t\t\t\t\t\t\t\t\t\t\t& & [a,b]\t\t\t\\\\\n\\text{Exponential}(\\lambda)\t& & \\lambda e^{-\\lambda x} \t\t\t\t\t\t\t\t& & [0,\\infty)\t\t\\\\\n\\text{Normal}(\\mu,\\sigma^2)\t& & \\exp\\big[-(x-\\mu)^2/2\\sigma^2\\big]/\\sigma\\sqrt{2\\pi}& & (-\\infty,\\infty)\\\\ \\hline\n\\end{array}\\]\n\\caption{The fundamental continuous distributions\\label{tab:basic_cts}}\n\\end{table}\n\nTwo other notable continuous distributions are based on the following definite integrals,\n\\[\nB(\\alpha,\\beta) = \\int_0^1 t^{\\alpha-1}(1-t)^{\\beta-1}\\,dt\n\\qquad\\text{and}\\qquad\n\\Gamma(\\alpha) = \\int_0^{\\infty} t^{\\alpha-1}e^{-t}\\,dt.\n\\]\nThese are special functions known the \\emph{beta function} and the \\emph{gamma function} respectively, and have been widely studied. Unsurprisingly the corresponding distriubtions are known as the beta distribution and the gamma distributions, as shown in Table~\\ref{tab:beta_gamma}.\n\\begin{table}[ht]\n\\[\\begin{array}{lclcl}\\hline\n\\text{Distribution} \t\t& & \\text{PDF}\t\t\t\t\t\t\t\t\t\t\t& & \\text{Range}\t\\\\ \\hline\n\\text{Beta}(\\alpha,\\beta)\t& & x^{\\alpha-1}(1-x)^{\\beta-1}/B(\\alpha,\\beta)\t\t& & [0,1]\t\t\t\\\\\n\\text{Gamma}(\\alpha,\\beta)\t\t& & \\beta^{\\alpha}x^{\\alpha-1}e^{-\\beta x}/\\Gamma(\\alpha)& & [0,\\infty)\t\t\\\\ \\hline\n\\end{array}\\]\n\\caption{The beta and gamma distributions\\label{tab:beta_gamma}}\n\\end{table}\n\n\\begin{exercise}\nFor each distribution shown in Tables~\\ref{tab:basic_cts} and \\ref{tab:beta_gamma} verify that the expressions given for their PDFs are indeed PDFs.\n\\end{exercise}\n\n\n\n\\begin{exercise}\n\\begin{questions}\n\\question % MA0266\nThe PDF of a continuous random variable $X$ is given by\n\\[\nf(x) = \\left\\{\\begin{array}{ll}\n\tcx^2 \t& 1\\leq x\\leq 2,  \\\\\n\t0\t\t& \\text{otherwise.}\n\\end{array}\\right.\t\n\\]\n\\begin{parts}\n\\part Find the value of the constant $c$, and sketch the PDF of $X$.\n\\begin{answer}\n The PDF must integrate to 1:\n\\[\n\\int_{-\\infty}^{\\infty}f(x)\\,dx\n\t= \\int_{1}^{2} cx^{2}\\,dx \n\t= \\left[\\frac{cx^{3}}{3} \\right]_{1}^{2} \n\t= \\frac{7c}{3}\n\t = 1\n\\]\nso $c=3/7$. (The sketch is a quadratic curve between $x=1$ and $x=2$.)\n\\end{answer}\n\\part Show that $\\prob(X > 3/2) = 37/56$.\n\\begin{answer}\n\\[\n\\prob(X > 3/2) \t= \\int_{3/2}^{2}\\frac{3x^{2}}{7}\\,dx \n\t\t\t= \\left[\\frac{x^{3}}{7}\\right]_{3/2}^{2} \n\t\t\t= \\frac{37}{56}\n\\]\n\\end{answer}\n\\part Find the CDF of $X$.\n\\begin{answer}\nFor $1\\leq x\\leq 2$,\n\\[\nF(x) \t= \\int_{-\\infty}^{x} f(x)\\,dx\n\t\t= \\int_{1}^{x}\\frac{3x^{2}}{7}\\,dx\n\t\t= \\left[ \\frac{x^{3} }{7} \\right] _{1}^{x} \n\t\t= \\frac{x^{3}-1}{7}\n\\]\nso the CDF of $X$ is\n\\[\nF(x) = \\begin{cases}\n\t0\t\t\t\t& x < 1 \\\\\n\t(x^{3}-1)/7\t\t& 1\\leq x < 2 \\\\\n\t1\t\t\t\t& x \\geq 2\n\\end{cases}\t\n\\]\t\n\\end{answer}\n\\end{parts}\n\n\\question % GS 2.3.5(a)\nConsider the function\n\\[\nf(x) = \\begin{cases}\n\tc/x^d\t& x > 1, \\\\\n\t0\t\t& \\text{otherwise.}\n\\end{cases}\n\\]\n\\begin{parts}\n\\part Why can $f$ be a PDF only when $d>1$?\n\\begin{answer}\nThe function $f(x)=c/x^d$ is only integrable when $d>1$. in which case\n\\[\n\\int_{-\\infty}^\\infty f(x)\\,dx = \\int_1^\\infty \\frac{c}{x^d}\\,dx = \\left[\\frac{-c}{(d-1)x^{d-1}}\\right]_1^{\\infty} = \\frac{c}{d-1}\n\\]\n\\end{answer}\n\\part If $d>1$, find the value of $c$ and the corresponding CDF.\n\\begin{answer}\nIf $d>1$,\n\\[\n\\int_{-\\infty}^\\infty f(x)\\,dx = \\int_1^\\infty \\frac{c}{x^d}\\,dx = \\left[\\frac{-c}{(d-1)x^{d-1}}\\right]_1^{\\infty} = \\frac{c}{d-1}\n\\]\nIf $f$ is a PDF, we need that $\\int_{-\\infty}^\\infty f(x)\\,dx = 1$, so we must have that $c = d-1$. The corresponding CDF is\n\\[\nF(x) = \\int_{-\\infty}^x f(u)\\,du  \n\t= \\int_1^\\infty \\frac{d-1}{u^d}\\,du \n\t= \\left[\\frac{-1}{x^{d-1}}\\right]_1^x\n\t= 1 - \\frac{1}{x^{d-1}}\n\\]\nfor $x>1$, and zero otherwise.\n\\end{answer}\n\\end{parts}\n\n\\end{questions}\n\\end{exercise}\n", "meta": {"hexsha": "7d3a776ae65b7ad2d27922b5cc8714e23d367abe", "size": 10027, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/03B_pmfs_pdfs.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/03B_pmfs_pdfs.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/03B_pmfs_pdfs.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 39.3215686275, "max_line_length": 513, "alphanum_fraction": 0.6530368006, "num_tokens": 3654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118111485244, "lm_q2_score": 0.8791467754256018, "lm_q1q2_score": 0.7268010229774844}}
{"text": "%% ps1_q1.tex\n\\section{ Functions in mathematics and Haskell. } \nWe're tasked with implementation of two base functions in Haskell, $f(x) := x^2$ and $g(x) := x + 1.$\nThese are pretty straightforward:\n\\inputminted[firstline=7,\n             lastline=11,\n             fontsize=\\footnotesize, tabsize=4]{haskell}{ps1.hs}\nIn order to implement the and-then composition, we introduce a helper function, {\\tt andThen} for $\\fatsemi$:\n\\inputminted[firstline=13,\n             lastline=14,\n             fontsize=\\footnotesize, tabsize=4]{haskell}{ps1.hs}\nNow we can implement both $h = f \\circ g$ and $i = f \\fatsemi g$:\n\\inputminted[firstline=16,\n             lastline=20,\n             fontsize=\\footnotesize, tabsize=4]{haskell}{ps1.hs}\nand the answers are as follows: $h(2) = 9,\\ i(2) = 5.$", "meta": {"hexsha": "2855e26f77522da17a931e064b6bc8434070e8e1", "size": 784, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ps1/ps1_q1.tex", "max_stars_repo_name": "alf239/procats", "max_stars_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ps1/ps1_q1.tex", "max_issues_repo_name": "alf239/procats", "max_issues_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ps1/ps1_q1.tex", "max_forks_repo_name": "alf239/procats", "max_forks_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.0, "max_line_length": 109, "alphanum_fraction": 0.6556122449, "num_tokens": 233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865198, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7266552746062273}}
{"text": "\n\\subsection{Forms on real functions}\n\nA form takes two vectors and produces a scalar.\n\n\\subsubsection{Integration as a form}\n\nWe can use integration to get a bilinear form.\n\n\\(\\int f(x) g(x) dx\\)\n\nIf we instead want a sesquilinear form we can instead use:\n\n\\(\\int \\bar {f(x)} g(x) dx\\)\n\n", "meta": {"hexsha": "707f52cd363dac5bc4f917dde26f59a8129a0c8f", "size": 288, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/functionalAnalysis/04-01-forms.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/functionalAnalysis/04-01-forms.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/functionalAnalysis/04-01-forms.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.0, "max_line_length": 58, "alphanum_fraction": 0.7083333333, "num_tokens": 80, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7266307364806277}}
{"text": "\\subsection{Example with transformation}\n\nThe $2\\times 2$ matrix $A$ with property $R_\\theta(\\tb{v})=A\\tb{v}$ rotates the vector by $\\theta$.\nUsing the unit circle to find the coordinates using the basis vectors $\\tb{e}_1$ and $\\tb{e}_2$:\n\n\\[\n    R_{\\theta}\\left(\\tb{e}_{1}\\right)=\\left[\\begin{array}{l}\n    \\cos \\theta \\\\\n    \\sin \\theta\n    \\end{array}\\right]\n\\]\n\n\\[\n    R_{\\theta}\\left(\\tb{e}_{2}\\right)=\\left[\\begin{array}{c}\n    -\\sin \\theta \\\\\n    \\cos \\theta\n    \\end{array}\\right]\n\\]\n\nThis results in $A$:\n\n\\[\n    \\left[\\begin{array}{cc}\n    \\cos \\theta & -\\sin \\theta \\\\\n    \\sin \\theta & \\cos \\theta\n    \\end{array}\\right]\n\\]\n\nFinding the inverse of this is simply rotating back by $\\theta$, so finding $R^{-1}_{\\theta}$:\n\n\\[\n    \\left[\\begin{array}{cc}\n    \\cos (-\\theta) & -\\sin (-\\theta) \\\\\n    \\sin (-\\theta) & \\cos (-\\theta)\n    \\end{array}\\right]\n    =\n    \\left[\\begin{array}{cc}\n    \\cos \\theta & \\sin \\theta \\\\\n    -\\sin \\theta & \\cos \\theta\n    \\end{array}\\right]\n\\]", "meta": {"hexsha": "0920e10d94d0db6625918f23445584b4f07760b1", "size": 986, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/6_transformation-inverses.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "linear-algebra/tex/6_transformation-inverses.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "linear-algebra/tex/6_transformation-inverses.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0487804878, "max_line_length": 99, "alphanum_fraction": 0.5740365112, "num_tokens": 343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7266307333244498}}
{"text": "\\title{Distribution of Angle between Two Linked Triangles}\n\\author{\n        Daniel Johnson \\\\\n                Division of Applied Mathematics\\\\\n        Brown University\n}\n\\date{\\today}\n\n\\documentclass[12pt]{article}\n\n\\usepackage{graphicx,amsfonts,amsbsy,bbm, amsmath}\n\\newcommand*{\\Scale}[2][4]{\\scalebox{#1}{$#2$}}%\n\n\\begin{document}\n\\maketitle\n\n\\section{One Dimensional Constraint Manifold}\nFirst we consider the case in which one triangle is fixed with the coordinates $(0, 1/2, 0), (0, -1/2, 0), (\\sqrt{3}/2, 0, 0)$. The second face will share the vertices $(0, 1/2, 0)$ and $(0, -1/2, 0)$ and its third vertex $v$ is allowed to vary subject to the constraints of being unit distance from the other vertices. The corresponding constraint space can be described by parameterizing $v$ by $\\theta$, the dihedral angle between faces.\n\\begin{align}\nv(\\theta) &= \\left[\\sqrt{3}/2\\cos\\theta, 0, \\sqrt{3}/2\\sin\\theta\\right]^T\n\\end{align}\n\nDiaconis et al. outline a method for sampling uniformly from a manifold $\\mathcal{M}$. If the manifold is of $m$ dimensions sitting in an $n$ dimensional ambient space, and a parameterization $f: \\mathbbm{R}^m \\to \\mathbbm{R}^n$ the sampling distribution on the parameters that corresponds to a uniform sampling on $\\mathcal{M}$ is given by $h(\\omega, \\theta, \\phi) \\propto \\left(\\det\\left[(Df)^TDf\\right]\\right)^{1/2}$.\n\nIn this example, we have the following parameterization. \n\\begin{align}\nf(\\theta) &= \\Scale[1.0]{\\begin{bmatrix}\n0 \\\\ 1/2 \\\\ 0 \\\\ 0 \\\\ -1/2 \\\\ 0 \\\\ \\sqrt{3}/2 \\\\ 0 \\\\ 0 \\\\\\sqrt{3}/2 \\cos\\theta \\\\ 0 \\\\ \\sqrt{3}/2\\sin\\theta\n\\end{bmatrix}} \\\\\nDf(\\theta) &= \\Scale[1.0]{\\begin{bmatrix}\n0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ -\\sqrt{3}/2\\sin\\theta \\\\ 0 \\\\ \\sqrt{3}/2\\cos\\theta\n\\end{bmatrix}} \n\\end{align}\nThus the sampling distribution on $\\theta$ is uniform. \n\\begin{align}\nh(\\theta) &\\propto \\sqrt{\\det\\left[3/4\\right]}\\\\\n&\\propto 1\n\\end{align}\n\n\\section{Three Dimensional Constraint Manifold}\n\nNow we let the common edge rotate about the x-axis while its center remains fixed at the origin. More formally, define the point $u = \\left[0, \\frac{1}{2}\\cos\\omega, \\frac{1}{2}\\sin\\omega\\right]^T$ in the y-z plane. Then, we parameterize the shared edge by $\\omega \\in [0, 2\\pi)$ with its endpoints being $u(\\omega)$ and $-u(\\omega)$. Then we use $\\theta$ and $\\phi$ to parameterize the remaining two vertices $v_1$ and $v_2$ as follows.\n\\begin{align}\nv_1 &= \\left[\\frac{\\sqrt{3}}{2}\\cos\\theta, \\frac{\\sqrt{3}}{2}\\sin\\theta\\sin\\omega, -\\frac{\\sqrt{3}}{2}\\sin\\theta\\cos\\omega\\right]^T \\\\ \nv_2 &= \\left[\\frac{\\sqrt{3}}{2}\\cos(\\theta+\\phi), \\frac{\\sqrt{3}}{2}\\sin(\\theta+\\phi)\\sin\\omega, -\\frac{\\sqrt{3}}{2}\\sin(\\theta+\\phi)\\cos\\omega\\right]^T \n\\end{align}\nWith these parameterizations, it is trivial to verify that the constrains $|u - (-u)| = |v_1 - u| = |v_1 + u| =|v_2 - u| = |v_2 + u| = 1$ are all satisfied for any choice of $(\\omega, \\theta, \\phi)$. Additionally, the dihedral angle between the two triangles is given by $\\phi$. \n\nWe proceed in deriving the sampling distributions of the 3 parameters that corresponds to uniform sampling of the 3 dimensional constraint manifold embedded in $\\mathbbm{R}^{12}$ using the method outlined in Diaconis et al. First we concatenate our parameterizations into a function $f: \\mathbbm{R}^3 \\to \\mathbbm{R}^{12}$ That maps $(\\omega, \\theta, \\phi) \\in [0, 2\\pi)^3$ onto the constraint manifold. \n\\begin{align}\nf(\\omega, \\theta, \\phi) &= \\Scale[1.0]{\\begin{bmatrix}\n0 \\\\ \\frac{1}{2}\\cos\\omega \\\\ \\frac{1}{2}\\sin\\omega \\\\ 0 \\\\ -\\frac{1}{2}\\cos\\omega \\\\ -\\frac{1}{2}\\sin\\omega \\\\\n\\frac{\\sqrt{3}}{2}\\cos\\theta \\\\ \\frac{\\sqrt{3}}{2}\\sin\\theta\\sin\\omega \\\\ -\\frac{\\sqrt{3}}{2}\\sin\\theta\\cos\\omega  \\\\ \n\\frac{\\sqrt{3}}{2}\\cos(\\theta+\\phi) \\\\ \\frac{\\sqrt{3}}{2}\\sin(\\theta+\\phi)\\sin\\omega \\\\ -\\frac{\\sqrt{3}}{2}\\sin(\\theta+\\phi)\\cos\\omega\n\\end{bmatrix}} \\\\\nDf(\\omega, \\theta, \\phi) &= \\Scale[1.0]{\\begin{bmatrix}\n0 & 0 & 0\\\\ \n-\\frac{1}{2}\\sin\\omega  & 0 & 0 \\\\ \n\\frac{1}{2}\\cos\\omega  & 0 & 0 \\\\ \n0  & 0 & 0 \\\\ \n\\frac{1}{2}\\sin\\omega  & 0 & 0 \\\\ \n-\\frac{1}{2}\\cos\\omega  & 0 & 0 \\\\\n0 & -\\frac{\\sqrt{3}}{2}\\sin\\theta & 0 \\\\ \n\\frac{\\sqrt{3}}{2}\\sin\\theta\\cos\\omega &\\frac{\\sqrt{3}}{2}\\cos\\theta\\sin\\omega & 0 \\\\ \n\\frac{\\sqrt{3}}{2}\\sin\\theta\\sin\\omega   & -\\frac{\\sqrt{3}}{2}\\cos\\theta\\cos\\omega & 0 \\\\ \n0 & -\\frac{\\sqrt{3}}{2}\\sin(\\theta+\\phi) & -\\frac{\\sqrt{3}}{2}\\sin(\\theta+\\phi) \\\\ \n\\frac{\\sqrt{3}}{2}\\sin(\\theta+\\phi)\\cos\\omega & \\frac{\\sqrt{3}}{2}\\cos(\\theta+\\phi)\\sin\\omega & \\frac{\\sqrt{3}}{2}\\cos(\\theta+\\phi)\\sin\\omega   \\\\ \n\\frac{\\sqrt{3}}{2}\\sin(\\theta+\\phi)\\sin\\omega & -\\frac{\\sqrt{3}}{2}\\cos(\\theta+\\phi)\\cos\\omega  & -\\frac{\\sqrt{3}}{2}\\cos(\\theta+\\phi)\\cos\\omega   \n\\end{bmatrix}} \\\\\n(Df)^TDf &= \\Scale[1.0]{\\begin{bmatrix}\n\\frac{1}{2} + \\frac{3}{4}\\sin^2\\theta + \\frac{3}{4}\\sin^2(\\theta + \\phi) & 0 & 0 \\\\\n0 & \\frac{3}{2} & \\frac{3}{4} \\\\\n0 & \\frac{3}{4} & \\frac{3}{4} \n\\end{bmatrix}}\n\\end{align}\nThus the sampling distribution is computed.\n\\begin{align}\nh(\\omega, \\theta, \\phi) &\\propto \\sqrt{1 + \\frac{3}{2}\\sin^2\\theta + \\frac{3}{2}\\sin^2(\\theta + \\phi)}\n\\end{align}\n\n\\section{Four Dimensional Constraint Manifold} \n\nSuppose we relax the constraints of the previous calculation. Fix the midpoint of the shared edge at the origin, but allow it the freedom to rotate in any direction. Then, the endpoints of the shared edge lie at opposite ends of the sphere with radius $1/2$. We use spherical coordinates to parameterize the axis $[-u(\\phi,\\omega),u(\\phi,\\omega)]$.\n\\begin{align}\nu(\\phi,\\omega) &= \\left(\\frac{1}{2}\\cos(\\phi),\\frac{1}{2}\\sin(\\phi)\\cos(\\omega), \\frac{1}{2}\\sin(\\phi)\\sin(\\omega) \\right)\n\\end{align}\nNow we parameterize the remaining two vertices as $v_1 = R(2u, \\theta)v_0$ and $v_2 = R(2u, \\theta + \\xi)v_0$ where $v_0$ is any fixed point satisfying $|v_0 - u| = |v_0 + u| = 1$ and $R(\\hat{u},\\hat{\\theta})$ is the rotation matrix with unit axis of rotation $\\hat{u}$ and angle of rotation $\\hat{\\theta}$. \n\\begin{align}\nv_1 &= R(2u, \\theta)v_0 \\\\\n&= \\left(\\cos\\theta I + 4(1-\\cos\\theta)uu^T + 2\\sin\\theta[u]_\\times\\right)v_0 \\\\\n&= \\cos\\theta v_0 + 4(1-\\cos\\theta)u(u\\cdot v_0) + 2\\sin\\theta (u\\times v_0) \\\\\n&= \\cos\\theta v_0 + 2\\sin\\theta (u\\times v_0) \\\\\nv_2 &= R(2u, \\theta + \\xi)v_0 \\\\\n&= \\cos(\\theta+\\xi) v_0 + 2\\sin(\\theta + \\xi) (u\\times v_0)\n\\end{align}\n\n\n%\\begin{align}\n%R(2u,\\theta) &= \\Scale[0.75]{\\begin{bmatrix} \\cos \\theta + 4u_x^2 \\left(1-\\cos \\theta\\right) & 4u_x u_y \\left(1-\\cos \\theta\\right) - 2u_z \\sin \\theta & 4u_x u_z \\left(1-\\cos \\theta\\right) + 2u_y \\sin \\theta \\\\ 4u_y u_x \\left(1-\\cos \\theta\\right) + 2u_z \\sin \\theta & \\cos \\theta + 4u_y^2\\left(1-\\cos \\theta\\right) & 4u_y u_z \\left(1-\\cos \\theta\\right) - 2u_x \\sin \\theta \\\\ 4u_z u_x \\left(1-\\cos \\theta\\right) - 2u_y \\sin \\theta   & 4u_z u_y \\left(1-\\cos \\theta\\right) + 2u_x \\sin \\theta & \\cos \\theta + 4u_z^2\\left(1-\\cos \\theta\\right) \n%\\end{bmatrix}} \\\\\n%&= \\cos\\theta I + 4(1-\\cos\\theta)uu^T + 2\\sin\\theta[u]_\\times \\\\\n%\\end{align}\n\nThus, we compute as follows. \n\\begin{align}\n  f(\\phi, \\omega, \\theta, \\xi) &= \\begin{bmatrix} u \\\\ -u \\\\ v_1 \\\\ v_2 \\end{bmatrix} \\\\\n  Df(\\phi, \\omega, \\theta, \\xi) &= \\begin{bmatrix} Du \\\\ -Du \\\\ Dv_1 \\\\ Dv_2 \\end{bmatrix} \\\\\n  \\left(Df\\right)^TDf &=   2\\left(Du\\right)^TDu  + \\left(Dv_1\\right)^TDv_1 + \\left(Dv_2\\right)^TDv_2 \n\\end{align}\n\n\\begin{align}\n  Du(\\phi, \\omega, \\theta, \\xi) &= \\begin{bmatrix} -\\frac{1}{2}\\sin\\phi & 0 & 0 & 0 \\\\ \\frac{1}{2}\\cos\\phi\\cos\\omega & -\\frac{1}{2}\\sin\\phi\\sin\\omega & 0 & 0\\\\  \\frac{1}{2}\\cos\\phi\\sin\\omega & \\frac{1}{2}\\sin\\phi\\cos\\omega & 0 & 0\\end{bmatrix} \\\\\n  \\left(Du\\right)^TDu &= \\Scale[0.50]{\\begin{bmatrix} \n\\frac{1}{4}\\sin^2\\phi + \\frac{1}{4}\\cos^2\\phi\\cos^2\\omega+ \\frac{1}{4}\\cos^2\\phi\\sin^2\\omega\n&  \\frac{1}{4}\\cos\\phi\\cos\\omega\\sin\\phi\\sin\\omega - \\frac{1}{4}\\cos\\phi\\cos\\omega\\sin\\phi\\sin\\omega \n& 0 & 0\n\\\\ \\frac{1}{4}\\cos\\phi\\cos\\omega\\sin\\phi\\sin\\omega - \\frac{1}{4}\\cos\\phi\\cos\\omega\\sin\\phi\\sin\\omega \n& \\frac{1}{4}\\sin^2\\phi\\sin^2\\omega + \\frac{1}{4}\\sin^2\\phi\\cos^2\\omega\n& 0 & 0\n\\\\ 0\n& 0\n& 0 & 0\\\\ 0\n& 0\n& 0 & 0 \\end{bmatrix}} \\\\\n &= \\Scale[1.00]{\\begin{bmatrix} \n\\frac{1}{4}\n& 0\n& 0 & 0\n\\\\ 0 \n& \\frac{1}{4}\\sin^2\\phi\n& 0 & 0\n\\\\ 0\n& 0\n& 0 & 0\\\\ 0\n& 0\n& 0 & 0 \\end{bmatrix}}\n\\end{align} \\\\\n\n\n\\begin{align}\nv_1 &= R(2u, \\theta)v_0 \\\\\n&= \\left(\\cos\\theta I + 4(1-\\cos\\theta)uu^T + 2\\sin\\theta[u]_\\times\\right)v_0 \\\\\n&= \\cos\\theta v_0 + 4(1-\\cos\\theta)u(u\\cdot v_0) + 2\\sin\\theta (u\\times v_0) \\\\\n&= \\cos\\theta v_0 + 2\\sin\\theta (u\\times v_0) \\\\\nv_2 &= R(2u, \\theta + \\xi)v_0 \\\\\n&= \\cos(\\theta+\\xi) v_0 + 2\\sin(\\theta + \\xi) (u\\times v_0)\n\\end{align}\n\n\n\\begin{align}\n\\nabla_\\phi v_1 &= 2\\sin\\theta(\\nabla_\\phi u \\times v_0) \\\\\n\\nabla_\\omega v_1 &= 2\\sin\\theta(\\nabla_\\omega u \\times v_0) \\\\\n\\nabla_\\theta v_1 &= -\\sin\\theta v_0 + 2\\cos\\theta(u\\times v_0) \\\\\n\\nabla_\\xi v_1 &= 0\n\\end{align}\n\n\\begin{align}\n\\nabla_\\phi v_2 &= 2\\sin(\\theta+\\xi)(\\nabla_\\phi u \\times v_0) \\\\\n\\nabla_\\omega v_2 &= 2\\sin(\\theta+\\xi)(\\nabla_\\omega u \\times v_0) \\\\\n\\nabla_\\theta v_2 &= -\\sin(\\theta+\\xi) v_0 + 2\\cos(\\theta+\\xi)(u\\times v_0) \\\\\n\\nabla_\\xi v_2 &= -\\sin(\\theta+\\xi) v_0 + 2\\cos(\\theta+\\xi)(u\\times v_0) \\\\\n\\end{align}\n\n\n\\begin{align}\nDv_1 &= \\Scale[1.00]{\\begin{bmatrix} \n\\nabla_\\phi v_1 &\n\\nabla_\\omega v_1 &\n\\nabla_\\theta v_1 &\n\\nabla_\\xi v_1 \n\\end{bmatrix}} \\\\\n \\left(Dv_1\\right)^TDv_1 &= \\Scale[1.00]{\\begin{bmatrix} \n \\frac{3}{4}\\sin^2\\theta & 0 & 0 & 0 \\\\\n 0 & \\frac{3}{4}\\sin^2\\theta \\sin^2\\omega & 0 & 0\\\\\n 0 & 0 & \\frac{3}{4}& 0\\\\\n 0 & 0 & 0 & 0 \n\\end{bmatrix}} \n\\end{align} \n\n\\begin{align}\n \\left(Dv_2\\right)^TDv_2 &= \\Scale[1.00]{\\begin{bmatrix} \n \\frac{3}{4}\\sin^2(\\theta+\\xi) & 0 & 0 & 0 \\\\\n 0 & \\frac{3}{4}\\sin^2(\\theta+\\xi) \\sin^2\\omega & 0 & 0\\\\\n 0 & 0 & \\frac{3}{4} & \\frac{3}{4}\\\\\n 0 & 0 & \\frac{3}{4} & \\frac{3}{4}\n\\end{bmatrix}} \n\\end{align} \n\n\\begin{align}\n \\left(Df\\right)^TDf &= \\Scale[0.70]{\\begin{bmatrix} \n \\frac{3}{4}\\sin^2\\theta + \\frac{3}{4}\\sin^2(\\theta+\\xi) + \\frac{1}{2} & 0 & 0 & 0 \\\\\n 0 & \\frac{3}{4}\\sin^2\\theta \\sin^2\\omega + \\frac{3}{4}\\sin^2(\\theta+\\xi) \\sin^2\\omega + \\frac{1}{2}\\sin^2\\phi & 0 & 0\\\\\n 0 & 0 & \\frac{3}{2} & \\frac{3}{4}\\\\\n 0 & 0 & \\frac{3}{4} & \\frac{3}{4}\n\\end{bmatrix}} \n\\end{align} \n\n\\begin{align}\nh(\\phi, \\omega, \\theta, \\xi) &\\propto \\sqrt{\\det\\left(\\left(Df\\right)^TDf\\right)} \\\\\n&\\propto \\sqrt{\\left( \\frac{3}{4}\\sin^2\\theta + \\frac{3}{4}\\sin^2(\\theta+\\xi) + \\frac{1}{2} \\right)\\left(\\frac{3}{4}\\sin^2\\theta \\sin^2\\omega + \\frac{3}{4}\\sin^2(\\theta+\\xi) \\sin^2\\omega + \\frac{1}{2}\\sin^2\\phi\\right)} \\\\\n&\\propto \\sqrt{\\left(3\\sin^2\\theta + 3\\sin^2(\\theta+\\xi) + 2\\right)\\left(3\\sin^2\\theta \\sin^2\\omega + 3\\sin^2(\\theta+\\xi) \\sin^2\\omega + 2\\sin^2\\phi\\right)}\n\\end{align}\n\n\n\n\\end{document}\n\n\\begin{align}\nDv(\\phi, \\omega, \\theta, \\xi) &= \\Scale[1.0]{\\begin{bmatrix}\n\\frac{\\partial R}{\\partial\\phi}v_0 & \\frac{\\partial R}{\\partial\\omega}v_0 & \\frac{\\partial R}{\\partial\\theta}v_0 \n\\end{bmatrix}} \\\\\n\\left(Dv\\right)^TDv &= \\Scale[1.0]{\\begin{bmatrix}\n(v_0)^T(\\frac{\\partial R}{\\partial\\phi})^T\\frac{\\partial R}{\\partial\\phi}v_0 & (v_0)^T(\\frac{\\partial R}{\\partial\\phi})^T\\frac{\\partial R}{\\partial\\omega}v_0 & (v_0)^T(\\frac{\\partial R}{\\partial\\phi})^T\\frac{\\partial R}{\\partial\\theta}v_0 \\\\\n(v_0)^T(\\frac{\\partial R}{\\partial\\omega})^T\\frac{\\partial R}{\\partial\\phi}v_0 & (v_0)^T(\\frac{\\partial R}{\\partial\\omega})^T\\frac{\\partial R}{\\partial\\omega}v_0 & (v_0)^T(\\frac{\\partial R}{\\partial\\omega})^T\\frac{\\partial R}{\\partial\\theta}v_0 \\\\ \n    (v_0)^T(\\frac{\\partial R}{\\partial\\theta})^T\\frac{\\partial R}{\\partial\\phi}v_0 & (v_0)^T(\\frac{\\partial R}{\\partial\\theta})^T\\frac{\\partial R}{\\partial\\omega}v_0 & (v_0)^T(\\frac{\\partial R}{\\partial\\theta})^T\\frac{\\partial R}{\\partial\\theta}v_0     \n\\end{bmatrix}}\n\\end{align}\n\n\n\\begin{align}\n  R &= \\cos\\theta I + 4(1-\\cos\\theta)uu^T + 2\\sin\\theta[u]_\\times \\\\\n  \\frac{\\partial R}{\\partial\\phi} &= 4(1-\\cos\\theta)(u\\frac{\\partial u^T}{\\partial\\phi} + \\frac{\\partial u}{\\partial\\phi}u^T) + 2\\sin\\theta\\frac{\\partial [u]_\\times}{\\partial\\phi} \\\\ \n  \\frac{\\partial R}{\\partial\\omega} &= 4(1-\\cos\\theta)(u\\frac{\\partial u^T}{\\partial\\omega} + \\frac{\\partial u}{\\partial\\omega}u^T) + 2\\sin\\theta\\frac{\\partial [u]_\\times}{\\partial\\omega}  \\\\\n  \\frac{\\partial R}{\\partial\\theta} &= -\\sin\\theta I + 4\\sin\\theta uu^T + 2\\cos\\theta[u]_\\times \\\\\n\\end{align}\n\n\\begin{align}\n\\frac{\\partial u}{\\partial\\phi}u^T &= \\frac{1}{4}\\Scale[1.0]{\\begin{bmatrix}\n-\\cos\\phi\\sin\\phi & \\cos^2\\phi\\cos\\omega & \\cos^2\\phi\\sin\\omega \\\\\n-\\sin^2\\phi\\cos\\omega & \\sin\\phi\\cos\\phi\\cos^2\\omega & \\sin\\phi\\cos\\phi\\sin\\omega\\cos\\omega \\\\\n-\\sin^2\\phi\\sin\\omega & \\sin\\phi\\cos\\phi\\sin\\omega\\cos\\omega  & \\sin\\phi\\cos\\phi\\sin^2\\omega\n\\end{bmatrix}} \\\\\nu\\frac{\\partial u^T}{\\partial\\phi} + \\frac{\\partial u}{\\partial\\phi}u^T &= \\frac{1}{4}\\Scale[1.0]{\\begin{bmatrix}\n-\\sin 2\\phi & \\cos 2\\phi \\cos\\omega & \\cos 2\\phi\\sin\\omega \\\\\n\\cos 2\\phi\\omega & \\sin 2\\phi\\cos^2\\omega & \\sin 2\\phi\\sin 2\\omega \\\\\n\\cos 2\\phi\\sin\\omega & \\sin 2\\phi\\sin 2\\omega & \\sin 2\\phi\\sin^2\\omega \n\\end{bmatrix}} \n\\end{align}\n\n\\begin{align}\n\\frac{\\partial u}{\\partial\\omega}u^T &= \\frac{1}{4}\\Scale[1.0]{\\begin{bmatrix}\n0 & -\\sin\\phi\\cos\\phi\\sin\\omega & \\sin\\phi\\cos\\phi\\cos\\omega \\\\\n0 & -\\sin^2\\phi\\sin\\omega\\cos\\omega & \\sin^2\\phi\\cos^2\\omega \\\\\n0 & -\\sin^2\\phi\\sin^2\\omega & \\sin^2\\phi\\sin\\omega\\cos\\omega\n\\end{bmatrix}} \\\\\nu\\frac{\\partial u^T}{\\partial\\omega} + \\frac{\\partial u}{\\partial\\omega}u^T &= \\frac{1}{4}\\Scale[1.0]{\\begin{bmatrix}\n0 & -\\sin\\phi\\cos\\phi\\sin\\omega & \\sin\\phi\\cos\\phi\\cos\\omega \\\\\n-\\sin\\phi\\cos\\phi\\sin\\omega & -\\sin^2\\phi\\sin 2\\omega & \\sin^2\\phi\\cos 2\\omega \\\\\n\\sin\\phi\\cos\\phi\\cos\\omega & \\sin^2\\phi\\cos 2\\omega & \\sin^2\\phi\\sin 2\\omega\n\\end{bmatrix}} \n\\end{align}\n\n\\begin{align}\nuu^T &= \\frac{1}{4}\\Scale[1.0]{\\begin{bmatrix}\n\\cos^2\\phi & \\sin\\phi\\cos\\phi\\cos\\omega & \\sin\\phi\\cos\\phi\\sin\\omega \\\\\n\\sin\\phi\\cos\\phi\\cos\\omega & \\sin^2\\phi\\cos^2\\omega & \\sin^2\\phi\\sin\\omega\\cos\\omega \\\\\n\\sin\\phi\\cos\\phi\\sin\\omega & \\sin^2\\phi\\sin\\omega\\cos\\omega & \\sin^2\\phi\\sin^2\\omega\n\\end{bmatrix}} \n\\end{align}\n\n\\begin{align}\n[u]_\\times &= \\frac{1}{2}\\Scale[1.0]{\\begin{bmatrix}\n0 & -\\sin\\phi\\sin\\omega & \\sin\\phi\\cos\\omega \\\\\n\\sin\\phi\\sin\\omega & 0 & -\\cos\\phi \\\\\n-\\sin\\phi\\cos\\omega & \\cos\\phi & 0\n\\end{bmatrix}} \n\\end{align}\n\n\\begin{align}\n\\frac{\\partial[u]_\\times}{\\partial\\phi} &= \\frac{1}{2}\\Scale[1.0]{\\begin{bmatrix}\n0 & -\\cos\\phi\\sin\\omega & \\cos\\phi\\cos\\omega \\\\\n\\cos\\phi\\sin\\omega & 0 & \\sin\\phi \\\\\n-\\cos\\phi\\cos\\omega & -\\sin\\phi & 0\n\\end{bmatrix}} \n\\end{align}\n\n\\begin{align}\n\\frac{\\partial[u]_\\times}{\\partial\\omega} &= \\frac{1}{2}\\Scale[1.0]{\\begin{bmatrix}\n0 & -\\sin\\phi\\cos\\omega & -\\sin\\phi\\sin\\omega \\\\\n\\sin\\phi\\cos\\omega & 0 & 0 \\\\\n\\sin\\phi\\sin\\omega & 0 & 0\n\\end{bmatrix}} \n\\end{align}\n\n\n\\begin{align}\n[u]^T_\\times[u]_\\times &= \\frac{1}{4}\\Scale[1.0]{\\begin{bmatrix}\n\\sin^2\\phi & -\\sin\\phi\\cos\\phi\\cos\\omega & -\\sin\\phi\\cos\\phi\\sin\\omega \\\\\n-\\sin\\phi\\cos\\phi\\cos\\omega & \\sin^2\\phi\\sin^2\\omega + \\cos^2\\phi & -\\sin^2\\phi\\sin\\omega\\cos\\omega\\\\\n-\\sin\\phi\\cos\\phi\\sin\\omega & -\\sin^2\\phi\\sin\\omega\\cos\\omega & \\sin^2\\phi\\cos^2\\phi + \\cos^2\\omega\n\\end{bmatrix}} \n\\end{align}\n\n\\begin{align}\n(\\frac{\\partial R}{\\partial\\theta})^T\\frac{\\partial R}{\\partial\\theta} &=  (-\\sin\\theta I + 4\\sin\\theta uu^T + 2\\cos\\theta[u]_\\times)^T(-\\sin\\theta I + 4\\sin\\theta uu^T + 2\\cos\\theta[u]_\\times) \\\\\n%  &=  \\sin^2\\theta I - 4\\sin^2\\theta uu^T - 2\\sin\\theta\\cos\\theta[u]_\\times - 4\\sin^2\\theta uu^T + 16\\sin^2uu^Tuu^T+ 8\\sin\\theta\\cos\\theta uu^T\\theta[u]_\\times - 2\\sin\\theta\\cos\\theta[u]_\\times^T + 8\\sin\\theta\\cos\\theta \\theta[u]_\\times^T uu^T  + 4\\cos^2 \\theta[u]_\\times^T\\theta[u]_\\times  \n  &=  \\sin^2\\theta I - 8\\sin^2\\theta uu^T  + 16\\sin^2\\theta uu^Tuu^T  + 4\\cos^2 \\theta[u]_\\times^T\\theta[u]_\\times  \\\\\n  &=  \\sin^2\\theta I - 8\\sin^2\\theta uu^T  + 4\\sin^2\\theta uu^T  + 4\\cos^2 \\theta[u]_\\times^T\\theta[u]_\\times  \\\\\n  &=  \\sin^2\\theta I - 4\\sin^2\\theta uu^T  + 4\\cos^2 \\theta[u]_\\times^T\\theta[u]_\\times  \n\\end{align}\n\n\n\n\n%\\begin{align}\n%\\frac{\\partial R}{\\partial\\phi} &= \\Scale[0.60]{\\begin{bmatrix}  \n%8u_x\\frac{\\partial u_x}{\\partial\\phi} \\left(1-\\cos \\theta\\right) \n%& 4(u_x\\frac{\\partial u_y}{\\partial\\phi} +  u_y\\frac{\\partial u_x}{\\partial\\phi}) \\left(1-\\cos \\theta\\right) - 2\\frac{\\partial u_z}{\\partial\\phi} \\sin \\theta \n%& 4(u_x\\frac{\\partial u_z}{\\partial\\phi} +  u_z\\frac{\\partial u_x}{\\partial\\phi}) \\left(1-\\cos \\theta\\right) + 2\\frac{\\partial u_y}{\\partial\\phi} \\sin \\theta \n%\\\\ 4(u_x\\frac{\\partial u_y}{\\partial\\phi} +  u_y\\frac{\\partial u_x}{\\partial\\phi}) \\left(1-\\cos \\theta\\right) + 2\\frac{\\partial u_z}{\\partial\\phi} \\sin \\theta \n%& 8u_y\\frac{\\partial u_y}{\\partial\\phi} \\left(1-\\cos \\theta\\right) \n%& 4(u_y\\frac{\\partial u_z}{\\partial\\phi} +  u_z\\frac{\\partial u_y}{\\partial\\phi}) \\left(1-\\cos \\theta\\right) - 2\\frac{\\partial u_x}{\\partial\\phi} \\sin \\theta \n%\\\\ 4(u_x\\frac{\\partial u_z}{\\partial\\phi} +  u_z\\frac{\\partial u_x}{\\partial\\phi}) \\left(1-\\cos \\theta\\right) - 2\\frac{\\partial u_y}{\\partial\\phi} \\sin \\theta \n%& 4(u_y\\frac{\\partial u_z}{\\partial\\phi} +  u_z\\frac{\\partial u_y}{\\partial\\phi}) \\left(1-\\cos \\theta\\right) + 2\\frac{\\partial u_x}{\\partial\\phi} \\sin \\theta \n%& 8u_z\\frac{\\partial u_z}{\\partial\\phi} \\left(1-\\cos \\theta\\right) \\end{bmatrix}} \\\\\n%\\frac{\\partial R}{\\partial\\omega} &= \\Scale[0.60]{\\begin{bmatrix}  \n%8u_x\\frac{\\partial u_x}{\\partial\\omega} \\left(1-\\cos \\theta\\right) \n%& 4(u_x\\frac{\\partial u_y}{\\partial\\omega} +  u_y\\frac{\\partial u_x}{\\partial\\omega}) \\left(1-\\cos \\theta\\right) - 2\\frac{\\partial u_z}{\\partial\\omega} \\sin \\theta \n%& 4(u_x\\frac{\\partial u_z}{\\partial\\omega} +  u_z\\frac{\\partial u_x}{\\partial\\omega}) \\left(1-\\cos \\theta\\right) + 2\\frac{\\partial u_y}{\\partial\\omega} \\sin \\theta \n%\\\\ 4(u_x\\frac{\\partial u_y}{\\partial\\omega} +  u_y\\frac{\\partial u_x}{\\partial\\omega}) \\left(1-\\cos \\theta\\right) + 2\\frac{\\partial u_z}{\\partial\\omega} \\sin \\theta \n%& 8u_y\\frac{\\partial u_y}{\\partial\\omega} \\left(1-\\cos \\theta\\right) \n%& 4(u_y\\frac{\\partial u_z}{\\partial\\omega} +  u_z\\frac{\\partial u_y}{\\partial\\omega}) \\left(1-\\cos \\theta\\right) - 2\\frac{\\partial u_x}{\\partial\\omega} \\sin \\theta \n%\\\\ 4(u_x\\frac{\\partial u_z}{\\partial\\omega} +  u_z\\frac{\\partial u_x}{\\partial\\omega}) \\left(1-\\cos \\theta\\right) - 2\\frac{\\partial u_y}{\\partial\\omega} \\sin \\theta \n%& 4(u_y\\frac{\\partial u_z}{\\partial\\omega} +  u_z\\frac{\\partial u_y}{\\partial\\omega}) \\left(1-\\cos \\theta\\right) + 2\\frac{\\partial u_x}{\\partial\\omega} \\sin \\theta \n%& 8u_z\\frac{\\partial u_z}{\\partial\\omega} \\left(1-\\cos \\theta\\right) \\end{bmatrix}} \\\\\n%\\frac{\\partial R}{\\partial\\theta} &= \\Scale[0.75]{\\begin{bmatrix} \n%-\\sin \\theta + 4u_x^2 \\sin \\theta \n%& 4u_x u_y \\sin \\theta - 2u_z \\cos \\theta \n%& 4u_x u_z \\sin \\theta + 2u_y \\cos \\theta \n%\\\\ 4u_y u_x \\sin \\theta + 2u_z \\cos \\theta \n%& -\\sin \\theta + 4u_y^2\\sin \\theta \n%& 4u_y u_z \\sin \\theta - 2u_x \\cos \\theta \n%\\\\ 4u_z u_x \\sin \\theta - 2u_y \\cos \\theta   \n%& 4u_z u_y \\sin \\theta + 2u_x \\cos \\theta \n%& -\\sin \\theta + 4u_z^2\\sin \\theta \n%\\end{bmatrix}} \n%\\end{align}\n\n\n\n\\end{document}\n\n", "meta": {"hexsha": "caf5740a4605588c7f68cba25246bcef631ff3fb", "size": 18946, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "triangle_linkage_dist.tex", "max_stars_repo_name": "Danie1Johnson/research", "max_stars_repo_head_hexsha": "c10ce2a3901a4789b580c88d4855aa1c8017497f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "triangle_linkage_dist.tex", "max_issues_repo_name": "Danie1Johnson/research", "max_issues_repo_head_hexsha": "c10ce2a3901a4789b580c88d4855aa1c8017497f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2015-01-06T20:03:27.000Z", "max_issues_repo_issues_event_max_datetime": "2017-04-28T00:22:24.000Z", "max_forks_repo_path": "triangle_linkage_dist.tex", "max_forks_repo_name": "Danie1Johnson/research", "max_forks_repo_head_hexsha": "c10ce2a3901a4789b580c88d4855aa1c8017497f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.2361516035, "max_line_length": 538, "alphanum_fraction": 0.6309511242, "num_tokens": 8097, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7266264991264099}}
{"text": "\\section{Evaluating a decision tree}\nIn addition to the standard metrics, such as classification accuracy, we\nevaluate decision trees as follows. Every element of the data set is \nfed into the decision tree, thereby\nassigning each one to a leaf. Now, for each leaf, we have four numbers.\n\\be\n\\item \\(n^H_1, n^T_1\\) which is the number of testing samples assigned \nto the leaf that were labeled heads and tails respectively. The ``weight'' of a\nleaf is \\(n^H_1 + n^T_1\\)\n\\item \\(n^H_0, n^T_0\\) same as above but for the training samples\n\\ee\n\nThese numbers are used follows. Continuing our gambling metaphor,\nthe house is given only \\(n^H_0, n^T_0\\) to set the odds, whereas the gambler\nhas access to all four.\nThe ``true'' probability of heads, \\(\\rho\\), is assumed to be \n\\(\\frac{n^H_1}{n^H_1+ n^T_1}\\). \n\nConsider three examples, in all of which \\(n^H_0, n^T_0 = 60, 40\\). \nThe benefit, \\(b\\) that the gambler can expect to make per trial varies\ndepending on \\(rho\\) as follows.\n\\be\n\\item \\(\\rho = 0.8\\). The adversary would bet heads.\n\\(b = 0.8 \\times \\frac{40}{60} + 0.2 \\times -1 = \\frac{1}{3}\\)\n\\item \\(\\rho = 0.6\\). If the adversary bet heads, \n\\(b = 0.6 \\times \\frac{40}{60} + 0.4 \\times -1 = 0\\)\nIf the adversary bet tails, \n\\(b = 0.6 \\times -1 + 0.4 \\times \\frac{60}{40} = 0\\).\n\\item \\(\\rho = 0.4\\). The adversary would bet tails.\n\\(b = 0.4 \\times -1 + 0.6 \\times \\frac{60}{40} = \\frac{1}{2}\\) \n\\ee\n\nThe weighted benefit of a leaf is simply \\(w \\times b\\).\nThe ``cost'' of the decision tree is sum over the \nweighted benefit, normalized by the weights of all leaves \n\\(= \\frac{\\sum_l w_l \\times b_l}{\\sum_l w_l}\\)\n\n", "meta": {"hexsha": "a442416df877ae3f94725bb2a1a04ceceb378e59", "size": 1624, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ML/DT/doc/old_dt_eval.tex", "max_stars_repo_name": "subramon/qlu", "max_stars_repo_head_hexsha": "2fb8a2b3636dd11e2dfeae2a6477bd130316da47", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ML/DT/doc/old_dt_eval.tex", "max_issues_repo_name": "subramon/qlu", "max_issues_repo_head_hexsha": "2fb8a2b3636dd11e2dfeae2a6477bd130316da47", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2020-07-29T16:48:25.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-26T23:47:22.000Z", "max_forks_repo_path": "ML/DT/doc/old_dt_eval.tex", "max_forks_repo_name": "subramon/qlu", "max_forks_repo_head_hexsha": "2fb8a2b3636dd11e2dfeae2a6477bd130316da47", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-05-14T22:34:13.000Z", "max_forks_repo_forks_event_max_datetime": "2015-05-14T22:34:13.000Z", "avg_line_length": 42.7368421053, "max_line_length": 79, "alphanum_fraction": 0.6785714286, "num_tokens": 551, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715774, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7265916109800906}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath, amssymb, amsfonts, amsthm}\n\\usepackage{bm}\n\\usepackage{color}\n\\newcommand{\\pd}[2]{\\frac{\\partial{#1}}{\\partial{#2}}}\n\n\\numberwithin{equation}{section}\n\\let\\vec\\bm\n\n\\theoremstyle{plain}\n\\newtheorem{thm}{Theorem}\n\\numberwithin{thm}{section}\n\n\\theoremstyle{plain}\n\\newtheorem{prop}{Proposition}\n\\numberwithin{prop}{section}\n\n\\theoremstyle{definition}\n\\newtheorem{defn}{Definition}\n\\numberwithin{defn}{section}\n\n\\theoremstyle{remark}\n\\newtheorem*{rem}{Remark}\n\n\\newtheorem*{cor}{Corollary}\n\n\\title{Hamiltonian Mechanics - A Quick Recapitulation}\n\\author{Amey Joshi}\n\\date{06-Mar-2021}\n\\begin{document}\n\n\\maketitle\n\\abstract{This article summarises the main ideas of Hamiltonian mechanics and\nillustrates them with a few examples.}\n\n\\section{The Hamiltonian function}\\label{s1}\nConsider a system of $n$ degrees of freedom described by the generalised \ncoordinates $q_1, \\ldots, q_n$ and a Lagrangian function $L(q_i, \\dot{q}_i, t)$.\nThe generalised momentum is defined as\n\\begin{equation}\\label{s1e1}\np_i = \\frac{\\partial{L}}{\\partial\\dot{q}_i}.\n\\end{equation}\nThe Legendre-Fenchel transformation of a function $f:X \\rightarrow \n\\mathbf{R}$, where $X \\subset \\mathbf{R}^n$ is defined as\n\\begin{equation}\\label{s1e2}\nf^\\ast(x^\\ast) = \\sup_{x \\in X}\\left((x^\\ast, x) - f(x)\\right), \n\\end{equation}\nfor all $x^\\ast \\in X^\\ast$. The set $X^\\ast$ is \n\\begin{equation}\\label{s1e3}\nX^\\ast = \\left\\{x^\\ast \\in \\mathbf{R}^n : \\sup_{x \\in X}\n         \\left((x^\\ast, x) - f(x)\\right) < \\infty\\right\\}.\n\\end{equation}\nThe expression $(x^\\ast, x)$ is the dot product of $x^\\ast$ and $x$. Let us \nassume that the function $f$ is differentiable and let us define\n\\begin{equation}\\label{s1e4}\nF(x, x^\\ast) = (x^\\ast, x) - f(x).\n\\end{equation}\nThen,\n\\[\n\\frac{\\partial F}{\\partial x_i} = x^\\ast_i - \\frac{\\partial f}{\\partial x_i}\n\\]\nso that the supremum of the set $(x^\\ast, x) - f(x)$ is indeed the maximum\nof the function $F$. In this case, the Legendre-Fenchel transform becomes\n\\begin{equation}\\label{s1e5}\nf^\\ast(x^\\ast) = \\left((x^\\ast, D_x(f)) - f(x)\\right).\n\\end{equation}\nThe symbol $D_x(f)$ stands for the gradient of $f$ with respect to $x$.\n\nThe Lagrangian $L(q_i, \\dot{q}_i, t)$ is assumed to be a differentiable \nthroughout its domain so that its Legendre-Fenchel transformation with respect \nto the variables $\\dot{q}_i^\\ast$ is\n\\begin{equation}\\label{s1e6}\nL^\\ast(q_i, \\dot{q}_i^\\ast, t) = \\sum_{i=1}^n \\dot{q}_i^\\ast \\dot{q}_i - \nL(q_i, \\dot{q}_i^\\ast, t),\n\\end{equation}\nwhere\n\\begin{equation}\\label{s1e7}\n\\dot{q}_i^\\ast = \\frac{\\partial L}{\\partial\\dot{q}_i}.\n\\end{equation}\nThe right hand side is defined, in equation \\eqref{s1e1}, to be the generalised \nmomeumtum $p_i$. Therefore, equation \\eqref{s1e6} is written as\n\\begin{equation}\\label{s1e8}\nL^\\ast(q_i, p_i, t) = \\sum_{i=1}^n p_i\\dot{q}_i - L(q_i, \\dot{q}_i, t).\n\\end{equation}\nThe function $L^\\ast$ is called the Hamiltonian of the system and is denoted\nby $H$.\n\nWhy did we not define the function $H$ as\n\\begin{equation}\\label{s1e9}\nH(q_i, p_i, t) = \\sum_{i=1}^n p_i\\dot{q}_i - L(q_i, \\dot{q}_i, t)?\n\\end{equation}\nWritten in this manner, the right hand side is a function of $q_i, \\dot{q}_i,\np_i$ and $t$. However, the supremum over $x$ in equation \\eqref{s1e2} ensures\nthat the result is function of $x^\\ast$ alone. The differentiability of $L$\nresults in the simple form of $L^\\ast$, (or $H$), and we are also guaranteed\nthat this latter function does not depend on $\\dot{q}_i$\n\\cite{touchette2005legendre}. \n\nFrom equation \\eqref{s1e9} we have\n\\begin{eqnarray}\n\\frac{\\partial{H}}{\\partial q_i} &=& \n  -\\frac{\\partial L}{\\partial q_i} \\label{s1e10} \\\\\n\\frac{\\partial{H}}{\\partial p_i} &=& \\dot{q}_i \\label{s1e11}.\n\\end{eqnarray}\nSince the Lagrangian $L$ satisfies the Euler-Lagrange equation\n\\begin{equation}\\label{s1e12}\n\\frac{\\partial L}{\\partial q_i} = \\frac{d}{dt}\n\\frac{\\partial L}{\\partial\\dot{q}_i} = \\dot{p}_i,\n\\end{equation}\nthe pair of equations \\eqref{s1e10} and \\eqref{s1e11} become\n\\begin{eqnarray}\n\\frac{\\partial{H}}{\\partial q_i} &=& -\\dot{p}_i \\label{s1e13} \\\\\n\\frac{\\partial{H}}{\\partial p_i} &=& \\dot{q}_i. \\label{s1e14}\n\\end{eqnarray}\nThese are Hamilton's canonical equations.\n\n\\section{The physical significance of the Hamiltonian function}\\label{s2}\nLet us assume that our system can also be described using $N$ cartesian\ncoordinates\n\\begin{equation}\\label{s2e1}\nx_i = x_i(q_1, \\ldots, q_n), i = 1, \\ldots, N.\n\\end{equation}\nWe can then write\n\\begin{equation}\\label{s2e2}\n\\dot{x}_i = \\sum_{j=1}^n\\frac{\\partial x_i}{\\partial q_j}\\dot{q}_j.\n\\end{equation}\nIf $m_i$ is the mass associated with the coordinate $x_i$ then its kinetic \nenergy is\n\\begin{equation}\\label{s2e3}\nT = \\frac{1}{2}\\sum_{i=1}^N m_i\\dot{x}_i^2 = \n\\sum_{j,k=1}^n \\alpha_{j,k}\\dot{q}_j\\dot{q}_k,\n\\end{equation}\nwhere\n\\begin{equation}\\label{s2e4}\n\\alpha_{j, k} = \\sum_{i=1}^N m_i\\frac{\\partial x_i}{\\partial q_j}\n\\frac{\\partial x_i}{\\partial q_k}\n\\end{equation}\nis a function of $q_j, q_k$ alone.\n\\begin{prop}\\label{s2p1}\n$T$ is a homogeneous function of the generalised velocities.\n\\end{prop}\n\\begin{proof}\n\\[\nT(q_1, \\ldots, q_n, \\lambda\\dot{q}_1, \\ldots, \\lambda\\dot{q}_n) = \n\\lambda^2 T(q_1, \\ldots, q_n, \\dot{q}_1, \\ldots, \\dot{q}_n).\n\\]\n\\end{proof}\nBy Euler's theorem on homogeneous functions,\n\\begin{equation}\\label{s2e5}\n\\sum_{i=1}^n \\dot{q}_i\\frac{\\partial T}{\\partial\\dot{q}_i} = 2T.\n\\end{equation}\n\\begin{prop}\\label{s2p2}\nIf the potential energy of the system is independent of the generalised\nvelocities and time then\n\\[\n\\sum_{i=1}^n \\dot{q}_ip_i = 2T.\n\\]\n\\end{prop}\n\\begin{proof}\nWe can write the Lagrangian as\n\\[\nL(q_i, \\dot{q}_i) = T(q_i, \\dot{q}_i) - V(q_i)\n\\]\nso that\n\\[\n\\frac{\\partial L}{\\partial\\dot{q}_i} = \\frac{\\partial T}{\\partial\\dot{q}_i}.\n\\]\nThe proposition follows from the above equation and \\eqref{s1e1}.\n\\end{proof}\n\\begin{rem}\nThe Lagrangian of a point mass descending in a column of viscous fluid is\n\\begin{equation}\\label{s2e6}\nL = \\exp\\left(\\frac{\\gamma t}{m}\\right)\\left(\\frac{m\\dot{x}^2}{2} - U(x)\\right),\n\\end{equation}\nwhich is not of the form $T - V$. \n\nThe Lagrangian of a particle of charge $q$ and mass $m$ in an electromagnetic\nfield is \n\\begin{equation}\\label{s2e7}\nL = \\frac{1}{2}mv^2 + q\\vec{A}\\cdot\\vec{v} - q\\phi,\n\\end{equation}\nwhere $\\vec{A}$ and $\\phi$ are the vector and scalar potentials of the fields.\nNeither is this function a difference of the kinetic energy $mv^2/2$ and \nthe potential energy $q\\phi$.\n\\end{rem}\n\n\\begin{prop}\\label{s2p3}\nIf the potential energy of the system is independent of the generalised\nvelocities and time then $H = T + V$.\n\\end{prop}\n\\begin{proof}\nThe Lagrangian can be written as $L(q_i, \\dot{q}_i) = T(q_i, \\dot{q}_i)\n- V(q_i)$. The proposition follows from this form of the Lagrangian, the\ndefinition \\eqref{s1e9} of the Hamiltonian and proposition \\ref{s2p2}.\n\\end{proof}\n\n\\begin{prop}\\label{s2p4}\nIf the Lagrangian is independent of time then the Hamiltonian is a constant\nof motion.\n\\end{prop}\n\\begin{proof}\n\\[\n\\frac{dH}{dt} = \\sum_{i=1}^n\\dot{p}_i\\dot{q}_i + \\sum_{i=1}^np_i\\ddot{q}_i\n- \\sum_{i=1}^n\\frac{\\partial L}{\\partial q_i}\\dot{q}_i \n- \\sum_{i=1}^n\\frac{\\partial L}{\\partial\\dot{q}_i}\\ddot{q}_i = 0.\n\\]\n\\end{proof}\n\nFrom propositions \\ref{s2p3} and \\ref{s2p4} it follows that\n\\begin{thm}\\label{s2t1}\nIf a system can be described the Lagarangian of the form\n\\[\nL(q_i, \\dot{q}_i) = T(q_i, \\dot{q}_i) - V(q_i)\n\\]\nthen the Hamiltonian of the system is the total energy of the system and it\nis a constant.\n\\end{thm}\n\n\\section{The phase space}\\label{s3}\nA system with $n$ degrees of freedom can be described by $n$ generalised\ncoordinates $q_1, \\ldots, q_n$. Its behaviour can be described either by the\nLagrangian $L(q_i, \\dot{q}_i, t)$ or the Hamiltonian $H(q_i, p_i, t)$. In\nthe former case, the system can be represented as a point in a \n$n+1$-dimensional configuration space whose coordinates as $q_1, \\ldots, q_n, t$\nor a $2n+1$-dimensional phase space whose coordinates are $q_1, \\ldots, q_n,\np_1, \\ldots, p_n, t$.\n\nThe motion of the system appears as a curve in either the configuration space\nor the phase space. The benefit of the phase space is that the curves \nrepresenting the motion of the system do not cross each other. For if they did\nthen at the point of intersection the system will have two possible ways of\nevolution.\n\nConsider an ensemble of systems represented by the \\emph{same} Hamiltonian. \nEach of these is represented by a point in the phase space. If $\\rho$ is the\nnumber density of the systems then it satisfies the equation of continuity,\n\\begin{equation}\\label{s3e1}\n\\frac{\\partial\\rho}{\\partial t} + \n\\sum_{j=1}^n\\frac{\\partial(\\rho\\dot{q}_j)}{\\partial q_j} + \n\\sum_{j=1}^n\\frac{\\partial(\\rho\\dot{p}_j)}{\\partial p_j} = 0\n\\end{equation}\nanalogous to the equation of continuity of a fluid of density $\\rho_m$ and\nmoving with a velocity $\\vec{v}$,\n\\begin{equation}\\label{s3e2}\n\\frac{\\partial\\rho_m}{\\partial t} + \\nabla\\cdot(\\rho_m\\vec{v}) = 0.\n\\end{equation}\nEquation \\eqref{s3e1} can be written as\n\\begin{equation}\\label{s3e3}\n\\frac{\\partial\\rho}{\\partial t} + \n\\sum_{j=1}^n\\frac{\\partial\\rho}{\\partial q_j} \\dot{q}_j + \n\\sum_{j=1}^n\\frac{\\partial\\rho}{\\partial p_j} \\dot{p}_j + \n\\rho\\left(\\sum_{j=1}^n\\frac{\\partial\\dot{q}_j}{\\partial q_j} + \n\\sum_{j=1}^n\\frac{\\partial\\dot{p}_j}{\\partial p_j}\\right)  = 0\n\\end{equation}\nThe last term vanishes because of Hamilton's equations \\eqref{s1e13} and\n\\eqref{s1e14} while the first three terms can be combined as the total\ntime derivative of $\\rho$ giving us\n\\begin{equation}\\label{s3e4}\n\\frac{d\\rho}{dt} = 0.\n\\end{equation}\nThus, the ensemble of systems all described by the same Hamiltonian moves in the\nphase space like an incompressible fluid.\n\n\\section{Canonical transformation}\\label{s4}\nConsider the transformations\n\\begin{eqnarray}\nq^\\ast_i &=& q^\\ast_i(q_1, \\ldots, q_n, p_1, \\ldots, p_n) \\label{s4e1} \\\\\np^\\ast_i &=& p^\\ast_i(q_1, \\ldots, q_n, p_1, \\ldots, p_n) \\label{s4e2}\n\\end{eqnarray}\nfor all $i = 1, \\ldots, n$, $n$ being the number of degrees of freedom of the\nsystem. The form of the Hamiltonian is may not remain the same as a result of\nthese transformations. However, $H(q_i, p_i, t) \\mapsto H^\\ast(q^\\ast_i, \np^\\ast_i, t)$ and if\n\\begin{eqnarray}\n\\frac{\\partial H^\\ast}{\\partial q^\\ast_i} &=& -\\dot{p}^\\ast_i \\label{s4e3} \\\\\n\\frac{\\partial H^\\ast}{\\partial p^\\ast_i} &=&  \\dot{q}^\\ast_i \\label{s4e4}\n\\end{eqnarray}\nthen the transformations \\eqref{s4e1} and \\eqref{s4e2} are called \\emph{\ncanonical transformations}. Canonically transformed variables obey canonical\nequations of motions.\n\nThe simplest canonical transformations are the point transformations\n\\begin{eqnarray}\nq^\\ast_i &=& q^\\ast_i(q_1, \\ldots, q_n, t)\\label{s4e5} \\\\\np^\\ast_i &=& \\frac{\\partial L}{\\partial \\dot{q}^\\ast_i} \\label{s4e6}\n\\end{eqnarray}\nThe next simplest canonical transformation are\n\\begin{eqnarray}\nq^\\ast_i &=& p_i \\label{s4e7} \\\\\np^\\ast_i &=& q_i \\label{s4e8}\n\\end{eqnarray}\n\nThe system can as well be described by the two Lagrangians\n\\begin{eqnarray}\nL(q_i, \\dot{q}_i, t) &=& \\sum_{i=1}^n p_i\\dot{q}_i - H(q_i, p_i, t)\n\\label{s4e9} \\\\\nL^\\ast(q^\\ast_i, \\dot{q}^\\ast_i, t) &=& \\sum_{i=1}^n p^\\ast_i\\dot{q}^\\ast_i - \nH(q^\\ast_i, p^\\ast_i, t) \\label{s4e10}\n\\end{eqnarray}\neach one of which satisfies the action principle. That is\n\\begin{eqnarray}\n\\delta\\int_{t_1}^{t_2} L(q_i, \\dot{q}_i, t)dt &=& 0 \\label{s4e11} \\\\\n\\delta\\int_{t_1}^{t_2} L^\\ast(q^\\ast_i, \\dot{q}^\\ast_i, t)dt &=& 0 \\label{s4e12}\n\\end{eqnarray}\nFrom equations \\eqref{s4e11} and \\eqref{s4e12} we infer that the two\nLagrangians are related as\n\\begin{equation}\\label{s4e13}\nL(q_i, \\dot{q}_i, t) = L^\\ast(q^\\ast_i, \\dot{q}^\\ast_i, t) + \\frac{dF}{dt},\n\\end{equation}\nfor some function $F$. Equivalently, we can write\n\\begin{equation}\\label{s4e14}\n\\sum_{i=1}^n p_i\\dot{q}_i - H(q_i, p_i, t) = \n\\sum_{i=1}^n p^\\ast_i\\dot{q}^\\ast_i - H^\\ast(q^\\ast_i, p^\\ast_i, t) +\n\\frac{dF}{dt}.\n\\end{equation}\nOn rearranging and writing it in terms or differentials,\n\\begin{equation}\\label{s4e15}\n\\sum_{i=1}^n(p_i dq_i - p^\\ast_i dq^\\ast_i) = H^\\ast dt - Hdt + dF.\n\\end{equation}\n\nThe function $F$ in \\eqref{s4e14} is called the \\emph{generating function}. One\nmight think that it depends on all $4n$ variables $q_i, p_i, q_i^\\ast, p_i^\\ast$\n. However, there are $2n$ equations relating the two. Therefore, only half of\nthem are independent. Therefore, we choose it to depend on one `old' and one \n`new' coordinate. Thus, the four possibilities are\n\\begin{eqnarray}\nF = F(q_i, q_i^\\ast) \\label{s4e16} \\\\\nF = F(q_i, p_i^\\ast) \\label{s4e17} \\\\\nF = F(p_i, q_i^\\ast) \\label{s4e18} \\\\\nF = F(p_i, p_i^\\ast) \\label{s4e19} \n\\end{eqnarray}\nAssume that $F$ is of the form \\eqref{s4e17} in equation \\eqref{s4e15} to get\n\\begin{equation}\\label{s4e20}\n\\sum_{i=1}^np_idq_i - Hdt = \\sum_{i=1}^np^\\ast_idq^\\ast_i - H^\\ast dt + \ndF(q_i, p_i^\\ast).\n\\end{equation}\nRearrange it as\n\\[\n\\sum_{i=1}^n(p_idq_i + q_i^\\ast dp^\\ast_i) + (H^\\ast - H)dt = \nd\\left(\\sum_{i=1}^n p_i^\\ast q_i^\\ast\\right) + dF(q_i, p_i^\\ast)\n\\]\nLet\n\\begin{equation}\\label{s4e21}\nS = \\sum_{i=1}^n p_i^\\ast q_i + F\n\\end{equation}\nthen we have\n\\begin{equation}\\label{s4e22}\n\\sum_{i=1}^n(p_idq_i + q_i^\\ast dp^\\ast_i) + (H^\\ast - H)dt = dS.\n\\end{equation}\nThe left hand side suggest that $S$ can be considered to be a function of\n$q_i, p_i^\\ast, t$ and\n\\begin{eqnarray}\np_i &=& \\pd{S}{q_i} \\label{s4e23} \\\\\nq_i^\\ast &=& \\pd{S}{p_i^\\ast} \\label{s4e24} \\\\\nH^\\ast - H &=& \\pd{S}{t} \\label{s4e25}\n\\end{eqnarray}\nIf we can find a transformation that can lead to $H^\\ast = 0$, we get\n\\begin{equation}\\label{s4e26}\n\\pd{S}{t} + H\\left(q_i, p_i, t\\right) = 0\n\\end{equation}\nor, using equation \\eqref{s4e23}\n\\begin{equation}\\label{s4e27}\n\\pd{S}{t} + H\\left(q_i, \\pd{S}{q_i}, t\\right) = 0.\n\\end{equation}\nThis is Hamilton-Jacobi equation.\n\nBefore we proceed for a more detailed consideration of the Hamilton-Jacobi\nequation we will remark on why canonical transformations are interesting. If\nwe are able to find $q_i^\\ast$ such that $H^\\ast$ does not depend on any one\nof them then all the conjugate momenta $p_i^\\ast$ are constant because\n\\begin{equation}\\label{s4e28}\np_i^\\ast = \\pd{H^\\ast}{q_i^\\ast} = 0.\n\\end{equation}\nIf we call the constant momenta\n\\begin{equation}\\label{s4e29}\np_i^\\ast = \\beta_i\n\\end{equation}\nthen\n\\begin{equation}\\label{s4e30}\nq_i^\\ast = \\pd{H^\\ast}{p_i^\\ast} = \\pd{H^\\ast}{\\beta_i} = \\alpha_i,\n\\end{equation}\nanother constant. As a result,\n\\begin{equation}\\label{s4e31}\nq_i^\\ast(t) = \\alpha_i t + q_i^\\ast(0).\n\\end{equation}\n\n\\section{Hamilton-Jacobi equation}\\label{s5}\nThe Hamilton-Jacobi equation is a first order partial differential equation\nin the unknown $S$ considered to be a real-valued function of $n+1$ variables\n$q_1, \\ldots, q_n$ and $t$. However, we had assumed $S$ to be a function of\n$2n + 1$ variables $q_1, \\ldots, q_n, p_1^\\ast, \\ldots, p_n^\\ast$ and $t$.\nWe reconcile these facts by noting that the solution of \\eqref{s4e27} will\nhave $n + 1$ constants of which one is additive while the rest are not. We\nignore the additive constant and express the solution as $S(q_1, \\ldots, q_n,\n\\beta_1, \\ldots, \\beta_n, t)$. Thus,\n\\begin{equation}\\label{s5e1}\np_i^\\ast = \\beta_i.\n\\end{equation}\nTherefore, from equations \\eqref{s4e23} and \\eqref{s4e24} we get\n\\begin{eqnarray}\np_i &=& \\pd{S}{q_i} \\label{s5e2} \\\\\nq_i^\\ast &=& \\pd{S}{\\beta_i} \\label{s5e3}\n\\end{eqnarray}\nSince $H^\\ast = 0$, $q_i^\\ast$ and $p_i^\\ast$ are both constants. Let us set\n\\begin{equation}\\label{s5e4}\nq_i^\\ast = \\gamma_i,\n\\end{equation}\nso that $q_i$ can be evaluated in terms of the constants $\\beta_i, \\gamma_i$ \nand $t$. We will illustrate the use of Hamilton-Jacobi equation with an example.\n\n\\subsection{Simple harmonic oscillator}\nThe Hamiltonian of this conservative system is\n\\begin{equation}\\label{s5e5}\nH = \\frac{p^2}{2m} + \\frac{kq^2}{2},\n\\end{equation}\nwhere $m$ is mass of the oscillator and $k$ is the spring constant. The \nHamilton-Jacobi equation is\n\\begin{equation}\\label{s5e6}\n\\pd{S}{t} + H\\left(q, \\pd{S}{q}\\right) = 0.\n\\end{equation}\nNote that the Hamiltonian of a harmonic oscillator is independent of $t$.\nLet us assume $S$ to be of the form $S(q, t) = S_1(q) + F(t)$. (Recall that\nin the Hamilton-Jacobi equation $S$ is assumed to be a function of the $n+1$\nvariables $q_1, \\ldots, q_n$ and $t$.) We thus have\n\\[\n\\pd{F}{t} = -H\\left(q, \\pd{S}{q}\\right).\n\\]\nThe left hand side depends only on $t$ and the right hand side only on $q$, \neach side can be equated to a constant $-E$, the total energy of the system.\nThus,\n\\begin{equation}\\label{s5e7}\nF = -\\beta t\n\\end{equation}\nwhere we ignore the additive constant. Now consider\n\\begin{equation}\\label{s5e8}\nH\\left(p, \\pd{S_1}{q}\\right) = \\beta.\n\\end{equation}\nUse the form of Hamiltonian in equation \\eqref{s5e5} to get\n\\begin{equation}\\label{s5e9}\n\\frac{1}{2m}\\left(\\pd{S_1}{q}\\right)^2 + \\frac{kq^2}{2} = \\beta.\n\\end{equation}\nThe solution of this equation is\n\\begin{equation}\\label{s5e10}\nS_1(q) = \\int\\sqrt{2m\\beta - kmq^2}dq \n\\end{equation}\nThe function $S(q, t)$ is thus,\n\\begin{equation}\\label{s5e11}\nS(q, t) = \\int\\sqrt{2m\\beta - kmq^2}dq - \\beta t.\n\\end{equation}\nNow,\n\\begin{equation}\\label{s5e12}\nq^\\ast = \\pd{S}{\\beta} = m\\int\\frac{dq}{\\sqrt{2m\\beta - kmq^2}} - t.\n\\end{equation}\nBut $q^\\ast$ is another constant, say $\\gamma/\\omega$, where\n\\begin{equation}\\label{s5e13}\n\\omega^2 = \\frac{k}{m}\n\\end{equation}\nso that\n\\[\nm\\int\\frac{dq}{\\sqrt{2m\\beta - kmq^2}} = \\frac{\\gamma}{\\omega} + t.\n\\]\nThe integral can be readily evaluated to get\n\\begin{equation}\\label{s5e14}\nq = \\sqrt{\\frac{2\\beta}{k}}\\sin(\\omega t + \\gamma).\n\\end{equation}\n\n\\section{Action-angle variables}\\label{s6}\nIf a conservative system is periodic then we define an `action variable' as\n\\begin{equation}\\label{s6e1}\nJ_i = \\oint p_idq_i.\n\\end{equation}\nThe time independent Hamilton-Jacobi equation is\n\\begin{equation}\\label{s6e2}\nH\\left(q_i, \\pd{S}{q_i}\\right) = E.\n\\end{equation}\nWe can write the solution of this equation as\n\\begin{equation}\\label{s6e3}\nS(q_1, \\ldots, q_n, \\beta_1, \\ldots, \\beta_n) = \n\\sum_{i=1}^n S_i(q_i, \\beta_1, \\ldots, \\beta_n).\n\\end{equation}\nNow,\n\\begin{equation}\\label{s6e4}\nJ_i = \\oint p_i dq_i = \\oint \\pd{S}{q_i}dq_i = \\oint \\frac{dS_i}{dq_i}dq_i.\n\\end{equation}\nFrom \\eqref{s6e3} and \\eqref{s6e4} it is clear that $J_i$ are a function of\n$\\beta_1, \\ldots, \\beta_n$. Thus,\n\\begin{equation}\\label{s6e5}\nJ_i = J_i(\\beta_1, \\ldots, \\beta_n)\n\\end{equation}\nwhich can be inverted so that\n\\begin{equation}\\label{s6e6}\n\\alpha_i = \\alpha_i(J_1, \\ldots, J_n).\n\\end{equation}\nWe can then write equation \\eqref{s6e3} as\n\\begin{equation}\\label{s6e7}\nS = S(q_1, \\ldots, q_n, J_1, \\ldots, J_n).\n\\end{equation}\nEquations \\eqref{s5e2} and \\eqref{s5e3} now become\n\\begin{eqnarray}\np_i &=& \\pd{S}{q_i} \\label{s6e8} \\\\\nq_i^\\ast &=& \\pd{S}{J_i} \\label{s6e9}\n\\end{eqnarray}\nFrom equation \\eqref{s4e25}\n\\begin{equation}\\label{s6e10}\nH^\\ast = H = E(J_1, \\ldots, J_n).\n\\end{equation}\nNow,\n\\begin{equation}\\label{s6e11}\n\\dot{p}_i^\\ast = -\\pd{H^\\ast}{q_i^\\ast} = 0\n\\end{equation}\nbut\n\\begin{equation}\\label{s6e12}\n\\dot{q}_i^\\ast = \\pd{H^\\ast}{p_i^\\ast} = \\pd{H^\\ast}{J_i}\n\\end{equation}\nbecause we regard $\\beta_i$, or equivalently $J_i$, as $p_i^\\ast$. From\n\\eqref{s6e10},\n\\begin{equation}\\label{s6e13}\n\\dot{q}_i^\\ast = \\pd{E}{J_i} = \\nu_i,\n\\end{equation}\na constant, from which we readily get\n\\begin{equation}\\label{s6e14}\nq_i^\\ast = \\nu_i t + \\alpha_i,\n\\end{equation}\n$\\alpha_i$ being a constant of integration. Traditionally, $q_i^\\ast$ are\ndenoted by $\\omega_i$ so that equation \\eqref{s6e15} becomes\n\\begin{equation}\\label{s6e15}\n\\omega_i = \\nu_i t + \\alpha_i.\n\\end{equation}\n$\\omega_i$ are called the angle variables corresponding to $J_i$, the action\nvariables.\n\n\\bibliographystyle{plain}\n\\bibliography{hm}\n\\end{document}\n", "meta": {"hexsha": "b038ecc00f7fdb38997c7d603d30902f732a746b", "size": 19737, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cm/hm/hm.tex", "max_stars_repo_name": "amey-joshi/physics", "max_stars_repo_head_hexsha": "66ae9bf4a363bd32b09df22a049e281953adb39b", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cm/hm/hm.tex", "max_issues_repo_name": "amey-joshi/physics", "max_issues_repo_head_hexsha": "66ae9bf4a363bd32b09df22a049e281953adb39b", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cm/hm/hm.tex", "max_forks_repo_name": "amey-joshi/physics", "max_forks_repo_head_hexsha": "66ae9bf4a363bd32b09df22a049e281953adb39b", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.891588785, "max_line_length": 80, "alphanum_fraction": 0.698130415, "num_tokens": 7434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.8311430415844385, "lm_q1q2_score": 0.7264832227200023}}
{"text": "\\chapter{Background}\\label{chap:background}\nThe following work is based on the book Reinforcement Learning:\nAn Introduction\\cite{Sutton1998} from Richard S. Sutton and Andrew G. Barto\n\\section{Markov Decision Processes}\nThe Markov Decision Process (MPD)  is the mathematical framework of Reinforcement Learning and\nis defined as a tuple < $\\mathcal{S, A, R, T, }$ >\n\\begin{itemize}\n\\item $\\mathcal{S}$ is a number of states, s $\\in \\mathcal{R}^{n}$\n\\item $\\mathcal{A}$ is a of actions, a $ \\in \\mathcal{R}^{n}$\n\\item $\\mathcal{T}$ is the transition probability function\n\\item $\\mathcal{R}$ is the reward\n\\end{itemize}\n\n\nEvery state in a Markov Decision Process needs satisfy the Markov Property.\nThis means that \"The future is independent of the past given the present\".\nThe definition is given by an State Reward pair as \n\n\n\\begin{equation}\n\\mathcal{P}(S_{t+1}, R_{t+1}) | S_{t}, R_{t}) =  \\mathcal{P}(S_{t+1}, R_{t+1}) | S_{t+1}, R_{t+1}, S_{t+1}, R_{t+1})\n\\end{equation}\n\nUnfortunately for most real-world problem this assumption is violated. This is also the case for the\nstate transition function, which is definite as\n\n\\begin{equation}\n  \\mathcal{P}(S_{t+1}| R_{t+1}) | s_{t}, a_{t}) =  \\mathcal{P}(S_{t+1}| S_{t} = s ,  A_{t} = a)\n\\end{equation}\n \nThe Reward is a function of state action pairs\n\\begin{equation}\n  \\mathcal{P}(S_{t+1}| R_{t+1}) | s_{t}, a_{t}) =  \\mathcal{P}(S_{t+1}| S_{t} = s ,  A_{t} = a)\n\\end{equation}\n \nThe goal of the agent is to find the policy that maximizes the total reward.\nThis policy is a function that maps states to actions in the deterministic case.\nWhile a stochastic policy has a certain probability to choose an action in a state.\nFor any MDP there is always at least one optimal policy. \nIn case the transition probability is given, the dynamic programming-based Value Iteration  Algorithm is one way to compute this policy.\nWhich is build upon the concept of a Value Function.\n\n\n\\subsection{Value Function}\nThe value function $V^{\\pi}$ : $\\mathcal{S}$ $\\rightarrow$ $\\mathcal{R}$, represents expeceted total reward of a policy in a given state and following the policy\nIt is defined as follows,\n \n\\begin{equation}\n  \\begin{aligned}\n    V^{\\pi}(s) &= \\mathbb{E}_{\\pi} [R_t | s_t = s] \\\\\n    &= \\mathbb{E}_{\\pi} [\\sum^{\\infty}_{k=0} \\gamma^{k} r_{t+k+1} | s_t = s] \\label{MDP:eq1} \\\\\n    &= \\sum_{a \\in \\mathcal{A}} \\pi(s, a) \\sum_{s' \\in \\mathcal{S}} \\mathcal{T}^{a}_{ss'}[\\mathcal{R}^{a}_{ss'} + \\gamma V^\\pi(s')]\n  \\end{aligned}\n\\end{equation}\n\n\nOne way to find the optimal policy is the value Iteration Algorithm.\nIn each Iteration the value function is updated by the following equation,\n\n\\begin{equation}\n  V_{i+1}(s) := \\max_a \\Big\\{ \\sum_{s', r} P(s',r| s,a) (r + \\gamma V_i(s')) \\Big\\}\n\\end{equation}\n\n\n\\subsection{Q Function}\n\nIn many real-world problems, the transition function is unknown, and approximate the Value function is not feasible, because\nit would require evaluating all possible actions in a single state every time step.\nIn this case the Q-value function helps by using the state action pair\n\n\n\\begin{equation}\n  Q(s_t, a_t) \\leftarrow Q(s_t, a_t) + \\alpha[r_{t+1} + \\gamma \\max_a Q(s_{t+1}, a) - Q(s_t, a_t)]\n\\end{equation}\n\n\nThis update equation is used to find an optimal policy in the Q-Learning Algorithm, repesened in Algorithm \\ref{alg:q-learning}\n\n\\input{figures/background/Q-learning.tex}\n\n\nThe fact that the policy for interacting with the environment is different from the one to update the Q-value Function makes it to an off-policy Algorithm\n\n\n\\section{Neural Network}\n\nIn complex environments, the state space is continuous, which makes it infeasible to use to store all state-action pairs in a table.\nAdvances in machine learning especially in deep learning make it possible to approximate this Q function.  \nA basic element of Deep learning is artificial neural networks which are inspired by the human brain.\nNeural network have a structure of input layer connected to hidden layers followed by the output layer. \nA standard Network has linear many hidden layers represented as nodes. The nodes between different layers are connected by weights. \nThe values of the weights can be trained iteratively by using an optimization  technique like stochastic gradient descent and backpropagation.\nThis simple architecture could be seen as matrix multiplications which makes it a linear function. \nBy adding nonlinear activation functions it is able to approximate more complex nonlinear functions.\n\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.5\\textwidth]{figures/background/nn.png}\n  \\caption{Deep Neural Network with several hidden layers}\n  \\label{fig:tab-training}\n\\end{figure}\n\n\n", "meta": {"hexsha": "f3e8d4aec71cdf8227e2b5819fe815876efbc002", "size": 4677, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/3-background.tex", "max_stars_repo_name": "ChrisProgramming2018/bachelorThesisLatex", "max_stars_repo_head_hexsha": "46ca9c643797dea09c11d72cc95fbe85e35b169b", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/3-background.tex", "max_issues_repo_name": "ChrisProgramming2018/bachelorThesisLatex", "max_issues_repo_head_hexsha": "46ca9c643797dea09c11d72cc95fbe85e35b169b", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/3-background.tex", "max_forks_repo_name": "ChrisProgramming2018/bachelorThesisLatex", "max_forks_repo_head_hexsha": "46ca9c643797dea09c11d72cc95fbe85e35b169b", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.5428571429, "max_line_length": 161, "alphanum_fraction": 0.7335899081, "num_tokens": 1311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7264776455201085}}
{"text": "\\section{Methodology}\n\n\\subsection{Echo State Networks}\nAn ``echo state network'' (also\ncalled a ``liquid state machine'' \\cite{lukosevicius_practical_2012}) is a type\nof recurrent neural network that uses a single layer of many neurons called a\n``reservoir''. The reservoir has an adjacency matrix $\\bm{A}$ that is\n\\begin{enumerate}\n\t\\item sparsely populated\n\t\\item connected by uniformly random weights centered at zero\n\t\\item has a large number of neurons\n\\end{enumerate}\nA reservoir computer also satisfies the \\textit{echo state property}\n\\cite{pathak_model-free_2018, lukosevicius_reservoir_2009}. This\nproperty ensures that a system's state has a decaying influence on future states\n(like an echo of sound or ripples on water). This property is satisfied in most\ncases when the spectral radius (the absolute value of the greatest eigenvalue of\n$\\bm{A}$)\\cite{lukosevicius_reservoir_2009} is,\n\\begin{align}\n\t\\rho(\\bm{A}) < 1.\n\\end{align}\nHowever, the echo state property can still be satisfied for a spectral radius\ngreater than unity \\cite{lukosevicius_practical_2012}.\n\n\\begin{figure}[H]\n\t\\includegraphics[width=\\columnwidth]{reservoir_network.jpg}\n\t\\caption{A basic reservoir computer or echo state network. The connections in\n\tthe reservoir are given by $\\bm{A}$}\n\t\\label{fig:RCmodel}\n\\end{figure}\n\nFigure \\ref{fig:RCmodel} gives a visual representation of a basic\n\\acrshort{ESN}. An\ninput vector of length \\textit{K} is mapped to the reservoir layer by an input\nweight matrix $\\bm{W_{in}}$. The state of the reservoir is mapped to an output\nlayer of length \\textit{N} with an output weight matrix $\\bm{W_{out}}$. An ESN\ndoes not require $K=N$, nor does it require $K \\neq N$. In this\nwork, the input vector is a function of time, $\\bm{u}(t)$, and the output\nvector is the next state of the system, $\\bm{u}_p(t+\\Delta t)$. Ideally, the\ndifference between the prediction, $\\bm{u}_p$, and the actual, $\\bm{u}_a$, is\nminimized. During training, the output weight matrix is trained through\nbackpropagation using a loss function like cross entropy\n\\cite{pathak_model-free_2018, vlachas_backpropagation_2020}.\n\n\\subsection{Hyperparameter Search}\nDue to the architecture of \\acrshort{ESN}s, the weights and connections\ninside the reservoir do not need to be trained and, in our choice of\nimplementation, cannot be. This dramatically reduces the training time because\nonly the linear output layer needs to be trained. One drawback of this approach\nis its sensitivity to hyperparameters, which must be carefully chosen before\nrunning the network \\cite{ pathak_model-free_2018,\nlukosevicius_practical_2012, lukosevicius_reservoir_2009,gallicchio_deep_2019}.\nHere, we perform grid searches\nto establish which combination of hyperparameters minimizes the mean squared\nerror of the model,\n\\begin{align}\n\tMSE &= \\frac{1}{N}\\sum_i^N (\\hat{y} - y_i)^2\\\\\n\t\\intertext{where}\n\t\\hat{y} &= \\mbox{the average value of the ouput.}\\nonumber\n\\end{align}\n\n\\subsection{Model Prediction}\nThe weights of the output layer, $\\bm{W_{out}}$, are\ntrained through backpropagation by minimizing the error. When a trained model\nis given some initial state and then makes a prediction, $\\bm{u}_p(t+\\Delta\nt)$, this prediction becomes the initial state for the next prediction and so\non. Even a good model, like in Pathak et. al \\cite{pathak_model-free_2018}, has\nsome propagating error that deteriorates the prediction fidelity.\n", "meta": {"hexsha": "7f853aa04e33d89c9b62c8b15d281f5618943eb9", "size": 3401, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "publications/abstracts/reservoir-computing-abs/methodology.tex", "max_stars_repo_name": "datw0258/2020-dotson-optimal-sizing", "max_stars_repo_head_hexsha": "6d27cf722c15e9f41a14848d32824a0db7d229bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "publications/abstracts/reservoir-computing-abs/methodology.tex", "max_issues_repo_name": "datw0258/2020-dotson-optimal-sizing", "max_issues_repo_head_hexsha": "6d27cf722c15e9f41a14848d32824a0db7d229bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-06-03T14:42:31.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-03T14:42:31.000Z", "max_forks_repo_path": "publications/abstracts/reservoir-computing-abs/methodology.tex", "max_forks_repo_name": "datw0258/2020-dotson-optimal-sizing", "max_forks_repo_head_hexsha": "6d27cf722c15e9f41a14848d32824a0db7d229bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.2898550725, "max_line_length": 80, "alphanum_fraction": 0.7800646869, "num_tokens": 916, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.7879311981328134, "lm_q1q2_score": 0.7264109725415535}}
{"text": "\\input{preamble.tex}\n\\title{String Quantization}\n\n\n\\begin{document}\n\\maketitle \n\n\\section{Discrete phonons}\n\nSuppose we have a chain of masses m, each linked by a string of length a.\nEach mass can be displaced about the equilibrium position vertically, by an amount\n\\(x_n\\).\n\nThen we have the following equations of motion:\n\n\\[m \\ddot{x_n} = k \\left(x_{n+1} + x_{n-1}\\right) - 2 k x_n\\]\n\nWe can work in the fourier basis, which decouples the motion of the masses into modes of vibrations labelled\nby the wavenumber \\(q \\in (-\\frac{\\pi}{2}, \\frac{\\pi}{2})\\):\n\n\n\\begin{align}\n    & x_q = e^{i(qan-\\omega(q) t)}\\\\\n    & \\omega_q^2 = -2k/m \\cos(qa)- 2k/m\n\\end{align}\n\n\\subsection{Lagrangian and Hamiltonian Style}\n\nIt is nice to work in the Lagrangian and Hamiltonian scheme in preparation for quantization.\nLet's set up a finite string of N masses, each mass m, separated by distance l in equilibrium. \nThe displacement of the ith mass is \\(\\phi_i\\).\n\nThe Hamiltonian is KE +PE:\n\n\\begin{align}\n    & H = \\frac12 \\sum_{i = 0}^{N-1} ( m(\\dot{\\phi_i}^2) + k (\\phi_i- \\phi_{i-1})^2) \\\\\n    & \\frac12 \\sum_{i = 0}^{N-1} l \\left( \\frac{m}{l} \\dot{\\phi_i}^2 + k l^2 (\\phi_i - \\phi_{i-1}/l)^2 \\right)\n\\end{align}\n\nThe lagrangian is:\n\n\\begin{align}\n    & L = \\frac12 \\sum_{i = 0}^{N-1} ( m(\\dot{\\phi_i}^2) - k (\\phi_i- \\phi_{i-1})^2) \\\\\n    & \\frac12 \\sum_{i = 0}^{N-1} \\left(l \\frac{m}{l} \\dot{\\phi_i}^2 - k l^2 (\\phi_i - \\phi_{i-1}/l)^2 \\right))\n\\end{align}\n\n\nIn the limit N goes to infinity, l to 0 , we can define the ratio: \\(l/m = \\mu\\), \\(kl = T\\).\nThe lagrangian density, \\(\\mathcal{L} = L/l\\):\n\n\\begin{align}\n    & \\mathcal{L} = \\int dx  \\frac12 \\left(\\mu \\dot{\\phi}^2 - T \\pd{\\phi}{x}^2 \\right)\n\\end{align}\n\n\nThe principle of least action guarantees that the variation of the action is 0:\n\n\\newcommand{\\La}{\\mathcal L}\n\\newcommand{\\Ha}{\\mathcal H}\n\n\\begin{align}\n    &\\delta \\int d^4 x \\mathcal{L}(\\phi, \\partial_{x^\\mu}{\\phi}) = 0 \\\\\n    \\arr & \\int d^4 x \\pd{\\La}{\\phi} \\delta \\phi + \\pd{\\La}{(\\partial_\\mu \\phi)} \\delta \\partial_\\mu(\\phi) \\\\\n    \\arr & \\int d^4 (\\pd{\\La}{\\phi} \\delta - \\partial_\\mu \\pd{\\La}{(\\partial_\\mu \\phi)}) \\delta \\phi \n    + \\partial_\\mu \\left(\\pd{\\La}{(\\partial_\\mu \\phi)} \\delta \\phi \\right)\n\\end{align}\n\nThe last term is the 4-divergence, which can be converted to the difference between the spatial integrals\nat the initial and final times, and therefore vanishes.\n\nWe therefore have the condition:\n\n\\begin{align}\n    \\partial_\\mu \\pd{\\La}{(\\partial_\\mu \\phi)} - \\pd{\\La}{\\phi} = 0\n\\end{align}\n\nApplying equation (11) to the string, we obtain the famous string equation:\n\n\\begin{align}\n    \\pdd{\\phi}{x}-\\frac{1}{v^2}\\pdd{\\phi}{t} = 0\n\\end{align}\nwhere \\(v^2 = \\frac{T}{\\mu}\\)\n\n\\subsection{Classical Source Term}\n\n\\subsection{Canonical Momenta}\n\nWe can compute the following canonical momenta:\n\n\\begin{align}\n    & \\pd{L}{\\dot{\\phi}} = \\mu \\dot{\\phi} - T \\partial_x \\phi v \\\\\n    & \\pd{L}{\\partial_x \\phi} = \\frac{\\mu}{v} \\dot{\\phi} - T \\partial_x \\phi\n\\end{align}\n\n\nWe see the canonical momenta is associated with the momentum of the transverse motion of the wave,\ni.e. the larger \\(\\dot{\\phi}\\) is, the larger the canonical momentum.\n\n\\paragraph{Some redefinition}: for convenience purposes, we redefine the field \\(\\phi \\arr \\sqrt{T} \\phi\\),\nso that T disappears from the equations. The field will have different units\n\n\n\n\n\n\\section{Decoupling the String into independent Oscillators}\n\n\\subsection{Normal Coordinates}\n\nAs with any wave equation, canonical quantization lends itself more nicely in a fourier basis.  We make the following guess:\n\n\\begin{align}\n    & \\phi_n = \\frac{1}{\\sqrt{L}} e^{i(k_n x- \\omega_n t)}\n\\end{align}\n\nWhere we choose\n\\begin{itemize}\n    \\item \\(\\omega_n >0\\)\n    \\item \\(k_n = 2n \\pi/L\\) with \\(n \\in I\\)(periodic Boundary Conditions)\n    \\item \\(\\omega_n^2 = v^2 k_n^2\\) (Wave Equation)\n\\end{itemize}\n\nWe note that there are both positive and negative \\(\\omega and k_n\\) solutions.\nBy Plancherel's theorem, the general solution can be written as follows.\n\n\\begin{align}\n    & \\phi(x,t)= \\sum_{n= -\\infty}^{\\infty} c_n(a_n \\phi_n + a_n* \\phi_n*)\n    & \\phi(x,t)= \\sum_{n = -\\infty}^{\\infty} c_n(a_n(t)e^{ik_n x} + a_n(t)* e^{-ik_n x})\n\\end{align}\nWhere \\(a_n(t)= a(0)e^{-i \\omega_n t}\\)\nWe have indeed successfully decoupled the string into independent oscillators, since the coefficient \\(a(t)\\) satisfy:\n\\[\\ddot{a_n}+ \\omega_n^2 a_n = 0\\]\n\nThe complex conjugate is there to ensure real solutions for the field.\n\nWe also have the following orthogonality identities:\n\n\\begin{align}:\n    &\\int_0^L \\phi_n \\phi_m = \\delta_{n,-m} e^{-2i\\omega_n t} \\\\\n    &\\int_0^L \\phi_n* \\phi_m = \\delta_{n,m}\n\\end{align}\n\n\\subsection{Hamiltonian}\n\nThe new kinetic energy, potential energy and Hamitonian are:\n\n\\begin{align}\n    & T = \\frac{1}{2v^2} \\int dx \\dot{\\phi}^2 \\\\\n    & U = \\frac{1}{2} \\int dx \\pd{\\phi}{x}^2 \\\\\n    & H = T + U = \\sum_{-\\infty}^{\\infty} c_n^2(\\frac{\\omega^2}{v^2} + k_n^2) a_n^2(t) + c_n c_{-n} (k_n^2 - \\frac{\\omega_n^2}{v^2})Re(a_n a_{-n}) \\\\\n\\end{align}\n\nUsing the \\(c_{-n} = -c_n\\), we can rewrite:\n\n\\begin{align}\n    & H = \\sum_n 2 c_n^2 \\frac{\\omega_n^2}{v^2} a_n(t) a_n(t)*\n\\end{align}\n\nWe work in natural units, where \\(h = c = 1\\).  \nWe can make a dimensionless by defining \\(c_n = \\sqrt{\\frac{v^2}{2 \\omega_n}}\\).\nTHe hamiltonian takes the form of:\n\\[H = \\sum_n \\omega_n a_n a*_n\\]\n\nRemarks:\n\n\\begin{itemize}\n    \\item The number a and a* have a lot of similarity to raising and lowering operators\n    \\item To make real a real dynamical variable, we can define \\(q_n = \\frac{1}{\\sqrt{2 \\omega_n}}(a_n + a_n*)\\)\n    \\item We can then define \\(p_n = \\ud{q}{t} = - i (\\frac{\\omega_n}{2})^{1/2} (a_n - a_n*)\\)\n    \\item The hamiltonian takes the form: \\(H = \\frac12 \\sum_n (p_n^2 + \\omega_n^2 q_n^2)\\)\n    \\item Re-expressing \\(q_n = \\sqrt{2\\omega_n} q_n + i \\sqrt{\\frac{2}{\\omega_n}} p_n\\)\n    \\item \\(p_n = \\sqrt{2\\omega_n} q_n - i \\sqrt{\\frac{2}{\\omega_n}} p_n\\)\n\\end{itemize}\n\n\n\n\\section{Canonical Quantization}\n\nWe are now ready to quantize the string.  The canonical commutation relations are:\n\n\\begin{align}\n    & [q_n, q_m] = [p_m, p_n] = 0 \\\\\n    & [q_n, p_m] = i \\hbar \\delta_{nm}\n\\end{align}\n\n\nThose commutation relations immediately imply commutation relations for the raising & lowering operators:\n\n\\[\n     [a_n, a_m *]= \\delta_{mn}\n     \\]\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "28fbe25c9a317812a43e1d601ddc17f9d41a7ed1", "size": 6353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "review/quantize_string.tex", "max_stars_repo_name": "Neelraj21/phython", "max_stars_repo_head_hexsha": "68a2cedccae694eb84880f3aa55cc01d458e055e", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-08-09T09:41:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-22T05:10:17.000Z", "max_issues_repo_path": "review/quantize_string.tex", "max_issues_repo_name": "Neelraj21/phython", "max_issues_repo_head_hexsha": "68a2cedccae694eb84880f3aa55cc01d458e055e", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "review/quantize_string.tex", "max_forks_repo_name": "Neelraj21/phython", "max_forks_repo_head_hexsha": "68a2cedccae694eb84880f3aa55cc01d458e055e", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-11-04T12:57:10.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-18T17:32:25.000Z", "avg_line_length": 32.0858585859, "max_line_length": 149, "alphanum_fraction": 0.6466236424, "num_tokens": 2233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.896251378675949, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7263928474891334}}
{"text": "\\section{Notation}\nThroghout this paper we assume that we are working in a three-dimensional\neuclidian space. We shall use $P_1, P_2, \\ldots$ to denote polytopes with\npoints in $\\mathbb{R}^3$, and $\\point{p_1}, \\point{p_2}, \\ldots$ to denote\npoints in $\\mathbb{R}^3$, where in particular $\\point{0} = (0, 0, 0)$.\nFor a $\\point{p_i}$ we indicate its three components with $(p_{i_x}, p_{i_y}, p_{i_z})$.\n", "meta": {"hexsha": "9dbef738bec9d8367d5a97482aa6e585dafb7d59", "size": 402, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/notation.tex", "max_stars_repo_name": "formalmethods/polytopepacking", "max_stars_repo_head_hexsha": "7879d1ceb252f731fa4bbc9d93341b832e62115d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-04-07T13:54:39.000Z", "max_stars_repo_stars_event_max_datetime": "2016-04-07T13:54:39.000Z", "max_issues_repo_path": "report/notation.tex", "max_issues_repo_name": "bobosoft/polytopepacking", "max_issues_repo_head_hexsha": "7879d1ceb252f731fa4bbc9d93341b832e62115d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-03-18T08:05:41.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-21T20:44:27.000Z", "max_forks_repo_path": "report/notation.tex", "max_forks_repo_name": "formalmethods/polytopepacking", "max_forks_repo_head_hexsha": "7879d1ceb252f731fa4bbc9d93341b832e62115d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.4285714286, "max_line_length": 88, "alphanum_fraction": 0.6990049751, "num_tokens": 146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7263928413349497}}
{"text": "\\section{Partition function}\n\nTheories with an action can be quantized using a path integral.\nThe partition function in Euclidean signature is defined as\n% \\footnote{\n% Wick rotation analytically continues time to imaginary (Euclidean) time, $t\\rightarrow -i t_E$,\n% then the oscillatory exponential becomes decaying. }\n% the same as the canonical partition function in statistical mechanics. }\n\\begin{equation}\n Z = \\int D\\phi \\, e^{-S[\\phi]},\n\\end{equation}\nwhich is an infinite-dimensional integral, \nover all possible field configurations (represented by the measure $D\\phi$) on all of spacetime.\n\n\nFor $\\mathcal{N}=2^*$ on $S^4$ and its limiting cases $\\mathcal{N}=4$ (massless hypermultiplet) and pure $\\mathcal{N}=2$ (infinitely-heavy hypermultiplet that is integrated out), \nthere is one localization locus.\nIt is the moduli space of Coulomb vacua, \nparametrized by the vacuum expectation value of a scalar of the vector multiplet:\n\\begin{equation}\\label{vevScalar}\n \\braket{\\Phi_0} = \\text{diag}(a_1, \\ldots, a_N), \n\\end{equation}\nwhere $a_i$ are real numbers.\nThe Coulomb phase of the theory \nis a consequence of the spontaneous symmetry breaking of the bosonic quartic potential $\\sim [\\Phi_I, \\Phi_J]^2$,\nthat breaks the original gauge group $U(N)$ to $U(1)^{N}$.\n\nThe result for the localized partition function is of the form:\n\\begin{equation}\\label{Zmatrixmodel}\n Z=\\int \\; d^N a \\, \\prod_{i<j} (a_i-a_j)^2 \\; Z_\\text{1-loop}(a)\\; \\left|Z_\\text{inst}(a)\\right|^2\\; e^{- \\frac{8\\pi^2 N}{\\lambda} \\sum_k a_k^2}.\n\\end{equation}\nThe classical action comes from the curvature coupling of the scalars in \\eqref{SS4}.\n\nThe 1-loop correction, for the different theories are\n\\begin{eqnarray}\n \\text{$\\mathcal{N}=2^*$ SYM:}  & & Z_\\text{1-loop} = \\prod_{i<j} \\dfrac{H^2(a_i-a_j)}{H(a_i-a_j-MR) H(a_i-a_j+MR)}\\\\\n \\text{$\\mathcal{N}=2$ SYM:}  & & Z_\\text{1-loop} = \\prod_{i<j} H^2(a_i-a_j) \\\\\n \\text{$\\mathcal{N}=4$ SYM:}  & & Z_\\text{1-loop} = 1\n\\end{eqnarray}\nwhere \n\\begin{equation}\n H(x) \\equiv \\prod_{n=1}^{\\infty}\\left(1+\\dfrac{x^2}{n^2}\\right)^n e^{-\\frac{x^2}{n}}.\n\\end{equation}\n% This function is $1$ at the origin and vanishes very fast away from it.\nWe used the 't Hooft coupling $\\lambda = g_{YM}^2 N$,\nand $R$ is again the radius of the hypersphere.\n\n\nThe instanton partition function is the generating function of instantons of topological charge $k$:\n\\begin{equation}\n Z_\\text{inst} = \\sum_{k=0}^\\infty (e^{i 2\\pi\\tau})^k Z_k,\n\\end{equation}\nwhere $Z_0 = 1$ and \n\\begin{equation}\n\\tau = i \\frac{4\\pi}{g_\\text{YM}^2} + \\frac{\\theta}{2\\pi} \n\\end{equation}\nis the complexified Yang-Mills coupling\\footnote{\nThe instanton action is the pure Yang-Mills action with an additional topological term.\nFor an instanton of charge $k$, the action is given by:\n\\[\nS_\\text{YM} (k)=\n    -\\frac{1}{2 g_\\text{YM}^2} \\text{tr} \\int d^4 x \\sqrt{g} F_{\\mu\\nu} F^{\\mu\\nu}\n    -i \\frac{\\theta}{8\\pi^2} \\text{tr} \\int F \\wedge F \n    = \\left( \\frac{8\\pi^2}{g_\\text{YM}^2} - i \\theta \\right) k\n    = - i 2 \\pi \\tau \\, k. \n\\]\n% This action breaks CP symmetry.\n% In QCD, there is no experimental evidence of CP violation, hence $\\theta$ must be very small,\n% and it is a considered a fine-tuning problem called the strong CP problem.\n}.\n% Instantons are tunnelling events in Minkowski signature\n% In QCD, the groundstate, called the $\\theta$-vacuum, is considered the superposition of all vacua. }.\n\nFor the $\\mathcal{N}=4$ case, $Z_\\text{inst} = 1$, \\cite{Okuda:2010ke}.\nFor the $\\mathcal{N}=2$ cases, it is non-trivial, \\cite{Nekrasov:2002qd}.\nHowever, the regime of interest is the large $N$ limit:\n\\begin{equation}\\label{largeNlimit}\n N\\rightarrow \\infty \\quad \\text{and} \\quad \\lambda = g_\\text{YM}^2 N \\quad \\text{is kept finite},\n\\end{equation}\nthen the expansion parameter becomes\n$$e^{i 2\\pi\\tau}=e^{-\\frac{8\\pi^2 N}{\\lambda} + i \\theta},$$\nhence the instanton contributions are expected to be exponentially suppressed. \nThis is checked in \\cite{Russo:2013kea}.\n\n\n% \n% for a single instanton in $\\mathcal{N}=2^*$\n% \\begin{equation}\n%  Z_\\text{1-inst} = - e^{-\\frac{8\\pi^2 N}{\\lambda} + i \\theta} (M R)^2 \n% \t\t  \\sum_{l=1}^N \\prod_{j\\neq l}^N \\dfrac{ (a_l-a_j +i)^2 - (MR)^2}{(a_l-a_j) (a_l-a_j+2i)}\n% \\end{equation}\n% Integral representation\n% \\begin{equation}\n%  Z_\\text{1-inst} = e^{-\\frac{8\\pi^2 N}{\\lambda} + i \\theta} \\dfrac{2 (M R)^2}{(M R)^2+1} \n% \t\t  \\int \\frac{dz}{2\\pi} \\prod_{j=1}^N \\dfrac{(z-a_j)^2 - (MR)^2}{(z-a_j)^2+1}\n% \\end{equation}\n\n\n\n\n\n\n\n\n\n\\section{Large-$N$ matrix model}\n\nThe localized partition function \\eqref{Zmatrixmodel} is a matrix model.\n% Therefore, it is convenient to think of it as an analogous statistical model, as we shall see.\nFor the $\\mathcal{N}=4$ case, the model is particularly simple, \nit is the well-known Gaussian unitary ensemble (GUE) in the random matrix theory.\nThe product of the eigenvalue differences is the Vandermonde determinant squared, \nwhich is essentially the Jacobian factor after diagonalizing the Hermitean matrix in \\eqref{vevScalar}.\nWriting it in terms of the effective action:\n\\begin{equation}\\label{eq:ZGUE}\n Z_\\text{GUE} = \\int \\; d^N a \\;  e^{- S[a]}, \n \\quad S[a]=- \\sum_{i\\neq j}^N \\log(|a_i-a_j|) + \\frac{8\\pi^2 N}{\\lambda} \\sum^N_k a_k^2\n\\end{equation}\nwe see that the Vandermonde determinant gives the 2d Coulomb potential.\nThis partition function is indeed identified with that of a 2d Coulomb gas confined on a line,\nwith the repulsive electrostatic force and an attractive harmonic force \\cite{Dyson:1962es}.\n\n\n% Exact methods exist, \n% such as the orthogonal polynomial method, \n% to solve the spectral distribution.\n% These allow physicists to compute observables exactly for $\\mathcal{N}=4$ (cite Genis).\n\nFor $\\mathcal{N}=2^*$, the matrix model is highly non-trivial, \nbut we can solve it systematically in the large $N$ limit,\nwhere the saddle-point approximation and the continuous approximation in principle apply.\nThe only relevant quantity to compute then is the distribution of the eigenvalues:\n\\begin{equation} \\label{def:rho}\n\\rho(x) = \\dfrac{1}{N} \\, \\sum_{i=1}^N \\delta(x-a_i) .\n\\end{equation}\nIt must have a compact support, i.e. $\\rho(\\pm \\mu) = 0$,\nwhere the endpoint $\\mu$ determines the scale of the spontaneous symmetry breaking.\nBy definition, it is also unit-normalized:\n\\begin{equation}\n \\int_{-\\mu}^\\mu dx\\, \\rho(x) = 1.\n\\end{equation}\n\n\nThe saddle-point equation, from extremizing the effective action \\eqref{eq:ZGUE} in terms of \\eqref{def:rho}, \nis a singular (principal value) integral equation:\n\\begin{equation} \\label{saddlepointEq}\n \\dfrac{\\delta S [\\rho]}{\\delta \\rho(x)} = 0 \\quad\n \\Rightarrow \\quad\n \\fint_{-\\mu}^\\mu dy \\, K(x-y) \\rho(y) = \\dfrac{8\\pi^2}{\\lambda}x.\n\\end{equation}\nThe singular kernel for the GUE case is just the Hilbert kernel\\footnote{\nThe name is in relation with the Hilbert transform. \nIt is also known as Cauchy kernel in the literature.},\nthat is \n\\begin{equation}\n K_\\text{Hilbert}(x)=\\dfrac{1}{x}.\n\\end{equation}\nIn the Coulomb gas picture, the saddle-point equation determines the equilibrium distribution due to the force balance.\nThe result is the well-known Wigner's semicircle distribution\n\\begin{equation}\\label{semicircle}\n \\rho(x) = \\dfrac{2}{\\pi \\mu^2} \\sqrt{\\mu^2-x^2}, \n \\quad \\mu = \\dfrac{\\sqrt{\\lambda}}{2\\pi},\n\\end{equation}\nshown in figure \\ref{fig:semicircle}.\n\n\n\\begin{figure}[t]\n\\begin{center}\n \\centerline{\\includegraphics[width=0.8\\textwidth]{Images/semicircle.pdf}}\n \\caption{\\label{fig:semicircle} Wigner's semicircle distribution, solution to the Gaussian unitary ensemble (GUE).}\n\\end{center}\n\\end{figure}\n\nFor the $\\mathcal{N}=2^*$ SYM, the kernel is\n\\begin{equation}\n K(x)=\\dfrac{1}{x}-\\mathcal{K}(x)+\\dfrac{1}{2}\\,\\mathcal{K}(x+MR)+\\dfrac{1}{2}\\,\\mathcal{K}(x-MR),\n\\end{equation}\nwhere \n\\begin{equation}\n \\mathcal{K}(x) \\equiv -\\dfrac{H'(x)}{H(x)} \n                = 2x\\sum_{n=1}^{\\infty} \\left(\\dfrac{1}{n}-\\dfrac{n}{n^2+x^2} \\right),\n\\end{equation}\nand much more interesting features show up in the saddle-point solution, as shown in figure \\ref{fig:phaseDiagram}.\nLet us briefly review these results.\n\n\nIn the strong-coupling regime, the bulk of the distribution is also a semicircle but with a rescaled endpoint:\n\\begin{equation}\\label{semicircleN=2*}\n \\rho(x) = \\dfrac{2}{\\pi \\mu^2} \\sqrt{\\mu^2-x^2}, \n \\quad\n \\mu=\\dfrac{\\sqrt{\\lambda (1+(MR)^2)}}{2\\pi},\n \\quad (\\lambda \\rightarrow \\infty).\n\\end{equation}\nThis is due to the fact that the kernel is approximately a Hilbert kernel \\cite{Buchel:2013id}:\n\\begin{equation} \\label{Kapprox}\n K(x) \\approx \\dfrac{1+(MR)^2}{x}, \\quad (\\lambda \\rightarrow \\infty).\n\\end{equation}\nClose to the edge-points, this approximation no longer holds,\nand it was the goal of Paper I to find the endpoint distribution in the strong coupling regime.\n\nWe computed the endpoint distribution exactly using the so-called Wiener-Hopf method, \nwhich is essentially the Fourier transform of the convolution integral in \\eqref{saddlepointEq} in a semi-infinite interval \n(zero being at the endpoint),\nthat relies on a certain factorization of the kernel.\n\nThe distribution exhibits oscillatory behavior with a period proportional to the scale $M R$. \nIn the decompactification limit $MR\\rightarrow \\infty$ (but $\\mu\\gg MR$ because we remain in the strong coupling limit), \nthe peaks of the oscillation diverge, see figure \\ref{fig:phaseDiagram}.\nThe analytical endpoint distribution at strictly infinite coupling and flat space, with $\\xi\\equiv\\mu-x$, is summarized below:\n\\begin{equation}\n \\rho(\\xi )= \\frac{2^{3/2}}{\\pi \\mu^{3/2}}\n% \\frac{\\sqrt{2 M R}}{\\pi \\mu^{3/2}}\n \\begin{cases}\n   MR \\sqrt{\\xi}, \n   &\\quad (\\xi \\sim 1)\\\\\n   \\dfrac{\\sqrt{M R}}{2}\\sum_{k=0}^{\\left[\\frac{\\xi }{MR}\\right]}\n             \\left(\\left\\{\\frac{\\xi }{MR}\\right\\} + k\\right)^{-1/2}\n   &\\quad (\\xi \\sim M R),\n \\end{cases}\n\\end{equation}\nwhere $[\\cdot]$ and $\\{\\cdot\\}$ denote the integer and the fractional part, respectively, \nand $\\mu=MR\\sqrt{\\lambda}/(2\\pi)$, from \\eqref{semicircleN=2*}.\n\nPhysically, the cusps appear due to a resonance phenomena \n\\begin{equation}\nm_{ij} = |a_i-a_j \\pm MR| \\approx 0\n\\end{equation}\nof very light states in the hypermultiplet sector.\nSimilar features were already observed for finite couplings in the flat space limit \\cite{Russo:2013qaa},\nand it was numerically shown that there are infinite-many critical couplings defined by \n\\begin{equation}\n \\mu = g(\\lambda_c^{(n)}) M R, \\quad g(\\lambda_c^{(n)}) = \\dfrac{n}{2}, \\quad n=1,\\ldots\n\\end{equation}\nThis means there are infinitely many phase transitions, where the phases are distinguished by the number of cusps of the distribution,\nand the coupling $\\lambda$ is the order parameter.\nAt strong coupling, the critical behavior persists and matches with the one obtained from the decompactification limit, \nhence these two limits commute \\cite{Zarembo:2014ooa}.\n\n\n\n\n\\begin{figure}[t]\n\\begin{center}\n \\centerline{\\includegraphics[width=0.9\\textwidth]{Images/phaseDiagram.pdf}}\n\\end{center}\n\\caption{\\label{fig:phaseDiagram} Phase diagram for the partition function of $\\mathcal{N}=2^*$ SYM on $S^4$, in the large $N$ limit. \nThe plots at the decompactification limit are taken from \\cite{Russo:2013qaa}, and the ones at strong coupling limit are from Paper I, where only close to the endpoint is shown and $R=1$.\nIn the zero mass limit, we have $\\mathcal{N}=4$ SYM, where the distribution is the Wigner semicircle for any coupling.}\n\\end{figure}\n\n\nSuch phase transitions are common among large-$N$ matrix models, \nand have been observed in e.g. ABJM models \\cite{Anderson:2014hxa}, 5d $\\mathcal{N}=1$ SYM with massive matter multiplets \\cite{Nedelin:2015mta}.\nIn our case, the gauge/string duality in principle gives us an opportunity to understand them from the point of view of gravity.\nThe physical observables we use to probe the infinite-coupling phase are Wilson loops, the topic of the next chapter.\n\n\n\n\n\n\n", "meta": {"hexsha": "f169b913dac53bf56299f2f74f754ad2402e5707", "size": 11872, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/PartitionFunctions.tex", "max_stars_repo_name": "yixinyi/PhDThesis", "max_stars_repo_head_hexsha": "fa5e6d89bf6e7658cebae8bab8a3d22fe4e53e29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/PartitionFunctions.tex", "max_issues_repo_name": "yixinyi/PhDThesis", "max_issues_repo_head_hexsha": "fa5e6d89bf6e7658cebae8bab8a3d22fe4e53e29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapters/PartitionFunctions.tex", "max_forks_repo_name": "yixinyi/PhDThesis", "max_forks_repo_head_hexsha": "fa5e6d89bf6e7658cebae8bab8a3d22fe4e53e29", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.3129770992, "max_line_length": 187, "alphanum_fraction": 0.7146226415, "num_tokens": 3785, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759492, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.7263928372321605}}
{"text": "\\section{Application: Dimensionless variables}\n\nThis section shows how solving systems of equations can be used to\ndetermine appropriate dimensionless variables. It is only an\nintroduction to this topic and considers a specific example of a\nsimple airplane wing shown below. We assume for simplicity that it is\na flat plane at an angle to the wind which is blowing against it with\nspeed $V$ as shown.\n\n\\begin{center}\n  \\begin{tikzpicture}\n    \\draw[fill=cyan](-5,1)--(0, 2)--(1.75,1.25)--(-3.25,0.25)--(-5,1);\n    \\draw(-3.25,0.25)--(-5,0.25);\n    \\draw[->](-6,1.5)--(-3.5,1.5);\n    \\node[above right] at (-4,0.5){$A$};\n    \\node[right] at (-1,0.5){$B$};\n    \\node[above right] at (-4.75,0.25){$\\theta$};\n    \\node[above] at (-5,1.5){$V$};\n  \\end{tikzpicture}\n\\end{center}\n\nThe angle $\\theta$ is called the angle of incidence, $B$ is the span\nof the wing and $A$ is called the chord. Denote by $l$ the lift. Then\nthis should depend on various quantities like $\\theta,V,B,A$ and so\nforth. Here is a table which indicates various quantities on which it\nis reasonable to expect $l$ to depend.\n\\begin{equation*}\n  \\begin{tabular}{|l|l|l|}\n    \\hline\n    Variable & Symbol & Units \\\\ \\hline\n    chord & $A$ & $\\m$ \\\\ \\hline\n    span & $B$ & $\\m$ \\\\ \\hline\n    angle incidence & $\\theta$ & $\\m^0\\kg^0\\s^0$ \\\\ \\hline\n    speed of wind & $V$ & $\\m\\s^{-1}$ \\\\ \\hline\n    speed of sound & $V_0$ & $\\m\\s^{-1}$ \\\\ \\hline\n    density of air & $\\rho$ & $\\kg\\m^{-3}$ \\\\ \\hline\n    viscosity & $\\mu$ & $\\kg\\s^{-1}\\m^{-1}$ \\\\ \\hline\n    lift & $l$ & $\\kg\\s^{-2}\\m$ \\\\ \\hline\n  \\end{tabular}\n\\end{equation*}\nHere $\\m$ denotes meters, $\\s$ refers to seconds and $\\kg$ refers to\nkilograms. All of these are likely familiar except for $\\mu$, which we\nwill discuss in further detail now.\n\nViscosity is a measure of how much internal friction is experienced\nwhen the fluid moves. It is roughly a measure of how \\textquotedblleft\nsticky\" the fluid is. Consider a piece of area parallel to the\ndirection of motion of the fluid. To say that the viscosity is large\nis to say that the tangential force applied to this area must be large\nin order to achieve a given change in speed of the fluid in a\ndirection normal to the tangential force. Thus\n\\begin{equation*}\n  \\mu (\\text{area}) (\\text{velocity gradient}) =\\text{\n    tangential force}\n\\end{equation*}\nHence\n\\begin{equation*}\n  (\\text{units of $\\mu$}) \\m^2\\paren{\\frac{\\m}{\\s \\m}}\n  = \\kg\\s^{-2}\\m\n\\end{equation*}\nThus the units of $\\mu$ are\n\\begin{equation*}\n  \\kg\\s^{-1}\\m^{-1}\n\\end{equation*}\nas claimed above.\n\nReturning to our original discussion, you may think that we would want\n\\begin{equation*}\n  l=f(A,B,\\theta,V,V_0,\\rho,\\mu)\n\\end{equation*}\nThis is very cumbersome because it depends on seven variables. Also,\nit is likely that without much care, a change in the units such as\ngoing from meters to centimeters would result in an incorrect value\nfor $l$. The way to get around this problem is to look for $l$ as a\nfunction of dimensionless variables multiplied by something which has\nunits of force. It is helpful because first of all, you will likely\nhave fewer independent variables and secondly, you could expect the\nformula to hold independent of the way of specifying length, mass and\nso forth. One looks for\n\\begin{equation*}\n  l=f(g_1,\\ldots,g_k) \\rho V^2AB\n\\end{equation*}\nwhere the units of $\\rho V^2AB$ are\n\\begin{equation*}\n  \\frac{\\kg}{\\m^3}\\paren{\\frac{\\m}{\\s}}^2\\m^2=\\frac{\\kg\\times \\m}{\\s^2}\n\\end{equation*}\nwhich are the units of force. Each of these $g_i$ is of the form\n\\begin{equation}\n  A^{x_1}B^{x_2}\\theta^{x_3}V^{x_4}V_0^{x_5}\\rho^{x_6}\\mu\n  ^{x_7}  \\label{11-july-e1f}\n\\end{equation}\nand each $g_i$ is independent of the dimensions. That is, this\nexpression must not depend on meters, kilograms, seconds, etc. Thus,\nplacing in the units for each of these quantities, one needs\n\\begin{equation*}\n  \\m^{x_1}\\m^{x_2}(\\m^{x_4}\\s^{-x_4}) (\\m^{x_5}\\s\n  ^{-x_5}) (\\kg\\m^{-3})^{x_6}(\\kg\\s\n  ^{-1}\\m^{-1})^{x_7}=\\m^0\\kg^0\\s^0\n\\end{equation*}\nNotice that there are no units of $\\theta$ because it is just the\nradian measure of an angle. Hence its dimensions consist of length\ndivided by length, thus it is dimensionless. Then this leads to the\nfollowing equations for the $x_i$.\n\\begin{equation*}\n  \\begin{array}{cc}\n    \\m: & x_1+x_2+x_4+x_5-3x_6-x_7=0 \\\\\n    \\s :\\  & -x_4-x_5-x_7=0 \\\\\n    \\kg: & x_6+x_7=0\n  \\end{array}\n\\end{equation*}\nThe augmented matrix for this system is\n\\begin{equation*}\n  \\begin{mymatrix}{rrrrrrr|r}\n    1 & 1 & 0 & 1 & 1 & -3 & -1 & 0 \\\\\n    0 & 0 & 0 & 1 & 1 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 & 1 & 1 & 0\n  \\end{mymatrix}\n\\end{equation*}\nThe {\\rref} is given by\n\\begin{equation*}\n  \\begin{mymatrix}{rrrrrrr|r}\n    1 & 1 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & 1 & 1 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 & 1 & 1 & 0\n  \\end{mymatrix}\n\\end{equation*}\nand so the solutions are of the form\n\\begin{eqnarray*}\n  x_1 &=& -x_2-x_7 \\\\\n  x_3 &=& x_3 \\\\\n  x_4 &=& -x_5-x_7 \\\\\n  x_6 &=& -x_7\n\\end{eqnarray*}\nThus, in terms of vectors, the solution is\n\\begin{equation*}\n  \\begin{mymatrix}{c}\n    x_1 \\\\\n    x_2 \\\\\n    x_3 \\\\\n    x_4 \\\\\n    x_5 \\\\\n    x_6 \\\\\n    x_7\n  \\end{mymatrix} =\\begin{mymatrix}{c}\n    -x_2-x_7 \\\\\n    x_2 \\\\\n    x_3 \\\\\n    -x_5-x_7 \\\\\n    x_5 \\\\\n    -x_7 \\\\\n    x_7\n  \\end{mymatrix}\n\\end{equation*}\nThus the free variables are $x_2,x_3,x_5,x_7$. By assigning values to\nthese, we can obtain dimensionless variables by placing the values\nobtained for the $x_i$ in the formula {\\eqref{11-july-e1f}}. For\nexample, let $x_2=1$ and all the rest of the free variables are\n0. This yields\n\\begin{equation*}\n  x_1=-1,x_2=1,x_3=0,x_4=0,x_5=0,x_6=0,x_7=0\n\\end{equation*}\nThe dimensionless variable is then $A^{-1}B^{1}$. This is the ratio\nbetween the span and the chord. It is called the aspect ratio, denoted\nas $AR$. Next let $x_3=1$ and all others equal zero. This gives for a\ndimensionless quantity the angle $\\theta$. Next let $x_5=1$ and all\nothers equal zero.  This gives\n\\begin{equation*}\n  x_1=0,x_2=0,x_3=0,x_4=-1,x_5=1,x_6=0,x_7=0\n\\end{equation*}\nThen the dimensionless variable is $V^{-1}V_0^{1}$. However, it is\nwritten as $V/V_0$. This is called the Mach number\n$\\mathcal{M}$. Finally, let $x_7=1$ and all the other free variables\nequal 0. Then\n\\begin{equation*}\n  x_1=-1,x_2=0,x_3=0,x_4=-1,x_5=0,x_6=-1,x_7=1\n\\end{equation*}\nthen the dimensionless variable which results from this is\n$A^{-1}V^{-1}\\rho ^{-1}\\mu$. It is customary to write it as\n$\\Reynolds=(AV\\rho) /\\mu$. This one is called the Reynold's number. It\nis the one which involves viscosity. Thus we would look for\n\\begin{equation*}\n  l=f(\\Reynolds,AR,\\theta,\\mathcal{M}) \\kg\\times \\m/\\s^2\n\\end{equation*}\nThis is quite interesting because it is easy to vary $\\Reynolds$ by\nsimply adjusting the velocity or $A$ but it is hard to vary things\nlike $\\mu$ or $\\rho$. Note that all the quantities are easy to\nadjust. Now this could be used, along with wind tunnel experiments, to\nget a formula for the lift that would be reasonable. You could also\nconsider more variables and more complicated situations in the same\nway.\n\n", "meta": {"hexsha": "6ec216f7da24401eae34d7644d324aec69d010ad", "size": 7076, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/SystemsofEquations-Application-Dimensionless.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/SystemsofEquations-Application-Dimensionless.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/SystemsofEquations-Application-Dimensionless.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 36.8541666667, "max_line_length": 71, "alphanum_fraction": 0.6674674958, "num_tokens": 2545, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.8962513800615313, "lm_q1q2_score": 0.7263928322009615}}
{"text": "\\documentclass[main.tex]{subfiles}\n\n\\begin{document}\n\t\\section{Reciprocal lattice and scattering} \\label{sec:scattering}\n\t\\subsection{Theory}\n\tThe reciprocal lattice is an incredibly useful construct, as it allows for an easy description of wave phenomena, where the main variable is the wave vector $ \\V{k} $. The reciprocal lattice is a lattice (as defined in the previous section), but in reciprocal space. This again means that the free variable is not position, but the wave vector.\n\t\n\tThe definition of a reciprocal lattice is all of the points $ \\V{G} $, that satisfy\n\t\\begin{equation}\\label{eq:reciprocal_lattice}\n\t\te^{i \\V{G} \\D \\V{R}} = 1,\n\t\\end{equation}\n\tfor any lattice point in real space $ \\V{R} $. Further, the primitive lattice vectors of the reciprocal lattice all satisfy the property \\cite{kittel}\n\t\\begin{equation}\\label{eq:rec_prim_def}\n\t\t\\V{a}_i \\D \\V{b}_j = 2\\pi \\delta_{ij},\n\t\\end{equation}\n\twhere $ \\delta_{ij} $ is the familiar Kronecker delta. This property of the reciprocal lattice vectors is what makes $ \\V{G} $ a lattice in reciprocal space. The real space lattice points have the coordinates $ \\V{R} = n_1 \\V{a}_1 + n_2 \\V{a}_2 + n_3 \\V{a}_3 $, and say an arbitrary point in the reciprocal space is constructed as\n\t\\begin{equation}\\label{eq:rec_lat_vec}\n\t\t\\V{G} = m_1 \\V{b}_1 + m_2 \\V{b}_2 + m_3 \\V{b}_3,\n\t\\end{equation}\n\tthen plugging these into Eq. \\eqref{eq:reciprocal_lattice} we get\n\t\\begin{equation}\n\t\te^{i (n_1 \\V{a}_1 + n_2 \\V{a}_2 + n_3 \\V{a}_3) \\D (m_1 \\V{b}_1 + m_2 \\V{b}_2 + m_3 \\V{b}_3)} = e^{2\\pi i (n_1 m_1 + n_2 m_2 + n_3 m_3)},\n\t\\end{equation}\n\twhere the second equality follows from the defining property of the primitive lattice vectors in reciprocal space. For $ \\V{G} $ to be part of the reciprocal lattice, for any choice of integer $ n_i $, then $ m_i $ need also be integers. As such the reciprocal lattice really is a lattice, as defined in section \\ref{sec:lattice_theory}, but in the reciprocal space. Usually (in the case of lattice planes and scattering) we express the 3 coefficients for the reciprocal lattice vectors using Miller indices ($ hkl $), where $ h=m_1, k=m_2, l=m_3 $.\n\t\n\tNow, to actually construct the reciprocal primitive lattice vectors, the following formulas are used:\n\t\\begin{equation}\\label{eq:rec_prim_vec}\n\t\t\\V{b}_1 = \\frac{2\\pi \\, \\V{a}_2 \\times \\V{a}_3}{\\V{a}_1 \\D (\\V{a}_2 \\times \\V{a}_3)}, \\quad \\V{b}_2 = \\frac{2\\pi \\, \\V{a}_3 \\times \\V{a}_1}{\\V{a}_2 \\D (\\V{a}_3 \\times \\V{a}_1)}, \\quad \\V{b}_3 = \\frac{2\\pi \\, \\V{a}_1 \\times \\V{a}_2}{\\V{a}_3 \\D (\\V{a}_1 \\times \\V{a}_2)},\n\t\\end{equation}\n\twhere the cross product in the numerator ensures that $ \\V{a}_i $ and $ \\V{b}_j $ are orthogonal to each other for $ i \\neq j $, and the denominator serves as a sort of normalization, such that the dot product equals 2$ \\pi $. Further, by dimensional analysis, $ \\V{b}_i $ has dimensions $ \\e{m}\\inverse $, as expected for wave vectors.\n\t\n\tThe reciprocal lattice can also be understood in terms of families of lattice planes. First, a lattice plane is defined as any plane that contains at least 3 lattice points (this also guarantees that an infinite set of lattice points is contained by the plane, by virtue of the non-uniqueness of the primitive lattice vectors). A family of lattice planes is an infinite series of parallel planes, equally spaced, such that all points of the lattice is contained in the planes, and that all planes contain lattice points.\n\t\n\tFirst consider the series of planes containing the points $ \\V{r}_m $, defined by\n\t\\begin{equation}\n\t\t\\V{G} \\D \\V{r}_m = 2\\pi m,\n\t\\end{equation}\n\tfor some integer $ m $. This form ensures that all lattice points are contained in the planes. The minimum distance between planes can then be calculated from\n\t\\begin{equation}\n\t\t\\V{G} \\D (\\V{r}_2 - \\V{r}_1) = 2\\pi,\n\t\\end{equation}\n\tas the minimum distance will be when $ (\\V{r}_2-\\V{r}_1) $ and $ \\V{G} $ are parallel, yielding\n\t\\begin{equation}\n\t\td = \\frac{2\\pi}{|\\V{G}|}.\n\t\\end{equation}\n\tNow any reciprocal lattice vector will give yield a set of equidistant, parallel planes, but not all of these sets will be families of lattice planes. The family of lattice planes in the direction $ \\U{G} $ will have have some distance $ d = 2\\pi /|\\V{G}| $, where $ \\V{G} $ is a reciprocal lattice vector. An infinite set of reciprocal lattice vectors share this direction, but increasing the magnitude of the reciprocal lattice vector $ \\V{G} $ will decrease the distance between the set of planes, and at some point there will be planes that do not contain any lattice points.\n\t\n\tAs such, there is some minimum magnitude of the reciprocal lattice vector that defines a given family of lattice planes. This means that for a family of lattice planes, the distance is $ d = 2\\pi /| \\V{G}_{min}| $.\n\t\n\t\\subsubsection{Scattering}\n\tIn a scattering experiment, an incoming collection of waves (be it electrons, neutrons, x-ray photons or something completely different) with wave vector $ \\V{k} $ is incident upon a crystal. Some of these will be scattered into states with wave vector $ \\V{k}' $ whilst others will pass on through. \n\t\n\tThe following derivation of the scattering criteria and intensities follow that of \\cite{simon}.\n\t\n\tTo find the general conditions for scattering, we start with Fermi's Golden Rule, which is a measure of the transition rate between states. It is given as\n\t\\begin{equation}\\label{eq:Scat_fermi}\n\t\t\\Gamma(\\V{k}', \\V{k}) = \\frac{2\\pi}{\\hbar}|\\braket{\\V{k}' | V | \\V{k}}|^2 \\delta(E_{\\V{k}'}-E_{\\V{k}}),\n\t\\end{equation}\n\twhere the matrix element is\n\t\\begin{equation}\\label{eq:Scat_mat_el_initial}\n\t\t\\braket{\\V{k}' | V | \\V{k}} = \\infint \\frac{e^{-i \\V{k}'\\D\\V{r}}}{\\sqrt{L^3}} V(\\V{r}) \\frac{e^{i \\V{k}\\D\\V{r}}}{\\sqrt{L^3}} \\ud \\V{r} = \\frac{1}{L^3} \\infint e^{-i(\\V{k}'-\\V{k}) \\D \\V{r}} \\, V(\\V{r}) \\ud \\V{r},\n\t\\end{equation}\n\twhich is just the Fourier transform of the potential! Further, we assume the potential is periodic in the unit cell, allowing us to use the same trick as with the Nearly Free Electron Model: Since $ V(\\V{r} + \\V{R}) =  V(\\V{r}) $ for any lattice point $ \\V{R} $, we can define $ \\V{r} = \\V{R} + \\V{x} $ where $ \\V{x} $ is a position within the unit cell, and then split up the integral into an infinite sum over lattice points:\n\t\\begin{equation}\\label{eq:Scat_mat_el}\n\t\t\\braket{\\V{k}' | V | \\V{k}} = \\frac{1}{L^3}\\infint e^{-i(\\V{k}'-\\V{k})\\D(\\V{R}+\\V{x})} V(\\V{R}+ \\V{x}) \\ud \\V{x} = \\frac{1}{L^3} \\sum_{\\V{R}} e^{-i(\\V{k}'-\\V{k}) \\D \\V{R}}\\int_{\\substack{\\text{unit-} \\\\\\text{cell}}} e^{-i (\\V{k}'-\\V{k}) \\D \\V{x}} V(\\V{x}) \\ud \\V{x}.\n\t\\end{equation}\n\tNow, as in the one dimensional case, this sum of complex exponentials has two possible outcomes. If $ \\V{k}'-\\V{k} $ is a reciprocal lattice vector, all the terms are unity and the sum adds up to the total number of unit cells in the crystal. If $ \\V{k}'-\\V{k} $ is not a reciprocal lattice vector, then the terms will just oscillate, like roots of unity, summing to 0. This condition is called the Laue condition:\n\t\\begin{equation}\\label{eq:Scat_Laue}\n\t\t\\V{k}' - \\V{k} =  \\V{G}.\n\t\\end{equation}\n\tFurthermore, when the scattered wave leaves the crystal, it has to have the same magnitude of the wave vector as the incoming wave, as required from the delta function in Fermi's Golden Rule:\n\t\\begin{equation}\\label{eq:Scat_E_cons}\n\t\t|\\V{k}'| = |\\V{k}|.\n\t\\end{equation}\n\tTogether these conditions are statements of conservation of crystal momentum and energy respectively. With the conditions met we still need to find the actual scattering amplitudes. This is where the integral in Eq. \\eqref{eq:Scat_mat_el} comes in. It turns out that the intensity of the scattered wave vector is proportional to the absolute square of this integral, called the \\textit{structure factor} \\cite{simon}:\n\t\\begin{equation}\n\t\tI \\propto |S(\\V{G})|^2, \\quad S(\\V{G}) = \\int_{\\substack{\\text{unit-} \\\\\\text{cell}}} e^{-i \\V{G} \\D \\V{x}} V(\\V{x}) \\ud \\V{x}.\n\t\\end{equation}\n\tThis is as far as is workable without specifying the form of the potential. For now we will assume we are working with neutron scattering. Since neutrons are not charged, they only scatter from the atomic cores by nuclear forces, and not from electrons. For this reason we model the potential of each atom in the unit cell as a delta function with some appropriate potential strength associated:\n\t\\begin{equation}\\label{eq:Scat_neutron_pot}\n\t\tV(\\V{x}) \\sum_{\\text{atoms} \\,j} f_j \\delta(\\V{x}-\\V{x}_j),\n\t\\end{equation}\n\twhere the potential strength is called the \\textit{form factor}. With this potential, the structure factor becomes\n\t\\begin{equation}\\label{eq:Scat_struct}\n\t\tS(\\V{G}) = \\sum_{\\text{atoms} \\,j} f_j e^{i \\V{G} \\D \\V{x}_j}.\n\t\\end{equation}\n\t\n\tFor the purposes of the program, we will further restrict the available lattice to a simple cubic with a basis. This will allow us to illustrate the core ideas of scattering whilst keeping any clutter to a minimum.\n\t\n\tAnother thing this allows us to show is systemic absences. For a cubic lattice with a basis, the structure factor becomes\n\t\\begin{equation}\\label{eq:Scat_struct_ortho}\n\t\tS(\\V{G}) = S_{hkl} = \\sum_{\\text{atoms}\\, j} f_j e^{i (h\\V{b}_1 + k\\V{b}_2 + l\\V{b}_3) \\D \\V{x}_j} = \\sum_{\\text{atoms}\\, j} f_j e^{2\\pi i (hx_j + ky_j + lz_j)},\n\t\\end{equation}\n\twhere the coordinates of $ \\V{x}_j $ are in units of the lattice constant $ a $. For a bcc lattice, which corresponds to a simple cubic lattice, with two identical atoms at $ (0,0,0) $ and $ (1/2, 1/2, 1/2) $ (again in units of the lattice constant), the structure factor becomes\n\t\\begin{equation}\n\t\tS_{hkl} = f\\ (1 + e^{2\\pi i (h/2 + k/2 + l/2)}) = f\\ (1 + e^{\\pi i (h+k+l)}) = f \\ (1+ (-1)^{h+k+l}),\n\t\\end{equation}\n\tmeaning that for there to be any scattering for a bcc lattice, $ h+k+l $ must be even. This is what is known as a systemic absence. There is also a systemic absence for fcc lattices, which can be thought of as a simple cubic lattice, with identical atoms at $ (0,0,0), (1/2, 1/2, 0), (1/2, 0, 1/2) $ and $ (0, 1/2, 1/2) $:\n\t\\begin{equation}\n\t\tS_{hkl} = f\\ (1 + e^{\\pi i (h+k)} + e^{\\pi i (k+l)} + e^{\\pi i (h+l)}).\n\t\\end{equation}\n\tHere all of $ h+k, k+l $ and $ h+l $ must be even, corresponding to $ h,k,l $ all being either even or odd. As such there are systemic absences in both bcc and fcc lattices, but not simple cubic lattices, where all combinations of $ h,k $ and $ l $ can lead to scattering.\n\t\n\t\\subsection{Implementation}\t\n\tThe scattering program creates one figure with two sets of axes. One interactive set with the physical setup, including the desired crystal structure, incoming probe beam, detector screen and detected scattering events. The second shows only a top down view of the detector screen with the detected scattering events.\n\t\n\tFor the first set of axes, the scattering program builds upon the lattice plotting program. It plots the desired lattice (simple cubic with a basis), calculates scattering for this crystal given a list of form factors and an incoming wave vector, and displays the results on a simulated detection screen. The wave vectors point of impact is kept fixed, but the magnitude and angle of incidence can be changed by the user.\n\t\n\tOn the second set of axes we plot a top down view of the detection plane, along with scattering events and the associated Miller indices. To make the program more user friendly, we (by default) define the incoming wave vector in units of $ 2\\pi/a $, such that the user does not need to always include these factors.\n\t\n\tCalculating the actual scattering is done by first creating the reciprocal lattice with Eq. \\eqref{eq:rec_prim_vec}, and next creating an array of reciprocal lattice vectors with indices $ h,k,l \\in \\{-5, -4, \\dots, 5\\} $ (excluding $ h=k=l=0 $ as this just results in a \"scattered\" wave vector equal to the incident wave vector). This of course does not constitute the whole possible range reciprocal lattice vectors, but a line has to be drawn somewhere. This interval includes $ 11^3 - 1 = 1330$ different reciprocal lattice vectors, which should be plenty to get an understanding of scattering.\n\t\n\tThis array of reciprocal lattice vectors is then used to calculate the \"scattered\" wave vectors by Eq. \\eqref{eq:Scat_Laue}. These do not necessarily meet the other criteria of energy conservation, though, and there are further criteria to consider.\n\t\n\tThe first additional criteria is the direction of the scattered wave vector. The scattered wave vector has to point in the direction of the detection screen, otherwise it will not physically \"hit\" the screen. In the program the detection screen is placed parallel to the $ xy $-plane, with $ z=z_0, z_0 > 0 $. As such any scattered wave vector will need to have $ k'_z > 0 $ to be detected.\n\t\n\tSecond is any systemic absences. The reason we need to check for this is the fact that we show the Miller indices on the second set of axes. So if we do not filter out any scattering wave vectors, whose intensity is zero, we will get a spot on the detection plane with zero intensity, but the Miller indices still plotted. The systemic absence is calculated by taking the absolute square of  Eq. \\eqref{eq:Scat_struct} and checking whether or not it is equal to 0. If so we exclude the wave vector from the scattered events.\n\t\n\tThese three criteria (conservation of energy, proper direction, and a lack of systemic absence) are all calculated by the program, and if a scattered wave vector does not fulfil all of them, it is discarded.\n\t\n\tLeft are only a handful, if any, of scattered wave vectors. For each of these, the impact point of the scattered wave vector on the detection plane has to be calculated. This is done by calculating the intersection between a line and a plane. The line is defined by the point of impact $ \\V{p}_0 $ of the incident wave vector along with the scattered wave vector $ \\V{k}' $. The plane is defined as mentioned above, with $ z=z_0 $. In this case the intersection happens when\n\t\\begin{equation}\n\t\tp_{0,z} + t\\D k'_z = z_0,\n\t\\end{equation}\n\tfor some value of $ t $. This value of $ t $ can then be used to calculate the point of intersection $ \\V{p} $ as\n\t\\begin{equation}\n\t\t\\V{p} = \\V{p}_0 + t \\V{k}'.\n\t\\end{equation}\n\tThese points are then plotted in the first set of axes along with the detection plane and the incoming wave vector (scaled so its length is equal to the wavelength), and on the second set of axes along with the associated Miller indices.\n\t\n\tTwo additional features for the scattering program are also available. The first is the \"show all\" feature. This plots all outgoing wave-vectors and their associated lines (starting at the impact point for the incident beam, and ending at the intersection between the outgoing wave vector and the detection plane).\n\t\n\tThe second is a \"highlighting\" feature. This feature works by taking a set of Miller indices and highlighting the scattering associated with said set (if scattering occurs for this reciprocal lattice vector). It plots the relevant scattering event in a different colour, and plots the associated family of planes.\n\t\n\t\\begin{wrapfigure}{r}{3cm}\n\t\t\\includegraphics[width=3cm]{figures/plane_distance.pdf}\n\t\t\\caption{The distance between to adjacent planes is $ d $, and the vertical distance $ D $ is $ d/\\cos \\theta$}\n\t\t\\label{fig:plane_distance}\n\t\\end{wrapfigure}\n\t\n\tThese planes are created in one of two ways. If the plane is \\textit{not} perpendicular to the $ xy $-plane (corresponding to a normal vector $ \\V{n} $ with a $ z $-component different from 0) the equation of the plane is used with the origin as the starting point $ \\V{r}_0 $. For the normal vector, the program uses the displacement vector $ \\V{d} = 2\\pi \\U{G} / |\\V{G}| $:\n\t\\begin{equation}\n\t\t0 = \\V{d} \\D (\\V{r}-\\V{r}_0) = \\V{n} \\D \\V{r}, \\quad \\Leftrightarrow \\quad z = -\\frac{d_x x + d_y y}{d_z}.\n\t\\end{equation}\n\tThe program then calculates the $ z $-component of the plane from a given array of $ x $ and $ y $-values. This, of course, only creates one plane. Each subsequent plane is created by displacing the original plane vertically by an amount $ d/\\cos \\theta = d^2/d_z$ (see figure \\ref{fig:plane_distance}). This process is repeated in the positive direction until the smallest $ z $-value of the uppermost plane is outside of the plot box, and likewise in the negative direction, yielding a full set of parallel planes, spaced by $ \\V{d} $ (at least within the plot box).\n\t\n\tHowever, if the plane \\textit{is} perpendicular to the $ xy $-plane, this method does not work. Here the program creates a plane from the span of two vectors perpendicular to the displacement vector. Since the plane is perpendicular to the $ xy $-plane, one such vector is $ \\U{z} $, the unit vector in the $ z $-direction. Then the second vector can just be taken as the cross product between $ \\V{d} $ and $ \\U{z} $. Again the origin is taken as the starting point:\n\t\\begin{equation}\n\t\t\\V{r} = \\V{r}_0 + s \\U{z} + t (\\U{z} \\times \\V{d}).\n\t\\end{equation}\n\tTo get any subsequent planes, an integer multiple of the displacement vector $ \\V{d} $ is added to the starting plane.\n\t\n\t\\begin{wrapfigure}{r}{2in}\n\t\t\\includegraphics[width=2in]{figures/lattice_planes_1.pdf}\n\t\t\\caption{A bcc lattice showing the (001) family of lattice planes.}\n\t\t\\label{fig:lattice_planes}\n\t\\end{wrapfigure}\n\tFor both of these methods the planes need to be limited so they are only plotted within the plot box. This is done by replacing the $ z $-component of any point outside the plot box with \\texttt{NaN}, which will cause Matplotlib to not plot the associated point. This is especially pertinent in the second case, where not only the $ z $-component may be outside the plot box, but also the $ x $ and $ y $-components may be. Because of this $ \\U{z}/4 $ and $ (\\U{z} \\times \\U{G})/4 $ are used to increase the resolution of each plane, along with a large range of values for $ s $ and $ t $ (in this case taken to be integers, though the same effect could be achieved by using a more densely packed interval for $ s $ and $ t $ and keeping the original vectors).\n\t\n\t \n\tFurther, a second program is added alongside the scattering program. This second program just allows the user to plot any crystal, along with any family of lattice planes, defined by a set of Miller indices supplied by the user.\n\t\n\t\\subsection{Examples}\n\tSay we just want to plot the (001) family of lattice planes for a bcc lattice, then we write the following and get figure \\ref{fig:lattice_planes}.\n\\begin{lstlisting}\nReciprocal(lattice_name=\"bcc\",\n\t\t   indices=(0,0,1))\n\\end{lstlisting}\n\tAs another example, consider the case of simulating neutron scattering on a cubic lattice with a four atom basis (one at lattice points, the others at the centres of the faces of the unit cell). We set the relative form factors as 1 for the atoms on the lattice points and 0.5 for the others. We set $ \\V{k}_{in} = (0, 0, -1.5)$ in units of $ 2\\pi/a $. Lastly we highlight the scattering corresponding to the Miller indices (112). This is all done by the following line, and produces figure \\ref{fig:scattering_no_systemic}.\n\\begin{lstlisting}\nScattering(k_in=np.array([0, 0, -1.5]),\n\t\t   basis=np.array([[0, 0, 0], \n\t\t\t\t\t\t   [0.5, 0.5, 0],\n\t\t\t\t\t\t   [0.5, 0, 0.5],\n\t\t\t\t\t\t   [0, 0.5, 0.5]]),\t\n\t\t   highlight=(1,1,2),\n\t\t   form_factor=np.array([1, 0.5, 0.5, 0.5]))\n\\end{lstlisting}\n\tBut what if we want to plot scattering on regular fcc lattice, with the same wave vector as before? Then we just set the scattering length for all atoms to 1. This gives figure \\ref{fig:scattering_systemic}, where we have also set identical colours for the four atoms to emphasize that they are now identical.\n\\begin{lstlisting}\nScattering(k_in=np.array([0, 0, -1.5]),\n\t\t   basis=np.array([[0, 0, 0], \n\t\t\t\t\t\t   [0.5, 0.5, 0],\n\t\t\t\t\t\t   [0.5, 0, 0.5],\n\t\t\t\t\t\t   [0, 0.5, 0.5]]),\t\n\t\t   form_factor=np.array([1, 0.5, 0.5, 0.5]),\n\t\t   colors=['xkcd:cement']*4)\n\\end{lstlisting}\n\tNote on this figure the absence of any scattering. This is an example of a systemic absence for the fcc lattice, because not all indices in each of the 5 sets are even (or odd). The highlighted scattering event in figure \\ref{fig:scattering_no_systemic} has 2 odd indices and 1 even index.\n\t\n\t\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{figures/scattering_no_systemic.pdf}\n\t\t\\caption{Scattering on a cubic lattice with a four atom basis (one at lattice points and the others on the faces of the unit cell), with form factors of 1 for the lattice point atoms, and 0.5 for the others. The choice of incoming wave vector gives rise to 5 scattering events, corresponding to 5 different sets of miller indices.}\n\t\t\\label{fig:scattering_no_systemic}\n\t\\end{figure}\n\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{figures/scattering_systemic.pdf}\n\t\t\\caption{The same scattering setup as in figure \\ref{fig:scattering_no_systemic}, but with equal form factors for the four atoms (effectively an fcc lattice). Note the absence of scattering events due to systemic absence, since for each of the sets of Miller indices either $ h+k $, $ k+l $ or $ h+l $ is odd.}\n\t\t\\label{fig:scattering_systemic}\n\t\\end{figure}\n\n\t\n\n\\end{document}", "meta": {"hexsha": "89bbcb245e4a0ad472e6f09c2467514930cdce3c", "size": 21173, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/reciprocal.tex", "max_stars_repo_name": "NikolaiNielsen/Bachelor", "max_stars_repo_head_hexsha": "e26f3cee6dcfc858b606b5d3112f553836dd3990", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-05-17T02:07:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-06T09:18:38.000Z", "max_issues_repo_path": "thesis/reciprocal.tex", "max_issues_repo_name": "NikolaiNielsen/Bachelor", "max_issues_repo_head_hexsha": "e26f3cee6dcfc858b606b5d3112f553836dd3990", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thesis/reciprocal.tex", "max_forks_repo_name": "NikolaiNielsen/Bachelor", "max_forks_repo_head_hexsha": "e26f3cee6dcfc858b606b5d3112f553836dd3990", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-07-19T05:12:31.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-24T08:32:13.000Z", "avg_line_length": 101.7932692308, "max_line_length": 761, "alphanum_fraction": 0.7217682898, "num_tokens": 6116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.726275751644569}}
{"text": "\\chapter{Network theory}\n\n  \\section{Definitions}\n        \n    \\subsection{Graph}\n\n      A graph $G$ is a pair of sets $(V, E)$ such that $E \\subseteq [V]^2$. $V$ or $V(G)$ is a set of arbitrary objects called \\emph{vertices} (singular is \\emph{vertex}) or \\emph{nodes}, while $E$ or $E(G)$ is a set of vertex pairs, called \\emph{edges} or \\emph{arcs} on occasion; elements of $E$ are two-element subsets of $V$\\cite{Diestel2012}.\n      \n      There are two graph types in respect to edge type: \\emph{undirected} and \\emph{directed}, pictured on figure \\ref{fig:graphs_orientation_undirected} and \\ref{fig:graphs_orientation_directed} respectively. In the former, edges are ordered pairs of vertices, i.e. $e = (u, v) = (v, u)$. In the latter they are unordered or just sets of two vertices, that is $e = (u, v) \\neq (v, u) = d$.\n      \\begin{figure}[H]\n        \\centering        \n          \\begin{subfigure}[b]{0.27\\textwidth}\n            \\includegraphics[width=\\textwidth]{chapters/02_problem_definition/graph_undirected}\n            \\caption{An undirected graph.}\n            \\label{fig:graphs_orientation_undirected}\n          \\end{subfigure}\n          \\qquad\\qquad\\qquad\n          \\begin{subfigure}[b]{0.27\\textwidth}\n            \\includegraphics[width=\\textwidth]{chapters/02_problem_definition/graph_directed}\n            \\caption{A directed graph.}\n            \\label{fig:graphs_orientation_directed}\n          \\end{subfigure}\n        \\caption{Types of graphs in respect to orientation.}\n        \\label{fig:graphs_orientation}\n      \\end{figure}\n      \n      Then we have \\emph{simple graphs}, where there are no edges from a vertex to itself (called loops) and there are no more than one edge between any two distinct vertices (i.e. edges form sets). On the other side we have \\emph{multigraphs} (or \\emph{pseudographs}), that may both have loops (not everyone agrees with that) and multiple edges (also called parallel edges) between different vertices (thus they form a multiset).\n      \\begin{figure}[H]\n        \\centering        \n          \\begin{subfigure}[b]{0.25\\textwidth}\n            \\includegraphics[width=\\textwidth]{chapters/02_problem_definition/graph_simple}\n            \\caption{A simple graph.}\n            \\label{fig:graphs_simple}\n          \\end{subfigure}\n          \\qquad\\qquad\\qquad\n          \\begin{subfigure}[b]{0.25\\textwidth}\n            \\includegraphics[width=\\textwidth]{chapters/02_problem_definition/graph_multi}\n            \\caption{A multigraph.}\n            \\label{fig:graphs_multi}\n          \\end{subfigure}\n        \\caption{Types of graphs in respect to edge distinctness.}\n        \\label{fig:graphs_types}\n      \\end{figure}\n\n      If $(u, v)$ is an edge in an undirected graph then we call $u$ a \\emph{neighbour} of $v$ and vice versa. Then we call the number of such neighbours a \\emph{degree} of a vertex. In directed graphs however, if $u \\rightarrow v$ is a directed edge, then we call $u$ the \\emph{predecessor} of $v$, which in turn we call a \\emph{successor} of $u$. The \\emph{in-degree} of a vertex is the number of predecessors and the \\emph{out-degree} of a node is the number of its successors. It is important to note that given $u$ and $v$ and if $u \\rightarrow v$ and $v \\rightarrow u$ then $u \\leftrightarrow v$.\n\n      A graph $H = (U, D)$ is a \\emph{subgraph} of $G = (V, E)$ if $U \\subseteq V$ and $D \\subseteq E$.\n\n    \\subsection{Paths}\n\n      \\subsubsection{Path}\n\n        A \\emph{path} is a sequence of edges where each successive edge share a vertex and all other edges have no vertices in common.\n\n      \\subsubsection{Cycle}\n\n        A \\emph{cycle} is a path which starts and ends at the same vertex and has at least one edge.\n        \n      \\begin{figure}[H]\n        \\centering\n        \\begin{minipage}[b]{0.43\\textwidth}\n          \\centering\n          \\includegraphics[width=\\textwidth]{chapters/02_problem_definition/path}\n          \\captionof{figure}{A path.}\n          \\label{fig:path}\n        \\end{minipage}\n        \\qquad\\qquad\n        \\begin{minipage}[b]{0.3\\textwidth}\n          \\centering\n          \\includegraphics[width=\\textwidth]{chapters/02_problem_definition/cycle}\n          \\captionof{figure}{A cycle.}\n          \\label{fig:cycle}\n        \\end{minipage}\n      \\end{figure}\n\n      \\subsubsection{Tree}\n\n        A \\emph{tree} is a special graph that is a connected acyclic graph. A tree is also a minimal connected graph, meaning that removing any of the edges will make the graph disconnected.\n\n      \\subsubsection{Spanning tree}\n\n        A \\emph{spanning tree} of graph $G$ is a subgraph that is a tree and contains all vertices of $G$. Obviously, no spanning trees exist for disconnected graphs.\n        \n      \\begin{figure}[H]\n        \\centering\n        \\begin{minipage}[b]{0.35\\textwidth}\n          \\centering\n          \\includegraphics[width=\\textwidth]{chapters/02_problem_definition/tree}\n          \\captionof{figure}{A tree.}\n          \\label{fig:tree}\n        \\end{minipage}\n        \\qquad\n        \\begin{minipage}[b]{0.55\\textwidth}\n          \\centering\n          \\includegraphics[width=0.7\\textwidth]{chapters/02_problem_definition/tree_spanning}\n          \\captionof{figure}{Spanning tree (bold edges) of grid graph.}\n          \\label{fig:tree_spanning}\n        \\end{minipage}\n      \\end{figure}\n    \n    \\subsection{Weighted graph}\n    \n      A \\emph{weighted graph} is a graph that associates a label---called \\emph{weight}---with every edge in the graph. Weights of edges are usually represented with real numbers. The \\emph{weight of a path} in such graph is the sum of the edge weights of the edges forming a path. A non-edge has sometimes a special weight assigned with a value of infinity. Weight can also represent \\emph{costs}, then words are used instead of numeric weight. A graph is always assumed to be unweighted unless otherwise has been stated.\n    \n    \\subsection{Graph isomorphism}\n        \n      An \\emph{isomorphism} of graphs $G$ and $H$ is a bijection between the vertices of $G$ and $H$\n      \\begin{equation}\n        f: V(G) \\rightarrow V(H)\\mbox{,}\n      \\end{equation}\n      such that an edge exists between any two vertices $u$ and $v$ of $G$ if and only if an edge exists between $f(u)$ and $f(v)$ in graph $H$. A correspondence of this kind is commonly called \\textquote{edge-preserving bijection,} where isomorphisms are \\textquote{structure-preserving bijections} in general notion.\n        \n      The above definition assumes that graphs are undirected and unweighted. However, a different definitions of isomorphism may be applied to other types of graphs, by adding the requirements to preserve the corresponding additional elements of structure like link directions, weights, \\emph{etc.}, with the following exception in respect to graph labelling. If labels in graph are uniquely taken from the integer range $1,\\ldots,n$, where $n$ is the number of the vertices of the graph, two labeled graphs will be isomorphic if the corresponding underlying unlabelled graphs are isomorphic.\n      \\begin{table}[H]\n        \\centering\n        \\begin{minipage}[h]{0.3\\textwidth}\n          \\centering\n          \\includegraphics[width=0.55\\textwidth]{chapters/02_problem_definition/isomorphism_1}\n        \\end{minipage}\n        \\quad\n        \\begin{minipage}[h]{0.3\\textwidth}\n          \\centering\n          \\includegraphics[width=\\textwidth]{chapters/02_problem_definition/isomorphism_2}\n        \\end{minipage}\n        \\qquad\n        \\begin{minipage}[h]{0.3\\textwidth}\n          \\begin{tabularx}{\\textwidth}{|C{1}|} \\hline\n          \\rowcolor[gray]{0.75} $f: V(G) \\rightarrow V(H)$\\\\\\hline\n            $f(1) = a$ \\\\\\hline\n            $f(2) = b$ \\\\\\hline\n            $f(3) = c$ \\\\\\hline\n            $f(4) = d$ \\\\\\hline\n            $f(5) = e$ \\\\\\hline\n            $f(6) = f$ \\\\\\hline\n            $f(7) = g$ \\\\\\hline\n            $f(8) = h$ \\\\\\hline\n          \\end{tabularx}\n        \\end{minipage}\n        \\captionof{figure}{Graphs $G$ (left), $H$ (middle) and an isomorphism between them (right).}\n      \\end{table}\n      \n      The concept of \\emph{graph isomorphism} makes it possible to characterise graph properties essential to the structure of the graphs themselves from properties associated with graph representations like graph drawings or data structures for graphs and labelings, \\emph{etc.} For example, if a graph has exactly one cycle, then all graphs in its isomorphism class\\footnote{A collection of graphs isomorphic to each other.} also have exactly one cycle. On the other hand, in the common case when the vertices of a graph are (represented by) the integers $1, 2, \\ldots, N$, then the expression\n      \\begin{equation}\n        \\sum_{v \\in V(G)} v\\cdot\\mbox{deg} v\\mbox{,}\n      \\end{equation}\n      may be different for two isomorphic graphs. But that was mentioned as an exception to the general definition.\n\n    \\subsection{Graph properties}\n\n      In order to focus on the abstract structure of graphs, we define \\emph{graph properties} as maintained under all possible \\emph{isomorphisms} of a graph. However, there is a distinction referred to this term; specifically, a \\emph{property} is usually referred to descriptive characterisations of graphs (i.e. it is a class of graphs), while \\emph{invariant} is used for properties expressed quantitatively (i.e. it is a function from graphs to some other set, like $\\mathbb{N}$). To avoid naming collisions, from now on I will mention only properties and invariants in the former sense. \n\n      \\subsubsection{Graph invariants}\n\n        \\paragraph{Order}\n\n          The \\emph{order} of a graph is the number of vertices in a graph and is denoted by $|V(G)|$ or $|G|$.\n            \n        \\paragraph{Size}\n\n          The \\emph{size} of a graph is the number of its edges\\cite{Harris2000} in a graph and is denoted by $|E(G)|$ or $||G||$. In an undirected graph, there are $0 \\leq E \\leq \\binom{V}{2}$ and in directed graph: $0 \\leq E \\leq V(V-1)$. \n\n        \\paragraph{Eccentricity}    \n\n          The \\emph{eccentricity} $\\epsilon(v)$ of vertex $v$ is the greatest geodesic distance between $v$ and any other vertex.    \n                    \n        \\paragraph{Radius}\n\n          The \\emph{radius} $r$ of a graph is the minimum eccentricity of any vertex in the graph.\n\n        \\paragraph{Diameter}\n        \n          The longest of the shortest path lengths is the \\emph{diameter} $d$ of a graph. It is the maximum eccentricity of any vertex in the graph. In order to find it, one first need to find the shortest path between each pair of vertices; then the greatest length of any of these paths would be the diameter of the graph.\n\n      \\subsubsection{Graph properties}\n\n        \\paragraph{Connected}\n\n          Let $G = (V, E)$ be a graph. A non-empty graph $G$ is \\emph{connected} if any two of its vertices are linked by a path in $G$, i.e. \n          \\begin{equation}\n            \\forall_{i,j \\in \\mathbb{N} \\cap i,j < |G|} \\forall_{v_i \\in V} \\exists_{v_j \\in V} (v_i, v_j) \\in E\\mbox{.}\n          \\end{equation}\n          In other words, we call a graph \\emph{connected} if there is a path from any vertex to any other vertex.\n\n          A maximal connected subgraph of $G$ is a \\emph{component} of $G$. The empty graph has no components since connected graphs are non-empty. \n\n          A graph that is \\emph{disconnected} consists of several \\emph{connected components}. Two vertices are considered to be in the same connected component if there is a path between them.\n\n          $G$ is called $k$\\emph{-connected} (for $k \\in \\mathbb{N}$) if $k < |G|$ and $G - X$ is connected for every $X \\subseteq V$ with $k > |X|$. Every non-empty graph is $0$-connected and $1$-connected graphs are precisely non-trivial connected graphs. The greatest integer $k$ such that $G$ is $k$-connected is the \\emph{connectivity} $\\kappa(G)$ of $G$. Hence graph is disconnected if and only if $\\kappa(G) = 0$. The simplest 2-connected graphs are the cycles; all the others can be inductively constructed by adding paths to cycles.\n\n        \\paragraph{Cyclic}\n        \n          Graph is cyclic when it consists of a single cycle.\n          \n        \\paragraph{Acyclic}\n        \n          A graph is called acyclic if there are no subgraphs that are cycles.\n\n        \\paragraph{Bipartite}\n        \n          We call a graph a \\emph{bipartite} or a \\emph{bigraph} if a graph has vertices that can be divided into two disjoint sets $U$ and $V$ such that the edges only exist between independent vertices in $U$ and $V$ and never between vertices of the same set\\cite{Diestel2012}. Equivalent definition is that a bipartite graph is a graph that does not contain any cycles with odd lengths\\cite{AsratianDenleyHaggkvist1998}. An example of bipartite graph is presented on figure \\ref{fig:cs_network} in section \\ref{sec:cs}.\n\n          The two sets $U$ and $V$ may be thought of as a colouring of the graph with two colours: if one colours all nodes in $U$ blue, and all nodes in $V$ green, each edge has endpoints of differing colours, as is required in the graph colouring problem\\cite{AsratianDenleyHaggkvist1998,Scheinerman2012}. In contrast, such a colouring is impossible in the case of a non-bipartite graph, such as a triangle: after one node is coloured blue and another green, the third vertex of the triangle is connected to vertices of both colours, preventing it from being assigned either colour.\n          \n          A bigraph with partition sets $U$ and $V$ with $E$ denoting edges of the graph is often written as $G=(U,V,E)$. If such graph is disconnected, it may have more than one bipartition;\\cite{ChartrandZhang2008}. In this case, the $(U,V,E)$ notation is helpful in specifying one particular bipartition that may be of importance in an application.\n          \n          Bipartite graphs very often arise naturally when dealing with real-world examples. For instance, a graph of movie actors and movies, with an edge between an actor and a movie if the actor has starred in that movie. It is a classic example of an affiliation network, which is a type of bigraph used in analysis of social networks\\cite{WassermanFaust1994}.\n\n  \\section{Graphs representation}\n\n    Graphs are usually visualised as \\emph{embeddings}. An embedding of a graph $G(V, E)$ is representation of $G$ on $\\Sigma$ plane in which all $v \\in V$ are associated to points on $\\Sigma$ and each of $e \\in E$ are arcs or straight line segments between points corresponding to vertices at both ends of $e$. If no two arcs ever intersect, the embedding of a graph is called \\emph{planar}, otherwise it is called a \\emph{non-planar}. Because the same graph can have many embeddings that are different, it is important not to confuse the particular embedding with a graph itself. In particular, planar graphs can have non-planar embeddings too.\n\n    There are many other ways of graph visualisation, but apart from the above and below, they are not useful for analysis of the data that is a subject of this thesis.\n\n    Graphs can be explicitly represented by either \\emph{adjacency matrices} or \\emph{adjacency lists}.\n        \n    The adjacency matrix of a graph $G$ is a $|V| \\times |V|$ matrix of indicator variables. Each entry in this matrix indicates whether a particular edge between indexes is or is not in graph $G$:\n    \\begin{equation}\n      A[i, j] = [(i, j) \\in E] \\mbox{.}\n    \\end{equation}\n    For undirected graph, similar to the edges, the adjacency matrix is always symmetric: $A[i, j] = A[j, i]$. In simple graphs, diagonal entries in $A$ are all zeros since loops are not allowed. The most valuable property of adjacency matrix is that we can decide in $\\Theta(1)$ time whether two arbitrary vertices are connected by an edge just by looking at the appropriate elements of the matrix. We also can scan for a list of all vertex neighbours by looking at the corresponding row (or column), which will require $\\Theta(V)$ time. The main disadvantage is that this matrix will always take $\\Theta(V^2)$ space regardless of how many edges the graph really have. This makes adjacency matrices efficient for \\emph{dense} graphs.\n    \\begin{table}[H]\n        \\centering\n        \\begin{minipage}[b]{0.3\\textwidth}\n          \\centering\n          \\includegraphics[width=0.8\\textwidth]{chapters/02_problem_definition/adjacency}\n          \\captionof{figure}{Graph $G$.}\n        \\end{minipage}\n        \\quad\n        \\begin{minipage}[b]{0.33\\textwidth}\n          $$\\begin{pmatrix}\n            0 & 1 & 0 & 0 & 1 \\\\\n            1 & 0 & 1 & 0 & 0 \\\\\n            0 & 1 & 0 & 1 & 1 \\\\\n            0 & 0 & 1 & 0 & 0 \\\\\n            1 & 0 & 1 & 0 & 0\n          \\end{pmatrix}$$\n          \\captionof{figure}{Adjacency matrix.}\n        \\end{minipage}\n        \\qquad\n        \\begin{minipage}[b]{0.27\\textwidth}\n          \\begin{tabularx}{\\textwidth}{L{1}}\n            $1 \\to 2 \\to 5$ \\\\\n            $2 \\to 1 \\to 3$ \\\\\n            $3 \\to 2 \\to 4 \\to 5$ \\\\\n            $4 \\to 3$ \\\\\n            $5 \\to 1 \\to 3$\n          \\end{tabularx}\n          \\caption{Adjacency list.}\n        \\end{minipage}\n      \\end{table}\n\n    On the other hand, adjacency lists are good when dealing with \\emph{sparse} graphs (graphs with relatively small number of edges). Adjacency list is an array of linked lists (one per vertex). For undirected graphs each edge $(u, v)$ is stored twice: once in $u\\mbox{'s}$ neighbourhood and once in $v\\mbox{'s}$ neighbour list. For directed graph each edge is stored only once. Either way, adjacency list will take $O(V+E)$ space; listing all the neighbours of $v$ vertex takes $O(1+\\mbox{deg}\\,v)$ time (by scanning the neighbour list). We can determine whether $(u, v)$ is an edge by scanning neighbours of $u$ in $O(1+\\mbox{deg}\\,u)$ time.\n\n", "meta": {"hexsha": "16795a73f14a791110a021e858740e6bedbbe120", "size": 17724, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/chapters/02_problem_definition/graph_theory.tex", "max_stars_repo_name": "michalochman/complex-networks", "max_stars_repo_head_hexsha": "49337376e32fac253d8de9919d5acd00a9b566bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/chapters/02_problem_definition/graph_theory.tex", "max_issues_repo_name": "michalochman/complex-networks", "max_issues_repo_head_hexsha": "49337376e32fac253d8de9919d5acd00a9b566bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/chapters/02_problem_definition/graph_theory.tex", "max_forks_repo_name": "michalochman/complex-networks", "max_forks_repo_head_hexsha": "49337376e32fac253d8de9919d5acd00a9b566bb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.7795275591, "max_line_length": 734, "alphanum_fraction": 0.673493568, "num_tokens": 4775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7262757433763094}}
{"text": "\n\\subsection{Lindelöf space}\n\nIn a Lindelöf space all open covers have countable subcovers.\n\nThis is weaker than compactness, which requires that every open cover has a finite subcover.\n\n", "meta": {"hexsha": "a348e996847bc1bc9ad393772dc3d8e9288a0303", "size": 187, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/topologyFinite/07-01-lindelof.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/topologyFinite/07-01-lindelof.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/topologyFinite/07-01-lindelof.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.375, "max_line_length": 92, "alphanum_fraction": 0.8021390374, "num_tokens": 46, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7981867705385763, "lm_q1q2_score": 0.7262757346399346}}
{"text": "\\section{Recurrent neural networks}\n\\label{sec:RNNs}\n\nThe nonlinear filtering algorithm that we choose to explore is the recurrent neural network (RNN). RNN's have advanced the state-of-the-art in many sequence and time-series processing tasks \\cite{Greff2017}. (Examples include speech and language modelling \\cite{LeCun2015,Goodfellow2016}; protein structure prediction \\cite{Sonderby2014}; and diagnosis prediction from intensive care unit time series \\cite{Lipton2015}).\\footnotemark{} Relevant for SWR detection, RNN's can process multi-channel time-series, and calculating a new output sample has a relatively low cost\\footnote{In contrast with very deep fully connected or convolutional neural networks.}, which is beneficial for real-time operation.\n\n\\footnotetext{For the reader with an interest in neuroscience: RNNs have recently been used in various computational studies. Examples include \\cite{Cueva2018} and \\cite{Banino2018}, where an RNN was trained on a navigational task, after which the entries of the internal state vector of the RNN exhibited grid-cell-like activation patterns; \\cite{Song2017}, who combined reinforcement learning theory with RNNs to model reward seeking and value-based computations; \\cite{Li2017}, where RNNs were used to quantify and classify behaviour of the \\emph{C. Elegans} model organism; and \\cite{Guclu2017}, who modelled the fMRI hemodynamic response using an RNN. For an overview of artifical neural networks in general as models in neuroscience, see \\cite{Kriegeskorte2015}.}\n\n\nA recurrent neural network is a nonlinear dynamical system, driven by an input signal $\\z_t \\in \\reals^C$. In the case of SWR detection, $\\z_t$ is the multichannel LFP recording, with $C$ the number of channels. The RNN maintains an internal state vector $\\h_t \\in \\reals^M$, which is updated at each discrete time step $t$ as:\n%\n\\begin{equation}\n\\label{eq:RNN_f}\n\\h_t = f(\\h\\prev, \\z_t).\n\\end{equation}\n%\n$f$ is a nonlinear function, parametrised by the coefficients of several affine transformations\\footnote{Linear transformations (rotate, shear, scale), plus translations.} (see \\cref{sec:GRU_eqs} for the complete update equations). The state vector $\\h_t$ allows the RNN to maintain an efficient and task-relevant memory of past input samples \\cite{LeCun2015}.\\footnotemark{} We can read out the state vector of the RNN to obtain an output time series $n_t \\in \\reals$, with\n%\n\\begin{equation}\n\\label{eq:RNN_g}\nn_t = g(\\h_t),\n\\end{equation}\n%\nwhere $g$ is again a parametrized nonlinear function.\n\n\\footnotetext{The vector $\\h_t$ is also called the `hidden state', and its $M$ entries are sometimes called `hidden units', `neurons', or `memory cells'.}\n\nBy tuning the coefficients of the affine transformations in $f$ and $g$ in an offline training phase, we can change the behaviour of the RNN so that its output $n_t$ for a given input signal $\\z_t$ approaches a desired output $y_t$. RNN's are thus also a data-driven algorithm. (See \\cref{sec:RNN-optim} for a description of this training phase, which involves the so called 'backpropagation through time' method). In the case of SWR detection, we can design a training signal $y_t$ that is for examples $1$ during SWR events in $\\z_t$, and $0$ otherwise (see \\cref{sec:data-driven-algorithms}). If we avoid overfitting to the training data, we can use the trained RNN to detect SWR's in unseen signals $\\z_t$. This is, in short, the proposed method of SWR detection in this chapter.\n", "meta": {"hexsha": "da3cc865c5c86dc9028aebd54ef9e61aeed7649d", "size": 3475, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/RNN/RNNs.tex", "max_stars_repo_name": "tfiers/master-thesis", "max_stars_repo_head_hexsha": "3e97128eeb18827b03da90817fe6f6985c84ad80", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-23T01:39:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-23T01:39:24.000Z", "max_issues_repo_path": "modules/RNN/RNNs.tex", "max_issues_repo_name": "tfiers/master-thesis", "max_issues_repo_head_hexsha": "3e97128eeb18827b03da90817fe6f6985c84ad80", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 46, "max_issues_repo_issues_event_min_datetime": "2018-09-18T16:38:12.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-10T22:37:35.000Z", "max_forks_repo_path": "modules/RNN/RNNs.tex", "max_forks_repo_name": "tfiers/master-thesis", "max_forks_repo_head_hexsha": "3e97128eeb18827b03da90817fe6f6985c84ad80", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 124.1071428571, "max_line_length": 783, "alphanum_fraction": 0.7807194245, "num_tokens": 891, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970779778825, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7261836556564996}}
{"text": "\\section*{Regression}\n\\subsection*{Linear Regression}\nError: $\\hat{R}(w) = \\sum_{i=1}^n (y_i - w^Tx_i)^2 = ||Xw-y||^2_2$\\\\\n$w^* = \\underset{w}{\\operatorname{argmin}} \\sum_{i=1}^n (y_i - w^Tx_i)^2$\\\\\nClosed form: $w^*=(X^T X)^{-1} X^T y$\\\\\n$\\nabla_w \\hat{R}(w) = -2 \\sum_{i=1}^n (y_i-w^T x_i) \\cdot x_i = 2X^T (Xw-y)$\n\n\\subsection*{Convex / Jensen's inequality}\n$\\text{g(x) is convex} \\Leftrightarrow x_1,x_2 \\in \\mathbb{R}, \\lambda \\in [0,1]: g''(x) > 0$\\\\\n$g(\\lambda x_1 + (1-\\lambda) x_2) \\leq \\lambda g(x_1) + (1-\\lambda) g(x_2)$\n\n\\subsection*{Gradient Descent}\n1. Start arbitrary $w_o \\in \\mathbb{R}$\\\\\n2. For $t = 1,2,...$ do $w_{t+1} = w_t - \\eta_t \\nabla \\hat{R}(w_t)$\n\n\\subsection*{Expected Error (True Risk)}\nAssumption: data set generated iid: $R(w) =$\\\\ \n$\\int P(x,y) (y-w^Tx)^2 \\partial x \\partial y = \\mathbb{E}_{x,y}[(y-w^Tx)^2]$\\\\\n$\\hat{R}_D(w) = \\frac{1}{|D|}\\sum_{(x,y)\\in D} {(y-w^Tx)^2}$ (estim. error)\n\n\\subsection*{Gaussian/Normal Distribution}\n$\\sigma =$ standard deviation, $\\sigma^2 =$ var., $\\mu =$ mean:\\\\\n$f(x) = \\frac{1}{\\sqrt{2\\pi\\sigma^2}} exp(-\\frac{(x-\\mu)^2}{2\\sigma^2})$\n\n\\subsection*{L2-reg: Ridge Regression}\nRegularization: $\\underset{w}{\\operatorname{min}} \\sum \\limits_{i=1}^n (y_i - w^Tx_i)^2 + \\lambda ||w||_2^2$\\\\\nClosed form solution: $w^*=(X^T X + \\lambda I)^{-1} X^T y$\\\\\n$(X^T X + \\lambda I)$ always invertible.\\\\\nGradient: $\\nabla_w \\hat{R}(w) = -2 \\sum \\limits_{i=1}^n (y_i-w^T x_i) \\cdot x_i + 2 \\lambda w$\n\n%\\subsection*{L1-regularized regression (the Lasso)}\n%Regularization: $\\underset{w}{\\operatorname{min}} \\sum \\limits_{i=1}^n (y_i - w^Tx_i)^2 + \\lambda ||w||_1$\\\\\n%Encourages coefficients to be exactly 0.\n\n\\subsection*{Standardization}\nGoal: each feature: $\\mu = 0$, unit $\\sigma^2$: $\\tilde{x}_{i,j} = \\frac{(x_{i,j}-\\hat{\\mu}_j)}{\\hat{\\sigma}_j}$\\\\\n$\\hat{\\mu}_j = \\frac{1}{n}\\sum_{i=1}^n x_{i,j}$, $\\hat{\\sigma}_j^2 = \\frac{1}{n}\\sum_{i=1}^n {(x_{i,j}-\\hat{\\mu}_j)}^2$ \n\n\n%\\subsection*{Multivariate Gaussian}\n%$\\sigma =$ covariance matrix, $\\mu$ = mean\\\\\n%$f(x) = \\frac{1}{2\\pi \\sqrt{|\\Sigma|}} e^{- \\frac{1}{2} (x-\\mu)^T \\Sigma^{-1} (x-\\mu)}$\n\n%\\subsection*{Regularization}\n%The error term $L$ and the regularization $C$ with regularization parameter $\\lambda$: $\\min \\limits_w L(w) + \\lambda C(w)$\\\\\n%L1-regularization for number of features \\\\\n%L2-regularization for the length of $w$\n\n%my idea\n%\\subsection*{Regularization}\n%A lot of supervised learning problems can be written in this way: $\\lambda$: $\\min \\limits_w \\hat{R}(w) + \\lambda C(w)$\\\\", "meta": {"hexsha": "ddc83d97d4487105438536d0b543a91f338be507", "size": 2509, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/Regression.tex", "max_stars_repo_name": "meck93/intro_ml_ethz", "max_stars_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-04-24T14:58:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-19T14:02:08.000Z", "max_issues_repo_path": "source/Regression.tex", "max_issues_repo_name": "meck93/intro_ml_ethz", "max_issues_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/Regression.tex", "max_forks_repo_name": "meck93/intro_ml_ethz", "max_forks_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.1960784314, "max_line_length": 126, "alphanum_fraction": 0.6145874851, "num_tokens": 1035, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897475985937, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7261424445801651}}
{"text": "The Self Organizing Map, SOM, introduced by Kohonen is a\nnon-supervised neural\nlearning algorithm. The map is composed of neighboring cells which are\nin competition by means of mutual interactions and they adapt in order\nto match characteristic patterns of the examples given during the\nlearning. The SOM is usually on a plane (2D).\n\nThe algorithm implements a nonlinear projection from a high\ndimensional feature space to a lower dimension space, usually 2D. It\nis able to find the correspondence between a set of structured data\nand a network of much lower dimension while keeping the topological\nrelationships existing in the feature space. Thanks to this\ntopological organization, the final map presents clusters and their\nrelationships. \n\n%\\subsection{The algorithm}\nKohonen's SOM is usually represented as an array of cells where each\ncell is, $i$, associated to a feature (or weight) vector  $\\underline m_i = \\left[m_{i1},m_{i2},\\cdots,m_{in}\\right]^T\\in\n\\mathbb{R}^n$ (figure \\ref{carte}).\\\\\n\\begin{figure}\n\\center\n\\includegraphics[width=0.45\\textwidth]{carte.eps}\n\\itkcaption[Kohonen's Self Organizing Map]{Kohonen's Self Organizing Map}\n\\label{carte}\n\\end{figure}\n\nA cell (or neuron) in the map is a good detector for a given input\nvector $\\underline x = \\left[x_{1},x_{2},\\cdots,x_{n}\\right]^T\\in\n\\mathbb{R}^n$ if the latter is {\\em close} to the former. This\ndistance between vectors can be represented by the scalar product \n$\\underline{x}^T\\cdot\\underline{m_i}$, but for most of the cases other\ndistances can be used, as for instance the Euclidean one. The cell\nhaving the weight vector closest to the input vector is called the\n{\\em winner}.\n\n%\\subsubsection{Learning}\nThe goal of the learning step is to get a map which is representative\nof an input example set. It is an iterative procedure which consists\nin passing each input example to the map, testing the response of each\nneuron and modifying the map to get it closer to the examples.\n\n\\begin{algo}\nSOM learning:\n\\begin{enumerate}\n\\item $t=0$.\n\\item Initialize the weight vectors of the map (randomly, for instance).\n\\item While $t<$ number of iterations, do:\n\\begin{enumerate}\n\\item $k=0$.\n\\item While $k<$ number of examples, do:\n\\begin{enumerate}\n\\item Find the vector $\\underline{m}_i(t)$ which minimizes the distance\n$d(\\underline{x}_k,\\underline{m}_i(t))$\n\\item For a neighborhood $N_c(t)$ around the winner cell, apply the transformation:\n\\begin{equation}\n\\underline{m}_i(t+1)=\\underline{m}_i(t)+\\beta(t)\\left[\\underline{x}_k(t)-\\underline{m}_i(t)\\right]\n\\label{khoupdate}\n\\end{equation}\n\\item $k=k+1$\n\\end{enumerate}\n\\item $t=t+1$.\n\\end{enumerate}\n\n\\end{enumerate}\n\\end{algo}\n\n\nIn \\ref{khoupdate}, $\\beta(t)$ is a decreasing function with the\ngeometrical distance to the winner cell. For instance:\n\\begin{equation}\n\\beta(t)=\\beta_0(t)e^{-\\frac{\\parallel \\underline{r}_i -  \\underline{r}_c\\parallel^2}{\\sigma^2(t)}},\n\\end{equation}\nwith $\\beta_0(t)$ and $\\sigma(t)$ decreasing functions with time and\n$\\underline{r}$ the cell coordinates in the output -- map -- space.\\\\\n\nTherefore the algorithm consists in getting the map closer to the\nlearning set. The use of a neighborhood around the winner cell allows\nthe organization of the map into areas which specialize in the\nrecognition of different patterns. This neighborhood also ensures that\ncells which are topologically close are also close in terms of the\ndistance defined in the feature space.\n\n", "meta": {"hexsha": "f61abf0d5a4e50c124a2fa5b21198a74e24efbc5", "size": 3429, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/SoftwareGuide/Latex/Kohonen.tex", "max_stars_repo_name": "xcorail/OTB", "max_stars_repo_head_hexsha": "092a93654c3b5d009e420f450fe9b675f737cdca", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-02-13T14:48:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-03T02:54:28.000Z", "max_issues_repo_path": "Documentation/SoftwareGuide/Latex/Kohonen.tex", "max_issues_repo_name": "xcorail/OTB", "max_issues_repo_head_hexsha": "092a93654c3b5d009e420f450fe9b675f737cdca", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2015-10-14T10:11:38.000Z", "max_issues_repo_issues_event_max_datetime": "2015-10-15T08:26:23.000Z", "max_forks_repo_path": "Documentation/SoftwareGuide/Latex/Kohonen.tex", "max_forks_repo_name": "xcorail/OTB", "max_forks_repo_head_hexsha": "092a93654c3b5d009e420f450fe9b675f737cdca", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-01-17T10:36:14.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-03T02:54:36.000Z", "avg_line_length": 41.313253012, "max_line_length": 121, "alphanum_fraction": 0.7629046369, "num_tokens": 918, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755218, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7261420298499002}}
{"text": "\\chapter{More group structure of the cube}\\label{chap:structure}\nIn this chapter, we dive into more details about the group structure of Rubik's Cubes and explain how to find the group size of an arbitrarily large Rubik's Cube. While giving the definition of the semi-direct group, we illustrate the explicit structure of $G_3$ to build up for the next chapter.\n\n\\section{Size of the Rubik's Cube group}\n\\par In Chapter~\\ref{chap:encryption}, we mentioned that there exist some illegal states of the Rubik's Cube $C_3$ and thus the group $G_3$ constructed by states of $C_3$ is a subgroup of $S_{48}$. We now want to show how to find the size of group $G_3$ and we expand the method to illustrate how to calculate size of group $G_n$ constructed by an arbitrary large cube $C_n$.\n\\par Recall Figure~\\ref{fig:cube-type}, we showed that there are 8 corner cubes in $C_3$. The 8 corner cubes can freely exchange their locations and they can be arranged in $8!$ ways. When we fix locations of the 8 corner cubes, each of them can be arranged in 3 different orientations, giving $3^8$ possibilities for each ordering of the corner pieces. Similarly, there are 12 edge cubes that can freely exchange their locations and the can be arranged in $12!$ ways. When we fix locations of the 12 edge cubes, each of them can be arranged in 2 different orientations, giving $2^{12}$ possibilities for each permutation of the edge cubes. However, further reductions are required due to the structure of the Rubik's Cube.\n\\par The reason we need to further reduce the group size is explicitly explained in Chapter 11 in paper\\cite{janet}. We will not repeat all the details presented there but give the essential part of the argument. For the 8 corner cubes of $C_3$, only 7 of them can be oriented independently, meaning the orientation of the 8th corner cube depends on the preceding seven. Hence, when we fix locations for all 8 corner cubes, they can have at most $3^7$ possible different orientations. Similarly, when we determine orientations for 11 of the 12 edge cubes, the orientation of the last edge cube will be fixed. It follows that there are $2^{11}$ possible orientations for each permutation of the edge cubes. So for now, the order of $C_3$ can be calculated as $8! \\cdot 3^7 \\cdot 12! \\cdot 2^{11}$. In \\cite{janet}, a labelling system on the cube was created, and the authors proved that any permutation of the edges must be an even permutation. Therefore we must reduce this number by half. Finally, we find the order of $C_3$ is $8! \\cdot 3^7 \\cdot 12! \\cdot 2^{10} = 43,250,003,274,489,856,000$.\n\\par For a hint of the proof for above statements, recall that in Chapter~\\ref{chap:encryption}, we defined each valid state as a shuffling result of a series of fundamental moves. By analyzing properties of those permutations, we can obtain a good understanding on how to determine if a state of $C_3$ is valid.\n\\par Now we can explain how to find group order of $G_n$ for a arbitrarily large cube $C_n$. The calculation for corner cubes will stay true for any cube $C_n$ but the calculation for edge cubes will change since cubes with different side lengths have different number of edge cubes and for larger cubes, there will be two types of edge cubes. We also need to introduce a couple more different small cubes with single visible colored piece. We can use $C_7$ to illustrate all types of small cubes. Consider Figure~\\ref{fig:7-center-corner} as one face of the cube. The small cubes colored in blue are the corner cubes and those colored in yellow are the fixed center cubes. Those small cubes behave the same as they are in $C_3$.\n\\begin{figure}[ht]\n    \\centering\n    \\begin{minipage}{0.45\\textwidth}\n        \\centering\n        \\includegraphics[width=4cm]{figures/structure/7_grid_center_corner.png}\n        \\caption{Center and corner cubes}\\label{fig:7-center-corner}\n    \\end{minipage}\n    \\begin{minipage}{0.45\\textwidth}\n        \\centering\n        \\includegraphics[width=4cm]{figures/structure/7_grid_edge.png}\n        \\caption{Edge cubes}\\label{fig:7-edge}\n    \\end{minipage}\n\\end{figure}\nIn Figure~\\ref{fig:7-edge}, we are showing the two types of edge cubes. The ones colored in green are called \\textit{wing edges} and the ones colored in grey are called \\textit{middle edges}. Clearly, when we shuffle the cube, the middle edge will only permute with other middle edges and the wing edges will permute with other wing edges. The middles edges in $C_7$ generate exactly the same amount of permutations and orientations as they are in $C_3$. We can further split the wing edges into two sets as shown in Figure~\\ref{fig:7-wing-edge}. The yellow wing edges will only permute with other yellow wing edges and the blue ones will permute with other blue ones. For an arbitrary large cube $C_n$, we can calculate the number of sets of wing edges it has by finding $\\lfloor \\frac{n - 2}{2} \\rfloor$ and each set of wing edges has $2 \\cdot 12 = 24$ small cubes. Due to the inner structure of Rubik's Cubes, different from the middles edges, each one of the wing edges has only one possible orientation when it is at fixed locations.\n\\begin{figure}[ht]\n    \\centering\n    \\begin{minipage}{0.45\\textwidth}\n        \\centering\n        \\includegraphics[width=4cm]{figures/structure/7_grid_wing_edge.png}\n        \\caption{Wing edges}\\label{fig:7-wing-edge}\n    \\end{minipage}\n    \\begin{minipage}{0.45\\textwidth}\n        \\centering\n        \\includegraphics[width=4cm]{figures/structure/7_grid_plus_center.png}\n        \\caption{$+$ centers}\\label{fig:7-plus-center}\n    \\end{minipage}\n\\end{figure}\n\\par Besides the fixed centers, there are three more types of small cubes with only one visible piece we want to introduce. The ones displayed in Figure~\\ref{fig:7-plus-center} are called the ``\\textit{$+$ centers}'' since they form the $+$ shape. Similar to the wing edges, they can be further split into two sets and those pieces only permute with same colored ones. Secondly, we want to show the ``\\textit{$\\times$ centers}''. As displayed in Figure~\\ref{fig:7-x-center}, those pieces form the $\\times$ shape and they can be split to two sets as well.\n\\begin{figure}[ht]\n    \\centering\n    \\begin{minipage}{0.45\\textwidth}\n        \\centering\n        \\includegraphics[width=4cm]{figures/structure/7_grid_x_center.png}\n        \\caption{$\\times$ centers}\\label{fig:7-x-center}\n    \\end{minipage}\n    \\begin{minipage}{0.45\\textwidth}\n        \\centering\n        \\includegraphics[width=4cm]{figures/structure/7_grid_oblique_center.png}\n        \\caption{Oblique centers}\\label{fig:7-oblique-center}\n    \\end{minipage}\n\\end{figure}\nThe number of sets of $+$ centers and $\\times$ centers of an arbitrarily large cube $C_n$ can be calculated by the equation defined above for wing edges, and each set of $+$ centers or $\\times$ centers contains $4 \\cdot 6 = 24$ small cubes. Finally, the pieces that are not covered by the $+$ shape and the $\\times$ shape are denoted the oblique centers. They are displayed in Figure~\\ref{fig:7-oblique-center}. Though these three type of centers pieces are different, they permute in a similar fashion; they can change their locations freely but not their orientations.\n\\par We can further differentiate odd cubes and even cubes. Since $C_7$ is an odd cube, all types of small cubes exist within it. For an even cube, there will be no middle edges and ``$+$ centers'' since the fixed center piece does not exist. Therefore, there is no preferred orientation of an even cube, and some sequences of fundamental movements will be equivalent to rotating the entire cube in a three-dimensional space. Thus, the number of permutations is reduced by a factor of 24. This is because all 24 possible positions and orientations of the first corner are equivalent because of the lack of fixed centres. After addressing all types of small cubes and the difference between odd and even cubes, we now have all the tools we need to calculate group size of $G_n$ for an arbitrary cube $C_n$. In Table~\\ref{tab:permutation}, we show details of this calculation. \n\\begin{table}[ht]\n    \\centering\n    \\begin{tabular}{|p{3cm}|p{11cm}|}\n        \\hline Type of cube & Number of orderings \\\\ \\hline\n        \\hline Corner cubes & All cubes can arrange their corners in $8! \\cdot 3^7$ different ways.  \\\\ \n        \\hline Middle edges & All odd cubes can arrange their middles edges in $12! \\cdot 2^{10}$ ways. Since even cube does not have middle edges, an arbitrary cube $C_n$ has $(12! \\cdot 2^{10})^{n \\mod 2}$ ways to order its middles edges. \\\\ \n        \\hline Wing edges & An arbitrary cube $C_n$ has $(24!)^{\\lfloor \\frac{n - 2}{2} \\rfloor}$ ways to order its wing edges. \\\\ \n        \\hline Fixed centers & Only odd cubes have fixed centers and since they are fixed, they do not any anymore possible orderings to the calculation. \\\\ \n        \\hline \\pbox{3cm}{\\vspace*{0.1cm} ``$+$ centers'' \\\\ ``$\\times$ centers'' \\\\  Oblique centers \\vspace*{0.1cm}} & \\vspace*{-0.8cm} Since those center pieces permute in a similar fashion, we can put them together to calculate the number of orderings they generate. The details of this calculation can be found in paper\\cite{size} and the result is given as $(\\frac{24!}{(4!)^6})^{\\lfloor (\\frac{n - 2}{2})^2 \\rfloor}$. \\\\ \\hline\n    \\end{tabular}\n    \\caption{Number of permutation different type of small cubes generates}\\label{tab:permutation}\n\\end{table}\nFinally we can put everything together and the order of group $G_n$ for states of an arbitrary Rubik's Cube $C_n$ can be calculated by the following function:\n$$f(n) = 8! \\cdot 3^7 \\cdot (12! \\cdot 2^{10})^{n \\mod 2} \\cdot (24!)^{\\lfloor \\frac{n - 2}{2} \\rfloor} \\cdot (\\frac{24!}{(4!)^6})^{\\lfloor (\\frac{n - 2}{2})^2 \\rfloor} \\cdot 24^{-((n + 1) \\mod 2)}$$\nIn Table~\\ref{tab:cube-size}, we show some calculations we obtained by using the equation above to demonstrate how fast the corresponding group size increases when the side length of a Rubik's Cube increase.\n\\begin{table}[ht]\n    \\centering\n    \\begin{tabular}{|c|c|}\n        \\hline Cube group & Group size \\\\\n        \\hline $G_3$ & $4.325 \\times 10^{19}$ \\\\\n        \\hline $G_4$ & $7.401 \\times 10^{45}$ \\\\\n        \\hline $G_5$ & $2.829 \\times 10^{74}$ \\\\\n        \\hline $G_6$ & $1.572 \\times 10^{116}$ \\\\\n        \\hline $G_7$ & $1.950 \\times 10^{160}$ \\\\ \\hline\n    \\end{tabular}\n    \\caption{Group size of different Rubik's Cubes}\n    \\label{tab:cube-size}\n\\end{table}\nThis quantifies our claim in Chapter~\\ref{chap:encryption} that the key space explodes as the size of our cube increases. The function $f(n)$ gives us the size of an arbitrary $G_n$, but the exact algebraic structure is not known for $n > 3$.\n\n\\section{Semi-direct product of a group}\nThe group structure of $G_3$ is well understood and it can be expressed as a semi-direct product of other common groups such as the cyclic group. Before we show how to represent $C_3$, we need to review some group theory knowledge, and some definitions here will help in understanding the key exchange protocol in Chapter~\\ref{chap:exchange} as well. \n\\begin{definition} A function $\\phi$ from a group $G$ to a group $H$ is a \\textbf{homomorphism} if $\\phi$ preserves the group operation; that is if $\\phi(ab) = \\phi(a)\\phi(b)$ for all $a, b \\in G$.\n\\end{definition}\n\\begin{definition} An \\textbf{isomorphism} is a homomorphism $\\phi$ from a group $G$ to a group $H$ that is one-to-one and onto.\n\\end{definition}\n\\begin{definition} An \\textbf{automorphism} is an isomorphism from a group $G$ onto itself. The set of automorphisms of a group $G$ is denoted by $Aut(G)$.\n\\end{definition}\n\\begin{definition} The \\textbf{alternating group}, denoted $A_n$ is the group of all even permutations in $S_n$.\n\\end{definition}\n\\begin{definition} Let $G$ be a group and $H$ be a subgroup of $G$, the subgroup $H$ is a \\textbf{normal subgroup} of $G$, denoted by $H \\triangleleft G$, if $\\forall g \\in G$, $gH = Hg$.\n\\end{definition}\n\\begin{definition} Let $G$ and $H$ be two groups. Then the \\textbf{direct product} of $G$ and $H$ is the group $G \\times H$ under the operation $(g_1, h_1) \\cdot (g_2, h_2) = (g_1g_2, h_1h_2)$ where $g_1,g_2 \\in G$ and $h_1,h_2 \\in H$.\n\\end{definition}\n\\begin{definition} Let $H_1$ and $H_2$ be two subgroups of $G$, then $G = H_1 \\rtimes H_2$ is a \\textbf{semi-direct product} if:\n    \\begin{enumerate}\n        \\item $G = H_1H_2$.\n        \\item $H_1 \\cap H_2 = e$, where $e$ is the identity element of $G$.\n        \\item $H_1 \\triangleleft G$.\n    \\end{enumerate}\n\\end{definition}\n\\par We can now describe the group structure of $G_3$. A complete proof can be found in \\cite{janet}, but we will sketch the details here. Let us consider two subgroups of $G_3$. First the subgroup $H_1$ of cube orientations, which leave the position of every small cube fixed but can change their orientations. One can show this subgroup is a normal subgroup of $G$. It can be represented by moves that flip a few edges or twist corners. For example, the move ``$R\\,U\\,D\\,B2\\,U2\\,B'\\,U\\,B\\,U\\,B2\\,D'\\,R'\\,U'$ '' flips two edges. The structure of this group is $\\mathbb{Z}_3^7 \\times \\mathbb{Z}_2^{11}$ since the group of rotations of each corner is a cyclic group of order $3$ and we mentioned that we can determine orientations of 7 among 8 corner cubes freely and the last one will be fixed. The argument for flipping edges is exactly the same.\n\\par In addition, we take the subgroup $H_2$ which permutes the positions of the small cubes but does not change their orientations. Similar to above, this group can be represented by a direct product of two subgroups, which are the group of permutations on the corners $S_8$ and the group of even permutations on the edges $A_{12}$ (because of the even parity). Hence the structure of $H_2$ is $S_8 \\times A_{12}$. Notice that here we do not mind if $H_2$ is a normal subgroup or not.\n\\par Clearly $H_1 \\cap H_2 = e$, where $e$ is the identity in $G_3$, since $H_1$ keeps all small cubes fixed but changes their orientations, whereas $H_2$ always moves the cubes. Since $H_1$ and $H_2$ account for all possible change on the cube $C_3$, $H_1H_2$ can form the entire group $G_3$. It follows that the cube group $G_3$ is isomorphic to the semi-direct product of these two groups:\n$$G_3 = H_1 \\rtimes H_2 \\cong (\\mathbb{Z}_3^7 \\times \\mathbb{Z}_2^{11}) \\rtimes (S_8 \\times A_{12})$$\nBy finding the group order of above semi-direct product, we will again retrieve the same result we found earlier in this chapter. For instance, the largest order of an element in $G_3$ is 1260 and one such element is ``$R\\,U2\\,D'\\,B\\,D'$ ''\\cite{order}. However, we have not yet found a efficient method to generalize those results to other Rubik's Cube groups $G_n$.\n\\par In this chapter, we introduced methods to find group size of $G_n$ of an arbitrary large cube $C_n$. The explosion of the group sizes we observed suggests that larger cubes may make brute force attacks more computationally expensive. Although not known for larger cubes, we are able to give the isomorphism class for $G_3$. Since this additional structure is known, it could open up the door to opportunities to further reduce computation cost of the brute attacks on encryption based on $C_3$.", "meta": {"hexsha": "333369006ff5695d270ac71203ff73aca13eae3e", "size": 15229, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/chapters/structure.tex", "max_stars_repo_name": "Weiqi97/Honor-Thesis", "max_stars_repo_head_hexsha": "eff11dea2fe14a66e787154c9c0bd1ed4b02bd06", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "content/chapters/structure.tex", "max_issues_repo_name": "Weiqi97/Honor-Thesis", "max_issues_repo_head_hexsha": "eff11dea2fe14a66e787154c9c0bd1ed4b02bd06", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "content/chapters/structure.tex", "max_forks_repo_name": "Weiqi97/Honor-Thesis", "max_forks_repo_head_hexsha": "eff11dea2fe14a66e787154c9c0bd1ed4b02bd06", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 139.7155963303, "max_line_length": 1096, "alphanum_fraction": 0.7333377109, "num_tokens": 4212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7261420255161963}}
{"text": "\\documentclass[a4paper,10pt]{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\n\\title{Yet another derivation of the KLT update rule}\n\\author{}\n\n\n\\begin{document}\n\\maketitle\n\nWe want to optimize this function with respect to the displacement d,\n\\begin{equation}\n E(d) = \\sum_{(x,y)\\in W} (I(x,y) - J(x+d_x,y+d_y))^2 \\ .\n\\end{equation}\nWe will do this iterativelly.\n\nAssume that we have a previous guess $\\tilde d$ of the displacement, and we only want to compute the update $\\delta d$ such that\n\\begin{equation}\n d = \\tilde d + \\delta d \\ .\n\\end{equation}\nUsing the notation\n\\begin{equation}\n \\tilde J(x,y) = J(x + \\tilde d_x, y + \\tilde d_y) \\ ,\n\\end{equation}\nthe functional to be optimized at each iteration is\n\\begin{equation}\n E(\\delta d) = \\sum_{(x,y)\\in W} (I(x,y) - \\tilde J(x + \\delta d_x, y + \\delta d_y))^2 \\ .\n\\end{equation}\nThe first order approximation of $\\tilde J$ with respect to  $\\delta d$ is\n\\begin{equation}\n\\begin{split}\n \\tilde J(x + \\delta d_x, y + \\delta d_y)\n   & = \\tilde J(x,y) + \\partial_x \\tilde J(x,y) \\delta d_x + \\partial_y \\tilde J(x,y) \\delta d_y\n\\\\ & = \\tilde J(x,y) + \\nabla \\tilde J(x,y)^T \\delta d \\ .\n\\end{split}\n\\end{equation}\nInserting this into the functional gives\n\\begin{equation}\n E(\\delta d) \\approx \\sum_{(x,y)\\in W} (I(x,y) - \\tilde J(x,y) - \\nabla \\tilde J(x,y)^T \\delta d)^2 \\ .\n\\end{equation}\nDeriving with respect to $\\delta d$ and equalling to 0 gives\n\\begin{equation}\n 0 =\n \\sum_{(x,y)\\in W} (I(x,y) - \\tilde J(x,y)\n          - \\nabla \\tilde J(x,y)^T \\delta d)\n        \\nabla \\tilde J(x,y) \\ ,\n\\end{equation}\nwhich is a 2-vector equallity.  Factorizing $\\delta d$,\n\\begin{equation}\n \\sum_{(x,y)\\in W} \\nabla \\tilde J(x,y) \\nabla \\tilde J(x,y)^T \\  \\delta d\n = \\sum_{(x,y)\\in W} (I(x,y) - \\tilde J(x,y)) \\nabla \\tilde J(x,y)\n\\end{equation}\nwhich is a set of 2 linear equations on $\\delta d$.\n\nWe define now the gradient matrix as\n\\begin{equation}\n Z = \\sum_{(x,y)\\in W} \\nabla \\tilde J(x,y) \\nabla \\tilde J(x,y)^T\n= \\sum_{(x,y)\\in W}\n  \\begin{pmatrix}\n   (\\partial_x \\tilde J)^2\n&  \\partial_x \\tilde J \\partial_y\\tilde J\n\\\\ \\partial_x \\tilde J \\partial_y\\tilde J\n&  (\\partial_y \\tilde J)^2\n  \\end{pmatrix}\n\\end{equation}\nand error vector as\n\\begin{equation}\n \\mathbf e = \\sum_{(x,y)\\in W} (I(x,y) - \\tilde J(x,y)) \\nabla \\tilde J(x,y) \\ .\n\\end{equation}\nThe system to solve at each iteration is\n\\begin{equation}\n Z \\delta d = \\mathbf e \\ .\n\\end{equation}\n\n\n\\section{Implementation Details}\n\\subsection{Smoothing the Images}\nBefore tracking images should be slightly smoothed.  There are two reasons for this:\n\\begin{enumerate}\n \\item The linearization of $J$ only makes sense if $J$ is smooth.\n \\item The tracking equations require to compute the gradient of $J$.  Given sampling of $J$ at a certain scale, there is no way to get its gradient at the same scale with an accurate precision.  We can however compute the gradient at a smoother scale by convolving $J$ with the derivatives of a Gaussian kernel.  This is\n \\begin{equation}\n  \\bar J = G \\star J  \\quad \\text{and} \\quad \\nabla\\bar J = \\nabla G \\star J \\ .\n \\end{equation}\nWhen doing this, we are computing the derivatives of the smooth version $\\bar J$, not the derivatives of $J$.  Therefore, we have to use the smooth version $\\bar J$ in all the equations instead of $J$, if we want the derivatives to be coherent with the image.\n\\end{enumerate}\nSince we smooth $J$, it seems reasonable to also smooth $I$ so that they are at the same scale.\n\nTo sum up, given the two images $I$ and $J$, tracking has to be done over their smoothed versions\n\\begin{equation}\n  \\bar I = G \\star I \\ , \\quad \n  \\bar J = G \\star J  \\quad \\text{and} \\quad\n  \\nabla\\bar J = \\nabla G \\star J \\ .\n\\end{equation}\n\n\n\\end{document}\n", "meta": {"hexsha": "bc8364857d6fc7336259ac2d43ef477213a5458e", "size": 3729, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/notes_on_klt.tex", "max_stars_repo_name": "jackyspeed/libmv", "max_stars_repo_head_hexsha": "aae2e0b825b1c933d6e8ec796b8bb0214a508a84", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 160, "max_stars_repo_stars_event_min_datetime": "2015-01-16T19:35:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T02:55:30.000Z", "max_issues_repo_path": "doc/notes_on_klt.tex", "max_issues_repo_name": "rgkoo/libmv-blender", "max_issues_repo_head_hexsha": "cdf65edbb80d8904e2df9a20116d02546df93a81", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2015-04-04T17:54:35.000Z", "max_issues_repo_issues_event_max_datetime": "2015-12-15T18:09:03.000Z", "max_forks_repo_path": "doc/notes_on_klt.tex", "max_forks_repo_name": "rgkoo/libmv-blender", "max_forks_repo_head_hexsha": "cdf65edbb80d8904e2df9a20116d02546df93a81", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 51, "max_forks_repo_forks_event_min_datetime": "2015-01-12T08:38:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-19T06:37:25.000Z", "avg_line_length": 37.29, "max_line_length": 321, "alphanum_fraction": 0.6763207294, "num_tokens": 1275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436728, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.726123333559001}}
{"text": "\\section{Extended Kalman Filter}\n\\label{ekf_section}\n\nIn estimation theory, the extended Kalman filter (EKF) is the nonlinear version of the Kalman filter which linearizes about an estimate of the current mean and covariance. In the case of well defined transition models, the EKF has been considered to estimate the state. In this system we have a state and an observer these are given by equation.\n$ X=AX +BU + W_d $  and $ Y=CX + W_n $\nIn this $ W_d $ is disturbance and $ W_n $ is the noise by sensor.\nSo Kalman filter is used judges between data be disturbance and noise.\n\n\nIf $W_d >> W_n$ that means disturbance amount is higher than noise hence state estimation can rely more on sensor data for mapping than on previous state. And sensor is more reliable.\n\nif $W_n >> W_d$ that means noise amount is higher than disturbance hence state estimation can rely more on previous plot data for mapping than on sensor. And state is more reliable than sensor.\n\nSo accordingly in paper we learned that non-linear system is defined as.\n\n\\begin{figure}[!htb]\n\\includegraphics[width=\\textwidth]{./figures/EKF.jpg}\n\\caption{Kalman filter state estimation~\\cite{ByBo2015} }\n\\end{figure}\n\n\\begin{algorithm}\n\\caption{Kalman filter algorithm}\\label{alg-gd}\n\\begin{algorithmic}[1]\n\\STATE Kalman Filter \\({(\\mu_{t-1},\\Sigma_{t-1},u_t,z_t)}\\)\n\\STATE \\( {\\mu_{t}}=A_t \\mu_{t-1} + B_t u_t \\)\n\\STATE \\( \\Sigma_{t}=A_t \\Sigma_{t-1} A_t^T +R_t\\)\n\\STATE \\( K_t = \\Sigma_{t} C_t(C_t^T \\Sigma_{t}C_t^T+Q_t)^{-1}\\)\n\\STATE \\( \\mu_{t}=\\mu_{t}+K_t(z_t-C_t \\mu_t) \\)\n\\STATE \\(\\Sigma_{t}=(I-K_t C_t)\\Sigma_{t}\\)\n\\STATE return \\( \\mu_t ,  \\Sigma_t \\)\n\\end{algorithmic}\n\\end{algorithm}\n\nSo now lets take non-linear state equation as follows\n\n\\begin{equation}\n\\overrightarrow{z}_{k+1}= \\overrightarrow{f}_k (\\overrightarrow{z}_k) + v_k \n\\end{equation}\n\n\\begin{equation} \n\\begin{pmatrix}\n  \\overrightarrow{x}_{k+1} \\\\\n  \\overrightarrow{v}_{k+1} \\\\\n  \\overrightarrow{a}_{k+1} \\\\\n  \\overrightarrow{\\lambda}_{k+1} \\\\\n \\end{pmatrix}\n =\n \\begin{pmatrix}\n  I_3 & \\frac{T}{\\lambda}I_3  & \\frac{T^2}{2 \\lambda} I_3 & 0\\\\\n  0 & I_3 & T I_3 & 0 \\\\\n  0 & 0 & I_3 & 0 \\\\\n  0 & 0 & 0 & 1\\\\\n \\end{pmatrix} \n\\begin{pmatrix}\n\\overrightarrow{x}_{k} \\\\\n  \\overrightarrow{v}_{k} \\\\\n  \\overrightarrow{a}_{k} \\\\\n  \\overrightarrow{\\lambda}_{k} \\\\\n \\end{pmatrix}\n\\end{equation}\n\nwhere $x_k+1$ is the position without scale of the IMU/Camera and $v_{k+1}$ , $a_k+1$ are the velocity and acceleration of the IMU/Camera in metric unit [m]. $ν_k$ is the gaussian process noise. \nMain reason behind extended kalman filter working is when ever transition takes places between matices resultant output remains Gaussian and have defined mean and co-variance so in out treatment we can only do those transformation where we dont loose condition of system being Gaussian.\nFor example, Linear curve when transformed is Gaussian but if the function is non linear it is resultant does not result into Gaussian so whole point of using Kalman filter is killed.\nSo in Extended Kalman filter we linearize the system.\nEvery vector in $z_k$ is resolved in the world frame W. Note that we do not\ninclude the orientation information in the model nor use it as a measurement in order. to keep the algorithm simple and fast. On each acceleration measurement we do the conversion from the inertial to the world frame by using a zero order hold  of the unfiltered attitude measurement returned by the visual SLAM framework. As we work in a middle size environment with enough loops we assume negligible drift win the SLAM map and assume thus highly accurate attitude estimation from the visual SLAM framework. The model in its linearized form yields,\n\n\\begin{figure}[!htb]\n\\includegraphics[width=\\textwidth]{./figures/NonLinear.jpg}\n\\caption{Non-Linear system~\\cite{ByBo2015}}\n\\end{figure}\n\n\\begin{equation}\nF_k= \n \\begin{pmatrix}\n  I_3 & \\frac{T}{\\lambda}I_3  & \\frac{T^2}{2 \\lambda} I_3& -\\frac{T}{ \\lambda^2} I_3 - \\frac{T^2}{ 2 \\lambda^2} I_3\\\\\n  0 & I_3 & T I_3 & 0 \\\\\n  0 & 0 & I_3 & 0 \\\\\n  0 & 0 & 0 & 1\\\\\n \\end{pmatrix} \n\\end{equation}\n\nFor fusion implementation we consider the measurements in different observation\nvectors. For a multi rate filter, as it is in our case, the literature suggests two solutions. One would be using a (higher order) hold to synchronize the different measurements. Another is to weight the uncertainty of the measurement according to its temporal occurrence. The authors claim no certainty at all if no\nmeasurement is available (i.e. the measurement noise variance is infinite). Thus the update equations simplify to improve results. A more complex weighting function (i.e. exponential decay in time) could also be applied, however, at the cost of speed. The measurement updates for the vision and the IMU yields (‘V’ and ‘I’ denotes Vision and IMU)\n\nThe innovation done by authors in for the vision part is,\n\\begin{equation}\nK_{V,k}=P_k^- H_{V,k}^T (H_{V,k} P_k H_{V,k}^T +R_v)^{-1}\n\\end{equation}\n\\begin{equation}\n\\overrightarrow{z}_{k}=\\overrightarrow{z}_{k}+K_{V,k}(\\overrightarrow{x}_{SLAM}-H_{V,k} \\overrightarrow{z}_{k})\n\\end{equation}\n\\begin{equation}\nP_k=(I-K_{V,k} H_{V,k}) P_k^-\n\\end{equation}\n\nThe innovation for by authors in the IMU part is,\n\\begin{equation}\nK_{I,k}=P_k^- H_{I,k}^T (H_{I,k} P_k H_{I,k}^T +R_I)^{-1}\n\\end{equation}\n\\begin{equation}\n\\overrightarrow{z}_{k}=\\overrightarrow{z}_{k}+K_{I,k}(\\overrightarrow{x}_{IMU}-H_{I,k} \\overrightarrow{z}_{k})\n\\end{equation}\n\\begin{equation}\nP_k=(I-K_{I,k} H_{I,k}) P_k^-\n\\end{equation}\n\nThe two matrices $R_I$ , $R_V$ are the noise covariance matrices for the vision and IMU measurement inputs $x_{SLAM}$ , $a_{IMU}$ which are resolved in the world frame W.\nThe vector $x_{SLAM}$ is the position without scale obtained from the vision algorithm(SLAM). The IMU measurement $a_{IMU}$ needs special attention, because significant errors arise in the conversion from the raw IMU output.\n\\begin{equation}\n\\overrightarrow{a}_{w}=R_{wc}R_{ca} (\\overrightarrow{a}_a - \\overrightarrow{b})-\\overrightarrow{g}_w\n\\end{equation}\n\n", "meta": {"hexsha": "2c0922f378eb280ae421cc1f0cfd463c91f1ffd8", "size": 6041, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/text/EKF.tex", "max_stars_repo_name": "rohit517/Scale-Estimation-Monocular-SLAM", "max_stars_repo_head_hexsha": "ec86d42b83f2574db7b1e22b12cc531b09062c45", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Report/text/EKF.tex", "max_issues_repo_name": "rohit517/Scale-Estimation-Monocular-SLAM", "max_issues_repo_head_hexsha": "ec86d42b83f2574db7b1e22b12cc531b09062c45", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/text/EKF.tex", "max_forks_repo_name": "rohit517/Scale-Estimation-Monocular-SLAM", "max_forks_repo_head_hexsha": "ec86d42b83f2574db7b1e22b12cc531b09062c45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.0775862069, "max_line_length": 549, "alphanum_fraction": 0.7326601556, "num_tokens": 1809, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361676202372, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7259872341893677}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{float}\n\\usepackage{amsmath}\n\n\n\\usepackage[hmargin=3cm,vmargin=6.0cm]{geometry}\n%\\topmargin=0cm\n\\topmargin=-2cm\n\\addtolength{\\textheight}{6.5cm}\n\\addtolength{\\textwidth}{2.0cm}\n%\\setlength{\\leftmargin}{-5cm}\n\\setlength{\\oddsidemargin}{0.0cm}\n\\setlength{\\evensidemargin}{0.0cm}\n\n\n\n\\begin{document}\n\n\\section*{Student Information } \n%Write your full name and id number between the colon and newline\n%Put one empty space character after colon and before newline\nFull Name : Zeynep Özalp \\\\\nId Number : 2237691 \\\\\n\n% Write your answers below the section tags\n\\section*{Answer 1}\n\\subsection*{a} \nLet $R(x), G(x), B(x)$ be generating functions for red, green blue candies respectively. Actually, we can extend the terms of R(x) and B(x) to infinity but notice that we can not select 10 red candies since blue candies should be odd and the least odd number is 1. We can select at most 5 blue candies since there must be at least 4  red candies. Thus, generating functions are\n$$R(x)=x^4+x^5+x^6+x^7+x^8+x^9$$  \n$$G(x)=1+x^2+x^4$$ \n$$B(x)=x+x^3+x^5$$    \nThen the ways to select 10 candies is the coefficient of $x^{10}$ in, let say $S(x)$, where $S(x)=R(x)G(x)B(x)$.\n$$S(x)=(x^4+x^5+x^6+x^7+x^8+x^9)(1+x^2+x^4)(x+x^3+x^5)$$ \n$$S(x)=(x^4+x^5+x^6+x^7+x^8+x^9)(x+2x^3+3x^5+2x^7+x^9)$$\nThe coefficient of $x^{10}$ in $S(x)$ is 6.\n\\subsection*{b}\nIf we have 5 candies of each of them, we can not select more than 5 candies. So, we need to delete the terms with power more than five in generating functions of them. Therefore,\n$$R(x)=x^4+x^5$$  \n$$G(x)=1+x^2+x^4$$ \n$$B(x)=x+x^3+x^5$$ \n$$S(x)=(x^4+x^5)(1+x^2+x^4)(x+x^3+x^5)$$\n$$S(x)=(x^4+x^5+x^6+x^7+x^8+x^9)(x+x^3+x^5)$$\nThe coefficient of $x^{10}$ in $S(x)$ is 3.\n\\subsection*{c}\n$$F(x)=x\\dfrac{7x}{(1-2x)(1+3x)}$$\nLet $F(x)=xG(x)$\n$$G(x)=\\dfrac{a}{1-2x}+\\dfrac{b}{1+3x}=\\dfrac{7x}{(1-2x)(1+3x)}$$\n$a+3ax+b-2bx=7x$. When we solve, $a=7/5,\\ b=-7/5$\n$$G(x)=\\frac{7}{5}\\bigg( \\dfrac{1}{1-2x}-\\dfrac{1}{1+3x}\\bigg)$$\nNotice that\n$$\\dfrac{1}{1-2x}=\\sum_{k=0}^{\\infty}2^kx^k \\longleftrightarrow <1,2,2^2,...>$$\n$$\\dfrac{1}{1+3x}=\\sum_{k=0}^{\\infty}(-3)^kx^k \\longleftrightarrow <1,(-3),(-3)^2,...>$$\n$$G(x)=\\frac{7}{5}\\sum_{k=0}^{\\infty}(2^k-(-3)^k)x^k\\longleftrightarrow \\frac{7}{5}<0,2-(-3),2^2-(-3)^2,...>$$\n$$F(x)=xG(x)=\\frac{7}{5}\\sum_{k=0}^{\\infty}(2^k-(-3)^k)x^{k+1}$$\n$$F(x)\\longleftrightarrow \\frac{7}{5}<0,0,1,(2-(-3)),(2^2-(-3)^2),...>$$\n$$F(x)\\longleftrightarrow <0,0,\\frac{7}{5},\\frac{7(2-(-3))}{5},\\frac{7(2^2-(-3)^2)}{5},...>$$\n\\subsection*{d}\nFirst, notice that $s_1=8s_0+10^0=8s_0+1=9$. So, $s_0=1$.\n$$s_n=8s_{n-1}+10^{n-1}$$\n$$s_nx^n=8s_{n-1}x^n+10^{n-1x^n}$$\nLet $G(x)=\\sum_{n=0}^{\\infty}s_nx^n$. Since $s_0=1$, subtract 1 from $G(x)$ to start from $n=1$.\n$$G(x)-1=\\sum_{n=1}^{\\infty}s_nx^n=\\sum_{n=1}^{\\infty}(8s_{n-1}x^n+10^{n-1}x^n)$$\n$$G(x)-1=8\\sum_{n=1}^{\\infty}s_{n-1}x^n+\\sum_{n=1}^{\\infty}10^{n-1}x^n$$\n$$G(x)-1=8x\\sum_{n=1}^{\\infty}s_{n-1}x^{n-1}+x\\sum_{n=1}^{\\infty}10^{n-1}x^{n-1}$$\n$$G(x)-1=8x\\sum_{n=0}^{\\infty}s_{n}x^{n}+x\\sum_{n=0}^{\\infty}10^{n}x^{n}$$\n$$G(x)-1=8xG(x)+\\dfrac{x}{1-10x}$$\nwhere I have used the Table 1 on page 542 to evaluate the second summation. Thus,\n$$G(x)=\\dfrac{1-9x}{(1-8x)(1-10x)}$$\n$$G(x)=\\dfrac{A}{1-8x}+\\dfrac{B}{1-10x}$$\nSolving this gives $A=1/2, B=1/2$.\n$$G(x)=\\frac{1}{2}\\bigg(\\dfrac{1}{1-8x}+\\dfrac{1}{1-10x}\\bigg)$$\nAgain, use Table 1 to convert these into sums.\n$$G(x)=\\frac{1}{2}\\bigg(\\sum_{n=0}^{\\infty}8^nx^n+\\sum_{n=0}^{\\infty}10^nx^n\\bigg)$$\n$$G(x)=\\sum_{n=0}^{\\infty}\\frac{1}{2}(8^n+10^n)x^n$$\nTherefore,\n$$s_n=\\frac{1}{2}(8^n+10^n)$$\n\n\\section*{Answer 2}\nFor simplicity, I will use the term \"A-set\" to represent the set of all numbers that are divisible by a given integer in a given interval.\n\\subsection*{a}\nLet $k=cm$ where c is an integer and $A_k=\\{k_1,k_2k_3,..\\}$. If $k|k_i$ where $k_i\\in A_k$, then $k_i=bk$ where b is an integer.\n$$k_i=b(cm)=bcm$$\nSo, all elements in $A_k$ are divisible by m. Thus, $A_m$ contains all the elements of $A_k$ since these elements are divisible by m. Then,\n$$A_k\\subseteq A_m$$\n\\subsection*{b}\nIf n is a composite number, n has a prime divisor less than or equal to $\\sqrt{n}$, by theorem 2 on page 258. So the greatest prime divisor of n can be $\\sqrt{n}$.\\\\\nFrom part a, the A-set of a composite number is the subset of the A-sets of prime divisors of it. So, we do not need to consider A-sets of composite numbers because all numbers which can be divisible by a composite number is also divisible by a prime number. Since the greatest prime number which divides the greatest composite number, which is n, can be less than or equal to $\\sqrt{n}$ and since all other composite numbers less than  or equal to n are divisible by some primes $p\\leq \\sqrt{n}$, the right-hand side of equation 1 is equal to the union of A-sets of prime numbers up to $\\sqrt{n}$.\n\\subsection*{c}\nAssume that n is divisible by m. Thus,\n$$A_m=\\{2m,3m,4m,...,(\\frac{n}{m}m)\\}$$\nClearly, there are $n/m-1$ elements in $A_m$. Now assume that n is not divisible by m. Let k is the number before n that is divisible by m. Thus,\n$$A_m'=\\{2m,3m,4m,...,(\\frac{k}{m}m)\\}$$\nin the interval $(m,k]$.\nClearly, there are $k/m-1$ elements in $A_m'$. Since n is greater than k and is not divisible by m, $|A_m|=|A_m'|$. Thus, $|A_m|=k/m-1=\\lfloor n/m \\rfloor -1$.\n\\subsection*{d}\nSince a and b are relatively prime, the intersection of $A_a$ and $A_b$ is the $lcm(a,b)=ab$ and its multiples. This set is the union of $A_{ab}$ and $\\{ab\\}$. So, the only number is $lcm(a,b)=ab$.\n\\subsection*{e}\nSince all the elements in P is primes, $A_p$ is the multiples of those primes and the intersection of all A-sets is the A-set of the number, say k, such that\n$$k=p_1p_2p_3...$$ \nwhere $p_i$'s are the elements of P. Therefore,\n$$\\bigg |\\bigcap_{p \\in P}A_p\\bigg |=|A_k|+1$$\nAdd 1 because $k$ should be in the intersection of all A-sets of p's in P but  is not in the A-set of k.\n\\subsection*{f}\nFrom part b,\n$$|C_{45}|=\\bigg|\\bigcup_{primes\\ p\\leq \\sqrt{45}}A_p\\bigg|$$\n$$|C_{45}|=|A_2\\cup A_3\\cup A_5|=|A_2|+|A_3|+|A_5|-|A_2\\cap A_3|-|A_2\\cap A_5|-|A_5\\cap A_3|+|A_2\\cup A_3\\cup A_5|$$\n\\subsection*{g}\nFrom part b, c, d and e: \\\\\n$|A_2\\cap A_3|=|A_6|+1=7$\n$|A_2\\cap A_5|=|A_{10}|+1=4$\n$|A_5\\cap A_3|=|A_{15}|+1=3$\n$|A_2\\cup A_3\\cup A_5|=|A_{30}|+1=1$\n$$|C_{45}|=|A_2|+|A_3|+|A_5|-|A_6|-|A_{10}|-|A_{15}|+|A_{30}|$$\n$$|C_{45}|=21+14+8-7-4-3+1=30$$\nNotice that $C_{45}$ is defined in the interval (1,45] so 1 is not in $C_{45}$. Thus the number of composite numbers up to 45 is $|C_{45}|+1=31$. Subtracting this from 45 will give the number of primes up to 45.\n$45-31=14$\n\n\\section*{Answer 3}\n\\subsection*{a}\nIf $\\ll$ is a transitive relation, then for pairs for all arbitrary (a,b), (c,d), (e,f) in $Z^2$, the following is true.\n$$[((a,b)\\ll (c,d)) \\wedge ((c,d)\\ll (e,f))]\\rightarrow ((a,b)\\ll (e,f))$$\nIf $(a,b)\\ll (c,d)$ and $(c,d)\\ll (e,f)$, this means\n$$(a<c) \\vee (a=c \\wedge b\\leq d)$$\n$$(c<e) \\vee (c=e \\wedge d\\leq f)$$\nIf $\\ll$ is a transitive relation\n$$(a<e) \\vee (a=e \\wedge b\\leq f)$$\nmust hold.\\\\\n1. Consider the first case: $(a<c)$ and $(c<e)$. Then, $a<e$ and relation holds for the first case.\\\\\n2. Consider the second case: $(a=c \\wedge b\\leq d)$ and $(c=e \\wedge d\\leq f)$. Clearly $a=e$ and since $b\\leq d \\leq f$, this implies $b\\leq f$.\nTherefore, $\\ll$ is a transitive relation.\n\\subsection*{b}\nEquivalence relations are reflexive, symmetric, transitive relations.\n\\subsubsection*{Reflexivity}\nFor all functions f, k in R such that $x\\geq k$, the following is true for any k.\n$$f(x)=f(x)$$\n$$f\\ \\alpha \\ f$$\nThus, $\\alpha$ is reflexive.\n\\subsubsection*{Symmetry}\nIf $f\\ \\alpha \\ g$, for $x\\geq k$, $f(x)=g(x)$. If $g\\ \\alpha \\ f$, for $x\\geq k$, $g(x)=f(x)$.\nIf $f\\ \\alpha \\ g$ holds, so do $g\\ \\alpha \\ f$ for the same arbitrary k and vice versa. Thus, $\\alpha$ is symmetric.\n\\subsubsection*{Transitivity}\nIf $\\alpha$ is a transitive relation, then for pairs f, g and h the following is true.\n$$[(f\\alpha g) \\wedge (g\\alpha h)]\\rightarrow (f \\alpha h)$$\nIf $f\\alpha g$ and $g\\alpha h$, this means\n$$f(x)=g(x)$$ for every $x \\geq k_1$.\n$$g(x)= h(x)$$ for every $x \\geq k_2$.\\\\\nSince these tree functions are equal at points greater than the maximum of $k_1$ and $k_2$, clearly\n$$f \\alpha h$$ for every $x \\geq max(k_1,k_2)$\nThus, $\\alpha$ is transitive.\n\n\n\n\n\\end{document}\n\n​\n\n", "meta": {"hexsha": "88c7571fd3f76bc9a02e3fe1254617cf653dbadc", "size": 8377, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ceng223/hw4/hw4.tex", "max_stars_repo_name": "zeynepozalp/Coursework", "max_stars_repo_head_hexsha": "d2526229a757a926c311e49c7ffec995ebb9f365", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ceng223/hw4/hw4.tex", "max_issues_repo_name": "zeynepozalp/Coursework", "max_issues_repo_head_hexsha": "d2526229a757a926c311e49c7ffec995ebb9f365", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ceng223/hw4/hw4.tex", "max_forks_repo_name": "zeynepozalp/Coursework", "max_forks_repo_head_hexsha": "d2526229a757a926c311e49c7ffec995ebb9f365", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.6855345912, "max_line_length": 598, "alphanum_fraction": 0.6388922048, "num_tokens": 3510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.8757869965109765, "lm_q1q2_score": 0.7259738218291412}}
{"text": "\n\\documentclass[12pt]{amsart}\n\\usepackage{geometry} % see geometry.pdf on how to lay out the page. There's lots.\n\\geometry{a4paper} % or letter or a5paper or ... etc\n\\usepackage[T1]{fontenc}\n\\usepackage[latin9]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsaddr}\n\\usepackage{amssymb}\n\\usepackage{hyperref}\n\\usepackage{dirtytalk}\n\\usepackage{float}\n\\usepackage{listings}\n\\usepackage{color}\n \\title{Exploration of Patterns for use in Class}\n\n\\date{\\today}\n\n%%% BEGIN DOCUMENT\n\\begin{document}\n\\maketitle\n\n\\section{Fundamental Patterns}\n\\section{Definitions}\n\\begin{enumerate}\n\t\\item Singleton: A set with one value.\n\t\\item Set: A mathematical set. Ex. An undirected graph is a set of edge descriptions.\n\t\\item Sequence: A mathematical sequence. Ex. A digraph is a sequence of edge descriptions.\n\\end{enumerate}\n\\section{Functor Pattern}\nA  pattern that allows a generic function to apply a specific function  without changing or modifying the generic function.$\\\\$\n\n\\section{Fold Pattern:set or sequence to singleton} \nFor function $f$, set or sequence $S$, and singleton $a,\\\\$\n\n\\begin{align*}\n fold(f,S,a) &=\n  \\begin{cases}\n   a & \\text{if } S=\\varnothing\\\\\n   fold(f,S,f(x:x\\in S,a)) & \\text{otherwise}\n  \\end{cases}\n\\end{align*}\n\\section{Unfold Pattern:singleton to set or sequence}\nFor function $f$, and singleton $d\\\\$\n\\begin{align*}\nunfold(f,d) &=\n  \\begin{cases}\n   \\varnothing & \\text{if }f(d)=\\varnothing\\\\\n   f(d)\\cup unfold(f,f(d)) & \\text{otherwise}\n  \\end{cases}\n\\end{align*}\n\n\\section{Derived Patterns}\n\\subsection{Hylomorphism Pattern}\nFor functions $f$ and $g$, singleton $d$, and singleton $a,\\\\$\n\\begin{align*}\nhylo(f,g,d,a) &= fold(f,unfold(g,d),a)\n\\end{align*}\t\n\\subsection{Map Pattern}\nFor set or sequence $A=\\varnothing$, set or sequence $S$, and function $f$, where $f(s:s\\in S, A)$ performs some transformation $t$ as well as $\\{t(s)\\}\\cup A,\\\\$ \n\\begin{align*}\nmap(f,S) &= fold(f,S,A)\n\\end{align*}\n\\subsection{Filter Pattern}\nFor set or sequence $A=\\varnothing$, set or sequence $S$, and function $f$, where $f(s:s\\in S, A)$ performs some comparison $c$ and $\\{t(s)\\}\\cup A$ when $c(s)=true,\\\\$\n\\begin{align*}\nfilter(f,S) &= fold(f,S,A)\n\\end{align*}\n\\subsection{Monad Pattern}\n\n\\subsection{Sream Pattern}\nunfold pattern derivative (Stream is the same as Lazy Evaluation)\n\\end{document}", "meta": {"hexsha": "b1eb9f591622397c9edf3524cce3094d4c13e89f", "size": 2310, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "patterns_explore.tex", "max_stars_repo_name": "byui-cse/cse382-course", "max_stars_repo_head_hexsha": "6d88ab799f113bb6781b364af7a6a06da1fcc9e3", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "patterns_explore.tex", "max_issues_repo_name": "byui-cse/cse382-course", "max_issues_repo_head_hexsha": "6d88ab799f113bb6781b364af7a6a06da1fcc9e3", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "patterns_explore.tex", "max_forks_repo_name": "byui-cse/cse382-course", "max_forks_repo_head_hexsha": "6d88ab799f113bb6781b364af7a6a06da1fcc9e3", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.6438356164, "max_line_length": 168, "alphanum_fraction": 0.7095238095, "num_tokens": 706, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7259738206620954}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{graphicx}\n\\usepackage{fancyvrb} \n\\usepackage{url}\n\\title{RSA implementation - Homework \\#3 \\\\ \\bigskip \\large CNS Course Sapienza}\n\\date{20th November 2020}\n\\author{Leonardo Razovic 1712242}\n\\begin{document}\n\\maketitle\n\n\\section{Introduction}\nThe \\textit{Rivest–Shamir–Adleman} \\textbf{(RSA)} cryptosystem revolutionized cryptography when it\nemerged in 1977 as the first public-key encryption scheme; whereas classical, symmetric-key\nencryption schemes use the same secret key to encrypt and decrypt messages, public-key encryption\n(also called asymmetric encryption) uses two keys: one is your public key, which can be used by\nanyone who wants to encrypt messages for you, and the other is your private key, which is required\nin order to decrypt messages encrypted using the public key.\nThe RSA algorithm involves four steps: \\textit{key generation, key distribution, encryption, and decryption}.\n\\subsection{Key generation}\nThe keys for the RSA algorithm are generated in the following way:\\cite{rsa-wik}\n\\begin{itemize}\n  \\item In order to generate a key, you pick two large prime numbers $p$ and $q$. These numbers have to be picked at random, and in secret.\n  \\item You multiply them together to produce the modulus $n = p \\cdot q$, which is public.\n  \\item Compute $\\lambda(n)$, where $\\lambda$ is Carmichael's totient function.\\\\\n        Since $n = p \\cdot q$, and $\\lambda(n) = lcm(\\lambda(p),\\lambda(q))$, and since $p$ and $q$ are prime, $\\lambda(p) = \\phi(p) = p - 1$ and likewise $\\lambda(q) = q - 1$.\\\\\n        Hence $\\lambda(n) = lcm(p - 1, q - 1)$.\n  \\item Pick an encryption exponent $e$ (which is also public) such that $1 < e < \\lambda(n)$ and $gcd(e, \\lambda(n)) = 1$.\n        Usually, this value is either $3$ or $65537$. Because those numbers have a small number of $1$'s\n        in their binary expansion, you can compute the exponentiation more efficiently.\\\\\n        $(n, e)$ is the public key.\n  \\item There is a value $d$, the \\textit{decryption exponent}, fairly easy to compute assuming that you know $p$ and $q$, such that $d$ is the modular multiplicative inverse of e modulo $\\lambda(n)$.\n\\end{itemize}\n\\subsection{Key distribution}\nSuppose that Bob wants to send information to Alice. Bob must know Alice's public key to encrypt the message and Alice must use her private key to decrypt\nthe message. To enable Bob to send his encrypted messages, Alice transmits her public key $(n, e)$\nto Bob via a reliable, but not necessarily secret, route. Alice's private key $d$ is never distributed.\n\\subsection{Encryption}\nAnyone can use the public key $(n, e)$  to encrypt a message $M$ into a ciphertext $C$ such that $C \\equiv M^e (mod \\ n)$\n\\subsection{Decryption}\nUsing $d$, you can decrypt the message like so: $M \\equiv C^d (mod \\ n)$\nThe security of RSA relies on that decryption operation being impossible without knowing the secret\nexponent $d$, and that the secret exponent $d$ is very hard (practically impossible)\nto compute from the public key $(n, e)$.\n\\section{Design}\nTo implement the protocol Rust 1.48.0 has been chosen, with the auxiliary help of several libraries to manage numbers with a high\namount of bit. The main libraries used are:\n\\begin{itemize}\n  \\item num-bigint: Big integer types for Rust, BigInt and BigUint.\n  \\item glass\\_pumpkin: A cryptographically-secure, random number generator, useful for generating large prime numbers\n  \\item openssl: Provdes OpenSSL bindings for the Rust programming language, used to test the encryption/decryption using RSA and AES\n\\end{itemize}\n\\subsection{Generate $p$, $q$ and $n$}\nThe first step is to generate the values of p and q. These two values must be prime numbers, integers, and large enough to be considered safe.\nTo do this we have chosen to use \\Verb\"glass_pumpkin\" that allows you to generate random prime numbers of a\ndesired bit length. The randomness comes from the operating system.\nSince $p$ and $q$ are values of type \\Verb\"BigUint\" and that this type implements \\Verb\"Mul\" \\cite{mul}\nit is possible to claculate $n = p \\cdot q$.\nThe length of $n$ in bits represents the length of the key, so if you generate $p$ and $q$ of $512$ bits, you get $n$ at 1024 bits.\nThe library for generating random prime numbers follows these steps:\n\\begin{itemize}\n  \\item Generate a random odd number of a given bit-length.\n  \\item Divide the candidate by the first 2048 prime numbers. (This helps to eliminate certain cases that pass Miller-Rabin but are not prime.)\n  \\item Test the candidate with Fermat's Theorem.\n  \\item Runs $log_2(bit\\_length)$ + 5 Miller-Rabin tests with one of them using generator $2$.\n  \\item Run Lucas primality test.\n\\end{itemize}\n\\subsection{Generate $\\lambda(n)$}\nTo compute $\\lambda(n) = lcm(p - 1, q - 1)$ where $\\lambda$ is Carmichael's totient function, it's possibile to use the \\Verb\"lcm()\" function\nprovided by \\Verb\"num_bigint\".\n\\subsection{Generate $e$}\nTo find $e$ we have two possibilities: use a precomputed value, like $3$ or $ 2^{16} + 1 = 65537$, or\npick a value such that $1 < e < \\lambda(n)$ and $gcd(e, \\lambda(n)) = 1$. In the code both of the options\nare possibile, using the \\Verb\"gen_biguint_range()\" function that generates a random \\Verb\"BigUint\" within the given range, ($1$ and $\\lambda(n)$ in our case)\nand check if the greatest common divisor between $e$ and $\\lambda(n)$ is equal to $1$.\n\\subsection{Perform Encryption and Decryption}\nTo perform the encryption of a given plaintext we can use the \\Verb\"modpow()\" provided by \\Verb\"num-bigint\" that returns\n(plaintext \\^{} exponent $e$) \\% modulus $n$ in the encryption\nand (ciphertet \\^{} exponent $d$) \\% modulus $n$ in the decryption phase.\n\\section{Evaluation}\nAll tests were performed using Rust 1.48.0 and OpenSSL \\cite{openssl} 1.1.1h on Arch Linux running Linux 5.9.8, using an Intel i5 9600KF processor.\nTo evaluate the correctness and speed of my implementation I compared the results obtained with the results obtained by RSA via OpenSSL.\nEach test was performed using Rust's test functions that have been run 20 times, the times reported are an average of the run times.\n\\begin{table}[h!]\n  \\centering\n  \\begin{tabular}{|l|l|l|}\n    \\hline\n    \\textit{}                    & \\textit{My RSA} & \\textit{OpenSSL RSA} \\\\ \\hline\n    \\textit{Key Generation Time} & \\textit{28105}  & \\textit{20535}       \\\\ \\hline\n    Encryption Time              & 142             & 137                  \\\\ \\hline\n    Decryption Time              & 850             & 822                  \\\\ \\hline\n  \\end{tabular}\n  \\caption{My implmentantion vs OpenSSL, times expressed in micros}\n\\end{table}\n\\\\\nTo speed up the time for encryption and decryption, it is possible to use a smaller exponent $e$, such as $65537$\n\\begin{table}[h!]\n  \\centering\n  \\begin{tabular}{|l|l|l|}\n    \\hline\n    \\textit{}                    & \\textit{My RSA} & \\textit{OpenSSL RSA} \\\\ \\hline\n    \\textit{Key Generation Time} & \\textit{23517}  & \\textit{17096}       \\\\ \\hline\n    Encryption Time              & 135             & 132                  \\\\ \\hline\n    Decryption Time              & 405             & 398                  \\\\ \\hline\n  \\end{tabular}\n  \\caption{My implmentantion using a fixed exponent vs OpenSSL, times expressed in micros}\n\\end{table}\n\\\\\nAnother test to evaluate the speed was done by comparing the times obtained using AES-128-CBC in OpenSSL,\nhere we can see very much the slowness of RSA towards AES.\n\\begin{table}[h!]\n  \\centering\n  \\begin{tabular}{|l|l|l|}\n    \\hline\n    \\textit{}                & \\textit{My RSA} & \\textit{OpenSSL AES} \\\\ \\hline\n    \\textit{Generating Keys} & \\textit{25107}  & \\textit{0}           \\\\ \\hline\n    Encryption Time          & 712             & 650                  \\\\ \\hline\n    Decryption Time          & 704             & 638                  \\\\ \\hline\n  \\end{tabular}\n  \\caption{My implmentantion vs OpenSSL AES-128-CBC, times expressed in micros}\n\\end{table}\n\\\\\nUsing the Linux \\Verb\"perf\" tool it was possible to create a flame graph which shows that most of the time is spent to\ngenerate the keys, especially in checking if the randomly generated numbers are prime.\\\\\n\\begin{figure}[h]\n  \\includegraphics[scale=0.17]{flame.png}\n  \\caption{The flame graph generated by the complete execution of key generation, encryption, and decryption}\n\\end{figure}\n\\section{Conclusion}\nIn this homework it was possible to study and implement an unsafe, but valid,\nversion of RSA and compare it with real (and safe) implementations.\nThe results obtained show how slow an asymmetric scheme, such as RSA, can be, compared to a symmetric scheme, such as AES-128 in CBC mode.\n\n\\begin{thebibliography}{9}\n  \\bibitem{mul}\n  Crate num\\_bigint documentation.\\\\\n  \\url{https://docs.rs/num-bigint/0.3.1/num_bigint/struct.BigUint.html#impl-Mul\\%3CBigUint\\%3E}\n  \\\\Accessed: 2020-19-11.\n\n  \\bibitem{openssl}\n  OpenSSL Software Foundation.\\\\\n  \\url{https://www.openssl.org/index.html}\n  \\\\ Accessed: 2020-19-11.\n\n  \\bibitem{rsa-wik}\n  RSA (cryptosystem)\\\\\n  \\url{https://en.wikipedia.org/wiki/RSA_(cryptosystem)}\n  \\\\Accessed: 2020-20-11.\n\\end{thebibliography}\n\\end{document}\n", "meta": {"hexsha": "9e2afd9aa53d74888ecc2dfb71cf689b8b7b5b5c", "size": 9126, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/main.tex", "max_stars_repo_name": "lrazovic/rust_rsa", "max_stars_repo_head_hexsha": "4eb157ea327547f123f1b6a2dfec232fae466ba1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-03-29T17:44:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-18T19:27:47.000Z", "max_issues_repo_path": "report/main.tex", "max_issues_repo_name": "lrazovic/rust_rsa", "max_issues_repo_head_hexsha": "4eb157ea327547f123f1b6a2dfec232fae466ba1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/main.tex", "max_forks_repo_name": "lrazovic/rust_rsa", "max_forks_repo_head_hexsha": "4eb157ea327547f123f1b6a2dfec232fae466ba1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.84, "max_line_length": 200, "alphanum_fraction": 0.7056760903, "num_tokens": 2512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.725973817797987}}
{"text": "\\subsection{BN Matching}\nThe traditional method of implementing style transfer is using the mean square error (MSE) of the Gramian Matrix of the feature maps. This the the method that is used in the original Gatys style transfer and is also the basis in Ruder. But there are other such methods, one of which is BN Matching which was first implemented by Li \\textit{et al.} \\cite{Li:1}.\\newline\\newline\nBN (batch normalization) Matching is based on matching the mean and standard deviation of the features. This type of styling uses 1st order statistics, unlike traditional style transfer which uses 2nd order statistics. The advantage of using 1st order statistics is that it requires less computation and therefore is faster. For that reason it is often utilized for commercial purposes. The downside is that it sacrifices quality for speed.\\newline\\newline\nThe original purpose of BN normalization is to reduce the issue of internal covariate shifting, which is a common problem with training deep neural networks. The normalization works by standardizing each feature into mini-batches and then it learns a common slope and bias for each mini-batch. The BN layer makes transformations on our model for each feature $j$ in the following manner.\n\\begin{equation}\n\\begin{aligned}\n\\label{eq:batch_normalization}\n    \\hat{x}_j&=\\frac{x_j-{\\mathbb{E}}[X_{.j}]}{\\sqrt{Var[X_{.j}]}}\\\\\n    y_j&=\\gamma_j\\hat{x}_j + \\beta_j\n\\end{aligned}\n\\end{equation}\nHere $x_j$ and $y_j$ are the input and output scalars of one neuron in our data, $X_{.j}$ is the $j^{th}$ column of the input, while $\\gamma_j$ and $\\beta_j$ are to be learned. Using this method we can calculate the batch normalization for each feature. The core idea of this is to align the distribution of our data.  With this we can use BN statistics to represent the style of our image and we can construct a loss function by matching the mean and standard deviation of the features. \n\n\n", "meta": {"hexsha": "28979d59db14ed9df50aa539d6f49eacad92b079", "size": 1937, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/Background/bn-matching.tex", "max_stars_repo_name": "kjerand/video-style-transfer", "max_stars_repo_head_hexsha": "fe44a1b486e976725cddd6db4981b161dea13813", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-11-23T18:08:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-05T21:02:19.000Z", "max_issues_repo_path": "report/Background/bn-matching.tex", "max_issues_repo_name": "kjerand/video-style-transfer", "max_issues_repo_head_hexsha": "fe44a1b486e976725cddd6db4981b161dea13813", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/Background/bn-matching.tex", "max_forks_repo_name": "kjerand/video-style-transfer", "max_forks_repo_head_hexsha": "fe44a1b486e976725cddd6db4981b161dea13813", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-11-24T15:13:48.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-26T21:36:09.000Z", "avg_line_length": 129.1333333333, "max_line_length": 488, "alphanum_fraction": 0.7816210635, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7259738152872229}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\n\\section{Extension to continuous time}\n\nFrom a general viewpoint, the discrete process can be interpreted as an approximation of its continuous counterpart: whereas the state of the discrete-time random walker can only change at unit-time intervals, the continuous-time random walkers undergo a waiting time between each change of state which is itself a random variable. More precisely, the waiting time is a continuous memoryless random variable distributed exponentially. Obviously, the transition probabilities from one node to the other are the same for both discrete- and continuous-time processes, only the time at which the jump occurs may vary. The continuous-time process corresponding to~\\eqref{eq:discreteMP} is governed by the following dynamics:\n\\begin{equation} \\label{eq:continuousMP_general}\n    \t\\dot{\\b p} = \\b p \\diag\\left\\{\\bs \\lambda(\\b q)\\right\\} \\b Q^{-1} \\b A - \\b p \\diag\\left\\{\\bs \\lambda(\\b q)\\right\\} = -\\b p \\b L,\n\\end{equation}\nwhere $\\lambda_i(\\b q)$ is the rate at which random walkers leave node $i$, and \n\\begin{equation}\n\t\\b L = \\diag\\{\\bs \\lambda(\\b q)\\}[-\\b Q^{-1} \\b A + \\b I].\t\n\\end{equation}\nTwo particular cases of this process are implemented by the stability software and are thus examined here, depending on the choice of $\\bs \\lambda(\\b q)$: the so-called \\textit{normalized Laplacian dynamics} and \\textit{standard (combinatorial) Laplacian dynamics}. Their names come from the similarity that arises between $\\b L$ and the normalized/standard Laplacian matrix. Each of those two dynamics represent best different physical processes. The former corresponds to the choice $\\bs \\lambda_{norm}(\\b q) = \\b 1$. Hence, the expected waiting time is $1$ at every node, and $\\b L = -\\b Q^{-1} \\b A + \\b I = -\\b M + \\b I$. The latter corresponds to $\\bs \\lambda_{combi}(\\b q) = \\b q/\\langle \\b q \\rangle$. In that case, $\\b L = (-\\b A + \\b Q)/\\langle \\b q \\rangle$ and the average waiting time at node $i$ is $\\langle \\b q \\rangle/q_i$. Hence, the expected waiting time at a given node is smaller (resp. larger) than $1$ if the total weight of the outgoing edges from that node is larger (resp. smaller) than the average total weight of the outgoing edges on the network. However, the expected waiting time over the whole network is $\\langle \\langle \\b q \\rangle/\\b q \\rangle = 1$.\\label{expectedtimebetweenjumps} The corresponding governing equations are respectively \n\\begin{equation} \\label{eq:continuousMP_norm}\n\t\\dot{\\b p} = \\b p \\b Q^{-1} \\b A - \\b p = \\b p \\b M - \\b p\n\\end{equation}\nfor the normalized Laplacian and\n\\begin{equation} \\label{eq:continuousMP_combi}\n    \t\\dot{\\b p} = \\b p \\frac{\\b A}{\\langle \\b q \\rangle} - \\b p\\frac{\\b Q}{\\langle \\b q \\rangle}\n\\end{equation}\nfor the combinatorial Laplacian.\n\nThe clustered autocovariance matrix for partition $\\P$ at time $t$ is easily generalized to \n\\begin{equation}\n\t\\b R(t;\\P) = \\b H_{\\P}^{\\t}(\\b \\Pi\\b P(t) - \\bs \\pi^{\\t}\\bs \\pi)\\b H_{\\P},\n\\end{equation}\nwhere $\\b P(t)$ is the the transition matrix of the process at time $t$: $\\b P(t) = \\Exp^{-t\\b L}$. The continuous-time definition of the stability of a partition $\\P$ follows almost straightforwardly:\n\\begin{equation}\n\tr(t;\\P) = \\trace \\left[ \\b R(t; \\P) \\right].\n\\end{equation}\nNotice that it is not necessary to minimize over the time interval $[0,t]$: indeed, it can be shown that $\\trace \\left[ \\b R(t;\\P) \\right]$ is monotonically decreasing with time. The interpretation in terms of a random walk is similar to the discrete case: let $P(\\C,t)$ be the probability that a random walker is in community $\\C$ at time $t$ if it was initially in $\\C$, when the system is at stationarity. Discounting the probability of such an event to take place by chance at stationarity and summing over all communities of $\\P$ leads to the definition of the stability of the partition $\\P$:\n\\begin{equation} \\label{eq:generalstability}\n\tr(t;\\P) = \\sum_{\\C \\in \\P} P(\\C,t) - P(\\C,\\infty).\n\\end{equation}\nBy ergodicity, the memory of the initial condition is lost at infinity and $P(\\C,\\infty)$ is thus equal to the probability that two independent walkers are in $\\C$ at stationarity. Equation~\\eqref{eq:generalstability} tells us that only the communities in which a random walker is likely to stay bring a positive contribution to stability, where \\textit{likely to stay} means that the probability for a walker to be in its initial community at time $t$ is larger than the probability of that event occurring by chance at stationarity. The stability curve of the graph can now be expressed as a continuous function of $t$:\n\\begin{equation}\n\tr(t) = \\max_{\\P} r(t;\\P).\n\\end{equation}", "meta": {"hexsha": "eb808ae5d7572db63ae1475741f8edc6eeb9b7f3", "size": 4684, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/clustering/continuoustime.tex", "max_stars_repo_name": "dufaysr/tfe", "max_stars_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inputs/clustering/continuoustime.tex", "max_issues_repo_name": "dufaysr/tfe", "max_issues_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inputs/clustering/continuoustime.tex", "max_forks_repo_name": "dufaysr/tfe", "max_forks_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 126.5945945946, "max_line_length": 1273, "alphanum_fraction": 0.7292912041, "num_tokens": 1307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.8289388019824947, "lm_q1q2_score": 0.7259738142736296}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{tikz}\n\\setlength{\\parindent}{0pt}\n\n\\newtheorem*{theorem}{Theorem}\n\\newtheorem*{definition}{Definition}\n\\newtheorem*{lemma}{Lemma}\n\\newtheorem*{corollary}{Corollary}\n\\newtheorem{example}{Example}\n\\newtheorem*{trick}{Trick}\n\\newtheorem*{question}{Question}\n\n\\title{Lecture 18: Change of Variables}\n\\author{}\n\\date{}\n\n\\begin{document}\n    \n\\maketitle\n\n\\section{Introduction to Change of Variables in Double Integrals}\n\n\\begin{example}\n  Calculate the area of the ellipse with semiaxes $a$ and $b$.\n\n  We can use double integrals to calculate the area. By definition of double \n  integrals, the area of the described ellipse \n  \\begin{equation*}\n    \\begin{split}\n      A &= \\iint_R 1 dA \\\\\n        &= \\iint_{(\\frac{x}{a})^2 + (\\frac{y}{b})^2 = 1} dx dy \\\\\n    \\end{split}\n  \\end{equation*}\n  \n  To simplify the equation, we can set\n  \\begin{gather*}\n    u = \\frac{x}{a} \\\\\n    v = \\frac{y}{b} \\\\\n  \\end{gather*}\n  Then\n  \\begin{gather*}\n    du = \\frac{dx}{a} \\\\\n    dv = \\frac{dy}{b} \\\\\n    du dv = \\frac{dx dy}{ab} \\\\\n    dx dy = ab du dv \\\\\n  \\end{gather*}\n  \n  Therefore, the equation of the double integral is equivalent to\n  \\begin{equation*}\n    \\begin{split}\n      A &= \\iint_{(\\frac{x}{a})^2 + (\\frac{y}{b})^2 = 1} dx dy \\\\\n        &= \\iint_{u^2 + v^2 = 1} ab du dv \\\\\n        &= ab \\iint_{u^2 + v^2 = 1} du dv \\\\\n        &= \\pi ab \\\\\n    \\end{split}\n  \\end{equation*}\n\n  Therefore, the area of the ellipse with semiaxes $a$ and $b$ is $\\pi ab$.\n\\end{example}\n\nFrom the above example we can see, in general when we change the variables in a \ndouble integral, we need to find the scaling factor between $dA = dx dy$ and \n$dA' = du dv$. In order to ensure the correctness of the double integral after \nchanging the variables, we need to multiply the scaling factor with \ndifferentials of changed variables, to ensure the differential of area is still \n$dA$ rather than $dA'$. Also note that the scaling factor between $dA$ and $dA'$ \nmight not be constant in the region $R$.\n\n\\begin{question}\n  Why when we make sure $dA$ is correctly expressed by $du dv$ the double \n  integral with change of variables yields the correct result?\n\n  Answer:\n\n  Probably think about it from the definition of double integral, and the \n  geometric interpretation of change of variables.\n\\end{question}\n\n\\section{Change of Variables with Linear Transformation}\n\n\\begin{example}\n  Find the scaling factor between $dA = dx dy$ and $dA' = du dv$ with the \n  following linear transformation:\n  \\begin{equation*}\n    \\begin{cases}\n      u = 3x - 2y \\\\\n      v = x + y \\\\\n    \\end{cases}\n  \\end{equation*}\n\n  In the $xy$-coordinates, $dA = dx dy$ represents a small rectangle. Regarding \n  the geometric interpretation of the linear transformation, we have the \n  following two observations:\n  \\begin{itemize}\n    \\item A rectangle in the $xy$-coordinates corresponds to a parallelogram in \n    the $uv$-coordinates. The ratio of the area of the parallelogram in the \n    $uv$-coordinates to the area of the rectangle in the $xy$-coordinates is the \n    area scaling factor.\n    \\item The area scaling factor of the linear transformation doesn't depend on \n    the choice of rectangles, either the position or the area.\n  \\end{itemize}\n\n  Based on the above two observations, we can study a special case to find the \n  scaling factor of the linear transformation. The special case we choose is a \n  unit rectangle with the left bottom corner on the origin.\n\n  \\begin{tikzpicture}\n    [help line/.style={dashed}]\n    \\draw[->] (-1, 0) -- (2, 0) node[right] {x};\n    \\draw[->] (0, -1) -- (0, 2) node[right] {y};\n    \\draw (0, 0) node[below right] {O};\n    \\draw[-] (0, 0) -- (0, 1) -- (1, 1) -- (1, 0) -- (0, 0);\n  \\end{tikzpicture}\n\n  After the linear transformation,\n  \\begin{gather*}\n    (0, 0) \\rightarrow (0, 0) \\\\\n    (1, 0) \\rightarrow (3, 1) \\\\\n    (1, 1) \\rightarrow (1, 2) \\\\\n    (0, 1) \\rightarrow (-2, 1) \\\\\n  \\end{gather*}\n\n  \\begin{tikzpicture}\n    [help line/.style={dashed}]\n    \\draw[->] (-2, 0) -- (3, 0) node[right] {u};\n    \\draw[->] (0, -1) -- (0, 3) node[right] {v};\n    \\draw (0, 0) node[below right] {O};\n    \\draw[-] (0, 0) -- (3, 1) -- (1, 2) -- (-2, 1) -- (0, 0);\n  \\end{tikzpicture}\n\n  We can use the determinant to calculate the area of a parallelogram in a plane\n  \\begin{equation*}\n    \\begin{split}\n      A &= \\det(<3, 1>, <-2, 1>) \\\\\n        &= \\begin{vmatrix}\n             3 & 1 \\\\\n             -2 & 1 \\\\ \n           \\end{vmatrix} \\\\\n        &= 5 \\\\\n    \\end{split}\n  \\end{equation*}\n\n  Therefore, the scaling factor of the linear transformation is $5$:\n  \\begin{gather*}\n    dA' = 5dA \\\\\n    dA = \\frac{1}{5} dA' \\\\\n    dx dy = \\frac{1}{5} du dv \\\\\n  \\end{gather*}\n\n\\end{example}\n\n\\begin{question}\n  Why the scaling factor in the above example is $5$ rather than $\\frac{1}{5}$?\n\n  Answer:\n\\end{question}\n\n\\section{Change of Variables in General}\n\nFor general cases of change of variables:\n\\begin{gather*}\n  u = u(x, y) \\\\\n  v = v(x, y) \\\\\n\\end{gather*}\n\nBy linear approximation, we have\n\\begin{gather*}\n  \\Delta u \\approx u_x \\Delta x + u_y \\Delta y \\\\\n  \\Delta v \\approx v_x \\Delta x + v_y \\Delta y \\\\\n  \\begin{bmatrix}\n    \\Delta u \\\\\n    \\Delta v \\\\\n  \\end{bmatrix} \\approx \n  \\begin{bmatrix}\n    u_x & u_y \\\\\n    v_x & v_y \\\\\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    \\Delta x \\\\\n    \\Delta y \\\\\n  \\end{bmatrix} \\\\\n\\end{gather*}\n\nTherefore, for any transformation or change of variables, a small rectangle in \nthe original coordinate system corresponds to a parallelogram in the new \ncoordinate system.\n\nThe correspondence of the vertices between the small rectange in the original \ncoordinate system and the parallelogram in the new coordinate system is\n\\begin{gather*}\n  (0, 0) \\rightarrow (0, 0) \\\\\n  (\\Delta x, 0) \\rightarrow (u_x \\Delta x, v_x \\Delta x) \\\\\n  (0, \\Delta y) \\rightarrow (u_y \\Delta y, v_y \\Delta y) \\\\\n  (\\Delta x, \\Delta y) \\rightarrow (u_x \\Delta x + u_y \\Delta y, v_x \\Delta x + v_y \\Delta y) \\\\\n\\end{gather*}\n\nTherefore, the area of the parallelogram is\n\\begin{equation*}\n  \\begin{split}\n    A &= \\det(<u_x \\Delta x, v_x \\Delta x>, <u_y \\Delta y, v_y \\Delta y>) \\\\\n      &= \\begin{vmatrix}\n           u_x \\Delta x & v_x \\Delta x \\\\\n           u_y \\Delta y & v_y \\Delta y \\\\\n         \\end{vmatrix} \\\\\n      &= (u_x v_y - u_y v_x) \\Delta x \\Delta y \\\\\n      &= \\begin{vmatrix}\n           u_x & u_y \\\\\n           v_x & v_y \\\\\n         \\end{vmatrix} \\Delta x \\Delta y \\\\\n  \\end{split}\n\\end{equation*}\n\nTherefore, the scaling factor between two coordinates is \n$\\begin{vmatrix}\n   u_x & u_y \\\\\n   v_x & v_y \\\\\n\\end{vmatrix}$. Since the scaling factor consists of partial derivatives, it \nvaries with different positions of the differential of area.\n\nHere we define the Jacobian determinant as\n\\begin{equation*}\n  J = \\frac{\\partial(u, v)}{\\partial(x, y)} = \\begin{vmatrix}\n                                                u_x & u_y \\\\\n                                                v_x & v_y \\\\ \n                                              \\end{vmatrix}\n\\end{equation*}\nThen\n\\begin{equation*}\n  du dv = |J| dx dy = |\\frac{\\partial(u, v)}{\\partial(x, y)}| dx dy\n\\end{equation*}\n\n\\begin{example}\n  Find the scaling factor between the Cartesian coordinates and the polar \n  coordinates.\n\n  According to the definition of the polar coordinates\n  \\begin{gather*}\n    x = r \\cos\\theta \\\\\n    y = r \\sin\\theta \\\\\n  \\end{gather*}\n\n  Then we can find the Jacobian determinant as\n  \\begin{equation*}\n    \\begin{split}\n      J &= \\frac{\\partial(x, y)}{\\partial(r, \\theta)} \\\\\n        &= \\begin{vmatrix}\n             \\frac{\\partial x}{\\partial r} & \\frac{\\partial x}{\\partial \\theta} \\\\\n             \\frac{\\partial y}{\\partial r} & \\frac{\\partial y}{\\partial \\theta} \\\\\n           \\end{vmatrix} \\\\\n        &= \\begin{vmatrix}\n             \\cos\\theta & -r \\sin\\theta \\\\\n             \\sin\\theta & r \\cos\\theta \\\\\n           \\end{vmatrix} \\\\\n        &= r \\cos^2\\theta + r \\sin^2\\theta \\\\\n        &= r \\\\\n    \\end{split}\n  \\end{equation*}\n\n  Therefore, \n  \\begin{equation*}\n    dx dy = |\\frac{\\partial(x, y)}{\\partial(r, \\theta)}| dr d\\theta = r dr d\\theta\n  \\end{equation*}\n\\end{example}\n\nNote that the Jacobian determinant of a change of variables works in both ways, \nwhich means\n\\begin{gather*}\n  J_1 = \\frac{\\partial(x, y)}{\\partial(u, v)} = \\frac{dx dy}{du dv} \\\\\n  J_2 = \\frac{\\partial(u, v)}{\\partial(x, y)} = \\frac{du dv}{dx dy} \\\\\n  \\frac{dx dy}{du dv} \\cdot \\frac{du dv}{dx dy} = 1 \\\\\n  \\frac{\\partial(x, y)}{\\partial(u, v)} \\cdot \\frac{\\partial(u, v)}{\\partial(x, y)} = 1 \\\\\n\\end{gather*}\n\nTherefore, the two Jacobian determinants are inverse to each other, and we can \nchoose the easier one to calculate.\n\n\\begin{example}\n  Calculate $\\int_0^1 \\int_0^1 x^2 y dx dy$ by changing the variables as\n  \\begin{gather*}\n    u = x \\\\\n    v = xy \\\\\n  \\end{gather*}\n\n  First we need to calculate the differential of area.\n  \\begin{gather*}\n    \\begin{split}\n      J &= \\frac{\\partial(u, v)}{\\partial(x, y)} \\\\\n        &= \\begin{vmatrix}\n             1 & 0 \\\\\n             y & x \\\\\n           \\end{vmatrix} \\\\\n        &= x \\\\\n    \\end{split} \\\\\n    \\begin{split}\n      du dv &= |J| dx dy \\\\\n            &= |x| dx dy \\\\\n            &= x dx dy \\ (x \\geq 0)\n    \\end{split} \\\\\n  \\end{gather*}\n\n  Then we need to calculate the integrand\n  \\begin{equation*}\n    \\begin{split}\n      x^2 y dx dy &= x^2 y \\frac{1}{x} du dv \\\\\n                  &= xy du dv \\\\\n                  &= v du dv \\\\\n    \\end{split}\n  \\end{equation*}\n\n  Then we need to determine the region of the double integral in the new \n  coordinates.\n\n  In the $xy$-coordinates, the region of the double integral is a rectangle as \n  shown in the below diagram.\n\n  \\begin{tikzpicture}\n    [help line/.style={dashed}]\n    \\draw[->] (-1, 0) -- (2, 0) node[right] {x};\n    \\draw[->] (0, -1) -- (0, 2) node[right] {y};\n    \\draw (0, 0) node[below right] {O};\n    \\draw[-] (0, 0) -- (1, 0) -- (1, 1) -- (0, 1) -- (0, 0);\n  \\end{tikzpicture}\n\n  After changing the variables, if we calculate the double integral in the order \n  of $du dv$, it means for each possible value of $v$, we will keep it constant, \n  and vary the value of $u$.\n\n  Therefore, the way we determine the boundary of the region is to find the \n  range of $v$, and for each value of $v$, find the possible values of $u$ based \n  on the region in $xy$-coordinates.\n\n  According to the diagram, we can find that the range of $v$ is $(0, 1)$, and \n  for each value of $v$, the range of $u$ is $(v, 1)$.\n\n  Therefore, the double integral after changing the variables is\n  \\begin{equation*}\n    \\begin{split}\n      \\int_0^1 \\int_0^1 x^2 y dx dy &= \\int_0^1 \\int_v^1 v du dv \\\\\n                                    &= \\int_0^1 (uv)|_{u = v}^{u = 1} dv \\\\\n                                    &= \\int_0^1 v - v^2 dv \\\\\n                                    &= (\\frac{v^2}{2} - \\frac{v^3}{3})|_0^1 \\\\\n                                    &= \\frac{1}{6} \\\\\n    \\end{split}\n  \\end{equation*}\n\\end{example}\n\n\\end{document}", "meta": {"hexsha": "86c8a20bc72f11dfa4ac5f8139c80e36d2e07ca0", "size": 11069, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture18.tex", "max_stars_repo_name": "jinxinwangstd/multivariable-calculus-mit", "max_stars_repo_head_hexsha": "d165ef6ff085fafd0fb89b8027fc5f5e0dbfa1e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lecture18.tex", "max_issues_repo_name": "jinxinwangstd/multivariable-calculus-mit", "max_issues_repo_head_hexsha": "d165ef6ff085fafd0fb89b8027fc5f5e0dbfa1e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture18.tex", "max_forks_repo_name": "jinxinwangstd/multivariable-calculus-mit", "max_forks_repo_head_hexsha": "d165ef6ff085fafd0fb89b8027fc5f5e0dbfa1e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5356125356, "max_line_length": 96, "alphanum_fraction": 0.5936398952, "num_tokens": 3519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107309, "lm_q2_score": 0.8688267813328976, "lm_q1q2_score": 0.7258904652801612}}
{"text": "% !TEX root = main.tex\n\n\\chapter[Holomorphic Functions]{Differentiability and Holomorphic Functions}\n\\section{The Derivative of a Complex Function}\nThroughout this section, let $U$ be an open subset of $\\C$.  The definition of differentiability for a function $f: U \\to \\C$ looks almost identical to the corresponding definition for real functions.\n\n\\begin{definition}\nLet $f: U \\to \\C$ be a function, and let $z \\in U$.  We say that $f$ is \\emph{differentiable at $z$} if the limit\n\\begin{equation}\n\\label{e:diff}\n\\lim_{\\substack{h \\to 0\\\\ h \\in \\C \\backslash \\set{0}}} \\frac{f(z+h)-f(z)}{h}\n\\end{equation}\nexists.  When it does, we denote its value by $f'(z)$.\n\n%If $f$ is differentiable at $w$ for all $w \\in U$, we say that $f$ is \\emph{holomorphic on $U$}.\n\\end{definition}\n\nSince $U$ is open, for a fixed $z \\in U$, the quantity (the \\emph{difference quotient})\n\\[\n\\frac{f(z+h)-f(z)}{h}\n\\]\nis defined whenever $h$ is `sufficiently small' (to ensure that $z+h \\in U$ and so $f(z+h)$ is defined) but not zero (to avoid division by zero). In other words, $0$ is a limit point of the domain of the difference quotient (regarded as a function of $h$).\n\n For this reason, we can again omit the second subscript and write~\\eqref{e:diff} as\n\\[\n\\lim_{h \\to 0} \\frac{f(z+h)-f(z)}{h}\n\\]\nwithout ambiguity.\n\n\n\n\n\\begin{example}\n\\label{e:diff1}\nLet us investigate whether or not the function\n\\[\nf:\\C \\to \\C, \\quad f(z)=-i\\conj{z}\n\\]\nis differentiable at any points $z \\in \\C$.\n\\end{example}\n\n%1 page handwritten.\n\\begin{solution}\nFix $z \\in \\C$. To evaluate the limit\n\\[\n\\lim_{h \\to 0} \\frac{f(z+h)-f(z)}{h},\n\\]\nwe first try to simplify the expression\n\\[\n\\frac{f(z+h)-f(z)}{h}.\n\\]\nFor any $z \\in \\C \\backslash \\set{0}$, \n\\[\n\\frac{f(z+h)-f(z)}{h} = \\frac{-i\\ \\conj{(z+h)}-(-i)\\conj{z}}{h} = -i \\frac{\\conj{h}}{h}.\n\\]\n%\\vspace*{8cm}\nBut then the limit\n\\[\n\\lim_{h \\to 0} \\frac{f(z+h)-f(z)}{h} = \\lim_{h \\to 0} -i \\frac{\\conj{h}}{h},\n\\]\nis the same as the limit that we considered in Example~\\ref{e:rlim}, except scaled by a factor of $-i$.  Hence this limit does not exist for the same reason; that is\n\\[\n\\rlim{h \\to 0}{h \\in \\R \\backslash \\set{0}} -i \\frac{\\conj{h}}{h} = -i, \\text{ while } \\rlim{h \\to 0}{h \\in i\\R \\backslash \\set{0}} -i \\frac{\\conj{h}}{h} = i.\n\\]\nSo $f$ is not differentiable at any point $z \\in \\C$.\n\\end{solution}\n\n\n\n\\begin{example}\n\\label{e:diff2}\nThe function $\\mathbf{g}: \\R^2 \\to \\R^2$ is defined by\n\\[\n\\mathbf{g}(x,y)=(1,-x^2-y^2)\\quad (x,y) \\in \\R^2.\n\\]\nFind the corresponding complex function $g:\\C \\to \\C$ and investigate where it is differentiable.\n\\end{example}\n\n\\begin{solution}\nThe corresponding function $g: \\C \\to \\C$ is\n\\[\ng(x+iy) = 1+i(-x^2-y^2),\n\\]\nor equivalently,\n\\[\ng(z) = 1-i z \\conj{z}.\n\\]\nAgain, we fix $z \\in \\C$ and look at the difference quotient\n\\[\n\\frac{g(z+h)-g(z)}{h} = -i(z \\frac{\\conj{h}}{h}+\\conj{z}+\\conj{h})\n\\]\nfor $h \\in \\C \\backslash \\set{0}$.\\\\\n\nAs with the previous example, we have $\\frac{\\conj{h}}{h}$ appearing in the difference quotient, so it looks like our limit will not exist.  Again, we shall check by evaluating the restricted limits along the real and imaginary axes.\n\n\\begin{align*}\n\\rlim{h \\to 0}{h \\in \\R \\backslash \\set{0}} -i \\left( z \\frac{\\conj{h}}{h} + \\conj{z} + \\conj{h} \\right) & = -i(z + \\conj{z} ) \\\\\n\\rlim{h \\to 0}{h \\in i\\R \\backslash \\set{0}} -i \\left( z \\frac{\\conj{h}}{h} + \\conj{z} + \\conj{h} \\right) & = -i (-z+\\conj{z} ).\n\\end{align*}\nThese restricted limits are equal if and only if $z+\\conj{z} = -z + \\conj{z}$, which occurs if and only if $z=0$.  It follows that the unrestricted limit\n\\[\n\\lim_{h \\to 0} \\frac{g(z+h)-g(z)}{h}\n\\]\ndoes not exist at any $z \\in \\C \\backslash \\set{0}$, hence $g$ is not differentiable at any of these points.\n\nWhat about when $z=0$?  While the restricted limits along the real and imaginary axes are equal, this is \\emph{not} enough to conclude that the unrestricted limit exists.  Indeed, we must verify this directly:\n\\[\n\\lim_{h \\to 0} \\frac{g(0+h)-g(0)}{h} = \\lim_{h \\to 0} -i \\conj{h} = 0.\n\\]\n(Here we have used the fact that $z \\mapsto \\conj{z}$ is continuous (Example~\\ref{e:cts}), and so limit can be found by substitution of $z=0$.)  In other words, $g$ is differentiable at $0$ (and nowhere else), with $g'(0)=0$.\n%\\vspace*{15cm}\n\\end{solution}\n\\begin{note}\nIn Example~\\ref{e:diff2}, both the real and the imaginary parts of $g$ are differentiable with respect to both $x$ and $y$ everywhere in $\\R^2$.\n\\end{note}\n\n\n\\begin{example}\n\\label{e:diff3}\nConsider the function $f$ defined by $f(z)=\\dfrac{1}{z}$.  At which points $z \\in \\C$ is $f$ differentiable?\n\\end{example}\n\n\\begin{solution}\nSince the domain of $f$ is the (open) set $\\C \\backslash \\set{0}$, we must necessarily restrict our attention to points $z$ in this set.  Then with $h \\neq 0$, we have\n\\[\n\\frac{f(z+h)-f(z)}{h} = \\frac{\\left( \\frac{1}{z+h} \\right) - \\frac{1}{z}}{h} = \\frac{-1}{z(z+h)}.\n\\]\nSince by assumption $z \\neq 0$, the algebra of limits (Proposition~\\ref{p:alglimits}) tells us that $-\\dfrac{1}{z(z+h)} \\to - \\dfrac{1}{z^2}$ as $h \\to 0$.  Thus $f$ is differentiable at every $z \\in \\C \\backslash \\set{0}$, with $f'(z) = -\\dfrac{1}{z^2}$.\n%\\vspace*{6cm}\n\\end{solution}\n\n\\begin{example}\n\\label{e:diff4}\nFix $\\alpha \\in \\C$ and let $f$ be the constant function $f(z) = \\alpha$ for all $z \\in \\C$.  Then $f$ is differentiable at every point $z \\in \\C$, and satisfies $f'(z)=0$ for all $z \\in \\C$.\n\\end{example}\n\\begin{solution}\nFor any $z\\in \\C$, and $h \\in \\C \\backslash \\set{0}$,\n\\[\n\\frac{f(z+h)-f(z)}{h} = \\frac{\\alpha-\\alpha}{h}=0 \\to 0 \\text{ as } h \\to 0.\n\\]\n\\end{solution}\n\n\\begin{question}\nIf $f:U \\to \\C$ is differentiable at every point $z$ in $U$, and has $f'(z)=0$ for all $z$, is $f$ necessarily constant?\n\\end{question}\n\n\\begin{answer}\nNot necessarily.  If $U=U_1 \\cup U_2$ where $U_1$ and $U_2$ are disjoint open subsets of $\\C$, and $f:U \\to \\C$ is defined by\n\\[\nf(z) = \\begin{cases}\n0 & \\text{ if } z \\in U_1 \\\\\n1& \\text{ if } z \\in U_2,\n\\end{cases}\n\\]\nthen $f'(z)$ exists and is equal to $0$ at every $z \\in U$, but $f$ is non-constant.\n\\end{answer}\n%\\vspace*{5cm}\n\n\\begin{example}\n\\label{e:diff5}\nFix $\\beta \\in \\C$ and let $f(z)=\\beta z$.  Then $f'(z_0) = \\beta$ for all $z_0 \\in \\C$.\n\\end{example}\n\n\\begin{comment}\n\\begin{solution}\n\\[\n\\frac{f(z+h)-f(z)}{h} = \\frac{\\beta(z+h)-\\beta z}{h}=\\beta  \\to 0 \\text{ as } h \\to 0.\n\\]\n\\end{solution}\n\\end{comment}\n\n\\section{Holomorphic Functions}\n\n\\begin{definition}\nLet $U \\subseteq \\C$ be an open set and $f:U \\to \\C$ a complex function.  If $f$ is differentiable at $z$ for all $z \\in U$, we say that $f$ is \\emph{holomorphic on $U$}.\n\\end{definition}\nWhy \\emph{holomorphic} and not simply \\emph{differentiable} on $U$?  One reason for this is that there are many functions $f$ that are differentiable on the real line, but fail to be differentiable throughout any open subset $U \\subseteq \\C$.\n\n\n\\begin{definition}\nLet $f:U \\to \\C$ be a complex function and $z \\in U$.  If there is some $r>0$ such that $f$ is differentiable at every point in the open disc $D(z,r)$, then $f$ is said to be \\emph{holomorphic at $z$}.\n\\end{definition}\n\nIf a function $f$ is holomorphic at $z$, then it is differentiable at $z$, but the converse is not necessarily true.\n\n\n\\begin{example}\nLet us examine whether or not the functions from Examples~\\ref{e:diff1},~\\ref{e:diff2} and~\\ref{e:diff3} are holomorphic on any subsets of $\\C$.\n\\begin{blankbox}\n\\begin{itemize}\n\\item $f(z)=-i\\conj{z}$ is not differentiable at any $z \\in \\C$ and therefore not holomorphic on any $U \\subseteq \\C$.\n%\\vspace*{2cm}\n\\item $f(z) = 1-i z \\conj{z}$ is differentiable at $0$ and nowhere else.  Since the one-point set $\\set{0}$ is not an open set, there is no open subset $U \\subseteq \\C$ with $f$ holomorphic on $U$.\n%\\vspace*{3cm}\n\\item $f(z) = \\dfrac{1}{z}$ is differentiable at every point of the (open) set $\\C \\backslash \\set{0}$ and is therefore holomorphic on this set.\n%\\vspace*{3cm}\n\\end{itemize}\n\\end{blankbox}\n\\end{example}\n\n\n\n\nIf $f:U \\to \\C$ is holomorphic on $U$, then we get a new function $f':U \\to \\C, \\ z \\mapsto f'(z)$, called the \\emph{derivative of $f$}.  In other words, for $z \\in U$, $f'(z)$ is defined as the limit\n\\[\nf'(z) = \\lim_{\\substack{h \\to 0 \\\\ h \\in \\C \\backslash \\set{0}}} \\frac{f(z+h)-f(z)}{h}.\n\\]\n\n\n\nAs for differentiable functions in $\\R$, we have sum, product, chain and quotient rules for holomorphic functions defined on open subsets of $\\C$.\n\n\\begin{theorem}[Rules of Differentiation; proof non-examinable]\n\\label{t:diffrules}\nLet $U$ and $V$ be open subsets of $\\C$ and let $f:U \\to \\C$ and $g:V \\to \\C$ be holomorphic on $U$ and $V$ respectively.  Then\n\\begin{enumerate}\n\\item (Sum rule) $f+g$ is homomorphic on $U \\cap V$ and $(f+g)'(z)=f'(z)+g'(z)$\n\\item (Scalar Multiples) For any $\\alpha \\in \\C$, $(\\alpha f )$ is holomorphic on $U$ and $(\\alpha f)' (z) = \\alpha f'(z)$\n\\item (Product Rule) $fg$ is holomorphic on $U \\cap V$ and $(fg)'(z)=f'(z)g(z)+g'(z)f(z)$\n\\item (Quotient Rule) The quotient $f/g$ is holomorphic on $U \\cap \\set{ z \\in V: g(z) \\neq 0}$ and \n\\[\n\\left( \\frac{f}{g} \\right) '(z) = \\frac{f'(z)g(z)-f(z)g'(z)}{g(z)^2}\n\\]\n\\item (Chain Rule) $f \\circ g$ is holomophic on $V \\cap g^{-1}(U)$ and $(f\\circ g)'(z) = f'(g(z))g'(z).$\n\\end{enumerate}\n\\end{theorem}\n\n%\\vspace*{7cm}\n\\begin{comment}\nSince we only ever speak of a function being holomorphic on an \\emph{open} subset $U \\subseteq \\C$, the statement of Theorem~\\ref{t:diffrules} implicitly relies on the assumption that $U \\cap V$, $U \\cap \\set{ z \\in V: g(z) \\neq 0 }$ and $V \\cap g^{-1} (U)$ are all open whenever $U$ and $V$ are open and $f$ and $g$ are holomorphic.  These are all relatively easy to prove (the second and third rely on Proposition~\\ref{p:diffimpliescontinuous}).\n\nThe proof of Theorem~\\ref{t:diffrules} is very similar to that of the corresponding result for functions of a real variable, and is thus omitted.\n\\end{comment}\n\\begin{example}\n Let $p:\\C \\to \\C$ be a complex polynomial\n\\[\np(z) = \\alpha_0 + \\alpha_1z + \\ldots + \\alpha_n z^n.\n\\]\nThen $p$ is holomorphic on $\\C$.\n\\end{example}\n\n\\begin{solution}\nWe saw in Examples~\\ref{e:diff4} and~\\ref{e:diff5} that the functions $f(z) = \\beta z$ and $g(z)= \\alpha$ (where $\\alpha, \\beta \\in \\C$ are fixed), are holomorphic on $\\C$ with derivatives $f'(z) = \\beta$ and $g'(z)=0$ for all $z \\in \\C$.  Together with Theorem~\\ref{t:diffrules}, this shows that $p(z)$ is holomorphic on $\\C$ with derivative\n\\[\np'(z) = \\alpha_1 + 2\\alpha_2 z + \\ldots + n \\alpha_n z^{n-1}.\n\\]\nThus complex polynomials can be differentiated using exactly the same rules as for real polynomials\n\\end{solution}\n\\begin{note}\nA similar argument shows that if $g(z) = \\dfrac{1}{z^n}$ where $n >0$, then $g'(z) = -\\dfrac{n}{z^{n+1}}$.\n\\end{note}\n\\begin{example}\nThe complex functions $\\exp,\\ \\sin$ and $\\cos$ defined in Chapter 1 are also holomorphic on $\\C$, with derivatives\n\\[\n\\left( \\exp (z) \\right)'=\\exp(z) \\quad \\left( \\sin (z) \\right)' = \\cos (z) \\quad\\text{and}\\quad \\left( \\cos(z) \\right)' = - \\sin(z).\n\\]\n\\end{example}\n\n%\\vspace*{6cm}\n\n\n\\begin{proposition}[Proof non-examinable]\n\\label{p:diffimpliescontinuous}\nLet $f: U \\to \\C$ be differentiable at a point $z \\in U$.  Then $f$ is continuous at $z$.\n\\end{proposition}\n\n\n\\begin{question} If $f$ is holomophic on $U$, is $f'$ holomorphic on $U$?\n\\end{question}\n\\begin{example}\nIn real analysis, consider $g:\\R \\to \\R$ defined by\n\\[\ng(x) = \\begin{cases}\n-x^2 & x<0 \\\\\nx^2 & x\\geq 0.\n\\end{cases}\n\\]\n\\begin{blankbox}\nIt is easily shown that $g$ is differentiable on $\\R$ with $g'(x) = 2 \\abs{x}$ for all $x \\in \\R$.  However, we know that $x \\mapsto 2 \\abs{x}$ fails to be differentiable at $0$.\n\nIn fact for holomorphic functions, the answer is yes.  This gives us an even stronger result: if $f:U \\to \\C$ is holomorphic on $U$, then $f$ is infinitely differentiable on $U$.  We shall return to this later on in the module.\n\\end{blankbox}\n\\end{example}\n\n\\section{The Cauchy Riemann Equations}\nAgain, let $U \\subseteq \\C$ be open.  Suppose we are given $f:U \\to \\C$, then we have seen how to write $f$ as a sum of its real and imaginary parts:\n\n\n\\[ f(x+iy)=u(x,y)+iv(x,y) \\]\nfor all $z=x+iy \\in U$.  \\\n\n\\begin{comment}\nWritten in terms of $z$, we have\n\\[\nf(z) = \\underbrace{\\frac{f(z)+\\conj{f(z)}}{2}}_{\\text{Real}} + i \\underbrace{\\left(\\frac{f(z)-\\conj{f(z)}}{2i} \\right)}_{\\text{Real}}\n\\]\n\\end{comment}\n\n\n\\begin{question}\nIf $u$ and $v$ are differentiable with respect to both $x$ and $y$, does it follow that $f$ is holomorphic?  \n\\end{question}\n\n%\\vspace*{2cm}\n\\begin{answer}\nNo.  We saw in Example~\\ref{e:diff1} that\n\\[\nf(x+iy) = 1-i (x^2+y^2),\n\\]\nwhose real and imaginary parts are differentiable everywhere in $\\R^2$ with respect to both $x$ and $y$, is not differentiable at any point $z \\in \\C \\backslash \\set{0}$.\n\\end{answer}\n\nFor clarity, let us recall the definition of partial derivatives.\n\n\n\n\\begin{definition}\nSuppose that $u: \\R^2 \\to \\R$ is a function.  Then the \\emph{partial derivatives} of $u$ with respect to $x$ and $y$ are the functions $\\frac{\\partial u}{\\partial x}$ and $\\frac{\\partial u}{\\partial y}$ respectively, defined via\n\\begin{align*}\n\\frac{\\partial u}{\\partial x} (x_0,y_0):&= \\lim_{\\substack{h\\to 0\\\\h \\in \\R \\backslash \\set{0}}} \\frac{u(x_0+h,y_0)-u(x_0,y_0)}{h}\\\\\n\\frac{\\partial u}{\\partial y} (x_0,y_0):&= \\lim_{\\substack{h\\to 0\\\\h \\in \\R \\backslash \\set{0}}} \\frac{u(x_0,y_0+h)-u(x_0,y_0)}{h}\n\\end{align*}\nat the points $(x_0,y_0)$ where the limits exist.\n\\end{definition}\n\n\n\n\\begin{theorem}[Differentiability Implies the Cauchy-Riemann Equations]\n\\label{t:cr1}\n\nLet $f$ be a complex-valued function defined on some open set $U$ and let $z_0=x_0+iy_0 \\in U$.  Write\n\\[\nf(x+iy) = u(x,y)+iv(x,y).\n\\]\nThen if $f$ is differentiable at the point $z_0$ we have the following:\n\n\\begin{enumerate}\n\\item[(i)] The partial derivatives $\\pd{u}{x}, \\pd{u}{y}, \\pd{v}{x}, \\pd{v}{y}$ all exist at the point $(x_0,y_0) \\in \\R^2$ corresponding to $z_0$.\n\\item[(ii)] The partial derivatives satisfy the Cauchy-Riemann Equations at $(x_0,y_0)$:\n\\begin{equation}\n\\label{eq:cr}\n\\pd{u}{x} (x_0,y_0) = \\pd{v}{y} (x_0,y_0),\\quad \\pd{u}{y} (x_0,y_0) = - \\pd{v}{x} (x_0,y_0)\n\\end{equation}\n\\item[(iii)] At this point  the derivative of $f$ satisfies\n\\[\nf'(z_0)= \\pd{u}{x} (x_0,y_0) + i \\pd{v}{x} (x_0,y_0) = \\pd{v}{y} (x_0,y_0) - i \\pd{u}{y} (x_0,y_0).\n\\]\n\\end{enumerate}\n\\end{theorem}\n\nBefore proving Theorem~\\ref{t:cr1}, let us look at some examples that demonstrate how it is a powerful result.\n\n\n\n\\begin{example}\n Verify that the Cauchy-Riemann equations are satisfied by the function  $f(z)=z^2$.\\\\\n\\end{example}\n\\begin{solution}\nHere we have\n\\[\nf(x+iy) = \\underbrace{x^2-y^2}_{u(x,y)} + i \\underbrace{2xy}_{v(x,y)},\n\\]\nand hence\n\\[\n\\pd{u}{x} = 2x = \\pd{v}{y} \\text{ and } \\pd{u}{y} = -2y = - \\pd{v}{x}.\n\\]\nThus~\\eqref{eq:cr} holds at every $(x,y) \\in \\R^2$.  Moreover, we have\n\\[\n\\pd{u}{x} + i \\pd{v}{x} = 2x+i2y = 2(x+iy) = 2z = f'(z),\n\\]\nas expected.\n\\end{solution}\n\\begin{example} Use the Cauchy-Riemann equations to investigate the differentiability of $f(z)=\\conj{z}$.\n\\end{example}\n\n\\begin{solution}\nThis time\n\\[\nf(x+iy) = \\underbrace{x}_{u(x,y)} + i \\underbrace{-y}_{v(x,y)},\n\\]\nso that $\\pd{u}{x} = 1$ while $\\pd{v}{y}=-1$ and~\\eqref{eq:cr} does not hold at any point $(x,y) \\in \\R^2$ (note that we need both of the equations in~\\eqref{eq:cr} to hold).\n Thus we conclude that $f(z) = \\conj{z}$ is not differentiable at any point $ z \\in \\C$.\n \\end{solution}\n\n\\begin{exercise}\nBefore we cover it in lectures, try to prove Theorem~\\ref{t:cr1} yourself as follows:\n\\begin{enumerate}\n\\item[(i)] Assuming that $f$ is differentiable at $z_0$, what can be said about the restricted limits\n\\[\n\\rlim{h \\to 0}{h \\in \\R \\backslash \\set{0}} \\frac{f(z_0+h)-f(z_0)}{h} \\quad\\text{and}\\quad \\rlim{h \\to 0}{h \\in \\C \\backslash \\set{0}} \\frac{f(z_0+h)-f(z_0)}{h} \\quad ?\n\\]\n\\item[(ii)] Write the restricted limits from (i) in terms of (the partial derivatives of) $u$ and $v$.  The result should follow easily.\n\\end{enumerate}\n\\end{exercise}\n\\begin{proof}[Proof of Theorem~\\ref{t:cr1}]\nSince $f$ is differentiable at $z_0$ we know that\n\\[\n\\rlim{h\\to 0}{h \\in \\C \\backslash \\set{0}} \\frac{f(z_0+h)-f(z_0)}{h}\n\\]\nexists and is equal to $f'(z_0)$.  In particular, all of corresponding restricted limits exist, and are also equal to $f'(z_0)$.  As before, we shall examine the restricted limits along the real and imaginary axes.\n\nIf we restrict $h$ to the nonzero real axis, then\n\\[\nz_0+h = (x_0+h)+iy_0,\n\\]\nwhich corresponds to the point $(x_0+h,y_0) \\in \\R^2$.  Thus the restricted limit satisfies:\n\n%\\vspace*{10cm}\n\\begin{align*}\nf'(z_0) & = \\rlim{h \\to 0}{h \\in \\R \\backslash \\set{0}} \\frac{f(z_0+h)-f(z_0)}{h} \\\\\n& = \\rlim{h \\to 0}{h \\in \\R \\backslash \\set{0}} \\frac{\\left[ u(x_0+h,y_0)+iv(x_0+h,y_0) \\right] - \\left[ u(x_0,y_0)+iv(x_0,y_0) \\right]}{h} \\\\\n& \\vspace*{2cm} \\\\\n& = \\left( \\rlim{h \\to 0}{h \\in \\R \\backslash \\set{0}} \\frac{u(x_0+h,y_0)-u(x_0,y_0)}{h}  \\right) +i \\left(  \\rlim{h \\to 0}{h \\in \\R \\backslash \\set{0}} \\frac{v(x_0+h,y_0)-v(x_0,y_0)}{h} \\right)  \\\\\n& = \\pd{u}{x} (x_0,y_0)+i \\pd{v}{x} (x_0,y_0).\n\\end{align*}\nHence both $\\pd{u}{x}$ and $\\pd{v}{x}$ exist at the point $(x_0,y_0)$, and the derivative of $f$ at $z_0$ satisfies\n\\begin{equation}\n\\label{eq:cr1}\n\\tag{$\\dagger$}\nf'(z_0) = f'(x_0+iy_0) = \\pd{u}{x} (x_0,y_0)+i \\pd{v}{x} (x_0,y_0).\n\\end{equation}\n%\\vspace*{7cm}\n\nWe shall now examine the restricted limit along the nonzero imaginary axis. This limit must also satisfy\n\\[\nf'(z_0) = \\rlim{h\\to 0}{h \\in i \\R \\backslash \\set{0}} \\frac{f(z_0+h)-f(z_0)}{h}.\n\\]\n%\\vspace*{3cm}\nIf $h \\in i \\R \\backslash \\set{0}$, then $h=0+ik$ for some $k \\in \\R \\backslash \\set{0}$, and so\n\\[\nz_0+h=x_0+i(y_0+k),\n\\]\nwhich corresponds to the point  $(x_0,y_0+k) \\in \\R^2$.\n\nThus\n\\begin{align*}\nf'(z_0) & = \\rlim{h \\to 0}{h \\in i\\R \\backslash \\set{0}} \\frac{f(z_0+h)-f(z_0)}{h} \\\\\n& = \\rlim{k \\to 0}{k \\in \\R \\backslash \\set{0}} \\frac{\\left[ u(x_0,y_0+k)+iv(x_0,y_0+k) \\right] - \\left[ u(x_0,y_0)+iv(x_0,y_0) \\right]}{ik} \\\\\n& \\vspace*{2cm} \\\\\n& =   \\rlim{k \\to 0}{k \\in \\R \\backslash \\set{0}} \\frac{i\\ \\left[ v(x_0,y_0+k)-v(x_0,y_0) \\right]}{ik} +\n \\rlim{k \\to 0}{k \\in \\R \\backslash \\set{0}} \\frac{u(x_0,y_0+k)-u(x_0,y_0)}{ik}     \\\\[5ex]\n & =   \\rlim{k \\to 0}{k \\in \\R \\backslash \\set{0}} \\frac{v(x_0,y_0+k)-v(x_0,y_0)}{k} \n -i \\left( \\rlim{k \\to 0}{k \\in \\R \\backslash \\set{0}} \\frac{u(x_0,y_0+k)-u(x_0,y_0)}{k} \\right)     \\\\\n & = \\pd{v}{y} (x_0,y_0)-i \\pd{u}{y} (x_0,y_0).\n\\end{align*}\nSo $\\pd{u}{y}$ and $\\pd{v}{y}$ also exist at $(x_0,y_0)$, and the derivative of $f$ at $z_0$ also satisfies\n\\begin{equation}\n\\label{eq:cr2}\n\\tag{$\\ddagger$}\nf'(z_0) = f'(x_0+iy_0) = \\pd{v}{y} (x_0,y_0) - i \\pd{u}{y} (x_0,y_0).\n\\end{equation}\nEquating the real and imaginary parts of the two expressions~\\eqref{eq:cr1} and~\\eqref{eq:cr2} for $f'(z_0)$ gives\n\\[\n\\pd{u}{x} (x_0,y_0) = \\pd{v}{y} (x_0,y_0) \\text{ and } \\pd{v}{x}(x_0,y_0) = - \\pd {u}{y} (x_0,y_0),\n\\]\nwhich completes the proof.\n%\\vspace*{15cm}\n\\end{proof}\nThe Cauchy Riemann Equations provide a very useful way of showing that a function is \\emph{not} holomorphic.  We cannot use Theorem~\\ref{t:cr1} to show that a function is holomorphic.\n\\begin{example}\nFor the function $f: \\C \\to \\C$ defined by\n\\[\nf(z) = \n\\begin{cases}\n\\exp(-z^{-4}) & z \\neq 0 \\\\\n0 & z=0\n\\end{cases}\n\\]\nthe partial derivatives of $u$ and $v$ satisfy the Cauchy-Riemann equations everywhere, but $f$ is not differentiable (nor even continuous) at $z=0$.  (This is difficult to prove).\n\\end{example}\n\\begin{comment}\n\\begin{remark}\nA partial converse does exist: if $f:U \\to \\C$ is given by\n\\[\nf(x+iy)=u(x,y)+iv(x,y)\n\\]\nand if at all points of $U$, the partial derivatives of $u$ and $v$ (a) exist (b) satisfy the Cauchy Riemann equations and (c) are continuous, then $f$ is holomophic on $U$.  This is far more difficult to prove (and you are forbidden from using it in this module!).\n\\end{remark}\n\\begin{remark} (Note: completely irrelevant for this module)\nLet $f:U \\to \\C$ be given and let $\\mathbf{f}:U \\to \\R^2$ denote the corresponding real function.  If $f$ satisfies the Cauchy-Riemann equations, then $\\mathbf{f}$ satisfies the \\emph{Laplace Equation}\n\\[\n\\pd{{}^2\\mathbf{f}}{x^2} + \\pd{{}^2\\mathbf{f}}{y^2}=0,\n\\]\nand important partial differential equation that shows up in many branches of mathematics and physics.  Thus the study of holomorphic functions is closely related to the study of the Laplace equation.  Indeed, solutions to this PDE are known as \\emph{harmonic functions}, and there is an entire branch of mathematics dedicated to their study.\n\\end{remark}\n\\end{comment}\n\n\\section{Geometry of Derivatives for Complex-Valued Functions}\nWhen working with differentiable functions in $\\R$, it is useful to have the geometric picture of the derivative of a function $g: \\R \\to \\R$ - for example, by considering $g'(x)$ as the slope of the tangent to the graph of $g$ at the point $(x,g(x))$.  In this section we will try to give a geometric description of the derivative of a holomorphic function $f:U \\to \\C$ at a point $z_0 \\in U$.  Since we cannot draw the graph of such a function, some care is needed.\n\nReturning to the real case, consider the following graph of a differentiable function $g:\\R \\to \\R$:\n\\begin{center}\n\\begin{tabular}{ccc}\n\\altgraphics[scale=0.5]{ch2_realderivative1_full}{ch2_realderivative1} & \\qquad & \\altgraphics[scale=0.5]{ch2_realderivative2_full}{ch2_realderivative2}\n\\end{tabular}\n\\end{center}\n\nFor sufficiently small $h$ we have\n\\[\n\\frac{g(a+h)-g(a)}{h} \\approx g'(a).\n\\]\n\\begin{blankbox}\nWe can rewrite this approximation as\n\\[\ng(a+h)-g(a) \\approx g'(a) h.\n\\]\nNow, at least when $g'(a) \\neq 0$, we know that $g$ maps the interval $[a,a+h]$, of length $h$, to the interval $[g(a),g(a+h)]$ of length $g(a+h)-g(a)$  i.e. length approximately $g'(a)h$. \n\nIn other words, $g$ moves $[a,a+h]$ to an interval from $g(a)$, and (approximately) scales it by a factor of $g'(a)$.\n%\\vspace*{3cm}\n\\end{blankbox}\nIf $g'(a)$ is negative, then $[a,a+h]$ is approximately sent to $[g(a+h),g(a)]$. \n\\begin{blankbox}\nThen the mapping reverses the direction of the interval, i.e., sends $[a,a+h]$ to $[g(a+h),g(a)]$.  Again, the interval is scaled by a factor of $\\abs{g'(a)}$, but this time, also rotated by an angle of $\\pi$.  We can represent these mappings using one-dimensional figures as shown.\n\n{\n\\centering\n%\\altgraphics[scale=0.4]{ch2_4lines_full}{ch2_4lines}\n\\hidegraphics[width=0.8\\textwidth]{ch2_4lines}\n\\showgraphics[width=\\textwidth]{ch2_4lines_full}\n}\n\\end{blankbox}\n\nFor a complex function $f:U \\to \\C$, its graph is the set of points\n\\[\n\\set{ (z,f(z)): z \\in U },\n\\]\nas subset of $\\C^2$.  We would need 4 coordinates to draw such a graph, which is impossible.\n\n\\begin{question}\nHow do we describe the geometry of derivatives of complex functions?\n\\end{question}\n\n\\begin{answer}\nTo describe the derivative of $f'(z_0)$ for a point $z_0 \\in U$ geometrically, we will look at an analogy of the real case we have described above.   Indeed, rather than looking at a small interval of the form $[a,a+h]$, we look at a small disk $D(z_0,r)$ centred at  $z_0$.  Again, let us restrict to the case where $g'(z_0) \\neq 0$.\n\nIf $r$ is `small' and $z=z_0+h \\in D(z_0,r)$ then again\n\\[\n\\frac{f(z_0+h)-f(z_0)}{h} \\approx f'(z_0).\n\\]\n\nThis can be rewritten as\n\\[\nf(z_0+h) - f(z_0)\\approx hf'(z_0), \\quad\\text{i.e.}\\quad f(z)-f(z_0) \\approx hf'(z_0).\n\\]\nIf we think of $h$ as the vector from $z_0$ to $z$, and $f(z)-f(z_0)$ as the vector from $f(z_0)$ to $f(z)$, then roughly speaking, $f$  sends $h$ to $hf'(z_0)$.  In other words, the vector $h$ gets moved to a vector from $f(z_0)$, and approximately gets multiplied by $f'(z_0)$, i.e.\n\\begin{itemize}\n\\item scaled by a factor of $\\abs{f'(z_0)}$ and\n\\item rotated by angle $\\arg (f'(z_0))$ anticlockwise about $f(z_0)$.\n\\end{itemize}\nAgain, we are using the fact that for $z_1,z_2 \\in \\C$, $\\abs{z_1z_2} = \\abs{z_1} \\abs{z_2}$ and $\\arg (z_1z_2) = \\arg(z_1)+\\arg(z_2)$.\n\n\\begin{center}\n\\begin{tabular}{cc}\n\\hidegraphics[scale=1]{ch2_deriv3} & \\qquad \\hidegraphics[scale=1]{ch2_deriv4} \\\\\n\\end{tabular}\n\\showgraphics[width=\\textwidth]{ch2_complexderiv_full}\n\\end{center}\n\\end{answer}\nSince the above remarks hold for any $z \\in D(z_0,r)$, the mapping $f$ approximately transforms all points in $D(z_0,r)$ in the same way.\n\\begin{summary}\nLet $f$ be differentiable at a point $z_0 \\in \\C$ with $f'(z_0) \\neq 0$, then $f$ approximately maps small disks centred at $z_0$ to small disks centred at $f(z_0)$ as follows:\n\\begin{center}\n\\emph{scaling by a factor of $\\abs{f'(z_0)}$ and rotating by an angle of $\\arg (f'(z_0))$ anticlockwise about $f(z_0)$.}\n\\end{center}\n\\end{summary}\n\\begin{figure}[H]\n\\centering\n\\altgraphics[width=\\textwidth]{ch2_geometry_deriv_full}{ch2_geometry_deriv}\n\\caption{The image under $f$ of a small disc centred at $z_0$.}\n\\end{figure}\n\n\\begin{example}\nFind the geometric effect of applying the function\n\\[\nf(z)=z^2-\\frac{i}{z^2}\n\\]\nto a small disk centred at $i$.\n\\end{example}\n%\\vspace*{12cm}\n\\begin{solution}\nSince $f$ is differentiable at $i$, the previous remarks indicate that a small disc centred at $i$ gets sent to a small disc centred at $f(i)$, where\n\\[\nf(i) = i^2-\\frac{i}{i^2} = -i+1.\n\\]\nTo determine the geometric effect of $f$ applied to this disc, we need to calculate $\\abs{f'(i)}$ and $\\arg (f'(i))$.  The rules of differentiation tell us that\n\\[\nf'(z) = 2z-i \\left( \\frac{-2}{z^3} \\right) = 2z+ \\frac{2i}{z^3},\n\\]\nand hence $f'(i) = 2i-2$, which has modulus $\\abs{2i-2}=2\\sqrt{2}$ and argument $3\\pi/4$.\n\nHence a small disc at $i$ is approximately mapped to a small disc at $-1+i$, and is scaled by a factor of $2\\sqrt{2}$ and rotated by an angle of $3\\pi/4$  in the anticlockwise direction about $-1+i$.\n\n\\end{solution}\n\n\\begin{figure}[H]\n\\centering\n\\hidegraphics[scale=1]{ch2_parametric3} \\quad \\hidegraphics[scale=1]{ch2_parametric4}\n\\showgraphics[scale=0.5]{ch2_parametric3_full}\n\\caption{The geometric effect of applying $f(z)=z^2-\\dfrac{i}{z^2}$ to small circles centred at $i$. The transformed circles are centred at $f(i)$.  As Figure~\\ref{f:circles} shows, the images of the smaller circles are almost circular, but the larger ones less so.  The horizontal line from $i$ is rotated by $\\arg(f'(i))$.}\n\\label{f:circles}\n\\end{figure}\n\n\\begin{example}\nDetermine the geometric effect of applying the function $f$, where $f(z)=z^3$, to a small disc centred at $z_0 = \\sqrt{3}-i$.\n\\end{example}\n\\begin{solution}\nThis time, the disc gets sent to a disc centred at $f(z_0) = (\\sqrt{3}-i)^3 = -4i$.  Since $f'(z)=3z^2$, we have\n\\[\nf'(\\sqrt{3}-i) = 3 ( \\sqrt{3}-i)^2 = 3 (2-i2\\sqrt{3}) = 6-i6\\sqrt{3}.\n\\]\nThus\n\\[\n\\abs{f'(\\sqrt{3}-i) } = \\sqrt{(6)^2+\\left(6\\sqrt{3}\\right)^2 } = 12,\n\\]\nand\n\\[\n\\arg \\left( f' (\\sqrt{3}-i ) \\right) = \\arg \\left( 6-i6\\sqrt{3} \\right) = - \\pi/3.\n\\]\n\nHence a small disc at $\\sqrt{3}-i$ is approximately mapped to a small disc at $-4i$, and is scaled by a factor of $12$ and rotated by an angle of $-\\pi/3$  in the \\emph{clockwise} direction about $-4i$ (note: this time the rotation is clockwise since $\\arg (f'(z_0))$ is negative).\n\\end{solution}\n\n\n\n\n", "meta": {"hexsha": "781b792f847366c621df06ba0f3ed10505d26621", "size": 27091, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2003/LectureNotes/Chapter_2.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2003/LectureNotes/Chapter_2.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2003/LectureNotes/Chapter_2.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 43.2073365231, "max_line_length": 467, "alphanum_fraction": 0.6572662508, "num_tokens": 10165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528094861981, "lm_q2_score": 0.8519528094861981, "lm_q1q2_score": 0.7258235895914262}}
{"text": "Many people (and textbooks) incorrectly refer to \\java{\\%} as the ``modulus operator''.\nIn mathematics, however, {\\bf modulus} is the number you're dividing by.\nIn the previous example, the modulus is 12.\nThe Java language specification refers to  \\java{\\%} as the ``remainder operator''.\n\nThe remainder operator looks like a percent sign, but you might find it helpful to think of it as a division sign ($\\div$) rotated to the left.\n\n%Note that both \\java{/} and \\java{\\%} perform {\\em integer division}, so the result always rounds down.\n%The reason why integer division ``rounds down'' is that the hardware computes the quotient and remainder separately.\n\n\\index{divisible}\n\\index{extract digits}\n\nModular arithmetic turns out to be surprisingly useful.\nFor example, you can check whether one number is divisible by another: if \\java{x \\% y} is zero, then \\java{x} is divisible by \\java{y}.\nYou can use remainder to ``extract'' digits from a number: \\java{x \\% 10} yields the rightmost digit of \\java{x}, and \\java{x \\% 100} yields the last two digits.\nAnd many encryption algorithms use the remainder operator extensively.\n\n\n\\section{Putting it all together}\n\nAt this point, you have seen enough Java to write useful programs that solve everyday problems.\nYou can (1) import Java library classes, (2) create a \\java{Scanner}, (3) get input from the keyboard, (4) format output with \\java{printf}, and (5) divide and mod integers.\nNow we will put everything together in a complete program:\n\n%Since we've looked at each of these topics in isolation, it's important to see how they fit together in a complete program.\n%If you've been working through the examples on your computer as you've been reading (like we recommended in Section~\\ref{sec:examples}), then good job!\n\n\nUsing division and modulo, we can convert to feet and inches like this:\n\n\\begin{code}\n    feet = 76 / 12;    // quotient\n    inches = 76 % 12;  // remainder\n\\end{code}\n\nThe first line yields 6.\nThe second line, which is pronounced ``76 mod 12'', yields 4.\nSo 76 inches is 6 feet, 4 inches.\n\nAddition, subtraction, and multiplication all do what you expect, but you might be surprised by division.\nFor example, the following fragment tries to compute the fraction of an hour that has elapsed:%, but it has a logic error:\n\nAt this point, you have seen enough Java to write useful programs that solve everyday problems.\nYou can (1) import Java library classes, (2) create a \\java{Scanner}, (3) get input from the keyboard, (4) format output with \\java{printf}, and (5) divide and mod integers.\nNow we will put everything together in a complete program:\n\n%Since we've looked at each of these topics in isolation, it's important to see how they fit together in a complete program.\n%If you've been working through the examples on your computer as you've been reading (like we recommended in Section~\\ref{sec:examples}), then good job!\n\n\\index{Convert.java}\n\n\\begin{trinket}{Convert.java}\nimport java.util.Scanner;\n\n/**\n* Converts centimeters to feet and inches.\n*/\npublic class Convert {\n\n    public static void main(String[] args) {\n        double cm;\n        int feet, inches, remainder;\n        final double CM_PER_INCH = 2.54;\n        final int IN_PER_FOOT = 12;\n        Scanner in = new Scanner(System.in);\n\n        // prompt the user and get the value\n        System.out.print(\"Exactly how many cm? \");\n        cm = in.nextDouble();\n\n        // convert and output the result\n        inches = (int) (cm / CM_PER_INCH);\n        feet = inches / IN_PER_FOOT;\n        remainder = inches % IN_PER_FOOT;\n        System.out.printf(\"%.2f cm = %d ft, %d in\\n\",\n        cm, feet, remainder);\n    }\n}\n\\end{trinket}\n\nAlthough not required, all variables and constants are declared at the top of \\java{main}.\nThis practice makes it easier to find their types later on, and it helps the reader know what data is involved in the algorithm.\n", "meta": {"hexsha": "c835f40b306a56af9a265ef4d6434f2b0d6736bf", "size": 3898, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tests/unit/cases/comments.tex", "max_stars_repo_name": "codio/book-converter", "max_stars_repo_head_hexsha": "ea3fd75f2ca8704ffad6bfcc83cf7af557bcd0b8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-14T12:22:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-14T12:22:25.000Z", "max_issues_repo_path": "tests/unit/cases/comments.tex", "max_issues_repo_name": "codio/book-converter", "max_issues_repo_head_hexsha": "ea3fd75f2ca8704ffad6bfcc83cf7af557bcd0b8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-08-21T08:24:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-11T23:57:03.000Z", "max_forks_repo_path": "tests/unit/cases/comments.tex", "max_forks_repo_name": "codio/book-converter", "max_forks_repo_head_hexsha": "ea3fd75f2ca8704ffad6bfcc83cf7af557bcd0b8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.4047619048, "max_line_length": 173, "alphanum_fraction": 0.7239610056, "num_tokens": 927, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504226, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7258235639718841}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{subfigure}\n\\usepackage{float}\n\\usepackage{ulem}\n\\usepackage{bm}\n\n\\usepackage{anysize}\n\n\\marginsize{2cm}{2cm}{0.9cm}{1.8cm}\n\\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}\n\\usepackage{listings}\n\\lstset{language=Matlab}\n\\lstset{breaklines}\n\\lstset{extendedchars=false}\n\n\\title{Machine Learning/Pattern Recognition\\\\  \\begin{Large} Homework \\#4 \\end{Large} }\n\\author{Jiyu Tian}\n\\date{}\n\n\n\\begin{document}\n\n\\maketitle\n%%---------------------------------------------------------------\n%% Problem 1\n%%---------------------------------------------------------------\n\\section{Problem 4.1}\n\\textbf{\\begin{large}Solution:\\end{large}}\\\\\n\\\\\n(a) The expectation maximization algorithm for a given Gaussian mixture model is:\\\\\n\\\\\n\\textbf{1.} Initialize the means $\\bm{\\mu}_k$, covariances $\\bm{\\Sigma}_k$ and mixing coefficients $\\pi_k$, and evaluate the initial value of the likelihood.\\\\\n\\textbf{2. E step}. Evaluate the responsibilities using the current parameter values\n\\begin{equation*}\n\\gamma(z_{nk})=\\frac{\\pi_k \\mathcal{ N}(\\bm{x}_n|\\bm{\\mu}_k,\\bm{\\Sigma}_k)}{\\sum_{j=1}^K\\pi_j \\mathcal{ N}(\\bm{x}_n|\\bm{\\mu}_j,\\bm{\\Sigma}_j)}\n\\end{equation*}\n\\textbf{3. M step}. Re-estimate the parameters using the current responsibilities\n\\begin{equation*}\n\\bm{\\mu}_k^{new}=\\frac{1}{N_k}\\sum_{n=1}^N\\gamma(z_{nk})\\bm{x}_n \n\\end{equation*}\n\\begin{equation*}\n\\bm{\\Sigma}_k^{new}=\\frac{1}{N_k}\\sum_{n=1}^N\\gamma(z_{nk})(\\bm{x}_n-\\bm{\\mu}_k^{new})(\\bm{x}_n-\\bm{\\mu}_k^{new})^T\n\\end{equation*}\n\\begin{equation*}\n\\pi_k^{new}=\\frac{N_k}{N}\n\\end{equation*}\nwhere $N_k = \\sum_{n=1}^N\\gamma(z_{nk})$.\\\\\n\\textbf{4.} Evaluate the log likelihood\n\\begin{equation*}\n\\text{ln }p(\\bm{X}|\\bm{\\mu},\\bm{\\Sigma},\\bm{\\pi})= \\sum^N_{n=1} \\text{ln } \\{\\sum_{j=1}^K\\pi_k \\mathcal{ N}(\\bm{x}_n|\\bm{\\mu}_k,\\bm{\\Sigma}_k)\\}\n\\end{equation*}\nand check for convergence of either the parameters or the log likelihood. If the convergence criterion is not satisfied return to step 2.\\\\\n\\\\\n(b) See Figure 1. Comparing to K-means, EM performed better because it takes into consideration the corresponding covariance matrix rather than uniformly identity covariance matrix.\\\\\n\\\\\n(c) See Figure 2. EM is able to find the true clusters and the origin covariance matrices. However, it performs not quite well in the intersection.\n\\vfill\n\\clearpage\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{41b.png}\n\\caption{Result\\ of\\ clustering\\ with\\ EM-GMM\\ on\\ dataset1.mat}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{41c.png}\n\\caption{Result of clustering with EM-GMM on dataset2.mat}\n\\end{figure}\n\n\\vfill\n\\clearpage\n\n\n\\noindent(d) See Figure 3. Since the true clusters are radial while EM tries to fit the data points with Gaussian mixture, EM does not find the true clusters. However, EM still performs better than K-means.\\\\\n\\\\\n(e) See Figure 4. EM is able to capture the distribution of this non-Gaussian dataset better than K-means. \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{41d.png}\n\\caption{Result of clustering with EM-GMM on dataset3.mat}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{41e.png}\n\\caption{Result of clustering with EM-GMM on dataset4.mat}\n\\end{figure}\n\\vfill\n\\clearpage\n\\section{Problem 4.2}\n\\textbf{\\begin{large}Solution:\\end{large}}\\\\\n\\\\\n(a) See Figure 5. The maximum matches the true number of clusters.\\\\\n\\\\\n(b) See Figure 6. The maximum matches the true number of clusters.\\\\\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{42a.png}\n\\caption{BIC result of clustering with EM-GMM on dataset1.mat}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{42b.png}\n\\caption{BIC result of clustering with EM-GMM on dataset2.mat}\n\\end{figure}\n\\vfill\n\\clearpage\n\n\\noindent(c) See Figure 7. BIC does not find the true number of clusters.\\\\\n\\\\\n(d) See Figure 8. The maximum matches the true number of clusters. However, there would be only two clusters in the result, which I believe depends on the initial conditions for EM algorithm.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{42c.png}\n\\caption{BIC result of clustering with EM-GMM on dataset3.mat}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{42d.png}\n\\caption{BIC result of clustering with EM-GMM on dataset4.mat}\n\\end{figure}\n\\vfill\n\\clearpage\n\n\\noindent(e) Both K-means and EM-GMM give the result of four clusters, but EM-GMM has a better explanation for the dataset.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{42e.png}\n\\caption{BIC result of clustering with EM-GMM on dataset5.mat}\n\\end{figure}\n\n\n\\end{document}\n", "meta": {"hexsha": "d9095d7740990448d5d155e100bf4040d648baca", "size": 4776, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "EECE5644-Introduction-to-Machine-Learning-and-Pattern-Recognition/Homework-4/Report/main.tex", "max_stars_repo_name": "tjyiiuan/Graduate-Courses", "max_stars_repo_head_hexsha": "7f8b018dc92431d8f054a38e1a7fd2c284e1cce0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "EECE5644-Introduction-to-Machine-Learning-and-Pattern-Recognition/Homework-4/Report/main.tex", "max_issues_repo_name": "tjyiiuan/Graduate-Courses", "max_issues_repo_head_hexsha": "7f8b018dc92431d8f054a38e1a7fd2c284e1cce0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "EECE5644-Introduction-to-Machine-Learning-and-Pattern-Recognition/Homework-4/Report/main.tex", "max_forks_repo_name": "tjyiiuan/Graduate-Courses", "max_forks_repo_head_hexsha": "7f8b018dc92431d8f054a38e1a7fd2c284e1cce0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.1666666667, "max_line_length": 208, "alphanum_fraction": 0.7158710218, "num_tokens": 1501, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711718571774, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7258012201301993}}
{"text": "\\section{General continuous piecewise linear functions as a DNN}\n\\subsection{Lattice representation of CPWL}\n\nWe say a function $f:\\mathbb{R}^n \\to \\mathbb{R}$ is continuous piecewise linear (CPWL) if there exists a finite set of polyhedra whose union is $\\mathbb{R}^n$, and $f$ is affine linear over each polyhedron (note that the definition automatically implies continuity of the function because the affine regions are closed and cover $\\mathbb{R}^n$, and affine functions are continuous). The number of pieces of $f$ is the number of maximal connected subsets of $\\mathbb{R}^n$ over which $f$ is affine linear (which is finite).\n\n\\begin{figure}[!ht]\n\\centering\n\t\\includegraphics[width=0.6\\textwidth]{6DL/figures/latticePWL.png}   \n\t\\caption{Unique order regions.} \n\t\\label{fig:latticePWL}\n\\end{figure}\nFigure \\ref{fig:latticePWL} shows a CPWL function with unidimensional domain that has a domain partition generated by $4$ boundaries. The result is a set of $5$ regions and the corresponding set of $5$ local functions, two of which are identical, $f_2$ and $f_5$. In the case of a model described in terms of the local functions. \n\nThe arrangements in ascending order of the linear functions in the points $a$ and $b$ of region $R_4$ are respectively, ($f_2 = f_5 < f_1 < f_4 < f_3$) and ($f_2= f_5 < f_4 < f_1 < f_3$). We note that the intersection of the linear functions fland f4occurs at point x5, an inner point of $R_4$. Given the importance of the order arrangement when dealing with models based on the local functions, the division of region $R_4$ into two subregions is practically meaningful.\n\nAny intersection of linear functions produces a change of order arrangement. So, if we consider every intersection of local functions, the resulting domain partition will be formed by connected, and convex regions with a unique order arrangement. It should be noted that some of those intersections might not correspond to any boundary of the PWL function.  \n\nWe introduce a domain partition that will have unique order on each subdomain \\cite{tarela1999region}.\n\\begin{definition}\n\tLet $f:\\mathbb{R}^n\\to\\mathbb{R}$ be a continuous piecewise linear function with m distinct local functions $l_i$, $1\\le i\\le m$. Consider the intersections between local functions, those intersections with some noticed segments in $f$ will be called visible boundaries, and those boundaries corresponds to the set of functions $\\{\\phi_{\\lambda_v}\\}$. The rest of intersections occurring inside the domain will be called hidden boundaries and noted as $\\{\\phi'_{\\lambda_h}\\}$. A \\textbf{unique-order region} is each region of the domain partition produced by the boundary configuration $\\{\\phi_{\\lambda_v}\\}\\bigcup\\{\\phi'_{\\lambda_h}\\}$.\n\\end{definition}\n\n\\bigskip\nThe unique-order regions have the following characterizations:\n\\begin{itemize}\n\t\\item The domain of $f$ is divided into $M$ unique-order regions.\n\t\\item The local function associated to two unique-order regions may be identical.\n\t\\item The unique-order regions are convex.\n\t\\item A unique-order region has the same rearrangement in ascending order of the values of the $m$ local functions in all its points.\n\\end{itemize}\n\n\\begin{remark}\n\tIf $m$ is the number of distinct linear components of $f$, then the maximum number of rearrangements in ascending order is $m!$. However, the number of unique-order regions is in general lower than $m!$, because of the geometric constraints of the problem \\cite{wilkinson1963method}. Thus, the different arrangements in $\\mathbb{R}^n$ is $Q$, then:\n\t\\begin{equation*}\n\t\\begin{aligned}\n\t&\\mathrm{if}\\ 1\\le m\\le n+1\\quad\\Rightarrow Q=m!\\\\\n\t&\\mathrm{if}\\ m\\ge n+2\\quad\\Rightarrow (n+1)!<Q<m!\n\t\\end{aligned}\n\t\\end{equation*}\n\tThe number of unique-regions is $M$, then we have $M\\le Q$, since only some of these arrangements constitute unique-order regions.\n\\end{remark}\n\n\n\n\n\\begin{lemma}\\label{lem:1dlattice}\n\tIf $p(t)$ is a continuous piecewise linear function. And the unique-order region partition is\n\t$$0 = t_0 < t_1 < ... < t_{r+1} = 1$$\n\tand the linear function in $[t_i,t_{i+1}]$ is $l_i(t) = k_i t+b_i$. And parameter satisfied \n\t$$ b_0 > b_r,\\qquad k_0 + b_0 > k_r + b_r $$\n\twhich means\n\t$$l_0(t)> l_r(t)\\quad \\mbox{in}\\quad [t_0,t_1]$$\n\t$$l_0(t)> l_r(t)\\quad \\mbox{in}\\quad [t_r,t_{r+1}]$$\n\tThen, exist $l_p(t) = k_p t+ b_p$, such that\n\t$$b_p \\ge b_0,\\qquad k_p+b_p\\le k_r+b_r$$  \n\tThat's to say\n\t$$l_0(t)\\le l_p(t)\\quad \\mbox{in}\\quad [t_0,t_1]$$\n\t$$l_p(t)\\le l_r(t)\\quad \\mbox{in}\\quad [t_r,t_{r+1}]$$\n\\end{lemma}\n\\begin{figure}[th]\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{6DL/pic/fig1}\n\t\\caption{}\n\\end{figure}\n\n\\begin{proof}\n\t\n\tLet $k_p=\\min\\{k_i\\}$, $\\Delta t_i=t_{i+1}-t_i$. \n\tSince here we only have linear functions, so we can represent each point $(t_i,y_i)$ by using $k_i$'s and $\\Delta t_i$'s.\n\tThen the point $(t_p,b_0+\\sum_{i=0}^{p-1}k_i\\Delta t_i)$ is on $y=k_p t+b_p$, so we can represent $b_p$ as following:\n\t$$b_p=b_0+\\sum_{i=0}^{p-1}k_i\\Delta t_i-k_p t_p=b_0+\\sum_{i=0}^{p-1}(k_i-k_p)\\Delta t_i$$\n\tSince here $k_p$ is the minimum, we have:\n\t$$b_p=b_0+\\sum_{i=0}^{p-1}(k_i-k_p)\\Delta t_i\\ge b_0$$\t\t\n\tAnd\n\t\\begin{equation*}\n\t\\begin{aligned}\n\tk_p+b_p&=k_p+b_0+\\sum_{i=0}^{p-1}(k_i-k_p)\\Delta t_i\\\\\n\tk_r+b_r&=k_r+b_0+\\sum_{i=0}^{r-1}(k_i-k_p)\\Delta t_i\\\\\n\t(k_r+b_r)-(k_p+b_p)&=k_r-k_p+\\sum_{i=p}^{r-1}(k_i-k_p)\\Delta t_i\\ge 0\n\t\\end{aligned}\n\t\\end{equation*}\n\twhich means we find the desired pair of $k$ and $p$.\n\tNotice here $k_p\\ne k_0$ and $k_p\\ne k_r$ by the assumptions in the lemma. This completes the proof.\n\t\n\\end{proof}\t\n\n\n\\bigskip\t\t\n\\begin{theorem}\\label{PWLtoRelu}\n\tFor every continuous piecewise linear function $f:\\mathbb{R}^n\\to\\mathbb{R}$ with finite pieces defined by the distinct local linear functions $l_i$, $1\\le i\\le m$ and $\\{\\Omega_k\\}_{k=1}^M$ be the unique-order subdomains. Then there exist finite non-empty subsets of $\\{1,2,\\dots,m\\}$, say $s_k$, $1\\le k\\le M$, such that \n\t\\begin{equation}\n\tf(x)=\\max_{1\\le k\\le M}\\{\\min_{i\\in s_k} l_i\\},\n\t\\end{equation}\n\there $s_k=\\{i: l_i\\ge l_k\\ \\mathrm{on}\\ \\Omega_{k}\\}$.\n\\end{theorem}\n\n\n\\begin{proof}\n\tLet $l_i(x)=f(x)|_{\\Omega_k}$. In each $\\Omega_{k}$, consider the functions lie completely above $l_k$, and define the convex polynomial\n\t$$\\Phi_{k}=\\min_{i\\in s_k} l_i.$$\n\tDefine\n\t$$\\Phi(x)=\\max_{k} \\Phi_{k}(x)$$\n\tand next we show that $\\Phi_{k}(x)\\le f(x)$ for all x and every $k$.\n\t \n\t\n\tFor any fixed $k$, if $x_0\\in\\Omega_{k}$,\n\t$$\n\t\\Phi_{k}(x_0)=l_k(x_0)= f(x_0).\n\t$$\n\tIf $x_0\\notin\\Omega_{k}$, then we suppose $x_0\\in \\Omega_{k'}$, so \n\t$$\n\tf(x_0)|_{\\Omega_{k'}}=l_{k'}(x_0).\n\t$$ \n\tNotice that here we have unique-order region, thus in each $\\Omega_i$, the order of $l_k$ and $l_{k'}$ is fixed. There're several situations:\n\t\\begin{enumerate}\n\t\t\\item  If $l_{k'}(x)\\ge l_{k}(x)$ for $x\\in \\Omega_{k}$, then $l_{k'}$ is a lattice variable in the convex polynomial $\\Phi_k$, and so\n\t\t$$\\Phi_{k}(x_0)\\le l_{k'}(x_0)=f(x_0).$$\n\t\t\\item  If $l_{k'}(x)< l_{k}(x)$ for $x\\in \\Omega_{k}$, then we consider the domain $\\Omega_{k'}$:\n\t\t\\begin{enumerate}\n\t\t\t\\item \n\t\t\tIf $l_{k'}(x)\\ge l_k(x)$ for $x\\in \\Omega_{k'}$. Then on $\\Omega_{k'}$,\n\t\t\t\\begin{equation*}\n\t\t\t\\Phi_{k}(x_0)= l_k(x_0)\\le l_{k'}(x_0)=f(x_0)\n\t\t\t\\end{equation*}\n\t\t\t\\item  \n\t\t\tIf $l_{k'}(x)< l_k(x)$ for $x\\in \\Omega_{k'}$. We take $x\\in \\Omega_{k}^\\circ, x' \\in \\Omega_{k'}^\\circ$. Then we have a path $L(\\theta)$, the coordinate of the path is defined as \n\t\t\t$$\n\t\t\t(x + \\theta(x'-x),f(x + \\theta(x'-x)))\n\t\t\t$$ \n\t\t\twith $\\theta\\in[0,1]$(see Figure~\\ref{fig:sec:lattice}). It is just a piecewise linear function with the parameter $\\theta$. Notice that the domain partition is unique-order. So if we want to compare the order of the linear function,  we just compare one point value in that region. \n\t\t\\begin{figure}[th]\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.7\\linewidth]{6DL/pic/fig2}\n\t\t\t\\caption{figure}\n\t\t\t\\label{fig:sec:lattice}\n\t\t\\end{figure}\n\t\tThen by Lemma \\ref{lem:1dlattice}, there must exist $l_t$ with $t\\ne k,k'$ and\n\t\t\t\\begin{equation*}\n\t\t\t\\begin{aligned}\n\t\t\t&l_t\\le l_{k'}\\quad \\mathrm{on}\\ \\Omega_{k'}\\\\\n\t\t\t&l_t\\ge l_{k}\\quad \\mathrm{on}\\ \\Omega_{k}\n\t\t\t\\end{aligned}\n\t\t\t\\end{equation*}\n\t\t\tThen we should have:\n\t\t\t$$\\Phi_{k}(x_0)\\le l_t(x_0)\\le l_{k'}(x_0)=f(x_0).$$\n\t\t\\end{enumerate}\n\t\\end{enumerate}\nThus for every $\\Phi_{k}$, we have $\\Phi_{k}(x)\\le f(x)$ for all $x$. It is obvious that  $f(x)\\le \\Phi_{k}(x)$ for all $x$ since\n$$\nf(x)=l_k(x)\\le \\max_k l_k=\\max \\Phi_k=\\Phi(x),\\quad \\forall x\\in \\Omega_k.\n$$\nSo \n\t\t\t$$f(x)=\\max_{k}\\min_{i\\in s_k}\\{l_i\\}$$\n\t\t\tThis is exactly the desired form. Here $|s_k|\\le m$, and the number of $\\Phi_{k}$ depends on the partition we do. \n\\end{proof}\n\n\n\n\n\\subsection{General CPWL as a DNN}\n\nAssume that $f:\\mathbb{R}^d\\to\\mathbb{R}$ is a continuous function\nthat are piecewise linear on $m$ subdomains\n$$\n\\Omega_i, \\quad i=1:m.\n$$\nNamely, on each $\\Omega_i$, $f$ is a linear function:\n$$\nf(x)=f_i(x)=a_i\\cdot x+b_i, \\quad x\\in \\Omega_i,\n$$\nwith some $a_i \\in \\mathbb{R}^d$ and $b_i \\in \\mathbb{R}$.\n\nCombining Theorem \\ref{PWLtoRelu} with Lemma \\ref{linearcombine2Relu}, we have the following result.\n\\begin{theorem}\nEvery $\\mathbb{R}^{d} \\rightarrow \\mathbb{R}$ ReLU DNN represents a piecewise linear function, and every piecewise linear function $\\mathbb{R}^{d} \\rightarrow \\mathbb{R}$ can be represented by a ReLU DNN with at most $\\left\\lceil\\log _{2}(d+1) \\right\\rceil+1$ depth.\n\\end{theorem}\n\\begin{proof}\nIt is clear that any function represented by a ReLU DNN is a PWL function. To see the converse, we first note that any PWL function can be represented as a linear combination of piecewise linear convex functions. More formally, by Theorem \\ref{PWLtoRelu}, for every piecewise linear function $f: \\mathbb{R}^{d} \\rightarrow \\mathbb{R},$ there exists a finite set of affine linear functions $\\ell_{1}, \\ldots, \\ell_{m}$ and subsets $s_{1}, \\ldots, s_{M} \\subseteq\\{1, \\ldots, m\\}$ (not necessarily disjoint) where each $s_{i}$ is of cardinality at most $d+1,$ such that\n$$\nf=\\sum_{k=1}^{p} v_{k}\\left(\\max _{i \\in s_{k}} \\ell_{i}\\right)\n$$\nwhere $v_{j} \\in\\{-1,+1\\}$ for all $j=1, \\ldots, p .$ Since a function of the form $\\max _{i \\in s_{j}} \\ell_{i}$ is a piecewise linear convex function with at most $n+1$ pieces (because $\\left|s_{j}\\right| \\leq d+1$ ),   any continuous piecewise linear function (not necessarily convex) can be obtained as a linear combination of piecewise linear convex functions each of which has at most $d+1$ affine pieces. Note that $\\max \\{x, y\\}=\\frac{x+y}{2}+\\frac{|x-y|}{2}$ is implementable by a two layer ReLU network and use this construction in an inductive manner to show that maximum of $d+1$ numbers can be computed using a ReLU DNN with depth at most $\\left\\lceil\\log _{2}(d+1)\\right\\rceil$.\n\\end{proof}\n\n\nFor the relationship between ReLU DNNs and general CPWL functions, we have the next theorem with some estimation~\\cite{arora2016understanding}. \n\\begin{theorem}\\label{main0}\n\tA continuous function $f:\\mathbb{R}^d\\to\\mathbb{R}$ that are piecewise linear on $m$ subdomains $\\{\\Omega_j\\}_{j=1}^m$ can be represented by a ReLU DNN. \n\tFurthermore, \n\t\\begin{enumerate}\n\t\t\\item the number of  hidden layers  is bounded by \n\t\t\\begin{equation}\n\t\t\\label{layer}\n\t\tN_{\\rm layer}\\le \\lceil \\log_2(d+1)\\rceil.      \n\t\t\\end{equation}\n\t\t\\item the number of neurons \n\t\t\\begin{equation}\n\t\t\\label{neurons}\n\t\tN_{\\rm neuron}=\n\t\t\\left\\{\n\t\t\\begin{array}{ll}\n\t\t\\mathcal  O\\left(d2^{mM+(d+1)(m-d-1)}\\right) & \\mbox{ if } m\\ge d+1,\\\\     \n\t\t\\mathcal O\\left(d2^{mM}\\right) & \\mbox{ if } m< d+1.\n\t\t\\end{array}\n\t\t\\right.\n\t\t\\end{equation}\n\t\there $M$, satisfying $m\\le M\\le m!$, is the number of subdomains in which $f_i-f_j$ does not change sign. \n\t\\end{enumerate}\n\\end{theorem}\nCombining Theorem~\\ref{main0} with Theorem~\\ref{lowerbound}, we have the following corollary regarding the minimal number of layers needed to recover all piecewise linear functions.\n\n\\begin{corollary}\n\t\\begin{equation}\n\t2 \\le J_d \\le \\lceil\\log_2(d+1)\\rceil.\n\t\\end{equation}\n\tThis also indicates that $\\lceil\\log_2(d+1)\\rceil$ is ``optimal\" for $d=2,3$.\n\\end{corollary}\n\n\n\n\\endinput \n\n\\section{$\\lceil \\log(d+1)\\rceil$-depth dnn}\nGiven any $L>n+1$ linear functions, the maximum of these $L$ functions can be represented as the maximum of only $n+1$ linear functions. The next lemma shows that we can reduce the number of functions by one if it is larger than $n+1$. \nLet $l(x,a)=[1\\ x^T]a$.\n\\begin{lemma}\\label{reduce}\n\tFor any interger $L$ with $1\\le n< L$, $c_0\\in\\mathbb{R}$ and arbitrary linear function $l_1(x),\\dots,l_L(x)$ of $x\\in\\mathbb{R}^d$, there exist finite groups of $L-1$ linear functions, say $l(x,b_1(k))$, $\\dots$,\n\t$l(x,b_{L-1}(k))$, $1\\le k\\le K$, and corresponding $c_k\\in\\mathbb{R}$, $\\sigma_k\\in\\{1,-1\\}$ such that\n\t\n\t\\begin{equation}\\label{goal}\n\t\\max\\{c_0,l_1,\\dots,l_L\\} = \\sum_{k=1}^{K}\\sigma_k\\max\\{c_k,l(x,b_1(k)),\\dots,l(x,b_{L-1}(k))\\},\n\t\\end{equation}\n\twhere $K=2^{n+1}-1$.\n\\end{lemma}\n\n\\begin{proof}\n\t\tLet $l_i(x)=l(x,a_i)=a_{i0}+x^T\\bar{a}_i$ with $a_{i0}\\in\\mathbb{R}$ and $\\bar{a}_i\\in\\mathbb{R}^n$ for $1\\le i\\le L$. Assume there are at most $\\bar{n}$ linearly independent $\\bar{a}_i$, $\\bar{n}\\le n$. Without loss of generality, assume $\\bar{a}_1,\\dots,\\bar{a}_{\\bar{n}}$ are linearly independent. Then by basic linear algebra, we know that \n\t\t\\begin{equation}\\label{0}\n\t\tl_L=\\sum_{j=1}^{\\bar{n}}\\alpha_j l_j+\\alpha_0.\n\t\t\\end{equation}\n\t\tDenote\n\t\t$$\n\t\t\\mu(x)=\\max\\{l_{\\bar{n}+1},\\dots,l_{L-1}\\}.\n\t\t$$\n\t\tThen\n\t\t\\begin{equation}\\label{1}\n\t\t\\max\\{c_0,l_1,\\dots,l_L\\}=\\max\\{c_0,l_1,\\dots,l_{\\bar{n}},\\mu(x),l_L\\}.\n\t\t\\end{equation}\n\t\t If $\\alpha_j = 0$ in \\eqref{0} for each $1\\le j\\le \\bar{n}$, then by taking $\\max\\{c_0,\\alpha_0\\}$, we already make the RHS of (\\ref{1}) as the RHS of (\\ref{goal}). Otherwise, $\\exists \\alpha_j\\ne0$ for some $1\\le j\\le \\bar{n}$, we can assume that $\\alpha_{\\eta} \\neq 0, \\alpha_{\\eta+1}= ... = \\alpha_{\\bar{n}}=0$, so \n\t\t$$\n\t\tl_L=\\sum_{j=1}^{\\eta}\\alpha_j l_j+\\alpha_0,\\qquad \\eta\\le \\bar{n}.\n\t\t$$ \n\t\tNext we show that it can be represented by\n\t\t\\begin{equation}\\label{latticereaarange1}\n\t\t\\max\\{c_0,l_1,\\dots,l_L\\}=\\max\\{c_0,l_1',\\dots,l_{\\bar{n}}',\\mu(x),l_L'\\}\n\t\t\\end{equation}\n\t\twhere $\\displaystyle l_L'=\\alpha_\\eta l_\\eta+\\sum_{j=1}^{\\eta-1}\\alpha_jl_j'+\\alpha_0$ with $\\alpha_\\eta\\neq 1$.\n\t\t\n\t\tIf $\\alpha_i=1$ for each $1\\le i\\le\\eta$, we can do the following linear transformation $(l'_1,\\dots,l'_{\\bar{n}})^T=A(l_1,\\dots,l_{\\bar{n}})^T$, where\n\t\t\\begin{equation*}\n\t\t\\begin{aligned}\n\t\tl'_i&=l_i,\\qquad &\\mathrm{for}\\ i\\ne\\eta,\\\\\n\t\tl'_i&=\\sum_{j=1}^{\\eta} l_j+\\alpha_0,\\qquad &\\mathrm{for}\\ i=\\eta.\\\\\n\t\t\\end{aligned}\n\t\t\\end{equation*} \n\t\tThen (\\ref{1}) equals \n\t\t$$\n\t\t\\max\\{c_0,l'_1,\\dots,l'_{\\bar{n}},\\mu(x),-\\alpha_0-l'_1-\\dots-l'_{\\eta-1}+l'_{\\eta}\\}.\n\t\t$$\n\t\tin this case, \n\t\t$$\n\t\tl_L'=-\\alpha_0-l'_1-\\dots-l'_{\\eta-1}+l'_{\\eta}\n\t\t$$\n\t\tthe coefficients of $l'_1,\\dots,l'_{\\eta-1}$ are not 1. So we can rearrange $l_i'$ and assume there is at least one $\\alpha_i\\ne1$ for $1\\le i\\le\\eta$, say $\\alpha_{\\eta}\\ne1$. This leads to the representation \\eqref{latticereaarange1}. Let\n\t\t\\begin{equation*}\n\t\t\\begin{aligned}\n\t\tf&=\\max\\{c_0,\\mu(x),l_1',\\dots,l_{\\eta-1}',l_{\\eta+1}',\\dots,l_{\\bar{n}}'\\},\\\\\n\t\tg&=l_{\\eta},\\\\\n\t\th&=\\sum_{j=1}^{\\eta-1}\\alpha_j l_j'+\\alpha_0.\n\t\t\\end{aligned}\n\t\t\\end{equation*}\n\t\tBy (\\ref{key-reduce}), \n\t\t\\begin{eqnarray}\\label{2}\n\t\t\\max\\{c_0,l_1',\\dots,l_{\\bar{n}}',\\mu(x),l_L'\\}&&=\\max\\{f,g,\\alpha_{\\eta} g+h  \\}\\\\ \n\t\t\\label{3}\n\t\t&&=\\sigma_1\\max\\{f,g,\\frac{\\sum_{j=1}^{\\eta-1}\\alpha_j l_j'+\\alpha_0}{1-\\alpha_{\\eta}}  \\}\\\\ \n\t\t\\label{4}\n\t\t&&+\\sigma_2\\max\\{f,\\alpha_{\\eta} g+h,\\frac{\\sum_{j=1}^{\\eta-1}\\alpha_j l_j'+\\alpha_0}{1-\\alpha_{\\eta}}   \\}\\\\ \n\t\t\\label{5}\n\t\t&&+\\sigma_3\\max\\{f,\\bar{g} \\}.\n\t\t\\end{eqnarray}\n\t\t(\\ref{5}) is already the desired form, because now we only take maximum  over $L-1$ linear functions and one constant.\n\t\t\n\t\tAs for the (\\ref{3}), notice that now we have eliminated $l_{\\eta}$ in the third expression\n\t\t$$\n\t\t\\alpha_\\eta l_\\eta'+\\sum_{j=1}^{\\eta-1}\\alpha_j l_j'+\\alpha_0\\quad \\Rightarrow \\quad \\frac{\\sum_{j=1}^{\\eta-1}\\alpha_j l_j'+\\alpha_0}{1-\\alpha_{\\eta}}.\n\t\t$$ \n\t\tSo continue this procedure, at last we will only have constant in the last expression, by taking maximum of this constant and $c_0$, we can reduce one term in the max expression.\n\t\t\n\t\tFor (\\ref{4}), consider the linear transformation $(l''_1,\\dots,l''_{\\bar{n}})^T=B(l_1',\\dots,l_{\\bar{n}}')^T$:\n\t\t\\begin{equation*}\n\t\t\\begin{aligned}\n\t\tl''_i&=l_i',\\qquad &\\mathrm{for}\\ i\\ne\\eta,\\\\\n\t\tl''_i&=\\sum_{j=1}^{\\eta}\\alpha_{j} l_j'+\\alpha_0,\\qquad &\\mathrm{for}\\ i=\\eta.\\\\\n\t\t\\end{aligned}\n\t\t\\end{equation*}\n\t\tSo (\\ref{4}) becomes\n\t\t$$\n\t\t\\max\\{c_0,\\mu,l''_1,\\dots,l''_{\\bar{n}},\\sum_{j=1}^{\\eta-1}\\alpha_j l''_j+\\alpha_0\\}.\n\t\t$$\n\t\tThen it is the same as (\\ref{3}). Follow the same steps as for \\eqref{3}, we can achieve the desired result.\n\t\\end{proof}\n\t\n\t\\begin{figure}[ht]\n\t\t\\begin{center}\n\t\t\t\\begin{tikzpicture}[>=triangle 45,font=\\sffamily]\n\t\t\t\\node (X)  {(\\ref{2})};\n\t\t\t\\node (Y) [below left=1cm and 2cm of X]  { (\\ref{3})};% 2cm below, 1cm to the left (optional)\n\t\t\t\\node (Z) [below right=1cm and 2cm of X] {(\\ref{4})};\n\t\t\t\\node (O) [below =1 cm of X] {(\\ref{5})};\n\t\t\t\\node (U) [below left=1cm and 1.2cm of Y] { ...};\n\t\t\t\\node (V) [below right=1cm and 1.2cm of Y] {... };\n\t\t\t\\node (W) [below =1cm of Y] { };\n\t\t\t\\node (U1)[below left=1cm and 1.2cm of Z] {...};\n\t\t\t\\node (V1)[below right=1cm and 1.2cm of Z] {...};\n\t\t\t\\node (W1) [below =1cm of Z] {};\n\t\t\t\\node (T1)[below left=1cm and 0.5cm of U] { };\n\t\t\t\\node (T2)[below right=1cm and 0.5cm of U] { };\n\t\t\t\\node (T3)[ below =1cm of U] { };\n\t\t\t\\node (T4)[ below left=1cm and 0.5cm of V] { };\n\t\t\t\\node (T5)[ below right=1cm and 0.5cm of V] { };\n\t\t\t\\node (T6)[ below =1cm of V] { };\n\t\t\t\\node (T7)[below right=1cm and 0.5cm of U1] { };\n\t\t\t\\node (T8)[ below left=1cm and 0.5cm of U1] { };\n\t\t\t\\node (T9)[below =1cm of U1] { };\n\t\t\t\\node (T10)[below right=1cm and 0.5cm of V1] { };\n\t\t\t\\node (T11)[ below left=1cm and 0.5cm of V1] { };\n\t\t\t\\node (T12)[below =1cm of V1] { };\n\t\t\t\\draw [semithick,->] (X) -- (Y);\n\t\t\t\\draw [semithick,->] (X) -- (Z);\n\t\t\t\\draw [semithick,->] (X) -- (O);\n\t\t\t\\draw [semithick,->] (Y) -- (U);\n\t\t\t\\draw [semithick,->] (Y) -- (V);\n\t\t\t\\draw [semithick,->] (Y) -- (W);\n\t\t\t\\draw [semithick,->] (Z) -- (U1);\n\t\t\t\\draw [semithick,->] (Z) -- (V1);\n\t\t\t\\draw [semithick,->] (Z) -- (W1);\n\t\t\t\\draw [semithick,->] (U) -- (T1);\n\t\t\t\\draw [semithick,->] (U) -- (T2);\n\t\t\t\\draw [semithick,->] (U) -- (T3);\n\t\t\t\\draw [semithick,->] (V) -- (T4);\n\t\t\t\\draw [semithick,->] (V) -- (T5);\n\t\t\t\\draw [semithick,->] (V) -- (T6);\n\t\t\t\\draw [semithick,->] (U1) -- (T7);\n\t\t\t\\draw [semithick,->] (U1) -- (T8);\n\t\t\t\\draw [semithick,->] (U1) -- (T9);\n\t\t\t\\draw [semithick,->] (V1) -- (T10);\n\t\t\t\\draw [semithick,->] (V1) -- (T11);\n\t\t\t\\draw [semithick,->] (V1) -- (T12);\n\t\t\t\\end{tikzpicture}\n\t\t\t\\caption{The process of reducing one term.}\n\t\t\\end{center}\n\t\t\\label{fig:Redu}\n\t\\end{figure}\n\t\n\t\\begin{remark}\n\t\t\\label{timesestimate}\n\t\tWhenever we eliminate one $l_i$ in the expression of $l_L$, we will gain 3 terms, which is (\\ref{3}-\\ref{5}). Among these three terms, (\\ref{5}) is in desired form, and we need to continue to use (\\ref{key-reduce}) for (\\ref{3}) and (\\ref{4}) until we only have constant. Note that in the proof, $\\eta\\le n$.  By this procedure, we will gain at most $2^{n+1}-1$ terms (see Figure~\\ref{fig:Redu}). \n\t\\end{remark}", "meta": {"hexsha": "c79f39ad129ff8de397c224bd30a9eb2780510a5", "size": 19378, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/lattice.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/lattice.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/lattice.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.5149051491, "max_line_length": 692, "alphanum_fraction": 0.6561564661, "num_tokens": 7384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711718571775, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7258012185502247}}
{"text": "\n\\subsection{SUVAT}\n\n\\subsubsection{Introduction}\n\nFor a constant acceleration environment we want to find equations to link:\n\\begin{itemize}\n\\item Initial speed: \\(v_{t_0}\\)\n\\item End speed: \\(v_{t_1}\\)\n\\item Time: \\(t_1-t_0\\)\n\\item Acceleration: \\(a\\)\n\\item Displacement \\(s_{t_1}-s_{t_0}\\)\n\\end{itemize}\n\n\\subsubsection{The SUVAT equations}\n\nThese are the following, and are derived below.\n\n\\begin{itemize}\n\\item \\(v_{t_1}=a(t_1-t_0)+v_{t_0}\\)\n\\item \\((s_{t_1}-s_{t_0})=v_{t_0}(t_1-t_0)+\\dfrac{1}{2}a(t_1-t_0)^2\\)\n\\item \\((s_{t_1}-s_{t_0})=v_{t_1}(t_1-t_0)-\\dfrac{1}{2}a(t_1-t_0)^2\\)\n\\item \\(v_{t_1}^2= v_{t_0}^2+2a(s_{t_1}-s_{t_0})\\)\n\\item \\((s_{t_1}-s_{t_0})=(t_1-t_0)\\dfrac{v_{t_1}+v_{t_1}}{2}\\)\n\\end{itemize}\n\n\\subsubsection{Equation 1: No displacement}\n\nThis equation is:\n\n\\(v_{t_1}=a(t_1-t_0)+v_{t_0}\\)\n\nTo derive this start with:\n\n\\(v_t:=\\dfrac{\\delta s_t}{\\delta t}\\)\n\n\\(a:=\\dfrac{\\delta v_t}{\\delta t}\\)\n\nIf acceleration is constant, then \n\n\\(\\dfrac{\\delta v_t}{\\delta t}=a\\)\n\n\\(v_t=\\int a dt +v_0\\)\n\n\\(v_t=at+v_0\\)\n\\subsubsection{Equation 2: No end velocity}\n\nThis equation is:\n\n\\((s_{t_1}-s_{t_0})=v_{t_0}(t_1-t_0)+\\dfrac{1}{2}a(t_1-t_0)^2\\)\n\nTo derive this start with:\n\n\\(v:=\\dfrac{\\delta s_t}{\\delta t}\\)\n\nThen:\n\n\\(\\dfrac{\\delta s_t}{\\delta t}=at+v_0\\)\n\n\\(s_t=\\dfrac{1}{2}at^2+v_0t+s_0\\)\n\n\\((s_t-s_0)=v_0t+\\dfrac{1}{2}at^2 \\)\n\n\\subsubsection{Equation 3: No start velocity}\n\nThis equation is:\n\n\\((s_{t_1}-s_{t_0})=v_{t_1}(t_1-t_0)-\\dfrac{1}{2}a(t_1-t_0)^2\\)\n\nTo derive this start with:\n\n\\(v_t=at+v_0\\)\n\n\\((s_t-s_0)=t\\dfrac{v_t+v_0}{2}\\)\n\nSo:\n\n\\(v_0=v_t-at\\)\n\n\\(v_0=\\dfrac{2}{t}(s_t-s_0)- v_t\\)\n\n\\(v_t-at=\\dfrac{2}{t}(s_t-s_0)- v_t\\)\n\n\\((s_t-s_0)=v_tt-\\dfrac{1}{2}at^2\\)\n\n\\subsubsection{Equation 4: No time}\n\nThis equation is:\n\n\\(v_{t_1}^2= v_{t_0}^2+2a(s_{t_1}-s_{t_0})\\)\n\nTo derive this start with:\n\n\\(v_t=at+v_0\\)\n\n\\((s_t-s_0)=t\\dfrac{v_t+v_0}{2}\\)\n\nSo:\n\n\\(t=\\dfrac{v_t-v_0}{a}\\)\n\n\\(t=2\\dfrac{s_t-s_0}{v_t+v_0}\\)\n\n\\(\\dfrac{v_t-v_0}{a}=2\\dfrac{s_t-s_0}{v_t+v_0}\\)\n\n\\((v_t-v_0)(v_t+v_0)=2a(s_t-s_0)\\)\n\n\\(v^2_t= v^2_0+2a(s_t-s_0)\\)\n\\subsubsection{Equation 5: No acceleration}\n\nThis equation is:\n\n\\((s_{t_1}-s_{t_0})=(t_1-t_0)\\dfrac{v_{t_1}+v_{t_1}}{2}\\)\n\nTo derive this start with:\n\n\\(v_t=at+v_0\\)\n\n\\(s_t-s_0=\\dfrac{1}{2}at^2+v_0t\\)\n\nSo:\n\n\\(a=\\dfrac{v_t-v_0}{t}\\)\n\n\\(a=\\dfrac{2[(s_t-s_0)-v_0t]}{t^2}\\)\n\n\\(\\dfrac{v_t-v_0}{t}=\\dfrac{2[(s_t-s_0)-v_0t]}{t^2}\\)\n\n\\(t(v_t-v_0)=2[(s_t-s_0)-v_0t]\\)\n\n\\(t(v_t+v_0)=2(s_t-s_0)\\)\n\n\\((s_t-s_0)=t\\dfrac{v_t+v_0}{2}\\)\n\n", "meta": {"hexsha": "922fd0e1b3a5a80fbc0590488991a5def7c7a7da", "size": 2468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/physics/newton/01-01-suvat.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/physics/newton/01-01-suvat.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/physics/newton/01-01-suvat.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.2814814815, "max_line_length": 74, "alphanum_fraction": 0.6203403566, "num_tokens": 1227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7258012122729549}}
{"text": "\\documentclass[12pt]{article}\n\n\\title{Important theorems}\n\\author{Abel Doñate}\n\\date{}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{hyperref}\n\\usepackage{graphicx}\n\\graphicspath{ {./images/} }\n\\usepackage{wrapfig}\n\n\\setcounter{page}{0}\n\n%Geometry\n\\usepackage{geometry}\n\\geometry{a4paper, margin=1in}\n\n\n\n\\begin{document}\n\n\\maketitle\n\\tableofcontents\n\\newpage\n\n\\section{Fermat's little theorem}\nIf $a$ and $p$ are coprimes, then:\n\\[a^{p-1}\\equiv 1 \\ (mod \\ p)\\]\n\\\\\n\\textbf{Proof}\\\\\nConsider the set $S=\\{ a, 2a, \\cdots, (p-1)a\\}$.\\\\\nNow we pick 2 elements of the set, for instance $ka, la$, with $1\\leq k<l\\leq p-1$. We are going to show that necessarily $ka \\not\\equiv la\\ (mod \\ p)$. Let's prove it by contradiction:\\\\\n\\\\\nIf we suppose that it is true, then:\n\\[ka \\equiv la\\ (mod \\ p) \\ \\ \\implies p|(l-k)a \\ \\ \\implies \\begin{cases}\np|a \\ \\ \\ \\text{(impossible, they are coprimes)} \\\\\n\\text{or} \\\\\np|(l-k) \\ \\ \\ \\text{(impossible, it is positive and less than $p$)}\n\\end{cases} \\]\nSo, it is proven by contradiction.\\\\\nThus, the residues of the elements of $S$ must be different from each other, so the set of the elements of $S$ in modulo $p$ is $S_p=\\{1, 2, \\cdots, p-1\\}$, as it has to have the same number of elements that $S$ (the set does not has to be necessarily in order from $S$).\\\\\n\nNow we multiply the elements of $S$ and the elements of $S_p$. If we consider the residues modulo $p$ of the results, they must be the same, because each element of $S_p$ is the residue of one element of $S$. Then:\n\\[a\\cdot 2a \\cdots (p-1)a = 1\\cdot 2 \\cdots (p-1) \\ (mod \\ p) \\implies a^{p-1}(p-1)! = (p-1)! \\ (mod \\ p)  \\]\nTrivially $(p-1)!$ is coprime with p (they do not share any factor), so we can divide the expression by $(p-1)!$. As desired we end up with\n\\[a^{p-1}\\equiv 1 \\ (mod \\ p)\\]\n\\qed\n\n\\newpage\n\n\\section{Wilson's theorem}\nLet $p$ any prime. Then it holds:\n\\[(p-1)!\\equiv -1 \\ (mod \\ p)\\]\n\\\\\n\\textbf{Proof} \\\\\nFirst we are going to proof two Lemmas.\\\\ \\\\\n\\textbf{Lemma 1.} If $a^2\\equiv 1 \\ (mod \\ p)$, then $a \\equiv 1 \\ (mod \\ p)$ or $a \\equiv 1 \\ (mod \\ p)$. \\\\\nThe proof of this lemma is following:\n\\[a^2\\equiv 1 \\ (mod \\ p) \\implies p|a^2-1 \\implies p|(a+1)(a-1) \\implies \\begin{cases}\np|(a+1) \\\\\n\\text{or} \\\\\np|(a-1) \n\\end{cases}\\]\nso, a must be $1$ or $-1$ in modulo $p$. \\\\\n\\\\\n\\textbf{Lemma 2.} Every number between $2$ and $p-2$ has a unique inverse that is not itself.\\\\\nThe proof is very simple. Using \\textit{Lemma 1}, the only numbers that could be its own inverse are $1$ and $-1$. We know that, as every element must have an inverse ($\\mathbf{Z_p}$ is a group), the inverse of the remaining elements must be different from themselves.\\\\\n\\\\\nNow we are ready for the proof. If we take $(p-1)!$, we can split it in this way\n\\[(p-1)!=1\\cdot (2\\cdot 3 \\cdots (p-3) \\cdot (p-2))\\cdot (p-1)\\]\nObserve that in the middle remains the numbers between $2$ and $p-2$. Using \\textit{Lemma 2} we can pair the elements in pairs formed by one element and its inverse (that is not itself) so that the product is $1 \\ (mod \\ p)$. Finally multiplying by $1$ and $(p-1)$ gives us \\[(p-1)!\\equiv -1 \\ (mod \\ p)\\] as desired. \\\\\n\\qed\n\n\n\n\\end{document}\n", "meta": {"hexsha": "9c79cbcf93f6d1057d1d69b5cd90300a7a1894ab", "size": 3186, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Cuatri 1A/Foundations/Theorems.tex", "max_stars_repo_name": "abeldm3108/Apuntes", "max_stars_repo_head_hexsha": "2bd5ef414fbb671f8e232d646e6ef671d773288c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Cuatri 1A/Foundations/Theorems.tex", "max_issues_repo_name": "abeldm3108/Apuntes", "max_issues_repo_head_hexsha": "2bd5ef414fbb671f8e232d646e6ef671d773288c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Cuatri 1A/Foundations/Theorems.tex", "max_forks_repo_name": "abeldm3108/Apuntes", "max_forks_repo_head_hexsha": "2bd5ef414fbb671f8e232d646e6ef671d773288c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.825, "max_line_length": 320, "alphanum_fraction": 0.6563088512, "num_tokens": 1134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324983301568, "lm_q2_score": 0.8902942319436397, "lm_q1q2_score": 0.7257967909563414}}
{"text": "\\section{Conclusion and future work}\n\nWe introduced a mathematical framework to design neural networks for data that live on simplicial complexes and provided preliminary results on their ability to impute missing data.\nFuture work might include:\n(i) comparing SNNs with state-of-the-art imputation algorithms,\n(ii) using SNNs to solve vector field problems,\n(iii) generalizing coarsening and pooling to simplicial complexes,\n(iv) using boundaries and coboundaries to mix data structured by relationships of different dimensions,\nand (v) studying the expressive power of SNNs.\n% Their expressive power remains to be fully understood on non-homogeneous spaces.\n\nUnrelated to the simplicial nature of this work, we would like to emphasize how the spectral language was key to developing and even formulating our method.\n% Fourier analysis was developed to exploit symmetries in solving PDEs, and later used for data analysis and processing.\nOn homogeneous spaces, convolutions are defined as inner-products with filters shifted by the actions of a symmetry group of the space.\nThey are the most general shift-invariant linear operators.\n% Convolutions are a sufficient and necessary condition for shift-invariance~\\cite{kondor2018groupnn}\nOn non-homogeneous spaces however, the spectral language yields generalized convolutions which are inner-products with \\emph{localized} filters~\\cite[Sec.~2.4]{perraudin2019deepsphere}. %~\\cite[Sec.~2.2]{perraudin2017stationarity}.\nThose too are invariant to any symmetry the space might have.\n% generality of spaces: homogeneous ⊂ global symmetries ⊂ some automorphisms (local symmetries) ⊂ asymmetric\n% (homogeneous == any point is moved to any other by an automorphism)\nConvolutions exploit the space's structure to reduce learning complexity by sharing learnable weights through shifts and localizations of filters.\n", "meta": {"hexsha": "dd0393864f14cd6e993e7ffdc6235bfa5256a8c7", "size": 1857, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "discussion.tex", "max_stars_repo_name": "stefaniaebli/paper-snn-neurips2020tda", "max_stars_repo_head_hexsha": "935658c9fa93897b4e288918e6e9c3fb0a0bee3e", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-01-06T18:45:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T05:09:20.000Z", "max_issues_repo_path": "discussion.tex", "max_issues_repo_name": "stefaniaebli/paper-snn-neurips2020tda", "max_issues_repo_head_hexsha": "935658c9fa93897b4e288918e6e9c3fb0a0bee3e", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "discussion.tex", "max_forks_repo_name": "stefaniaebli/paper-snn-neurips2020tda", "max_forks_repo_head_hexsha": "935658c9fa93897b4e288918e6e9c3fb0a0bee3e", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.4090909091, "max_line_length": 231, "alphanum_fraction": 0.8185245019, "num_tokens": 405, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7257365028272559}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\begin{document}\n\n\\section{Stochastic Process}\nA stochastic process is of the form\n\\begin{align}\nX_{T+1}-X_{T} = \\theta(T) X_{T} +f(t) +r_{T} \\sigma(T),\n\\end{align}\nwhere $r_T$ is a random variable drawn from the distribution $P(r,\\vec{\\lambda})$, where $\\vec{\\lambda}$ are the parameters that describe the distribution.\n\n\n\\begin{align}\nP(X_T) &=  \\int dX_{T-\\Delta T}  \\int dr_T \\ P(X_T,X_{T-\\Delta T},r), \\\\\n &=  \\int dX_{T-\\Delta T}  \\int dr_T \\ P(X_T|X_{T-\\Delta T},r)P(X_{T-\\Delta T},r_T),\n\\end{align}\nassuming that $X_{T-\\Delta T}$ is independent of the random variable $r_T$, then this expression becomes\n\\begin{align}\nP(X_T) &= \\int dX_{T-\\Delta T}  \\int dr_T \\ P(X_T|X_{T-\\Delta T},r_T)P(X_{T-\\Delta T})P(r_T) .\n\\end{align}\nNext, we apply the constraint where \n\\begin{align}\nr_{T} = \\frac{X_{T+1}-X_T -\\theta(T) X_{T}-f(T) }{\\sigma(T)},\n\\end{align}\nthis constraint is enforced through the function \n\\begin{align}\nP(X_T|X_{T-\\Delta T},r_T) = \\delta\\left(r_{T} -\\frac{X_{T}-X_{T-1} -\\theta(T-\\Delta T) X_{T-\\Delta T}-f(T) }{\\sigma(T-\\Delta T)} \\right).\n\\end{align}\nCarrying out the integral over $r_T$ results in\n\\begin{align}\nP(X_T)  &=  \\int dX_{T-\\Delta T} P(X_{T-\\Delta T})P\\left(r_T = \\frac{X_{T}-X_{T-1} -\\theta(T-\\Delta T) X_{T-\\Delta T}-f(T-\\Delta T) }{\\sigma(T-\\Delta T)}\\right),\n\\end{align}\nthis last expression relates the probability distribution of the current value $X_T$ to the value at a time infinitesimally in the past. Carrying out this expression recursively we obtain\n\\begin{align}\nP(X_T)  &=  \\int dX_{T-\\Delta T}  \\ P\\left(\\frac{X_{T}-X_{T-\\Delta T}-f(T-\\Delta T) -\\theta(T-\\Delta T) X_{T-\\Delta T} }{\\sigma(T-\\Delta T)}\\right)  \\notag\\\\\n& \\cdots \\int dX_{0} \\ P\\left(\\frac{X_{1}-X_{0}-f(T_0) -\\theta(T_0) X_{0} }{\\sigma(T_0)}\\right)\\delta(X_0 -x_0),\n\\end{align}\nwhere $x_0$ is the position at the initial point $T_0$.\\\\\n\n\n\\section{Gaussian Noise}\nNow we have the general forms of the stochastic integrals that we want to work with\n\n\n\\subsection{Fokker-Plank Equation}\n\n\\subsection{Path integrals}\nThis probability can also be expressed as a path integral of the form\n\\begin{align}\nP(X_T)  &=  \\int \\mathcal{D}X \\ \\text{Exp}\\left(\\int\\limits_{T_0}^T S(\\dot{X},X,t)  dt \\right),\n\\end{align}\nwhere the action is\n\\begin{align}\nS(\\dot{X},X,t) &= -\\frac{1}{2\\sigma^{2}(t)}\\left( \\dot{X}(t)-f(t)-\\theta(t) X(t) \\right)^2\n\\end{align}\n\n\n\\end{document}", "meta": {"hexsha": "80d89950db2b99ae53f426a8f80de30710999176", "size": 2503, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/path_int.tex", "max_stars_repo_name": "OscarJHernandez/OscarJHernandez.github.io", "max_stars_repo_head_hexsha": "ffa646da5ab91bad2d06aadac91b2f55d2deacd2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/path_int.tex", "max_issues_repo_name": "OscarJHernandez/OscarJHernandez.github.io", "max_issues_repo_head_hexsha": "ffa646da5ab91bad2d06aadac91b2f55d2deacd2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-05-19T13:40:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T04:11:04.000Z", "max_forks_repo_path": "notes/path_int.tex", "max_forks_repo_name": "OscarJHernandez/OscarJHernandez.github.io", "max_forks_repo_head_hexsha": "ffa646da5ab91bad2d06aadac91b2f55d2deacd2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.0327868852, "max_line_length": 187, "alphanum_fraction": 0.6727926488, "num_tokens": 934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.725736498183774}}
{"text": "\\subsection{Linearity}\r\n\\noindent\r\nAnother useful way to classify differential equations is by linearity.\r\n\\begin{definition}\r\n\tA differential equation is linear if all terms in the equation involving the dependent variables and its derivatives are in linear terms.\r\n\\end{definition}\r\n\\noindent\r\n``Linear terms'' means that dependent variables should all be of degree 1, not be multiplied by a derivative involving the same variable, and not be in other functions like $\\sin$ or $\\ln$.\r\nHowever, this does not exclude differential equations from having parts that are functions of only independent variables, like in equation 4.\\\\\r\n\r\n\\noindent\r\nBelow is a table of linearity and equation numbers.\r\n\\begin{table}[H]\r\n\t\\centering\r\n\t\\begin{tabular}{c|c}\r\n\t\tLinearity & Equation Number \\\\\r\n\t\t\\hline\r\n\t\tLinear &  2, 3, 4, 5, 8, 9 \\\\\r\n\t\tNonlinear & 1, 6, 7, 10 \\\\\r\n\t\\end{tabular}\r\n\\end{table}\r\n\\noindent\r\nWe'll focus a lot of time on linear equations because we have some mathematical tools that are good at dealing with them.", "meta": {"hexsha": "e5d55262b7d261054a5771ff590a152969ab0b73", "size": 1020, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/basics/classification/linearity.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/basics/classification/linearity.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/basics/classification/linearity.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 44.347826087, "max_line_length": 190, "alphanum_fraction": 0.7480392157, "num_tokens": 263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7257341832755171}}
{"text": "\\documentclass[a4paper,12pt]{scrartcl}\n\n% font packages\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\n% packages for mathematical type setting\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{bbm}\n\n% packge for norm command\n\\usepackage{physics}\n\n% references\n\\usepackage{cleveref}\n\n\\author{\\normalsize Linus Böhm, Jurek Rostalsky}\n\\title{Benign Overfitting}\n\\date{}\n\n% formatting\n\\setlength{\\parindent}{0pt}\n\\pagestyle{empty}\n\n% definition\n\\theoremstyle{definition}\n\\newtheorem{definition}{Definition}[section]\n\n\n\\begin{document}\n\\maketitle\n\\section{Basic definitions} \\label{sec:basic_definitions}\nLet \\(x \\in \\mathbb{H}, y \\in \\mathbb{R}\\) with zero mean. Where \\(\\mathbb{H}\\) is a Hilbert space.\n\n\\begin{definition} [covariance matrix]\n\t\\label{def:covarianvce_matrix}\n\t\\begin{equation}\n\t\t\\Sigma = \\mathbb{E}\\left(\\left(x - \\mathbb{E}(x)\\right)\\left(x - \\mathbb{E}(x)\\right)^T\\right) =  \\mathbb{E}(xx^T)\n\t\\end{equation} \n\\end{definition}\n\n\\begin{definition} [linear regression]\n\t\\label{def:linear_regression}\n\tThe problem of finding a parameter vector \\(\\theta^\\ast \\in \\mathbb{H}\\) with\n\t\\begin{equation}\n\t\t\\theta^\\ast = arg \\min\\limits_\\theta \\mathbb{E}\\left((y - x^T \\theta)^2\\right)\n\t\\end{equation}\n\tis called \\textbf{linear regression}.\n\\end{definition}\n\nLet \\(\\left((x_1, y_1), ..., (x_n, y_n)\\right) \\in (\\mathbb{H} \\times \\mathbb{R})^n\\) a list of \\(n\\) sampled data points. Now we define the matrix \\(X = \\big(x_1 \\, x_2 \\, ... \\, x_n\\big)\\) and the vector \\(y = (y_1 \\, y_2 \\, ... \\, y_n)^T\\). If there is a \\(\\theta \\in \\mathbb{H}\\) with \\(y - X^T \\theta = 0\\) that \\(\\theta\\) is a minimum of the linear regression problem sind the expectation of a square is non negative. Usually such a \\(\\theta\\) isn't unique, so we are interested in the minimum norm \\(\\theta\\) with that property.\n\n\\begin{definition}[minimum norm estimator]\n\tFor given samples \\(X \\in \\mathbb{H}^n, y \\in \\mathbb{R}^n\\). The \\textbf{minimum norm estimator} \\(\\theta\\) is the solution of the QQP:\n\t\t\\begin{align*}\n\t\t\t\\label{eq:QQP}\n\t\t\t\\hat{\\theta} = arg \\min\\limits_{\\theta} &\\norm{\\theta}^2 & \\text{subject to: } \\norm{X^T \\theta - y}^2 = \\min\\limits_\\beta \\norm{X^T \\beta - y}^2 && \\text{(QQP)}\\\\\n\t\t\\end{align*}\t\t\n\\end{definition}\n\nThe minimum norm estimator can be obtained by solving the normal equation:\n\\begin{equation}\n\\label{eq:normal_equation}\n\tXX^T \\theta = X y,\n\\end{equation}\nwhich can be done by numerical stable with QR-decomposition.\n\n\\newpage\n\n\\begin{definition} [Excess risk] \n\t\\label{def:Excess risk}\\ \\\\\n\t\n\t$\\mathbb{E}_{x,y}$ denotes the conditional expectation , then define: \n\t\n\t\\begin{equation}\n\tR:= \\mathbb{E}_{x,y}[(y - x^T\\theta)^2 - (y - x^T\\theta^*)^2]\n\t\\end{equation} \n\\end{definition}\n\n\n\\begin{definition} [Effective Ranks] \n\t\\label{def:Effective Ranks}\\ \\\\\n\t\n\tFor the covariance operator $\\sum$, define $\\lambda_i = \\mu_i(\\sum)$ for $i = 1,2,...$ . Whereby \\newline $\\mu_1(\\sum) \\geq \\mu_1(\\sum) \\geq ...$ . If $\\sum\\limits_{i=1}^\\infty \\lambda_i < \\infty$ and $\\lambda_{k+1} > 0$ for $k \\geq 0,$ define: \n\t\n\t\\begin{equation}\n\tr_k(\\sum) = \\frac{\\sum_{i>k}\\lambda_i}{\\lambda_{k+1}} ,\\hspace*{2cm}\n    R_k(\\sum) = \\frac{(\\sum_{i>k}\\lambda_i)^2}{R_k(\\sum_{i>k})\\lambda_i^2}\n\t\\end{equation} \n\\end{definition}\n\n\\newpage\n\\section{Theorems} \\label{sec:Theorems}\n\n\\newtheorem{thm}{Theorem}\n\n\\begin{thm}\\ \\\\\n\tFor any $\\sigma_x$ there are $b,c,c_1 > 1$, for which the following holds. Consider a linear regression problem from definition~\\ref{def:linear_regression}. Define:\n\\begin{equation}\n\\begin{aligned}\nk^* = \\min \\{k \\geq 0: r_k(\\sum) \\leq bn\\},\n\\end{aligned}\n\\end{equation}\n\nWhere the minimum of the empty set is defined as $\\infty$. Suppose $\\delta < 1$ with $\\log(\\frac{1}{\\delta}) < n/c$. If $k^* \\leq n/c_1$, then $\\mathbb{E}R(\\hat{\\theta}) \\leq \\delta^2/c.$ Otherwise,\n\n\\begin{equation}\n\\begin{aligned}\nR(\\hat{\\theta}) \\leq c(\\norm{\\theta^*}^2\\norm{\\sum}\\max{\\sqrt{\\frac{r_0(\\sum)}{n}},\\frac{r_0(\\sum)}{n},\\sqrt{\\frac{\\log(1/\\delta)}{n}}}) + c\\log(\\frac{1}{\\delta})\\sigma_y^2\\left(\\frac{k^*}{n} + \\frac{n}{R_{k^*(\\sum)}}\\right)\\\\\n\\end{aligned}\n\\end{equation}\n\nwith probability at least $1 - \\delta$, and \n\n\\begin{equation}\n\\begin{aligned}\n\\mathbb{E}R(\\hat{\\theta}) \\geq \\frac{\\sigma^2}{c} \\left(\\frac{k^*}{n} + \\frac{n}{R_{k^*(\\sum)}}\\right) \n\\end{aligned}\n\\end{equation}\nMoreover there are universal constants $a_1.a_2,n_0$ such that $\\forall n \\geq n_0, \\forall \\sum, \\forall t \\geq 0$ there is a $\\theta^*$ with $\\norm{\\theta^*} = t$ such that for $x \\sim N(0,\\sum)$ and $y|x \\sim N(x^T\\theta^*,\\norm{\\theta^*}^2\\norm{\\sum})$, with probability at least $1/4$,\n\n\\begin{equation}\n\\begin{aligned}\nR(\\hat{\\theta})\\geq \\frac{1}{a_1}\\norm{\\theta^*}^2\\norm{\\sum}\\mathbbm{1}_{\\left[\\frac{r_0(\\sum)}{n\\log(1+r_0(\\sum))} \\geq a_2\\right]}\n\\end{aligned}\n\\end{equation}\n \n\\end{thm}\n\n\n\\begin{thm}\\ \\\\\nThe excess risk of the minimum norm estimator satisfies:\n\\begin{equation}\n\\begin{aligned}\nR(\\hat{\\theta)}) & \\leq 2(\\theta^*)^TB\\theta^* + c\\delta^2\\log(\\frac{1}{\\delta})tr(C) \\text{ and} \\\\\n\\mathbb{E}_\\epsilon R(\\hat{\\theta}) & \\geq (\\theta^*)^TB\\theta* + \\delta^2tr(C) \\text{ where}\\\\\\\\\nB & = (I - X^T(XX^T)^{-1}X)\\sum(I - X^T(XX^T)^{-1}X),  \\\\\nC & = (XX^T)^{-1}X\\sum X^T(XX^T)^{-1}\n\\end{aligned}\n\\end{equation} \n\n\\end{thm}\n\n\\end{document}\n", "meta": {"hexsha": "ab69aeba74fb86fea1da32f9d74805508dbd07e2", "size": 5280, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "script/BenignOverfitting.tex", "max_stars_repo_name": "Mathemalsky/BenignOverfitting", "max_stars_repo_head_hexsha": "f3bd4f5d9455f4402440bd5abbc813c152aa866b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "script/BenignOverfitting.tex", "max_issues_repo_name": "Mathemalsky/BenignOverfitting", "max_issues_repo_head_hexsha": "f3bd4f5d9455f4402440bd5abbc813c152aa866b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "script/BenignOverfitting.tex", "max_forks_repo_name": "Mathemalsky/BenignOverfitting", "max_forks_repo_head_hexsha": "f3bd4f5d9455f4402440bd5abbc813c152aa866b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.9183673469, "max_line_length": 535, "alphanum_fraction": 0.6589015152, "num_tokens": 1986, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198946, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.725734181887157}}
{"text": "\\chapter{Formulae}\n\n{\\color{red} This chapter may be not required}\n\nPlane wave basis $b_{\\alpha}(\\mathbf{r})$:\n\\begin{equation}\nb_{\\alpha}(\\mathbf{r}) = \\frac{1}{\\sqrt{\\Omega}} e^{\\mathbf{G}_{\\alpha}\\cdot\\mathbf{r}}\n\\end{equation}\n\nLattice vectors of unit cell in reciprocal space:\n\\begin{equation}\\label{eq:recvecs}\n\\mathbf{b} = 2\\pi\\left( a^{T} \\right)^{-1}\n\\end{equation}\n\n\\textbf{G}-vectors:\n\\begin{equation}\n\\mathbf{G} = i \\mathbf{b}_{1} + j \\mathbf{b}_{2} + k \\mathbf{b}_{3}\n\\end{equation}\n\nStructure factor:\n\\begin{equation}\nS_{I}(\\mathbf{G}) = \\sum_{\\mathbf{G}} e^{ -\\mathbf{G}\\cdot\\mathbf{X}_{I} }\n\\end{equation}\n", "meta": {"hexsha": "5669d7584954fd30602841552d092d9f453a7213", "size": 622, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PW/Doc/formulae.tex", "max_stars_repo_name": "f-fathurrahman/ffr-ElectronicStructure.jl", "max_stars_repo_head_hexsha": "35dca9831bfc6a3e49bb0f3a5872558ffce4b211", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-01-03T02:19:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-29T13:30:20.000Z", "max_issues_repo_path": "PW/Doc/formulae.tex", "max_issues_repo_name": "f-fathurrahman/ffr-ElectronicStructure.jl", "max_issues_repo_head_hexsha": "35dca9831bfc6a3e49bb0f3a5872558ffce4b211", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PW/Doc/formulae.tex", "max_forks_repo_name": "f-fathurrahman/ffr-ElectronicStructure.jl", "max_forks_repo_head_hexsha": "35dca9831bfc6a3e49bb0f3a5872558ffce4b211", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-03-23T06:58:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-03T00:54:28.000Z", "avg_line_length": 25.9166666667, "max_line_length": 87, "alphanum_fraction": 0.6623794212, "num_tokens": 251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109713976399, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.7256233555954115}}
{"text": "%Some d^i and s^i fixed to d_i and s_i.\n%Rhetorical questions are okay in spoken lectures but I think they should be used more sparingly in text.\n\n\\section{Simplices, more about homology}\nPreviously we introduced the standard $n$-simplex $\\Delta^n\\subseteq\\mathbf{R}^{n+1}$. Singular simplices in a space $X$ are maps $\\sigma\\colon\\Delta^n\\to X$ and constitute the set $\\Sin_n(X)$. For example, $\\Sin_0(X)$ consists of points of $X$. In addition to the \\emph{face maps} $d_i\\colon\\Sin_n(X)\\to\\Sin_{n-1}(X)$ we described, there are also \\emph{degeneracy maps} $s_i\\colon\\Sin_n(X)\\to\\Sin_{n+1}(X)$, and the collection $\\{\\Sin_n(X),d_i,s_i\\}$ forms a \\emph{simplicial set}. Simplicial sets are combinatorial models for topological spaces. In the language of category theory, which we will discuss shortly, we have a functor $\\mathbf{Top}\\to\\{\\text{simplicial sets}\\}$.\n\nTo the semi-simplicial set $\\{\\Sin_n(X),d_i\\}$ we then applied the free abelian group functor, obtaining a semi-simplicial abelian group. Using the $d_i$s, we constructed a boundary map $\\partial$ which makes $S_\\ast(X)$ a \\emph{chain complex} because $\\partial^2=0$ (see Exercise \\ref{exer:simplicialidentities}). We capture this process in a diagram:\n\\begin{equation*}\n\\xymatrix{\\mathbf{Top}\\ar[d]\\ar[r] & \\{\\text{semi-simplicial sets}\\}\\ar[r] & \\{\\text{semi-simplicial abelian groups}\\}\\ar[d]\\\\\n    \\{\\text{simplicial sets}\\}\\ar[ur] & & \\{\\text{chain complexes}\\}\\ar[d]^{\\text{take homology}}\\\\\n & &\\{\\text{graded abelian group}\\}}\n\\end{equation*}\nGiven a chain complex $\\partial\\colon A_n\\to A_{n-1}$, one can define its homology $H_n(A,\\partial)=\\ker\\partial_n/\\img\\partial_n$.\n\nHere's an example. Suppose we have $\\sigma\\colon \\Delta^1\\to X$. Define $\\phi\\colon\\Delta^1\\to\\Delta^1$ which sends $(t,1-t)\\mapsto (1-t,t)$. Precomposing $\\sigma$ with $\\phi$ gives another singular simplex $\\overline{\\sigma}$ which reverses the orientation of $\\sigma$. It is \\textit{not} true that $\\overline{\\sigma}=-\\sigma$ in $S_1(X)$.\n\nHowever, we show that $\\overline{\\sigma}\\equiv -\\sigma\\bmod B_1(X)$, meaning there is a $2$-chain in $X$ whose boundary is $\\overline{\\sigma}+\\sigma$. If $d_0\\sigma=d_1\\sigma$ so that $\\sigma\\in Z_1(X)$, then $\\overline{\\sigma}$ and $-\\sigma$ are homologous: $[\\overline{\\sigma}]=-[\\sigma]$ in $ H_1(X)$.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.6\\linewidth]{assets/L02/02-pi-then-sigma}\n\t\\caption{If $\\sigma$ is a 1-simplex in $X$, then precomposing by $\\pi$ gives a 2-simplex $\\sigma \\circ \\pi$ in $X$.}\n\t\\label{fig:02-pi-then-sigma}\n\\end{figure}\n\nLet $c^n_{x}$ denote the constant $n$-simplex at $x$. Consider the 2-simplex in Figure \\ref{fig:02-pi-then-sigma}. Its boundary is $\\partial(\\sigma\\circ\\pi)=\\sigma\\pi d^0-\\sigma\\pi d^1 +\\sigma\\pi d^2=\\overline{\\sigma}-c^1_{\\sigma(0)}+\\sigma$. To compensate for the unwanted $-c^1_{\\sigma(0)}$ term, consider the constant $2$-simplex $c^2_{\\sigma(0)}$; its boundary is $c^1_{\\sigma(0)}-c^1_{\\sigma(0)}+c^1_{\\sigma(0)}=c^1_{\\sigma(0)}$. So $\\overline{\\sigma}+\\sigma=\\partial(\\sigma\\circ\\pi + c^2_{\\sigma(0)})$ and $\\overline{\\sigma}\\equiv -\\sigma\\bmod B_1(X)$ as claimed.\n\nTo give the simplest explicit examples, let's compute the homologies of $\\emptyset$ and $\\ast$. For the former, $\\Sin_n(\\emptyset)=\\emptyset$, so $S_\\ast(\\emptyset)=0$. Hence $\\cdots\\to S_2\\to S_1\\to S_0$ is the zero chain complex. This means that $Z_\\ast(\\emptyset)=B_\\ast(\\emptyset)=0$. The homology in all dimensions is therefore $0$.\n\nFor $\\ast$, we have $\\Sin_n(\\ast)=\\{c^n_\\ast\\}$ for all $n\\geq 0$. Consequently $S_n(\\ast)=\\mathbf{Z}$. The boundary maps $\\partial\\colon S_n(\\ast)\\to S_{n-1}(\\ast)$ in the chain complex depend on the parity of $n$ as follows:\n\\[\\partial(c^n_\\ast)=\\sum_{i=0}^{n}(-1)^i c^{n-1}_\\ast=\n\\begin{cases}\n    c^{n-1}_* & \\text{for } n \\text{ even, and}\\\\\n    0 & \\text{for } n \\text{ odd.}\n  \\end{cases}\n\\]\nThis means that our chain complex is:\n$$\\cdots\\to\\mathbf{Z}\\xrightarrow{0}\\mathbf{Z}\\xrightarrow{1}\\mathbf{Z}\\xrightarrow{0}\\mathbf{Z}\\to 0.$$\nThe boundaries coincide with the cycles except in dimension zero, where $B_0(\\ast)=0$ while $Z_0(\\ast)=\\mathbf{Z}$. Therefore $ H_0(\\ast)=\\mathbf{Z}$ but $ H_i(\\ast)=0$ for $i>0$.\n\nWe've defined homology groups for each space, but haven't considered what happens to maps between spaces. A continuous map $f\\colon X\\to Y$ induces a map $f_\\ast\\colon \\Sin_n(X)\\to\\Sin_n(Y)$ by composition: $\\sigma\\mapsto f\\circ \\sigma=:f_\\ast\\sigma$. For $f_\\ast$ to be a map of semi-simplicial sets, it needs to commute with face maps. Explicitly, we need $f_\\ast \\circ d_i = d_i \\circ f_\\ast$. A diagram is said to be \\emph{commutative} if all composites with the same source and target are equal, so this is equivalent to commutativity of the below.\n\\begin{eqnarray*}\n\\xymatrix{\\Sin_n(X)\\ar[r]^{f_\\ast}\\ar[d]^{d_i} & \\Sin_n(Y)\\ar[d]^{d_i}\\\\\n\\Sin_{n-1}(X)\\ar[r]^{f_\\ast} & \\Sin_{n-1}(Y)}\n\\end{eqnarray*}\nWe see that $d_if_\\ast\\sigma=(f_\\ast\\sigma)\\circ d^i=f\\circ\\sigma\\circ d^i$, and $f_\\ast(d_i\\sigma)=f_\\ast(\\sigma\\circ d^i)=f\\circ\\sigma\\circ d^i$ as desired. The diagram remains commutative when we pass to the free abelian groups of chains.\n\nIf $C_\\ast$ and $D_\\ast$ are chain complexes, a \\emph{chain map} $f\\colon C_\\ast\\to D_\\ast$ is a collection of maps $f_n\\colon C_n\\to D_n$ such that the following diagram commutes for every $n$:\n\\begin{equation*}\n    \\xymatrix{\n\tC_n\\ar[r]^{f_n}\\ar[d]^{\\partial_C} & D_n\\ar[d]^{\\partial_D}\\\\\n\tC_{n-1}\\ar[r]^{f_{n-1}} & D_{n-1}\n    }\n\\end{equation*}\nFor example, if $f\\colon X\\to Y$ is a continuous map, then $f_\\ast \\colon S_\\ast(X)\\to S_\\ast(Y)$ is a chain map as discussed above.\n\nA chain map induces a map in homology $f_\\ast: H_n(C)\\to H_n(D)$. The method of proof is a so-called ``diagram chase'' and it will be the first of many. We check that we get a map $Z_n(C)\\to Z_n(D)$. Let $c\\in Z_n(C)$, so that $\\partial_C c = 0$. Then $\\partial_D f_n(c) = f_{n-1}\\partial_C c = f_{n-1}(0) = 0$, because $f$ is a chain map. This means that $f_n(c)$ is also an $n$-cycle, i.e., $f$ gives a map $Z_n(C)\\to Z_n(D)$.\n\nSimilarly, we also get a map $B_n(C)\\to B_n(D)$. Let $c\\in B_n(C)$, so that there exists $c^\\prime \\in C_{n+1}$ such that $\\partial_C c^\\prime = c$. Then $f_n(c) = f_n\\partial_C c^\\prime = \\partial_D f_{n+1}(c^\\prime)$. Thus $f_n(c)$ is the boundary of $f_{n+1}(c^\\prime)$, and $f$ gives a map $B_n(C)\\to B_n(D)$.\n\nThe two maps $Z_n(C)\\to Z_n(D)$ and $B_n(C)\\to B_n(D)$ give a map on homology $f_\\ast: H_n(X)\\to H_n(Y)$, as desired.", "meta": {"hexsha": "fa0bcdbc44b451444dfde16908dc6547d50842df", "size": 6483, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-2-simplices.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "old-905/lec-2-simplices.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "old-905/lec-2-simplices.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 106.2786885246, "max_line_length": 677, "alphanum_fraction": 0.6857936141, "num_tokens": 2306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085145, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.7256224413808341}}
{"text": "\\section{Linear Smoothers: Influence, Variance, and Degrees of Freedom}\nAll the smoothers we have discussed in this class are linear\nsmoothers. The\nestimates of the regression function can be written as \n\\[\n\\hat{\\f} = \\bS \\by.\n\\]\n\nFor some of the smoothers we have defined we can define a weight sequence\nfor any $x$ and define\n\\[\n\\hat{f}(x) = \\sum_{i=1}^n W_i (x) y_i.\n\\]\n\n\nHow can we characterize the amount of smoothing being performed? The\nsmoothing parameters provide a characterization, but it is not ideal\nbecause it does not permit us to compare between different smoothers\nand for smoothers like loess it does not take into account the shape\nof the weight function nor the degree of the polynomial being fit.\n\nWe now use the connections between smoothing and multivariate linear\nregression (they are both linear smoothers) to characterize pointwise\ncriteria that characterize the amount of smoothing at a single point\nand global criteria that characterize the global amount of smoothing.\n\nWe will define variance reduction, influence, and degrees of freedom\nfor linear smoothers.\n\n\nThe variance of the interpolation estimate is $\\var[y_1] =\n\\sigma^2$. The variance of our smooth estimate is \n\\[\n\\var[\\hat{f}(x)] = \\sigma^2 \\sum_{i=1}^n W_i^2(x)\n\\]\nso we define $\\sum_{i=1}^n W_i^2(x)$ as the variance reduction. Under\nmild conditions one can show that this is less than 1.\n\n\\begin{figure}[htb]\n\\caption{Degrees of freedom for loess and smoothing splines as\nfunctions of the smoothing parameter}\n\\begin{center}\n\\epsfig{figure=Plots/plot-06-01.ps,angle=270,width=.8\\textwidth}\n\\end{center}\n\\end{figure}\n\nBecause \n\\[\n\\sum_{i=1}^n \\var[\\hat{f}(x_i)] = \\tr(\\bS\\bS')\\sigma^2,\n\\]\nthe total variance reduction from $\\sum_{i=1}^n \\var[y_i]$ is\n$\\tr(\\bS\\bS')/n$. \n\n\nIn linear regression the variance reduction is related to the degrees of\nfreedom, or number of parameters. For linear regression, $\\sum_{i=1}^n\n\\var[\\hat{f}(x_i)] \n= p \\sigma^2$. One widely used definition of degrees of freedoms for\nsmoothers is $df = \\tr(\\bS\\bS')$.\n\nThe sensitivity of the fitted value, say $\\hat{f}(x_i)$, to the data\npoint $y_i$ can be\nmeasured by $W_i(x_i)/\\sum_{i=1}^n W_n(x_i)$ or $\\bS_{ii}$ (remember\nthe denominator is usually 1).\n\nThe total influence or sensitivity is $\\sum_{i=1}^n W_i(x_i) =\n\\tr(\\bS)$.\n\nIn linear regression $\\tr(\\bS)=p$ is also equivalent to the degrees of\nfreedom. This is also used as a definition of degrees of freedom.\n\n\n\n\n\n\\begin{figure}[htb]\n\\caption{Comparison of three definition of degrees of freedom}\n\\begin{center}\n\\epsfig{figure=Plots/plot-06-02.ps,angle=270,width=.8\\textwidth}\n\\end{center}\n\\end{figure}\n\n\nFinally we notice that \n\\[\n\\E[ (\\by - \\hat{\\f})'(\\by - \\hat{\\f}) ] = \\{n - 2\\tr(\\bS) +\n\\tr(\\bS\\bS')\\}\\sigma^2\n\\]\nIn the linear regression case this is $(n-p)\\sigma^2$. We therefore denote \n$n - 2\\tr(\\bS) + \\tr(\\bS\\bS')$ as the residual degrees of freedom. A\nthird definition of degrees of freedom of a smoother is then\n$2\\tr(\\bS) - \\tr(\\bS\\bS')$.\n\nUnder relatively mild assumptions we can show that \n\\[\n1 \\leq \\tr(\\bS\\bS') \\leq \\tr(\\bS) \\leq 2\\tr(\\bS) - \\tr(\\bS\\bS') \\leq n\n\\]\n\n\n", "meta": {"hexsha": "74b8a3c6f3ce1d6c4150f56ee16f132b846d50cc", "size": 3109, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-06-01.tex", "max_stars_repo_name": "igrabski/rafalab.github.io", "max_stars_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2016-08-17T23:04:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T19:21:02.000Z", "max_issues_repo_path": "pages/754/section-06-01.tex", "max_issues_repo_name": "igrabski/rafalab.github.io", "max_issues_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-18T00:41:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-21T22:35:40.000Z", "max_forks_repo_path": "pages/754/section-06-01.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 31.09, "max_line_length": 75, "alphanum_fraction": 0.7198456095, "num_tokens": 967, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.8459424353665382, "lm_q1q2_score": 0.7256224274118763}}
{"text": "\\subsection{Graphs of Trigonometric Functions}\nThe graph of the functions $\\sin x$ and $\\cos x$ can be visually represented as:\n\n$$\\includegraphics[width=4.0in]{images/sine-cosine}$$\n\nBoth $\\sin x$ and $\\cos x$ have domain $(-\\infty,\\infty)$ and range $[-1,1]$.\nThat is,\n$$-1\\leq\\sin x\\leq 1\\qquad -1\\leq\\cos x\\leq 1.$$\nThe zeros of $\\sin x$ occur at the integer multiples of $\\pi$, that is, $\\sin x=0$ whenever $x=n\\pi$, where $n$ is an integer.\nSimilarly, $\\cos x=0$ whenever $x=\\pi/2+n\\pi$, where $n$ is an integer.\n\nThe six basic trigonometric functions can be visually represented as:\n\n$$\\includegraphics[width=7in]{images/trig-functions-new}$$\n\nBoth tangent and cotangent have range $(-\\infty,\\infty)$, whereas cosecant and secant have range $(-\\infty,-1]\\cup[1,\\infty)$.\nEach of these functions is periodic. Tangent and cotangent have period $\\pi$, whereas sine, cosine, cosecant and secant have period $2\\pi$.", "meta": {"hexsha": "a17734798620fa6d525736f35a74da77f75917b3", "size": 917, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1-review/1-3-4-graphs-trig-functions.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1-review/1-3-4-graphs-trig-functions.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1-review/1-3-4-graphs-trig-functions.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.9411764706, "max_line_length": 139, "alphanum_fraction": 0.7099236641, "num_tokens": 290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.725555635511083}}
{"text": "\\section{Newton's method}\n\n\\subsection{Implementation}\n\n\nWe are going to use the class algorithm:\n\n\n\\includegraphics[width=\\linewidth]{3_hessian_formula.png}\n\n\\subsubsection{Hessian matrix}\n\nFor function $f(x,y) = (x+2)^2 + 2(y-2)^2 + 2 \\sin (2 \\pi x) \\sin (2 \\pi y)$\n\n\\begin{equation*}\n  \\frac{\\partial }{\\partial x} f = 2 (x + 2) + 2 \\sin (2 \\pi y) \\cos ( 2 \\pi x) 2 \\pi =  2 (x + 2) +  4 \\pi \\sin (2 \\pi y) \\cos ( 2 \\pi x)   \n\\end{equation*}\n\n\\begin{equation*}\n  \\frac{\\partial }{\\partial y} f = 4 (y - 2) +  4 \\pi \\sin (2 \\pi x) \\cos ( 2 \\pi y)   \n\\end{equation*}\n\n\n\\begin{equation*}\n  \\frac{\\partial ^2 }{\\partial y \\partial x} f =  \\frac{\\partial ^2 }{\\partial x \\partial y } f =  8 \\pi^2 \\cos (2 \\pi x) \\cos ( 2 \\pi y)   \n\\end{equation*}\n\n\n\\begin{equation*}\n  \\frac{\\partial^2 }{\\partial y^2} f = 4  -  8 \\pi^2 \\sin (2 \\pi x) \\sin ( 2 \\pi y)   \n\\end{equation*}\n\n\n\\begin{equation*}\n  \\frac{\\partial^2 }{\\partial x^2} f = 2  -  8 \\pi^2 \\sin (2 \\pi x) \\sin ( 2 \\pi y)   \n\\end{equation*}\n\n\n\\subsubsection{Implementation}\n\nOne implementation (really similar to the \\texttt{gradient\\_descent\\_trace}\n\n\\begin{minted}{python}\ndef newton_trace(initial_point, fun, grad_fun, hessian, eta, max_iter):\n    \"\"\" Newton method\n    INPUT \n    - initial_point: \n    - f: differential function\n    - grad_fun: Gradient\n    - hessian: hessian\n    - eta: learning rate\n    - max_iter: number of iterations\n\n    OUTPUT \n    w trace\n    \"\"\"\n\n    w = initial_point\n    w_list = [initial_point]\n    iterations = 0\n\n    while iterations < max_iter:\n        w = w - eta *np.linalg.inv(hessian(w[0],w[1])).dot(grad_fun(w[0], w[1]))\n        w_list.append(w)\n        iterations += 1\n\n    return np.array(w_list)\n\n \\end{minted}\n\n\n The results after run are\n\n \\begin{verbatim}\nWith eta = 0.01, \ncoordenates (x,y)= (-0.9793498427941949, 0.9893767407575305), \nthe number of iterations: 50 and the image is f(x,y) = 3.0671859515488302\n\n\nWith eta = 0.1, \ncoordenates (x,y)=(-0.9463274028190676, 0.9717082373563009), \nthe number of iterations: 50 and the image is f(x,y) = 3.1079767229661335\n\\end{verbatim}\n\n\n\n \\includegraphics[width=\\linewidth]{3_1_eta_01.png}\n \\includegraphics[width=\\linewidth]{3_1_eta_001.png}\n \\includegraphics[width=\\linewidth]{3_1_comparatives_etas.png}\n\n\n As we see this method does not minimize the function independently of the learning rate and even worse than the initial point. This is because this algorithm is sensible about where the gradient is zero.\n\n So in this case the algorithm get trapped in a saddle point.\n\n However if the function is convex it would be more precise even though the selection of the learning rating was bigger. \n\n\n\n\n\n\\subsubsection{Different initial points }\n\n\\begin{center}\n  \\begin{tabular}{ |c|c|c| }\n    \\hline\n    Initial point  & Final coordinates & Final value  \\\\ \n    \\hline\n\n    (-0.5 -0.5) & (-0.9463274,  0.97170824)  &  3.10798 \\\\\n    (1, 1)    & [1.067, 0.911] &  11.345 \\\\\n( 2.1, -2.1)   &  ( 3.261, -3.118)  & 78.711 \\\\\n    (-3 , 3)  &  (-3.0536726 ,  3.02829176) &   3.108\\\\\n(-2 , 2)  &  (-2,  2) &  0 \\\\\n \n \\hline\n\\end{tabular}\n\\end{center}\n\nIf we compare with the gradient descendant's algorithm\n\n\\begin{center}\n  \\begin{tabular}{ |c|c|c| }\n    \\hline\n    Initial point  & Final coordinates & Final value  \\\\ \n    \\hline\n\n    (-0.5 -0.5) &  (-0.793 -0.126) &   9.125 \\\\\n(1 1) &  (0.677 1.29) &   6.437 \\\\\n( 2.1 -2.1) &  ( 0.149 -0.096 ) &   12.491 \\\\\n(-3  3) &  (-2.7315  2.713) &  -0.381 \\\\\n(-2  2) &  (-2.  2.) &  0 \\\\\n    \n \n \\hline\n\\end{tabular}\n\\end{center}\n\n\n\nSo apart form the first one and the last point (which is a solution) the Newton's method is worse.\n\nLet's see what is happening by plotting their traces. \n\n\\includegraphics[width=\\linewidth]{3_2_comparation_1.png}\n\\includegraphics[width=\\linewidth]{3_2_comparation_2.png}\n\n\nAnalysing the results we have observed that the points get easily trapped in a point, this may be because this algorithm is sensitive to the hessian.\n\n\nIf we compute these points' gradients and hessian we see that:\n\n\\begin{verbatim}\n\nFor (-0.38067878, -0.52778221)\n\tThe gradient value is [ 1.64133153 -1.67813744]\n\tThe inverse hessian is [[-0.00432244  0.01843361]\n [ 0.01843361 -0.00367461]]\n\nFor (1.06677195, 0.91078249)\n\tThe gradient value is [ 0.03180694 -0.02149455]\n\tThe inverse hessian is [[-0.00634209  0.01835718]\n [ 0.01835718 -0.00574093]]\n\nFor (3.26077803, -3.11750721)\n\tThe gradient value is [ 11.09387996 -11.19723696]\n\tThe inverse hessian is [[0.0182662  0.00126589]\n [0.00126589 0.0176255 ]]\n\nFor (-2.0, 2.0)\n\tThe gradient value is [-6.15574622e-15  6.15574622e-15]\n\tThe inverse hessian is [[-0.00064245  0.01268142]\n [ 0.01268142 -0.00032122]]\n\n\\end{verbatim}\n\nAs we thought the hessians of all these points are \\textit{close} the null matrix.\n\n\\subsubsection{Conclusions}\n\nThis algorithm minimizes correctly the gradient but not the function. Therefore, if a function have saddle points this algorithm would not be as useful as the gradient descendent. Moreover, other problem is that the function should be twice differentiable. \n ", "meta": {"hexsha": "27eba5e6178369dbd4a069823b7e56963de5000e", "size": 5039, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "practica1/memory/hessian.tex", "max_stars_repo_name": "BlancaCC/aprendizaje-automatico", "max_stars_repo_head_hexsha": "3a1288b951ffcf1121ee43aa37efe2daf7a06450", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "practica1/memory/hessian.tex", "max_issues_repo_name": "BlancaCC/aprendizaje-automatico", "max_issues_repo_head_hexsha": "3a1288b951ffcf1121ee43aa37efe2daf7a06450", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-04T14:03:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-04T14:03:37.000Z", "max_forks_repo_path": "practica1/memory/hessian.tex", "max_forks_repo_name": "BlancaCC/aprendizaje-automatico", "max_forks_repo_head_hexsha": "3a1288b951ffcf1121ee43aa37efe2daf7a06450", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5355191257, "max_line_length": 257, "alphanum_fraction": 0.6610438579, "num_tokens": 1769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8824278633625322, "lm_q1q2_score": 0.7255225977263828}}
{"text": "\\section{Supervised learning on image classification}\\label{sec:MLbasics}\nWe consider a basic machine learning problem for classifying a\ncollection of images into $\\kappa$ distinctive classes.  As an\nexample, we consider a two-dimensional image which is usually\nrepresented by a tensor\n$$\nf\\in  {\\mathcal D} := \\mathbb{R}^{c \\times m\\times n}.\n$$\nHere \n\\begin{equation}\n\\label{data-c}\nc=\n\\left\\{\n\\begin{array}[rl]{rl}\n1 & \\mbox{for grayscale image},\\\\    \n3 & \\mbox{for color image}.\n\\end{array}\n\\right.\n\\end{equation}\n\nA typical supervised machine learning problem begins with a data set (training data)\n$$\nD := \\{(f_i, y_i)\\}_{i=1}^N,\n$$ \nwith\n$$\n\\{f_i\\}_{i=1}^N \\subset {\\mathcal D},\n$$\nand $y_i \\in \\mathbb{R}^{\\kappa}$ is the label for data $f_i$, with\n$[y_i]_j$ as the probability for $f_i$ in classes $j$. \n\n\nRoughly speaking, a supervised learning problem can be thought as a data fitting\nproblem in a high dimensional space ${\\mathcal D}$.\nNamely, we need to find a mapping\n$H:  \\mathbb R^{c\\times m\\times n}\\mapsto \\mathbb R^\\kappa,$\nsuch that, for a given $f\\in  {\\mathcal D}$, \n\\begin{equation}\\label{eq:idealouput}\nH(f)\\approx e_i\\in \\mathbb R^\\kappa,\n\\end{equation}\nif $f$ is in class $i$, for $1\\le i\\le \\kappa$. \nFor the general setting above, we use a probatilistic model for understanding the\noutput $H(f) \\in \\mathbb{R}^{\\kappa}$ as a discrete \ndistribution on $\\{1, \\cdots,\\kappa\\}$, with $[H (f)]_i$ as the probability\nfor $f$ in the class $i$, namely\n\\begin{equation}\n\\label{distrib}\n0 \\le [H(f)]_i \\le 1,\\quad \n\\sum_{i=1}^\\kappa  [H(f)]_i=1. \n\\end{equation}\nAt last, we finish our model with a simple strategy to choose\n\\begin{equation}\\label{eq:maxchoose}\n\\mathop{\\arg\\max}_{i}\\{[H(f)]_i~:~ i = 1:\\kappa\\},\n\\end{equation}\nas the label for a test data $f$, which ideally is close to\n\\eqref{eq:idealouput}.  The remaining key issue is the construction of\nthe classification mapping $H$.\n\n\n%\\subsection{Model construction}\n%In many CNN type models for image classification, there are usually\n%three major steps to construct $H$.\nThe main step in the construction of $H$ is to \nconstruct a nonlinear mapping\n\\begin{equation}\n\\label{linearize}\nH_0: {\\mathcal D} \\mapsto V_J,\n\\end{equation}\nwith \n\\begin{equation}\n\\label{VJ}\nV_J = \\mathbb R^{c_J \\times m_J\\times n_J}. \n\\end{equation}\nTo be consistent with the notation for CNN which will be described below,\nhere the subscript $J$ refers to the number of \ncoarsening girds in CNN. \nRoughly speaking, the map $H_0$ plays two roles.  The first role\nis to conduct a dimensionality reduction, namely\n$$\nc_Jm_Jn_J\\ll  mnc.\n$$\nThe second role is to map a complicated set of data into a set of data\nthat are linearly separable. As a result, the simple logistic regression \nprocedure can be applied.\n\nThe first step in a logistic regression is to introduce a linear mapping:\n\\begin{equation*}\n\\Theta: {\\mathcal D} \\to\\mathbb{R}^{\\kappa} ,\n\\end{equation*}as \n\\begin{equation}\\label{thetamap}\n\\Theta(x)=Wx+b,\n\\end{equation}\nwhere $W=(w_{ij})\\in\\mathbb{R}^{(c_J\\times m_J \\times n_J)\\times \\kappa}$, \n$b\\in\\mathbb{R}^{\\kappa}$.\n\n\nWe then use the soft-max function.\n\\begin{equation}\n\\label{softmax}\n[S(z)]_i=[{\\rm Solftmax}(z)]_i= \\frac{e^{z_i}}{\\sum_{j} e^{z_j}},\n\\end{equation}\nto obtain a logistic regression model \n\\begin{equation}\n\\label{eq:log_reg}\nS \\circ \\Theta: \\mathbb R^{c_J \\times m_J\\times n_J}\\mapsto \\mathbb R^\\kappa.\n\\end{equation}\n\n\nBy combining the nonlinear mapping $H$ in \\eqref{linearize}\nand the logistic regression \\eqref{eq:log_reg}, we obtain the following classifier:\n\\begin{equation}\n\\label{classifier}\nH=  S\\circ \\Theta\\circ H_0.\n\\end{equation}\n\n%\\subsection{Loss function and training}  \nGiven the model \\eqref{classifier},\nwe finish the training phase with solving the next optimization \nproblem:\n\\begin{equation}\n\\label{eq:3}\n\\min \\sum_{j=1}^Nl(y_j, H(f_j)),\n\\end{equation}\nwhere\nHere $l(y_j, H(f_j))$ is a  loss function that measures the\npredicted result $H(f_j)$ and the real label $y_j$. \nIn logistic regression, \nthe following cross-entropy loss function is often used\n$$\nl(y_j, H(f)) = \\sum_{i=1}^\\kappa -[y]_i \\log [H(f)]_i.\n$$", "meta": {"hexsha": "7561d2b0fba1df3f3d37ab55562970ee07ba94b0", "size": 4122, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ShortLRforImages.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/ShortLRforImages.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/ShortLRforImages.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.465648855, "max_line_length": 84, "alphanum_fraction": 0.7142163998, "num_tokens": 1369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.7255189079677182}}
{"text": "Artificial neural networks (ANN) were inspired by the idea of developing programs that are able to learn how to perform certain tasks by getting examples. Neural networks generally don't have any task-specific rules implemented, they learn the important features by themselves. \n\nThe basic idea was to model the neurons in a biological brain. Such artificial neurons (also called connected units or nodes) are linked to each other and transmit signals. The neuron receives the signal and combines it with a certain weight and bias before sending it to the next connected unit. The weight and the bias are free parameters which have to be optimized by the network itself. \nIn ANNs, nodes are combined into layers. The input data is processed by several layers connected to each other. Each layer is typically trained to extract a certain feature of the input data to yield the required information at the end. \n\nNeural networks are mostly used for two different kinds of analysis. The first one is the prediction of a continuous variable, which is called a regression problem. The second, which is specified here, is the problem of identifying an input as part of a class, called a classification model.\nIn classification problems the training is typically supervised. The network is given input data and corresponding label vectors which state to which category the respective input belongs. False labelling is penalized and leads to weight and bias adjustments.\n\nTraining a network means giving examples of the task and evaluating the performance of the network. This evaluating is done through backpropagation. The input propagates through the network until it reaches the output layer. There it is compared to the actual output vector. The difference between these two or the classification error is given by a loss function. This error is then propagated backwards through the network until every neuron has an associated error value. Through this value the weight and bias of the corresponding neuron is then changed to improve the performance of the network. \n\nAs updating the weights after every input sample is inefficient and makes the loss function very noisy, several samples are combined in one batch or minibatch. The training values are averaged over the sample and the network learns more general features. \n\nTypically the available input data is limited and can not be easily generated. The network therefore uses the same data several times during the training. One training session which uses the entire data set exactly once is called an epoch. To fully train a ANN several hundred epochs are needed. To prevent the network only being able to classify the training data correctly a small part of it is being split off. This data set is called the validation data. After every epoch the network evaluates its progress on the validation data which has not been used during training. This secures an independent evaluation.  \n\nIn contrast to the free parameters set by the network, hyperparameters have to be specified before training starts. Different kinds of networks have different hyperparameters, one for example being the size of the minibatch. Optimized hyperparameters contribute significantly to the success of the network. \\cite{Bishop2016}\n\n\n\\section{Image recognition}\nImage recognition has always played a huge part in the development of neural networks. Current state-of-the-art networks in image recognition have now reached human or even superhuman performance. Image recognition with neural networks is normally placed within the \\enquote{deep learning} category. Such architectures include successive layers with nonlinear processing units. Each layer is connected to its predecessor and uses the output of the latter as input. This enables the network to learn different features, higher layers then correspond to higher levels of abstraction. \n\n The problem with conventional multilayer perceptrons are the computing power needed. In conventional ANNs the neurons are fully connected, meaning that every node in one layer is connected to every node in the layer before and after. The number of weights per node is equivalent to the product of width, height and colours of the picture. They therefore scale very badly to higher resolution images. Fully connected layers also do not take localized characteristics into account. In image recognition neighbouring pixels are more important than those far apart.\nConvolutional neural networks (CNNs) can solve both problems and are currently the best performing networks \\cite{imagenet}.\n\n\n\n\\section{Convolutional neural networks}\n\n\\begin{figure}\n\\centering\n\\includegraphics[scale=1.5]{convolve.png}\n\\caption{A convolutional layer with its kernel. The elements of the kernel are also called a filter. The kernel moves across the whole input data on the left. The right matrix is the product of input and kernel. \\cite{convwindow}}\n\\label{convwindow}\n\\end{figure}\nA convolutional neural network contains several layers in which one input sample is processed in small receptive fields (as seen in fig. \\ref{convwindow}). These receptive fields are most often called kernel or filter. One neuron in the layer corresponds to only this part of the input image in width and height but gets the whole depth of the input volume. The dot product between the entries of the kernel and the input is computed and sent to the neuron. The filter values or weights are free parameters of the network that have to be optimized. For different sets of parameters different features can be detected.\nThe map of neurons is called the activation map. As several input pixels are passed on to one neuron, the size of the input data gets gradually smaller while it is being processed by the network.\n\nConvolutional neural networks are dominated by three different features which make them ideal for image recognition. The first is the 3D volume of neurons, where they are classified in three dimensions, width, height and depth of colour. This ideally represents a picture. The second is the application of spatial locality. One neuron of a following layer is only connected to a small part of neurons in its predecessor. Therefore the network learns to recognize local patterns. With many such layers stacked the patterns learned get increasingly more global, the first one only recognizing lines, while the last one identifies complete features such as \\enquote{cat}, \\enquote{dog} or \\enquote{mouse}.\nAt last a convolutional neural network takes translational invariance into account. To classify an image correctly, the position of the object in the image is not important. Therefore all neurons in one convolutional layer share the same weights and bias, that means, the same filter is applied while forwarding the signal. Thus one layer always recognizes the same feature, regardless of its position in the image \\cite{lecunimage}. \n\nThe hyperparameters for this kind of ANN, which have to be manually tuned, are firstly the size of the convolutional window. If a size of one in width and height is chosen, the window only takes one pixel into account. A bigger size means more information is being observed. The bigger the window the less localized the features detected are. Smaller windows mean more computing power needed, and may not be able to detect larger objects, especially in high resolution pictures. At times it may be advantageous to choose a non-symmetrical kernel size.\n\nThe second hyperparameter is the depth of the output volume. It is possible to choose how often a kernel with a new set of weights will be used on the input data or further on in the network. As one kernel with a set of weights is also called a filter, the number of filters can be manually tuned. The more filters are being used, the more free parameters the network has. This can be beneficial as more details can be learned by the network but also disadvantageous as overfitting, which is explained later, is more likely to occur.\n\nIf the kernel size is chosen, the stride must be finetuned as well. If the stride is one, then the window only moves one pixel in one direction each time. A high overlap of kernel windows occurs which also produces a large output volume. This can significantly increase the computing time. If the kernel size is large, than a higher overlap is helpful.\n\nWhen the size of the input volume is not a multiple of the kernel size window, then the output dimensions differ from those of the input. Most of the time it is helpful to pad the input volume with zeros at the edges to preserve the spatial size of the input while going through layers. It is also beneficial to minimize edge effects. \\cite{lecun-89e}\n\n\\section{Overfitting}\nOverfitting is a potential problem of deep-learning networks. By choosing layers with a high number of learnable weights and biases, the number of free parameters is very high compared to the actual number of features learnable. Therefore a network is prone to overfit the training data, performing very well during the training but failing while validating on other data (fig. \\ref{accuracy}). \n\n\\begin{figure}\n\\centering\n\\includegraphics[scale=0.35]{overfittingacc.png}\n\\caption{Training and validation accuracy. The validation accuracy follows the training accuracy well if there is little or no overfitting. In the case of strong overfitting the validation accuracy increases very little or even decreases during the training.}\n\\label{accuracy}\n\\end{figure}\nOne method to address the problem of overfitting is \\enquote{max pooling}. Max pooling also reduces the spatial size, thus limiting the amount of computational power needed. The general idea is that only the rough location in comparison to others of the feature detected is needed, so the input is downsampled with the help of a non-linear function. The working principle is the same as in a convolutional layer. A kernel window moves over the input without overlapping. In every region the activation numbers of the included pixels are compared. The maximum is determined and only this pixel is forwarded to the next layer. For example, in the case of a 2x2 kernel window, the spatial size is reduced by 75 \\%, while the depth dimension stays the same. As the network cannot fit parameters to very detailed features, it has to pick up general features, which help correct classification. \n\nAnother method to reduce overfitting is dropout. With dropout a input unit is set to zero before being forwarded to the next layer with a possibility $p$. This is the same as to set every weight of one neuron to zero. This is done with after every minibatch of samples, which is tantamount to every parameter update of the network. This forces the CNN to learn more robust features to better generalize the data analysis. Dropout also cuts down on computational time. \n\n\\section{Activation functions}\nDeep neural networks need two different kinds of activation functions. The first one is to propagate the signal through the network. After the product between the input signal and the weight of one neuron is computed, the outcome is put into the activation function. Only if a nonlinear activation function is used, non trivial problems can be solved with only few nodes. The activation function is applied after every layer, meaning that every output signal is put into relation with the help of the function. The current best working activation function is the ReLu function. ReLu stands for rectified linear unit. It is calculated by\n\\begin{equation}\nf(x) = \\mathrm{max} (0,x)\n\\end{equation}\nwith x as the input signal. Negative signals are therefore always set to zero while propagating through the network. Other activation functions are for example the sigmoid function or the tangens hyperbolicus. Unlike the ReLu function, those functions saturate when dealing with very high input signals and therefore perform worse.\n\nThe second activation function is needed at the output layer, the last layer in the network. Most deep neural networks are multi-class networks. Multi-class means that the output is not simply signal or background but identifies the input as belonging to one class of several. That means that the output activation function calculates the probability of belonging in each class in correlation to every other probability. A usual activation function in this case is the softmax function. The softmax function calculates a n-dimensional vector of random real values to a n-dimensional vector, where every number lies between 0 and 1 and the sum of all entries is 1. It is calculated by\n\\begin{equation}\n\\sigma (\\vec{z})_{j} = \\frac{\\mathrm{e}^{z_j}}{\\sum_{k=1}^{n} \\mathrm{e}^{z_k} } \\quad .\n\\end{equation}\nThe vector $\\vec{z}$ is the output vector of the neural network, which corresponds after the application of the activation function to $\\sigma (\\vec{z})_{j}$, the probability of the input belonging to the corresponding classes.\nThe softmax function cannot be applied if the network is not only multi-class, but also multi-label. The categories in a multi-label network are not mutually exlusive. One input can therefore be classified into several different categories, their probability to fit is not correlated to each other. In this case the beforementioned sigmoid activation function can be used. This function also squashes a vector of real numbers to a vector of real numbers between 0 and 1. In this case the sum of all numbers does not have to be 1. The output $\\sigma (\\vec{z})_{j}$ is the independent probability of the input data belonging to class j without taking the other classes into account. The function looks like\n\\begin{equation}\n\\sigma (\\vec{z})_{j} = \\frac{1}{1 + \\mathrm{e}^{z_j}}  \n\\end{equation}\nwith $\\mathrm{e}^{z_j}$ as the output vector of the network.\nAssigning a class to the input data is normally done by selecting those entries which have a number higher than 0.5, meaning a probability higher than 50\\% of belonging to that class. \n\\section{Loss functions}\nLoss functions are a way to track the progress while training a neural network. A loss function assigns a real number to the difference between real and estimated class labels of the input, which should be minimized. During training the network changes the weights of the neurons according to the increase or decrease of the loss function. For a specific problem it is important to use a suitable loss function. For classification problems such as image recognition with more than two classes, either categorical or binary crossentropy can be used. In machine learning cross entropy is the same as logistic loss. It is calculated by\n\\begin{equation}\nf(x) = y_{\\mathrm{true}} \\cdot \\mathrm{ln} (y_{\\mathrm{pred}}) + (1 - y_{\\mathrm{true}}) \\cdot \\mathrm{ln} (1 - y_{\\mathrm{pred}})\n\\end{equation}\nwhere $y_{\\mathrm{true}}$ is the true label vector of the input and $y_{\\mathrm{pred}}$ the label vector of the prediction of the network.\n\nThe difference between categorical and binary crossentropy is only the way in which it is applied. With categorical crossentropy, the whole vector is compared. If only one entry differs, it is considered falsely labeled. This is useful in multi-class problems, where the labels are mutually exclusive. With multi-label problems, binary crossentropy works better. Binary crossentropy compares every label separately, therefore not penalizing one incorrect label so much. \n\n\\section{Optimization algorithms}\nTo minimize the loss function the neural network has to update its weights and biases during training. This updating is done through an optimization algorithm. To find a minimum of the loss function it is possible to evaluate the gradient of the function. The updating of the network is then proportional to the negative of the gradient. This is an iterative algorithm which finds the steepest descent to a local minimum. The size of the steps taken in the direction of the descent is also called the learning rate. The learning rate is a hyperparameter which has to be optimized to get best training results. \n\nTo compute the gradient for the whole training data takes very long. To shorten the time and computing power needed stochastic gradient descent (SDG) is implemented. SDG uses only one stochastically chosen example to compute the gradient and update the parameters. This can of course result in very varying parameter updates. To prevent this the gradient is computed not over one sample, but over a whole batch. This works because the samples in the dataset are correlated. They all depict the same or similar things, so an update computed for one batch is a good approximation for the complete set. It also can be done much more often, therefore achieving faster convergence for the loss function.\n\nMost optimization algorithms also use momentum. Momentum can be understood by making an analogy to classical physics. If a ball at the top of a hill rolls down, it gains momentum if the direction downhill always stays the same. The hill here represents our loss function. If the gradient of a step points in the same \\enquote{direction} as the step before, the \\enquote{speed} or step size increases. If the direction changes, the step size gets smaller. If a minimum is found and the imaginary ball oversteps it, the gradient points in the other direction and momentum decreases. The minimum can so be found iteratively.\n\nTo further prevent the network from overstepping the minimum which is still a possibility even with momentum, the Nesterov Accelerated Gradient can be implemented. Instead of evaluating the gradient, changing the loss function and then applying momentum, the network anticipates what is going the happen. At first the momentum is applied to the current position. This is an approximation of the future position of the function. At this position the gradient is computed. The network there \\enquote{sees} where its going to end up in the next step and can therefore move in the right direction (see fig. \\ref{nesterov}). This minimizes the possibility of overstepping and decreases the convergence time. The strength of momentum is also a hyperparameter which needs to be tuned.\n\n\\begin{figure}\n\\centering\n\\resizebox{!}{5cm}{\n\\begin{tikzpicture}\n%% Linke Hälfte\n\n%Pfeile\n\\draw [-triangle 60, very thick, red](0,0) -- (5,0);\n\\draw [-triangle 60, very thick, gruen](0,0) -- (2,4.5);\n\\draw [-triangle 60, dashed, red, opacity= 0.7] (2,4.5) -- (7,4.5);\n\\draw[-triangle 60, very thick, blue] (0,0) -- (7,4.5);\n\n%Kugel\n\\draw[ball color=red] (0,0) node (v1) {} circle (.2);\n%\\fill[red]  (0,0) ellipse (0.5 and 0.5); Alternative Kugel, mehr ein Kreis\n\n%% Texte\n\\node[red] at (2.5,-0.5) { \\large{gradient step}};\n\\node[gruen] at (0,3.5) {\\large{momentum}};\n\\node[gruen] at (-0.6,3) {\\large{step}};\n\\node[blue] at (5,2) {\\large{actual step}};\n\\node at (3,6) {\\LARGE{Momentum update}};\n\n% Trennlinie\n\\draw [gray, very thick](9,6.5) -- (9,-1);\n\n%% Rechte Hälfte\n\n%Pfeile\n\\draw [-triangle 60, gruen, very thick](11,0) node (v2) {} -- (13,4.5) node (v3) {};\n\\draw [blue, -triangle 60, very thick](11,0) -- (17,3) node (v4) {};\n\\draw [red, -triangle 60, very thick](13,4.5) -- (17,3);\n\n%Kugel\n\\draw[ball color=red] (11,0) circle (.2);\n\n%%Texte\n\\node at (13.5,6) {\\LARGE{Nesterov momentum update}};\n\\node[gruen] at (10.5,3.5) {\\large{momentum}};\n\\node[gruen] at (9.9,3) {\\large{step}};\n\\node[blue] at (15,1) {\\large{actual step}};\n\\node[red] at (15.5,5) {\\large{'lookahead'}};\n\\node[red] at (15.5,4.5) {\\large{gradient step}};\n\n\\end{tikzpicture}\n}\n\\caption{Classical momentum compared to Nesterov momentum. The network anticipates its future position through momentum and calculates the gradient based on that. It ends up on a slightly different position, thus converging faster. \\cite{nesterov}}\n\\label{nesterov}\n\\end{figure}\n\nDuring the training it is helpful to decrease the learning rate over time. As the loss gets smaller, the gradient also decreases. Too high learning rates can start to behave chaotically and the network cannot settle into the minimum of the loss function. To manually decrease the learning rate the common types of decay are step decay, which reduces the learning rate by a factor every few epochs, exponential decay or 1/t decay, where t is the number of epochs. \n\nSuch decays act globally and are difficult to tune. Setting the decay rate too high means severely slowing down the network, setting it too low risks erratic jumps of the loss function. Several more complicated algorithms have been developed to be used for optimizing functions. One of the current best working algorithms is the Adam algorithm (\\cite{adam}). Adam is derived from adaptive moment estimation. The learning rate is adjusted for each parameter separately and based on first and second moments of the gradient. It is bounded by a set step size and naturally annealed during the training. Adam performs well on sparse and noisy gradients and needs very little memory, as only first order gradients have to be calculated.\n", "meta": {"hexsha": "6de646afd153c114179677365a13c48ce7d3dc5f", "size": 20980, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap/neuralnetworks.tex", "max_stars_repo_name": "IsiH/BA-Castor", "max_stars_repo_head_hexsha": "f28fdfd29c564dec0fc91b32b0a764c00ab7b79a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chap/neuralnetworks.tex", "max_issues_repo_name": "IsiH/BA-Castor", "max_issues_repo_head_hexsha": "f28fdfd29c564dec0fc91b32b0a764c00ab7b79a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chap/neuralnetworks.tex", "max_forks_repo_name": "IsiH/BA-Castor", "max_forks_repo_head_hexsha": "f28fdfd29c564dec0fc91b32b0a764c00ab7b79a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 139.8666666667, "max_line_length": 889, "alphanum_fraction": 0.7944709247, "num_tokens": 4541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942171172603, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7255022392057437}}
{"text": "\\section{The Diffusion Equation}\r\n\\subsection{Physical Origin}\r\nWe want to understand physical phenomena that ``diffuses'' due to spatial gradient.\r\nAn early example was Fick's Law $\\underline{J}=-D\\nabla c$ where $J$ is the flux, $c$ is the concentration and $D$ is the diffusion coefficient.\r\nFor heat flow, we also have Fourier's Law saying $\\underline{q}=-k\\nabla\\Theta$ where $\\underline{q}$ is the heat flux, $k$ is the thermal conductivity and $\\Theta$ is the temperature.\\\\\r\nIn a volume $V$, the overall heat energy $Q$ is\r\n$$Q=\\int_V c_V\\rho\\Theta\\,\\mathrm dV$$\r\nwhere $c_V$ is the specific heat capacity of the matertial of the volume $V$, and $\\rho_V$ is the mass density.\r\nTe rate of change of it would then be, making use of Fourier's law,\r\n$$\\frac{\\mathrm dQ}{\\mathrm dt}=\\int_Vc_V\\rho\\frac{\\partial\\Theta}{\\partial t}\\,\\mathrm dV$$\r\nOn the other hand, integrating Fick's Law over $S=\\partial V$,\r\n$$-\\frac{\\mathrm dQ}{\\mathrm dt}=\\int_S\\underline{q}\\cdot\\underline{\\hat{n}}\\,\\mathrm dS=\\int_S(-k\\nabla\\Theta)\\cdot\\underline{\\hat{n}}\\,\\mathrm dS=\\int_V(-k\\nabla^2\\Theta)\\,\\mathrm dV$$\r\nby Fourier's Law.\r\nTherefore,\r\n$$\\int_Vc_V\\rho\\frac{\\partial\\Theta}{\\partial t}-k\\nabla^2\\Theta\\,\\mathrm dV=0$$\r\nfor all volumn $V$.\r\nSo the integrand must vanish everywhere (assuming it is continuous), which gives\r\n$$\\frac{\\partial\\Theta}{\\partial t}-D\\nabla^2\\Theta=0$$\r\nwhere $D=k/(c_V\\rho)$.\r\nThis is known as the diffusion equation.\\\\\r\nWe can also derive this from a more fundamental point of view.\r\nConsider gas particles diffuse by scattering.\r\nSo for every small time change $\\Delta t$ in time a particle moves for a distance $\\xi$ with probability (PDF) $p(\\xi)$.\r\nLet $\\langle X\\rangle$ be the mean of $X$.\r\nWe assume $\\langle\\xi\\rangle=0$.\r\nSuppose the PDF after $N\\Delta t$ steps is $P_{N\\Delta t}(x)$, then for $(N+1)\\Delta t$ step,\r\n\\begin{align*}\r\n    P_{(N+1)\\Delta t}(x)&=\\int_{-\\infty}^\\infty p(\\xi)P_{N\\Delta t}(x-\\xi)\\,\\mathrm d\\xi\\\\\r\n    &\\approx \\int_{-\\infty}^\\infty p(\\xi)\\left(P_{N\\Delta t}(x)-\\xi P_{N\\Delta t}^\\prime(x)+\\frac{\\xi^2}{2}P_{N\\Delta t}^{\\prime\\prime}(x)\\right)\\,\\mathrm d\\xi\\\\\r\n    &=P_{N\\Delta t}(x)+P_{N\\Delta t}^{\\prime\\prime}(x)\\frac{\\langle\\xi^2\\rangle}{2}\r\n\\end{align*}\r\nIdentify $P_{N\\Delta t}(x)=P(x,N\\Delta t)$, then we have\r\n$$P(x,(N+1)\\Delta t)-P(x,N\\Delta t)=\\frac{\\partial^2P}{\\partial x^2}(x,N\\Delta t)\\frac{\\langle\\xi^2\\rangle}{2}$$\r\nBy some probabilistic argument, $\\langle\\xi^2\\rangle\\propto\\Delta t$, so this gives\r\n$$\\frac{\\partial P}{\\partial t}=D\\frac{\\partial^2P}{\\partial x^2}$$\r\nfor a constant $D$.\r\n\\subsection{Similarity Solution}\r\nThe characteristic relation between variance and time suggests that we may start seeking a solution in terms of the dimensionless parameter $\\eta=x/(2\\sqrt{Dt})$.\r\nThat is, we want to find solutions of the form $\\Theta(x,t)=\\Theta(\\eta)$.\r\nChange variables in this way,\r\n$$\\frac{\\partial\\Theta}{\\partial t}=\\frac{\\partial\\eta}{\\partial t}\\frac{\\mathrm d\\Theta}{\\mathrm d\\eta}=-\\frac{1}{2}\\frac{x}{\\sqrt{D}t^{3/2}}\\Theta^\\prime=-\\frac{\\eta}{2t}\\Theta^\\prime$$\r\n$$D\\frac{\\partial^2\\Theta}{\\partial x^2}=D\\frac{\\partial}{\\partial x}\\left(\\frac{\\partial\\eta}{\\partial x}\\frac{\\mathrm d\\Theta}{\\mathrm d\\eta}\\right)=D\\frac{\\partial}{\\partial x}\\left( \\frac{1}{2\\sqrt{Dt}}\\Theta^\\prime \\right)=\\frac{D}{4Dt}\\Theta^{\\prime\\prime}=\\frac{1}{4t}\\Theta^{\\prime\\prime}$$\r\nPutting them all together gives $\\Theta^{\\prime\\prime}=-2\\eta\\Theta^\\prime$, which gives $\\Theta^\\prime\\propto e^{-\\eta^2}$, therefore\r\n$$\\Theta(\\eta)=\\Theta(0)+\\frac{2C}{\\sqrt{\\pi}}\\int_0^\\eta e^{-u^2}\\,\\mathrm du=\\Theta(0)+C\\operatorname{erf}(\\eta)=\\Theta(0)+C\\operatorname{erf}\\left( \\frac{x}{2\\sqrt{Dt}} \\right)$$\r\nwhere $C$ is a constant and $\\operatorname{erf}$ is the error function defined by\r\n$$\\operatorname{erf}(z)=\\frac{2}{\\sqrt{\\pi}}\\int_0^ze^{-u^2}\\,\\mathrm du$$\r\nThis can describes discontinuous initial conditions (e.g. step functions) that spreads over time.\r\n\\subsection{Heat Conduction in a Finite Bar}\r\nSuppose we have a bar of length $2L$ at $[-L,L]$ and initial temperature\r\n$$\\Theta(x,0)=H(x)=\\begin{cases}\r\n    1\\text{, for $x\\in [0,L]$}\\\\\r\n    0\\text{, for $x\\in [-L,0)$}\r\n\\end{cases}$$\r\nwith boundary conditions $\\Theta(L,t)=1,\\Theta(-L,t)=0$.\r\nWe want to use Sturm-Liouville theory, but there is a problem here:\r\nOur boundary conditions is not homogeneous.\r\nSo we must make the condition homogeneous by a suitable superposition.\r\nBut there is an obvious choice of this, namely $\\Theta_s(x,t)=(x+L)/(2L)$.\r\nTherefore we with a transformation $\\hat\\Theta=\\Theta-\\Theta_s$ the problem becomes\r\n$$\\frac{\\partial\\hat\\Theta}{\\partial t}=D\\frac{\\partial^2\\hat\\Theta}{\\partial x^2},\\hat\\Theta(-L,t)=\\hat\\Theta(L,t)=0,\\hat\\Theta(x,0)=H(x)-\\frac{x+L}{2L}$$\r\nNow we do seperation of variables $\\hat\\Theta(x,t)=X(x)T(t)$, which gives $X^{\\prime\\prime}=-\\lambda X,\\dot{T}=-D\\lambda T$ where $\\lambda$ is the seperation constant.\r\nThe boundary conditions imply that $\\lambda>0$ and\r\n$$X(x)=A\\cos{\\sqrt{\\lambda}x}+B\\sin(\\sqrt{\\lambda}x)$$\r\nwhere $A,B$ are constants.\r\nThe initial condition is odd, so $A=0$ and consequently the eigenvalues are $\\lambda_n=(n\\pi/L)^2$ for $n=1,2,3,\\ldots$, so we obtained the family of solutions\r\n$$X_n=B_n\\sin\\frac{n\\pi x}{L},\\lambda_n=\\frac{n^2\\pi^2}{L^2},n=1,2,3,\\ldots$$\r\nPut $\\lambda_n$ in the temporal equation gives\r\n$$T_n(t)=C_n\\exp\\left( -\\frac{Dn^2\\pi^2}{L^2}t \\right)$$\r\nSo\r\n$$\\hat\\Theta(x,t)=\\sum_{n=1}^\\infty b_n\\sin\\left(\\frac{n\\pi x}{L}\\right)\\exp\\left( -\\frac{Dn^2\\pi^2}{L^2}t \\right)$$\r\nNow we impose initial conditions at $t=0$ which gives\r\n\\begin{align*}\r\n    b_n&=\\frac{1}{L}\\int_{-L}^L\\hat\\phi(x,0)\\sin\\frac{n\\pi x}{L}\\,\\mathrm dx\\\\\r\n    &=\\frac{2}{L}\\int_0^L\\hat\\phi(x,0)\\sin\\frac{n\\pi x}{L}\\,\\mathrm dx\\\\\r\n    &=\\frac{2}{L}\\int_0^L\\left( H(x)-\\frac{x+L}{2L} \\right)\\sin\\frac{n\\pi x}{L}\\,\\mathrm dx\\\\\r\n    &=\\frac{2}{L}\\int_0^L\\left( H(x)-\\frac{1}{2} \\right)\\sin\\frac{n\\pi x}{L}\\,\\mathrm dx-\\frac{2}{L}\\int_0^L\\frac{x}{2L}\\sin\\frac{n\\pi x}{L}\\,\\mathrm dx\\\\\r\n    &=\\begin{cases}\r\n        2/[(2m-1)\\pi]-1/(n\\pi)\\text{, for $n=2m-1$ odd}\\\\\r\n        1/n\\pi\\text{, for $n$ even}\r\n    \\end{cases}\\\\\r\n    &=\\frac{1}{n\\pi}\r\n\\end{align*}\r\nTherefore we get the final solution\r\n$$\\Theta(x,t)=\\frac{2+L}{2L}+\\hat\\Theta(x,t)=\\frac{x+L}{2L}+\\sum_{n=1}^\\infty \\frac{1}{n\\pi}\\sin\\left(\\frac{n\\pi x}{L}\\right)\\exp\\left( -\\frac{Dn^2\\pi^2}{L^2}t \\right)$$\r\nA plot reveals that this solution is very similar to the similarity solution we got earlier especially for small $t$.", "meta": {"hexsha": "f191b57d027f0ac094a9a55a41caf06fb524494c", "size": 6479, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/diffuse.tex", "max_stars_repo_name": "david-bai-notes/IB-Methods", "max_stars_repo_head_hexsha": "b60135106d09d1e24d2f7b9c7e3eee1ca69f6907", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4/diffuse.tex", "max_issues_repo_name": "david-bai-notes/IB-Methods", "max_issues_repo_head_hexsha": "b60135106d09d1e24d2f7b9c7e3eee1ca69f6907", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4/diffuse.tex", "max_forks_repo_name": "david-bai-notes/IB-Methods", "max_forks_repo_head_hexsha": "b60135106d09d1e24d2f7b9c7e3eee1ca69f6907", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 76.2235294118, "max_line_length": 299, "alphanum_fraction": 0.667695632, "num_tokens": 2321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.8705972600147106, "lm_q1q2_score": 0.7254901237964636}}
{"text": "\\section{Hamilton's Principle of Least Action}\n3 equivalent formulations\n\\begin{itemize}\n    \\item Newton's laws\n    \\item Lagrange's equation\n    \\item Hamiton's principle\n\\end{itemize}\nLet us generalize to non-Cartesian coordinates\n\\begin{align}\n    \\left( x, y, z \\right) \\to \\left( q_1, q_2, q_3 \\right)\n\\end{align}\nFor example, $(q_1, q_2, q_3)$\ncould be\n$(r, \\theta, \\phi)$\nor\n$(\\rho, \\phi, z)$.\n\nNecessary that each position $\\vec{r}$\nuniquely specifies $(q_1, q_2, q_3)$\n\\begin{align}\n    q_i &= q_i(x, y, z)\\\\\n    \\vec{r} &= \\vec{r}\\left( q_1, q_2, q_3 \\right).\n\\end{align}\nWe can rewrite $x,y,z$\nand also\n$\\dot{x},\\dot{y},\\dot{z}$\nin terms of the\n$q_1,q_2,q_3$\nand\n$\\dot{q}_1,\\dot{q}_2,\\dot{q}_3$.\nThen\n\\begin{align}\n    L &=\n    \\frac{1}{2}m\\dot{\\vec{r}}^2 - U(\\vec{r})\n    = L(q_i, \\dot{q}_i)\n\\end{align}\nLet's write the action integral\n\\begin{align}\n    S &=\n    \\int_{t_1}^{t_2} dt\\,\n    L\\left( q_i, \\dot{q}_i \\right).\n\\end{align}\nLet's draw the picture again.\n\nThe value of the action integral for every single coordinate system,\nso the action is minimized for all paths.\nIt's going to be the same path in the extremum value.\nAnd so that means $L$ will satisfy an Euler-Lagrange equation in these\ncoordinates.\n\nThe value of $L$ at any point and therefore the integral $S$ for any path is\nunaltered by the change of variables.\nThus it must be true that $S$ is stationary at the correct path even in the new\ncoordinates system.\nThis implicitly implies that the Euler-Lagrange equations\n\\begin{align}\n    \\frac{d}{dt}\\left( \\frac{\\partial L}{\\partial \\dot{q}_i} \\right)\n    - \\frac{\\partial L}{\\partial q_i} &= 0\n\\end{align}\nholds for any set of generalized coordaintes.\n\n\\section{Generalized Force and Momentum}\nforce a particle in 1D,\n\\begin{align}\n    L &= \\frac{1}{2} m\\doc{x}^2 - U(x)\n\\end{align}\nand\n\\begin{align}\n    \\frac{d}{dt}\\underbrace{%\n        \\left(\n            \\frac{\\partial L}{\\partial \\dot{x}}\n        \\right)\n    }_{m\\dot{x} = p}\n    =\n    \\underbrace{%\n        \\frac{\\partial L}{\\partial x}\n    }_{%\n        -\\frac{\\partial U}{\\partial x}\n    }\n\\end{align}\nSo that gives\n\\begin{align}\n    \\frac{dp}{dt} &= -\\frac{\\partial U}{\\partial x}.\n\\end{align}\nSo in general.\n\\begin{align}\n    \\text{generalized momentum} &:= \\frac{\\partial L}{\\partial \\dot{q}_i}\\\\\n    \\text{generalized force} &:= \\frac{\\partial L}{\\partial q_i}.\n\\end{align}\nThe Euler-Lagrange equation says that\nthe rate of change of generalized momentum equals the generalized force.\n\n\\begin{example}[Single particle in polar coordinates]\n    The kinetic energy is\n    \\begin{align}\n        T &= \\frac{1}{2}mv^2 =\n        \\frac{1}{2} m\\left( \\dot{r}^2 + r^2 \\dot{\\phi}^2 \\right)\n    \\end{align}\n    and the Lagrangian is\n    \\begin{align}\n        L &= T - U\\\\\n        &=\n        \\frac{1}{2}m\\left( \\dot{r}^2 + r^2\\dot{\\phi}^2 \\right)\n        - U(r, \\phi)\n    \\end{align}\n\\end{example}\nThen the Euler-Lagrange equation is\n\\begin{align}\n    \\frac{d}{dt}\n    \\underbrace{%\n        \\left(\n            \\frac{\\partial L}{\\partial\\dot{r}}\n        \\right)\n    }_{%\n        m\\dot{r}\n    }\n    =\n    \\underbrace{%\n        \\frac{\\partial L}{\\partial r}\n    }_{%\n        -\\frac{\\partial U}{\\partial r} + mr\\dot{\\phi}^2\n    }\n\\end{align}\nwhich leads to the radial equation of motion.\n\\begin{align}\n    m\\underbrace{\\ddot{r}}_{\\text{radial acceleration}}\n    - \\underbrace{m r\\dot{\\phi}^2}_{\\text{centripetal force}}\n    &=\n    \\underbrace{- \\frac{\\partial U}{\\partial r}}_{%\n        \\text{radial component of force}\n    }\n\\end{align}\nThen the angular equation of motion is\n\\begin{align}\n    \\frac{d}{dt}\\underbrace{%\n        \\left(\n            \\frac{\\partial L}{\\partial\\dot{\\phi}}\n        \\right)\n    }_{mr^2\\dot{\\phi}}\n    &=\n    \\underbrace{\\frac{\\partial L}{\\partial \\phi}}_{\n        -\\frac{\\partial U}{\\partial \\phi}\n    }\n\\end{align}\nso you get\n\\begin{align}\n    \\frac{d}{dt}\\underbrace{\\left( mr^2\\dot{\\phi} \\right)}_{\\text{angular\n    momentum}}\n    &=\n    \\underbrace{- \\frac{\\partial U}{\\partial \\phi}}_{r F_{\\phi}=\\text{torque}}\n\\end{align}\nThen the force is\n\\begin{align}\n    \\vec{F} = - \\vec{\\nabla} U\n    = -\\frac{\\partial U}{\\partial r} \\hat{e}_r\n    - \\frac{1}{r} \\frac{\\partial U}{\\partial \\phi} \\hat{e}_\\phi\n\\end{align}\n\n\\section{Constrained system}\nConsider a pendulum of length $l$.\nThe position is given by $(x,y)$\nbut there is a constraint\n\\begin{align}\n    \\sqrt{x^2 + y^2} &= l.\n\\end{align}\nSo you only need one degree of freedom.\n\nThe system only has one degree of freedom because location of bob is specified\nonce we know the value of $x$.\nAlternatively,\nlocation is specified by the value of generalized coordinate $\\theta$.\n\nThe coordinate transform is\n\\begin{align}\n    x &= l \\sin\\theta\\\\\n    y &= l \\cos\\theta.\n\\end{align}\n\nThe kinetic energy is\n\\begin{align}\n    T &= \\frac{1}{2}m \\left( \\dot{x}^2 + \\dot{y}^2 \\right)\\\\\n    &= \\frac{1}{2}m l^2 \\dot{\\theta}^2\n\\end{align}\nand the potential energy\nis\n\\begin{align}\n    U &= mgl(1 - \\cos\\theta)\n\\end{align}\nThen the Lagrangian is\n\\begin{align}\n    L &= T - U\\\\\n    &= \\frac{1}{2} ml^2 \\dot{\\theta}^2\n    - mgl(1 - \\cos\\theta)\n\\end{align}\nThe Euler-Lagrange equation is\n\\begin{align}\n    \\frac{d}{dt}\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}} \\right)\n    -\n    \\frac{\\partial L}{\\partial \\theta} = 0\n\\end{align}\nwhich gives the equation of motion\n\\begin{align}\n    ml^2\\ddot{\\theta} + mgl\\sin\\theta &= 0\\\\\n    \\ddot{\\theta} + \\frac{g}{l}\\sin\\theta &= 0.\n\\end{align}\n\n\\section{Generalized Coordinates for a Constrained System}\nWe say that the parameters\n$q_1,q_2,\\ldots,q_n$ are generalized coodrinates for the system of\n$N$ particles\n$\\alpha = 1,2,\\ldots,N$\nwith psoitions $\\vec{r_}_{\\alpha}$\nif\n\\begin{enumerate}\n    \\item Each position $\\vec{r}_{\\alpha}$ can be expanded as a function of\n        $\\left( q_1,q_2,\\ldots,q_n \\right)$\n        and (possibly) $t$.\n        \\begin{align}\n            \\vec{r}_{\\alpha} &=\n            \\left( q_1, q_2, \\ldots, q_n, t \\right)\n        \\end{align}\n        for $\\alpha = 1,2,\\ldots,N$.\n    \\item Each $q_i$ can e expressed in terms of the $\\vec{r}_{\\alpha}$\n        and (possibly) $t$.\n        \\begin{align}\n            q_i &= q_i\\left( \\vec{r}_1, \\vec{r}_2,\\ldots,\\vec{r}_N, t \\right)\n        \\end{align}\n    \\item The number of generazed coordinates is the smallest number that allows\n        the system to be parameterized in this way\n        \\begin{align}\n            n &= 3N & \\text{for unconstrained system}\\\\\n            n &< 3N & \\text{for constrained system}\n        \\end{align}\n\\end{enumerate}\n\\begin{example}[Double pendulum]\n    There is a pivot point to which a rigid bar of length $l_1$ is free to\n    swing,\n    at the end of which is a mass $m_1$.\n    It makes an anble $\\phi_1$ with the veritical.\n    Another rigid bar is attached to where $m_2$ is,\n    but is also free to swing,\n    of length $l_2$ which makes an anble $\\phi_2$ with the vertical,\n    at the end of which is a mass $m_2$.\n\\end{example}\nThe position of the first mass is\n\\begin{align}\n    \\vec{r}_1 &= \\vec{r}_1(\\phi_1)\\\\\n    \\vec{r}_2 &= \\vec{r}_2(\\phi_1, \\phi_2)\n\\end{align}\n", "meta": {"hexsha": "3ba66e973f09f756e19ee3a44212eac0ad9b48a9", "size": 7065, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys610/lecture12.tex", "max_stars_repo_name": "ehua7365/umdphysnotes", "max_stars_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-11T12:53:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-11T12:53:46.000Z", "max_issues_repo_path": "phys610/lecture12.tex", "max_issues_repo_name": "ehua7365/umdphysnotes", "max_issues_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "phys610/lecture12.tex", "max_forks_repo_name": "ehua7365/umdphysnotes", "max_forks_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.26, "max_line_length": 80, "alphanum_fraction": 0.6198159943, "num_tokens": 2416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245787544825, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.7254901019612006}}
{"text": "\\section{Composition of transformations}\n\n\n\n%-------------------------------------------------------------------------------------------\n\\subsection{Order of composition}\n\\label{subsec:tools:composition:order}\n\nLet us consider two images $I_F$ and $I_M$ (resp. fixed and moving images). We want to register $I_M$ to $I_F$ and a common way to do it is to apply successively different registration methods. In this example, we use three registration methods (e.g. rigid, affine, and non-linear). First, we apply the first registration method between images $I_F$ and $I_M$. We obtain a transformation (form the fixed to the moving image) $T_1$ and an image $I_1$ ($I_M$ re-sampled in the geometry of $I_F$):\n\n\\begin{equation}\n\\textrm{method}_1(I_F,I_M) \\rightarrow \\{T_1,I_1\\}\n\\end{equation}\n\nThen we apply the second registration method between images $I_F$ and $I_1$. By considering the image $I_1$ instead of $I_M$, we initialize the registration process by starting the algorithm \\textit{closer} to the optimal transformation. We obtain a transformation $T_2$ and an image $I_2$ ($I_1$ re-sampled in the geometry of $I_F$):\n\n\\begin{equation}\n\\textrm{method}_2(I_F,I_1) \\rightarrow \\{T_2,I_2\\}\n\\end{equation}\n\nFinally, we apply the third registration method between images $I_F$ and $I_2$. We obtain a transformation $T_3$ and an image $I_3$ ($I_2$ re-sampled in the geometry of $I_F$):\n\n\\begin{equation}\n\\textrm{method}_3(I_F,I_2) \\rightarrow \\{T_3,I_3\\}\n\\end{equation}\n\nIf we assume that the successive registration processes improved the image registration, the image $I_3$ should be the image the most similar to $I_F$, then $I_2$, $I_1$, and finally $I_M$. An important issue here is that $I_3$ is the result of three consecutive re-samplings of the initial moving image $I_M$. In order to avoid the multiple approximations due to these re-samplings, one may want to re-sample only once $I_M$ using the global transformation from $I_F$ to $I_M$. However, this global transformation is not $T_3$ but the composition of $T_1$, $T_2$, and $T_3$. Indeed, $T_3$ is the transformation from $I_F$ to $I_2$ ; the image $I_M$ re-sampled using $T_3$ is probably not correctly registered onto $I_F$.\n\\\\\n\nLet us consider the image re-sampling of $I_M$ using $T_1$. Let $\\mathbf{x}=(x,y,z)$ be a point (in the real world coordinates) in the real grid of the fixed image. The re-sampling is defined as:\n\n\\begin{equation}\nI_1(\\mathbf{x}) = I_M(T_1(\\mathbf{x}))\n\\end{equation}\n\nNow, let us now consider the image re-sampling of $I_1$ using $T_2$:\n\n\\begin{align}\nI_2(\\mathbf{x}) & = I_1(T_2(\\mathbf{x})) \\\\\n                & = I_M(T_1(T_2(\\mathbf{x}))\n\\end{align}\n\nFinally, we re-sample $I_2$ using $T_3$:\n\n\\begin{align}\nI_3(\\mathbf{x}) & = I_2(T_3(\\mathbf{x})) \\\\\n                & = I_1(T_2(T_3(\\mathbf{x})) \\\\\n                & = I_M(T_1(T_2(T_3(\\mathbf{x}))) \\\\\n                & \\triangleq I_M( T_1 \\circ T_2 \\circ T_3(\\mathbf{x}) ) \\label{eq:composition}\n\\end{align}\n\nEq.~\\ref{eq:composition} shows that the global transformation allowing to re-sample the image $I_M$ onto $I_F$ using a single global transformation $T$ which is the composition of $T_1$, $T_2$, and $T_3$:\n\n\\begin{equation}\nT = T_1 \\circ T_2 \\circ T_3\n\\end{equation}\n\n\n\n%-------------------------------------------------------------------------------------------\n\\subsection{Composing transformations using \\texttt{rpiFuseTransformation}}\n\nThe \\texttt{rpiFuseTransformation} executable is a program that allow to fuse (compose) a list of transformation into a unique transformation. Since it is not possible yet -- at least in a general case -- to store a list of transformations into a single file, we propose to store the list as a XML file. This XML lists the type of each transformation and the path to the files containing the transformations :\n%\n\\begin{lstlisting}\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<listoftransformations>\n\n    <transformation>\n        <type>linear</type>\n        <path>t0.txt</path>\n        <invert>1</invert>\n    </transformation>\n\n    <transformation>\n        <type>displacementfield</type>\n        <path>t1.nii.gz</path>\n        <invert>0</invert>\n    </transformation>\n\n</listoftransformations>\n\\end{lstlisting}\n%\n\nIn this example, we have 2 transformations. The first one (denoted $T_0$) is a linear transformation stored into the text file ``t0.txt''. The second transformation (denoted $T_1$) is a displacement field stored into the -- image -- file ``t1.nii.gz''. The computed transformation is given by $T_0 \\circ T_1$. Thus, the order the transformations written into the XML file is important since the composition of two transformations is usually not commutative (see section~\\ref{subsec:tools:composition:order}). The XML file can contain any strictely positive number of transformations. The meaning of the different tags is:\n%\n\\begin{itemize}\n%\n\\item Tag \\texttt{<listoftransformations>} contains a set of transformations. This tag is mandatory.\n%\n\\item Tag \\texttt{<transformation>} contains a transformation. This tag must be an element of the tag \\texttt{<listoftransformations>}. This tag is mandatory.\n%\n\\item Tag \\texttt{<type>} contains the type of the considered transformation. The available types are ``linear'', ``displacemendfield'', and ``stiaionaryvelocityfield''. This tag must be an element of the tag \\texttt{<transformation>}. This tag is mandatory.\n%   \n\\item Tag \\texttt{<path>} contains the path to the file containing the transformation. A displacement field or a stationary velocity field must be stored into an image file (e.g. Nifty, Analyse, etc.). This tag must be an element of the tag \\texttt{<transformation>}. This tag is mandatory.\n%\n\\item Tag \\texttt{<invert>} indicates if the considered transformation has to be inverted before the fusion. The value ``1'' induces the transformation inversion ; the value ``0'' means no inversion. This tag is optional. By default, no inversion is performed.\n%\n\\end{itemize}\n%\nThe type of the output transformation depends on the transformations of the list. A list of linear transformations will be fused into a linear transformation. If the list contains at least one displacement field, the output transformation will be a displacement field. If the option \"--force-displacement-field\" is used, the ouput transformation will be a displacement field.\nFor now on, if the list contains linear transformations and stationary velocity fields, the computed transformation will be a displacement field. However, this will change in the near future in order to compute a unique stationary velocity field (thanks to Marco Lorenzi).\n\\\\\nOne should choose the output file extension according to the transformation computed. Indeed, if the output transformation is a displacement field, only image format are supported (e.g. .nii). No checking on the file extension will be performed since the output transformation type is easily predictable.\n\n\n", "meta": {"hexsha": "16e9a25c352f590120445a50f78a90c627c0a5c2", "size": 6912, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/chap_registration_composition.tex", "max_stars_repo_name": "nzemzemi/RPI", "max_stars_repo_head_hexsha": "aaf34a1ae801f5fc35833e4c21df12a4d16658f4", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/chap_registration_composition.tex", "max_issues_repo_name": "nzemzemi/RPI", "max_issues_repo_head_hexsha": "aaf34a1ae801f5fc35833e4c21df12a4d16658f4", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-07-15T11:50:23.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-15T13:17:07.000Z", "max_forks_repo_path": "doc/chap_registration_composition.tex", "max_forks_repo_name": "nzemzemi/RPI", "max_forks_repo_head_hexsha": "aaf34a1ae801f5fc35833e4c21df12a4d16658f4", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2015-07-02T21:05:06.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-04T15:43:14.000Z", "avg_line_length": 64.0, "max_line_length": 721, "alphanum_fraction": 0.7220775463, "num_tokens": 1797, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.7254660477857431}}
{"text": "\\chapter{Probability Distributions \\label{chapter:probabilitydistributions}}\n\nMany of the methods we will examine in these workshops depend on basic concepts from probability theory. For example, linear and logistic regression are members of a class of supervised learning algorithms called \\textbf{generalized linear models} (see Chapter~\\ref{chapter:glms}) which make assumptions about the type of probability distribution followed by the outcome variable. Decision trees use a concept called \\textbf{entropy} (see Chapter~\\ref{chapter:decisiontrees}), whose mathematical formulation depends on the probability distribution underlying the outcome. Many \\textbf{hypothesis tests} (see Chapter~\\ref{chapter:hypothesistesting}) likewise rely on probabilistic assumptions about the data. Probability is everywhere.\n\nThe following sections review some key probability concepts -- in an extremely hand-wavey and non-rigorous way -- and the properties of some of the most common probability distributions you will encounter in machine learning and statistics. \n\n\\section{Definitions}\n\nA \\textbf{probability distribution} is just a mathematical function that provides the relative likelihoods of various possible outcomes of an observation. We call the quantity that is being observed a \\textbf{random variable}. Probability distributions can be discrete or continuous. The random variable involved can be a number, a vector of numbers, a category/class, etc. The \\textbf{sample space} is the set of all possible outcomes. The integral (or sum) of the probability distribution over the entire sample space is $1.0$. You will often hear probability distributions for continuous random variables referred to as \\textbf{probability densities}. \n\nProbability distributions are grouped into families that are characterized by their overall shapes. These families contain \\textbf{parameters} that, when varied, produce different distributions. Specific probability distributions from within a single family can often look quite different. \n\nWe use the notation $E[x|\\theta]$ to refer to the \\textbf{expected value}, or mean, of a distribution, given its parameter(s), $\\theta$. There can be more than one parameter, and it will not always be called $\\theta$; this is just an example. We use the notation $\\text{var}(x|\\theta)$ to refer to the \\textbf{variance}, or spread, of a distribution around its mean. \n\n\\section{Normal Distribution \\label{sect:normal}} \n\nAlso called the \\textbf{Gaussian distribution}, the normal distribution is probably the most well-known continuous probability distribution. It has the following properties:\n\\begin{equation*} p(x | \\mu, \\sigma) = \\frac{1}{\\sqrt{2 \\pi \\sigma^2}} e^{-\\frac{(x-\\mu)^2}{2 \\sigma^2}} \\qquad  E[x| \\mu, \\sigma] = \\mu \\qquad \\text{var}(x | \\mu, \\sigma) = \\sigma^2 \\end{equation*}\nwhere $x \\in \\mathbb{R}$. We will abbreviate the normal distribution as $\\mathcal{N}(\\mu, \\sigma)$.  The value of $\\mu$ changes the position of the center of the normal distribution.\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{img/l01-figure1-normal-mean-change.png}\n\\end{center}\nThe value of $\\sigma$ changes the width of the normal distribution.\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{img/l01-figure2-normal-sd-change.png}\n\\end{center}\n\n\\begin{question}{question:normalex}\nList 5 random variables from medicine or biology that should follow normal distributions.\n\\end{question}\n \n\n\\section{Bernoulli Distribution \\label{sect:bernoulli}}\n\nThe \\textbf{Bernoulli distribution} is a discrete probability distribution with the following properties:\n$$ p(x|\\mu) = \\mu^x (1 - \\mu) ^ {1-x} \\qquad E[x| \\mu] = \\mu \\qquad \\text{var}(x | \\mu) = \\mu (1 - \\mu) $$\nwhere $x \\in \\{0, 1\\}$. It is used to model events where the outcome is yes/no. Think of it as a weighted coin, with $\\mu$ the probability that the coin comes up ``heads'' on a single toss. Here are three Bernoulli distributions with (from left to right) $\\mu = 1.0, 0.7, 0.2$. The number along the bottom is $x$, which can only be $0$ or $1$. \n\\begin{center}\n\\includegraphics[width=0.3\\textwidth]{img/l01-figure2a-bernoulli-1-0.png}\n\\includegraphics[width=0.3\\textwidth]{img/l01-figure2b-bernoulli-0-7.png}\n\\includegraphics[width=0.3\\textwidth]{img/l01-figure2c-bernoulli-0-2.png}\n\\end{center}\n\nThe \\textbf{categorical distribution} is a generalization of the Bernoulli distribution to an outcome with more than two levels. The categorical distribution looks like this:\n$$ p(x|\\phi_1, \\dots, \\phi_K) = \\phi_1^{\\mathbb{I}(x=1)} \\phi_2^{\\mathbb{I}(x=2)} \\cdots \\phi_K^{\\mathbb{I}(x=K)} $$\nwhere $\\sum_{k=1}^K \\phi_k = 1$. The term $\\mathbb{I}(x=j)$ is an \\textbf{indicator}. It equals 1 if $x=j$ and 0 otherwise. For example, $\\mathbb{I}(x=2)$ is 1 if $x=2$ and 0 otherwise. \n\n\\begin{question}{}\nList 5 random variables from medicine or biology that should follow Bernoulli distributions.\n\\end{question}\n\n\n\\section{Binomial Distribution \\label{sect:binomial}}\n\nThe \\textbf{binomial distribution} models the number of positive outcomes, $x$, out of $n$ independent\\footnote{The word \\textbf{independent} just means that the outcome of one trial does not influence the outcome of any other trial.} Bernoulli trials, each of which is positive with probability $\\mu$. This distribution has the following properties, with $x \\in \\{0, \\dots, n\\}$:\n$$ p(x|n,\\mu) = {n\\choose x} \\mu^x (1 - \\mu) ^ {n-x} \\qquad E[x| \\mu] = n \\mu \\qquad \\text{var}(x | \\mu) = n \\mu (1 - \\mu) $$\nwhere the notation ${n \\choose x}$ is defined as:\n$$ {n \\choose x} = \\frac{n!}{x!(n-x)!}. $$\nThis notation denotes the number of ways it is possible to choose $x$ things out of a group of $n$ things, where the ordering doesn't matter. The exclamation point denotes the \\textbf{factorial function}: $x! = x(x-1)(x-2)\\cdots(2)(1)$. \n\nThe shape of the binomial distribution is governed by the values of $n$ and $\\mu$. Here, we vary $n$ but keep $\\mu$ constant at $0.5$:\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{img/l01-figure3-binom-n-change.png}\n\\end{center}\nAnd here we vary $\\mu$ but keep $n$ constant at $50$:\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{img/l01-figure4-binom-p-change.png}\n\\end{center}\n\n\\begin{question}{question:binomialex}\nList 5 random variables from medicine or biology that should follow binomial distributions.\n\\end{question}\n\n\n\\section{Poisson Distribution \\label{sect:poisson}}\n\nThe \\textbf{Poisson distribution} is a probability distribution that is often used to model discrete quantitative data, such as counts. It has the following properties:\n$$ p(x | \\lambda) = \\frac{e^{-\\lambda} \\lambda^x}{x!} \\qquad E[x|\\lambda] = \\lambda \\qquad \\text{var}(x|\\lambda) = \\lambda $$\nwhere $x \\in \\left\\{0, 1, 2, \\dots \\right\\}$. Below are four examples of Poisson distributions. If events of a particular type occur continuously and independently at a constant rate (\\textbf{Poisson process}), the number of events within a time window of fixed width will be distributed according to the Poisson distribution, with rate parameter $\\lambda$ proportional to the width of the window.\n\nSituations where the population size, $n$, is large, the probability of an individual event, $p$, is small, but the expected number of events, $np$, is moderate (say five or more) can generally be modeled using a Poisson distribution with $\\lambda = np$. \n\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{img/l01-figure3a-poisson-lambda-change.png}\n\\end{center}\n\n\\begin{question}{question:poissonex}\nList 5 random variables from medicine or biology that should follow Poisson distributions.\n\\end{question}\n\n\n\\section{Geometric \\label{sect:geometric}}\n\nThe \\textbf{geometric distribution} models the number of failures in a sequence of Bernoulli trials before the first success. It has the following properties:\n$$ p(x|\\mu) = (1-\\mu)^x \\mu \\qquad E[x|\\mu] = \\frac{1-\\mu}{\\mu} \\qquad \\text{var}(x|\\mu) = \\frac{1-\\mu}{\\mu^2}  $$\nfor $x \\in \\left\\{0, 1, 2, \\dots \\right\\}$, where $\\mu$ refers to the probability (in the Bernoulli trial) that the trial is a success. Some examples of geometric distributions with different $\\mu$ are shown below: \n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{img/l01-figure4-geometric-mu-change.png}\n\\end{center}\n\n\\begin{question}{question:geometricex}\nList 5 random variables from medicine or biology that should follow geometric distributions.\n\\end{question}\n\n\n\\section{Exponential \\label{sect:exponential}}\n\nThe \\textbf{exponential distribution} is a continuous probability distribution that models waiting times between events that happen independently and continuously at a constant rate (Poisson process), as well as many other random variables\\footnote{For example, in an epidemiologic model of an infectious process like COVID-19 community spread, exponential waiting times are often used to model transitions between the susceptible, exposed, infectious, and recovered compartments in the model.}. It has the following properties:\n$$ p(x|\\lambda) = \\lambda e^{-\\lambda x} \\qquad E[x|\\lambda] = \\frac{1}{\\lambda} \\qquad \\text{var}(x|\\lambda) = \\frac{1}{\\lambda^2} $$\nwhere $x \\in \\mathbb{R}^+$ ($x$ is a positive real number, or zero). The exponential distribution is the continuous analogue of the geometric distribution. It is memoryless, which means that the distribution of a waiting time until an event does not depend on how much time has elapsed already.\n\nHere are some different exponential distributions. Compare them to the geometric distribution, above.\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{img/l01-figure5-exponential-lambda-change.png}\n\\end{center}\n\n\\begin{question}{question:exponentialex}\nList 5 random variables from medicine or biology that should follow exponential distributions.\n\\end{question}\n\n\n\\section{Chi-Squared Distribution \\label{sect:chisqdist}}\n\nHow this distribution arises:\n\\begin{enumerate}\n\\item If $Z \\sim \\mathcal{N}(0, 1)$, the distribution of $U = Z^2$ is called the chi-squared distribution with one degree of freedom.\n\\item If $U_1, U_2, \\dots, U_k$ are independent $\\chi_1^2$ random variables, their sum,\n$ V = \\sum_{i=1}^k U_i $\nfollows $\\chi_k^2$, a chi-squared distribution with $k$ degrees of freedom.\n\\end{enumerate}\n\nYou'll often see the chi-squared distribution used as the sampling distribution for the sample variance in a variety of statistical hypothesis tests. It looks like this:\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{img/hyp-example-chisq-distribution.png}\n\\end{center}\n\nThe parameter $k$, the \\textbf{degrees of freedom}, controls the shape of the chi-squared distribution. The actual formula for the chi-squared distribution looks a bit intimidating, but I'm including it here so you can compare it to the other distributions we've seen:\n$$ p(x|k) = \\frac{1}{2^{k/2} \\Gamma(k/2)} x^{k/2 - 1} e^{-x/2} $$\n$$ E[x | k] = k \\qquad \\text{var}(x | k) = 2k $$ \nThe gamma function shown in the denominator of the probability density,\n$$ \\Gamma(z) = \\int_0^{\\infty} x^{z-1} e^{-x} dx, $$\nis a generalization of the factorial function to complex numbers. For any positive integer $n$, $\\Gamma(n) = (n-1)!$. \n\n\\section{Student's T Distribution \\label{sect:tdist}}\n\nIf $Z \\sim \\mathcal{N}(0, 1)$ and $U \\sim \\chi_k^2$ and $Z$ and $U$ are independent, \n$$ T = \\frac{Z}{\\sqrt{U/k}} \\sim t_k $$\nor in words, the statistic $T$ follows a $t$-distribution with $k$ degrees of freedom. The T distribution plays an important role in a family of statistical hypothesis tests called T-tests. \n\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{img/hyp-example-t-distribution.png}\n\\end{center}\n\nAgain, the functional form of the T distribution is a bit intimidating, but I'm including it for completeness:\n\n$$ p(x|k) = \\frac{\\Gamma \\left(\\frac{k+1}{2} \\right)} {\\sqrt{k\\pi}\\,\\Gamma \\left(\\frac{k}{2} \\right)} \\left(1+\\frac{x^2}{k} \\right)^{-\\frac{k+1}{2}} $$\n$$ E[x|k] = 0~~\\text{ for }k>1; \\text{ otherwise undefined} $$\n$$ \\text{var}(x|k) = \\left\\{ \\begin{array}{cl} \\frac{k}{k-2} & k>2 \\\\\n                                               \\infty & 1 < k \\leq 2 \\\\\n                                               \\text{undefined} & \\text{otherwise} \\end{array} \\right. $$\n\n\\section{F Distribution \\label{sect:fdist}}\n\nIf $U$ and $V$ are independent $\\chi^2$ random variables with $m$ and $n$ degrees of freedom,\n$$ W = \\frac{U/m}{V/n} \\sim F_{m, n} $$\nor in words, the statistic $W$ follows an $F$ distribution with $m$ and $n$ degrees of freedom. I'm not writing out the functional form of the F distribution here because it's too awful-looking, but graphically it looks like this:\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{img/hyp-example-f-distribution.png}\n\\end{center}\n\nNote that if $T \\sim t_k$, then $T^2 \\sim F_{1,k}$. The $F$-distribution plays an important role in a class of statistical analysis techniques called \\textbf{ANalysis Of VAriance}, or \\textbf{ANOVA}.\n\n\\vspace{2mm}\n\n\\begin{question}{question:likexamples}\nFor each of the following experimental conditions, which distribution (from those listed above) provides the best model for how the data $x^{(1)},\\dots,x^{(n)}$ are generated?\n    \\begin{enumerate}\n    \\item[(a)] You are observing several patients' skin in a clinical study to see how long it takes them to develop a rash. You take a picture each day. Let $x^{(i)}$ be the number of days of \\emph{no rash} before the rash occurs.\n\n\\begin{center}{\\small\n\\begin{tabular}{cc}\n\\toprule\nPatient ID ($i$) & $x^{(i)}$ \\\\\n\\midrule\n1 & 4 \\\\\n2 & 1 \\\\\n3 & 0 \\\\\n4 & 2 \\\\\n5 & 2 \\\\\n6 & 4 \\\\\n7 & 3 \\\\\n8 & 1 \\\\\n9 & 0 \\\\\n10 & 1 \\\\\n\\end{tabular}}\n\\end{center}\n\n    \\item[(b)] Same situation as above except that instead of taking a picture each day, the patient texts you at the moment he/she observes a rash. The data look like this, where $x^{(i)}$ is the time (in days) at which patient $i$ develops a rash: \n\n\\begin{center}{\\small\n\\begin{tabular}{cc}\n\\toprule\nPatient ID ($i$) & $x^{(i)}$ \\\\\n\\midrule\n1 & 2.25 \\\\\n2 & 3.43\\\\\n3 & 0.68\\\\\n4 & 0.04\\\\\n5 & 3.78\\\\\n6 & 5.65\\\\\n7 & 2.88\\\\\n8 & 3.88\\\\\n9 & 2.83\\\\\n10 & 1.87\\\\\n\\end{tabular}}\n\\end{center}\n \n    \\item[(c)] Imagine you are Ladislaus Bortkiewicz, and you are modeling the number of persons killed by mule or horse kicks in the Prussian army per year. You have data from the late 1800s over the course of 20 years. Let $x^{(i)}$ be the number of people killed in year $i$.\n        \n\\begin{center}{\\small\n\\begin{tabular}{cc|cc}\n\\toprule\nYear ($i$) & $x^{(i)}$ & Year ($i$) & $x^{(i)}$ \\\\\n\\midrule\n1 & 8 & 11 & 9 \\\\\n2 & 10 & 12 & 7 \\\\\n3 & 5 & 13 & 10 \\\\\n4 & 3 & 14 & 12 \\\\\n5 & 10 & 15 & 8 \\\\\n6 & 8 & 16 & 7 \\\\\n7 & 7 & 17 & 8 \\\\\n8 & 2 & 18 & 8 \\\\\n9 & 6 & 19 & 10 \\\\\n10 & 11 & 20 & 7 \\\\\n\\end{tabular}}\n\\end{center}\n    \n    \\item[(d)] Every year, $10$ scientists go to the same geographic area (same Lyme prevalence) and they each collect $40$ ticks. They test each tick for Lyme disease and record the number of ticks that have Lyme. Let $x^{(i)}$ be the number of ticks with Lyme in the $i$th scientist's bunch.\n        \n\\begin{center}{\\small\n\\begin{tabular}{cc}\n\\toprule\nScientist ID ($i$) & $x^{(i)}$ \\\\\n\\midrule\n1 & 8 \\\\\n2 & 9 \\\\\n3 & 14 \\\\\n4 & 15 \\\\\n5 & 12 \\\\\n6 & 7 \\\\\n7 & 6 \\\\\n8 & 8 \\\\\n9 & 8 \\\\\n10 & 14 \\\\\n\\end{tabular}}\n\\end{center}\n    \n    \\item[(e)] You have waist circumference data on 1045 men aged 70 and above (see Dey's 2002 paper in the Journal of the American Geriatric Society). It looks like this:\n    \n\\begin{center}\n\\includegraphics[width=0.5\\textwidth]{img/l01-problem5.png}\n\\end{center}\n\n    \\end{enumerate}\n\\end{question}\n\n", "meta": {"hexsha": "0899798051f61f64eb1bfeb44d926e41b1d227e3", "size": 15518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-probability-distributions.tex", "max_stars_repo_name": "blpercha/mcds-notes", "max_stars_repo_head_hexsha": "33531a443afb154b5c415299276a2ad215463896", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-12-10T16:51:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T01:31:23.000Z", "max_issues_repo_path": "tex/mcds-probability-distributions.tex", "max_issues_repo_name": "blpercha/mcds-notes", "max_issues_repo_head_hexsha": "33531a443afb154b5c415299276a2ad215463896", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/mcds-probability-distributions.tex", "max_forks_repo_name": "blpercha/mcds-notes", "max_forks_repo_head_hexsha": "33531a443afb154b5c415299276a2ad215463896", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T17:16:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T17:16:44.000Z", "avg_line_length": 58.1198501873, "max_line_length": 734, "alphanum_fraction": 0.718327104, "num_tokens": 4492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951143326726, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.7254660359900702}}
{"text": "\\section{Linear Programming}\r\nRecall that a linear program is the maximisation of $c^\\top x$ subject to $Ax\\le b,x\\ge 0$, where $c\\in\\mathbb R^n$, $A$ is an $m\\times n$ matrix and $b\\in\\mathbb R^m$.\r\nWe also know its dual problem in the form of minimising $b^\\top\\lambda$ subject to $A^\\top\\lambda\\ge c,\\lambda\\ge 0$.\r\n\\subsection{The Fundamental Theorem}\r\n\\begin{theorem}[Fundamental Theorem of Linear Programming]\r\n    Consider the primal problem stated.\r\n    A vector $x^\\star\\in\\mathbb R^n$ is optimal for the primal problem iff there is some vector $\\lambda^\\star\\in\\mathbb R^m$ such that:\\\\\r\n    1. $x^\\star$ is feasible for the primal problem.\\\\\r\n    2. $\\lambda^\\star$ is feasible for the dual problem.\\\\\r\n    3. $(b-Ax^\\star)^\\top\\lambda^\\star=0=(c-A^\\top\\lambda^\\star)^\\top x^\\star$ (i.e. the complementary slackness).\\\\\r\n    Also, if these are true, then $\\lambda^\\star$ is optimal for the dual problem, and $c^\\top x^\\star=b^\\top\\lambda^\\star$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    For the `if' direction, note that if $x,\\lambda$ are feasible for the primal and dual problems, then by Theorem \\ref{weak_dual}, $c^\\top x\\le b^\\top\\lambda$.\r\n    But if $x^\\star$ and $\\lambda^\\star$ satisfy complementary slackness, $c^\\top x^\\star=b^\\top\\lambda^\\star$, consequently $c^\\top x\\le b^\\top\\lambda^\\star\\le c^\\top x^\\star$ for all feasible $x$ and $b^\\top\\lambda\\ge c^\\top x^\\star=b^\\top\\lambda^\\star$ for all feasible $\\lambda$.\r\n    Hence $x^\\star$ and $\\lambda^\\star$ are optimal for their respective problems.\\\\\r\n    For the ``only if'' direction, note that the objective function $f(x)=c^\\top x$ and constraint function $g(x)=Ax$ are linear, hence are both concave and convex at the same time.\r\n    In particular, $f$ is concave while $g$ is convex.\r\n    Hence the value function of the primal function is concave, therefore Theorem \\ref{lagrange_nece} guarantees the existence of $\\lambda^\\star$.\r\n\\end{proof}\r\n\\subsection{Extreme Points}\r\nConsider the maximisation of $\\psi(x)$ subject to $x\\in X$ where $X$ is convex and $\\psi$ is also convex.\r\nIn particular, for any $p\\in(0,1)$,\r\n$$\\psi(px+(1-p)y)\\le p\\psi(x)+(1-p)\\psi(y)\\le\\max\\{\\psi(x),\\psi(y)\\}$$\r\nHence the maximum of $\\psi$ on any segment occurs at one of the endpoints.\r\nTherefore it is sufficient to consider the maximisation problem in the set of points in $X$ that is not contained properly in a line segment.\r\n\\begin{definition}\r\n    Let $X\\subset\\mathbb R^n$ be a convex set.\r\n    A point $x\\in X$ is an extreme point if the only case where there can be $y,z\\in X,p\\in (0,1)$ with $x=py+(1-p)z$ is when $x=y=z$.\r\n\\end{definition}\r\nExtreme points are of course very useful in linear programs as linear functions are both concave and convex.\r\nThe concavity tells us we can characterise the optimal solution via duality.\r\nAs the set of feasible solutions is convex, the convexity tells us we only need to search for optimal solutions to the extreme points of the set of feasible solutions.\r\nIn particular, if the linear program has an optimal solution, then it has a optimiser that is an extreme point.\r\n\\subsection{Basic Feasible Solutions}\r\nAs we have seen, it is helpful if we formulate linear programs in the form of inequality functional constraints.\r\nThere is another form which we can write the linear programs in order to make it more convenient to optimise.\r\n\\begin{definition}\r\n    A linear program is in standard form if the constraint can be written as $Ax=b,x\\ge 0$.\r\n\\end{definition}\r\nAll linear programs can be put into the standard form.\r\nFor instance, $Ax\\le b,x\\ge 0$ can be transformed to $Ax+z=b,x,z\\ge 0$ by our previous idea of slack variables.\r\nSimply $Ax=b$ can be modified to $A(x-y)=b,x,y\\ge 0$.\r\nCombining the ideas, $Ax\\le b$ can be transformed to $A(x-y)+z,x,y,z\\ge 0$.\r\n\\begin{definition}\r\n    Given an $m\\times n$ matrix $A$ with $n>m$ and $b\\in\\mathbb R^m$.\r\n    A solution $x\\in\\mathbb R^n$ of the equation $Ax=b$ is called basic if at most $m$ entries of $x$ are nonzero, i.e. $x_i\\neq 0$ holds for at most $m$ different $i\\in\\{1,\\ldots,n\\}$.\\\\\r\n    If $x$ is a basic solution and $x\\ge 0$, it is called a basic feasible solution.\r\n\\end{definition}\r\nNow denote the set of feasible solutions by $C=\\{x\\ge 0:Ax=b\\}$, then we have\r\n\\begin{theorem}\r\n    If $x$ is an extreme point of $C$, then $x$ is a basic feasible solution.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    We will prove the contrapositive.\r\n    Let $x$ be a point in $C$ that is not basic, then there are at least $m+1$ indices $i_1,\\ldots,i_r$ with $x_{i_k}>0$.\r\n    Then the set $\\{A_{i_1},\\dots,A_{i_r}\\}$ of columns of the matrix $A$ would be linearly dependent as $t\\ge m+1$, therefore there exists $(w_1,\\ldots,w_r)\\neq 0$ such that $w_aA_{i_a}=0$ (summation implied).\r\n    We construct\r\n    $$z_i=\\begin{cases}\r\n        w_k\\text{, if $i=i_k$ for some $k=1,\\ldots,r$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    Then $Az=0$ and $z\\neq 0$, so $A(x\\pm\\epsilon z)=Ax=b$ for any $\\epsilon$ for any $\\epsilon$.\r\n    As $x_{i_k}>0$ for any $k$, it is possible to choose some $\\epsilon>0$ such that $x\\pm\\epsilon z\\ge 0$.\r\n    So $x\\pm\\epsilon z\\in C$ and\r\n    $$x=\\frac{1}{2}(x+\\epsilon z)+\\frac{1}{2}(x-\\epsilon_z)$$\r\n    Hence $x$ is not extreme.\r\n\\end{proof}\r\nThis theorem has a partial converse.\r\n\\begin{theorem}\r\n    Suppose that every set of $m$ columns of $A$ is linearly independent and $x$ is a basic feasible solution, then $x$ is necessarily an extreme point of $C$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    By definition, at most $m$ many indices $i$ satisfy $x_i>0$.\r\n    Suppose there is some $y,z\\in C$ and $p\\in (0,1)$ such that $x=py+(1-p)z$, then $y,z\\ge 0$, so whenever $x_i=0$ we have $y_i=z_i=0$.\r\n    Thus there are at least $n-m$ indices $i$ satisfying $y_i=z_i=0$.\r\n    But also $Ay=b=Az$, so\r\n    $$0=A(y-z)=\\sum_{i}w_iA_i$$\r\n    where $w=y-z$.\r\n    But at most $m$ entries of $w$ are nonzero while any set of $m$ columns of $A$ is linearly independent, whence we conclude $w=0$.\r\n    It follows that $x=y=z$.\r\n\\end{proof}\r\nIn conclusion, we can find the optimal solution of a linear program by checking each of the basic feasible solutions, whcih are easier to find and, more importantly, finite.\r\n\\subsection{Algorithms for Linear Programs}\r\nConsider a linear program in standard form of maximising $c^\\top x$ subject to $Ax=b,x\\ge 0$ where $c\\in\\mathbb R^n,b\\in\\mathbb R^m$ and $A$ is an $m\\times n$ matrix.\r\nAssume that $n>m$ and every set of $m$ columns of $A$ is linearly independent, and that the problem is non-degenerate, i.e. every basic feasible solution $x$ has exactly $m$ indices $i$ with $x_i\\neq 0$.\r\nOur goal is to find a mechanical method of finding the optimal solution to the problem.\\\\\r\nA na\\\"ive method to do this is to check all extreme points of $C$.\r\nBut we also know that extreme points are precisely the basic feasible solutions.\r\nThus we can roll out an algorithm as follows:\\\\\r\nFirst, fix $B\\subset\\{1,\\ldots,n\\}$ with $|B|=m$ write and $N=\\{1,\\ldots,n\\}\\setminus B$.\r\nSuch a $B$ is called a basis of the solution.\r\nSuppose $B=\\{i_1,\\ldots,i_m\\}$, then we define $A_B=(A_{i_1}\\ldots A_{i_m})$ which is an invertible matrix by assumption.\r\nFor any $x\\in\\mathbb R^n$, denote $x_B=(x_{i_1},\\ldots,x_{i_m})^\\top$.\r\nThe quantities $c_B,A_N,x_N,c_N$ are defined similarly.\\\\\r\nOur aim is to find a basic solution of $Ax=b$.\r\nWe can write the problem instead in the form $A_Bx_B+A_Nx_N=b$.\r\nSet $x_N=0$ shall yield $x_B=A_B^{-1}b$ as $A_B$ is invertible.\r\nBy a rearrangement of coordinate we can write the solution as\r\n$$x=\\begin{pmatrix}\r\n    x_B\\\\\r\n    x_N\r\n\\end{pmatrix}=\\begin{pmatrix}\r\n    A_B^{-1}b\\\\\r\n    0\r\n\\end{pmatrix}$$\r\nwhich is basic.\r\nNow $x$ is feasible iff $A_B^{-1}b\\ge0$ (which can be checked).\r\nAssuming $x$ is a basic feasible solution, then we can just compute the objective function $c^\\top x=c_B^\\top x_B$.\r\nRepeat this procedure for all possible choices of $B$ gives a list of all basic feasible solutions and the value of objective function evaluated there.\r\nThis is a finite set, so we can find its maximiser which is the solution to the problem.\\\\\r\nThere are some issues with this approach.\r\nFirstly, if $n$ is large, the number of choices of $B$, that is $\\binom{n}{m}$, would grow very fast, making it more computationally complex.\r\nAlso, this method assumed the existence of maximiser which is not always the case.\r\nOur idea algorithm should certainly detect it when a maximiser does not exist, i.e. the problem is unbounded.\\\\\r\nThere is a better method to accomplish what we wanted.\r\nWe also use the idea of computing the basic feasible solutions like above, but we will try not to evaluate all candidate solutions.\r\nBy calculation we can show that the dual problem is to minimise $b^\\top\\lambda$ subject to $A^\\top\\lambda\\ge c$.\r\nSo by the fundamental theorem, a feasible $x^\\star$ is optimal for our primal problem iff there is a feasible (in the dual problem) Lagrange multiplier $\\lambda^\\star\\in\\mathbb R^m$ such that complementary slackness $(c-A^\\top\\lambda^\\star)^\\top x^\\star=0$ is satisfied.\\\\\r\nConsider a basic feasible solution $x=(A_B^{-1}b,0)^\\top$, then if it is optimal, then there is some $\\lambda$ satisfying complementary slackness\r\n$$0=(c-A^\\top\\lambda)^\\top x=(c_B-A_B^\\top\\lambda)^\\top x_B$$\r\nBut no index of $x_B$ is zero by assumption, hence $\\lambda=(A_B^\\top)^{-1}c_B$.\r\nSo we can roll out our algorithm in the same way as before, but each time we check as well the feasibility of $\\lambda$.\r\nWe can stop if such $\\lambda$ is feasible, because by the fundamental theorem we have already found the optimal solution.\r\nWe also know when the problem is unbounded, that is when none of the basic feasible solution gives a feasible $\\lambda$.\r\n\\subsection{The Simplex Algorithm}\r\nA third way, which is known as the simplex algorithm, is a yet faster method.\r\nSo far our algorithms depend on iterating all candidates for basic feasible solutions randomly, which inspires us to find the solutions in a particular order to speed up the process.\r\nIn particular, if our current basic feasible solution does not work, we will want to find the next basic feasible solution that increases the objective function.\\\\\r\nWe start with an initial basic feasible solution $x_0$ whose components with indices in $B_0\\subset\\{1,\\ldots,n\\}$ are nonzero.\r\nWrite $N_0=\\{1,\\ldots,n\\}\\setminus B_0$.\r\nWe can associate a Lagrange multiplier $\\lambda_0$ by complementary slackness, i.e. one that satisfies $(c-A^\\top\\lambda_0)_{B_0}=0$.\r\nIn particular, $(c-A^\\top\\lambda_0)^\\top x_0=0$, so $c^\\top x_0=b^\\top\\lambda_0$.\r\nLet $\\mu_0=c-A^\\top\\lambda_0$.\r\nIf $\\mu_0\\le 0$ then we are done and $x_0$ is optimal, otherwise we choose $x_1$ by the following:\r\n\\begin{claim}\r\n    Suppose there is some $j\\in N_0$ such that $\\mu_{j,0}>0$ and there is an $i\\in B_0$ such that there is a basic feasible solution $x_1$ with basis $B_1=B_0\\cup\\{j\\}\\setminus\\{i\\}$.\r\n    Then\r\n    $$c^\\top x_1=c^\\top x_0+\\mu_{j,0}x_{j,1}>c^\\top x_0$$\r\n\\end{claim}\r\n\\begin{proof}\r\n    If $x$ is any feasible solution, then\r\n    $$c^\\top x=c^\\top x+\\lambda_0^\\top(b-Ax)=b^\\top\\lambda_0+(c-A^\\top\\lambda_0)^\\top x=c^\\top x_0+\\sum_{k\\in N_0}\\mu_{k,0}x_k$$\r\n    as $\\mu_{k,0}=0$ for any $k\\in B_0$.\r\n    The sum is then\r\n    $$\\sum_{k\\in N_0}\\mu_k x_{k,1}=\\sum_{k\\in N_1}\\mu_kx_{k,1}+\\mu_jx_{j,1}-\\mu_ix_{i,1}=\\mu_jx_{j,1}$$\r\n    Also $x_{j,1}>0$ by non-degeneracy assumption.\r\n    The claim follows.\r\n\\end{proof}\r\n\\begin{proposition}\\label{simplex_unbounded}\r\n    Suppose there is a $j\\in N_0$ such that $\\mu_{j,0}>0$ and for every $i\\in B_0$ the basis solution with basis $B_1=B_0\\cup\\{j\\}\\setminus\\{i\\}$ is infeasible, then the problem is unbounded.\r\n\\end{proposition}\r\nSo if no feasible $x_1$ exists, then we can stop the algorithm and conclude that the problem is unbounded.\r\nOtherwise, we can repeat the algorithm again and again, and stop either at a basic feasible solution whose accompanied Lagrange multiplier is feasible in the dual problem or at a point where we can conclude the unboundedness of the problem.\r\nWe may, however, have to go through all basic feasible solutions if we start with a bad guess, but at least we know after each step we shall obtain a better solution candidate.\r\n\\subsection{Simplex Algorithm in Action}\r\nWe are still considering the problem of maximising $c^\\top x$ subject to $Ax=b,x\\ge 0$, assuming the same things we assumed previously.\r\nSuppose we know one basic feasible solution $x_0$, we want to use the simplex algorithm.\r\nBefore that, we need to do some pre-processing of the problem.\r\nLet $B$ be the basis of $x_0$ and $N=\\{1,\\ldots,n\\}\\setminus B$ as usual.\r\nFor $x\\in\\mathbb R^n$, we rearrange the components $x=(x_B,x_N)^\\top$ as usual.\r\nFurthermore, the objective function can be written as\r\n$$c^\\top x=c^\\top x_0+\\mu_{N,0}^\\top x_N$$\r\nfor feasible $x$.\r\nwhere $\\mu_0=c-A^\\top\\lambda_0$ and $\\lambda_0=(A_B^\\top)^{-1}c_B$ is the Lagrange multiplier obtained by complementary slackness.\r\nThe set of feasible solutions is then subject to the condition\r\n$$x_B+A_B^{-1}A_Nx_N=x_{B,0},x_B,x_N\\ge 0$$\r\nTo use the simplex algorithm, we first formulate the initial \\text{simplex tableau} as the $(m+1)\\times(n+1)$ matrix (in practice some of the columns are shuffled due to the position of the basis)\r\n$$\\Gamma=\\begin{pmatrix}\r\n    I&A_B^{-1}A_N&x_{B,0}\\\\\r\n    0&\\mu_{N,0}^\\top&-c^\\top x_0\r\n\\end{pmatrix}$$\r\nwhere $I$ is the $m\\times m$ identity.\r\nWe first test for optimality of $x_0$.\r\nIf $\\mu_0\\le 0$, then we can stop as it would be optimal due to the fundamental theorem.\r\nOtherwise, we choose the pivot column, i.e. $j\\in N$ such that $\\mu_{j,0}>0$.\r\na rule of thumb is to pick $j$ such that $\\mu_{j,0}$ is the largest.\r\nWe also pick the pivot row by looking within the pivot column $j$ and find the $i\\in B$ which minimises $x_{i,0}/\\Gamma_{i,j}$ over all $i\\in B$ with $\\Gamma_{i,j}>0$.\r\nIf this cannot be done, i.e. $\\Gamma_{i,j}\\le 0$ for all $i$, then we can stop as it indicates the unboundedness of the problem.\\\\\r\nAssume we go through these steps without stopping the algorithm, we perform the pivot operation to move to the next basic feasible solution.\r\nTo do this, we scale row $i$ with $1/\\Gamma_{i,j}$ and replace row $k$ with\r\n$$(\\text{old row }k)-(\\text{old row }i)\\times\\frac{\\Gamma_{k,j}}{\\Gamma_{i,j}}$$\r\nfor all $k\\neq i$ and run the algorithm on this new simplex tableau.\r\n\\begin{remark}\r\n    1. For the initial basic feasible solution we have $x_{i,0}>0$ and $x_{j,0}=0$, whilst for the next basic feasible solution $x_{i,1}=0$ and $x_{j,1}=x_{i,0}/\\Gamma_{i,j}>0$.\\\\\r\n    2. The pivot operation is actually just a Gaussian elimination.\\\\\r\n    3. The $\\Gamma$ we obtained after the pivot operation is the same $\\Gamma$ had we start with $x_1$ instead.\\\\\r\n    4. Suppose $\\Gamma_{i,j}\\le 0$ for all $i\\in B$, then for $i\\in B$ and for $r>0$ let $x_r=x_0+r(\\delta_j-\\Gamma_{i,j}\\delta_i)$ where $\\delta_k$ is the $k^{th}$ standard basis.\r\n    Then the transformation $x_0\\mapsto x_r$ replaces $x_{i,0}$ with $x_{i,r}=x_{i,0}-r\\Gamma_{i,j}$ and $x_{j,0}=0$ with $x_{j,r}=r$ and leaves other entries unchanged.\r\n    Now $x_r$ is feasible since $x_r\\ge 0$ and\r\n    $$\\begin{pmatrix}\r\n        I&A_B^{-1}A_N\r\n    \\end{pmatrix}x_r=x_0$$\r\n    But $c^\\top x_r=c^\\top x_0+r\\mu_{j,0}\\to\\infty$ as $r\\to\\infty$, so the problem is unbounded.\r\n    This proves Proposition \\ref{simplex_unbounded}.\r\n\\end{remark}\r\n\\begin{example}\r\n    Consider the linear program to maximise $3x_1+2x_2$ subject to\r\n    $$\\begin{cases}\r\n        2x_1+x_2\\le 4\\\\\r\n        2x_1+3x_2\\le 6\\\\\r\n        x_1,x_2\\ge 0\r\n    \\end{cases}$$\r\n    Then its dual problem is to minimise $4\\lambda_1+6\\lambda_2$ subject to\r\n    $$\\begin{cases}\r\n        2\\lambda_1+2\\lambda_2\\ge 3\\\\\r\n        \\lambda_1+3\\lambda_2\\ge 2\\\\\r\n        \\lambda_1,\\lambda_2\\ge 0\r\n    \\end{cases}$$\r\n    By introducing slack variables, the primal problem has constraint\r\n    $$\\begin{cases}\r\n        2x_1+x_2+z_1=4\\\\\r\n        2x_1+3x_2+z_2=6\\\\\r\n        x_1,x_2,z_1,z_2\\ge 0\r\n    \\end{cases}$$\r\n    and the dual problem has constraint\r\n    $$\\begin{cases}\r\n        2\\lambda_1+2\\lambda_2-v_1= 3\\\\\r\n        \\lambda_1+3\\lambda_2-v_2= 2\\\\\r\n        \\lambda_1,\\lambda_2,v_1,v_2\\ge 0\r\n    \\end{cases}$$\r\n    So the complementary slackness translates to\r\n    $$x_1v_1=x_2v_2=\\lambda_1z_1=\\lambda_2z_2=0$$\r\n    Running the simplex algorithm shall yield the maximiser $x_1=3/2,x_2=1$ with then corresponding dual solution $\\lambda_1=5/4,\\lambda_2=1/4$.\r\n    We start with the simplex tableau (asterisked columns are where the identity matrix and the zero vectors are at)\r\n    $$\\begin{array}{c|cccc|c}\r\n        &&&\\ast&\\ast&\\\\\r\n        &x_1&x_2&z_1&z_2&\\\\ \\hline\r\n        z_1&2&1&1&0&4\\\\\r\n        z_2&2&3&0&1&6\\\\ \\hline\r\n        \\text{payoff}&3&2&0&0&0\r\n    \\end{array}$$\r\n    Now the payoff row is not non-positive, hence we have not arrived at the optimal solution.\r\n    As $3$ is the largest payoff entry, we let $x_1$ enter the basis, so the first column is the pivot column.\r\n    We choose the first row to be the pivot row.\r\n    The the pivot operation yields the next simplex tableau:\r\n    $$\\begin{array}{c|cccc|c}\r\n        &\\ast&&&\\ast&\\\\\r\n        &x_1&x_2&z_1&z_2&\\\\ \\hline\r\n        x_1&1&1/2&1/2&0&2\\\\\r\n        z_2&0&2&-1&1&2\\\\ \\hline\r\n        \\text{payoff}&0&1/2&-3/2&0&-6\r\n    \\end{array}$$\r\n    It is still not optimal due to the positive $1/2$ entry in the payoff row.\r\n    So this time the pivot column is the second column and we choose the second row as the pivot row.\r\n    This gives us\r\n    $$\\begin{array}{c|cccc|c}\r\n        &\\ast&\\ast&&&\\\\\r\n        &x_1&x_2&z_1&z_2&\\\\ \\hline\r\n        x_1&1&0&3/4&-1/4&3/2\\\\\r\n        x_2&0&1&-1/2&1/2&1\\\\ \\hline\r\n        \\text{payoff}&0&0&-5/4&-1/4&-13/2\r\n    \\end{array}$$\r\n    which we realise is optimal as the payoff is nonpositive.\r\n\\end{example}\r\n\\begin{remark}\r\n    1. If the linear program is a minimisation instead of a maximisation problem, then the stopping criterion would be the tableau being nonnegative.\\\\\r\n    2. When the problem is of the form like above, i.e. maximising $c^\\top x$ subject to $Ax\\le b,x\\ge 0$, one observe that the coefficient of the payoff row under the slack variables are minus the corresponding dual variables (via complementary slackness).\r\n    For the final tableau, the feasible dual variables are the Lagrange multipliers for the problems.\\\\\r\n    3. In the example, we have\r\n    $$\\begin{pmatrix}\r\n        3/4&-1/4\\\\\r\n        -1/2&1/2\r\n    \\end{pmatrix}\\begin{pmatrix}\r\n        2&1&1&0&4\\\\\r\n        2&3&0&1&6\r\n    \\end{pmatrix}=\\begin{pmatrix}\r\n        1&0&3/4&-1/4&3/2\\\\\r\n        0&1&-1/2&1/2&1\r\n    \\end{pmatrix}$$\r\n    Hence the perturbed problem of maximising $3x_1+2x_2$ subject to\r\n    $$\\begin{cases}\r\n        2x_1+x_2\\le 4+\\epsilon_1\\\\\r\n        2x_1+3x_2\\le 6+\\epsilon_2\\\\\r\n        x_1,x_2\\ge 0\r\n    \\end{cases}$$\r\n    with $\\epsilon_{1,2}$ small yields the final tableau\r\n    $$\\begin{array}{c|cccc|c}\r\n        &\\ast&\\ast&&&\\\\\r\n        &x_1&x_2&z_1&z_2&\\\\ \\hline\r\n        x_1&1&0&3/4&-1/4&3/2+3\\epsilon_1/4-\\epsilon_2/4\\\\\r\n        x_2&0&1&-1/2&1/2&1-\\epsilon_1/2+\\epsilon_2/2\\\\ \\hline\r\n        \\text{payoff}&0&0&-5/4&-1/4&-13/2-5\\epsilon_1/4-\\epsilon_2/4\r\n    \\end{array}$$\r\n    Therefore it has maximiser at\r\n    $$x_1=\\frac{3}{2}+\\frac{3}{4}\\epsilon_1-\\frac{1}{4}\\epsilon_1,x_2=1-\\frac{1}{2}\\epsilon_1+\\frac{1}{2}\\epsilon_2, 3x_1+2x_2=\\frac{13}{2}+\\frac{5}{4}\\epsilon_1+\\frac{1}{4}\\epsilon_2$$\r\n    given that they are feasible (possible for small enough $\\epsilon_{1,2}$).\r\n\\end{remark}\r\n\\subsection{The Two-Phase Algorithm}\r\nAgain our problem is to maximise $c^\\top x$ subject to $Ax=b,x\\ge 0$.\r\nIn order to roll out the simplex algorithm, we need at least one basic feasible solution.\r\nIt is certainly tempting if we can know a way that can yield one efficiently.\\\\\r\nThere are a lot of approaches, for example just pick a basis and computed $A_B^{-1}b$ (using the notations we introduced earlier).\r\nThis is certainly a sufficient algorithm, but this might not be very efficient.\\\\\r\nConsider a new problem of minimising $e^\\top y$ subject to $Ax+y=b,x,y\\ge 0$ where $e=(1,\\ldots,1)^\\top$.\r\nThe variable $y$ here is called an artificial variable.\r\nNow $(x,y)=(0,b)$ is a basic feasible solution for this problem, so we can apply the simplex algorithm which must terminate at some $(x,y)=(x_0,0)$ given that the original problem is feasible.\r\nThen $x_0$ has to be basic feasible for the original problem.\r\nSo we can modify the algorithm by adding a first phase to compute one basic feasible solution first (called Phase I) and then apply the simplex algorithm to it (which is Phase II).\r\n\\begin{example}\r\n    Consider the problem to maximise $x_1-3x_2+5x_3$ subject to\r\n    $$\\begin{cases}\r\n        x_1+x_2+x_3\\le 30\\\\\r\n        -x_2+2x_3=20\\\\\r\n        -x_1+2x_2+x_3\\ge 40\\\\\r\n        x_1,x_2,x_3\\ge 0\r\n    \\end{cases}$$\r\n    we introduce slack variables as usual to transform the constraint to\r\n    $$\\begin{cases}\r\n        x_1+x_2+x_3+z_1=30\\\\\r\n        -x_2+2x_3=20\\\\\r\n        -x_1+2x_2+x_3-z_2=40\\\\\r\n        x_1,x_2,x_3,z_1,z_2\\ge 0\r\n    \\end{cases}$$\r\n    Add in artificial variable $y_1,y_2$,\r\n    $$\\begin{cases}\r\n        x_1+x_2+x_3+z_1=30\\\\\r\n        -x_2+2x_3+y_1=20\\\\\r\n        -x_1+2x_2+x_3-z_2+y_2=40\\\\\r\n        x_1,x_2,x_3,z_1,z_2,y_1,y_2\\ge 0\r\n    \\end{cases}$$\r\n    In some sense we should have added a variable $y_3$ on the first expression as well, but it is actually redundant as we already have an nonnegative expression.\r\n    We solve this new problem with the simplex algorithm, with the initial tableau:\r\n    $$\\begin{array}{c|ccccccc|c}\r\n        &&&&\\ast&&\\ast&\\ast&\\\\\r\n        &x_1&x_2&x_3&z_1&z_2&y_1&y_2&\\\\ \\hline\r\n        z_1&1&1&1&1&0&0&0&30\\\\\r\n        y_1&0&-1&2&0&0&1&0&20\\\\\r\n        y_2&-1&2&1&0&-1&0&1&40\\\\ \\hline\r\n        \\text{Phase II}&1&-3&5&0&0&0&0&0\\\\ \\hline\r\n        \\text{Phase I}&0&0&0&0&0&1&1&0\r\n    \\end{array}$$\r\n    We have put the objective functions of both phases so that we can manipulate both simultaneously so that when Phase I is completed, we can immediately go to Phase II.\\\\\r\n    Now the identity part of the upper part of the tableau does not correspond to the zero part of the Phase I payoff, so we do a transformation to modify the tableau:\r\n    $$\\begin{array}{c|ccccccc|c}\r\n        &&&&\\ast&&\\ast&\\ast&\\\\\r\n        &x_1&x_2&x_3&z_1&z_2&y_1&y_2&\\\\ \\hline\r\n        z_1&1&1&1&1&0&0&0&30\\\\\r\n        y_1&0&-1&2&0&0&1&0&20\\\\\r\n        y_2&-1&2&1&0&-1&0&1&40\\\\ \\hline\r\n        \\text{Phase II}&1&-3&5&0&0&0&0&0\\\\ \\hline\r\n        \\text{Phase I}&1&-1&-3&0&1&0&0&-60\r\n    \\end{array}$$\r\n    Note that as we are encountering a minimisation problem in Phase I, our aim is to make the last row nonnegative.\r\n    Pivot once:\r\n    $$\\begin{array}{c|ccccccc|c}\r\n        &&&\\ast&\\ast&&&\\ast&\\\\\r\n        &x_1&x_2&x_3&z_1&z_2&y_1&y_2&\\\\ \\hline\r\n        z_1&1&3/2&0&1&0&-1/2&0&20\\\\\r\n        x_3&0&-1/2&1&0&0&1/2&0&10\\\\\r\n        y_2&-1&5/2&0&0&-1&-1/2&1&30\\\\ \\hline\r\n        \\text{Phase II}&1&-1/2&0&0&0&-5/2&0&-50\\\\ \\hline\r\n        \\text{Phase I}&1&-5/2&0&0&1&3/2&0&-30\r\n    \\end{array}$$\r\n    Pivot twice:\r\n    $$\\begin{array}{c|ccccccc|c}\r\n        &&\\ast&\\ast&\\ast&&&&\\\\\r\n        &x_1&x_2&x_3&z_1&z_2&y_1&y_2&\\\\ \\hline\r\n        z_1&8/5&0&0&1&3/5&-1/5&-3/5&2\\\\\r\n        x_3&-1/5&0&1&0&-1/5&2/5&1/5&16\\\\\r\n        x_2&-2/5&1&0&0&-2/5&-1/5&2/5&12\\\\ \\hline\r\n        \\text{Phase II}&4/5&0&0&0&-1/5&-13/5&1/5&-44\\\\ \\hline\r\n        \\text{Phase I}&0&0&0&0&0&1&1&0\r\n    \\end{array}$$\r\n    The last row is nonnegative and the objective function attains zero, so we have already achieved our aim for Phase I with the basic feasible solution shown in the tableau.\r\n    This produces our initial tableau for Phase II:\r\n    $$\\begin{array}{c|ccccc|c}\r\n        &&\\ast&\\ast&\\ast&&\\\\\r\n        &x_1&x_2&x_3&z_1&z_2&\\\\ \\hline\r\n        z_1&8/5&0&0&1&3/5&2\\\\\r\n        x_3&-1/5&0&1&0&-1/5&16\\\\\r\n        x_2&-2/5&1&0&0&-2/5&12\\\\ \\hline\r\n        \\text{Phase II}&4/5&0&0&0&-1/5&-44\\\\\r\n    \\end{array}$$\r\n    Now we are maximising, so we need to make the payoff nonpositive.\r\n    After the first pivoting we have\r\n    $$\\begin{array}{c|ccccc|c}\r\n        &\\ast&\\ast&\\ast&&&\\\\\r\n        &x_1&x_2&x_3&z_1&z_2&\\\\ \\hline\r\n        x_1&1&0&0&5/8&3/8&5/4\\\\\r\n        x_3&0&0&1&1/8&-1/8&65/4\\\\\r\n        x_2&0&1&0&1/4&-1/4&25/2\\\\ \\hline\r\n        \\text{Phase II}&0&0&0&-1/2&-1/2&-45\\\\\r\n    \\end{array}$$\r\n    which has nonpositive payoff, hence the optimal solution is at $(x_1,x_2,x_3)=(5/4,25/2,65/4)$.\r\n\\end{example}", "meta": {"hexsha": "bb44335d36416afdce636518728361f17ac3fca7", "size": 24409, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/linear.tex", "max_stars_repo_name": "david-bai-notes/IB-Optimisation", "max_stars_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3/linear.tex", "max_issues_repo_name": "david-bai-notes/IB-Optimisation", "max_issues_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3/linear.tex", "max_forks_repo_name": "david-bai-notes/IB-Optimisation", "max_forks_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.2357512953, "max_line_length": 284, "alphanum_fraction": 0.6642222131, "num_tokens": 8397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8596637577007394, "lm_q1q2_score": 0.725466034967289}}
{"text": "% Series expansion (Differentiate between the two approaches being used)\n\\subsection{Series Expansion}\n\nSymPy is able to calculate the symbolic series expansion of an arbitrary series\nor expression involving elementary and special functions and multiple\nvariables. For this it has two different implementations: the \\texttt{series}\nmethod and Ring Series.\n\nThe first approach stores a series as an instance of the \\texttt{Expr} class.\nEach function has its specific implementation of its expansion, which is able to\nevaluate the Puiseux series expansion about a specified point. For example,\nconsider a Taylor expansion about 0:\n\n\\begin{verbatim}\n>>> series(sin(x+y) + cos(x*y), x, 0, 2)\n1 + sin(y) + x*cos(y) + O(x**2)\n\\end{verbatim}\n\nThe newer and much faster approach called Ring Series makes use of the\nfact that a truncated Taylor series is simply a polynomial. Correspondingly, it\nmay be represented by a sparse polynomial, which performs\nwell in a under a wide range of cases. Ring Series also gives\nthe user the freedom to choose the type of coefficients to use, resulting in\nfaster operations on certain types.\n\nFor this, several low-level methods for expansion of trigonometric, hyperbolic\nand other elementary operations (like series inversion, calculating the $n$th\nroot, etc.) are implemented using variants of the Newton Method~\\cite{zimmerman}.\nAll these support Puiseux series expansion. The following example demonstrates\nthe use of an elementary function that calculates the Taylor expansion of the\nsine of a series.\n\n\\begin{verbatim}\n>>> from sympy.polys.ring_series import rs_sin\n>>> R, t = ring('t', QQ)\n>>> rs_sin(t**2 + t, t, 5)\n-1/2*t**4 - 1/6*t**3 + t**2 + t\n\\end{verbatim}\n\nThe function \\texttt{sympy.polys.rs\\_series} makes use of these elementary\nfunctions to expand an arbitrary SymPy expression. It does so by following a\nrecursive strategy of expanding the lowermost functions first and then\ncomposing them recursively to calculate the desired expansion. Currently, it\nonly supports expansion about 0 and is under active development. Ring Series\nis several times faster than the default implementation with the speed\ndifference increasing with the size of the series. The\n\\texttt{sympy.polys.rs\\_series} takes as input any SymPy expression and hence\nthere is no need to explicitly create a polynomial \\texttt{ring}. An example\ndemonstrating its use:\n\n% rs_series bug, output sometimes has a factored out\n% no-doctest\n\\begin{verbatim}\n>>> from sympy.polys.ring_series import rs_series\n>>> from sympy.abc import a, b\n>>> rs_series(sin(a + b), a, 4)\n-1/2*(sin(b))*a**2 + (sin(b)) - 1/6*a**3*(cos(b)) + a*(cos(b))\n\\end{verbatim}\n\n\\subsection{Formal Power Series}\n\nSymPy can be used for computing the formal power series of a function.\nThe implementation is based on the algorithm described in the paper on\nformal power series~\\cite{Gruntz93formalpower}.  The advantage of this approach is\nthat an explicit formula for the coefficients of the series expansion is generated\nrather than just computing a few terms.\n\nThe following example shows how to use \\texttt{fps}:\n\n\\begin{verbatim}\n>>> f = fps(sin(x), x, x0=0)\n>>> f.truncate(6)\nx - x**3/6 + x**5/120 + O(x**6)\n>>> f[15]\n-x**15/1307674368000\n\\end{verbatim}\n\n\\subsection{Fourier Series}\n\nSymPy provides functionality to compute Fourier series of a function using the\n\\texttt{fourier\\_series} function:\n\n\\begin{verbatim}\n>>> L = symbols('L')\n>>> expr = 2 * (Heaviside(x/L) - Heaviside(x/L - 1)) - 1\n>>> f = fourier_series(expr, (x, 0, 2*L))\n>>> f.truncate(3)\n4*sin(pi*x/L)/pi + 4*sin(3*pi*x/L)/(3*pi) + 4*sin(5*pi*x/L)/(5*pi)\n\\end{verbatim}\n", "meta": {"hexsha": "18dc0656cec72f28d5c0195a37ca4fd904557469", "size": 3618, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "series.tex", "max_stars_repo_name": "ProgZone/sympy-paper", "max_stars_repo_head_hexsha": "b3b85809cc92d1fd588971f944abda9fa995a426", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2016-03-27T06:55:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-22T18:42:39.000Z", "max_issues_repo_path": "series.tex", "max_issues_repo_name": "ProgZone/sympy-paper", "max_issues_repo_head_hexsha": "b3b85809cc92d1fd588971f944abda9fa995a426", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 205, "max_issues_repo_issues_event_min_datetime": "2016-03-17T03:08:15.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-01T17:09:29.000Z", "max_forks_repo_path": "series.tex", "max_forks_repo_name": "ProgZone/sympy-paper", "max_forks_repo_head_hexsha": "b3b85809cc92d1fd588971f944abda9fa995a426", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 37, "max_forks_repo_forks_event_min_datetime": "2016-03-17T16:02:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-15T15:06:54.000Z", "avg_line_length": 40.2, "max_line_length": 82, "alphanum_fraction": 0.7551133223, "num_tokens": 947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190938, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7254660194556114}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\subsection{Worksheet - Variational Principle Applied to Free Fall}\nAs a second example for the variational principle, let’s consider the (one-dimensional) free fall of a particle of mass $m$ due to gravity starting at zero and from rest for a duration T.\n\n\\begin{p}\nWrite down the Lagrange-Function $\\LL = T - U$ using a generalized coordinate q.\n\\end{p}\n\\begin{s}\nLet us use the height of particle as our generalized coordinate $q$. In this case the velocity of the particle is simply $\\dot{q}$, so we have that:\n\\[T = \\frac{1}{2}m\\dot{q}^2, \\quad U = mgq\\]\nHence the Lagrangian is:\n\\[\\LL = T - U = \\frac{1}{2}m\\dot{q}^2 - mgq\\]\n\\end{s}\n\n\\begin{p}\nUsing Newton’s 2\\textsuperscript{nd} law, write down the equation of motion for $q$ and the solution $q(t)$.\n\\end{p}\n\\begin{s}\nBy Newton's second law, we have that there is only a gravitational force $-mg$ acting on the particle, and hence it reads:\n\\[\\sum F = -mg = m\\ddot{q} \\implies -g = \\ddot{q}\\]\nWe solve this second order differential equation by integrating twice, which gives us:\n\\[q(t) = -\\frac{1}{2}gt^2 + \\dot{q}(t=0)t + q(t=0)\\]\nSince the particle starts at rest, we have that $\\dot{q}(0) = 0$ and hence:\n\\[q(t) = -\\frac{1}{2}gt^2 + q(t=0)\\]\n\\end{s}\n\n\\begin{p}\nWrite down the “boundary conditions” $q(t=0)$ and $q(t=T)$.\n\\end{p}\n\\begin{s}\nWe define our coordinate system such that $q(t=0) = 0$, and then by the solution above, $q(t=T) = -\\frac{1}{2}gT^2$.\n\\end{s}\n\n\\begin{p}\nA possible 'trial trajectory' could be the from $q_{\\text {trial }, \\alpha}(t)=-\\frac{1}{2} g t^{2}+\\alpha \\sin \\left(\\frac{\\pi t}{T}\\right)$. (This is how variational calculus is carried out!) Check that this function satisfies the boundary conditions at $\\mathrm{t}=0$ and $\\mathrm{t}=\\mathrm{T}$.\n\\end{p}\n\\begin{s}\nWe see that:\n\\[q(t=0) = -\\frac{1}{2}g(0)^2 + \\alpha \\sin \\left(\\frac{\\pi (0)}{T}\\right) = 0\\]\nand\n\\[q(t=T) = -\\frac{1}{2}gT^2 + \\alpha \\sin \\left(\\frac{\\pi T}{T}\\right) = -\\frac{1}{2}gT^2 \\]\nas desired.\n\\end{s}\n\n\\begin{p}\nInstead of considering all possible trajectories that obey the boundary conditions, we consider here only a specific family parameterized by $\\alpha .$ Thus $S\\left[q_{\\text {trial}, \\alpha}(t)\\right]=S(\\alpha)$ is a function of $\\alpha$ Write down $S\\left[q_{\\text {trial}, \\alpha}(t)\\right]$ and show that it can be written as\n\\[ S\\left[q_{\\text {trial}, \\alpha}(t)\\right]=S[q(t)]+m \\alpha^{2} \\pi^{2} / 4 T \\]\nIn the above form it is evident that the true trajectory $(\\alpha=0)$ minimizes $S$.\n\\end{p}\n\\begin{s}\nPlugging in the trial trajectory into the Lagrangian determined in question 1, we have:\n\\begin{align*}\nS\\left[q_{\\text {trial}, \\alpha}(t)\\right] &= \\int_{0}^T \\LL(q,\\dot{q}, t)dt\n\\\\ &= \\int_{0}^T\\frac{1}{2}m\\left(\\dod{}{t}\\left(-\\frac{1}{2} g t^{2}+\\alpha \\sin \\left(\\frac{\\pi t}{T}\\right)\\right)\\right)^2 - mg\\left(-\\frac{1}{2} g t^{2}+\\alpha \\sin \\left(\\frac{\\pi t}{T}\\right)\\right)dt\n\\\\ &= \\int_{0}^T\\frac{1}{2}m\\left(-gt + \\frac{\\alpha \\pi}{T}\\cos(\\frac{\\pi t}{T})\\right)^2 + \\frac{mg^2}{2}t^2 - mg\\alpha\\sin(\\frac{\\pi t}{T}) dt\n\\\\ &= \\int_0^T \\frac{1}{2}m\\left(g^2t^2 - 2\\frac{gt\\alpha\\pi}{T}\\cos(\\frac{\\pi t}{T}) + \\frac{\\alpha^2\\pi^2}{T^2}\\cos[2](\\frac{\\pi t}{T})\\right) + \\frac{mg^2}{2}t^2 - mg\\alpha\\sin(\\frac{\\pi t}{T}) dt\n\\\\ &= \\int_0^T mg^2t^2 + \\frac{m\\alpha^2\\pi^2}{2T^2}\\cos[2](\\frac{\\pi t}{T}) dt \\text{ (Integrals over full period of sine/cosine are zero)}\n\\\\ &= \\int_0^T mg^2t^2 + \\frac{m\\alpha^2 \\pi^2}{4T}\n\\\\ &= S[q(t)] + \\frac{m\\alpha^2 \\pi^2}{4T}\n\\end{align*}\nClearly this is minimized for $\\alpha = 0$, and for any $\\alpha > 0$ the action is larger. The one the action that makes the action minimal is the true physical path.\n\\end{s}\n\n\\begin{p}\nShow that if $S = \\int_{t_1}^{t_2} f(x, y, \\dot{x}, \\dot{y}) dt$ that there are \\textbf{two} Euler-Lagrange equations for the stationary curves $x(t), y(t)$. Write the Euler-Lagrange equations.\n\\end{p}\n\\begin{s}\nLet the correct path be given by $x = x(u)$ and by $y = y(u)$, and the wrong/varied path be given by $x = x(u) + \\alpha\\xi(u)$ and $y = y(u) + \\beta\\eta(u)$. By a very similar process to worksheet 1, we impose the requirement that $\\left. \\od{S}{\\alpha}\\right|_{\\alpha = 0} = 0$ and $\\left. \\od{S}{\\beta}\\right|_{\\beta = 0} = 0$. This leads to the two Euler Lagrange equations:\n\\[\\dpd{f}{x} = \\dod{}{u}\\dpd{f}{x'} \\text{ and } \\dpd{f}{y} = \\dod{}{u}\\dpd{f}{y'}\\]\n\\end{s}\n\n\\begin{p}\nConstruct Lagrange’s equations for a particle in a two-dimensional potential $U(x,y)$, and show that these are equivalent to a particle obeying Newton’s equations.\n\\end{p}\n\\begin{s}\nWe have that the Lagrangian is given by:\n\\[\\LL = \\frac{1}{2}m\\left(\\dot{x}^2+\\dot{y}^2\\right) - U(x,y)\\]\nSo by the two Euler-Lagrange equations above:\n\\[\\dpd{L}{x} = \\dod{}{t}\\dpd{L}{\\dot{x}} \\implies -\\dod{U(x,y)}{x} = \\dod{}{t}m\\dot{x} \\implies F_x = m \\ddot{x} \\]\n\\[\\dpd{L}{y} = \\dod{}{t}\\dpd{L}{\\dot{y}} \\implies -\\dod{U(x,y)}{y} = \\dod{}{t}m\\dot{y} \\implies F_y = m \\ddot{y} \\]\nSo we recover Newton's second law of:\n\\[\\v{F} = m\\ddot{\\v{r}}\\]\n\\end{s}\n\\end{document}", "meta": {"hexsha": "c60c83951e89a72519f983551a0c1275026700b0", "size": 5072, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-2/Worksheet-2.tex", "max_stars_repo_name": "RioWeil/PHYS306-notes", "max_stars_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture-2/Worksheet-2.tex", "max_issues_repo_name": "RioWeil/PHYS306-notes", "max_issues_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture-2/Worksheet-2.tex", "max_forks_repo_name": "RioWeil/PHYS306-notes", "max_forks_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.976744186, "max_line_length": 377, "alphanum_fraction": 0.6413643533, "num_tokens": 1931, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118068790619, "lm_q2_score": 0.8774767890838837, "lm_q1q2_score": 0.725420421797975}}
{"text": "\\section{Static Analysis}\n\n\\subsection{Control Flow Graph}\n\\begin{itemize}\n    \\item Every node is an instruction\n    \\item If instruction $p$ is followed by $q$, there is an arc $p\\rarr q$\n\\end{itemize}\n\nTrue and false values in conditionals are not represented.\n\\begin{itemize}\n    \\item Assignment and reading is replaced with \\emph{define}\n    \\item Variable in the right part is replaced with \\emph{use}\n\\end{itemize}\n\nEvery instruction $p$ has $def(p)$ and $use(p)$ set.\n\n\\subsection{Liveness intervals of Variables}\nA variable is live at some point if later its current value is used by an instruction.\n\nFor the final node (if it has only one exiting arc): $live_{out}(p) = \\emptyset$. For the other nodes:\n\\begin{align*}\n    live_{in}(p) &= use(p) \\cup (live_{out}(p) \\setminus def(p)) \\\\\n    live_{out}(p) &= \\bigcup_{q\\in succ(p)} live_{in}(q)\n\\end{align*}\n\nTo solve the system of flow equations, start with $live_{out}(p) = \\emptyset$, then iteratively find $live_{in}(p)$ and $live_{out}(p)$, until convergence.\n\n\\paragraph{Applications}\n\\begin{itemize}\n    \\item Memory allocation: if two variables are never simultaneously live, they do not interfere\n    \\item Useless definitions: instruction that defines a variable that is not live out of the instruction.\n\\end{itemize}\n\n\\subsection{Reaching Definitions}\n\nA definition of $a$ in $q$ reaches the entrance of instruction $p$ if there exists a path from $q$ to $p$ that does not traverse any node where $a$ is defined.\n\nIf $p$ defines $a$, any other definition $a_q$ (with $q\\ne p$) is suppressed by $p$: $sup(p) = \\{a_q | a \\in def(p) \\land a \\in def(q) \\land q \\ne q\\}$\n\n\\begin{align*}\n    in(1) &= \\emptyset \\\\\n    out(p) &= def(p) \\cup (in(p) \\setminus sup(p)) \\\\\n    in(p) &= \\bigcup_{q\\in pred(p)} out(q)\n\\end{align*}\n\nNote that $in(p)$ and $out(p)$ contain $a_q$ or $a_?$ (for usage of variable $a$ at the start of the program).\n\nTo solve the system of flow equations, start with $in(p) = \\emptyset$, then iteratively find $out(p)$ and $in(p)$, until convergence.\n\nConstant propagation: it's possible to replace variable $a$ in $p$ with $k$ if it exists $q: a = k$ such that $a_q$ reaches $p$ and no other definition $a_r$ ($r\\ne q$) reaches the entrance of $p$.\n\n\\subsection{Availability}\n\nA variable $a$ is available on the entrance of $p$ if every path from the initial node to $p$ includes a definition of $a$.\n", "meta": {"hexsha": "fd369813fa60400dd32d9056f0441682d58fde3b", "size": 2386, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "syntax/static-analysis.tex", "max_stars_repo_name": "TiberioG/FLC-cheatsheet", "max_stars_repo_head_hexsha": "d86e8ba9c80fece75ffccf47c273334b677f4934", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-01-13T14:36:20.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-18T16:22:18.000Z", "max_issues_repo_path": "syntax/static-analysis.tex", "max_issues_repo_name": "TiberioG/FLC-cheatsheet", "max_issues_repo_head_hexsha": "d86e8ba9c80fece75ffccf47c273334b677f4934", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "syntax/static-analysis.tex", "max_forks_repo_name": "TiberioG/FLC-cheatsheet", "max_forks_repo_head_hexsha": "d86e8ba9c80fece75ffccf47c273334b677f4934", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-05-21T11:05:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-17T14:59:50.000Z", "avg_line_length": 43.3818181818, "max_line_length": 197, "alphanum_fraction": 0.6944677284, "num_tokens": 700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7254204095563045}}
{"text": "\\documentclass[a4paper]{article}\n\n%% Language and font encodings\n\\usepackage[english]{babel}\n\\usepackage[utf8x]{inputenc}\n\\usepackage[T1]{fontenc}\n\n%% Sets page size, margins, and layout properties\n\\usepackage[a4paper,top=3cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}\n\\setlength{\\parskip}{\\baselineskip}\n\n%% Useful packages\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage[colorinlistoftodos]{todonotes}\n\\usepackage[colorlinks=true, allcolors=blue]{hyperref}\n\\usepackage{physics}\n\\usepackage{array}\n\n%% Math Operations\n\\DeclareMathOperator*{\\argmax}{arg\\,max}\n\\DeclareMathOperator*{\\argmin}{arg\\,min}\n\n\\title{LaTeX Equation Practice}\n\\author{Raymond Heberer\\\\\n  \\texttt{ray.heberer@gmail.com}}\n  \n\\usepackage{datetime}\n\\newdate{date}{25}{05}{2018}\n\\date{\\displaydate{date}}\n\n\\begin{document}\n\\maketitle\n\n\\section{Introduction}\n\n\\paragraph{} Ideas from mathematics underly virtually every technique and concept in Machine Learning (ML). While possessing a rigorous understanding of all these ideas is certainly not required, it can be beneficial. For the beginning practitioner, the scope of the math that forms the foundation of ML is intimidating, and many choose to reassure themselves by observing that modern programming frameworks mean that the ability to implement an algorithm is far removed from the ability to understand its mathematical underpinnings. \n\nThis \"top-down\" approach, emphasizing results over theory, is both effective and marketable. However, there are certain mathematical foundations of ML that are worth becoming familiar with.\n\nIn what follows, I state some of the most important equations a beginner should seek to understand when approaching ML. The contents of this document will lay the groundwork for at least one article on Medium.\n\n\\section{Functions and Derivatives}\n\n\\subsection{Variables and Function Notation}\n\n$$ y = f(x) $$\n\n\\subsection{Equation of a Line}\n\n$$ y = mx + b $$\n\n\\subsection{The Power Rule}\n\n$$ \\dv{}{x}\\left(x^n\\right)  = nx^{n-1} $$\n\n\\subsection{Finite Differences and Difference Quotients}\n\n$$ \\frac{\\Delta f(x)}{\\Delta x} = \\frac{f\\left(x+\\Delta x\\right) - f(x)}{\\Delta x} $$\n$$ \\Delta f(x) = f\\left(x+\\Delta x\\right) - f(x) $$\n$$ \\nabla f(x) = f(x) - f\\left(x - \\Delta x\\right) $$\n$$ \\delta f(x) = f\\left(x+\\frac{1}{2}\\Delta x\\right) - f\\left(x - \\frac{1}{2}\\Delta x\\right) $$\n\n\\section{Vectors and Matrices}\n\n$$ \\vec{a}, \\vec{b} \\in \\mathbb{R}^n $$\n\n\\subsection{Vector Arithmetic}\n\n$$ \\vec{a} + \\vec{b} = (a_1+b_1, a_2+b_2, \\ldots, a_n+b_n) $$\n$$ \\lambda\\vec{a} = (\\lambda a_1, \\lambda a_2,\\ldots, \\lambda a_n) $$\n\n\\subsection{Vector Magnitude}\n\n$$ |\\vec{a}| = \\sum_{i=1}^{n}\\sqrt{a_i^2} = \\sqrt{a_1 + a_2 + \\ldots + a_n} $$\n\n\\subsection{L1 and L2 Norms}\n\n$$ ||\\vec{a}||_1 = \\sum_{i=1}^{n} |a_i| $$\n$$ ||\\vec{a}||_1 = \\sum_{i=1}^{n} \\sqrt{a_i^2} $$\n\n\\subsection{Matrix Multiplication}\n\n$$ \\mathbf{A} \\in \\mathbb{R}^{m \\times n}, \\mathbf{B} \\in \\mathbb{R}^{n \\times p} $$\n\n$$ \\mathbf{A} = \n\\begin{pmatrix}\na_{11} & a_{12} & \\ldots & a_{1n} \\\\\na_{21} & a_{22} & \\ldots & a_{2n} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\na_{m1} & a_{m2} & \\ldots & a_{mn}\n\\end{pmatrix}\n$$\n\n$$ \\mathbf{AB} \\in \\mathbb{R}^{m \\times p} $$\n\n$$ \\mathbf{C} = \\mathbf{AB} = \n\\begin{pmatrix}\nc_{11} & c_{12} & \\ldots & c_{1p} \\\\\nc_{21} & c_{22} & \\ldots & c_{2p} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\nc_{m1} & c_{m2} & \\ldots & c_{mp}\n\\end{pmatrix}\n$$\n\n$$ c_{ij} = a_{i1}b_{1j} + a_{i2}b_{2j} + \\ldots + a_{im}b_{mj} = \\sum_{k=1}^{m}a_{ik}b_{kj} $$\n\n\\subsection{Matrix Inversion}\n\n$$ \\mathbf{A} \\in \\mathbb{R}^{n \\times n} $$\n\n$$ \\mathbf{A}^{-1}\\mathbf{A} = \\mathbf{AA}^{-1} = \\mathbf{I}_n $$\n\n$$ \\mathbf{A}^{-1} \\in \\mathbb{R}^{n \\times n} $$\n\n$$ \\mathbf{I} = \n\\begin{pmatrix}\n1 & 0 & \\ldots & 0 \\\\\n0 & 1 & \\ldots & 0 \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\n0 & 0 & \\ldots & 1\n\\end{pmatrix}\n$$\n\n\\section{Statistical Relationships and Procedures}\n\n\\subsection{Correlation}\n\n$$ \\rho_{\\mathbf{X}, \\mathbf{Y}} = \\frac{\\mathbf{cov}(\\mathbf{X}, \\mathbf{Y})}{\\sigma_{\\mathbf{X}}\\sigma_{\\mathbf{Y}}} $$\n\n$$ = \\frac{E[(\\mathbf{X}-\\mu_{\\mathbf{X}})(\\mathbf{Y}-\\mu_{\\mathbf{Y}})]}{\\sigma_{\\mathbf{X}}\\sigma_{\\mathbf{Y}}} $$\n\n$$ r_{xy} = \\frac{\\sum_{i=1}^{n}(x_i-\\bar{x})(y_i-\\bar{y})}\n{\\sqrt{\n\\sum_{i=1}^{n}(x_i-\\bar{x})^2\n\\sum_{i=1}^{n}(y_i-\\bar{y})^2\n}} $$\n\n$$ \\bar{x} = \\frac{1}{n}\\sum_{i=1}^{n}x_i $$\n\n\\subsection{Principal Components Analysis}\n\n$$ \\mathbf{w_{(1)}} = \\argmax_{||\\mathbf{w}||=1}\\left\\{ ||\\mathbf{Xw}||^2 \\right\\} = \\argmax_{||\\mathbf{w}||=1}\\left\\{ ||\\mathbf{w}^T\\mathbf{X}^T\\mathbf{Xw}||^2 \\right\\}$$\n\n$$ \\mathbf{w_{(1)}}=\\argmax\\left\\{\\frac{||\\mathbf{w}^T\\mathbf{X}^T\\mathbf{Xw}||^2}{\\mathbf{w}^T\\mathbf{w}}\\right\\}$$\n\n$$ \\mathbf{W}_k = \\argmax_{||\\mathbf{w}||=1}\\left\\{ ||\\mathbf{\\hat{X}}_k\\mathbf{w}||^2 \\right\\} $$\n\n$$ \\mathbf{\\hat{X}}_k = \\mathbf{X}-\\sum_{s=1}^{k-1}\\mathbf{Xw}_{(s)}\\mathbf{w}_{(s)}^T $$\n\n\\subsubsection{Singular-Value Decomposition (SVD)}\n\n$$ \\mathbf{M} \\in \\mathbb{R}^{m \\times n}$$\n\n$$ \\mathbf{M} = \\mathbf{U\\Sigma V}^* $$\n\n\\begin{itemize}\n  \\item The nonzero singular values are the square roots of the nonzero eigenvalues of $\\mathbf{M}^*\\mathbf{M}$ or $\\mathbf{MM}^*$\n  \\item $\\mathbf{\\Sigma}$ is a diagonal $(m \\times n)$ matrix of non-negative real numbers, known as the \\textbf{singular values} of $\\mathbf{M}$\n  \\item The columns of $\\mathbf{V}$ (right singular vectors) are eigenvectors of $\\mathbf{M}^*\\mathbf{M}$\n  \\item The columns of $\\mathbf{U}$ (left singular vectors) are eigenvectors of $\\mathbf{MM}^*$\n\\end{itemize}\n\n\\end{document}\n\n", "meta": {"hexsha": "a221e1864e0ecf63d154fc3c32c307f2253ed808", "size": 5565, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Week 04 Presenting/LaTeX-equation-practice.tex", "max_stars_repo_name": "rayheberer/LambdaCodingChallenges", "max_stars_repo_head_hexsha": "ae73493f2161264a0c39b809347e0ccea9576e51", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2018-04-18T07:43:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-13T17:24:24.000Z", "max_issues_repo_path": "Week 04 Presenting/LaTeX-equation-practice.tex", "max_issues_repo_name": "SNOmad1/LambdaSchoolDataScience", "max_issues_repo_head_hexsha": "ae73493f2161264a0c39b809347e0ccea9576e51", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Week 04 Presenting/LaTeX-equation-practice.tex", "max_forks_repo_name": "SNOmad1/LambdaSchoolDataScience", "max_forks_repo_head_hexsha": "ae73493f2161264a0c39b809347e0ccea9576e51", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2018-08-18T15:59:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-17T02:14:51.000Z", "avg_line_length": 33.3233532934, "max_line_length": 534, "alphanum_fraction": 0.6506738544, "num_tokens": 2121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117812622842, "lm_q2_score": 0.8774767922879693, "lm_q1q2_score": 0.7254204019687024}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{numprint}\n\n\\author{Daniel Fernandes Martins (danielfmt)}\n\\title{Question \\#7 Solution}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Cross-Validation}\n\nThis question gives us 3 data points: $(-1,0)$, $(\\rho,1)$, $(1,0)$, and a choice\nof two models: constant $[h_0(x)=b]$ and linear $[h_1(x)=ax+b]$, and asks at\nwhich $\\rho \\geq 0$ the two models give the same cross-validation error assuming\nwe use leave-one-out cross-validation and the squared error measure.\n\nThe cross-validation error for a model $m$ on these 3 points is\n\n\\begin{equation*}\nE_{cv}^{(m)}=\\frac{1}{3}(e_1^{(m)} + e_2^{(m)} + e_3^{(m)}),\n\\end{equation*}\n\nwhere $e_n^{(m)}$ is the squared error measure for point $n$ and model $m$:\n\n\\begin{equation*}\ne_n^{(m)}=(h_m(x_n)-y_n)^2\n\\end{equation*}\n\nNow we need to compute the cross-validation error for all three permutations on\nboth models.\n\n\\subsection{The Constant Model}\n\nIn the constant model $h_0$, the best fit is found by averaging the values of\n$y$ coordinate of all points.\n\nTaking the points $(-1,0)$ and $(1,0)$ for training, and $(\\rho,1)$ for validation,\nthe validation error is\n\n\\begin{equation*}\ne_1^{(0)} = \\left(\\frac{0+0}{2} - 1\\right)^2 = 1.\n\\end{equation*}\n\nWe get the same value for the last two permutations:\n\n\\begin{equation*}\ne_2^{(0)} = e_3^{(0)} = \\left(\\frac{0+1}{2} - 0\\right)^2 = \\frac{1}{4}\n\\end{equation*}\n\nThus the cross-validation error $E_{cv}^{(0)}$ for the constant model $h_0$ is\n\n\\begin{equation*}\nE_{cv}^{(0)} = \\frac{1}{3} \\left( 1 + \\frac{1}{4} + \\frac{1}{4} \\right).\n\\end{equation*}\n\n\\subsection{The Linear Model}\n\nWe know that, given two points, the best fit for the linear model $h_1$ is a\nline that passes through both of them.\n\nThe first permutation (training: $(-1,0)$ $(1,0)$, validation: $(\\rho,1)$), is\neasy to compute because this line has slope $m=0$:\n\n\\begin{equation*}\ne_1^{(1)} = (1 - 0)^2 = 1\n\\end{equation*}\n\nFor the remaining two permutations, we need to find the equation for the line\norder to compute the squared error for the validation point.\n\nThe slope of the line passing through the points $(-1,0)$ and $(\\rho,1)$ is\ngiven by\n\n\\begin{equation*}\nm = \\frac{1-0}{\\rho-(-1)} = \\frac{1}{\\rho+1},\n\\end{equation*}\n\nand in order to find the equation for that line, just pick any point $(x_1,y_1)$\nand plug it on the formula $y-y_1 = m(x-x_1)$. For instance, if we pick\n$(x_1,y_1)=(-1,0)$, we get\n\n\\begin{equation*}\ny = \\frac{x+1}{\\rho+1}.\n\\end{equation*}\n\nFinally, to compute the squared error for this permutation, plug the $x$\ncoordinate of the validation point $(1,0)$ in the line equation, subtract the\nresult by $y$ and square it, resulting in\n\n\\begin{equation*}\ne_2^{(1)} = \\left( \\frac{2}{\\rho+1} \\right)^2.\n\\end{equation*}\n\nIf you do same thing in order to compute the validation error for the last\npermutation, you will get\n\n\\begin{equation*}\ne_3^{(1)} = \\left( \\frac{-2}{\\rho-1} \\right)^2.\n\\end{equation*}\n\nSo the cross-validation error $E_{cv}^{(1)}$ for the linear model $h_1$ is given\nby\n\n\\begin{equation*}\nE_{cv}^{(1)} = \\frac{1}{3} \\left( 1 + \\left(\\frac{2}{\\rho+1}\\right)^2 +\n \\left(\\frac{-2}{\\rho-1}\\right)^2 \\right).\n\\end{equation*}\n\n\\subsection{Solving For $\\rho$}\n\nNow that we found $E_{cv}^{(m)}$ for both models, we can form a single equation\n\n\\begin{equation*}\n\\frac{1}{3} \\left( 1 + \\left(\\frac{2}{\\rho+1}\\right)^2 + \\left(\\frac{-2}{\\rho-1}\\right)^2 \\right) =\n\\frac{1}{3} \\left( 1 + \\frac{1}{4} + \\frac{1}{4} \\right),\n\\end{equation*}\n\nand solve it for $\\rho \\geq 0$ in order to get the correct answer\n$\\rho=\\sqrt{9+4\\sqrt{6}}$.\n\n\\end{document}\n", "meta": {"hexsha": "83a1e30f03f7d777d7b71e876dd3d6571b9b2d32", "size": 3591, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week-07/math/q07.tex", "max_stars_repo_name": "danielfm/edx-learning-from-data", "max_stars_repo_head_hexsha": "1675e14c20fc1b7ad54d2704b9c8a941e043cbcb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 98, "max_stars_repo_stars_event_min_datetime": "2015-04-27T06:55:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:09:19.000Z", "max_issues_repo_path": "week-07/math/q07.tex", "max_issues_repo_name": "danielfm/edx-learning-from-data", "max_issues_repo_head_hexsha": "1675e14c20fc1b7ad54d2704b9c8a941e043cbcb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-05-14T19:33:33.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-12T13:07:41.000Z", "max_forks_repo_path": "week-07/math/q07.tex", "max_forks_repo_name": "danielfm/edx-learning-from-data", "max_forks_repo_head_hexsha": "1675e14c20fc1b7ad54d2704b9c8a941e043cbcb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 56, "max_forks_repo_forks_event_min_datetime": "2015-01-10T08:18:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-28T08:46:22.000Z", "avg_line_length": 28.728, "max_line_length": 99, "alphanum_fraction": 0.6677805625, "num_tokens": 1278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732855, "lm_q2_score": 0.8872045952083047, "lm_q1q2_score": 0.7253558479782034}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=1}^\\infty \\frac{\\cos \\frac\\pi3 n}{n^2}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Note}\r\n\r\nThe series $\\displaystyle \\sum_{n=1}^\\infty \\frac{\\cos \\frac\\pi3 n}{n^2}$ is NOT an alternating series.\r\n\r\n\\subsection*{Solution}\r\n\r\nWe consider \r\n\\[\r\n\\sum_{n=1}^\\infty \\left|\\frac{\\cos \\frac\\pi3 n}{n^2}\\right|\r\n= \\sum_{n=1}^\\infty \\frac{|\\cos \\frac\\pi3 n|}{n^2}\r\n\\]\r\nNote that \r\n\\[ 0 \\leq  |\\cos \\frac\\pi3 n| \\leq 1\\]\r\nso by dividing all three sides by $n^2$, we have\r\n\\[ 0 \\leq  \\frac{|\\cos \\frac\\pi3 n|}{n^2} \\leq \\frac1{n^2}.\\]\r\nThe series $\\displaystyle \\sum \\frac1{n^2}$ converges by the $p$-test. Since, terms of the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{|\\cos \\frac\\pi3 n|}{n^2}$ are positive, by the Direct Comparison test, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{|\\cos \\frac\\pi3 n|}{n^2}$ converges.\r\n\r\nTherefore the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{\\cos \\frac\\pi3 n}{n^2}$ converges by the Absolute Convergence Test. In fact, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{\\cos \\frac\\pi3 n}{n^2}$ is absolutely convergent.\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "26831d7b77db09cc47988057db200e545a37065f", "size": 1808, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/k4.tex", "max_stars_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_stars_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "key/series/k4.tex", "max_issues_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_issues_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "key/series/k4.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 36.8979591837, "max_line_length": 295, "alphanum_fraction": 0.6515486726, "num_tokens": 638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825655188238, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7252649706167765}}
{"text": "\\subsection{Hypergraphs}\\label{subsec:hypergraphs}\n\n\\begin{definition}\\label{def:hypergraph}\n  Fix a \\hyperref[def:set]{set} \\( V \\), whose members we will call \\term{vertices} or \\term{nodes}, and a disjoint from \\( V \\) set \\( E \\), whose members we will call \\term{hyperedges}.\n\n  A \\term{hypergraph} is a tuple \\( H = (V, E, \\mscrE) \\), where \\( \\mscrE: E \\multto V \\) is a \\hyperref[def:multi_valued_function/total]{total multi-valued function} whose role is to give us a nonempty set of endpoints \\( \\mscrE(e) \\) for each edge \\( e \\in E \\).\n\n  \\begin{figure}[h]\n    \\begin{equation}\\label{eq:fig:def:hypergraph}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/def__hypergraph.pdf}\n      \\end{aligned}\n    \\end{equation}\n    \\caption{A hypergraph containing four hyperedges of rank two and one of rank four.}\\label{fig:def:hypergraph}\n  \\end{figure}\n\n  \\begin{thmenum}\n    \\thmitem{def:hypergraph/cardinality} The \\term{cardinality} of a hyperedge \\( e \\) is the \\hyperref[thm:cardinality_existence]{cardinality}\n    \\begin{equation*}\n      \\card(e) \\coloneqq \\card(\\mscrE(e))\n    \\end{equation*}\n    of the set of all vertices of \\( e \\).\n\n    Hyperedges of rank \\( 1 \\) are called \\term{loops} and hyperedges of rank \\( 2 \\) are called \\term{edges}. Loops are often considered to be edges, especially in \\hyperref[def:undirected_multigraph]{multigraphs}.\n\n    \\thmitem{def:hypergraph/parallel_hyperedges} We say that the hyperedges \\( e \\) and \\( d \\) are parallel if they have the same endpoints.\n\n    \\thmitem{def:hypergraph/incidence} We say that the vertex \\( v \\) and the hyperedge \\( e \\) are \\term{incident} if \\( v \\) is an endpoint \\( e \\).\n\n    \\thmitem{def:hypergraph/adjacency} We say that \\( v \\) and \\( w \\) are \\term{adjacent vertices} if there exists an hyperedge \\( e \\) such that both \\( v \\) and \\( w \\) are endpoints of \\( e \\).\n\n    Similarly, we say that \\( e \\) and \\( d \\) are \\term{adjacent hyperedges} if they have a common endpoint.\n\n    \\thmitem{def:hypergraph/order} The \\term{order} \\( \\ord(H) \\) of the hypergraph \\( H \\) is the \\hyperref[thm:cardinality_existence]{cardinality} of \\( V \\).\n\n    We say that the hypergraph is finite if both \\( V \\) and \\( E \\) are finite and infinite otherwise. If no parallel hyperedges are allowed, the hypergraph is finite if \\( \\ord(H) \\) is finite.\n\n    \\thmitem{def:hypergraph/degree} The \\term{degree} \\( \\deg(v) \\) of a vertex \\( v \\in V \\) is the cardinality of set\n    \\begin{equation*}\n      \\set{ e \\in E \\given v \\T{is an endpoint of} e }.\n    \\end{equation*}\n\n    If \\( \\deg(v) = 0 \\), we say that \\( v \\) is an \\term{isolated vertex}, especially in connection with \\fullref{def:quiver_geometric_realization/undirected}.\n\n    The degree \\( \\deg(H) \\) of the hypergraph itself is the maximum of the degrees of all vertices. It is possible that the maximum in \\( \\deg(H) \\) is not attained if \\( H \\) is infinite.\n\n    We say that the graph is \\term{locally finite} if the degree of every vertex is finite.\n\n    This is not to be confused with \\hyperref[def:category_size]{locally finite categories}.\n\n    \\thmitem{def:hypergraph/submodel} The hypergraph \\( H' = (V', E', \\mscrE') \\) is a is a sub-hypergraph of \\( H = (V, E, \\mscrE) \\) if \\( V' \\subseteq V \\), \\( E' \\subseteq E \\) and \\( \\mscrE' \\) is a \\hyperref[def:multi_valued_function/restriction]{restriction} of \\( \\mscrE \\) to \\( E' \\).\n\n    We say that sub-hypergraph \\( H' \\) is \\term{full} if\n    \\begin{equation}\\label{eq:def:hypergraph/submodel/full}\n      E' = \\set{ e \\in E \\given \\mscrE(e) \\subseteq V' }.\n    \\end{equation}\n\n    In this case, we also say that \\( V' \\) \\term{induces} the sub-hypergraph \\( H' \\).\n\n    \\thmitem{def:hypergraph/trivial} Unlike the \\hyperref[def:group/trivial]{trivial group} \\( \\set{ e } \\) or \\hyperref[def:partially_ordered_set/trivial]{empty ordered set}, which are unique up to an isomorphism, there is no single agreed upon graph called the \\enquote{trivial hypergraph}.\n\n    An unambiguous concept is that of an \\term{edgeless hypergraph}, in which the set of hyperedges is empty, but the set of vertices may or may not be empty. Every hypergraph \\( H: E \\to V \\) has \\( 2^{\\ord(V)} \\) edgeless sub-hypergraphs (one for each subset of \\( V \\)).\n\n    The \\term{order-zero hypergraph} \\( H: \\varnothing \\multto \\varnothing \\) is the unique hypergraph that is a sub-hypergraph of all others.\n\n    The terms \\term{empty hypergraph}, \\term{null hypergraph} and \\term{trivial hypergraph} may refer to either edgeless graphs or the order-zero graph, depending on the author and the situation.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:family_of_sets_induces_hypergraph}\n  Every \\hyperref[rem:family_of_sets]{family} of nonempty sets \\( \\mscrA \\) induces a \\hyperref[def:hypergraph]{hypergraph} as follows:\n  \\begin{itemize}\n    \\item The set of vertices is \\( \\bigcup \\mscrA \\).\n    \\item The set of hyperedges is \\( \\mscrA \\) itself.\n  \\end{itemize}\n\\end{proposition}\n\\begin{proof}\n  The hypergraph is given by the function\n  \\begin{equation*}\n    \\begin{aligned}\n      &H: \\mscrA \\multto \\bigcup \\mscrA \\\\\n      &\\mscrE(A) \\coloneqq A,\n    \\end{aligned}\n  \\end{equation*}\n  which is better represented as the binary relation\n  \\begin{equation*}\n    \\set{ (A, x) \\given A \\in \\mscrA \\T{and} x \\in A }.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{example}\\label{ex:hypergraphs_not_induced_by_family}\n  The hypergraph \\eqref{eq:fig:def:hypergraph} is a counterexample to the converse of \\fullref{thm:family_of_sets_induces_hypergraph}. It cannot be represented as a family of sets because the edges \\( e_2 \\) and \\( \\widehat{e_2} \\) are \\hyperref[def:hypergraph/parallel_hyperedges]{parallel} and would be represented by the same set.\n\n  Another counterexample is a hypergraph with a nonempty vertex set and no hyperedges. The union of the endpoints of all hyperedges is empty and is thus only a strict subset of the vertices.\n\\end{example}\n\n\\begin{definition}\\label{def:category_of_small_hypergraphs}\n  Suppose that we are given a \\hyperref[def:grothendieck_universe]{Grothendieck universe} \\( \\mscrU \\), which is safe to assume to be the smallest suitable one as explained in \\fullref{def:large_and_small_sets}.\n\n  We denote the \\hyperref[def:category]{category} of \\( \\mscrU \\)-small \\hyperref[def:hypergraph]{hypergraphs} by \\( \\ucat{HypGph} \\) or, if the universe is clear from the context, simply by \\( \\cat{HypGph} \\). See \\fullref{def:category_size} for a further discussion of universes and categories.\n\n  \\begin{itemize}\n    \\item The \\hyperref[def:category/objects]{set of objects} \\( \\obj(\\cat{HypGph}) \\) is the set of all \\( \\mscrU \\)-small hypergraphs, i.e. the hypergraphs \\( H = (V, E, \\mscrE) \\) such that \\( V \\) and \\( E \\) are both members of \\( \\mscrU \\).\n\n    \\item The \\hyperref[def:category/morphisms]{set of morphisms} \\( \\cat{HypGph}(H, G) \\) from \\( H \\) to \\( G \\) is the set hypergraph homomorphisms. Given two hypergraphs \\( H: E_H \\multto V_H \\) and \\( G: E_G \\multto V_G \\), a \\term{hypergraph homomorphism} is a pair of functions\n    \\begin{equation}\\label{eq:def:category_of_small_hypergraphs/homomorphism}\n      \\begin{cases}\n        f_V: V_H \\to V_G \\\\\n        f_E: E_H \\to E_G\n      \\end{cases}\n    \\end{equation}\n    such that, for every hyperedge \\( e \\in E_H \\), if \\( v \\in V_H \\) is an endpoint of \\( e \\), then \\( f_V(v) \\) is an endpoint of \\( f_E(e) \\).\n\n    Note that \\enquote{graph embedding} commonly refers to an embedding of its \\hyperref[def:quiver_geometric_realization/undirected]{geometric realization}, hence we will avoid the term when referring to injective hypergraph homomorphisms. Furthermore, it should be clarified whether we mean \\enquote{injective on vertices} or \\enquote{injective on edges}, which is an important distinction in category theory --- see \\fullref{def:functor_invertibility}.\n\n    \\item The \\hyperref[def:category/composition]{composition of the morphisms}\n    \\begin{align*}\n      &(f_V, f_E) \\in \\cat{HypGph}(A, B),\n      &(g_V, g_E) \\in \\cat{HypGph}(B, C)\n    \\end{align*}\n    is the morphism\n    \\begin{equation*}\n      (g_V \\bincirc f_V, g_E \\bincirc f_E) \\in \\cat{HypGph}(A, C).\n    \\end{equation*}\n\n    \\item The \\hyperref[def:category/identity]{identity morphism} on the hypergraph \\( H = (V, E, \\mscrE) \\) is the pair of \\hyperref[def:multi_valued_function/identity]{identity functions} \\( (\\id_V, \\id_H) \\).\n  \\end{itemize}\n\\end{definition}\n\n\\begin{definition}\\label{def:hypergraph_incidence_matrix}\n  Let \\( H = (V, E, \\mscrE) \\) be a finite hypergraph. Its \\term{incidence matrix}\n  \\begin{equation*}\n    M = \\seq{ M_{ve} }_{v \\in V, e \\in E}\n  \\end{equation*}\n  has elements\n  \\begin{equation*}\n    M_{ve} \\coloneqq \\begin{cases}\n      1,  &v \\T{is \\hyperref[def:hypergraph/incidence]{incident} to} e \\\\\n      0,  &\\T{otherwise.}\n    \\end{cases}\n  \\end{equation*}\n\n  Compare this definition to \\fullref{def:quiver_incidence_matrix}.\n\\end{definition}\n\n\\begin{example}\\label{ex:def:hypergraph_incidence_matrix}\n  The \\hyperref[def:hypergraph_incidence_matrix]{incidence matrix} of the hypergraph \\eqref{eq:fig:def:hypergraph} is\n  \\begin{equation}\\label{eq:ex:def:hypergraph_incidence_matrix}\n    \\begin{blockarray}{cccccc}\n        & e_1 & e_2 & \\widehat{e_2} & e_3 & e_4 \\\\\n      \\begin{block}{c(ccccc)}\n      a & 1   & 1   & 1             &     &     \\\\\n      b & 1   &     &               & 1   &     \\\\\n      c &     & 1   & 1             &     & 1   \\\\\n      d &     &     &               & 1   & 1   \\\\\n      e &     &     &               &     & 1   \\\\\n      f &     &     &               &     & 1   \\\\\n      \\end{block}\n    \\end{blockarray}\n  \\end{equation}\n\n  Every column corresponds to a hyperedge and its nonzero elements are the endpoints of the hyperedge.\n\\end{example}\n\n\\begin{definition}\\label{def:hypergraph_vector_spaces}\n  Let \\( H = (V, E, \\mscrE) \\) be a \\hyperref[def:hypergraph]{hypergraph}. We introduce several \\hyperref[def:vector_space]{vector spaces} that allow us to study hypergraphs using linear algebra.\n\n  \\begin{thmenum}\n    \\thmitem{def:hypergraph_vector_spaces/vertex} The \\term{vertex space} \\( \\BbbF_2^V \\) is the \\hyperref[thm:functions_over_ring_form_algebra]{function space} \\( \\BbbF_2^V \\), where \\( \\BbbF_2 \\) is the \\hyperref[thm:f2_is_boolean_algebra]{two-element field}.\n\n    Every subset \\( U \\subseteq V \\) of vertices induces a unique vector \\( \\vect{U} = \\seq{ \\vect{U}_u }_{u \\in U} \\) in the \\hyperref[def:hypergraph_vector_spaces/vertex]{vertex space} \\( \\BbbF_2^V \\) such that\n    \\begin{equation*}\n      \\vect{U}_u \\coloneqq \\begin{cases}\n        1, &u \\in A \\\\\n        0, &u \\not\\in A\n      \\end{cases}\n    \\end{equation*}\n\n    This vector is called the \\term{characteristic vector} of \\( U \\). Conversely, every vector in \\( \\BbbF_2^V \\) induces a set of vertices. If \\( U \\) consists of a single vertex \\( u \\), we write \\( \\vect{u} \\) rather than \\( \\vect{\\set{u}} \\).\n\n    Without a choice of ordering of \\( V \\), there is no canonical basis in \\( \\BbbF_2^V \\). Thus, even for finite graphs, we cannot in general regard the vectors of \\( \\BbbF_2^V \\) as ordered tuple.\n\n    \\thmitem{def:hypergraph_vector_spaces/edge} Analogously, the \\term{hyperedge space} \\( \\BbbF_2^E \\) is the \\hyperref[thm:functions_over_ring_form_algebra]{function space} \\( \\BbbF_2^E \\). Every subset of \\( E \\) induces a unique characteristic vector in \\( \\BbbF_2^E \\) and vice versa.\n\n    The space is motivated by \\hyperref[def:undirected_multigraph_path]{undirected paths} and their \\hyperref[def:undirected_multigraph_path/characteristic_vector]{characteristic vectors}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:graphs_as_linear_transformations}\n  Let \\( V = \\set{ 1, \\ldots, m } \\) and \\( E = \\set{ 1, \\ldots, n } \\). Then there is a bijection between the \\( m \\times n \\) \\hyperref[def:array/matrix]{matrices} over \\( \\BbbF_2 \\) and the \\hyperref[def:hypergraph]{hypergraphs} \\( H = (V, E, \\mscrE) \\).\n\\end{proposition}\n\\begin{proof}\n  The \\hyperref[def:hypergraph_incidence_matrix]{incidence matrix} of every hypergraph is a matrix in \\( \\BbbF_2^{m \\times n} \\).\n\n  Conversely, let \\( M = \\seq{ M_{ve} } \\in \\BbbF_2^{m \\times n} \\) and define the hypergraph \\( H \\coloneqq (V, E, \\mscrE) \\), where\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\mscrE: E \\multto V \\\\\n      &\\mscrE(e) \\coloneqq \\set{ v \\in 1, \\ldots, n \\given M_{ve} = 1 }.\n    \\end{aligned}\n  \\end{equation*}\n\n  Then the adjacency matrix of \\( H \\) is \\( M \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:hypergraph_transversal}\\mcite[32]{GondranMinoux1984Graphs}\n  Let \\( H = (V, E, \\mscrE) \\) be a \\hyperref[def:hypergraph]{hypergraph}. We say that a set \\( T \\subseteq V \\) of vertices is a \\term{transversal} of \\( H \\) if it is incident to every edge of \\( H \\).\n\\end{definition}\n\n\\begin{example}\\label{ex:hypergraph_vertex_set_is_transversal}\n  Every hypergraph has at least one transversal since the vertex set it itself a transversal.\n\\end{example}\n\n\\begin{definition}\\label{def:hypergraph_minimal_transversal}\n  A transversal \\( T \\) of the hypergraph \\( H = (V, E, \\mscrE) \\) is said to be \\term{minimal} if any of the following equivalent conditions hold:\n  \\begin{thmenum}\n    \\thmitem{def:hypergraph_minimal_transversal/order} \\( T \\) is a minimal \\hyperref[def:partially_ordered_set_extremal_points/maximal_and_minimal_element]{element} under \\hyperref[def:subset]{set inclusion} in the set of all transversals of \\( H \\).\n\n    \\thmitem{def:hypergraph_minimal_transversal/singleton} For every vertex \\( v \\) in \\( T \\) there exists a hyperedge \\( e_v \\in E \\) such that\n    \\begin{equation*}\n      T \\cap \\mscrE(e_v) = \\set{ v }.\n    \\end{equation*}\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:hypergraph_minimal_transversal/order}{def:hypergraph_minimal_transversal/singleton} Let \\( T \\) be minimal under inclusion among all transversals.\n\n  Fix a vertex \\( v \\in T \\). Since \\( T \\) is minimal, the set \\( T \\setminus \\set{ v } \\) is not a transversal. So there exists a hyperedge \\( e_v \\in E \\) such that \\( (T \\setminus \\set{ v }) \\cap \\mscrE(e_v) = \\varnothing \\).\n\n  Now since \\( T \\) is a transversal for \\( H \\), the set \\( T \\cap \\mscrE(e_v) \\) is nonempty and thus\n  \\begin{align*}\n    T \\cap \\mscrE(e_x)\n    &=\n    \\parens[\\Big]{ (T \\setminus \\set{ v }) \\cup \\set{ v } } \\cap \\mscrE(e_v)\n    \\reloset {\\eqref{eq:def:semilattice/distributive_lattice/finite/meet_over_join}} = \\\\ &=\n    \\underbrace{\\parens[\\Big]{ (T \\setminus \\set{ v }) \\cap \\mscrE(e_v) }}_{\\varnothing} \\cup \\parens[\\Big]{ \\set{ v } \\cap \\mscrE(e_v) }\n    = \\\\ &=\n    \\set{ v }.\n  \\end{align*}\n\n  \\ImplicationSubProof{def:hypergraph_minimal_transversal/singleton}{def:hypergraph_minimal_transversal/order} Now suppose that for every vertex \\( v \\in T \\) there exists a hyperedge \\( e_v \\in E \\) such that \\( T \\cap \\mscrE(e_v) = \\set{ v } \\).\n\n  Suppose that \\( T \\) is not minimal. Then there exists some vertex \\( w \\in T \\) be such that \\( T \\setminus \\set{ w } \\) is a transversal. But our assertion gives us an edge \\( e_u \\in E \\) such that \\( T \\cap \\mscrE(e_u) = \\set{ w } \\). Clearly the set \\( T \\setminus \\set{ w } \\) cannot be a transversal of \\( H \\) since\n  \\begin{equation*}\n    (T \\setminus \\set{ w }) \\cap \\mscrE(e_u) = \\varnothing.\n  \\end{equation*}\n\n  This contradiction proves that \\( T \\) is minimal under set inclusion.\n\\end{proof}\n\n\\begin{example}\\label{ex:hypergraph_with_no_minimal_transversal}\n  We will give an example of a hypergraph without a minimal transversal.\n\n  For every nonnegative integer \\( n \\) define the set\n  \\begin{equation*}\n    e_n \\coloneqq \\set{ n, n + 1, n + 2, \\ldots }.\n  \\end{equation*}\n\n  Let \\( H \\) be the hypergraph whose hyperedges are \\( e_1, e_2, \\cdots \\). The set of vertices is \\( e_1 \\), hence \\( e_1 \\) is also a transversal.\n\n  Now assume that \\( T \\) is a minimal transversal for \\( H \\). Since, by \\fullref{thm:natural_numbers_are_well_ordered}, the natural numbers are well-ordered, \\( T \\) has a minimum. Let \\( n_0 \\coloneqq \\min T \\).\n\n  But \\( T \\setminus \\set{ n_0 } \\) is also a transversal because each hyperedge \\( e_n \\) intersects \\( T \\) at infinitely many points besides \\( n_0 \\).\n\n  The obtained contradiction shows that \\( H \\) has no minimal transversal.\n\\end{example}\n\n\\begin{theorem}[Hypergraph minimal transversal existence]\\label{thm:hypergraphs_have_minimal_transversal}\n  Every \\hyperref[def:hypergraph]{hypergraph} has a \\hyperref[def:hypergraph_minimal_transversal]{minimal transversal}.\n\n  In \\hyperref[def:zfc]{\\logic{ZF}} this theorem is equivalent to the \\hyperref[def:zfc/choice]{axiom of choice} --- see \\fullref{thm:axiom_of_choice_equivalences/hypergraph}.\n\\end{theorem}\n\\begin{proof}\n  The proof is merely a translation of the axiom of choice into the language of hypergraphs.\n\n  \\ImplicationSubProof[def:zfc/choice]{the axiom of choice}[thm:hypergraphs_have_minimal_transversal]{minimal transversal existence} Let \\( H = (V, E, \\mscrE) \\) be a hypergraph. Then\n  \\begin{equation*}\n    \\set{ \\mscrE(e) \\given e \\in E }\n  \\end{equation*}\n  is a family of nonempty sets and thus there exists a set \\( B \\subseteq V \\) such that \\( B \\cap \\mscrE(e) \\) for every hyperedge \\( e \\in E \\). This is a minimal transversal by \\fullref{def:hypergraph_minimal_transversal/singleton}.\n\n  \\ImplicationSubProof[thm:hypergraphs_have_minimal_transversal]{minimal transversal existence}[def:zfc/choice]{axiom of choice} Let \\( \\mscrA \\) be an arbitrary family of nonempty sets. Let \\( H \\) be the hypergraph \\hyperref[thm:family_of_sets_induces_hypergraph]{induced by} \\( \\mscrA \\). Let \\( T \\) be a minimal transversal of \\( H \\). Then, by definition, for every hyperedge \\( e \\in \\mscrA \\), the intersection \\( T \\cap \\mscrE(e) \\) is a singleton set. Hence, \\( T \\) is the image of a \\hyperref[def:choice_function]{choice function} for \\( \\mscrA \\).\n\\end{proof}\n", "meta": {"hexsha": "ee23ea5ec2724e84f5e27de934e2b784a67b5d1d", "size": 17908, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/hypergraphs.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/hypergraphs.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/hypergraphs.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.0563380282, "max_line_length": 560, "alphanum_fraction": 0.6803663167, "num_tokens": 5739, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256512199033, "lm_q2_score": 0.8615382165412808, "lm_q1q2_score": 0.7252649701906978}}
{"text": "%================================\n\\section{Continuity}\n%================================\n\n\n% https://en.wikipedia.org/wiki/Base_(topology)#Theorems\n\n\n%--------------------------------\n\\begin{definition}\n\t[continuous maps]\n\t\\label{def: continuous maps}\n\tLet $(X, \\mathcal T_X)$ and $(Y, \\mathcal T_Y)$ be topological spaces. A map $f: X \\to Y$ is said to be \\textit{continuous} iff for any open set $U$ in $Y$, its preimage in $X$ under $f$ is open.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tIn Definition \\ref{def: continuous maps}, note that even if for any open set $U$ in $X$, $f[X]$ is open in $Y$, $f$ is not necessarily continuous. For example, let $X = (\\mathbb R, \\mathcal T_X)$ with $\\mathcal T_X$ induced by standard Euclidean metric, let $Y=(\\mathbb R, \\mathcal T_Y)$ with $\\mathcal T_Y$ as a indiscrete topology, and define\n\t$$\n\tf(x) = [x],\n\t$$\n\twhere $[x]$ denotes the integer part of $x$. Then for all $U \\subseteq X$, $f[U]$ is open in $Y$, but by Definition \\ref{def: continuous maps}, $f$ is not continuous.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tLet $(X, \\mathcal T_X)$ and $(Y, \\mathcal T_Y)$ be topological spaces, if $\\mathcal T_X$ is the discrete topology on $X$, then any function with domain $X$ is continuous. If $\\mathcal T_Y$ is the indiscrete topology on $Y$, then any function with codomain $Y$ is continuous.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tA function is continuous bijection does not implies that its inverse is continuous. For example, let $X$ be any set and let $\\mathcal T$ and $\\mathcal T'$ be its topologies. If $\\mathcal T$ is finer than $\\mathcal T'$, then any bijection $f: (X, \\mathcal T) \\to (X, \\mathcal T')$ is continuous. In this case, however, if $\\mathcal T \\ne \\mathcal T'$, then $f^{-1}$ is not continuous.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{theorem}\n\t\\label{prop: alt-def of continuous maps by neighbourhoods}\n\tLet $(X, \\mathcal T_X)$ and $(Y, \\mathcal T_Y)$ be topological spaces. A map $f: X \\to Y$ is continuous at $x \\in X$ iff for any neighbourhood $N_y$ of $f(x)$, there is a neighbourhood $N_x$ of $x$, such that $f[N_x] \\subseteq N_y$.\n\t\n\t\\begin{proof}\n\t\tLet $N_y$ be a neighbourhood of $f(x)$. Clearly, there exists an open set $U_y$ contains $y$.\n\t\n\t\tBy Definition \\ref{def: continuous maps}, $f$ is continuous at $x$ iff $x \\in f^{-1}[U_y] \\in \\mathcal T_X$. Clearly, $f^{-1}[U_y]$ is a neighbourhood of $x$. We have $f[f^{-1}[U_y]] = U_y \\subseteq N_y$.\n\t\t\n\t\tBy Proposition \\ref{prop: alt-def of open sets by neighbourhoods}, there $U_x$ must contains at least one neighbourhood $N_x$ of $x$, thus, $f[N_x] \\subseteq U_y$.\n\t\\end{proof}\n\\end{theorem}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tLet $(X, \\mathcal T_X)$ and $(Y, \\mathcal T_{Y})$ be metrizable spaces. A map $f: X \\to Y$ is continuous at $p \\in X$ iff for any $\\varepsilon > 0$, there is a $\\delta > 0$, such that for all $x \\in B_X(p, \\delta)$, $f(x) \\in B_Y(f(p), \\varepsilon)$, where $B_X$ is defined by any metrics $\\rho_X$ induces $\\mathcal T_X$, and $B_Y$ is defined by any metrics $\\rho_Y$ induces $\\mathcal T_Y$.\n\t\n\t\\begin{proof}\n\t\tClearly, for all $\\varepsilon > 0$, $B_Y(f(x,), \\varepsilon)$ is an open neighbourhood of $f(x)$.\n\t\t\n\t\t$f$ is not necessarily be injective, so $f^{-1}[B_Y(f(x), \\varepsilon)] = U \\in x$. By Definition \\ref{def: continuous maps}, $U$ is open, so for some $\\delta > 0$, $B_X(x, \\delta) \\subseteq U$. Thus, By Proposition \\ref{prop: alt-def of continuous maps by neighbourhoods}, $f$ is continuous iff $f[B_X(x, \\delta)] \\subseteq B_Y(f(x), \\varepsilon)$. This satisfies the conditions we have.\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tLet $(X, \\mathcal T_X)$ and $(Y, \\mathcal T_Y)$ be topological spaces. A function $f: X \\to Y$ is said to be continuous iff for any closed set $V$ in $Y$, its preimage in $X$ under $f$ is closed.\n\t\n\t\\begin{proof}\n\t\tLet $U_Y$ be any open set in $Y$, let $U_X$ be the preimage of $U_Y$ under $f$. By Definition \\ref{def: continuous maps}, $U_X$ is open in $X$. Let\n\t\t$$\n\t\tV_X = f^{-1}[Y \\setminus U_Y] = X \\setminus U_X,\n\t\t$$\n\t\tThen $V_X$ is closed.\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[convergence of sequences]\n\t\\label{def: convergence of sequences}\n\tLet $(X, \\mathcal T)$ be a topological space, and let $\\{x_n\\}$ be a sequence in $X$. Then $\\{x_n\\}$ is said to be \\textit{converges} in $X$ iff there is an $x \\in X$, such that for any open neighbourhood $U_x$ of $x$, it contains a cofinite subset $A \\subseteq \\{x_n\\}$. That is, there exists $N$ in the domain of $\\{x_n\\}$, for any natural numbers $n \\ge N$, $x_n \\in U_x$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\t\\\n\t\\begin{enumerate}\n\t\t\\item\n\t\tIn a discrete topological space, a sequence $\\{x_n\\}$ converges iff there is an $N$ in the domain of $\\{x_n\\}$, for any natural numbers $m > N$, $x_N = x_m$.\n\t\t\n\t\t\\item\n\t\tIn a indiscrete topological space, any sequence $\\{x_n\\}$ in $X$ converges in $X$. And\n\t\t$$\n\t\t\\lim_{n \\to \\infty} \\{x_n\\} = X.\n\t\t$$\n\t\\end{enumerate}\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tIn a Hausdorff space, any convergent sequence converges to a unique point in the space.\n\t\n\t\\begin{proof}\n\t\tLet $(X, \\mathcal T)$ be a Hausdorff space, and let $\\{x_n\\}$ be a sequence in $X$. Suppose $\\{x_n\\}$ converges to more than one point, say to $x, y \\in X$ with $x \\ne y$, then, for all neighbourhoods $N_x$ of $x$ and $N_y$ of $y$, $N_x$ contains a cofinite subset $A \\subseteq \\{x_n\\}$ and $N_y$ contains a cofinite subset $B \\subseteq \\{x_n\\}$. If this were true, $N_x \\cap N_y$ should be non-empty, otherwise $N_x$ or $N_y$ should be finite.\n\t\t\n\t\tThen, $x$ and $y$ are not separated by neighbourhoods, thus $(X, \\mathcal T)$ is not Hausdorff. This is a contradiction.\n\t\t\n\t\tBut, as $(X, \\mathcal T)$ is Hausdorff, there must be mutually disjoint $N_x$ and $N_y$. Thus, the assumption cause a contradiction.\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tAs all metrizable spaces are Hausdorff, so any convergent sequence in a metrizable space converges to at most one point.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tLet $(X, \\mathcal T_X)$ and $(Y, \\mathcal T_Y)$ be topological space, let $f: X \\to Y$ be a map, and let $\\{x_n\\}$ be a convergent sequence in $X$. If $f$ is continuous, then $f[\\{x_n\\}]$ is a sequence convergent in $Y$.\n\t\n\t\\begin{proof}\n\t\tLet $U_y$ be any open neighbourhood of $f(x)$. By Definition \\ref{def: continuous maps}, $f^{-1}[U_y]$ is also an open neighbourhood of $x$. By Definition \\ref{def: convergence of sequences}, $f^{-1}[U_y]$ contains a cofinite subset $A \\subseteq \\{x_n\\}$. Then $f[A]$ is a cofinite subset of $f[\\{x_n\\}]$. As $f[f^{-1}[U_y]] \\supseteq f^{-1}[A]$, $f[\\{x_n\\}]$ converges in $f[f^{-1}[U_y]] \\supseteq f^{-1}[A]$.\n\t\\end{proof}\t\t\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tIn this proposition, even if $f[\\{x_n\\}]$ converges in $Y$, $f$ might be discontinuous. For example, let $X$ any set, let $\\mathcal T$ be the indiscrete topology on $X$, let $U$ be another cofinite subset of $X$ with $X \\ne U$, and let $\\mathcal T' = \\{ \\emptyset, X, U\\}$. Let $f: (X, \\mathcal T) \\to (X, \\mathcal T')$ be defined by\n\t$$\n\tf(x) = x.\n\t$$\n\t\n\tBy Definition \\ref{def: continuous maps}, $f$ is not continuous. But, for any convergent sequence $\\{x_n\\}$ in $(X, \\mathcal T)$, $f[\\{x_n\\}]$ also convergent in $(X, \\mathcal T)$.\n\\end{note}\n%--------------------------------\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n%", "meta": {"hexsha": "a506d91dc86228ed957c5997b644e634ae58c4a0", "size": 8071, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-v0/continuity.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-v0/continuity.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-v0/continuity.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.8186528497, "max_line_length": 446, "alphanum_fraction": 0.582579606, "num_tokens": 2506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.7252649691203799}}
{"text": "\\chapter{Cycles in the Collatz Graph}\n\\label{ch:cycles}\n\n\\section{A remark about cycles}\n\\label{sec:cycles}\nIn graph theory, a path of length $n\\geq 1$ that starts and ends at the same vertex is called a circuit. A circuit, in which no vertex is repeated with the sole exception that the initial vertex is the terminal vertex, is called a cycle. A cycle of length $n$ is referred to as an $n$-cycle. For these definitions, we rely on \\cite[p.~599]{Ref_Rosen}, \\cite[p.~35]{Ref_Benjamin_Chartrand_Zhang} and \\cite[p.~445]{Ref_Chartrand_Zhang}. Furthermore, we call a cycle originating from the root a trivial cycle.\n\n\\begin{remark}\nIn order for the cycles to become graphically visible, we now require that in a graph $H$ two vertices $v_1$ and $v_2$ are one and the same if the label of both nodes are identical: $l_{V(H)}(v_1)=l_{V(H)}(v_2)\\rightarrow v_1=v_2$. As a consequence, there is no guarantee that the graph precisely refers to the algebraic structure of a free monoid anymore. A free monoid requires that each of its elements can be written in one and only one way.\n\\end{remark}\n\nWhen different nodes collapse on one, the graph is no longer necessarily a tree. Let us point to the monoid $S^\\ast$, which we introduced in section \\ref{sec:groups_graphs}. Take for example four of its elements, the empty string $e$, the strings $qqr$, $qqrqqr$, and $qqrqqrqqr$. These elements lie as well within the subset $U\\subset T\\subset S^\\ast$, and they are represented by nodes of the tree $H_U$ that all have the same label $1=ev_{S^\\ast}(qqr,1)=ev_{S^\\ast}(qqrqqr,1)=ev_{S^\\ast}(qqrqqrqqr,1)$. These nodes are one and the same, the root of $H_U$. Visually, then in $H_U$ a directed edge goes from the vertex labeled with $4$ back to the root node. Analogically, in $H_{C,3}$ a loop connects the root to itself, since due to the path contraction even labeled nodes do not exist in $H_{C,3}$. The  aforementioned example reflects the trivial cycle of the Collatz sequence.\n\nFigure~\\ref{fig:5} depicts a section of $H_{C,5}$, which includes the $3$-cycle $43,17,27$. Because of the two non-trivial cycles $(43,17,27)$ and $(83,33,13)$, in $H_{C,5}$ there does not exist a path between the root and the vertex $43$ and between the root and the vertex $83$. Hence, $H_{C,5}$ is said to be a disconnected graph. Generally, a graph is called a disconnected graph if it is impossible to walk (along its edges) from any vertex to any other \\cite[pp.~46-47]{Ref_Benjamin_Chartrand_Zhang}.\n\n\\begin{figure}\n\t\\includegraphics[width=1.00\\textwidth]{figures/h_c5a.png}\n\t\\caption{Section of $H_{C,5}$ including the $3$-cycle $43,17,27$}\n\t\\label{fig:5}\n\\end{figure}\n\nThe following considerations focus on non-trivial cycles, and therefore on cycles that do not originate from the root, but cause the graph to be a disconnected graph. Utilizing the example of the graph $H_{C,5}$ we are able to deduct from the cycle $(43,17,27)$ the simple and self-evident equality $\\textit{left-child}^3(43)=43$:\n\\begin{equation*}\n\\begin{array}{l}\n\\textit{left-child}(43)=\\frac{1}{5}*\\left(43*2^1-1\\right)=17\n\\\\[\\medskipamount]\n\\textit{left-child}(17)=\\frac{1}{5}*\\left(17*2^3-1\\right)=27\n\\\\[\\medskipamount]\n\\textit{left-child}(27)=\\frac{1}{5}*\\left(27*2^3-1\\right)=43\n\\end{array}\n\\end{equation*}\n\nObviously, the authors note, it would be interesting to find out what circumstances enable a graph to have non-trivial cycles, whether it be the $5x+1$ variant, the $7x+1$ variant of $H_C$ or any variant $H_{C,k}$ with $k\\geq 1$.\n\n\\section{\\texorpdfstring{Which variants of $H_C$ have non-trivial cycles?}{Which variants of HC have non-trivial cycles?}}\n\\label{sec:non_trivial_cycles}\nThe generalization of the relationship between successive nodes, given by equation~\\ref{eq:generalized_reachability} leads to the condition for an existence of an $n$-cycle in any $kx+1$ variant of $H_C$, which looks analogous to the condition given by equation~\\ref{eq:func_cycle} that specifies $H_{C,3}$ has a cycle:\n\\begin{equation}\n\\label{eq:generalized_cycle}\n2^\\alpha=\\prod_{i=1}^{n}\\left(k+\\frac{1}{v_i}\\right)\n\\end{equation}\n\nThe natural number $\\alpha$ is the sum of edges that have been contracted between the vertices $v_i$ forming the cycle, in other words $\\alpha$ is the number of divisions by $2$ within the sequence. The natural number $n$ is the cycle length and $k$ obviously specifies the variant of $H_C$. Since between each vertex at least one edge has been contracted (at least one division by $2$ took place), we know that our exponent alpha is greater than or equal to the sequence length:\n\\begin{equation}\n\\label{eq:n_alpha}\n\\alpha\\ge n\n\\end{equation}\n\nIn their 2020 publication Koch et al. \\cite{Ref_Koch_2020} provide a list of cycles for different values of $k$, identified with a linear search performed by a Python script \\cite{Ref_Koch_Github}. Table~\\ref{table:known_cycles} lists all these discovered cycles (refer to \\cite{Ref_Koch_2020} for details on the discovery procedure and search intervals). Note that the cycles in table~\\ref{table:known_cycles} are written in reverse order, i.e. in the order which corresponds to the Collatz sequence. To obtain the cycles in terms of graph theory referring to the graph $H_C$, read them from right to left.\n\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{|L|R|R|C|}\n\t\t\\hline\n\t\t\\thead{\\boldsymbol{k}} &\n\t\t\\thead{\\textbf{cycle}} &\n\t\t\\thead{\\boldsymbol{\\alpha}} &\n\t\t\\thead{\\textbf{non-trivial}} \\\\\n\t\t\\hline\n\t\t1 &\n\t\t1 &\n\t\t1 &\n\t\t\\\\\n\t\t\\hline\n\t\t3 &\n\t\t1 &\n\t\t2 &\n\t\t\\\\\n\t\t\\hline\n\t\t5 &\n\t\t1,3 &\n\t\t5 &\n\t\t\\\\\n\t\t\\hline\n\t\t5 &\n\t\t13,33,83 &\n\t\t7 &\n\t\t\\checkmark \\\\\n\t\t\\hline\n\t\t5 &\n\t\t27,17,43 &\n\t\t7 &\n\t\t\\checkmark \\\\\n\t\t\\hline\n\t\t7 &\n\t\t1 &\n\t\t3 &\n\t\t\\\\\n\t\t\\hline\n\t\t15 &\n\t\t1 &\n\t\t4 &\n\t\t\\\\\n\t\t\\hline\n\t\t31 &\n\t\t1 &\n\t\t5 &\n\t\t\\\\\n\t\t\\hline\n\t\t63 &\n\t\t1 &\n\t\t6 &\n\t\t\\\\\n\t\t\\hline\n\t\t127 &\n\t\t1 &\n\t\t7 &\n\t\t\\\\\n\t\t\\hline\n\t\t181 &\n\t\t27,611 &\n\t\t15 &\n\t\t\\checkmark \\\\\n\t\t\\hline\n\t\t181 &\n\t\t35,99 &\n\t\t15 &\n\t\t\\checkmark \\\\\n\t\t\\hline\n\t\t255 &\n\t\t1 &\n\t\t8 &\n\t\t\\\\\n\t\t\\hline\n\t\t511 &\n\t\t1 &\n\t\t9 &\n\t\t\\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{Known $n$-cycles in $kx+1$ variants of $H_C$ for $k\\leq1000$, $n\\leq 100$}\n\t\\label{table:known_cycles}\n\\end{table}\n\nBased on the results shown in table~\\ref{table:known_cycles} we state the following theorem~\\ref{theo:2} that renders more precisely the prerequisite for cycles that may occur in any variants of $H_C$.\n\n\\begin{theorem}\n\t\\label{theo:2}\n\tAn $n$-cycle can only exist in a graph $H_{C,k}$, if the following equation holds:\n\t\\begin{equation*}\n\t2^{\\bar\\alpha}=2^{\\lfloor n\\log_2k\\rfloor+1}=\\prod_{i=1}^{n}\\left(k+\\frac{1}{v_i}\\right)\n\t\\end{equation*}\n\\end{theorem}\n\nThe statement behind theorem~\\ref{theo:2} consists in the claim that, in order for an $n$-cycle to occur, the exponent $\\alpha$ has to be $\\bar\\alpha=\\lfloor n\\log_2k\\rfloor+1$. This statement is true if the following general condition for the validity of the cycle-alpha's upper limit always holds (see \\cite{Ref_Koch_2020}):\n\\begin{equation}\n\\label{eq:condition_max}\nn\\log_2k-\\lfloor n\\log_2k\\rfloor<2-\\log_2\\left(\\prod_{i=1}^{n}\\left(1+\\frac{1}{kv_{i}}\\right)\\right)\n\\end{equation}\n\nA product $\\prod(1+a_n)$ with positive terms $a_n$ is convergent if the series $\\sum a_n$ converges, see Knopp \\cite[p.~220]{Ref_Knopp}. A similar statement provides Murphy \\cite{Ref_Murphy}, who write the factors in the form $c_n=1+a_n$ and explains that if $\\prod c_n$ is convergent then $c_n\\rightarrow1$ and therefore if $\\prod (1+a_n)$ is convergent then $a_n\\rightarrow0$. Thus, to verify whether the product in condition~\\ref{eq:condition_max} is converging towards a limiting value, it is sufficient to examine the following sum:\n\\begin{equation*}\n\\sum_{i=1}^{n}\\frac{1}{kv_{i}}\n\\end{equation*}\n\nThe sum of reciprocal vertices depending only from $v_1$ is given in appendix~\\ref{appx:sum_reciprocal_vertices}.\n\n\\section{Cycles and the product in the condition for cycle-alpha's upper limit}\nLet us start with the following product equality, which will give us insights into the relationship between cycles and the product in the condition for alpha's upper limit. The variables $V_1,\\ldots,V_m$ and $W_1,\\ldots,W_n$ are all odd positive integers:\n\\begin{equation}\n\t\\label{eq:product_equality}\n\t(V_1+1)\\cdots(V_m+1)\\cdot W_1\\cdots W_n=V_1\\cdots V_m\\cdot(W_1+1)\\cdots(W_n+1)\n\\end{equation}\n\nEvery natural odd number $V$ can be expressed in the form of $V=v\\cdot2^{\\alpha}-1$ whereby $v$ is an positive odd integer and $\\alpha>0$ is any natural number. This allows us to perform the following substitution (we use $\\alpha_V$ for denoting the divisions by two between successive nodes $v_i$ and $\\alpha_W$ for divisions by two between successive nodes $w_i$):\n\n\\begin{equation}\n\t\\label{eq:product_equality_substitution}\n\t\\begin{array}{lll}\n\t\tV_1&=v_22^{\\alpha_{V,1}}-1&=kv_1\\\\\n\t\tV_2&=v_32^{\\alpha_{V,2}}-1&=kv_2\\\\\n\t\t\\vdots&\\vdots&\\vdots\\\\\n\t\tV_{m-1}&=v_m2^{\\alpha_{V,m-1}}-1&=kv_{m-1}\\\\\n\t\tV_m&=v_12^{\\alpha_{V,m}}-1&=kv_m\n\t\\end{array}\\qquad\n\t\\begin{array}{lll}\n\t\tW_1&=w_22^{\\alpha_{W,1}}-1&=kw_1\\\\\n\t\tW_2&=w_32^{\\alpha_{W,2}}-1&=kw_2\\\\\n\t\t\\vdots&\\vdots&\\vdots\\\\\n\t\tW_{n-1}&=w_n2^{\\alpha_{W,n-1}}-1&=kw_{n-1}\\\\\n\t\tW_n&=w_12^{\\alpha_{W,n}}-1&=kw_n\n\t\\end{array}\n\\end{equation}\n\nThe substitution rotating from $v_2=(kv_1+1)\\cdot2^{-\\alpha_{V,1}}$ to $v_m=(kv_{m-1}+1)\\cdot2^{-\\alpha_{V,m-1}}$ and finally back to $v_1=(kv_m+1)\\cdot2^{-\\alpha_{V,m}}$ describes a cycle. The result of these substitutions into equation~\\ref{eq:product_equality} is the following equality:\n\\begin{flalign*}\n\tv_22^{\\alpha_{V,1}}\\cdots v_m2^{\\alpha_{V,m-1}}v_12^{\\alpha_{V,m}}\\cdot W_1\\cdots W_n&=V_1\\cdots V_m\\cdot w_22^{\\alpha_{W,1}}\\cdots w_n2^{\\alpha_{W,n-1}}w_12^{\\alpha_{W,n}}\\\\\n\tv_22^{\\alpha_{V,1}}\\cdots v_m2^{\\alpha_{V,m-1}}v_12^{\\alpha_{V,m}}\\cdot kw_1\\cdots kw_n&=kv_1\\cdots kv_m\\cdot w_22^{\\alpha_{W,1}}\\cdots w_n2^{\\alpha_{W,n-1}}w_12^{\\alpha_{W,n}}\n\\end{flalign*}\n\nThe trivial case where $n=m$ and the sum of exponents are equal $\\sum_{i=1}^{m}\\alpha_{V,i}=\\sum_{i=1}^{n}\\alpha_{W,i}$ simplifies the product equality as follows:\n\\begin{flalign*}\n\t(V_1+1)\\cdots(V_n+1)\\cdot W_1\\cdots W_n&=V_1\\cdots V_n\\cdot(W_1+1)\\cdots(W_n+1)\\\\\n\tv_1\\cdots v_n\\cdot\\cancel{2^{\\alpha_{V,1}+\\ldots+\\alpha_{V,n}}}\\cdot W_1\\cdots W_n&=V_1\\cdots V_m\\cdot w_1\\cdots w_n\\cdot\\cancel{2^{\\alpha_{W,1}+\\ldots+\\alpha_{W,n}}}\n\\end{flalign*}\nThis equality becomes immediatly true if $V_1\\cdots V_n=W_1\\cdots W_n$ which is the less spectacular case. The more interesting case arises from setting $V_i=kv_i$ and $W_i=kw_i$ as given by substitution~\\ref{eq:product_equality_substitution} wich turns the product equality into an always true statement as well:\n\\begin{flalign*}\n\tv_1\\cdots v_n\\cdot W_1\\cdots W_n&=V_1\\cdots V_m\\cdot w_1\\cdots w_n\\\\\n\tv_1\\cdots v_n\\cdot k^n\\cdot w_1\\cdots w_n&=k^n\\cdot v_1\\cdots v_n\\cdot w_1\\cdots w_n\n\\end{flalign*}\n\n\\begin{example}\n\tThe following exemplarly product equality fullfills equation~\\ref{eq:product_equality}, whereby $V_1=65$, $V_2=165$, $V_3=415$ and $W_1=135$, $W_2=85$, $W_3=215$:\n\t\\[\n\t(65+1)(165+1)(415+1)\\cdot135\\cdot85\\cdot215=65\\cdot165\\cdot415\\cdot(135+1)(85+1)(215+1)\n\t\\]\n\tWe perform the following substitutions:\n\t\\[\n\t\\arraycolsep=0.2em\\begin{array}{ll}\n\t\tV_1=65&=v_22^{\\alpha_{V,1}}-1=33\\cdot2^1-1=5v_1\\\\\n\t\tV_2=165&=v_32^{\\alpha_{V,2}}-1=83\\cdot2^1-1=5v_2\\\\\n\t\tV_3=415&=v_12^{\\alpha_{V,3}}-1=13\\cdot2^5-1=5v_3\n\t\\end{array}\\hspace{1em}\n\t\\begin{array}{ll}\n\t\tW_1=135&=w_22^{\\alpha_{W,1}}-1=17\\cdot2^3-1=5w_1\\\\\n\t\tW_2=85&=w_32^{\\alpha_{W,2}}-1=43\\cdot2^1-1=5w_2\\\\\n\t\tW_3=215&=w_12^{\\alpha_{W,3}}-1=27\\cdot2^3-1=5w_3\n\t\\end{array}\n\t\\]\n\tThe result of these substitutions is:\n\t\\[\n\t33\\cdot\\cancel{2^1}\\cdot83\\cdot\\cancel{2^1}\\cdot13\\cdot\\cancel{2^5}\\cdot135\\cdot85\\cdot215=65\\cdot165\\cdot415\\cdot17\\cdot\\cancel{2^3}\\cdot43\\cdot\\cancel{2^1}\\cdot27\\cdot\\cancel{2^3}\n\t\\]\n\tSince the sum of exponents $\\alpha_{V,i}$ and $\\alpha_{W,i}$ are equal, we can cancel out all powers of two and obtain:\n\t\\[\n\tv_2v_3v_1W_1W_2W_3=33\\cdot83\\cdot13\\cdot135\\cdot85\\cdot215=65\\cdot165\\cdot415\\cdot17\\cdot43\\cdot27=V_1V_2V_3w_2w_3w_1\n\t\\]\n\tThis product equality becomes true $v_2v_3v_1\\cdot k^3\\cdot w_1w_2w_3=k^3\\cdot v_1v_2v_3\\cdot w_2w_3w_1$ when we set $V_i=kv_i$ and $W_i=kw_i$ (for $i=1,2,3$) which inevitably leads to the two corresponding cycles for $k=5$ that are already presented by table~\\ref{table:known_cycles}.\n\\end{example}\n\nLet us define the difference $\\Delta=(1+\\nicefrac{1}{V_1})(1+\\nicefrac{1}{V_2})\\cdots(1+\\nicefrac{1}{V_m})-(1+\\nicefrac{1}{W_1})(1+\\nicefrac{1}{W_2})\\cdots(1+\\nicefrac{1}{W_n})$.\nWe know that if this difference is zero, then we have found two cycles, as for example $0=(1+\\nicefrac{1}{65})(1+\\nicefrac{1}{165})(1+\\nicefrac{1}{415})-(1+\\nicefrac{1}{135})(1+\\nicefrac{1}{85})(1+\\nicefrac{1}{215})$.\nCan you identify empirically some set pairs $\\{V_1,V_2,\\ldots,V_m\\}$ and $\\{W_1,W_2,\\ldots,W_n\\}$, where the difference is not necessarly zero but a whole number, e.g. $\\Delta=1,2,3,\\ldots$?\n", "meta": {"hexsha": "9c5c669a5abdf5b0049b099b815565169453c94c", "size": 12858, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01 Graph Theory/TeX/v6.0/chapter/04_cycles.tex", "max_stars_repo_name": "Sultanow/collatz", "max_stars_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-01T15:12:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T15:54:55.000Z", "max_issues_repo_path": "01 Graph Theory/TeX/v6.0/chapter/04_cycles.tex", "max_issues_repo_name": "Sultanow/collatz", "max_issues_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01 Graph Theory/TeX/v6.0/chapter/04_cycles.tex", "max_forks_repo_name": "Sultanow/collatz", "max_forks_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-06T20:44:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-06T20:44:07.000Z", "avg_line_length": 54.9487179487, "max_line_length": 882, "alphanum_fraction": 0.713407995, "num_tokens": 4713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256591565729, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7252649680500616}}
{"text": "\\subsection{HDBSCAN}\n\\label{sec:ctm-hdb}\n\nThe third and last clustering algorithm we experimented with was HDBSCAN (Hierarchical Density-Based Spatial Clustering of Applications with Noise) \\cite{McInnes2017}. Similar to the previous two algorithms, it tries to group unlabeled data points with its own set of criteria. As its name implies, it tries to group points based on spatial density to ensure the resulting groups meet some density parameter.\n\nThe advantage of HDBSCAN is that it does not require us to specify the number of clusters we want to find. Instead, we specify the minimum number of points in each cluster $P$ and the algorithm will dynamically group points such that the resulting clusters have at least $P$ points. This gives us more flexibility in our parameters because choosing the number of clusters is harder than choosing the minimum number of points per cluster. We do not know the proper the number of clusters and thus must estimate it through an ad-hoc procedure. However, we do have a stronger conceptual understanding of the number of points per cluster: since we know there are only a limited number of approaches to solve an assignment and we know the majority of the students will follow similar approaches, either through collaboration or coincidence due to limited unique approaches, we know the $P$ value must be a significant fraction of the total number of students.\n\nHowever, the disadvantage of this algorithm is that it is not guaranteed to be able to label every point; outlier points that cannot satisfy the group's density criteria are discarded as noise. The higher the minimum cluster size parameter $P$, the more points will be unlabeled. Ideally we want our groups to be as dense as possible so that we know the grouped points are extremely similar to each other. Ultimately, it is a balance between how many points we can label (automation rate) and how dense the resulting groups are.\n\nFigure~\\ref{fig:ctm-hdb} shows how the algorithm labels our data set based on varying minimum cluster sizes. A cluster size of 5 is able to achieve 3 groups, which is close to the 4 groups set for the previous two algorithms. However as we can see from the graph, the 3 groups are slightly sparse. As a result, we chose $P=10$ because it is able to label most of the points without sacrificing too much density; at higher cluster sizes, we do not seem to significantly increase our groups' densities.\n\nOnce we were satisfied with our parameters, we ran the HDBSCAN algorithm and designated each student's score to be equal to the \\textquote{strength} of the student's corresponding group prediction returned from the algorithm.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{conversion-to-mark/marking_paster_nbio_ece459-a1-w2017_hdb}\n\\caption[HDBSCAN Clustering]{These graphs show our data points clustered with HDBSCAN using different minimum cluster size parameters. The higher the minimum size, the denser the resulting clusters. Furthermore, higher cluster sizes also result in more outlier points marked as noise (dark blue) as well as fewer total clusters. Cluster size of 5 has three different groups whereas cluster sizes of 10 and higher only have two different groups.}\n\\label{fig:ctm-hdb}\n\\end{figure}\n", "meta": {"hexsha": "da60a6ad84ed0926fa98b011d671970c1df07889", "size": 3256, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/thesis/body/conversion-to-mark/hdbscan.tex", "max_stars_repo_name": "Trinovantes/Masters", "max_stars_repo_head_hexsha": "a7f036a08cda7e508b0c51fefa6ac150555ec2ee", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "thesis/thesis/body/conversion-to-mark/hdbscan.tex", "max_issues_repo_name": "Trinovantes/Masters", "max_issues_repo_head_hexsha": "a7f036a08cda7e508b0c51fefa6ac150555ec2ee", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thesis/thesis/body/conversion-to-mark/hdbscan.tex", "max_forks_repo_name": "Trinovantes/Masters", "max_forks_repo_head_hexsha": "a7f036a08cda7e508b0c51fefa6ac150555ec2ee", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 171.3684210526, "max_line_length": 954, "alphanum_fraction": 0.808046683, "num_tokens": 682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7252649624956748}}
{"text": "\\chapter{Cycles in the Collatz Graph}\n\\label{ch:cycles}\n\n\\section{A remark about cycles}\n\\label{sec:cycles}\nIn graph theory, a path of length $n\\geq 1$ that starts and ends at the same vertex is called a circuit. A circuit, in which no vertex is repeated with the sole exception that the initial vertex is the terminal vertex, is called a cycle. A cycle of length $n$ is referred to as an $n$-cycle. For these definitions, we rely on \\cite[p.~599]{Ref_Rosen}, \\cite[p.~35]{Ref_Benjamin_Chartrand_Zhang} and \\cite[p.~445]{Ref_Chartrand_Zhang}. Furthermore, we call a cycle originating from the root a trivial cycle.\n\n\\begin{remark}\nIn order for the cycles to become graphically visible, we now require that in a graph $H$ two vertices $v_1$ and $v_2$ are one and the same if the label of both nodes are identical: $l_{V(H)}(v_1)=l_{V(H)}(v_2)\\rightarrow v_1=v_2$. As a consequence, there is no guarantee that the graph precisely refers to the algebraic structure of a free monoid anymore. A free monoid requires that each of its elements can be written in one and only one way.\n\\end{remark}\n\nWhen different nodes collapse on one, the graph is no longer necessarily a tree. Let us point to the monoid $S^\\ast$, which we introduced in section \\ref{sec:groups_graphs}. Take for example four of its elements, the empty string $e$, the strings $qqr$, $qqrqqr$, and $qqrqqrqqr$. These elements lie as well within the subset $U\\subset T\\subset S^\\ast$, and they are represented by nodes of the tree $H_U$ that all have the same label $1=ev_{S^\\ast}(qqr,1)=ev_{S^\\ast}(qqrqqr,1)=ev_{S^\\ast}(qqrqqrqqr,1)$. These nodes are one and the same, the root of $H_U$. Visually, then in $H_U$ a directed edge goes from the vertex labeled with $4$ back to the root node. Analogically, in $H_{C,3}$ a loop connects the root to itself, since due to the path contraction even labeled nodes do not exist in $H_{C,3}$. The  aforementioned example reflects the trivial cycle of the Collatz sequence.\n\nFigure~\\ref{fig:5} depicts a section of $H_{C,5}$, which includes the $3$-cycle $43,17,27$. Because of the two non-trivial cycles $(43,17,27)$ and $(83,33,13)$, in $H_{C,5}$ there does not exist a path between the root and the vertex $43$ and between the root and the vertex $83$. Hence, $H_{C,5}$ is said to be a disconnected graph. Generally, a graph is called a disconnected graph if it is impossible to walk (along its edges) from any vertex to any other \\cite[pp.~46-47]{Ref_Benjamin_Chartrand_Zhang}.\n\n\\begin{figure}\n\t\\includegraphics[width=1.00\\textwidth]{figures/h_c5a.png}\n\t\\caption{Section of $H_{C,5}$ including the $3$-cycle $43,17,27$}\n\t\\label{fig:5}\n\\end{figure}\n\nThe following considerations focus on non-trivial cycles, and therefore on cycles that do not originate from the root, but cause the graph to be a disconnected graph. Utilizing the example of the graph $H_{C,5}$ we are able to deduct from the cycle $(43,17,27)$ the simple and self-evident equality $\\textit{left-child}^3(43)=43$:\n\\begin{equation*}\n\\begin{array}{l}\n\\textit{left-child}(43)=\\frac{1}{5}*\\left(43*2^1-1\\right)=17\n\\\\[\\medskipamount]\n\\textit{left-child}(17)=\\frac{1}{5}*\\left(17*2^3-1\\right)=27\n\\\\[\\medskipamount]\n\\textit{left-child}(27)=\\frac{1}{5}*\\left(27*2^3-1\\right)=43\n\\end{array}\n\\end{equation*}\n\nObviously, the authors note, it would be interesting to find out what circumstances enable a graph to have non-trivial cycles, whether it be the $5x+1$ variant, the $7x+1$ variant of $H_C$ or any variant $H_{C,k}$ with $k\\geq 1$.\n\n\\section{\\texorpdfstring{Which variants of $H_C$ have non-trivial cycles?}{Which variants of HC have non-trivial cycles?}}\n\\label{sec:non_trivial_cycles}\nThe generalization of the relationship between successive nodes, given by equation~\\ref{eq:generalized_reachability} leads to the condition for an existence of an $n$-cycle in any $kx+1$ variant of $H_C$, which looks analogous to the condition given by equation~\\ref{eq:func_cycle} that specifies $H_{C,3}$ has a cycle:\n\\begin{equation}\n\\label{eq:generalized_cycle}\n2^\\alpha=\\prod_{i=1}^{n}\\left(k+\\frac{1}{v_i}\\right)\n\\end{equation}\n\nThe natural number $\\alpha$ is the sum of edges that have been contracted between the vertices $v_i$ forming the cycle, in other words $\\alpha$ is the number of divisions by $2$ within the sequence. The natural number $n$ is the cycle length and $k$ obviously specifies the variant of $H_C$. Since between each vertex at least one edge has been contracted (at least one division by $2$ took place), we know that our exponent alpha is greater than or equal to the sequence length:\n\\begin{equation}\n\\label{eq:n_alpha}\n\\alpha\\ge n\n\\end{equation}\n\nIn their 2020 publication Koch et al. \\cite{Ref_Koch_2020} provide a list of cycles for different values of $k$, identified with a linear search performed by a Python script \\cite{Ref_Koch_Github}. Table~\\ref{table:known_cycles} lists all these discovered cycles (refer to \\cite{Ref_Koch_2020} for details on the discovery procedure and search intervals). Note that the cycles in table~\\ref{table:known_cycles} are written in reverse order, i.e. in the order which corresponds to the Collatz sequence. To obtain the cycles in terms of graph theory referring to the graph $H_C$, read them from right to left.\n\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{|L|R|R|C|}\n\t\t\\hline\n\t\t\\thead{\\boldsymbol{k}} &\n\t\t\\thead{\\textbf{cycle}} &\n\t\t\\thead{\\boldsymbol{\\alpha}} &\n\t\t\\thead{\\textbf{non-trivial}} \\\\\n\t\t\\hline\n\t\t1 &\n\t\t1 &\n\t\t1 &\n\t\t\\\\\n\t\t\\hline\n\t\t3 &\n\t\t1 &\n\t\t2 &\n\t\t\\\\\n\t\t\\hline\n\t\t5 &\n\t\t1,3 &\n\t\t5 &\n\t\t\\\\\n\t\t\\hline\n\t\t5 &\n\t\t13,33,83 &\n\t\t7 &\n\t\t\\checkmark \\\\\n\t\t\\hline\n\t\t5 &\n\t\t27,17,43 &\n\t\t7 &\n\t\t\\checkmark \\\\\n\t\t\\hline\n\t\t7 &\n\t\t1 &\n\t\t3 &\n\t\t\\\\\n\t\t\\hline\n\t\t15 &\n\t\t1 &\n\t\t4 &\n\t\t\\\\\n\t\t\\hline\n\t\t31 &\n\t\t1 &\n\t\t5 &\n\t\t\\\\\n\t\t\\hline\n\t\t63 &\n\t\t1 &\n\t\t6 &\n\t\t\\\\\n\t\t\\hline\n\t\t127 &\n\t\t1 &\n\t\t7 &\n\t\t\\\\\n\t\t\\hline\n\t\t181 &\n\t\t27,611 &\n\t\t15 &\n\t\t\\checkmark \\\\\n\t\t\\hline\n\t\t181 &\n\t\t35,99 &\n\t\t15 &\n\t\t\\checkmark \\\\\n\t\t\\hline\n\t\t255 &\n\t\t1 &\n\t\t8 &\n\t\t\\\\\n\t\t\\hline\n\t\t511 &\n\t\t1 &\n\t\t9 &\n\t\t\\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{Known $n$-cycles in $kx+1$ variants of $H_C$ for $k\\leq1000$, $n\\leq 100$}\n\t\\label{table:known_cycles}\n\\end{table}\n\nBased on the results shown in table~\\ref{table:known_cycles} we state the following theorem~\\ref{theo:2} that renders more precisely the prerequisite for cycles that may occur in any variants of $H_C$.\n\n\\begin{theorem}\n\t\\label{theo:2}\n\tAn $n$-cycle can only exist in a graph $H_{C,k}$, if the following equation holds:\n\t\\begin{equation*}\n\t2^{\\bar\\alpha}=2^{\\lfloor n\\log_2k\\rfloor+1}=\\prod_{i=1}^{n}\\left(k+\\frac{1}{v_i}\\right)\n\t\\end{equation*}\n\\end{theorem}\n\nThe statement behind theorem~\\ref{theo:2} consists in the claim that, in order for an $n$-cycle to occur, the exponent $\\alpha$ has to be $\\bar\\alpha=\\lfloor n\\log_2k\\rfloor+1$. This statement is true if the following general condition for the validity of the cycle-alpha's upper limit always holds (see \\cite{Ref_Koch_2020}):\n\\begin{equation}\n\\label{eq:condition_max}\nn\\log_2k-\\lfloor n\\log_2k\\rfloor<2-\\log_2\\left(\\prod_{i=1}^{n}\\left(1+\\frac{1}{kv_{i}}\\right)\\right)\n\\end{equation}\n\nA product $\\prod(1+a_n)$ with positive terms $a_n$ is convergent if the series $\\sum a_n$ converges, see Knopp \\cite[p.~220]{Ref_Knopp}. A similar statement provides Murphy \\cite{Ref_Murphy}, who write the factors in the form $c_n=1+a_n$ and explains that if $\\prod c_n$ is convergent then $c_n\\rightarrow1$ and therefore if $\\prod (1+a_n)$ is convergent then $a_n\\rightarrow0$. Thus, to verify whether the product in condition~\\ref{eq:condition_max} is converging towards a limiting value, it is sufficient to examine the following sum:\n\\begin{equation*}\n\\sum_{i=1}^{n}\\frac{1}{kv_{i}}\n\\end{equation*}\n\nThe sum of reciprocal vertices depending only from $v_1$ is given in appendix~\\ref{appx:sum_reciprocal_vertices}.\n", "meta": {"hexsha": "bf178f1e33a744a0d8d1367ed99a4bd1f202fb6f", "size": 7774, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01 Graph Theory/TeX/v5.0/chapter/04_cycles.tex", "max_stars_repo_name": "Sultanow/collatz", "max_stars_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-01T15:12:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T15:54:55.000Z", "max_issues_repo_path": "01 Graph Theory/TeX/v5.0/chapter/04_cycles.tex", "max_issues_repo_name": "Sultanow/collatz", "max_issues_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01 Graph Theory/TeX/v5.0/chapter/04_cycles.tex", "max_forks_repo_name": "Sultanow/collatz", "max_forks_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-06T20:44:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-06T20:44:07.000Z", "avg_line_length": 49.5159235669, "max_line_length": 882, "alphanum_fraction": 0.7182917417, "num_tokens": 2524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256432832332, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.7252649558709696}}
{"text": "\\chapter{Matrix Calculations} \\index{Matrix calculations}\nA very powerful feature of {\\REDUCE} is the ease with which matrix\ncalculations can be performed. To extend our syntax to this class of\ncalculations we need to add another prefix operator, {\\tt MAT},\n\\ttindex{MAT} and a further\nvariable and expression type as follows:\n\n\\section{MAT Operator}\\ttindex{MAT}\nThis prefix operator is used to represent $n\\times m$ matrices. {\\tt\nMAT} has {\\em n} arguments interpreted as rows of the matrix, each of\nwhich is a list of {\\em m} expressions representing elements in that row.\nFor example, the matrix\n\\[ \\left( \\begin{array}{lcr} a & b & c \\\\ d & e & f \\end{array} \\right) \\]\nwould be written as {\\tt mat((a,b,c),(d,e,f))}.\n\nNote that the single column matrix\n\\[ \\left( \\begin{array}{c} x \\\\ y \\end{array} \\right) \\]\nbecomes {\\tt mat((x),(y))}.  The inside parentheses are required to\ndistinguish it from the single row matrix\n\\[ \\left( \\begin{array}{lr} x & y \\end{array} \\right) \\]\nthat would be written as {\\tt mat((x,y))}.\n\n\\section{Matrix Variables}\n\nAn identifier may be declared a matrix variable by the declaration {\\tt\nMATRIX}.\\ttindex{MATRIX}\nThe size of the matrix may be declared explicitly in the matrix\ndeclaration, or by default in assigning such a variable to a matrix\nexpression. For example,\n\\begin{verbatim}\n        matrix x(2,1),y(3,4),z;\n\\end{verbatim}\ndeclares {\\tt X} to be a 2 x 1 (column) matrix, {\\tt Y} to be a 3 x 4\nmatrix and {\\tt Z} a matrix whose size is to be declared later.\n\nMatrix declarations can appear anywhere in a program. Once a symbol is\ndeclared to name a matrix, it can not also be used to name an array,\noperator or a procedure, or used as an ordinary variable. It can however\nbe redeclared to be a matrix, and its size may be changed at that time.\nNote however that matrices once declared are {\\em global\\/} in scope, and so\ncan then be referenced anywhere in the program.  In other words, a\ndeclaration within a block (or a procedure) does not limit the scope of\nthe matrix to that block, nor does the matrix go away on exiting the block\n(use {\\tt CLEAR} instead for this purpose).  An element of a matrix is\nreferred to in the expected manner; thus {\\tt x(1,1)} gives the first\nelement of the matrix {\\tt X} defined above.  References to elements of a\nmatrix whose size has not yet been declared leads to an error.  All\nelements of a matrix whose size is declared are initialized to 0.  As a\nresult, a matrix element has an {\\em instant evaluation\\/}\\index{Instant\nevaluation} property and cannot stand for itself.  If this is required,\nthen an operator should be used to name the matrix elements as in:\n\\begin{verbatim}\n        matrix m; operator x;  m := mat((x(1,1),x(1,2));\n\\end{verbatim}\n\n\\section{Matrix Expressions}\n\nThese follow the normal rules of matrix algebra as defined by the\nfollowing syntax:\\ttindex{MAT}\n\\begin{verbatim}\n        <matrix expression> ::=\n                  MAT<matrix description>|<matrix variable>|\n                  <scalar expression>*<matrix expression>|\n                  <matrix expression>*<matrix expression>\n                  <matrix expression>+<matrix expression>|\n                  <matrix expression>^<integer>|\n                  <matrix expression>/<matrix expression>\n\\end{verbatim}\nSums and products of matrix expressions must be of compatible size;\notherwise an error will result during their evaluation.  Similarly, only\nsquare matrices may be raised to a power.  A negative power is computed as\nthe inverse of the matrix raised to the corresponding positive power.\n{\\tt a/b} is interpreted as {\\tt a*b\\verb|^|(-1)}.\n\n{\\it Examples:}\n\nAssuming {\\tt X} and {\\tt Y} have been declared as matrices, the following\nare matrix expressions\n\\begin{verbatim}\n        y\n        y^2*x-3*y^(-2)*x\n        y + mat((1,a),(b,c))/2\n\\end{verbatim}\nThe computation of the quotient of two matrices normally uses a two-step\nelimination method due to Bareiss.  An alternative method using Cramer's\nmethod is also available.  This is usually less efficient than the Bareiss\nmethod unless the matrices are large and dense, although we have no solid\nstatistics on this as yet.  To use Cramer's method instead, the switch\n{\\tt CRAMER}\\ttindex{CRAMER} should be turned on.\n\n\n\\section{Operators with Matrix Arguments}\n\nThe operator {\\tt LENGTH}\\ttindex{LENGTH} applied to a matrix returns a\nlist of the number of rows and columns in the matrix.  Other operators\nuseful in matrix calculations are defined in the following subsections.\nAttention is also drawn to the LINALG\n\\extendedmanual{(chapter~\\ref{LINALG})} and NORMFORM\n\\extendedmanual{(chapter~\\ref{NORMFORM})} packages.\n\n\\subsection{DET Operator}\\ttindex{DET}\nSyntax:\n\\begin{verbatim}\n        DET(EXPRN:matrix_expression):algebraic.\n\\end{verbatim}\n\nThe operator {\\tt DET} is used to represent the determinant of a square\nmatrix expression.  E.g.,\n\\begin{verbatim}\n        det(y^2)\n\\end{verbatim}\nis a scalar expression whose value is the determinant of the square of the\nmatrix {\\tt Y}, and\n\\begin{verbatim}\n        det mat((a,b,c),(d,e,f),(g,h,j));\n\\end{verbatim}\nis a scalar expression whose value is the determinant of the matrix\n\\[ \\left( \\begin{array}{lcr} a & b & c \\\\ d & e & f \\\\ g & h & j\n\\end{array} \\right) \\]\n\nDeterminant expressions have the {\\em instant evaluation\\/} property.\n\\index{Instant evaluation}  In other words, the statement\n\\begin{verbatim}\n        let det mat((a,b),(c,d)) = 2;\n\\end{verbatim}\nsets the {\\em value\\/} of the determinant to 2, and does not set up a rule\nfor the determinant itself.\n\n\\subsection{MATEIGEN Operator}\\ttindex{MATEIGEN}\nSyntax:\n\\begin{verbatim}\n        MATEIGEN(EXPRN:matrix_expression,ID):list.\n\\end{verbatim}\n\n{\\tt MATEIGEN} calculates the eigenvalue equation and the corresponding\neigenvectors of a matrix, using the variable {\\tt ID} to denote the\neigenvalue.  A square free decomposition of the characteristic polynomial\nis carried out.  The result is a list of lists of 3 elements, where the\nfirst element is a square free factor of the characteristic polynomial,\nthe second its multiplicity and the third the corresponding eigenvector\n(as an {\\em n} by 1 matrix).  If the square free decomposition was\nsuccessful, the product of the first elements in the lists is the minimal\npolynomial.  In the case of degeneracy, several eigenvectors can exist for\nthe same eigenvalue, which manifests itself in the appearance of more than\none arbitrary variable in the eigenvector.  To extract the various parts\nof the result use the operations defined on lists.\n\n{\\it Example:}\n The command\n\\begin{verbatim}\n        mateigen(mat((2,-1,1),(0,1,1),(-1,1,1)),eta);\n\\end{verbatim}\ngives the output\n\\begin{verbatim}\n        {{ETA - 1,2,\n\n          [ARBCOMPLEX(1)]\n          [             ]\n          [ARBCOMPLEX(1)]\n          [             ]\n          [      0      ]\n\n          },\n\n         {ETA - 2,1,\n\n          [      0      ]\n          [             ]\n          [ARBCOMPLEX(2)]\n          [             ]\n          [ARBCOMPLEX(2)]\n\n          }}\n\\end{verbatim}\n\n\\subsection{TP Operator}\\ttindex{TP}\nSyntax:\n\\begin{verbatim}\n        TP(EXPRN:matrix_expression):matrix.\n\\end{verbatim}\n\nThis operator takes a single matrix argument and returns its transpose.\n\n\\subsection{Trace Operator}\\ttindex{TRACE}\nSyntax:\n\\begin{verbatim}\n        TRACE(EXPRN:matrix_expression):algebraic.\n\\end{verbatim}\nThe operator {\\tt TRACE} is used to represent the trace of a square matrix.\n\n\\subsection{Matrix Cofactors}\\ttindex{COFACTOR}\nSyntax:\n\\begin{verbatim}\n  COFACTOR(EXPRN:matrix_expression,ROW:integer,COLUMN:integer):\n\t   algebraic\n\\end{verbatim}\n\nThe operator {\\tt COFACTOR} returns the cofactor of the element in row\n{\\tt ROW} and column {\\tt COLUMN} of the matrix {\\tt MATRIX}.  Errors occur\nif {\\tt ROW} or {\\tt COLUMN} do not simplify to integer expressions or if\n{\\tt MATRIX} is not square.\n\n\\subsection{NULLSPACE Operator}\\ttindex{NULLSPACE}\nSyntax:\n\\begin{verbatim}\n        NULLSPACE(EXPRN:matrix_expression):list\n\\end{verbatim}\n{\\tt NULLSPACE} calculates for a matrix {\\tt A} a list of linear\nindependent vectors (a basis) whose linear combinations satisfy the\nequation $A x = 0$.  The basis is provided in a form such that as many\nupper components as possible are isolated.\n\nNote that with {\\tt b := nullspace a} the expression {\\tt length b} is the\n{\\em nullity\\/} of A, and that {\\tt second length a - length b} calculates the\n{\\em rank\\/} of A.  The rank of a matrix expression can also be found more\ndirectly by the {\\tt RANK} operator described below.\n\n{\\it Example:} The command\n\\begin{verbatim}\n        nullspace mat((1,2,3,4),(5,6,7,8));\n\\end{verbatim}\n   gives the output\n \n\\begin{verbatim}\n        {\n         [ 1  ]\n         [    ]\n         [ 0  ]\n         [    ]\n         [ - 3]\n         [    ]\n         [ 2  ]\n         ,\n         [ 0  ]\n         [    ]\n         [ 1  ]\n         [    ]\n         [ - 2]\n         [    ]\n         [ 1  ]\n         }\n\\end{verbatim}\n \nIn addition to the {\\REDUCE} matrix form, {\\tt NULLSPACE} accepts as input a\nmatrix given as a list of lists, that is interpreted as a row matrix.  If\nthat form of input is chosen, the vectors in the result will be\nrepresented by lists as well.  This additional input syntax facilitates\nthe use of {\\tt NULLSPACE} in applications different from classical linear\nalgebra.\n\n\\subsection{RANK Operator}\\ttindex{RANK}\n \nSyntax:\n\\begin{verbatim}\n        RANK(EXPRN:matrix_expression):integer\n\\end{verbatim}\n{\\tt RANK} calculates the rank of its argument, that, like {\\tt NULLSPACE}\ncan either be a standard matrix expression, or a list of lists, that can\nbe interpreted either as a row matrix or a set of equations.\n\n{\\tt Example:}\n\n\\begin{verbatim}\n        rank mat((a,b,c),(d,e,f));\n\\end{verbatim}\nreturns the value 2.\n\n\\section{Matrix Assignments} \\index{Matrix assignment}\n\nMatrix expressions may appear in the right-hand side of assignment\nstatements. If the left-hand side of the assignment, which must be a\nvariable, has not already been declared a matrix, it is declared by default\nto the size of the right-hand side. The variable is then set to the value\nof the right-hand side.\n\nSuch an assignment may be used very conveniently to find the solution of a\nset of linear equations. For example, to find the solution of the\nfollowing set of equations\n\\begin{verbatim}\n        a11*x(1) + a12*x(2) = y1\n        a21*x(1) + a22*x(2) = y2\n\\end{verbatim}\nwe simply write\n\\begin{verbatim}\n        x := 1/mat((a11,a12),(a21,a22))*mat((y1),(y2));\n\\end{verbatim}\n\n\\section{Evaluating Matrix Elements}\n\nOnce an element of a matrix has been assigned, it may be referred to in\nstandard array element notation.  Thus {\\tt y(2,1)} refers to the element\nin the second row and first column of the matrix {\\tt Y}.\n\n", "meta": {"hexsha": "8e6082a84559b880f61b1a0bece5c78a7759052d", "size": 10739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "atomic_Decomp/Redlog/reduce.doc/matrix.tex", "max_stars_repo_name": "Korosensei42/AtomicDecomposition", "max_stars_repo_head_hexsha": "ca10f97c2cef1a258a4e9fade0a3133d1389d08e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "atomic_Decomp/Redlog/reduce.doc/matrix.tex", "max_issues_repo_name": "Korosensei42/AtomicDecomposition", "max_issues_repo_head_hexsha": "ca10f97c2cef1a258a4e9fade0a3133d1389d08e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "atomic_Decomp/Redlog/reduce.doc/matrix.tex", "max_forks_repo_name": "Korosensei42/AtomicDecomposition", "max_forks_repo_head_hexsha": "ca10f97c2cef1a258a4e9fade0a3133d1389d08e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.5272108844, "max_line_length": 78, "alphanum_fraction": 0.6992271161, "num_tokens": 2798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.7252468016367731}}
{"text": "%---------------------------Aspect Beta----------------------------------\n\\section{Aspect Beta}\n\nThis metric measures the radius ratio (\\emph{cf.}\n\\S\\ref{s:tet-radius-ratio}) of a positively-oriented tetrahedron. Note\nthat it is equal to the tetrahedral radius ratio.\n\nFor a positively-oriented tetrahedron, the aspect $\\beta$ is the\nquotient of these two radii normalized by $\\frac{1}{3}$ so \nthat an equilateral tetrahedron has quality of~$1$:\n\\begin{eqnarray*}\nq & = & \\frac{R}{3 r} \\nonumber \\\\\n  & = & \\frac { \\left| \n   \\normvec{L_3}^2 \\left( \\vec L_2 \\times \\vec L_0 \\right) + \n   \\normvec{L_2}^2 \\left( \\vec L_3 \\times \\vec L_0 \\right) + \n   \\normvec{L_0}^2 \\left( \\vec L_3 \\times \\vec L_2 \\right)\n   \\right| A}{108 V^2}.\n\\end{eqnarray*}\n\nNote that if the tetrahedron has negative orientation, we set $q = DBL\\_MAX$.\n\n\\tetmetrictable{aspect $\\beta$}%\n{$1$}%                  Dimension\n{$[1,3]$}%              Acceptable range\n{$[1,DBL\\_MAX]$}%       Normal range\n{$[1,DBL\\_MAX]$}%       Full range\n{$1$}%                  Equilateral tet\n{\\cite{par:93}}%        Citation\n{v\\_tet\\_aspect\\_beta}% Verdict function name\n", "meta": {"hexsha": "c0ae223ae109a7fc5c5a7641d0f187acf6ba4b3c", "size": 1125, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetAspectBeta.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetAspectBeta.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetAspectBeta.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 37.5, "max_line_length": 77, "alphanum_fraction": 0.6035555556, "num_tokens": 370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.7251555657038771}}
{"text": "\\documentclass[dissertation.tex]{subfiles}\n\\begin{document}\n\\chapter{Prerequisites}\\label{cha:prerequisites}\n\\section{Splines and \\bss}\\label{sec:spline}\nA \\emph{spline} is a piecewise polynomial function with prescribed\nregularity on its domain.\n\nMore formally we define a spline \\cite{deboor}\\cite{farin}\\cite{salomon}\\cite{bartels}\n$$s:[a,b]\\subset\\mR\\rightarrow\\mR$$\nas follows.\nWe have a partition of that interval defined by the \\emph{breakpoints}\n$$\\tau = \\{\\tau_0,\\dots,\\tau_\\ell\\}$$\nsuch that $a=\\tau_0<\\tau_1<\\dots<\\tau_{\\ell-1}<\\tau_\\ell=b$. Such\nbreakpoints define $\\ell$ intervals\n$$\nI_i=\n\\begin{cases}\n  [\\tau_i,\\tau_{i+1}) & \\mbox{if } i=0,\\dots,\\ell-2\\\\\n    [\\tau_i,\\tau_{i+1}] & \\mbox{if } i=\\ell-1.\\\\\n\\end{cases}\n$$\nIt is possible to define the following spaces:\n\\paragraph{Piecewise polynomial functions space} $P_{m,\\tau}$\nis the space of the functions that are polynomials of maximum degree $m$\nin each interval $I_i$ of the partition, formally:\n\\begin{multline*}\n  P_{m,\\tau}=\\{f:[a,b]\\rightarrow\\mR\\ \\mid\\ \\exists p_0\\dots\n  p_{\\ell-1}\\in\\Pi_m \\ \\text{such that}\\\\\n  f(t)=p(t),\\ \\forall t\\in I_i,\\\n  i=0\\dots \\ell-1\\}\n\\end{multline*}\nwhere $\\Pi_m$ is the space of the polynomials of degree $\\le m$. The\ndimension of $P_{m,\\tau}$ is\n\\begin{equation*}\n  dim(P_{m,\\tau})=\\ell(m+1)\n\\end{equation*}\nbecause the dimension of $\\Pi_m$\nis $m+1$.\n\\paragraph{Classic spline space}\\index{Classic splines} $S_{m,\\tau}$ is the space of\nthe piecewise polynomial functions of degree $m$ that have continuity\n$C^{m-1}$ in\nthe junctions of the intervals, formally:\n$$\nS_{m,\\tau}=P_{m,\\tau}\\cap C^{m-1}[a,b].\n$$\nThe dimension of this space is\n\\begin{equation}\n  \\label{eq:dimClassicSpline}\n  \\ell(m+1)-(\\ell-1)\\cdot m\\,=\\,\\ell+m.\n\\end{equation}\n\n\\paragraph{Generalized spline space}\\index{Generalized splines} $S_{m,\\tau,M}$ is the\nspace of piecewise polynomial functions of degree $m$ with a prescribed\nregularity at each breakpoint ranging from $-1$ to $m-1$. The\nregularity is prescribed by the multiplicity vector\n$$\nM=\\{m_1,\\dots,m_{\\ell-1}\\},\\quad m_i\\in\\mN,\\quad 1\\leq m_i\\leq m+1\n$$\nas follows,\n\\begin{multline*}\n  S_{m,\\tau,M}=\\{f:[a,b]\\rightarrow\\mR\\ \\mid\\ \\exists p_0\\dots\n  p_{\\ell-1}\\in\\Pi_m \\ \\text{such that}\\\\\n  f(t)=p(t),\\ \\forall t\\in I_i,\\\n  i=0\\dots \\ell-1\\ \\text{and}\\\\\n  p_{i-1}^{(j)}(\\tau_i)=p_{i}^{(j)}(\\tau_i),\\ j=0,\\dots,m-m_i,\\ i=1,\\dots,\\ell-1\\}.\n\\end{multline*}\nThe dimension of the space is equal to \n\\begin{equation*}\n  dim(S_{m,\\tau,M})=\\ell(m+1)-\\sum_{i=1}^{\\ell-1}(m-m_i+1)=m+\\mu +1\\qquad(\\mu=\\sum_{i=1}^{\\ell-1}m_i)  \n\\end{equation*}\n\nand is true that\n$$\n\\Pi_m\\subseteq S_{m,\\tau}\\subseteq S_{m,\\tau,M}\\subseteq P_{m,\\tau},\n$$\nin particular:\n\\begin{itemize}\n  \\item if $m_i=1$ for all $i=1,\\dots,\\ell-1$, then\n    $S_{m,\\tau,M}=S_{m,\\tau}$;\n  \\item if $m_i=m+1$ for all $i=1,\\dots,\\ell-1$, then\n    $S_{m,\\tau,M}=P_{m,\\tau}$.\n\\end{itemize}\n\n\\subsection{Truncated-powers basis for classic\n  splines}\\label{sec:truncpow}\\index{Classic splines!truncated-powers basis}\nA truncated power $(t-\\tau_i)_+^m$ is\ndefined by\n$$\n(t-\\tau_i)_+^m=\n\\begin{cases}\n  0,&\\mbox{if}\\quad t\\leq\\tau_i\\\\\n  (t-\\tau_i)^m, &\\mbox{otherwise}.\n\\end{cases}\n$$\nIt is possible to demonstrate that the functions\n$$\ng_i(t)=(t-\\tau_i)_+^m)\\ \\in S_{m,\\tau},\\quad i=1,\\dots,\\ell-1\n$$\nare linearly independents, and that the set\n$$\n1,t,t^2,\\dots,t^m,(t-\\tau_1)_+^m,\\dots,(t-\\tau_{\\ell-1})_+^m\n$$\nforms a basis for the classic spline space \\cite{deboor}. Then a\ngeneric element $s\\in S_{m,\\tau}$ can be expressed as follows,\n\\begin{equation}\\label{eq:classicSplineElement}\n  s(t)=\\sum_{i=0}^m c_i t^i\\, +\\, \\sum_{j=1}^{\\ell-1} d_j\n  (t-\\tau_j)_+^m\\qquad\n  \\begin{split}\n    &c_i\\in\\mR,\\ i=0,\\dots,m\\\\\n    &d_j\\in\\mR,\\ j=1,\\dots,\\ell-1.\n  \\end{split}\n\\end{equation}\n\n\\subsection{\\bss basis for classic\n  splines}\\label{sec:bsplines}\\index{\\bss}\\index{Classic splines!\\bss basis}\n\\emph{\\bss} are a specific basis which can be alternatively used to\nrepresent any generalized spline \\cite{deboor}\\cite{farin}\\cite{salomon}\\cite{bartels}. In this\nparagraph, however, we consider only their definition to generate the\nclassic spline space $S_{m,\\tau}$. Furthermore in some textbooks, for\nnotational convenience, the\n\\emph{order}$=m+1$ is considered.\n\nFor defining the \\bss \\cite{deboor} we need to extend the partition vector\n$\\tau=\\{\\tau_0,\\cdots,\\tau_\\ell\\}$ with $m$ knots to the left and $m$ to\nthe right, thus we define a new vector, usually called \\emph{extended knot} vector,\n$$\nT=\\{t_0,\\dots,t_{m-1},t_{m},\\dots,t_{n+1},t_{n+2},\\dots,t_{n+m+1}\\}\n$$\nsuch that\n\\begin{equation*}\n  t_0\\leq\\dots\\leq t_{m-1}\\leq \\overmath{\\equiv\\tau_0\\equiv a}{t_{m}}<\\dots<\\overmath{\\equiv\\tau_\\ell\\equiv b}{t_{n+1}}\\leq t_{n+2}\\leq\\dots\\leq t_{n+m+1}.    \n\\end{equation*}\nSince $\\tau$ has $\\ell+1$ elements, we can calculate the value of\n$$\nn=\\ell+m-1.\n$$\nThus the dimension of $S_{m,\\tau}$, for\n\\cref{eq:dimClassicSpline}, is \n\\begin{equation*}\n  dim(S_{m,\\tau})=\\ell+m=n+1  \n\\end{equation*}\n\nThe $n+1$ basis $N_{i,m+1}(t)$ of the \\bss of degree $m$ are defined,\nfor $i=0,\\dots,n$, by the recursive formula:\n\\begin{align*}\n  N_{i,1}(t) &=\n  \\begin{cases}\n    1,\\quad \\mbox{if}\\quad t_i\\leq t<t_{i+1}\\\\\n    0,\\quad \\mbox{otherwise}\\qquad\\qquad\\qquad i=0,\\dots,n+m\n  \\end{cases}\\\\\n  N_{i,r}(t) &= \\omega_{i,r-1}(t)\\cdot N_{i,r-1}(t)\\ +\\\n  (1-\\omega_{i+1,r-1}(t))\\cdot N_{i+1,r-1}(t)\\\\\n             &\\pushright i=0,\\dots,n+m+1-3,\\ r=2,\\dots,m+1\n\\end{align*}\nwhere\n$$\n\\omega_{i,r}(t) = \\begin{cases}\n  \\frac{t-t_i}{t_{i+r}-t_i},&\\mbox{if }t_i\\neq t_{i+r}\\\\\n  0, &\\mbox{otherwise.}\n\\end{cases}\n$$\n\nThen any function $s\\in S_{m,\\tau}$ can be expressed also as a linear\ncombination of \\bss,\n\\begin{equation}\\label{eq:bsplineElement}\n  s(t)=\\sum_{i=0}^nv_i N_{i,m+1}(t)\\qquad, v_i\\in\\mR, i=0,\\dots,n.\n\\end{equation}\n\n\\subsection{Spline curves}\\index{Spline curves}\nA \\emph{spline curve} in the affine space $\\mE^d$ is the image of a\nparametric vector function $\\ve{S}:[a,b]\\rightarrow\\mE^d$ whose\ncomponents are all splines belonging to a fixed spline space\n$S_{m,\\tau}$, for $d=3$\n\\begin{equation}\\label{eq:bsplineCurveComp}\n  \\ve{S}(u) = \\left[\n    \\begin{array}{c}\n      \\ve{x}(u)\\\\\n      \\ve{y}(u)\\\\\n      \\ve{z}(u)\n    \\end{array}\n    \\right].\n\\end{equation}\n\n$\\ve{S}(u)$ can be written as follows in the\ntruncated-powers basis\n% A parametric spline \\emph{curve} $\\ve{S}(t)$ is a curve in a certain\n% dimension obtained applying a spline function to a set of points\n% in the same dimension\n% called \\emph{control vertices}. We can apply the control vertices to a\n% spline expressed with the truncated powers as in\n\\cref{eq:classicSplineElement} replacing the coefficients $c_i$ and\n$d_i$ with points\n\\begin{equation}\\label{eq:classicSplineCurve}\n  \\begin{multlined}\n  \\ve{S}(u)=\\sum_{i=0}^m \\ve{c_i}\\cdot t^i\\, +\\, \\sum_{j=1}^{\\ell-1}\n  \\ve{d_j}\\cdot (u-\\tau_j)_+^m\\qquad,\\ve{c_i}\\in\\mE^d,\\\n  \\ve{d_j}\\in\\mE^d\\\\\n  i=0,\\dots,m;\\ j=0,\\dots,\\ell-1.\n  \\end{multlined}\n\\end{equation}\n\nThis representation is not practical because\nthere isn't an intuitive correlation between the points\n$\\ve{c_i}$, $\\ve{d_j}$ and the curve itself. Moreover the\ndetermination of an interpolant to assess argued points in $\\mE^d$\nis not a well conditioned problem if this form is adopted\n\\cite{deboor}. To overcome those drawbacks the \\emph{\\bss\n  basis} is adopted (\\cref{sec:bsplines}).\n\nWe can apply control vertices to a spline expressed with the \\bs\nbasis as in \\cref{eq:bsplineElement} replacing the coefficients $v_i$\nwith points, in this case $\\ve{S}(u)$ is represented as follows\n\\begin{equation}\\label{eq:bsplineCurve}\n  \\ve{S}(u)=\\sum_{i=0}^n\\ve{v_i}\\cdot N_{i,m+1}(u)\\qquad\n  ,\\ve{v_i}\\in\\mE^d,\\ i=0,\\dots,n.\n\\end{equation}\nThe representation of \\cref{eq:bsplineCurve} is more convenient\nthan the previous one (\\cref{eq:classicSplineCurve}) because the curve\n$\\ve{S}(u)$ roughly \nfollows the shape given by the points $\\ve{v_i}$. Those points are\ncalled \\emph{control vertices} because they are used to control the\ncurve shape. Conformally the polygon they define is called \\emph{control polygon}.\n\n\\section{\\bss curves properties}\\label{sec:bsplineProp}\\index{\\bss!properties}\nIn this section we describe some properties of \\bs curves that we\nuse for the development of the project.\n\n\\subsection{\\acf{CHP}}\\label{sec:convexHull}\\index{\\bss!\\acf{CHP}}\nThe \\acf{CHP} states that a \\bs curve $\\ve{S}(u)$ of order $m$,\ndefined by the control polygon \n$\\ve{v_0},\\ve{v_1},\\dots,\\ve{v_n}$, is contained inside the union of the\nconvex hulls composed of $m+1$ vertices of the control polygon\n\\cite{farin}. If we\ncall $\\conv(\\ve{w_0},\\ve{w_1},\\dots,\\ve{w_j})$ the convex hull of the\nvertices $\\ve{w_0},\\ve{w_1},\\dots,\\ve{w_j}$ then we have\n\\begin{eqnarray*}\n  C_0&=&\\conv(\\ve{v_0},\\ve{v_1},\\dots,\\ve{v_{m}})\\\\\n  C_1&=&\\conv(\\ve{v_1},\\ve{v_2},\\dots,\\ve{v_{m+1}})\\\\\n  &\\cdots&\\\\\n  C_{n-m}&=&\\conv(\\ve{v_{n-m}},\\ve{v_{n-m+1}},\\dots,\\ve{v_{n}})\\\\\n\\end{eqnarray*}\nand the area where $\\ve{S}$ is contained is\n\\begin{equation*}\n  C=C_0\\cup C_1\\cup\\dots\\cup C_{n-m}\n\\end{equation*}\nor in other words must be true\n\\begin{equation*}\n  \\ve{S}(u)\\cap C =\\ve{S}(u)\\qquad \\forall u\\in[a,b]\n\\end{equation*}\nwhatever is the partition vector.\n\n\\begin{myfig}{Convex hull containing \\bs of degree 2}{fig:convexHull}\n  \\begin{tikzpicture}\n    \\coordinate (a) at (0,0);\n    \\coordinate (b) at (0.5,1.7);\n    \\coordinate (c) at (2,3);\n    \\coordinate (d) at (4,3);\n    \\coordinate (e) at (5.5,1.7);\n    \\coordinate (f) at (6,0);\n    \n    \\path[convexHull] (a) -- (b) -- (c) -- (a);\n    \\path[convexHull] (b) -- (c) -- (d) -- (b);\n    \\path[convexHull] (c) -- (d) -- (e) -- (c);\n    \\path[convexHull] (d) -- (e) -- (f) -- (d);\n    \n    \\draw[convexHullBord] (a) -- (c);\n    \\draw[convexHullBord] (b) -- (d);\n    \\draw[convexHullBord] (c) -- (e);\n    \\draw[convexHullBord] (d) -- (f);\n    \n    \\draw[controlPoly] (a) -- (b) -- (c) -- (d) -- (e) -- (f);\n    \\foreach \\p in {a,b,c,d,e,f}\n    \\filldraw[controlVert] (\\p) circle (2pt);\n\n    \\node[above left] at (a) {$\\ve{v_0}$};\n    \\node[above left] at (b) {$\\ve{v_1}$};\n    \\node[above] at (c) {$\\ve{v_2}$};\n    \\node[above] at (d) {$\\ve{v_3}$};\n    \\node[above right] at (e) {$\\ve{v_4}$};\n    \\node[above right] at (f) {$\\ve{v_5}$};\n  \\end{tikzpicture}  \n\\end{myfig}\nIn \\cref{fig:convexHull} an example of control polygon is visible,\ntogether with the region $C$ (in cyan) where an associated quadratic\n\\bs curve is located.\n\nNote that the \\ac{CHP} holds also in\n3-dimensional\nspace - i.e. a quadratic \\bs in 3-dimensional space is contained\ninside a flat surface composed by the union of triangles. From degree 3\nthe area where $\\ve{S}$ is contained is not plane anymore\nbecause it is composed by the union of solid polyhedrons.\n\n\\subsection{Aligned vertices}\\index{\\bss!aligned vertices}\\label{sec:alignedVertices}\nBecause control polygons with sequences of\naligned vertices have been adopted in some parts of this project, in\nthis section their specific \neffect on the curve shape is analyzed. \n\nWe can have the following situations:\n\\paragraph{$m$ aligned control vertices}\nIf $m$ control vertices $v_i,\\dots,v_{i+m-1}$ of the control polygon\nare on the same line then\nthe curve $\\ve{S}$ touches the segment joining those vertices.\n\n\\paragraph{$m+1$ aligned control vertices}\nIf $m+1$ control vertices $v_i,\\dots,v_{i+m}$ of the control polygon\nare on the same line then a polynomial arc of the curve $\\ve{S}$\nlays on the segment joining those vertices.\n\n\\subsection{Smoothness}\\label{sec:smoothness}\\index{Smoothness}\\index{\\bss!smoothness}\nA function is said smooth of class $C^d$ if it is possible to\ncalculate the $d$-th derivative of it and if such derivative is\ncontinue. A function $f$ that is not continue is said to be of class\n$C^{-1}$, a function that is continue until derivative $d$ is said to\nbe of class $C^d$, a function that is always continue for every\nderivative is said to be of class $C^\\infty$.\n\nA \\bs curve of degree $m$ with $n$ control vertices is composed by\n$n-m$ polynomial segments, one for each \ninterval \n\\begin{equation*}\n[t_i,t_{i+1}]\\qquad i=m,\\dots,n+1;\n\\end{equation*}\nthis means that $\\ve{S}(u)$ is $C^\\infty$ for\n\\begin{equation*}\nu\\in(t_i,t_{i+1})\\qquad i=m,\\dots,n+1.\n\\end{equation*}\nNote that, if we use generalized \\bs curves, an interval\n$[t_i,t_{i+1}]$ can also degenerate in just a point if\nwe have a knot multiplicity $>1$, in\nsuch case there isn't a polynomial segment.\nOn every breakpoint $\\tau_i$ with $i=1,\\dots,n+m$ we have that the curve has\nsmoothness\\footnote{If we use generalized \\bs curves, it has\n  smoothness $C^{m-r}$ where $r$ is the\nmultiplicity of the knot \\cite{farin}.} $C^{m-1}$.\n\nIn our project we don't use generalized \\bs curves, thus a\ncurve of degree $m$ has global smoothness\n\\begin{equation*}\n  C^{m-1}.\n\\end{equation*}\n\n\\subsection{End point interpolation}\\index{\\bss!end point interpolation}\\label{sec:clamped}\nIn general a \\bs curve with control vertices\n\\begin{equation*}\n  \\ve{v_0}, \\dots, \\ve{v_n}\n\\end{equation*}\nand extended knot vector\n\\begin{equation*}\n  T=\\{t_0,\\dots,t_{m-1},t_{m},\\dots,t_{n+1},t_{n+2},\\dots,t_{n+m+1}\\}\n\\end{equation*}\ndoes not necessarily interpolate any control vertex $v_i$, neither the\nfirst nor the last one. But we are\ninterested in using \\bs for representing paths from one point to\nanother. Hence, it should be a nice feature to have that the curve defined in\nthe domain $[a,b]$ is shaped such that\n\\begin{equation}\\label{eq:clamped}\n  \\begin{cases}\n    \\ve{S}(u)=\\ve{v_0}& \\text{for } u=a\\\\\n    \\ve{S}(u)=\\ve{v_n}& \\text{for } u=b.\n  \\end{cases}\n\\end{equation}\n\nWe can obtain \\cite{deboor} the conditions of \\cref{eq:clamped} if we\nimpose\n\\begin{equation*}\n  t_0=\\dots= t_{m-1}= \\overmath{\\equiv a}{t_{m}}<\\dots<\n\\overmath{\\equiv b}{t_{n+1}}= t_{n+2}=\\dots= t_{n+m+1}\n\\end{equation*}\non the extended partition vector $T$. In other words\n\\begin{equation*}\n  T=\\{\\overbrace{a,\\dots,a}^m,t_{m+1},\\dots,t_{n},\\overbrace{b,\\dots,b}^m\\}.\n\\end{equation*}\n\n\\subsection{Curvature and torsion}\\index{Curvature and torsion}\\index{\\bss!curvature and torsion}\nSince we are interested in comparing different curves,\nwe need to recognize if a certain curve is a \\emph{good} or a\n\\emph{bad} one. One factor that characterizes a certain curve can \nbe its smoothness (\\cref{sec:smoothness}) - i.e. a $C^3$ curve\nis better than a $C^2$ curve - but this isn't\nenough for comparing curves. Usually\n\\emph{curvature} and \n\\emph{torsion} are used for this purpose\n\\cite{docarmo}\\cite{salomon}. Both are scalar quantities defined on\nsufficiently smooth \nparametric curves for each value of the parameter, and they do not\ndepend on the selected parametrization.\n\nFor a generic parametric curve\\footnote{\\label{ftn:genericParCur}Thus\n  also a \\bs curve.} $\\ve{S}(u)$ defined for $u\\in[a,b]$\ngiven the notation $\\wedge$ for the vector product and for \\cref{eq:bsplineCurveComp}\n\\begin{equation*}\n  \\dot{\\ve{S}}(u) = \\frac{\\md}{\\md u} \\ve{S}(u)=\\left[\n    \\begin{array}{c}\n      \\frac{\\md}{\\md u} \\ve{x}(u)\\\\\n      \\frac{\\md}{\\md u} \\ve{y}(u)\\\\\n      \\frac{\\md}{\\md u} \\ve{z}(u)\n    \\end{array}\n    \\right],\n\\end{equation*}\nwe define the\ncurvature $\\kappa(u)$ and, in points with non vanishing curvature,\nthe torsion $\\tau(u)$ as\n\\begin{empheq}[left={=\\empheqbiglbrace~}]{align}\n  \\kappa(u) &= \\frac{\\norm{\\dot{\\ve{S}}(u)\\wedge\\ddot{\\ve{S}}(u)}}{{\\norm{\\dot{\\ve{S}}(u)}}^3}  \\label{eq:curvature}\\\\\n  \\tau(u) &= \\frac{\\det\\left[\\dot{\\ve{S}}(u),\\ddot{\\ve{S}}(u),\\dddot{\\ve{S}}(u)\\right]}{\\norm{\\dot{\\ve{S}}(u)\\wedge\\ddot{\\ve{S}}(u)}} = \\frac{\\left(\\dot{\\ve{S}}(u)\\wedge\\ddot{\\ve{S}}(u)\\right)\\cdot\\dddot{\\ve{S}}(u)}{\\norm{\\dot{\\ve{S}}(u)\\wedge\\ddot{\\ve{S}}(u)}}.  \\label{eq:torsion}\n\\end{empheq}\n\n\\Cref{eq:curvature} and \\cref{eq:torsion} describe completely the\nbehavior of $\\ve{S}(u)$ locally for each value of $u$. Curvature and\ntorsion have also a geometric interpretation: for each value $\\tilde{u}$ of\nthe parameter $u$, the inverse $\\frac{1}{\\kappa(\\tilde{u})}$ of the\ncurvature is the radius of curvature of $\\ve{S}$ at\n$\\ve{S}(\\tilde{u})$ - i.e. the radius of the \nosculating circle tangent in that point. $\\tau(\\tilde{u})$ indicates\n(if $\\kappa(\\tilde{u})\\neq 0$) how sharply the plane where\nthe curve lies is rotating.\n\nThe value of $\\kappa(u)$ can be only non negative, while $\\tau(u)$ is\na signed quantity.\n\nTwo curves of same smoothness can be compared using the plots of\ncurvature and torsion, in general curves that have lower peaks of\n$\\kappa(u)$ and $\\tau(u)$ are better than curves with\nhigher peaks.\n\n\\subsection{Arc length}\\index{Arc length}\\index{\\bss!arc length}\nSometimes we are interested in evaluating the length of a generic\nparametric curve\\footnote{See \\cref{ftn:genericParCur}.} $\\ve{S}(u)$\ndefined for $u\\in[a,b]$. We can obtain such length, called \\emph{arc\n  length}, calculating the integral\n\\begin{equation*}\n  \\int_a^b\\norm{\\dot{\\ve{S}}(u)}\\md u.\n\\end{equation*}\n\nWe can approximate this value using a discrete tabulation of the curve\n$\\ve{S}(u)$ and an integrating method like the \\emph{trapezoidal\n  rule} \\cite{press}\\cite{stoer}.\n\n\\section{Voronoi Diagrams}\\label{sec:voronoi}\\index{\\acfp{VD}}\nIn this section we introduce \\acfp{VD}, an important structure used in\nthe project. \\acp{VD} \\cite{deberg} provide a method to create a\npartition of the\nspace using distances from a set of input points called\n\\emph{sites}. Formally we have a set\n\\begin{equation*}\n  S=\\{\\ve{s_0},\\ve{s_1},\\dots,\\ve{s_n}\\} \\subset \\mE^d\n\\end{equation*}\nof $n$ sites in the euclidean space of dimension $d$, and we build a\nset of $n$ Voronoi \\emph{cells}\\footnote{$2^{\\mE^d}$ is the power set of\n  $\\mE^d$, the set of all the subsets of $\\mE^d$.}\n\\begin{equation*}\n  Vor(S)=\\{V(\\ve{s_0}),\\dots,V(\\ve{s_n})\\}\\subset 2^{\\mE^d}\n\\end{equation*}\nsuch that\n\\begin{equation*}\n  V(\\ve{\\ve{s_i}})=\\{\\ve{p}\\in\\mE^d\\ :\\\n  \\norm{\\ve{p}-\\ve{s_i}}<\\norm{\\ve{p}-\\ve{s_j}}\\ \\forall \\ve{s_j}\\neq\\ve{s_i}\\}\n\\end{equation*}\nis the set of the points in $\\mE^d$ closer to $\\ve{s_i}$ than to any\nother site.\n\n\\image{voronoi.eps}{Example of a \\ac{VD}, dashed lines are infinite edges.}{fig:voronoi}\n\\Cref{fig:voronoi} is an example of the \\ac{VD} built on some random\nsites, the dashed lines in the figure are edges that go to infinite.\n\n\\image{fortune.png}{Fortune's algorithm execution}{fig:fortune}\n\\index{Fortune's algorithm}The most important algorithm for\ncalculating \\acp{VD} is the \\emph{Fortune's}\n\\emph{sweeping line} algorithm that builds the diagram in $\\bigO(n\\log\nn)$ and it is optimal. The algorithm involves building $Vor(S)$\nincrementally while sweeping the space, see \\cref{fig:fortune}. Every\ntime that the sweeping\nline finds a site the algorithm creates a parabola using the site as\nfocus and the sweeping line as directrix. Such parabolas, or better\nthe arcs between each intersection of them, constitute\nthe \\emph{beach line}. A parabola disappears from the scene when the\nassociated\narc vanishes. The evolution of the intersection points on the beach line\nconstitutes the edges of the \\ac{VD}, and each point where an arc of\nthe beach line disappears constitutes a vertex of the \\ac{VD}.\nRefer to \\cite{deberg} and\n\\cite{fortune} for details about the Fortune's algorithm.\n\nOne property of \\acp{VD} is that $V(\\ve{s_i})$ can be a closed or an\nopen area - i.e. the edges of the cells can be infinite - it is important\nto keep this in mind if we want to interpret $Vor(S)$ as a graph. In\nthat case the graph will have edges that go to infinite. We call such\ngraph $G(Vor(S))$.\n\nAnother property is that, if we have $d+1$ sites $\\ve{s_0'},\\dots,\\ve{s_d'}$ that lay on the\nsurface of a $(d-1)$-sphere\\footnote{A circumference in $2$-dimensional\n  space, a sphere in $3$-dimensional space, an hypersphere in\n  $n$-dimensional space with $n\\ge 3$.} that does not have any other site on\nthe interior, then the center point of the $(d-1)$-sphere is the\nvertex shared only between the $d+1$ cells\n$V(\\ve{s_0'}),\\dots,V(\\ve{s_d'})$ \\cite{deberg}. This is not true for\nless than\n$d+1$ sites on a\n$(d-1)$-sphere because they are not enough to define it univocally,\nbut is possible to have $n>d+1$ sites on a $(d-1)$-sphere. In that\ncase, the center of the $(d-1)$-sphere is the shared vertex of the\ncells corresponding to the $n$ sites. This is important to reason\nabout the topography of $G(Vor(S))$ because if we allow more than\n$d+1$ sites on a $(d-1)$-sphere then the maximum degree\n$\\Delta(G(Vor(S)))$ of the graph can be arbitrarily big (up to the\nnumber of vertices). However, the fact that we work with coordinates in\n$\\mE^d$ legitimizes the restriction\\footnote{We can also relax this\n  restriction and in case create multiple nodes connected by zero-distance\n  edges on the graph.} of not\nallowing more than $d+1$ sites on an $(d-1)$-sphere, limiting\n$\\Delta(G(Vor(S)))$ to $d+1$.\n\n\\section{Statistical methods}\\label{sec:statisticalMethods}\nIn this section we briefly introduce the \\acf{MCM}\n\\cite{metropolis}\\cite{sobol}\\cite{newman} and the \\acf{SA} \\cite{kirkpatrick}\\cite{ho},\ntwo statistical methods to calculate unknown quantities and to find\nfunctions minima. Additionally, we introduce \\acf{LR} \\cite{benjamin}, a\nmethod to transform a constrained optimization problem in an\nunconstrained one by increasing the state space\ndimension.\n\\subsection{Notes on probabilities}\n\\subsubsection{\\ac{PE}}\\index{\\acf{PE}}\nFor a random variable $X$ normally distributed with\n\\begin{itemize}\n\\item mean $\\mu$;\n\\item variance $\\sigma$;\n\\end{itemize}\nfor\n\\begin{equation*}\n  r=0.6745\\sigma\n\\end{equation*}\nwe have that\n\\begin{equation*}\n  \\prob{\\abs{X-\\mu}<r} = \\prob{\\abs{X-\\mu}>r} = 0.5.\n\\end{equation*}\nThus values of $X$ that deviate from $\\mu$ less or more than $r$ have the\nsame probability, and $r$ identifies the most \\ac{PE} in a\nnormal distribution.\n\\subsubsection{\\acf{PCLT}}\\index{\\acf{PCLT}}\nConsider $N$ independent and \\emph{identically-distributed} random variables\n$X_1,X_2,\\dots,X_N$, with same mean and same variance\n\\begin{eqnarray*}\n  \\expected{X_1}=\\expected{X_2}=\\dots=\\expected{X_N}&=&m\\\\\n  \\variance{X_1}=\\variance{X_2}=\\dots=\\variance{X_N}&=&b^2.\n\\end{eqnarray*}\n\nConsider the sum of those random variables:\n\\begin{equation*}\n  Y = X_1+X_2+\\cdots+X_N;\n\\end{equation*}\nwe have that\n\\begin{eqnarray*}\n  \\expected{Y}&=&\\expected{X_1+X_2+\\cdots+X_N}=Nm\\\\\n  \\variance{Y}&=&\\variance{X_1+X_2+\\cdots+X_N}=Nb^2.\n\\end{eqnarray*}\n\nConsider a normally distributed random variable $Z$ with\nparameters:\n\\begin{eqnarray*}\n  \\mu&=&Nm\\\\\n  \\sigma&=&b\\sqrt{N}\n\\end{eqnarray*}\nwith \\ac{PDF} $p_Z(x)$.\n\nThe \\emph{\\ac{PCLT}} affirms that, for $N$ big\nenough, and for every interval $(x_1,x_2)$, applies:\n\\begin{equation}\\label{eq:tcl}\n  \\prob{x_1<Y<x_2}\\approx\\int_{x_1}^{x_2}p_Z(x) \\md x.\n\\end{equation}\nThus, the sum of an elevate number of identically-distributed random\nvariables is a random variable with normal distribution with mean $Nm$\nand variance $Nb^2$, even if\n$X_1,X_2,\\dots,X_N$ aren't normally distributed.\n\n\\subsection{\\acf{MCM}}\\index{\\acf{MCM}}\nIf we suppose to calculate an unknown quantity $m$, we need\nto find a random variable $X$ such that:\n\\begin{equation*}\n  \\expected{X} = m.\n\\end{equation*}\nIf we have such distribution with variance:\n\\begin{equation*}\n  \\variance{X} = b^2\n\\end{equation*}\nit is possible to formalize the following passages.\n\nConsider $N$ random variables $X_1,X_2,\\dots,X_N$ that have\ndistribution identical to the distribution of $X$. For the \\ac{PCLT}\n\\cref{eq:tcl} we have that, for $N$ big enough\n\\begin{equation*}\n  Y=X_1+X_2+\\cdots+X_N\n\\end{equation*}\nis normally distributed with parameters\n\\begin{eqnarray*}\n  \\mu &=& Nm\\\\\n  \\sigma&=&b\\sqrt{N}.\n\\end{eqnarray*}\n\nFor the \\emph{three sigma rule} \\cite{pukelsheim} we have that:\n\\begin{equation*}\n  \\prob{\\mu-3\\sigma < Y <\\mu +3\\sigma}\\approx 0.997\n\\end{equation*}\nthat is\n\\begin{equation*}\n  \\prob{Nm-3b\\sqrt{N} < Y < Nm+3b\\sqrt{N}}\\approx 0.997\n\\end{equation*}\ndividing by $N$\n\\begin{equation*}\n  \\prob{m-\\frac{3b}{\\sqrt{N}} < \\frac{Y}{N} <\n    m+\\frac{3b}{\\sqrt{N}}}\\approx 0.997\n\\end{equation*}\nthat is\n\\begin{equation*}\n  \\prob{\\abs{\\frac{Y}{N}-m} <\\frac{3b}{\\sqrt{N}}}\\approx 0.997\n\\end{equation*}\nresults in\n\\begin{equation}\\label{eq:mc}\n  \\prob{\\abs{\\frac{1}{N}\\sum_{i=1}^NX_i-m} <\\frac{3b}{\\sqrt{N}}}\\approx 0.997.\n\\end{equation}\n\n\\Cref{eq:mc} asserts that, if we extract a sample for each random\nvariable $X_i$, the arithmetic mean of those values is approximately\nequal to $m$. Moreover, the error of such approximation is equal to\n$3b/\\sqrt{N}$, that tend to $0$ increasing $N$. It is also possible to\nfurther \nreduce the uncertainty ($1-0.997=0.003$) by increasing the number $k$ of\nsigma used for the\napproximation and evaluating the error $kb/\\sqrt{N}$.\n\nIn practice, since the random variables $X_i$ have the same\ndistribution of $X$, it is sufficient to extract $N$ samples from $X$ to\nreach the same conclusions.\n\nThe \\acf{MCM} is constituted by the following procedure, to be adapted\naccording to the problems:\n\\begin{enumerate}\n\\item find the distribution $X$ having desired quantity $m$ as mean\n  value and $b^2$ as variance;\n\\item extract $N$ samples from $X$, with $N$ big enough to have an\n  error as small as desired;\n\\item the arithmetic mean of those $N$ samples is the approximation of\n  the desired value $m$.\n\\end{enumerate}\nEssentially, we transforme the problem from \\emph{calculating $m$} to\n\\emph{finding\n  the distribution $X$}, or anyway the $N$ samples distributed\naccordingly to $X$.\n\nIf we want to characterize more in detail the error committed taking\n$N$ samples, we can use to \\ac{PE}. If we set $k=0.6745$ then we\nhave that\n\\begin{equation*}\n  \\prob{\\abs{\\frac{1}{N}\\sum_{i=1}^NX_i-m} <\\frac{0.6745\\cdot b}{\\sqrt{N}}}\\approx 0.5\n\\end{equation*}\nand so\n\\begin{equation*}\n  r_N = \\frac{0.6745\\cdot b}{\\sqrt{N}}\n\\end{equation*}\nindicates how much the value $\\frac{1}{N}\\sum_{i=1}^NX_i$ deviates\nfrom the desired value $m$. Such value characterize the absolute error\n\\begin{equation*}\n\\abs{\\frac{1}{N}\\sum_{i=1}^NX_i-m}  \n\\end{equation*}\ncommitted taking $N$ samples.\n\n\\ac{MCM} is useful to simulate events that have an high degree of\nuncertainty in the inputs or an high degree of liberty in the\nstate: for instance, numerically integrate a function with many\ndimensions or \\acf{SA} (\\cref{sec:simulatedAnnealing}).\n\n\\subsection{\\acf{SA}}\\label{sec:simulatedAnnealing}\\index{\\acf{SA}}\nThe \\ac{SA} is a method used to find the global maximum or\nminimum of a function. It is inspired by a method\nused in metallurgy that consists in heating and then cooling slowly a\nmaterial to increase the size of the crystals and improving\nthe chemico-physical properties. The function that must be optimized\ncan be\ndefined in a multiple-dimensional space.\n\n\\subsubsection{Statistical thermodynamic}\nTo describe the basic principles of statistical thermodynamic we\nconsider the following example. In a one-dimensional lattice every point\nis a particle with a value of spin that can be \\emph{up} or\n\\emph{down}. If the lattice has $N$ points then the system can be in\n$2^N$ different configurations, where each one of those configurations\ncorresponds to a value of energy, for instance:\n\\begin{equation*}\n  E=B(n_+-n_-)\n\\end{equation*}\nwhere $B$ is some constant, $n_+$ is the number of particles with spin\n\\emph{up} and $n_-$ is the number of particles with spin \\emph{down}.\n\nThe probability $B(\\sigma)$ of finding the system in a certain\nconfiguration $\\sigma$ is given by the distribution of\n\\emph{Boltzmann-Gibbs}:\n\\begin{equation}\\label{eq:distBoltz}\n  P(\\sigma) = C \\me^{-E_\\sigma/T}\n\\end{equation}\nwhere $E_\\sigma$ is the energy of the configuration, $T$ is the\ntemperature\\footnote{The real Boltzmann-Gibbs distribution is\n  $P(\\sigma) = C \\me^{-E_\\sigma/kT}$ where $k$ is the \\emph{Boltzmann\n    constant} and $T$ is the thermodynamic temperature, but for the\n  example the temperature is a parameter not correlated to the\n  physical world, thus it is possible to ignore $k$.} and $C$ is a\nnormalization constant.\n\nThe average energy of the system is then:\n\\begin{eqnarray*}\n  \\bar{E} &=& \\frac{\\sum_\\sigma E_\\sigma P(\\sigma)}{\\sum_\\sigma\n    P(\\sigma)}\\\\\n  &=& \\frac{\\sum_\\sigma E_\\sigma \\me^{-E_\\sigma/T}}{\\sum_\\sigma \\me^{-E_\\sigma/T}}.\n\\end{eqnarray*}\nThe computation of the value of $\\bar{E}$ can be difficult with an\nhigh number of \nstates, but it is possible to create a \\ac{MCM} simulating the random\nfluctuation between the states such that the distribution given by\n\\cref{eq:distBoltz} is respected. Starting from an arbitrary initial\nconfiguration, after a certain number of \\emph{Monte Carlo trials},\nthe method converges to the equilibrium status $\\bar{E}$ and it\ncontinues\nto fluctuate around it. \\ac{SA} is a method of this kind.\n\n\\subsubsection{\\acf{SA} algorithm}\\index{\\acf{SA}!algorithm}\n\\ac{SA} operates on a system starting from a certain initial state\n$s_0$, then it executes a series of iterations where a\nneighbour of the state is evaluated and, with a certain distribution\nof probability, the system is moved in the new state or not.\n\nA possible algorithm for a \\ac{SA} method is \\cref{alg:sa}. $s_0$ is\nthe initial state; $temp$ is the function that assigns a\ntemperature based on the current iteration number such that for low\n$k$ the returned temperature is high and for high $k$ the returned temperature\nis low; $neighbour$ is the function that returns a random neighbour of\nthe current state; $uniform$ returns an uniformly-randomly chosen\nnumber in $[0,1]$; $P_a$ is the distribution of accepting probability\nthat depends on the energy of the current state, on the energy of the\nneighbour, and on the current temperature. In case of acceptance, the\nneighbour becomes the current state and the process continues.\n\n\\begin{algo}{\\acf{SA}}{alg:sa}\n  \\Function{anneal}{$s_0$}\n  \\State $s\\Ass s_0$\n  \\For{$k\\Ass 0,kMax$}\n  \\State $T\\Ass temp(\\frac{k}{kMax})$\n  \\State $sNew\\Ass neighbour(s)$\n  \\If{$uniform(0,1)<P_a(E(s), E(sNew), T)$}\n  \\State $s\\Ass sNew$\n  \\EndIf\n  \\EndFor\n  \\State\\Return $s$\n  \\EndFunction\n\\end{algo}\nThe relation with the statistical thermodynamic is that $P_a$ is chosen\nsuch that\n\\cref{eq:distBoltz} holds\\footnote{A similar distribution is enough.},\nmoreover $temp$ returns decreasing values of\ntemperature with the succession of iterations. This explains the\ncomparison with the metallurgy annealing.\n\nInitially $P_a$ was chosen such that\n\\begin{equation*}\n  P_a(E(s), E(sNew), T)=\n  \\begin{cases}\n    1,& \\text{if }E(sNew)<E(s)\\\\\n    \\me^{-(E(sNew)-E(s))/T},& \\text{otherwise}\n  \\end{cases}\n\\end{equation*}\nbut this isn't strictly necessary to develop a \\ac{SA} method.\n\n\\subsection{\\acf{LR}}\\label{sec:lagrangianRelaxation}\\index{\\acl{LR}}\nA general constrained discrete optimization problem can be expressed in\nthe form:\n\\begin{equation}\\label[problem]{eq:opt}\n\\begin{aligned}\n& \\underset{x}{\\text{minimize}}\n& & f(x) \\\\\n& \\text{subject to}\n& & g(x)=0\n\\end{aligned}\n\\end{equation}\nwhere $x\\in X$ is the state of the system in a discrete space $X$, $f(x)$\nis the function to\nminimize, and $g(x)=0$ is the constraint. The functions can also be\nin a multidimensional discrete space, in that case the $x$ is a vector\n$\\ve{x}=(x_1,\\dots,x_n)$ of variables.\n\nTo solve this class\nof problems a \\emph{Lagrange relaxation} method can be used\n\\cite{bertsekas}: it expands\nthe variable space $X$ by a \\emph{Lagrange multiplier} space\n$\\Lambda$, equal in dimension to the number of constraints - one in the\n\\cref{eq:opt}.\n\nThe \\emph{generalized discrete Lagrangian\n  function}, corresponding to the \\cref{eq:opt}, is:\n\\begin{equation}\\label{eq:lagrangianFun}\n  L_d(x,\\lambda)=f(x)+\\lambda H(g(x))\n\\end{equation}\nwhere $\\lambda$ is a variable in $\\Lambda$; if the dimension of\n$\\Lambda$ is more than one $\\lambda$, it must be transposed in\n~\\cref{eq:lagrangianFun}. $H(x)$ is a non negative function\nwith the property that $H(0)=0$ and aimed to transform g in a non\nnegative function. For instance, it can be  $H(g(x))=|g(x)|$ or\n$H(g(x))=g^2(x)$. \n\nUnder the previous assumptions, the set of \\emph{local minima}\nin \\cref{eq:opt} - that respect the constraints -  coincides\nwith the set of \\emph{discrete saddle point}\nin the augmented space. A point $(x^*,\\lambda^*)$ is a discrete saddle\npoint if:\n\\begin{equation*}\n  L_d(x^*,\\lambda)\\leq L_d(x^*,\\lambda^*)\\leq L_d(x,\\lambda^*)\n\\end{equation*}\nfor all $x\\in\\mathcal{N}(x^*)$ and for all $\\lambda\\in\\Lambda$, where\n$\\mathcal{N}(x^*)$ is the set of all $x^*$'s neighbours.\n\nTo solve the optimization \\cref{eq:opt} it is necessary to calculate,\namong the saddle points, the global minimum for $f$. We can use an\noptimization method, like \\ac{SA}, that descends in $X$ and ascends in\n$\\Lambda$.\n\n\\section{Intersections in space}\\label{sec:intersections}\\index{3D geometry}\nWe work in a spatial environment with polyhedral obstacles. Thus, in\norder to define admissible paths, first of all we need routines\nperforming the following three basic geometric tasks: \n\\begin{enumerate}\n\\item establish if a point is in or out\n  of a convex polyhedron;\n\\item \\label[task]{tsk:segmentTriangle}check if a segment intersects a triangle;\n\\item establish whether two triangles intersect.\n\\end{enumerate}\n\nIn the project we need to consider three kinds of collision detection\nmethods in 3-dimension euclidean space.\n\n\\subsection{Point inside convex polyhedron in 3D space}\\index{3D\n  geometry!point inside polyhedron}\nTo test if a point $\\ve{p}$ is inside a convex polyhedron $V$ with\nvertices $\\ve{v_1},\\ve{v_2},\\dots,\\ve{v_n}$, we use a method that rely\non convex hulls \\cite{deberg}\\cite{schneider}.\n\n\\begin{algo}{Check if point $\\ve{p}$ is inside convex polyhedron $V$}{alg:pointInPoly}\n  \\Function{isPointInPolyhedron}{$\\ve{p}$, $V$}\n  \\State $inside\\Ass\\True$\n  \\State $C\\Ass convexHullVertices([\\ve{p},\\ve{v_1},\\ve{v_2},\\dots,\\ve{v_n}])$\n  \\ForAll{$\\ve{c}\\in C$}\\label{ln:pointInPolyFor}\n  \\If{$c=p$}\n  \\State $inside\\Ass\\False$\n  \\State \\Break\n  \\EndIf\n  \\EndFor\n  \\State\\Return $inside$\n  \\EndFunction\n\\end{algo}\n\\Cref{alg:pointInPoly} performs the first task. It first\ncomputes the vertices of the convex hull of all\nthe vertices of $V$ plus the point $\\ve{p}$ and then checks if\n$\\ve{p}$ is one \nof them or not. If $\\ve{p}$ is on the convex hull that\nmeans that $\\ve{p}$ is external\\footnote{Or $\\ve{p}$ coincides with a\n  vertex of $V$.} to $V$ because we have extended the convex hull\nformed by the vertices of $V$. Otherwise this means that $\\ve{p}$ is\ninside $V$.\n\nThe cost of this algorithm is\n\\begin{equation*}\n  \\bigO(n\\log n)\n\\end{equation*}\nwhere $n$ is the number of vertices of $V$, because the cost to \nconstruct the convex hull is \\cite{deberg} $\\bigO(n\\log n)$, and\nthen we have another negligible term $\\bigO(n)$ for the cycle on\n\\cref{ln:pointInPolyFor}.\n\n\\subsection{Segment-triangle in 3D space}\\label{sec:intersectionST}\\index{3D\n  geometry!segment-triangle intersection}\\index{intersections!segment-triangle}\nWe need to deal with the intersection between a segment\n$S=\\overline{\\ve{a_2}\\ve{b_2}}$ and a triangle\n$T=\\triangle\\ve{a_1}\\ve{b_1}\\ve{c_1}$. $S$ and $T$ can be in one of\nthe following cases also summarized in \\cref{tab:intersectSegmentTriang}:\n\\begin{enumerate}[label=\\textbf{case \\arabic*}]\n\\item\\label[void]{en:ist:nc:ni} $S$ and $T$ do not intersect and the plane containing\n  $T$ is not in the sheaf of planes generated by the line\n  containing $S$;\n\\item\\label[void]{en:ist:c:ni} $S$ and $T$ do not intersect and the plane containing\n  $T$ is in the sheaf of planes generated by the line\n  containing $S$;\n\\item\\label[void]{en:ist:nc:i} $S$ and $T$ intersect only at one point and the plane containing\n  $T$ is not in the sheaf of planes generated by the line\n  containing $S$;\n\\item\\label[void]{en:ist:c:i} $S$ and $T$ intersect in one or infinite points and the plane\n  containing $T$ is in the sheaf of planes generated by the line\n  containing $S$.\n\\end{enumerate}\nThe discriminating factors among the cases are two: the presence of intersection\nand coplanarity.\n\\cref{tab:intersectSegmentTriang}.\n\\begin{table}\n  \\centering\n  \\begin{tabular}{l|cc}\n    &not coplanar&coplanar\\\\\n    \\hline\n    not intersect& \\cref{en:ist:nc:ni} & \\cref{en:ist:c:ni}\\\\\n    intersect& \\cref{en:ist:nc:i} & \\cref{en:ist:c:i}\\\\\n  \\end{tabular}\n  \\caption{Relations between $S$ and $T$}\n  \\label{tab:intersectSegmentTriang}\n\\end{table}\n\n\\begin{myfig}{Example intersection between a segment\n    $\\overline{\\ve{a_2}\\ve{b_2}}$ and a triangle $\\triangle \\ve{a_1}\\ve{b_1}\\ve{c_1}$.}{fig:segmentTriangleIntersection}\n  \\begin{tikzpicture}\n    \\coordinate (A1) at (0,0);\n    \\coordinate (B1) at (4,5);\n    \\coordinate (C1) at (8,1);\n\n    \\coordinate (cut1) at (barycentric cs:A1=0.8,B1=0.,C1=0.2);\n    \\coordinate (cut2) at (barycentric cs:A1=0.,B1=0.8,C1=0.2);\n\n    \\coordinate (A2) at (2,5);    \n    \\coordinate (B2) at (4.5,1.5);\n\n    \\coordinate (X) at (intersection of cut1--cut2 and B2--A2);\n\n    \\draw[poly] (A1) -- (C1) -- (B1) -- (A1);\n    \\draw[poly] (A2) -- (X);\n    \\draw[polyTract] (B2) -- (X);\n\n    \\foreach \\p in {A1,B1,C1,A2,B2}\n    \\filldraw[vertex] (\\p) circle (2pt);\n\n    \\filldraw[intersection] (X) circle (2pt);\n\n    \\node[below=0.5em] at (A1) {$\\ve{a_1}$};\n    \\node[above=0.5em] at (B1) {$\\ve{b_1}$};\n    \\node[below=0.5em] at (C1) {$\\ve{c_1}$};\n    \\node[above=0.5em] at (A2) {$\\ve{a_2}$};\n    \\node[right=0.5em] at (B2) {$\\ve{b_2}$};\n    \\node[right=0.2em] at (X) {$\\ve{x}$};\n  \\end{tikzpicture}\n\\end{myfig}\nIn \\cref{fig:segmentTriangleIntersection} a\n\\cref{en:ist:nc:i} situation is shown where there is intersection in\nonly one \npoint $\\ve{x}$. To establish whether $S$ and $T$ intersect, we need to\nsolve \nfour equations in four unknowns \\cite{schneider} where we look for a point\n$\\ve{x}$ being a convex linear\ncombination of $\\ve{a_2}$ and $\\ve{b_2}$ and at the same time a convex\nlinear combination of $\\ve{a_1}$,\n$\\ve{b_1}$ and $\\ve{c_1}$. In other words, when there is a collision,\nthen there is a solution for the unknowns\n$\\alpha$, $\\beta$, $\\gamma$, $\\delta$, $\\zeta$ of the system\n\\begin{equation}\\label[system]{eq:segmentTriangleIntersection1}\n  \\begin{cases}\n    \\alpha \\ve{a_2} + \\beta\\ve{b_2}=\\gamma\\ve{a_1}+\\delta\\ve{b_1}+\\zeta\\ve{c_1} \\\\\n    \\alpha + \\beta = 1\\\\\n    \\gamma + \\delta +\\zeta=1\n  \\end{cases}\n\\end{equation}\nwith the further conditions\n\\begin{equation}\\label[system]{eq:segmentTriangleIntersection1c}\n  \\begin{cases}\n    \\alpha \\ge 0\\\\\n    \\beta \\ge 0\\\\\n    \\gamma \\ge 0\\\\\n    \\delta \\ge 0\\\\\n    \\zeta \\ge 0.\n  \\end{cases}\n\\end{equation}\nNote that the first equation of\n\\cref{eq:segmentTriangleIntersection1} has vectorial coefficients\n$\\ve{a_2}$, $\\ve{b_2}$, $\\ve{a_1}$, $\\ve{b_1}$, $\\ve{c_1}$, thus we\nhave a system with five unknowns in five equations. If\n\\Cref{eq:segmentTriangleIntersection1} has just one solution then we are\nin \\cref{en:ist:nc:ni} when \\cref{eq:segmentTriangleIntersection1c} is\nfulfilled or in \\cref{en:ist:nc:i} when it is not. If it has\ninfinite\nsolutions then we are on \\cref{en:ist:c:ni} or \\cref{en:ist:c:i},\ndepending again on the fulfillment of\n\\cref{eq:segmentTriangleIntersection1c}. Finally, if it has no\nsolution, then $S$ or $T$ are degenerated.\n\nWe are interested in finding only \\cref{en:ist:nc:i} collisions because, for\nsimplicity, we consider the special case of a segment that lays on the\nsurface of a triangle as nonintersecting with it, and, for coherence, we\nrestrict the conditions of \\cref{eq:segmentTriangleIntersection1c} to\n\\begin{equation}\n  \\begin{cases}\n    \\alpha > 0\\\\\n    \\beta > 0\\\\\n    \\gamma > 0\\\\\n    \\delta > 0\\\\\n    \\zeta > 0.\n  \\end{cases}\n\\end{equation}\n\n\\Cref{eq:segmentTriangleIntersection1} can be simplified in the three\nequations \n\\begin{equation}\\label[system]{eq:segmentTriangleIntersection2}\n  \\begin{cases}\n    \\alpha \\ve{a_2} + (1-\\alpha)\\ve{b_2}=\\gamma\\ve{a_1}+\\delta\\ve{b_1}+(1-(\\gamma+\\delta))\\ve{c_1} \\\\\n  \\end{cases}\n\\end{equation}\nin the unknowns $\\alpha$, $\\gamma$ and $\\delta$ with the relative conditions\n\\begin{equation}\\label[system]{eq:segmentTriangleIntersection2c}\n  \\begin{cases}\n    \\alpha > 0\\\\\n    \\alpha < 1\\\\\n    \\gamma > 0\\\\\n    \\delta > 0\\\\\n    \\gamma+\\delta<1.\n  \\end{cases}\n\\end{equation}\n\n\\begin{algo}{Find intersection between segment $S$ and triangle $T$}{alg:intersectSegmentTriangle}\n  \\Function{intersect}{$S, T$}\n  \\State $intersect\\Ass\\False$\n  \\State $coordinates\\Ass\\emptyset$\n  \\If{$(\\alpha,\\gamma,\\delta)\\Ass\n    solve($\\cref{eq:segmentTriangleIntersection2}$)$}\\label{ln:intersectSegmentTriangleIf}\n  \\If{$satisfy($\\cref{eq:segmentTriangleIntersection2c}$)$}\n  \\State $intersect\\Ass\\True$\n  \\State $coordinates\\Ass(\\gamma, \\delta, 1-(\\gamma+\\delta))$\n  \\EndIf\n  \\EndIf\n  \\State\\Return $(intersect, coordinates)$\n  \\EndFunction\n\\end{algo}\nThus, \\cref{alg:intersectSegmentTriangle} which performs\n\\cref{tsk:segmentTriangle} \nessentially consists in solving\n\\cref{eq:segmentTriangleIntersection2} with the parameters $\\ve{a_2}$,\n$\\ve{b_2}$, $\\ve{a_1}$, $\\ve{b_1}$ and $\\ve{c_1}$ from $S$ and $T$;\nand then in checking if the solution is admissible. The condition of\n\\cref{ln:intersectSegmentTriangleIf} is $\\True$ if\n\\cref{eq:segmentTriangleIntersection2} has solution and if that\nis unique.\n\nWe also have the positive secondary effect that from the solution\n$(\\alpha,\\gamma,\\delta)$ of \\cref{eq:segmentTriangleIntersection2} we\ncan extract the barycentric coordinates $(\\gamma, \\delta,\n1-(\\gamma+\\delta))$ of the intersection point $\\ve{x}$ on the system of\nthe vertices $\\ve{a_1}$, $\\ve{b_1}$, $\\ve{c_1}$ of $T$.\n\n\\subsection{Triangle-triangle in 3D space}\\label{sec:intersectionsTriangleTriangle}\\index{3D\n  geometry!triangle-triangle intersection}\\index{intersections!triangle-triangle}\nWe are interested in detecting collisions between two triangles\n$T_1=\\triangle \\ve{a_1}\\ve{b_1}\\ve{c_1}$ and $T_2=\\triangle\\ve{a_2}\\ve{b_2}\\ve{c_2}$ in 3-dimensional\nspace. First of all consider the coplanarity relation between the two\ntriangles, we have the cases:\n\\begin{enumerate}[label=\\textbf{case \\arabic*}]\n\\item\\label[void]{en:itt:c} $T_1$ and $T_2$ are contained by the same plane;\n\\item\\label[void]{en:itt:nc} $T_1$ and $T_2$ are contained by different planes.\n\\end{enumerate}\nTo simplify the problem we decide - similarly to the case of\nintersection between segment and triangle - that when we are on \\cref{en:itt:c}\nwe consider $T_1$ and $T_2$ not intersecting in any case, even if from a\ngeometrical point of view they share points. After this premise we can\nassert that the possible relation between $T_1$ and $T_2$ can be\nexclusively one\nof the following types \\cite{schneider}:\n\\begin{enumerate}[label=\\textbf{type \\arabic*}, start=0]\n\\item\\label[void]{en:itt:i0} $T_1$ and $T_2$ do not intersect;\n\\item\\label[void]{en:itt:i1} two edges of $T_1$ intersect the plane\n  section delimited by $T_2$, or vice versa;\n\\item\\label[void]{en:itt:i2} one edge of $T_1$ intersects the plane\n  section delimited by $T_2$ and one edge of $T_2$ intersects the\n  plane section delimited by $T_1$.\n\\end{enumerate}\n\n\\begin{myfig}{Example of \\cref{en:itt:i1} intersection between a triangle $T_1=\\triangle \\ve{a_1}\\ve{b_1}\\ve{c_1}$\n    and another triangle $T_2=\\triangle \\ve{a_2}\\ve{b_2}\\ve{c_2}$.}{fig:trianglesIntersection1}\n  \\begin{tikzpicture}\n    \\coordinate (A1) at (0,0);\n    \\coordinate (B1) at (4,5);\n    \\coordinate (C1) at (8,1);\n\n    \\coordinate (cut1) at (barycentric cs:A1=0.8,B1=0.,C1=0.2);\n    \\coordinate (cut2) at (barycentric cs:A1=0.,B1=0.8,C1=0.2);\n\n    \\coordinate (A2) at (0,3);\n    \\coordinate (B2) at (2,5);    \n    \\coordinate (C2) at (4.5,1.5);\n\n    \\coordinate (Xs1) at (intersection of A1--B1 and C2--A2);\n    \\coordinate (Xs2) at (intersection of A1--B1 and C2--B2);\n    \\coordinate (X1) at (intersection of cut1--cut2 and C2--A2);\n    \\coordinate (X2) at (intersection of cut1--cut2 and C2--B2);\n\n    \\draw[poly] (Xs1) -- (A1) -- (C1) -- (B1) -- (Xs2);\n    \\draw[polyTract] (Xs1) -- (Xs2);\n    \\draw[poly] (X1) -- (A2) -- (B2) -- (X2);\n    \\draw[polyTract] (X1) -- (C2) -- (X2);\n    \\draw[cutting] (X1) -- (X2);\n\n    \\foreach \\p in {A1,B1,C1,A2,B2,C2}\n    \\filldraw[vertex] (\\p) circle (2pt);\n\n    \\filldraw[intersection] (X1) circle (2pt);\n    \\filldraw[intersection] (X2) circle (2pt);\n\n    \\node[below=0.5em] at (A1) {$\\ve{a_1}$};\n    \\node[above=0.5em] at (B1) {$\\ve{b_1}$};\n    \\node[below=0.5em] at (C1) {$\\ve{c_1}$};\n    \\node[left=0.5em] at (A2) {$\\ve{a_2}$};\n    \\node[above=0.5em] at (B2) {$\\ve{b_2}$};\n    \\node[right=0.5em] at (C2) {$\\ve{c_2}$};\n    \\node[below=0.2em] at (X1) {$\\ve{x_1}$};\n    \\node[right=0.2em] at (X2) {$\\ve{x_2}$};\n  \\end{tikzpicture}\n\\end{myfig}\n\\begin{myfig}{Example of \\cref{en:itt:i2} intersection between a triangle $T_1=\\triangle \\ve{a_1}\\ve{b_1}\\ve{c_1}$\n    and another triangle $T_2=\\triangle \\ve{a_2}\\ve{b_2}\\ve{c_2}$.}{fig:trianglesIntersection2}\n  \\begin{tikzpicture}\n    \\coordinate (A1) at (0,0);\n    \\coordinate (B1) at (4,5);\n    \\coordinate (C1) at (8,1);\n\n    \\coordinate (cut) at (barycentric cs:A1=0.8,B1=0.,C1=0.2);\n    \\coordinate (X2) at (barycentric cs:A1=0.,B1=0.8,C1=0.2);\n\n    \\coordinate (A2) at (0,6);\n    \\coordinate (B2) at (8,7);    \n    \\coordinate (C2) at (4.5,1.5);\n\n    \\coordinate (Xs1) at (intersection of A1--B1 and C2--A2);\n    \\coordinate (Xs2) at (intersection of C1--B1 and C2--B2);\n    \\coordinate (X1) at (intersection of cut--X2 and C2--A2);\n\n    \\draw[poly] (Xs1) -- (A1) -- (C1) -- (X2);\n    \\draw[polyTract] (Xs1) -- (B1) -- (X2);\n    \\draw[poly] (X1) -- (A2) -- (B2) -- (Xs2);\n    \\draw[polyTract] (X1) -- (C2) -- (Xs2);\n    \\draw[cutting] (X1) -- (X2);\n\n    \\foreach \\p in {A1,B1,C1,A2,B2,C2}\n    \\filldraw[vertex] (\\p) circle (2pt);\n\n    \\filldraw[intersection] (X1) circle (2pt);\n    \\filldraw[intersection] (X2) circle (2pt);\n\n    \\node[below=0.5em] at (A1) {$\\ve{a_1}$};\n    \\node[above=0.5em] at (B1) {$\\ve{b_1}$};\n    \\node[below=0.5em] at (C1) {$\\ve{c_1}$};\n    \\node[left=0.5em] at (A2) {$\\ve{a_2}$};\n    \\node[above=0.5em] at (B2) {$\\ve{b_2}$};\n    \\node[right=0.5em] at (C2) {$\\ve{c_2}$};\n    \\node[below=0.2em] at (X1) {$\\ve{x_1}$};\n    \\node[right=0.2em] at (X2) {$\\ve{x_2}$};\n  \\end{tikzpicture}\n\\end{myfig}\n\\begin{algo}{Find intersection between triangle $T_1$ and triangle $T_2$}{alg:intersectTriangles}\n  \\Function{intersect}{$T_1=(\\ve{a_1},\\ve{b_1},\\ve{c_1}),\\ T_2=(\\ve{a_2},\\ve{b_2},\\ve{c_2})$}\n  \\ForAll{$S\\in \\{\\overline{\\ve{a_1}\\ve{b_1}},\\ \\overline{\\ve{b_1}\\ve{c_1}},\\ \\overline{\\ve{c_1}\\ve{a_1}}\\}$}\n  \\If{$intersect(S,T_2)$}\\label{ln:intersectTriangles1}\n  \\State\\Return $\\True$\n  \\EndIf\n  \\EndFor\n  \\ForAll{$S\\in \\{\\overline{\\ve{a_2}\\ve{b_2}},\\ \\overline{\\ve{b_2}\\ve{c_2}},\\ \\overline{\\ve{c_2}\\ve{a_2}}\\}$}\n  \\If{$intersect(S,T_1)$}\\label{ln:intersectTriangles2}\n  \\State\\Return $\\True$\n  \\EndIf\n  \\EndFor\n  \\State\\Return $\\False$\n  \\EndFunction\n\\end{algo}\nOn \\cref{fig:trianglesIntersection1} and\n\\cref{fig:trianglesIntersection2} we can see two examples of\n\\cref{en:itt:i1} and \\cref{en:itt:i2}, respectively. To establish\nif $T_1$ and $T_2$\nintersect we need to check if every edge of $T_1$ intersects $T_2$\nand if every edge of $T_2$ intersects $T_1$. If we find at least one\nedge that intersects with one triangle, then $T_1$ and $T_2$\nintersect. \\Cref{alg:intersectTriangles} executes such check, the function\n$intersect$ on \\cref{ln:intersectTriangles1} and\n\\cref{ln:intersectTriangles2} is the intersection check between a segment\nand a triangle done by \\cref{alg:intersectSegmentTriangle}.\n\n\\end{document}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../dissertation\"\n%%% End:\n", "meta": {"hexsha": "8731ef3aca36740d5f42e1f25425746cc916b0a0", "size": 47407, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/prerequisites.tex", "max_stars_repo_name": "trianam/dissertation", "max_stars_repo_head_hexsha": "fb94ad42341d2277e775233036ded0e36e787e8b", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-07-27T09:17:12.000Z", "max_stars_repo_stars_event_max_datetime": "2016-07-27T09:17:12.000Z", "max_issues_repo_path": "chapters/prerequisites.tex", "max_issues_repo_name": "trianam/dissertation", "max_issues_repo_head_hexsha": "fb94ad42341d2277e775233036ded0e36e787e8b", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/prerequisites.tex", "max_forks_repo_name": "trianam/dissertation", "max_forks_repo_head_hexsha": "fb94ad42341d2277e775233036ded0e36e787e8b", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.9385004212, "max_line_length": 282, "alphanum_fraction": 0.6944965933, "num_tokens": 16622, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430604060731, "lm_q2_score": 0.8723473862936942, "lm_q1q2_score": 0.72504547638138}}
{"text": "\\lesson{4}{Oct 18 2021 Mon (10:55:28)}{Graphing Quadratics}{Unit 2}\n\n\\subsubsection*{Parts of a Parabola}\n\nParabolas consist of a:\n\n\\begin{itemize}\n    \\item Vertex\n    \\item Axis of Symmetry\n    \\item Domain\n    \\item Range\n    \\item X-Y Intercepts (Sometimes though)\n\\end{itemize}\n\n\\paragraph{Vertex} Here is how you find the vertex of a parabola:\n\n\\begin{itemize}\n    \\item \\bf{Step One: $x$-Coordinate} Set the expression inside the parentheses equal to $0$ and solve for the value of $x$\n    \\item \\bf{Step Two: $y$-Coordinate} Substitute the value of $x$ from step one into the original equation and solve for $y$\n\\end{itemize}\n\nLet's try an example:\n\n\\begin{example}[Given the equation $f(x) = -2(x - 5)^2 + 8$, find the $(x,y)$ coordinate of the vertex]\n    \\begin{align}\n        f(x) &= -2(x - 5)^2 + 8 \\\\\n             &= -2([x - 5 = 0])^2 + 8\n             &= 5 - 5 = 0 \\\\\n             &= x = 5\n    \\end{align}\n    \n    Now, we're going to solve for the $y$ coordinate\n    \n    \\begin{align}\n        f(x) &= -2(5)(5 - 5)^2 + 8 \\\\\n             &= -2(5 - 5)^2 + 8 \\\\\n             &= -2(0)^2 + 8 \\\\\n             &= -2(0) + 8 \\\\\n             &= y = 8 \\\\\n    \\end{align}\n    \n    Now, we know that the vertex of the parabola is $(5, 8)$.\n\\end{example}\n\n\\newpage\n\n\\subsubsection*{Elements of the Parabola}\n\n\\begin{marginfigure}\n    \\centering\n    \\incfig{parabola}\n    \\sidecaption{Here is an example of what a parabola looks like.}\n    \\label{fig:parabola}\n\\end{marginfigure}\n\n\\paragraph{Line of Symmetry} The \\bf{axis of symmetry} is in the line\nthat divides the parabola into two equal parts where each part is a\nmirror reflection of the other.\n\nAs you can see, the axis of symmetry is along the line $x = -3$.\n\nTo find the equation of the axis of symmetry algebraically, set the expression inside the parentheses equal to $0$ and solve for $x$.\n\n\\paragraph{Domain and Range} Any number can be substituted for the variable $x$ to produce a unique $y$ value. Therefore, the domain is \\bf{\"All Real Numbers}.\n\nThis parabola opens up since the value is positive ($+$). Because the parabola opens up, the vertex represents the minimum point on the graph.\nAll of the $y$ values on the parabola must be above the minimum $y-coordinate$ of $-1$, which makes the range of the parabola this:\n\n\\begin{align}\n    y \\geq -1\n\\end{align}\n\n\\paragraph{Intercepts} Substituting $0$ for $x$ and solving for $y$ will result in the $y-intercept$:\n\n\\begin{align}\n    f(g) &= (x + 3)^2 - 1 \\\\\n         &= (0 + 3)^2 - 1 \\\\\n         &= (3)^2 - 1 \\\\\n         &= 9 - 1 \\\\\n         &= 8\n\\end{align}\n\nThere you go, you have your $y-intercept$. To determine the $x-intercept$, you just plug in the $y-intercept$:\n\n\\begin{align}\n    f(9) &= (9 + 3)^2 - 1 \\\\\n         &= (3)^2 - 1 \\\\\n         &= 9 - 1 \\\\\n         &= 8\n\\end{align}\n\n\\subsubsection*{Different Quadratic Equation forms}\n\nWhile identifying the:\n\n\\begin{enumerate}\n    \\item Vertex\n    \\item Axis of Symmetry\n    \\item Domain\n    \\item Range\n    \\item Intercepts\n\\end{enumerate}\n\nis most easily done using the vertex form of a quadratic equation, most of the time, quadratic equations are written in standard form.\n\nHere is the standard form of a quadratic equation:\n\n\\begin{align}\n    f(x) = ax^2 + bx + c\n\\end{align}\n\nNow, we can move that into vertex form, here is an example:\n\n\\begin{align}\n    f(x) &= -2x(x - 5)^2 + 8 \\\\\n         &= -2x(x - 5)(x - 5) + 8 \\\\\n         &= -2x(x^2 - 5x - 5x + 25) + 8 \\\\\n         &= -2x(x^2 - 10x + 25) + 8 \\\\\n         &= -2x^2 + 20x - 50 + 8 \\\\\n         &= -2x^2 + 20x - 42 \\\\\n\\end{align}\n\nBut, it's not that easy to identify the vertex and axis, so let's us \\bf{Axis of Symmetry} equation, which is:\n\n\\begin{align}\n    f(x) = -\\frac{b}{2a}\n\\end{align}\n\nNow, let's try to convert an equation in the standard form to this form:\n\n\\begin{align}\n    f(x) &= -2x^2 + 20x - 42 \\\\\n         &= -\\frac{20}{2(-2)} \\\\\n         &= -\\frac{20}{-4} \\\\\n         &= x = 5\n\\end{align}\n\nwhich gives you the axis of symmetry for the $x-axis$. Now, just substitute $5$ for $x$ to find the $y-coordinate$:\n\n\\begin{align}\n    f(x) &= -2x^2 + 20x - 42 \\\\\n         &= -2(5)^2 + 20(5) - 42 \\\\\n         &= -2(25) + 100 - 42 \\\\\n         &= -50 + 100 - 42 \\\\\n         &= 8 \\\\\n         &= (5, 8)\n\\end{align}\n\n\\subsubsection*{Working our way up}\n\n\\begin{marginfigure}\n    \\centering\n    \\incfig{parabola}\n    \\sidecaption{Here is an example of what a parabola looks like.}\n    \\label{fig:parabola}\n\\end{marginfigure}\n\nNow, I have discussed how you can find key features within the equation, but let's try and make our equation from the graph.\nTaking the image of the parabola, let's try and see if we can create the equation from the graph:\n\nLet's take the vertex $(-3, -1)$ and a random point, $(0, 8)$. Here is how it works:\n\n\\begin{align}\n    f(x) &= a(x - h)^2 + k \\\\\n         &= a(x + 3)^2 - 1 \\\\\n         &= 8 = a(0 + 3)^2 - 1 \\\\\n    8 &= a(0 + 3)^2 - 1 \\\\\n       &= a(3)^2 - 1 \\\\\n       &= 9a - 1 \\\\\n       &= 9 = 9a \\\\\n       &= \\frac{9}{9} = \\frac{9}{9a} \\\\\n       &= 1\n\\end{align}\n\nNow, let's put it all together:\n\n\\begin{align}\n    a &= 1, h = -3, k = -1 \\\\\n    f(x) &= a(x - h)^2 + k \\\\\n         &= (x + 3)^2 - 1 \\\\\n         &= (x + 3)(x + 3) - 1 \\\\\n         &= (x^2 + 3x + 3x + 9) - 1 \\\\\n         &= (x^2 + 6x + 9) - 1 \\\\\n         &= x^2 + 6x + 8 \\\\\n\\end{align}\n\n\\newpage\n", "meta": {"hexsha": "9f537e83f70046367a9c58fd4e9e4701ce721823", "size": 5328, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-2/lesson-4.tex", "max_stars_repo_name": "SingularisArt/notes", "max_stars_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-08-31T12:45:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T07:29:05.000Z", "max_issues_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-2/lesson-4.tex", "max_issues_repo_name": "SingularisArt/notes", "max_issues_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-2/lesson-4.tex", "max_forks_repo_name": "SingularisArt/notes", "max_forks_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.3404255319, "max_line_length": 159, "alphanum_fraction": 0.568506006, "num_tokens": 1793, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430436757313, "lm_q2_score": 0.8723473829749844, "lm_q1q2_score": 0.7250454590283874}}
{"text": "%!TEX root = ../main.tex\n\\section{Background}\n\\label{sec:background}\n\nIn the following, we explain the fundamental concepts underlying the remaining sections. These concepts include totality in general and productivity in particular, coinductive data, and copatterns.\n\n\\subsection{Why Do We Care About Totality?}\nIn a partial (i.e. non-total) programming setting, a well-typed program results in a value \\emph{if} it terminates \\emph{and} it does not result in a run-time error, both of which are possible (even for well-typed programs). Non-termination and run-time errors can be eliminated by making a program total.\n\n\\emph{Totality} means that for any input, the program always produces an output\\,\\citep{Turner04totalfunctional}. Consequently, any total program must be defined for all possible cases of its input. Otherwise, some input would exist for which no output would be defined. Stating that a program is total has different implications, depending on whether the output of a program is of inductive or coinductive type.\n\nIf a program results in an instance of an inductive type, it is total if it is \\emph{terminating}. Since the output is finite by definition, a program is terminating when it has constructed all of its output. Termination is often ensured by showing that all recursive invocations of the program happens on structurally smaller input.\n\nIn the case where a program results in a coinductive instance, it is total if it is \\emph{productive}. Because coinductive data is potentially infinite, the program cannot be expected to produce all of its output in finite time. Instead, a productive program must continuously be able to produce a finite prefix of its output in finite time. Hence, a total program returning something of coinductive type is said to be productive, since it must be able to produce an output on every invocation.\n\nMaking programs total has multiple benefits. First of all, it gives us a guarantee that an output is always produced. Secondly, due to the Curry-Howard correspondence, total programs can be used as proofs, which enables us to establish strong guarantees about program correctness. In Idris, partial functions are not evaluated by the type checker and thus can never consitute part of a proof. The reason for this is not only that the type checker may loop forever, but also because generally recursive functions give rise to an inconsistent logic. A common argument against total programming is that it is impossible to create programs which are not meant to terminate, such as servers and operating systems. But \\emph{totality} should not be mistaken for \\emph{termination}. It is true that servers and operating systems are not meant to terminate, but they can be \\emph{productive}, a notion which is well-suited for systems that need to be responsive. In short, we care about totality because it provides us with a guarantee that our programs always produce an output, which in addition to eliminating a whole class of errors ultimately enables us construct provably correct programs.\n\n% Non-termination is a possibility\n% Not used in proof --- not expanded by type checker\n% We can write total servers and operating systems!\n% termination vs. productivity\n\n\\subsection{Codata}\n\\label{sec:codata}\nCoinductive data, or codata (these terms will be used interchangeably), is data defined in terms of \\emph{observations}\\,\\citep{Jacobs97atutorial}. Since its inception, codata has proven to be a useful tool to describe dynamic structures involving some notion of state, such as transition systems and automata\\,\\citep{Jacobs97atutorial}, and informally we can say that it allows us to model infinite structures. The idea of infinity arises from the fact that we can define codata which can be observed in infinitely many different states.\n\n\\subsubsection{The Duality Between Inductive and Coinductive Data} There is a close correlation between inductively defined data and coinductively defined data. In the field of category theory, this correlation is often defined as the duality between initial algebra and final coalgebra\\,\\citep{Jacobs97atutorial}. For those less acquainted with category theory (which includes the authors), this duality can be described as the distinction between \\emph{construction} and \\emph{observation}. Inductive data is constructed by the application of a finite set of constructors, whereas coinductive data can be observed in a given state by a finite set of observations. The distinction is perhaps most easily made clear with an example. Consider a the list data structure in Figure~\\ref{fig:inductive_list}, defined in Idris-like syntax:\n\n\\begin{figure}\n\\begin{alltt}\ndata List : Type -> Type where\n  Nil  : List a \n  (::) : a  -> List a -> List a\n\\end{alltt}\n\\caption{An inductive definition of a list structure.}\n\\label{fig:inductive_list}\n\\end{figure}\n\nAn instance of \\texttt{List} can be constructed using the two constructors, \\texttt{Nil} and \\texttt{(::)} (cons). Notably, the only way to construct a \\texttt{List} in finite time is to apply the \\texttt{Nil} constructor at some point. Hence, a \\texttt{List} instance is clearly defined by construction, so \\texttt{List} is an inductive definition. Could we define lists coinductively also? A coinductive definition requires that we define what can be observed about a list. So, what can we say about list? The definition of \\texttt{List} provides some intuition. At any point in time, we can either observe no elements (\\texttt{Nil}) or we can observe an element and the rest of the list (\\texttt{(::)}). We cannot, however, straightforwardly implement a coinductive list with two such observations, since the observations in a coinductive definition must specify those observations which can be made at any \\emph{one} point in time. Surely, we can never at the same time observe no elements and one element (and the rest of the list). What we can say is that if we blindly observe any position in the list, we will either find nothing, or we will find an element and a pointer to the rest of the list. Let us try to formalize this notion with the definition of \\texttt{CoList} in Figure~\\ref{fig:CoList}.\n\n\\begin{figure}\n\\begin{alltt}\ncodata CoList : Type -> Type where\n  Elem : CoList a -> Either () (a, CoList a)\n\\end{alltt}\n\\caption{A coinductive definition of a list structure.}\n\\label{fig:CoList}\n\\end{figure}\n\n% cons : a -> List a -> List a\n% Elem (cons a l) = Just (a, l)\n\n% append : List a -> List a -> List a\n% Elem (append xs ys) = case Elem xs of\n%                         Just (a, l) => Just (a, (append l ys))\n%                         Nothing => Elem ys \n\nNotice how the types (and names) have changed. Since we have to define the object of our observations, the \\texttt{Elem} observation must take a \\texttt{CoList a} as parameter. Also, because we are not \\emph{constructing} a \\texttt{CoList}, the result of \\texttt{Elem} does not have to be \\texttt{CoList~a}. Instead it is an \\texttt{Either} type, which denotes that whenever we try to observe an instance of \\texttt{CoList}, we can either get nothing if the list is empty, represented here by a unit value, or \\texttt{(x, xs)}, where \\texttt{x} is an element and \\texttt{xs} is the rest of the list. \n\nUnderstanding the duality between these two definitions requires a bit of desugaring. We can desugar the \\texttt{Either} type from the second example into a sum type, \\texttt{() + (a, CoList a)}. Furthermore, we can desugar the two constructors from the first example into one constructor. Since \\texttt{Nil} has no parameters, its input can be described by a unit value. The \\texttt{(::)} constructor has two parameters, an element and a list. The constructors of \\texttt{List} can therefore be reduced to one constructor with a sum type \\texttt{() + (a, List a)} as parameter, describing the input of both \\texttt{Nil} and \\texttt{(::)}. The desugared types of the two definitions are shown side by side in Figure~\\ref{fig:List_CoList_duality}.\n\n\\begin{figure}\n\\begin{alltt}\nList   : () + (a, List a)   ->   List a\nCoList : CoList a           ->   () + (a, CoList a)\n\\end{alltt}\n\\caption{The desugared types of \\texttt{List} and \\texttt{CoList}.}\n\\label{fig:List_CoList_duality}\n\\end{figure}\n\nWhen juxtaposing these types, it becomes apparent that the ways we can construct an inductively defined list is dual to what we can observe about a coinductively defined list. This duality is a general property which exists between inductive and coinductive data: Constructors tell us how data can be built, observations tell us what we can observe about our data.\n\n% \\subsubsection{Bisimulation}\n% Since coinductive data has no inherent structure, it does not always make sense to talk about equality between two instances of a coinductive type. Instead, it may be the case that two instances of codata give rise to the same sequence of observations, such that they cannot be told apart by the results of our observations. When instances of codata are observationally indistinguishable in this way, we say they are \\emph{bisimilar}, as one instance simulates the behaviour of the other. Further details on this phenomenon can be found in the tutorial by Jacobs and Rutten\\,\\citep{Jacobs97atutorial}.\n\n\\subsection{The Current Status of Codata in Idris}\n\\label{sec:stateinidris}\nCoinductive data types already exist in Idris, although they are not defined by observations. Instead, they are defined by constructors. A coinductive definition by constructors as currently implemented in Idris is shown in Figure~\\ref{fig:stream_current} for an infinite list, also called a \\texttt{Stream}.\n\n\\begin{figure}\n\\begin{alltt}\ncodata Stream : Type -> Type where\n  (::) : a -> Stream a -> Stream a\n\\end{alltt}\n\\caption{A stream definition as it currently looks in Idris.}\n\\label{fig:stream_current}\n\\end{figure}\n\nAt first glance, the type of the \\texttt{(::)} constructor looks reasonable. Taking this type at face value, let us try to imagine how a \\texttt{Stream} of all the natural numbers could be built:\n\n\\begin{alltt}\n(0 :: (1 :: (2 :: (3 :: (4 :: (5 :: \\ldots))))))\n\\end{alltt}\n\nThis seems to be impossible. Building a \\texttt{Stream} requires a new \\texttt{Stream}, which again requires a new \\texttt{Stream}, leading to an infinite chain of \\texttt{Stream}s. Is \\texttt{Stream} inhabited at all? Fortunately, the answer is yes, the reason being that the syntax hides an important detail. Internally, the \\texttt{(::)} constructor only requires a lazily evaluated \\texttt{Stream} as its second argument. Instead of giving an actual stream, we can provide a promise that the rest of the \\texttt{Stream} can be generated later. This is captured by the \\texttt{Inf} type operator in Figure \\ref{fig:stream_current_Inf_and_natsFrom}, which is applied automatically by elaborator. The corecursive call in \\texttt{nats} will be lazily evaluated, and therefore not cause an infinite computation.\n\n\\begin{figure}\n\\begin{alltt}\ncodata Stream : Type -> Type where\n  (::) : a -> Inf (Stream a) -> Stream a\n\nnatsFrom : Nat -> Stream Nat\nnatsFrom n = n :: Delay (natsFrom (S n))\n\\end{alltt}\n\\caption{A stream definition as it currently looks in Idris with the implicit \\texttt{Inf} operator made explicit. This allows us to define an infinite sequence of natural numbers as shown with \\texttt{natsFrom}. The \\texttt{Delay} constructor for lazily evaluated defintions is applied on the recursive call to \\texttt{natsFrom}.}\n\\label{fig:stream_current_Inf_and_natsFrom}\n\\end{figure}\n\nThis scheme of lazily evaluating coinductive arguments is applied automatically to any constructor in a \\texttt{codata} declaration during elaboration, and \\texttt{Inf} is therefore optional (for mixed inductive-coinductive definitions) in the concrete Idris syntax. As such, codata in Idris is currently modeled as lazily evaluated data where observations can be made by pattern matching.\n\nTo ensure the productivity of functions returning codata, Idris has a productivity checker which analyzes a program according to the \\emph{guardedness} principle\\,\\citep{Coquand94,Gimenez95}: Any corecursive call must appear directly under a constructor. In the \\texttt{natsFrom} example, the corecursive call appears directly under the \\texttt{(::)} constructor. If we try to define the a stream of the natural numbers without a \\texttt{Nat} argument (shown in Figure \\ref{fig:nats}), however, the productivity checker rejects the program (as of Idris version \\texttt{0.9.12-git:d9a96d1}, at least), complaining that \\texttt{nats} is possibly not total. In this case the corecursive call does not appear directly under \\texttt{(::)}, but is wrapped in a call to \\texttt{map}. Therefore, even though \\texttt{nats} is in fact productive, it is not productive according to the guardedness principle.\n\n\\begin{figure}\n\\begin{alltt}\nnats : Stream Nat\nnats = Z :: map S nats\n\\end{alltt}\n\\caption{A stream of all the natural numbers which is productive, but not according to the guardedness principle.}\n\\label{fig:nats}\n\\end{figure}\n\nIn its original formulation (which is also the one implemented for Idris), the guardedness principle is quite simple, but also rather conservative. The productivity checking algorithm we present in Section~\\ref{sec:productivity} accepts more functions as being productive, but is arguably not as simple.\n\n\\subsection{Copatterns}\n\\label{sec:copatterns}\n\\emph{Destructor copatterns}, or simply \\emph{copatterns}\\,\\citep{Abel13Copatterns}, provide a way of defining functions on coinductive data in terms of observations. Like pattern matching allows us to define functions on inductive data by analyzing the structure of the input, copatterns enable us to make experiments on functions with a result of coinductive type. Building on the intuition presented in Section~\\ref{sec:codata}, we begin by defining an infinite list by observations, \\texttt{Stream}, in the same vein as \\texttt{CoList}:\n\n\\begin{figure}\n\\begin{alltt}\ncodata Stream : Type -> Type where\n  head : Stream a -> a\n  tail : Stream a -> Stream a \n\\end{alltt}\n\\caption{An infinite list defined by observations.}\n\\label{fig:stream}\n\\end{figure}\n\nThe syntax for \\texttt{codata} definitions presented in Figure~\\ref{fig:stream} is quite similar to the existing syntax shown in Figure~\\ref{fig:stream_current}. The major difference is that we no longer define constructors, but observations. On a \\texttt{Stream}, two observations can be made: \\texttt{head} and \\texttt{tail}. The former provides us with the first element of the stream, while the latter gives us with the rest of the infinite stream, upon which another element can be observed with \\texttt{head}. With respect to the stream definition given in Section~\\ref{sec:stateinidris}, the \\texttt{head} observation from Figure~\\ref{fig:stream} corresponds to the first argument of the \\texttt{(::)} constructor, and \\texttt{tail} corresponds to the second argument. The \\texttt{Stream} defined by observations can be used to define the \\texttt{nats} function from Figure~\\ref{fig:nats} using copatterns, as shown in Figure~\\ref{fig:nats_copatterns}.\n\n\\begin{figure}\n\\begin{alltt}\nnats : Stream Nat\nhead nats = Z\ntail nats = map S nats\n\\end{alltt}\n\\caption{A definition of \\texttt{nats} using copatterns.}\n\\label{fig:nats_copatterns}\n\\end{figure}\n\nBecause the result type of \\texttt{nats} is coinductive, we can use copatterns to define the outcomes of our observations. The intuition is that the first element of \\texttt{nats} is zero (\\texttt{Z}), and the rest of the natural numbers are all the natural numbers incremented by one (\\texttt{map S nats}). Initially, the \\texttt{head} observation will therefore return \\texttt{Z}. Making a \\texttt{tail} observation results in a new stream where all the elements of \\texttt{nats} are incremented by one (using the \\texttt{S} constructor for natural numbers). Consequently, the outcome of making a subsequent \\texttt{head} observation is \\texttt{S Z}. As we can increment a natural number infinitely many times, we can also make infinitely many \\texttt{tail} observations, where the result of a \\texttt{head} observation will be incremented for each \\texttt{tail} observation. \n\nSyntactically, projection happens on the outside of definitions when we use copatterns, as opposed to pattern matching, where projection on parameters happens inside of definitions. As an example, consider the definition of \\texttt{map} in Figure~\\ref{fig:map_copatterns}.\n\n\\begin{figure}\n\\begin{alltt}\nmap : (a -> b) -> Stream a -> Stream b\nhead (map f s) = f (head s)\ntail (map f s) = map f (tail s)\n\\end{alltt}\n\\caption{The \\texttt{map} function defined with copatterns.}\n\\label{fig:map_copatterns}\n\\end{figure}\n\nFor \\texttt{map}, it is clear that the observations are applied on the entire definition \\texttt{map f s}. Projections on the entire definition make sense because \\texttt{map f s} has the coinductive type \\texttt{Stream b}, and can therefore be the subject of observations. In this sense, copatterns can be said to be dual to pattern matching in the same way that coinductive data is dual to inductive data. With pattern matching, we can analyze how data has been constructed, and with copatterns we can define the outcome of observations. Where pattern matching is a way of processing input, copatterns provide the means for describing output. In continuation of this description, the behaviour of copatterns during evaluation becomes interesting, but we will defer this discussion to Section~\\ref{sec:implementing-copatterns}.\n\nIn general, copatterns are used whenever we define a function that results in something coinductive. Nevertheless, there are some cases where definitions do not benefit from the use of copatterns, even though their result is coinductive. Especially, this is the case for definitions that are terminating rather than productive. An elaboration on this will be provided in Section~\\ref{sec:copattern_in_idris_productivity_checker}.\n\n% Dual to pattern matching\n\n% Copatterns in Agda\n\n% Inductively defined data can be analyzed by defining functions on that data by traditional pattern matching, where a \\emph{pattern} is a (finite and valid) combination of constructor applications for the given data. In this respect, \n\n% \\begin{figure}\n% \\begin{alltt}\n% pow2 : Stream Nat\n% head pow2 = S Z\n% head (tail pow2) = S (S Z)\n% tail (tail pow2) = zipWith _+_ (tail pow2) (tail pow2)\n% \\end{alltt}\n% \\caption{A definition of an infinite stream of powers of 2 using copatterns.}\n% \\end{figure}\n\n% by defining functions on that data using traditional pattern \n\n% Inductively defined data can be analyzed by defining functions in terms of a set of \\textit{patterns}, where a pattern constitutes a recognizable structure in the data we are analyzing. \n\n\n\n\n% Because we know that the data has been constructed using a finite number of data constructors, the number of ways we can take that same data apart is also finite by definition. \n\n\n% Consider a standard list data structure, defined in Haskell-like syntax:\n\n% \\begin{alltt}\n% data List a = Nil \n%             | Cons a (List a)\n% \\end{alltt}\n\n% \\texttt{List a} consists of two data constructors, \\texttt{Nil} and \\texttt{Cons}. Because these two constructors constitute the only that we can construct a \\texttt{List a}, \n\n\\subsection{Existing Implementations of Copatterns}\nCopatterns already exist in other languages, for example in Agda\\,\\cite{Norell:thesis}. Here, definitions for coinductive types are quite interesting. A coinductive type is defined as a record type with a \\texttt{coinductive} flag, an example of which can be seen in Figure~\\ref{fig:agda_stream}. Observations are defined as fields of the record type.\n\n%Notice the implicit sizes. These are not strictly necessary, but are needed if the user wants productivity checking using sized types rather than guardedness. These different techniques for are discussed in Section~\\ref{sec:related_work}. \n\n\\begin{figure}\n\\begin{alltt}\nrecord Stream (A : Set) : Set where\n  coinductive\n  field\n    head : A\n    tail : Stream A\nopen Stream\n\\end{alltt}\n\\caption{Sized \\texttt{Stream} definition in Agda.}\n\\label{fig:agda_stream}\n\\end{figure}\n\nDefinitions with copatterns are almost identical to what has already been discussed. A simple example where sized types are not necessary for productivity checking is \\texttt{repeat} in Figure~\\ref{fig:agda_repeat}. This definition passes a simple guardedness check.\n\n\\begin{figure}\n\\begin{alltt}\nrepeat : \\{A : Set\\} -> A -> Stream A\nhead (repeat a) = a\ntail (repeat a) = repeat a \n\\end{alltt}\n\\caption{A corecursive \\texttt{repeat} function in Agda.}\n\\label{fig:agda_repeat}\n\\end{figure}\n\nIf we want to write more advanced corecursive functions in Agda, we have to use sized types to reason about productivity. Further discussion on these will be provided in Section~\\ref{sec:sized_types}.\n\n%Earlier we saw a definition of a stream of natural numbers. An Agda implementation of this is shown in Figure~\\ref{fig:agda_nats}. Since \\texttt{nats} does not pass the guardedness check, we have to help the productivity checker by using sized types.", "meta": {"hexsha": "f721da3cd70c1474fe4be00fdaf0d11d409fc0a2", "size": 21091, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/background.tex", "max_stars_repo_name": "tdidriksen/copatterns", "max_stars_repo_head_hexsha": "7e12781ad0174a5f57bf57f6f1077e134b6de9dc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-27T15:37:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-27T15:37:01.000Z", "max_issues_repo_path": "report/sections/background.tex", "max_issues_repo_name": "tdidriksen/copatterns", "max_issues_repo_head_hexsha": "7e12781ad0174a5f57bf57f6f1077e134b6de9dc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/sections/background.tex", "max_forks_repo_name": "tdidriksen/copatterns", "max_forks_repo_head_hexsha": "7e12781ad0174a5f57bf57f6f1077e134b6de9dc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 89.7489361702, "max_line_length": 1307, "alphanum_fraction": 0.7759707932, "num_tokens": 5197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594992, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7250454530229251}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\\usepackage[cache=false]{minted}\n\\usepackage{makecell}\n\\usepackage{amsmath}\n\n\\title{Recursion in Python}\n\\author{Guillaume Macneil}\n\n\\begin{document}\n\\maketitle\n\n\\begin{abstract}\nThis is the fifth lesson on the 'Introduction to Python' course. This course is loosely based around the 'MIT Introduction to Computer Science - Fall 2016' course. Our course is more focused towards the Python programming side of things.\n\\end{abstract}\n\n\\section{Introduction to Recursion}\nThere are two main ways to define recursion:\n\n\\begin{itemize}\n    \\item \\textbf{\\textit{Semantically}}, recursion is a programming technique where a function calls itself. This is a confusing concept for many, \"How can a piece of code tell the interpreter to run that very code, all while the code itself is running?\" This is a good question, and can be explained in many ways - my favourite of which using acronyms.\\medskip\n\n    In the book 'G{\\\"o}del, Escher, Bach: An Eternal Golden Braid', Douglas R. Hofstadter describes recursion using the acronym '\\textbf{GOD}' (not to be confused with the deity). Two of the characters in the book encounter a being called a Djinn and one of them asks what '\\textbf{GOD}' stands for. The Djinn replies that '\\textbf{GOD}' stands for '\\textbf{GOD} \\textbf{o}f \\textbf{D}jinn', which in turn stands for '\\textbf{GOD} \\textbf{o}f \\textbf{D}jinn \\textbf{o}f \\textbf{D}jinn', which in turn stands for '\\textbf{GOD} \\textbf{o}f \\textbf{D}jinn \\textbf{o}f \\textbf{D}jinn \\textbf{o}f \\textbf{D}jinn' and so on. Though the book discusses recursion in much greater detail, I feel that this describes recursion quite well, with '\\textbf{GOD}' being a function and '\\textbf{G}' being the code that recursively calls the '\\textbf{GOD}' function.\\footnote{This section on the book 'GEB' has become a bit of a tangent, so I will finish it by saying that 'GEB' is a very good book to read for anyone interested in Computer Science, Mathematics or to some degree Psychology. I will warn you though it is a \\textbf{substantial} book.}\n\n    \\item \\textbf{\\textit{Algorithmically}}, recursion is a way to design solutions to problems by the \\textit{divide-and-conquer} technique - a way of reducing a problem into simpler versions of itself which can, in turn be solved either individually or by reducing the problem again.\n\\end{itemize}\nIt is important to note that the '\\textbf{GOD}' acronym example isn't entirely representative of how recursion works in general programming. The acronym example is an example of what is called \\textit{infinite recursion}, meaning that the function will continue to call itself forever, with no end in sight. In programming, the goal is to avoid this because otherwise the program would never end. So, in programming the recursive function must have one or more \\textit{base cases} - reduced versions of the problem that are easily solvable.\n\n\\section{Recursion in Python}\nLet's start by considering multiplication. Multiplication is the act of adding '\\textit{a}' repeatedly to itself '\\textit{b}' times. There is a way a multiplication function can be written without recursion:\n\n\\begin{minted}{python}\ndef multiply(a, b):\n    output = 0\n\twhile b > 0:\n\t\toutput += a\n\t\tb -= 1\n\treturn output\n\nmultiply(3, 5)\n# Returns 15\n\\end{minted}\nNow there's nothing inherently wrong with this function, it's actually quite a neat solution (in my opinion), but there is a simpler way of doing it using recursion. Let's visualise what we are doing conceptually:\n\\[a\\times b=a_1+a_2+a_3+a_4+...+a_{b-3}+a_{b-2}+a_{b-1}+a_b \\]\nIf we think about it closely we could vastly simplify this by using some multiplication. \"But wait a minute! How can we use multiplication when we are defining the process of multiplication?\" By using recursion. Look at what the equation becomes:\n\\[a\\times b=a+a(b-1)\\]\nNow this seems much more manageable, so here is the multiplication function written recursively using Python:\n\n\\begin{minted}{python}\ndef multiply(a, b):\n\tif b == 1:\n\t\treturn a\n\telse:\n\t\treturn a + multiply(a, b-1)\n\nmultiply(3, 5)\n# Returns 15\n\\end{minted}\n\nNow this function is much less easy to understand than the last one. You can see that it takes \\textit{a} and \\textit{b} as arguments - the two numbers to multiply. You can also see that the first part of the if statement immediately returns the number \\textit{a} if \\textit{b} is equal to 1. This makes sense because any number multiplied by 1 is left unchanged. In the else block though, the function returns the number \\textit{a} added to a new instance of the function which takes \\textit{a} and \\textit{b-1} as arguments. If you look carefully, you can see that we have actually written out the simplified equation here. By this recursive process, you can also see that the function will keep calling itself until \\textit{b} is equal to 1. This is the \\textit{base case}. Once \\textit{b} is equal to 1, the function will just output the summation so far - which turns out to be the product of the two arguments. \\medskip\n\nNow after all that, you might be wondering: \"Why would I bother doing that? The first, non-recursive function is so much easier.\" This is a valid question which is made even more valid when you consider that recursion isn't even always more efficient than just simple iteration. Recursion is, however, generally more intuitive than iteration - even if it may not seem so currently. It is important to remember that recursion is just a tool in your programming toolbox, just because you can use recursion for a problem doesn't always make it worthwhile. \\medskip\n\nAnyway, here is a \\textit{factorial} implementation as a final example of recursion. \\textit{Factorial} is a mathematical operation that multiplies an integer \\textbf{n} by every integer before it, not including \\textbf{0}. Here it is in mathematical notation:\n\\[n!=n\\times(n-1)\\times(n-2)\\times(n-3)\\times(n-4)\\times...\\times1 \\]\nAs you can see, this is a very similar operation to the multiplication example, here is how it could be written in python:\n\\begin{minted}{python}\ndef fact(n):\n    if n == 1:\n        return 1\n    else:\n        return n*fact(n-1)\n\\end{minted}\n\\end{document}\n", "meta": {"hexsha": "c40b1c60b80cc091b25ba2344e85c1d8d64e4960", "size": 6223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/recursion.tex", "max_stars_repo_name": "MetallicSquid/intro-to-python", "max_stars_repo_head_hexsha": "7fe8eb1a2f024bca4fd7e3c364f3aa638d611150", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/recursion.tex", "max_issues_repo_name": "MetallicSquid/intro-to-python", "max_issues_repo_head_hexsha": "7fe8eb1a2f024bca4fd7e3c364f3aa638d611150", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/recursion.tex", "max_forks_repo_name": "MetallicSquid/intro-to-python", "max_forks_repo_head_hexsha": "7fe8eb1a2f024bca4fd7e3c364f3aa638d611150", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 81.8815789474, "max_line_length": 1132, "alphanum_fraction": 0.7629760566, "num_tokens": 1603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7250454511549466}}
{"text": "\\section{Numbers}\\label{sec:numbers}\n\nNumbers are perhaps the most ubiquitous concept in mathematics. Even among non-mathematicians, division by zero or \\( 0.999\\ldots = 1 \\) seem to be a common topic of discourse, either as a joke or a sincere misunderstanding.\n\nThe aforementioned topics were studied extensively by mathematicians and have simple justifications from the point of view of abstract mathematics:\n\\begin{itemize}\n  \\item We may want to somehow define division by zero in the \\hyperref[def:set_of_real_numbers]{set \\( \\BbbR \\) of real numbers}, however that would make it a \\hyperref[def:semiring/commutative_unital_ring]{commutative unital ring} rather than a \\hyperref[def:field]{field}, which, by \\fullref{thm:def:semiring/properties/cancellable_iff_not_zero_divisor}, would deprive us of the cancellative property of multiplication.\n\n  Our familiar arithmetic of real numbers heavily relies on the cancellative property, therefore we simply disallow division by zero.\n\n  \\item The set \\( \\BbbR \\) of real numbers is a uniform space and thus every \\hyperref[def:fundamental_net]{fundamental sequence} is convergent by \\fullref{thm:cauchys_net_convergence_criterion}. Furthermore, since \\( \\BbbR \\) is also a \\hyperref[def:separation_axioms/T2]{Hausdorff} space, by \\fullref{thm:t2_iff_singleton_limits}, every fundamental sequence has a unique limit.\n\n  Now consider the following two fundamental sequences:\n  \\begin{align*}\n    &1, 1, 1, 1, \\ldots, \\\\\n    &0, 0.9, 0.99, \\ldots.\n  \\end{align*}\n\n  Their difference\n  \\begin{equation*}\n    1, 0.1, 0.01, \\ldots\n  \\end{equation*}\n  converges to \\( 0 \\).\n\n  Therefore, the two original sequences converge to the same real number, namely \\( 1 \\).\n\\end{itemize}\n\nUnfortunately, a formal study of numbers also leads to artifacts such as the nonstandard natural numbers discussed in \\fullref{rem:standard_models_of_arithmetic}.\n\nWe will describe some basic properties of the common number systems:\n\\begin{itemize}\n  \\item The \\hyperref[def:set_of_natural_numbers]{set \\( \\BbbN \\) of natural numbers} from the perspective of \\fullref{sec:mathematical_logic}.\n  \\item The \\hyperref[def:set_of_integers]{set \\( \\BbbZ \\) of integers} from the perspective of \\fullref{sec:commutative_algebra}.\n  \\item The \\hyperref[def:set_of_rational_numbers]{set \\( \\BbbQ \\) of rational numbers}, only briefly mentioned.\n  \\item The \\hyperref[def:set_of_real_numbers]{set \\( \\BbbR \\) of real numbers} from the perspective of \\fullref{sec:real_analysis}.\n  \\item The \\hyperref[def:set_of_real_numbers]{set \\( \\BbbC \\) of complex numbers} from the perspective of \\fullref{sec:complex_analysis} and \\fullref{sec:commutative_algebra}.\n\\end{itemize}\n", "meta": {"hexsha": "7fa5da9bb39bb628e2ef139d56d15420d2f0c03b", "size": 2686, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/numbers.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/numbers.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/numbers.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 70.6842105263, "max_line_length": 422, "alphanum_fraction": 0.7699180938, "num_tokens": 735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7250454502646022}}
{"text": "\\section{L'H\\^{o}pital's Rule}\r\n\\subsection{Indeterminate Form 0/0}\r\nIf both $f(x)$ and $g(x)$ are 0 at $x=a$, then the limit\r\n\\begin{equation*}\r\n\t\\lim_{x\\to a}{\\frac{f(x)}{g(x)}}.\r\n\\end{equation*}\r\nis an indeterminate form of 0/0, meaning we can't substitute $x=a$ to evaluate the limit.\r\nHowever, L'\\^{o}pital's Rule allows us to modify this limit to get another limit, which might not have this indeterminate form but is guaranteed to have the same limit.\r\n\r\n\\begin{theorem}[L'H\\^{o}pital's Rule, Weaker Form]\r\n\tIf $f(a) = g(a) = 0$; $f^\\prime(a)$ and $g^\\prime(a) \\neq 0$ exist, then\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to a}{\\frac{f(x)}{g(x)}} = \\frac{f^\\prime(a)}{g^\\prime(a)}.\r\n\t\\end{equation*}\r\n\\end{theorem}\r\n\\begin{proof}\r\n\t\\begin{align*}\r\n\t\t\\lim_{x\\to a}{\\frac{f(x)}{g(x)}} &= \\lim_{x\\to a}{\\frac{f(x)-0}{g(x)-0}} \\\\\r\n\t\t&= \\lim_{x\\to a}{\\frac{f(x)-f(a)}{g(x)-g(a)}} \\\\\r\n\t\t&= \\lim_{x\\to a}{\\frac{\\frac{f(x)-f(a)}{x-a}}{\\frac{g(x)-g(a)}{x-a}}} \\\\\r\n\t\t&= \\frac{\\lim_{x\\to a}{\\frac{f(x)-f(a)}{x-a}}}{\\lim_{x\\to a}{\\frac{g(x)-g(a)}{x-a}}} \\\\\r\n\t\t&= \\frac{f^\\prime(a)}{g^\\prime(a)}.\r\n\t\\end{align*}\r\n\\end{proof}\r\n\r\n\\begin{example}\r\n\tFind $\\lim_{x\\to 2}{\\frac{x^2-4}{x-2}}$ using L'H\\^{o}pital's Rule.\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to 2}{\\frac{x^2-4}{x-2}} = \\frac{2(2)}{1} = 4.\r\n\t\\end{equation*}\r\n\t\r\n\tNote that we get the same answer if we didn't use L'H\\^{o}pital's Rule and instead factored.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to 2}{\\frac{x^2-4}{x-2}} = \\lim_{x\\to 2}{\\frac{(x+2)(x-2)}{x-2}} \\lim_{x\\to 2}{x+2} = 4.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\r\nIt's possible that $f^\\prime(a) = g^\\prime(a) = 0$, meaning we're still left with the indeterminate form 0/0.\r\nHowever, we can use a stringer form of L'H\\^{o}pital's Rule that allows us to not have to immediate substitute $x=a$ and allows us to apply the rule multiple times if needed.\r\n\\begin{theorem}[L'H\\^{o}pital's Rule, Stronger Form]\r\n\tIf $f(a)=g(a)=0$; $f$ and $g$ are differentiable on an open interval $I$ that contains $a$; $g^\\prime(x)\\neq 0$ if $x\\neq a$, then\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to a}{\\frac{f(x)}{g(x)}} = \\lim_{x\\to a}{\\frac{f^\\prime(x)}{g^\\prime(x)}}\r\n\t\\end{equation*}\r\n\tif the right-hand limit exists.\r\n\\end{theorem}\r\n\r\n\\begin{example}\r\n\tFind the following limit or show that it doesn't exist.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to 0}{\\frac{\\cos{x}-1}{e^x - x - 1}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\t$\\cos{0}-1 = 0 = e^0 - 0 - 1$; $e^x - x - 1 \\neq 0$ if $x\\neq 0$ on all real numbers.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to 0}{\\frac{\\cos{x}-1}{e^x - x - 1}} = \\lim_{x\\to 0}{\\frac{-\\sin{x}}{e^x - 1}}.\r\n\t\\end{equation*}\r\n\t\r\n\t$-\\sin{0} = 0 = e^0 - 1$; $e^x - 1 \\neq 0$ if $x\\neq 0$ on all real numbers.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to 0}{\\frac{-\\sin{x}}{e^x - 1}} = \\lim_{x\\to 0}{\\frac{-\\cos{x}}{e^x}} = \\frac{-1}{1} = -1.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\\subsection{Indeterminate Forms $\\infty/\\infty$, $\\infty\\cdot 0$, \\& $\\infty - \\infty$}\r\n\\subsubsection{$\\infty/\\infty$}\r\nL'H\\^{o}pital's still applies as written for the indeterminate form $\\infty/\\infty$.\r\n\r\n\\begin{example}\r\n\tFind the following limit or show that it doesn't exist.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to\\pi/2}\\frac{\\tan{x}}{1+\\tan{x}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tApplying L'H\\^{o}pital's Rule,\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to\\pi/2}{\\frac{\\tan{x}}{1+\\tan{x}}} = \\lim_{x\\to\\pi/2}\\frac{\\sec^2{x}}{\\sec^2{x}} = 1.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\\subsubsection{$\\infty\\cdot 0$}\r\nWe need to rearrange the limit into a 0/0 or $\\infty/\\infty$ indeterminate form.\r\n\\begin{example}\r\n\tFind the following limit or show that it doesn't exist.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to\\infty}{x\\sin{\\frac{1}{x}}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tRearranging,\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to\\infty}{x\\sin{\\frac{1}{x}}} = \\lim_{x\\to\\infty}\\frac{\\sin{\\frac{1}{x}}}{\\frac{1}{x}}.\r\n\t\\end{equation*}\r\n\t\r\n\tSince the limit now has indeterminate form 0/0, we can apply L'H\\^{o}pital's Rule.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to\\infty}\\frac{\\sin{\\frac{1}{x}}}{\\frac{1}{x}} = \\lim_{x\\to\\infty}\\frac{\\frac{-1}{x^2}\\cos{\\frac{1}{x}}}{\\frac{-1}{x^2}} = cos(0) = 1.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\\subsubsection{$\\infty - \\infty$}\r\nWe need to rearrange the limit into a 0/0 or $\\infty/\\infty$ indeterminate form.\r\n\\begin{example}\r\n\tFind the following limit or show that it doesn't exist.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to 1}{\\frac{1}{\\ln{x}} - \\frac{1}{x-1}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tRearranging,\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to 1}{\\frac{1}{\\ln{x}} - \\frac{1}{x-1}} = \\lim_{x\\to 1}{\\frac{x-1-\\ln{x}}{(x-1)\\ln{x}}}.\r\n\t\\end{equation*}\r\n\tSince the limit now has indeterminate form 0/0, we can apply L'H\\^{o}pital's Rule.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to 1}{\\frac{x-1-\\ln{x}}{(x-1)\\ln{x}}} = \\lim_{x\\to 1}{\\frac{1-\\frac{1}{x}}{(x-1)\\frac{1}{x} + \\ln{x}}} = \\lim_{x\\to 1}{\\frac{\\frac{1}{x^2}}{\\frac{1}{x} - (x-1)\\frac{1}{x^2} + \\frac{1}{x}}} = \\frac{1}{1-0+1} = \\frac{1}{2}.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\\subsection{Indeterminate Forms $1^\\infty$, $0^0$, \\& $\\infty^0$}\r\nFor indeterminate forms with exponents, we should take the natural log of the limit, solve that limit, and then exponentiate.\r\n\r\n\\subsubsection{$1^\\infty$}\r\n\\begin{example}\r\n\tFind the following limit or show that it doesn't exist.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to \\infty}{\\left(1+\\frac{1}{x}\\right)^x}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tLet $L$ be the value of the limit.\r\n\t\\begin{align*}\r\n\t\tL &= \\lim_{x\\to \\infty}{\\left(1+\\frac{1}{x}\\right)^x} \\\\\r\n\t\t\\ln{L} &= \\lim_{x\\to\\infty}{\\ln{\\left(\\left(1+\\frac{1}{x}\\right)^x\\right)}} \\\\\r\n\t\t&= \\lim_{x\\to\\infty}{x\\ln{\\left(1+\\frac{1}{x}\\right)}} \\text{ (indeterminate form $\\infty\\cdot 0$)} \\\\\r\n\t\t&= \\lim_{x\\to\\infty}{\\frac{\\ln{\\left(1+\\frac{1}{x}\\right)}}{\\frac{1}{x}}} \\text{ (indeterminate form $0/0$)} \\\\\r\n\t\t&= \\lim_{x\\to\\infty}{\\frac{\\frac{1}{1+\\frac{1}{x}}\\frac{-1}{x^2}}{\\frac{-1}{x^2}}} \\\\\r\n\t\t&= \\lim_{x\\to\\infty}{\\frac{1}{1+\\frac{1}{x}}} \\\\\r\n\t\t&= 1 \\\\\r\n\t\te^{\\ln{L}} &= e^1 \\\\\r\n\t\tL &= e.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{$0^0$}\r\n\\begin{example}\r\n\tFind the following limit or show that it doesn't exist.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to 0^+}{x^x}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tLet $L$ be the value of the limit.\r\n\t\\begin{align*}\r\n\t\tL &= \\lim_{x\\to 0^+}{x^x} \\\\\r\n\t\t\\ln{L} &= \\lim_{x\\to 0^+}{x\\ln{x}} \\text{ (indeterminate form $0\\cdot-\\infty$)} \\\\\r\n\t\t&= \\lim_{x\\to 0^+}{\\frac{\\ln{x}}{\\frac{1}{x}}} \\text{ (indeterminate form $-\\infty/\\infty$)} \\\\\r\n\t\t&= \\lim_{x\\to 0^+}{\\frac{\\frac{1}{x}}{\\frac{-1}{x^2}}} \\\\\r\n\t\t&= \\lim_{x\\to 0^+}{\\frac{1}{\\frac{-1}{x}}} \\\\\r\n\t\t&= \\lim_{x\\to 0^+}{-x} \\\\\r\n\t\t&= 0 \\\\\r\n\t\te^{\\ln{L}} &= e^0 \\\\\r\n\t\tL &= 1.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{$\\infty^0$}\r\n\\begin{example}\r\n\tFind the following limit or show that it doesn't exist.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to\\infty}{x^{\\frac{1}{x}}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tLet $L$ be the value of the limit.\r\n\t\\begin{align*}\r\n\t\tL &= \\lim_{x\\to\\infty}{x^{\\frac{1}{x}}} \\\\\r\n\t\t\\ln{L} &= \\lim_{x\\to\\infty}{\\frac{1}{x}\\ln{x}} \\text{ (indeterminate form $0\\cdot\\infty$)} \\\\\r\n\t\t&= \\lim_{x\\to\\infty}{\\frac{\\ln{x}}{x}} \\text{ (indeterminate form $\\infty/\\infty$)} \\\\\r\n\t\t&= \\lim_{x\\to\\infty}{\\frac{\\frac{1}{x}}{1}} \\\\\r\n\t\t&= 0 \\\\\r\n\t\te^{\\ln{L}} &= e^0 \\\\\r\n\t\tL &= 1.\r\n\t\\end{align*}\r\n\\end{answer}", "meta": {"hexsha": "8b9c871fc9b3b0156f405d0bfb168bd5a1423f68", "size": 7396, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/sequences_lhopital_improper/lhopital.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/sequences_lhopital_improper/lhopital.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/sequences_lhopital_improper/lhopital.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9263157895, "max_line_length": 232, "alphanum_fraction": 0.5835586804, "num_tokens": 3189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.8723473697001441, "lm_q1q2_score": 0.7250454443464286}}
{"text": "\\Lecture{Jayalal Sarma}{Oct 21, 2020}{19}{Computing Ramsey Numbers and Multidimensional Ramsey numbers}{Shivlal Gangesh}{$\\alpha$}{JS}\n\\section{Generalizing Ramsey numbers}\n\\begin{definition}[3-dimensional Ramsey numbers]\n$R_3(p,q,r)$ is the minimum number $n$, such that any 3-edge coloring $K_n$ must have either a red $K_p$ or a blue $K_q$ or a green $K_r$\n\\end{definition}\n\\begin{definition}[$k$-dimensional Ramsey numbers]\n$R_k(s_1,s_2,\\cdots ,s_k)$ is the minimum number of vertices $n$ such that for any $k$-edge coloring of $K_n$  there must exist an $i$ such that there is a $K_{s_i}$ of colour $i$\n\\end{definition}\n\n\\section{Some Observations}\n\\begin{property}\n$R(2,p)=p$\n\\end{property}\n\\begin{proof}\n$ $ \n \\begin{description}\n    \\item[Case1 : $R(2,p) \\leq p$]\n    $ $ \\newline\n    Any 2-coloring of $K_p$ must have either a red $K_2$ or blue $K_p$. This is true because either there can exist a red edge (red $K_2$) or no red edge (blue $K_p$) in $K_p$\n    \\item[Case 2 : $R(2,p) \\geq p$]\n    $ $ \\newline\n    There exist a 2-coloring of edges of $K_{p-1}$ such that no red $K_2$ exists and no blue $K_p$ exists. Coloring all the edges of $K_{p-1}$ with blue will result in no red $K_2$ and no blue $K_p$ in $K_{p-1}$\n \\end{description}\n\\end{proof}\n\\begin{claim}\n$$ R(p,q) \\leq {p+q-2 \\choose p-1} $$\n\\end{claim}\n\\begin{proof}\n \\begin{align*}\n     R(p,q) &\\leq  R(p,q-1) + R(p-1,q) && \\textrm{(Erdos-Szekeres recurrence relation)} \\\\\n     &\\leq {p+(q-1)-2 \\choose p-1} + {p-1+q-2 \\choose p-2} \\\\\n     &\\leq {p+q-3 \\choose p-1} + {p+q-3 \\choose p-2} \\\\\n     &\\leq {p+q-2 \\choose p-1}  && ({n+1 \\choose k+1} = {n \\choose k+1} +{n \\choose k})\n \\end{align*}\n\n\\end{proof}\n\\section{Explicit Computation of R(3,4)}\nWe don't know the exact values of Ramsey numbers for higher values as their computation becomes very hard. There is this famous saying by Paul Erdos on the difficulty of computing Ramsey numbers that\n\\begin{description}\n   \\item[Paul Erdos on Ramsey numbers] \n   $ $ \\newline\n\\textit{   \"Suppose aliens invade the earth and threaten to obliterate it in a year's time unless human beings can find the Ramsey number for red five and blue five. We could marshal the world's best minds and fastest computers, and within a year we could probably calculate the value. If the aliens demanded the Ramsey number for red six and blue six, however, we would have no choice but to launch a preemptive attack.\"}\n\\end{description}\n So let us now try to calculate the value of $R(3,4)$. \n \\begin{claim}\n $$ R(3,4) = 9 $$\n \\end{claim}\n \\begin{proof}\n $ $\n Consider any 2-coloring of $K_9$ and call it as $G$. We need to prove that $G$ has either a red $K_3$ or a blue $K_4$. Any vertex in $G$ can have it's incident edges as one of the three cases below\n  \\begin{itemize}\n  \\item \\textbf{Case 1 : }There are at least $4$ red edges going out of the vertex\n  \\item \\textbf{Case 2 : }There are at least $6$ blue edges going out of the vertex\n  \\item \\textbf{Case 3 : }There are exactly $3$ red edges and $5$ blue edges going out of the vertex\n  \\end{itemize}\n However note that not all vertices in $G$ come under \\textbf{Case 3} because, if so then the total sum of degrees of all vertices becomes odd which is not possible. So let $v$ be a vertex in $G$ which does not fall under \\textbf{Case 3}. Then\n \\begin{description}\n    \\item[Case 1 : There are at least 4 red edges going out of $v$ ]\n    $ $ \\newline\n    Let $H_1$ be the subgraph of $G$ formed from the four vertices which are sharing the red edge with $v$.  Since we know that $R(2,4)=4$, $H_1$ with 4 vertices must have a red $K_2$ or a blue $K4$, So along with vertex $v$, $G$ must have a red $K_3$ or a blue $K_4$.\n    \\item[Case 2 :There are at least 6 blue edges going out of $v$]\n    $ $ \\newline\n    Let $H_2$ be the subgraph of $G$ formed from the six vertices which are sharing the blue edge with $v$. Since we know that $R(3,3)=6$, $H_2$ with 6 vertices must have a red $K_3$ or a blue $K3$, So along with vertex $v$, $G$ must have a red $K_3$ or a blue $K_4$.\n    \\item[Proof for tightness]\n    $ $ \\newline\n    To prove that $9$ is tight, we need to show that there is a 2-coloring of $K_8$ such that it does not have red $K_3$ or blue $K_4$. Given below is one such  example\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.5\\linewidth]{images/R34counter_example.png}\n    \\caption{2-coloring of $K_8$ with no red $K_3$ and no blue $K_4$}\n\\end{figure}\n \\end{description}\n  \n \\end{proof}\n As the values $p$, $q$ increases we can only calculate the range of the Ramsey number. The following is a table with value or range of Ramsey numbers for the first few natural numbers.\n \\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=1\\linewidth]{images/RamseyTable.png}\n    \\caption{Table for $R(p,q)$}\n\\end{figure}", "meta": {"hexsha": "b001c4d0b65f24c0762ab7086d9c7243ed1fd95f", "size": 4805, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week07L2.tex", "max_stars_repo_name": "pot8ohead/theory-toolkit", "max_stars_repo_head_hexsha": "177249454691f7e264d9ee7d5a354e180a54e095", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week07L2.tex", "max_issues_repo_name": "pot8ohead/theory-toolkit", "max_issues_repo_head_hexsha": "177249454691f7e264d9ee7d5a354e180a54e095", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week07L2.tex", "max_forks_repo_name": "pot8ohead/theory-toolkit", "max_forks_repo_head_hexsha": "177249454691f7e264d9ee7d5a354e180a54e095", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.0625, "max_line_length": 422, "alphanum_fraction": 0.6878251821, "num_tokens": 1582, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.7250192751274894}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\n\\section{Discrete-time compartment model} \\label{sec:dtcm(chapcomp)}\nIt is also possible to build a discrete-time compartment model, and this could even be more relevant than a continuous-time one in the context of numerical implementation. Consider equation~\\eqref{eq:compartmentmatrix}. For a given time step $\\Delta t > 0$, we would like to build a similar expression that would link $\\b c(t+\\Delta t)$ to $\\b c(t)$. From the theory of ordinary differential equations~\\cite{EDO}, we know that the general solution to that equation is\n\\begin{equation} \\label{eq:generalODEsol}\n\t\\b c(t) = \\Exp^{\\bs \\Omega^{-1}\\b A(t-t_0)} \\b c(t_0) + \\int_{t_0}^t \\Exp^{\\bs \\Omega^{-1}\\b A(t-s)} \\b q(s) \\rm ds.\n\\end{equation}\nFor a general source term $\\b q$, it is not possible to write a matrix expression of the form $\\b c(t+\\Delta t) = \\b A_{\\Delta t} \\b c(t) + \\b B_{\\Delta t} \\b q(t)$, but it is possible under certain conditions on $\\b q$. In this work, we won't need such conditions because we make the assumption that there is no source/sink term, i.e. we assume that $\\b q = 0$. Let $t_0 < t_1 < t_2 < \\dots$ be such that $t_{k+1} = t_k + \\Delta t$. If $\\b c(t_k)$ is known, $\\b c(t_{k+1})$ can be computed using~\\eqref{eq:generalODEsol} with $\\b q = 0$:\n\\begin{equation}\n\t\\b c(t_{k+1}) = \\Exp^{\\bs \\Omega^{-1}\\b A\\Delta t} \\b c(t_k).\n\\end{equation}\nDoing this, we have found a matrix relation that links $\\b c(t+\\Delta t)$ to $\\b c(t)$:\n\\begin{equation} \\label{eq:generaldiscretecompartment}\n\t\\b c(t + \\Delta t) = \\b A_{\\Delta t} \\b c(t),\n\\end{equation}\nwhere $\\b A_{\\Delta t} = \\Exp^{\\bs \\Omega^{-1}\\b A\\Delta t}$ is the \\textit{discrete interaction matrix}. Notice that the discrete interaction matrix is closely related to the transition probability matrix introduced in chapter~\\ref{chap:clustering}. Indeed, developing~\\eqref{eq:generaldiscretecompartment} for $C_i(t)$ yields\n\\begin{equation} \\label{eq:crapaud}\n\tC_i(t+\\Delta t) = [\\b A_{\\Delta t}]_{i,1} C_{1}(t) + [\\b A_{\\Delta t}]_{i,2} C_{2}(t) + \\ldots + [\\b A_{\\Delta t}]_{i,N} C_{N}(t).  \t\n\\end{equation}\nLet $P_i(t)$ denote the number of tracer's particles in compartment $i$ at time $t$, and let $P$ be the mass of one tracer's particle. Notice that\n\\begin{equation}\n\tC_i(t) = \\frac{P_i(t) P}{|\\Omega_i|}.\n\\end{equation}\nMultiplying equation~\\eqref{eq:crapaud} by $|\\Omega_i|/P$ yields after some manipulations\n\\begin{equation}\n\tP_i(t) = [\\b A_{\\Delta t}]_{i,1} \\frac{|\\Omega_i|}{|\\Omega_1|} P_{1}(t) + [\\b A_{\\Delta t}]_{i,2}\\frac{|\\Omega_i|}{|\\Omega_2|} P_{2}(t) + \\ldots + [\\b A_{\\Delta t}]_{i,N}\\frac{|\\Omega_i|}{|\\Omega_N|} P_{N}(t).\n\\end{equation}\nHence, the factor $\\frac{|\\Omega_i|}{|\\Omega_j|}[\\b A_{\\Delta t}]_{i,j}$ can be interpreted as the probability \\label{page:probability_interpretation} for a tracer's particle to end up in compartment $i$ after a period $\\Delta t$ if it was initially in compartment $j$. This consideration suggests that the entries of $\\b A_{\\Delta t}$ should be nonnegative: this is indeed an important property of the discrete interaction matrix that shall be proven shortly.\n\\begin{property} \\label{prop1_discr_comp}\n\tThe entries of the discrete interaction matrix are nonnegative:\n\t\\begin{equation}\n\t\t[\\b A_{\\Delta t}]_{ij} \\ge 0 \\mbox{ for every } i,j = 1,\\dots,N.\n\t\\end{equation}\n\\end{property}\n\\begin{proof}\n\tLet $C_0 > 0$ be a positive constant, and fix $j \\in \\{1,\\dots,N\\}$. Suppose that \n\t\\begin{equation}\n\t\t\\b c(t) = \\begin{pmatrix} c_1(t) \\\\ \\vdots \\\\ c_{j-1}(t) \\\\ c_j(t) \\\\ c_{j+1}(t) \\\\ \\vdots \\\\ c_N(t) \\end{pmatrix}\n\t\t\t\t= \\begin{pmatrix} 0 \\\\ \\vdots \\\\ 0 \\\\ C_0 \\\\ 0 \\\\ \\vdots \\\\ 0 \\end{pmatrix}.\n\t\\end{equation}\n\tBy equation~\\eqref{eq:generaldiscretecompartment},\n\t\\begin{equation}\n\t\t\\b c(t+\\Delta t) = \\b A_{\\Delta t} \\b c(t) = \\begin{pmatrix} [\\b A_{\\Delta t}]_{1,j} C_0 \\\\ \\vdots \\\\ [\\b A_{\\Delta t}]_{N,j} C_0 \\end{pmatrix}.\n\t\\end{equation}\n\tSince $\\b c$ is a concentration, we must have that $\\b c(t) \\ge \\b 0$ at any time $t$. Therefore, since $C_0 > 0$ we must have that\n\t\\begin{equation}\n\t\t[\\b A_{\\Delta t}]_{i,j} \\ge 0 \\mbox{ for every } i = 1,\\dots,N.\n\t\\end{equation}\n\tFinally, as we have made no assumption on $j$, this must be true for any $j \\in \\{1,\\dots,N\\}$, which concludes the proof.\n\\end{proof}\nThe interpretation of $\\frac{|\\Omega_i|}{|\\Omega_j|}[\\b A_{\\Delta t}]_{i,j}$ in terms of a transition probability of the tracer's particles between compartments suggests another important property of the discrete interaction matrix. Indeed, the tracer's particles can neither disappear nor be created, hence the sum of the probabilities over all possible destinations (i.e. over all compartments since we consider an isolated domain) must be equal to one:\n\\begin{equation}\n\t\\sum_{i=1}^N \\frac{|\\Omega_i|}{|\\Omega_j|}[\\b A_{\\Delta t}]_{i,j} = 1 \\quad \\mbox{for every } j=1,\\dots,N.\n\\end{equation}\nThis property can be deduced from property~\\ref{prop1_comp}:\n\n\\begin{property} \\label{prop1ter_comp} \\label{prop2_discr_comp}\n\tThe columns of the discrete interaction matrix satisfy the following relation:\n\t\\begin{equation}\n\t\t\\sum_{i=1}^N |\\Omega_i|  [\\b A_{\\Delta t}]_{ij} = |\\Omega_j| \\quad \\mbox{for every } j=1,\\dots,N.\n\t\\end{equation}\n\tIn matrix form:\n\t\\begin{equation}\n\t\t\\bs \\omega^\\t \\b A_{\\Delta t} = \\bs \\omega^\\t .\n\t\\end{equation}\n\\end{property}\n\\begin{proof}\n\tThe expression of the mean concentration over $\\Omega$ is the same as in the continuous case:\n\t\\begin{equation}\n\t\t\\bar C = \\frac{1}{|\\Omega|} \\b 1^\\t \\bs \\Omega \\b c.\n\t\\end{equation}\n\tSince $\\bar C$ is constant, we must have that\n\t\\begin{equation}\n\t\t|\\Omega| \\bar C(t+\\Delta t) = |\\Omega| \\bar C(t) = \\b1^\\t \\bs \\Omega \\b c(t) = \\bs \\omega^\\t \\b c(t),\n\t\\end{equation}\n\tbut by equation~\\eqref{eq:generaldiscretecompartment} we also have that\n\t\\begin{equation}\n\t\t|\\Omega| \\bar C(t+\\Delta t) = \\b1^\\t \\bs \\Omega \\b c(t+\\Delta t) = \\b1^\\t \\bs \\Omega \\b A_{\\Delta t} \\b c(t) = \\bs \\omega^\\t \\b A_{\\Delta t} \\b c(t).\n\t\\end{equation}\n\tHence, $\\bs \\omega^\\t \\b c(t) = \\bs \\omega^\\t \\b A_{\\Delta t} \\b c(t)$, and since this must be true for every possible value of $\\b c(t)$, we must have that\n\t\\begin{equation} \\label{eq:prop1ter_comp}\n\t\t\\bs \\omega^\\t = \\bs \\omega^\\t \\b A_{\\Delta t},\n\t\\end{equation}\n\tthe desired result.\n\\end{proof}\n\\begin{corollary}{prop1ter_comp} \\label{corollary2}\n\tIf the compartments all have the same size, the discrete interaction matrix is  left stochastic:\n\t\\begin{equation}\n\t\t\\b 1^\\t \\b A_{\\Delta t} = \\b 1^\\t.\n\t\\end{equation}\n\\end{corollary}\n\\begin{proof}\n\tLet $|\\Omega_0|$ be the size of the compartments. Then, $\\bs \\omega = |\\Omega_0| \\b 1$ and equation~\\eqref{eq:prop1ter_comp} reduces to\n\t\\begin{equation}\n\t\t|\\Omega_0| \\b 1^\\t = |\\Omega_0| \\b 1^\\t \\b A_{\\Delta t}.\n\t\\end{equation}\n\\end{proof}\nProperty~\\ref{prop2_comp} also has an interpretation in terms of the discrete interaction matrix:\n\\begin{property} \\label{prop2ter_comp} \\label{prop3_discr_comp}\n\tThe discrete interaction matrix is right stochastic:\n\t\\begin{equation}\n\t\t\\b A_{\\Delta t} \\b 1 = \\b 1.\n\t\\end{equation}\n\\end{property}\n\\begin{proof}\n\tLet $C_0 > 0$ be a constant and $\\b c(t) = C_0 \\b 1$. Introducing the latter in~\\eqref{eq:generaldiscretecompartment} yields\n\t\\begin{equation}\n\t\tC_0 \\b 1 = \\b A_{\\Delta t} C_0 \\b 1 = C_0 \\b A_{\\Delta t} \\b 1.\n\t\\end{equation}\n\\end{proof}\nTwo last properties allow to bound the entries of the discrete interaction matrix:\n\\begin{property} \\label{prop4_discr_comp}\n\tThe entries of the discrete interaction matrix are smaller than one:\n\t\\begin{equation}\n\t \t\t[\\b A_{\\Delta t}]_{i,j} \\le 1 \\mbox{ for every } i,j = 1,\\dots,N.\n\t\\end{equation}\n\\end{property}\n\\begin{proof}\n\tWe proceed by contradiction. Suppose there exists $i,j \\in \\{1,\\dots,N\\}$ such that $[\\b A_{\\Delta t}]_{i,j} > 1$. By property~\\ref{prop1_discr_comp}, all the entries of $\\b A_{\\Delta t}$ are nonnegative so that\n\t\\begin{equation}\n\t\t\\sum_{k = 1}^N [\\b A_{\\Delta t}]_{i,k} > 1,\n\t\\end{equation}\n\tin contradiction with property~\\ref{prop2ter_comp}.\n\\end{proof}\n\\begin{property} \\label{prop5_discr_comp}\n\tThe entries of the discrete interaction matrix satisfy\n\t\\begin{equation}\n\t\t\\frac{|\\Omega_i|}{|\\Omega_j|} [\\b A_{\\Delta t}]_{i,j} \\le 1 \\mbox{ for every } i,j = 1,\\dots,N.\n\t\\end{equation}\n\\end{property}\n\\begin{proof}\n\tWe proceed again by contradiction. Suppose there exist $i,j \\in \\{1,\\dots,N\\}$ such that $\\frac{|\\Omega_i|}{|\\Omega_j|} [\\b A_{\\Delta t}]_{i,j} > 1$. By property~\\ref{prop1_discr_comp}, all the entries of $\\b A_{\\Delta t}$ are nonnegative so that\n\t\\begin{equation}\n\t\t\\sum_{k = 1}^N \\frac{|\\Omega_k|}{|\\Omega_j|}[\\b A_{\\Delta t}]_{k,j} > 1,\n\t\\end{equation}\n\tin contradiction with property~\\ref{prop1ter_comp}.\n\\end{proof}\nThis last property is in agreement with the interpretation of the factors $\\frac{|\\Omega_i|}{|\\Omega_j|} [\\b A_{\\Delta t}]_{i,j}$ as probabilities of transition between the compartments.", "meta": {"hexsha": "0a87d76147c797f7bc3c00e802ebfc4e765ad35a", "size": 8877, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/compartments/discretetime_comp_model.tex", "max_stars_repo_name": "dufaysr/tfe", "max_stars_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inputs/compartments/discretetime_comp_model.tex", "max_issues_repo_name": "dufaysr/tfe", "max_issues_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inputs/compartments/discretetime_comp_model.tex", "max_forks_repo_name": "dufaysr/tfe", "max_forks_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.795620438, "max_line_length": 538, "alphanum_fraction": 0.6827757125, "num_tokens": 3108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7250192692240242}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{bbm}\n\\usepackage{color}\n\\usepackage{graphicx} \n\\usepackage{caption}\n\\usepackage{subcaption}\n\n\\newcommand{\\X} {\\mathbf{X}}\n\n\\newcommand{\\todo}[1] { \\emph{ {\\color{red}TODO: #1} } }\n\n\\begin{document}\n\n\\section{Incremental calculation of a covariance matrix}\nGiven a $T\\times N$ matrix $m$ of measurements in $N$ variables\nat $T$ timesteps, the covariance matrix of all variables is given by\n\\begin{align}\n  C_{ij} &= \\left<\\left(\\X_i- \\left<\\X_i\\right>\\right) \\left(\\X_j-\\left<\\X_j\\right>\\right)\\right>,\n\\end{align}\nwhere $\\X_i \\in \\mathbb{R}^T$ denotes column $i$ of matrix $m$ with all observations\nof variable $i$ and $\\left< \\dots \\right>$ is the average of the given observations.\nUsing the definition\n\\begin{align}\n  \\mu_i := \\left< \\X_i \\right>,\n\\end{align}\nthe construction of the covariance matrix can be expressed as\n\\begin{align}\n  C_{ij} &= \\left<\\left(\\X_i - \\mu_i\\right) \\left(\\X_j - \\mu_j\\right)\\right>\\\\\n         &= \\left<\\X_i \\X_j\\right> - \\left< \\mu_i \\X_j \\right> - \\left< \\mu_j \\X_i \\right> + \\left< \\mu_i \\mu_j \\right>\\\\\n         &= \\left<\\X_i \\X_j\\right> - \\mu_i \\left<\\X_j \\right> - \\mu_j \\left<\\X_i\\right> + \\left< \\mu_i \\mu_j \\right>\\\\\n         &= \\left<\\X_i \\X_j\\right> - \\mu_i \\mu_j - \\mu_j \\mu_i + \\mu_i \\mu_j\\\\\n         &= \\left<\\X_i \\X_j\\right> - \\mu_i \\mu_j\\\\\n         &= \\frac{1}{T} \\sum_t m_{ti} m_{tj} - \\mu_i \\mu_j\\\\\n         &= \\frac{1}{T-1}\\left( \\sum_t m_{ti} m_{tj} - \\frac{1}{T} \\left(\\sum_t m_{ti}\\right) \\left(\\sum_t m_{tj}\\right) \\right)\n            \\label{eq:cov_standard}.\n\\end{align}\nFollowing this expression, we see that the covariance matrix can be\nconstructed incrementally by summing over the observations with constant memory consumption.\nThe used memory will be of order\n\\begin{align}\n  \\mathcal{O}_M &= \\mathcal{O}_C + N\\mathcal{O}_\\mu\\\\\n                &= \\mathcal{O}\\left( (N-1)(N-2) / 2 \\right) + N\\mathcal{O}\\left(1\\right)\\\\\n                &= \\mathcal{O}\\left( N^2 \\right),\n\\end{align}\nwith the memory consumption $\\mathcal{O}_C$ of the (symmetric) covariance matrix and\nthe memory consumption $\\mathcal{O}_\\mu$ per observable average.\nThe runtime behavior will be of order\n\\begin{align}\n  \\mathcal{O}_R &= \\mathcal{O}\\left(T N\\left(N-1\\right)\\right).\n\\end{align}\nAssuming the number of observations $T$ is much greater than the number of variables $N$, i.e. $T \\gg N$,\nthe runtime behavior may be described as being linear in $T$:\n\\begin{align}\n  \\mathcal{O}_R &= \\mathcal{O}\\left(T\\right).\n\\end{align}\n\n\\subsection{Weighted variables}\nTo construct a covariance matrix with weighted variables (e.g. a mass-weighted covariance of molecular coordinates),\none previously defines a set of $N$ weights $w_i$ and expands the given incremental form (\\ref{eq:cov_standard}) to\n\\begin{align}\n  \\tilde{C}_{ij} &= \\frac{1}{T}\\left( \\sum_t w_i m_{ti} w_j m_{tj} - \\frac{1}{T} \\left(\\sum_t w_i m_{ti}\\right) \\left(\\sum_t w_j m_{tj}\\right) \\right)\\\\\n                 &= \\frac{1}{T}\\left( w_i w_j \\sum_t m_{ti} m_{tj} - \\frac{1}{T} \\left(w_i \\sum_t m_{ti}\\right) \\left(w_j \\sum_t m_{tj}\\right) \\right)\\\\\n                 &= \\frac{w_i w_j}{T}\\left(\\sum_t m_{ti} m_{tj} - \\frac{1}{T} \\left(\\sum_t m_{ti}\\right) \\left(\\sum_t m_{tj}\\right) \\right).\n\\end{align}\nHere, it is assumed that all the weights are normalized, i.e. that they fulfill the relation\n\\begin{align}\n  \\sum_i^N w_i = 1,\n\\end{align}\nwith $0 \\le w_i \\le 1$.\nIf this is not the case, one can trivially transform the set of weights to a normalized one by dividing the weights by their sum.\n\n\\subsection{Weighted observations}\nTo construct a covariance matrix based on observations of different quality, we introduce the weights $\\nu\\left(t\\right)$, defined\nfor an observation at time $t$.\nAgain, one can extend eq. (\\ref{eq:cov_standard}) to a weighted form:\n\\begin{align}\n  \\hat{C}_{ij} &= \\frac{1}{\\tau}\\left( \\sum_t \\nu\\left(t\\right) m_{ti} m_{tj}\n                   - \\frac{1}{\\tau} \\left(\\sum_t \\nu\\left(t\\right) m_{ti}\\right) \\left(\\sum_t \\nu\\left(t\\right) m_{tj}\\right) \\right),\n\\end{align}\nwith $\\tau = \\sum_t \\nu\\left(t\\right)$ being the total weight.\nIn the case of unweighted observations, i.e. for $\\nu\\left(t\\right) = 1 \\; \\forall \\; t$, this reduces to the standard definition\nof a covariance matrix (eq. (\\ref{eq:cov_standard})).\n\n\\end{document}\n", "meta": {"hexsha": "d015bf03eb435421cddac64f73f8f8ff99f40313", "size": 4353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/theory.tex", "max_stars_repo_name": "simonbray/FastPCA", "max_stars_repo_head_hexsha": "a586cbc0e00122565a2b8ab0a62fc84839aec524", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2017-03-04T03:10:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-10T22:34:09.000Z", "max_issues_repo_path": "doc/theory.tex", "max_issues_repo_name": "simonbray/FastPCA", "max_issues_repo_head_hexsha": "a586cbc0e00122565a2b8ab0a62fc84839aec524", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2016-02-04T17:13:02.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-22T12:08:50.000Z", "max_forks_repo_path": "doc/theory.tex", "max_forks_repo_name": "lettis/FastPCA", "max_forks_repo_head_hexsha": "771e226bd4d05e4ed9bc6a62d8af92708aa5eede", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-02-04T20:15:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-14T11:55:15.000Z", "avg_line_length": 49.4659090909, "max_line_length": 152, "alphanum_fraction": 0.6668963933, "num_tokens": 1491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.7250192612758515}}
{"text": "\\section{Graph Algorithms}\n\n\nWelcome to the new episode of PrinceOfPersia presents: Fun with algorithms ;)\n\nYou can find all the definitions here in the book \"Introduction to graph theory\", Douglas.B West. Important graph algorithms :\n\\subsection{DFS}\nThe most useful graph algorithms are search algorithms. DFS (Depth First Search) is one of them.\n\nWhile running DFS, we assign colors to the vertices (initially white). Algorithm itself is really simple :\n\\begin{verbatim}\ndfs (v):\n        color[v] = gray\n        for u in adj[v]:\n                if color[u] == white\n                        then dfs(u)\n        color[v] = black\n\\end{verbatim}\nBlack color here is not used, but you can use it sometimes.\n\nTime complexity : $O(n + m)$.\n\\subsubsection{DFS tree}\nDFS tree is a rooted tree that is built like this :\n\n\\begin{verbatim}\nlet T be a new tree\ndfs (v):\n        color[v] = gray\n        for u in adj[v]:\n                if color[u] == white\n                        then dfs(u) and par[u] = v (in T)\n\n        color[v] = black\n\\end{verbatim}\nLemma: There is no cross edges, it means if there is an edge between v and u, then v = par[u] or u = par[v].\n\\subsubsection{Starting time, finishing time}\nStarting time of a vertex is the time we enter it (the order we enter it) and its finishing time is the time we leave it. Calculating these are easy :\n\\begin{verbatim}\nTIME = 0\ndfs (v):\n        st[v] = TIME ++\n        color[v] = gray\n        for u in adj[v]:\n                if color[u] == white\n                        then dfs(u)\n        color[v] = black\n        ft[v] = TIME // or we can use TIME ++\n\\end{verbatim}\nIt is useable in specially data structure problems (convert the tree into an array).\n\nLemma: If we run dfs(root) in a rooted tree, then v is an ancestor of u if and only if stv ≤ stu ≤ ftu ≤ ftv .\n\nSo, given arrays st and ft we can rebuild the tree.\n\\subsubsection{Finding cut edges}\nThe code below works properly because the lemma above (first lemma):\n\\begin{verbatim}\nh[root] = 0\npar[v] = -1\ndfs (v):\n        d[v] = h[v]\n        color[v] = gray\n        for u in adj[v]:\n                if color[u] == white\n                        then par[u] = v and dfs(u) and d[v] = min(d[v], d[u])\n                        if d[u] > h[v]\n                                then the edge v-u is a cut edge\n                else if u != par[v])\n                        then d[v] = min(d[v], h[u])\n        color[v] = black\n\\end{verbatim}\nIn this code, h[v] =  height of vertex v in the DFS tree and d[v] = min(h[w] where there is at least vertex u in subtree of v in the DFS tree where there is an edge between u and w).\n\\subsubsection{Finding cut vertices}\nThe code below works properly because the lemma above (first lemma):\n\\begin{verbatim}\nh[root] = 0\npar[v] = -1\ndfs (v):\n        d[v] = h[v]\n        color[v] = gray\n        for u in adj[v]:\n                if color[u] == white\n                        then par[u] = v and dfs(u) and d[v] = min(d[v], d[u])\n                        if d[u] >= h[v] and (v != root or number_of_children(v) > 1)\n                                then the edge v is a cut vertex\n                else if u != par[v])\n                        then d[v] = min(d[v], h[u])\n        color[v] = black\n\\end{verbatim}\nIn this code, h[v] =  height of vertex v in the DFS tree and d[v] = min(h[w] where there is at least vertex u in subtree of v in the DFS tree where there is an edge between u and w).\n\\subsubsection{Finding Eulerian tours}\nIt is quite like DFS, with a little change :\n\\begin{verbatim}\nvector E\ndfs (v):\n        color[v] = gray\n        for u in adj[v]:\n                erase the edge v-u and dfs(u)\n        color[v] = black\n        push v at the end of e\n\\end{verbatim}\ne is the answer.\n\\subsection{BFS}\nBFS is another search algorithm (Breadth First Search). It is usually used to calculate the distances from a vertex v to all other vertices in unweighted graphs.\n\nCode :\n\\begin{verbatim}\n        BFS(v):\n                for each vertex i\n                        do d[i] = inf\n                d[v] = 0\n                queue q\n                q.push(v)\n                while q is not empty\n                        u = q.front()\n                        q.pop()\n                        for each w in adj[u]\n                                if d[w] == inf\n                                        then d[w] = d[u] + 1, q.push(w)\n\\end{verbatim}\nDistance of vertex u from v is d[u].\n\nTime complexity : O(n + m).\n\\subsubsection{BFS tree}\nBFS tree is a rooted tree that is built like this :\n\\begin{verbatim}\nlet T be a new tree\n        BFS(v):\n                for each vertex i\n                        do d[i] = inf\n                d[v] = 0\n                queue q\n                q.push(v)\n                while q is not empty\n                        u = q.front()\n                        q.pop()\n                        for each w in adj[u]\n                                if d[w] == inf\n                                        then d[w] = d[u] + 1, q.push(w) and par[w] = u (in T)\n\\end{verbatim}\n\\subsection{SCC}\nThe most useful and fast-coding algorithm for finding SCCs is Kosaraju.\n\nIn this algorithm, first of all we run DFS on the graph and sort the vertices in decreasing of their finishing time (we can use a stack).\n\nThen, we start from the vertex with the greatest finishing time, and for each vertex v that is not yet in any SCC, do : for each u that v is reachable by u and u is not yet in any SCC, put it in the SCC of vertex v. The code is quite simple.\n\n\\subsection{Shortest path}\nShortest path algorithms are algorithms to find some shortest paths in directed or undirected graphs.\n\\subsubsection{Dijkstra}\nThis algorithm is a single source shortest path (from one source to any other vertices). Pay attention that you can't have edges with negative weight.\n\nPseudo code :\n\\begin{verbatim}\ndijkstra(v) :\n        d[i] = inf for each vertex i\n        d[v] = 0\n        s = new empty set\n        while s.size() < n\n                x = inf\n                u = -1\n                for each i in V-s //V is the set of vertices\n                        if x >= d[i]\n                                then x = d[i], u = i\n                insert u into s\n                // The process from now is called Relaxing\n                for each i in adj[u]\n                        d[i] = min(d[i], d[u] + w(u,i))\n\\end{verbatim}\nThere are two different implementations for this. Both are useful (C++11).\n\nOne) $O(n^2)$\n\\begin{verbatim}\nint mark[MAXN];\nvoid dijkstra(int v){\n\tfill(d,d + n, inf);\n\tfill(mark, mark + n, false);\n\td[v] = 0;\n\tint u;\n\twhile(true){\n\t\tint x = inf;\n\t\tu = -1;\n\t\tfor(int i = 0;i < n;i ++)\n\t\t\tif(!mark[i] and x >= d[i])\n\t\t\t\tx = d[i], u = i;\n\t\tif(u == -1)\tbreak;\n\t\tmark[u] = true;\n\t\tfor(auto p : adj[u]) //adj[v][i] = pair(vertex, weight)\n\t\t\tif(d[p.first] > d[u] + p.second)\n\t\t\t\td[p.first] = d[u] + p.second;\n\t}\n}\n\\end{verbatim}\nTwo) \n\n1) Using std :: set :\n\\begin{verbatim}\nvoid dijkstra(int v){\n\tfill(d,d + n, inf);\n\td[v] = 0;\n\tint u;\n\tset<pair<int,int> > s;\n\ts.insert({d[v], v});\n\twhile(!s.empty()){\n\t\tu = s.begin() -> second;\n\t\ts.erase(s.begin());\n\t\tfor(auto p : adj[u]) //adj[v][i] = pair(vertex, weight)\n\t\t\tif(d[p.first] > d[u] + p.second){\n\t\t\t\ts.erase({d[p.first], p.first});\n\t\t\t\td[p.first] = d[u] + p.second;\n\t\t\t\ts.insert({d[p.first], p.first});\n\t\t\t}\n\t}\n}\n\\end{verbatim}\n2) Using std :: priority$\\_$queue (better):\n\\begin{verbatim}\nbool mark[MAXN];\nvoid dijkstra(int v){\n\tfill(d,d + n, inf);\n\tfill(mark, mark + n, false);\n\td[v] = 0;\n\tint u;\n\tpriority_queue<pair<int,int>,vector<pair<int,int> >, less<pair<int,int> > > pq;\n\tpq.push({d[v], v});\n\twhile(!pq.empty()){\n\t\tu = pq.top().second;\n\t\tpq.pop();\n\t\tif(mark[u])\n\t\t\tcontinue;\n\t\tmark[u] = true;\n\t\tfor(auto p : adj[u]) //adj[v][i] = pair(vertex, weight)\n\t\t\tif(d[p.first] > d[u] + p.second){\n\t\t\t\td[p.first] = d[u] + p.second;\n\t\t\t\tpq.push({d[p.first], p.first});\n\t\t\t}\n\t}\n}\n\\end{verbatim}\n\n\\subsubsection{Floyd-Warshall}\nFloyd-Warshal algorithm is an all-pairs shortest path algorithm using dynamic programming.\n\nIt is too simple and undrestandable :\n\\begin{verbatim}\nFloyd-Warshal()\n\td[v][u] = inf for each pair (v,u)\n\td[v][v] = 0 for each vertex v\n\tfor k = 1 to n\n\t\tfor i = 1 to n\n\t\t\tfor j = 1 to n\n                d[i][j] = min(d[i][j], d[i][k] + d[k][j])\n\\end{verbatim}\nTime complexity : $O(n^3)$.\n\\subsubsection{Bellman-Ford}\nBellman-Ford is an algorithm for single source shortest path where edges can be negative (but if there is a cycle with negative weight, then this problem will be NP).\n\nThe main idea is to relax all the edges exactly n - 1 times (read relaxation above in dijkstra). You can prove this algorithm using induction.\n\nIf in the n - th step, we relax an edge, then we have a negative cycle (this is if and only if).\n\nCode :\n\\begin{verbatim}\nBellman-Ford(int v)\n\td[i] = inf for each vertex i\n\td[v] = 0\n\tfor step = 1 to n\n\t\tfor all edges like e\n\t\t\ti = e.first // first end\n\t\t\tj = e.second // second end\n\t\t\tw = e.weight\n\t\t\tif d[j] > d[i] + w\n\t\t\t\tif step == n\n\t\t\t\t\tthen return \"Negative cycle found\"\n                d[j] = d[i] + w\n\\end{verbatim}\nTime complexity : $O(nm)$.\n\\subsubsection{SPFA}\nSPFA (Shortest Path Faster Algorithm) is a fast and simple algorithm (single source) that its complexity is not calculated yet. But if m = O(n2) it's better to use the first implementation of Dijkstra.\n\nThe origin of this algorithm is unknown. It's said that at first Chinese coders used it in programming contests.\n\nIts code looks like the combination of Dijkstra and BFS :\n\\begin{verbatim}\nSPFA(v):\n\td[i] = inf for each vertex i\n\td[v] = 0\n\tqueue q\n\tq.push(v)\n\twhile q is not empty\n\t\tu = q.front()\n\t\tq.pop()\n\t\tfor each i in adj[u]\n\t\t\tif d[i] > d[u] + w(u,i)\n\t\t\t\tthen d[i] = d[u] + w(u,i)\n\t\t\t\tif i is not in q\n                    then q.push(i)\n\\end{verbatim}\nTime complexity : Unknown!.\n\\subsection{MST}\nMST = Minimum Spanning Tree :) (if you don't know what it is, google it).\n\nBest MST algorithms :\n\\subsubsection{Kruskal}\nIn this algorithm, first we sort the edges in ascending order of their weight in an array of edges.\n\nThen in order of the sorted array, we add ech edge if and only if after adding it there won't be any cycle (check it using DSU).\n\nCode :\n\\begin{verbatim}\nKruskal()\n\tsolve all edges in ascending order of their weight in an array e\n\tans = 0\n\tfor i = 1 to m\n\t\tv = e.first\n\t\tu = e.second\n\t\tw = e.weight\n\t\tif merge(v,u) // there will be no cycle\n            then ans += w\n\\end{verbatim}\nTime complexity : $O(m\\log{m})$.\n\\subsubsection{Prim}\nIn this approach, we act like Dijkstra. We have a set of vertices S, in each step we add the nearest vertex to S, in S (distance of v from $S = \\min_{u \\in S}(weight(u,v))$ where weight(i, j) is the weight of the edge from i to j) .\n\nSo, pseudo code will be like this:\n\\begin{verbatim}\nPrim()\n\tS = new empty set\n\tfor i = 1 to n\n\t\td[i] = inf\n\twhile S.size() < n\n\t\tx = inf\n\t\tv = -1\n\t\tfor each i in V - S // V is the set of vertices\n\t\t\tif x >= d[v]\n\t\t\t\tthen x = d[v], v = i\n\t\td[v] = 0\n\t\tS.insert(v)\n\t\tfor each u in adj[v]\n            do d[u] = min(d[u], w(v,u))\n\\end{verbatim}\nC++ code:\nOne) $O(n^2)$\n\\begin{verbatim}\nbool mark[MAXN];\nvoid prim(){\n\tfill(d, d + n, inf);\n\tfill(mark, mark + n, false);\n\tint x,v;\n\twhile(true){\n\t\tx = inf;\n\t\tv = -1;\n\t\tfor(int i = 0;i < n;i ++)\n\t\t\tif(!mark[i] and x >= d[i])\n\t\t\t\tx = d[i], v = i;\n\t\tif(v == -1)\n\t\t\tbreak;\n\t\td[v] = 0;\n\t\tmark[v] = true;\n\t\tfor(auto p : adj[v]){ //adj[v][i] = pair(vertex, weight)\n\t\t\tint u = p.first, w = p.second;\n\t\t\td[u] = min(d[u], w);\n\t\t}\n\t}\n}\n\\end{verbatim}\nTwo) $O(m\\log{n})$\n\\begin{verbatim}\nvoid prim(){\n\tfill(d, d + n, inf);\n\tset<pair<int,int> > s;\n\tfor(int i = 0;i < n;i ++)\n\t\ts.insert({d[i],i});\n\tint v;\n\twhile(!s.empty()){\n\t\tv = s.begin() -> second;\n\t\ts.erase(s.begin());\n\t\tfor(auto p : adj[v]){\n\t\t\tint u = p.first, w = p.second;\n\t\t\tif(d[u] > w){\n\t\t\t\ts.erase({d[u], u});\n\t\t\t\td[u] = w;\n\t\t\t\ts.insert({d[u], u});\n\t\t\t}\n\t\t}\n\t}\n}\n\\end{verbatim}\nAs Dijkstra you can use std :: priority$\\_$queue instead of std :: set.\n\n\\subsection{Maximum Flow}\nI only wanna put the source code here (EdmondsKarp):\n\\begin{verbatim}\nalgorithm EdmondsKarp\n    input:\n        C[1..n, 1..n] (Capacity matrix)\n        E[1..n, 1..?] (Neighbour lists)\n        s             (Source)\n        t             (Sink)\n    output:\n        f             (Value of maximum flow)\n        F             (A matrix giving a legal flow with the maximum value)\n    f := 0 (Initial flow is zero)\n    F := array(1..n, 1..n) (Residual capacity from u to v is C[u,v] - F[u,v])\n    forever\n        m, P := BreadthFirstSearch(C, E, s, t, F)\n        if m = 0\n            break\n        f := f + m\n        (Backtrack search, and write flow)\n        v := t\n        while v ≠ s\n            u := P[v]\n            F[u,v] := F[u,v] + m\n            F[v,u] := F[v,u] - m\n            v := u\n    return (f, F)\n\t\n\t\n\t\nalgorithm BreadthFirstSearch\n    input:\n        C, E, s, t, F\n    output:\n        M[t]          (Capacity of path found)\n        P             (Parent table)\n    P := array(1..n)\n    for u in 1..n\n        P[u] := -1\n    P[s] := -2 (make sure source is not rediscovered)\n    M := array(1..n) (Capacity of found path to node)\n    M[s] := ∞\n    Q := queue()\n    Q.offer(s)\n    while Q.size() > 0\n        u := Q.poll()\n        for v in E[u]\n            (If there is available capacity, and v is not seen before in search)\n            if C[u,v] - F[u,v] > 0 and P[v] = -1\n                P[v] := u\n                M[v] := min(M[u], C[u,v] - F[u,v])\n                if v ≠ t\n                    Q.offer(v)\n                else\n                    return M[t], P\n    return 0, P\n\\end{verbatim}\n\t\nEdmondsKarp pseudo code using Adjacency nodes:\n\\begin{verbatim}\nalgorithm EdmondsKarp\n    input:\n        graph (Graph with list of Adjacency nodes with capacities,flow,reverse and destinations)\n        s             (Source)\n        t             (Sink)\n    output:\n        flow             (Value of maximum flow)\n    flow := 0 (Initial flow to zero)\n    q := array(1..n) (Initialize q to graph length)\n    while true\n        qt := 0            (Variable to iterate over all the corresponding edges for a source)\n        q[qt++] := s    (initialize source array)\n        pred := array(q.length)    (Initialize predecessor List with the graph length)\n        for qh=0;qh < qt && pred[t] == null\n            cur := q[qh]\n            for (graph[cur]) (Iterate over list of Edges)\n                 Edge[] e :=  graph[cur]  (Each edge should be associated with Capacity)\n                 if pred[e.t] == null && e.cap > e.f\n                    pred[e.t] := e\n                    q[qt++] : = e.t\n        if pred[t] == null\n            break\n        int df := MAX VALUE (Initialize to max integer value)\n        for u = t; u != s; u = pred[u].s\n            df := min(df, pred[u].cap - pred[u].f)\n        for u = t; u != s; u = pred[u].s\n            pred[u].f  := pred[u].f + df\n            pEdge := array(PredEdge)\n            pEdge := graph[pred[u].t]\n            pEdge[pred[u].rev].f := pEdge[pred[u].rev].f - df;\n        flow := flow + df\n    return flow\n\\end{verbatim}\n\\subsubsection{Dinic's algorithm}\nHere is Dinic's algorithm as you wanted.\n\nInput: A network G = ((V, E), c, s, t).\n\nOutput: A max s - t flow.\n\n1.set f(e) = 0 for each e in E\n\n2.Construct G$\\_$L from G$\\_$f of G. if dist(t) == inf, then stop and output f \n\n3.Find a blocking flow fp in G$\\_$L\n\n4.Augment flow f by fp  and go back to step 2.\n\nTime complexity : $O(mm\\log{n})$.\n\nTheorem: Maximum flow = minimum cut.\n\n\\subsubsection{Maximum Matching in bipartite graphs}\nMaximum matching in bipartite graphs is solvable also by maximum flow like below :\n\nAdd two vertices S, T to the graph, every edge from X to Y (graph parts) has capacity 1, add an edge from S with capacity 1 to every vertex in X, add an edge from every vertex in Y with capacity 1 to T.\n\nFinally, answer = maximum matching from S to T .\n\nBut it can be done really easier using DFS.\n\nAs, you know, a bipartite matching is the maximum matching if and only if there is no augmenting path (read Introduction to graph theory).\n\nThe code below finds a augmenting path:\n\\begin{verbatim}\nbool dfs(int v){// v is in X, it reaturns true if and only if there is an augmenting path starting from v\n\tif(mark[v])\n\t\treturn false;\n\tmark[v] = true;\n\tfor(auto &u : adj[v])\n\t\tif(match[u] == -1 or dfs(match[u])) // match[i] = the vertex i is matched with in the current matching, initially -1\n\t\t\treturn match[v] = u, match[u] = v, true;\n\treturn false;\n}\n\\end{verbatim}\nAn easy way to solve the problem is:\n\\begin{verbatim}\nfor(int i = 0;i < n;i ++)if(match[i] == -1){\n\tmemset(mark, false, sizeof mark);\n\tdfs(i);\n}\n\\end{verbatim}\nBut there is a faster way:\n\\begin{verbatim}\nwhile(true){\n\tmemset(mark, false, sizeof mark);\n\tbool fnd = false;\n\tfor(int i = 0;i < n;i ++) if(match[i] == -1 && !mark[i])\n\t\tfnd |= dfs(i);\n\tif(!fnd)\n\t\tbreak;\n}\n\\end{verbatim}\nIn both cases, time complexity = $O(nm)$.\n\n\\subsection{Trees}\nTrees are the most important graphs.\n\nIn the last lectures we talked about segment trees on trees and heavy-light decomposition.\n\n\\subsubsection{Partial sum on trees}\nWe can also use partial sum on trees.\n\nExample: Having a rooted tree, each vertex has a value (initially 0), each query gives you numbers v and u (v is an ancestor of u) and asks you to increase the value of all vertices in the path from u to v by 1.\n\nSo, we have an array p, and for each query, we increase p[u] by 1 and decrease p[par[v]] by 1. The we run this (like a normal partial sum):\n\\begin{verbatim}\nvoid dfs(int v){\n\tfor(auto u : adj[v])\n\t\tif(u - par[v])\n\t\t\tdfs(u), p[v] += p[u];\n}\n\\end{verbatim}\n\\subsubsection{DSU on trees}\nWe can use DSU on a rooted tree (not tree DSUs, DSUs like vectors).\n\nFor example, in each node, we have a vector, all nodes in its subtree (this can be used only for offline queries, because we may have to delete it for memory usage).\n\nHere again we use DSU technique, we will have a vector V for every node. When we want to have V[v] we should merge the vectors of its children. I mean if its children are u1, u2, ..., uk where V[u1].size() ≤ V[u2].size() ≤ ... ≤ V[uk].size(), we will put all elements from V[ui] for every 1 ≤ i < k, in V[k] and then, V[v] = V[uk].\n\nUsing this trick, time complexity will be .\n\nC++ example (it's a little complicated) :\n\\begin{verbatim}\ntypedef vector<int> vi;\nvi *V[MAXN];\nvoid dfs(int v, int par = -1){\n\tint mx = 0, chl = -1;\n\tfor(auto u : adj[v])if(par - u){\n\t\tdfs(u,v);\n\t\tif(mx < V[u]->size()){\n\t\t\tmx = V[u]->size();\n\t\t\tchl = u;\n\t\t}\n\t}\n\tfor(auto u : adj[v])if(par - u and chl - u){\n\t\tfor(auto a : *V[u])\n\t\t\tV[chl]->push_back(a);\n\t\tdelete V[u];\n\t}\n\tif(chl + 1)\n\t\tV[v] = V[chl];\n\telse{\n\t\tV[v] = new vi;\n\t\tV[v]->push_back(v);\n\t}\n}\n\\end{verbatim}\n\\subsubsection{LCA}\nLCA of two vertices in a rooted tree, is their lowest common ancestor.\n\nThere are so many algorithms for this, I will discuss the important ones.\n\nEach algorithm has complexities  < O(f(n)), O(g(n)) > , it means that this algorithm's preprocess is O(f(n)) and answering a query is O(g(n)) .\n\nIn all algorithms, h[v] =  height of vertex v.\nOne) Brute force  < O(n), O(n) > \n\nThe simplest approach. We go up enough to achieve the goal.\n\nPreproccess :\n\\begin{verbatim}\nvoid dfs(int v,int p = -1){\n\tif(par + 1)\n\t\th[v] = h[p] + 1;\n\tpar[v] = p;\n\tfor(auto u : adj[v])\tif(p - u)\n\t\tdfs(u,v);\n}\n\\end{verbatim}\nQuery :\n\\begin{verbatim}\nint LCA(int v,int u){\n\tif(v == u)\n\t\treturn v;\n\tif(h[v] < h[u])\n\t\tswap(v,u);\n\treturn LCA(par[v], u);\n}\n\\end{verbatim}\nTwo) SQRT decomposition \n\nI talked about SQRT decomposition in the first lecture.\n\nHere, we will cut the tree into $\\sqrt{H}$ (H = height of the tree), starting from 0, k - th of them contains all vertices with h in interval $[k\\sqrt{H},(k+1)\\sqrt{H}]$.\n\nAlso, for each vertex v in k - th piece, we store r[v] that is, its lowest ancestor in the piece number k - 1.\n\nPreprocess:\n\\begin{verbatim}\nvoid dfs(int v,int p = -1){\n\tif(par + 1)\n\t\th[v] = h[p] + 1;\n\tpar[v] = p;\n\tif(h[v] % SQRT == 0)\n\t\tr[v] = p;\n\telse\n\t\tr[v] = r[p];\n\tfor(auto u : adj[v])\tif(p - u)\n\t\tdfs(u,v);\n}\n\\end{verbatim}\nQuery:\n\\begin{verbatim}\nint LCA(int v,int u){\n\tif(v == u)\n\t\treturn v;\n\tif(h[v] < h[u])\n\t\tswap(v,u);\n\tif(h[v] == h[u])\n\t\treturn (r[v] == r[u] ? LCA(par[v], par[u]) : LCA(r[v], r[u]));\n\tif(h[v] - h[u] < SQRT)\n\t\treturn LCA(par[v], u);\n\treturn LCA(r[v], u);\n}\n\\end{verbatim}\nThree) Sparse table <$O(n\\log{n})$, $O(1)$>\n\nLet's introduce you an order of tree vertices, haas and I named it Euler order. It is like DFS order, but every time we enter a vertex, we write it's number down (even when we come from a child to this node in DFS).\n\nCode for calculate this :\n\\begin{verbatim}\nvector<int> euler;\nvoid dfs(int v,int p = -1){\n\teuler.push_back(v);\n\tfor(auto u : adj[v])\tif(p - u)\n\t\tdfs(u,v), euler.push_back(v);\n}\n\\end{verbatim}\nIf we have a vector<pair<int,int> > instead of this and push {h[v], v} in the vector, and the first time {h[v], v} is appeared is s[v] and s[v] < s[u] then LCA(v, u) = ($min_{i = s[v]}^{s[u]}euler[i]$).second.\n\nFor this propose we can use RMQ problem, and the best algorithm for that, is to use Sparse table.\n\nFour) Something like Sparse table :) <$O(n\\log{n})$,$O(\\log{n})$>\n\nThis is the most useful and simple (among fast algorithms) algorithm.\n\nFor each vector v and number i, we store its $2^i$-th ancestor. This can be done in $O(n\\log{n})$. Then, for each query, we find the lowest ancestors of them which are in the same height, but different (read the source code for understanding).\n\nPreprocess:\n\\begin{verbatim}\nint par[MAXN][MAXLOG]; // initially all -1\nvoid dfs(int v,int p = -1){\n\tpar[v][0] = p;\n\tif(p + 1)\n\t\th[v] = h[p] + 1;\n\tfor(int i = 1;i < MAXLOG;i ++)\n\t\tif(par[v][i-1] + 1)\n\t\t\tpar[v][i] = par[par[v][i-1]][i-1];\n\tfor(auto u : adj[v])\tif(p - u)\n\t\tdfs(u,v);\n}\n\\end{verbatim}\nQuery:\n\\begin{verbatim}\nint LCA(int v,int u){\n\tif(h[v] < h[u])\n\t\tswap(v,u);\n\tfor(int i = MAXLOG - 1;i >= 0;i --)\n\t\tif(par[v][i] + 1 and h[par[v][i]] >= h[u])\n\t\t\tv = par[v][i];\n\t// now h[v] = h[u]\n\tif(v == u)\n\t\treturn v;\n\tfor(int i = MAXLOG - 1;i >= 0;i --)\n\t\tif(par[v][i] - par[u][i])\n\t\t\tv = par[v][i], u = par[u][i];\n\treturn par[v][0];\n}\n\\end{verbatim}\n\nFive) Advance RMQ  < O(n), O(1) > \n\nIn the third approach, we said that LCA can be solved by RMQ.\n\nWhen you look at the vector euler you see that for each i that 1 ≤ i < euler.size(), |euler[i].first - euler[i + 1].first| = 1.\n\nSo, we can convert the euler from its size(we consider its size is n + 1) into a binary sequence of length n (if euler[i].first - euler[i + 1].first = 1 we put 1 otherwise 0).\n\nSo, we have to solve the problem on a binary sequence A .\n\nTo solve this restricted version of the problem we need to partition A into blocks of size . Let A'[i] be the minimum value for the i - th block in A and B[i] be the position of this minimum value in A. Both A and B are  long. Now, we preprocess A' using the Sparse Table algorithm described in lecture 1. This will take  time and space. After this preprocessing we can make queries that span over several blocks in O(1). It remains now to show how the in-block queries can be made. Note that the length of a block is , which is quite small. Also, note that A is a binary array. The total number of binary arrays of size l is . So, for each binary block of size l we need to lock up in a table P the value for RMQ between every pair of indices. This can be trivially computed in  time and space. To index table P, preprocess the type of each block in A and store it in array . The block type is a binary number obtained by replacing  - 1 with 0 and  + 1 with 1 (as described above).\n\nNow, to answer RMQA(i, j) we have two cases:\n\ni and j are in the same block, so we use the value computed in P and T\n\ni and j are in different blocks, so we compute three values: the minimum from i to the end of i's block using P and T, the minimum of all blocks between i's and j's block using precomputed queries on A' and the minimum from the beginning of j's block to j, again using T and P; finally return the position where the overall minimum is using the three values you just computed.\n\nSix) Tarjan's algorithm O(na(n)) (a(n) is the inverse ackermann function)\n\nTarjan's algorithm is offline; that is, unlike other lowest common ancestor algorithms, it requires that all pairs of nodes for which the lowest common ancestor is desired must be specified in advance. The simplest version of the algorithm uses the union-find data structure, which unlike other lowest common ancestor data structures can take more than constant time per operation when the number of pairs of nodes is similar in magnitude to the number of nodes. A later refinement by Gabow $\\&$ Tarjan (1983) speeds the algorithm up to linear time.\n\nThe pseudocode below determines the lowest common ancestor of each pair in P, given the root r of a tree in which the children of node n are in the set n.children. For this offline algorithm, the set P must be specified in advance. It uses the MakeSet, Find, and Union functions of a disjoint-set forest. MakeSet(u) removes u to a singleton set, Find(u) returns the standard representative of the set containing u, and Union(u, v) merges the set containing u with the set containing v. TarjanOLCA(r) is first called on the root r.\n\\begin{verbatim}\n function TarjanOLCA(u)\n     MakeSet(u);\n     u.ancestor := u;\n     for each v in u.children do\n         TarjanOLCA(v);\n         Union(u,v);\n         Find(u).ancestor := u;\n     u.colour := black;\n     for each v such that {u,v} in P do\n         if v.colour == black\n             print \"Tarjan's Lowest Common Ancestor of \" + u +\n                   \" and \" + v + \" is \" + Find(v).ancestor + \".\";\n\\end{verbatim}\nEach node is initially white, and is colored black after it and all its children have been visited. The lowest common ancestor of the pair {u, v} is available as Find(v).ancestor immediately (and only immediately) after u is colored black, provided v is already black. Otherwise, it will be available later as Find(u).ancestor, immediately after v is colored black.\n\\begin{verbatim}\n function MakeSet(x)\n     x.parent := x\n     x.rank   := 0\n \n function Union(x, y)\n     xRoot := Find(x)\n     yRoot := Find(y)\n     if xRoot.rank > yRoot.rank\n         yRoot.parent := xRoot\n     else if xRoot.rank < yRoot.rank\n         xRoot.parent := yRoot\n     else if xRoot != yRoot\n         yRoot.parent := xRoot\n         xRoot.rank := xRoot.rank + 1\n  \n function Find(x)\n     if x.parent == x\n        return x\n     else\n        x.parent := Find(x.parent)\n        return x.parent\n\\end{verbatim}\n", "meta": {"hexsha": "693fe654960087536480cd602ef1ed45e5051ee9", "size": 26527, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ga.tex", "max_stars_repo_name": "Abreto/acm-icpc-template", "max_stars_repo_head_hexsha": "43552abf6d03aa5958dfca785aa538548a0e563b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ga.tex", "max_issues_repo_name": "Abreto/acm-icpc-template", "max_issues_repo_head_hexsha": "43552abf6d03aa5958dfca785aa538548a0e563b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ga.tex", "max_forks_repo_name": "Abreto/acm-icpc-template", "max_forks_repo_head_hexsha": "43552abf6d03aa5958dfca785aa538548a0e563b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.9219948849, "max_line_length": 982, "alphanum_fraction": 0.6049685226, "num_tokens": 7808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.7249875218760932}}
{"text": "\\subsection{Ordering of the integers}\n\n\\subsubsection{Ordering integers}\n\nIntegers are an ordered pair of naturals.\n\n\\(\\{\\{x\\},\\{x,y\\}\\}\\)\n\nFor example \\(-4\\) can be:\n\n\\(\\{\\{4\\},\\{4,8\\}\\}\\)\n\n\\(\\{\\{0\\},\\{0,8\\}\\}\\)\n\nWe extend the ordering to say:\n\n\\(\\{\\{x\\},\\{x,y\\}\\}\\le \\{\\{s(x)\\},\\{s(x),y\\}\\}\\)\n\n\\(\\{\\{x\\},\\{x,s(y)\\}\\}\\le \\{\\{x\\},\\{x,y\\}\\}\\)\n\nSo can we define this on an arbitrary pair:\n\n\\(\\{\\{a\\},\\{a,b\\}\\}\\le \\{\\{c\\},\\{c,d\\}\\}\\)\n\nWe know that:\n\n\\(\\{\\{a\\},\\{a,b\\}\\}=\\{\\{s(a)\\},\\{s(a),s(b)\\}\\}\\)\n\nAnd either of:\n\n\\(\\{\\{a\\},\\{a,b\\}\\}=\\{\\{0\\},\\{0,A\\}\\}\\)\n\n\\(\\{\\{a\\},\\{a,b\\}\\}=\\{\\{B\\},\\{B,0\\}\\}\\)\n\n\\(\\{\\{a\\},\\{a,b\\}\\}=\\{\\{0\\},\\{0,0\\}\\}\\)\n\nAs the latter is a case of either of the other \\(2\\), we consider only the first \\(2\\).\n\nSo we can define:\n\n\\(\\{\\{a\\},\\{a,b\\}\\}\\le \\{\\{c\\},\\{c,d\\}\\}\\)\n\nAs any of:\n\n\\(1: \\{\\{0\\},\\{0,A\\}\\}\\le \\{\\{0\\},\\{0,C\\}\\}\\)\n\n\\(2: \\{\\{0\\},\\{0,A\\}\\}\\le \\{\\{D\\},\\{D,0\\}\\}\\)\n\n\\(3: \\{\\{B\\},\\{B,0\\}\\}\\le \\{\\{0\\},\\{0,C\\}\\}\\)\n\n\\(4: \\{\\{B\\},\\{B,0\\}\\}\\le \\{\\{D\\},\\{D,0\\}\\}\\)\n\nCase 1:\n\n\\(\\{\\{0\\},\\{0,A\\}\\}\\le \\{\\{0\\},\\{0,C\\}\\}\\)\n\nTrivial, depends on relative size of \\(A\\) and \\(C\\).\n\nCase 2:\n\n\\(\\{\\{0\\},\\{0,A\\}\\}\\le \\{\\{D\\},\\{D,0\\}\\}\\)\n\nWe can see that:\n\n\\(\\{\\{D\\},\\{D,A\\}\\}\\le \\{\\{D\\},\\{D,0\\}\\}\\)\n\nAnd therefore this holds.\n\nCase 3:\n\n\\(\\{\\{B\\},\\{B,0\\}\\}\\le \\{\\{0\\},\\{0,C\\}\\}\\)\n\nWe can see that:\n\n\\(\\{\\{B\\},\\{B,0\\}\\}\\le \\{\\{B\\},\\{B,C\\}\\}\\)\n\nAnd therefore this does not hold.\n\nCase 4:\n\n\\(\\{\\{B\\},\\{B,0\\}\\}\\le \\{\\{D\\},\\{D,0\\}\\}\\)\n\nTrivial, like case 1.\n\n", "meta": {"hexsha": "2f4583dab7313cfeab54f22a0d34e67e9dc59fca", "size": 1464, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/integers/01-02-integersOrdering.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/integers/01-02-integersOrdering.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/integers/01-02-integersOrdering.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.2235294118, "max_line_length": 87, "alphanum_fraction": 0.387295082, "num_tokens": 749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7249875143881056}}
{"text": "\\chapter{Proofs}\n\\label{chapter:proofs}\n\\section{Direct Proofs}\n\\marginurl{%\n    What is a Mathematical Proof:\\\\\\noindent\n    Introduction to Mathematical Reasoning \\#1\n}{youtu.be/eJD0gGqveIE}\n\nWe start the discussion of the proofs in mathematics from an example of a proof\nin ``everyday'' life. Assume that we know that the following statements are\ntrue.\n\\begin{enumerate}\n    \\item If a salmon has fins and scales it is kosher,\n    \\item if a salmon has scales it has fins,\n    \\item any salmon has scales.\n\\end{enumerate}\nUsing these facts we may conclude that any salmon is kosher; indeed, any salmon\nhas scales by the third statement, hence, by the second statement any salmon has\nfins, finally, by the first statement any salmon is kosher since it has fins and\nscales.\n\nOne may notice that this explanation is a sequence of conclusions such that\neach of them is true because the previous one is true.\nMathematical proof is also a sequence of statements such that every statement\nis true if the previous statement is true. If $P$ and $Q$ are some statements\nand $Q$ is always true when $P$ is true, then we say that $P$ implies $Q$.\nWe denote the statement that $P$ implies $Q$ by $P \\implies Q$.\n\n\\nomenclature[L]{$P \\implies Q$}{denotes the statement saying that\nif $P$ is true, then $Q$ is true as well}\n\n\nIn order to define the implication formally let us consider the following table.\n\\begin{center}\n  \\begin{tabular}{ l l l }\n      \\toprule\n      $P$ & $Q$ & $P \\implies Q$ \\\\\n      \\midrule\n      T   & T   & T \\\\\n      T   & F   & F \\\\\n      F   & T   & T \\\\\n      F   & F   & T \\\\\n      \\bottomrule\n  \\end{tabular}\n\\end{center}\nLet $P$ and $Q$ be some statements. Then this table says that if $P$ and $Q$\nare both false, then $P \\implies Q$ is true etc.\n\n\\begin{exercise}\n  Let $n$ be an integer.\n  \\begin{enumerate}\n    \\item Is it always true that ``$n^2$ is positive''\n      implies ``$n$ is not equal to $0$''?\n    \\item Is it always true that ``$n^2 - n - 2$ is equal to $0$'' implies\n      ``$n$ is equal to $2$''?\n  \\end{enumerate}\n\\end{exercise}\nIn the example we gave at the beginning of the section we used some\n\\emph{known} facts. But what does it mean to know something? In math we\ntypically say that we know a statement if we can prove it. But in order to prove\nthis statement we need to know something again, which is a problem! In order to\nsolve it, mathematicians introduced the notion of an \\emph{axiom}.\nAn axiom is a statement that is believed to be true and when we prove a statement\nwe prove it under the assumption that these axioms are true\\footnote{Note that\nin different parts of mathematics axioms may be different.}.\n\nFor example, we may consider axioms of inequalities for real numbers.\n\\begin{enumerate}\n  \\item Let $a$ and $b$ be real numbers. Only one of the following is true:\n    \\begin{itemize}\n      \\item $a < b$,\n      \\item $b < a$, or\n      \\item $a = b$.\n    \\end{itemize}\n  \\item Let $a$, $b$, and $c$ be real numbers. Then $a < b$ iff $a + c < b + c$\n    (iff is an abbreviation for ``if and only if'').\n  \\item Let $a$, $b$, and $c$ be real numbers. Then $a < b$ iff $ac < bc$\n    provided that $c > 0$ and $a < b$ iff $ac > bc$ if $c < 0$.\n  \\item Let $a$, $b$, $c$ be real numbers. If $a < b$ and $b < c$, then $a < c$.\n\\end{enumerate}\n\n\\marginurl{%\n  What We Know and How to Find a Proof:\\\\\\noindent\n  Introduction to Mathematical Reasoning \\#2\n}{youtu.be/nBjJi6aTk2M}\n\n\nLet us now try to prove something using these axioms, we prove that if $a > 0$,\nthen $a^2 > 0$. Note that $a > 0$, hence, by the third axiom $a^2 > 0$\n(note that we also used an additional statement saying that $0 \\cdot 0 = 0$).\n\nSimilarly, we may prove that if $a < 0$, then $a^2 > 0$. And combining these\ntwo statements together we may prove that if $a \\neq 0$, then $a^2 > 0$.\n\nProofs like this are called direct proofs.\n\n\\begin{exercise}\n  Consider another set of axioms; these axioms describe some objects that look\n  like geometrical obejects, so they are called axioms of four-point geometry.\n\n  These aximoms are using three undefined terms: ``point'', ``line'', and ``is\n  on''. The axioms are the following statements.\n  \\begin{itemize}\n    \\item For every pair of distinct points $x$ and $y$, there is a unique line\n      $\\ell$ such that x is on l and y is on l.\n    \\item Given a line $\\ell$ and a point $x$ that is not on $\\ell$, there is a\n      unique line $m$ such that $x$ is on $m$ and no point on $\\ell$ is also on\n      $m$.\n    \\item There are exactly four points.\n    \\item It is impossible for three points to be on the same line.\n  \\end{itemize}\n\n  Prove (using these axioms) that there are at least two distinct lines.\n\\end{exercise}\n\nLet $n$ and $m$ be some integers. Using direct proofs we may prove the\nfollowing two statements.\n\\begin{itemize}\n  \\item if $n$ is even, then $nm$ is also even (a number $\\ell$ is even\n    if there is an integer $k$ such that $\\ell = 2k$),\n  \\item if $n$ is even and $m$ is even, then $n + m$ is also even.\n\\end{itemize}\n\nWe start from proving the first statement. There is an integer $k$ such that\n$n = 2k$ since $n$ is even. As a result, $nm = 2 (nk)$ so $nm$ is even.\n\nNow we prove the second statement. Since $n$ and $m$ are even there are $k$ and\n$\\ell$ such that $n = 2k$ and $m = 2\\ell$. Hence, $n + m = 2 (k + \\ell)$ so\n$n + m$ is even.\n\n\\section{Constructing Proofs Backwards}\nHowever, sometimes it is not easy to find the proof. In this case one of the\npossible methods to deal with this problem is to try to prove starting from\nthe end.\n\nFor example, we may consider the statement $(a + b)^2 = a^2 + 2ba + b^2$.\nImagine, for a second, that you have not learned about axioms.\nIn this case you would write something like this:\n\\begin{multline*}\n    (a + b)^2 = (a + b) \\cdot (a + b) = \\\\\n    a (a + b) + b (a + b) = \\\\\n    a^2 + ab + ba + b^2 = a^2 + 2ba + b^2.\n\\end{multline*}\n\nLet us try to prove it completely formally using the following axioms.\n\\begin{enumerate}\n  \\item Let $a$, $b$, and $c$ be real number. If $a = b$ and $b = c$, then $a =\n    c$.\n  \\item Let $a$, $b$, and $c$ be real numbers. If $a = b$, then $a + c = b + c$\n    and $c + a = c + b$.\n  \\item Let $a$, $b$, and $c$ be real numbers. Then $a (b + c) = ab + ac$.\n  \\item Let $a$ and $b$ be real numbers. Then $ab = ba$.\n  \\item Let $a$ and $b$ be real numbers. Then $a + b = b + a$.\n  \\item Let $a$ be a real number. Then $a^2 = a \\cdot a$ and $a \\cdot a = a^2$.\n  \\item Let $a$ be a real number. Then $a + a = 2a$.\n\\end{enumerate}\nSo the formal proof of the statement $(a + b)^2 = a^2 + 2ab + b^2$ is as\nfollows. First note that $(a + b)^2 = (a + b) \\cdot (a + b)$ (by axiom~6),\nhence, by axiom~1, it is enough to show that\n$(a + b) \\cdot (a + b) = a^2 + 2ab + b^2$. By axiom~3,\n$(a + b) \\cdot (a + b) = (a + b) \\cdot a + (a + b) \\cdot b$. Axiom~4 implies\nthat $(a + b) \\cdot a = a \\cdot (a + b)$ and $(a + b) \\cdot b = b \\cdot (a + b)$\nHence, by axioms~1 and~2 applied twice\n\\[\n  a \\cdot (a + b) + b \\cdot (a + b) =\n  (a + b) \\cdot a + b \\cdot (a + b) =\n  (a + b) \\cdot a + (a + b) \\cdot b.\n\\]\nAs a result,\n\\begin{multline*}\n  (a + b) \\cdot (a + b) =\n  (a + b) \\cdot a + (a + b) \\cdot b = \\\\\n  a \\cdot (a + b) + b \\cdot (a + b) =\n  a \\cdot a + a \\cdot b + b \\cdot a + b \\cdot b;\n\\end{multline*}\nso by axiom 1, it is enough\nto show that $a \\cdot a + a \\cdot b + b \\cdot a + b \\cdot b = a^2 + 2ab + b^2$.\nAdditionally, by axiom~6, $a \\cdot a = a^2$ and $b \\cdot b = b^2$. Hence, by\naxiom~2, it is enough to show that\n$a^2 + a \\cdot b + b \\cdot a + b^2 = a^2 + 2ab + b^2$. By axiom~4,\n$a \\cdot b = b \\cdot a$, hence, by axiom~2,\n$a \\cdot b + b \\cdot a = b \\cdot a + b \\cdot a$. Therefore by axiom~7,\n$a \\cdot b + b \\cdot a = 2 b \\cdot a$. Finally, by axiom~2,\n$a \\cdot b + b \\cdot a + a^2 + b^2 = 2b \\cdot a + a^2 + b^2$ and by axiom~5,\n$a \\cdot b + b \\cdot a + a^2 + b^2 = a^2 + a \\cdot b + b \\cdot a + b^2$ and\n$2b \\cdot a + a^2 + b^2 =  a^2 + 2b \\cdot a + b^2$. Which finishes the proof by\naxiom~1.\n\n\\section{Analysis of Simple Algorithms}\n\\label{section:simple-algorithm}\nWe can use this knowledge to analyze simple algorithms. For example, let us\nconsider the following algorithm.\n\\begin{algorithm}\n  \\begin{algorithmic}[1]\n    \\Function{Max}{$a$, $b$, $c$}\n      \\State $r \\gets a$\n      \\If {$b > r$}\n        \\State $r \\gets b$\n      \\EndIf\n\n      \\If {$c > r$}\n        \\State $r \\gets c$\n      \\EndIf\n      \\State \\Return $r$\n    \\EndFunction\n  \\end{algorithmic}\n  \\caption{The algorithm that finds the maximum element of $a$, $b$, $c$.}\n\\end{algorithm}\nWe may prove that it is correct; i.e. it returns the maximum of $a$, $b$, and\n$c$. We need to consider the following cases.\n\\begin{itemize}\n  \\item If the maximum is equal to $a$. In this case, at line~2, we set $r = a$,\n    at line~3 the inequality $b > r$ is false (since $a = r$ is the maximum) and\n    at line~6 the inequality $c > r$ is also false (since $a = r$ is the\n    maximum). Hence, we do not change the value of $r$ after line~2 and\n    the returned value is $a$.\n  \\item If the maximum is equal to $b$. We set $r = a$ at line~2.\n    The inequality $b > r$ at line~3 is true (since $b$ is the maximum) and\n    we set $r$ to be equal to $b$.\n    So at line~6, the inequality $c > r$ is false (since $b = r$ is the\n    maximum). Hence, the returned value is $b$.\n  \\item If the maximum is equal to $c$. We set $r = a$ at line~2.\n    If the inequality $b > r$ is true at line~3 we set $r$ to be equal to $b$.\n    So at line~6 the inequality $c > r$ is true (since $c$ is the\n    maximum). Hence, we set $r$ being equal to $c$ and the returned value is\n    $c$.\n\\end{itemize}\n\n\\section{Proofs in Real-life Mathematics}\nIn this chapter in most of the cases we explicitly used axioms to prove\nstatements. However, the resulting proofs are really long and hard to understand\n(the last example in the previous section is a good example of this phenomenon).\nBecause of this mathematicians tend to skip steps in the proofs when they\nbelieve that they are clear. It is worth to mention a nice quotation of Scott\nAaronson about this problem\n\\begin{displayquote}\n  When mathematicians say that a theorem has been ``proved,'' they still mean,\n  as they always have, something more like: ``we’ve reached a social consensus\n  that all the ideas are now in place for a strictly formal proof that could be\n  verified by a machine \\dots with the only task remaining being massive rote\n  coding work that none of us has any intention of ever doing!''\n\\end{displayquote}\nThis is the reason why it is arduous to read mathematical texts and it\nis very different from reading non-mathematical books.\nA problem that arises because of this tendency is that some mistakes may happen\nif we skip way too many steps. In the last two centuries there were several\nattempts to solve this issue, one approach to this we are going to discuss in\nPart~\\ref{part:logic}.\n\\marginurl{%\n  Death of proof greatly exaggerated\n}{scottaaronson.com/blog/?p=4133}\n\n\n\\begin{chapterendexercises}\n  \\exercise Using the axioms of inequalities show that if $a$ is a non-zero\n    real number, then $a^2 > 0$.\n  \\exercise Using the axioms of inequalities prove that for all real\n    numbers $a$, $b$, and $c$,\n    \\[\n      bc + ac + ab \\le a^2 + b^2 + c^2.\n    \\]\n  \\exercise[recommended] Prove that for all integers $a$, $b$, and $c$,\n    If $a$ divides $b$ and $b$ divides $c$, then $a$ divides $c$.\n    Recall that an integer $m$ divides an integer $n$ if there is an integer\n    $k$ such that $mk = n$.\n  \\exercise[recommended] Show that square of an even integer is even.\n  \\exercise Prove that $0$ divides an integer $a$ iff $a = 0$.\n  \\exercise Using the axioms of inequalities, show that if $a > 0$, $b$, and $c$\n    are real numbers, then $b \\ge c$ implies that $ab \\ge ac$.\n  \\exercise Using the axioms of inequalities, show that if $a, b < 0$ are real\n    numbers, then $a \\le b$ implies that $a^2 \\ge b^2$.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "e3fb463d2d9443d6c5c12422f5cfc1a158f9b884", "size": 11940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_1/chapter_1_proofs.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_1/chapter_1_proofs.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_1/chapter_1_proofs.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 43.7362637363, "max_line_length": 81, "alphanum_fraction": 0.6520938023, "num_tokens": 3838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8128673246376008, "lm_q1q2_score": 0.724924063262111}}
{"text": "%!TEX root = ../CombinatoricsNotes.tex\n\n\\section{Incidence problems}\n\\lect{4}{4}\n% \\marginnote{Lecture X: Monday, April 4, 2016.}\n\\begin{theorem}[Euler's formula]\nLet $G$ be a connected graph drawn in the plane without crossings. Then\n\\[\n|V(G)| - |\\edges (G)| + \\reg (G) =2\n\\]\nwhere $\\reg (G)$ is the number of regions in which the drawing divides the plane.\n\\end{theorem}\n\n\\begin{corollary} \\label{cor:bound_edges_of_planar_3VG}\nLet $G$ be a graph drawn in the plane without crossings. Then\n\\[\n|\\edges (G) |\\leq 3 |V(G)|.\n\\]\n\\end{corollary}\n\\begin{proof}\t\nWe assume $|V(G)|\\geq 3$. By adding additional edges we can ensure that each region of the drawing has a cycle of length 3 as its boundary. Then\n\\[\n3 \\reg(G) = 2 |\\edges (G)|\n\\]\nby double counting pairs (edge, region) such that each edge belongs to two regions boundary. Substituting into Euler's formula, we have \n\\[\n|V(G)| - |\\edges (G)| + \\frac{2}{3}|\\edges (G)| = 2\n\\]\nso\n\\[\n|\\edges (G)| = 3 | V(G)| - 6 \\leq 3 |V(G)|.\n\\]\n\\end{proof}\n\nLet $\\crossings(G)$ denote the minimal number of pairs of crossing edges taken over all drawing of $G$ in the plane  where vertices are represented by points, edges by curves joining corresponding points, and the drawing of edges are allowed to intersect, and each intersection is a \\emph{crossing}\\sidenote{locally looks like an $X$, not two curves bouncing off each other.}.\n\nThen $\\crossings(G)=0$ iff $G$ can be drawn in the plane without crossings, and $\\crossings(K_5)=1$, by the drawing\n\\begin{center}\n\\begin{tikzpicture}\n\n\\end{tikzpicture}\n\\end{center}\n\n\n\\begin{corollary} \\label{cor:bound_crossings_planar_graph93}\n$\\crossings(G) \\geq |\\edges (G)| - 3 |V(G)|$.\n\\end{corollary}\n\\begin{proof}\t\nLet $G$ be a graph with $\\crossings(G) = c$. In a drawing of $G$ with $c$ pairs of crossing edges, remove $c$ edges to obtain a graph drawin without crossings. Then by \\cref{cor:bound_edges_of_planar_3VG},\n\\[\n|\\edges (G)| - c \\leq 3 |V(G)|\n\\]\nas we wanted.\n\\end{proof}\n\n\\begin{theorem}[Crossing number lemma]\n\\label{thm:crossing_number_lemma}\n\n\\[\n\\crossings(G) \\geq \\frac{1}{64}\\frac{m^3}{n^2}\n\\]\nfor every graph $G$ with $m$ edges and $n$ vertices such that $m\\geq 4n$.\n\\end{theorem}\n\\begin{proof}\t\nLet $p \\in [0,1]$ which we will choose later. Let $X\\subset V(G)$ be obtained by choosing to include each vertex independently at random with probability $p$. Let $G'$ be the random subgraph of $G$ induced by $X$, namely $V(G') = X$, $\\edges(G') = \\edges(G| X)$. Let $m = |\\edges(G)|$, $n= |V(G)|$, $x= \\crossings(G)$, $m' = |\\edges(G')|$, $n' = |V(G')|$, $x' = \\crossings(G')$. Then by construction $\\E[n'] = np$. Since each edge of $G$ survives with probability $p^2$, by linearity $\\E[m']= mp^2$. Next, $\\E[x'] \\leq xp^4$ because the probability that a particular pair of crossing edges survives is $p^4$.\n\nBy \\cref{cor:bound_crossings_planar_graph93}, $x'\\geq m' - 3n'$. Taking expectation values, we have the bound $x p^4 \\geq mp^2 - 3np$. That is,\n\\[\nx\\geq \\frac{m}{p^2} - 3 \\frac{n}{p^3}.\n\\]\nNow, we choose optimal $p$:\n\\begin{gather*}\n \\frac{\\partial}{\\partial p} \\left( \\frac{m}{p^2}- \\frac{3n}{ p^3} \\right) = - \\frac{2m}{p^3} + \\frac{9n}{p^4} = 0 \\\\\n \\implies p=\\frac{1}{4.5}\\frac{n}{m}.\n\\end{gather*}\nLet us simply take $p = \\frac{1}{4}\\frac{n}{m}.$ Then\n\\begin{gather*}\n\\crossings (G):=x \\geq \\frac{m}{\\frac{16 n^2}{m^2}} - \\frac{3n}{\\frac{64 n^3}{m^3}}p = \\frac{m^3}{n^2} \\left( \\frac{1}{16} - \\frac{3}{64} \\right) = \\frac{1}{64}\\frac{m^3}{n^2}.\n\\end{gather*}\n\\end{proof}\n\nLet $P$ be a set of points in the plane. Let $L$ be a set of lines. Then define\n\\[\nI(P,L):= |\\{ ( p,L ): p\\in P, l\\in L, p\\in L \\}|.\n\\]\nThen $I(P,L)$ is the number of \\emph{incidences} of $P$ and $L$. Let $I(m,n)$ denote the maximum $I(P,L)$ over sets $P,L$ with $|P| = m$, $|L| = n$. Clearly, $I(m,n)\\leq mn$.\n\\begin{example} We see $I(3,3) \\leq 6$ by considering cases: if the three lines are parallel, the number of incidences is at most three. If two lines are parallel, there are at most five incidences. If none of the lines are parallel, there are at most six incidences. On the other hand, \\cref{fig:I33} shows $I(3,3)\\geq 6$.\n\\begin{marginfigure}\n\\begin{center}\n\\begin{tikzpicture}[scale=.7,rotate=180]\n\\node (x) at (2,0) {$\\bullet$};\n\\node (y) at (1,2) {$\\bullet$};\n\n\\node (z) at (0,0) {$\\bullet$};\n\n% \\node (w) at (1,0) {$w$};\n\n\\draw [shorten >=-1cm,shorten <=-1cm](x) -- (y);\n\\draw[shorten >=-1cm,shorten <=-1cm] (y) -- (z);\n\\draw[shorten >=-1cm,shorten <=-1cm] (z) -- (x);\n\\end{tikzpicture}\n\\vspace{1em}\n\\end{center}\n\\caption{We see $I(3,3)\\geq 6$.} \\label{fig:I33}\n\\end{marginfigure}\n\\end{example}\n\n\n\n\n\\begin{example}\nLet $n=4k^3$. Set\n\\[\nP = \\{ (x,y): 0\\leq x \\leq k-1, 0 \\leq y\\leq 4k^2 - 1, x,y\\in \\Z\\}\n\\]\nand \n\\[\nL = \\{ y = ax+b: 0\\leq a \\leq 2k-1, 0\\leq b\\leq 2k^2-1, a,b\\in \\Z \\}\n\\]\nThen $|P| = |L| =n$. We have $I(P,L)= k \\cdot |L|  = kn \\geq \\frac{1}{2}n^{4/3}$\n\nevery line in $L$ incident with $k$ points in $P$.\n\n\n\n\\begin{gather*}\n(x,ax+b)\\in P \\\\\n\\text{for } 0\\leq x \\leq k-1, 0\\leq a \\leq 2k-1, 0\\leq b \\leq 2k^2- 1\n\\end{gather*}\n$ax+b \\leq (k-1)(2k-1) + 2k^2 - 1 < 4k^2$. So $I(n,n) \\geq c n^{4/3}$ for all $n$ and some $c>0$.\n\\end{example}\n\n\\begin{theorem}[\\cite{Szemeredi-Trotter1983}] \\label{thm:bound_I_m_n95} \\label{thm:Szemerdi_Trotter}\n\\[\nI(m,n) \\leq 4 m^{2/3} n^{2/3} + 4m + n.\n\\]\n\\end{theorem}\n\n\\begin{proof}\t\nLet $P,L$ be sets of points and lines such that $|P| = m$, $|L| = n$ and $I(P,L) = I(n,m)$. Let $G$ be a graph drawn in the plane with crossings such that $V(G)  = P$, and $\\edges(G)$ are drawn as line segments joining consecutive points on lines in $L$. \\marginnote{I.e., follow one line at a time, connecting consecutive points.}\nThen\n\\[\n\\crossings(G)\\leq n^2\n\\]\nbecause every crossing in $G$ is an intersection of two lines in $L$ (loose estimate). Then\n\\[\nI:=I(P,L) = |\\edges(G)| + n\n\\]\nif there is a point of $P$ on every line in $L$ (if not, delete that line). We see this by following each line in $L$, and noting between every two incidences, we have an edge: if there are $k$ points in $P$ on a single line, there are $k-1$ edges connecting them.\n\nThen $|\\edges(G)| = I -n$. We have $|\\edges(G)|\\leq 4 |V(G)|$ if $I - n \\leq 4m$, that is $I\\leq 4m + n$.\n\nOtherwise,  by \\cref{thm:crossing_number_lemma},\n\\[\nn^2 \\geq \\crossings (G) \\geq \\frac{1}{64} \\frac{|\\edges(G)|^3}{|V(G)|^2} = \\frac{1}{64} \\frac{(I-n)^3}{m^2}.\n\\]\nThat is, \n\\begin{gather*}\n64 m^2 n^2 \\geq (I-n)^3\\\\\n4 m^{2/3} n^{2/3}\\geq I- n\\\\\nI \\leq 4m^{2/3}n^{2/3}+n.\\qedhere\n\\end{gather*}\n\\end{proof}\n\n\\begin{conjecture*}[\\cite{Erdos-Szemeredi-1983}]\nFor every $\\epsilon>0$ there exists $c_{\\epsilon} > 0$ s.t. for every $A\\subset \\Z$,\n\\[\n|A+A| + |A\\cdot A| \\geq c_{\\epsilon} |A|^{2 - \\epsilon},\n\\]\nwhere $A+A = \\{a+b: a,b\\in A\\}$ and $A\\cdot A = \\{a\\cdot b: a,b\\in A\\}$.\n\\end{conjecture*}\n\n\n\\begin{theorem}[\\cite{elekes1997number}] \\label{thm:96_elekes}\nThere exists $c>0$ such that for every $A\\subset \\Z$, \n\\[\n|A+A|\\cdot |A\\cdot A| \\geq c |A|^{5/2}.\n\\]\nIn particular, by the arithmetic-geometric inequality,\n\\[\n|A+A| + |A\\cdot A| \\geq c |A|^{5/4}.\n\\]\n\\end{theorem}\n\\begin{proof}\t\nLet \n\\[\n P = \\{(a,b):a \\in A+A, b\\in A\\cdot A\\}.\n \\] Then $|P| =|A+A|\\cdot |A\\cdot A| $.Choose\n\\[\nL = \\{y = a(x-b): a,b\\in A\\}.\n\\]\nThen $|L| = |A|^2$. Next, \n\\[\n I(P,L) \\geq |A|^3\n \\] since each line in $L$ contains $|A|$ points in $P$ as follows: $y = a(x-b)$, so choose $x= b+a' \\in A+A$ for any $a' \\in A$. Then $y = aa' \\in A\\cdot A$, so $(x,y) \\in P$.\n\nTherefore, by \\cref{thm:bound_I_m_n95},\n\\begin{align*}\t\n|A|^3 &\\leq I(P,L) \\leq 4 |A|^{4/3} |A+A|^{2/3}|A\\cdot A|^{2/3} + 4|A+A| \\cdot |A\\cdot A| + |A|^2.\n\\end{align*}\nAt least one of these three terms is $\\frac{1}{3}$ of the LHS. Easy if it is not the first one. Otherwise: $\\frac{1}{3}|A|^3 \\leq 4 |A|^{4/3} |A+A|^{2/3} |A\\cdot A|^{2/3}$, so\n\\[\n\\left(\\frac{1}{12}\\right)^{3/2}|A|^{5/2} \\leq |A+A| \\cdot |A\\cdot A|. \\qedhere\n\\]\n\\end{proof}", "meta": {"hexsha": "407f523fc2b2cd3c6eb4e5d0ff67e32de9444487", "size": 7879, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/ch9_incidence.tex", "max_stars_repo_name": "ericphanson/CombinatoricsNotes", "max_stars_repo_head_hexsha": "6b369a77b77cf6f0281b59f227aaa31e6903079c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-04-24T06:43:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-20T04:27:41.000Z", "max_issues_repo_path": "chapters/ch9_incidence.tex", "max_issues_repo_name": "ericphanson/CombinatoricsNotes", "max_issues_repo_head_hexsha": "6b369a77b77cf6f0281b59f227aaa31e6903079c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/ch9_incidence.tex", "max_forks_repo_name": "ericphanson/CombinatoricsNotes", "max_forks_repo_head_hexsha": "6b369a77b77cf6f0281b59f227aaa31e6903079c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-04T19:38:24.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-04T19:38:24.000Z", "avg_line_length": 38.4341463415, "max_line_length": 608, "alphanum_fraction": 0.6206371367, "num_tokens": 3197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.8918110454379297, "lm_q1q2_score": 0.7249240606088383}}
{"text": "\\subsection{Regular Polygon}\n\\subsubsection{Description of the Algorithm}\nThe main idea behind this algorithm is to rotate a vector around a point\n\\textit{n} times.\n\nFollowing a detailed description of the algorithm:\n\n\\begin{enumerate}\n  \\item calculate the parameters\n  \\item from 1 .. node\\_counts calculate the points\n  \\item reverse the order of points\n\\end{enumerate}\n\n\\subsubsection{Implementation description}\nThe calculation of the parameters is the first part to do. The\nparameter characterize the regular polygon about the position on the\nsampling grid, the radius, the winding number and the node count.\nThere is room for further improvements or more parameters, like to\nset the segment length and calculate the possible radius and the\ncenter.\n\nTrigonometric functions like Sinus and Cosinus helps to calculate the points.\n\n\\begin{lstlisting}[basicstyle=\\scriptsize]\n  auto gamma = 2 * \\pi * winding_number / node_count;\n  auto rotation_angle = -gamma / 2;\n\n  auto x = radius * std::cos(seg_counter * gamma + rotation_angle) + center.x();\n  auto y = radius * std::sin(seg_counter * gamma + rotation_angle) + center.y();\n\\end{lstlisting}\n\nThe rotation angle is not necessary for the algorithm. But it helps to perform\ncalculations during other algorithms easier. The rotation angle $ - gamma / 2$\nrotates the whole polygon in a way, that the first segment lies vertically.\n\nThe final step revers the order of the points. This is also not really necessary\nfor the algorithm, but it produces a polygon which has the same direction as the\npolygons from all other algorithms.\n\n\\subsubsection{Complexity}\nThe $n$ in the complexity analysis stands for the node count.\n\n\\begin{enumerate}\n  \\item calculate the parameters $\\bigO(1)$\n  \\item from 1 .. node\\_counts calculate the points $\\bigO(n)$\n  \\item reverse the order of points $\\bigO(n)$\n\\end{enumerate}\n\nThis leads to the sum of $\\bigO(1) + \\bigO(n) + \\bigO(n) \\Rightarrow \\bigO(n)$\n\n\n\\subsubsection{Parameters}\n\\begin{description}\n  \\item [--nodes] how many nodes the polygon has to have. [default: 100]\n  \\item [--sampling-grid] the area within the polygon could grow. [default: 1500x800]\n  %% \\item [--winding-number]\n  \\item [--segment-length] set the segment length. [default: 0]\n  \\item [--radius] the radius for regular polygon. [default: 60]\n\\end{description}\n\n\\subsubsection{Examples}\n\\begin{figure}[ht]\n  \\centering\n\n  \\begin{minipage}[t]{0.4\\textwidth}\n    \\begin{tikzpicture}[yscale=0.05,xscale=0.05]\n\n      \\setcounter{i}{1}\n\n      \\draw[->] (0,0) -- (80,0) node[below] {$x$};\n      \\draw[->] (0,0) -- (0,70) node[left] {$y$};\n\n      \\foreach \\p in {(40,80), (70,58), (70, 22), (40,0), (10,22), (10,58)} {\n        \\node[point] (\\arabic{i}) at \\p {};\n        \\stepcounter{i}\n      }\n\n      \\draw (1) -- (2) -- (3) -- (4) -- (5) -- (6) -- (1);\n    \\end{tikzpicture}\n    \\caption{Regular polygon with 6 points}\n    \\label{fig:rp:points-6}\n  \\end{minipage}\\hfill\n  \\begin{minipage}[t]{0.4\\textwidth}\n    \\begin{tikzpicture}[yscale=0.05,xscale=0.05]\n\n      \\setcounter{i}{1}\n\n      \\draw[->] (0,0) -- (80,0) node[below] {$x$};\n      \\draw[->] (0,0) -- (0,70) node[left] {$y$};\n\n      \\foreach \\p in {(33,70), (70,60), (70, 20), (33,10), (0,40)} {\n        \\node[point] (\\arabic{i}) at \\p {};\n        \\stepcounter{i}\n      }\n\n      \\draw (1) -- (2) -- (3) -- (4) -- (5) -- (1);\n    \\end{tikzpicture}\n    \\caption{Regular polygon with 5 points}\n    \\label{fig:rp:points-5}\n  \\end{minipage}\n\\end{figure}\n\n\\FloatBarrier\n", "meta": {"hexsha": "86c59607d82933fb5ff4d2a1e4c5c5e32935f41f", "size": 3481, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/regular_polygon.tex", "max_stars_repo_name": "utnapischtim/polygon", "max_stars_repo_head_hexsha": "4c926553f436199d643f43a0129610d8d67d72da", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/regular_polygon.tex", "max_issues_repo_name": "utnapischtim/polygon", "max_issues_repo_head_hexsha": "4c926553f436199d643f43a0129610d8d67d72da", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/regular_polygon.tex", "max_forks_repo_name": "utnapischtim/polygon", "max_forks_repo_head_hexsha": "4c926553f436199d643f43a0129610d8d67d72da", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.4711538462, "max_line_length": 85, "alphanum_fraction": 0.6713588049, "num_tokens": 1039, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7249240531548782}}
{"text": "\\section{Operational semantics}\n\nThe \\emph{operational semantics} of a programming language is a\nmathematical description that ascribes meaning to programs by defining\nthe effect of each construct on the state of an abstract machine, each\nstate depending on the previous one. It defines a set of values and an\nevaluation relationship between programs and values, the latter\ncontaining the results. Evaluation is defined inductively on the\nabstract syntax of the language under consideration, that is to say,\nthe value of a construct solely depends on its shape and those of its\nsubparts. In other words again, the value of an abstract syntax tree\n(AST) depends on the pattern matched by its root and the value of its\nimmediate subtrees. Formally, an \\emph{interpreter} is the\nimplementation of an operational semantics, which, by construction, is\ndefined in terms of the syntax of the language being interpreted and\non the semantics of the implementation language.\n\n\\paragraph{A basic calculator}\n\nLet us quickly envisage a simple calculator as an \\OCaml interpreter\nwhose values are integers: \\Xtype \\type{value} \\equal\n\\type{int}\\textsf{;;} We need first to define the concrete syntax of\nthe language by means of a context-free grammar expressed in\nBackus-Naur Form:\n\\begin{verbatim}\nExpression ::= integer\n             | Expression BinOp Expression\n             | \"(\" Expression \")\"\nBinOp ::= \"+\" | \"-\" | \"*\" | \"/\"\n\\end{verbatim}\nNext, we define the abstract syntax in \\OCaml as follows:\n\\begin{tabbing}\n\\Xtype \\type{expr} \\= \\equal \\= \\cst{Const} \\Xof\n\\type{int} \\vbar \\cst{BinOp} \\Xof \\type{bin\\_op} \\(\\times\\)\n\\type{expr} \\(\\times\\) \\type{expr}\\\\\n\\Xand \\type{bin\\_op} \\equal \\cst{Add} \\vbar \\cst{Sub}\n\\vbar \\cst{Mult} \\vbar \\cst{Div}\n\\end{tabbing}\nNote that we will sometimes use the font for the abstract syntax trees\nfor the source code. For example\n\\lpar\\num{1}\\texttt{+}\\num{7}\\rpar\\texttt{*}\\num{9} (mixed fonts)\ninstead of \\texttt{(1+7)*9}.\n\nFor the sake of brevity, and because we want to focus on the\nevaluation, we left out the definition of the lexemes denoted by\n\\texttt{integer} in the grammar above. For example, the syntax\nanalysis would transform the concrete syntax excerpt\n\\texttt{\"(1+2)*(5/1)\"} or \\texttt{\"(1 +2)*(5 / 1)\"} into the\n\\emph{term} \\textsf{BinOp (Mult, BinOp (Add, Const 1, Const 2), BinOp\n  (Div, Const 5, Const 1))}, which is the preorder traversal of the\nabstract syntax tree shown in \\fig~\\vref{fig:binop}.\n\\begin{figure}[b]\n\\centering\n\\includegraphics{binop}\n\\caption{Abstract syntax tree of \\texttt{(1+2)*(5/1)}\n\\label{fig:binop}}\n\\end{figure}\n\nThe interpreter, that is, the evaluation function\nis then\n\\begin{tabbing}\n\\Xlet \\= \\Xrec \\= \\ident{eval} \\ident{e} = \\Xmatch\n \\ident{e} \\Xwith\\\\\n \\> \\cst{Const} \\ident{n} \\(\\rightarrow\\) \\ident{n}\\\\\n \\vbar \\> \\cst{BinOp}\n \\lpar\\ident{op},\\ident{e}\\(\\sb{1}\\),\\ident{e}\\(\\sb{2}\\)\\rpar{}\n \\(\\rightarrow\\) \\= \\Xlet \\ident{v\\(\\sb{1}\\)} = \\ident{eval e\\(\\sb{1}\\)}\n \\Xand  \\ident{v\\(\\sb{2}\\)} = \\ident{eval e\\(\\sb{2}\\)}\\\\\n \\> \\> \\Xin \\= \\Xmatch \\ident{op} \\Xwith \\= \\;\\, \\cst{Add} \\(\\rightarrow\\)\n \\ident{v}\\(\\sb{1}\\) \\texttt{+} \\ident{v}\\(\\sb{2}\\)\\\\\n \\> \\> \\> \\> \\vbar  \\cst{Sub} \\(\\rightarrow\\)\n \\ident{v}\\(\\sb{1}\\) \\texttt{-} \\ident{v}\\(\\sb{2}\\)\\\\\n \\> \\> \\> \\> \\vbar \\cst{Mult} \\(\\rightarrow\\) \n \\ident{v}\\(\\sb{1}\\) \\texttt{*} \\ident{v}\\(\\sb{2}\\)\\\\\n \\> \\> \\> \\> \\vbar \\cst{Div} \\(\\rightarrow\\)\n \\ident{v}\\(\\sb{1}\\) \\texttt{/} \\ident{v}\\(\\sb{2}\\)\n\\end{tabbing}\nLet us consider again the example \\texttt{\"(1+2)*(5/1)\"}. Let~$e$ be\nthe corresponding AST. Its evaluation is the value of the call\n$(\\ident{eval} \\, e)$, whose data flow is represented in\n\\fig~\\vref{fig:binop_15}\n\\begin{figure}\n\\centering\n\\includegraphics{binop_15}\n\\caption{Evaluation of \\texttt{(1+2)*(5/1)}\n\\label{fig:binop_15}}\n\\end{figure}\nwith upwards arrows --~pointing to partial results until the root is\nreached and the final value computed. The control flow is descendant\n(the root is examined before the subtrees) and the data flow is\nascending (the value of the root depends on the values of the\nimmediate subtrees).\n\n\\paragraph{Inference rules}\n\nAnother, more mathematical representation consists in the definition\nof a relationship $\\ceval{e}{v}$, called \\emph{judgement}, which\nreads: `The expression~$e$ is evaluated into the value~$v$', by means\nof \\emph{inference rules}. These are logical implications $P_1 \\wedge\nP_2 \\wedge \\ldots \\wedge P_n \\Rightarrow C$ conveniently laid out as\n\\begin{equation*}\n\\inferrule\n  {P_1 \\\\ P_2 \\\\ \\ldots \\\\ P_n}\n  {C}\n\\end{equation*}\nThe propositions~$P_i$ are the \\emph{premises} and~$C$ is the\n\\emph{conclusion}. When there are no premises, then~$C$ is an\n\\emph{axiom} and simply noted~$C$. The computational reading of the\nrule is: in order to evaluate~$C$, we need first to evaluate the~$P_i$\nin an unspecified order.\n\nRules and axioms can contain variables which are not explicitly\nquantified by~$\\forall$ or~$\\exists$, in which case they are\nimplicitly and universally quantified at the head of the rule. For\ninstance, the axiom $A(x)$ means $\\forall x.A(x)$, and the rule\n\\begin{equation*}\n\\inferrule\n  {P_1(x) \\\\ P_2(y)}\n  {P(x,y)}\n\\end{equation*}\nsignifies $\\forall x,y.(P_1(x) \\, \\wedge \\, P_2(y) \\Rightarrow\nP(x,y))$. Given a set of inference rules about one or more\nrelationships, we implicitly define those as the smallest\nrelationships satisfying the rules.\n\n\\paragraph{Operational semantics of a calculator}\n\nA \\emph{metavariable} is a variable of the descriptive language\n--~here, formal logic~-- and not a variable of the described language\n--~here, the expressions inputted in the calculator.\n\\begin{itemize*}\n\n  \\item Expressions, that is, the values of type \\type{expr}, are\n    noted~$e$;\n\n  \\item values are written~$v$ ($v \\in \\mathbb{Z}$);\n\n  \\item the mathematical integers associated to their \\OCaml\n    representation~$n$ are noted $\\dot{n}$ ($\\dot{n} \\in \\mathbb{Z}$).\n\n\\end{itemize*}\nTherefore, $e$, $v$, $n$ and $\\dot{n}$ are metavariables and\njudgements comply with the pattern $\\ceval{e}{v}$. Here are the rules:\n\\begin{mathpar}\n\\inferrule\n  {\\ceval{\\cst{Const} \\; n}{\\dot{n}}}\n  {}\\;\\,\\TirName{const}\n\\and\n\\inferrule\n  {\\ceval{e_1}{v_1}\\\\ \\ceval{e_2}{v_2}}\n  {\\ceval{\\cst{BinOp} \\, \\lpar\\cst{Add},e_1,e_2\\rpar}{v_1 + v_2}}\n  \\;\\TirName{add}\n\\and\n\\inferrule*[right=sub]\n  {\\ceval{e_1}{v_1}\\\\ \\ceval{e_2}{v_2}}  \n  {\\ceval{\\cst{BinOp} \\, \\lpar\\cst{Sub},e_1,e_2\\rpar}{v_1 - v_2}}\n\\and\n\\inferrule*[right=mult]\n  {\\ceval{e_1}{v_1}\\\\ \\ceval{e_2}{v_2}}\n  {\\ceval{\\cst{BinOp} \\, \\lpar\\cst{Mult},e_1,e_2\\rpar}\n         {v_1 \\times v_2}}\n\\and\n\\inferrule*[right=div]\n  {\\ceval{e_1}{v_1}\\\\ \\ceval{e_2}{v_2}}  \n  {\\ceval{\\cst{BinOp} \\, \\lpar\\cst{Div},e_1,e_2\\rpar}{v_1 / v_2}}\n\\end{mathpar}\n\n\\paragraph{Implementation}\n\nThe systematic way to program an operational semantics in \\OCaml\nconsists in matching the patterns given by the conclusions of the\ninference rules, as suggested below:\n\\begin{mathpar}\n\\inferrule*[right=sub]\n  {\\ceval{e_1}{v_1}\\\\ \\ceval{e_2}{v_2}}  \n  {\\ceval{\\cst{BinOp} \\, \\lpar\\cst{Sub},e_1,e_2\\rpar}{v_1 - v_2}}\n\\end{mathpar}\nwhich becomes \n\\begin{center}\n\\vbar \\cst{BinOp}\n\\lpar\\cst{Sub},\\ident{e\\(\\sb{1}\\)},\\ident{e\\(\\sb{2}\\)}\\rpar{}\n\\(\\rightarrow\\) \\Xlet \\ident{v\\(\\sb{1}\\)} \\equal \\ident{eval}\n\\ident{e\\(\\sb{1}\\)} \\Xand \\ident{v\\(\\sb{2}\\)} \\equal \\ident{eval}\n\\ident{e\\(\\sb{2}\\)} \\Xin \\ident{v\\(\\sb{1}\\)} \\texttt{-}\n\\ident{v\\(\\sb{2}\\)}\n\\end{center}\n\nNote that we grouped all the rules with \\cst{BinOp} in the conclusion,\nin order to create a single pattern. We should keep in mind that the\nevaluation of pattern matchings in \\OCaml is fully specified (they are\nchecked in order), whereas there is no such notion in the operational\nsemantics: the rules are not ordered.\n\n\\paragraph{Determinacy}\n\nIt is important that an expression cannot evaluate to more than one\nvalue and that property is called \\emph{determinacy}. Formally, the\ndeterminacy of an operational semantics $\\ceval{e}{v}$ is formally\nexpressed as the proposition\n\\begin{center}\n\\emph{If $\\ceval{e}{v}$ and $\\ceval{e}{v'}$, then $v=v'$.}\n\\end{center}\nIn order to prove it, we proceed by structural induction on the proof\ntrees of $\\ceval{e}{v}$ and $\\ceval{e}{v'}$, while selecting the rules\ndepending on the shape of~$e$.\n\n\\mypar{Local bindings}\n\nIn order to simplify the writing of expressions, we wish to name\nsub-expressions, as in the following excerpt of concrete syntax:\n\\begin{center}\n\\sf \\textbf{let} x = 1+2*7 \\textbf{in} 9*x*x - x + 2\n\\end{center}\nIn that aim, we add \\emph{identifiers} (\\verb+x+) and \\emph{local\n  bindings} (\\textsf{\\textbf{let} ... \\textbf{in} ...}) to the\nconcrete syntax of expressions. Note that we use the term `variable'\nto qualify the identifiers in the abstract syntax for historical\nreasons (since these really denote constants and do not vary), but a\nvariable is a name, not the object it denotes.\n\nThe concrete syntax is:\n\\begin{verbatim}\nExpression ::= ...  | ident                     /* identifier */\n                    | \"let\" ident \"=\" Expression \"in\" Expression\n\\end{verbatim}\nNotice that we should define the set of lexemes denoted by\n\\texttt{ident}, but we don't. The extension to the abstract syntax is:\n\n\\bigskip\n\n\\noindent \\Xtype \\type{expr} \\equal \\texttt{...} \\vbar{} \\cst{Var}\n\\Xof \\type{string} \\vbar \\cst{Let} \\Xof \\type{string} \\(\\times\\)\n\\type{expr} \\(\\times\\) \\type{expr}\n\n\\bigskip\n\nVariables are written~$x$. We should not confuse~$x$, a meta variable\nmeaning `any variable', with \\cst{Var} \\str{x} (a particular AST of\nthe described language) and \\str{x} or \\texttt{x} (pieces of source\ncode of the preceding variable).\n\nLet us see now what operational semantics we ascribe to these\nexpressions with variables.\n\n\\paragraph{Environments}\n\nAn \\emph{environment} associates variables to values (by construction,\nthese are their values). One of such an association is called a\n\\emph{binding}. More precisely, a binding is a pair $(x,v)$, which we\nwill sometimes write instead $x \\mapsto v$, as if it were an\nenvironment reduced to a single variable in its domain. An environment\nis a partial function from variables to values.\n\nThe empty environment in \\OCaml is\n\\begin{center}\n\\Xlet \\ident{empty\\_env} \\equal \\Xfun \\_ $\\rightarrow$\n\\ident{raise} \\cst{Not\\_found}\n\\end{center}\nThe addition of a binding $x \\mapsto v$ to an environment~$\\rho$ is\nnoted $(x \\mapsto v) \\oplus \\rho$. If~$x$ was already bound in~$\\rho$,\nthat is, if~$\\rho (x)$ was defined, then this new binding hides the\nolder, that is to say that $(x \\mapsto v \\oplus \\rho) (x) = v$, even\nif $\\rho (x) \\neq v$. A na\\\"{\\i}ve but direct implementation would be\n\\begin{center}\n\\Xlet \\ident{extend} \\lpar\\ident{x},\\ident{v}\\rpar{} \\ident{env}\n\\equal \\Xfun \\ident{y} $\\rightarrow$ \\Xif \\ident{x} \\equal \\ident{y}\n\\Xthen \\ident{v} \\Xelse \\ident{env} \\ident{y}\n\\end{center}\nJudgements take now the form $\\eval{\\rho}{e}{v}$ and they feature the\nenvironment~$\\rho$ in the context, that is, the left\\hyp{}hand side of\nthe judgements:\n\\begin{mathpar}\n\\inferrule\n  {\\eval{\\rho}{\\cst{Const} \\; n}{\\dot{n}}}\n  {}\\;\\,\\TirName{const}\n\\\\\n\\inferrule\n  {x \\in \\dom{\\rho}}\n  {\\eval{\\rho}{\\cst{Var} \\; x}{\\rho (x)}}\\;\\TirName{var}\n\\\\\n\\inferrule*[right=add]\n  {\\eval{\\rho}{e_1}{v_1}\\\\ \\eval{\\rho}{e_2}{v_2}}\n  {\\eval{\\rho}\n        {\\cst{BinOp} \\, \\lpar\\cst{Add},e_1,e_2\\rpar}\n        {v_1 + v_2}}\n\\and\n\\inferrule*[right=sub]\n  {\\eval{\\rho}{e_1}{v_1}\\\\ \\eval{\\rho}{e_2}{v_2}}  \n  {\\eval{\\rho}\n        {\\cst{BinOp} \\, \\lpar\\cst{Sub},e_1,e_2\\rpar}\n        {v_1 - v_2}}\n\n\\inferrule*[right=mult]\n  {\\eval{\\rho}{e_1}{v_1}\\\\ \\eval{\\rho}{e_2}{v_2}}  \n  {\\eval{\\rho}\n         {\\cst{BinOp} \\, \\lpar\\cst{Mult},e_1,e_2\\rpar}\n        {v_1 \\times v_2}} \n\\and\n\\inferrule*[right=div]\n  {\\eval{\\rho}{e_1}{v_1}\\\\ \\eval{\\rho}{e_2}{v_2}}  \n  {\\eval{\\rho}\n        {\\cst{BinOp} \\, \\lpar\\cst{Div},e_1,e_2\\rpar}\n        {v_1 / v_2}}\n\\and\n\\inferrule*[right=let]\n  {\\eval{\\rho}{e_1}{v_1}\\\\ \n   \\eval{x \\mapsto v_1 \\oplus \\rho}{e_2}{v_2}}\n  {\\eval{\\rho}\n        {\\cst{Let} \\, \\lpar{x},e_1,e_2\\rpar}\n        {v_2}}\n\\end{mathpar}\n\nWe can now translate these inference rules into \\OCaml, which results\nin a slight modification of the first version:\n\\begin{tabbing}\n\\Xlet \\= \\Xrec \\= \\ident{eval} \\ident{env} \\ident{e} = \\Xmatch\n \\ident{e} \\Xwith\\\\\n \\> \\cst{Const} \\ident{n} \\(\\rightarrow\\) \\ident{n}\\\\\n \\vbar \\> \\cst{BinOp}\n \\lpar\\ident{op},\\ident{e}\\(\\sb{1}\\),\\ident{e}\\(\\sb{2}\\)\\rpar{}\n \\(\\rightarrow\\) \\= \\Xlet \\ident{v\\(\\sb{1}\\)} = \\ident{eval e\\(\\sb{1}\\)}\n \\Xand  \\ident{v\\(\\sb{2}\\)} = \\ident{eval e\\(\\sb{2}\\)}\\\\\n \\> \\> \\Xin \\= \\lpar\\Xmatch \\ident{op} \\Xwith \\= \\;\\, \\cst{Add} \\(\\rightarrow\\)\n \\ident{v}\\(\\sb{1}\\) \\texttt{+} \\ident{v}\\(\\sb{2}\\)\\\\\n \\> \\> \\> \\> \\vbar  \\cst{Sub} \\(\\rightarrow\\)\n \\ident{v}\\(\\sb{1}\\) \\texttt{-} \\ident{v}\\(\\sb{2}\\)\\\\\n \\> \\> \\> \\> \\vbar \\cst{Mult} \\(\\rightarrow\\) \n \\ident{v}\\(\\sb{1}\\) \\texttt{*} \\ident{v}\\(\\sb{2}\\)\\\\\n \\> \\> \\> \\> \\vbar \\cst{Div} \\(\\rightarrow\\)\n \\ident{v}\\(\\sb{1}\\) \\texttt{/} \\ident{v}\\(\\sb{2}\\)\\rpar\\\\\n\n\\vbar \\> \\cst{Var} \\ident{x} \\(\\rightarrow\\) \\ident{env} \\ident{x}\\\\\n\\vbar \\> \\cst{Let} \\lpar\\ident{x},\\ident{e}\\(\\sb{1}\\),\\ident{e}\\(\\sb{2}\\)\\rpar{}\n\\(\\rightarrow\\) \\= \\Xlet \\ident{v}\\(\\sb{1}\\) \\equal \\ident{eval}\n\\ident{env} \\ident{e}\\(\\sb{1}\\)\\\\\n\\>\\>\\Xin  \\ident{eval} \\lpar\\ident{extend}\n\\lpar\\ident{x},\\ident{v}\\(\\sb{1}\\)\\rpar{} \\ident{env}\\rpar{}\n\\ident{e}\\(\\sb{2}\\)\n\\end{tabbing}\nNote the encoding of $x \\mapsto v_1 \\oplus \\rho$ by \\ident{extend}\n\\lpar\\ident{x},\\ident{v}\\(\\sb{1}\\)\\rpar{} \\ident{env}, and how the\nevaluation of the initial expression must take place in the empty\nenvironment. The values of the semantics are in~$\\mathbb{Z}$, whereas,\nin the interpreter, they have the type \\type{int}, hence can\noverflow. We will not discuss this issue here.\n\n\\paragraph{An example}\n\nLet us consider an example with variables: \\textsf{\\textbf{let} x = 1\n  \\textbf{in} (1+2)*(5/x)}. Let~$e$ be the AST corresponding to that\nexpression. \\Fig~\\vref{fig:binop_15_var}\n\\begin{figure}[b]\n\\centering\n\\includegraphics[scale=0.84]{binop_15_var}\n\\caption{Evaluation of \\textsf{\\textbf{let} x = 1 \\textbf{in} (1+2)*(5/x)}\n\\label{fig:binop_15_var}}\n\\end{figure}\nshows its evaluation, that is, how \\textsf{(eval empty\\_env $e$)} is\ncomputed. Note that, we write~$\\varnothing$ instead of\n\\ident{empty\\_env}, and \\ident{env} instead of \\lpar\\ident{extend}\n\\lpar\\str{x},\\num{1}\\rpar{} \\ident{empty\\_env}\\rpar.\n\nIn order to simplify further the presentation of the evaluations, we\ncan use an auxiliary function, from character strings to expressions,\ncorresponding to the composition of the lexical and syntactical\nanalyses. We will write it \\mbox{$\\src{\\_}$: \\type{string}\n  $\\rightarrow$ \\type{expr}}, where the underscore is a placeholder\nfor the actual argument, but we will omit the quotes of the string\nitself:\n\n\\medskip\n\n\\noindent $\\src{\\text{\\Xlet \\ident{x} \\equal{} \\num{1} \\Xin \\Xlet\n  \\ident{y} \\equal{} \\num{2} \\Xin \\ident{x} \\texttt{+} \\ident{y}}}$\\\\\n= \\text{\n      \\cst{Let} \\lpar\\str{x},\n         \\cst{Const} \\num{1}, \n         \\cst{Let} \\lpar\\str{y},\n            \\cst{Const} \\num{2},\n            \\cst{BinOp} \\lpar\\cst{Add},\n              \\cst{Var} \\str{x},\n              \\cst{Var}\n              \\str{y}\\rpar\\!\\rpar\\!\\rpar}.\n\n\\medskip\n\nMetavariables~$\\meta{e}$ may occur in the concrete syntax to designate\ncharacter strings produced by the grammar rule \\texttt{Expression},\nlike so:\n\\begin{equation*}\n\\src{\\Xlet \\; \\ident{x} \\; \\equal \\; \\num{2} \\; \\Xin \\; \\meta{e}} =\n\\cst{Let} \\; \\lpar\\str{x}, \\cst{Const} \\, \\num{2},\n\\src{\\meta{e}}\\!\\rpar.\n\\end{equation*}\nTo simplify further, we will write~$e$ in stead\nof~$\\src{\\meta{e}}$. Actually, we can easily write a formal\ndefinition of the syntax analysis on programs whose syntax is already\ncorrect:\n\\begin{align*}\n\\src{\\meta{n}} & = \\cst{Const} \\, \\lpar\\ident{int\\_of\\_string} \\;\n\\meta{n}\\rpar = \\cst{Const} \\; n = \\dot{n},\\\\\n\\src{\\meta{e}_1 \\, \\texttt{+} \\, \\meta{e}_2} & = \\cst{BinOp} \\,\n\\lpar\\cst{Add}, e_1, e_2\\rpar,\\\\\n\\src{\\meta{e}_1 \\, \\texttt{-} \\, \\meta{e}_2} & = \\cst{BinOp} \\,\n\\lpar\\cst{Sub}, e_1, e_2\\rpar,\\\\\n\\src{\\meta{e}_1 \\, \\texttt{*} \\, \\meta{e}_2} & = \\cst{BinOp} \\,\n\\lpar\\cst{Mult}, e_1, e_2\\rpar,\\\\\n\\src{\\meta{e}_1 \\, \\texttt{/} \\, \\meta{e}_2} & = \\cst{BinOp} \\,\n\\lpar\\cst{Div}, e_1, e_2\\rpar,\\\\\n\\src{x} & = \\cst{Var} \\, x,\\\\\n\\src{\\Xlet \\; x \\; \\equal \\; \\meta{e}_1 \\; \\Xin \\;\n  \\meta{e}_2} & = \\cst{Let} \\, \\lpar{x}, e_1, e_2\\rpar,\\\\\n\\src{\\lpar\\meta{e}\\rpar} & = e.\n\\end{align*}\n\n\\paragraph{More legible rules}\n\nHere are the inference rules revisited in the light of the previous\nsimplifications:\n\\begin{mathpar}\n\\inferrule\n  {\\meval{\\rho}{\\meta{n}}{\\dot{n}}}\n  {}\\;\\,\\TirName{const}\n\\and\n\\inferrule\n  {x \\in \\dom{\\rho}}\n  {\\meval{\\rho}{x}{\\rho (x)}}\\;\\TirName{var}\n\\and\n\\inferrule*[right=add]\n  {\\eval{\\rho}{e_1}{v_1}\\\\ \n   \\eval{\\rho}{e_2}{v_2}}\n  {\\meval{\\rho}{\\meta{e}_1 \\, \\texttt{+} \\, \\meta{e}_2}{v_1 + v_2}}\n\\and\n\\inferrule*[right=sub]\n  {\\eval{\\rho}{e_1}{v_1}\\\\ \n   \\eval{\\rho}{e_2}{v_2}}\n  {\\meval{\\rho}{\\meta{e}_1 \\, \\texttt{-} \\, \\meta{e}_2}{v_1 - v_2}}\n\\and\n\\inferrule*[right=mult]\n  {\\eval{\\rho}{e_1}{v_1}\\\\ \n   \\eval{\\rho}{e_2}{v_2}}\n  {\\meval{\\rho}{\\meta{e}_1 \\, \\texttt{*} \\, \\meta{e}_2}{v_1 \\times v_2}}\n\\and\n\\inferrule*[right=div]\n  {\\eval{\\rho}{e_1}{v_1}\\\\ \n   \\eval{\\rho}{e_2}{v_2}}\n  {\\meval{\\rho}{\\meta{e}_1 \\, \\texttt{/} \\, \\meta{e}_2}{v_1 / v_2}}\n\\and\n\\inferrule*[right=let]\n  {\\eval{\\rho}{e_1}{v_1}\\\\ \n   \\eval{x \\mapsto v_1 \\oplus \\rho}{e_2}{v_2}}\n  {\\meval{\\rho}{\\Xlet \\; x \\; \\equal \\; \\meta{e}_1 \\; \\Xin\n  \\; \\meta{e}_2}{v_2}}\n\\end{mathpar}\n\n\\paragraph{Another evaluation}\n%XXX\nGiven the following excerpt of concrete syntax, `\\Xlet \\ident{x}\n\\equal \\num{1} \\Xin ((\\Xlet \\ident{x} \\equal \\num{2} \\Xin \\ident{x}) +\n\\ident{x})', the abstract syntax tree generated by the parser is shown\nin \\fig~\\vref{fig:let_x}.\n\\begin{figure}[b]\n\\centering\n\\includegraphics{let_x}\n\\caption{AST of \\Xlet \\ident{x}\n\\equal \\num{1} \\Xin ((\\Xlet \\ident{x} \\equal \\num{2} \\Xin \\ident{x}) +\n\\ident{x}) \\label{fig:let_x}}\n\\end{figure}\nWe combine the inference rules to evaluate the expression: we obtain a\n\\emph{proof tree} (of the evaluation of the expression into the\nvalue~3), also called \\emph{derivation}, shown in\n\\fig~\\vref{fig:eval_tree}.\n\\begin{figure}\n\\centering\n\\includegraphics[bb=48 642 414 719,scale=0.93]{eval_tree}\n\\caption{Proof tree of \\Xlet \\ident{x}\n\\equal \\num{1} \\Xin ((\\Xlet \\ident{x} \\equal \\num{2} \\Xin \\ident{x}) +\n\\ident{x}) \\label{fig:eval_tree}}\n\\end{figure}\nThe proof tree is built bottom\\hyp{}up, that is, from the root to the\nleaves (beware that proof trees are laid out on the page with their\nroot below their leaves), depending on the shape of the conclusions,\nand we deduce step by step equations involving metavariables denoting\nvariables. Next, these equations are solved and provide us with the\nsought value, that is, the result of the evaluation.\n\nLet~$v$ be the value of the term $\\src{\\text{\\Xlet \\ident{x} \\equal\n    \\num{1} \\Xin \\lpar\\lpar\\Xlet \\ident{x} \\equal \\num{2} \\Xin\n    \\ident{x}\\rpar{} \\texttt{+} \\ident{x}\\rpar}}$. The only rule\nhaving a conclusion of that form is \\RefTirName{let}. We therefore\napply an instance of it, in an empty environment:\n\\begin{mathpar}\n\\inferrule\n  {\\eval{\\varnothing}{\\src{\\num{1}}}{1}\\\\\n     {\\eval\n        {\\str{x} \\mapsto 1}\n        {\\src{\\Xlet \\; \\ident{x} \\; \\equal \\; 2 \\; \\Xin \\;\n              \\ident{x} \\; \\texttt{+} \\; \\ident{x}}}\n        {v}}\n  }\n  {\\eval\n    {\\varnothing}\n    {\\src{\\Xlet \\; \\ident{x} \\; \\equal \\; \\num{1} \\; \\Xin \\;\n       \\lpar\\lpar\\Xlet \\; \\ident{x} \\; \\equal \\; 2 \\;\n       \\Xin \\; \\ident{x}\\rpar \\; \\texttt{+} \\; \\ident{x}\\rpar}}\n    {v}}\n\\end{mathpar}\nThe second premise can only be a conclusion of the rule\n\\RefTirName{add}:\n\\begin{mathpar}\n    \\inferrule*\n      {\\eval\n         {\\str{x} \\mapsto 1}\n         {\\src{\\Xlet \\; \\ident{x} \\; \\equal \\; \\num{2} \\; \\Xin \\; \\ident{x}}}\n         {v_1}\\\\\n        {\\eval\n           {\\str{x} \\mapsto 1}\n           {\\src{\\ident{x}}}\n           {1}\n        }\n     }\n     {\\eval\n        {\\str{x} \\mapsto 1}\n        {\\src{\\lpar\\Xlet \\; \\ident{x} \\; \\equal \\; \\num{2} \\;\n         \\Xin \\; \\ident{x}\\rpar{} \\; \\texttt{+} \\;\n         \\ident{x}}}\n        {v_1+1}\n     }\n\\end{mathpar}\n\\noindent and the deduced equation is simply $v = v_1 + 1$.\n\n\\noindent The first premise can only be the conclusion of the rule \\RefTirName{let}:\n\\begin{mathpar}\n  \\inferrule\n     {\\eval\n        {\\str{x} \\mapsto 1}\n        {\\src{2}}\n        {2}\\\\\n      \\eval\n        {\\str{x} \\mapsto 2 \\oplus \\str{x} \\mapsto 1}\n        {\\src{\\ident{x}}}\n        {2}\n     }\n     {\\eval\n        {\\str{x} \\mapsto 1}\n        {\\src{\\Xlet \\; \\ident{x} \\; \\equal \\; \\num{2} \\; \\Xin \\; \\ident{x}}}\n        {2}\n     }\n\\end{mathpar}\nThus, $v_1=2$. By substituting $v_1$ by its value, we draw $v=2+1=3$.\n\n\\mypar{Formalising errors}\n\nDuring the evaluation presented above, several problems might have\narisen: \\ident{x}~could have valued~0 (division by zero) or $\\str{x}\n\\not\\in \\dom{\\rho}$. In the former case, the rule is\n\\begin{mathpar}\n\\inferrule*[right=div]\n  {\\eval{\\rho}{e_1}{v_1}\\\\\n   \\eval{\\rho}{e_2}{v_2}}\n  {\\eval{\\rho}{\\src{\\meta{e}_1 \\, \\texttt{/} \\, \\meta{e}_2}}{v_1 /\n    v_2}}\n\\end{mathpar}\n\\noindent We can formalise the correct cases and the division error:\n\\begin{mathpar}\n\\inferrule\n  {\\eval{\\rho}{e_1}{v_1}\\\\\n   \\eval{\\rho}{e_2}{v_2}\\\\\n   v_2 \\neq 0}\n  {\\eval{\\rho}{\\src{\\meta{e}_1 \\, \\texttt{/} \\, \\meta{e}_2}}{v_1/v_2}}\n\\and\n\\inferrule\n  {\\eval{\\rho}{e_2}{0}}\n  {\\eval{\\rho}{\\src{\\meta{e}_1 \\, \\texttt{/} \\, \\meta{e}_2}}\n        {\\textsl{error}}}\n\\end{mathpar}\nTo formalise \\textsl{error}, we replace the relationship\n$\\eval{\\rho}{e}{v}$ by $\\eval{\\rho}{e}{r}$, where~$r$ is a\n\\emph{result}: results are values or errors. Moreover, from now on, we\nconsider that values in the semantics have the type \\type{int} instead\nof the mathematical set~$\\mathbb{Z}$, because we do not need so much\nabstraction and this will get us closer to the implementation, that\nis, the interpreter.\n\n\\medskip\n\n\\begin{raggedright}\n\\Xtype \\type{value} \\equal \\type{int}\\textsf{;;}{}\\\\\n\\Xtype \\type{error} \\equal \\cst{DivByZero} \\vbar \\cst{FreeVar}\n\\Xof \\type{string}\\textsf{;;}{}\\\\ \n\\Xtype \\type{result} \\equal \\cst{Val} \\Xof \\type{value}\n\\vbar \\cst{Err} \\Xof \\type{error}\\textsf{;;}{}\n\\end{raggedright}\n\n\\medskip\n\n\\noindent The rules which can produce errors are\n\\begin{mathpar}\n\\inferrule*[right=div-zero]\n  {\\eval{\\rho}{e_2}{\\cst{Val} \\, \\num{0}}}\n  {\\eval\n     {\\rho}\n     {\\src{\\meta{e}_1 \\, \\texttt{/} \\, \\meta{e}_2}}\n     {\\cst{Err} \\, \\cst{DivByZero}}}\n\n\\inferrule*[right=free-var]\n  {x \\not\\in \\dom{\\rho}}\n  {\\eval{\\rho}\n        {\\src{x}}\n        {\\cst{Err} \\, \\lpar\\cst{FreeVar} \\, x\\rpar}}\n\n\\inferrule*[right=div]\n  {\\eval{\\rho}{e_1}{\\cst{Val} \\, v_1}\\\\ \n   \\eval{\\rho}{e_2}{\\cst{Val} \\, v_2}}\n  {\\meval{\\rho}\n         {\\meta{e}_1 \\, \\texttt{/} \\, \\meta{e}_2}\n         {\\cst{Val} \\, \\lpar v_1 \\, \\texttt{/} \\, v_2\\rpar}}\n\n\\inferrule*[right=mult]\n  {\\eval{\\rho}{e_1}{\\cst{Val} \\, v_1}\\\\ \n   \\eval{\\rho}{e_2}{\\cst{Val} \\, v_2}}\n  {\\meval{\\rho}\n        {\\meta{e}_1 \\, \\texttt{*} \\, \\meta{e}_2}\n        {\\cst{Val} \\, \\lpar{v_1 \\, \\texttt{*} \\, v_2\\rpar}}}\n\n\\inferrule\n  {\\eval{\\rho}{e_1}{\\cst{Val} \\, v_1}\\\\ \n   \\eval{\\rho}{e_2}{\\cst{Val} \\, v_2}}\n  {\\meval{\\rho}\n         {\\meta{e}_1 \\, \\texttt{+} \\, \\meta{e}_2}\n         {\\cst{Val} \\, \\lpar{v_1 \\, \\texttt{+} \\, v_2}\\rpar}}\n\\;\\TirName{add}\n\n\\inferrule*[right=sub]\n  {\\eval{\\rho}{e_1}{\\cst{Val} \\, v_1}\\\\ \n   \\eval{\\rho}{e_2}{\\cst{Val} \\, v_2}}  \n  {\\meval{\\rho}\n         {\\meta{e}_1 \\, \\texttt{-} \\, \\meta{e}_2}\n         {\\cst{Val} \\, \\lpar{v_1 \\, \\texttt{-} \\, v_2}\\rpar}}\n\\\\\n\\inferrule\n  {\\meval{\\rho}{\\meta{n}}{\\cst{Val} \\, n}}\n  {}\\;\\,\\TirName{const}\n\\and\n\\inferrule\n  {x \\in \\dom{\\rho}}\n  {\\meval{\\rho}{x}{\\cst{Val} \\, \\lpar\\rho(x)\\rpar}}\n\\;\\TirName{var}\n\n\\inferrule*[right=let]\n  {\\eval{\\rho}{e_1}{\\cst{Val} \\, v_1}\\\\ \n   \\eval{x \\mapsto v_1 \\oplus \\rho}{e_2}{\\cst{Val} \\, v_2}}\n  {\\meval{\\rho}{\\Xlet \\; x \\; \\equal \\; \\meta{e}_1 \\; \\Xin\n  \\; \\meta{e}_2}{\\cst{Val} \\, v_2}}\n\\end{mathpar}\n\\begin{mathpar}\n\\inferrule*[right=add-err$_1$]\n  {\\eval{\\rho}{e_1}{\\cst{Err} \\, z}\\\\\n   \\eval{\\rho}{e_2}{r}}\n  {\\meval{\\rho}\n         {\\meta{e}_1 \\, \\texttt{*} \\, \\meta{e}_2}\n         {\\cst{Err} \\, z}}\n\n\\inferrule*[right=add-err$_2$]\n  {\\eval{\\rho}{e_1}{r}\\\\\n   \\eval{\\rho}{e_2}{\\cst{Err} \\, z}}\n  {\\meval{\\rho}\n         {\\meta{e}_1 \\, \\texttt{+} \\, \\meta{e}_2}\n         {\\cst{Err} \\, z}}\n\\end{mathpar}\nLet us remark first that we need two rules because two premises can be\nevaluated into errors, and the semantics does not express the\ncommutative property of the addition over integers. The other cases\nare similar. Second, in case of multiple errors, only one will be\npropagated and the evaluation order, having been left unspecified on\npurpose, we cannot say \\emph{a priori} which error will be propagated.\n\nFor the sake of simplicity, let us use the exceptions of \\OCaml to\nimplement the propagation of errors, and, thereby, avoid the type\n\\type{result}. \n\\begin{tabbing}\n\\Xexception \\cst{Err} \\Xof \\type{error}\\\\\n\\\\\n\\Xlet \\= \\Xrec \\ident{eval} \\ident{env} \\ident{e} \\equal \\Xmatch\n\\ident{e} \\Xwith \\texttt{...} \\\\\n\\vbar \\> \\cst{Var} \\ident{x} \\(\\rightarrow\\)\n \\underline{\\lpar\\Xtry} \\ident{env} \\ident{x} \\underline{\\Xwith \\cst{Not\\_found}\n  \\(\\rightarrow\\) \\ident{raise} \\lpar\\cst{Err} \\lpar\\cst{FreeVar}\n  \\ident{x}\\rpar\\rpar\\rpar}\\\\\n\\vbar \\> \\cst{BinOp}\n\\lpar\\textbf{\\cst{Div}},\\ident{e}\\(\\sb{1}\\),\\ident{e}\\(\\sb{2}\\)\\rpar{}\n\\(\\rightarrow\\)\\\\\n\\> \\Xlet v\\(\\sb{1}\\) \\equal \\ident{eval env}\n\\ident{e}\\(\\sb{1}\\) \\Xand v\\(\\sb{2}\\) \\equal \\ident{eval env}\n\\ident{e}\\(\\sb{2}\\)\\\\\n\\> \\Xin \\underline{\\Xif v\\(\\sb{2}\\) \\equal \\num{0} \\Xthen\n\\ident{raise} \\lpar\\cst{Err} \\cst{DivByZero}\\rpar{}\n\\Xelse} v\\(\\sb{1}\\)\\textsf{/}v\\(\\sb{2}\\) \\\\\n\\texttt{| ...}\n\\end{tabbing}\n(The underlined code is the difference with the previous version.)\nNotice that we could speed up error handling by evaluating\nfirst~\\ident{e}$_2$, then~\\ident{e}$_1$ if and only if \\ident{v}$_2$\n\\nequal \\num{0}. The interpreter enforces then a particular order of\nevaluation for the arguments of the division operation, but this order\nmust not be relied upon by the user. In general terms, if the order of\nevaluation is specified, like in \\Java, then there is no ambiguity,\notherwise, the ambiguity might be used by the implementors of the\ncompiler for optimisations.\n\nThe operational semantics sometimes seems not to say anything, but it\ncan express the dependencies between evaluations (see rule\n\\RefTirName{let}), and the evaluations in case of errors: contrast the\nrule\n\\begin{mathpar}\n\\inferrule*[right=div-zero]\n  {\\eval{\\rho}{e_1}{r_1}\\\\\n   \\eval{\\rho}{e_2}{\\cst{Val} \\, \\num{0}}\n  }\n  {\\meval\n     {\\rho}\n     {\\meta{e}_1 \\, \\texttt{/} \\, \\meta{e}_2}\n     {\\cst{Err} \\, \\cst{DivByZero}}\n  }\n\\end{mathpar}\n\n\\paragraph{Free variables}\n\nIt is possible to determine whether some variables are free in an\nexpression before evaluation, thereby avoiding the error \\cst{FreeVar}\nat run\\hyp{}time. That kind of analysis is a particular case of\n\\emph{static analysis}, that is, taking place at compile\\hyp{}time.\n\nLet~$\\mathcal{F}$ the function which associates an expression to its\nfree variables. We can write~$\\mathcal{F} \\src{\\_}$ instead of\n$\\mathcal{F}(\\src{\\_})$. It is defined by the following equations,\nwhere the priority of~`$\\backslash$' is higher than that of~`$\\cup$',\nand~$\\meta{o}$ denotes a character string generated by the grammatical\nrule \\texttt{BinOp}:\n\\begin{align*}\n\\mathcal{F} \\src{\\meta{n}} & = \\varnothing,\\\\\n\\mathcal{F} \\src{x} & = \\{x\\},\\\\\n\\mathcal{F} \\src{\\meta{e}_1 \\; \\meta{o} \\;\\, \\meta{e}_2} & = \\mathcal{F}(e_1) \\cup \\mathcal{F}(e_2),\\\\\n\\mathcal{F} \\src{\\Xlet \\; x \\; \\equal \\; \\meta{e}_1 \\; \\Xin \\;\n  \\meta{e}_2} & = \\mathcal{F}(e_1) \\cup \\mathcal{F}(e_2) \\backslash \\{x\\}.\n\\end{align*}\nLet us revisit the example \\textsf{\\textbf{let} x = 1 \\textbf{in}\n  ((\\textbf{let} x = 2 \\textbf{in} x) + x)}. We have:\n\n\\begin{equation*}\n\\begin{array}{lcl}\n\\multicolumn{3}{l}{\n\\mathcal{F} \\src{\\Xlet \\; \\ident{x} \\; \\equal \\; \\num{1} \\; \\Xin \\;\n  \\lpar\\lpar\\Xlet \\; \\ident{x} \\; \\equal \\; \\num{2} \\; \\Xin \\;\n  \\ident{x}\\rpar{} \\; \\texttt{+} \\; \\ident{x}\\rpar}}\\\\\n\\phantom{XXX}\n &=& \\mathcal{F} \\src{\\num{1}} \\, \\cup \\, \\mathcal{F} \\src{\\lpar\\Xlet \\; \\ident{x} \\;\n     \\equal \\; \\num{2} \\; \\Xin \\; \\ident{x}\\rpar{} \\; \\texttt{+}\n    \\; \\ident{x}} \\backslash \\{\\str{x}\\}\\\\ \n &=& \\varnothing \\, \\cup \\,\n     (\\mathcal{F} \\src{\\Xlet \\; \\ident{x} \\; \\equal \\; \\num{2} \\;\n     \\Xin \\; \\ident{x}} \\, \\cup \\, \\mathcal{F} \\src{\\ident{x}})\n     \\backslash \\{\\str{x}\\} \\\\\n &=& (\\mathcal{F} \\src{\\num{2}} \\, \\cup \\, \\mathcal{F} \\src{\\ident{x}} \\backslash\n      \\{\\str{x}\\} \\, \\cup \\, \\{\\str{x}\\}) \\backslash \\{\\str{x}\\}\\\\\n &=& (\\varnothing \\, \\cup \\, \\{\\str{x}\\} \\backslash \\{\\str{x}\\}\n     \\, \\cup \\, \\{\\str{x}\\}) \\backslash \\{\\str{x}\\}\\\\\n &=& \\varnothing.\n\\end{array}\n\\end{equation*}\nThe expression does not contain any free variable. By definition, such\nan expression is said to be \\emph{closed}. Moreover, since the\nexpression does not contain any division, we have proved that \nno error will occur during evaluation.\n\n\\paragraph{Graphical representation of bindings}\n\nUntil now, the data constructor \\cst{Let} is the only one that adds\nbindings to the environment: it is said to be `binding'. Let us resume\nthe previous example. From each occurrence of a variable (\\cst{Var}),\nlet us move up towards the root: if we find a \\cst{Let} binding that\nvariable, we create an edge from it to its binding \\cst{Let}; if, once\nthe root has been reached, no \\cst{Let} has been found, the variable\nis free in the expression. The example is seen in\n\\fig~\\vref{fig:graph_fv}.\n\\begin{figure}\n\\centering\n\\includegraphics[bb=71 632 282 726]{graph_fv}\n\\caption{Free variables bound by upward edges in the AST\n\\label{fig:graph_fv}}\n\\end{figure}\n\n\\paragraph{Testing zero}\n\nLet us come back once again to our language and let us add a\nconditional construct with test against zero.\n\\begin{itemize}\n\n  \\item The extension to the concrete syntax is\n\\begin{verbatim}\nExpression ::=  ... | \"ifz\" Expression \"then\" Expression \n                      \"else\" Expression\n\\end{verbatim}\n\n  \\item The extension to the abstract syntax is\n\n\\noindent \\Xtype \\type{expr} \\equal \\texttt{...} \\vbar \\cst{Ifz} \\Xof\n\\type{expr} \\(\\times\\) \\type{expr} \\(\\times\\) \\type{expr}\n\n  \\item The syntax analysis (in the absence of error) is\n\n\\noindent $\\src{\\kwd{ifz} \\; \\meta{e}_1 \\; \\Xthen \\; \\meta{e}_2 \\;\n  \\Xelse \\; \\meta{e}_3} = \\cst{Ifz} \\, \\lpar e_1, e_2, e_3\\rpar$.\n\n  \\item The free variables are found with\n\n\\noindent $\\mathcal{F} \\src{\\kwd{ifz} \\; \\meta{e}_1 \\; \\Xthen \\;\n  \\meta{e}_2 \\; \\Xelse \\; \\meta{e}_3} = \\mathcal{F} (e_1) \\, \\cup \\,\n          \\mathcal{F} (e_2) \\, \\cup \\, \\mathcal{F} (e_3)$.\n\n\\end{itemize}\nThe operational semantics is extended with the following rules:\n\\begin{mathpar}\n  \\inferrule*[right=if-then]\n    {\\eval{\\rho}{e_1}{0}\\\\\n     \\eval{\\rho}{e_2}{v_2}}\n    {\\meval{\\rho}{\\kwd{ifz} \\; \\meta{e}_1 \\; \\Xthen \\;\n     \\meta{e}_2 \\; \\Xelse \\; \\meta{e}_3}{v_2}}\n\\and\n  \\inferrule*[right=if-else]\n    {\\eval{\\rho}{e_1}{\\dot{n}}\\\\\n     \\dot{n} \\neq 0\\\\\n     \\eval{\\rho}{e_3}{v_3}}\n    {\\meval{\\rho}{\\kwd{ifz} \\; \\meta{e}_1 \\; \\Xthen \\;\n     \\meta{e}_2 \\; \\Xelse \\; \\meta{e}_3}{v_3}}\n\\end{mathpar}\n\n\\paragraph{Functions}\n\nLet us add to the calculator function abstractions and their\ncorresponding calls, called \\emph{applications} in the\n\\(\\lambda\\)-calculus.\n\\begin{itemize}\n\n  \\item The concrete syntax is extended like so:\n\\begin{verbatim}\nExpression ::= ... \n             | \"fun\" ident \"->\" Expression /* abstraction */\n             | Expression Expression       /* application */\n\\end{verbatim}\n\n  \\item The abstract syntax becomes:\n\n  \\noindent \\Xtype \\type{expr} \\equal \\texttt{...} \\vbar \\cst{Fun}\n  \\Xof \\type{string} \\(\\times\\) \\type{expr} \\vbar \\cst{App}\n  \\Xof \\type{expr} \\(\\times\\) \\type{expr}\n\n  \\noindent where\n  \\begin{itemize*}\n\n    \\item \\cst{Fun} \\lpar$x$, $e$\\rpar{} denotes a function which\n      associates the expression~$e$, called the \\emph{body}, to the\n      variable~$x$, called the \\emph{parameter} (which may or may not\n      be free in~\\(e\\));\n\n    \\item \\cst{App} \\lpar$e_1$, $e_2$\\rpar{} represents the\n      application of an expression~$e_1$, which is expected to be\n      evaluated into an abstraction, to an expression~$e_2$, called\n      the \\emph{argument}.\n\n  \\end{itemize*}\n\n  \\item The syntax analysis needs to record the fact that abstraction\n    (respectively, application) has a lower (respectively, higher)\n    priority than operators. All we can do here is say:\n\\begin{align*}\n\\src{\\Xfun \\; x \\rightarrow \\meta{e}}\n  &= \\cst{Fun} \\, \\lpar{x}, e\\rpar,\\\\\n\\src{\\meta{e}_1 \\; \\meta{e}_2}\n  &= \\cst{App} \\, \\lpar e_1, e_2\\rpar.\n\\end{align*}\n\n\\end{itemize}\nWe want the language of our calculator to have the same semantics as\nthe subset of \\OCaml which its syntax coincides. The implementation of\nan interpreter or a compiler in the same language it interprets or\ncompile is called \\emph{bootstrapping}. For instance, the \\OCaml\ncompiler itself is bootstrapped, a first compiler being written\nin~\\Clang.\n\nWhat operational semantics can be ascribed to abstraction and\napplication?\n\nFirst, we need to extend the computation of the free variables of an\nexpression to abstractions and applications, like so:\n\\begin{equation*}\n\\left\\{\n\\begin{aligned}\n\\mathcal{F} \\src{\\Xfun \\; x \\rightarrow \\meta{e}} &= \n  \\mathcal{F} (e) \\backslash \\{x\\}\\\\\n\\mathcal{F} \\src{\\meta{e}_1 \\, \\meta{e}_2} &= \n  \\mathcal{F} (e_1) \\cup \\mathcal{F} (e_2)\n\\end{aligned}\n\\right.\n\\end{equation*}\nFor example, $\\mathcal{F} \\src{\\Xfun \\; \\ident{y} \\rightarrow \\ident{x}\n\\; \\texttt{+} \\; \\lpar\\Xfun \\; \\ident{x} \\rightarrow \\ident{x}\\rpar{}\n\\; \\ident{y}} = \\{\\ident{x}\\}$. Graphically, this is represented as in\n\\fig~\\vref{fig:fun_fv},\n\\begin{figure}\n\\centering\n\\includegraphics{fun_fv}\n\\caption{Variables bound in $\\mathcal{F} \\src{\\Xfun \\; \\ident{y}\n    \\rightarrow \\ident{x} \\; \\texttt{+} \\; \\lpar\\Xfun \\; \\ident{x}\n  \\rightarrow \\ident{x}\\rpar{} \\; \\ident{y}}$\n\\label{fig:fun_fv}}\n\\end{figure}\nwhere the free variable is framed.\n\n\\mypar{Abstraction and application}\n\nLet us try first the following semantics for the abstraction:\n\\begin{equation*}\n\\inferrule*[right=\\;\\, abs-dyn]\n  {}\n  {\\meval{\\rho} \n         {\\Xfun \\; x \\rightarrow \\meta{e}}\n         {\\src{\\Xfun \\; x \\rightarrow \\meta{e}}}}\n\\end{equation*}\nThe rule \\RefTirName{abs-dyn} implies that the programs in\n\\fig~\\vref{fig:equiv_src}\n\\begin{figure}\n\\centering\n\\subfloat[\\label{fig:first_src}]{\n\\begin{minipage}{0.2\\linewidth}{\n\\begin{tabbing}\n\\Xlet \\ident{x} \\equal \\num{1} \\Xin \\\\\n\\quad \\= \\Xlet \\ident{f} \\equal \\Xfun \\ident{y} \\(\\rightarrow\\)\n\\ident{x} \\texttt{+} \\ident{y} \\Xin \\\\\n\\> \\Xlet \\ident{x} \\equal \\num{2} \\\\\n\\Xin \\underline{\\ident{f}} \\ident{x}\n\\end{tabbing}}\n\\end{minipage}\n}\n\\qquad\n\\subfloat[\\label{fig:snd_src}]{\n\\begin{minipage}{0.2\\linewidth}{\n\\begin{tabbing}\n\\Xlet \\ident{x} \\equal \\num{1} \\Xin\\\\\n\\quad \\= \\Xlet \\ident{f} \\equal \\Xfun \\ident{y} \\(\\rightarrow\\)\n\\ident{x} \\texttt{+} \\ident{y} \\Xin\\\\ \n\\> \\Xlet \\ident{x} \\equal \\num{2}\\\\\n\\Xin \\underline{\\lpar\\Xfun \\ident{y} \\(\\rightarrow\\) \\ident{x} \\texttt{+}\n\\ident{y}\\rpar} \\ident{x}\n\\end{tabbing}}\n\\end{minipage}\n}\n\\caption{Two equivalent programs under rule \\RefTirName{abs-dyn} \\label{fig:equiv_src}}\n\\end{figure}\nare equivalent. Consider in \\fig~\\ref{fig:first_abs}\n\\begin{figure}[!t]\n\\centering\n\\includegraphics{first_abs}\n\\caption{AST of the program in \\fig~\\vref{fig:first_src}\\label{fig:first_abs}}\n\\end{figure}\nthe abstract syntax tree of the program in \\fig~\\ref{fig:first_src}\nand, in \\fig~\\ref{fig:snd_abs},\n\\begin{figure}[!b]\n\\centering\n\\includegraphics[bb=71 563 406 721]{snd_abs}\n\\caption{AST of the program in \\fig~\\vref{fig:snd_src}\\label{fig:snd_abs}}\n\\end{figure}\nthat of \\fig~\\ref{fig:snd_src}. The variable~\\ident{x} under the \\Xfun\nhas been \\emph{captured} by the third \\Xlet. (A fact denoted by a\ndashed line to the now incorrect binder.) This means that, with our\nsemantics \\RefTirName{abs-dyn}, the value of a variable may change\nover the course of the evaluation, depending on the current\nenvironment: this is called \\emph{dynamic binding}. Few programming\nlanguages feature it, notably Lisp, \\TeX{} and \\textsf{cpp} macros,\nbecause programs tend to be more difficult to understand and\nmaintain. In general, \\emph{static binding} --~also called\n\\emph{lexical scoping}~-- is preferred: the value of the free\nvariables in the body of functions is fixed at the declaration\nsite. The first program would then result in~3 and the second in~4. We\nmust come up with a semantics for the abstraction which respects\nreferential transparency (that is, the fact that a variable can be\nreplaced by its value between parentheses, without altering the\nmeaning of the embedding expression) and static binding.\n\n\\paragraph{Semantics for the application}\n\nIf functions are values, they can be returned by functions, that is,\nthey can be the value of an application. For instance:\n\\begin{tabbing}\n \\Xlet \\ident{add} \\equal \\Xfun \\ident{x} \\(\\rightarrow\\) \\Xfun\n \\ident{y} \\(\\rightarrow\\) \\ident{x} \\texttt{+} \\ident{y} \\Xin\\\\\n \\quad \\Xlet \\ident{incr} \\equal \\ident{add} \\num{1}\\\\\n \\Xin \\ident{incr} \\num{5}\n\\end{tabbing}\nThat kind of application is said to be \\emph{partial}, as opposed\nto \\emph{complete}, like (\\ident{add} \\num{1} \\num{5}). We have to\nfind a semantics for the application that enables partial\napplications.\n\n\\paragraph{Closures and typing}\n\nThe general solution to the above design constraints on the\nabstraction and the application consists in evaluating functions into\na new kind of value called \\emph{closure}. A closure\n$\\clos{x}{e}{\\rho}$ is made of a functional expression\n$\\cst{Fun} \\, \\lpar{x},e\\rpar$ and an environment~$\\rho$. We then have\nto redefine the type of values, like so:\n\n\\bigskip\n\n\\noindent\\Xtype \\type{value} \\equal \\cst{Int} \\Xof \\type{int} \\vbar\n\\cst{Clos} \\Xof \\type{string} \\(\\times\\) \\type{expr} \\(\\times\\)\n\\lpar\\type{string} $\\rightarrow$ \\type{value}\\rpar\\textsf{;;}{}\n\n\\bigskip\n\n\\noindent and also the implementation of the \\OCaml function \\ident{eval}. Note\nthat expressions can make inconsistent assumptions with regards to\ntheir context, what is called \\emph{typing errors}, in particular,\narithmetic operations must have integer operands and only functions\ncan be called.\n\n\\paragraph{Semantics for abstraction and application}\n\n\\begin{mathpar}\n\\inferrule*[right=\\;\\, abs]\n  {\\meval{\\rho}\n         {\\Xfun \\; x \\rightarrow \\meta{e}}\n         {\\clos{x}{e}{\\rho}}}\n  {}\n\\and\n\\inferrule*[right=app]\n  {\\eval{\\rho}{e_1}{\\clos{x_0}{e_0}{\\rho_0}}\\\\\n   \\eval{\\rho}{e_2}{v_2}\\\\\n   \\eval{x_0 \\mapsto v_2 \\oplus \\rho_0}{e_0}{v_0}\n  }\n  {\\meval{\\rho}{\\meta{e}_1 \\; \\meta{e}_2}{v_0}}\n\\end{mathpar}\nThe implementation of rule \\RefTirName{App} should evaluate~$e_1$\nbefore~$e_2$ in order to check if~$e_1$ indeed is evaluated into a\nclosure --~otherwise, we save time by signalling an error at an early\nstage. As for rule \\RefTirName{Abs}, we can restrict the\nenvironment~$\\rho$ in a closure $\\clos{x}{e}{\\rho}$ to the free\nvariables of the function $\\cst{Fun} \\, \\lpar{x},e\\rpar$:\n\\begin{equation*}\n\\inferrule*[right=\\;\\, abs-opt]\n     {\\eval{\\rho}\n           {\\src{\\Xfun \\; x \\rightarrow \\meta{e}} \\, \\Xas \\, f}\n           {\\clos{x}{e}{\\rho\\arrowvert\\mathcal{F}(f)}}}\n     {}\n\\end{equation*}\nwhere \\(\\rho \\arrowvert d\\) is~\\(\\rho\\) restricted to the domain~\\(d\\)\nand `\\(e \\; \\Xas \\; x\\)' binds the metavariable~\\(x\\) to the\nexpression~\\(e\\).\n\n\\paragraph{Evaluation strategies}\n\nIn the rule \\RefTirName{App}, the expression~\\(e_1\\) is first\nevaluated into a closure to which is passed the value~\\(v_1\\)\nof~\\(e_1\\): that strategy is called \\emph{call by value}, or\n\\emph{strict semantics}, in use in programming languages like \\OCaml\nand \\Java. Other languages, notably \\Haskell and \\Clean, feature a\nstrategy called \\emph{call by name} or \\emph{lazy evaluation}, which\nconsists in passing the non\\hyp{}evaluated argument~\\(e_1\\) to the\nclosure, to be evaluated only if the result requires it. An\noptimisation of call by name is \\emph{call by need}, whereby the same\nexpression is not recomputed, as their values are cached by the\nrun\\hyp{}time.\n\n\\paragraph{Non-termination}\n\nIn theory, we can already use our calculator to compute anything\ncomputed by the underlying computer. For instance, we already have the\npower of recursion thanks to the auto\\hyp{}application, as\ndemonstrated by the following non\\hyp{}terminating program:\n\\begin{center}\n\\Xlet \\ident{omega} \\equal \\Xfun \\ident{f} $\\rightarrow$ \\ident{f}\n\\ident{f} \\Xin \\ident{omega} \\ident{omega}\n\\end{center}\nThe operational style we followed up to this point evaluates an\nexpression into its value, but this is not practical when studying the\ntermination of computations. For the previous program, this issue\nwould manifest itself as the occurrence in the derivation of\n\\begin{mathpar}\n\\inferrule\n  {\\meval{\\rho}{\\ident{f}\\,}{v_1}\\\\\n   \\eval{\\str{f} \\mapsto v_1 \\oplus \\rho}\n        {\\src{\\ident{f} \\; \\ident{f}\\,}}\n        {v}\n  }\n  {\\eval{\\rho}\n        {\\src{\\ident{f} \\; \\ident{f}\\,}}\n        {v}\n  }\n\\end{mathpar}\nThe first premise states that $\\rho(\\str{f}) = v_1$, hence $\\rho =\n\\str{f} \\mapsto v_1 \\oplus \\rho$, therefore the conclusion and the\nsecond premise are identical, implying that the evaluation never ends.\n\nA programming language featuring a conditional construct and\nrecursion or auto\\hyp{}application enables the specification of all\ncomputations available to the underlying computer: it is\n\\emph{Turing\\hyp{}complete}. This property is very useful, but it\nentails the existence of non\\hyp{}terminating programs and the\nnonexistence of programs which can recognise them all (by G{\\\"o}del's\nincompleteness theorem). A very rough sketch of the idea is as\nfollows. Let us use \\emph{reductio ad absurdum} and suppose the\nexistence of a predicate for termination. Let~$f$ be the function such\nthat for all function~$g$, if~$g$ always terminates (that is, for\nall~$x$, $g(x)$ is defined), then $f(g)$ does not terminate;\notherwise, $f(g)$ terminates. Therefore, $f(f)$ does not terminate\nis~$f$ terminates, and $f(f)$ terminates if~$f$ does not terminate.\nThis is a contradiction from which we deduce that the hypothesis is\nfalse and there is no termination predicate.\n\n\\mypar{Recursive functions}\n\nTo bring to the fore the expressiveness of our toy language, let us\ndefine functions with the help of the auto\\hyp{}applicative\nfunction \\ident{omega}. First, let us define a function \\ident{fix},\ntraditionally called the \\emph{Y~combinator}:\n\\begin{tabbing}\n\\Xlet \\ident{omega} \\equal \\Xfun \\ident{f} $\\rightarrow$ \\ident{f}\n\\ident{f} \\Xin\\\\\n\\quad \\Xlet \\ident{fix} \\equal \\Xfun \\ident{g} $\\rightarrow$\n\\ident{omega} \\lpar\\Xfun \\ident{h} $\\rightarrow$ \\underline{\\Xfun \\ident{x}\n$\\rightarrow$} \\ident{g} \\lpar\\ident{h} \\ident{h}\\rpar{} \\underline{\\ident{x}}\\rpar{}\n\\Xin\\\\\n\\quad \\texttt{...}\n\\end{tabbing}\nNote the underlined code (technically, an \\(\\eta\\)-expansion),\nnecessary to deal with a strict semantics. It is possible, albeit\nrather tedious, to show that the evaluation of \\lpar\\ident{fix}\n\\ident{f} \\ident{x}\\rpar{} has the pattern\n\\begin{mathpar}\n\\inferrule\n  {\\ldots\\\\\n   \\inferrule*[vdots=1.5em]\n     {\\ldots \\\\\n      \\meval{\\rho}\n            {\\ident{f} \\; \\lpar\\ident{fix} \\; \\ident{f}\\rpar{} \\; \\ident{x}}\n            {v}}\n     {\\ldots}}\n  {\\meval{\\rho}\n         {\\lpar\\ident{fix} \\; \\ident{f}\\rpar{} \\; \\ident{x}}\n         {v}}\n\\end{mathpar}\nIn other words, for all \\ident{x}, \\lpar\\ident{fix} \\ident{f}\\rpar{}\n\\ident{x} \\equal \\ident{f} \\lpar\\ident{fix} \\ident{f}\\rpar{}\n\\ident{x}, that is, \\lpar\\ident{fix} \\ident{f}\\rpar{} \\equal \\ident{f}\n\\lpar\\ident{fix} \\ident{f}\\rpar{}. Also, by definition, the fixed\npoint~$p$ of a function~$f$ satisfies $p = f(p)$. Therefore, the fixed\npoint of a function~\\ident{f}, if it exists, is \\lpar\\ident{fix}\n\\ident{f}\\rpar{}.\n\n\\paragraph{Factorial revisited}\n\nLet\n\\begin{tabbing}\n\\quad \\Xlet \\ident{pre\\_fact} \\equal \\Xfun \\ident{f} $\\rightarrow$\n\\Xfun \\ident{n} $\\rightarrow$ \\kwd{ifz} \\ident{n} \\Xthen \\num{1}\n\\Xelse \\ident{n} \\texttt{*} \\ident{f}\n\\lpar\\ident{n}\\texttt{-}\\num{1}\\rpar{} \\Xin\\\\\n\\quad \\Xlet \\ident{fact} \\equal \\ident{fix} \\ident{pre\\_fact}\n\\Xin \\texttt{...}\n\\end{tabbing}\nTherefore, \\ident{fact} is the fixed point of \\ident{pre\\_fact}, if\nany, that is to say\n\\begin{center}\n\\ident{fact} \\equal \\ident{pre\\_fact} \\ident{fact} \\equal \\Xfun\n\\ident{n} $\\rightarrow$ \\kwd{ifz} \\ident{n} \\Xthen \\num{1} \\Xelse\n\\ident{n} \\texttt{*} \\ident{fact}\n\\lpar\\ident{n}\\texttt{-}\\num{1}\\rpar.\n\\end{center}\nTherefore, \\ident{fact} is the factorial function, because it\nsatisfies the defining recurrent equations.\n\n\\paragraph{Local recursive binding}\n\nFor additional flexibility, let us extend the syntax with a local\nrecursive binding, as follows:\n\\begin{itemize}\n\n  \\item Concrete syntax\\\\\n\\texttt{Expression ::= ...}\\\\\n\\texttt{\\hphantom{Expression} | \"let rec\" ident \"=\" Expression \"in\" Expression}\n\n  \\item Abstract syntax\\\\\n  \\Xtype \\type{expr} \\equal \\texttt{...} \\vbar \\cst{LetRec} \\Xof\n  \\type{string} \\(\\times\\) \\type{expr} \\(\\times\\) \\type{expr}\\textsf{;;}\n\n  \\medskip \n\n  \\item Syntax analysis\\\\\n  $\\src{\\Xlet \\; \\Xrec \\;\n  x \\; \\equal \\; \\meta{e}_1 \\; \\Xin \\; \\meta{e}_2}\n  = \\cst{LetRec} \\, \\lpar x, e_1, e_2\\rpar$\n\n  \\medskip \n\n  \\item Free variables\\\\ $\\mathcal{F} \\src{\\Xlet \\;\n  \\Xrec \\; x \\; \\equal \\; \\meta{e}_1 \\; \\Xin \\; \\meta{e}_2}\n  = (\\mathcal{F} (e_1) \\cup \\mathcal{F} (e_2)) \\backslash \\{x\\}$\n\n\\end{itemize}\nWe can define the operational semantics of that construct in two\nways. The first consists in not considering it as elementary (native),\nand express its semantics in terms of another construct and, in this\ninstance, assuming that the operator \\ident{fix} is predefined:\n\\begin{mathpar}\n\\inferrule*[right=let-rec]\n  {\\meval\n     {\\rho}\n     {\\Xlet \\; x \\; \\equal \\; \\ident{fix} \\; \\lpar\\Xfun \\; x \\rightarrow\n      \\meta{e}_1\\rpar{} \\; \\Xin \\; \\meta{e}_2}\n     {v}\n  }\n  {\\meval\n     {\\rho}\n     {\\Xlet \\; \\Xrec \\; x \\; \\equal \\; \\meta{e}_1 \\; \\Xin \\; \\meta{e}_2}\n     {v}\n  }\n\\end{mathpar}\nThe second way consists in considering that construct as different\nfrom the others:\n\\begin{mathpar}\n\\inferrule*[right=let-rec]\n   {\\eval{x \\mapsto v_1 \\oplus \\rho}{e_1}{v_1}\\\\\n    \\eval{x \\mapsto v_1 \\oplus \\rho}{e_2}{v_2}}\n   {\\meval{\\rho}{\\Xlet \\; \\Xrec \\; x \\; \\equal \\; \\meta{e}_1\n    \\; \\Xin \\; \\meta{e}_2}{v_2}}\n\\end{mathpar}\nThe straightforward implementation of the latter rule is\n\\begin{tabbing}\n \\Xlet \\= \\Xrec \\ident{eval} \\ident{env} \\ident{e} \\equal\n \\Xmatch \\ident{e} \\Xwith \\texttt{...} \\\\ \n \\vbar \\> \\cst{LetRec} \\lpar\\ident{x},\\ident{e}$_1$,\\ident{e}$_2$\\rpar{}\n $\\rightarrow$\\\\\n \\> \\quad \\Xlet \\Xrec \\ident{env'} \\equal \\ident{extend} \n \\lpar\\ident{x},\\ident{v}$_1$\\rpar{} \\ident{env}\\\\\n \\> \\quad \\Xand \\ident{v}$_1$ \\equal \\ident{eval} \\ident{env'} \\ident{e}$_1$\\\\\n \\> \\quad \\Xin \\ident{eval} \\ident{env'} \\ident{e}$_2$\n\\end{tabbing}\n\\noindent For technical reasons linked to the type system of \\OCaml\n(the so\\hyp{}called \\emph{value restriction} on recursive values), we\nactually have to write:\n\\begin{tabbing}\n \\Xlet \\= \\Xrec \\ident{eval} \\ident{env} \\ident{e} \\equal\n \\Xmatch \\ident{e} \\Xwith \\texttt{...} \\\\ \n \\vbar \\> \\cst{LetRec}\n \\lpar\\ident{x},\\ident{e}$_1$,\\ident{e}$_2$\\rpar{} $\\rightarrow$\\\\\n \\> \\quad \\Xlet \\Xrec \\ident{env'} \\equal \\underline{\\Xfun\n \\ident{x} $\\rightarrow$} \\ident{extend} \n \\lpar\\ident{x}, \\ident{v}$_1$\\underline{\\lpar\\rpar}\\rpar{} \\ident{env} \\underline{\\ident{x}}\\\\\n \\> \\quad \\Xand \\ident{v}$_1$ \\equal \\underline{\\Xfun \\lpar\\rpar{}\n $\\rightarrow$} \\ident{eval} \\ident{env'} \\ident{e}$_1$\\\\\n \\> \\quad \\Xin \\ident{eval} \\ident{env'} \\ident{e}$_2$\n\\end{tabbing}\nA multiple \\Xlet \\Xrec (with \\Xand) can always be reduced to\na simple \\Xlet \\Xrec (with \\Xin) by parameterising one of the\ndefinitions by the other. Let\n\\begin{center}\n\\Xlet \\Xrec $x$ \\equal $\\meta{e}_1$ \\Xand $y$ \\equal $\\meta{e}_2$ \\Xin\n$\\meta{e}$\n\\end{center}\nwhere $x \\neq y$. It is equivalent, by definition, to\n\\begin{tabbing}\n\\Xlet \\= \\Xrec $x$ \\equal \\underline{\\Xfun $y$\n  $\\rightarrow$} $\\meta{e}_1$ \\Xin\\\\\n\\> \\Xlet \\Xrec $y$ \\equal \\underline{\\Xlet $x$ \\equal $x \\, y$\n  \\Xin} $\\meta{e}_2$ \\Xin\\\\\n\\> \\underline{\\Xlet $x$ \\equal $x \\, y$}\\\\\n\\underline{\\Xin} $\\meta{e}$\n\\end{tabbing}\nWe can then encode the simple \\Xlet \\Xrec with \\ident{fix}, or else\nconsider it as native to the interpreted language. In both cases,\nthere is no need to extend the operational semantics.\n\nNevertheless, we should think about generalising our syntactic\nequivalence to~\\(n\\) variables:\n\\begin{center}\n\\Xlet \\Xrec $x_1$ \\equal $\\meta{e}_1$ \\Xand $x_2$ \\equal\n$\\meta{e}_2$ \\Xand~\\ldots~\\Xand $x_n$ \\equal $\\meta{e}_n$ \\Xin\n$\\meta{e}$\n\\end{center}\n\n\\paragraph{Parallel definitions}\n\nWe can add to our language the construct\n\\begin{center}\n\\Xlet $x$ \\equal $\\meta{e}_1$ \\Xand $y$ \\equal\n$\\meta{e}_2$ \\Xin $\\meta{e}$\n\\end{center}\nwhere $x \\neq y$. If~$x \\in \\mathcal{F}(e_2)$, we define it as being\nequivalent to\n\\begin{tabbing}\n\\underline{\\Xlet} \\= \\underline{$z$ \\equal $x$ \\Xin}\\\\\n\\> \\Xlet $x$ \\equal $\\meta{e}_1$ \\Xin\\\\\n\\> \\Xlet $y$ \\equal \\underline{\\Xlet $x$ \\equal $z$ \\Xin} $\\meta{e}_2$\\\\\n\\Xin $\\meta{e}$\n\\end{tabbing}\nwhere\n$z \\not\\in \\mathcal{F}(e_1) \\cup \\mathcal{F}(e_2) \\cup \\mathcal{F}(e)$,\nin order to avoid capture by~$e_1$, $e_2$, or~$e$. Therefore, there is\nno need to extend the operational semantics to cope with this\nconstruct: an equivalence between abstract syntax trees is sufficient\nto provide the meaning. Nevertheless, we should care to generalise\nthat equivalence:\n\\begin{center}\n\\Xlet $x_1$ \\equal $\\meta{e}_1$ \\Xand $x_1$ \\equal\n$\\meta{e}_2$ \\Xand~\\ldots~\\Xand $x_n$ \\equal $\\meta{e}_n$\n\\Xin $\\meta{e}$\n\\end{center}\n\n\\paragraph{Occam's razor}\n\nThe observation of the rules \\RefTirName{let}, on the one hand, and\n\\RefTirName{abs} and \\RefTirName{app}, on the other hand, leads us to\nrealise that the rule \\RefTirName{let} can be removed without\nconsequence on the expressivity of the language. More precisely, we\nwill prove that the constructs \\kwd{let} $x$ \\equal{}\n$\\meta{e}_1$ \\kwd{in} $\\meta{e}_2$ and \\lpar\\kwd{fun} $x$\n$\\rightarrow$ $\\meta{e}_2$\\rpar{} $\\meta{e}_1$ are equivalent from the\nstandpoint of evaluation, that is to say, one yields a value~$v$ if\nand only if the other yields~$v$ as well.\n\nThe rule \\RefTirName{app} can be rewritten by swapping~$e_1$ and~$e_2$:\n\\begin{mathpar}\n\\inferrule\n  {\\eval{\\rho}{e_2}{\\clos{x_0}{e_0}{\\rho_0}}\\\\\n   \\eval{\\rho}{e_1}{v_1}\\\\\n   \\eval{x_0 \\mapsto v_1 \\oplus \\rho_0}{e_0}{v_0}\n  }\n  {\\meval{\\rho}{\\meta{e}_2 \\; \\meta{e}_1}{v_0}}\n\\end{mathpar}\nBy substituting $\\Xfun \\; x \\rightarrow \\, \\meta{e}_2$ in stead\nof~$\\meta{e}_2$, we draw\n\\begin{mathpar}\n\\inferrule\n  {\\meval{\\rho}{\\Xfun \\; x \\rightarrow \\, \\meta{e}_2}\n        {\\clos{x_0}{e_0}{\\rho_0}}\\\\\n   \\eval{\\rho}{e_1}{v_1}\\\\\n   \\eval{x_0 \\mapsto v_1 \\oplus \\rho_0}{e_0}{v_0}\n  }\n  {\\meval\n     {\\rho}\n     {\\lpar\\Xfun \\; x \\rightarrow \\, \\meta{e}_2\\rpar{} \\; \\meta{e}_1}\n     {v_0}\n  }\n\\end{mathpar}\nThe axiom \\RefTirName{abs} states\n\\(\\inferrule\n  {\\meval{\\rho}\n         {\\Xfun \\; x \\rightarrow \\meta{e}_2}\n         {\\clos{x}{e_2}{\\rho}}}\n  {}\\),\nhence $x = x_0$, $e_2 = e_0$ and $\\rho = \\rho_0$, which implies, by\nsubstituting in the penultimate rule and renaming $v_0$ into~$v_2$:\n\\begin{mathpar}\n\\inferrule\n  {\\meval{\\rho}{\\Xfun \\; x \\rightarrow \\, \\meta{e}_2}\n        {\\clos{x}{e_2}{\\rho}}\\\\\n   \\eval{\\rho}{e_1}{v_1}\\\\\n   \\eval{x \\mapsto v_1 \\oplus \\rho}{e_2}{v_2}\n  }\n  {\\meval\n     {\\rho}\n     {\\lpar\\Xfun \\; x \\rightarrow \\, \\meta{e}_2\\rpar{} \\; \\meta{e}_1}\n     {v_2}\n  }\n\\end{mathpar}\nSince an axiom is, by definition, true, we can remove it from a\npremise:\n\\begin{mathpar}\n\\inferrule\n  {\\eval{\\rho}{e_1}{v_1}\\\\\n   \\eval{x \\mapsto v_1 \\oplus \\rho}{e_2}{v_2}\n  }\n  {\\meval\n     {\\rho}\n     {\\lpar\\Xfun \\; x \\rightarrow \\, \\meta{e}_2\\rpar{} \\; \\meta{e}_1}\n     {v_2}\n  }\n\\end{mathpar}\nThe rule \\RefTirName{let} is\n\\begin{mathpar}\n\\inferrule*[right=let]\n  {\\eval{\\rho}{e_1}{v_1}\\\\ \n   \\eval{x \\mapsto v_1 \\oplus \\rho}{e_2}{v_2}}\n  {\\meval{\\rho}{\\Xlet \\; x \\; \\equal \\; \\meta{e}_1 \\; \\Xin\n  \\; \\meta{e}_2}{v_2}}\n\\end{mathpar}\nThe premisses are the same as in the previous rule, therefore the\nconclusions are identical, which was to be demonstrated. It is thus\npossible, in theory, to do without the local bindings in our language,\neither at the level of the semantics, or the abstract syntax. (This\nsituation will change when type inference will come into play later\non.)\n\nIn general, when a programming construct is found to have the same\nsemantics as a combination of other constructs, it is best to retain\nthat construct in the abstract syntax because this allows the lexer to\nassign physical locations to the corresponding lexemes, in view of\npossible error messages. Indeed, the other option, consisting in\nproducing the abstract syntax tree of the combination at\nparse\\hyp{}time, loses that information, although the semantics is\nlikely simpler, like stating\n\\begin{mathpar}\n\\inferrule*[right=let]\n  {\\meval\n     {\\rho}\n     {\\lpar\\Xfun \\; x \\rightarrow \\, \\meta{e}_2\\rpar{} \\; \\meta{e}_1}\n     {v_2}\n  }\n  {\\meval{\\rho}{\\Xlet \\; x \\; \\equal \\; \\meta{e}_1 \\; \\Xin\n  \\; \\meta{e}_2}{v_2}\n  }\n\\end{mathpar}\n\n\\mypar{Imperative programming}\n\nUntil now, variables were actually constants: once assigned, their\nvalue remain unchanged during the course of evaluation. In this\nsection, we are going to show how we can model variables whose values\ndo really vary over time, that is, they \\emph{mutate}. The programming\nstyle based on the use of such variables is called \\emph{imperative},\nor \\emph{effectful}.\n\nEven though, for the sake of the presentation, we wish to have all\nvariable become mutable, we nevertheless would like to be able to\ndistinguish at the level of the concrete syntax their mutations by\nmeans of assignments. For example \\Xlet \\ident{x} \\equal \\num{1} \\Xin\n\\Xlet \\ident{y} \\equal \\lpar\\ident{x} \\assign \\ident{x} \\texttt{+}\n\\num{2}\\rpar{} \\Xin \\ident{x} is evaluated into \\cst{Int} \\num{3}, and\n\\ident{x} \\assign \\ident{x} \\texttt{+} \\num{2} is an assignment.\n\n\\paragraph{A functional model for mutable variables}\n\nIn order to model mutable variables in a purely functional setting, we\nhave to introduce the new concepts of \\emph{address} and \\emph{store}\n(or \\emph{memory}). An address is an element of a numerable,\ninfinite set --~very much like variables. A store~$\\sigma$ binds\naddresses~$a$ to values~$v$. An environment~$\\rho$ has to be redefined\nnow to bind a variable~$x$ to its address~$a$, and not to its value\ndirectly as before. This is how we can hide a binding by another in\nthe store without changing the environment, which effectfully models\nassignments in a functional manner. Therefore, we do not need a native\nnotion for assignment in the semantics: as far as the interpreter is\nconcerned, if it is itself written in a functional language, that\nlanguage can remain pure.\n\nNext, we either introduce the notion of \\emph{instruction}, as found\nin programming languages like~\\Clang and \\Java, or we extend the\nexpressions, as does \\OCaml. In the latter case, we need to add a\nspecial value which is the result of the evaluation of an assignment:\nthe value \\cst{Unit}. For instance, \\ident{x} \\assign \\num{2} is\nevaluated into \\cst{Unit}.\n\nFor the sake of generality and simplicity, it is good to also add an\nexpression which is evaluated immediately into \\cst{Unit}. We will\nnote it \\lpar\\rpar, after the convention in \\OCaml, like\n\\Xlet \\ident{f} \\equal \\Xfun \\ident{x} $\\rightarrow$ \\num{1}\n\\Xin \\ident{f} \\lpar\\rpar. Note that we must distinguish the\nvalue \\cst{Unit} and the corresponding expression, which we will\ndenote by \\cst{U} in the abstract syntax.\n\\begin{itemize}\n\n  \\item Concrete syntax\\\\\n\\texttt{Expression ::= ... | ident \":=\" Expression | ()}\n\n  \\item Abstract syntax\\\\\n     \\Xtype \\type{expr} \\equal \\texttt{...} \\vbar \\cst{Assign} \\Xof\n    \\type{string} \\(\\times\\) \\type{expr} \\vbar \\cst{U}\\textsf{;;}{} \n\n  \\item Syntax analysis\\\\\n  $\\src{x \\; \\assign \\; \\meta{e}} = \\cst{Assign} \\, \\lpar{x},\n  e\\rpar$, and $\\src{\\unit} = \\cst{U}$.\n\n  \\item Free variables\\\\\n  $\\mathcal{F} \\src{x \\; \\assign \\; \\meta{e}} = \\{x\\} \\cup \\mathcal{F}(e)$,\n  and $\\mathcal{F}\\src{\\lpar\\rpar} = \\varnothing$.\n\n  \\item Operational semantics\n\n  We need to revisit our judgement and inference rules and have\n  instead $\\ieval{\\rho}{\\sigma}{e}{v}{\\sigma'}$, meaning: `Given the\n  context made of the environment~$\\rho$ and the store~$\\sigma$, the\n  evaluation of~$e$ yields the value~$v$ and a new store~$\\sigma'$.'\n\n\\end{itemize}\nFirst, here are the simpler inference rules (to contrast with \n\\RefTirName{var} above):\n\\begin{mathpar}\n\\inferrule\n  {}\n  {\\ieval{\\rho}{\\sigma}{\\src{\\lpar\\rpar}}{\\cst{Unit}}{\\sigma}}\n  {}\\;\\,\\TirName{unit}\n\\and\n\\inferrule\n  {x \\in \\dom{\\rho}\\\\\n   \\rho(x) \\in \\dom{\\sigma}}\n  {\\ieval{\\rho}{\\sigma}{\\src{x}}{\\sigma \\circ \\rho (x)}{\\sigma}}\n  {}\\;\\TirName{var}\n\\end{mathpar}\nIn order to access the content of a variable, we thus have to go\nthrough the environment and the store, and that is why we must make\nsure that $x \\in \\dom{\\rho}$ and $\\rho(x) \\in \\dom{\\sigma}$. Our new\njudgement $\\ieval{\\rho}{\\sigma}{e}{v}{\\sigma'}$ must satisfy the\nfollowing property:\n\\begin{center}\n\\sl if $\\codom{\\rho} \\subseteq \\dom{\\sigma}$, then\n$\\dom{\\sigma} \\subseteq \\dom{\\sigma'}$,\n\\end{center}\nthat is to say, the evaluation may hide a binding by another in the\nstore, or add a new binding, but cannot retract any --~it is\nmonotonic. Again, in other words, when the evaluation is over,\nvariables still have an associated value, potentially different from\ntheir initial value.\n\n\\paragraph{Proof by induction on the length of the derivations}\n\nThe operational semantics enables a kind of proof called `by induction\non the length of the derivation (or the height of the proof\ntrees)'. By \\emph{derivation}, we either mean a proof tree which is\nisomorphic to a list, or a subtree of the proof tree, in which case\nthe proper measure would be the height. The sketch of this technique\nis as follows. First, the property to establish is checked on the\naxioms (derivation of length~\\(1\\)). Second, we assume that the\nproperty is true for all the derivations of length~\\(n-1\\), and we\nprove that all the derivations of length~\\(n\\) by examining all\navailable rules, and imagining that they are the roots of a proof of\nlength~\\(n\\). By the induction hypothesis, the premisses satisfy the\nproperty, because their derivation has a length strictly lower\nthan~\\(n\\).\n\nLet us try an example by considering the following property:\n\\begin{center}\n\\sl If $\\ieval{\\rho}{\\sigma}{e}{v}{\\sigma'}$ and $\\codom{\\rho} \\subseteq\n \\dom{\\sigma}$, then $\\dom{\\sigma} \\subseteq \\dom{\\sigma'}$.\n\\end{center}\nIt is clearly satisfied by all the axioms. Assignments hide the\nbinding of a variable in the store:\n\\begin{mathpar}\n\\inferrule*[right=assign]\n  {\\ieval{\\rho}{\\sigma}\n         {e}\n         {v}{\\sigma'}\\\\\n   x \\in \\dom{\\rho}\\\\\n   \\rho(x) \\in \\dom{\\sigma'}\n  }\n  {\\ieval{\\rho}{\\sigma}\n         {\\src{x \\; \\assign \\; \\meta{e}}}\n         {\\cst{Unit}}{(\\rho(x) \\mapsto v \\oplus \\sigma')}\n  }\n\\end{mathpar}\nThat rule satisfies the property at hand. Indeed, by the induction\nhypothesis (on the length of the derivation), the first premisse\nimplies that, if $\\codom{\\rho} \\subseteq \\dom{\\sigma}$, then\n$\\dom{\\sigma} \\subseteq \\dom{\\sigma'}$. The third premisse then\nimplies $\\dom{\\rho(x) \\mapsto v \\oplus \\sigma'} = \\dom{\\sigma'}$, thus\n$\\dom{\\sigma} \\subseteq \\dom{(\\rho(x) \\mapsto v \\oplus \\sigma')}$. We\nneed~$\\sigma$ because it may be the case that the evaluation of~$e$\nhides bindings of~\\(\\sigma\\) other than~\\(\\rho \\mapsto v\\), and we\nmust consider these possible occlusions. For instance,\n\\begin{center}\n\\Xlet \\ident{x} \\equal \\num{1} \\Xin \\Xlet \\ident{y} \\equal \\num{2}\n\\Xin \\Xlet \\ident{z} \\equal \\lpar\\ident{x} \\assign \\lpar\\ident{y} \\assign\n\\num{3}\\rpar\\!\\rpar{} \\Xin \\ident{y}\n\\end{center}\nis evaluated into \\cst{Int} \\num{3}.\n\nThe rule \\RefTirName{let} introduces a new binding in the environment\nand the store, which obeys the invariant above:\n\\begin{mathpar}\n\\inferrule*[right=let]\n  {\\ieval{\\rho}{\\sigma}{e_1}{v_1}{\\sigma_1}\\\\\n   a \\not\\in \\dom{\\sigma_1}\\\\\\\\\n   \\ieval{(x \\mapsto a \\oplus \\rho)}{(a \\mapsto v_1 \\oplus \\sigma_1)}\n         {e_2}\n         {v_2}{\\sigma_2}\n  }\n  {\\ieval{\\rho}{\\sigma}{\\src{\\Xlet \\,\\ x \\; \\equal \\; \\meta{e}_1\n  \\; \\Xin \\; \\meta{e}_2}}{v_2}{\\sigma_2}}\n\\end{mathpar}\nIndeed, if $\\codom{\\rho} \\subseteq \\dom{\\sigma}$, then, by the\ninduction hypothesis (on the length of the derivation of the first\npremisse), we have $\\dom{\\sigma} \\subseteq \\dom{\\sigma_1}$, thus, by\ntransitivity, $\\codom{\\rho} \\subseteq \\dom{\\sigma_1}$, whence\n$\\codom{(x \\mapsto a \\oplus \\rho)} \\subseteq \\dom{(a \\mapsto v_1\n  \\oplus \\sigma_1)}$. From the induction hypothesis on the third\npremisse, this entails that $\\dom{(a \\mapsto v_1 \\oplus \\sigma_1)}\n\\subseteq \\dom{\\sigma_2}$. But $a \\not\\in \\dom{\\sigma_1}$ implies\n$\\dom{\\sigma_1} \\subset \\dom{(a \\mapsto v_1 \\oplus \\sigma_1)}$,\ntherefore $\\dom{\\sigma} \\subset \\dom{\\sigma_2}$. In particular, there\nis no equality.\n\n\\paragraph{Garbage collection}\n\nWhen we introduced the environments in the semantics, we saw that\nlocal bindings could mask other bindings. With the addition of stores,\nwe realise that local bindings can hide and add bindings in the store\nwhich are not accessible from the environment. In both cases, bindings\nin the environment or the store become definitively inaccessible,\ntherefore the space the corresponding value occupy in the memory of\nthe computer is lost for the rest of the evaluation. That is why the\ncompilers of certain programming languages, like \\OCaml, \\Java\nand \\Ada, generate a code that dynamically performs an accessibility\nanalysis on the data, and it devolves back to the underlying process\nthe space used by the inaccessible cells: this is the \\emph{garbage\ncollector}.\n\n\\paragraph{Order of evaluation}\n\nWe need to fix the order of evaluation of the arithmetic operands in\nthe semantics in order to keep track, in the store, of the effects of\nthe assignments which may have taken place during the evaluation of\nthe operands:\n\\begin{mathpar}\n\\inferrule\n  {\\ieval{\\rho}{\\sigma}{\\src{\\meta{n}}}{\\dot{n}}{\\sigma}}\n  {}\\;\\,\\TirName{const}\n\\and\n\\inferrule\n  {\\ieval{\\rho}{\\sigma}{e_1}{v_1}{\\sigma_1}\\\\ \n   \\ieval{\\rho}{\\sigma_1}{e_2}{v_2}{\\sigma_2}}\n  {\\ieval{\\rho}{\\sigma}{\\src{\\meta{e}_1 \\, \\texttt{+} \\, \\meta{e}_2}}\n         {v_1 + v_2}{\\sigma_2}}\n  {}\\;\\,\\TirName{add}\n\\end{mathpar}\n(The other arithmetic rules would follow the same schema.) It is\nnevertheless always possible that the documentation of the compiler\nstates that the order is left unspecified, leaving room for the\ncompiler's implementors to modify the order as they see fit, for\nexample to perform some platform\\hyp{}dependent optimisations.\n\nThe semantics with mutation for the abstraction and the application is\nas follows:\n\\begin{mathpar}\n\\inferrule*[right=\\;\\, abs]\n  {\\ieval{\\rho}{\\sigma}\n         {\\src{\\Xfun \\; x \\rightarrow \\meta{e}}}\n         {\\clos{x}{e}{\\rho}}{\\sigma}}\n  {}\n\\and\n\\inferrule*[right=app]\n  {\\ieval{\\rho}{\\sigma}{e_1}{\\clos{x_0}{e_0}{\\rho_0}}{\\sigma_1}\\\\\n   \\ieval{\\rho}{\\sigma_1}{e_2}{v_2}{\\sigma_2}\\\\\n   a \\not\\in \\dom{\\sigma_2}\\\\\n   \\ieval{(x_0 \\mapsto a \\oplus \\rho_0)}{(a \\mapsto v_2 \\oplus \\sigma_2)}\n         {e_0}\n         {v_0}{\\sigma_3}\n  }\n  {\\ieval{\\rho}{\\sigma}{\\src{\\meta{e}_1 \\; \\meta{e}_2}}{v_0}{\\sigma_3}}\n\\end{mathpar}\nIn comparison with the semantics without mutation, the order of\nevaluation is here fixed in the semantics: \\(e_1\\)~is evaluated\nbefore~\\(e_2\\), in order to check first that~\\(e_1\\) is indeed\nevaluated into a closure (if not, we save time by signalling an error\nas early as possible). Furthermore, the fact that $a \\not\\in\n\\codom{\\rho}$ allows us to forget the assignments on the parameter,\nfor example, \\Xlet \\ident{f} \\equal \\Xfun \\ident{x} $\\rightarrow$\n\\ident{x} \\assign \\ident{x} \\texttt{+} \\num{1} \\Xin \\ident{f} \\num{3}.\n\nThe semantics with mutation of the native recursive expressions is as follows.\n\\begin{mathpar}\n\\inferrule*[right=let-rec]\n  {a \\not\\in \\dom{\\sigma}\\\\\\\\\n   \\ieval\n     {(x \\mapsto a \\oplus \\rho)}\n     {(a \\mapsto v_1 \\oplus \\sigma)}\n     {e_1}{v_1}{\\sigma_1}\\\\\n   \\ieval\n     {(x \\mapsto a \\oplus \\rho)}\n     {\\sigma_1}\n     {e_2}{v_2}{\\sigma_2}\n  }\n  {\\ieval{\\rho}{\\sigma}{\\src{\\Xlet \\; \\Xrec \\; x \\; \\equal \\;\n     \\meta{e}_1 \\; \\Xin \\; \\meta{e}_2}}{v_2}{\\sigma_2}\n  }\n\\end{mathpar}\n\n\\paragraph{Sequences and general iterators}\n\nWe can now add to our language the sequence construct, and a general\niterator. \n\\begin{itemize}\n\n  \\item Concrete syntax\\\\\n\\texttt{Expression ::= ...}\\\\\n\\texttt{\\hphantom{Expression} | Expression \";\" Expression}\\\\\n\\texttt{\\hphantom{Expression} | \"while\" Expression \"do\" Expression \"done\"}\n\n  \\item Abstract syntax\\\\\n     \\Xtype \\type{expr} \\equal \\texttt{...} \\vbar{} \\cst{Seq}\n     \\Xof \\type{expr} \\(\\times\\) \\type{expr} \n     \\vbar{} \\cst{While} \\Xof \\type{expr} \\(\\times\\)\n     \\type{expr}\\textsf{;;}{}\n\n  \\item Syntax analysis\\\\ $\\src{\\meta{e}_1\\!\\texttt{;} \\meta{e}_2} =\n    \\cst{Seq} \\, \\lpar e_1, e_2\\rpar$, and $\\src{\\Xwhile \\; \\meta{e}_1\n      \\; \\Xdo \\; \\meta{e}_2 \\; \\Xdone} = \\cst{While} \\, \\lpar e_1,\n    e_2\\rpar$.\n\n  \\item Free variables\\\\\n    $\\mathcal{F} \\src{\\meta{e}_1\\!\\texttt{;} \\meta{e}_2}\n    = \\mathcal{F}(e_1) \\cup \\mathcal{F}(e_2)$, and\\\\\n    $\\mathcal{F} \\src{\\Xwhile \\; \\meta{e}_1 \\; \\Xdo \\; \\meta{e}_2 \\; \\Xdone}\n    = \\mathcal{F}(e_1) \\cup \\mathcal{F}(e_2)$.\n\n\\end{itemize}\nThe operational semantics is as follows:\n\\begin{mathpar}\n\\inferrule*[right=seq]\n  {x \\not\\in \\mathcal{F} (e_2)\\\\\n   \\meval\n     {\\rho}\n     {\\Xlet \\; x \\; \\equal \\; \\meta{e}_1 \\; \\Xin \\; \\meta{e}_2}\n     {v}\n  } \n  {\\meval{\\rho}{\\meta{e}_1\\!\\texttt{;} \\meta{e}_2}{v}}\n\\and\n\\inferrule[while]\n  {f,p \\not\\in \\mathcal{F} (e_2)\\\\\n   x \\not\\in \\mathcal{F} (e_1)\\\\\n   \\meval\n     {\\rho} \n     {\\small \\Xlet \\; \\Xrec \\; f \\; \\equal \\; \\Xfun \\; p \\rightarrow \\Xif \\; p\n      \\lpar\\rpar \\; \\Xthen \\; \\meta{e}_2\\!\\texttt{;} f \\, p \\; \\Xelse \\;\n      \\lpar\\rpar \\; \\Xin \\; f \\lpar\\Xfun \\; x \\rightarrow \\meta{e}_1\\rpar}\n     {v}\n  }\n  {\\meval\n     {\\rho}\n     {\\Xwhile \\; \\meta{e}_1 \\; \\Xdo \\; \\meta{e}_2 \\; \\Xdone}\n     {v}\n  }\n\\end{mathpar}\nLet us remark that the value~\\(v\\) is actually always \\lpar\\rpar{} in\nthe rule \\RefTirName{while}. Moreover, if we added Boolean comparisons\nover integers, we could write\n\\begin{center}\n\\Xlet \\ident{x} \\equal \\num{0} \\Xin\n\\lpar\\Xwhile \\ident{x} \\texttt{<} \\num{10} \\Xdo \\ident{x} \\assign \\ident{x}\n\\texttt{+} \\num{1} \\Xdone \\texttt{;} \\ident{x}\\rpar\n\\end{center}\n\n\\paragraph{Implementation of the semantics with mutation}\n\nTo implement our new semantics, the first choice to commit is that of\nthe \\OCaml data type for addresses. Even though \\OCaml integers can\noverflow, we will use them for implementing addresses. The next point\nto make is about the rules where we must chose an address which is\nfree in the store, formally $a \\not\\in \\dom{\\sigma}$. A solution\nconsists to create each time an address which is absolutely unique,\nfor instance, it may be a strictly increasing integer. We should then\nthread an additional argument, representing that counter, through our\nevaluation function \\ident{eval}, and, every time we need a new\naddress, we would increment that argument and pass along further its\nvalue plus one. The polymorphic functions operating over the\nenvironments (\\ident{extend}, for adding a binding, and\n\\ident{lookup}, for seeking a binding), can also be used on stores.\n", "meta": {"hexsha": "6395aa02ace82000fa2b956d9d9072de3ada4b0c", "size": 67530, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "semantics.tex", "max_stars_repo_name": "rinderknecht/Book", "max_stars_repo_head_hexsha": "6f302ab1319c8ae9b3ea690c45fdb3d2b6fbca16", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "semantics.tex", "max_issues_repo_name": "rinderknecht/Book", "max_issues_repo_head_hexsha": "6f302ab1319c8ae9b3ea690c45fdb3d2b6fbca16", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "semantics.tex", "max_forks_repo_name": "rinderknecht/Book", "max_forks_repo_head_hexsha": "6f302ab1319c8ae9b3ea690c45fdb3d2b6fbca16", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2173174873, "max_line_length": 102, "alphanum_fraction": 0.6625351696, "num_tokens": 23843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.724924048796072}}
{"text": "% To be compiled with pdflatex\r\n% This file is to be included into master file via \\input command\r\n% Note that there is no \\begin{document} \\end{document} brackets!\r\n\r\n\\newpage\r\n\\section{Appendix: \\\\ Basic discrete-time digital filter theory}\r\n\\label{app:DF}\r\n\r\n\\mbox{}\r\n\r\nHere the basic formulas for the digital linear filter theory are given.\r\n\r\n\\emph{Definition}: a time-invariant, single-input-single-output (SISO), order N\r\ndisctete-time linear digital filter is given by a\r\nlinear, order-N difference equation with constant coefficients:\r\n\\begin{equation} \\label{eq:filter-diff}\r\n\ty(i) = \\sum_{k=0}^{N} b_{k} u(i-k) - \\sum_{k=1}^{N} a_{k} y(i-k), \\,\\,\r\n\ti = 0,...\r\n\\end{equation}\r\nwhere $i$ is \\emph{disctete time}, \\index{discrete time} $u(i)$ is the\r\n\\emph{input sequence}, \\index{input sequance} $y(i)$ is the \\emph{output\r\nsequence}. \\index{output sequence}\r\nThe filter in Eq. (\\ref{eq:filter-diff}) is called \\emph{causal} \\index{causal\r\nfilter} because\r\n$y(i)$ does not depend on time instances $i+1$ and on. Appying $z$-transform\r\nto Eq. (\\ref{eq:filter-diff}) one gets:\r\n$$ y(z) (1+\\sum_{k=1}^{N} a_{k} z^{-k}) = u(z) \\sum_{k=0}^{N} b_{k} z^{-k}. $$\r\nfrom where the \\emph{transfer function} \\index{transfer function} is:\r\n\\begin{equation} \\label{eq:transfer-function}\r\n\tH(z) = \\frac{y(z)}{u(z)} = b_{0} + \\frac{\\sum_{k=1}^{N} \\beta_{k} b_{k}\r\n\tz^{-k}}{1+\\sum_{k=1}^{N} a_{k} z^{-k}},\r\n\\end{equation}\r\n$$ \\beta_{k} = b_{k} - b_{0} a_{k}. $$\r\nThe canonical state-space model\r\n\\begin{equation} \\label{eq:canonical-state-space}\r\n\t\\bm{x}(i+1) = \\mathcal{A} \\bm{x}(i) + \\mathcal{B} \\bm{u}(i),\r\n\\end{equation}\r\n$$ \\bm{y}(i) = \\mathcal{C} \\bm{x}(i) + \\mathcal{D} \\bm{u}(i) $$\r\ndescribes the filter in terms of its internal state $\\bm{x}(i)$ dynamics. The\r\nfirst equation is the \\emph{state dynamics equation}, \\index{state dynamics\r\nequation} the second is the \\emph{measurement equation}. \\index{measurement\r\nequation}\r\nThe state space model parameters for the filter are easily derivable from Eq.\r\n(\\ref{eq:transfer-function}):\r\n\\begin{equation} \\label{eq:state-space-filter}\r\n\t\\bm{u}(i) = [u(i)],\r\n\\end{equation}\r\n$$ \\bm{y}(i) = [y(i)], $$\r\n$$ \\mathcal{A} = \\left[\r\n\\begin{array}{ccccc}\r\n\t-a_{1} & -a_{2} & \\cdots & -a_{N-1} & -a_{N} \\\\\r\n\t1      & 0      & \\cdots & 0        & 0      \\\\\r\n\t0      & 1      & \\cdots & 0        & 0      \\\\\r\n\t\\vdots & \\vdots & \\ddots & \\vdots   & \\vdots \\\\\r\n\t0      & 0      & \\cdots & 1        & 0      \\\\\r\n\\end{array}\r\n\\right] $$\r\n$$ \\mathcal{B} = [1 \\, \\cdots \\, 0]^{T}, $$\r\n$$ \\mathcal{C} = [\\beta_{1} \\, \\cdots \\, \\beta_{N}], $$\r\n$$ \\mathcal{D} = [b_{0}]. $$", "meta": {"hexsha": "03eb150d72e61d9ae773c01f49d42d9fcb7db8be", "size": 2602, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_docGMT/DF.tex", "max_stars_repo_name": "cmcorreia/oomao", "max_stars_repo_head_hexsha": "59787859283e89cdb8c2ee88388198f283be9abb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-10-01T18:30:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T01:19:40.000Z", "max_issues_repo_path": "_docGMT/DF.tex", "max_issues_repo_name": "cmcorreia/oomao", "max_issues_repo_head_hexsha": "59787859283e89cdb8c2ee88388198f283be9abb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-04-30T17:22:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-30T17:22:35.000Z", "max_forks_repo_path": "_docGMT/DF.tex", "max_forks_repo_name": "cmcorreia/oomao", "max_forks_repo_head_hexsha": "59787859283e89cdb8c2ee88388198f283be9abb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.3666666667, "max_line_length": 80, "alphanum_fraction": 0.6076095311, "num_tokens": 959, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552536, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7248705765731488}}
{"text": "\\chapter{Differential geometry}\n\n\\section{Tensor}\n\n\\cite{wptensor}\n\nThe tensor product of \\(A\\) and \\(B\\) is \\(A \\otimes B\\).\nIff \\(a\\) is a basis of \\(A\\) and \\(b\\) is a basis of \\(B\\),\nthen \\(a \\otimes b\\) is a basis of \\(A \\otimes B\\).\nThus if \\(A\\) has \\(m\\) basis vectors \\(\\{a_1,\\ldots,a_m\\}\\) and \\(B\\) has \\(n\\) basis vectors \\(\\{b_1,\\ldots,b_n\\}\\),\nthen \\(C = A \\otimes B\\) has \\(mn\\) basis tensors \\(\\{c_{11}, \\ldots, c_{1n}, c_{21}, \\ldots, c_{2n}, \\ldots, c_{mn}\\}\\)\nwhere \\(c_{ij} = a_i \\otimes b_j\\).\n\nLet \\(V\\) be a vector space over ring \\(R\\).\nLet \\(P = \\{1,\\ldots,p\\}^p\\) and \\(Q = \\{1,\\ldots,q\\}^q\\).\nA \\emph{tensor} \\(T\\) of type \\((p,q)\\) is an element of\n\\(V_q^p\\) where\n\\[\n    V_q^p = \\underbrace{V \\otimes \\ldots \\otimes V}_p \\otimes \\underbrace{V^* \\otimes \\ldots \\otimes V^*}_q.\n\\]\nThe tensor \\(T\\) can be stated as a sum of the basis tensors:\n\\( T = \\sum_{i \\in P} \\sum_{j \\in Q} T_j^i t_j^i \\)\nwhere \\(t_j^i = e_{i_1} \\otimes \\ldots \\otimes e_{i_p} \\otimes f_{j_1} \\otimes \\ldots \\otimes f_{j_q}\\).\n\n\\section{Geometric manifold}\n\n\\section{Tangent space}\n\nThe tangent space of a point on a manifold is the set of all tangent vectors of that manifold at that point.\n", "meta": {"hexsha": "cd34e6545893638a9d8470f8684ce16b024db716", "size": 1192, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/differential-geometry.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/differential-geometry.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/differential-geometry.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 39.7333333333, "max_line_length": 120, "alphanum_fraction": 0.610738255, "num_tokens": 465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506716354847, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.7248632888549392}}
{"text": "% !TeX root = ../main.tex\n\\section{Preliminaries}\nIn this section, we review the essential notions used in this work. The notation is consistent with major works on unification and rewriting. The reader is referred to \\cite{bezem2003term} for a more detailed discussion on rewriting.\n\nA signature is a set $\\signature$ of function symbols. Associated with every $f \\in \\signature$ there is a non-negative integer $n$, the arity of the function symbol $f$. We denote this by writing $f:n$. Function symbols of arity $0$ is called \\textit{constants}. Furthermore, we assume existence of a countable infinite set of variables $\\var$ disjoint from $\\sigma$ and, inductively, construct the set $\\terms$ of all terms built using the signature $\\signature$ and the variables set $\\var$ in the following way: every variable is a $\\terms$-term and if $f:n \\in \\signature$ and $t_1, \\cdots, t_n \\in \\terms$ then $f(t_1, \\dots, t_n) \\in \\terms$. The set of all variables occurring in a term $t$ is denoted by $\\vars{t}$.\n\nThe structure of a term can be represented as a tree where function symbols are nodes and arrows point to the arguments of the function.\n\\begin{figure}[!ht]\n\t\\begin{displaymath}\n\t\t\\xymatrix{\n\t\t&f|_\\Lambda \\ar@{-}^2[dr]\\ar@{-}_1[dl]&\\\\\n\t\ta  & & g \\ar@{-}^{21}[d] \\\\\n\t\t& &x\n\t\t}\n\t\\end{displaymath}\n\t\\caption{Tree representation of a term.}\n\t\\label{figure:tree-representation-of-a-term}\n\\end{figure}\nA precise formalism of describing subterm occurrences in a term is obtained by the notion of \\textit{position}. The set $\\pos{t}$ of positions of $t$ is inductively defined as follows:\n\\begin{displaymath}\n    \\restr{t}{p} =\n\t\\begin{cases}\n\t\tt                & \\mbox{if } p = \\Lambda                               \\\\\n\t\t\\restr{t_i}{p_i} & \\mbox{if } t = (t_1,\\dots, t_n); \\ \\ 1 \\leq i \\leq n\n\t\\end{cases}\n\\end{displaymath}\n\nSo positions are sequences of natural numbers denoting subterm occurrences. The set $\\pos{t}$ is partitioned into two subsets; $\\basicPos{t}$, the set of all non-variable positions of $t$, i.e., $\\{p \\in \\pos{t} \\mid \\restr{t}{p} \\notin \\var \\}$ and $\\varPos{t}$, the set of all variable positions of $t$, $\\{p \\in \\pos{t} \\mid \\restr{t}{p} \\in \\var \\}$. If $p \\in \\pos{t}$ then $t[s]_p$ denotes the term obtained from $t$ by replacing the subterm of $t$ at position $p$ by $s$. Formally;\n\\begin{displaymath}\n    t[s]_p =\n\t\\begin{cases}\n\t\ts                & \\mbox{if } p = \\Lambda                               \\\\\n\t\tf(t_1, \\dots, t_i[s]_q, \\dots, t_n) & \\mbox{if } t = f(t_1, \\dots, t_n) \\mbox{ and } p = i \\cdot q\n\t\\end{cases}\n\\end{displaymath}\nPositions are partially ordered by the \\textit{prefix order} $\\leq$, i.e. $p \\leq q$ if there exists an $r$ such that $q = p \\cdot r$. We write $p < q$ for the strict part of $\\leq$.\n\nA substitution $\\sigma$ over $\\terms$ is a function $\\sigma : \\var \\to \\terms$ such that the set $\\{ x \\in \\var \\mid x \\sigma \\neq x \\}$ is finite. The application of a substitution $sigma$ to a term $t$ is defined by induction on the structure of terms:\n\\begin{displaymath}\n    t\\sigma =\n\t\\begin{cases}\n\t\tx\\sigma                & \\mbox{if } t = x                               \\\\\n\t\tf(t_1\\sigma, \\dots, t_n\\sigma) & \\mbox{if } t = f(t_1, \\dots, t_n)\n\t\\end{cases}\n\\end{displaymath}\nThe domain of a substitution $\\sigma$ is the set of variables that are not mapped to themselves by $\\sigma$. That is;\n$$ \\dom{\\sigma} = \\{x \\in \\var \\mid x \\sigma \\neq x\\}$$\nthe \\textit{range} of $\\sigma$ is the set of terms\n$$ \\ran{\\sigma} = \\bigcup\\limits_{x \\in \\dom{\\sigma}}  \\{ x\\sigma \\},$$\nand the set of variables occurring in the range is $\\vran{\\sigma} := \\vars{\\ran{\\sigma}}$.\n\nWe represent substitutions in a more suitable way: a list of bindings from variables in the domain to terms in the range:\n$$[x_1 / t_1, \\dots, x_n / t_n ]$$\nThe restriction of a substitution $\\sigma$ to a set of variables $V$, denoted by $\\restr{\\sigma}{V}$, is the substitution which is equal to the identity everywhere except over $V \\cap \\dom{\\sigma}$, where it is equal to $\\sigma$. Composition of two substitutions is written, $\\sigma \\theta$, and is defined by\n$$t\\sigma \\theta = (t\\sigma)\\theta.$$\nAn algorithm for constructing the composition of two substitutions represented as sets of bindings is as follows:\n\\begin{enumerate}\n    \\item Apply $\\theta$ to every term in $\\ran{\\sigma}$ to obtain $\\sigma_1$;\n    \\item Remove from $\\theta$ any biding $x/t$, where $x \\in \\dom{\\sigma}$, to obtain $\\theta_1$;\n    \\item Remove from $\\sigma_1$ any trivial binding $x/x$, to obtain $\\sigma_2$; and\n    \\item Take the union of the two list of bidings $\\sigma_2$ and $\\theta_1$.\n\\end{enumerate}\nTwo substitutions $\\theta, \\sigma$ are equal on the set of variables $V$, denoted by $\\sigma =^V \\theta$ iff $x \\sigma = x \\theta$, for all $x \\in V$. A variable renaming is a bijective substitution on $\\var$. A substitution $\\sigma$ is \\textit{more general} than a substitution $\\tau$ on the set of variables $V$, denoted as $\\sigma \\iqoless[E][V] \\tau$, if there exists a substitution $\\eta$ such that $ \\tau =^V \\sigma \\eta$.\n\n\nTwo terms $s$ and $t$ are unifiable if there exists a substitution $\\rho$, a so-called unifier of $s$ and $t$, such that $s \\rho = t \\rho$. Save the following result for later use.\n\n\\begin{lemma}\\label{lemma:unifiers-preserve-variables}\n    If $\\sigma$ is an idempotent most general unifier of two terms $s, t$ that have no variables in common then $\\dom{\\sigma} \\cup \\vran{\\sigma} = \\vars{s} \\cup \\vars{t}$.\n\\end{lemma}\n\nLet $\\sim$ be a binary relation on terms. Say that $\\sim$ is closed under contexts if $s \\sim t$ implies $u[s]_p \\sim u[t]_p$, for all terms $u$ and positions $p \\in \\pos{u}$. The relation $\\sim$ is closed under substitutions if $s\\sigma \\sim t\\sigma$ whenever $s \\sim t$, for all substitutions $\\sigma$. A relation that is closed under contexts and substitutions is called a \\textit{rewrite relation}.\n\nAn equation is an unordered pair $(s,t)$ of terms, written as $s = t$. Let $E$ be a set of equations. The rewrite relation $\\contr_E$ generated by $E$ is defined as:\n\\begin{center}\n    $s \\contr_E t$ iff there exists a position $p \\in \\pos{s}$, a substitution $\\sigma$ and a equation $l = r \\in E$ such that \\newline\n    $\\restr{s}{p} = l \\sigma$ and $t = s[r\\sigma]_p$.\n\\end{center}\n\nThe smallest symmetric relation that contains $E$ and is closed under contexts and substitutions is denoted by $\\leftrightarrow_E$. The transitive-reflexive closure of $\\leftrightarrow_E$ is denoted by $\\eqUnif{E}$. This relations also extend to substitutions in the obvious way. We call $E$ the equational theory generated by the set of equational axioms $E$.\n\nTwo terms $s$ and $t$ are $E$-unifiable if there exists a substitution $\\sigma$ such that $s\\sigma \\eqUnif{E} t\\sigma$. A set of substitutions $S$ is a complete set of $E$-unifiers of two terms $s$ and $t$ if the following conditions are satisfied:\n\\begin{enumerate}\n    \\item $\\dom{\\sigma} \\subseteq \\vars{s} \\cup \\vars{t}$ for all $\\sigma$ for all $\\sigma \\in S$;\n    \\item every $\\sigma \\in S$ is an $E$-unifier of $s$ and $t$,\n    \\item if $\\tau$ is an $E$-unifier of $s$ and $t$ then there exists a $\\sigma \\in S$ such that $\\sigma \\iqoless[E][V] \\tau$ where $V = \\vars{s} \\cup \\vars{t}$.\n\\end{enumerate}\n\nA \\textit{rewrite rule} is a directed equation $l \\contr r$ satisfying $l \\notin \\var$ and $\\vars{r} \\subseteq \\vars{l}$. A \\textit{variant} of a rewrite rule $l \\contr r$ is an instance $l \\sigma \\contr r \\sigma$, where $\\sigma$ is a variable renaming substitution. A \\textit{term rewriting system} is a set of rewrite rules. Sometimes we give a tag name to a rule, write $\\trs = \\{ \\rho_1 : l \\contr r, \\cdots, \\rho_k : l \\contr r \\}$ and access the rule by its name.\n\nThe rewrite relation $\\contr_\\trs$ associated with the TRS $\\trs$ is defined as follows: $s \\contr_\\trs t$ if there exists a variant $l \\contr r$ of a rewrite rule in $\\trs$, a position $p \\in \\pos{s}$, and a substitution $\\sigma$ such that $\\restr{s}{p} = l \\sigma$ and $t = s[r \\sigma]_p$. The subterm $l\\sigma$ of $s$ is called a \\textit{redex} (from reducible expression) and we say that the term $s$ reduces to $t$ by \\textit{contracting} the redex $l \\sigma$. We call $s \\contr_\\trs t$ a rewrite step. If we want to be more specific about this contraction we write: $s \\contr_{[p, l \\contr r, \\sigma]}t$ to say that this reduction occurs at position $p$, using the variant $l \\contr r$ and substitution $\\sigma$.\n\nThe reflexive-transitive closure of $\\contr$ is denoted by $\\stc$. If $s \\stc t$ we say that $s$ \\textit{reduces} to $t$. The transitive closure of $\\contr$ is denoted by $\\contr^+$. The transitive-reflexive-symmetric closure of $\\contr_\\trs$ is called \\textit{conversion} and is denoted by $\\eqUnif{\\trs}$. If $E$ is a set of equation corresponding to $\\trs$, i.e. $E = \\{ l = r \\mid l \\contr r \\in \\trs \\}$ then $\\eqUnif{E}$ and $\\eqUnif{\\trs}$ coincide. Two terms $t_1, t_2$ are \\textit{joinable}, denoted by $t_1 \\downarrow t_2$ if there exists a term $s$ such that $t_1 \\stc s \\stcR t_2$.\n\nA term $s$ is a normal form if there is no $t$ satisfying $s \\stc t$. Also, say $s$ is normalised. A term $s$ has a normal form if there exists a rewrite sequence $s \\stc t$ and $t$ is a normal form. A TRS is weakly normalising if every term has a normal form and is \\textit{strongly normalising} if there are no infinite reduction sequences $t_1 \\contr t_2 \\contr \\cdots \\contr t_i \\contr t_{i+1} \\cdots$. A term rewrite system $\\trs$ is \\textit{locally confluent} if all divergence $t_1 \\contrR s \\contr t_2$ is joinable. We also say $\\trs$ is \\textit{confluent} if every divergence sequence $t_1 \\stcR s \\stc t_2$ is joinable. A term rewriting system is \\textit{convergent} if it is confluent and strongly normalising. In this case, denote by $\\trsNF{t}$ the unique normal form of $t$, for any term $t$.\n\nA substitution $\\sigma$ is $\\trs$-normalised if for all $x \\in \\dom{\\sigma}, \\; x \\sigma$ is a $\\trs$-normal form. A substitution $\\sigma$ is normalisable if $x \\sigma$ has a normal form, for every $x \\in \\dom{\\sigma}$. When $\\trs$ is convergent we denote by $\\trsNF{\\sigma}$ the unique normal form of $\\sigma$.\n", "meta": {"hexsha": "054a65325a7be158dd9d358ee09aa15865bdb0db", "size": 10146, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/preliminaries.tex", "max_stars_repo_name": "deividrvale/report-narrowing", "max_stars_repo_head_hexsha": "1e3ce34a1afb5268b4307fcc9af9374d2e121a27", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sections/preliminaries.tex", "max_issues_repo_name": "deividrvale/report-narrowing", "max_issues_repo_head_hexsha": "1e3ce34a1afb5268b4307fcc9af9374d2e121a27", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/preliminaries.tex", "max_forks_repo_name": "deividrvale/report-narrowing", "max_forks_repo_head_hexsha": "1e3ce34a1afb5268b4307fcc9af9374d2e121a27", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 103.5306122449, "max_line_length": 806, "alphanum_fraction": 0.6843090873, "num_tokens": 3127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7248230458070466}}
{"text": "Before diving into technical details of the model specification, \nwe discuss the modeling philosophy behind our collaborative multi-output Gaussian processes.\nTo learn the outputs jointly, we need a mechanism through which information can be transferred among the outputs.\nThis is achieved in the model by allowing the outputs to share multiple sets of inducing variables, \neach of which captures a different pattern common to the outputs.\nThese variables  play a double pivotal role in the model: they collaboratively share  information \nacross the outputs and  provide sufficient statistics so as to induce sparse processes. \n\n\\newcommand{\\Zj}{\\Z_j}\n\\newcommand{\\Zhi}{\\Z^h_i}\nConsider the joint regression of $P$ tasks with inputs $\\X = \\{\\x_n \\in \\calR^D\\}_{n=1}^N$ and outputs $\\y = \\{\\y_i\\}_{i=1}^P$ where $\\y_i = \\{y_{in}\\}_{n=1}^N$.\nWe  model each output as a weighted combination of $Q$ shared latent functions $\\{ g_{j}\\}_{j=1}^{Q}$, plus an individual latent \nfunction $\\{ h_{i}\\}_{i=1}^{P}$ unique to that output for greater flexibility.\nThe $Q$ shared functions have independent Gaussian process priors  $g_j(\\x) \\sim \\GP(0, k_j(\\cdot,\\cdot))$. %, with $j= 1, \\ldots Q$.\nSimilarly, each individual function of an output also has a GP prior, i.e.~$h_i(\\x) \\sim \\GP(0, k^h_i(\\cdot,\\cdot))$. %with $i=1 ,\\ldots P$.\n\n\nAs we want to sparsify these processes, \nwe introduce a set of \\emph{shared inducing variables} $\\u_j$ for  each $g_j(\\x)$, i.e. $\\u_j$ contains the values of \n$g_j(\\x)$ at the inducing inputs $\\Z_j$. Likewise, we have \nindividual inducing variables corresponding to each  $h_i(\\x)$,  which we denote with $\\v_i$ and their \ncorresponding inducing inputs $\\Zhi$.\n%\nThe inducing inputs lie in the same space as the inputs $\\X$.\n% which should be apparent since their corresponding values come from the processes defined on the input space.\nFor convenience, we  assume all processes have the same number of inducing points, $M$.\nHowever we emphasize that this is not\n imposed in practice.\n\n% information is transfered via the inducing variables\n\nWe denote the collective variables: $\\g = \\{\\g_j\\}$, $\\h = \\{\\h_i \\}$, $\\u = \\{\\u_j\\}$, $\\v = \\{\\v_i\\}$, $\\Z = \\{\\Zj\\}$, and $\\Z^h = \\{\\Zhi \\}$ where $\\g_j = \\{g_j(\\x_n)\\}$, $\\h_i = \\{h_i(\\x_n)\\}$. \nNote that we reserve subscript $i$ for indexing the outputs and their corresponding individual processes ($i = 1 \\hdots P$), $j$ for the shared latent processes ($j = 1 \\hdots Q$), and $n$ for the inputs ($n = 1 \\hdots N$).\n%\n\\subsection{PRIOR MODEL}\nFrom the definition of the GPs and the independence of the processes, \nthe \\emph{prior} of the multi-output model can be written as:\n\\begin{align}\n\\label{eq:gu}\np(\\g | \\u) &= \\prod_{j=1}^Q p(\\g_j | \\u_j) = \\prod_{j=1}^Q \\Normal(\\g_j; \\BigMu_j, \\tilde{\\K}_j )\\\\\n\\label{eq:u}\np(\\u) &= \\prod_{j=1}^Q p(\\u_j) = \\prod_{j=1}^Q \\Normal(\\u_j; \\vec{0}, k(\\Zj, \\Zj)) \\\\\n\\label{eq:hv}\np(\\h | \\v) &= \\prod_{i=1}^P p(\\h_i | \\v_i) = \\prod_{i=1}^P \\Normal(\\h_i; \\BigMu^h_i, \\tilde{\\K}^h_i)\\\\\n\\label{eq:v}\np(\\v) &= \\prod_{i=1}^P p(\\v_i) = \\prod_{i=1}^P \\Normal(\\v_i; \\vec{0}, k(\\Zhi, \\Zhi)),\n\\end{align}\nwhere the corresponding means and covariances of the Gaussians are given by:\n\\begin{align}\n \\BigMu_j &= k(\\X,\\Zj)k(\\Zj,\\Zj)^{-1}\\u_j \\\\\n\\BigMu^h_i &= k(\\X,\\Zhi)k(\\Zhi,\\Zhi)^{-1}\\v_i \\\\\n\\tilde{\\K}_j &= k_j(\\X,\\X) - k(\\X,\\Zj)k(\\Zj,\\Zj)^{-1}k(\\Zj,\\X) \\\\\n\\tilde{\\K}^h_i &= k^h_i(\\X,\\X) - k(\\X,\\Zhi)k(\\Zhi,\\Zhi)^{-1}k(\\Zhi,\\X).\n\\end{align}\nIn the equations and hereafter, we omit the subscripts $j,h,i$ from the kernels $k_j(\\cdot,\\cdot)$ and $k^h_i(\\cdot,\\cdot)$ when it is clear from the parameters inside the parentheses which covariance function is in action.\n\nEquations \\eqref{eq:u} and \\eqref{eq:v} follow directly from the properties of GPs, while the expressions for $p(\\g|\\u)$ and $p(\\h|\\v)$ (Equations  \\eqref{eq:gu} and \\eqref{eq:hv}) come from the conditionals of the multivariate Gaussian distributions.\nInstead of writing the joint priors $p(\\g,\\u)$ and $p(\\h,\\v)$, the above equivalent equations are given to emphasize the sufficient statistics role of $\\u$ and $\\v$ in the model.\nHere by sufficient statistics we mean, for any sparse process (say $g_j$), any other set of function values is \nindependent of $\\g_j$ given the inducing variables $\\u_j$.\n%\n\\subsection{LIKELIHOOD MODEL}\nAs mentioned above, we assume that  observations for each output \nare  (noisy) linear combinations of the $Q$ latent functions $g_{j}(\\vec{x})$ plus\nan independent function $h_{i}(\\vec{x})$. Hence we have that the likelihood \nwith standard iid Gaussian noise is given by:\n\\begin{align}\np(\\y | \\g, \\h ) = \\prod_{i=1}^P \\prod_{n=1}^N \\Normal( y_{in} ; \\sum_{j=1}^Q w_{ij} g_j(\\x_n) + h_i(\\x_n), \\beta_i^{-1}),\n\\end{align}\nwhere $w_{ij}$ are the corresponding weights and $\\beta_i$ is the precision of each Gaussian.\n%which says that $y_{in}$ is a linear combination of the latent functions with weight $w_{ij}$ for the $j$th shared latent process plus a contribution from the individual process $h_i$.\nAs the latent values $\\g$ are specified conditioned on the inducing variables $\\u$, this construction implies that each output is a weighted combination of the inducing values.\nWe note that if $\\u$ and $\\v$ are marginalized out, we obtain the semiparametric latent factor model \\citep{teh-et-al-aistats-05}.\nHowever, doing so is against the purpose of our model which encourages sharing of outputs via the inducing variables.\nFurthermore, as we shall see in the next section, explicit representation of these variables is fundamental to scalable inference of the model.\n\n%\\textbf{Augmented sparse GPs}\n%Toward scalable modeling, we replace standard GPs with sparse GPs augmented with \\textit{different} set of inducing inputs.\n%This adds much flexibility to the model as each of the shared process $g_j(\\x)$ can model a different pattern in the data with its own covariance function and inducing inputs. The roles of $g_j(\\x)$ and $h_i(\\x)$ can be quite different, so it is necessary that each has its own inducing inputs.\n%Furthermore, $g_j(\\x)$ can be seen as a \\textit{global} function operating on the entire input space (of all output dimensions), while each $h_i(\\x)$ operates only on the inputs of the $i$-th output, which can be a subspace of the input.\n", "meta": {"hexsha": "493af5042e4055ef8d42d9326d8ba840796dc0de", "size": 6263, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/model.tex", "max_stars_repo_name": "fkopsaf/cogp", "max_stars_repo_head_hexsha": "3b07f621ff11838e89700cfb58d26ca39b119a35", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2015-05-28T13:46:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T11:02:08.000Z", "max_issues_repo_path": "paper/model.tex", "max_issues_repo_name": "fkopsaf/cogp", "max_issues_repo_head_hexsha": "3b07f621ff11838e89700cfb58d26ca39b119a35", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-07-30T08:52:36.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T01:44:21.000Z", "max_forks_repo_path": "paper/model.tex", "max_forks_repo_name": "trungngv/cogp", "max_forks_repo_head_hexsha": "3b07f621ff11838e89700cfb58d26ca39b119a35", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2016-04-03T03:18:18.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-23T13:28:55.000Z", "avg_line_length": 77.3209876543, "max_line_length": 295, "alphanum_fraction": 0.7084464314, "num_tokens": 1915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759583, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.7248230363273719}}
{"text": "\\section{Taylor Series}\r\n\\subsection{Construction}\r\nAlthough we can approximate lots of functions using power series derived from the geometric series, it'd be nice if we had a more general way to approximate any function using a power series.\r\nWe already have an approximation using a tangent line: the 0th and 1st derivatives of the function and line are equal at the point of tangency.\r\nWe could extend this idea of derivatives being equal to higher-order derivatives and higher degree polynomials.\r\n\r\n\\begin{example}\r\n\tConstruct  polynomial $P(x)=a_0+a_1x + a_2x^2 + a_3x^3 + a_4x^4$ with the following behavior at $x=0$:\r\n\t\\begin{align*}\r\n\t\tP(0) &= 1 \\\\\r\n\t\tP^\\prime(0) &= 2 \\\\\r\n\t\tP^{\\prime\\prime}(0) &= 3 \\\\\r\n\t\tP^{\\prime\\prime\\prime}(0) &= 4 \\\\\r\n\t\tP^{(4)}(0) &= 5.\r\n\t\\end{align*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tPlugging in $x=0$ and solving for $a_0$,\r\n\t\\begin{align*}\r\n\t\ta_0 + a_1(0) + a_2(0)^2 + a_3(0)^4 + a_4(0)^4 &= 1 \\\\\r\n\t\ta_0 &= 1.\r\n\t\\end{align*}\r\n\t\r\n\tDifferentiating once, plugging in $x=0$, and solvinf for $a_1$,\r\n\t\\begin{align*}\r\n\t\tP^\\prime(x) &= a_1 + 2a_2x + 3a_3x^2 + 4a_4x^3 \\\\\r\n\t\t2 &= a_1 + 2a_2(0) + 3a_3(0)^2 + 4a_4(0)^3 \\\\\r\n\t\ta_1 &= 2.\r\n\t\\end{align*}\r\n\t\r\n\tContinuing with differentiating and plugging in $x=0$, we get $a_2 = \\frac{3}{2}$, $a_3 = \\frac{2}{3}$, and $a_4 = \\frac{5}{25}$.\r\n\tSo,\r\n\t\\begin{equation*}\r\n\t\tP(x) = 1 + 2x + \\frac{3}{2}x^2 + \\frac{2}{3}x^3 + \\frac{5}{24}x^4.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tConstruct a degree 4 polynomial that approximates $\\ln{(1+x)}$ at $x=0$.\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{table}[H]\r\n\t\t\\begin{center}\r\n\t\t\t\\begin{tabular}{ccc}\r\n\t\t\t\t$f(x)$ & $P(x)$ & $a_n$ \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\t$f(x)=\\ln{(1+x)}$ & $P(x)=a_0 + a_1x + a_2x^2 + a_3x^3 + a_4x^4$ & \\\\\r\n\t\t\t\t$f(0)=\\ln{(1+0)}=0$ & $P(0)=a_0$ & $a_0 = 0$ \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\t$f^\\prime(x)=\\frac{1}{1+x}$ & $P^\\prime(x) = a_1 + 2a_2x + 3a_3x^2 + 4a_4x^3$ & \\\\\r\n\t\t\t\t$f^\\prime(0)=\\frac{1}{1+0}=1$ & $P^\\prime(0) = a_1$ & $a_1 = 1$ \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\t$f^{\\prime\\prime}(x)=\\frac{-1}{(1+x)^2}$ & $P^{\\prime\\prime}(x)=2a_2 + 6a_3x + 12a_4x^2$ & \\\\\r\n\t\t\t\t$f^{\\prime\\prime}(0)=\\frac{-1}{(1+0)^2} = -1$ & $P^{\\prime\\prime}(x)=2a_2$ & $a_2 = \\frac{-1}{2}$ \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\t$f^{(3)}(x) = \\frac{2}{(1+x)^3}$ & $P^{(3)}(x) = 6a_3 + 24a_4x$ & \\\\\r\n\t\t\t\t$f^{(3)}(0) = \\frac{2}{(1+0)^3}=2$ & $P^{(3)}(0) = 6a_3$ & $a_3 = \\frac{1}{3}$ \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\t$f^{(4)}(x) = \\frac{-6}{(1+x)^4}$ & $P^{(4)}(x) = 24a_4$ & \\\\\r\n\t\t\t\t$f^{(4)}(x) = \\frac{-6}{(1+0)^4}=-6$ & $P^{(4)}(0) = 24a_4$ & $a_4 = \\frac{-1}{4}$ \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\\end{tabular}\r\n\t\t\\end{center}\r\n\t\\end{table}\r\n\t\r\n\tSo, our polynomial is\r\n\t\\begin{equation*}\r\n\t\tP(x) = x - \\frac{x^2}{2} + \\frac{x^3}{3} - \\frac{x^4}{4}.\r\n\t\\end{equation*}\r\n\t\r\n\tNote that this polynomial exactly matches the power series we derived for $\\ln{(1+x)}$. \\\\\r\n\tThis polynomial is called the 4th order Taylor polynomial of $\\ln{(1+x)}$ at $x=0$.\r\n\tThe series created from all order Taylor polynomials is called the Taylor series of $\\ln{(1+x)}$ at $x=0$.\r\n\\end{answer}\r\n\r\n\\subsection{Definition}\r\n\\begin{definition}\r\n\tLet $f$ be a $n$ times differentiable function where all derivatives exist at $x=a$.\r\n\tThe Taylor series for $f$ at $x=a$ is\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{\\frac{f^{(k)}(x)}{k!}(x-a)^k} = f(a) + f^\\prime(a)(x-a) + \\frac{f^{\\prime\\prime}(a)}{2!}(x-a)^2 + \\ldots + \\frac{f^{(n)}(a)}{n!}(x-a)^n + \\ldots.\r\n\t\\end{equation*}\r\n\tThe $n$th partial sum of the Taylor Series,\r\n\t\\begin{equation*}\r\n\t\tP_n(x) = \\sum_{k=0}^{n}{\\frac{f^{(k)}(x)}{k!}(x-a)^k}\r\n\t\\end{equation*}\r\n\tis the Taylor polynomial of order $n$ for $f$ at $x=a$.\r\n\\end{definition}\r\n\r\nWhen $a=0$ you might also hear Taylor series referred to as Maclaurin series.\r\nLike power series, Taylor series have intervals of convergence.\r\n\r\n\\begin{example}\r\n\tFind the Taylor series for $e^x$ at $x=0$.\r\n\tVerify using term-by-term differentiation that $e^x$ is its own derivative.\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe know that $e^x$ is its own derivative, so $f^{(k)}(0)=e^0 = 1$ for all $i$.\r\n\tApplying the definition,\r\n\t\\begin{align*}\r\n\t\te^x &= e^0 + e^0(x-0) + \\frac{e^0}{2!}(x-0)^2 + \\frac{e^0}{3!}(x-0)^3 + \\ldots + \\frac{e^0}{n!}(x-0)^n + \\ldots \\\\\r\n\t\t&= 1 + x + \\frac{x^2}{2!} + \\frac{x^3}{3!} + \\ldots + \\frac{x^n}{n!} + \\ldots.\r\n\t\\end{align*}\r\n\t\r\n\tDifferentiating term-by-term,\r\n\t\\begin{equation*}\r\n\t\t\\dd{}{x}e^x = 1 + x + \\frac{x^2}{2!} + \\ldots + \\frac{x^{n-1}}{(n-1)!} + \\ldots\r\n\t\\end{equation*}\r\n\twe see that we get the same series, confirming that $e^x$ is its own derivative.\r\n\\end{answer}\r\n\r\n\\subsection{Common Maclaurin Series}\r\n\\begin{align*}\r\n\t\\frac{1}{1-x} &= 1 + x + x^2 + \\ldots = \\sum_{k=0}^{\\infty}{x^k}, \\abs{x} < 1 \\\\\r\n\t\\frac{1}{1+x} &= 1 - x + x^2 - \\ldots = \\sum_{k=0}^{\\infty}{(-1)^kx^k}, \\abs{x} < 1 \\\\\r\n\te^x &= 1 + x + \\frac{x^2}{2!} + \\ldots = \\sum_{k=0}^{\\infty}{\\frac{x^k}{k!}}, \\text{ all real $x$} \\\\\r\n\t\\sin{x} &= x - \\frac{x^3}{3!} + \\frac{x^5}{5!} - \\ldots = \\sum_{k=0}^{\\infty}{(-1)^k\\frac{x^{2k+1}}{(2k+1)!}}, \\text{ all real $x$} \\\\\r\n\t\\cos{x} &= 1 - \\frac{x^2}{2!} + \\frac{x^4}{4!} - \\ldots = \\sum_{k=0}^{\\infty}{(-1)^k\\frac{2^{2k}}{(2k)!}}, \\text{ all real $x$} \\\\\r\n\t\\ln{(1+x)} &= x - \\frac{x^2}{2} + \\frac{x^3}{3} - \\ldots = \\sum_{k=0}^{\\infty}{(-1)^k\\frac{x^{k+1}}{k+1}}, \\abs{x} \\leq 1 \\\\\r\n\t\\arctan{x} &= x - \\frac{x^3}{3} + \\frac{x^5}{5} - \\ldots = \\sum_{k=0}^{\\infty}{(-1)^k\\frac{x^{2k+1}}{2k+1}}, \\abs{x} \\leq 1.\r\n\\end{align*}\r\n\r\n\\subsubsection{Euler's Identity}\r\nYou might have seen the identity $e^{i\\pi} + 1 = 0$ or even $e^{ix} = \\cos{x} + i\\sin{x}$.\r\nUsing our common Taylor Series, we can derive this famous identity. \\\\\r\n\r\n\r\nStarting with the Taylor series for $e^{ix}$,\r\n\\begin{align*}\r\n\te^{ix} &= 1 + (ix) + \\frac{(ix)^2}{2!} + \\frac{(ix)^3}{3!} + \\frac{(ix)^4}{4!} + \\frac{(ix)^5}{5!} + \\ldots = \\sum_{k=0}^{\\infty}{\\frac{(ix)^k}{k!}}, \\text{ all real $x$} \\\\\r\n\t&= 1 + ix + i^2\\frac{x^2}{2!} + i^3\\frac{x^3}{3!} + i^4\\frac{x^4}{4!} + i^5\\frac{x^5}{5!} + \\ldots = \\sum_{k=0}^{\\infty}{i^k\\frac{x^k}{k!}}, \\text{ all real $x$} \\\\\r\n\t&= 1 + ix - \\frac{x^2}{2!} - i\\frac{x^3}{3!} + \\frac{x^4}{4!} + i\\frac{x^5}{5!} - \\ldots, \\text{ all real $x$} \\\\\r\n\t&= \\left(1 - \\frac{x^2}{2!} + \\frac{x^4}{4!} + \\ldots \\right) + i\\left(x - \\frac{x^3}{3!} + \\frac{x^5}{5!} + \\ldots \\right) \\\\\r\n\t&= \\cos{x} + i\\sin{x}.\r\n\\end{align*}\r\n\r\nPlugging in $x=\\pi$,\r\n\\begin{align*}\r\n\te^{i\\pi} &= \\cos{\\pi} + i\\sin{\\pi} \\\\\r\n\t&= -1 + 0 \\\\\r\n\te^{i\\pi} + 1 &= 0.\r\n\\end{align*}", "meta": {"hexsha": "d05903171a999caf8a281ea13053b5cfc657e093", "size": 6425, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/infinite_series/taylor_series.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/infinite_series/taylor_series.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/infinite_series/taylor_series.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 45.2464788732, "max_line_length": 192, "alphanum_fraction": 0.5425680934, "num_tokens": 2925, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619134371954, "lm_q2_score": 0.8791467595934563, "lm_q1q2_score": 0.7248230196065311}}
{"text": "\\section{Typing}\n\n\\subsection{Term}\n\n\\begin{enumerate}\n    \\item $\\tt Type$ is a term.\n    \\item Variables $\\tt x,y$, etc., are terms.\n    \\item Constants $\\tt c,d$, etc., are terms.\n    \\item If $\\tt x$ is a variable and $\\tt T,U$ are terms, then $\\tt\\forall x:T,U$ is a term.\n    \\item If $\\tt x$ is a variable and $\\tt T,u$ are terms, then $\\tt\\lambda x:T.\\ u$ is a term.\n    \\item If $\\tt x$ and $\\tt u$ are terms, then $\\tt (t\\ u)$ is a term.\n    \\item If $\\tt x$ is a variable and $\\tt t,T,u$ are terms, then $\\tt let\\ \\ x:=t:T\\ \\ in\\ \\ u$ is a term.\n\\end{enumerate}\n\n\\subsection{Typing Rule}\n\n\\subsubsection{Notation}\n\\begin{itemize}\n\\item $\\Gamma$ : local context.\n\\item $\\tt u\\{x/t\\}$ : substitute free occurrence of variable $\\tt x$ to term $\\tt t$ in term $\\tt u$.\n\\item $\\mathcal{WF}(\\Gamma)$ : $\\Gamma$ is well-formed.\n\\end{itemize}\n\n\\subsubsection{Typing Rules}\n\\begin{equation*}\n\\mathcal{WF}([])[] \n    \\tag{\\sc T-Empty}\n\\end{equation*}\n\\begin{equation*}\n\\frac{\\Gamma\\vdash {\\tt T:Type\\qquad \\qquad x}\\notin\\Gamma}\n    {\\mathcal{WF}(\\Gamma ::(\\tt x:T))} \n    \\tag{\\sc T-Ax}\n\\end{equation*}\n\\begin{equation*}\n\\frac{\\Gamma\\vdash {\\tt t:T\\qquad c}\\notin \\Gamma}\n    {\\mathcal{WF}(\\Gamma:\\tt c:=t:T)} \n    \\tag{\\sc T-Def}\n\\end{equation*}\n\\begin{equation*}\n\\frac{\\mathcal{WF}(\\Gamma)\\qquad ({\\tt x:T})\\in\\Gamma}\n    {\\Gamma\\vdash\\tt x:T} \n    \\tag{\\sc T-Var1}\n\\end{equation*}\n\\begin{equation*}\n\\frac{\\mathcal{WF}(\\Gamma)\\qquad ({\\tt x:=t:T})\\in\\Gamma}\n    {\\Gamma\\vdash\\tt x:T} \n    \\tag{\\sc T-Var2}\n\\end{equation*}\n\\begin{equation*}\n\\frac{\\mathcal{WF}(\\Gamma)\\qquad ({\\tt c:T})\\in \\Gamma}\n    {\\Gamma\\vdash\\tt c:T} \n    \\tag{\\sc T-Const1}\n\\end{equation*}\n\\begin{equation*}\n\\frac{\\mathcal{WF}(\\Gamma)\\qquad ({\\tt c:=t:T})\\in \\Gamma}\n    {\\Gamma\\vdash\\tt c:T} \n    \\tag{\\sc T-Const2}\n\\end{equation*}\n\n\\begin{equation*}\n\\frac{\\Gamma\\vdash{\\tt T:Type}\\qquad \\Gamma::({\\tt x:T})\\vdash\\tt U:Type}\n    {\\Gamma\\vdash\\tt\\forall x:T,U:Type} \n    \\tag{\\sc T-Prod}\n\\end{equation*}\n\\begin{equation*}\n\\frac{\\Gamma\\vdash\\forall{\\tt x:T,U:Type}\\qquad \\Gamma::({\\tt x:T})\\vdash{\\tt t:U}}\n    {\\Gamma\\vdash\\lambda{\\tt x:T.\\ t:\\forall x:T,U}} \n    \\tag{\\sc T-Abs}\n\\end{equation*}\n\\begin{equation*}\n\\frac{\\Gamma\\vdash\\forall{\\tt x:U,T}\\qquad \\Gamma\\vdash{\\tt u:U}}\n    {\\Gamma\\vdash{\\tt (t\\ u):T\\{x/u\\}}} \n    \\tag{\\sc T-App}\n\\end{equation*}\n\\begin{equation*}\n\\frac{\\Gamma\\vdash{\\tt t:T}\\qquad \\Gamma::({\\tt x:=t:T})\\vdash{\\tt u:U}}\n    {\\Gamma\\vdash{\\tt let\\ \\ x:=t:T\\ \\ in\\ \\ u:U\\{x/t\\}}} \n    \\tag{\\sc T-Let}\n\\end{equation*}\n\\begin{equation*}\n\\frac{(\\Gamma\\vdash {\\tt A_i:s_i)_{i=1..n}}\\qquad (\\Gamma,\\tt f_1:A_1,\\cdots,f_n:A_n\\vdash t_i:A_i)_{i=1..n}}\n    {\\Gamma\\vdash\\tt Fix\\ f_i\\{f_1:A_1:=t_1\\cdots f_n:A_n:=t_n\\}:A_i}\n    \\tag{\\sc T-Fix}\n\\end{equation*}\n\n\\subsection{Inductive Definition}\n\n\\subsubsection{Notation}\n\\begin{itemize}\n    \\item ${\\tt Ind}[p](\\Gamma_I:=\\Gamma_C)$ : inductive definition.\n    \\item $\\Gamma_I$ : names and types of inductive type.\n    \\item $\\Gamma_C$ : names and types of constructors of inductive type.\n    \\item $p$ : the number of parameters of inductive type.\n    \\item $\\Gamma_P$ : the context of parameters.\n\\end{itemize}\n\n\\subsubsection*{Example}\nHere is an example:\n\\begin{center}\n\\begin{minipage}{0.6\\textwidth}\n\\begin{minted}{coq}\nInductive list (T : Type) : Type :=\n| nil : list T\n| cons : T -> list T -> list T.\n\\end{minted}\n\\end{minipage}\n\\end{center}\n$$\n\\tt Ind\\ [1]\\left([list:Type\\to Type]:=\n\\begin{bmatrix}\n\\tt nil:\\forall T:Type,\\ list\\ T\\\\\n\\tt cons:\\forall T:Type,\\ T\\to list\\ T\\to list\\ T\n\\end{bmatrix}\\right)\n$$\nSadly, due to our limited time and energy, our system only supports inductive definition with $|\\Gamma_I|=1$,\nwhich means inhibiting mutual inductive type like the following case:\n\\begin{center}\n\\begin{minipage}{0.6\\textwidth}\n\\begin{minted}{coq}\nInductive tree : Type :=\n    node : forest -> tree\nwith forest : Type :=\n    | emptyf : forest\n    | consf : tree -> forest -> forest.\n\\end{minted}\n\\end{minipage}\n\\end{center}\n$$\n\\tt Ind\\ []\\left(\n\\begin{bmatrix}\\tt tree:Type\\\\\\tt forest:Type\\end{bmatrix}\n:=\n\\begin{bmatrix}\n\\tt node:forest\\to tree\\\\\n\\tt emptyf:forest\\\\\n\\tt consf:tree\\to forest\\to forest\n\\end{bmatrix}\\right)\n$$\n\n\\subsubsection{Typing Rule}\n\\begin{equation*}\n\\frac{\\mathcal{WF}(\\Gamma)\\qquad {\\tt Ind}[p](\\Gamma_I:=\\Gamma_C)\\in \\Gamma\\qquad {\\tt(a:A)}\\in\\Gamma_i}\n    {\\Gamma\\vdash\\tt a:A}\n    \\tag{\\sc T-Ind}\n\\end{equation*}\n\\begin{equation*}\n\\frac{\\mathcal{WF}(\\Gamma)\\qquad {\\tt Ind}[p](\\Gamma_I:=\\Gamma_C)\\in \\Gamma\\qquad {\\tt (c:C)}\\in\\Gamma_C}\n    {\\Gamma\\vdash\\tt c:C}\n    \\tag{\\sc T-Constr}\n\\end{equation*}\n\\begin{equation*}\n\\frac{(\\Gamma_P\\vdash{\\tt A_j:s_j'})_{j=1..k}\\qquad (\\Gamma_i;\\Gamma_P\\vdash{\\tt C_i:s_{q_i}})_{i=1..n}}\n    {\\mathcal{WF}(\\Gamma;{\\tt Ind}[p](\\Gamma_I:=\\Gamma_C))}\n    \\tag{\\sc T-Wf-Ind}\n\\end{equation*}\n\n\n\\subsection{Match}\n\n\\subsubsection{Notation}\nThe basic idea of this operator is that we have an object $\\tt m$ in an inductive type $\\tt I$ and we want\nto prove a property which possibly depends on $\\tt m$. For this, it is enough to prove the property for\n$\\tt m=(c_i\\ u_1\\ \\cdots\\ u_{p_i})$ for each constructor of $\\tt I$.\nThe term for this proof will be written:\n$$\n\\tt match\\ m\\ in\\ I\\ \\_\\ a\\ return\\ P\\ with\\ (c_1\\ x_{11}\\ \\cdots\\ x_{1p_1})\\Rightarrow f_1\\ |\\ \\cdots\\ |\\ (c_n\\ x_{n1}\\ \\cdots\\ x_{np_n})\\Rightarrow\nf_n\\ end\n$$\\par\nNote that the arguments of $\\tt I$ corresponding to parameters must be $\\tt\\_$, because the result type is not \ngeneralized to all possible values of the parameters. The other arguments of $\\tt I$ (sometimes called \\textit{indices}\nin the literature) have to be variables ($\\tt a$ above) and these variables can occur in $\\tt P$. The expression after \n$\\tt in$ must be seen as an inductive type pattern. Notice that expansion of implicit arguments and notations apply \nto this pattern. For the purpose of presenting the inference rules, we use a more compact notation:\n$$\n\\tt case(m,(\\forall ax.\\ P),\\lambda x_{11}\\cdots x_{1p_1}.\\ f_1\\ |\\ \\cdots\\ |\\ \\lambda x_{n1}\\cdots x_{np_n}.\\ f_n)\n$$\n\n\\subsubsection{Type of Branch}\nBefore coming to the typing rule of {\\tt match}, we have to deal with the type of every branch case of {\\tt match}.\\par\nLet $\\tt c$ be a term of type $\\tt C$, assume $\\tt C$ is a type of constructor for an inductive type $\\tt I$. Let\n$\\tt P$ be a term that represents the property to be proved. Assume $\\tt r$ is the number of parameters and \n$p$ is the number of arguments.\\par\nDefine a new type $\\tt \\{c:C\\}^P$ which represents the type of the branch corresponding to the $\\tt c:C$ constructor.\n\\begin{center}\n\\begin{tabular}{lcl}\n$\\tt \\{c:(I\\ p_1\\ \\cdots\\ p_r\\ t_1\\ \\cdots\\ t_p)\\}^P$ & $\\equiv$ & $\\tt (P\\ t_1\\ \\cdots\\ t_p\\ c)$\\\\\n$\\tt \\{c:\\forall x:T,\\ C\\}^P$ & $\\equiv$ & $\\tt \\forall x:T, \\{(c\\ x):C\\}^P$\n\\end{tabular}\n\\end{center}\nWe write $\\tt\\{c\\}^P$ for $\\tt\\{c:C\\}^P$ with $\\tt C$, the type of $\\tt c$.\n\n\\subsubsection{Typing Rule}\n\\begin{equation*}\n\\frac{\\Gamma\\vdash{\\tt c:(I\\ q_1\\ \\cdots\\ q_r\\ t_1\\ \\cdots\\ t_s)}\\qquad \n        \\Gamma\\vdash{\\tt [P\\ |\\ I\\ q_1\\ \\cdots\\ q_r]}\\qquad\n    (\\Gamma\\vdash{\\tt f_i:\\{(c_{p_i}\\ q_1\\ \\cdots\\ q_r)\\}^P})_{i=1..l}}\n    {\\Gamma\\vdash{\\tt case(c,P,f_1\\ |\\ \\cdots\\ |\\ f_l):(P\\ t_1\\ \\cdots\\ t_s\\ c)}}\n    \\tag{\\sc T-Match}\n\\end{equation*}\n$\\tt [A\\ |\\ B]$ means the consequent of $\\tt A$ is $\\tt B$.\n", "meta": {"hexsha": "2915283d63ebdd1992d8ef38f5fea6541919307e", "size": 7317, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/typing.tex", "max_stars_repo_name": "lsrcz/mini-prover", "max_stars_repo_head_hexsha": "0aa4cdf3b495ddf6707f27dcbee810d519b43177", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-05-31T05:55:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T20:17:52.000Z", "max_issues_repo_path": "tex/report/typing.tex", "max_issues_repo_name": "lsrcz/mini-prover", "max_issues_repo_head_hexsha": "0aa4cdf3b495ddf6707f27dcbee810d519b43177", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/report/typing.tex", "max_forks_repo_name": "lsrcz/mini-prover", "max_forks_repo_head_hexsha": "0aa4cdf3b495ddf6707f27dcbee810d519b43177", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.585, "max_line_length": 149, "alphanum_fraction": 0.6409730764, "num_tokens": 2739, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7248179043841392}}
{"text": "\n\\subsection{Central limit theorem}\n\n\\subsubsection{Generalise weak law of large numbers}\n\n\\subsubsection{Characteristic function of summed IID events}\n\n\\(Z=\\sum_{i=1}^nY_i\\)\n\n\\(\\phi_Z(t)=E[e^{itZ}]\\)\n\n\\(\\phi_Z(t)=E[e^{it\\sum_{i=1}^nY_i}]\\)\n\n\\(\\phi_Z(t)=E[e^{itY}]^n\\)\n\n\\(\\phi_Z(t)=\\phi_Y(t)^n\\)\n\n\\subsubsection{Taylor series: first moments dominate with means}\n\n\\(Z=\\sum_{i=1}^nY_i\\)\n\n\\(Y=\\dfrac{X}{n}\\)\n\n\\(\\phi_Z(t)=\\phi_Y(t)^n\\)\n\n\\(\\phi_Z(t)=\\phi_{\\dfrac{X}{n}}(t)^n\\)\n\n\\(\\phi_Z(t)=\\phi_X(\\dfrac{t}{n})^n\\)\n\n\\(\\phi_X(t)=1+it\\mu_X -\\dfrac{(\\mu_X +\\sigma_X^2 )t^2}{2} +\\sum_{j=3}^{\\infty }\\dfrac{E[X^j](it)^j}{j!}\\)\n\n\\(\\phi_X(\\dfrac{t}{n})=1+i\\dfrac{t\\mu_X }{n}-\\dfrac{(\\mu_X +\\sigma_X^2 )(\\dfrac{t}{n})^2}{2} +\\sum_{j=3}^{\\infty }\\dfrac{E[X^j](i\\dfrac{t}{n})^j}{j!}\\)\n\n\\(\\phi_X(\\dfrac{t}{n})=1+i\\dfrac{t\\mu_X }{n}-\\dfrac{(\\mu_X +\\sigma_X^2 )t^2}{2n^2} +\\sum_{j=3}^{\\infty }\\dfrac{E[X^j](i\\dfrac{t}{n})^j}{j!}\\)\n\n\\subsubsection{Eliminating the imaginary term}\n\nWe want \\(\\mu \\) to be \\(0\\).\n\n\\(Z=\\sum_{i=1}^nY_i\\)\n\n\\(Y=\\dfrac{X-\\mu_X }{n}\\)\n\n\\(\\phi_Y(t)=1+it\\mu_Y -\\dfrac{(\\mu_Y +\\sigma_Y^2 )t^2}{2} +\\sum_{j=3}^{\\infty }\\dfrac{E[Y^j](it)^j}{j!}\\)\n\n\\(\\mu_Y =E[\\dfrac{X-\\mu_X }{n}] ={\\mu_X -\\mu_X }{n}=0\\)\n\n\\(\\phi_Y(t)=1-\\dfrac{\\sigma_Y^2t^2}{2} +\\sum_{j=3}^{\\infty }\\dfrac{E[Y^j](it)^j}{j!}\\)\n\n\\(\\sigma^2_Y =E[(\\dfrac{X-\\mu_X }{n})^2]\\)\n\n\\(\\sigma^2_Y =E[\\dfrac{X^2+\\mu^2_X-2X\\mu_X }{n^2}]\\)\n\n\\(\\sigma^2_Y =\\dfrac{E[X^2]+E[\\mu^2_X]-E[2X\\mu_X] }{n^2}]\\)\n\\(\\sigma^2_Y =\\dfrac{E[X^2]-\\mu^2_X}{n^2}]\\)\n\n\\(\\sigma^2_Y =\\dfrac{\\sigma^2_X}{n^2}\\)\n\n\\(\\phi_Y(t)=1-\\dfrac{\\sigma_X^2t^2}{2n^2} +\\sum_{j=3}^{\\infty }\\dfrac{E[(\\dfrac{X-\\mu}{n})^j](it)^j}{j!}\\)\n\n\\(\\phi_Z(t)=\\phi_Y(t)^n\\)\n\n\\(\\phi_Z(t)=[1-\\dfrac{\\sigma_X^2t^2}{2n^2} +\\sum_{j=3}^{\\infty }\\dfrac{E[(\\dfrac{X-\\mu}{n})^j](it)^j}{j!}]^n\\)\n\n\\(\\phi_Z(t)=[1-\\dfrac{\\sigma_X^2t^2}{2n^2}]^n\\)\n\nEliminating \\(\\sigma^2 \\)\n\n\\(Z=\\sum_{i=1}^nY_i\\)\n\n\\(Y=\\dfrac{X-\\mu_X }{\\sigma n}\\)\n\n\\(\\phi_Y(t)=1+it\\mu_Y -\\dfrac{(\\mu_Y +\\sigma_Y^2 )t^2}{2} +\\sum_{j=3}^{\\infty }\\dfrac{E[Y^j](it)^j}{j!}\\)\n\n\\(\\mu_Y =E[\\dfrac{X-\\mu_X }{\\sigma_X n}] ={\\mu_X -\\mu_X }{\\sigma_X n}=0\\)\n\n\\(\\phi_Y(t)=1-\\dfrac{\\sigma_Y^2t^2}{2} +\\sum_{j=3}^{\\infty }\\dfrac{E[Y^j](it)^j}{j!}\\)\n\n\\(\\sigma^2_Y =E[(\\dfrac{X-\\mu_X }{\\sigma n})^2]\\)\n\n\\(\\sigma^2_Y =E[\\dfrac{X^2+\\mu^2_X-2X\\mu_X }{\\sigma^2 n^2}]\\)\n\n\\(\\sigma^2_Y =\\dfrac{E[X^2]+\\mu^2_X-2E[X]\\mu_X }{\\sigma^2 n^2}\\)\n\n\\(\\sigma^2_Y =\\dfrac{E[X^2]-\\mu^2_X}{\\sigma^2 n^2}\\)\n\n\\(\\sigma^2_Y =\\dfrac{\\sigma^2_X}{\\sigma^2 n^2}\\)\n\n\\(\\sigma^2_Y =\\dfrac{1}{n^2}\\)\n\n\\(\\phi_Y(t)=1-\\dfrac{t^2}{2n^2} +\\sum_{j=3}^{\\infty }\\dfrac{E[(\\dfrac{X-\\mu}{\\sigma n})^j](it)^j}{j!}\\)\n\n\\(\\phi_Z(t)=\\phi_Y(t)^n\\)\n\n\\(\\phi_Z(t)=[1-\\dfrac{t^2}{2n^2} +\\sum_{j=3}^{\\infty }\\dfrac{E[(\\dfrac{X-\\mu}{\\sigma n})^j](it)^j}{j!}]^n\\)\n\n\\(\\phi_Z(t)=[1-\\dfrac{t^2}{2n^2}]^n\\)\n\n\\subsubsection{Preparing for exponential expansion}\n\nWe know that\n\n\\([1+\\dfrac{x}{n}]^n=e^x\\)\n\nAs \\(n \\rightarrow \\infty\\).\n\nWith:\n\n\\(Z=\\sum_{i=1}^nY_i\\)\n\n\\(Y=\\dfrac{X-\\mu_X }{\\sigma n}\\)\n\nWe have:\n\n\\(\\phi_Z(t)=[1-\\dfrac{t^2}{2n^2}]^n\\)\n\nWith:\n\n\\(Z=\\sum_{i=1}^nY_i\\)\n\n\\(Y=\\dfrac{X-\\mu_X }{\\sigma \\sqrt n}\\)\n\nWe have:\n\n\\(\\phi_Z(t)=[1-\\dfrac{t^2}{2n}]^n\\)\n\nWhich tends towards\n\n\\(\\phi_Z(t)=e^{-\\dfrac{1}{2}t^2}\\)\n\n\\subsubsection{Rescaling}\n\nThe average of random variables, less their mean, and divided by their standard deviation multiplied by the square root of the sample size, follows a normal distribution as \\(n\\) increases.\n\nWhat does this say about the actual distribution of sample averages?\n\n\\(Z=\\sum_{i=1}^nY_i\\)\n\n\\(Y_i=\\dfrac{X_i-\\mu_X }{\\sigma_X \\sqrt n}\\)\n\n\\(\\sum_{i=1}^nY_i\\)\n\n\\(Y=\\dfrac{X}{n}\\)\n\nLet's create \\(Q\\).\n\n\\(Q=\\dfrac{Z\\sigma_X }{\\sqrt n}+\\mu_X\\)\n\n\\(Q=\\dfrac{(\\sum_{i=1}^nY_i)\\sigma_X }{\\sqrt n}+\\mu_X\\)\n\n\\(Q=\\dfrac{(\\sum_{i=1}^n(\\dfrac{X_i-\\mu_X }{\\sigma_X \\sqrt n}))\\sigma_X }{\\sqrt n}+\\mu_X\\)\n\n\\(Q=\\sum_{i=1}^n(\\dfrac{X_i-\\mu_X }{n})+\\mu_X\\)\n\n\\(Q=\\sum_{i=1}^n(\\dfrac{X_i-\\mu_X }{n}+\\dfrac{\\mu_X}{n})\\)\n\n\\(Q=\\sum_{i=1}^n(\\dfrac{X_i}{n})\\)\n\nThis is the sample average.\n\n\\(\\phi_Q(t)=\\phi_{\\dfrac{Z\\sigma_X }{\\sqrt n}+\\mu_X}(t)\\)\n\n\\(\\phi_Q(t)=\\phi_Z(\\dfrac{t\\sigma_X }{\\sqrt n})e^{it\\mu_X}\\)\n\n\\(\\phi_Z(\\dfrac{t\\sigma_X }{\\sqrt n})=e^{-\\dfrac{1}{2}(\\dfrac{t\\sigma_X }{\\sqrt n})^2}\\)\n\n\\(\\phi_Z(\\dfrac{t\\sigma_X }{\\sqrt n})=e^{-\\dfrac{1}{2}\\dfrac{t^2\\sigma^2_X }{n}}\\)\n\n\\(\\phi_Q(t)=e^{-\\dfrac{1}{2}\\dfrac{t^2\\sigma^2_X }{n}}e^{it\\mu_X}\\)\n\n\\subsubsection{Normal distribution}\n\nWe name the normal distribution this function when \\(n=1\\)\n\n\\(N(\\mu_X, \\sigma^2_X)=e^{-\\dfrac{1}{2}\\dfrac{t^2\\sigma^2_X }{n}}e^{it\\mu_X}\\)\n\n\\(N(\\mu_X, \\sigma^2_X)=e^{-\\dfrac{1}{2}t^2\\sigma^2_X }e^{it\\mu_X}\\)\n\n\\subsubsection{Getting the probability distribution function}\n\n\\(\\phi_X(t)=e^{-\\dfrac{1}{2}t^2\\sigma^2_X} e^{it\\mu_X}\\)\n\n\\(\\phi_X(t)=e^{-\\dfrac{1}{2}t^2\\sigma^2_X}[\\cos (t\\mu_X )+i\\sin (t\\mu_X)]\\)\n\n", "meta": {"hexsha": "fa48646ce57acab93ce2c748d2da07bd3b83f5e9", "size": 4789, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/iidCLT/01-04-IIDCLT.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/iidCLT/01-04-IIDCLT.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/iidCLT/01-04-IIDCLT.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8864864865, "max_line_length": 189, "alphanum_fraction": 0.5694299436, "num_tokens": 2371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145179, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.7247958304471456}}
{"text": "\\chapter{Residual Neural Networks}\nRecall that \n\\begin{equation}\nf^j = \\theta^j \\circ g\\circ f^{j-1}= \\theta^j \\circ g\\circ\n\\theta^{j-1} \\circ g \\circ f^{j-2} \n\\end{equation}\n\\begin{equation}\\label{fjj}\nf^j = \\theta^j \\circ g\\circ \\theta^{j-1} \\circ x_{j-1}\n\\end{equation}\nwhere\n\\begin{equation}\n  \\label{eq:4}\nx_{j-1}=g \\circ f^{j-2}, \\quad x_0=x  \n\\end{equation}\nWe note \\eqref{fjj} can be viewed as a nonlinear encoder for\n$x_{j-1}$.  We now introduce the enhanced encoder has follows:\n\\begin{equation}\n  \\label{tildefj}\n  \\tilde f^j=f^{j}+\\tilde \\theta_{j-1}\\circ x_{j-1}\n\\end{equation}\nwhich is the main idea used for ResNet. \n\nSo we have the network like:\n\\begin{equation}\n\\begin{cases}\nf^{2j} &= \\theta^{2j} \\circ g^{2j}( \\tilde f^{2j-1}), \\\\\nf^{2j-1} &= \\theta^{2j-1} \\circ g^{2j-1}(f^{2j-2}), \\\\\nf_0 &= \\theta^0(x).\n\\end{cases} \\\\\n\\end{equation}\nWhen $\\tilde \\theta_{j}$ is a square ``matrix\", we can just take $ \\theta_{j} = I$, this is what ResNet often used.\n\nLet us make some comments\n\\begin{enumerate}\n\\item It has been numerically observed that when $n_j=n_{j-1}$, one can take \n  \\begin{equation}\n    \\label{eq:1}\n\\theta_j=id.    \n  \\end{equation}\n\\item In the usual CNN, it may happen that $\\theta^j\\approx 0$.  This\n  means that the information is getting ``lost'' at the current level\n  by ``improper'' (too much?) pooling or stride.  In this case,\n  \\eqref{tildefj} helps ``recover'' the information from the previous\n  layer.   In this case\n  \\begin{equation}\n\\tilde f^j\\approx x_{j-1}    \n  \\end{equation}\n\\item Continuing with the above argument, it is then reasonable to\n  expect that ResNet can use very large number of layers so that the\nkey features are still well kept from layer to layer.\n\\end{enumerate}\n\n\\bigskip \n\\bigskip \n\\begin{equation}\nf^j = \\theta^j \\circ g^j(f^{j-1} + g\\circ f^{j-3}) ),\n\\end{equation}\n\nTake \n\\begin{equation}\nx = g\\circ f^{j-3},\n\\end{equation}\nso $f^{j-1}$ is a function of $x$ as:\n\\begin{equation}\nf^{j-1} = \\theta^{j-1} \\circ g \\circ \\theta^{j-1} (x).\n\\end{equation}\n\n\\section{ResNet model based on classical notation}\nFor general image classification problems, many numerical results shows that, if we just use the general CNN structure, you will get worse generallization error with deeper network. However, after 2015, Kaiming He and etc found that if they adopt the ``shortcut\" structure into the general CNN they will get better result as networks become deeper and deeper in some degree and they call that kinds of CNN model as ResNet. After that, all state-of-art DL models adopt the ResNet properties to construct those deep CNN models with low generalization error. \n\n\\subsection{Shortcut connection and ResNet models}\nFirst, we would like to talk about the so called ``shortcut connection\" in general neural network. As we know, the output of $f_j$ is dependent with $f_i$ for all $ i < j$, but is just decided by $f_{j-1}$ directly and this can be shown in BP algorithm. Shortcut connection means to make the direct dependence longer like \n\\begin{equation}\nf^j = \\theta^j \\circ g^j \\circ h( f^{j-1}, \\cdots, f^{j-k}).\n\\end{equation} \n\nIf we use the idea of encoder for CNN, we can take both $f^j$ with $j = 1:J$ as the nonlinear encoder of data. By the way, we can also think that $f^j$ is the nonlinear encoder of $f^i$ with $i < j$.  So, we may take $h$ as:\n\\begin{equation}\nh(f^{j-1}, \\cdots, f^{j-k}) = f^{j-1} + \\sum_{s = 2}^k P_{j-s}^{j-1} f^{j-s}.\n\\end{equation}\nor we need to add nonlinear map as:\n\\begin{equation}\nh(f^{j-1}, \\cdots, f^{j-k}) = f^{j-1} + \\sum_{s = 2}^k P_{j-s}^{j-1} g^{j-s+1}(f^{j-s}).\n\\end{equation}\n\n\n\n\n\nSo, in fact we have many choice for change ResNet models, now we just introduce what kinds of shortcut connection in  RestNet. \n\\begin{equation}\nf^j = \\theta^j \\circ g^j(f^{j-1} + P^jg^{j-2}(f^{j-3}) ),\n\\end{equation}\nthis can be shown in the next figure:\n\\begin{figure}[!htb]\n\t\\center{\\includegraphics[width=6cm] {figures/ShortCut.png}}        \n\t\\caption{The Architecture of ShortCut Connection with Distance 2}      \n\t\\label{LeNet-5}\n\\end{figure}\nSo, a general ResNet structure would be like:\n\\begin{equation}\n\\begin{cases}\nf^{2j-1} &= \\theta^{2j-1} \\circ g^{2j-1}(f^{2j-2}), \\\\\n\\tilde f^{2j-1} &= f^{2j-1} + g\\circ \\tilde f^{2(j-1)-1}, \\\\\nf^{2j} &= \\theta^{2j} \\circ g^{2j}(\\tilde f^{j-1}),  \\\\\nf_0 &= \\theta^0(x).\n\\end{cases}\n\\end{equation}\n\n\n\n\\subsection{ResNet in ImageNet}\nHere is a table to show the general structure for ResNet for ImageNet in 2015.\n\\begin{figure}[!htb]\n\t\\center{\\includegraphics[width=10cm] {figures/ResNet_ImageNet.png}}        \n\t\\caption{The Architecture of RestNet for ImageNet}      \n\t\\label{LeNet-5}\n\\end{figure}\n\nThe $\\times 2$ block is the same to above, and the $\\times 3$ block is shown next:\nHere is a table to show the general structure for ResNet for ImageNet in 2015.\n\\begin{figure}[!htb]\n\t\\center{\\includegraphics[width=6cm] {figures/ShortCut2.png}}        \n\t\\caption{The Architecture of two kinds of shortcut connection}      \n\t\\label{LeNet-5}\n\\end{figure}\nOr we can show it as:\n\\begin{equation}\nf^j = \\theta^j \\circ g^j(f^{j-1} + P^jg^{j-3}(f^{j-4}) ),\n\\end{equation}\nthen the network would like:\n\\begin{equation}\n\\begin{cases}\nf^{3j-2} &= \\theta^{3j-2} \\circ g^{3j-2}(f^{3(j-1)}), \\\\\nf^{3j-1} &= \\theta^{3j-2} \\circ g^{3j-1}({f}^{3j-2}) \\\\\n\\tilde{f}^{3j-1} &= f^{3j-1} + g(\\tilde f^{3(j-1)-1}), \\\\\nf^{3j} &= \\theta^{3j}\\circ g^{3j}(\\tilde f^{3j-1}) \\\\\nf_0 &= \\theta^0(x).\n\\end{cases} \n\\end{equation}\n\n\\subsection{Some properties of ResNet v.s PlainNet}\nIn the first paper about the ResNet, the authors proposed some properties of ResNet:\n\\begin{enumerate}\n\\item In some region, the deeper network the better results for ResNet. But, this cannot hold for plain network generally. \n\\begin{figure}[!htb]\n\t\\center{\\includegraphics[width=6cm] {figures/PlainNet.png}}        \n\t\\caption{The Architecture of two kinds of shortcut connection}      \n\t\\label{LeNet-5}\n\\end{figure}\n\n\\begin{figure}[!htb]\n\t\\center{\\includegraphics[width=10cm,height=4.5cm] {figures/PlianNetvsResNet.png}}        \n\t\\caption{The Architecture of two kinds of shortcut connection}      \n\t\\label{LeNet-5}\n\\end{figure}\n\n\\begin{figure}[!htb]\n\t\\center{\\includegraphics[width=12cm,height=4cm] {figures/PlianNetvsResNet-10.png}}        \n\t\\caption{The Architecture of two kinds of shortcut connection}      \n\t\\label{LeNet-5}\n\\end{figure}\n\n\n\\item Generally speaking, ResNet networks can be trained more easily than the plain network with the same depth.\n\n\\item For some case, if the pooling or convolution with stride is bigger than 1, the size of $f^{j-1}$ and $g^{j-3}(f^{j-4})$ are not the same, so we may need a \"interpolation-restriction\" matrix $P_{j-3}^{j-1}$ for the essential dimension is restriction but the channel dimension is restriction. And even for the dimension is the same, we can also use a transform for this operator i.e\n\\begin{equation}\nf^j = \\theta^j \\circ g^j(f^{j-1} + P^jg^{j-2}(f^{j-3}) ),\n\\end{equation}\nIn the first paper about the ResNet, there are some numerical results to show that, P is only adopted when the dimension is changed.\n\\begin{figure}[!htb]\n\t\\center{\\includegraphics[width=6cm] {figures/ResNetProjection.png}}        \n\t\\caption{The Architecture of two kinds of shortcut connection}      \n\t\\label{LeNet-5}\n\\end{figure}\n\nFor the next three strategies:\n\\begin{enumerate}\n\\item Zero-padding shortcuts are used for increasing dimensions, and all shortcuts are parameter-free, i,e all $P^j$ is fix.\n\\item Projection shortcuts are used for increasing dimensions, and other shortcuts are identity.\n\\item All shortcuts are projections, i.e we need train all $P^j$.\n\\end{enumerate}\n\n\n\\section{One developed ResNet model}\nFor this model, which can be expressed as:\n\\begin{equation}\\label{I_ResNet_old}\n\t\\begin{cases}\n\t\tf^{2j-1} &= \\theta^{2j-1} \\circ g^{2j-1}(f^{2j-2}), \\\\\n\t\t\\tilde f^{2j-1} &= f^{2j-1} + g\\circ \\tilde f^{2(j-1)-1}, \\\\\n\t\tf^{2j} &= \\theta^{2j} \\circ \\tilde f^{j-1},  \\\\\n\t\tf_0 &= \\theta^0(x).\n\t\\end{cases}\n\\end{equation}\nThis can make sense is because of the fact that, if we take \n\\begin{equation}\nF(x) = \\theta \\circ g \\circ \\theta(x)\n\\end{equation}\nand noted\n\\begin{equation}\ng^{j-2}(f^{j-3}) = x^1,\n\\end{equation}\nthen we have\n\\begin{equation}\nx^l = P^lx^{l-1} + F^l(x^{l-1}),\n\\end{equation}\nand for $P^{l} = I$ for almost cases.  For example, $P^l = I$ for $l = t+1: T$, which means:\n\\begin{equation}\nx^T = x^t + \\sum_{l=t}^{T} F^l(x^{l-1}).\n\\end{equation}\nwhich means that information can transform for long distance especially between two pooling operations.\n\n\\newpage\n\\subsection{A look at some special case}\nLet us take $j=9$ in \\eqref{ResNet0}\n\n\\begin{equation}\\label{ResNet9}\n  \\begin{array}{rcl}\nf^0&=&\\theta^0(x)\\\\    \nf^1&=&\\theta^1\\circ g\\circ f^0(x)\\\\    \n\\tilde f^1&=&f^1 \\\\\nf^2&=&\\theta^2\\circ g\\circ f^1(x)\\\\    \nf^3&=&\\theta^3\\circ g\\circ f^2(x)\\\\    \n\\tilde f^3&=&f^3+g\\circ \\tilde f^1 \\\\\nf^4&=& \\theta^4\\circ g\\circ \\tilde f^3(x) \\\\\nf^5&=&\\theta^5\\circ g\\circ f^4(x)\\\\    \n\\tilde f^5&=&f^5+g\\circ \\tilde f^3 \\\\\nf^6&=&\\theta^6\\circ g\\circ \\tilde f^5(x)\\\\    \nf^7&=&\\theta^7\\circ g\\circ f^6(x)\\\\  \n\\tilde f^7&=&f^7+g\\circ \\tilde f^5 \\\\\n f^8&=& \\theta^8\\circ g\\circ\\tilde f^7(x) \\\\ \n f^9&=& \\theta^9 \\circ g \\circ f^8(x)\n  \\end{array}\n\\end{equation}\n\nThe above equation \\eqref{ResNet9} shows the ResNet with 9 layers and step-2.\n\nNow if we note\n\\begin{equation}\ny^l = g \\circ \\tilde{f}^l,\n\\end{equation}\nand\n\\begin{equation}\nF^l(y^l) = \\theta^{l+2} \\circ g \\circ \\theta^{l+1}(y^l),\n\\end{equation}\n\nSo the above net work is:\n\\begin{equation}\\label{ResNet9-1}\n  \\begin{array}{rcl}\nf^9 &=& F^7(y^7) \\\\\ny^7 &=& g \\circ  [ F^5(y^5) + y^5 ]\\\\\ny^5 &=& g \\circ  [F^3(y^3) + y^3 ]\\\\\ny^3 &=& g \\circ  [F^1(y^1) + y^1 ]\\\\\ny^1 &=& g \\circ f^1\n  \\end{array}\n\\end{equation}\nSo, remove the $g$ in \\eqref{ResNet9-1} seems very natural in the\nabove notation.\n\nThe most recent \n\\begin{equation}\\label{ResNet9-1}\n  \\begin{array}{rcl}\nf^9 &=& F^7(y^7) \\\\\ny^7 &=& F^5(y^5) + y^5 \\\\\ny^5 &=& F^3(y^3) + y^3 \\\\\ny^3 &=& F^1(y^1) + y^1 \\\\\ny^1 &=&  f^1\n  \\end{array}\n\\end{equation}\nThe most recent \n\\begin{equation}\\label{ResNet9-new}\n  \\begin{array}{rcl}\nf^9 &=& F^7(y^7) \\\\\ny^7 &=& F^5(y^5) + y^5 \\\\\ny^5 &=& F^3(y^3) + y^3 \\\\\ny^3 &=& F^1(y^1) +  y^1 \\\\\ny^1 &=&  f^1\n  \\end{array}\n\\end{equation} \nNow adding all the formulas in \\eqref{ResNet9-new}, we get\n\\begin{equation}\\label{ResNet9-additive}\nf^9 = F^7(y^7) + F^5(y^5) + F^3(y^3) +  F^1(y^1) + f^1\n\\end{equation}\n\nRecall in multigrid\n$$\nI-B_kA_kP_k=(I-T_k)(I-B_{k-1}A_{k-1}P_{k-1})\n=I-T_k(I-B_{k-1}A_{k-1}P_{k-1})-B_{k-1}A_{k-1}P_{k-1}\n$$\n$$\nB_kA_kP_k=B_{k-1}A_{k-1}P_{k-1}\n+T_k(I-B_{k-1}A_{k-1}P_{k-1}) \n$$\n$$\nB_JA_J=P_1+\\sum_{k=2}^JT_k(I-B_{k-1}A_{k-1}P_{k-1}) \n=P_1+\\sum_{k=2}^JT_k\\prod_{j=1}^{k-1}(I-T_j)\n$$\n\nWe note that\n$$\nF^1(y^1)=\\theta^3\\circ g\\circ \\theta^2\\circ y^1\n$$\nWe can take \n$$\n\\theta^2=\\check \\theta^2\\circ (I-\\hat\\theta^1)\n$$\nWe can find \n$$\n\\bar\\theta^3\\circ g\\circ \\bar\\theta^2 = I\n$$\nwhich means\n$$\n\\sum_{i=1}^k a_ig(w_ix+b_i)+c =x\n$$\nNow we make some special choices:\n\\begin{equation}\\label{id}\n\\bar\\theta^3\\circ g\\circ (\\bar\\theta^2\\circ(\\theta^2-I)) = \\theta^2-I\n\\end{equation}\nThus\n$$\ny^3=\\theta^2\\circ y^1\n$$\nThis recovers the linear model! Here to recover the \\eqref{id} we only need the have that \n\n\\begin{equation}\\label{id_cond}\n\\theta^3 \\in \\mathbb{R}^{n\\times 2n} \\quad \\text{and} \\quad \\theta^2 \\in \\mathbb{R}^{2n \\times n}.\n\\end{equation}\n\n\\newpage\n\nThe introduction of the original paper on ResNet \\cite{HeKaiming2015} include the following statement:\n\\begin{quote}\\it\n  We can also use a square matrix $W_s$ in Eqn. (1). But we will show by experiments that the identity mapping is sufficient for addressing the degradation problem and is economical, and thus $W_s$ is only used when matching dimensions. \n\\end{quote}\nIn our notation, $W_s$ is just the $\\tilde\\theta^3$ in \\eqref{ResNet4}.\n\nWe now compare a usual DNN as follows\n\\begin{equation}\\label{OriginalResNet4}\n  \\begin{array}{rcl}\nf^0&=&\\theta^0(x)\\\\    \nf^1&=&\\theta^1\\circ g\\circ f^0(x)\\\\    \n&\\vdots& \\\\        \nf^9&=&\\theta^9\\circ g\\circ f^8(x)\n  \\end{array}\n\\end{equation}\n\\end{enumerate}\n\nWe now study the relationship between \\eqref{ResNet4} and \\eqref{OriginalResNet4}.  Our question is then: Can we find weights such that the following identity holds\n\\begin{equation}\n\\label{ResNet4}\n\\theta^4\\circ g\\circ f^3=\\tilde \\theta^4\\circ g\\circ[f^3+\\tilde \\theta^3\\circ g\\circ f^1].    \n\\end{equation}\nand furthermore $\\tilde \\theta^3$ is non-singular? \n\nLet us first consider the case that $g=id$, we ask\n$$\n\\theta^4\\circ f^3=\\tilde \\theta^4[f^3+\\tilde \\theta^3\\circ f^1].    \n$$\n$$\n\\theta^4\\circ \\theta^3\\circ \\theta^2 f^1=\\tilde \\theta^4[\\theta^3\\circ \\theta^2 f^1+\\tilde \\theta^3\\circ f^1].    \n$$\n$$\n\\theta^4\\circ \\theta^3\\circ \\theta^2 =\\tilde \\theta^4\\circ [\\theta^3\\circ \\theta^2 +\\tilde \\theta^3].    \n$$\n\n\n\\newpage\n\\subsection{New notation}\n\\begin{equation}\n  \\label{extractor}\nH_k(x)=\\xi^k\\circ g\\circ \\eta_k(x)  \n\\end{equation}\nThe ResNet can then be written as\n\\begin{equation}  \\label{RNk}\nx^k=x^{k-1}+H_k(x^{k-1}), \\quad k=1:J  \n\\end{equation}\nwith \n$$\nx^0=x.\n$$\nWe make the following observations:\n\\begin{enumerate}\n\\item \\eqref{RNk} looks like nonlinear ``smoother'' or ``rougher'',\n  but it is a combination of additive-multiplicative or\n  BPX like.  It is like Block Gauss-Seidel with each block given by Jacobi.\n\\item We can make the above procedure to be multiplicative, which may\n  improve efficiency. \n\\item Each different $k$ in \\eqref{RNk} gives a new layer in the\n  ResNet, but these are kind of ``fake'' layers.\n\\item The really new layer is only created by restriction, such as\n  ``stride''\n\\item Different $H_k$ gives more parameters, which in a way gets\n  closer to the variable convolution ... which corresponds to\n  \\begin{enumerate}\n\\item more different kernels on each pixel point\n\\item  more channels, \n\\end{enumerate}\n\\item The real layers should only be given when the dimension of the \n  problem changes.   Namely the dimensions of different layers has to be\n  different. \n\\item The relationship between ResNet and PlainNet is as follows:\n  \\begin{enumerate}\n  \\item PlainNet is Gauss-Seidel\n\\item ResNet is to convert part of the above Gauss-Seidel by a mixture\n  of   Gauss-Seidal and Jacobi!\n  \\end{enumerate}\n\\end{enumerate}\n\n\\subsubsection{New terminology: ``extractor''}\nWe call each $H_k$ as \n\\begin{enumerate}\n\\item ``extractor''\n\\item smoother\n\\item rougher\n\\end{enumerate}\n\n\n\n", "meta": {"hexsha": "20783d5d66c1bda9f7610c32f41cc9ea3e71e044", "size": 14422, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ResNet.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/ResNet.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/ResNet.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.3380952381, "max_line_length": 556, "alphanum_fraction": 0.673415615, "num_tokens": 5264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276222, "lm_q2_score": 0.8376199694135333, "lm_q1q2_score": 0.7247289754059791}}
{"text": "% !TeX root = ../main.tex\n% Add the above to each chapter to make compiling the PDF easier in some editors.\n\n\\chapter{Homomorphism and Isomorphism Theorems}\nIn this chapter, we will discuss tools to show that two groups are isomorphic.\n\n\\begin{thm}[Homomorphism Theorem]\\index{homomorphism theorem}\nLet $\\varphi : G \\to H$ be a group homomorphism. Then, \\begin{align}\n    \\rep{\\varphi} : \\Quot{G}{\\ker{\\varphi}} \\to \\im{\\varphi},\\quad a \\ker{\\varphi} \\mapsto \\varphi(a)\n\\end{align} is an isomorphism. Especially, $\\Quot{G}{\\ker{\\varphi}} \\isom \\im{\\varphi}$.\n\\end{thm} \\begin{proof}\n\\leavevmode\\begin{itemize}\n    \\item We will first show that $\\rep{\\varphi}$ is well-defined. For any $a, b \\in G$, \\begin{align*}\n        &a \\ker{\\varphi} = b \\ker{\\varphi} \\\\\n        \\iff\\quad &\\inv{a} b \\in \\ker{\\varphi} \\margintag{by \\cref{lem:cosets_eq}} \\\\\n        \\iff\\quad &\\varphi(\\inv{a} b) = e_H \\margintag{using the definition of the kernel \\eqref{eq:kernel}} \\\\\n        \\iff\\quad &\\inv{\\varphi(a)} \\varphi(b) = e_H \\margintag{using that $\\varphi$ is a homomorphism \\eqref{eq:homomorphism}} \\\\\n        \\iff\\quad &\\varphi(a) = \\varphi(b) \\\\\n        \\iff\\quad &\\rep{\\varphi}(a \\ker{\\varphi}) = \\rep{\\varphi}(b \\ker{\\varphi}). \\margintag{using the definition of $\\rep{\\varphi}$}\n    \\end{align*} The direction ``$\\Rightarrow$'' shows that $\\rep{\\varphi}$ is well-defined. Note that ``$\\Leftarrow$'' shows that $\\rep{\\varphi}$ is injective.\n    \n    \\item Next, we show that $\\rep{\\varphi}$ is a homomorphism. For any $a, b \\in G$, \\begin{align*}\n        \\rep{\\varphi}(a \\ker{\\varphi} \\cdot b \\ker{\\varphi}) &= \\rep{\\varphi}(a b \\ker{\\varphi}) \\margintag{using the operation of the quotient group \\eqref{eq:quotient_group_op}} \\\\[5pt]\n        &= \\varphi(a b) \\margintag{using the definition of $\\rep{\\varphi}$} \\\\\n        &= \\varphi(a) \\cdot \\varphi(b) \\margintag{using that $\\varphi$ is a homomorphism \\eqref{eq:homomorphism}} \\\\\n        &= \\rep{\\varphi}(a \\ker{\\varphi}) \\cdot \\rep{\\varphi}(b \\ker{\\varphi}). \\margintag{using the definition of $\\rep{\\varphi}$}\n    \\end{align*}\n    \n    \\item Finally, we observe that $\\rep{\\varphi}$ is surjective. That is, for any $a \\in \\im{\\varphi}$, we have that $a \\ker{\\varphi} \\in \\Quot{G}{\\ker{\\varphi}}$. \\qedhere\n\\end{itemize}\n\\end{proof}\n\n\\begin{ex}{Homomorphism theorem}{}\nWe have already seen in \\cref{ex:homomorphisms} that for any field $K$, ${\\det : \\GL{n}{K} \\to \\woZ{K}}$ is a homomorphism with ${\\ker{\\det} = \\SL{n}{K}}$. Thus, by the homomorphism theorem, \\begin{align}\n    \\Quot{\\GL{n}{K}}{\\SL{n}{K}} \\isom \\woZ{K}.\n\\end{align}\n\\end{ex}\n\n\\begin{marginfigure}\n    \\includegraphics[width=\\textwidth]{correspondence_thm.png}\n    \\caption{Sketch of the correspondence of subgroups $U_i$ ``between'' $G$ and $N$ and the subgroups $\\Quot{U_i}{N}$ ``between'' $\\Quot{G}{N}$ and $\\Quot{N}{N}$.}\\label{fig:correspondence_thm}\n\\end{marginfigure}\n\n\\begin{thm}[Correspondence Theorem]\\index{correspondence theorem}\nThe mapping, \\begin{align}\n    f : \\{U \\subgroup G \\mid N \\subseteq U\\} \\to \\{V \\subgroup \\Quot{G}{N}\\},\\quad U \\mapsto \\Quot{U}{N},\n\\end{align} is an inclusion-preserving\\footnote{We say that a mapping ${f : A \\to B}$ is \\emph{inclusion-preserving}\\index{inclusion-preserving mapping} if for any $a_1, a_2 \\in A$ such that ${a_1 \\subseteq a_2}$, we have ${f(a_1) \\subseteq f(a_2)}$.} bijection and fore every $U \\subgroup G$, \\begin{align}\n    U \\normal G \\iff \\Quot{U}{N} \\normal \\Quot{G}{N}.\n\\end{align}\n\\end{thm} \\noindent A sketch of the correspondence theorem is given in \\cref{fig:correspondence_thm}.\n\n\\begin{marginfigure}\n    \\includegraphics[width=\\textwidth]{first_isom_thm.png}\n    \\caption{Sketch of the first isomorphism theorem.}\\label{fig:first_isom_thm}\n\\end{marginfigure}\n\n\\begin{thm}[First Isomorphism Theorem]\\index{first isomorphism theorem}\\index{isomorphism theorem}\nLet $U \\subgroup G$ and $N \\normal G$. Then, \\begin{thmlist}\n    \\item $U N \\subgroup G$ where $U N \\defeq \\{x \\cdot n \\mid x \\in U, n \\in N\\}$\n    \\item $U \\cap N \\normal U$\n    \\item $\\Quot{UN}{N} \\isom \\Quot{U}{(U \\cap N)}$\n\\end{thmlist}\n\\end{thm} \\noindent A sketch of the correspondence theorem is given in \\cref{fig:first_isom_thm}.\n\n\\begin{marginfigure}\n    \\includegraphics[width=\\textwidth]{second_isom_thm.png}\n    \\caption{Sketch of the second isomorphism theorem..}\\label{fig:second_isom_thm}\n\\end{marginfigure}\n\n\\begin{thm}[Second Isomorphism Theorem]\\index{second isomorphism theorem}\\index{isomorphism theorem}\nLet $U, N \\normal G$ with $N \\subseteq U$. Then, $\\Quot{(\\Quot{G}{N})}{(\\Quot{U}{N})} \\isom \\Quot{G}{U}$.\n\\end{thm}", "meta": {"hexsha": "1da4a6fe843ac6ab46834a5d5e9458aae262e6bd", "size": 4582, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/03_homomorphism_and_isomorphism_theorems.tex", "max_stars_repo_name": "jonhue/algebra", "max_stars_repo_head_hexsha": "b91da0f3fff239010d0584535f1b5f0d4f0184aa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/03_homomorphism_and_isomorphism_theorems.tex", "max_issues_repo_name": "jonhue/algebra", "max_issues_repo_head_hexsha": "b91da0f3fff239010d0584535f1b5f0d4f0184aa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/03_homomorphism_and_isomorphism_theorems.tex", "max_forks_repo_name": "jonhue/algebra", "max_forks_repo_head_hexsha": "b91da0f3fff239010d0584535f1b5f0d4f0184aa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.6388888889, "max_line_length": 307, "alphanum_fraction": 0.6691401135, "num_tokens": 1618, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8652240877899775, "lm_q1q2_score": 0.7247289686897195}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=2}^\\infty \\frac{2n}{n^2+1}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution 1}\r\n\r\nThe function $f(x)=\\frac{2x}{x^2+1}$ is continuous, positive, and decreasing on $[2,\\infty)$.\r\n\\begin{align*}\r\n\\int_2^\\infty \\frac{2x}{x^2+1}\\,dx\r\n&= \\lim_{t \\to \\infty} \\int_2^t \\frac{2x}{x^2+1}\\,dx\\\\\r\n&= \\lim_{t \\to \\infty} (\\ln|t^2+1| - \\ln |2^2+1|)\\\\\r\n&= \\infty\r\n\\end{align*}\r\nSince the integral $\\displaystyle \\int_2^\\infty \\frac{2x}{x^2+1}\\,dx$ diverges, the series $\\displaystyle \\sum_{n=2}^\\infty \\frac{2n}{n^2+1}$ diverges by the Integral Test.\r\n\r\n\\subsection*{Solution 2}\r\n\r\nSince $n^2 \\geq 1$, by adding $n^2$ to both sides of this inequality\r\n\\[ 2n^2 \\geq n^2 + 1\\]\r\nDividing both sides of this ineqaulity by $n(n^2+1)$, we get\r\n\\[ \\frac{2n}{n^2+1} \\geq \\frac1n\\]\r\nSince the series $\\sum \\frac1{n}$ diverges by the $p$-test, the series $\\sum \\frac{2n}{n^2+1}$ diverges by the Direct Comparison Test.\r\n\r\n\\subsection*{Solution 3}\r\n\r\nThe series $\\sum \\frac1{n}$ diverges by the $p$-test. Let $a_n = \\frac{2n}{n^2+1}$ and $b_n = \\frac1{n}$.\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} \\frac{a_n}{b_n}\r\n&= \\lim_{n \\to \\infty} \\frac{2n^2}{n^2+1}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{4n}{4n} \\text{ by l'hopital}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac44 \\text{ by algebra}\\\\\r\n&= 1\r\n\\end{align*}\r\nThe Limit Comparison Test applies, since this limit was a positive, finite number. Therefore, the series $\\sum \\frac{2n}{n^2+1}$ diverges by the Limit Comparison Test.\r\n\r\n\r\n\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\left|\\frac{a_{n+1}}{a_n}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\right|\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} a_n\r\n&= \\lim_{n \\to \\infty} \\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "200274c8dc23ca64c6a6eff8672a276dd8761367", "size": 2406, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/h2.tex", "max_stars_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_stars_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "key/series/h2.tex", "max_issues_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_issues_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "key/series/h2.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 32.5135135135, "max_line_length": 173, "alphanum_fraction": 0.6271820449, "num_tokens": 934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8652240912652671, "lm_q1q2_score": 0.7247289645863263}}
{"text": "\\clearpage\n\\subsection{Pascal Expression} % (fold)\n\\label{sub:program-creation-pas_expression}\n\nAn \\nameref{sub:expression} in Pascal is a mathematical calculation or a literal value. Each expression will have a \\nameref{sub:type}, and can contain a number of mathematic operators. Table \\ref{tbl:program-creation-pas operators and expresions} lists the operators that you can include in your expressions, listed in order of precedence.\\footnote{Expressions follow the standard mathematic order of precedence (BODMAS).} The operators you can use depend on the kind of data that you are using within the expression.\n\n\\begin{table}[h]\n  \\begin{minipage}{\\textwidth}\n  \\centering\n  \\begin{tabular}{|c|l|l|}\n    \\hline\n    \\textbf{Operator} & \\textbf{Description} & \\textbf{Example} \\\\\n    \\hline\n    \\texttt{ ( ) }     &   Parenthesis                 & \\texttt{(1 + 1) * 2}  \\\\\n    \\texttt{mod * / div}\\footnote{\\texttt{div} performs an integer division, ignoring any remainder.}      &   Modulo\\footnote{The remainder after division. For example 9 modulo 3 is 0, 10 modulo 3 is 1, 11 modulo 3 is 2 etc.}, Multiplication and Division & \\texttt{1 / 2 * 5}  \\\\\n     & & \\texttt{1 div 2 * 5} \\\\\n    \\texttt{+ -}      &   Addition and subtraction    & \\texttt{10 + 3 - 4}   \\\\\n    \\hline\n  \\end{tabular}\n  \\end{minipage}\n  \\caption{Pascal Operators and Example Expressions}\n  \\label{tbl:program-creation-pas operators and expresions}\n\\end{table}\n\n\\begin{table}[h]\n  \\begin{minipage}{\\textwidth}\n  \\centering\n  \\begin{tabular}{|c|c|l|}\n    \\hline\n    \\textbf{Example Expression} & \\textbf{Value} & \\textbf{Type} \\\\\n    \\hline\n    \\texttt{ 73 }     &   73                 & \\texttt{Integer}  \\\\\n    \\texttt{ 2.1 }      & 2.1   & \\texttt{Single}    \\\\\n    \\texttt{ `Hello World' }      &   `Hello World'    & \\texttt{String}   \\\\\n    \\texttt{ `Hello ' + `World' }      &   `Hello World'    & \\texttt{String}   \\\\\n    \\texttt{ `Fred' }      &   `Fred'    & \\texttt{String}   \\\\\n    \\texttt{ 3 * 2 } & 6 & \\texttt{Integer} \\\\\n    \\texttt{ 1 + 3 * 2 }  & 7 & \\texttt{Integer} \\\\\n    \\texttt{ (1 + 3) * 2} & 8 & \\texttt{Integer} \\\\\n    \\texttt{ 7 - 3 + 1 }  & 5 & \\texttt{Integer} \\\\\n    \\texttt{ 3 / 2 } & 1.5 & \\texttt{Single} \\\\\n    \\texttt{ 3 div 2 } & 1 & \\texttt{Integer} \\\\\n    \\texttt{ 3 mod 2 } & 1 & \\texttt{Integer} \\\\\n    \\texttt{ 11 mod 3 } & 2 & \\texttt{Integer} \\\\\n    \\texttt{ 3.0 / 2.0} & 1.5 & \\texttt{Single} \\\\\n    \\texttt{ 3 / 2.0 } & 1.5 & \\texttt{Single} \\\\\n    \\texttt{ 1 + (3 / 2.0) + 6 * 2 - 8} & 6.5 & \\texttt{Single} \\\\\n    \\hline\n  \\end{tabular}\n\\end{minipage}\n  \\caption{Pascal Example Expressions}\n  \\label{tbl:program-creation-pas example expresions}\n\\end{table}\n\n\n\\mynote{\n\\begin{itemize}\n  \\item Table \\ref{tbl:program-creation-pas example expresions} shows some example expressions, their values, and types.\n  \\item Expressions can be literal values, entered in the code.\n  \\item Expression can contain mathematical calculations using standard addition, subtraction, multiplication, division, and grouping.\n\\end{itemize}\n}\n\n\n% subsection c_expression (end)", "meta": {"hexsha": "f822ff44e0bc982188a4d0720848fbbd4601a010", "size": 3077, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "topics/program-creation/pascal/pas-expression.tex", "max_stars_repo_name": "thoth-tech/programming-arcana", "max_stars_repo_head_hexsha": "bb5c0d45355bf710eff01947e67b666122901b07", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-10T04:50:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-10T04:50:54.000Z", "max_issues_repo_path": "topics/program-creation/pascal/pas-expression.tex", "max_issues_repo_name": "thoth-tech/programming-arcana", "max_issues_repo_head_hexsha": "bb5c0d45355bf710eff01947e67b666122901b07", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-12-29T19:45:10.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-29T19:45:10.000Z", "max_forks_repo_path": "topics/program-creation/pascal/pas-expression.tex", "max_forks_repo_name": "macite/programming-arcana", "max_forks_repo_head_hexsha": "8f3040983d420129f90bcc4bd69a96d8743c412c", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-06-02T03:18:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T07:42:53.000Z", "avg_line_length": 47.3384615385, "max_line_length": 518, "alphanum_fraction": 0.6317842054, "num_tokens": 1052, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7247289620085}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\begin{document}\n\n\\section{The Problem}\n\nThe problem originally appeared as the Puzzler on FiveThirtyEight web site on Friday, August 14, 2020.\\footnote{\\url{https://fivethirtyeight.com/features/are-you-hip-enough-to-be-square/}} Here is the problem:\n\n\\begin{quotation}\nThe Riddler Manufacturing Company makes all sorts of mathematical tools: compasses, protractors, slide rules — you name it!\n\nRecently, there was an issue with the production of foot-long rulers. It seems that each ruler was accidentally sliced at three random points along the ruler, resulting in four pieces. Looking on the bright side, that means there are now four times as many rulers — they just happen to have different lengths.\n\nOn average, how long are the pieces that contain the 6-inch mark?\n\\end{quotation}\n\nThere is not a unique answer to this problem. The answer depends on the process used to determine the location of the three slices. The following sections describes an algorithm for computing the location of the slices and computes the solution for that algorithm. There is a summary at the end\nwith the result for each algorithm, together with some additional results for other algorithms from Python simulations.\n\nWithin these sections we observe the following conventions:\n\\begin{enumerate}\n\\item The ruler is twelve inches long. So all lengths are in inches.\n\\item The three points where the slices occur designated by $x$, $y$, and $z$. Unless otherwise noted, we will have $0 < x < y < z < 12$. We note that there is zero probability of any of $<$ actually being equality, so the possibility is ignored. \n\\item All random choices are uniformly distributed. A sentence ``Randomly choose a point between $3$ and $12$'' implies a uniform distribution where the\nprobability of choosing a point between $3$ and $4$ inches is $1/9$.\n\\end{enumerate}\n\n\\section{Choose Three Independent Points}\n\nFor this algorithm we independently choose three random points between zero and $12$ inches and then sort them in order to obtain $x$, $y$, and $z$.\n\nWe divide this into four cases:\n\\begin{enumerate}\n\\item $0 < x < y < z < 6$\n\\item $0 < x < y < 6 < z < 12$\n\\item $0 < x < 6 < y < z < 12$\n\\item $6 < x < y < z < 12$\n\\end{enumerate}\n\nCases 1 and 4 occur with probability $1/8$ and cases 2 and 3 occur with probability $3/8$. If we reverse the numbers on the ruler case 1 is equivalent\nto case 4 and case 2 is equivalent to case 3.\n\nFor case 1 the desired length (length of the piece with the $6$ inch mark) is $12 - z$. $z$ is the maximum of three uniformly distributed random numbers\nin the same interval. We know \\footnote{For example,\n\\url{https://math.stackexchange.com/questions/460649/the-largest-of-n-random-numbers-over-a-uniform-distribution}} that the maximum is $\\frac{N}{N+1}$\ntimes the length of the interval. In this case that gives the expected value of $z = \\frac{3}{4} \\cdot 6  = 4.5$. So the expected length is $12 - 4.5 = 7.5$ inches.\n\nFor case 2 the desired length is $z - y$. The expected value of $z = 9$, the middle of the interval. The expected value of $y = \\frac{2}{3} \\cdot 6 = 4$. The\nexpected length is $9 - 4 = 5$ inches.\n\nCombining the cases, remembering that cases 1 and 4 and cases 2 and 3 are equivalent, gives the expected length as $ \\frac{1}{4} \\cdot 7.5 + \\frac {3}{4} \\cdot 5 = 5 + \\frac{5}{8} = 5.625$ inches.\n\n\\section{Choose $x$, then $y$, then $z$}\n\nFor this algorithm, we choose $x$ between $0$ and $12$, then $y$ between $x$ and $12$, and finally, $z$ between $y$ and $12$.\n\nWe note for this case that if $x \\ge 6$, the choices for $y$ and $z$ are irrelevant and the length is $x$. If $x < 6$, we then have to look at $y$, and potentially\n$z$ to compute the desired length. We will define $E$ to be the desired length, $EX(x)$ to be the expected length for  a given value of $x$ assuming $0 < x < 6$, and $EY(y)$ to be the expected length for a given value of $y$ assuming $0 < x < y < 6$.\n\nWe have\n$$ E =  \\frac{1}{12} \\left({\\int_{0}^{6} EX(x) dx} + {\\int_{6}^{12} x \\,dx}\\right)$$\n\nSimilarly, we have\n\\begin{eqnarray*}\nEX(x) &=& \\frac{1}{12-x} \\left({\\int_{x}^{6} EY(y) dy} + {\\int_{6}^{12} y-x \\,dy}\\right)\\\\\nEY(y) &=&  \\frac{1}{12-y} \\left({\\int_{y}^{6} 12-z \\,dz} + {\\int_{6}^{12} z-y \\,dz}\\right)\n\\end{eqnarray*} \n\nWorking backwards (with help from Wolfram Alpha!\\footnote{\\url{https://www.wolframalpha.com/input/}}):\n\\begin{eqnarray*}\nEY(y) &=& \\frac{1}{12-y} \\left( \\frac{1}{2} y^2 -12 y + 54 + 6(9-y) \\right)\\\\\n&=& \\frac{\\frac{1}{2}y^2 -18y +108}{12-y}\n\\end{eqnarray*}\n\\begin{eqnarray*}\nEX(x) &=& \\frac{1}{12-x} \\left({\\int_{x}^{6} \\frac{\\frac{1}{2}y^2 -18y +108}{12-y} \\,dy} + {\\int_{6}^{12} y-x \\,dy}\\right)\n\\end{eqnarray*}\n\\begin{eqnarray*}\n\\int_{x}^{6} \\frac{\\frac{1}{2}y^2 -18y +108}{12-y} \\,dy &=& \\frac{1}{2} \\left(\\frac{1}{2}x^2 + 12x + 144\\,log\\left(\\frac{12-x}{6}\\right)-90\\right)\\\\\n&&-18\\left(x + 12\\,log\\left(\\frac{12-x}{6}\\right) -6\\right)\\\\\n&&+108 \\, log\\left(\\frac{12-x}{6}\\right)\\\\\n&=&\\frac{1}{4}x^2 -12x -36log\\left(\\frac{12-x}{6}\\right) + 63\\\\\n{\\int_{6}^{12} y-x \\,dy}&=&-6x +54\\\\\nEX(x)&=&\\frac{\\frac{1}{4}x^2 -18x -36log\\left(\\frac{12-x}{6}\\right) + 117}{12-x}\\\\\n\\end{eqnarray*}\n\\begin{eqnarray*}\nE &=&  \\frac{1}{12} \\left({\\int_{0}^{6} \\frac{\\frac{1}{4}x^2 -18x -36log\\left(\\frac{12-x}{6}\\right) + 117}{12-x} dx} + {\\int_{6}^{12} x \\,dx}\\right)\n\\end{eqnarray*}\n\\begin{eqnarray*}\n\\int_{0}^{6} \\frac{\\frac{1}{4}x^2 -18x -36log\\left(\\frac{12-x}{6}\\right) + 117}{12-x} dx &=&\\frac{1}{4}\\left(144log(2) - 90\\right)\\\\\n&&-18\\left(12log(2) - 6\\right)\\\\\n&&-36\\left(\\frac{1}{2}log^2(2)\\right)\\\\\n&&117\\,log(2)\\\\\n&=&-63\\, log(2) - 18 \\,log^2(2) +85.5\\\\\n\\int_{6}^{12} x \\,dx &=& 54                                                            \n\\end{eqnarray*}\n\\begin{eqnarray*}\nE &=& \\frac{1}{12}\\left(-63\\, log(2) - 18 \\,log^2(2) +139.5\\right)\\\\\n&=& -5.25\\,log(2) - 1.5\\,log^2(2)+11.625 \\approx 7.265298\n\\end{eqnarray*}\n\n\\section{Choose $y$, then $x$ and $z$}\n\nThis algorithm is similar to the last one except we first choose $y$ between $0$ and $12$ and then choose $x$ between $0$ and $y$ and $z$\nbetween $y$ and $12$.\n\nWe note in this case that for $y > 6$ we only have to choose $x$ and for $y < 6$ we only have to choose $z$. Further, we can see that these two\ncases are symmetric: reversing the ruler transforms one into the other. So, we assume $y > 6$ and ignore the choice of $z$. Similar to the previous\nwe define $E$ to be the desired length and $EY(y)$ to be the expected length for a given value of y assuming $6 < y < 12$.\n\nWe have\n\\begin{eqnarray*}\nE &=& \\frac{1}{6} \\int_{6}^{12} EY(y) dy\\\\\nEY(y) &=& \\frac{1}{y} \\left( \\int_{0}^{6} y-x \\,dx + \\int_{6}^{y} x \\, dx \\right)\\\\\n&=& \\frac{1}{y} \\left( 6y - 18 + \\frac{1}{2} y^2 - 18 \\right)\\\\\n&=& \\frac{1}{2}y + 6 - \\frac{36}{y}\\\\\nE &=& \\frac{1}{6} \\int_{6}^{12}  \\frac{1}{2}y + 6 - \\frac{36}{y} dy\\\\\n&=& \\frac{1}{6} \\left( \\frac{12^2}{4} + 6 \\cdot 12 - 36\\,log(12) - \\frac{6^2}{4} - 6 \\cdot 6 + 36\\,log(6)\\right)\\\\\n&=& \\frac{1}{6} \\left( 63 - 36 \\, log(2) \\right)\\\\\n&=& 10.5 - 6 log(2) \\approx 6.341117\n\\end{eqnarray*}\n\n\\section{Summary}\n\nThe table below summarizes the results for different algorithms. In addition to the analytical results from the preceding sections, the table includes\nexpected lengths from Python simulations of some additional algorithms. These results are marked with an asterisk (*). Due to time constraints,\nI was unable to derive analytical results for these values. The Python program that generated these numbers can be \nfound at \\url{https://github.com/chrisreedy/fun/blob/master/SlicedRuler/ruler.py}.\n\n\\,\n\n\\begin{tabular}{l l}\n\\textbf{Algorithm} & \\textbf{Expected Length} \\\\\n\\hline Choose Three Independent Points & $5.625$ \\\\\nChoose $x$, then $y$, then $z$ & $\\approx 7.265298$\\\\\nChoose $y$, then $x$ and $z$ & $\\approx 6.341117$\\\\\nChoose $x$, then $z$, then $y$ & $7.08^*$ \\\\\nChoose Longest for next Slice & $4.47^*$ \\\\\nChoose Slice containing 6\" for next Slice & $4.35^*$\n\\end {tabular}\n\n\\end{document}", "meta": {"hexsha": "34a80bd6578196bd4c9e81d66a747c37249213f6", "size": 8010, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SlicedRuler/slicedruler.tex", "max_stars_repo_name": "chrisreedy/fun", "max_stars_repo_head_hexsha": "81dfcb6ef45f46bdd5b5146ee997655270b9694a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SlicedRuler/slicedruler.tex", "max_issues_repo_name": "chrisreedy/fun", "max_issues_repo_head_hexsha": "81dfcb6ef45f46bdd5b5146ee997655270b9694a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SlicedRuler/slicedruler.tex", "max_forks_repo_name": "chrisreedy/fun", "max_forks_repo_head_hexsha": "81dfcb6ef45f46bdd5b5146ee997655270b9694a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.4084507042, "max_line_length": 309, "alphanum_fraction": 0.6619225968, "num_tokens": 2808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059560743422, "lm_q2_score": 0.9136765245890102, "lm_q1q2_score": 0.7246422935768492}}
{"text": "\\paragraph{Nim}\nFor simplicity, we denote $a_i$ as the number of stones in the $i$-th pile, $M_i(S)$ as removing stones with the amount chosen in the set $S$ from the $i$-th pile, and $M_i=M_i[1,a_i]$. Without further explanation, it is assumed that the SG function of a game $SG=\\bigoplus_{i=1}^nSG(a_i)$.\n\n\\subparagraph{Nim}\n$M=\\bigcup_{i=1}^nM_i$.\n\nNormal: $SG(n)=n$.\n\nMisere: The same, opposite if all piles are $1$'s.\n\n\\subparagraph{Nim (powers)}\nGiven $k$, $M=\\bigcup_{i=1}^nM_i\\{k^m|m\\ge 0\\}$.\n\nNormal: If $k$ is odd, $SG(n)=n\\%2$. Otherwise,\n\n$$SG(n)=\\biggl\\{\\begin{array}{lr}\n2 & n\\%(k+1)=k \\\\\nn\\%(k+1)\\%2 & \\mathrm{otherwise}\\,.\\end{array}$$\n\n\\subparagraph{Nim (no greater than half)}\n$M=\\bigcup_{i=1}^nM_i[1,\\frac{a_i}{2}]$.\n\nNormal: $SG(2n)=n,SG(2n+1)=SG(n)$.\n\n\\subparagraph{Nim (always greater than half)}\n$M=\\bigcup_{i=1}^nM_i[\\left\\lceil \\frac{a_i}{2}\\right\\rceil, a_i]$.\n\nNormal: $SG(0)=0,SG(n)=\\left\\lfloor \\log_2 n\\right\\rfloor +1$.\n\n\\subparagraph{Nim (proper divisors)}\n$M=\\bigcup_{i=1}^nM_i\\{x|x>1\\wedge a_i\\% x=0\\}$.\n\nNormal: $SG(1)=0,SG(n)=\\max_x(n\\%2^x=0)$.\n\n\\subparagraph{Nim (divisors)}\n$M=\\bigcup_{i=1}^nM_i\\{x|a_i\\% x=0\\}$.\n\nNormal: $SG(0)=0,SG(n)=1+\\max_x(n\\%2^x=0)$.\n\n\\subparagraph{Nim (fixed)}\nGiven a finite set $S$, $M=\\bigcup_{i=1}^nM_i(S)$.\n\nNormal: $SG_1(n)$ is eventually periodic.\n\nGiven a finite set $S$, $M=\\bigcup_{i=1}^nM_i(S\\cup {a_i})$.\n\nNormal: $SG_2(n)=SG_1(n)+1$.\n\n\\subparagraph{Moore's Nim}\nGiven $k$, $M=\\bigcup\\{M_{x_1}\\times M_{x_2} \\dots\\times M_{x_l}|l\\le k \\wedge\\forall i(x_i<x_{i+1})\\}$.\n\nNormal: Sum all $(a_i)_2$ in base $k+1$ without carry. Lose if the result is $0$.\n\nMisere: The same, except if all piles are $1$'s.\n\n\\subparagraph{Staircase Nim}\nOne can take any number of objects from $a_{i+1}$ to $a_i$($i\\ge 0$).\n\nNormal: Lose if $\\bigoplus_{i=0}^{(n-1)/2}a_{2i+1}=0$.\n\n\\subparagraph{Lasker's Nim}\n$M=\\bigcup_{i=1}^nM_i\\cup S_i$. ($S_i$: Split a pile into two non-empty piles.)\n\nNormal: $SG(n)=\\biggl\\{\\begin{array}{lr}\nn & n\\%4=1,2\\\\\nn+1 & n\\%4=3\\\\\nn-1 & n\\%4=0\\,.\\end{array}$\n\n\\subparagraph{Kayles}\n$M=\\bigcup_{i=1}^nM_i[1,2]\\cup MS_i[1,2]$. ($MS_i$: Split a pile into two non-empty piles after removing stones.)\n\nNormal: Periodic from the $72$-th item with period length $12$.\n\n\\subparagraph{Dawson's chess}\n$n$ stones in a line. One can take a stone if its neighbours are not taken.\n\nNormal: Periodic from the $52$-th item with period length $34$.\n\n\\paragraph{Ferguson game}\nTwo boxes with $m$ stones and $n$ stones. One can empty any one box and move any positive number of stones from another box to this box each step.\n\nNormal: Lose if both $m$ and $n$ are odd.\n\n\\paragraph{Fibonacci game}\n$n$ stones. The first player may take any positive number of stones during the first move, but not all of them. After that, each player may take any positive number of stones, but less than twice the number of stones taken during the last turn.\n\nNormal: Win if $n$ is not a fibonacci number.\n\n\\paragraph{Wythoff's game}\nTwo piles of stones. Players take turns removing stones from one or both piles; when removing stones from both piles, the numbers of stones removed from each pile must be equal.\n\nNormal: Lose if $\\lfloor \\frac{\\sqrt{5}+1}{2}|A-B| \\rfloor=\\min(A,B)$\n\n\\paragraph{Mock turtles}\n$n$ coins in a line. One can turn over any $1$, $2$, or $3$ coins, but the rightmost coin turned must be from head to tail.\n\nNormal: $SG(n)=2n+[\\operatorname{popcount}(n)\\mathrm{\\ is\\ even}]$.\n\n\\paragraph{Ruler}\n$n$ coins in a line. One can turn over any consecutive coins, but the rightmost coin turned must be from head to tail.\n\nNormal: $SG(n)=\\operatorname{lowbit}(n)$.\n\n\\paragraph{Hackenbush}\nThe game starts with the players drawing a ground line (conventionally, but not necessarily, a horizontal line at the bottom of the paper or other playing area) and several line segments such that each line segment is connected to the ground, either directly at an endpoint, or indirectly, via a chain of other segments connected by endpoints. Any number of segments may meet at a point and thus there may be multiple paths to ground.\n\nOn his turn, a player cuts (erases) any line segment of his choice. Every line segment no longer connected to the ground by any path falls (i.e., gets erased). According to the normal play convention of combinatorial game theory, the first player who is unable to move loses.\n\nPlayed exclusively with vertical stacks of line segments, also referred to as bamboo stalks, the game directly becomes Nim and can be directly analyzed as such. Divergent segments, or trees, add an additional wrinkle to the game and require use of the colon principle stating that when branches come together at a vertex, one may replace the branches by a non-branching stalk of length equal to their nim sum. This principle changes the representation of the game to the more basic version of the bamboo stalks. The last possible set of graphs that can be made are convergent ones, also known as arbitrarily rooted graphs. By using the fusion principle, we can state that all vertices on any cycle may be fused together without changing the value of the graph. Therefore, any convergent graph can also be interpreted as a simple bamboo stalk graph. By combining all three types of graphs we can add complexity to the game, without ever changing the Nim sum of the game, thereby allowing the game to take the strategies of Nim.\n\n\\paragraph{Joseph cycle}\n$n$ players are numbered with $0,1,2,...,n-1$. $f_{1,m}=0,f_{n,m}=(f_{n-1,m}+m)\\mod n$.\n", "meta": {"hexsha": "2efc7183124ad61d0cce6d8dd16de988df3e81f2", "size": 5507, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/mathematics/game-theory/game-theory.tex", "max_stars_repo_name": "Nisiyama-Suzune/LMR", "max_stars_repo_head_hexsha": "16325b9efcb71240111ac12ea55c0cb45b0c5834", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 48, "max_stars_repo_stars_event_min_datetime": "2018-08-15T11:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T23:38:29.000Z", "max_issues_repo_path": "src/mathematics/game-theory/game-theory.tex", "max_issues_repo_name": "Nisiyama-Suzune/LMR", "max_issues_repo_head_hexsha": "16325b9efcb71240111ac12ea55c0cb45b0c5834", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mathematics/game-theory/game-theory.tex", "max_forks_repo_name": "Nisiyama-Suzune/LMR", "max_forks_repo_head_hexsha": "16325b9efcb71240111ac12ea55c0cb45b0c5834", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2019-07-18T10:27:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-08T13:03:47.000Z", "avg_line_length": 48.7345132743, "max_line_length": 1026, "alphanum_fraction": 0.7169057563, "num_tokens": 1749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7246422837085499}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage[english]{babel}\n\\usepackage[utf8x]{inputenc}\n\\usepackage{amsmath}\n\\newcommand\\numberthis{\\addtocounter{equation}{1}\\tag{\\theequation}}\n\n\\usepackage{graphicx}\n\\usepackage{fullpage}\n\\title{MATH 542 Final Exam}\n\\author{Saket Choudhary\\\\skchoudh@usc.edu}\n\n\\begin{document}\n\\maketitle\n\n\\section*{Problem 1}\n\\subsection*{Problem 1a}\n\n\\begin{align*}\nY_i &= \\beta_0 + \\beta_1 x_{i1} + \\beta_2 x_{i2} + \\dots + \\beta_{p-1}x_{i,p-1} + \\epsilon_i\\\\\nY_i &= \\alpha + \\beta_1(x_{i1}-\\bar{x}_1) + \\beta_2(x_{i2} - \\bar{x}_2) + \\dots + \\beta_{p-1}(x_{i,p-1}-\\bar{x}_{p-1})\\\\\n&= \\alpha - \\beta_1 \\bar{x}_1 -\\beta_2 \\bar{x}_2 - \\dots - \\beta_{p-1}\\bar{x}_{p-1} + \\beta_1 x_{i1} + \\beta_2 x_{i2} + \\dots + \\beta_{p-1}x_{i,p-1} + \\epsilon_i\\\\\n\\implies \\beta_0 &= \\alpha - \\beta_1 \\bar{x}_1 -\\beta_2 \\bar{x}_2 - \\dots - \\beta_{p-1}\\bar{x}_{p-1}\\\\\n\\implies \\alpha &= \\beta_0 + \\beta_1 \\bar{x}_1 -\\beta_2 \\bar{x}_2 - \\dots - \\beta_{p-1}\\bar{x}_{p-1}\n\\end{align*}\n\n\\subsection*{Problem 1.2}\n\\begin{align*}\n\\bar{x_j} &= \\sum_{i=1}^n \\frac{x_{ij}}{n}\\\\\n&= \\frac{1}{n}\\mathbf{1_n}'\\mathbf{X_i}\\\\\nY &= \\begin{pmatrix}\n1 & x_{11}-\\bar{x}_1 & x_{12}-\\bar{x}_2 & \\dots & x_{1,p-1}-\\bar{x}_{p-1}\\\\\n1 & x_{21}-\\bar{x}_2 & x_{22}-\\bar{x}_2 & \\dots & x_{2, p-1}-\\bar{x}_{p-1}\\\\\n\\vdots & \\\\\n1 & x_{n1}-\\bar{x}_1 & x_{n2}-\\bar{x}_2 & \\dots & x_{n,p-1}-\\bar{x}_{p-1}\n\\end{pmatrix}\\begin{pmatrix}\n\\alpha\\\\\n\\beta_1\\\\\n\\vdots\\\\\n\\beta_{p-1}\n\\end{pmatrix} + \\mathbf{\\epsilon}\\\\\n&=\\big(\\begin{pmatrix}\n1 & x_{11} & x_{12} & \\dots & x_{1,p-1}\\\\\n1 & x_{21} & x_{22} & \\dots & x_{2, p-1}\\\\\n\\vdots & \\\\\n1 & x_{n1} & x_{n2} & \\dots & x_{n,p-1}\n\\end{pmatrix}- \\begin{pmatrix}\n0 & \\bar{x}_1 & \\bar{x}_2 & \\dots & \\bar{x}_{p-1}\\\\\n0 & \\bar{x}_1 & \\bar{x}_2 & \\dots & \\bar{x}_{p-1}\\\\\n\\vdots & \\\\\n0 & \\bar{x}_1 & \\bar{x}_2 & \\dots & \\bar{x}_{p-1}\\\\\n\\end{pmatrix} \\big)\\begin{pmatrix}\n\\alpha\\\\\n\\beta_1\\\\\n\\vdots\\\\\n\\beta_{p-1}\n\\end{pmatrix} + \\mathbf{\\epsilon}\\\\\n&= \\big(\\begin{pmatrix}\n\\mathbf{1_n} & \\mathbf{X}\n\\end{pmatrix} - \\begin{pmatrix}\n\\mathbf{0_n} & \\frac{1}{n}\\mathbf{1_n1_n'X}\n\\end{pmatrix}\\big)\\begin{pmatrix}\n\\alpha\\\\\n\\beta_1\\\\\n\\vdots\\\\\n\\beta_{p-1}\n\\end{pmatrix} + \\mathbf{\\epsilon}\\\\\n&= \\begin{pmatrix}\n\\mathbf{1_n} & \\mathbf{X}-\\frac{1}{n}\\mathbf{1_n1_n'X}\n\\end{pmatrix}\\begin{pmatrix}\n\\alpha\\\\\n\\beta_1\\\\\n\\vdots\\\\\n\\beta_{p-1}\n\\end{pmatrix}+ \\mathbf{\\epsilon}\\\\\n&= \\begin{pmatrix}\n\\mathbf{1_n} & \\mathbf{X_c}\n\\end{pmatrix}\\begin{pmatrix}\n\\alpha\\\\\n\\beta_1\\\\\n\\vdots\\\\\n\\beta_{p-1}\n\\end{pmatrix}+ \\mathbf{\\epsilon}\\\\\n\\implies \\mathbf{X_c} &= (\\mathbf{I}-\\frac{\\mathbf{1_n1_n'}}{n})X\n\\end{align*}\n\n\\subsection*{Problem 1.3}\n\n\\begin{align*}\n\\mathbf{1_n'X_c} &= \\begin{pmatrix}\n1 & 1 & 1 & \\dots & 1\n\\end{pmatrix} \\begin{pmatrix}\n\\mathbf{I}-\\frac{1}{n}\\mathbf{1_n1_n'}\n\\end{pmatrix}\\mathbf{X}\\\\\n&= \\begin{pmatrix}\n1 & 1 & 1 & \\dots & 1\n\\end{pmatrix} \\begin{pmatrix}\n1-\\frac{1}{n} & \\frac{-1}{n} & \\frac{-1}{n} & \\dots & \\frac{-1}{n}\\\\\n\\frac{-1}{n} &1-\\frac{1}{n} & -\\frac{1}{n} & \\dots & -\\frac{1}{n}\\\\\n\\vdots\\\\\n\\frac{-1}{n} &-\\frac{1}{n} & -\\frac{1}{n} & \\dots & 1-\\frac{1}{n}\\\\\n\\end{pmatrix}\\\\\n&= (1-\\frac{1}{n}) -\\frac{1}{n}*(n-1)\\\\\n&= 0\n\\end{align*}\n\n\\subsection*{Problem 1.4.a}\n\n\\begin{align*}\nY_1 &= \\alpha + \\beta_1(x_{11}-\\bar{x}_1) + \\beta_2(x_{12} - \\bar{x}_2) + \\dots + \\beta_{p-1}(x_{1,p-1}-\\bar{x}_{p-1})\\\\\nY_2 &= \\alpha + \\beta_1(x_{21}-\\bar{x}_1) + \\beta_2(x_{22} - \\bar{x}_2) + \\dots + \\beta_{p-1}(x_{2,p-1}-\\bar{x}_{p-1})\\\\\n\\vdots \\\\\nY_n &= \\alpha + \\beta_1(x_{n1}-\\bar{x}_1) + \\beta_2(x_{n2} - \\bar{x}_2) + \\dots + \\beta_{p-1}(x_{n,p-1}-\\bar{x}_{p-1})\\\\\n\\hline\\\\\n\\sum_{i=1}Y_i &= n\\alpha + \\beta_1(\\sum_{i=1}x_{i1}-n\\bar{x}_1) + \\beta_2(\\sum_{i=1}x_{i2}-n\\bar{x}_2) + \\dots + \\beta_{p-1}(\\sum_{i=1}x_{i,p-1}-n\\bar{x}_{p-1})\\\\\n\\sum_{i=1}x_{i,j}-n\\bar{x}_j &= 0\\\\\n\\implies \\hat{\\alpha} &= \\frac{\\sum_{i=1}Y_i}{n}\n\\end{align*}\nNow, we perform $Y_i-\\bar{Y}$ eliminating $\\alpha$ Let $Z=Y_i-\\bar{Y}$m the problem then reduces to the following form: $Z = \\mathbf{X_c}\\beta + \\epsilon$ where $\\beta = \\begin{pmatrix}\n\\beta_1 & \\beta_2 & \\dots & \\beta_{p-1}\n\\end{pmatrix}$ and hence simply re-using OLS results, $\\hat{\\beta} =\\mathbf{X_c'X_c}^{-1}\\mathbf{X_c'}Y$\n\nMore rigorously:\n\n\\begin{align*}\n\\hat{\\beta} &= (X'X)^{-1}X'Y\\\\\nX'X\\hat{\\beta} &= X'Y\\\\ \n\\mathbf{X'X} &= \\begin{pmatrix}\n\\mathbf{1_n}'\\\\\n\\mathbf{X_c}'\n\\end{pmatrix} \\begin{pmatrix}\n\\mathbf{1_n} & \\mathbf{X_c}\n\\end{pmatrix}\\\\\n&= \\begin{pmatrix}\n\\mathbf{1_n}' \\mathbf{1_n} & \\mathbf{1_n'X_c}\\\\\n\\mathbf{X_c'1_n} & \\mathbf{X_c'X_c}\n\\end{pmatrix}\\\\\n\\begin{pmatrix}\n\\mathbf{1_n}' \\mathbf{1_n} & \\mathbf{1_n'X_c}\\\\\n\\mathbf{X_c'1_n} & \\mathbf{X_c'X_c}\n\\end{pmatrix} \\begin{pmatrix}\n\\alpha\\\\\n\\beta_1\n\\end{pmatrix} &= \\begin{pmatrix}\n\\mathbf{1_n'}\\\\\n\\mathbf{X_c'}\n\\end{pmatrix}\\mathbf{Y}\\\\\n\\implies n\\hat{\\alpha} + \\mathbf{1_n'X_c}\\beta_1 &= \\sum_{i=1}Y_i = n\\bar{Y} \\text{using first row}\\\\\n\\hat{\\alpha} + 0 &= \\bar{Y} \\text{ since }\\mathbf{X_c'1_n1} =0 \\\\\n\\implies \\hat{\\alpha} &= \\bar{Y}\\\\\n\\mathbf{X_c'1_n1_n'} + \\mathbf{X_c'X_c}\\hat{\\beta_1} &= \\mathbf{X_c'Y} \\text{using second row}\\\\\n\\implies \\mathbf{X_c'X_c}\\hat{\\beta_1} &= \\mathbf{X_c'Y} \\text{ since }\\mathbf{X_c'1_n1} =0\\\\\n\\implies \\hat{\\beta_1} &= \\mathbf{(X_c'X_c)^{-1}X_c'Y}\n\\end{align*}\n\n\n\\subsection*{Problem 1.4.b}\nInverse of a block matrix\n\\begin{align*}\n\\begin{pmatrix}\nA_{11} & A_{12}\\\\\nA_{21} & A_{22}\n\\end{pmatrix}^{-1} &= \\begin{pmatrix}\n(A_{11}-A_{12}A_{22}^{-1}A_{21})^{-1} & -(A_{11}-A_{12}A_{22}^{-1}A_{21})^{-1}A_{12}A_{22}^{-1}\\\\\n-(A_{22}-A_{21}A_{11}^{-1}A_{12})^{-1} & (A_{22}-A_{21}A_{11}^{-1}A_{12})\n\\end{pmatrix}\n\\end{align*}\n\n\\begin{align*}\n\\mathbf{X'X} &= \\begin{pmatrix}\n\\mathbf{1_n}'\\\\\n\\mathbf{X_c}'\n\\end{pmatrix} \\begin{pmatrix}\n\\mathbf{1_n} & \\mathbf{X_c}\n\\end{pmatrix}\\\\\n&= \\begin{pmatrix}\n\\mathbf{1_n}' \\mathbf{1_n} & \\mathbf{1_n'X_c}\\\\\n\\mathbf{X_c'1_n} & \\mathbf{X_c'X_c}\n\\end{pmatrix}\\\\\n&= \\begin{pmatrix}\n\\mathbf{1_n}' \\mathbf{1_n} & 0\\\\\n0 & \\mathbf{X_c'X_c}\n\\end{pmatrix}\\\\\n\\mathbf{X'X}^{-1} &= \\begin{pmatrix}\n\\mathbf{1_n}' \\mathbf{1_n} & \\mathbf{1_n'X_c}\\\\\n\\mathbf{X_c'1_n} & \\mathbf{X_c'X_c}\n\\end{pmatrix}^{-1}\\\\\n&= \\begin{pmatrix}\nn & 0\\\\\n0 & (\\mathbf{X_c'X_c})^{-1}\n\\end{pmatrix}\\\\\n(X'X)^{-1}X'Y &= \\begin{pmatrix}\n\\frac{1}{n} & 0\\\\\n0 & (\\mathbf{X_c'X_c})^{-1}\n\\end{pmatrix}_{(p+1) \\times (p+1)}\\begin{pmatrix}\n\\mathbf{1_n}'\\\\\n\\mathbf{X_c}'\n\\end{pmatrix}_{(p+1) \\times n}\\mathbf{Y}_{n \\times 1}\\\\\n&= \\begin{pmatrix}\n\\frac{1}{n} & 0\\\\\n0 & (\\mathbf{X_c'X_c})^{-1}\n\\end{pmatrix}\\begin{pmatrix}\n\\mathbf{1_n}'Y\\\\\n\\mathbf{X_c}'Y\n\\end{pmatrix}\\\\\n&= \\begin{pmatrix}\n\\frac{1}{n}\\mathbf{1_n}'Y_{1 \\times 1}\\\\\n\\mathbf{(X_c'X_c)^{-1}X_c}'Y_{p-1 \\times 1}\n\\end{pmatrix}\\\\\n&= \\begin{pmatrix}\n\\bar{Y}\\\\\n\\mathbf{(X_c'X_c)^{-1}X_c}'Y\n\\end{pmatrix}_{p \\times 1}\\\\\n\\begin{pmatrix}\n\\alpha\\\\\n\\beta_1\\\\\n\\beta_2\\\\\n\\vdots\\\\\n\\beta_{p-1}\\end{pmatrix} &= \\begin{pmatrix}\n\\bar{y}\\\\\n\\mathbf{(X_c'X_c)^{-1}X_c}'Y_{p-1\\times 1}\n\\end{pmatrix}\n\\end{align*}\n\n\n\\subsection*{Problem 1.5}\n\nYes, column space of $X$ is identical to $\\begin{pmatrix}\n\\mathbf{1_n} & \\mathbf{X_c}\n\\end{pmatrix}$ since $X_c = (I-\\frac{J}{n})X$\n\n\\subsection*{Problem 1.6}\n\\begin{align*}\n\\mathbf{P} &= \\mathbf{X(X'X)^{-1}X'Y}\\\\\n&= \\begin{pmatrix}\n\\mathbf{1_n} & X_c\n\\end{pmatrix} \\begin{pmatrix}\n\\frac{1}{n} & 0\\\\\n0 & (\\mathbf{X_c'X_c})^{-1}\n\\end{pmatrix}\\begin{pmatrix}\n\\mathbf{1_n'}\\\\\n\\mathbf{X_c'}\n\\end{pmatrix}\\\\\n\\implies \\mathbf{P} &= \\mathbf{X_c(X_c'X_c)^{-1}X_c'} + \\frac{\\mathbf{1_n1_n'}}{n}\\\\\n\\end{align*}\n\n\\begin{align*}\nSSE &= \\mathbf{\\epsilon'\\epsilon}\\\\\n&=(Y-X\\hat{\\beta})'(Y-X\\hat{\\beta})\\\\\n&= Y'Y-\\hat{\\beta}'X'Y-Y'X\\hat{\\beta}+\\hat{\\beta}'X'X\\hat{\\beta}\\\\\n&= Y'Y-2Y'X\\hat{\\beta} + \\hat{\\beta}'X'X\\{(X'X)^{-1}X'Y\\}\\\\\n&= Y'Y-2Y'X\\hat{\\beta} + \\hat{\\beta}'IX'Y\\\\\n&= Y'Y-2Y'X\\hat{\\beta} + \\hat{\\beta}'X'Y\\\\\n&= Y'Y-2Y'X\\hat{\\beta} + Y'X\\hat{\\beta}'\\\\\n&= Y'Y-Y'X\\hat{\\beta}\\\\\n&= Y'Y-Y'\\begin{pmatrix}\n1_n & X_c\n\\end{pmatrix}\\begin{pmatrix}\n\\bar{y}\\\\\n\\mathbf{(X_c'X_c)^{-1}X_c}'Y_{p-1\\times 1}\n\\end{pmatrix}\\\\\n&=Y'Y-Y'\\begin{pmatrix}\n1_n & X_c\n\\end{pmatrix}\\begin{pmatrix}\n\\frac{1}{n}1_n'\\mathbf{Y}\\\\\n\\mathbf{(X_c'X_c)^{-1}X_c}'Y_{p-1\\times 1}\n\\end{pmatrix}\\\\ \n&= Y'(I-\\frac{1_n1_n'}{n})Y - \\mathbf{Y'X_c}\\mathbf{(X_c'X_c)^{-1}X_c}'\\mathbf{Y}\\\\\n&=\\sum_{i=1}^n(Y_i-\\bar{Y})^2 -\\mathbf{Y'X_c}\\mathbf{(X_c'X_c)^{-1}X_c}'\\mathbf{Y}\\\\\n&=\\sum_{i=1}^n(Y_i-\\bar{Y})^2 -\\mathbf{Y'P_c}\\mathbf{Y}\\\\\n\\end{align*}\n\n\\subsection*{Problem 1.7}\n\n\\begin{align*}\nY_i^* &= Y_i-\\bar{Y}\\\\\n\\mathbf{Y}^* &= \\mathbf{Y}-\\frac{1}{n}\\mathbf{1_n1_n'Y}\\\\\n\\sum_{i=1}^n(Y_i-\\bar{Y})^2 &= \\mathbf{Y'}^{*}\\mathbf{Y}^*\\\\\n\\implies SSE &= \\mathbf{Y'}^{*}\\mathbf{Y}^*-\\mathbf{Y'^*P_c}\\mathbf{Y^*}\n\\end{align*}\n\n\\end{document}", "meta": {"hexsha": "c1ce2ccb6e4eccefd2e27de0a291dbcd81848612", "size": 8595, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016_Spring/MATH-542/Final/problem1.tex", "max_stars_repo_name": "NeveIsa/hatex", "max_stars_repo_head_hexsha": "c5cfa2410d47c7e43a476a8c8a9795182fe8f836", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2015-09-10T02:45:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T03:20:47.000Z", "max_issues_repo_path": "2016_Spring/MATH-542/Final/problem1.tex", "max_issues_repo_name": "NeveIsa/hatex", "max_issues_repo_head_hexsha": "c5cfa2410d47c7e43a476a8c8a9795182fe8f836", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-09-16T23:11:00.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-23T21:21:52.000Z", "max_forks_repo_path": "2016_Spring/MATH-542/Final/problem1.tex", "max_forks_repo_name": "saketkc/hatex", "max_forks_repo_head_hexsha": "c5cfa2410d47c7e43a476a8c8a9795182fe8f836", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-09-25T19:06:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T03:21:09.000Z", "avg_line_length": 30.4787234043, "max_line_length": 185, "alphanum_fraction": 0.5926701571, "num_tokens": 4248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.8289388104343893, "lm_q1q2_score": 0.7245565435453454}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Probability}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nVarious exercises relating to probability.\n\\end{abstract}\n\\maketitle\n\n\\begin{exercise}\n\\begin{itemize}\n\\item If it exists, find the value of the constant $c$ below which makes the function a PDF on the interval $[e,e^2]$. If no such constant exists, enter N/A.\n\\[ f(x) = c \\ln x \\]\n\\[ c = \\answer{e^{-2}}. \\]\n\\begin{hint}\nYou'll need to integrate by parts.\n\\end{hint}\n\\item For the same function as above, find the value of the constant $c$ which makes it a PDF on the interval $[e^{-2},e^2]$. If no such constant exists, enter N/A.\n\\[ c = \\answer{N/A}. \\]\n\\begin{hint}\nThe function $\\ln x$ is negative on $[e^{-2},1)$ and positive on $(1,e^2]$. What does that imply for the possibility of it being a PDF?\n\\end{hint}\n\\end{itemize}\n\\end{exercise}\n\n\n\\begin{exercise}\nSuppose $X$ is a random variable which represents the length of time your customers remain on hold before reaching a customer service agent. A reasonable model for such a random variable is to use an exponential distribution, i.e., to have a PDF given by\n\\[ f(x) = c e^{-cx} \\]\nfor some positive constant $c$.  If the mean hold time is $2$ minutes, what is the standard deviation?\n\\[ \\sigma = \\answer{2}. \\]\nWhat is the probability that a customer will have to wait more than one standard deviation beyond the mean before their call is answered?\n\\[ P = \\answer{e^{-2}} \\approx 13.5\\%. \\]\n\\begin{hint}\nFirst you need to solve for $c$.\n\\begin{hint}\nThe equation will be \\[ 2 = \\int c x e^{-cx} dx. \\]\n\\begin{hint}\nThis gives $c = 1/2$.\n\\begin{hint}\nThe easiest formula to use here is\n\\[ \\sigma^2 = \\int_0^\\infty x^2 f(x) dx - \\mu^2, \\]\nwhere $\\mu$ is the mean.\n\\end{hint}\n\\end{hint}\n\\end{hint}\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nSuppose $X$ is a random variable on the interval $[1,10]$ whose PDF is given by \n\\[ f(x) = \\frac{c}{x} \\]\nfor some positive constant $c$ (note: this is the PDF that arises in the phenomenon known as \\link[Benford's Law]{https://en.wikipedia.org/wiki/Benford\\%27s_law}). Compute the mean $\\mu$ and the median $m$ associated to this PDF. Which is larger?\n\\[ \\mu = \\answer{\\frac{9}{\\ln 10}} \\ \\ \\text{ and } m = \\answer{\\sqrt{10}} \\]\nThe \\wordChoice{\\choice[correct]{mean}\\choice{median}} is more sensitive to tails. Since this distribution has a tail extending \\wordChoice{\\choice{to the left/for smaller $x$}\\choice[correct]{to the right/for larger $x$}}, it is expected (and in fact, true) that the mean is \\wordChoice{\\choice[correct]{larger}\\choice{smaller}} than the median.\n\\begin{hint}\nFirst you need to solve for the constant $c$.\n\\begin{hint}\n\\[ c = \\frac{1}{\\ln 10} \\]\n\\end{hint}\n\\end{hint}\n\\end{exercise}\n\n\n\\section*{Sample Quiz Questions}\n\\begin{question}%%%%%[ProbabAssort001]\n\nFind the value of \\(c\\) which makes the function\n\\[f(x) = \\frac{1}{2}e^{-x} - ce^{-2x}\\]\na probability density function on the interval \\([0, \\infty)\\). \nWhat is the value of the mean \\(\\mu\\) of the corresponding random variable? (Hints will not be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle c = 1, ~ \\mu = \\frac{1}{2}\\)}\n\\choice[correct]{\\(\\displaystyle c = -1, ~ \\mu = \\frac{3}{4}\\)}\n\\choice{\\(\\displaystyle c = 1, ~ \\mu = 1\\)} \n\\choice{\\(\\displaystyle c = -1, ~ \\mu = \\frac{5}{4}\\)}\n\\choice{\\(\\displaystyle c = 1, ~ \\mu = \\frac{3}{2}\\)}\n\\choice{\\(\\displaystyle c = -1, ~ \\mu = \\frac{7}{4}\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nTo compute the constant \\(c\\), we use the fact that the integral of a probability density function must equal \\(1\\), so \n\\[ \\mu = \\int_{0}^{\\infty} \\left( \\frac{1}{2}e^{-x} - ce^{-2x} \\right) ~ dx = 1.\\]\nThis gives the equation \\[\\frac{1}{2} - \\frac{1}{2}c = 1,\\]\nwhich then implies that \\(c = -1\\). \\begin{hint} To compute the mean \\(\\mu\\), we use the formula\n\\[ \\mu = \\int_{0}^{\\infty} x \\left( \\frac{1}{2}e^{-x} + e^{-2x} \\right) ~ dx.\\]\n Calculating the integral gives \\(\\mu = 3/4.\\) \\end{hint}\n\\end{feedback}\n\\end{question}\n\n\\begin{question}%%%%%[ProbEVsinibp001]\nA certain random variable \\(X\\) takes values in the interval \\(\\left[2 \\pi , \\frac{5}{2} \\pi \\right]\\).\nIf the probability density function is given by\n\\[ A \\sin {x} \\]\n for some appropriate value of the constant \\(A\\),\ncompute the expected value \\(\\mu\\) of \\(X\\).  (Hints will not be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\mu = -1 + 2 \\pi\\)}\n\\choice{\\(\\displaystyle \\mu = 1 + \\frac{3}{2} \\pi\\)}\n\\choice{\\(\\displaystyle \\mu = 2 \\pi\\)}\n\\choice{\\(\\displaystyle \\mu = -1 + \\frac{5}{2} \\pi\\)}\n\\choice[correct]{\\(\\displaystyle \\mu = 1 + 2 \\pi\\)}\n\\choice{\\(\\displaystyle \\mu = \\frac{5}{2} \\pi\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nThe constant \\(A\\) will be the reciprocal of the integral\n\\[ \\int_{2 \\pi}^{\\frac{5}{2} \\pi} \\sin {x}\\, dx \\]\n\\begin{hint}\n One can check that\n\\[ \\begin{aligned} \\int_{2 \\pi}^{\\frac{5}{2} \\pi} \\sin {x}\\, dx & = 1. \\end{aligned} \\] \\begin{hint} \nTo compute the expected value \\(\\mu\\) we also need to compute the integral \n\\[ \\int_{2 \\pi}^{\\frac{5}{2} \\pi} x \\sin {x}\\, dx \\]\n To compute the integral, we can use integration by parts. A reasonable strategy is to integrate  \\(\\sin {x}\\) and differentiate  \\(x\\). \\begin{hint}\n This gives the equality\n\\[ \\begin{aligned} \\int x \\sin {x}\\, dx & = - x \\cos {x} - \\int \\left(- \\cos {x}\\right)\\, dx \\\\\n & = - x \\cos {x} + \\sin {x}. \\end{aligned} \\]\nTherefore \n\\[ \\begin{aligned} \\int_{2 \\pi}^{\\frac{5}{2} \\pi} x \\sin {x}\\, dx & = \\left. \\left[- x \\cos {x} + \\sin {x} \\right] \\right|_{2 \\pi}^{\\frac{5}{2} \\pi}\\\\ & = 1 - \\left(- 2 \\pi \\right) = 1 + 2 \\pi. \\end{aligned} \\]\nTherefore the expected value is the ratio of the integrals, i.e.,\n\\[ \\begin{aligned} \\mu & = \\frac{1 + 2 \\pi}{1} = 1 + 2 \\pi. \\end{aligned} \\]\n\\end{hint} \\end{hint} \\end{hint}\n\\end{feedback}\n\\end{question}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%[2019ProbImprop]\nA certain random variable $X$ has values in $(1,\\infty)$ and has the property that there is some constant $C$ such that\n\\[ P( X > a) = C \\ln \\frac{a^3+1}{a^3} \\]\nfor every $a > 1$. Compute the value of $C$ and determine whether the expected value $\\mu$ of $X$ is finite or infinite. [Hint: There is enough information given to compute $C$ without calculating any integrals.]\n\\begin{multipleChoice}\n\\choice{$C = \\ln 2$ and $\\mu < \\infty$}\n\\choice{$C = 1$ and $\\mu < \\infty$} \n\\choice[correct]{$C = (\\ln 2)^{-1}$ and $\\mu < \\infty$} \n\\choice{$C = \\ln 2$ and $\\mu = \\infty$}\n\\choice{$C = 1$ and $\\mu  = \\infty$}\n\\choice{$C = (\\ln 2)^{-1}$ and $\\mu = \\infty$}\n\\end{multipleChoice}\n\n\n\\begin{feedback}\nWe know that $X$ is always greater than one, so\n\\[ 1 = P(X > 1) = C \\ln \\frac{1+1}{1}, \\]\nwhich gives $C = (\\ln 2)^{-1}$.  If we let $f(x)$ denote the probability density function of $X$, then\n\\[ \\frac{1}{\\ln 2} \\ln \\frac{a^3+1}{a^3} = P(X > a) = \\int_a^\\infty f(x) dx. \\]\nDifferentiating both sides with respect to $a$ gives\n\\[ \\frac{1}{\\ln 2} \\left[ \\frac{3 a^2}{a^3+1} - \\frac{3}{a} \\right] = - f(a) \\]\nso \n\\[ f(a) = \\frac{1}{\\ln 2} \\left[ \\frac{3}{a} - \\frac{3a^2}{a^3+1} \\right] = \\frac{3}{a(a^3+1) \\ln 2}. \\]\nThe expected value of $X$ must equal\n\\[ \\int_1^\\infty \\frac{3a}{a(a^3+1) \\ln 2} da = \\frac{3}{\\ln 2} \\int_1^\\infty \\frac{da}{a^3+1}. \\]\nThis integral will be finite by direct comparison to the convergent integral $\\int_1^\\infty a^{-3} da$.\n\\end{feedback}\n\\end{question}\n\n\\begin{question}%%%%%[2015C.08]\n\nThe function \n\\[ f(x) = \\begin{cases} \\displaystyle \\frac{k}{x^3} & 1 \\leq x < \\infty \\\\ 0 & \\text{otherwise} \\end{cases} \\]\nis a probability density function for a certain value of \\(k\\). For that probability density function, find the probability that \\(x > 2\\).\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\frac{1}{2}\\)}\n\\choice{\\(\\displaystyle \\frac{1}{3}\\)}\n\\choice[correct]{\\(\\displaystyle \\frac{1}{4}\\)}\n\\choice{\\(\\displaystyle \\frac{2}{3}\\)}\n\\choice{\\(\\displaystyle \\frac{1}{5}\\)}\n\\choice{\\(\\displaystyle \\frac{1}{6}\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2016C.07]\n\nFor a certain real number \\(k\\), the function\n\\[ f(X) = \\begin{cases} \\displaystyle \\frac{k}{X^2+1} & \\text{if } X \\geq 0 \\\\ 0 & \\text{otherwise} \\end{cases} \\]\nis a probability density function for a continuous random variable \\(X\\). For this value of \\(k\\), find the probability that \\(X > 1\\).\n\\begin{multiplechoice}\n\\choice{\\(0\\)}\n\\choice{\\(\\displaystyle \\frac{1}{3}\\)}\n\\choice{\\(\\displaystyle \\frac{2}{3}\\)}\n\\choice{\\(1\\)}\n\\choice[correct]{\\(\\displaystyle \\frac{1}{2}\\)}\n\\choice{\\(\\displaystyle \\frac{1}{4}\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2017C.09]\n\nLet \\[ f(r) = \\begin{cases} C r^2 e^{-2r/b} & r \\geq 0 \\\\ 0 & r < 0 \\end{cases}. \\]\nFind \\(C\\) so that this is a probability density function (pdf) for the random variable \\(r\\). Here \\(b\\) is a positive constant. This function is used to model the distance between the nucleus and the electron in a hydrogen atom. The constant \\(b\\) is called the \\textit{Bohr length}. Find the mean of the pdf.\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle C = \\frac{b^3}{4}\\), mean \\(\\displaystyle = b\\)}\n\\choice{\\(\\displaystyle C = \\frac{4}{b^2}\\), mean \\(\\displaystyle = b\\)}\n\\choice{\\(\\displaystyle C = \\frac{4}{b}\\), mean \\(\\displaystyle = b^2\\)} \n\\choice[correct]{\\(\\displaystyle C = \\frac{4}{b^3}\\), mean \\(\\displaystyle = \\frac{3}{2}b\\)}\n\\choice{\\(\\displaystyle C = \\frac{4}{b^2}\\), mean \\(\\displaystyle = \\frac{3}{2}b^2\\)}\n\\choice{\\(\\displaystyle C = \\frac{4}{b}\\), mean \\(\\displaystyle = \\frac{3}{2}b^3\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "b476f82f9fe9d5325e175ed2a5e2d7453d22c299", "size": 9612, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "applications/17probabilitypractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/17probabilitypractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/17probabilitypractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.6601941748, "max_line_length": 346, "alphanum_fraction": 0.6437786101, "num_tokens": 3337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241803, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7245565298473112}}
{"text": "\\chapter{Functions}\n\n\\footnote{\\url{https://en.wikipedia.org/wiki/Lambda_calculus}}%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Lambda_calculus_definition}}\n\n\\index{definitions!function}%\nWe can think of a function as a computer.\n\nThe type \\( a \\to b \\) is inhabited by functions that take an inhabitant of \\(a\\) and give an inhabitant of \\(b\\).\n\nA function \\(f : a \\to b\\) maps an \\(a\\) to a \\(b\\).\n\nThe expression \\(f(x)\\) means the result of applying \\(f\\) to \\(x\\).\n\nIf \\(x : a\\), then \\( f(x) : b \\).\n\nFor example, if \\(f(x) = x^2 + x + 1\\), then \\(f(2+3) = (2+3)^2 + (2+3) + 1\\) by substituting \\(x\\) with \\(2+3\\).\n\nDon't write \\(f(x)\\) to mean the function \\(f\\).\nThe function is \\(f\\).\nThe expression \\(f(x)\\) means the result of applying \\(f\\) to \\(x\\).\n\n\\paragraph{Defining functions}\n\nAn \\emph{unnamed function expression} is written like \\( x \\to x^2 + 1 \\).\n\nExample application: the expression \\( (x \\to x + 1)(5) \\) reduces to \\( 5 + 1 \\).\n\n\\paragraph{Composing functions}\n\nWe write \\(f \\circ g\\) to mean \\( x \\to f(g(x)) \\).\n\n\\paragraph{Applying functions}\n\n\\paragraph{The inverse of an invertible function}\n\nIf \\(f(x) = y\\), then \\(f^{-1}(y) = x\\),\nbut only if \\(f\\) does not map anything else to \\(y\\).\nWe say that \\(f^{-1}\\) is the inverse of \\(f\\).\n\nAn invertible function is a function whose inverse is also a function.\n\n\\((f \\circ g)^{-1} \\equiv g^{-1} \\circ f^{-1}\\)\n\n\\section{Function-returning functions}\n\n\\(x \\to (y \\to x+y)\\).\n\n\\section{Currying: one parameter is enough}\n\nA two-input function has a type like \\( (a,b) \\to c \\).\n\n\\index{definitions!currying}%\n\\emph{Currying} is the transformation from \\( f(x,y) \\) to \\( (f'(x))(y) \\) (from \\(f\\) to \\(x \\to y \\to f(x,y)\\)).\n\\emph{Uncurrying} is the inverse of currying.\n\nWe conflate \\( (f'(x))(y) \\) and \\( f(x,y) \\).\n\nWe assume that every function takes one input.\n\nDo not confuse:\n\\begin{itemize}\n    \\item a function that takes \\(n\\) inputs, and\n    \\item a function that takes \\emph{one} input that is an \\(n\\)-tuple.\n\\end{itemize}\n\n\\section{Plotting the graph of a function}\n\nIf you type \\verb@sin(x)@ into Google\\footnote{\\url{https://www.google.com/}},\nit will plot the graph of \\(y = \\sin(x)\\) for you.\n\nYou can also type \\verb@y=sin(x)@ into Wolfram Alpha\\footnote{\\url{https://wolframalpha.com/}}.\n\nYou can use GNU Octave.\n\nYou can use Gnuplot.\n\n\\paragraph{Thinking of an operator as a function}\n\nAn infix operator is an operator that is placed between two things.\nFor example, the dot in \\(a \\cdot b\\) is an infix operator.\n\nAn operator does not have to be a symbol.\nIt can be a letter.\nIt can be a complicated notation.\nFor example, \\(\\pdv{f}{x}\\).\n\nWe can treat an infix operator as another way of writing a function application.\nWe can think of \\(a \\cdot b\\) as a convenient way of writing \\((\\cdot)(a,b)\\).\n\n\\footnote{\\url{https://en.wikipedia.org/wiki/Operator_(mathematics)}}%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Operator_(physics)}}\n\n\\section{Equivalence of functions, eta-reduction}\n\\label{sec:function-equivalence}\n\nWe write \\(f \\equiv g\\) to mean that \\(f\\) gives the same result as \\(g\\) for all parameters.\n\n\\section{Exercises}\n\nTo evaluate something is to reduce it to normal form.\n\n\\ExerciseAnswer{Evaluate the expression \\((x \\to x + 1)(5)\\), assuming the usual arithmetic.}{Substitute: \\(5 + 1\\). Reduce: \\(6\\).}\n\n\\ShowAnswers\n", "meta": {"hexsha": "22f95ed206d3eb13a0501899bf643782495a91f0", "size": 3344, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/function.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/physics/function.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/physics/function.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 31.5471698113, "max_line_length": 132, "alphanum_fraction": 0.6650717703, "num_tokens": 1012, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7245450472348522}}
{"text": "\\chapter{Association Rule Mining}\n\n\\begin{description}\n\\item[Itemset] A collection of one or more items\n\\item[Frequent itemset] An itemset whose support is greater than or equal to a \\emph{minsup} threshold\n\\end{description}\n\n$$let\\ {X \\Rightarrow Y}$$\n\\begin{align*}\nSupport\\ Count, \\sigma &=\\# Trans(X \\cup Y) \\\\\nSupport, s &= \\frac{\\# Trans(X \\cup Y)}{Total\\ \\#\\ Trans} \\\\\nConfidence=P(Y|X)&=\\frac{\\# Trans(X \\cup Y)}{\\# Trans\\ contain\\ X}\n\\end{align*}\n\n\\noindent Goal of Association Rule Mining:\n\n$$support \\ge min\\_sup$$\n$$confident \\ge min\\_conf$$\n\n\\section{Frequent Itemset Generation}\n\nApriori Principle: If an itemset is frequent, then all of its subsets must also be frequent. This principle reduce the number of frequent itemset candidates\n$$\\forall X, Y: X \\subseteq Y \\Rightarrow s(X) \\ge s(Y)$$\nStore each candidate in a hash tree structure to count the support efficiently \\\\\n\n\\begin{description}\n\\item[Maximal Frequent itemset] none of its immediate supersets is frequent\n\\item [Closed itemset] none of its immediate supersets has the same support as the itemset\n\\end{description}\n\n\\subsection{Alternative: FP-Growth Algorithm}\nConstruct FP-tree from a transactional DB:\n\\begin{table}[h!]\n\\begin{tabular}{r p{12cm}}\n\\hline\n    1: & Scan DB once, find frequent 1-itemset\\\\\n    2: & Order frequent items in frequency descending order (L-order)\\\\\n    3: & Process DB based on L-order\\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\n\\noindent Mining frequent patterns using FP-tree:\n\\begin{table}[h!]\n\\begin{tabular}{r p{12cm}}\n\\hline\n    1: & Construct conditional pattern base for each item in header table\\\\\n    2: & Construct conditional FP-tree from each conditional pattern-base\\\\\n    3: & Recursively mine conditional FP-trees and grow frequent patterns obtained so far\\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\n\\section{Rule Generation}\nConfidence of rules generated from the same itemset has an anti-monotone property:\n$$c(ABC \\rightarrow D) \\ge c(AB \\rightarrow CD) \\ge c(A \\rightarrow BCD)$$\n\n\n\n\n", "meta": {"hexsha": "a626de8683fa40487b7c611502f91a70b1638ee6", "size": 2001, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter8.tex", "max_stars_repo_name": "Andyccs/data-mining-summary", "max_stars_repo_head_hexsha": "27ffac528e9e225c8a15ff44fbf2ed3e1c6b9f7a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter8.tex", "max_issues_repo_name": "Andyccs/data-mining-summary", "max_issues_repo_head_hexsha": "27ffac528e9e225c8a15ff44fbf2ed3e1c6b9f7a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter8.tex", "max_forks_repo_name": "Andyccs/data-mining-summary", "max_forks_repo_head_hexsha": "27ffac528e9e225c8a15ff44fbf2ed3e1c6b9f7a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.8032786885, "max_line_length": 156, "alphanum_fraction": 0.7306346827, "num_tokens": 565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7245450332708744}}
{"text": "\\lab{Algorithms}{Value Function Iteration}{Value Function Iteration}\n\\newcommand\\ve{\\varepsilon}\n\\objective{This section teaches the fundamentals of Dynamic Programming using value function iteration.}\n\nOften it is of interest to optimize decision making in some sequential process.  For example, an oil company may need to decide\nhow much oil to excavate and sell each month as prices change, a person entering retirement may need to decide how much of their\nsavings to spend each year, or a model of economic growth may require a decision about how much to invest in capital versus how\nmuch to spend each year.  In this lab we will formulate a general dynamic optimization problem.  We will explore techniques for\nsolving such a problem with both finite and infinite time horizons.\n\n\\section*{The Sequential Problem, Finite Horizon}\nSuppose there are time periods $t=0,1,\\ldots, T$ and at each time period we take an action $c_t$. Furthermore, at the beginning\nof each time period $t$ we are in some state $W_t$.  In many cases $W_t$ might represent an available resource, such as money.\nAt each time we receive some reward, $u(W_t,c_t)$, for taking action $c_t$ given state $W_t$.  We assume that rewards are worth\nmore now than later. We let $\\beta\\in (0,1)$ represent what is called the discount factor and gives the ratio of preference for\nrewards today versus rewards tomorrow.  For example, receiving a dollar today is preferable to receiving a dollar in a year\nbecause taking a dollar today and putting it in a  savings account results in having more than a dollar in a year.  Lastly, over\ntime our state variable $W_t$ changes according to some rule depending on the previous state and our actions,\n\\begin{equation}\n\\label{motion}\nW_{t+1} = g(W_t,c_t).\n\\end{equation}\nEquation \\eqref{motion} is sometimes referred to as the law of motion, as it describes how we move from state to state.\nMathematically such a problem can be represented as follows:\n\\begin{equation*}\n\\max \\sum_{t=0}^T \\beta^t u(W_t,c_t) \\quad \\text{s.t.} \\quad W_{t+1} = g(W_t,c_t)\n\\end{equation*}\nwhere our initial state, $W_0$ is given.  There may also be restrictions on our choices $c_t$.  For example, in many applications\nthe state $W_t$ represents the amount of some resource available, and $c_t$ represents the amount we use up in time period $t$.\n In this case we would require $c_t \\in [0,W_t]$.\n\nFor simplicity, lets assume that $u$ is a function of $c_t$ only (this is often, though not always, the case in practice).\n First let's consider the case that $T=0$.  So we maximize\n\\begin{equation}\\label{1perprob}\nu(c_0)\n\\end{equation}\nover $c_0 \\in [0,W_0]$.  In most cases $u$ is increasing, which we will assume here.  In this case it will be optimal to choose\n the largest value of $c_0$ possible, that is, $c_0 = W_0$.  Thinking of $W_0$ as our available resources, this simply means,\n that if we don't have future periods to consider, we will use all of it.\n\nIn fact this is always true in the last period.  In the problem with $T$-periods we know that we will use all of our resources\nremaining in period $T$.  Consider the two period problem:\n\\begin{equation}\n\\label{2perprob}\n\\max \\, \\{u(c_0) + \\beta u(c_1)\\}\n\\end{equation}\nwhere $c_0 \\in [0,W_0]$, $c_1 \\in [0,W_1]$ and $W_1 = g(W_0,c_0)$.  We know that in the last period we will use all of our\nremaining resources so that $c_1 = W_1$.  Substituting gives\n\\begin{equation*}\n\\max \\, \\{u(c_0) + \\beta u(g(W_0,c_0))\\}.\n\\end{equation*}\nThen we need only determine $c_0$.  Taking the derivative of \\eqref{2perprob} with respect to $c_0$ and setting equal to zero\ngives the first order condition\n\\begin{equation}\n\\label{FOC}\nu'(c_0) = -\\beta u'(g(W_0,c_0))g_c(W_0,c_0)\n\\end{equation}\nwhere $g_c$ is the partial derivative of $g$ with respect to $c$.\n\nGiven a specific form for $u$ we could solve for $W_1$ and obtain the optimal solution.  In fact, we can solve a problem of\nany length $T$ in this manner by starting at the last time period and working backward.  We know that $W_{T+1} = 0$.  Working\nbackward in time we obtain an equation at each time step $t<T$ by taking the derivative with respect to $c_t$ and setting equal\n to zero.  This process is called backward induction.  The equations at each time step, such as equation \\eqref{FOC} are\n sometimes called the inter-temporal Euler equations.  These equations, along with $c_T = W_T$ make $T+1$ equations to go with\n our $T+1$ unknowns $c_0,c_1,c_2,\\ldots,c_T$ where we can use the law of motion to relate the $c_t$ and $W_t$.\n\n\\section*{The Recursive Problem, Finite Horizon}\nApproaching the problem sequentially like this can be somewhat messy.  The dynamic programming approach we consider now is more\neasily adaptable to many situations.  The key to the dynamic programming approach is to define our optimization problem in terms\n of subproblems.  Notice that if we are in time period $t$, we face a problem of exactly the same form as the problem at time\n $0$.  We are in some state $W_t$, and want to maximize the sum from $t$ to $T$.  With this idea in mind, we define a function\n  $V_t(W_t)$ called the value function.  The function $V_t$ gives the value of entering time $t$ in state $W_t$ and making\n  optimal decisions moving forward.  So\n\\begin{equation*}\nV_{t-1}(W_{t-1}) = \\max_{c_t} \\left\\{u(c_{t-1}) + \\beta V_t(g(W_{t-1},c_{t-1}))\\right\\}.\n\\end{equation*}\nThis is called the Bellman Equation.  The key to this formulation is that we decide what to do in period $t-1$ with the\nassumption that our actions in the remaining periods will be optimal.  This is called the principal of optimality.\n\nLet us consider a specific example from economics called The Cake Eating Problem.  Suppose $W_t$ represents the amount of\ncake available at time $t$.  At each time period we can choose how much to consume.  What we eat, $c_t$, gives us a reward.\nWhat we save, $W_t-c_t$, does not give us a reward (until it is eaten in a later period).  The law of motion \\eqref{motion}\nbecomes\n\\begin{equation}\\label{LOM_EX}\nW_{t+1} = g(W_t,c_t) = W_t-c_t\n\\end{equation}\n\nNow we have completely defined the problem.  The Bellman Equation is\n\\begin{equation*}\nV_{t-1}(W_{t-1}) = \\max_{c_t} \\left\\{u(c_{t-1}) + \\beta V_t(W_{t-1}-c_{t-1})\\right\\}.\n\\end{equation*}\nNotice that by the law of motion, each $c_t$ is determined by $W_t$ and $W_{t+1}$.\nIn fact, rearranging \\eqref{LOM_EX}, we have\n\\begin{equation*}\nc_t = W_t - W_{t+1}.\n\\end{equation*}\nWe can therefore rewrite the value function as\n\\begin{equation}\nV_{t-1}(W_{t-1}) = \\max_{W_t} \\left\\{u(W_{t-1} - W_{t}) + \\beta V_t(W_t)\\right\\}.\n\\label{cake_valfn}\n\\end{equation}\n\nWe see that determining the optimal actions $c_t$ is equivalent to determining the optimal states $W_{t}$ in the\nabove formulation. The solution to this\nproblem is often called a \\emph{policy function}.  A policy function determines an action based on the current\nstate.  Denoting the policy function by $\\psi$, this can be written as\n\\begin{equation*}\nW_{t+1}=\\psi_t \\left(W_t\\right).\n\\end{equation*}\nThe policy function gives the optimal amount of cake to leave for next period (equivalent to the amount of consumption) given\nthe amount of cake at the start of the period.  In other words, it determines the choice of $W_t$ that satisfies the $\\max$\ncondition in \\eqref{cake_valfn}.\n\nAs before, we know that in the last time period we should not save anything.  So $V_{T+1}(W_{T+1}) = 0$, i.e. there is\nno value in leaving wealth for period $T+1$. Stated in another way, our action at time $T$ should be to eat all of the\nremaining cake $W_T$, so $W_{T+1} = \\psi_T(W_T) = 0$.\nPlugging this result into the Bellman Equation gives us $V_T(W_T) = u(W_T)$.\nNow consider the value function equation for period $T-1$:\n\\begin{align*}\nV_{T-1}(W_{T-1}) &= \\max_{W_T} \\left\\{u(W_{T-1} - W_T) + \\beta V_T(W_T)\\right\\} \\\\\n                 &= \\max_{W_T} \\left\\{u(W_{T-1} - W_T) + \\beta u(W_T)\\right\\}.\n\\end{align*}\nWe can determine this value by optimizing over $W_T$, where $0 \\leq W_T \\leq W_{T-1}$.\nContinuing backwards in this manner leads us to the solution of the original problem.\n\n\\begin{problem}\n\\label{prob:cake_prob}\nFollow the steps below to solve the problem described above.  Take $u(c_t) = \\sqrt{c_t}$.\nYou will write a function called \\li{eatCake} that takes parameters $\\beta$ (the discount factor),\n$N$ (the number of discrete cake values to consider), $W_{max}$ (the original size of the cake,\nset to the default value of $1$), a keyword argument \\li{finite} (set to default value \\li{True}),\na keyword argument  $T$ (the number of time periods, set to\ndefault value \\li{None}), and a keyword argument \\li{plot}, which indicates whether\nto plot the computed results. The function should return arrays representing the value function and the\npolicy function (we describe how to compute these in the following steps).\n\\begin{enumerate}\n\\item Approximate the continuum of possible cake sizes by creating an array\nof evenly-spaced values that range from to 0 to $W_{max}$ inclusive.\nLet the number of possible cake values be given by $N$. In Python, this can be accomplished easily by\nusing the \\li{linspace} function in NumPy. You should obtain an array (call it $w$) of the form\n\\[\nw = (w_1, w_2, \\ldots, w_N),\n\\]\nwhere $w_1 = 0$ and $w_N = W_{max}$.\n\n\\item Note that in order to compute the value function, we need $u(W_{t-1}-W_t)$.\nWe will pre-compute all possible such values and store them in an array, as follows.\nCreate an $N$ by $N$ matrix that contains\nall possible values of $W_{t-1} - W_t$ (where $W_{t-1}$ corresponds to rows and $W_{t}$ to columns).  Make sure that\n$c_t \\geq 0$ is satisfied by replacing negative entries in the matrix with zero.  Then take the square root to get a matrix\nof $u(W_{t-1}-W_t)$.  To make sure we do not choose $W_{t-1} - W_t < 0$ when maximizing, replace the corresponding entries of\nthe $u(W_{t-1}-W_t)$ matrix with a large negative number (e.g. $-10^{10}$). You should end up with a matrix whose\n$(i,j)$-th entry is equal to $\\sqrt{w_i - w_j}$ when $i \\geq j$, and is equal to $-10^{10}$ when $i < j$.\n\n\\item Next, create an $N$ by $T+2$ (corresponding to $t=0,1,\\ldots, T+1$) matrix representing the value function for a given\ntime $t$ and state $W_t$.  We can initialize it to zeros and begin filling in the columns starting with the last (which we\nknow is zeros).\n\n\\item Now we are ready to iterate backward and compute the value function for each time period.  To find $V_T$, we first compute\n$u(W_T - W_{T+1}) + \\beta V_{T+1}(W_{T+1})$ for all values of $W_{T}$ and $W_{T+1}$.  This will result in an $N$ by $N$ matrix\nwhere the rows correspond to values of $W_{T}$ and the columns correspond to values of $W_{T+1}$.\n%Note that to compute this\n%we need a matrix representing $\\beta V_{T+1}(W_{T+1})$.  Because this quantity does not depend on $W_T$, its rows should be\n%equal.  To do this, we want to take $\\beta V_{T+1}(W_{T+1})$ as a row vector and stack this vector to create a matrix with\n%equal rows.  There are multiple ways to do this.  One is the \\li{np.repeat} function.  For example, if \\li{b} is a row vector\n%it could be used like the following.\n%\\begin{lstlisting}\n%b = [[1, 2, 3]]\n%np.repeat(b, 3, axis = 0)\n%array([[1, 2, 3],\n%[1, 2, 3],\n%[1, 2, 3]])\n%\\end{lstlisting}\n%In general, be careful about having the correct rows, columns, transposes, etc throughout your code.\n\nNow we maximize over choices of $W_{T+1}$ (choosing how much to save for next period).  Then we will have a row vector\nrepresenting the value function for period $T$ across all possible $W_{T+1}$.  Iterate this procedure to fill in the value\nfunction for all $t=0,1,\\ldots, T+1$.\n\n\\item In each iteration, you maximize to find the value function at time $t$.  Save the values of $W_{t+1}$ that achieve the\nmaximum.  The result is an $N$ by $T+1$ matrix whose $(n,t)$ entry gives the optimal amount of cake to leave for period\n$t+1$ given that we start period $t$ with the the $n$-th value of our vector of cake.  This is the policy function.\n\n\\item If the keyword argument \\li{plot} is set to \\li{True}, plot the surface of the Value and Policy functions.\nThis can be done by including the following import lines\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n>>> from matplotlib import cm\n>>> from mpl_toolkits.mplot3d import Axes3D\n\\end{lstlisting}\nand using the following code:\n\\begin{lstlisting}\n>>> W = np.linspace(0, Wmax, N)\n>>> x = np.arange(0, N)\n>>> y = np.arange(0, T+2)\n>>> X, Y = np.meshgrid(x, y)\n>>> fig1 = plt.figure()\n>>> ax1 = Axes3D(fig1)\n>>> ax1.plot_surface(W[X], Y, np.transpose(V), cmap=cm.coolwarm)\n>>> plt.show()\n\n>>> fig2 = plt.figure()\n>>> ax2 = Axes3D(fig2)\n>>> y = np.arange(0,T+1)\n>>> X, Y = np.meshgrid(x, y)\n>>> ax2.plot_surface(W[X], Y, np.transpose(psi), cmap=cm.coolwarm)\n>>> plt.show()\n\\end{lstlisting}\nwhere \\li{W} is the vector of cake amounts, \\li{V} is the value function, and \\li{psi} is the policy function.\n\n\\item Return the arrays giving the value function and the policy function.\n\\end{enumerate}\n\nSolve the problem using cake size $1$, discount factor $\\beta = .9$, number of time periods $T = 10$, and number of\ndiscrete cake values $N = 100$. You should also try plotting the value and policy functions for fixed time periods across\n$W_t$, or for fixed $W_t$\nacross time and make sure that these plots fit your intuition. See Figure \\ref{fig:valueslices}. Your output should\nagree with the figure.\n\\end{problem}\n\n\\begin{figure}\n\\begin{subfigure}{.5\\textwidth}\n    \\includegraphics[width=\\textwidth]{fixed_time.pdf}\n\\end{subfigure}\n\\begin{subfigure}{.5\\textwidth}\n    \\includegraphics[width=\\textwidth]{fixed_w.pdf}\n\\end{subfigure}\n\\caption{Slices of the finite horizon value function for fixed values of $t$ and $W$.}\n\\label{fig:valueslices}\n\\end{figure}\n\n\\section*{The Recursive Problem, Infinite Horizon}\\label{SecRecProbInFHor}\nNext we consider an infinite horizon problem.  For simplicity, we continue with the example from the previous section.\nSuppose that rather than optimizing over $t = 0,1,\\ldots,T$, we wish to optimize over an infinite time horizon:\n\\begin{equation*}\n\\max \\sum_{t=0}^\\infty \\beta^t u(W_t,c_t) \\quad \\text{s.t.} \\quad W_{t+1} = g(W_t,c_t).\n\\end{equation*}\nSince at any time $t$, there are an infinite number of periods remaining, one might suspect that the optimal policy will\nnot depend on the current time $t$.\n\n\\begin{problem}\n\\label{prob:cake_prob2}\nCompute the solution to Problem \\ref{prob:cake_prob} with $T = 1000$, and the rest of the inputs the same.\nPlot the policy function across time for fixed $W_t = 1$.\nNotice that it is the same for all time periods, except those near the end time $T$.\n\\end{problem}\n\nAs suggested by the results of Problem \\ref{prob:cake_prob2},  the policy function for the infinite horizon problem does not\ndepend on the time $t$ (this can be proved).  That is, at any time $t$, the optimal decision depends only on the amount of cake\nat the beginning of the period, not the value of $t$.  So everything can now be written in terms of variables today and variables\ntomorrow. We will denote variables tomorrow with a ``$\\:'\\:$\".\n\\begin{equation}\n\\label{EqBellman}\nV\\left(W\\right) = \\max_{W'\\in[0,W]}\\:\\: \\left\\{u\\left(W - W'\\right) + \\beta V\\left(W'\\right)\\right\\}\n\\end{equation}\nNote that the value function $V$ on the left-hand-side of \\eqref{EqBellman} and on the right-hand-side are the same function.\n\nBecause the problem now has an infinite horizon, the nature of the solution is a little different. The solution to \\eqref{EqBellman}\nis a policy function $W'=\\psi(W)$ that creates a fixed point in $V$. In other words, the solution is a policy function $\\psi(W)$\nthat makes the function $V$ on the left-hand-side of \\eqref{EqBellman} equal the function $V$ on the right-hand-side.\n\nDefine $C$ as an operator on any value function $V_k\\left(W\\right)$. Let $C$ perform the following operation.\n\\begin{equation}\n\\label{EqContraction}\nC\\Bigl(V_k\\left(W\\right)\\Bigr) \\equiv \\max_{W'\\in[0,W]}\\:\\: \\left\\{u\\left(W-W'\\right) + \\beta V_k\\left(W'\\right)\\right\\}.\n\\end{equation}\nNote that the value function on the right-hand-side of \\eqref{EqContraction} and on the left-hand-side are the same function $V_k$,\nbut have a different inputs--$W$ versus $W'$. The operator $C$ takes in a function $V_k$, and gives a new\nfunction which we will call $V_{k+1}$:\n\\begin{equation*}\nV_{k+1}\\left(W\\right) \\equiv C\\Bigl(V_k\\left(W\\right)\\Bigr).\n\\end{equation*}\nThe value function $V_{k+1}$ that results from the operation $C$ is not necessarily the same as the value function that the system\nbegan with $V_k$. However, according to equation \\eqref{EqBellman} we seek a $V$ such that $C(V) = V$.  The solution, then, is the\nfixed point in $V$.\n\\begin{equation*}\nC\\Bigl(V_k\\left(W\\right)\\Bigr) = V_{k+1}\\left(W\\right) = V_k\\left(W\\right) = V\\left(W\\right)\n\\end{equation*}\n\nWhen trying to solve a fixed point equation, it is often very helpful to utilize the Contraction Mapping Principle, which\nguarantees the existence of a fixed point of a mapping, provided that the map sends any two distinct inputs to outputs\nthat are strictly closer to each other than the inputs, in a controlled way. This principle also provides a constructive\nway to obtain the fixed point, namely by iterating the map.\nFortunately, it can be shown that if $u(\\cdot)$ is real-valued, continuous, and bounded, $\\beta\\in(0,1)$, and that the constraint\nset $W'\\in[0,W]$ is nonempty, compact-valued, and continuous, then the operator $C$ is a contraction and thus we can obtain\na solution $V$ by iteration:\n\\begin{equation*}\n\\lim_{k\\rightarrow\\infty}\\: C^k\\Bigl(V_0\\left(W\\right)\\Bigr) = V_k(W) =  V\\left(W\\right)\n\\end{equation*}\nfor any $V_0$.\n\nRemember, in the infinite horizon problem both the value and policy functions do not depend on time.  Computationally, this means that\n the value and policy functions in the infinite horizon problem are one dimensional.\n\n\\begin{problem}\nExpand your \\li{eatCake} function to solve the Cake Eating Problem with an infinite time horizon. If the keyword argument\n\\li{finite} has the value \\li{True}, then your function should behave as in Problem \\ref{prob:cake_prob}, solving the finite\ntime horizon problem. However, if \\li{finite = False}, solve the infinite time horizon problem through the following steps.\nBoth problems will require you to pre-compute the values $u(W - W')$, where $W$ and $W'$ range over the set of discrete cake\namounts. Be sure to avoid replicating code by factoring it out.\nAs in Problem \\ref{prob:cake_prob}, take $u(c_t) = \\sqrt{c_t}$.\n\\begin{enumerate}\n\\item As in Problem \\ref{prob:cake_prob}, approximate the continuum of possible\ncake sizes by a column vector called $W$ that ranges from 0 to $W_{max}$ in $N$ steps.\n\n\\item \\label{item:step2} Initialize the value function, V to a vector of zeros of length $N$.  This is $V_0$.  Perform one iteration\nof the contraction operation given in equation \\eqref{EqContraction} to get a new value function $V_1$ (this should be very similar\nto Problem 1).  Determine the resulting policy function $W' = \\psi_1\\left(W\\right)$.  [HINT: The policy function should be a vector\nof length $N$ of optimal future values of the cake $W'$ given the current value of the cake $W$, and $V_T$ should be an $N$-length\nvector representing the value of entering a period with cake size $W$.]\n\n\\item \\label{item:step3} Measure the distance between the two value functions as the sum of the\nsquared differences,\n\\begin{equation}\n\\label{EqDist}\n\\delta_1\\equiv \\norm{V_1\\left(W\\right) - V_0\\left(W'\\right)}_2^2 = \\left(V_1 - V_0\\right)^T\\left(V_1 - V_0\\right).\n\\end{equation}\nDefined in this way, $\\delta_1\\in [0,\\infty)$.\n\n%\\item \\label{item:step4} Take the resulting $V_1$ from \\ref{item:step2}, and perform the same contraction on it to generate $V_2$\n%and $\\psi_2$. That is, generate,\n%\\begin{equation*}\n%  V_2\\left(W\\right) = C\\Bigl(V_1\\left(W\\right)\\Bigr) = \\max_{W'\\in[0,W]}\\: u\\left(W - W'\\right) + \\beta V_1\\left(W'\\right)\n%\\end{equation*}\n%and the accompanying policy function $W'=\\psi_2\\left(W\\right)$. Calculate the accompanying distance measure for $\\delta_2$ using\n% the formula from \\eqref{EqDist} with the updated period subscripts. Compare $\\delta_2$ with $\\delta_1$ from \\ref{item:step3}.\n%\n%\\item \\label{item:step5} Repeat \\ref{item:step4} and generate $V_3$ and $\\psi_2$ by performing the contraction on $V_2$. Compare\n%$\\delta_3$ to $\\delta_2$ and $\\delta_1$.\n\n\\item Write a loop that performs the contraction operation from steps \\ref{item:step2} and \\ref{item:step3} iteratively\nuntil the distance measure is very small ($\\delta_k < 10^{-9}$).  The distance measure $\\delta_k$ being arbitrarily close to zero means\n you have converged to the fixed point $V_k = V_{k+1} = V$. (For fun, you can show that the policy function converges to the same\n function regardless of what you put in for your initial policy function value.)\n\n\\item If \\li{plot = True}, plot the converged policy function vector\n($y$-axis) as a function of the cake amounts ($x$-axis).\n\n\\item Return the value function and policy function arrays.\n\nCompute the value function and policy function for the infinite time horizon problem with\ncake size $1$, discount factor $\\beta = .9$, and number of\ndiscrete cake values $N = 100$. The plot you generate should agree with Figure \\ref{fig:infinitePolicy}.\n\\end{enumerate}\n\\end{problem}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{infiniteHorizon.pdf}\n\\caption{Policy function for infinite time horizon.}\n\\label{fig:infinitePolicy}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{convergence.pdf}\n\\caption{Due to the contraction mapping principle, $\\delta_k$ decreases as we perform iterations\nuntil it is small enough to meet our convergence tolerance.}\n\\end{figure}\n\n\\section*{Infinite Horizon, Stochastic, i.i.d.}\\label{SecRecProbInfinHorStochiid}\n\nIn practice, dynamic programming problems often involve some level of uncertainty.\nFor example as time progresses prices may fluctuate, resources may vary, or preferences themselves may change.\n In this lab, we reexamine the cake eating problem, this time allowing for uncertainty.\n\nWe consider again the problem of optimizing a sequence of decisions over an infinite time horizon.\nWe assume that the individual's preferences deviate each period according to some ``shock\" $\\ve$,\nwhere $\\ve$ is a random variable.  We assume that the shock terms $\\ve$ for each time period are\nindependent and identically\ndistributed (i.i.d.).  In effect, this means the probabilities associated with the $\\ve$ are the\nsame for any time $t$ and do not depend on each other.  We assume for now that the $\\ve$ are\ndistributed normally with mean $\\mu$ and variance $\\sigma^2$.  The Bellman equation can be easily\nrewritten in the following way to incorporate the uncertainty,\n\\begin{equation}\\label{stoch_Bellman}\n   V\\left(W,\\ve\\right) = \\max_{W'\\in[0,W]}\\: \\{\\ve u\\left(W - W'\\right) +\n   \\beta E_{\\ve'}\\left[V\\left(W',\\ve'\\right)\\right]\\},\n\\end{equation}\nwhere $\\ve \\sim N(\\mu,\\sigma^2)$ and\n$E$ is the unconditional expectation operator over $\\ve$.  Note that now the value function depends\non two variables.  It represents the value of entering the period with $W$, the amount of cake,\nand a preference shock of $\\ve$.  For example, in a period where the realization of $\\ve$ is higher,\nwe will get more value from the cake eaten in the current period.  Because we do not know the value of\nthe shock in the next period $\\ve'$, we consider only the expected value for future time.\n\nIt turns out, we can solve this problem in a manner similar to the infinite horizon deterministic cake-eating\nproblem considered in the Value Function Iteration lab.  It is worth noting that in this case,\n the value and policy functions will be two dimensional as they will depend on both $W$ and $\\ve$.\n\nIn order to deal with $\\ve$ computationally, we would like to represent it as a vector of possible values\nit could take along with the corresponding probabilities that it takes each of those values.  However,\n$N(\\mu,\\sigma^2)$ is a continuous distribution, so we cannot represent every value $\\ve$ could take.\nWe need a discrete distribution that approximates $N(\\mu,\\sigma^2)$.\n\nTo do this, we choose $N$ equally spaced points centered about the mean, at which to approximate the\ndistribution. Call these values $\\ve_1,\\ldots,\\ve_N$, and let the spacing between adjacent points be\ngiven by $\\delta$.\nWe can then break up the support of the distribution into $N$ bins, where adjacent bins share a common\nendpoint. Call the endpoints of these bins $v_1,\\ldots,v_{N+1}$. By choosing the endpoints to be\nhalfway between each $\\ve_k$, we have the formula\n\\[\nv_k = \\ve_k - \\frac{1}{2}\\delta, \\qquad k=1,\\ldots,N\n\\]\nand\n\\[\nv_{N+1} = \\ve_N + \\frac{1}{2}\\delta.\n\\]\n\n\\begin{figure}[h!]\n\\label{stoch1_fig1}\n\\begin{center}\n\\includegraphics[width = \\textwidth]{discnorm.pdf}\n\\end{center}\n\\caption{Discretization of $N(\\mu,\\sigma^2)$.  We approximate $P(\\ve = \\ve_k)$ by the area of the shaded region.}\n\\end{figure}\n\nWe can then associate $\\ve_k$ with the area under the curve from $v_k$ to $v_{k+1}$.\nIn Python, we can find the area using the function \\li{norm.cdf} found in the \\li{stats} package.\nThe cdf (cumulative distribution function) gives the area under the curve from $-\\infty$ to a specified value.\nFor example, in the following code, \\li{eps} is the area under the curve from 0 to 1.\n\n\\begin{lstlisting}\n>>> from scipy import stats as st\n>>> mu = 0\n>>> sigma = 1\n>>> eps = st.norm.cdf(1,loc=mu,scale=sigma) - st.norm.cdf(0,loc=mu,scale=sigma)\n\\end{lstlisting}\n\nIn general, it is sufficient to take our points $\\ve_k$ ranging from $\\mu - 3\\sigma$ to $\\mu + 3\\sigma$, as this\nrange contains about 99.7\\% of the probability mass.\n\n\\begin{problem}\nWrite a function called \\li{discretenorm} that accepts an integer $K$ representing the number of discrete points\ndesired, a mean $\\mu$, and a standard deviation $\\sigma$. It should return a length-$K$ vector of equally-spaced\nvalues ranging from $\\mu - 3\\sigma$ to $\\mu + 3\\sigma$ inclusive,\nand a length-$K$ vector containing the associated probabilities.\nPlot the approximation of $N(0,1)$ using different values of $K$ to check that your results are plausible.\n\\end{problem}\n\nNow that we have a discrete distribution for $\\ve$, we can solve for the value and policy functions\ndetermined by \\eqref{stoch_Bellman}.\n\n\\begin{problem}\nComplete the following steps to solve the problem described above.\nAssume that the period utility function is $u(c)=\\sqrt{c}$.\nWrite a function \\li{stochEatCake}\nthat accepts parameters $\\beta$ (discount factor), $N$ (number of discrete cake values),\na tuple of values \\li{e_params}, $W_{max}$ (the original size of the cake, set to default value 1),\na keyword argument \\li{iid} (set to default value \\li{True}), and\na keyword argument \\li{plot} (set to default value of \\li{False}). Inside the function, carry out the steps\noutlined below.\n\nThe argument \\li{e_params} is a tuple consisting of the values needed to generate\nthe discrete approximation to $\\ve$. In the present case, this tuple consists (in order) of\n$K$ (the number of discrete approximations of $\\ve$), $\\mu$ (the\nmean of the shock term $\\ve$), and $\\sigma$ (the standard deviation of the shock term $\\ve$),\nsince these are the arguments we need to pass to our \\li{discretenorm} function.\n\n\\begin{enumerate}\n\\item First, compute an approximation of $\\ve$ using the \\li{discretenorm} function created in Problem 1.\nUse $K$ equally spaced points to approximate $N(\\mu,\\sigma^2)$. Denote the resulting $K$-length\nvector of equally-spaced values by\n\\[e =(e_1,\\ldots,e_K),\n\\]\nand denote the $K$-length vector of the associated probabilities\nby\n\\[\\Gamma = (\\Gamma_1,\\ldots,\\Gamma_K).\n\\]\nNote that $\\Gamma_k$ give the probability $P(\\ve = e_k)$.\n\nSince the values needed for the \\li{discretenorm} function are contained in the \\li{e_params} input,\nwe can feed these values directly into the function in the following way:\n\\begin{lstlisting}\n>>> e, gamma = discretenorm(*e_params)\n\\end{lstlisting}\nThe \\li{*} operator essentially unpacks the values of a tuple or list.\n\n\\item As in the Value Function Iteration lab, create a vector\n\\[w = (w_1,\\ldots,w_N)\n\\]\nof possible cake sizes. This should be\na length-$N$ vector of equally spaced values from 0 to $W_{max}$, inclusive.\n\n\\item Represent the value function as a $N \\times K$ matrix $v$, satisfying\n\\[\nv_{i,j} = V(w_i, e_j).\n\\]\n(The rows correspond to different values of $W$ and the columns correspond to different values of $\\ve$.)\nInitialize each entry of the matrix to 0.\n\nLikewise, represent the policy function as a $N \\times K$ matrix $p$, satisfying\n\\[\np_{i,j} = \\psi(w_i,e_j).\n\\]\nInitialize all entries to 0.\n\n\\item In order to evaluate the value function equation, we need to pre-compute $\\ve u(W-W')$ for all values of\n$\\ve,W,W'$.\nBegin by computing all possible values of $u(W-W')$, and storing these values in a $N \\times N$ array,\nas in the Value Function Iteration lab. Call this array $u$. Make sure that the upper triangular\nentries of this array are equal to zero, as these entries correspond to consuming more cake than is\navailable, which is impossible.\n\nThe values $\\ve u(W-W')$ will be represented by a three-dimensional array $\\hat{u}$ of size\n$N\\times N\\times K$, satisfying\n\\[\n\\hat{u}_{i,j,k} = v_{i,j}e_k.\n\\]\nWe can compute this array easily as follows:\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> u_hat = np.repeat(u, K).reshape((N,N,K))*e\n\\end{lstlisting}\n\n\n\\item We also need to compute $E_{\\ve'}\\Bigl[V\\left(W',\\ve'\\right)\\Bigr]$ for each value of $W'$.\nThe expected value is simply\n\\begin{equation*}\nE_{\\ve'}\\Bigl[V\\left(W',\\ve'\\right)\\Bigr] = \\sum_{k=1}^K \\Gamma_kV(W',e_k').\n\\end{equation*}\nThe result is length $N$ vector, call it $E$, satisfying\n\\[\nE_i = E_{\\ve'}\\Bigl[V\\left(w_i,\\ve'\\right)\\Bigr] = \\sum_{k=1}^K \\Gamma_kv_{i,k}\n\\]\nThis calculation can be done by multiplying $\\Gamma$ element-wise to each row of the\nvalue function matrix $v$, and then summing along the rows. Something like the following\nline of code should do the trick:\n\\begin{lstlisting}\n>>> E = (v*gamma).sum(axis=1)\n\\end{lstlisting}\n\n\\item We can now compute the value function contraction\n\\begin{equation*}\\label{EqContractStochiid}\nC\\Bigl(V\\left(W,\\ve\\right)\\Bigr) \\equiv \\max_{W'\\in[0,W]}\\:\n\\Bigl\\{\\ve u\\left(W-W'\\right) + \\beta E_{\\ve'}\\Bigl[V\\left(W',\\ve'\\right)\\Bigr]\\Bigr\\}.\n\\end{equation*}\nThe first task is to create a $N \\times N \\times K$ array $c$ satisfying\n\\[\nc_{i,j,k} = \\hat{u}_{i,j,k} + \\beta E_j.\n\\]\nThis can be done in any manner of ways. Below is a one-liner that does the job.\n\\begin{lstlisting}\n>>> c = np.swapaxes(np.swapaxes(u_hat, 1, 2) + beta*E, 1, 2)\n\\end{lstlisting}\n\nNow, for any $k$ and $i < j$, set $c_{i,j,k}$ to a large negative number, say $-10^{10}$,\nso that when maximizing over this array, we do not choose to consume more cake than is available.\nAgain, this can be done in a variety of different ways, but the following does the job concisely:\n\\begin{lstlisting}\n>>> c[np.triu_indices(N, k=1)] = -1e10\n\\end{lstlisting}\n\nFinally, maximize over the second axis of $c$ (which corresponds to different values of $W'$)\nto obtain the updated value function matrix:\n\\begin{lstlisting}\n>>> v_new = np.max(c, axis=1)\n\\end{lstlisting}\nYou can likewise update your policy function matrix as follows:\n\\begin{lstlisting}\n>>> max_indices = np.argmax(c, axis=1)\n>>> p = w[max_indices]\n\\end{lstlisting}\n\n\\item We now have our updated value function matrix $v_{new}$ as well as the\nprevious $v$, which we refer to here as $v_{old}$. As we iterate on the value function equation, we need a norm\n\\begin{equation*}\n\\delta = \\|v_{new} - v_{old}\\|_2\n\\end{equation*}\nthat measures the distance between these two value functions to determine convergence.\nYou may compute the norm using the SciPy function \\li{scipy.linalg.norm}, or by direct calculation.\nAt the end of each iteration, make sure to set $v$ to $v_{new}$, so that the updates carry through the\nloop.\nIterate on the contraction until $\\delta < 10^{-9}$.\n\n\\item If \\li{plot = True}, make a 3-D surface plot of the policy function for the converged problem\n$W' = \\psi\\left(W,\\ve\\right)$ which gives the value of the cake tomorrow as a\nfunction of the cake today  and the taste shock today.  Do the same for the value function.\nExample code to create the value function plot is provided below.\n\\begin{lstlisting}\n>>> x = np.arange(0,N)\n>>> y = np.arange(0,K)\n>>> X,Y = np.meshgrid(x,y)\n>>> fig1 = plt.figure()\n>>> ax1 = Axes3D(fig1)\n>>> ax1.plot_surface(w[X], Y, v.T, cmap=cm.coolwarm)\n>>> plt.show ()\n\\end{lstlisting}\nCreating the policy function plot is similar.\n\n\\item Return the converged value function matrix $v$ and policy function matrix $p$.\n\n\n\\end{enumerate}\nTest your function using values $\\beta = .9$, $N = 100$, $K = 7$, $\\sigma = .5$, $\\mu = 4\\sigma$,\nand \\li{plot = True}.\nThe proper way to set this up and call the function is as follows:\n\\begin{lstlisting}\n>>> e_params = (7, 4*.5, .5)\n>>> stuff = stochEatCake(.9, 100, e_params, plot=True)\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width = \\textwidth]{stoch_value.pdf}\n    \\caption{3D surface representing the value function for the Stochastic Cake-Eating problem.}\n\\end{figure}\n\n\\section*{Infinite Horizon, Stochastic, AR(1)}\\label{SecRecProbInfinHorStochAR1}\n\nIn the previous example, we assumed that the shocks at time $t$ were independent of what happened in\nprevious periods.  Often a shock may depend on recent events.  We will assume now that the shocks are persistent,\nmeaning preferences in the current period are more likely to be close to what they were in the previous period.\nWe can characterize the persistence by what is called an autoregressive process of order one, denoted AR(1).\nSuch a process is defined as follows.\n\\begin{equation}\\label{EqAR1shock}\n\\ve' = (1-\\rho)\\mu + \\rho\\ve + \\nu' \\quad\\text{where}\\quad \\rho\\in(0,1) \\quad\\text{and}\\quad \\nu\\sim N(0,\\sigma^2).\n\\end{equation}\n\nEssentially, instead of allowing the shocks to have a mean which is independent of the past, the mean is now a\nweighted average (weighted by $\\rho$) of some $\\mu$ and the previous realization of the shock, $\\ve$.  As it turns\n out, we can approximate this process by thinking of it as a Markov Chain. This means we need to determine a\n discrete set of points representing possible values of $\\ve$ and a Markov transition matrix that gives the\n probabilities of moving from one value of $\\ve$ to another.  There are methods for determining the discrete\n approximation of $\\ve$ with a Markov transition matrix.  These methods are beyond the scope of this section,\n but you can use the file \\li{tauchenhussey.py} to implement them in the next problem.\n\nThe Bellman equation becomes the following, in which the only change from the i.i.d. shock case is that the\nexpectations operator is now conditional on the current shock $\\ve$:\n\n\\begin{equation*}\n   V\\left(W,\\ve\\right) = \\max_{W'\\in[0,W]}\\: \\{\\ve u\\left(W - W'\\right) +\n   \\beta E_{\\ve'|\\ve}\\left[V\\left(W',\\ve'\\right)\\right]\\},\n\\end{equation*}\nwhere $\\ve'$ is distributed according to \\eqref{EqAR1shock}.\nLet $\\Gamma_{i,j}=P\\left(\\ve_j'|\\ve_i\\right)$ where $\\ve_j'$ is the value of the shock in\nthe next period and $\\ve_i$ is the value of the shock in the current period.\nIn other words, $\\Gamma$ is the Markov transition matrix.\n\nThe solution to this problem is of the same type as that in the i.i.d. case, since the only difference is\nthe probability distributions of the $\\ve$.\n\n\\begin{problem}\nExpand your \\li{stochEatCake} function to handle the case of AR(1) shock terms. The function should\nhandle this case for the parameter value \\li{iid = False}, and should handle the previous case of\nnormally distributed i.i.d. shock terms for the parameter value \\li{iid = True}. You will need to\nadd a few ``if ... else\" statements, as well as implement the steps outlined below, but most of the\ncode will remain unchanged.\n\n\\begin{enumerate}\n\\item In the AR(1) case, the \\li{e_params} argument should be a tuple of values needed to\ngenerate the arrays $e$ and $\\Gamma$ that approximate the values and distribution of $\\ve$\nas a Markov chain.\nUse the file \\li{tauchenhussey.py} to calculate these arrays.\nThe provided Python function \\li{tauchenhussey} produces the vector $e$ of length $M$\nand an $M\\times M$ transition matrix $\\Gamma$.\nThus, you simply need the following lines of code, similar to the previous case.\n\\begin{lstlisting}\n>>> from tauchenhussey import tauchenhussey\n>>> e, gamma = tauchenhussey(*e_params)\n\\end{lstlisting}\n\n\\item Because our values for $e$ and $\\Gamma$ are different in the AR(1) case than\nin the i.i.d. case, we must compute the expectation in a different manner.\nIn particular, we need to compute the conditional expectation\n\\begin{equation*}\nE_{\\ve'|\\ve}\\Bigl[V\\left(W',\\ve'\\right)\\Bigr].\n\\end{equation*}\nWe obtain a two-dimensional array, since the expectation depends on both $W'$ and on $\\ve$.\nThe expectation can be computed by the matrix multiplication $v\\Gamma^T$.\nYour code should match the following.\n\\begin{lstlisting}\n>>> E = v.dot(gamma.T)\n\\end{lstlisting}\n\n\\item The last difference comes in computing the array $c$. Fortunately, it is easier in this case.\nRecall that $c$ gives the values for\n\\[\n\\ve u\\left(W-W'\\right) + \\beta E_{\\ve'|\\ve}\\Bigl[V\\left(W',\\ve'\\right)\\Bigr].\n\\]\nThe array $\\hat{u}$ contains the values for the first term in the expression, and the array $E$\ncontains the values for the expectation term.\nHence, we obtain $c$ by simple addition. Array broadcasting makes this work without problems.\n\\begin{lstlisting}\n>>> c = u_hat + beta*E\n\\end{lstlisting}\nYou will still need to set the upper triangular entries of $c$ to a large negative number, just as in the\nprevious case.\n\\end{enumerate}\n\nThose are the only differences. Let the following code snippet be a guideline for how to implement\nthese differences.\n\\begin{lstlisting}\n>>> if iid:\n>>>     # compute E as outlined in problem 2\n>>> else:\n>>>     # compute E as outlined in the current problem\n\\end{lstlisting}\n\nNow test your function with $\\beta = .9$, $N = 100$, \\li{iid = False}, and \\li{plot = True}.\nAs inputs to \\li{tauchenhussey}, let $K=7$, the mean of the process\n$\\mu=4\\sigma$, $\\rho = 1/2$, $\\sigma=1/2$, and\n\\[baseSigma=(0.5+\\frac{\\rho}{4})\\sigma +\n(0.5 - \\frac{\\rho}{4})\\frac{\\sigma}{\\sqrt{1-\\rho^2}}.\n\\]\nYour \\li{e_params} parameter will therefore be a tuple of values containing (in order)\n$K$, $\\mu$, $\\rho$, $\\sigma$, and $baseSigma$.\n\\end{problem}\n", "meta": {"hexsha": "836781e9e8bca0abadb1d4ec4084b7c36ff6d36e", "size": 38546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/ValueFunctionIter/VFI.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/ValueFunctionIter/VFI.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/ValueFunctionIter/VFI.tex", "max_forks_repo_name": "lcbendall/numerical_computing", "max_forks_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.4435028249, "max_line_length": 135, "alphanum_fraction": 0.731749079, "num_tokens": 11096, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.867035763237924, "lm_q1q2_score": 0.7243941062651987}}
{"text": "\\chapter{Dynamic Programming}\n\\section{Summary}\nDynamic programming is a \\textbf{collection of algorithms} that can be used to find the \\textbf{optimal policy}. It assumes a perfect model of the system (MDP) and uses a lot of computational power. \n\n\\begin{equation}\nv_*(s) = \\max_a \\sum_{s',r} p(s', r | s, a)[r + \\gamma v_*(s')]\n\\label{eq:bellman optimality equation state-value function}\n\\end{equation}\n\n\\begin{equation}\nq_*(s, a) = \\sum_{s', r} p(s', r | s, a) [r + \\gamma \\max_{a'} q_*(s', a')]\n\\label{eq:bellman optimality equation action-value function}\n\\end{equation}\n\n\\subsection{Policy evaluation}\nThe bellman equation from \\ref{eq:bellman equation value function derivation} can be converted into an iterative method called \\textbf{iterative policy evaluation} to find the value function. It takes the expected value over all the same next states. All updates in dynamic programming are called \\textbf{expected updates}, because they are based on expectation over all possible next states rather then the sample next states.\n\n\\begin{equation}\n\\begin{split}\nv(s)_{k+1} \n& = \\EX_\\pi\\left[ R_{t+!} + \\gamma v_k(S_{k+1}) | S_t = s \\right] \\\\\n& = \\sum_a \\pi(a | s) \\sum_{s', r} p(s', r | s, a) \\left[r + \\gamma v(s')\\right] \\\\\n\\end{split}\n\\label{eq:iterative policy evaluation update rule}\n\\end{equation}\n\n\\subsection{Policy improvement}\n\\begin{equation}\n\\begin{split}\nq_\\pi(a, s) & = \\EX\\left[R_{t+1} + \\gamma v_\\pi(S_{t+1}) | S_t = s, A_t = a \\right]\\\\\n& = \\sum_{s', r} p(s', r | s, a)\\big[r + \\gamma v_\\pi(s')\\big]\n\\end{split}\n\\label{eq:policy improvement, select the next action}\n\\end{equation}\n\nGiven a policy $\\pi$ and value function $v_\\pi(s)$, one action $a$ can be selected that maximizes equation~\\ref{eq:policy improvement, select the next action} and all sequential actions follow the policy $\\pi$. The \\textbf{policy improvement theorem}  say's that if a new policy $\\pi'$ satisfies equation~\\ref{eq:policy improvement theorem condition}, the the new policy will satisfy equation~\\ref{eq:policy improvement theorem result}. And be as good or better then the original policy.(proof on page 78-79 of the book)\n\n\\begin{equation}\nq_\\pi(s, \\pi'(s)) \\geq v_\\pi(s)\n\\label{eq:policy improvement theorem condition}\n\\end{equation}\n\n\\begin{equation}\nv_{\\pi}(s) \\leq v_{\\pi'}(s)\n\\label{eq:policy improvement theorem result}\n\\end{equation}\n\nThe new improved policy $\\pi'$ is formally written down in equation~\\ref{eq:greedy policy action-value}. The corresponding value function is formally written down in equation~\\ref{eq:greedy policy value function to bellman equation}. Where we \\textbf{end up with the bellman optimality equation}. Indicating that the policy can improve until it's the optimal policy.\n\n\\begin{equation}\n\\begin{split}\n\\pi'(s) & = \\argmax_a q_\\pi (s, a) \\\\\n& = \\argmax_a \\EX\\left[ R_{t+1} + \\gamma v_\\pi(S_{t+1} | S_t = s, A_t = a) \\right] \\\\\n& = \\argmax_a \\sum_{s',r} p(s', r|s, a)\\left[r + \\gamma v_{\\pi}(s')\\right]\n\\end{split}\n\\label{eq:greedy policy action-value}\n\\end{equation}\n\n\\begin{equation}\n\\begin{split}\nv_{\\pi'}(s) \n& = \\max_a \\EX\\left[ R_{t+1} + \\gamma v_\\pi'(S_{t+1}) | S_t = s, A_t=a \\right] \\\\\n& = \\max_a \\sum_{s', r}p(s', r|s, a)\\left[r + \\gamma v_{\\pi'}(s')\\right]\n\\end{split}\n\\label{eq:greedy policy value function to bellman equation}\n\\end{equation}\n\n\\subsection{Policy iteration}\n\nThe iterative process of evaluating a policy, and then creating a new policy that is greedy towards the old one is called \\textbf{policy iteration}.\n\n\\subsection{Value iteration}\n\nInstead of evaluating the complete policy first, and then improving the policy. The policy can be improved after every state evaluation. Effective \\textbf{turning the bellman optimality equation into the iterative update} of equation~\\ref{eq:value iteration}.\n\n\\begin{equation}\nv_{k+1} = \\max_a = \\sum_{s',r} p(s', r| s, a)\\big[ r + \\gamma v_k(s')\\big]\n\\label{eq:value iteration}\n\\end{equation}\n\n\\subsection{Generalized policy iteration}\nThe iterative process of repeatedly evaluating a policy and using it to create an improved version of that policy, is referred to as \\textbf{generalized policy iteration} or short GPI. Both policy iteration and value iteration are GPI, as do many stochastic methods.\n\n\n\\section{Exercises}\n\n\\subsection{Exercise 4.8}\nThe reward is only obtained when the capital is above 99. When the capital is at 50, there is a 50\\% chance you can win the game. So this obviously is the optimal policy. When you reach 51: it would be rather odd to bet the entire capital, as you don't need to risk it all to reach 100. Bigger downside, but same upside. So the best course of action is to bet with 1, see if you can grow this above 50. If you lose it, you still have a 50\\% chance to win by betting it all.", "meta": {"hexsha": "454587d2e3f80f1fc5293012190a71c24bff9a9c", "size": 4735, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "RL/notes/TeX_files/chapter04.tex", "max_stars_repo_name": "Zilleplus/HML", "max_stars_repo_head_hexsha": "ab9510e27103bb7c14e801606bb25b7c4e17e8ea", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "RL/notes/TeX_files/chapter04.tex", "max_issues_repo_name": "Zilleplus/HML", "max_issues_repo_head_hexsha": "ab9510e27103bb7c14e801606bb25b7c4e17e8ea", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "RL/notes/TeX_files/chapter04.tex", "max_forks_repo_name": "Zilleplus/HML", "max_forks_repo_head_hexsha": "ab9510e27103bb7c14e801606bb25b7c4e17e8ea", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.8068181818, "max_line_length": 520, "alphanum_fraction": 0.7243928194, "num_tokens": 1413, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094304, "lm_q2_score": 0.8354835289107309, "lm_q1q2_score": 0.7243941049028602}}
{"text": "\\newpage\n\\subsection{A new training algorithm}\n%\\begin{figure}[H]\n%\t\\centering\n%\t\\includegraphics[width=3in]{part_logGDfullL.png}   \n%\t\\caption{part of log(Train Loss) for full dataset}\n%\\end{figure}\n\nIf we print the first several steps, we will notice that the loss of Net0 descends the fastest among those networks. After 5-10 steps, it suddenly become the slowest. If at this point we can switch to another curve, then the training process might speed up.\\\\\n\n\\subsection{Regression training}\nActually, there is two ways to achieve this. We may use a very simple regression example to discribe those two methods. We denote our training data as $X\\in \\mathbb{R}^{d_x\\times N}$, the label is $Y\\in \\mathbb{R}^{d_y\\times N}$. Basically, our model is the simplest linear model\n\\begin{equation}\n\tf(x) = Wx,\n\\end{equation}\nand our loss function is \n\\begin{equation}\n\tL(W, D) = \\|WX - Y\\|_F^2.\n\\end{equation}\nFirst, we use \n\\begin{equation}\n\tW = W - lr \\frac{\\partial L}{\\partial W}\n\\end{equation}\nto do several iterations to obtain $\\overline{W}$. Then we have three ways to continue.\\\\\n\\begin{itemize}\n\t\\item Reformulate the problem as \n\t\\begin{equation}\n\t\\min_{U,V} \\|(\\overline{W}+ UV)X - Y\\|_F^2\n\t\\end{equation}\n\twhere $U\\in \\mathbb{R}^{d_y\\times d_1}$, $V\\in\\times \\mathbb{R}^{d_1\\times d_x}$. If the solution of above problem is $\\overline{U}, \\overline{V}$, then our final solution is $W = \\overline{W}+\\overline{U}\\overline{V}$. Notice that if we use a zero initialization in the above problem, the begining loss is $\\|\\overline{W} X - Y\\|_F^2$.\\\\\n\t\\item Factorize $\\overline{W} = U_0 V_0$, where $\\overline{U}_0\\in \\mathbb{R}^{d_y\\times d_1}$, $\\overline{V}_0\\in\\times \\mathbb{R}^{d_1\\times d_x}$. And we use $(U_0,V_0)$ as the initial value for the following problem:\n\t\\begin{equation}\n\t\\min_{U,V} \\|UVX - Y\\|_F^2.\n\t\\end{equation}\n\tIf the solution of above problem is $\\overline{U}, \\overline{V}$, then our final solution is $W = {\\overline{U}}{\\overline{V}}$.\n\\end{itemize}\n\n\\subsection{Classification Training}\nFor classification problem, we have three possible ways to speed up the training algorithms. Define function $l: \\mathbb{R}^{d_x}\\times \\{1,2,\\cdots,d_y\\} \\rightarrow \\mathbb{R}$ as\n\\begin{equation}\n\tl(\\bm s, i) = \\log ({\\bm 1}^T e^{\\bm s}) - s_i,\n\\end{equation}\nwhere $\\bm s = (s_1,s_2,\\cdots,s_{d_y})$. So our final cross-entropy loss can be written as\n\\begin{equation}\n\tL(\\bm\\theta,D) = \\sum_{i = 1}^{d_y} \\sum_{x\\in D_i} l(f(x), i) \n\\end{equation}\nwhere $f$ is the mapping of our model.  \nWe use single-layer and 2-layer linear NN as our examples to state our possible ways to speed up training. For single-layer linear NN we use $W,b$ to represents the weight matrix and bias vector, so $f(x) = Wx + b$. For 2-layer linear NN we use $W_1,W_2,b$ to represents the 2 weight matrices and the bias vector , and $f(x) = W_2 W_1 x + b$ (which implies the first layer is without bias).\\\\\n\nThere are 3 main ideas of speed-up training algorithms.\n\\begin{itemize}\n\t\\item  Use single-layer linear NN and cross-entropy loss to do several iterations to get parameter $\\overline{W}, \\overline{b}$. Then we modify the optimization problem as\n\t\\begin{equation}\n\t\t\\min_{W_1,W_2,b}\\sum_{i = 1}^{d_y} \\sum_{x\\in D_i} l((\\overline{W}+W_2 W_1)x + (\\overline{b}+b), i) \n\t\\end{equation}\n\tIf $\\tilde{W}_1,\\tilde{W}_2,\\tilde{b}$ is one of the solution of the above problem, then our final solution is $W^* = \\overline{W} + \\tilde{W}_2\\tilde{W}_1, b^* = \\overline{b} + \\tilde{b}$.\\\\\n\t\n\t\\item In the second training algorithm, we use a 2-layer linear NN all the time. The loss is \n\t\\begin{equation}\n\t\\sum_{i = 1}^{d_y} \\sum_{x\\in D_i} l(W_2 W_1x + b, i) \n\t\\end{equation}\n\t But in first several steps, we fix the initial $W_1$, only update $W_2$ and $b$. If you regard $W_1 x$ as a whole, we can see we are actually training a single-layer linearNN at the begining. After several steps, we start to update $W_1,W_2,b$ together just as the regular GD.\\\\\n\t \n\t \\item The third idea is, just like the first idea, we use single-layer linear NN and cross-entropy loss to do several iterations to get parameter $\\overline{W}, \\overline{b}$. But after that, we factorize $\\overline{W} = U_0 V_0$, where $\\overline{U}_0\\in \\mathbb{R}^{d_y\\times d_1}$, $\\overline{V}_0\\in\\times \\mathbb{R}^{d_1\\times d_x}$. And we use $W_2 = U_0, W_1 = V_0, b = \\overline{b}$ as the initial value for the following problem:\n\t \\begin{equation}\n\t \\min_{W_1,W_2,b} \\sum_{i = 1}^{d_y} \\sum_{x\\in D_i} l(W_2 W_1x + b, i) .\n\t \\end{equation}\n\n\t \n\\end{itemize}\n\n\\subsubsection{Idea I}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=2.5in]{train1_hidden100.png}\n\t\\caption{New training algorithm 1: $d_1 = 100, lr = 0.1$}\n\\end{figure}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=2.5in]{train1_hidden500.png}\n\t\\caption{New training algorithm 1: $d_1 = 500, lr = 0.1$}\n\\end{figure}\nHere we found that when we switch to the 2-layer model, the descent speed becomes slower.\n\n\\subsubsection{Idea II}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=2.5in]{train2_hidden10.png}\n\t\\caption{New training algorithm 2: $d_1 = 10, lr = 0.1$}\n\\end{figure}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=2.5in]{train2_hidden100.png}\n\t\\caption{New training algorithm 2: $d_1 = 100, lr = 0.1$}\n\\end{figure}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=2.5in]{train2_hidden500.png}\n\t\\caption{New training algorithm 2: $d_1 = 500, lr = 0.1$}\n\\end{figure}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=2.5in]{train2_hidden1000.png}\n\t\\caption{New training algorithm 2: $d_1 = 1000, lr = 0.1$}\n\\end{figure}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=2.5in]{train2_hidden2000_lr1.png}\n\t\\caption{New training algorithm 2: $d_1 = 2000, lr = 0.1$}\n\\end{figure}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=2.5in]{train2_hidden2000_lr05.png}\n\t\\caption{New training algorithm 2: $d_1 = 2000, lr = 0.05$}\n\\end{figure}\n\nHere are some interesting things we can observe:\n\\begin{itemize}\n\t\\item It seems that idea II do have an acceleration at 20th iteration (bacause we start to update all parameters that step), but the descending speed is slower than Net0 in the first 20 steps when the hidden size is less than 500.\n\t\\item When we increase the hidden size to 1000 or 2000, our idea do descend faster than Net0 at the beginning, but slower than Net1. So our idea II seems useless when size of hidden-layer is very large.\n\n\t\n\\end{itemize}\n", "meta": {"hexsha": "5b61e3fbb27b7493b845c81516c44bb299065d5f", "size": 6434, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/New_training.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/New_training.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/New_training.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.8870967742, "max_line_length": 440, "alphanum_fraction": 0.7113770594, "num_tokens": 2243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7243940912314527}}
{"text": "\\chapter{Duals, adjoint, and transposes}\nThis chapter is dedicated to the basis-free interpretation\nof the transpose and conjugate transpose of a matrix.\n\nPoster corollary: we will see that\nsymmetric matrices with real coefficients\nare diagonalizable and have real eigenvalues.\n\n\\section{Dual of a map}\n\\prototype{The example below.}\nWe go ahead and now define a notion\nthat will grow up to be the transpose of a matrix.\n\n\\begin{definition}\n\tLet $V$ and $W$ be vector spaces.\n\tSuppose $T \\colon V \\to W$ is a linear map.\n\tThen we actually get a map\n\t\\begin{align*}\n\t\tT^\\vee \\colon W^\\vee &\\to V^\\vee \\\\\n\t\tf &\\mapsto f \\circ T.\n\t\\end{align*}\n\tThis map is called the \\vocab{dual map}.\n\\end{definition}\n\n\\begin{example}\n\t[Example of a dual map]\n\tWork over $\\RR$.\n\tLet's consider $V$ with basis $e_1$, $e_2$, $e_3$\n\tand $W$ with basis $f_1$, $f_2$.\n\tSuppose that\n\t\\begin{align*}\n\t\tT(e_1) &= f_1 + 2f_2 \\\\\n\t\tT(e_2) &= 3f_1 + 4f_2 \\\\\n\t\tT(e_3) &= 5f_1 + 6f_2.\n\t\\end{align*}\n\tNow consider $V^\\vee$ with its dual basis $e_1^\\vee$,\n\t$e_2^\\vee$, $e_3^\\vee$\n\tand $W^\\vee$ with its dual basis $f_1^\\vee$, $f_2^\\vee$.\n\tLet's compute $T^\\vee(f_1^\\vee) = f_1^\\vee \\circ T$:\n\tit is given by\n\t\\begin{align*}\n\t\tf_1^\\vee \\left( T(ae_1 + be_2 + ce_3) \\right)\n\t\t&= f_1^\\vee\\left( (a+3b+5c) f_1 + (2a+4b+6c) f_2 \\right) \\\\\n\t\t&= a + 3b + 5c.\n\t\\end{align*}\n\tSo accordingly we can write\n\t\\[ T^\\vee(f_1^\\vee) = e_1^\\vee + 3e_2^\\vee + 5e_3^\\vee \\]\n\tSimilarly,\n\t\\[ T^\\vee(f_2^\\vee) = 2e_1^\\vee + 4e_2^\\vee + 6e_3^\\vee. \\]\n\tThis determines $T^\\vee$ completely.\n\\end{example}\nIf we write the matrices for $T$ and $T^\\vee$ in terms of our basis,\nwe now see that\n\\[ T = \\begin{bmatrix}\n\t\t1 & 3 & 5 \\\\\n\t\t2 & 4 & 6\n\t\\end{bmatrix}\n\t\\quad\\text{and}\\quad\n\tT^\\vee = \\begin{bmatrix}\n\t\t1 & 2 \\\\\n\t\t3 & 4 \\\\\n\t\t5 & 6\n\t\\end{bmatrix}.\n\\]\nSo in our selected basis,\nwe find that the matrices are \\vocab{transposes}:\nmirror images of each other over the diagonal.\n\nOf course, this should work in general.\n\\begin{theorem}\n\t[Transpose interpretation of $T^\\vee$]\n\tLet $V$ and $W$ be finite-dimensional $k$-vector spaces.\n\tThen, for any $T \\colon V \\to W$,\n\tthe following two matrices are transposes:\n\t\\begin{itemize}\n\t\t\\ii The matrix for $T \\colon V \\to W$\n\t\texpressed in the basis $(e_i)$, $(f_j)$.\n\t\t\\ii The matrix for $T^\\vee \\colon W^\\vee \\to V^\\vee$\n\t\texpressed in the basis $(f_j^\\vee)$, $(e_i^\\vee)$.\n\t\\end{itemize}\n\\end{theorem}\n\\begin{proof}\n\tThe $(i,j)$th entry of the matrix $T$\n\tcorresponds to the coefficient of $f_j$ in $T(e_i)$,\n\twhich corresponds to the coefficient of $e_i^\\vee$\n\tin $f_j^\\vee \\circ T$.\n\\end{proof}\nThe nice part of this is that the definition of $T^\\vee$ is basis-free.\nSo it means that if we start with any linear map $T$,\nand then pick whichever basis we feel like,\nthen $T$ and $T^\\vee$ will still be transposes.\n\n\\section{Identifying with the dual space}\nFor the rest of this chapter, though,\nwe'll now bring inner products into the picture.\n\nEarlier I complained that there was no natural isomorphism $V \\cong V^\\vee$.\nBut in fact, given an inner form\nwe can actually make such an identification:\nthat is we can naturally associate every linear map\n$\\xi \\colon V \\to k$ with a vector $v \\in V$.\n\nTo see how we might do this, suppose $V = \\RR^3$\nfor now with an orthonormal basis $e_1$, $e_2$, $e_3$.\nHow might we use the inner product to\nrepresent a map from $V \\to \\RR$?\nFor example, take $\\xi \\in V^\\vee$ by\n$\\xi(e_1) = 3$, $\\xi(e_2) = 4$ and $\\xi(e_3) = 5$.\nActually, I claim that\n\\[ \\xi(v) = \\left< v, 3e_1 + 4e_2 + 5e_3 \\right> \\]\nfor every $v$.\n\\begin{ques}\n\tCheck this.\n\\end{ques}\n\nAnd this works beautifully in the real case.\n\\begin{theorem}[$V \\cong V^\\vee$ for real inner form]\n\t\\label{thm:real_dual_isomorphic}\n\tLet $V$ be a finite-dimensional \\emph{real}\n\tinner product space and $V^\\vee$ its dual.\n\tThen the map $V \\to V^\\vee$ by\n\t\\[ v \\mapsto \\left<  -, v \\right> \\in V^\\vee \\]\n\tis an isomorphism of real vector spaces.\n\\end{theorem}\n\\begin{proof}\n\tIt suffices to show that the map is injective and surjective.\n\t\\begin{itemize}\n\t\t\\ii Injective: suppose $\\left< v_1, v \\right> = \\left< v_2, v \\right>$\n\t\tfor every vector $v \\in V$.\n\t\tThis means $\\left< v_1 - v_2, v \\right> = 0$ for every vector $v \\in V$.\n\t\tThis can only happen if $v_1 - v_2 = 0$; for example, take $v = v_1 - v_2$\n\t\tand use positive definiteness.\n\t\t\\ii Surjective: take an orthonormal basis $e_1$, \\dots $e_n$\n\t\tand let $e_1^\\vee$, \\dots, $e_n^\\vee$ be the dual basis on $V^\\vee$.\n\t\tThen $e_1$ maps to $e_1^\\vee$, et cetera.\n\t\t\\qedhere\n\t\\end{itemize}\n\\end{proof}\nActually, since we already know $\\dim V = \\dim V^\\vee$\nwe only had to prove one of the above.\nAs a matter of personal taste, I find the proof of injectivity more elegant,\nand the proof of surjectivity more enlightening,\nso I included both.\nThus\n\\begin{moral}\n\tIf a real inner product space $V$ is given an inner form,\n\tthen $V$ and $V^\\vee$ are canonically isomorphic.\n\\end{moral}\n\nUnfortunately, things go awry if $V$ is complex.\nHere is the results:\n\\begin{theorem}[$V$ versus $V^\\vee$ for complex inner forms]\n\tLet $V$ be a finite-dimensional \\emph{complex}\n\tinner product space and $V^\\vee$ its dual.\n\tThen the map $V \\to V^\\vee$ by\n\t\\[ v \\mapsto \\left<  -, v \\right> \\in V^\\vee \\]\n\tis a bijection of sets.\n\\end{theorem}\nWait, what? Well, the proof above shows that it is both injective\nand surjective, but why is it not an isomorphism?\nThe answer is that it is not a linear map:\nsince the form is sesquilinear we have for example\n\\[ iv \\mapsto \\left< -, iv\\right> = -i \\left< -, v\\right> \\]\nwhich has introduced a minus sign!\nIn fact, it is an \\emph{anti-linear} map, in the sense we defined before.\n\nEager readers might try to fix this by defining\nthe isomorphism $v \\mapsto \\left< v, - \\right>$ instead.\nHowever, this also fails, because the right-hand side\nis not even an element of $V^\\vee$:\nit is an ``anti-linear'', not linear.\n\nAnd so we are stuck.\nFortunately, we will only need the ``bijection'' result\nfor what follows, so we can continue on anyways.\n(If you want to fix this, \\Cref{prob:complex_conj_space}\ngives a way to do so.)\n\n\n\\section{The adjoint (conjugate transpose)}\nWe will see that, as a result of the flipping above,\nthe \\emph{conjugate transpose} is actually the better concept\nfor inner product spaces: since it can be defined using only the inner product\nwith making mention to dual spaces at all.\n\\begin{definition}\n\tLet $V$ and $W$ be finite-dimensional inner product spaces,\n\tand let $T \\colon V \\to W$.\n\tThe \\vocab{adjoint} (or \\vocab{conjugate transpose})\n\tof $T$, denoted $T^\\dagger \\colon W \\to V$,\n\tis defined as follows: for every vector $w \\in W$,\n\twe let $T^\\dagger(w) \\in V$ be the unique vector with\n\t\\[ \\left< v, T^\\dagger(w) \\right>_V = \\left< T(v), w \\right>_W \\]\n\tfor every $v \\in V$.\n\\end{definition}\n\nSome immediate remarks about this definition:\n\\begin{itemize}\n\\ii Our $T^\\dagger$ is well-defined,\nbecause $\\left< T(-), w \\right>_W$ is some function in $V^\\vee$,\nand hence by the bijection earlier\nit should be uniquely of the form $\\left< -, v \\right>$ for some $v \\in V$.\n\\ii This map $T^\\dagger$ is indeed a linear map (why?).\n\\ii The niceness of this definition is that it doesn't\nmake reference to any basis or even $V^\\vee$,\nso it is the ``right'' definition for a inner product space.\n\\ii By symmetry, of course, we also have\n$\\left< T^\\dagger(v), w \\right> = \\left< v, T(w)\\right>$.\n\\end{itemize}\n\n\\begin{example}\n\t[Example of an adjoint map]\n\tWe'll work over $\\CC$, so the conjugates are more visible.\n\tLet's consider $V$ with orthonormal basis $e_1$, $e_2$, $e_3$\n\tand $W$ with orthonormal basis $f_1$, $f_2$.\n\tWe put\n\t\\begin{align*}\n\t\tT(e_1) &= if_1 + 2f_2 \\\\\n\t\tT(e_2) &= 3f_1 + 4f_2 \\\\\n\t\tT(e_3) &= 5f_1 + 6if_2.\n\t\\end{align*}\n\tWe compute $T^\\dagger(f_1)$.\n\tIt is the unique vector $x \\in V$ such that\n\t\\[ \\left< v, x \\right>_V = \\left< T(v), f_1 \\right>_W \\]\n\tfor any $v \\in V$.\n\tIf we expand $v = ae_1 + be_2 + ce_3$ the above equality becomes\n\t\\begin{align*}\n\t\t\\left< ae_1 + be_2 + ce_3, x \\right>_V\n\t\t&= \\left< T(ae_1 + be_2 + ce_3), f_1 \\right>_W \\\\\n\t\t&= ia + 3b + 5c.\n\t\\end{align*}\n\tHowever, since $x$ is in the second argument,\n\tthis means we actually want to take\n\t\\[ T^\\dagger(f_1) = -ie_1 + 3e_2 + 5e_3 \\]\n\tso that the sesquilinearity will conjugate the $i$.\n\\end{example}\n\n\nThe pattern continues, though we remind the reader that\nwe need the basis to be orthonormal to proceed.\n\\begin{theorem}\n\t[Adjoints are conjugate transposes]\n\tFix an \\emph{orthonormal} basis of a finite-dimensional inner product space $V$.\n\tLet $T \\colon V \\to V$ be a linear map.\n\tIf we write $T$ as a matrix in this basis,\n\tthen the matrix $T^\\dagger$ (in the same basis)\n\tis the \\emph{conjugate transpose} of the matrix of $T$;\n\tthat is, the $(i,j)$th entry of $T^\\vee$\n\tis the complex conjugate of the $(j,i)$th entry of $T$.\n\\end{theorem}\n\\begin{proof}\n\tOne-line version: take $v$ and $w$ to be basis elements,\n\tand this falls right out.\n\n\tFull proof: let\n\t\\[ T = \\begin{bmatrix}\n\t\t\ta_{11} & \\dots & a_{1n} \\\\\n\t\t\t\\vdots & \\ddots & \\vdots \\\\\n\t\t\ta_{n1} & \\dots & a_{nn}\n\t\t\\end{bmatrix} \\]\n\tin this basis $e_1$, \\dots, $e_n$.\n\tThen, letting $w = e_i$ and $v = e_j$ we deduce that\n\t\\[ \\left< e_i, T^\\dagger(e_j) \\right> = \\left< T(e_i) , e_j\\right> = a_{ji}\n\t\t\\implies\n\t\t\\left< T^\\dagger(e_j), e_i \\right> = \\ol{a_{ji}} \\]\n\tfor any $i$, which is enough to deduce the result.\n\\end{proof}\n\n\\section{Eigenvalues of normal maps}\nWe now come to the advertised theorem.\nRestrict to the situation where $T \\colon V \\to V$.\nYou see, the world would be a very beautiful place if it turned out\nthat we could pick a basis of eigenvectors that was also \\emph{orthonormal}.\nThis is of course far too much to hope for;\neven without the orthonormal condition,\nwe saw that Jordan form could still have $1$'s off the diagonal.\n\nHowever, it turns out that there is\na complete characterization of exactly when our overzealous dream is true.\n\n\\begin{definition}\n\tWe say a linear map $T$\n\t(from a finite-dimensional inner product space to itself)\n\tis \\vocab{normal} if $TT^\\dagger = T^\\dagger T$.\n\n\tWe say a complex $T$ is \\vocab{self-adjoint} or \\vocab{Hermitian} if $T = T^\\dagger$;\n\ti.e.\\ as a matrix in any orthonormal basis, $T$ is its own conjugate transpose.\n\tFor real $T$ we say ``self-adjoint'', ``Hermitian'' or \\vocab{symmetric}.\n\\end{definition}\n\\begin{theorem}\n\t[Normal $\\iff$ diagonalizable with orthonormal basis]\n\tLet $V$ be a finite-dimensional complex inner product space.\n\tA linear map $T \\colon V \\to V$ is normal\n\tif and only if one can pick an orthonormal basis of eigenvectors.\n\\end{theorem}\n\\begin{exercise}\n\tShow that if there exists such an orthonormal basis\n\tthen $T \\colon V \\to V$ is normal,\n\tby writing $T$ as a diagonal matrix in that basis.\n\\end{exercise}\n\\begin{proof}\n\tThis is long, and maybe should be omitted on a first reading.\n\tIf $T$ has an orthonormal basis of eigenvectors,\n\tthis result is immediate.\n\n\tNow assume $T$ is normal.\n\tWe first prove $T$ is diagonalizable; this is the hard part.\n\t\\begin{claim}\n\t\tIf $T$ is normal, then $\\ker T = \\ker T^r = \\ker T^\\dagger$ for $r \\ge 1$.\n\t\t(Here $T^r$ is $T$ applied $r$ times.)\n\t\\end{claim}\n\t\\begin{subproof}\n\t\t[Proof of Claim]\n\t\tLet $S = T^\\dagger \\circ T$, which is self-adjoint.\n\t\tWe first note that $S$ is Hermitian and $\\ker S = \\ker T$.\n\t\tTo see it's Hermitian, note\n\t\t$\\left<Sv, w \\right> = \\left<Tv, Tw \\right> = \\left<v, S w \\right>$.\n\t\tTaking $v = w$ also implies $\\ker S \\subseteq \\ker T$\n\t\t(and hence equality since obviously $\\ker T \\subseteq \\ker S$).\n\n\t\tFirst, since we have $\\left< S^r(v), S^{r-2}(v) \\right>\n\t\t= \\left< S^{r-1}(v), S^{r-1}(v)\\right>$,\n\t\tan induction shows that $\\ker S = \\ker S^r$ for $r \\ge 1$.\n\t\tNow, since $T$ is normal, we have $S^r = (T^\\dagger)^r \\circ T^r$,\n\t\tand thus we have the inclusion\n\t\t\\[ \\ker T \\subseteq \\ker T^r \\subseteq \\ker S^r = \\ker S = \\ker T \\]\n\t\twhere the last equality follows from the first claim.\n\t\tThus in fact $\\ker T = \\ker T^r$.\n\n\t\tFinally, to show equality with $\\ker T^\\dagger$ we \n\t\t\\begin{align*}\n\t\t\t\\left< Tv, Tv\\right> &= \\left< v, T^\\dagger T v\\right> \\\\\n\t\t\t&= \\left< v, T T^\\dagger v \\right> \\\\\n\t\t\t&= \\left< T^\\dagger v, T^\\dagger v \\right>. \\qedhere\n\t\t\\end{align*}\n\t\\end{subproof}\n\n\tNow consider the given $T$, and any $\\lambda$.\n\t\\begin{ques}\n\t\tShow that $(T - \\lambda\\id)^\\dagger = T^\\dagger - \\ol\\lambda \\id$.\n\t\tThus if $T$ is normal, so is $T - \\lambda \\id$.\n\t\\end{ques}\n\tIn particular, for any eigenvalue $\\lambda$ of $T$,\n\twe find that $\\ker (T-\\lambda\\id) = \\ker(T-\\lambda\\id)^r$.\n\tThis implies that all the Jordan blocks of $T$ have size $1$;\n\ti.e.\\ that $T$ is in fact diagonalizable.\n\tFinally, we conclude that the eigenvectors of $T$ and $T^\\dagger$ match,\n\tand the eigenvalues are complex conjugates.\n\n\tSo, diagonalize $T$.\n\tWe just need to show that if $v$ and $w$ are eigenvectors of $T$\n\twith distinct eigenvalues, then they are orthogonal.\n\t(We can use Gram-Schmidt on any eigenvalue that appears multiple times.)\n\tTo do this, suppose $T(v) = \\lambda v$ and $T(w) = \\mu w$\n\t(thus $T^\\dagger(w) = \\ol\\mu w $).\n\tThen\n\t\\[ \\lambda \\left< v,w\\right>\n\t\t= \\left< \\lambda v, w\\right>\n\t\t= \\left< Tv, w\\right>\n\t\t= \\left< v, T^\\dagger(w)\\right>\n\t\t= \\left< v, \\ol \\mu w \\right> \n\t\t= \\mu \\left< v, w\\right>. \\]\t\t\n\tSince $\\lambda \\neq \\mu$, we conclude $\\left< v,w \\right> = 0$.\n\\end{proof}\nThis means that not only can we write\n\\[ T = \\begin{bmatrix}\n\t\t\\lambda_1 & \\dots & \\dots & 0 \\\\\n\t\t0 & \\lambda_2 & \\dots & 0 \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\t0 & 0 & \\dots & \\lambda_n\n\t\\end{bmatrix}\n\\]\nbut moreover that the basis associated with this matrix happens to be orthonormal vectors.\n\nAs a corollary:\n\\begin{theorem}[Hermitian matrices have real eigenvalues]\n\tA Hermitian matrix $T$ is diagonalizable,\n\tand all its eigenvalues are real.\n\\end{theorem}\n\\begin{proof}\n\tObviously Hermitian $\\implies$ normal,\n\tso write it in the orthonormal basis of eigenvectors.\n\tTo see that the eigenvalues are real, note that $T = T^\\dagger$\n\tmeans $\\lambda_i = \\ol{\\lambda_i}$ for every $i$.\n\\end{proof}\n\n\\section{\\problemhead}\n\\begin{sproblem}\n\t[Double dual]\n\t\\gim\n\t\\label{prob:double_dual}\n\tLet $V$ be a finite-dimensional vector space.\n\tProve that\n\t\\begin{align*}\n\t\tV &\\to (V^\\vee)^\\vee \\\\\n\t\tv &\\mapsto \\left( \\xi \\mapsto \\xi(v) \\right)\n\t\\end{align*}\n\tgives an isomorphism.\n\t(This is significant because the isomorphism is \\emph{canonical},\n\tand in particular does not depend on the choice of basis.\n\tSo this is more impressive.)\n\t\\begin{hint}\n\t\tYou can \\emph{prove} the result just by taking a basis\n\t\t$e_1$, \\dots, $e_n$ of $V$\n\t\tand showing that it is a linear map sending $e_1$\n\t\tto the basis $(e_1^\\vee)^\\vee$.\n\t\\end{hint}\n\\end{sproblem}\n\n\\begin{problem}\n\t[Fundamental theorem of linear algebra]\n\tLet $T \\colon V \\to W$ be a map of finite-dimensional $k$-vector spaces.\n\tProve that\n\t\\[ \\dim \\img T = \\dim \\img T^\\vee\n\t\t= \\dim V - \\dim \\ker T = \\dim W - \\dim \\ker T^\\vee. \\]\n\t\\begin{hint}\n\t\tUse \\Cref{thm:linear_map_basis} and it will be immediate\n\t\t(the four quantities equal the $k$ in the theorem).\n\t\\end{hint}\n\t\\begin{sol}\n\t\tBy \\Cref{thm:linear_map_basis},\n\t\twe may select $e_1$, \\dots, $e_n$ a basis of $V$\n\t\tand $f_1$, \\dots, $f_m$ a basis of $W$\n\t\tsuch that $T(e_i) = f_i$ for $i \\le k$\n\t\tand $T(e_i) = 0$ for $i > k$.\n\t\tThen $T^\\vee(f_i^\\vee) = e_i^\\vee$ for $i \\le k$\n\t\tand $T^\\vee(f_i^\\vee) = 0$ for $i > k$.\n\t\tAll four quantities are above are then equal to $k$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{dproblem}\n\t[Row rank is column rank]\n\tA $m \\times n$ matrix $M$ of real numbers is given.\n\tThe \\emph{column rank} of $M$ is the dimension of the span in $\\RR^m$\n\tof its $n$ column vectors.\n\tThe \\emph{row rank} of $M$ is the dimension of the span in $\\RR^n$\n\tof its $m$ row vectors.\n\tProve that the row rank and column rank are equal.\n\t\\begin{hint}\n\t\tThis actually is just the previous problem in disguise!\n\t\tThe row rank is $\\dim \\img T^\\vee$\n\t\tand the column rank is $\\dim \\ker T$.\n\t\\end{hint}\n\\end{dproblem}\n\n\\begin{problem}\n\t[The complex conjugate spaces]\n\t\\label{prob:complex_conj_space}\n\tLet $V = (V, +, \\cdot)$ be a complex vector space.\n\tDefine the \\vocab{complex conjugate vector space},\n\tdenoted $\\ol V = (V, +, \\ast)$\n\tby changing just the multiplication:\n\t\\[ c \\ast v = \\ol c \\cdot V. \\]\n\tShow that for any sesquilinear form on $V$,\n\tif $V$ is finite-dimensional, then\n\t\\begin{align*}\n\t\t\\ol V & \\to V^\\vee \\\\\n\t\tv &\\mapsto \\left< -, v \\right> \n\t\\end{align*}\n\tis an isomorphism of complex vector spaces.\n\\end{problem}\n\n\\begin{problem}\n\t[$T^\\dagger$ vs $T^\\vee$]\n\tLet $V$ and $W$ be real inner product spaces\n\tand let $T \\colon V \\to W$ be an inner product.\n\tShow that the following diagram commutes:\n\t\\begin{center}\n\t\\begin{tikzcd}\n\t\tW \\ar[r, \"T^\\dagger\"] \\ar[d, \"\\cong\"']\n\t\t\t& V \\ar[d, \"\\cong\"] \\\\\n\t\tW^\\vee \\ar[r, \"T^\\vee\"']  & V^\\vee\n\t\\end{tikzcd}\n\t\\end{center}\n\tHere the isomorphisms are $v \\mapsto \\left< -, v\\right>$.\n\tThus, for real inner product spaces,\n\t$T^\\dagger$ is just $T^\\vee$ with the duals eliminated\n\t(by \\Cref{thm:real_dual_isomorphic}).\n\\end{problem}\n\n\\begin{problem}\n\t[Polynomial criteria for normality]\n\tLet $V$ be a complex inner product space\n\tand let $T \\colon V \\to V$ be a linear map.\n\tShow that $T$ is normal if and only if\n\tthere is a polynomial\\footnote{Here,\n\t\t$p(T)$ is meant in the same composition\n\t\tsense as in Cayley-Hamilton.}\n\t$p \\in \\CC[t]$ such that \\[ T^\\dagger = p(T). \\]\n\t\\begin{hint}\n\t\tIf there is a polynomial, check $TT^\\dagger = T^\\dagger T$ directly.\n\t\tIf $T$ is normal, diagonalize it.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tFirst, suppose $T^\\ast = p(T)$.\n\t\tThen $T^\\ast T = p(T) \\cdot T = T \\cdot p(T) = T T^\\ast$ and we're done.\n\n\t\tConversely, suppose $T$ is diagonalizable\n\t\tin a way compatible with the inner form\n\t\t(OK since $V$ is finite dimensional).\n\t\tConsider the orthonormal basis.\n\t\tThen $T$ consists of eigenvalues on the main diagonals\n\t\tand zeros elsewhere, say\n\t\t\\[ T = \\left(\n\t\t\t\\begin{array}{cccc}\n\t\t\t\t\\lambda_1 & 0 & \\dots & 0 \\\\\n\t\t\t\t0 & \\lambda_2 & \\dots & 0 \\\\\n\t\t\t\t\\vdots & \\vdots & \\ddots &  \\vdots \\\\\n\t\t\t\t0 & 0 & \\dots & \\lambda_n\n\t\t\t\\end{array}\n\t\t\t\\right). \\]\n\t\tIn that case, we find that for any polynomial $q$ we have\n\t\t\\[ q(T) = \\left(\n\t\t\t\\begin{array}{cccc}\n\t\t\t\tq(\\lambda_1) & 0 & \\dots & 0 \\\\\n\t\t\t\t0 & q(\\lambda_2) & \\dots & 0 \\\\\n\t\t\t\t\\vdots & \\vdots & \\ddots &  \\vdots \\\\\n\t\t\t\t0 & 0 & \\dots & q(\\lambda_n)\n\t\t\t\\end{array}\n\t\t\t\\right). \\]\n\t\tand\n\t\t\\[ T^\\ast = \\left(\n\t\t\t\\begin{array}{cccc}\n\t\t\t\t\\ol{\\lambda_1} & 0 & \\dots & 0 \\\\\n\t\t\t\t0 & \\ol{\\lambda_2} & \\dots & 0 \\\\\n\t\t\t\t\\vdots & \\vdots & \\ddots &  \\vdots \\\\\n\t\t\t\t0 & 0 & \\dots & \\ol{\\lambda_n}\n\t\t\t\\end{array}\n\t\t\t\\right). \\]\n\t\tSo we simply require a polynomial $q$\n\t\tsuch that $q(\\lambda_i) = \\ol{\\lambda_i}$ for every $i$.\n\t\tSince there are finitely many $\\lambda_i$,\n\t\twe can construct such a polynomial using Lagrange interpolation.\n\t\\end{sol}\n\\end{problem}\n", "meta": {"hexsha": "80b6281d49ab718d4e75b41c35652414c80c11e9", "size": 18809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/linalg/transpose.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/linalg/transpose.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/linalg/transpose.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.0914179104, "max_line_length": 90, "alphanum_fraction": 0.6640438088, "num_tokens": 6664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107309, "lm_q2_score": 0.8670357460591569, "lm_q1q2_score": 0.7243940848092527}}
{"text": "\\section{Polygons}\nIn this section we will discuss basic tasks on polygons: how to find their area and two ways to detect if a point is inside or outside them.\n\n\\subsection{Polygon area}\\label{ss:polygon-area}\nTo compute the area of a polygon, it is useful to first consider the area of a triangle $ABC$.\n\n\\centerFig{polygon0}\n\nWe know that the area of this triangle is $\\frac{1}{2} |AB| |AC| \\sin\\theta$, because $|AC| \\sin\\theta$ is the length of the height coming down from $C$. This looks a lot like the definition of cross product: in fact,\n\\[\\frac{1}{2} |AB| |AC| \\sin\\theta = \\frac{1}{2} \\left|\\crossv{AC}{AC}\\right|\\]\n\nSince $O$ is the origin, it can be implemented simply like this:\n\\begin{lstlisting}\ndouble areaTriangle(pt a, pt b, pt c) {\n    return abs(cross(b-a, c-a)) / 2.0;\n}\n\\end{lstlisting}\n\nNow that we can compute the area of a triangle, the intuitive way to find the area of a polygon would be to\n\\begin{enumerate}\n\\item divide the polygon into triangles;\n\\item add up all the areas.\n\\end{enumerate}\n\nHowever, it turns out that reliably dividing a polygon into triangles is a difficult problem in itself. So instead we'll add and subtract triangle areas in a clever way. Let's take this quadrilateral as an example:\n\\centerFig{polygon1}\n\nLet's take an arbitrary reference point $O$. Let's consider the vertices of $ABCD$ in order, and for every pair of consecutive points $P_1,P_2$, we'll add the area of $OP_1P_2$ to the total if $\\vv{P_1P_2}$ goes counter-clockwise around $O$, and subtract it otherwise. Additions are marked in blue and subtractions in red.\n\\centerFig{polygon2}\n\nWe can see that this will indeed compute the area of quadrilateral $ABCD$. In fact, it works for any polygon (draw a few more examples to convince yourself).\n\nNote that the sign (add or subtract) that we take for the area of $OP_1P_2$ is exactly the sign that the cross product takes. If we take the origin as reference point $O$, it gives this simple implementation:\n\\begin{lstlisting}\ndouble areaPolygon(vector<pt> p) {\n    double area = 0.0;\n    for (int i = 0, n = p.size(); i < n; i++) {\n        area += cross(p[i], p[(i+1)%n]); // wrap back to 0 if i == n-1\n    }\n    return abs(area) / 2.0;\n}\n\\end{lstlisting}\nWe have to take the absolute value in case the vertices are given in clockwise order. In fact, testing the sign of \\lstinline|area| is a good way to know whether the vertices are in counter-clockwise (positive) or clockwise (negative) order. It is good practice to always put your polygons in counter-clockwise order, by reversing the array of vertices if necessary, because some algorithms on polygons use this property.\n\n\\subsection{Cutting-ray test}\nLet's say we want to test if a point $A$ is inside a polygon $P_1 \\cdots P_n$. Then one way to do it is to draw an imaginary ray from $A$ that extends to infinity, and check how many times this ray intersects $P_1 \\cdots P_n$. If the number of intersections is odd, $A$ is inside, and if it is even, $A$ is outside.\n\n\\centerFig{polygon3}\n%For example, in the figure above, the ray from $A_1$ has 3 intersections with the polygon so $A_1$ is inside, while the ray from $A_2$ has 2 intersections with the polygon so $A_2$ is outside.\n\nHowever, sometimes this can go wrong if the ray touches a vertex of the polygon, as below. The ray from $A_3$ intersects the polygon twice, but $A_3$ is inside. We can try to solve the issue by counting one intersection per segment touched, which would give three intersections for $A_3$, but then the ray from $A_4$ will intersect the polygon twice even though $A_4$ is inside.\n\n\\centerFig{polygon4}\n\nSo we need to be more careful in defining what counts as an intersection. We will split the plane into two halves along the ray: the points lower than $A$, and the points at least as high (blue region). We then say that a segment $[P_iP_{i+1}]$ crosses the ray right of $A$ if it touches it \\emph{and} $P_i$ and $P_{i+1}$ are on opposite halves.\n\n\\centerFig{polygon5}\n\nBelow we show for some segments whether they are considered to cross the ray or not. We can see in the last two examples that the behavior is different if the segment touches the ray from below or from above.\n\n\\begin{center}\n\\includeFig{polygon6}\n\\includeFig{polygon11}\n\\end{center}\n\n\\exo{Verify that, with this new definition of crossing, $A_3$ and $A_4$ are correctly detected to be inside the polygon.}\n\nChecking the halves to which the points belong is easy, but checking that the segment touches the ray is a bit more tricky. We could check whether the segments $[P_i,P_{i+1}]$ and $[AB]$ intersect for $B$ very far on the ray, but it actually we can do it more simply using $\\orient$: if $P_i$ is below and $P_{i+1}$ above, then $\\orient(A,P_i,P_{i+1})$ should be positive, and otherwise it should be negative.\nWe can then implement this with the code below:\n\\begin{lstlisting}\n// true if P at least as high as A (blue part)\nbool above(pt a, pt p) {\n    return p.y >= a.y;\n}\n// check if [PQ] crosses ray from A\nbool crossesRay(pt a, pt p, pt q) {\n    return (above(a,q) - above(a,p)) * orient(a,p,q) > 0;\n}\n\\end{lstlisting}\n\nIf we now return to the original problem, we still have to check whether $A$ is on the boundary of the polygon. We can do that by using \\lstinline|onSegment()| defined in \\ref{onsegment}.\n\\begin{lstlisting}\n// if strict, returns false when A is on the boundary\nbool inPolygon(vector<pt> p, pt a, bool strict = true) {\n    int numCrossings = 0;\n    for (int i = 0, n = p.size(); i < n; i++) {\n        if (onSegment(p[i], p[(i+1)%n], a))\n            return !strict;\n        numCrossings += crossesRay(a, p[i], p[(i+1)%n]);\n    }\n    return numCrossings & 1; // inside if odd number of crossings\n}\n\\end{lstlisting}\n\n\\subsection{Winding number}\\label{ss:wind-2d}\nAnother way to test if $A$ is inside polygon $P_1 \\cdots P_n$ is to think of a string with one end attached at $A$ and the other following the boundary of the polygon, doing one turn. If between the start position and the end position the string has done a full turn, then we are inside the polygon. If however the direction string has simply oscillated around the same position, then we are outside the polygon. Another way to test it is to place one finger on point $A$ while another one follows the boundary of the polygon, and see if the fingers are twisted at the end.\n\nThis idea can be generalized to the \\emph{winding number}. The winding number of a closed curve around a point is the number of times this curve turns counterclockwise around the point. Here is an example.\n\n\\centerFig{polygon7}\n\nPoints $A_1$ and $A_2$ are completely out of the curve so the winding number around them is $0$ (no turn). Points $A_3$ and $A_4$ are inside the main loop, which goes counterclockwise, so the winding number around them is $1$. The curve turns twice counterclockwise around $A_5$, so the winding number is $2$. Finally the curve goes clockwise around $A_6$, for a winding number of $-1$.\n\n\\begin{mathy}\nIn fact, we can move the curve continuously without changing the winding number as long as we don't touch the reference point. Therefore we can ``untie'' loops which don't contain the point. That's why, when looking at $A_3$ or $A_4$, we can completely ignore the loops that contain $A_5$ and $A_6$.\n\\end{mathy}\n\n\\begin{mathy}\nIf we move the reference point while keeping the curve unchanged, the value of the winding number will only change when it crosses the curve. If it crosses the curve from the right (according to its orientation), the winding number increases by 1, and if it crosses it from the left, the winding number decreases by 1.\n\n\\centerFig{polygon8}\n\\end{mathy}\n\n\\exoWithSolution{\n    What value will \\lstinline|areaPolygon()| (section~\\ref{ss:polygon-area}) give when applied to a closed polyline that crosses itself, like the curve above, instead of a simple polygon? Assume we don't take the absolute value.\n}{\n    It will give the sum of the areas of the parts delimited by the curve, multiplied by their corresponding winding numbers. For the curve below, it will give the sum of:\n    \\protect\\begin{itemize}\n    \\protect\\item $1\\ \\times$ the area of the part containing $A_3$ and $A_4$;\n    \\protect\\item $2\\ \\times$ the area of the part containing $A_5$;\n    \\protect\\item $-1\\ \\times$ the area of the part containing $A_6$.\n    \\protect\\end{itemize}\n    \n    \\protect\\centerFig{polygon7}\n}{area-crossing}\n\nTo compute the winding number, we need to keep track of the amplitude travelled, positive if counterclockwise, and negative if clockwise. We can use \\lstinline|angle()| from section~\\ref{ss:dot} to help us.\n\\begin{lstlisting}\n// amplitude travelled around point A, from P to Q\ndouble angleTravelled(pt a, pt p, pt q) {\n    double ampli = angle(p-a, q-a);\n    if (orient(a,p,q) > 0) return ampli;\n    else return -ampli;\n}\n\\end{lstlisting}\n\nAnother way to implement it uses the arguments of points:\n\\begin{lstlisting}\ndouble angleTravelled(pt a, pt p, pt q) {\n    // remainder ensures the value is in [-pi,pi]\n    return remainder(arg(q-a) - arg(p-a), 2*M_PI);\n}\n\\end{lstlisting}\n\nThen we simply sum it all up and figure out how many turns were made:\n\\begin{lstlisting}\nint windingNumber(vector<pt> p, pt a) {\n    double ampli = 0;\n    for (int i = 0, n = p.size(); i < n; i++)\n        ampli += angleTravelled(a, p[i], p[(i+1)%n]);\n    return round(ampli / (2*M_PI));\n}\n\\end{lstlisting}\n\n\\begin{warning}\nThe winding number is not defined if the reference point is on the curve/polyline. If it is the case, this code will give arbitrary results, and potentially \\lstinline|(int)NAN|.\n\\end{warning}\n\n\\subsubsection{Angles of integer points}\nWhile the code above works, its use of floating-point numbers makes it non ideal, and when coordinates are integers, we can do better. We will define a new way to work with angles, as a type \\lstinline|angle|. This type will also be useful for other tasks, such as for sweep angle algorithms.\n\nInstead of working with amplitudes directly, we will represent angles by a point and a certain number of full turns.\\footnote{This approach is based on an original idea in \\cite{kactl}, see ``Angle.h''.} More precisely, in this case, we will use point $(x,y)$ and number of turns $t$ to represent angle $\\atanTwo(y,x) + \\turn t$.\n\nWe start by defining the new type \\lstinline|angle|. We also define a utility function \\lstinline|t360()| which turns an angle by a full turn.\n\\begin{lstlisting}\nstruct angle {\n    pt d; int t = 0; // direction and number of full turns\n    angle t180(); // to be defined later\n    angle t360() {return {d, t+1};}\n};\n\\end{lstlisting}\nThe range of angles which have the same value for $t$ is $(-\\half + \\turn t, \\half + \\turn t]$.\n\nWe will now define a comparator between angles. The approach is the same as what we did for the polar sort in section~\\ref{polar-sort}, so we will reuse the function \\lstinline|half()| which separates the plane into two halves so that angles within one half are easily comparable:\n\\begin{lstlisting}\nbool half(pt p) {\n    return p.y > 0 || (p.y == 0 && p.x < 0);\n}\n\\end{lstlisting}\n\nIt returns \\lstinline|true| for the part highlighted in blue and \\lstinline|false| otherwise. Thus, in practice, it allows us to separate each range $(-\\half + \\turn t, \\half + \\turn t]$ into the subranges $(-\\half + \\turn t, \\turn t]$, for which \\lstinline|half()| returns \\lstinline|false|, and $(\\turn t, \\half + \\turn t]$, for which \\lstinline|half()| returns \\lstinline|true|.\n\\centerFig{polygon9}\n\nWe can now write the comparator between angles, which is nearly identical to the one we used for polar sort, except that we first check the number of full turns \\lstinline|t|.\n\\begin{lstlisting}\nbool operator<(angle a, angle b) {\n    return make_tuple(a.t, half(a.d), 0) <\n           make_tuple(b.t, half(b.d), cross(a.d,b.d));\n}\n\\end{lstlisting}\n\nWe also define the function \\lstinline|t180()| which turns an angle by half a turn counterclockwise. The resulting angle has an opposite direction. To find the number of full turns $t$, there are two cases:\n\\begin{itemize}\n\\item if \\lstinline|half(d)| is \\lstinline|false|, we are in the lower half $(-\\half + \\turn t, \\turn t]$, and we will move to the upper half $(\\turn t, \\half + \\turn t]$, without changing $t$;\n\\item if \\lstinline|half(d)| is \\lstinline|true|, we are in the upper half $(\\turn t, \\half + \\turn t]$, and we will move to $(-\\half + \\turn (t+1), \\turn (t+1)]$, the lower half for $t+1$.\n\\end{itemize}\n\\begin{lstlisting}\nangle t180() {return {d*(-1), t + half(d)};}\n\\end{lstlisting}\n\nWe will now implement the function that will allow us to compute the winding number. Consider an angle with direction point $D$. Given a new direction $D'$, we would like to move the angle in such a way that if direction $D'$ is to the left of $D$, the angle increases, and if $D'$ is to the right of $D$, the angle decreases.\n\n\\centerFig{polygon10}\n\nIn other words, we want the new angle to be an angle with direction $D'$, and such that the difference between it and the old angle is at most $180\\degree$. We will use this formulation to implement the function:\n\\begin{lstlisting}\nangle moveTo(angle a, pt newD) {\n    // check that segment [DD'] doesn't go through the origin\n    assert(!onSegment(a.d, newD, {0,0}));\n    \n    angle b{newD, a.t};\n    if (a.t180() < b) // if b more than half a turn bigger\n        b.t--;        //     decrease b by a full turn\n    if (b.t180() < a) // if b more than half a turn smaller\n        b.t++;        //     increase b by a full turn\n    return b;\n}\n\\end{lstlisting}\nWe know that \\lstinline|b| as it is first defined is less than a full turn away from \\lstinline|a|, so the two conditions are enough to bring it within half a turn of \\lstinline|a|.\n\nWe can use this to implement a new version of \\lstinline|windingNumber()| very simply. We start at some vertex of the polygon, move vertex to vertex while maintaining the angle, then read the number of full turns once we come back to it.\n\\begin{lstlisting}\nint windingNumber(vector<pt> p, pt a) {\n    angle a{p.back()}; // start at last vertex\n    for (pt d : p)\n        a = moveTo(a, d); // move to first vertex, second, etc.\n    return a.t;\n}\n\\end{lstlisting}\n", "meta": {"hexsha": "8b786a53587633c52639f31a09b97922ca054c27", "size": 14193, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/basics/polygon.tex", "max_stars_repo_name": "cbarnson/UVa", "max_stars_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_stars_repo_licenses": ["Unlicense", "MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-07T17:00:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-05T02:08:35.000Z", "max_issues_repo_path": "archives/codelibraries/cp-geo-master/basics/polygon.tex", "max_issues_repo_name": "cbarnson/UVa", "max_issues_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_issues_repo_licenses": ["Unlicense", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "archives/codelibraries/cp-geo-master/basics/polygon.tex", "max_forks_repo_name": "cbarnson/UVa", "max_forks_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_forks_repo_licenses": ["Unlicense", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.7086956522, "max_line_length": 573, "alphanum_fraction": 0.7200732756, "num_tokens": 3889, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7243611297832606}}
{"text": "\\section{(2+1) dimensional SPT path integral}\n\\begin{align}\n    H_\\rho^n(G, M)\n    &=\n    \\frac{Z_\\rho^n(G, M)}{B_\\rho^n(G, M)}\\\\\n    &=\n    \\frac{\\ker d_n}{\\im d_{n-1}}\n\\end{align}\nwhere\n\\begin{align}\n    d_n:\n    C_\\rho^n(G, M)\n    \\to\n    C_\\rho^{n+1}(G, M)\n\\end{align}\n\nYou can have $+$ orientation tetrahedrons.\nYou can also have $-$ orientation tetrahedrons.\n\nLet $\\nu_3$ be homogeneous and $\\omega_3$\nbe inhomogeneous.\nThen the path integral is\n\\begin{align}\n    Z &=\n    \\frac{1}{|G|^{N_V}}\n    \\sum_\\left\\{ {g_i \\right\\}}\n    \\prod_{\\Delta^3\\ni (i,j,k,l)}\n    \\left[ \n    \\nu_3\\left( g_i, g_j, g_k, g_l \\right)\n    \\right]^{S\\left( \\Delta^3 \\right)}\n\\end{align}\nNote that\n\\begin{align}\n    g\\cdot \\nu_3\\left( g_1,\\ldots, g_4 \\right)\n    &=\n    \\left[ \n    \\nu_3\\left( gg_1, gg_2, gg_3, gg_4 \\right)\n    \\right]^{\\sigma(g)}\n\\end{align}\ndue to $g$ -action\nand then due to $G$-symmetry,\n\\begin{align}\n    g\\cdot \\nu_3\\left( g_1,\\ldots, g_4 \\right)\n    &=\n    \\left[ \n    \\nu_3\\left( gg_1, gg_2, gg_3, gg_4 \\right)\n    \\right]^{\\sigma(g)}\n    =\n    \\nu_3\\left( g_1, \\ldots, g_4 \\right)\n\\end{align}\nThen\n\\begin{align}\n    \\nu_3\\left( g_1,\\ldots, g_4 \\right)\n    &=\n    \\left[ \\nu_3\\left( 1, g_{12}, g_{13}, g_{14} \\right) \\right]^{\\sigma\\left(\n    g_1 \\right)}\n\\end{align}\nrecalling $g_{ij} = g_i^{-1} g_j$.\nAnd so\n\\begin{align}\n    \\omega_3\\left( g,h,k \\right)\n    &=\n    \\nu_3\\left( \n    1,g,gh,ghk\n    \\right)\n\\end{align}\nThus we have the path integral\n\\begin{align}\n    Z\\left( M^3, A \\right)\n    &=\n    \\prod_{\\Delta^3\\ni \\left( i,j,k,l \\right)}\n    \\left[\n    \\omega_3\\left( A_{ij}, A_{jk}, A_{kl} \\right)\n    \\right]^{S\\left( \\Delta^3 \\right)}\\\\\n    &=\n    \\frac{1}{|G|^{N_V}}\n    \\sum_\\left\\{ {g_i \\right\\}}\n    \\prod_{\\Delta^3\\ni (i,j,k,l)}\n    \\left[\n    \\omega_3\\left( g_i^{-1}A_{ij} g_{j},\n    g_j^{-1}A_{jk}g_k,\n    g_k^{-1}A_{kl}g_l\\right)\n    \\right]^{S\\left( \\Delta^3 \\right)}\n\\end{align}\n\nWe can draw out the Pachner motes in 3D.\n\nThere is the 1-4 Pachner move which inserts a vertex inside a tetrahedron to\nproduce 4 tetrahedrons.\n\nThere is also the 2-3 Pacher move,\nwhich takes two tetrahedrons sharing a face,\nto produce 3 tetrahedra.\nIf the vertices are labelled 0123 and 01234\nno the two original tetrahedra,\nthen new tetrahedra have vertices\n01234, 1234, 0234.\n\nWe want our path integral to be invariant under Pacher moves.\nIn mathematics,\nthere is the famous \\emph{pentagon equation}\n\\begin{align}\n    \\nu \\nu = \\nu\\nu\\nu\n\\end{align}\nwhich implies\n\\begin{align}\n    d\\omega_3 = 1\n\\end{align}\nso that\n$\\nu_3$ and $\\omega_3$ are 3-cocycles.\n\nIf we change\n$\\omega_3 \\to \\omega_3\\, d\\mu_2$,\nthen this cancels out of the path integral.\nEvery $\\mu_2$ enters the product twice with opposite orientation,\nso this cancels out the $\\mu_2$.\n\nUltimately,\ndistinct (2+1)D topological actions will be classified by\n\\begin{align}\n    H_\\rho^3\\left( G, U(1) \\right)\n\\end{align}\nThe $\\rho$ is there so that every time the symmetry $G$ is anti-unitary,\nit's the complex conjugate.\nThe $U(1)$ can be replaced by another group,\nbut it has to be a unitary group.\n$\\rho$ is just a map $\\rho: G\\times U(1)\\to U(1)$ such that\n\\begin{align}\n    \\rho_g\\left( e^{i\\theta} \\right)\n    &=\n    e^{i\\theta'}\n\\end{align}\n\nWe can repeat this whole thing in any general dimensions,\nso what we get is that in $(d+1)$ dimensions,\nwe have distinct actions which are classified by\n$H^{d+1}\\left( G, U(1) \\right)$.\nThis gives a path integral\n\\begin{align}\n    Z_{\\left[ \\omega_{d+1} \\right]}\n    \\left( \n    M^{d+1},\n    A\n    \\right)\n\\end{align}\nfor flat $G$ gauge field $A$\nand\n\\begin{align}\n    \\left[ \\omega_{d+1} \\right]\n    \\in H^{d+1}\\left( G, U(1) \\right)\n\\end{align}\nis just a cohomology class.\nAnd this gives us invertible TQFT with background flat $G$ gauge field,\nbecause $|Z(M,A)|=1$.\n\nSo just like in $1+1$ dimensions,\nwe can write down the wave function,\nwe can write down the wave function in $d$ dimensions,\nand show there is no intrinsic order in SPT,\nand this gives a general solvable model with SPT in general dimensions.\n\nThis gives us a whole class of distinct SPTs classified by $H^{d+1}$.\nThis is not the full classification of SPTs actually.\nThere is a more general classification in terms of cobordisms.\nIn the dimensions we're interested in,\nthis is often the full classification,\nbut often there are states beyond cohomology,\nthere a  whole class of SPT phases called ``beyond cohomology''.\nThe often appear in anti-unitary symmetries in higher dimensions.\n\nSo far we have invertible TQFT.\n\nLet me just say a few more things in terms of how much this classifies.\nIn (1+1)D,\nthis $H^2\\left( G, U(1) \\right)$ is the full classification of invertible\nbosonic phases.\n\nIn (2+1)D,\nthis $H^3(G,U(1))$ is a full classification of bosonic SPTs,\nbut there are invertible phases that are not SPTs.\nThese occur when you have chiral central charge,\nyou can have bosonic states with chiral edge mods.\nStrictly speaking,\nif you break the symmetry,\nthey are not adiabatically connected to the ground state.\n\nAnd then in $(3+1)D$,\nthis $H^4\\left( G, U(1) \\right)$\nis a full classification of invertible bosonic invertible theories if $G$ is\nunitary.\nBut it's partial classification if $G$ has anti-unitary elements.\nThis leads us to so-called \\emph{beyond cohomology} SPTs.\n\nThere is a theory which is expected to capture everything,\nwhich is the cobordism theory,\nwhich I mentioned earlier on in the course.\nFor now I'll leave it at this.\n\n\n\\begin{question}\n    In 1+1 dimensions,\n    there are bosonic phases?\n\\end{question}\nIn 1+1 D,\neven with no symmetry there is the Majorana chain.\n\n\\begin{question}\n    In 1D you can always bosonize?\n\\end{question}\nThere is a real difference between fermions and bosons.\nWhen you bosonize,\nsomething that is local on one side is no longer local on the other side.\nIt's precisely because the notion of locality changes.\n\n\\begin{question}\n    The cobordism is larger than the group cohomology.\n    In 6D,\n    they become the same cobordism phase.\n    Different phases have different topological invariants.\n    How do they collect into the same/\n\\end{question}\nI don't know.\nThe argument why these different phases are different,\nin 1D we say the constant depth circuits which trivialize it,\nbut I don't know what goes wrong in higher dimensions.\n\n\\begin{question}\n    Example of invertible phases in (2+1)D?\n\\end{question}\nThe basic one is called the $E_8$ phase,\nwhich has a chiral central charge of 8.\nIt does not need any symmetry to exist,\nbut it has chiral central charge of 8.\nOne way of thinking about it,\nis stack 8 copies of the Kitaev honeycomb model,\ncondense a bunch of vortices,\nand you get this.\nEverything is made out of these $C_{-}=8$.\n\n\\begin{question}\n    Is this related to the $E_8$ the Lie group?\n\\end{question}\nYou can take $E_8$ level 1 Chern-Simon theory and you get this.\nOr you can get the Cartan matrix of the Lie algebra $E_8$.\nIt's intriguing this exceptional group $E_8$ comes up.\n\n\\begin{question}\n    ??\n\\end{question}\nWe wrote this class of modes,\nbut there's no reason to expect this is full classification.\nThis is not even proven,\nI would say,\nin every dimensions.\nThis is just the current dimension.\nThe current understanding is,\nthere is a conjecture,\nwhich is that bosonic SPTs in $(d+1)$-dimensions\nare classified these cobordism groups\n\\begin{align}\n    \\Hom\\left(\\Omega_{d+1}\\left( BG \\right), U(1)\n    \\right)\n\\end{align}\nwhich means the manifolds are equipped with a $G$-gauge field as well.\nThis is the Pontryagin dual.\nNothing is really proven in terms of full classification.\nTo prove rigorously topological phases are fully classified,\nmeans you have to understand all topological phases,\nwhich is really beyond our understanding.\nThis is based on what we understand so far and what seems to make sense.\n\n\nThis sketch, what is not captured?\nIn 2+1D the ones not captured are he ones with chiral edge models.\nIts' because the edge gives you a Hamiltonian as a sum of commuting projectors,\nwhich you can argue will always gap the edge.\nThis class of models cannot exhibit fully robust chiral edge modes.\nThe reason some anti-unitary symmetries are outside the group cohomology models\nis a deeper issue.\nIt ultimately has to do with the fact that group cohomologies characterise the\nability to couple to background gauge fields,\nbut there's something beyond background gauge fields,\nand there's no reason to think $G$-gauge theory should be enough on its own\nanyway.\n\n\\begin{question}\n    Edge modes in 1+1D?\n\\end{question}\nThose are captured,\nbut hose are gappable.\nIf I break the symmetry I can get rid of them.\nThese are ones where even if you break all symmetries you cannot get rid of\nthem.\n\n\\begin{question}\n    ??\n\\end{question}\nThese chiral central charge has nothing to do with symmetry,\nit's like thermal Hall conductance.\nIt's true that anti-unitary symmetries,\nyou cannot gauge.\nWhen you have a background $G$-gauge field,\nyou can promote it to a dynamical gauge field by summing over configurations.\nYou can't do that if talking about anti-unitary symmetries.\n\nLet's talk a bit more about what the physical meaning of this $H^3$ is.\nSo far this $H^3$ we used to describe a class of models,\nwe saw in 1+1D,\nwe saw a projective action on the edge.\nYou guys asked if there is an analogy for higher dimensions.\nThere is.\n\n\\section{Physical origin of $H^3(G, U(1))$}\nLet's just briefly recall that in $(1+1)$-D,\nfor the $H^2(G, U(1))$ what happens.\nWe considered a system on an open chain,\nthen applied a symmetry operation of $G$,\nwith representation $R_g$,\nwhich localizes a s an action on the left $U_g^L$ and an action on the right end\npoint $U_g^R$,\nand we get a projective phase we cannot get rid of and that is why we have this\nsecond cohomology class.\n\\begin{align}\n    U_g^L U_h^2\n    =\n    \\omega_2(g, h)\n    U_{gh}^L\n\\end{align}\n\nNow consider $(2+1)$D. (Else-Nayak 2014)\nThe idea is to apply some symmetry operation and see hat happens on the edge.\nSay your system is on a disk,\nyou apply a symmetry operation,\nand see what it looks like on the edge.\nWe have some restriction of the operator on the edge,\nthen we cut that operator open,\nso it looks like an operator on a segment.\nThen we restrict $U_g^{\\left( edge \\right)}$\non a segment,\nand we reduce it down to a point,\nand we have a projective phase that turns up.\n\nThat's the rough idea.\nTo get this in more detail,\nI want to say more about the idea \nif we have a local unitary,\na unitary operator that arises as a constant depth local unitary circuit,\nthere's an idea of restricting that unitary to a subregion.\n\nConsider a unitary $U$ acting on a space $C$.\n$U$ is a local unitary,\nmeaning that it's a constant depth local quantum circuit.\n\nAnother local unitary $U_M$ is going to be the restriction of $U$ to a\nsubmanifold $M$\nif it acts exactly the same as $U$ on the subregion $M$ away from the\nboundaries.\nThat is,\nit acts the same as $U$ in the interior of $M$ far way from $\\partial M$.\nThere are a few things you can say about such a restriction.\n\nFirstly,\nthe restriction always exists.\nSuppose we have a unitary that acts as some circuit on a bunch of qubits.\nSo something like this [picture].\n\nLet's say this is $U$ acting on $C$.\nI can always define a restriction\nby cutting this unitary along some lines here,\nand looking at the unitary only acting on the middle.\nObviously there's some ambiguity on the edge,\nbut in the bulk it's clear I can define a unitary that acts in the same way as\n$U$.\n\nIt's important that $U$ is a constant depth circuit,\nso there is a kind of light cone,\nnothing on this side is going to cross to this side beyond a certain size.\nOf course near the boundaries of $M$ there are ambiguities.\n\nThe restriction is obviously ambiguous near the boundaries,\nand they are ambiguous up to some operators.\n\n\\begin{question}\n    We must have some conditions on the size of the submanifold as well?\n\\end{question}\nIf it's too small compared to the depth of the circuit,\nwe can't do this.\nWe're assuming the region is large compared to the depth of the circuit.\n\nThe second thing is that this is defined modulo local unitaries near the\nboundary $\\partial M$.\n\nThis is the analogue of what we saw in $1+1$ dimensions.\nWe applied the symmetries,\nacting like $U_g^L$ and $U_g^R$\nwhere we could change the phase near the boundary,\nand that's the ambiguity.\nBut here,\ninstead of a phase,\nThis is the higher-dimensional generalization of phase ambiguity.\n\nLet's consider the symmetry operator\nacting on the low energy subspace of the edge theory.\nIt's a unitary.\nThis state is gapped on the bulk,\nbut it's gapless on the boundary.\nThe states we are concerned with are where the edge is in some low energy\nsubspace,\nso the excitations on the edge have a much lower energy than the bulk energy\ngap.\n\nThen we apply some symmetry operations.\nBecause the bulk is in the ground state and symmetric,\nafter applying $R_g$,\nthis is just applying $U_g^{edge}$ on the edge.\n\n\nSo let's assume $R_g R_h = R_{gh}$.\nThat's going to also be true for these edge operators.\nIf not,\nthere will be a projective representation no the edge,\nwhich is in conflict that the ground state is unique and in the ground state.\nFor 1+1 D open chain,\nthe ground state is not symmetric,\nbecause we have these edge states that can fuse to a singlet,\nso we can have a symmetric ground state,\nbut we have a degeneracy when these things are far away from each other.\nIn higher dimensions,\nthe edge is connected,\neven though there are gapless excitations on the edge,\nit is still unique and symmetric.\n\\begin{align}\n    U_g^{edge} U_h^{edge} u_{gh}^{edge}\n\\end{align}\n\nIf the edge preserves symmetry,\nthe ground state is unique,\nthen there is no projective representation for the edge.\nNow we take this local unitary on the edge and we cut it open.\n\nSo suppose I take a cut.\n\\begin{align}\n    U_g^{cut} U_h^{cut} = \\Omega(g, h) U_{gh}^{cut}\n\\end{align}\nwhere $\\Omega(g, h)$\nis a unitary operator with only support for the new end points $a$ and $b$.\nFor the bulk we do satisfy the group law,\nbut it's only at the edge boundary where we don't necessarily support the group\nlaw.\n\n\nNow we can consider associativity.\nWe considered\n\\begin{align}\n    U_g^6cut U_h^{cut} U_k^{cut}\n    =\n    U_g^{cut}\n    \\Omega(h, k)\n    U_{h,k}^{cut}\\\\\n    &=\n    ^g\\Omega(h, k)\\Omega(g, h, k) U_{ghk}^{cut}\n\\end{align} \nwhere\n\\begin{align}\n    ^g\\Omega(h, k)\n    :=\n    U_g^{cut} \\Omega(h, k)\n    \\left( U_g^{cut} \\right)^{-1}\n\\end{align}\nso then\n\\begin{align}\n    U_g^6cut U_h^{cut} U_k^{cut}\n    &=\n    \\Omega(g, h)\n    \\Omega(gh, k)\n    U_{ghk}^{cut}\n\\end{align}\nAnd so we are led to this equation\n\\begin{align}\n    \\Omega(g, h) \\Omega(gh, k)\n    =\n    ^g\\Omega(h, k)\n    \\Omega(g, h, k)\n\\end{align}\nBut now we realise $\\Omega$ is an operator with support on $a$ nd $b$.\nConsider restriction of $\\Omega(g, h)$\nto $\\Omega_a(g, h)$.\nAnd so we can consider some phase\n\\begin{align}\n    \\Omega_a(g, h)\n    \\Omega_a(gh, k)\n    =\n    \\omega_3(g, h, k)\n    ^g\\Omega_a(h, k)\n    \\Omega_a(g, hk)\n\\end{align}\nwhere $\\omega_3(g,h,k) \\in U(1)$\nand $\\omega_3 \\in C^3(G, U(1))$.\nBut you see that $\\Omega_3$ does need to satisfy the $3$-cochain equation\n\\begin{align}\n    d\\omega_3 = 1\n\\end{align}\nSo then if we change\n\\begin{align}\n    \\Omega_a(g, h)\n    \\to\n    \\Omega_a(g, h)\n    \\mu_2(g,h)\n\\end{align}\nfor $\\mu_2\\in U(1)$,\nthen\n\\begin{align}\n    \\omega_3 \\to \\omega_3\\, d\\mu_2\n\\end{align}\nThis shows us the distinct set of phases is classified by $H^2(G,U(1)$.\nSo distinct $\\omega_3$'s are classified by\n\\begin{align}\n    H^3(G, U(1))\n\\end{align}\nSo that associativity condition is satisfied up to a phase and that's where we\nget this $H^3$.\n\nThere's no projective representation anywhere.\nWe're just restricting and cutting\nuntil we finally get this.\n\nIn order to get this to work,\nwe need to assume something more specific about how $U_g^{edge}$ looks like.\nIn higher dimensions,\nwe have to assume\n\\begin{align}\n    U_g^{edge}\n    &=\n    N_g\n    S_g\n\\end{align}\nwhere $N_g=\\sum_\\alpha e^{i N_g'(\\alpha)}$ is non-on site but diagonal,\nand $S_g=\\sum_\\alpha \\bra{g \\alpha}\\ket{\\alpha}$\nAnd in general,\nthe docs appear \n\n\\begin{question}\n    what happens if you had a system living on an annulus.\n\\end{question}\nIf you're taking about intrinsically 2D systems,\nyou can talk about the edge on a \n\nI'm just focusing on this operator on one segment.\nOn that segment,\nI satisfy this group up to 1 \n\nThere are for mathematicians rigorous definitions and derivations.\n\nI just wanted to mention one more ting.\nThree's another way of phrasing these topological.\n\nThere is a compact way to define the topological action for group cohomology\nmodels\n\\begin{align}\n    Z\\left( M^{d+1}, A \\right) &=\n    e^{iS_{top}(A)}\n\\end{align}\nFirstly, every group $G$ has a corresponding space called ``classifying\nspare'' $BG$.\nThe defining property is that\n$\\pi_1(GB) = G$\nand\n$\\pi_k(BG)=0$\nfor $k>1$.\nEvery $G$ gauge field is in one-to-one correspondence with\nhomotopy classes of maps.\nYou can think of gauge fields as being a map from your manifold into your\nclassifying space.\n$f: M^d \\to BG$.\nWhat we did when we triangulated the manifold,\nand put gauge fields on links,\nthat actually does specify a map from $M$ to $BG$.\nThis is just a fancy way of saying what we did in practice.\n\nThe classifying space for the circle is\n$B\\mathbb{Z} = S^1$.\nThe classifying space for $\\mathbb{Z}_2$ is\n$B\\mathbb{Z}_2 = \\mathbb{RP}^{\\infty}$.\nThe classifying space for phases is\n$BU(1) = \\mathbb{CP}^{\\infty}$.\n\nSecondly, the other thing is that group cohomology\n$H^k(G, U(1))$\nis equivalent to\n``regular'' cohomology (singular de Rham cohomology)\nNakahara has a nice book called geometry, topology and physics..\n\\begin{align}\n    H^k(G, U(1)) \\simeq \n    H^k(BG, U(1))\n\\end{align}\nis true for finite $G$,\nbut is more subtle for groups.\n\n\nThirdly,\nif I had a cohomology on $Y$,\nI can get a class on $X$ and the map that does this is called\n$f^*$, the \\emph{pullback}.\nThat is,\nif $f:X \\to Y$,\nthen\n\\begin{align}\n    f^*: H_k(Y, U(1)) \\to H^k(X, U(1))\n\\end{align}\nis the pullback.\n\nWe can put these 3 facts together.\nGiven a class $[w_{d+1}] \\in H^{d+1}\\left( BG, U(1) \\right) \\simeq H^{d+1}(G,\nU(1)$\nwhich is isomorphic\nand a $G$ gauge field determined by\n\\begin{align}\n    f_A: M^{d+1} \\to BG\n\\end{align}\nthen we can define an element of the $H^{d+1}$ cohomology class\n\\begin{align}\n    f_A^\\left[ \\omega_{d+1} \\right]\n    \\in\n    H^{d=1}\\left( M^{d+1}, U(1) \\right)\n\\end{align}\nand then we have our path integral\n\\begin{align}\n    e^{iS_{top}}\n    &=\n    e^{i\\int_{M^{d+1}} f_A^*\\left[ \\omega_{d+1} \\right]}\\\\\n    &= Z\\left( M^{d+1}, A \\right)\n\\end{align}\nThese 3 facts allow you to package this path integral in this nice way.\nUnfortunately,\nI would need at least 3 lectures to unpack all of this.\nI'm just telling you so you know where to look to learn about this.\nAre there any questions?\nActually,\nif you have questions,\nI might not be able to answer it.\n\nIn the last minute,\nI want to mention where I'm going next.\n\nSuppose we have a TQFT with $G$-symmetry $T$.\nWe can always ``gauge'' $G$.\nThat means we promote he background $G$ gauge field to a dynamical gauge field,\nwhich gives a new configuration $T$ mod $G$,\nwhich is $T/G$.\nI can then sum over flat gauge field configurations.\nI put brackets to say we are summing over inequivalent ones that are not related\nby gauge transformation.\n\\begin{align}\n    Z_{T/G}\\left( M^{d+1} \\right)\n    =\n    \\sum_{\\left[ A \\right]}\n    Z_{\\left[ \\omega_{d+1} \\right]}\n    \\left( M^{d+1}, A \\right)\n\\end{align}\nAnd so dynamical, topological $G$-gauge theory is classified by\n$H^{d+1}\\left( G, U(1) \\right)$.\nWe are interested in 2 classes of this phenomena.\n\n1. Discrete and finite $G$.\nThis leads to models like the toric code,\nand more generally quantum double models.\nLike Levin-Wen models, etc.\nIf we start off with an invertible theory,\nand we gauge $G$,\nwe end up with a non-irreversible theory.\nSO one way of getting non-invertible theories is this.\n\n2. Continuous $G$.\nThis takes us toe Chern-Simons theory in $(2+1)$D.\nAt this point,\nthe discussion bifurcates.\n\nWe can talk about non-invertible phases\nyou get from gauging invertible theories.\n\nWe can also label things on triangulations and sum over all labels.\nNext time,\nI'll start getting into this quantum Chern-Simon theories,\nwhich allows us to describe fractional quantum hall states,\nwhich are the only experimentally realised non-invertible theory.\n\nAre all non-invertible topological phases obtainable by gauging an invertible\nTQFT.\n30 year old conjecture by Moore and Cyberg still standing.\nThere are candidate counterexamples,\nbut we're not sure.\n", "meta": {"hexsha": "3a4043fa0cd960452b73fc211be5d6f750fa4237", "size": 20648, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys733/lecture21.tex", "max_stars_repo_name": "ehua7365/umdphysnotes", "max_stars_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-11T12:53:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-11T12:53:46.000Z", "max_issues_repo_path": "phys733/lecture21.tex", "max_issues_repo_name": "ehua7365/umdphysnotes", "max_issues_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "phys733/lecture21.tex", "max_forks_repo_name": "ehua7365/umdphysnotes", "max_forks_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.838150289, "max_line_length": 80, "alphanum_fraction": 0.7137737311, "num_tokens": 6232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.7243464566591912}}
{"text": "\\section{Validation}\n\nTo validate our implementation of the stochastic simulation model, the 3 region problem previously solved using differential equations, is now solved using the stochastic model.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width= 1.0 \\linewidth]{plots/sir_three_region_sim_10000.pdf}\n\t\\caption{10 solutions using the stochastic simulation model, on the same 3-region problem as in the theoretical case.}\n\t\\label{fig:sir_three_region_sim_10000}\n\\end{figure}\n\nFigure \\ref{fig:sir_three_region_sim_10000} shows a big discrepancy between the solution obtained using differential equations and those obtained using stochastic simulation. This is most likely because the differential equation model allows for transferring people partially. This means regions that has a very low probability of getting infected early in the stochastic model, starts their infection immediately in the differential equation model. This hypothesis can be validated by increasing the number of people in each region (N), as this will cause the discreteness of the stochastic model to be less important. The result of this can be seen in figure \\ref{fig:sir_three_region_sim_1000000}. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width= 1.0 \\linewidth]{plots/sir_three_region_sim_1000000.pdf}\n\t\\caption{10 solutions using the stochastic simulation model, on the same 3-region problem as in the theoretical case.}\n\t\\label{fig:sir_three_region_sim_1000000}\n\\end{figure}\n\nAs seen in figure \\ref{fig:sir_three_region_sim_1000000} having more people results a much smaller discrepancy. This discrepancy caused by using a discrete model is not necessarily a failure of the stochastic model, but rather it is the differential equation model that overestimates the infection start for initially healthy regions, when the region populations are small.\n", "meta": {"hexsha": "69abff8e76c2b8794cabebe9d71ddb9281407622", "size": 1848, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/validation.tex", "max_stars_repo_name": "FrederikWR/course-02443-stochastic-virus-outbreak", "max_stars_repo_head_hexsha": "4f1d7f1fa4aa197b31ed86c4daf420d5a637974e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/validation.tex", "max_issues_repo_name": "FrederikWR/course-02443-stochastic-virus-outbreak", "max_issues_repo_head_hexsha": "4f1d7f1fa4aa197b31ed86c4daf420d5a637974e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/validation.tex", "max_forks_repo_name": "FrederikWR/course-02443-stochastic-virus-outbreak", "max_forks_repo_head_hexsha": "4f1d7f1fa4aa197b31ed86c4daf420d5a637974e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.0, "max_line_length": 701, "alphanum_fraction": 0.8225108225, "num_tokens": 404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.9046505415276079, "lm_q1q2_score": 0.7243464532929297}}
{"text": "\\documentclass[11point]{article}\n\n\\usepackage[letterpaper,margin=1in]{geometry}\n\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage{bbm}\n\\usepackage{bm}\n\n\n\\newcommand{\\beq}{\\begin{eqnarray}}\n\\newcommand{\\eeq}{\\end{eqnarray}}\n\\renewcommand{\\d}[1]{\\:\\mathrm{d}#1}\n\\renewcommand{\\vec}[1]{\\bm{#1}}\n\\newcommand{\\grvec}[1]{\\bm{#1}}\n\n\n\\newcommand{\\one}{\\mathbbm{1}}\n\\newcommand{\\reals}{\\mathbb{R}}\n\n\\newcommand{\\df}[1]{\\delta \\left( #1 \\right)}\n\\newcommand{\\set}[1]{\\left\\{#1\\right\\}}\n\n\\newcommand{\\var}[1]{\\texttt{#1}}\n\n\\begin{document}\n\\section{Notation}\n\\begin{itemize}\n\\item\nFor any cell $i$ with center $\\vec{x}_i$, let $R_i$ denote the \nregion of space occupied by it. Assume that for any other cell \n$j$, that $R_i \\cap R_j = \\emptyset$. \n\\item \nFor any  computational \nmesh with voxels $\\set{ \\Omega }$ and corresponding \nvolumes $\\set{W}$, let $\\rho( \\Omega) $ denote the mean \nsubstrate density in voxel $\\Omega$, and let \n$n(\\Omega) = \\int_\\Omega \\rho \\d{V}$ denote the total\n amount of substrate in the voxel. \n\nNote that BioFVM tracks the mean substrate density in each voxel, \nso $\\rho \\equiv \\rho( \\Omega )$ throughout $\\Omega$. \n\\item \nFor any voxel $\\Omega_k$ with an index $k$, let $W_k$ denote \nits volume, define $\\rho_k = \\rho( \\Omega_k )$, and \ndefine $n_k = n( \\Omega_k)$. \n\n\\item \nFor any cell $i$ with center $\\vec{x}_i$, let $\\Omega_i$ denote the \nvoxel containing cell $i$, with corresponding volume $W_i$. \n\\item\nLet $\\one_i(\\vec{x})$ be the characteristic  function for the cell, so that \n$\\one_i(\\vec{x}) =1$ inside the cell (inside $R_i$), and \n$\\one_i(\\vec{x}) = 0$ otherwise. \n\\item \nLet $V_i = \\int_{\\reals^3} \\one_i(\\vec{x}) \\d{V} = V_i$ be the total volume of cell $i$. \n\\item \nFor any cell $i$, let $N_i$ denote the \\emph{internalized} total substrate. \n\n\\end{itemize}\n\n\\section{Net extracellular substrate change \ndue to the $i^\\textrm{th}$ cell}\nNote that in BioFVM the cells' contribution \nto changes in total substrate in any volume $\\Omega$ is given by \n\\beq\n\\frac{ \\partial }{ \\partial t} \n\\int_\\Omega \\rho \\d{V} & = &  \n\\sum_{\\textrm{cells } i} \n\\int_\\Omega  \\one_i(\\vec{x})\n\\Bigl(  S_i \\left( \\rho^T_i - \\rho \\right)  - U_i \\rho   \\Bigr) \\d{V}\\\\\n& \\approx & \n\\sum_{\\textrm{cells } i}\nV_i \\int_\\Omega \\df{ \\vec{x} - \\vec{x}_i }\n\\Bigl(  S_i \\left( \\rho^T_i - \\rho \\right)  - U_i \\rho   \\Bigr) \\d{V}.\n\\eeq \n\nNow, let $\\Omega = \\Omega_i$ be the voxel containing $\\vec{x}_i$ as \ndefined above. Then assuming that only cell $i$ is in $\\Omega_i$:  \\beq\n\\frac{ d{n_i} }{ d{t} }  \n= \n\\frac{ \\partial }{ \\partial t} \n\\int_{\\Omega_i} \\rho \\d{V}\n & \\approx &  \nV_i \n\\Bigl(  S_i \\left( \\rho^T_i - \\rho(\\vec{x}_i) \\right)  - U_i \\rho(\\vec{x}_i)   \\Bigr)  \\\\\n& = & \nV_i \n\\Bigl(  S_i \\left( \\rho^T_i - \\rho_i \\right)  - U_i \\rho_i   \\Bigr) .\n\\eeq \n(The case with multiple cells in a single computational voxel generalizes by performing this calculation separately for each cell contained in the voxel.)\n\nNow, because $n_i = \\rho_i W_i $, and asssuming $W_i$ is constant or changes very slowly compared to substrate densities, \n\\beq\nW_i \\frac{ d{\\rho_i} }{ d{t} }  & \\approx &  \nV_i \n\\Bigl(  S_i \\left( \\rho^T_i - \\rho_i \\right)  - U_i \\rho_i   \\Bigr)   \\\\\n\\Longrightarrow \n\\frac{d\\rho_i }{dt} & \\approx & \n\\frac{ V_i }{W_i }\n\\Bigl( S_i \\left( \\rho_i^T - \\rho_i \\right) - U_i \\rho_i \\Bigr) \n\\eeq \n\n\\subsection{BioFVM implementation}\nNow, let's apply a backward Euler scheme as in BioFVM, to determine the net change in total substrate in any time step with duration $\\Delta t$: \n\\beq\n\\frac{ \\rho_i(t+\\Delta t) - \\rho_i(t)}{\\Delta t} \n& \\approx & \n\\frac{ V_i }{W_i } \n\\Bigl( S_i \\left( \\rho_i^T - \\rho_i(t+\\Delta t) \\right) \n- U_i \\rho_i( t + \\Delta t ) \\Bigr)\\\\\n\\Longrightarrow \n\\rho_i( t+\\Delta t) \n& \\approx & \n\\frac{\\rho_i(t)  + c_1 }{c_2},\n\\eeq\nwhere \n\\beq\nc_1 & = & \\Delta t \\frac{ V_i }{W_i } \n\\left( S_i \\rho_i^T \\right) \\\\ \nc_2 & = & 1 + \\Delta t \\frac{ V_i }{W_i } \n\\left( S_i + U_i \\right) .\n\\eeq\n\nThis is the algorithm in \n\n\\begin{center}\\verb|void Basic_Agent::simulate_secretion_and_uptake( Microenvironment* pS, double dt )|\n\\end{center}\n\nThe constants $c_1$ and $c_2$ are set in \n\\verb|void Basic_Agent::set_internal_uptake_constants( double dt )|. \n\n\\subsection{Net extracellular substrate change}\n\nNow, let's determine the change in total substrates in this implementation. First, \n\\beq\nn_i(t+\\Delta t ) - n_i(t) & = & \nW_i \\rho_i(t+\\Delta t) - W_i \\rho_i(t) \\\\\n& = & \nW_i \\left( \\frac{\\rho_i(t)+c_1}{c_2} - \\rho_i(t) \\right) \\\\ \n& = & \nW_i \\left( \\frac{\\rho_i(t) + c_1  - c_2 \\rho_i(t) }{c_2} \\right) \\\\ \n& = & \nW_i \\left( \\frac{ (1-c_2) \\rho_i(t) + c_1  }{c_2} \\right) \\\\ \n\\eeq\nNotice that this can be calculated completely using constants that are already computed and used in BioFVM. \n\\subsection{Algorithm}\nWe will use the following operations in the cell secretion/uptake function. (In the actual implementation, \nperform this on the entire vector of substrates, and use element-wise operations. i.e., Hadamard products and \nquotients.) \n\\begin{enumerate}\n\\item \n\\verb|change = 1 // 1|\n\\item \n\\verb|change -= c2 // 1-c2|\n\\item \n\\verb|change *= substrates // (1-c2)*rho|\n\\item \n\\verb|change += c1 // (1-c2)*rho + c1|\n\\item \n\\verb|change /= c2 // ((1-c2)*rho + c1)/c2|\n\\item \n\\verb|change *= voxel_volume // W_i*((1-c2)*rho + c1)/c2|\n\\end{enumerate}\nThis is the net change in total substrates in $\\Omega_i$. For conservation, \nthe net chnage in cell $i$ is equal and opposite. Thus \n\\begin{enumerate}\n\\setcounter{enumi}{6}\n\\item \n\\verb|internalized_substrates -= change|\n\\end{enumerate}\n\n\\section{Additional option(s)}\nIf you set \\verb|Basic_Agent::use_internal_densities_as_targets = true|, then whenever\nthe internal constants are changed, it sets \n\\beq\n\\rho_i^* & = & \\frac{N_i}{V_i}\n\\eeq\nThis criterion would be appropriate for non-active, diffusive secretion from the cell. \n\nPlease note that \nif $\\rho_i^* < \\rho_i$, there is nothing in the mathematical form to prevent diffusion of the substrate \nback into the cell. If this is a concern, I suggest users manually test for that and set \nthe secretion rates to zero accordingly. \n\nFuture releases of PhysiCell may automate this testing, but we note that this test should be performed \nsubstrate-by-substrate. \n\n\\section{Internal model}\nWithout an internal model, internalized substrate will reflect the total history of \nall uptaken substrates, or the sum tutoal fo all secreted substrates.  In particular, \nin the case of secretion, the internalized value will be negative to upload mass conservation. (No thing made inside, minus the secreted amount.) \n\nUsers can provide their own internal model (e.g., for metabolomics), but we provide a ``sensible default.'' Inside the cell, we model: \n\\beq\n\\frac{dN}{dt} & = & \\overbrace{-u N}^\\textrm{use} + \\overbrace{c ( N^* -  n)}^\\textrm{creation} \\\\\n& = & \n-u \\rho_I W + s( \\rho_I^* - \\rho_E ) W, \n\\eeq\nwhere $\\rho_I$ is the internal density, and $c$, $u$, and $\\rho_I^*$ are to be determined. We shall give the rationale for this form in the analysis below. \n\nTo determine these parameters, let us consider the total amount of substrate in the cell: \n\\beq\n\\frac{dN}{dt} & =& \n\\overbrace{ U \\rho_E W  }^\\textrm{import} \n- \n\\overbrace{ S \\left( \\rho_E^* - \\rho_E \\right) W }^\\textrm{export} \n- \n\\overbrace{ u \\rho_I W }^\\textrm{internal use} \n+ \n\\overbrace{ c \\left( \\rho_I^* - \\rho_E \\right)W  }^\\textrm{internal creation}\n\\eeq\nNow, consider the case where there is uptake and use but no creation or secretion. Then \n\\beq\n\\frac{dN}{dt} & = & \nU\\rho_E W - u \\rho_I W = \\left( U \\rho_E - u \\rho_I \\right) W. \n\\eeq\nIn quasi-steady (or steady) conditions, we seek $u$ so that \n$\\rho_I \\approx \\rho_E$. Notice that if $u = U$, then \n\\beq\n\\frac{dN}{dt}  & = & U \\left( \\rho_E - \\rho_I \\right) W, \n\\eeq\nand so $\\rho_I = \\rho_E$ in quasi-steady condition. This model \nbalances import with internal use. Moreover, if we balance all substrate in the \nenvironment (assuming without loss of generality only one uptaking cell): \n\\beq\n\\frac{d}{dt} \\left( n + N \\right) & = &\n- U \\rho_E W + U \\rho_E W - U \\rho_I V = - U \\rho_I W, \n\\eeq\nand over long times, $\\rho_I \\approx \\rho_E$ , so we arrive at the \nnormal situation from BioFVM where the overall loss rate is \n$- U \\rho_E W$. \n\nNext, consider the case of only creation and export. In that case, \n\\beq\n\\frac{dN}{dt} & = & \n-S ( \\rho_E^* - \\rho_E ) W + s ( \\rho_I^* - \\rho_E) W. \n\\eeq\nSuppose we follow our prior motivation and set $s = S$. Then \n\\beq\n\\frac{dN}{dt} & = & \nS \\left( - \\rho_E^*  + \\rho_E + \\rho_I^* - \\rho_E \\right) W \n= S \\left( -\\rho_E^* + \\rho_I^* \\right)W. \n\\eeq\nIf we choose $\\rho_I^* = \\rho_E^*$, then \n\\beq\n\\frac{dN}{dt} &  = & 0\n\\eeq\nand so we have successfully balanced creation and export. This the \nmotivation for the functional form $s ( \\rho_I^* - \\rho_E)$ instead \nof the more obvious $s ( \\rho_I^* - \\rho_I)$. The biophysical interpretation \nis that the cell internally creates the substrate until the extenral density \nreaches the target value. \n\n\\subsection{Summary:}\nReturning now to the original notation where $\\vec{\\rho}$ is the vector of (extracellular) substrate densities, $\\vec{N}$ is the vector of total internalized \nsubstrates, then we use (as an internal model), and \n\\beq\n\\frac{d\\vec{N}}{dt} & = & \n- \\vec{u}\\circ \\vec{N} + \\vec{c} \\circ \\left( \\vec{\\rho}^* - \\vec{\\rho}  \\right)W\n\\eeq\nand we set defaults: \n\\beq\n\\vec{u} & = & \\vec{U} \\\\\n\\vec{c} & = & \\vec{S} \n\\eeq\n\n\\section{Key cellular processes}\nWhen a cell divides, it must distribute its internalized substrates to its daughter cells while maintaining conservation of mass. \n\nIn PhysiCell 1.5.0, we do this by dividing the substrate by half in each of the daughter cells. \n\nWhen a cell dies and is removed by the simulation, multiple things could happen: for some substrates, it may make sense to \nremove them from the environment entirely, release it entirely at the time of lysis, or slowly release it back into the environment \nwhile the cell degrades. \n\nIn PhysiCell, we opt for the simplest solution: release (some fraction) of internalized substrates when the basic agent (and hence cell) calls \nits destructor. Let $0 \\le F \\le 1$ denote the fraction of internalized \nsubstrates released at the time of death. \n\nWe overwrite the density in the cell's voxel by first noting that there should be conservation of mass: \n\\beq\nn_i( t + \\Delta t ) & = & \nn_i( t ) + F N_i (t)  \\\\ \n\\Longrightarrow \nV_i \\rho_i(t + \\Delta t) & = &\nV_i \\rho_i(t) + F N_i(t) \\\\ \n\\Longrightarrow \n\\rho_i( t + \\Delta t ) & = & \n\\rho_i(t) + \\frac{F}{V_i} N_i \n\\eeq\n\n\n\\end{document}", "meta": {"hexsha": "b515db27113287c283da7c28b1ac1ad02644185e", "size": 10545, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/math/substrate-internalization-equations.tex", "max_stars_repo_name": "matt-stack/PhysiCell_GPU", "max_stars_repo_head_hexsha": "e1e07680b99f5c624448f2dfa607cfdbf0176c2f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-04-18T02:00:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-08T08:18:50.000Z", "max_issues_repo_path": "documentation/math/substrate-internalization-equations.tex", "max_issues_repo_name": "matt-stack/PhysiCell_GPU", "max_issues_repo_head_hexsha": "e1e07680b99f5c624448f2dfa607cfdbf0176c2f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-05-23T01:38:33.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-23T02:01:42.000Z", "max_forks_repo_path": "documentation/math/substrate-internalization-equations.tex", "max_forks_repo_name": "matt-stack/PhysiCell_GPU", "max_forks_repo_head_hexsha": "e1e07680b99f5c624448f2dfa607cfdbf0176c2f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2020-04-05T16:52:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-13T17:54:38.000Z", "avg_line_length": 35.8673469388, "max_line_length": 158, "alphanum_fraction": 0.6786154576, "num_tokens": 3584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7242313514662992}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\n\\setlength\\parindent{0pt}\n\n\\title{Learning Notes on Statistical Learning Theory}\n\\author{a1trl9}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\\section{Lecture 3}\nWe have achieved:\n\\begin{equation}\n    L(\\hat{\\theta})-L(\\theta^{*}) \\approx \\frac{p}{2n} + o(\\frac{1}{n})\n\\end{equation}\nThe limitation of the result above is we assume the data are precisely\ndistributed according to a particular ground truth parameter \\(\\theta^{*}\\).\nAlso, we ignore the dependence of higher order terms on other hyperparameters.\n\n\\subsection{Uniform Convergence Framework}\n\n\\textbf{Definition:} uniform convergence is a property of hypothesis\nclass \\(\\mathcal{H}\\) of the following form:\n\\begin{equation}\n\\mathrm{Pr}[\\forall h \\in \\mathcal{H}, | \\hat{L}(\\theta)-L(\\theta)\\leq \\epsilon] \\geq 1 - \\delta\n\\end{equation}\n\n\\textbf{Why uniform convergence framework implies generalization?}\n\\vspace{2mm}\n\\begin{equation}\n\\begin{aligned}\n&L(\\hat{h})-L(h^{*})\\\\\n&=L(\\hat{h}) - \\hat{L}(\\hat{h})+\\hat{L}(\\hat{h})-\\hat{L}(h^{*})+\\hat{L}(h^{*})-L(h^{*})\n\\end{aligned}\n\\end{equation}\n\nSince \\(\\hat{h}\\) is the optimal solution for the training example, \\(\\hat{L}(\\hat{h})-\\hat{L}(h^{*})\\leq 0\\), so\nwe get:\n\\begin{equation}\n\\begin{aligned}\nL(\\hat{h})-L(h^{*})&\\leq L(\\hat{h}) - \\hat{L}(\\hat{h})+0+\\hat{L}(h^{*})-L(h^{*})\\\\\n&\\leq |L(\\hat{h})-\\hat{L}(\\hat{h})| + |\\hat{L}(h^*)-L(h^*)|\\\\\n&\\leq 2|L({h})-\\hat{L}(h)|\n\\end{aligned}\n\\end{equation}\n\nTherefore, when uniform convergence holds:\n\\begin{equation}\n\\mathrm{Pr}(L(\\hat{h})-L(h^{*})\\leq 2\\epsilon)\\geq\\mathrm{Pr}[\\forall h \\in \\mathcal{H}, | \\hat{L}(\\theta)-L(\\theta)\\leq \\epsilon]\\geq 1-\\delta\n\\begin{aligned}\n\\end{aligned}\n\\end{equation}\n\n\\subsection{Finite Hypothesis Classes}\nIf \\(\\mathcal(H)\\) is finite and \\(l(x, y), h)\\in [0, 1]\\), we have the\nfollowing statements (based on Hoeffding Inequality):\n\\begin{enumerate}\n\\item For any fixed \\(h\\in \\mathcal{H}\\) and \\(\\epsilon > 0\\):\n\\begin{equation*}\n\\mathrm{Pr}[|\\hat{L}(h)-L(h)|\\leq \\epsilon] \\geq 1 - 2e^{-2n\\epsilon^2}\n\\end{equation*}\n\\item For any \\(\\epsilon > 0\\):\n\\begin{equation*}\n\\mathrm{Pr}[\\forall h\\in \\mathcal{H}, | \\hat{L}(h) - L(h)| \\leq \\epsilon]\\geq 1 - 2|\\mathcal{H}|e^{-2n\\epsilon^2}\n\\end{equation*}\n\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "8279c8bf510916adb086dd90788c1c03fb666ca8", "size": 2261, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slt.tex", "max_stars_repo_name": "a1trl9/stle", "max_stars_repo_head_hexsha": "f6d58624bb9d7dabed13cf6e2ed01de598ef7426", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slt.tex", "max_issues_repo_name": "a1trl9/stle", "max_issues_repo_head_hexsha": "f6d58624bb9d7dabed13cf6e2ed01de598ef7426", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slt.tex", "max_forks_repo_name": "a1trl9/stle", "max_forks_repo_head_hexsha": "f6d58624bb9d7dabed13cf6e2ed01de598ef7426", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.25, "max_line_length": 143, "alphanum_fraction": 0.6581158779, "num_tokens": 860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7242313500668622}}
{"text": "\n\\subsection{Prior and posterior predictive distributions for dependent variables}\n\n\\subsubsection{Prior predictive distribution}\n\nOur prior predictive distribution for \\(P(y|X)\\) depends on our prior for \\(\\theta \\).\n\n\\(P(y|X)=\\int_\\Theta P(\\mathbf y|X, \\theta)P(\\theta )d\\theta \\)\n\n\\subsubsection{Posterior predictive distribution}\n\nOnce we have calculated \\(P(\\theta |\\mathbf y, \\mathbf X)\\), we can calculate a posterior probability distribution for \\(P(y|X)\\).\n\n\\(P(y|\\mathbf x, \\mathbf y,  \\mathbf X )=\\int_\\Theta P(y|\\mathbf x, \\theta)P(\\theta |\\mathbf y, \\mathbf X)d\\theta \\)\n\n", "meta": {"hexsha": "f300a44ce160bb6d68c45b8066531f2ab0c8dbda", "size": 585, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/bayesianDiscriminative/02-02-prior.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/bayesianDiscriminative/02-02-prior.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/bayesianDiscriminative/02-02-prior.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.5625, "max_line_length": 130, "alphanum_fraction": 0.7162393162, "num_tokens": 166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541561135441, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.724207596638484}}
{"text": "\n\\subsection{Indifference curves}\n\nWe have \\(U=f(x,y)\\)\n\nAn indifference curve is a curve where a consumer is indifferent to all points on it.\n\n\\(f(x,y)=c\\)\n\n\\subsection{Marginal rate of substitution}\n\nThe marginal rate of substitution is the amount of one good that a customer is willing to give up for another.\n\nThis is the gradient of the indifference curve.\n\n\\(MRS(x_1, x_2)=\\dfrac{MU(x_1)}{MU(x_2)}\\)\n\n\\(MU(x_1) = \\dfrac{1}{x_1}\\alpha_1\\prod_i x_i^{\\alpha_i}\\)\n\\(MU(x_2) = \\dfrac{1}{x_2}\\alpha_2\\prod_i x_i^{\\alpha_i}\\)\n\n\\(MRS(x_1, x_2)=\\dfrac{\\dfrac{1}{x_1}\\alpha_1\\prod_i x_i^{\\alpha_i}}{\\dfrac{1}{x_2}\\alpha_2\\prod_i x_i^{\\alpha_i}}\\)\n\n\\(MRS(x_1, x_2)=\\dfrac{\\dfrac{1}{x_1}\\alpha_1}{\\dfrac{1}{x_2}\\alpha_2}\\)\n\n\\(MRS(x_1, x_2)=\\dfrac{\\dfrac{\\alpha_1}{x_1}}{\\dfrac{\\alpha_2}{x_2}}\\)\n\n", "meta": {"hexsha": "341dae9a0d949097b191320487e86b16a68ba1f8", "size": 790, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/consumer/01-02-indifference.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/consumer/01-02-indifference.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/consumer/01-02-indifference.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2592592593, "max_line_length": 116, "alphanum_fraction": 0.6848101266, "num_tokens": 317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761565, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.7242075953792014}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{examples}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% ============================================================================================\n\\bgroup\n\\CdbSetup{action=hide}\n\\begin{cadabra}\n   import cdblib\n   checkpoint_file = 'tests/semantic/output/example-01.json'\n   cdblib.create (checkpoint_file)\n   checkpoint = []\n\\end{cadabra}\n\\egroup\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 1 The metric connection}\n\n\\begin{cadabra}\n   # Define some properties\n\n   {a,b,c,d,e,f,h,i,j,k,l,m,n,o,p,q,r,s,t,u#}::Indices.\n\n   g_{a b}::Metric.\n   g_{a}^{b}::KroneckerDelta.\n\n   \\nabla{#}::Derivative.\n   \\partial{#}::PartialDerivative.\n\n   # Define rules for covariant derivative and the Christoffel symbol\n\n   nabla := \\nabla_{c}{g_{a b}} -> \\partial_{c}{g_{a b}} - g_{a d}\\Gamma^{d}_{b c}\n                                                         - g_{d b}\\Gamma^{d}_{a c}.   # cdb (nabla.100,nabla)\n\n   Gamma := \\Gamma^{a}_{b c} -> (1/2) g^{a d} (  \\partial_{b}{g_{d c}}\n                                               + \\partial_{c}{g_{b d}}\n                                               - \\partial_{d}{g_{b c}} ).   # cdb (Gamma.100,Gamma)\n\n   # Start with a simple expression\n\n   cderiv := \\nabla_{c}{g_{a b}}.                                           # cdb (ex-01.100,cderiv)\n\n   # Do the computations\n\n   substitute          (cderiv, nabla)                                      # cdb (ex-01.101,cderiv)\n   substitute          (cderiv, Gamma)                                      # cdb (ex-01.102,cderiv)\n   distribute          (cderiv)                                             # cdb (ex-01.103,cderiv)\n   eliminate_metric    (cderiv)                                             # cdb (ex-01.104,cderiv)\n   eliminate_kronecker (cderiv)                                             # cdb (ex-01.105,cderiv)\n   canonicalise        (cderiv)                                             # cdb (ex-01.106,cderiv)\n\n   checkpoint.append (cderiv)\n\\end{cadabra}\n\n\\clearpage\n\n\\begin{align*}\n   &\\Cdb{nabla.100}\\\\\n   &\\Cdb{Gamma.100}\n\\end{align*}\n\n\\begin{align*}\n   \\cdb{ex-01.100} &= \\Cdb{ex-01.101}\\\\\n                   &= \\Cdb{ex-01.102}\\\\\n                   &= \\Cdb{ex-01.103}\\\\\n                   &= \\Cdb{ex-01.104}\\\\\n                   &= \\Cdb{ex-01.105}\\\\\n                   &= \\Cdb{ex-01.106}\n\\end{align*}\n\n\\clearpage\n\n% ============================================================================================\n% export to json format\n\n\\bgroup\n\\CdbSetup{action=hide}\n\\begin{cadabra}\n   for i in range( len(checkpoint) ):\n      cdblib.put ('check{:03d}'.format(i),checkpoint[i],checkpoint_file)\n\\end{cadabra}\n\\egroup\n\n\\end{document}\n\n", "meta": {"hexsha": "93dcce7872797c90930d4ff793b5bc97b3f48738", "size": 2781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/example-01.tex", "max_stars_repo_name": "leo-brewin/cadabra-tutorial", "max_stars_repo_head_hexsha": "5b428ae158b5346315ab6c975dee9de933e5c3d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2019-12-20T07:49:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T22:55:47.000Z", "max_issues_repo_path": "source/cadabra/example-01.tex", "max_issues_repo_name": "leo-brewin/cadabra-tutorial", "max_issues_repo_head_hexsha": "5b428ae158b5346315ab6c975dee9de933e5c3d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/cadabra/example-01.tex", "max_forks_repo_name": "leo-brewin/cadabra-tutorial", "max_forks_repo_head_hexsha": "5b428ae158b5346315ab6c975dee9de933e5c3d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-22T13:52:19.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-22T13:52:19.000Z", "avg_line_length": 30.5604395604, "max_line_length": 109, "alphanum_fraction": 0.4444444444, "num_tokens": 752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7241817946106068}}
{"text": "% !TEX encoding = UTF-8 Unicode\n\\documentclass[12pt]{scrartcl}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\usepackage{url}\n\\usepackage[utf8]{inputenc}\n\\usepackage{units}\n\n\\author{Michael Kiefer}\\publishers{MaibornWolff GmbH, Versmannstr. 2, 20457 Hamburg}\n\\title{Calculations for the Clean-Air UVC device}\n\n\\begin{document}\n\\maketitle{}\n\n\\section{Concept}\nWe consider a set-up with air flowing through a cylinder, assuming the flow is independent of the position in the cylinder. At the center of the cylinder, we have the UVC lamp (a fluorescent tube). \nWe want to calculate the energy that gets deposited on a virus particle while passing through the cylinder. The worst case is a virus passing at the wall of the cylinder, with the greatest distance to the lamp.\n\nAt that position, we have an Irradiance $I$ as\n\\begin{equation}\nI   = \\frac{E}{A_{\\text{surface}}},  \\label{eqn:irradiance}\n\\end{equation}\nwith the Energy $E$ and the side surface of the cylinder $A_{\\text{surface}}$,\n\nThe outer surface of the tube is determined by the length $l$ and the radius $r$ of the tube as\n\n\\begin{equation}\nA_{\\text{surface}} = 2\\pi r l.  \\label{eqn:surface}\n\\end{equation}\n\nThe energy is determined by the power $P$ emitted by the lamps within the time $t$ that it takes for a volume element to pass through the irradiated part of the tube\n\n\\begin{equation}\nE = P  t  \\label{eqn:energy}\n\\end{equation}\n\nWe derive the time from the air flow $\\Phi$, the volume $V$ that passes through the tube in a given time.\n\\begin{align}\n\\Phi &= V / t\\\\\n\\Rightarrow t &=V / \\Phi\n\\end{align}\n\nThe volume is given by the geometry of the cylinder, using length and base area $A_{\\text{base}}$\n\\footnote{we do not use the cylinder's radius fo calculating the area here, as we want to keep it for the generalization in section \\ref{sect:multitube}.}\n\\begin{equation}\nV = l A_{\\text{base}} \\label{eqn:volume}\n\\end{equation}\n\nWith equations \\eqref{eqn:energy}, \\eqref{eqn:volume} and \\eqref{eqn:surface} in \\eqref{eqn:irradiance}, we obtain\n\\begin{equation}\nI =\\frac{P }{\\Phi } \\frac{A_{\\text{base}}}{2 \\pi r }\\label{eqn:irradiance_final}\n\\end{equation}\n\n\n\\section{Multiple lamps}\\label{sect:multitube}\nWe want to estimate the irradiance created by multiple lamps at a certain position in our setup. At such a position, we can calculate the irradiance $I_i $ caused by each of the lamps $i$ with \\eqref{eqn:irradiance_final} using the distance to the lamp as $r_{i}$. The resulting irradiance is simply the sum of these\\footnote{$P$ in this case is the sum of the powers of the individual lamps $P_i$.}.\n\\begin{equation}\nI_{\\text{total}}=  \\sum_{i} I_i = \\frac{P A_{\\text{base}}}{\\Phi 2 \\pi}  \\sum_{i} \\frac{1}{ r_i }\n\\end{equation}\n\nIn order to disable the virus particles, we need to expose them to a certain level of irradiation. With this targeted value $I_{\\text{target}}$ given, we can calculate the maximum flow $\\Phi_{\\text{max}}$ that our device can process as\n\n\\begin{equation}\n\\Phi_{\\text{max}}=  \\frac{P A_{\\text{base}}}{I_{\\text{target}} 2 \\pi}  \\sum_{i} \\frac{1}{ r_i }\n\\end{equation}\n\n\\section{Application to the MaibornWolff clean air device}\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.45\\linewidth]{images/PosA.png} % requires the graphicx package\n   \\includegraphics[width=0.45\\linewidth]{images/PosB.png} % requires the graphicx package\n   \\caption{Distances at position A (left) and B (right)}\n   \\label{fig:distances}\n\\end{figure}\n\nNumbers on the irradiation dose vary. \nIn order to deactivate coronavirus particles, \\cite {ozog}  says that an irradiation of $\\unit[10]{J/m^2}$ is sufficient. However, \\cite{bianco} says that an irradiation of $\\unit[37]{J/m^2}$ is needed. In \\cite{hessling} this value is given as the probable value for the log-reduction dose which would mean that such an irradiation would at least deactivate 90\\% of the virus particles. For the ongoing calculation, we aim at an irradiation with $\\unit[120]{J/m^2}$ which would mean a log-3 reduction in case of the number given by \\cite{hessling}.\n\nIn our set-up, the lamps each consume $\\unit[36]{W}$ in electrical power and emit $\\unit[12]{W}$ of UVC light.\n\nThe two sets of distances given in figure \\ref{fig:distances} describe the positions that are furthest away from the lamps and thus the places where the irradiation is the weakest.\n\nUsing the excel sheet attached in the source repository, we calculate that the maximum throughput the device can tend to is in the range of $\\unit[1000]{m^3/h}$. The WHO recommends an exchange rate of 6 air changes per hour \\cite{who}. Assuming a height of $\\unit[2.5]{m}$, this means that one device is appropriate for a room of up to $\\unit[66]{m^2}$.\n\n\n\\begin{thebibliography}{9}\n\n\\bibitem{hessling}\n   Heßling, Martin et al. \n   “Ultraviolet irradiation doses for coronavirus inactivation - review and analysis of coronavirus photoinactivation studies.”\n   GMS hygiene and infection control vol. 15 Doc08. \n   14 May. 2020, \n   doi: https://doi.org/10.3205/dgkh000343\n   \n\\bibitem{bianco}\n  Andrea Bianco et al.,\n  \"UV-C irradiation is highly effective in inactivating and inhibiting SARS-CoV-2 replication\"\n  medRxiv 2020.06.05.20123463\n  doi: https://doi.org/10.1101/2020.06.05.20123463 \n  \n\\bibitem{ozog}\n  David M. Ozog, et al.,\n  The Effect of Ultraviolet C Radiation Against SARS-CoV-2 Inoculated N95 Respirators\n  medRxiv 2020.05.31.20118588; doi: \\url{https://doi.org/10.1101/2020.05.31.20118588}\n\n\\bibitem{who}\n  Coronavirus disease (COVID-19): Ventilation and air conditioning in health facilities\n  29 July 2020  Q\\&A\n  \\url{https://www.who.int/news-room/q-a-detail/coronavirus-disease-covid-19-ventilation-and-air-conditioning-in-health-facilities}\n\n\\end{thebibliography}\n\n\\end{document}\n\n\n\n", "meta": {"hexsha": "4f2b2eedb265b837fbd9397373073dae2db95c61", "size": 5753, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/theory.tex", "max_stars_repo_name": "angrox/clean-air", "max_stars_repo_head_hexsha": "4489a3e38b04d5f6952c53de30e9190a60bae92a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2020-11-10T07:30:26.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-03T19:46:27.000Z", "max_issues_repo_path": "documentation/theory.tex", "max_issues_repo_name": "angrox/clean-air", "max_issues_repo_head_hexsha": "4489a3e38b04d5f6952c53de30e9190a60bae92a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 30, "max_issues_repo_issues_event_min_datetime": "2020-11-10T08:20:58.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-18T07:42:18.000Z", "max_forks_repo_path": "documentation/theory.tex", "max_forks_repo_name": "angrox/clean-air", "max_forks_repo_head_hexsha": "4489a3e38b04d5f6952c53de30e9190a60bae92a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-11-10T07:46:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T15:32:19.000Z", "avg_line_length": 48.3445378151, "max_line_length": 549, "alphanum_fraction": 0.7443073179, "num_tokens": 1720, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359876, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7241817830979046}}
{"text": "%---------------------------Relative Size Squared---------------------------\n\\section{Relative Size Squared\\label{s:hex-relative-size-squared}}\n\nConsider the ratio $D$ of the hex volume to the average volume of an ensemble of hexahedra:\n\\[\nD = \\frac{\\sum_{i=0}^7 \\alpha_i}{8\\overline{V}} = \\frac{\\alpha_8}{64\\overline{V}}.\n\\]\nThe relative size the minimum of $D$ and its inverse; and the relative size squared is\n\\[\n  q = \\left(\\min\\left\\{ D, \\frac {1}{D} \\right\\}\\right)^2 .\n\\]\n\nNote that if $\\overline{V} < DBL\\_MIN$ or $D \\leq DBL\\_MIN$, we set $q = 0$.\n\n\\hexmetrictable{relative size squared}%\n{$1$}%                                        Dimension\n{$[0.5,1]$}%                                  Acceptable range\n{$[0,1]$}%                                    Normal range\n{$[0,1]$}%                                    Full range\n{Dependent on $\\overline{V}$}%                Cube\n{\\cite{knu:03}}%                              Citation\n{v\\_hex\\_relative\\_size\\_squared}%            Verdict function name\n", "meta": {"hexsha": "cee1568a721b760f47b2c9b0fa757d6f77a13e19", "size": 1007, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexRelativeSizeSquared.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexRelativeSizeSquared.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexRelativeSizeSquared.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 43.7826086957, "max_line_length": 91, "alphanum_fraction": 0.5084409136, "num_tokens": 278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7241522714216404}}
{"text": "\n\n\nGenerating random signals, surfaces, and volumes is important for the study of stochastic scattering processes.  Stationary Gaussian random signals are fully characterized by the correlation function or, equivalently, the power spectral density (PSD), which take two parameters: root-mean-square (RMS) height and correlation length.  The correlation function can be anisotropic for two and three dimensions. The PSD is the average power envelope of a randomized frequency spectrum. To generate a random signal or surface from a PSD, each frequency of the sampled PSD is seeded with a complex standard Gaussian, and then an inverse Fourier transform is taken. Derivations of isotropic  Gaussian and exponential PSDs in one, two, and three dimensions can be found in \\cite{mack2011analytic}, which can be extended to the anisotropic cases. \n\nFractal surfaces are different creatures. They are Gaussian processes that exhibit self-similarity at different length scales. This means that the RMS height changes depending on the distance over which one measures it. The two parameters that characterize fractal surfaces are the RMS height (or RMS variation) at a given length scale and a Hurst exponent. Fractal surfaces are considered better representations of naturally occurring surfaces than those given by the exponential or Gaussian correlation functions.\n\nIn general, large domains and high sampling rates are required to generate scenes with correct statistics. The scene size should contain many correlation lengths and there should be a sufficient number of points to sample the highest spectral content. When these conditions are not met, the RMS of numerically generated signals is usually lower than the desired value, \\cite{mack2013generating}. A quick fix is to simply renormalize the surface RMS to the desired value. When the correlation length is less than the sample rate, or when the correlation length is equal to zero, surface points can simply be drawn as independent Gaussian random variables with a desired RMS. \n\nWe give routines for generating 1D, 2D, and 3D Gaussian random signals, surfaces, and volumes with Gaussian or exponential correlation functions, 1D fractal surfaces, as well as 3D bicontinuous media. We give a routine for generating ocean waves that have nonlinear dispersion relations. In addition, we provide a routine for generating spherical particles where the surface radius has log-normal statistics. Finally, a routine for creating 1D profiles of ionosphere irregularity is included. \n\n\n\\section{1D Random Signals}\n\\label{sec:1drandom}\nA 1D random signal could be a voltage signal, or a corrugated rough surface (like a corn field) that have variation in only one dimension. The process of generating a surface from a power spectral density is detailed in \\cite{mack2013generating,tsang2000scattering2}.  The autocorrelation of a zero mean stationary random process $f$ is given by \n\\begin{equation}\n< f(x_1) f(x_2) > = \\sigma^2 C(x_2-x_1)\n\\end{equation}\n\n\\noindent where $\\sigma$ is the root-mean-squared (RMS) variation and $C(\\Delta x)$ is the correlation function. Here the  correlation function is only a function of the difference of distances between points, or lag, $\\Delta x = x_2-x_1$. Gaussian and exponential correlation functions are given by\n\\begin{eqnarray}\nC(\\Delta x) &=& \\exp\\left(-\\dfrac{\\Delta x^2}{l_c^2}\\right) \\\\\nC(\\Delta x) &=& \\exp\\left(-\\dfrac{\\vert \\Delta x \\vert}{l_c}\\right) \n\\end{eqnarray}\n\nwith correlation length $l_c$. The corresponding power spectral densities are, respectively, \n\\begin{eqnarray}\nW(k_x) &=& \\dfrac{\\sigma^2 l_c}{2\\sqrt{\\pi}}\\exp\\left(-\\dfrac{k_x^2 l_c^2}{4}\\right)\\\\\nW(k_x) &=& \\dfrac{\\sigma^2 l_c}{\\pi\\left(1+k_x^2l_c^2\\right)} \n\\end{eqnarray}\n\n\n \\begin{figure}[t] \n   \\centering\n   \\subfigure{\\includegraphics[width=4in]{RandomObjects/Figures/gaussiansurf1} } \\\\\n    \\subfigure{\\includegraphics[width=4in]{RandomObjects/Figures/gaussiansurf2} }\n    \\caption{1D Gaussian random signals with Gaussian and exponential correlation functions generated from the same random seed. The vertical and horizontal axes are normalized by the RMS and correlation length, respectively. Note, signals with an exponential correlation function always have a discontinuous derivative no matter how finely they are sampled.}\n\\end{figure}\n\n\n\nThe spectrum of a 1D rough surface with physical length $L_x$ is given by\n\\begin{equation}\nF(k_x) = \\gamma(k_x)\\sqrt{\\delta k_x W(k_x)}\n\\end{equation}\n\n\\noindent where $\\delta k_x = 2 \\pi/ L_x$ and $\\gamma(k_x)$ is an independent draw from the complex standard normal distribution for each spatial frequency $k_x$.  It is $\\gamma$ that imparts randomness to each realization of the PSD.  The complex standard normal is defined:\n\\begin{equation}\n\\gamma = \\dfrac{1}{\\sqrt{2}}\\left( \\mathcal{N}(0,1) + i \\mathcal{N}(0,1)\\right)\n\\end{equation}\n\n\\noindent where $\\mathcal{N}(0,1)$ is the standard normal distribution with zero mean and unit variance. $\\gamma$ is normalized so that its variance is one.  Finally, the surface is realized with an inverse Fourier transform:\n\\begin{equation}\nf(x) = \\mathcal{F}_{k_x}^{-1}\\left[F(k_x)\\right]\n\\end{equation}\n\nAnother important quantity is the variance of the difference of surface heights as a function of lag. This is called the Allan variance. The square root of this quantity is the Allan deviation or RMS deviation. The deviation is zero at zero lag and grows following the correlation function until points separated by more than the correlation length become uncorrelated and the variance is equal to two times the variance of the underlying process. The variance at lag $\\Delta x$ is \n\\eq{v^2(\\Delta x) = 2 \\sigma^2 \\left(1 - C(\\Delta x)\\right)}\n\nThen the RMS deviation at lag $\\Delta x$ is \n\\eq{v(\\Delta x) = \\sqrt{2} \\sigma \\sqrt{\\left(1 - C(\\Delta x)\\right)}}\n\n\n\n%\n% \\begin{figure}[H] \n%   \\centering\n%   \\subfigure{\\includegraphics[width=3in]{RandomObjects/Figures/gaussiansurf} }\n%    \\subfigure{\\includegraphics[width=3in]{RandomObjects/Figures/gaussiancorr} }\\\\\n%     \\subfigure{\\includegraphics[width=3in]{RandomObjects/Figures/gaussiandev} }\n%    \\caption{1D Gaussian random signals with Gaussian and exponentially correlation functions. Note, a signal with exponential correlation function always has discontinuous derivative no matter how fine the sampling.}\n%\\end{figure}\n%\n\n\n\nThe routine \\texttt{rough1} generates a real-valued zero-mean 1D Gaussian random signal. The inputs are the number of points $N_x$, length of the signal $L_x$, RMS height $\\sigma$, correlation length $l_c$. Use string switch \\texttt{norm} or \\texttt{exp} for Gaussian or exponential correlation functions. When the correlation length is less than the sample size, and therefore the signal is not properly sampled, the routine returns independent draws from a Gaussian distribution at each point with the given RMS. When generating a real valued signal from its spectrum, we usually make the spectrum conjugate symmetric before taking the IFFT. Instead, it is easier to seed the PSD with samples from an unnormalized non-conjugate complex standard normal distribution and then take the real part of the IFFT.  Matlab's \\texttt{ifft} divides by the number of samples in each dimension, so to keep the transform independent of domain size, this factor has to be put back. The 1D PSDs are coded inline, but can be plotted separately by the routines \\texttt{psdnorm} and \\texttt{psdexp}.  \n\n\n  {\\footnotesize\n\\VerbatimInput{\\code/RandomObjects/rough1.m}\n}\n\n%\n%{\\footnotesize\n%\\VerbatimInput{\\code/RandomObjects/psdnorm.m}\n%}\n%\n%{\\footnotesize\n%\\VerbatimInput{\\code/RandomObjects/psdexp.m}\n%}\n\n%\n%\n% \\begin{figure}[h] \n%   \\centering\n%   \\includegraphics[width=4in]{RandomObjects/Figures/rough1} \n%   \\caption{1D Gaussian and exponentially correlated rough surfaces with 0.1 RMS and 3 m correlation length generated with the same random seed.  Note that the exponential correlation function yields a function with discontinuous derivative.}\n%\\end{figure}\n%\n% \\begin{figure}[h] \n%   \\centering\n%   \\includegraphics[width=4in]{RandomObjects/Figures/rough1_corr} \n%   \\caption{1D Gaussian and exponentially computed correlation functions. }\n%\\end{figure}\n\n\n\n\\section{2D Random Surfaces}\n\nA 2D random rough surface is like a beach or patch of dirt, which is a height map of two variables.  2D rough surfaces are created like 1D random signals, except that the PSDs acquire an extra dimension and scaling factors. In addition, anisotropic correlations are now possible. Gaussian and exponential correlation functions are given by\n\\ea{C(\\Delta x, \\Delta y) &=& \\exp\\left(-\\dfrac{\\Delta x^2}{l_{cx}^2}-\\dfrac{\\Delta y^2}{l_{cy}^2}\\right) \\\\\nC(\\Delta x, \\Delta y) &=& \\exp\\left(-\\sqrt{\\dfrac{\\Delta x^2}{l_{cx}^2} + \\dfrac{\\Delta y^2}{l_{cy}^2} }  \\right)}\n\nThe corresponding power spectral densities are \n\\ea{W(k_x,k_y) &=& \\dfrac{\\sigma^2 l_{cx} l_{cy}}{4\\pi}\\exp\\left(-\\dfrac{k_x^2 l_{cx}^2}{4}-\\dfrac{k_y^2 l_{cy}^2}{4}\\right) \\\\\nW(k_x,k_y) &=& \\dfrac{\\sigma^2 l_{cx}l_{cy}}{2\\pi\\left(1+k_x^2l_{cx}^2+k_y^2l_{cy}^2\\right)^{3/2}}}\n\nThe 2D frequency spectrum is given by\n\\begin{equation}\nF(\\bb{k}) = \\gamma(\\bb{k})\\sqrt{\\delta k_x \\delta k_y W(\\bb{k})} \n\\end{equation}\n\\begin{equation}\n\\begin{array}{ccc}\n\\delta k_x = \\dfrac{2\\pi}{L_x} & \\delta k_y = \\dfrac{2\\pi}{L_y} & k = \\sqrt{k_x^2 + k_y^2}\n\\end{array}\n\\end{equation}\n\nHere, $\\gamma(\\bb{k})$ is the complex standard normal distribution evaluated independently at each $\\bb{k}$.  \n\n\\begin{figure}[H] \n   \\centering\n \\subfigure{\\includegraphics[width=2.5in]{RandomObjects/Figures/rough2norm}}\n  \\subfigure{\\includegraphics[width=2.5in]{RandomObjects/Figures/rough2exp}}\n   \\caption{2D Gaussian and exponentially correlated rough surfaces generated with the same random seed. The surface height is normalized by the RMS, and the axes are normalized by the correlation length.}\n\\end{figure}\n\n\nThe routine \\texttt{rough2} generates a real-valued zero-mean 2D Gaussian random surface. The inputs are the number of points $N_x$, $N_y$ in each dimension, side lengths of the domain $L_x$, $L_y$, RMS height $\\sigma$, and correlation lengths in each dimension $l_{cx}$, $l_{cy}$. It returns the surface in \\texttt{meshgrid} format. Use string switch \\texttt{norm} or \\texttt{exp} for Gaussian or exponential correlation functions. As in the 1D case, we can avoid having to make the spectrum conjugate symmetric by drawing from the unnormalized non-conjugate complex standard normal and then simply taking the real part of the 2D IFFT. If the correlation lengths in both dimensions are less than their respective sample sizes, the surface heights are independent draws from a Gaussian distribution. If the correlation length of one dimension is less than its sample size, then we treat the other dimension as a collection of independent 1D rough surfaces. These provisions help maintain the correct RMS height when the PSD is poorly sampled. \n\n{\\scriptsize %\\footnotesize\n\\VerbatimInput{\\code/RandomObjects/rough2.m}\n}\n\n\\clearpage\n\n\n\\section{3D Random Volumes}\n\nA 3D rough volume represents random fluctuations in space, such as random dielectric material or density variations. The Gaussian and exponential correlation functions are\n\\ea{C(\\Delta x, \\Delta y, \\Delta z) &=& \\exp\\left(-\\dfrac{\\Delta x^2}{l_{cx}^2}-\\dfrac{\\Delta y^2}{l_{cy}^2} - \\dfrac{\\Delta z^2}{l_{cz}^2 }\\right) \\\\\nC(\\Delta x, \\Delta y, \\Delta z) &=& \\exp\\left(-\\sqrt{\\dfrac{\\Delta x^2}{l_{cx}^2} + \\dfrac{\\Delta y^2}{l_{cy}^2} + \\dfrac{\\Delta z^2}{l_{cz}^2} }  \\right)}\n\nThe corresponding power spectral densities are\n\\ea{W(k_x,k_y,k_z) &=& \\dfrac{\\sigma^2 l_{cx} l_{cy} l_{cz}}{8\\pi^{3/2}}\\exp\\left(-\\dfrac{k_x^2 l_{cx}^2}{4}-\\dfrac{k_y^2 l_{cy}^2}{4}-\\dfrac{k_z^2 l_{cz}^2}{4}\\right) \\\\\nW(k_x,k_y,k_z) &=& \\dfrac{\\sigma^2 l_{cx}l_{cy}l_{cz}}{3\\pi\\left(1+k_x^2l_{cx}^2+k_y^2l_{cy}^2+k_z^2l_{cz}^2\\right)^{2}} }\n\nThe spectrum is then \n\\begin{equation}\nF(\\bb{k}) = \\gamma(\\bb{k})\\sqrt{\\delta k_x \\delta k_y \\delta k_z W(\\bb{k})} \n\\end{equation}\n\\begin{equation}\n\\begin{array}{cccc}\n\\delta k_x = \\dfrac{2\\pi}{L_x} & \\delta k_y = \\dfrac{2\\pi}{L_y} & \\delta k_z = \\dfrac{2\\pi}{L_z} & k = \\sqrt{k_x^2 + k_y^2 + k_z^2}\n\\end{array}\n\\end{equation}\n\n\n \\begin{figure}[H] \n    \\subfigure{\n   \\includegraphics[width=3in]{RandomObjects/Figures/gauss3Dnorm} } \n   \\subfigure{\n    \\includegraphics[width=3in]{RandomObjects/Figures/gauss3Dexp} } \n   \\caption{3D Gaussian and exponential correlated random volumes generated with the same seed. The function value is normalized by the RMS, and the axes are normalized by the correlation length.}\n\\end{figure}\n\n\n\nThe routine \\texttt{rough3} generates a real-valued zero-mean 3D Gaussian random volume. The inputs are the number of points $N_x$, $N_y$, $N_z$ in each dimension, side lengths of the domain $L_x$, $L_y$, $L_z$, RMS fluctuation $\\sigma$, and correlation lengths in each dimension $l_{cx}$, $l_{cy}$, $l_{cz}$.  It returns the volume in \\texttt{meshgrid} format. Use string switch \\texttt{norm} or \\texttt{exp} for Gaussian or exponential correlation functions. If the correlation lengths in all dimensions are less than their respective sample sizes, the values are independent draws from a Gaussian distribution. If correlation lengths in two dimensions are less than their sample sizes, the third dimension is composed of independent 1D random signals. If the correlation length of one dimension is less than its sample size, the other two dimensions are independent 2D random signals. \n\n\\clearpage\n{\\footnotesize\n\\VerbatimInput{\\code/RandomObjects/rough3.m}\n}\n\n\n\\clearpage\n\\newpage\n\n\\section{1D Fractal Signals}\n\nFractal signals are a class of Gaussian random process that are self-similar at increasing length scales. In short, the RMS grows as the profile length grows. Equivalently, these signals describe fractional Brownian motion, of which traditional Brownian motion is a subset. For in-depth explanations of fractal surfaces, theory, and relation to natural surfaces, see \\cite{shepard1995self,shepard1999radar}. For details on computing these signals quickly, see \\cite{kroese2015spatial}.  \n\nThe statistics of 1D fractal signals are described by either an RMS height (or variance) over all points which depends on total length of the profile, or the RMS deviation (or Allan variance), that depends on the relative positions, or lag, between pairs of points. For a 1D profile with height $z(x)$, the variance of the heights is computed as \n\\eq{\\sigma^2 = \\left< (z - \\bar{z})^2 \\right> }\n\nand the Allan variance is computed as\n\\eq{v^2 = \\left< (z(x) - z(x + \\Delta x))^2 \\right>}\n\n\\noindent where $ \\Delta x$ is the lag and $\\left< \\right>$ is the ensemble average.  For natural fractal surfaces, these quantities can be described by a power law such that the RMS height over the entire profile length, $x$, is\n\\eq{\\sigma(x) = \\sigma_o \\left( \\dfrac{x}{x_o}\\right)^H \\label{rmsh} }\n\n\\noindent where $\\sigma_o$ is the RMS height at length scale $x_o$, and $H$ is the Hurst exponent, which takes values $0 \\le H \\le 1$. Alternatively, the surface can be described by a power law such that the RMS deviation (Allan deviation, or just deviation) at lag $\\Delta x$ is given by\n\\eq{v(\\Delta x) = v_o \\left( \\dfrac{\\Delta x}{\\Delta x_o}\\right)^H \\label{rmsv}}\n\n\\noindent where $v_o$ is the RMS deviation at lag $\\Delta x_o$, and $\\Delta x$ is the lag at which we evaluate the deviation. The Hurst exponent controls the growth of the surface over distance, while the other parameters simply scale the result. The statistics of both the surface height and variation are Gaussian. When $H=1/2$ the process becomes standard 1D Brownian motion.\n\n\\begin{figure}[H] \n   \\centering\n   \\subfigure{\\includegraphics[width=3.2in]{RandomObjects/Figures/fracsurf}} \n   \\subfigure{\\includegraphics[width=3.2in]{RandomObjects/Figures/fracdiffvrms}}\n   \\caption{Top: 1D fractal profiles generated from the same seed.  Bottom: RMS deviation relative to $x = 0$, $v(\\Delta x)$, analytic and numeric computed over 500 trials. This shows how the deviation of the fractal surface continues to grow with length scale. }\n\\end{figure}\n\n\nFrom \\cite{shepard1995self}, the RMS slope is defined\n\\eq{s_{rms} = \\sqrt{\\left< \\left(\\dfrac{\\Delta z}{\\Delta x}\\right)^2 \\right > }}\nThe RMS of $\\Delta z$ is just \\eqref{rmsv}, therefore, the RMS slope is\n\\eq{s_{rms} = \\dfrac{v(\\Delta x)}{\\Delta x} = v_o \\left( \\dfrac{\\Delta x}{\\Delta x_o}\\right)^{H-1} \\label{rmsslope} }\n\n\n%From \\cite{kroese2015spatial}, the covariance of the random variables of two heights, $X_1$ and $X_2$, at two points $x_1$ and $x_2$, is given by \n%\n%\\eq{\\textrm{Cov}[X_1,X_2] = \\dfrac{1}{2}\\left(\\vert x_1 \\vert^{2H} + \\vert x_2 \\vert^{2H}  - \\vert x_1 - x_2 \\vert^{2H}\\right)}\n\n%For example, the PDF of surface variation $\\bar{z} = z - z(0)$ as a function of lag is \n%\\eq{f_z(\\bar{z} \\vert \\Delta x) = \\dfrac{1}{\\sqrt{2\\pi} v(\\Delta x)}\\exp\\left(-\\dfrac{1}{2}\\dfrac{\\bar{z}^2}{ v^2(\\Delta x)}\\right)}\n\n\nThe routine \\texttt{fractal1} generates a zero-mean 1D fractal signal based on the routine in \\cite{kroese2015spatial}, to which we have added options for normalization by RMS height or RMS deviation. It takes as input the pair ($\\sigma_o$, $x_o$) or ($v_o$, $\\Delta x_o$), the Hurst exponent $H$, the number of sample points, and the length of the profile. Use string switch \\texttt{'rms'} or \\texttt{'dev'} for normalization by RMS height or RMS deviation. The signal generated by \\cite{kroese2015spatial} was found to scale perfectly for RMS deviation, \\eqref{rmsv}. For RMS height, the signal is simply rescaled by \\eqref{rmsh}. \n\n{\\footnotesize\n\\VerbatimInput{\\code/RandomObjects/fractal1.m}\n}\n\n\n\n\\clearpage\n\\newpage\n\n\\section{Bicontinuous Random Media}\n\nBicontinuous random media are used to model 2-species material with different levels of connectivity. For example, these have been used to model the distribution of ice/void volumes of settled snow that have different amounts of melting and compaction, \\cite{ding2010electromagnetic,xu2012electromagnetic,chang2016microwave,tan2016uniaxial}. Bicontinuous random media partition the volume into binary regions by cutting a fluctuating 3D field at a prescribed level and then assigning the material based on whether the value of the field is above or below the level cut at a given point. The field has Gaussian statistics, therefore the cutting level corresponds to the volume fraction of the binary regions. We outline the components of the model given in \\cite{ding2010electromagnetic,xu2012electromagnetic} for isotropic bicontinuous random media, while an anisotropic model can be found in \\cite{tan2016uniaxial}.\n\n\\paragraph{Distribution} The 3D fluctuating field is a sum of random plane waves \n\\eq{S(\\br) = \\dfrac{1}{\\sqrt{N}} \\sum_{n=1}^N \\cos\\left(\\bb{k}_n \\cdot \\br + \\phi_{n} \\right) \\label{flutuatingfieldbicont}}\n\n\\noindent where $S(\\br)$ is the fluctuating field, $N$ is the number of wave vector directions, $\\bb{k}_n$ is the wave vector, and $\\phi_n$ is a random phase. The wave vector directions, $\\hat{k}_n$, are distributed uniformly random over the sphere. The wave vector magnitudes, $k_n$, are drawn from a gamma distribution. The phase is drawn from a uniform random variable between 0 and $2\\pi$.  The gamma distribution for the wave vector amplitudes is given by, \\cite{ding2010electromagnetic},\n\\eq{p(k) = \\dfrac{1}{\\Gamma(b+1)}\\dfrac{(b+1)^{b+1}}{\\left< k\\right>} \\left(\\dfrac{k}{\\left< k\\right>}\\right)^b e^{-(b+1) \\frac{k}{\\left< k\\right>}} \\label{gammasnow}}\n\n\\noindent where $\\Gamma$ is the gamma function, $\\left< k\\right>$ is the mean wavenumber and $b$ is a constant. Physically, $\\left< k\\right>$ corresponds to the reciprocal of the average length scale of heterogeneity (average snow grain size), while $b$ corresponds to the width of the distribution (spread of snow grain size) \\cite{xu2012electromagnetic}. Despite its appearance, \\eqref{gammasnow} is equivalent to the common form of the gamma distribution that has shape parameter $b+1$ and scale parameter $\\left< k\\right>/(b+1)$. These parameters are needed to draw samples from built-in routines. The mean of the distribution is $\\left< k\\right>$ and the standard deviation is $\\sigma = \\left< k\\right>/\\sqrt{b+1}$.\n\nAn indictor function is used to assign the binary classification to each point in the field based on a level cut. The indicator function is \n\\eq{\\Theta(S(\\br)) = \\begin{cases} 1, & S(\\br) > \\alpha \\\\\n0, & S(\\br) \\le \\alpha \\end{cases}}\n\n\\noindent where $\\Theta(\\br)$ is the indicator function and $\\alpha$ is the cutting level.  The statistics of the field are zero-mean Gaussian with variance 1/2. Because of this, the fractional volume, $f_v$, of the 1 indicator is related to the cutting level as \n\\eq{f_v = \\dfrac{1}{2}\\left(1 - \\textrm{erf}(\\alpha)\\right)}\n\n\\noindent where $\\textrm{erf}$ is the error function.  The cutting level is given in terms of the fractional volume as \n\\eq{\\alpha = \\textrm{erf}^{-1}\\left(1 - 2f_v\\right)}\n\n\\noindent where $\\textrm{erf}^{-1}$ is the inverse error function.\n\nThe construction of \\eqref{flutuatingfieldbicont} as a sum over spatial plane waves has several interesting consequences. The direct sum, together with the fact that $N$ needs to be large, makes the computation slow over a large number of points. In \\cite{ding2010electromagnetic} a value of $N = 10^4$ is used, though we have found that $N=10^3$ suffices. Also, because this does not use a PSD, FFT methods cannot be used to accelerate the computation. However, precisely because \\eqref{flutuatingfieldbicont} is spatially sampled and not based on a PSD or FFT, the 3D field and indicator function can be computed at arbitrary points, for example, along 1D lines, 2D sheets, or 3D volumes. This allows large volumes to be computed in pieces by using the same random seed.\n\n\\newpage \n\\paragraph{Correlation Function}\n\nThe spatial correlation function of $\\Theta(\\br)$ is radially symmetric and given by, \\cite{ding2010electromagnetic}, \n\\eq{\\Gamma_{\\alpha}(r) = f_v^2 + C_{\\alpha}(r)}\n\n\\noindent where \n\\ea{C_{\\alpha}(r) &=& \\sum_{m=1}^{\\infty} C_m(\\alpha) \\left[ C_s(r)\\right]^m \\\\\nC_m(\\alpha) &=& \\dfrac{e^{-2\\alpha^2} \\left[H_{m-1}(\\alpha)\\right]^2}{\\pi m! 2^m} \\\\\nC_s(r) &=& \\dfrac{\\sinc(b\\varphi)}{\\sinc(\\varphi)} \\cos^{b+1}(\\varphi) \\\\\n\\varphi &=& \\textrm{tan}^{-1}\\left(\\dfrac{\\left< k\\right> r}{b+1} \\right)}\n\n\\noindent where $C_{\\alpha}(r) = \\Gamma_{\\alpha}(r) - f_v^2$ and $C_s(r)$ is the autocovariance of $S(\\br)$. The coefficients, $C_m(\\alpha)$, are given in terms of the Hermite polynomials, $H_m(x)$. In addition, $\\sinc(x) = \\sin(x)/x$.  Finally, $\\Gamma_{\\alpha}(0) = f_v$, $\\Gamma_{\\alpha}(\\infty) = f_v^2$, $C_s(0) = 1$, and $C_s(\\infty) = 0$. \n\n%The coefficients $C_m(\\alpha)$ can be computed using the log transform, $C_m(\\alpha) = e^{\\ln C_m(\\alpha)}$, and the following recursion relation\n%\\ea{\\ln C_{m+1}(\\alpha) &=& \\ln C_m(\\alpha) + 2(\\ln H_{m} - \\ln H_{m-1}) - \\ln (m+1)  - \\ln 2 \\\\\n%\\ln C_{1}(\\alpha) &=&  -2\\alpha^2 - \\ln\\pi  - \\ln 2 }\n%\n%\\ea{\\ln C_m(\\alpha) &=& -2\\alpha^2 + 2\\ln H_{m-1} - \\ln\\pi - \\ln m! - m \\ln 2 \\\\\n%\\ &=& -2\\alpha^2 + 2\\ln H_{m-1} - \\ln\\pi - \\sum_{k=1}^m \\ln k - m \\ln 2}\n%\n%Evaluating at $m+1$\n%\\ea{\\ln C_{m+1}(\\alpha) &=& -2\\alpha^2 + 2\\ln H_{m} - \\ln\\pi - \\sum_{k=1}^{m+1} \\ln k- (m+1) \\ln 2 \\\\\n%&=& -2\\alpha^2 + 2\\ln H_{m}  + 2\\ln H_{m-1}  - 2\\ln H_{m-1} - \\ln\\pi - \\sum_{k=1}^m \\ln k - \\ln (m+1) - m \\ln 2 - \\ln 2 \\\\\n%&=& \\ln C_m(\\alpha) + 2(\\ln H_{m} - \\ln H_{m-1}) - \\ln (m+1)  - \\ln 2}\n%\n%Finally, the Hermite polynomials can be computed inline with the recursion \n%\\eq{H_{m+1}(x) = 2xH_m(x) - 2mH_{m-1}(x)}\n%\n%and initial conditions $H_0(x) = 1$ and $H_1(x) = 2x$. \n\n \\begin{figure}[H] \n \\centering\n   \\includegraphics[width=4.5in]{RandomObjects/Figures/bicont} \n      \\caption{Bicontinuous random media for $l_{ave} = 2\\pi/\\left< k\\right> = 5$ mm, $b= 10$, and $f_v$ = 0.3. The 2D slices of the same field are computed separately by running the routine again with the same random seed. }\n\\end{figure}\n\n\n\\paragraph{Routine}\n\nThe routine \\texttt{bicont} returns the bicontinuous indicator function, $\\Theta(\\br)$. It takes as input the arrays of the Cartesian coordinates $\\br = (x,y,z)$, which can be any size, the mean length scale of the heterogeneity, $l_{ave}$, spreading parameter, $b$, and fractional volume, $f_v$. The mean length scale is converted to mean wavenumber as $\\left<k\\right> = 2\\pi/l_{ave}$. $l_{ave}$ needs to have the same units as the coordinates. The number of plane waves, $N$, is optional and defaults to $N=10^3$. Random plane directions are computed with our routine \\texttt{randsphere}. This relies on Matlab routines \\texttt{gamrnd} and \\texttt{erfinv} which require certain toolboxes. The fluctuating field, $S(\\br)$, is an optional output. \n\n%Finally, the routine \\texttt{bicontcorr} returns the three correlation functions, $\\Gamma_{\\alpha}(r)$, $C_{\\alpha}(r)$, and $C_s(r)$, computed with the recursion method above using inputs of radial distance, $r$, and distribution parameters $l_{ave}$, $b$, and $f_v$.\n\n\\clearpage\n{\\footnotesize\n\\VerbatimInput{\\code/RandomObjects/bicont.m}\n}\n\n%\\newpage\n\n%\\section{2D Fractal Surfaces}\n\n\n\\newpage\n\n\\section{Ocean Waves}\n\nOcean wave scenes are generated as a 2D rough surface. Ocean waves have a nonlinear dispersion relation, so some care is needed when deriving the power spectral density. Models for temporal evolution also come in linear and nonlinear flavors, but all use the same underlying PSD. Note, only one realization of the ocean spectrum is needed in order to evolve the surface in time.\n  \n\\begin{figure}[h] \n   \\centering\n   \\includegraphics[width=4in]{RandomObjects/Figures/pmspectrum} \n   \\caption{Pierson-Moskowitz spectrum for $U_{10} = 3$ m/s}\n\\end{figure}\n\nThe classic Pierson-Moskowitz (PM) omnidirectional wave spectrum for fully developed ocean waves is \n\\begin{equation}\nF(f) = \\dfrac{\\alpha g^2}{\\left(2\\pi\\right)^4 f^{5}} \\textrm{exp}\\left[-(5/4)\\left(\\dfrac{f_p}{f}\\right)^4\\right]\n\\end{equation}\n\n\\noindent where $\\alpha = 0.0081$ is the Phillips constant, $g = 9.81$ m/s$^2$ is gravitational acceleration, $f$ is the spectral frequency, and $f_p$ is the peak frequency, both frequencies have units of Hz \\cite{alves2003revisiting}.  This is an omnidirectional spectrum; angular variation will be added later to account for wind direction. The peak frequency is given empirically as \n\\begin{equation}\nf_p = 0.13 \\dfrac{g}{U_{10}}\n\\end{equation}\n\n\\noindent where $U_{10}$ is the wind speed 10 meters above the mean surface level.  The variance of the wave height is given by the integral over the density function \n\\eq{\\sigma^2 = \\int_0^{\\infty} F(f) df  = \\dfrac{\\alpha g^2}{\\left(2\\pi\\right)^4 5 f_p^4 }}\n\nThe RMS wave height is then \n\\eq{\\sigma = \\dfrac{\\sqrt{\\alpha} g}{\\left(2\\pi\\right)^2 \\sqrt{5} f_p^2 } \\label{oceanrms} }\n\nThe dispersion relation for ocean waves is $\\omega^2  = g k$ from which it follows that the phase velocity, group velocity, and wavelength are\n\\begin{eqnarray}\nv_p &=& \\dfrac{\\omega}{k} = \\sqrt{\\dfrac{g}{k}} \\\\\nv_g &=& \\dfrac{d\\omega}{dk} = \\dfrac{g}{2\\omega} \\\\\n\\lambda & = & \\dfrac{g}{2 \\pi f^2}\n\\end{eqnarray}\n\nTo create wave scenes, the omnidirectional spectrum given in frequency needs to be converted to 2D $k$-space.  This requires a change of variables.  If one desires the 1D ocean spectra in $k$-space, the change of variables via the Jacobian is explained in \\cite{tolman2009user}.  How to convert to the 2D omnidirectional spectra is explained in \\cite{plant2009ocean} and repeated here.  The total wave height variance integrated over all angles must not depend on the independent variable, $f$ or $k$.  This condition is met when \n\\begin{equation}\n\\int F(k) k dk = \\int F(f) df\n\\end{equation}\n\n\\noindent which yields the change of variables\n\\begin{equation}\nF(k) = F(f) \\dfrac{df}{k dk} = F(f) \\dfrac{d\\omega}{2\\pi k dk} = F(f) \\dfrac{v_g}{2\\pi k}\n\\end{equation}\n\n\\noindent where $F(k)$ is the 2D omnidirectional spectrum.  Next, the 2D PSD is the product of the omnidirectional spectrum and an angle dependent spreading function \\cite{soriano2006doppler}:\n\\begin{equation}\nW(\\bb{k}) = F(k)\\phi(\\theta)\n\\end{equation}\n\n\\noindent where $\\bb{k}$ is the 2D wavenumber and $(k,\\theta)$ are its polar coordinates.  The spreading function can take a few forms, most are some power of $\\cos(\\theta)$, given in \\cite{soriano2006doppler} as\n\\begin{equation}\n\\phi(\\theta) = \\dfrac{1}{N} \\biggl \\vert \\cos^5\\left(\\dfrac{\\theta-\\theta_{\\textrm{v}}+\\pi}{2}\\right) \\biggr \\vert\n\\end{equation}\n\n\\noindent where $\\theta_{\\textrm{v}}$ is the direction from which the wind is blowing (meteorological convention).  The normalization is $N = \\int_{-\\pi}^{\\pi} \\vert \\cos^5(\\theta/2)\\vert d\\theta = 32/15$.  More general spreading functions are given in \\cite{hasselmann1980directional,niedzwecki1991comparative}.  A factor of $\\pi$ has been added to the argument to give the spectrum the correct orientation relative to our definition of the wind direction, the $k$-vectors, and FFT convention.  \n\n\\begin{figure}[htbp] \n   \\centering\n   \\includegraphics[width=2.5in]{RandomObjects/Figures/oceanPSD} \n   \\caption{2D ocean PSD (normalized) for $U_{10} = 3$ m/s, and $\\theta_{\\textrm{v}} = 35^o$. Most waves travel downwind, some have an upwind component, none travel directly upwind.}\n\\end{figure}\n\nFrom \\cite{soriano2006doppler, niedzwecki1991comparative}, the complex amplitude of the wave heights at time $t$ is given by\n\\begin{equation}\nA(\\bb{k},t) = \\gamma(\\bb{k})\\sqrt{\\delta k_x \\delta k_yW(\\bb{k})} e^{-i\\omega t}\n\\end{equation}\n\n\\noindent where $\\gamma(\\bb{k})$ is the complex standard Gaussian distribution.  $\\omega$ is replaced with the dispersion relation, $\\sqrt{gk}$, giving a spectrum in terms of $k$ and $t$. The effect of the nonlinear dispersion relation is that different parts of the spatial spectrum oscillate at different rates in time.  The steps are $\\delta k_x = 2\\pi/L_x$ and $\\delta k_y = 2\\pi/L_y$ where $L_x$ and $L_y$ and the lengths for domain in each dimension.   \n\nFor a linear sea surface, the surface height is the real part of the 2D inverse Fourier transform of the complex amplitudes.  \n\\begin{equation}\nA(\\bb{x},t) = \\textrm{Re} \\mathcal{F}_{\\bb{k}}^{-1}\\left[A(\\bb{k},t)\\right]\n\\end{equation}\n\nA collection of nonlinear ocean wave models can be found in \\cite{osborne2010nonlinear}.  A simple nonlinear model is the Creamer 2 surface, \\cite{soriano2006doppler}. It adds a term to the spectrum, which modifies the features of the peaks and troughs slightly. The additional spectral term is \n\\eq{C_t^2(\\bb{k}) = -\\dfrac{k_x^2}{2k}\\mathcal{F}\\left[h_{t_x}^2\\right] -\\dfrac{k_xk_y}{k}\\mathcal{F}\\left[h_{t_x}h_{t_y}\\right]  -\\dfrac{k_y^2}{2k}\\mathcal{F}\\left[h_{t_y}^2\\right]   }\n\n\\noindent where $h_{t_x}$ and $h_{t_y}$ are the components of the Hilbert transform of the surface\n\\eq{\\bb{h}_t(\\bb{x}) = \\textrm{Re}\\sum_{\\bb{k}} \\left(-i\\dfrac{\\bb{k}}{k}\\right) A_t(\\bb{k}) e^{i\\bb{k}\\cdot\\bb{x}} }\n\nThe Hilbert transform is computed in the spatial frequency domain.  Numerically, the infinite values that result from divide by $k=0$ are zeroed out, and a wide radial low pass filer is applied to $C_t^2(\\bb{k})$ to clean the spectrum before the last transform.  The filter used is \n\\eq{B(k) = \\dfrac{1}{1 + \\left(\\dfrac{k}{k_c}\\right)^{\\mu}} }\n\n\\noindent where $k_c$ is the cutoff, and $\\mu$ controls the roll off.  Values of $k_c = 5$ and $\\mu = 8$ have been used.  The final surface is the sum of linear and nonlinear surfaces\n\\eq{A_t(\\bb{x}) = \\textrm{Re} \\mathcal{F}^{-1}\\left[ A_t(\\bb{k}) + B(k)C_t^2(\\bb{k})\\right] }\n\n\n\\begin{figure}[htbp] \n   \\centering\n   \\includegraphics[width=3in]{RandomObjects/Figures/oceansurfaceheight} \n   \\caption{Simulated wave heights at $t=0$ for $U_{10} = 3$ m/s, and $\\theta_{\\textrm{v}} = 35^o$.}\n   \\label{fig:3}\n\\end{figure}\n\n\nThe function \\texttt{psdOcean} produces the 2D ocean wave PSD as a combination of the Pierson-Moskowitz 1D omnidirectional spectrum and a wind direction spreading function. It also returns the $k$-space components which are needed to evolve the surface.  The routine \\texttt{evolveOcean} creates the surface at one instance in time, taking as inputs the ocean PSD and wavenumber components from \\texttt{psdOcean} and one realization of $\\gamma$.  Use the string switch \\texttt{creamer2} to activate the nonlinear term. Numerically, the RMS wave height of the generated ocean surface does not always match the analytical value, therefore, consider renormalizing the surface RMS to the value given by \\eqref{oceanrms}. \n\n\n{\\scriptsize\n\\VerbatimInput{\\code/RandomObjects/psdOcean.m}\n}\n\n{\\scriptsize\n\\VerbatimInput{\\code/RandomObjects/evolveOcean.m}\n}\n\n%\\begin{figure}[htbp] \n%   \\centering\n%   \\includegraphics[width=3.5in]{waveseries} \n%   \\caption{Time series of wave heights.  Left to right, top to bottom, for $t = [0,1]$ seconds sampled at 0.125 seconds.  }\n%   \\label{fig:4}\n%\\end{figure}\n\n\\newpage\n\n\\section{Gaussian Random Particles}\n\nIn this section we give a procedure for creating and computing a spherical particle with Gaussian surface roughness. This is based on the formulation in \\cite{muinonen1996light}. Specifically, the radius of the particle surface has log-normal statistics and the radii are correlated through a circular isotropic Gaussian angular correlation function. We have added 1) a derivation for the spherical harmonic expansion coefficients of the angular correlation function, which was not included in the paper, 2) computation using normalized Legendre polynomials, as well as 3) a stable way to carry out the computation in the small correlation limit.\n\n%\\subsubsection{Log-normal Radius}\n\\paragraph{Log-normal Radius}\nFrom \\cite{muinonen1996light}, the particle radius at spherical coordinate $(\\theta,\\phi)$ is described by the log-normal distribution\n\\eq{r(\\theta,\\phi) = \\dfrac{a}{\\sqrt{1 + \\sigma^2}} \\exp\\left[s(\\theta,\\phi) \\right]}\n\n\\noindent which has mean $a$, and variance $a^2\\sigma^2$, where $s(\\theta,\\phi)$ is a zero-mean Gaussian random variable at each point $(\\theta,\\phi)$ with variance $\\beta^2$.  The covariance of $s$ between two spherical points $(\\theta_i,\\phi_i)$, $(\\theta_j,\\phi_j)$ is given by \n\\eq{\\Sigma_{s,ij} = \\beta^2 C_s(\\gamma_{ij})}\n\n\\noindent where $\\gamma_{ij}$ is the angular correlation between directions $i$ and $j$ and $C_s$ is the correlation function.  The covariances and distribution parameters are related as \n\\ea{\\Sigma_{r,ij} &=& a^2 \\left[ \\exp(\\Sigma_{s,ij}) - 1 \\right] \\\\\n\\sigma^2 C_r &=& \\exp(\\beta^2 C_s) - 1 \\\\\n\\sigma^2 &=& \\exp(\\beta^2) - 1}\n\n\n%\\subsubsection{Spherical Harmonic Expansion}\n\\paragraph{Spherical Harmonic Expansion}\nThe random variable, $s$, and angular correlation function are expressed in terms of real-valued spherical harmonics and associated Legendre polynomials, respectively, as\n\\eq{s(\\theta,\\phi) = \\sum_{l=0}^{\\infty} \\sum_{m=0}^l P_l^m(\\cos\\theta)(a_{lm}\\cos(m\\phi) + b_{lm} \\sin(m\\phi)) \\label{expansion} }\n\\eq{C_s(\\gamma) = \\sum_{l=0}^{\\infty} c_l P_l(\\cos\\gamma) \\label{correlationexp}}\n\n\\noindent where $a_{lm}$ and $b_{lm}$ are zero-mean Gaussian random variables with variance \n\\eq{\\beta^2_{lm} = (2- \\delta_{m,0}) \\dfrac{(l-m)!}{(l+m)!} \\beta^2 c_l }\n\nThe correlation function is chosen as a spherical Gaussian of the form:\n\\ea{C_s(\\gamma) &=& \\exp\\left( -\\dfrac{2}{ l_c^2} \\sin^2(\\gamma/2) \\right)  \\label{correlation} \\\\ \nl_c &=& 2 \\sin(\\Gamma/2) }\n\n\\noindent where $l_c$ is the angular correlation (unitless) and $\\Gamma$ is the correlation angle (radians). The function is circular such that the derivative at $\\gamma=0$ and $\\gamma=\\pi$ is zero. The maximum correlation angle is $\\Gamma = \\pi$, for which the value at the maximum angle of separation, $\\gamma = \\pi$, is $\\exp(-1/2) \\approx 0.61$. Using \\eqref{correlationexp}, \\eqref{correlation} and orthogonality (derivation below) the expansion coefficients for the correlation function are \n\\eq{c_l  = (2l+1) \\exp\\left( -\\dfrac{1}{l_c^2}\\right)  i_l\\left( \\dfrac{1}{l_c^2}\\right)}\n\n\\noindent where $i_l(x)$ is the modified spherical Bessel function of the first kind. The number of required harmonics in the expansion increases as the correlation length decreases.  \\cite{muinonen1996light} uses the following heuristic for 5 digits of precision:\n\\eq{L_{max} = \\dfrac{275^o}{\\Gamma} + 2.5}\n\n\\begin{figure}[h] \n   \\centering\n   \\includegraphics[width=3.5in]{RandomObjects/Figures/GaussianParticles/csgamma} \n   \\caption{Angular correlation function, $C_s(\\gamma)$.}\n   \\label{}\n\\end{figure}\n\n\n%\\subsubsection{Derivation of $c_l$}\n\\paragraph{Derivation of $c_l$}\nA derivation for $c_l$ was not included in \\cite{muinonen1996light}.  Applying orthogonality of the Legendre polynomials in \\eqref{correlationexp}, the expansion coefficients of the correlation function are generally\n\\eq{c_l    = \\dfrac{2l+1}{2}\\int_0^{\\pi} C_s(\\gamma) P_l(\\cos\\gamma) \\sin\\gamma d \\gamma }\n\n%Applying orthogonality to \\eqref{correlationexp}\n%\\eq{\\int_0^{\\pi} C_s(\\gamma) P_n(\\cos\\gamma) \\sin\\gamma d \\gamma  = \\int_0^{\\pi}\\sum_{l=0}^{\\infty} c_l P_l(\\cos\\gamma)P_n(\\cos\\gamma) \\sin\\gamma d \\gamma}\n%\n%and using the relations\n%\\eq{x = \\cos\\gamma }\n%\\eq{\\gamma = \\arccos x }\n%\\eq{\\int_{-1}^{1} P_n(x) P_m(x) dx = \\dfrac{2}{2 n + 1} \\delta_{mn}}\n\nUsing $\\sin^2(\\gamma/2) = (1 - \\cos \\gamma)/2$, the correlation function can be written\n\\eq{C_s(\\gamma) = \\exp\\left( -\\dfrac{1}{ l_c^2} (1 - \\cos\\gamma) \\right) =  \\exp\\left( -\\dfrac{1}{ l_c^2}\\right)\\exp\\left(\\dfrac{1}{ l_c^2} \\cos\\gamma \\right)}\n\n\\noindent after which the integral becomes\n\\eq{c_l    = \\dfrac{2l+1}{2} \\exp\\left( -\\dfrac{1}{ l_c^2}\\right)  \\int_0^{\\pi} \\exp\\left( \\dfrac{1}{ l_c^2} \\cos\\gamma \\right) P_l(\\cos\\gamma) \\sin\\gamma d\\gamma \\label{cltmp}}\n\nFrom \\cite{neves2006analytical, gouesbet1994rigorous}, this integral has the form\n\\eq{\\int_0^{\\pi} \\exp\\left[\\pm i R \\cos\\theta\\right] P_{l}^{\\vert m \\vert}(\\cos\\theta) \\sin^{\\vert m \\vert + 1}\\theta d\\theta = 2 (\\pm i)^{l+\\vert m \\vert} \\dfrac{(l + \\vert m \\vert)!}{(l - \\vert m \\vert)!} \\dfrac{j_l(R)}{R^{\\vert m \\vert}}}\n\n%Using $m=0$ and identifying $- i R = 1/l_c^2$ it becomes\n%\\eq{\\int_0^{\\pi} \\exp\\left[\\pm i R \\cos\\theta\\right] P_{l}(\\cos\\theta) \\sin\\theta d\\theta = 2 (\\pm i)^{l} j_l(R) \\label{simplifiedint}}\n\n%Identifying\n%\\eq{ - i R = \\dfrac{1}{l_c^2}}\n\nUsing $m=0$ and identifying $- i R = 1/l_c^2$, then \\eqref{cltmp} reduces to\n\\eq{c_l  = \\dfrac{2l+1}{2} \\exp\\left( -\\dfrac{1}{ l_c^2}\\right)  2 (-i)^{l} j_l\\left( i  \\dfrac{1}{l_c^2}\\right)}\n\nUsing $(-i)^n = i^{-n}$, and the fact that $i_n(x) = i^{-n} j_n(i x)$, where $i_n(x)$ is the modified spherical Bessel function of the first kind,\n\\eq{i_n(x) = \\sqrt{\\dfrac{\\pi}{2 x}} I_{n+1/2}(x)}\n\n\\noindent the expansion coefficients for the correlation function simplify to \n\\eq{c_l  = (2l+1) \\exp\\left( -\\dfrac{1}{ l_c^2}\\right)  i_l\\left(  \\dfrac{1}{l_c^2}\\right) \\label{cl}}\n\n\\begin{figure}[H] \n   \\centering\n   \\begin{tabular}{cccc}\n \\subfigure{\\includegraphics[width=2.1in]{RandomObjects/Figures/GaussianParticles/part7}}\n \\subfigure{\\includegraphics[width=2.1in]{RandomObjects/Figures/GaussianParticles/part8}}\n \\subfigure{\\includegraphics[width=2.1in]{RandomObjects/Figures/GaussianParticles/part9}}\n \\\\\n  \\subfigure{\\includegraphics[width=2.1in]{RandomObjects/Figures/GaussianParticles/part4}}\n \\subfigure{\\includegraphics[width=2.1in]{RandomObjects/Figures/GaussianParticles/part5}}\n \\subfigure{\\includegraphics[width=2.1in]{RandomObjects/Figures/GaussianParticles/part6}}\n  \\\\\n \\subfigure{\\includegraphics[width=2.1in]{RandomObjects/Figures/GaussianParticles/part1}}\n \\subfigure{\\includegraphics[width=2.1in]{RandomObjects/Figures/GaussianParticles/part2}}\n \\subfigure{\\includegraphics[width=2.1in]{RandomObjects/Figures/GaussianParticles/part3}}\n% \\\\\n% \\subfigure{\\includegraphics[width=2.1in]{RandomObjects/Figures/GaussianParticles/part1}}\n% \\subfigure{\\includegraphics[width=2.1in]{RandomObjects/Figures/GaussianParticles/part2}}\n% \\subfigure{\\includegraphics[width=2.1in]{RandomObjects/Figures/GaussianParticles/part3}}\n% \\subfigure{\\includegraphics[width=2.1in]{RandomObjects/Figures/GaussianParticles/part4}}\n\\end{tabular}\n\\caption{Examples of Gaussian random particles with mean radius, $a=1$, for different log-normal RMS, $a\\sigma$, and angular correlations, $\\Gamma$.  Each correlation value requires a different number of total harmonics, however the spherical harmonics coefficients are computed from the same random seed (i.e., the random draws count up from the lowest harmonic), which ensures that the same features are observed across the different particles.}\n\\end{figure}\n\n\\clearpage\n%\\subsubsection{Fully Normalized Legendre Polynomials}\n\\paragraph{Fully Normalized Legendre Polynomials}\nEquation \\eqref{expansion} is best computed with the fully normalized Legendre polynomials, which avoid direct computation of the factorials. Defining $a_{lm}'$ and $b_{lm}'$ as draws from standard normal distribution with zero mean and unit variance, \\eqref{expansion} can be written \n \\eq{s(\\theta,\\phi) = \\sum_{l=0}^{\\infty} \\sum_{m=0}^l P_l^m(\\cos\\theta) \\sqrt{(2- \\delta_{m,0}) \\dfrac{(l-m)!}{(l+m)!}  c_l} \\beta (a_{lm}'\\cos(m\\phi) + b_{lm}' \\sin(m\\phi)) \\label{stmp1}}\n\n%\\ea{a_{lm} &=& \\beta_{lm} N(0,1) \\\\\n%b_{lm} &=& \\beta_{lm} N(0,1) }\n\nThe fully normalized associated Legendre polynomials are \n\\eq{\\widetilde{P}_l^m(x) = \\sqrt{\\dfrac{(l + 1/2)(l - m)!}{(l+m)!} } P_l^m(x) \\label{fullynorm}}\n\nSubstituting \\eqref{cl} into \\eqref{stmp1} and using \\eqref{fullynorm}, we get \n%\\eq{s(\\theta,\\phi) = \\sum_{l=0}^{\\infty} \\sum_{m=0}^l P_l^m(\\cos\\theta) \\sqrt{(2- \\delta_{m,0}) \\dfrac{(l-m)!}{(l+m)!}  (2l+1) \\exp\\left( -\\dfrac{1}{ l_c^2}\\right)  i_l\\left(  \\dfrac{1}{l_c^2}\\right)} \\beta (a_{lm}'\\cos(m\\phi) + b_{lm}' \\sin(m\\phi))}\n\n\\eq{s(\\theta,\\phi) = \\beta \\sum_{l=0}^{\\infty} \\sum_{m=0}^l c_{lm}'  \\widetilde{P}_l^m(\\cos\\theta)  (a_{lm}'\\cos(m\\phi) + b_{lm}' \\sin(m\\phi))}\n\n\\noindent where \n\\eq{c_{lm}' =   \\sqrt{2 (2- \\delta_{m,0})  \\exp\\left( -\\dfrac{1}{ l_c^2}\\right)  i_l\\left(  \\dfrac{1}{l_c^2}\\right)}}\n\n\n%\\subsubsection{Small Correlation Limit}\n\\paragraph{Small Correlation Limit}\nWhen the correlation angle is small, e.g., $\\Gamma < 3^o$, the following computation is problematic\n\\eq{A_l(l_c) = \\exp\\left( -\\dfrac{1}{ l_c^2}\\right)  i_l\\left( \\dfrac{1}{l_c^2}\\right) \\label{allc}}\n\n\\noindent because the exponent goes to zero and the Bessel function becomes large.  The solution is to use the log transform as well as recursion over the series expansion of the Bessel function. From \\cite[Eq.~10.53.3]{NIST:DLMF}, the series expansion of the modified Bessel function is \n\\eq{i_l(z) = z^l \\sum_{k=0}^{\\infty} \\dfrac{(1/2 z^2)^k}{k! (2l + 2k + 1)!!}} \n\nSetting $z = 1/l_c^2$ and pulling all terms into the sum \\eqref{allc} can be written  \n\\eq{A_l(z) = \\sum_{k=0}^{\\infty} e^{-z} z^l  \\dfrac{(1/2 z^2)^k}{k! (2l + 2k + 1)!!} = \\sum_{k=0}^{\\infty} a_{l,k} } \n\nUsing the log transform, the terms of the sum are expressed as $a_{l,k} = e^{\\ln a_{l,k}}$. Writing out the logarithm\n\\eq{\\ln a_{l,k} = -z + l \\ln z + k(-\\ln 2 + 2 \\ln z) - \\ln k! - \\ln (2l + 2k + 1)!! \\label{logtemp}}\n%\\eq{A_l(z) = \\sum_{k=0}^{\\infty} e^{\\ln a_{l,k}} }\n%\\eq{A_l(z) = \\sum_{k=0}^{\\infty} e^{\\ln a_{l,k}} }\nThe double factorial for odd integers is $n!! = \\prod_{k=1}^{(n+1)/2} (2k - 1)$. Using this in \\eqref{logtemp} and converting the products to sums\n\\eq{\\ln a_{l,k} = -z + l \\ln z + k(-\\ln 2 + 2 \\ln z) - \\sum_{n=1}^k \\ln n - \\sum_{n=1}^{l+k+1} \\ln (2n - 1)}\n%or\n%\\ea{(2l + 2k + 1 )!! %&=& \\prod_{n=1}^{(2l + 2k + 1+1)/2} (2n - 1) \\\\\n%&=& \\prod_{n=1}^{l+k+1} (2n - 1)}\n\n\nTo avoid recomputing the sums for new $l$ and $k$, fast recursion relations are derived by writing out $l+1$ or $k+1$ and separating $\\ln a_{l,k}$: \n\\ea{\\ln a_{l+1,k} &=& \\ln a_{l,k} + \\ln z  - \\ln (2(l+k) + 3) \\label{lrecur} \\\\\n\\ln a_{l,k+1} &=&   \\ln a_{l,k}  -\\ln 2 + 2 \\ln z - \\ln (k+1) - \\ln(2(l+k) + 3) \\label{krecur}}\n\n%\\ea{\\ln a_{l+1,k} &=&  -z + (l+1) \\ln z + k(-\\ln 2 + 2 \\ln z) - \\sum_{n=1}^k \\ln n - \\sum_{n=1}^{l+1+k+1} \\ln (2n - 1)  \\\\\n%\\ &=& -z + l \\ln z + \\ln z + k(-\\ln 2 + 2 \\ln z) - \\sum_{n=1}^k \\ln n - \\sum_{n=1}^{l+1+k} \\ln (2n - 1)  - \\ln (2(l+1+k+1) - 1)  \\\\\n%\\ &=& \\ln a_{l,k} + \\ln z  - \\ln (2(l+k) + 3) \\label{lrecur}}\n\n%To derive a recursion relation in $k$, write out $k+1$, and separate $\\ln a_{l,k}$ \n\n%\\ea{\\ln a_{l,k+1} &=&  -z + l \\ln z + (k+1) (-\\ln 2 + 2 \\ln z) - \\sum_{n=1}^{k+1} \\ln n - %\\sum_{n=1}^{l+k+1+1} \\ln (2n - 1) \\\\\n%\\ &=& -z + l \\ln z + k(-\\ln 2 + 2 \\ln z) +  (-\\ln 2 + 2 \\ln z)  - \\sum_{n=1}^k \\ln n -  \\ln (k+1) - \\sum_{n=1}^{l+k+1} \\ln (2n - 1) - \\ln (2(l + k+2) - 1)  \\\\\n%\\ &=& \\ln a_{l,k}  -\\ln 2 + 2 \\ln z - \\ln (k+1) - \\ln(2(l+k) + 3) \\label{krecur}}\n\nThe procedure is to compute $a_{l,0}$ (up to a given $L$) using \\eqref{lrecur}, then recurse over $k$ using \\eqref{krecur} until convergence. The convergence will be different for each $l$.  Using $k=0$ in \\eqref{lrecur}, $a_{l,0}$ are computed with: \n\\eq{\\ln a_{l+1,0}=  \\ln a_{l,0} + \\ln z  - \\ln (2l + 3) }\n\n\\noindent where $\\ln a_{0,0} = -z $. \n\n\\paragraph{Routine}\nThe routine \\texttt{gaussianRandomParticle} takes as input the coordinates $(\\theta,\\phi)$, mean radius of the particle, log-normal surface RMS, and correlation angle, and returns the radius of the surface at each spherical point computed with the methods above. The maximum degree $L$ is optional and defaults to the heuristic. It computes the harmonic sum directly to allow input of any sampling of $(\\theta,\\phi)$, but this is inefficient for a large number of points and small correlation angles (because $L$ is large), even though the computation is correct. If the spherical angles can be sampled at the points of quadrature, the particle surface could be computed using a fast spherical transform, which is mentioned here for future development. Alternatively, a version of this in which the Legendre polynomials are computed on the fly with inline recursion could be developed to save memory.\n\n{\\footnotesize\n\\VerbatimInput{\\code/RandomObjects/gaussianRandomParticle.m}\n}\n\n\\clearpage\n\n\\section{Ionosphere Irregularity}\n\\paragraph{Background} Earth's ionosphere is a complex plasma medium that exists at altitudes between 100 km and 600 km and affects the propagation of radio, radar, and GPS signals. The influence of the ionosphere on these signals increases as the radio frequency decreases. It starts to affect radar around L-band (1-2 GHz) and UHF-band (300 MHz - 1 GHz), becomes a significant dispersive medium in the VHF band (30-300 MHz), and is completely reflecting in the HF band below the plasma frequency (around 10 MHz). The strength of the ionosphere is highly dependent on the time of day and latitude. The ionosphere is always changing, but a given 3D spatial distribution of electron density can usually be considered constant over a short time duration, for example, of a synthetic aperture radar acquisition from an orbiting spacecraft.  \n\nThe simplest parameters that quantify the ionosphere are 1) electron density, $N_e$, which is a function of altitude and given in terms of number of electrons per unit volume (el/m$^3$), 2) the total electron content (TEC) which is the column-integrated electron density up to a given altitude, given in terms of number of elections per unit area (el/m$^2$), and 3) irregularities that are random fluctuations in the spatial distribution of the plasma density. The TEC is given by \n\\eq{TEC(h) = \\int_{0}^{h} N_e(z) dz}\n\n\\noindent where $N_e(z)$ is the electron density as a function altitude, and $h$ is the altitude up to which we wish to evaluate the TEC. TEC is often the only parameter needed to assess the two-way effects of the ionosphere on the radar signal such as dispersion, Faraday rotation, and absorption loss. Irregularities contribute to scintillation, which are fluctuations of the phase and amplitude of the radar echo about a mean response. Scintillation creates small phase variations across a synthetic aperture, and these phase variations lead to decoherence and a drop in coherent gain when creating images. While strong ionospheric dispersion at VHF frequencies is almost completely correctable, scintillation is often uncorrectable, because there is no way to predict what the irregularities will be at a given time or place. Finally, the study of Earth's ionosphere spans many decades, and more information on these topics can be found in the literature.\n\n\\paragraph{Formulation} We give a routine for creating a 1D profile of ionospheric irregularities that is suitable for radar analysis. This is based on the 2-parameter PSD model in \\cite{liu2003ionospheric,ishimaru1999ionospheric}, from which 1D profiles can be created using the methods from Section \\ref{sec:1drandom}. The 2-parameter model effectively creates different regimes of roughness that define the underlying structure of the irregularity. These are controlled through two log-slope regions in the PSD. The log-slope values come from empirical observations, while the mean and relative variation are set by user-defined scale factors. The signal can be scaled to either electron density, assuming a uniform column, or to the TEC itself. The scale factors in this model are not very informative, however, computing actual TEC and irregularity amplitude is quite complicated. A more informative model is given, for example, in \\cite{rogers2013impacts}, which provides a PSD of radar phase scintillation using scale factors from up-to-date global ionospheric models. Still, the use of user-defined scale factors can suffice for first-order analysis.\n\nFrom \\cite{liu2003ionospheric,ishimaru1999ionospheric}, the 2-parameter PSD for the electron density irregularity is given for 3D $k$-space as \n\\eq{\\Phi(k) = \\begin{cases}\n\\dfrac{A}{(k^2 + k_o^2)^{v_1}} & k \\le k_b \\\\\n\\\\\n\\dfrac{A(k_o^2 + k_b^2)^{v_2-v_1}}{(k^2 + k_o^2)^{v_2}} & k > k_b \\\\\n\\end{cases}}\n\n\\noindent where $k$ is the spatial wavenumber, $k_o = 2\\pi/L_o$ is the outerscale wavenumber at length scale $L_o$, $k_b = 2\\pi/L_b$ is the break wavenumber at length scale $L_b$, $v_1$ and $v_2$ are log-slope parameters, and $A$ is a scale factor. The values for the parameters are empirical and cited in \\cite{ishimaru1999ionospheric} as: $L_o \\approx 10$ km, $L_b \\approx 500$ m, $2v_1\\approx$  3-3.5, and $2v_2\\approx$  5-5.5.  \n\nThe 1D PSD, $V(k)$, is related to the 3D PSD as \\cite{ishimaru1978wave}\n\\eq{\\Phi(k) = -\\dfrac{1}{2\\pi k} \\dd{V(k)}{k}}\n\nwhich leads to the 1D PSD, \\cite{liu2003ionospheric}, \n\\eq{V(k_x) = \\begin{cases}\n\\dfrac{\\pi A}{v_1 - 1}\\dfrac{1}{(k_x^2 + k_o^2)^{v_1-1}} - \\dfrac{\\pi A}{(k_b^2 + k_o^2)^{v_1-1}}\\left(\\dfrac{1}{v_1-1} - \\dfrac{1}{v_2-1} \\right) & k_x \\le k_b \\\\\n\\\\\n\\dfrac{\\pi A(k_o^2 + k_b^2)^{v_2-v_1}}{v_2-1}\\dfrac{1}{(k_x^2 + k_o^2)^{v_2-1}} & k_x > k_b \\\\\n\\end{cases} \\label{scintpsd}}\n\n\\noindent where $k_x$ is now a 1D wavenumber. The key feature of this PSD are two regimes of log-slope power. \n\nThe 1D profile of electron density, $N_e(x)$, is realized by multiplying each frequency of the PSD with a draw from a complex standard normal distribution and then taking the inverse Fourier transform. The amplitude, $A$, has so far been arbitrary, but it is there to adjust the scale of the signal. Let $n_e(x)$ be a zero mean profile generated by \\eqref{scintpsd} which is normalized by its RMS. This signal can then be rescaled as\n\\eq{N_e(x) =  \\overline{N}_e \\left( \\tilde{\\sigma} n_e(x) + 1\\right) \\label{iononorm}}\n\n\\noindent where $\\overline{N}_e$ is the average electron density and $\\tilde{\\sigma}$ is the relative RMS variation given as a fraction, or percentage, of the mean. This assumes that the ionospheric column has uniform electron density. Alternatively, \\eqref{iononorm} can be used for TEC if $\\overline{N}_e$ and $\\tilde{\\sigma}$ are replaced by the average TEC and percentage RMS variation in TEC, respectively. %Note, it is unclear from \\cite{liu2003ionospheric} if the relative variation, $\\tilde{\\sigma}$, is supposed to be peak to peak, the RMS, or 2 times the RMS. We define $\\tilde{\\sigma}$ as the relative RMS of the signal after subtracting the mean. \n\n\n\\begin{figure}[H] \n   \\centering\n   \\subfigure{\\includegraphics[width=3in]{RandomObjects/Figures/ionoPSD1} }\n      \\subfigure{\\includegraphics[width=3in]{RandomObjects/Figures/ionoPSD2} }        \n   \\caption{PSD of ionosphere irregularity with respect to wavenumber (left) and length scale (right) for the default parameters: $L_o = 10$ km, $L_b = 500$ m, $2v_1=$ 3.5, and $2v_2=$ 5.5.  Dashed lines are the outerscale and breakscale. The end points of the curves correspond to the wavenumber or length scale of the total profile length or the sampling step. }\n\\end{figure}\n\n\\begin{figure}[H] \n   \\centering\n \\includegraphics[width=4in]{RandomObjects/Figures/ionoProfile} \n   \\caption{Profile of ionosphere irregularity for the default parameters: $L_o = 10$ km, $L_b = 500$ m, $2v_1=$3.5, and $2v_2=$5.5. Numerically, the correlation length was found to be about 1 km. }\n\\end{figure}\n\n\\paragraph{Routine} The routine \\texttt{ionosphere1} produces a 1D profile of ionosphere irregularity based on the 2-parameter PSD above. It takes as input the number of sample points, profile length, average value, and relative RMS variation in percentage of the mean. The scale factors can be electron density or TEC. It uses the same generating procedure as \\texttt{rough1} in Section \\ref{sec:1drandom}. Default model parameters are: $L_o = 10$ km, $L_b = 500$ m, $2v_1=$3.5, and $2v_2=$5.5. Different values can be optionally included as input arguments, in the same order, where an input of \\texttt{'[]'} will use the default value. The routine can output the PSD, wavenumber, and model parameters for plotting.\n\n\n{\\footnotesize\n\\VerbatimInput{\\code/RandomObjects/ionosphere1.m}\n}\n\n\n%\\section{Fractals}\n%\n%Fractals are not computed with PSDs, so we treat them separately.  From Tsang, one type of 1D fractal is given by the Weierstrass-Mandelbrot function.  \n%\n%\\[ f(x) = h C \\sum_{n=0}^{N-1} b^{(s-2)n} \\sin\\left(k_L b^n x + \\Phi_n\\right) \\]\n%\n%\\noindent where\n%\n%\\begin{eqnarray}\n%h &=& \\textrm{RMS height} \\nonumber \\\\\n%N &=& \\textrm{number of modes} \\nonumber \\\\\n%s &=& \\text{fractal dimension} \\quad (1 \\le s < 2) \\nonumber \\\\\n%C &=& \\sqrt{\\dfrac{2\\left(1-b^{2(s-2)}\\right)}{1- b^{2(s-2)N} }} = \\textrm{normalization constant} \\nonumber \\\\\n%\\Phi_n &=& \\textrm{phase term drawn for each mode from a uniform distribution between 0 and $2\\pi$}\\nonumber \n%\\end{eqnarray}\n%\n%The signal is band limited between wave numbers $k_L$ and $k_U$ through the relations\n%\n%\\begin{eqnarray}\n%k_U &=& k_L b^{N-1} \\\\\n%b &=& \\left(\\dfrac{k_U}{k_L} \\right)^{\\frac{1}{N-1}} \n%\\end{eqnarray}\n%\n%We can convert the band limits into the more intuitive length scales\n%\n%\\begin{eqnarray}\n%l_U  &=& \\dfrac{2\\pi}{k_L} \\\\\n%l_L &=& \\dfrac{2\\pi}{k_U} \n%\\end{eqnarray}\n%\n%\\noindent where $l_U$ and $l_L$ are the longest and shortest length scales, respectively, of the surface roughness.  Because we ultimately sample this function, our smallest length scale must satisfy Nyquist.  Let $L_x$ be the extent of the surface and $N_x$ be the number of samples, then the smallest allowable length scale is \n%\n%\\[ l_L >  l_{\\textrm{min}} = \\dfrac{N_x-1}{\\pi L_x} \\]\n%\n%The routine \\texttt{fractal1} implements this function.  $l_L$ is checked and set to $1.05 l_{min}$ if Nyquist is not satisfied in order to prevent aliasing.  This way you can choose the sample rate as it relates to the problem at hand.  As long as $l_U$ is not too large (and $k_L$ close to zero), the signal is mostly zero mean.  Increasing the modes increases the density of frequency components in the band, but be generous in order for the fractal shape to be realized (e.g., $N > $ 100).  One last note, because this fractal is just a sum of sinusoids, it has continuous derivatives.  The first derivative is an optional output.\n%\n%\n%{\\footnotesize\n%\\VerbatimInput{\\code/RandomObjects/fractal1.m}\n%}\n% \n% \\begin{figure}[h] \n%   \\centering\n%   \\includegraphics[width=5in]{RandomObjects/fractal1} \n%   \\caption{1D fractal surface and spectrum. $N_x =$ 500 samples, $L_x =$ 200 m, RMS = 1 m, $l_L =$ 1 m, $l_U =$ 20 m, $s =$ 1.5, $N =$ 100.}\n%\\end{figure}\n\n\n", "meta": {"hexsha": "5396315ebba7fcf7f19eb4ae04c6e6af1c9820cf", "size": 56144, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/RandomObjects/RandomObjects.tex", "max_stars_repo_name": "nasa-jpl/Waveport", "max_stars_repo_head_hexsha": "caeb9540693185e000e08d826bc2ccabb6aa82bd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-08-29T13:29:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T20:09:47.000Z", "max_issues_repo_path": "Tex/RandomObjects/RandomObjects.tex", "max_issues_repo_name": "ruzakb/Waveport", "max_issues_repo_head_hexsha": "caeb9540693185e000e08d826bc2ccabb6aa82bd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tex/RandomObjects/RandomObjects.tex", "max_forks_repo_name": "ruzakb/Waveport", "max_forks_repo_head_hexsha": "caeb9540693185e000e08d826bc2ccabb6aa82bd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-08-29T13:28:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-08T19:58:04.000Z", "avg_line_length": 78.0862308762, "max_line_length": 1158, "alphanum_fraction": 0.7243160445, "num_tokens": 17510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683105, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7241353279315291}}
{"text": "\\section{Time Reversal}\r\nWhat if we reverse the time parameter in a Markov chain?\r\nUsually it will result in an absolute mess, however, if we restrict the initial distribution to be invariant, then we should be able to obtain something nontrivial (since at least we know the distribution at each step).\r\n\\begin{theorem}\r\n    Let $P$ be irreducible with an invariant distribution $\\pi$.\r\n    Suppose $(X_n)_{0\\le n\\le N}$ is $\\operatorname{Markov}(\\pi,P)$ and set $Y_n=X_{N-n}$, then $(Y_n)_{0\\le n\\le N}\\sim\\operatorname{Markov}(\\pi,\\hat{P})$ where $\\hat{P}=(\\hat{p}_{ij})$ satisfying $\\pi_j\\hat{p}_{ji}=\\pi_ip_{ij}$.\r\n    In addition, $\\hat{P}$ is irreducible and has invariant distribution $\\pi$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    $\\hat{P}$ is well-defined and is a stochastic matrix since $\\pi_j\\neq 0$ for any $j$ (as $P$ is irreducible).\r\n    Indeed,\r\n    $$\\sum_{i\\in I}\\hat{p}_{ji}=\\frac{1}{\\pi_j}\\sum_{i\\in I}\\pi_ip_{ij}=\\frac{\\pi_j}{\\pi_j}=1$$\r\n    Also,\r\n    $$\\sum_{j\\in I}\\pi_j\\hat{p}_{ij}=\\sum_{j\\in I}\\pi_ip_{ij}=\\pi_i$$\r\n    so $\\pi$ is indeed an invariant distribution for $(Y_n)$.\r\n    Now\r\n    \\begin{align*}\r\n        \\mathbb P[Y_0=i_0,\\ldots,Y_N=i_n]&=\\mathbb P[X_0=i_N,\\ldots,X_N=i_0]\\\\\r\n        &=\\pi_{i_N}p_{i_Ni_{N-1}}\\cdots p_{i_1i_0}\\\\\r\n        &=\\pi_{i_{N-1}}\\hat{p}_{i_{N-1}i_N}p_{i_{N-1}i_{N-2}}\\cdots p_{i_1i_0}\\\\\r\n        &=\\cdots\\\\\r\n        &=\\pi_{i_0}\\hat{p}_{i_0i_1}\\cdots\\hat{p}_{i_{N-1}i_N}\r\n    \\end{align*}\r\n    which shows $(Y_n)\\sim\\operatorname{Markov}(\\pi,\\hat{P})$ due to Theorem \\ref{markov_alt_defn}.\\\\\r\n    To see $\\hat{P}$ is irreducible, for any $i,j\\in I$ there is a sequence $i_0=i,i_1,\\ldots,i_n=j$ such that $p_{i_0i_1}\\cdots p_{i_{n-1}i_n}>0$ by the irreducibility of $P$.\r\n    So\r\n    $$\\hat{p}_{i_0i_1}\\cdots \\hat{p}_{i_{n-1}i_n}=\\frac{\\pi_{i_0}}{\\pi_{in}}p_{i_0i_1}\\cdots p_{i_{n-1}i_n}>0$$\r\n    which shows the irreducibility of $\\hat{P}$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A stochastic matrix $P$ and a measure $\\lambda$ are said to be in detailed balance if $\\forall i,j\\in I,\\lambda_ip_{ij}=\\lambda_jp_{ji}$.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    If $P,\\lambda$ are in detailed balance, then $\\lambda$ is invariant for $P$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Just write it out: $\\sum_{i\\in I}\\lambda_ip_{ij}=\\sum_{i\\in I}\\lambda_jp_{ji}=\\lambda_j$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $P$ be irreducible and $(X_n)\\sim\\operatorname{Markov}(\\lambda,P)$.\r\n    Then $(X_n)$ is reversible if the sequence $(X_{N-n})_{0\\le n\\le N}$ is also $\\operatorname{Markov}(\\lambda,P)$ for all $N$.\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Let $P$ be irreducible and $\\lambda$ be a distribution.\r\n    Suppose $(X_n)\\sim\\operatorname{Markov}(\\lambda,P)$, then the followings are equivalent:\\\\\r\n    (a) $(X_n)$ is reversible.\\\\\r\n    (b) $P,\\lambda$ are in detailed balance.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Both (a) and (b) imply that $\\lambda$ is invariant, so we might as well assume that.\r\n    By the preceding theorem, both conditions are equivalent to $P=\\hat{P}$.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider the Markov chain on $\\{0,\\ldots,M\\}$ such that $p_{0,1}=p, p_{0,0}=q,p_{M,M}=p,p_{M,M-1}=q$ and for $i\\in\\{1,\\ldots,M-1\\}$, $p_{i,i+1}=p, p_{i,i-1}=q$ for some fixed $p\\in (0,1),q=1-p$.\r\n    Then $\\lambda_ip_{i,i+1}=\\lambda_{i+1}p_{i+1,i}$ iff $\\lambda_i=C(p/q)^i$ for some constant $C$.\r\n    Choosing $C$ that normalises $\\lambda_i$ gives an invariant distribution that is in detailed balance with $P$, so the chain started there is reversible.\r\n\\end{example}\r\n\\begin{example}[Random Walk on Graphs]\r\n    For a finite connected graph, there is a natural structure of Markov chain on it with transition probabilities (noting a vertex is not neighbouring itself)\r\n    $$p_{ij}=\\begin{cases}\r\n        1/\\deg i\\text{, if $i,j$ are neighbours}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    This is known as a random walk on this graph.\r\n    Easily $P$ is irreducible by connectedness and $P$ is in detailed balance with $(v_i)=(\\deg i)$ as $v_ip_{ij}=1=v_jp_{ji}$.\r\n\\end{example}\r\n\\begin{example}[Non-example]\r\n    Consider\r\n    $$P=\\begin{pmatrix}\r\n        0&2/3&1/3\\\\\r\n        1/3&0&2/3\\\\\r\n        2/3&1/3&0\r\n    \\end{pmatrix}$$\r\n    Then the distribution $\\pi=(1/3,1/3,1/3)$ is invariant but not reversible.\r\n\\end{example}", "meta": {"hexsha": "81eb2e7120bd18e09bd6dc2c5ebb892e468cea42", "size": 4295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "9/reversal.tex", "max_stars_repo_name": "david-bai-notes/IB-Markov-Chains", "max_stars_repo_head_hexsha": "cef4f20b59106a1deaed4de2f503e594e3ffc61d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "9/reversal.tex", "max_issues_repo_name": "david-bai-notes/IB-Markov-Chains", "max_issues_repo_head_hexsha": "cef4f20b59106a1deaed4de2f503e594e3ffc61d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "9/reversal.tex", "max_forks_repo_name": "david-bai-notes/IB-Markov-Chains", "max_forks_repo_head_hexsha": "cef4f20b59106a1deaed4de2f503e594e3ffc61d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.2666666667, "max_line_length": 231, "alphanum_fraction": 0.641443539, "num_tokens": 1534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.8519528000888387, "lm_q1q2_score": 0.724135323096273}}
{"text": "\\section{Case Study: Lorenz System}\n\nThe Lorenz system is defined by\n\\begin{align*}\n\t\\dot x &= \\sigma (y-x)\\\\\n\t\\dot y &= x(\\rho-z)-y\\\\\n\t\\dot z &= xy-\\beta z \\text,\n\\end{align*}\nwhere $\\sigma = 10$, $\\beta = \\frac 8 3$ and $\\rho$ is the variable parameter.\n\nAs a reduction operator for the creation of the bifurcation diagram\n\\[\n\t\\mathbf y \\mapsto \\{||\\mathbf y(t) - \\mathbf a||\\ |\\ t \\in [0,2\\pi),\\ \\mathbf y_3(t) = \\rho + 7, \\ \\mathbf y'_3(t) > 0\\}\n\\]\nis used, where $\\mathbf a = (\\sqrt{\\beta(\\rho-1)}, \\sqrt{\\beta(\\rho-1)}, \\rho-1)^T$ is one of the fixed points of the system.\nIt maps a solution to the distances of its intersections with the $z = \\rho+7$ plane to the fixed point $\\mathbf a$.\nThis particular choice was made empirically, as most other choices result in changing numbers of intersections for single solution branches, too many intersections or result in many lines overlapping one another.\n\nThe system features stable periodic solutions for $\\rho \\in \\{99.65, 100.5, 160, 350\\}$.\nThese values are used as starting points for the creation of the bifurcation diagram.\nThe general process of\n\\begin{itemize}\n\t\\item finding a stable solution\n\t\\item tracing it to a bifurcation point or until otherwise satisfied\n\t\\item doubling the period to find period doubling bifurcations\n\t\\item switching to the double period branch using perturbation\n\\end{itemize}\nis the same as for the Rössler system.\n%Moreover, this is possible using the same parameters. %distracting?\n\nSee figures \\ref{fig:lorenzfull}, \\ref{fig:lorenzcut} for visual results.\nThe tracing of the solutions for $\\rho \\to 0$ had to be suspended, because it became too slow to be practical.\nSee the discussion in \\autoref{sec:outro} for details.\n\n\\newgeometry{top=0cm}\n\n\\begin{figure}\n\\centering\\makebox[0pt]{\\rotatebox{90}{\\includegraphics{img/lorenzoverview.png}}}\n\\caption{\n\tAn overview of the Lorenz bifurcation diagram.\n}\n\\label{fig:lorenzfull}\n\\end{figure}\n\n\n\\begin{figure}\n\\centering\\makebox[0pt]{\\rotatebox{90}{\\includegraphics{img/lorenzcut80.png}}}\n\\caption{\n\tThe periodic orbits for $\\rho=80$, together with an underlying trajectory obained through forward intergration (grey) in phase-space.\n\tThe colors of the periodic solutions match the bifurcation diagram.\n}\n\\label{fig:lorenzcut}\n\\end{figure}\n\n\\restoregeometry\n", "meta": {"hexsha": "d7d33bd630b504b54a89be1ff94e8644b9821b35", "size": 2300, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doctheory/lorenz.tex", "max_stars_repo_name": "285714/ncm", "max_stars_repo_head_hexsha": "fcf289c7ef5f8500ebcb238e36c6a7ee9e054147", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doctheory/lorenz.tex", "max_issues_repo_name": "285714/ncm", "max_issues_repo_head_hexsha": "fcf289c7ef5f8500ebcb238e36c6a7ee9e054147", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doctheory/lorenz.tex", "max_forks_repo_name": "285714/ncm", "max_forks_repo_head_hexsha": "fcf289c7ef5f8500ebcb238e36c6a7ee9e054147", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.0714285714, "max_line_length": 212, "alphanum_fraction": 0.7404347826, "num_tokens": 673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7240905005018864}}
{"text": "%================================\n%::::::::::::::::::::::::::::::::\n\\chapter{Set Theory}\n%::::::::::::::::::::::::::::::::\n%================================\n\n\n%================================\n\\section{Countability of Sets}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n    \\label{def: countability}\n    A set $A$ is said to be \\textit{countable} iff there is a bijection $f: I \\to A$ with $I \\subseteq \\mathbb N$.\n    \n    $A$ is said to be \\textit{uncountable} iff for any injection $f: I \\to A$ with $I \\supseteq \\mathbb N$, $f$ is not surjection.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n    \\label{def: cardinal number}\n    The \\textit{cardinal number} of a set $A$, denoted $|A|$ or $\\#A$, is defined to the quantity of it elements.\n\n    Customarily, we write $\\aleph_0$ for $|\\mathbb N|$, and $\\mathfrak{c}$ for $|\\mathbb R|$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n    \\label{def: comparing cardinal number}\n    Given $A$ and $B$ as sets, we define the following:\n    \\begin{enumerate}[(i)]\n        \\item $|A| = |B|$ iff there is a bijection $f: A \\to B$;\n        \\item $|A| \\le |B|$ iff there is an injection $g: A \\to B$;\n        \\item $|A| < |B|$ iff for any injection $g: A \\to B$, $g$ is not surjection.\n    \\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n    \\label{def: finite and infinite sets}\n    A set $A$ is said to be \\textit{finite} iff $|A| < \\aleph_0$; it is \\textit{infinite} iff $|A| \\ge \\aleph_0$.\n\\end{definition}\n%--------------------------------\n\n\nBy \\ref{def: comparing cardinal number}, $A$ is finite iff for all injection $f: A \\to \\mathbb N$, $f$ is not surjection. Respectively, $A$ is infinite iff there exists injection $f: \\mathbb N \\to A$.\n\n\n%--------------------------------\n\\begin{proposition}\n    For any countable set $A$, $|A| \\le \\aleph_0$.\n    \n    %--------------------------------\n\t\\begin{proof}\n\t    If $A$ is finite, i.e., $|A| < \\aleph_0$, it is clearly countable.\n\t    \n\t    If $A$ is infinite, by Definition \\ref{def: finite and infinite sets}, $|A| \\ge \\aleph_0$. As $A$ is countable, there must be an bijective $f: I \\to A$ with $I \\subseteq \\mathbb N$, then (iii) in Definition \\ref{def: comparing cardinal number} fails, so $|A| = \\aleph_0$.\n\t\\end{proof}\n\t%--------------------------------\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n    \\label{prop: uncountable iff uncountable cardinal number}\n    \n    For any set $A$, $A$ is uncountable iff $|A| > \\aleph_0$.\n    \n    %--------------------------------\n\t\\begin{proof}\n\t    By Definition \\ref{def: countability}, $A$ is uncountable iff for any injection $f: I \\to A$ with $I \\supseteq \\mathbb N$, $f$ is not surjection. This holds iff for any $I \\subseteq \\mathbb N$, $|I| < |A|$. $\\mathbb N \\subseteq \\mathbb N$, Thus $\\aleph_0 < |A|$.\n\t\\end{proof}\n\t%--------------------------------\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tThe subsets of any countable sets are countable.\n\t\n\t%--------------------------------\n\t\\begin{proof}\n\t\tClearly, by intuition or by Definition \\ref{def: comparing cardinal number}, for any sets $A$ and $B$, $A \\subseteq B$ implies $|A| \\le |B|$. By Proposition \\ref{prop: uncountable iff uncountable cardinal number}, $B$ is countable iff $|B| \\le \\aleph_0$. Then we have $|A| \\le \\aleph_0$. This holds iff $A$ is countable.\n\t\\end{proof}\n\t%--------------------------------\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tThe super sets of any uncountable sets are uncountable.\n\t\n\t%--------------------------------\n\t\\begin{proof}\n\t\tLet $A$ be an uncountable set. $|A| > \\aleph_0$ implies that for any $B \\supseteq A$, $|B| > |A| > \\aleph_0$. Thus, by Proposition \\ref{prop: uncountable iff uncountable cardinal number}.\n\t\\end{proof}\n\t%--------------------------------\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: The Cartesian product of countable sets is countable}\n    The Cartesian product of countable sets is countable.\n    \n    %--------------------------------\n    \\begin{proof}\n    \tIf $A$ or $B$ is empty, $A \\times B$ is empty. The empty set is countable.\n    \t\n    \tLet $A$ and $B$ be both infinite countable, then there exist $f: \\mathbb N \\to A$ and $g: \\mathbb N \\to B$. Let $h: \\mathbb N \\to \\mathcal P(A \\times B)$ defined by\n    \t$$\n        h(x) =\n        \\begin{cases}\n        \\{(f_0, g_0)\\} & x = 0 \\\\\n        \\{(f_0, g_1), (f_1, g_0)\\} & x = 1 \\\\\n        \\{(f_0, g_2), (f_1, g_1), (f_2, g_0)\\} & x = 2 \\\\\n        \\{(f_0, g_3), (f_1, g_2), (f_2, g_1), (f_3, g_0)\\} & x = 3 \\\\\n        \\vdots & \\vdots\n        \\end{cases}\n        $$\n        \n        Now we have\n        $$\n        A \\times B = \\bigcup_{x = 0}^\\infty f(x).\n        $$\n        Thus,\n        $$\n        |A \\times B| = \\left| \\bigcup_{x = 0}^\\infty f(x) \\right| = \\sum_{x = 0}^\\infty (x + 1).\n        $$\n        \n        Clearly,\n        $$\n        \\aleph_0 = |\\{0\\} \\cup \\{1, 2\\} \\cup \\{3,4,5\\} \\cup \\ldots | = |A \\times B|.\n        $$\n        Thus, $A\\times B$ is countable.\n    \\end{proof}\n    %--------------------------------\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: The countable union of countable sets is countable}\n    The countable unions of countable sets is countable.\n    \n    \\begin{proof}\n        Similar to Proposition \\ref{prop: The Cartesian product of countable sets is countable}.\n    \\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n    If $A$ is a countable set but $B$ is not, then $B \\setminus A$ is uncountable.\n\n\t%--------------------------------    \n    \\begin{proof}\n        If $B \\setminus A$ is countable, $B \\setminus A \\cup A$ must be countable. Then $B \\subseteq B \\setminus A \\cup A$ is also countable, contradicted to the condition.\n    \\end{proof}\n    %--------------------------------\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: there is no  countably infinite power set}\n\tThere is no countably infinite $\\mathcal P(X)$ for any set $X$.\n\t\n\t%--------------------------------\n\t\\begin{proof}\n\t\tAs $\\aleph_0$ is the smallest infinite cardinal number, let $X = \\mathbb N$. Let\n\t\t$$\n\t\t\\mathcal U = \\left\\{ U = \\bigcup_{i=0}^\\infty \\{ x_i \\in \\{2i, 2i + 1\\} \\} \\right\\} \\subseteq \\mathcal P(X).\n\t\t$$\n\t\tSuppose $\\mathcal U$ is countable, then there is a list\n\t\t$$\n\t\t\\mathcal W = \\bigcup_{k = 0}^{\\infty} \\{U_k = \\{x_{k,i}\\} \\} \\supseteq \\mathcal U.\n\t\t$$\n\t\t\n\t\tNow construct a new set\n\t\t$$\n\t\tW = \\{ w_i \\}_{i = 0}^\\infty\n\t\t$$\n\t\twhere for all $i \\in \\mathbb N$, $w_{i} = 2i$ if $x_{i,i} = 2i + 1$, and $w_i = 2i + 1$ if $x_{i,i} = 2i$. Now we have $W \\in \\mathcal U$ but $W \\notin \\mathcal W$, which is contradicted to the condition. Thus $\\mathcal U$ is not countable, thus $\\mathcal P(X) \\supseteq \\mathcal U$ is not either.\n\t\\end{proof}\n\t%--------------------------------\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n    $\\mathbb R$ is uncountable.\n    \n\t%--------------------------------\n\t\\begin{proof}\n\t\tSimilar to Proposition \\ref{prop: there is no  countably infinite power set}.\n\t\\end{proof}\n\t%--------------------------------    \n\\end{proposition}\n%--------------------------------\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n%", "meta": {"hexsha": "5e1fea361ee2e2efe0d9b9e2fdfdc9b5816a2f9a", "size": 7787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-mathematical-anlysis/content.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-mathematical-anlysis/content.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-mathematical-anlysis/content.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.8352490421, "max_line_length": 322, "alphanum_fraction": 0.4813150122, "num_tokens": 2326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7240904748328608}}
{"text": "\n\\subsection{Bases of topologies}\n\nSubset \\(B\\) of topology \\(T\\) is a base for \\(T\\) if all elements of \\(T\\) are unions of members of \\(B\\).\n\n\\subsubsection{Second-countable space}\n\nIf \\(B\\) is finite then the toplogy is a second-countable space.\n\n", "meta": {"hexsha": "803d2c810105e29628561bf108ff8e9082faf742", "size": 250, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/topologyFinite/03-02-base.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/topologyFinite/03-02-base.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/topologyFinite/03-02-base.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0, "max_line_length": 107, "alphanum_fraction": 0.696, "num_tokens": 68, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.7718435030872967, "lm_q1q2_score": 0.7240849215036383}}
{"text": "\\documentclass{subfile}\n\n\\begin{document}\n\t\\section{Bernoulli and Power Mean Inequality}\\label{sec:powermean}\n\tThe \\index{Bernoulli inequality}\\emph{Bernoulli inequality} is a well known result and it has some nice consequences. We mentioned earlier that we will show more proofs of arithmetic-geometric mean inequality. We will show one such proof here using this inequality.\n\t\t\\begin{theorem}[\\itshape Bernoulli's inequality]\n\t\t\tLet $n$ be a positive integer and $x>-1$ be a real number. Then\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t(1+x)^{n}\n\t\t\t\t\t\t& \\geq1+nx\n\t\t\t\t\\end{align*}\n\t\t\\end{theorem}\n\t\\index{Generalized Bernoulli inequality}This inequality can be generalized as the following result.\n\t\t\\begin{theorem}[\\itshape Generalized Bernoulli inequality]\n\t\t\tLet $x_{1},\\ldots,x_{n}>-1$ be real numbers such that either all are positive or all are negative. Then\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t(1+x_{1})\\cdots(1+x_{n})\n\t\t\t\t\t\t& > 1+x_{1}+\\ldots+x_{n}\n\t\t\t\t\\end{align*}\n\t\t\\end{theorem}% Do we use Hadžiivanov, Nikolaĭ; Prodanov, Ivan Bernoulli's inequalities?\n\tLet $a_{1},\\ldots,a_{n}$ be positive real numbers. Then the \\index{Power mean}\\emph{generalized mean} or \\emph{power mean of order} $r$ is defined as\n\t\t\\begin{align*}\n\t\t\t\\mathfrak{M}_{r}(a_{1},\\ldots,a_{n})\n\t\t\t\t& = \\left(\\dfrac{a_{1}^{r}+\\ldots+a_{n}^{r}}{n}\\right)^{\\frac{1}{r}}\n\t\t\\end{align*}\n\tNote that the arithmetic mean of $a_{1},\\ldots,a_{n}$ is actually $\\mathfrak{M}_{1}(a_{1},\\ldots,a_{n})$. Similarly, the harmonic mean is $\\mathfrak{M}_{-1}(a_{1},\\ldots,a_{n})$. Moreover, $\\mathfrak{M}_0(a_{1},\\ldots,a_{n})$ is the geometric mean which we show below.\n\t\n\tWe may omit the numbers $a_{1},\\ldots,a_{n}$ and just call it $\\mathfrak{M}_{r}$ instead of $\\mathfrak{M}_{r}(a_{1},\\ldots,a_{n})$ if the context is clear. An even better way to denote this would be using $\\mathfrak{M}_{r}(\\mathbf{a})$ where $\\mathbf{a}=(a_{1},\\ldots,a_{n})$.\n\t\t\\begin{align*}\n\t\t\t\\mathfrak{M}_{r}(\\mathbf{a})\n\t\t\t\t& = \\dfrac{\\|\\mathbf{a}\\|_{r}}{\\sqrt[r]{n}}\n\t\t\\end{align*}\n\tWe can also denote the arithmetic, geometric and harmonic means of $\\mathbf{a}$ by $\\mathfrak{A}(\\mathbf{a}),\\mathfrak{G}(\\mathbf{a})$ and $\\mathfrak{H}(\\mathbf{a})$ respectively. The notations $\\mathfrak{M},\\mathfrak{A},\\mathfrak{G},\\mathfrak{H}$ are inspired by \\textcite{hardy_littlewood_polya_1934}. \n\t\n\tNext, we show that $\\mathfrak{G}(\\mathbf{a})$ is the geometric mean.\n\t\t\\begin{align*}\n\t\t\t\\mathfrak{G}(\\mathbf{a})\n\t\t\t\t& = \\lim\\limits_{r\\to0}\\left(\\dfrac{a_{1}^{r}+\\ldots+a_{n}^{r}}{n}\\right)^{\\dfrac{1}{r}}\n\t\t\\end{align*}\n\tThen we can write arithmetic-geometric-harmonic mean inequality as $\\mathfrak{A}(\\mathbf{a})\\geq\\mathfrak{G}(\\mathbf{a})\\geq \\mathfrak{H}(\\mathbf{a})$. This is generalized in the next result.\n\t\t\\begin{theorem}[\\itshape Power mean inequality]\n\t\t\tIf $r,s$ are real numbers such that $r\\leq s$, then for a vector $\\mathbf{a}$,\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\min\\{\\mathbf{a}\\}\n\t\t\t\t\t\t& \\leq \\mathfrak{M}_{r}(\\mathbf{a})\\leq \\mathfrak{M}_{s}(\\mathbf{a})\\leq\\max\\{\\mathbf{a}\\}\n\t\t\t\t\\end{align*}\n\t\t\tEquality occurs if and only if $r=s$.\n\t\t\\end{theorem}\n\tThis inequality can be extended further with the notion of what we call \\textit{weighted means}. Let $\\omega=(w_{1},\\ldots,w_{n})$ be a vector of non-negative real numbers such that $w_{1}+\\ldots+w_{n}=1$. Then the weighted arithmetic mean of the real numbers $a_{1},\\ldots,a_{n}$ is\n\t\t\\begin{align*}\n\t\t\t\\mathfrak{A}(\\mathbf{a},\\omega)\n\t\t\t\t& = w_{1}a_{1}+\\ldots+w_{n}a_{n}\n\t\t\\end{align*}\n\tIn general, the \\index{weighted power mean}\\textit{weighted power mean of order} $r$ is\n\t\t\\begin{align*}\n\t\t\t\\mathfrak{M}_{r}(\\mathbf{a},\\omega)\n\t\t\t\t& = \\left(w_{1}a_{1}^{r}+\\ldots+w_{n}a_{n}^{r}\\right)^{\\frac{1}{r}}\n\t\t\\end{align*}\n\tIf the context is clear on what the weights are, then we may omit the weight from the notation and simply write $\\mathfrak{M}_{r}(\\mathbf{a})$. Let us call $\\omega$ a \\textit{weight vector} if $w_{1},\\ldots,w_{n}\\geq 0$ and $w_{1}+\\ldots+w_{n}=1$. We can convert almost any vector of non-negative real numbers into a weight vector. If $\\tau=(t_{1},\\ldots,t_{n})$ is an arbitrary vector not all elements zero, then\n\t\t\\begin{align*}\n\t\t\t\\omega\n\t\t\t\t& = \\left(\\dfrac{t_{1}}{t_{1}+\\ldots+t_{n}},\\ldots,\\dfrac{t_{n}}{t_{1}+\\ldots+t_{n}}\\right)\n\t\t\\end{align*}\n\tis a weight vector. The power mean inequality applies to weighted means as well.\n\t\t\\begin{theorem}[\\itshape Weighted Power Mean Inequality]\\label{thm:weightedpowermean}\n\t\t\tLet $\\mathbf{a}$ and $\\omega$ be vectors with $n$ elements. Then for real numbers $r,s$ such that $r\\leq s$,\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\min\\{\\mathbf{a}\\} \\leq \\mathfrak{M}_{r}(\\mathbf{a},\\omega)\n\t\t\t\t\t\t& \\leq \\mathfrak{M}_{s}(\\mathbf{a},\\omega)\\leq \\max\\{\\mathbf{a}\\}\n\t\t\t\t\\end{align*}\n\t\t\\end{theorem}\n\tA special case of this is the \\index{weighted arithmetic-geometric mean inequality}\\textit{weighted arithmetic-geometric mean inequality}.\n\t\t\\begin{align}\n\t\t\tw_{1}a_{1}+\\ldots+w_{n}a_{n}\n\t\t\t\t& \\geq a_{1}^{w_{1}}\\cdots a_{n}^{w_{n}}\\label{eqn:weightedamgm}\n\t\t\\end{align}\n\\end{document}", "meta": {"hexsha": "e023e175aea9f14e3c6cddb2565c3e71503ca697", "size": 4993, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "powermean.tex", "max_stars_repo_name": "ineq-tech/inequality", "max_stars_repo_head_hexsha": "ebf89351c843b6a7516e10e2ebf0d64e3f1f3f83", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-06T08:29:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-06T08:29:30.000Z", "max_issues_repo_path": "powermean.tex", "max_issues_repo_name": "ineq-tech/inequality", "max_issues_repo_head_hexsha": "ebf89351c843b6a7516e10e2ebf0d64e3f1f3f83", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "powermean.tex", "max_forks_repo_name": "ineq-tech/inequality", "max_forks_repo_head_hexsha": "ebf89351c843b6a7516e10e2ebf0d64e3f1f3f83", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.8441558442, "max_line_length": 414, "alphanum_fraction": 0.6713398758, "num_tokens": 1869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8856314738181875, "lm_q1q2_score": 0.7240696883075093}}
{"text": "\\chapter{Number}\n\n\\section{Natural number}\n\n\\index{natural number}%\nThe set of all \\emph{natural numbers} is \\(\\Nat\\).\nThe symbol \\(\\Nat\\) is also used for the type of natural numbers.\n\n\\section{Peano axioms}\n\n\\index{Peano axioms}%\nThe \\emph{Peano axioms} are\n\\begin{enumerate*}[label={(\\arabic*)}]\n    \\item \\(0 : \\Nat\\),\n    \\item \\(n : \\Nat \\implies S(n) : \\Nat\\),\n    \\item \\(S(x) = S(y) \\iff x = y\\),\n    \\item the\n\\index{axiom of induction}%\n\\index{induction!axiom of}%\n\\emph{axiom of induction}:\n\\end{enumerate*}\n\\[\n    \\phi(0) \\wedge (\\forall n \\in \\Nat : [\\phi(n) \\implies \\phi(S(n))]) \\implies (\\forall n \\in \\Nat : \\phi(n))\n\\]\n\\index{successor}%\nwhere \\(S\\) is the \\emph{successor symbol}.\nThus, \\(1 = S(0), ~ 2 = S(1) = S(S(0)), ~ 3 = S(2) = S(S(1)) = S(S(S(0)))\\), and so on.\n\n\\section{Construction}\n\n\\index{Zermelo construction of natural numbers}%\n\\index{natural number!Zermelo construction}%\nZermelo construction:\n\\(S(n) = \\{n\\}\\).\nThus, \\(0 = \\emptyset\\), \\(1 = \\{\\emptyset\\}\\), \\(2 = \\{\\{\\emptyset\\}\\}\\), and so on.\n\n\\index{von Neumann construction of natural numbers}%\n\\index{natural number!von Neumann construction}%\nVon Neumann construction:\n\\(0 = \\{\\}\\),\n\\(S(n) = n \\cup \\{n\\}\\).\nThus \\(0 \\leftrightarrow \\{\\}\\), \\(1 \\leftrightarrow \\{\\{\\}\\}\\), \\(2 \\leftrightarrow \\{\\{\\}, \\{\\{\\}\\}\\}\\), and so on.\nProperty: \\(n \\subseteq S(n)\\).\n\n\\section{Closure under successor}\n\n\\(\\Nat\\) is the smallest set closed under successor.\n\nAssert: \\(\\Nat = S(\\Nat)\\).\n\nEquation:\n\\(\\Nat = \\Nat \\cup \\{\\Nat\\}\\).\n\nConsequence:\n\n\\(x \\in \\Nat \\iff x \\in \\Nat \\vee x \\in \\{\\Nat\\}\\)\n\n\\(x \\in \\Nat \\iff x = \\Nat\\)\n?\n\n\\section{Integer}\n\n\\index{integer}%\n\\index{number!integer}%\n\\(\\Int\\) is the set of all \\emph{integers}.\n\\begin{enumerate*}[label={(\\arabic*)}]\n    \\item \\(\\Nat \\subseteq \\Int\\),\n    \\item \\(\\forall x \\in \\Int : (-x) \\in \\Int\\), and\n    \\item \\(x + (-x) = 0\\).\n\\end{enumerate*}\n\n\\(\\Int\\) is the smallest superset of \\(\\Nat\\)\nsuch that \\(\\Int\\) is closed under negation.\n\n\\section{Rational number}\n\n\\index{number!rational}%\n\\index{rational number}%\nThe set of all \\emph{rational numbers} is\n\\(\\Rational = \\{ a/b ~|~ a : \\Int, b : \\Int, b \\neq 0 \\}\\).\nIff \\(x : \\Rational\\) and \\(x \\neq 0\\) then \\(x/x = 1\\).\n\n\\section{Real number}\n\n\\index{number!real}%\n\\index{real number}%\n\\index{digit}%\n\\index{base (positional notation)}%\n\\(\\Real\\) is the \\emph{set of all real numbers}.\nThe \\emph{base-\\(b\\) positional notation} of a real number\nis \\(\\ldots a_2 a_1 a_0 . a_{-1} a_{-2} \\ldots\\).\nThe value of that number is \\(\\sum_{k \\in \\Int} a_k b^k\\)\nwhere each \\(a_k\\) is a \\emph{digit} and \\(b\\) is the \\emph{base},\nwhere \\(b \\in \\Nat\\), \\(b > 1\\).\n\\(\\Real\\) is isomorphic to \\(B^\\infty\\) where \\(1 < |B| < \\infty\\).\n\n\\section{Complex number}\n\n\\index{complex number}\n\\(\\Complex = \\{ a + bi ~|~ a \\in \\Real, b \\in \\Real \\}\\)\nis the set of all \\emph{complex numbers} where \\(i = \\sqrt{-1}\\).\n\n\\index{Euler's identity}%\n\\emph{Euler's identity} is \\( e^{i \\pi} + 1 = 0 \\).\n\nLet \\(z = a+bi = re^{it}\\).\n\\index{complex number!rectangular form}%\n\\index{rectangular form!of a complex number}%\nThe \\emph{rectangular form} of \\(z\\) is \\(a+bi\\).\n\\index{complex number!polar form}%\n\\index{polar form!of a complex number}%\nThe \\emph{polar form} of \\(z\\) is \\(re^{it}\\).\n\\index{conjugate!of a complex number}%\n\\index{complex number!conjugate}%\n\\index{complex conjugate}%\nThe \\emph{conjugate} of \\(z\\) is \\(\\conjbar{z} = \\conjstar{z} = a-bi = re^{-it}\\).\n\\index{complex magnitude}%\n\\index{complex number!magnitude}%\n\\index{magnitude!of a complex number}%\nThe \\emph{magnitude} of \\(z\\) is \\(\\abs{z} = r = \\sqrt{z\\conj{z}} = \\sqrt{a^2+b^2}\\).\n\\index{complex argument}%\n\\index{complex number!argument}%\n\\index{argument!of a complex number}%\nThe \\emph{argument} of \\(z\\) is \\(\\arg(z) = \\{ t ~|~ z = \\abs{z} e^{it} \\}\\).\n\\index{complex argument!principal value}%\n\\index{complex number!principal value of argument}%\n\\index{principal value of the complex argument}%\nThe \\emph{principal value of the argument} of \\(z\\) is \\(\\Arg(z)\\)\nwhich is the element of \\(\\arg(z)\\) closest to zero.\n\n\\section{Prime}\n\n\\index{coprime numbers}%\n\\index{number!coprime}%\nTwo numbers are \\emph{coprime} iff their only common divisor is 1.\n\\index{prime number}%\n\\index{number!prime}%\nA \\emph{prime number} is divisible by 1 and itself only, except 1.\n\nLet \\(P\\) be the set of all prime numbers.\n\n\\paragraph{Nontrivial multiples}\nLet \\(\\{\\Nat\\ge 2\\} = \\Nat - \\{0,1\\}\\).\nLet \\(M(n) = \\{ k n : k \\in N_2 \\}\\) be the set of nontrivial multiples of \\(n\\).\nThen \\( \\Nat - P = \\bigcup_{n \\in \\{\\Nat\\ge 2\\}} M(n) \\).\nProperty: \\(M(ab) \\supseteq M(a) \\cap M(b)\\).\nProperty: \\(M(ab) \\subseteq M(a)\\).\nProperty: iff \\(gcd(a,b)=1\\) then \\(M(a) \\cap M(b) = \\emptyset\\).\n\nDefine \\(Q(A) = \\bigcup_{a \\in A} M(a)\\).\nProperty: \\(Q(\\emptyset) = \\emptyset\\).\nProperty: \\(Q(\\{a\\}) = M(a)\\).\nProperty: \\(Q(A \\cap B) \\subseteq Q(A)\\).\nProperty: \\(Q(A \\cup B) \\supseteq Q(A)\\).\n\nDefine \\(R(n) = \\bigcup_{k=2}^n Q(n)\\).\n\nDefine \\(M_n(d) = M(d) \\cap \\{\\Nat \\le n\\}\\).\nDefine \\(Q_n(A) = Q(A) \\cap \\{\\Nat \\le n\\}\\).\nDefine \\(R_n(m) = R(m) \\cap \\{\\Nat \\le n\\}\\).\nProperty: \\(|M_n(d)| \\le \\lfloor n/d \\rfloor\\).\nDefine \\(u_n(m) = |R_n(m)| / |\\{\\Nat \\le n\\}|\\).\nDefine \\(u(m) = \\lim_{n \\to \\infty} u_n(m)\\).\n\nExample: \\(u(2) = 1/2\\), \\(u(3) = u(4) = 4/6\\), \\(u(5) = u(6) = 23/30\\), \\(u(7) = u(8) = u(9) = u(10) = 86/105\\).\n\n\\section{Primality and monoid}\n\nThe ordered pair \\((a,b)\\) is a \\emph{2-factorization} of \\(x\\) iff \\(ab = x\\).\nThe \\emph{2-factorization set} of \\(x\\) is \\(F(x) = \\{ (a,b) ~|~ ab = x \\}\\).\n\nIn \\(\\Nat\\):\nIf \\(x \\ge 1\\) then \\(|F(x)|\\) is even.\nLet \\(G(n) = \\{ x : |F(x)| = n \\}\\).\n\n\\paragraph{Factor}\nIff \\(ab = x\\) then\n\\(a\\) is a \\emph{left factor} of \\(x\\),\n\\(a\\) is a \\emph{left divisor} \\(x\\),\n\\(a\\) \\emph{left-divides} \\(x\\),\n\\(b\\) is a \\emph{right factor} of \\(x\\),\n\\(b\\) is a \\emph{right divisor} of \\(x\\),\n\\(b\\) \\emph{right-divides} \\(x\\),\n\\(a\\) is a \\emph{factor} of \\(x\\),\nand \\(b\\) is a \\emph{factor} of \\(x\\).\nIff \\(ab = x\\) and \\(ac = y\\),\nthen \\(a\\) is a \\emph{common left factor} of \\(x\\) and \\(y\\).\nIff \\(ab = x\\) and \\(cb = x\\),\nthen \\(b\\) is a \\emph{common right factor} of \\(x\\) and \\(y\\).\nA \\emph{common factor} is a common left factor or common right factor.\n\n\\paragraph{Prime}\n\\(x\\) is\n\\emph{prime} iff \\(F(x) = \\{(1,x),(x,1)\\}\\),\n\\emph{composite} iff it is not prime.\n\nWhat is the maximum number of primes in a monoid with n elements?\nLet the answer be a(n).\na(1)=0. a(2)=1. a(3)=2. a(n)=n-1?\n\nAn \\emph{ordered monoid} is a monoid and an order \\(\\le\\).\n\nA \\emph{monotone monoid} is a monoid where \\(a \\le ab\\) and \\(b \\le ab\\).\n\nThe element \\(g\\) is a\n\\index{generator}%\n\\emph{generator} of \\((S,\\cdot,1)\\) iff \\(\\{g^n ~|~ n \\in \\Nat\\} = S\\)\nwhere \\(g^0 = 1\\) and \\(g^{n+1} = g \\cdot g^n\\).\n\n\\section{R2 = R}\n\nThere is a bijection between \\(\\Real^2\\) and \\(\\Real\\).\nWe do this by interleaving the digits.\n\\[\n    (x, y) \\leftrightarrow \\ldots X_2 Y_2 X_1 Y_1 X_0 Y_0 . x_1 y_1 x_2 y_2 x_3 y_3 \\ldots\n\\]\n", "meta": {"hexsha": "47d8330b9ea8e7016d65da5e03bcd39cf4373e05", "size": 6979, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/number.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/number.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/number.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 32.1612903226, "max_line_length": 117, "alphanum_fraction": 0.5952142141, "num_tokens": 2666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.7240234398870956}}
{"text": "\\documentclass{article}\n\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{mathpartir}\n\n\\usepackage{fullpage} % this is useful if you have wide derivations etc.\n\n% Some commands\n\\newcommand{\\eval}{\\Downarrow}\n\\newcommand{\\reduces}{\\to}\n\\newcommand{\\reducess}{\\twoheadrightarrow}\n\n\\title{Example of evaluation and typing derivations in \\LaTeX}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Inference rules}\n\n\\begin{mathpar}\n\\inferrule[E-Iszero]\n{t \\reduces t'}\n{\\texttt{iszero}\\ t \\reduces \\texttt{iszero}\\ t'}\n\n\\inferrule[E-IszeroZero]\n{}\n{\\texttt{iszero 0} \\reduces \\texttt{true}}\n\n\\inferrule[E-IszeroSucc]\n{}\n{\\texttt{iszero (succ}\\ nv \\texttt{)} \\reduces \\texttt{false}}\n\n\\inferrule[E-Succ]\n{t \\reduces t'}\n{\\texttt{succ}\\ t \\reduces \\texttt{succ}\\ t'}\n\n\\inferrule[E-Pred]\n{t \\reduces t'}\n{\\texttt{pred}\\ t \\reduces \\texttt{pred}\\ t'}\n\n\\inferrule[E-PredZero]\n{}\n{\\texttt{pred}\\ 0 \\reduces \\texttt{0}}\n\n\\inferrule[E-PredSucc]\n{}\n{\\texttt{pred (succ}\\ nv \\texttt{)} \\reduces nv}\n\n\\inferrule[E-IfTrue]\n{}\n{\\texttt{if true then}\\ t_2\\ \\texttt{else}\\ t_3\\ \\reduces t_2}\n\n\\inferrule[E-IfFalse]\n{}\n{\\texttt{if false then}\\ t_2\\ \\texttt{else}\\ t_3\\ \\reduces t_3}\n\n\\inferrule[E-If]\n{t_1 \\reduces t_1'}\n{\\texttt{if}\\ t_1 \\ \\texttt{then}\\ t_2\\ \\texttt{else}\\ t_3\\ \\reduces \n \\texttt{if}\\ t_1' \\ \\texttt{then}\\ t_2\\ \\texttt{else}\\ t_3}\n\\end{mathpar}\n\n\n\\section{Derivations}\n\n\\begin{mathpar}\n\\inferrule*[right=B-IfTrue]\n{\\inferrule*[right=B-True]{}{\\texttt{true} \\eval \\texttt{true}} \\\\\n \\inferrule*[right=B-False]{}{\\texttt{false} \\eval \\texttt{false}} }\n{\\texttt{if true then false else true}\\ \\eval \\texttt{false}}\n\\end{mathpar}\n\n\\begin{mathpar}\n\\inferrule*[right=B-IfFalse]\n{\\inferrule*[right=B-False]{}{\\textsf{false} \\eval \\textsf{false}} \\and\n \\inferrule*[right=B-IfTrue]\n  {\n    \\inferrule*[right=B-True]{}{\\textsf{true} \\eval \\textsf{true}} \\\\\n    \\inferrule*[right=B-False]{}{\\textsf{false} \\eval \\textsf{false}}}\n  {\\textsf{if true then false else true} \\eval \\textsf{false}} \n}\n{\\textsf{if false then true else (if true then false else true)}\\ \\eval \\textsf{false}}\n\\end{mathpar}\n\n\\end{document}\n", "meta": {"hexsha": "59f1583c2d01843812ef719d5d5f074f0f04b991", "size": 2097, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "media/papers/TR/latex_example.tex", "max_stars_repo_name": "akrzemi1/Mach7", "max_stars_repo_head_hexsha": "eef288eb9fe59712ff153dd70791365391b7b118", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1310, "max_stars_repo_stars_event_min_datetime": "2015-01-04T03:44:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:44:01.000Z", "max_issues_repo_path": "media/papers/TR/latex_example.tex", "max_issues_repo_name": "akrzemi1/Mach7", "max_issues_repo_head_hexsha": "eef288eb9fe59712ff153dd70791365391b7b118", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 62, "max_issues_repo_issues_event_min_datetime": "2015-01-12T07:59:17.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-14T22:02:14.000Z", "max_forks_repo_path": "media/papers/TR/latex_example.tex", "max_forks_repo_name": "akrzemi1/Mach7", "max_forks_repo_head_hexsha": "eef288eb9fe59712ff153dd70791365391b7b118", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 108, "max_forks_repo_forks_event_min_datetime": "2015-02-13T17:39:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-18T11:06:59.000Z", "avg_line_length": 23.5617977528, "max_line_length": 87, "alphanum_fraction": 0.6871721507, "num_tokens": 803, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.8333246035907932, "lm_q1q2_score": 0.724014740219218}}
{"text": "\\section{Feasibility Study}\n\nBelow we show how it's possible to directly implement the three main vector type transformations (along\nwith a couple of other particularly useful ones) in Idris, which are guaranteed to be correct at compile time.\n\nThe \\textit{Shape} of a vector is defined as an Idris \\textit{Vect} of a given number dimensions, each\nrepresented as a natural number. This shape is used to define the vector type.\n\nDefining the vector requires a recursive type definition, having the base case of a 0 dimensional vector \nequivalent to the base vector type. This follows from the result that if any dimension in the\nvector has 0 elements, then the vector itself must have no elements.\n\n\\inputIdrisListing{code/vector.idr}\n\n\n\\subsection{Implementing Vector Type Transformation Functions}\n\nFrom the \\textit{Vector} definition it's trivial to define the \\textit{singleton} function\nas a function taking an n dimensional \\textit{Vector} and mapping it to a 1+n dimensional\n\\textit{Vector}, as well as its inverse function:\n\n\\inputIdrisListing{code/singleton.idr}\n\n\nDefining the \\textit{map} instance uses pattern matching on the dependent types\nto check whether the number of dimensions the \\textit{Vector} has is 0, in which case the \ngiven function is applied to the single element. Otherwise the map function is applied\nrecursively to all elements in the \\textit{Vector} until all the base elements have been\ntransformed.\n\n\\inputIdrisListing{code/map.idr}\n\n\nTaking a given \\textit{Vector} which has 2 or more dimensions, we can decrease \nthe dimensionality by 1 by concatenating all the Sub-Vectors as follows\n\\inputIdrisListing{code/redDim.idr}\nThis results in a \\textit{Vector} with a dimensionality of one less than the input \\textit{Vector}.\nThe new \\textit{Vector} contains the same elements as the input \\textit{Vector}, and ordering is\nalso preserved. \n\n\n\\begin{figure*}\n\\begin{center}\n\\includegraphics[scale=0.65]{images/flow.pdf}\n\\caption{Flowchart illustrating the structure of the Framework.}\n\\label{flow}\n\\end{center}\n\\end{figure*}\n\n\\inputIdrisListing{code/reshape.idr}\n\\newpage\n\\inputIdrisListing{code/reshapeInv.idr}\n\n\nTaking a given \\textit{Vector} which has 1 or more dimensions; in which the most \"outer\" dimension is\nmade up of \\textbf{n * m} elements, where \\textbf{n, m} $\\in \\mathbb{N}$. We can increase the dimensionality of\nthe given \\textit{Vector} by 1 by splitting the \\textit{Vector} at each \\textbf{n} sub-Vectors which results in \n\\textbf{m} lots of \\textbf{n} sub-Vectors. \n\\inputIdrisListing{code/incDim.idr}\n\n\nDefining the \\textit{reshape} transformation function and its inverse can be achieved with aid from the \nincrease and decreasing dimensional transformations listed above.\n\n\nDue to Idris' support for implementing EDSLs, and the ability to directly implement\nthe vector transformations, it should be feasible to fit these transformations\ninto an EDSL. \n\n\n", "meta": {"hexsha": "7f0b3e8bf2eab209ff47e9de93be98bbab3b9dcf", "size": 2906, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "proposal/include/feasibility_study.tex", "max_stars_repo_name": "RossMeikleham/MSci-Project", "max_stars_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-10-20T11:17:45.000Z", "max_stars_repo_stars_event_max_datetime": "2015-10-20T11:17:45.000Z", "max_issues_repo_path": "proposal/include/feasibility_study.tex", "max_issues_repo_name": "RossMeikleham/MSci-Project", "max_issues_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "proposal/include/feasibility_study.tex", "max_forks_repo_name": "RossMeikleham/MSci-Project", "max_forks_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.9295774648, "max_line_length": 112, "alphanum_fraction": 0.7911218169, "num_tokens": 725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245911726382, "lm_q2_score": 0.8688267762381844, "lm_q1q2_score": 0.7240147181085262}}
{"text": "\n\n\n\\input{../preamble}\n\\DeclareMathOperator{\\Ce}{Re}\n\n\n\n\\begin{document}\n\\title{Crash Course on Representation Theory - Day 2}\n\\author{Apurva Nakade}\n\\thispagestyle{fancy}\n\\maketitle\n\n\n\nCharacter theory is the part of representation theory that allows one to determine the `prime' decomposition of representations.\n\n\\section{Character Theory}\nGiven a linear transformation $A \\in GL(V)$ we can define the trace of $A$ to be the sum of diagonal entries of $A$ in any basis, recall that the trace does not depend upon the choice of any basis. For a representation $\\rho$ we can post-compose with the trace map, the resulting function is called the \\textbf{character} of the representation.\n\\begin{align}\n\t\\chi_{\\rho}: G \\xrightarrow{\\rho} GL(V) \\xrightarrow{\\mathrm{trace}} \\C\n\\end{align}\nThe trace is a single number associated to a matrix and hence contains very little information about the matrix, but as it turns out, the character of a representation (which is a function $G \\rightarrow \\C$) contains enough information to differentiate between representations. We say that the character is a complete invariant of representations.\n\n\n\\subsection{Orthogonality relations}\nWe can use characters to define a hermitian inner product on the space of representations! For representations $\\rho_1, \\rho_2$ define an inner product and norm as\n\\begin{align}\n\t\\innerp{\\rho_1}{\\rho_2} & = \\dfrac{1}{|G|} \\sum \\limits _ {g \\in G} {\\chi_{\\rho_1}(g)} \\conj{\\chi_{\\rho_2}(g)} \\\\\n\t\\norm{\\rho_1}^2         & = \\innerp{\\rho_1}{\\rho_1}\n\\end{align}\n\nThe following is an EXTREMELY useful theorem in character theory (which requires nothing more than linear algebra to prove).\n\\begin{thm}[Orthogonality relations] $\\:$\n\tLet $\\rho_1, \\rho_2, \\ldots, \\rho_d$ be the distinct irreducible representations of $G$. If $\\rho$ is an arbitrary representation which has a decomposition $\\sigma = \\rho_1^{k_1} \\oplus \\rho_2^{k_2} \\oplus \\cdots \\oplus \\rho_d^{k_d} $ then\n\t\\begin{align}\n\t\t\\innerp{\\rho_i}{\\sigma} & = k_i\n\t\\end{align}\n\tIn particular, we have $\\norm{\\chi_{\\rho_i}} = 1$ for all $i$ and $\\innerp{\\chi_{\\rho_1}}{\\chi_{\\rho_2}} = 0$ for $i \\neq j$.\n\\end{thm}\n\n\\subsection{Character Tables}\nBy the cyclicity of trace we have\n\\begin{align*}\n\t\\chi_\\rho(h^{-1}gh) = \\mathrm{trace}(\\rho(h)^{-1} \\rho(g) \\rho(h)) = \\mathrm{trace}(\\rho(h)\\rho(h)^{-1} \\rho(g)) = \\mathrm{trace}(\\rho(g)) = \\chi_\\rho(g)\n\\end{align*}\nand so to determine the character of a representation it is enough to determine the character of one element in each conjugacy class. Such information is typically organized in a table called the \\textbf{character table}. The character tables from the examples from yesterday's notes are as follows.\n\n\\begin{align*}\n\t\\mbox{\n\t\\begin{tabular}{r|ccc}\n\t$\\Z/3$      & \\{0\\}     & \\{1\\}                              & \\{2\\}                                \\\\\n\t\\hline\n\t            & 1         & 1                                  & 1                                    \\\\\n\t            & 1         & $\\omega$                           & $\\omega^2$                           \\\\\n\t            & 1         & $\\omega^2$                         & $\\omega$\n\t\\end{tabular}\n\t}\n\t&\\qquad \\qquad\n\t\\mbox{\n\t\\begin{tabular}{r|ccc}\n\t$S_3(=D_6)$ & $\\{(1)\\}$ & $\\{(1 \\: 2); (2 \\: 3); (1 \\: 3)\\}$ & $\\{ (1 \\: 2 \\: 3); (1 \\: 3 \\: 2) \\}$ \\\\\n\t\\hline\n\ttrivial     & 1         & 1                                  & 1                                    \\\\\n\tsign        & 1         & -1                                 & 1                                    \\\\\n\t2-dim       & 1         & 0                                  & $2\\cos(2 \\pi / 3)$\n\t\\end{tabular}\n\t}\n\\end{align*}\n\n\\begin{center}\n\n\\end{center}\n\n\\begin{center}\n\n\\end{center}\n\n\\begin{center}\n\t\\begin{table}[H]\n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{r|ccccc}\n\t\t\t\t$Q_8$             & $\\{ 1 \\}$ & $\\{ -1 \\}$ & $\\{ i, -i \\}$ & $\\{ j, -j \\}$ & $\\{ k, -k \\}$ \\\\\t\\hline\n\t\t\t\ttrivial           & 1         & 1          & 1             & 1             & 1             \\\\\n\t\t\t\t$\\mathrm{sign}_i$ & 1         & 1          & 1             & -1            & -1            \\\\\n\t\t\t\t$\\mathrm{sign}_j$ & 1         & 1          & -1            & 1             & -1            \\\\\n\t\t\t\t$\\mathrm{sign}_k$ & 1         & 1          & -1            & -1            & 1             \\\\\n\t\t\t\t2-dim             & 2         & -2         & 0             & 0             & 0\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\t\\end{table}\n\\end{center}\n\n\n\\section{Frobenius determinant}\nThe Frobenius determinant can be easily computed using linear algebra. We'll do it using representation theory, this is completely unnecessary.\n\n\nThe first thing to observe is that the Frobenius matrix $F_n$ is constructed out of the regular representation for the group $\\Z/n$. Consider the $n$ dimensional vector space with basis $e_0, e_1, \\ldots, e_{n-1}$ on which $\\Z/n$ acts as:\n\\begin{align}\n\t\\rho(k)(e_j) & = e_{(k+j \\mod n)}\n\\end{align}\nThe $j^{th}$ column of the matrix $\\rho(k)$ has the 1 in the $(k+j \\mod n)^{th}$ place and 0 everywhere else. This is exactly the place where the $x_k's$ occur in the Frobenius matrix!!! Hence we get the identity\n\\begin{align}\n\t\\label{eq:eq1}\n\tF_n = \\sum \\limits_{k=0}^n x_k \\rho(k) = \\sum \\limits_{k=0}^n x_k \\rho(1)^k\n\\end{align}\nFor $0 \\le l < n$ let $\\rho_l$ be the 1 dimensional irreducible representations of $\\Z/n$ with $\\rho_l(1) = \\omega^l$ where $\\omega = e^{2 \\pi i /n}$. For some constants $c_i$ we must have\n\\begin{align}\n\t\\rho = \\rho_0 ^ {c_0} \\oplus \\cdots \\oplus \\rho_{n-1} ^ {c_{n-1}}\n\\end{align}\nTo compute $c_l$ we compute the inner product $c_l = \\innerp{\\rho_l}{\\rho}=\\sum \\limits _ {k \\in \\Z/n} {\\chi_{\\rho_l}(k)} \\conj{\\chi_{\\rho}(k)}/n$. The matrices $\\rho(k)$ have all the diagonal entries 0 except for $k = 0$ which has all the diagonal entries 1 and hence $\\chi_\\rho(k) = \\begin{cases} n \\mbox{ if k = 0} \\\\ 0 \\mbox{ otherwise} \\end{cases}$ so that $c_l = 1$ for all $l$ and we get\n\\begin{align}\n\t\\rho = \\rho_0 \\oplus \\rho_1 \\oplus \\cdots \\oplus \\rho_{n-1}\n\\end{align}\nWe can choose a basis such that the matrix $\\rho(1)$ is a diagonal matrix with entries $\\rho_l(1) = \\omega^l$, plugging in \\eqref{eq:eq1}\n\\begin{align}\n\tF_n = \\sum \\limits_{k=0}^n \\begin{bmatrix} x_k &   &   &   \\\\ &  \\omega^k x_k & & \\\\ & & \\ddots & \\\\ & & & \\omega^{(n-1)k} x_k & \\end{bmatrix}\n\t&=\n\t\\begin{bmatrix} \\sum \\limits_{k=0}^n x_k       &   &   &   \\\\ & \\sum \\limits_{k=0}^n \\omega^k x_k & & \\\\ & & \\ddots & \\\\ & & & \\sum \\limits_{k=0}^n \\omega^{(n-1)k}x_k & \\end{bmatrix} \\\\\n\t\\implies \\det F_n\t= \\prod \\limits_{l=0}^{n-1} \\sum \\limits_{k=0}^n \\omega^{kl} x_k &= \\prod \\limits_{l=0}^{n-1}\\left(x_0 + \\omega^{l} x_1 + \\cdots + \\omega^{(n-1)l}x_{n-1}\\right)\n\\end{align}\n\\begin{flushright}\n\t$\\qed$\n\\end{flushright}\nThis naturally leads to the following question.\n\\begin{ques}\n\tConsider the Frobenius matrix $F_G$ whose entries are obtained from the multiplication table for $G$ i.e. the rows and columns are indexed by the entries of $G$ and the $g,h^{th}$ entry is $x_{gh^{-1}}$. What is $\\det F_G$?\n\\end{ques}\nThe above proof generalizes directly to an arbitrary group and the determinant can be computed in terms of the regular representation of $G$ and the irreducible representations of $G$.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\iffalse\n\\subsection{Standard representation of $S_n$}\nAs we saw earlier the standard representation of $S_n$ breaks down into two representations $W \\oplus W^{\\perp}$ where $W$ is the 1 dimensional vectors space spanned by $e_1 + \\cdots + e_n$ and $W^{\\perp}$ is the perpendicular vector space consisting of vectors of the form $\\{ c_1 e_1 + \\cdots + c_n e_n : c_1 + \\cdots + c_n = 0\\}$\nAs we saw earlier the standard representation of $S_n$ breaks down into two representations $W \\oplus W^{\\perp}$ where $W$ is the 1 dimensional vectors space spanned by $e_1 + \\cdots + e_n$ and $W^{\\perp}$ is the perpendicular vector space consisting of vectors of the form $\\{ c_1 e_1 + \\cdots + c_n e_n : c_1 + \\cdots + c_n = 0\\}$\n\\begin{proposition}\n\t\\begin{align}\n\t\t\\dfrac{1}{n!}\\sum\\limits_{\\sigma \\in S_n} (\\mbox{number of fixed points of } \\sigma)^2 = 2\n\t\\end{align}\n\\end{proposition}\n\\fi\n\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "e878f834024d85c291123c94f031627704f1f82c", "size": 8106, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "05 Representation theory/02 Character Theory.tex", "max_stars_repo_name": "apurvnakade/mc2017", "max_stars_repo_head_hexsha": "ebec59bce5ee1979872e0f37208da6abd91dbb75", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "05 Representation theory/02 Character Theory.tex", "max_issues_repo_name": "apurvnakade/mc2017", "max_issues_repo_head_hexsha": "ebec59bce5ee1979872e0f37208da6abd91dbb75", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "05 Representation theory/02 Character Theory.tex", "max_forks_repo_name": "apurvnakade/mc2017", "max_forks_repo_head_hexsha": "ebec59bce5ee1979872e0f37208da6abd91dbb75", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.037037037, "max_line_length": 394, "alphanum_fraction": 0.597582038, "num_tokens": 2634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7240147132138346}}
{"text": "\\section{Functions of Several Variables}\\label{sec:FunctionsSeveralVariables}\n\nIn single-variable calculus we were concerned with functions that map\nthe real numbers $\\mathbb{R}$ to $\\mathbb{R}$, sometimes called ``real functions of\none variable'', meaning the ``input'' is a single real number and the\n``output'' is likewise a single real number. Now we turn to functions of several\nvariables, where several input variables are mapped to one value: functions\n$f\\colon\\mathbb{R}^n\\to\\mathbb{R}$. We will deal primarily with $n=2$ and to a lesser\nextent $n=3$; in fact many of the techniques we discuss can be applied\nto larger values of $n$ as well.\n\nA function $f\\colon\\mathbb{R}^2\\to\\mathbb{R}$ maps a pair of values $(x,y)$ to a\nsingle real number. The three-dimensional coordinate system we have\nalready used is a convenient way to visualize such functions: above\neach point $(x,y)$ in the $x$-$y$ plane we graph the point $(x,y,z)$,\nwhere of course $z=f(x,y)$. \n\n\\begin{example}{Plane}{PlaneFunction}\nDescribe the function $f(x,y)=3x+4y-5$.\n\\end{example}\n\\begin{solution}\nWriting this as \n$z=3x+4y-5$ and then $3x+4y-z=5$ we recognize the equation of a\nplane. In the form $f(x,y)=3x+4y-5$ the emphasis has shifted: we now\nthink of $x$ and $y$ as independent variables and $z$ as a variable\ndependent on them, but the geometry is unchanged.\n\\end{solution}\n\n\\begin{example}{Sphere}{SphereEquation}\nDescribe the equation $x^2+y^2+z^2=4$.\n\\end{example}\n\\begin{solution}\nWe have seen that $x^2+y^2+z^2=4$ represents a sphere of radius\n2. We cannot write this in the form $f(x,y)$, since for\neach $x$ and $y$ in the disk $x^2+y^2<4$ there are two corresponding\npoints on the sphere. As with the equation of a circle, we can resolve\nthis equation into two functions, $\\ds f_1(x,y)=\\sqrt{4-x^2-y^2}$ and \n$\\ds f_2(x,y)=-\\sqrt{4-x^2-y^2}$, representing the upper and lower\nhemispheres, respectively. Each of these is an example of a function with a\nrestricted domain: only certain values of $x$ and $y$ make sense\n(namely, those for which $x^2+y^2\\le 4$) and the graphs of these\nfunctions are limited to a small region of the plane.\n\\end{solution}\n\n\\begin{example}{Square Root}{MultivariateSquareRootFunction}\nDescribe the function $f(x,y)=\\sqrt x+\\sqrt y$.\n\\end{example}\n\\begin{solution}\nThis function is defined only when\nboth $x$ and $y$ are non-negative. When $y=0$ we get $f(x,y)=\\sqrt x$,\nthe familiar square root function in the $x$-$z$ plane, and when $x=0$\nwe get the same curve in the $y$-$z$ plane. Generally speaking, we see\nthat starting from $f(0,0)=0$ this function gets larger in every direction\nin roughly the same way that the square root function gets\nlarger. For example, if we restrict attention to the line $x=y$, we\nget $f(x,y)=2\\sqrt x$ and along the line $y=2x$ we have $f(x,y)=\\sqrt\nx+\\sqrt{2x}=(1+\\sqrt2)\\sqrt x$.\n\\end{solution}\n\n\\begin{figure}[H]\n%\\texonly\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n\\put {\\hbox{\\epsfxsize5cm\\epsfbox{images/square_root.eps}}} at 0 0\n\\endpicture}}\n%\\endtexonly\n\\caption{$f(x,y)=\\sqrt{x}+\\sqrt{y}$}\n\\label{fig:double square root}\n\\end{figure}\n\nA computer program that plots such surfaces can be very useful, as it\nis often difficult to get a good idea of what they look like. Still,\nit is valuable to be able to visualize relatively simple surfaces\nwithout such aids. As in the previous example, it is often a good idea\nto examine the function on restricted subsets of the plane, especially\nlines. It can also be useful to identify those points $(x,y)$ that\nshare a common $z$-value.\n\n\\begin{example}{Elliptic Paraboloid}{EllipticParaboloidFunction}\nDescribe the graph of $f(x,y)=x^2+y^2$.\n\\end{example}\n\\begin{solution}\nWhen $x=0$ this becomes\n$f=y^2$, a parabola in the $y$-$z$ plane; when $y=0$ we get the\n``same'' parabola $f=x^2$ in the $x$-$z$ plane. \n\nFinally, picking a value $z=k$, at what points does\n$f(x,y)=k$? This means $x^2+y^2=k$, which we recognize as the equation\nof a circle of radius $\\sqrt k$. So the graph of $f(x,y)$ has\nparabolic cross-sections, and the same height everywhere on concentric\ncircles with center at the origin. This fits with what we have already\ndiscovered. \n\\end{solution}\n\n\\begin{figure}[H]\n%\\texonly\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n\\put {\\hbox{\\epsfxsize5cm\\epsfbox{images/parabolic_bowl.eps}}} at 0 0\n\\put {\\hbox{\\epsfxsize4cm\\epsfbox{images/parabolic_level_curves.eps}}} at 2 0\n\\endpicture}}\n%\\endtexonly\n\\caption{$f(x,y)=x^2 + y^2$}\n\\label{fig:parabolic bowl}\n\\end{figure}\n\nAs in this example, the points $(x,y)$ such that $f(x,y)=k$ usually\nform a curve, called a \\dfont{level curve}\\index{level curve} of the\nfunction. A graph of some level curves can give a good idea of the\nshape of the surface; it looks much like a topographic map of the\nsurface. In Figure~\\ref{fig:parabolic bowl} both the surface and\nits associated level curves are shown. Note that, as with a\ntopographic map, the heights corresponding to the level curves are\nevenly spaced, so that where curves are closer together the surface is\nsteeper.\n\nFunctions $f\\colon\\mathbb{R}^n\\to\\mathbb{R}$ behave much like functions of two\nvariables; we will on occasion discuss functions of three variables.\nThe principal difficulty with such functions is visualizing them, as\nthey do not ``fit'' in the three dimensions we are familiar with. For\nthree variables there are various ways to interpret functions that\nmake them easier to understand. For example, $f(x,y,z)$ could\nrepresent the temperature at the point $(x,y,z)$, or the pressure, or\nthe strength of a magnetic field.  It remains useful to consider those\npoints at which $f(x,y,z)=k$, where $k$ is some constant value. If\n$f(x,y,z)$ is temperature, the set of points $(x,y,z)$ such that\n$f(x,y,z)=k$ is the collection of points in space with temperature $k$;\nin general this is called a \\dfont{level set}; for\nthree variables, a level set is typically a surface, called a \\dfont{level surface}.\n\n\\begin{example}{Level Surfaces}{LevelSurfacesExample}\nSuppose the temperature at $(x,y,z)$ is \n$T(x,y,z)=e^{-(x^2+y^2+z^2)}$. This function has a maximum value of 1\nat the origin, and tends to 0 in all directions. If $k$ is positive\nand at most 1,\nthe set of points for which $T(x,y,z)=k$ is those points satisfying\n$x^2+y^2+z^2=-\\ln k$, a sphere centered at the origin. The level\nsurfaces are the concentric spheres centered at the origin.\n\\end{example}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:FunctionsSeveralVariables}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nLet $f(x,y)=(x-y)^2$. \nDetermine the equations and shapes of the cross-sections when\n$x=0$, $y=0$, $x=y$, and describe the level curves.\nUse a three-dimensional graphing tool to graph the surface.\n\\begin{sol}\n$z=y^2$, $z=x^2$, $z=0$, lines of slope 1\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $f(x,y)=|x|+|y|$. \nDetermine the equations and shapes of the cross-sections when\n$x=0$, $y=0$, $x=y$, and describe the level curves.\nUse a three-dimensional graphing tool to graph the surface.\n\\begin{sol}\n$z=|y|$, $z=|x|$, $z=2|x|$, diamonds\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $f(x,y)=e^{-(x^2+y^2)}\\sin(x^2+y^2)$. \nDetermine the equations and shapes of the cross-sections when\n$x=0$, $y=0$, $x=y$, and describe the level curves.\nUse a three-dimensional graphing tool to graph the surface.\n\\begin{sol}\n$z=e^{-y^2}\\sin(y^2)$, $z=e^{-x^2}\\sin(x^2)$, \n$z=e^{-2x^2}\\sin(2x^2)$, circles\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $f(x,y)=\\sin(x-y)$. \nDetermine the equations and shapes of the cross-sections when\n$x=0$, $y=0$, $x=y$, and describe the level curves.\nUse a three-dimensional graphing tool to graph the surface.\n\\begin{sol}\n$z=-\\sin(y)$, $z=\\sin(x)$, \n$z=0$, lines of slope 1\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $f(x,y)=(x^2-y^2)^2$. \nDetermine the equations and shapes of the cross-sections when\n$x=0$, $y=0$, $x=y$, and describe the level curves.\nUse a three-dimensional graphing tool to graph the surface.\n\\begin{sol}\n$z=y^4$, $z=x^4$, \n$z=0$, hyperbolas\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the domain of each of the following functions of two variables:\n\\begin{enumerate}\n\t\\item\t$\\ds\\sqrt{9-x^2}+\\sqrt{y^2-4}$\n\t\\item\t$\\arcsin(x^2+y^2-2)$\n\t\\item\t$\\ds\\sqrt{16-x^2-4y^2}$\n\\end{enumerate}\n\\begin{sol}\n\\begin{enumerate}\n\t\\item\t$\\{(x,y)\\mid |x|\\le3\\ \\hbox{and}\\ |y|\\ge2\\}$\n\t\\item\t$\\{(x,y)\\mid 1\\le x^2+y^2\\le3\\}$\n\t\\item\t$\\{(x,y)\\mid x^2+4y^2\\le16\\}$\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nBelow are two sets of level curves.  One is for a cone, one\nis for a paraboloid.  Which is which? Explain.\n\n%\\texonly\n\\nobreak\n\\hbox to \\hsize{\\hfill\\epsfxsize4cm\\epsfbox{images/parabolic_level_curves_2.eps}\n\\hfill\\epsfxsize4cm\\epsfbox{images/conical_level_curves.eps}\\hfill}\n%\\endtexonly\n%\\htmlfigure{Partial_Differentiation_two_level_curve_graphs.html}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "a6a52bc6c4e9ce5e211e61dabf1823fe776ae06b", "size": 9052, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14-partial-differentiation/14-1-functions-of-several-variables.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "14-partial-differentiation/14-1-functions-of-several-variables.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "14-partial-differentiation/14-1-functions-of-several-variables.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.0336134454, "max_line_length": 85, "alphanum_fraction": 0.7191780822, "num_tokens": 2902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.810478913248044, "lm_q2_score": 0.8933094159957173, "lm_q1q2_score": 0.7240084446704539}}
{"text": "\\chapter{Triangle Quality Metrics}\n\nAll the metrics in this section are defined on a triangular element\nas illustrated in Figure~\\ref{f:tri}.\n\n\\begin{figure}[bhp]\n  \\centering\n  \\includegraphics[width=2in]{tri}\n  \\caption{Numbering of vertices and edges on a triangular element.%\n                                                                  \\label{f:tri}}\n\\end{figure}\n\nNote that unlike all the other elements that follow,\nwe name edge vectors of the triangle by the vertex opposite the edge so that\n\\begin{equation*}\n\\begin{array}{lcl}\n  \\vec L_0 &=& \\vec P_2 - \\vec P_1\\\\\n  \\vec L_1 &=& \\vec P_0 - \\vec P_2\\\\\n  \\vec L_2 &=& \\vec P_1 - \\vec P_0.\n\\end{array}\n\\end{equation*}\n\nThe triangle edge lengths are denoted as follows:\n\\[\nL_0 = \\normvec{L_0}\\quad\nL_1 = \\normvec{L_1}\\quad\nL_2 = \\normvec{L_2}\n\\]\nand the largest and smallest edge lengths are, respectively,\n\\[\nL_{\\min} = \\min\\left(L_0, L_1, L_2\\right)\n  \\rule{2em}{0pt}\nL_{\\max} = \\max\\left(L_0, L_1, L_2\\right)\n\\]\n\nThe area of a triangle is one half the magnitude of the cross product of any pair of adjacent edge vectors:\n\\begin{equation*}\n  A\n    = \\frac{1}{2}\\normvec{L_0\\times\\vec L_1}\n    = \\frac{1}{2}\\normvec{L_1\\times\\vec L_2}\n    = \\frac{1}{2}\\normvec{L_2\\times\\vec L_0}\n\\end{equation*}\n\nIn addition, we will let $r$ be the inradius\n\\begin{equation*}\n\\label{eq:Arp}\n  r = \\frac{2A}{\\normvec{L_0} + \\normvec{L_1} + \\normvec{L_2}}\n\\end{equation*}\nand $R$ the circumradius\n\\[\n  R = \\frac{\\normvec{L_0} \\normvec{L_1} \\normvec{L_2}}%\n           {2 r \\left(\\normvec{L_0} + \\normvec{L_1} + \\normvec{L_2}\\right)}\n\\]\nof the triangle.\nThese are respectively the radii of the inscribed and circumscribed circles of this triangle.\n\nWe will frequently use $n$ to represent some arbitrary edge $L_n$ or vertex $P_n$ of the triangle.\nWhen referring to the next counterclockwise entry $n+1$ (or clockwise entry $n-1$),\nwe take the result modulo $3$ so that, for example, if $n = 1$, $n+1 = 2$ and $n+2 = 0$.\n\n% -------------------Metric Table-------------------\n\\newcommand{\\trimetrictable}[8]{%\n  \\begin{center}\n  \\begin{tabular}{ll}\n    \\multicolumn{2}{r}{\\textbf{\\sffamily\\Large triangle #1}}\\\\\\hline\n    Dimension:                           & #2\\\\ \n    Acceptable Range:                    & #3\\\\ \n    Normal Range:                        & #4\\\\ \n    Full Range:                          & #5\\\\ \n    $q$ for equilateral unit triangle:   & #6\\\\\n    Reference:                           & #7\\\\\n    \\verd\\ function:       & \\texttt{#8}\\\\ \\hline\n  \\end{tabular} \n  \\end{center}\n}\n\n\\newpage \\input{TriArea}\n\\newpage \\input{TriAspectRatio}\n\\newpage \\input{TriAspectFrobenius}\n\\newpage \\input{TriCondition}\n\\newpage \\input{TriDistortion}\n\\newpage \\input{TriEdgeRatio}\n\\newpage \\input{TriMaximumAngle}\n\\newpage \\input{TriMinimumAngle}\n\\newpage \\input{TriScaledJacobian}\n\\newpage \\input{TriRadiusRatio}\n\\newpage \\input{TriRelativeSizeSquared}\n\\newpage \\input{TriShape}\n\\newpage \\input{TriShapeAndSize}\n", "meta": {"hexsha": "1198528fa63fe41a27b74289241365abdb5fda2f", "size": 2952, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/Tri.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-01-07T20:50:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-29T18:22:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/Tri.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/Tri.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 32.8, "max_line_length": 107, "alphanum_fraction": 0.6382113821, "num_tokens": 990, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741042, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7240008226660435}}
{"text": "\\documentclass[10pt]{article}\n\\usepackage{mycommands}\n\\usepackage{graphicx,wrapfig,listings,fancyhdr, bibentry}\n\\usepackage[all,dvips,arc,curve,color,frame]{xy}\n\\pagestyle{fancy}\n% \\usepackage[top=1.1in, bottom=1.0in, left=1.5in, right=1.5in]{geometry}\n\\doublespacing\n\\fancyhead[LO,LE]{T. Hopper}\n\\fancyhead[CO,CE]{Support Vector Machines}\n\\fancyfoot[CO,CE]{}\n\\fancyhead[RO, LE] {\\thepage}\n\n\n\\renewcommand{\\proofname}{Solution}\n \\renewcommand{\\labelenumi}{(\\alph{enumi})}\n\\lstset{language=Mathematica}\n\n\n\\begin{document}\n % \\unfinished\n\n% \\noindent OR 706 \\hfill Support Vector Machines \\hfill Tim Hopper\n\nSupport Vector Machines (SVMs) are statistical machine learning algorithms used, among other applications, to as a binary classifier. Classification algorithms such as the SVM, logistic regression, classification trees, linear discriminate analysis, and neural networks, ``learns'' to distinguish between classes of points in $\\R^{n}$ given historic training data.\n\n\\subsection{Maximal Margin Separating Hyperplane} % (fold)\n\\label{ssub:maximal_margin_separating_hyperplane}\n\n% subsubsection maximal_margin_separating_hyperplane (end)\nFor motivation, consider the two classes of points in $\\R^{2}$ in Figure \\ref{fig:sep_plot_2}. Note that there are infinitely many lines that could be drawn to separate the red from the green points. Any such line can be described by the equation\n\\begin{equation}\n\tf(x)=\\beta^{T} x+\\beta_{0}=0\n\\end{equation}\nfor some $\\beta\\in \\R^{2}$, $\\beta_{0}\\in \\R$, and $x\\in \\R^{2}$. Simple geometric arguments show that for the green points $x$, $f(x)<0$; likewise, for any red point $f(x)>0$.\n\n\\begin{figure}[htb]\n\t\t\t\t\\begin{center}\n\t\t\t\t\\includegraphics[width=300px]{Project/sep_plot_2.pdf}\n\t\t\t\t\\caption{Linearly separable data}\n\t\t\t\t\t\\label{fig:sep_plot_2}\n\t\t\t\t\\end{center}\n\t\t\t\t\\end{figure}\n\n\nMoreover, for any two points $x_{1}$ and $x_{2}$ lying on the line $L$ described by $f(x)=0$,\n \\[\n \t\\beta^{T}(x_{1}-x_{2})=-\\beta_{0}+\\beta_{0}=0,\n \\]\nand thus $\\beta^{*}=\\beta/\\norm{\\beta}$ is unit normal vector to $L$. The signed, normal distance from any point $x\\in \\R^{2}$ to $L$ is $\\frac{1}{\\norm{\\beta}}(\\beta^{T}x+\\beta_{0})$.\n\nSuppose our feature set of $N$ points is given by $(x_{i},y_{i})$ where the class of $x_{i}\\in\\R^{2}$ is given by $y_{i}$ such that $y_{i}=1$ if $x_{i}$  is red and $y_{i}=-1$ if $x_{i}$ is green. This way, for any $i$, $y_{i}(\\beta^{T}x_{i}+\\beta_{0})$ is the positive distance from $x_{i}$ to $L$. We define the margin of the separating line to be the distance from $L$ to the closest point in $\\set{x_{i}}$.\n\nThe maximal margin separating hyperplane by solving the program:\n\\begin{align*}\n\t\\operatorname*{maximize}_{\\beta,\\beta_{0}, \\norm{\\beta}=1}\\qquad & M \\\\\n\t\\text{subject to}\\qquad & y_{i} (\\beta^{T}x_{i}+\\beta_{0})\\geq M \\\\\n\t&i=1,...,N.\n\\end{align*}\nWe can integrate the $\\norm{\\beta}=1$ constraint into inequality constraints as\n\\[\n\t\\frac{1}{\\norm{\\beta}}y_{i} (\\beta^{T}x_{i}+\\beta_{0})\\geq M\n\\]\nor\n\\[\n\ty_{i} (\\beta^{T}x_{i}+\\beta_{0})\\geq M \\norm{\\beta}.\n\\]\nNote that for any $\\beta, \\beta_{0}$ satisfying the inequalities, any positive multiple also satisfies. Thus, we let $\\norm{\\beta}=1/M$ and give an equivalent program:\n\\begin{align}\n\t\\label{eq:sephypplan}\\operatorname*{maximize}_{\\beta,\\beta_{0}}\\qquad & \\frac{1}{2}\\norm{\\beta}^{2} \\\\\n\t\\text{subject to}\\qquad & y_{i} (\\beta^{T}x_{i}+\\beta_{0})\\geq 1 \\nonumber\\\\\n\t&i=1,...,N.\\nonumber\n\\end{align}\n\nObserve that the objective function in \\eqref{eq:sephypplan} is quadratic and the inequality constraints are nonlinear; thus, the program is convex and can be easily solved. The separating hyperplane program for arbitrary dimensional data can be naively solved in Mathematica:\n\n\\begin{lstlisting}\nSeparatingHyperplane[x_List, y_List] :=\n Module[\n  {conditions, vars, b, w, ans,\n   dim = Length[x[[1]]] (* Dimension of training data *),\n   n = Length[x](* Size of training data *)},\n  vars = Table[w[i], {i, 1, dim}];\n  conditions = Join[\n    {Norm[vars]^2} (* Cost function *),\n    Table[y[[i]] (vars.x[[i]] + b) >= 1, {i, 1, n}]\n    ];\n  ans = Minimize[conditions, Join[vars, {b}]];\n  ans = #[[2]] & /@ ans[[2]];\n  {ans[[1;;-2]], ans[[-1]]}\n  ]\n\\end{lstlisting}\n\nThe function \\textbf{SeparatingHyperplane} returns $\\set{\\beta_{0}, \\beta}$. The problem is more effectively solved with its Lagrangian dual, but we leave that development for the non-separable case below.\n\n\\subsection{Non-Separable Data} % (fold)\n\\label{sub:non_separable_data}\n\nAny hyperplane of parameters $\\beta$ ($\\norm{\\beta}=1$) and $\\beta_{0}$ given by\n\\[\n\t\\set{x \\;|\\; f(x)={\\beta^{T}x+\\beta_{0}}=0}\n\\]\ninduces a binary classification rule given by\n\\[\n\tG(x)=\\operatorname{sign}\\bra{\\beta^{T}x+\\beta}.\n\\]\n\nWe now consider a set $\\set{\\parens{x_{i},y_{i}}}$ of $N$ points where $x_{i}\\in R^{n}$ where each $x_{i}$ is of class $y_{i}\\in\\set{-1,1}$. Unlike our previous example, this data may not be separable by a hyperplane. Nevertheless, we want to find a hyperplane that, in some sense, optimally classifies the data. The program given above cannot handle non-separable data, because misclassifications cause it to be unbounded.\n\nTo construct a new program, we permit misclassifications by introducing positive slack variables $\\xi=(\\xi_{1},\\xi_{2},\\ldots,\\xi_{N})$ and change our constraint to\n\\[\n\ty_{i}(\\beta^{T}x_{i}+\\beta_{0})\\geq M(1-\\xi_{i}).\n\\]\n\nSince we want to minimize the number of misclassifications, we penalize the cost function for misclassified test points. Our resulting program is\n\\begin{align*}\n\t\\operatorname*{minimize}_{\\beta,\\beta_{0}}\\qquad &\n\t \t\\frac{1}{2}\\norm{\\beta}^{2} +C\\sum_{i=1}^{N}\\xi_{i}\\\\\n\t\\text{subject to}\\qquad & \ty_{i}(\\beta^{T}x_{i}+\\beta_{0})\\geq 1-\\xi_{i} \\\\\n\t&\\xi_{i}\\geq 0\\\\\n\t&i=1,...,N\n\\end{align*}\nfor some penalizing constant $C$. This is again a convex problem.\n\n\\subsubsection{Dual Formulation} % (fold)\n\\label{ssub:dual_formulation}\n\nWe introduce Lagrange multipliers $\\alpha_{i}, \\mu_{1}$ (for $i=1,\\ldots,N$) to give the Lagrangian\n\\[\n\t\\phi=\n\t\t\\frac{1}{2}\\norm{\\beta^{2}}\n\t\t+C\\sum_{i=1}^{N}\\xi_{i}\n\t\t-\\sum_{i=1}^{N}\\alpha_{i}\n\t\t\t\\bra{\ty_{i}(\\beta^{T}x_{i}+\\beta_{0})-(1-\\xi_{i})}\n\t\t-\\sum_{i=1}^{N}\\mu_{i}\\xi_{i}.\n\\]\nWe compute the Lagrange dual by setting the gradient with respect to the primal variables equal to zero:\n\\begin{align}\n\t\\beta&=\\sum_{i=1}^{N}\\alpha_{i}y_{i}x_{i} \\label{eq:dual_con_3}\\\\\n\t0&=\\sum_{i=1}^{N}a_{i}y_{i} \\label{eq:dual_con_1}\\\\\n\t\\alpha_{i}&=C-\\mu_{i}, \\;\\forall\\, i.\\label{eq:dual_con_2}\n\\end{align}\n\n\nSubstituting this into $\\phi$, we obtain the Lagrangian dual\n\\[\n\t\\phi(\\alpha,\\mu)=\\sum_{i=1}^{N}\\alpha_{i}-\\frac{1}{2}\\sum_{i=1}^{N}\\sum_{j=1}^{N}\\alpha_{i}\\alpha_{j}y_{i}y_{j}x_{i}^{T}x_{j}.\n\t\\]\nEquations \\eqref{eq:dual_con_1} and \\eqref{eq:dual_con_2} give constraints for minimizing the dual function. Since $\\mu_{i}\\geq$, we minimize the dual subject to\n\\eqref{eq:dual_con_1} and $0\\leq a_{i}\\leq C$. Because the primal problem is convex, the dual optimal value is also primal optimal.\n\nAt the global optimal solution, the KKT conditions guarantee the gradient of the Lagrangian being zero (equations \\eqref{eq:dual_con_3}-\\eqref{eq:dual_con_2}). Also, primal feasibility and complementary slackness:\n\\begin{align}\n\ty_{i}(x_{i}^{T}\\beta+\\beta_{0})+(1-\\xi_{i})&\\geq 0\\\\\n\t\\alpha_{i}\\bra{y_{i}(x_{i})^{T}\\beta+\\beta_{0}-(1-\\xi_{i})}&=0\\label{eq:comp_slack_1}\\\\\n\t\\mu_{i}\\xi_{i}&=0,\n\\end{align}\nfor $i = 1,\\ldots, N$.\n\nNote that the dual problem only requires the training data in the form of an inner product. This inner product can be replaced by generalized (Mercer) kernel functions which transform the data into other spaces without significant computational difficulty. The dual formulation even gives a closed formed solution for transforming the data into certain infinite dimensional spaces. Further discussion of kernel methods is outside the scope of this project.\n\nGiven a optimal solution to the dual problem $\\set{\\hat{\\alpha}_{i},\\hat{\\xi}_{i}}$, the primal solution is\n\\[\n\t\\hat{\\beta}=\\sum_{i=1}^{N}\\hat{\\alpha}_{i}y_{i}x_{i},\n\\]\nand $\\beta_{0}$ is given by \\eqref{eq:comp_slack_1} for any $i$ such that $\\alpha_{i}= 0$.\n% subsubsection dual_formulation (end)\n% subsection non_separable_data (end)\n\n\\subsection{Sequential Minimal Optimization Algorithm} % (fold)\n\\label{sec:smo_algorithm}\nIn 1998 John Platt of Microsoft Research published a paper  \\cite{platt1998sequential} describing his Sequential Minimal Optimization Algorithm for solving the dual problem. The SMO algorithm is a variation on the more general stochastic gradient descent algorithm and is very fast for solving the SVM.\n\nBecause of the linear dependence given by \\eqref{eq:dual_con_1}, the parameters $\\alpha_{i}$ cannot be optimized independently as in stochastic gradient descent. Platt recognized that the linear dependence requires optimization of two parameters $\\alpha_{i}$ and $\\alpha_{j}$ together.\n\nI have included a \\textbf{Mathematica} implementation of Andrew Ng's Simplified SMO algorithm described in \\cite{ng_smo}. The simplified SMO does not guarantee under every possible training set. However, except in pathological cases, it provides a satisfactory SVM.\n\nIn Figure \\ref{fig:svm_plot_2d}, I used my algorithm to find the separating hyperplane for 25 red points sampled from $N((1,1),(1.5,1.5))$ and 25 green points from $N((-1,-1),(1.5,1.5))$. The data has significant overlap and is thus not linearly separable; 45 points are correctly classified, and 5 are misclassified.\n\n\\begin{figure}[htb]\n\t\t\t\t\\begin{center}\n\t\t\t\t\\includegraphics[width=300px]{Project/svm_plot_2d.pdf}\n\t\t\t\t\\caption{Non-separable data with linear separator}\n\t\t\t\t\t\\label{fig:svm_plot_2d}\n\t\t\t\t\\end{center}\n\t\t\t\t\\end{figure}\n\nMy code generalizes to data in arbitrary dimension and arbitrary Mercer kernels. In figure \\ref{fig:svm_plot_ker}, I used the polynomial kernel $K(x,x')=(1+\\ang{x,x'})^{2}$ on the same data as \\ref{fig:svm_plot_2d}; 47 points are correctly classified, and 3 are misclassified. Of course, kernel methods are prone to overfitting.\n\n\n\\begin{figure}[htb]\n\t\t\t\t\\begin{center}\n\t\t\t\t\\includegraphics[width=300px]{Project/svm_plot_ker.pdf}\n\t\t\t\t\\caption{Non-separable data with quadratic kernel}\n\t\t\t\t\t\\label{fig:svm_plot_ker}\n\t\t\t\t\\end{center}\n\t\t\t\t\\end{figure}\n% section smo_algorithm (end)\n\n\n\\nocite{burges,platt1998sequential,ng,ng_smo}\n\\bibliographystyle{plain}\n\\bibliography{OR706Project}\n\n\n\\end{document}\n\n", "meta": {"hexsha": "32727083ee19e99b3040a64da5016adf1ca13777", "size": 10384, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "OR706 Support Vector Machines.tex", "max_stars_repo_name": "tdhopper/smo-svm", "max_stars_repo_head_hexsha": "e1ff56048357d76bf521e5065bdce00ee60fd1de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-11-22T04:33:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-13T09:50:33.000Z", "max_issues_repo_path": "OR706 Support Vector Machines.tex", "max_issues_repo_name": "afcarl/smo-svm", "max_issues_repo_head_hexsha": "e1ff56048357d76bf521e5065bdce00ee60fd1de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "OR706 Support Vector Machines.tex", "max_forks_repo_name": "afcarl/smo-svm", "max_forks_repo_head_hexsha": "e1ff56048357d76bf521e5065bdce00ee60fd1de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-11-22T02:33:24.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-08T21:53:07.000Z", "avg_line_length": 50.1642512077, "max_line_length": 456, "alphanum_fraction": 0.7104198767, "num_tokens": 3321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245617, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7240008034698286}}
{"text": "% corrected VD 85\n\n\\subsubsection{Long short-term memory}~\\\\\n\n\nAn LSTM unit is composed of a memory cell, an input gate, an output gate and a\nforget gate. The cell stores information over a long period and the three gates\ncontrol the flow of information through the cell. RNNs using LSTM units deal\nwith the vanishing gradient problem because these units allow gradients to flow\nunchanged.\\cite{doi:10.1162/neco.1997.9.8.1735}\\\\\n\nThe standard formulation of a single LSTM cell can be given by the following\nequations:\n\n\\begin{align}\n  f_t &= \\sigma(W_f h_{t-1}+V_f x_t+b_f)\\\\\n  i_t &= \\sigma(W_i h_{t-1}+V_i x_t+b_i)\\\\\n  C_t^{'} &= \\tanh(W_C h_{t-1}+V_C x_t+b_C)\\\\\n  C_t &= f_t C_{t-1}+i_t C_t^{'}\\\\\n  o_t &= \\sigma(W_o h_{t-1}+V_o x_t+b_o)\\\\\n  h_t &= o_t \\tanh(C_t)\n\\end{align}\n\nwhere $\\sigma$ is the sigmoid function, $\\tanh$ is the hyperbolic tangent\nfunction, $f,i,C^{'},C,o$ are the forget gate, input gate, new memory cell\ncontent, and memory cell content, output gate respectively. See representation\nof an LSTM cell in Figure~\\ref{memorycell}.\n\n\\input{sections/scientific/fr2/lstmcell.tex}\n", "meta": {"hexsha": "907537500c13a26566637f3972d1174898eee7d1", "size": 1098, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/scientific/fr2/lstm.tex", "max_stars_repo_name": "Lemswasabi/bsps3-report", "max_stars_repo_head_hexsha": "ca3f7bee2d4740c5c7ad9f586766ab04a0e5f58b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sections/scientific/fr2/lstm.tex", "max_issues_repo_name": "Lemswasabi/bsps3-report", "max_issues_repo_head_hexsha": "ca3f7bee2d4740c5c7ad9f586766ab04a0e5f58b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/scientific/fr2/lstm.tex", "max_forks_repo_name": "Lemswasabi/bsps3-report", "max_forks_repo_head_hexsha": "ca3f7bee2d4740c5c7ad9f586766ab04a0e5f58b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6, "max_line_length": 79, "alphanum_fraction": 0.723132969, "num_tokens": 357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7239931290824491}}
{"text": "\\section{Normal Mapping}\nNormal Mapping provides an enormous boost in detail for a relatively low cost. To implement\nNormal Mapping, tangents and bitangents of each vertex are required. Tangents are computed in CPU\nwhen a model is loaded, saving important time. Bitangents are computed in shader code, as a cross\nproduct between re-orthogonalized Tangents and Normals.\n\nNormals and Tangents for each vertex are calculated when loading the model and are first processed\non the Geometry pass where the TBN\\footnote{TBN is a matrix that contains the Tangent, Bitangent\nand Normal vectors} matrix is calculated and then written to a 2D texture, for light pass to use.\n\n\\noindent Normals used in light pass are calculated with the following equations:\n\n$$norm(x)=\\frac{2*x - 1}{\\vert 2*x - 1 \\vert}$$\n$$N(n, t)=norm(t*norm(2*n - 1))$$\n\n\\noindent Where n is the normal vector and t, the TBN matrix.\n\nOn larger meshes the three TBN vectors could end up non-perpendiuclar to each other resulting in\na non orthogonal TBN matrix. That throws the normal mapping quality a bit off. To address that\nissue a mathematical trick called \\textit{Gram-Schmidt process} is used, to re-orthogonalize\nthe TBN matrix. First, the tangent needs to be re-orthogonalized with respect to N and then\nthe perpenducular bitangent vector can by calculated by the cross product of tangent and normal\nvectors.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.4,clip=true]{./image/nm1.png}\n    \\caption{Normal Mapping on a metallic wall}\n\\end{figure}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.4,clip=true]{./image/nm2.png}\n    \\caption{Normal Mapping on a house model}\n\\end{figure}\n\n\\newpage\n", "meta": {"hexsha": "846853beef0443cb32a4fa4f9b1260ecbee429cf", "size": 1692, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/normalmaps.tex", "max_stars_repo_name": "ScaryBoxStudios/TheRoom", "max_stars_repo_head_hexsha": "880c8730cb5c271def472df76fa655df1970b94b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-11-12T11:40:45.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-12T11:40:45.000Z", "max_issues_repo_path": "doc/normalmaps.tex", "max_issues_repo_name": "ScaryBoxStudios/TheRoom", "max_issues_repo_head_hexsha": "880c8730cb5c271def472df76fa655df1970b94b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/normalmaps.tex", "max_forks_repo_name": "ScaryBoxStudios/TheRoom", "max_forks_repo_head_hexsha": "880c8730cb5c271def472df76fa655df1970b94b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.5263157895, "max_line_length": 98, "alphanum_fraction": 0.7712765957, "num_tokens": 442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.7239931151854672}}
{"text": "\\documentclass[../report/main.tex]{subfiles}\n \n\\begin{document}\n\n% The asterix after \\subsection disables section numbering\n\\subsection*{Problem 1 Part D}\nFormulate a generalized linear programming model for the transshipment problem. Give the objective function and constraints as mathematical formulas.\n\n\\subsection*{Note}\nI can't help but feel that I've already done this in Parts A through C but I'll repeat (and try to expand) here in a more general form.\n\n\\subsection*{Objective Function}\nWhereas...\\\\\\\\\\indent$n$ = number of plants $\\geq 1$\\\\\\indent$q$ = number of warehouses $\\geq 1$\\\\\\indent$m$ = number of retailers $\\geq 1$\\\\\\indent$np_{ij}$ = number of refrigerators shipped from plant $p_i$ to warehouse $w_j$ $\\geq 0$\\\\\\indent$cp_{ij}$ = cost of moving a refrigerator between plant $p_i$ and warehouse $w_j$ $> 0$\\\\\\indent$nw_{jk}$ = number of refrigerators shipped from warehouse $w_j$ to retailer $r_k$ $\\geq 0$\\\\\\indent$cw_{jk}$ = cost of moving a refrigerator between warehouse $w_j$ and retailer $r_k$ $> 0$\\\\\\\\The \\textbf{\\underline{objective function}} is to...\n\\\\\\\\\\indent minimize $cost = \\mathop{\\sum_{i=1}^{n}\\sum_{j=1}^{q}}np_{ij}*cp_{ij} +  \\mathop{\\sum_{j=1}^{q}\\sum_{k=1}^{m}}nw_{jk}*cw_{jk}$\n\n\\subsection*{Constraints}\nThe objective function (designed to minimize $cost$) is \\textbf{\\underline{subject to}} the following contraints...\\\\\\\\\\indent $0 \\leq $ capacity of each plant $= s_i \\leq$ some maximum\\\\\\indent $0 \\leq $ throughput capability of each warehouse $ = q_j \\leq$ some maximum\\\\\\indent $0 \\leq $ demand of each retailer  $ = m_k \\leq$ some maximum\\\\\\\\and also...\\\\\\\\\\indent $\\mathop{\\sum_{i=1}^{n}}np_{ij} = $ capacity of a given plant $p_i$\\\\\\\\\\indent $\\mathop{\\sum_{i=1}^{n}}np_{ij} = \\mathop{\\sum_{k=1}^{m}}nw_{jk}= $ throughput capability for a given warehouse $w_j$\\\\\\\\\\indent $\\mathop{\\sum_{k=1}^{m}}nw_{jk} = $ demand of a given retailer $r_k$\n\\end{document}", "meta": {"hexsha": "0c82c32819cba9e4ef6a831bd6b1b11db369ff1a", "size": 1909, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem_one/partD.tex", "max_stars_repo_name": "OSU-CS-325/Project_Three_LP", "max_stars_repo_head_hexsha": "88301202f62a44a1b17a98bbc33c0efdb4a9d458", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "problem_one/partD.tex", "max_issues_repo_name": "OSU-CS-325/Project_Three_LP", "max_issues_repo_head_hexsha": "88301202f62a44a1b17a98bbc33c0efdb4a9d458", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "problem_one/partD.tex", "max_forks_repo_name": "OSU-CS-325/Project_Three_LP", "max_forks_repo_head_hexsha": "88301202f62a44a1b17a98bbc33c0efdb4a9d458", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-24T18:35:38.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-24T18:35:38.000Z", "avg_line_length": 106.0555555556, "max_line_length": 645, "alphanum_fraction": 0.7014143531, "num_tokens": 584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681158979307, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.723866305398431}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS630: Database Management Systems\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 1}\n\nConsider a database schema with three relations:\n\n\\begin{terminal}\nStudents (@*\\underline{sid}*@:integer, sname:string, age:integer)\nEnrolled (@*\\underline{sid}*@:integer, @*\\underline{cid}*@:integer, grade:integer)\nCourses  (@*\\underline{cid}*@:integer, cname:string, credits:integer)\n\\end{terminal}\n\nThe keys are underlined in each relation.\nStudents are identified uniquely by \\texttt{sid}, and courses by \\texttt{cid}.\nStudents enroll to take courses, and for each course they obtain a grade which is an integer.\n\\texttt{sname} is the student name (string), \\texttt{age} represents the student age and is an integer.\n\\texttt{cname} is the course name (string), and \\texttt{credits} is the number of credits for a particular course (integer).\n\nWrite relational algebra expressions for the following queries:\n\n\\begin{enumerate}\n  \\item Find the names of students who got grade 10 in some course.\n\n  \\textbf{Solution:}\n  $$\\displaystyle \\pi_{sname}((\\sigma_{grade=10}Enrolled)\\Join Students)$$\n  \\item Find the ages of students who take some course with 3 credits.\n\n  \\textbf{Solution:}\n  $$\\displaystyle \\pi_{age} (\\pi_{sid} (\\pi_{cid} (\\sigma_{credits=3}Courses) \\Join Enrolled) \\Join Students)$$\n  \\item Find the names of students who take a course named \"Calculus\".\n\n  \\textbf{Solution:}\n  $$\\displaystyle \\pi_{sname} (\\pi_{sid} (\\pi_{cid} (\\sigma_{cname=\"Calculus\"}Courses) \\Join Enrolled)\\Join Students)$$\n  \\item Find the names of students who obtained grade at least 8 in some course that has less than 4 credits.\n\n  \\textbf{Solution:}\n  $$\\displaystyle \\pi_{sname} (\\pi_{sid} (\\sigma_{grade>0}(\\pi_{cid} (\\sigma_{credits<4}Courses) \\Join Enrolled)) \\Join Students) $$\n\n  \\item Find the names of students who obtained only grades of 10 (implies that they took at least one course).\n\n  \\textbf{Solution:}\n  \\begin{enumerate}\n  \\item S1 is constructed to represent IDs of students who obtained grades of 10 at lease in one course; i.e. includes IDs of students who might have obtained a different grade in different course(s).\n  $$\\displaystyle \\rho(S1, \\pi_{sid}( \\sigma_{grade=10}Enrolled)) $$\n  \\item S2 is constructed to represent IDs of all students who obtained a grade different than 10 at least in one course.\n  $$\\displaystyle \\rho(S2, \\pi_{sid}(\\sigma_{grade<>10}Enrolled)) $$\n  \\item Desired list is obtained by looking up names of students whose ID is in S1 and not in S2.\n  $$\\displaystyle \\pi_{sname}((S1-S2) \\Join Students) $$\n  \\end{enumerate}\n\n  \\item Find the names of  students who took a course with three credits or who obtained grade 10 in some course.\n\n  \\textbf{Solution:}\n  \\begin{enumerate}\n  \\item S1 is constructed to represent IDs of students who took a course with three credits.\n  $$\\displaystyle \\rho(S1, \\pi_{sid} (\\pi_{cid} (\\sigma_{credits=3}Courses) ) \\Join Enrolled)$$\n  \\item S2 is constructed to represent IDs of students who obtained grade 10 at least in one course.\n  $$\\displaystyle \\rho(S2, \\pi_{sid}(\\sigma_{grade=10}Enrolled) ) $$\n  \\item Desired list is obtained by merging S1 and S2 lists and looking up names of students corresponding to IDs of merged list.\n  $$\\displaystyle \\pi_{sname}((S1 \\cup S2) \\Join Students) $$\n  \\end{enumerate}\n\n  \\item Find the ages of students who attend \"Calculus\" but never took any 4-credit course (assume there is a course \"Calculus\" with 3 credits).\n\n  \\textbf{Solution:}\n  \\begin{enumerate}\n  \\item S1 is constructed to represent IDs of students who attend \"Calculus\".\n  $$ \\displaystyle \\rho(S1,   \\pi_{sid}( \\pi_{cid}( \\sigma_{cname=\"Calculus\"}Courses) \\Join Enrolled) ) $$\n  \\item S2 is constructed to represent IDs of students who took at lease one 4-credit course.\n  $$ \\displaystyle \\rho(S2, \\pi_{sid} (\\pi_{cid}( \\sigma_{credits=4}Courses) \\Join Enrolled) ) $$\n  \\item Desired list is obtained by finding names of students whose ID is in S1 and not in S2.\n  $$ \\displaystyle \\pi_{sname}((S1-S2)\\Join Students) $$\n  \\end{enumerate}\n\n  \\item Find the names of students who have the lowest age.\n\n  \\textbf{Solution:}\n  $$\\displaystyle \\rho(S1(1\\rightarrow sid1, 2\\rightarrow sname1, 3\\rightarrow age1),Students)$$\n  $$\\rho(S2(1\\rightarrow sid2, 2\\rightarrow sname2, 3\\rightarrow age2),Students)$$\n  $$\\rho(Elders(1\\rightarrow sid),\\pi_{sid1}(S1 \\Join_{(age1>age2)} S2)) $$\n  Desired list includes names of students whose ID is not among Elders.\n  $$ \\pi_{sname}((\\pi_{sid}(Students)-Elders) \\Join Students) $$\n\n  \\item Find the names of students who are enrolled in a single course.\n\n  \\textbf{Solution:}\n  \\begin{enumerate}\n  \\item{S1 is constructed to represent IDs of students who are not enrolled in any courses.}\n  $$\\displaystyle \\rho(S1, \\pi_{sid}Students-\\pi_{sid}Enrolled)$$\n  \\item{S2 is constructed to represent IDs of students who are enrolled in more than one course.}\n  $$\\displaystyle \\rho(E1(1\\rightarrow sid1, 2\\rightarrow cid1, 3\\rightarrow grade1),Enrolled)$$\n  $$\\rho(E2(1\\rightarrow sid2, 2\\rightarrow cid2, 3\\rightarrow grade2),Enrolled)$$\n  $$\\rho(S2,\\pi_{sid}(E1 \\Join_{(sid1=sid2\\wedge cid1\\neq cid2)} E2) ) $$\n  \\item{Students enrolled in a single course are those whose ID is neither in S1 nor in S2.}\n  $$\\displaystyle \\pi_{sname}( ((\\pi_{sid}Students-S1)-S2)\\Join Students)$$\n  \\end{enumerate}\n\n  \\item Find the grades of students who are enrolled in course(s) with the highest number of credits.\n\n  \\textbf{Solution:}\n  \\begin{enumerate}\n  \\item C4 is constructed to give list of course IDs with highest number of credits.\n  $$\\displaystyle \\rho(C1(1\\rightarrow cid1, 2\\rightarrow cname1, 3\\rightarrow credits1),Courses)$$\n  $$\\rho(C2(1\\rightarrow cid2, 2\\rightarrow cname2, 3\\rightarrow credits2),Courses)$$\n  $$\\rho(C3,\\pi_{cid1}(C1 \\Join_{(credits1<credits2)} C2)) $$\n  $$\\rho(C4(1 \\rightarrow cid),\\pi_{cid1}Courses-C3)$$\n  \\item Desired list is obtained using C4 table.\n  $$ \\pi_{grade}(C4 \\Join Enrolled) $$\n  \\end{enumerate}\n\n\\end{enumerate}\n", "meta": {"hexsha": "d23046411bc7a0c5d298acf44b1e2fbd3afcffd5", "size": 6256, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs630-2014f/src/tex/hw01/hw01q01.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs630-2014f/src/tex/hw01/hw01q01.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs630-2014f/src/tex/hw01/hw01q01.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 53.4700854701, "max_line_length": 200, "alphanum_fraction": 0.7092391304, "num_tokens": 1840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7238663023300772}}
{"text": "\\chapter{Description of the complete mathematical model}\n\\label{ap:model}\n\\textit{In this appendix we will analyse formally the proposed model, presented in Chapter \\ref{ch::model}. Functions derivatives are trivial, so they will not be indicated except where otherwise indicated.}\n\n%--------------------------------------------%\n%--------------------------------------------%\n\\section*{Error propagation along the y axis}\nAccordingly with the geometric model for \\acs{SOL} systems, we can write:\n  \\begin{equation}\n    \\label{app:eq:triangulation}\n\ty(\\alpha) = y_f + z_f \\tan(\\phi + \\alpha)\n  \\end{equation}\nwhere $y(\\alpha)$ is the point $y$ coordinate; $(x_f, y_f, z_f)$ are the principal point projection coordinates in the laser plane (both in the world reference system); $\\phi$ is the triangulation angle and $\\alpha$ is the angle offset along $y$ axis.\nUsing the error propagation model for general non-trivial functions, the error is evaluated as follows:\n  \\begin{equation*}\n    \\sigma_{y_\\alpha} = \\sqrt{\n      \\left( \\frac{\\partial y}{\\partial y_f} \\right)^2 \\sigma_{y_f}^2\n      + \\left( \\frac{\\partial y}{\\partial z_f} \\right)^2 \\sigma_{z_f}^2\n      + \\left( \\frac{\\partial y}{\\partial \\phi} \\right)^2 \\sigma_\\phi^2\n      + \\left( \\frac{\\partial y}{\\partial \\alpha} \\right)^2 \\sigma_\\alpha^2\n    }\n  \\end{equation*} \\\\\n\nIf laser plane doesn't lie on the target section plane, a common practise is applied the so called ``\\textit{radial compensation}'' to \\ref{app:eq:triangulation} output:\n  \\begin{equation*}\n    y_w = y(\\alpha) \\cdot cos(\\rho)\n  \\end{equation*}\nwhere $\\rho$ is the angle between laser plane and object plane of symmetry.\nIn this case the final error is:\n  \\begin{equation}\n    \\sigma_{y_w} = \\sqrt{\n      \\left( \\frac{\\partial y_w}{\\partial y(\\alpha)} \\right)^2 \\sigma_{y_\\alpha}^2\n      + \\left( \\frac{\\partial y_w}{\\partial \\rho} \\right)^2 \\sigma_\\rho^2\n    }\n    \\label{app:eq:sigma-yw}\n  \\end{equation} \\\\\n\nA variation of $y_w$ in the world corresponds to a variation of $y_{s_i}$ in the image plane with an angle $\\alpha_i$ according to the relation:\n  \\begin{equation}\n    \\label{app:eq:triang_angle}\n  \t\\alpha_i = \\arctan\\left( \\frac{y_{s_i}}{f} \\right)\n  \\end{equation}\nwhere $y_{s_i}$ is the point coordinate in the tilted image plane, and $f$ is the focal length. The error propagation is computed as:\n  \\begin{equation}\n  \t\\sigma_{\\alpha_i} = \\sqrt{\n  \t  \\left( \\frac{\\partial \\alpha_i}{\\partial y_{s_i}} \\right)^2 \\sigma_{y_{s_i}}^2\n  \t  + \\left( \\frac{\\partial \\alpha_i}{\\partial f} \\right)^2 \\sigma_f^2\n  \t}\n    \\label{app:eq:sigma-alpha}\n  \\end{equation} \\\\\n\nAs it is known, Scheimpflug principle causes tilting of the image plane. Accordingly with \\cite{SchCameraCalib}, the relation between tilted coordinates and parallel coordinates to the sensor is given by:\n  \\begin{equation}\n    \\label{app:eq:sch_y}\n    y_{s_i} = \\lambda_1 \\frac{y_{p_i}}{\\cos\\upsilon} =\n    \\frac{f}{f - x_{p_i}\\tan\\chi - y_{p_i}\\frac{\\tan\\upsilon}{\\cos\\chi}} \\frac{y_{p_i}}{ \\cos\\upsilon}\n  \\end{equation}\nwhere $\\upsilon$ is the tilt angle with respect to $y$ axis, and $\\chi$ is the swing angle with respect to $x$ axis, either in the image plane coordinates system, parallel to the camera sensor. The constant $\\lambda_1$ is function of $f$, $\\upsilon$ and $\\chi$, and of point coordinates in the last image plane $\\left( x_p, y_p \\right)$. The error propagation follows:\n  \\begin{equation*}\n    \\sigma_{y_{s_i}} = \\sqrt{\n      \\left( \\frac{\\partial y_{s_i}}{\\partial y_{p_i}} \\right)^2 \\sigma_{y_{p_i}}^2 +\n      \\left( \\frac{\\partial y_{s_i}}{\\partial x_{p_i}} \\right)^2 \\sigma_{x_{p_i}}^2 +\n      \\left( \\frac{\\partial y_{s_i}}{\\partial \\upsilon} \\right)^2 \\sigma_\\upsilon^2 +\n      \\left( \\frac{\\partial y_{s_i}}{\\partial \\chi} \\right)^2 \\sigma_\\chi^2 +\n      \\left( \\frac{\\partial y_{s_i}}{\\partial f} \\right)^2 \\sigma_f^2\n    }\n  \\end{equation*}\nIn this case we indicate the partial derivatives for completeness: \\\\\n\\begin{equation*}\n  \\begin{array}{rl}\n    \\frac{\n      \\partial y_s}{\\partial y_p} = &\n          \\frac{f\\cdot\\sec\\upsilon}{f -y_p\\cdot\\sec\\chi\\tan\\upsilon - x_p\\cdot\\tan\\chi} +\n          \\frac{f\\cdot y_p\\cdot \\sec\\chi\\tan\\upsilon\\sec\\upsilon}{\\left( f -y_p\\cdot\\sec\\chi\\tan\\upsilon - x_p\\cdot\\tan\\chi \\right)^2} \\\\~\\\\\n      \\frac{\\partial y_s}{\\partial x_p} = &\n          \\frac{f\\cdot y_p\\cdot \\tan\\chi\\sec\\upsilon}{\\left( f -y_p\\cdot\\sec\\chi\\tan\\upsilon - x_p\\cdot\\tan\\chi \\right)^2} \\\\~\\\\\n      \\frac{\\partial y_s}{\\partial \\chi} = &\n          \\frac{f\\cdot y_p\\cdot \\sec\\upsilon \\left( -y_p\\cdot \\tan\\chi\\sec\\chi\\tan\\upsilon - x_p\\cdot\\sec^2\\chi \\right)}{\\left( f -y_p\\cdot\\sec\\chi\\tan\\upsilon - x_p\\cdot\\tan\\chi \\right)^2} \\\\~\\\\\n      \\frac{\\partial y_s}{\\partial \\upsilon} = &\n          \\frac{f\\cdot y_p^2\\cdot \\sec\\chi\\sec^3\\upsilon}{ \\left( f -y_p\\cdot\\sec\\chi\\tan\\upsilon - x_p\\cdot\\tan\\chi \\right)^2} +\n          \\frac{f\\cdot y_p\\cdot \\sec\\upsilon\\tan\\upsilon}{f -y_p\\cdot\\sec\\chi\\tan\\upsilon - x_p\\cdot\\tan\\chi} \\\\~\\\\\n      \\frac{\\partial y_s}{\\partial f} = &\n          \\frac{f\\cdot y_p\\cdot \\sec\\upsilon}{ \\left( f -y_p\\cdot\\sec\\chi\\tan\\upsilon - x_p\\cdot\\tan\\chi \\right)^2} +\n          \\frac{y_p\\cdot \\sec\\upsilon}{f -y_p\\cdot\\sec\\chi\\tan\\upsilon - x_p\\cdot\\tan\\chi}\n  \\end{array}\n\\end{equation*} \\\\\n\nDeveloping this model, we took into account only the first order lens radial distortion:\n  \\begin{equation}\n  \t\\label{app:eq:sensor_to_camera_distortion}\n    \\begin{matrix}\n      y_{p_i} = y_{p_i}^{d} \\left( 1 + k_1r^2 \\right) \\\\~\\\\\n      \\sigma_{y_{p_i}} = \\sqrt{\n        \\left( \\frac{\\partial y_{p_i}}{\\partial y_{p_i}^d} \\right)^2 \\sigma_{y_{p_i}^d}^2\n        + \\left( \\frac{\\partial y_{p_i}}{\\partial k_1} \\right)^2 \\sigma_{k_1}^2\n      }\n    \\end{matrix}\n  \\end{equation}\nWhere $y_{p_i}^d$ is the distorted coordinate in the sensor plane, $k_1$ is the lens radial distortion first order coefficient and $r$ is the lens radius, estimated in the worst case as $r = \\frac{image \\, size}{2}$. \\\\\n\nThe distorted coordinate in sensor plane is evaluate accordingly with:\n  \\begin{equation}\n      \\label{app:eq:sensor_to_camera_center}\n      y_{p_i}^d = d'_y (y_{c_i} - c_y)\n  \\end{equation}\nwhere $c_y$ is the $y$ coordinate of the center image, $d'_y$ is the normalized center to center distance between adjacent sensor elements, and $y_c$ is the point coordinate in pixel. Its error is computed as:\n  \\begin{equation*}\n    \\sigma_{y_{p_i}^d} = \\sqrt{\n      \\left( \\frac{\\partial y_{p_i}^d}{\\partial y_{c_i}} \\right)^2 \\sigma_{y_{c_i}}^2\n      + \\left( \\frac{\\partial y_{p_i}^d}{\\partial c_y} \\right)^2 \\sigma_{c_y}^2\n    }\n  \\end{equation*} \\\\\n\nAt the end of the chain, the sub-pixel approximation error is evaluated as follows:\n  \\begin{equation*}\n    \\sigma_{y_{c_i}} = |\\delta_i - \\hat{\\delta}_i|\n  \\end{equation*}\nwhere $\\delta_i$ is the real laser peak position inside the pixel, and $\\hat{\\delta}_i$ is the approximated peak position.\n\n%--------------------------------------------%\n%--------------------------------------------%\n\\section*{Error propagation along the x axis}\nThe analysis for error propagation along coordinate $x$ is similar to the previous one. For this reason, the parameters using the same notation won't be explained. \\\\\n\nThe point $x$ coordinate is evaluated accordingly with the geometric model:\n  \\begin{equation*}\n    x(\\alpha, \\beta) = \\frac{y_\\alpha - y_f}{\\sin(\\phi + \\alpha)}\\tan(\\beta)\n  \\end{equation*}\nwhere $\\beta$ is the triangulation angle with respect to the $x$ axis. As in the previous case, we have to balance the laser pitch rotation:\n  \\begin{equation*}\n    x_w = x(\\alpha, \\beta) \\cdot \\cos(\\gamma)\n  \\end{equation*}\nwhere $\\gamma$ is the laser pith angle. So the error is:\n  \\begin{equation}\n    \\sigma_{x_w} = \\sqrt{\n      \\left( \\frac{\\partial x_w}{\\partial y_\\alpha} \\right)^2 \\sigma_{y_\\alpha}^2 +\n      \\left( \\frac{\\partial x_w}{\\partial \\phi} \\right)^2 \\sigma_\\phi^2 +\n      \\left( \\frac{\\partial x_w}{\\partial \\alpha} \\right)^2 \\sigma_\\alpha^2 +\n      \\left( \\frac{\\partial x_w}{\\partial \\beta} \\right)^2 \\sigma_\\beta^2 +\n      \\left( \\frac{\\partial x_w}{\\partial \\gamma} \\right)^2 \\sigma_\\gamma^2\n    }\n    \\label{app:eq:sigma-xw}\n  \\end{equation}\nFor clarity, we provide the partial derivatives below:\n  \\begin{equation*}\n    \\begin{array}{rl}\n      \\frac{\\partial x_c}{\\partial y} = & \\tan\\beta\\sec\\gamma\\csc(\\phi + \\alpha) \\\\~\\\\\n      \\frac{\\partial x_c}{\\partial \\phi} = & -y\\cdot\\tan\\beta\\cot(\\phi + \\alpha)\\csc(\\phi + \\alpha) \\\\~\\\\\n      \\frac{\\partial x_c}{\\partial \\alpha} = & -y\\cdot\\tan\\beta\\sec\\gamma\\cot(\\phi + \\alpha)\\csc(\\phi + \\alpha) \\\\~\\\\\n      \\frac{\\partial x_c}{\\partial \\beta} = & y\\cdot\\sec^2\\beta\\sec\\gamma\\csc(\\phi + \\alpha) \\\\~\\\\\n      \\frac{\\partial x_c}{\\partial \\gamma} = & y\\cdot \\tan\\beta\\tan\\gamma\\sec\\gamma\\csc(\\phi + \\alpha)\n    \\end{array}\n  \\end{equation*} \\\\\n\nHow did in Equation \\ref{app:eq:triang_angle}, the triangulation angle is computed as:\n  \\begin{equation*}\n    \\begin{matrix}\n      \\beta_i = \\arctan\\left( \\frac{x_{s_i}}{f} \\right)\n      \\qquad \\qquad\n  \t  \\sigma_{\\beta_i} = \\sqrt{\n  \t      \\left( \\frac{\\partial \\beta_i}{\\partial y_{s_i}} \\right)^2 \\sigma_{y_{s_i}}^2\n  \t      + \\left( \\frac{\\partial \\beta_i}{\\partial f} \\right)^2 \\sigma_f^2\n  \t  }\n    \\end{matrix}\n  \\end{equation*} \\\\\n\nThe image plane swing caused by Scheimpflug principle, is given by:\n  \\begin{equation}\n    \\label{app:eq:sch_x}\n    \\begin{matrix}\n      x_{s_i} = \n        \\lambda_1\\left( \\frac{x_{p_i}}{\\cos\\chi} + y_{p_i}\\tan\\upsilon\\tan\\chi \\right) = \\\\\n        \\frac{f}{f - x_{p_i}\\tan\\chi - y_{p_i}\\frac{\\tan\\upsilon}{\\cos\\chi}} \\left( \\frac{x_{p_i}}{\\cos\\chi} + y_{p_i}\\tan\\upsilon\\tan\\chi \\right)\n    \\end{matrix}\n  \\end{equation}\nThe error is computed as above:\n  \\begin{equation*}\n    \\sigma_{x_{s_i}} = \\sqrt{\n      \\left( \\frac{\\partial x_{s_i}}{\\partial y_{p_i}} \\right)^2 \\sigma_{y_{p_i}}^2 +\n      \\left( \\frac{\\partial x_{s_i}}{\\partial x_{p_i}} \\right)^2 \\sigma_{x_{p_i}}^2 +\n      \\left( \\frac{\\partial x_{s_i}}{\\partial \\upsilon} \\right)^2 \\sigma_\\upsilon^2 +\n      \\left( \\frac{\\partial x_{s_i}}{\\partial \\chi} \\right)^2 \\sigma_\\chi^2 +\n      \\left( \\frac{\\partial x_{s_i}}{\\partial f} \\right)^2 \\sigma_f^2\n    }\n  \\end{equation*} \\\\\n\nHow in Equations \\ref{app:eq:sensor_to_camera_distortion} and \\ref{app:eq:sensor_to_camera_center}, the transformation from sensor coordinates to undistorted image plane coordinates, is computed as:\n\\begin{equation}\n  \\begin{matrix}\n    \\label{app:eq:camera_to_image_x}\n    x_{p_i} = x_{p_i}^d (1 + k_1r^2) \\qquad \\qquad\n    x_{p_i}^d = d_x'(x_{c_i} - c_x)\n  \\end{matrix}\n\\end{equation}\nthe errors of which are:\n  \\begin{equation*}\n    \\sigma_{x_{p_i}} = \\sqrt{\n        \\left( \\frac{\\partial x_{p_i}}{\\partial x_{p_i}^d} \\right)^2 \\sigma_{x_{p_i}^d}^2\n        + \\left( \\frac{\\partial x_{p_i}}{\\partial k_1} \\right)^2 \\sigma_{k_1}^2\n      }\n\t  \\qquad\n    \\sigma_{x_{p_i}^d} = \\sqrt{\n      \\left( \\frac{\\partial x_{p_i}^d}{\\partial x_{c_i}} \\right)^2 \\sigma_{x_{c_i}}^2\n      + \\left( \\frac{\\partial x_{p_i}^d}{\\partial c_x} \\right)^2 \\sigma_{c_x}^2\n    }\n  \\end{equation*} \\\\\n\nIn this case, we can't perform a sub-pixel approximation, so the laser power distribution along the pixel was modelled as an \\textit{uniform distribution} with standard deviation:\n  \\begin{equation*}\n    \\sigma_{x_{c_i}} = \\frac{1}{2\\sqrt{3}}\n  \\end{equation*} \\\\\n\nEquations \\ref{app:eq:sensor_to_camera_distortion}, \\ref{app:eq:sensor_to_camera_center} and \\ref{app:eq:camera_to_image_x} was used accordingly with \\cite{TsaiTvLenses}, while Equations \\ref{app:eq:sch_y} and \\ref{app:eq:sch_x} was used accordingly with \\cite{SchCameraCalib}.\n\n%--------------------------------------------%\n%--------------------------------------------%\n\\section*{Error propagation in diameter evaluation}\nAccordingly with the Erone's formula, the diameter of the circle circumscribed to a triangle (in our case, defined by three rolling points in the rolling circle) is evaluable with the equation:\n  \\begin{equation}\n    D = \\frac{2\\cdot a\\cdot b\\cdot c}{\\sqrt{( a + b + c )( - a + b + c )( a - b + c )( a + b - c )}}\n    \\label{app:eq:diam-prop}\n  \\end{equation}\nwhere $a$, $b$ and $c$ are the lengths of the edges of the triangle. \\\\\n\nProjecting each vertex on a same coordinate reference system $(ZW)$, we can characterize that point with a vector $y_i$, that can be decomposed into its two components $z_i$ and $w_i$ as follows:\n  \\begin{equation}\n    \\begin{matrix}\n      z_i = y_i \\cdot \\cos \\theta_i + H_i \\\\\n      w_i = y_i \\cdot \\sin \\theta_i \\\\\n    \\end{matrix}\n    \\label{app:eq:components}\n  \\end{equation}\nwhere $\\theta_i$ is the triangulation angle and $H_i$ is the offset of the laser projector, with respect to the origin of the coordinate system. At this point, it is simple to compute the edges length as:\n  \\begin{equation}\n    \\left\\{\n    \\begin{matrix} \n      & a = \\sqrt{(w_1 + w_2)^2 + (z_1 + z_2)^2} \\\\\n      & b = \\sqrt{(w_2 + w_3)^2 + (z_2 + z_3)^2} \\\\\n      & c = \\sqrt{(w_3 + w_1)^2 + (z_3 + z_1)^2}\n    \\end{matrix}\n    \\right.\n    \\label{app:eq:edges-len}\n  \\end{equation}\nHence, replacing in Equation \\ref{app:eq:diam-prop} the results obtained in Equations \\ref{app:eq:edges-len} and \\ref{app:eq:components}, we can conclude that the error is propagated accordingly with:\n  \\begin{equation*}\n    \\sigma_D = \\sqrt{\n      \\sum_{i = 1}^3 \\left( \\frac{\\partial D}{\\partial y_i} \\sigma_{y_i} \\right)^2 + \n      \\sum_{i = 1}^3 \\left( \\frac{\\partial D}{\\partial H_i} \\sigma_{H_i} \\right)^2 + \n      \\sum_{i = 1}^3 \\left( \\frac{\\partial D}{\\partial \\theta_i} \\sigma_{\\theta_i} \\right)^2\n    }\n  \\end{equation*} \\\\\n\nBecause of there exists a linear relation between the reference system $(ZW)$ and the reference systems of each laser-camera pair, it is possible to define each vector $y_i$ as:\n  \\begin{equation*}\n    |y_i| = \\sqrt{x_w^2 + y_w^2 + z_w^2}\n  \\end{equation*}\nwhere $\\left( x_w, y_w, z_w \\right)$ are the coordinates evaluated in the two sections above, and with $z_w = 0$, because each point lies on the laser plane. Thus, it is simple to determine $\\sigma_{y_i}$ as:\n  \\begin{equation*}\n    \\sigma_{y_i} = \\sqrt{\n      \\left( \\frac{\\partial y_i}{\\partial x_w} \\sigma_{x_w} \\right)^2 + \n      \\left( \\frac{\\partial y_i}{\\partial y_w} \\sigma_{y_w} \\right)^2\n    }\n    % = \\frac{x}{\\sqrt{x_w^2 + y_w^2}}\n  \\end{equation*}\nwhere $\\sigma_{x_w}$ and $\\sigma_{y_w}$ are the value computed with Equations \\ref{app:eq:sigma-xw} and \\ref{app:eq:sigma-yw}, respectively. \\\\\n\nAccordingly with the previous model, $\\theta_i$ is the triangulation angle evaluated with respect to the $Y$ axis, thus $\\sigma_{\\theta_i}$ is the same error estimated with Equation \\ref{app:eq:sigma-yw}. Vice-versa $H_i$ are a constructive parameters, hence we can set $\\sigma_{H_i}$ reasonably, with respect to the requirements of product construction.\n", "meta": {"hexsha": "5c88b47b5738eb3d448ebfd92289c7e50cb80e80", "size": 14814, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/thesis/src/appendexes/model.tex", "max_stars_repo_name": "extoxesses/LaserMat", "max_stars_repo_head_hexsha": "4e893cd56ecea8497918ecafb642b2fbf9a085a2", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-05-12T08:53:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T06:36:55.000Z", "max_issues_repo_path": "report/thesis/src/appendexes/model.tex", "max_issues_repo_name": "extoxesses/LaserMat", "max_issues_repo_head_hexsha": "4e893cd56ecea8497918ecafb642b2fbf9a085a2", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/thesis/src/appendexes/model.tex", "max_forks_repo_name": "extoxesses/LaserMat", "max_forks_repo_head_hexsha": "4e893cd56ecea8497918ecafb642b2fbf9a085a2", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.276119403, "max_line_length": 368, "alphanum_fraction": 0.64709059, "num_tokens": 4973, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.7237669699784719}}
{"text": "\\chapter{Environment}\n\n\\section{Atmosphere}\n\nUS Standard Atmosphere 1976 is used to calculate air temperature, pressure, density, viscosity and speed of sound depending on altitude.\n\nMean molecular weight is given as follows:\n\\begin{equation}\n  M_0 = \\frac{ \\sum_{j} M_j F_j }{ \\sum_{j} F_j } = 28.9645\n\\end{equation}\n\nTemperature is given by the following formula: \\cite{NASA-TM-X-74335}\n\\begin{equation}\n  T \\left( h \\right)\n  =\n  T_j + \\left( \\frac{dT}{dh} \\right)_j \\left( h - h_j \\right)\n\\end{equation}\n\nPressure is given as follows: \\cite{NASA-TM-X-74335}\n\\begin{align}\n  p \\left( h \\right)\n  =\n  p_j \\left( \\frac{T_j}{ T \\left( h \\right) } \\right)\n  ^\n  { \\frac{gM_0}{ R \\left( \\frac{dT}{dh} \\right)_j } }\n  &\\mathrm{~for~} \\left( \\frac{dT}{dh} \\right)_j \\neq 0 \\\\\n    p \\left( h \\right)\n  =\n  p_j e^{ \\frac{ g M_0 \\left( h - h_j \\right) }{RT_j} }\n  &\\mathrm{~for~} \\left( \\frac{dT}{dh} \\right)_j = 0\n\\end{align}\n\nDensity is expressed by the following formula: \\cite{NASA-TM-X-74335}\n\\begin{equation}\n  \\rho \\left( h \\right)\n  =\n  \\frac{ p \\left( h \\right) M_0 }{ RT \\left( h \\right) }\n\\end{equation}\n\nSpeed of sound is given as follows: \\cite{NASA-TM-X-74335}\n\\begin{equation}\n  c_S \\left( h \\right)\n  =\n  \\sqrt{ \\frac{ \\gamma RT \\left( h \\right) }{ M_0 } }\n\\end{equation}\n\nDynamic viscosity is given by the formula: \\cite{NASA-TM-X-74335}\n\\begin{equation}\n  \\mu \\left( h \\right)\n  =\n  \\frac{ 1.458 \\cdot 10^{-6} \\sqrt{ \\left[ T \\left( h \\right) \\right]^3 } }\n  { T \\left( h \\right) + S }\n\\end{equation}\n\nKinetic viscosity is given as follows: \\cite{NASA-TM-X-74335}\n\\begin{equation}\n  \\nu \\left( h \\right)\n  =\n  \\frac{ \\mu \\left( h \\right) }{ \\rho \\left( h \\right) }\n\\end{equation}\n\n\\newpage\n\n\\vfill\n\n\\begin{table}[h!]\n  \\begin{center}\n    \\begin{tabular}{ S | S | S | S }\n      \\toprule\n      \\textbf{Altitude} & \\textbf{Temperature gradient} & \\textbf{Temperature} & \\textbf{Pressure} \\\\\n      {$h_j$} & {$\\left( \\cfrac{dT}{dh} \\right)_j$} & {$T_j$} & {$p_j$} \\\\\n      {[m]} & {[K/m]} & {[K]} & {[Pa]} \\\\ \\midrule\n          0 & -6.5e-3 & 288.15 & 101325.0    \\\\\n      11000 &  0.0    & 216.65 &  22632.0    \\\\\n      20000 &  1.0e-3 & 216.65 &   5474.8    \\\\\n      32000 &  2.8e-3 & 228.65 &    868.01   \\\\\n      47000 &  0.0    & 270.65 &    110.9    \\\\\n      51000 & -2.8e-3 & 270.65 &     66.938  \\\\\n      71000 & -2.0e-3 & 214.65 &      3.9564 \\\\\n      \\bottomrule\n    \\end{tabular}\n    \\caption{Reference levels \\cite{NASA-TM-X-74335} }\n  \\end{center}\n\\end{table}\n\n\\vfill\n\n\\begin{table}[h!]\n  \\begin{center}\n    \\begin{tabular}{ l | S | S }\n      \\toprule\n      \\textbf{Gas species} & \\textbf{Molecular weight} & \\textbf{Fractional volume} \\\\\n      {} & {[kg/kmol]} & {[-]} \\\\ \\midrule\n      Nitrogen       & 28.0134  & 0.78084     \\\\\n      Oxygen         & 31.9988  & 0.209476    \\\\\n      Argon          & 39.948   & 0.00934     \\\\\n      Carbon Dioxide & 44.00995 & 0.000314    \\\\\n      Neon           & 20.183   & 0.00001818  \\\\\n      Helium         & 4.0026   & 0.00000524  \\\\\n      Krypton        & 83.8     & 0.00000114  \\\\\n      Xenon          & 131.3    & 0.000000087 \\\\\n      Methane        & 16.04303 & 0.000002    \\\\\n      Hydrogen       & 2.01594  & 0.0000005   \\\\\n      \\bottomrule\n    \\end{tabular}\n    \\caption{Molecular weights and fractional volume composition of S/L dry air \\cite{NASA-TM-X-74335} }\n  \\end{center}\n\\end{table}\n\n\\vfill\n", "meta": {"hexsha": "d2cbe750e3ec02654d0f0ac549667e54eb283836", "size": 3367, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/fdm_3.tex", "max_stars_repo_name": "marek-cel/mscsim-docs", "max_stars_repo_head_hexsha": "9984f33c84787c4420f11f2834bb35e040e1f36f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-12-01T02:27:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-09T07:02:20.000Z", "max_issues_repo_path": "tex/fdm_3.tex", "max_issues_repo_name": "marek-cel/mscsim-docs", "max_issues_repo_head_hexsha": "9984f33c84787c4420f11f2834bb35e040e1f36f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/fdm_3.tex", "max_forks_repo_name": "marek-cel/mscsim-docs", "max_forks_repo_head_hexsha": "9984f33c84787c4420f11f2834bb35e040e1f36f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-12-01T10:56:23.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-01T19:41:05.000Z", "avg_line_length": 30.3333333333, "max_line_length": 136, "alphanum_fraction": 0.561033561, "num_tokens": 1311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7236992357917574}}
{"text": "% !TEX root = main.tex\n\n%----------------------------------------------------------------------\n\\section{The method of moments}\n%----------------------------------------------------------------------\nPerhaps the simplest estimators are based on the \\emph{method of moments}.\n\n\\bigskip\nLet $X$ be a random variable, let $f(x;\\mathbf{\\theta})$ be its PMF/PDF and consider its $k$th moment:\n\\[\\begin{array}{lll}\n\\expe(X^k) & = \\displaystyle\\sum_{i=1}^{\\infty} x_i^k f(x_i;\\mathbf{\\theta}) \\qquad\t& \\text{(discrete case),} \\\\[3ex]\n\\expe(X^k) & = \\displaystyle\\int_{-\\infty}^{\\infty} x^k f(x;\\mathbf{\\theta})\\,dx\t\t& \\text{(continuous case)}.\n\\end{array}\\]\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the distribution of $X$. To estimate $k$ parameters $\\mathbf{\\theta} = (\\theta_1,\\theta_2,\\ldots,\\theta_k)$, we equate the expressions for the first $k$ moments with the first $k$ empirical moments, then solve the resulting system of equations with respect to $\\theta_1,\\theta_2,\\ldots,\\theta_k$. The number of equations must be equal to the number of unknown parameters we wish to estimate: these are known as the \\emph{moment equations}.\n\\[\n\\expe(X) = \\frac{1}{n}\\sum_{i=1}^n X_i,\n\\quad\n\\expe(X^2) = \\frac{1}{n}\\sum_{i=1}^n X_i^2,\n\\quad\\ldots,\\quad\n\\expe(X^k) = \\frac{1}{n}\\sum_{i=1}^n X_i^k.\n\\]\n%\n%\\ben\n%\\it % single parameter\n%To estimate a scalar parameter $\\theta$ using the \\emph{method of moments}, we equate the first theoretical moment with the first empirical moment (i.e.\\ the sample mean), then solve this with respect to $\\theta$:\n%\\[\n%\\expe(X;\\theta) = \\frac{1}{n}\\sum_{i=1}^n X_i.% \\equiv \\bar{X}.\n%\\]\n%\\it % two parameters\n%To estimate two parameters $\\mathbf{\\theta} = (\\theta_1,\\theta_2)$, we equate the first two theoretical moments with the first two empirical moments, then solve this system of two equations with respect to $\\theta_1$ and $\\theta_2$:\n%\\[\n%\\expe(X;\\mathbf{\\theta}) = \\frac{1}{n}\\sum_{i=1}^n X_i\n%\\qquad\\text{and}\\qquad\n%\\expe(X^2;\\mathbf{\\theta}) = \\frac{1}{n}\\sum_{i=1}^n X_i^2,\n%\\]\n%\\it % k parameters\n%To estimate $k$ parameters $\\mathbf{\\theta} = (\\theta_1,\\theta_2,\\ldots,\\theta_k)$, we equate the first $k$ theoretical moments with the first $k$ empirical moments, then solve the resulting system of equations with respect to $\\theta_1,\\theta_2,\\ldots,\\theta_k$. The number of equations must be equal to the number of unknown parameters we wish to estimate.\n%%\\it In fact, we can equate the theoretical and empirical expected values of \\emph{any} functions of $X$:\n%%\\begin{align*}\n%%\\expe\\big[g_1(X);\\mathbf{\\theta}\\big] & = \\frac{1}{n}\\sum_{i=1}^n g_1(X_i), \\\\\n%%\\expe\\big[g_2(X);\\mathbf{\\theta}\\big] & = \\frac{1}{n}\\sum_{i=1}^n g_2(X_i), \\quad\\text{etc.}\n%%\\end{align*}\n%\\een\n\n% example: uniform\n\\begin{example}\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the continuous $\\text{Uniform}(0,\\theta)$ distribution, where $\\theta>0$ is unknown. Find an estimator of $\\theta$ using the method of moments.\n\\begin{solution}\nLet $X\\sim\\text{Uniform}(0,\\theta)$. In this case, $\\expe(X) = \\theta/2$ so the first moment equation is\n\\[\n\\frac{1}{2}\\theta = \\frac{1}{n}\\sum_{i=1}^n X_i.\n\\]\nSolving for $\\theta$ we obtain $\\hat{\\theta}_{\\text{\\scriptsize{MME}}} = \\displaystyle\\frac{2}{n}\\sum_{i=1}^n X_i$.\n\\end{solution}\n\\end{example}\n\n% example: normal\n\\begin{example}\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $N(\\mu,\\sigma^2)$ distribution. Find estimators of $\\mu$ and $\\sigma^2$ using the method of moments.\n\\end{example}\n\n\\begin{solution}\nLet $X\\sim N(\\mu,\\sigma^2)$ and let $\\theta=(\\mu,\\sigma^2)$ be the parameter vector. Equating the first and second moments with the empirical first and second moments,\n\\[\n\\expe(X)\t= \\frac{1}{n}\\sum_{i=1}^n X_i\n\\qquad\\text{and}\\qquad\n\\expe(X^2)\t= \\frac{1}{n}\\sum_{i=1}^n X_i^2.\n\\]\nThe theoretical moments are $\\expe(X) = \\mu$ and $\\expe(X^2) = \\sigma^2 + \\mu^2$. Solving the resulting equations for $\\mu$ and $\\sigma^2$, we obtain %the following MMEs of $\\mu$ and $\\sigma^2$:\n\\[\n\\hat{\\mu}_{\\text{\\scriptsize{MME}}}\t= \\Xbar\n\\qquad\\text{and}\\qquad\n\\hat{\\sigma}^2_{\\text{\\scriptsize{MME}}}\t\n%= \\frac{1}{n}\\sum_{i=1}^n X_i^2 - \\bar{X}^2 \n= \\frac{1}{n}\\sum_{i=1}^n (X_i-\\bar{X})^2.\n\\]\n%\\begin{align*}\n%\\hat{\\mu}\t\t\t& = \\Xbar, \\\\\n%\\hat{\\sigma}^2\t& = \\frac{1}{n}\\sum_{i=1}^n X_i^2 - \\bar{X}^2 = \\frac{1}{n}\\sum_{i=1}^n (X_i-\\bar{X})^2.\n%\\end{align*}\n\\bit\n\\it The MME of $\\mu$ is the \\emph{sample mean}.\n\\it The MME of $\\sigma^2$ is the \\emph{empirical mean squared deviation from the sample mean}. \n\\eit\nNote that the latter is \\emph{not} the sample variance.\n\\end{solution}\n\n%----------------------------------------------------------------------\n\\begin{exercise}\n\\begin{questions}\n\n% MME of Bernoulli distribution\n\\question\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $\\text{Bernoulli}(\\theta)$ distribution. Find an estimator of $\\theta$ using the method of moments.\n\\begin{answer}\nThe first moment of the $\\text{Bernoulli}(\\theta)$ distribution is $\\theta$. \nEquating this to the first empirical moment (i.e.\\ the sample mean), \n\\[\n\\hat{\\theta}_{\\text{\\scriptsize{MME}}} = \\frac{1}{n}\\sum_{i=1}^n X_i.\n\\]\nThe MME of $\\theta$ is thus the proportion of successes observed in $n$ trials.\n\\end{answer}\n\n% MME of exponential distribution\n\\question\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $\\text{Exponential}(\\lambda)$ distribution, where $\\lambda>0$ is an unknown rate parameter. Find an estimator of $\\lambda$ using the method of moments. \n\\begin{answer}\nLet $X\\sim\\text{Exponential}(\\lambda)$. Then $\\expe(X) = 1/\\lambda$, so the first moment equation is \n\\[\n\\frac{1}{\\lambda} = \\bar{X}.\n\\]\nSolving for $\\lambda$, we obtain $\\hat{\\lambda}_{\\text{\\scriptsize{MME}}} = \\bar{X}^{-1}$.\n\\end{answer}\n\n% MME of Poisson distribution\n\\question\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from the $\\text{Poisson}(\\lambda)$ distribution, where $\\lambda>0$ is unknown. Find an estimator of $\\lambda$ using the method of moments.\n\\begin{answer}\nLet $X\\sim\\text{Poisson}(\\lambda)$. The expected value of $X$ is $\\expe(X)=\\lambda$, so the first moment equation is simply \n\\[\n\\lambda = \\bar{X}.\n\\]\nSolving for $\\lambda$, we obtain $\\hat{\\lambda}_{\\text{\\scriptsize{MME}}} = \\bar{X}$.\n\\end{answer}\n\\end{questions}\n\\end{exercise}\n%----------------------------------------------------------------------\n\n", "meta": {"hexsha": "db94cd9c1456ebf2de7520b970d41b56386d1d58", "size": 6297, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/07C_method_of_moments.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/07C_method_of_moments.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/07C_method_of_moments.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 48.8139534884, "max_line_length": 488, "alphanum_fraction": 0.6514213117, "num_tokens": 2110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673359709795, "lm_q2_score": 0.8902942224835226, "lm_q1q2_score": 0.7236910928605356}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{tikz}\n\\setlength{\\parindent}{0pt}\n\n\\newtheorem*{theorem}{Theorem}\n\\newtheorem*{definition}{Definition}\n\\newtheorem*{lemma}{Lemma}\n\\newtheorem*{corollary}{Corollary}\n\\newtheorem{example}{Example}\n\\newtheorem*{trick}{Trick}\n\\newtheorem*{question}{Question}\n\n\\title{Lecture 6: Kepler's Second Law}\n\\author{}\n\\date{}\n\n\\begin{document}\n    \n\\maketitle\n\n\\section{Describe Motion with Vectors}\n\nWith parametric equations, we have a way not only to describe a motion, but also \nto analyze the motion with more details.\n\n\\subsection{Position vectors}\n\nPosition vectors are used to describe the position of a point in a motion.\n\\begin{equation*}\n  \\vec{r}(t) = <x(t), y(t), z(t)>\n\\end{equation*}\n\nTake the cycloid of the wheel of radius 1 rolling at unit speed as an example:\n\\begin{equation*}\n  \\vec{r}(t) = <t - \\sin t, 1 - \\cos t>\n\\end{equation*}\n\n\\subsection{Velocity vectors}\n\nVelocity vectors are used to describe how fast and in what direction a point \nmoves in a motion.\n\\begin{equation*}\n  \\begin{split}\n    \\vec{v} &= \\frac{d\\vec{r}}{dt} \\\\\n            &= <\\frac{dx}{dt}, \\frac{dy}{dt}, \\frac{dz}{dt}> \\\\\n  \\end{split}\n\\end{equation*}\nSpeed is a scalar, and used to describe how fast a point moves in a motion.\n\\begin{equation*}\n  speed = |\\vec{v}|\n\\end{equation*}\n\nTake the cycloid of the wheel of radius 1 rolling at unit speed as an example:\n\\begin{gather*}\n  \\begin{split}\n    \\vec{v} &= \\frac{d\\vec{r}}{dt} \\\\\n            &= <\\frac{d(t - \\sin t)}{dt}, \\frac{d(1 - \\cos t)}{dt}> \\\\\n            &= <1 - \\cos t, \\sin t> \\\\\n  \\end{split} \\\\\n  \\begin{split}\n    |\\vec{v}| &= \\sqrt{(1 - \\cos t)^2 + \\sin^2 t} \\\\\n              &= \\sqrt{1 - 2\\cos t + \\cos^2 t + \\sin^2 t} \\\\\n              &= \\sqrt{2 - 2\\cos t} \\\\\n  \\end{split} \\\\\n\\end{gather*}\nAt $t = 0$, the velocity vector $\\vec{v} = <0, 0>$, so the speed at that time is\n0.\n\n\\subsection{Acceleration vectors}\n\nAcceleration vectors are used to describe how velocity changes in a motion.\n\\begin{equation*}\n  \\vec{a} = \\frac{d\\vec{v}}{dt}\n\\end{equation*}\n\nTake the cycloid of the wheel of radius 1 rolling at unit speed as an example:\n\\begin{equation*}\n  \\begin{split}\n    \\vec{a} &= \\frac{d\\vec{v}}{dt} \\\\\n            &= <\\frac{d(1 - \\cos t)}{dt}, \\frac{d(\\sin t)}{dt}> \\\\\n            &= <\\sin t, \\cos t> \\\\\n  \\end{split}\n\\end{equation*}\nAt $t = 0$, the acceleration vector $\\vec{a} = <0, 1>$, which means the point at \nthat time has an acceleration in the positive direction of the $y$ axis. \nCombining with the previous conclusion that the velocity at this time is 0, it \nexplains why the trajectory between two arches has a vertical tangent line.\n\n\\subsection{Arc length}\n\nArc length, usually denoted by $s$, is the distance traveled along the \ntrajectory of a motion. According to this definition,\n\\begin{equation*}\n  \\frac{ds}{dt} = speed = |\\vec{v}|\n\\end{equation*}\n\nTake the cycloid of the wheel of radius 1 rolling at unit speed as an example. \nThe length of an arch of the cycloid is\n\\begin{equation*}\n  \\int_{0}^{2\\pi} \\sqrt{2 - 2\\cos t} dt\n\\end{equation*}\n\n\\subsection{Unit tangent vector}\n\nUnit tangent vector, denoted by $\\hat{T}$, is an unit vector in the direction of \nthe tangent line at a position in a motion.\n\nSince $\\vec{v}$ is a tangent vector,\n\\begin{equation*}\n  \\hat{T} = \\frac{\\vec{v}}{|\\vec{v}|}\n\\end{equation*}\n\nAnother definition for the unit tangent vector:\n\\begin{gather*}\n  \\begin{split}\n    \\vec{v} &= \\frac{d\\vec{r}}{dt} \\\\\n            &= \\frac{d\\vec{r}}{ds} \\cdot \\frac{ds}{dt} \\\\\n            &= \\frac{d\\vec{r}}{ds} \\cdot |\\vec{v}| \\\\\n  \\end{split} \\\\\n  \\begin{split}\n    \\frac{d\\vec{r}}{ds} &= \\frac{\\vec{v}}{|\\vec{v}|} \\\\\n                        &= \\hat{T} \\\\\n  \\end{split} \\\\\n  \\vec{v} = \\hat{T} \\cdot \\frac{ds}{dt} \\\\\n\\end{gather*}\n\nTherefore, we can see the velocity vector can be interpreted as:\n\\begin{enumerate}\n  \\item direction: the unit tangent vector $\\hat{T}$.\n  \\item magnitude: the speed $\\frac{ds}{dt}$.\n\\end{enumerate}\n\nThe geometric interpretation of $\\frac{d\\vec{r}}{ds} = \\hat{T}$: during the time \nperiod of $\\Delta t$, \n\\begin{gather*}\n  \\Delta \\vec{r} = \\vec{r}(t + \\Delta t) - \\vec{r}(t) \\\\\n  \\Delta \\vec{r} \\approx \\hat{T} \\cdot \\Delta s \\\\\n  \\frac{\\Delta \\vec{r}}{\\Delta t} \\approx \\hat{T} \\cdot \\frac{\\Delta s}{\\Delta t} \\\\\n\\end{gather*}\nWith $\\Delta t$ approaches 0, the above formula becomes\n\\begin{gather*}\n  \\frac{d\\vec{r}}{dt} = \\hat{T} \\cdot \\frac{ds}{dt} \\\\\n  \\frac{d\\vec{r}}{ds} = \\hat{T} \\\\\n\\end{gather*}\n\n\\section{Example of Describing Motion with Vectors: Kepler's Second Law}\n\n\\subsection{Kepler's Second Law}\n\nKepler's Second Law: Motion of planets is in a plane, and the area swept out by \nthe line from sun to planet at a constant rate.\n\nNewton later explain this law with gravitational attraction.\n\n\\subsection{Translation with Vector Notations}\n\nThe first part of Kepler's Second Law is: motion of planets is in a plane. The \nplane of planet motion is determined by two vectors: the position vector of the \nplanet $\\vec{r}$ and its velocity vector $\\vec{v}$. The plane of planet motion \nremains unchanged $\\iff$ the direction of the normal vector of the plane remains\nunchanged $\\iff$ $dir(\\vec{r} \\times \\vec{v})$ is constant.\n\nThe second part of Kepler's Second Law is: the area swept out by the line from \nsun to planet at a constant rate. The area swept out in unit time can be \ncalculated as\n\\begin{gather*}\n  \\begin{split}\n    dA &= \\frac{1}{2}|\\vec{r} \\times d\\vec{r}| \\\\\n       &= \\frac{1}{2}|\\vec{r} \\times \\vec{v}| dt \\\\\n  \\end{split} \\\\\n  \\frac{dA}{dt} = \\frac{1}{2}|\\vec{r} \\times \\vec{v}| \\\\\n\\end{gather*}\nTherefore, the area swept out by the line from sun to planet at a constant rate \n$\\iff$ $\\frac{dA}{dt}$ is constant $\\iff$ $|\\vec{r} \\times \\vec{v}|$ is constant.\n\nTherefore, Kepler's Second Law $\\iff$ both $dir(\\vec{r} \\times \\vec{v})$ and \n$|\\vec{r} \\times \\vec{v}|$ are constant $\\iff$ $\\vec{r} \\times \\vec{v}$ is \nconstant $\\iff$ $\\frac{d}{dt}(\\vec{r} \\times \\vec{v}) = 0$.\n\n\\begin{gather*}\n  \\frac{d}{dt}(\\vec{r} \\times \\vec{v}) = 0 \\\\\n  \\frac{d\\vec{r}}{dt} \\times \\vec{v} + \\vec{r} \\times \\frac{d\\vec{v}}{dt} = 0 \\\\\n  \\vec{v} \\times \\vec{v} + \\vec{r} \\times \\vec{a} = 0 \\\\\n  0 + \\vec{r} \\times \\vec{a} = 0 \\\\\n  \\vec{r} \\times \\vec{a} = 0 \\\\\n  \\vec{r} \\parallel \\vec{a} \\\\\n\\end{gather*}\n\nTherefore, Kepler's Second Law holds for any moving object if and only if its \nacceleration vector is always parallel to its position vector.\n\n\\end{document}", "meta": {"hexsha": "2cb68f082037b16de1b8a6be5c7620dae044233f", "size": 6523, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture6.tex", "max_stars_repo_name": "jinxinwangstd/multivariable-calculus-mit", "max_stars_repo_head_hexsha": "d165ef6ff085fafd0fb89b8027fc5f5e0dbfa1e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lecture6.tex", "max_issues_repo_name": "jinxinwangstd/multivariable-calculus-mit", "max_issues_repo_head_hexsha": "d165ef6ff085fafd0fb89b8027fc5f5e0dbfa1e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture6.tex", "max_forks_repo_name": "jinxinwangstd/multivariable-calculus-mit", "max_forks_repo_head_hexsha": "d165ef6ff085fafd0fb89b8027fc5f5e0dbfa1e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.2806122449, "max_line_length": 84, "alphanum_fraction": 0.6438755174, "num_tokens": 2186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7236869992451403}}
{"text": "\\textit{\\noindent\nLet $X$ be an infinite-dimensional Fréchet space. %\nProve that $X^\\ast$, with its $\\weakstar$topology, %\nis of the first category in itself.\n}\n\\newline\\newline\\noindent\nThis is actually a consequence of the below lemma,  %\nwhich we prove first. %\nThe proof that $X^\\ast$ is of the first category in itself comes right after, %\nas a corollary.%\n%\n\\paragraph{Lemma.}%\nIf $X$ is an infinite dimensional topological vector space whose dual %\n%\n  $X^\\ast$ %\n%\nseparates points on $X$, then the polar\n%\n  \\begin{align}\n    K_A\\Def \\{ \\Lambda \\in X^\\ast:\\, \\magnitude{\\Lambda} \\leq 1 \\text{ on } A\\}\n  \\end{align} \n%\nof any absorbing subset $A$ is a $\\weakstar$closed set that has empty interior.\n%\n\\begin{proof}%\nLet $x$ range over $X$. The linear form %\n%\n  $\\Lambda \\mapsto \\Lambda x$ %\n%\nis $\\weakstar$continuous; see \\citeresultFA{3.14}. %\nTherefore, %\n%\n  $P_x= \\set{\\Lambda \\in X^\\ast}{\\magnitude{\\Lambda x} \\leq 1}$ %\n%\nis $\\weakstar$ closed: %\n%In particular, every $P_a$ ($a \\in A$) is $\\weakstar$closed:  %\nAs the intersection of $\\set{P_a}{a\\in A}$, %\n$K_A$ is also a $\\weakstar$closed set. %\nWe now prove the second half of the statement. % %\n%\n\\newline\\newline\\noindent\n%\nFrom now on, $X$ is assumed to be endowed with its weak topology: %\n$X$ is then locally convex, but its dual space is still %\n%\n  $X^\\ast$ (see \\citeresultFA{3.11}). %\n%\nPut %\n%\n  \\begin{align}\n    W \\Def \\bigcap_{x\\in F} \\set{\\Lambda \\in X^\\ast}{\\magnitude{\\Lambda x} < r_x}, \n  \\end{align}\n%\nwhere $r_x$ runs on $\\R_+$, %\nas $F$ runs through the nonempty finite subsets of $X$. %\n%\nClearly, the collection of all such $W$ is a local base of $X^\\ast$. %\nPick one of those $W$ and remark that the following subspace %\n%\n  \\begin{align}\n    M \\Def \\text{span}(F)\n  \\end{align}\n%\nis finite dimensional. %\nAssume, to reach a contradiction, that $A\\subset M$. %\nSo, every $x$ lies in $t_xM=M$ for some $t_x>0$, since $A$ is absorbing. %\nAs a consequence, $X=M$ is finite dimensional, which is a desired contradiction.\n%\nWe have just established that $A\\not\\subset M$: %\nNow pick $\\varit{a}$ in $A\\setminus M$ and so conclude that %f\n%\n  \\begin{align}\n    b\\Def \\frac{a}{t_a}\\in A\n  \\end{align}\n%\nRemark that $b\\notin M$ (otherwise, $a = t_a b \\in t_a M=M$ would hold) %\nand that $M$ is closed (see \\citeresultFA{1.21 (b)}): %\nBy the Hahn-Banach theorem \\citeresultFA{3.5}, %\nthere exists $\\Lambda_a$ in $X^\\ast$ such that \n%\n  \\begin{align}\\label{3.11. Polar_4.}\n    \\Lambda_a b > 2\n  \\end{align}\n%\nand\n%\n  \\begin{align}\\label{3.11. Polar_4bis.}\n    \\Lambda_a (M) = \\singleton{0}.\n  \\end{align}\n%\nThe latter equality implies that $\\Lambda_a$ vanishes on $F$; %\nhence $\\Lambda_a$ is an element of $W$. %\nOn the other hand, given an arbitrary $\\Lambda \\in K_A$, %\nthe following inequalities  %\n%\n  \\begin{align}\n    \\magnitude{\\Lambda_a b + \\Lambda b} \n      \\geq \n    2 - \\magnitude{\\Lambda b} \n      >\n    1.\n  \\end{align}\n%\nshow that $\\Lambda + \\Lambda_a$ is not in $K_A$. %\n%\nWe have thus proved that\n%\n  \\begin{align}\n  \\Lambda + W\\not\\subset K_A.\n  \\end{align}\n%\nSince $W$ and $\\Lambda$ are both arbitrary, this achieves the proof. %\n\\end{proof}\n%\n%\\newline\\newline\n\\noindent\nWe now give a proof of the original statement. %\n%\n\\paragraph{Corollary.}%\nIf $X$ is an infinite-dimensional Fréchet space, %\nthen $X^\\ast$ is meager in itself.\n%\n\\begin{proof}%\nFrom now on, $X^\\ast$ is only endowed with its $\\weakstar$topology. %\nLet $d$ be an invariant distance that is compatible with the topology of $X$, %\nso that the following sets\n%\n  \\begin{align}\n    B_n \\Def \\set{x\\in X}{d(0, x) <  1/n}\\quad (\\counting{n}) \n  \\end{align}\n%\nform a local base of $X$. %\n%\nIf $\\Lambda$ is in $X^\\ast$, then %\n%\n  \\begin{align}\n    \\magnitude{\\Lambda} \\leq  m \\text{ on } B_n\n  \\end{align}\n%\nfor some $(n, m) \\in \\singleton{1, 2, 3, \\dots}^2$; see \\citeresultFA{1.18}. %\n%\nHence, $X^\\ast$ is the countable union of all % \n%\n  \\begin{align}\\label{3.11. Countable union.}\n    m\\cdot K_n \\quad (\\counting{m,n}), \n  \\end{align}\n%\nwhere $K_n$ is the polar of $B_n$. %\nClearly, showing that every $m\\cdot K_n$ is nowhere dense %\nis now sufficient. %\nTo do so, we use the fact that $X^\\ast$ separates points; %\nsee \\citeresultFA{3.4}. % \nAs a consequence, the above lemma implies %\n%\n  \\begin{align}\n    \\left({\\overline{K}_n}\\right)^\\circ = \\left({{K}_n}\\right)^\\circ=\\emptyset. \n  \\end{align}\n%\nSince the multiplication by $m$ is an homeomorphism (see \\citeresultFA{1.7}), %\nthis is equivalent to %\n%\n  \\begin{align}\\label{3.11. Nowhere dense.}\n    \\left(\\,{\\overline{m\\cdot K_n}}\\, \\right)^\\circ \n      = \n    %\\left(\\, m \\cdot \\overline{{{K}_n}} \\, \\right)^\\circ\n    %  = \n    %\\left(m \\cdot K_n \\right)^\\circ \n    %  = \n    m\\cdot \\left({{K}_n}\\right)^\\circ \n      = \n    \\emptyset.\n  \\end{align}\n%\nSo ends the proof.% \n\\end{proof}", "meta": {"hexsha": "aff53dc1e6f07fc4ce5a2e9841ef3cfa67879226", "size": 4810, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter_3/3_11.tex", "max_stars_repo_name": "gitcordier/FunctionalAnalysis", "max_stars_repo_head_hexsha": "4d54af9cab1ce2bf512341cc1f2a0c81d7097754", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter_3/3_11.tex", "max_issues_repo_name": "gitcordier/FunctionalAnalysis", "max_issues_repo_head_hexsha": "4d54af9cab1ce2bf512341cc1f2a0c81d7097754", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter_3/3_11.tex", "max_forks_repo_name": "gitcordier/FunctionalAnalysis", "max_forks_repo_head_hexsha": "4d54af9cab1ce2bf512341cc1f2a0c81d7097754", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.4857142857, "max_line_length": 83, "alphanum_fraction": 0.6436590437, "num_tokens": 1659, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7236869966031552}}
{"text": "\n\\subsection{The partial differential operator}\n\n\\subsubsection{Differential}\n\nWhen we change the value of an input to a function, we also change the output. We can examine these changes.\n\nConsider the value of a function \\(f(x)\\) at points \\(x_1\\) and \\(x_2\\).\n\n\\(y_1=f(x_1)\\)\n\n\\(y_2=f(x_2)\\)\n\n\\(y_2-y_1=f(x_2)-f(x_1)\\)\n\n\\(\\dfrac{y_2-y_1}{x_2-x_1}=\\dfrac{f(x_2)-f(x_1)}{x_2-x_1}\\)\n\nLet's define \\(x_2\\) in terms of its distance from \\(x_1\\):\n\n\\(x_2=x_1+\\epsilon\\)\n\n\\(\\dfrac{y_2-y_1}{\\epsilon }=\\dfrac{f(x_1+\\epsilon )-f(x_1)}{\\epsilon }\\)\n\nWe define the differential of a function as:\n\n\\(\\dfrac{\\delta y}{\\delta x}=\\lim_{\\epsilon \\rightarrow 0^+}\\dfrac{f(x+\\epsilon )-f(x)}{\\epsilon }\\)\n\nIf this is defined, then we say the function is differentiable at that point.\n\n\\subsubsection{Differential operator}\n\n\\subsubsection{Graph test}\n\n\n\\begin{tikzpicture}\n\\begin{axis}[\n    axis lines = left,\n    xlabel = $x$,\n    ylabel = {$f(x)$},\n]\n%Below the red parabola is defined\n\\addplot [\n    domain=-10:10, \n    samples=100, \n    color=red,\n]\n{x^2 + 5};\n\\addlegendentry{$x^2 + 5$}\n%Here the blue parabloa is defined\n\\addplot [\n    domain=-10:10, \n    samples=100, \n    color=blue,\n    ]\n{2 * x};\n\\addlegendentry{$2x$}\n \n\\end{axis}\n\\end{tikzpicture}\n\n\n", "meta": {"hexsha": "f07ef787d23e942e22e6a687b132329eb4cba16f", "size": 1245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/calculus/01-01-The_partial_differential_operator.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/calculus/01-01-The_partial_differential_operator.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/calculus/01-01-The_partial_differential_operator.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.0806451613, "max_line_length": 108, "alphanum_fraction": 0.6522088353, "num_tokens": 446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282706, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7236869844963165}}
{"text": "\\chapter{Continuous-time Signals}\n\nA continuous-time (CT) signal \\index{CT Signal} is a function of one or more independent variables conveying information about a physical phenomena. This lecture gives an introduction to continuous-time signals as functions. You learn how to characterize such signals in a number of ways and are introduced to two very important signals: the unit impulse and the complex exponential.\n\n\\section{Signals as Functions}\n\nIn order to reason about signals mathematically we need a representation or {\\it model}. Signals are modeled as functions, mappings between sets\n\\[\nf: A \\rightarrow B\n\\]\nwhere $A$ is a set called the {\\it domain} and $B$ is a set called the {\\it co-domain}.\n\nThe most basic classification of signals depends on the sets that makeup the domain and co-domain. We will be interested in two versions of the domain, the reals denoted $\\mathbb{R}$ and the integers denoted $\\mathbb{Z}$. We will be interested in two versions of the co-domain, the reals $\\mathbb{R}$ and the set of complex numbers $\\mathbb{C}$.\n\n\\begin{definition}[Analog Signal]\n  If the function $f: \\mathbb{R} \\rightarrow \\mathbb{R}$, we call this an analog or real, continuous-time signal, e.g. a voltage at time $t \\in \\mathbb{R}$, $v(t)$. We will write these as $x(t)$, $y(t)$, etc. The units of $t$ are seconds. Fig.~\\ref{fig:ctplots} shows some graphical representations, i.e. plots.\n\\end{definition}\n\n\\begin{figure}[ht]\n  \\begin{center}\n  \\frame{\\includegraphics[scale=0.5]{graphics/ctsignals.pdf}}\n  \\end{center}\n  \\caption{Example plots of analog signals.}\n  \\label{fig:ctplots}\n\\end{figure}\n\n\\begin{definition}[Real, Discrete-time Signal]\n  If the function $f: \\mathbb{Z} \\rightarrow \\mathbb{R}$, we call this a real, discrete-time signal, e.g. the temperature every day at noon. We will write these as $x[n]$, $y[n]$, etc. Note $n$ is dimensionless.\n\\end{definition}\n\n\\begin{figure}[ht]\n  \\begin{center}\n    \\frame{\\includegraphics[scale=0.5]{graphics/dtsignals.pdf}}\n  \\end{center}\n  \\caption{Example plots of real discrete-time signals.}\n  \\label{fig:dtplots}\n\\end{figure}\n\nSome other possibilities:\n  \n\\begin{itemize}\n\\item $f: \\mathbb{R} \\rightarrow \\mathbb{Z}$, digital, continuous-time signals, e.g. the output of a general purpose pin on a microcontroller\n\\item $f: \\mathbb{Z} \\rightarrow \\mathbb{Z}$, digital, discrete-time signals, e.g. the signal on a computer bus\n\\end{itemize}\n\nThe co-domain can also be complex.\n\n\\begin{itemize}\n\\item $f: \\mathbb{R} \\rightarrow \\mathbb{C}$, complex-valued, continuous-time signals, e.g.\\\\\n  \\[\n  x(t) = e^{j\\omega t} = \\cos(\\omega t) + j\\sin(\\omega t)\n  \\]\n\\item $f: \\mathbb{Z} \\rightarrow \\mathbb{C}$, complex-valued, discrete-time signals, e.g.\\\\\n  \\[\n  x[n] = e^{j\\omega n} = \\cos(\\omega n) + j\\sin(\\omega n)\n  \\]\n\\end{itemize}\n  \nSince the domains $\\mathbb{R}$ and $\\mathbb{Z}$ are usually interpreted as time, we will call these {\\it time-domain} signals. In the time-domain, when the co-domain is $\\mathbb{R}$ we call these real signals. All physical signals are real. However complex signals will become important when we discuss the frequency domain.\n\n\\section{Primitive Models}\n\nWe mathematically model signals by combining elementary/primitive functions, for example:\n  \n\\begin{itemize}\n\\item polynomials: $x(t) = t$, $x(t) = t^2$, etc.\n\\item transendental functions: $x(t) = e^t$, $x(t) = \\sin(t)$, $x(t) = \\cos(t)$, etc.\n\\item piecewise functions, e.g.\n  \\[\n     x(t) = \\left\\{  \\begin{array}{cl}\n       f_1(t) & t < 0\\\\\n       f_2(t) & t \\geq 0\\\\\n     \\end{array}\\right.\n     \\]\n\\end{itemize}\n\n\\begin{example}[Modeling a Switch]\n  Consider a mathematical model of a switch, which moves positions at time $t = 0$.\n\n  \\begin{center}\n  \\begin{circuitikz}[american voltages,scale=0.8, every node/.style={transform shape}]\n    \\draw\n    (0,0) to[battery, l=$V$] (0,2.3)\n    (3,2) node[spdt,xscale=-1,yscale=-1,anchor=in] (Sw) {}\n    (0,2.3) to[short] (Sw.out 2)\n    (Sw.out 1) to[short] (1.8,0)\n    (0,0) to[short, -o] (4,0)\n    (3,2) to[short, -o] (4,2)\n    (4,2) to[open, v=$x(t)$] (4,0);;\n  \\end{circuitikz}\n\\end{center}\n\nWe use this model so much we give it it's own name and symbol: Unit Step, $u(t)$\n\n    \\[\n     u(t) = \\left\\{  \\begin{array}{cl}\n        0 & t < 0\\\\\n        1 & t \\geq 0\\\\\n      \\end{array}\\right.\n  \\]\n  so a mathematical model of the switch circuit above would be $x(t) = V u(t)$.\n\n  Note: some texts define the step function at $t=0$ to be $1$ or $\\frac{1}{2}$. It is typically plotted like so:\n  \\begin{center}\n    \\begin{tikzpicture}[scale=0.8, every node/.style={transform shape}]\n  \\begin{axis}[ xlabel=$t$, axis x line=center, axis y line = center, \n    xmin=-2, xmax=2, ymin=0, ymax=1.1, x label style={at={(axis cs:2,0)},anchor=west}]\n    \\draw[-,blue,style={ultra thick}] (axis cs:-2,0) -- (axis cs:0,0);\n    \\draw[-latex,blue,style={ultra thick}] (axis cs:0,1) -- (axis cs:2,1);\n  \\end{axis}\n\\end{tikzpicture}\n    \\end{center}\n\\end{example}\n\n\\begin{example}[Pure audio tone at \"middle C\"]\n  A signal modeling the air pressure of a specific tone might be \n  \\[\n  x(t) = \\sin\\left(2\\pi (261.6) t\\right)\n  \\]\n\\end{example}\n\n\\begin{example}[Chord]\n    The chord \"G\", an additive mixture of tones at G, B, and D and might be modeled as\n    \\[\n    x(t) = \\sin\\left(2\\pi (392) t\\right) + \\sin\\left(2\\pi (494) t\\right) + \\sin\\left(2\\pi (293) t\\right) \n    \\]\n    This example shows we can use addition to build-up signals to approximate real signals of interest.\n\\end{example}\n\n\\section{Basic Transformations}\n\nWe can also apply transformations to signals to increase their modeling flexibility.\n  \n\\begin{itemize}\n\\item  magnitude scaling\n  \\[\n  x_2(t) = a x_1(t)\n  \\]\n  for $a \\in \\mathbb{R}$.\n\\item derivatives\n  \\[\n  x_2(t) = x_1^\\prime(t)\n  \\]\n\\item integrals\n  \\[\n  x_2(t) = \\int\\limits_{-\\infty}^t x_1(\\tau) \\; d\\tau\n  \\]\n\\item sums\n  \\[\n  y(t) = \\sum\\limits_{i} x_i(t)\n  \\]\n  an important example we will see is the CT Fourier series.  \n\\item multiplication (modulation)\n  \\[\n  y(t) = x_1(t) x_2(t)\n  \\]\n  For example amplitude modulation $y(t) = x(t)\\sin(\\omega_0 t)$\n\\item time shift\n  \\[\n  x_2(t) = x_1(t+\\tau)\n  \\]\n  \\begin{itemize}\n  \\item if $\\tau <0$ it is called a {\\it delay}\n  \\item if $\\tau >0$ it is called an {\\it advance}\n  \\end{itemize}\n  \\item time scaling\n    \\[\n    x_2(t) = x_1\\left(\\frac{t}{\\tau}\\right)\n    \\]\n    \\begin{itemize}\n    \\item if $\\tau >0$ increasing $\\tau$ expands in time, slows the signal\n    \\item if $\\tau <0$ time reverses and decreasing $\\tau$ expands in time\n    \\end{itemize}\n    Example: time reversal $ x_2(t) = x_1(-t)$\n\\end{itemize}\n\n\\section{Characterization of Signals}\n\nThere are a few basic ways of characterizing signals.\n\n\\begin{definition}[Causal CT Signal]\n  A CT signal is \\emph{causal} if $x(t) = 0$ $\\forall t < 0$.\n\\end{definition}\n\\begin{definition}[Anti-Causal CT Signal]\n  A CT signal is \\emph{anti-causal} or acausal if $x(t) = 0$ $\\forall t \\geq 0$.\n\\end{definition}\n\nA signal can be written as the sum of a causal and anti-causal signal.\n\n\\begin{definition}[Periodic Signals]\n  A CT signal is \\emph{periodic} if $x(t) = x(t + T)$ $\\forall t$ for a fixed parameter $T \\in \\mathbb{R}$ called the \\emph{period}.\n\\end{definition}\n  \nThe simplest periodic signals are those based on the sinusoidal functions.\n  \n\\begin{definition}[Even Signal]\n  A CT signal is \\emph{even} if $x(t) = x(-t)$ $\\forall t$.\n\\end{definition}\n\n\\begin{definition}[Odd Signal]\n  A CT signal is \\emph{odd} if $x(t) = -x(-t)$ $\\forall t$. \n\\end{definition}\n\nAny CT signal can be written in terms of an even and odd component\n\\[\nx(t) = x_e(t) + x_o(t) \n\\]\nwhere \n\\[\n\\begin{array}{ll}\n  x_e(t) &= \\frac{1}{2}\\left\\{x(t) + x(-t)\\right\\} \\\\\n  & \\\\\n  x_o(t) &= \\frac{1}{2}\\left\\{x(t) - x(-t)\\right\\}\n\\end{array}\n\\]\n\n\\begin{definition}[Energy of a CT Signal]\n  The \\emph{energy} of a CT signal $x(t)$ is defined as a measure of the function\n  \\[\n  E_x = \\lim_{T\\rightarrow\\infty} \\int\\limits_{-T}^T \\lvert x(t) \\rvert^2 dt \\; .\n  \\]\n\\end{definition}\n\n\\begin{definition}[Power of a CT Signal]\n  The \\emph{power} of a CT signal is the energy averaged over an interval as that interval tends to infinity.\n  \\[\n  P_x = \\lim_{T\\rightarrow\\infty} \\frac{1}{2T} \\int_{-T}^T \\lvert x(t)\\rvert^2 dt \\; .\n  \\]\n\\end{definition}\n\nSignals can be characterized based on their energy or power:  \n\\begin{itemize}\n\\item Signals with finite, non-zero energy and zero power are called {\\it energy signals}.\n\\item Signals with finite, non-zero power (and by implication infinite energy) are called {\\it power signals}.\n\\end{itemize}\n\nNote, these categories are non-exclusive, some signals are neither energy or power signals.\n\n\\section{Unit Impulse Function}\nAn important CT signal is the unit impulse function, also called the \"delta\" $\\delta$ function for the symbol traditionally used to define it. Applying this signal to a system models a \"kick\" to that system. For example, consider striking a tuning fork. The reason this signal is so important is that it will turn out that the response of the system to this input tells us all we need to know about a linear, time-invariant system!\n\n\\begin{definition}[CT Impulse Function]\nThe CT impulse function is not really a function at all, but a mathematical object called a \"distribution\". Some equivalent definitions:\n\n\\[\n\\delta(t) = \\lim_{\\epsilon \\rightarrow 0}\\left\\{\n\\begin{array}{ll}\n  \\frac{1}{2\\epsilon} & |t| < \\epsilon\\\\\n  0 & \\text{else}\n\\end{array}\n\\right.\n\\]\n\n\\[\n\\delta(t) = \\lim_{\\epsilon \\rightarrow 0} \\frac{1}{\\sqrt{2\\pi}\\epsilon} e^{-\\frac{t^2}{2\\epsilon^2}}\n\\]\nNote the area under each definition is always one.\n\\end{definition}\n\nIn practice we can often use the following definition and some properties, without worrying about the distribution functions.\n\\[\n\\delta(t) = \\left\\{\n\\begin{array}{ll}\n  0 & t \\neq 0\\\\\n  \\infty & t = 0\n\\end{array}\n\\right. \n\\]\nwhich we draw an vertical arrow in plots:\n\\begin{center}\n  \\begin{tikzpicture}[scale=0.8, every node/.style={transform shape}]\n    \\begin{axis}[ xlabel=$t$, axis x line=center, axis y line = center, \n        xmin=-2, xmax=2, ymin=0, ymax=1.1, x label style={at={(axis cs:2,0)},anchor=west}]\n      \\addplot+[ycomb,mark=triangle,style={ultra thick}] plot coordinates {(0,1)};\n    \\end{axis}\n  \\end{tikzpicture}\n\\end{center}\nNote the height of the arrow is arbitrary. Often in the case of a non-unit impulse function the area is written in parenthesis near the arrow tip.\n\nThe following properties of the impulse function will be used often.\n\n\\begin{itemize}\n\\item The area under the unit impulse is unity since by definition\n  \\[\n  \\int\\limits_{-\\infty}^{\\infty} \\delta(t) \\; dt = 1\n  \\]\n\\item Sampling property: $x(t)\\delta(t-t_0) = x(t_0)\\delta(t-t_0)$\n\\item Sifting Property:\n  \\[\n  \\int\\limits_{a}^{b} x(t)\\delta(t-t_0) \\; dt = x(t_0)\n  \\]\n  for any $a < t_0 < b$.\n\\end{itemize}\n\nWe previously defined the unit step function. The impulse can be defined in terms of the step:\n\\[\n\\delta(t) = \\frac{du}{dt}\n\\]\nand vice-versa\n\\[\nu(t) = \\int\\limits_{-\\infty}^{t} \\delta(\\tau) \\; d\\tau\n\\]\nusing the notion of distributions, e.g.\n\n\\[\nu(t) = \\int\\limits_{-\\infty}^{t} \\delta(\\tau) \\; d\\tau = \\lim_{\\epsilon \\rightarrow 0} \\int\\limits_{-\\infty}^{t} \\frac{1}{\\sqrt{2\\pi}\\epsilon} e^{-\\frac{\\tau^2}{2\\epsilon^2}} \\; d\\tau = \\lim_{\\epsilon \\rightarrow 0} \\frac{1}{2}\\left(1+\\text{erf}\\left( \\frac{t}{\\sqrt{2}\\epsilon}\\right)\\right)\n\\]\n\nThe step and impulse function are related, but in many cases finding the response of a system to a step input is easier.\n\nWe can apply additional transformations to the impulse and step functions to get other useful signals, e.g.\n\n\\begin{itemize}\n\\item ramp\n  \\[\n  r(t) = \\int\\limits_{-\\infty}^{t} u(\\tau) \\; d\\tau = tu(t)\n  \\]\n  \n\\item causal pulse of width $\\epsilon$\n  \\[\n  p(t) = u(t) - u(t-\\epsilon)\n  \\]\n  \n\\item non-causal pulse of width $2\\epsilon$\n  \\[\n      p(t) = u(t+\\epsilon) - u(t-\\epsilon)\n      \\]\n\\end{itemize}\n\n\\section{CT Complex Exponential}\n\nOne of the most important signals in systems theory is the complex exponential:\n\\[\nx(t) = C\\, e^{a t}\n\\]\nwhere the parameters $C, a \\in \\mathbb{C}$ in general.\n\nWhen $C$ and $a$ are both real ($\\Im(C) = \\Im(a) = 0$), we have the familiar exponential. When $a > 0$, $x(t) = C e^{a t}$ looks like:\n\n\\begin{center}   \n  \\begin{tikzpicture}\n    \\begin{axis}[xmin=-2, xmax=2, ymin = 0, ymax=7, samples=50, xlabel=$t$, xticklabels={,,}, yticklabels={,,}]\n      \\addplot[blue, thick] (x,e^x);\n      \\addplot[mark=none, black] coordinates {(0,0) (0,7)};\n      \\addplot[mark=none, black] coordinates {(-2,1) (2,1)};\n      \\node at (axis cs:0,2) [anchor=north east] {$C$};\n    \\end{axis}\n  \\end{tikzpicture}\n\\end{center}\n\nWhen $a < 0$, $x(t) = C e^{a t}$ looks like:\n\n\\begin{center}\n  \\begin{tikzpicture}\n    \\begin{axis}[xmin=-2, xmax=2, ymin = 0, ymax=7, samples=50, xlabel=$t$, xticklabels={,,}, yticklabels={,,}]\n      \\addplot[blue, thick] (x,e^-x);\n      \\addplot[mark=none, black] coordinates {(0,0) (0,7)};\n      \\addplot[mark=none, black] coordinates {(-2,1) (2,1)};\n      \\node at (axis cs:0,2) [anchor=north east] {$C$};\n    \\end{axis}\n  \\end{tikzpicture}\n\\end{center}\n\nTo get the pure sinusoidal case, let $C \\in \\mathbb{R}$ and $a$ be purely imaginary: $a = j\\omega_0$:\n\\[\nx(t) = Ce^{j\\omega_0 t}\n\\]\nwhere $\\omega_0$ is the frequency (in radians/sec). This is called the complex sinusoid.\n\nBy Euler's identity:\n\\[\ne^{j\\omega_0 t} = \\cos(\\omega_0 t) + j\\sin(\\omega_0 t)\n\\]\nand\n\\[\n\\Re(x(t)) = \\cos(\\omega_0 t) = \\frac{1}{2}\\left( e^{j\\omega_0 t} + e^{-j\\omega_0 t} \\right)\n\\]\n\\[\n\\Im(x(t)) = \\sin(\\omega_0 t) = \\frac{1}{2j}\\left( e^{j\\omega_0 t} - e^{-j\\omega_0 t} \\right)\n\\]\nare both real sinusoids.\n\nNote that the sinusoids are periodic. Recall a signal $x(t)$ is periodic with period $T$ if\n\\[\nx(t) = x(t+T) \\; \\forall t\n\\]\nIn the case of the complex sinusoid\n\\[\nCe^{j\\omega_0 t} = Ce^{j\\omega_0 (t+T)}= Ce^{j\\omega_0 t}\\underbrace{e^{j\\omega_0 T}}_{\\text{must be 1}}\n\\]\n\n\\begin{itemize}\n\\item if $\\omega_0 = 0$ this is true for all $T$\n\\item if $\\omega_0 \\neq 0$, then to be periodic $\\omega_0 T = 2\\pi m$ for $m = \\pm 1, \\pm 2, \\cdots$. The smallest $T$ for which this is true is the {\\it fundamental period} $T_0$\n  \\[\n  T_0 = \\frac{2\\pi}{|\\omega_0|}\n  \\]\n  or equivalently $\\omega_0 = \\frac{2\\pi}{T_0}$\n\\end{itemize}\n\nSome useful properties of sinusoids:\n\n\\begin{itemize}\n\\item If x(t) is periodic with period $T$ and $g$ is any function then $g(x(t))$ is periodic with period $T$.\n\\item If $x_1(t)$ is periodic with period $T_1$ and $x_2(t)$ is periodic with period $T_2$, and if there exists positive integers $a,b$ such that\n  \\[\n  aT_1 = b T_2 = P\n  \\]\n  then $x_1(t) + x_2(t)$ and $x_1(t)x_2(t)$ are periodic with period $P$\n\\end{itemize}\nThe last property implies that both $T_1$ and $T_2$ must both be rational in $\\pi$ or neither should be. For example\n\n\\begin{itemize}\n\\item $x(t) = \\sin(2\\pi t) + \\cos(5\\pi t)$ is periodic\n\\item $x(t) = \\sin(2 t) + \\cos(5 t)$ is periodic\n\\item $x(t) = \\sin(2\\pi t) + \\cos(5 t)$ is {\\bf not} periodic\n\\end{itemize}\n\nWhen the parameter $C$ is complex we get a phase shift. Again let $a = j\\omega_0$. When $C$ is complex we can write it as $C = Ae^{j\\phi}$ where $A = |C|$ and $\\phi = \\angle C$. Then\n\n\\[\nx(t) = Ae^{j\\phi} e^{j\\omega_0 t} = Ae^{j(\\omega_0 t+\\phi)} \n\\]\nand\n\\[\n\\Re(x(t)) = A\\cos(\\omega_0 t+\\phi) \n\\]\n\\[\n\\Im(x(t)) = A\\sin(\\omega_0 t+\\phi) \n\\]\n\nSince $\\sin$ is a special case of $\\cos$, i.e. $\\cos(\\theta) = \\sin(\\theta + \\frac{\\pi}{2})$, the general real sinusoid is\n\n\\[\nA\\cos(\\omega_0 t + \\phi)\n\\]\n  \n\\begin{itemize}\n\\item $A$ is called the amplitude\n\\item $\\omega_0$ is again the frequency in radians/sec.\n\\item $\\phi$ is called the phase shift and is related to a time shift $T_s$ by\n  \\[\n  \\phi = \\omega_0T_s\n  \\]\n\\end{itemize}\n\nFor example the signal graphically represented as follows\n\\begin{center}\n  \\includegraphics[scale=0.6]{graphics/ctsinusoid.pdf}\n\\end{center}\nhas the functional representation\n\\[\nx(t) = 2\\cos\\left(\\frac{\\pi}{2} (t+\\tfrac{1}{2}) \\right) =  2\\cos\\left(\\frac{\\pi}{2} t +\\frac{\\pi}{4} \\right)\n\\]\n\n\\subsection{Energy of CT complex sinusoid}\n\nRecall the energy of a CT signal $x(t)$ is    \n\\[\n  E_x = \\lim_{T\\rightarrow\\infty} \\int\\limits_{-T}^T \\lvert x(t) \\rvert^2 dt \\; .\n\\]\nSubstituting $x(t) = e^{j\\omega_0 t}$ and letting $T = N T_0$\n  \\[\n    E_x = \\lim_{N\\rightarrow\\infty} \\int\\limits_{-N T_0}^{N T_0} \\underbrace{\\lvert e^{j\\omega_0 t} \\rvert^2}_{\\text{always 1}} \\; dt = \\lim_{N\\rightarrow\\infty} 2NT_0 = \\infty\n  \\]\n\n\\subsection{Power of CT complex sinusoid}\n\nRecall the power of a CT signal $x(t)$ is\n\\[\n  E_x = \\lim_{T\\rightarrow\\infty} \\frac{1}{2T} \\int\\limits_{-T}^T \\lvert x(t) \\rvert^2 dt \\; .\n\\]\nAgain, substituting $x(t) = e^{j\\omega_0 t}$ and letting $T = N T_0$\n\\[\n  E_x = \\lim_{N\\rightarrow\\infty} \\frac{1}{2NT_0} \\int\\limits_{-N T_0}^{N T_0} \\underbrace{\\lvert e^{j\\omega_0 t} \\rvert^2}_{\\text{always 1}} \\; dt = \\lim_{N\\rightarrow\\infty} \\frac{1}{2NT_0} 2NT_0 = 1\n\\]\n  \n\\subsection{Harmonics}\n\nTwo CT complex sinusoids are {\\it harmonics} of one another is both are periodic in $T_0$. This occurs when\n\n\\[\n    x_k(t) = e^{jk\\omega_0 t} \\; \\text{for} \\; k = 0, \\pm 1, \\pm 2, \\cdots\n\\]\n\nThe term comes from music where the vibrations of a string instrument are modeled as a weighted combination of harmonic tones. \n\n\\subsection{Geometric interpretation of the Complex Exponential}\n\nIn the general case we get a sinusoid signal modulated by an exponential. Let $C = Ae^{j\\phi}$ and $a = r + j\\omega_0$, then\n\\[\n  x(t) = C e^{a t} =  Ae^{j\\phi} e^{(r+j\\omega_0)t}\n\\]\nExpanding the terms and using Euler's identity gives:\n\\[\nx(t) = \\underbrace{Ae^{rt}\\cos(\\omega_0 t+\\phi)}_{\\Re \\text{part}} + j \\underbrace{Ae^{rt}\\sin(\\omega_0 t+\\phi)}_{\\Im \\text{part}}\n\\]\nEach part is a real sinusoid whose amplitude is modulated by a real exponential.\n\nAn important visualization of the general case is to view the signal x(t) as a vector rotating counter-clockwise in the complex plane for positive $t$.\n\n\\begin{center}\n \\includegraphics[scale=0.7]{graphics/CT_complexsinusoid_visual}\n\\end{center}\n\nFor $r < 0$ the tip of the arrow traces out an inward spiral, whereas for $r > 0$ it traces out an outward spiral. For $r = 0$ it traces out the unit circle.\n\n\\section{Solved Problems}\n\n\\begin{enumerate}\n\n\\item Consider a signal described by the function\n  \\[\n  x(t) = e^{-3t}\\sin(10\\pi t)u(t)\n  \\]\n\n  a) Determine the magnitude and phase of $x\\left( \\frac{1}{20}\\right)$\\\\\n  \\textbf{Solution:}\n  Substituting $t = \\frac{1}{20}$ gives\n  \\[\n  x\\left( \\frac{1}{20}\\right) = e^{-3\\frac{1}{20}}\\sin\\left(10\\pi \\frac{1}{20}\\right)u\\left( \\frac{1}{20}\\right) = e^{-\\frac{3}{20}} \\approx 0.86\n  \\]\n  Since the signal is purely real and exponential is always positive, the magnitude is\n  \\[\n  \\left|x\\left( \\frac{1}{20}\\right)\\right| = \\left| e^{-\\frac{3}{20}}\\right| =  e^{-\\frac{3}{20}}  \\approx 0.86\n  \\]\n  and the phase is\n  \\[\n  \\angle x\\left( \\frac{1}{20}\\right) = 0\n  \\]\n\n  b) Using Matlab, plot the signal $|x(t)|$ between $[-2, 2]$. Give your code and embed the plot.\\\\\n\n  \\textbf{Solution:}\n\\begin{verbatim}\n% Solution to PS01 - Problem 1b\nt = -2:0.001:2;\nx = exp(-3*t).*sin(10*pi*t).*heaviside(t);\nhp = plot(t,abs(x));\ngrid on;\nxh = xlabel('t');\nyh = ylabel('|x(t)|');\nth = title('Plot for PS01 Problem 1b');\n\n% make the plot more readable\nset(gca, 'FontSize', 12, 'Box', 'off', 'LineWidth', 2);\nset(hp, 'linewidth', 2);\nset([xh, yh, th], 'FontSize', 12);\n\nset(gcf, 'PaperPositionMode', 'auto');\nprint -dpng ps1p1b.png\n\\end{verbatim}\n%% \\begin{center}\n%% \\includegraphics[scale=0.8]{graphics/ps1p1b.png}\n%% \\end{center}\n\n  \\item Find a solution to the differential equation\n  \\[\n  \\frac{dy}{dt}(t) + 9y(t) = e^{-t}\n  \\]\n  for $t \\geq 0$, when $y(0) = 1$.\\\\\n\n  \\textbf{Solution:}\n  The homogeneous equation is\n  \\[\n  \\frac{dy_h}{dt}(t) + 9y_h(t) = 0\n  \\]\n  with initial condition $y_h(0) = 1$. It's solution is of the form\n  \\[\n  y_h(t) = C\\, e^{-9t} \n  \\]\n  for constant $C$. Using the initial condition\n  \\[\n  y_h(0) = C\\, e^{-0} = C = 1\n  \\]\n  gives\n  \\[\n  y_h(t) = e^{-9t} \n  \\]\n  The particular solution is of the form\n  \\[\n  y_p(t) = C_1 e^{-t} + C_2 e^{-9t}\n  \\]\n  Substitution and equating coefficients gives $C_1 = \\frac{1}{8}$ and $C_2 = -\\frac{1}{8}$. The total solution is the sum of the two solutions or\n  \\[\n  y(t) = \\frac{1}{8} e^{-t} - \\frac{1}{8} e^{-9t} + e^{-9t} = \\frac{1}{8} e^{-t} + \\frac{7}{8} e^{-9t}\n  \\]\n\n  \\item Compute the integral\n    \\[\n    \\int\\limits_{-\\infty}^{\\infty} e^{-t^2} \\, \\delta(t-10)\\; dt\n    \\]\n    where $\\delta(t)$ is the delta function.\\\\\n    \\textbf{Solution:}\n\n  Using the sifting property of the delta function\n  \\[\n  \\int\\limits_{a}^{b} f(t) \\, \\delta(t-t_0)\\; dt = f(t_0)\n  \\]\n  for $a < t_0 < b$, we get\n  \\[\n  \\int\\limits_{-\\infty}^{\\infty} e^{-t^2} \\, \\delta(t-10)\\; dt = e^{-100} \\approx 0\n  \\]  \n\\end{enumerate}\n", "meta": {"hexsha": "99d897649db50bf335768983a6ad1c3f5ff4d999", "size": 20801, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "02-ct-signals.tex", "max_stars_repo_name": "clwyatt/notes-2714", "max_stars_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "02-ct-signals.tex", "max_issues_repo_name": "clwyatt/notes-2714", "max_issues_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "02-ct-signals.tex", "max_forks_repo_name": "clwyatt/notes-2714", "max_forks_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.3818181818, "max_line_length": 431, "alphanum_fraction": 0.6504975722, "num_tokens": 7277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825635346563, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.7236869799307103}}
{"text": "\n\\subsection{Method of moments}\n\n\\subsubsection{Introduction}\n\nIf we have \\(k\\) parameters to estimate, we can solve this if we have \\(k\\) equations.\n\nWe generate these\n\nFirst, we link each first \\(k\\) moments to functions of the parameters.\n\nThen we replace the momenets with sample estimates.\n\n\\subsubsection{Estimation}\n\nThe moments of this population distribution are:\n\n\\(\\mu_i =E[X^i]=g_i(\\theta_1,...,\\theta_k)\\)\n\nWe have a sample.\n\n\\(X=[X_1,...,X_n]\\)\n\nWe now define the method of moments estimator\n\n\\(\\hat \\mu_i=\\dfrac{1}{n}\\sum_{j=1}^nx_j^i\\)\n\n\n\n\n", "meta": {"hexsha": "b1acbfc74c4abd2a8591fb4e4c40fdb729032ca9", "size": 556, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/MOM/01-01-MoM.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/MOM/01-01-MoM.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/MOM/01-01-MoM.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.935483871, "max_line_length": 86, "alphanum_fraction": 0.7086330935, "num_tokens": 157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.7236585492923915}}
{"text": "\\documentclass[fleqn]{article}\n\n\\usepackage{mathtools}\n\\usepackage{nccmath}\n\\usepackage{graphicx}\n\\usepackage{float}\n\\usepackage{booktabs}\n\n\\usepackage [english]{babel}\n\\usepackage [autostyle, english = american]{csquotes}\n\\MakeOuterQuote{\"}\n\n\\DeclarePairedDelimiter\\Floor\\lfloor\\rfloor\n\\DeclarePairedDelimiter\\Ceil\\lceil\\rceil\n\n\\title{ODE model of the spread of measles in secondary schools}\n\\author{David Gurevich}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\nThe following introduces a system of differential equations that is used to model the spread of measles through a secondary school.\n\n\\section*{List of Symbols}\n\n\t$\\beta$ - Probability of disease transmission following an interaction \\\\\n\t$\\sigma$ - Rate of maturation from exposed class to infected class \\\\ \n\t$\\alpha$ - Rate at which symptoms appear in an infected individual \\\\\n\t$\\gamma$ - Rate at which infected individuals recover following the first appearance of \\indent symptoms \\\\\n\t$\\omega$ - Probability of an individual visiting the bathroom \\\\\n\t$q$ - Quantity of virus \"shed\" per minute \\\\ \n\t$Q$ - Ventilation of air inside washroom (per cubic meter) \\\\\n\t$V$ - Volume of each washroom (cubic meters) \\\\\n\t$P$ - Pulmonary ventilation rate (cubic meters per minute) \\\\\n\t$T$ - Average duration of washroom visit \\\\\n\t$\\mathcal{F}$ - Symmetrical contact matrix for friends between grades \\\\\n\t$\\mathcal{C}$ - Symmetrical contact matrix for classmates between grades \\\\\n\n\\newpage\n\n\\section*{SVEIR Model}\n\n$S_i$ - Proportion of population $i$ that is susceptible \\\\\n$V_i$ - Proportion of population $i$ that is vaccinated \\\\\n$E_i$ - Proportion of population $i$ that is exposed \\\\\n$I_i$ - Proportion of population $i$ that is infected \\\\\n$H_i$ - Proportion of population $i$ that is at home because of infection \\\\\n$R_i$ - Proportion of population $i$ that has recovered \\\\\n$W$ - Sum of all concentrations of measles virus in the air in washrooms\\\\ \\\\\n$\\tau$ - Day state: 1 if students are at home, 2 if students are in the halls, 3 if \\indent students are in class\n\\begin{equation}\n\\dfrac{dS_i}{dt} = \n\\begin{dcases}\n\t0 & \\text{if $\\tau = 1$} \\\\\n\t- \\Big[\\Big(\\sum_{j=1}^4 \\dfrac{2}{20} \\beta \\mathcal{F}_{i,j} I_j \\Big) + \\dfrac{1}{6} \\omega \\beta W P \\Big](\\dfrac{S_i}{N_i}) & \\text{if $\\tau = 2$} \\\\\n\t- \\Big[\\Big(\\sum_{j=1}^4 \\dfrac{2}{20} \\beta \\mathcal{C}_{i,j} I_j \\Big) + \\dfrac{1}{6} \\omega \\beta W P \\Big](\\dfrac{S_i}{N_i}) & \\text{if $\\tau = 3$} \t\n\\end{dcases}\n\\end{equation}\n\n\\begin{equation}\n\\dfrac{dV_i}{dt} = 0\n\\end{equation}\n\n\\begin{equation}\n\\dfrac{dE_i}{dt} = \n\\begin{dcases}\n\t0 & \\text{if $\\tau = 1$} \\\\\n\t\\Big[\\Big(\\sum_{j=1}^4 \\dfrac{2}{20} \\beta \\mathcal{F}_{i,j} I_j \\Big) + \\dfrac{1}{6} \\omega \\beta W P \\Big](\\dfrac{S_i}{N_i}) - \\sigma E_i & \\text{if $\\tau = 2$} \\\\\n\t\\Big[\\Big(\\sum_{j=1}^4 \\dfrac{2}{20} \\beta \\mathcal{C}_{i,j} I_j \\Big) + \\dfrac{1}{6} \\omega \\beta W P \\Big](\\dfrac{S_i}{N_i}) - \\sigma E_i & \\text{if $\\tau = 3$} \t\n\\end{dcases}\n\\end{equation}\n\n\\begin{equation}\n\\dfrac{dI_i}{dt} = \\sigma E_i - \\alpha I_i\n\\end{equation}\n\n\\begin{equation}\n\\dfrac{dH_i}{dt} = \\alpha I_i - \\gamma H_i\n\\end{equation}\n\n\\begin{equation}\n\\dfrac{dR_i}{dt} = \\gamma H_i\n\\end{equation}\n\n\\begin{equation}\n\\dfrac{dW}{dt} = \n\\begin{dcases}\n\\dfrac{-Q}{V} & \\text{if $\\tau = 1$} \\\\\n\\dfrac{-Q}{V} + \\dfrac{1}{6} \\omega q T \\sum_{j=1}^4 I_j & \\text{if $\\tau = 2, 3$}\n\\end{dcases}\n\\end{equation}\n\n\\newpage\n\n\\begin{figure}[t!]\n\t\\vspace*{-1.5in}\n\t\\hspace{-2.7in}\n\t\\includegraphics[scale=0.52]{fig.png}\n\\end{figure}\n\\begin{center}\nFigure 1: Plot of ODE solution to model\n\\begin{table}[h]\n\\begin{tabular}{@{}cccc@{}}\n$\\beta$ = 0.91                                                                                                                                                     & $\\dfrac{1}{\\gamma}$ = 4 & $Q$ = 5                                                          & $T$ = 2.2                                                        \\\\\n$\\dfrac{1}{\\sigma}$ = 11                                                                                                                                            & $\\omega$ = 0.00047     & $V$ = 32                                                         &                                                                  \\\\[0.4cm]\n$\\dfrac{1}{\\alpha}$ = 4                                                                                                                                             & $q$ = 144              & $P$ = 0.00556                                                    &                                                                  \\\\\n\\multicolumn{1}{l}{}                                                                                                                                               & \\multicolumn{1}{l}{}   & \\multicolumn{1}{l}{}                                             & \\multicolumn{1}{l}{}                                             \\\\\n\\multicolumn{1}{l}{$ \\mathcal{F} = \\begin{bmatrix} 0.97 & 0.03 & 0 & 0 \\\\ 0.03 & 0.97 & 0.03 & 0 \\\\ 0 & 0.03 & 0.097 & 0.03 \\\\ 0 & 0 & 0.03 & 0.97 \\end{bmatrix}$} & \\multicolumn{1}{l}{}   & \\multicolumn{2}{l}{$ \\mathcal{C} = \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}$}\n\\end{tabular}\n\\end{table}\n\n\\end{center}\n\n\n\\end{document}", "meta": {"hexsha": "3c2b4eb6e98833c6078c35eefb92d0fc157fbd49", "size": 5261, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doc.tex", "max_stars_repo_name": "davidgur/Compartmental-Model", "max_stars_repo_head_hexsha": "c04e58b3d48fdb1e3be15935cfd9d4063ce222cb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/doc.tex", "max_issues_repo_name": "davidgur/Compartmental-Model", "max_issues_repo_head_hexsha": "c04e58b3d48fdb1e3be15935cfd9d4063ce222cb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/doc.tex", "max_forks_repo_name": "davidgur/Compartmental-Model", "max_forks_repo_head_hexsha": "c04e58b3d48fdb1e3be15935cfd9d4063ce222cb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.3534482759, "max_line_length": 332, "alphanum_fraction": 0.522334157, "num_tokens": 1627, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958426, "lm_q2_score": 0.7931059414036511, "lm_q1q2_score": 0.7236585381373338}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\n\\begin{document}\n\n\\subsection{Abstract}\n\nA generalized multilinear regression model, termed the Higher-Order Partial Least Squares (HOPLS) \\cite{HOPLS}, is introduced with the aim to predict a tensor $\\tensor{Y}$ from a tensor $\\tensor{X}$ through projecting the data onto the latent space and performing regression on the corresponding latent variables. This method could be applied to a wide range of datasets. To solve the problem of predicting eye movement we get time series of frames passed through Convolutional Neural Network (CNN).\n\n\\subsection{Problem statement}\n\nWe are given a dataset, that consists of several videos with eye movements and its positions. Let $\\tensor{X}$ is an output of CNN, $\\tensor{Y}$ --- eye coordinate. Assume $\\tensor{X} \\in \\mathbb{R}^{I_1 \\times ... \\times I_N}$ and $\\tensor{Y} \\in \\mathbb{R}^{J_1 \\times ... \\times J_M}$. We assume $\\tensor{X}$ is decomposed as a sum of rank-$(1,L_2,...,L_N)$ Tucker blocks, while $\\tensor{Y}$ is decomposed as a sum of rank-$(1, K_2,...,K_M)$ Tucker blocks, which can be expressed as\n\n\\begin{equation}\n    \\begin{split}\n        \\tensor{X} = \\sum_{r=1}^R \\tensor{G}_r \\times_1 \\textbf{t}_r \\times_2 \\textbf{P}_r^{(1)} \\times_3 ... \\times_n \\textbf{P}_r^{(n-1)} + \\tensor{E}_R \\\\\n        \\tensor{Y} = \\sum_{r=1}^R \\tensor{D}_r \\times_1 \\textbf{t}_r \\times_2 \\textbf{Q}_r^{(1)} \\times_3 ... \\times_n \\textbf{Q}_r^{(n-1)} + \\tensor{F}_R\n    \\end{split}\n\\end{equation}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/HOPLS}\n\\caption{Schematic diagram of the HOPLS model}\n\\label{fig:eye_pred:1}\n\\end{figure} \n\n\\noindent where $R$ is the number of latent vectors, $t_r \\in \\mathbb{R}^{I_1}$ is the $r$-th latent vector, $\\left\\{\\textbf{P}_r^{(n)}\\right\\}_{n=1}^{N-1} \\in \\mathbb{R}^{I_{n+1} \\times L_{n+1}}$ and \n$\\left\\{\\textbf{Q}_r^{(m)}\\right\\}_{m=1}^{M-1} \\in \\mathbb{R}^{J_{n+1} \\times K_{n+1}}$\nare loading matrices on mode-$n$ and mode-$m$ respectively, and $\\tensor{G}_r \\in \\mathbb{R}^{1 \\times L_2 \\times ... \\times L_N}$ and $\\tensor{D}_r \\in \\mathbb{R}^{1 \\times K_2 \\times ... \\times K_M}$ are core tensors.\n\nTo make a prediction we should use \n\\begin{equation}\n    \\label{prediction}\n    \\hat{\\tensor{Y}} = \\tensor{X} \\textbf{W} \\textbf{Q}^{* \\top}\n\\end{equation}\nwhere $\\textbf{W}$ and $\\textbf{Q}^{*}$ have $R$ columns, represented by\n\\begin{equation}\n    \\begin{split}\n        & \\textbf{w}_r = \\left( \\textbf{P}_r^{(N-1)} \\otimes ... \\otimes \\textbf{P}_r^{(1)} \\right) \\tensor{G}_{r}^+ \\\\\n        & \\textbf{q}^*_r = \\tensor{D}_{r} \\left( \\textbf{Q}_r^{(M-1)} \\otimes ... \\otimes \\textbf{Q}_r^{(1)} \\right)\n    \\end{split}\n\\end{equation}\n\n\\subsection{Problem solution}\n\nUse CNN that converts 480x640 pixels images to 24x32 resolution. Its output is $\\tensor{X}$. So $N = 3, I_2 = 34, I_3 = 39$. $\\tensor{Y}$ tensor is given and it is 2 dimensional tensor with $J_2 = 2$ (Fig. \\ref{fig:eye_pred:2}). For these tensors we use Higher-Order Partial Least Squares algorithm described in \\cite{HOPLS} and make a prediction according \\eqref{prediction}. \n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/trajectory}\n\\caption{Trajectory of the center of eye}\n\\label{fig:eye_pred:2}\n\\end{figure}\n\n\\subsection{Code}\n\nHOPLS algorithm was made by Arthur Dehgan, co-author of \\cite{HOPLS} and avalible at  https://github.com/arthurdehgan/HOPLS.\nThe code for computation experiment is located on https://github.com/artem062/ForecastingMethods.\n\n\\subsection{Experiment}\n\nIt was used LPW dataset, that consist of 66 videos with eye moving. This videos was compressed and converted to the tensors. To archive the best $R$ plot the value of $Q^2 = 1 - \\|\\tensor{Y} - \\hat{\\tensor{Y}}\\|^2_F / \\|\\tensor{Y}\\|^2_F$.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=1.0\\textwidth]{figures/plot}\n\\caption{Graph of dependence of $Q^2$ on $R$}\n\\label{fig:eye_pred:3}\n\\end{figure}\n\nThis graph shows that optimal value of $R$ by train dataset is 54, but for test it is 45.\n\n\\end{document}", "meta": {"hexsha": "10a75797b018bd3c77068742f8339c49654b4e82", "size": 4050, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/Voronov2021Lab9/main.tex", "max_stars_repo_name": "Intelligent-Systems-Phystech/mmp2021", "max_stars_repo_head_hexsha": "213f5d81e2ae0c4e77b197b63e6980523f65d9bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-09-15T18:31:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-20T03:58:47.000Z", "max_issues_repo_path": "sections/Voronov2021Lab9/main.tex", "max_issues_repo_name": "Intelligent-Systems-Phystech/mmp2021", "max_issues_repo_head_hexsha": "213f5d81e2ae0c4e77b197b63e6980523f65d9bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/Voronov2021Lab9/main.tex", "max_forks_repo_name": "Intelligent-Systems-Phystech/mmp2021", "max_forks_repo_head_hexsha": "213f5d81e2ae0c4e77b197b63e6980523f65d9bb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-19T21:55:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T13:56:02.000Z", "avg_line_length": 55.4794520548, "max_line_length": 499, "alphanum_fraction": 0.6908641975, "num_tokens": 1384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223264, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7234967392124622}}
{"text": "\\section{Part 1}\n\nThe shared code for this part, as well as the random generator for all the parts is here:\n\n\\lstinputlisting{one.py}\n\n\\section{Part 1.a Normally Distributed pseudo-random numbers}\n\nThe file of the functions used for this exercise is:\n\n\\lstinputlisting{one_a.py}\n\nMy script produces the following plots, see Fig. \\ref{fig:xi_xi}, Fig. \\ref{fig:thousand}, and Fig. \\ref{fig:million}.\nThese plots suggest the random number generator is sufficiently random and is not biased towards any numbers.\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{./plots/Xi_Xi_1.png}\n  \\caption{The results of the first 1000 numbers of the random generator. }\n  \\label{fig:xi_xi}\n\\end{figure}\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{./plots/Index_Xi_1.png}\n  \\caption{First 1000 random numbers vs index.}\n  \\label{fig:thousand}\n\\end{figure}\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{./plots/1000000_rand.png}\n  \\caption{1,000,000 random numbers plotted in 20 bins 0.05 wide.}\n  \\label{fig:million}\n\\end{figure}\n\n\n\\section{Part 1.b Box-Muller Method}\n\nThe file of the functions used for this exercise is:\n\n\\lstinputlisting{one_b.py}\n\nMy script produces the following result, see Fig. \\ref{fig:boxmuller}. As can be seen, the Box-Muller implementation seems\nto create a Gaussian distribution.\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{./plots/box_gauss.png}\n  \\caption{Box-Muller method.}\n  \\label{fig:boxmuller}\n\\end{figure}\n\n\n\\section{Part 1.c KS-test}\n\nThe file of the functions used for this exercise is:\n\n\\lstinputlisting{one_c.py}\n\nThe result of this function is given by the Figures \\ref{fig:kstest}, and \\ref{fig:kstestP}.\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{./plots/KStest.png}\n  \\caption{KS Test.}\n  \\label{fig:kstest}\n\\end{figure}\n\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{./plots/KStest_pvalue.png}\n  \\caption{KS Test P-values.}\n  \\label{fig:kstestP}\n\\end{figure}\n\nThis seems to show that the KS tests are fairly similar in their results, and their results seem to\nsuggest that the Box-Muller implementation is consistent with a Gaussian distribution.\n\n\n\\section{Part 1.d Kuiper Test}\n\nThe file of the functions used for this exercise is:\n\n\\lstinputlisting{one_d.py}\n\nMy script produces the following results, see Fig. \\ref{fig:kuiperTest} and Fig. \\ref{fig:kuiperP}.\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{./plots/KuiperTest.png}\n  \\caption{Kuiper Test implementation.}\n  \\label{fig:kuiperTest}\n\\end{figure}\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{./plots/Kuiper_pvalue.png}\n  \\caption{Kuiper Test implementation.}\n  \\label{fig:kuiperP}\n\\end{figure}\n\nThis seems to show that the probabilities derived from my Kuiper Test differs somewhat from the Kuiper test in Astropy, although the cause for that is unknown. At\nthe same time, the value for V is similar between both the Astropy version and my own.\nIt also shows that my the Box-Muller implementation seems to still be consistent with a Gaussian Distribution.\n\n\n\\section{Part 1.e 10 Sets of Numbers}\n\nThe file of the functions used for this exercise is:\n\n\\lstinputlisting{one_e.py}\n\nMy script produces the following result, see Fig. \\ref{fig:10_sets} for my CDF, and Fig. \\ref{fig:10_sets_sci} for results using\nScipy's norm.cdf as a comparison.\n\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{./plots/RandNumKS.png}\n  \\caption{Results of KS Test on 10 sets of numbers.}\n  \\label{fig:10_sets}\n\\end{figure}\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{./plots/RandNumKS_sci.png}\n  \\caption{Results of KS Test on 10 sets of numbers with Scipy norm.cdf.}\n  \\label{fig:10_sets_sci}\n\\end{figure}\n\nFrom these results, we can see some of the random number sets are consistent with Gaussians for small amounts of numbers,\nbut when using $10^5$ points, none of the sets of random numbers seems consistent. Overall, the closest seems to be\nset 3 from the p-values. When lookng at the results using Scipy's norm.cdf as comparison, there seems to also be set 5 that\nclose to a Gaussian the most times on the graph compared to other ones, but is still not consistent at $10^5$ points. Therefore,\nI conclude that sets 5 and 3 are the most consistent with a Gaussian distribution when taking in large numbers of points, sets\n1, 9, and 6 are consistent with a Gaussian at specific numbers of points, but none are consistent over all the range in numbers of points.\n\n", "meta": {"hexsha": "8c6462f99dc0066d16fc7f5a779b4037487eca4b", "size": 4617, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "part_1.tex", "max_stars_repo_name": "jacobbieker/NUR_Handin2", "max_stars_repo_head_hexsha": "6e620b23191edaec4452d29eac90ec37ced0c038", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "part_1.tex", "max_issues_repo_name": "jacobbieker/NUR_Handin2", "max_issues_repo_head_hexsha": "6e620b23191edaec4452d29eac90ec37ced0c038", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "part_1.tex", "max_forks_repo_name": "jacobbieker/NUR_Handin2", "max_forks_repo_head_hexsha": "6e620b23191edaec4452d29eac90ec37ced0c038", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-05-17T07:33:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-17T07:33:07.000Z", "avg_line_length": 32.9785714286, "max_line_length": 162, "alphanum_fraction": 0.7565518735, "num_tokens": 1327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8824278772763471, "lm_q1q2_score": 0.7234967360032046}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{changepage}\n\\usepackage[margin=0.75in]{geometry}\n\n\\setlength\\parindent{0pt}\n\n\\begin{document}\nArguably the most common stable distribution parameterization has characteristic function given by\n\\begin{equation*}\n\t\\varphi(t; \\alpha, \\beta, c, \\mu) = \\exp(it\\mu - \\lvert ct \\rvert^\\alpha (1 - i\\beta\\operatorname{sgn}(t)\\Phi)), \\qquad \\Phi = \\begin{cases}\n\t\t\\tan(\\frac{\\pi\\alpha}{2}), &\\text{if } \\alpha \\neq 1\\\\\n\t\t-\\frac{2}{\\pi}\\log\\lvert t \\rvert, &\\text{if } \\alpha = 1\n\t\\end{cases}\n\\end{equation*}\nFor simplicity, we force the scale $c=1$ and the location $\\mu = 0$, yielding\n\\begin{equation*}\n\t\\varphi(t; \\alpha, \\beta) = \\exp(-\\lvert t \\rvert^\\alpha (1 - i\\beta\\operatorname{sgn}(t)\\Phi))\n\\end{equation*}\nwith $\\Phi$ defined as before.\n\n\\subsection*{PDF Integrand Derivation}\n\t\nProbability density functions are the Fourier transforms of their respective characteristic functions, so\n\\begin{align*}\n\tf(x) &= \\frac{1}{2\\pi} \\int_{-\\infty}^\\infty \\varphi(t) e^{-ixt} \\,dt\\\\\n\t&= \\frac{1}{2\\pi} \\int_{-\\infty}^\\infty \\exp(-\\lvert t \\rvert^\\alpha (1 - i\\beta\\operatorname{sgn}(t)\\Phi)) \\exp(-ixt) \\,dt\\\\\n\t\\intertext{By Euler's formula and ignoring strictly complex terms (since the PDF is real-valued),}\n\t&= \\frac{1}{2\\pi} \\int_{-\\infty}^\\infty \\exp(-\\lvert t \\rvert^\\alpha) [\\cos(\\lvert t \\rvert^\\alpha \\beta \\operatorname{sgn}(t)\\Phi)\\cos(xt)+\\sin(\\lvert t \\rvert^\\alpha \\beta \\operatorname{sgn}(t)\\Phi)\\sin(xt)] \\,dt\n\t\\intertext{Lastly, by symmetry,}\n\tf(x) &= \\frac{1}{\\pi} \\int_0^\\infty \\exp(-t^\\alpha) [\\cos(t^\\alpha\\beta\\Phi)\\cos(xt)+\\sin(t^\\alpha\\beta\\Phi)\\sin(xt)] \\,dt\n\\end{align*}\nNote that the oscillatory terms $\\cos(xt)$ and $\\sin(xt)$ should be incorporated into a weighting function in QUADPACK routines.\\\\\n\nTransforming into the $S_0$ parameterization of Nolan amounts to computing $f(x+\\beta\\tan(\\pi\\alpha/2))$ instead of $f(x)$ when $\\alpha \\neq 1$.\n\n\\subsection*{CDF Integrand Derivation}\n\nDue to an inversion formula by Gil-Pelaez, we have\n\\begin{align*}\n\tF(x) &= \\frac{1}{2} - \\frac{1}{\\pi} \\int_0^\\infty \\frac{\\operatorname{Im}[\\varphi(t)e^{-ixt}]}{t} \\,dt\n\t\\intertext{Rewriting to make use of $t \\geq 0$ yields}\n\t&= \\frac{1}{2} - \\frac{1}{\\pi} \\int_0^\\infty \\frac{\\operatorname{Im}[ \\exp(-t^\\alpha (1 - i\\beta\\Phi)) \\exp(-ixt)]}{t} \\,dt\n\t\\intertext{and applying Euler's formula gives us}\n\tF(x) &= \\frac{1}{2} - \\frac{1}{\\pi} \\int_0^\\infty \\frac{\\exp(-t^\\alpha)[-\\cos(t^\\alpha \\beta\\Phi) \\sin(xt)+\\sin(t^\\alpha \\beta\\Phi)\\cos(xt)]}{t} \\,dt\n\\end{align*}\n\nNote that the oscillatory terms $\\cos(xt)$ and $\\sin(xt)$ should be incorporated into a weighting function in QUADPACK routines.\\\\\n\nTransforming into the $S_0$ parameterization of Nolan amounts to computing $F(x+\\beta\\tan(\\pi\\alpha/2))$ instead of $F(x)$ when $\\alpha \\neq 1$.\n\\end{document}", "meta": {"hexsha": "a29c3d36a2fcf9f069f3df6f97852605705ac3b3", "size": 2864, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "figures/simple_quadrature_derivation/simple_quadrature_derivation.tex", "max_stars_repo_name": "ragibson/levy-stable-benchmarks", "max_stars_repo_head_hexsha": "2ffdd574c7833476029373e423f393105f130102", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-09T18:25:32.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-09T18:25:32.000Z", "max_issues_repo_path": "figures/simple_quadrature_derivation/simple_quadrature_derivation.tex", "max_issues_repo_name": "ragibson/levy-stable-benchmarks", "max_issues_repo_head_hexsha": "2ffdd574c7833476029373e423f393105f130102", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "figures/simple_quadrature_derivation/simple_quadrature_derivation.tex", "max_forks_repo_name": "ragibson/levy-stable-benchmarks", "max_forks_repo_head_hexsha": "2ffdd574c7833476029373e423f393105f130102", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.037037037, "max_line_length": 215, "alphanum_fraction": 0.6787709497, "num_tokens": 1056, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866548, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.7234967208735691}}
{"text": "% A (minimal) template for problem sets and solutions using the exam document class\n\n% Organization:\n%% Define new commands, macros, etc. in macros.tex\n%% Anything that you would put before \\begin{document} should go in prelude.tex\n\n%% For multiple psets, each should get its own file to \\input into main with a \\section{}\n\\input{prelude}\n\\begin{document}\n\n\\title{Computational Fluid Dynamics\\\\Homework 5}\n\\author{Francisco Jose Castillo Carrasco}\n\\date{\\today}\n\\maketitle\n\n\\input{macros}\n\n%% Content goes here\n\\section*{Introduction}\nIn this assignment I will be using the Crank-Nicholson method to solve the following PDE\n\\begin{align*}\n\\frac{\\partial T}{\\partial t}=\\alpha\\frac{\\partial^2 T}{\\partial x^2}+q(x,t),\n\\end{align*}\ndefined on the domain $x\\in[-1,1]$ with boundary conditions \n\\begin{align*}\nT(-1,t)&=2-\\sin\\left(\\frac{3\\pi}{2}t\\right),\\\\\n\\frac{\\partial T}{\\partial x}(1,t)&=0,\n\\end{align*}\nand initial condition $T(x,0)=2$, with $\\alpha=0.1$. The source term $q$ for $t>0$ is given by\n\\begin{align*}\nq(x,t)=\\frac{3\\pi}{2\\sqrt{t}}&\\sin\\left(\\frac{\\pi}{2}\\sqrt{t}\\right)\\cos\\left(\\frac{\\pi}{2}\\sqrt{t}\\right)\\left(x^3-x^2-x+1\\right)+\\frac{3\\pi}{2}\\cos\\left(\\frac{3\\pi}{2}t\\right)\\sin\\left(\\frac{\\pi}{2}x\\right)\\\\\n&+\\alpha\\left(\\sin^2\\left(\\frac{\\pi}{2}\\sqrt{t}\\right)(6-18x)+\\frac{\\pi^2}{4}\\sin\\left(\\frac{3\\pi}{2}t\\right)\\sin\\left(\\frac{\\pi}{2}x\\right)\\right),\n\\end{align*}\nand $q(x,0)=0$.\n\nThis first part of the assignment (the one typed) includes the formulation of the problem using the Crank Nicholson method for a node based and a cell based mesh.\n\\subsection*{Node Based Mesh}\n\\input{NodeMesh}\n\n\\subsection*{Cell Based Mesh}\n\\input{CellMesh}\n\\section*{Maximum stable time step for the FTCS}\nAs we saw in class, the maximum stable time step size for the FTCS is\n\\begin{align*}\n\\Delta t=\\frac{h^2}{2\\alpha},\n\\end{align*}\nand the time step used in the code is four time this,\n\\begin{align*}\n\\Delta t=2\\frac{h^2}{\\alpha}.\n\\end{align*}\nThere is no index form for this.\n\\end{document}", "meta": {"hexsha": "1b81093921fa69ed3c4692acf77d807b7296a912", "size": 1999, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/CFD/Homework_5/Latex/Homework5_part1.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/CFD/Homework_5/Latex/Homework5_part1.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/CFD/Homework_5/Latex/Homework5_part1.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.4423076923, "max_line_length": 210, "alphanum_fraction": 0.7053526763, "num_tokens": 672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339797047029, "lm_q2_score": 0.8615382058759128, "lm_q1q2_score": 0.7234629062878298}}
{"text": "\n\\color{black}\n\\subsection*{Stationary distribution a Markov model}\n\nCompute the stationary distribution\n\\begin{equation*}\n\\vec{\\pi} = \\mat{P}_{\\lambda_1} \\vec{\\pi}\n\\end{equation*}\nof the Markov chain $\\lambda_1$. Proceed as follows: introduce \n\\begin{equation*}\n  \\mat{A} = \\begin{bmatrix} \\mat{I} - \\mat{P}_{\\lambda_1} \\\\ \\trn{\\vec{1}} \\end{bmatrix} \\qquad \\text{and} \\qquad \n  \\vec{b} = \\begin{bmatrix} \\vec{0} \\\\ 1 \\end{bmatrix}\n\\end{equation*}\nwhere the matrix $\\mat{I}$ and the vector $\\vec{0}$ and $\\vec{1}$ have to be of appropriate sizes. Then solve\n\\begin{equation*}\n\\mat{A} \\, \\vec{\\pi} = \\vec{b}\n\\end{equation*}\nfor $\\vec{\\pi}$. Round your result to two decimals.\n\\color{blue}\n%%%%%\n%%%%% enter your answer after the '=' sign\n%%%%%\n\\begin{equation*}\n\\vec{\\pi} = \\begin{bmatrix} 0.33333333 \\\\ 0.33333333 \\\\ 0.33333333 \\end{bmatrix}\n\\end{equation*}\n%%%%%\n%%%%%\n%%%%%\n\\color{black}\n\nIf you like, paste the code you used to practically compute your result after the following \\texttt{import} statements\n\\color{blue}\n%%%%%\n%%%%% paset your code after the import statements\n%%%%%\n\\begin{PythonCode}\nimport numpy as np\nimport numpy.linalg as la\n\n\n\\end{PythonCode}\n%%%%%\n%%%%%\n%%%%%\n\\color{black}\n\n\n", "meta": {"hexsha": "bb5c77d71c6c527d526f2aa34917ec15422e167f", "size": 1203, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SelfTest1SS2020/selfTestProblem4.tex", "max_stars_repo_name": "baraaHassan/Game-AI-Course", "max_stars_repo_head_hexsha": "dd4ed04b10b2231aac2f98b3b88274f7ab0cc339", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SelfTest1SS2020/selfTestProblem4.tex", "max_issues_repo_name": "baraaHassan/Game-AI-Course", "max_issues_repo_head_hexsha": "dd4ed04b10b2231aac2f98b3b88274f7ab0cc339", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SelfTest1SS2020/selfTestProblem4.tex", "max_forks_repo_name": "baraaHassan/Game-AI-Course", "max_forks_repo_head_hexsha": "dd4ed04b10b2231aac2f98b3b88274f7ab0cc339", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0625, "max_line_length": 118, "alphanum_fraction": 0.6600166251, "num_tokens": 410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8615382165412809, "lm_q1q2_score": 0.7234629048774747}}
{"text": "\\lab{Index of Pseudocode Notation}{Index of Notation}\n\\label{notation_index}\n\n\\section*{Objects}\n\\renewcommand{\\arraystretch}{1.3}\n\\begin{tabular}{l l}\n$A$ \t\t\t\t\t& A capitol letter typically denotes a matrix, or 2-D NumPy array\\\\\n$[[a, b], [c, d]]$ \t\t\t& The explicit array $\\left(\\begin{array}{cc}\na & b\\\\\nc & d\\\\\\end{array}\\right)$\\\\\n$A \\gets \\allocate{m}{n}$, \n$\\v \\gets \\allocate{k}$ \t& Allocate memory for an $m \\times n$ NumPy array $A$\n\t\t\t\t\t\tor for a vector $\\v$ of length $k$\\\\\n$\\Id{n}$\t \t\t\t& The $n\\times n$ array with 1's on the diagonal and 0's elsewhere \\\\\n$a$ \t\t\t\t\t& A lowercase letter typically denotes a scalar\\\\\n\n$A[:, j], \\v[i]$ \t\t\t& Slice the 2-D array $A$ or 1-D array $\\v$ as in Python\\\\\n$\\v$ \t\t\t\t\t& A boldface letter typically denotes a vector, or 1-D NumPy array\\\\\n$\\zeros{m}{n}$,\n$\\zeros{k}$\t \t\t& The $m\\times n$ array or length-$k$ vector of zeros \n\\end{tabular}\n\n\\section*{Operations}\n\\begin{tabular}{l l}\n$\\makecopy{A}$\t\t& Make a copy of the array $A$\\\\\n$A/a$, $\\v/a$, $b/a$ \t\t& Divide by the scalar $a$\\\\\n$AB$, $aB$\t\t\t& Multiply scalars or matrices\\\\\n$\\norm{\\v}, \\norm{\\v}_2$ \t\t& Find the (Euclidean) norm of $\\v$\\\\\n$\\shape{A}$\t\t\t& Return the dimensions of the array $A$\\\\\n$\\sign(a)$\t\t\t\t& Return the sign of the scalar $a$\\\\\n$\\size{A}$\t\t\t\t& Return the number of elements in the array $A$\\\\\n$A\\trp$\t\t\t\t& Transpose the array $A$\n\\end{tabular}\n\n\\section*{Programming constructs}\n\\begin{tabular}{p{5.5cm} p{8cm}}\n$\\vartriangleright$\t\t& Comment\\\\\n${\\bf for}\\; i=1 \\ldots n\\; {\\bf do}$ & ``For'' loop. Iterate from 1 to $n$.\\\\\n$\\gets$\t\t\t\t& Assignment operator. If $a \\gets b$ then $a$ is assigned the value of $b$.\\\\\n$\\bf{if} \\;\\ldots\\; \\bf{else}$\t\t& ``If'' construction with optional ``else''\\\\\n$\\bf{Procedure}<${\\sc Name}$>$(Parameters)\t\t& Defines the start of the algorithm called $<${\\sc Name}$>$ which accepts the specified parameters as inputs\\\\\n$\\bf{while}$\t\t\t& ``While'' construction\\\\\n$\\bf{return}$\t\t\t& End of algorithm. Return any values specified.\n\\end{tabular}", "meta": {"hexsha": "45164e4199698b2a74c2a061f5964dc28205f3d2", "size": 1991, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notation_index.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "notation_index.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notation_index.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 45.25, "max_line_length": 155, "alphanum_fraction": 0.6238071321, "num_tokens": 703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.7234628916784259}}
{"text": "\n%----------------------------------------------------------------------------------------\n%\tCHAPTER 2\n%----------------------------------------------------------------------------------------\n%\\chapterimage{chapter_head_void.pdf} % Chapter heading image\n\n\\chapter{In-text Elements}\n\n\\section{Theorems}\\index{Theorems}\n\nThis is an example of theorems. Theorema \\ref{theo:A}, \\ref{theo:B}, \\ref{theo:C}, \\ref{theo:D} e \\ref{theo:E}.\n\n\\subsection{Several equations}\\index{Theorems!Several Equations}\nThis is a theorem consisting of several equations.\n\n\\begin{theorem}[Name of the theorem]\n\\label{theo:A}\nIn $E=\\mathbb{R}^n$ all norms are equivalent. It has the properties:\n\\begin{align}\n& \\big| ||\\mathbf{x}|| - ||\\mathbf{y}|| \\big|\\leq || \\mathbf{x}- \\mathbf{y}||\\\\\n&  ||\\sum_{i=1}^n\\mathbf{x}_i||\\leq \\sum_{i=1}^n||\\mathbf{x}_i||\\quad\\text{where $n$ is a finite integer}\n\\end{align}\n\\end{theorem}\n\n\\begin{proofraw}[Relativa ao Teorema \\ref{theo:A}]\nIn $E=\\mathbb{R}^n$ all norms are equivalent. It has the properties:\n\\begin{align}\n& \\big| ||\\mathbf{x}|| - ||\\mathbf{y}|| \\big|\\leq || \\mathbf{x}- \\mathbf{y}||\\\\\n&  ||\\sum_{i=1}^n\\mathbf{x}_i||\\leq \\sum_{i=1}^n||\\mathbf{x}_i||\\quad\\text{where $n$ is a finite integer}\n\\end{align}\n\\end{proofraw}\n\n\\subsection{Single Line}\\index{Theorems!Single Line}\nThis is a theorem consisting of just one line.\n\n\\begin{theorem}\n\\label{theo:B}\nA set $\\mathcal{D}(G)$ in dense in $L^2(G)$, $|\\cdot|_0$. A set $\\mathcal{D}(G)$ in dense in $L^2(G)$, $|\\cdot|_0$. \nA set $\\mathcal{D}(G)$ in dense in $L^2(G)$, $|\\cdot|_0$. A set $\\mathcal{D}(G)$ in dense in $L^2(G)$, $|\\cdot|_0$. \n\\end{theorem}\n\n\\begin{exercise}[Exercise name]\nGiven a vector space $E$, a norm on $E$ is an application, denoted $||\\cdot||$, $E$ in $\\mathbb{R}^+=[0,+\\infty[$ such that:\n\\begin{align}\n& ||\\mathbf{x}||=0\\ \\Rightarrow\\ \\mathbf{x}=\\mathbf{0}\\\\\n& ||\\lambda \\mathbf{x}||=|\\lambda|\\cdot ||\\mathbf{x}||\\\\\n& ||\\mathbf{x}+\\mathbf{y}||\\leq ||\\mathbf{x}||+||\\mathbf{y}||\n\\end{align}\n\\end{exercise}\n\n\\begin{exercise}[Exercise name A0]\n\\label{ex:A0}\nGiven a vector space $E$, a norm on $E$ is an application, denoted $||\\cdot||$, $E$ in $\\mathbb{R}^+=[0,+\\infty[$ such that:\n\\begin{align}\n& ||\\mathbf{x}||=0\\ \\Rightarrow\\ \\mathbf{x}=\\mathbf{0}\\\\\n& ||\\lambda \\mathbf{x}||=|\\lambda|\\cdot ||\\mathbf{x}||\\\\\n& ||\\mathbf{x}+\\mathbf{y}||\\leq ||\\mathbf{x}||+||\\mathbf{y}||\n\\end{align}\n\\end{exercise}\n\n%------------------------------------------------\n\n\\section{Definitions}\\index{Definitions}\n\nThis is an example of a definition. A definition could be mathematical or it could define a concept.\n\\begin{theorem}\n\\label{theo:C}\nA set $\\mathcal{D}(G)$ in dense in $L^2(G)$, $|\\cdot|_0$. A set $\\mathcal{D}(G)$ in dense in $L^2(G)$, $|\\cdot|_0$. \nA set $\\mathcal{D}(G)$ in dense in $L^2(G)$, $|\\cdot|_0$. A set $\\mathcal{D}(G)$ in dense in $L^2(G)$, $|\\cdot|_0$. \n\\end{theorem}\n\n\\begin{theorem}\n\\label{theo:D}\nA set $\\mathcal{D}(G)$ in dense in $L^2(G)$, $|\\cdot|_0$. A set $\\mathcal{D}(G)$ in dense in $L^2(G)$, $|\\cdot|_0$. \nA set $\\mathcal{D}(G)$ in dense in $L^2(G)$, $|\\cdot|_0$. A set $\\mathcal{D}(G)$ in dense in $L^2(G)$, $|\\cdot|_0$. \n\\end{theorem}\n\n\\begin{definition}[Definition name]\nGiven a vector space $E$, a norm on $E$ is an application, denoted $||\\cdot||$, $E$ in $\\mathbb{R}^+=[0,+\\infty[$ such that:\n\\begin{align}\n& ||\\mathbf{x}||=0\\ \\Rightarrow\\ \\mathbf{x}=\\mathbf{0}\\\\\n& ||\\lambda \\mathbf{x}||=|\\lambda|\\cdot ||\\mathbf{x}||\\\\\n& ||\\mathbf{x}+\\mathbf{y}||\\leq ||\\mathbf{x}||+||\\mathbf{y}||\n\\end{align}\n\\end{definition}\n\n\\begin{theorem}[Theorem name]\n\\label{theo:E}\nGiven a vector space $E$, a norm on $E$ is an application, denoted $||\\cdot||$, $E$ in $\\mathbb{R}^+=[0,+\\infty[$ such that:\n\\begin{align}\n& ||\\mathbf{x}||=0\\ \\Rightarrow\\ \\mathbf{x}=\\mathbf{0}\\\\\n& ||\\lambda \\mathbf{x}||=|\\lambda|\\cdot ||\\mathbf{x}||\\\\\n& ||\\mathbf{x}+\\mathbf{y}||\\leq ||\\mathbf{x}||+||\\mathbf{y}||\n\\end{align}\n\\end{theorem}\n\n\\begin{example}[Example name]\nGiven a vector space $E$, a norm on $E$ is an application, denoted $||\\cdot||$, $E$ in $\\mathbb{R}^+=[0,+\\infty[$ such that:\n\\begin{align}\n& ||\\mathbf{x}||=0\\ \\Rightarrow\\ \\mathbf{x}=\\mathbf{0}\\\\\n& ||\\lambda \\mathbf{x}||=|\\lambda|\\cdot ||\\mathbf{x}||\\\\\n& ||\\mathbf{x}+\\mathbf{y}||\\leq ||\\mathbf{x}||+||\\mathbf{y}||\n\\end{align}\n\\end{example}\n\n\\begin{exercise}[Exercise name A]\n\\label{exer:A}\nGiven a vector space $E$, a norm on $E$ is an application, denoted $||\\cdot||$, $E$ in $\\mathbb{R}^+=[0,+\\infty[$ such that:\n\\begin{align}\n& ||\\mathbf{x}||=0\\ \\Rightarrow\\ \\mathbf{x}=\\mathbf{0}\\\\\n& ||\\lambda \\mathbf{x}||=|\\lambda|\\cdot ||\\mathbf{x}||\\\\\n& ||\\mathbf{x}+\\mathbf{y}||\\leq ||\\mathbf{x}||+||\\mathbf{y}||\n\\end{align}\n\\end{exercise}\n\n\n\\begin{exercise}[Exercise name]\nGiven a vector space $E$, a norm on $E$ is an application, denoted $||\\cdot||$, $E$ in $\\mathbb{R}^+=[0,+\\infty[$ such that:\n\\begin{align}\n& ||\\mathbf{x}||=0\\ \\Rightarrow\\ \\mathbf{x}=\\mathbf{0}\\\\\n& ||\\lambda \\mathbf{x}||=|\\lambda|\\cdot ||\\mathbf{x}||\\\\\n& ||\\mathbf{x}+\\mathbf{y}||\\leq ||\\mathbf{x}||+||\\mathbf{y}||\n\\end{align}\n\\end{exercise}\n\n\\begin{exercise}[Exercise name B]\n\\label{exer:B}\nGiven a vector space $E$, a norm on $E$ is an application, denoted $||\\cdot||$, $E$ in $\\mathbb{R}^+=[0,+\\infty[$ such that:\n\\begin{align}\n& ||\\mathbf{x}||=0\\ \\Rightarrow\\ \\mathbf{x}=\\mathbf{0}\\\\\n& ||\\lambda \\mathbf{x}||=|\\lambda|\\cdot ||\\mathbf{x}||\\\\\n& ||\\mathbf{x}+\\mathbf{y}||\\leq ||\\mathbf{x}||+||\\mathbf{y}||\n\\end{align}\n\\end{exercise}\n%------------------------------------------------\n\nExer \\ref{ex:A0}(Exercise name A0), \\ref{exer:A}(Exercise name A) e \\ref{exer:B}(Exercise name B).\n\n\\section{Notations}\\index{Notations}\n\nNotations \\ref{not:A}, \\ref{not:B}, \\ref{not:C} e \\ref{not:D}.\n\n\\begin{notation}\n\\label{not:A}\nGiven an open subset $G$ of $\\mathbb{R}^n$, the set of functions $\\varphi$ are:\n\\begin{enumerate}\n\\item Bounded support $G$;\n\\item Infinitely differentiable;\n\\end{enumerate}\na vector space is denoted by $\\mathcal{D}(G)$. \n\\end{notation}\n\n\\begin{notation}[Notation name title very large]\n\\label{not:B}\nGiven an open subset $G$ of $\\mathbb{R}^n$, the set of functions $\\varphi$ are:\n\\begin{enumerate}\n\\item Bounded support $G$;\n\\item Infinitely differentiable;\n\\end{enumerate}\na vector space is denoted by $\\mathcal{D}(G)$. \n\\end{notation}\n\n\\begin{notation}\n\\label{not:C}\nGiven an open subset $G$ of $\\mathbb{R}^n$, the set of functions $\\varphi$ are:\n\\begin{enumerate}\n\\item Bounded support $G$;\n\\item Infinitely differentiable;\n\\end{enumerate}\na vector space is denoted by $\\mathcal{D}(G)$. \n\\end{notation}\n\n\\begin{notation}[Notation name]\n\\label{not:D}\nGiven an open subset $G$ of $\\mathbb{R}^n$, the set of functions $\\varphi$ are:\n\\begin{enumerate}\n\\item Bounded support $G$;\n\\item Infinitely differentiable;\n\\end{enumerate}\na vector space is denoted by $\\mathcal{D}(G)$. \n\\end{notation}\n\n%------------------------------------------------\n\n\\section{Boxequation}\\index{Boxequation}\n\n\\begin{boxequation}\nGiven a vector space $E$, a norm on $E$ is an application, denoted $||\\cdot||$, $E$ in $\\mathbb{R}^+=[0,+\\infty[$ such that:\n\\begin{align}\n& ||\\mathbf{x}||=0\\ \\Rightarrow\\ \\mathbf{x}=\\mathbf{0}\\\\\n& ||\\lambda \\mathbf{x}||=|\\lambda|\\cdot ||\\mathbf{x}||\\\\\n& ||\\mathbf{x}+\\mathbf{y}||\\leq ||\\mathbf{x}||+||\\mathbf{y}||\n\\end{align}\n\\end{boxequation}\n\n\n\\section{Frasebox}\\index{Frasebox}\n\n\\begin{frasebox}{Frase title}{Fernando P. R.}\nGiven a vector space $E$, a norm on $E$ is an application, denoted $||\\cdot||$, $E$ in $\\mathbb{R}^+=[0,+\\infty[$ such that:\n\\begin{align}\n& ||\\mathbf{x}||=0\\ \\Rightarrow\\ \\mathbf{x}=\\mathbf{0}\\\\\n& ||\\lambda \\mathbf{x}||=|\\lambda|\\cdot ||\\mathbf{x}||\\\\\n& ||\\mathbf{x}+\\mathbf{y}||\\leq ||\\mathbf{x}||+||\\mathbf{y}||\n\\end{align}\n\\end{frasebox}\n%------------------------------------------------\n\n\\section{Attentionbox}\\index{Attentionbox}\n\nThis is an example of a remark.\n\n\\begin{attentionbox}\nThe concepts presented here are now in conventional employment in mathematics. \nVector spaces are taken over the field $\\mathbb{K}=\\mathbb{R}$, however, established properties are easily extended to $\\mathbb{K}=\\mathbb{C}$.\n\\end{attentionbox}\n\n%------------------------------------------------\n\n\\section{Informationbox}\\index{Informationbox}\n\nThis is an example of a remark.\n\n\\begin{informationbox}{Título A}\nThe concepts presented here are now in conventional employment in mathematics. \nVector spaces are taken over the field $\\mathbb{K}=\\mathbb{R}$, however, established properties are easily extended to $\\mathbb{K}=\\mathbb{C}$.\n\\end{informationbox}\n\n%------------------------------------------------\n\n\\section{Elaborationbox}\\index{Elaborationbox}\n\nThis is an example of a remark.\n\n\\begin{elaborationbox}{título}\nThe concepts presented here are now in conventional employment in mathematics. \nVector spaces are taken over the field $\\mathbb{K}=\\mathbb{R}$, however, established properties are easily extended to $\\mathbb{K}=\\mathbb{C}$.\n\\end{elaborationbox}\n%------------------------------------------------\n\n\n\n", "meta": {"hexsha": "3304eac8e9ecda9184a2f5fa7429f697d7e174a0", "size": 8972, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/cap2/cap2.tex", "max_stars_repo_name": "trucomanx/template-book-scientific1", "max_stars_repo_head_hexsha": "5782845a4f8cb2eb6ba2f7833da848b038d3c4ce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/cap2/cap2.tex", "max_issues_repo_name": "trucomanx/template-book-scientific1", "max_issues_repo_head_hexsha": "5782845a4f8cb2eb6ba2f7833da848b038d3c4ce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/cap2/cap2.tex", "max_forks_repo_name": "trucomanx/template-book-scientific1", "max_forks_repo_head_hexsha": "5782845a4f8cb2eb6ba2f7833da848b038d3c4ce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.9218106996, "max_line_length": 143, "alphanum_fraction": 0.6113464111, "num_tokens": 3178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7234462123752764}}
{"text": "\\section{The matrix of a linear transformation}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find the matrix of a linear transformation with respect to\n    general bases in vector spaces.\n  \\end{enumerate}\n\\end{outcome}\n\nIn Section~\\ref{sec:matrix-of-transformation}, we saw that linear\ntransformations $T:\\R^n\\to\\R^m$ are in one-to-one correspondence with\n$m\\times n$-matrices. Here, we will generalize this correspondence to\narbitrary finite-dimensional vector spaces. There is an important\ndifference, however. While $\\R^n$ comes with a natural coordinate\nsystem (i.e., every vector in $\\R^n$ has a first component, second\ncomponent, and so on), there is no distinguished coordinate system on\nan arbitrary vector space. To define the matrix of a linear\ntransformation $T:V\\to W$, we must first choose a basis, or\nequivalently a coordinate system, for $V$ and for $W$. Different\nchoices of basis will give rise to different matrices.\n\nLet $V$ be a vector space with basis\n$B=\\set{\\vect{v}_1,\\ldots,\\vect{v}_n}$. Recall from\nSection~\\ref{ssec:bases-and-coordinates} that the \\textbf{coordinates}\nof a vector $\\vect{v}$ with respect to the basis $B$%\n\\index{coordinate!with respect to basis}%\n\\index{coordinate system!and basis} are the unique scalars\n$a_1,\\ldots,a_n$ such that\n\\begin{equation*}\n  \\vect{v} = a_1\\,\\vect{v}_1 + \\ldots + a_n\\,\\vect{v}_n.\n\\end{equation*}\nAs before, we write\n\\begin{equation*}\n  \\coord{\\vect{v}}_B = \\begin{mymatrix}{c} a_1 \\\\ a_2 \\\\ a_3 \\end{mymatrix}\n\\end{equation*}\nto denote the coordinates of $\\vect{v}$ with respect to the basis $B$.\nWe will now see how to use bases and coordinates to encode any linear\nmap between finite-dimensional vector spaces as a matrix.\n\n\\begin{proposition}{The matrix of a linear transformation}{matrix-of-linear-transformation-vector-space}\n  Let $V$ and $W$ be finite-dimensional vector spaces over a field\n  $K$. Assume $B$ is a basis of $V$ and $C$ is a basis of $W$.  Let\n  $T:V\\to W$ be a linear transformation. Then there exists a unique\n  $m\\times n$-matrix $A$ such that for all $\\vect{v}\\in V$,\n  \\begin{equation*}\n    A\\coord{\\vect{v}}_B = \\coord{T\\vect{v}}_C.\n  \\end{equation*}\n  Moreover, $A$ can be computed as follows: the $i\\th$ column of $A$\n  holds the coordinates of $T(\\vect{v}_i)$, where $\\vect{v}_i$ is the\n  $i\\th$ vector of the basis $B$, and the coordinates are computed\n  with respect to the basis $C$.\n\\end{proposition}\n\n\\begin{proof}\n  Let $B=\\set{\\vect{v}_1,\\ldots,\\vect{v}_n}$ and\n  $C=\\set{\\vect{w}_1,\\ldots,\\vect{w}_m}$.  By\n  Theorem~\\ref{thm:transformation-basis}, the linear transformation\n  $T$ is completely determined by the images of the basis vectors,\n  $T(\\vect{v}_1),\\ldots,T(\\vect{v}_n)\\in W$. Since\n  $\\set{\\vect{w}_1,\\ldots,\\vect{w}_m}$ is a basis of $W$, we can write\n  each $T(\\vect{v}_i)$ as a linear combination of\n  $\\vect{w}_1,\\ldots,\\vect{w}_m$:\n  \\begin{eqnarray*}\n    T(\\vect{v}_1)\n    &=& a_{11}\\vect{w}_1 + a_{21}\\vect{w}_2 + \\ldots + a_{m1}\\vect{w}_m, \\\\\n    T(\\vect{v}_2)\n    &=& a_{12}\\vect{w}_1 + a_{22}\\vect{w}_2 + \\ldots + a_{m2}\\vect{w}_m, \\\\\n    &\\cdots& \\\\\n    T(\\vect{v}_n)\n    &=& a_{1n}\\vect{w}_1 + a_{2n}\\vect{w}_2 + \\ldots + a_{mn}\\vect{w}_m.\n  \\end{eqnarray*}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{cccc}\n      a_{11} & a_{12} & \\cdots & a_{1n} \\\\\n      a_{21} & a_{22} & \\cdots & a_{2n} \\\\\n      \\vdots & \\vdots & \\ddots & \\vdots \\\\\n      a_{m1} & a_{m2} & \\cdots & a_{mn} \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Then $A$ is an $m\\times n$-matrix. We must prove that it has the\n  desired property, i.e., that\n  $A\\coord{\\vect{v}}_B = \\coord{T\\vect{v}}_C$, for all\n  $\\vect{v}\\in V$. Since both the left-hand side and the right-hand\n  side are linear functions of $\\vect{v}$, it suffices to check that\n  this property holds for basis vectors. Consider, therefore, one of\n  the basis vectors $\\vect{v}_i$.  Note that\n  $\\vect{v}_i = 0\\vect{v}_1 + 0\\vect{v}_2 + \\ldots + 1\\vect{v}_i +\n  \\ldots + 0\\vect{v}_n$. Therefore, the coordinates of $\\vect{v}_i$\n  with respect to the basis $B$ are\n  \\begin{equation*}\n    \\coord{\\vect{v}_i}_B =\n    \\begin{mysmallmatrix}{c}\n      0 \\\\ \\vdots \\\\ 1 \\\\ \\vdots \\\\ 0\n    \\end{mysmallmatrix}\n    = \\vect{e}_i,\n  \\end{equation*}\n  where $\\vect{e}_i$ is the usual $i\\th$ standard basis vector.  On\n  the other hand, since\n  $T(\\vect{v}_i) = a_{1i}\\vect{w}_1 + \\ldots + a_{mi}\\vect{w}_m$,\n  we have\n  \\begin{equation*}\n    \\coord{T(\\vect{v}_i)}_C =\n    \\begin{mysmallmatrix}{c}\n      a_{1i} \\\\ \\vdots \\\\ a_{mi}\n    \\end{mysmallmatrix}\n    = A\\vect{e}_i.\n  \\end{equation*}\n  Here, in the last equation, we have used the fact that $A\\vect{e}_i$\n  is the same thing as the $i\\th$ column of $A$. We therefore have\n  $\\coord{T(\\vect{v}_i)}_C = A\\vect{e}_i = A \\coord{\\vect{v}_i}_B$, as\n  desired.\n\\end{proof}\n\n\\begin{definition}{The matrix of a linear transformation}{matrix-of-linear-transformation-vector-space}\n  The matrix $A$ of\n  Proposition~\\ref{prop:matrix-of-linear-transformation-vector-space} is called the\n  \\textbf{matrix of the linear transformation\\/ $T$ with respect to\n    the bases $B$ and $C$}%\n  \\index{linear transformation!matrix of!w.r.t. basis}%\n  \\index{matrix!of a linear transformation!w.r.t. basis}.  We also\n  write\n  \\begin{equation*}\n    A = \\coord{T}_{C,B}.\n  \\end{equation*}\n  Therefore,\n  \\begin{equation*}\n    \\coord{T}_{C,B}\\coord{\\vect{v}}_B = \\coord{T\\vect{v}}_C\n  \\end{equation*}\n  for all $\\vect{v}\\in V$.\n\\end{definition}\n\n\\begin{example}{Finding the matrix of a linear transformation}{matrix-of-linear-transformation-vector-space}\n  Find the matrix of the derivative operator $D:\\Poly_3\\to\\Poly_2$\n  with respect to the basis $B=\\set{1,x,x^2,x^3}$ of $\\Poly_3$ and the\n  basis $C=\\set{1,x,x^2}$ of $\\Poly_2$.\n\\end{example}\n\n\\begin{solution}\n  We first find the images of each basis vector of the basis $B$, and\n  we write each of them as a linear combination of basis vectors from\n  the basis $C$. Let us denote the basis vectors of $B$ as\n  $\\vect{v}_1 = 1$, $\\vect{v}_2 = x$, $\\vect{v}_3 = x^2$, and\n  $\\vect{v}_4=x^3$, and the basis vectors of $C$ as $\\vect{w}_1 = 1$,\n  $\\vect{w}_2 = x$, and $\\vect{w}_3 = x^2$. We have\n  \\begin{equation*}\n    \\begin{array}{rclclclcl}\n      D(\\vect{v}_1) &=& D(1) &=& 0 &=& 0 + 0x + 0x^2 &=& 0\\vect{w}_1 + 0\\vect{w}_2 + 0\\vect{w}_3, \\\\\n      D(\\vect{v}_2) &=& D(x) &=& 1 &=& 1 + 0x + 0x^2 &=& 1\\vect{w}_1 + 0\\vect{w}_2 + 0\\vect{w}_3, \\\\\n      D(\\vect{v}_3) &=& D(x^2) &=& 2x &=& 0 + 2x + 0x^2 &=& 0\\vect{w}_1 + 2\\vect{w}_2 + 0\\vect{w}_3, \\\\\n      D(\\vect{v}_4) &=& D(x^3) &=& 3x^2 &=& 0 + 0x + 3x^2 &=& 0\\vect{w}_1 + 0\\vect{w}_2 + 3\\vect{w}_3. \\\\\n    \\end{array}\n  \\end{equation*}\n  Therefore, we have\n  \\begin{equation*}\n    A=\\coord{D}_{C,B} =\n    \\begin{mymatrix}{rrrr}\n      0 & 1 & 0 & 0 \\\\\n      0 & 0 & 2 & 0 \\\\\n      0 & 0 & 0 & 3 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Same linear transformation, different bases}{matrix-of-linear-transformation-vector-space2}\n  Find the matrix of the derivative operator $D:\\Poly_3\\to\\Poly_2$\n  with respect to the basis $B'=\\set{1,x+1,x^2+x+1,x^3+x^2+x+1}$ of\n  $\\Poly_3$ and the basis $C'=\\set{1,x-1,x^2-1}$ of $\\Poly_2$.\n\\end{example}\n\n\\begin{solution}\n  This is the same linear transformation as in the previous example,\n  but we are given different bases. Let us denote the basis vectors of\n  $B'$ as $\\vect{v}_1 = 1$, $\\vect{v}_2 = x+1$, $\\vect{v}_3 = x^2+x+1$, and\n  $\\vect{v}_4=x^3+x^2+x+1$, and the basis vectors of $C'$ as $\\vect{w}_1 = 1$,\n  $\\vect{w}_2 = x-1$, and $\\vect{w}_3 = x^2-1$. We must write each\n  $D(\\vect{v}_i)$ as a linear combination of $\\vect{w}_1$,\n  $\\vect{w}_2$, and $\\vect{w}_3$, which requires solving a system of\n  linear equations for each of them. We have:\n  \\begin{equation*}\n    \\begin{array}{rclclcl}\n      D(\\vect{v}_1) &=& D(1) &=& 0 &=& 0\\vect{w}_1 + 0\\vect{w}_2 + 0\\vect{w}_3, \\\\\n      D(\\vect{v}_2) &=& D(x+1) &=& 1 &=& 1\\vect{w}_1 + 0\\vect{w}_2 + 0\\vect{w}_3, \\\\\n      D(\\vect{v}_3) &=& D(x^2+x+1) &=& 2x+1 &=& 3\\vect{w}_1 + 2\\vect{w}_2 + 0\\vect{w}_3, \\\\\n      D(\\vect{v}_4) &=& D(x^3+x^2+x+1) &=& 3x^2+2x+1 &=& 6\\vect{w}_1 + 2\\vect{w}_2 + 3\\vect{w}_3. \\\\\n    \\end{array}\n  \\end{equation*}\n  Therefore, the matrix is\n  \\begin{equation*}\n    \\coord{D}_{C',B'} =\n    \\begin{mymatrix}{rrrr}\n      0 & 1 & 3 & 6 \\\\\n      0 & 0 & 2 & 2 \\\\\n      0 & 0 & 0 & 3 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nThe last two examples illustrate that a linear transformation can have\nmany different matrices, because the matrix depends not only on the\nlinear transformation, but also on the given bases. The art of linear\nalgebra often lies in choosing ``convenient'' bases for a given\napplication. Often, a ``convenient'' basis is one that gives rise to\nsimple matrices, for example, matrices containing many zeros, or\nmatrices that are diagonal.\n\n\\begin{example}{Finding a convenient basis}{matrix-of-linear-transformation-vector-space3}\n  Let $T:\\Poly_3\\to\\Mat_{2,2}$ be the linear transformation\n  defined by\n  \\begin{equation*}\n    T(ax^3+bx^2+cx+d)=\n    \\begin{mymatrix}{cc} a+d & b-c \\\\ b+c & a-d \\end{mymatrix}\n  \\end{equation*}\n  for all $ax^3+bx^2+cx+d\\in\\Poly_3$. Let\n  $B=\\set{x^3, x^2, x, 1}$ and\n  \\begin{equation*}\n    C=\\set{\n      \\begin{mymatrix}{cc} 1 & 0 \\\\ 0 & 0 \\end{mymatrix},\n      \\begin{mymatrix}{cc} 0 & 1 \\\\ 0 & 0 \\end{mymatrix},\n      \\begin{mymatrix}{cc} 0 & 0 \\\\ 1 & 0 \\end{mymatrix},\n      \\begin{mymatrix}{cc} 0 & 0 \\\\ 0 & 1 \\end{mymatrix}\n    }\n  \\end{equation*}\n  be bases of $\\Poly_3$ and $\\Mat_{2,2}$, respectively.\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item Find $\\coord{T}_{C,B}$.\n    \\item Find a basis $C'$ of $\\Mat_{2,2}$ such that\n      $\\coord{T}_{C',B}$ is the identity matrix.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{example}\n\n\\begin{solution}\n  (a) We have\n  \\begin{equation*}\n    \\begin{array}{rcccl}\n      T(x^3)\n      &=& \\begin{mymatrix}{rr} 1 & 0 \\\\ 0 & 1 \\end{mymatrix}\n      &=&\n      1 \\begin{mymatrix}{cc} 1 & 0 \\\\ 0 & 0 \\end{mymatrix}\n      + 0 \\begin{mymatrix}{cc} 0 & 1 \\\\ 0 & 0 \\end{mymatrix}\n      + 0 \\begin{mymatrix}{cc} 0 & 0 \\\\ 1 & 0 \\end{mymatrix}\n      + 1 \\begin{mymatrix}{cc} 0 & 0 \\\\ 0 & 1 \\end{mymatrix}, \\\\\\\\[-2ex]\n      T(x^2)\n      &=& \\begin{mymatrix}{rr} 0 & 1 \\\\ 1 & 0 \\end{mymatrix}\n      &=&\n      0 \\begin{mymatrix}{cc} 1 & 0 \\\\ 0 & 0 \\end{mymatrix}\n      + 1 \\begin{mymatrix}{cc} 0 & 1 \\\\ 0 & 0 \\end{mymatrix}\n      + 1 \\begin{mymatrix}{cc} 0 & 0 \\\\ 1 & 0 \\end{mymatrix}\n      + 0 \\begin{mymatrix}{cc} 0 & 0 \\\\ 0 & 1 \\end{mymatrix}, \\\\\\\\[-2ex]\n      T(x)\n      &=& \\begin{mymatrix}{rr} 0 & -1 \\\\ 1 & 0 \\end{mymatrix}\n      &=&\n      0 \\begin{mymatrix}{cc} 1 & 0 \\\\ 0 & 0 \\end{mymatrix}\n      - 1 \\begin{mymatrix}{cc} 0 & 1 \\\\ 0 & 0 \\end{mymatrix}\n      + 1 \\begin{mymatrix}{cc} 0 & 0 \\\\ 1 & 0 \\end{mymatrix}\n      + 0 \\begin{mymatrix}{cc} 0 & 0 \\\\ 0 & 1 \\end{mymatrix}, \\\\\\\\[-2ex]\n      T(1)\n      &=& \\begin{mymatrix}{rr} 1 & 0 \\\\ 0 & -1 \\end{mymatrix}\n      &=&\n      1 \\begin{mymatrix}{cc} 1 & 0 \\\\ 0 & 0 \\end{mymatrix}\n      + 0 \\begin{mymatrix}{cc} 0 & 1 \\\\ 0 & 0 \\end{mymatrix}\n      + 0 \\begin{mymatrix}{cc} 0 & 0 \\\\ 1 & 0 \\end{mymatrix}\n      - 1 \\begin{mymatrix}{cc} 0 & 0 \\\\ 0 & 1 \\end{mymatrix}.\n    \\end{array}\n  \\end{equation*}\n  Therefore,\n  \\begin{equation*}\n    \\coord{T}_{C,B}\n    =\n    \\begin{mymatrix}{rrrr}\n      1 & 0 &  0 &  1 \\\\\n      0 & 1 & -1 &  0 \\\\\n      0 & 1 &  1 &  0 \\\\\n      1 & 0 &  0 & -1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\n  \\noindent (b) Since the matrices $T(x^3)$, $T(x^2)$, $T(x)$, and $T(1)$\n  form a basis of $\\Mat_{2,2}$, we can take $C'$ to consist of\n  these four matrices, i.e.,\n  \\begin{equation*}\n    C' = \\set{\n      \\begin{mymatrix}{cc} 1 &  0 \\\\ 0 &  1 \\end{mymatrix},\n      \\begin{mymatrix}{cc} 0 &  1 \\\\ 1 &  0 \\end{mymatrix},\n      \\begin{mymatrix}{cc} 0 & -1 \\\\ 1 &  0 \\end{mymatrix},\n      \\begin{mymatrix}{cc} 1 &  0 \\\\ 0 & -1 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  Then\n  \\begin{equation*}\n    \\coord{T}_{C',B}\n    =\n    \\begin{mymatrix}{rrrr}\n      1 & 0 &  0 &  0 \\\\\n      0 & 1 &  0 &  0 \\\\\n      0 & 0 &  1 &  0 \\\\\n      0 & 0 &  0 &  1 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  is the identity matrix.\n\\end{solution}\n\nWe end this section with some properties of matrices of linear\ntransformations.\n\n\\begin{proposition}{Properties of matrices of linear transformations.}{matrix-of-linear-transformation-properties}\n  Let $V$, $W$, and $U$ be finite-dimensional vector spaces with\n  respective bases $B$, $C$, and $D$. Suppose $T,T':V\\to W$ and\n  $S:W\\to U$ are linear transformations. The following hold:\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item $\\coord{S\\circ T}_{D,B} = \\coord{S}_{D,C}\\coord{T}_{C,B}$.\n    \\item $\\coord{1_V}_{B,B} = I$.\n    \\item $T$ is invertible if and only if $\\coord{T}_{C,B}$ is\n      invertible, and in that case,\n      $\\coord{T^{-1}}_{B,C} = (\\coord{T}_{C,B})^{-1}$.\n    \\item $\\coord{0}_{C,B} = 0$.\n    \\item $\\coord{T+T'}_{C,B} = \\coord{T}_{C,B} + \\coord{T'}_{C,B}$.\n    \\item $\\coord{kT}_{C,B} = k\\coord{T}_{C,B}$.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{proposition}\n", "meta": {"hexsha": "fcc1d2d8579f345dc9ea1a3cc1bf50278da68ca3", "size": 13096, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/LinearTransformationsGeneral-Matrix.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/LinearTransformationsGeneral-Matrix.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/LinearTransformationsGeneral-Matrix.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 40.2953846154, "max_line_length": 114, "alphanum_fraction": 0.6075137447, "num_tokens": 5129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8774767778695834, "lm_q1q2_score": 0.7234461946330629}}
{"text": "\\section{Common Families of Distributions}\n\n\\subsection{Exercise 1}\n\\begin{align*}\n        \\mathrm{E} [X] &= \\sum_{i = N_0}^{N_1} \\frac{i}{N_1 - N_0 + 1} = \\frac{1}{N_1 - N_0 + 1} (\\sum_{i = 1}^{N_1} i - \\sum_{i = 1}^{N_0 - 1} i) = \\frac{N_1 + N_0}{2} \\\\\n        \\mathrm{E} [X^2] &= \\frac{1}{N_1 - N_0 + 1} (\\sum_{i = 1}^{N_1} i^2 - \\sum_{i = 1}^{N_0 - 1} i^2) = \\frac{2N_0^2 + 2N_0N_1 - N_0 +2N_1^2 + N_1}{6} \\\\\n        \\mathrm{Var} [X] &= \\mathrm{E} [X^2] - \\mathrm{E} [X]^2 = \\frac{(N_1 - N_0 + 1)^2 - 1}{12} \n\\end{align*}\n\n\\subsection{Exercise 2}\n(a) Suppose the number of defective parts in the lot is $D$. The likelihood that we accept a sample from such\na lot is $P(X = 0)$, where $X$ is distributed according to $\\text{Hypergeom}(100, D, K)$. \nGiven that a lot is unacceptable if $D > 5$, we need only consider the case where $D = 6$, since larger $D$ \nlead to lower likelihood of being incorrectly accepted. Thus, we solve\n\\begin{align*}\n        \\frac{\\binom{94}{K}}{\\binom{100}{K}} < 0.1 \n\\end{align*}\nby running the following Python code:\n\\begin{lstlisting}[language=python]\n  from scipy import special\n\n  K = 1\n  while special.binom(94, K) / special.binom(100, K) > 0.1:\n    K += 1\n\\end{lstlisting}\nto get that $K = 32$.\n\n(b) This is the same as part (a) except that we now have to consider $P(X = 0) + P(X = 1) < 0.1$. Slightly\nmodifying the Python code above yields $K = 51$.\n\n\\subsection{Exercise 3}\nAt each second, the probability that at least one car passes in the next 3 seconds is $1 - P(X = 0)$, where\n$X$ is binomial with $n = 3$ and $p = p$. Thus, the probability that the pedestrian has to wait 4 seconds\nbefore starting to cross is the probability that at least one car passes in the first three seconds multiplied \nby the probabilities that a car crosses at the 4th second and that no cars cross during seconds 5-7. This\nprobability is $(1 - (1 - p)^3) p (1 - p)^3$.\n\n\\textbf{NOTE:} I compared my answer to the actual solutions, but I don't buy that the actual\nanswer is $(1 - p (1 - p)^3) (1 - p)^3$ based on the logic provided. What if cars pass on the first and second\nseconds, but then no cars pass after? The pedestrian could then leave after two seconds.\n\n\\subsection{Exercise 4}\n(a) If unsuccessful keys are not eliminated, then this is the same as asking for the expectation of a \ngeometric random variable with $p = \\frac{1}{n}$, so we expect that it will take $n$ trials.\n\n(b) If we eliminate unsuccessful keys, then our expectation looks like  \n\\begin{align*}\n        \\mathrm{E} [X] &= \\frac{1}{n} + 2 * \\frac{n - 1}{n} * \\frac{1}{n - 1} + ... \\\\\n                       &= \\frac{1}{n} \\sum_{i = 1}^n i = \\frac{n + 1}{2}\n\\end{align*}\n\n\\subsection{Exercise 5}\nThe standard drug's effectiveness can be modeled as a binomial distribution with $n = 100$ and $p = 0.8$, since\nwe are given that the drug is expected to be effective in 80 out of 100 cases. Computing $P(X \\geq 85)$ yields\na value of approximately 0.129, which means that it is fairly unlikely for the new drug to work in 85\n(or more) cases if it was worse than the first drug. Thus, we conclude that the new drug is superior.\n\n\\subsection{Exercise 7}\nWe would like to have $P(X \\geq 2) = 1 - P(X < 2) > 0.99$. Thus, we can solve \n$e^{-\\lambda} (1 + \\lambda) < 0.01$ to get that $\\lambda > 6.638$.\n\n\\subsection{Exercise 12}\nI tried to do this analytically but struggled to show equivalence between the summations; obtaining the result\nthrough qualitative reasoning is much simpler. $F_X(r - 1)$ is the probability that there are at most $r - 1$\nsuccesses in $n$ Bernoulli trials, which is the same as saying that we get success number $r$ after $n$ trials.\nThus, we must have at least $n + 1 - r$ failures, which is $1 - F_Y(n - r)$ (I don't deserve credit for this,\nI looked up part of the solution here - maybe I'll retry the analytic approach later).\n\n\\subsection{Exercise 15}\nI spent an absurd amount of time on this question because I was working off of Wikipedia's provided negative\nbinomial MGF, which treats $p$ as $1 - p$. After finding the proper MGF, the result is straightforward: \n\\begin{align*}\n        \\lim_{r \\to \\infty} \\bigg(\\frac{p}{1 - (1 - p)e^t}\\bigg)^r &= \n        \\lim_{r \\to \\infty}\\bigg(1 + \\frac{p}{1 - (1 - p)e^t} - \\frac{1 - (1 - p)e^t}{1 - (1 - p)e^t}\\bigg)^r \\\\\n                                                                   &= \\lim_{r \\to \\infty} \\bigg(1 + \\frac{r\\frac{-(1 - p) + (1 - p)e^t}{1 - (1 - p)e^t}}{r}\\bigg)^r \\\\\n                                                                   &= \\exp(-\\lambda + \\lambda e^t)\n\\end{align*}\n\n\\subsection{Exercise 19}\nSince $\\alpha = 1, 2, 3, ...$ we have $\\Gamma(\\alpha) = (\\alpha - 1)!$. We can then integrate by parts with \n$u = \\frac{1}{(\\alpha - 1)!} z^{\\alpha - 1}$ and $dv = e^{-z}$ to get\n\\begin{align*}\n        \\int_{x}^{\\infty} \\frac{1}{(\\alpha - 1)!} z^{\\alpha - 1} e^{-z} dz &= \\frac{x^{\\alpha - 1} e^{-x}}{(\\alpha - 1)!} + \\int_{x}^{\\infty} \\frac{1}{(\\alpha - 2)!} z^{\\alpha - 2} e^{-z} dz \\\\\n                                                                           &= \\sum_{y = 0}^{\\alpha - 1} \\frac{x^y e^{-x}}{y!}\n\\end{align*}\nwhere the last line follows from repeatedly integrating by parts until $z^{\\alpha - k} = 0$. Probabilistically,\nthis equality gives that $P(X \\geq x) = P(Y \\leq \\alpha - 1)$ where $X$ is Gamma distributed with \n $\\alpha = \\alpha, \\beta = 1$ and $Y$ is Poisson with $\\lambda = x$.\n\n\\subsection{Exercise 44}\nDirectly applying Chebychev to $P(\\abs{X} \\geq b)$ gives $P(\\abs{X} \\geq b) \\leq \\frac{\\mathrm{E}[\\abs{X}]}{b}$.\nFurthermore, since $P(\\abs{X} \\geq b) = P(X^2 \\geq b^2)$, we can apply Chebychev again to get\n$P(\\abs{X} \\geq b) \\leq \\frac{\\mathrm{E} [X^2]}{b^2}$. Both $\\mathrm{E} [\\abs{X}]$ and $\\mathrm{E} [X^2]$ \ncan be computed via integration by parts as 1 and 2 respectively. Thus, for $b = 3$ the $X^2$ bound is\nbetter and for  $b = \\sqrt{2}$ the $\\abs{X}$ bound is better.\n\n\\subsection{Exercise 45}\n(a)\n\\begin{align*}\n        M_X(t) &= \\int_{-\\infty}^{\\infty} e^{tx} f_X(x) dx \\\\ \n               &\\geq e^{at} \\int_{x \\geq a} f_X(x) dx \\quad \\text{since } e^{xt} \\geq e^{at} \\text{ for } x \\geq a, t \\geq 0 \\\\\n               &\\geq e^{at} P(X \\geq a)\n\\end{align*}\n\n(b) Identical to (a), except we use  $x \\leq a$ in step 2 since $t < 0$.\n\n(c) We just need $h(t, x)$ to be nonnegative and $h(t, x) \\geq 1$ for all $x, t \\geq 0$, since then we can\nreplicate the steps of (a).\n\n", "meta": {"hexsha": "10c7b8c7f4f6dc9b2b800edfe04eac136c1dcaf2", "size": 6405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Stat_Inference_Casella_Berger/chapter_3.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "Stat_Inference_Casella_Berger/chapter_3.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Stat_Inference_Casella_Berger/chapter_3.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.2272727273, "max_line_length": 193, "alphanum_fraction": 0.612802498, "num_tokens": 2237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619134371953, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.723446184599885}}
{"text": "\\documentclass[12pt, letterpaper]{article}\n\\usepackage[fleqn]{amsmath}\n\\begin{document}\n\\section{Equations of motion}\n\\begin{equation} m \\dot{v} + bv = F(t) \\end{equation}\n\\begin{equation} \\dot{x} = v \\end{equation}\n\n\\section{Define state variables}\n\\begin{equation} x_{1} = x \\end{equation}\n\\begin{equation} x_{2} = \\dot{x} = v \\end{equation}\n\\begin{equation} \\dot{x_{1}} = x_{2} \\end{equation}\n\\begin{equation} \\dot{x_{2}} = \\dot{v} = \\frac{F(t)}{m} - \\frac{bx_{2}}{m} \\end{equation}\n\\begin{equation} y = x_{1} \\end{equation}\n\\begin{equation} u = F(t)\\end{equation}\n\n\\section{State space form}\n\\begin{equation}\n\\begin{bmatrix} \\dot{x_{1}} \\\\ \\dot{x_{2}} \\end{bmatrix} \n= \n\\begin{bmatrix} 0 & 1 \\\\ 0 & -\\frac{b}{m} \\end{bmatrix} \n\\begin{bmatrix} x_{1}\\\\ x_{2} \\end{bmatrix} \n+ \n\\begin{bmatrix} 0\\\\ \\frac{1}{m} \\end{bmatrix}u\n\\end{equation}\n\n\\begin{equation} y = \\begin{bmatrix} 1 & 0 \\end{bmatrix} \\begin{bmatrix} x_{1} \\\\ x_{2} \\end{bmatrix} + \\begin{bmatrix} 0 \\end{bmatrix}u\n\\end{equation}\n\n\\end{document}", "meta": {"hexsha": "06391bc498cff996dacd3a3ebd9adc28d4f2cc69", "size": 1009, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "kalman_filter/writeup/state_space_equation.tex", "max_stars_repo_name": "ryan-dd/autonomous-systems", "max_stars_repo_head_hexsha": "39fa1394e6b9577600e52d9b7ecd9184a1c90ce1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "kalman_filter/writeup/state_space_equation.tex", "max_issues_repo_name": "ryan-dd/autonomous-systems", "max_issues_repo_head_hexsha": "39fa1394e6b9577600e52d9b7ecd9184a1c90ce1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "kalman_filter/writeup/state_space_equation.tex", "max_forks_repo_name": "ryan-dd/autonomous-systems", "max_forks_repo_head_hexsha": "39fa1394e6b9577600e52d9b7ecd9184a1c90ce1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.7931034483, "max_line_length": 136, "alphanum_fraction": 0.6551040634, "num_tokens": 426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.7232780134832577}}
{"text": "\\chapter{THE LEXIMIN METHOD} \\label{ch:algorithm}% Must have a blank line after every section label\n\n\\epigraph{Young man, in mathematics you don't understand things. You just get used to them.}{John von Neumann}\n\n\\noindent In this chapter, I describe the leximin method for hierarchical community detection. It relates a common problem in traffic engineering to the problem of community detection and finds communities in a divisive, hierarchical way. By maximizing all-pairs concurrent flow on the graph in an iterative process, edges become saturated with flow. At each level, these edges separate the graph into two or more parts. Flat clusters can be extracted based on some objective function; we select the clustering which maximizes modularity.\n\nI define \\say{leximin} and explain its connection to this problem. Next, I explain how the method identifies sparsest cuts to form a community structure. After defining the method, I illustrate the differences from the related MCF cut algorithm~\\cite{mann2008extensions}. Finally, I give the computational complexity of the method as essentially $O(N^{11})$ in terms of the number of nodes $N$ and provide remarks to guide a practical implementation.\n\n\n\n\\section{Introduction}\n\nThe leximin method works to find cuts in the graph that separate it into well-connected subgraphs. The intuition of the method is a progressive filling process on a network of pipes~\\cite{le2005rate}. \n\n\\begin{method}{Progressive Filling~\\cite{le2005rate}}\n\nBegin with all rates equal to zero. Grow all rates at the same pace (or at a pace proportional to demand, when demand is not unity). Continue until one or more edges is saturated. These are the bottlenecks, or critical edges. The rates for demand pairs that use these links are now fixed: They do not increase anymore. Rates between other demand pairs continues to increase until a new bottleneck is found, and so on until the entire graph is saturated---all demand pairs have found a bottleneck. The process terminates because all edge capacities are finite and the graph is finite. The resulting allocation is max-min fair and unique~\\cite{le2005rate}.\n\\end{method}\n\nMatula first introduced the leximin method for community detection in 1985~\\cite{matula1985divisive}. It rests on a hierarchical version of the maximum concurrent flow problem (MCFP) that was independently rediscovered nearly twenty years later by Nace and Doan in 2003~\\cite{nace2003some}. In 2004, Allalouf and Shavitt made explicit the MCFP with non-unit demand which Matula identified in 1985 and Nace and Doan say is \\say{easily generalized} from their model~\\cite{allalouf2004maximum}. Much work has also built on Matula's MCFP, examining the simpler case that flow follows a fixed path or set of paths~\\cite{pioro2003efficient, nace2003some, nace2006tutorial}.\n\nThe MCFP finds a fair allocation of flow between all pairs---that is, an allocation that is maximin maximal. When maximizing throughput between all pairs, a set of \\emph{critical edges} will become fully saturated, corresponding to the idea of \\emph{breakdown} in traffic theory: \\say{the onset of congested traffic in an initial free traffic flow}~\\cite{kerner2009traffic}. Because of these bottlenecks, there is residual capacity that can be utilized. The hierarchical MCFP (sometimes \\say{lexicographically maximum concurrent flow problem}) utilizes that residual capacity to produce a max-min fair allocation---a leximin maximal satisfaction of demand.\n\nThe remainder of this chapter is structured as follows. In \\autoref{sec:leximin_meaning}, we define \\emph{leximin} as it pertains to flow networks. In \\autoref{sec:sparsest cut}, we define sparsest cuts and show how they create a canonical hierarchical decomposition. In \\autoref{sec:leximin algorithm}, we discuss the hierarchical maximum concurrent flow problem and how it is used to determine sparsest cuts and grids. \\autoref{sec:differences} outlines the differences between the leximin method and the related MCF cut algorithm. Finally, in \\autoref{sec:complexity and size}, we opine on the complexity, implementation, and practical limits of the algorithm.\n\n\n\n\n\n\n\\section{Leximin fairness} \\label{sec:leximin_meaning}\n\nThe leximin method is so named because it identifies a lexicographic maximin (i.e.\\ leximin) satisfaction of demand. A \\emph{maximin} process is one that \\emph{max}imizes the \\emph{min}imum utility. For our purposes, utility and throughput are synonymous. A maximin flow allocation is one that has the highest minimum throughput. This is what the MCFP identifies. \\emph{Lexicographic ordering} is a generalization of familiar alphabetic ordering: words are ordered by their first position, then their second, and so on. Lexicographic maximin extends the idea of maximin to multiple levels: we maximize the minimum utility, then for those who are not yet constrained, we maximize \\emph{their} minimum utility, and so on. Economists have adopted the shorthand \\say{leximin} because it is more economical in its number of syllables.\n\nThe leximin satisfaction of demand has a desirable property in traffic networks because it enforces \\say{max-min fairness}. Bertsekas et al.~\\cite{bertsekas1992data} discuss the idea of max-min fairness: that no pair's allocation can increase without reducing allocation to a pair with equal or lesser allocation. More casually, no-one can be made better off without taking from someone as well off or worse off. This is the same idea as leximin, and it is often an objective in bandwidth allocation for computer networks. Solving the hierarchical MCFP is a polynomial-time method for identifying such an allocation.\n\n\n\n\n\n\n\n\\section{The Sparsest Cut} \\label{sec:sparsest cut}\n\nOn an unweighted graph (one with unit capacity on each edge), the sparsest cut is the minimal set of edges, with respect to the potential edges that could exist between the subgraphs it separates. In the case that an edge set~$\\hat{E}$ cuts a graph into two parts~$A$ and~$\\overline{A}$, the cut density is:\n\n$$\\frac{|\\hat{E}|}{|A| \\cdot |\\overline{A}|}$$\n\nThe sparsest cut is the edge set~$\\hat{E}$ that minimizes this value. Sometimes multiple cuts exist at a single level of throughput. Beyond the two-part case, the reader is referred to Mann~\\cite{mann2008extensions, mann2008sparsest}. The edges that are not in $\\hat{E}$ are non-critical. As there exists residual capacity on these edges after saturating the sparsest cut, the level of throughput can be raised on these edges. The pipes can keep being filled.\n\n\n\n\\subsection{The Sparsest Cut Hierarchy}\n\nBeginning from the level of flow that saturated our sparsest cut, we keep filling the pipes, raising throughput. All the water already in the pipes is still there, eating up capacity. We approach a next-level bottleneck, and a next, until the entire network is partitioned into single nodes. Importantly, solving the hierarchical MCFP yields a unique dendrogram. The throughput continues to increase for each subproblem. Since the set of critical edges is canonical at every level, the dendrogram is canonical. The complication is in the case of ties, which cause \\emph{degenerate cuts}: cuts at the same throughput value.\n\nWhile a sparsest cut at a given throughput level~$z_i$ is not always unique, it is unique as long as there is no \\emph{tie}, which is discussed in \\autoref{ch:robustness}. When a tie occurs, the set of sparsest cuts is unique, and they will each be identified at the same throughput level~$z_i$. This guarantees a unique dendrogram, even in the face of ties.\n\n\nIn the following section, we discuss how the leximin method uses the hierarchical MCFP to find sparsest cuts and yield the dendrogram.\n\n\n\n\n\n\n\\section{The Leximin Method for Community Detection} \\label{sec:leximin algorithm}\n\nThis algorithm identifies communities by identifying sparsest cuts in the graph. To find hierarchical structure, this can be repeated until the graph is decomposed into singletons. A flat structure can be extracted that maximizes some measure of community quality, such as stability of clusters~\\cite{mcinnes2017hdbscan} or modularity~\\cite{newman2006modularity}. Some of these measures allow early stopping, rather than generating the entire top-down structure. Identifying sparsest cuts is NP-hard~\\cite{shahrokhi1990maximum, matula1990sparsest}, but the maximum concurrent flow problem (MCFP) can identify a class of sparsest cuts (\\say{bottlenecks}) in polynomial time~\\cite{matula1990sparsest}. \n\n\n\n\n\\subsection{The MCFP and hierarchical MCFP}\n\nThe MCFP is a multicommodity flow problem with demand between all pairs of nodes in the network~\\cite{matula1985concurrent}. The MCFP maximizes \\emph{concurrent} flow: flow is supplied between all pairs in proportion to the demand between them. With unit demand, this means that flow between all pairs must be equal. The ratio of supplied flow to demand is called \\emph{throughput} or \\emph{satisfaction ratio}, and it must be the same between all pairs. The MCFP maximizes this throughput under the constraints of capacity on the edges.\n\nA problem instance is represented by the tuple $\\left< G, c, d \\right>$ where $G = (V, E)$ is a graph, $c$ is a function $c\\colon \\{i, j\\}  \\rightarrow c_e \\  \\forall \\{i, j\\} \\in E$ which provides the capacity of each edge, and $d$ is a function $d\\colon \\{i, j\\}  \\rightarrow d_{ij} \\  \\forall \\{i, j\\} \\in D$ which defines the demand between all pairs. ($D \\subseteq V \\times V$~is the set of node pairs with demand between them.) The standard formulation assumes unit capacity on each edge and unit demand between all pairs.\n\nThere exist multiple possible LP representations of the MCFP. While more compact, efficient methods have emerged, the edge--path formulation is the conceptually simplest:\n\\begin{align}\n    \\max z(G, c, d)  & && \\text{throughput} \\nonumber\\\\\n    \\mathrm{s.t.} \\sum_{p \\in P_{ij}} f_p &= zd_{ij} \\forall \\{i, j\\} \\in D && \\text{fairness constraint} \\nonumber\\\\\n    \\sum_{\\{p \\in P:\\{i,j\\} \\in E_p\\}} f_p &\\leq c_{ij} \\forall \\{i, j\\} \\in E && \\text{capacity constraint} \\nonumber\\\\\n    f_p &\\geq 0,  p \\in P && \\text{non-negativity of flow} \\label{eq:mcfp}\n\\end{align}\nWe seek to maximize the concurrent throughput~$z$. Our first constraint enforces proportional maximization: the proportion of demand satisfied is the same for all pairs. The throughput~$z$ is  the sum of flows~$f_p$ for every path~$p$ in the set of paths~$P_{i, j}$ between nodes~$i$ and~$j$ (i.e. the total satisfied demand between~$i$ and~$j$).\n\n\\subsection{Formulation of the Leximin Method by Linear Programming}\n\nIn the hierarchical form, we maximize not just concurrent flow, but lexicographic concurrent flow. Residual capacity is not wasted. Instead, we use it to raise throughput for demand pairs that have not been constrained. We do this by solving a new LP for each throughput level, depending on the previous LPs: \n\n\\begin{align}\n    \\max z_n(G, c, d)  & && \\text{throughput} \\nonumber\\\\\n    \\mathrm{s.t.} \\sum_{p \\in P_{ij}} f_p &= z d_{ij} \\forall \\{i, j\\} \\in D_n && \\text{fairness constraint} \\nonumber\\\\\n    \\mathrm{s.t.} \\sum_{p \\in P_{ij}} f_p &= z_l d_{ij} \\forall \\{i, j\\} \\in D_l, l = 1,\\ldots,D_{n-1} && \\text{lower levels constraint} \\nonumber\\\\\n%    \\sum_{\\{p \\in P:\\{i,j\\} \\in E_p\\}} f_p &\\leq c_{ij} \\forall \\{i, j\\} \\in E \\setminus \\mathit{crit}_n && \\text{free capacity constraint} \\nonumber\\\\\n    \\sum_{\\{p \\in P:\\{i,j\\} \\in E_p\\}} f_p &\\leq c_{ij} \\forall \\{i, j\\} \\in E && \\text{capacity constraint} \\nonumber\\\\\n    f_p &\\geq 0,  p \\in P && \\text{non-negativity of flow} \\label{eq:mcfp}\n\\end{align}\n\n%\\todo{Please check the formula before I send it to the committee.} \nHere, $z_l$ is a constant: the throughput of the $l$th subproblem, which was identified previously. $D_n$ identifies the subset of demand pairs that has not yet been saturated in subproblem $n$, and $D_l$ is the set of edges saturated in subproblem $l$. Some capacity has been utilized to achieve the previous level of throughput. Discounting that from the network's capacity \\say{leaves the water in the pipes}, so we find a next solution building from there. We also no longer seek to further maximize demand between pairs that have already been constrained by a bottleneck. Because there is a bottleneck separating those pairs, they could not be maximized anyway.\n\n\n\\subsection{Determining the Sparsest Cut from the Hierarchical MCFP}\n\nThere is a unique set of critical edges saturated to capacity by every optimal assignment of flows, and removing these critical edges partitions the graph into two or more components~\\cite{matula1985concurrent}. The remaining edges are non-critical, and their residual capacity can be used to improve throughput for the remainder of the graph. This creates a new set of critical edges and a new division.\n\nSometimes, the entire edge set of a subgraph bounded by cuts is saturated. This is a phenomenon called \\emph{gridlock}, which is particular to maximizing concurrent flow. The subgraph is sufficiently homogeneous that there is no need to further dissect it and identify further community structure. The gridlock phenomenon is explored in \\autoref{ch:random}.\n\n\\subsection{Main Steps of the Leximin Method}\n\nThe following steps are the iterative procedure to identify hierarchical community structure by identifying a leximin allocation of concurrent flow.\n\n\\begin{algorithm}\n\t\\caption{Leximin clustering method}\n\t\\label{alg:hmcfp-cc}\n\t\t\\KwData{A graph $G = (V, E)$, edge capacities $c$, demand pairs $d$}\n\t\t\\KwResult{A clustering $\\mathcal{C}(G)$}\n\t\t$n \\longleftarrow 1$\\;\n\t\t\\While{$\\exists d \\in D$ not saturated} {\n\t\t    \\textbf{Solve the hierarchical MCFP subproblem} $P_n$\\;\n\t\t    Extract critical edges~$\\hat{E}_n$: those with nonzero shadow prices\\;\n\t\t    Reduce available capacity on edges by $z$\\;\n\t\t    $\\forall d \\in D_n$: $\\lambda_d \\longleftarrow z$ \\;\n\t\t    $i \\longleftarrow n + 1$\\;\n\t\t}\n\t\tThe final assignment of flows is max-min fair, and the satisfied demand is leximin maximal. The critical edges and their corresponding throughputs $z_i$ define a hierarchical structure of cuts.\n\t\t\\vspace{0.25cm}\n\\end{algorithm}\n\nThe final consideration in constructing the dendrogram is the height at which each community should be merged. This height is called the \\emph{cophenetic distance}~\\cite{sokal1962comparison}. In this method, arbitrarily broken ties are reconciled by using throughput~$z$ as the cophenetic distance, rather than simply the number of divisions that have occurred to this point. This means that the ties (explored in \\autoref{ch:robustness}) are reconciled as a multiway split at the same height, rather than remaining arbitrarily broken. \n\n\n\n\n\n\\section{Differences from the MCF Cut Algorithm} \\label{sec:differences}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.6\\textwidth]{fig/Paw3}\n\\caption{The paw graph}\n\\label{fig:paw3}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.6\\textwidth]{fig/level1}\n\\caption{The first cut of the paw graph by the leximin algorithm. Green lines indicate paths of flow to fairly maximize minimum throughput. The red line indicates the cut.}\n\\label{fig:level1}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.6\\textwidth]{fig/MCF_level2}\n\\caption{The subproblems for the MCF cut algorithm after its first cut: $K_3$ and a singleton}\n\\label{fig:MCF_level2}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.4\\textwidth]{fig/dendrogram_4_tie}\n\\caption{The dendrogram produced by the MCF cut algorithm on the paw graph}\n\\label{fig:MCF_dendrogram}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.6\\textwidth]{fig/level2}\n\\caption{The second cut of the paw graph by the leximin algorithm. Green lines indicate paths of flow to fairly maximize minimum throughput. Red lines indicate cuts. Lighter colors represent fixed flow and previous cuts.}\n\\label{fig:level2}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.6\\textwidth]{fig/level3}\n\\caption{The third and final cut of the paw graph by the leximin method. The decision to cut $\\{2, 3\\}$ again instead of $\\{1, 3\\}$ is arbitrary.}\n\\label{fig:level3}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.4\\textwidth]{fig/dendrogram_4_cascade}\n\\caption{The dendrogram produced by the leximin method on the paw graph}\n\\label{fig:leximin_dendrogram}\n\\end{figure}\n\nThe MCF cut algorithm is a similar technique to the leximin method which takes a divide-and-conquer approach~\\cite{mann2008extensions}. It solves the MCFP on the network, then splits the network into components to process separately. This amounts to progressive filling up to the first bottleneck, then blocking the saturated pipes, draining the sections on each side, and starting anew on each side of the bottleneck. The components separated by the cut are re-solved independently of one another. This makes each subproblem smaller, but yields a different sequence of cuts and a different dendrogram.\n\nThe difference in behavior of the leximin and MCF Cut methods is best shown on a simple example. The paw graph is a graph formed by adding a fourth node to the complete graph $K_3$ and joining it to one of the existing vertices by an edge, as shown in \\autoref{fig:paw3}.\n\nThe operation of the two algorithms begins identically; they differ in their treatment of subsequent steps. First, they progressively fill the network until an edge is saturated. Because this is the first iteration, there are no prior capacity usages in the leximin's hierarchical MCFP. This makes it equivalent to the MCFP solved in the MCF cut algorithm. \\autoref{fig:level1} shows that the edge $\\{3, 4\\}$ (the \\say{tail} of the paw graph) is saturated first, when there is $1/3$~unit of flow between all pairs. This edge is identified as critical. This is where the behavior deviates.\n\nThe MCF cut algorithm separates this graph into two subproblems: a triangle ($K_3$) and a singleton, as shown in \\autoref{fig:MCF_level2}. When processing the triangle, we start from an initial state of no flow. Although the edge $\\{1, 2\\}$ had the least flow on it at the end of the first step, it is on equal footing with the other two edges of the triangle. The dendrogram for this method is then shown in \\autoref{fig:MCF_dendrogram}.\n\n\n\nIn contrast to the MCF cut method, the leximin method does not remove flow already present in the network due to previous iterations. The starting point for the second iteration is shown in \\autoref{fig:level2} as the lighter-colored lines. The flow required to saturate a new set of critical edges is shown in darker green. Here, there is an unambiguous next cut. The final edge is cut in \\autoref{fig:level3}, which gives the final dendrogram: \\autoref{fig:leximin_dendrogram}.\n\nBecause there is no clear definition of a community---and much less, a hierarchical communty---it is unclear which of these results is preferable. The leximin method has a clearer real-world significance, though: it partitions the graph based on the load applied to the graph. Further, the leximin method has desirable theoretical properties discussed in \\autoref{ch:robustness}.\n\n\n\\section{Complexity and Size Considerations} \\label{sec:complexity and size}\n\n%The leximin algorithm is dramatically slower than competing algorithms, which can process networks with tens and hundreds of millions of nodes. The bulk of the mathematical effort  is solving the hierarchical MCFP. Proposals to increase this step's efficiency have been proposed. Dong et al.\\ present the \\say{triples} formulation of the MCFP, which drastically reduces the number of variables over the edge--path formulation, while also reducing the number of constraints~\\cite{dong2015compact}.  Nevertheless, a dense network of 160 nodes can take an hour to process on current hardware. \n\nSolving a linear program is a polynomial-time technique, when inputs are algebraic numbers~\\cite{adler1992polynomial}. The fastest known LP method has complexity $$O\\left(\\frac{n^3}{\\log n}L\\right)$$ where $n$ is the number of variables in the standard form of the LP and $L$ is the information length of the LP, which grows with the product of the number of variables and constraints~\\cite{anstreicher1999linear}. In the efficient \\say{triples} formulation of the MCFP, there are $O(mN)$ variables and $O(N^2)$ constraints. \n\nSince real-world networks have sparse connectivity~\\cite{chakrabarti2006graph}, we can restrict our focus to these. Even on sparse graphs, solving an LP will take essentially $O(N^{10})$ time relative to the number of nodes in the graph. Given that up to $(N-1)$ LPs will be solved (one for each level of the hierarchy~\\cite{nace2003some}), this amounts to a complexity of near $O(N^{11})$. The next slowest options are Walktrap ($O(N^{3.2})$) and Girvan--Newman ($O(N^3)$ on sparse graphs). \n\n\\subsection{Practical Considerations for Implementation}\nThe edge--path form of the MCFP involves an exponential number of variables, which is untenable. Fortunately, more efficient representations have emerged. An implementer should prefer the triples formulation of the MCFP~\\cite{dong2015compact}, which is easily extended to the hierarchical case. This method has a polynomial number of variables and constraints, yielding a tractable linear program in the complexity class P\\@. Work to expedite handling degenerate cuts has also been done~\\cite{danna2012practical}. The details of such a method, as well as its implementation, are out of the scope of this work.\n\nAdditionally, the method should only be applied to graphs of up to a few hundred nodes. On a sparse graph of 240 nodes, the runtime is measured in hours.\n\n%\\begin{algorithm}\n%\t\\caption{MCF cut algorithm~\\cite{mann2008extensions}}\n%\t\\label{alg:mcf_cut}\n%\t\t\\KwData{A graph $G = (V, E)$, edge capacities $c$, demand pairs $d$}\n%\t\t\\KwResult{A clustering $\\mathcal{C}(G)$}\n%\t\t$queue \\longleftarrow \\{G\\}$\n%\t\t\\While{$queue \\neq \\emptyset$}{\n%\t\t\t$H \\longleftarrow queue.dequeue()$\\;\n%\t\t\t\\textbf{Solve the MCFP on $H$}\\;\n%\t\t    Extract critical edges~$\\hat{E}_i$: those with nonzero shadow prices \\;\n%\t\t    \\Unless{Something}{\n%\t\t\t\\ForEach{component $H_j$ in $H$ cut by $\\hat{E}_i$}{\n%\t\t\t\t$queue.enqueue(H_j)$\\;\n%\t\t\t}}\n%\t\t}\n%\t\t\\vspace{0.25cm}\n%\\end{algorithm}\n", "meta": {"hexsha": "c0a7acf52b804c7e079fb35f5326c87b043e066a", "size": 22276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/algorithm.tex", "max_stars_repo_name": "aryamccarthy/thesis", "max_stars_repo_head_hexsha": "ef0e45e24e1cde26d3014d8da8cede559bbff5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "reports/algorithm.tex", "max_issues_repo_name": "aryamccarthy/thesis", "max_issues_repo_head_hexsha": "ef0e45e24e1cde26d3014d8da8cede559bbff5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "reports/algorithm.tex", "max_forks_repo_name": "aryamccarthy/thesis", "max_forks_repo_head_hexsha": "ef0e45e24e1cde26d3014d8da8cede559bbff5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 94.7914893617, "max_line_length": 829, "alphanum_fraction": 0.7746453582, "num_tokens": 5637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7232780070691807}}
{"text": "% chapter included in vclmanual.tex\n\\documentclass[vcl_manual.tex]{subfiles}\n\\begin{document}\n\n\\chapter{Mathematical functions}\\label{chap:MathematicalFunctions}\n\\flushleft\n\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & exponent \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Description & extracts the exponent part of a floating point number. The result is an integer vector.\\newline \nexponent(a) = floor(log2(abs(a))).\\newline\nThe value for a = 0 is implementation dependent \\\\ \\hline\n \\bfseries Efficiency & medium \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f a(1.0f, 2.0f, 3.0f, 4.0f);\nVec4i b = exponent(a);  // b = (0, 1, 1, 2)\n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & fraction \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Description & extracts the fraction part of a floating point number.\\newline\na = pow(2,exponent(a)) * fraction(a) \\newline\nThe value for a = 0, INF, or NAN is implementation dependent \\\\ \\hline\n\\bfseries Efficiency & medium \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f a(2.0f, 3.0f, 4.0f, 5.0f);\nVec4f b = fraction(a);  // b = (1.00f, 1.50f, 1.00f, 1.25f)\n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & exp2 \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Description & calculates integer powers of 2. The input is an integer vector, the output is a floating point vector. Overflow gives +INF, underflow gives zero. This function will never produce subnormals, and never raise exceptions \\\\ \\hline\n\\bfseries Efficiency & medium \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4i a(-1, 0, 1, 2);\nVec4f b = exp2(a);     // b = (0.5f, 1.0f, 2.0f, 4.0f)\n\\end{lstlisting}\n\\vspacebig\n\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & mul\\_add \\newline\nnmul\\_add \\newline\nmul\\_sub \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Description & mul\\_add(a,b,c) = a*b+c \\newline\nnmul\\_add(a,b,c) = -a*b+c \\newline\nmul\\_sub(a,b,c) = a*b-c \\newline\nThese functions use fused multiply-and-add (FMA) instructions if available. Some compilers use FMA instructions automatically for expressions like a*b+c. Use these functions for optimal performance on all compilers or to specify calculation order, etc. \\\\ \\hline\n\\bfseries Precision & The intermediate product a*b is calculated with infinite precision if the FMA instruction set is enabled. \\\\ \\hline\n\\bfseries Efficiency & good \\\\ \\hline\n\\end{tabular}\n\\vspacesmall\n\n\n\\section{Floating point categorization functions}\\label{FloatingPointCategorizationFunctions}\n\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & is\\_finite \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Description & returns a boolean vector with true for elements that are normal, subnormal or zero, false for INF and NAN \\\\ \\hline\n\\bfseries Efficiency & medium \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f  a( 0.0f, 1.0f, 2.0f, 3.0f);\nVec4f  b(-1.0f, 0.0f, 1.0f, 2.0f);\nVec4f  c = a / b;\nVec4fb d = is_finite(c);  // d = (true, false, true, true)\n\\end{lstlisting}\n\\vspacebig\n\n\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & is\\_inf \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Description & returns a boolean vector with true for elements that are +INF or -INF, false for all other values, including NAN \\\\ \\hline\n\\bfseries Efficiency & good \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f  a( 0.0f, 1.0f, 2.0f, 3.0f);\nVec4f  b(-1.0f, 0.0f, 1.0f, 2.0f);\nVec4f  c = a / b;\nVec4fb d = is_inf(c);  // d = (false, true, false, false)\n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & is\\_nan \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Description & returns a boolean vector with true for all types of NAN, false for all other values, including INF \\\\ \\hline\n\\bfseries Efficiency & good \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f  a(-1.0f, 0.0f, 1.0f, 2.0f);\nVec4f  b = sqrt(a);\nVec4fb c = is_nan(b);  // c = (true, false, false, false)\n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & is\\_subnormal \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Description & returns a boolean vector with true for subnormal (denormal) vector elements, false for normal numbers, INF and NAN \\\\ \\hline\n\\bfseries Efficiency & medium \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f  a(1.0f, 1.0E-10f, 1.0E-20f, 1.0E-30f);\nVec4f  b = a * a;           // b = (1.0f, 1.E-20f, 1.E-40f, 0.f)\nVec4fb c = is_subnormal(b); // c = (false,false,true,false)\n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & is\\_zero\\_or\\_subnormal \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Description & returns a boolean vector with true for zero and subnormal (denormal) vector elements, false for nonzero normal numbers, INF and NAN \\\\ \\hline\n\\bfseries Efficiency & good \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f  a(1.0f, 1.0E-10f, 1.0E-20f, 1.0E-30f);\nVec4f  b = a * a;           // b = (1.0f, 1.E-20f, 1.E-40f, 0.f)\nVec4fb c = is_zero_or_subnormal(b); // c = (false,false,true,true)\n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & infinite4f, infinite8f, infinite16f, \\newline\ninfinite2d, infinite4d, infinite8d \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Description & returns positive infinity \\\\ \\hline\n\\bfseries Efficiency & good \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f  a = infinite4f(); // a = (INF, INF, INF, INF)\n\\end{lstlisting}\n\\vspacebig\n\n\n\\label{nan4f}\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & nan4f(unsigned int n) \\newline\nnan8f(unsigned int n) \\newline\nnan16f(unsigned int n) \\newline\nnan2d(unsigned int n) \\newline\nnan4d(unsigned int n) \\newline\nnan8d(unsigned int n) \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Description & returns not-a-number (NAN). \\newline\nThe optional parameter n may be used for error tracing. \\newline\nThe maximum value of n is 0x003FFFFF.\nThis parameter can be retrieved later by the function nan\\_code (page \\pageref{nanCode}). \\\\ \\hline\n\\bfseries Efficiency & good \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f a = nan4f(); // a = (NAN, NAN, NAN, NAN)\n\\end{lstlisting}\n\\vspacesmall\n\n\n\\section{Floating point control word manipulation functions}\\label{FPControlWordManipulationFunctions}\n\nMXCSR is a control word that controls floating point exceptions, rounding mode and subnormal numbers. There is one MXCSR for each thread. \n\nThe MXCSR has the following bits:\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Bit index & \\bfseries meaning \\\\ \\hline\n0 & Invalid Operation Flag \\\\ \\hline\n1 & Denormal (subnormal) Flag \\\\ \\hline\n2 & Divide-by-Zero Flag \\\\ \\hline\n3 & Overflow Flag \\\\ \\hline\n4 & Underflow Flag \\\\ \\hline\n5 & Precision Flag \\\\ \\hline\n6 & Denormals (subnormals) Are Zeros \\\\ \\hline\n7 & Invalid Operation Mask \\\\ \\hline\n8 & Denormal (subnormal) Operation Mask \\\\ \\hline\n9 & Divide-by-Zero Mask \\\\ \\hline\n10 & Overflow Mask \\\\ \\hline\n11 & Underflow Mask \\\\ \\hline\n12 & Precision Mask \\\\ \\hline\n13-14 & Rounding control: \\newline\n00: round to nearest or even \\newline\n01: round down towards -infinity \\newline\n10: round up towards +infinity \\newline\n11: round towards zero (truncate) \\newline\nIf the rounding mode is temporarily changed then it must be set back to 00 for the vector class library to work correctly. \\\\ \\hline\n15 & Flush to Zero \\\\ \\hline\n\\end{tabular}\n\nPlease see programming manuals from Intel or AMD for further explanation.\n\n\n\\vspacebig\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & get\\_control\\_word \\\\ \\hline\n\\bfseries Description & reads the MXCSR control word \\\\ \\hline\n\\bfseries Efficiency & medium \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nint m = get_control_word();  // default value m = 0x1F80\n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & set\\_control\\_word(n) \\\\ \\hline\n\\bfseries Description & writes the MXCSR control word \\\\ \\hline\n\\bfseries Efficiency & medium \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:  \n// Enable overflow and divide by zero exceptions:\nset_control_word(0x1980); \n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & reset\\_control\\_word \\\\ \\hline\n\\bfseries Description & sets the MXCSR control word to the default value \\\\ \\hline\n\\bfseries Efficiency & medium \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nreset_control_word();\n\\end{lstlisting}\n\n\\label{noSubnormals}\n\\vspacesmall\n\\begin{tabular}{|p{25mm}|p{100mm}|}\n\\hline\n\\bfseries Function & no\\_subnormals \\\\ \\hline\n\\bfseries Description & Disables the use of subnormal (denormal) values. \\newline\nFloating point numbers with an absolute value below  \\newline\n1.18E-38 for single precision or 2.22E-308 for double precision are represented by subnormal numbers. The handling of subnormal numbers is extremely time-consuming on many CPUs. The no\\_subnormals function sets the \"denormals are zeros\" and \"flush to zero\" mode to avoid the use of subnormal numbers. It is recommended to call this function at the beginning of each thread in order to improve the speed of mathematical calculations if very low numbers are likely to occur. \\\\ \\hline\n\\bfseries Efficiency & medium \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nno_subnormals();\n\\end{lstlisting}\n\n\n\\section{Floating point mathematical functions}\\label{FPMathematicalFunctions}\n\nMathematical functions such as logarithms, exponential functions, power, trigonometric functions, etc. are available either as inline code or through external function libraries. These functions all take vectors as input and produce vectors as output.\n\\vspacesmall\n\n\nThe use of vector math functions is straightforward:\n\\begin{example}\n\\label{exampleSinFunction}\n\\end{example} % frame disappears if I put this after end lstlisting\n\\begin{lstlisting}[frame=single]\n#include <stdio.h>\n#include \"vectorclass.h\"\n#include \"vectormath_trig.h\"    // trigonometric functions\n\nint main() {\n    Vec4f a(0.0f, 0.5f, 1.0f, 1.5f);// define vector\n    Vec4f b = sin(a);               // sine function\n    // b = (0.0000f, 0.4794f, 0.8415f, 0.9975f)\n\n    // output results:\n    for (int i = 0; i < b.size(); i++) {\n        printf(\"%6.4f \", b[i]);\n    }\n    printf(\"\\n\");\n    return 0;\n}\n\n\\end{lstlisting}\n\\vspacesmall\n\n\\section{Inline mathematical functions}\\label{InlineMathematicalFunctions}\n\nThe inline mathematical functions are available by including the appropriate header file, e. g. vectormath\\_exp.h for powers, logarithms and exponential functions, and vectormath\\_trig.h for trigonometric functions. An advantage of the inline version is that the compiler can optimize the code across function calls, eliminate common sub-expressions, etc. The disadvantage is that you may get multiple instances of the same function taking up space in the code cache.\n\\vspacesmall\n\nThe speed of the inline functions is similar to or better than external vector function libraries in most cases and many times faster than standard (scalar) math function libraries. \nUnlike many other mathematical function libraries, this library does not use lookup tables. This gives better parallelism, a very small load on the data cache, and a more predictable execution time.\n\\vspacesmall\n\nThe precision is good. The calculation error is typically below 2 ULP (Unit in the Last Place = least significant bit) on the output. (The relative value of one ULP is $2^{-52}$ for double precision and $2^{-23}$ for single precision). Cases where the error can exceed 3 ULP are mentioned under the specific function.\n\\vspacesmall\n\nThe functions do not generate exceptions or set \\codei{errno} when an input is out of range. This would be inefficient and it would be problematic for the error handler to detect which vector element caused the error. Instead, the functions return INF (infinity) or NAN (not a number) in case of error. Generally, an overflow will produce INF. A negative overflow produces -INF. An underflow towards zero returns 0. Other errors produce NAN. An efficient way of detecting errors is to let the INF and NAN codes propagate through the calculations and detect the error at the end of a series of calculations as explained on page \\pageref{FloatingPointErrors}. It is possible to include an error code in a NAN and detect it with the function nan\\_code on page \\pageref{nanCode}.\n\\vspacesmall\n\nNote that many of the inline math functions do not support subnormal numbers. Subnormal numbers may be treated as zero by the logarithm, exponential, power and root functions. It is recommended to set the “denormals are zero” and “flush to zero” flags by calling the function \\codei{no\\_subnormals()} first (see page \\pageref{noSubnormals}). This may speed up some calculations and give more consistent results.\n\\vspacesmall\n\nA description of each mathematical function is given below.\n\\vspacesmall\n\n\n\\section{Using an external library for mathematical functions}\\label{ExternalMathLibrary}\n\nAs an alternative to the inline mathematical functions, you can use an external function library named Intel SVML (Short Vector Math Library).\n\\vspacesmall\n\nYou can use the Intel SVML library with any compiler. The SVML library is available for all platforms relevant to the vector class library. SVML is included with Intel C++ compilers, but it can be used with other compilers as well.\nThe performance of SVML will usually be good on both Intel and non-Intel processors, as long as you are not using the Intel compiler.\nAfter installing an Intel compiler, you can look for the file name: svml\\_dispmt.lib for Windows or libsvml.a for Linux. You also need the library libircmt.lib or libirc.a for a CPU dispatcher called by the svml library.\nYou also need the library svmlpatch.lib if compiling for 64-bit Windows. This library is provided in the folder svml\\_patch.\n\\vspacesmall\n\nLink the necessary library files into your C++ project. Be sure to choose the 32-bit version or 64-bit version of each library according to the platform you are compiling for.\n\\vspacesmall\n\nInclude the header file vectormath\\_lib.h instead of vectormath\\_exp.h, vectormath\\_trig.h, or vectormath\\_hyp.h if you want to use the SVML library. \nIt is not possible to mix the two kinds of mathematical functions (inline and library) in the same C++ file.\n\\vspacesmall\n\nThe available vector math functions are listed below. The efficiency is listed as poor because mathematical functions take more time to execute than most other functions, but they are still much faster than scalar alternatives. The details listed apply to the inline version. Details for the SVML library versions may be sought in the documentation for the specific library.\n\\vspacesmall\n\n\n\\section{Powers, exponential functions and logarithms}\\label{ExpLogFunctions}\n\n\\vspacesmall\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & pow(vector, vector), pow(vector, scalar) \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_exp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & pow(a,b) = $a^b$ \\newline \nSee also faster alternatives below for integer and rational powers. \\\\ \\hline\n\\bfseries Range & Subnormal numbers are treated as zero. The result is NAN if a is negative and b is not an integer. NAN's are always propagated by the inline version of pow, even in cases where the IEEE 754 standard specifies otherwise. The library version may fail to propagate NANs in the cases pow(NAN,0) and pow(1,NAN). \\\\ \\hline\n\\bfseries Precision & better than (0.8*abs(b)+2) ULP \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f a( 1.0f,  2.0f, 3.0f, 4.0f);\nVec4f b( 0.0f, -1.0f, 0.5f, 2.0f);\nVec4f c = pow(a, b);\n// c = (1.0000, 0.5000, 1.7321, 16.0000)\nVec4f d = pow(a, 2.4f);\n// d = (1.0000, 5.2780, 13.9666, 27.8576)\n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & pow(vector, int) \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & no extra header file required \\\\ \\hline\n\\bfseries Library version & not available \\\\ \\hline\n\\bfseries Description & see page \\pageref{powVectorInt} \\\\ \\hline\n\\bfseries Efficiency & medium \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f a(0.0f, 1.0f, 2.0f, 3.0f);\nint   b = 3;\nVec4f c = pow(a, b);  // c = (0.0f, 1.0f, 8.0f, 27.0f)\n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & pow\\_const(vector, const int) \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & no extra header file required \\\\ \\hline\n\\bfseries Library version & not available \\\\ \\hline\n\\bfseries Description & see page \\pageref{powConstVectorInt} \\\\ \\hline\n\\bfseries Efficiency & medium, often better than pow(vector, int) \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f a(0.0f, 1.0f, 2.0f, 3.0f);\nVec4f c = pow_const(a, 3);  // c = (0.0f, 1.0f, 8.0f, 27.0f)\n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & pow\\_ratio(vector x, const int a, const int b) \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_exp.h \\\\ \\hline\n\\bfseries Library version & not available \\\\ \\hline\n\\bfseries Description & Raises all elements of x to the rational power a/b.\\newline\na and b must be compile-time constant integers. \\\\ \\hline\n\\bfseries Range & x may be zero only if a and b are positive. x may be negative only if b is odd.\\newline\nThe range is the same as for cbrt (page \\pageref{cbrt}) if b is 3.\n The result when x is infinite may be NAN in some cases.\nSubnormal numbers are treated as zero in some cases.  \\\\ \\hline\n\\bfseries Precision & slightly imprecise for extreme values of \\codei{a} due to accumulating rounding errors. \nThe precision is similar to the cbrt function when b is 3 or 6. \\\\ \\hline\n\\bfseries Efficiency & Quite good for b = 1, 2, 4, or 8. Reasonable for b = 3 or 6. No better than pow for other values of b. \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f a(1.0f, 2.0f, 3.0f, 4.0f);\n// Reciprocal square root\nVec4f b = pow_ratio(a, -1, 2);  // c = (1.0, 0.707, 0.577, 0.500)\n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & exp \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_exp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & exponential function $e^x$ \\\\ \\hline\n\\bfseries Range & double: abs(x) \\textless 708.39. float: abs(x) \\textless 87.3 \\\\ \\hline\n\\bfseries Efficiency & Poor. The performance of the inline version for single precision vectors (Vec16f etc.) is better when the instruction set AVX512ER is supported. The performance can be improved further, at a slight loss of precision, when VCL\\_FASTEXP is defined in addition to AVX512ER. \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\n#include \"vectormath_exp.h\"\nVec16f a, b;\nb = exp(a);\n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & expm1 \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_exp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & $e^x-1$. Useful to avoid loss of precision if x is close to 0 \\\\ \\hline\n\\bfseries Range & double: abs(x) \\textless{} 708.39. float: abs(x) \\textless{} 87.3 \\\\ \\hline\n\\bfseries Efficiency & Poor. (not improved with AVX512ER) \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & exp2 \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_exp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & $2^x$ \\\\ \\hline\n\\bfseries Range & double: abs(x) \\textless{} 1020. float: abs(x) \\textless{} 27. \\\\ \\hline\n\\bfseries Efficiency & The performance of the inline version is good for single precision vectors if instruction set AVX512ER is supported. (VCL\\_FASTEXP is not needed). \\newline\nUse pow or pow\\_const instead if x is an integer. \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & exp10 \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_exp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & $10^x$ \\\\ \\hline\n\\bfseries Range & double: abs(x) \\textless{} 307.65. float: abs(x) \\textless{} 37.9. \\\\ \\hline\n\\bfseries Efficiency & Poor. The performance of the inline version for single precision vectors (Vec16f etc.) is better when the instruction set AVX512ER is supported. The performance can be improved further, at a slight loss of precision, when VCL\\_FASTEXP is defined in addition to AVX512ER. \\newline\nUse pow or pow\\_const instead if x is an integer. \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\n#define VCL_FASTEXP\n#include \"vectormath_exp.h\"\nVec16f a, b;\nb = exp10(a); \n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & log \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_exp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & natural logarithm \\\\ \\hline\n\\bfseries Range & The input must be a normal number. Subnormal numbers are treated as zero. \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & log1p \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_exp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & log(1+x) \\newline\nUseful to avoid loss of precision if x is close to 0 \\\\ \\hline\n\\bfseries Range & x \\textgreater{} -1 \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & log2 \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_exp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & logarithm base 2  \\\\ \\hline\n\\bfseries Range & The input must be a normal number. Subnormal numbers are treated as zero. \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & log10 \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_exp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & logarithm base 10  \\\\ \\hline\n\\bfseries Range & The input must be a normal number. Subnormal numbers are treated as zero. \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\\label{cbrt}\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & cbrt \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_exp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & cube root  \\\\ \\hline\n\\bfseries Range & float: 0, $\\pm 10^{-28} ..{}  10^{28}$ \\newline\n                  double: 0, $\\pm 10^{-200} ..{}  10^{200}$ \\newline\n                  The return value is 0 if abs(x) is too small \\\\ \\hline\n\\bfseries Precision & 5 ULP \\\\ \\hline                  \n\\bfseries Efficiency & Faster than pow \\\\ \\hline\n\\end{tabular}\n\n\\vspacebig\n\n\n\n\\section{Trigonometric functions and inverse trigonometric functions}\nAll angles are in radians.\n\n\n\\vspacesmall\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & sin \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_trig.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & sine function \\\\ \\hline\n\\bfseries Range & Defined for abs(x) \\textless{} $10^8$. 0 for big x \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f a(0.0f, 0.5f, 1.0f, 1.5f);// define vector\nVec4f b = sin(a);               // sine function\n// b = (0.0000f, 0.4794f, 0.8415f, 0.9975f)\n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & cos \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_trig.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & cosine function \\\\ \\hline\n\\bfseries Range & Defined for abs(x) \\textless{} $10^8$. 1 for big x \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & sincos \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_trig.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h (some platforms only) \\\\ \\hline\n\\bfseries Description & sine and cosine computed simultaneously.\\\\ \\hline\n\\bfseries Range & Defined for abs(x) \\textless{} $10^8$. 0 and 1 for big x \\\\ \\hline\n\\bfseries Efficiency & faster than computing sin and cos separately \\\\ \\hline\n\\end{tabular}\n\\begin{lstlisting}[frame=none]\n// Example:\nVec4f a(0.0f, 0.5f, 1.0f, 1.5f);\nVec4f s, c;\ns = sincos(&c, a);\n// s = (0.0000, 0.4794, 0.8415, 0.9975)\n// c = (1.0000, 0.8776, 0.5403, 0.0707)\n\\end{lstlisting}\n\n\n\\vspacesmall\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & tan \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_trig.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & tangent function \\\\ \\hline\n\\bfseries Range & Defined for abs(x) \\textless{} $10^7$. 0 for big x \\newline\ntan($\\pi/2$) will not produce infinity because the value of $\\pi/2$ cannot be represented exactly as a floating point number. The output will be big, though, when the input is as close to $\\pi/2$ as possible.\\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & asin \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_trig.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & inverse sine function \\\\ \\hline\n\\bfseries Range & -1 $\\leq$ x $\\leq$ 1 \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & acos \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_trig.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & inverse cosine function \\\\ \\hline\n\\bfseries Range & -1 $\\leq$ x $\\leq$ 1 \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & atan \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_trig.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & Inverse tangent \\\\ \\hline\n\\bfseries Range & Results between $-\\pi/2$ and $\\pi/2$ \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & atan2 \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_trig.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & Inverse tangent with two parameters, x and y, gives the angle to a point in the (x,y) plane \\\\ \\hline\n\\bfseries Range & Results between $-\\pi$ and $\\pi$ \\newline\nThe result of atan2(0,0) is 0 by convention\\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacesmall\n\n\n\\section{Hyperbolic functions and inverse hyperbolic functions}\\label{HyperbolicFunctions}\n\n\\vspacesmall\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & sinh \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_hyp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & hyperbolic sine \\\\ \\hline\n\\bfseries Range & double: abs(x) \\textless{} 709. float: abs(x) \\textless{} 88. \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & cosh \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_hyp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & hyperbolic cosine \\\\ \\hline\n\\bfseries Range & double: abs(x) \\textless{} 709. float: abs(x) \\textless{} 88. \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & tanh \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_hyp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & hyperbolic tangent \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & asinh \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_hyp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & inverse hyperbolic sine \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & acosh \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_hyp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & inverse hyperbolic cosine \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & atanh \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_hyp.h \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & inverse hyperbolic tangent \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacesmall\n\n\n\\section{Other mathematical functions}\\label{OtherMathematicalFunctions}\n\n\\vspacesmall\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & erf \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & not available \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & error function \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & erfc \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & not available \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & error function complement \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & erfinv \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & not available \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & inverse error function \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & cdfnorm \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & not available \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & cumulative normal distribution function \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & cdfnorminv \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & not available \\\\ \\hline\n\\bfseries Library version & vectormath\\_lib.h \\\\ \\hline\n\\bfseries Description & inverse cumulative normal distribution function \\\\ \\hline\n\\bfseries Efficiency & poor \\\\ \\hline\n\\end{tabular}\n\\vspacebig\n\n\\label{nanCode}\n\\begin{tabular}{|p{30mm}|p{120mm}|}\n\\hline\n\\bfseries Function & Vec4ui nan\\_code(Vec4f) \\newline\nVec8ui nan\\_code(Vec8f)\\newline\nVec16ui nan\\_code(Vec16f)\\newline\nVec2uq nan\\_code(Vec2d)\\newline\nVec4uq nan\\_code(Vec4d)\\newline\nVec8uq nan\\_code(Vec8d) \\\\ \\hline\n\\bfseries Defined for & all floating point vector classes \\\\ \\hline\n\\bfseries Inline version & vectormath\\_exp.h \\\\ \\hline\n\\bfseries Library version & not available \\\\ \\hline\n\\bfseries Description & Extracts an error code hidden as payload in a NAN. This code can be generated with the functions nan4f etc. (page \\pageref{nan4f}) and propagated through a series of calculations. When two NANs are combined (e.g. NAN1+NAN2), current processors propagate the first one. NANs produced by CPU instructions, such as 0./0. or sqrt(-1.) have a code of zero. NANs cannot propagate through integers and booleans.\\newline\nThe return value is (0x00400000 + code) for a quiet NAN.\nThe sign bit is ignored.\\newline\nThe return value is 0 for inputs that are not NAN. \\\\ \\hline\n\\bfseries Efficiency & medium \\\\ \\hline\n\\end{tabular}\n\\vspacesmall\n\n\n\\end{document}", "meta": {"hexsha": "5d609ac8c5a2419a312969091ed9e4b9f14ebda3", "size": 34974, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "vcl_mathematical_functions.tex", "max_stars_repo_name": "haferburg/manual", "max_stars_repo_head_hexsha": "c7b365e7a7bbd3c155ff85edf9c6084311b0c10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2019-08-05T13:15:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T03:17:29.000Z", "max_issues_repo_path": "vcl_mathematical_functions.tex", "max_issues_repo_name": "haferburg/manual", "max_issues_repo_head_hexsha": "c7b365e7a7bbd3c155ff85edf9c6084311b0c10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-08-03T05:13:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-03T05:13:02.000Z", "max_forks_repo_path": "vcl_mathematical_functions.tex", "max_forks_repo_name": "haferburg/manual", "max_forks_repo_head_hexsha": "c7b365e7a7bbd3c155ff85edf9c6084311b0c10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-08-08T08:28:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-02T08:39:06.000Z", "avg_line_length": 40.339100346, "max_line_length": 775, "alphanum_fraction": 0.7334877337, "num_tokens": 10748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942093072239, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.7232604403397785}}
{"text": "\\chapter{Graphics} \\label{Ch:Graphics}\n\n\\section{Ground Track Plotting}\n\nA ground track plot displays spherical latitude and longitude over a Poincare (unwrapped cylinder) projection of a body's surface geography. The algormithm used to generate a ground track plot ensures that line wrapping at the plot boundaries is handled correctly, and that when wrapping occurs, the plot is interpolated to the plot boundary.\n\nLongitude is computed by converting position and velocity of the object to the body fixed system of the ground track plot central body.  Define $x$, $y$, and $z$ as the body fixed coordinates of the object.   The longitude is calculated using\n%\n\\begin{equation}\n     \\lambda =  atan2(y,x)\n\\end{equation}\n%\nand the latitude is calculate using\n%\n\\begin{equation}\n     \\phi = asin{\\frac{z}{r}}\n\\end{equation}\n%\nwhere\n%\n\\begin{equation}\n    r = \\sqrt{x^2 + y^2 + z^2}\n\\end{equation}\n\nThere are three special cases to consider when plotting a new point on a ground track: (1) the new point wraps off the right-hand side of the plot, (2) the new point wraps off the left-had side of the plot, and (3) the new point does not wrap off either plot boundary.  When wrapping oocurs as in cases (1) and (2), the plot algorithm must perform  \"Pen Up\" and \"Pen Down\" commands to avoid connecting points on opposite ends of the plot with a spurious straight line.  Secondly, when wrapping occurs, the system must interpolate the line segments to plot boundaries. \n\nThe test to determine the case depends  upon whether the object is moving clockwise or counterclockwise in the body fixed system of the ground track plot central body.    The orbit direction is determined by evaluating the z component of orbit angular momentum expressed in the body fixed system.  Define a variable $d$ that is positive for clockwise motion in the body fixed system (the spacecraft is moving to the right on a ground track plot), and negative for counterclockwise motion. (spacecraft is moving to the left on  a ground track plot), and 0 for no motion.   The variable $d$ is computed as follows\n%\n\\begin{equation}\n   d = sign(x \\dot{y} - \\dot{x}y)\n\\end{equation}\n%\n%\n\\begin{equation}\n    m = \\frac{\\phi_i -\\phi_{i-1}}{\\lambda_i - \\lambda_{i-1}}\n\\end{equation}\n\n\\begin{center}\n\\begin{minipage}{6 in}\n\\begin{small}\n\\begin{algorithm}[H]\n\n    \\KwIn{$\\lambda_i,\\lambda_{i-1},\\phi_i,\\phi_{i-1},d_i,d_{i-1}$}\n    %\n    \\KwOut{Updated Ground Track Plot}\n    $m\\lambda_i^+ = mod(\\lambda_i,2 \\pi)$\\;\n    $m\\lambda_{i-1}^+ = mod(\\lambda_{i-1},2 \\pi)$\\;\n    $m\\lambda_i^- = mod(\\lambda_i,-2 \\pi)$\\;\n    $m\\lambda_{i-1}^- = mod(\\lambda_{i-1},-2 \\pi)$\\;\n\\% New point wraps off RHS border\\;\n  \\uIf{ $ d_i = d_{i-1} = 1 $ \\mbox{And} $m\\lambda_{i-1}^+ < \\pi $ \\mbox{And} $m\\lambda_i^+ > \\pi$}\n          {\n           \n           $m = \\displaystyle\\frac{\\phi_i - \\phi_{i-1}}{m\\lambda_i^+ - m\\lambda_{i-1}^+}$\\;\n           $\\phi_b = m (\\pi - m\\lambda_i^+) + \\phi_i$\\;\n           Plot line segment from ($\\lambda_{i-1},\\phi_{i-1}$) to ($\\pi,\\phi_b$)\\;\n           Plot line segment from ($-\\pi,\\phi_b$) to ($\\lambda_i,\\phi_i$)\\;\n          }{\n          \\% New point wraps off LHS border\\;\n  \\uElseIf {$ d_i = d_{i-1} = -1 $ \\mbox{And} $m\\lambda_i^- < -\\pi $ \\mbox{And} $m\\lambda_{i-1}^- > -\\pi$}\n              {\n           \n           $m = \\displaystyle\\frac{\\phi_i - \\phi_{i-1}}{m\\lambda_i^- - m\\lambda_{i-1}^- }$\\;\n           $\\phi_b = m (-\\pi - m\\lambda_i^-) + \\phi_i$\\;\n           Plot line segment from ($\\lambda_{i-1},\\phi_{i-1}$) to ($-\\pi,\\phi_b$)\\;\n           Plot line segment from ($\\pi,\\phi_b$) to ($\\lambda_i,\\phi_i$)\\;\n               }\n               \\% New does not wrap off plot border \\;\n  \\Else \n           {\n                Plot line segment from ($\\lambda_{i-1},\\phi_{i-1}$) to ($\\lambda_i,\\phi_i$)\\;\n            }\n    }    \n    \\hspace{.2 in}\n    %\n    \\label{alg:GroundTrackAlgorithm}\\caption{Algorithm for Updating A Ground Track Plot}\n    %\n\\end{algorithm}\n\\end{small}\n\\end{minipage}\n\\end{center}\n\n\\section{Footprint and Limb Computation}\n\n\\subsection{Overview}\n\nComputing an instrument footprint or the Earth Limb as viewed from a spacecraft involves essentially three related problems: (1) Determining the intersection of a given line with a given ellipsoid, (2) determination of a line tangent to a known ellipsoid, and (3) determining how to select the points along the footprint or limb curve to provide a smooth plot in the graphics.    These problems are related and discussed in order below starting with the problem of computing the intersection of a line and an ellipsoid.\n\n\\subsection{Intersection of Line and Ellipsoid}\n\nBegin by defining a ray $\\boldsymbol{\\ell}$ such that\n%\n\\begin{equation}\n    \\boldsymbol{\\ell} = \\mathbf{p} + \\alpha\\hat{\\mathbf{d}} \\label{Eq:RayParametrization}\n\\end{equation}\n%\nwhere $\\mathbf{p}$ (in this context the usually location of a spacecraft) is the the starting location of ray $\\boldsymbol{\\ell}$, $\\hat{\\mathbf{d}}$ is the unit vector in the direction of the ray, and $\\alpha$ is the distance from coordinates $\\mathbf{p}$ in the direction.  The equation for a tri-axial ellipoid is defined as\n%\n\\begin{equation}\n  \\frac{x^2}{R_x^2} + \\frac{y^2}{R_y^2} + \\frac{z^2}{R_z^2} - 1 = 0 \\label{Eq:TriAxialEllipsoid}\n\\end{equation}\n%\nwhere $R_x$, $R_y$, and $R_z$ are the ellipsoid radii in the $x$, $y$, and $z$ directions respectively.\nFor simplicity of notation, we'll assume all coordinates such $x$, $y$, and $z$, and ray $\\boldsymbol\\ell$ are \nexpressed in the body coordinates of the ellipsoid.\n%\nSubtituting Eq.~(\\ref{Eq:RayParametrization}) into Eq.~(\\ref{Eq:TriAxialEllipsoid}) results in\n%\n\\begin{equation}\n    \\frac{\\boldsymbol{\\ell}^T \\hat{\\mathbf{i}}}{R_x^2} + \\frac{\\boldsymbol{\\ell}^T \\hat{\\mathbf{j}}}{R_y^2} \n    + \\frac{\\boldsymbol{\\ell}^T \\hat{\\mathbf{k}}}{R_z^2} - 1 = 0 \\label{Eq:EllipseSimltaneous}\n\\end{equation}\n%\nwhere $\\hat{\\mathbf{i}}$, $\\hat{\\mathbf{i}}$, and $\\hat{\\mathbf{i}}$ are unit vectors in the $x$, $y$, and $z$ directions respectively.  Define $\\alpha^*$ as the value of $\\alpha$ that simulteoulsy satisfies both the equation for ray $\\boldsymbol{\\ell}$ and the equation for the triaxial ellipoid.  Expanding Eq.~(\\ref{Eq:EllipseSimltaneous}) and grouping terms by powers of $\\alpha^*$ yields\n%\n\\begin{equation}\n    \\alpha^{*2}\\left( \\frac{d_x^2}{R_x^2} + \\frac{d_y^2}{R_y^2} + \\frac{d_z^2}{R_z^2} \\right) +\n    2\\alpha^{*}\\left( \\frac{d_x p_x}{R_x^2} + \\frac{d_y p_y}{R_y^2} + \\frac{d_z p_z}{R_z^2} \\right)+\n    \\left( \\frac{p_x^2}{R_x^2} + \\frac{p_y^2}{R_y^2} + \\frac{p_z^2}{R_z^2} - 1\\right) = 0\n\\end{equation}\n%\nThis is a quadratic equation and the solution is \n%\n\\begin{equation}\n    \\alpha^* = \\frac{-B \\pm \\sqrt{B^2 - 4 A C}}{2A}\\label{Eq:Quadratic}\n\\end{equation}\n%\nwhere \n%\n\\begin{eqnarray}\n    A &=& \\left( \\frac{d_x^2}{R_x^2} + \\frac{d_y^2}{R_y^2} + \\frac{d_z^2}{R_z^2} \\right)\\\\\n    B &=& 2\\left( \\frac{d_x p_x}{R_x^2} + \\frac{d_y p_y}{R_y^2} + \\frac{d_z p_z}{R_z^2} \\right)\\\\\n    C &=& \\left( \\frac{p_x^2}{R_x^2} + \\frac{p_y^2}{R_y^2} + \\frac{p_z^2}{R_z^2} - 1\\right) \n\\end{eqnarray}\n%\nThere are three physical types of solutions for $\\alpha^*$ given by Eq.~(\\ref{Eq:Quadratic}).  If $(B^2 - 4 A C) < 0$ then ray $\\boldsymbol\\ell$ does not intersect\nthe ellipoid.  If $(B^2 - 4 A C) = 0$ then ray $\\boldsymbol\\ell$ is tangent to the ellipsoid (we'll revisit this relation when computing the limb curve). In this case,\n%\n\\begin{equation}\n    \\boldsymbol{\\ell}^* = \\mathbf{p} -\\frac{B}{2A}\\hat{\\mathbf{d}} \n\\end{equation}\n%\nFinally, if $(B^2 - 4 A C) > 0$ then ray $\\boldsymbol\\ell$ intersects the ellipsoid\nat two locations.  For graphics purposes, we require the smaller value of $\\alpha^*$ given by Eq.~(\\ref{Eq:Quadratic}). If we define $\\boldsymbol\\alpha^*$ as a vector containing the two solutions for $\\alpha$ corresponding to the two intersection points, then, the equation for the nearest intersection point, $\\boldsymbol{\\ell}^*$ is given by\n%\n\\begin{equation}\n    \\boldsymbol{\\ell}^* = \\mathbf{p} + min(\\boldsymbol\\alpha^*)\\hat{\\mathbf{d}} \n\\end{equation}\n\n\\subsection{Determining the Limb Region}\n\n\\subsection{Selecting Points for Accurate Graphics}", "meta": {"hexsha": "ae7126447ae76b58e08527893fe879dc00625609", "size": 8136, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/SystemDocs/MathematicalSpecification/Graphics.tex", "max_stars_repo_name": "Randl/GMAT", "max_stars_repo_head_hexsha": "d6a5b1fed68c33b0c4b1cfbd1e25a71cdfb8f8f5", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-01-01T13:14:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-09T07:05:07.000Z", "max_issues_repo_path": "doc/SystemDocs/MathematicalSpecification/Graphics.tex", "max_issues_repo_name": "ddj116/gmat", "max_issues_repo_head_hexsha": "39673be967d856f14616462fb6473b27b21b149f", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-03-15T08:58:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-20T20:11:26.000Z", "max_forks_repo_path": "doc/SystemDocs/MathematicalSpecification/Graphics.tex", "max_forks_repo_name": "ddj116/gmat", "max_forks_repo_head_hexsha": "39673be967d856f14616462fb6473b27b21b149f", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-10-13T10:26:49.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-09T07:06:55.000Z", "avg_line_length": 53.5263157895, "max_line_length": 611, "alphanum_fraction": 0.6677728614, "num_tokens": 2646, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7232450650264423}}
{"text": "\n\\subsection{Estimators}\n\nWhen we take statistics we are often concerned with inferring properties of the underlying probability function.\n\nAs the properties of the probability distribution function affect the chance of observing the sample, we can analyse samples to infer properties of the underlying distribution.\n\nThere are many properties would could be interested in. This includes moments and parameters of a specific probability distribution function.\n\nAn estimator is a statistic which is our estimate of one of these values.\n\nEmphasise that statistics and estimators are different things. A statistic may be terrible estimator, but be useful for other purposes. \n\n\n", "meta": {"hexsha": "617bf714a332932986812723e4289f73cc4443ad", "size": 675, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/generative/01-01-estimators.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/generative/01-01-estimators.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/generative/01-01-estimators.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.0, "max_line_length": 176, "alphanum_fraction": 0.8251851852, "num_tokens": 117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473879530491, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7231226097418412}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Written By Michael Brodskiy\n% Class: Analytic Geometry & Calculus III (Math-292)\n% Professor: V. Cherkassky\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\documentclass[12pt]{article} \n\\usepackage{alphalph}\n\\usepackage[utf8]{inputenc}\n\\usepackage[russian,english]{babel}\n\\usepackage{titling}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{enumitem}\n\\usepackage{amssymb}\n\\usepackage[super]{nth}\n\\usepackage{everysel}\n\\usepackage{ragged2e}\n\\usepackage{geometry}\n\\usepackage{fancyhdr}\n\\geometry{top=1.0in,bottom=1.0in,left=1.0in,right=1.0in}\n\\newcommand{\\subtitle}[1]{%\n  \\posttitle{%\n    \\par\\end{center}\n    \\begin{center}\\large#1\\end{center}\n    \\vskip0.5em}%\n\n}\n\\usepackage{hyperref}\n\\hypersetup{\ncolorlinks=true,\nlinkcolor=blue,\nfilecolor=magenta,      \nurlcolor=blue,\ncitecolor=blue,\n}\n\n\\urlstyle{same}\n\n\n\\title{Lecture V Notes}\n\\date{\\today}\n\\author{Michael Brodskiy\\\\ \\small Professor: V. Cherkassky}\n\n% Mathematical Operations:\n\n% Sum: $$\\sum_{n=a}^{b} f(x) $$\n% Integral: $$\\int_{lower}^{upper} f(x) dx$$\n% Limit: $$\\lim_{x\\to\\infty} f(x)$$\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Vectors in Space $-$ 13.1}\n\nA vector function: $\\overrightarrow{r}(t) = \\langle f(t), g(t), h(t) \\rangle = f(t)\\hat{\\bold{i}} + g(t)\\hat{\\bold{j}} + h(t)\\hat{\\bold{k}}$\\\\\n\nExample: $$\\overrightarrow{r}(t)=\\langle t^2, ln(2-t), \\sqrt{t} \\rangle$$\nThe domains of each component function must be considered to find the domain of the vector function, $0\\leq x < 2$\\\\\n\nFor a vector function: $$\\lim_{t\\to a} \\overrightarrow{r}(t)=\\langle \\lim_{t\\to a} f(t), \\lim_{t\\to a} g(t), \\lim_{t\\to a} h(t) \\rangle$$\\\\\n\nExample: Find the limit\n$$\\lim_{t\\to 0} (e^{-3t}\\hat{\\bold{i}} + \\frac{t^2}{\\sin^2{t}}\\hat{\\bold{j}} + \\cos(2t)\\hat{\\bold{k}})=\\hat{\\bold{i}}+\\hat{\\bold{j}}+\\hat{\\bold{k}}$$\n\n\\section{Derivatives and Integrals of Vector Functions $-$ 13.2}\n\n$$\\overrightarrow{r}'(t)=\\lim_{h\\to 0} \\frac{\\overrightarrow{r}(t+h)-\\overrightarrow{r}(t)}{h}$$\n\n$\\overrightarrow{r}'(t)$ is a vector tangent to $\\overrightarrow{r}(t)$, where $\\overrightarrow{r}'(t)=\\langle f'(t), g'(t), h'(t) \\rangle$\n\nThe unit tangent vector, $\\overrightarrow{T}(t)$, may found using the formula: $\\overrightarrow{T}(t)=\\frac{\\overrightarrow{r}'(t)}{|\\overrightarrow{r}'(t)|}$\n\nThe integral of the vector function $\\overrightarrow{r}(t)$ is: $$\\int_{a}^{b} \\overrightarrow{r}(t) dt = \\left(\\int_{a}^{b} f(t) dt\\right)\\hat{\\bold{i}} + \\left(\\int_{a}^{b} g(t) dt\\right)\\hat{\\bold{j}} + \\left(\\int_{a}^{b} h(t) dt\\right)\\hat{\\bold{k}}$$\n\n\\end{document}\n", "meta": {"hexsha": "fb797a7985b0f75da1811294c5bce121787a7969", "size": 2848, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture Notes/Lecture5.tex", "max_stars_repo_name": "MDBrodskiy/Vector_Calculus", "max_stars_repo_head_hexsha": "d4820f31c0c585ae65e6d61249d8c725077005eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-15T15:51:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-15T15:51:52.000Z", "max_issues_repo_path": "Lecture Notes/Lecture5.tex", "max_issues_repo_name": "MDBrodskiy/Vector_Calculus", "max_issues_repo_head_hexsha": "d4820f31c0c585ae65e6d61249d8c725077005eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture Notes/Lecture5.tex", "max_forks_repo_name": "MDBrodskiy/Vector_Calculus", "max_forks_repo_head_hexsha": "d4820f31c0c585ae65e6d61249d8c725077005eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.5128205128, "max_line_length": 255, "alphanum_fraction": 0.577247191, "num_tokens": 928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7231225996178459}}
{"text": "%\\section{Exercise 7. Metrizability \\& number theory}\n\\noindent\n\\textit{\nLet be X the vector space of all complex functions on the unit interval \n$[0, 1]$, topologized by the family of seminorms \n%\n  \\begin{align}\n    \\mathit{p_{x}(f\\,)=|f(x)| \\quad\\quad (0\\leq x\\leq 1).\\nonumber}\n  \\end{align}\n%\nThis topology is called the topology of pointwise convergence. \nJustify this terminology.\nShow that there is a sequence $\\{f_n\\}$ in X such that (a) $\\{f_n\\}$ converges \nto $0$ as $n \\to\\infty$, but (b) if $\\{γ_n\\}$ is any sequence of scalars such \nthat $γ_n\\to\\infty$ then $\\{γ_nf_n\\}$ does not converge to $0$. \n(Use the fact that the collection of all complex sequences converging to $0$ \nhas the same cardinality as $[0, 1]$.)\nThis shows that metrizability cannot be omited in (b) of Theorem 1.28.\n}\n\\begin{proof}\n%Our justification consists in proving that $\\tau$-convergence and pointwise \n%convergence are the same one. \n%\n%To do so, remark first that \nThe family of the seminorms $p_{\\varit{x}}$ is separating: \nBy \\citeresultFA{1.37}, the collection $\\mathscr{B}$ of all finite intersections \nof the sets \n%\n  \\begin{align}\n    %\\tensor*[_x]{V}{_k}\n    V(\\varit{x},\\varit{k})\n      \\Def \n    \\singleton{p_\\varit{x} < 2^{\\,\\minus \\varit{k}}} \n      \\quad\\quad\n    (\\varit{\\varit{x}} \\in [0, 1], \\varit{k}=1, 2, 3, \\dots)\n  \\end{align}\n%\nis therefore a local base for a topology $\\tau$ on $X$. \nSo, \n%\n  \\begin{align}\n    %\n    \\label{Inequality boolean series}\n    %\n    \\sum_{n=1}^\\infty \\boolean{f_n \\notin \\cap_{i=1}^m U_i} \\leq \n    \\sum_{n=1}^\\infty \\sum_{i=1}^m \\boolean{f_n \\notin U_{i}} = \n    \\sum_{i=1}^m \\sum_{n=1}^\\infty \\boolean{f_n \\notin U_i} %\\off{U_{i}    \n    \\quad\\quad (f_n \\in X, U_i \\in \\tau).\n  \\end{align}%\n%\nNow assume that $\\{f_n\\}$ $\\tau$-converges to some $f$, \\ie \n%\n  \\begin{align}\n    %\n    \\sum_{n=1}^\\infty \\boolean{f_n \\notin f + W} < \\infty \\quad\\quad (W \\in \\mathscr{B}).\n  \\end{align}\nThe special case %\n%\n$W = V(\\varit{x}, \\varit{k})$ %\n%\nmeans that %\n%\n  $\\magnitude{f_n(\\varit{\\varit{x}}) - f(\\varit{x})} < 2^{\\,\\minus \\varit{k}}$ %\n%\nfor almost all $n$,  \\ie \n  $\\singleton{f_n(\\varit{x})}$ converges to $f(\\varit{x})$. \nConversely, assume that $\\singleton{f_n}$ does not $\\tau$-converges in $X$, \\ie \n%\n  \\begin{align}\n    %\n    \\label{Divergence}\n    %\n    \\forall f \\in X, \\exists W \\in \\localbase{B}: \n      \\sum_{n=1}^\\infty\\boolean{f_n \\notin f +  W} = \\infty. \n    %\n  \\end{align}\n%\n$W$ is now the intersection of finitely many %\n%\n$V(\\varit{\\varit{x}}, \\varit{k})$, %\n%\nsay  \n%\n  $ V(x_1, k_1), \\dots, V(x_m, k_m)$. Thus,  %\n%\n  \\begin{align}\n    \\sum_{i=1}^m \\sum_{n=1}^\\infty \\boolean{f_n \\notin f + V(x_i, k_i)}\n      %\n        \\citegeq{\\ref{Inequality boolean series}} \n      %\n    \\sum_{n=1}^\\infty \\boolean{f_n \\notin f + W}\n    % \n      \\citeq{\\ref{Divergence}} \n    %\n    \\infty .\n  \\end{align}\n%\nWe can now conclude that, for some index $\\varit{i}$, \n%\n  \\begin{align}\n    \\sum_{n=1}^\\infty \\boolean{\n      f_n \\notin f + V(x_i, k_i)\n    } = \\infty .\n  \\end{align}\nIn other word, %\n%\n$\\singleton{f_n(x_i)}$ %\n%\nfails to converge to \n$f(x_i)$.\nWe have so proved that \n%\n  $\\tau$-convergence is a rewording of pointwise convergence.\n%\n% SECOND PART\nWe now establish the second part. \\\\% \n\\\\\\noindent\nTo do so, we split $\\varit{x}$ into two variables: %\n$\\varit{r}$ if $\\varit{x}$ is rational, $\\alpha$ otherwise.\n%\nThe proof is based on the following well-known result: Each $\\alpha$ %\nhas a {\\it unique} binary expansion. %\nMore precisely, there exists a bijection %\n%\n$b:[0, 1] \\setminus \\Q \\to %\n\\set{\\beta \\in \\{0, 1\\}^{\\N_+}}{\\beta \\text{ is not eventually periodic}}$ %\n%\nwhere %\n$b(\\alpha) = (\\beta_1, \\beta_2, \\dots)$ %\nis the only bit stream such that %\n%\n  \\begin{align}\n    \\label{definition of alpha}\n    \\alpha = \\sum_{k=1}^\\infty \\beta_k \\cdot 2^{\\,\\minus k}.\n  \\end{align}\n%\nRemark that %\n%\n$b(\\alpha)_1 + \\dots + b(\\alpha)_n \\longrightarrow \\infty$, %\n%\nsince %\n%\n$b(\\alpha)$\n%\nhas infinite support, then fix %\n%\n  \\begin{equation}\n    \\label{definition of f_n(alpha)}\n    f_n(\\alpha)\\Def %\n    \\frac{1}{b(\\alpha)_1+\\cdots+ b(\\alpha)_n} \\tendsto{n}{\\infty} 0.\n  \\end{equation}\n%\nThe actual values $f_n(r)$ are of no interest, %\nas long as every sequence $\\set{f_n(r)}{\\counting{n}}$ converges to $0$. %\nFor example, put $f_n(r) = r/n$, or just $f_n(r) = 0$. %\nWe also take % \n%\n  $\\gamma_n \\longrightarrow \\infty$, \\ie % \n%\ngiven any counting number $\\varit{p}$, %\n$\\gamma_{n}$ is greater than $\\varit{p}$ for almost all $\\varit{n}$.\n%\nNext, we choose $n_{p}$ among those \\textit{almost all} $\\mathit{n}$ that are \nlarge enough to satisfy \n%\n  \\begin{align}\n    \\label{definition of n_p}\n    n_p - n_{p-1} > p\n  \\end{align}\n%\n(start with $n_0=0$).\n%\nSo, every list %\n%\n  $n_{p}, n_{p'}, n_{p''}, \\dots $ %\n%\nthat satisfies %\n%\n  $n_{p'}- n_{p} = n_{p''} - n_{p'} = \\dots$ %\n%\nis finite %\n(otherwise, %\n    $n_{p'}-n_{p} \\geq n_{p+1} - n_{p}  \n    > p \n    \\rightarrow  \\infty %\n    $\nwould hold from; see (\\ref{definition of n_p})).\nIn other words, {\\it the distribution of %\n%\n$\\mathit{n_1, n_2, \\dots}$ %\n%\ndisplays no periodic pattern}. %\nAs a consequence, the {\\it characteristic function} %\n  $\\chi: k\\mapsto \\boolean{k \\in \\singleton{n_1, n_2, \\dots}}$ %\nis not eventually periodic. %\nCombined with (\\ref{definition of alpha}), this establishes that \n%\n\\def\\xgamma{\\alpha_{\\gamma}}\n%\n  \\begin{align}\n    \\xgamma \n      \\Def\n    \\sum_{k=1}^\\infty \\chi_k 2^{\\minus \\varit{k}}\n      %\\notin \\Q\n  \\end{align}\n%\nis irrational. Conversely, still with (\\ref{definition of alpha}),  %\n%\n  \\begin{align}\n    b(\\xgamma)_{k} = \\chi_{k}.\n  \\end{align}\n%\nNow remark that %\n%\n  \\begin{alignat}{2}\n    \\chi_1 + \\cdots + \\chi_{n_{1}} & &&=1 \\\\\n    \\chi_1 + \\cdots + \\chi_{n_{1}} & + \\cdots + \\chi_{n_{2}} &&=2 \\\\\n    \\nonumber \\vdots&  &&\\\\\n    \\chi_1 + \\cdots + \\chi_{n_{1}} & + \\cdots + \\chi_{n_{2}} + \\cdots + \n    \\chi_{n_{p}}&&=p.\n  \\end{alignat}\n%\nCombined with (\\ref{definition of f_n(alpha)}), this yields %\n%\n  \\begin{align}\n    \\gamma_{n_p} f_{n_{p}}(\\xgamma) = \\frac{\\gamma_{n_p}}{p} > 1.\n  \\end{align}\n%\nThere so exists a subsequence $\\singleton{\\gamma_{n_p}}$ such that %\n%\n  $\\singleton{\\gamma_{n_p} f_{\\gamma_{n_p}}}$ %\n%\nfails to converge pointwise to $0$. %\nIn other words, (b) holds, which is in violent contrast with %\n\\citeresultFA{1.28}: $X$ is therefore not metrizable. So ends the proof.\n\\end{proof}\n% END\n", "meta": {"hexsha": "8a3ac06d443f4db6c0b917102670cdc54789dbd4", "size": 6397, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter_1/1_07.tex", "max_stars_repo_name": "gitcordier/FunctionalAnalysis", "max_stars_repo_head_hexsha": "4d54af9cab1ce2bf512341cc1f2a0c81d7097754", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter_1/1_07.tex", "max_issues_repo_name": "gitcordier/FunctionalAnalysis", "max_issues_repo_head_hexsha": "4d54af9cab1ce2bf512341cc1f2a0c81d7097754", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter_1/1_07.tex", "max_forks_repo_name": "gitcordier/FunctionalAnalysis", "max_forks_repo_head_hexsha": "4d54af9cab1ce2bf512341cc1f2a0c81d7097754", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.8781512605, "max_line_length": 89, "alphanum_fraction": 0.6070032828, "num_tokens": 2353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7231225941158308}}
{"text": "\\subsection{Noetherian rings}\\label{subsec:noetherian_rings}\n\n\\begin{definition}\\label{def:noetherian_module}\\mcite[prop. 8.30]{Knapp2016BasicAlgebra}\n  A module \\( M \\) over \\( R \\) is called \\term{Noetherian} if it satisfies any of the following conditions:\n  \\begin{thmenum}\n    \\thmitem{def:noetherian_module/ascending_chain} Every strict chain of submodules of \\( M \\)\n    \\begin{equation*}\n      M_1 \\subsetneq M_2 \\subsetneq \\ldots\n    \\end{equation*}\n    is finite.\n\n    \\thmitem{def:noetherian_module/finite_basis} Every submodule of \\( M \\) is finitely \\hyperref[def:free_left_module]{generated}.\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:noetherian_module/ascending_chain}{def:noetherian_module/finite_basis} We can construct a basis as follows: choose any element \\( x_1 \\) of \\( M \\). Next, choose an element \\( x_2 \\in M \\setminus \\braket {x_1} \\), then \\( x_3 \\in M \\setminus \\braket {x_1, x_2} \\) and, so on.\n\n  This process must stop after finitely many steps because we obtain the strict chain\n  \\begin{equation*}\n    \\braket {x_1} \\subsetneq \\braket {x_1, x_2} \\cdots\n  \\end{equation*}\n  of submodules.\n\n  \\ImplicationSubProof{def:noetherian_module/finite_basis}{def:noetherian_module/ascending_chain} Suppose that all submodules of \\( M \\) are finitely generated. Let\n  \\begin{equation*}\n    M_1 \\subsetneq M_2 \\subsetneq \\ldots\n  \\end{equation*}\n  be a strictly ascending chain of submodules.\n\n  Then the submodule \\( N \\coloneqq \\bigcup_{i=1}^\\infty M_i \\) is also finitely generated. There exists a member \\( M_N \\) of the chain containing all the generators of \\( N \\). Then no further strict inclusion of modules is possible. We conclude that the chain\n  \\begin{equation*}\n    M_1 \\subsetneq M_2 \\subsetneq \\ldots\n  \\end{equation*}\n  is finite.\n\\end{proof}\n\n\\begin{definition}\\label{def:noetherian_ring}\n  A \\term{Noetherian ring} is an Noetherian submodule over itself, i.e. it satisfies the conditions in \\fullref{def:noetherian_module} on its ideals.\n\\end{definition}\n\n\\begin{theorem}[Hilbert basis theorem]\\label{thm:hilberts_basis_theorem}\\mcite[418]{Knapp2016BasicAlgebra}\n  If \\( R \\) is Noetherian, so is \\( R[X] \\).\n\\end{theorem}\n\n\\begin{theorem}\\label{thm:noetherian_rings_closed_under}\n  The \\hyperref[def:set]{classes} of Noetherian \\hyperref[def:noetherian_module]{modules} and Noetherian \\hyperref[def:noetherian_ring]{rings} are closed with respect to many operations, including the following:\n\n  \\begin{thmenum}\n    \\thmitem{thm:noetherian_rings_closed_under/localization}\\cite[corollary 8.48]{Knapp2016BasicAlgebra} The \\hyperref[def:ring_localization]{localizations} \\( S^{-1} R \\) of a Noetherian ring \\( R \\) are also Noetherian.\n\n    \\thmitem{thm:noetherian_rings_closed_under/modules}\\cite[proposition 8.34]{Knapp2016BasicAlgebra} Any \\hyperref[def:free_left_module]{finitely generated module} over a Noetherina ring is also \\hyperref[def:noetherian_module]{Noetherian}.\n\n    \\thmitem{thm:noetherian_rings_closed_under/submodules}\\cite[proposition 6.3(a)]{КоцевСидеров2016} Every submodule of a Noetherian module is Noetherian.\n\n    \\thmitem{thm:noetherian_rings_closed_under/quotients}\\cite[proposition 6.3(a)]{КоцевСидеров2016} Every quotient of a Noetherian module is Noetherian.\n\n    \\thmitem{thm:noetherian_rings_closed_under/restoration}\\cite[proposition 6.3(b)]{КоцевСидеров2016} If the module \\( M \\) has a Noetherian submodule \\( N \\) such that \\( M / N \\) is also Noetherian, then \\( M \\) itself is Noetherian.\n\n    \\thmitem{thm:noetherian_rings_closed_under/polynomial_ring} The polynomial ring \\( R[X] \\) over a Noetherian ring \\( R \\) is also Noetherian. See \\fullref{thm:hilberts_basis_theorem}.\n  \\end{thmenum}\n\\end{theorem}\n\n\\begin{theorem}[Primary decomposition]\\label{thm:primary_decomposition}\\mcite[thm. 10.6]{КоцевСидеров2016}\n  In a Noetherian ring \\( R \\), every ideal \\( I \\) can be represented as an intersection\n  \\begin{equation*}\n    I = \\bigcap_{i=1}^n P_i\n  \\end{equation*}\n  of finitely many primary \\hyperref[def:primary_ring_ideal]{ideals}.\n\\end{theorem}\n", "meta": {"hexsha": "2064e39fe61c725583b799303d24927594d3d92c", "size": 4067, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/noetherian_rings.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/noetherian_rings.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/noetherian_rings.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.1, "max_line_length": 302, "alphanum_fraction": 0.752643226, "num_tokens": 1307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388040954683, "lm_q2_score": 0.8723473763375644, "lm_q1q2_score": 0.7231225908970801}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n\\usepackage{parskip}\n\\counterwithin*{equation}{subsubsection}\n\\setcounter{secnumdepth}{4}\n\n\\begin{document}\n    \\section{Derive the normal equation}\n\tGiven a data \\textbf{X},\\textbf{y} and assuming a probabilistic model given by $y=\\beta^{T}x+\\epsilon$ where $\\epsilon\\sim Normal(0,\\sigma^2)$, show that the $\\beta$ that maximizes the probability of obtaining the data is given by: $\\beta=(X^{T}X)^{-}X^{T}y$.\n\t\n\t\\subsection{Solution}\n\t\\subsubsection{Feature space}\n\tAssume $m$ training examples $(x^{(1)},y^{(1)}),(x^{(2)},y^{(2)}),...,(x^{(m)},y^{(m)})$ with $n$ features $x_1, x_2,...,x_n$. At index 0, let $x^{(1)}_0, x^{(2)}_0,..., x^{(i)}_0,...,x^{(n)}_0$ all equal 1. Therefore, if there are $n$ features and a 0th index, there will be $n+1$ feature vectors.\n\t\n\tLet $X$ be the design matrix of $n+1$ feature vectors $x^{(i)}_{n+1}$ where $x^{(i)}$ denotes the $i$-th $n+1$-dimensional feature vector contained within $X$. \n\t\n\tThus, each row of the matrix $X$ is filled by $(x^{(1\\:\\text{to}\\:m)})^{T}$, making $X$ an $m\\times(n+1)$-dimensional matrix of all the features of the training data:\n\t\n\t\\begin{equation*}\n\tx^{(i)} = \\begin{bmatrix}\n\tx^{(i)}_0\\\\x^{(i)}_1\\\\x^{(i)}_2\\\\.\\\\x^{(i)}_n\n\t\\end{bmatrix}\\in\\rm I\\!R^{n+1}\\qquad\n\tX=\\begin{bmatrix}\n\tx^{(1)}_0&x^{(1)}_1&x^{(1)}_2&.&.&.&x^{(1)}_n\\\\\n\tx^{(2)}_0&x^{(2)}_1&x^{(2)}_2&.&.&.&x^{(2)}_n\\\\\n\t.&.&.&.&.&.&.\\\\\n\tx^{(i)}_0&x^{(i)}_1&x^{(i)}_2&.&.&.&x^{(i)}_n\\\\\n\t.&.&.&.&.&.&.\\\\\n\tx^{(m)}_0&x^{(m)}_1&x^{(m)}_2&.&.&.&x^{(m)}_n\n\t\\end{bmatrix}\n\t\\end{equation*}\n\t\t\n\tLet $y$ be the vector of true values of the above described training examples.\n\t\n\t\\begin{equation*}\n\ty=\\begin{bmatrix}\n\ty_1\\\\y_2\\\\.\\\\.\\\\y_m\n\t\\end{bmatrix}\n\t\\end{equation*}\n\t\n\t\\subsubsection{Hypothesis function}\n\tGiven the hypothesis function:\n\t$$\n\th_\\beta(x)=\\beta_0x_0+\\beta_1x_1+...+\\beta_nx_n\n\t$$\n\t(Recall that $x_0$ = 1.)\n\t\n\tThe above hypothesis function can be represented using matrix notation. The regression coefficients of hypothesis function $h_\n\t\\beta(x)$ can be represented as an $n+1$-dimensional vector:\n\t\\begin{equation*}\n\t\\beta=\\begin{bmatrix}\n\t\\beta_0\\\\\\beta_1\\\\\\beta_2\\\\.\\\\.\\\\.\\\\\\beta_n\n\t\\end{bmatrix}\\in\\rm I\\!R^{n+1}\n\t\\end{equation*}\n\t\n\tSimilarly, each of the $m$ training examples is an $n+1$-dimensional vector $\\Bigg[\\begin{smallmatrix}\n\tx^{(i)}_0\\\\x^{(i)}_1\\\\.\\\\x^{(i)}_n\n\t\\end{smallmatrix}\\Bigg]$ with $x^{(i)}_0=1$ to allow for a convenient vector multiplication.\n\t\n\tThus, the hypothesis function for each $x_i$, $h_\\beta(x_i)$, can be written as:\n\t\\begin{equation*}\n\th_\\beta(x_i)=\\beta^{T}x+\\epsilon\n\t\\end{equation*}\n\twhere $\\beta$ and $x_i$ are $n+1$-dimensional vectors, and $\\epsilon$ is the normally distributed error for each observation.\n\t\n\t\\subsubsection{Training error}\n\tThe training error for the above generalized example could be expanded algebraically as:\n\t\\begin{equation*}\n\tError\\:(\\epsilon)=\\begin{bmatrix}\n\ty_1 - (\\beta_0x^{(1)}_0+\\beta_1x^{(1)}_1+\\beta_2x^{(1)}_2+...+\\beta_nx^{(1)}_n)\\\\\n\ty_2 - (\\beta_0x^{(2)}_0+\\beta_1x^{(2)}_1+\\beta_2x^{(2)}_2+...+\\beta_nx^{(2)}_n)\\\\\n\ty_3 - (\\beta_0x^{(3)}_0+\\beta_1x^{(3)}_1+\\beta_2x^{(3)}_2+...+\\beta_nx^{(3)}_n)\\\\\n\t...\\\\\n\t...\\\\\n\ty_m - (\\beta_0x^{(m)}_0+\\beta_1x^{(m)}_1+\\beta_2x^{(m)}_2+...+\\beta_nx^{(m)}_n)\n\t\\end{bmatrix}=\n\t\\begin{bmatrix}\n\t\\epsilon_1\\\\\n\t\\epsilon_2\\\\\n\t\\epsilon_3\\\\\n\t.\\\\\n\t.\\\\\n\t\\epsilon_m\n\t\\end{bmatrix}\\in\\rm I\\!R^{m}\n\t\\end{equation*}\n\t\n\tThis can be simplified using matrix notation and the matrices that were defined above. $y_{1\\:\\text{to}\\:m}$ in the matrix above correspond to the matrix $y$ of true values. The $\\beta_{0\\:\\text{to}\\:n}$ correspond to the matrix $\\beta$ of regression coefficients. The $x_{0\\:\\text{to}\\:n}$ correspond to the design matrix $X$ of the $m\\times(n+1)$-dimensional feature space.\n\t\n\tUsing matrix addition and multiplication, the above matrix simplifies to:\n\t\\begin{equation*}\n\tError\\:(\\epsilon) =y_{m\\times1}- X_{m\\times n+1}\\beta_{n+1}\\in\\rm I\\!R^{m}\n\t\\end{equation*}\n\t(The subscripts denote the dimensions of these matrices for convenience.)\n\t\n\t\\subsubsection{Deriving the cost function}\n\tThe likelihood of obtaining the model parameters from the data is given by:\n\t\\begin{equation*}\n\t\\mathcal{L}(\\beta|y,X)=\\Pr(X|\\beta)\n\t\\end{equation*}\n\twhere $\\mathcal{L}$ is the likelihood, $X$ is the design matrix (i.e., the data), and $\\beta$ is the vector of model parameters.\n\t\n\tThe probability of the data $X$ given the model parameters $\\beta$ is the joint probability of each individual data point:\n\t\\begin{equation*}\n\t\\Pr(X|\\beta)=\\prod_{i=1}^{m}\\Pr(y_i|x_i,\\beta)\n\t\\end{equation*}\n\t\n\tIt is given that $\\epsilon\\sim Normal(0,\\sigma)$. As the noise $\\epsilon$ is additive, the linearity condition implies that $\\Pr(y_i|x_i,\\beta)\\sim Normal(\\beta^{T}x_i,\\sigma_\\epsilon^2)$.\n\t\n\tThe goal is to find a set of model parameters $\\beta$ that maximize the likelihood. Taking the logarithm of both sides helps simplify the equation. Since the logarithm is a monotonic function, the maximum of the log-likelihood occurs at the same value of $\\beta$ as the maximum of the likelihood. Thus, taking the $\\ln$ of both sides:\n\t\\begin{align*}\n\t\\ln\\mathcal{L}(\\beta)&= \\ln \\prod_{i=1}^{m}\\Pr(y_i|x_i,\\beta)\\\\\n\t&=\\sum_{i=1}^{m}\\left[\\ln \\Pr(y_i|x_i,\\beta)\\right]\\\\\n\t&=\\sum_{i=1}^{m}\\left[-\\frac{1}{2\\sigma_\\epsilon^2}(y_i-\\beta^Tx_i)^2-\\ln \\left(\\sqrt{2\\pi\\sigma_\\epsilon^2}\\right)\\right]\n\t\\end{align*}\n\tThe last step follows because $\\Pr(y_i|x_i\\beta)$ is a Gaussian probability density as noted above.\n\t\n\tAs the goal is to maximize the above likelihood (or more precisely, log-likelihood) in terms of the model parameters, the above terms that do not depend on $\\beta$ (i.e., $-\\frac{1}{2\\sigma_\\epsilon^2}$, $-\\ln \\sqrt{2\\pi\\sigma_\\epsilon^2}$) can be ignored. Thus, the optimization problem can be written as:\n\t\\begin{equation*}\n\t\\ln\\mathcal{L}(\\beta)=\\sum_{i=1}^{m}(y_i-\\beta^Tx_i)^2\n\t\\end{equation*}\n\tThis is the sum of least squares!\n\t\n\t\\subsubsection{Rewriting the cost function using matrices}\n\tThe goal is to minimize the least-squares cost function:\n\t\\begin{equation*}\n\tJ(\\beta_{0...n})= \\frac{1}{2m}\\sum_{i=1}^{m}(y_i - h_\\beta(x^{(i)}))^2\n\t\\end{equation*}\n\twhere, as above, $x^{(i)}$ is the $i$-th sample from a set of $m$ samples and $y^{(i)}$ is the $i$-th true value.\n\t\n\tBecause the term $h_\\beta(x^{(i)})-x^{(i)}=\\epsilon^{(i)}$, i.e.,\n\t\n\t\\begin{equation*}\n\tJ(\\beta_{0...n})= \\frac{1}{2m}\\sum_{i=1}^{m}(y_i - h_\\beta(x^{(i)}))^2=\\frac{1}{2m}\\sum_{i=1}^{m}\\epsilon_i^2\n\t\\end{equation*}\n\t\n\tanother way of stating this problem is minimizing the sum of the squared errors in the $Error$ vector $\\epsilon$, i.e., $\\epsilon^{T}\\times\\epsilon$. Concretely,\n\t\n\t\\begin{equation*}\n\t\\sum_{i=1}^{m}\\epsilon_i^2 = \\begin{bmatrix}\n\t\\epsilon_1&\\epsilon_2&\\epsilon_3&.&.&\\epsilon_m\n\t\\end{bmatrix}\n\t*\n\t\\begin{bmatrix}\n\t\\epsilon_1\\\\\n\t\\epsilon_2\\\\\n\t\\epsilon_3\\\\\n\t.\\\\\n\t.\\\\\n\t\\epsilon_m\n\t\\end{bmatrix}=\\epsilon_1^2+\\epsilon_2^2+\\epsilon_3^2+...+\\epsilon_m^2\n\t\\end{equation*}\n\t\n\tAs above, $\\epsilon=y-X\\beta$. Thus,\n\t\\begin{equation*}\n\tJ(\\beta_{0...n})=\\frac{1}{2m}(y-X\\beta)^{T}(y-X\\beta)\n\t\\end{equation*}\n\t\n\tIgnoring the constant $\\frac{1}{2m}$,\n\t\\begin{align*}\n\tJ(\\beta_{0...n})&=(y^T-(X\\beta^T))(y-X\\beta)\\\\\n\t&=y^Ty-y^TX\\beta-(X\\beta)^Ty+(X\\beta)^TX\\beta\n\t\\end{align*}\n\tTake the transpose of the second term in the above equation $(y^TX\\beta)^T=(X\\beta)^Ty$. Thus,\n\t\\begin{align*}\n\tJ(\\beta_{0...n})&=y^Ty-(X\\beta)^Ty-(X\\beta)^Ty+(X\\beta)^TX\\beta\\\\\n\t&=y^Ty-2(X\\beta)^Ty+(X\\beta)^TX\\beta\n\t\\end{align*}\n\tDistribute the transpose in the last term and the final equation for $J(\\beta_{0...n})$ is:\n\t\\begin{equation*}\n\tJ(\\beta_{0...n})= y^Ty-2(X\\beta)^Ty+\\beta^{T}X^TX\\beta\n\t\\end{equation*}\n\t\n\t\\subsubsection{Minimizing the cost function}\n\tIn order to find the minimum of the cost function, the derivative of $J(\\beta_{0...n})$ must be taken and then set to zero:\n\t\\begin{equation*}\n\t\\frac{\\partial{J}}{\\partial{\\beta}}=0\n\t\\end{equation*}\n\t\n\tTo simplify the operations, the derivative of each term of $J(\\beta_{0...n})$ will be taken separately. $y^{T}y$ will be ignored given it has no $\\beta$ terms and the derivative of a constant is 0.\n\t\\begin{equation*}\n\tJ(\\beta_{0...n}) = P(\\beta_{0...n})+Q(\\beta_{0...n})+y^Ty\n\t\\end{equation*}\n\t\\begin{equation}\n\tP(\\beta_{0...n})=\\beta^{T}X^TX\\beta\n\t\\end{equation}\n\t\\begin{equation}\n\tQ(\\beta_{0...n})=-2(X\\beta)^Ty\n\t\\end{equation}\n\t\n\t\\paragraph{Differentiate $P(\\beta_{0...n})$}~\\\\\n\t\\begin{equation*}\n\tP(\\beta_{0...n})=\\beta^{T}X^TX\\beta\n\t\\end{equation*}\n\t\n\tImportantly, the product $X^T_{n+1\\times m}X_{m\\times n+1}$ is a square, symmetrical $n+1 \\times n+1$-dimensional matrix. For convenience $Z$ will be substituted for $X^TX$. Therefore, $P(\\beta_{0...n})$ can be rewritten as: $\\beta^TZ\\beta$ where $Z$ is the square, symmetrical matrix defined above.\n\t\n\tFor the case where a scalar $\\alpha$ is given by\n\t\\begin{equation*}\n\t\\alpha=x^TAx\n\t\\end{equation*}\n\twhere x is $n\\times1$, $A$ is $n\\times n$, and $A$ does not depend on $x$:\n\t\\begin{align*}\n\t\\alpha &= \\sum_{j=1}^{n}\\sum_{i=1}^{n}a_{ij}x_ix_j\\\\\n\t\\frac{\\partial\\alpha}{\\partial x_k}&=\\sum_{j=1}^{n}a_{kj}x_j+\\sum_{i=1}^{n}a_{ik}x_i\\qquad\\text{for the $k$th element of $x$}\\\\\n\t\\frac{\\partial\\alpha}{\\partial x}&=x^TA^T+x^TA\\hspace{53pt}\\text{for all $k=1,2,...n$}\\\\\n\t&=x^T(A^T+A)\n\t\\end{align*}\n\t\n\tFor the special case where $A$ is a symmetrical matrix, $A^T=A$, therefore $(A^T+A)=2A$ and $\\frac{\\partial\\alpha}{\\partial x}=2x^TA$.\n\t\n\tBack to the problem at hand, $Z$ was noted to be a square, symmetrical matrix. Therefore,\n\t\\begin{align*}\n\tP(\\beta_{0...n})&=\\beta^TZ\\beta\\\\\n\t\\frac{\\partial P}{\\partial\\beta}&=2\\beta^TZ\\\\\n\t&=2\\beta^TX^TX\\qquad\\text{substituting $X^TX$ for $Z$}\\\\\n\t&=2(\\beta^TX^TX)^T\\qquad\\text{take the transpose}\\\\\n\t&=2X^TX\\beta\n\t\\end{align*}\n\t\n\t\\paragraph{Differentiate $Q(\\beta_{0...n})$}~\\\\\n\t\\begin{align*}\n\tQ(\\beta_{0...n})&=-2(X\\beta)^Ty\\\\\n\t&=-2\\left( \\begin{bmatrix}\n\tx^{(1)}_0&x^{(1)}_1&x^{(1)}_2&.&.&.&x^{(1)}_n\\\\\n\tx^{(2)}_0&x^{(2)}_1&x^{(2)}_2&.&.&.&x^{(2)}_n\\\\\n\t.&.&.&.&.&.&.\\\\\n\tx^{(i)}_0&x^{(i)}_1&x^{(i)}_2&.&.&.&x^{(i)}_n\\\\\n\t.&.&.&.&.&.&.\\\\\n\tx^{(m)}_0&x^{(m)}_1&x^{(m)}_2&.&.&.&x^{(m)}_n\n\t\\end{bmatrix}\\begin{bmatrix}\n\t\\beta_0\\\\\\beta_1\\\\\\beta_2\\\\.\\\\.\\\\.\\\\\\beta_n\n\t\\end{bmatrix}\\right)^T\\begin{bmatrix}\n\ty_1\\\\y_2\\\\.\\\\.\\\\y_m\n\t\\end{bmatrix}\\\\\n\t&=-2\\left(\\begin{bmatrix}\n\t\\beta_0x^{(1)}_0+\\beta_1x^{(1)}_1+\\beta_2x^{(1)}_2+...+\\beta_nx^{(1)}_n\\\\\n\t\\beta_0x^{(2)}_0+\\beta_1x^{(2)}_1+\\beta_2x^{(2)}_2+...+\\beta_nx^{(2)}_n\\\\\n\t...\\\\\n\t\\beta_0x^{(i)}_0+\\beta_1x^{(i)}_1+\\beta_2x^{(i)}_2+...+\\beta_nx^{(i)}_n\\\\\n\t...\\\\\n\t\\beta_0x^{(m)}_0+\\beta_1x^{(m)}_1+\\beta_2x^{(m)}_2+...+\\beta_nx^{(m)}_n\n\t\\end{bmatrix}\\right)^T\\begin{bmatrix}\n\ty_1\\\\y_2\\\\.\\\\.\\\\y_m\n\t\\end{bmatrix}\n\t\\end{align*}\n\t\n\t\\begin{multline*}\n\tQ(\\beta_{0...n})=-2[\\:y_1(\\beta_0x^{(1)}_0+...+\\beta_nx^{(1)}_n)\\\\\n\t+y_2(\\beta_0x^{(2)}_0+...+\\beta_nx^{(2)}_n)+...+y_m(\\beta_0x^{(m)}_0+...+\\beta_nx^{(m)}_n)\\:]\n\t\\end{multline*}\n\t\n\tRearranging the above using sums:\t\n\t\\begin{align}\n\tQ(\\beta_{0...n})&=-2\\sum_{r=1}^{m}y_r(\\beta_0x_0^{(r)}+...+\\beta_nx^{(r)}_n)\\\\\n\t&=-2\\sum_{r=1}^{m}y_r\\sum_{s=1}^{n}\\beta_sx_s^{(r)}\n\t\\end{align}\n\t\n\tUsing equation (3) above to differentiate:\t\n\t\\begin{equation*}\n\t\\frac{\\partial Q}{\\partial \\beta}=-2\\sum_{r=1}^{m}y_r(\\beta_0x_0^{(r)}+...+\\beta_nx^{(r)}_n) \\partial \\beta\n\t\\end{equation*}\n\t\n\tThis can be rewritten as a series of partial derivatives:\n\t\\begin{align*}\n\t\\frac{\\partial Q}{\\partial \\beta_0}&=-2(x_0^{(1)}y_1+x_1^{(1)}y_1+...+x_n^{(1)}y_m)\\\\\n\t\\frac{\\partial Q}{\\partial \\beta_1}&=-2(x_0^{(2)}y_1+x_1^{(2)}y_1+...+x_n^{(2)}y_m)\\\\\n\t\\frac{\\partial Q}{\\partial \\beta_2}&=-2(x_0^{(3)}y_1+x_1^{(3)}y_1+...+x_n^{(3)}y_m)\\\\\n\t...\\\\\n\t\\frac{\\partial Q}{\\partial \\beta_n}&=-2(x_0^{(m)}y_1+x_1^{(m)}y_1+...+x_n^{(m)}y_m)\n\t\\end{align*}\n\t\n\tThis can be collapsed as a vector of partial derivatives:\n\t\\begin{equation*}\n\t\\begin{bmatrix}\n\t\t\\frac{\\partial Q}{\\partial \\beta_0}\\\\\n\t\t\\frac{\\partial Q}{\\partial \\beta_1}\\\\\n\t\t\\frac{\\partial Q}{\\partial \\beta_2}\\\\\n\t\t.\\\\\n\t\t.\\\\\n\t\t\\frac{\\partial Q}{\\partial \\beta_n}\n\t\\end{bmatrix}=-2\\left(\\begin{bmatrix}\n\tx_0^{(1)}&x_1^{(1)}&x_2^{(1)}&.&.&x_n^{(1)}\\\\\n\tx_0^{(2)}&x_1^{(2)}&x_2^{(2)}&.&.&x_n^{(2)}\\\\\n\t.&.&.&.&.&.\\\\\n\t.&.&.&.&.&.\\\\\n\tx_0^{(m)}&x_1^{(m)}&x_2^{(m)}&.&.&x_n^{(m)}\n\t\\end{bmatrix}\\right)^T\\begin{bmatrix}\n\ty_1\\\\\n\ty_2\\\\\n\t.\\\\\n\t.\\\\\n\ty_m\n\t\\end{bmatrix}\n\t\\end{equation*}\n\t\n\tIn other words,\n\t\\begin{equation*}\n\t\\frac{\\partial Q}{\\partial \\beta_0}=-2\\frac{\\partial (X\\beta)^Ty}{\\partial \\beta_0}=-2X^Ty\n\t\\end{equation*}\n\t\t\n\tPutting this all together,\n\t\\begin{align*}\n\tJ(\\beta_{0...n}) &= P(\\beta_{0...n})+Q(\\beta_{0...n})\\\\\n\t\\frac{\\partial J}{\\partial\\beta}&=\\frac{\\partial P}{\\partial \\beta}+\\frac{\\partial Q}{\\partial \\beta_0}\\\\\n\t&=2X^TX\\beta-2X^Ty=0\\qquad\\text{and solve for $\\beta$}\\\\\n\t2X^TX\\beta&=2X^Ty\\\\\n\tX^TX\\beta&=X^Ty\\qquad\\text{multiply both sides by $(X^TX)^-$}\\\\\n\t\\beta&=(X^TX)^-X^Ty\\qquad\\blacksquare\n\t\\end{align*}\n\t\n\t\\section{Show that Regularized Linear Regression has a Bayesian interpretation}\n\tGiven data \\textbf{X},\\textbf{y} and assuming a linear model $y=\\beta^Tx$ with a prior distribution over $\\beta$ given by a normal distribution with mean 0, show that the $\\beta$ that maximizes the probability of having obtained the data is given by:\n\t\\begin{equation*}\n\t\\beta=(X^TX+\\lambda I)^- X^Ty\n\t\\end{equation*}\n\twhere $\\lambda$ depends on the variance of the prior distribution.\n\t\n\t\\subsection{Solution}\n\t\\subsubsection{Using Bayes' theorem to rephrase maximum likelihood estimation}\n\tThe maximum likelihood estimator discussed \\textbf{2.1.4} can be related to the most probable Bayes estimator given a uniform prior distribution. The maximum \\textit{a posteriori} estimate is the vector of parameters $\\beta$ that maximize the probability of $\\beta$ given the data. Using Bayes' theorem to write this:\n\t\\begin{equation*}\n\t\\Pr(\\beta|x_1, x_2,...,x_n)=\\frac{h(x_1, x_2,...,x_n|\\beta)\\Pr(\\beta)}{\\Pr(x_1, x_2,...,x_n)}\n\t\\end{equation*}\n\twhere $\\Pr(\\beta)$ is the prior distribution for the parameters $\\beta$ and $\\Pr(x_1, x_2,...,x_n)$ is the probability of obtaining the data. The denominator is independent of $\\beta$, so the Bayesian estimator is obtained by maximizing $h(x_1, x_2,...,x_n|\\beta)\\Pr(\\beta)$ with respect to $\\beta$.\n\t\n\tIn the derivation of the cost function in \\textbf{2.1.4}, the Bayesian estimator could be considered to correspond to the maximum likelihood estimator for a uniform prior distribution of $\\beta$s given by $\\Pr(\\beta)\\sim Uniform(0,\\beta)$. In other words, it is solving for $\\Pr(data|\\beta)$, i.e., the probability of obtaining the data given the parameters $\\beta$.\n\t\n\tIn contrast to finding $\\Pr(data|\\beta)$, here the problem is written as finding $\\Pr(\\beta|data)$, which is derived using Bayes' theorem and \\textbf{prior} knowledge (i.e., a prior) of the distribution of $\\beta$.\n\t\n\tIn \\textbf{Exercise 3}, the prior distribution of the $\\beta$ vector is given as $\\Pr(\\beta)\\sim Normal(0,\\beta)$. Therefore, the Bayesian estimator can be rewritten as:\n\t\\begin{align*}\n\t\\Pr(\\beta|data)&=\\frac{\\Pr(data|\\beta)*prior}{\\Pr(data)}\\\\\n\t\\Pr(\\beta|x_1, x_2,...,x_n)&=h(x_1, x_2,...,x_n|\\beta)\\Pr(\\beta)\n\t\\end{align*}\n\tagain ignoring the denominator because it is independent of $\\beta$.\n\t\n\t\\subsubsection{Maximum \\textit{a posteriori} estimator}\n\tThe maximum \\textit{a posteriori} extimator is then given by:\n\t\\begin{equation*}\n\t\\mathcal{L}(\\beta|X)=\\Pr(X|\\beta)\\Pr(\\beta)\n\t\\end{equation*}\n\twhere $\\mathcal{L}$ is the likelihood, $X$ is the design matrix (i.e., the data), $\\beta$ is the vector of model parameters, and $\\Pr(\\beta)$ is given by the normal distribution as described above.\n\t\n\tThe likelihood of the model parameters given the data is the joint probability of each individual data point multiplied by the prior:\n\t\\begin{equation*}\n\t\\mathcal{L}(\\beta|X)=\\Pr(\\beta)\\prod_{i=1}^{m}\\Pr(y_i|x_i,\\beta)\n\t\\end{equation*}\n\t\n\tAs before, the log-likelihood is easier to work with:\n\t\\begin{align}\n\t\\ln\\mathcal{L}(\\beta|X)&=\\ln\\left[\\Pr(\\beta)\\prod_{i=1}^{m}\\Pr(y_i|x_i,\\beta)\\right]\\\\\n\t&=\\ln\\Pr(\\beta)+\\sum_{i=1}^{m}\\ln\\left[\\Pr(y_i|x_i,\\beta)\\right]\n\t\\end{align}\n\t\n\tFrom \\textbf{2.1.4} above, the second term $\\sum_{i=1}^{m}\\ln\\left[\\Pr(y_i|x_i,\\beta)\\right]$ is the sum of squared residuals $\\sum_{i=1}^{m}(y_i-\\beta^Tx_i)^2$.\n\t\n\tTo gain an intuition of how the first term can be written as a sum, assume the parameters $\\beta$ are distributed normally and independently around the origin with variance $\\sigma^2_\\beta$, as given:\n\t\\begin{align*}\n\t\\Pr(\\beta)&=\\prod_{i=0}^{n}\\Pr(\\beta_i)\\\\\n\t&=\\frac{1}{2\\pi\\sigma_\\beta^2}\\exp\\left(-\\frac{\\sum_{i=0}^{n}\\beta_i^2}{2\\sigma_\\beta^2}\\right)\\\\\n\t&=\\frac{1}{2\\pi\\sigma_\\beta^2}\\exp\\left(-\\frac{\\beta^T\\beta}{2\\sigma_\\beta^2}\\right)\\qquad\\text{written as a vector}\\\\\n\t\\ln\\Pr(\\beta)&=-\\frac{1}{2\\sigma_\\beta^2}\\beta^T\\beta\\qquad\\text{taking the $\\ln()$ of both sides}\n\t\\end{align*}\n\t\n\tPlugging this back into equation (2) above and rewriting the sum of least squares in matrix form (see \\textbf{2.1.5}), we obtain the below. Recall that the objective can be multiplied by any scalar without affecting the optimum:\n\t\\begin{align*}\n\t\\ln\\mathcal{L}(\\beta|X)&=-\\frac{1}{2\\sigma_\\beta^2}\\beta^T\\beta-\\left(\\frac{1}{2\\sigma_\\epsilon^2}(y-X\\beta)^{T}(y-X\\beta)\\right)\\\\\n\t&=-\\frac{\\sigma_\\epsilon^2}{\\sigma_\\beta^2}\\beta^T\\beta-(y-X\\beta)^{T}(y-X\\beta)\n\t\\end{align*}\n\t\n\tRather than maximizing the above function, the signs can be reversed and the function minimized:\n\t\\begin{align*}\n\t\\ln\\mathcal{L}(\\beta|X)&=\\frac{\\sigma_\\epsilon^2}{\\sigma_\\beta^2}\\beta^T\\beta+(y-X\\beta)^{T}(y-X\\beta)\\qquad\\text{set $\\frac{\\sigma_\\epsilon^2}{\\sigma_\\beta^2}=\\lambda$}\\\\\n\t&=\\beta^{T}X^TX\\beta+\\lambda\\beta^T\\beta-2\\beta^TX^Ty\\\\\n\t\\end{align*}\n\t\n\tThe first and third terms' partial derivatives with respect to $\\beta$  were proven above in \\textbf{Exercise 2}:\n\t\\begin{equation*}\n\t2X^TX\\beta-2X^Ty\n\t\\end{equation*}\n\t\n\tThe second term's partial derivative with respect to $\\beta$ is:\n\t\\begin{equation*}\n\t2\\lambda\\beta\n\t\\end{equation*}\n\t\n\tPutting this all together:\n\t\\begin{equation*}\n\t\\frac{\\partial\\mathcal{L}}{\\partial\\beta}=2X^TX\\beta-2X^Ty+2\\lambda\\beta\n\t\\end{equation*}\n\tSet the derivative equal to 0 to minimize, and then solve for $\\beta$. The $\\lambda$ term, recall, depends on the variance of the prior distribution:\n\t\\begin{align*}\n\t0&=X^TX\\beta-X^Ty+\\lambda\\beta\\\\\n\tX^Ty&=X^TX\\beta+\\lambda\\beta\\\\\n\tX^Ty&=(X^TX+\\lambda I)\\beta\\\\\n\t\\beta&=(X^TX+\\lambda I)^-X^Ty\n\t\\qquad\\blacksquare\n\t\\end{align*}\n\\end{document}\n", "meta": {"hexsha": "028338f413e6d7915ca4afbd5dc95d0314f70b2d", "size": 18445, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex files/Derivation of the Normal Equation.tex", "max_stars_repo_name": "mazin-abdelghany/coursera-machine-learning", "max_stars_repo_head_hexsha": "5b2d6fa46c1e68314054623c13b06e0ef96776ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex files/Derivation of the Normal Equation.tex", "max_issues_repo_name": "mazin-abdelghany/coursera-machine-learning", "max_issues_repo_head_hexsha": "5b2d6fa46c1e68314054623c13b06e0ef96776ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex files/Derivation of the Normal Equation.tex", "max_forks_repo_name": "mazin-abdelghany/coursera-machine-learning", "max_forks_repo_head_hexsha": "5b2d6fa46c1e68314054623c13b06e0ef96776ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.8830845771, "max_line_length": 376, "alphanum_fraction": 0.6526429927, "num_tokens": 7211, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7231225840472864}}
{"text": "\\subsection{Linear Approximations with the Gradient}\r\n\\noindent\r\nThe 4th gradient property can be generalized a bit further. Suppose we have $f(x,y,z)$, $\\vec{r}(u,v) = \\langle x(u,v), y(u,v), z(u,v) \\rangle$, and $g(u,v) = f\\circ\\vec{r}(u,v)$.\r\n\\begin{equation*}\r\n\t\\frac{\\partial g}{\\partial u} = \\frac{\\partial f}{\\partial x}\\frac{\\partial x}{\\partial u} + \\frac{\\partial f}{\\partial y}\\frac{\\partial y}{\\partial u} + \\frac{\\partial f}{\\partial z}\\frac{\\partial z}{\\partial u}\r\n\\end{equation*}\r\n\\noindent\r\nWe can rewrite our linear approximation as $\\Delta z\\approx\\nabla f\\cdot\\langle \\Delta x, \\Delta y\\rangle$.\\\\\r\nIn fact, we how have a way to find derivatives of $f\\circ\\vec{r}(t)$.\r\n\\begin{equation*}\r\n\t\\frac{\\mathrm{d}f}{\\mathrm{d}t} = \\frac{\\partial f}{\\partial x}\\frac{\\mathrm{d}x}{\\mathrm{d}t} + \\frac{\\partial f}{\\partial y}\\frac{\\mathrm{d}y}{\\mathrm{d}t} = \\nabla f \\cdot \\langle x^{\\prime}(t), y^{\\prime}(t) \\rangle\r\n\\end{equation*}", "meta": {"hexsha": "f8080c218e768de3a0b6bfcb1d1b1a995a5c7cbf", "size": 946, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/linearApproximationsGradient.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/linearApproximationsGradient.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/linearApproximationsGradient.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 78.8333333333, "max_line_length": 221, "alphanum_fraction": 0.6606765328, "num_tokens": 337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896845856298, "lm_q2_score": 0.7853085758631158, "lm_q1q2_score": 0.7231040358713885}}
{"text": "Mathematical models used to simulate water distribution systems are subject to uncertainty. \nEffective characterization of uncertainty is critical for reliable analysis with simulation-based studies. \nParticularly for contamination incidents, uncertainty quantification is needed to effectively \nuse simulation tools that provide insights into response actions. \nHydraulic parameters that might cause uncertainty include: \n(1) customer demands at each node and time, (2) operational controls (e.g., valve settings, pump curves), (3) \ninfrastructure topography and characteristics (e.g., missing pipes or junctions, effective pipe diameters) and (4) initial conditions (e.g., tank levels, pump statuses). \nWater quality parameters that might cause uncertainty include: \n(1)  initial water quality, (2) contaminant species, (3) contaminant reaction dynamics, (4) the amount\nof contaminant injected, (5) injection location, (6) injection time and (7) injection duration.\n\nThe \\code{uq} subcommand examines the effect of hydraulic and water quality uncertainty on the extent of contamination in terms of the identification of the contamination source. \nThis subcommand can be used to quantify uncertainty after running source identification using the Bayesian probability based formulation (Section \\ref{sec.bayesian_algorithm}). Given a particular confidence level, nodes can be categorized according to their probability of contamination. Nodes whose contamination probability, $\\gamma_n$, that are above a \nthreshold are labeled with respect to their contamination state as LY for ``likely yes,'' LN for``likely no'' and UN for ``unknown.''  \nFor example, for a 95\\% confidence level: \n\n\\[ \\left\\{ \\begin{array}{ll}\n         \\gamma_n \\geq 0.975 & \\mbox{LY},\\\\\n        0.025\\leq \\gamma_n \\leq 0.975 & \\mbox{UN}, \\\\\n        \\gamma_n \\leq 0.025 & \\mbox{LN} \\end{array} \\right. \n\\] \n\nWith the \\code{uq} subcommand \nthe effects of uncertainty in customer demand, isolation valve status, bulk reaction rate coefficient and \ncontaminant injection location, start time, duration and rate can be studied on the size and location of the contamination incident.\n\nA flowchart representation of the \\code{uq} subcommand is shown in Figure \\ref{fig:uq_flowchart}. Given a list of EPANET 2.00.12 compatible network models (INP format) \ncoupled with a list of injection scenarios (TSG format), the \\code{uq} subcommand\nruns Monte Carlo simulations to estimate the probability that each node in the network is contaminated.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[scale=0.30]{graphics/uq_flowchart.png}\n\t\\caption{Uncertainty quantification flowchart.}\n\t\\label{fig:uq_flowchart}\n\\end{figure}\n\n\\section{Uncertainty Quantification Method}\\label{uqn_algorithms}\nThe \\code{uq} subcommand runs an ensemble of scenarios where each scenario is defined using an INP and TSG file. The INP and TSG files \ncontain the hydraulic and water quality parameters for the scenario.  \nThe results are used to compute the probability that each node is contaminated, using the following equation:\n\\begin{equation}\n\\gamma_n = \\sum_{s \\in S} \\delta_{s,n}\\beta_s\n\\label{nodeprob}\n\\end{equation}\nwhere $\\gamma_n $ is the probability that node $n$ is contaminated, $\\beta_s$ is the probability of scenario $s$ and $\\delta_{s,n}$ is a binary parameter that is $1$ if scenario $s$ contaminates node $n$, and $0$ otherwise. The values of $\\delta_{s,n}$ are determined from the simulations over the full potential scenario set, and the values for $\\beta_s$ are determined using equation~\\eqref{source_probability} based on previous measurements provided in the measurements file. If no measurements file is provided, then the values for $\\beta_s$ are assumed to be uniform. A threshold value is used to decide whether a node is contaminated or not in a single scenario.\n\n\\section{\\code{uq} Subcommand}\\label{sec.uq_subcommand}\n\nThe \\code{uq} subcommand is executed using the following command line:\n\\begin{unknownListing}\nwst uq <configfile>\n\\end{unknownListing}\nwhere \\code{configfile} is a WST configuration file in the YAML format.\n\nThe \\code{---help} option prints information about this subcommand,\nsuch as usage, arguments and a brief description:\n\\begin{unknownListing}\nwst uq --help\n\\end{unknownListing}\n\n\\subsection{Configuration File}\n\nThe \\code{uq} subcommand generates a template configuration\nfile using the following command line:\n\n\\begin{unknownListing}\nwst uq --template <configfile>\n\\end{unknownListing}\n\nThe \\code{uq} template configuration file is shown in\nFigure \\ref{fig:uq_template}. Brief descriptions of the\noptions are included in the template after the \\# sign.\n\n\\begin{figure}[h]\n  \\unknownInputListing{examples/uq_config.yml}{}{1}{17}\n  \\caption{The \\code{uq} configuration template file.}\n  \\label{fig:uq_template}\n\\end{figure}\n\n\\subsection{Configuration Options}\\label{sec.uq_subcommand.config_options}\n\nFull descriptions of the WST configuration options used by the \\code{uq} subcommand are listed below.\n\\input{examples/uq_config}\n\n\\subsection{Subcommand Output}\nThe \\code{uq} subcommand creates two YAML files called <output prefix>\\_uq\\_scenarios.yml and <output prefix>\\_uq\\_nodes.yml that contain\na list of probabilities for the scenarios and nodes, respectively.\nThe log file named <output prefix>uq\\_output.log contains basic debugging information. \n\n\\section{Uncertainty Quantification Example}\n\nA list of EPANET 2.00.12 INP and TSG files are required to run the \\code{uq} subcommand. The configuration file for this example, uq\\_ex1.yml, is shown in Figure \\ref{fig:uq_confex1}. \n\n\\begin{figure}[h]\n  \\unknownInputListing{../../examples/uq_ex1.yml}{}{1}{17}\n  \\caption{The \\code{uq} configuration file for example 1.}\n  \\label{fig:uq_confex1}\n\\end{figure}\n\nThe file with the list of scenarios for this example is shown in Figure \\ref{fig:uq_scenarios}.\n\n\\begin{figure}[h]\n  \\unknownInputListing{../../examples/Net3/uq/list_scenarios.dat}{}{1}{3}\n  \\caption{List of scenarios.}\n  \\label{fig:uq_scenarios}\n\\end{figure}\n\nSummary information is printed to the screen, as shown in Figure \\ref{fig:uq_out1}.\n\n\\begin{figure}[h]\n  \\unknownInputListing{examples/uq/uq_ex1_screen_output.txt}{}{1}{31}\n  \\caption{Screen output for example 1.}\n  \\label{fig:uq_out1}\n\\end{figure}\n\nThe results from the \\code{uq} subcommand can be represented in probability maps using the \\code{visualization} subcommand (Chapter 11). \n", "meta": {"hexsha": "e730783c11bdf95d00b5ce65e21229f35ae3d678", "size": 6406, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/wst/uq.tex", "max_stars_repo_name": "USEPA/Water-Security-Toolkit", "max_stars_repo_head_hexsha": "6b6b68e0e1b3dcc8023b453ab48a64f7fd740feb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-06-10T18:04:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-05T18:11:40.000Z", "max_issues_repo_path": "doc/wst/uq.tex", "max_issues_repo_name": "USEPA/Water-Security-Toolkit", "max_issues_repo_head_hexsha": "6b6b68e0e1b3dcc8023b453ab48a64f7fd740feb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/wst/uq.tex", "max_forks_repo_name": "USEPA/Water-Security-Toolkit", "max_forks_repo_head_hexsha": "6b6b68e0e1b3dcc8023b453ab48a64f7fd740feb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-09-24T19:04:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-05T18:11:43.000Z", "avg_line_length": 54.2881355932, "max_line_length": 668, "alphanum_fraction": 0.7781767093, "num_tokens": 1614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.7956581073313276, "lm_q1q2_score": 0.7229491922231875}}
{"text": "\n\\appendix\n\n\\section{A Python prototype}\n\nObservation in last paragraph allows us to code a bunch of Python functions, \nlying on top of SymPy module, that produce \n$\\mathcal{C}_{\\equiv 2}^{(\\alpha+1)}$ consuming $\\mathcal{C}_{\\equiv 2}^{(\\alpha)}$:\nthe construction is strictly \\emph{blockwise}, according theorems stated\nin previous section. Here's the implementation:\n\n\\begin{adjustwidth}{-1cm}{0cm}\n    \\inputminted{python}{../../PhD/projects/recurrences-unfolding/sympy-notebook/colouring.py}\n\\end{adjustwidth}\n\nThe following is a session that builds $\\mathcal{C}_{\\equiv 2}^{(7)}$:\n\\begin{minted}{python}\n    catalan_matrix = Matrix([\n        [1,0,0,0,0,0], \n        [1,1,0,0,0,0], \n        [2,2,1,0,0,0], \n        [5,5,3,1,0,0], \n        [14,14,9,4,1,0], \n        [42,42,28,14,5,1]])\n    alpha = 2\n    bound = 2**alpha\n    pc = catalan_matrix[:bound, :bound]\n    pc = pc.applyfunc(lambda c: c % 2)\n    # _ = colour_matrix(pc)\n    pc = build_modular_catalan(pc)\n    # _ = colour_matrix(pc)\n    pc = build_modular_catalan(pc)\n    # _ = colour_matrix(pc)\n    pc = build_modular_catalan(pc)\n    # _ = colour_matrix(pc)\n    pc = build_modular_catalan(pc)\n    # _ = colour_matrix(pc)\n    pc = build_modular_catalan(pc)\n    # _ = colour_matrix(pc)\n\\end{minted}\n\nFunction \\mintinline{python}|build_modular_catalan| implements given theorems to avoid\ncomputing convolutions and series expansion: the starting building block in the \nabove session is $\\mathcal{C}_{\\equiv 2}^{(2)}$, hence it is very quick. \nIf desired, it is possible to display coloured triangles as svg images:\njust uncomment \\mintinline{python}|# _ = colour_matrix(pc)| lines.\n", "meta": {"hexsha": "31d4306f409d299a733450a56831a0bd5cfb2ad6", "size": 1642, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modular-article/appendix-python-implementation.tex", "max_stars_repo_name": "massimo-nocentini/master-thesis", "max_stars_repo_head_hexsha": "0d82bfcc82c92512d0795f286256a19f39b9b1f9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "modular-article/appendix-python-implementation.tex", "max_issues_repo_name": "massimo-nocentini/master-thesis", "max_issues_repo_head_hexsha": "0d82bfcc82c92512d0795f286256a19f39b9b1f9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "modular-article/appendix-python-implementation.tex", "max_forks_repo_name": "massimo-nocentini/master-thesis", "max_forks_repo_head_hexsha": "0d82bfcc82c92512d0795f286256a19f39b9b1f9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.9361702128, "max_line_length": 94, "alphanum_fraction": 0.6741778319, "num_tokens": 519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7229491908284763}}
{"text": "\\section{Clustering}\n\n% ===\n\\emph{\\textit{k}-means:}\\enskip\n$\\arg\\min_\\theta \\sum_{i\\leq n} \\norm{\\bm x_i - \\theta_{c(\\bm x_i)}}^2$\n\n% ===\n\\subsection{Mixture Models}\n\n\\textit{Assume:}\\enskip\n$\\bm x \\sim p(\\bm x\\mid \\pi_{1\\ldots k}, \\theta_{1\\ldots k}) = \\sum_{c\\leq k} \\pi_c p(\\bm x \\mid \\bm\\theta_c)$\n\n\\textbf{Find:}\n$\\highlight{\\hat\\theta = \\arg\\max_\\theta  p(\\mathcal X\\mid \\pi,\\theta)}\n\\color{gray} = \\prod_{\\bm x} p(\\bm x\\mid \\pi,\\theta)$\n\n\\emph{Gaussian Mixtures:}\\enskip\n$\\to$\\enskip\n$p(\\bm x \\mid \\theta_c) = p(\\bm x \\mid \\bm\\mu, \\bm\\Sigma)$\n\nIntroduce \\textit{latent indicator variables} for mode assignments $M_{\\bm x c} \\in \\{0,1\\}$. Then, the \\textbf{log-likelihood:}\n\n$L(\\mathcal X, \\bm M \\mid \\bm\\theta) = \\sum_{\\bm x} \\sum_{c\\leq k} M_{\\bm x c} \\log (\\pi_c p(\\bm x \\mid \\bm\\theta_c))$\n\n% ===\n\\subsubsection{EM-Algorithm \\normalfont\\sffamily for Gaussian Mixtures}\n\n\\begin{highlightbox}\n    \\textbf{E-step:}\\enskip\n    Calculate\n    \n    $Q(\\bm\\theta; \\bm\\theta^{(t)}) = \\E[\\bm M \\mid \\mathcal X, \\bm\\theta^{(t)}]{L(\\mathcal X, \\bm M \\mid \\bm\\theta)} = \\ldots$ \\\\\n    $= \\sum\\limits_{\\bm x} \\sum\\limits_{c\\leq k} \\paren[\\big]{\n    \\begingroup\n        \\color{OrangeRed} \\underbracket[.7pt][2pt]{\\the\\everymath \\E*[\\bm M \\mid \\mathcal X, \\bm\\theta^{(t)}]{M_{\\bm x c}}}%_{\\gamma_{\\bm x c}}\n    \\endgroup\n    \\cdot \\log \\pi_c p(\\bm x\\mid \\bm\\theta_c) }$\n    \n    where \\highlight*{$\\begingroup\\color{OrangeRed} \\gamma_{\\bm x c} \\endgroup = \\frac{p(\\bm x \\mid c, \\bm\\theta^{(t)}) \\: p(c\\mid \\bm\\theta^{(t)})}{p(\\bm x \\mid \\bm\\theta^{(t)})}$}, \\enskip\n    $\\sum_{c\\leq k} \\gamma_{\\bm x c} = 1$\n    \n    \n    \\textbf{M-step:}\\enskip\n    $\\bm\\theta^{(t+1)} \\in \\arg\\max_{\\bm\\theta} Q(\\bm\\theta; \\bm\\theta^{(t)})$\n    \n    s.t. $\\sum_c \\pi_c = 1$. \\enskip\n    Solve via Lagrangian, yields\n    \n    \\begin{highlightbox*}\n        $\\pi_c {=} \\frac{1}{\\abs{\\mathcal X}} \\sum\\limits_{\\bm x} \\gamma_{\\bm x c}$,\\hfill\n        $\\bm\\mu_c {=} \\frac{\\sum_{\\bm x} \\gamma_{\\bm x c} \\bm x}{\\sum_{\\bm x} \\gamma_{\\bm x c}}$,\\hfill\n        $\\sigma^2_c {=} \\frac{\\sum_{\\bm x} \\gamma_{\\bm x c} (\\bm x - \\bm\\mu_c)^2}{\\sum_{\\bm x} \\gamma_{\\bm x c}}$\n    \\end{highlightbox*}\n\\end{highlightbox}\n\n% ===\n\\subsection{Non-parametric Bayesian Methods}\n\n$\\mathrm{Dir}(\\bm x \\mid \\bm\\alpha) = \\frac{1}{B(\\alpha)} \\prod_{k=1}^n x_k^{\\alpha_k - 1}$,\\enskip\n$B(\\bm\\alpha) = \\frac{ \\prod_{k=1}^n \\Gamma(\\alpha_k)}{\\Gamma(\\sum_{k=1}^n \\alpha_k)}$\n\nRewrite \\textbf{Finite mixture models:}\n\n$p(x) = \\sum_{k=1}^K \\pi_k p(x\\mid \\theta_k)\n= \\int p(x\\mid\\theta) G(\\theta) \\diff\\theta$\n\nwhere $G(\\theta) = \\sum_{k=1}^\\infty \\pi_k \\delta_{\\theta_k}\\!(\\theta)$\n$\\color{gray} \\leftarrow \\text{ discrete distr.}$\n\n\n\\emph{Stick-breaking process:}\n\nDraw $\\theta_k \\sim H$ and $\\beta_k \\sim \\mathrm{Beta}(1,\\alpha)$ for $k{=}1,2,\\ldots$\n\n$\\pi_k = \\beta_k (1 - \\sum_{k=1}^{k-1} \\pi_i)$\n$\\implies \\highlight{\\!\\pi {=} \\{ \\pi_k \\}_{k=1}^\\infty \\sim \\mathrm{GEM}(\\alpha)\\!\\!}$\n\n\\vspace{-2pt}$\\implies\n\\begingroup \\color{gray}\n    \\sum_{k=1}^\\infty \\pi_k \\delta_{\\theta_k}\\!(\\theta) =\n\\endgroup\n\\highlight{G(\\theta) \\sim \\mathrm{DP}(\\alpha, H)}$\n\nSample $\\theta^{(1)}, \\theta^{(2)}, \\ldots$ from $G$.\\enskip\nDenote $\\theta^{(i)} {=} \\theta_{k_i}$.\n\n$\\implies \\theta^{(i)}, \\theta^{(j)}$ with $k_i {=} k_j$ belong to same ``cluster''\n\n\n\\emph{Chinese Rest. Process:}\n\\vspace{-5pt}\n\n$P(\\text{cust}_{n+1} \\text{ joins table } \\tau \\mid \\mathcal P) =\n\\begin{cases}\n    \\frac{\\abs{\\tau}}{\\alpha + n} & \\text{if } \\tau \\in \\mathcal P, \\\\\n    \\frac{\\alpha}{\\alpha + n} & \\text{new table}\n\\end{cases}$\n\n$P(\\text{partition } \\mathcal P)\n= \\frac{\\alpha^{\\abs{\\mathcal P}}}{\\alpha^{(n)}} \\prod_{\\tau\\in\\mathcal P} (\\abs{\\tau} - 1)!$\n\n\\textbf{expec. \\#clusters:}\\enskip\n$\\E{\\bm 1} = \\sum_{i\\leq N} \\frac{\\alpha}{\\alpha + i} \\sim \\mathcal O(\\alpha \\log N)$\n\n\n\\emph{De Finetti:}\n$(X_1, \\ldots, X_n)$ are inftly \\textbf{exchangable} RVs \\textit{if}\n$P(X_1, \\ldots, X_n) = \\int \\paren*{\\prod_{i=1}^n p(X_i \\mid G)} \\diff P(G)$\n\n% Equivalent formulations (?)\n\\iffalse\n    $P(X_1, \\ldots X_n) = \\int P(G) \\prod_{i=1}^n p(X_i \\mid G) \\diff G$\n    \n    $P(X_1, \\ldots X_n) = \\int P(\\theta) \\prod_{i=1}^n p(X_i \\mid \\theta) \\diff\\theta$\n\\fi\n\n\n\\subsubsection{Finite GMM}\n\\begin{enumerate}\n    \\item Cluster centers:\\enskip\n        $\\mu_k \\sim \\Gauss{\\mu_0, \\sigma_0}$\n    \\item Prob's of clusters:\\enskip\n        $\\pi_{1\\ldots K} \\sim \\mathrm{Dir}(\\alpha_{1\\ldots K})$\n    \\item Cluster assignments:\\enskip\n        $z_i \\sim \\mathrm{Categorical}(\\pi_{1\\ldots K})$\n    \\item Coordinates of data:\\enskip\n        $x_i \\sim \\Gauss{\\mu_{z_i}, \\sigma_{z_i}}$\n\\end{enumerate}\n\n\n\\subsubsection{DP Mixture Model (DP-GMM)}\n\\begin{enumerate}\n    \\item Cluster centers:\\enskip\n        $\\mu_k \\sim \\Gauss{\\mu_0, \\sigma_0}$,\\enskip\n        $\\color{gray} k {=} 1, 2, \\ldots$\n    \\item Prob's of clusters:\\enskip\n        $\\pi = (\\pi_1, \\pi_2, \\ldots) \\sim \\mathrm{GEM}(\\alpha)$\n    \\item Cluster assignments:\\enskip\n        $z_i \\sim \\mathrm{Categorical}(\\pi)$\n    \\item Coordinates of data:\\enskip\n        $x_i \\sim \\Gauss{\\mu_{z_i}, \\sigma}$,\\enskip\n        $\\color{gray} i {=} 1 \\ldots N$\n\\end{enumerate}\n\n\\emph{Fitting a DP-MM:}\\enskip\n\\textbf{Collapsed Gibbs sampler}\n\n$p(z_i {=} k \\mid \\bm z_{-i}, \\bm x, \\alpha, \\bm\\mu) \\propto\n\\begingroup \\color{OrangeRed} \\text{Prior} \\endgroup \\times\n\\begingroup \\color{Green} \\text{Likelihood} \\endgroup$\n\\\\\\hfill\n$\\propto \\begin{cases}\n    \\begingroup \\color{OrangeRed}\n        \\frac{\\abs{\\bm x_{-i,k}}}{\\alpha+N-1}\n    \\endgroup\n    \\begingroup \\color{Green}\n        p(x_i \\vert \\bm x_{-i, k}, \\bm\\mu)\n    \\endgroup\n    & \\text{for existing } k\n    \\\\\n    \\begingroup \\color{OrangeRed}\n        \\frac{\\alpha}{\\alpha+N-1}\n    \\endgroup\n    \\begingroup \\color{Green}\n        p(x_i\\vert \\bm\\mu)\n    \\endgroup\n    & \\text{otw.}\n\\end{cases}$\n\n$\\bm x_{-i,c} \\coloneqq \\brace{ x_j \\mid z_j {=} c, j {\\neq} i }$ data assigned to clust. $c$\n\n\n\n% ===\n", "meta": {"hexsha": "72f1fc2885e66f818a6b4c6195c57f8966a84c83", "size": 5900, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/AML20/sections/10_clustering.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/AML20/sections/10_clustering.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/AML20/sections/10_clustering.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7142857143, "max_line_length": 190, "alphanum_fraction": 0.5930508475, "num_tokens": 2386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7229491851542916}}
{"text": "\\chapter{Conditional Probability}\n\nLet's say there is a virus going around, and there is a vaccine for it\nthat requires 2 shots. You are working at a school, and you are\nwondering how effective the vaccines are. Some students are\nunvaccinated, some have had one shot, and some have had two shots. One\nday you test all 644 students to see who has the virus. You end up\nwith the following table:\n\n\\begin{tabular}{c | c c c}\n  & $V_0$ & $V_1$ & $V_2$ \\\\\n  \\hline\n  $T_{+}$ & 88 students & 36 students & 96 students \\\\\n  $T_{-}$ & 92 students & 76 students & 256 students \\\\\n\\end{tabular}\n\nHere are what the symbols mean:\n\n\\begin{itemize}\n\\item $V_0$: student has had zero vaccination shots\n\\item $V_1$: student has had one vaccination shot\n\\item $V_2$: student has had both vaccination shots\n\\item $T_{+}$: student tested positive for the virus\n\\item $T_{-}$: student tested negative for the virus\n\\end {itemize}\n\nSo, for example, your data indicates that there were 76 students who\nhad only one of the two shots and tested negative for the virus.\n\nYour principal has a few questions. The first is ``If I put five\nrandomly choosen students in a study group together, what is the\nprobabilty that one of them has the virus?''\n\nThe first thing you might do is make a new table that shows what is\nthe probability of a randomly choosen student being in any particular\ngroup. You just divide each entry by 644 (the total number of\nstudents).\n\n\\begin{tabular}{c | c c c}\n  & $V_0$ & $V_1$ & $V_2$ \\\\\n  \\hline\n  $T_{+}$ & $p(V_0 \\text{ AND } T_{+}) = 13.7\\%$ & $p(V_1 \\text{ AND } T_{+}) = 5.6\\%$ & $p(V_2 \\text{ AND } T_{+}) = 14.9\\%$\\\\\n  $T_{-}$ & $p(V_0 \\text{ AND } T_{-}) = 14.3\\%$ & $p(V_1 \\text{ AND } T_{-}) = 11.8\\%$ & $p(V_2 \\text{ AND } T_{-}) = 39.8\\%$\n\\end{tabular}\n\n(In this table, I expressed the number as a percentage with a decimal\npoint -- you had to round off the numbers. If you wanted exact answers, you\nwould have keep each as a fraction: 36 students represents\n$\\frac{9}{161}$ of the student body.)\n\n\\section{Marginalization}\n\nNow we can sum across the columns and rows.\n\n\\begin{tabular}{c | c c c | c}\n  & $V_0$ & $V_1$ & $V_2$ & sum \\\\\n  \\hline\n  $T_{+}$ & 0.137 & 0.056 & 0.149 & $p(T_{+}) = 0.342$\\\\\n  $T_{-}$ & 0.143 & 0.118 & 0.398 & $p(T_{+}) = 0.547$\\\\\n  \\hline\n  sum & $p(V_0) = 0.280$ & $p(V_1) = 0.174$ & $p(V_2) = 0.547$ & \n\\end{tabular}\n\nIf a child is choosen randomly from the entire student body, there is\na 34.2\\% that the student has tested positive for the virus. And there is\n17.4\\% chance that the student has one shot of the vaccine.\n\nThis summing of the probabilities across one dimension is known as\n\\textit{marginalizing}. Marginalization is just summing across all the\nvariable that you don't care about. You don't care who has the virus,\njust the probability that a student has not received even one shot of\nthe vaccine? You marginalize all the vaccine statuses.\n\nTo answer the principal's question, the easy thing to do is find the\nanswer of the opposite ``if I put five randomly choosen students in a\nstudy group together, what is the probabilty that \\textit{none} of\nthem has tested positive for the virus?''\n\nThe chance that a randomly choose student doesn't have the virus\n($p(T_{-}$) is 54.7\\%.  Thus the chance that 5 randomly chosen\nstudents don't have the virus is $0.547 \\times 0.547 \\times 0.547\n\\times 0.547 \\times 0.547 = 0.0489$ Thus the probability of the\nopposite is $1.0 - 0.0489 = 0.951$\n\nThe answer, then, is ``If you put 5 kids in a study group together,\nthere is a 95.1 \\% probability that at least one of them has the\nvirus.''\n% KA: https://www.khanacademy.org/math/ap-statistics/probability-ap/stats-conditional-probability/v/testing-independence-from-experimental-data\n\n\\section{Conditional Probability}\n\nNow the principal asks you, ``What if I make a group of 5 kids who\nhave had both shots of the vaccine? What are the odds that one of them\nhas tested positive for the virus?''\n\nThis involves the idea of \\textit{Conditional probability}.  You want\nto know the odds that a student doesn't have the virus given that\nstudent has had both shots of the vaccine.\n\nThere is a mathematical notation for this:\n\n$$p(T_{-} | V_{2})$$\n\nThat is the probability that a student who has had both vaccination\nshots will test negative for the virus.\n\nHow would you calculate this? You would count all the students who had\na positive test \\textit{and} both vaccination shots, which you would\ndivide by the total number of students who had both vaccination shots.\n\n$$p(T_{-} | V_{2}) = \\frac{256}{96 + 256} = \\frac{8}{11} \\approx 72.7\\%$$\n\nIf we are working from the probabilities, you can get the same result\nthis way: Divide the probability that a randomly choosen student had a\npositive test \\textit{and} both vaccination shots by the probabilty\nthat a student had both vaccination shots:\n\n$$p(T_{-} | V_{2}) = \\frac{p(T_{-} \\text{ AND } V_{2})}{p(T_{-})} =  \\frac{0.398}{0.547} \\approx 72.7\\%$$\n\nNotice that this is different from $p( V_{2} | T_{-})$, which is the\nprobability that a student has had both vaccinations, given they\ntested negative for the virus.\n\nBack to the principal's question: \"If you have 5 students who have had\nboth vaccinations, what is the probability that all of them tested\nnegative for the virus?\" The probability that one student is virus-free\nis $\\frac{8}{11}$, so the probability that 5 students are virus-free\nis $\\frac{8}{11}^5 \\approx 0.203$.  So, there is a $79.6\\%$ chance\nthat at least one of the five has the virus.\n% KA: https://www.khanacademy.org/math/statistics-probability/probability-library/conditional-probability-independence/v/calculating-conditional-probability\n\n\\section{Chain Rule for Probability}\n\nYou just used this equality: For any events $A$ and $B$\n\n$$p(A | B) = \\frac{p(A \\text{ AND } B)}{p(B)}$$\n\nThis is more commonly written like this:\n\n$$p(A \\text{ AND } B) = \\frac{p(A | B)}{p(B)}$$\n\nThis is an abstract way of writing the idea, but the idea itself\nis pretty intuitive: The probability that I'm going to buy and ticket\nand win the lottery is equal to the probability that I buy a ticket\ntimes the probability that I win, given that I have bought a ticket.\n(Here $A$ is ``win the lottery'' and $B$ is ``buy a ticket''.)\n\nThis is known as \\textit{The Chain Rule of Probability}.  And we can\nchain together as many events as we want: The probability that you are\ngoing to die in the car that you bought with your winnings from the\nlottery ticket you bought is:\n\n$$p(W \\text{ AND } X \\text{ AND } Y \\text{ AND } Z) = p( W | X \\text{ AND } Y \\text{ AND } Z) p( X |  Y \\text{ AND } Z) p (Y | Z) p(Z)$$\n\nwhere\n\n\\begin{itemize}\n\\item $W =$ Dying in car accident\n\\item $X =$ Buying a car with lottery winnings\n\\item $Y =$ Winning the lottery\n\\item $Z =$ Buying a lottery ticket\n\\end{itemize}\n\nIn English, then, the equation says:\n\n``The probability that you will die in a car accident, buy a car with\nlottery winnings, win the lottery, and buy a lottery ticket is equal\nto the probability that you buy a lottery ticket times the probability\nthat you win the lottery (given that you have bought a ticket) times\nthe probability that buy a car with those lottery winnings (given that\nbought a ticket and won) times the probability that you crash that car\n(given that you have bought the car, won the lottery, and bought a\nticket).''\n\n% KA: https://www.khanacademy.org/math/ap-calculus-ab/ab-differentiation-2-new/ab-3-1a/v/chain-rule-introduction\n\n\n\n  \n", "meta": {"hexsha": "549692f3f25acb482870af5d8a8d941c44a2c2d3", "size": 7453, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/DiscreteProbability/conditional_prob-en_US.tex", "max_stars_repo_name": "hillegass/sequence", "max_stars_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/DiscreteProbability/conditional_prob-en_US.tex", "max_issues_repo_name": "hillegass/sequence", "max_issues_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/DiscreteProbability/conditional_prob-en_US.tex", "max_forks_repo_name": "hillegass/sequence", "max_forks_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 41.4055555556, "max_line_length": 156, "alphanum_fraction": 0.7152824366, "num_tokens": 2211, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835493924953, "lm_q2_score": 0.8652240964782011, "lm_q1q2_score": 0.7228804991455222}}
{"text": "% Copyright ©2015 The gonum Authors. All rights reserved.\n% Use of this source code is governed by a BSD-style\n% license that can be found in the LICENSE file.\n\n\\documentclass{article}\n\n\\usepackage{amsmath,amsfonts}\n\\usepackage[margin=4cm]{geometry}\n\n\\title{Louvain algorithm for undirected and directed graphs}\n\\author{The {\\tt gonum} Authors}\n\n\\begin{document}\n\n\\maketitle\n\nThe algorithm attempts to find communities (highly connected sub-graphs),\nand it does this by minimising the modularity function\n\\begin{equation}\n\tQ(c) = \\frac{1}{2m}\\sum_i\\sum_j\\left[ A_{ij} - \\gamma \\frac{k_ik_j}{2m} \\right] \\delta_{ij}(c),\n\\end{equation}\nwhere $c$ is a partition of nodes into subsets or communities,\n$A_{ij}$ is the edge weight between nodes $i$ and $j$, \n$\\gamma$ is a tuning parameter,\n\\begin{equation}\nm = \\frac{1}{2}\\sum_i\\sum_jA_{ij},\n\\end{equation}\n\\begin{equation}\nk_i = \\sum_j{A_{ij}},\n\\end{equation}\nand \n\\begin{equation}\n\t\\delta_{ij}(c) = \\left \\{ \\begin{array}{ll}\n\t1 & \\text{if} \\quad  c(i) = c(j) \\\\\n\t0 & \\text{otherwise} \\end{array} \\right ..\n\\end{equation}\nHere $c(i)$ denotes the community to which node $i$ belongs \nin the partitioning $c$.\n\nThe algorithm finds a hierarchical community structure by iterating \nbetween two phases:\n\\begin{enumerate}\n\t\\item Find a set of communities that minimise $Q$.\n\t\\item Construct a new graph, whose nodes are the communities \n\tfound in the preceding phase one step.\n\\end{enumerate}\nEach iteration of these two phases is called a `pass'.\nIn this way, the algorithm obtains a nested community structure, \nwhere at each level $Q$ is minimised for the relevant graph.\nWe consider this process in more detail, in particular looking \nat phase one first in the first pass, when each node is a single\nnode, and then how this generalises to later passes when each node \nis a community.\n\n\\section{Undirected Graphs}\n\n\\subsection{Initial Pass}\n\\label{sec:initialPass}\n\nThe initial pass is simple as the initial pass uses the original graph, \nand in all following passes graphs constructed in the previous pass's \nphase two are used.\nHere we will consider this initial simple formulation for phase one, and\nin Section~\\ref{sec:laterPasses} we consider how this generalises for \npasses two and onwards. \nPhase one works by initially allocating each node to a separate community,\nand then iterating through each node $a$ and checking if moving it into \na different community $\\beta$ will reduce $Q$.\nIf there are possible moves that will reduce $Q$, $a$ is moved into the \nthe community which will generate the largest reduction in $Q$. \nThis process is continued until there are no moves left to reduce $Q$ \nfurther, meaning a local minimum for $Q$ has been achieved. \nThen the algorithm moves to phase two (constructing a new graph where\neach node in the new graph is a community in the old graph). \n\nNote that we assume the original graph to be simple and undirected.\nFirst, we introduce some notation that will be useful:\nLet $c(i)$ denote the community to which node $i$ belongs, \nand let $\\alpha$ be the community that the node $a$ mentioned above\nbelongs to, i.e., $\\alpha = c_a$.\nThen we define\n\\newcommand{\\Stot}[1]{\\Sigma_{\\text{tot}}^{#1}}\n\\begin{equation}\n\t\\Stot{\\alpha} = \\sum_{i \\in \\alpha}\\sum_{j}A_{ij} = \\sum_{i \\in \\alpha}k_i,\n\\end{equation}\n\\newcommand{\\kin}[2]{k_{#1}^{#2}}\n\\begin{equation}\n\t\\kin{i}{\\alpha} = \\sum_{j \\in \\alpha}A_{ij},\n\\end{equation}\nand\n\\newcommand{\\Sin}[1]{\\Sigma_{\\text{in}}^{#1}}\n\\begin{equation}\n\t\\Sin{\\alpha} = \\sum_{i \\in \\alpha}\\sum_{j \\in \\alpha}A_{ij} = \\sum_{i \\in \\alpha}\\kin{i}{\\alpha}.\n\\end{equation}\n\nWe are interested in how $Q$ will change if we move a node $a$ from its \ncurrent community $\\alpha$, to a new community $\\beta$.\nThis will have two effects, it will remove the terms from $Q$ \nrelated to $a$ in $\\alpha$, which we will call $Q^-$ and it will add terms \nrelated to $a$ in $\\beta$, which we will call $Q^+$. \nThe total change in $Q$ caused by the movement of $a$ from $\\alpha$ to $\\beta$ is \n\\begin{equation}\n\t\\Delta Q = Q^{+} - Q^{-},\n\\end{equation}\nwhere\n\\begin{align*}\nQ^- &= \\frac{1}{2m}\\left[ \\left( A_{aa} - \\gamma \\frac{k_a^2}{2m} \\right) \n+ 2\\sum_{i \\in \\alpha, \\, i \\neq a} \\left( A_{ia} - \\gamma \\frac{k_ik_a}{2m} \\right) \\right] \\\\\n\t&= \\frac{1}{2m}\\left[ \\left( A_{aa} - \\gamma \\frac{k_a^2}{2m} \\right) \n+ 2 \\left( \\kin{a}{\\alpha} -A_{aa}\\right) - \\gamma \\frac{2k_a}{2m}\\sum_{i \\in \\alpha, \\, i \\neq a} k_i \\right] \\\\\n\t&= \\frac{1}{2m}\\left[ \\left( A_{aa} - \\gamma \\frac{k_a^2}{2m} \\right) \n+ 2 \\left( \\kin{a}{\\alpha} -A_{aa}\\right) - \\gamma \\frac{2k_a}{2m}\\left( \\Stot{\\alpha} - k_a \\right)  \\right], \\\\\n\\end{align*}\nand\n\\begin{align*}\nQ^+ &= \\frac{1}{2m}\\left[ \\left( A_{aa} - \\gamma \\frac{k_a^2}{2m} \\right) \n+ 2\\sum_{i \\in \\beta} \\left( A_{ia} - \\gamma \\frac{k_ik_a}{2m} \\right) \\right] \\\\\n\t\t&= \\frac{1}{2m}\\left[ \\left( A_{aa} - \\gamma \\frac{k_a^2}{2m} \\right) \n+ 2\\kin{a}{\\beta} - \\gamma \\frac{2k_a}{2m}\\sum_{i \\in \\beta} k_i \\right] \\\\\n\t\t&= \\frac{1}{2m}\\left[ \\left( A_{aa} - \\gamma \\frac{k_a^2}{2m} \\right) \n+ 2\\kin{a}{\\beta} - \\gamma \\frac{2k_a\\Stot{\\beta}}{2m} \\right]. \\\\\n\\end{align*}\nThe first term in both these expressions ($Q^-$ and $Q^+$) is the same, and so cancels:\n\\begin{equation}\n\\Delta Q = \\frac{1}{2m}\\left[ \\left( 2\\kin{a}{\\beta} - \\gamma \\frac{2k_a\\Stot{\\beta}}{2m} \\right) \n\t\t- \\left( 2 \\left( \\kin{a}{\\alpha} -A_{aa}\\right) - \\gamma \\frac{2k_a}{2m}\\left( \\Stot{\\alpha} - k_a \\right) \\right) \\right]. \n\\end{equation}\n \n\\subsection{Later Passes}\n\\label{sec:laterPasses}\n\nIn phase two a `meta-graph' is constructed where nodes correspond to \nthe communities found in the preceding phase one step, and edge weight\nbetween two such communities (nodes, in the meta-graph)\n$\\alpha$ and $\\beta$ are defined to be\n\\begin{equation}\n\tA_{\\alpha \\beta}^* = \\sum_{i \\in \\alpha}\\sum_{j \\in \\beta}A_{ij}.\n\t\\label{eqn:Aij*}\n\\end{equation} \nNote that $i$ and $j$ refer to nodes in the original graph, not nodes \nin the previous graph, and so holds any meta-graph, not just the first.\nAlso note that this definition of $A^*_{\\alpha \\beta}$ allows for \n$A^*_{\\alpha \\alpha}$ to be non-zero as\n\\begin{equation}\nA_{\\alpha \\alpha}^* = \\sum_{i \\in \\alpha}\\sum_{j \\in \\alpha}A_{ij} = \\Sin{\\alpha}.\n\\end{equation} \n\nIn this newly constructed graph, $\\alpha$ and $\\beta$ are nodes, but \nalso refer to communities (sets of nodes) in the original graph, and I \nuse these two interpretations interchangeably.\nThis should be the only ambiguous bit of notation in this document, I hope.\n\nThe results of Section~\\ref{sec:initialPass} generalise to these meta-graphs,\nand the generalised results mirror those of Section~\\ref{sec:initialPass} closely\n-- I distinguish the new results from those of Section~\\ref{sec:initialPass} by a \nsuperscript $*$.\nI use $i$ and $j$ to denote nodes of the original graph as in Section~\\ref{sec:initialPass}, \nand use $z$ and $w$ to denote nodes of the meta-graph (communities of the original).\nI use analogous notation to Section~\\ref{sec:initialPass}, $c^*(z)$, to \ndenote the community to which node $z$ of the meta-graph belongs, \nand let $\\mathfrak{a}$ be the community that the node $\\alpha$ belongs to \n($c^*(\\alpha) = \\mathfrak{a}$), i.e.\n\\begin{equation}\n\t\\mathfrak{a} = \\{z | c^*(z) = c^*(\\alpha) \\}.\n\\end{equation}\n\nGiven this notation, we can observe that\n\\begin{equation}\nm^* = \\frac{1}{2}\\sum_{z}\\sum_{w}{A_{zw}^*} = \\frac{1}{2}\\sum_{z}\\sum_{w}{\\sum_{i \\in z}\\sum_{j \\in w}A_{ij}} = \\frac{1}{2}\\sum_i\\sum_jA_{ij} = m,\n\\end{equation}\n\\begin{equation}\nk_{z}^* = \\sum_{w}{A_{zw}^*} =  \\sum_{w}{\\sum_{i \\in z}\\sum_{j \\in w}A_{ij}} = \\sum_{i \\in z}\\sum_{j}A_{ij} = \\Stot{z},\n\\end{equation}\n\\begin{equation}\n\t\\Stot{\\mathfrak{a} *} = \\sum_{z \\in \\mathfrak{a}}\\sum_{w}A_{zw}^* = \\sum_{z \\in \\mathfrak{a}}k_z^* = \\sum_{z \\in \\mathfrak{a}}\\Stot{z},\n\\end{equation}\n\\begin{equation}\n\t\\kin{z}{\\mathfrak{a} *} = \\sum_{w \\in \\mathfrak{a}}{A_{zw}^*} = \\sum_{w \\in \\mathfrak{a}}{\\sum_{i \\in z}\\sum_{j \\in w}A_{ij}},\n\\end{equation}\nand\n\\begin{equation}\n\\Sin{\\mathfrak{a} *} = \\sum_{z \\in \\mathfrak{a}}\\sum_{w \\in \\mathfrak{a}}A_{zw}^* = \\sum_{z \\in \\mathfrak{a}}\\kin{z}{\\mathfrak{a} *} = \\sum_{z \\in \\mathfrak{a}}\\sum_{w \\in \\mathfrak{a}}{\\sum_{i \\in z}\\sum_{j \\in w}A_{ij}}.\n\t%\\label{eqn:Sin}\n\\end{equation}\n\nIf we let $\\mathfrak{b}$ denote the community to which we are considering moving $\\alpha$,\nthen the expression for $\\Delta Q$ from Section~\\ref{sec:initialPass} trivially generalises to\n\\begin{equation}\n\\Delta Q = \\frac{1}{2m}\\left[ \\left( 2 \\kin{\\alpha}{\\mathfrak{b} *} - \\gamma \\frac{2k_{\\alpha}^*\\Stot{\\mathfrak{b} *}}{2m} \\right) \n\t\t- \\left( 2\\left( \\kin{\\alpha}{\\mathfrak{a} *} - A_{\\alpha \\alpha}^* \\right) - \\gamma \\frac{2k_{\\alpha}^*}{2m} \\left( \\Stot{\\mathfrak{a} *} - k_{\\alpha}^* \\right ) \\right) \\right] \\\\\n\\end{equation}\n\n\\section{Directed Graphs}\n\\label{sec:directedGraphs}\n\nIt is of interest to consider how this generalises to directed graphs.\nIf we are to treat incoming and outgoing nodes equally, there are several\nthoughts on how to extend the algorithm to directed graphs, of which we \nwill explore three: \n\\begin{itemize}\n\t\\item Construct an undirected graph first, and then use the undirected case.\n\t\\item Generalise the expressions from the undirected case to the directed case, \n\twe will consider two different suggestions for such generalisations. \n\\end{itemize}\nWe will show that one of the two `generalisation of expressions' approaches is \nequivalent to constructing an undirected graph, and the other is not.\n\n\\subsection{Construction of an undirected graph}\nA simple approach to generalising to directed graphs is to construct \nan undirected graph with edge weights\n\\begin{equation}\nA_{ij} = B_{ij} + B_{ji},\n\\label{eqn:undirectedAB}\n\\end{equation}\nand simply use the undirected algorithm.\nAnother suggestion is to average the directed edges to make\nan undirected graph, i.e. to use a directed graph with edge weights\n\\begin{equation}\nA_{ij} = \\frac{B_{ij} + B_{ji}}{2}.\n\\end{equation}\nThis raises an important question: does scaling all edge weights across \nthe entire graph by a constant affect the results of the algorithm?\nHopefully not, but worth checking.\nWe can follow this through the results for the undirected graph by \nsubstituting $A_{ij}^{(1)} = pA_{ij}$, $p \\in \\mathbb{R}$, and \ndistinguishing the new expressions by a superscript ${(1)}$. These\nnew expressions are:\n\\begin{equation}\nm^{(1)} = \\frac{1}{2}\\sum_i\\sum_jpA_{ij}  = p\\frac{1}{2}\\sum_i\\sum_j A_{ij} = pm ,\n\\end{equation}\n\\begin{equation}\nk_i^{(1)} = \\sum_j{pA_{ij}} = p\\sum_j{A_{ij}} = pk_i,\n\\end{equation}\nand so\n\\begin{align*}\n\tQ^{(1)}(c) &= \\frac{1}{2pm}\\sum_i\\sum_j\\left[ pA_{ij} - \\gamma \\frac{pk_ipk_j}{2pm} \\right] \\delta_{ij}(c) \\\\\n\t&= \\frac{1}{2m}\\sum_i\\sum_j\\left[ A_{ij} - \\gamma \\frac{k_ik_j}{2m} \\right] \\delta_{ij}(c) \\\\\n\t&= Q(c)\n\\end{align*}\nNote that as we have shown $Q^{(1)} = Q$ there is no need to go into the remainder of the terms \ninvolved in the algorithm, as they all derive from $Q$.\n\n\\subsection{First generalisation of expressions approach}\n\nOne suggested extension to directed graphs is to modify the expressions \ninvolved by adding the `from' case and the `to' case for each term. \nIf we let $B_{ij}$ be the edge weight between nodes $i$ and $j$ in \nthe directed graph, and distinguishing these extended expressions by \na superscript $(2)$, the extended expressions become:\n\\begin{equation}\nm^{(2)} = \\frac{1}{2}\\left ( \\sum_i\\sum_jB_{ij} + \\sum_i\\sum_jB_{ji}\\right)  = \\frac{1}{2}\\sum_i\\sum_j \\left( B_{ij} + B_{ji} \\right) ,\n\\end{equation}\n\\begin{equation}\nk_i^{(2)} = \\sum_jB_{ij} + \\sum_jB_{ji} = \\sum_j{\\left( B_{ij} + B_{ji} \\right)},\n\\end{equation}\nand similarly\n\\begin{equation}\n\tQ^{(2)}(c) = \\frac{1}{2m}\\sum_i\\sum_j\\left[ \\left( B_{ij} + B_{ji} \\right) - \\gamma \\frac{k_i^{(2)}k_j^{(2)}}{2m} \\right] \\delta_{ij}(c).\n\\end{equation}\n\nNote how this is equivalent to the construction of an undirected graph as \nper Equation~(\\ref{eqn:undirectedAB}). Similarly to above, \nthere is no need to go into the remainder of the terms \ninvolved in the algorithm, as they all derive from $Q$.\n\n\n\\subsection{Second generalisation of expressions approach}\n\nAnother approach to generalising the expressions to the \ndirected case, that still treats incoming and outgoing edges \nas equally important, is to propose an alternative modularity \nexpression:\n\\newcommand{\\dkin}[1]{k_{#1}^{\\text{in}}}\n\\newcommand{\\dkout}[1]{k_{#1}^{\\text{out}}}\n\\begin{equation}\nQ^{(3)}(c) = \\frac{1}{2m}\\sum_i\\sum_j\\left[ 2B_{ij} - 2\\gamma \\frac{\\dkin{i}\\dkout{j}}{2m} \\right] \\delta_{ij}(c), \\\\\n\\end{equation}\nwhere \n\\begin{equation}\n\\dkout{i} = \\sum_j{B_{ij}} \n\\quad \\quad \\text{and} \\quad \\quad\n\\dkin{i} = \\sum_j{B_{ji}},\n\\end{equation}\nso $k_i^{(2)} = \\dkin{i} + \\dkout{i}$.\nNote I leave the factor of two in the expression for $Q^{(3)}$ so that it \nremains as comparable to that for $Q^{(2)}$ as possible.\nThere is no need for alternative $m$, as it will still be the same as above.\n$Q^{(3)}$ will differ from $Q^{(2)}$ in two ways.\nFirstly, as $k_i^{(2)} = \\dkin{i} + \\dkout{i}$, \n\\begin{align*}\n\\sum_i\\sum_j k_i^{(2)} k_j^{(2)} \\delta_{ij}(c)  &= \\sum_i\\sum_j  (\\dkin{i} + \\dkout{i}) (\\dkin{j} + \\dkout{j}) \\delta_{ij}(c) \\\\\n &= \\sum_i\\sum_j \\left[ (\\dkin{i}\\dkin{j} + \\dkout{i}\\dkout{j}) + (\\dkin{i}\\dkout{j} + \\dkin{j}\\dkout{i}) \\right] \\delta_{ij}(c). \\\\\n &= \\sum_i\\sum_j \\left[ (\\dkin{i}\\dkin{j} + \\dkout{i}\\dkout{j}) + 2\\dkin{i}\\dkout{j} \\right] \\delta_{ij}(c), \\\\\n\\end{align*}\nand similarly,\n\\begin{equation}\n\\sum_i\\sum_j  \\left( B_{ij} + B_{ji} \\right) \\delta_{ij}(c) = 2\\sum_i\\sum_j B_{ij} \\delta_{ij}(c).\n\\end{equation}\nFrom these two expressions, we can see that \n\\begin{equation}\nQ^{(3)} - Q^{(2)} = \\frac{1}{2m}\\sum_i\\sum_j \\gamma \\frac{\\dkin{i}\\dkin{j} + \\dkout{i}\\dkout{j}}{2m} \\delta_{ij}(c).\n\\end{equation}\n\n\n\\section{Directed Graphs in more detail}\n\\label{sec:directedGraphsDetail}\n\nIn Section \\ref{sec:directedGraphs} we essentially showed three \nthings:\n\\begin{itemize}\n\t\\item How an undirected graph could be constructed from a directed\n\tgraph, thereby allowing the undirected algorithm to be used for \n\tdirected graphs.\n\t\\item How scaling all edge weights by a non-zero constant would not \n\taffect the modularity function.\n\t\\item An alternative approach to extending the algorithm to \n\tdirected graphs that is not equivalent to first reducing it \n\tto an undirected graph.\n\\end{itemize}\nIt is this third point that we will explore here.\nAnalogously to Sections \\ref{sec:initialPass} and \\ref{sec:laterPasses} we will \nbreak this up into the initial pass and the later passes.\n\n\\subsection{Initial pass}\n\\label{sec:initialPassDirected}\n\nContinuing with the notation of Section \\ref{sec:initialPass}, in which \n$c(i)$ denotes the community to which node $i$ belongs, \nand $\\alpha = c(a)$, we define\n\\newcommand{\\dinStot}[1]{\\Sigma_{\\text{tot}}^{\\text{in}(#1)}}\n\\newcommand{\\doutStot}[1]{\\Sigma_{\\text{tot}}^{\\text{out}(#1)}}\n\\begin{equation}\n\t\\doutStot{\\alpha} = \\sum_{i \\in \\alpha}\\sum_{j}B_{ij} = \\sum_{i \\in \\alpha}\\dkout{i}\n\t\\quad \\quad \\text{and} \\quad \\quad\n\t\\dinStot{\\alpha} = \\sum_{i \\in \\alpha}\\sum_{j}B_{ji} = \\sum_{i \\in \\alpha}\\dkin{i},\n\\end{equation}\n\\newcommand{\\dinkin}[2]{k_{#1}^{\\text{in}(#2)}}\n\\newcommand{\\doutkin}[2]{k_{#1}^{\\text{out}(#2)}}\n\\begin{equation}\n\t\\doutkin{i}{\\alpha} = \\sum_{j \\in \\alpha}B_{ij}\n\t\\quad \\quad \\text{and} \\quad \\quad\n\t\\dinkin{i}{\\alpha} = \\sum_{j \\in \\alpha}B_{ji},\n\\end{equation}\nand we will entertain one more ambiguous notation choice:\n%\\newcommand{\\Sin}[1]{\\Sigma_{\\text{in}}^{#1}}\n\\begin{equation}\n\t\\Sin{\\alpha} = \\sum_{i \\in \\alpha}\\sum_{j \\in \\alpha}B_{ij} = \\sum_{i \\in \\alpha}\\doutkin{i}{\\alpha} = \\sum_{i \\in \\alpha}\\dinkin{i}{\\alpha}.\n\\end{equation}\n\nAnalogously to Section \\ref{sec:initialPass}, we are interested in how \n$Q^{(3)}$ will change if we move a node $a$ from its \ncurrent community $\\alpha$, to a new community $\\beta$, \nand analogously this will have two effects -- it will remove the terms \nfrom $Q^{(3)}$ related to $a$ in $\\alpha$, which we will call $Q^{-(3)}$ \nand it will add terms related to $a$ in $\\beta$, which we will call $Q^{+(3)}$. \nThe total change in $Q^{(3)}$ caused by the movement of $a$ from $\\alpha$ to $\\beta$ is \n\\begin{equation}\n\t\\Delta Q^{(3)} = Q^{+(3)} - Q^{-(3)},\n\\end{equation}\nwhere\n\\begin{align*}\nQ^{-(3)} &= \\frac{1}{2m}\\left[ \\left( 2B_{aa} - 2\\gamma \\frac{\\dkin{a}\\dkout{a}}{2m} \\right) \n+ \\sum_{i \\in \\alpha, \\, i \\neq a} \\left( 2B_{ia} + 2B_{ai} - 2\\gamma \\frac{\\dkin{i}\\dkout{a}}{2m} - 2\\gamma \\frac{\\dkin{a}\\dkout{i}}{2m} \\right) \\right] \\\\\n\t\t\t\t &= \\frac{1}{2m}\\left[ \\left( 2B_{aa} - 2\\gamma \\frac{\\dkin{a}\\dkout{a}}{2m} \\right) \n+ 2(\\dinkin{a}{\\alpha} - B_{aa}) + 2(\\doutkin{a}{\\alpha} - B_{aa}) \\hdots \\right . \\\\\n & \\quad \\quad \\quad \\quad \\quad \\quad \\left .\n- \\frac{2\\gamma\\dkout{a}}{2m} (\\dinStot{\\alpha} - \\dkin{a}) - \\frac{2\\gamma\\dkin{a}}{2m} (\\doutStot{\\alpha} - \\dkout{a}) \\right] \\\\\n\\end{align*}\nand\n\\begin{align*}\nQ^{+(3)} &= \\frac{1}{2m}\\left[ \\left( 2B_{aa} - 2\\gamma \\frac{\\dkin{a}\\dkout{a}}{2m} \\right) \n+ \\sum_{i \\in \\beta} \\left( 2B_{ia} + 2B_{ai} - 2\\gamma \\frac{\\dkin{i}\\dkout{a}}{2m} - 2\\gamma \\frac{\\dkin{a}\\dkout{i}}{2m} \\right) \\right] \\\\\n\t\t\t\t &= \\frac{1}{2m}\\left[ \\left( 2B_{aa} - 2\\gamma \\frac{\\dkin{a}\\dkout{a}}{2m} \\right) \n+ 2\\dinkin{a}{\\beta} + 2\\doutkin{a}{\\beta} - \\frac{2\\gamma\\dkout{a}}{2m} \\dinStot{\\beta}  - \\frac{2\\gamma\\dkin{a}}{2m} \\doutStot{\\beta} \\right] \\\\\n\\end{align*}\nSimilarly to Section \\ref{sec:initialPass}, the first term in both these expressions is the same, and so cancels, leaving:\n\\begin{align*}\n\\Delta Q^{(3)} &= \\frac{2}{2m}\\left[ \n\\left( \\dinkin{a}{\\beta} + \\doutkin{a}{\\beta} - \\frac{\\gamma\\dkout{a}}{2m} \\dinStot{\\beta}  - \\frac{\\gamma\\dkin{a}}{2m} \\doutStot{\\beta} \\right) \\right. \\\\\n& \\hspace{-1cm}\n- \\left. \\left( (\\dinkin{a}{\\alpha} - B_{aa}) + (\\doutkin{a}{\\alpha} - B_{aa}) - \\frac{\\gamma\\dkout{a}}{2m} (\\dinStot{\\alpha} - \\dkin{a}) - \\frac{\\gamma\\dkin{a}}{2m} (\\doutStot{\\alpha} - \\dkout{a})  \\right) \\right] \\\\\n &= \\frac{2}{2m}\\left[ (\\dinkin{a}{\\beta}-\\dinkin{a}{\\alpha}) + (\\doutkin{a}{\\beta}-\\doutkin{a}{\\alpha}) + 2B_{aa} \\right. \\\\\n& \\hspace{-1cm} \\left.\n- \\frac{\\gamma\\dkout{a}}{2m} (\\dinStot{\\beta}-\\dinStot{\\alpha}) - \\frac{\\gamma\\dkin{a}}{2m} (\\doutStot{\\beta} - \\doutStot{\\alpha}) - \\frac{2\\gamma\\dkin{a}\\dkout{a}}{2m} \\right]\n\\end{align*}\n\n\n\n\\subsection{Later passes}\n\\label{sec:laterPassesDirected}\n\nIn phase two a `meta-graph' is constructed where nodes correspond to \nthe communities found in the preceding phase one step, and edge weight\nbetween two such communities (nodes, in the meta-graph)\n$\\alpha$ and $\\beta$ are defined to be\n\\begin{equation}\n\tB_{\\alpha \\beta}^* = \\sum_{i \\in \\alpha}\\sum_{j \\in \\beta}B_{ij}.\n\t\\label{eqn:Bij*}\n\\end{equation} \nNote that $i$ and $j$ refer to nodes in the original graph, not nodes \nin the previous graph, and so holds any meta-graph, not just the first.\nAlso note that this definition of $B^*_{\\alpha \\beta}$ allows for \n$B^*_{\\alpha \\alpha}$ to be non-zero, in fact\n\\begin{equation}\nB_{\\alpha \\alpha}^* = \\sum_{i \\in \\alpha}\\sum_{j \\in \\alpha}B_{ij} = \\Sin{\\alpha}.\n\\end{equation} \n\nIn this newly constructed graph, $\\alpha$ and $\\beta$ are nodes, but \nalso refer to communities (sets of nodes) in the original graph, and I \nuse these two interpretations interchangeably, completely analogously to \nSection \\ref{sec:laterPasses}.\n\nThe results of Section~\\ref{sec:initialPassDirected} generalise to these meta-graphs,\nand the generalised results mirror those of Section~\\ref{sec:initialPassDirected} closely\n-- I distinguish the new results from those of Section~\\ref{sec:initialPassDirected} by a \nsuperscript $*$.\nI use $i$ and $j$ to denote nodes of the original graph as in Sections~\\ref{sec:initialPass}\nand \\ref{sec:initialPassDirected}, \nand use $z$ and $w$ to denote nodes of the meta-graph (communities of the original).\nI use analogous notation to Section~\\ref{sec:initialPass}, $c^*(z)$, to \ndenote the community to which node $z$ of the meta-graph belongs, \nand let $\\mathfrak{a}$ be the community that the node $\\alpha$ belongs to, \ni.e., $\\mathfrak{a} = c^*(\\alpha) $.\n\nGiven this notation, we get all the same results as in \\ref{sec:laterPasses}, but \neach split into two cases `out' and `in', separating by direction, essentially, so\n\\newcommand{\\dkinStar}[1]{k_{#1}^{\\text{in} *}}\n\\newcommand{\\dkoutStar}[1]{k_{#1}^{\\text{out} *}}\n\\begin{equation}\n\\dkoutStar{z} = \\sum_w{B_{zw}^*} = \\sum_w\\sum_{i \\in z}\\sum_{j \\in w}B_{ij} = \\sum_{i \\in z}\\sum_jB_{ij} = \\doutStot{z},\n\\end{equation}\n\\begin{equation}\n\\dkinStar{z}  = \\sum_w{B_{wz}^*} = \\sum_w\\sum_{i \\in z}\\sum_{j \\in w}B_{ji} = \\sum_{i \\in z}\\sum_jB_{ji} = \\dinStot{z},\n\\end{equation}\n\\newcommand{\\dinStotStar}[1]{\\Sigma_{\\text{tot}}^{\\text{in}(#1) *}}\n\\newcommand{\\doutStotStar}[1]{\\Sigma_{\\text{tot}}^{\\text{out}(#1) *}}\n\\begin{equation}\n\t\\doutStotStar{\\mathfrak{a}} = \\sum_{z \\in \\mathfrak{a}}\\sum_{w}B_{zw}^* = \\sum_{z \\in \\mathfrak{a}}\\dkoutStar{z} = \\sum_{z \\in \\mathfrak{a}}\\doutStot{z},\n\\end{equation}\n\\begin{equation}\n\t\\dinStotStar{\\mathfrak{a}}  = \\sum_{z \\in \\mathfrak{a}}\\sum_{w}B_{wz}^* = \\sum_{z \\in \\mathfrak{a}}\\dkinStar{z}  = \\sum_{z \\in \\mathfrak{a}}\\dinStot{z},\n\\end{equation}\n\\newcommand{\\dinkinStar}[2]{k_{#1}^{\\text{in}(#2) *}}\n\\newcommand{\\doutkinStar}[2]{k_{#1}^{\\text{out}(#2) *}}\n\\begin{equation}\n\t\\doutkinStar{z}{\\mathfrak{a}} = \\sum_{w \\in \\mathfrak{a}}{B_{zw}^*} = \\sum_{w \\in \\mathfrak{a}}{\\sum_{i \\in z}\\sum_{j \\in w}B_{ij}},\n\\end{equation}\n\\begin{equation}\n\t\\dinkinStar{z}{\\mathfrak{a}}  = \\sum_{w \\in \\mathfrak{a}}{B_{wz}^*} = \\sum_{w \\in \\mathfrak{a}}{\\sum_{i \\in z}\\sum_{j \\in w}B_{ji}},\n\\end{equation}\nand\n\\begin{equation}\n\\Sin{\\mathfrak{a} *} = \\sum_{z \\in \\mathfrak{a}}\\sum_{w \\in \\mathfrak{a}}A_{zw}^* = \\sum_{z \\in \\mathfrak{a}}\\kin{z}{\\mathfrak{a} *} = \\sum_{z \\in \\mathfrak{a}}\\sum_{w \\in \\mathfrak{a}}{\\sum_{i \\in z}\\sum_{j \\in w}A_{ij}}.\n\t%\\label{eqn:Sin}\n\\end{equation}\n\nIf we let $\\mathfrak{b}$ denote the community to which we are considering moving $\\alpha$,\nthen the expression for $\\Delta Q$ from Section~\\ref{sec:initialPassDirected} simply generalises as\n\\begin{align*}\n\\Delta Q^{(3)} &= \\frac{2}{2m}\\left[ (\\dinkinStar{\\alpha}{\\mathfrak{b}}-\\dinkinStar{\\alpha}{\\mathfrak{a}}) + (\\doutkinStar{\\alpha}{\\mathfrak{b}}-\\doutkinStar{\\alpha}{\\mathfrak{a}}) + 2B_{\\alpha\\alpha}^* \\right. \\\\\n& \\hspace{-1cm} \\left.\n- \\frac{\\gamma\\dkoutStar{\\alpha}}{2m} (\\dinStotStar{\\mathfrak{b}}-\\dinStotStar{\\mathfrak{a}}) - \\frac{\\gamma\\dkinStar{\\alpha}}{2m} (\\doutStotStar{\\mathfrak{b}} - \\doutStotStar{\\mathfrak{a}}) - \\frac{2\\gamma\\dkinStar{\\alpha}\\dkoutStar{\\alpha}}{2m} \\right]\n\\end{align*}\n\n\n\\end{document}\n", "meta": {"hexsha": "046c02baf0ef3a650876db5a98828d0192409dc9", "size": 22627, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "vendor/github.com/gonum/graph/community/louvain.tex", "max_stars_repo_name": "weherdh/origin", "max_stars_repo_head_hexsha": "8e9a9ec4909c7a55ddeb920928687ea842c94d9f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-10-04T14:40:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T10:38:04.000Z", "max_issues_repo_path": "graph/community/louvain.tex", "max_issues_repo_name": "mingrammer/gonum", "max_issues_repo_head_hexsha": "b555074219fc5ed0bf39429799953c12f1a78810", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 40, "max_issues_repo_issues_event_min_datetime": "2017-03-15T21:33:58.000Z", "max_issues_repo_issues_event_max_datetime": "2017-05-10T21:54:52.000Z", "max_forks_repo_path": "graph/community/louvain.tex", "max_forks_repo_name": "mingrammer/gonum", "max_forks_repo_head_hexsha": "b555074219fc5ed0bf39429799953c12f1a78810", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-04-21T15:03:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-20T18:08:53.000Z", "avg_line_length": 48.4518201285, "max_line_length": 254, "alphanum_fraction": 0.6762275158, "num_tokens": 8266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7228804768985442}}
{"text": "\\section{Introduction}\n\n\nConsider the pure bending of an isotropic and homogeneous thin clamped\nplate. \nLet $\\Omega$ denote the midline of the plate, $\\Gamma$ denote the \nboundary of $\\Omega$ and $w$ denote the vertical displacement.\nThe buckling eigenvalue problem consists of finding \nvalues $k^{2}$ such that the boundary value problem\n\n\\begin{align}\n\\Delta (\\Delta + k^2) w &= 0 \\quad \\textrm{in} \\quad \\Omega \\label{eq:buck1} \\; , \\\\\nw &= 0 \\quad \\textrm{on} \\quad \\Gamma \\label{eq:buck2} \\; ,\\\\\n\\dwdn &=0 \\quad \\textrm{on} \\quad \\Gamma \\label{eq:buck3} \n\\end{align}\nhas a non-trivial solution $w$. \nIt is well known that the values $k^2$ are necessarily real \nand positive and there is a countable collection\nof such values \n$0 < k_{1}^{2} \\leq k_{2}^2 \\leq \\ldots \\uparrow \\infty$,\ncounting multiplicites.\n\n\\begin{remark}\n  When $k = i\\alpha$, the differential equation\n  \\cref{eq:buck1} is known as the modified biharmonic\n  equation. As there appears to be no preferred\n  name for the equation with real-valued $k$,\n  we will refer to \\cref{eq:buck1} as the\n  oscillatory biharmonic equation.\n\\end{remark}\n\nThe eigenvalues (and eigenfunctions)\nof the boundary value problem \\cref{eq:buck1,eq:buck2,eq:buck3}\ndescribe the critical buckling load (and deflection)\nof a thin plate under\na compressive force applied along the edge. While the\nisotropy and homogeneity assumptions are restrictive,\nthe equations are still of interest in materials design\n(CITATIONS). The analytical properties of the eigenvalues and\neigenfunctions are also of interest from a mathematical\nperspective, often as they contrast with the eigenvalues\nand eigenmodes of an idealized drum (CITATIONS). For instance,\nit is well-known that the first eigenfunction of the\ndrum problem (i.e. the eigenvalue problem of the Laplace\nequation with homogeneous Dirichlet boundary conditions)\nis either nonpositive or nonnegative on any domain.\nIn contrast, it is possible for the first buckling\neigenfunction of a convex domain with analytic boundary\nto take both positive and negative values \\cite{antunes2011buckling}.\n\nA related problem is that of the Stokes eigenvalue problem\nwhich is to find values $k^2$ such that\n\\begin{align}\n\\Delta (\\Delta + k^2) w &= 0 \\quad \\textrm{in} \\quad \\Omega \\label{eq:stokes1} \\; , \\\\\n\\nabla w &= 0 \\quad \\textrm{on} \\quad \\Gamma \\label{eq:stokes2} \\; ,\\\\\n\\end{align}\nhas a non-trivial solution $w$.\nWhile the buckling eigenvalues are identical to the Stokes\neigenvalues on simply connected domains, on multiply\nconnected domains it turns out that the buckling eigenvalues\nare a subset of the Stokes eigenvalues.\n\nIn this note, we derive integral conditions on the stream function \nassociated with the Stokes eigenfunction\nto determine whether the Stokes eigenvalue is also a \nbuckling eigenvalue on multiply connected domains.\nThus, given the Stokes eigenvalues \nof the domain and the stream functions associated with the \ncorresponding eigenfunctions, \nthe buckling eigenvalues can be determined using a simple\npost-processing step.\nGiven $k^2$ to be a Stokes eigenvalue, we also derive\na well-conditioned second-kind integral equation for computing \nthe stream function associated with the \nStokes eigenfunction. \n\n\nNumerical simulations have long played an important\nrole in the analyses described above and there are a number\nof available methods (note that some of the references\nincluded here are written in terms of the related\nStokes eigenvalue problem, which has equivalent\neigenvalues on simply connected domains). We do not\nseek to review the literature here but will provide\nsome context for the present work. Finite element methods\nare ubiquitous in mechanical engineering applications\nand are flexible with respect to both the governing\nequations and the shape of the domain. Such a method\nwould first obtain a ``weak'' form of the equations\n\\cref{eq:buck1,eq:buck2,eq:buck3} and then \napproximate the solution space in some\nfinite dimensional basis, resulting in a discrete model\nfor the buckling problem.\nThe eigenvalues $k^2$ are then\napproximated by the eigenvalues of the discrete\nmodel \\cite{johnson1974beam,rannacher1979nonconforming,\n  jia2009approximation,carstensen2014guaranteed}.\n\n\\note{needs work}\n\nThe rest of this paper is organized as follows ...\n\n", "meta": {"hexsha": "8322ab7c88f205982268ed272936a7048f6de1a4", "size": 4285, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/draft-01/01intro.tex", "max_stars_repo_name": "askhamwhat/biharm-evals", "max_stars_repo_head_hexsha": "d836302f544670b3d899bd91ea4cb49e9afb6a75", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/draft-01/01intro.tex", "max_issues_repo_name": "askhamwhat/biharm-evals", "max_issues_repo_head_hexsha": "d836302f544670b3d899bd91ea4cb49e9afb6a75", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/draft-01/01intro.tex", "max_forks_repo_name": "askhamwhat/biharm-evals", "max_forks_repo_head_hexsha": "d836302f544670b3d899bd91ea4cb49e9afb6a75", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.6019417476, "max_line_length": 86, "alphanum_fraction": 0.7841306884, "num_tokens": 1107, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467643431002, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7228249176068167}}
{"text": "\\section{Linear Transformation and Matrix}\n\n\\subsection{Linear Transformation}\n\n\n\\begin{definition}\n\tA \\cindex{linear transformation}  from $V$ to $W$ is a function $T: V \\rightarrow W$ that:\n\t\\begin{enumerate}\n\t\t\\item $T(x+y) = T(x) + T(y)$\n\t\t\\item $T(c x) = c T(x)$\n\t\\end{enumerate}\n\\end{definition}\n\nThe two linear transformation verification criteria could be combined into one: prove that \n\\begin{equation}\n    T(cx + y) = cTx+Ty\n\\end{equation}\n\n\nThe \\cindex{identity transformation}  $\\mathrm{I}_v : V \\rightarrow V$ is defined as $\\mathrm{I}_v(x) = x$.\n\nThe \\cindex{zero transformation}  $T_0: V \\rightarrow W$ is defined as $T_0 = 0$.\n\n\\begin{definition}\n\tLet $T:V \\rightarrow W$ be linear. the \\cindex{null space}  $\\nullspace{T}$ of $T$ is the set $\\set{x \\in V : T(x) = 0}$. It is also called the \\cindex{kernel} of $T$. It measures how much  information is lost by the transformation $T$.\n\\end{definition}\n\n\\begin{definition}\n\tThe \\cindex{range}  of $T$ is defined as $\\rangespace{T} = \\set{ {T(x):x \\in V}}$. It measures how much information is retained by the transformation $T$.\n\\end{definition}\n\n\\begin{theorem}\n\tLet $T: V \\rightarrow W$ be linear. If $\\beta=\\set{v_i}$ is a basis for $V$, then\n\t\\begin{equation}\n\t\t\\rangespace{T} =  \\vectorspan{T(\\beta)} = \\vectorspan{\\set{T(v_i)}}\n\t\\end{equation}\n\\end{theorem}\n\n\\begin{definition}\n\tLet $T: V \\rightarrow W$ be linear. the \\cindex{nullity}  of $T$ is the dimension of $\\nullspace{T}$. The \\cindex{rank} \\label{rankdefinition} of $T$ is the dimension of $\\rangespace{T}$.\n\\end{definition}\n\n\\begin{theorem}[\\cindex{Dimension Theorem}]\n\tIf $V$ is finite dimensional, $T:V\\rightarrow W$ is linear, then\n\t\\begin{equation}\n\t\t\\dimension{\\nullspace{T}} + \\dimension{\\rangespace{T}} = \\dimension{T}\n\t\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\n\texpand nullity set to a basis and prove the image of extra parameters are independent.\n\\end{proof}\n\n\\begin{theorem}\\label{uniquelineartransformation}\n\tLet $V:\\set{v_i}$ and $W:\\set{w_i}$ be vector space over $F$, and their dimensions are the same. Then there exists a unique linear transformation $T:V \\rightarrow W$ such that $T(v_i) = w_i$.\n\\end{theorem}\n\n\\begin{proof}\n    For $\\displaystyle x = \\sum_{i=1}^{n} a_i v_i$, define $T:V \\rightarrow W$ that $\\displaystyle T(x) = \\sum_{i=1}^n a_i w_i$.\n\\end{proof}\n\n\\thmref{uniquelineartransformation} is useful when proving two functions are the same.\n\n\n\\begin{theorem}\n    Let $T: V \\rightarrow W$ be a linear transformation. $T$ is one-to-one if and only if $\\nullspace{T} = \\{ 0 \\}$.    \n\\end{theorem}\n\n\n\n\n\n\n\n% matrix representation\n\\subsection{Matrix Representation}\n\n\\begin{definition}\n\tA \\cindex{ordered basis}  for $V$ is a basis for $V$ with a specific order.\n\\end{definition}\n\n\\begin{definition}\n\t$\\set{e_1, e_2, \\dots, e_n}$ is the \\cindex{standard ordered basis}  for $F^n$. $\\set{1, x, \\dots, x^n}$ is the \\cindex{standard ordered basis}  for $P_n (F)$.\n\\end{definition}\n\n\\begin{definition}\n\tLet $\\beta = \\set{u_1, u_2, \\dots, u_n}$ be an ordered basis for $V$. $\\forall x \\in V$, let $\\set{a_1, a_2, \\dots, a_n}$ be the unique scalar such that\n\t\\begin{equation*}\n\t\tx = \\sum_{i=1}^n a_i u_i\n\t\\end{equation*}\n\t\n\tthe \\cindex{coordinate vector}  of $x$ relative to $\\beta$, is defined as \n\t\\begin{equation}\n\t\t\\coordinate{x}_\\beta = \\begin{bmatrix}\n\t\ta_1 \\\\\n\t\ta_2 \\\\\n\t\t\\vdots \\\\\n\t\ta_n\n\t\t\\end{bmatrix}\n\t\\end{equation}\n\t\n\tNote that $\\coordinate{u_i}_\\beta = e_i$.\n\\end{definition}\n\n\\begin{definition}\n\tLet $V$ with ordered basis $\\beta=\\set{v_i}$, $W$ with ordered basis $\\gamma:\\set{w_i}$, $T:V \\rightarrow W$ be linear. There exists unique scala $a_{ij} \\in F$ such that\n\t\\begin{equation}\n\t\tT(v_j) = \\sum_{i=1}^m a_{ij} w_j\n\t\\end{equation}\n\t\n\tThe $m \\times n$ \\cindex{matrix}\\footnote{The word matrix is Latin for womb which is the same root as matrimony. The idea is that a matrix is a receptacle for holding numbers. } $A$ defined by $A_{ij}=a_{ij}$ is the \\cindex{matrix representation}  of $T$ in the ordered basis $\\beta$ and $\\gamma$ and write $A=\\coordinate{T}_\\beta^\\gamma$. If $V = W$ and $\\beta = \\gamma$, we write $A=\\coordinate{T}_\\beta$.\n\t\\qed\n\\end{definition}\n\n\tNote that the $j$-th column of $A$ is $\\coordinate{T(v_j)}_\\gamma$: $\\coordinate{T}_\\beta^\\gamma = \\coordinate{\\dots, \\coordinate{T(v_j)}_\\gamma, \\dots}$.\n\t\n\tNote that $T$ is the relationship between two basis. The value of $T$ might be the same as basis, for example when they are operators on $F^n$, but $T$ and basis are different objects. It is easy to confuse them, especially on $F^n$.\n\t\n\n\\begin{theorem}\n\tIf $\\mathrm{U},T:V \\rightarrow W$ are linear transformation that $\\coordinate{\\mathrm{U}}_\\beta^\\gamma = \\coordinate{T}_\\beta^\\gamma$, then $\\mathrm{U} = T$.\n\\end{theorem}\n\n\\begin{definition}\n\t\\cindex{$\\mathcal{L}(V,W)$} contains all linear transformation from $V$ to $W$.\n\\end{definition}\n\n\\begin{theorem}\n\tLet $T$,$\\mathrm{U}$ be linear transformation over $V$ and $W$, \n\t\\begin{enumerate}\n\t\t\\item $\\coordinate{T + \\mathrm{U}}_\\beta^\\gamma = \\coordinate{T}_\\beta^\\gamma  + \\coordinate{\\mathrm{U}}_\\beta^\\gamma $\n\t\t\\item $\\coordinate{a T }_\\beta^\\gamma = a \\coordinate{T}_\\beta^\\gamma $ for all scalar $a$\n\t\\end{enumerate}\n\\end{theorem}\n\n\\begin{theorem}\n\tlet $T:V\\rightarrow W$ and $\\mathrm{U}:W\\rightarrow Z$. Then $\\mathrm{UT}: V \\rightarrow Z$ is linear.\n\\end{theorem}\n\n\\begin{definition}\n\tLet $T:V\\rightarrow W$ and $\\mathrm{U}:W\\rightarrow Z$ be linear transformation. $A_{m \\times n}=\\coordinate{\\mathrm{U}}_\\alpha^\\beta$ and $B_{n \\times p}=\\coordinate{T}_\\beta^\\gamma$ where $\\alpha=\\set{v_i}$, $\\beta=\\set{w_i}$, $\\gamma=\\set{z_i}$. Define the \\cindex{product} of matrix $AB$ as:\n\t\\begin{equation}\n\t\t(AB)_{ij} = \\sum_{k=1}^n A_{ik} B_{kj}\n\t\\end{equation}\n\t\n\tthen \n\t\\begin{equation}\n\t    \\coordinate{UT}_\\alpha^\\gamma = \\coordinate{U}_\\beta^\\gamma \\coordinate{T}_\\alpha^\\beta\n\t\\end{equation}\n\\end{definition}\n\n\\begin{proof}\n\tFor product $AB=\\coordinate{UT}_\\alpha^\\gamma$, we have \n\t\\begin{equation}\n\t\t\\begin{aligned}\n\t\t\t(UT)(v_j) &= U(T(v_j)) = U \\left( \\sum_{k=1}^m B_{kj} w_k \\right) = \\sum_{k=1}^m B_{kj} U(w_k) \\\\\n\t\t\t&= \\sum_{k=1}^m B_{kj} \\left( \\sum_{i=1}^p A_{ik} z_i \\right) = \\sum_{k=1}^m  \\left( \\sum_{i=1}^p A_{ik} B_{kj} \\right)  z_i \\\\\n\t\t\t&= \\sum_{i=1}^p C_{ij} z_i\n\t\t\\end{aligned}\n\t\\end{equation}\n\\end{proof}\n\n\n\\begin{definition}\n\tthe \\cindex{Kronecker delta}  $\\delta_{ij}$ is defined as \n\t\\begin{equation}\n\t\t\\delta_{ij} = \\begin{cases}\n\t\t\t1 & \\text{, if } i = j \\\\\n\t\t\t0 & \\text{, if } i \\neq j\n \t\t\\end{cases}\n\t\\end{equation}\n\\end{definition}\n\n\\begin{definition}\n\tThe $n\\times n$ \\cindex{identity matrix} \\cindex{$I_n$} is defined as $\\left(I_n \\right)_{ij} = \\delta_{ij}$.\n\\end{definition}\n\n\\begin{theorem}\n\tLet $u_j$ and $v_j$ be the $j$th column of $AB$ and $B$, then\n\t\\begin{enumerate}\n\t\t\\item $u_j = A v_j$ : $AB = \\coordinate{A v_1, A v_2, \\dots, A v_j, \\dots, A v_p}$\n\t\t\\item $v_j = B e_j$ : $B = B \\times I_n$\n\t\\end{enumerate}\n\\end{theorem}\n\n\\begin{theorem} Let $T:V \\rightarrow W$ be linear, we have\n\t\\begin{equation}\n\t\t\\coordinate{T(u)}_\\gamma = \\coordinate{T}_\\beta^\\gamma \\coordinate{u}_\\beta\n\t\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\n\tFix $u \\in V$, and define linear transformation $f: F \\rightarrow V$ by $f(a) = a u$ and $g: F \\rightarrow W$ by $g(a) = a T(u)$. Let $a=\\{1\\}$ be the standard basis of $F$. Notice that $g=Tf$. we have:\n\t\\begin{equation}\n\t\t[T(u)]_\\gamma = [g(1)]_\\gamma = [g]_\\alpha^\\gamma = [Tf]_\\alpha^\\gamma = \\coordinate{T}_\\beta^\\gamma [f]_\\alpha^\\beta = \\coordinate{T}_\\beta^\\gamma [f(1)]_\\beta = \\coordinate{T}_\\beta^\\gamma [u]_\\beta\n\t\\end{equation}\n\\end{proof}\n\nNote: in the above proof, a vector could be treated as a linear transformation from a field to vector space.\n\n\\begin{definition}\n\tLet $A$ be an $m \\times n$ matrix. The mapping \\cindex{$L_A$} that $L_A: F^n \\rightarrow F^m$ defined by $L_A (x) = A x$ is called \\cindex{left-multiplication transformation} . \\qed\n\\end{definition}\n\n\nA linear transformation is different from matrix:\n\\begin{enumerate}\n    \\item Matrix is finite dimensional, so it defines relation only in finite dimension space. A linear transformation could be of any dimension.\n    \\item For a transformation, its matrix representation depends on the chosen basis.\n\\end{enumerate}\n\n\n\n\\begin{theorem}\n    \\begin{equation}\n        \\begin{aligned}\n            \\begin{cases}\n            [L_A]_\\alpha^\\beta &= A \\\\\n            L_{\\coordinate{T}_\\alpha^\\beta} &= T\n        \\end{cases}    \n        \\end{aligned}\n    \\end{equation}\n\\end{theorem}\n\n\n\\subsection{Inverse}\n\n\\begin{definition}\n\tLet $T: V\\rightarrow W$ and $\\mathrm{U}:W \\rightarrow V$ be linear. $\\mathrm{U}$ is an \\cindex{inverse}   of $T$ if $\\mathrm{TU} = I_W$ and $\\mathrm{UT} = I_V$. If $T$ has an inverse, $T$ is \\cindex{invertable}  , which is denoted as $T^{-1}$.\n\\end{definition}\n\n\\begin{theorem}\n    $(\\mathrm{UT})^{-1} = T^{-1} \\mathrm{U}^{-1}$.\n\\end{theorem}\n\n\\begin{definition}\n\tLet $A$ be $n \\times n$ matrix. $A$ is invertable if there is an $n \\times n$ matrix $B$ that $AB=BA=I$.\n\\end{definition}\n\n\\begin{theorem}\n    if $T$ is invertible, \n\t\\begin{equation*}\n\t\t\\coordinate{T^{-1}}_\\gamma^\\beta = \\left(\\coordinate{T}_\\beta^\\gamma \\right)^{-1}\n\t\\end{equation*}\n\\end{theorem}\n\\begin{proof}\n\t\\begin{equation*}\n\t\tI_n = \\coordinate{I_V}_\\beta = \\coordinate{T^{-1} T}_\\beta = \\coordinate{T^{-1}}_\\gamma^\\beta \\coordinate{T}_\\beta^\\gamma\n\t\\end{equation*}\n\\end{proof}\n\n\\begin{definition}\n\t$V$ is \\cindex{isomorphic} to $W$ if there exists a linear transformation $T:V\\rightarrow W$ that is invertible. $T$ is called an \\cindex{isomorphism}  from $V$ to $W$.\n\\end{definition}\n\n\\begin{theorem}\n\t$V$ is isomorphic to $W$ if $\\dimension{V} = \\dimension{W}$.\n\\end{theorem}\n\n\\begin{proof}\n\tIf the dimensions are the same, choose basis $\\beta$ of $V$ and $\\gamma$ of $W$ and create a linear mapping $T:\\beta \\rightarrow \\gamma$ by \\thmref{uniquelineartransformation}.\n\\end{proof}\n\n\n\\begin{theorem}\n\tLet $V$ be a vector space over $F$. Then $V$ is isomorphic to $F^n$ $\\Leftrightarrow$ $\\dimension{V} = n$.\n\\end{theorem}\n\n\n\\begin{theorem}\n\tThe function $\\Phi: \\mathcal{L}(V,M) \\rightarrow M_{m \\times n}(F)$ defined by $\\Phi (T) = \\coordinate{T}_\\beta^\\gamma$, is an isomorphism. The dimension has relation that \n\t\\begin{equation}\n\t\t\\dimension{\\mathcal{L}(V,M)} = \\dimension{V} \\times \\dimension{W}\n\t\\end{equation}\n\\end{theorem}\n\n\n\\subsection{Change of Coordinate Matrix}\n\n\n\\begin{theorem}\n\tLet $\\beta$ and $\\beta^\\prime$ be two ordered basis of $V$. Let $Q = \\coordinate{I_V}_{\\beta^\\prime}^\\beta$, then\n\t\\begin{enumerate}\n\t\t\\item $Q$ is invertible.\n\t\t\\item $\\forall \\alpha \\in V$, $\\coordinate{\\alpha}_\\beta = Q \\coordinate{\\alpha}_{\\beta^\\prime} = \\coordinate{I_V}_{\\beta^\\prime}^\\beta \\coordinate{\\alpha}_{\\beta^\\prime}$.\n\t\\end{enumerate}\n\t\n\t$Q= \\coordinate{I_V}_{\\beta^\\prime}^\\beta$ is called \\cindex{change of coordinate matrix} that changes from $\\beta^\\prime$-coordinates to $\\beta$-coordinates.\n\\end{theorem}\n\n\\begin{proof}\n    $\\forall \\alpha \\in V $,  $\\coordinate{\\alpha}_\\beta = \\coordinate{I_V (\\alpha)}_\\beta =  \\coordinate{I_V}_{\\beta^\\prime}^\\beta \\coordinate{\\alpha}_{\\beta^\\prime} = Q \\coordinate{\\alpha}_{\\beta^\\prime}$.\n\\end{proof}\n\nIf $Q$ changes $\\beta^\\prime$-coordinate into $\\beta$-coordinate, $Q^{-1}$ changes $\\beta$-coordinate into $\\beta^\\prime$-coordinate.\n\n\\begin{definition}\n\tA \\cindex{linear operator} is a linear transformation that map from $V$ to itself.\n\\end{definition}\n\n\\begin{theorem}\\label{twoindextransform}\n\tIf $T$ is a linear operator on $V$, then\n\t\\begin{equation}\n\t\t\\coordinate{T}_{\\beta^\\prime} = \\coordinate{I_V}_{\\beta}^{\\beta^\\prime} \\coordinate{T}_\\beta \\coordinate{I_V}_{\\beta^\\prime}^\\beta= Q^{-1} \\coordinate{T}_\\beta Q \n\t\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\n    $Q \\coordinate{T}_{\\beta^\\prime} = [I]_{\\beta^\\prime}^\\beta \\coordinate{T}_{\\beta^\\prime}^{\\beta^\\prime} = [I T]_{\\beta^\\prime}^\\beta = [T I]_{\\beta^\\prime}^\\beta = \\coordinate{T}_\\beta^\\beta [I]_{\\beta^\\prime}^\\beta = \\coordinate{T}_\\beta Q$.\n\\end{proof}\n\n\\begin{theorem}\n    Let $A \\in M_{n \\times n} (F)$, and $\\gamma:\\set{a_i}$ is an ordered basis for $F^n$. Then $\\coordinate{L_A}_\\gamma = Q^{-1} A Q$, where $Q = \\coordinate{a_1, a_2, \\dots, a_n}$.\n\\end{theorem}\n\n\\begin{proof}\n    $\\coordinate{L_A}_I = A$, so\n    \\begin{equation*}\n        [L_A]_\\gamma = \\coordinate{I_V}_I^\\gamma \\times \\coordinate{L_A}_I \\times \\coordinate{I_V}_\\gamma^I = \\coordinate{I_V}_I^\\gamma \\times A \\times \\coordinate{I_V}_\\gamma^I\n    \\end{equation*}\n    \n    A take aways is that $Q$ is the change of coordinate matrix from $\\gamma$ to $I$.\n\\end{proof}\n\n\n\\begin{theorem} \\label{specialchangeofcoordinates}\n\tLet $T:V\\rightarrow W$, $\\beta$ and $\\beta^\\prime$ are ordered basis of $V$, $\\gamma$ and $\\gamma^\\prime$ are ordered basis of $W$. Then\n\t\\begin{equation}\n\t\t\\coordinate{T}_{\\beta^\\prime}^{\\gamma^\\prime} = \\coordinate{I_W}_\\gamma^{\\gamma^\\prime} \\coordinate{T}_\\beta^\\gamma \\coordinate{I_V}_{\\beta^\\prime}^\\beta\n\t\\end{equation}\n\\end{theorem}\n\n\n\\begin{example}\nThere is an example of the usage of change of coordinate matrix: do reflection operation $T$ against a line $y = a x$. Let $\\beta$ be the standard basis of $R^2$ and $\\beta^\\prime$ be the standard basis of $R^2$ after the rotation of $y = a x$. The operation $T$ has a matrix representation in $\\beta^\\prime$\n\t\\begin{equation*}\n\t\t\\coordinate{T}_{\\beta^\\prime} = \\begin{bmatrix}\n\t\t\t1 & 0 \\\\\n\t\t\t0 & -1\n\t\t\\end{bmatrix}\t\t\n\t\\end{equation*}\n\tThen calculate $\\coordinate{T}_\\beta$ based on $\\coordinate{T}_{\\beta^\\prime}$.    \n\\end{example}\n\n\t\n\n\n\n\\begin{definition}\n\t$B$ is \\cindex{similar} to $A$ if there is an invertible matrix $Q$ that $B = Q^{-1} A Q$.\n\\end{definition}\n\n\\begin{theorem}\nIf $T$ is a linear operator on finite dimension vector space $V$, and if $\\beta$ and $\\beta^\\prime$ are any ordered basis of $V$, then $\\coordinate{T}_{\\beta^\\prime}$ is similar to $\\coordinate{T}_\\beta$.    \n\\end{theorem}\n\n\n\n\n\\subsection{Quotient Space}\n\n\\begin{definition}\n    Let subspace $U \\subset V$, The \\cindex{affine subset}  $v + U$ of $V$ is defined as:\n    \\begin{equation}\n        v + U = \\{ v + u: u \\in U\\}\n    \\end{equation}    \n\\end{definition}\n\n\\begin{definition}\n    Let subspace $U \\subset V$. Then the \\cindex{quotient space} $V/U$ is defined as:\n    \\begin{equation}\n        V/U = \\{ v + U: v \\in V \\}\n    \\end{equation}\n\\end{definition}\n\n\\begin{definition}\n    Let subspace $U \\subset V$. The \\cindex{quotient map} $\\pi: V \\rightarrow V/U$ is defined as:\n    \\begin{equation}\n        \\pi(v) = v + U\n    \\end{equation}\n\\end{definition}\n\n\\begin{theorem}\n    \\begin{equation}\n        \\dimension{V/U} = \\dimension{V} - \\dimension{U}\n    \\end{equation}\n\\end{theorem}\n\n\\begin{proof}\n    Define $\\pi : V \\rightarrow V/U$. The null space is $U$.\n\\end{proof}\n\n\\begin{theorem}\n    Define $\\tilde{T}: V/\\nullspace{T} \\rightarrow W$ by:\n    \\begin{equation*}\n        \\tilde{T}\\left(v + \\nullspace{T} \\right) = Tv\n    \\end{equation*}\n    Then $\\tilde{T}$ is an isomorphism between $V/\\nullspace{T}$ and $T$.\n\\end{theorem}\n\\begin{proof}\n    If $u + \\nullspace{T} = v + \\nullspace{T}$, then $u - v \\in \\nullspace{T}$. So $T(u - v) = T(u) - T(v) = 0$ and $T(u) = T(v)$.\n\\end{proof}\n\n\n\n% dual space section\n\\subsection{Dual Space}\n\n\n\\begin{definition}\n\tA \\cindex{linear functional} is a linear transformation that map from $V$ into $F$.\n\\end{definition}\n\n\\begin{definition}\n\tAn $i$-th coordinate function $f_i$ with respect to basis $\\beta$ is defined as $f_i(x) = a_i$ where\n\t\\begin{equation*}\n\t\t\\coordinate{x}_\\beta = \\begin{bmatrix}\n\t\t\ta_1 \\\\\n\t\t\ta_2 \\\\\n\t\t\t\\vdots \\\\\n\t\t\ta_n\n\t\t\\end{bmatrix} = \\begin{bmatrix}\n\t\t\tf_1(a) \\\\\n\t\t\tf_2(a) \\\\\n\t\t\t\\vdots \\\\\n\t\t\tf_n(a)\n\t\t\\end{bmatrix}\n\t\\end{equation*}\n\\end{definition}\n\n\n\n\\begin{definition}\n\tThe \\cindex{dual space}\\label{dualspacedefinition} of $V$ is the vector space $V^* = \\mathcal{L}(V,F)$. The \\cindex{double dual space} $V^{**}$ is the dual space of $V^*$.\n\\end{definition}\n\n\nThe dimension of dual space is $\\dimension{V^*} = \\dimension{\\mathcal{L}(V,F)} = \\dimension{V} \\times \\dimension{F} = \\dimension{V}$.\n\n\\begin{definition}\n\tLet $\\beta = \\set{x_i}$ be an ordered basis for finite dimensional vector space $V$. Define $f_i (x) = a_i$ where\n\t\\begin{equation*}\n\t    \\coordinate{x}_\\beta = \\begin{bmatrix}\n\t        a_1 \\\\\n\t        a_2 \\\\\n\t        \\vdots \\\\\n\t        a_n\n\t    \\end{bmatrix}\n\t\\end{equation*}\n\t\n\t$f_i$ is the $i$-th coordinate function with respect to basis $\\beta$. let $\\beta^*=\\set{f_i}$. Then $\\beta^*$ is an ordered basis for $V^*$, and $\\forall f \\in V^*$, we have\n\t\\begin{equation}\n\t\tf = \\sum_{i=1}^n f(x_i) f_i\n\t\\end{equation}\n\t$\\beta^*$ is called the \\cindex{dual basis} of $\\beta$.\n\\end{definition}\n\\begin{proof}\n\tLet $g =\\displaystyle \\sum_{i=1}^n f(x_i) f_i$, we have\n\t\\begin{equation*}\n\tg(x_j) = \\left( \\sum_{i=1}^n f(x_i) f_i \\right) (x_j) = \\sum_{i=1}^n f(x_i) f_i (x_j) = \\sum_{i=1}^n f(x_i) \\delta_{ij} =f(x_j)\n\t\\end{equation*}\n\\end{proof}\n\n\n\\begin{theorem}\n\tLet $V$ and $W$ be vector space over $F$ with ordered basis $\\beta$ and $\\gamma$. For any linear transformation $T:V \\rightarrow W$, the mapping $T^t: W^* \\rightarrow V^*$ defined as $T^\\top (g) = gT, \\forall g \\in W^*$ is a linear transformation with property that $\\left[T^\\top \\right]_{\\gamma^*}^{\\beta^*} = \\left(\\left[T \\right]_\\beta^\\gamma \\right)^\\top$.\n\\end{theorem}\n\\begin{proof}\n\tLet $\\beta = \\{x_i\\}$ and $\\gamma=\\{y_i\\}$ with dual basis $\\beta^*=\\{f_i\\}$ and $\\gamma^*=\\{g_i\\}$, $A=\\coordinate{T}_\\beta^\\gamma$. we have\n\t\\begin{equation*}\n\t\tT^\\top (g_j) = g_j T = \\sum_{s=1}^n (g_j T) (x_s) f_s\n\t\\end{equation*}\n\t\n\tSo the row $i$, column $j$ entry of $[T^\\top]_{\\gamma^*}^{\\beta^*}$ is\n\t\\begin{equation*}\n\t(g_j T)(x_i) = g_j (T(x_i))= g_j \\left( \\sum_{k=1}^m A_{kj} y_k \\right) = \\sum_{k=1}^m A_{kj} g_j(y_k)= \\sum_{k=1}^m A_{kj} \\delta_{kj} = A_{ji}\n\t\\end{equation*}\n\t\n\tHence $\\left[T^\\top \\right]_{\\gamma^*}^{\\beta^*} = A^\\top $.\n\\end{proof}\n\n\\begin{definition}\n    For $U \\subset V$, the \\cindex{annihilator} of $U$, denoted as $U^0_V$, is defined as\n    \\begin{equation*}\n        U^0_V = \\{ \\phi \\in V^*: \\phi(u) = 0, \\forall u \\in U \\}\n    \\end{equation*}\n    So the annihilator map $U$ to $0$. For vectors in $V - U$, the mapping could be any result. The annihilator is a subspace.\n\\end{definition}\n\n\\begin{theorem}\n    \\begin{equation}\n        \\dimension{U} + \\dimension{U_V^0} = \\dimension{V}\n    \\end{equation}\n\\end{theorem}\n\n\\begin{proof}\n    Define $i \\in \\mathcal{L}(U,V)$ that $i(u) = u, \\forall u \\in U$. $i^* \\in \\mathcal{L}(V^*,U^*)$. So\n    \\begin{equation*}\n        \\dimension{\\rangespace{i^*} } +\\dimension{\\nullspace{i^*}} = \\dimension{V^*}\n    \\end{equation*}\n    By definition, $\\nullspace{i^*} = U^0_V$. Also $\\rangespace{i^*} = U^*$.\n\\end{proof}\n\n\n\\begin{theorem}\n    Let $V$ and $W$ be two finite-dimentional vector space, and $T \\in \\mathcal{L}(V,W)$. Then:\n    \\begin{enumerate}\n        \\item $\\nullspace{T^*}  = (\\rangespace{T} )^0$\n        \\item $\\rangespace{T^*} = (\\nullspace{T} )^0$\n        \\item $\\dimension{\\rangespace{T^*}} = \\dimension{\\text{range } T}$\n        \\item $\\dimension{\\nullspace{T^*}} = \\dimension{\\nullspace{T}} + \\dimension{W} - \\dimension{V}$\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\n    Suppose $\\varphi \\in \\text{null } T^*$. Then $ 0 = T^*(\\varphi) = \\varphi T$. Then\n    \\begin{equation*}\n        0 = (\\varphi T)(v) = \\varphi (Tv) \n    \\end{equation*}\n    So $\\varphi \\in (\\text{range } T)^0_W$.\n    \n    \\begin{equation*}\n        \\begin{aligned}\n            \\dimension{\\rangespace{T^*}} &= \\dimension{W^*} - \\dimension{\\nullspace{T^*}} \\\\\n            &= \\dimension{W} - \\dimension{\\rangespace{T}^0} \\\\\n            &= \\dimension{\\rangespace{T}}\n        \\end{aligned}\n    \\end{equation*}\n    \n    \\begin{equation*}\n        \\begin{aligned}\n            \\dimension{\\nullspace{T^*}} &= \\dimension{\\rangespace{T}^0}\\\\\n            &= \\dimension{W} - \\dimension{\\rangespace{T}} \\\\\n            &= \\dimension{W} - (\\dimension{V} - \\dimension{\\nullspace{T}} ) \\\\\n            &= \\dimension{W} + \\dimension{\\nullspace{T}} - \\dimension{V}\n        \\end{aligned}\n    \\end{equation*}\n\\end{proof}\n\n\n\\begin{definition}\n    For vector $x \\in V$, define $\\hat{x}: V^* \\rightarrow F $ by $\\hat{x}(f) = f(x)$. $\\hat{x}$ is a linear functional on $V^*$, so $\\hat{x} \\in V^{**}$.\n\\end{definition}\n\n\n\\begin{theorem}\n    Define $\\psi : V \\rightarrow V^{**}$ by $\\psi (x) = \\hat{X}$.  Then $\\psi$ is an isomorphism.\n\\end{theorem}\n\n\\begin{theorem}\n    Let $V$ be a finite dimension vector space with dual space $V^*$. Every ordered basis for $V^*$ is the dual basis for some basis for $V$.\n\\end{theorem}\n\n\\begin{center}\n    \\begin{tikzcd}\nV \\arrow[rrddd, \"V^*\"{name=U}] \\arrow[rrrr, \"T\"] && & & W \\arrow[llddd, \"W^*\"'{name=W}] \\\\\n\\\\\n\\\\\n&& F\n\\arrow[rightarrow, from=W, to=U, \"T^\\top\"]\n\\end{tikzcd}\n\\end{center}\n\n\n\n\n\n", "meta": {"hexsha": "f50d9d40cb5f8edbadc30cc96c64584f3b236daa", "size": 20769, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/linear_algebra/la.2.linear_transformation.tex", "max_stars_repo_name": "elvisren/machine-learning-notes", "max_stars_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-07T03:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-04T17:28:22.000Z", "max_issues_repo_path": "src/linear_algebra/la.2.linear_transformation.tex", "max_issues_repo_name": "elvisren/machine-learning-notes", "max_issues_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/linear_algebra/la.2.linear_transformation.tex", "max_forks_repo_name": "elvisren/machine-learning-notes", "max_forks_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-01T23:34:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-01T23:34:47.000Z", "avg_line_length": 36.5651408451, "max_line_length": 408, "alphanum_fraction": 0.6425441764, "num_tokens": 7253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8918110511888303, "lm_q1q2_score": 0.7227940475076563}}
{"text": "\\section{Application: Least squares approximations and curve fitting}\n\\label{sec:least-squares}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find least squares approximations for a system of equations.\n  \\item Find best fit lines and parabolas for a set of data points.\n  \\end{enumerate}\n\\end{outcome}\n\nIn this section, we will consider the problem of finding approximate\nsolutions to a system of linear equations $A\\vect{v}=\\vect{b}$. This\ncan be useful when the system is inconsistent, but we would still like\nto find a ``best'' answer. For example, consider the following system\nof equations.\n\\begin{equation*}\n  \\begin{array}{rcrcl}\n    0.1 x &+& 0.2 y &=& 0.3, \\\\\n    0.2 x &+& 0.5 y &=& 0.7, \\\\\n    0.7 x &+& 0.2 y &=& 0.9. \\\\\n  \\end{array}\n\\end{equation*}\nThis system has the solution $(x,y)=(1,1)$, so it is clearly\nconsistent. Now imagine that we introduce some small inaccuracies into\nthe equations. The inaccuracies might perhaps be due to round-off\nerrors, or due to measurement errors if the coefficients are obtained\nfrom experimental data. We might end up with the following system of\nequations:\n\\begin{equation*}\n  \\begin{array}{rcrcl}\n    0.1000001 x &+& 0.2 y &=& 0.3, \\\\\n    0.2 x &+& 0.5 y &=& 0.7, \\\\\n    0.7 x &+& 0.2 y &=& 0.9. \\\\\n  \\end{array}\n\\end{equation*}\nExcept for a tiny error in one of the coefficients, this is the same\nsystem of equations as before. We would expect that such a small error\ndoes not affect the result much. However, this last system of\nequations is inconsistent; it has no solutions at all. You can see\nthis by observing that $(x,y)=(1,1)$ is still the unique solution to\nthe last two equations; substituting this into the first equation, we\nget $0.3000001 = 0.3$, which almost, but not exactly, true. What we\nwould like to find in a situation like this is an ``approximate\nsolution'', i.e., numbers $x$ and $y$ such that each of the three\nequations ``almost'' holds. We can formulate the problem more\nprecisely as follows:\n\n\\begin{problem}{Least squares approximation problem}{least squares-approximation}\n  Given a (possibly inconsistent) system of equations\n  $A\\vect{v}=\\vect{b}$, find $\\vect{v}$ such that\n  \\begin{equation*}\n    \\norm{A\\vect{v} - \\vect{b}}\n  \\end{equation*}\n  is as small as possible. We call such a vector $\\vect{v}$ a\n  \\textbf{least squares approximation}%\n  \\index{least squares approximation}%\n  \\index{approximation!least squares} for the system of equations.\n\\end{problem}\n\nTo see why this is called a ``least squares'' approximation, consider\na system of equations\n\\begin{equation*}\n  \\begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n    a_{11}x_1 &+& \\cdots &+& a_{1n}x_n &=& b_1, \\\\\n    a_{21}x_1 &+& \\cdots &+& a_{2n}x_n &=& b_2, \\\\\n    \\multicolumn{7}{c}{\\cdots} \\\\\n    a_{m1}x_1 &+& \\cdots &+& a_{mn}x_n &=& b_m. \\\\\n  \\end{array}\n\\end{equation*}\nWe can write this in matrix form $A\\vect{v}=\\vect{b}$, where\n\\begin{equation*}\n  A = \\begin{mymatrix}{ccc}\n    a_{11} & \\cdots & a_{1n} \\\\\n    \\vdots & \\ddots & \\vdots \\\\\n    a_{m1} & \\cdots & a_{mn} \\\\\n  \\end{mymatrix},\n  \\quad\n  \\vect{b} = \\begin{mymatrix}{c} b_1 \\\\ \\vdots \\\\ b_m \\end{mymatrix},\n  \\quad\\mbox{and}\\quad\n  \\vect{v} = \\begin{mymatrix}{c} x_1 \\\\ \\vdots \\\\ x_n \\end{mymatrix}.\n\\end{equation*}\nThen\n\\begin{equation*}\n  A\\vect{v} - \\vect{b} ~=~\n  \\begin{mymatrix}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n    a_{11}x_1 &+& \\cdots &+& a_{1n}x_n &-& b_1 \\\\\n    \\multicolumn{7}{c}{\\cdots} \\\\\n    a_{m1}x_1 &+& \\cdots &+& a_{mn}x_n &-& b_m \\\\\n  \\end{mymatrix},\n\\end{equation*}\nand therefore\n\\begin{equation*}\n  \\norm{A\\vect{v} - \\vect{b}}^2 ~=~\n  (a_{11}x_1 + \\cdots + a_{1n}x_n - b_1)^2 + \\ldots\n  + (a_{m1}x_1 + \\cdots + a_{mn}x_n - b_m)^2.\n\\end{equation*}\nTherefore, minimizing $\\norm{A\\vect{v}-\\vect{b}}$ is the same as\nminimizing the sum of the squares of the errors of all the equations,\nwhere the error of each equation is defined to be the difference\nbetween its left-hand side and right-hand side.\n\nWe note that $\\norm{A\\vect{v}-\\vect{b}}=0$ if and only if\n$A\\vect{v}=\\vect{b}$. Therefore, if the system of equations\n$A\\vect{v}=\\vect{b}$ is consistent, then its least squares\napproximations are exactly the solutions of the system of equations in\nthe usual sense.\n\nThe least squares approximation problem has a very elegant solution,\nprovided by the following proposition.\n\n\\begin{proposition}{Solution of the least squares approximation problem}{least-squares-approximation}\n  A vector $\\vect{v}$ is a least squares approximation of the system\n  of equations $A\\vect{v}=\\vect{b}$ if and only if\n  \\begin{equation*}\n    A^TA\\vect{v} = A^T\\vect{b}.\n  \\end{equation*}\n\\end{proposition}\n\n\\begin{proof}\n  Let $\\vect{a}_1,\\ldots\\vect{a}_n$ be the columns of the matrix\n  $A$. Recall that $\\sspan\\set{\\vect{a}_1,\\ldots\\vect{a}_n}$ is called\n  the \\textbf{column space}%\n  \\index{column space}%\n  \\index{matrix!column space} of $A$, which we write as $\\col(A)$.  If\n  \\begin{equation*}\n    \\vect{v} = \\begin{mymatrix}{c} x_1 \\\\ \\vdots \\\\ x_n \\end{mymatrix},\n  \\end{equation*}\n  is any vector, then by the definition of matrix multiplication, we\n  have\n  \\begin{equation*}\n    A\\vect{v} = x_1\\vect{a}_1 + \\ldots + x_n\\vect{a}_n.\n  \\end{equation*}\n  Therefore, a vector is of the form $A\\vect{v}$ if and only if it is\n  an element of $\\col(A)$. In particular, the equation\n  $A\\vect{v}=\\vect{b}$ has a solution if and only if $\\vect{b}$ is an\n  element of the column space of $A$. For $\\vect{v}$ to be a least\n  squares approximation, we want $\\norm{A\\vect{v}-\\vect{b}}$ to be as\n  small as possible. This means that we are looking for the element of\n  $\\col(A)$ that is closest to $\\vect{b}$.\n  \\begin{center}\n    \\begin{tikzpicture}[x={(1cm,-0.1cm)},y={(0.4cm,0.5cm)},z={(0cm,1cm)},scale=0.9]\n      \\filldraw[draw=red!80,fill=red!10](-4,-3,0) -- (4,-3,0) -- (4,3,0) -- (-4,3,0) -- cycle;\n      \\path[red] (2,0,0) node[right] {$\\col(A)$};\n      \\draw[->,thick,blue!80!black](0,0,0) -- node[left, pos=0.6] {$\\vect{b}$} (2,1.5,2.5);\n      \\draw[->,thick,blue!80!black](0,0,0) -- node[above, pos=0.6] {$A\\vect{v}$} (2,1.5,0);\n      \\draw[->,thick,blue!80!black](2,1.5,2.5) -- node[right] {$A\\vect{v}-\\vect{b}$} (2,1.5,0);\n      \\fill (0,0,0) circle [radius=2.2pt] node [left=3pt] {$\\vect{0}$};\n      \\fill (2,1.5,2.5) circle [radius=2.2pt];\n      \\fill (2,1.5,0) circle [radius=2.2pt];\n    \\end{tikzpicture}\n  \\end{center}\n  From Proposition~\\ref{prop:projection-subspace}, we know that this\n  happens when $A\\vect{v}-\\vect{b}$ is orthogonal to $\\col(A)$. Since\n  $\\col(A)=\\sspan\\set{\\vect{a}_1,\\ldots\\vect{a}_n}$, this is\n  equivalent to saying that $A\\vect{v}-\\vect{b}$ is orthogonal to each of\n  the vectors $\\vect{a}_1,\\ldots\\vect{a}_n$. Therefore,\n  \\begin{equation*}\n    \\vect{a}_i^T(A\\vect{v}-\\vect{b})=0\n  \\end{equation*}\n  for $i=1,\\ldots,n$. Since $\\vect{a}_1^T,\\ldots\\vect{a}_n^T$ are the\n  rows of the matrix $A^T$, this system of $n$ equations is equivalent\n  to the single equation\n  \\begin{equation*}\n    A^T(A\\vect{v}-\\vect{b})=\\vect{0},\n  \\end{equation*}\n  or equivalently,\n  \\begin{equation*}\n    A^TA\\vect{v} = A^T\\vect{b}.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{example}{Least squares approximation}{least-squares-approximation}\n  Find the least squares approximation for the system of equations\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}r@{~}c@{~}r@{~}c@{~}r}\n      2x &+& 2y &+& 2z &=&  1, \\\\\n      x  &-&  y &-&  z &=& -2, \\\\\n      -x &-&  y &+& 2z &=&  4, \\\\\n      2x &+& 2y &-&  z &=& -8. \\\\\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We first write the system in matrix form $A\\vect{v}=\\vect{b}$, where\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      2 & 2 & 2 \\\\\n      1 & -1 & -1 \\\\\n      -1 & -1 & 2 \\\\\n      2 & 2 & -1 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{b} = \\begin{mymatrix}{r} 1 \\\\ -2 \\\\ 4 \\\\ -8 \\end{mymatrix}.\n  \\end{equation*}\n  By Proposition~\\ref{prop:least-squares-approximation}, the least\n  squares approximation is given by the solution of the system of\n  equations $A^TA\\vect{v} = A^T\\vect{b}$. We calculate:\n  \\begin{equation*}\n    A^TA =\n    \\begin{mymatrix}{rrrr}\n      2 & 1 & -1 & 2 \\\\\n      2 & -1 & -1 & 2 \\\\\n      2 & -1 & 2 & -1 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{rrr}\n      2 & 2 & 2 \\\\\n      1 & -1 & -1 \\\\\n      -1 & -1 & 2 \\\\\n      2 & 2 & -1 \\\\\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rrr}\n      10 & 8 & -1 \\\\\n      8  & 10 & 1 \\\\\n      -1 & 1 & 10 \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  \\begin{equation*}\n    A^T\\vect{b} =\n    \\begin{mymatrix}{rrrr}\n      2 & 1 & -1 & 2 \\\\\n      2 & -1 & -1 & 2 \\\\\n      2 & -1 & 2 & -1 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{r} 1 \\\\ -2 \\\\ 4 \\\\ -8 \\end{mymatrix}\n    =\n    \\begin{mymatrix}{r} -20 \\\\ -16 \\\\ 20  \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, we must solve the system of equations\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      10 & 8 & -1 \\\\\n      8  & 10 & 1 \\\\\n      -1 & 1 & 10 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    =\n    \\begin{mymatrix}{r} -20 \\\\ -16 \\\\ 20  \\end{mymatrix}.\n  \\end{equation*}\n  After some row operations, we find that the unique solution is\n  $(x,y,z) = (-1, -1, 2)$.  We can double-check this answer as\n  follows. We calculate\n  \\begin{equation*}\n    A\\vect{v} - \\vect{b}\n    ~=~\n    \\begin{mymatrix}{rrr}\n      2 & 2 & 2 \\\\\n      1 & -1 & -1 \\\\\n      -1 & -1 & 2 \\\\\n      2 & 2 & -1 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{r} -1 \\\\ -1 \\\\ 2 \\end{mymatrix}\n    - \\begin{mymatrix}{r} 1 \\\\ -2 \\\\ 4 \\\\ -8 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r} 0 \\\\ -2 \\\\ 6 \\\\ -6 \\end{mymatrix}\n    - \\begin{mymatrix}{r} 1 \\\\ -2 \\\\ 4 \\\\ -8 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 2 \\\\ 2 \\end{mymatrix}\n  \\end{equation*}\n  and check that this vector is orthogonal to every column of\n  $A$. Since this is the case, our answer is correct.\n\\end{solution}\n\nAn important application of least squares approximations is\n\\textbf{curve fitting}%\n\\index{curve fitting}%\n\\index{fitting!curve fitting}: finding the ``best'' function of a given type\n(for example, linear, quadratic) to fit a given series of data points.\nThe next two examples show how to use least square approximations to\nsolve curve fitting problems.\n\n\\begin{example}{Least squares line}{least-squares-line}\n  A company has collected daily data on temperature and ice cream\n  sales over a period of one week. The data is as follows:\n  \\begin{equation*}\n    \\begin{array}{c@{~~~}|c|@{~~~}c}\n      \\mbox{Date} & \\mbox{Peak temperature} & \\mbox{Sales} \\\\\\hline\n      \\mbox{July 1}  & 17\\degC & \\$320  \\\\   % 300 1 -5   1\n      \\mbox{July 2}  & 22\\degC & \\$570  \\\\   % 600 1  0  -3 -1  1  1\n      \\mbox{July 3}  & 26\\degC & \\$850  \\\\   % 840 1  4   1 -1 -1\n      \\mbox{July 4}  & 20\\degC & \\$470  \\\\   % 480 1 -2      0 -1\n      \\mbox{July 5}  & 24\\degC & \\$750  \\\\   % 720 1  2      2  1  1\n      \\mbox{July 6}  & 23\\degC & \\$620  \\\\   % 660 1  1   1       -2  1\n      \\mbox{July 7}  & 23\\degC & \\$680  \\\\   % 660 1  1              -1\n    \\end{array}\n  \\end{equation*}\n  The company is interested in predicting how temperature will affect\n  future sales. Find a function of the form $y=a+bx$ that best fits\n  the data, where $x$ is temperature in degrees Celsius and $y$ is\n  sales in dollars. By ``best fit'', we mean that the sum of the\n  square of the errors should be as small as possible (where each\n  error is the difference between the dollar amount predicted by the\n  formula $y=a+bx$ and the actual dollar amount).  Such a function is\n  called a \\textbf{least squares line}%\n  \\index{least squares line}%\n  \\index{curve fitting!least squares line}%\n  \\index{line fitting}%\n  \\index{fitting!line fitting} or a \\textbf{linear regression}%\n  \\index{linear regression}%\n  \\index{curve fitting!linear regression} for the data.\n\\end{example}\n\n\\begin{solution}\n  We first write down a system of equations that expresses the\n  relationship $y=a+bx$ for each of the seven data points $(x,y)$:\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}r@{~}c@{~}r}\n      a &+& 17b &=& 320, \\\\\n      a &+& 22b &=& 570, \\\\\n      a &+& 26b &=& 850, \\\\\n      a &+& 20b &=& 470, \\\\\n      a &+& 24b &=& 750, \\\\\n      a &+& 23b &=& 620, \\\\\n      a &+& 23b &=& 680. \\\\\n    \\end{array}\n  \\end{equation*}\n  This is a system of seven equations in two variables (the variables\n  are $a$ and $b$). This system is likely inconsistent, because there\n  are more equations than variables, and also because it is unlikely\n  that the relationship between temperature and sales is exactly (as\n  opposed to approximately) linear. Instead, we find the least squares\n  approximation for the system of equations. We let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      1 & 17 \\\\\n      1 & 22 \\\\\n      1 & 26 \\\\\n      1 & 20 \\\\\n      1 & 24 \\\\\n      1 & 23 \\\\\n      1 & 23 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{b} =\n    \\begin{mymatrix}{r}\n      320 \\\\\n      570 \\\\\n      850 \\\\\n      470 \\\\\n      750 \\\\\n      620 \\\\\n      680 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  By Proposition~\\ref{prop:least-squares-approximation}, we must solve\n  the equation $A^TA\\vect{v} = A^T\\vect{b}$. We calculate\n  \\begin{equation*}\n    A^TA = \\begin{mymatrix}{cc}\n      7 & 155 \\\\\n      155 & 3483\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    A^T\\vect{b} =\n    \\begin{mymatrix}{c}\n      4260 \\\\\n      97380\n    \\end{mymatrix}.\n  \\end{equation*}\n  So the system of equations we must solve is\n  \\begin{equation*}\n    \\begin{mymatrix}{cc}\n      7 & 155 \\\\\n      155 & 3483\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} a \\\\ b \\end{mymatrix}\n    =\n    \\begin{mymatrix}{c}\n      4260 \\\\\n      97380\n    \\end{mymatrix}.\n  \\end{equation*}\n  After some row operations, we find the unique solutions\n  $(a,b)=(-720,60)$. This means that the desired linear approximation\n  is $y=-720 + 60x$. The following plot shows this function along with\n  the original data points.\n  \\begin{center}\n    \\begin{tikzpicture}[xscale=0.7,yscale=0.7]\n      \\draw[->] (15,2) -- (28,2) node[right] {$x$ (temperature)};\n      \\draw[->] (15,2) -- (15,10) node[above] {$y$\\makebox[0in][l]{ (sales)}};\n      \\draw (15,2) -- +(0,-0.5) node[below] {15};\n      \\draw (20,2) -- +(0,-0.5) node[below] {20};\n      \\draw (25,2) -- +(0,-0.5) node[below] {25};\n      \\draw (15,2)  -- +(-0.5,0) node[left] {200};\n      \\draw (15,4)  -- +(-0.5,0) node[left] {400};\n      \\draw (15,6)  -- +(-0.5,0) node[left] {600};\n      \\draw (15,8)  -- +(-0.5,0) node[left] {800};\n      \\draw (15,10) -- +(-0.5,0) node[left] {1000};\n      \\fill (17,3.2) circle [radius=3.1pt];\n      \\fill (22,5.7) circle [radius=3.1pt];\n      \\fill (26,8.5) circle [radius=3.1pt];\n      \\fill (20,4.7) circle [radius=3.1pt];\n      \\fill (24,7.5) circle [radius=3.1pt];\n      \\fill (23,6.2) circle [radius=3.1pt];\n      \\fill (23,6.8) circle [radius=3.1pt];\n      \\draw[red,thick] (15.5,2.1) -- (27.5,9.3);\n    \\end{tikzpicture}\n  \\end{center}\n  The following table compares the observed data to the computed\n  linear regression (sorted by increasing temperature). It also shows\n  the error for each data point.\n  \\begin{equation*}\n    \\begin{array}{c@{~~~}|c|@{~~~}c|@{~~~}c}\n      \\mbox{Temperature} & \\mbox{Actual sales} & \\mbox{Best linear fit} & \\mbox{Error}\\\\\\hline\n      17 & 320 & 300 & -20 \\\\\n      20 & 470 & 480 & +10 \\\\\n      22 & 570 & 600 & +30 \\\\\n      23 & 620 & 660 & +40 \\\\\n      23 & 680 & 660 & -20 \\\\\n      24 & 750 & 720 & -30 \\\\\n      26 & 850 & 840 & -10 \\\\\n    \\end{array}\n  \\end{equation*}\n  The sum of the squares of the errors is $20^2 + 10^2 + 30^2 + 40^2 + 20^2 + 30^2 + 10^2 = 4400$.\n\\end{solution}\n\n\\begin{example}{Least squares parabola}{least-squares-parabola}\n  \\index{least squares parabola}%\n  \\index{curve fitting!least squares parabola}\n  Find a quadratic polynomial that is the best fit for the following\n  data points:\n  \\begin{equation*}\n    \\begin{array}{rcr@{~}r}\n      (x_1,y_1) &=& ( 3,& 23.5), \\\\\n      (x_2,y_2) &=& ( 4,& 13.5), \\\\\n      (x_3,y_3) &=& ( 5,& 12.5), \\\\\n      (x_4,y_4) &=& ( 6,&  5.5), \\\\\n      (x_5,y_5) &=& ( 7,&  9.0), \\\\\n      (x_6,y_6) &=& ( 8,&  8.0), \\\\\n      (x_7,y_7) &=& ( 9,& 19.0). \\\\\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We are looking for an equation of the form\n  $y=a+bx+cx^2$. Substituting each of the seven data points into the\n  equation, we obtain 7 equations in the unknowns $a$, $b$, and $c$:\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}r@{~}c@{~}rcr}\n      a &+& 3b &+&  9c &=& 23.5, \\\\\n      a &+& 4b &+& 16c &=& 13.5, \\\\\n      a &+& 5b &+& 25c &=& 12.5, \\\\\n      a &+& 6b &+& 36c &=&  5.5, \\\\\n      a &+& 7b &+& 49c &=&  9.0, \\\\\n      a &+& 8b &+& 64c &=&  8.0, \\\\\n      a &+& 9b &+& 81c &=& 19.0. \\\\\n    \\end{array}\n  \\end{equation*}\n  We write this in matrix form at $A\\vect{v} = \\vect{b}$, where\n  \\begin{equation*}\n    A =\n    \\begin{mymatrix}{rrr}\n      1 & 3 &  9 \\\\\n      1 & 4 & 16 \\\\\n      1 & 5 & 25 \\\\\n      1 & 6 & 36 \\\\\n      1 & 7 & 49 \\\\\n      1 & 8 & 64 \\\\\n      1 & 9 & 81 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{b} =\n    \\begin{mymatrix}{r}\n      23.5 \\\\\n      13.5 \\\\\n      12.5 \\\\\n      5.5 \\\\\n      9.0 \\\\\n      8.0 \\\\\n      19.0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  To find the least squares approximation, we calculate\n  \\begin{equation*}\n    A^TA = \\begin{mymatrix}{ccc}\n      7 & 42 & 280 \\\\\n      42 & 280 & 2016 \\\\\n      280 & 2016 & 15316 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    A^T\\vect{b} =\n    \\begin{mymatrix}{c}\n      91 \\\\\n      518 \\\\\n      3430 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  and solve the system of equations $A^TA\\vect{v} = A^T\\vect{b}$, i.e.,\n  \\begin{equation*}\n    \\begin{mymatrix}{ccc}\n      7 & 42 & 280 \\\\\n      42 & 280 & 2016 \\\\\n      280 & 2016 & 15316 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} a \\\\ b \\\\ c \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{c}\n      91 \\\\\n      518 \\\\\n      3430 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  After doing some row operations, we find that the unique solution is\n  $(a,b,c) = (67,-19,1.5)$. Therefore, the desired quadratic\n  approximation is $y = 67 - 19x + 1.5x^2$. The following plot shows\n  this function along with the original data points.\n  \\begin{center}\n    \\def\\X{*2.0}\n    \\def\\Y{*0.4}\n    \\begin{tikzpicture}[scale=0.5, domain=2.67:10, samples=50]\n      \\draw[->] (0\\X,0\\Y) -- (12\\X,0\\Y) node[right] {$x$};\n      \\draw[->] (0\\X,0\\Y) -- (0\\X,27\\Y) node[above] {$y$};\n      \\draw (0\\X,0\\Y) -- +(0,-0.5) node[below] {0};\n      \\draw (5\\X,0\\Y) -- +(0,-0.5) node[below] {5};\n      \\draw (10\\X,0\\Y) -- +(0,-0.5) node[below] {10};\n      \\draw (0\\X,0\\Y)  -- +(-0.5,0) node[left] {0};\n      \\draw (0\\X,5\\Y)  -- +(-0.5,0) node[left] {5};\n      \\draw (0\\X,10\\Y)  -- +(-0.5,0) node[left] {10};\n      \\draw (0\\X,15\\Y)  -- +(-0.5,0) node[left] {15};\n      \\draw (0\\X,20\\Y) -- +(-0.5,0) node[left] {20};\n      \\draw (0\\X,25\\Y) -- +(-0.5,0) node[left] {25};\n      \\fill ( 3\\X, 23.5\\Y) circle [radius=4.4pt];\n      \\fill ( 4\\X, 13.5\\Y) circle [radius=4.4pt];\n      \\fill ( 5\\X, 12.5\\Y) circle [radius=4.4pt];\n      \\fill ( 6\\X,  5.5\\Y) circle [radius=4.4pt];\n      \\fill ( 7\\X,  9.0\\Y) circle [radius=4.4pt];\n      \\fill ( 8\\X,  8.0\\Y) circle [radius=4.4pt];\n      \\fill ( 9\\X, 19.0\\Y) circle [radius=4.4pt];\n      \\draw[red,thick] plot (\\x\\X,{(67-19*\\x+1.5*\\x*\\x)\\Y});\n    \\end{tikzpicture}\n  \\end{center}\n  The following table shows the original data, the values of the\n  best fit parabola, and the error for each data point.\n  \\begin{equation*}\n    \\begin{array}{c@{~~~}|c|@{~~~}c|@{~~~}c}\n      x & \\mbox{Actual $y$} & \\mbox{Best fit parabola} & \\mbox{Error} \\\\\\hline\n      3 &  23.5 &  23.5 & ~~~0.0 \\\\\n      4 &  13.5 &  15.0 &   +1.5 \\\\\n      5 &  12.5 & ~~9.5 &   -3.0 \\\\\n      6 & ~~5.5 & ~~7.0 &   +1.5 \\\\\n      7 & ~~9.0 & ~~7.5 &   -1.5 \\\\\n      8 & ~~8.0 &  11.0 &   +3.0 \\\\\n      9 &  19.0 &  17.5 &   -1.5 \\\\\n    \\end{array}\n  \\end{equation*}\n  The sum of the squares of the errors is $0^2 + 1.5^2 + 3^2 + 1.5^2 + 1.5^2 + 3^2 + 1.5^2 = 27$.\n\\end{solution}\n", "meta": {"hexsha": "2a30e26be2979a67e8cf27ce108586b0e692181c", "size": 19964, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/InnerProductSpaces-Application-LeastSquares.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/InnerProductSpaces-Application-LeastSquares.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/InnerProductSpaces-Application-LeastSquares.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 36.4306569343, "max_line_length": 101, "alphanum_fraction": 0.574684432, "num_tokens": 7903, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148792, "lm_q2_score": 0.8918110418436166, "lm_q1q2_score": 0.7227940317686322}}
{"text": "\\section{Gradient derivatives}\n\\label{sec:appendix:gradient-derivatives}\n\n\\subsection{Weight matrix construction}\n\\label{sec:appendix:gradient-derivatives:weight-matrix-construction}\nFor clarity the weight matrix construction is defined using scalar notation\n\\begin{equation}\nW_{h_\\ell, h_{\\ell-1}} = \\tanh(\\hat{W}_{h_\\ell, h_{\\ell-1}}) \\sigma(\\hat{M}_{h_\\ell, h_{\\ell-1}})\n\\end{equation}\n\nThe of the loss with respect to $\\hat{W}_{h_\\ell, h_{\\ell-1}}$ and $\\hat{M}_{h_\\ell, h_{\\ell-1}}$ is then derived using backpropagation.\n\\begin{equation}\n\\begin{aligned}\n\\frac{\\partial\\mathcal{L}}{\\partial \\hat{W}_{h_\\ell, h_{\\ell-1}}} &= \\frac{\\partial\\mathcal{L}}{\\partial W_{h_\\ell, h_{\\ell-1}}} \\frac{\\partial W_{h_\\ell, h_{\\ell-1}}}{\\partial \\hat{W}_{h_\\ell, h_{\\ell-1}}} \\\\\n&= \\frac{\\partial\\mathcal{L}}{\\partial W_{h_\\ell, h_{\\ell-1}}} (1 - \\tanh^2(\\hat{W}_{h_\\ell, h_{\\ell-1}})) \\sigma(\\hat{M}_{h_\\ell, h_{\\ell-1}}) \\\\\n\\frac{\\partial\\mathcal{L}}{\\partial \\hat{M}_{h_\\ell, h_{\\ell-1}}} &= \\frac{\\partial\\mathcal{L}}{\\partial W_{h_\\ell, h_{\\ell-1}}} \\frac{\\partial W_{h_\\ell, h_{\\ell-1}}}{\\partial \\hat{M}_{h_\\ell, h_{\\ell-1}}} \\\\\n&= \\frac{\\partial\\mathcal{L}}{\\partial W_{h_\\ell, h_{\\ell-1}}} \\tanh(\\hat{W}_{h_\\ell, h_{\\ell-1}}) \\sigma(\\hat{M}_{h_\\ell, h_{\\ell-1}}) (1 - \\sigma(\\hat{M}_{h_\\ell, h_{\\ell-1}}))\n\\end{aligned}\n\\end{equation}\n\nAs seen from this result, one only needs to consider $\\frac{\\partial\\mathcal{L}}{\\partial W_{h_\\ell, h_{\\ell-1}}}$ for $\\mathrm{NAC}_{+}$ and $\\mathrm{NAC}_{\\bullet}$, as the gradient with respect to $\\hat{W}_{h_\\ell, h_{\\ell-1}}$ and $\\hat{M}_{h_\\ell, h_{\\ell-1}}$ is a multiplication on $\\frac{\\partial\\mathcal{L}}{\\partial W_{h_\\ell, h_{\\ell-1}}}$.\n\n\\subsection{Gradient of \\texorpdfstring{$\\mathrm{NAC}_{\\bullet}$}{NAC-mul}}\n\\label{sec:appendix:gradient-derivatives:gradient-nac-mul}\n\nThe $\\textrm{NAC}_\\bullet$ is defined using scalar notation.\n\\begin{equation}\nz_{h_\\ell} = \\exp\\left(\\sum_{h_{\\ell-1}=1}^{H_{\\ell-1}} W_{h_{\\ell}, h_{\\ell-1}} \\log(|z_{h_{\\ell-1}}| + \\epsilon) \\right)\n\\end{equation}\n\nThe gradient of the loss with respect to $W_{h_\\ell, h_{\\ell-1}}$ can the be derived using backpropagation.\n\\begin{equation}\n\\begin{aligned}\n\\frac{\\partial z_{h_\\ell}}{\\partial W_{h_\\ell, h_{\\ell-1}}} &= \\exp\\left(\\sum_{h'_{\\ell-1}=1}^{H_{\\ell-1}} W_{h_{\\ell}, h'_{\\ell-1}} \\log(|z_{h'_{\\ell-1}}| + \\epsilon) \\right) \\log(|z_{h_{\\ell-1}}| + \\epsilon) \\\\\n&= z_{h_\\ell} \\log(|z_{h_{\\ell-1}}| + \\epsilon)\n\\end{aligned}\n\\end{equation}\n\nWe now wish to derive the backpropagation term $\\delta_{h_\\ell} = \\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}$, because $z_{h_\\ell}$ affects $\\{z_{h_{\\ell+1}}\\}_{h_{\\ell+1}=1}^{H_{\\ell+1}}$ this becomes:\n\\begin{equation}\n\\delta_{h_\\ell} = \\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}} = \\sum_{h_{\\ell+1}=1}^{H_{\\ell+1}} \\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell+1}}} \\frac{\\partial z_{h_{\\ell+1}}}{\\partial z_{h_\\ell}} = \\sum_{h_{\\ell+1}=1}^{H_{\\ell+1}} \\delta_{h_{\\ell+1}} \\frac{\\partial z_{h_{\\ell+1}}}{\\partial z_{h_\\ell}}\n\\end{equation}\n\nTo make it easier to derive $\\frac{\\partial z_{h_{\\ell+1}}}{\\partial z_{h_\\ell}}$ we re-express the $z_{h_\\ell}$ as $z_{h_{\\ell+1}}$.\n\\begin{equation}\nz_{h_{\\ell+1}} = \\exp\\left(\\sum_{h_{\\ell}=1}^{H_{\\ell}} W_{h_{\\ell+1}, h_{\\ell}} \\log(|z_{h_{\\ell}}| + \\epsilon) \\right)\n\\end{equation}\n\nThe gradient of $\\frac{\\partial z_{h_{\\ell+1}}}{\\partial z_{h_\\ell}}$ is then:\n\\begin{equation}\n\\begin{aligned}\n\\frac{\\partial z_{h_{\\ell+1}}}{\\partial z_{h_\\ell}} &= \\exp\\left(\\sum_{h_{\\ell}=1}^{H_{\\ell}} W_{h_{\\ell+1}, h_{\\ell}} \\log(|z_{h_{\\ell}}| + \\epsilon) \\right) W_{h_{\\ell+1}, h_{\\ell}} \\frac{\\partial \\log(|z_{h_{\\ell}}| + \\epsilon)}{\\partial z_{h_\\ell}} \\\\\n&= \\exp\\left(\\sum_{h_{\\ell}=1}^{H_{\\ell}} W_{h_{\\ell+1}, h_{\\ell}} \\log(|z_{h_{\\ell}}| + \\epsilon) \\right) W_{h_{\\ell+1}, h_{\\ell}} \\frac{\\mathrm{abs}'(z_{h_{\\ell}})}{|z_{h_{\\ell}}| + \\epsilon} \\\\\n&= z_{h_{\\ell+1}} W_{h_{\\ell+1}, h_{\\ell}} \\frac{\\mathrm{abs}'(z_{h_{\\ell}})}{|z_{h_{\\ell}}| + \\epsilon} \n\\end{aligned}\n\\end{equation}\n\n$\\mathrm{abs}'(z_{h_{\\ell}})$ is the gradient of the absolute function. In the paper we denote this as $\\mathrm{sign}(z_{h_{\\ell}})$ for brevity. However, depending on the exact definition used there may be a difference for $z_{h_{\\ell}} = 0$, as $\\mathrm{abs}'(0)$ is undefined. In practicality this doesn't matter much though, although theoretically it does mean that the expectation of this is theoretically undefined when $E[z_{h_{\\ell}}] = 0$.\n\n\\subsection{Gradient of NMU}\n\\label{sec:appendix:gradient-derivatives:gradient-nmu}\n\nIn scalar notation the NMU is defined as:\n\\begin{equation}\nz_{h_\\ell} = \\prod_{h_{\\ell-1}=1}^{H_{\\ell-1}} \\left(W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell} \\right)\n\\end{equation}\n\nThe gradient of the loss with respect to $W_{h_{\\ell-1},h_\\ell}$ is fairly trivial. Note that every term but the one for $h_{\\ell-1}$, is just a constant with respect to $W_{h_{\\ell-1},h_\\ell}$. The product, except the term for $h_{\\ell-1}$ can be expressed as $\\frac{z_{h_\\ell}}{W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}}$. Using this fact, the gradient can be expressed as:\n\n\\begin{equation}\n\\frac{\\partial \\mathcal{L}}{\\partial w_{h_{\\ell}, h_{\\ell - 1}}} = \\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}} \\frac{\\partial z_{h_\\ell}}{\\partial w_{h_{\\ell}, h_{\\ell - 1}}} = \\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}} \\frac{z_{h_\\ell}}{W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}} \\left(z_{h_{\\ell-1}} - 1\\right)\n\\end{equation}\n\nSimilarly, the gradient $\\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}}$ which is essential in backpropagation can equally easily be derived as:\n\n\\begin{equation}\n\\frac{\\partial \\mathcal{L}}{\\partial z_{h_{\\ell-1}}} = \\sum_{h_\\ell = 1}^{H_\\ell} \\frac{\\partial \\mathcal{L}}{\\partial z_{h_\\ell}} \\frac{\\partial z_{h_\\ell}}{\\partial z_{h_{\\ell-1}}} = \\sum_{h_\\ell = 1}^{H_\\ell} \\frac{z_{h_\\ell}}{W_{h_{\\ell-1},h_\\ell} z_{h_{\\ell-1}} + 1 - W_{h_{\\ell-1},h_\\ell}} W_{h_{\\ell-1},h_\\ell}\n\\end{equation}\n", "meta": {"hexsha": "e2a62645e681555f481a821243195b4ec27ffa85", "size": 6033, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/appendix/gradient-derivatives.tex", "max_stars_repo_name": "wlm2019/Neural-Arithmetic-Units", "max_stars_repo_head_hexsha": "f9de9d004bb2dc2ee28577cd1760d0a00c185836", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 147, "max_stars_repo_stars_event_min_datetime": "2019-10-07T11:01:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T02:51:18.000Z", "max_issues_repo_path": "paper/appendix/gradient-derivatives.tex", "max_issues_repo_name": "wlm2019/Neural-Arithmetic-Units", "max_issues_repo_head_hexsha": "f9de9d004bb2dc2ee28577cd1760d0a00c185836", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-12-03T12:40:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-03T12:40:21.000Z", "max_forks_repo_path": "paper/appendix/gradient-derivatives.tex", "max_forks_repo_name": "wlm2019/Neural-Arithmetic-Units", "max_forks_repo_head_hexsha": "f9de9d004bb2dc2ee28577cd1760d0a00c185836", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2019-12-21T15:58:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-03T08:32:38.000Z", "avg_line_length": 76.3670886076, "max_line_length": 448, "alphanum_fraction": 0.6461130449, "num_tokens": 2432, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.7227713831151064}}
{"text": "\n\\section{Non Relativistic Theory}\n\n    Using the non relativistic Schr\\\"odinger equation, the ground state\n    wave-function for a hydrogenic atom is given by\n    equation~\\ref{eq:schrodinger-ground}.\n    The corresponding electron density for the ground state is given by\n    \\(\n        \\rho(\\mb{r}) = \\psi_{1s}^{*} \\psi_{1s} \n                     = \\frac{1}{\\pi a_{0}^{3}} e^{-Zr/a_0}\n    \\).\n    We know that for a hydrogenic atom we can assume spherical symmetry,\n    and therefore by substituting the charge density into\n    equation~\\ref{eq:nff-spherical} we get the non relativistic normal \n    form factor for hydrogenic atoms.\n    \\begin{equation*}\n        f_0(q) = \\frac{4}{q} \\left( \\frac{Z}{a_0} \\right)^3\n                 \\int_0^\\infty e^{-2Zr/a_0} \\sin(qr) r \\; dr\n    \\end{equation*}\n    \\begin{equation} \\label{eq:nff-nonrelativistic}\n        \\boxed{\n            f_0(q) = \\left( \\frac{2Z}{a_0} \\right)^4 \n                     \\left[ \\left( \\frac{2Z}{a_0} \\right)^2 + q^2 \\right]^{-2} \n        }\n    \\end{equation}\n    Here we have $q = 4\\pi \\sin(\\theta/2)/\\lambda$ $\\InvAngstrom$ as stated earlier. This\n    result was has also been obtained by Hubbell~\\cite{Hubbell-1975} and\n    Pirenne~\\cite{Pirenne}, however in a slightly modified form due to a\n    different definition of $q$ which does not include the factor of $4\\pi$.\n", "meta": {"hexsha": "21941545c13d91be128b1e99586e8d9f2e1b3850", "size": 1344, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "normal_nonrelativistic.tex", "max_stars_repo_name": "mikepsn/atomic-form-factors-thesis", "max_stars_repo_head_hexsha": "63a8d151c4d53c369d223d44ff80c075ea102420", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "normal_nonrelativistic.tex", "max_issues_repo_name": "mikepsn/atomic-form-factors-thesis", "max_issues_repo_head_hexsha": "63a8d151c4d53c369d223d44ff80c075ea102420", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "normal_nonrelativistic.tex", "max_forks_repo_name": "mikepsn/atomic-form-factors-thesis", "max_forks_repo_head_hexsha": "63a8d151c4d53c369d223d44ff80c075ea102420", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.8, "max_line_length": 89, "alphanum_fraction": 0.6227678571, "num_tokens": 432, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7227713696404743}}
{"text": "\\chapter{Power law phenomenon}\n\\section{The power law}\nInitially the simplest distribution assumed for the degree distribution on a social network is a \\textit{Normal Gaussian}. But it is verified that the distribution of the degree is proportional to $ f(k) = \\frac{1}{k^\\beta} $ with $ \\beta  $ close to 2. A function $ f(k) $ that decrease as increase $ k $ is called \\textit{power law}\n\\subsection{Difference between a normal distribution and a power law}\nThe normal distribution is a representation of a balanced phenomenon, where in the mean there is the maximum frequency and in the slopes decrease the frequency.\\\\\nIn the power law instead is a representation of a imbalanced phenomenon where, with small values of x we have high frequency and with high values x we have a small frequency. Some example of power law phenomenon are the richness, number of relations in a social network.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{img/power_law_example}\n\t\\caption{Degree distribution on a Facebook social network}\n\t\\label{fig:powerlawexample}\n\\end{figure}\n\\subsection{Check if a degree distribution is a power law}\nIn order to check if a degree distribution is a power law it must be in the form $ f(k) = \\alpha \\cdot \\dfrac{1}{k^{\\beta}} $.\nWe can do a linear regression in log-log scale of $ f(k) $ that is\n\\begin{align*}\n\\log(f(k)) = \\log\\left(\\dfrac{\\alpha}{k^{\\beta}}\\right) = \\log(\\alpha) - \\beta \\cdot \\log(k)\n\\end{align*}\nand should be a straight line to represent a power law\n\n\\section{Generative model of social network based on degree distributions}\nIn this section we study some generative models based on degree distribution of real graph. The generative models aim to estimate the $ p(x) $, the distribution of data that in this case is a social network\n\\subsection{Erd\\\"{o}s-Gilbert-R\\'{e}nyi model}\nThis model is very simple, in fact it consider the probability \\textit{p} that exists an edge between two nodes is independent to any other. \\\\ In statistical terms we can consider the distribution edge as a $ Bernoulli(k;p) $.\\\\ In this case we define the graph as $ G(n,p) $ where n is the number of nodes and p the probability that exists an edge.\\\\\nThe expected number of edges is:\n%In prof handouts the formula is wrong, this is taken from https://economics.mit.edu/files/4621\n\\begin{align*}\n\\E \\left[ Edges \\right]= \\sum_{1\\leq x \\leq y \\leq n} (1\\cdot p + 0 \\cdot (1-p)) = \\sum_{1\\leq x \\leq y \\leq n} p = \\binom{n}{2} p = \\dfrac{n(n-1)}{2} p\n\\end{align*}\nSince in a indirect graph an edge is present in the two extremes of the edge the expected degree of a node is $ 2 \\cdot   \\frac{n(n-1)}{2} p $.\\\\\nThe probability that a node have \\textit{k} neighbours is a binomial distribution  so we can express as $ Bin(k; n, p) = \\binom{n}{k} \\cdot p^k \\cdot (1-p) $. %also here an error on prof handouts \n\\\\\nThis model for \\textit{n} and \\textit{k} sufficiently big approximate to a normal distribution\n\\subsection{Chung-lu model}\nIn this model the probability that exists an edge between two nodes is proportional to the expected degree of the pair of nodes.\n\\begin{itemize}\n\t\\item Initially we set $ \\textbf{d} = (d_1 \\ldots d_n) $, the expected degree of each node.\n\t\\item The probability that exists an edge between the node \\textit{i} and \\textit{j} is \\begin{align*}  p(E_{ij}) = \\dfrac{d_i d_j}{\\sum_k d_k} \t\\end{align*} \n\\end{itemize}\nIf the degree distribution \\textbf{d} is a power law, then the graph generated is a power law\n\\subsection{Barabasi-Albert model}\nThe previous models are static, in fact they have a fixed number of nodes. \\\\This model is dynamic so it mean that doesn't require the number of nodes a priori but they can be added always.\\\\ \nWith this dynamism try to give an explain to creation of a social network at difference of the previous models.\\\\\nEvery time a node is inserted an edge is created with the \\textit{preferential attachment} system.\n\\subsubsection{Preferential attachment system}\nEvery time a node \\textit{j} is added, a direct edge is created with the following two possibilities:\n\t\\begin{itemize}\n\t\t\\item with probability \\textit{p} choose a random node $ i < j $  \n\t\t\\item with probability $ (1-p) $ choose a node with probability proportional to the in-degree of the node\n\t\\end{itemize}\nThe latter option is called \\textit{rich-get-richer rule}. In fact if you have a  high number of relation you are more likely to make more.\n\\subsubsection{Degree distribution}\nWhen a node \\textit{j} is created, the probability that exists the edge $ (j, i)) $ with $ j > i $ is:\n\\begin{align*}\nP(E_{ji}) &= \\dfrac{1}{j-1} \\cdot p + \\dfrac{G_i(j-1)}{\\sum_{h \\leq (j-1)} G_h(j-1)} \\cdot (1-p) \\\\\n&=  \\dfrac{1}{j-1} \\cdot p + \\dfrac{G_i(j-1)}{j-1} \\cdot (1-p) \n\\end{align*}\nwhere $ G_i(j-1) $ is the in-degree of the node \\textit{i} at the time $ j-1 $\n\\subsubsection{Deterministic $ G_j(t) $}\nWe want to find an approximation of $ G_j(t) $ that give deterministically the in-degree of a node $ l $ at time $ t $. Let us denote as $ g_l(t) $ the approximation of $ G_l(t) $. The increase of in-degree can be expressed from a differential equation:\n\\begin{align*}\n\t& \\dfrac{d(g_l(t))}{dt} = \\dfrac{p}{t} + \\dfrac{ g_l(t) \\cdot (1-p)}{t} = \\dfrac{p + g_l(t) (1-p)}{t} \\\\\n\t& \\dfrac{d(g_l(t))}{dt} \\cdot \\dfrac{1}{p + g_l(t) (1-p)} =  \\dfrac{1}{t} \\\\\n\t& \\int \\dfrac{d(g_l(t))}{dt} \\cdot \\dfrac{1}{p + g_l(t) (1-p)} dt = \\int   \\dfrac{1}{t}  dt \\\\\n\t& g_l(t) \\cdot \\dfrac{\\ln(p + g_l(t) (1-p))}{1-p} + c' = \\ln(t) + c'' \\\\\n\t& g_l(t) \\cdot  \\ln(p + g_l(t) (1-p)) =  \\ln(t) \\cdot (1-p) + c \\\\\n\t& e^{\\ln(p + g_l(t) (1-p))} = e^{\\ln(t) \\cdot (1-p) + c} \\\\\n\t&e^{\\ln(p + g_l(t) (1-p))} = e^{\\ln(t) \\cdot (1-p) } \\cdot e^c \\\\\n\t&(p + g_l(t) (1-p)) = t^{(1-p) } \\cdot e^c \\\\\n\t& g_l(t) = \\dfrac{t^{1-p} \\cdot e^c - p}{1-p}\t \n\\end{align*}\nWhen we insert the node $ l $ at time $ l $ we have that $ g_l(l) = 0  $ so we have\n\\begin{align*} \n & 0= \\dfrac{l^{1-p} \\cdot e^c - p}{1-p}\t \\\\\n & \\dfrac{p}{1-p} =\\dfrac{l^{1-p} \\cdot e^c}{1-p} \\\\\n &\te^c = \\dfrac{p}{l^{1-p}}\n\\end{align*}\nif we substitute the latter expression in $ g_l(t) $ we have\n\\begin{align*}\n\t &g_l(t) = \\dfrac{t^{1-p} \\cdot \\dfrac{p}{l^{1-p}} - p}{1-p}  \\\\\n\t &g_l(t) = p \\cdot \\left( \\left(\\frac{t}{l}\\right)^{(1-p)}  -1 \\right) \\cdot \\dfrac{1}{1-p}\n\\end{align*}\n\\noindent\nWe can use the latter expression to estimate the number of nodes that at time \\textit{t} have degree at least \\textit{k}. So we write\n\\begin{align*}\n\t& \\left( \\left(\\frac{t}{l}\\right)^{(1-p)}  -1 \\right) \\cdot \\dfrac{p}{1-p} \\geq k \\\\\\\\\n\t&\\text{Then we pone respect to l: } \\\\\n\t& \\left(\\frac{t}{l}\\right)^{(1-p)} \\geq k \\cdot \\dfrac{1-p}{p} + 1 \\\\\n\t& \\frac{t}{l} \\geq \\left(k \\cdot \\dfrac{1-p}{p} + 1\\right)^{\\frac{1}{1-p}} \n\t\\end{align*}\nNote that the next expression is the fraction of nodes at time \\textit{t} that have at least in-degree \\textit{k}:\n\\begin{align*}\n\t & \\frac{l}{t}\\leq \\left(k \\cdot \\dfrac{1-p}{p} + 1\\right)^{-\\frac{1}{1-p}} \\\\\n\t  & l \\leq t \\cdot \\left(k\\cdot \\dfrac{1-p}{p} + 1\\right)^{-\\frac{1}{1-p}}\n\\end{align*}\nTo have the nodes that have \\textit{exactly k in-degree} at \\textit{time t} we must take the opposite of derivative (why?) of $  \\left(k \\cdot \\dfrac{1-p}{p} + 1\\right)^{-\\frac{1}{1-p}} $ respect to k.\\\\ The result is \n\\begin{center}\n\t$ \\dfrac{1}{1-p} \\left( k \\dfrac{1-p}{p} + 1 \\right)^{-\\left(1 + \\frac{1}{1-p}\\right)} $\n\\end{center}\nWe can infer from the latter expression that the distribution of in-degree nodes is a power law with exponent $ \\beta =  1 + \\frac{1}{1-p}$.\\\\\nFrom \n\\begin{itemize}\n\t\\item  when $ p \\simeq 1 $ we exponent disappear then we tend to Erd\\\"{o}s-Gilbert-R\\'{e}nyi model.\n\t\\item when $ p \\simeq 0 $ we apply almost ever the Preferential Attachment  System,  so the new nodes will more probably link to others with high in-degree, that is very similar to what happen with Chung-lu model.\n\t\\item The distribution disappear when $ p \\propto k^{-2} $ %Not understand how\n%\tin fact we have\\\\ $ \\left( k \\dfrac{1-k^{-2}}{k^{-2}} + 1 \\right)^{-\\dfrac{1-k^{-2}+1}{1-k^{-2}}}  = \\left( k \\dfrac{1-k^{-2} + k^{-2}}{k^{-2}} \\right) ^ {\\dfrac{k^{-2}-2}{1-k^{-2}}}= k^{3 \\cdot \\dfrac{k^{-2}-2}{1-k^{-2}}}$\n\\end{itemize}", "meta": {"hexsha": "e88ae8ee446039a4ed8b5795d6a330cb7d788dc6", "size": 8175, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/power_law.tex", "max_stars_repo_name": "Michedev/AAGM_resume", "max_stars_repo_head_hexsha": "31bcd6b58a39b19aa03a5aa13f8ad3e4d8f21ff3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/power_law.tex", "max_issues_repo_name": "Michedev/AAGM_resume", "max_issues_repo_head_hexsha": "31bcd6b58a39b19aa03a5aa13f8ad3e4d8f21ff3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/power_law.tex", "max_forks_repo_name": "Michedev/AAGM_resume", "max_forks_repo_head_hexsha": "31bcd6b58a39b19aa03a5aa13f8ad3e4d8f21ff3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 76.4018691589, "max_line_length": 352, "alphanum_fraction": 0.6709480122, "num_tokens": 2752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805822, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7227679491441549}}
{"text": "%---------------------------Scaled Jacobian-----------------------------\n\\section{Scaled Jacobian}\n\nThe scaled Jacobian is the minimum of\nthe Jacobian at each corner divided by the lengths of the 2 edge vectors\n(which is the minimum sine of the included angles):\n\\[\nq =\n  \\min \\left\\{ \\frac {\\alpha_0} {\\normvec{L_0} \\normvec{L_3}}, \n               \\frac {\\alpha_1} {\\normvec{L_1} \\normvec{L_0}},\n               \\frac {\\alpha_2} {\\normvec{L_2} \\normvec{L_1}},\n               \\frac {\\alpha_3} {\\normvec{L_3} \\normvec{L_2}}\n  \\right\\}.\n\\]\nNote that if any edge has $L< DBL\\_MIN$, we take $q = 0$.\n\n\\quadmetrictable{scaled Jacobian}%\n{$1$}%                                      Dimension\n{$[0.3,1]$}%                                Acceptable range\n{$[-1,1]$}%                                 Normal range\n{$[-1,1]$}%                                 Full range\n{$1$}%                                      Unit square\n{\\cite{knu:00}}%                            Citation\n{v\\_quad\\_scaled\\_jacobian}%                Verdict function name\n\n", "meta": {"hexsha": "0c3b8d21e6a017e3f31d98e242d25ff557622491", "size": 1034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadScaledJacobian.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadScaledJacobian.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadScaledJacobian.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 39.7692307692, "max_line_length": 72, "alphanum_fraction": 0.4719535783, "num_tokens": 278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.722662059520346}}
{"text": "\\title{Bayesian Neural Network}\n\n\\subsection{Bayesian Neural Network}\n\nA Bayesian neural network is a neural network with a prior\ndistribution on its weights \\citep{neal2012bayesian}.\n\nConsider a data set $\\{(\\mathbf{x}_n, y_n)\\}$, where each data point\ncomprises of features $\\mathbf{x}_n\\in\\mathbb{R}^D$ and output\n$y_n\\in\\mathbb{R}$. Define the likelihood for each data point as\n\\begin{align*}\n  p(y_n \\mid \\mathbf{w}, \\mathbf{x}_n, \\sigma^2)\n  &=\n  \\text{Normal}(y_n \\mid \\mathrm{NN}(\\mathbf{x}_n\\;;\\;\\mathbf{w}), \\sigma^2),\n\\end{align*}\nwhere $\\mathrm{NN}$ is a neural network whose weights and biases form\nthe latent variables $\\mathbf{w}$. Assume $\\sigma^2$ is a\nknown variance.\n\nDefine the prior on the weights and biases $\\mathbf{w}$ to be the standard normal\n\\begin{align*}\n  p(\\mathbf{w})\n  &=\n  \\text{Normal}(\\mathbf{w} \\mid \\mathbf{0}, \\mathbf{I}).\n\\end{align*}\n\nLet's build the model in Edward. We define a 3-layer Bayesian neural\nnetwork with $\\tanh$ nonlinearities.\n\\begin{lstlisting}[language=Python]\nfrom edward.models import Normal\n\ndef neural_network(x):\n    h = tf.tanh(tf.matmul(x, W_0) + b_0)\n    h = tf.tanh(tf.matmul(h, W_1) + b_1)\n    h = tf.matmul(h, W_2) + b_2\n    return tf.reshape(h, [-1])\n\nN = 40  # number of data points\nD = 1   # number of features\n\nW_0 = Normal(loc=tf.zeros([D, 10]), scale=tf.ones([D, 10]))\nW_1 = Normal(loc=tf.zeros([10, 10]), scale=tf.ones([10, 10]))\nW_2 = Normal(loc=tf.zeros([10, 1]), scale=tf.ones([10, 1]))\nb_0 = Normal(loc=tf.zeros(10), scale=tf.ones(10))\nb_1 = Normal(loc=tf.zeros(10), scale=tf.ones(10))\nb_2 = Normal(loc=tf.zeros(1), scale=tf.ones(1))\n\nx = tf.cast(x_train, dtype=tf.float32)\ny = Normal(loc=neural_network(x), scale=0.1 * tf.ones(N))\n\\end{lstlisting}\nThis program builds the model assuming the features \\texttt{x\\_train}\nalready exists in the Python environment. Alternatively, one can also\ndefine a TensorFlow placeholder,\n\\begin{lstlisting}\nx = tf.placeholder(tf.float32, [N, D])\n\\end{lstlisting}\nThe placeholder must be fed with data later during inference.\n\nA toy demonstration is available in the \\href{/getting-started}{Getting Started} section.\nSource code is available at\n\\href{https://github.com/blei-lab/edward/blob/master/examples/bayesian_nn.py}\n{\\texttt{examples/bayesian\\_nn.py}} in the Github repository.\n\n\\subsubsection{References}\\label{references}\n", "meta": {"hexsha": "b4dbf9d3a0864c9f9b57c83b9a3cdb220e7c7d81", "size": 2343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tutorials/bayesian-neural-network.tex", "max_stars_repo_name": "zhangyewu/edward", "max_stars_repo_head_hexsha": "8ec452eb0a3801df8bda984796034a9e945faec7", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5200, "max_stars_repo_stars_event_min_datetime": "2016-05-03T04:59:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T03:32:26.000Z", "max_issues_repo_path": "docs/tex/tutorials/bayesian-neural-network.tex", "max_issues_repo_name": "zhangyewu/edward", "max_issues_repo_head_hexsha": "8ec452eb0a3801df8bda984796034a9e945faec7", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 724, "max_issues_repo_issues_event_min_datetime": "2016-05-04T09:04:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T02:41:12.000Z", "max_forks_repo_path": "docs/tex/tutorials/bayesian-neural-network.tex", "max_forks_repo_name": "zhangyewu/edward", "max_forks_repo_head_hexsha": "8ec452eb0a3801df8bda984796034a9e945faec7", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1004, "max_forks_repo_forks_event_min_datetime": "2016-05-03T22:45:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T00:08:08.000Z", "avg_line_length": 36.0461538462, "max_line_length": 89, "alphanum_fraction": 0.7123346137, "num_tokens": 729, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.722662045837694}}
{"text": "\\section{Small Tips and Tricks}\\label{subsec:tipsAndTricks}\n\nWe end this tutorial by giving some helpful tips and tricks, and giving pointers\nwhere to find more information about HOL4.\n\n\\subsection{Extending the Simplifier}\nWhile proving the gaussian sum in \\autoref{sec:hol_ex1} we had to explicitly\ntell the simplifier that it should also use the definition of function\n\\lstinline{sum} while proving properties about the function.\nIn a pen-and-paper proof, one would never explicitly write this down and as such\nit is desirable to have the same convenience in HOL4.\nWe can do so by slightly changing the definition of \\lstinline{sum}:\n%\n\\begin{lstlisting}\nDefinition sum_def[simp]:\n  sum 0 = 0 /\\\n  sum n = n + sum (n-1)\nEnd\n\\end{lstlisting}\n\nBy appending \\lstinline{[simp]} to the name of the function, HOL4 automatically\nadds \\lstinline{sum_def} to the list of theorems used by the simplifier.\nA similar mechanism exists for adding theorems to the simplifier.\nHowever, this mechanic has to be used with caution as it is very easy to make\nthe simplifier diverge.\n\nAs an example, suppose we used the old definition of \\lstinline{sum} which\ndefines the function as a recursive function not in equational style:\n\n\\begin{lstlisting}\nDefinition sum_def[simp]:\n  sum n = if (n = 0) then 0 else n + sum (n-1)\nEnd\n\\end{lstlisting}\n\nIf we restart the proof for the gaussian sum now, and run through the first two\ntactics only (\\lstinline{nltac `Induction on 'n'. simplify.`}) HOL4 will just\nkeep running.\nAs a rule of thumb, it is recommended to be conservative and rather mention a\ndefinition than adding it to the simplifier.\nThe machinery can be useful for (non-recursive) abbreviations.\nFor theorems, one should refrain from adding commutativity or associativity\ntheorems, but adding theorems of the form $\\forall x. P x \\rightarrow Q x$, where\n$Q$ does not depend on $P$ should be fine.\n\n\\subsection{Making Proof Scripts More Robust}\nThe most cumbersome work once a proof has been developed is making sure that it\nremains correct even when versions of HOL4 change.\nWe give some simple recommendations that have proven quite useful over time.\n\nFirst, we recommend commenting larger case splits and induction proofs.\nWhile it may seem obvious now which case is being worked on by the proofscript\nthis might not be the case in a month, or a year of time after writing the\ninitial version.\n\nSecond, we recommend using tactics like\n\\lstinline{first_x_assum, last_assum, qpat_x_assum}.\nThese tactics are independent of the specific order of assumptions and thus make\nthe proof more robust to additional assumptions, or their removal.\n\n\\subsection{Getting More Help}\nThis small tutorial has only covered the basics.\nMore reference material can be found on \\url{https://hol-theorem-prover.org/#doc}.\nWe especially recommend looking at the documentation of the emacs mode\n(\\url{https://hol-theorem-prover.org/hol-mode.html}), and the description manual.\n\nThe help index located at \\lstinline{<HOLDIR>/help/HOLindex.html} provides\ndocumentation for a lot of tactics and contains signature files for all of the\nHOL4 distributions libraries and theories.\n\nFinally, the HOL-info mailing list\n(\\url{https://sourceforge.net/projects/hol/lists/hol-info}) is a good place to\nask further questions, as well as the \\texttt{\\#hol} channel of the Slack of the\nCakeML project (\\url{https://join.slack.com/t/cakeml/shared_invite/MjM1NjEyODgxODkzLTE1MDQzNjgwMTUtYjI4YTdlM2VmMQ}).\n", "meta": {"hexsha": "db32c5d2b54a9d0e4a7aecad8a00326262c1a7f6", "size": 3455, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Manual/Lassie-Tutorial/tipsTricks.tex", "max_stars_repo_name": "dwRchyngqxs/HOL", "max_stars_repo_head_hexsha": "3b1931c130fcab243da332adb2c1413c42c59cf9", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 492, "max_stars_repo_stars_event_min_datetime": "2015-01-07T16:36:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T22:18:48.000Z", "max_issues_repo_path": "Manual/Lassie-Tutorial/tipsTricks.tex", "max_issues_repo_name": "dwRchyngqxs/HOL", "max_issues_repo_head_hexsha": "3b1931c130fcab243da332adb2c1413c42c59cf9", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 759, "max_issues_repo_issues_event_min_datetime": "2015-01-01T00:40:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T17:33:39.000Z", "max_forks_repo_path": "Manual/Lassie-Tutorial/tipsTricks.tex", "max_forks_repo_name": "dwRchyngqxs/HOL", "max_forks_repo_head_hexsha": "3b1931c130fcab243da332adb2c1413c42c59cf9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 126, "max_forks_repo_forks_event_min_datetime": "2015-02-17T03:20:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T00:42:55.000Z", "avg_line_length": 46.0666666667, "max_line_length": 116, "alphanum_fraction": 0.7892908828, "num_tokens": 858, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117898012104, "lm_q2_score": 0.8740772368049822, "lm_q1q2_score": 0.7226099568635432}}
{"text": "LazySets provides ways to convert one set representation to another.\nIf a conversion is not possible due to restrictions in the represented class of sets, LazySets provides ways to obtain approximations.\nTurning to an approximate but simpler set representation is also interesting for answering questions efficiently that would otherwise be computationally expensive.\n\n\n\\subsection{Conversion}\n\nLazySets extends Julia's \\code{convert} function for converting between set representations. The first argument is the target type and the second argument is the source set.\n%\nBelow are three mathematically equivalent representations of the interval $\\X = [0, 1] \\subseteq \\R$:\n\n\\begin{minipage}{\\linewidth}\n\t\\vspace{-\\abovedisplayskip}\n\t\\begin{lstlisting}\njulia> X = Interval(0, 1)\nInterval{Float64,\n  IntervalArithmetic.Interval{Float64}}([0, 1])\n\njulia> convert(Hyperrectangle, X)\nHyperrectangle{Float64, Vector{Float64},\n  Vector{Float64}}([0.5], [0.5])\n\njulia> convert(Zonotope, X)\nZonotope{Float64, Vector{Float64},\n  Matrix{Float64}}([0.5], [0.5])\n\t\\end{lstlisting}\n\\end{minipage}\nThere are even more possibilities, such as representing $\\X$ as an intersection of half-spaces (try \\code{convert(HPolytope, X)}).\n\n\n\\smallskip\n\nWith multiple dispatch it is easy to define less obvious conversions, e.g., to convert the Cartesian product of an interval and a two-dimensional hyperrectangle to a three-dimensional zonotope:\n\n\\begin{minipage}{\\linewidth}\n\t\\vspace{-\\abovedisplayskip}\n\t\\begin{lstlisting}\njulia> X = rand(Interval)\n\njulia> Y = rand(Hyperrectangle, dim=2)\n\njulia> Z = convert(Zonotope, X × Y)\nZonotope{Float64, ...}\n\njulia> dim(Z)\n3\n\\end{lstlisting}\n\\end{minipage}\n\n\n\\subsection{Approximation}\\label{sec:approximation}\n\n\\begin{figure}\n\t\\hfill\n\t\\includegraphics[height=30mm]{img/overapproximate}\n\t\\hfill\n\t\\includegraphics[height=30mm]{img/polardirs}\n\t\\hfill\\\n\t\\vspace*{1mm}\n\t\\caption{Left picture: Overapproximation of the polytope from Fig.~\\ref{fig:supfunc} (orange) with a hyperrectangle (blue) and two zonotopes. The zonotope generators were synthesized from three (red) resp.\\ five (green) polar directions (right). Observe that the approximations are pairwise incomparable.}\n\t\\label{fig:overapproximate}\n\\end{figure}\n\nIn many applications we do not require exact results but are content with an approximation. To still give mathematical guarantees, one usually aims for either over- or underapproximations.\n\nWe can use the support function to get an overapproximation: For every nonempty compact convex set $X \\subseteq \\R^n$ and $D \\subseteq \\R^n$ we have\n\\begin{equation*}\n\tX \\subseteq \\bigcap_{d \\in D} \\{d^T x \\leq \\rho(d, X)\\}\n\\end{equation*}\nand equality holds for $D = \\R^n$.\n\n\\smallskip\n\nLazySets has predefined common template directions such as \\code{OctDirections(2)} for directions normal to a regular octagon in two dimensions. Fig.~\\ref{fig:supfunc} (right) illustrates the evaluation of overapproximating the set $X$ with octagonal directions, resulting in a polygon with eight constraints. Apart from common fixed template directions there are also options for parametric uniform directions in two (\\code{PolarDirections}) or three (\\code{SphericalDirections}) dimensions or for a custom set of directions (\\code{CustomDirections}).\n\n\\begin{minipage}{\\linewidth}\n\\vspace{-\\abovedisplayskip}\n\\begin{lstlisting}\njulia> Xoct = overapproximate(X, OctDirections(2))\n\njulia> length(constraints_list(Xoct))\n8\n\\end{lstlisting}\n\\end{minipage}\n\nIn two dimensions, LazySets can compute $\\varepsilon$-close overapproximations using a method by Kamenev~\\cite{kamenev1996algorithm} later refined in~\\cite{lotov2008modified}.\n%\nIt is used via \\code{overapproximate(X, $\\varepsilon$)}, where $\\varepsilon$ is the specified tolerance.\n%\nThe higher-dimensional extension is not implemented yet.\n%\nOn the other hand, a higher-dimensional set can be lazily projected using the support function to a lower-dimensional subspace, where the available method applies.\n\n\\smallskip\n\nIn some applications, we may want to ensure that the result has a specific set type.\nThe smallest bounding box is available by specifying the second argument type. It yields a \\code{Hyperrectangle}, which is more efficient to work with.\n\n\\begin{minipage}{\\linewidth}\n\t\\vspace{-\\abovedisplayskip}\n\t\\begin{lstlisting}\njulia> overapproximate(X, Hyperrectangle)\n\njulia> box_approximation(X) # alias\n\\end{lstlisting}\n\\end{minipage}\n\nWe can use \\code{overapproximate(P, Zonotope, D)}, where \\code{P} is a polytope and \\code{D} is a vector of directions used as candidates for the generators, to obtain a zonotope (in any dimension). We show some example overapproximations in Fig.~\\ref{fig:overapproximate}.\nUnderapproximations can be obtained using the function \\code{underapproximate}.\n", "meta": {"hexsha": "5a4272fac98600750ac4a818fdbe6d6831c17428", "size": 4770, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/approx.tex", "max_stars_repo_name": "JuliaReach/LazySets-JuliaCon21", "max_stars_repo_head_hexsha": "033612bd98ef8692195e4860e7eaa7bfbd05e6c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-09-28T20:12:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-27T16:51:11.000Z", "max_issues_repo_path": "paper/approx.tex", "max_issues_repo_name": "JuliaReach/LazySets-JuliaCon21", "max_issues_repo_head_hexsha": "033612bd98ef8692195e4860e7eaa7bfbd05e6c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-11-03T13:31:10.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-16T21:15:45.000Z", "max_forks_repo_path": "paper/approx.tex", "max_forks_repo_name": "JuliaReach/LazySets-JuliaCon21", "max_forks_repo_head_hexsha": "033612bd98ef8692195e4860e7eaa7bfbd05e6c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-27T15:57:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-27T15:57:41.000Z", "avg_line_length": 43.3636363636, "max_line_length": 552, "alphanum_fraction": 0.7794549266, "num_tokens": 1254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241803, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7226099567018297}}
{"text": "\\emph{Matrices} (singular: \\emph{matrix}) are arrays of numbers, for example,\n\\[ M = \\begin{bmatrix}\n 4 & -\\sqrt{3} & \\pi \\\\ -5.2 & 0 & 13\n\\end{bmatrix}, \\]\nand \\emph{vectors} are matrices that have only one column. The use of vectors and matrices makes the notation and handling of data and variables in large computations clearer and more compact, and their study has also led to new concepts and theories. Vectors and matrices are fundamental in mathematics and for applications of mathematical analysis.\n\nIn the example below, we will work with a matrix that represents the connections in a network of cities, and this matrix can therefore be considered the link that makes the road network accessible to mathematical analysis. Other networks that are frequently analysed using matrices include social networks (e.g., to study the spread of news), the world wide web (e.g., Google PageRank), contact networks (e.g., to minimise contagion in a hospital).\n\n\\begin{application}[Random walks]\nA very large number of hikers is travelling randomly around the network of cities\n\\begin{center}\n\t\\includegraphics[width=0.5\\textwidth]{./Figures/network.pdf}\n\\end{center}\nwhere the road between $A$ and $B$ can only be travelled in one direction. A hiker would arrive in a city, stay for the day, randomly pick one of the outgoing roads -- each with equal probability; possibly the city he or she came from the previous day --  and then travel there the next morning. For example, if there are 100 hikers in $D$ today, then an average of 50 of them will hike to $C$ the next day. Besides those new arrivals from $D$, the city $C$ will further receive new hikers from $A$ and from $B$.\n\nThe hikers in this example are called \\emph{random walkers} in mathematical jargon, and an important and applicable task is to find the \\emph{steady state} of the system -- that is, the distribution of hikers so that the total number of hikers in each city does not change from one day to the next. For example, looking at the above map, you might expect that after a long time there should be a larger concentration of hikers in $C$ than in $E$.\n\nThe steady state  can be found by balancing the number of incoming and outgoing hikers for each city. Let $d$ and $e$ be the steady-state proportion of hikers in cities $D$ and $E$, and consider all travelling to and from $E$: outgoing $= e$, incoming = $\\tfrac12d$, which gives $e = \\tfrac12d$. Repeating this for the other cities leads to a collection of five equations.\n\nAlternatively, one can choose a matrix approach and use vectors to describe the distribution of hikers over the network. The first entry of that vector stands for the proportion of hikers in $A$, the second for the proportion in $B$, etc. For example,\n\\[ v_1 = \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix}, \\quad v_2 = \\begin{bmatrix} 0.2 \\\\ 0.2 \\\\ 0.2 \\\\ 0.2 \\\\ 0.2 \\end{bmatrix}\\]\nmeans in the first case that all hikers are in $C$, and in the second case that they are evenly distributed over all five cities. Next we describe their movements using a matrix. After the review of matrix multiplication in the next section, you will be able to convince yourself that\n\\[ v_{\\text{tomorrow}} = \\begin{bmatrix} 0 & \\rfrac12 & \\rfrac13 & 0 & 0 \\\\\n\t\t\t\t\t\t\t\t\t 0 & 0 & \\rfrac13 & 0 & 0 \\\\\n\t\t\t\t\t\t\t\t\t 1 & \\rfrac12 & 0 & \\rfrac12 & 0 \\\\\n\t\t\t\t\t\t\t\t\t 0 & 0 & \\rfrac13 & 0 & 1 \\\\\n\t\t\t\t\t\t\t\t\t 0 & 0 & 0 & \\rfrac12 & 0 \\end{bmatrix} v_{\\text{today}}\n\t\t\t\t\t   = P \\, v_{\\text{today}} \\]\nreflects the movement of the hikers around the network of cities\\footnote{For example:\n\\[ \\text{all hikers in $C$} \\leftrightarrow\nv = \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix}\n\\quad \\stackrel{P}{\\longrightarrow} \\quad\nP \\, v = \\begin{bmatrix} \\rfrac13 \\\\ \\rfrac13 \\\\ 0 \\\\ \\rfrac13 \\\\ 0 \\end{bmatrix}\n\\leftrightarrow  \\text{ hikers evenly distributed over $A,B,D$}\n\\qquad \\text{\\checkmark} \\]\nNow check this for the other four ``concentrated'' configurations. If that works, then $P$ is correct.\n}. The task of finding a steady state now corresponds to finding a vector (i.e., a distribution of hikers) that does not change through application of $P$ (i.e., from one day to the next). Note that individual hikers keep moving -- the steady state is the distribution of hikers such that their \\emph{total} number in each city stays the same. Denoting this vector by $v^*$ and its entries $a,b,c,d,e$, we obtain $v^*=Pv^*$, or\n\\[ \\begin{bmatrix} a\\\\b\\\\c\\\\d\\\\e \\end{bmatrix} =\n\\begin{bmatrix} 0 & \\rfrac12 & \\rfrac13 & 0 & 0 \\\\\n0 & 0 & \\rfrac13 & 0 & 0 \\\\\n1 & \\rfrac12 & 0 & \\rfrac12 & 0 \\\\\n0 & 0 & \\rfrac13 & 0 & 1 \\\\\n0 & 0 & 0 & \\rfrac12 & 0 \\end{bmatrix} \\begin{bmatrix} a\\\\b\\\\c\\\\d\\\\e \\end{bmatrix}. \\]\nThis is an equation of 5-vectors (the result of the matrix multiplication on the right-hand side is a 5-vector as well) and therefore corresponds to a collection of five ordinary equations -- can you locate the equation $e = \\tfrac12d$ from the previous paragraph in it?\n\nThe equation $v^*=Pv^*$ is in fact an eigenvalue equation for the matrix $P$. We will learn how to solve it in this chapter. The solution is\n\\[a=0.177,\\:\\:b=0.118,\\:\\:c=0.353,\\:\\:d=0.235,\\:\\:e=0.118\\:.\\]\n\\end{application}\n\n\n\\section{Review of Matrix Arithmetic}\n\\label{sec:rma}\n\\begin{definition}[Matrices] ~\\\\\n\\begin{enumerate}[(i)]\n\t\\item A $m \\times n$ matrix is an array\n\t\t\\[A = \\begin{bmatrix}\n\t\ta_{11} & a_{12} & a_{13} & \\cdots & a_{1n} \\\\\n\t\ta_{21} & a_{22} & a_{23} & \\cdots & a_{2n} \\\\\n\t\ta_{31} & a_{32} & a_{33} & \\cdots & a_{3n} \\\\\n\t\t\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\ta_{m1} & a_{m2} & a_{m3} & \\cdots & a_{mn} \\\\\n\t\t\\end{bmatrix},\\]\n\t\twhere $m$ is the number of rows and $n$ the number of columns. We also refer to $A$ as a matrix of \\emph{size} $m \\times n$.\n\t\\item An equation of the form $A=B$, where $A$ and $B$ are matrices of the same size $m \\times n$, means that $a_{ij} = b_{ij}$ for all $i\\in\\{1,2,\\dots,m\\},j\\in\\{1,2,\\dots,n\\}.$ Matrices of different sizes can never be equal.\n\t\\item Addition and subtraction can only be carried out for matrices of the same size, and then the operation is carried out elementwise:\n\t\t\\begin{equation*}\\begin{split}\n\t\tA \\pm B & = \\begin{bmatrix}\n\t\ta_{11} & a_{12} & \\cdots & a_{1n} \\\\\n\t\ta_{21} & a_{22} & \\cdots & a_{2n} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\ta_{m1} & a_{m2} & \\cdots & a_{mn} \\\\\n\t\t\\end{bmatrix} \\pm \\begin{bmatrix}\n\t\tb_{11} & b_{12} & \\cdots & b_{1n} \\\\\n\t\tb_{21} & b_{22} & \\cdots & b_{2n} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\tb_{m1} & b_{m2} & \\cdots & b_{mn} \\\\\n\t\t\\end{bmatrix} \\\\ & = \\begin{bmatrix}\n\t\ta_{11} \\pm b_{11} & a_{12} \\pm b_{12} & \\cdots & a_{1n} \\pm b_{1n} \\\\\n\t\ta_{21} \\pm b_{21} & a_{22} \\pm b_{22} & \\cdots & a_{2n} \\pm b_{2n} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\ta_{m1} \\pm b_{m1} & a_{m2} \\pm b_{m2} & \\cdots & a_{mn} \\pm b_{mn} \\\\\n\t\t\\end{bmatrix}.\n\t\t\\end{split}\\end{equation*}\n\t\\item Multiplying a number with a matrix is called \\emph{scalar multiplication}:\n\t\t\\[ \\lambda A = \\lambda \\begin{bmatrix}\n\t\ta_{11} & a_{12} & \\cdots & a_{1n} \\\\\n\t\ta_{21} & a_{22} & \\cdots & a_{2n} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\ta_{m1} & a_{m2} & \\cdots & a_{mn} \\\\\n\t\t\\end{bmatrix} = \\begin{bmatrix}\n\t\t\\lambda a_{11} & \\lambda a_{12} & \\cdots & \\lambda a_{1n} \\\\\n\t\t\\lambda a_{21} & \\lambda a_{22} & \\cdots & \\lambda a_{2n} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\t\\lambda a_{m1} & \\lambda a_{m2} & \\cdots & \\lambda a_{mn} \\\\\n\t\t\\end{bmatrix}.\\]\n\t\\item Multiplying two matrices $A$ and $B$ is called \\emph{matrix multiplication} -- it can be carried out only if the number of columns of $A$ agrees with the number of rows of $B$:\n\t\t\\begin{equation*}\n\t\tA \\, B =\\begin{bmatrix}\n\t\ta_{11} & a_{12} & \\cdots & a_{1n} \\\\\n\t\ta_{21} & a_{22} & \\cdots & a_{2n} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\ta_{m1} & a_{m2} & \\cdots & a_{mn} \\\\\n\t\t\\end{bmatrix} \\begin{bmatrix}\n\t\tb_{11} & b_{12} & \\cdots & b_{1k} \\\\\n\t\tb_{21} & b_{22} & \\cdots & b_{2k} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\tb_{n1} & b_{n2} & \\cdots & b_{nk} \\\\\n\t\t\\end{bmatrix}\n\t\t= \\begin{bmatrix}\n\t\tc_{11} & c_{12} & \\cdots & c_{1k} \\\\\n\t\tc_{21} & c_{22} & \\cdots & c_{2k} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\tc_{m1} & c_{m2} & \\cdots & c_{mk} \\\\\n\t\t\\end{bmatrix},\n\t\t\\end{equation*}\n\t\twhere $c_{ij} = \\sum_{s=1}^n a_{is}b_{sj}$. The resulting matrix is of size $m \\times k$.\n\t\\item A \\emph{square matrix} is a matrix with $m=n$. The \\emph{identity matrix}, which has entries $1$ on the diagonal and is zero everywhere else,\n\t\\[ I = \\begin{bmatrix} 1 & & & \\\\ & 1 & & \\\\ & & \\ddots & \\\\ & & & 1 \\end{bmatrix},\\]\n\tis an important example of a square matrix.\n\t\t\n\\end{enumerate}\n\\end{definition}\n\n\\begin{remark}\n\\begin{enumerate}[(i)]\n\t\\item Regarding the condition on when two matrices can be multiplied, it should be useful to remember that ``$m \\times n \\cdot n \\times k$ works and gives a $m \\times k$ matrix.'' Therefore, the result of a $1 \\times n$ with a $n \\times 1$ is a $1 \\times 1$, which is just a single real number, also called a \\emph{scalar}.\n\t\\item The rule for matrix multiplication may seem quite complicated -- it becomes easier to remember once one breaks down the procedure as follows. The case $1 \\times n \\cdot n \\times 1$ just mentioned is the building block for matrix products:\n\\begin{equation*}\\begin{split}\n \\begin{bmatrix} a_{11} & a_{12} & a_{13} &\\cdots & a_{1n} \\end{bmatrix}\n   \\begin{bmatrix} b_{11} \\\\ b_{21} \\\\ b_{31} \\\\ \\vdots \\\\ b_{n1} \\end{bmatrix}\n   & = a_{11}b_{11} + a_{12}b_{21} + a_{13}b_{31} + \\dots + a_{1n}b_{n1} \\\\\n   & = \\sum_{s=1}^n a_{1s}b_{s1} = c_{11} \\:.\n\\end{split}\\end{equation*}\nHere, both matrices have the same number of elements, and those entries are multiplied pairwise and then added up. For larger matrices, one just repeats this procedure $m \\cdot k$ times:\n\\[\\left[ \\begin{array}{cccc}\n\\rowcolor{olive!20}\na_{11} & a_{12} & \\cdots & a_{1n} \\\\\na_{21} & a_{22} & \\cdots & a_{2n} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\na_{m1} & a_{m2} & \\cdots & a_{mn} \\\\\n\\end{array} \\right] \\left[ \\begin{array}{c>{\\columncolor{olive!20}}ccc}\nb_{11} & b_{12} & \\cdots & b_{1k} \\\\\nb_{21} & b_{22} & \\cdots & b_{2k} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\nb_{n1} & b_{n2} & \\cdots & b_{nk} \\\\\n\\end{array} \\right]\n= \\left[ \\begin{array}{cccc}\nc_{11} & \\cellcolor{olive!20} c_{12} & \\cdots & c_{1k} \\\\\nc_{21} & c_{22} & \\cdots & c_{2k} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\nc_{m1} & c_{m2} & \\cdots & c_{mk} \\\\\n\\end{array} \\right]. \\]\n\t\\item Another important definition for matrices is the \\emph{transpose} of a matrix, which leaves the entries $a_{11}, a_{22}, a_{33}, \\dots$ alone and swaps all other entries across the diagonal. This operation is denoted with a ``$^\\top$'' and changes the size of the matrix unless it is square, cf. the examples below.\n\\end{enumerate}\t\n\\end{remark}\n\n\\begin{example}\n\\begin{enumerate}[(i)]\n\t\\item The $2 \\times 2$ identity matrix is $I = \\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}.$\n\t\\item The matrix\n\t\\[ A = \\begin{bmatrix}\n\t1 & 2 \\\\ 3 & 4 \\\\ 5 & 6\n\t\\end{bmatrix}\\]\n\tis of size $3 \\times 2$ and its transpose is the $2 \\times 3$ matrix\n\t\\[ A^{\\top} = \\begin{bmatrix}\n\t1 & 3 & 5 \\\\ 2 & 4 & 6\n\t\\end{bmatrix}.\\]\n\t\\item For the matrix $A$ from (ii), we have\n\t\\[ A + A = \\begin{bmatrix}\n\t1 & 2 \\\\ 3 & 4 \\\\ 5 & 6\n\t\\end{bmatrix} + \\begin{bmatrix}\n\t1 & 2 \\\\ 3 & 4 \\\\ 5 & 6\n\t\\end{bmatrix} = \\begin{bmatrix}\n\t1+1 & 2+2 \\\\ 3+3 & 4+4 \\\\ 5+5 & 6+6\n\t\\end{bmatrix} = \\begin{bmatrix}\n\t2 & 4 \\\\ 6 & 8 \\\\ 10 & 12\n\t\\end{bmatrix},\\]\n\twhich agrees with\n\t\\[ 2 \\, A = 2 \\, \\begin{bmatrix}\n\t1 & 2 \\\\ 3 & 4 \\\\ 5 & 6\n\t\\end{bmatrix} = \\begin{bmatrix}\n\t2\\cdot1 & 2\\cdot2 \\\\ 2\\cdot3 & 2\\cdot4 \\\\ 2\\cdot5 & 2\\cdot6\n\t\\end{bmatrix} = \\begin{bmatrix}\n\t2 & 4 \\\\ 6 & 8 \\\\ 10 & 12\n\t\\end{bmatrix}.\\]\n\t\\item For $A$ and its transpose $A^\\top$, we obtain the products\n\t\\begin{equation*} \\begin{split}\n\tA \\, A^\\top & = \\begin{bmatrix}\n\t1 & 2 \\\\ 3 & 4 \\\\ 5 & 6\n\t\\end{bmatrix} \\begin{bmatrix}\n\t1 & 3 & 5 \\\\ 2 & 4 & 6\n\t\\end{bmatrix} \\\\ & = \\begin{bmatrix}\n\t 1 \\cdot 1 + 2 \\cdot 2 & 1 \\cdot 3 + 2 \\cdot 4 & 1 \\cdot 5 + 2 \\cdot 6 \\\\\n\t 3 \\cdot 1 + 4 \\cdot 2 & 3 \\cdot 3 + 4 \\cdot 4 & 3 \\cdot 5 + 4 \\cdot 6 \\\\ \n\t 5 \\cdot 1 + 6 \\cdot 2 & 5 \\cdot 3 + 6 \\cdot 4 & 5 \\cdot 5 + 6 \\cdot 6\n\t\\end{bmatrix} = \\begin{bmatrix}\n\t5 & 11 & 17 \\\\ 11 & 25 & 39 \\\\ 17 & 39 & 61\n\t\\end{bmatrix}\n\t\\end{split} \\end{equation*}\n\tand\n\t\\begin{equation*}\\begin{split}\n    A^\\top A & = \\begin{bmatrix}\n\t1 & 3 & 5 \\\\ 2 & 4 & 6\n\t\\end{bmatrix} \\begin{bmatrix}\n\t1 & 2 \\\\ 3 & 4 \\\\ 5 & 6\n\t\\end{bmatrix} \\\\ & = \\begin{bmatrix}\n\t1 \\cdot 1 + 3 \\cdot 3 + 5 \\cdot 5 & 1 \\cdot 2 + 3 \\cdot 4 + 5 \\cdot 6 \\\\\n\t2 \\cdot 1 + 4 \\cdot 3 + 6 \\cdot 5 & 2 \\cdot 2 + 4 \\cdot 4 + 6 \\cdot 6\n\t\\end{bmatrix} = \\begin{bmatrix}\n\t35 & 44 \\\\ 44 & 56\n\t\\end{bmatrix}.\n\t\\end{split}\\end{equation*}\n\\end{enumerate}\n\\end{example}\n\n\\begin{properties}\n\t\\label{prop:matrix_mult}\n\t\\begin{enumerate}[(i)]\n\t\t\\item Matrix addition is commutative and associative:\n\t\t\\[ A + B = B + A \\:, \\qquad A+B+C = (A+B)+C = A+(B+C) \\:, \\]\n\t\twhere all three matrices are of the same size.\n\t\t\\item Matrix multiplication is associative as well, but it is not commutative. That is, $AB$ is not always the same as $BA$. However, scalars can be swapped with matrices,\n\t\t\\[ A(\\lambda B) = \\lambda A B \\:. \\]\n\t\t\\item For combinations of the two operations, distributive laws hold:\n\t\t\\[ A (B+ \\wtd{B}) = AB + A\\wtd{B} \\:, \\qquad (A+\\wtd{A})B = AB + \\wtd{A}B \\:,\\]\n\t\twhere $A,\\wtd{A}$ are $m \\times n$ and $B,\\wtd{B}$ are $n \\times k$.\n\t\t\\item For the transpose of a matrix multiplication, we have\n\t\t\\[ (AB)^\\top = B^\\top A^\\top,\\]\n\t\twhere the sizes of $A$ and $B$ are as in the previous property.\n\t\\end{enumerate}\n\\end{properties}\n\n\\begin{definition}[Vectors]\n\\label{def:vectors}\n~\\\\\n\\begin{enumerate}[(i)]\n\t\\item A $n$-vector is a $n \\times 1$ matrix:\n\t\t\\[v = \\begin{bmatrix}\n\t\tv_1 \\\\\n\t\tv_2 \\\\\n\t\tv_3 \\\\\n\t\t\\vdots \\\\\n\t\tv_n \\\\\n\t\t\\end{bmatrix}.\\]\n\t\tWe also refer to $v$ as a vector of size $n$.\n\t\\item As for matrices, $v=w$ means that $v_i = w_i$ for all $i\\in\\{1,2,\\dots,n\\}$, and vectors of different sizes can never be equal. In equations like \n\t\\[ v = 0 \\:, \\]\n\tthe $0$ on the right-hand side is understood to stand for the $n \\times 1$ vector of all zeros rather than the number zero. \n\t\\item Addition and subtraction can only be carried out for vectors of the same size, and then the operation is carried out elementwise:\n\t\t\\begin{equation*}\n\t\tv \\pm w = \\begin{bmatrix}\n\t\tv_1 \\\\\n\t\tv_2 \\\\\n\t\t\\vdots \\\\\n\t\tv_n \\\\\n\t\t\\end{bmatrix} \\pm \\begin{bmatrix}\n\t\tw_1 \\\\\n\t\tw_2 \\\\\n\t\t\\vdots \\\\\n\t\tw_n \\\\\n\t\t\\end{bmatrix} \\\\ = \\begin{bmatrix}\n\t\tv_1 \\pm w_1 \\\\\n\t\tv_2 \\pm w_2 \\\\\n\t\t\\vdots \\\\\n\t\tv_n \\pm w_n \\\\\n\t\t\\end{bmatrix}.\n\t\t\\end{equation*}\n\t\\item Multiplying a number with a vector is called scalar multiplication:\n\t\t\\[ \\lambda v = \\lambda \\begin{bmatrix}\n\t\tv_1 \\\\\n\t\tv_2 \\\\\n\t\t\\vdots \\\\\n\t\tv_n \\\\\n\t\t\\end{bmatrix} = \\begin{bmatrix}\n\t\t\\lambda v_1 \\\\\n\t\t\\lambda v_2 \\\\\n\t\t\\vdots \\\\\n\t\t\\lambda v_n \\\\\n\t\t\\end{bmatrix}. \\]\n\t\\item Multiplication of a matrix and a vector is carried out according to the rules of matrix multiplication: If the number of columns of $A$ agrees with the size of $v$, then\n\t\t\\begin{equation*}\n\t\tA \\, v =\\begin{bmatrix}\n\t\ta_{11} & a_{12} & \\cdots & a_{1n} \\\\\n\t\ta_{21} & a_{22} & \\cdots & a_{2n} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\ta_{m1} & a_{m2} & \\cdots & a_{mn} \\\\\n\t\t\\end{bmatrix} \\begin{bmatrix}\n\t\tv_1 \\\\\n\t\tv_2 \\\\\n\t\t\\vdots \\\\\n\t\tv_n \\\\\n\t\t\\end{bmatrix}\n\t\t= \\begin{bmatrix}\n\t\tc_1 \\\\\n\t\tc_2 \\\\\n\t\t\\vdots \\\\\n\t\tc_m \\\\\n\t\t\\end{bmatrix},\n\t\t\\end{equation*}\n\t\twhere $c_i = \\sum_{s=1}^n a_{is}v_{s}$. The result is a vector of size $m$.\n\t\\item The \\emph{scalar product} (or \\emph{dot product}) of two vectors $v$ and $w$ of the same size is\n\t\t\\[ v \\circ w = \\begin{bmatrix} v_1 \\\\ v_2 \\\\ \\vdots \\\\ v_n \\end{bmatrix} \\circ\n\t\t\t\t\t   \\begin{bmatrix} w_1 \\\\ w_2 \\\\ \\vdots \\\\ w_n \\end{bmatrix}\n\t\t\t\t\t   = \\sum_{s=1}^n v_s w_s \\:. \\]\n\t\\item A \\emph{row vector} of size $n$ is a $1 \\times n$ matrix:\n\t\\[v = \\begin{bmatrix}\n\tv_1 & v_2 & v_3 & \\cdots & v_n \\end{bmatrix}. \\]\n\t\\item The \\emph{norm} of a vector is\n\t\\[ ||v|| = \\sqrt{v_1^2+v_2^2+ \\dots v_n^2} = \\sqrt{v \\circ v} \\:. \\]\n\t\\end{enumerate}\n\\end{definition}\n\n\\begin{remark}\n\\label{rem:vectors}\n\\begin{enumerate}[(i)]\n\t\\item The term ``vector'' always refers to a one-column matrix as in (i) of Definition~\\ref{def:vectors}, and it is sometimes called \\emph{column vector} to distinguish it more explicitly from a row vector. Note that parts (i)-(v) of~\\ref{def:vectors} are inherited from the corresponding matrix definitions, and only (vi)-(viii) are new and specific to vectors. Regarding multiplication and products: a simple dot ``$\\cdot$'' stands either for regular multiplication of two numbers, for scalar multiplication (multiplication of a number with a vector or matrix), or for matrix multiplication (multiplication of matrices and vectors of appropriate size). However, the ``$\\cdot$'' may be omitted. For scalar products, we always write the~``$\\circ$''.\n\t\\item The matrix transpose allows to write the scalar product of two vectors as a matrix product: Let $v,w$ be two vectors of the same size, then\n\t\\[ v \\circ w = v^\\top w \\:. \\]\n\t\\item When defining a vector in-line, it is more convenient to write down its transpose. For example, $v = \\begin{bmatrix} 2 & -1 & 3 \\end{bmatrix}^\\top$ is the vector\n\t\\[ v = \\begin{bmatrix} 2 \\\\ -1 \\\\ 3 \\end{bmatrix}. \\]\n\t\\item We write $v\\in\\mathbb{R}^n$ for a vector of size $n$, meaning that $v$ has $n$ entries and each of them is a real number. For $n=2$ or $n=3$~: Picturing a vector as an arrow in the two-dimensional plane $\\mathbb{R}^2$ or in the three-dimensional space $\\mathbb{R}^3$, the norm $||v||$ is simply its length. The angle $\\theta$ between two vectors $v$ and $w$ of the same size is\n\t\\[ \\cos \\theta = \\frac{v \\circ w}{||v|| \\, ||w||} \\:. \\]\n\t\\end{enumerate}\n\\end{remark}\n\n\\begin{example}\n\\begin{enumerate}[(i)]\n\t\\item \\[ \\begin{bmatrix}\n\t11 \\\\ -6 \\\\ 6\n\t\\end{bmatrix} - \\begin{bmatrix}\n\t-7 \\\\ -1 \\\\ 3\n\t\\end{bmatrix} = \\begin{bmatrix}\n\t18 \\\\ -5 \\\\ 3\n\t\\end{bmatrix} \\]\n\t\\item \\[ \\begin{bmatrix}\n\t4 & -1 \\\\ 0 & -3 \\\\ 7 & 1\n\t\\end{bmatrix} \\begin{bmatrix}\n\t-9 \\\\ 3\n\t\\end{bmatrix} = \\begin{bmatrix}\n\t4 \\cdot (-9) + (-1) \\cdot 3 \\\\\n\t0 \\cdot (-9) + (-3) \\cdot 3 \\\\\n\t7 \\cdot (-9) + 1 \\cdot 3 \\\\\n\t\\end{bmatrix} = \\begin{bmatrix}\n\t-39 \\\\ -9 \\\\ -60\n\t\\end{bmatrix}\\]\n\t\\item The scalar product of $v = \\begin{bmatrix} 4 & - 4 & 1 \\end{bmatrix}^\\top$\n\tand $w = \\begin{bmatrix} 3 & -2 & -5\\end{bmatrix}^\\top$ is\n\t\\[ v \\circ w = \\begin{bmatrix} 4 \\\\ -4 \\\\ 1 \\end{bmatrix} \\circ\n\t\\begin{bmatrix} 3 \\\\ -2 \\\\ -5\\end{bmatrix} \n\t= 4 \\cdot 3 + (-4) \\cdot (-2) + 1 \\cdot (-5) = 15 \\:. \\]\n\t\\item The scalar product in the previous example can also be computed as a matrix multiplication, namely $v^\\top w =15$. Transposing the second vector instead gives a $3 \\times 3$ matrix:\n\t\\begin{equation*}\n\t\\begin{split}\nv w^\\top &= \\begin{bmatrix} 4 \\\\ -4 \\\\ 1 \\end{bmatrix} \n\\begin{bmatrix} 3 & -2 & -5\\end{bmatrix} \\\\ &= \\begin{bmatrix}\n4 \\cdot 3 & 4 \\cdot (-2) & 4 \\cdot (-5) \\\\\n(-4) \\cdot 3 & (-4) \\cdot (-2) & (-4) \\cdot (-5) \\\\\n1 \\cdot 3 & 1 \\cdot (-2) & 1 \\cdot (-5) \\\\\n\\end{bmatrix} = \\begin{bmatrix}\n12 & -8 & -20 \\\\ -12 & 8 & 20 \\\\ 3 & -2 & -5 \n\\end{bmatrix}.\n\t\\end{split}\n\t\\end{equation*}\n\t\\item \n\t\\[ \\begin{bmatrix}\n\t0 & -2 & 13\n\t\\end{bmatrix} \\begin{bmatrix}\n\t3 & 2 & -4 \\\\ 5 & -3 & 0 \\\\ 1 & -2 & 1\n\t\\end{bmatrix} \\begin{bmatrix}\n\t3 \\\\ 7 \\\\ -1\n\t\\end{bmatrix} = \\begin{bmatrix}\n\t0 & -2 & 13\t\n\t\\end{bmatrix} \\begin{bmatrix}\n\t27 \\\\ -6 \\\\ -12\n\t\\end{bmatrix} = -144 \\]\n\t\\item The norm of $v=\\begin{bmatrix}1 & 2 & 3\\end{bmatrix}^\\top$ is\n\t\\[ ||v|| = \\sqrt{1^2+2^2+3^2} = \\sqrt{14} \\:. \\]\n\tFor its angle with $\\begin{bmatrix}3 & 2 & 1\\end{bmatrix}^\\top$, we find\n\t\\[ \\cos \\theta = \\frac{3+4+3}{\\sqrt{14}\\sqrt{14}} = \\frac57 \\:, \\]\n\twhich gives $\\theta = \\arccos \\left(\\rfrac57\\right) \\approx 0.7752$ (this angle is in radians and corresponds to $44.42$ degrees; here, $\\arccos$ is the inverse function of $\\cos$).\n\\end{enumerate}\n\\end{example}\n\n\\begin{definition}[Determinants]\nThe \\emph{determinant} of a square matrix is a scalar and defined as follows for matries of sizes up to $3 \\times 3$.\n\\begin{enumerate}[(i)]\n\t\\item The determinant of a $1 \\times 1$ matrix is\n\t\\[ \\det \\begin{bmatrix} a_{11} \\end{bmatrix} = a_{11} \\:. \\]\n\t\\item The determinant of a $2 \\times 2$ matrix is\n\t\\[ \\det\\begin{bmatrix} a_{11} & a_{12} \\\\ a_{21} & a_{22} \\end{bmatrix}\n\t= a_{11}a_{22} - a_{21}a_{12} \\:. \\]\n\t\\item The determinant of a $3 \\times 3$ matrix is\n\t\\begin{equation*}\n\t\\begin{split} \\det\\begin{bmatrix} a_{11} & a_{12} & a_{13} \\\\ a_{21} & a_{22} & a_{23} \\\\ a_{31} & a_{32} & a_{33} \\end{bmatrix} = a_{11}a_{22}a_{33} + & a_{12}a_{23}a_{31} + a_{13}a_{21}a_{32} \\\\ & - a_{31}a_{22}a_{13} - a_{32}a_{23}a_{11} - a_{33}a_{21}a_{12} \\:.\n\t\\end{split}\n\t\\end{equation*}\n\\end{enumerate}\n\\end{definition}\n\n\\begin{remark}\n\\begin{enumerate}[(i)]\n\t\\item One can write $\\abs{\\dots}$ as an abbreviation for $\\det\\begin{bmatrix} \\dots \\end{bmatrix}$.\n\t\\item Determinants of $1 \\times 1$ matrices are quite straightforward; for $2 \\times 2$, subtract the product of the off-diagonal entries from the product of the diagonal entries; see the following two points for $3 \\times 3$. Determinants are also defined for larger square matrices, but the formulas become quite bulky then and one would not write them out as in the definition above.\n\t\\item Sarrus' rule should help you memorise the formula for the determinant of a $3 \\times 3$ matrix: For $A$ with entries as in (iii) of the definition above, write down $A$, copy the first two columns and append them to the right of the matrix; draw (or imagine) the lines\n\t\\[ \\begin{array}{ccccc}\n\t\t\\tikzmark{A11}{a_{11}} & \\tikzmark{A12}{a_{12}} & \\tikzmark{A13}{a_{13}} & \\tikzmark{A11A}{a_{11}} & \\tikzmark{A12A}{a_{12}} \\\\\n\t\ta_{21} & a_{22} & a_{23} & a_{21} & a_{22} \\\\\n\t\t\\tikzmark{A31}{a_{31}} & \\tikzmark{A32}{a_{32}} & \\tikzmark{A33}{a_{33}} & \\tikzmark{A31A}{a_{31}} & \\tikzmark{A32A}{a_{32}} \\\\\n\t\\end{array} \\:; \\]\n\t\\begin{tikzpicture}[overlay,remember picture]\n%\t\\draw (A11.center) -- (A33.center);\n%\t\\draw (A12.center) -- (A31A.center);\n%\t\\draw (A13.center) -- (A32A.center);\n%\t\\draw[dashed] (A31.center) -- (A13.center);\n%\t\\draw[dashed] (A32.center) -- (A11A.center);\n%\t\\draw[dashed] (A33.center) -- (A12A.center);\n\t\\draw[opacity=.3,line width=4mm,line cap=round,draw=blue] (A11.center) -- (A33.center);\n\t\\draw[opacity=.3,line width=4mm,line cap=round,draw=blue] (A12.center) -- (A31A.center);\n\t\\draw[opacity=.3,line width=4mm,line cap=round,draw=blue] (A13.center) -- (A32A.center);\n\t\\draw[opacity=.3,line width=4mm,line cap=round,draw=red] (A31.center) -- (A13.center);\n\t\\draw[opacity=.3,line width=4mm,line cap=round,draw=red] (A32.center) -- (A11A.center);\n\t\\draw[opacity=.3,line width=4mm,line cap=round,draw=red] (A33.center) -- (A12A.center);\n\t\\end{tikzpicture}\n\t\n\tadd up the products of the entries in each blue line, and subtract the three red products.\n\t\\item Laplace's formula:\n\t\\[ \\begin{vmatrix}\n\ta_{11} & a_{12} & a_{13} \\\\ a_{21} & a_{22} & a_{23} \\\\ a_{31} & a_{32} & a_{33}\n\t\\end{vmatrix} = a_{11}\\begin{vmatrix}\n\ta_{22} & a_{23} \\\\ a_{32} & a_{33}\n\t\\end{vmatrix} - a_{12}\\begin{vmatrix}\n\ta_{21} & a_{23} \\\\ a_{31} & a_{33}\t\n\t\\end{vmatrix} + a_{13}\\begin{vmatrix}\n\ta_{21} & a_{22} \\\\ a_{31} & a_{32}\n\t\\end{vmatrix} \\:. \\]\n\tHere we have ``developed'' the determinant along the first row $(a_{11},a_{12},a_{13})$, but it is also possible to develop along a different row or even along a column. The general formulas are\n\t\\begin{equation}\n\t\\label{eq:laplace}\n\t\\begin{split}\n\t\\det A & = \\sum_{j=1}^3 (-1)^{i+j} a_{ij} \\det \\wtd{A}_{ij}\n\t\\qquad \\text{(dev. along $i$-th row),} \\\\\n\t\\det A & = \\sum_{i=1}^3 (-1)^{i+j} a_{ij} \\det \\wtd{A}_{ij} \\qquad \\text{(dev. along $j$-th column),}\n\t\\end{split}\n\t\\end{equation}\n\twhere $\\wtd{A}_{ij}$ is the $2 \\times 2$ matrix we obtain by removing the $i$-th row and the $j$-th column from $A$. Choose the row/column wisely! For example, if there is a row or a column with only one nonzero entry, developing along it will shorten the computation.\n\t\\item Laplace's formula generalises to larger square matrices -- just replace the maximum index $3$ of the sums in~\\eqref{eq:laplace} with $n$. Note that Laplace's formula does not directly compute determinants -- it reduces the problem of finding a $n \\times n$ determinant to finding the determinants of $n$ matrices of size $(n-1) \\times (n-1)$. Sarrus' rule works only for $3 \\times 3$'s, it can not be applied to larger matrices.\n\\end{enumerate}\n\\end{remark}\n\n\\begin{example}\n\\begin{enumerate}[(i)]\n\t\t\\item \\[ \\begin{vmatrix} 1 & 2 \\\\ 3 & 4 \\end{vmatrix} = 1 \\cdot 4 - 2 \\cdot 3 = -2 \\]\n\t\t\\item \\[ \\begin{vmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\\\ 7 & 8 & 9 \\end{vmatrix} = 1 \\cdot 5 \\cdot 9 + 2 \\cdot 6 \\cdot 7 + 3 \\cdot 4 \\cdot 8 - 7 \\cdot 5 \\cdot 3 - 8 \\cdot 6 \\cdot 1 - 9 \\cdot 4 \\cdot 2 = 0 \\]\n\t\t\\item \\[ \\begin{vmatrix} 1 & -3 & 2 \\\\ 0 & 7 & -1 \\\\ 0 & 0 & -3 \\end{vmatrix} = 1 \\cdot 7 \\cdot (-3) = -21 \\]\n\t\t\\item To compute the determinant of \n\\[ A = \\begin{bmatrix} 4 & -1 & 11 & 3  \\\\ -2 & 3 & -3 & -5 \\\\ \n0 & 1 & -8 & 0 \\\\ 1 & 0 & -6 & -2 \\end{bmatrix}, \\]\nwe use Laplace's formula, developing along the row with the most zero entries:\n\\begin{equation*}\n\\begin{split}\n\\det A \n& = (-1)^{3+1} \\cdot 0 \\begin{vmatrix} \\ldots \\end{vmatrix}\n+ (-1)^{3+2} \\cdot 1 \\begin{vmatrix} \\ldots \\end{vmatrix}\n+ (-1)^{3+3} \\cdot (-8) \\begin{vmatrix} \\ldots \\end{vmatrix} \\\\\n& \\quad + (-1)^{3+4} \\cdot 0 \\begin{vmatrix} \\ldots \\end{vmatrix} \n= - \\begin{vmatrix} 4 & 11 & 3 \\\\ -2 & -3 & -5 \\\\ 1 & -6 & -2 \\end{vmatrix}\n- 8 \\begin{vmatrix} 4 & -1 & 3 \\\\ -2 & 3 & -5 \\\\ 1 & 0 & -2 \\end{vmatrix} \\\\ \n& = -4\\begin{vmatrix} -3 & -5 \\\\ -6 & -2 \\end{vmatrix} \n+11\\begin{vmatrix} -2 & -5 \\\\ 1 & -2 \\end{vmatrix}\n-3\\begin{vmatrix} -2 & -3 \\\\ 1 & -6 \\end{vmatrix}\n-8\\cdot\\begin{vmatrix} \\ldots \\end{vmatrix} = \\ldots = 342 \\:.  \n\\end{split}\n\\end{equation*}\n\\end{enumerate}\n\\end{example}\n\n\\begin{properties}\n\t\\label{prop:det}\n\tLet $A$ be a $n \\times n$ matrix and let $\\lambda$ be a scalar.\n\t\\begin{enumerate}[(i)]\n\t\t\\item If $A$ has a row or a column of zeros, then $\\det A=0$.\n\t\t\\item If a row of $A$ is a multiple of some other row of $A$, then $\\det A =0$. Similar for columns.\n\t\t\\item If $A$ is an upper triangular matrix,\n\t\t\\[ A = \\begin{bmatrix} \n\t\ta_{11} & a_{12} & a_{13} & \\cdots & a_{1n}\\\\\n\t\t0      & a_{22} & a_{23} &        & a_{2n}\\\\\n\t\t0      & 0      & a_{33} &        & a_{3n}\\\\\n\t\t\\vdots &        & \\ddots & \\ddots &\\vdots \\\\\n\t\t0      & 0      & \\cdots & 0 & a_{nn} \n\t\t\\end{bmatrix}, \\]\n\t\tthen the determinant is just the product along the diagonal, \n\t\t\\[ \\det A = a_{11} a_{22} a_{33} \\dots a_{nn} \\:. \\]\n\t\\end{enumerate}\n\\end{properties}\n\n\\begin{application}[Orthogonal projection]\n\tA data scientist is working on a large data set of the form\n\t\\[\\{(x_1,y_1), (x_2,y_2), (x_3,y_3), \\dots, (x_n,y_n)\\} \\:. \\]\n\tShe begins her analysis by plotting all data points in the $xy$-plane:\n\t%\\figbox{Data in the $xy$-plane:}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.6\\textwidth]{./Figures/f201.png}\n\t\\end{center}\n\tHere, $n$ individuals or events were observed, and two pieces of information were recorded for each individual/event (e.g., $n$ patients, $x_k$ stands for the score on a certain medical test, and $y_k$ stands for the score on a different test). Note that the data points are concentrated around a line. The data scientist has computed the slope of the line -- we will learn how fit lines through data later -- and now wants to project the data points onto it. One of the main advantages of this step is that the projected data will then be one-dimensional. That is, each point can then be described by one real number, namely its position along the line. This reduction can make a significant difference for the overall computational complexity of big data projects.\n\t\n\tWe now derive how to project points \\emph{orthogonally} onto a line. Let $L\\subseteq\\mathbb{R}^2$ be a line and let $w\\in\\mathbb{R}^2$ be a point that is not an element of $L$. Denote the projection of $w$ onto $L$ by $\\wtd{w}$. To project orthogonally means that the line segment connecting $w$ and $\\wtd{w}$ is orthogonal to $L$. Let $v$ be a vector that spans $L$, i.e. $L$ is the set of all scalar multiples of $V$,\n\t\\[ L = \\{ \\lambda v \\: | \\: \\lambda \\in \\mathbb{R} \\} \\subseteq \\mathbb{R}^2 \\:. \\]\n\tThis looks as follows, and the goal is now to find a formula for $\\wtd{w}$ in terms of $v$ and~$w$.\n\t%\\figbox{Orth. proj. onto a line:}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.6\\textwidth]{./Figures/f202.png}\n\t\\end{center}\n\t\n\tTo visualise elements of $\\mathbb{R}^2$, we are using two interpretations interchangeably: $w$ can be interpreted as a point, e.g.,\n\t\\[ w = (1,2) \\:, \\]\n\tor as a vector,\n\t\\[ w = \\begin{bmatrix} 1 \\\\ 2 \\end{bmatrix}, \\]\n\twhere the latter is often drawn as an arrow. Basing the arrow at the origin $(0,0)$ of the $xy$-plane, and interpreting it as ``move $1$ in the $x$ direction and $2$ in the $y$ direction'', we see that the vector $w$ points to the point $w$. This correspondence justifies switching freely between the two interpretations.\n\t\n\tBack to the task at hand, let us collect a few formulas for the right-angled triangle in the sketch:\n\t\\begin{enumerate}\n\t\t\\item \\[ \\cos \\theta = \\frac{ v \\circ w }{||v||\\,||w||} \\]\n\t\t\\hfill (cf. Remark~\\ref{rem:vectors} (iv))\n\t\t\\item \\[ \\cos \\theta \n\t\t= \\frac{\\text{length adjacent side}}{\\text{length hypotenuse}} \n\t\t= \\frac{||\\wtd{w}||}{||w||} \\]\n\t\t\\hfill (trig. identity for right-angled triangle)\n\t\t\\item \\[ \\wtd{w} = \\frac{||\\wtd{w}||}{||v||} \\, v \\]\n\t\\end{enumerate}\n\tRegarding the last formula: $\\wtd{w}$ can be written as $\\wtd{w}=\\lambda v$ with $\\lambda > 0$, since it lies on the side of $L$ in which $v$ points. To verify that the factor $\\lambda = \\rfrac{||\\wtd{w}||}{||v||}$ is correct, we use the fact that $||\\lambda v||=|\\lambda| \\,||v||$~:\n\t\\[ \\left|\\left| \\, \\frac{||\\wtd{w}||}{||v||} v  \\, \\right| \\right|\n\t=  \\left| \\frac{||\\wtd{w}||}{||v||} \\right| ||v||\n\t=  \\frac{||\\wtd{w}||}{||v||} ||v||\n\t= ||\\wtd{w}|| \\qquad \\text{\\checkmark} \\]\n\tCombining these formulas gives\n\t\\begin{equation*}\n\t\\wtd{w} \\stackrel{(3)}{=} v \\cdot \\frac{||\\wtd{w}||}{||v||}\n\t\\stackrel{(2)}{=} v \\cdot \\frac{\\cos\\theta\\,||w||}{||v||}\n\t\\stackrel{(1)}{=} v \\cdot \\frac{\\frac{ v \\circ w }{||v||\\,||w||}\\,||w||}{||v||}\n\t= \\frac{v \\cdot (v \\circ w)}{||v||^2} \\:.\n\t\\end{equation*}\n\tBoth $v \\circ w$ and $||v||^2 = v \\circ v$ are scalars that can be written as matrix products via transposition of the first factor. Once all operations are regular products, associativity of matrix multiplication can be used. We find that the projection $w \\mapsto \\wtd{w}$ is carried out by multiplication with a $2 \\times 2$ matrix:\n\t\\[ \\wtd{w} = \\frac{v \\cdot (v^\\top \\cdot w)}{v^\\top \\cdot v}\n\t= \\frac{v \\, v^\\top}{v^\\top \\, v} \\, w  = P_L \\, w \\:. \\]\n\\end{application}\n\n\\begin{exercise}\n\\begin{enumerate}[(i)]\n\t\\item Practise matrix multiplication by finding $AB$ and $BA$ for the matrices\\footnote{For the difference $AB-BA$, you should obtain\n\t\\[ \\begin{bmatrix}\n\t10 & 7 & -20 \\\\ -23 & -9 & 39 \\\\ 1 & 3 & -1 \n\t\\end{bmatrix}. \\]} \n\t\\[ A = \\begin{bmatrix}\n\t4 & 2 & -1 \\\\ -3 & -3 & 9 \\\\ 1 & 0 & 6\n\t\\end{bmatrix}, \\quad B = \\begin{bmatrix}\n\t3 & 3 & -1 \\\\ 0 & -4 & 2 \\\\ 0 & 0 & 2\n\t\\end{bmatrix}. \\]\n\t\\item Compute the matrix product \n\t\\[ \\begin{bmatrix} 1 & 2 \\end{bmatrix} \n\t\\begin{bmatrix} 3 & 4 \\\\ 5 & 6 \\end{bmatrix}\n\t\\begin{bmatrix} 7 \\\\ 8 \\end{bmatrix}. \\]\n\tThe multiplication can be carried out in two different ways: $(AB)C$ and $A(BC)$ -- try both approaches and make sure that you obtain the same result.\n\t\\item Consider the function $f(x)=x^2-2x-3$. This expression can also be written as $x^2 - 2 \\cdot x^1 - 3 \\cdot x^0$, since $x^0=1$. For matrices, the zeroth power is defined similarly: $A^0=I$, where $I$ is the identity matrix. Hence find $f(A)$ for the matrix\\footnote{$f(A)=0$.}\n\t\\[ A = \\begin{bmatrix} -1 & 0 \\\\ 4 & 3\t\\end{bmatrix}. \\]\n\t\\item Find the angle between the two vectors\\footnote{$\\theta = \\tfrac{\\pi}{3}$.}\n\t\\[ v = \\begin{bmatrix} 2 & -1 & 0 & 1 \\end{bmatrix}^\\top,\n\t\\quad w = \\begin{bmatrix} 4 & 2 & 2 & 0 \\end{bmatrix}^\\top. \\]\n\t\\item Pick a $2 \\times 3$ and a $3 \\times 1$ matrix and check that property (iv) in~\\ref{prop:matrix_mult} holds. Similarly, verify the statements made in~\\ref{prop:det} for a few examples. (Be aware though that verifying examples does not constitute a proof!)\n\t\\item Compute the determinants of\\footnote{The determinants are $8,18,30$.}\n\t\\[ \\begin{bmatrix} 3 & 1 \\\\ -5 & 1 \\end{bmatrix}, \\quad\n\t\\begin{bmatrix}\t3 & 1 & -2 \\\\ -5 & 1 & 3 \\\\ 2 & 0 & 1 \\end{bmatrix}, \\quad\n\t\\begin{bmatrix}\n\t3 & 1 & -2 & 3 \\\\ -5 & 1 & 3 & -4 \\\\ 2 & 0 & 1 & -1 \\\\ 1 & -5 & 3 & -3 \n\t\\end{bmatrix} . \\]\n\t\\item Let $A$, $B$, $C$ be $n \\times n$ matrices with the properties $AB=I$, $BC=I$, $CA=I$. Find $\\tfrac13\\left(A^2+B^2+C^2\\right)$.\n\t\\item Let $I$ be the $2 \\times 2$ identity matrix. Show that for any $2 \\times 2$ matrix\\footnote{Consider a general matrix $A = \\begin{bmatrix} a & b \\\\ c & d \\end{bmatrix}$; multiply with $I$ in both orders; compare.} $A$, \\[A \\, I = I \\, A = A\\:.\\] \n\t\\item The product $AB$ is not always the same as $BA$, but for some matrices we do have $AB=BA$ -- e.g., if one of the two is the zero matrix or the identity matrix. Perhaps there are more matrices that commute with a given matrix~$A$.\n\t\n\tConsider\n\t\\[ A = \\begin{bmatrix} 1 & 0 \\\\ -1 & 0\t\\end{bmatrix}. \\]\n\tFor which $2 \\times 2$ matrices $X$ do we have\\footnote{Matrices of the form\n\t\t\\[ X = \\begin{bmatrix} a & 0 \\\\ b & a+b \\end{bmatrix}, \\]\n\t\twhere $a,b\\in\\mathbb{R}$, commute with $A$.} $AX=XA$ ?\n\t\\item Show that\\footnote{Prove by induction; use angle sum identities for trigonometric functions.}\n\t\\[ \\begin{bmatrix} \\cos \\theta & - \\sin \\theta \\\\ \\sin \\theta & \\cos \\theta \\end{bmatrix}^n\n\t= \\begin{bmatrix} \\cos n\\theta & - \\sin n\\theta \\\\ \\sin n\\theta & \\cos n\\theta \\end{bmatrix}. \\]\n\t\\item Suppose you have to find the determinant of a $7 \\times 7$ matrix that has no zero entries. You plan to reduce the problem to finding $3 \\times 3$'s by applying Laplace's formula several times. How many $3 \\times 3$ determinants do you have to compute?\n\t\\item Find the two scalars $\\lambda_1$ and $\\lambda_2$ for which the determinant of \n\t\\[ A_{\\lambda} = \\begin{bmatrix}\n\t\\lambda & 1 & 1 \\\\ 1 & \\lambda & 1 \\\\ 1 & 1 & \\lambda\n\t\\end{bmatrix} \\]\n\tis equal to zero\\footnote{Computing this determinant with Sarrus' rule leads to a third-order algebraic expression in $\\lambda$. To find its zeros, you first need to guess one solution -- property (ii) of~\\ref{prop:det} should be helpful. The second value for $\\lambda$ is $\\lambda_2=-2$.}.\n\t\\item Project the point $p=(\\rfrac12,10)$ orthogonally onto the line\\footnote{\n\t\\[  \\wtd{p} = \\frac{1}{26}\n\t\\begin{bmatrix} 1 & 5 \\\\ 5 & 25 \\end{bmatrix} \\begin{bmatrix} \\rfrac12 \\\\ 10 \\end{bmatrix}\n\t= \\frac{50.5}{26}\\begin{bmatrix} 1 \\\\ 5 \\end{bmatrix}\n\t\\approx \\begin{bmatrix} 1.942 \\\\ 9.712 \\end{bmatrix} \\]}\n\t$L \\: : \\: y=5x$.\n\\end{enumerate}\n\\end{exercise}\n\n\n\\section{Systems of Linear Equations: Gaussian Elimination}\n\\label{sec:sys_lin_equ}\nSuppose that the two equations\n\\begin{equation*}\n\\begin{cases}\n\\begin{array}{rcccccl}\n2 & x & - & 3 & y & = & 7 \\\\\n-2 & x & + & & y & = & 5\n\\end{array} \\end{cases}\n\\end{equation*}\nneed to be satisfied simultaneously. Adding them together gives $-2y = 12$ and therefore $y = -6$. Now that $y$ is known, the first of the original equations reads $2x-3(-6) = 7$ and hence the solution is\n\\begin{equation}\n\\label{eq:sole_sol}\nx = -\\frac{11}{2}, \\: y = -6 \\:.\n\\end{equation}\n\n\\begin{remark}\n\\begin{enumerate}[(i)]\n\t\\item The first equation above defines a line in the $xy$-plane, namely $y=\\tfrac23x-\\tfrac73$. Similarly, the second equation describes the line $y=2x+5$. With the computation above, we have found the intersection of those two lines.\n\t\\item In order to convince yourself that it is permissible to add two equations together, think of two libra scales. Suppose that each of them is in balance. Then, taking the two objects from one scale and putting them onto the two arms of the other, the scale will still be in balance.\n\t\\item The solution~\\eqref{eq:sole_sol} above -- which consists of two equations -- can also be written as one vector equation:\n\t\\[ \\begin{bmatrix} x \\\\ y \\end{bmatrix} \n\t= \\begin{bmatrix} -\\tfrac{11}{2} \\\\ -6 \\end{bmatrix}. \\] \n\\end{enumerate}\n\\end{remark}\n\n\\begin{definition}[Linear systems of equations] \n\\label{def:lin_sys_equ}\nA collection of equations of the form\n\\begin{equation*}\n\\begin{cases}\n\\begin{array}{ccccccccc}\na_{11} \\: x_1 & + & a_{12} \\: x_2 & + & a_{13} \\: x_3 & \\dots & + & a_{1n} \\: x_n & = \\: b_1 \\\\\na_{21} \\: x_1 & + & a_{22} \\: x_2 & + & a_{23} \\: x_3 & \\dots & + & a_{2n} \\: x_n & = \\: b_2 \\\\\n\\vdots & & & & \\vdots & & & &\\vdots \\\\\na_{m1} \\: x_1 & + & a_{m2} \\: x_2 & + & a_{m3} \\: x_3 & \\dots & + & a_{mn} \\: x_n & = \\: b_m \n\\end{array} \\end{cases}\n\\end{equation*}\nis called a \\emph{linear system of equations}. Here, $(x_1,x_2,\\dots,x_n)$ are the variables, the $a_{ij}$ are the coefficients of the system, and $(b_1,b_2,\\dots,b_m)$ is the right-hand side (RHS). If the RHS is zero, $b_1 = b_2 = \\dots = b_m = 0$, then the system is called \\emph{homogeneous}. A combination of variables $(x_1^*,x_2^*,\\dots,x_n^*)$ that satisfies all $m$ equations simultaneously is called a \\emph{solution} of the system.\n\\end{definition}\n\n\\begin{remark}\n\\begin{enumerate}[(i)]\n\\item For $n=2$ or $n=3$ the variables are often called $(x,y)$ or $(x,y,z)$.\n\\item Each equation demands that some ``linear combination'' of the variables -- that is, the variables multiplied by some coefficients and then added up -- be equal to some given value. If powers or square roots or other functions of the variables appear in an equation, then it is not linear and can not be solved with the theory developed in this chapter.\n\\item Such a system can have no solution, a unique solution, or many solutions.\n\\item We refer to the equations in the system as \\emph{rows}, and the following definition lists modifications of a system that do not change the set of solutions. We have already used one such modification in the computation above: adding one row to another.\n\\end{enumerate}\n\\end{remark}\n\n\\begin{definition}[Elementary row operations]\n\t\\label{def:ero}\nThe following \\emph{row operations} on a system of equations do not change the set of its solutions.\n\\begin{enumerate}[(i)]\n\\item Add one row to another.\n\\item Multiply a row by a scalar different from zero.\n\\item Add the multiple of a row to another row.\n\\item Swap rows.\n\\end{enumerate}\n\\end{definition}\n\n\\begin{example}\n\\label{expl:lin_sys_equ}\nSolve the system\n\\begin{equation*}\n\\begin{cases}\n\\begin{array}{rrrrrrr}\n x & - & y &  &  & = & 3 \\phantom{\\:.} \\\\\n-3 x & + & 4 y & + & z & = & -1 \\phantom{\\:.} \\\\\n2 x &  & & + & 7 z & = & -3 \\:.\n\\end{array} \\end{cases}\n\\end{equation*}\n{\\it Sol.:} We ``eliminate'' the terms $-3x$ and $2x$ by adding $3$ times the first row to the second and by subtracting $2$ times the first row from the third. This transformation is denoted ``$R2 \\rightarrow R2 + 3 \\cdot R1$'' and ``$R3 \\rightarrow R3 - 2 \\cdot R1$'', i.e. the arrow is to be read as ``is replaced with'':\n\\begin{equation}\n\\label{eq:first_3x3_example}\n\\begin{split}\n\\begin{array}{cc}\n& ~~~\\rightarrow~~~ \\\\\nR2 \\rightarrow R2 + 3 \\cdot R1 & \\\\\nR3 \\rightarrow R3 - 2 \\cdot R1 &\n\\end{array}\n& \\begin{cases}\n\\begin{array}{rrrrrrr}\nx & - & y &  &  & = & 3 \\\\\n & & y & + & z & = & 8 \\\\\n & & 2 y & + & 7 z & = & -9 \n\\end{array} \\end{cases} \\\\ \n\\begin{array}{cc}\n& ~~~\\rightarrow~~~ \\\\\n& \\\\\nR3 \\rightarrow R3 - 2 \\cdot R2 &\n\\end{array}\n& \\begin{cases}\n\\begin{array}{rrrrrrr}\nx & - & y &  &  & = & 3 \\phantom{\\:.} \\\\\n& & y & + & z & = & 8 \\phantom{\\:.} \\\\\n& & & & 5 z & = & -25 \\:.\n\\end{array} \\end{cases}  \n\\end{split}\n\\end{equation}\nThe last line yields $z = -5$, and one can then find $y$ and $x$ by back-substituting into the first two equations,\n\\[ x = 16, \\: y = 13, \\: z = -5 \\:. \\]\n\\end{example}\n\n\\begin{remark}\n\\begin{enumerate}[(i)]\n\\item The system in Definition~\\ref{def:lin_sys_equ} can also be written in matrix form. Keeping in mind that an equation of two $n$-vectors amounts to $n$ equations, convince yourself that the following is equivalent to the system in~\\ref{def:lin_sys_equ}.\n\\[\n\\begin{bmatrix}\na_{11} & a_{12} & a_{13} & \\cdots & a_{1n} \\\\\na_{21} & a_{22} & a_{23} & \\cdots & a_{2n} \\\\\n\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\na_{m1} & a_{m2} & a_{m3 }& \\cdots & a_{mn}\n\\end{bmatrix} \\begin{bmatrix}\nx_1 \\\\ x_2 \\\\ x_3 \\\\ \\vdots \\\\ x_n\n\\end{bmatrix} = \\begin{bmatrix}\nb_1 \\\\ b_2 \\\\ \\vdots \\\\ b_m\n\\end{bmatrix}.\n\\]\n\\item The transformation~\\eqref{eq:first_3x3_example} via elementary row operations in the previous example is called \\emph{Gaussian elimination}. We now define two standard matrix forms that are the goal of this process.\n\\end{enumerate}\n\\end{remark}\n\n\\begin{definition}[Augmented matrix, row echelon form, rank]\n\\end{definition}\n\\begin{enumerate}[(i)]\n\t\\item The \\emph{augmented matrix} for the system in Definition~\\ref{def:lin_sys_equ} is\n\t\\[ [A\\:|\\:b] = \\left[\\begin{array}{ccccc|c}\n\ta_{11} & a_{12} & a_{13} & \\dots & a_{1n} & b_1 \\\\\n\ta_{21} & a_{22} & a_{23} & \\dots & a_{2n} & b_2 \\\\\n\t\\vdots & \\vdots & \\vdots &\\ddots & \\vdots & \\vdots \\\\\n\ta_{m1} & a_{m2} & a_{m3} & \\dots & a_{mn} & b_m \n\t\\end{array}\\right], \\]\n\tand it can be subjected to elementary row operations the same way as fully written-out systems of linear equations.\n\t\\item The first nonzero entry in a row of a matrix is called the \\emph{leading entry}. A matrix (augmented or not) of the form\n\t\\[ \\left[\\begin{array}{ccccccc}\n\t\\rowcolor{blue!50}\n\t(*) & \\phantom{(*)} & \\phantom{(*)} & \\phantom{(*)} & \\phantom{(*)} & \\phantom{(*)} & \\phantom{(*)} \\\\\n\t\\cellcolor{red!30} & \\cellcolor{red!30} & \\cellcolor{blue!50}(*) & \\cellcolor{blue!50} & \\cellcolor{blue!50} & \\cellcolor{blue!50} & \\cellcolor{blue!50} \\\\\n\t\\cellcolor{red!30} & \\cellcolor{red!30} & \\cellcolor{red!30} & \\cellcolor{blue!50}(*) & \\cellcolor{blue!50}& \\cellcolor{blue!50} & \\cellcolor{blue!50} \\\\ \n\t\\cellcolor{red!30} & \\cellcolor{red!30}0 & \\cellcolor{red!30} & \\cellcolor{red!30} & \\cellcolor{red!30} & \\cellcolor{red!30} & \\cellcolor{blue!50}(*) \\\\ \n\t\\rowcolor{red!30}\n\t& & & & & & \n\t\\end{array}\\right], \\]\n\twhere all entries in the red (light) part are zero and the $(*)$ stand for leading entries, is said to be in \\emph{row echelon form} (REF). That is, zero rows are at the bottom and for the remaining rows -- say there are $r$ of them -- we have\n\t\\[ j_1 < j_2 < j_3 < \\dots < j_r \\:, \\]\n\twhere $j_i$ is the column index of the leading entry in row $i$ (e.g., in the schematic example above, $j_1=1,j_2=3,j_3=4,j_4=7$).\n\t\\item A matrix in REF is further said to be in \\emph{reduced row echelon form} (RREF), if all leading entries are $1$ and if each leading entry is the only nonzero entry in its column.\n\t\\item The \\emph{rank} of a matrix is the number of nonzero rows in its REF.\n\\end{enumerate}\n\n\\begin{example}\n\\label{expl:augm_matrix}\n\\begin{enumerate}[(i)]\n\t\\item The matrices\n\t\\[ \\begin{bmatrix}\n\t-3 & 0 & 1 \\\\ 0 & 0 & 2 \\\\ 0 & 0 & 0\n\t\\end{bmatrix}, \\begin{bmatrix}\n\t0 & 1 & 1 & 0 \\\\ 0 & 0 & 2 & -3 \n\t\\end{bmatrix}, \\begin{bmatrix}\n\t1 & 2 & 3 \\\\ 0 & 4 & 5 \\\\ 0 & 0 & 6 \\\\ 0 & 0 & 0\n\t\\end{bmatrix} \\]\n\tall are in REF and have ranks 2, 2, and 3. If those matrices are the outcome of Gaussian elimination, then the original matrices have the same rank -- the rank does not change under elementary row operations, but it can be read off directly only from the REF. The matrices\n\t\\[ \\begin{bmatrix}\n\t-3 & 0 & 1 \\\\ 0 & 0 & 0 \\\\ 0 & 0 & 2\n\t\\end{bmatrix}, \\begin{bmatrix}\n\t1 & 2 & 3 \\\\ 0 & 4 & 5 \\\\ 0 & 6 & 7 \\\\ 0 & 0 & 8\n\t\\end{bmatrix} \\]\n\tare not in REF.\n\t\\item The matrices\n\t\\[ I, \\begin{bmatrix}\n\t1 & -2 & 0 \\\\ 0 & 0 & 1 \\\\ 0 & 0 & 0\n\t\\end{bmatrix}, \\begin{bmatrix}\n\t0 & 1 & 0 & 2 \\\\ 0 & 0 & 1 & -3 \n\t\\end{bmatrix} \\]\n\tall are in RREF, but the matrices in (i) are not.\n\t\\item In Example~\\ref{expl:lin_sys_equ}, we have transformed\n\t\\[ \\left[\\begin{array}{ccc|c}\n\t\t1 & -1 & 0 & 3 \\\\\n\t\t-3 & 4 & 1 & -1 \\\\\n\t\t2 & 0 & 7 & -3 \n\t\\end{array}\\right] \\qquad \\stackrel{\\eqref{eq:first_3x3_example}}{\\rightarrow} \\qquad \\left[\\begin{array}{ccc|c}\n\t1 & -1 & 0 & 3 \\\\\n\t0 & 1 & 1 & 8 \\\\\n\t0 & 0 & 5 & -25 \n\t\\end{array}\\right]. \\]\n\tThe transformed augmented matrix is in REF and has rank $3$. Therefore, the original augmented matrix has rank $3$ as well. Including the vector of variables that is dropped when writing systems as augmented matrices, the last line reads\n\t\\[ \\begin{bmatrix}\n\t0 & 0 & 5\n\t\\end{bmatrix} \\begin{bmatrix}\n\tx \\\\ y \\\\ z\n\t\\end{bmatrix} = -25 \\:, \\]\n\ti.e.,  $0 \\cdot x + 0 \\cdot y + 5 \\cdot z = 5z = -25$. With back-substitution, one can then find $x$ and $y$ as before. Another option is to bring the augmented matrix into reduced row echelon form:\n\t\\[ \n\t\\begin{array}{ccc}\n\t\\left[\\begin{array}{ccc|c}\n\t1 & -1 & 0 & 3 \\\\\n\t0 & 1 & 1 & 8 \\\\\n\t0 & 0 & 5 & -25 \n\t\\end{array}\\right] & \\stackrel{R3 \\rightarrow \\rfrac15 \\cdot R3}{\\rightarrow} \\qquad & \\left[\\begin{array}{ccc|c}\n\t1 & -1 & 0 & 3 \\\\\n\t0 & 1 & 1 & 8 \\\\\n\t0 & 0 & 1 & -5 \n\t\\end{array}\\right] \\\\ & & \\\\\n\t& \\stackrel{R2 \\rightarrow R2 - R3}{\\rightarrow} \\qquad & \\left[\\begin{array}{ccc|c}\n\t1 & -1 & 0 & 3 \\\\\n\t0 & 1 & 0 & 13 \\\\\n\t0 & 0 & 1 & -5 \n\t\\end{array}\\right] \\\\ & & \\\\\n\t& \\stackrel{R1 \\rightarrow R1 + R2}{\\rightarrow} \\qquad & \\left[\\begin{array}{ccc|c}\n\t1 & 0 & 0 & 16 \\\\\n\t0 & 1 & 0 & 13 \\\\\n\t0 & 0 & 1 & -5 \n\t\\end{array}\\right].\n\t\\end{array}\t\\]\n\tThe augmented matrix now corresponds to\n\t\\[ \\begin{bmatrix}\n\t16 \\\\ 13 \\\\ -5\n\t\\end{bmatrix} = \\begin{bmatrix}\n\t1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1 \n\t\\end{bmatrix} \\begin{bmatrix}\n\tx \\\\ y \\\\ z\n\t\\end{bmatrix} = \\begin{bmatrix}\n\tx \\\\ y \\\\ z\n\t\\end{bmatrix}, \\]\n\tfrom which -- for this example -- the solution can be read off directly.\n\t\\item To solve the system\n\t\\begin{equation*}\n\t\\begin{cases}\n\t\\begin{array}{rrrrrrr}\n\t-3x &   &    & + & 3z & = & 4 \\phantom{\\:,} \\\\\n\t 3x & + & 5y & + &  z & = & 0 \\phantom{\\:,} \\\\\n\t -x & + & 5y & + & 5z & = & 3 \\:,\n\t\\end{array} \\end{cases} \n\t\\end{equation*}\n\twe construct the augmented matrix and transform it with elementary row operations. It is preferable to have an entry $1$ in the upper left corner -- therefore, we start by swapping row 3 to the top and multiply it by $-1$~:\n\t\\[ \n\t\\begin{array}{ccc}\n\t\\left[\\begin{array}{ccc|c}\n\t-3 & 0 & 3 & 4 \\\\\n\t3  & 5 & 1 & 0 \\\\\n\t-1 & 5 & 5 & 3 \n\t\\end{array}\\right] & \\stackrel{R3 \\leftrightarrow R1}{\\rightarrow} \\qquad & \\left[\\begin{array}{ccc|c}\n\t-1 & 5 & 5 & 3 \\\\\n\t3 & 5 & 1 & 0 \\\\\n\t-3 & 0 & 3 & 4 \n\t\\end{array}\\right] \\\\ & & \\\\\n\t& \\stackrel{R1 \\rightarrow - R1}{\\rightarrow} \\qquad & \\left[\\begin{array}{ccc|c}\n\t1 & -5 & -5 & -3 \\\\\n\t3 & 5 & 1 & 0 \\\\\n\t-3 & 0 & 3 & 4 \n\t\\end{array}\\right] \\\\ & & \\\\\n\t& \\stackrel{R2 \\rightarrow R2 -3 R1}{\\rightarrow} \\qquad & \\left[\\begin{array}{ccc|c}\n\t1 & -5 & -5 & -3 \\\\\n\t0 & 20 & 16 & 9 \\\\\n\t-3 & 0 & 3 & 4 \n\t\\end{array}\\right] \\\\ & & \\\\\n\t& \\stackrel{R3 \\rightarrow R3 + 3 R1}{\\rightarrow} \\qquad & \\left[\\begin{array}{ccc|c}\n\t1 & -5 & -5 & -3 \\\\\n\t0 & 20 & 16 & 9 \\\\\n\t0 & -15 & -12 & -5 \n\t\\end{array}\\right] \\\\ & & \\\\\n\t& \\stackrel{R3 \\rightarrow R3 + \\rfrac{3}{4} R2}{\\rightarrow} \\qquad & \\left[\\begin{array}{ccc|c}\n\t1 & -5 & -5 & -3 \\\\\n\t0 & 20 & 16 & 9 \\\\\n\t0 & 0 & 0 & \\rfrac{7}{4} \n\t\\end{array}\\right].\n\t\\end{array}\t\\]\n\tThe last line reads\n\t\\[ \\rfrac74 = \\begin{bmatrix}\n\t0 & 0 & 0\n\t\\end{bmatrix} \\begin{bmatrix}\n\tx \\\\ y \\\\ z\n\t\\end{bmatrix} = 0 \\cdot x + 0 \\cdot y + 0 \\cdot z = 0 \\:, \\]\n\t which is never true -- for no combination $(x,y,z)$. Hence the system of linear equations does not have a solution.\n\\end{enumerate}\n\\end{example}\n\n\\begin{remark}\nAs the previous example has shown, if the REF of the augmented matrix has a row of zeros on the left-hand side, but the corresponding entry on the right is different from zero, then the system does not have a solution. A formal way of expressing this is\n\\[ \\rank A < \\rank[A\\:|\\:b] \\]\n-- the rank of the coefficient matrix alone is smaller than the rank of the augmented matrix.\n\\end{remark}\n\n\\begin{theorem}[Solutions of systems of linear equations]\n\\label{thm:rank_sols}\nSuppose a system of $m$ linear equations in $n$ variables is given. That is, the coefficient matrix $A$ of the system is of size $m \\times n$. Denote the right-hand side of the system by $b$. Then:\n\\begin{enumerate}[(i)]\n\\item If\t\n\\[ \\rank A < \\rank [A\\:|\\:b] \\:, \\]\t\nthen the system does not have a solution.\n\\item If\t\n\\[ \\rank A = \\rank [A\\:|\\:b]  = n \\:, \\]\t\nthen the system has a unique solution.\n\\item If\t\n\\[ \\rank A = \\rank [A\\:|\\:b] < n \\:, \\]\t\nthen the system has many solutions.\n\\item Those cases cover all possibilities, as $\\rank A$ can not be greater than $n$ or $\\rank [A\\:|\\:b]$.\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{example}\n\\label{expl:systems_of_eqns}\n\\begin{enumerate}[(i)]\n\t\\item Example (iii) of~\\ref{expl:augm_matrix} corresponds to the unique-solution case of Theorem~\\ref{thm:rank_sols}, and example (iv) to the no-solution case. The third case is demonstrated in the following examples.\n\t\\item Let us re-do Example~\\ref{expl:augm_matrix} (iv) with the right-hand side \n\t$b = \\begin{bmatrix} -9 & 8 & -4 \\end{bmatrix}^\\top.$\n\tThe same row operations as before lead to\n\\[\t\\left[\\begin{array}{ccc|c}\n\t\t\t-3 & 0 & 3 & -9 \\\\\n\t\t\t3  & 5 & 1 & 8 \\\\\n\t\t\t-1 & 5 & 5 & -4 \n\t\\end{array}\\right] \\quad \\stackrel{\\dots}{\\rightarrow} \\quad \\left[ \\begin{array}{ccc|c}\n\t\t\t1 & -5 & -5 & 4 \\\\\n\t\t\t0 & 20 & 16 &  -4 \\\\\n\t\t\t0 & -15 & -12 & 3 \n\t\t\\end{array}\\right]. \\]\n\tThe third row is a multiple of the second, and the next operation, $R3 \\rightarrow R3 + \\rfrac{3}{4} R2$, eliminates the third row altogether. We then continue to bring the system into RREF:\n\t\\[\\begin{array}{ccc}\n\t\t\\left[\\begin{array}{ccc|c}\n\t\t\t1 & -5 & -5 & 4 \\\\\n\t\t\t0  & 20 & 16 & -4 \\\\\n\t\t\t0 & 0 & 0 & 0 \n\t\t\\end{array}\\right] & \\stackrel{R2 \\rightarrow \\rfrac{1}{20}R2}{\\rightarrow} \\qquad & \\left[\\begin{array}{ccc|c}\n\t\t\t1 & -5 & -5 & 4 \\\\\n\t\t\t0 & 1 & \\rfrac45 & -\\rfrac15 \\\\\n\t\t\t0 & 0 & 0 & 0 \n\t\t\\end{array}\\right] \\\\ & & \\\\\n\t\t& \\stackrel{R1 \\rightarrow R1 + 5 R2}{\\rightarrow} \\qquad & \\left[\\begin{array}{ccc|c}\n\t\t\t1 & 0 & -1 & 3 \\\\\n\t\t\t0 & 1 & \\rfrac45 & -\\rfrac15 \\\\\n\t\t\t0 & 0 & 0 & 0 \n\t\t\\end{array}\\right]. \n\t\\end{array}\t\\]\n\tThe solution $\\begin{bmatrix} x & y & z \\end{bmatrix}^\\top$ is now obtained as follows. Variables corresponding to columns that do not have a leading entry can be chosen freely. This is expressed using a parameter,\n\t\\[ z = t \\qquad (t \\in \\mathbb{R}) \\:. \\]\n\tTo obtain an expression for $y$, we use the row whose leading entry is in the column corresponding to $y$:\n\t\\[ y + \\tfrac45 z = -\\tfrac15 \\quad \\rightarrow \\quad y = -\\tfrac15-\\tfrac45t \\:. \\]\n\tSimilarly for $x$:\n\t\\[ x - z = 3 \\quad \\rightarrow \\quad x = 3 + t \\:. \\]\n\tTherefore, the answer is\n\t\\[  \\left\\{ \\begin{array}{l}\n\tx = 3 + t \\\\\n\ty = -\\tfrac15 -\\tfrac45t \\\\\n\tz = t \\:,\n\t\\end{array} \\right. \\qquad (t\\in\\mathbb{R}), \\]\n\twhich can also be written as\n\t\\[ \\begin{bmatrix}\n\tx \\\\ y \\\\z\n\t\\end{bmatrix} = \\begin{bmatrix}\n\t3 \\\\ -\\rfrac15 \\\\ 0 \n\t\\end{bmatrix} + t \\cdot \\begin{bmatrix}\n\t1 \\\\ - \\rfrac45 \\\\ 1\n\t\\end{bmatrix}, \\qquad (t\\in\\mathbb{R}). \\]\n\tThe latter form is the equation of a line -- namely the line of common points of the three planes $-3x +3z=-9$, $3x+5y+z=8$, $-x+5y+5z=-4$.\n\t\\item For the system\n\t\\begin{equation*}\n\t\\begin{cases}\n\t\\begin{array}{rrrrrrr}\n\t-6x_1 & +6x_2 & +2x_3 & -2x_4 & = & 2 \\phantom{\\:,}\\\\\n\t-9x_1 & +8x_2 & +3x_3 & -2x_4 & = & 3 \\phantom{\\:,}\\\\\n\t-3x_1 & +2x_2 & +\\phantom{1}x_3 &  & = & 1 \\phantom{\\:,}\\\\\n\t-15x_1 & +14x_2 & +5x_3 & -4x_4 & = & 5 \\:,\n\t\\end{array} \\end{cases}\n\t\\end{equation*}\n\tGaussian elimination leads to the REF \n\t\\[ \\left[ \\begin{array}{cccc|c}\n\t\t-3 & 2 & 1 &  0 & 1 \\\\\n\t\t 0 & 2 & 0 & -2 & 0 \n\t\\end{array} \\right] \\]\n\t(dropping two rows of zeros) and to the RREF\n\t\\[ \\left[ \\begin{array}{cccc|c}\n\t\t1 & 0 & -\\rfrac13 & -\\rfrac23 & -\\rfrac13 \\\\\n\t\t0 & 1 & 0 & -1 & 0 \n\t\\end{array} \\right]. \\]\n\tThe solution is\n\t\\[ \\left\\{ \\begin{array}{l}\n\tx_1 = \\tfrac13 (t+2s-1) \\\\\n\tx_2 = s \\\\\n\tx_3 = t \\\\\n\tx_4 = s \\:,\n\t\\end{array} \\right. \\]\n\twhere $t,s\\in\\mathbb{R}.$\n\\end{enumerate}\n\\end{example}\n\n\\begin{exercise}\n\\begin{enumerate}[(i)]\n\t\\item Fill in the Gaussian elimination steps for Example~\\ref{expl:systems_of_eqns} (iii) (careful: the RREF of a matrix is unique, but the REF is not -- therefore, the REF you find may differ from the one given above).\n\t\\item Find $\\rank A$ and $\\rank [A\\:|\\:b]$ for the augmented matrices\n\t\\[ \\left[ \\begin{array}{cc|c}\n\t1 & 0 & \\rfrac13 \\\\\n\t1 & 1 & \\rfrac13 \n\t\\end{array} \\right], \\quad\n\t\\left[ \\begin{array}{ccc|c}\n\t1 & 2 & 3 & 4 \\\\\n\t0 & 5 & 6 & 7 \\\\\n\t0 & 0 & 8 & 9 \\\\\n\t2 & 5 & 7 & 3 \n\t\\end{array} \\right], \\quad\n\t\\left[ \\begin{array}{cccc|c}\n\t3 & 2 & 0 & 5 & 0 \\\\\n\t3 & -2 & 3 & 6 & -1 \\\\\n\t2 & 0 & 1 & 5 & -3 \\\\\n\t1 & 6 & -4 & -1 & 4 \n\t\\end{array} \\right], \\]\n\tand state for each case whether we have no solution, a unique solution, or infinitely many solutions\\footnote{\n\\begin{center}\n\t\\begin{tabular}{ l | c | c | c | c}\n\t\t & ~$n$~ & $\\rank A$ & $\\rank [A\\:|\\:b]$ &  \\# sol. \\\\ \\hline\n\t\t(i) & 2 & 2 & 2 & 1 \\\\ \\hline\n\t\t(ii) & 3 & 3 & 4 & 0 \\\\ \\hline\n\t\t(iii) & 4 & 3 & 3 & $\\infty$ \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{center}}.\n\t\\item Find all solutions of the homogeneous system\\footnote{Using the parameter $t\\in\\mathbb{R}$, we obtain $(x,y,z)=(-2t,-2t,t)$.}\n\t\\[ \\begin{cases}\t\n\t\t\\begin{array}{rrrrrrr}\n\t\t\t4x & -2y & +4z & = & 0 \\phantom{\\:.}\\\\\n\t\t\t   &  +y & +2z & = & 0 \\phantom{\\:.}\\\\\n\t\t\t3x &  -y & +4z & = & 0 \\:. \n\t\t\\end{array} \\end{cases} \\]\n\t\\item Convince yourself of the fact that homogeneous systems always have a solution, i.e. at least one solution\\footnote{The vector \n\t\\[ \\begin{bmatrix} x & y & z \\end{bmatrix}^\\top\n\t=  \\begin{bmatrix} 0 & 0 & 0 \\end{bmatrix}^\\top, \\]\n\tsatisfies all three equations. One can also argue more abstractly that the no-solution case in Theorem~\\ref{thm:rank_sols} never happens if $b=0$.}.\n\t\\item Find all solutions of the inhomogeneous system\n\t\\[ \\begin{cases}\t\n\t\\begin{array}{rrrrrrr}\n\t4x & -2y & +4z & = & -3 \\phantom{\\:.}\\\\\n\t-x &  +y & +2z & = & 1 \\phantom{\\:.}\\\\\n\t3x &  -y & +4z & = & 7 \\:.\n\t\\end{array} \\end{cases} \\]\n\t\\item An equation $a_1 x + a_2 y + a_3 z = b$ describes a plane in $\\mathbb{R}^3$ (just as $a_1x+a_2y=b$ describes a line in $\\mathbb{R}^2$; here, $b\\in\\mathbb{R}$). For example, $y = 0$ describes the $xz$-plane. Think about this interpretation for a moment and connect it to solving systems of equations, i.e., finding simultaneous solutions of several equations. For example, try to picture different arrangements of three planes such that they have no point in common, exactly one point in common, and infinitely many points in common.\n\t\\item Find $\\alpha$ such that\n\t\\[ \\begin{cases}\n\t\\begin{array}{rrrrrrr}\n\t5x & -3y & = & 2 \\\\\n\t-x & +2y & = & 1 \\\\\n\t-4x & +4y & = & \\alpha \n\t\\end{array} \\end{cases} \\]\n\thas a solution\\footnote{Bring the system in REF using Gaussian elimination as usual. Then choose $\\alpha$ such that we are not in the no-solution case of Theorem~\\ref{thm:rank_sols}.}.\n\t\\item Find $\\alpha, \\beta$ such that\n\t\\[ \\begin{bmatrix}\n\t\\alpha & 1 & 1 \\\\ 1 & \\beta & 1 \\\\ 1 & 3\\beta & 1\n\t\\end{bmatrix} \\begin{bmatrix} x_1 \\\\ x_2 \\\\ x_3\n\t\\end{bmatrix} = \\begin{bmatrix} 4 \\\\ 3 \\\\ 4\t\\end{bmatrix} \\]\n\thas no solution, a unique solution, infinitely many solutions\\footnote{Unique solution if $\\alpha\\not=1$ and $\\beta\\not=0$. Infinitely many solutions if $\\alpha=1$ and $\\beta=\\rfrac13$. Otherwise, no solutions.}.\n\t\\item In the last exercise of the previous section, you were asked to orthogonally project the point $p=(\\rfrac12,10)$ onto the line $L \\: : \\: y=5x$. Now consider the following two different types of projections.\n\t\\begin{enumerate}[(a)]\n\t\t\\item $P_{L,x} \\: : \\: p=(\\rfrac12,10) \\mapsto \\wtd{p}=(2,10)$ \n\t\t\t\t\\hfill \\text(projection in the $x$ direction)\n\t\t\\item $P_{L,y} \\: : \\: p=(\\rfrac12,10) \\mapsto \\wtd{p}=(\\rfrac12,\\rfrac52)$\n\t\t\t\t\\hfill \\text(projection in the $y$ direction)\n\\end{enumerate}\n\tSketch the action of the three different types of projections and find the matrices $P_{L,x},P_{L,y}$. What is the advantage of orthogonal projection over projection along the coordinate axes\\footnote{\\[\n\t\t\\begin{bmatrix} a & b \\\\ c & d \\end{bmatrix} \\begin{bmatrix} x \\\\ y \\end{bmatrix} \n\t\t= \\begin{bmatrix} ax+by \\\\ cx+dy \\end{bmatrix} \\stackrel{\\text{!}}{=}\n\t\tP_{L,x} \\begin{bmatrix} x \\\\ y \\end{bmatrix}\n\t\t= \\begin{bmatrix} \\frac15y \\\\ y \\end{bmatrix} \n\t\t\\quad \\Rightarrow \\quad \n\t\tP_{L,x} = \\begin{bmatrix} 0 & \\rfrac15 \\\\ 0 & 1 \\end{bmatrix} \\]\n\tAlternatively, one can think about where the standard vectors \n\t$\\begin{bmatrix} 1 & 0 \\end{bmatrix}^\\top$ and\n\t$\\begin{bmatrix} 0 & 1 \\end{bmatrix}^\\top$ get mapped to: \n\t\\[ P_{L,y} \\: : \\: \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}\n\t\\mapsto \\begin{bmatrix} 1 \\\\ 5 \\end{bmatrix}, \\quad \n\t\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}\n\t\\mapsto \\begin{bmatrix} 0 \\\\ 0 \\end{bmatrix} \n\t\\quad \\Rightarrow \\quad \n\tP_{L,y} = \\begin{bmatrix} 1 & 0 \\\\ 5 & 0 \\end{bmatrix}. \\]}?\n\\end{enumerate}\n\\end{exercise}\n\n\n\\section{Eigenvalues and Eigenvectors}\n\n\\begin{definition}[Eigenvalues and eigenvectors]\n\tLet $A$ be a $n \\times n$ square matrix. A scalar $\\lambda \\in \\mathbb{R}$ is called an \\emph{eigenvalue} of $A$, if there exists a $n$-vector $v\\not=0$ with \n\t\\[ Av = \\lambda v \\:. \\]\n\tSuch a vector $v$ is called an \\emph{eigenvector} of $A$.\n\\end{definition}\n\n\\begin{remark}\n\\label{rem:ev}\n\\begin{enumerate}[(i)]\n\t\\item In this section, all matrices are square, of size $n \\times n$, and vectors are of the corresponding size $n$. \n\t\\item The vector on the left-hand side of the eigenvalue equation above is obtained via matrix multiplication. The vector on the right is found by scalar multiplication, which is much easier to compute. This observation already suggests that eigenvalues and eigenvectors are useful for simplifying matrix computations.\n\t\\item The condition $v\\not=0$ for eigenvectors is crucial. Indeed, for the zero vector, we have\n\t\\[ A0 = 0 =\\lambda 0 \\]\n\tfor any square matrix $A$ and for any scalar $\\lambda$. Therefore, eigenvectors are nonzero by definition (otherwise, any $\\lambda\\in\\mathbb{R}$ would be an eigenvalue). However, eigen\\emph{values} can be zero: If there exists $v\\not=0$ such that\n\t\\[ Av= 0 = 0 \\cdot v \\:, \\]\n\tthen $v$ is an eigenvector of $A$ with eigenvalue $\\lambda=0$ (where the first $0$ in the equation stands for zero vector and the second $0$ for the number zero).\n\t\\item If $v$ is an eigenvector of $A$, then any nonzero multiple of $v$ is an eigenvector with the same eigenvalue: If we scalar-multiply $v$ by $\\mu\\not=0$, then\n\t\\[ A(\\mu v) = \\mu (Av) = \\mu (\\lambda v) = \\lambda (\\mu v) \\:. \\]\n\t\\item An approach to computing eigenvalues will be given by Theorem~\\ref{thm:eigenvalues} below. That theorem and the results in the preceding lemma provide good opportunities to present a few proofs.\n\\end{enumerate}\n\\end{remark}\n\n\\begin{lemma}\n\\label{lem:rank_det}\nFor a $n \\times n$ matrix $M$, we have:\n\\begin{enumerate}[(i)]\n\t\\item There exists $v\\not=0$ with $Mv=0 \\quad \\Longleftrightarrow \\quad \\rank M<n$~.\n\t\\item The determinant of $M$ does not change when $M$ is subjected to elementary row operation (iii) in Definition~\\ref{def:ero} -- adding the multiple of a row to another row.\n\t\\item Each time two rows are swapped, the determinant changes by a factor of $-1$.\n\t\\item $\\quad \\rank M <n \\quad \\Longleftrightarrow \\quad \\det M =0$~.\n\\end{enumerate}\n\\end{lemma}\n\\begin{proof}\n\\begin{enumerate}[(i)]\n\t\\item Note that $\\rank M = \\rank [M\\:|\\:0]$, and we are therefore either in case (ii) or in case (iii) of Theorem~\\ref{thm:rank_sols}. Note further that the zero vector $w=0$ solves $Mw=0$. If $\\rank M = n$, this solution is unique by~\\ref{thm:rank_sols} -- that is, there are no other solutions and hence no nonzero solutions. If $\\rank M < n$, there are other solutions -- that is, nonzero solutions do exist in that case.\n\t\\item Denote the rows of $M$ by $r^{(1)},r^{(2)},\\dots,r^{(n)}$, and let $B$ be the matrix obtained by adding $\\mu$ times the $q$-th row to the $p$-th row, where $p \\not= q$:\n\t\\[ M = \\begin{bmatrix}\n\t--r^{(1)}-- \\\\\n\t--r^{(2)}-- \\\\\n\t\\vdots \\\\\n\t--r^{(n)}--\n\t\\end{bmatrix}, \\qquad B = \\begin{bmatrix}\n\t--r^{(1)}-- \\\\\n\t\\vdots \\\\\n\t--r^{(p-1)}-- \\\\\n\t-\\,r^{(p)} + \\mu r^{(q)}\\,- \\\\\n\t--r^{(p+1)}-- \\\\\n\t\\vdots \\\\\n\t--r^{(n)}--\n\t\\end{bmatrix}. \\]\n\tTo show that $\\det B = \\det M$, we apply Laplace's formula developing along the $p$-th row of $B$. As in the previous section, the matrix $\\wtd{A}_{ij}$ is the $(n-1) \\times (n-1)$ matrix obtained by deleting the $i$-th row and the $j$-th column from $A$:\n\t\\begin{equation*}\n\t\\begin{split}\n\t\\det B & = \\sum_{j=1}^n (-1)^{p+j} \\left( r_j^{(p)} + \\mu r_j^{(q)} \\right) \\det \\wtd{B}_{pj} \\\\\n\t& = \\sum_{j=1}^n (-1)^{p+j} \\left( r_j^{(p)} + \\mu r_j^{(q)} \\right) \\det \\wtd{M}_{pj} \\\\\n\t& = \\sum_{j=1}^n (-1)^{p+j} r_j^{(p)} \\det \\wtd{M}_{pj} + \\sum_{j=1}^n (-1)^{p+j} \\mu r_j^{(q)} \\det \\wtd{M}_{pj} \\\\\n\t& = \\det M + \\det \\left( \\begin{bmatrix}\n\tr^{(1)} \\\\ \\vdots \\\\ r^{(q)} \\\\ \\vdots \\\\ \\mu r^{(q)} \\\\ \\vdots \\\\ r^{(n)}\n\t\\end{bmatrix}\\right) = \\det M + 0 = \\det M \\:,\n\t\\end{split}\n\t\\end{equation*}\n\twhere the simplification in the last line is due to property (ii) of~\\ref{prop:det}. We have shown that the determinant does not change when a multiple of a row is added to another row.\n\t\\item By induction over $n$~:\n\t\\begin{itemize}\n\t\t\\item[$\\mathbf{n=2}$~:]\n\t\t\\[ \\begin{vmatrix}\n\t\tc & d \\\\ a & b\n\t\t\\end{vmatrix} = bc-ad = - \\begin{vmatrix}\n\t\ta & b \\\\ c & d\n\t\t\\end{vmatrix} \\qquad \\text{\\checkmark} \\]\n\t\t\\item[$\\mathbf{n=3}$~:] Suppose two rows of a $3 \\times 3$ matrix have been swapped. Apply Laplace's formula in the row that has not changed. In each of the three $2 \\times 2$ matrices, the rows have been swapped, and we therefore -- cf. the $n=2$ case above -- obtain an overall factor of $-1$.\n\t\t\\item[$\\mathbf{n=4}$~:] Suppose two rows of a $4 \\times 4$ matrix have been swapped. Apply Laplace's formula in one of the rows that has not changed. In each of the four $3 \\times 3$ matrices, two rows have been swapped, and we therefore -- cf. the $n=3$ case above -- obtain an overall factor of $-1$.\n  \t\t\\item[$\\mathbf{n>4}$~:] Via repetition of the step $n \\rightsquigarrow n + 1$, the statement follows for all $n\\geq2$.\n\t\\end{itemize}\n\t\\item First suppose that $M$ is in REF. Square matrices in REF have only zero entries below the diagonal. Therefore, $M$ is a upper diagonal matrix and its determinant is the product of its diagonal entries. If $\\rank M < n$, then at least one diagonal entry is equal to zero, and thus $\\det M = 0$. If $\\rank M = n$, then none of the diagonal entries is zero, and therefore $\\det M \\not= 0$. Hence statement (iv) is true for REF matrices. Since all matrices can be brought into REF by swapping rows and adding multiples of rows to other rows, the general case follows from (ii) and (iii).\n\\end{enumerate}\n\\end{proof}\n\n\\begin{theorem}[Eigenvalue equation]\n\\label{thm:eigenvalues}\t\n\tIf $\\lambda$ is an eigenvalue of $A$, then\n\t\\[ \\det(A - \\lambda I) = 0 \\:. \\]\n\tThe converse is also true: If $\\det(A - \\lambda I) = 0$, then $\\lambda$ is an eigenvalue of $A$. The above equation -- a condition on the parameter $\\lambda$ -- is called the \\emph{eigenvalue equation} of $A$.\n\\end{theorem}\n\\begin{proof}\n\t\\[ \\begin{array}{cccrlcc}\n\t\\lambda \\text{~eigenvalue of~}A &\\stackrel{\\text{def.}}{\\Longleftrightarrow} & & Av & = \\lambda v & & (\\text{for some~}v\\not=0) \\\\\t\n\t&\\Longleftrightarrow & & Av - \\lambda v & = 0 & & (\\text{for some~}v\\not=0) \\\\\t\n\t&\\Longleftrightarrow & & (A - \\lambda I)v & = 0 & & (\\text{for some~}v\\not=0) \\\\\n\t&\\stackrel{\\text{Lemma~\\ref{lem:rank_det} (i)}}{\\Longleftrightarrow} & & \\rank (A - \\lambda I) & < n & & \\\\\t\n\t&\\stackrel{\\text{\\ref{lem:rank_det} (iv)}}{\\Longleftrightarrow} & & \\det(A - \\lambda I) & = 0 & & \n\t\\end{array} \\]\n\\end{proof}\n\n\\begin{example}\n\\label{expl:evs}\n\t\\begin{enumerate}[(i)]\n\t\\item Find the eigenvalues and eigenvectors of\n\t\t\\[ A = \\begin{bmatrix}\n\t\t1 & 5 \\\\ 10 & -4 \n\t\t\\end{bmatrix}. \\]\n\t\t{\\it Sol.:}\n\t\tThe eigenvalue equation is \n\t\t\\begin{equation*}\n\t\t\\begin{split}\n\t\t0 & = \\det (A-\\lambda I) =\\det \\left( \n\t\t\\begin{bmatrix}\n\t\t1 & 5 \\\\ 10 & -4\n\t\t\\end{bmatrix} - \\lambda \\begin{bmatrix}\n\t\t1 & 0 \\\\ 0 & 1\n\t\t\\end{bmatrix}\n\t\t\\right) \\\\ \n\t\t& = \\begin{vmatrix}  \n\t\t1 - \\lambda & 5 \\\\ 10 & -4 - \\lambda\n\t\t\\end{vmatrix} = (1-\\lambda)(-4-\\lambda)-10 \\cdot 5\\\\ \n\t\t& = \\lambda^2 +3\\lambda -54 = (\\lambda+9)(\\lambda-6) \\:,\n\t\t\\end{split}\n\t\t\\end{equation*}\n\t\tand its roots \n\t\t\\[ \\begin{cases} \\lambda_1 = -9 \\\\ \\lambda_2 = 6 \\:. \\end{cases}  \\]\n\t\tare the eigenvalues of $A$.\n\t\t\n\t\tThe eigenvector $v_1$ is found  by solving $Av_1=\\lambda_1v_1 \\leftrightarrow (A-\\lambda_1 I)v_1=0$~:\n\t\t\\[\\begin{array}{ccc}\n\t\t\\left[\\begin{array}{cc|c}\n\t\t1-\\lambda_1 & 5 & 0 \\\\\n\t\t10 & -4-\\lambda_1& 0 \\\\\n\t\t\\end{array}\\right] & = \\qquad & \\left[\\begin{array}{cc|c}\n\t\t10 & 5 & 0 \\\\\n\t\t10 & 5 & 0 \n\t\t\\end{array}\\right] \\\\ & & \\\\\n\t\t& \\stackrel{R2 \\rightarrow R2 - R1}{\\rightarrow} \\qquad & \n\t\t\\left[\\begin{array}{cc|c}\n\t\t10 & 5 & 0 \\\\\n\t\t0 &  0 & 0 \n\t\t\\end{array}\\right]\n\t\t.\\end{array} \\]\n\t\tThe first row of that system corresponds to \n\t\t\\[ 10 x + 5 y = 0 \\:, \\]\n\t\twhich gives $y = - 2 x$. As was pointed out in Remark~\\ref{rem:ev}, multiples of eigenvectors are eigenvectors as well -- this explains why the above system does not determine $x$ and $y$ uniquely; for any solution $(x,y)$ and any constant factor $c\\not=0$, the scalar multiple $(cx,cy)$ is a solution as well. Choosing $x=1$, we obtain\n\t\t\\[v_1 = \\begin{bmatrix}\n\t\t1 \\\\ -2\n\t\t\\end{bmatrix} \\qquad (\\lambda_1 = -9) \\:. \\]\n\t\t\t\t\n\t\tFor the second eigenvector, we solve $(A-\\lambda_2 I)v_2=0$~:\n\t\t\\[\\begin{array}{ccc}\n\t\t\\left[\\begin{array}{cc|c}\n\t\t1-\\lambda_2 & 5 & 0 \\\\\n\t\t10 & -4-\\lambda_2& 0 \\\\\n\t\t\\end{array}\\right] & = \\qquad & \\left[\\begin{array}{cc|c}\n\t\t-5 & 5 & 0 \\\\\n\t\t10 & -10 & 0 \n\t\t\\end{array}\\right] \\\\ & & \\\\\n\t\t& \\stackrel{R2 \\rightarrow R2 + 2 R1}{\\rightarrow} \\qquad & \n\t\t\\left[\\begin{array}{cc|c}\n\t\t-5 & 5 & 0 \\\\\n\t\t0 &  0 & 0 \n\t\t\\end{array}\\right].\n\t\t\\end{array}\t\\]\n\t\tHere, the first row reads\n\t\t\\[ -5 x + 5 y = 0 \\]\n\t\tand leads to\n\t\t\\[v_2 = \\begin{bmatrix}\n\t\t1 \\\\ 1\n\t\t\\end{bmatrix} \\qquad (\\lambda_2 = 6) \\:. \\]\n\t\\item Verify the results from the previous example.\\\\\n\t\t{\\it Sol.:}\n\t\t\\[ Av_1 = \\begin{bmatrix}\n\t\t1 & 5 \\\\ 10 & -4 \n\t\t\\end{bmatrix} \\begin{bmatrix}\n\t\t1 \\\\ -2\n\t\t\\end{bmatrix} = \\begin{bmatrix}\n\t\t1-10 \\\\ 10 + 8\n\t\t\\end{bmatrix} = \\begin{bmatrix}\n\t\t-9 \\\\ 18\n\t\t\\end{bmatrix} = -9 \\begin{bmatrix}\n\t\t1 \\\\ -2\n\t\t\\end{bmatrix} = \\lambda_1 v_1\n\t\t\\qquad \\text{\\checkmark} \\]\n\t\t\\[ Av_2 = \\begin{bmatrix}\n\t\t1 & 5 \\\\ 10 & -4 \n\t\t\\end{bmatrix} \\begin{bmatrix}\n\t\t1 \\\\ 1\n\t\t\\end{bmatrix} = \\begin{bmatrix}\n\t\t1+5 \\\\ 10 - 4\n\t\t\\end{bmatrix} = \\begin{bmatrix}\n\t\t6 \\\\ 6\n\t\t\\end{bmatrix} = 6 \\begin{bmatrix}\n\t\t1 \\\\ 1\n\t\t\\end{bmatrix} = \\lambda_2 v_2\n\t\t\\qquad \\text{\\checkmark} \\]\n\t\\item Find the eigenvalues and eigenvectors of\n\t\t\\[ M = \\begin{bmatrix}\n\t\t-5 & 0 & 7 \\\\ 6 & 2 & -6 \\\\ -4 & 0 & 6 \n\t\t\\end{bmatrix}. \\]\n\t\t{\\it Sol.:}\n\t\t\\begin{equation*}\n\t\t\\begin{split}\n\t\t0 & = \\det (M-\\lambda I) = \\begin{vmatrix}  \n\t\t\t-5-\\lambda & 0 & 7 \\\\ \n\t\t\t6 & 2-\\lambda & -6 \\\\ \n\t\t\t-4 & 0 & 6-\\lambda \n\t\t\\end{vmatrix} \\\\\n\t\t& = (-5-\\lambda)(2-\\lambda)(6-\\lambda) + 0 + 0 - (-4)(2-\\lambda)(7)- 0 - 0 \\\\\n\t\t& = (2-\\lambda) \\left[ (-5-\\lambda)(6-\\lambda)+28 \\right]\n\t\t= (2-\\lambda) \\left[ (\\lambda+5)(\\lambda-6)+28 \\right] \\\\\n\t\t& = (2-\\lambda) \\left[ \\lambda^2-\\lambda-2 \\right]\n\t\t= - (\\lambda+1) (\\lambda-2) (\\lambda-2) \\:,\n\t\t\\end{split}\n\t\t\\end{equation*}\n\t\twhich gives eigenvalues\n\t\t\\[ \\begin{cases} \\lambda_1 = -1 \\\\ \\lambda_2 = 2 \\\\ \\lambda_3 = 2 \\:. \\end{cases} \\]\n\t\t\n\t\tFor $v_1$~:\n\t\t\\[\\begin{array}{ccc}\n\t\t\\left[\\begin{array}{ccc|c}\n\t\t-5-\\lambda_1 & 0 & 7 & 0 \\\\\n\t\t 6 & 2-\\lambda_1 & -6 & 0\\\\ \n\t\t -4 & 0 & 6-\\lambda_1 & 0\n\t\t\\end{array}\\right] & = \\qquad & \\left[\\begin{array}{ccc|c}\n\t\t-4 & 0 & 7 & 0 \\\\\n\t\t6 & 3 & -6 & 0\\\\ \n\t\t-4 & 0 & 7 & 0\n\t\t\\end{array}\\right] \\\\ & & \\\\\n\t\t& \\stackrel{R3 \\rightarrow R3 - R1}{\\rightarrow} \\qquad & \n\t\t\\left[\\begin{array}{ccc|c}\n\t\t-4 & 0 & 7 & 0 \\\\\n\t\t6 & 3 & -6 & 0\\\\ \n\t\t0 & 0 & 0 & 0\n\t\t\\end{array}\\right] \\\\ & & \\\\\n\t\t& \\stackrel{R2 \\rightarrow R2 + \\rfrac32 R1}{\\rightarrow} \\qquad & \n\t\t\\left[\\begin{array}{ccc|c}\n\t\t-4 & 0 & 7 & 0 \\\\\n\t\t0 & 3 & \\rfrac92 & 0\\\\ \n\t\t0 & 0 & 0 & 0\n\t\t\\end{array}\\right]\n\t\t\\\\ & & \\\\\n\t\t& \\stackrel{R2 \\rightarrow \\rfrac13 R2, \\, R1 \\rightarrow -\\rfrac14 R1}{\\rightarrow} \\qquad & \n\t\t\\left[\\begin{array}{ccc|c}\n\t\t1 & 0 & -\\rfrac74 & 0 \\\\\n\t\t0 & 1 & \\rfrac32 & 0\\\\ \n\t\t0 & 0 & 0 & 0\n\t\t\\end{array}\\right].\n\t\t\\end{array}\t\\]\n\t\tWe now need to find the components $x$, $y$, $z$ of $v_1$. One of them can be chosen freely, say $z=4$. Then the first equation reads $x-\\tfrac744 = 0$, yielding $x=7$. The second equation reads $y+\\tfrac324 = 0$ and we obtain $y=-6$ and\n\t\t\\[v_1 = \\begin{bmatrix}\n\t\t7 \\\\ -6 \\\\ 4\n\t\t\\end{bmatrix} \\qquad (\\lambda_1 = -1) \\:. \\]\n\n\t\tFor a matrix with three distinct eigenvalues, the computations of $v_2$ and $v_3$ would be analogous to the computation of $v_1$. The matrix in this example has a double eigenvalue though, $\\lambda_2=\\lambda_3=2$. In this case, one has to solve only one system, $(A-2 I)v=0$. Due to $\\lambda =2$ being a double eigenvalue, it has a larger set of solutions from which one then has to choose two \\emph{different} solutions $v_2$ and $v_3$. Here, ``different'' means that $v_3$ is not simply a scalar multiple of $v_2$.\n\t\t\n\t\tFor $v_{2/3}$~:\n\t\t\\[\\begin{array}{ccc}\n\t\t\\left[\\begin{array}{ccc|c}\n\t\t-5-\\lambda_{2/3} & 0 & 7 & 0 \\\\\n\t\t6 & 2-\\lambda_{2/3} & -6 & 0\\\\ \n\t\t-4 & 0 & 6-\\lambda_{2/3} & 0\n\t\t\\end{array}\\right] & = \\qquad & \\left[\\begin{array}{ccc|c}\n\t\t-7 & 0 & 7 & 0 \\\\\n\t\t6 & 0 & -6 & 0\\\\ \n\t\t-4 & 0 & 4 & 0\n\t\t\\end{array}\\right] \\\\ & & \\\\\n\t\t& \\stackrel{\\dots}{\\rightarrow} \\qquad & \n\t\t\\left[\\begin{array}{ccc|c}\n\t\t1 & 0 & -1 & 0 \\\\\n\t\t0 & 0 & 0 & 0\\\\ \n\t\t0 & 0 & 0 & 0\n\t\t\\end{array}\\right].\n\t\t\\end{array}\t\\]\n\t\tWe are left with one equation that imposes a condition on three variables. A simple choice to represent the solution is\n\t\t\\[v_2 = \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\end{bmatrix},\n\t\t  \\quad v_3 = \\begin{bmatrix} 1 \\\\ 0 \\\\ 1 \\end{bmatrix}\n\t\t \\qquad (\\lambda_2 = \\lambda_3 = 2) \\:. \\]\n\t\t (Check that these two vectors solve the system of equations represented by the augmented matrix above.)\n\t\\item Find the eigenvalues and eigenvectors of\n\t\t\\[ L = \\begin{bmatrix}\n\t\t0 & 0.75 \\\\ 0.75 & 0.4375 \n\t\t\\end{bmatrix}. \\]\n\t\t{\\it Sol.:}\n\t\tThe eigenvalue equation is \n\t\t\\[ 0 = \\det (L-\\lambda I) = \\begin{vmatrix}  \n\t\t0 - \\lambda & 0.75 \\\\ 0.75 & 0.4375 - \\lambda\n\t\t\\end{vmatrix} = \\lambda^2 - 0.4375\\lambda - 0.5625 \\:, \\]\n\t\twhich gives eigenvalues (none of the decimals appearing here is rounded)\n\t\t\\[ \\begin{cases} \\lambda_1 = -0.5625 \\\\ \\lambda_2 = 1 \\:. \\end{cases} \\]\n\t\t\n\t\tWe find $v_1$ by solving $(L-\\lambda_1 I)v_1=0$~:\n\t\t\\[\\begin{array}{ccc}\n\t\t\\left[\\begin{array}{cc|c}\n\t\t0-\\lambda_1 & 0.75 & 0 \\\\\n\t\t0.75  & 0.4375 - \\lambda_1& 0 \\\\\n\t\t\\end{array}\\right] & = \\qquad & \\left[\\begin{array}{cc|c}\n\t\t0.5625 & 0.75 & 0 \\\\\n\t\t0.75  & 1 & 0 \n\t\t\\end{array}\\right] \\\\ & & \\\\\n\t\t& \\stackrel{R2 \\rightarrow R2 - \\frac{0.75}{0.5625} R1}{\\rightarrow} \\qquad & \n\t\t\\left[\\begin{array}{cc|c}\n\t\t0.5625 & 0.75 & 0 \\\\\n\t\t0 &  0 & 0 \n\t\t\\end{array}\\right].\n\t\t\\end{array}\t\\]\n\t\tLetting $x$ and $y$ stand for the components of $v_1$, the first equation reads\n\t\t\\[ \\left(\\frac34\\right)^2 x + \\frac34 \\, y = 0 \\:, \\]\n\t\twhich gives $x = - \\tfrac43 y$. As in the previous examples, $y$ can be chosen freely  and then $x$ is determined accordingly. We choose\n\t\t\\[v_1 = \\begin{bmatrix}\n\t\t0.8 \\\\ -0.6\n\t\t\\end{bmatrix} \\qquad \\text{(for $\\lambda_1 = -0.5625$)} \\:, \\]\n\t\tand obtain the second eigenvector similarly:\n\t\t\\[v_2 = \\begin{bmatrix}\n\t\t0.6 \\\\ 0.8\n\t\t\\end{bmatrix} \\qquad \\text{(for $\\lambda_2 = 1$)} \\:. \\]\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{definition}[Linear independence]\n\\label{def:li}\nConsider a set \n\\[ S = \\{ v^{(1)},v^{(2)},v^{(3)}, \\dots v^{(m)}\\} \\: \\subseteq\\mathbb{R}^n \\]\nof $m$ vectors of size $n$.\n\\begin{enumerate}[(i)]\n\\item A vector $w \\in \\mathbb{R}^n$ is said to be a \\emph{linear combination} of the vectors in $S$ if it can be written in the form\n\\[ w = c_1v^{(1)}+c_2v^{(2)}+c_3v^{(3)} + \\dots + c_mv^{(m)} \\]\nfor some coefficients $c_1,c_2,c_3,\\dots,c_m$.\n\\item The vectors in $S$ are said to be \\emph{linearly independent} if \n\\[ c_1v^{(1)}+c_2v^{(2)}+c_3v^{(3)} + \\dots + c_mv^{(m)} = 0 \\]\nimplies\n\\[ c_1=0,\\:c_2=0,\\:c_3=0,\\:\\dots,\\:c_m=0 \\:. \\]\nThat is, the vectors of $S$ are called linearly independent if the zero vector can only be written as the trivial linear combination of vectors in $S$ (the linear combination where all coefficients are zero). Otherwise, the vectors are called \\emph{linearly dependent}.\n\\end{enumerate}\n\\end{definition}\n\n\\begin{remark}\n\\label{rmk:lin_indep}\t\n\\begin{enumerate}[(i)]\n\t\\item Suppose we have a linearly dependent set of vectors,\n\t\\[ c_1v^{(1)}+c_2v^{(2)}+c_3v^{(3)} + \\dots + c_mv^{(m)} = 0 \\:. \\]\n\tNot all of the coefficients are equal to zero; say $c_m\\not=0$. Then\n\t\\[v^{(m)} = -\\frac{c_1}{c_m}v^{(1)}-\\frac{c_2}{c_m}v^{(2)}-\\frac{c_3}{c_m}v^{(3)} - \\dots - \\frac{c_{m-1}}{c_m}v^{(m-1)} \\:, \\]\n\twhich shows that in a set of linearly dependent vectors, at least one of the vectors is a linear combination of the others.\n\t\\item For $3 \\times 3$ matrices, the eigenvalue equation is a third-order equation, which can not be solved as readily as a second-order equation. One therefore should be careful not to give away any information when computing the determinant: In Example~\\ref{expl:evs} (iii), a factor of $(2-\\lambda)$ was kept rather than multiplied out -- multiplying it out would have given an expression of the form\n\t\\[ -\\lambda^3 + a \\lambda^2 + b \\lambda + c \\:, \\]\n\tof which one then would have to guess a root before being able to continue with polynomial division and the quadratic formula.\n\\end{enumerate}\n\\end{remark}\n\n\\begin{example}\n\\label{expl:lin_indep}\n\\begin{enumerate}[(i)]\n\t\\item Show that $v^{(1)} = \\begin{bmatrix}\n\t1 & 0\n\t\\end{bmatrix}^\\top, \\: v^{(2)} = \\begin{bmatrix}\n\t0 & 1\n\t\\end{bmatrix}^\\top$ are linearly independent. \\\\\n\t{\\it Sol.:}\n\tSuppose we have coefficients $c_1$ and $c_2$ such that the corresponding linear combination of the two vectors gives the zero vector. That is,\n\t\\[ \\begin{bmatrix}\n\t0 \\\\ 0\n\t\\end{bmatrix} = c_1 v^{(1)} + c_2 v^{(2)} = \\begin{bmatrix}\n\tv^{(1)}_1 & v^{(2)}_1 \\\\ v^{(1)}_2 & v^{(2)}_2\n\t\\end{bmatrix} \\begin{bmatrix} c_1 \\\\ c_2\\end{bmatrix}\n\t= \\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix} \\begin{bmatrix} c_1 \\\\ c_2\\end{bmatrix}\n\t= \\begin{bmatrix}\tc_1 \\\\ c_2 \t\\end{bmatrix}, \\]\n\twhich reads $c_1=0$ and $c_2=0$. Therefore, the vectors $v^{(1)},v^{(2)}$ are linearly independent. This computation was simplified by the fact that the matrix obtained from the vectors is the identity matrix. In less straight-forward cases and also for larger $n$, one checks whether the system\n\t\\begin{equation}\n\t\\label{eq:lin_dep_equ}\n\t \\begin{bmatrix}\n\tv^{(1)}_1 & v^{(2)}_1 & \\cdots & v^{(m)}_1 \\\\\n\tv^{(1)}_2 & v^{(2)}_2 & \\cdots & v^{(m)}_2 \\\\\t \n\t\\vdots\t& \\vdots & \\ddots & \\vdots \\\\\t\t\t\t\n\tv^{(1)}_n & v^{(2)}_n & \\cdots & v^{(m)}_n \\\\\t \n\t\\end{bmatrix} \\begin{bmatrix} c_1 \\\\ c_2 \\\\ \\vdots \\\\ c_m\n\t\\end{bmatrix} = \\begin{bmatrix}\n\t0 \\\\ 0 \\\\ \\vdots \\\\ 0\n\t\\end{bmatrix}\n\t\\end{equation}\n\thas solutions other than $c_1=c_2=\\ldots=c_m=0$.\n\t\\item Show that $v^{(1)} = \\begin{bmatrix}\n\t1 & 0 & 0\n\t\\end{bmatrix}^\\top, \\: v^{(2)} = \\begin{bmatrix}\n\t0 & 0 & 1\n\t\\end{bmatrix}^\\top, \\: v^{(3)} = \\begin{bmatrix}\n\t-2 & 0 & 7\n\t\\end{bmatrix}^\\top$ are linearly dependent. \\\\\n\t{\\it Sol.:}\n\tSolving the system~\\eqref{eq:lin_dep_equ} is an approach that always works, but here, noticing that $v^{(3)}$ is a linear combination of the other two,\n\t\\[v^{(3)} = -2v^{(1)}+7v^{(2)} \\:, \\]\n\tleads more quickly to the conclusion that the set of vectors is linearly dependent.\n\\end{enumerate}\n\\end{example}\n\n\\begin{application}[Leslie matrices]\nWe now apply matrices to the study of population dynamics. In addition to providing an application in the natural sciences, it will also demonstrate the usefulness of eigenvectors.\n\nA biologist has been monitoring a certain population of birds over a number of years. Each bird is either a hatchling or an adult, and vectors are used to describe the state of the population. For example, a population of 25 hatchlings and 89 adults is denoted $p = \\begin{bmatrix} 25 & 89 \\end{bmatrix}^\\top$. The biologist has found that\n\\begin{itemize}\n\t\\item the survival rate of the hatchlings is 35\\%, and hatchlings that survive their first year become adults;\n\t\\item the reproduction rate of the adults is 26\\%, meaning that 100 adults contribute an average of 26 hatchlings to next year's population;\n\t\\item hatchlings do not reproduce; and\n\t\\item the survival rate of adults is 67\\%.\n\\end{itemize}\n\nIt would now be useful to find a $2 \\times 2$ matrix $L$ that describes the growth/decline of the population from one year to the next:\n\\[ p_{\\,\\text{next year}} = L \\, p_{\\,\\text{this year}} \\:. \\]\nThe properties above show what happens to 100 hatchlings,\n\\[ \\begin{bmatrix} 100 & 0 \\end{bmatrix}^\\top \\mapsto\n\\begin{bmatrix} 0 & 35 \\end{bmatrix}^\\top, \\]\nand what happens to 100 adults, \n\\[ \\begin{bmatrix} 0 & 100 \\end{bmatrix}^\\top \\mapsto\n\\begin{bmatrix} 26 & 67 \\end{bmatrix}^\\top. \\]\nThe matrix that carries out these mappings is\n\\[ L = \\begin{bmatrix}\n 0 & 0.26 \\\\ 0.35 & 0.67\n\\end{bmatrix}, \\]\nwhich is called the \\emph{Leslie matrix} and maps a population vector to next year's state.\n\nWhat we have achieved so far is merely a systematic way of writing out the biologist's observations -- no progress that adds value to his research has been made yet. This changes once an analysis of eigenvectors is included into our study: The eigenvalues of $L$ are\n\\[ \\lambda_1 = -0.116 \\:, \\quad \\lambda_2 = 0.786 \\:. \\]\nDenote the corresponding eigenvectors $v_1, v_2$ as usual and let the current state of the population be $p_0$. Writing $p_0$ as a linear combination of the two eigenvectors,\n\\[ p_0 = c_1 v_1 + c_2 v_2 \\]\n(the coefficients can be found by solving a linear system), we find for the population $k$ years from now:\n\\begin{equation*}\n\\begin{split}\np_k & = L^kp_0 = L^{k-1}Lp_0 = L^{k-1}\\left[L(c_1v_1+c_2v_2)\\right] \\\\\n& = L^{k-1}\\left[ c_1L(v_1)+c_2L(v_2) \\right] \n= L^{k-1}\\left[ c_1 \\lambda_1 v_1 + c_2 \\lambda_2 v_2 \\right] \\\\\n& = L^{k-2}\\left[ c_1 \\lambda_1 L(v_1) + c_2 \\lambda_2 L(v_2) \\right] \n= \\ldots = c_1 \\lambda_1^k v_1 + c_2 \\lambda_2^k v_2 \\:.\n\\end{split}\n\\end{equation*}\nNote that\n\\[ \\lambda^k \\to 0 \\quad \\text{for~} k \\to \\infty \\]\nfor both eigenvalues, since both have absolute value less than $1$. This means, unfortunately, that the birds will go extinct unless preservation measures are put in place. Besides identifying a need for preservation, the eigenvalue analysis of Leslie matrices can also indicate which measures would be most effective.\n\\end{application}\n\n\\begin{exercise}\n\\label{excs:evals}\n\\begin{enumerate}[(i)]\n\t\\item Verify that $v_1=\\begin{bmatrix} -17 & 2 & 34\t\\end{bmatrix}^\\top$ is an eigenvector with eigenvalue $\\lambda_1=13$ of\n\t\\[  A = \\begin{bmatrix}\t1 & 0 & -6 \\\\ 0 & -4 & 1 \\\\ -2 & 0 & 12 \\end{bmatrix}. \\]\n\tFurther verify that $v_2 = \\begin{bmatrix} 0 & 1 & 0 \\end{bmatrix}^\\top$ and $v_3 = \\begin{bmatrix} 24 & 1 & 4 \\end{bmatrix}^\\top$ are eigenvectors as well. What are the corresponding eigenvalues, $\\lambda_2$ and $\\lambda_3$?\n\t\\item For the matrices\n\t\\[  \\begin{bmatrix} 2 & 3 \\\\ 3 & 2 \\end{bmatrix}, \\quad \n\t\\begin{bmatrix} 9 & -1 \\\\ 3 & 5\t\\end{bmatrix}, \\]\n\tfind all eigenvalues as well as the corresponding eigenvectors\\footnote{The eigenvalues of the first matrix are $\\lambda_1=5$, $\\lambda_2=-1$, and the second matrix has eigenvalues $8$ and $6$. To verify the eigenvectors you have found, make sure that multiplying them against the matrix gives the correct scalar multiple.}.\n\t\\item For the matrices\n\t\\[  \\begin{bmatrix} 3 & 2 & 4\\\\ 2 & 0 & 2 \\\\ 4 & 2 & 3 \\end{bmatrix}, \\quad \n\t\\begin{bmatrix} 0 & 1 & 1\\\\ 1 & 0 & 1 \\\\ 0 & 1 & 0 \\end{bmatrix}, \\]\n\tfind all eigenvalues as well as the corresponding eigenvectors\\footnote{$(\\lambda_1,\\lambda_2,\\lambda_3)=(-1,-1,8);(-1,\\rfrac{1+\\sqrt{5}}{2},\\rfrac{1-\\sqrt{5}}{2})$.}.\n\t\\item Find all eigenvalues of\n\t\\[ B = \\begin{bmatrix}\n\t3 &  1 &  5 &  5 \\\\ \n\t0 & -4 &  5 &  0 \\\\\n\t0 &  0 & -2 &  3 \\\\\n\t0 &  0 &  0 &  4  \n\t\\end{bmatrix}.\\]\n\tCan you make a general statement for upper triangular square matrices of any size? Hence argue that two matrices with the same set of eigenvalues need not be the same.\n\t\\item For each of the following sets of vectors, decide whether it is linearly independent or not\\footnote{Yes; no; no.}.\n\t\\[ \\left\\{ \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix},\n\t\\begin{bmatrix} 1 \\\\ -1 \\end{bmatrix} \\right\\} \\:, \\quad\n\t\\left\\{ \\begin{bmatrix} 2 \\\\ -3 \\end{bmatrix},\n\t\\begin{bmatrix} -6 \\\\ 9 \\end{bmatrix} \\right\\} \\:, \\quad\n\t\\left\\{ \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix},\n\t\\begin{bmatrix} 1 \\\\ -1 \\end{bmatrix},\n\t\\begin{bmatrix} -4 \\\\ 5 \\end{bmatrix} \\right\\} \\:. \\]\n \t\\item Write $w=\\begin{bmatrix} 2 & -3 & 9 & 1 \\end{bmatrix}^\\top$ as a linear combination\n \tof\\footnote{The discussion in Example~\\ref{expl:lin_indep} shows how to set up the system for finding the coefficients.} \n\t\\[ v_1 = \\begin{bmatrix} 1 \\\\ 3 \\\\ 0 \\\\ 5 \\end{bmatrix}, \\quad\n\tv_2 = \\begin{bmatrix} 1 \\\\ 2 \\\\ 1 \\\\ 4 \\end{bmatrix}, \\quad\n\tv_3 = \\begin{bmatrix} 1 \\\\ 1 \\\\ 2 \\\\ 3 \\end{bmatrix} , \\quad\n\tv_4 = \\begin{bmatrix} 1 \\\\ -3 \\\\ 6 \\\\ -1 \\end{bmatrix}. \\]\n\t\\item Find $\\alpha \\in \\mathbb{R}$ such that $\\lambda=0$ is an eigenvalue of\n\t\\[ \\begin{bmatrix} 1 & -1 & 1 \\\\ 1 & 2 & \\alpha \\\\ 3 & 0 & 6 \\end{bmatrix}. \\]\n\tFor this value of $\\alpha$, find the other two eigenvalues of the matrix\\footnote{$(\\lambda_2,\\lambda_3)=(3,6)$.}.\n\t\\item Show that the matrix\n\t\t\\[ A = \\begin{bmatrix}\n\t\t0 & -1 \\\\ 1 & 0\n\t\t\\end{bmatrix} \\]\n\thas no \\emph{real} eigenvalues. There are complex solutions to the eigenvalue equation though -- what are they?\n \t\\item Let $A$ be a square matrix such that there exists $k\\in\\mathbb{N}$ such that\n \t\\[ A^k = 0 \\:, \\]\n \twhere the zero on the right stands for the zero matrix, not the number zero. Show that $\\lambda=0$ is an eigenvalue of $A$ and that it is the only eigenvalue.\n \t\\item Consider a set $S$ of $n$ vectors of size $n$,\n \t\t\\[ S = \\{ v^{(1)},v^{(2)}, \\dots , v^{(n)} \\} \\:, \\]\n \t\tand show that\n \t\t\\[ S \\text{~linearly independent} \\quad \\Longleftrightarrow \\quad \\det V \\not= 0 \\:, \\]\n \t\twhere $V$ is the matrix whose columns are the vectors of $S$, i.e., the matrix in~\\eqref{eq:lin_dep_equ} of Example~\\ref{expl:lin_indep} (with $m=n$)\\footnote{Lemma~\\ref{lem:rank_det}.}.\n \t\\item Let $A$ be a $n \\times n$ matrix, $v$ an $n$-vector, and $k\\in\\mathbb{N}$ such that\n \t\\[ \\left\\{\\begin{array}{rcl} A^k\\,v & \\not= & 0 \\\\\n \t A^{k+1}\\,v & = & 0 \\:. \\end{array} \\right. \\]\n \tShow that the set \n \t\\[ S = \\{ v,Av,v,A^2v,\\ldots,A^k\\,v\\} \\]\n \tis linearly independent\\footnote{The set $S$ is linearly independent if\n \t\\begin{equation}\n \t\\label{eq:lin_dep_exc}\n \tc_0 \\, v + c_1 \\, A \\, v + c_2 \\, A^2 \\, v + \\ldots + c_k \\, A^k \\, v = 0\n \t\\tag{$\\star$}\n \t\\end{equation}\n \timplies that all coefficients are zero. Hence show that all coefficients in~\\eqref{eq:lin_dep_exc} are zero -- apply powers of $A$ to~\\eqref{eq:lin_dep_exc} to do that.}.\n \t\\item Consider a bird population that has the matrix $L$ from Example~\\ref{expl:evs} as its Leslie matrix. Suppose the current state is $p_0=\\begin{bmatrix} 200 & 1100 \\end{bmatrix}^\\top$. Find the long-term behaviour of the population\\footnote{The population converges to\n \t\t\\[ p_\\infty = \\begin{bmatrix} 600 & 800 \\end{bmatrix}^\\top. \\]}.\n\\end{enumerate}\n\\end{exercise}\n\n\n\\section{Inverse Matrices}\n\n\\begin{definition}\n\tIf for a square matrix $A$ there exists a matrix $B$ of the same size with \n\t\\[ AB = BA = I \\:, \\]\n\tthen we say that $A$ is \\emph{invertible} and $B$ is called its \\emph{inverse}, written $B=A^{-1}$.\n\\end{definition}\n\n\\begin{remark}\nNot all square matrices are invertible.\n\\end{remark}\n\n\\begin{theorem}\n\\label{thm:invertibility}\n\\[ A \\text{~invertible} \\quad \\Longleftrightarrow \\quad \\det A \\not=0 \\]\n\\end{theorem}\n\n\\begin{example}\n\\label{expl:inverses}\n\\begin{enumerate}[(i)]\n\t\\item In order to invert the matrix \n\\[ A = \\begin{bmatrix}\n1 & 2 \\\\ 2 & 4 \\end{bmatrix}, \\]\n\tdefine a $2 \\times 2$ matrix with general entries $a,b,c,d\\in\\mathbb{R}$ and check whether it is possible to obtain the identity matrix as a product:\n\\[ \\begin{bmatrix}\n1 & 2 \\\\ 2 & 4 \\end{bmatrix} \\begin{bmatrix}\na & b \\\\ c & d \\end{bmatrix} = \\begin{bmatrix}\na+2c & b+2d \\\\ 2a+4c & 2b+4d \\end{bmatrix} \\stackrel{\\text{!}}{=} \\begin{bmatrix}\n1 & 0 \\\\ 0 & 1 \\end{bmatrix}, \\]\nwhere the exclamation mark means that we want the matrix containing combinations of $a,b,c,d$ to be equal to the identity matrix on the right. However, no choice of $a,b,c,d$ achieves this -- for example, setting the bottom left entry, $2a+4c$, equal to zero implies that the upper left entry is zero as well.\n\n\tThat $A$ is not invertible could have been found more easily by looking at its determinant.\n\t\\item The determinant of\n\t\\[ B = \\begin{bmatrix}\n\t1 & 2 \\\\ 3 & 4 \\end{bmatrix} \\]\n\tis $\\det B = 1\\cdot4-3\\cdot2=-2\\not=0$, and therefore $B$ is invertible. Its inverse is\n\t\\[ B^{-1} = \\begin{bmatrix}\n\t-2 & 1 \\\\ \\rfrac{3}{2} & \\rfrac{-1}{2} \\end{bmatrix}. \\]\n\tOne can find the inverse with the naive approach in (i) or with the the more systematic approaches below. Either way, you can verify that the stated $B^{-1}$ is indeed the inverse of $B$ by finding their matrix products.\n\t\\item A $1 \\times 1$ matrix is just a number, $C=\\begin{bmatrix}\n\tc_{11} \\end{bmatrix}$. The determinant of that trivial matrix is its entry, $\\det C = c_{11}$. The above theorem states that this number has an inverse if and only if it is different from zero. You knew that already -- for $x=0$ there is no $y\\in\\mathbb{R}$ with $xy=1$, but for all other $x$, there is.\n\\end{enumerate}\n\\end{example}\n\n\\begin{remark}\n\\label{rem:inverses}\nWe now derive a systematic way to find inverses. Let $A$ be an invertible $n \\times n$ matrix. To find $A^{-1}$, denote the vectors $\\begin{bmatrix}\n0 & 0 & \\dots & 0 & 1 & 0 & \\dots & 0 \n\\end{bmatrix}^{\\top}$ of size $n$, where the entry $1$ is in the $j$-th place, by $e_j$. Now convince yourself of the following observations.\n\\begin{enumerate}[(i)]\n\t\\item For any $n \\times n$ matrix $B$, the $j$-th column of $B$ is $Be_j$.\n\t\\item If $A$ maps $v$ to $w$, then $A^{-1}$ maps $w$ to $v$~:\n\\[ Av=w \\quad \\Longrightarrow\\ \\quad A^{-1}w=A^{-1}Av = Iv = v \\:. \\]\n\t\\item Solving the augmented matrix $[A\\:|\\:w]$ gives the vector $v$ that is mapped to $w$ by $A$~: $Av=w$.\n\t\\item Now combine those three points to find the columns of $A^{-1}$~:\n\\begin{equation*}\n\\begin{split}\n\\text{denote the $j$-th column of $A^{-1}$ by $c_j$ } & \n\\stackrel{\\text{(i)}}{\\longrightarrow}\nc_j=A^{-1}e_j \\\\\n& \\stackrel{\\text{(ii)}}{\\longrightarrow}\nAc_j=e_j \\\\\n& \\stackrel{\\text{(iii)}}{\\longrightarrow}\nc_j \\text{~is the solution of~} [A\\:|\\:e_j] \\:.\n\\end{split}\n\\end{equation*}\n\t\\item We therefore need to solve $[A\\:|\\:e_j]$ for all $j\\in\\{1,2,3,\\dots,n\\}$ to obtain the columns $c_j$ of $A^{-1}$. This can be done with a single Gaussian elimination by augmenting all $n$ vectors at once:\n\t\\begin{itemize}\n\t\t\\item Augmenting $e_1,e_2,e_3,\\ldots,e_n$ side by side amounts to augmenting the identity matrix.\n\t\t\\item The RREF of $A$ is the identity matrix, since $A$ has a nonzero determinant and therefore rank $n$ (cf. Lemma~\\ref{lem:rank_det}). That is, $A$ can be transformed into~$I$.\n\t\t\\item If the left-hand side of an augmented matrix is $I$, then the solution can be read off directly: $b$ is the solution of $[I\\:|\\:b]$ (as in Example~\\ref{expl:augm_matrix} (iii)).\n\t\\end{itemize}\n\n\tWe have derived the following algorithm for finding inverse matrices.\n\t\\item To find the inverse of the invertible matrix $A$, augment the identity matrix $I$ and bring $A$ in reduced row echelon form using elementary row operations. The matrix on the right is then the inverse of $A$~:\n\t\\[ [\\,A\\:|\\:I\\,] \\qquad\n\t\\stackrel{\\text{elementary row operations}}{\\rightsquigarrow}\n\t\\qquad [\\,I\\:|\\:A^{-1}\\,] \\:. \\]\n\\end{enumerate}\n\\end{remark}\n\n\\begin{example} Check whether\n\\[ A = \\begin{bmatrix}\n-5 & 0 & 7 \\\\ 6 & 2 & -6 \\\\ -4 & 0 & 6\n\\end{bmatrix} \\]\nis invertible and find its inverse in case it is.\\\\\n{\\it Sol.:} Developing along the second column, Laplace's method gives\n\\begin{equation*}\n\\begin{split}\n\\det A & = (-1)^{2+1} \\cdot 0 \\cdot \\left| \\dots \\right| \n+ (-1)^{2+2} \\cdot 2 \\cdot \\left| \\dots \\right| \n+ (-1)^{2+3} \\cdot 0 \\cdot \\left| \\dots \\right| \\\\\n& = 2 \\cdot \\begin{vmatrix} -5 & 7 \\\\ -4 & 6 \\end{vmatrix}\n= 2 \\cdot (-30+28) = -4 \\not= 0 \\:.\n\\end{split}\n\\end{equation*}\nHence $A$ is invertible. The method from the previous remark,\n\\[\\begin{array}{ccc}\n\\left[\\begin{array}{ccc|ccc}\n-5 & 0 & 7 & 1 & 0 & 0 \\\\\n6 & 2 & -6 & 0 & 1 & 0 \\\\ \n-4 & 0 & 6 & 0 & 0 & 1\n\\end{array}\\right] & \\stackrel{\\text{(i)}}{\\rightarrow} & \n\\left[\\begin{array}{ccc|ccc}\n120 & 0 & -168 & -24 & 0 & 0 \\\\\n-120 & -40 & 120 & 0 & -20 & 0 \\\\ \n-120 & 0 & 180 & 0 & 0 & 30\n\\end{array}\\right] \\\\ & & \\\\\n& \\stackrel{\\text{(ii)}}{\\rightarrow} & \n\\left[\\begin{array}{ccc|ccc}\n120 & 0 & -168 & -24 & 0 & 0 \\\\\n0 & -40 & -48 & -24 & -20 & 0 \\\\ \n0 & 0 & 12 & -24 & 0 & 30\n\\end{array}\\right] \\\\ & & \\\\\n& \\stackrel{\\text{(iii)}}{\\rightarrow} & \n\\left[\\begin{array}{ccc|ccc}\n120 & 0 & 0 & -15\\cdot24 & 0 & 14\\cdot30 \\\\\n0 & -40 & 0 & -5\\cdot24 & -20 & 4\\cdot30 \\\\ \n0 & 0 & 12 & -24 & 0 & 30\n\\end{array}\\right] \\\\ & & \\\\\n& \\stackrel{\\text{(iv)}}{\\rightarrow} & \n\\left[\\begin{array}{ccc|ccc}\n1 & 0 & 0 & -3 & 0 & \\rfrac{7}{2} \\\\\n0 & 1 & 0 & 3 & \\rfrac{1}{2} & -3 \\\\ \n0 & 0 & 1 & -2 & 0 & \\rfrac{5}{2}\n\\end{array}\\right],\n\\end{array}\t\\]\nleads to \n\\[ A^{-1} = \\begin{bmatrix}\t-3 & 0 & \\rfrac{7}{2} \\\\\n\t3 & \\rfrac{1}{2} & -3 \\\\ -2 & 0 & \\rfrac{5}{2} \\end{bmatrix}. \\]\nThe Gaussian elimination can of course be carried out in a different way. Here, the following steps were used.\n\\begin{enumerate}[(i)]\n\t\\item Multiply $R1,R2,R3$ by $-24,-20,30$, respectively, to prepare the elimination of the bottom two entries of the first column.\n\t\\item Add $R1$ to both $R2$ and $R3$ to carry out that elimination.\n\t\\item In general, the middle entry of the third row would have to be eliminated next, but here it is already zero. That is, we already have REF. Now use the entry $12$ to eliminate the entries $-168$ and $-48$.\n\t\\item Again, the middle entry of the first row would have to be eliminated next, but here it is already zero. We have the left-hand side in diagonal form, and it remains to divide the three rows by $120,-40,12$ to obtain the identity matrix.\n\\end{enumerate}\n\\end{example}\n\n\\begin{remark}\n\\label{rem:inverse}\nAs a first simple example to do on your own, you are encouraged to find $B^{-1}$ from Remark~\\ref{expl:inverses} (ii) with that method. Once you are comfortable with that computation, you may use the formula for inverses of $2 \\times 2$ matrices:\n\\[ A = \\begin{bmatrix} a & b \\\\ c & d \\end{bmatrix}\n\\qquad \\Longrightarrow \\qquad \nA^{-1} = \\frac{1}{ad-bc} \\begin{bmatrix} d & -b \\\\ -c & a \\end{bmatrix}. \\]\n\nYou can verify this formula by multiplication. Of course, one can apply it only when the given matrix $A$ is invertible -- what happens if you try use it for a matrix that is not invertible (e.g. for the matrix in Example~\\ref{expl:inverses} (i))?\n\\end{remark}\n\n\\begin{application}[Approximate solutions]\n\tWe now derive a general technique as an application of the theory covered so far: finding approximate solutions of linear systems that do not have solutions. This is of general importance in many different areas of mathematics and other STEM disciplines.\n\t\n\tLet $A$ be a $m \\times n$ matrix and define the \\emph{range} of $A$ as the set of vectors of $\\mathbb{R}^m$ that $A$ maps to,\n\t\\[ \\mathrm{range} \\, A = \\{ w \\in \\mathbb{R}^m \\: | \\: \n\t\\text{there exists } v \\in \\mathbb{R}^n \\text{ such that } Av=w \\} \\:. \\]\n\tThe connection to solving linear systems is\n\t\\[ Av = b \\text{ has a solution} \\quad \\Longleftrightarrow\n\t\\quad b \\in \\mathrm{range}\\, A \\:. \\]\n\t\n\tNow suppose that $Av=b$ that does not have a solution. An idea for finding an approximate solution is to find an element $\\wtd{b}$ of the range of $A$ that is close to $b$. Since $\\wtd{b} \\in \\mathrm{range} \\, A$, the system $A\\wtd{v}=\\wtd{b}$ is solvable, and its solution can then be considered an approximate solution of $Av=b$. The idea for obtaining $\\wtd{b}$ is to project the vector $b$ onto the range of $A$. In Section~\\ref{sec:rma}, we have seen how to project a point onto the line spanned by a vector $v = \\begin{bmatrix} a & b\n\t\\end{bmatrix}^\\top$, and that is in fact the same as projecting onto the range of the matrix \n\t\\[ A = \\begin{bmatrix} 0 & a \\\\ 0 & b \\end{bmatrix}. \\]\n\tThis observation suggests to generalise the formula \n\t\\begin{equation}\n\t\\label{eq:1d_proj}\n\tP_L = \\frac{v \\, v^\\top}{v^\\top \\, v}\n\t\\end{equation}\n\tfrom the application in Section~\\ref{sec:rma} to matrices. The notation $\\tfrac{1}{x} = x^{-1}$ for real numbers suggests to replace the fraction in~\\eqref{eq:1d_proj} with a matrix product that contains an inverse. The product in the numerator, $A A^\\top$, is of the form $m \\times n \\cdot n \\times m = m \\times m$. The denominator, $A^\\top A$,  has size $n \\times m \\cdot m \\times n = n \\times n$, and its inverse is $n \\times n$ as well. Therefore the matrices $A A^\\top$ and $A^\\top A$ can not multiply in either order, as the sizes do not match. However, it is possible to insert the matrix coming from the denominator between the two factors of the numerator:\n\t\\[ P_A = A \\, (A^\\top \\, A)^{-1} A^\\top. \\]\n\t\n\tWe have derived the following approach to finding approximate solutions $\\wtd{v}$~: if $Av=b$ does not have a solution, then\n\t\\[ Av=b \\quad \\leadsto \\quad A\\wtd{v}=\\wtd{b} = P_A \\, b \n\t= A \\, (A^\\top \\, A)^{-1} A^\\top \\, b \\:, \\]\n\tof which\n\t\\begin{equation}\n\t\\label{eq:proj_range}\n\t\\wtd{v} = (A^\\top \\, A)^{-1} A^\\top \\, b\n\t\\end{equation}\n\tis a solution. Note that we have not proven the validity of this method -- we have merely identified the only consistent way to generalise the projection formula from Section~\\ref{sec:rma} to matrices. It will be shown in the next chapter that~\\eqref{eq:proj_range} is correct. \n\\end{application}\n\n\\begin{application}[Linear regression]\n\tNext we derive an important technique that is used for statistical modelling and machine learning. Suppose data of the following form has been collected.\n\t\\[ X = \\begin{bmatrix}\n\tx_1^{(1)} & x_2^{(1)} & \\dots & x_n^{(1)} \\\\\n\tx_1^{(2)} & x_2^{(2)} & \\dots & x_n^{(2)} \\\\\n\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\tx_1^{(m)} & x_2^{(m)} & \\dots & x_n^{(m)}\n\t\\end{bmatrix}, \\quad y = \\begin{bmatrix}\n\ty^{(1)} \\\\ y^{(2)} \\\\ \\vdots \\\\ y^{(m)} \n\t\\end{bmatrix}. \\]\n\tIn the matrix $X$, which is called the \\emph{design matrix}, each row stands for an individual or event for which data has been collected, and the elements of that row, \n\t\\[ \\begin{bmatrix}\n\tx_1^{(k)} & x_2^{(k)} & \\dots & x_n^{(k)} \\\\\n\t\\end{bmatrix},\\]\n\tdescribe different attributes. There further is an additional observed value, $y^{(k)}$, for that individual/event, which we suspect to be related to the corresponding attributes $x_j^{(k)}$ ($1 \\leq j \\leq n$). If we can find the relation $X \\leftrightarrow y$, it can be used to predict future $y$ values. For example, the data $X$ above could be information extracted from last year's annual reports of $m$ companies. The attributes could be company size, net income, total amount of debt, etc., and the values $y$ the change in price of the companies' shares on the stock market. \n\t\n\tThe most simple relationship between $X$ and $y$ is\n\t\\[ y^{(k)} = w_1 \\cdot x_1^{(k)} + w_2 \\cdot x_2^{(k)} + \\dots + w_n \\cdot x_n^{(k)} \\:. \\]\n\tWhile this equation is certainly solvable for an individual row, it is very unlikely that there is a single vector $w$ that works for all rows -- for the model to be statistically sound, the amount of data, $m$, needs to be larger than $n$. Then there are more equations than variables, and the existence of a solution is unlikely. Fortunately, we know how to find the approximate solution of $Xw=y$~: \n\t\\[ \\wtd{w} = (X^\\top X)^{-1} X^\\top y \\:. \\]\n\t\t\n\tReturning to the financial application mentioned above: Once you have found the relation $w$ between last year's reported data and the subsequent performance on the stock market, and once this year's annual reports have been published, you could produce the matrix $X$ for a selection of listed companies and then compute the corresponding $y$-values as\n\t\\[ y^{\\text{this year}} = X^{\\text{this year}} \\, w^{\\text{last year}} \\:. \\]\n\tHowever, such ``predictions'' can be wholly inappropriate; there is a large number of caveats, e.g.: perhaps this approach is not able to capture the true relationship $X \\leftrightarrow y$, perhaps that relationship depends on other factors as well, or perhaps there is no true relationship and the model is built on coincidence. One therefore has to be very careful when interpreting the predictions given by machine learning algorithms. Statisticians and data scientists always take a range of measures to test and validate their model before they deploy their findings.\n\\end{application}\n\n\\begin{exercise}\n\\begin{enumerate}[(i)]\n\t\\item Find the inverses of \n\t\\[ \\begin{bmatrix} 2 & -2 \\\\ 0 & 8 \\end{bmatrix}, \n\t\\begin{bmatrix}\t9 & -4 \\\\ 7 & 8 \\end{bmatrix}. \\]\n\tNext, pick a vector, compute the vector that it gets mapped to by the matrix, and then check that the inverse undoes that transformation.\n\t\\item Find the inverses of\n\t\\[ \\begin{bmatrix}\n\t1 & 2 & 3 \\\\ 0 & 4 & 5 \\\\ 0 & 6 & 7\n\t\\end{bmatrix}, \\quad\n\t\\begin{bmatrix}\n\t\\rfrac{-5}{18} & \\rfrac{1}{18} & \\rfrac{7}{18} \\\\\n\t\\rfrac{1}{18} & \\rfrac{7}{18} & \\rfrac{-5}{18} \\\\\n\t\\rfrac{7}{18} & \\rfrac{-5}{18} & \\rfrac{1}{18}\n\t\\end{bmatrix}. \\]\n\t\\item Find the inverse of\\footnote{Matrices like the given one are called \\emph{block diagonal}. Here we have two $1 \\times 1$ blocks and one $2 \\times 2$ block on the diagonal. What do you notice for the inverse?}\n\\[ \\begin{bmatrix}\n1 & 0 & 0 & 0 \\\\ 0 & 2 & 0 & 0 \\\\  \n0 & 0 & 1 & 2 \\\\\n0 & 0 & 3 & 4 \\\\\n\\end{bmatrix}. \\]\n\t\\item Consider the system\n\t\\begin{equation*}\n\t\\left\\{\\begin{array}{rcrcl}\n\tx & + & 5y & = & 4 \\\\\n\t-2x & + & y & = & 3 \\:,\n\t\\end{array}\\right.\n\t\\end{equation*}\n\tand solve it in two ways: First, as in Section~\\ref{sec:sys_lin_equ}. Secondly, find the inverse of the matrix $A$ of coefficients and obtain the solution $v = \\begin{bmatrix} x & y \\end{bmatrix}^{-1}$ as\n\t\\[ v = A^{-1} \\begin{bmatrix} 4 \\\\ 3 \\end{bmatrix}. \\]\n\tWhich approach do you find faster?\n\t\\item Convince yourself that Theorem~\\ref{thm:invertibility} is true\\footnote{Lemma~\\ref{lem:rank_det} should be helpful here. The following is an alternative approach. When $\\det A = 0$, we have a certain eigenvalue, $\\lambda = \\dots$ Which one? Now try to apply the $v \\leftrightarrow w$ argument from Remark~\\ref{rem:inverses} to the corresponding eigenvector. Does that work?}.\n\t\\item Let $\\lambda$ be an eigenvalue of an invertible matrix $A$. Show that $\\lambda\\not=0$ and that $A^{-1}$ has $\\lambda^{-1}$ as an eigenvalue.\n\t\\item Given that the set of vectors $\\{v_1,v_2,v_3\\}$ in $\\mathbb{R}^3$ is linearly independent, show that $\\{w_1,w_2,w_3\\}$, where\n\t\\[ \\begin{cases} w_1 = v_1 + v_2 \\\\\n\tw_2 = 3v_2 + 2v_3 \\\\ w_3 = v_1 - 2v_2 + v_3\t\\:, \\end{cases} \\]\n\tis linearly independent as well\\footnote{Let $V$ and $W$ be the $3 \\times 3$ matrices consisting of the vectors $v_j$ and $w_j$. The observation\n\t\\[ V \\begin{bmatrix} 1 & 0 & 1 \\\\ 1 & 3 & -2 \\\\ 0 & 2 & 1 \\end{bmatrix} = W \\]\n\tis now very useful. Check whether the matrix $C$ of coefficients for the transformation $v_j \\leadsto w_j$ is invertible. If so, you can write $V=WC^{-1}$. Compare to Example~\\ref{expl:lin_indep} for inspiration on how to complete the proof.}.\n\t\\item For the bird population from the last problem of exercise set~\\ref{excs:evals}, find the state of the population in the previous year.\n\t\t\\item Suppose you are taking a module which is assessed via a mid-term exam, coursework assignments, and a final exam. You know three of last year's students, and they had the following marks.\n\t\\[ \\begin{cases} S_1 = (55,43,61) \\\\\n\tS_2 = (72,60,82) \\\\\n\tS_3 = (64,63,68) \\:, \\end{cases} \\]\n\twhere the marks are stated in the format ``$($mid-term exam, coursework, final exam$)$''. Given that you have scored $73$ and $74$ on the mid-term exam and on the coursework assignment, predict your score on the final exam using linear regression. However, this ``prediction'' is not an appropriate use of linear regression! Why not\\footnote{Your predicted score on the final exam is\n\t\t\\[ y = \\begin{bmatrix} 73 & 74 \\end{bmatrix}\n\t\t\\left( \\begin{bmatrix} 55 & 72 & 64 \\\\ 43 & 60 & 63 \\end{bmatrix}\n\t\t\\begin{bmatrix} 55 & 43 \\\\ 72 & 60 \\\\ 64 & 63 \\end{bmatrix} \\right)^{-1}\n\t\t\\begin{bmatrix} 55 & 72 & 64 \\\\ 43 & 60 & 63 \\end{bmatrix}\n\t\t\\begin{bmatrix} 61 \\\\ 82 \\\\ 68 \\end{bmatrix} = \\dots \\approx 77.3 \\:.  \\]\n\t\tYou should not rely on this prediction though, as it is problematic in a number of ways. Most notably:\n\t\t\\begin{itemize}\n\t\t\t\\item there is not enough data;\n\t\t\t\\item the lecturer may have changed the level of difficulty of the assessments;\n\t\t\t\\item and, most importantly, your performance on the final exam depends above all on how well you study!\n\t\\end{itemize}}?\n\\end{enumerate}\n\\end{exercise}", "meta": {"hexsha": "bfd9c07148ea21a5bd534f800421357d5c35ebb7", "size": 101300, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/ch_vm.tex", "max_stars_repo_name": "pasc85/MathematicalMethods", "max_stars_repo_head_hexsha": "1dd151a72deebbcb0da09955d897bbad1691597b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/ch_vm.tex", "max_issues_repo_name": "pasc85/MathematicalMethods", "max_issues_repo_head_hexsha": "1dd151a72deebbcb0da09955d897bbad1691597b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2020-11-26T21:39:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-28T11:35:22.000Z", "max_forks_repo_path": "Chapters/ch_vm.tex", "max_forks_repo_name": "pasc85/MathematicalMethods", "max_forks_repo_head_hexsha": "1dd151a72deebbcb0da09955d897bbad1691597b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.7863710114, "max_line_length": 767, "alphanum_fraction": 0.6383119447, "num_tokens": 37504, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7225222322474895}}
{"text": "\\subsection{Real differentiability}\\label{subsec:real_differentiability}\n\n\\begin{proposition}\\label{thm:real_valued_differentiability}\n  Let \\( U \\subseteq \\BbbR^n \\) be an open set. A real-valued function \\( f: U \\to \\BbbR \\) is differentiable at \\( x \\) in the direction \\( h \\) if and only if \\( \\varphi(t) = f(x + th) \\) is right-differentiable at \\( 0 \\).\n\\end{proposition}\n\\begin{proof}\n  \\begin{equation*}\n    f_+'(x)(h) \\coloneqq \\lim_{t \\downarrow 0} \\frac {f(x + th) - f(x)} t = \\varphi_+'(0)(1).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{example}[Weierstrass' nowhere differentiable function]\\label{ex:weierstrass_nowhere_differentiable_function}\\mcite[\\textnumero 271]{Фихтенгольц1968Том2}\n  Let \\( a \\in (0, 1) \\) and \\( b \\) is a positive odd integer such that\n  \\begin{equation*}\n    ab > 1 + \\frac 3 2 \\pi.\n  \\end{equation*}\n\n  Define the function\n  \\begin{equation*}\n    f(x) \\coloneqq \\sum_{k=0}^\\infty a^k \\cos(b^k \\pi x).\n  \\end{equation*}\n\n  \\begin{figure}\n    \\centering\n    \\includegraphics{output/ex__weierstrass_nowhere_differentiable_function.pdf}\n    \\caption\n    {\n      Plot of the third partial sum of the Weierstrass function with \\( a = 0.9 \\) and \\( b = 7 \\) from \\( -\\sfrac \\pi 8 \\) to \\( \\sfrac \\pi 8 \\).\n    }\n    \\label{fig:ex:weierstrass_nowhere_differentiable_function/plot}\n  \\end{figure}\n\n  Since \\( \\cos \\) is bounded for real arguments and \\( a \\in (0, 1) \\), each term is uniformly bounded by \\( 1 \\) and by \\fullref{thm:weierstrass_series_criterion}, \\( f \\) is continuous. However, it is not \\hyperref[def:differentiability]{differentiable} at any point. The proof of the latter is involved and will not be given here.\n\\end{example}\n", "meta": {"hexsha": "42a581d6c010a53d9957a4b3ff19bf4441294b2f", "size": 1675, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/real_differentiability.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/real_differentiability.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/real_differentiability.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.8571428571, "max_line_length": 334, "alphanum_fraction": 0.6805970149, "num_tokens": 569, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.722522213617109}}
{"text": "\\section{Theoretical Justifications of AMP}\n\n\\begin{frame}{AMP Finds Flatter Local Minima}\n\n\\begin{columns}\n\\column{0.68\\textwidth}\n\n\\begin{block}{Locally Gaussian Assumption of Empirical Risk}\n\\vspace{-0.5em}\n\\begin{equation*}\n\\mathcal{L}_\\mathrm{ERM}\\approx\\gamma(\\boldsymbol{\\theta};\\boldsymbol{\\mu},\\boldsymbol{\\kappa},A,C)\n\\end{equation*}\n\\vspace{-1.5em}\n\n\\textit{where $\\gamma(\\boldsymbol{\\theta};\\boldsymbol{\\mu},\\boldsymbol{\\kappa},A,C)$ is minimized when $\\boldsymbol{\\theta}=\\boldsymbol{\\mu}$ and the minimum value is $\\gamma^\\ast(\\boldsymbol{\\mu},\\boldsymbol{\\kappa},A,C)=C-A$.}\n\\end{block}\n\n\\begin{theorem}[stated informally]\nThe minimum value of the AMP loss is\n\\vspace{-0.5em}\n\\begin{equation*}\n\\gamma_\\mathrm{AMP}^\\ast(\\boldsymbol{\\mu},\\boldsymbol{\\kappa},A,C)=C-A\\exp\\left(-\\frac{\\epsilon^2}{2\\sigma^2}\\right)\n\\end{equation*}\n\\vspace{-1.5em}\n\nwhere $\\sigma^2$ is the smallest eigenvalue of $\\boldsymbol{\\kappa}$.\n\\end{theorem}\n\n\\column{0.32\\textwidth}\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{figs/surface.png}\n\\end{figure}\n\\vspace{-0.5em}\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{figs/gaussian.pdf}\n\\caption{The minimum values of $\\gamma$ and $\\gamma_\\mathrm{AMP}$.}\n\\end{figure}\n\\end{columns}\n\\vspace{1em}\n\\end{frame}\n\n\\begin{frame}{AMP Regularizes Gradient Norm}\n\n\\begin{theorem}[stated informally]\nLet $N=1$. The AMP training is equivalent to ERM training with an additional term:\n\\begin{equation*}\n\\widetilde{\\mathcal{J}}_\\mathrm{ERM}(\\boldsymbol{\\theta}):=\\mathcal{J}_\\mathrm{ERM}(\\boldsymbol{\\theta})+\\Omega(\\boldsymbol{\\theta})\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\Omega(\\boldsymbol{\\theta}):=\\begin{cases}\n\\zeta\\Vert\\nabla_{\\boldsymbol{\\theta}}\\mathcal{J}_\\mathrm{ERM}(\\boldsymbol{\\theta})\\Vert_2^2,&\\Vert\\zeta\\nabla_{\\boldsymbol{\\theta}}\\mathcal{J}_\\mathrm{ERM}(\\boldsymbol{\\theta})\\Vert_2\\le\\epsilon\\\\\n\\epsilon\\Vert\\nabla_{\\boldsymbol{\\theta}}\\mathcal{J}_\\mathrm{ERM}(\\boldsymbol{\\theta})\\Vert_2,&\\Vert\\zeta\\nabla_{\\boldsymbol{\\theta}}\\mathcal{J}_\\mathrm{ERM}(\\boldsymbol{\\theta})\\Vert_2>\\epsilon\n\\end{cases}\n\\end{equation*}\n\\end{theorem}\n\n% Thus, the AMP training algorithm effectively tries to find the local minima of empirical risk that not only have low values, but also have small gradient norm near the minima. Note that a minimum with smaller gradient norms around it is a flatter minimum.\n\n\\end{frame}\n", "meta": {"hexsha": "d45dc47ed24a077bffe652ca93383b1a63200959", "size": 2364, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/justification.tex", "max_stars_repo_name": "hiyouga/AMP-Poster-Slides-LaTeX", "max_stars_repo_head_hexsha": "c1fd40aa5ef3216f17b4d27dc6e6092e3cc52e40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-05-25T11:56:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-20T07:12:01.000Z", "max_issues_repo_path": "slides/justification.tex", "max_issues_repo_name": "hiyouga/AMP-Poster-Slides-LaTeX", "max_issues_repo_head_hexsha": "c1fd40aa5ef3216f17b4d27dc6e6092e3cc52e40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-05-28T15:25:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-30T05:01:24.000Z", "max_forks_repo_path": "slides/justification.tex", "max_forks_repo_name": "hiyouga/AMP-Poster-Slides-LaTeX", "max_forks_repo_head_hexsha": "c1fd40aa5ef3216f17b4d27dc6e6092e3cc52e40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-05-26T01:39:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T06:36:04.000Z", "avg_line_length": 38.7540983607, "max_line_length": 257, "alphanum_fraction": 0.7381556684, "num_tokens": 779, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7225103346950411}}
{"text": "%---------------------------Condition Number-----------------------------\n\\section{Condition\\label{s:tri-condition}}\n\nThe condition number of the weighted Jacobian matrix is\n\\[\n  q = \\frac{\n    \\left(\\vec L_2\\cdot\\vec L_2 + \\vec L_1\\cdot\\vec L_1 + \\vec L_1\\cdot\\vec L_2 \\right)}%\n    {2A\\sqrt{3}}.\n\\]\n\nNote that when $A = 0$, we set $q = DBL\\_MAX$.\nIn theory the condition number is invariant to which node it is computed at,\nbut floating point truncation error can contribute to differences between\nvalues computed for each node.\n\\verd\\ always uses the first vertex.\n\n\\trimetrictable{condition}%\n{$1$}%                                                Dimension\n{$[1,1.3]$}%                                          Acceptable range\n{$[1,DBL\\_MAX]$}%                                     Normal range\n{$[1,DBL\\_MAX]$}%                                     Full range\n{$1$}%                                                Unit equilateral triangle value\n{\\cite{knu:00,knu:03}}%                               Reference(s)                   \n{v\\_tri\\_condition}%                            Verdict function name\n\n", "meta": {"hexsha": "3e13b82560a12441b7bfd28d3c553e875f64432d", "size": 1107, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TriCondition.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TriCondition.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TriCondition.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 42.5769230769, "max_line_length": 89, "alphanum_fraction": 0.4923215899, "num_tokens": 254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7225103283708774}}
{"text": "\\section{Proper Methodology}\nThe problem is formulated as a normal form game where the players are the two hospitals. \nEach hospital is given \\( N_A \\) and \\( N_B \\) number of strategies where \\( N_A \\) \nand \\( N_B \\) are the total capacities of the hospitals. \nIn other words, depending on the capacity of each hospital, they may choose to stop \nreceiving patients from arriving ambulances whenever they reach a certain capacity \nthreshold. \nThe goal of this problem is to satisfy the ED regulations which state that 95\\% \nof the patients should see a specialist within 4 hours of their arrival to the hospital. \nThe mean of the random variable \\( W_q \\) is the average waiting time in the queue \nfor hospital i.\n\n\n\\begin{equation}\n     W_q(\\lambda_i, \\mu_i, \\hat{c_i}) = \\frac{1}{\\hat{c_i} \\mu_i} \n     \\frac{(\\hat{c_i} \\rho_i) ^ {\\hat{c_i}}}{\\hat{c_i}! (1 - \\rho_i) ^ 2}P_0, \n     \\quad i \\in \\{A,B\\}\n\\end{equation}\n\nThus, the utilities of the two players should be the proportion of people that fall \nwithin the 4 hours target. \nThis is also equivalent to the probability of the waiting time of an individual \nto be less than or equal to 4 hours. \n\n\\begin{equation}\n    P(W_q(\\lambda_i, \\mu_i, \\hat{c_i}) \\leq 4), \\quad i \\in \\{A,B\\}\n\\end{equation}\n\nTherefore, a sensible goal for each player should be to minimise that probability, \nbut the actual target of the hospitals is to satisfy 95\\% of those patients within \nthe 4-hour time limit. Therefore, the goal should be to get that probability as \nclose to 0.95 as possible. \nThus each player should aim to minimise:\n\n\\begin{equation}\n    |0.95 - P(W_q(\\lambda_i, \\mu_i, \\hat{c_i}) \\leq 4)|, \\quad i \\in \\{A,B\\}\n\\end{equation}\n\nThe classic formulation of a normal form game looks into the maximisation of each \nplayer's payoff. \nConsequently the utilities can be altered such that the goal of each player is to \nmaximise:\n\n\\begin{align}\\label{Utilities}\n    U_{\\hat{c_A}, \\hat{c_B}} ^ {A} = 1 - |0.95 - P(W_q(\\lambda_A, \\mu_A, \\hat{c_A}) \\leq 4)| \\\\\n    U_{\\hat{c_A}, \\hat{c_B}} ^ {B} = 1 - |0.95 - P(W_q(\\lambda_B, \\mu_B, \\hat{c_B}) \\leq 4)|\n\\end{align}\n\nFinally, the problem can be expressed as a normal form game with two players where \neach player/hospital has \\( N_A \\) and \\( N_B \\) strategies respectively. \nThe two \\( N_A \\times N_B \\) payoff matrices for the utilities of the two hospitals \ncan be defined as:\n\n\\begin{table}[h]\n    \\centering\n    \\begin{minipage}{.5\\linewidth}\n        A = \n        \\begin{tabular}{|l|l|l|l|}\n            \\hline\n            \\( U_{1,1}^A \\) & \\( U_{1,2}^A \\) & \\dots & \\( U_{1,C_2}^A \\) \\\\ \\hline\n            \\( U_{2,1}^A \\) & \\( U_{2,2}^A \\) & \\dots & \\( U_{2,C_2}^A \\) \\\\ \\hline\n            \\vdots & \\vdots & \\( \\ddots \\) & \\vdots \\\\ \\hline\n            \\( U_{C_1,1}^A \\) & \\( U_{C_1,2}^A \\) & \\dots & \\( U_{C_1,C_2}^A \\) \\\\ \\hline\n        \\end{tabular}\n    \\end{minipage}%\n    \\begin{minipage}{.5\\linewidth}\n        B = \n        \\begin{tabular}{|l|l|l|l|}\n            \\hline\n            \\( U_{1,1}^B \\) & \\( U_{1,2}^B \\) & \\dots & \\( U_{1,C_2}^B \\) \\\\ \\hline\n            \\( U_{2,1}^B \\) & \\( U_{2,2}^B \\) & \\dots & \\( U_{2,C_2}^B \\) \\\\ \\hline\n            \\vdots & \\vdots & \\( \\ddots \\) & \\vdots \\\\ \\hline\n            \\( U_{C_1,1}^B \\) & \\( U_{C_1,2}^B \\) & \\dots & \\( U_{C_1,C_2}^B \\) \\\\ \\hline\n        \\end{tabular}\n    \\end{minipage}\n\\end{table}  \nOnce the certain strategies of the game have been selected the ambulance service \ncan decide what would be the optimal way to distribute patients. \nHowever, the way the ambulance service distributes patients can affect the utilities \nof the game. So how would one solve this kind of problem?\n \n\\subsection{Solution}\nAs mentioned before the problem requires the construction of two queuing models \nthat will be needed for the formulation of the normal form game. \nBased on those utilities the ambulance service will then decide the percentage of \npatients that will distribute to each hospital. \n\nFirst and foremost, the model consists of several parameters that are unknown and \nare assumed to be fixed. \nThe model will be run multiple times for various values of these parameters.\n\n\n\\begin{table}[h]\n    \\centering\n    \\begin{tabular}{|l|l|}\n        \\hline\n        \\( \\Lambda_2 \\) & Number of patients that need to be distributed \\\\ \\hline\n        \\( \\lambda_{1,i} \\) & Arrival rate of other patients that enter hospital i \\\\ \\hline\n        \\( \\mu_i \\) & Service rate of hospital i \\\\ \\hline\n        \\( N_i \\) & Total capacity of hospital i \\\\ \\hline\n    \\end{tabular}\n    \\caption{Fixed Parameters}\n\\end{table}\n\nHaving established the fixed parameters of the model, the hospitals' utilities need \nto be calculated. \nIn order to do so a backwards induction approach will be used. \nThe EMS aims to distribute the patients such that the mean waiting time of patients \nis minimal. \nThis can be further interpreted as when the mean waiting time of hospital A equals \nthe mean waiting time of hospital B. \nThus, the minimal mean waiting time can be found for the values of \\( p_A \\) and \n\\( p_B \\) that solve the following equation:\n\n\\begin{equation}\\label{Equal_Wait}\n    W_q(\\lambda_A, \\mu_A, \\hat{c_A}) = W_q(\\lambda_B, \\mu_B, \\hat{c_B})\n\\end{equation}\n\nEquation (\\ref{Equal_Wait}) needs to be solved for all values of \\( c_i \\in \\{1,2, \n\\dots C_A\\} \\) and \\( c_j \\in \\{1,2, \\dots C_B\\} \\). \nThen, for every \\( c_i \\) and \\( c_j \\) the utility equation (\\ref{Utilities}) has \nto be calculated for both hospitals. \nIn order to solve it though, one must first estimate the probability \n\\( P[(W_q)_{\\{A, B\\}}] \\leq 4] \\). \nThat is the probability that the waiting time in the queue for one of the hospitals \nis less than 4 hours. \nFor a multi-server system, the distribution of the waiting time can be given by \nequation \\ref{Dist_Wait}. \nThe above expression returns the probability that the waiting time in the queue \nis less than some time T.\n\n\\begin{equation}\\label{Dist_Wait}\n    P(W_q > T) = \\frac{(\\frac{\\lambda}{\\mu})^c P_0}{c!(1-\\frac{\\lambda}{c \\mu})} \n    (e^{-(c \\mu - \\lambda)T})\n\\end{equation}\n\nConsequently when incorporating equation (\\ref{Dist_Wait}) into (\\ref{Utilities}) \na newer utility equation can be acquired:\n \n\\begin{equation}\\label{Utilities2}\n    U_{\\hat{c_i}, \\hat{c_j}} ^ {\\{A, B\\}} = 1 - \\left| \\left[ \n        \\frac{(\\frac{\\lambda}{\\mu})^c P_0}{c!(1-\\frac{\\lambda}{c \\mu})} \n        \\left( e^{-(c \\mu - \\lambda)T} \\right) \\right] - 0.05 \\right|\n\\end{equation}\n\n\\begin{table}[h]\n    \\centering\n    \\begin{minipage}{.5\\linewidth}\n        A = \n        \\begin{tabular}{|l|l|l|l|}\n            \\hline\n            \\( U_{1,1}^A \\) & \\( U_{1,2}^A \\) & \\dots & \\( U_{1,C_2}^A \\) \\\\ \\hline\n            \\( U_{2,1}^A \\) & \\( U_{2,2}^A \\) & \\dots & \\( U_{2,C_2}^A \\) \\\\ \\hline\n            \\vdots & \\vdots & \\( \\ddots \\) & \\vdots \\\\ \\hline\n            \\( U_{C_1,1}^A \\) & \\( U_{C_1,2}^A \\) & \\dots & \\( U_{C_1,C_2}^A \\) \\\\ \\hline\n        \\end{tabular}\n    \\end{minipage}%\n    \\begin{minipage}{.5\\linewidth}\n        B = \n        \\begin{tabular}{|l|l|l|l|}\n            \\hline\n            \\( U_{1,1}^B \\) & \\( U_{1,2}^B \\) & \\dots & \\( U_{1,C_2}^B \\) \\\\ \\hline\n            \\( U_{2,1}^B \\) & \\( U_{2,2}^B \\) & \\dots & \\( U_{2,C_2}^B \\) \\\\ \\hline\n            \\vdots & \\vdots & \\( \\ddots \\) & \\vdots \\\\ \\hline\n            \\( U_{C_1,1}^B \\) & \\( U_{C_1,2}^B \\) & \\dots & \\( U_{C_1,C_2}^B \\) \\\\ \\hline\n        \\end{tabular}\n    \\end{minipage}\n\\end{table}  \n", "meta": {"hexsha": "bf1b1eeae082557844878f5a362b00f62e14d0e2", "size": 7410, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/main/Methodology/Proper/main.tex", "max_stars_repo_name": "11michalis11/AmbulanceDecisionGame", "max_stars_repo_head_hexsha": "45164ba51da0417297f715e41716cb91facc120f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/main/Methodology/Proper/main.tex", "max_issues_repo_name": "11michalis11/AmbulanceDecisionGame", "max_issues_repo_head_hexsha": "45164ba51da0417297f715e41716cb91facc120f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 20, "max_issues_repo_issues_event_min_datetime": "2020-04-20T09:08:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T11:09:25.000Z", "max_forks_repo_path": "tex/main/Methodology/Proper/main.tex", "max_forks_repo_name": "11michalis11/AmbulanceDecisionGame", "max_forks_repo_head_hexsha": "45164ba51da0417297f715e41716cb91facc120f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.8461538462, "max_line_length": 95, "alphanum_fraction": 0.6221322537, "num_tokens": 2479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.929440403812707, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.722453896853766}}
{"text": "\n\\subsection{Addition of sine and cosine}\n\n\\subsubsection{Adding waves with same frequency}\n\nWe know that:\n\n\\(a\\sin(bx+c)=a\\sin(bx)\\cos(c)+a\\sin(c)\\cos(bx)\\)\n\nSo:\n\n\\(a\\sin(bx+c)+d\\sin(bx+e)=a\\sin(bx)\\cos(c)+a\\sin(c)\\cos(bx)+ d\\sin(bx)\\cos(e)+d\\sin(e)\\cos(bx)\\)\n\nWe know that:\n\n\\(\\sin(\\theta )=\\dfrac{e^{i\\theta }-e^{-i\\theta }}{2i}\\)\n\nSo:\n\n\\(a\\sin(bx+c)+d\\sin(bx+f)=a\\dfrac{e^{i(bx+c)}-e^{-i(bx+c)}}{2i}+d\\dfrac{e^{i(bx+f)}-e^{-i(bx+f)}}{2i}\\)\n\n\\(a\\sin(bx+c)+d\\sin(bx+f)=\\dfrac{a(e^{i(bx+c)}-e^{-i(bx+c)})+d(e^{i(bx+f)}-e^{-i(bx+f)})}{2i}\\)\n\n\\(a\\sin(bx+c)+d\\sin(bx+f)=\\dfrac{a(e^{ibx}e^{ic}-e^{-ibx}e^{-ic})+d(e^{ibx}e^{if}-e^{-ibx}e^{-if)})}{2i}\\)\n\n\\(a\\sin(bx+c)+d\\sin(bx+f)=\\dfrac{(e^{ibx}(ae^{ic}+de^{if})-e^{-ibx}(ae^{-c}+d^{-if})}{2i}\\)\n\n\\(a_i\\sin(b_ix+c_i)+a_j\\sin(b_jx+c_j)=a_i\\sin(b_ix+c_i)+a_j\\sin(b_ix+c_j)\\)\n\n\\(a_i\\sin(b_ix+c_i)+a_j\\sin(b_jx+c_j)=a_i\\sin(b_ix)\\cos(c_i)+a_i\\sin(c_i)\\cos(b_ix)+a_j\\sin(b_ix)\\cos(c_j)+a_j\\sin(c_j)\\cos(b_ix)\\)\n\n", "meta": {"hexsha": "3a502946bd537df9b611a79867562fb825311f51", "size": 953, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/trigonometry/01-04-trigIdentities.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/trigonometry/01-04-trigIdentities.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/trigonometry/01-04-trigIdentities.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.78125, "max_line_length": 131, "alphanum_fraction": 0.5634837356, "num_tokens": 481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.929440397949314, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.7224538922961514}}
{"text": "\\lab{Conjugate-Gradient}{Conjugate-Gradient}\n\\objective{Learn about the Conjugate-Gradient Algorithm and its Uses}\n\n\\section*{Descent Algorithms and the Conjugate-Gradient Method}\nThere are many possibilities for solving a linear system of equations, each method with its own set of pros and cons. In this lab, we\nwill explore the \\emph{Conjugate-Gradient algorithm}, which is a method for solving large systems of equations where other methods,\nsuch as Cholesky factorization and simple Gaussian elimination, are unsuitable. This algorithm, however, works equally well for\noptimizing convex quadratic functions, and it can even be extended to more general classes of optimization problems.\n\nThe type of linear system that Conjugate-Gradient can solve involves a matrix with special structure.\nGiven a symmetric positive-definite $n\\times n$ matrix $Q$ and an $n$-vector $b$, we wish to find the $n$-vector $x$ satisfying\n\\[\nQx = b.\n\\]\nA unique solution exists because positive-definiteness implies invertibility.\nFor our purposes here, it is useful to recast this problem as an equivalent optimization problem:\n\\[\n\\min_{x} f(x) := \\frac{1}{2}x^TQx - b^Tx + c.\n\\]\nNote that $\\nabla f(x) = Qx - b$, so that minimizing $f(x)$ is the same as solving\n\\[\n0 = \\nabla f(x) = Qx - b,\n\\]\nwhich is our original linear system.\n\nSo how do we go about minimizing the quadratic objective function $f$? Line Search methods belonging to the class called\n\\emph{descent algorithms} use the following strategy: start with an initial guess $x_0$, identify a direction from\nthis particular point along which the objective function decreases (called a \\emph{descent direction}), and perform a line search to\nfind a new point $x_1$ satisfying $f(x_1) < f(x_0)$. Continue iteratively to produce a sequence of points $\\{x_0, x_1, x_2, \\ldots \\}$\nthat (hopefully) converges to the true minimizer.\n\nOne obvious candidate for the descent direction from some point $x_i$ is simply\n$-\\nabla f(x_i)$, since this vector points in the direction of steepest decrease. This procedure is known as the Method of Steepest\nDescent. Steepest descent, however, can be very inefficient for certain problems: depending on the geometry\nof the objective function, the sequence of points can ``zig-zag\" back and forth without making appreciable progress toward the true\nminimizer. In contrast, the Conjugate-Gradient algorithm ensures that the true global minimizer is reached in at most $n$ steps. See\nFigure \\ref{basis:steepVsConj} for an illustration of this contrast.\nTo understand why this is the case and how the algorithm chooses each descent direction, we next discuss the idea of vector conjugacy.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{steepVsConj.pdf}\n\\caption{Paths traced by Steepest Descent (blue) and Conjugate-Gradient (green). Notice the\nzig-zagging nature of the Steepest Descent path, as opposed to the direct Conjugate-Gradient path,\nwhich finds the minimizer in 2 steps.}\n\\label{basis:steepVsConj}\n\\end{figure}\n\n\\section*{Conjugacy}\nConsider again our symmetric positive definite $n \\times n$ matrix $Q$. Two vectors $x, y \\in \\mathbb{R}^n$ are said to be \\emph{conjugate}\nwith respect to $Q$ if $x^TQy = 0$. A set of vectors $\\{x_0, x_1, \\ldots, x_m\\}$ is said to be conjugate if each pair of vectors are conjugate\nto each other. Note that if $Q = I$, then conjugacy is the same as orthogonality. Thus, the notion of conjugacy is in some ways a generalization\nof orthogonality. It turns out that a conjugate set of vectors is linearly independent, and a conjugate basis--which can be constructed in a manner\nanalogous to the Gram-Schmidt orthogonalization process--can be used to diagonalize the matrix $Q$.\nThese are some of the theoretical reasons behind the effectiveness of the Conjugate-Gradient algorithm.\n%Take this section out? Add more to it?\n\n\\section*{The Algorithm}\nIf we are given a set of $n$ $Q$-conjugate vectors, we can simply choose these as our direction vectors and follow the basic descent algorithm.\nConvergence to the minimizer in at most $n$ steps is guaranteed because each iteration in the algorithm minimizes the objective function\nover an expanding affine subspace of dimension equal to the iteration number. Thus, at the $n$-th iteration, we have minimized the function over all of\n$\\mathbb{R}^n$.\n\nUnfortunately, we are not often given a set of conjugate vectors in advance, so how do we produce such a set? As mentioned earlier, a\nGram-Schmidt process could be used, and the set of eigenvectors also works, but both of these options are computationally expensive.\nBuilt into the algorithm is a way to determine a new conjugate direction based only on the previous direction, which means less memory usage and\nfaster computation. We have stated the details of Conjugate-Gradient in Algorithm \\ref{alg:conjgrad}.\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Conjugate-Gradient Algorithm}{}\n    \\State \\textrm{Choose initial point } $x_0$.\n    \\State $r_0 \\gets Qx_0 - b, d_0 \\gets -r_0, k \\gets 0$.\n    \\While{$r_k \\neq 0$}\n        \\State $\\alpha_k \\gets \\frac{r_k^Tr_k}{d_k^TQd_k}$.\n        \\State $x_{k+1} \\gets x_k + \\alpha_kd_k$.\n        \\State $r_{k+1} \\gets r_k + \\alpha_kQd_k$.\n        \\State $\\beta_{k+1} \\gets \\frac{r_{k+1}^Tr_{k+1}}{r_k^Tr_k}$.\n        \\State $d_{k+1} \\gets -r_{k+1} + \\beta_{k+1}d_k$.\n        \\State $k \\gets k+1$.\n    \\EndWhile\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Conjugate-Gradient Algorithm}\n\\label{alg:conjgrad}\n\\end{algorithm}\n\nNote that the points $x_i$ are the successive approximations to the minimizer, the vectors $d_i$ are the conjugate descent\ndirections, and the vectors $r_i$, which actually correspond to the steepest descent directions, are used in determining the conjugate directions.\nThe constants $\\alpha_i$ and $\\beta_i$ are used, respectively, in the line search, and in ensuring the $Q$-conjugacy of the descent directions.\n\nThe most numerically expensive computation in the algorithm is matrix-vector multiplication.\nNotice, however, that each iteration of the algorithm only requires one distinct matrix-vector multiplication, $Qd_k$. The rest of the\noperations are simply vector-vector multiplication, addition, and scalar multiplication. This makes for a very fast algorithm.\nAs noted earlier, Conjugate-Gradient is especially preferred when $Q$ is large and sparse. In this case, it may be possible to\ndesign a specialized sub-routine that performs matrix-vector multiplication by $Q$, by taking advantage of its sparseness. Doing so may\nlead to further speed-ups in the overall algorithm.\n\nWe now have an algorithm that can solve certain $n \\times n$ linear systems and minimize quadratic functions on $\\mathbb{R}^n$ in at most $n$ steps,\nand sometimes fewer, depending on the spectrum of the matrix $Q$. Further improvements on convergence may be obtained by preconditioning the matrix,\nbut we do not go into detail here.\n\n\\begin{problem}\nImplement the basic Conjugate-Gradient algorithm presented above.\nWrite a function \\li{conjugateGradient()} that accepts a vector $b$, an initial\nguess $x_0$, a symmetric positive-definite matrix $Q$, and a default tolerance of .0001 as inputs.\nContinue the algorithm until $\\|r_k\\|$ is less than the tolerance.\nReturn the solution $x^*$ to the linear system $Qx = b$.\n\\end{problem}\n\n\\section*{Example}\nWe now work through an example that demonstrates the usage of the Conjugate-Gradient algorithm. We assume that we have already written\nthe specified function in the above problem.\n\nWe must first generate a symmetric positive-definite matrix $Q$. This can be done by generating a random matrix $A$ and setting $Q = A^TA$.\nSo long as $A$ is of full column rank, the matrix $Q$ will be symmetric positive-definite.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import linalg as la\n\n>>> # initialize the desired dimension of the space\n>>> n = 10\n\n>>> # generate Q, b\n>>> A = np.random.random((n,n))\n>>> Q = A.T.dot(A)\n>>> b = np.random.random(n)\n\\end{lstlisting}\nAt this point, check to make sure that $Q$ is nonsingular by examining its determinant (use \\li{scipy.linalg.det()}).\nProvided that the determinant is nonzero, we proceed by writing a function that performs matrix-vector multiplication by $Q$ (we\nwill not take advantage of sparseness just now), randomly selecting a starting point (Conjugate-Gradient is not sensitive to the location of\nthe starting point), obtaining the answer using our function, and checking it with the answer obtained by \\li{scipy.linalg.solve()}.\n\\begin{lstlisting}\n>>> # generate random starting point\n>>> x0 = np.random.random(n)\n\n>>> # find the solution\n>>> x = conjugateGradient(b, x0, mult)\n\n>>> # compare to the answer obtained by SciPy\n>>> print np.allclose(x, la.solve(Q,b))\n\\end{lstlisting}\nThe output of the print statement should be \\li{True}.\n\nTime the performance of your algorithm and of \\li{scipy.linalg.solve()} on inputs of size 100.\n\n\\section*{Application: Least Squares and Linear Regression}\nThe Conjugate-Gradient method can be used to solve linear least squares problems, which are ubiquitous in applied science.\nRecall that a least squares problem can be formulated as an optimization problem:\n\\[\n\\min_x \\|Ax - b\\|_2,\n\\]\nwhere $A$ is an $m \\times n$ matrix with full column rank, $x \\in \\mathbb{R}^n$, and $b \\in \\mathbb{R}^m$. The solution can\nbe calculated analytically, and is given by\n\\[\nx^* = (A^TA)^{-1}A^Tb,\n\\]\nor in other words, the minimizer solves the linear system\n\\[\nA^TAx = A^Tb.\n\\]\nSince $A$ has full column rank, we know that $A^TA$ is an $n \\times n$ matrix of rank $n$, which means it is invertible. We can\ntherefore conclude that $A^TA$ is symmetric positive-definite, so we may use Conjugate-Gradient to solve the linear system\nand obtain the least squares solution.\n\nLinear least squares is the mathematical underpinning of linear regression, which is a very common technique in many scientific fields.\nIn a typical linear regression problem, we have a set of real-valued data points \\{$y_1,\\ldots, y_m\\}$, where each\n$y_i$ is paired with a corresponding set of predictor variables $\\{x_{i,1}, x_{i,2}, \\ldots, x_{i,n}\\}$ with $n < m$.\nThe linear regression model posits that\n\\[\ny_i = \\beta_0 + \\beta_1x_{i,1} + \\beta_2x_{i,2} + \\cdots + \\beta_nx_{i,n} + \\epsilon_i\n\\]\nfor $i = 1, 2, \\ldots, m$. The real numbers $\\beta_0,\\ldots,\\beta_n$ are known as the parameters of the model, and the\n$\\epsilon_i$ are independent normally-distributed error terms. Our task is to calculate the parameters that best fit the data.\nThis can be accomplished by posing the problem in terms of linear least squares: Define\n\\[\nb = [y_1, \\ldots, y_m]^T,\n\\]\n\\[\nA =\n\\begin{bmatrix}\n1 & x_{1,1} & x_{1,2} & \\cdots & x_{1,n}\\\\\n1 & x_{2,1} & x_{2,2} & \\cdots & x_{2,n}\\\\\n\\vdots & \\vdots & \\vdots & \\ddots & \\vdots\\\\\n1 & x_{m,1} & x_{m,2} & \\cdots & x_{m,n}\n\\end{bmatrix},\n\\]\nand\n\\[\nx = [\\beta_0, \\beta_1,\\ldots, \\beta_n]^T.\n\\]\nNow use Conjugate-Gradient to solve the system\n\\[\nA^TAx = A^Tb.\n\\]\nThe solution $x^* = [\\beta_0^*, \\beta_1^*, \\ldots, \\beta_n^*]^T$ gives the parameters that best fit the data.\nThese values can be understood as defining the hyperplane that best fits the data. See Figure \\ref{fig:linregression}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{linregression.pdf}\n\\caption{Solving the Linear Regression problem results in a best-fit hyperplane.}\n\\label{fig:linregression}\n\\end{figure}\n\n\\begin{problem}\nUsing your Conjugate-Gradient function, solve the linear regression problem specified by the data contained in the file\n\\texttt{linregression.txt}. This is a whitespace-delimited text file formatted so that the $i$-th row consists of\n$y_i, x_{i,1}, \\ldots, x_{i,n}$. Use the function \\li{numpy.loadtxt()} to load in the data. Report your solution.\n\\end{problem}\n\n\\section*{Non-linear Conjugate-Gradient Algorithms}\nThe algorithm presented above is only valid for certain linear systems and quadratic functions, but the basic strategy may be adapted\nto minimize more general convex or non-linear functions. There are multiple ways to modify the algorithm, and they all involve getting\nrid of $Q$, since there is no such $Q$ for non-quadratic functions. Generally speaking, we need to find new formulas for $\\alpha_k$,\n$r_k$, and $\\beta_k$.\n\nThe scalar $\\alpha_k$ is simply the result of performing a line-search in the given direction $d_k$, so we may define\n\\[\n\\alpha_k = \\underset{x}{\\arg\\min}f(x_k + \\alpha d_k).\n\\]\nThe vector $r_k$ in the original algorithm was really just the gradient of the objective\nfunction, and so we may define \n\\[\nr_k = \\nabla f(x_k).\n\\]\nThere are various ways to define the constants $\\beta_k$ in this more general setting, and the\nright choice will depend on the nature of the objective function. A well-known formula, due to Fletcher and Reeves, is\n\\[\n\\beta_{k+1} = \\frac{\\nabla f_{k+1}^T \\nabla f_{k+1}}{\\nabla f_{k}^T \\nabla f_{k}}.\n\\]\n\nMaking these adjustments is not difficult, but we will opt instead to use built-in functions in Python. In particular,\nthe SciPy module \\li{scipy.optimize} provides a function \\li{fmin_cg()}, which uses a non-linear Conjugate-Gradient method\nto minimize general functions. Using this function is easy -- we only need to pass to it the objective function and an\ninitial guess.\n\n\\section*{Application: Logistic Regression}\nLogistic regression is an important technique in statistical analysis and classification. The core problem in\nlogistic regression involves an optimization that we can tackle using nonlinear Conjugate-Gradient.\n\nAs in linear regression, we have a set of data points $y_i$ together with predictor variables\n$x_{i,1}, x_{i,2}, \\ldots, x_{i,n}$ for $i = 1, \\ldots, m$. However, the $y_i$ are binary data points --\nthat is, they are either $0$ or $1$. Furthermore, instead of having a linear relationship between the\ndata points and the response variables, we assume the following probabilistic relationship:\n\\[\n\\mathbb{P}(y_i = 1 \\, | \\, x_{i,1}, \\ldots, x_{i,n}) = p_i,\n\\]\nwhere\n\\[\np_i = \\frac{1}{1+\\exp(-(\\beta_0 + \\beta_1x_{i,1} + \\cdots + \\beta_nx_{i,n}))}.\n\\]\nThe parameters of the model are the real numbers $\\beta_0, \\beta_1,\\ldots, \\beta_n$.\nObserve that we have $p_i \\in (0, 1)$ regardless of the values of the predictor variables and parameters.\n\nThe probability of observing the data points $y_i$ under this model, assuming they are independent, is given by\nthe expression\n\\[\n\\prod_{i=1}^m p_i^{y_i}(1-p_i)^{1-y_i}.\n\\]\nWe seek to choose the parameters $\\beta_0, \\ldots, \\beta_n$ that maximize this probability.\nTo this end, define the \\emph{likelihood function} $L:\\mathbb{R}^{n+1} \\rightarrow \\mathbb{R}$ by\n\\[\nL(\\beta_0, \\ldots, \\beta_n) = \\prod_{i=1}^m p_i^{y_i}(1-p_i)^{1-y_i}.\n\\]\nWe can now state our core problem as follows:\n\\[\n\\max_{(\\beta_0,\\ldots,\\beta_n)}L(\\beta_0, \\ldots, \\beta_n).\n\\]\n\nMaximizing this function can be problematic for numerical reasons. By taking the logarithm of the likelihood,\nwe have a more suitable objective function whose maximizer agrees with that of the original likelihood function,\nsince the logarithm is strictly monotone increasing. Thus, we define the \\emph{log-likelihood function}\n$l : \\mathbb{R}^{n+1} \\rightarrow \\mathbb{R}$ by $l = \\log \\circ L$.\n\nFinally, we multiply by $-1$ to turn our problem into minimization. The final statement of the problem is:\n\\[\n\\min_{(\\beta_0,\\ldots,\\beta_n)}-l(\\beta_0, \\ldots, \\beta_n).\n\\]\nA few lines of calculation reveal that\n\\begin{align*}\nl(\\beta_0,\\ldots,\\beta_n) = &-\\sum_{i=1}^{m}\\log(1+\\exp(-(\\beta_0 + \\beta_1x_{i,1} + \\cdots +\\beta_nx_{i,n}))) +\\\\\n &\\sum_{i=1}^m y_i(\\beta_0 + \\beta_1x_{i,1} + \\cdots + \\beta_nx_{i,n}).\n\\end{align*}\nThe values for the parameters that we obtain are known collectively as the \\emph{maximum likelihood estimate}.\n\nLet's work through a simple example. We will deal with just one predictor variable, and therefore two parameters.\nThe data is given in Table \\ref{table:data}.\nThis is obviously just toy data with no meaning, but one can think of the $y_i$ data points as indicating, for example, the\npresence of absence of a particular disease in subject $i$, with $x_i$ being the subject's weight, or age, or something\nof the sort.\n\n\\begin{table}\n  \\caption{Data for Logistic Regression Example}\n  \\centering\n  \\begin{tabular}{c c}\n    \\hline\\hline\n    $y$ & $x$\\\\\n    \\hline\n    0 & 1 \\\\\n    0 & 2 \\\\\n    0 & 3 \\\\\n    0 & 4 \\\\\n    1 & 5 \\\\\n    0 & 6 \\\\\n    1 & 7 \\\\\n    0 & 8 \\\\\n    1 & 9 \\\\\n    1 & 10\\\\\n    \\hline\n  \\end{tabular}\n  \\label{table:data}\n\\end{table}\n\nIn the code below we initialize our data.\n\\begin{lstlisting}\n>>> y = np.array([0, 0, 0, 0, 1, 0, 1, 0, 1, 1])\n>>> x = np.ones((10, 2))\n>>> x[:,1] = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])\n\\end{lstlisting}\nAlthough we have just one predictor variable, we initialized \\li{x} with two columns,\nthe first of which consists entirely of ones, and the second of which contains the values of the\npredictor variable. This extra column of ones corresponds to the parameter $\\beta_0$, which, as you\nwill note, is not multiplied by any of the predictor variables in the log-likelihood function.\n\nWe next need to write a Python function that returns the value of our objective function for any value of the parameters,\n$(\\beta_0, \\beta_1)$.\n\\begin{lstlisting}\n>>> def objective(b):\n...     #Return -1*l(b[0], b[1]), where l is the log likelihood.\n...    return (np.log(1+np.exp(x.dot(b))) - y*(x.dot(b))).sum()\n\\end{lstlisting}\n\nFinally, we minimize the objective function using \\li{fmin_cg()}.\n\\begin{lstlisting}\n>>> guess = np.array([1., 1.])\n>>> b = fmin_cg(objective, guess)\nOptimization terminated successfully.\n         Current function value: 4.310122\n         Iterations: 13\n         Function evaluations: 128\n         Gradient evaluations: 32\n>>> print b\n[-4.35776886  0.66220658]\n\\end{lstlisting}\n\nWe can visualize our answer by plotting the data together with the function\n\\[\n\\phi(x) = \\frac{1}{1 + \\exp(-\\beta_0 - \\beta_1x)},\n\\]\nusing the values $\\beta_0, \\beta_1$ that we obtained from the minimization.\n\\begin{lstlisting}\n>>> dom = np.linspace(0, 11, 100)\n>>> plt.plot(x, y, 'o')\n>>> plt.plot(dom, 1./(1+np.exp(-b[0]-b[1]*dom)))\n>>> plt.show()\n\\end{lstlisting}\n\nUsing this procedure, we obtain the plot in Figure \\ref{conj:logreg}. Note that the graph of $\\phi$, known as a \\emph{sigmoidal curve},\ngives the probability of $y$ taking the value $1$ at a particular value of $x$. Observe that as $x$ increases,\nthis probability approaches $1$. This is reflected in the data.\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{logreg.pdf}\n\\caption{Data from the logistic regression example together with the calculated\nsigmoidal curve.}\n\\label{conj:logreg}\n\\end{figure}\n\n\\begin{problem}\nFollowing along with the example given above, find the maximum likelihood estimate of the parameters for\nthe logistic regression data in the file \\texttt{logregression.txt}. This is a whitespace-delimited text file\nformatted so that the $i$-th row consists of $y_i, x_{i,1}, x_{i,2}, x_{i,3}.$ Since there are three\npredictor variables, there are four parameters in the model. Report the calculated values.\n\nYou should be able to use much of the code above unchanged. In particular, the function \\li{objective()} does\nnot need any changes. You simply need to set your variables \\li{y} and \\li{x} appropriately, and\nchoose a new initial guess (an array of length four). Note that \\li{x} should be an $m \\times 4$ array whose first\ncolumn consists entirely of ones, whose second column contains the values in the second column of the data file,\nand so forth.\n\\end{problem}\n\nLogistic regression can become a bit more tricky when some of the predictor variables take on binary or categorical\nvalues. In such situations, the data requires a bit of pre-processing before running the minimization.\n\nThe values of the parameters that we obtain can be useful in analyzing relationships\nbetween the predictor variables and the $y_i$ data points. They can also be used to classify or predict values of new\ndata points.\n\n%should I give the Polak-Ribi\\`{e}, Fletcher-Reeves, and Hestenes-Stiefel formulas? Maybe in the exercises? Should I\n%include a discussion of when each choice is appropriate?\n\n\n\n\n", "meta": {"hexsha": "3e9c446d51decdb780c2b633e3c289a7e688aaef", "size": 20211, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol2B/ConjugateGradient/ConjugateGradient.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol2B/ConjugateGradient/ConjugateGradient.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol2B/ConjugateGradient/ConjugateGradient.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 51.1670886076, "max_line_length": 151, "alphanum_fraction": 0.7398941171, "num_tokens": 5642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7224509881429211}}
{"text": "\\subsection{Hyperbolic Paraboloids}\r\n\\noindent\r\nHyperbolic paraboloids have the form\r\n\\begin{equation*}\r\n\tz = x^2 - y^2\r\n\\end{equation*} \r\nThey are not radially symmetric and look like a saddle or Pringle's chip.\r\n\r\n[INSERT IMAGE]", "meta": {"hexsha": "8de810d1242159a9fcbaf8fd98b048a8a552c8fa", "size": 230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/hyperbolicParaboloids.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/hyperbolicParaboloids.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/hyperbolicParaboloids.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.5555555556, "max_line_length": 74, "alphanum_fraction": 0.7391304348, "num_tokens": 70, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.722442981460924}}
{"text": "\\lab{Plotting With matplotlib and Mayavi}{Plotting}\n\\objective{Introduce some of the basic plotting functions available in matplotlib and Mayavi.}\n\\label{lab:Matplotlib_and_Mayavi}\n\n\\section*{2-D plotting with \\li{matplotlib}}\nThe Python library \\li{matplotlib} will be our primary tool for creating 2-D graphs in this text. This lab introduces the basic features of \\li{matplotlib}; for more information, visit the documentation at \\url{http://matplotlib.org}.\n\nTo begin, import \\li{pyplot} from \\li{matplotlib}.\n\\begin{lstlisting}\nfrom matplotlib import pyplot as plt\n\\end{lstlisting}\n\n\\subsection*{Line plots}\nThe function call \\li{plt.plot(x, y)} takes two 1-D NumPy arrays, \\li{x} and \\li{y}, and plots the points \\li{(x[i], y[i])}, connecting them with straight lines.\n\nFor example, this code plots $y=e^x$ on the interval $[-2,3]$. The output is in Figure \\ref{fig:exp_plot}.\n\\begin{lstlisting}\nimport numpy as np\n# Create an array of 501 evenly spaced points in [-2,3].\nx = np.linspace(-2, 3, 501)\ny = np.exp(x)\nplt.plot(x, y)\nplt.show()\n\\end{lstlisting}\n\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}[t]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{exp_plot.pdf}\n\\caption{A graph of $e^x$.}\n\\label{fig:exp_plot}\n\\end{subfigure}\n\\begin{subfigure}[t]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{statemachine.pdf}\n\\caption{A graph of ten lines with randomly generated $y$ values.}\n\\label{fig:statemachine}\n\\end{subfigure}\n\\caption{Plots created with \\li{plt.plot()}.}\n\\label{fig:lineplots}\n\\end{figure}\n\n\nAll calls to \\li{plt} functions will modify the same figure until you call \\li{plt.show()}. \nThe function \\li{plt.show()} displays the current figure and resets the system, so that the next call to a \\li{plt} function modifies a new figure. \n\nWe can take advantage of this system to plot multiple lines on the same axes.\nFor example, the following code plots ten lines, each with random values at integers from 1 to 10. \nThe output is in Figure \\ref{fig:statemachine}.\n\\begin{lstlisting}\nx = np.linspace(1, 10, 10)\n\n# Create a 10x10 array of uniformly distributed values in [0,1).\ny = np.random.rand(10, 10)\n\n# Plot each row of y\nfor row in y:\n    plt.plot(x, row)\nplt.show()\n\\end{lstlisting}\n\nAlternatively, we can produce the same graph with a single call to \\li{plt.plot()}.\n\\begin{lstlisting}\nplt.plot(x, y[0], x, y[1], x, y[2], x, y[3], x, y[4], x, y[5], x, y[6], x, y[7], x, y[8], x, y[9])\nplt.show()\n\\end{lstlisting}\n\n\n\n\\begin{comment}\n\\begin{problem} Plot the function $\\sin(x)$ from $0$ to $2\\pi$ with a red dashed line.\nThen plot the function $\\cos(x)$ on the same domain with a blue dotted line.\nImplement both with a single call to the \\li{plot()} function.\nInformation on how to do this can be found in Appendix \\ref{mpltables}.\n\\end{problem}\n\\end{comment}\n\n\\begin{comment}\nThere are also many functions that we may use to set different values in\nthe plotting environment. A few examples are shown in Table\n\\ref{mpl:useful_functions}.\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|l|p{6cm}|p{4cm}|}\n\n    \\hline\n\n    Function & Description & Usage\\\\\n\n    \\hline\n\n    \\li{annotate} & adds a commentary at a given point on the plot &\n    annotate('text',(x,y))\\\\\n\n    \\li{arrow} & draws an arrow from a given point on the plot &\n    arrow(x,y,dx,dy)\\\\\n\n    \\li{axhline} & draws a horizontal line at y from xmin to xmax &\n    axhline(y=0, xmin=0, xmax=1)\\\\\n\n    \\li{axvline} & draws a vertical line at x from ymin to ymax &\n    axvline(x=0, ymin=0, ymax=1)\\\\\n\n    \\li{axhspan} & draws a rectangle from xmin to xmax and ymin to ymax,\n    if no xmin and xmax are given it goes across the plot &\n    axhspan(ymin, ymax, xmin=0, xmax=1)\\\\\n\n    \\li{axvspan} & draws a rectangle from ymin to ymax and xmin to xmax,\n    if no ymin and ymax are given it goes across the entire plot &\n    axvspan(xmin, xmax, ymin=0, ymin=1)\\\\\n\n    \\li{figlegend} & place a legend in the plot & figlegend(handles,\n    labels, loc)\\\\\n\n    \\li{grid} & add gridlines & grid()\\\\\n\n    \\li{text} & add text at a given position on the plot &\n    text(x,y,'text')\\\\\n\n    \\li{title} & add a title to the plot & title('text')\\\\\n\n    \\li{xlim} & set the x limits, returns current limits if no arguments\n    are given & xlim(xmin,xmax)\\\\\n\n    \\li{ylim} & set the y limits, returns current limits if no arguments\n    are given & ylim(ymin,ymax)\\\\\n\n    \\li{xticks} & set the location of the tick marks on the x axis,\n    returns current locations if no arguments are given & xticks(x)\\\\\n\n    \\li{yticks} & set the location of the tick marks on the y axis,\n    returns current locations if no arguments are given & yticks(y)\\\\\n\n    \\li{xlabel} & add a label to the x axis & xlabel('text')\\\\\n\n    \\li{ylabel} & add a label to the y axis & ylabel('text')\\\\\n\n    \\hline\n\n    \\end{tabular}\n    \\end{center}\n    \\caption{Some Functions to Set Plotting Options}\n    \\label{mpl:useful_functions}\n    \\end{table}\n\n\t\\end{comment}\n\t\n\\begin{problem}\\label{prob:lineplot}\nPlot the curve $1/(x-1)$ on [-2,6].\nDo the following to your plot:\n\n\\begin{enumerate}\n\\item The function \\li{plt.plot()} will make the curve look continuous at $x=1$. \nPlot the two sides of the curve separately (still with a single call to \\li{plt.plot()}) so that the graph looks discontinuous at $x=1$.\n\\item Plot the curve with a line that is magenta, dashed, and thick (see Appendix \\ref{mpltables}).\n\\item Change the range of the $y$-axis to be $[-6, 6]$.\n\\end{enumerate}\nYour final plot should look like Figure \\ref{fig:problem2}.\n\n\\begin{figure}[H]\n\\includegraphics[width=.7\\textwidth]{soln2.pdf}\n\\caption{Correct output for Problem \\ref{prob:lineplot}.}\n\\label{fig:problem2}\n\\end{figure}\n\\end{problem}\n\n\\begin{comment}\n\\begin{problem} Plot the curve $\\sin(x)\\frac{1}{x+1}$ from $0$ to $10$.\n\nUse blue shading under the curve when it is positive and red when it is negative (you may want to consider using the \\li{fill_between} command.\nMake the line dotted.\nLabel the x-axis ``x-axis'', the y-axis ``y-axis'',and the plot ``My Plot''.\nEnable the grid lines.\n\nFinally, use the \\li{scatter} command to include a scatter plot of half of the value of the function at each of its maxima and minima in the range.\nDisplay these points as upward-pointing triangles.\nDon't forget to make sure the x limits of the plot are still 0 and 10.\n\n\\emph{Helpful Hint}: Since you are working with arrays of discrete values, you will want to find the index values where your $x$ and $y$ values are closest to the actual maxima and minima. As you work, consider the following:\n\\begin{itemize}\n\\item How would you manually find maxima and minima of a function?\n\\item How could you do something similar with your $x$ and $y$ arrays?\n\\end{itemize}\nYour plot should look like the figure below.\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{soln3.pdf}\n\\label{fig:problem3}\n\\end{figure}\n\\end{problem}\n\\end{comment}\n\n\n\n\n\\subsection*{Heatmaps}\nA function from $\\mathbb{R}^2$ to $\\mathbb{R}$ is usually plotted as a surface in $\\mathbb{R}^3$.\nA \\emph{heatmap} visualizes such a function in only two dimensions by assigning the output of the function to a color (instead of a height).\nFor example, Figure \\ref{fig:pcmexample} uses a heatmap to graph $f(x,y) = \\sin(x)\\sin(y)$ on $[-6,6] \\times [-6,6]$.\n\nThe plot in Figure \\ref{fig:pcmexample} was created with the function \\li{plt.pcolormesh()}.\nTo draw Figure \\ref{fig:pcmexample}, we must first create a grid of points at which to evaluate $f$.\nWe do this with the function \\li{np.meshgrid()}, which is explained in Figure \\ref{fig:meshgrid}.\n\n\\begin{figure}\n\\begin{tikzpicture}[>=stealth', shorten <= .1cm,shorten >=.1cm, dot/.style=\n\t{circle,fill=black,minimum size=3pt,inner sep=0pt, outer sep=-1pt} ]\n\n\\foreach \\x/\\y in {0/0, 0/2, 0/4, 2/0, 2/2, 2/4, 4/0, 4/2, 4/4} \n\t\\node[draw, dot]at(\\x,\\y){};\n\\foreach \\x/\\y in {0/0, 0/1, 0/2, 1/0, 1/1, 1/2, 2/0, 2/1, 2/2} \n\t\\node[draw=none]at(\\x*2-.5, \\y*2+.3){(\\x,\\y)};\n\n\\foreach \\x/\\y in {0/0, 0/1, 0/2, 1/0, 1/1, 1/2, 2/0, 2/1, 2/2} \n\t\\node[draw=none]at(\\x*.75+7, \\y*.75+.1){\\y};\n\\foreach \\x/\\y in {0/0, 0/1, 0/2, 1/0, 1/1, 1/2, 2/0, 2/1, 2/2} \n\t\\node[draw=none]at(\\x*.75+7, \\y*-.75+3.9){\\x};\n\n\\draw[-, thick](6.7,-.25)--(6.7,1.95); \n\\draw[-, thick](8.8,-.25)--(8.8,1.95);\n\\draw[-, thick](6.7,2.05)--(6.7,4.25);\n\\draw[-, thick](8.8,2.05)--(8.8,4.25);\n\\draw[-, thick](8.8,4.14)--(8.7,4.14);\n\\draw[-, thick](8.8,2.16)--(8.7,2.16);\n\\draw[-, thick](6.7,4.14)--(6.8,4.14);\n\\draw[-, thick](6.7,2.16)--(6.8,2.16);\n\\draw[-, thick](8.8,1.84)--(8.7,1.84);\n\\draw[-, thick](8.8,-.135)--(8.7,-.135);\n\\draw[-, thick](6.8,1.84)--(6.7,1.84);\n\\draw[-, thick](6.8,-.135)--(6.7,-.135);\n\n\\node[draw=none](X)at(6.3,.9){\\texttt{Y}=};\n\\node[draw=none](y)at(6.3,3.15){\\texttt{X}=};\n\n\\node[draw=none](point1)at(-.3, -.4){\\texttt{x}=\\big[0,};\n\\node[draw=none, node distance=2.35cm](point2)\n\t[right of=point1]{1,};\n\\node[draw=none, node distance=2cm](point3)\n\t[right of=point2]{2\\big]};\n\\node[draw=none, rotate=270](point4)at(4.4,4.25)\n\t{\\texttt{y}=\\big[0,};\n\\node[draw=none, rotate=270, node distance=2.35cm](point5)\n\t[right of=point4]{1,};\n\\node[draw=none, rotate=270, node distance=2cm](point6)\n\t[right of=point5]{2\\big]};\n\n\n\n\\end{tikzpicture}\n\n\\caption{This figure illustrates the function call \\li{np.meshgrid(x, y)}, which returns the arrays \\li{X} and \\li{Y}. \nThe returned arrays give the $x$- and $y$-coordinates of the points in the grid formed by \\li{x} and \\li{y}.}\n\\label{fig:meshgrid}\n\\end{figure}\n\n\\begin{lstlisting}\nx = np.linspace(-6, 6, 401)\ny = np.linspace(-6, 6, 401)\nX, Y = np.meshgrid(x, y)\n\\end{lstlisting}\nThe arrays $X$ and $Y$ satisfy \\li{(X[i,j], Y[i,j]) = (x[i],y[j])}.\n\nNow we can evaluate $f(x,y)$ at each point in the grid and plot the result.\n\\begin{lstlisting}\nf = np.sin(X) * np.sin(Y)\nplt.pcolormesh(X, Y, f)\nplt.pcolorbar()    # Show scale\nplt.show()\n\\end{lstlisting}\nThis plot is shown in Figure \\ref{fig:pcmexample}\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{sinxsiny.png}\n\\caption{A heatmap of $f(x,y)=\\sin\\left(x\\right)\\times\\sin\\left(y\\right)$ drawn by \\li{plt.pcolormesh()}.}\n\\label{fig:pcmexample}\n\\end{figure}\n\n\\begin{comment}\n\\begin{problem} Use plt.pcolormesh to plot the absolute value of the function $x^3 +2x^2 -x +3$ on the complex plane with 0 $\\leq$ \\li{x} $\\leq$ 2 and 0 $\\leq$ \\li{y} $\\leq$ 2.\n\\emph{Helpful Hint}: First create your domain arrays, then convert these to a single array of complex variables to evaluate the function.\n\nYour plot should look like Figure \\ref{fig:pcolormesh}.\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{pcolor2.png}\n\\caption{Another example of a colorplot.}\n\\label{fig:pcolormesh}\n\\end{figure}\n\\end{problem}\n\\end{comment}\n\n\\begin{problem}\\label{prob:heatmap}\n\\leavevmode\n\\begin{enumerate}\n\\item Plot the function $f(x,y) = \\sin(x)\\sin(y)/(xy)$ on $[-2\\pi,2\\pi] \\times [-2\\pi,2\\pi]$. \nInclude the scale bar in your plot.\n\\item Change the color scheme of your plot with the keyword argument \\li{cmap='seismic'} in the call to \\li{plt.pcolormesh()}. \nYou can see a list of all possible color schemes at \\url{http://matplotlib.org/examples/color/colormaps_reference.html}.\n\\item Change the limits on the $x$- and $y$-axes so that the plot is only over the domain $[-2\\pi,2\\pi] \\times [-2\\pi,2\\pi]$.\n\\item Fix the aspect ratio of your plot so that it is a square using the line \\li{plt.gca().set_aspect('equal')}.\n\\end{enumerate}\nYour finished plot should look like Figure \\ref{fig:heatmapProb}.\n\n\\begin{figure}[H]\n\\includegraphics[width=.7\\textwidth]{pcolor2.png}\n\\caption{Correct output for Problem \\ref{prob:heatmap}.}\n\\label{fig:heatmapProb}\n\\end{figure}\n\\end{problem}\n\n\\begin{comment}\n\nMatplotlib can also be used for 3D plotting. The following is an example\nof how to use matplotlib to plot the function $z=\\sin(x)\\sin(y)$ with\nboth x and y ranging from -6 to 6. The resulting plot is shown in Figure\n\\ref{mpl:3dplot}. If you change the number of sample points used you\nwill notice that graphs look much nicer with large numbers of sample\npoints, but it will also take much longer for your computer to render\nthe image.\n\n\\begin{lstlisting} from mpl_toolkits.mplot3d import Axes3D from\nmatplotlib import pyplot as plt import numpy as np fig = plt.figure() ax\n= fig.gca(projection='3d') x = np.linspace(-6, 6, 301) y =\nnp.linspace(-6, 6, 301) X, Y = np.meshgrid(x, y) Z = np.sin(X) *\nnp.sin(Y) ax.plot_surface(X, Y, Z) plt.show() \\end{lstlisting}\n\n\\begin{figure} \\includegraphics[width=\\textwidth]{3dplot.pdf} \\caption{A\n3D plot of $\\sin\\left(x\\right)\\times\\sin\\left(y\\right)$.}\n\\label{mpl:3dplot} \\end{figure}\n\n\\begin{problem} Plot the function \\begin{equation*}\n\\frac{\\cos\\left(\\sqrt{x^2 + y^2}\\right)}{\\frac{x^2 + y^2}{10} + 1}\n\\end{equation*} on $[-10, 10] \\times [-10, 10]$. \\end{problem}\n\n\nMatplotlib also allows us to make interactive graphs as follows:\n\n% This example is largely based on one of the examples in the matplotlib\n% docs. I have simplified it and changed the way the libraries are\n% imported, but we could do a citation anyway.\n%\n\\begin{lstlisting} import numpy as np from matplotlib import pyplot as\nplt from matplotlib import widgets as wg ax = plt.subplot(111)\nplt.subplots_adjust(bottom=.25) t = np.arange(0., 1., .001) a0 = 5. f0 =\n3. s = a0 * np.sin(2 * np.pi * f0 * t) l = plt.plot(t, s)[0]\nplt.axis([0, 1, -10, 10]) axfreq = plt.axes([.25, .05, .65, .03]) axamp\n= plt.axes([.25, .1, .65, .03]) sfreq = wg.Slider(axfreq, 'Freq', .1,\n30., valinit=f0) samp = wg.Slider(axamp, 'Amp', .1, 10., valinit=a0) def\nupdate(val): amp = samp.val freq = sfreq.val l.set_ydata(amp * np.sin(2\n* np.pi * freq * t)) plt.draw() sfreq.on_changed(update)\nsamp.on_changed(update) plt.show() \\end{lstlisting} The resulting plot\nis shown in Figure \\ref{mpl:interact}.\n\n\\begin{figure} \\includegraphics[width=\\textwidth]{interact.pdf}\n\\caption{A snapshot of an interactive plot made using Matplotlib.}\n\\label{mpl:interact} \\end{figure}\n\n\\begin{problem} Modify the code above to add a third slider to\nmanipulate the phase of the wave shown. Have it range from 0 to $2\\pi$\nand set the default value to zero. \\end{problem}\n\n\\end{comment}\n\n\\subsection*{Other plots}\nA \\emph{histogram} is a way to visualize a 1-D data set, or list of values. \nA histogram is created by dividing up the range of the values into a finite number of intervals, or \\emph{bins}.\nThen, the number of values in each bin is added up.\nGraphically, these totals are represented by bars whose length is equal to the number of values in the bin.\n\nFor example, suppose we randomly choose 20 integers between 1 and 10.\nThis code creates a histogram depicting how many of each number we chose.\nIts output is in Figure \\ref{fig:histogram}.\n\n\\begin{lstlisting}\nx = np.random.randint(1, 11, 20)\nplt.hist(x, bins=10, range=[.5, 10.5])\nplt.show()\n\\end{lstlisting}\n\nIn this example our data set \\li{x} consists of only integer values.\nWe created 10 bins in the range [.5, 10.5] so that each bin contains exactly one integer.\n\nThe function \\li{plt.hist()} also returns some arrays, the first of which is a list of the total number of values in each bin.\n\nWe could also use a \\emph{scatter plot} to visualize the random integers \\li{x} that we generated in the previous example. \nThe \\li{matplotlib} function call \\li{plt.scatter(x,y)} draws a scatter plot from two 1-D arrays \\li{x} and \\li{y} by plotting the points \\li{(x[i], y[i])}.\nAs an example, the code below produces Figure \\ref{fig:scatter}.\n\n\\begin{lstlisting}\nt = np.linspace(1,20,20)\n# The argument 's' specifies the marker size\nplt.scatter(t, x, s=100)\nplt.show()\n\\end{lstlisting}\n\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}[t]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{histogram.pdf}\n\\caption{A histogram.}\n\\label{fig:histogram}\n\\end{subfigure}\n\\begin{subfigure}[t]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{scatter.pdf}\n\\caption{A scatter plot.}\n\\label{fig:scatter}\n\\end{subfigure}\n\\caption{A scatter plot produced with \\li{plt.scatter()} and a histogram produced with \\li{plt.hist()}.}\n\\label{fig:otherplots}\n\\end{figure}\n\n\n\\subsection*{Subplots}\n\\emph{Subplots} are nonoverlapping plots arranged in a grid within a single figure (see Figure \\ref{fig:subplots}).\nIn \\li{matplotlib}, specify which subplot you wish to modify with with command \\li{plt.subplot(numrows, numcols, fignum)}.\nHere, \\li{numrows} is the number of rows of subplots in the figure, \\li{numcols} is the number of columns of subplots in the figure, and \\li{fignum} is the index of the subplot you wish to modify.\nThis index starts at 1 and increments across rows first.\n\nThe following code draws Figure \\ref{fig:subplots}.\n\\begin{lstlisting}\nx = np.linspace(-np.pi, np.pi, 400)\ny1 = np.sin(x)\ny2 = np.cos(x)\n\n# Draw the first subplot\nplt.subplot(2, 1, 1)\nplt.plot(x, y1)\n\n# Draw the second subplot\nplt.subplot(2, 1, 2)\nplt.plot(x, y2)\n\nplt.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{subplots.pdf}\n\\caption{The graphs of $\\sin(x)$ and $\\cos(x)$ as subplots in a single figure.}\n\\label{fig:subplots}\n\\end{figure}\n\n\\begin{problem}\\label{prob:subplot}\nFollow these steps to generate a plot similar to that in Figure \\ref{fig:subplotProb}.\n\\begin{enumerate}\n\\item Generate 50 random numbers in the interval $[0,1)$ with the function \\li{np.random.rand()}.\n\\item Create a plot with two subplots. \nIn the first subplot, draw a histogram of your data with 5 equally-sized bins.\n\\item In the second subplot, \n\\begin{enumerate}\n\\item Draw a scatter plot of your data. \nUse the integers 1-50 for the $x$-coordinates and use your data for the $y$-coordinates.\n\\item Plot a red horizontal line whose height is equal to the mean of your data.\n\\end{enumerate}\n\\end{enumerate}\n\n\\begin{figure}[H]\n\\includegraphics[width=.7\\textwidth]{subplotProb.pdf}\n\\caption{Correct output for Problem \\ref{prob:subplot}.}\n\\label{fig:subplotProb}\n\\end{figure}\n\n\\end{problem}\n\n\n\\begin{comment}\n\\begin{problem}\nMake a plot with 4 subplots.\nIn the subplots place graphs of $e^x$, $sin(x)$, $cos(x)$, and $x^2$.\nPlot each graph over the interval $(-\\pi,\\pi)$.\nTitle each graph accordingly and title the entire figure ``My Different Plots.\"\n\\end{problem}\n\\end{comment}\n\n\\begin{comment}\n%Table \\ref{mpl:basics}\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|l|p{7cm}|p{3cm}|}\n\n    \\hline\n\n    Function & Description & Usage\\\\\n\n    \\hline\n\n    \\li{bar} & makes a bar graph & bar(left,height)\\\\\n\n    \\li{barh} & makes a horizontal bar graph & barh(bottom,width)\\\\\n\n    \\li{fill} & plots lines with shading under the curve & fill(x,y)\\\\\n\n    \\li{fill\\_between} & plots lines with shading between two given y\n    values & fill\\_ between(x,y1, y2=0)\\\\\n\n    \\li{hist} & plots a histogram from data & hist(data)\\\\\n\n    \\li{pie} & make a pie chart & pie(x)\\\\\n\n    \\li{plot} & plots lines and data on standard axes & plot(x,y)\\\\\n\n    \\li{polar} & plots lines and data on polar axes & polar(theta,r)\\\\\n\n    \\li{loglog} & plots lines and data on logarithmic x and y axes &\n    loglog(x,y)\\\\\n\n    \\li{scatter} & plots data, has more options for scatter plots than\n    the plot function & scatter(x,y)\\\\\n\n    \\li{semilogx} & plots lines and data with a log scaled x axis &\n    semilogx(x,y)\\\\\n\n    \\li{semilogy} & plots lines and data with a log scaled y axis &\n    semilogy(x,y)\\\\\n\n    \\li{specgram} & make a spectogram from data & specgram(x)\\\\\n\n    \\li{spy} & plot the sparsity pattern of a 2D array & spy(Z)\\\\\n\n    \\li{triplot} & plot triangulation between given points &\n    triplot(x,y)\\\\\n\n    \\hline\n\n    \\end{tabular}\n    \\end{center}\n    \\caption{Some basic functions in Matplotlib.}\n    \\label{mpl:basics}\n    \\end{table}\n\n\n    \\end{comment}\n\n\\section*{3-D plotting with Mayavi (Optional)}\n\nAlthough \\li{matplotlib} is capable of creating 3-D plots, Mayavi does it better. \nWe will use Mayavi for all 3-D plots in these labs.\nFor information beyond what is found in this tutorial, see \\url{http://docs.enthought.com/mayavi/mayavi/}.\nTo get started, import \\li{mlab} from \\li{mayavi}.\n\\begin{lstlisting}\nfrom mayavi import mlab\n\\end{lstlisting}\n\nThe module \\li{mlab} has many plotting functions.\nWe will introduce a few in this lab; for more see \\url{http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html}.\nYou can also browse examples at \\url{http://docs.enthought.com/mayavi/mayavi/auto/examples.html}.\n\n\\begin{comment}\n\\begin{table}\n\\begin{center}\n\\begin{tabular}\n{|c|l|}\n\\hline\nFunction & Description \\\\\n\\hline\n\\li{barchart} & Produces 3D histogram-like plots\\\\\n\\li{contour3d} & Plots level surfaces of functions of three variables\\\\\n\\li{flow} & Creates a trajectory of particles following the flow of a vector field\\\\\n\\li{imshow} & Use a colormap to view a 2D array as an image\\\\\n\\li{mesh} & Plot a surface using \\li{(x,y,z)} coordinates supplied as three 2D arrays\\\\\n\\li{plot3d} & Draws lines between points\\\\\n\\li{points3d} & Plots glyphs (like points) at the coordinates supplied\\\\\n\\li{quiver3d} & Generate 3D vector fields\\\\\n\\li{surf} & Plot a surface with a 2D array as elevation data\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\caption{Some plotting functions in \\li{mlab}.}\n\\label{table:mlab_functions}\n\\end{table}\n\nAll these functions can be ``tested\" (which provides an example figure for the function) with the command:\n\\begin{lstlisting}\nmlab.test_<plotting function>()\nmlab.show()\n\\end{lstlisting}\nNote that pressing tab after typing \\li{mlab.test_} will provide a list of available commands and that, like matplotlib, we use the \\li{show()} command to actually view our plot.\n\nFor example, to test the \\li{fancy_mesh} function, we run the following:\n\\begin{lstlisting}\nmlab.test_fancy_mesh()\nmlab.show()\n\\end{lstlisting}\n\n\nThe result should resemble Figure \\ref{fig:fancymesh}.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{fancymesh.png}\n\\caption{An example of the fancy mesh plotting function}\n\\label{fig:fancymesh}\n\\end{figure}\n\n\nIn this lab, we will focus our attention on introducing the \\li{mesh}, \\li{plot3d}, and \\li{points3d} functions.\n\nLike matplotlib, \\li{mlab} takes a set of data points and plots it.\nHowever, instead of passing just \\li{x} and \\li{y} coordinates as we did in matplotlib, we also send \\li{z} coordinates to produce a 3D plot.\n\n\n\\end{comment}\n\n\\subsection*{Lines}\nThe function call \\li{mlab.plot3d(x,y,z)} plots the points \\li{(x[i], y[i], z[i])} and connects them with straight lines.\nThe code below produces the flower in Figure \\ref{fig:plot3d}\n\n\\begin{lstlisting}\nnum = np.pi/1000\npts = np.arange(0, 2*np.pi + num, num)\nx = np.cos(pts) * (1 + np.cos(pts*6))\ny = np.sin(pts) * (1 + np.cos(pts*6))\nz = np.sin(pts*6/11)\nmlab.plot3d(x, y, z)\nmlab.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{plot3d.png}\n\\caption{Sample output of \\li{mlab.plot3d()}.}\n\\label{fig:plot3d}\n\\end{figure}\n\n\n\\subsection*{Points}\nThe function call \\li{mlab.points3d(x,y,z)} plots the points \\li{(x[i], y[i], z[i])}, but does not connect them. \nIn the code below, the optional input array \\li{s} defines a scalar for each point that modifies the color and size of the point.\nThe output is in Figure \\ref{fig:points3d}.\n\n\\begin{lstlisting}\npts = np.linspace(0, 4 * np.pi, 30)\nx = np.sin(2 * pts)\ny = np.cos(pts)\nz = np.cos(2 * pts)\ns = 2+np.sin(pts)\n# Adjust the keyword argument 'scale_factor' so all points are visible\nmlab.points3d(x, y, z, s, scale_factor=.15)\nmlab.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{points3d.png}\n\\caption{Sample output of \\li{mlab.points3d()}.}\n\\label{fig:points3d}\n\\end{figure}\n\n\n\\subsection*{Surfaces}\nYou can draw a surface in mayavi with \\li{mlab.surf()}.\nThis function accepts three arrays, \\li{X}, \\li{Y}, and \\li{Z}, where \\li{X} and \\li{Y} determine a grid of points similar to the output of \\li{np.meshgrid()}.\nThe array \\li{Z} gives the height of the surface at each of these points.\n\nThe output of \\li{np.meshgrid()} is the transpose of what \\li{mlab.surf()} expects.\nTo avoid confusion, use the function \\li{np.mgrid()} instead.\nThis function uses the slicing syntax \\li{[start:stop:step]} \nThe code below produces the hyperbolic paraboloid in Figure \\ref{fig:surf_example}.\n\n\\begin{lstlisting}\nX, Y = np.mgrid[-4:4:0.025, -4:4:0.025]\nZ = X**2/4-Y**2/4\nmlab.surf(X, Y, Z, colormap='RdYlGn')\nmlab.show()\n\\end{lstlisting}\n\n\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{mesh_example.png}\n\\caption{Sample output of \\li{mlab.surf()}.}\n\\label{fig:surf_example}\n\\end{figure}\n\nThe plotting functions in Mayavi allow you to specify the color of a plot, either as a solid color or with a varying colormap.\nFor example, the plot in Figure \\ref{fig:surf_example} uses the colormap \\li{'RdYlGn'}.\nFor a list of all colormaps in Mayavi, see \\url{http://docs.enthought.com/mayavi/mayavi/mlab_changing_object_looks.html}.\n\n\n%TODO: this problem is copied from https://github.com/enthought/mayavi/blob/master/examples/mayavi/mlab/canyon.py.\n% we either need to cite this (and thus give the solution) or find a different problem.\n\\begin{comment}\n\\begin{problem}\\label{prob:grand_canyon}\nProvided Grand Canyon topological radar data from NASA, do the following.\n\n\\begin{itemize}\n\\item Reshape the data to be 3601x3601.\n\\item Cast the data type as \\li{float32}.\n\\item Slice the data, taking the first 1000 rows and columns 900-1900.\n\\item There is some missing data, so set the minimum of your data equal to the minimum of the the positive data points.\n\\item Preset the figure using the following commands: \\li{mlab.figure(size=(400,320)}, \\li{bgcolor = (.16, .28, .46))}\n\\item Now plot with \\li{mlab.surf}, using the colormap \\li{gist_earth}, with a \\li{warp_scale=.2}, \\li{vmin=1200}, and \\li{vmax=1610}.\n\\item Take a smaller view of the canyon using \\li{mlab.view(-5.9, 83, 570, [5.3, 20, 238])}.\n\\end{itemize}\n\nThis should produce Figure \\ref{fig:GrandCanyon}\n\n\\begin{figure}[H]\n\\includegraphics[width=.7\\textwidth]{GrandCanyon.png}\n\\caption{Correct output for Problem \\ref{prob:grand_canyon}.}\n\\label{fig:GrandCanyon}\n\\end{figure}\n\n\\end{problem}\n\\end{comment}\n\n", "meta": {"hexsha": "5666898d5977c7e90918657f1362b8d0787343bb", "size": 25955, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Python/matplotlib/matplotlib.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Python/matplotlib/matplotlib.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Python/matplotlib/matplotlib.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 36.71145686, "max_line_length": 234, "alphanum_fraction": 0.7072625698, "num_tokens": 8273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673133042217, "lm_q2_score": 0.8887588038050466, "lm_q1q2_score": 0.7224429810244821}}
{"text": "\\chapter{Conclusion}\n\n\\section{Solution Transfer}\n\nThis work has described a method for conservative interpolation\nbetween curved meshes. The transfer process conserves globally\nto machine precision since we can use exact quadratures for all\nintegrals. The primary source of error comes from solving the linear\nsystem with the mass matrix for the target mesh. This allows\nless restrictive usage of mesh adaptivity, which can make computations\nmore efficient. Additionally, having a global transfer algorithm\nallows for remeshing to be done less frequently.\n\nThe algorithm breaks down into three core subproblems: B\\'{e}zier triangle\nintersection, an advancing front for intersecting elements and\nintegration on curved polygons. The inherently local nature of the\nadvancing front allows the algorithm to be parallelized via domain\ndecomposition with little data shared between processes. By\nrestricting integration to the intersection of elements from the\ntarget and donor meshes, the algorithm can accurately transfer\nboth continuous and discontinuous fields.\n\n\\subsection{Future Work}\n\nAs mentioned in the preceding chapters, there are several research\ndirections possible to build upon the solution transfer algorithm.\nThe usage of Green's theorem nicely extends to \\(\\reals^3\\) via\nStoke's theorem, but the B\\'{e}zier triangle intersection algorithm\nis specific to \\(\\reals^2\\). The equivalent B\\'{e}zier tetrahedron\nintersection algorithm is significantly more challenging.\n\nThe restriction to shape functions from the global coordinates basis\nis a symptom of the method and not of the inherent problem. The\npre-image basis has several appealing properties, for example\nthis basis can be precomputed on \\(\\utri\\). The problem of a\nvalid tessellation of a curved polygon warrants more exploration.\nSuch a tessellation algorithm would enable usage of the pre-image\nbasis.\n\nThe usage of the global coordinates basis does have some benefits.\nIn particular, the product of shape functions from different meshes\nis still a polynomial in \\(\\reals^2\\). This means that we could\ncompute the coefficients of \\(F = \\phi_0 \\phi_1\\) directly and\nuse them to evaluate the antiderivatives \\(H\\) and \\(V\\) rather\nthan using the fundamental theorem of calculus. Even if this\ndid not save any computation, it may still be preferred over\nthe FTC approach because it would remove the usage of quadrature\npoints outside of the domain \\(\\mathcal{P}\\).\n\n\\section{Ill-conditioned B\\'{e}zier Curve Intersection}\n\nThe B\\'{e}zier triangle intersection subproblem can be solved\npartially by intersecting B\\'{e}zier curves (i.e. the edges).\nHowever, the probability of ``almost tangent'' or ill-conditioned\nB\\'{e}zier curve intersections increases to unity as the mesh\nsize \\(h\\) goes to \\(0\\).\n\nTurning our focus to ill-conditioned B\\'{e}zier curve intersections,\nwe designed a modified Newton's method that computed the residual\nas if in extended precision. Building on existing work, we describe\na compensated de Casteljau algorithm that allows the evaluation of\na polynomial in Bernstein form as accurate as if the computations\nwere done in \\(K\\)-times the working precision. The residual\n\\(F(s, t) = b_0(s) - b_1(t)\\) depends on four evaluations of\na polynomial in Bernstein form, so \\(F\\) can be computed more precisely\nby using the compensated evaluation algorithm.\n", "meta": {"hexsha": "732b2fbf8c8d55a98eee42a020dc8c8a603eefdf", "size": 3348, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/conclusion.tex", "max_stars_repo_name": "dhermes/phd-thesis", "max_stars_repo_head_hexsha": "732c75b4258e6f41b2dafb2929f0e3dbd380239b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-08-24T15:36:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-13T01:38:19.000Z", "max_issues_repo_path": "doc/conclusion.tex", "max_issues_repo_name": "dhermes/phd-thesis", "max_issues_repo_head_hexsha": "732c75b4258e6f41b2dafb2929f0e3dbd380239b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-08-21T05:57:22.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-16T16:43:00.000Z", "max_forks_repo_path": "doc/conclusion.tex", "max_forks_repo_name": "dhermes/phd-thesis", "max_forks_repo_head_hexsha": "732c75b4258e6f41b2dafb2929f0e3dbd380239b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.9701492537, "max_line_length": 74, "alphanum_fraction": 0.8010752688, "num_tokens": 727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7224429759096745}}
{"text": "\\section{Integration by Parts}{}{}\\label{sec:Parts}\n%We have already seen that recognizing the product rule can be useful,\n%when we noticed that\n%$$\\int \\sec^3u+\\sec u \\tan^2u\\,du=\\sec u \\tan u.$$\n%As with substitution, we do not have to rely on insight or cleverness\n%to discover such antiderivatives; there is a technique that will often\n%help to uncover the product rule.\n%\n%Start with the product rule:\n%$${d\\over dx}f(x)g(x)=f'(x)g(x)+f(x)g'(x).$$\n%We can rewrite this as\n%$$f(x)g(x)=\\int f'(x)g(x)\\,dx +\\int f(x)g'(x)\\,dx,$$\n%and then\n%$$\\int f(x)g'(x)\\,dx=f(x)g(x)-\\int f'(x)g(x)\\,dx.$$\n%This may not seem particularly useful at first glance, but it turns\n%out that in many cases we have an integral of the form\n%$$\\int f(x)g'(x)\\,dx$$\n%but that \n%$$\\int f'(x)g(x)\\,dx$$\n%is easier. This technique for turning one integral into another is\n%called {\\dfont integration by parts},\n%and is usually written in more compact form. If we let $u=f(x)$ and\n%$v=g(x)$ then $du=f'(x)\\,dx$ and $dv=g'(x)\\,dx$ and \n%$$\\int u\\,dv = uv-\\int v\\,du.$$\n%To use this technique we need to identify likely candidates for\n%$u=f(x)$ and $dv=g'(x)\\,dx$.\n%\n%\\begin{example}{Product of a Linear Function and Logarithm}{Product of a Linear Function and Logarithm}\\label{Product of a Linear Function and Logarithm}\n%Evaluate $\\ds\\int x\\ln x\\,dx$. \n%\\end{example}\n%\n%\\begin{solution}\n%Let $u=\\ln x$ so $du=1/x\\,dx$. Then\n%we must let $dv=x\\,dx$ so $\\ds v=x^2/2$ and\n%$$\n% \\int x\\ln x\\,dx={x^2\\ln x\\over 2}-\\int {x^2\\over2}{1\\over x}\\,dx=\n% {x^2\\ln x\\over 2}-\\int {x\\over2}\\,dx={x^2\\ln x\\over 2}-{x^2\\over4}+C.\n%$$\\vskip-10pt\n%\\end{solution}\n%\n%\\begin{example}{Product of a Linear Function and Trigonometric Function}{Product of a Linear Function and Trigonometric Function}\\label{Product of a Linear Function and Trigonometric Function}\n%Evaluate $\\ds\\int x\\sin x\\,dx$. \n%\\end{example}\n%\n%\\begin{solution}\n%Let $u=x$ so $du=dx$. Then\n%we must let $dv=\\sin x\\,dx$ so $v=-\\cos x$ and\n%$$\\int x\\sin x\\,dx=-x\\cos x-\\int -\\cos x\\,dx=\n%-x\\cos x+\\int \\cos x\\,dx=-x\\cos x+\\sin x+C.$$\\vskip-10pt\n%\\end{solution}\n\nHere's a simple integral that we can't yet evaluate:\n$$\\int x\\cos x \\,dx.$$\nIt's a simple matter to take the derivative of the integrand using the Product Rule, but there is no Product Rule for integrals.  However, this section introduces \\textit{Integration by Parts}, a method of integration that is based on the Product Rule for derivatives. It will enable us to evaluate this integral.\n\nThe Product Rule says that if $u$ and $v$ are functions of $x$, then  $(uv)' = u\\primeskip'v + uv\\primeskip'$.  For simplicity, we've written $u$ for $u(x)$ and $v$ for $v(x)$.  Suppose we integrate both sides with respect to $x$.  This gives\n$$\\int (uv)'\\,dx = \\int (u\\primeskip'v+uv\\primeskip')\\,dx.$$\nBy the Fundamental Theorem of Calculus, the left side integrates to $uv$.  The right side can be broken up into two integrals, and we have\n$$\\int (uv)'\\,dx = \\int u\\primeskip'v\\,dx + \\int uv\\primeskip'\\,dx.$$\nrearranging we get\n$$\\int uv\\primeskip'\\,dx = \\int (uv)'\\,dx - \\int u\\primeskip'v\\,dx.$$\nwhich gives \n$$\\int uv\\primeskip'\\,dx = uv - \\int u\\primeskip'v\\,dx.$$\nUsing differential notation, we can write $du = u\\primeskip'(x)dx$ and $dv=v\\primeskip'(x)dx$ and the expression above can be written as follows:\n$$\\int u\\,dv = uv - \\int v\\,du.$$\nThis is the Integration by Parts formula. For reference purposes, we state this in a theorem.\n\n\n\\begin{theorem}{Integration by Parts}{IBP}\n{Let $u$ and $v$ be differentiable functions of $x$ on an interval $I$ containing $a$ and $b$. Then \n\t$$\\int u\\ dv = uv - \\int v\\ du,$$ and \\index{integration!by parts}\n\t$$\\int_{x=a}^{x=b} u\\ dv = uv\\Big|_a^b - \\int_{x=a}^{x=b}v\\ du.$$\n}\n\\end{theorem}\n\n\nLet's try an example to understand our new technique.\\\\\n\n\\begin{example}{Integrating using Integration by Parts}{ex_ibp1}\n\t{\n\tEvaluate $\\ds\\int x\\cos{x}\\ dx$.}\t\n\\end{example}\t\n\n\\begin{solution}\n{The key to Integration by Parts is to identify part of the integrand as ``$u$'' and part as ``$dv$.'' Regular practice will help one make good identifications, and later we will introduce some principles that help. For now, let  $u=x$ and $dv=\\cos{x}\\ dx$.\n\t\nIt is generally useful to make a small table of these values as done below. Right now we only know $u$ and $dv$ as shown on the left of Figure \\ref{fig:ibp1}; on the right we fill in the rest of what we need. If $u = x$, then $du = dx$. Since $dv = \\cos x\\ dx$, $v$ is an antiderivative of $\\cos x$. We choose $v = \\sin x$.\\\\\n\t\n\t\\noindent\\begin{minipage}{\\textwidth}\n\t\t\\noindent\\begin{minipage}[t]{.45\\textwidth}\n\t\t\t%\\centering\n\t\t\t\\vskip-10pt\n\t\t\t\\begin{align*}\n\t\t\tu&= x & v&=\\text{?}\\\\\n\t\t\tdu&= \\text{?} & dv&=\\cos x\\ dx\n\t\t\t\\end{align*}\n\t\t\\end{minipage}\\begin{minipage}[t]{.1\\textwidth}\\centering\\vskip15pt$\\Rightarrow$\\end{minipage}\n\t\t\\begin{minipage}[t]{.45\\textwidth}\n\t\t\t\\vskip-10pt\n\t\t\t\\begin{align*}\n\t\t\tu&= x & v&=\\sin x\\\\\n\t\t\tdu&= dx & dv&=\\cos x\\ dx\n\t\t\t\\end{align*}\n\t\t\\end{minipage}\n\t\t\\captionsetup{type=figure}%\n\t\t\\caption{Setting up Integration by Parts.}\\label{fig:ibp1}\n\t\\end{minipage}\\\\\n\t\\vskip\\baselineskip\n\t\n\t%  On the right side of the formula we can see that we need $du$ and $v$.  We get $du$ by taking the derivative of $u$, and we get $du=(1)\\,dx$, or simply $du=dx$.  We get $v$ by finding an antiderivative of $dv$.  Here we get $v=\\sin x $.  \n\tNow substitute all of this into the Integration by Parts formula, giving\n\t$$\\int x\\cos x\\,dx = x\\sin x - \\int \\sin x \\,dx.$$\n\tWe can then integrate $\\sin x$ to get $-\\cos x + C$ and overall our answer is\n\t$$\\int x\\cos x\\ dx = x\\sin x + \\cos x + C.$$\n\tNote how the antiderivative contains a product, $x\\sin x$. This product is what makes Integration by Parts necessary.\n}\t\n\\end{solution}\n\n\nThe example above demonstrates how Integration by Parts works in general.  We try to identify $u$ and $dv$ in the integral we are given, and the key is that we usually want to choose $u$ and $dv$ so that $du$ is simpler than $u$ and $v$ is hopefully not too much more complicated than $dv$.  This will mean that the integral on the right side of the Integration by Parts formula, $\\int v\\,du$ will be simpler to integrate than the original integral $\\int u\\,dv$.\n\nIn the example above, we chose $u=x$ and $dv=\\cos x\\,dx$.  Then $du=dx$ was simpler than $u$ and $v=\\sin x$ is no more complicated than $dv$.  Therefore, instead of integrating $x\\cos x \\,dx$, we could integrate $\\sin x\\,dx$, which we knew how to do.\n\nA useful mnemonic for helping to determine $u$ is ``LIPET,'' where \n\\begin{center}L = \\textbf{L}ogarithmic, I = \\textbf{I}nverse Trig., P = \\textbf{P}olynomial (algebraic), E = \\textbf{E}xponential, and T = \\textbf{T}rigonometric.\n\\end{center}\n\nIf the integrand contains both a logarithmic and an polynomial term, in general letting $u$ be the logarithmic term works best, as indicated by L coming before P in LIPET.\n\nNote: Some texts us ``LIATE,'' where A = \\textbf{A}lgebraic. This method works just as well as LIPET.\n\n\n%A useful mnemonic for helping to determine $u$ is ``LIATE,'' where \n%\\begin{center}L = \\textbf{L}ogarithmic, I = \\textbf{I}nverse Trig., A = \\textbf{A}lgebraic (polynomials), \n%\t\n%\tT = \\textbf{T}rigonometric, and E = \\textbf{E}xponential.\n%\\end{center}\n%\n%If the integrand contains both a logarithmic and an algebraic term, in general letting $u$ be the logarithmic term works best, as indicated by L coming before A in LIATE.\n\nWe now consider another example.\\\\\n\n\\begin{example}{Integrating using Integration by Parts}{ex_ibp2}\n\t{\n\tEvaluate $\\displaystyle \\int x e^x\\,dx$.}\t\n\\end{example}\n\n\\begin{solution}\n{Using the LIPET rule, we see that the integrand contains a  \\textbf{P}olynomial term ($x$) and an \\textbf{E}xponential term ($e^x$). Our mnemonic suggests letting $u$ be the polynomial term, so we choose $u=x$ and $dv=e^x\\,dx$.  Then $du=dx$ and $v=e^x$ as indicated by the tables below.\\\\\n\t\n\t\\noindent\\begin{minipage}{\\textwidth}\n\t\t\\noindent\\begin{minipage}[t]{.45\\textwidth}\n\t\t\t%\\centering\n\t\t\t\\vskip-10pt\n\t\t\t\\begin{align*}\n\t\t\tu&= x & v&=\\text{?}\\\\\n\t\t\tdu&= \\text{?} & dv&=e^x\\ dx\n\t\t\t\\end{align*}\n\t\t\\end{minipage}\\begin{minipage}[t]{.1\\textwidth}\\centering\\vskip15pt$\\Rightarrow$\\end{minipage}\n\t\t\\begin{minipage}[t]{.45\\textwidth}\n\t\t\t\\vskip-10pt\n\t\t\t\\begin{align*}\n\t\t\tu&= x & v&=e^x\\\\\n\t\t\tdu&= dx & dv&=e^x\\ dx\n\t\t\t\\end{align*}\n\t\t\\end{minipage}\n\t\t\\captionsetup{type=figure}%\n\t\t\\caption{Setting up Integration by Parts.}\\label{fig:ibp2}\n\t\\end{minipage}\\\\\n\t\\vskip\\baselineskip\n\t\n\tWe see $du$ is simpler than $u$, while there is no change in going from $dv$ to $v$.  This is good.  The Integration by Parts formula gives\n\t$$\\int x e^x\\,dx = xe^x - \\int e^x\\,dx.$$\n\tThe integral on the right is simple; our final answer is\n\t$$\\int xe^x\\ dx = xe^x - e^x + C.$$\n\tNote again how the antiderivatives contain a product term.\n}\t\n\\end{solution}\t\n\n\\begin{example}{Product of a Linear Function and Logarithm}{Product of a Linear Function and Logarithm}\\label{Product of a Linear Function and Logarithm}\nEvaluate $\\ds\\int x\\ln x\\,dx$. \n\\end{example}\n\n\\begin{solution}\nUsing the LIPET rule, we let $u=\\ln x$ so $du=1/x\\,dx$. Then\nwe must let $dv=x\\,dx$ so $\\ds v=x^2/2$ and\n$$\n \\int x\\ln x\\,dx={x^2\\ln x\\over 2}-\\int {x^2\\over2}{1\\over x}\\,dx=\n {x^2\\ln x\\over 2}-\\int {x\\over2}\\,dx={x^2\\ln x\\over 2}-{x^2\\over4}+C.\n$$\\vskip-10pt\n\\end{solution}\n\n\n\n\\begin{example}{Secant Cubed (again)}{Secant Cubed (again)}\\label{Secant Cubed (again)}\nEvaluate $\\ds\\int\\sec^3 x\\,dx$. \n\\end{example}\n\n\\begin{solution}\nOf course we already know the answer\nto this, but we needed to be clever to discover it. Here we'll use the\nnew technique to discover the antiderivative.\nLet $u=\\sec x$ and $\\ds dv=\\sec^2 x\\,dx$. Then $du=\\sec x\\tan x$ and\n$v=\\tan x$ and\n\\begin{eqnarray*}\n  \\int\\sec^3 x\\,dx&=&\\sec x\\tan x-\\int \\tan^2x\\sec x\\,dx\\cr\n  &=&\\sec x\\tan x-\\int (\\sec^2x-1)\\sec x\\,dx\\cr\n  &=&\\sec x\\tan x-\\int \\sec^3x\\,dx +\\int\\sec x\\,dx.\\cr\n\\end{eqnarray*}\nAt first this looks useless---we're right back to\n$\\ds \\int\\sec^3x\\,dx$. But looking more closely:\n\\begin{eqnarray*}\n  \\int\\sec^3x\\,dx&=&\\sec x\\tan x-\\int \\sec^3x\\,dx +\\int\\sec x\\,dx\\cr\n  \\int\\sec^3x\\,dx+\\int \\sec^3x\\,dx&=&\\sec x\\tan x +\\int\\sec x\\,dx\\cr\n  2\\int\\sec^3x\\,dx&=&\\sec x\\tan x +\\int\\sec x\\,dx\\cr\n  \\int\\sec^3x\\,dx&=&{\\sec x\\tan x\\over2} +{1\\over2}\\int\\sec x\\,dx\\cr\n  &=&{\\sec x\\tan x\\over2} +{\\ln|\\sec x+\\tan x|\\over2}+C.\n\\end{eqnarray*}\\vskip-10pt\n\\end{solution}\n\n\\subsection*{Tabular Method}\n\n\\begin{example}{Product of a Polynomial and Trigonometric Function}{Product of a Polynomial and Trigonometric Function}\\label{Product of a Polynomial and Trigonometric Function}\nEvaluate $\\ds\\int x^2\\sin x\\,dx$. \n\\end{example}\n\n\\begin{solution}\nLet $u=x^2$, $dv=\\sin x\\,dx$; then $du=2x\\,dx$ and $v=-\\cos x$. \nNow $$\\ds \\int x^2\\sin x\\,dx=-x^2\\cos x+\\int 2x\\cos x\\,dx.$$ \nThis is\nbetter than the original integral, but we need to do integration by\nparts again. Let $u=2x$, $dv=\\cos x\\,dx$; then\n$du=2$ and $v=\\sin x$, and\n\\begin{eqnarray*}\n  \\int x^2\\sin x\\,dx&=&-x^2\\cos x+\\int 2x\\cos x\\,dx\\cr\n  &=&-x^2\\cos x+ 2x\\sin x - \\int 2\\sin x\\,dx\\cr\n  &=&-x^2\\cos x+ 2x\\sin x + 2\\cos x + C.\n\\end{eqnarray*}\\vskip-10pt\n\\end{solution}\n\nSuch repeated use of integration by parts is fairly common, but it can\nbe a bit tedious to accomplish, and it is easy to make\nerrors, especially sign errors involving the subtraction in the\nformula. There is a nice tabular method to accomplish the calculation\nthat minimizes the chance for error and speeds up the whole\nprocess. We illustrate with the previous example. Here is the\ntable:\n$$\\begin{array}{|c|c|c|}\n\\hline\n\\mbox{sign}& u& dv\\\\\\hline\n\\mbox{+}& x^2& \\sin x\\\\\\hline\n\\mbox{-}& 2x& -\\cos x\\\\\\hline\n\\mbox{+}& 2& -\\sin x\\\\\\hline\n\\mbox{-}& 0& \\cos x\\\\\\hline\n\\end{array}$$\nTo form this table, we start with $u$ at the top of the second\ncolumn and repeatedly compute the derivative; starting with $dv$ at\nthe top of the third column, we repeatedly compute the\nantiderivative. In the first column, we place a ``$-$'' in every\nsecond row. To form the \nsecond table we combine the first and second columns by\nignoring the boundary; if you do this by hand, you may simply start\nwith two columns and add a ``$-$'' to every second row.\n\nAlternatively, we can use the following table:\n$$\\begin{array}{|c|c|}\n\\hline\nu& dv\\\\\\hline\nx^2& \\sin x\\\\\\hline\n-2x& -\\cos x\\\\\\hline\n2& -\\sin x\\\\\\hline\n0& \\cos x\\\\\\hline\n\\end{array}$$\nTo compute with this second table we begin at the top. Multiply the\nfirst entry in column $u$ by the second entry in column $dv$ to get\n$\\ds -x^2\\cos x$, and add this to the integral of the product of the\nsecond entry in column $u$ and second entry in column $dv$.  This\ngives:\n$$-x^2\\cos x+\\int 2x\\cos x\\,dx,$$\nor exactly the result of the first application of integration by\nparts.  Since this integral is not yet easy, we return to the table.\nNow we multiply twice on the diagonal, $\\ds (x^2)(-\\cos x)$ and\n$(-2x)(-\\sin x)$ and then once straight across, $(2)(-\\sin x)$, and\ncombine these as\n$$-x^2\\cos x+2x\\sin x-\\int 2\\sin x\\,dx,$$\ngiving the same result as the second application of integration by\nparts. While this integral is easy, we may return yet once more to the\ntable. Now multiply three times on the diagonal to get $\\ds\n(x^2)(-\\cos x)$, $(-2x)(-\\sin x)$, and $(2)(\\cos x)$, and once\nstraight across, $(0)(\\cos x)$. We combine these as before to get\n$$\n  -x^2\\cos x+2x\\sin x +2\\cos x+\\int 0\\,dx=\n  -x^2\\cos x+2x\\sin x +2\\cos x+C.\n$$\nTypically we would fill in the table one line at a time, until the\n``straight across'' multiplication gives an easy integral. If we can\nsee that the $u$ column will eventually become zero, we can instead\nfill in the whole table; computing the products as indicated will then\ngive the entire integral, including the ``$+C\\,$'', as above.\n\n\\begin{example}{}{}\nDo Example \\ref{exa:ex_ibp2} again, using the tabular method.\n\\end{example}\n\n\\begin{solution}\nRecognising that $ x $\thas a derivative that vanishes, and $ e^x $ is easy to repeatedly integrate, we construct the table with $ u=x:$\n$$\\begin{array}{|c|c|}\n\\hline\nu& dv\\\\\\hline\nx& e^x\\\\\\hline\n-1& e^x\\\\\\hline\n+0& e^x\\\\\\hline\n\\end{array}$$\nThis gives\n$$\\int xe^x\\ dx = xe^x - e^x + C.$$\nwhich agrees with the result in Example \\ref{exa:ex_ibp2}. \n\\end{solution}\n\n\n\\subsection*{Some Classic Examples of IBP}\n\n\\begin{example}{Solving for the unknown integral}{ex_ibp4}\n\t{\n\tEvaluate $\\displaystyle \\int e^x\\cos x \\,dx$.}\t\n\\end{example}\t\n\n\\begin{solution}\n{This is a classic problem.  Our mnemonic (LIPET) suggests letting $u$ be the exponential factor, sowe choose $u=e^x$ and hence $dv = \\cos x\\,dx$.  Then $du=e^x\\,dx$ and $v=\\sin x$ as shown below.\\\\\t\n\t\\noindent\\begin{minipage}{\\textwidth}\n\t\t\\noindent\\begin{minipage}[t]{.45\\textwidth}\n\t\t\t%\\centering\n\t\t\t\\vskip-10pt\n\t\t\t\\begin{align*}\n\t\t\tu&= e^x & v&=\\text{?}\\\\\n\t\t\tdu&= \\text{?} & dv&=\\cos x\\ dx\n\t\t\t\\end{align*}\n\t\t\\end{minipage}\\begin{minipage}[t]{.1\\textwidth}\\centering\\vskip15pt$\\Rightarrow$\\end{minipage}\n\t\t\\begin{minipage}[t]{.45\\textwidth}\n\t\t\t\\vskip-10pt\n\t\t\t\\begin{align*}\n\t\t\tu&= e^x& v&=\\sin x\\\\\n\t\t\tdu&= e^x\\ dx & dv&=\\cos x\\ dx\n\t\t\t\\end{align*}\n\t\t\\end{minipage}\n\t\t\\captionsetup{type=figure}%\n\t\t\\caption{Setting up Integration by Parts.}\\label{fig:ibp4}\n\t\\end{minipage}\\\\\n\t\\vskip\\baselineskip\n\tNotice that $du$ is no simpler than $u$, going against our general rule (but bear with us). The Integration by Parts formula yields\n\t$$\\int e^x\\cos x\\ dx = e^x\\sin x - \\int e^x\\sin x\\,dx.$$\n\tThe integral on the right is not much different than the one we started with, so it seems like we have gotten nowhere. Let's  keep working and apply Integration by Parts to the new integral, using $u=e^x$ and $dv = \\sin x\\,dx$. This leads us to the following:\\\\ %Then we get $du=e^x\\,dx$ and $v=-\\cos x$.  \n\t\n\t\\noindent\\begin{minipage}{\\textwidth}\n\t\t\\noindent\\begin{minipage}[t]{.45\\textwidth}\n\t\t\t%\\centering\n\t\t\t\\vskip-10pt\n\t\t\t\\begin{align*}\n\t\t\tu&= e^x & v&=\\text{?}\\\\\n\t\t\tdu&= \\text{?} & dv&=\\sin x\\ dx\n\t\t\t\\end{align*}\n\t\t\\end{minipage}\\begin{minipage}[t]{.1\\textwidth}\\centering\\vskip15pt$\\Rightarrow$\\end{minipage}\n\t\t\\begin{minipage}[t]{.45\\textwidth}\n\t\t\t\\vskip-10pt\n\t\t\t\\begin{align*}\n\t\t\tu&= e^x& v&=-\\cos x\\\\\n\t\t\tdu&= e^x\\ dx & dv&=\\sin x\\ dx\n\t\t\t\\end{align*}\n\t\t\\end{minipage}\n\t\t\\captionsetup{type=figure}%\n\t\t\\caption{Setting up Integration by Parts (again).}\\label{fig:ibp4a}\n\t\\end{minipage}\\\\\n\t\\vskip\\baselineskip\n\t\n\tThe Integration by Parts formula then gives:\n\t\\begin{align*}\n\t\\int e^x\\cos x\\,dx &= e^x\\sin x - \\left(-e^x\\cos x - \\int -e^x\\cos x\\,dx\\right)\\\\\n\t&= e^x\\sin x+ e^x\\cos x - \\int e^x\\cos x\\ dx.\n\t\\end{align*}\n\tIt seems we are back right where we started, as the right hand side contains $\\int e^x\\cos x\\,dx$.  But this is actually a good thing.  \n\t\n\tAdd $\\ds\\int e^x\\cos x\\ dx$ to both sides. This gives \n\t\\begin{align*}\n\t2\\int e^x\\cos x\\ dx & = e^x\\sin x + e^x\\cos x \\\\\n\t\\intertext{Now divide both sides by 2:}\n\t\\int e^x\\cos x\\ dx & = \\frac{1}{2}\\big(e^x\\sin x + e^x\\cos x\\big).\n\t\\end{align*}\n\t\n\tSimplifying a little and adding the constant of integration, our answer is thus\n\t$$\\int e^x\\cos x\\ dx = \\frac12e^x\\left(\\sin x + \\cos x\\right)+C.$$\n\t\\vskip-15pt\n}\t\n\\end{solution}\t\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\n\\begin{example}{IBP: the antiderivative of $\\ln x$}{ex_ibp5}\n{Evaluate $\\displaystyle \\int \\ln x\\,dx$.}\t\n\\end{example}\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\n\\begin{solution}\n{One may have noticed that we have rules for integrating the familiar trigonometric functions and $e^x$, but we have not yet given a rule for integrating $\\ln x$.  That is because $\\ln x$ can't easily be integrated with any of the rules we have learned up to this point.  But we can find its antiderivative by a clever application of Integration by Parts.  Set $u=\\ln x$ and $dv=dx$.  This is a good, sneaky trick to learn as it can help in other situations. This determines $du=(1/x)\\,dx$ and $v=x$ as shown below.\\\\\n\t\n\t\\noindent\\begin{minipage}{\\textwidth}\n\t\t\\noindent\\begin{minipage}[t]{.45\\textwidth}\n\t\t\t%\\centering\n\t\t\t\\vskip-10pt\n\t\t\t\\begin{align*}\n\t\t\tu&= \\ln x & v&=\\text{?}\\\\\n\t\t\tdu&= \\text{?} & dv&=dx\n\t\t\t\\end{align*}\n\t\t\\end{minipage}\\begin{minipage}[t]{.1\\textwidth}\\centering\\vskip15pt$\\Rightarrow$\\end{minipage}\n\t\t\\begin{minipage}[t]{.45\\textwidth}\n\t\t\t\\vskip-10pt\n\t\t\t\\begin{align*}\n\t\t\tu&= \\ln x& v&=x\\\\\n\t\t\tdu&= 1/x\\ dx & dv&=dx\n\t\t\t\\end{align*}\n\t\t\\end{minipage}\n\t\t\\captionsetup{type=figure}%\n\t\t\\caption{Setting up Integration by Parts.}\\label{fig:ibp5}\n\t\\end{minipage}\\\\\n\t\\vskip\\baselineskip\n\tPutting this all together in the Integration by Parts formula, things work out very nicely:\n\t$$\\int \\ln x\\,dx = x\\ln x - \\int x\\,\\frac1x\\,dx.$$\n\tThe new integral simplifies to $\\int 1\\,dx$, which is about as simple as things get.  Its integral is $x+C$ and our answer is\n\t$$\\int \\ln x\\ dx = x\\ln{x} - x + C.$$\n}\\\\\n\\end{solution}\t\t\n\n\n\\begin{example}{Integrating using Int. by Parts: antiderivative of $\\arctan x$}{ex_ibp6}\n{Evaluate $\\displaystyle \\int \\arctan x  \\,dx$.}\n\\end{example}\n\n\\begin{solution}\n{The same sneaky trick we used above works here.  Let $u=\\arctan x$ and $dv=dx$.  Then $du=1/(1+x^2)\\,dx$ and $v=x$.  The Integration by Parts formula gives\n\t$$\\int \\arctan x \\,dx = x\\arctan x - \\int \\frac x{1+x^2}\\,dx.$$\n\tThe integral on the right can be solved by substitution.  Taking $u=1+x^2$, we get $du=2x\\,dx$.  The integral then becomes\n\t$$\\int \\arctan x \\,dx = x\\arctan x - \\frac12\\int \\frac 1{u}\\,du.$$\n\tThe integral on the right evaluates to $\\ln|u|+C$, which becomes $\\ln(1+x^2)+C$.  Therefore, the answer is\n\t$$\\int \\arctan x\\ dx = x\\arctan x - \\ln(1+x^2) + C.$$\n}\\\\\t\t\n\\end{solution}\t\t\n\n\n\n\n\\subsection*{ Substitution Before Integration}\n\nWhen taking derivatives, it was common to employ multiple rules (such as using both the Quotient and the Chain Rules). It should then come as no surprise that some integrals are best evaluated by combining integration techniques. In particular, here we illustrate making an ``unusual'' substitution first before using Integration by Parts.\\\\\n\n\\begin{example}{Integration by Parts after substitution}{ex_ibp8}\n\t{\n\tEvaluate $\\ds \\int \\cos(\\ln x)\\ dx$.}\t\n\\end{example}\n\n\n\\begin{solution}\n{The integrand contains a composition of functions, leading us to think Substitution would be beneficial. Letting $u=\\ln x$, we have $du = 1/x\\ dx$. This seems problematic, as we do not have a $1/x$ in the integrand. But consider:\n\t$$du = \\frac 1x\\ dx \\Rightarrow x\\cdot du = dx.$$\n\tSince $u = \\ln x$, we can use inverse functions and conclude that $x = e^u$. Therefore we have that\n\t\\begin{align*}\n\tdx &= x\\cdot du \\\\\n\t&= e^u\\ du.\n\t\\end{align*}\n\tWe can thus replace $\\ln x$ with $u$ and $dx$ with $e^u\\ du$. Thus we rewrite our integral as \n\t$$\\int \\cos(\\ln x)\\ dx = \\int e^u\\cos u \\ du.$$\n\tWe evaluated this integral in Example \\ref{exa:ex_ibp4}. Using the result there, we have:\n\t\\begin{align*}\n\t\\int \\cos(\\ln x)\\ dx &= \\int e^u\\cos u \\ du \\\\\n\t&= \\frac12e^u\\big(\\sin u + \\cos u\\big) + C \\\\\n\t&= \\frac12e^{\\ln x} \\big(\\sin(\\ln x) + \\cos (\\ln x)\\big)+C\\\\\n\t&= \\frac12x \\big(\\sin(\\ln x) + \\cos (\\ln x)\\big)+C.\n\t\\end{align*}\n\t\\vskip-\\baselineskip\n}\n\\end{solution}\t\t\n\n\n\n\n\\subsection*{Definite Integrals and Integration By Parts}\n\n\nSo far we have focused only on evaluating indefinite integrals. Of course, we can use Integration by Parts to evaluate definite integrals as well, as Theorem \\ref{thm:IBP} states. We do so in the next example.\\\\\n\n\\begin{example}{Definite integration using Integration by Parts}{ex_ibp7}\n\t{\n\tEvaluate $\\displaystyle \\int_1^2 x^2 \\ln x \\,dx$.}\t\n\\end{example}\n\n\n\\begin{solution}\n{%Once again, our mnemonic suggests we let $u=\\ln x$.  %(We could let $u = x^2$ and $dv = \\ln x\\ dx$, as we now know the antiderivatives of $\\ln x$. However, letting $u = \\ln x$ makes our next integral much simpler as it removes the logarithm from the integral entirely.)\n\tOur mnemonic suggests letting $u=\\ln x$, hence $dv =x^2\\,dx$. \n\t%So we have $u=\\ln x$ and $dv=x^2\\,dx$.  \n\tWe then get $du = (1/x)\\,dx$ and $v=x^3/3$ as shown below.\\\\\n\t\n\t\\noindent\\begin{minipage}{\\textwidth}\n\t\t\\noindent\\begin{minipage}[t]{.45\\textwidth}\n\t\t\t%\\centering\n\t\t\t\\vskip-10pt\n\t\t\t\\begin{align*}\n\t\t\tu&= \\ln x & v&=\\text{?}\\\\\n\t\t\tdu&= \\text{?} & dv&=x^2\\ dx\n\t\t\t\\end{align*}\n\t\t\\end{minipage}\\begin{minipage}[t]{.1\\textwidth}\\centering\\vskip15pt$\\Rightarrow$\\end{minipage}\n\t\t\\begin{minipage}[t]{.45\\textwidth}\n\t\t\t\\vskip-10pt\n\t\t\t\\begin{align*}\n\t\t\tu&= \\ln x& v&=x^3/3\\\\\n\t\t\tdu&= 1/x\\ dx & dv&=x^2\\ dx\n\t\t\t\\end{align*}\n\t\t\\end{minipage}\n\t\t\\captionsetup{type=figure}%\n\t\t\\caption{Setting up Integration by Parts.}\\label{fig:ibp7}\n\t\\end{minipage}\\\\\n\t\\vskip\\baselineskip\n\t\n\tThe Integration by Parts formula then gives\n\t\\begin{align*}\n\t\\int_1^2 x^2 \\ln x\\,dx &= \\frac{x^3}3\\ln x\\bigg|_1^2 - \\int_1^2 \\frac{x^3}{3}\\,\\frac 1x\\,dx \\\\\n\t&=  \\frac{x^3}3\\ln x\\bigg|_1^2 - \\int_1^2 \\frac{x^2}{3}\\,dx \\\\\n\t&=  \\frac{x^3}3\\ln x\\bigg|_1^2 - \\frac{x^3}{9}\\bigg|_1^2\\\\\n\t&=  \\left(\\frac{x^3}3\\ln x - \\frac{x^3}{9}\\right)\\bigg|_1^2\\\\\n\t&=\t\\left(\\frac83\\ln 2 - \\frac89\\right)-\\left(\\frac13\\ln 1 - \\frac19\\right) \\\\\n\t&= \\frac83\\ln 2 - \\frac79 \\\\\n\t&\\approx 1.07.\n\t\\end{align*}\n\t\\vskip-15pt\n}\t\n\\end{solution}\t\t\n\n\nIn general, Integration by Parts is useful for integrating certain products of functions, like $\\int x e^x\\,dx$ or $\\int x^3\\sin x\\,dx$.   It is also useful for integrals involving logarithms and inverse trigonometric functions.  \n\nAs stated before, integration is generally more difficult than derivation. We are developing tools for handling a large array of integrals, and experience will tell us when one tool is preferable/necessary over another. For instance, consider the three similar--looking integrals \n$$\\int xe^x\\,dx, \\qquad  \\int x e^{x^2}\\,dx \\qquad \\text{and} \\qquad \\int xe^{x^3}\\,dx.$$\n\nWhile the first is calculated easily with Integration by Parts, the second is best approached with Substitution.  Taking things one step further, the third integral has no answer in terms of elementary functions, so none of the methods we learn in calculus will get us the exact answer.\n\nIntegration by Parts is a very useful method, second only to substitution. In the following sections of this chapter, we continue to learn other integration techniques.  \n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Parts}}\n\n\\begin{enumialphparenastyle}\n\nFind the antiderivatives.\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int x\\cos x\\,dx$\n\\begin{sol}\n $\\cos x+x\\sin x+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int x^2\\cos x\\,dx$\n\\begin{sol}\n $\\ds x^2\\sin x-2 \\sin x+2x\\cos x +C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int xe^x\\,dx$\n\\begin{sol}\n $\\ds (x-1)e^x +C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int xe^{x^2}\\,dx$\n\\begin{sol}\n $\\ds (1/2)e^{x^2} +C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int \\sin^2 x\\,dx$\n\\begin{sol}\n $(x/2)-\\sin(2x)/4 +C=$\\hfill\\break$(x/2)-(\\sin x\\cos x)/2+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int \\ln x\\,dx$\n\\begin{sol}\n $x\\ln x-x +C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int x\\arctan x\\,dx$\n\\begin{sol}\n $\\ds (x^2\\arctan x +\\arctan x -x)/2+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int x^3\\sin x\\,dx$\n\\begin{sol}\n $\\ds -x^3\\cos x+3x^2\\sin x+6x\\cos x-6\\sin x+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int x^3\\cos x\\,dx$\n\\begin{sol}\n $\\ds x^3\\sin x+3x^2\\cos x-6x\\sin x-6\\cos x+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int x\\sin^2 x\\,dx$\n\\begin{sol}\n $\\ds x^2/4-(\\cos^2 x)/4-(x\\sin x\\cos x)/2+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int x\\sin x\\cos x\\,dx$\n\\begin{sol}\n $\\ds x/4-(x\\cos^2 x)/2+(\\cos x\\sin x)/4+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int \\arctan(\\sqrt x)\\,dx$\n\\begin{sol}\n $x\\arctan(\\sqrt x)+\\arctan(\\sqrt x)-\\sqrt{x}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int \\sin(\\sqrt x)\\,dx$\n\\begin{sol}\n $2\\sin(\\sqrt x)-2\\sqrt x\\cos(\\sqrt x)+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int\\sec^2 x\\csc^2 x\\,dx$\n\\begin{sol}\n $\\sec x\\csc x-2\\cot x+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "78e21a6b0e474b6e8f11f4719fd674f0f174c0e0", "size": 26030, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7-techniques-of-integration/7-4-int-by-parts.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "7-techniques-of-integration/7-4-int-by-parts.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "7-techniques-of-integration/7-4-int-by-parts.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2794117647, "max_line_length": 517, "alphanum_fraction": 0.6585094122, "num_tokens": 9477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.8887587883361618, "lm_q1q2_score": 0.7224429724793876}}
{"text": "% -*- coding: utf-8 -*-\n\\section{Theorem}\n% --------------------------------------------------- Slide --\n\\subsection{Theorem Code}\n\\label{theoremCode}\n\\begin{frame}{Theorem}\n  There is also a group of blocks that are especially useful for presenting mathematics. For example the ‘theorem’ environment, the ‘corollary’ environment and the ‘proof’ environment.\n  \\begin{semiverbatim}\n    \\\\begin\\{theorem\\}[Pythagoras] \\newline\n      $ a^2 + b^2 = c^2$ \\newline\n    \\\\end\\{theorem\\} \\newline\n    \\\\begin\\{corollary\\} \\newline\n      $ x + y = y + x  $ \\newline\n    \\\\end\\{corollary\\} \\newline\n    \\\\begin\\{proof\\} \\newline\n      $\\omega +\\phi = \\epsilon $ \\newline\n    \\\\end\\{proof\\}\n  \\end{semiverbatim}\n\\end{frame}\n\n% --------------------------------------------------- Slide --\n\\subsection{Theorem Blocks}\n\\label{theoremBlocks}\n\\begin{frame}{Theorem Blocks}\n  \\begin{theorem}[Pythagoras]\n    $ a^2 + b^2 = c^2$\n  \\end{theorem}\n  \\begin{corollary}\n    $ x + y = y + x  $\n  \\end{corollary}\n  \\begin{proof}\n    $\\omega +\\phi = \\epsilon $\n  \\end{proof}\n  As definition, you can also use the custom one ``thm/cor'' which is defined in ``slides/usrdef.tex''.\n\\end{frame}\n", "meta": {"hexsha": "82e79553e0ef3115b48aa7e1cd095fdafce0140d", "size": 1165, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "200+ beamer 模板合集/math-beamer-master(数学类报告)/examples/theorem.tex", "max_stars_repo_name": "lemoxiao/Awesome-Beamer-Collection", "max_stars_repo_head_hexsha": "3ab28a23fb60cb0a97fcec883847e2d8728b98c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-07-30T04:09:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-24T09:27:26.000Z", "max_issues_repo_path": "Math-beamer/examples/theorem.tex", "max_issues_repo_name": "iydon/LaTeX_template", "max_issues_repo_head_hexsha": "776dfc82707dd495dc4efee42b759003a4811576", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-11-24T10:57:10.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-25T05:01:48.000Z", "max_forks_repo_path": "Math-beamer/examples/theorem.tex", "max_forks_repo_name": "iydon/LaTeX_template", "max_forks_repo_head_hexsha": "776dfc82707dd495dc4efee42b759003a4811576", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-11-02T03:10:26.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-12T04:13:23.000Z", "avg_line_length": 32.3611111111, "max_line_length": 184, "alphanum_fraction": 0.5836909871, "num_tokens": 353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7224285027759846}}
{"text": "\\chapter{Exploratory Data Analysis}\n\\chaptermark{EDA}\n\\label{sec:exploratory}\n\n\nIn this chapter, we give a short review of methods for \\emph{exploratory data analysis} (EDA), \\aka \\emph{descriptive statistics}.\\marginnote{Descriptive Statistics}\nRecall that our goal is an assumptions-free description of our data. \nEDA thus consist of computing interpretable summaries of the data, called \\emph{summary statistics}, and visualizations. \n\n\n\\section{Summary Statistics}\n\\label{sec:summary_statistics}\n\nWe now distinguish between summary statistics that apply to attributes, categorical by definition, and variables, continuous by definition. \n\n\n\\subsection{Summarizing Categorical Data}\n\n\\subsubsection{Univariate}\nSummarizing a vector of categorical data can naturally be done by tabulating it, i.e., computing the frequency and relative frequency of each category.\nClearly averages, medians, and the likes are incomputable, since categorical data has no ordering, nor does it admit simple operations such as summation.\n\n\\begin{extra}\nVariability of categorical data can clearly not be measured by its variance, since it does not admit a summation operation.\nIt is, however, possible to define different measures of variability that do apply.\nThe \\emph{entropy} is such an example.\\marginnote{Entropy}\n\\end{extra}\n\n\n\\subsubsection{Bivariate}\nGeneralizing the univariate case to bivariate, or multivariate, one can keep tabulating. I.e., compute the frequency, and relative frequency, of combinations of categories.\n\n\n\n\\subsection{Summarizing  Continuous Data}\nContinuous variables admit many more mathematical manipulations than categorical attributes. \n\n\n\\subsubsection{Univariate}\n\nWe start by presenting the most natural summaries of the data. Without going into the formal definition, we refer to them as \\emph{summary of location}.\\marginnote{Location Summaries}\nThese include:\n\n\\begin{definition}[The Mean]\nThe \\emph{mean}, or \\emph{average}, is defined as \n\\begin{align}\n\t\\bar{x}:= \\frac{1}{n}\\sum_{i=1}^{n} x_i\n\\end{align}\n\\end{definition}\n\n\\begin{definition}[The Median]\nThe median is the observation that is smaller than half of the sample and larger than half of the sample.\n\\end{definition}\n\n\\begin{definition}[$\\alpha$-Trimmed Mean]\nThe $\\alpha$-trimmed mean is the average of the observations left after ignoring the largest and the smallest $(100\\alpha) \\%$ of them.\n\\end{definition}\nThe \\naive average is the $0$-trimmed mean, and the median is the $0.5$-trimmed mean.\n\nFrom summaries of location, we move to summaries of \\emph{scale}. \\marginnote{Summary of Scale}\n\n\\begin{definition}[The Standard Deviation]\n\\begin{align}\n\ts(x):= \\sqrt{\\frac{1}{n-1} \\sum_{i=1}^{n} (x_i-\\bar{x})^2}.\n\\end{align}\n\\end{definition}\n\nFor the following, we require the definition of the sample quantiles, themselves \\textbf{not} a scale summary.\n\n\\begin{definition}[$\\alpha$ Quantile]\nThe $\\alpha$-quantile of a sample $x=(x_1,\\dots,x_n)$, denoted $x_\\alpha$, is the observation that is larger than $(100\\alpha)\\%$, and smaller then  $(100(1-\\alpha))\\%$ of the sample. \n\\end{definition}\nThe empirical maximum and minimum are then $x_{1.0}$ and $x_{0.0}$, respectively.\n\n\n\\begin{definition}[The Range]\n\\label{def:range}\n\\begin{align}\n\t\\range{x}:= \\max_i\\set{x_i}-\\min_i\\set{x_i}= x_{1.0}-x_{0.0}.\n\\end{align}\n\\end{definition}\n\n\\begin{definition}[The Inter Quantile Range- IQR]\n\\label{def:iqr}\n\\begin{align}\n\tIQR(x):= x_{0.75}-x_{0.25}.\n\\end{align}\n\\end{definition}\n\n\n\n\\begin{definition}[The Median Absolute Deviation- MAD]\n\\label{def:mad}\n\\begin{align}\n\tMAD(x):= c \\: \\set{|x-x_{0.5}|}_{0.5}.\n\\end{align}\nwhere $c$ is some constant.\nIn the \\R function \\rcode{mad()}, $c$ is set at $1.4826$ so that it estimates $\\sigma$ in a Gaussian population. \n\\end{definition}\n\nAfter summaries of scale, we move to summaries of \\emph{skewness}, or \\emph{asymmetry}.\n\n\\begin{definition}[Yule Skewness Measure]\n\\begin{align}\n\tYULE(x):= \\frac{\\frac{1}{2} (x_{0.75}+x_{0.25})-x_{0.5}}{\\frac 12IQR(x)}\n\\end{align}\n\\end{definition}\n\n \n\n\n\\subsubsection{Bivariate}\nFrom univariate data $x$, we move to bivariate $x,y$.\nClearly we can apply univariate summaries component-wise. \nWe want, however, to summarize the \\emph{joint} behaviour of the data. \nFor this purpose, we assume that data comes in pairs, implying that $x$ and $y$ are of same length.\n\n\n\\begin{definition}[Covariance]\nThe sample covariance, or \\emph{empirical} covariance is defined as\n\\begin{align}\n\tCov(x,y):= \\frac{\\sum_{i=1}^{n} (x_i-\\bar{x})(y_i-\\bar{y})}{n-1}\n\\end{align}\n\\end{definition}\n\n\n\n\\begin{definition}[Pearson's Correlation Coefficient]\n\\emph{Pearson’s Correlation Coefficient}, or \\emph{Pearson's Moment Product Correlation Coefficient}, is defined as\n\\begin{align}\n\tr(x,y):= \\frac{(n-1) Cov(x,y)}{S(x) S(y)}= \\frac{\\sum_{i=1}^{n} (x_i-\\bar{x})(y_i-\\bar{y})}{S(x) S(y)}\n\\end{align}\n\\end{definition}\nWe can dwell into the meaning and intuition underlying Pearson's correlation coefficient, but we will not. \nThe curious reader is reffered to \\cite{rodgers_thirteen_1988}.\n\nThe next measure of association captures a more general association.\n\\begin{definition}[Spearman's Correlation Coefficient]\nSpearman's correlation coefficient is merely Pearson's correlation coefficient computed on the \\emph{ranks} of $x$ and $y$. \n\\end{definition}\n\nWe conclude by noting that \\emph{regression coefficients} are also a measure of association. \n\n\n\n\n\n\\subsubsection{Multivariate Data}\nMultivariate data, both continuous (variables), and discrete (attributes), admits a vast realm of method for summary and visualization.\nClearly, associations between several variables can be very complicated so that the more we try to summarize, the more information we give up. On the other hand, and unlike the univariate and bivariate case, our minds will need some type of simplification since they cannot grasp the raw data (did you ever try to imagine how $\\mathbb{R}^4$ looks like?).\nAs usual, we emphasize that our purpose is to summarize the joint association in the data. \nFor component-wise summaries, we can always apply the univariate summaries one variable at a time. \n\nBy far the most popular measures of joint association are the covariance matrix and correlation matrix.\n\n\\begin{definition}[Covariance Matrix]\n\\label{def:covariance}\nFor multivariate data consisting of $x_1,\\dots,x_j,\\dots,x_p$ vectors, each with $n$ entries: $x_{j,1},\\dots,x_{j,n}$, we define the (sample) covariance matrix to be a $p\\times p$ matrix whose elements are the (sample) covariances between corresponding vectors:\n\\begin{align}\n\t\\hat{\\Sigma}_{k,l}:= Cov(x_k, x_l).\n\\end{align}\n\\end{definition}\n\n\n\\begin{extra}[Sample Covariance Matrix]\nThe matrix $\\hat{\\Sigma}$ has many useful properties. \nThe curious reader is referred to \\cite{petersen_matrix_2006}, and references therein, for more details.\n\\end{extra}\n\n\\begin{definition}[Correlation Matrix]\nFor multivariate data consisting of $x_1,\\dots,x_j,\\dots,x_p$ vectors, each with $n$ entries: $x_{j,1},\\dots,x_{j,n}$, we define the (sample) correlation matrix to be a $p\\times p$ matrix whose elements are the (Pearson) correlations between corresponding vectors:\n\\begin{align}\n\t\\hat{R}_{k,l}:= r(x_k, x_l)\n\\end{align}\n\\end{definition}\n\n\n\\begin{extra}[Multivariate Data Analysis]\nMultivariate analysis is an important, and very actively studied field in statistics and machine learning.\nA non-comprehensive list of methods that belong to this realm include \nPrincipal Component Analysis (PCA),\\marginnote{PCA, SVD,ICA}\nFactor Analysis (FA), \nIndependent Component Analysis (ICA),\nGraphical Models,\nDimensionality Reduction, \nManifold Learning, \nSelf Organizing Maps, \netc.\nAsk me for reference books or courses if this topic interests you.\n\\end{extra}\n\n\\afterpage{\\clearpage}\n\n\n\\section{Visualization}\n\\label{sec:visualizations}\n\n\\subsection{Visualizing Categorical Data}\n\n\n\n\\subsubsection{Univariate}\nMuch like computing summaries, there is not much to be said about visualizing univariate categorical variables. \nThe most natural, and perhaps only visualization, is the \\emph{bar plot}, illustrated in Figure~\\ref{fig:barplot}.\n\n\\begin{remark}[Pie Chart]\nAbout those pie charts. \nThere is really no reason to use them. Ever\\footnote{\\url{http://www.businessinsider.com/pie-charts-are-the-worst-2013-6}.}.\n\\end{remark}\n\n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[height=0.3\\textheight]{art/categorical-data1x}\n\\caption[Bar Plot]{The Bar-Plot. \\newline\n\\url{http://www.r-tutor.com/elementary-statistics/qualitative-data/bar-graph}}\n\\label{fig:barplot}\n\\end{figure}\n\n\n\n\\subsubsection{Bivariate}\nVisualizing a two-way cross-table can be done using an extension of the bar-plot.\nSeveral extensions exist. By far, the most informative and recommended figure, in this author's view, is the \\emph{mosaic plot}, illustrated in Figure~\\ref{fig:mosaic}. \\marginnote{Mosaic Plot}\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[height=0.3\\textheight]{art/mosaic1}\n\\caption[Mosaic Plot]{Mosaic Plot. \\newline\n\\url{http://www.statmethods.net/advgraphs/mosaic.html}}\n\\label{fig:mosaic}\n\\end{figure}\n\n\n\n\n\n\n\n\\afterpage{\\clearpage}\n\n\n\\subsection{Visualizing Continuous Data}\n\n\n\n\n\\subsubsection{Univariate}\nVisualization of univariate continuous vectors can present the raw data, or it distribution (i.e.- discarding the indexes).\nThe most basic visualizations are the \\emph{dotchart}, \\emph{histogram}, \\emph{boxplot}, \\emph{stem-and-leaf plot}. \nThese are illustrated in figures \\ref{fig:dot_plot}, \\ref{fig:histogram_eruptions}, \\ref{fig:boxplot}, \\ref{fig:stem_and_leaf} respectively. \n\n\n \n\\begin{figure}[h]\n\\centering\n\\includegraphics[height=0.3\\textheight]{art/lmCm0}\n\\caption[Dot Plot]{Dot Plot. \\newline \\url{http://stackoverflow.com/questions/15109822/r-creating-scatter-plot-from-data-frame}}\n\\label{fig:dot_plot}\n\\end{figure}\n\n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[height=0.3\\textheight]{art/histogram_eruptions}\n\\caption[Histogram]{Histogram. \nNotice the ticks on the x axis. These are the raw data points. Make sure you always add them, with the \\rcode{rug()} \\R command. \n\\newline \\url{http://compbio.pbworks.com/w/page/16252882/Basic}}\n\\label{fig:histogram_eruptions}\n\\end{figure}\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[height=0.3\\textheight]{art/ex6aout}\n\\caption[BoxPlot]{Boxplot. \\newline \\url{http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm}}\n\\label{fig:boxplot}\n\\end{figure}\n\n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[height=0.3\\textheight]{art/stem_and_leaf}\n\\caption[Stem and Leaf Pot]{Stem-and-leaf plot. \\newline\n\\url{https://www.mathsisfun.com/data/stem-leaf-plots.html}}\n\\label{fig:stem_and_leaf}\n\\end{figure}\n\n\n\n\n\\subsubsection{Bivariate}\nThe simultaneous visualization of two continuous variables, can naturally be done with a \\emph{scatter plot}.\nMore sophisticated visualization, which generalizes the histogram into two dimensions, is the \\emph{hexbin plot}.  \nThese are illustrated in figures \\ref{fig:scatterplot}, and \\ref{fig:hexbin}, respectively. \n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[height=0.3\\textheight]{art/scatterplot}\n\\caption[Scatter Plot]{Scatter Plot. \\newline \n\\url{http://texample.net/tikz/examples/scatterplot/}}\n\\label{fig:scatterplot}\n\\end{figure}\n\n\n\n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[height=0.3\\textheight]{art/hexbin2}\n\\caption[HexBin Plot]{HexBin plot (a 2D histogram).\n\\newline \\url{http://www.r-bloggers.com/5-ways-to-do-2d-histograms-in-r/}}\n\\label{fig:hexbin}\n\\end{figure}\n\n\n\n\n\n\n\\subsubsection{Multivariate Data}\nSince we cannot possibly visualize data in more than $3$-dimensions, and we clearly prefer data in $1$ or $2$ dimensions, the visualization of multivariate data will typically consist of summarizing the data into $1D$ or $2D$, and then applying the above mentioned visualization techniques.\n\nAn important exception is due to the observation that a computer image, is essentially a matrix. \nWe can thus visualize matrices, with a simple image, and in particular, covariance and correlation matrices, as illustrated in Figure~\\ref{fig:covariance_image}.\n\nA second exception is when the data has both continous variables and discrete attributes. \nEndlessly many combinations are then possible.\nThe author strongly recommends to visit Hans Rosling's \\emph{Gap Minder} at \\url{http://www.gapminder.org/world} for an excellent interactive visualization. \\marginnote{Gap Minder}\n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[height=0.3\\textheight]{art/covarianceSupervised}\n\\caption[Covariance Matrix]{Image of covariance matrix. \\newline\n\\url{http://cs.brown.edu/courses/csci1950-g/results/final/sghosh/}}\n\\label{fig:covariance_image}\n\\end{figure}\n\n\n\n\n\\subsection{On-Line Visualization}\nFor the purpose of quality control, we may often want an \\emph{on-line} visualization, and not \\emph{off-line}, as the ones previously discussed.\nThis is the purpose of \\emph{dashboards}, illustrated in Figure~\\ref{fig:dashboard}.\\marginnote{Dashboard}\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[height=0.3\\textheight, width=0.9\\linewidth]{art/dashboard}\n\\caption[Dashboard]{Dashboard. \\newline\n\\url{http://www.iconics.com/Home/Products/AnalytiX/Quality-AnalytiX.aspx}}\n\\label{fig:dashboard}\n\\end{figure}\n\n\\afterpage{\\clearpage}\n", "meta": {"hexsha": "b195e6057822e6230334ab3322336ea0bd555a9f", "size": 13231, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Class_notes/exploratory.tex", "max_stars_repo_name": "johnros/qualityEngineering", "max_stars_repo_head_hexsha": "4a1c0959672fb5c5a6e59829e543c95beb4e5b44", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Class_notes/exploratory.tex", "max_issues_repo_name": "johnros/qualityEngineering", "max_issues_repo_head_hexsha": "4a1c0959672fb5c5a6e59829e543c95beb4e5b44", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Class_notes/exploratory.tex", "max_forks_repo_name": "johnros/qualityEngineering", "max_forks_repo_head_hexsha": "4a1c0959672fb5c5a6e59829e543c95beb4e5b44", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.7527777778, "max_line_length": 354, "alphanum_fraction": 0.7659285012, "num_tokens": 3625, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.8539127566694177, "lm_q1q2_score": 0.7223610386257597}}
{"text": "\\documentclass[paper-main.tex]{subfiles}\n\n\\begin{document}\n\n\n\n\\section{Open-source code}\n\\label{app:code}\nThis project is implemented in Python 3 scripts and jupyter notebooks and MATLAB. \nWe refer the reader to the Supplementary Material for software references. \nThe current build and sample data can be found at:\n\\url{https://github.com/daccordeon/gravexplain}\n\n\n\n\n\n\n\n\\section{Detecting a sinusoidal signal in Gaussian noise}\n\\label{app:sinusoid_likelihood}\n\n\nIn this appendix, we demonstrate that the modulus of the Fourier transform is an appropriate detection statistic when searching for a sinusoidal signal in Gaussian noise. \nWe describe the data as\n\\begin{equation}\nx(t) = s(t) + n(t)\\,, \n\\label{eqn:GNdata}\n\\end{equation}\nwhere $s(t)$ and $n(t)$ are the signal and noise, respectively.\nThe signal takes the form\n\\begin{equation}\ns(t) = A \\cos\\left[{\\omega t + \\phi}\\right]\\,,\n\\label{eqn:GNmodel}\n\\end{equation}\nwhere $A$, $\\omega$, and $\\phi$ are the amplitude, angular frequency and phase of the signal, respectively. \nThe noise $n(t)$ is a fluctuating zero-mean time series with the following property: if we define an inner product between two arbitrary time series $u(t)$ and $v(t)$ as \n\\begin{equation}\n\\ip{u}{v} = \\frac{1}{T} \\int_0^T \\mathrm{d} t \\, u(t) v(t)\\,,\n\\label{eqn:ipuv}\n\\end{equation}\nwhere $T$ is the total time of the observation, then the likelihood $\\mathcal{L}$ of measuring the noise-noise product $\\ip{n}{n}$ is given by \n\\begin{equation}\n\\mathcal{L} = \\exp\\left( -\\frac{1}{2}\\ip{n}{n}\\right)\\,.\n\\label{eqn:ipnn}\n\\end{equation}\nEquations~\\ref{eqn:ipuv} and~\\ref{eqn:ipnn} define what it means for noise to be Gaussian through the fundamental measurement of $\\ip{n}{n}$.\n\n\n\n\n\nThe likelihood of measuring the signal $s(t)$ in the presence of noise follows from Eqns.~\\ref{eqn:GNdata} and~\\ref{eqn:ipnn} by replacing $n(t)$ in Eqn.~\\ref{eqn:ipnn} with $x(t) - s(t) = n(t)$ from Eqn.~\\ref{eqn:GNdata}.~\\cite{JKS:1998,Jaynes:2003}\nThe result is\n\\begin{eqnarray}\n\\mathcal{L} &=& \\exp\\left( -\\frac{1}{2}\\ip{x-s}{x-s} \\right) \\label{eqn:likeOne}\\,, \\\\ \n            &=& \\exp\\left( -\\frac{1}{2}\\ip{x}{x} - \\frac{A^2}{2} \\ip{\\cos[\\omega t + \\phi]}{\\cos[\\omega t + \\phi]} \\right. \\nonumber\\\\\n                 &&\\hspace{3em} \\left. +  A \\ip{x}{\\cos[\\omega t + \\phi]} \\vphantom{\\frac12}\\right) \\,,\\\\ \n                 &=& \\exp \\left( -\\frac{1}{2}\\ip{x}{x} - \\frac{A^2}{4} + A \\ip{x}{\\cos[\\omega t + \\phi]} \\right)\\,.\\label{eqn:logLike}\n\\end{eqnarray}\nWe then maximise Eqn~.\\ref{eqn:logLike} with respect to $A$, obtaining \n\\begin{eqnarray}\n\\label{eqn:maxLogLike}\n\\mathcal{L}_\\mathrm{max} = \\exp \\left( - \\frac{1}{2} \\ip{x}{x} + \\ip{x}{\\cos[\\omega t + \\phi]}^2 \\right)\\,,\n\\end{eqnarray}\nfor $A = 2\\ip{x}{\\cos[\\omega t + \\phi]}$.\nFrom the second term of Eqn.~\\ref{eqn:maxLogLike}, we see that the maximum likelihood of a sinusoidal signal in Gaussian noise is the modulus of the cosine Fourier transform, plus the term $\\ip{x}{x}$, which is independent of $\\omega$ and $\\phi$ and can therefore be ignored when searching over $\\omega$.\n\nTwo important points must be made about the above procedure. \n(i) Fundamentally the goal is to maximize $\\mathcal{L}$ in Eqn.~\\ref{eqn:likeOne} by varying $s(t)$ through $A$.\nFor the special case of the Gaussian likelihood (Eqn.~\\ref{eqn:ipnn}), which peaks at $\\ip{n}{n}= 0$, this is equivalent to minimizing the difference between $x(t)$ and $s(t)$ as evident in Eqn.~\\ref{eqn:ipuv}.\nIn general, however, minimizing the difference between $x(t)$ and $s(t)$ is not equivalent always to the fundamental goal of maximising $\\mathcal{L}$, for example if $\\mathcal{L}$ peaks at $\\ip{n}{n} \\neq 0$, or if $\\mathcal{L}$ has multiple maxima.\n(ii) The maximum likelihood $\\mathcal{L}_{\\rm max}$ in Eqn.~\\ref{eqn:maxLogLike} (or equivalently its logarithm) defines the detection statistic. \nWhen its value exceeds a threshold (chosen freely by the analyst) at some value of $\\omega$, a signal is deemed to have been detected at that value of $\\omega$.\nTherefore the specific functional form of Eqn.~\\ref{eqn:maxLogLike} matters, which is a second reason why one must start from Eqn.~\\ref{eqn:ipnn} rather than Eqn.~\\ref{eqn:likeOne}, in addition to reason (i).\n\n\n\n\n\\section{Viterbi algorithm}\n\\label{app:viterbi}\nThis appendix contains some details regarding the implementation of the Viterbi algorithm described in Section~\\ref{sec:viterbi}. \nThe Viterbi algorithm~\\cite{Viterbi:1967} is a classic method in signal processing, whose theoretical underpinnings and implementation are accessible to undergraduate students. \nSee the Supplementary Material for further resources and other pseudocode examples available online.\n\nHere, we present some pseudocode (below) of the implementation used in Section~\\ref{sec:viterbi}. We use Fourier amplitudes, normalized between $(0, 1)$ by dividing by the maximum value in the grid, as multiplicative weights. \nTo avoid numerical underflow we take the logarithm of the Fourier amplitudes, which we can equivalently use as additive weights.\n\n\nLet $X$ be a grid of $j=0,\\ldots,N_f$ rows and $i=0,\\ldots,N_t$ columns of additive weights for each node. Let Y and Z be grids of the same shape to store the weight of the best path to each node and the row index of the previous node on that path, respectively. Let W be a length $N_t+1$ array to store the final sequence of row indices for the optimal path. We restrict paths to only move one cell up or down at a time (or stay constant). For the boundary cases of $j=0,N_f$, we only search over $k \\in \\{0,1\\}$ and $k \\in \\{-1,0\\}$, respectively, to stay inside the grid (this is not shown in the pseudocode below).\n\n\\begin{algorithmic}\n\\Function{Viterbi}{$X$}\n    % \\State $a \\gets a+1$\n    % \\State \\Return $a$\n\n    \\For{each row $j=0,\\ldots,N_f$}\n\t\t\\State $Y_{0,j} \\gets X_{0,j}$\n    \\EndFor\n\n    \\For{each column $i=1,\\ldots,N_t$}\n\t    \\For{each row $j=0,\\ldots,N_f$}\n\t\t\n\t    \t\\State $Y_{i,j} \\gets X_{i,j} + \\underset{k \\in \\{-1,0,1\\}}{\\max} (Y_{i-1,j+k})$\n\t    \t\\State $Z_{i,j} \\gets j + \\underset{k \\in \\{-1,0,1\\}}{\\arg\\max} (Y_{i-1,j+k})$\n   \n\t    \\EndFor\n    \\EndFor\n\n    \\State $W_{N_t} \\gets \\underset{j=0,\\ldots,N_f}{\\arg\\max} (Y_{N_t,j})$\n\n    \\For{each col $i=N_t-1,\\ldots,0$}\n\n\t\t\\State $W_i \\gets Z_{i+1, W_{i+1}}$\n\n    \\EndFor    \n\n    \\State \\Return $W$\n\\EndFunction\n\\end{algorithmic}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "edf80575ede32f270cbf5aec6a63f5c65379e48a", "size": 6352, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/ifo-appendix.tex", "max_stars_repo_name": "daccordeon/gravexplain", "max_stars_repo_head_hexsha": "4fb188b8bb37ba2c4f2b8eaf2ef478d278bbad09", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-26T21:44:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T14:36:34.000Z", "max_issues_repo_path": "paper/ifo-appendix.tex", "max_issues_repo_name": "daccordeon/gravexplain", "max_issues_repo_head_hexsha": "4fb188b8bb37ba2c4f2b8eaf2ef478d278bbad09", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 20, "max_issues_repo_issues_event_min_datetime": "2019-11-26T21:46:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-11T06:46:14.000Z", "max_forks_repo_path": "paper/ifo-appendix.tex", "max_forks_repo_name": "daccordeon/gravexplain", "max_forks_repo_head_hexsha": "4fb188b8bb37ba2c4f2b8eaf2ef478d278bbad09", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.816, "max_line_length": 618, "alphanum_fraction": 0.6948992443, "num_tokens": 2032, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.85391273808085, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7223610262174582}}
{"text": "\\chapter{Sets}\n\nSets are one of the most basic mathematical tools. The purpose of this\nchapter is to define sets, and do basic reasoning about them. We're\nalso going to give a loose definition of common sets we deal\nwith. Spoiler: it will later turn out that much of what we do in this\nchapter is actually wrong, and can lead to some\ncontradictions.\\footnote{If you're really impatient, and can't wait\n  for another chapter, you can read the \\link{Wikipedia page on\n    Russell's\n    paradox}{https://en.wikipedia.org/wiki/Russell\\%27s_paradox}}\n\nSets are collections of objects. The easiest way to denote sets is to\nlist their elements between curly braces: $\\braces{}$.\n\n\\begin{displaymath}\n  \\mset{1,2,3,4}\n\\end{displaymath}\n\nThere is no notion of duplication or order, so all of the following\nsets are the same\n\n\\begin{tabu}{rp{5.5cm}}\n  $\\mset{1,2,3,4}$         & \\\\\n  $\\mset{1,1,2,2,3,3,4,4}$ & (Each element is duplicated.) \\\\\n  $\\mset{2,1,4,3,4,4,1}$   & (The order is different, and some of the elements are duplicated.)\n\\end{tabu}\n\nThere's a set with no elements, called the ``null set'', or the\n``empty set'', or a variety of other names. It's usually denoted\n$\\emptyset$, $\\phi$, or some variant thereof. I'm going to use $\\nil$.\n\nFirst of all, if we have a set $A$ and an object $x$, and $x$ is an\nelement of $A$, we'll write $x \\in A$. Note: I've have an old textbook\nthat uses the Greek letter epsilon ($\\epsilon$ or $\\varepsilon$) in\nplace of $\\in$. The $\\in$ symbol kind of looks like an `E', which you\ncan mentally associate with ``element''. The symbol $\\in$ can be read\nas ``is an element of''. If some potential element $y$ is \\xtb{not} in\n$A$, then we'll write $y \\notin A$.\\footnote{As a general rule, if you\n  have some symbol that indicates that something is true, crossing out\n  the symbol indicates that thing is false.}\n\nContinuing with the above example, we have the set\n$\\mset{1,2,3,4}$. We have\n\n\\begin{displaymath}\n  1 \\in \\mset{1,2,3,4}\n\\end{displaymath}\n\nbut\n\n\\begin{displaymath}\n  5 \\notin \\mset{1,2,3,4}\n\\end{displaymath}\n\nWe can have sets that have infinitely many elements. For instance, the\n``natural numbers'', usually denoted with $\\N$, are\ninfinite.\\footnote{Conventions differ on whether or not $\\N$ includes\n  $0$. It doesn't matter all that much, especially as far as this book\n  is concerned.} These are positive whole numbers (i.e. not fractions\nor decimals).\n\n\\begin{displaymath}\n  \\N = \\mset{1,2,3,4,\\dots}\n\\end{displaymath}\n\nThe ``integers'' are any whole numbers, which include $0$ and negative\nnumbers. The integers are usually denoted with $\\Z$. The $\\Z$ stands\nfor ``Zahlen'', which is German for ``numbers''.\\footnote{I heard this\n  from a professor once. If it's wrong, blame him.}\n\n\\begin{displaymath}\n  \\Z = \\mset{\\dots, -3, -2, -1, 0, 1, 2, 3, \\dots}\n\\end{displaymath}\n\n\\section{Set comprehensions}\n\nBefore we go much further, I want to introduce the notion of a ``set\ncomprehension'', or ``set builder notation''. The basic format is this:\n\n\\begin{displaymath}\n  \\scomp{\\text{\\xtb{What each element looks like}}}{\\text{\\xtb{Conditions}}}\n\\end{displaymath}\n\nThe ``conditions'' are just things that have to hold true about the\nelement.\n\nHere are some examples:\n\n\\begin{displaymath}\n  \\scomp{x \\in \\N}{x < 5} = \\mset{1,2,3,4}\n\\end{displaymath}\n\\begin{displaymath}\n  \\scomp{2x \\in \\N}{x < 5} = \\mset{2,4,6,8}\n\\end{displaymath}\n\\begin{displaymath}\n  \\scomp{x \\in \\Z}{x < 5} = \\mset{\\dots,-3,-2,-1,0,1,2,3,4}\n\\end{displaymath}\n\nEach set comprehension should be read in two parts: the part before\nthe colon, and the part after the colon.\n\n\\begin{itemize}\n\\item $x \\in \\N$ means that we are choosing\\footnote{Yes, we'll get to\n    the axiom of choice later. Calm down.} elements of $\\N$, and we're\n  calling the element $x$.\n\\item $x < 5$ means that we are choosing all elements of $\\N$ which\n  are less than $5$. In the part before the colon, we are choosing one\n  such element as an example, and calling it $x$.\n\\end{itemize}\n\n\\subsection{Trying these on your computer}\n\nMany programming languages have ``list comprehensions'', which are\nconceptually similar to set comprehensions. For instance, in Haskell,\nwe can construct the equivalent of our sets from above like this:\n\n\\begin{lstlisting}[language=Haskell,caption={The sets from above, in Haskell}]\nghci> [ x | x <- [1..4] ]\n[1,2,3,4]\nghci> [ 2*x | x <- [1..4] ]\n[2,4,6,8]\n\\end{lstlisting}\n\nIn Python, the syntax is a bit different, but:\n\n\\begin{lstlisting}[language=Python,caption={The same thing in Python}]\n>>> [ x for x in range(1,5) ]\n[1, 2, 3, 4]\n>>> [ 2*x for x in range(1,5) ]\n[2, 4, 6, 8]\n\\end{lstlisting}\n\nYou probably already have Python installed on your system. Open a\nterminal, and run the command \\monospace{python} (hit Enter after\ntyping ``python''). If not, try following the instructions here:\n\\barelink{https://wiki.python.org/moin/BeginnersGuide/Download}.\n\nYou probably do \\xtb{not} have Haskell installed on your system,\nunless you installed it on purpose. You can find documentation on how\nto install Haskell here: \\barelink{http://haskellstack.org/}.\n\n\\subsubsection{Lists v. Sets}\n\nLists are different from sets, because, in a list, order and\nduplication matter. You can test this out in Haskell like this:\n\n\\begin{lstlisting}[language=Haskell,caption={List equality in Haskell}]\nghci> [1,2,3,4] == [1,2,3,4]\nTrue\nghci> [1,2,3,4] == [4,3,2,1]\nFalse\nghci> [1,2,3,4] == [1,2,3,1,3,3,1,4,2]\nFalse\n\\end{lstlisting}\n\nHaskell actually has a type for sets, called \\monospace{Set}. To turn\na list into a set, you use the function \\monospace{fromList}\n\n\\begin{lstlisting}[language=Haskell,caption={Set equality in Haskell}]\nghci> import Data.Set\nghci> fromList [1,2,3,4] == fromList [1,2,3,4]\nTrue\nghci> fromList [1,2,3,4] == fromList [4,3,2,1]\nTrue\nghci> fromList [1,2,3,4] == fromList [1,4,3,1,2]\nTrue\n\\end{lstlisting}\n\n\\section{Rational and Real Numbers}\n\nThe reason I introduced the set comprehension notation is because (1)\nit's useful and important, and (2) it's convenient to define the\nrational numbers (numbers that can be expressed as a ratio of two\nintegers) like this:\n\n\\begin{displaymath}\n  \\Q = \\scomp{\\frac{x}{y} \\in \\R}{x, y \\in \\Z; y \\ne 0}\n\\end{displaymath}\n\nRemember, kids: \\xtb{you can't divide by zero}, hence the $y \\ne 0$\npart. The notation $x, y \\in \\Z$ is just shorthand for $x \\in \\Z$ and\n$y \\in \\Z$. Mathematicians are incredibly lazy, so you'll often see\nconfusing notational shorthand used as a replacement for actually\nexplaining an idea. The symbol $\\R$ refers to the ``real\nnumbers''. The symbol $\\Q$ stands for ``quotient''.\n\nRational numbers are numbers that can be expressed as a ratio of two\nintegers. Real numbers turn out to be really hard to define. You can\nfor now think of a real number as any number that can be written down,\nsupposing one had infinite paper, ink, and time. For instance, $\\pi$\ncannot be expressed as the ratio of two integers, but is a real\nnumber.\n\n\\subsection{Numerical representations of Real numbers}\n\nAs it turns out, this definition of real numbers doesn't work! The\nreason is, there are cases where you write down two different numbers,\nand they refer to the same number.\n\n(I stole this example from a professor of mine, Peter Alfeld, who\npresumably stole it from someone else.\\cite{pa-unique})\n\n\\begin{example}[Issues with numerical representations of real numbers]\n  Consider the number $x = 0.9999999\\dots$. We can multiply by\n  $10$. To do so, we just move everything one digit to the left.\n\n  \\begin{rclmath}\n      x & = & 0.99999\\dots \\\\\n    10x & = & 9.99999\\dots \\\\\n  \\end{rclmath}\n\n  Well, we can take $9x = 10x - x$, and get this\n\n  \\begin{rclmath}\n    10x & = & 9.99999\\dots \\\\\n      x & = & 0.99999\\dots \\\\\n     9x & = & 9 \\\\\n  \\end{rclmath}\n\n  We get this because every single digit to the right of the decimal\n  point cancels. We can take $x = \\frac{9x}{9}$ and get\n\n  \\begin{rclmath}\n     9x & = & 9 \\\\\n      x & = & 1 \\\\\n  \\end{rclmath}\n\n  This is a silly example, and doesn't constitute a ``proof''. However,\n  it should give you a glimpse at why numerical representations of real\n  numbers are problematic.\n\\end{example}\n\nHere's another example, which I stole from LeRoy Eide (he showed me\nthis in person).\n\n\\begin{example}[Issues with numerical representations of integers]\n  Take a number that begins with an endless string of $9$s to the\n  left.\n\n  \\begin{displaymath}\n    x = \\dots99994\n  \\end{displaymath}\n\n  Let's take $x + 6$.\n\n  \\begin{displaymath}\n    \\begin{tabu}{rr}\n        & \\dots99994 \\\\\n      + & 6 \\\\\n      \\tabucline \\\\\n      = & 0 \\\\\n    \\end{tabu}\n  \\end{displaymath}\n\n  Try it! You add the $6$ to the $4$, and get $10$. Fair enough, put\n  $0$ and carry the $1$\n\n  \\tabulinesep=0ex\n  \\begin{displaymath}\n    \\begin{tabu}{rr}\n        & \\text{1\\hspace{2.1mm}}  \\\\\n        & \\dots99994 \\\\\n      + & 6 \\\\\n      \\tabucline \\\\\n      = & 00 \\\\\n    \\end{tabu}\n  \\end{displaymath}\n\n  Let's try it again\n\n  \\begin{displaymath}\n    \\begin{tabu}{rr}\n        & \\text{1\\hspace{0.9mm}1\\hspace{2.1mm}}  \\\\\n        & \\dots99994 \\\\\n      + & 6 \\\\\n      \\tabucline \\\\\n      = & 000 \\\\\n    \\end{tabu}\n  \\end{displaymath}\n\n  Continue this process...\n\n  \\begin{displaymath}\n    \\begin{tabu}{rr}\n        & \\text{\\dots 1\\hspace{0.9mm}1\\hspace{0.9mm}1\\hspace{0.9mm}1\\hspace{2.1mm}}  \\\\\n        & \\dots99994 \\\\\n      + & 6 \\\\\n      \\tabucline \\\\\n      = & \\dots 00000 \\\\\n    \\end{tabu}\n  \\end{displaymath}\n\n  Therefore, we conclude that $\\dots999994 + 6 = 0$, and therefore\n  that $\\dots99994 = -6$.\n\\end{example}\n\nNote, we do use infinite carry all the time. For instance, it's why\n\n\\begin{displaymath}\n  \\frac{2}{3} + \\frac{1}{3} = 0.666\\dots + 0.333\\dots = 0.999\\dots = 1\n\\end{displaymath}\n\nInfinite carry actually follows nicely from something called\n``mathematical induction''. I'll explain induction in a later chapter.\n\n\\begin{example}(More insanity with numbers)\n  We can take this a step further, and combine the two cases.\n\n  Let's look at $x = \\dots99994$, and examine what happens when we\n  take $\\frac{x}{100}$.\n\n  \\begin{displaymath}\n    \\frac{x}{100} = \\dots999.94\n  \\end{displaymath}\n\n  Let's look at $\\frac{x}{10}$\n\n  \\begin{displaymath}\n    \\frac{x}{10} = \\dots999.4\n  \\end{displaymath}\n\n  Well, remember $\\frac{x}{10} = \\frac{10x}{100}$. Let's let\n  $y = \\frac{x}{100}$. Therefore, $10y = \\frac{x}{10}$. Let's do what\n  we did before, and take $10y - y$\n\n  \\begin{displaymath}\n    \\begin{tabu}{rr}\n        & \\dots999.4\\text{\\hspace{2mm}} \\\\\n      - & \\dots999.94 \\\\\n      \\tabucline \\\\\n      = & -0.54 \\\\\n      = & -\\frac{54}{100} \\\\\n    \\end{tabu}\n  \\end{displaymath}\n\n  Now we have that $9y = -\\frac{54}{100}$. Therefore, $y =\n  -\\frac{6}{100} = -\\frac{3}{50}$. However, we had that $y =\n  \\frac{x}{10}$, and therefore $10y = x$. Thus, we have\n\n  \\begin{displaymath}\n    x = -\\frac{3}{5} = -0.6\n  \\end{displaymath}\n\n  Remember, before, we proved $x = -6$.\n\\end{example}\n\nThe problem here is that \\xtb{decimal (base $10$) representations of\n  real numbers are not unique}. That sounds like a contradiction, but\nit really isn't. It turns out, and we might prove this later, that you\ncan tweak the rules of writing numbers down to make decimal\nrepresentations unique. For decimal numbers, we assert that the number\ncan't begin or end with an infinite string of $9$s.\n\n\\section{Unions and Intersections}\n\\section{Differences}\n\\section{De Morgan's Laws}\n", "meta": {"hexsha": "1d2dd64d71a7393fc18e7a3b075302dabe5d22f8", "size": 11374, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/2.tex", "max_stars_repo_name": "pharpend/sets-logics", "max_stars_repo_head_hexsha": "ff0aee4c32fe50c54e32c99b703fa2c0ddac0ec2", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/2.tex", "max_issues_repo_name": "pharpend/sets-logics", "max_issues_repo_head_hexsha": "ff0aee4c32fe50c54e32c99b703fa2c0ddac0ec2", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/2.tex", "max_forks_repo_name": "pharpend/sets-logics", "max_forks_repo_head_hexsha": "ff0aee4c32fe50c54e32c99b703fa2c0ddac0ec2", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7709497207, "max_line_length": 95, "alphanum_fraction": 0.6801477053, "num_tokens": 3612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7222485800670024}}
{"text": "% -*- root: Main.tex -*-\n\\section{SVD}\n$\\mathbf{A} = \\mathbf{U} \\mathbf{D} \\mathbf{V}^\\top = \\sum_{k=1}^{\\operatorname{rank}(\\mathbf{A})} d_{k,k} u_k (v_k)^\\top$\\\\\n$\\mathbf{A} \\in \\mathbb{R}^{N \\times P}, \\mathbf{U} \\in \\mathbb{R}^{N \\times N}, \\mathbf{D} \\in \\mathbb{R}^{N \\times P}, \\mathbf{V} \\in \\mathbb{R}^{P \\times P}$\\\\\n$\\mathbf{U}^\\top \\mathbf{U} = I = \\mathbf{V}^\\top \\mathbf{V}$ ($\\mathbf{U}, \\mathbf{V}$orthonormal)\\\\\n$\\mathbf{U}$ columns are eigenvectors of $\\mathbf{A} \\mathbf{A}^\\top$, $\\mathbf{V}$ columns are eigenvectors of $\\mathbf{A}^\\top \\mathbf{A}$, $\\mathbf{D}$ diagonal elements are singular values.\\\\\n$(\\mathbf{D}^{-1})_{i,i} = \\frac{1}{\\mathbf{D}_{i, i}}$ (don't forget to transpose)\n\n1. calculate $\\mathbf{A}^\\top \\mathbf{A}$.\\\\\n2. calculate eigenvalues of $\\mathbf{A}^\\top \\mathbf{A}$, the square root of them, in descending order, are the diagonal elements of $\\mathbf{D}$.\\\\\n3. calculate eigenvectors of $\\mathbf{A}^\\top \\mathbf{A}$ using the eigenvalues resulting in the columns of $\\mathbf{V}$.\\\\\n4. calculate the missing matrix: $\\mathbf{U} = \\mathbf{A} \\mathbf{V} \\mathbf{D}^{-1}$.\\\\\n5. normalize each column of $\\mathbf{U}$ and $\\mathbf{V}$.\ncomputational cost = $O(mn^2 + m^2n), m\\geq n$\n\\subsection*{Low-Rank approximation}\nUsing only $K$ largest eigenvalues and corresponding eigenvectors. $\\tilde{\\mathbf{A}}_{i, j} = \\sum_{k=1}^K \\mathbf{U}_{i, k} \\mathbf{D}_{k,k} \\mathbf{V}_{j, k} = \\sum_{k=1}^K \\mathbf{U}_{i, k} \\mathbf{D}_{k,k} (\\mathbf{V}^\\top)_{k, j}$.\n\n\\subsection*{Eckart-Young Theorem}\n$\\min_{rank(B)=K} ||A-B||_F^2 = ||A-A_k||_F^2 = \\sum_{r=k+1}^{rank(A)} \\sigma_r^2$\n$\\min_{rank(B)=K} ||A-B||_2 = ||A-A_k||_2 = \\sigma_{k+1}$\n\n\\subsection*{Linear Auto-encoder}\nBy EY, the optimal $C,D$ matrices s.t. $\\hat X = DCX$ are $C=AU_k^\\top, D=U_kA^{-1}$ with $A$ a rotation matrix $\\rightarrow$low interpretability of the latent space and allow weight sharing $C=D^\\top$ w/o loss of generality.\n\n\\subsection*{SVD Thresholding}\n$\\textbf{B}^* = shrink_\\tau (\\textbf{A}) := \\text{argmin}_\\textbf{B}\\left[\\frac{1}{2}\\|A-B\\|_F^2+\\tau \\|B\\|_*\\right]$ \\\\\n$D_\\tau = diag(max(0, \\sigma_i - \\tau))$ \\\\\nproj. op: $\\Pi(\\textbf{X}) = x_{ij}$ if $(i,j) \\in I$ else $0$ \\\\\n$ \\textbf{B}_{t+1} = \\textbf{B}_t + \\eta_t \\Pi(A - schrink_\\tau (\\textbf{B}_t)) $", "meta": {"hexsha": "ab8be196959ec52d0bdffed1ba4b075abd519def", "size": 2281, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SVD.tex", "max_stars_repo_name": "Emilien-P/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "ebda1cb98b2e3d17e055b05cb0fd1e7decce507f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-17T18:13:31.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-17T18:13:31.000Z", "max_issues_repo_path": "SVD.tex", "max_issues_repo_name": "Emilien-P/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "ebda1cb98b2e3d17e055b05cb0fd1e7decce507f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SVD.tex", "max_forks_repo_name": "Emilien-P/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "ebda1cb98b2e3d17e055b05cb0fd1e7decce507f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 78.6551724138, "max_line_length": 238, "alphanum_fraction": 0.6273564226, "num_tokens": 947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.7222031658945768}}
{"text": "\\chapter{Appendix - Math Prerequisites}\n\\label{appendix:gmm_log_prob}\nFor a two-dimensional \\ac{GMM} $g \\sim GMM(\\mu, \\Sigma, \\pi, \\rho)$ with mean vector $\\mu$, variance matrix $\\Sigma$, mode importance vector $\\pi$ and Pearson's correlation coefficients $\\rho$ the probability at $(x, y)$ can be computed as:\\footnote{\\href{https://de.wikipedia.org/wiki/Mehrdimensionale_Normalverteilung}{Wikipedia - Multivariate Normal Distribution}}.\n\n\\begin{align}\nf_m(x, y | \\mu, \\sigma, \\rho) \n&= \\frac{1}{2 \\pi \\sqrt{\\det \\Sigma}} \\exp \\left(- \\frac{1}{2} (\\boldsymbol{x} - \\boldsymbol{\\mu})^T \\Sigma (\\boldsymbol{x} - \\boldsymbol{\\mu}) \\right) \\\\\n&= {\\frac{\\sqrt{1- \\rho^2}}{2 \\pi \\sigma_x \\sigma_y} \n\\exp - \\frac{1}{2 (1 - \\rho^2)}} \\left( \\frac{( x - \\mu _x)^2}{\\sigma_x^2} +\n\\frac {(y - \\mu_y)^2}{\\sigma_y^2}-{\\frac {2\\rho (x - \\mu_x)(y - \\mu_y)}\n{\\sigma_x \\sigma_y}} \\right)\t\n\\end{align}\n\nThe Pearson coefficient is the covariance for two normalized random variables $X$ and $Y$, in their normalized form $\\tilde{X} = (X - \\mu_x)/\\sigma_x$ and $\\tilde{Y} = (Y - \\mu_y) / \\sigma_y$. Using the law of linear transformations of covariances we get:\\footnote{\\href{https://en.wikipedia.org/wiki/Pearson_correlation_coefficient}{Wikipedia - Pearson correlation coefficient}} \n\n\\begin{equation}\nCov(\\tilde{X}, \\tilde{Y}) = \\frac{1}{\\sigma_x \\sigma_y} Cov(X, Y) = \\rho_{X, Y}\n\\end{equation}\n\nThe expected value over all modes $m \\in [0, M]$ super-imposes the \\ac{PDF} for the bi-variate Gaussian distributions, weighting each one by its importance $\\pi_m$:\n\n\\begin{equation}\n\\mathbb{E}_{GMM}[x, y] = \\sum_{m=0}^M \\pi_m \\cdot f_m(x, y) =  \\sum_{m=0}^M \\exp \\left( \\log \\pi_m + \\log f_m(x, y) \\right)\t\n\\end{equation}\n\n\n\\chapter{Appendix - Detailed Planning Approach Comparison}\nThere are several categories from which the properties of planning approaches can be evaluated: \n\n\\begin{itemize}\n    \\item Optimality: trajectory cost vs minimal possible (optimal) cost\n    \\begin{itemize}\n        \\item globally: $J(x(t), u(t)) = J^*(x(t), u(t)) \\forall t$\n        \\item locally: $J(x(t), u(t)) \\approx J^*(x(t), u(t)) \\forall x(t) + \\epsilon, u(t) + \\epsilon $\n        \\item not at all\n    \\end{itemize}\n    \n    \\item Risk-Awareness: Point-wise constraints are easier to fulfill since each state can be regarded individually, however it assumes independence between the states, which is clearly not given due to the dynamical constraints of the ego. As shown in \\cite{JansonSP15} both the additive and multiplicative formulation do not scale with increasing planning horizon, since the accumulated risk converges to infinity. Also the using point-wise constraint often is a very conservative choice, as it does not allow to take more risk at some point to be more efficient or to save risk somewhere else. \n    \\begin{itemize}\n        \\item trajectory-wise: $\\sum_{k = 0}^N r(x_k, u_k) \\leq R_{max}$\n        \\item point-wise: $r(x_k, u_k) \\leq R_{max} \\forall k$\n    \\end{itemize}\n\n    \\item Computational Feasibility:  \n    \\begin{itemize}\n        \\item real-time planning\n        \\item online policy/trajectory correction (e.g. using perturbation) \n        \\item not real-time applicable\n    \\end{itemize}\n    \n    \\item Explainability \\& Guarantees: When the result of the planning algorithm is not interpretable it is very hard (or even impossible) to give theoretical guarantees with respect to safety constraints. Therefore for these approaches an additional step, determining the empirical risk of collision using Monte Carlo simulations, is necessary, at the cost of additional run-time.  \n\\end{itemize}\n\n\\begin{center}\n\\begin{tabular}{c||p{2cm}|p{1cm}|p{2cm}|p{1cm}|p{1cm}|p{1cm}|p{1cm}|p{1cm}}\n    Method & \n    \\rotatebox[origin=c]{90}{Space ?} &  \\rotatebox[origin=c]{90}{Risk-Awareness ?} & \n    \\rotatebox[origin=c]{90}{PPDF Model ?} & \n    \\rotatebox[origin=c]{90}{Risk as cost ?} &\n    \\rotatebox[origin=c]{90}{Optimality ?} &\n    \\rotatebox[origin=c]{90}{Parametrization ?} &\n    \\rotatebox[origin=c]{90}{Interactive ?} &\n    \\rotatebox[origin=c]{90}{Interpretability ?} \\\\\n    \\hline\\hline\n    \n    CCMPC & continuous & point-wise & approximate (uni-Gaussians) & no & locally & sparse & no & yes \\\\\n    \\hline\n    SIPP & discrete & point-wise & accurate (sampled GMM) & no & globally & sparse & no & yes \\\\\n    \\hline\n    DRL & continuous & none & none & no & none & much & yes & no \\\\\n    \\hline\n    PORCA & continuous & none & none & none & none & much & yes & no \\\\\n    \\hline\n    SACBP & continuous & yes & accurate (sampled traject.) & yes & locally & sparse & no & yes \\\\\n    \\hline\n    POMDP & discrete & yes & accurate & yes & globally & much (state definition) & no & yes \\\\\n    \\hline\n    IRL & discrete & yes & accurate & none & none & much (optimal trajectory) & medium & medium\n    \n\\end{tabular}\n\\end{center}\n%", "meta": {"hexsha": "a2e98c81163ef2d7925bdc42320119f384f0a1ac", "size": 4827, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/thesis/appendix.tex", "max_stars_repo_name": "simon-schaefer/mantrap", "max_stars_repo_head_hexsha": "9a2b3f32a0005cc0cb79bb78924f09da5a94587d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-11T18:13:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T02:52:48.000Z", "max_issues_repo_path": "report/thesis/appendix.tex", "max_issues_repo_name": "StanfordASL/mantrap", "max_issues_repo_head_hexsha": "9a2b3f32a0005cc0cb79bb78924f09da5a94587d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/thesis/appendix.tex", "max_forks_repo_name": "StanfordASL/mantrap", "max_forks_repo_head_hexsha": "9a2b3f32a0005cc0cb79bb78924f09da5a94587d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-12-09T00:03:26.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T10:39:03.000Z", "avg_line_length": 58.8658536585, "max_line_length": 598, "alphanum_fraction": 0.6747462192, "num_tokens": 1456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7222031630032627}}
{"text": "\\lesson{4}{Sep 22 2021 Wen (12:43:32)}{Complex Numbers}{Unit 1}\n\n\\subsubsection*{Imaginary Numbers}\n\nWhat pairs of identical factors will produce $-1$ when multiplied? \\\\ $1 \\times\n1$ doesn't work since it equals positive $1$. The same is true of $-1 \\times 1$\nwhich also equals positive $1$. \\\\ $1 \\times -1$ equals $-1$, but these are not\nidentical factors.\n\n\\begin{definition}[$i$]\n    To solve this problem, the concept of the imaginary number \\textit{i} was\n    invented. The imaginary number was defined to be:\n    \n    \\[ i = \\sqrt{-1} \\]\n    \n    With this definition, the square root of negative radicands, in addition to\n    positive radicands, may be simplified.\n\\end{definition}\n\n\\begin{example}[$i$]\n    Simplify: $\\sqrt{-8}$\n    \n    \\begin{align}\n        \\sqrt{-1} \\times \\sqrt{8} &= i \\times \\sqrt{8} \\\\\n                                  &= i \\sqrt{8} \\\\\n                                  &= i \\sqrt{4} \\times \\sqrt{2} \\\\\n                                  &= 2i \\sqrt{2}\n    \\end{align}\n\\end{example}\n\n\\subsubsection*{Squaring Imaginary Numbers}\n\nYou know that $i = \\sqrt{-1}$ \\\\\nConsequently, $i^2 = (\\sqrt{-1})^2$ \\\\\nSince squaring a square root will eliminate the square root sign:\n\n\\begin{align}\n    \\sqrt{3^2} &= \\sqrt{3} \\times \\sqrt{3} \\\\\n               &= \\sqrt{9} \\\\\n               &= 3\n\\end{align}\n\nThen:\n\n\\begin{align}\n    i^2 &= (\\sqrt{-1})^2 \\\\\n        &= i^2 \\\\\n        &= -1\n\\end{align}\n\n\\subsubsection*{Cubing Imaginary Numbers}\n\nWhat about cubing the imaginary number:\n\n\\begin{align}\n    i^3 &= i \\times i \\times i \\\\\n        &= i^3 \\\\\n        &= (i \\times i) \\times i \\\\\n        &= i^3 = i^2 \\times i \\\\\n        &= i^3 = -1 \\times i \\\\\n        &= i^3 \\\\\n        &= -i\n\\end{align}\n\n\\subsubsection{Biquadrate Imaginary Numbers}\n\n\\textbf{i} to the fourth power can be found in a similar way:\n\n\\begin{align}\n    i^4 &= i \\times i \\times i \\times i \\\\\n        &= i^4 \\\\\n        &= (i \\times i) \\times (i \\times i) \\\\\n        &= i^4 \\\\\n        &= -1 \\times -1 \\\\\n        &= i = 1\n\\end{align}\n\n\\subsubsection*{Simplifying $i$}\n\n\\begin{example}[Simplifying $i$]\n    Simplify: $i^{27}$\n    \n    \\begin{align}\n        \\frac{27}{4} &= 6 R \\longrightarrow 3 \\\\\n                     &= i^{R \\longrightarrow 3} \\\\\n                     &= -i\n    \\end{align}\n\\end{example}\n\n\\newpage\n", "meta": {"hexsha": "79961596424eca4605f966b5a418835112147499", "size": 2301, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-1/lesson-4.tex", "max_stars_repo_name": "SingularisArt/notes", "max_stars_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-08-31T12:45:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T07:29:05.000Z", "max_issues_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-1/lesson-4.tex", "max_issues_repo_name": "SingularisArt/notes", "max_issues_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-1/lesson-4.tex", "max_forks_repo_name": "SingularisArt/notes", "max_forks_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.2857142857, "max_line_length": 79, "alphanum_fraction": 0.5336810083, "num_tokens": 713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843132, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.7221606723577355}}
{"text": "\\section{Methodology}\n\n\\subsection{\\textbf{Echo State Networks}}\nAn ``echo state network'' (also\ncalled a ``liquid state machine'' \\cite{lukosevicius_practical_2012}) is a type\nof recurrent neural network that uses a single layer of many neurons called a\n``reservoir.'' The reservoir has an adjacency matrix $\\bm{A}$ that\n\\begin{enumerate}\n\t\\item is sparsely populated\n\t\\item is connected by uniformly random weights centered at zero\n\t\\item has a large number of neurons\n\\end{enumerate}\nA reservoir computer also satisfies the \\textit{echo state property}\n\\cite{pathak_model-free_2018, lukosevicius_reservoir_2009}. This\nproperty ensures that a system's state has a decaying influence on future states\n(like an echo of sound or ripples on water). This property is satisfied in most\ncases when the the absolute value of the greatest eigenvalue of\n$\\bm{A}$ (the spectral radius, $\\rho$) \\cite{lukosevicius_reservoir_2009} is,\n\\begin{align}\n\t\\rho(\\bm{A}) < 1.\n\\end{align}\nHowever, the echo state property can still be satisfied for a spectral radius\ngreater than unity \\cite{lukosevicius_practical_2012}.\n\n\\begin{figure}[H]\n\t\\includegraphics[width=\\columnwidth]{reservoir_network.jpg}\n\t\\caption{A basic reservoir computer or echo state network. The connections in\n\tthe reservoir are given by $\\bm{A}$}\n\t\\label{fig:RCmodel}\n\\end{figure}\n\nFigure \\ref{fig:RCmodel} gives a visual representation of a basic\n\\acrshort{ESN}. An\ninput vector of length \\textit{K} is mapped to the reservoir layer by an input\nweight matrix $\\bm{W_{in}}$. The state of the reservoir is mapped to an output\nlayer of length \\textit{N} with an output weight matrix $\\bm{W_{out}}$.\nThe output weight matrix is trained through\nbackpropagation using a loss function like cross entropy\n\\cite{pathak_model-free_2018, vlachas_backpropagation_2020}.\n\nIn this\nwork, the input vector is a function of time, $\\bm{u}(t)$, and the output\nvector is the next state of the system, $\\bm{u}_p(t+\\Delta t)$. Ideally, the\ndifference between the prediction, $\\bm{u}_p$, and the actual, $\\bm{u}_a$, is\nminimized. \\glspl{ESN} are capable of mapping an input vector of any size to\nan output vector of any size. For example, $\\bm{u}(t)$ could be the total\ndemand\nat $t$ and $\\bm{u}_p(t+\\Delta t)$ could be the total demand at $t+\\Delta t$. In\nthat scenario the reservoir is a one-to-one map. Alternatively, $\\bm{u}(t)$\ncould be several data points, temperature, air pressure, irradiance, wind\nspeed, and total demand, at time $t$ and $\\bm{u}_p(t+\\Delta t)$ could be the\nnet demand at $t+\\Delta t$. In this case the reservoir is a many-to-one map.\nDetermining the combination of input data that leads to the most accurate\npredictions is a key area of research and an important part of this study\n\\cite{kobylinski_high-resolution_2020,bianchi_reservoir_2020}. For the results\nshown below, $\\bm{u}(t)$ is just the hourly demand.\n\n\\subsection{\\textbf{Hyperparameter Search}}\nDue to the architecture of \\glspl{ESN}, the weights and connections\ninside the reservoir do not need to be trained and, in our choice of\nimplementation, cannot be. This dramatically reduces the training time because\nonly the linear output layer needs to be trained. One drawback of this approach\nis its sensitivity to hyperparameters, which must be carefully chosen before\nrunning the network \\cite{ pathak_model-free_2018,\nlukosevicius_practical_2012, lukosevicius_reservoir_2009,gallicchio_deep_2019}.\nHere, we perform grid searches\nto establish which combination of hyperparameters minimizes the mean squared\nerror of the model,\n\\begin{align}\n\tMSE &= \\frac{1}{N}\\sum_i^N (\\hat{y} - y_i)^2\\\\\n\t\\intertext{where}\n\t\\hat{y} &= \\mbox{the average value of the ouput.}\\nonumber\n\\end{align}\n\n\\subsection{\\textbf{Constructing the \\gls{ESN}}}\n\nWe constructed the \\gls{ESN} in our initial demonstration with the open source\nPython package \\texttt{pyESN} \\cite{korndorfer_pyesn_2015}. The code\nis freely available on GitHub. Two models were trained with\nhistorical demand data from \\gls{uiuc} in 2017.  Each model had a\nreservoir of 500 neurons. One was trained on 1000 hours of\ndata and predicted the following 100 hours of demand in two hour\nincrements. The other was trained on 3500 hours of data and, once again,\npredicted the following 100 hours.\n\nA grid search informed our choice of hyperparameters for these models, shown in\nFigure \\ref{fig:gridsearch}. This search determined the optimal combination of\nspectral radius ($\\rho$) and noise injection (for regularization of reservoir\nneurons), shown in Figure \\ref{fig:gridsearch}, following the recommendations\nfrom \\cite{lukosevicius_practical_2012}. Figure\n\\ref{fig:gridsearch} shows that there may be multiple combinations of\nhyperparameters that give a low mean squared error. The hyperparameters that\nwill be used in future work reflect a global minimum in the parameter space\nwhere $\\rho = 1.3$ and \\texttt{noise} $= 0.01$. \n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.8\\columnwidth]{noise_spectral_radius.png}\n  \\caption{A grid search over a range of spectral radii and noise levels. The\n  optimal set minimizes the mean squared error.}\n  \\label{fig:gridsearch}\n\\end{figure}\n", "meta": {"hexsha": "a344ad6e4d3c78645348ed50bc5098402757a5e8", "size": 5159, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "publications/abstracts/reservoir-computing-abs/methodology.tex", "max_stars_repo_name": "yardasol/pride", "max_stars_repo_head_hexsha": "d63ee7711c7f5e4bd88b89dabd4140c562ac32e7", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-17T22:38:04.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-25T03:17:58.000Z", "max_issues_repo_path": "publications/abstracts/reservoir-computing-abs/methodology.tex", "max_issues_repo_name": "yardasol/pride", "max_issues_repo_head_hexsha": "d63ee7711c7f5e4bd88b89dabd4140c562ac32e7", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 110, "max_issues_repo_issues_event_min_datetime": "2020-06-03T17:26:50.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-24T20:44:53.000Z", "max_forks_repo_path": "publications/abstracts/reservoir-computing-abs/methodology.tex", "max_forks_repo_name": "yardasol/pride", "max_forks_repo_head_hexsha": "d63ee7711c7f5e4bd88b89dabd4140c562ac32e7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-06-01T23:09:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-01T07:54:44.000Z", "avg_line_length": 50.0873786408, "max_line_length": 80, "alphanum_fraction": 0.7770885831, "num_tokens": 1407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7221606679665455}}
{"text": "\n\\subsection{The multinomial data generating process}\n\n\\subsubsection{Introduction}\n\nIn the binomial case we had:\n\n\\(z_i=\\alpha + \\beta x_i +\\epsilon_i \\)\n\nAnd set \\(y_i\\) to \\(1\\) if \\(z_i>0\\)\n\nIn the multinomial case we have \\(m\\) alternatives\n\n\\(z_{ij}=\\alpha + \\beta x_{ij} +\\epsilon_{ij} \\)\n\nAnd set \\(y_{ij}=1\\) if \\(z_{ij}>z_{ik}\\forall k\\ne j\\)\n\n\\subsubsection{Generalised version}\n\nWe can rewrite this as:\n\n\\(z_{ij}=v_{ij} +\\epsilon_{ij} \\)\n\nWhere:\n\n\\(v_{ij}=\\alpha+\\beta x_{ij}\\)\n\nIn this case \\(v\\) does not depend on \\(j\\), but in other formulations it could.\n\n\\subsubsection{Probabilities}\n\n\\(P_{ij}=P(y_{ij}=1|x_{ij})\\)\n\n\\(P_{ij}=P(z_{ij}>z_{ik}\\forall k\\ne j)\\)\n\n\\(P_{ij}=P(\\epsilon_{ik} <v_{ij} -v_{ik} +\\epsilon_{ij}\\forall k\\ne j)\\)\n\n\\subsubsection{The form of the multinomial model: Intercepts}\n\nPreviously we described the multinomial model\n\n\\(z_{ij}=v_{ij} +\\epsilon_{ij} \\)\n\nWhere:\n\n\\(v_{ij}=\\alpha+\\beta x_{ij}\\)\n\nThe probability of \\(j\\) being chosen is.\n\n\\(P_{ij}=P(\\epsilon_{ik} <v_{ij} -v_{ik} +\\epsilon_{ij}\\forall k\\ne j)\\)\n\nInterceps in \\(v\\) cancel out. Therefore in the basic model there is no need to use\n\n\\(v_{ij}=\\alpha+\\beta x_{ij}\\)\n\nWe can instead use:\n\n\\(v_{ij}=\\beta x_{ij}\\)\n\n\\subsubsection{The form of the multinomial model: Conditional model}\n\nWe have :\n\n\\(v_{ij}=\\beta x_{ij}\\)\n\nWhat do we include in \\(x_{ij}\\)?\n\nWe can include observable characteristics for each product:\n\n\\(v_{ij}=\\alpha_j + \\beta x_j\\)\n\nOne of the \\(\\alpha_j\\) must be normalised to \\(0\\), as only differences matter. We cannot tell the difference if all \\(\\alpha \\) are raised by the same amount.\n\nFor consistency with other models we can write this as:\n\n\\(v_{ij}=\\beta x_{ij}\\)\n\nEven though this does not vary from individual to individual.\n\nHere \\(\\beta \\) represents average preferences for each product characteristic.\n\n\\subsubsection{The form of the multinomial model: The multinomial model}\n\nWe have differing characteristics for each individual:\n\n\\(v_{ij}=\\beta x_i\\)\n\nHowever this adds a constant for each product. For this to discriminate we need varying coefficients.\n\n\\(v_{ij}=\\beta_j x_i\\)\n\nAs we only observe differences, one of the \\(\\beta_j\\) must be normalised to \\(0\\).\n\nWe can rewrite this.\n\n\\(v_{ij}=\\sum_k \\beta_k\\delta_{kj} x_i\\)\n\n\\(v_{ij}=\\beta z_{ij}\\)\n\nThe original \\(x_i\\) is dense and contains data about the individual.\n\n\\(z_{ij}\\) is sparce and only has entries in the \\{j\\} section.\n\nHere \\(\\beta \\) represents how the \n\n\\subsubsection{The form of the multinomial model: Combined multinomial and conditional model}\n\nIf we have observations of the characteristics of both individuals and alternatives we can write:\n\n\\(v_{ij}=\\beta_m m_{ij}+\\beta_cc_{ij}\\)\n\n\\(v_{ij}=\\beta x_{ij}\\)\n\nHere \\(\\beta \\) represents both:\n\n\\begin{itemize}\n\\item Average preferences for customer characteristics (conditional)\n\\item How preferences change as individual characteristics change (multinomial)\n\\end{itemize}\n\n", "meta": {"hexsha": "b44cdf2fa9c41a94f58abf62f3aae11f691153ae", "size": 2940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/glmMulti/01-01-multinomial.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/glmMulti/01-01-multinomial.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/glmMulti/01-01-multinomial.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.2975206612, "max_line_length": 160, "alphanum_fraction": 0.7013605442, "num_tokens": 857, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650403, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7221596602845182}}
{"text": "\\chapter{Set Theory}\nSet Theory is one of the most fundamental topics in Abstract/Discrete\nMathematics. If you have ever heard about Relations, Equivalence Classes,\nGroups, Rings, and Fields, they are all based off Set Theory! This chapter\ncovers the following and it is essential that you know all of it:\n\n\\section{Definitions}\n\\begin{definition}\n    Set A is said to be a \\underline{\\textbf{subset}} of the set B if ($\\forall\n    x \\in A$)[$x \\in B$].\n\\end{definition}\n\n\\begin{definition}\n    The \\underline{\\textbf{union}} of set A and set B is the set: \\{$x \\mid x\n    \\in A \\vee x \\in B$\\}.\n\\end{definition}\n\n\\begin{definition}\n    The \\underline{\\textbf{intersection}} of A and B is the set: \\{$x \\mid x\n    \\in A \\wedge x \\in B$\\}.\n\\end{definition}\n\n\\begin{definition}\n    The \\underline{\\textbf{difference}} of A and B is the set: \\{$x \\mid x \\in\n    A \\wedge x \\not\\in B$\\}.\n\\end{definition}\n\n\\begin{definition}\n    Sets A and B are said to be \\underline{\\textbf{equal}} if $(A \\subset B)\n    \\wedge (B \\subset A)$.\n\\end{definition}\n\n\\begin{definition}\n    The \\underline{\\textbf{complement}} of A is the set: \\{$x \\mid x \\in D\n    \\wedge x \\not\\in A$\\}, where D is the domain or universal set.\n\\end{definition}\n\n\\begin{definition}\n    The \\underline{\\textbf{cardinality}} of A is the number of elements in A.\n\\end{definition}\n\n\\section{Proofs}\nThis class in particular will not test too many hard proofs in Set Theory. In\nfact, most proofs in this chapter will require you to construct simple direct\nproofs. So, let us show you an example of how proofs in set theory might look\nlike:\n\n\\begin{question}\n    If A and B are two sets, show that $\\overline{A \\cap B} = \\overline{A} \\cup\n    \\overline{B}$.\n\\end{question}\n\n\\begin{proof}\n    We need to show that $\\overline{A \\cap B} \\subset \\overline{A} \\cup\n    \\overline{B}$ and $\\overline{A} \\cup \\overline{B} \\subset \\overline{A \\cap\n    B}$\n\n    Let $x$ be an arbitrary element $\\in \\overline{A \\cap B}$\n    \\[\n        \\begin{split}\n            \\implies &x \\not\\in A \\cap B \\\\\n            \\implies &\\neg(x \\in A \\wedge x \\in B) \\\\\n            \\implies &x \\not\\in A \\vee x \\not\\in B \\\\\n            \\implies &x \\in \\overline{A} \\cup \\overline{B} \\\\\n            \\implies &\\overline{A \\cap B} \\subset \\overline{A} \\cup \\overline{B}\n        \\end{split}\n    \\]\n\n    Let $x \\in \\overline{A} \\cup \\overline{B}$\n\n    \\[\n        \\begin{split}\n            \\implies &x \\in \\overline{A} \\vee x \\in \\overline{B} \\\\\n            \\implies &\\neg x \\in A \\vee \\neg x \\in B \\\\\n            \\implies &\\neg (x \\in A \\wedge x \\in B) \\\\\n            \\implies &\\neg (x \\in A \\cap B) \\\\\n            \\implies &x \\in \\overline{A \\cap B} \\\\\n            \\implies &\\overline{A} \\cup \\overline{B} \\subset \\overline{A \\cap B}\n        \\end{split}\n    \\]\n\n    Thus, $\\overline{A \\cap B} = \\overline{A} \\cup \\overline{B}$.\n\\end{proof}\n\nYou also need to know set identities but they are the same as the basic\nidentities of propositional logic, so I haven't included them in this section.\n\nI have also skipped the section of Generalized Unions and Intersections as they\nare based on the basic definition of union and intersection of sets. Otherwise,\nthat is pretty much it with regards to set theory!\n", "meta": {"hexsha": "f9f1e2f207ce6af1bf67ac625c37e66b8cef148b", "size": 3220, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ECS 20 Study Guide/Sets.tex", "max_stars_repo_name": "UC-Davis-CS-Tutoring/Study-Guides", "max_stars_repo_head_hexsha": "3123a6e883b7379c865df9287da2b969e7af20bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ECS 20 Study Guide/Sets.tex", "max_issues_repo_name": "UC-Davis-CS-Tutoring/Study-Guides", "max_issues_repo_head_hexsha": "3123a6e883b7379c865df9287da2b969e7af20bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2018-12-19T03:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-30T05:45:28.000Z", "max_forks_repo_path": "ECS 20 Study Guide/Sets.tex", "max_forks_repo_name": "UC-Davis-CS-Tutoring/Study-Guides", "max_forks_repo_head_hexsha": "3123a6e883b7379c865df9287da2b969e7af20bb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-06-19T01:54:16.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-19T01:54:16.000Z", "avg_line_length": 35.3846153846, "max_line_length": 80, "alphanum_fraction": 0.6400621118, "num_tokens": 1009, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.819893335913536, "lm_q1q2_score": 0.7221596596571597}}
{"text": "\\section{Question 3}\n\\begin{equation}\n\tG(s) = \\dfrac{K\\exp(-\\tau s)}{s(s^2 + s + a)}, \\quad \\tau>0, \\quad a > 0, \\quad K > 0\n\\end{equation}\nThe transfer function in which s is replaced by $j\\omega$ where $\\omega$ is frequency.\n\n% The phase angle:\n% $$\n% \\angle G(jw) = \\left. \\angle K \\right. - (\\angle j\\omega + \\left.\\angle \\left((j\\omega)^2 + j\\omega + a \\right))\\right.\n% $$\n% $$\n% \\angle G(jw) = \\left. \\angle K \\right. - (\\angle j\\omega + \\left.\\angle \\left(j\\omega -\\omega^2 + a \\right))\\right.\n% $$\n% $$\n% \\angle G(jw) = \\tan^{-1}\\left(\\dfrac{0}{K}\\right) - \\tan^{-1}\\left(\\dfrac{\\omega}{0}\\right) - \\tan^{-1}\\left(\\dfrac{\\omega}{a - \\omega^2}\\right)\n% $$\n% $$\n% \\angle G(jw) = 0^{\\circ} - 90^{\\circ} - \\tan^{-1}\\left(\\dfrac{\\omega}{a - \\omega^2}\\right) = 0 - \\dfrac{\\pi}{2} - \\tan^{-1}\\left(\\dfrac{\\omega}{a - \\omega^2}\\right)\n% $$\n% The amplitude ratio:\n% $$\n% \\left\\vert G(j\\omega) \\right\\vert = \\left\\vert \\dfrac{K}{j\\omega\\left((j\\omega)^2 + j\\omega + a \\right)} \\right\\vert \n% =  \\left\\vert \\dfrac{K}{j\\omega\\left(j\\omega -\\omega^2 + a\\right)} \\right\\vert\n% $$\n% $$\n% \\left\\vert G(j\\omega) \\right\\vert = \\dfrac{\\left\\vert K \\right\\vert}{\\left\\vert j\\omega \\right\\vert\n% \\left\\vert j\\omega -\\omega^2 + a \\right\\vert\n% } = \\dfrac{K}{\\omega\\sqrt{\\omega^2 + (\\omega^2-a)^2}}\n% $$\nCause $a>0$ we have just one pole on imaginary axis.\n\\begin{figure}[H]\n\t\\caption{Contour near the origin of the s plane and closed contour in the s plane}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q2/nyquist_s_plane.png}\n\\end{figure}\nOn the semicircular path with radius $\\epsilon$ (where $\\epsilon \\ll 1 $), the complex variable s can be written\n$$\ns = \\epsilon \\exp(j\\theta)\n$$\nwhere $\\theta$ varies from $-\\dfrac{\\pi}{2}$ to $\\dfrac{\\pi}{2}$.\n\\begin{figure}[H]\n\t\\caption{s-Plane}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q2/nyquist_s_plane_name.png}\n\\end{figure}\nNow we calculate $j\\omega$ in A, C, D and F.\n\nA:\n\n$s = j\\omega,\\quad \\omega = -\\epsilon$\n$$\n \\lim_{\\omega\\to -\\epsilon}G(j\\epsilon)  = \\dfrac{K\\exp(\\tau j\\epsilon)}{-j\\epsilon((j\\epsilon)^2 - j\\epsilon + a)} = \\dfrac{K\\exp(\\tau j\\omega)}{-j\\epsilon(-\\epsilon^2 - j\\epsilon + a)} = \\dfrac{K\\exp(\\tau j\\epsilon)}{j\\epsilon^3 - \\epsilon^2 - aj\\epsilon}\n$$\n$$\n\\lim_{\\epsilon \\to 0}\\dfrac{K\\exp(\\tau j\\epsilon)}{j\\epsilon^3 - \\epsilon^2 - aj\\epsilon} = \\lim_{\\epsilon \\to 0} \\dfrac{K\\exp(\\tau j\\epsilon)}{-aj\\epsilon} = \\lim_{\\epsilon \\to 0} \\dfrac{Kj\\exp(\\tau j\\epsilon)}{a\\epsilon} =  \\infty \\angle 90^{\\circ}\n$$\n\nC:\n\n$s = j\\omega,\\quad \\omega = \\epsilon$\n$$\n \\lim_{\\omega\\to \\epsilon}G(j\\omega)  = \\dfrac{K\\exp(-\\tau j\\epsilon)}{j\\epsilon((j\\epsilon)^2 + j\\epsilon + a)} = \\dfrac{K\\exp(-\\tau j\\epsilon)}{j\\epsilon(-\\epsilon^2 + j\\epsilon + a)} = \\dfrac{K\\exp(-\\tau j\\epsilon)}{j\\epsilon^3 - \\epsilon^2 - aj\\epsilon}\n$$\n$$\n\\lim_{\\epsilon \\to 0}\\dfrac{K\\exp(-\\tau j\\epsilon)}{j\\epsilon^3 - \\epsilon^2 + aj\\epsilon} = \\lim_{\\epsilon \\to 0} \\dfrac{K\\exp(-\\tau j\\epsilon)}{-aj\\epsilon} = \\lim_{\\epsilon \\to 0} \\dfrac{-Kj\\exp(-\\tau j\\epsilon)}{a\\epsilon} =  \\infty \\angle -90^{\\circ}\n$$\n\nA to C:\n\n$s = j\\omega,\\quad \\omega = \\epsilon\\exp(j\\theta), \\quad \\theta: -\\dfrac{\\pi}{2}\\to 0 \\to \\dfrac{\\pi}{2}(CCW)$\n$$\n \\lim_{\\epsilon\\to 0}G(\\epsilon\\exp(j\\theta))  =\\dfrac{K\\exp(-\\tau j\\epsilon)}{\\epsilon\\exp(j\\theta)((\\epsilon\\exp(j\\theta))^2 + \\epsilon\\exp(j\\theta) + a)} =  \\dfrac{K\\exp(-\\tau j\\epsilon)}{\\epsilon^3\\exp(3j\\theta) + \\epsilon^2\\exp(2j\\theta) + a\\epsilon\\exp(j\\theta)} \n$$\n$$\n\\lim_{\\epsilon \\to 0}\\dfrac{K\\exp(-\\tau j\\epsilon)}{a\\epsilon\\exp(j\\theta)} = \\lim_{\\epsilon \\to 0} \\dfrac{K\\exp(-j\\theta-\\tau j \\epsilon)}{a\\epsilon} =  \\infty \\angle -\\theta \n$$\n\nD:\n\n$s = j\\omega,\\quad \\omega = \\infty$\n$$\n\\lim_{\\omega\\to \\infty}G(j\\omega)  =  \\lim_{\\omega\\to \\infty}\\dfrac{K\\exp(-\\tau j\\omega)}{j\\omega((j\\omega)^2 + j\\omega + a)} = \\lim_{\\omega\\to \\infty} \\dfrac{K\\exp(-\\tau j\\omega)}{j\\omega(-\\omega^2 + j\\omega + a)} = \\lim_{\\omega\\to \\infty} \\dfrac{K\\exp(-\\tau j\\omega)}{-j\\omega^3 - \\omega^2 + aj\\omega}\n$$\n$$\n\\lim_{\\omega\\to \\infty} \\dfrac{K\\exp(-\\tau j\\omega)}{-j\\omega^3} = \\lim_{\\omega\\to \\infty} \\dfrac{jK\\exp(-\\tau j\\omega)}{\\omega^3}  \n= 0 \\angle 90^{\\circ}\n$$\n\nF:\n\n$s = j\\omega,\\quad \\omega = -\\infty$\n$$\n\\lim_{\\omega\\to -\\infty}G(j\\omega)  =  \\lim_{\\omega\\to -\\infty}\\dfrac{K\\exp(-\\tau j\\omega)}{j\\omega((j\\omega)^2 + j\\omega + a)} = \\lim_{\\omega\\to -\\infty} \\dfrac{K\\exp(-\\tau j\\omega)}{j\\omega(-\\omega^2 + j\\omega + a)} = \\lim_{\\omega\\to -\\infty} \\dfrac{K\\exp(-\\tau j\\omega)}{-j\\omega^3 - \\omega^2 + aj\\omega}\n$$\n$$\n\\lim_{\\omega\\to -\\infty} \\dfrac{K\\exp(-\\tau j\\omega)}{-j\\omega^3} = \\lim_{\\omega\\to -\\infty} \\dfrac{jK\\exp(-\\tau j\\omega)}{\\omega^3}  \n= 0 \\angle -90^{\\circ}\n$$\n\n\\begin{figure}[H]\n\t\\caption{Nyquist plot using MATLAB ($a = 1, K = 1, \\tau = 0.01$)}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q3/MATLAB-Nyquist.png}\n\\end{figure}\n\nNow we know shape of nyquist plot. we find out where it's equal to $-1$.\n\n$$\nG(j\\omega) = -1 + 0j = \\dfrac{K\\exp(-\\tau j\\omega)}{j\\omega((j\\omega))^2 + j\\omega + a)} = \\dfrac{K\\exp(-\\tau j\\omega)}{-j\\omega^3 - \\omega^2 + aj\\omega} = -1\n$$\n\n$$\n\\to j\\omega^3 + \\omega^2 -aj\\omega = K\\exp(-\\tau j\\omega) \\to j\\omega^3 + \\omega^2 -aj\\omega - K\\exp(-\\tau j\\omega) = 0\n$$\nif we assume $\\omega\\tau \\ll 1$ the problem is like previous question.\nTwo equation and two unknowns.\n\\begin{align*}\n\tj\\omega^3 &=aj\\omega-Kj\\omega\\tau \\to \\omega^2 = a-K\\tau\\\\\n\t\\omega^2 &=K \\to \\omega^2 = K\n\\end{align*}\nWhen $a = K$ the nyquist plot cross from $-1$ point. When $a-\\tau\\omega>K$ the nyquist plot is before $-1$ and when $a-\\tau\\omega<K$ the nyquist plot cross $-1$ and system is unstable.\n\\begin{figure}[H]\n\t\\caption{Stable Nyquist plot using MATLAB ($a = 2, K = 1, \\tau = 0.01$)}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q3/MATLAB-Nyquist_stable.png}\n\\end{figure} \n\\begin{figure}[H]\n\t\\caption{Unstable Nyquist plot using MATLAB ($a = 1, K = 2, \\tau = 0.01$)}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q3/MATLAB-Nyquist_unstable.png}\n\\end{figure}\n\nWhen $\\tau \\ll 1$ it's not true and we have nonlinear equation that is hard to slove.\n\\begin{align*}\n\tj\\omega^3 &=aj\\omega - Kj\\sin(\\tau\\omega)\\\\\n\t\\omega^2 &=K\\cos(\\tau\\omega)\n\\end{align*}\n\nwhen $\\tau$ increase we must increase $a$ or decrease $K$ for stable system.\n\n\\begin{figure}[H]\n\t\\caption{Unstable Nyquist plot using MATLAB ($a = 1, K = 1, \\tau = 2$)}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q3/MATLAB-Nyquist_increase_tau.png}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\caption{Stable Nyquist plot using MATLAB ($a = 2, K = 1, \\tau = 2$)}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q3/MATLAB-Nyquist_increase_tau_and_a.png}\n\\end{figure}\nWhen we increase $\\tau$ it's make our system unstable.\n\n\\begin{figure}[H]\n\t\\caption{Unstable Nyquist plot  with large $\\tau$ using MATLAB ($a = 2, K = 1, \\tau = 100$)}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q3/MATLAB-Nyquist_increase_tau_very_lage.png}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\caption{Stable Nyquist plot with large $\\tau$ and small $K$ using MATLAB ($a = 2, K = 0.00001, \\tau = 100$)}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q3/MATLAB-Nyquist_increase_tau_very_lage_K_very_low.png}\n\\end{figure}\n\n\n\n\n", "meta": {"hexsha": "5c5fe1624c4fb4c7de7508ac2b4723f3eb08313b", "size": 7187, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW I/Report/Q3/Q3.tex", "max_stars_repo_name": "alibaniasad1999/Principle-Of-Controller-Design", "max_stars_repo_head_hexsha": "2a6285f627377a5e5edfb32c92e054ab213d311a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW/HW I/Report/Q3/Q3.tex", "max_issues_repo_name": "alibaniasad1999/Principle-Of-Controller-Design", "max_issues_repo_head_hexsha": "2a6285f627377a5e5edfb32c92e054ab213d311a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW/HW I/Report/Q3/Q3.tex", "max_forks_repo_name": "alibaniasad1999/Principle-Of-Controller-Design", "max_forks_repo_head_hexsha": "2a6285f627377a5e5edfb32c92e054ab213d311a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.5266272189, "max_line_length": 307, "alphanum_fraction": 0.6339223598, "num_tokens": 2919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7221596538988224}}
{"text": "\\documentstyle[a4wide,12pt]{article}\n\n\\begin{document}\n\n\n\n\n\\section*{Building a model for the solar system using ordinary differential equations}\n\n\\subsection*{Introduction.}\n\nThe aim of this project is to develop a code for simulating the solar\nsystem using a widely popular algorithm for solving coupled ordinary\ndifferential equations, the so-called velocity Verlet algorithm. An\nimportant aspect of this project is to be able to object orient your\ncode. There are several coupled ordinary differenatial equations where\nthe basic equations, except for various physical constants and\nvariables, are rather similar. Thus, write once and run many times,\none of the central points of object orientation, is something which\nmakes our program easier to extend and build upon when we add more\nplanets or moons or other astronomical objects. The basic equations\nwhich govern the system are rather simple, a set of coupled equations\nthat codify Newton's law of motion due the gravitational force.\n\nIn the first part however, we will limit ourselves (in order to test the algorithm) \nto a hypothetical solar system\nwith the Earth only orbiting around the sun.\nThe only force in the problem is gravity. Newton's law of gravitation  is given by a force $F_G$\n\\[\nF_G=\\frac{GM_{\\odot}M_{\\mathrm{Earth}}}{r^2},\n\\]\nwhere $M_{\\odot}$ is the mass of the Sun and $M_{\\mathrm{Earth}}$ is the mass of the Earth. The gravitational constant is $G$ and $r$ is the distance between the Earth and the Sun.\nWe assume that the Sun has a mass which is much larger \nthan that of the Earth. We can therefore safely neglect the \nmotion of the Sun in this problem.  In the first part of this project, your aim is to compute the motion\nof the the Earth using different methods for solving ordinary differential equations.\n\nWe assume that the orbit of the Earth around the Sun \nis co-planar, and we take this to be the $xy$-plane.\nUsing Newton's second law of motion we get the following equations\n\\[\n\\frac{d^2x}{dt^2}=\\frac{F_{G,x}}{M_{\\mathrm{Earth}}},\n\\]\nand \n\\[\n\\frac{d^2y}{dt^2}=\\frac{F_{G,y}}{M_{\\mathrm{Earth}}},\n\\]\nwhere $F_{G,x}$ and $F_{G,y}$ are the $x$ and $y$ components of the gravitational force. \n\nWe will use so-called astronomical units when rewriting our equations. \nUsing astronomical units (AU as abbreviation)it means that \none astronomical unit of length, known as 1 AU, is the average distance between the Sun and Earth, that is\n$1$ AU = $1.5\\times 10^{11}$ m.  It can also be convenient to use years instead of seconds since years match\nbetter the time evolution of the solar system. The mass of the Sun is $M_{\\mathrm{sun}}=M_{\\odot}=2\\times 10^{30}$ kg. The masses of all relevant planets and their distances from the sun are listed in the table here in kg and AU.\n\n\n\\begin{quote}\n\\begin{tabular}{ccc}\n\\hline\n\\multicolumn{1}{c}{ Planet } & \\multicolumn{1}{c}{ Mass in kg } & \\multicolumn{1}{c}{ Distance to  sun in AU } \\\\\n\\hline\nEarth   & $M_{\\mathrm{Earth}}=6\\times 10^{24}$ kg     & 1AU                    \\\\\nJupiter & $M_{\\mathrm{Jupiter}}=1.9\\times 10^{27}$ kg & 5.20 AU                \\\\\nMars    & $M_{\\mathrm{Mars}}=6.6\\times 10^{23}$ kg    & 1.52 AU                \\\\\nVenus   & $M_{\\mathrm{Venus}}=4.9\\times 10^{24}$ kg   & 0.72 AU                \\\\\nSaturn  & $M_{\\mathrm{Saturn}}=5.5\\times 10^{26}$ kg  & 9.54 AU                \\\\\nMercury & $M_{\\mathrm{Mercury}}=3.3\\times 10^{23}$ kg & 0.39 AU                \\\\\nUranus  & $M_{\\mathrm{Uranus}}=8.8\\times 10^{25}$ kg  & 19.19 AU               \\\\\nNeptun  & $M_{\\mathrm{Neptun}}=1.03\\times 10^{26}$ kg & 30.06 AU               \\\\\nPluto   & $M_{\\mathrm{Pluto}}=1.31\\times 10^{22}$ kg  & 39.53 AU               \\\\\n\\hline\n\\end{tabular}\n\\end{quote}\n\n\\noindent\nPluto is no longer considered  a planet, but we add it here for historical reasons. It is optional in this project to include Pluto and eventual moons. \n\nIn setting up the equations we can limit ourselves to a co-planar motion and use only the $x$ and $y$ coordinates. But you should feel free to extend your equations to three dimensions, it is not very difficult and the data from NASA are all in three dimensions.\n\n\\href{{http://www.nasa.gov/index.html}}{NASA} has an excellent site at \\href{{http://ssd.jpl.nasa.gov/horizons.cgi#top}}{\\nolinkurl{http://ssd.jpl.nasa.gov/horizons.cgi\\#top}}.\nFrom there you can extract initial conditions in order to start your differential equation solver.\nAt the above website you need to change from \\textbf{OBSERVER} to \\textbf{VECTOR} and then write in the planet you are interested in.\nThe generated data contain the $x$, $y$ and $z$ values as well as their corresponding velocities. The velocities are in units of AU per day.\nAlternatively they can be obtained in terms of km and km/s. \n\nFor the first system below involving only the Earth and the Sun, you could just initialize the position with say $x=1$ AU\nand $y=0$ AU. \n\n\\paragraph{a: The Earth-Sun system.}\nWe assume that mass units can be obtained by using the fact that Earth's orbit is almost circular around the Sun.\nFor circular motion we know that the force must obey the following relation\n\\[\nF_G= \\frac{M_{\\mathrm{Earth}}v^2}{r}=\\frac{GM_{\\odot}M_{\\mathrm{Earth}}}{r^2},\n\\]\nwhere $v$ is the velocity of Earth. \nThe latter equation can be used to show that\n\\[\nv^2r=GM_{\\odot}=4\\pi^2\\mathrm{AU}^3/\\mathrm{yr}^2.\n\\]\n\nDiscretize the above differential equations and set up an algorithm\nfor solving these equations using Euler's forward algorithm and the\nso-called velocity Verlet method discussed in the lecture notes and\nlecture slides.\n\n\\paragraph{b: Writing an object oriented code for the Earth-Sun system.}\n\nWrite then a program which solves the above differential equations for\nthe Earth-Sun system using Euler's method and the velocity Verlet\nmethod.  Write these codes without object orientation first in order\nto make sure everything is running correctly. Thereafter you should\nstart planning to object orient your code.  Try to figure out which\nparts and operations could be written as classes and generalized.\nYour task here is to think of the program flow and figure out which\nparts can be abstracted and reused for many types of operations.\n\nFor those of you who will focus on the Molecular Dynamics version of\nProject 5, much of the structures developed here as well as the\nimplementation of the Verlet algorithm, can be used in that project as\nwell.\n\n\\paragraph{c: Test of the algorithms.}\n\nFind out which initial value for the velocity that gives a circular\norbit and test the stability of your algorithm as function of\ndifferent time steps $\\Delta t$.  Make a plot of the results you\nobtain for the position of the Earth (plot the $x$ and $y$ values\nand/or if you prefer to use three dimensions the $z$-value as well)\norbiting the Sun.\n\nCheck also for the case of a circular orbit that both the kinetic and the potential energies are conserved.\nCheck also if the  angular momentum is conserved. Explain why these quantities\nshould be conserved.\n\nDiscuss eventual differences between the Verlet algorithm and the\nEuler algorithm. Consider also the number of FLOPs involved and\nperform a timing of the two algorithms for equal final times.\n\nWe will use the velocity Verlet algorithm in the remaining part of the project. \n\n\n\n\\paragraph{d: Escape velocity.}\nConsider then a planet which begins at a distance of 1 AU from the sun. Find out by trial and error\nwhat the initial velocity must be in order for the planet to escape from the sun.  Can you find an exact answer?  How does that match your numerical results?\n\nTry also to change the gravitional force, by replacing \n\\[\nF_G=\\frac{GM_{\\odot}M_{\\mathrm{Earth}}}{r^2},\n\\]\nwith\n\\[\nF_G=\\frac{GM_{\\odot}M_{\\mathrm{Earth}}}{r^{\\beta}},\n\\]\nwhere you let $\\beta\\in [2,3]$. What happens to the earth-sun system when $\\beta$ creeps towards $3$? Comment your results.\n\n\\paragraph{e: The three-body problem.}\nWe will now study the three-body problem, still with the Sun kept fixed as the center of mass of the system  but \nincluding Jupiter (the most massive planet in the solar system, having a mass that is approximately 1000 times\nsmaller than that of the Sun) together with the Earth. This leads to a three-body problem. Without Jupiter, the Earth's motion is stable and unchanging with time. The aim here is to find out how much Jupiter alters the Earth's motion.\n\nThe program you have developed can easily be modified by simply adding the magnitude of the force betweem the Earth and Jupiter.\n\nThis force is given again by \n\\[\nF_{\\mathrm{Earth-Jupiter}}=\\frac{GM_{\\mathrm{Jupiter}}M_{\\mathrm{Earth}}}{r_{\\mathrm{Earth-Jupiter}}^2},\n\\]\nwhere $M_{\\mathrm{Jupiter}}$ is the mass of the sun and $M_{\\mathrm{Earth}}$ is the mass of Earth. \nThe gravitational constant is $G$ and $r_{\\mathrm{Earth-Jupiter}}$ is the distance between Earth and Jupiter.\n\nWe assume again that the orbits of the two planets are co-planar, and we take this to be the $xy$-plane (you can easily extend the equations to three dimensions). \nModify your first-order differential equations in order to accomodate both the\nmotion of the Earth and Jupiter by taking into account the distance in $x$ and\n$y$ between the Earth and Jupiter. Set up the algorithm and plot the positions of the Earth and Jupiter using the velocity Verlet algorithm.\nDiscuss the stability of the solutions using your Verlet solver.\n\nRepeat \nthe calculations by increasing the mass of Jupiter by a factor of 10 and 1000\n and plot the position of the Earth.  Study again the stability of the Verlet solver.\n\n\\paragraph{f: Final model for all planets of the solar system.}\nFinally, using our Verlet solver, we carry out a real three-body calculation where all three systems, \nthe Earth, Jupiter and the Sun are in motion. To do this, choose the center-of-mass position of the three-body system as \nthe origin rather than the position of the sun. Give the Sun an initial velocity which makes the total momentum of the system exactly zero (the center-of-mass will remain fixed). Compare these results with those from the previous exercise and comment your results. Extend your program to include all planets in the solar system (if you have time, you can also include the various moons, but it is not required) and discuss your results. Use the above NASA link  to set up the initial positions and velocities for all planets. \n\n\n\\paragraph{g: The perihelion precession of Mercury.}\n\nAn important test of the general theory of relativity was to compare its prediction for the\nperihelion precession of Mercury to the observed value. The observed value of the perihelion precession, when\nall classical effects (such as the perturbation of the orbit due to gravitational attraction from the other planets) are\nsubtracted, is $43''$ ($43$ arc seconds) per century.\n\nClosed elliptical orbits are a special feature of the Newtonian $1/r^2$ force. In general, any correction to the\npure $1/r^2$ behaviour will lead to an orbit which is not closed, i.e.~after one complete orbit around the Sun, the\nplanet will not be at exactly the same position as it started. If the correction is small, then each orbit around\nthe Sun will be almost the same as the classical ellipse, and the orbit can be thought of as an ellipse whose \norientation in space slowly rotates. In other words, the perihelion of the ellipse slowly precesses around the Sun.\n\nYou will now study the orbit of Mercury around the Sun, adding a general relativistic correction to the Newtonian\ngravitational force, so that the force becomes\n\\[\nF_G = \\frac{GM_\\mathrm{Sun}M_\\mathrm{Mercury}}{r^2}\\left[1 + \\frac{3l^2}{r^2c^2}\\right]\n\\]\nwhere $M_\\mathrm{Mercury}$ is the mass of Mercury, $r$ is the distance between Mercury and the Sun, $l=|\\vec{r}\\times\\vec{v}|$ is the magnitude of Mercury's orbital angular momentum per unit mass, \nand $c$ is the speed of light in vacuum. Run a simulation \nover one century of Mercury's orbit around the Sun with no other planets present, starting with Mercury at perihelion on the $x$ axis.\nCheck then the value of the perihelion angle $\\theta_\\mathrm{p}$, using\n\\[\n\\tan \\theta_\\mathrm{p} = \\frac{y_\\mathrm{p}}{x_\\mathrm{p}}\n\\]\nwhere $x_\\mathrm{p}$ ($y_\\mathrm{p}$) is the $x$ ($y$) position of Mercury at perihelion, i.e.~at the point\nwhere Mercury is at its closest to the Sun. You may use that the speed of Mercury at perihelion is $12.44\\,\\mathrm{AU}/\\mathrm{yr}$, and that the distance to the Sun\nat perihelion is $0.3075\\,\\mathrm{AU}$.\nYou need to make sure that the time resolution used in your simulation\nis sufficient, for example by checking that the perihelion precession you get with a pure Newtonian force is at least\na few orders of magnitude smaller than the observed perihelion precession of Mercury. Can the observed perihelion \nprecession of Mercury be explained by the general theory of relativity?\n\n\n\n\\end{document}\n\n\n\n\n\n", "meta": {"hexsha": "5e71b27fe614095ce64aecc5a2ef408869156081", "size": 12839, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/Honorsprojects/Solarsystem.tex", "max_stars_repo_name": "Shield94/Physics321", "max_stars_repo_head_hexsha": "9875a3bf840b0fa164b865a3cb13073aff9094ca", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2020-01-09T17:41:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T00:48:58.000Z", "max_issues_repo_path": "doc/Honorsprojects/Solarsystem.tex", "max_issues_repo_name": "Shield94/Physics321", "max_issues_repo_head_hexsha": "9875a3bf840b0fa164b865a3cb13073aff9094ca", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2020-01-08T03:47:53.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-15T15:02:57.000Z", "max_forks_repo_path": "doc/Honorsprojects/Solarsystem.tex", "max_forks_repo_name": "Shield94/Physics321", "max_forks_repo_head_hexsha": "9875a3bf840b0fa164b865a3cb13073aff9094ca", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 33, "max_forks_repo_forks_event_min_datetime": "2020-01-10T20:40:55.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-11T20:28:41.000Z", "avg_line_length": 56.3114035088, "max_line_length": 526, "alphanum_fraction": 0.7521613833, "num_tokens": 3320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.8688267762381844, "lm_q1q2_score": 0.7221193384974627}}
{"text": "\\chapter{Interpolating with Polynomials}\n\nLet's say someone on a distant planet records video of a hammer being\nthrow up into the air.  They send you three random frames of the\nhammer in flight. Each frame has a timestamp and you can clearly see\nhow high the hammer is in each one. Can you create a 2nd degree\npolynomial that explains the entire flight of the hammer?\n\nThat is, you have three points $(t_0, h_0), (t_1, h_1), (t_2, h_2)$.\nCan you find $a,b,c$ such that the graph of $at^2 + bt + c = t$ passes\nthrough all three points?\n\nThe answer is yes.  In fact, given any $n$ points, there is exactly\none $n-1$ degree polynomial that passes through all the points.\n\nThere are a lot of variables floating around. Let's make it concrete:\nThe photos are taken at $t = 2$ seconds, $t = 3$ seconds, and $t = 4$\nseconds. In those photos, the height of the hammer is $5m$, $7m$, and\n$6m$. So, we want our polynomial to pass through these points: (2, 5),\n(3, 7), (4,6).\n\n\\includegraphics[width=0.7\\textwidth]{interpolation.png}\n\n\nHow can you find that polynomial? Let's do it in small steps. Can you\ncreate a 2nd degree polynomial that is not zero at $t = 2$, but is zero\nat $t = 3$ and $t = 4$? Yes, you can: $(x - 3)(x - 4)$ has\nexactly two roots at $t = 3$ and $t = 4$.  The value of this polynomial at\n$t = 2$ is $(2 - 3)(2 - 4) = 2$. We really want it to be $5m$, so\nwe can divide the whole polynomial by 2 and multiply it by 5.\n\nNow we have the polynomial:\n\\begin{equation*}\nf_0(x) = \\frac{5}{(2 - 3)(2 - 4)}(x - 3)(x - 4) = \\frac{5}{2}x^2 - \\frac{35}{2}x + 30\n\\end{equation*}\nThis is a second degree polynomial that is 5 at $t=2$ and 0 at $t=3$ and $t=4$.\n\nNow we create a polynomial that is 7 at $t=3$ and 0 at $t= 2$ and $t=4$:\n\\begin{equation*}\nf_1(x) = \\frac{7}{(3 - 2)(3 - 4)}(x - 2)(x - 4) = -7x^2 +42x - 56\n\\end{equation*}\n\nFinally, we create a polynomial that is 6 at $t=4$ and zero at $t=2$ and $t=3$:\n\\begin{equation*}\nf_2(x) = \\frac{6}{(4 - 2)(4 - 3)}(x - 2)(x - 3) = 3x^2 - 15x + 18\n\\end{equation*}\n\nAdding these three polynomials together gives you a new polynomial that touches all three points:\n\\begin{equation*}\n  f(x) = \\frac{5}{2}x^2 - \\frac{35}{2}x + 30  - 7x^2 + 42x - 56 + 3x^2 - 15x + 18  = -\\frac{3}{2}x^2 + \\frac{19}{2}x -8\n\\end{equation*}\n\nYou can test this with your \\pytype{Polynomial} class. Create a file called \\filename{test\\_interpolation.py}. Add this code:\n\\begin{Verbatim}\nfrom Polynomial import Polynomial\nimport matplotlib.pyplot as plt\n\nin_x = [2,3,4]\nin_y = [5,7,6]\n\npn = Polynomial([-8, 19/2, -3/2])\nprint(pn)\n\n# These lists will hold our x and y values\nx_list = []\ny_list = []\n\n# Starting x\ncurrent_x = 1.5\n\nwhile current_x <= 4.5:\n    # Evaluate pn at current_x\n    current_y = pn(current_x)\n\n    # Add x and y to respective lists\n    x_list.append(current_x)\n    y_list.append(current_y)\n\n    # Move x forward\n    current_x += 0.05\n    \n# Plot the curve\nplt.plot(x_list, y_list)\n\n# Plot black circles on the given points\nplt.plot(in_x, in_y, \"ko\")\nplt.grid(True)\nplt.show()\n\\end{Verbatim}\n\nYou should get a nice plot that shows the graph of the polynomial\npassing through those three points.\n\nIn general, then, if you give me any three points $(t_0, h_0), (t_1, h_1), (t_2, h_2)$, here is a second degree polynomial that pass through all three points:\n\\begin{equation*}\n\\frac{h_0}{(t_0 - t_1)(t_0 - t_2)}(x - t_1)(x - t_2) + \\frac{h_1}{(t_1 - t_0)(t_1 - t_2)}(x - t_0)(x - t_2) + \\frac{h_2}{(t_2 - t_0)(t_2 - t_1)}(x - t_0)(x - t_1)\n\\end{equation*}\n\nWhat if you are given 9 points ($(t_0, h_0), (t_1, h_1), \\ldots, (t_8,\nh_8)$) and want to find a 8th degree polynomial that passes through\nall of them? Just what you would expect:\n\\begin{equation*}\n\\frac{h_0}{(t_0 - t_1)(t_0 - t_2)\\ldots(t_0 - t_8)}(x - t_1)(x - t_2)\\ldots(x - t_8) + \\ldots + \\frac{h_8}{(t_8 - t_0)\\ldots(t_8-t_7)}(x - t_0)\\dots(x - t_7)\n\\end{equation*}\n\n\\textit{FIXME: Do I need to define summation and prod here?}\n\nThe general solution is, given $n$ points, the $n-1$ degree polynomial that goes through them is\n\\begin{equation*}\n  y =\\sum_{i=0}^{n}\\left ( \\prod_{\\stackrel{\\!0\\leq j\\leq n}{j\\neq i}}\\frac{x-t_j}{t_i-t_j}\\right ) h_i\n\\end{equation*}\n\nThat would be tedious for a person to compute, but computers love this\nstuff. Let's create a method that creates instances of Polynomial\nusing interpolation.\n\n\\section{Interpolating polynomials in python}\n\nYour method will take two lists of numbers, one contains x-values and\nthe other contains y-values. So comment out the line that creates the\npolynomial in \\filename{test\\_interpolation.py} and create it from two lists:\n\\begin{Verbatim}\nin_x = [2,3,4]\nin_y = [5,7,6]\n# pn = Polynomial([-8, 19/2, -3/2])\npn = Polynomial.from_points(in_x, in_y)\nprint(pn)\n\\end{Verbatim}\n\nAdd the following method to your Polynomial class in \\filename{Polynomial.py}\n\\begin{Verbatim}\n    @classmethod\n    def from_points(cls, x_values, y_values):\n        coef_count = len(x_values)\n\n        # Sums start with a zero polynomial\n        sum_pn = Polynomial([0.0] * coef_count)\n        for i in range(coef_count):\n\n            # Products start with the constant 1 polynomial\n            product_pn = Polynomial([1.0])\n            for j in range(coef_count):\n\n                # Must skip j=i\n                if j != i:\n                    # (1x - x_values[j]) has a root at x_values[j]\n                    factor_pn = Polynomial([-1 * x_values[j], 1])\n                    product_pn = product_pn * factor_pn\n                    \n            # Scale so product_pn(x_values[i]) = y_values[i]\n            scale_factor  = y_values[i] / product_pn(x_values[i])\n            scaled_pn = scale_factor * product_pn\n\n            # Add it to the sum\n            sum_pn = sum_pn + scaled_pn\n            \n        return sum_pn  \n\\end{Verbatim}\n\nIt should work exactly the same as before.  You should get the same\npolynomial printed out as before. You shoud get the same plot of the\ncurve passing through the three points.\n\nHow about five points? Change \\pyvar{in\\_x} and \\pyvar{in\\_y} at the\nstart of \\filename{test\\_interpolation.py}:\n\\begin{Verbatim}\nin_x = [1.7, 2, 2.7, 3.5, 4, 4.4]\nin_y = [8, 12, 1, 4, -1, 6]\n\\end{Verbatim}\n\nYou should get a polynomial that passes through all five points:\n\\begin{equation*}\n11.21x^5 - 171.05x^4 + 1019.44x^3 - 2957.53x^2 + 4161.78x - 2258.75  \n\\end{equation*}\nIt should look like this:\n\\includegraphics[width=0.7\\textwidth]{fiveinterp.png}\n", "meta": {"hexsha": "0f79a13a74dfa108abb3b6cddbee22c43d791eb8", "size": 6413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Polynomials/interpolating-en_US.tex", "max_stars_repo_name": "rajivjhoomuck/sequence", "max_stars_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/Polynomials/interpolating-en_US.tex", "max_issues_repo_name": "rajivjhoomuck/sequence", "max_issues_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/Polynomials/interpolating-en_US.tex", "max_forks_repo_name": "rajivjhoomuck/sequence", "max_forks_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 36.2316384181, "max_line_length": 162, "alphanum_fraction": 0.6599095587, "num_tokens": 2211, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.868826771143471, "lm_q1q2_score": 0.722119334263027}}
{"text": "The goal of transient analysis is to compute the temperature profile \\mq, which\nis defined in \\eref{temperature-profile}, that corresponds to a given power\nprofile \\mp, which is defined in \\eref{power-profile}, by solving the system\ngiven in \\eref{temperature-model-original}. Traditionally, this operation is\nundertaken numerically \\cite{skadron2003}; however, we are interested in\nobtaining and working with an analytical solution to the system, since such a\nsolution has many advantages, as we shall see later on.\n\n\\subsection{\\pasttitle}\n\nLet us discuss an analytical approach to solving the system of differential\nequations given in \\eref{temperature-differential-original}. To begin with, the\nsystem is rewritten as follows:\n\\[\n  \\frac{\\d \\tvs(t)}{\\d t} = \\tm{A} \\tvs(t) + \\m{C}^{-1} \\tm{B} \\vp(t)\n\\]\nwhere\n\\[\n  \\tm{A} = -\\m{C}^{-1} \\m{G}.\n\\]\nNext, we apply a technique that is taken from the family of exponential\nintegrators, which have good stability properties; the interested reader is\nreferred to \\cite{hochbruck2010} for an overview. Multiplying both sides of the\nabove system of differential equations by $e^{-\\tm{A} t}$ and noting that\n\\[\n  e^{-\\tm{A} t} \\frac{\\d \\tvs(t)}{\\d t} = \\frac{\\d e^{-\\tm{A} t} \\tvs(t)}{\\d t} + e^{-\\tm{A} t} \\tm{A} \\tvs(t),\n\\]\nwe obtain\n\\[\n  \\tvs(t) = e^{\\tm{A} t} \\tvs(0) + e^{\\tm{A} t} \\int_0^t e^{-\\tm{A} \\tau} \\m{C}^{-1} \\tm{B} \\vp(\\tau) \\d \\tau,\n\\]\nwhich is the solution at time $t$ starting from the initial condition $\\tvs(0)$\nat time~0.\n\nImagine now that the power consumption of the processing elements does not\nchange over time: $\\vp(t) = \\vp$. In this case, the system is a system of linear\ndifferential equations that has the following analytical solution:\n\\begin{equation} \\elab{transient-solution-original}\n  \\tvs(t) = e^{\\tm{A} t} \\tvs(0) + \\tm{A}^{-1} (e^{\\tm{A} t} - \\m{I}) \\m{C}^{-1} \\tm{B} \\vp\n\\end{equation}\nwhere $\\m{I}$ is the identity matrix.\n\nSuppose now that the sampling interval \\dt of \\mp is small enough so that the\npower consumption in each interval $[t_i, t_{i + 1})$ can be reasonably\napproximated by a constant equal to $\\vp_i = \\vp(t_i)$. The corresponding \\mq\ncan then be found by applying the following recurrence derived from\n\\eref{transient-solution-original}:\n\\begin{equation} \\elab{transient-recurrence-original}\n  \\tvs_{i} = \\tm{E} \\tvs_{i - 1} + \\tm{F} \\vp_i\n\\end{equation}\nfor $i = \\range{1}{\\ns}$ where\n\\begin{align*}\n  & \\tvs_0 = \\v{0} = (\\range{0}{0}), \\\\\n  & \\tm{E} = e^{\\tm{A} \\dt}, \\text{ and} \\\\\n  & \\tm{F} = \\tm{A}^{-1}(e^{\\tm{A} \\dt} - \\m{I})\\m{C}^{-1} \\tm{B}.\n\\end{align*}\nNote that, in order to obtain the actual \\mq, the recurrence should be followed\nby \\eref{temperature-algebraic-original}, which involves two trivial algebraic\noperations.\n\nSimilarly to the observations made in \\cite{thiele2011, pagani2015}, our\nexperience shows that the approach to transient analysis described above\nprovides a significant performance improvement compared to iterative solutions\nto systems of ordinary differential equations, such as the fourth-order\nRunge--Kutta method \\cite{press2007}. However, there is still room for\nimprovement, as we discuss next.\n\n\\subsection{\\solutiontitle}\n\\slab{transient-solution}\n\nEven though the matrices $\\tm{E}$ and $\\tm{F}$ have to be computed only once,\nthey necessitate two computationally problematic operations: the matrix\nexponential and matrix inverse involving $\\tm{A} \\in \\real^{\\nn \\times \\nn}$,\nwhich is a generic matrix. It is preferable to have a symmetric matrix $\\m{A}\n\\in \\real^{\\nn \\times \\nn}$ when these operations are concerned, since such a\nmatrix admits the eigendecomposition, which can be seen in\n\\eref{eigendecomposition}. Having computed such a decomposition, the calculation\nof the matrix exponential and matrix inverse becomes trivial as follows:\n\\begin{align}\n  & e^{\\m{A} \\dt}\n  = \\m{U} e^{\\m{\\Lambda} \\dt} \\transpose{\\m{U}}\n  = \\m{U} \\, \\diagonal{e^{\\lambda_1 \\dt}}{e^{\\lambda_\\nn \\dt}} \\transpose{\\m{U}} \\text{ and} \\elab{matrix-exponential} \\\\\n  & \\m{A}^{-1}\n  = \\m{U} \\m{\\Lambda}^{-1} \\transpose{\\m{U}}\n  = \\m{U} \\, \\diagonal{\\lambda_1^{-1}}{\\lambda_\\nn^{-1}} \\transpose{\\m{U}}. \\elab{matrix-inverse}\n\\end{align}\n\nIn order to obtain such an $\\m{A}$, we propose to perform an auxiliary\ntransformation. Recall first that the conductance matrix $\\m{G}$ is a symmetric\nmatrix, which, intuitively, is due to the fact that, if node~$i$ is connected to\nnode~$j$ with a certain conductance, node~$j$ is also connected to node~$i$ with\nthe same conductance; see \\fref{thermal-circuit}. However, $\\tm{A} = -\\m{C}^{-1}\n\\m{G}$ does not have this property. The desired symmetry can be kept intact\nusing the following substitution:\n\\[\n  \\begin{split}\n    & \\vs(t) = \\m{C}^{\\frac{1}{2}} \\tvs(t) \\text{ and} \\\\\n    & \\m{A} = -\\m{C}^{-\\frac{1}{2}} \\m{G} \\m{C}^{-\\frac{1}{2}}\n  \\end{split}\n\\]\nwhere $\\m{A}$ is symmetric, since\n\\[\n  \\transpose{\\m{A}}\n  = -\\transpose{(\\m{C}^{-\\frac{1}{2}} \\m{G} \\m{C}^{-\\frac{1}{2}})}\n  = -\\transpose{(\\m{C}^{-\\frac{1}{2}})} \\transpose{\\m{G}} \\transpose{(\\m{C}^{-\\frac{1}{2}})}\n  = -\\m{C}^{-\\frac{1}{2}} \\m{G} \\m{C}^{-\\frac{1}{2}}\n  = \\m{A}.\n\\]\nConsequently, \\eref{temperature-model-original} is rewritten as follows:\n\\begin{subnumcases}{\\elab{temperature-model}}\n  \\frac{\\d \\vs(t)}{\\d t} = \\m{A} \\vs(t) + \\m{B} \\vp(t) \\elab{temperature-differential} \\\\\n  \\vq(t) = \\transpose{\\m{B}} \\vs(t) + \\vq_\\ambient \\elab{temperature-algebraic}\n\\end{subnumcases}\nwhere\n\\[\n  \\m{B} = \\m{C}^{-\\frac{1}{2}} \\tm{B}.\n\\]\nSimilarly, the solution in \\eref{transient-solution-original} becomes\n\\[\n  \\vs(t) = e^{\\m{A} t} \\vs_0 + \\m{A}^{-1} (e^{\\m{A} t} - \\m{I}) \\m{B} \\v{p},\n\\]\nand the recurrence in \\eref{transient-recurrence-original} becomes\n\\begin{equation} \\elab{transient-recurrence}\n  \\vs_i = \\m{E} \\vs_{i - 1} + \\m{F} \\vp_i\n\\end{equation}\nfor $i = \\range{1}{\\ns}$ where\n\\begin{align*}\n  & \\vs_0 = \\v{0}, \\\\\n  & \\m{E} = e^{\\m{A} \\dt}, \\text{ and} \\\\\n  & \\m{F} = \\m{A}^{-1} \\left(e^{\\m{A} \\dt} - \\m{I}\\right) \\m{B}.\n\\end{align*}\nUsing the eigendecomposition in \\eref{eigendecomposition}, the last equation can\nbe efficiently computed in the following way:\n\\[\n  \\m{F} = \\m{U} \\, \\diagonal{\\frac{e^{\\lambda_1 \\dt} - 1}{\\lambda_1}}{\\frac{e^{\\lambda_\\nn \\dt} - 1}{\\lambda_\\nn}} \\transpose{\\m{U}} \\m{B}.\n\\]\nAs before, the recurrence in \\eref{transient-recurrence} should be followed by\n\\eref{temperature-algebraic} in order to obtain \\mq. The above auxiliary\ntransformation is helpful not only for transient analysis but also in other\ncontexts, as we shall see later on.\n\nLet us note at this point that there have been attempts to simplify the\ntemperature model by making additional assumptions in order to reduce the size\nof the circuit, thereby speeding up the solution process. For instance, the\ntechniques proposed in \\cite{bao2010, rai2011} are targeting single-core\nplatforms, and the approach described in \\cite{rao2009} is aimed at homogeneous\nplatforms and applications where the execution times of tasks are comparable\nwith the thermal time constant of the thermal package, which is in the order of\n100~s. Such techniques can be combined with what we present in this thesis as\nlong as $\\m{C}$ remains a diagonal matrix, and $\\m{G}$ remains a symmetric\npositive definite matrix.\n", "meta": {"hexsha": "4413caced40f635237349e568ef01bf051044f0c", "size": 7234, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "include/certainty/development/transient-analysis.tex", "max_stars_repo_name": "IvanUkhov/thesis", "max_stars_repo_head_hexsha": "95a7e2ee7664b94156906322610555e36e53cfe0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "include/certainty/development/transient-analysis.tex", "max_issues_repo_name": "IvanUkhov/thesis", "max_issues_repo_head_hexsha": "95a7e2ee7664b94156906322610555e36e53cfe0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "include/certainty/development/transient-analysis.tex", "max_forks_repo_name": "IvanUkhov/thesis", "max_forks_repo_head_hexsha": "95a7e2ee7664b94156906322610555e36e53cfe0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.5921052632, "max_line_length": 139, "alphanum_fraction": 0.6850981476, "num_tokens": 2419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7220800976444923}}
{"text": "% this is a comment!!!\n% these don't appear in your final rendered document\n\n\n\\documentclass{article} % Starts an article\n\\usepackage{amsmath} % Imports amsmath\n\n\n% enables text wrapping\n\\usepackage{url}\n\n\\usepackage{graphicx} % takes care of graphic including machinery\n\n\\usepackage{subfig}\n\n\\usepackage[margin=1in,letterpaper]{geometry} % decreases margins\n\n\\title{\\LaTeX Introduction} % Title\n% \\LaTeX prints LaTeX all fancy like\n\\author{Jeffery Russell}\n\n\\begin{document} % Begins a document\n  \\maketitle % places document at start of file\n  \\LaTeX{} is a document preparation system for\n  the \\TeX{} typesetting program.\n\n\\section{Math}\n\n\tIn \\LaTeX, there are tons of options for writing math.\n\tOver time you will memorize a lot of them, however, TexMaker has a side panel with all the math symbols. Math can be done in-line with single dollar signs like this: $y = mx +b$. Isn't this cool! However, math can also be done in bigger blocks that you can then reference.\n\n  % The following shows some math examples\n  \\begin{align}\n  \t\\label{math1}\n    E_0 &= mc^2 \\\\\n    E &= \\frac{mc^2}{\\sqrt{1-\\frac{v^2}{c^2}}}\n  \\end{align} \n  \n Look at equation \\ref{math1}. Isn't that a cool function! Math blocks can also be constructed using the double dollar sign. But, these don't get a reference number associated with them\n\\footnote{This is a footnote!}.\n \n$$\n\\begin{bmatrix}\n1 & 3\\\\\n7 & 5\n\\end{bmatrix} \\odot\n\\begin{bmatrix}\n6 & 8\\\\\n4 & 2\n\\end{bmatrix}\\\\*\n$$\n\n\n\\section{Tables}\n\n\n% use this website to generate tables: https://www.tablesgenerator.com/\n\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{l|l|l|l}\n &  Short & Medium & Long \\\\ \\hline\n Topical & 1.0  &  0.6 & 0.2  \\\\ \\hline\n User & 0.0  & 0.2  & 0.2 \n\\end{tabular}\n\\caption{\\label{tab:googlePerformance}Google Precision Results}\n\\end{table}\n\n\nIf I am talking about something in a table, I can refer to table \\ref{tab:googlePerformance} like this\\footnote{Table generated with help of website tablesgenerator.com}.\nThat is it!\n\n\n\\section{Figures} \\label{sec:figures}\n\nWhat about including cool images in your document that looks all professional like?\n\n\n\n\\begin{figure*}[h!]\n    \\centering  % this centers the graphic on the page\n    \\includegraphics[width=.8\\textwidth]{data_visuzlization.png} % graphic has a width of 80% of the page\n    \\caption{Plot Shoing Age, Height, and Snowfolk Class} % text to display with figure\n    \\label{fig:dataViz} % label for you to cite the figure with\n\\end{figure*}\n\n\n% What about the [h!] at the begining of figure?\n% This parameter determines where the figure will be placed, there are several options:\n%\n% h -- place float here\n% t -- place at top of page\n% b -- place at bottom of page\n% p -- put on special page for floats\n% ! -- do what I specify and don't optimize page layout\n\nAfter you have your figure, you can refer to it like math, and tables like this: figure \\ref{fig:dataViz} is cool.\nWhy is this cool I hear you asking? Well, if you update the graphic, you just have to place it in this folder and overwrite the old one.\nYou don't have to search for it in a word document.\nAlso if you insert a graphic above figure \\ref{fig:dataViz}, you don't need to re-label anything.\n\n\n\\subsection{Side By Side Figures} \\label{sec:sidebyside}\n\nThe command subsection is used to create a subsection. There are also commands for subsubsections.\nYou can also reference sections like this: section \\ref{sec:sidebyside}.\nWe can see that section \\ref{sec:sidebyside} is inside section \\ref{sec:figures}.\nIf you want to reference a section, you have to add a label to it that is on the same line as the section command.\n\n\n\\begin{figure*}[h!]\n    \\centering\n    \\subfloat{{\\includegraphics[width=0.45\\textwidth]{height_roc_graph.png}}}%\n    \\qquad\n    \\subfloat{{\\includegraphics[width=0.45\\textwidth]{age_roc_graph.png}}}%\n    \\caption{ROC Curves for Age and Height Classifications}%\n    \\label{fig:rocCurves}\n\\end{figure*}\n\n\nCreating a side by side figure is very similar to how you would create a normal figure.\nHowever, note that for this you need the package \"subfig\". Referencing this is the same:\nfigure \\ref{fig:rocCurves}.\n\n\n\\subsection{Citations}\n\nWow, let's cite my favorite book \\cite{DUMMY:1}.\nIt is typical to put all your bibtex citations in a file ending with the extension \".bib\".\nAt the end of the document, you can create the bibliography using the \"\\\\bibliography\" command.\nWhat is amazing about this is that you can then specify what type of bibilography it generates. IE: you can cite using ieee, MLA, APA, etc. This package takes care of all the formatting and ordering of your citations. Another cool thing is that, you can have loads of citations in your bib file, but, the references list will get generated using only the ones that you ended up using in your paper. \n\n\\newpage\n\n\\bibliography{example} \n\\bibliographystyle{ieeetr}\n\n\\end{document}", "meta": {"hexsha": "4d8362a34b4b81803aad154a7941866a8e3bd37f", "size": 4859, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "basic_example.tex", "max_stars_repo_name": "jrtechs/latex-quick-reference", "max_stars_repo_head_hexsha": "8c65109aeccc859697a1c648ffc18d8f8e2fddde", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-19T11:01:31.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-19T11:01:31.000Z", "max_issues_repo_path": "basic_example.tex", "max_issues_repo_name": "jrtechs/latex-quick-reference", "max_issues_repo_head_hexsha": "8c65109aeccc859697a1c648ffc18d8f8e2fddde", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-02T20:03:44.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-02T20:03:44.000Z", "max_forks_repo_path": "basic_example.tex", "max_forks_repo_name": "jrtechs/latex-quick-reference", "max_forks_repo_head_hexsha": "8c65109aeccc859697a1c648ffc18d8f8e2fddde", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.9568345324, "max_line_length": 399, "alphanum_fraction": 0.7369829183, "num_tokens": 1340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.8757869803008764, "lm_q1q2_score": 0.7220530133196228}}
{"text": "\\section*{Exercise 1.1}\r\nThe number of all the conditions that selecting 200 people from 2000 people is\r\n\\[\r\n    N_1=\\binom{2000}{120}.\r\n\\]\r\nThe number of the conditions that my friend and I are selected is equal to the number of conditions that selecting 118 people from 1998 people. That is\r\n\\[\r\n    N_2=\\binom{1998}{118}.\r\n\\]\r\nHence, the probability that my friend and I are selected is\r\n\\[\r\n    P=\\frac{\\binom{1998}{118}}{\\binom{2000}{120}}=\\frac{1998!}{118!1880!}\\div\\frac{2000!}{120!1880!}\\approx0.00357.\r\n\\]\r\n\r\n\\section*{Exercise 1.2}\r\n\\enum{\r\n\\item\r\nWe denote that $C=B\\backslash A$, which means $A\\cap C=\\varnothing$.\r\n\r\nSince $P[\\bigcup_k A_k]=\\sum_k P[A_k]$, then $P[B]=P[A\\cup C]=P[A]+P[C]$.\r\n\r\nSince $P[C]\\geq 0$, then $P[B]\\geq P[A]$.\r\n\r\nHence $P[A]\\leq P[B]$.\r\n\r\n\\item\r\nSince $A$ and $B$ are independent, then $P[A\\cap B]=P[A]P[B]>0$.\r\n\r\nHence $A\\cap B \\neq \\varnothing$.\r\n\r\nThus $A$ and $B$ are not mutually exclusive. \r\n\r\n\\item\r\nWe denote that $C=A\\cap B$, so that\r\n\\[\r\n    (A\\backslash C)\\cap(C)\\cap(B\\backslash C)=\\varnothing.\r\n\\]\r\n\r\nSince $P[\\bigcup_k A_k]=\\sum_k P[A_k]$ for $\\bigcap_k A_k=\\varnothing$, then\r\n\r\n\\spl{\r\n    P[A\\cup B]&=P[(A\\backslash C)\\cup C\\cup(B\\backslash C)]\\\\\r\n    &=P[A\\backslash C]+P[C]+P[B\\backslash C]\\\\\r\n    &=P[A\\backslash C]+P[C]+P[B\\backslash C]\\textbf{+P[C]-P[C]}\\\\\r\n    &=(P[A\\backslash C]+P[C])+(P[B\\backslash C]+P[C])-P[C]\\\\\r\n    &=P[A]+P[B]-P[C]\\\\\r\n    &=P[A]+P[B]-P[A\\cap B].\r\n}\r\n}\r\n\r\n\\section*{Exercise 1.3}\r\n\\enum{\r\n\\item\r\nNo.\r\n\r\nAssume that the probability of \"heads\" for one toss is $p$, then\r\n\\spl{\r\n    &P[\\text{two heads}]=p^2=\\frac{1}{3}\\\\\r\n    &P[\\text{no head}]=(1-p)^2=\\frac{1}{3}\\\\\r\n    &P[\\text{one head}]=1-(1-p)^2-p^2=\\frac{1}{3}\\\\\r\n}\r\nThere's no such $p$ satisfying the equations.\r\n\r\n\\item \r\nNo.\r\n\r\nAssume that the probabilities of \"heads\" are respectively $p_1$ and $p_2$, then\r\n\\spl{\r\n    &P[\\text{two heads}]=p_1p_2=\\frac{1}{3}\\\\\r\n    &P[\\text{no head}]=(1-p1)(1-p_2)=\\frac{1}{3}\\\\\r\n    &P[\\text{one head}]=p_1(1-p_2)+p_2(1-p_1)=\\frac{1}{3}\\\\\r\n}\r\nWe obtain $\r\n\\left\\{\r\n\\begin{aligned}\r\n    p_1&=\\frac{3+\\sqrt{3}i}{6}\\\\ \r\n    p_2&=\\frac{3-\\sqrt{3}i}{6}\\\\ \r\n\\end{aligned}\r\n\\right.\r\n$\r\n\r\nHence there's no real root for $p_1$ and $p_2$.\r\n}\r\n\r\n\\section*{Exercise 1.4}\r\n\\enum{\r\n\\item \r\nThe probability that the selected participant has been asked the first question is $\\frac{1}{2}$; the probability that the selected participant has \\textbf{not} been asked the first question is $\\frac{1}{2}$.\r\n\r\nWe denote \"claim to see the barn\" as \"B\", \"has been asked the first question\" as \"A\".\r\n\r\n\\[\r\n    P=P[B|A]P[A]+P[B|\\urcorner A]P[\\urcorner A]=0.17\\times0.5+0.03\\times0.5=0.1\r\n\\]\r\n\r\n\\item\r\nSince\r\n\\spl{\r\n    P[A]&=0.5\\neq0\\\\\r\n    P[B|A]&=0.17,\\\\\r\n}\r\nthen\r\n\\[\r\n    P[B]=0.1\\neq P[B|A].\r\n\\]\r\nHence seeing the barn is not independent of being asked the first question.\r\n}\r\n\r\n\\section*{Exercise 1.5}\r\nWe suppose that the chips we can get are only from the market. Also, we suppose that the stolen chips are all sold on the market.\r\n\r\nDenote that \"being defective\" as \"D\" and \"being stolen\" as \"S\", so that\r\n\\[\r\n    P[S|D]=\\frac{P[D|S]P[S]}{P[D]}.\r\n\\]\r\nSince the stolen chips are stolen before inspection, then \r\n\\begin{equation}\\label{1}\r\n    P[D|S]=0.5.\r\n\\end{equation}\r\n\r\nFor the probability that the chip we get was stolen,\r\n\\begin{equation}\\label{2}\r\n    P[S]=0.01.\r\n\\end{equation}\r\n\r\nFinally,\r\n\\begin{equation}\\label{3} \r\n    P[D]=P[D|\\urcorner S]P[\\urcorner S]+P[D|S]P[S]=0.05\\times0.99+0.5\\times0.01=0.0545.\r\n\\end{equation}\r\n\r\nAccording to Results \\ref{1}, \\ref{2} and \\ref{3}, we obtain\r\n\\[\r\n    P[S|D]=\\frac{0.5\\times0.01}{0.0545}=\\frac{10}{109}\\approx0.0917.\r\n\\]\r\n\r\n\\section*{Exercise 1.6}\r\nThe prisoner is right.\r\n\r\nDenote that \"A\", \"B\", \"C\" means A, B, C is going to die, respectively; \"B*\" means B is told not to die by the warden.\r\n\r\nFor example, B is told not to die. Then we obtain\r\n\\spl{\r\n    P[A|B*]&=\\frac{P[B*|A]P[A]}{P[B*|A]P[A]+P[B*|B]P[B]+P[B*|C]P[C]}\\\\ \r\n    &=\\frac{\\frac{1}{2}\\times\\frac{1}{3}}{\\frac{1}{2}\\times\\frac{1}{3}+0\\times\\frac{1}{3}+1\\times\\frac{1}{3}}=\\frac{1}{3}.\r\n}\r\nThat is $P[C|B*]=1-P[A|B*]-P[B|B*]=1-\\frac{1}{3}-0=\\frac{2}{3}$.\r\n\r\nIn this case, the chance that A is going to die does not change, but the chance that C is going to die doubles.\r\n\r\n\\section*{Exercise 1.7}\r\n\\enum{\r\n\\item \r\n\\[\r\nm_X(t)=E[e^{tX}]=\\sum_{k=1}^n e^{tx_k}\\frac{1}{n}=\\frac{1}{n}\\sum_{k=1}{n}e^{tx_k},\\quad t\\in\\mathbb{R}.\r\n\\]\r\n\\item \r\n\\spl{\r\n    E[X]=\\frac{\\dd m_X(t)}{\\dd t}\\bigg|_{t=0}=\\frac{1}{n}\\sum_{k=1}^n x_ke^{tx_k}\\bigg|_{t=0}=\\frac{1}{n}\\sum_{k=1}^n x_k.\r\n}\r\n\\spl{\r\n    Var[X]&=E[X^2]-E[X]^2=\\frac{\\dd^2 m_X(t)}{\\dd t^2}\\bigg|_{t=0}-(\\frac{\\dd m_X(t)}{\\dd t}\\bigg|_{t=0})^2\\\\\r\n    &=\\frac{1}{n}\\sum_{k=1}^n x_k^2 e^{tx_k}\\bigg|_{t=0}-(\\frac{1}{n}\\sum_{k=1}^n x_k)^2\\\\\r\n    &=\\frac{1}{n}\\sum_{k=1}^nx_k^2-(\\frac{1}{n}\\sum_{k=1}^n x_k)^2.\r\n}\r\n}\r\n\r\n\\section*{Exercise 1.8}\r\nSince there exists some $\\varepsilon$ such that $m_X(t)=m_Y(t)$ for all $t\\in (-\\varepsilon,\\varepsilon)$, then their high order of derivatives exist and are the same. In other words,\r\n\\[\r\n    \\left\\{\r\n    \\begin{aligned}\r\n        &E[X]=\\frac{\\dd m_X(t)}{\\dd t}\\bigg|_{t=0}=\\frac{\\dd m_Y(t)}{\\dd t}\\bigg|_{t=0}=E[Y]\\\\\r\n        &E[X^2]=\\frac{\\dd^2 m_X(t)}{\\dd t^2}\\bigg|_{t=0}=\\frac{\\dd^2 m_Y(t)}{\\dd t^2}\\bigg|_{t=0}=E[Y^2]\\\\\r\n        &\\vdots\\\\\r\n        &E[X^{n}]=\\frac{\\dd^n m_X(t)}{\\dd t^n}\\bigg|_{t=0}=\\frac{\\dd^n m_Y(t)}{\\dd t^n}\\bigg|_{t=0}=E[Y^{n}]\\\\\r\n    \\end{aligned}\r\n    \\right.\r\n\\]\r\n\r\nWe also know that\r\n\\begin{equation}\\label{eq1}\r\n    \\left\\{\r\n    \\begin{aligned}\r\n        &E[X]=\\sum_{x=0}^nxf_X(x)\\\\\r\n        &E[X^2]=\\sum_{x=0}^nx^2f_X(x)\\\\\r\n        &\\vdots\\\\\r\n        &E[X^n]=\\sum_{x=0}^nx^nf_X(x)\\\\\r\n    \\end{aligned}\r\n    \\right.\r\n\\end{equation}\r\n\r\nSimilarly, for $(Y,f_Y)$,\r\n\\begin{equation}\\label{eq2}\r\n    \\left\\{\r\n    \\begin{aligned}\r\n        &E[Y]=\\sum_{x=0}^nxf_Y(x)\\\\\r\n        &E[Y^2]=\\sum_{x=0}^nx^2f_Y(x)\\\\\r\n        &\\vdots\\\\\r\n        &E[Y^n]=\\sum_{x=0}^nx^nf_Y(x)\\\\\r\n    \\end{aligned}\r\n    \\right.\r\n\\end{equation}\r\n\r\nWe also know that\r\n\\begin{equation}\\label{eq3}\r\n\\begin{split}\r\n    &f_X(0)+f_X(1)+\\hdots+f_X(n)=1,\\\\\r\n    &f_Y(0)+f_Y(1)+\\hdots+f_Y(n)=1.\r\n\\end{split}\r\n\\end{equation}\r\n\r\nTo simplify the calculations, we denote that\r\n\\[\r\n    \\textbf{E}_{(n+1)\\times1}=\\left(\r\n    \\begin{aligned}\r\n        &E[Y]\\\\\r\n        &E[Y^2]\\\\\r\n        &\\vdots\\\\\r\n        &E[Y^n]\\\\\r\n        &1\\\\\r\n    \\end{aligned}\r\n    \\right)\r\n    =\r\n    \\left(\r\n    \\begin{aligned}\r\n        &E[X]\\\\\r\n        &E[X^2]\\\\\r\n        &\\vdots\\\\\r\n        &E[X^n]\\\\\r\n        &1\\\\\r\n    \\end{aligned}\r\n    \\right),\r\n\\]\r\n\\[ \r\n    \\textbf{A}_{(n+1)\\times(n+1)}=\\left(\r\n    \\begin{tabular}{cccc}\r\n        0 & 1 & $\\hdots$ & n\\\\\r\n        $0^2$ & $1^2$ & $\\hdots$ & $n^2$\\\\\r\n        &$\\vdots$&&\\\\\r\n        $0^n$ & $1^n$ & $\\hdots$ & $n^n$\\\\\r\n        1 & 1 & $\\hdots$ & 1\\\\\r\n    \\end{tabular}\r\n    \\right),\r\n\\]\r\n\r\nwhere $\\textbf{det(A)}\\neq0$.\r\n\r\n\\[\r\n    \\textbf{X}_{(n+1)\\times1}=\\left(\r\n    \\begin{aligned}\r\n        &f_X(0)\\\\\r\n        &f_X(1)\\\\\r\n        &\\vdots\\\\\r\n        &f_X(n-1)\\\\\r\n        &f_X(n)\\\\\r\n    \\end{aligned}\r\n    \\right),\\quad\r\n    \\textbf{Y}_{(n+1)\\times1}=\r\n    \\left(\r\n    \\begin{aligned}\r\n        &f_Y(0)\\\\\r\n        &f_Y(1)\\\\\r\n        &\\vdots\\\\\r\n        &f_Y(n-1)\\\\\r\n        &f_Y(n)\\\\\r\n    \\end{aligned}\r\n    \\right)\r\n\\]\r\n\r\nHence, equations \\ref{eq1}, \\ref{eq2}, \\ref{eq3} can be presented as\r\n\\begin{equation}\\label{eq4}\r\n\\begin{split}\r\n    &\\textbf{A}\\textbf{X}=\\textbf{E}\\\\\r\n    &\\textbf{A}\\textbf{Y}=\\textbf{E} \r\n\\end{split}\r\n\\end{equation}\r\n\r\nWe can tell that Eqs. \\ref{eq4} are the same equation system. Since $\\textbf{det(A)}\\neq0$, we find that the equation system obtains only one solution.\r\n\r\nThus $\\textbf{X}=\\textbf{Y}$; that is\r\n\\begin{equation*}\r\n    \\left\\{\r\n    \\begin{aligned}\r\n        &f_X(0)=f_Y(0)\\\\\r\n        &f_X(1)=f_Y(1)\\\\\r\n        &\\vdots\\\\\r\n        &f_X(n)=f_Y(n)\\\\ \r\n    \\end{aligned}\r\n    \\right.\r\n\\end{equation*}\r\n\r\nIn other words, $f_X(x)=f_Y(x)$ for $x=0,1,\\hdots,n$.\r\n\r\n\\section*{Exercise 1.9}\r\n\\enum{\r\n\\item \r\nApplying the total probability formula, we obtain\r\n\\[\r\n    P[Z=z]=\\sum_{y=1}^zP[Z=z|Y=y]P[Y=y].\r\n\\]\r\nSince X and Y are independent, then\r\n\\[\r\n    P[Z=z|Y=y]=P[X=z-y|Y=y]=P[X=z-y].\r\n\\]\r\n\r\nThus\r\n\\[\r\n    P[Z=z]=\\sum_{y=1}^{z}P[X=z-y]P[Y=y]=\\sum_{x+y=z}P[X=x]P[Y=y].\r\n\\]\r\n\r\n\\item \r\nFor a geometric random variable, $P_g[X=x]=(1-p)^{x-1}p$.\r\n\r\nFor a pascal distribution with $r=2$, $$P_p[X=x]=\\binom{x-1}{1}p^2(1-p)^{x-2}=(x-1)p^2(1-p)^{x-2}$$.\r\n\r\nThe sum of two independent geometric random variables is\r\n\\spl{\r\n    P[Z=X+Y]&=P[Z=z]\\\\\r\n    &=\\sum_{x+y=z}P_g[X=x]P_g[Y=y]\\\\\r\n    &=\\sum_{x+y=z}(1-p)^{x-1}p(1-p)^{y-1}p\\\\\r\n    &=\\sum_{x+y=z}(1-p)^{x+y-2}p^2\\\\\r\n    &=\\sum_{x+y=z}(1-p)^{z-2}p^2\r\n}\r\nSince $x=1,\\hdots,z-1$ and $y=1,\\hdots,z-1$, then there are $z-1$ terms of $(1-p)^{z-2}p^2$.\r\n\\[\r\n    P[Z=z]=(z-1)(1-p)^{z-2}p^2=P_p[X=x].\r\n\\]\r\n\r\nHence, the sum of two independent geometric random variables follows a Pascal distribution with $r = 2$.\r\n}", "meta": {"hexsha": "6ffc897076e5500476eba5cc7e146ac275ae7c8e", "size": 8947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "VE401ProbStat/Assignments/Assignment1/sections/solution.tex", "max_stars_repo_name": "PANDApcd/Calculus", "max_stars_repo_head_hexsha": "2ce2283b640858f88e74f3838d48c68cfc1be82a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "VE401ProbStat/Assignments/Assignment1/sections/solution.tex", "max_issues_repo_name": "PANDApcd/Calculus", "max_issues_repo_head_hexsha": "2ce2283b640858f88e74f3838d48c68cfc1be82a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "VE401ProbStat/Assignments/Assignment1/sections/solution.tex", "max_forks_repo_name": "PANDApcd/Calculus", "max_forks_repo_head_hexsha": "2ce2283b640858f88e74f3838d48c68cfc1be82a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.1121212121, "max_line_length": 209, "alphanum_fraction": 0.5457695317, "num_tokens": 3679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.7220489447349266}}
{"text": "% !TeX root = ./corona_contact_tracing.tex\n% chktex-file 46\n% !TeX spellcheck = en-GB\n% !TeX encoding = utf8\n\n\\subsection{SIR Model}\nOur basic stochastic SIR model relies on the assumptions that every person in an environment can be modeled as a point value, which has a location (i.e.\\ GPS coordinates) and an infection state. These states can be either \\textit{susceptible} (S), \\textit{infected} (I), \\textit{recovered} (R) or in advanced models also \\textit{under quarantine} (Q) or \\textit{dead} (D). All individuals, here called agents, have a probability (here called diffusion rate $d$ to make a step per time step on a predefined grid. In the case, that some agents meet at the same location, disease spreading can occur. An infected agent spreads the disease with probability $\\beta$ to all the agents in its close vicinity (same location on the grid). Furthermore recovery is covered by taking a recovery rate into account, i.e.\\ a probability $\\gamma$ to recover from the disease per time step. If an infected agent recovers from the disease, the state of the agent changes from \\textit{infected} to \\textit{recovered}, which is definite (no double infections). The process ends, when no infected agents are left.\n\\begin{center}\n    Susceptibles $\\overset{\\beta}{\\longrightarrow}$ Infected $\\overset{\\gamma}{\\longrightarrow}$ Recovered.\n\\end{center}\n\nAn example of a early model state is shown in Figure~\\ref{fig:1}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.4\\linewidth]{initial_setup.png}\n    \\caption{Early state of SIR model, blue dots = susceptibles, red dots = infected agents, green dots = Recovered agents}%\n    \\label{fig:1}\n\\end{figure}\n\nIn this case, 1000 agents were initialized on a 100 by 100 grid, where a certain amount of infected agents were introduced as a seed. Letting the agents perform random walks on the grid (maximally one step each time step with probability $d$), and letting the model converge, the results in figure~\\ref{fig:2} can be observed.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.9\\linewidth]{1_1000_agents}\n    \\caption{Plot of the proportions of susceptible (blue), infected (red) and recovered (green) individuals in each state over time.}%\n    \\label{fig:2}\n\\end{figure}\n\nWith the above stated parameters ($d=0.8$, $\\beta=0.6$, $\\gamma=0.01$), the disease does not spread over the whole population. However over 80\\% were infected over time, which could be a very likely scenario of the corona out brake.", "meta": {"hexsha": "016844a2fff43661548357bcf504f9e918e35b70", "size": 2497, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/sir_model.tex", "max_stars_repo_name": "PellelNitram/corona_contact_tracing", "max_stars_repo_head_hexsha": "df5a6ba18b84397b721893fb5eb89889dc82ab2f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-03-21T20:44:54.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-14T05:32:49.000Z", "max_issues_repo_path": "docs/sir_model.tex", "max_issues_repo_name": "PellelNitram/corona_contact_tracing", "max_issues_repo_head_hexsha": "df5a6ba18b84397b721893fb5eb89889dc82ab2f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/sir_model.tex", "max_forks_repo_name": "PellelNitram/corona_contact_tracing", "max_forks_repo_head_hexsha": "df5a6ba18b84397b721893fb5eb89889dc82ab2f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-03-22T15:37:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-31T10:11:24.000Z", "avg_line_length": 86.1034482759, "max_line_length": 1092, "alphanum_fraction": 0.7553063676, "num_tokens": 646, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.721995553983215}}
{"text": "\\section{Overview}\\label{sec:abstractrefinements:overview}\n\nWe start with a high level overview of abstract refinements, \nby illustrating how they can be used to uniformly specify and \nautomatically verify various kinds of invariants.\n\n\\subsection{Parametric Invariants}\\label{sec:overview:parametric}\n\n\\mypara{Parametric Invariants via Type Polymorphism}\nSuppose we had a generic comparison @(<=) :: a -> a -> Bool@ as in\n\\ocaml.\nWe could use it to write: \n\\begin{code}\n  max     :: a -> a -> a\n  max x y = if x <= y then y else x \n\n  maximum :: [a] -> a\n  maximum (x:xs) = foldr max x xs\n\\end{code}\nIn essence, the type given for @maximum@ states that\n\\emph{for any} @a@, if a list of @a@ values is passed\ninto @maximum@, then the returned result is also an @a@\nvalue.\n%\nHence, for example, if a list of \\emph{prime} numbers \nis passed in, the result is prime, and if a list of \n\\emph{even} numbers is passed in, the result is even. \nThus, we can use refinement types \\cite{LiquidPLDI08} \nto verify\n%\n\\begin{code}\n  type Even = {v:Int | v % 2 = 0 }\n\n  maxEvens :: [Int] -> Even\n  maxEvens xs = maximum (0 : xs') \n    where xs' = [ x | x <- xs, x `mod` 2 == 0]\n\\end{code}\n%\nHere the @%@ represents the modulus operator in the refinement logic\n\\cite{z3} and we type the primitive {@mod :: x:Int -> y:Int -> {v: Int | v = x % y}@}.\nVerification proceeds as follows.\nGiven that {@xs :: [Int]@}, the system has to verify that\n{@maximum (0 : xs') :: Even@}.\n%\nTo this end, the type parameter of @maximum@ is instantiated with the \n\\emph{refined} type @Even@, yielding the instance:\n%\n\\begin{code}\n  maximum :: [Even] -> Even\n\\end{code}\n%\nThen, @maximum@'s argument should be proved to have type\n{@[Even]@}.\nSo, the type parameter of @(:)@ \nis instantiated with {@Even@}, yielding the instance: \n%\n\\begin{code}\n  (:) :: Even -> [Even] -> [Even]\n\\end{code}\n%\nFinally, the system infers that {@0 :: Even@} and {@xs' :: [Even]@}, \n\\ie the arguments of {@(:)@} have the expected types, thereby verifying\nthe program.\n%\nThe refinement type instantiations can be inferred,\nfrom an appropriate set of logical qualifiers, \nusing the abstract interpretation framework of Liquid\nTypes~\\cite{LiquidPLDI08}.\nHere, once \n@ v%2 = 0 @ \nis added to the set of qualifiers, either manually or (as done by \nour implementation) by automatically scraping predicates from \nrefinements appearing in specification signatures, the \nrefinement type instantiations and hence verification, proceed \nautomatically.\n%\nThus, parametric polymorphism offers an easy means of encoding \nsecond-order invariants, \\ie of quantifying over or parametrizing \nthe invariants of inputs and outputs of functions. \n\n\\mypara{Parametric Invariants via Abstract Refinements}\nInstead, suppose that the comparison operator was monomorphic and only\nworked for @Int@ values. The resulting (monomorphic) signatures\n\\begin{code}\n  max     :: Int -> Int -> Int\n  maximum :: [Int] -> Int\n\\end{code}\npreclude the verification of @maxEvens@ (\\ie typechecking against the \nsignature shown earlier). This is because the new type of @maximum@ \nmerely states that \\emph{some} @Int@  is returned as output and not \nnecessarily one that enjoys the properties of the values in the input\nlist. This is a shame, since the property clearly still holds.\nWe could type\n%@max :: forall t <: Int. t -> t -> t@\n\\begin{code}\n  max :: forall t <: Int. t -> t -> t\n\\end{code}\nbut this route would introduce the complications\nthat surround bounded quantification which could render checking \nundecidable~\\cite{piercebook}.\n\nTo solve this problem, we introduce \\emph{abstract refinements} \nwhich let us \nquantify or parameterize a type over its constituent refinements.\nFor example, we can type @max@ as\n\\begin{code}\n  max :: forall <p :: Int -> Bool>. Int<p> -> Int<p> -> Int<p>\n\\end{code}\nwhere @Int<p>@ is an abbreviation for the refinement type {@{v:Int | p v}@}.\nIntuitively, an abstract refinement @p@ is encoded in the refinement logic \nas an \\emph{uninterpreted function symbol}, which satisfies the\n\\emph{congruence} axiom~\\cite{Nelson81}\n%\n$$\\forall \\overline{X}, \\overline{Y}: (\\overline{X} = \\overline{Y})\n\\Rightarrow P(\\overline{X}) = P(\\overline{Y})$$\n%\nThus, it is trivial to verify, with an SMT solver, that @max@ \nenjoys the above type: the input types ensure that both @p x@ and @p y@ \nhold and hence the returned value in either branch satisfies \nthe refinement  @{v:Int | p v}@, thereby ensuring the output \ntype. By the same reasoning, we can generalize the type of @maximum@ \nto\n\\begin{code}\n  maximum :: forall <p :: Int -> Bool>. [Int<p>] -> Int<p>\n\\end{code}\nConsequently, we can recover the verification of @maxEvens@.\nNow, instead of instantiating a \\emph{type} parameter, we simply instantiate\nthe \\emph{refinement} parameter of @maximum@ with the concrete \nrefinement \n@{\\v -> v % 2 = 0}@,\nafter which type checking proceeds as usual \\cite{LiquidPLDI08}. \n%\nLater, we show how to retain automatic verification by inferring\nrefinement parameter instantiations via liquid typing\n(\\S~\\ref{sec:abstractrefinements:infer}).\n\n\\mypara{Parametric Invariants and Type Classes}\nThe example above regularly arises in practice, due to type classes. \nIn Haskell, the functions above are typed\n%\n\\begin{code}\n  (<=)    :: (Ord a) => a -> a -> Bool\n  max     :: (Ord a) => a -> a -> a\n  maximum :: (Ord a) => [a] -> a\n\\end{code}\n%\nWe might be tempted to ignore the typeclass constraint \nand treat \\ttcode{maximum} as @[a] -> a@. \nThis would be quite unsound, as typeclass predicates preclude\nuniversal quantification over refinement types. \nConsider the function @sum :: (Num a) => [a] -> a@ which adds the elements \nof a list.\n%Clearly,\nThe @Num@ class constraint implies that numeric operations occur \nin the function, so\nif we pass @sum@ a list of odd numbers, \nwe are \\emph{not} guaranteed to get back an odd number. \n\n%Thus, given that we cannot instantiate class-predicated type \n%parameters with arbitrary refinement types, \n\nThus, how do we soundly verify the desired type of @maxEvens@ \nwithout instantiating class predicated type parameters with \narbitrary refinement types? First, via the same analysis as \nthe monomorphic @Int@ case, we establish that\n%\n\\begin{code}\n  max    :: forall <p :: a -> Bool>. (Ord a) => a<p> -> a<p> -> a<p>\n  maximum:: forall <p :: a -> Bool>. (Ord a) => [a<p>] -> a<p>\n\\end{code}\n%\nNext, at the call-site for @maximum@ in @maxEvens@ we\ninstantiate the type variable @a@ with @Int@ and \nthe abstract refinement @p@ with @{\\v -> v % 2 = 0}@\nafter which, the verification proceeds as described\nearlier (for the @Int@ case).\nThus, abstract refinements allow us to quantify over \ninvariants without relying on parametric polymorphism, \neven in the presence of type classes.\n\n\\subsection{Index-Dependent Invariants}\\label{sec:overview:index}\n\nNext, we illustrate how abstract invariants allow us to \nspecify and verify index-dependent invariants of key-value maps. \nTo this end, we develop a small library of \\emph{extensible vectors} \nencoded, for purposes of illustration, as functions from @Int@ to \nsome generic range @a@. Formally, we specify vectors as \n%\n\\begin{code}\n  data Vec a <dom :: Int -> Bool, rng :: Int -> a -> Bool> \n    = V (i:Int<dom> -> a <rng i>)\n\\end{code}\n%\nHere, we are parameterizing the definition of the type @Vec@ \nwith \\emph{two} abstract refinements, @dom@ and @rng@, which\nrespectively describe the \\emph{domain} and \\emph{range} of the vector.\nThat is, @dom@ describes the set of \\emph{valid} indices\nand @r@ specifies an invariant relating each @Int@ index\nwith the value stored at that index.\n\n\\mypara{Creating Vectors}\nWe can use the following basic functions to create vectors:\n%\n\\begin{code}\n  empty :: forall <p :: Int -> a -> Bool>.Vec<{\\_ -> False}, p> a\n  empty = V (\\_ -> error \"Empty Vec\")\n\n  create :: x:a -> Vec <{\\_ -> True}, {\\_ v -> v = x}> a\n  create x = V (\\_ -> x)\n\\end{code}\n%\nThe signature for @empty@ states that its domain is empty (\\ie is\nthe set of indices satisfying the predicate @False@) and that the\nrange satisfies @any@ invariant. The signature for @create@,\ninstead, defines a \\emph{constant} vector that maps every index to the\nconstant @x@.\n\n\\mypara{Accessing Vectors}\nWe can write the following @get@ function for reading the contents\nof a vector at a given index:\n%\n\\begin{code}\n  get :: forall <d :: Int -> Bool, r :: Int -> a -> Bool>\n         i:Int<d> -> Vec<d, r> a -> a<r i>\n  get i (V f) = f i\n\\end{code}\n%\nThe signature states that for any domain @d@ and range @r@,\nif the index @i@ is a valid index, \\ie is of type, \\verb+Int<d>+ \nthen the returned value is an \\verb+a+ that additionally satisfies the\nrange refinement at the index @i@.\n%\nThe type for @set@, which \\emph{updates} the vector at\na given index, is even more interesting, as it allows us to \n\\emph{extend} the domain of the vector:\n%\n\\begin{code}\n  set :: forall <d :: Int -> Bool, r :: Int -> a -> Bool>\n         i:Int<d>\n      -> a<r i>\n      -> Vec<d && {\\k -> k != i}, r> a\n      -> Vec<d, r> a\n  set i v (V f) = V (\\k -> if k == i then v else f k)\n\\end{code}\n%\nThe signature for @set@ requires that \n(a)~the input vector is defined everywhere at @d@ \\emph{except}\nthe index @i@ and \n(b)~the value supplied must be of type @a<r i>@, \\ie satisfy the range \nrelation at the index @i@ at which the vector is being updated.\nThe signature ensures that the output vector is defined at\n@d@ and each value satisfies the index-dependent range refinement @r@.\n%\nNote that it is legal to call @get@ with a vector that is \\emph{also} \ndefined at the index @i@ since, by contravariance, such a vector is a\nsubtype of that required by (a).\n\n\n\\mypara{Initializing Vectors} Next, we can write the following function,\n@init@, that ``loops\" over a vector, to @set@ each index to \na value given by some function.\n%\n\\begin{code}\n  initialize :: forall <r :: Int -> a -> Bool>.\n                (z: Int -> a<r z>) \n             -> i: {v: Int | v >= 0} \n             -> n: Int \n             -> Vec <{\\v -> 0 <= v && v < i}, r> a \n             -> Vec <{\\v -> 0 <= v && v < n}, r> a \n\n  initialize f i n a \n    | i >= n    = a\n    | otherwise = initialize f (i+1) n (set i (f i) a)\n\\end{code}\n%\nThe signature requires that \n(a)~the higher-order function @f@ produces values that satisfy \nthe range refinement @r@ and \n(b)~the vector is initialized from @0@ to @i@.\n%\nThe function ensures that the output vector is initialized from @0@\nthrough @n@.\n%\nWe can thus verify that\n%\n\\begin{code}\n  idVec   :: Vec <{\\v -> 0<=v && v<n}, {\\i v -> v=i}> Int\n  idVec n = initialize (\\i -> i) 0 n empty\n\\end{code}\n%\n\\ie @idVec@ returns a vector of size @n@ where each\nkey is mapped to itself. Thus, abstract refinement types allow us \nto verify low-level idioms such as the incremental initialization \nof vectors, which have previously required \nspecial analyses~\\cite{Gopan05,JhalaMcMillanCAV07,CousotsPOPL11}.\n\n\\mypara{Null-Terminated Strings}\n%\nWe can also use abstract refinements to verify code which \nmanipulates C-style null-terminated strings, \nrepresented as @Char@ vectors for ease of exposition.\nFormally, a null-terminated string of size @n@ has the type\n%\n\\begin{code}\n  type NullTerm n \n    = Vec <{\\v -> 0<=v<n}, {\\i v -> i=n-1 => v='\\0'}> Char\n\\end{code}\n%%Vec <{\\v -> 0 <= v && v < n},\n%%     {\\i v -> i = n - 1 => v = '\\0'}>\n%%    Char\n%\nThe above type describes a length-@n@ vector of characters whose\nlast element must be a null character, signalling the end of\nthe string.\n%\nWe can use this type in the specification of a function,\n@upperCase@, which iterates through the characters of a string,\nuppercasing each one until it encounters the null terminator:\n%\n%  Vec <{\\v -> 0 <= v && v < n},\n%       {\\i v -> i = n - 1 => v = '\\0'}>\n%      Char ->\n%  Vec <{\\v -> 0 <= v && v < n},\n%       {\\i v -> i = n - 1 => v = '\\0'}>\n%      Char\n% upperCase n s = ucs 0 s where\n%   ucs i s = let c = get i s in\n%             if c == '\\0' \n%               then s\n%               else ucs (i + 1) (set i (toUpper c) s)\n\\begin{code}\n  upperCase :: n:{v: Int| v>0} -> NullTerm n -> NullTerm n\n  upperCase n s = ucs 0 s \n    where\n      ucs i s = case get i s of\n                  '\\0' -> s\n                  c    -> ucs (i + 1) (set i (toUpper c) s)\n\\end{code}\n%\nNote that the length parameter @n@ is provided solely as a ``witness''\nfor the length of the string @s@, which allows us to use the length of\n@s@ in the type of @upperCase@; @n@ is not used in the\ncomputation.\n%\nIn order to establish that each call to @get@ accesses string @s@\nwithin its bounds, our type system must establish that, at each call\nto the inner function @ucs@, @i@ satisfies the type\n@{v: Int | 0 <= v && v < n}@.\n%\nThis invariant is established as follows.\n%\nFirst, the invariant trivially holds on the first call to @ucs@, as\n@n@ is positive and @i@ is $0$.\n%\nSecond, we assume that @i@ satisfies the type\n%\n@{v: Int | 0 <= v && v < n}@,\n%\nand, further, we know from the types of @s@ and @get@ that @c@ has the\ntype @{v: Char | i = n - 1 => v = '\\0'}@.\n%\nThus, if @c@ is non-null, then @i@ cannot be equal to @n - 1@.\n%\nThis allows us to strengthen our type for @i@ in the else branch to\n@{v: Int | 0 <= v && v < n - 1}@ and thus to conclude that the value\n@i + 1@ recursively passed as the @i@ parameter to @ucs@ satisfies the\ntype @{v: Int | 0 <= v && v < n}@, establishing the inductive\ninvariant and thus the safety of the @upperCase@ function.\n\n\\mypara{Memoization} \nNext, let us illustrate how the same expressive signatures allow us to\nverify memoizing functions. We can specify to the SMT solver the \ndefinition of the Fibonacci function via an uninterpreted function \n@fib@ and an axiom:\n%\n\\begin{code}\n  measure fib :: Int -> Int\n  axiom: forall i. (fib i) = if i <= 1 then 1 else fib (i-1) + fib (i-2)\n\\end{code}\n%axiom_fib :: i:Int -> {v: Bool | (? v) <=> (fib(i) = i <= 1 ? 1 : fib(i-1) + fib(i-2))}\n%\nNext, we define a type alias @FibV@ for the vector \nwhose values are either @0@ (\\ie undefined) or \nequal to the Fibonacci number of the corresponding index. \n%(We use @Int@ instead of @Maybe Int@ as the domain for brevity.)\n%\n\\begin{code}\n  type FibV = Vec<{\\_->True},{\\i v-> v != 0 => v = fib i}> Int \n\\end{code}\n%\nFinally, we can use the above alias to verify @fastFib@, \nan implementation of the Fibonacci function, which uses \na vector memoize intermediate results \n%\n\\begin{code}\n  fastFib   :: n:Int -> {v:Int | v = fib(n)}\n  fastFib n = snd $ fibMemo (create 0) n\n\n  fibMemo :: FibV -> i:Int -> (FibV, {v: Int | v = fib(i)})   \n  fibMemo t i \n    | i <= 1    = (t, 1)\n    | otherwise = case get i t of   \n                    0 -> let (t1, n1) = fibMemo t  (i-1)\n                             (t2, n2) = fibMemo t1 (i-2)\n                             n        = n1 + n2 \n                         in  (set i n t2,  n)\n                    n -> (t, n)\n\\end{code} %$ \n%\n%% axiom_fib :: i:Int -> {v: Bool | (? v) <=> (fib(i) = i <= 1 ? 1 : fib(i-1) + fib(i-2))}\n%%\n%% fibMemo t i \n%%   | i <= 1    \n%%   = (t, assume (axiom_fib i) $ 1)\n%%   \n%%   | otherwise \n%%   = case get i t of   \n%%       0 -> let (t1, n1) = fibMemo t  (i-1)\n%%                (t2, n2) = fibMemo t1 (i-2)\n%%                n        = assume (axiom_fib i) $ n1 + n2\n%%            in  (set i n t2,  n)\n%%       n -> (t, n)\n%\nThus, abstract refinements allow us to define key-value maps with\nindex-dependent refinements for the domain and range. \nQuantification over the domain and range refinements allows us\nto define generic access operations (\\eg @get@, @set@,\n@create@, @empty@) whose types enable us establish\na variety of precise invariants.\n\n\\subsection{Recursive Invariants}\\label{sec:overview:rec}\n\nNext, we turn our attention to recursively defined datatypes and show \nhow abstract refinements allow us to specify and verify high-level\ninvariants that relate the elements of a recursive structure.\nConsider the following refined definition for lists:\n%\n\\begin{code}\n  data [a] <p :: a -> a -> Bool> where\n    []  :: [a]<p>\n    (:) :: h:a -> [a<p h>]<p> -> [a]<p>\n\\end{code}\n%data List <p :: a -> a -> Bool> a where\n%  Nil  :: List<p> a \n%  Cons :: h:a -> List<p> (a<p h>) -> List<p> a\n%\n%% data List a <p :: a -> a -> Bool>  \n%%   = Cons { head :: a\n%%          , tail :: List <p> (a <p head>) }\n%%   | Nil\n%% \\end{code}\n%\nThe definition states that a value of type @[a]<p>@ \nis either empty (@[]@) or constructed from a pair of  \na \\emph{head} @h::a@ and a \\emph{tail} of a list of \n@a@ values \\emph{each} of which satisfies the refinement @(p h)@. \nFurthermore, the abstract refinement @p@ holds recursively\nwithin the tail, ensuring that the relationship @p@ \nholds between \\emph{all} pairs of list elements.\n\nThus, by plugging in appropriate concrete refinements, \nwe can define the following aliases, which correspond \nto the informal notions implied by their names:\n\\begin{code}\n  type IncrList a = [a]<{\\h v -> h <= v}>\n  type DecrList a = [a]<{\\h v -> h >= v}>\n  type UniqList a = [a]<{\\h v -> h != v}>\n\\end{code}\n%%\n%\\begin{code}\n%type IncList a    = List <{\\h v -> h <= v}> a \n%type DecList a    = List <{\\h v -> h >= v}> a \n%type UniqueList a = List <{\\h v -> h != v}> a \n%\\end{code}\n%\nThat is, @IncrList a@ (resp. @DecrList a@) describes a list sorted\nin increasing (resp. decreasing) order and @UniqList a@ describes\na list of \\emph{distinct} elements, \\ie not containing any duplicates.\nWe can use the above definitions to verify\n%\n\\begin{code}\n  [1, 2, 3, 4] :: IncrList Int\n  [4, 3, 2, 1] :: DecrList Int\n  [4, 1, 3, 2] :: UniqList Int\n\\end{code}\n%\n%\n%\\begin{code}\n%xs :: IncList Int\n%xs = 1 `Cons` 2 `Cons` 3 `Cons` 4 `Cons` Nil\n%\n%ys :: IncList Int\n%ys = 4 `Cons` 3 `Cons` 2 `Cons` 1 `Cons` Nil\n%\n%zs :: UniqueList Int\n%zs = 4 `Cons` 1 `Cons` 3 `Cons` 2 `Cons` Nil\n%\\end{code}\n%\nMore interestingly, we can verify that the usual algorithms \nproduce sorted lists:\n%\n\\begin{code}\n  insertSort :: (Ord a) => [a] -> IncrList a \n  insertSort []     = []\n  insertSort (x:xs) = insert x (insertSort xs) \n  \n  insert :: (Ord a) => a -> IncrList a -> IncrList a \n  insert y []       = [y]\n  insert y (x:xs) \n    | y <= x        = y : x : xs\n    | otherwise     = x : insert y xs\n\\end{code}\n%\n%insertSort        :: (Ord a) => List a -> IncList a \n%insertSort Nil           = Nil \n%insertSort (x `Cons` xs) = insert x (insertSort xs) \n%\n%insert y Nil                  \n%  = y `Cons` Nil \n%insert y (Cons x xs) \n%  | y <= x    = y `Cons` (x `Cons` xs) \n%  | otherwise = x `Cons` (insert y xs)\n%\n%\nThus, abstract refinements allow us to \\emph{decouple} the definition \nof the list from the actual invariants that hold.\nThis, in turn, allows us to conveniently reuse the same \nunderlying (non-refined) type to implement various algorithms \nunlike, say, singleton-type based implementations which require \nup to three different types of lists (with three different ``nil\" and ``cons\" \nconstructors~\\cite{Sheard06}). This, makes abstract refinements \nconvenient for verifying complex sorting implementations like that of \n@Data.List.sort@ which, for efficiency, use lists with different \nproperties (\\eg increasing and decreasing).\n\n\\mypara{Multiple Recursive Refinements} \nWe can define recursive types with multiple parameters. \nFor example, consider the following refined version of a type used \nto encode functional maps (\\ttcode{Data.Map}):\n%\n\\begin{code}\n  data Tree k v <l :: k -> k -> Bool, r :: k -> k -> Bool>\n    = Bin { key   :: k\n          , value :: v \n          , left  :: Tree <l, r> (k <l key>) v \n          , right :: Tree <l, r> (k <r key>) v }\n    | Tip\n\\end{code}\n%\nThe abstract refinements \\ttcode{l} and \\ttcode{r} relate each \\ttcode{key}\nof the tree with \\emph{all} the keys in the \\emph{left} and \\emph{right}\nsubtrees of \\ttcode{key}, as those keys are respectively of type \n\\ttcode{k <l key>} and \\ttcode{k <r key>}.\n%\nThus, if we instantiate the refinements with the following predicates\n\\begin{code}\n  type BST k v     = Tree<{\\x y -> x> y},{\\x y-> x< y}> k v\n  type MinHeap k v = Tree<{\\x y -> x<=y},{\\x y-> x<=y}> k v\n  type MaxHeap k v = Tree<{\\x y -> x>=y},{\\x y-> x>=y}> k v\n\\end{code}\nthen @BST k v@, @MinHeap k v@ and @MaxHeap k v@ \ndenote exactly binary-search-ordered, min-heap-ordered, and\nmax-heap-ordered trees (with keys and values of types @k@ and\n@v@).  \n%\nWe demonstrate in (\\S~\\ref{sec:experiments}) how we use the above types to \nautomatically verify ordering properties of complex, full-fledged libraries.\n\n\\subsection{Inductive Invariants}\\label{sec:overview:induction}\n\nFinally, we explain how abstract refinements allow us to formalize \nsome kinds of structural induction within the type system. \n\n\\mypara{Measures} First, let us formalize a notion of \\emph{length} for\nlists within the refinement logic. To do so, we define a special \n\\ttcode{len} measure by structural induction\n%\n\\begin{code}\n  measure len :: [a] -> Int \n    len []      = 0 \n    len (x:xs)  = 1 + len(xs)\n\\end{code}\n%\nWe use the measures to automatically strengthen the \ntypes of the data constructors~\\ref{sec:measures}:\n%\n\\begin{code}\n  data [a] where \n    []  :: {v:[a] | len v = 0}\n    (:) :: a -> xs:[a] -> {v:[a]| len v = 1 + len xs}\n\\end{code}\n%\nNote that the symbol \\ttcode{len} is encoded as an \\emph{uninterpreted}\nfunction in the refinement logic, and is, except for the congruence axiom,\nopaque to the SMT solver. The measures are guaranteed, by construction, \nto terminate and so we can soundly use them as uninterpreted \nfunctions in the refinement logic. Notice also, that we can define \n\\emph{multiple} measures for a type; in this case we simply conjoin \nthe refinements from each measure when refining each data constructor.\n\nWith these strengthened constructor types, we can verify, for example,\nthat @append@ produces a list whose length is the sum of the input lists'\nlengths:\n%\n\\begin{code}\n  append :: l:[a] -> m:[a] -> {v:[a]| len v = len l + len m}\n  append []     zs = zs\n  append (y:ys) zs = y : append ys zs\n\\end{code}\n%\nHowever, consider an alternate definition of @append@ that uses @foldr@\n%\n\\begin{code}\n  append ys zs = foldr (:) zs ys \n\\end{code}\n%\nwhere @foldr :: (a -> b -> b) -> b -> [a] -> b@.\nIt is unclear how to give @foldr@ a (first-order) refinement type\nthat captures the rather complex fact that the fold-function \nis ``applied\" all over the list argument, or, that it is a catamorphism.\nHence, hitherto, it has not been possible to verify the second definition \nof @append@.\n\n\n\\mypara{Typing Folds} Abstract refinements allow us to \nsolve this problem with a very expressive type for \\ttcode{foldr} \nwhilst remaining firmly within the boundaries of SMT-based \ndecidability. We write a slightly modified fold:\n%\n\\begin{code}\n  foldr :: forall <p :: [a] -> b -> Bool>. \n           (xs:[a] -> x:a -> b <p xs> -> <p (x:xs)>) \n        -> b<p []> \n        -> ys:[a]\n        -> b<p ys>\n  foldr op b []     = b\n  foldr op b (x:xs) = op xs x (foldr op b xs) \n\\end{code}\n%\nThe trick is simply to quantify over the relationship @p@\nthat @foldr@ establishes between the input list @xs@ and\nthe output @b@ value. This is formalized by the type signature,\nwhich encodes an induction principle for lists: \nthe base value @b@ must \n(1)~satisfy the relation with the empty list,\nand the function @op@ must take \n(2)~a value that satisfies the relationship with the tail \n    @xs@ (we have added the @xs@ as an extra ``ghost\"\n    parameter to @op@), \n(3)~a head value @x@, and return\n(4)~a new folded value that satisfies the relationship with \\ttcode{x:xs}.\nIf all the above are met, then the value returned by @foldr@\nsatisfies the relation with the input list @ys@.\n%\nThis scheme is not novel in itself~\\cite{coq-book}\n--- what is new is the encoding, via uninterpreted predicate symbols, \nin an SMT-decidable refinement type system.\n\n\\mypara{Using Folds} Finally, we can use the expressive type\nfor the above @foldr@ to verify various inductive properties \nof client functions:\n%\n\\begin{code}\n  length :: zs:[a] -> {v: Int | v = len zs}\n  length = foldr (\\_ _ n -> n + 1) 0\n\n  append :: l:[a] -> m:[a] -> {v:[a]| len v = len l + len m}\n  append ys zs = foldr (\\_ -> (:)) zs ys \n\\end{code}\n%\nThe verification proceeds by just (automatically) instantiating the \nrefinement parameter \\ttcode{p} of \\ttcode{foldr} with the concrete\nrefinements, via Liquid typing:\n%\n\\begin{code}\n  {\\xs v -> v = len xs}                 -- for length\n  {\\xs v -> len v = len xs + len zs}    -- for append\n\\end{code}\n\n%%This concludes a tour of the many kinds of expressive specifications\n%%that abstract refinements enable, while preserving fully automatic\n%%verification. \n", "meta": {"hexsha": "f22f5ba135fea21df4eec94ad5a3d493549477ea", "size": 24564, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/abstractrefinements/overview.tex", "max_stars_repo_name": "nikivazou/thesis", "max_stars_repo_head_hexsha": "a12f2e857a358e3cc08b657bb6b029ac2d500c3b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-12-02T00:46:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-20T07:04:01.000Z", "max_issues_repo_path": "text/abstractrefinements/overview.tex", "max_issues_repo_name": "nikivazou/thesis", "max_issues_repo_head_hexsha": "a12f2e857a358e3cc08b657bb6b029ac2d500c3b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "text/abstractrefinements/overview.tex", "max_forks_repo_name": "nikivazou/thesis", "max_forks_repo_head_hexsha": "a12f2e857a358e3cc08b657bb6b029ac2d500c3b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2016-12-02T00:46:51.000Z", "max_forks_repo_forks_event_max_datetime": "2016-12-02T00:46:51.000Z", "avg_line_length": 35.9648609078, "max_line_length": 90, "alphanum_fraction": 0.65917603, "num_tokens": 7342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631476836816, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7219955495344964}}
{"text": "\\section{Derivative Rules for Trigonometric Functions}\\label{sec:DerivativeRulesTrig}\r\nWe next look at the derivative of the sine function.\r\nIn order to prove the derivative formula for sine, we recall two limit computations from earlier:\r\n$$\\lim_{x\\to 0}\\frac{\\sin x}{x}=1\\qquad\\mbox{~and~}\\qquad\\lim_{x\\to 0}\\frac{\\cos x -1}{x}=0,$$\r\nand the double angle formula\r\n$$\\sin\\left(A+B\\right)=\\sin A\\cos B+\\sin B\\cos A.$$\r\n\r\n\\begin{theorem}{Derivative of Sine Function}{Derivative of Sine Function}\r\n$\\ds{\\left(\\sin x\\right)'=\\cos x}$\r\n\\end{theorem}\r\n\r\n\\begin{proof}\r\nLet $f(x)=\\sin x$. \r\nUsing the definition of derivative we have:\r\n$$\\begin{array}{ccl}\r\nf'(x) & = &  \\ds{\\lim_{h\\to 0}\\frac{f(x+h)-f(x)}{h}}\\\\\r\n\\\\\r\n& = & \\ds{\\lim_{h\\to 0}\\frac{\\sin(x+h)-\\sin x}{h}}\\\\\r\n\\\\\r\n& = & \\ds{\\lim_{h\\to 0}\\frac{\\sin x\\cos h+\\cos x\\sin h-\\sin x}{h}}\\\\\r\n\\\\\r\n& = & \\ds{\\lim_{h\\to 0}\\sin x\\cdot\\lim_{h\\to 0}\\frac{\\cos h-1}{h}+\\lim_{h\\to 0}\\cos x\\cdot\\lim_{h\\to 0}\\frac{\\sin h}{h}}\\\\\r\n\\\\\r\n& = & \\ds{\\sin x\\cdot 0+\\cos x\\cdot 1}\\\\\r\n\\\\\r\n& = & \\ds{\\cos x}\\\\\r\n\\end{array}$$\r\nsince \r\n$$\\lim_{x\\to 0}\\frac{\\sin x}{x}=1\\mbox{~~and~~}\\lim_{x\\to 0}\\frac{\\cos x -1}{x}=0.$$\r\n\\end{proof}\r\n\r\nA formula for the derivative of the \\ifont{cosine function} can be found in a similar fashion:\r\n$$\\frac{d}{dx}(\\cos x)=-\\sin x.$$\r\n\r\nUsing the quotient rule we get formulas for the remaining trigonometric ratios. To summarize, here are the derivatives of the six trigonometric functions:\r\n$$\\begin{array}{|rcl|rcl|rcl|}\r\n\\hline\r\n~&~&~&~&~&~&~&~&~\\\\\r\n\\ds{\\frac{d}{dx}\\left(\\sin(x)\\right)} &= & \\ds{\\cos(x)} &\r\n\\ds{\\frac{d}{dx}\\left(\\tan(x)\\right)}&= & \\ds{\\sec^2(x)} &\r\n\\ds{\\frac{d}{dx}\\left(\\csc(x)\\right)} &= & \\ds{-\\csc(x)\\cot(x)} \\\\\r\n~&~&~&~&~&~&~&~&~\\\\\r\n\\hline\r\n~&~&~&~&~&~&~&~&~\\\\\r\n\\ds{\\frac{d}{dx}\\left(\\cos(x)\\right)} &= & \\ds{-\\sin(x)} &\r\n\\ds{\\frac{d}{dx}\\left(\\cot(x)\\right)} &= & \\ds{-\\csc^2(x)} &\r\n\\ds{\\frac{d}{dx}\\left(\\sec(x)\\right)} &= & \\ds{\\sec(x)\\tan(x)} \\\\\r\n~&~&~&~&~&~&~&~&~\\\\\r\n\\hline\r\n\\end{array}$$\r\n\r\n\\begin{example}{Derivative of Product of Trigonometric Functions}{Derivative of Product of Trigonometric Functions}\r\nFind the derivative of $f(x)=\\sin x\\tan x$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nUsing the Product Rule we obtain\r\n$$f'(x)=\\cos x\\tan x+\\sin x\\sec^2x.$$\r\n\\end{solution}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:DerivativeRulesTrig}}\r\n\r\n\\begin{enumialphparenastyle}\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind the derivatives of the following functions.\r\n\\begin{multicols}{3}\r\n\\begin{enumerate}\r\n\t\\item\t$\\ds \\sin x\\cos x$\r\n\t\\item\t$\\ds \\cot x$\r\n\t\\item\t$\\ds\\csc x-x\\tan x$\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFind the points on the curve $\\ds y= x+ 2\\cos x$ that have a\r\nhorizontal tangent line.\r\n\\begin{sol} \r\n$\\ds \\pi/6+2n\\pi$, $5\\pi/6+2n\\pi$, any integer $n$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "2573b1bd51cc8754fe7109507eb8658f1c4f0a68", "size": 2923, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-derivatives/4-5-der-rules-trig.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4-derivatives/4-5-der-rules-trig.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4-derivatives/4-5-der-rules-trig.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.2159090909, "max_line_length": 155, "alphanum_fraction": 0.5935682518, "num_tokens": 1125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122188543454, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.7219103206140682}}
{"text": "%---------------------------Scaled Jacobian-----------------------------\n\\section{Scaled Jacobian}\n\nLet $J$ be the Jacobian as defined in \\S\\ref{s:tet-jacobian}\n\n\\[\n\\lambda_1 = \\normvec{ L_0 }\n            \\normvec{ L_2 }\n            \\normvec{ L_3 }  \n\\]\n\n\\[\n\\lambda_2 = \\normvec{ L_0 }\n            \\normvec{ L_1 }\n            \\normvec{ L_4 }  \n\\]\n\n\\[\n\\lambda_3 = \\normvec{ L_1 }\n            \\normvec{ L_2 }\n            \\normvec{ L_5 }  \n\\]\n\n\\[\n\\lambda_4 = \\normvec{ L_3 }\n            \\normvec{ L_4 }\n            \\normvec{ L_5 }  \n\\]\n\n\n\\[\n\\lambda_{\\max} = \\max\\left\\{\\lambda_1, \\lambda_2, \\lambda_3, \\lambda_4, J\\right\\} \n\\]\n\n\\begin{equation*}\nq = \\frac{J\\sqrt{2}}{\\lambda_{\\max}}\n\\end{equation*}\n\nNote that if $\\lambda_{\\max} < DBL\\_MIN$, we set $q = DBL\\_MAX$.\n\n\\tetmetrictable{scaled Jacobian}%\n{$1$}%                                        Dimension\n{$[\\frac{1}{2},\\frac{\\sqrt{2}}{2}]$}%         Acceptable range\n{$[-\\frac{\\sqrt{2}}{2},\\frac{\\sqrt{2}}{2}]$}% Normal range\n{$[-DBL\\_MAX,DBL\\_MAX]$}%                     Full range\n{1}%                                          Equilateral tet\n{\\cite{knu:00}}%                              Citation\n{v\\_tet\\_scaled\\_jacobian}%                            Verdict function name\n\n", "meta": {"hexsha": "71395e9879b36d408dcb567793740449a9ac8067", "size": 1227, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetScaledJacobian.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetScaledJacobian.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetScaledJacobian.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 24.54, "max_line_length": 82, "alphanum_fraction": 0.4612876936, "num_tokens": 401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355092, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.7219103146316452}}
{"text": "\\lab{Solitons}{Solitons}\n\\label{lab:solitons}\n\n\\objective{\nWe study traveling wave solutions of the Korteweg-de Vries (KdV) equation, using a pseudospectral discretization in space and a Runge-Kutta integration scheme in time.  }\n\n\nHere we consider soliton solutions of the Korteweg-de Vries (KdV) equation. This equation is given by \n\\[  \\frac{\\partial u }{\\partial t} + u \\frac{\\partial u}{\\partial x} + \\frac{\\partial^3 u}{\\partial x^3} = 0.\n\\]\nThe KdV equation is a canonical equation that describes shallow water waves. \n\nThe KdV equation possesses traveling wave solutions called solitons.  \nThese traveling waves have the form \n\\[ u(x,t) = 3s \\sech^2\\left(\\frac{\\sqrt{s}}{2}(x - st - a)\\right),\n\\]\nwhere $s$ is the speed of the wave. \nSolitons were first studied by John Scott Russell in 1834, in the Union Canal in Scotland. \nWhen a canal boat suddenly stopped, the water piled up in front of the boat continued moving down the canal in the shape of a pulse.  \n\nNote that there is a soliton solution for each wave speed $s$, and that the amplitude of the soliton depends on the speed of the wave. \nSolitons are traveling waves in the shape of a pulse, they are nonlinearly stable (bumped waves return to their previous shape), and they maintain their energy as they travel. \nThey also enjoy an additional stability property: They play well with others. \nTwo interacting solitons will maintain their shape after crossing paths. \n\n\n\\section*{Numerical solution}\nConsider the KdV equation on $[-\\pi,\\pi]$, together with an appropriate initial condition: \n\\begin{align*}\n\t &{ }u_t = -\\left(\\frac{u^2}{2} \\right)_x - u_{xxx},\\\\\n     &{ }u(x,0) = u_0(x).\n\\end{align*}\nWe will use initial data that is zero at the endpoints. This will allow us to use a pseudospectral method for periodic initial data to find a numerical approximation for the solution $u(x,t)$. \n\nIf we use $N$ subintervals in space, we then obtain the spatial step $h = 2\\pi/N$ and the grid points $\\{x_j\\}_{j=1} = \\{-\\pi,-\\pi + h,\\ldots,\\pi-h\\}$.  \nLet $\\mathcal{F}(u)(t) = \\hat{u}(t)$ denote the Fourier transform of $u(x,t)$ (in space), so that \n\\[\n\\mathcal{F}(u) = \\hat{u}(k,t), \\quad k=-N/2+1, \\ldots, N/2.\n\\]\nSimilarly we let $\\mathcal{F}^{-1}$ represent the discrete inverse Fourier transform.\nRecall that $k$ represents the wave numbers in Fourier space; our code defines it by \n\\begin{lstlisting}\n# Dependencies for this lab's code:\nfrom __future__ import division\nfrom math import sqrt, pi\nimport numpy as np\t\t\t\t\t\nfrom scipy.fftpack import fft, ifft\t\t\nfrom mpl_toolkits.mplot3d.axes3d import Axes3D\nimport matplotlib.pyplot as plt\nfrom matplotlib import cm\n\n# Array of wave numbers.  This array is reordered in Python to \n# accomodate the ordering inside the fft function in scipy.\nk = np.concatenate(( np.arange(0,N/2) ,\n\t\t\t\t\t np.array([0])\t,\n\t\t\t\t\t np.arange(-N/2+1,0,1)\t)).reshape(N,)\n\\end{lstlisting}\n\n\nWe now apply the Fourier transform to the KdV equation. In Fourier space, we obtain \n\\begin{align*}\n\t\\mathcal{F}(u)_t &= -\\frac{ik}{2}\\mathcal{F}(u^2)- (ik)^3\\mathcal{F}(u).\n\\end{align*}\nLet $U(t)$ be the vector valued function given by $U(t) = (u(x_j,t))_{j=1}^N$.\nLet $\\mathcal{F}(U)(t)$ denote the discrete Fourier transform of $u(x,t)$ (in space), so that \n\\[\n\\mathcal{F}(U)(t) = (\\mathcal{F}(u)(k,t))_{k=-N/2+1}^{N/2}.\n\\]\nSimilarly we let $\\mathcal{F}^{-1}$ represent the discrete inverse Fourier transform.\nUsing the pseudospectral approximation in space leads to the system of ODEs\n\\begin{align}\n\t\\mathcal{F}(U)_t =  -\\frac{i}{2} \\vec{k}\\mathcal{F}\\left( \\mathcal{F}^{-1}(\\mathcal{F}(U))^2\\right) + i\\vec{k}^3\\mathcal{F}(U)\n\\end{align}\nwhere $\\vec{k}$ is a vector, and multiplication is done element-wise. In terms of $Y = \\mathcal{F}(U)$, this simplifies to \n\\begin{align}\n\tY_t =  -\\frac{i}{2} \\vec{k}\\mathcal{F}\\left( \\mathcal{F}^{-1}(Y)^2\\right) + i\\vec{k}^3Y\n\t\\label{lab:solitons:pseudospectral}\n\\end{align}\nand is implemented below.\n\\begin{lstlisting}\n# Defines the left hand side of the ODE y' = G(t,y)\n# defined above.\nik3 = 1j*k**3.\ndef G_unscaled(t,y):\n\tout = -.5*1j*k*fft(ifft(y,axis=0)**2.,axis=0)  + ik3*y        \n\treturn out\n\\end{lstlisting}\n\nEquation \\eqref{lab:solitons:pseudospectral} is solved below, using a soliton as initial data for the KdV equation. \nNote that the Fourier transform must be applied to the soliton before solving, and that the final numerical solution must be transformed back from Fourier space before plotting. \n\\begin{lstlisting}\nN = 256\nx = (2.*np.pi/N)*np.arange(-N/2,N/2).reshape(N,1)   # Space discretization\ns, shift = 25.**2., 2.  \t\t\t\t\t\t\t# Initial data is a soliton\ny0 = (3.*s*np.cosh(.5*(sqrt(s)*(x+shift)))**(-2.)).reshape(N,) \n\n# Solves the ODE.\nmax_t = \ndt = # constant*N**(-2.)\nmax_tsteps = int(round(max_t/dt))\ny0 = fft(y0,axis=0)\nT,Y = RK4(G_unscaled, y0, t0=0, t1=max_t, n=max_tsteps)\n\n# Using the variable stride, we step through the data, \n# applying the inverse fourier transform to obtain u.\n# These values will be plotted.\nstride = int(np.floor((max_t/25.)/dt))\nuvalues, tvalues = np.real(ifft(y0,axis=0)).reshape(N,1), np.array(0.).reshape(1,1)\nfor n in range(1,max_tsteps+1):\n\tif np.mod(n,stride) == 0:\n\t\tt = n*dt\n\t\tu = np.real( ifft(Y[n], axis=0) ).reshape(N,1)\n\t\tuvalues = np.concatenate((uvalues,np.nan_to_num(u)),axis=1)\n\t\ttvalues = np.concatenate((tvalues,np.array(t).reshape(1,1)),axis=1)\n\nfig = plt.figure()\nax = fig.gca(projection='3d')\nax.view_init(elev=45., azim=150)\ntv, xv = np.meshgrid(tvalues,x,indexing='ij')\nsurf = ax.plot_surface(tv,xv, uvalues.T, rstride=1, cstride=1, cmap=cm.coolwarm,\n\t\t\t\t\t\tlinewidth=0, antialiased=False)\ntvalues = tvalues[0]; ax.set_xlim(tvalues[0], tvalues[-1])\nax.set_ylim(-pi, pi); ax.invert_yaxis()\nax.set_zlim(0., 4000.)\nax.set_xlabel('T'); ax.set_ylabel('X'); ax.set_zlabel('Z')\nplt.show()\n\\end{lstlisting}\n\nThe method we have used requires the use of an algorithm for (ODE) initial value problems, such as the RK4 algorithm. The RK4 method is implemented below.\n\\begin{lstlisting}\ndef initialize_all(y0, t0, t1, n):\n\t\"\"\" An initialization routine for the different ODE solving\n\tmethods in the lab. This initializes Y, T, and h. \"\"\"\n\t\n\tif isinstance(y0, np.ndarray):\n\t\tY = np.empty((n, y0.size),dtype=complex).squeeze()\n\telse:\n\t\tY = np.empty(n,dtype=complex)\n\tY[0] = y0\n\tT = np.linspace(t0, t1, n)\n\th = float(t1 - t0) / (n - 1)\n\treturn Y, T, h\n\n\ndef RK4(f, y0, t0, t1, n):\n\t\"\"\" Use the RK4 method to compute an approximate solution\n\tto the ODE y' = f(t, y) at n equispaced parameter values from t0 to t\n\twith initial conditions y(t0) = y0.\n\t\n\t'y0' is assumed to be either a constant or a one-dimensional numpy array.\n\t't0' and 't1' are assumed to be constants.\n\t'f' is assumed to accept two arguments.\n\tThe first is a constant giving the current value of t.\n\tThe second is a one-dimensional numpy array of the same size as y.\n\t\n\tThis function returns an array Y of shape (n,) if\n\ty is a constant or an array of size 1.\n\tIt returns an array of shape (n, y.size) otherwise.\n\tIn either case, Y[i] is the approximate value of y at\n\tthe i'th value of np.linspace(t0, t, n).\n\t\"\"\"\n\tY, T, h = initialize_all(y0, t0, t1, n)\n\tfor i in xrange(1, n):\n\t\tK1 = f(T[i-1], Y[i-1])\n\t\ttplus = (T[i] + T[i-1]) * .5\n\t\tK2 = f(tplus, Y[i-1] + .5 * h * K1)\n\t\tK3 = f(tplus, Y[i-1] + .5 * h * K2)\n\t\tK4 = f(T[i], Y[i-1] + h * K3)\n\t\tY[i] = Y[i-1] + (h / 6.) * (K1 + 2 * K2 + 2 * K3 + K4)\n\treturn T, Y\n\\end{lstlisting}\n\n% \n% \\begin{lstlisting}\n% \n% \\end{lstlisting}\n% \\begin{lstlisting}\n% \n% \\end{lstlisting}\n% \\begin{lstlisting}\n% \n% \\end{lstlisting}\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{soliton.png}\n\\caption{The solution to Problem \\ref{problem:solitons:single}.}\n\\label{fig:solitons:single}\n\\end{figure}\n\n\n\\begin{problem}\nRun the code above to numerically solve the KdV equation on $[-\\pi,\\pi]$ with initial conditions \n\\[\nu(x,t=0) = 3s\\sech^2\\left(\\frac{\\sqrt{s}}{2}(x+a)\\right),\n\\]\nwhere $s = 25^2,$ $a = 2$. Solve on the time domain $[0,.0075]$. Define the stepsize variable {\\tt dt} in the code above so that the method is numerically stable.  How small must {\\tt dt} be? \n\nThe solution is shown in Figure \\ref{fig:solitons:single}.\n\\label{problem:solitons:single}\n\\end{problem}\n\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{interacting_solitons.png}\n\\caption{The solution to Problem \\ref{problem:solitons:interacting}.}\n\\label{fig:solitons:interacting}\n\\end{figure}\n\n\n\\begin{problem}\nNumerically solve the KdV equation on $[-\\pi,\\pi]$. This time we define the initial condition \nto be the superposition of two solitons,\n\\[\nu(x,t=0) = 3s_1\\sech^2\\left(\\frac{\\sqrt{s_1}}{2}(x+a_1)\\right) + 3s_2\\sech^2\\left(\\frac{\\sqrt{s_2}}{2}(x+a_2)\\right),\n\\]\nwhere $s_1 = 25^2,$ $a_1 = 2$, and $s_2 = 16^2,$ $a_1 = 1$.\\footnote{This problem is solved in \\textit{Spectral Methods in MATLAB}, by Trefethen.} Solve on the time domain $[0,.0075]$.  How small must {\\tt dt} be so that the method is numerically stable?  The solution is shown in Figure \\ref{fig:solitons:interacting}.\n\\label{problem:solitons:interacting}\n\\end{problem}\n\n\n\n\n\n\n\n\\begin{problem}\n\tConsider again equation \\eqref{lab:solitons:pseudospectral}. The linear term in this equation is \n\t$i\\vec{k}^3Y$. This term contributes much of the exponential growth in the ODE, and responsible for \n\thow short the time step must be to ensure numerical stability. Make the substitution $Z = e^{-ik^3t}Y$ and find a similar ODE for $Z$. This essentially allows the exponential growth to be scaled out (it's solved for analytically). Use the resulting equation to solve the previous problem. How short can the time step be made? \n\\end{problem}\n\n\n\n\n\n\n\n\n\n\n\n% \n% The discrete Fourier transform (DFT) of $f$, denoted by $\\hat{f}$ or $\\mathcal{F}(f)$, is given by\n% \\[\n% \\hat{f}(k) = h \\sum_{j=1}^N e^{-ikx_j}f(x_j) \\quad \\text{ where } k = -N/2+1, \\ldots,0,1,\\ldots, N/2.\n% \\]\n% The inverse DFT is then given by\n% \\begin{align}\n% \\begin{split}\n% f(x_j) &= \\frac{1}{2\\pi}\\sum_{k=-N/2}^{N/2}\\frac{e^{ikx_j}}{c_k}\\hat{f}(k), \\quad j = 1,\\ldots, N,\n% \\end{split}\\label{inverse_dft}\n% \\end{align}\n% where \n% \\begin{align}\n% \tc_k = \\begin{cases} 2 & \\text{if }k = -N/2 \\text{ or }k = N/2, \\\\ 1 &  \\text{otherwise.}\n% \\end{cases}\n% \\end{align}\n% The inverse DFT can then be used to define a natural interpolant (sometimes called a band-limited interpolant) by evaluating (\\ref{inverse_dft}) at any $x$ rather than $x_j$:\n% \\begin{align}\n% p(x) = \\frac{1}{2\\pi}\\sum_{k=-N/2}^{N/2} e^{ikx}\\hat{f}(k). \\label{interpolant}\n% \\end{align}\n% The interpolant for $f'$ is then given by \n% \\begin{align}\n% p'(x) = ik \\frac{1}{2\\pi}\\sum_{k=-N/2+1}^{N/2-1} e^{ikx}\\hat{f}(k). \\label{spectral2:deriv}\n% \\end{align}\n\n\n% Consider the function $u(x) = \\sin^2 (x) \\cos(x) +e^{2\\sin(x+1)}$. \n% Using \\eqref{spectral2:deriv}, the derivative $u'$ may be approximated with the following code.  \\footnote{See \\textit{Spectral Methods in MATLAB} by Lloyd N. Trefethen.  Another good reference is \\textit{Chebyshev and Fourier Spectral Methods} by John P. Boyd.}\n% We note that although we only approximate $u'$ at the Fourier grid points, \\eqref{spectral2:deriv} provides an analytic approximation of $u'$ in the form of a trigonometric polynomial.\n\n% \\begin{lstlisting}\n% import numpy as np\n% from scipy.fftpack import fft, ifft\n% import matplotlib.pyplot as plt\n% \n% N=24\n% x1 = (2.*np.pi/N)*np.arange(1,N+1)\n% f = np.sin(x1)**2.*np.cos(x1) + np.exp(2.*np.sin(x1+1))\n% \n% \n% k = np.concatenate(( np.arange(0,N/2) ,\n% \t\t\t\t\t np.array([0])\t, # Because hat{f}'(k) at k = N/2 is zero.\n% \t\t\t\t\t np.arange(-N/2+1,0,1)\t))\n% \n% # Approximates the derivative using the pseudospectral method\n% f_hat = fft(f)\n% fp_hat = ((1j*k)*f_hat)\n% fp = np.real(ifft(fp_hat))\n% \n% # Calculates the derivative analytically\n% x2 = np.linspace(0,2*np.pi,200)\n% derivative = (2.*np.sin(x2)*np.cos(x2)**2. - \n% \t\t\t\tnp.sin(x2)**3. + \n% \t\t\t\t2*np.cos(x2+1)*np.exp(2*np.sin(x2+1))\n% \t\t\t\t)\n% \n% plt.plot(x2,derivative,'-k',linewidth=2.)\n% plt.plot(x1,fp,'*b')\n% plt.savefig('spectral2_derivative.pdf')\n% plt.show()\n% \n% \\end{lstlisting}\n\n\n\n\n% \\begin{figure}\n% \\centering\n% \\includegraphics[width=\\textwidth]{spectral2_derivative.pdf}\n% \\caption{The derivative of $u(x) = \\sin^2 (x) \\cos(x) +e^{2\\sin(x+1)}$.}\n% \\label{fig:spectral:spectral2_derivative}\n% \\end{figure}\n% \n% \\begin{problem}\n% Consider again the function $u(x) = \\sin^2 (x) \\cos(x) +e^{2\\sin(x+1)}$.\n% Create a function that approximates $\\frac{1}{2}u''-u'$ on the Fourier grid points for a given $N$.\t\n% \\end{problem}\n\n% \\begin{lstlisting}\n% import numpy as np\n% import matplotlib.pyplot as plt\n% \n% # Solve the ODE $u_{xx} = e^u,$ with boundary conditions\n% #  $u(0) = u(2\\pi) = 0$\n% \n% \n% \\end{lstlisting}\n\n\n\n\n\n% \\section*{The advection equation}\n% Recall that the advection equation is given by\n% \\begin{align}\n% &{ }u_t + cu_x = 0\n% \\end{align}\n% where $c$ is the speed of the wave (the wave travels to the right for $c > 0$).\n% We will consider the solution of the advection equation on the circle; this essentially amounts to solving the advection equation on $[0,2\\pi]$ and assuming periodic boundary conditions. \n\n% A common method for solving time-dependent PDEs is called the \\textit{method of lines}. To apply the method of lines to our problem, we use our Fourier grid points in $[0,\\pi]$: given an even $N$, let $h = 2\\pi/N$, so that $\\{x_1,\\ldots,x_N\\} = \\{h,2h,\\ldots,2\\pi-h,2\\pi\\}$.  By using these grid points we obtain the collection of equations\n% \\begin{align}\n% &{ }u_t(x_j,t) + cu_x(x_j,t) = 0, \\quad t >0, \\quad j = 1, \\ldots N. \\label{spectral2:method_oflines}\n% \\end{align}\n\n\n\n\n\n\n\n% traveling wave solutions of a partial differential equation are solutions of the form $u(x,t) = u(x-st),$ where $s$ is the speed of the traveling wave.\n% Thus a traveling wave solution is a solution that is a function of one variable, $\\xi= x-st$.\n% This new frame of reference corresponds to an observer moving along with the wave, so that the wave appears stationary as the observer studies it.\n\n% \\subsection*{Burgers' equation}\n% We will examine the process of studying traveling wave solutions using Burgers' equation, a nonlinear PDE from gas dynamics.\n% It is given by\n% \\begin{align}\n% \tu_t + \\left( \\frac{u^2}{2} \\right)_x = \\nu u_{xx}, \\label{eqn:Burgers_pde}\n% \\end{align}\n% where $u$ and $\\nu$ represent the velocity and viscosity of the gas, respectively.\n% It models both the process of transport with the nonlinear advection term $(u^2/2)_x = u u_x$, as well as diffusion due to the viscosity of the gas ($\\nu u_{xx}$).\n% \n% Let us look for a traveling wave solution $u(x,t) = \\hat{u}(x-st)$ for Burgers equation.\n% We transform \\eqref{eqn:Burgers_pde} into the moving frame $(x,t) \\to (\\bar{x},\\bar{t}) = (x-st, t)$. In this frame \\eqref{eqn:Burgers_pde} becomes\n% \\begin{align}\n% \tu_{\\bar{t}} - s u_{\\bar{x}}+ \\left(\\frac{u^2}{2} \\right)_{\\bar{x}} = \\nu u_{\\bar{x}\\bar{x}}\n% \t\\label{eqn:Burgers_pde_moving_frame}\n% \\end{align}\n% % The coordinate system $(\\bar{x},\\bar{t})$ is called the moving frame because the traveling wave is stationary in this coordinate system.\n% This new frame of reference corresponds to an observer moving along with the wave, so that the wave appears stationary as the observer studies it.\n% Thus, $\\hat{u}_{\\bar{t}} = 0$, so that the wave profile $\\hat{u}$ satisfies the ordinary differential equation\n% \\begin{align}\n% \t -s u_{\\bar{x}}+ \\left(\\frac{u^2}{2} \\right)_{\\bar{x}} = \\nu u_{\\bar{x}\\bar{x}}.\n% \t\\label{eqn:Burgers_ode}\n% \\end{align}\n% \n% From here on we will drop the bar notation for simplicity.\n% We seek a traveling wave solution with asymptotically constant boundary conditions; that is,  $\\lim_{x \\to \\pm \\infty}\\hat{u}(x) = u_{\\pm}$\n% \n% both exist, and  $\\lim_{x \\to \\pm \\infty} \\hat{u}'(x) = 0$.\n% We will suppose that $u_- > u_+ > 0$.\n% \n% % A traveling wave solution $u(\\xi)$ of Burgers' equation will satisfy the ordinary differential equation\n% % \\[ -s u' + u u' = \\nu u''.\\]\n% \n% Note that to this point we still don't know the speed of the traveling wave.\n% Integrating both sides of this differential equation, and then taking the limit as $x \\to +\\infty$, we obtain\n% \\begin{align*}\n% -s\\int_{-\\infty}^x u' + \\int_{-\\infty}^x \\left(\\frac{u^2}{2}\\right)' &= \\nu \\int_{-\\infty}^x u'',\\\\\n% -s(u(x) - u_-) + \\frac{u^2(x)}{2} - \\frac{u_-^2}{2} &= \\nu (u'(x) - u'(-\\infty)), \\\\\n% -s(u_+ - u_-) + \\frac{u_+^2}{2} - \\frac{u_-^2}{2} &= 0.\n% \\end{align*}\n% Thus given boundary conditions $u_{\\pm}$ at $\\pm \\infty$, the speed of the traveling wave must be $s = \\frac{u_- + u_+}{2}$.\n% \n% % Usually at this point, the traveling wave must be numerically solved using the profile ODE (\\eqref{eqn:Burgers_ode} for Burgers equation).\n% However, the profile ODE for Burgers is simple enough that it is possible to obtain an analytic solution.\n% The traveling wave is  given by\n% % If we continue by solving the first order equation\n% % \\[-\\frac{u_- + u_+}{2}(u(x) - u_-) + \\frac{u^2(x)}{2} - \\frac{u_-^2}{2} = \\nu u'(x)\\]\n% % we obtain a one-parameter family of solutions\n% \\[\\hat{u}(x) = s - a \\tanh \\left(\\frac{ax }{2\\nu} + \\delta\\right)\\]\n% where $a = (u_- - u_+)/2$ and $\\delta$ is fixed real number.\n% We get a family of solutions because any translation of a traveling wave solution is also a traveling wave solution.\n% \n% \\subsection*{Stability of traveling waves}\n% Suppose that an evolutionary PDE\n% \\begin{align}\n% u_t = G(u,u_x, u_{xx}, \\ldots).\n% \\label{eqn:evol_pde_repeat}\n% \\end{align}\n% has a traveling wave solution $u(x,t) = \\hat{u}(x-st)$.\n% An interesting question to consider is whether the mathematical solution, $\\hat{u}$, has a physical analogue.\n% In other words, does the traveling wave show up in real life?\n% This question is the start of the mathematical study of stability of traveling waves.\n% \n% We begin by translating \\eqref{eqn:evol_pde_repeat} into the moving frame $(x,t) \\to (\\bar{x},\\bar{t}) = (x-st, t)$.\n% In this frame the PDE becomes\n% \\begin{align*}\n% u_t - su_x = G(u,u_x, u_{xx}, \\ldots).\n% \\end{align*}\n% In these coordinates the traveling wave is stationary.\n% Thus, the solution of\n% \\begin{align*}\n% \\begin{split}\n% u_t - su_x &= G(u,u_x, u_{xx}, \\ldots), \\\\\n% u(x,t = 0) &= \\hat{u}(x),\n% \\end{split}\n% \\end{align*}\n% is given by $u(x,t) = \\hat{u}(x)$.\n% We say that the traveling wave $\\hat{u}$ is asymptotically orbitally stable if whenever $v(x)$ is a small perturbation of $\\hat{u}(x)$, the general solution of\n% \\begin{align*}\n% \\begin{split}\n% u_t - su_x &= G(u,u_x, u_{xx}, \\ldots), \\\\\n% u(x,t = 0) &= v(x),\n% \\end{split}\n% \\end{align*}\n% converges to some translation of $\\hat{u}$ as $t \\to \\infty$.\n% Using this definition to prove stability of a traveling wave is a nontrivial task.\n% \n% \\subsection*{Visualizing stability of the traveling wave solution of Burgers' equation}\n% The traveling wave solution of Burgers' equation is a stable wave.\n% To view this numerically, we discretize the PDE\n% \\[u_t -su_x + uu_x = u_{xx}\\]\n% using the second order centered approximations\n% % \\begin{align*}\n% % &{ } u_t(x_j,t_{n+1/2}) \\approx \\frac{u_j^{n+1}-u_j^n}{\\triangle t}, \\quad\n% % u_x(x_j,t_{n+1/2}) \\approx \\frac{1}{2} \\left( \\frac{u_{j+1}^{n+1}-u_{j-1}^{n+1}}{2 \\triangle x} +  \\frac{u_{j+1}^{n}-u_{j-1}^{n}}{2 \\triangle x}\\right) ,\\\\\n% % &{ } u_{xx}(x_j,t_{n+1/2}) \\approx \\frac{1}{2} \\left( \\frac{u_{j+1}^{n+1}- u_{j}^{n+1}+u_{j-1}^{n+1}}{(\\triangle x)^2} + \\frac{u_{j+1}^{n}- u_{j}^{n}+u_{j}^{n+1}}{(\\triangle x)^2}\\right).\n% % \\end{align*}\n% \\begin{align*}\n% &{ } D_t U_j^{n+1/2} = \\frac{U_j^{n+1}-U_j^n}{\\triangle t}, \\quad\n% D_{xx}U_j^{n+1/2} = \\frac{1}{2} \\left( \\frac{U_{j+1}^{n+1}-U_{j-1}^{n+1}}{2 \\triangle x} +  \\frac{U_{j+1}^{n}-U_{j-1}^{n}}{2 \\triangle x}\\right),\\\\\n% &{ } D_{xx}U_j^{n+1/2} = \\frac{1}{2} \\left( \\frac{U_{j+1}^{n+1}- U_{j}^{n+1}+U_{j-1}^{n+1}}{(\\triangle x)^2} + \\frac{U_{j+1}^{n}- U_{j}^{n}+U_{j-1}^{n}}{(\\triangle x)^2}\\right)\n% \\end{align*}\n% \n% Substituting these expressions into the PDE we obtain a second-order, implicit Crank-Nicolson method\n% % \\begin{align*}\n% % &{ }u_j^{n+1} + k_1 (u_j^{n+1}-s)(u_{j+1}^{n+1} - u_{j-1}^{n+1})\n% % - k_2(u_{j+1}^{n+1} - 2u_j^{n+1}+ u_{j-1}^{n+1}) = \\\\\n% % &{ } u_j^n - k_1(u_j^n-s) (u_{j+1}^n - u_{j-1}^n)\n% % + k_2 (u_{j+1}^n -2u_j^n + u_{j-1}^n),\n% % \\end{align*}\n% \\begin{align*}\n% U_j^{n+1} - U_j^n &= K_1 \\big[(s - U_j^{n+1})(U_{j+1}^{n+1} - U_{j-1}^{n+1})\n% + (s - U_j^n) (U_{j+1}^n - U_{j-1}^n) \\big] \\\\\n% &{ }  \\quad\n% + K_2 \\big[(U_{j+1}^{n+1} - 2U_j^{n+1}+ U_{j-1}^{n+1}) + (U_{j+1}^n -2U_j^n + U_{j-1}^n) \\big],\\\\\n% &{ }  \\quad\n% \\end{align*}\n% where $K_1 = \\frac{ \\triangle t }{4 \\triangle x}$ and $K_2 = \\frac{ \\triangle t}{2(\\triangle x)^2}$.\n% \n% \\begin{problem}\n% Numerically solve the initial value problem\n% \\begin{align*}\n% \t&{ } u_t -su_x + uu_x = u_{xx}, \\quad x \\in (-\\infty,\\infty),\\\\\n% \t&{ } u(x,0) = v(x),\n% \\end{align*}\n% for $t \\in [0,1]$.\n% Let the perturbation $v(x)$ be given by\n% \\[v(x) = 3.5(\\sin{(3x)} + 1)\\frac{1}{\\sqrt{2\\pi}} \\exp{(-x^2/2)}\\]\n% And let the initial condition be $u(x, 0) = \\hat{u}(x) + v(x)$\n% Approximate the $x$ domain,$(-\\infty, \\infty)$, numerically by the finite interval $[-20,20]$, and fix $u(-20) = u_-$, $u(20) = u_+$. Let $u_- = 5$, $u_+ = 1$.\n% Use 150 intervals in space and 350 steps in time.\n% Animate your results.\n% You should see the solution converge to a translate of the traveling wave $\\hat{u}$.\n% \n% Hint: This difference scheme is no longer a linear equation.\n% We have a nonlinear equation in $U^{n+1}$.\n% We can still solve this function using Newton's method or some other similar solver.\n% In this case, use \\li{scipy.optimize.fsolve}.\n% \\end{problem}\n\n\n\n% \\section*{Traveling wave solutions of an evolution equation}\n% Consider the transport equation together with initial conditions on the real line:\n% \\begin{align*}\n% \t&{ }u_t + su_x  = 0, \\quad -\\infty < x < \\infty, \\\\\n% \t&{ }u(x,0) = f(x).\n% \\end{align*}\n% This initial value problem has as its general solution the function $u(x,t) = f(x -st)$. Thus the function $f$ represents a 'signal' that is transported to the right with speed $s$.\n% \n% In a similar fashion we may consider a general evolutionary PDE\n% \\begin{align}\n% u_t = G(u,u_x, u_{xx}, \\ldots),\n% \\label{lab:solitons:evol_pde}\n% \\end{align}\n% and ask whether Equation \\eqref{lab:solitons:evol_pde} has traveling wave solutions. \n% In other words, is there a signal or wave profile $f(x)$, so that $u(x,t) = f(x-st)$ is a solution of \\eqref{evol_pde} that carries the signal at a constant speed $s$?\n% \n% These traveling waves are often significant physically.  In a previous lab we looked at traveling \n% wave solutions of Burgers equation, an canonical equation in gas dynamics.  \n% \n% \n% For example, in a PDE modelling insect population dynamics a traveling wave could represent a swarm of locusts; in a PDE describing a combustion process a traveling wave could represent an explosion or detonation.", "meta": {"hexsha": "0e2d4794d29c65e209baaf4c524df259d90fe7af", "size": 22851, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/Solitons/Solitons.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Labs/Solitons/Solitons.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/Solitons/Solitons.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 44.0289017341, "max_line_length": 342, "alphanum_fraction": 0.6659227167, "num_tokens": 7959, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.7218888598420474}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amsthm}\n\\usepackage{amsfonts}\n\\usepackage{arcs}\n\\usepackage{wasysym}\n\\usepackage{tikz}\n\\usepackage{maria}\n\n\\newtheorem{lemma}{Lemma}\n\\theoremstyle{definition}\n\\newtheorem*{example}{Example}\n\\newtheorem*{exercise}{Exercise}\n\n\\newtheorem*{definition}{Definition}\n\\topmargin -0.5in\n\\oddsidemargin 0in\n\\textwidth 6in\n\\textheight 9.25in\n\n\n\\title{Generating Functions}\n\n\\author{Maria Monks -- Red Group}\n\\date{June 19, 2012}\n\n\\pagestyle{empty}\n\n\\begin{document}\n\n\\maketitle{}\n\n\\begin{quote}\n  A generating function is a clothesline on which we hang a sequence of numbers up for display.\n\\end{quote}\n\\hfill --Herbert Wilf, \\textit{Generatingfunctionology}\n\n\\section*{Generating function basics}\n\n\\indent  Generating functions are a useful tool for solving combinatorial problems.\n\nA classic example of a generating function identity is the geometric series formula $$\\frac{1}{1-x}=1+x+x^2+x^3+\\cdots.$$  (The term \\textit{function} is misleading - here $x$ is just a formal symbol, and the coefficients of the series are the important part!)\n\n\\begin{definition}\nThe \\textit{(ordinary) generating function} of the sequence $c_0,c_1,c_2,\\ldots$ with variable $x$ is the expression $$c_0+c_1x+c_2x^2+\\cdots.$$  We abbreviate this series as $$\\sum_{i=0}^\\infty c_ix^i.$$\n\\end{definition}\n\nGenerating functions can be added and multiplied together.  They can also be differentiated, and sometimes composed!  \n\nThe following are \\textit{definitions} of addition, multiplication, differentiation, and composition of generating functions (we're starting from the beginning here - no calculus allowed.)\n\n\\begin{itemize}\n \\item \\textbf{Addition:} $\\sum_{i=0}^\\infty a_i x^i+\\sum_{i=0}^\\infty b_i x^i=\\sum_{i=0}^\\infty (a_i+b_i) x^i$\n \\item \\textbf{Multiplication:} $\\left(\\sum_{i=0}^\\infty a_i x^i\\right)\\cdot \\left(\\sum_{i=0}^\\infty a_i x^i\\right)=\\sum_{n=0}^\\infty \\left(\\sum_{i=0}^n a_ib_{n-i}\\right)x^n$\n \\item \\textbf{Differentiation:} $\\frac{d}{dx} \\left(\\sum_{n=0}^\\infty a_n x^n\\right)=\\sum_{i=1}^\\infty na_nx^{n-1}$\n \\item \\textbf{Composition:} If $F(x)=f_0+f_1x+f_2x^2+\\cdots$ and $G(x)=g_1x+g_2x^2+\\cdots$, then $$F\\circ G(x)=\\sum_{n\\ge 0} f_nG(x)^n=\\sum_{N=0}^\\infty h_N x^N$$ where $$h_N=\\sum_{s_1+\\cdots+s_k=N} f_kg_{s_1}g_{s_2}\\cdots g_{s_n}.$$\n\\end{itemize}\n\n\\begin{exercise}\n  Is there a generating function that behaves like an additive identity?  A multiplicative identity?  Can subtraction and division of generating functions be defined?  Why did we only define composition above in the case that $G$ has no constant term?\n\\end{exercise}\n\n\\begin{exercise}\n  Use the definitions above to prove the generating function identity $$\\frac{1}{1-x}=1+x+x^2+x^3+\\cdots.$$  Notice that $1-x=1-x+0\\cdot x^2+0\\cdot x^3+\\cdots$ is a generating function as well.\n\\end{exercise}\n\n\\section*{Tricks for manipulating generating functions}\n\nLet $F(x)=\\sum_{n=0}^\\infty a_n x^n$ and $G(x)=\\sum_{n=0}^\\infty b_n x^n$ be generating functions over $x$.  Try your hand at proving the following identities, using only the definitions above.\n\n\\begin{itemize}\n  \\item $x F(x)=\\displaystyle\\sum_{n=1}^\\infty a_{n-1}x^n$\n  \\item $\\displaystyle{\\frac{F(x)-a_0}{x} = \\sum_{n=0}^\\infty a_{n+1}x^n}$\n  \\item $\\displaystyle{\\frac{d}{dx} (F(x)+G(x))=\\frac{d}{dx}F(x)+\\frac{d}{dx}G(x)}$\n  \\item $\\displaystyle{\\frac{d}{dx} (F(x)G(x))=G(x)\\cdot\\frac{d}{dx}F(x)+F(x)\\cdot \\frac{d}{dx}G(x)}$\n  \\item If $b_0\\neq 0$, $G(x)$ has a multiplicative inverse: $$G(x)^{-1}=b_0^{-1}-b_0^{-1}b_1x+ (b_0^{-3}b_1^2-b_0^{-2}b_2)x^2+\\cdots.$$\n  \\item If $b_0\\neq 0$, $\\displaystyle{\\frac{d}{dx} \\left(\\frac{F(x)}{G(x)}\\right)=\\frac{G(x)\\frac{d}{dx}F(x)-F(x)\\frac{d}{dx}G(x)}{G(x)^2}}$.\n\\end{itemize}\n\n\\begin{exercise}  Show that\n $$\\frac{1}{(1-x)^2}=1+2x+3x^2+4x^3+5x^4+\\cdots.$$ \n\\end{exercise}\n\n\\section*{Using generating functions to solve recurrences}\n\nSuppose we wish to find an explicit formula for the $n$th Fibonnacci number $F_n$, where $F_0=0$, $F_1=1$, and $F_{n}=F_{n-1}+F_{n-2}$ for all $n\\ge 2$.  Consider the generating function $$G(x)=\\sum_{n=0}^\\infty F_n x^n.$$  Let's manipulate this to take advantage of the recursion:\n$$ G(x)-xG(x)-x^2G(x) = F_0+F_1x-F_0x+\\sum_{n=2}^\\infty (F_n-F_{n-1}-F_{n-2}) x^n =x.$$\nThus $G(x)=x/(1-x-x^2)$.  Using partial fractions and expanding each term as a geometric series, we find that $$G(x)=\\sum_{n=0}^\\infty \\frac{1}{\\sqrt{5}}\\left(\\left(\\frac{1+\\sqrt{5}}{2}\\right)^n-\\left(\\frac{1-\\sqrt{5}}{2}\\right)^n\\right)x^n,$$ and so $F_n=\\frac{1}{\\sqrt{5}}\\left(\\left(\\frac{1+\\sqrt{5}}{2}\\right)^n-\\left(\\frac{1-\\sqrt{5}}{2}\\right)^n\\right)$.\n\n\\begin{exercise}\n  Use generating functions to find an explicit formula for the $n$th term in the sequence $a_n$ where $a_0 = 1$, $a_1 = 5$, $a_{n+2} = 4a_{n+1} -3a_n$.\n\\end{exercise}\n\n\\section*{Exponential generating functions}\n\nWe now have a good handle on ordinary generating functions.  But there are other useful generating functions associated to a given sequence of numbers!\n\n\\begin{definition} The \\textit{exponential generating function} for the sequence $\\{a_i\\}_{i=0}^\\infty$ is the series $\\sum_{n=0}^\\infty \\frac{a_n}{n!}x^n$.  \\end{definition}\n\n\\textbf{When to use them:}  Exponential generating functions are often useful for dealing with sequences that count \\textit{labeled} objects, whereas ordinary generating functions are better for \\textit{unlabeled} objects.  \n\nFor instance, if we let $p(n)$ be the number of ways of sorting $n$ indistinguishable balls into various groups, and let $B(n)$ be the number of ways of sorting $n$ balls labeled $1,2,\\ldots,n$ into various groups, it is easy to work with the ordinary generating function for $p(n)$ and the exponential generating function for $B(n)$, but not the other way around. (See Problems.)\n\n\\textbf{Behaviour:}  The product of exponential generating functions behaves somewhat differently from that of ordinary generating functions:\n$$\\left(\\sum_{n=0}^\\infty \\frac{a_n}{n!}x^n\\right)\\cdot \\left(\\sum_{n=0}^\\infty \\frac{b_n}{n!}x^n\\right)=\\sum_{n=0}^\\infty \\frac{1}{n!}\\left(\\sum_{k=0}^n\\binom{n}{k}a_k b_{n-k}\\right)x^n$$\n\n\\begin{exercise}\nWhat do addition and differentiation do to exponential generating functions?\n\\end{exercise}\n\nWe can define $e^{x}$, $\\sin(x)$, and $\\cos(x)$ to be the exponential generating functions shown below.  \n\\begin{itemize}\n  \\item $e^{x}=\\sum_{n=0}^\\infty \\frac{1}{n!}x^n$\n  \\item $\\sin(x)=\\sum_{n=0}^\\infty (-1)^n\\frac{1}{(2n+1)!}x^{2n+1}$\n  \\item $\\cos(x)=\\sum_{n=0}^\\infty (-1)^n\\frac{1}{(2n)!}x^{2n}$\n\\end{itemize}\n\n\\begin{exercise}\n  Using the definition of $e^x$ as a generating function, show that $e^{x}e^{y}=e^{x+y}$ and that $\\frac{d}{dx}e^{x}=e^x$.\n\\end{exercise}\n\nAnd now for some...\n\n\\section*{Problems!}\n\n\\begin{enumerate}\n\\item Prove the following generating function identities:\n   \\begin{enumerate}\n     \\item $(1+x)^{n}=\\sum_{k=0}^n \\binom{n}{k}x^k$\n     \\item $(1-x)^{-n}=\\sum_{k=0}^\\infty \\binom{-n}{k}(-x)^k=\\sum_{k=0}^\\infty \\binom{n+k-1}{k} x^k$\n     \\item $\\frac{1}{1-y(1+x)}=\\sum_{k,n}\\binom{n}{k}x^ky^n$\n   \\end{enumerate}\n\n\\item (Andy Niedermaier.)  Find a closed form for the generating function for each of the following sequences, and use it to find an explicit formula for $a_n$:\n\\begin{enumerate}\n  \\item $a_0 = 1$, $a_1 = 6$, $a_{n+2} = 4a_{n+1} - 4a_n$\n  \\item $a_0 = 0$, $a_1 = 5$, $a_2 = 47$, $a_{n+3} = 31a_{n+1} + 30a_n$\n  \\item $a_0 = a_1 = 1$, $a_{n+2} = a_{n+1} + 6a_n + n$\n\\end{enumerate}\n\n\\item Simplify $\\sum_{n=0}^\\infty n^2 x^n$.  (There are at least three nice ways of doing this!)\n\n\\item Prove the following combinatorial identities using generating functions:\n\\begin{enumerate}\n   \\item $\\sum_{k=0}^n\\binom{n}{k}^2=\\binom{2n}{n}$\n   \\item $\\sum_{k=0}^n k \\binom{n}{k}=n\\cdot 2^{n-1}$\n   \\item $\\binom{n}{0}+\\binom{n}{2}+\\binom{n}{4}+\\cdots=\\binom{n}{1}+\\binom{n}{3}+\\binom{n}{5}+\\cdots=2^{n-1}$\n\\end{enumerate}\n\n\\item Find an explicit formula for $$\\binom{n}{0}+\\binom{n}{3}+\\binom{n}{6}+\\binom{n}{9}+\\cdots$$ in terms of $n$.\n\n\\item  (360 Problems for Mathematical Contests.) Find a closed form expression for the sum $$S_n=\\binom{n}{1}-3\\binom{n}{3}+5\\binom{n}{5}-7\\binom{n}{7}+\\cdots.$$\n\n\\item In each of the following, find the ordinary generating function for the sequence whose $n$th term is described below.\n   \\begin{enumerate}\n     \\item The number of subsets of $\\{1,2,\\ldots,n\\}$.\n     \\item $p(n)$, the number of \\textit{partitions} of $n$.  That is, the number of ways of writing $n$ as a sum of positive integers where order doesn't matter.\n     \\item The number of partitions of $n$ into distinct parts.\n     \\item The number of partitions of $n$ into odd parts.  How does this relate to the generating function for partitions into distinct parts?\n     \\item The number of \\textit{$k$-compositions} of $n$, that is, ways of writing $n$ as a sum of $k$ \\textit{ordered} nonnegative integers $s_1,\\ldots,s_k$.\n     \\item The number of integer lattice paths from $(0,0)$ to $(n,n)$, going either one unit right or one unit up at each step, such that every point $(x,y)$ on the path satisfies $y\\le x$.\n   \\end{enumerate}\n\n\\item (HMMT 2007.)  Let $S$ denote the set of all triples $(i,j,k)$ of positive integers satisfying $i+j+k=17$.  Compute $$\\sum_{(i,j,k)\\in S} ijk.$$\n\n\\item \\textbf{Signless Stirling Numbers of the First Kind:} Let $c(n,k)$ be the number of permutations of $\\{1,2,\\ldots,n\\}$ which are a product of $k$ cycles.  Prove that $$\\sum_{k}c(n,k)y^k=y(y+1)\\cdots(y+n-1).$$\n\n\\item \\textbf{Stirling Numbers of the Second Kind:} Let $S(n,k)$ be the number of ways of partitioning a set of $n$ labeled elements into $k$ nonempty unordered blocks. Show that $$\\sum_{n} S(n,k)x^n=\\frac{x^k}{(1-x)(1-2x)\\cdots (1-kx)}.$$\n\n\\item \\textbf{Derangements:} Let $D_n$ be the number of \\textit{derangements} of $n$, that is, the number of permutations $\\phi$ of $\\{1,2,\\ldots,n\\}$ such that $\\phi(i)\\neq i$ for any $1\\le i \\le n$.  Find a closed form expression for the exponential generating function of $D_n$.  (Hint: Multiply $D(x)=\\sum_{n\\ge 0} \\frac{D_n}{n!} x^n$ by $e^x$.)\n\n\\end{enumerate}\n\n\\end{document}\n", "meta": {"hexsha": "f97ffe2edb760d692070e1b14df5304ede325397", "size": 10087, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "data_loading/data/olympiads_tex_converted/red-generating-functions.tex", "max_stars_repo_name": "zhukeepa/mathorg", "max_stars_repo_head_hexsha": "975c275e3ba24af2772563e6f89f0469c3ccde3b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-09T10:45:23.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-14T08:23:56.000Z", "max_issues_repo_path": "data_loading/data/olympiads_tex_converted/red-generating-functions.tex", "max_issues_repo_name": "zhukeepa/mathorg", "max_issues_repo_head_hexsha": "975c275e3ba24af2772563e6f89f0469c3ccde3b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2015-08-30T05:09:02.000Z", "max_issues_repo_issues_event_max_datetime": "2015-08-30T05:26:08.000Z", "max_forks_repo_path": "data_loading/data/olympiads_tex_converted/red-generating-functions.tex", "max_forks_repo_name": "zhukeepa/mathorg", "max_forks_repo_head_hexsha": "975c275e3ba24af2772563e6f89f0469c3ccde3b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-10-06T23:10:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-20T04:21:26.000Z", "avg_line_length": 57.3125, "max_line_length": 380, "alphanum_fraction": 0.6852384257, "num_tokens": 3609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7218888546701107}}
{"text": "\\subsection{Sample Variance}\n\n\\begin{frame}{Sample Variance}\n    \\begin{itemize}\n        \\item A basic time series measure\n        \n        \\item Linear complexity\n        \n        \\item Following calculation based on \\cite{chan1983algorithms}\n    \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Sample Variance}{Calculation}\n    \\begin{block}{Given}\n        \\begin{itemize}\n            \\item A domain set $\\mathbb{U}$\n            \n            \\item A distance measure function $d$ with $d: \\mathbb{U} \\times \\mathbb{U} \\to \\mathbb{R}$\n            \n        \\end{itemize}\n    \\end{block}\n    \\begin{block}{Input}\n        \\begin{itemize}\n            \\item A time series $Q = (q_1, q_2, \\dots, q_i, \\dots, q_l)$ with length $l$ over the domain set\n                $\\mathbb{U}$\n        \\end{itemize}\n    \\end{block}\n\\end{frame}\n\n\\begin{frame}{Sample Variance}{Calculation}\n    \\begin{block}{Calculation}\n        \\begin{itemize}\n            \\item $VAR(Q) = \\frac{1}{l}\\sum \\limits_{i=1}^{l} d(q_i, \\bar{q})^2$\n            \n        \\end{itemize}\n    \\end{block}\n    \\begin{block}{Mean of $Q$}\n        \\begin{itemize}\n            \\item $\\bar{q} = \\frac{1}{l} \\sum \\limits_{i=1}^{l} q_i$\n        \\end{itemize}\n    \\end{block}\n\\end{frame}\n", "meta": {"hexsha": "9e364f9b2edeb18f188f07cce7ffe887aa65aaa2", "size": 1223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "presentation/background/sample_variance.tex", "max_stars_repo_name": "GordonLesti/SlidingWindowFilter", "max_stars_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-06-22T09:37:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T11:43:53.000Z", "max_issues_repo_path": "presentation/background/sample_variance.tex", "max_issues_repo_name": "GordonLesti/SlidingWindowFilter", "max_issues_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "presentation/background/sample_variance.tex", "max_forks_repo_name": "GordonLesti/SlidingWindowFilter", "max_forks_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-11T23:15:57.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-11T23:15:57.000Z", "avg_line_length": 28.4418604651, "max_line_length": 108, "alphanum_fraction": 0.5486508585, "num_tokens": 387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7218540380003575}}
{"text": "\\chapter{Notation}\n\\begin{tabular}{@{}lll@{}}\n\\renewcommand{\\baselinestretch}{1.3}\\small\\normalsize\n$a$ & italic Latin letter & scalar\\\\\n$\\theta$ & italic Greek letter & angle\\\\\n\\ve{a} & boldface Greek/Latin letter & column vector\\\\\n\\ve{0} & boldface figure 0 & null vector (of appropriate dimension)\\\\\n\\m{M} & sans serif upper-case letter & matrix\\\\\n\\m{1} & sans serif figure 1 & identity matrix (of appropriate dim.)\\\\\n\\q{q} & sans serif lower-case letter & quaternion\\\\\n$\\dot{c}$ & dot & first derivative with respect to time\\\\\n$\\ddot{c}$ & double dot & second derivative with respect to time\\\\\n$\\m{J}^T$ & superscript $T$ & matrix transpose\\\\\n$\\m{M}^{-1}$ & superscript $-1$ & matrix or quaternion inverse (eq.~\\ref{quatInverse})\\\\\n$\\overline{\\q{q}}$ & bar & quaternion conjugate (eq.~\\ref{quatConjugate})\\\\\n$\\norm{\\ve{a}}$ & norm & vector or quaternion magnitude (eq.~\\ref{quatMagnitude})\\\\\n$\\tilde{\\ve{a}}$ & tilde & corresponding quaternion (eq.~\\ref{vectorToQuat})\\\\\n$\\dual{\\ve{a}}$ & asterisk & dual tensor (eq.~\\ref{dualTensor})\\\\\n$\\ve{a}\\times\\ve{b}$ & cross & vector cross product\\\\\n$\\ve{a}\\cdot\\ve{b}$ & dot & inner product\\\\\n$\\Re(\\q{q})$ & real & real part of a quaternion\\\\\n\\end{tabular}\n\\vspace{10pt}\n\nGiven any vector $\\ve{a} = (a_1, a_2, a_3)^T$, we define its dual\ntensor, written as a $3\\times3$ matrix, to be\n\\begin{equation}\\label{dualTensor}\n\\dual{\\ve{a}} = \\left[\\begin{array}{ccc}\n    0 & -a_3 & a_2 \\\\ a_3 & 0 & -a_1 \\\\ -a_2 & a_1 & 0\n    \\end{array}\\right]\n\\end{equation}\n(see \\cite{RHB:02,BaraffWitkin:97} and also Kalra~\\cite{Kalra:95}, who defines it to be\nthe transpose of the expression above).\nThe dual allows us to rewrite a vector cross product as a matrix multiplication:\n\\begin{equation}\n\\ve{a}\\times\\ve{b} = \\dual{\\ve{a}}\\,\\ve{b}\n\\end{equation}\nNote that $(\\dual{\\ve{a}})^T = -\\dual{\\ve{a}}$.\n\nLet us also recall some basic identities of vector and matrix algebra~\\cite{RHB:02}:\n\\begin{eqnarray*}\n\\ve{a}\\times\\ve{a} & = & \\ve{0}\\quad\\mathrm{(the~null~vector)} \\\\\n\\ve{a}\\times\\ve{b} & = & -\\ve{b}\\times\\ve{a} \\\\\n\\ve{a}\\times(\\ve{b} + \\ve{c}) & = & \\ve{a}\\times\\ve{b} + \\ve{a}\\times\\ve{c} \\\\\n\\ve{a}\\cdot\\ve{b} & = & \\ve{b}\\cdot\\ve{a} \\\\\n\\ve{a}\\cdot\\ve{b} & = & \\ve{a}^T\\,\\ve{b} \\\\\n\\ve{a}\\cdot(\\ve{b} + \\ve{c}) & = & \\ve{a}\\cdot\\ve{b} + \\ve{a}\\cdot\\ve{c} \\\\\n\\ve{a}\\cdot(\\ve{b}\\times\\ve{c}) & = & \\ve{b}\\cdot(\\ve{c}\\times\\ve{a}) \\\\\n    & = & \\ve{c}\\cdot(\\ve{a}\\times\\ve{b}) \\\\\n\\ve{a}\\times(\\ve{b}\\times\\ve{c}) & = &\n    \\ve{b}(\\ve{a}\\cdot\\ve{c}) - \\ve{c}(\\ve{a}\\cdot\\ve{b}) \\\\\n(\\m{A}\\m{B})\\m{C} & = & \\m{A}(\\m{B}\\m{C}) \\\\\n\\m{A}(\\m{B} + \\m{C}) & = & \\m{A}\\m{B} + \\m{A}\\m{C} \\\\\n(\\m{A}\\m{B})^T & = & \\m{B}^T\\m{A}^T \\\\\n\\m{A}\\m{A}^{-1} = \\m{A}^{-1}\\m{A} & = & \\m{1}\\quad\\mathrm{(the~identity~matrix)}\n\\end{eqnarray*}\n", "meta": {"hexsha": "bca48fe1f258d4008802eee6fa48532ad653f9f5", "size": 2746, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/notation.tex", "max_stars_repo_name": "ept/maniation", "max_stars_repo_head_hexsha": "546b78cec5cf3a83986a94086b97f4236b76df2a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-05-09T00:54:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:40:52.000Z", "max_issues_repo_path": "report/notation.tex", "max_issues_repo_name": "ept/maniation", "max_issues_repo_head_hexsha": "546b78cec5cf3a83986a94086b97f4236b76df2a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/notation.tex", "max_forks_repo_name": "ept/maniation", "max_forks_repo_head_hexsha": "546b78cec5cf3a83986a94086b97f4236b76df2a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-04-17T14:39:12.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-08T05:38:45.000Z", "avg_line_length": 48.1754385965, "max_line_length": 88, "alphanum_fraction": 0.5983248361, "num_tokens": 1156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7218540359358395}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage[left=1cm,right=1cm,\n    top=2cm,bottom=2cm,bindingoffset=0cm]{geometry}\n\\usepackage{braket}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{mathrsfs}\n\\usepackage[T2A]{fontenc}\n\\usepackage[utf8x]{inputenc}\n\\usepackage[english]{babel}\n\\usepackage{graphicx}\n\\parindent=0.5cm\n\n\\usepackage{hyperref} \n\\usepackage{indentfirst}\n\n\\numberwithin{equation}{section}\n%\\usepackage{showkeys}\n\n\\begin{document}\n\\section*{MSAI Statistics \\& Probability – Week 5 Seminar \\& HW}\\\\\n\n\\textbf{Problem 1:} Consider an Erd\\H{o}s-R\\'{e}nyi random graph $G(n,p)$ on $n$ vertices (that is, for any two vertices, there is an edge between them with probability $p$ and no edge with probability $1-p$; all edges are independent of each other). Find the expected number of triangles in $G(n,p)$ (triples of vertices all pairwise connected with an edge). Provide an answer for $n=7,~p=\\frac{1}{7}.$\n\\\\\n\n\\textbf{Problem 2:} Let $\\xi\\sim\\mathcal{N}(0,\\sigma^2)$ (a random variable distributed normally with zero mean and dispersion $\\sigma^2$). Find $\\mathbb{E}\\xi^k$ (expectation of $k$-th power of $\\xi$). Provide an answer for $\\sigma^2 = 2,~k=4.$\n\\\\\n\n\\textbf{Problem 3:} Let $\\xi\\sim\\textrm{Pois}(\\lambda)$ (a random variable with Poisson distribution with rate $\\lambda$). For some natural $k\\in\\mathbb{N}$, find $\\mathbb{E}{\\xi\\choose k}$ (expected ${\\xi\\choose k}$ - binomial coefficient). Provide an answer for $\\lambda=3,~k=4.$\n\\\\\n\n\\textbf{Problem 4:} Find $\\mathbb{E}\\xi$ if $\\xi$ have the following distribution function:\n$$F(x)=\n\\begin{cases}\n0, ~~~ x<-2,\\\\\n1/5, ~~~-2\\leq x<1 \\\\\nx^2/4, ~~~1\\leq x<2 \\\\\n1, ~~~ x\\geq 2\n\\end{cases}$$\n\n\\textbf{Problem 5:} (Conditional expectation). You have two fair dice (six-sided cubes, $1,2,...,6$ on the faces, each face equally probable). You throw them and read the sum of their values, $z=x+y$. Find the expected $\\mathbb{E}(x|z).$ \n\nTo do this, consider the following functional \n$$J(\\alpha)=\\sum_{x,z}(x-\\alpha z)^2p(x,z)=\\sum_{x,y}(x-\\alpha (x+y))^2p(x,y)$$\n- it only depends on $\\alpha$. You know all possible $x$ outcomes and all possible $z=x+y$ outcomes and their probabilities! Use any mathematical software to compute the expression of $J(\\alpha)$ as a function of $\\alpha$, and then minimize it with respect to $\\alpha.$\n\n\\end{document}\n\n", "meta": {"hexsha": "1175cfafd168d989f36975f3a203de22d42c112b", "size": 2337, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week05_expectations/Week05_HW_Theory.tex", "max_stars_repo_name": "girafe-ai/msai-statistics", "max_stars_repo_head_hexsha": "c9de8ca20bbb9f266e06598d376be50c35f00756", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-04-07T05:10:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-07T15:58:35.000Z", "max_issues_repo_path": "week05_expectations/Week05_HW_Theory.tex", "max_issues_repo_name": "girafe-ai/msai-statistics", "max_issues_repo_head_hexsha": "c9de8ca20bbb9f266e06598d376be50c35f00756", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-08T17:08:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-08T17:08:53.000Z", "max_forks_repo_path": "week05_expectations/Week05_HW_Theory.tex", "max_forks_repo_name": "girafe-ai/msai-statistics", "max_forks_repo_head_hexsha": "c9de8ca20bbb9f266e06598d376be50c35f00756", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-25T15:23:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T14:28:21.000Z", "avg_line_length": 45.8235294118, "max_line_length": 403, "alphanum_fraction": 0.703465982, "num_tokens": 767, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.8933093975331751, "lm_q1q2_score": 0.7218540357051304}}
{"text": "\\section{Introduction To Supervised Learning}\n\\subsection{Basic Concepts}\nWe use $\\mathcal{X}$ and $\\mathcal{Y}$ to denote the input space and the output space, where typically we have $\\mathcal{X}=\\mathbb{R}^p$, $\\mathcal{Y}=\\mathbb{R}$ or $\\{0,1\\}$. Let $(X,Y)$ be a pair of random variables distributed according to $F_{X,Y}$ which is a joint probability distribution on $\\mathcal{X}\\times\\mathcal{Y}$.   \n\nThis means that: we have two measurable functions\n\\begin{equation}\n\\label{eq:3}\nX: \\Omega\\mapsto \\mathcal X  \n\\end{equation}\nand\n\\begin{equation}\n\\label{eq:4}\nY: \\Omega\\mapsto \\mathcal Y  \n\\end{equation}\nThe distribution of $X$:\n\\begin{equation}\n\\label{eq:1}\nF_X(x)=P(\\omega\\in\\Omega: X(\\omega)\\le x) =\\int_{y\\le x}f_X(y) dy  \n\\end{equation}\nThe joint distribution \n\\begin{equation}\n\\label{eq:2}\nF_{X,Y}(x,y)=P(\\omega\\in\\Omega: (X(\\omega),Y(\\omega))\\le (x,y)) \n=\\int_{(u,v)\\le (x,y)}f_{X,Y}(u,v) du\\;dv\n\\end{equation}\nand \n\\begin{equation}\n(X,Y): \\Omega\\mapsto \\mathcal X\\times \\mathcal Y.\n\\end{equation}\n\\begin{equation}\n(X,Y)(\\omega) = (X(\\omega), Y(\\omega)) \\in \\mathcal{X}\\times\\mathcal{Y}\n\\end{equation}\nthen the probability of $(X,Y)$ in a measurable set of $\\mathcal{X}\\times\\mathcal{Y}$, for example $M_1\\times M_2$, can be written as\n\\begin{equation}\nP(\\omega\\in\\Omega: (X,Y)(\\omega) \\in M_1\\times M_2)= P\\left( \\{\\omega\\in\\Omega: X(\\omega)\\in M_1\\} \\cap \\{\\omega\\in\\Omega: Y(\\omega)\\in M_2\\} \\right)\n\\end{equation}\nwhich is also equal to\n\\begin{equation}\n\\int_{M_1\\times M_2} f_{X,Y}(u,v)dudv\n\\end{equation}\n\nWe can identify the distribution with its density function $f_{X,Y}(x,y)$. Usually the upper case $(X,Y)$ denotes random variables and the lower case $(x,y)$ denotes one specific sample. (where $x \\in \\mathcal{X}$ and $y \\in \\mathcal{Y}$).\n\n\\noindent We use $F_X$ and $F_{Y|X}$ to denote the marginal distribution of X and the conditional distribution of $Y$ given $X$. We also use $f_X(x)$ and $f_Y(y|X=x)$ to denote the marginal density function of $X$ and the conditional density function of $Y$ given $X=x$.\\\\\nwhere the marginal density function of $X$ can be written as \n\\begin{equation}\nf_X(x)= \\int_\\mathcal{Y}f_{X,Y}(x,y) dy\n\\end{equation}\nActually, it is the same $f_X(x)$ given in (1.3), Because the RHS satisfies the definition of density function of $X$:\n\\begin{align}\n\\int_{\\tilde{x} \\leq x}\t\\int_\\mathcal{Y}f_{X,Y}(\\tilde{x},y) dy d\\tilde{x} &= \\int_{(u,v)<(x,+\\infty)} f_{X,Y}(u,v)dudv\\\\\n&=P(\\omega\\in\\Omega: (X(\\omega),Y(\\omega))<(x,+\\infty))\\\\\n&=P(\\omega\\in\\Omega: X(\\omega)<x)\\\\\n&=F_X(x)\n\\end{align}\nOr you could view it as a simple proof of the equation(1.9).\\\\\n\nAnd the conditional density function of $Y$ given $X=x$ can be written as\n\\begin{equation}\nf_Y(y|X=x)= \\frac{f_{X,Y}(x,y)}{f_X(x)}\n\\end{equation}\nthen the probability of $Y$ in a measurable set of $\\mathcal{Y}$ when given $X=x$ can be computed as\n\\begin{equation}\nP(Y \\in M|X=x)= \\int_{y\\in M} \\frac{f_{X,Y}(x,y)}{f_X(x)} dy\n\\end{equation}\nFor a particular case, if the conditional distribution of $Y|X$ is discrete, which means $Y$ takes value from a countable (or finite) set $\\{y_1,...,y_n,...\\}$ with probablity $p_1,...,p_n,...$ respectively. Of course we have $\\sum_{i=1}^{\\infty}p_i=1$, Then the probability is simpliy denoted by:\n\\begin{equation}\nP(y_i|X=x)=P(y_i|x)=p_i\n\\end{equation}\nWe can see that the density function of pair $(X,Y)$ is uniquely identified by the marginal density function of $X$ and the conditional density function of $Y$ given $X=x$ for all $x \\in \\mathcal{X}$. So that $F_{X,Y}$ is uniquely identified by $F_X$ and $F_{Y|X}$. This provides another view of a sample $(x,y)$ drawn from the joint distribution $F_{X,Y}$, that we can firstly get $x$ from the marginal distribution $F_X$ and then get the corresponding label $y$ from the conditional distribution $F_{Y|X}$ given $X=x$.\\\\\n\n\\hrule \n\\noindent Let $S = \\{(x_1,y_1),...,(x_n,y_n) \\}$ be an i.i.d. random\nsample from $F_{X,Y}$. \n\\hrule \n\nLet us put this more mathematically. Now we have a pair random variable $(X,Y)$, but we are supposed to draw samples from the joint distribution n times independently. To finish it, we have to introduce more random variables and make them independent and identically distributed(i.i.d.). We define:\n\\begin{equation}\nZ=((X_1,Y_1), (X_2,Y_2),..., (X_n,Y_n)) :\\Omega^n \\mapsto (\\mathcal{X}\\times\\mathcal{Y})^n\t\n\\end{equation}\n\\begin{equation}\n(\\omega_1, \\omega_2,..., \\omega_n) \\mapsto ((X,Y)(\\omega_1), (X,Y)(\\omega_2),..., (X,Y)(\\omega_n))\n\\end{equation}\nthen for any $i$, $(X_i,Y_i)$ is the composition of the joint measurable function $Z$ and a projection $p_i$ from $(\\mathcal{X}\\times\\mathcal{Y})^n$ to its i-th component:\n\\begin{equation}\n(X_i,Y_i)=p_i \\circ Z :\\Omega^n \\mapsto (\\mathcal{X}\\times\\mathcal{Y})\n\\end{equation}\n\\begin{equation}\n(X_i,Y_i)(\\omega_1, \\omega_2,..., \\omega_n)= (X,Y)(\\omega_i)\n\\end{equation}\nIt is easy to check these n-tuple random variables are i.i.d. We will show a simple explanation of the independence. Assume that $M_1, M_2,..., M_n$ are n measurable set of $\\mathcal{X}\\times\\mathcal{Y}$, $M=M_1\\times M_2\\times...\\times M_n$ and $\\omega=(\\omega_1, \\omega_2,..., \\omega_n)$, then\n\\begin{align}\nP(\\omega \\in \\Omega^n : Z(w)\\in M) &= P((\\omega_1, \\omega_2,..., \\omega_n)\\in \\Omega^n : (X,Y)(\\omega_i) \\in M_i, \\forall 1\\leq i \\leq n ) \\\\\n&= \\prod_{i=1}^{n}P(\\omega_i \\in \\Omega : (X,Y)(\\omega_i) \\in M_i) \\\\\n&= \\prod_{i=1}^{n}P(\\omega \\in \\Omega^n : (X_i,Y_i)(\\omega) \\in M_i)\n\\end{align}\nWhich is obtained by  product measure of the product space $\\Omega^n$. \\\\\n\\noindent Thus random variable $Z$ maps a event in $\\Omega^n$ to a n-tuple samples $S = \\{(x_1,y_1),...,(x_n,y_n) \\}$.\\\\\n\n\\noindent The goal of supervised learning is to find a mapping $h:\\mathcal{X}\\mapsto\\mathcal{Y}$  based on the dataset S, so that $h(X)$ is a good approximation of $Y$. When $\\mathcal{Y}=\\mathbb{R}$ the learning problem is often called regression and when $\\mathcal{Y}=\\{0,1\\} or \\{-1,1\\}$, it is often called (binary) classification.\\\\\n\n\\begin{itemize}\n\t\\item  For the classification problem, the conditional distribution $F_{Y|X}$ is just a distribution on $\\{0,1\\}$ which is determined by the conditional probability $p=P(Y=0|X=x)$ and $q=P(Y=1|X=x)$. ($p+q=1$)\n\t\\item  For the regression problem, the conditional distribution $F_{Y|X}$ is a distribution over $\\mathbb{R}$ which is determined by the conditional density function $f_Y(y|X=x)$. And for any measurable set $A$ (in most case $A$ is just an interval) of $\\mathbb{R}$, the conditional probability is given by \n\t$$P(Y \\in A|X=x)= \\int_{y\\in A}f_Y(y|X=x)dy$$\n\\end{itemize}\n\n\\noindent The dataset S is often called the training set (or training data), and it is important since the distribution $F_{X,Y}$ is usually unknown. A learning algorithm is a procedure $\\mathcal{A}$ which takes the training set S and procedures a predictor $\\hat{h}=\\mathcal{A}(S)$ as the output. Typically the learning algorithm will search over a space of functions $\\mathcal{H}$, which we call the hypothesis space.\\\\\n\\begin{example}\n\tFor a specific example, if we want the machine to recognize whether a picture is a cat or a dog.\n\tAccording to the results we want, we illustrate this problem with two models, using the classification method and the regression method respectively.\\\\\n\t\n\tClassification case: We just want the machine to give two answers, dog or cat. In this case, the sample we got has specific label says $(x,0)$ for dog or $(x,1)$ for cat. However, whether a picture is a cat or a dog is uncertain and subject to people's subjective consciousness. And that is exactly what the underlying conditional distribution explains. We can imagine $p=P(Y=0|X=x)$ represents the percentage of people who recognize the picture $x$ as a dog. Later we can see the optimal predictor will map the picture to a dog if $p>\\frac{1}{2}$, to a cat if $p<\\frac{1}{2}$. But we do not get the actual value of $p$. The regression model below can help to obtain the prediction of value of $p$.\\\\\n\t\n\tRegression case: We not only want the machine to give cat or dog answer, but also want it to give the probability of the given picture to be a cat or a dog. In this case the sample picture we got must has it probability label (i.e. a real number in $[0,1]$) represents the probability for this picture to be a dog. The conditional distribution gives no information since every picture has a specific probability. Actually this is the deterministic case we will talk in a short while.\n\\end{example}\n\\begin{example}\n\t\\noindent For another specific example, if we want to use the pulse data of a woman to predict whether she is pregnant or not, the sample will be a pulse waveform. In oder to make the input space an Euclidean space, we discretized the time coordinates of the waveform. For example we get a wave for 10 seconds, we can divide it into 100 time-points, and then the y-axis value of these 100 points form a 100-dimension vector. Thus the input space $\\mathcal{X}$ can be thought as $\\mathbb{R}^{100}$. The output space $\\mathcal{Y}$ is obviously $\\{0,1\\}$, where $1$ denotes pregnant and $0$ denotes not. Thus $\\mathcal{X}\\times\\mathcal{Y}$ here is actually $\\mathbb{R}^{100} \\times \\{0,1\\}$. \\\\\n\t\n\t\\noindent The basic hypothesis is that there is a distribution $F_{X,Y}$ on $\\mathcal{X}\\times\\mathcal{Y}$,\t which means if we choose a random person and detect her pulse waveform, the discrete pulse data together with the pregnancy is considered as a joint random variable $(X,Y)$ whose distribution is $F_{X,Y}$. A sample drawn from $F_{X,Y}$ is a pair $(x,y)$, where $x$ is the wave data and y is the pregnancy or not. It is worth noting that, for the same wave data $x$, then $(x,0)$ and $(x,1)$ are both possible in our sample set. \\\\\n\tThe marginal distribution of $X$ means we only consider the distribution of pulse data, ignoring the pregnancy. The marginal distribution of $Y$ means the probability of a woman getting pregnant, which has nothing to do with the pulse data. The conditional distribution of $Y|X=x$ indicates the probability to getting pregnant of a woman with specific pulse waveform $x$.\n\\end{example}\n\n\\subsection{Loss Function and Risk}\nA loss function is a mapping $\\ell:\\mathcal{Y} \\times \\mathcal{Y}^* \\mapsto \\mathbb{R}^+$. For example, in binary classification the 0/1 loss function $\\ell(y,p) = I(y\\ne p)$ is often used and in regression the squared error loss function $\\ell(y,p)=(y-p)^2$ is often used. Other loss functions include the following: absolute loss, Huber loss, $\\epsilon-insensitive$ loss, hinge loss, logistic loss, exponential loss, modified least squares loss, etc. They will be discussed later in more details.\n\n\\noindent The performance of a predictor  $h:\\mathcal{X}\\mapsto\\mathcal{Y}$ is measured by the expected loss, a.k.a. the risk or generalization error:\n\\begin{equation}\nR(h): =\\mathbb{E}_{X,Y}[\\ell(Y, h(X))]\n\\end{equation}\nwhere the expectation is taken with respect to the distribution $F_{X,Y}$. Since in practice we estimate $\\hat{h}_S$ based on the training set S, we have $R(\\hat{h}_S)$ itself a random variable. More precisely, $\\mathcal{A}$ is a fucntion mapping $S$ to $\\hat{h}_S$, then $R\\circ \\mathcal{A}$ maps $S$ to a real number, which is a function of random variable $S$. Thus we may also use the quantity $R(\\mathcal{A})=\\mathbb{E}_{S}[R(\\hat{h}_S)]=\\mathbb{E}_{S}[R\\circ \\mathcal{A}(S)]$\nto characterize the generalization performance of the learning algorithm $\\mathcal{A}$, which is also called the expected risk of the learning algorithm.\\\\\n\n\\noindent The risk is an important measure of the goodness of the predictor $h(.)$ since it tells how it performs on average in terms of the loss function $\\ell(.,.)$ The minimum risk is defined as\n\\begin{equation}\nR^*= \\inf_h{R(h)}\n\\end{equation}\nwhere the infimum is often taken with respect to all measurable functions. The performance of a given predictor/estimator can be evaluated by how close $R(h)$ is to $R^*$. Minimization of the risk is non-trivial because the underlying distribution $F_{X,Y}$ is in general unknown, and the training data S only gives us an incomplete knowledge of $F_{X,Y}$ in practice.\n\n\\subsection{Deterministic vs. stochastic(agnostic) scenarios}\nWhen the label of a random variable $X$  can be uniquely determined by some measurable function $f: \\mathcal{X} \\to \\mathcal{Y}$(with probability one), then the scenario is said to be deterministic. The \"probability one\" means that the graph of $f$, $\\Gamma(f)=\\{(x,y)\\in \\mathcal{X}\\times \\mathcal{Y}: y=f(x), x\\in \\mathcal{X}\\}$ satisfies:\n\\begin{equation}\nP(\\omega \\in \\Omega: (X,Y)(\\omega) \\in \\Gamma(f)) = 1\n\\end{equation}\nOr more simply,\n\\begin{equation}\nP(Y=f(X))=1\n\\end{equation}\nIn that case, it is suffices to consider a distribution $F$ over the input space $\\mathcal{X}$ (instead of  $\\mathcal{X}\\times\\mathcal{Y}$). The training sample is obtained by drawing $(x_1,..., x_m)$ according to $F$ and the labels are obtained via $f: y_i=f(x_i)$ for all $i \\in [1, m]$. Many learning problems can be formulated within this deterministic scenario.\\\\\n\n\\noindent Within this setting, the output label is a deterministic function of the input, while in the stochastic case that is a probabilistic function of the input. More precisely, in the case $\\mathcal{Y}=\\mathbb{R}$ or $\\{0,1\\}$, there exsist a random variable $\\xi$ and a deterministic function $f$ such that, $Y=f(X,\\xi)$. It is easy to see that stochastic case is more general, and when the probability is one for each point in the input space, it becomes to the deterministic scenario.\\\\\nFor example, we can choose $\\xi$ to be uniformly random on $[0,1]$. We will do that in the following two common cases.\\\\\n\n\\noindent In binary classification case , for a given $x \\in \\mathcal{X}$, the distribution over $\\mathcal{Y}$ is determined by the probabilities $p(x)$ and $q(x)$, corresponding to the label $0$ and $1$. Then we can define $f$ to be,\n\\begin{numcases}{f(x,\\xi)=}\n0, & if 0 $\\leq \\xi < p(x)$ \\\\\n1, & if $p(x) \\leq \\xi \\leq 1$\n\\end{numcases}\nIn refression case, for a given $x \\in \\mathcal{X}$, the distribution over $\\mathcal{Y}$ is determined by the conditional distributed function $F_{x}(y)$. Similarly we define $f$ to be,\n\\begin{equation}\nf(x,\\xi)= \\inf\\{y:F_x(y) \\geq \\xi\\}\n\\end{equation}\nThen for any fixed $x \\in \\mathcal{X}$, the distributed function of $f(x,\\xi)$ is identical to that of $Y|X=x$.\\\\\n\n\\noindent By taking the expectation successively (which can be proved easily by $Fubini \\ Theorem$) we have:\n\\begin{equation}\nR(h)=\\mathbb{E}_{X,Y}[\\ell(Y, h(X))]=\\mathbb{E}_{X} \\left[ \\mathbb{E}_{Y|X}[\\ell(h(X),Y)] \\right] \t\n\\end{equation}\\\\\nIn the deterministic case, the conditional distribution of $Y|X$ is only one possible value $f(X)$. Then $f$ is the target fouction we need to learn. Thus, the above becomes:\n\\begin{equation}\nR(h)=\\mathbb{E}_{X}[\\ell(h(X),f(X))]\n\\end{equation}\\\\\n\\noindent An essential difference between these two scenarios is whether there exists a function with zero generalization error.\nIn the deterministic case, by definition, there exists a target function h with no generalization error: $R(h)=0$. In the stochastic case, generally there is a minimal non-zero error for any hypothesis, which says: $R^*>0$.\\\\\nThe arbitrariness of the loss function bring about this \"generally\". For example in the case $\\mathcal{Y}=\\mathcal{Y}^*=\\mathbb{R}$, if we choose the loss function to be a strange one, $\\ell(y,p)=|y-p|\\exp(-|y-p|)$, which intends to make $\\ell(y,p)$ decay to zero when the Euclidean distance of $x$ and $y$ increase to infinity. For this strange loss function, even in non-deterministic case, we can easily construct a series of $h_n$ such that $R(h_n)$ converge to zero, which means that $R^*=0$. \\\\\n\nFortunately, in binary classification or regression, if we choose the normal loss fucntion, $0/1$ error loss and squared error loss, then we can claim that a stochastic case is deterministic case if and only if $R^*=0$. \\\\\n\n\\noindent For the deterministic case, we have showed that $R^*=0$. To prove the other side, we need to prove that a stochastic case is deterministic case when $R^*=0$. Assume not, then there must exists a positive measure set $A\\subseteq \\mathcal{X}$, where the conditional distributution $Y|X=x$ is not concentrated in one value, which means for any $y\\in \\mathcal{Y}$, the probability $P(Y=y|X=x)\\ne 1$.\nThat implies for any fixed $x\\in A$, for any $y\\in \\mathcal{Y}$, we have\n\\begin{equation}\n\\mathbb{E}_{Y|X=x}[\\ell(y,Y)]= \\mathbb{E}_{Y|X=x}[(y-Y)^2]> 0\n\\end{equation}\nWe define a function $p(x)$ on $A$, (somewhere $p(x)$ can be $+\\infty$)\n\\begin{equation}\np(x)= \\inf_{y\\in \\mathcal{Y}} {E}_{Y|X=x}[(y-Y)^2]\n\\end{equation}\nBy the lemma in the next subsection, we know that $y=\\mathbb{E}[Y|X=x]$ can achieve the infimum $\\inf_{y\\in \\mathcal{Y}} {E}_{Y|X=x}[(y-Y)^2]$. So that $p(x)>0$ for any $x\\in A$. \nThen for any measurable function $h: \\mathcal{X} \\to \\mathcal{Y}$,\n\\begin{align}\nR(h)&= \\mathbb{E}_{X} \\left[ \\mathbb{E}_{Y|X}[\\ell(h(X),Y)] \\right]\\\\\n&= \\mathbb{E}_{X}[\\mathbb{E}_{Y|X}[(h(X)-Y)^2]]\\\\\n&\\geq \\mathbb{E}_{X}[p(x)]\\\\\n&\\geq \\int_{x\\in A} p(x) f_{X}(x) dx\n\\end{align}\nSince $A$ is a set of positive measure, we can assume that $f_{X}(x)$ is positive almost everywhere on $A$. Together with the positiveness of $p(x)$, we have got the integration of a almost everywhere positve function on a positive measure set, which is postive for certain. Then $R(h)$ has a positive lower bound independent with $h$, which implies that $R^*>0$, a contradiction.\\\\\nThe smaller of $R^*$ means the more deterministic of the case.\n\n\\subsection{Binary Classification}\nFor classification problem, a predictor $h$ is also called a classifier, and the loss function for binary classification is often taken to be 0/1 loss. In this case, we have\n\\begin{equation}\nR(h)=\\mathbb{\\mathbb{E}}_{X,Y}[\\ell(Y,h(X))]=\\mathbb{\\mathbb{E}}_{X,Y}[I(Y\\ne h(X))]=P(h(X)\\ne Y)\n\\end{equation}\n\n\\noindent And the infimum risk $R^*$ is also known as the Bayes risk.\\\\\nThe following results show that the Bayes classifier, which is defined as \n\\begin{equation}\nh^*(x)=\\arg\\max_{y\\in \\{0,1\\}}P(y|x)\n\\end{equation}\ncan achieve the Bayes risk.\n\n\\begin{lemma}\n\tAssume that $X$ is a random variable over $\\mathbb{R}$. Define a function $f$ over $\\mathbb{R}$, $f(\\mu)= \\mathbb{E}[(X-\\mu)^2]$. If $E[|X|]=+\\infty$, then $f(\\mu)$ will be $+\\infty$ everywhere on $\\mathbb{R}$. If $E[|X|]<\\infty$, then we know that $f$ is a quadratic function, which minimizes at $\\mathbb{E}[X]$.\n\t$$\\mathbb{E}[X]= \\arg\\min_{\\mu \\in \\mathbb{R}} \\mathbb{E}[(X-\\mu)^2] $$\n\\end{lemma}\n\\begin{proof}\n\tIf $E[|X|]=+\\infty$, which means:\n\t\\begin{equation}\n\t\\int_{\\mathbb{R}} |x|f_{X}(x) dx =+\\infty\n\t\\end{equation}\n\tFor any $\\mu \\in \\mathbb{R}$, there must exist a positive $a$, such that $(x-\\mu)^2>|x|$ on $(-\\infty,-a)\\cup (a,+\\infty)$. Then we have\n\t\\begin{equation}\n\t\\int_{\\mathbb{R}} (x-\\mu)^2f_{X}(x) dx \\geq \\int_{\\mathbb{R}\\backslash[-a,a]} |x|f_{X}(x) dx \\geq +\\infty\n\t\\end{equation}\n\tThus $E[(X-\\mu)^2]=+\\infty$ for any $\\mu \\in \\mathbb{R}$.\\\\\n\t\n\t\\noindent If $E[|X|]<+\\infty$,\n\t\\begin{align}\n\tf(\\mu)&= \\mathbb{E}[(X-\\mu)^2]= \\mathbb{E}[X^2-2\\mu X+\\mu^2]= \\mu^2 -2\\mathbb{E}[X]\\mu +\\mathbb{E}[X^2]\\\\\n\t&=(\\mu -\\mathbb{E}[X])^2 + \\mathbb{E}[X^2] - (\\mathbb{E}[X])^2\n\t\\end{align}\n\tThus $f(\\mu)$ is a quadratic function which minimizes at $\\mathbb{E}[X]$, and when $\\mu$ get closer to $\\mathbb{E}[X]$, $f(\\mu)$ gets smaller.\n\\end{proof}\n\nWe can already draw some conclusions from this lemma. If we choose the loss function to be the squared error loss, $\\ell(p,y)=(p-y)^2$, then generalization error becomes:\n\\begin{equation}\nR(h)= \\mathbb{E}_{X,Y}[(Y-h(X))^2] = \\mathbb{E}_{X}[\\mathbb{E}_{Y|X}[(Y-h(X))^2]]\n\\end{equation}\nThe lemma implies that $R(h)$ is minimized when $h(x)$ is nearest to $\\mathbb{E}[Y|X=x]$ for every $x\\in \\mathcal{X}$, which means that $\\big|h(x)-\\mathbb{E}[Y|X=x]\\big|$ should achieve its minial value.\\\\\n\nSince 0/1 error loss is a special case of the squared error loss (restrict squared loss on $\\{0,1\\}$), we can apply the lemma to binary classification case. For binary classification, $\\mathbb{E}[Y|X=x]= P(1|x)$. So that to minimize $R(h)$, $h(x)$ should be $1$ if $P(1|x)>\\frac{1}{2}$, should be $0$ if $P(1|x)<\\frac{1}{2}$. That is no other than $h^*(x)$.\n\\begin{corollary}\n\tFor any classifier h we have $R(h) \\geq R(h^*)$, i.e. $R(h^*)=R^*$\n\\end{corollary}\n\n\\subsection{Regression}\nIn regression we typically have $\\mathcal{X}=\\mathbb{R}^p$ and $\\mathcal{Y}=\\mathbb{R}$. And the risk is often measured by the squared error loss, $\\ell(p,y)=(p-y)^2$. The following result shows that for squared error regression, the optimal predictor is the conditional mean function $\\mathbb{E}[Y|X=x]$.\n\\begin{corollary}\n\tSuppose the loss function $\\ell(.,.)$ is the squared error loss. Let $h^*(x) = \\mathbb{\\mathbb{E}}[Y|X=x]$, then we have $R(h^*)=R^*$.\n\\end{corollary}\n\n\\noindent Thus regression with squared error can be thought as trying to estimate the conditional mean function.\n\\subsection{Approximation Error vs. Estimation Error}\nSuppose that the learning algorithm chooses the predictor from the hypothesis space $\\mathcal{H}$, and define\n\\begin{equation}\nh^*=\\arg\\inf_{h \\in \\mathcal{H}} R(h)\n\\end{equation}\ni.e. $h^*$ is the best predictor among $\\mathcal{H}$. Then the excess risk of the output $\\hat{h}_S$ of the learning algorithm is\ndefined and can be decomposed as follows:\n\\begin{equation}\nR(\\hat{h}_S)-R^* = \\underbrace{\\left( R(h^*)-R^* \\right)}_{approximation\\ error} + \\underbrace{\\left( R(\\hat{h}_S)-R(h^*) \\right)}_{estimation\\ error}\n\\end{equation}\nSuch a decomposition reflects a trade-off similar to the bias-variance tradeoff(maybe slightly more general). The approximation error is deterministic and is caused by the restriction of using $\\mathcal{H}$. The estimation error is caused by the usage of a finite sample that cannot completely represent the underlying distribution.\\\\\n\n\\noindent The approximation error term behaves like a bias square term, and the estimation error behaves like the variance term in standard statistical estimation problems. Similar to the bias-variance trade-off, there is also a trade-off between the approximation error and the estimation error. Basically if $\\mathcal{H}$ is large then we have a small approximation error but a relatively large estimation error and vice versa.\n\n\\section{Risk Minimization}\n\\subsection{Empirical risk Minimization}\nGiven a loss function $\\ell$(.,.), the risk $R(h)$ is not computable as $F_{X,Y}$ is unknown. Thus we may not able to directly minimize $R(h)$ to obtain some predictors. Fortunately we are provided with the training data\n$S=\\{(x_1,y_1),...,(x_n, y_n)\\}$ which represents the underlying distribution $F_{X,Y}$.\nInstead of minimizing $R(h)=\\mathbb{E}_{X,Y}[\\ell(h(X),Y)]$, one may replace $F_{X,Y}$ by its empirical distribution and thus obtain the following minimization problem:\n\\begin{equation}\n\\hat{h}_S = \\arg\\min_{h \\in \\mathcal{H}} \\frac{1}{m} \\sum_{i=1}^{m}{\\ell(h(x_i),y_i)}\n\\end{equation}\nwhich we call empirical risk minimization(ERM). Furthermore, we also define the empirical risk $\\hat{R}_S(h)$ as\n\\begin{equation}\n\\hat{R}_S(h):= \\frac{1}{m} \\sum_{i=1}^{m}{\\ell(h(x_i),y_i)}\n\\end{equation}\n\n\\noindent We can already note that for a fixed $h \\in \\mathcal{H}$, the expectation of the empirical error based on an i.i.d. sample S is equal to the generalization error:\n\\begin{equation}\n\\mathbb{E}_{S\\sim {D^m}}[\\hat{R}_S(h)]=R(h)\n\\end{equation}\nIndeed, by the linearity of the expectation and the fact that the sample is drawn i.i.d.,we can write\n\\begin{equation}\n\\mathbb{E}_{S\\sim {D^m}}[\\hat{R}_S(h)] = \\frac{1}{m}\\sum_{i=1}^{m}\\mathbb{E}_{S\\sim {D^m}}[{\\ell(h(x_i),y_i)}] = \\frac{1}{m}\\sum_{i=1}^{m}\\mathbb{E}_{S\\sim{D^m}}[{\\ell(h(x),y)}]\n\\end{equation}\nfor any $(x,y)$ in sample S. Thus,\n\\begin{equation}\n\\mathbb{E}_{S\\sim {D^m}}[\\hat{R}_S(h)] = \\mathbb{E}_{S\\sim{D^m}}[{\\ell(h(x),y)}]= \\mathbb{E}_{S\\sim{D}}[{\\ell(h(x),y)}]=R(h)\n\\end{equation}\n\n\\noindent Because under some conditions ( such as the expectation $R(h) < \\infty $)\\\\  $\\hat{R}_S(h) \\xrightarrow{a.s.} R(h)$ by the law of large numbers, the usage of ERM is at least partially justified.\\\\\n\n\\noindent ERM covers many popular methods and is widely used in practice. For example, if we take $\\mathcal{H} = \\{h(x) | h(x)=\\theta^Tx, \\forall \\theta \\in \\mathbb{R}^p\\}$ and $\\ell(y,p) = (y-p)^2$, then ERM becomes the well-known least squares estimation.\nThe celebrated maximum likelihood estimation (MLE) is also a special case of ERM where the loss function\nis taken to be the negative log-likelihood function. Example: in binary classification $(x_1, y_1),..., (x_m,y_m)$\nwhere $y_i \\in (-1, 1)$ and $\\mathcal{H} = \\{h(x) | h(x)=\\theta^Tx, \\forall \\theta \\in \\mathbb{R}^p\\}$, the logistic regression is computed by minimizing the logistic loss\n\\begin{equation}\n\\hat{\\theta} = \\arg\\min{\\frac{1}{m}} \\sum_{i=1}^{m}\\log(1+\\exp(-y_i\\theta^T x_i))\n\\end{equation}\nwhich is equivalent to MLE.\n\n\\subsection{Overfitting}\nERM works by minimizing the empirical risk $\\hat{R}_S(h)$, while the goal of learning is to obtain a predictor with\na small risk $R(h)$. Although under certain conditions the former will converge to the latter as $n \\rightarrow \\infty$,\nin practice we always have a finite sample and as a result, there might be a large discrepancy between those\ntwo targets, especially when $\\mathcal{H}$ is large and n is small. Overfitting refers to the situation where we have a\nsmall empirical risk but still a relatively large true risk.\\\\\nConsider the following example. Let $\\ell(y, p)=(y-p)^2$ and we obtain the predictor $h$ by ERM:\n\\begin{equation}\n\\hat{h}_S = \\arg\\min_{h \\in \\mathcal{H}} \\frac{1}{m} \\sum_{i=1}^{m}{(h(x_i)-y_i)^2}\n\\end{equation}\n\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[width=1.1\\linewidth]{6DL/figures/overfitting.png}\n\t\\caption{Overfitting}\n\t\\label{Overfitting1}\n\\end{figure}\n\n\\noindent Figure 1: Overfitting of polynomial regression. The true signal function(blue line) is $h^*(x)= sin(x)$, and\nthe function is fitted using 10 training examples (red dots). $P_1$ and $P_2$ show a lack of fitting(underfiting) and $P_5$ is overfitting.\n\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[width=0.8\\linewidth]{6DL/figures/overfitting2.jpeg}\n\t\\caption{True/empirical risk vs. model complexity}\n\t\\label{Overfitting2}\n\\end{figure}\n\n\\noindent Figure1 shows the case where $\\mathcal{H}$ is taken to be $P_1, P_2,...$, where $P_k$ is the set of all polynomial functions with order up to $k$\\\\\n\n\\noindent We can see that when $\\mathcal{H}=P_3$ the fitted predictor will have a small risk(close to the true signal $sin(x)$)\nTaking $P_k$ with larger k values as the hypothesis space can clearly improve its fitting with respect to the\n10 observations(red dots), but this does not necessarily reduce the true risk as it overfits the training data.\nLearning is more about generalization than memorization.\n\n\\subsection{Controlling Model Complexity}\nOverfitting is mainly caused by the fact that the hypothesis space $\\mathcal{H}$ is too large for the sample\nClearly the complexity of the hypothesis space $\\mathcal{H}$ (i..e the size of $\\mathcal{H}$) we can afford depends on the amount\nof training data we have. For a given training dataset, the relationship between the true risk, the empirical\nrisk and model complexity can be best illustrated as in Figure 2.\\\\\n\n\\noindent One way to avoid overfitting is to choose $\\mathcal{H}$ so that it is appropriate for the sample size. There are many ways to control the model complexity, and they are in fact quite similar in spirit. Here we list two commonly used approaches:\\\\\n\n%\\begin{adjustwidth}{1cm}{0cm}\n\\begin{enumerate}\n\t\\item Take $\\mathcal{H}_1$, $\\mathcal{H}_2$, ..., $\\mathcal{H}_n$,... to be a sequence of increasing sized spaces. For example, one typically has\n\t$\\mathcal{H}_k \\subset \\mathcal{H}_{k+1}$ and $\\cup \\mathcal{H}_k= \\mathcal{H}$. Given the training data S one finds $\\hat{h}_S$ by minimizing\n\t\\begin{equation}\n\t\\hat{h}_{S,n} = \\arg\\min_{h \\in \\mathcal{H}_n} \\hat{R}_S(h)\n\t\\end{equation}\n\tThis covers the method of Sieves and structural risk minimization (SRM) whoses hypothesis selected is the\n\tone among the $\\hat{h}_{S,n}$ solutions with the smallest sum of the empirical error and a complexity term $complexity(\\mathcal{H}_n,m)$ that depends on the size (or more generally the capacity, that is, another measure of the richness of $\\mathcal{H}$) of $\\mathcal{H}_n$, and the sample size $m$:\n\t\\begin{equation}\n\th^{SRM}_{S,n} = \\arg\\min_{h \\in \\mathcal{H}_n} \\hat{R}_S(h)+complexity(\\mathcal{H}_n,m)\n\t\\end{equation}\n\t\n\t\\item Define a penalty function $\\Omega: \\mathcal{H} \\mapsto \\mathbb{R}^+$ and find $\\hat{h}_S$ by the following optimization procedure which is called regularization:\n\t\\begin{equation}\n\t\\hat{h}_S = \\arg\\min_{h \\in \\mathcal{H}} \\hat{R}_S(h)+ \\lambda \\Omega(h)\n\t\\end{equation}\n\twhere $\\lambda >0$ is a regularization, which can balances the trade-off between goodness-of-fit and model complexity. The regularization term $\\Omega(h)$ is typically\n\tdefined as $||h||^2$ for some norm $||.||$ when $\\mathcal{H}$ is a vector space. In practice, $\\lambda$\n\tis typically selected using n-fold cross-validation. This is also known as the penalized empirical risk minimization.\\\\\n\\end{enumerate}\n%\\end{adjustwidth}\n\n\\noindent In practice we often need to select $\\mathcal{H}_n$ or $\\lambda$ based on the training data to achieve a good balance between goodness-of-fit and model complexity.\\\\\n\\begin{example}\n\t\\noindent Consider the following regression problem: let $\\mathcal{H} = \\{h(x) | h(x)=\\theta^Tx, \\forall \\theta \\in \\mathbb{R}^p\\}$ and we are trying to find an estimator $\\hat{\\theta}$ which minimizes the risk $\\mathbb{E}_{X,Y}[(Y-\\theta^TX)^2]$. For the first approach, we could define a sequence of increasing constants: $0\\leq \\eta_1 \\leq ... \\leq \\eta_k \\leq ...$, and define $\\mathcal{H}_k = \\{h(x) | h(x)=\\theta^Tx, \\theta^T\\theta \\leq \\eta_k\\}$. For the\n\tsecond approach we define $\\Omega(h) = \\theta^T\\theta$. Then it is well-known from optimization that those two approaches\n\tbecome mathematically equivalent, i.e. for any $\\eta_k$ there exists a $\\lambda$ such that those two optimization problems\n\thave the same solution. The following shows a proof of the equivalence:\\\\\n\t\n\t\\noindent For the second approach, we need to find the optimal $\\bar{\\theta}$ such that:\n\t\\begin{equation}\n\t\\bar{\\theta} = \\arg\\min_{\\theta \\in \\mathbb{R}^n}\\frac{1}{m} \\sum_{i=1}^{m} (\\theta^Tx_i-y_i)^2+\\lambda \\theta^T\\theta \n\t\\end{equation}\n\t\n\twhere $\\lambda$ is non-negative.\\\\\n\t\n\tObserve that the objective function is convex and a quadratic function, then it is a convex quadratic optimization problem with no constraint, so that $\\bar{\\theta}$ is the minimum solution if and only if:\n\t\\begin{equation}\n\t\\nabla_\\theta (\\frac{1}{m} \\sum_{i=1}^{m}(\\theta^Tx_i-y_i)^2+\\lambda \\theta^T\\theta )|_{\\bar {\\theta}} = 0 \n\t\\end{equation}\\\\\n\t\n\t\\noindent For the first approach, we need to find the optimal $\\bar{\\theta}$ such that:\n\t\\begin{equation}\n\t\\bar{\\theta} = \\arg\\min_{\\theta \\in X}\\frac{1}{m} \\sum_{i=1}^{m} (\\theta^Tx_i-y_i)^2 \n\t\\end{equation}\n\t\n\twhere $X = \\{\\theta \\in \\mathbb{R}^n | \\theta^T\\theta \\leq \\eta_k \\}$.\n\tWhich is also a convex quadratic optimization problem with the feasible region $X$.\n\tThe Lagrange funtion is defined as:\n\t\\begin{equation}\n\t\\mathcal{L}(\\theta, \\alpha) = \\frac{1}{m} \\sum_{i=1}^{m} (\\theta^Tx_i-y_i)^2+\\alpha (\\theta^T\\theta-\\eta_k)\t \n\t\\end{equation}\n\t\n\tFor $\\eta_k > 0$, $X$ is a closed ball whose interior $int(X) \\ne \\phi$. Then by the KKT conditions we know that the necessary and suficient condition of the constrained problem is: there exists $\\bar{\\alpha} \\geq 0$ such that:\n\t\\begin{align}\n\t&\\nabla_\\theta \\mathcal{L}(\\bar{\\theta}, \\bar{\\alpha}) = \t\\nabla_\\theta (\\frac{1}{m} \\sum_{i=1}^{m}(\\theta^Tx_i-y_i)^2+ \\bar{\\alpha} \\theta^T\\theta )|_{\\hat{\\theta}} = 0 \\\\ \n\t&\\nabla_\\alpha \\mathcal{L}(\\bar{\\theta}, \\bar{\\alpha}) = \\bar{\\theta}^T\\bar{\\theta}-\\eta_k \\leq 0 \\\\\n\t&\\bar{\\alpha} = 0 \\ \\ or \\ \\ \\bar{\\theta}^T\\bar{\\theta}  = \\eta_k\t      \n\t\\end{align}\n\tWhen $\\bar{\\alpha} = 0$, that means the constraint condition $\\theta^T\\theta \\leq \\eta_k$ has no effect on the minimization problem. We will get the same minimal solution when $\\theta$ runs over $\\mathbb{R}^n$.\\\\\n\tWhen $\\bar{\\alpha} \\ne 0$, that means $\\bar{\\theta}^T\\bar{\\theta}  = \\eta_k$ and the minimal solution is obtained at the boundary of $X$.\\\\\n\tIn both case, we take $\\bar{\\alpha}$ to be the penalty parameter $\\lambda$ then (12) is equivalent to (15),(16),(17), and we have proved that the constrained problem is equivalent to a non-constrained problem with a penalty term adding to the objective funtion.\n\\end{example}\n\\section{Concentration Inequalities and PAC Learning}\n\\subsection{Generalization Error Bounds and PAC learning}\nAlthough the concept of consistency of a learning algorithm is very important, it only measures how the expectation of a random variable $R(\\hat{h}_S)$ converges to the optimal Bayes risk asymptotically. However, it does not say how fast this convergence is, and neither does it tell us how this random variable is distributed. In particular, we are interested in probability bounds of the generalization error, such as the following: \"with\nprobability at least $1-\\epsilon$, the risk $R(\\hat{h}_S)$ is bounded by some quantity.\"\\\\\nRecall that the excess risk can be decomposed into approximation error and estimation error, i.e.\n\\begin{equation}\nR(\\hat{h}_S)-R^* = \\underbrace{\\left( \\inf_{h \\in \\mathcal{H}} R(h)-R^* \\right)}_{approximation\\ error} + \\underbrace{\\left( R(\\hat{h}_S)-\\inf_{h \\in \\mathcal{H}} R(h) \\right)}_{estimation\\ error}\n\\end{equation}\nThe approximation error is deterministic and mainly caused by two possible reasons: (1) the restriction\nof using the function class $\\mathcal{H}$; (2)if $\\inf_{h \\in \\mathcal{H}} R(h)$ in the above equation were replaced by the minimum risk achievable by the learning algorithm with infinite amount of data, then it can also be caused by the systematic\nas of the learning algorithm. Such an error is often not controllable as we do not know the underlying distribution $D_{X,Y}$. On the other hand, the estimation error depends on the sample size, the function class $\\mathcal{H}$ and the learning algorithm which we have control over. We would like to obtain probability bounds for\nthe estimation error. The definition of agnostic PAC-learning is also based on the estimation error.\\\\\n\n\\noindent The following introduces the Probably Approximately Correct(PAC) learning framework. We denote by $O(n)$ an upper bound on the cost of the computational representation of any element $x \\in \\mathcal{X}$. For example, $x$ may be a vector in $\\mathbb{R}^n$, for which the cost of an array-based representation would be in $O(n)$\n\\begin{definition}[Definition: Agnostic PAC-learning]\n\tLet $\\mathcal{H}$ be a hypothesis set. $\\mathcal{A}$ is an agnostic PAC-learning algorithm if there exists a polynomial function poly(.,. .,.,) such that for any $\\epsilon > 0$ and $\\delta > 0$, for all distributions $D$ over $\\mathcal{X} \\times \\mathcal{Y}$, the following holds for any sample size $m \\geq poly(1/\\epsilon, 1/\\delta, n)$:\n\t\\begin{equation}\n\tP_{S \\sim D^m} \\left( R(h_S)-\\inf_{h \\in \\mathcal{H}} R(h) \\leq \\epsilon \\right) \\geq 1-\\delta\n\t\\end{equation} \n\\end{definition}\n\n\\noindent The probably approximately correct(PAC) learning model typically states as follows: we say that $\\hat{h}_S$ is $\\epsilon-accurate$ with probability $1-\\delta$, if\nIn other words, we have $R(h_S)-\\inf_{h \\in \\mathcal{H}} R(h) \\leq \\epsilon$ with probability at least $(1-\\delta)$.\\\\\n\nSpecifically, if we use ERM to obtain our predictor $\\hat{h}_S = \\arg\\min_{h \\in \\mathcal{H}} \\hat{R}_S(h)$, and assume that $\\inf_{h \\in \\mathcal{H}} R(h) = R(h^*)$ for some $h^* \\in \\mathcal{H}$, then we have:\n\\begin{align}\nR(\\hat{h}_S)-\\inf_{h \\in \\mathcal{H}}R(h) &= R(\\hat{h}_S)-\\hat{R}_S(\\hat{h}_S)+\\hat{R}_S (\\hat{h}_S)-R(h^*) \\\\\n&\\leq R(\\hat{h}_S)-\\hat{R}_S (\\hat{h}_S)+\\hat{R}_S (h^*)-R(h^*) \\\\\n&\\leq 2\\sup_{h \\in \\mathcal{H}} |R(h)-\\hat{R}_S (h)|\t\n\\end{align}\nThus if we can obtain uniform bound of $\\sup_{h \\in \\mathcal{H}} |R(h)-\\hat{R}_S (h)|$ then the approximation error can be bounded.\nThus again justifies the usage of the ERM method.\\\\\nIntuitively, for any $h \\in \\mathcal{H}$, $\\hat{R}_S(h)$ is a random variable which follows a Binomial distribution with mean $R(h)$. Or we could think of it as the average of a series of random variables. Thus we should be\nable to bound the difference between an average of a set of random variables and their mean. The uniform bound, however, will depend crucially on how large/complex the hypothesis space $\\mathcal{H}$ is.\\\\\n\n\\subsection{Concentration Inequalities}\n\\begin{theorem}[Markov Inequality]\n\tFor any nonnegative random variable X and $\\epsilon > 0$,\n\t$$P(X \\geq \\epsilon) \\leq \\frac{\\mathbb{E}[X]}{\\epsilon}$$\n\\end{theorem}\n\n\n\\begin{theorem}[Chernoff Inequality]\n\tFor any random variable X and $\\epsilon > 0$,\n\t$$P(X \\geq \\epsilon) \\leq \\frac{\\mathbb{E}[\\exp(tX)]}{exp(t\\epsilon)}$$\n\tand thus\n\t$$P(X \\geq \\epsilon) \\leq \\inf_{t > 0} \\frac{\\mathbb{E}[exp(tX)]}{\\exp(t\\epsilon)}$$\n\\end{theorem}\n\n\\begin{theorem}[Chebyshev Inequality]\n\tFor any random variable X and $\\epsilon > 0$,\n\t$$P(|X-\\mathbb{E}[X]| > \\epsilon) \\leq \\frac{\\mathbb{V}[X]}{\\epsilon^2}$$\n\\end{theorem}\n\n\\begin{lemma}\n\tIf random variable X has mean zero, i.e. $\\mathbb{E}[X]=0$, and is bounded in $[a,b]$, then for any $s > 0$,\n\t$$\\mathbb{E}[\\exp(sX)] \\leq \\exp(s^2(b-a)^2/8)$$\n\\end{lemma}\n\n\\begin{theorem}[Hoeffding Inequality]\n\tLet $X_1 ,..., X_m$ be independent bounded  random variables such that $X_i \\in [a_i, b_i]$ with probability $1$. Let $S_m=\\sum_{i=1}^{m} X_i$. Then for any $\\epsilon > 0$, we have\n\t\\begin{align}\n\t& P(S_m-\\mathbb{E}[S_m] \\geq \\epsilon) \\leq \\exp \\left(-\\frac{2\\epsilon^2}{\\sum_{i=1}^{m}(b_i-a_i)^2} \\right)\\\\\n\t& P(S_m-\\mathbb{E}[S_m] \\leq -\\epsilon) \\leq \\exp \\left(-\\frac{2\\epsilon^2}{\\sum_{i=1}^{m}(b_i-a_i)^2} \\right)\\\\\n\t& P(|S_m-\\mathbb{E}[S_m]| \\geq \\epsilon) \\leq 2\\exp \\left(-\\frac{2\\epsilon^2}{\\sum_{i=1}^{m}(b_i-a_i)^2} \\right)\n\t\\end{align}\t\n\\end{theorem}\n\n\\begin{theorem}[McDiarmid's Inequality]\n\tLet $X_1,...,X_m \\in \\mathcal{X}^m$ be a set of $m \\geq 1$ independent random variables and assume that there exist $c_1,...,c_m > 0$ such that $f: \\mathcal{X} \\to \\mathbb{R}$ satisfies the following conditions:\n\t$$|f(x_1,...,x_i,...,x_m)-f(x_1,...,x\\prime_i,...,x_m)| \\leq c_i$$\n\tfor all $i \\in [1,m]$ and any points $x_1,...,x_m,x\\prime_i \\in \\mathcal{X}$. Let $f(S)$ denote $f(X_1,...,X_m)$, then for all $\\epsilon > 0$, the following inequalities hold:\n\t\\begin{align}\n\t& P(f(S)-\\mathbb{E}[f(S)] \\geq \\epsilon) \\leq \\exp \\left(-\\frac{2\\epsilon^2}{\\sum_{i=1}^{m}c_i^2} \\right)\\\\\n\t& P(f(S)-\\mathbb{E}[f(S)] \\leq -\\epsilon) \\leq \\exp \\left(-\\frac{2\\epsilon^2}{\\sum_{i=1}^{m}c_i^2} \\right)\\\\\n\t& P(|f(S)-\\mathbb{E}[f(S)]| \\geq \\epsilon) \\leq 2\\exp \\left(-\\frac{2\\epsilon^2}{\\sum_{i=1}^{m}c_i^2} \\right)\n\t\\end{align}\n\\end{theorem}\n\n\\section{Empirical Risk vs True Risk}\nAs follows from the previous discussion, the technical results behind the PAC learning framework are bounds on the difference \nbetween the empirical and true risk which are uniform with respect to the element $h\\in \\mathcal{H}$, i.e. bounds on\n\\begin{equation}\n\\sup_{h\\in \\mathcal{H}} |\\hat{R}(h) - R(h)|\n\\end{equation}\nThe quantity $\\hat{R}(h)$ is a random variable, so we really need to consider\n\\begin{equation}\n\\mathbb{E}(\\sup_{h\\in \\mathcal{H}} |\\hat{R}(h) - R(h)|)\n\\end{equation}\nand\n\\begin{equation}\n\\mathbb{P}(\\sup_{h\\in \\mathcal{H}} |\\hat{R}(h) - R(h)| \\geq \\epsilon)\n\\end{equation}\nIn particular, what we want is a bound of the form\n\\begin{equation}\n\\mathbb{P}(\\sup_{h\\in \\mathcal{H}} |\\hat{R}(h) - R(h)| \\geq \\epsilon) \\leq C(\\epsilon, m)\n\\end{equation}\nwhere $m$ is the number of samples and the function $C(\\epsilon, m)$ decays rapidly as $m\\rightarrow \\infty$.\n\n\\subsection{Guarantees for finite hypothesis sets-consistent case}\nWe say the hypothesis $h_S$ returned by the algorithm is consistent, if it admitts no error on\nthe training sample $S$. In this section, we present a general sample complexity\nbound, or equivalently, a generalization bound, for consistent hypotheses, in the\ncase where the cardinality $\\mathcal{H}$ of the hypothesis set is finite.\n\\begin{lemma}\n\tFor the special case: $\\mathcal{H} = \\{h\\}$, and $h$ is consistent with sample S, which means $\\hat{R}_S (h)=0$, then we have:\n\t$$P \\left( \\hat{R}_S (h)=0, R(h) \\geq \\epsilon \\right) \\leq \\exp(-m\\epsilon)$$\n\\end{lemma}\n\\begin{proof}\n\t\\begin{align}\n\tP \\left( \\hat{R}_S (h)=0, R(h) \\geq \\epsilon \\right) &\\leq P\\left( \\hat{R}_S (h)=0 \\big| R(h) \\geq \\epsilon \\right) \\\\\n\t&= (1-R(h))^m \\big|_{R(h) \\geq \\epsilon} \\\\\n\t&\\leq (1-\\epsilon)^m \\\\\n\t&\\leq \\exp(-m\\epsilon) \n\t\\end{align}\n\\end{proof}\n\n\\begin{theorem}[Learning bounds-Finite $\\mathcal{H}$, consistent case]\n\tLet $\\mathcal{H}$ be a finite set of functions mapping from $\\mathcal{X}$ to $\\{0,1\\}$. Let $\\mathcal{A}$ be an algorithm that for any target function $f \\in \\mathcal{H}$ and i.i.d. sample $S$ returns a consistent hypothesis $h_S$: $\\hat{R}_S (h_S)=0$. Then for any $\\epsilon, \\delta > 0 $, the inequality $P_{S \\sim D^m} (R(h_S) \\leq \\epsilon ) \\geq 1-\\delta$ holds if:\n\t\\begin{equation}\n\tm \\geq \\frac{1}{\\epsilon}(\\log(|H|) + \\log \\frac{1}{\\delta})\n\t\\end{equation}\n\tThis sample complexity result damits the following equivalent statement as a generalization bound: for any $\\epsilon, \\delta > 0 $, with probability at least $1-\\delta$,\n\t\\begin{equation}\n\tR(h_S) \\leq \\frac{1}{m} (\\log(|H|) + \\log \\frac{1}{\\delta})\n\t\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\n\tFix $\\epsilon > 0$. We do not know which consistent hypothesis $h_S \\in \\mathcal{H}$ is selected by the algorithm $\\mathcal{A}$. This hypothesis further depends on the training sample $S$. Therefore, we need to give a uniform convergence bound, that is, a bound that holds for the set of all consistent hypotheses, which a fortiori includes $h_S$. Thus we will bound the probability that some $h \\in \\mathcal{H}$ would be consistent and have error more than $\\epsilon$:\n\t\\begin{align}\n\tP\\left( R(h_S) \\geq \\epsilon \\right) &\\leq\n\tP\\left( \\exists h \\in \\mathcal{H}: \\hat{R}_S (h)=0, R(h) \\geq \\epsilon \\right) \\\\\n\t&= P\\left(\\bigcup_{h \\in \\mathcal{H}} \\{ \\hat{R}_S (h)=0, R(h) \\geq \\epsilon \\} \\right) \\\\\n\t&\\leq \\sum_{h \\in \\mathcal{H}} P\\left( \\hat{R}_S (h)=0, R(h) \\geq \\epsilon \\right) \n\t&(Union\\ bound)\\\\\n\t&\\leq |H|\\exp(-m\\epsilon)      \t\n\t&(By\\ Lemma1)\t\n\t\\end{align}\n\tSetting the right-handa side to be equal to $\\delta$ and solving for $\\epsilon$ concludes the proof.\n\\end{proof}\n\\begin{example}[Conjunction of boolean literals]\n\tConsider $\\mathcal{X}=\\{0,1\\}^n$, $\\mathcal{Y}=\\{positive, negative\\}$, and the fucntion class $C_n$ of conjunctions of at most n boolean literals $x_1,...,x_n$. A Boolean literal is either a variable $x_i$, $i\\in [1, n]$, or its negation $\\bar{x_i}$. For $n=4$, an example is the conjunction: $x_1\\wedge \\bar{x_2}\\wedge x_4$, where $\\bar{x_2}$ denotes the negation of the Boolean literal $x_2$. $(1,0,0,1)$ is a positive example for this conjunction while $(1,0,0,0)$ is a negative example.\\\\\n\t\n\tA simple algorithm for finding a consistent hypothesis is thus based on positive examples and consists of the following: for each positive example $(b1,., bn)$, if $b_i=1$ then $\\bar{x_i}$ is ruled out as a possible literal in the function class and if $b_i=0$ then $x_i$ is ruled out. The conjunction of all the literals not ruled out is thus a hypothesis consistent with the target. The figure below shows an example training sample as well as a consistent hypothesis for the case $n=6$.\\\\\n\t\n\tWe have $|\\mathcal{H}|=|C_n|=3^n$, since each literal can be included positively, with\n\tnegation, or not included. Plugging this into the sample complexity bound for\n\tconsistent hypotheses yields the following sample complexity bound for any $\\epsilon>0$ and $\\delta>0$:\n\t\\begin{equation}\n\tm>\\frac{1}{\\epsilon}\\left((\\log3)n+\\log\\frac{1}{\\delta}\\right)\n\t\\end{equation}\n\tThus, the class of conjunctions of at most $n$ Boolean literals is PAC-learnable. Note\n\tthat the computational complexity is also polynomial, since the training cost per\n\texample is in $O(n)$. For $\\delta=0.02$, $\\epsilon=0.1$, and $n=10$, the bound becomes $m\\geq149$. Thus, for a labeled sample of at least $149$ examples, the bound guarantees $99\\%$\n\taccuracy with a confidence of at least $98\\%$.\n\t\n\t\\begin{figure}[htbp]\n\t\t\\centering\n\t\t\\includegraphics[width=0.6\\linewidth]{6DL/figures/Boolean.png}\n\t\t\\caption{Boolean literals}\n\t\t\\label{Boolean literals}\n\t\\end{figure}\n\t\n\t\\noindent Figure: Each of the first six rows of the table represents a training example with\n\tits label, $+$ or $-$, indicated in the last column. The last row contains $0$(respectively\n\t1)in column if the $ith$ entry is $0$(respectively 1) for all the positive examples\n\tIt contains $\"?\"$ if both $0$ and $1$ appear as an $ith$ entry for some positive example\n\tThus, for this training sample, the hypothesis returned by the consistent algorithm\n\tdescribed in the text is $\\bar{x_1}\\wedge x_2 \\wedge x_5 \\wedge x_6$.\n\\end{example}\n\\begin{example}[Universal concept class]\n\tConsider $\\mathcal{X}=\\{0,1\\}^n$, of all Boolean vectors with n components, $\\mathcal{Y}=\\{positive, negative\\}$, and $\\mathcal{H}$ be the function class of all functions from $\\mathcal{X}$ to $\\mathcal{Y}$. Is this fucntion class PAC-learnable?\n\tTo guarantee a consistent hypothesis the hypothesis class must include all the fucntions. Since $|\\mathcal{H}|=2^{(2^n)}$. Theorem 9 gives the following sample complexity bound:\n\t\\begin{equation}\n\tm>\\frac{1}{\\epsilon}\\left((\\log2)2^n+\\log\\frac{1}{\\delta}\\right)\n\t\\end{equation}\n\tHere, the number of training samples required is exponential in $n$, which is the cost\n\tof the representation of a point in $\\mathcal{X}$. Thus, PAC-learning is not guaranteed by\n\tthe theorem.\n\\end{example}\n\n\\subsection{Guarantees for finite hypothesis sets-inconsistent case}\nIn the most general case, there may be no hypothesis in $\\mathcal{H}$ consistent with the labeled training sample. This, in fact, is the typical case in practice, where the learning problems may be somewhat difficult or the concept classes more complex than the hypothesis set used by the learning algorithm. However, inconsistent hypotheses with a small number of errors on the training sample can be useful and as we shall see, can benefit from favorable guarantees under some assumptions. This section presents learning guarantees precisely for this inconsistent case and finite hypothesis sets.\\\\\nTo derive learning guarantees in this more general setting, we will use Hoeffding's inequality or the following corollary, which relates the generalization error and empirical error of a single hypothesis.\n\n\\begin{corollary}\n\tFix $\\epsilon > 0$ and let $S$ denote an i.i.d sample of size $m$. Then for any $h$ mapping  from $\\mathcal{X}$ to $\\{0,1\\}$, the following inequalities hold:\n\t\\begin{align}\n\t& P_{S\\sim D^m} (\\hat{R}_S (h)-R(h) \\geq \\epsilon) \\leq \\exp(-2m\\epsilon^2)\\\\\n\t& P_{S\\sim D^m} (\\hat{R}_S (h)-R(h) \\leq-\\epsilon) \\leq \\exp(-2m\\epsilon^2)\\\\\n\t& P_{S\\sim D^m} (|\\hat{R}_S (h)-R(h)| \\geq \\epsilon) \\leq 2\\exp(-2m\\epsilon^2)\n\t\\end{align}\n\t\\begin{proof}\n\t\tThe results follows immediately by Hoeffding's inequality.\n\t\\end{proof}\n\\end{corollary}\n\n\\begin{corollary}[Generalization bound-single hypothesis]\n\tFix a hypothesis $h$ mapping  from $\\mathcal{X}$ to $\\{0,1\\}$. Then for any $\\delta > 0$, the following inequality holds with probability at least $1-\\delta$:\n\t$$R(h) \\leq \\hat{R}_S(h) + \\sqrt{\\frac{\\log \\frac{1}{\\delta}}{2m}}$$\n\\end{corollary}\n\\begin{proof}\n\tSetting the right-hand side of (2.16) to be equal to $\\delta$ and solving for $\\epsilon$ yields immediately the bound.\n\\end{proof}\n\\noindent This is more general but not as tight as the previous one since it does not utilize the fact $\\hat{R}_S(h)=0$.\\\\\n\\begin{example}[Tossing a coin]\n\tImagine tossing a biased coin that lands heads with probability $p$, and let our\n\thypothesis be the one that always guesses heads. Then the true error rate is $R(h)=p$\n\tand the empirical error rate $\\hat{R}(h)=\\hat{p}$ where $\\hat{p}$ is the empirical probability of heads based on the training sample drawn i.i.d. Thus, corollary 6 guarantees with\n\tprobability at least $1-\\delta$ that\n\t\\begin{equation}\n\t|p-\\hat{p}| \\leq \\sqrt{\\frac{\\log\\frac{2}{\\delta}}{2m}}\n\t\\end{equation}\n\tTherefore, if we choose $\\delta=0.02$ and use a sample of size $500$, with probability at\n\tleast $98\\%$, the following approximation quality is guaranteed for $\\hat{p}$:\n\t\\begin{equation}\n\t|p-\\hat{p}| \\leq \\sqrt{\\frac{\\log(10)}{1000}} \\approx 0.048\n\t\\end{equation}\n\\end{example}\n\nAlthough the result of Corollary 6 is very simple, it has very limited practical meaning. The main reason is that it only applies to a single fixed function h. Essentially, it says that for each fixed function $h$, there is a set $\\mathcal{S}$ of samples(whose measure $P(\\mathcal{S}) \\geq 1-\\delta$) for all $S\\in \\mathcal{S}$, $|\\hat{R}_S(h)-R(h)|$ is bounded. However, such $\\mathcal{S}$ sets could be different for different functions.\nThus, as in the proof for the consistent case, we need to derive a uniform convergence bound, that is a bound that holds with high probability for all hypotheses $h \\in \\mathcal{H}$. since:\n\\begin{equation}\n\\hat{R}_S(\\hat{h}_S)-R_S(\\hat{h}_S) \\leq \\sup_{h \\in \\mathcal{H}}(\\hat{R}_S(h)-R(h))\n\\end{equation}\nWe proceed to explain how one can obtain uniform bounds.\\\\\n\n\\begin{theorem}[Learning bound-finite $\\mathcal{H}$, inconsistent case]\n\tLet $\\mathcal{H}$ be a finite hypothesis set. Then, for any $\\delta>0$ with probability at least $1-\\delta$ the following inequality holds:\n\t$$\\forall h \\in \\mathcal{H}, \\quad |R(h) - \\hat{R}_S(h)| \\leq \\sqrt{\\frac{\\log |\\mathcal{H}| + \\log \\frac{2}{\\delta}}{2m}}$$\n\\end{theorem}\n\n\\begin{proof}\n\t\\begin{align}\n\tP\\left( \\exists h \\in \\mathcal{H}: |\\hat{R}_S (h)-R(h)| \\geq \\epsilon \\right)\n\t&= P\\left(\\bigcup_{h \\in \\mathcal{H}} \\{ |\\hat{R}_S (h)-R(h)| \\geq \\epsilon \\} \\right) \\\\\n\t(Union\\ bound)&\\leq \\sum_{h \\in \\mathcal{H}} P\\left( |\\hat{R}_S (h)-R(h)| \\geq \\epsilon \\right) \\\\\n\t&\\leq 2|H|\\exp(-2m\\epsilon^2)      \t\n\t\\end{align}\n\tSetting the right-hand side to be equal to $\\delta$ completes the proof.\n\\end{proof}\n\nSince this is a uniform upper bound, it can be applied to $\\hat{h}_S$, as (14) says. \\\\\n\nThus for finite hypothesis set $\\mathcal{H}$,\n\\begin{equation}\nR(h) \\leq \\hat{R}_S(h) + O\\left( \\sqrt{\\frac{\\log |\\mathcal{H}|}{2m}} \\right)\n\\end{equation}\n\nNote that the bound suggests seeking a trade-off between reducing the empirical error versus controlling the size of the hypothesis set: a larger hypothesis set is penalized by the second term but could help reduce the empirical error, that is the first term. But, for a similar empirical error, it suggests using a smaller hypothesis set.\\\\\n\n\nAlso note that we could also bound the expected value of $\\mathbb{E}[\\sup_{h \\in \\mathcal{H}} |R(h)-\\hat{R}_S(h)|]$ by using the fact that for any nonnegative random variable $Z$, $\\mathbb{E}[Z] = \\int_{0}^{\\infty} P(Z>t)dt$.\n\nFrom the above PAC learning examples we can see that\n\\begin{itemize}\n\t\\item It requires assumptions on data generation, i.e. samples are i.i.d.\n\t\\item The error bounds are valid with respect to repeated samples of training data.\n\t\\item For a fixed function we roughly have $|R(h)-\\hat{R}_S(h)| \\approx \\frac{1}{\\sqrt{m}}$.\n\t\\item If $\\mathcal{H}=n$ then $\\sup_{h \\in \\mathcal{H}} |R(h)-\\hat{R}_S(h)| \\approx \\sqrt{\\frac{\\log n}{m}}$. The term $\\log n$ can be thought as the complexity of the hypothesis space $\\mathcal{H}$.\n\\end{itemize}\n\nThere are several things which can be improved.\n\\begin{itemize}\n\t\\item \tHoeffding's inequality does not utlize the variance information. So the results could be improved by\n\tutilizing such information.\n\t\\item The union bound could be quite loose. For instance, it is as bad as if all the functions in $\\mathcal{H}$ were independent.\n\t\\item \tThe supremum over $\\mathcal{H}$ might be too conservative.\n\\end{itemize}\n\nThe bound in Example 2 becomes meaningless when $n$ is infinite. The following example generalizes it to the case of coutably many classifiers.\n\n\\begin{corollary}[countable number of classifiers]\n\tConsider the case $\\mathcal{H}=\\{h_1,h_2,...,h_n,...\\}$. Since we\n\tneed to bound the probability of the set of misleading samples (which could mislead any $h\\in \\mathcal{H}$ by $\\delta$, we\n\tneed budget the proability of being misled by $h_n$ to $\\omega_n\\delta$ such that $\\sum_{k=1}^{\\infty} \\omega_k \\leq 1$. So in order to apply the lemma, $\\epsilon$ must be chosen related to $h \\in \\mathcal{H}$, which is: \n\t\\begin{equation}\n\tP\\left( \\exists k \\in \\mathbb{N}: R(h_k)- \\hat{R}_S (h_k) \\geq \\epsilon_k \\right) \\leq \\delta\n\t\\end{equation}\n\twe only need to make sure that for any k,\n\t\\begin{equation}\n\tP\\left( R(h_k)- \\hat{R}_S (h_k) \\geq \\epsilon_k \\right) \\leq \\omega_k\\delta\n\t\\end{equation}\n\tSince,\n\t\\begin{align}\n\tP\\left( \\exists k \\in \\mathbb{N}: R(h_k)- \\hat{R}_S (h_k) \\geq \\epsilon_k \\right) &= P\\left( \\bigcup_{k=1}^{\\infty} \\{R(h_k)- \\hat{R}_S (h_k) \\geq \\epsilon_k \\} \\right) \\\\\n\t&\\leq \\sum_{k=1}^{\\infty} P\\left( R(h_k)- \\hat{R}_S (h_k) \\geq \\epsilon_k \\right) \\\\\n\t&= \\sum_{k=1}^{\\infty} \\omega_k\\delta \\\\\n\t&\\leq \\delta\n\t\\end{align}\n\tAgain the first inequality comes from the Bonferroni inequality. By a similar argument, we solve $\\epsilon_k$ by setting\n\t$\\exp(-2m\\epsilon_k^2)= \\omega_k\\delta$ which leads to $\\epsilon_k = \\sqrt{\\frac{1}{2m} \\log\\frac{1}{\\omega_k\\delta}}$. Thus we have with probability $(1-\\delta)$,\n\t\\begin{equation}\n\t\\forall k \\in \\mathbb{N}, R(h_k) \\leq \\hat{R}_S(h_k)+ \\sqrt{\\frac{\\log \\frac{1}{\\omega_k}+ \\log \\frac{1}{\\delta}}{2m}} \n\t\\end{equation}\n\\end{corollary}\n\nNote that the statement is probabilistic over the the samples drawn, so that the $\\omega_k$'s can not depend upon the samples drawn. This means $\\omega_k$'s have to be specified before seeing the training data, otherwise the result will not hold. One\nway to interpret $\\omega_k$'s is that they can be thought as the \"prior\" knowledge about the functions(such as in Bayesian inference), which means that if you had some prior guess as to which predictors are likely be the ERM predictor (of course this guess can not depend on the data), then you should choose these values of $\\omega_k$'s to be large in the theorem.\\\\\n\n\\section{Infinite Hypothesis Class}\n\\subsection{Growth Function And VC Dimension}\nWe have considered the case when $\\mathcal{H}$ is finite or countably infinite. In practice, however, the function class\n$\\mathcal{H}$ could be uncountable. Under this situation, the previous method does not work. The key idea is to group\nfunctions based on the sample\nGiven a sample $S=\\{(x_1,y_1),..,(x_n,y_n)\\}$, Consider the set\n$$\\mathcal{H}_{x_1,...,x_n} = \\{(h(x_1),...,h(x_n)) : h\\in \\mathcal{H}\\} $$\nThe size of this set is the total number of possible ways that $(x_1,...,x_n)$ can be classified. For binary classification the cardinality of this set is always finite, no matter how large $\\mathcal{H}$ is.\n\\begin{definition}[Growth Function]\n\tThe growth function is the macimum number of wags into which n points\n\tcan be classified by the function class:\n\t$$G_\\mathcal{H}(n) = \\sup_{\\{x_1,...,x_n\\} \\in \\mathcal{X}^n} |\\mathcal{H}_{x_1,...,x_n}|$$\n\\end{definition}\n\\noindent Growth function can be thought as a measure of the \"size\" for the class of functions $\\mathcal{H}$. Several facts about the growth function:\n\\begin{itemize}\n\t\\item When $\\mathcal{H}$ is finite, we always have $G_\\mathcal{H}(n) \\leq |\\mathcal{H}|=m$\n\t\\item \tSince $h(x)\\in \\{0,1\\}$, we have $G_\\mathcal{H}(n) \\leq2^n$. If $G_\\mathcal{H}(n) =2^n$, then there is a set of $n$ points such that the class of functions $\\mathcal{H}$ can generate any possible classification result on these points.\n\\end{itemize}\t\n\\begin{definition}[Shatterring]\n\tWe say that $\\mathcal{H}$ shatters $\\{x_1,...,x_n\\}$ if $|\\mathcal{H}_{x_1,...,x_n}|=2^n$\n\\end{definition}\n\\begin{definition}[VC Dimension]\n\tThe VC dimension of a class $\\mathcal{H}$ is the cardinality of the largest set that can be shattered by $\\mathcal{H}$:\n\t$$dim_{VC}(\\mathcal{H})= \\sup\\{n : G_\\mathcal{H}(n)=2^n\\}$$\n\\end{definition}\nNote that, by definition, if $dim_{VC}(\\mathcal{H})=d$, there exists a set of size $d$ that can\nbe fully shattered. But, this does not imply that all sets of size $d$ or less are fully\nshattered, in fact, this is typically not the case.\\\\\nTo further illustrate this notion, we will examine a series of examples of hypothesis\nsets and will determine the VC-dimension in each case. To compute the VC dimension we will typically show a lower bound for its value and then a matching upper bound. To give a lower bound $d$ for $dim_{VC}(\\mathcal{H})$, it suffices to show that a set $S$ of cardinality $d$ can be shattered by $\\mathcal{H}$. To give an upper bound, we need to prove that no set $S$ of cardinality $d+1$ can be shattered by $\\mathcal{H}$, which is typically more difficult.\\\\\n\\begin{example}\n\tConsider all functions of the form $\\mathcal{H}=\\{h(x)=I(x\\leq \\theta), \\theta \\in \\mathbb{R}\\}$. Then it can shatter 2 points, but for any three points it cannot shatter. So the VC dimension in this case is 2.\n\\end{example}\n\\begin{example}\n\tConsider all linear classifiers in $\\mathbb{R}^2$. In this case, all linear classifiers can\n\tshatter a set of 3 points. No set of four points can be shattered by linear classifiers. So the VC dimension of the hyperplanes in $\\mathbb{R}^2$ is 3.\n\\end{example}\n\\begin{example}\n\tConsider all linear classifiers in a p-dimensional Euclidean space, i.e. $\\mathcal{X}=\\mathbb{R}^p$. Given $x_1,...,x_n \\in \\mathbb{R}^p$, we define the augmented data vector:\\\\\n\t$$z_i=[1,x_i]^T \\in \\mathbb{R}^{p+1}, i=1,...,n $$\n\tThen the set of all linear classifiers can be written as\n\t$$H=\\{h:h(z)=sgn(\\theta^Tz),\\theta\\in \\mathbb{R}^{p+1}\\}$$\n\tDefine\n\t$$Z=[z_1,...,z_n] \\in \\mathbb{R}^{(p+1)\\times n}$$\n\tand we argue that $x_1,...x_n$ is shattered by $\\mathcal{H}$ if and only if the n columns of Z are linearly independent.\n\t\\begin{itemize}\n\t\t\\item If columns $z_1,...,z_n$ are linearly independent, we have $n<p+1$ and for any possible classification assignment $y \\in \\{\\pm1\\}^n$ the linear system $Z^T \\theta=y$ must have a solution. Thus, there is a linear classifier in $\\mathcal{H}$ (by taking the solution of the linear equation) which can produce such arbitrary class assignment $y$. Thus $x_1,...,x_n$ can be shattered by $\\mathcal{H}$.\n\t\t\\item Suppose $x_1,...,x_n$ are shattered by $\\mathcal{H}$. \n\t\tThis means that for each classification $y\\in \\{\\pm1\\}^n$, there exists a \n\t\t$\\theta_y\\in \\mathbb{R}^{d+1}$ such that $sgn(\\theta_y\\cdot x_i) = y_i$. It follows that the range of the matrix\n\t\t$Z^T$ intersects every quadrant in $\\mathbb{R}^n$. This implies that the matrix $Z^T$ has full rank (i.e. its\n\t\trange must be all of $\\mathbb{R}^n$) and thus the columns of $Z$ are linearly independent.\n\t\\end{itemize}\n\tSince if $n>p+1$ it is not possible to have $Z$'s columns linearly independent, but for $n<p+1$ we can always find such $x_1,...x_n$ to make it happen, we have $dim_{VC}(\\mathcal{H})=p+1$.\n\\end{example}\nA somewhat surprising result shows that the growth function $G_{\\mathcal{H}}$ either grows exponentially in $n$ or only increases polynomially in $n$, depends on whether $n$ is greater than its VC dimension or not.\n\\begin{theorem}[Sauer]\n\tIf $\\mathcal{H}$ is a class of functions with binary outputs and its VC dimension is $d=dim_{VC}(\\mathcal{H})$, Then for all $n \\in \\mathbb{N}$,\n\t\\begin{equation}\n\tG_\\mathcal{H}(n) \\leq \\sum_{i=0}^{d}\\binom{n}{i}\n\t\\end{equation}\n\\end{theorem}\n\\begin{proof}\n We prove this by induction on $d$ and $n$. \n \n For the base case, we note that if $n \\leq d$, the statement of the theorem is vacuously true, and if $d = 0$,\n it is clear that $\\mathcal{H}$ consists of a single classification function and thus the theorem holds as well.\n \n Now assume that $n > d > 0$. Let $x_1,...,x_n\\in \\mathcal{X}$ be an arbitrary set of points. Consider the following\n two subsets of $\\{\\pm1\\}^{n-1}$.\n \\begin{equation}\n  S_1 = \\{y\\in \\{\\pm 1\\}^{n-1}:\\exists h\\in \\mathcal{H}~\\text{s.t.}~y_i = h(x_i),~i = 1,...,n-1\\} \n \\end{equation}\n  \\begin{equation}\n  S_2 = \\{y\\in \\{\\pm 1\\}^{n-1}:\\exists h_1, h_2\\in \\mathcal{H}~\\text{s.t.}~y_i = h_1(x_i) = h_2(x_i),~h_1(x_n) = 1,~h_2(x_n) = -1\\} \n \\end{equation}\n Here $S_1$ is the set of classifications which occur for $x_1,...,x_{n-1}$ and $S_2$ is the set of \n classifications of $x_1,...,x_{n-1}$ for which $x_n$ can be either $\\pm 1$. It is clear that\n \\begin{equation}\n  |\\mathcal{H}_{x_1,...,x_n}| = |S_1| + |S_2|\n \\end{equation}\n since $S_1$ is the set of classifications of the first $n-1$ points which occur and $S_2$ is the set of classifications\n of the first $n-1$ points which occur twice (once with $x_n = 1$ and once with $x_n = -1$). Moreover, at most $d$ points\n can be shattered by $S_1$ and at most $d-1$ points can be shattered by $S_2$ since $\\mathcal{H}$ shatters at most $d$ points\n (any points shattered by $S_2$ would be shattered together with $x_n$ by $\\mathcal{H}$). The inductive hypothesis then implies\n that\n \\begin{equation}\n  |S_1| \\leq \\sum_{i=0}^{d}\\binom{n-1}{i},~|S_2| = \\sum_{i=0}^{d-1}\\binom{n-1}{i}\n \\end{equation}\n Thus we get\n \\begin{equation}\n  |\\mathcal{H}_{x_1,...,x_n}| = |S_1| + |S_2| \\leq \\sum_{i=0}^{d}\\binom{n-1}{i} + \\binom{n-1}{i-1} = \\sum_{i=0}^{d}\\binom{n}{i}\n \\end{equation}\n Since $x_1,...,x_n$ were arbitrary points, we see that\n \\begin{equation}\n  G_\\mathcal{H}(n) \\leq \\sum_{i=0}^{d}\\binom{n}{i}\n \\end{equation}\n as desired.\n\\end{proof}\nFrom this, we deduce the following polynomial bound in $n$.\n\\begin{corollary}\n\tLet $\\mathcal{H}$ be a hypothesis set with $dim_{VC}(\\mathcal{H})=d$. Then for all $n\\geq d $,\n\t\\begin{equation}\n\tG_\\mathcal{H}(n) \\leq \\left(\\frac{en}{d} \\right)^d = O(n^d)\n\t\\end{equation}\n\\end{corollary}\n\\begin{proof}\n\tThe proof begins by using Sauers lemma.\n\t\\begin{align}\n\tG_\\mathcal{H}(n) &\\leq \\sum_{i=0}^{d}\\binom{n}{i} \\\\\n\t&\\leq \\left(\\frac{n}{d}\\right)^d \\sum_{i=0}^{d}\\binom{n}{i} \\left(\\frac{d}{n}\\right)^i \\\\\n\t&\\leq \\left(\\frac{n}{d}\\right)^d \\sum_{i=0}^{n}\\binom{n}{i} \\left(\\frac{d}{n}\\right)^i \\\\\n\t&= \\left(\\frac{n}{d}\\right)^d \\left(1+ \\frac{d}{n}\\right)^n \\\\\n\t&\\leq \\left(\\frac{en}{d}\\right)^d\n\t\\end{align}\n\\end{proof}\n\n\\subsection{Generalization Bound For Binary Classification}\nWe introduce the generalization error bound which utilizes the growth function of $\\mathcal{H}$ or VC dimension of $\\mathcal{H}$ instead of the naive cardinality $|\\mathcal{H}|$. Recall that we are trying to determine how fast\n\\begin{equation}\n\\mathbb{P}_{(X_1,Y_1),...,(X_n,Y_n)} \\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)|>\\epsilon \\right)\n\\end{equation}\ndecays as $n\\to \\infty$. We are also assuming that the loss function $\\ell$ is bounded\nThe problem when the set $\\mathcal{H}$ is finite is covered in the notes, it is simply an\napplication of the union bound. The famous trick which solves the problem\nwhen $\\mathcal{H}$ is uncountably infinite is called the symmetrization lemma. In order to\nsimplify notation,I will denote by $S = \\{(X_1,Y_1),...,(X_n,Y_n) \\}$ the random data samples.\n\\begin{lemma}[Symmetrization lemma]\n\tLet $\\epsilon_1,...,\\epsilon_n$ be iid random variables which take the values $\\pm1$ each with probability $\\frac{1}{2}$ (i.e. random signs) and let $\\Phi : \\mathbb{R}\\to \\mathbb{R}$ be a convex function. Then\n\t\\begin{equation}\n\t\\mathbb{E}_S\\Phi\\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)| \\right) \\leq 2\\mathbb{E}_S\\mathbb{E}_{\\epsilon_1,...,\\epsilon_n} \\Phi \\left(\\sup_{h \\in \\mathcal{H}} \\frac{1}{n} \\bigg|\\sum_{i=1}^{n}\\epsilon_i \\ell(y_i,h(x_i))\\bigg| \\right)\n\t\\end{equation}\n\\end{lemma}\n\n\\begin{proof}\n\tThe proof proceeds by rewriting the expectation as follows\n\t\\begin{equation}\n\t\\mathbb{E}_S\\Phi\\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)| \\right)=\\mathbb{E}_S\\Phi\\left(\\sup_{h \\in \\mathcal{H}}\\frac{1}{n} \\bigg|\\sum_{i=1}^{n}\\epsilon_i \\ell(y_i,h(x_i))-\\mathbb{E}_{(X'_i,Y'_i)} \\ell(y'_i,h(x'_i))\\bigg| \\right)\n\t\\end{equation}\n\twhere $(X'_i,Y'_i)$ are i.i.d. with distribution $(X,Y)$. This formula holds because by definition\n\t\\begin{equation}\n\t\\mathbb{E}_{(X'_i,Y'_i)} \\ell(y'_i,h(x'_i)) = R(h)\n\t\\end{equation}\n\tThe$(x'_i,y'_i)$ are called ghost samples. We can rewrite the above as\n\t\\begin{equation}\n\t\\mathbb{E}_S\\Phi\\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)| \\right)=\\mathbb{E}_S\\Phi\\left(\\sup_{h \\in \\mathcal{H}}\\frac{1}{n} \\bigg|\\mathbb{E}_{S'} \\sum_{i=1}^{n}\\epsilon_i \\ell(y_i,h(x_i))-\\ell(y'_i,h(x'_i)) \\bigg| \\right)\n\t\\end{equation}\n\twhere $S'$ represents the distribution of the ghost samples. By the triangle\n\tinequality, we can pull the expectation out of the absolute value to get\n\t\\begin{equation}\n\t\\mathbb{E}_S\\Phi\\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)| \\right) \\leq \\mathbb{E}_S\\Phi\\left(\\sup_{h \\in \\mathcal{H}} \\mathbb{E}_{S'} \\frac{1}{n} \\bigg| \\sum_{i=1}^{n}\\epsilon_i \\ell(y_i,h(x_i))-\\ell(y'_i,h(x'_i)) \\bigg| \\right)\n\t\\end{equation}\n\tWe can also pull the expectation out of the supremum. If you wish, this can be\n\tviewed as an application of Jensen's inequality(or the triangle inequality, which follows from Jensen's inequality). Again by Jensen's inequality we can move the expectation outside of $\\Phi$(since $\\Phi$ is assumed to be convex). This yields\n\t\\begin{equation}\n\t\\mathbb{E}_S\\Phi\\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)| \\right) \\leq \\mathbb{E}_S\\mathbb{E}_{S'}\\Phi\\left(\\sup_{h \\in \\mathcal{H}} \\frac{1}{n} \\bigg| \\sum_{i=1}^{n}\\epsilon_i \\ell(y_i,h(x_i))-\\ell(y'_i,h(x'_i)) \\bigg| \\right)\n\t\\end{equation}\n\tNow comes the incredible trick. We observe the following symmetry between $S$ and $S'$. All of the samples in $S$ and $S'$ are iid with the same distribution! This means that we can swap the i-th sample in $S$ with the i-th sample in $S'$ and the distribution of both, and thus the expectation, remain\tunchanged. Furthermore, this swapping can be done for any subset of indices $\\{i_1,...,i_k\\}$, and the expectation still remains unchanged.\n\t\n\tWe now choose a uniformly random subset of indices, perform this swapping\n\tfor the subset, and take the expectation over the random subset. Since the value\n\tof the left-hand side above is independent of where we swapped, we will get the same value\n\t\n\tWe now note that if the i-th sample in $S$ and $S'$ are swapped, then this\n\thas the effect of negating the term\n\t\\begin{equation}\n\t\\ell(y_i,h(x_i))-\\ell(y'_i,h(x'_i))\n\t\\end{equation}\n\tThis means that the random swapping procedure described above is the same\n\tas negating each term in the sum independently with probability $\\frac{1}{2}$. Putting\n\tthis together, we see that the left hand side above is equal to\n\t\\begin{equation}\n\t\\mathbb{E}_{\\epsilon_1,...,\\epsilon_n}\\mathbb{E}_{S,S'} \\Phi\\left(\\sup_{h \\in \\mathcal{H}} \\frac{1}{n} \\bigg| \\sum_{i=1}^{n}\\epsilon_i (\\ell(y_i,h(x_i))-\\ell(y'_i,h(x'_i))) \\bigg| \\right)\n\t\\end{equation}\n\twhere the $\\epsilon_i$ are random signs ($\\pm1$ with probability $\\frac{1}{2}$).\n\tFinally, we rewrite this as\n\t\\begin{equation}\n\t\\mathbb{E}_{\\epsilon_1,...,\\epsilon_n}\\mathbb{E}_{S,S'} \\Phi\\left(\\sup_{h \\in \\mathcal{H}} \\frac{1}{n} \\bigg| \\sum_{i=1}^{n}\\epsilon_i \\ell(y_i,h(x_i))- \\sum_{i=1}^{n}\\epsilon_i\\ell(y'_i,h(x'_i)) \\bigg| \\right)\n\t\\end{equation}\n\tand use the triangle inequality and the convexity of $\\Phi$ in combination with the\n\tfact that $S$ and $S'$ are identically distributed to get\n\t\\begin{equation}\n\t\\mathbb{E}_S\\Phi\\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)| \\right) \\leq \\mathbb{E}_{S}\\mathbb{E}_{\\epsilon_1,...,\\epsilon_n} \\Phi \\left(2\\sup_{h \\in \\mathcal{H}} \\frac{1}{n} \\bigg| \\sum_{i=1}^{n}\\epsilon_i (\\ell(y_i,h(x_i))\\bigg| \\right)\n\t\\end{equation}\n\tas desired.\n\\end{proof}\nSuppose now that the function $\\Phi$ is convex and non-decreasing on $[0,\\infty]$.\nThe important point of this lemma is that the random signs $\\epsilon_i$ are independent\nof the sample! This permits us to use the union bound in combination with the\ngrowth function of the function class $\\mathcal{H}$ to obtain\n\\begin{equation}\n\\mathbb{E}_{\\epsilon_1,...,\\epsilon_n} \\Phi \\left(2\\sup_{h \\in \\mathcal{H}} \\frac{1}{n} \\bigg| \\sum_{i=1}^{n}\\epsilon_i (\\ell(y_i,h(x_i))\\bigg| \\right) \\leq G_{\\mathcal{H}}(n) \\sup_{h \\in \\mathcal{H}_S} \\mathbb{E}_{\\epsilon_1,...,\\epsilon_n} \\Phi \\left( \\frac{2}{n} \\bigg| \\sum_{i=1}^{n}\\epsilon_i (\\ell(y_i,h(x_i))\\bigg| \\right)\n\\end{equation}\nWe can now choose $\\Phi$ appropriately to estimate $\\mathbb{P}_S \\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)|>\\epsilon \\right)$.\nFor instance, we choose\n\\begin{numcases}{\\Phi(x)=}\n0, & $x\\leq \\frac{\\epsilon}{2}$ \\\\\n\\frac{2}{\\epsilon}(x-\\frac{\\epsilon}{2}), & $x> \\frac{\\epsilon}{2}$\n\\end{numcases}\nThen we have that\n\\begin{equation}\n\\mathbb{P}_S \\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)|>\\epsilon \\right) \\leq \\mathbb{E}_S \\Phi \\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)| \\right)\n\\end{equation}\nand we proceed to estimate\n\\begin{equation}\n\\mathbb{E}_{\\epsilon_1,...,\\epsilon_n} \\Phi \\left( \\frac{2}{n} \\bigg| \\sum_{i=1}^{n}\\epsilon_i (\\ell(y_i,h(x_i))\\bigg| \\right)\n\\end{equation}\nusing Hoeffding's inequality. First we have\n\\begin{equation}\n\\mathbb{E}_{\\epsilon_1,...,\\epsilon_n} \\Phi \\left( \\frac{2}{n} \\bigg| \\sum_{i=1}^{n}\\epsilon_i (\\ell(y_i,h(x_i))\\bigg| \\right) = \\frac{2}{\\epsilon} \\int_{\\frac{\\epsilon}{2}}^{\\infty} \\mathbb{P}_{\\epsilon_1,...,\\epsilon_n} \\left( \\frac{2}{n} \\bigg| \\sum_{i=1}^{n}\\epsilon_i (\\ell(y_i,h(x_i))\\bigg| >\\lambda \\right) d\\lambda\n\\end{equation}\nHoeffding's inequality now implies that\n\\begin{equation}\n\\mathbb{P}_{\\epsilon_1,...,\\epsilon_n} \\left( \\frac{2}{n} \\bigg| \\sum_{i=1}^{n}\\epsilon_i (\\ell(y_i,h(x_i))\\bigg| >\\lambda \\right) \\leq 2\\exp \\left(-\\frac{n\\lambda^2}{8} \\right)\n\\end{equation}\nand then change variables to get\n\\begin{equation}\n\\mathbb{E}_{\\epsilon_1,...,\\epsilon_n} \\Phi \\left( \\frac{2}{n} \\bigg| \\sum_{i=1}^{n}\\epsilon_i (\\ell(y_i,h(x_i))\\bigg| \\right) \\leq \\frac{4}{\\epsilon}\\sqrt{\\frac{8}{n}} \\int_{\\frac{\\epsilon}{2}\\sqrt{\\frac{n}{8}}}^{\\infty} \\exp(-\\tau^2) d\\tau\n\\end{equation}\nBy bounding the Gaussian tail integral, we will obtain a bound of the form \n\\begin{equation}\n\\int_{x}^{\\infty} \\exp(-\\tau^2) d\\tau \\leq \\frac{\\exp(-x^2)}{2x}\n\\end{equation}\nwhich gives\n\\begin{equation}\n\\mathbb{E}_{\\epsilon_1,...,\\epsilon_n} \\Phi \\left( \\frac{2}{n} \\bigg| \\sum_{i=1}^{n}\\epsilon_i (\\ell(y_i,h(x_i))\\bigg| \\right) \\leq \\frac{32}{n\\epsilon^2} \\exp\\left(-\\frac{n\\epsilon^2}{32} \\right)\n\\end{equation}\nand then we get\n\\begin{equation}\n\\mathbb{P}_S \\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)|>\\epsilon \\right) \\leq G_{\\mathcal{H}}(n) \\frac{32}{n\\epsilon^2} \\exp\\left(-\\frac{n\\epsilon^2}{32} \\right)\n\\end{equation}\nNow observe that\n\\begin{equation}\n\\min\\{1,\\frac{\\exp(-x)}{x}\\} \\leq 2\\exp(-x)\n\\end{equation}\nReplace $x$ by $\\frac{32}{n\\epsilon^2}$, so we finally get \n\\begin{equation}\n\\mathbb{P}_S \\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)|>\\epsilon \\right) \\leq 2G_{\\mathcal{H}}(n) \\exp\\left(-\\frac{n\\epsilon^2}{32} \\right)\n\\end{equation}\nWe have already proved the Vapnik-Chervonenkis theorem below.\n\\begin{theorem}[Growth function generalization bound]\n\tLet $\\mathcal{H}$ be a family of functions taking values from $\\{+1, -1\\}$. Then for any $\\delta>0$, with probability at least $1-\\delta$, we have\n\t\\begin{equation}\n\t\\forall h \\in \\mathcal{H}, R(h) \\leq \\hat{R}(h)+ 4\\sqrt{\\frac{2\\log(2G_{\\mathcal{H}}(n))+2\\log\\frac{2}{\\delta}}{n}}\n\t\\end{equation}\n\\end{theorem}\n\\begin{proof}\n\tSetting $\\delta = 2G_{\\mathcal{H}}(n) \\exp\\left(-\\frac{n\\epsilon^2}{32} \\right)$ and solve $\\epsilon$ we have the result.\n\\end{proof}\nThe explicit relationship just formulated between VC-dimension and the growth\nfunction combined with the corollary of Sauer leamma leads immediately to the following generalization bounds based on the VC-dimension.\n\\begin{corollary}[VC-dimension generalization bound]\n\tLet $\\mathcal{H}$ be a family of functions taking values from $\\{+1, -1\\}$ with VC-dimension $d_{\\mathcal{H}}$. Then for any $\\delta>0$, with probability at least $1-\\delta$, we have\n\t\\begin{equation}\n\t\\forall h \\in \\mathcal{H}, R(h) \\leq \\hat{R}(h)+ 4\\sqrt{\\frac{2d_{\\mathcal{H}}\\log(\\frac{en}{d_{\\mathcal{H}}})+2\\log\\frac{4}{\\delta}}{n}}\n\t\\end{equation}\n\\end{corollary}\n\\begin{proof}\n\tSauer lemma implies that $\tG_\\mathcal{H}(n) \\leq \\left(\\frac{en}{d} \\right) ^d$, and then by replacing $G_\\mathcal{H}(n)$ by the term $\\left(\\frac{en}{d}\\right) ^d$ in Theorem 9 we got this VC-dimension generalization bound. \n\\end{proof}\nMoreover, integrating the tail distribution bound one can obtain a bound on the expectation\n\\begin{align}\n\\mathbb{E}_S \\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)| \\right) &= \\int_{0}^{\\infty}  \\mathbb{P}_S \\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)|>\\epsilon \\right) d\\epsilon \\\\\n&\\leq \\int_{0}^{\\infty} 2G_{\\mathcal{H}}(n)\\exp\\left(-\\frac{n\\epsilon^2}{32} \\right)d\\epsilon\\\\\n&=G_{\\mathcal{H}}(n) \\sqrt{\\frac{32\\pi}{n}}\n\\end{align}\nHowever this bound doesn't make sense, since $G_{\\mathcal{H}}(n)$ grows polynomially in $n$. We use another trick to obtain a bound on the expectation that makes snese.\\\\\nFor simplicity, we denote $Z=\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)|$.\n\\begin{align}\n\\mathbb{E}[Z^2] &= \\int_{0}^{\\infty} \\mathbb{P}(Z^2\\geq \\epsilon) d\\epsilon \\\\\n& = \\int_{0}^{u} \\mathbb{P}(Z^2\\geq \\epsilon) d\\epsilon + \\int_{u}^{\\infty} \\mathbb{P}(Z^2\\geq \\epsilon) d\\epsilon \\\\\n& \\leq u+    \\int_{u}^{\\infty} 2G_{\\mathcal{H}}(n) \\exp\\left(-\\frac{n\\epsilon}{32} \\right) d\\epsilon \\\\\n& = u+\\frac{64G_{\\mathcal{H}}(n)}{n}\\exp \\left(-\\frac{nu}{32}\\right)\n\\end{align}\nMinimizing the RHS respect to $u$ we have $u=\\frac{32\\log(2G_{\\mathcal{H}}(n))}{n}$. Plugging in we have $\\mathbb{E}[Z^2] \\leq \\frac{32\\log(8G_{\\mathcal{H}}(n))}{n}$.\nBy the Cauchy-Schwarz inequality we have \n\\begin{equation}\n\\mathbb{E}_S \\left(\\sup_{h \\in \\mathcal{H}}|\\hat{R}(h)-R(h)| \\right)= \\mathbb{E}[Z] \\leq \\sqrt{\\mathbb{E}[Z^2]} \\leq \\sqrt{\\frac{32\\log(8G_{\\mathcal{H}}(n))}{n}}\n\\end{equation}\n\n\\subsection{Natarajan-dimension and Natarajan's lemma}\nThere is a natural way to generalize the VC-dimension to the  non-binary functions case. A naive attempt is to simply generalize the definition of shattering, that we say $\\mathcal{H}$ shatters $S \\subset \\mathcal{X}$, if $\\mathcal{H}|_{S} = \\mathcal{Y}^{S}$. However, this condition is too strong that will not lead to tight bounds on the hypothesis set complexity. For example, in the non-binary case, we take the hypothesis set $\\mathcal{H}$ to be $\\mathcal{H} = (\\mathcal{Y} \\backslash \\{l_0\\})^{\\mathcal{X}}$, which means $\\mathcal{H}$ only leave the label $l_0$ out but includes every function else. In this case, $\\mathcal{H}$ is capable to classify while it is dimension is $0$ which is unresonable. \n\nForgetting this naive definition, we recall two alternative generalizations, introduced by \\textbf{Natarajan(1989)}. In both definition, we reduce the requirement of shattering, which only needs $\\mathcal{H}$ contains a function whose behavior on $T$ differs from its behavior on $S\\backslash T$, where $T$ and $S\\backslash T$ is any partition of $S$. The two dimensions differ in how \"different behavior\" is defined.\n\\begin{definition}[Graph dimension]\n\tLet $\\mathcal{H} \\subset \\mathcal{Y}^{\\mathcal{X}}$ be a hypothesis set and let $S \\subset \\mathcal{X}$. We say that $\\mathcal{H}$ G-shatters $S$ if there exists an $f: S\\to \\mathcal{Y}$ such that for every $T\\subset S$, there is a $g \\in \\mathcal{H}$ such that\n\t\\begin{equation}\n\t\\forall x \\in T, g(x)=f(x), \\quad and \\quad \\forall x \\in S\\backslash T, g(x)\\ne f(x).\n\t\\end{equation}\n\tThe graph dimension of $\\mathcal{H}$, denoted by $d_G(\\mathcal{H})$, is the maximal cardinality of a set that is G-shattered by $\\mathcal{H}$. More precisely:\n\t\\begin{equation}\n\td_G(\\mathcal{H}) = \\sup \\{|S| : S \\subset \\mathcal{X} \\text{ is G-shatterd by } \\mathcal{H}\\}\n\t\\end{equation} \n\\end{definition}\n\n\\begin{definition}[Natarajan dimension]\n\tLet $\\mathcal{H} \\subset \\mathcal{Y}^{\\mathcal{X}}$ be a hypothesis set and let $S \\subset \\mathcal{X}$. We say that $\\mathcal{H}$ N-shatters $S$ if there exists $f_1, f_2 : S\\to \\mathcal{Y}$ such that $\\forall y \\in S, f_1(y)\\ne f_2(y)$, and for every $T\\subset S$, there is a $g \\in \\mathcal{H}$ such that\n\t\\begin{equation}\n\t\\forall x \\in T, g(x)=f_1(x), \\quad and \\quad \\forall x \\in S\\backslash T, g(x)=f_2(x).\n\t\\end{equation}\n\tThe Natarajan dimension of $\\mathcal{H}$, denoted by $d_N(\\mathcal{H})$, is the maximal cardinality of a set that is N-shattered by $\\mathcal{H}$. More precisely:\n\t\\begin{equation}\n\td_N(\\mathcal{H}) = \\sup \\{|S| : S \\subset \\mathcal{X} \\text{ is N-shatterd by } \\mathcal{H}\\}\n\t\\end{equation} \n\\end{definition}\nBoth of these two dimensions coincide with the VC-dimension for binary case when $|\\mathcal{Y}|=2$. So they are generalizations of VC-dimension. Note that we always have $d_N  \\leq d_G$.\n\nBy the way, in Ben David et al.(1995), it was proved that for every function class $\\mathcal{H}\\subset \\mathcal{Y}^{\\mathcal{X}}$,\n\\begin{equation}\nd_N(\\mathcal{H}) \\leq d_G(\\mathcal{H}) \\leq 4.67 \\log_2(|\\mathcal{Y}|)d_N(\\mathcal{H})\n\\end{equation}\nwhich implies that, when the label sapce $\\mathcal{Y}$ is finite (exactly the case we care about), the Natarajan dimension and the Graph dimension are equivalent, just with a constant difference. Since $d_N  \\leq d_G$, we will use Natarajan dimension to bound the generalization error. \n\nThe significance of introducing the Natarajan dimension lies in that we can obtain a relatively tight generalization bound in multi-classification case. First we need to bound the growth function in terms of Natarajan dimension. Similarly as the Sauer Lemma, we have the following combinatorial result: \n\n\\begin{lemma}[From Natarajan 1988b]\n\tLet $X$ and $Y$ be two finite sets, and $H \\subset Y^{X}$, If $k$ is the size of the ;argest subset of $X$ N-shattered by $H$, then we have:\n\t\\begin{equation}\n\t|H| \\leq (|X|)^k (|Y|)^{2k}\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\tBy induction on $|X|$.\n\tIt is clearly true for $|X|=1$, for all $|Y|$. Assume true for $|X|=l$, $|Y|= m$, and prove for $|X|=l+1$, $|Y|= m$. Let $X= \\{x_1,...,x_{l+1}\\}$ and $Y=\\{y_1,...,y_l\\}$. Define the subsets $|H_i|$ of $|H|$ as follows:\n\t\\begin{equation}\n\tH_i := \\{f| f\\in H, f(x_1)=y_i \\}\n\t\\end{equation}\n\tAlso, for $i\\ne j$ define the sets of functions $H_{ij}(i\\ne j)$ and $H_0$ as follows:\n\t\\begin{equation}\n\tH_{ij} := \\{f| f\\in H_i, \\exists g \\in H_j \\text{ such that } f=g \\text{ on } X-\\{x_1\\} \\}\n\t\\end{equation}\n\t\\begin{equation}\n\tH_0 := H - \\bigcup_{i\\ne j} H_{ij}\n\t\\end{equation}\n\tNow we have\n\t\\begin{equation}\n\t|H| = |H_0| + |\\cup_{i\\ne j}H_{ij}| \\leq |H_0| + \\sum_{i\\ne j}|H_{ij}|\n\t\\end{equation}\n\twe seek bounds on the quantities on the right-hand side of the last inequality. By\n\tdefinition, the functions in $H_0$ are all distinct on the m elements of $X \\backslash \\{x_1\\}$. So that $H_0$ can be viewed as function class restricted on $X \\backslash \\{x_1\\}$ which has $l$ elements.\n\tFurthermore, the largest set shattered in $H_0$ must be of cardinality no greater than\n\t$k$. Hence, we have by the inductive hypothesis,\n\t\\begin{equation}\n\t|H_0| \\leq l^km^{2k}\n\t\\end{equation}\n\tand then, we claim that every $H_{ij}$ shatters a set of cardinality at most $k-1$. Otherwise, assume that it shatters $k$ ponits. By definition $H$ would shatter the $k$ points plus $x_1$, which is a set of cardinality greater than $k$. A contradiction. Also  since the functions in H are all distinct on $X \\backslash \\{x_1\\}$, we have by the inductive hypothesis, for $i\\ne j$\n\t\\begin{equation}\n\t|H_{ij}| \\leq l^{k-1}m^{2(k-1)}\n\t\\end{equation}\n\tCombining the last three inequalities, we have\n\t\\begin{align}\n\t|H| &\\leq l^km^{2k} + \\sum_{i\\ne j}l^{k-1}m^{2(k-1)} \\\\\n\t&\\leq l^km^{2k} + m^2l^{k-1}m^{2(k-1)} \\\\ \n\t&= l^{k-1}m^{2k}(l+1) \\\\\n\t&\\leq (l+1)^km^{2k}\n\t\\end{align}\n\tBy induction, we completes the proof.\n\\end{proof}\n\n\\begin{corollary}\\label{cor3.1}\n\tFor any input space $\\mathcal{X}$, any finite label space $\\mathcal{Y}$ $(|\\mathcal{Y}|< \\infty)$ and any $\\mathcal{H} \\subset \\mathcal{Y}^{\\mathcal{X}}$, The Natarajan dimension of $\\mathcal{H}$ is denoted by $d_N$, then for any $n>0$,\n\t\\begin{equation}\n\tG_{\\mathcal{H}}(n) \\leq n^{d_N}|\\mathcal{Y}|^{2d_N}\n\t\\end{equation}\n\\end{corollary}\n\\begin{proof}\n\tBy definition of growth function, there exist $S\\subset \\mathcal{X}$, $|S|=n$, such that $\tG_{\\mathcal{H}}(n)= |\\mathcal{H}|_S|$.\n\t\n\tFor $\\mathcal{H}|_S \\subset \\mathcal{Y}^S$, use the lemma to get $|\\mathcal{H}|_S| \\leq |S|^k|\\mathcal{Y}|^{2k}$, where $k$ is the Natarajan dimension of $\\mathcal{H}|_S$. Of course $k\\leq d_N$. So we get\n\t\\begin{equation}\n\tG_{\\mathcal{H}}(n)= |\\mathcal{H}|_S| \\leq |S|^k|\\mathcal{Y}|^{2k} \\leq n^{d_N}|\\mathcal{Y}|^{2d_N}\n\t\\end{equation}\n\\end{proof}\n\\subsection{Generalization bounds for multi-classification}\nAfter obtaining the bound of growth function under multi-classification assumptions, actually we have already proved one of the main results of this paper.\n\n\\begin{theorem}[Natarajan-dimension generalization bounds]\n\tLet $\\mathcal{H}$ be a family of functions taking values from $\\{1,2,...,k\\}$ with Natarajan-dimension $d_N$ and assume that the loss function $\\ell$ is the 0-1 loss. $S$ is the sample set with size $n$. Then for any $\\delta>0$, with probability at least $1-\\delta$, we have\n\t\\begin{equation}\n\t\\forall h \\in \\mathcal{H}, R(h) \\leq \\hat{R}_S(h)+4\\sqrt{\\frac{2d_N\\log(k^2n)+2\\log\\frac{4}{\\delta}}{n}}\n\t\\end{equation}\n\\end{theorem}\n\\begin{proof}\n\tThe relationship between Natarajan-dimension and the growth function showed in Corollary\\ref{cor3.1} combined with Theorem\\ref{th3} leads immediately to the generalization bounds based on Natarajan-dimension.\n\\end{proof}\n\n\\section{Rademacher Complexity}\n\\subsection{Rademacher complexity bounds}\nIn the previous section, we have talked about the growth function and the VC-dimension and obtain the genralization bound based on these two complexity. In this section, we introduce a different notion of complexity for the family of hypotheses, Rademacher complexity. This will help us derive learning guarantees using relatively simple proofs based on McDiarmid's inequality, while obtaining high-quality bounds.\n\nWe will continue to use $\\mathcal{H}$ to denote a hypothesis set as in the previous chapters\nand $h$ an element of $\\mathcal{H}$. Many of the results of this section are general and hold for\nan arbitrary loss function $\\ell :\\mathcal{Y}\\times \\mathcal{Y} \\to \\mathbb{R}$. To each $h: \\mathcal{X}\\to \\mathcal{Y}$ , we can associate a function $g$ that maps $(x,y)$ to $\\ell(h(x),y)$ without explicitly describing the specific loss $\\ell$ used. In what follows $G$ will generally be interpreted as the family of loss functions associated to $\\mathcal{H}$.\n\nThe Rademacher complexity captures the richness of a family of functions by\nmeasuring the degree to which a hypothesis set can fit random noise. The following\nstates the formal definitions of the empirical and average Rademacher complexity.\n\\begin{definition}[Empirical Rademacher complexity]\n\tLet $g$ be a family of functions mapping from $Z$ to $[a,b]$ and $S=(z_1,...,z_m)$ a fixed\n\tsample of size m with elements in $Z$. Then, the empirical Rademacher complexity\n\tof G with respect to the sample $S$ is defined as:\n\t\\begin{equation}\n\t\\hat{\\mathcal{R}}_S(G)= \\mathbb{E}_{\\sigma} \\big[\\sup_{g\\in G}\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_ig(z_i)\\big]\n\t\\end{equation}\n\twhere $\\sigma=(\\sigma_1,...,\\sigma_m)^T$ with $\\sigma_i$s independent uniform random variables taking values in $\\{+1,-1\\}$. The random variables $\\sigma_i$ are called Rademacher variables\n\\end{definition}\nThe empirical Rademacher complexity measures on average how well the function class G correlates with random noise on $S$. This describes the richness of the family $G$. Richer or more complex families $G$ can generate more vectors $(g(z_1),...,g(z_m))$ and thus better correlate with random noise on average.\n\\begin{definition}[Rademacher complexity]\n\tLet $D$ denote the distribution according to which samples are drawn. For any\n\tinteger $m \\geq 1$, the Rademacher complexity of $G$ is the expectation of the empirical\n\tRademacher complexity over all samples of size $m$ draw according to $D$\n\t\\begin{equation}\n\t\\mathcal{R}_m(G)= \\mathbb{E}_{S\\sim D^m}[\\hat{\\mathcal{R}}_S(G)]\n\t\\end{equation}\n\\end{definition}\nWe are now ready to present our first generalization bounds based on Rademacher complexity.\n\\begin{theorem}\n\tLet G be a family of functions mapping from $Z$ to $[0,1]$. Then, for any $\\delta>0$, with\n\tprobability at least $1-\\delta$, each of the following holds for all $g\\in G$\n\\end{theorem}\n\\begin{equation}\n\\mathbb{E}[g(z)] \\leq \\frac{1}{m}\\sum_{i=1}^{m}g(z_i) +2\\mathcal{R}_m(G) +\\sqrt{\\frac{\\log(\\frac{1}{\\delta})}{2m}}\n\\end{equation}\n\\begin{equation}\nand \\qquad\t\\mathbb{E}[g(z)] \\leq \\frac{1}{m}\\sum_{i=1}^{m}g(z_i) +2\\hat{\\mathcal{R}}_S(G) +3\\sqrt{\\frac{\\log(\\frac{2}{\\delta})}{2m}}\n\\end{equation}\n\\begin{proof}\n\tFor any sample $S=(z_1,...z_m)$ and any $g\\in G$, we denote by $\\hat{\\mathbb{E}}_S[g]$ the empirical average of $g$ over $S$: $\\hat{\\mathbb{E}}_S[g]= \\frac{1}{m} \\sum_{i=1}^{m}g(z_i)$. We define $\\Phi$ for any sample $S$ and then apply the McDiarmid's inequality\n\t\\begin{equation}\n\t\\Phi(S)= \\sup_{g\\in G}(\\mathbb{E}[g]-\\hat{\\mathbb{E}}_S[g])\n\t\\end{equation}\n\tLet $S$ and $S'$ be two samples differing by exactly one point, say $z_m$ in $S$ and $z_m'$ in $S'$. Then we have\n\t\\begin{align}\n\t\\Phi(S')-\\Phi(S) &= \\sup_{g\\in G}(\\mathbb{E}[g]-\\hat{\\mathbb{E}}_{S'}[g]) -\\sup_{g\\in G}(\\mathbb{E}[g]-\\hat{\\mathbb{E}}_S[g])\\\\\n\t&\\leq \\sup_{g\\in G}(\\hat{\\mathbb{E}}_S[g])-\\hat{\\mathbb{E}}_{S'}[g])\\\\\n\t&= \\sup_{g\\in G} \\frac{g(z_m)-g(z'_m)}{m} \\\\\n\t&\\leq \\frac{1}{m}\n\t\\end{align}\n\tSimilarly, we can obtain $\\Phi(S)-\\Phi(S')\\leq \\frac{1}{m}$, thus $|\\Phi(S')-\\Phi(S)|\\leq \\frac{1}{m}$. Then, by McDiarmid's inequality, for any $\\delta>0$, with probability at least $1-\\frac{2}{\\delta}$, the following holds\n\t\\begin{equation}\n\t\\Phi(S)\\leq \\mathbb{E}_S[\\Phi(S)]+ \\sqrt{\\frac{\\log(\\frac{1}{\\delta})}{2m}}\n\t\\end{equation}\n\tNext we will show $\\mathbb{E}_S[\\Phi(S)] \\leq 2\\mathcal{R}_m(G)$\n\t\\begin{align}\n\t\\mathbb{E}_S[\\Phi(S)]&= \\mathbb{E}_S\\bigg[\\sup_{g\\in G}(\\mathbb{E}[g]-\\hat{\\mathbb{E}}_S[g])\\bigg]\\\\\n\t&=\\mathbb{E}_S\\bigg[\\sup_{g\\in G}\\mathbb{E}_{S'}\\big[\\hat{\\mathbb{E}}_{S'}[g]-\\hat{\\mathbb{E}}_S[g]\\big]\\bigg]\\\\\n\t&\\leq \\mathbb{E}_{S,S'}\\bigg[\\sup_{g\\in G}(\\hat{\\mathbb{E}}_{S'}[g]-\\hat{\\mathbb{E}}_S[g])\\bigg]\\\\\n\t&= \\mathbb{E}_{S,S'}\\bigg[\\sup_{g\\in G}\\frac{1}{m}\\sum_{i=1}^{m}(g(z'_i)-g(z_i))\\bigg]\\\\\n\t&= \\mathbb{E}_{\\sigma,S,S'}\\bigg[\\sup_{g\\in G}\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_i(g(z_i)-g(z'_i))\\bigg]\\\\\n\t&\\leq  \\mathbb{E}_{\\sigma,S'}\\bigg[\\sup_{g\\in G}\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_ig(z'_i)\\bigg] + \\mathbb{E}_{\\sigma,S}\\bigg[\\sup_{g\\in G}\\frac{1}{m}\\sum_{i=1}^{m}-\\sigma_ig(z_i)\\bigg]\\\\\n\t&\\leq 2\\mathbb{E}_{\\sigma,S}\\bigg[\\sup_{g\\in G}\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_ig(z_i)\\bigg] = 2\\mathcal{R}_m(G)\n\t\\end{align}\n\tThe reduction to $\\mathcal{R}_m(G)$ yields the bound in the first inequality, using $\\delta$ instead of $\\frac{\\delta}{2}$. To derive a bound in terms of $\\hat{\\mathcal{R}}_S(G)$, we observe that, changing one point in $S$ changes $\\hat{\\mathcal{R}}_S(G)$ by at most $\\frac{1}{m}$. Then\n\tusing again McDiarmid's inequality, with probability $1-\\frac{\\delta}{2}$ the following holds\n\t\\begin{equation}\n\t\\mathcal{R}_m(G)\\leq \\hat{\\mathcal{R}}_S(G) +\\sqrt{\\frac{\\log(\\frac{2}{\\delta})}{2m}}\n\t\\end{equation}\n\tFinally, we use the union bound to combine these two inequalities which yield that\n\twith probability at least $1-\\delta$\n\t\\begin{equation}\n\t\\Phi(S) \\leq 2\\hat{\\mathcal{R}}_S(G)+3\\sqrt{\\frac{\\log(\\frac{2}{\\delta})}{2m}}\n\t\\end{equation}\n\\end{proof}\n\nThe following result relates the empirical Rademacher complexities of a hypothesis set $h$ and to the family of loss functions $G$ associated to $\\mathcal{H}$ in the case of binary loss(0-1 loss)\n\\begin{lemma}\n\tLet $\\mathcal{H}$ be a family of functions taking values in $\\mathcal{Y}=\\{+1,-1\\}$, and let $G$ be the family of loss functions associated to $\\mathcal{H}$ for the 0-1 loss:$G=\\{(x,y) \\mapsto 1_{h(x)\\ne y} | h\\in \\mathcal{H}\\}$.\n\tFor any sample $S=\\{(x_1, y1),..., (x_m, y_m)\\}$, let $S_{\\mathcal{X}}$ denote its projection over $S_{\\mathcal{X}}=(x_1,.., x_m)$. Then, the following relation holds\n\tbetween the Rademacher complexities of $G$ and $\\mathcal{H}$:\n\t\\begin{equation}\n\t\\mathcal{R}_m(G)=\\frac{1}{2} \\mathcal{R}_m(\\mathcal{H})\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\t\\begin{align}\n\t\\hat{\\mathcal{R}}_S(G)&= \\mathbb{E}_{\\sigma} \\big[\\sup_{h\\in \\mathcal{H}}\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_i1_{h(x)\\ne y}\\big]\\\\\n\t&=\\mathbb{E}_{\\sigma} \\big[\\sup_{h\\in \\mathcal{H}}\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_i\\frac{1}{2}(1-y_ih(x_i))\\big]\\\\\n\t&= \\frac{1}{2} \\mathbb{E}_{\\sigma} \\big[\\sup_{h\\in \\mathcal{H}}\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_i y_ih(x_i)\\big] = \\frac{1}{2}\\hat{\\mathcal{R}}_{S_{\\mathcal{X}}}(\\mathcal{H})\n\t\\end{align}\n\tTaking expectation on both sides over $S$ concludes the lemma.\n\\end{proof}\nThese connections between the empirical and average Rademacher complexities can be used to derive generalization bounds for binary classification in terms of the Rademacher complexities of the hypothesis set $\\mathcal{H}$.\n\\begin{theorem}[Rademacher complexity bounds for binary classification]\n\tLet $\\mathcal{H}$ be a family of functions taking values in $\\mathcal{Y}=\\{+1,-1\\}$, and let $F$ be the distribution over the input space $\\mathcal{X}$. Then, for any $\\delta>0$, with probability at least $1-\\delta$ over a sample $S$ of size $m$ drawn according to $F$, each of the following holds for all $h\\in \\mathcal{H}$:\n\t\\begin{equation}\n\t\\qquad R(h) \\leq \\hat{R}(h) + \\mathcal{R}_m(\\mathcal{H}) + \\sqrt{\\frac{\\log(\\frac{1}{\\delta})}{2m}}\n\t\\end{equation}\n\t\\begin{equation}\n\tand \\qquad R(h) \\leq \\hat{R}(h) + \\hat{\\mathcal{R}}_{S}(\\mathcal{H}) + 3\\sqrt{\\frac{\\log(\\frac{2}{\\delta})}{2m}}\n\t\\end{equation}\n\\end{theorem}\n\\begin{proof}\n\tThe result follows immediately by theorem 3. 1 and lemma 3.1\n\\end{proof}\n%%%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\nThe theorem provides two generalization bounds for binary classification based on the Rademacher complexity. Note that the second bound, (3.18), is data-dependent. Thus, this bound could be particularly informative if we could compute $\\hat{\\mathcal{R}}_{S}(\\mathcal{H})$.\nFor binary classification problem, the empirical Rademacher complexity $\\hat{\\mathcal{R}}_{S}(\\mathcal{H})$ can actually be computed. Notice that:\n\\begin{align}\n\\hat{\\mathcal{R}}_{S}(\\mathcal{H}) &= \\mathbb{E}_{\\sigma} \\big[\\sup_{h\\in \\mathcal{H}}\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_i h(x_i)\\big]\\\\\n&= 1+2\\mathbb{E}_{\\sigma} \\big[\\sup_{h\\in \\mathcal{H}}\\frac{1}{m}\\sum_{i=1}^{m}-\\frac{1-\\sigma_i h(x_i)}{2}\\big]\\\\\n&= 1-2\\mathbb{E}_{\\sigma} \\big[\\inf_{h\\in \\mathcal{H}}\\frac{1}{m}\\sum_{i=1}^{m} \\frac{1-\\sigma_i h(x_i)}{2}\\big]\\\\\n&= 1-2\\mathbb{E}_{\\sigma} \\big[\\inf_{h\\in \\mathcal{H}}\\frac{1}{m}\\sum_{i=1}^{m} 1_{h(x_i)\\ne \\sigma_i} \\big] \\\\\n&= 1-2\\mathbb{E}_{\\sigma} \\big[\\inf_{h\\in \\mathcal{H}}\\hat{R}_S(h,\\sigma)\\big]\n\\end{align}\n\nwhere $\\hat{R}_S(h,\\sigma)$ is the empirical risk of classifier $h$ with respect to $S$ with random label $\\sigma=(\\sigma_1,...,\\sigma_m)$. When $\\mathcal{H}$ is so large that it can fit every random labeling perfectly, we have $\\hat{\\mathcal{R}}_{S}(\\mathcal{H})=1$ and the bound becomes meaningless.\\\\\n\nWe could estimate Rademacher complexity for function classes which are built from simpler classes. The following is a list of properties about Rademacher complexity.\n\\begin{itemize}\n\t\\item 1. If $\\mathcal{F}\\subset \\mathcal{G}$ then $\\mathcal{R}_m(\\mathcal{F}) \\leq \\mathcal{R}_m(\\mathcal{G})$. It follows from the definition.\n\t\\item 2. $\\mathcal{R}_m(c\\cdot \\mathcal{F}) = |c|\\mathcal{R}_m(\\mathcal{F})$, where $c\\cdot \\mathcal{F}=\\{x\\mapsto cf(x) | f\\in \\mathcal{F}\\}$. Since we have \n\t\\begin{equation}\n\t\\mathcal{R}_m(c\\cdot \\mathcal{F})= \\mathbb{E}_{\\sigma,S}\\bigg[\\sup_{f\\in \\mathcal{F}}\\frac{1}{m}\\sum_{i=1}^{m}c\\sigma_i f(x_i)\\bigg] = \\mathbb{E}_{\\sigma,S}\\bigg[|c|\\sup_{f\\in \\mathcal{F}}\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_i f(x_i)\\bigg] = |c|\\mathcal{R}_m(\\mathcal{F})\n\t\\end{equation}\n\t\\item 3. $\\mathcal{R}_m(\\mathcal{F}+g) = \\mathcal{R}_m(\\mathcal{F})$, where $\\mathcal{F}+g$ is defined as $\\{f+g| f\\in \\mathcal{F}\\}$ and $g$ is a fixed function. To show this we have:\n\t\\begin{align}\n\t\\mathcal{R}_m(\\mathcal{F}+g) &= \\mathbb{E}_{\\sigma,S}\\bigg[\\sup_{f\\in \\mathcal{F}}\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_i (f(x_i)+g(x_i))\\bigg]\\\\\n\t&= \\mathbb{E}_{\\sigma,S}\\bigg[\\sup_{f\\in \\mathcal{F}}\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_i f(x_i)\\bigg] + \\mathbb{E}_{\\sigma,S}\\bigg[\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_i g(x_i)\\bigg]\\\\\n\t&=\\mathcal{R}_m(\\mathcal{F})\n\t\\end{align}\n\t\\item 4. Let the convex hull of a set of functions $\\mathcal{F}$ be defined as\n\t\\begin{equation}\n\tconv(\\mathcal{F}) = \\left\\{ \\sum_{i=1}^{k}\\alpha_if_i : k\\geq 1,\\alpha_i\\geq 0, \\sum_{i=1}^{k}\\alpha_i=1, f_1,...,f_k\\in \\mathcal{F} \\right\\}.\n\t\\end{equation}\n\tThen we have $\\mathcal{R}_m(\\mathcal{F})= \\mathcal{R}_m(conv(\\mathcal{F}))$ since\n\t\\begin{align}\n\t\\mathcal{R}_m(conv(\\mathcal{F})) &= \\mathbb{E}\\bigg[ \\sup_{f_j\\in \\mathcal{F}, \\alpha_i\\geq 0, \\sum_{i=1}^{k}\\alpha_i=1} \\frac{1}{m} \\sum_{i=1}^{m}\\sigma_i \\sum_{j=1}^{k} \\alpha_jf_j(x_i) \\bigg]\\\\\n\t&= \\mathbb{E}\\bigg[ \\sup_{f_j\\in \\mathcal{F}, \\alpha_i\\geq 0, \\sum_{i=1}^{k}\\alpha_i=1}\\sum_{j=1}^{k}\\alpha_j \\left( \\frac{1}{m} \\sum_{i=1}^{m}\\sigma_i  f_j(x_i) \\right) \\bigg]\\\\\n\t&= \\mathbb{E}\\bigg[ \\sup_{f_j\\in \\mathcal{F}}\\max_{j} \\frac{1}{m}\\sum_{i=1}^{m}\\sigma_if_j(x_i) \\bigg]\\\\\n\t&= \\mathcal{R}_m(\\mathcal{F})\n\t\\end{align}\n\\end{itemize}\nThe Rademacher complexity is related to the growth funciton and VC-dimension. In the next sections, we will bound the Rademacher complexity by the growth funciton and VC-dimension which are easier to compute.\n\\subsection{The relation between Rademacher complexity and VC dimension}\nFirst we will show how the Rademacher complexity can be bounded in terms of growth function. We will use Massart's lemma.\n\\begin{theorem}[Massart's lemma]\n\tLet $A \\subset {\\mathbb{R}}^m$ be a finite set, with $r=\\max_{x\\in A}||x||_2$, then the following holds:\n\t\\begin{equation}\n\t\\mathbb{E}_{\\sigma} \\big[\\frac{1}{m}\\sup_{x\\in A}\\sum_{i=1}^{m}\\sigma_ix_i\\big] \\leq \\frac{r\\sqrt{2\\log|A|}}{m}\n\t\\end{equation}\n\twhere $\\sigma_i's$ are independent uniform random variables taking values in $\\{-1,+1\\}$ and $x_1,...,x_m$ are components of vector $x$.\n\\end{theorem}\n\\begin{proof}\n\tFor any $t>0$, using Jensen's inequality, rearranging terms, and bounding the supremum by a sum, the independence of the $\\sigma_i's$, and Hoeffding's lemma, we obtain:\n\t\\begin{align}\n\t\\exp\\left(t\\mathbb{E}_{\\sigma} \\big[\\sup_{x\\in A}\\sum_{i=1}^{m}\\sigma_ix_i \\big]\\right) &\\leq \\mathbb{E}_{\\sigma}\\left( \\exp \\left(t\\sup_{x\\in A}\\sum_{i=1}^{m}\\sigma_ix_i\\right)\\right) \\\\\n\t&= \\mathbb{E}_{\\sigma}\\left(\\sup_{x\\in A} \\exp \\left(t\\sum_{i=1}^{m}\\sigma_ix_i\\right)\\right)\\\\\n\t&\\leq \\sum_{x\\in A} \\mathbb{E}_{\\sigma}\\left(\\exp \\left(t\\sum_{i=1}^{m}\\sigma_ix_i\\right)\\right)\\\\\n\t(\\text{independence of the }\\sigma_i's)&=\\sum_{x\\in A} \\prod_{i=1}^{m}\\mathbb{E}_{\\sigma_i}[\\exp(t\\sigma_ix_i)] \\\\\n\t(\\text{Hoeffding's lemma})&\\leq \\sum_{x\\in A} \\prod_{i=1}^{m} \\exp\\left(\\frac{t^2(2x_i)^2}{8}\\right)\\\\\n\t&= \\sum_{x\\in A}\\exp\\left(\\frac{t^2||x||_2^2}{2}\\right)\\\\\n\t&\\leq  \\sum_{x\\in A} \\exp\\left(\\frac{t^2r^2}{2}\\right) = |A|\\exp\\left(\\frac{t^2r^2}{2}\\right)\n\t\\end{align}\n\tTaking the log of both sides and dividing by t gives us:\n\t\\begin{equation}\n\t\\mathbb{E}_{\\sigma} \\big[\\sup_{x\\in A}\\sum_{i=1}^{m}\\sigma_ix_i \\big] \\leq \\frac{\\log|A|}{t} + \\frac{tr^2}{2}\n\t\\end{equation}\n\tMinimizes RHS, when $t=\\frac{\\sqrt{2\\log|A|}}{r}$ we get:\n\t\\begin{equation}\n\t\\mathbb{E}_{\\sigma} \\big[\\sup_{x\\in A}\\sum_{i=1}^{m}\\sigma_ix_i \\big] \\leq r\\sqrt{2\\log|A|}\n\t\\end{equation}\n\tDividing both sides by $m$ leads to the statement of the lemma.\n\\end{proof}\nUsing this result, we can now bound the Rademacher complexity in terms of the growth function.\n\\begin{corollary}\n\tLet $G$ be a family of functions taking values in $\\{-1,+1\\}$. Then the following holds\n\t\\begin{equation}\n\t\\mathcal{R}_m(G) \\leq \\sqrt{\\frac{2\\log G_G(m)}{m}}\n\t\\end{equation}\n\\end{corollary}\n\\begin{proof}\n\tFor a fixed sample $S=(x_1,...,x_m)$, we denote by $G_S$ the set of vectors of function values $(g(x_1),...,g(x_m))$ where $g \\in G$. Since $g$ takes values in $\\{-1,+1\\}$, the norm of these vectors is bounded by $\\sqrt{m}$. We can then apply Massart's lemma as follows:\n\t\\begin{equation}\n\t\\mathcal{R}_m(G)= \\mathbb{E}_{S}\\bigg[\\mathbb{E}_{\\sigma}\\bigg[\\sup_{u\\in G_S}\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_iu_i\\bigg]\\bigg] \\leq \\mathbb{E}_{S}\\bigg[\\frac{\\sqrt{m}\\sqrt{2\\log|G_S|}}{m} \\bigg]\n\t\\end{equation}\n\tBy definition, $|G_S|$ is bounded by the growth function, thus\n\t\\begin{equation}\n\t\\mathcal{R}_m(G) \\leq \\mathbb{E}_{S}\\bigg[\\frac{\\sqrt{m}\\sqrt{2\\log G_G(m)}}{m} \\bigg] =\\sqrt{ \\frac{2\\log G_G(m)}{m}}\n\t\\end{equation}\n\twhich concludes the proof.\n\\end{proof}\nCombining the generalization bound of Rademacher complexity with this corollary yields immediately the following generalization bound in terms of the growth function.\n\\begin{corollary}[Growth function generalization bound]\n\tLet $\\mathcal{H}$ be a family of functions taking values in $\\{-1,+1\\}$. Then, for any $\\delta >0$, with probability at least $1-\\delta$, for any $h \\in \\mathcal{H}$,\n\t\\begin{align}\n\tR(h)&\\leq \\hat{R}(h) + \\sqrt{\\frac{2\\log G_{\\mathcal{H}}(m)}{m}} +\\sqrt{\\frac{\\log\\frac{1}{\\delta}}{2m}}\\\\\n\t&\\leq \\hat{R}(h) + \\sqrt{\\frac{4\\log G_{\\mathcal{H}}(m)+\\log\\frac{1}{\\delta}}{m}}\n\t\\end{align}\n\\end{corollary}\nSimilarly, we can bound the growth foucntion with the VC dimension of $\\mathcal{H}$ and obtain the VC dimension generalization bound.\nUsing Rademacher complexity is another way of getting the growth foucntion or the VC dimension generalization bound, which only differs by constants from the result we got in the previous section.\\\\\nAnother application of introducing Rademacher comlexity is to derive margin-based generalization bound in binary and multi-class case. In the next sections, we will talk about the margin based results.\n\n\\subsection{Margin based generalization bound for binary classification}\nUsually we do not minimize the 0-1 loss in practice, for 0-1 loss can not gives the sense of degree to classified correctly or incorrectly. Thus the hypothesis functions of the classifier are generally mapped to the real number space, such as the linear classifier. Hyperplane was used as the basis of classification. So there is a natural measure of classification confidence, which is the directed distance between the sample point $(x_i, y_i)$ and the hyperplane $wx+b=0$, says $y_i(wx_i+b)$. The distance is greater than zero means classified correctly, and the greater the directional distance is, the greater of confidence we will have, which should correspond to a smaller loss, and vice versa. \\\\\n\nLinear functions are not the only option. Generally we denote that $\\mathcal{H}$ is a set of functions mapping $\\mathcal{X}$ to $\\mathcal{Y}' = \\mathbb{R}$, and for $h \\in \\mathcal{H}$, $y_ih(x_i)$ is some kind of classification confidence. The label space $\\mathcal{Y}$ still be the binary label $\\{+1,-1\\}$ and the loss function we definded to be the following margin loss. \nThe quantity $\\rho > 0$ should thus be interpreted as the margin we wish to acheive.\n\n\\begin{definition}[Margin Loss Function]\n\tFor any $\\rho > 0$, we define the $\\rho$-margin loss $\\ell_{\\rho} : \\mathbb{R} \\times \\mathbb{R} \\to \\mathbb{R}_{+}$ to be the function $\\ell_{\\rho}(y,y') = \\Phi_{\\rho}(yy')$ with,\n\t\\begin{numcases}{\\Phi_{\\rho}(x)=}\n\t0 &if $\\rho \\leq x$ \\\\\n\t1-\\frac{x}{\\rho} & if $0\\leq x \\leq \\rho$ \\\\\n\t1 & if $x \\leq 0$\n\t\\end{numcases}\n\\end{definition}\nThe margin loss function is illustrated in the figure below.\n\\begin{figure}[ht]    \\centering \n\t\\begin{tikzpicture}\n\t% draw the axis\n\t\\draw[-latex] (-2.5,0) -- (3,0) node[below] {$x$};\n\t\\draw[-latex] (0,0) -- (0,2) node[above] {$y$};\n\t%draw node\n\t\\foreach \\x in {0,1}{\\draw(\\x,0)--(\\x,0.05)node[below,outer sep=2pt,font=\\tiny]at(\\x,0){\\x};}\n\t\\foreach \\y in {1}{\\draw(0,\\y)--(0.05, \\y)node[above left, inner sep=2pt,font=\\tiny]at(0,\\y){\\y};}\n\t\\draw(0.6,0)--(0.6,0.05)node[below,outer sep=2pt,font=\\tiny]at(0.6,0){$\\rho$};\n\t% draw the function (piecewise)\n\t\n\t\\draw[color=red, thick, smooth] (-2.5,1) -- (0,1) -- (0.6,0) -- (2.8,0);\n\t\\draw[color=blue, dashed] (-2.5,1) -- (0.6,1) -- (0.6,0) -- (2.8,0);\n\t\\end{tikzpicture}\n\t\\caption{The margin loss, defined with respect to margin parameter $\\rho$}\n\\end{figure}\n\\\\\n\\\\\n\\\\\n\\\\\nThe empirical margin loss is then defined as the margin loss over the training sample.\n\\begin{definition}[Empirical Margin Loss]\n\tGiven a sample $S=\\{(x_1,y_1),..,(x_n,y_n)\\}$ and hypothesis $\\mathcal{H}$ a set of real-valued functions, the empirical margin loss is\tdefined by\n\t\\begin{equation}\n\t\\hat{R}_{\\rho}(h) = \\frac{1}{m} \\sum_{i=1}^{n} \t\\Phi_{\\rho}(y_ih(x_i))\n\t\\end{equation}\n\\end{definition}\n\nNote that for any the empirical margin loss can be upper-bounded as follows\n\\begin{equation}\n\\hat{R}_{\\rho}(h) \\leq \\frac{1}{m} \\sum_{i=1}^{n} 1_{y_ih(x_i) \\leq \\rho}\n\\end{equation}\nand $y_ih(x_i)\\leq 0$ means that $(x_i, y_i)$ is classified incorrectly by $h$, so that the generalization error is \n\\begin{equation}\nR(h) = \\mathbb{E}_{X,Y}[1_{Yh(X) \\leq 0}]\n\\end{equation}\n$y_ih(x_i)$ can be thought as some kind of confidence. $y_ih(x_i)>0$ means $h$ classify $(x_i,y_i)$ correctly, and the larger $y_ih(x_i)$ is, the more confidence we have. The upper bound of margin loss admits a simple interpretation: it is the fraction of the points in the\ntraining sample $S$ that have been misclassified or classified with confidence less than $\\rho$.\n\nWhen $h$ is a linear function defined by a weight vector w with $||w||=1$, then $y_ih(x_i)$ has a explicit geometry interpretation, which is nothing but the geometry distance of the sample $(x_i,y_i)$ to the hyperplane $h(x)=0$.\n\nThe next lemma will be needed for the proof of the margin-based generalization bound.\n\\begin{lemma}[Talagrand's lemma]\n\tLet $\\Phi: \\mathbb{R} \\to \\mathbb{R}$ be an L-Lipschitz function, $S=\\{(x_1,y_1),..,(x_n,y_n)\\}$ be the sample set. Then, for any hypothesis set $\\mathcal{H}$ of real-valued functions, the following inequality holds\n\t\\begin{equation}\n\t\\hat{\\mathcal{R}}_S(\\Phi \\circ \\mathcal{H}) \\leq L \\hat{\\mathcal{R}}_S(\\mathcal{H})\n\t\\end{equation} \n\\end{lemma}\n\\begin{proof}\n\tBy definition, we have\n\t\\begin{align}\n\t\\hat{\\mathcal{R}}_S(\\Phi \\circ \\mathcal{H}) &= \\frac{1}{n} \\mathbb{E}_{\\sigma} \\bigg[\\sup_{h \\in \\mathcal{H}} \\sum_{i=1}^{n} \\sigma_i(\\Phi \\circ h)(x_i)\\bigg] \\\\\n\t&= \\frac{1}{n} \\mathbb{E}_{\\sigma_1,...,\\sigma_{n-1}} \\bigg[\\mathbb{E}_{\\sigma_n} \\big[ \\sup_{h \\in \\mathcal{H}} u_{n-1}(h) + \\sigma_n(\\Phi \\circ h)(x_n)\\big]\\bigg]\n\t\\end{align}\n\twhere we denote $\\sum_{i=1}^{n-1} \\sigma_i(\\Phi \\circ h)(x_i)$ by $u_{n-1}(h)$. By the definiton of supremum, for any $\\epsilon>0$, there exist $h_1, h_2$ such that\n\t\\begin{equation}\n\tu_{n-1}(h_1) + (\\Phi \\circ h_1)(x_n) \\geq \\sup_{h \\in \\mathcal{H}} \\big[u_{n-1}(h) + (\\Phi \\circ h)(x_n)- \\epsilon \\big] \n\t\\end{equation}\n\t\\begin{equation}\n\tu_{n-1}(h_2) - (\\Phi \\circ h_2)(x_n) \\geq \\sup_{h \\in \\mathcal{H}} \\big[u_{n-1}(h) - (\\Phi \\circ h)(x_n)- \\epsilon \\big] \n\t\\end{equation}\n\tThus, by definition of the expectation of $\\mathbb{E}_{\\sigma_n}$\n\t\\begin{align}\n\t& \\mathbb{E}_{\\sigma_n} \\big[ \\sup_{h \\in \\mathcal{H}} u_{n-1}(h) + \\sigma_n(\\Phi \\circ h)(x_n)\\big] -\\epsilon \\\\\n\t&= \\frac{1}{2}\\sup_{h \\in \\mathcal{H}} \\big[u_{n-1}(h) + (\\Phi \\circ h)(x_n)  -\\epsilon \\big] + \\frac{1}{2}\\sup_{h \\in \\mathcal{H}} \\big[u_{n-1}(h) - (\\Phi \\circ h)(x_n) -\\epsilon \\big] \\\\\n\t&\\leq \\frac{1}{2}\\big[u_{n-1}(h_1) + (\\Phi \\circ h_1)(x_n)\\big] +\\frac{1}{2}\\big[u_{n-1}(h_2) - (\\Phi \\circ h_2)(x_n)\\big] \\\\\n\t& = \\frac{1}{2}\\big[u_{n-1}(h_1) + u_{n-1}(h_2) + \\Phi \\circ(h_1-h_2)(x_n)\\big] \\\\\n\t&\\leq \\frac{1}{2}\\big[u_{n-1}(h_1) + u_{n-1}(h_2) + L|h_1(x_n)-h_2(x_n)|\\big]\n\t\\end{align}\n\tLet $s=sgn(h_1(x_n)-h_2(x_n))$, then\n\t\\begin{align}\n\t& \\mathbb{E}_{\\sigma_n} \\big[ \\sup_{h \\in \\mathcal{H}} u_{n-1}(h) + \\sigma_n(\\Phi \\circ h)(x_n)\\big] -\\epsilon \\\\\n\t& \\leq \\frac{1}{2}\\big[u_{n-1}(h_1) + sLh_1(x_n)\\big] +\\frac{1}{2}\\big[u_{n-1}(h_2) - sLh_2(x_n)\\big] \\\\\n\t&\\leq  \\frac{1}{2} \\sup_{h \\in \\mathcal{H}} \\big[u_{n-1}(h) + sLh(x_n)\\big] +\\frac{1}{2} \\sup_{h \\in \\mathcal{H}} \\big[u_{n-1}(h) - sLh(x_n)\\big] \\\\\n\t&= \\mathbb{E}_{\\sigma_n} \\big[ \\sup_{h \\in \\mathcal{H}} u_{n-1}(h) + \\sigma_n Lh(x_n)\\big]\n\t\\end{align}\n\tSince the inequality holds for any $\\epsilon>0$, then we have\n\t\\begin{equation}\n\t\\mathbb{E}_{\\sigma_n} \\big[ \\sup_{h \\in \\mathcal{H}} u_{n-1}(h) + \\sigma_n(\\Phi \\circ h)(x_n)\\big] \\leq \\mathbb{E}_{\\sigma_n} \\big[ \\sup_{h \\in \\mathcal{H}} u_{n-1}(h) + \\sigma_n Lh(x_n)\\big]\n\t\\end{equation}\n\tProceeding in the same way for other $\\sigma_i$ proves the lemma.\n\\end{proof}\n\n\\begin{theorem}[Margin bound for binary classification]\n\tLet $\\mathcal{H}$ be a set of real-valued functions. Fix $\\rho>0$, $S=\\{(x_1,y_1),..,(x_n,y_n)\\}$ be the sample set, then, for any $\\delta>0$, with probability at least $1-\\delta$, the following holds for all $h \\in \\mathcal{H}$:\n\t\\begin{equation}\n\tR(h) \\leq \\hat{R}_{\\rho}(h) + \\frac{2}{\\rho}\\mathcal{R}_n(\\mathcal{H}) + \\sqrt{\\frac{\\log\\frac{1}{\\delta}}{2n}}\n\t\\end{equation}\n\t\\begin{equation}\n\tR(h) \\leq \\hat{R}_{\\rho}(h) + \\frac{2}{\\rho}\\hat{\\mathcal{R}}_S(\\mathcal{H}) + 3\\sqrt{\\frac{\\log\\frac{2}{\\delta}}{2n}}\n\t\\end{equation}\n\\end{theorem}\n\\begin{proof}\n\tLet $\\mathcal{H}_1 = \\{ z=(x,y) \\mapsto yh(x) : h \\in \\mathcal{H} \\}$ and $\\mathcal{H}_2 = \\{  \\Phi \\circ f : f \\in \\mathcal{H}_1 \\}$. \n\tSince functions in $\\mathcal{H}_2$ range in $[0,1]$, by $theorem5$, with probability at least $1-\\delta$, for all $g \\in \\mathcal{H}_2$\n\t\\begin{equation}\n\t\\mathbb{E}[g(z)] \\leq \\frac{1}{n}\\sum_{i=1}^{m}g(z_i) + 2\\mathcal{R}_n(\\mathcal{H}_2) +\\sqrt{\\frac{\\log\\frac{1}{\\delta}}{2n}}\t\n\t\\end{equation}\n\tThus\n\t\\begin{equation}\n\t\\mathbb{E}[\\Phi_{\\rho}(yh(x))] \\leq \\hat{R}_{\\rho}(h) + 2\\mathcal{R}_n(\\Phi_{\\rho} \\circ \\mathcal{H}_1) +\\sqrt{\\frac{\\log\\frac{1}{\\delta}}{2n}}\n\t\\end{equation}\n\tSince the margin loss function is a upper bound of 0-1 loss function, we have \n\t$R(h) = \\mathbb{E}[1_{yh(x) \\leq 0}] \\leq \\mathbb{E}[\\Phi_{\\rho}(yh(x))]$. \n\tAlso by the Talagrand's lemma we have $\\mathcal{R}_n(\\Phi_{\\rho} \\circ \\mathcal{H}_1) \\leq \\frac{1}{\\rho} \\mathcal{R}_n(\\mathcal{H}_1)$. Thus\n\t\\begin{equation}\n\tR(h) \\leq \\hat{R}_{\\rho}(h) + \\frac{2}{\\rho}\\mathcal{R}_n(\\mathcal{H}_1) +\\sqrt{\\frac{\\log\\frac{1}{\\delta}}{2n}}\n\t\\end{equation}\n\tAnd then, it is easy to show\n\t\\begin{equation}\n\t\\mathcal{R}_n(\\mathcal{H}_1) =\\frac{1}{n}\\mathbb{E}_{S,\\sigma}\\bigg[\\sup_{h \\in \\mathcal{H}}\\sum_{i=0}^{n}\\sigma_iy_ih(x_i)\\bigg] = \\frac{1}{n}\\mathbb{E}_{S,\\sigma}\\bigg[\\sup_{h \\in \\mathcal{H}}\\sum_{i=0}^{n}\\sigma_ih(x_i)\\bigg] =  \\mathcal{R}_n(\\mathcal{H})\n\t\\end{equation}\n\twhich completes the proof of the first inequality. \n\tThe second inequality,(4.41), can be derived in the same way by using the second inequality of $theorem5$.\n\\end{proof}\n\nTo get a computable generalization bound, it is possible to bound the Rademacher complexity of linear hypotheses with bounded weight vector, as shown by the following theorem.\n\n\\begin{theorem}\n\tLet $\\mathcal{X} = \\{x \\in \\mathbb{R}^N: ||x|| \\leq r\\}$. $S \\subset \\mathcal{X}$ be a sample of size $n$ and let $\\mathcal{H}= \\{x \\mapsto w \\cdot x : ||w||\\leq \\Lambda \\}$.\n\tThen the empirical Rademacher complexity of $\\mathcal{H}$ can be bounded as follows\n\t\\begin{equation}\n\t\\hat{\\mathcal{R}}_S(\\mathcal{H}) \\leq \\sqrt{\\frac{r^2\\Lambda^2}{n}}\n\t\\end{equation}\n\\end{theorem}\n\\begin{proof}\n\tAssume that $S=\\{x_1,...x_n\\}$.\n\t\\begin{align}\n\t\\hat{\\mathcal{R}}_S(\\mathcal{H}) &= \\mathbb{E}_{\\sigma}\\bigg[\\sup_{||w||\\leq \\Lambda}\\frac{1}{n} \\sum_{i=0}^{n}\\sigma_iw \\cdot x_i\\bigg] \\\\\n\t\\text{(Cauchy-Schwarz inequality)}&\\leq \\frac{\\Lambda}{n}\\mathbb{E}_{\\sigma} ||\\sum_{i=1}^{n}\\sigma_ix_i||\\\\\n\t\\text{(Jensens inequality)}&\\leq \\frac{\\Lambda}{n}\\bigg[ \\mathbb{E}_{\\sigma} ||\\sum_{i=1}^{n}\\sigma_ix_i||^2 \\bigg]^{1/2}\\\\\n\t&= \\frac{\\Lambda}{n}\\bigg[ \\mathbb{E}_{\\sigma} \\big[\\sum_{i,j=1}^{n}\\sigma_i\\sigma_j(x_i\\cdot x_j) \\big] \\bigg]^{1/2}\\\\\n\t\\text{(independent of $\\sigma_i$'s)}&= \\frac{\\Lambda}{n}\\bigg[ \\sum_{i=1}^{n}||x_i||^2 \\bigg]^{1/2} \\\\\n\t&\\leq \\frac{\\Lambda}{n}\\sqrt{nr^2} = \\sqrt{\\frac{r^2\\Lambda^2}{n}}\n\t\\end{align}\n\\end{proof}\nCombining $theorem7$ and $theorem8$ gives directly the following general\nmargin bound for linear hypotheses with bounded weight vectors:\n\\begin{corollary}\n\tAssume that $\\mathcal{X} = \\{x \\in \\mathbb{R}^N: ||x|| \\leq r\\}$ and linear hypotheses $\\mathcal{H}= \\{x \\mapsto w \\cdot x : ||w||\\leq \\Lambda \\}$\tthen, for any $\\delta>0$, with probability at least $1-\\delta$, for any $h\\in \\mathcal{H}$\n\t\\begin{equation}\n\tR(h) \\leq \\hat{R}_{\\rho}(h) + \\frac{2}{\\rho}\\sqrt{\\frac{r^2\\Lambda^2}{n}} + \\sqrt{\\frac{\\log\\frac{1}{\\delta}}{2n}}\n\t\\end{equation}\n\\end{corollary}\n\nThis generalization bound for linear hypotheses is remarkable, since it does\nnot depend directly on the dimension of the feature space, but only on the margin and the radius $r$ of the sphere containing the data.\nIt suggests that a small generalization error can be achieved when the second term $\\frac{r}{\\rho}$ is small, while the first term empirical margin loss is small. The\nlatter occurs when few points are either classified incorrectly or correctly, but with\nmargin less than $\\rho$.\\\\\n\nThe bound of the corollary gives a strong justification for margin-maximization\nalgorithms such as SVM. First, note that for $\\rho = 1$, the margin loss can be upper\nbounded by a convex function, which is called the hinge loss:\n\\begin{equation}\n\\Phi_1(x) \\leq max\\{1-x,0\\}\n\\end{equation}\n\nUsing this fact, the bound of the corollary implies that with probability at least\n$1-\\delta$, for all $h\\in \\mathcal{H} = \\{x \\mapsto w \\cdot x : ||w||\\leq \\Lambda \\}$\n\\begin{equation}\nR(h) \\leq \\frac{1}{n}\\sum_{i=1}^{n}\\xi_i + 2\\sqrt{\\frac{r^2\\Lambda^2}{n}} + \\sqrt{\\frac{\\log\\frac{1}{\\delta}}{2n}}\n\\end{equation}\n\nwhere $\\xi_i = max\\{1-y_i(w\\cdot x_i), 0\\}$. The objective function minimized by the SVM\nalgorithm has precisely the form of this upper bound: the first term corresponds to\nthe slack penalty over the training set and the second to the minimization of model complexity $||w||$, which is exactly the concept of structural risk minimization. \\\\\n\nAs already pointed out, the bounds just discussed do not directly depend on the\ndimension of the feature space and guarantee good generalization with a favorable\nmargin. Thus, they suggest seeking large-margin separating hyperplanes in a very\nhigh-dimensional space. \n\n\n\\subsection{Margin based generalization bound for multi classification}\nFor multi-class classification problem, assume that $\\mathcal{Y}=\\{1,2,...,k\\}$. First we have a labeled sample $S=\\{(x_1,y_1),...,(x_n,y_n)\\} \\in (\\mathcal{X}\\times \\mathcal{Y})^n$, with $x_1,...,x_n$ drawn i.i.d. according to underlying distribution and $y_i = f(x_i)$ according to the target function $f : \\mathcal{X} \\to \\mathcal{Y}$.\n\nGiven a classifier function $h : \\mathcal{X} \\to \\mathcal{Y}$, with the loss function defined by 0-1 loss, the generalization error of $h$is defined as\n\\begin{equation}\nR(h) = \\mathbb{E}_{X}[1_{h(X)\\ne f(X)}]\n\\end{equation}\nTo derive the margin-based generalization bounds for multi-class classification, as the binary case, we still expect to bound $R(h)$ by the margin loss $\\hat{R}_{\\rho}(h)$. What we need to do is generalize the definition of margin loss to multi-class case.\n\nIn the multi-class setting, a hypothesis is defined based on a scoring function $h: \\mathcal{X} \\times \\mathcal{Y} \\to \\mathbb{R}$. ($h$ can also be viewed as function mapping $\\mathcal{X}$ to $\\mathbb{R}^\\mathcal{Y}$). The label associated to point $x$ is the one resulting in the largest score $h(x, y)$:\n\\begin{equation}\nx \\mapsto \\arg\\max_{y\\in \\mathcal{Y}}h(x,y)\n\\end{equation}\n\nWe want the true label of $x$ obtains a high score compared to other labels. Based on this idea, we naturally define the margin $\\rho_h(x, y)$ of $h$ at a sample $(x, y)$:\n\\begin{equation}\n\\rho_h(x,y) = h(x,y) - \\max_{y'\\ne y}h(x,y')\n\\end{equation}\nWe can see that $h$ misclassifies $(x, y)$ iff $\\rho_h(x, y) \\leq 0$. Thus\n\\begin{equation}\nR(h) = \\mathbb{E}_{X,Y}[1_{\\rho_h(x, y) \\leq 0}] \n\\end{equation}\nAnd then, for any $\\rho > 0$, we can define the empirical margin loss for multi-classification as\n\\begin{equation}\n\\hat{R}_{\\rho}(h) = \\frac{1}{n} \\sum_{i=1}^{n}\\Phi_{\\rho}(\\rho_h(x_i, y_i))\n\\end{equation}  \nwhere $\\Phi_{\\rho}$ is the margin loss function we defined in previous section. Similarly the empirical margin loss is upper bounded by:\n\\begin{equation}\n\\hat{R}_{\\rho}(h) \\leq \\frac{1}{n} \\sum_{i=1}^{n} 1_{\\rho_h(x_i, y_i) \\leq \\rho}\n\\end{equation}\nwhere the bound means that $(x_i,y_i)$ is misclassified by $h$ or correctly classified but with confidence less than or equal\nto $\\rho$.\\\\\n\nFirst we need a lemma to derive the margin-based generalization bounds.\n\\begin{lemma}\n\tLet $\\mathcal{H}_1,...,\\mathcal{H}_l$ be $l$ hypothesis sets in $\\mathbb{R}^{\\mathcal{X}}$ and let $\\mathcal{G} = \\{ \\max\\{h_1,...,h_l\\} : h_i \\in \\mathcal{H}_i, i=1,...,l\\}$. Then, for any sample $S$ of size $n$, the empirical Rademacher complexity of $\\mathcal{G}$ can be upper bounded as follows:\n\t\\begin{equation}\n\t\\hat{\\mathcal{R}}_S(\\mathcal{G}) \\leq \\sum_{i=1}^{l} \\hat{\\mathcal{R}}_S(\\mathcal{H}_i)\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\tLet $S = (x_1,..., x_n)$. We first prove the results for $l = 2$. For any $h_1 \\in \\mathcal{H}_1$ and $h_2 \\in \\mathcal{H}_2$ we have\n\t\\begin{equation}\n\t\\max\\{h_1, h_2\\} = \\frac{1}{2}[h_1 + h_2 + |h_1-h_2|]\n\t\\end{equation}\n\tThus\n\t\\begin{align}\n\t\\hat{\\mathcal{R}}_S(\\mathcal{G}) &= \\frac{1}{n} \\mathbb{E}_{\\sigma} \\bigg[\\sup_{\\substack{h_1 \\in \\mathcal{H}_1 \\\\ h_2 \\in \\mathcal{H}_2}}\\sum_{i=1}^{n} \\sigma_i \\max\\{h_1(x_i), h_2(x_i)\\}\\bigg] \\\\\n\t&= \\frac{1}{2n} \\mathbb{E}_{\\sigma} \\bigg[\\sup_{\\substack{h_1 \\in \\mathcal{H}_1 \\\\ h_2 \\in \\mathcal{H}_2}}\\sum_{i=1}^{n} \\sigma_i(h_1(x_i)+h_2(x_i)+ |h_1-h_2|(x_i))\\bigg]\\\\\n\t&\\leq \\frac{1}{2}\\hat{\\mathcal{R}}_S(\\mathcal{F}_1) + \\frac{1}{2}\\hat{\\mathcal{R}}_S(\\mathcal{F}_2) + \\frac{1}{2n}\\mathbb{E}_{\\sigma} \\bigg[\\sup_{\\substack{h_1 \\in \\mathcal{H}_1 \\\\ h_2 \\in \\mathcal{H}_2}}\\sum_{i=1}^{n} \\sigma_i|h_1-h_2|(x_i)\\bigg]\n\t\\end{align}\n\tSince  $x \\mapsto |x|$\n\tis 1-Lipschitz, by Talagrand's lemma the last term can be bounded as:\n\t\\begin{align}\n\t&\\frac{1}{2n}\\mathbb{E}_{\\sigma} \\bigg[\\sup_{\\substack{h_1 \\in \\mathcal{H}_1 \\\\ h_2 \\in \\mathcal{H}_2}}\\sum_{i=1}^{n} \\sigma_i|h_1-h_2|(x_i)\\bigg] \\\\\n\t&\\leq \\frac{1}{2n}\\mathbb{E}_{\\sigma} \\bigg[\\sup_{\\substack{h_1 \\in \\mathcal{H}_1 \\\\ h_2 \\in \\mathcal{H}_2}}\\sum_{i=1}^{n} \\sigma_i(h_1-h_2)(x_i)\\bigg] \\\\\n\t&\\leq \\frac{1}{2n}\\mathbb{E}_{\\sigma} \\bigg[\\sup_{h_1 \\in \\mathcal{H}_1}\\sum_{i=1}^{n} \\sigma_ih_1(x_i)\\bigg] + \\frac{1}{2n}\\mathbb{E}_{\\sigma} \\bigg[\\sup_{h_2 \\in \\mathcal{H}_2}\\sum_{i=1}^{n} -\\sigma_ih_2(x_i)\\bigg]\\\\\n\t&= \\frac{1}{2}\\hat{\\mathcal{R}}_S(\\mathcal{F}_1) + \\frac{1}{2}\\hat{\\mathcal{R}}_S(\\mathcal{F}_2)\n\t\\end{align}\n\tThus we have\n\t\\begin{equation}\n\t\\hat{\\mathcal{R}}_S(\\mathcal{G}) \\leq \\hat{\\mathcal{R}}_S(\\mathcal{F}_1) + \\hat{\\mathcal{R}}_S(\\mathcal{F}_2)\n\t\\end{equation}\n\tIn general case we can write $\\max\\{h_1,...,h_l\\}$ as $\\max\\{h_1, \\max\\{h_2,...,h_l\\} \\}$ and use the result of $l=2$ to constantly decrease $l$.\n\\end{proof}\nLet $\\mathcal{H} \\subset \\mathbb{R}^{\\mathcal{X} \\times \\mathcal{Y}}$ be a hypothesis set, with $\\mathcal{Y}=\\{1,2,...,k\\}$. We define:\n\\begin{equation}\n\\Pi (\\mathcal{H}) = \\{x\\mapsto h(x,y) : h \\in \\mathcal{H}, y\\in \\mathcal{Y}\\}\n\\end{equation}\nGeneralization error can be bounded by margin loss and the Rademacher complexity of $\\Pi (\\mathcal{H})$ we just defined. The following theorem shows this result for multi-class classification.\n\\begin{theorem}[Margin bound for multi-class classification]\n\tFix $\\rho>0$. Then, for any $\\delta>0$, with probability at least $1-\\delta$, the following multi-class classification generalization bound holds for all $h \\in \\mathcal{H}$:\n\t\\begin{equation}\n\tR(h) \\leq \\hat{R}_\\rho (h) +\\frac{2k^2}{\\rho} \\mathcal{R}_n(\\Pi_1(\\mathcal{H})) + \\sqrt{\\frac{\\log\\frac{1}{\\delta}}{2n}}\n\t\\end{equation}\n\\end{theorem}\n\\begin{proof}\n\tThe first part of the proof is similar to the binary case. Define $\\mathcal{H}_1=\\{(x,y)\\mapsto \\rho_h(x,y) : h \\in \\mathcal{H} \\}$, $\\mathcal{H}_2 = \\{\\Phi_{\\rho}\\circ f : f\\in \\mathcal{H}_1\\}$. $\\mathcal{H}_2$ take values in $[0,1]$. By $theorem5$, with probability at least $1-\\delta$, for all $h \\in \\mathcal{H}$:\n\t\\begin{equation}\n\t\\mathbb{E}[\\Phi_{\\rho}(\\rho_h(x,y))] \\leq \\hat{R}_\\rho (h) + 2\\mathcal{R}_n(\\Phi_{\\rho}\\circ \\mathcal{H}_1) + \\sqrt{\\frac{\\log\\frac{1}{\\delta}}{2n}}\n\t\\end{equation}\n\tSince $1_{u\\leq 0} \\leq \\Phi_{\\rho}(u)$, the generalization error is bounded by the left-hand term $R(h) = \\mathbb{E}_{X,Y}[1_{\\rho_h(x, y) \\leq 0}] \\leq \\mathbb{E}[\\Phi_{\\rho}(\\rho_h(x,y))]$.\\\\\n\tSince the $\\frac{1}{\\rho}$-Lipschitzness of $\\Phi_{\\rho}$, by Talagrand's lemma we have $\\mathcal{R}_n(\\Phi_{\\rho}\\circ \\mathcal{H}_1) \\leq \\frac{1}{\\rho} \\mathcal{R}_n(\\mathcal{H}_1)$. So the next part of this proof is to bound $\\mathcal{R}_n(\\mathcal{H}_1)$.\n\t\\begin{align}\n\t\\mathcal{R}_n(\\mathcal{H}_1) &= \\frac{1}{n} \\mathbb{E}_{S,\\sigma}\\bigg[\\sup_{h \\in \\mathcal{H}}\\sum_{i=1}^{n}\\sigma_i\\rho_h(x_i,y_i)\\bigg] \\\\\n\t&\\leq\\frac{1}{n}\\sum_{y\\in\\mathcal{Y}}\\mathbb{E}_{S,\\sigma}\\bigg[\\sup_{h \\in \\mathcal{H}}\\sum_{i=1}^{n}\\sigma_i\\rho_h(x_i,y)1_{y=y_i}\\bigg]\\\\\n\t&=  \\frac{1}{n}\\sum_{y\\in \\mathcal{Y}}\\mathbb{E}_{S,\\sigma}\\bigg[\\sup_{h \\in \\mathcal{H}}\\sum_{i=1}^{n}\\sigma_i\\rho_h(x_i,y)(\\frac{2(1_{y=y_i})-1}{2} + \\frac{1}{2}) \\bigg]\\\\\n\t&\\leq \\frac{1}{2n}\\sum_{y\\in\\mathcal{Y}}\\mathbb{E}_{S,\\sigma}\\bigg[\\sup_{h \\in \\mathcal{H}}\\sum_{i=1}^{n}\\sigma_i\\epsilon_i \\rho_h(x_i,y)\\bigg] + \\frac{1}{2n}\\sum_{y\\in\\mathcal{Y}}\\mathbb{E}_{S,\\sigma}\\bigg[\\sup_{h \\in \\mathcal{H}}\\sum_{i=1}^{n}\\sigma_i \\rho_h(x_i,y)\\bigg]\\\\\n\t&= \\frac{1}{n}\\sum_{y\\in\\mathcal{Y}}\\mathbb{E}_{S,\\sigma}\\bigg[\\sup_{h \\in \\mathcal{H}}\\sum_{i=1}^{n}\\sigma_i \\rho_h(x_i,y)\\bigg]\n\t\\end{align} \n\twhere $\\epsilon_i=2(1_{y=y_i})-1$ and we use the fact that $\\sigma_i$ and $\\epsilon_i\\sigma_i$ have the same distribution.\\\\\n\tLet $\\Pi_1(\\mathcal{H})^{(k-1)} = \\{\\max\\{h_1,...,h_l\\} : h_i \\in \\Pi_1(\\mathcal{H}), i=1,...,k-1 \\}$, and then\n\t\\begin{align}\n\t\\mathcal{R}_n(\\mathcal{H}_1) &\\leq \\frac{1}{n}\\sum_{y\\in\\mathcal{Y}}\\mathbb{E}_{S,\\sigma}\\bigg[\\sup_{h \\in \\mathcal{H}}\\sum_{i=1}^{n}\\sigma_i \\big( h(x_i,y) - \\max_{y'\\ne y}h(x_i,y')\\big)\\bigg] \\\\\n\t&\\leq \\sum_{y\\in \\mathcal{Y}}\\bigg[ \\frac{1}{n}\\mathbb{E}_{S,\\sigma}\\bigg[\\sup_{h \\in \\mathcal{H}}\\sum_{i=1}^{n}\\sigma_i h(x_i,y)\\bigg] + \\frac{1}{n}\\mathbb{E}_{S,\\sigma}\\bigg[\\sup_{h \\in \\mathcal{H}}\\sum_{i=1}^{n} \\sigma_i \\max_{y'\\ne y}h(x_i,y')\\bigg]\\bigg] \\\\\n\t&\\leq \\sum_{y\\in \\mathcal{Y}}\\bigg[\\frac{1}{n}\\mathbb{E}_{S,\\sigma}\\bigg[\\sup_{h \\in \\Pi_1(\\mathcal{H})}\\sum_{i=1}^{n}\\sigma_i h(x_i)\\bigg] + \\frac{1}{n}\\mathbb{E}_{S,\\sigma}\\bigg[\\sup_{h \\in \\Pi_1(\\mathcal{H})^{(k-1)}} \\sum_{i=1}^{n}\\sigma_i h(x_i)\\bigg]\\bigg]\\\\\n\t&\\leq k\\bigg[\\frac{k}{m} \\mathbb{E}_{S,\\sigma}\\bigg[\\sup_{h \\in \\Pi_1(\\mathcal{H})}\\sum_{i=1}^{n}\\sigma_i h(x_i)\\bigg]\\bigg]\\\\\n\t&= k^2\\mathcal{R}_n(\\Pi_1(\\mathcal{H}))\n\t\\end{align}\n\twhere the last inequality utilize the $lemma5$.\n\\end{proof}\nFor some specific hypothesis sets, a simple upper bound can be derived for the\nRademacher complexity of $\\Pi_1(\\mathcal{H})$, making $theorem9$ more explicit and computable. We will show this for linear hypothesis with bounded weight vectors, similarly as the binary case.\\\\\n\nAssume that the samples can be represented over $\\mathbb{R}^N$. In multi-class classification, the hypothesis set is based on $k$ weight vectors $w_1,...,w_k \\in \\mathbb{R}^N$. Each $w_i$ defines a scoring function $x \\mapsto w_i\\cdot x$ and the class we predict for $x \\in \\mathcal{X}$ is given by\n\\begin{equation}\n\\arg\\max_{y\\in \\mathcal{Y}} w_y \\cdot x\n\\end{equation}\nWe denote by $W$ the matrix formed by these weight vectors $W = (w_1,...,w_k)^T$ and we define the p-norm of $W$ by \n\\begin{equation}\n||W||_p = \\big(\\sum_{i=1}^{k}||w_i||^p\\big)^{1/p}\n\\end{equation}\n\\begin{corollary}\n\tLet $\\mathcal{X} = \\{x\\in\\mathbb{R}^N : ||x||\\leq r \\} $. $\\mathcal{Y}=\\{1,2,...,k \\} $. $S \\subset \\mathcal{X}$ be a sample of size $n$ and let $\\mathcal{H}_p \\subset \\mathbb{R}^{\\mathcal{X}\\times \\mathcal{Y}}$,\n\t\\begin{equation}\n\t\\mathcal{H}_p = \\{(x,y) \\mapsto w_y \\cdot x : W = (w_1,...,w_k)^T, ||W||_p\\leq \\Lambda \\}\n\t\\end{equation}\n\tThen for any $n \\geq 1$, the Rademacher complexity of $\\Pi_1(\\mathcal{H}_p)$ can be bounded as\n\t\\begin{equation}\n\t\\mathcal{R}_n(\\Pi_1(\\mathcal{H}_p)) \\leq \\sqrt{\\frac{r^2\\Lambda^2}{n}}\n\t\\end{equation}\n\\end{corollary}\n\\begin{proof}\n\tSince $||w_i|| \\leq \\big(\\sum_{i=1}^{k}||w_i||^p\\big)^{1/p} = ||W||_p\\leq \\Lambda$ for all $i=1,...,k$. Thus $\\Pi_1(\\mathcal{H}_p) \\subset \\{x \\mapsto w \\cdot x : ||w||\\leq \\Lambda \\}$. So the corollary is concluded by $Theorem8$.\n\\end{proof}\n\n\\begin{corollary}\n\tAssume that $\\mathcal{X} = \\{ x\\in \\mathbb{R}^N : ||x|| \\leq r \\}$, $\\mathcal{Y}=\\{1,...,k\\}$ and $\\mathcal{H}_p = \\{(x,y) \\mapsto w_y \\cdot x : W = (w_1,...,w_k)^T, ||W||_p\\leq \\Lambda \\}$, then for any $\\delta >0$m with probability at least $1-\\delta$, for any $h \\in \\mathcal{H}_p$\n\t\\begin{equation}\n\tR(h) \\leq \\hat{R}_{\\rho}(h) + \\frac{2k^2}{\\rho}\\sqrt{\\frac{r^2\\Lambda^2}{n}} + \\sqrt{\\frac{\\log\\frac{1}{\\delta}}{2n}}\n\t\\end{equation}\n\\end{corollary}\n\nNext, we simply describe an algorithm of \\textbf{Multi-calss SVMs} that can be derived directly from the theoretical guarantees of $Corollary6$.\\\\\nDeifine $\\xi_i = \\max\\{1-(w_{y_i}\\cdot x_i-\\max_{y'\\ne y_i}(w_{y'}\\cdot x_i)), 0\\}$, and we have for any $\\delta>0$, with probability at least $1-\\delta$, for all $h\\in \\mathcal{H}_2 = \\{(x,y) \\mapsto w_y \\cdot x : W = (w_1,...,w_k)^T, \\sum_{i=1}^{k}||w_i||^2 \\leq \\Lambda^2 \\}$,\n\\begin{equation}\nR(h) \\leq \\frac{1}{n}\\sum_{i=1}^{n}\\xi_i + 2k^2\\sqrt{\\frac{r^2\\Lambda^2}{n}} + \\sqrt{\\frac{\\log\\frac{1}{\\delta}}{2n}}\n\\end{equation}\nAn algorithm based on this theoretical guarantee consists of minimizing the right-hand side, that is, minimizing the empirical margin loss corresponding to the sum of the slack variables $\\xi_i$, and another one minimizing $\\Lambda^2$ or equivalently $\\sum_{i=1}^{k}||w_i||^2$. This precisely define the multi-class SVM algorithm, which is a convex optimization problem:\n\\begin{align}\n\\min_{\\xi, W} \\sum_{i=1}^{n}\\xi_i +& \\frac{C}{2}\\sum_{i=1}^{k}||w_i||^2\\\\\n\\text{subject to}\\quad & \\forall i=1,...,k , \\forall j\\ne y_i \\\\\n&w_{y_i}\\cdot x_i \\geq w_j\\cdot x_i +1-\\xi_i\n\\end{align}\nAfter we have learnd $W$, the prediction function is defined of the form $x \\mapsto \\arg\\max_{y\\in\\mathcal{Y}} w_y \\cdot x$.\n", "meta": {"hexsha": "82a9b8154385cbad229f9167cf0c110c02c1590b", "size": 122961, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ML-Theory.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/ML-Theory.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/ML-Theory.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 74.4766807995, "max_line_length": 708, "alphanum_fraction": 0.6872666943, "num_tokens": 43345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.8289388019824947, "lm_q1q2_score": 0.7216718622499168}}
{"text": "% Template:     Informe/Reporte LaTeX\n% Documento:    Archivo de ejemplo\n% Versión:      5.1.5 (15/05/2018)\n% Codificación: UTF-8\n%\n% Autor: Francisco Muñoz P.\n%        Facultad de Ciencias Físicas y Matemáticas\n%        Universidad de Chile\n%        fjmunoz95@gmail.com, frmunoz@dcc.uchile.cl\n%\n% Derechos del template corresponden a Pablo Pizarro. pablo.pizarro@ing.uchile.cl\n% Manual template: [http://latex.ppizarror.com/Template-Informe/]\n% Licencia MIT:    [https://opensource.org/licenses/MIT/]\n\n% define some usefull commands\n\\newcommand\\FF{\\mathcal{F}}\n\\newcommand\\prd{Phys. Rev. D}\n\\newcommand\\MF{\\text{MF}}\n\\newcommand\\IL{\\int_{-\\infty}^{\\infty}}\n\\newcommand\\WM{\\text{WMF}}\n\\newcommand\\wmf[2]{(#1|#2_{\\MF})^{\\WM}_{t_0}}\n% NUEVA SECCIÓN\n\\section{Introduction}{\\label{sec:intro}}\n\\newp por definir.\n\n\\section{Fourier Transform}{\\label{sec:ft}}\n\\newp The Fourier Transform it's a Mathematical tool that allow us to decompone singals by a given dictionary or in other words, to apply a change of basis to a given signal. Thinking on a continuous space for a signal $s(t)$, it's Fourier Transform is given by the following integral, where $i =  \\sqrt{-1}$ denotes the imaginary unit:\n\\insertequation[\\label{ft:ft}]{\\tilde{s}(f) = \\int_{-\\infty}^{\\infty} s(t)e^{-2i\\pi f t} dt = \\FF[s(t)]}\n\n\\newp And the inverse transform is:\n\n\\insertequation[\\label{ft:ift}]{s(t) = \\int_{-\\infty}^{\\infty} \\tilde{s}(f)e^{2i\\pi f t } df = \\FF^{-1}[\\tilde{s}(f)]}\n\n\\subsection{Properties of the Fourier Transform}{\\label{sec:ft::subsec:propft}}\n\\newp Some usefull properties of the Fourier Transform are:\n\t\\begin{description}\n\t\n\t\\item \\textbf{Fourier Transform is a linear operator}. This means that, given a constant $a$ and \t\tfunctions $s(t)$, $h(t)$, we can write:\n\t\\insertequation[\\label{propFT:linear1}]{\\FF[s(t) + h(t)] =  \\FF[s(t)] + \\FF[h(t)]} \n\t\\insertequation[\\label{propFT:linear2}]{\\FF[as(t)] = a\\FF[s(t)] }\n\n\t\\item \\textbf{A time-shift impart a phase in the fourier Transform.} For a given function $s(t)$, it's satisfied:\n\t\\insertequation[\\label{propFT:time-shift}]{\\FF[s(t - t_0)] = \\FF[s(t)]e^{-2i\\pi f t_0}}\n\t\n\t\\newp also can be obtained a conjugate of the transform by:\n\t\n\t\\insertequation[\\label{propFT:time_shift2}]{\\FF[s(t_0 - t)] = \\FF[s(t)]^{*}e^{-2\\pi f t_0}}\n\n\t\\item \\textbf{The Power Spectrum equal to square of absolute value of the Fourier Transform.} This computation allow us to remove the phase and the complex part which is changed to real by the absolute function.\n\t\n\t\\insertequation[\\label{psd}]{\\mathcal{P}_s = |\\FF[s(t)]|^{2}}\n\t\n\t\\item \\textbf{Convolution Theorem.} The definition of convolution for two functions $s(t)$ and $h(t)$, is given by:\n\t\n\t\\insertequation[\\label{convolution1}]{[s(t) * h(t)] = [h(t) * s(t)] = \\int_{-\\infty}^{\\infty} s(t-\\tau) h(\\tau) d\\tau}\n\t\n\tCalculating the Fourier Transform of this convolution leads to:\n\t\n\t\\insertequation[\\label{convolution2}]{\\FF[s * h] = \\FF[s] \\cdotp \\FF[h]}\n\t\n\tAlso, Fourier Transform of a point-wise multiplication of two functions leads to a convolution of Fourier Transforms:\n\t\n\t\\insertequation[\\label{convolution3}]{\\FF[s(t) \\cdotp h(t)](f) = \\FF[s](f) * \\FF[h](f)}\n\t\n\tIn practice using Fourier to calculate a convolution is faster than just calculate the convolution, that's why this is a very important concept.\n\t\n\t\\item \\textbf{Parseval's Formula}, it says that for $s(t)$ and $h(t)$ square-integrable functions with fourier transforms given by (\\ref{ft:ift}) and (\\ref{ft:ft}), it's satisfied:\n\t\n\t\\insertequation[\\label{parseval}]{\\int_{-\\infty}^{\\infty} s(t)h^{*}(t)dt = \\int_{-\\infty}^{\\infty}\\tilde{s}(f)\\tilde{h}^{*}(f) df}\n\t\n\t \\item \\textbf{Plancherel Theorem}, it's a direct consecuence of the Parseval Formula but in the sence of energy:\n\t \n\t \\insertequation[\\label{plancherel}]{\\int_{-\\infty}^{\\infty} \\mid x(t) \\mid^{2} (t)dt = \\int_{-\\infty}^{\\infty}\\mid \\tilde{s}(f)\\mid^{2} df} \t\n\t\n\t\\item \\textbf{Correlation.} The cross-correlation of two real signals $s(t)$ and $h(t)$ can be defined in the sense of a convolution by:\n\t\n\t\\insertequation[\\label{corr_as_conv}]{R_{hs}(t) = h \\star s = h^{*}(-t) \\ast s(t) = s(t) \\ast h^{*}(-t)}\n\t\n\t\\newp We are more interested in real signals when $s^{*}(-t) = s(-t)$ but the calculations will be in the general case. Using (\\ref{convolution1}) we get:\n\t\n\t\\insertequation[\\label{corr1}]{R_{hs}(t) = \\int_{-\\infty}^{\\infty} s(\\tau - t) h^{*}(-t) dt}\n\t\n\t\\newp Applying a simple change of variables($t \\longrightarrow -t$) we get:\n\t\n\t\\insertequation[\\label{corr2}]{R_{hs}(t) = \\int_{-\\infty}^{\\infty} s(\\tau + t)h^{*}(t) dt}\n\t\n\t\\newp Using the Time shift property (\\ref{propFT:time-shift}) with the Parseval's Formula (\\ref{parseval}):\n\t\n\t\\insertequation[\\label{corr3}]{R_{hs}(t) = \\int_{-\\infty}^{\\infty} \\tilde{s}(f)\\tilde{h}^{*}(f)e^{2i\\pi f \\tau} df}\n\t\n\t\\newp And this can be resumed as Fouriers Transforms:\n\t\n\t\\insertequation[\\label{corr4}]{R_{hs}(t) = \\FF^{-1}[\\FF[s] \\FF[h]^{*}] = \\FF^{-1}[\\FF[s(t) \\star h^{*}(-t)]]}\n\t\n\t\\newp A particular behavior is when calculating the auto-correlation of a signal, which correspond to the Inverse Fourier Transform of the Power Spectral Density:\n\t\n\t \\insertequation[\\label{autocorr}]{R_{hh} = \\FF^{-1}[\\mid \\tilde{h}(f)\\mid^{2}] = \\FF^{-1}[\\mathcal{P}_h(f)]}\n\t \n\\end{description}\n\n\\subsection{Some useful Fourier Transforms}{\\label{subsec_ftusefull}}\n\\begin{description}\n\t\\item \\textbf{Fourier Transform of a Sinusoid is a Delta Function.} \\texttt{need to insert a figure in this section}\n\t\\insertequation[\\label{sindelta}]{\\FF[Cos(2\\pi f_0t)] = \\frac{1}{2}[\\delta(f - f_0) + \\delta(f + f_0)]}\n\t\n\t\\item \\textbf{Fourier Transform of a Dicar Comb is a Dirac Comb.} The Dirac Comb is an infinite sequence of Dirac delta function placed at even intervals of size $T$:\t\n\n\t\\insertequation[\\label{diraccomb}]{III_T(t) = \\sum_{n=-\\infty}^{\\infty} \\delta(t-nT)}\n\t\n\tthus, the fourier Transform correspond to a Dirac Comb in the frequency domain:\n\t\n\t\\insertequation[\\label{diracft}]{\\FF[III_T(t)] = \\frac{1}{T} III_{1/T}(f)}\n\n\\end{description}\n\n\\subsection{Window Function}{\\label{subsec_window}}\n\\newp The Continuous Fourier Transform use the particularity that continuous functions are well defined for all times ($-\\infty < t < \\infty$). This is just an idealization that doesn't work on real signals because this only involve a finite span of time with some finite rate of sampling. The Fourier Transform of a discrete measured data will no longer be just the transform of the continuous underlying function, but rather the transform of the point-wise product of the signal($s(t)$) and the observing window($W(t)$), which will be a rectangular window of dirac comb.\n\n\\insertequation[\\label{window1}]{s_{obs}(t) = s(t)W(t)}\n\n\\newp Using the convolution theorem (ec. \\ref{convolution3}) the transform of eq. \\ref{window1} will be:\n\n\\insertequation[\\label{window2}]{\\FF[s_{obs}(t)] = \\FF[s(t)] * \\FF[W(t)]}\n\n\\subsubsection{Fixing periodicity}{\\label{subsubsec_fixperiod}}\n\n\\newp Fourier Transform works only for periodic signals, this means, for signals where its first point has exactly the same value as the last point (continuity in edges). But in real world, a measured signal has always some grade of noise which lead to a discontinuity in the edges. In order to fix this discontinuity we use a window function.\n\n\\newp For these cases, the window function will not be a rectangular, or at least, usualy we don't want to use this kind of window. The most useful windows are kind-of curve like \\textit{Hann window}, \\textit{Blackmann window} or \\textit{Tukey window}. We are going to use mostly the \\textit{Tukey window} which is: \\texttt{should use a example plot here for all windows.}\n\n\\insertequation[\\label{tukey}]{w(n) = \\begin{cases}\n\\frac{1}{2} \\left[1 + cos\\left(\\pi \\left(\\frac{2n}{\\alpha (N-1} - 1  \\right) \\right) \\right] & 0 \\leq n < \\frac{\\alpha(N-1)}{2} \\\\\n1 & \\frac{\\alpha(N-1)}{2} \\leq n \\leq (N-1)(1-\\frac{\\alpha}{2})\\\\\n\\frac{1}{2} \\left[1 + cos\\left(\\pi \\left(\\frac{2n}{\\alpha (N-1} - \\frac{2}{\\alpha} +  1  \\right) \\right) \\right] & (N-1)(1 - \\frac{\\alpha}{2} < n \\leq (N-1))\n\\end{cases}}\n\n\\newp Here, $\\alpha$ define the form of the window, when $\\alpha=0$ we get a rectangular window and for $\\alpha=1$ we get a \\textit{Hann window}.\n\\subsection{Nyquist-Shannon Sampling Theorem}{\\label{subsec_NSST}}\n\\newp sampling is a process of converting a signal (function-like of continuous time and/or space) into a numeric sequence, thus the sampling theorem states that, if a function $f(x)$ contains no frequencies higher than B hertz, it is completely determined by givin its ordinates at a series of points spaced $1/(2B)$ seconds apart. This means that a suficient sample-rate for uniform sampling is therefore anything larget than $2B$ samples per second, or from other perspective, for a given sample rate $f_s$, \\textbf{perfect reconstruction is guaranteed possible} for a bandlimit $B < f_s/2$.\n\n\\newp In the most general case of non-uniform sampling, this theorem states that a band-limited signal can be perfectly reconstructed from its samples if the \\textbf{average sampling rate} satisfies the Nyquist condition. this means that even if uniformly spaced samples can be easier reconstruced (easier algorithms), it is not a necessary condition for perfect reconstruction.\n\n\\subsection{Nyquist frequency}{\\label{subsec_nyqfreq}}\n\\newp The nyquist frequency is defined as half of the sampling rate  of a discrete signal when we have evenly-sampled data\n\n\\insertequation[\\label{nyq1}]{\\nu_N = 0.5 f_s}\n\n\\newp And correspond to the highest frequency limit of one interval over which a periodogram is uniquely defined. If we go far away from this nyquist limit, the periodogram (and the simple Fourier Transform) will have repeated information. \n\n\\newp For unevenly-sampled data, the symmetry that allow to define this frequency as eq. \\ref{nyq1} is broken and using an average sampling rate as in the Sampling Theorem doesn't work. In order to find a best approximation to the real nyquist frequency (called \\textit{pseudo-nyquist frequency}) there are several methods in literature. The one implemented here correspond to the method delevoped by Koen \\cite{koen-nyqFreq} who give a calculation formula to be solved for the nyquist frequency for arbitrary time spacing of measurements, this is the smallest positive root of\n\n\\insertequation[\\label{koen1}]{SS(\\nu) = \\sum_{l=1}^{N-1}\\sum_{k=l+1}^{N} [sin 2 \\pi \\nu (t_k - t_l)]^2 = 0}\n\n\\newp This calculation will take $O(N_{\\nu}N^2)$ where $N_{\\nu}$ correspond to the number of frequencies to try in the formula. Since is a very expensive calculation, generaly it is more useful to know what is the maximum frequency that we are interested in.\n\n\\subsection{Discrete Fourier Transform}{\\label{subsec_dft}}\n\\newp We can pass from cotinuous space to discrete space by applying a Rectangular Window with a dirac comb (eq. \\ref{window2}) This is because the delta serve to collapse the Fourier Integral into a Fourier Sumatory. Considering the most general case, where a continuous signal $s(t)$ is observed at an \\textbf{irregular sampling} of size $N_t$, leads to dirac comb:\n\n\\insertequation[\\label{irr-dirac-comb}]{III_{\\{t_j\\}}(t) = \\sum_{j = 1}^{N_t} \\delta(t - t_j)}\n\n\\newp Using this, the direct transform will be:\n\n\\insertequation[\\label{to-discrete1}]{\n\\begin{aligned}[b]\n\\FF[s_{obs}(t)] = \\tilde{s}_{k} & = \\FF[s(t){III}_{\\{t_j\\}}(t)]  \\\\\n\\tilde{s}_{k} & = \\int_{-\\infty}^{\\infty}s(t)\\sum_{j = 2}^{N_t} \\delta(t - t_j) e^{-2\\pi i f t} dt \\\\\n\\tilde{s}_{k} & = \\sum_{j = 1}^{N_t}\\int_{-\\infty}^{\\infty}s(t)\\delta(t - t_j) e^{-2\\pi i f t} dt  \\\\\n\\tilde{s}_{k} & = \\sum_{j = 1}^{N_t} s_je^{-2\\pi i t_j k \\Delta f}\n\\end{aligned}\n}\n\n\\newp Following the same idea we can get the inverse transform, considering that the \\textbf{frequencies will always be in a regular grid} so $f_k = k \\Delta f$:\n\n\\insertequation[\\label{to_discrete2}]{s_j = \\Delta f \\sum_{k = 1}^{N_f} \\tilde{s}_k e^{2 \\pi i t_j k \\Delta f}}\n\n\\newp the total number of frequencies ($N_f$) and how we define the $\\Delta f$ will be explained more clearly in the next sections.\n\n\\subsection{Frequency Sampling}{\\label{subsec_freqsampling}}\n\\newp Since we are considering the most general case of Fourier Transform for non-uniform sampling, it's neccessary to define clearly the frequency grid, more precisely we need to define the frequency limit on the low end and the high end, in addition to define the grid spacing.\n\\begin{description}\n\n\\item \\textbf{low-end frequency limit.} For a set of observations in a time interval of lenght $T$, a signal with frequency $1/T$ will complete exactly one oscillation in the observing window. Chosing a low-end frequency limit could be this frequency or just set the minimum frequency to zero for simplicity. Also is posible to give a custom low-end limit based on what frequencies we want to explore. If we have complex signals we will ned to define a negative low-end frequency limit.\n\n\\item \\textbf{high-end frequency limit.} In order to not miss information that could be relevant, it's neccessary to look for the maximum frequency that could give us information, this is given by the nyquist frequency defined in section \\ref{subsec_nyqfreq}. Also is posible to give a custom high-end limit based on what frequencies we want to explore.\n\n\\item \\textbf{grid spacing.} Choose the correct grid spacing it's also an important point, if we use a too fine grid will leads to unnecessarily long computational times, while, use a grid too coarse leads to missing narrow peaks that fall between grid points. A razonable idea is to choose grid spacing smaller than the spected width of the periodogram peaks, these peaks has a widht of $\\sim 1/T$ where $T$ is the duration of the window function. To ensure that our grid sufficiently samples each peak, we can over-sample by some factor ($n_0$) using a grid spacing of\n\n\\insertequation[\\label{grid-spacing}]{\\Delta f = \\frac{1}{n_0 T}}\n\n\\newp And with this we can know the total number of frequencies to evaluate\n\n\\insertequation[\\label{n-frequencies}]{N_f = n_0 T (f_{max} - f_{min})}\n\n\\newp choose the value of $n_0$ is kind-of arbitrary and we can find uses in literature in the range of $n_0 = 5$ to $n_0 = 10$ \\cite{vanderplas-lombScargle}.\n\n\\end{description}\n\n\\section{Fast Fourier Transform}\n\\newp The normal Discrete Fourier Transform showed in section \\ref{subsec_dft} takes times $O(N^2)$ to compute wheter is the direct or the inverse transform, this is a very expensive computation and can be improved to $O(N log(N))$ usign the algorithm of the Fast Fourier Transform(FFT). \\texttt{NEED TO READ MORE ABOUT THE ALGORITHM}\n\n\\subsection{Non-uniform Fast Fourier Transform}\n\\newp The same idea used in the optimization of the Discrete Fourier Tranform for evenly-sampled data called FFT can be used for unevnely-sampled data and we call this Non-unifor Fast Fourier Transform, using the same considerations. \\texttt{NEED TO EXPLORE MORE THE ALGORITHM}\n\n\\section{Fourier Transform as Signal Decomposition}\n\\newp An alternative approach to realize the Fourier Transfrom is to do a Signal Decomposition by regression, here we just take our data and find what coeficients give the best fit to the original data given a Dictionary which can be interpreted as a change of basis, if we use for the Dictionary the fourier Matrix, then the coeficients of the signal decomposition will be the values of the Fourier Transform.\n\n\\subsection{What is a Signal Decomposition?}\n\\newp given a signal $s \\in \\mathbb{R}^{N}$ we want to find a representative set of coeficients $\\beta \\in\\mathbb{R}^{M}$ such that:\n\n\\insertequation[\\label{signaldecom1}]{\\hat{s} = \\Phi \\hat{\\beta}}\n\n\\newp Where $\\Phi \\in \\mathbb{R}^{N \\times M}$ is known as the dictionary matrix. Every column of this dictionary matrix correspond to an \\textit{atom}, i.e. the constituents of signal $s$. A dictionary is called \\textit{complete} when $M = N$. $\\Phi$ can be either pre-defined or learned from data. We will select the atoms previously, for example, in a Fourier Dictionary we choose the atoms by knowing what frequencies we want.\n\\newp Solve eq. \\ref{signaldecom1} for a complete dictionary that is invertible means find $\\hat{\\beta}^{*}$ such that:\n\n\\insertequation[\\label{signaldecom2}]{\\hat{\\beta}^{*} = \\Phi^{-1} \\hat{s}}\n\n\\newp When the matrix is not invertible, the solution to eq. \\ref{signaldecom1} is obtained by solving the  Least Square problem:\n\n\\insertequation[\\label{leastsquare}]{\\underset{\\hat{\\beta}}{\\text{min}} \\frac{1}{2} \\| \\hat{s} - \\Phi\\hat{\\beta} \\|^{2}_{2}}\n\n\\newp Where $\\| \\cdotp \\|_{2}^{2}$ means the square of the L2-norm, the solution to this problem is:\n\n\\insertequation[\\label{pseudoinv1}]{\\hat{\\beta}^{*} = (\\Phi^{T}\\Phi)^{-1}\\Phi^{T} \\hat{s}}\n\n\\newp Which requieres $(\\Phi^{T}\\Phi)$ to be invertible, means, having linear independent columns. Te matrix $(\\Phi^{T}\\Phi)^{-1}\\Phi^{T}$ correspond to the left Moore-Penrose pseudo-inverse of $\\Phi$.\n\n\\newp Then complete dictionary is not often the better dictionary, here we are more interested in the overcomplete dictionary, this is a dictionary with more atoms than data samples ($M > N$). For overcomplete dictionaries eq. (\\ref{signaldecom1}) is under-determined and many solutions may exists. When $\\Phi$ is overcomplete, the product $(\\Phi^{T}\\Phi)$ is always a singular matrix and then (\\ref{pseudoinv1}) cannot be compute. In order to get an optimal its neccessary to include a regularization coeficient which impose conditions to help choose one of the many solutions of the underdetermined system. There are two kind of regularization usualy used, one is smooth-ness and the other is spartisy, the first refers to the least-rough or least-complex solution, this condition usualy leads to dense solutions with almost all points non-zeros, and the second one refeers to solution with less non-zero points and thus a more sparse solution. here we will show many method that try to find a good $\\beta$.\n\n\\subsubsection{Ridge Regression}\n\\newp this is an example of a regression that use as regularization smooth-ness, the ridge regression is defined as:\n\n\\insertequation[\\label{ridge1}]{\\underset{\\hat{\\beta}}{\\text{min}}\\alpha \\| \\beta \\|^{2}_{2} + \\| s - \\Phi \\beta \\|_{2}^{2}}\n\n\\newp Where $\\alpha > 0$ is the trade-off between reconstruction error and smooth-ness of the solution. Te solution to \\ref{ridge1} is:\n\n\\insertequation[\\label{ridge2}]{\\beta^{*} = (\\Phi^{T}\\Phi + \\alpha I)^{-1}\\Phi^{T}s}\n\n\\textbf{\\texttt{UNCOMPLETE, NEED TO EXPLAIN MORE METHODS}}\n\n\\subsection{Fourier Dictionary}\n\n\\newp The discrete Fourier Transform from section \\ref{subsec_dft} can be interpreted as a change of basis of the signals which means change the time representation of the signal $\\vec{s}$ to a frequency representation $vec{\\beta}$ using a sine/cose basis. This will means that we can write:\n\n\\insertequation[\\label{signaldecomp1}]{\\vec{s} = \\Phi \\cdotp \\vec{\\beta}}\n\n\\newp Where $\\Phi$ is the Dictionary/Basis to use in the change of representation. This Dictionary is the Fourier Matrix where every colummn (atom $\\phi$) correspond to a sine/cosine wave of a given frequency $k\\Delta f$:\n\n\\insertequation[\\label{signaldecomp2}]{\\phi_k = e^{2 \\pi i t_j k \\Delta f} \\forall t_j}\n\n \\newp and in order to represent Direct and Inverse Fourier Transform Correctly it's neccessary to use an orthogonal Basis which means an square matrix Dictionary with a defined Inverse, if this matrix is defined correctly (ofter in the evenly-sampled case) his adjoint will be his inverse in a way that allow us to define the Adjoint Transform and use it as the Inverse Transform.\n \n\\insertequation[\\label{signaldecom3}]{\\vec{\\beta} = \\Phi^{T} \\cdotp \\vec{s}}\n \n\\newp Sadly for unevenly-sampled data we usually want to compute a frequency grid higher than the time grid producing a oversampling Dictionary, and even if we choose the same number of frequencies than times, there is no guarantee that the resulting Fourier Matrix will be unitary and invertible in a way that his adjoint transform be his Inverse Transform. Because of this, we need to look for a way to compute the Pseudo-inverse of the dictionary ($\\Phi^{+}$) instead of the Inverse, usualy we can compute this by Single Value Decompostion, where the left decomposition (known as ):\n\n\\insertequation[\\label{pseudoinverse}]{\\Phi^{+}}\n\n\\textbf{\\texttt{UNCOMPLETE}}  \n\n\\section{Signal Detection}{\\label{sec:signalDetect}}\n\\newp Once we know how to interprete correctly some datas in frequency domain, using Non Unifor Fast Fourier Transform or Signal Decomposition, we are ready to work on the signal detection, i.e., on the search of a known signal in the observed data. This idea comes from the idealization of our data as an underlying signal plus additive \\textbf{Wide-Sense Stationary} (WSS) Gaussian noise, then it is posible, through use of linear filters, to find what is this underlaying signal by comparing the observed data to known waveforms. Linears filters are defined as convolution of input data $x(t)$ with an impulse response filter wich is just the time reverse of the template waveform $h(t)$, for this we define the product $(x|h)$:\n\n\\insertequation[\\label{signalDetect:linearFilter}]{(x|h)_{t_0} = [x(t) * h(-t)](t_0) = \\int_{-\\infty}^{\\infty} \\tilde{x}(f)\\tilde{h}^{*}(f) e^{2\\pi i f t_0} df}\n\n\\newp Here we have used eq. (\\ref{corr_as_conv}) to write this a correlation. It's also important to notice that in practice we should do a $causal$ time reverse for the impulse response $h(-t) \\longrightarrow h(T-t)$ where $T$ is the total duration of the template waveform, but if we always use templates of same duration as the data window, then this factor is not important due to the periodicity in Fourier Transform leadin to $h(T-t)=h(-t)$.\n\n\\newp And the optimal Filter is just find the filter that optimize a given quantity. The theory that we are going to use correspond to the \\textbf{Matched Filter} (MF) which maximize the \\textbf{Signal-to-Noise Ratio} (SNR) of the observed data, and in order to do this we need to consider an input signal to the filter composed of \\textbf{only White Gaussian Noise} which is a WSS Gaussian noise but with constant spectral density.\n\n\\newp Obviously the raw data detected by any deviced will have mostly colored Gaussian Noise, this means, a WSS Gaussian noise with non-constant spectral density, then it is necessary to do a previous filter which is called \\textit{Whitening Filter} (WF) to clear the noise.\n\n\\subsection{Whitening Filter}{\\label{sec:signalDetect::ssec:WF}}\n\n\\newp For an observed data $x(t)$ of additive WSS Gaussian colored noise $n(t)$, which could have or not an underlying signal $s(t)$, we define the whitening Filter with impulse response $h_w(-t)$ as the optimal filter when its output due to the input noise $n(t)$ is white, with variance $\\sigma^{2}$. This can be write as:\n\n\\insertequation[\\label{whiteningFilter:whitenData}]{(x|h_w)_{t_0} = (s|h_w)_{t_0} + (n|h_w)_{t_0} \\text{such that} var = \\mathbb{E}[(n|h_w)^{2}] = \\sigma^{2}}\n\n\\newp Working a litle with this variance we will get:\n\n\\insertequation[\\label{whiteningFilter:noiseVarAsCovarFunct}]{\n\\begin{aligned}[b]\n\\mathbb{E}[|(n|h_w)|^{2}]\t& = \\mathbb{E}[(n|h_w)(n|h_w)^{*}] \\\\\n\t\t\t\t\t\t& = \\mathbb{E}\\left[\\int_{-\\infty}^{\\infty} n(t_0 + t_1)h_w^{*}(t_1) dt_1 \\left(\\int_{-\\infty}^{\\infty} n(t_0 + t_2) h_w^{*}(t_2) dt_2 \\right)^{*}\\right] \\\\\n\t\t\t\t\t\t& = \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} h_w^{*}(t_1) \\mathbb{E}[n(t_0 + t_1) n(t_0 + t_2)^{*}] h_w(t_2) dt_1 dt_2 \\\\\n\\end{aligned}}\n\n\\newp In order to work with the covariance $\\mathbb{E}[n(t_0 + t_1) n(t_0 + t_2)^{*}]$ we need to set some considerations, first the noise used will be a 0 mean random noise, in a way that $\\mathbb{E}[n(t)] = 0$, second, the noise will be invariant in time (stationary) so $n(t + t_0) = n(t)$, with this que covariance will be reduced to:\n\n\\insertequation[\\label{whiteningFilter:noiseCovar}]{\\mathbb{E}[n(t_0 + t_1) n(t_0 + t_2)^{*}] = \\mathbb{E}[n(t_1)n^{*}(t_2)] = k_n(t_1, t_2) = k_n(\\tau)}\n\n\\newp Where we have used $\\tau = t_1 - t_2$, $k_n(\\tau)$ correspond to the auto-correlation function of the noise. \\textbf{Bochner's theorem} states that the covariance function of a stationary process can be represented as the fourier transform of a positive finite measure\\cite{gauss-procss}:\n\n\\insertequation[\\label{whiteningFilter:noiseCovTransf}]{k_n(\\tau) = \\int S_n(f)e^{2\\pi i f \\tau} df}\n\n\\newp This transform is defined as the two-sided power spectral density being a real and positive function with no zero values. Using this on eq. (\\ref{whiteningFilter:noiseVarAsCovarFunct}) we get:\n\n\\insertequation[\\label{whiteningFilter:noiseVar}]{\n\\begin{aligned}[b]\n\\mathbb{E}[|(n|h_w)|^{2}]\t& = \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} h_W^{*}(t_1) k_n(t_1 - t_2) h_w(t_2) dt_1 dt_2 \\\\\n\t\t\t\t\t\t& =\\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} h(t_2) \\left( \\int_{-\\infty}^{\\infty} S_n(f)e^{2\\pi i f (t_1 - t_2)} df\\right) h_w^{*}(t_1)  dt_1 dt_2 \\\\\n\t\t\t\t\t\t& = \\int_{-\\infty}^{\\infty} \\left( \\int_{-\\infty}^{\\infty} h_w^{*}(t_1)e^{2\\pi i f t_1} dt_1 \\right) S_n(f) \\left( \\int_{-\\infty}^{\\infty} h_w(t_2) e^{-2\\pi i f t_2} dt_2 \\right) df \\\\\n\t\t\t\t\t\t& = \\int_{-\\infty}^{\\infty}\\tilde{h}_w^{*}(f) e^{-2\\pi i f T} S_n(f) \\tilde{h_w}(f) e^{2\\pi i f T} df \\\\\n\t\t\t\t\t\t& = \\int_{-\\infty}^{\\infty}\\tilde{h}_w^{*}(f) S_n(f) h_w(f) df \\\\\n\t\t\t\t\t\t& = \\int_{-\\infty}^{\\infty}S_n(f) |\\tilde{h}_w(f)|^{2} df \\\\\n\\end{aligned}}\n\n\\newp With this, we define the Transfer function of the Whitening Filter impulse response as:\n\n\\insertequation[\\label{whiteningFilter:optimalWhiteningFilter}]{S_n(f)|\\tilde{h}_w(f)|^{2} = S_w(f) \\:\\: \\textbf{such that} \\:\\: \\sigma^{2} = \\int_{-\\infty}^{\\infty} S_w(f)}\n\n\\newp this directly leads to:\n\n\\insertequation[\\label{whiteningFilter:optimalWhiteningImpulseResponse}]{|\\tilde{h}_w(f)|^{2} = S_w(f)/S_n(f)}\n\n\\newp In a window of a finite duration with a finite number of measures $N$ and a White Variance of $\\sigma_w^{2}$, then $S_w(f) = \\sigma_w^{2}/N = N_0$ and then:\n\n\\insertequation[\\label{whiteningFilter:optimalWhiteningImpulseResponseValue}]{|\\tilde{h}_w(f)|^{2} = \\frac{N_0}{S_n(f)}}\n\n\\newp This definition of whitening will leads to a cleared signal of White noise with variance 1 and mean 0. After this, if we want to do another linear filter, we will need to normalize the impulse response by this whitening optimal filter too in order to get match the template waveform correctly.\n\n\\subsection{Matched Filter}{\\label{sec:signalDetect::ssec:MF}}\n\\newp Matched filter correspond to find the optimal linear filter for maximizing the Signal To Noise Ratio (SNR) in the presence of additive white noise of a given variance $\\sigma_w$ and 0 mean. For this we considers some data $x(t)$ with finite-energy which can be pure noise $x(t) = n(t)$ or a signal in addition to noise $x(t) = s(t) + n(t)$, this is taken as the input to a filter with impulse response $h_{\\MF}(-t)$ and use the linear filter product defined in eq. (\\ref{signalDetect:linearFilter})\n\n\\newp If we do a MF using two different templates waveform, with different energy, it make hard to say what lineal filter works better because our impulse response functions are unormalized. This is clearly seen from the noise, on the input the noise is white but on the output the noise is convolved with the template and thus is not white anymore, this introduce a change on variance:\n\n\\insertequation[\\label{matchedFilter:variance}]{\\sigma_{\\MF} = \\mathbb{E}[|(x|h_{\\MF})|^{2}] = N_0 \\IL |\\tilde{h}_{\\MF}(f)|^{2} df}\n\n\\newp Where we have used the variance of eq. (\\ref{whiteningFilter:noiseVar}) with the constant white noise PSD $S_w(f) = N_0$. Then we just need to divide the matched filter by square root of this variance in order to get a normed SNR of normal distribution $\\mathcal{N}(\\mu_{MF} / \\sigma_{MF}, 1)$ where $\\mu_{MF}$ is:\n\n\\insertequation[\\label{matchedFilter:mean}]{\\mu_{\\MF} = \\mathbb{E}[(x|h_{\\MF})] = \\mathbb{E}[(n|h_{\\MF})] + \\mathbb{E}[(s|h_{\\MF})] = 0 + (s|h_{\\MF})_{t_0}}\n\n\\newp Here we have that $\\mathbb{E}[(s|h_{\\MF})] = (s|h_{\\MF})_{t_0}$ because the linear filter product itself is an expected value of the output filter. This expected value is for a given $t_0$ where we supose it is produced the maximum SNR response which is writen as:\n\n\\insertequation[\\label{matchedFilter:SNR}]{SNR_{t_0} = \\frac{(x|h_{\\MF})_{t_0}}{\\sigma_{\\MF}}}\n\n\\newp And the optimal matched filter is when the expected underlying waveform that comes with noise on the input signals is just equal to the template waveform. from eq. (\\ref{matchedFilter:mean}) we can use $x(t)$ instead of $s(t)$ to estimate $\\mu_{\\MF}$\n\n\\subsubsection{scopes and limitations}{\\label{sec:signalDetect::ssec:MF::sssec:scopes}}\n\n\\newp Here we like to define limits on the behavior of the SNR, first we consider the situation when the input data is only white noise. Using the Cauchy-Schwarz inequality  on eq. (\\ref{matchedFilter:SNR}) with $|\\tilde{x}(f)|^{2} \\thickapprox \\lambda S_n(f)$, where $\\lambda$ depends on the normalization and method used to estimate the PSD, we get:\n\n\\insertequation[\\label{matchedFilterScopes:limitOnlyNoise}]{|SNR_{t_0}| = \\frac{|(x|h)_{t_0}|}{|\\sigma_{\\MF}|} = \\frac{|(n|h)_{t_0}|}{|\\sigma_{\\MF}|} \\leq \\frac{\\sqrt{\\lambda \\sigma_{w}} \\sqrt{\\int_{-\\infty}^{\\infty} |\\tilde{h}_{\\MF}(f)|^{2} df}}{\\sqrt{N_0 \\int_{-\\infty}^{\\infty} |\\tilde{h}_{\\MF}(f)|^{2} df}} \\begin{array}{c} \\text{Discrete} \\\\ = \\\\ case\n\\end{array} \\sqrt{\\frac{\\lambda N}{\\sigma_w}}}\n\n\\newp Here we have writen $N_0$ as the values on the discrete case $N_0 = \\sigma_w^{2} / N$ of $N$ samples, we are going to continue using this but we will write the equations on continuous case. Eq. (\\ref{matchedFilterScopes:limitOnlyNoise}) is a limit for every SNR produced when the input data is only white noise.\n\n\\newp Another important limit is to find the maximum value that a SNR can achieve for any type of input data (with or without underlying signal), again, using the Cauchy-Schwarz inequality, we get in this case:\n\n\\insertequation[\\label{matchedFilterScopes:limitGeneral}]{|SNR_{t_0}| \\leq \\frac{\\sqrt{\\int_{-\\infty}^{\\infty} |\\tilde{x}(f)|^{2} df} \\sqrt{\\int_{-\\infty}^{\\infty} |\\tilde{h}_{\\MF}(f)|^{2} df}}{\\sqrt{N_0 \\int_{-\\infty}^{\\infty} |\\tilde{h}_{\\MF}(f)|^{2} df}} \\begin{array}{c} \\text{Discrete} \\\\ = \\\\ case \\end{array} \\sqrt{\\frac{E_x N}{\\sigma_w^{2}}}}\n\n\\newp Where $E_x = \\IL |\\tilde{h}_{\\MF}(f)|^{2} df = \\IL |h_{\\MF}(t)|^{2} dt$ is the energy of the input data, here we see that the maximum value possible of the SNR only depend on the input data (energy, number of samples and white noise variance) and not on the template waveform.\n\n\\subsection{Whitened Matched Filter}{\\label{sec:signalDetect::ssec:WMF}}\n\n\\newp We can (and must) use the Whitening Filter (WF) together with the Matched Filter (MF) for our (guessed) input signal with colored WSS noise. Here we just need to apply WF to both the input data and the inpulse response on the MF:\n\\insertequation[\\label{whitenedMatchedFilter:filterConvolution}]{(x|h_{\\MF})^{\\WM}_{t_0} = [\\lbrace x * h_w\\rbrace * \\lbrace h_{\\MF} * h_{w} \\rbrace] = [x_w * h_{\\WM}]}\n\n\\newp Using the definition of lineal filter on eq. (\\ref{signalDetect:linearFilter}) with eq. (\\ref{convolution2}), this will be:\n\n\\insertequation[\\label{whitenedMatchedFilter:filterProduct}]{\\wmf{x}{h} = \\IL \\tilde{x}(f) \\tilde{h}_{\\MF}^{*}(f)|\\tilde{h}_w(f)|^{2} e^{2\\pi i f t_0} df}\n\n\\newp Where $|\\tilde{h}_w(f)|^{2}$ is given by eq. (\\ref{whiteningFilter:optimalWhiteningImpulseResponseValue}) this leads to:\n\n\\insertequation[\\label{whitenedMatchedFilter:filterProductValue}]{\\wmf{x}{h} = N_0\\IL \\frac{\\tilde{x}(f) \\tilde{h}^{*}(f)}{S_n(f)} e^{2\\pi i f t_0} df}\n\n\\newp This also affect the variance and the expected (value) remains with same definition as shown in eq. (\\ref{matchedFilter:mean}) but for the product defined in eq. (\\ref{whitenedMatchedFilter:filterProductValue}):\n\n\\insertequation[\\label{whitenedMatchedFilter:VarianceFilter}]{\\sigma_{\\WM}^{2} = \\mathbb{E}[|\\wmf{n}{h}|^{2}] = N_0 \\IL |\\tilde{h}_{\\MF}(f)|^{2}|\\tilde{h}_{w}(f)|^{2} df = N_0^{2} \\IL \\frac{|\\tilde{h}_{\\MF}(f)|^{2}}{S_n(f)} df}\n\n\\insertequation[\\label{whitenedMatchedFilter:ExpectedValueFilter}]{\\mu_{\\WM} = \\mathbb{E}[\\wmf{x}{h}] = \\mathbb{E}[\\wmf{x-n}{h}]}\n\n\\newp Here (and in the next sections) for simplicity we will write $\\wmf{x}{h} = (x|h)$, $\\sigma_{\\WM} = \\sigma$ and $\\mu_{\\WM} = \\mu$.Thus the SNR for the Whitened Matched Filter (writen as $\\rho$ for simplicity) will be:\n\n\\insertequation[\\label{whitenedMatchedFilter:SNR-WMF}]{\\rho_{t_0} = \\frac{(x|h)}{\\sigma}}\n\n\\newp This division doesn't depend on $N_0$ so clearly this matched filter doesnt work with White noise (and in next we will ignore this factor), instead, consider any WSS Gaussian noise. For this definition, the limit values of the matched filter defined in eq. (\\ref{matchedFilterScopes:limitOnlyNoise}) and (\\ref{matchedFilterScopes:limitGeneral}) should be the same but due to numerical computations, could be not exactly the same. This SNR has the same distribution than before $\\mathcal{N}(\\mu / \\sigma, 1)$.\n\n\\section{Statistical Theory of Signal Detection}{\\label{statTheoSigDet}}\n\\newp The observed signal carried an additive noise introduced by the detector and is usually modeled as a Wide-Sense Stationary (WSS) Gaussian random process, this means, the problem of extracting the signal from the noise (as shown in section (\\ref{sec:signalDetect}) can be interpreted as a statistical one. The presence of signal changes the statistical characteristics of the data observed $x(t)$, affecting his Probability Density Function (PDF). \n\\newp All the theory that will be described here are explained more extense in \\citep{ligo-gauss-case, mit-course-sigSysAndInfer, ligo-1992}.\n\\newp We are going to work with statistical hypothesis testing and then define a likelihood ratio with a threshold value in order to decide if there is really a signal or not.\n\n\\subsection{Hypothesis test}\n\n\\newp The main idea here is to consider two scenarios (binary hypothesis)  one is the \\textit{null hypothesis} $H_0$ which consider data absent of signal and \\textit{alternative hypothesis} $H_1$ which consider a signal present.\n\n\\insertgather{\\label{hypoTest:h0} H_0 : x(t) = n(t) \\\\\n\\label{hypoTest:h1} H_1: x(t) = n(t) + s(t)}\n\n\\newp The \\textit{Binary Hypothesis test} or \\textit{binary decision rule} consider 4 scenarios which can be representes as a confusion matrix. Two of these fourth posibilities are consider errors:\n\\begin{itemize}\n\\item $P(H_0|H_0)$, this is the probability of choose $H_0$ when $H_0$ is true. It's a \\textbf{correct decision}.\n\\item $P(H_1|H_0)$, probability of choose $H_1$ when $H_0$ is true. This is a Type I error and it's called \\textbf{false alarm probability}.\n\\item $P(H_0|H_1)$, probability of choose $H_0$ when $H_1$ is true. Type II error known as \\textbf{False dismissal probability}.\n\\item $P(H_1|H_1)$, probability of choose $H_1$ when $H_1$ is true. It's a \\textbf{correct decision}.\n\\end{itemize}\n\\newp The type II error is also the \\textit{probability of detection} of the signal. For the Test scenario, the type I error is called \\textit{significance of the test} and type II error is \\textit{power of the test}. \n\\newp Next, we need to find a test that is optimal. The main idea here, no mather what approach we use, is to calculate the \\textbf{likelihood ratio}.\n\\subsection{likelihood ratio}\n\\newp From the binary hypothesis test, for a given measure $x$, we will have a probability $P(H_0|x)$ of $H_0$ being true and probability $P(H_1|x)$ of $H_1$ being true, oviously, if $H_1$ is actually true, then $P(H_1|x) > P(H_0|x)$, same for case of $H_0$ being true, this can be writen in the compact form:\n\n\\insertequation[\\label{likelihood:desicion}]{P(H_1|x) \\begin{array}{c}H_1 \\\\ > \\\\ < \\\\ H_0 \\end{array} P(H_0|x)}\n\n\\newp Here is implicit that when $P(H_0|x) = P(H_1|x)$ we cannot know what hypothesis is correct. These conditional probabilities are using the posterior probability of the hypotesis, this is different from the \\textit{a priori} probabilities of every hypothesis $P(H_0)$ and $P(H_1)$. In order to evaluate the \\textit{posteriori} probabilites in (\\ref{likelihood:desicion}) we use the Bayes' rule:\n\n\\insertequation[\\label{likelihood:prioriDesicion}]{\\frac{p_1f(x|H_1)}{f(x)} \\begin{array}{c}H_1 \\\\ > \\\\ < \\\\ H_0 \\end{array} \\frac{p_0f(x|H_0)}{f(x)}}\n\n\\newp Where $f(x|H_j)$ is just the conditional PDF and $f(x)$ is the PDF of measure the observed data, since is the same for both hypothesis, we will not consider his values. On eq. (\\ref{likelihood:prioriDesicion}) we have considered that $f(x|H_j) > 0$ for $j=0,1$. Next we can just rewrite this equation in order to get the likelihood ratio $\\Lambda(x)$:\n\n\\insertequation[\\label{likelihood:ratio}]{\\Lambda(x) = \\frac{f(x|H_1)}{f(x|H_0)} \\begin{array}{c}H_1 \\\\ > \\\\ < \\\\ H_0 \\end{array} \\frac{p_0}{p_1} = \\eta}\n\n\\newp Where $\\eta$ is a \\textbf{threshold} that can be defined in several ways, one can estimate the optimal case usign bayesian inference or Neyman-Pearson (NP) detection between many others. For now we will use the NP theory to define the detection and threshold.\n\n\\subsection{Neyman-Pearson Detection}\n\\newp This approach consider a context in which we want to maximize the probability of detection defined as:\n\n\\insertequation[\\label{npDetection:probOfDetect}]{P_D = P(H_1|H_1) = \\int_{D_1} f(x|H_1) dx}\n\n\\newp While keeping the probability of false alarm:\n\n\\insertequation[\\label{npDetection:probOfFalseAlarm}]{P_{FA} = P(H_1|H_0) = \\int_{D_1} f(x|H_0) dx = \\alpha}\n\n\\newp Below a pre-specified leve $\\alpha$. The values in $D_1$ are all values for which the likelihood function is higher than a given threshold $\\eta$. Then the threshold is picked to provide the largest possible $P_D$ while ensuring that $P_{FA}$ is not larger than the pre-specified level. The smaller the $\\eta$, the largest the desicion region $D_1$ and the value of $P_D$, but $P_{FA}$ grows as well. We can just pick the smaller threshold that satisfied the given bound of $P_{FA}$.\n\n\\subsection{NP Detection for Whitened Matched Filter}\n\n\\newp Remembering that we consider the noise as a WSS White Gaussian random process, we can modelate this noise as a normal distribution of 0 mean ($\\mu = 0$) and a given variance $\\sigma$ ($\\mathcal{N}(0, \\sigma^{2})$), thus,  for both hypothesis from eq. (\\ref{hypoTest:h0}) and (\\ref{hypoTest:h1}) $n(t)$ distribute as:\n\n\\insertequation[\\label{npDetWMF:noiseDistr}]{n(t) \\thicksim N(0, \\sigma^{2}) \\longrightarrow f(x) = \\frac{1}{\\sqrt{2 \\pi \\sigma^{2}}}e^{-\\frac{x^{2}}{2\\sigma^{2}}}}\n\n\\newp When the matched filter as defined in sec. (\\ref{sec:signalDetect::ssec:WMF}) is applied, our hypothesis tests are:\n\n\\insertgather{\\label{npDetWMF:H0} H_0: \\:\\: (x|h) = (n|h) \\thicksim \\mathcal{N}(0, \\sigma) \\\\\n\\label{npDetWMF:H1} H_1 \\:\\: (x|h) = (n|h) + (s|h) \\thicksim \\mathcal{N}(\\mu, \\sigma)}\n\n\\newp then, for the SNR we normalize by square root of the variance, leading to hypothesis tests:\n\n\\insertgather{\\label{npDetWMF:H0SNR} H_0: \\:\\: \\frac{(x|h)}{\\sigma} = \\frac{(n|h)}{\\sigma} \\thicksim \\mathcal{N}(0, 1) \\\\\n\\label{npDetWMF:H1SNR} H_1 \\:\\: \\frac{(x|h)}{\\sigma} = \\frac{(n|h)}{\\sigma} + \\frac{(s|h)}{\\sigma} \\thicksim \\mathcal{N}(\\frac{\\mu}{\\sigma}, 1)}\n\n\\newp Here the product $(s|h)$ is optimal when the signal $s(t)$ is equal to the impulse response shifted by the optimal time of match $s(t) = h(t_0 - t)$, using the base definition of linear filter (\\ref{signalDetect:linearFilter}) writen as a simple convolution (\\ref{convolution1}), with the parseval's equation (\\ref{parseval}) and the equations defined in sec. (\\ref{sec:signalDetect::ssec:WMF}):\n\n\\insertequation[\\label{npDetWMF:optimalMean}]{(s|h) = [h(t_0 - t) * h(-t)](t_0) = \\IL h(t_0 - (t_0 - t))h(-t) dt = \\IL |\\tilde{h}(f)|^{2} df = (h|h)_{t_0=0} = \\sigma^{2}}\n\n\\newp The expected value of the optimal filter is just the variance of the output filter. And the Probability Density Function (PDF) of normal distributions is:\n\n\\insertequation[\\label{npDetWMF:PDF}]{f(\\rho) = \\frac{1}{\\sqrt{2\\pi}\\sigma} e^{-\\frac{(\\rho - \\mu)^{2}}{2\\sigma^{2}}}}\n\n\\newp Using this PDF as a conditional PDF with the hypothesis from eq. (\\ref{npDetWMF:H0}) and (\\ref{npDetWMF:H0}), where $\\mu = (s|h)$ for $H_1$, the likelihood ratio (\\ref{likelihood:ratio}) is writen as: \n\n\\insertequation[\\label{npDetWMF:likelihoodRatio}]{\n\\begin{aligned}[b]\n\\Lambda\\lbrace(x|h)\\rbrace & = \\frac{(\\sqrt{2\\pi})^{-1} exp\\left( -\\frac{((x|h) - (s|h))^{2}}{2\\sigma^{2}}\\right)}{(\\sqrt{2\\pi})^{-1} exp\\left( -\\frac{(x|h)^{2}}{2\\sigma^{2}}\\right)} \\\\\n\t\t\t   & = exp\\left(\\frac{2(x|h)(s|h) - (s|h)^{2}}{2 \\sigma^{2}} \\right) \\\\\n\t\t\t   & =  exp\\left(\\frac{(s|h)}{\\mathbb{E}[(n|h)^{2}]} \\lbrace (x|h) - \\frac{1}{2}(s|h) \\rbrace \\right)\n\\end{aligned}}\n\n\\newp Te factor $(s|h) / \\mathbb{E}[(n|h)^{2}]$ on the optimal case is simplified resulting in:\n\n\\insertequation[\\label{npDetWMF:likelihoodRatioSimplified}]{\\Lambda\\lbrace(x|h)\\rbrace = exp\\left( \\lbrace (x|h) - \\frac{1}{2}(h|h) \\rbrace \\right)}\n\n\\newp This likelihood ratio is the same that the one used in \\cite{ligo-gauss-case, ligo-1992} even if we derived the formulas from different perspectives. If we simplify this likelihood ratio by doing a natural logarithm, we get:\n\n\\insertequation[\\label{npDetWMF:logLikelihoodRatio}]{ln[\\Lambda\\lbrace(x|h)\\rbrace] =  \\lbrace (x|h) - \\frac{1}{2}(h|h) \\rbrace \\begin{array}{c}H_1 \\\\ > \\\\ < \\\\ H_0 \\end{array} ln\\left[ \\frac{p_0}{p_1} \\right] = ln[\\eta]}\n\n\n\\newp And here que can write a critical criteria over Threshold to decide what hypothesis is correct: \n\n\n\\insertequation[\\label{npDetWMF:criteriaOverThreshold}]{(x|h)\\begin{array}{c}H_1 \\\\ > \\\\ < \\\\ H_0 \\end{array} ln[\\eta] + \\frac{1}{2}(h|h) = \\eta'}\n\n\\newp Here we see that we can write the optimal threshold if we know what is the optimal and the \\textit{a priori} probability of $H_0$ and $H_1$ (or at least is ratio), but this is not know for the mosts cases, so we need to estimate a threshold for a given constrains. Under the NP criteria, we choose this threshold $\\eta'$ to maximize $P_D$ and satisfy the desired false alarm $P_{FA}$.\n\n\\newp We know that the solution for eq. (\\ref{npDetection:probOfFalseAlarm}) is a \\textit{complementary error function}:\n\n\\insertequation[\\label{npDetWMF:falseAlarmSolution}]{P_{FA} = \\int_{\\eta'}^{\\infty} \\frac{1}{\\sqrt{2\\pi}\\sigma} e^{-x^{2}/(2\\sigma^{2})} dx = \\text{erfc}\\left( \\frac{\\eta'}{\\sigma}\\right)}\n\\newp Where $erfc()$ means the complementary error function. Then we can solve for $\\eta'$ which leads to:\n\n\\insertequation[\\label{npDetMF:thresholdFromFalseAlarm}]{\\eta' = erfc^{-1}(P_{FA}) \\sigma }\n\n\\newp With this threshold defined, we calculate the probability of detection (\\ref{npDetection:probOfDetect}) which solution is:\n\n\\insertequation[\\label{npDetWMF:probOfDetectSolution}]{P_{D} = \\int_{\\eta'}^{\\infty} \\frac{1}{\\sqrt{2\\pi}\\sigma} e^{-(x - \\mu)^{2}/(2\\sigma^{2})} dx = \\text{erfc}\\left( \\frac{\\eta' - \\mu}{\\sigma}\\right)}\n\n\\newp In terms of the False Alarm:\n\n\\insertequation[\\label{npDetWMF:probOfDetectForGivenFalseAlarm}]{P_D = \\text{erfc}\\left(\\frac{\\sigma \\text{erfc}^{-1}(O_{FA}) - \\mu}{\\sigma} \\right) = \\text{erfc}[\\text{erfc}^{-1}(P_{FA}) - \\mu / \\sigma] = \\text{erfc}\\left[\\text{erfc}^{-1}(P_{FA}) - \\frac{(x|h)_{t_0}}{\\sqrt{(h|h)_{t_0=0}}} \\right]}\n\n\\newp This is the final value that we are going to use to determine if our SNR represent a detection or not, the parameters needed for this are the False alarm value $P_{FA}$ and the values calculated for the filter used to estimate the mean and variance. We can also define the counterpart, the probability of False alarm for a given Probability of detection:\n\n\\insertequation[\\label{npDetWMF:probOfFalseAlarForGivenProbOfDetect}]{P_{FA} = \\text{erfc}\\left[\\text{erfc}^{-1}(P_D) + \\frac{(x|h)_{t_0}}{\\sqrt{(h|h)_{t_0=0}}}\\right]}\n\n\\newp What of these two probabilities we want to compute depend on what kind of event we observe.\n\n\n\n\n\\newpage\n\\nocite{*}\n%\\bibliography{references, revtex-custom}\n%\\bibliographystyle{plain}\n%\\printbibliography \n\\begin{multicols}{2}[\\printbibheading]\n\\printbibliography[heading=none]\n\\end{multicols}\n", "meta": {"hexsha": "94656f76a5ce2902c013fb066e338788dd9f28f1", "size": 44182, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/report_content.tex", "max_stars_repo_name": "frmunozz/IrregularMatchedFilter", "max_stars_repo_head_hexsha": "b64c348345b16d777839f13dc585d1816cf81ca6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-12-15T16:38:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T16:38:49.000Z", "max_issues_repo_path": "report/report_content.tex", "max_issues_repo_name": "Francisco95/Match_filter", "max_issues_repo_head_hexsha": "b64c348345b16d777839f13dc585d1816cf81ca6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/report_content.tex", "max_forks_repo_name": "Francisco95/Match_filter", "max_forks_repo_head_hexsha": "b64c348345b16d777839f13dc585d1816cf81ca6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 87.4891089109, "max_line_length": 1009, "alphanum_fraction": 0.720044362, "num_tokens": 13732, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7216718593715664}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\n\\section{Assessing the robustness of a partition} \\label{subsec:robustness}\nWe present here two mechanisms commonly used to assess the relevance of a particular partition. One simple way is to consider that a robust partition should not be altered by a small modification of the quality function. Such a modification could be for example a perturbation of the Markov time $t$ at which the partition has been found. From this point of view, robust partitions correspond to \\textit{plateaux} in the community curve of the graph. In other words, robust partitions should be persistent over a wide interval of Markov time.\n\n\\begin{sloppypar} \nThe second indicator of the robustness of a partition that we will take into account in this work follows from considering that a robust partition is one that is persistent to small modifications of the optimization algorithm. The central tool to quantify this approach of the robustness of a partition is the \\textit{normalized variation of information} \\cite{meilua2007comparing}, which is a popular way to compare two partitions. Let $p(\\C)$ be the probability for a node to be in community $\\C$, i.e. $p(\\C) = n_\\C/n$ where $n_\\C$ is the number of nodes in community $\\C$. The variation of information between partitions $\\P_1$ and $\\P_2$ is defined as\n\\begin{equation} \\label{eq:clustering_VI}\n\t\\VI(\\P_1,\\P_2) := \\frac{H(\\P_1,\\P_2)-H(\\P_1)-H(\\P_2)}{\\log (n)} = \\frac{H(\\P_1|\\P_2)+H(\\P_2|\\P_1)}{\\log (n)},\n\\end{equation}\nwhere $\\log(n)$ is a normalization factor; \n\\begin{equation}\n\tH(\\P) := -\\sum_{\\C \\in \\P} p(\\C) \\log[p(\\C)] \t\n\\end{equation}\nis the Shannon entropy; $H(\\P_1,\\P_2)$ is the Shannon entropy of the joint probability $p(\\C_1,\\C_2)$ that a node belongs both to a community $\\C_1$ of $\\P_1$ and to a community $\\C_2$ of $\\P_2$. We have \n\\begin{equation}\n\tp(\\C_1,\\C_2) = \\frac{n_{\\C_1 \\cap\\, \\C_2}}{n},\t\n\\end{equation}\nand\n\\begin{equation}\n\tH(\\P_1,\\P_2) := -\\sum_{\\C_1 \\in \\P_1} \\sum_{\\C_2 \\in \\P_2} p(\\C_1,\\C_2) \\log[p(\\C_1,\\C_2)].\n\\end{equation}\nSimilarly, $H(\\P_1|\\P_2)$ is the conditional Shannon entropy of partition $\\P_1$ given $\\P_2$, which is defined in a standard way from the joint distribution: $p(\\C_1|\\C_2) = p(\\C_1,\\C_2)/p(\\C_2) = n_{\\C_1\\cap\\, \\C_2}/n_{\\C_2}$, and the expression of $H(\\P_1|\\P_2)$ follows straightforwardly. The latter can be interpreted as the additional information needed to describe $\\P_1$ once $\\P_2$ is known. This measure of the difference between two partitions is then used as follows: for each Markov time, an ensemble of Louvain optimizations of stability are performed, starting from different random initial node ordering.\\footnote{Remember that the problem being $\\mathcal{NP}$-hard, we rely on a heuristic algorithm --- the Louvain method --- that finds a good partition for a given Markov time, but not necessarily the optimal partition. Hence the partition found may differ if a different initial condition is provided.} The normalized variation of information allows then to quantify how different the optimized partitions are. Therefore, a low variation of information indicates optimized partitions that are very similar to each others, and thus that a small modification of the algorithm barely alter the partition. From the point of view of the field of dynamical system, robust partitions have thus an attractor with a large basin of attraction for the optimization method. \n\\end{sloppypar}", "meta": {"hexsha": "bf093ce34c6a03b25faa419b6180bf048e952921", "size": 3459, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/clustering/robustness.tex", "max_stars_repo_name": "dufaysr/tfe", "max_stars_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inputs/clustering/robustness.tex", "max_issues_repo_name": "dufaysr/tfe", "max_issues_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inputs/clustering/robustness.tex", "max_forks_repo_name": "dufaysr/tfe", "max_forks_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 150.3913043478, "max_line_length": 1382, "alphanum_fraction": 0.7533969355, "num_tokens": 984, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7216718593715664}}
{"text": "\\section{Surface Integrals}\r\n\\noindent\r\nWe can parameterize any surface as $\\vec{r}(u,v) = \\langle x(u,v), y(u,v), z(u,v) \\rangle$ (or using some other coordinate system). This is because we are simple taking one 2D surface, the uv-plane, and transforming it into another surface in such a way that areas ear each other in the uv-plane are near each other on the surface. This fact that areas stay close to each other allows us to make statement about the complicated surface while working with the simple uv-plane.\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nThe change of the surface in the $u$ direction is $\\frac{\\partial\\hat{r}}{\\partial u}\\mathrm{d}u$\\\\\r\nThe change of the surface in the $v$ direction is $\\frac{\\partial\\hat{r}}{\\partial v}\\mathrm{d}v$\\\\\r\nSo, the area of the surface in relation to $u$ and $v$ is the area of the parallelogram spanned by these two surface: a cross product.\r\n\\begin{equation*}\r\n\t\\mathrm{d}s = \\norm{\\left< \\frac{\\partial\\vec{r}}{\\partial u}\\mathrm{d}u \\right> \\times \\left< \\frac{\\partial\\vec{r}}{\\partial v}\\mathrm{d}v \\right>} = \\norm{\\vec{r_u} \\times \\vec{r_v}}\\mathrm{d}u\\mathrm{d}v\r\n\\end{equation*}\r\n\r\n\\begin{definition}\r\n\tFor a surface $S$ parameterized by $\\vec{r}(u,v)$ and $(u,v)\\subset D$, the surface area is\r\n\t\\begin{equation*}\r\n\t\tA(S) = \\iint\\limits_{S}{\\mathrm{d}s} = \\iint\\limits_{D}{\\norm{\\vec{r_u} \\times \\vec{r_v}}\\mathrm{d}u\\mathrm{d}v}\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\r\n\\input{./lineSurfaceIntegrals/surfaceIntegralsScalarFunctions}\r\n\\input{./lineSurfaceIntegrals/surfaceIntegralsVFs}", "meta": {"hexsha": "7f60c5e98163d2e668dbd2afc642dbae099b4d53", "size": 1536, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/lineSurfaceIntegrals/surfaceIntegrals.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/lineSurfaceIntegrals/surfaceIntegrals.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/lineSurfaceIntegrals/surfaceIntegrals.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 66.7826086957, "max_line_length": 476, "alphanum_fraction": 0.7135416667, "num_tokens": 483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7216718492302411}}
{"text": "\\input{../../assignment-header}\n\n%========================================================================\n\\title{Assignment 1:  Matlab Basics}\n\\date{Assigned:  Jan. 18  ---  Due:  Jan. 25}\n\\author{Optimal Control For Robotics}\n%========================================================================\n\\begin{document} %\n\\maketitle\n%=================================================\n\n\\section*{Problem 1: fun with random sequences  (25 pts)}\n\nIn this assignment you will write a computer program that generates\na sequence of points in a plane, which will converge to a well-known fractal.\nThere are two parts to this problem, each with slightly\ndifferent rules for generating the sequence of points, resulting in two different fractals.\n\n\\par\nIn addition to submitting plots for each part (on a single figure), you will\nalso be asked to submit your code and detail how long the assignment took you\nto complete. Make sure that your code is well documented (use comments!) and\nclearly written so that someone else can make sense of it.\n\n\\subsection*{Part One:  a special triangle}\nStart by selecting three control points ($A$, $B$, $C$)\nthat are uniformly spaced around the edge of a circle.\\\\\nNext, generate a sequence of points $P_0 ... P_N$\nusing a random number generator and the control points. \\\\\nUse $\\alpha = \\tfrac{1}{2}$ and\nthe choice of $A$, $B$, or $C$ should be randomly selected with equal probability.\n\n\\begin{align}\n  P_0 &= A \\\\\n  P_{k+1} &= \\alpha \\cdot P_k + (1 - \\alpha) \\cdot \\texttt{RandomChoice}(A, B, C)\n\\end{align}\n\nCreate a plot to visualize the sequence, using the following guidelines:\n\\vspace{-0.3em} \\begin{itemize}  \\setlength\\itemsep{0em}\n\\item plot the circle as a thin curved black line\n\\item plot each control point ($A$, $B$, $C$) as a small red circle\n\\item plot the initial point $P_0$ as a small green ``X''\n\\item plot $P_1 ... P_N$ as tiny blue dots, where N is 5000\n\\item make sure that the axes are scaled so that the circle looks like a circle\n\\end{itemize}\n\n\\subsection*{Part Two:  a special rectangle}\n\nRepeat the entire procedure from Part One, but make two changes:\n\\vspace{-0.6em} \\begin{itemize}  \\setlength\\itemsep{0em}\n  \\item Select four uniformly spaced control points around the edge of the circle, instead of three.\n  \\item Set $\\alpha = \\tfrac{1}{3}$\n\\end{itemize}\n\n\\subsection*{Deliverables:}\n\n\\begin{enumerate}\n  \\item Submit your matlab code as a single file:  \\texttt{prob\\_01\\_studentName.m}\n  \\item Submit a single figure (with two sub-plots) as a pdf:  \\texttt{prob\\_01\\_studentName.pdf}\n  \\item Create a short write-up for the problem:   \\texttt{prob\\_01\\_studentName.txt}\n\\end{enumerate}\n\n\\vspace{-1.0em} \\begin{itemize}  \\setlength\\itemsep{0em} \\setlength\\itemindent{18pt}\n  \\item Header: full name, studentName, date, problem name and number\n  \\item List any other students that you worked with.\n  \\item How long did this problem take you?\n  \\item Briefly describe or outline your code (roughly 50 -- 100 words).\n\\end{itemize}\n\n\\subsection*{Comments:}\n  \\vspace{-0.3em} \\begin{itemize}  \\setlength\\itemsep{0em}\n    \\item In part one you generated the \\textit{Sierpinski Triangle} fractal.\n          This algorithm is just one of many ways to create this fractal.\n    \\item This problem was inspired by the numberphile video \\quotes{Chaos Game}: \\\\\n          \\url{https://www.youtube.com/watch?v=kbKtFN71Lfs}\n    \\item See the Hints section at the end of the assignment for\n          how to save a Matlab figure into a pdf and\n          how to include multiple matlab functions in a single file.\n\\end{itemize}\n\n\\section*{Problem 2: simple plots and derivatives (25 pts)}\n\nIn this problem you will generate a single figure with a set of six-subplots.\nThe figure is described below, along with the functions that you will be plotting.\nAs with the previous problem, please keep track of the time you spend on this problem\nand make your code well-documented and organized.\nYou may use any method that you like to compute the derivatives of $x(t)$ and $y(t)$.\n\n\\begin{equation}\nx(t) = \\big(1 + (t-2)^2 \\big) \\cdot \\sin(3 t)\n\\end{equation}\n\n\\begin{equation}\ny(t) = t^3 - 6 t^2 + 2 t + 5\n\\end{equation}\n\n\\begin{equation}\n  \\dot{z}(t) \\equiv \\frac{d}{dt} z(t)\n  \\quad \\quad\n  \\ddot{z}(t) \\equiv \\frac{d^2}{dt^2} z(t)\n\\end{equation}\n\n\\subsection*{What to plot:}\n\n\\vspace{-0.6em} \\begin{itemize}  \\setlength\\itemsep{0em} \\setlength\\itemindent{18pt}\n\\item plot $x(t)$, $\\dot{x}(t)$, and $\\ddot{x}(t)$ on the domain $t \\in [0,5]$\n\\item plot $y(t)$, $\\dot{y}(t)$, and $\\ddot{y}(t)$ on the domain $t \\in [0,5]$\n\\item the plots for $x(t)$ and its derivatives should be in the left column\n\\item the plots for $y(t)$ and its derivatives should be in the right column\n\\item $x(t)$ and $y(t)$ should be in top two plots\n\\item $\\dot{x}(t)$ and $\\dot{y}(t)$ should be in middle two plots\n\\item $\\ddot{x}(t)$ and $\\ddot{y}(t)$ should be in bottom two plots\n\\item Plot a blue circle at the point where $y(t)$ reaches its maximum value on the domain $t \\in [0,5]$\n\\item Plot a red ``X'' at the point where $y(t)$ reaches its minimum value on the domain $t \\in [0,5]$\n\\item All plots should have both axes labeled and a title.\n\\end{itemize}\n\n\\subsection*{Deliverables:}\n\n\\begin{enumerate}\n  \\item Submit your matlab code as a single file:  \\texttt{prob\\_02\\_studentName.m}\n  \\item Create a single figure, with six sub-plots:  \\texttt{prob\\_02\\_studentName.pdf}\n  \\item Create a short write-up for the problem:   \\texttt{prob\\_02\\_studentName.txt}\n\\end{enumerate}\n\n\\vspace{-1.0em} \\begin{itemize}  \\setlength\\itemsep{0em} \\setlength\\itemindent{18pt}\n  \\item Header: full name, studentName, date, problem name and number\n  \\item List any other students that you worked with.\n  \\item How long did this problem take you?\n  \\item Briefly describe your code (roughly 50 -- 100 words).\n  \\item Show work for derivative calculations (use pseudo-code, \\textit{e.g.} $\\dot{x} \\to $ \\texttt{dx}).\n  \\item How did you compute the minimum and maximum values?\n\\end{itemize}\n\n\\pagebreak\n\n\\subsection*{Matlab Hints:}\n\n\\vspace{1.0em}\n\nYou can export a matlab figure to a .pdf file using the following function:\n\\lstinputlisting{../../../../codeLibrary/utilities/saveFigureToPdf.m}\n\n\\vspace{1.0em}\n\nYou can use multiple functions in a single file:\n\\lstinputlisting{prob_01_studentName.m}\n\n%=================================================\n\\end{document}\n", "meta": {"hexsha": "55a156e937c1afb5d33e9f3c4163ff95bdc53a57", "size": 6377, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "topics/01-course-intro/assignment/hw-01-matlab-basics.tex", "max_stars_repo_name": "ShaneRozenLevy/ME149_Spring2018", "max_stars_repo_head_hexsha": "0cd1960cd3699ef4f24f824c89b32a64c73b5b99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 45, "max_stars_repo_stars_event_min_datetime": "2018-01-10T15:55:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T22:54:58.000Z", "max_issues_repo_path": "topics/01-course-intro/assignment/hw-01-matlab-basics.tex", "max_issues_repo_name": "Boyang--Li/ME149_Spring2018", "max_issues_repo_head_hexsha": "333dcf4891ca05f007590f3a40f67ae46cf2cf6b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "topics/01-course-intro/assignment/hw-01-matlab-basics.tex", "max_forks_repo_name": "Boyang--Li/ME149_Spring2018", "max_forks_repo_head_hexsha": "333dcf4891ca05f007590f3a40f67ae46cf2cf6b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-02-24T00:15:06.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T14:08:38.000Z", "avg_line_length": 42.2317880795, "max_line_length": 106, "alphanum_fraction": 0.6906068684, "num_tokens": 1828, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059462938815, "lm_q2_score": 0.9099070054272775, "lm_q1q2_score": 0.7216526565788329}}
{"text": "\\documentclass[notitlepage]{problem-solving}\n\n\\def\\ord{\\operatorname{ord}}\n\n\\title{Sums Convergent under the $p$-adic Norm}\n\\date{June 2016}\n\\author{Matt McCarthy}\n\n\\addbibresource{p-adic-sum.bib}\n\\nocite{*}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{problem*}\n\tShow that\n\t\\[\n\t\t\\sum_{n=0}^\\infty 2^n = -1\n\t\\]\n\tunder the 2-adic metric.\n\\end{problem*}\n\n\\section{Background}\n\nIn order to talk about limits, we first need to understand the concept of a metric.\n\\begin{definition}[Metric Space]\n\tLet $X$ be a non-empty set and let $d:X\\times X\\rightarrow \\RR$ be a function.\n\tThen $d$ is a \\textit{metric} on $X$ if all of the following hold.\n\t\\begin{enumerate}\n\t\t\\item For all $x,y\\in X$, $d(x,y)\\geq 0$.\n\t\t\\item For all $x,y\\in X$, $d(x,y) = 0$ iff $x=y$.\n\t\t\\item For all $x,y\\in X$, $d(x,y)=d(y,x)$.\n\t\t\\item For all $x,y,z\\in X$, $d(x,z)\\leq d(x,y)+d(y,z)$ (triangle inequality).\n\t\\end{enumerate}\n\tIf $d$ is a metric on $X$, then we say $(X,d)$ forms a \\textit{metric space}.\n\\end{definition}\nAfter defining the metric space, we can consider whether or not a sequence in that space converges.\n\\begin{definition}[Convergent Sequence]\n\tLet $(X,d)$ be a metric space and let $(a_n)_{n\\in\\NN}\\subseteq X$ and let $a\\in X$.\n\tWe say $a_n$ is a \\textit{converges} to $a$ if for all $\\varepsilon>0$, there exists an $N\\in\\NN$ such that $d(a_n,a)<\\varepsilon$ for all $n\\geq N$.\n\tIf such an $a$ exists, we say $a_n$ is \\textit{convergent in $X$}.\n\\end{definition}\nFurthermore, if a sequence is convergent in a metric space, it is also Cauchy in that space.\n\\begin{definition}[Cauchy Sequence]\n\tLet $(X,d)$ be a metric space and let $(a_n)_{n\\in\\NN}\\subseteq X$.\n\tWe say $a_n$ is a \\textit{Cauchy sequence} if for all $\\varepsilon>0$, there exists an $N\\in\\NN$ such that $d(a_n,a_m)<\\varepsilon$ for all $n,m\\geq N$.\n\\end{definition}\nWhile convergent implies Cauchy, the other way does not always hold.\nFor example in $\\QQ$ under the Euclidean metric ($d(x,y)=|x-y|$), the sequence defined by $(1+1/n)^n$ is Cauchy but not convergent.\nHowever, if we move to $\\RR$, $(1+1/n)^n$ converges to $e$.\nCauchy sequences are sequences that \\textit{should} be convergent in our space.\nIf they are not, then we need to move to what is called the completion of the metric space.\n\\begin{definition}[Complete Metric Space]\n\tLet $(X,d)$ be a metric space.\n\tWe say $X$ is \\textit{complete} if all Cauchy sequences in $X$ converge in $X$.\n\\end{definition}\n\\begin{thm}\n\tLet $(X,d)$ be a metric space.\n\tThen $X$ has a unique completion, $C(X,d)$, up to isometry.\n\tFurthermore, this completion is isometric to the space $(B(X),D)$ where $B(X)$ is the set of all bounded functions from $X$ to $\\RR$, and $D(f,g)=\\sup_{x\\in X} |f(x)-g(x)|$.\n\\end{thm}\n\nNow that we have enough background in analysis, lets talk about the $p$-adic numbers.\nBefore we can define the $p$-adic's, we need to introduce the $p$-adic ordinal and $p$-adic absolute value first.\n\\begin{definition}[$p$-adic Ordinal]\n\tLet $p$ be a prime and let $a\\in\\ZZ$ be nonzero.\n\tThen the \\textit{$p$-adic ordinal} of $a$, denoted $\\ord_p a$, is defined as\n\t\\[\n\t\t\\ord_p a = \\max\\set{n\\,:\\, p^n | a}.\n\t\\]\n\tFurthermore, for any nonzero $x=b/c\\in\\QQ$,\n\t\\[\n\t\t\\ord_p x = \\ord_p a - \\ord_p b.\n\t\\]\n\\end{definition}\nUsing the definition of $p$-adic ordinal, we now provide the definition of the $p$-adic absolute value.\n\\begin{definition}[$p$-adic absolute value]\n\tLet $p$ be a prime and $x\\in\\QQ$.\n\tThen the \\textit{$p$-adic absolute value of $x$}, denoted $|x|_p$, is defined as\n\t\\[\n\t\t|x|_p =\n\t\t\\begin{cases}\n\t\t\tp^{-\\ord_p x} & x\\neq 0\\\\\n\t\t\t0 & x=0.\n\t\t\\end{cases}\n\t\\]\n\\end{definition}\nWhile an absolute value is not a metric in and of itself, it generates a metric.\nSimilarly to how we use $|x-y|$ as a metric, we use $|x-y|_p$ as the $p$-adic metric.\nWith this, we can define the $p$-adic numbers.\n\\begin{definition}[$p$-adic Numbers]\n\tThe set of \\textit{$p$-adic numbers} is the completion of the metric space $(\\QQ,|\\cdot|_p)$.\n\\end{definition}\nAdditionally, $\\QQ_p$ satisfies a stronger version of the triangle inequality.\n\\begin{thm}[Strong Triangle Inequality]\n\tFor all $x,y\\in\\QQ_p$, $|x+y|_p\\leq\\max\\set{|x|_p,|y|_p}$.\n\\end{thm}\n\n\\section{Solution}\n\n\\begin{problem*}\n\tShow that\n\t\\[\n\t\t\\sum_{n=0}^\\infty 2^n = -1\n\t\\]\n\tunder the 2-adic norm.\n\\end{problem*}\n\nTo start our solution, we prove that if a sequence in $\\QQ_p$ converges to 0 under the $p$-adic metric, the infinite sum of all of its terms is convergent in $\\QQ_p$.\nWhile this result is not true in $\\RR$ (e.g. the harmonic series), it works in $\\QQ_p$ because of the strong triangle inequality.\n\n\\begin{thm}\n\tLet $(a_n)_{n\\in\\NN}\\subseteq\\QQ_p$ such that $a_n\\rightarrow 0$.\n\tThen $\\sum_{n=0}^\\infty a_n$ converges in $\\QQ_p$.\n\\end{thm}\n\\begin{proof}\n\tLet $\\varepsilon > 0$ be given.\n\tSince $a_n\\rightarrow 0$, there exists an $N\\in\\NN$ such that $|a_n|<\\varepsilon$.\n\tForce $n\\geq m\\geq N$.\n\tConsider $|\\sum_{k=0}^n a_k - \\sum_{k=0}^m|_p$.\n\t\\[\n\t\t\\abs{\\sum_{k=0}^n a_k - \\sum_{k=0}^m}_p a_k = \\abs{\\sum_{k=m+1}^n a_k}_p\n\t\\]\n\tThus, by the strong triangle inequality,\n\t\\[\n\t\t\\abs{\\sum_{k=0}^n a_k - \\sum_{k=0}^m a_k}_p \\leq \\max\\limits_{m+1\\leq k\\leq n}\\set{|a_k|_p}.\n\t\\]\n\tHowever, we know that for each $k\\geq N$, $|a_k|_p<\\varepsilon$.\n\tTherefore,\n\t\\[\n\t\t\\abs{\\sum_{k=0}^n a_k - \\sum_{k=0}^m a_k}_p < \\varepsilon\n\t\\]\n\tand $\\paren{\\sum_{k=0}^n a_k}_{n\\in\\NN}$ is Cauchy in $\\QQ_p$.\n\tSince $\\QQ_p$ is defined as a complete metric space, $\\paren{\\sum_{k=0}^n a_k}_{n\\in\\NN}$ converges in $\\QQ_p$.\n\\end{proof}\n\nNow, in order to show that $\\sum_{n=0}^\\infty 2^n$ converges with respect to the $p$-adic metric, we show that $2^n\\rightarrow 0$ with respect to the $p$-adic metric.\n\n\\begin{lemma}\n\tUnder the 2-adic metric, $2^n\\rightarrow 0$.\n\\end{lemma}\n\\begin{proof}\n\tLet $\\varepsilon > 0$ be given.\n\tWithout loss of generality, assume $\\varepsilon < 1$.\n\tThus, $\\lg\\varepsilon < 0$.\n\tTake $N > -\\lg\\varepsilon$ and let $n\\geq N$.\n\tThen\n\t\\[\n\t\t|2^n|_2 = 2^{-n} \\leq 2^{-N} < 2^{\\lg\\varepsilon} = \\varepsilon.\n\t\\]\n\tTherefore, $2^n\\rightarrow 0$ under $|\\cdot|_2$.\n\\end{proof}\n\nFrom here, we do some algebraic manipulation to find the limit point.\n\n\\begin{proposition}\n\tIn $\\QQ_2$,\n\t\\[\n\t\t\\sum_{n=0}^\\infty 2^n = -1.\n\t\\]\n\\end{proposition}\n\\begin{proof}\n\tSince $2^n\\rightarrow 0$, $\\sum_{n=0}^\\infty 2^n$ converges to some $S\\in\\QQ_p$.\n\tConsider $S$.\n\t\\[\n\t\tS= \\sum_{n=0}^\\infty 2^n = 1 + \\sum_{n=1}^\\infty 2^n = 1+ 2\\sum_{n=1}^\\infty 2^{n-1} = 1+ 2 \\sum_{n=0} 2^n = 1+ 2S\n\t\\]\n\tSolving for $S$ yields,\n\t\\[\n\t\tS = -1.\n\t\\]\n\\end{proof}\n\n\\printbibliography\n\n\\end{document}\n", "meta": {"hexsha": "1ed3d6ac9b2e5adda3d0e0b3e83e211bfdd5d79b", "size": 6534, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016-summer/p-adic-sum/p-adic-sum.tex", "max_stars_repo_name": "matt-mccarthy/problem-solving", "max_stars_repo_head_hexsha": "8014f517e5290f2904cfb49f3831f05e484d59ec", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2016-summer/p-adic-sum/p-adic-sum.tex", "max_issues_repo_name": "matt-mccarthy/problem-solving", "max_issues_repo_head_hexsha": "8014f517e5290f2904cfb49f3831f05e484d59ec", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2016-summer/p-adic-sum/p-adic-sum.tex", "max_forks_repo_name": "matt-mccarthy/problem-solving", "max_forks_repo_head_hexsha": "8014f517e5290f2904cfb49f3831f05e484d59ec", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.7078651685, "max_line_length": 174, "alphanum_fraction": 0.664983165, "num_tokens": 2472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7216416033938516}}
{"text": "%!TEX root = modelguide.tex\n\n\\appendix\n\n\\chapter{Mathematical Review}\n\\label{MathematicalReview:sec}\n\nThis appendix reviews some of the mathematical concepts used in this\nmanual.\n\n\\section{Rotation transforms}\n\\label{Rotations:sec}\n\nRotation matrices are used to describe the orientation of 3D\ncoordinate frames in space, and to transform vectors between these\ncoordinate frames.\n\n\\begin{figure}[t]\n\\begin{center}\n \\iflatexml\n   \\includegraphics[width=2in]{images/rotationAB}\n \\else\n   \\includegraphics[width=2in]{images/rotationAB}\n \\fi\n\\end{center}\n\\caption{Two coordinate frames A and B rotated with respect\nto each other.}\n\\label{rotationAB:fig}\n\\end{figure}\n\nConsider two 3D coordinate frames A and B that are rotated with\nrespect to each other (Figure \\ref{rotationAB:fig}).  The orientation\nof B with respect to A can be described by a $3 \\times 3$ rotation\nmatrix $\\R_{BA}$, whose columns are the unit vectors giving the\ndirections of the rotated axes $\\x'$, $\\y'$, and $\\z'$ of B with\nrespect to A.\n\n$\\R_{BA}$ is an {\\it orthogonal} matrix, meaning that\nits columns are both perpendicular and mutually\northogonal, so that\n%\n\\begin{equation}\n\\R_{BA}^T \\, \\R_{BA} = \\I\n\\end{equation}\n%\nwhere $\\I$ is the $3 \\times 3$ identity matrix. The inverse\nof $\\R_{BA}$ is hence equal to its transpose:\n%\n\\begin{equation}\n\\R_{BA}^{-1} = \\R_{BA}^T.\n\\label{RABinv:eqn}\n\\end{equation}\n%\nBecause $\\R_{BA}$ is orthogonal, $|\\det \\R_{BA}| = 1$, and because it\nis a rotation, $\\det \\R_{BA} = 1$ (the other case, where $\\det \\R_{BA}\n= -1$, is not a rotation but a {\\it reflection}).  The 6 orthogonality\nconstraints associated with a rotation matrix mean that in spite of\nhaving 9 numbers, the matrix only has 3 degrees of freedom.\n\nNow, assume we have a 3D vector $\\v$, and consider its coordinates\nwith respect to both frames A and B.  Where necessary, we use a\npreceding superscript to indicate the coordinate frame with respect to\nwhich a quantity is described, so that ${}^A\\v$ and ${}^B\\v$ and\ndenote $\\v$ with respect to frames A and B, respectively.  Given the\ndefinition of $\\R_{AB}$ given above, it is fairly straightforward to\nshow that\n%\n\\begin{equation}\n{}^A\\v = \\R_{BA} \\, {}^B\\v\n\\label{vectorTransform:eqn}\n\\end{equation}\n%\nand, given (\\ref{RABinv:eqn}), that\n%\n\\begin{equation}\n{}^B\\v = \\R_{BA}^T \\, {}^A\\v.\n\\label{vectorInvTransform:eqn}\n\\end{equation}\n%\nHence in addition to describing the orientation of B with respect to A,\n$\\R_{BA}$ is also a transformation matrix that maps vectors in B\nto vectors in A.\n\nIt is straightforward to show that\n%\n\\begin{equation}\n\\R_{BA}^{-1} = \\R_{BA}^T = \\R_{AB}.\n\\label{rotationInverse:eqn}\n\\end{equation}\n%\n\n\\begin{figure}[t]\n\\begin{center}\n \\iflatexml\n   \\includegraphics[width=4.5in]{images/rotationsABC}\n \\else\n   \\includegraphics[width=4.5in]{images/rotationsABC}\n \\fi\n\\end{center}\n\\caption{Schematic illustration of three coordinate frames A, B, and C\nand the rotational transforms relating them.}\n\\label{rotationsABC:fig}\n\\end{figure}\n\nA simple rotation by an angle $\\theta$ about one of the basic\ncoordinate axes is known as a {\\it basic} rotation. The three\nbasic rotations about x, y, and z are:\n%\n\\begin{equation*}\n\\R_x(\\theta) = \\matl 1 & 0 & 0 \\\\ \n               0 & \\cos(\\theta) & -\\sin(\\theta) \\\\ \n               0 & \\sin(\\theta) & \\cos(\\theta) \n\t\t \\matr,\n\\end{equation*}\n%\n\\begin{equation*}\n\\R_y(\\theta) = \\matl \\cos(\\theta) & 0 & \\sin(\\theta) \\\\ \n               0 & 1 & 0 \\\\ \n               -\\sin(\\theta) & 0 & \\cos(\\theta) \n                 \\matr,\n\\end{equation*}\n%\n\\begin{equation*}\n\\R_z(\\theta) = \\matl \\cos(\\theta) & -\\sin(\\theta) & 0 \\\\ \n               \\sin(\\theta) & \\cos(\\theta) & 0 \\\\ \n               0 & 0 & 1 \n                 \\matr.\n\\label{elementaryRotations:sec}\n\\end{equation*}\n%\n\nNext, we consider transform composition. Suppose we have three\ncoordinate frames, A, B, and C, whose orientation are related to each other by\n$\\R_{BA}$, $\\R_{CB}$, and $\\R_{CA}$ (Figure\n\\ref{transformsABC:fig}).  If we know $\\R_{BA}$ and $\\R_{CA}$,\nthen we can determine $\\R_{CB}$ from\n%\n\\begin{equation}\n\\R_{CB} = \\R_{BA}^{-1} \\, \\R_{CA}.\n\\label{rotationCB:eqn}\n\\end{equation}\n%\nThis can be understood in terms of vector transforms. $\\R_{CB}$\ntransforms a vector from C to B, which is equivalent to first\ntransforming from C to A,\n%\n\\begin{equation}\n{}^A\\v = \\R_{CA} \\, {}^C\\v,\n\\end{equation}\n%\nand then transforming from A to B:\n%\n\\begin{equation}\n{}^B\\v = \\R_{BA}^{-1} \\, {}^A\\v = \\R_{BA}^{-1} \\; \\R_{CA} {}^C\\v = \\R_{CB} \\, {}^C\\v.\n\\end{equation}\n%\nNote also from (\\ref{rotationInverse:eqn}) that $\\R_{CB}$ can be \nexpressed as\n%\n\\begin{equation}\n\\R_{CB} = \\R_{AB} \\, \\R_{CA}.\n\\label{rotationCBII:eqn}\n\\end{equation}\n%\n\nIn addition to specifying rotation matrix components explicitly,\nthere are numerous other ways to describe a rotation.\nThree of the most common are:\n\n\\begin{description}\n\n\\item[Roll-pitch-yaw angles]\\mbox{}\n\nThere are 6 variations of roll-pitch-yaw angles. The one used in\nArtiSynth corresponds to older robotics texts (e.g., Paul, Spong) and\nconsists of a roll rotation $r$ about the z axis, followed by a pitch\nrotation $p$ about the new y axis, followed by a yaw rotation $y$\nabout the new x axis. The net rotation can be expressed by the\nfollowing product of basic rotations: $\\R_z(r) \\, \\R_y(p) \\, \\R_x(y)$.\n\n\\item[Axis-angle]\\mbox{}\n\nAn axis angle rotation parameterizes a rotation as a rotation by\nan angle $\\theta$ about a specific axis $\\u$. Any rotation\ncan be represented in such a way as a consequence of Euler's rotation\ntheorem.\n\n\\item[Euler angles]\\mbox{}\n\nThere are 6 variations of Euler angles. The one used in ArtiSynth\nconsists of a rotation $\\phi$ about the z axis, followed by a rotation\n$\\theta$ about the new y axis, followed by a rotation $\\psi$ about the\nnew z axis. The net rotation can be expressed by the following product\nof basic rotations: $\\R_z(\\phi) \\, \\R_y(\\theta) \\, \\R_z(\\psi)$.\n\n\\end{description}\n\n\\section{Rigid transforms}\n\\label{RigidTransforms:sec}\n\nRigid transforms are used to specify both the transformation of points\nand vectors between coordinate frames, as well as the relative\nposition and orientation between coordinate frames.\n\n\\begin{figure}[ht]\n\\begin{center}\n \\iflatexml\n   \\includegraphics[width=3.25in]{images/framesAB}\n \\else\n   \\includegraphics[width=3.25in]{images/framesAB}\n \\fi\n\\end{center}\n\\caption{A position vector $\\p_{BA}$ and rotation matrix\n$\\R_{BA}$ describing the position and orientation of frame B\nwith respect to frame A.}\n\\label{framesAB:fig}\n\\end{figure}\n\nConsider two 3D coordinate frames in space, A and B (Figure\n\\ref{framesAB:fig}). The translational position of B with respect to A\ncan be described by a vector $\\p_{BA}$ from the origin of A to the\norigin of B (described with respect to frame A). Meanwhile, the\norientation of B with respect to A can be described by the $3 \\times\n3$ rotation matrix $\\R_{BA}$ (Section \\ref{Rotations:sec}).  The\ncombined position and orientation of B with respect to A is known as\nthe {\\it pose} of B with respect to A.\n\n\\begin{figure}[t]\n\\begin{center}\n \\iflatexml\n   \\includegraphics[width=3.75in]{images/pointsAB}\n \\else\n   \\includegraphics[width=3.75in]{images/pointsAB}\n \\fi\n\\end{center}\n\\caption{Point vectors ${}^A\\q$ and ${}^B\\q$ describing\nthe position of a point $\\q$ with respect to frames A and B.}\n\\label{pointsAB:fig}\n\\end{figure}\n\nNow, assume we have a 3D point $\\q$, and consider its coordinates with\nrespect to both frames A and B (Figure \\ref{pointsAB:fig}). Given the\npose descriptions given above, it is fairly straightforward to show\nthat\n%\n\\begin{equation}\n{}^A\\q = \\R_{BA} \\, {}^B\\q + \\p_{BA},\n\\label{pointTransform:eqn}\n\\end{equation}\n%\nand, given (\\ref{RABinv:eqn}), that\n%\n\\begin{equation}\n{}^B\\q = \\R_{BA}^T \\, ({}^A\\q - \\p_{BA}).\n\\label{pointInvTransform:eqn}\n\\end{equation}\n%\n\nIf we extend our points into a 4D {\\it homogeneous} coordinate space\nwith the fourth coordinate $w$ equal to 1, i.e.,\n%\n\\begin{equation}\n\\q^* \\equiv \\matl \\q \\\\ 1 \\matr,\n\\end{equation}\n%\nthen (\\ref{pointTransform:eqn}) and\n(\\ref{pointInvTransform:eqn}) can be simplified to\n%\n\\begin{equation*}\n{}^A\\q^* = \\T_{BA} \\, {}^B\\q^* \\quad \\text{and} \\quad\n{}^B\\q^* = \\T_{BA}^{-1} \\, {}^A\\q^*\n\\end{equation*}\n%\nwhere\n%\n\\begin{equation}\n\\T_{BA} = \\matl \\R_{BA} & \\p_{BA} \\\\ 0 & 1 \\matr\n\\end{equation}\n%\nand\n%\n\\begin{equation}\n\\T_{BA}^{-1} = \\matl \\R_{BA}^T & -\\R_{BA}^T \\p_{BA} \\\\ 0 & 1 \\matr.\n\\end{equation}\n%\n$\\T_{BA}$ is the $4 \\times 4$ {\\it rigid transform matrix} that\ntransforms points from B to A and also describes the pose of\nB with respect to A (Figure \\ref{transformAB:fig}).\n\n\\begin{figure}[t]\n\\begin{center}\n \\iflatexml\n   \\includegraphics[width=3in]{images/transformAB}\n \\else\n   \\includegraphics[width=3in]{images/transformAB}\n \\fi\n\\end{center}\n\\caption{The transform matrix $\\T_{BA}$ from B to A.}\n\\label{transformAB:fig}\n\\end{figure}\n\nIt is straightforward to show that $\\R_{BA}^T$ and $-\\R_{BA}^T\n\\p_{BA}$ describe the orientation and position of $A$ with respect to\n$B$, and so therefore\n%\n\\begin{equation}\n\\T_{BA}^{-1} = \\T_{AB}.\n\\label{transformInverse:eqn}\n\\end{equation}\n%\n\nNote that if we are transforming a vector $\\v$ instead of a point\nbetween B and A, then we are only concerned about relative orientation\nand the vector transforms (\\ref{vectorTransform:eqn}) and\n(\\ref{vectorInvTransform:eqn}) should be used instead.\nHowever, we can express these using $\\T_{BA}$ if\nwe embed vectors in a homogeneous coordinate space \nwith the fourth coordinate $w$ equal to 0, i.e.,\n%\n\\begin{equation}\n\\v^* \\equiv \\matl \\v \\\\ 0 \\matr,\n\\end{equation}\n%\nso that\n%\n\\begin{equation*}\n{}^B\\v^* = \\T_{BA} \\, {}^A\\v^* \\quad \\text{and} \\quad\n{}^A\\v^* = \\T_{BA}^{-1} \\, {}^B\\v^*.\n\\end{equation*}\n%\n\n\\begin{figure}[t]\n\\begin{center}\n \\iflatexml\n   \\includegraphics[width=4.5in]{images/transformABC}\n \\else\n   \\includegraphics[width=4.5in]{images/transformABC}\n \\fi\n\\end{center}\n\\caption{Three coordinate frames A, B, and C and the transforms\nrelating each one to the other.}\n\\label{transformsABC:fig}\n\\end{figure}\n\nFinally, we consider transform composition. Suppose we have three\ncoordinate frames, A, B, and C, each related to the other by\ntransforms $\\T_{BA}$, $\\T_{CB}$, and $\\T_{CA}$ (Figure\n\\ref{transformsABC:fig}).  Using the same reasoning used to derive\n(\\ref{rotationCB:eqn}) and (\\ref{rotationCBII:eqn}), it is easy to\nshow that\n%\n\\begin{equation}\n\\T_{CB} = \\T_{BA}^{-1} \\; \\T_{CA} = \\T_{AB} \\; \\T_{CA}.\n\\end{equation}\n%\n\n\\section{Affine transforms}\n\\label{AffineTransforms:sec}\n\nAn {\\it affine transform} is a generalization of a rigid transform, in\nwhich the rotational component $\\R$ is replaced by a general $3 \\times\n3$ matrix $\\A$. This means that an affine transform implements a\ngeneralized basis transformation combined with an offset of the origin\n(Figure \\ref{affineAB:fig}). As with $\\R$ for rigid transforms, the\ncolumns of $\\A$ still describe the transformed basis vectors $\\x'$,\n$\\y'$, and $\\z'$, but these are generally no longer orthonormal.\n\n\\begin{figure}[ht]\n\\begin{center}\n \\iflatexml\n    \\includegraphics[width=3.25in]{images/affineAB}\n \\else\n    \\includegraphics[width=3.25in]{images/affineAB}\n \\fi\n\\end{center}\n\\caption{A position vector $\\p_{BA}$ and a general matrix $\\A_{BA}$\ndescribing the affine position and basis transform of frame B with respect to\nframe A.}\n\\label{affineAB:fig}\n\\end{figure}\n\nExpressed in terms of homogeneous coordinates,\nthe affine transform $\\X_{AB}$ takes the form\n%\n\\begin{equation}\n\\X_{BA} = \\matl \\A_{BA} & \\p_{BA} \\\\ 0 & 1 \\matr\n\\end{equation}\n%\nwith\n%\n\\begin{equation}\n\\X_{BA}^{-1} = \\matl \\A_{BA}^{-1} & -\\A_{BA}^{-1} \\p_{BA} \\\\ 0 & 1 \\matr.\n\\end{equation}\n%\nAs with rigid transforms, when an affine transform is applied to a\nvector instead of a point, only the matrix $\\A$ is applied and the\ntranslation component $\\p$ is ignored.\n\nAffine transforms are typically used to effect transformations that\nrequire stretching and shearing of a coordinate frame.  By the polar\ndecomposition theorem, $\\A$ can be factored into a regular\nrotation $\\R$ plus a symmetric shearing/scaling matrix $\\P$:\n%\n\\begin{equation}\n\\A = \\R \\, \\P\n\\end{equation}\n%\nAffine transforms can also be used to perform reflections, in which\n$\\A$ is orthogonal (so that $\\A^T \\, \\A = \\I$) but with $\\det \\A =\n-1$.\n\n\\section{Rotational velocity}\n\n\\begin{figure}[ht]\n\\begin{center}\n \\iflatexml\n    \\includegraphics[width=3.25in]{images/angularvelAB}\n \\else\n    \\includegraphics[width=3.25in]{images/angularvelAB}\n \\fi\n\\end{center}\n\\caption{Frame B rotating with respect to frame A.}\n\\label{angularvelAB:fig}\n\\end{figure}\n\nGiven two 3D coordinate frames A and B, the rotational, or {\\it\nangular}, velocity of B with respect to A is given by a 3D vector\n$\\Bom_{BA}$ (Figure \\ref{angularvelAB:fig}). $\\Bom_{BA}$\nis related to the derivative of $\\R_{BA}$ by\n%\n\\begin{equation}\n\\dot\\R_{BA} = [{}^A\\Bom_{BA}] \\R_{BA} = \\R_{BA} [{}^B\\Bom_{BA}]\n\\end{equation}\n%\nwhere ${}^A\\Bom_{BA}$ and ${}^B\\Bom_{BA}$ indicate $\\Bom_{BA}$ with\nrespect to frames $A$ and $B$ and $[ \\Bom ]$ denotes the $3 \\times 3$\ncross product matrix\n%\n\\begin{equation}\n[ \\Bom ] \\equiv \n\\matl\n0 & -\\omega_z & \\omega_y \\\\\n\\omega_z & 0 & -\\omega_x \\\\\n-\\omega_y & \\omega_x & 0 \\\\\n\\matr.\n\\label{xprodmatrix:eqn}\n\\end{equation}\n%\n\nIf we consider instead the velocity of $A$ with respect to $B$, it is\nstraightforward to show that\n%\n\\begin{equation}\n\\Bom_{AB} = -\\Bom_{BA}. \n\\end{equation}\n%\n\n\\section{Spatial velocities and forces}\n\\label{SpatialVelocitiesAndForces:sec}\n\nGiven two 3D coordinate frames A and B, the {\\it spatial velocity},\nor {\\it twist},\n$\\hat\\v_{BA}$ of B with respect to A is given by the 6D \ncomposition of the translational velocity $\\v_{BA}$ of the\norigin of B with respect to A and the angular velocity $\\Bom_{BA}$:\n%\n\\begin{equation}\n\\hat\\v_{BA} \\equiv \\matl \\v_{BA} \\\\ \\Bom_{BA} \\matr.\n\\end{equation}\n%\nSimilarly, the {\\it spatial force}, or {\\it wrench}, $\\hat\\f$ acting\non a frame B is given by the 6D composition of the translational force\n$\\f_B$ acting on the frame's origin and the moment $\\Btau$, or torque,\nacting through the frame's origin:\n%\n\\begin{equation}\n\\hat\\f_B \\equiv \\matl \\f_B \\\\ \\Btau_B \\matr.\n\\end{equation}\n%\n\n\\begin{figure}[ht]\n\\begin{center}\n \\iflatexml\n   \\includegraphics[width=3.25in]{images/rigidAB}\n \\else\n   \\includegraphics[width=3.25in]{images/rigidAB}\n \\fi\n\\end{center}\n\\caption{Two frames A and B rigidly connected within a rigid body\nand moving with respect to a third frame C.}\n\\label{rigidAB:fig}\n\\end{figure}\n\nIf we have two frames $A$ and $B$ rigidly connected within a rigid\nbody (Figure \\ref{rigidAB:fig}), and we know the spatial velocity\n$\\hat\\v_{BC}$ of $B$ with respect to some third frame $C$, we may wish\nto know the spatial velocity $\\hat\\v_{AC}$ of $A$ with respect to $C$.\nThe angular velocity components are the same, but the translational\nvelocity components are coupled by the angular velocity and the offset\n$\\p_{BA}$ between $A$ and $B$, so that\n%\n\\begin{equation*}\n\\v_{AC} = \\v_{BC} + \\p_{BA} \\times \\Bom_{BC}.\n\\end{equation*}\n%\n$\\hat\\v_{AC}$ is hence related to $\\hat\\v_{BC}$ via\n\\begin{equation*}\n\\matl \\v_{AC} \\\\ \\Bom_{AC} \\matr =\n\\matl \\I & [\\p_{BA}] \\\\ 0 & \\I \\matr \\,\n\\matl \\v_{BC} \\\\ \\Bom_{BC} \\matr.\n\\end{equation*}\n%\nwhere $[\\p_{BA}]$ is defined by\n(\\ref{xprodmatrix:eqn}).\n\nThe above equation assumes that all quantities are expressed\nwith respect to the same coordinate frame.\nIf we instead consider $\\hat\\v_{AC}$ and $\\hat\\v_{BC}$ to be represented\nin frames $A$ and $B$, respectively, then\nwe can show that\n%\n\\begin{equation}\n{}^A\\hat\\v_{AC} = \\X_{BA} \\, {}^B\\hat\\v_{BC},\n\\end{equation}\n%\nwhere\n%\n\\begin{equation}\n\\X_{BA} \\equiv\n\\matl \\R_{BA} & [\\p_{BA}] \\R_{BA} \\\\ 0 & \\R_{BA} \\matr.\n\\label{XvelAB:eqn}\n\\end{equation}\n%\nThe transform $\\X_{BA}$ is easily formed from the components of the\nrigid transform $\\T_{BA}$ relating $B$ to $A$.\n\nThe spatial forces $\\hat\\f_A$ and $\\hat\\f_B$ acting on frames $A$ and\n$B$ within a rigid body are related in a similar way, only with\nspatial forces, it is the moment that is coupled through the moment\narm created by $\\p_{BA}$, so that\n%\n\\begin{equation*}\n\\Btau_{A} = \\Btau_{B} + \\p_{BA} \\times \\f_{B}.\n\\end{equation*}\n%\nIf we again assume that $\\hat\\f_A$ and $\\hat\\f_B$\nare expressed in frames $A$ and $B$, we can show that\n%\n\\begin{equation}\n{}^A\\hat\\f_A = \\X^*_{BA} \\, {}^B\\hat\\f_B,\n\\end{equation}\n%\nwhere\n%\n% LaTeXML fails to interpret the [ bracket when directly after \\\\\n\\iflatexml\n\\begin{equation}\n\\X^*_{BA} \\equiv \n\\matl \\R_{BA} & 0 \\\\  ~[\\p_{BA}]\\R_{BA} & \\R_{BA} \\matr. \n\\label{XforceAB:eqn}\n\\end{equation}\n\\else\n\\begin{equation}\n\\X^*_{BA} \\equiv\n\\matl \\R_{BA} & 0 \\\\  [\\p_{BA}] \\R_{BA} & \\R_{BA} \\matr.\n\\label{XforceAB:eqn}\n\\end{equation}\n\\fi\n\n\n\\section{Spatial inertia}\n\\label{SpatialInertia:sec}\n\nAssume we have a rigid body with mass $m$ and a coordinate frame\nlocated at the body's center of mass.  If $\\v$ and $\\Bom$ give the\ntranslational and rotational velocity of the coordinate frame, then\nthe body's linear and angular momentum $\\p$ and $\\L$ are given by\n%\n\\begin{equation}\n\\p = m \\v \\quad \\text{and} \\quad \\L = \\J \\Bom,\n\\label{momenta:eqn}\n\\end{equation}\n%\nwhere $\\J$ is the $3 \\times 3$ {\\it rotational inertia} with respect\nto the center of mass. These relationships can be combined into a\nsingle equation\n%\n\\begin{equation}\n\\hat\\p = \\M \\hat\\v,\n\\label{momentum:eqn}\n\\end{equation}\n%\nwhere $\\hat\\p$ and $\\M$ are the {\\it spatial momentum} and\n{\\it spatial inertia}:\n%\n\\begin{equation}\n\\hat\\p \\equiv \\matl \\p \\\\ \\L \\matr, \\qquad\n\\M \\equiv \\matl m \\I & 0 \\\\ 0 & \\J \\matr.\n\\end{equation}\n%\nThe spatial momentum satisfies Newton's second law, so that\n%\n\\begin{equation}\n\\hat\\f = \\frac{d \\hat\\p}{dt} = \\M \\frac{d \\hat\\v}{dt} + \\dot\\M \\hat\\v,\n\\end{equation}\n%\nwhich can be used to find the acceleration of a body in response to a\nspatial force.\n\nWhen the body coordinate frame is {\\it not} located at the center of\nmass, then the spatial inertia assumes the more complicated form\n%\n\\begin{equation}\n\\matl \nm \\I & -m [\\c] \\\\ m [\\c] & \\J - m[\\c][\\c]\n\\matr,\n\\end{equation}\n%\nwhere $\\c$ is the center of mass and $[\\c]$ is defined by\n(\\ref{xprodmatrix:eqn}).\n\nLike the rotational inertia, the spatial inertia is always symmetric\npositive definite if $m > 0$.\n", "meta": {"hexsha": "e435f20c9e1b01aba4948bd2207685b57867f1b0", "size": 18189, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/modelguide/appendix.tex", "max_stars_repo_name": "aaltolab/artisynth_core", "max_stars_repo_head_hexsha": "ce01443e067f20a3f5874c05e9b97019ca7c7ca7", "max_stars_repo_licenses": ["Apache-2.0", "BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/modelguide/appendix.tex", "max_issues_repo_name": "aaltolab/artisynth_core", "max_issues_repo_head_hexsha": "ce01443e067f20a3f5874c05e9b97019ca7c7ca7", "max_issues_repo_licenses": ["Apache-2.0", "BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/modelguide/appendix.tex", "max_forks_repo_name": "aaltolab/artisynth_core", "max_forks_repo_head_hexsha": "ce01443e067f20a3f5874c05e9b97019ca7c7ca7", "max_forks_repo_licenses": ["Apache-2.0", "BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.1490384615, "max_line_length": 85, "alphanum_fraction": 0.6925064599, "num_tokens": 5926, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8615382058759128, "lm_q1q2_score": 0.7216416004160098}}
{"text": "\\section{Force Constants}\\index{Force constants}\\index{Internal!coordinate!force constants}\\label{fc}\r\nInternal coordinate force constants, $f_{ic}$, can be derived from the\r\nCartesian coordinates and the Cartesian force constant matrix by use of:\r\n$$\r\nf_{ic}(l) = \\sum_j\\sum_k\r\n\\frac{d({\\rm c.c.}_j)}{d({\\rm i.c.}_l)}\r\n\\frac{d^2E}{d({\\rm c.c.}_j)d({\\rm c.c.}_k)}\r\n\\frac{d({\\rm c.c.}_k)}{d({\\rm i.c.}_l)}.\r\n$$\r\nAs with the gradients, the calculation of $\\frac{d({\\rm c.c.}_j)}{d({\\rm\r\ni.c.}_l)}$ is quite simple, and in done in routine JCARIN.\r\n\r\nDuring the testing of this function, a minor fault in the conventional\r\nforce calculation was revealed.  To reduce any error introduced by\r\nfinite arithmetic, the Hessian matrix is symmetrized before the\r\nvibrational frequencies and normal coordinates are calculated.  This is\r\ndone by \\hyperref[pageref]{operating on the Hessian matrix}{ as\r\ndescribed on p.~}{}{sym_force}.\r\n\r\nIn addition to the requirement that the symmetry of the Hessian should be the\r\nsame as that of the nuclear coordinates, a second requirement is that the\r\ndiagonal elements of the Hessian should be equal to the negative of the sum of\r\nthe off-diagonal elements, that is, that:\r\n$$\r\nF_{ii} = -\\sum_{j\\ne i}F_{ij}.\r\n$$\r\nDuring the testing of the internal force constants, very small variations in\r\nthe force constants were found where no variation was expected.  This was\r\ntraced back to a failure of the above expression.  To correct this, the\r\ndiagonal terms of the force constant matrix were modified.  This resulted in a\r\nperfect equivalence of equivalent force constants.  An incidental benefit would\r\nbe that the associated error in the calculated frequencies would be eliminated.\r\n", "meta": {"hexsha": "9ba7662e1847961981e9d90e3deb68cf26a49c2d", "size": 1710, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuals/MOPAC2000_manual/t_fc.tex", "max_stars_repo_name": "openmopac/MOPAC-archive", "max_stars_repo_head_hexsha": "01510e44246de34a991529297a10bcf831336038", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-12-16T20:53:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T20:54:11.000Z", "max_issues_repo_path": "manuals/MOPAC2000_manual/t_fc.tex", "max_issues_repo_name": "openmopac/MOPAC-archive", "max_issues_repo_head_hexsha": "01510e44246de34a991529297a10bcf831336038", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "manuals/MOPAC2000_manual/t_fc.tex", "max_forks_repo_name": "openmopac/MOPAC-archive", "max_forks_repo_head_hexsha": "01510e44246de34a991529297a10bcf831336038", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.8181818182, "max_line_length": 102, "alphanum_fraction": 0.7456140351, "num_tokens": 456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541561135441, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7215835938152827}}
{"text": "\\section{Learning Theory}\n\\subsection{Bias and Variance}\n\\subsection{Notation}\n\\subsubsection{Union Bound}\n\\subsubsection{Hoeffding Inequality For Bernoulli Variables}\n\\subsection{Training Error}\nFor a given classifier $h$, we define the training error $\\widehat{\\epsilon}(h)$,\nalso known as the empirical risk or empirical error, to be:\n\\begin{equation} \\widehat{\\epsilon}(h) = \\frac{1}{m}\\sum_{i=1}^m 1_{\\{h(x^{(i)})\\neq y^{(i)}\\}} \\end{equation}\n\\subsection{Probably Approximately Correct (PAC)}\nPAC learning is a framework with the following set of assumptions:\n% \\begin{enumerate}\n% \\end{enumerate}\n\\subsection{Hypothesis Classes}\n\\subsubsection{Shattering}\n\\subsubsection{Upper Bound Theorem}\n\\subsubsection{VC Dimension}\n\\subsubsection{Vapnik Theorem}\n", "meta": {"hexsha": "70308593fa0352ad1283ac40bd5ed7083b3e296a", "size": 759, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study_guide/sections/learning_theory.tex", "max_stars_repo_name": "nextBillyonair/StudyGuide", "max_stars_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-02-18T19:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-17T21:49:14.000Z", "max_issues_repo_path": "study_guide/sections/learning_theory.tex", "max_issues_repo_name": "nextBillyonair/StudyGuide", "max_issues_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "study_guide/sections/learning_theory.tex", "max_forks_repo_name": "nextBillyonair/StudyGuide", "max_forks_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.9473684211, "max_line_length": 110, "alphanum_fraction": 0.768115942, "num_tokens": 215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.7215536380157339}}
{"text": "\n\\subsection{Mixed logit (random coefficients)}\n\n\\subsubsection{Introduction}\n\nIn our standard model we have:\n\n\\(z_{ij}=\\beta x_{ij} +\\epsilon_{ij} \\)\n\nIf we allow the parameters to vary for each individual we have:\n\n\\(z_{ij}=\\beta_i x_{ij} +\\epsilon_{ij} \\)\n\nThe probability of choosing \\(j\\) now depends on the distribution of \\(\\beta \\).\n\nIn the IID case we had:\n\n\\(P_{ij}=\\dfrac{e^{\\beta x_{ij}}}{\\sum_k e^{\\beta x_{ik}}}\\)\n\nRather than evaluate this at a single point \\(\\beta \\) we integrate.\n\n\\(P_{ij}=\\int \\dfrac{e^{\\beta x_{ij}}}{\\sum_k e^{\\beta x_{ik}}}f(\\beta )d\\beta \\)\n\nIf \\(\\beta \\) is degenerate this reduces to the standard logit model.\n\n", "meta": {"hexsha": "18feeda590e9af15568bbe523bb9aa4f4a07265c", "size": 653, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/glmMulti/01-05-mixed.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/glmMulti/01-05-mixed.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/glmMulti/01-05-mixed.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.1153846154, "max_line_length": 81, "alphanum_fraction": 0.6722817764, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625126757596, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.7214953804441909}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\\usepackage{amsmath} \n\\usepackage{amsthm}\n\\usepackage{amsfonts}\n\n\\begin{document}\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{definition}{Definition}\n\n\n\\title{Deriving Laplace's Equation in Spherical Coordinates}\n\\author{Justin Meiners}\n\n\\maketitle\n\n\\section{Laplace's Equation}\n\nLaplace's equation states\n$$\\nabla\\cdot\\nabla f=0$$.\n\nFor 3D coordinates this is written as:\n$$\\frac{\\partial^{2}}{\\partial x^{2}}+\\frac{\\partial^{2}}{\\partial y^{2}}+\\frac{\\partial^{2}}{\\partial z^{2}}=0$$\n\n\nBut, these are cartesian coordinates, we want to transform this into spherical coordinates.\n\n\\section{Spherical Coordinate System}\n\nThe 3 dimensional Laplace's equation can be transformed into spherical coordinates, by changing variables. This procedure is similar to change of variables for spherical integrals in multivariable calculus.\n\nA 3D sphere can be parameterized by three variables: radius, $\\theta$ and $\\phi$:\n\n\\begin{equation}\n\\begin{split}\nx&=r\\sin\\phi\\cos\\theta \\\\\ny&=r\\sin\\phi\\sin\\theta \\\\\nz&=r\\cos\\phi \\\\\n\\theta&=\\arctan(\\frac{y}{x}) \\\\\n\\phi&=arccos(\\frac{z}{r}) \\\\\nr^{2}&=x^{2}+y^{2}+z^{2} \\\\\n\\end{split}\n\\end{equation}\n\n\\section{First Derivative}\n\nFirst derivative for x\n\n$$\\frac{\\partial}{\\partial x}=\\frac{\\partial r}{\\partial x}\\frac{\\partial}{\\partial r} + \\frac{\\partial \\theta}{\\partial x}\\frac{\\partial}{\\partial \\theta} + \\frac{\\partial \\phi}{\\partial x}\\frac{\\partial}{\\partial \\phi}$$\n\n$$2r\\frac{\\partial r}{\\partial x}=2x$$\n$$\\frac{\\partial r}{\\partial x}=\\frac{x}{r}=\\sin\\phi\\cos\\theta$$\n\n$$\\frac{\\partial \\theta}{\\partial x}=\\frac{1}{1+\\frac{y^{2}}{x^{2}}}(\\frac{-y}{x^{2}})=\\frac{-y}{x^{2}+y^{2}}=\\frac{-\\sin(\\theta)}{r\\sin(\\phi)}$$\n\n$$\\frac{\\partial \\phi}{\\partial x}=\\frac{-1}{\\sqrt{1-\\frac{z^{2}}{r^{2}}}}z(\\frac{-1}{2})(x^{2}+y^{2}+z^{2})^{-3/2}(2x)$$\n$$=\\frac{zx}{\\sqrt{1-\\cos^{2}\\phi}r^{3}}=\\frac{\\cos\\phi\\cos\\theta}{r}$$\n\nFirst derivative for y\n\n$$\\frac{\\partial}{\\partial y}=\\frac{\\partial r}{\\partial y}\\frac{\\partial}{\\partial r}+\\frac{\\partial \\theta}{\\partial y}\\frac{\\partial}{\\partial \\theta}+\\frac{\\partial \\phi}{\\partial y}\\frac{\\partial}{\\partial \\phi}$$\n\n$$2r\\frac{\\partial r}{\\partial y}=2y$$\n$$\\frac{\\partial r}{\\partial y}=\\frac{y}{r}=\\sin(\\phi)\\sin(\\theta)$$\n$$\\frac{\\partial \\theta}{\\partial y}=\\frac{1}{1+\\frac{y^{2}}{x^{2}}}(\\frac{1}{x})=\\frac{x}{x^{2}+y^{2}}=\\frac{\\cos\\theta}{r\\sin\\phi}$$\n$$\\frac{\\partial \\phi}{\\partial y}=\\frac{-1}{\\sqrt{1-\\frac{z^{2}}{r^{2}}}}z(-1/2)(x^{2}+y^{2}+z^{2})^{-3/2}2y$$\n$$=\\frac{r\\cos{\\phi}r\\sin{\\phi}\\sin{\\theta}}{\\sin{\\phi}(r^{3})}=\\frac{\\cos(\\phi)\\sin(\\theta)}{r}$$\n\nFirst derivative for z\n\n$$\\frac{\\partial}{\\partial z}=\\frac{\\partial r}{\\partial z}\\frac{\\partial}{\\partial r}+\\frac{\\partial \\theta}{\\partial z}\\frac{\\partial}{\\partial \\theta}+\\frac{\\partial \\phi}{\\partial z}\\frac{\\partial}{\\partial \\phi}$$\n\n$$2r\\frac{\\partial r}{\\partial z}=2z$$\n$$\\frac{\\partial r}{\\partial z}=\\frac{z}{r}=\\cos(\\phi)$$\n$$\\frac{\\partial \\theta}{\\partial z}=0$$\n$$\\frac{\\partial \\phi}{\\partial z}=\\frac{-1}{\\sqrt{1-\\frac{z^2}{r^2}}}(\\frac{r - 1/2(x^{2}+y^{2}+z^{2})^{-3/2}(2z)(z)}{r^{2}})$$\n$$=\\frac{-1}{\\sqrt{1-\\cos^{2}\\phi}}(\\frac{1}{r}-\\frac{z^{2}}{r{^3}})$$\n$$=\\frac{-1}{\\sin \\phi}(\\frac{1}{r}-\\frac{z^{2}}{r^{3}})=\\frac{-1}{r\\sin\\phi}+\\frac{\\cos^{2}\\phi}{r\\sin(\\phi)}$$\n$$=\\frac{1-\\sin^{2}\\phi-1}{r\\sin\\phi}=\\frac{-\\sin\\phi}{r}$$\n\nHere are all the first derivatives together:\n$$\\frac{\\partial}{\\partial x}=\\sin\\phi\\cos\\theta\\frac{\\partial }{\\partial r}-\\frac{\\sin\\theta}{r\\sin\\phi}\\frac{\\partial}{\\partial \\theta} + \\frac{\\cos\\phi\\cos\\theta}{r}\\frac{\\partial}{\\partial \\phi}$$\n$$\\frac{\\partial}{\\partial y}=\\sin\\phi\\sin\\theta\\frac{\\partial}{\\partial r}+\\frac{\\cos\\theta}{r\\sin\\phi}\\frac{\\partial}{\\partial \\theta}+\\frac{\\cos\\phi\\sin\\theta}{r}\\frac{\\partial}{\\partial \\phi}$$\n$$\\frac{\\partial}{\\partial z}=\\cos\\phi\\frac{\\partial}{\\partial r} - \\frac{\\sin\\phi}{r}\\frac{\\partial}{\\partial\\phi}$$\n\n\\section{Second Derivative}\n\nWe must now take the second deriative by applying each of the first derivatives to themselves. \n\n$$\\frac{\\partial^{2}}{\\partial x^{2}} + \\frac{\\partial^{2}}{\\partial y^{2}} + \\frac{\\partial^{2}}{\\partial z^{2}}=\\frac{\\partial}{\\partial x}(\\frac{\\partial}{\\partial x}) + \\frac{\\partial}{\\partial y}(\\frac{\\partial}{\\partial y}) + \\frac{\\partial}{\\partial z}(\\frac{\\partial}{\\partial z})$$\n\nBecause of the chain rule, each term in the first derivative needs to be applied to each other term. For each $\\frac{\\partial}{\\partial x}$, $\\frac{\\partial}{\\partial y}$, there will be 9 terms and for $\\frac{\\partial}{\\partial z}$ there will be 4 terms. Each term will require the product rule, so double them, for $(9+9+4)2=44$ total.\n\nWith so many terms, it would be too unwieldy to start taking derivatives in order. Instead, we will organize them by differential terms, and then piece them together. Also, instead of computing the product rule, we will compute one part of the product rule at a time. As we will see, many of the terms will drop out anyway.\n\nSecond order terms (8 total):\n\n$$\\frac{\\partial^{2}}{\\partial r^{2}}:\\sin^{2}\\phi\\cos^{2}\\theta+\\sin^{2}\\phi\\sin^{2}\\theta+\\cos^{2}\\phi$$\n$$=\\sin^{2}\\phi(1)+\\cos^{2}\\phi=1$$\n\n$$\\frac{\\partial^{2}}{\\partial \\theta^{2}}:\\frac{\\sin^{2}\\theta}{r^{2}\\sin^{2}\\phi}+\\frac{\\cos^{2}\\theta}{r^{2}\\sin^{2}\\phi}+0$$\n$$=\\frac{1}{r^{2}\\sin^{2}\\phi}$$\n\n$$\\frac{\\partial^{2}}{\\partial \\phi^{2}}:\\frac{\\cos^{2}\\phi\\cos^{2}\\theta}{r^{2}} + \\frac{\\cos^{2}\\phi\\sin^{2}\\theta}{r^{2}} + \\frac{\\sin^{2}\\phi}{r^{2}}$$\n$$=\\frac{\\cos^{2}\\phi(1)+\\sin^{2}\\phi}{r^{2}}=\\frac{1}{r^{2}}$$\n\nMixed partial terms (14 total):\n\n$$\\frac{\\partial^{2}}{\\partial r \\partial\\theta}: \\frac{2\\sin\\phi\\cos\\theta(-\\sin\\theta)}{r\\sin\\phi}+\\frac{2\\sin\\phi\\sin\\theta(\\cos\\theta)}{r\\sin\\phi}+0=0$$\n$$\\frac{\\partial^{2}}{\\partial r \\partial\\phi}: \\frac{2\\sin\\phi\\cos\\phi\\cos^{2}\\theta}{r} + \\frac{2\\cos\\phi\\sin\\phi\\sin^{2}\\theta}{r} -\\frac{2\\sin\\phi\\cos\\phi}{r}$$\n$$=\\frac{2\\sin\\phi\\cos\\theta(1) - 2\\sin\\phi\\cos\\theta}{r}=0$$\n\n$$\\frac{\\partial^{2}}{\\partial\\theta \\partial\\phi}: \\frac{-2\\sin\\theta\\cos\\phi\\cos\\theta}{r^{2}\\sin\\phi} + \\frac{2\\cos\\theta\\cos\\phi\\sin\\theta}{r^{2}\\sin\\phi}=0$$\n\nFirst order terms (22 total):\n\n$$\\frac{\\partial}{\\partial r}: \\sin\\phi\\cos\\theta\\frac{\\partial}{\\partial r}(\\sin\\phi\\cos\\theta) + \\frac{-\\sin\\theta}{r\\sin\\phi}\\frac{\\partial}{\\partial \\theta}(\\sin\\phi\\cos\\theta) + \\frac{\\cos\\phi\\cos\\theta}{r}\\frac{\\partial}{\\partial\\phi}(\\sin\\phi\\cos\\theta) $$\n$$+\\sin\\phi\\sin\\theta\\frac{\\partial}{\\partial r}(\\sin\\phi\\sin\\theta)+\\frac{\\cos\\theta}{r\\sin\\phi}\\frac{\\partial}{\\partial \\theta}(\\sin\\phi\\sin\\theta)+\\frac{\\cos\\phi\\sin\\theta}{r}\\frac{\\partial}{\\partial\\phi}(\\sin\\phi\\sin\\theta)$$\n$$+\\cos\\phi\\frac{\\partial}{\\partial r}(\\cos\\phi) - \\frac{\\sin\\phi}{r}\\frac{\\partial}{\\partial \\phi}(\\cos\\phi)$$\n\n$$=0+\\frac{\\sin^{2}\\theta}{r}+\\frac{\\cos^{2}\\phi\\cos^{2}\\theta}{r} + 0 + \\frac{\\cos^{2}\\theta}{r} + \\frac{\\cos^{2}\\phi\\sin^{2}\\theta}{r}+0+\\frac{\\sin^{2}\\phi}{r}$$\n\n$$=\\frac{1}{r}+\\frac{\\cos^{2}\\phi +\\sin^{2}\\phi}{r}=\\frac{2}{r}$$\n\n$$\\frac{\\partial}{\\partial \\theta}: \\sin\\phi\\cos\\theta\\frac{\\partial}{\\partial r}(\\frac{-\\sin\\theta}{r\\sin\\phi}) + \\frac{-\\sin\\theta}{r\\sin\\phi}\\frac{\\partial}{\\partial \\theta}(\\frac{-\\sin\\theta}{r\\sin\\phi}) + \\frac{\\cos\\phi\\cos\\theta}{r}\\frac{\\partial}{\\partial \\phi}(\\frac{-\\sin\\theta}{r\\sin\\phi})$$ \n$$+ \\sin\\phi\\sin\\theta\\frac{\\partial}{\\partial r}(\\frac{\\cos\\theta}{r\\sin\\phi}) + \\frac{\\cos\\theta}{r\\sin\\phi}\\frac{\\partial}{\\partial\\theta}(\\frac{\\cos\\theta}{r\\sin\\phi}) + \\frac{\\cos\\phi\\sin\\theta}{r}\\frac{\\partial}{\\partial \\phi}(\\frac{\\cos\\theta}{r\\sin\\phi})$$\n$$=0$$\n\n$$\\frac{\\partial}{\\partial \\phi}: \\sin\\phi\\cos\\theta\\frac{\\partial}{\\partial r}(\\frac{\\cos\\phi\\cos\\theta}{r}) - \\frac{\\sin\\theta}{r\\sin\\phi}\\frac{\\partial}{\\partial\\theta}(\\frac{\\cos\\phi\\cos\\theta}{r}) + \\frac{\\cos\\phi\\cos\\theta}{r}\\frac{\\partial}{\\partial\\phi}(\\frac{\\cos\\phi\\cos\\theta}{r})$$\n$$+\\sin\\phi\\sin\\theta\\frac{\\partial}{\\partial r}(\\frac{\\cos\\phi\\sin\\theta}{r}) + \\frac{\\cos\\theta}{r\\sin\\phi}\\frac{\\partial}{\\partial\\theta}(\\frac{\\cos\\phi\\sin\\theta}{r}) + \\frac{\\cos\\phi\\sin\\theta}{r}\\frac{\\partial}{\\partial\\phi}(\\frac{\\cos\\phi\\sin\\theta}{r})$$\n$$+\\cos\\phi\\frac{\\partial}{\\partial r}(\\frac{-\\sin\\phi}{r})-\\frac{\\sin\\phi}{r}\\frac{\\partial}{\\partial\\phi}(\\frac{-\\sin\\phi}{r})$$\n$$=\\frac{-\\sin\\phi\\cos\\phi\\cos^{2}\\theta}{r^{2}}+\\frac{\\sin^{2}\\theta\\cos\\phi}{r^{2}\\sin\\phi}-\\frac{\\cos\\phi\\sin\\phi\\cos^{2}\\theta}{r^{2}}$$\n$$-\\frac{\\sin\\phi\\cos\\phi\\sin^{2}\\theta}{r^{2}}+\\frac{\\cos\\phi\\cos^{2}\\theta}{r^{2}\\sin\\phi}-\\frac{\\sin\\phi\\cos\\phi\\sin^{2}\\theta}{r^{2}}$$\n$$+\\frac{\\cos\\phi\\sin\\phi}{r^{2}}+\\frac{\\cos\\phi\\sin\\phi}{r}$$\n$$=\\frac{-\\sin\\phi\\cos\\phi(1)}{r^{2}}+\\frac{\\cos\\phi(1)}{r^{2}\\sin\\phi} - \\frac{\\sin\\phi\\cos\\phi(1)}{r^{2}} + \\frac{2\\cos\\phi\\sin\\phi}{r^{2}}$$\n$$=\\frac{\\cot\\phi}{r^{2}}$$\n\n\\section{Final Equation}\n\nAdding up each of the second derivative terms gives us the final equation.\n\n$$\\frac{\\partial^{2}}{\\partial r^{2}} + \\frac{2}{r}\\frac{\\partial}{\\partial r} + \\frac{1}{r^{2}\\sin^{2}\\phi}\\frac{\\partial^{2}}{\\partial\\theta^{2}} + \\frac{1}{r^{2}}\\frac{\\partial^{2}}{\\partial \\phi^{2}}+\\frac{\\cot\\phi}{r^{2}}\\frac{\\partial}{\\partial \\phi}=0$$\n\n\\end{document}\n\n", "meta": {"hexsha": "3780eb09b8ccdcc513090f69f6ffc6bd3c4e45ce", "size": 9200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/laplace.tex", "max_stars_repo_name": "neoliang/spherical-harmonics", "max_stars_repo_head_hexsha": "702fbd0c40a70262a95e27442996ddb00137807e", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2019-09-29T05:23:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-30T17:47:03.000Z", "max_issues_repo_path": "paper/laplace.tex", "max_issues_repo_name": "justinmeiners/spherical-harmonics", "max_issues_repo_head_hexsha": "702fbd0c40a70262a95e27442996ddb00137807e", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/laplace.tex", "max_forks_repo_name": "justinmeiners/spherical-harmonics", "max_forks_repo_head_hexsha": "702fbd0c40a70262a95e27442996ddb00137807e", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-02T07:16:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-12T14:12:48.000Z", "avg_line_length": 62.1621621622, "max_line_length": 336, "alphanum_fraction": 0.6340217391, "num_tokens": 3555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.721451867861059}}
{"text": "\\section{Functions of Random Variables, Derived Distributions}\n\n(This section needs revision)\n\nI find changes of variables to be the easiest to understand by writing down a joint probability distribution using a delta function to express the conditional probability for the new variables based on the old variables. The next step is to perform a change of variables in the delta function, and integrate. The delta function means that the relationship between the old and the new variables is deterministic. If the relationship is non-deterministic you can use whatever expression for the conditional probability is appropriate.\n\nLet's say that you want to know the probability distribution of the function $\\vec{u} = \\mathbf{H}(\\vec{x})$ of some random variable $\\vec{x}$ for which the probability distribution is known.\n\nI personally find it least confusing to approach this problem by thinking about the joint probability distribution, and then obtaining $p(\\vec{u})$ through marginalization:\n\n\\begin{equation}\np(\\vec{u}) = \\int dx^n p(\\vec{x},\\vec{u}) = \\int dx^n p_x(\\vec{x}) p_u(\\vec{u}|\\vec{x})\n\\end{equation}\n\nSince $\\vec{u}$ is a deterministic function of $\\vec{x}$, the conditional probabiltiy $p_u(\\vec{u}|\\vec{x}) = \\delta(\\vec{u} - \\mathbf{H}(\\vec{x}))$. Explicitly:\n\n\\begin{equation}\np(\\vec{u}) = \\int dx^n p_x(\\vec{x}) \\delta(\\vec{u} - \\mathbf{H}(\\vec{x}))\n\\end{equation}\n\nWhat this does, is to integrate over all the points $p_x(\\vec{x})$ where the argument of the delta function is zero. The important thing is that care needs to be taken when the argument of the delta function is itself a function. In that case, a change of variables has to be performed, so that this is no longer the case. On wikipedia, this is done by defining the new variable $du = |\\frac{d}{dx}g(x)|dx$, from which follows:\n\n\\begin{equation}\n\\delta(g(x)) = \\sum_{x_0} \\frac{\\delta(x-x_0)}{|g'(x_0)|}\n\\end{equation}\n\nWhere it is necessary to sum over each point $x_0$ for which $g(x_0) = 0$.\n\nWhich makes sense. Except, if you rewrite in terms of the new variable, you get an expression that does not strike me as necessarily the same:\n\n\\begin{equation}\n\\int f(x) \\delta(g(x))dx = \\sum_{n}\\int f(g_n^{-1}(u)) \\delta(u) \\left|\\frac{d}{du}g^{-1}(u)\\right|du\n\\end{equation}\n\nWhere the sum $n$ is over all functions $g_n^{-1}$ that satisfy $g(g_n^{-1}(u)) = u$. For example, if $u = g(x) = sin(x)$ then $g_n^{-1} = asin(u) + n2\\pi$, for any integer $n$. I feel more comfortable with the second path. The answer to my confusion is most likely the inverse function theorem (cf. section \\ref{sec:inverse_function_theorem}). In other words: this section needs revision! But hey, I flagged it.\n\nNote that a delta function with a vector argument can be written as a product of the delta functions along each dimension.\n\nDefine a new set of variables $\\vec{a} = \\vec{u} - \\mathbf{H}(\\vec{x})$. It follows that $\\vec{x} = \\mathbf{H_n^{-1}}(\\vec{u}-\\vec{a})$ and the volume element $dx^n = \\left| \\frac{d}{d\\vec{a}}\\mathbf{H}_n^{-1}(\\vec{u}-\\vec{a})\\right|da^n$. Here, $H^{-1}_n$ are all the functions that satisfy $\\mathbf{H}(\\mathbf{H}_n^{-1}(\\vec{u})) = \\vec{u}$. The integral becomes:\n\n\\begin{equation}\np(\\vec{u}) = \\int da^n p_x(\\mathbf{H}^{-1}_n(\\vec{u}-\\vec{a}))\\left| \\frac{d}{d\\vec{a}}\\mathbf{H}_n^{-1}(\\vec{u}-\\vec{a})\\right| \\delta(\\vec{a})\n\\end{equation}\n\nAt this point it is safe to evaluate the delta function integral. The result is:\n\n\\begin{equation}\np(\\vec{u}) = p_x(\\mathbf{H}^{-1}_n(\\vec{u})\\left| \\frac{d}{d\\vec{a}}\\mathbf{H}_n^{-1}(\\vec{u}-\\vec{a})\\right|_{(\\vec{a}=0)}\n\\end{equation}\n\n\\subsection{Example: Sum of Random Variables}\nIf the map $\\mathbf{H}$ is not bijective, for example because $\\vec{u}$ has lower dimensionality than $\\vec{x}$, then a bijective map can be artifically constructed by introducing additional variables that are then also marginalized out. For example, if the goal is to calculate the probability of measuring some sum of random variables $s$, then you can define:\n\n\\begin{equation}\nu_0 = s - \\sum(x_i)\\\\\nu_1 = x_1\\\\\nu_2 = x_2\\\\\n\\vdots\\\\\nu_{(n-1)} = x_{n-1}\n\\end{equation}\n\nThe inverse is:\n\n\\begin{equation}\nx_1 = u_1\\\\\nx_2 = u_2\\\\\n\\vdots\\\\\nx_n = s - u_0 - \\sum_{i<n} x_i\n\\end{equation}\n\nThe argument in the delta function is transformed $\\delta(s - \\sum(x_i)) \\rightarrow \\delta(u_0)$. The determinant of the Jacobian $|J| = |\\frac{d}{d\\vec{u}} H^{-1}(\\vec{u})|$ is given by $[\\frac{d}{du_1} \\mathbf{H^{-1}},\\frac{d}{du_2} \\mathbf{H^{-1}},...,\\frac{d}{du_{n-1}} \\mathbf{H^{-1}}]$. That's an $nxn$ matrix where the first row is all $-1$, the lower left is an $(n-1)x(n-1)$ identity matrix, and the lower right is a $(n-1)x1$ vector of 0s. The determinant is one. Consequently the probability distribution of measuring a sum $s$ is given by:\n\n\\begin{equation}\np(s)= \\int dx^{n-1} p_x(x_1,x_2,x_3,...,s-\\sum_{x<n}x_i)\n\\end{equation}\n\nWhich turns out to be the convolution when the variables are independent.\n\n\\subsection{Example: Lower Dimensional Random Variable}\n\nThis was already the case for the sum of several random variables, in which case the dimensionality of the problem was reduced from many to one. \n\nConsider the case many to fewer. Again, you just need to perform a change of variables. The new set of variables needs to have the same dimensionality as the old set of variables. The rest should follow pretty obviously. \n\nLinear example: $\\vec{y} = \\mathbf{M}\\vec{x}$ where $y$ has 2 dimensions and $x$ has 3. \n\nTransform:\n\n\\begin{equation}\nu_1 = y_1 - \\vec{M_1}\\cdot\\vec{x}\\\\\nu_2 = y_2 - \\vec{M_2}\\cdot\\vec{x}\\\\\nu_3 = x_3\n\\end{equation}\n\nYou can write this in terms of some invertible matrix $\\mathbf{W} = [\\mathbf{M},[0,0,1]]$ as $\\vec{u} = \\mathbf{W}\\vec{x}$, so that $dx^n = |\\mathbf{W}^{-1}|du^n|$. The integral is then:\n\n\\begin{equation}\np(y) = \\int du^n p_x(\\mathbf{W}^{-1}(\\vec{y}-\\vec{u}))\\delta(u_1)\\delta(u_2)|\\mathbf{W}^{-1}|\n\\end{equation}\n", "meta": {"hexsha": "19a909acda64db7b21d6a3521723ab024f4ab33a", "size": 5893, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/proba_changevars.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/proba_changevars.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/proba_changevars.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.93, "max_line_length": 552, "alphanum_fraction": 0.6994739521, "num_tokens": 1873, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916064587, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.7213494679643979}}
{"text": "\\newpage\\section{Sets}\n\n\n\\subsection{Lemmas}\n\n\n\\lem{}{\\label{lemma:sets_lemma_1}\n    Let $ S $ be a set with $ n $ elements, and let $ F $ be a family of\n    subsets of S such that for any pair $ A, B $ in $ F $, $ A \\cap B \\not=\n    \\varnothing $. Then $ |F| \\leq 2^{n-1} $ .\n}\n\n% \\begin{enumerate}\n%     \\iref{lemma:sets_lemma_1_1}{Iran TST 2008 D3P1}{}\n% \\end{enumerate}\n\n\n\\theo{https://en.wikipedia.org/wiki/Erdos-Ko-Rado_theorem}{Erdos Ko Rado theorem}{\n    Suppose that $ A $ is a family of distinct subsets of $\\{ 1 , 2 \\dots n\n    \\}$ such that each subset is of size $ r $ and each pair of subsets has a\n    nonempty intersection, and suppose that $ n \\geq 2r $. Then the number of\n    sets in $ A $ is less than or equal to the binomial coefficient \\[\\binom\n    {n-1}{r-1}\\]\n}\n\n\n\\lem{}{Let $ S $ be a set with $ n $ elements, and let $ F $ be a family of subsets of $ S $ such that for any pair $ A, B $ in $ F $, $ S $ is not contained by $ A \\cup B $. Then $ |F| \\leq 2^{n-1} $.}\\label{lemma:sets_lemma_2}\n\n\n\n\\lem{Kleitman lemma}{A set family $F$ is said to be downwards closed if the following holds: if $X$ is a set in $F$, then all subsets of $X$ are also sets in $F$. Similarly, $F$ is said to be upwards closed if whenever $X$ is a set in $F$, all sets containing $X$ are also sets in $F$. Let $F_1$ and $F_2$ be downwards closed families of subsets of $S = \\{1, 2, ..., n\\}$, and let $F_3$ be an upwards closed family of subsets of $S$. Then we have\n\n    \\begin{align}\n        |F_1 \\cap F_2| &\\geq \\frac{|F_1| \\cdot |F_2|}{2^n}\\\\\n        |F_1 \\cap F_3| &\\leq \\frac{|F_1| \\cdot |F_3|}{2^n} \t \n\\end{align}}\\label{lemma:sets_lemma_3_Kleitman}\n\n\n\n\\lem{}{Let $ S $ be a set with $ n $ elements, and let $ F $ be a family of subsets of $ S $ such that for any pair $ A, B $ in $ F $, $ A \\cap B \\not= \\varnothing $ and $ A \\cap B \\not= S $. Then $ |F| \\leq 2^{n-2} $.}\\label{lemma:sets_lemma_4}\n\n\\solu{\n    Using the sets in \\autoref{lemma:sets_lemma_1} and\n    \\autoref{lemma:sets_lemma_1}, defining upwards and downwards sets like in\n    \\autoref{lemma:sets_lemma_3_Kleitman}.\n}\n\n\n\n\\theo{https://www.wikiwand.com/en/Sunflower_(mathematics)}\n{The Sunflower Lemma}{\n    A \\textbf{sunflower} with $ k $ petals and a core $ X $ is a family of sets $ S_1,\n    S_2,\\dots, S_k $ such that $ S_i\\cap S_j = X $ for each $ i \\neq j $. (The\n    reason for the name is that the Venn diagram representation for such a\n    family resembles a sunflower.) The sets $ S_i \\setminus X $ are known as\n    petals and must be nonempty, though $ X $ can be empty. \\\\\n\n    Show that if $ F $ is a family of sets of cardinality $ s $, and $ |F| >\n    s!(k-1)^s $, then $ F $ contains a sunflower with $ k $ petals.\n}\\label{problem:induction_type1_20}\\label{problem:extreme_object_10}\n\n\n\\solu{Applying induction and considering the best case where $ |X|=0 $}\n\n\n\\subsection{Extremal Set Theory}\n\n\\begin{myitemize}\n    \\item \\href{http://math.mit.edu/~cb_lee/18.318/lecture8.pdf}{MIT 18.314 Lecture-8}\n\\end{myitemize}\n\n\n\\theo{}{Mirsky Theorem}{A set $ S $ with a chain of height $ h $ can’t be partitioned into $ t $ anti-chains if $ t < h $. In other words, the minimum number of sets in any anti-chain partition of $ S $ is equal to the maximum height of the chains in $ S $. (And Vice Versa)}\\label{theorem:mirsky_theorem}\n\n\n\\theo{}{}{In any poset, the largest cardinality of an antichain is at most the smallest cardinality of a chain-decomposition of that poset.}\n\n\n\\theo{}{Dilworth's Theorem}{Let $ P $ be a poset. Then there exist an antichain $ A $ and a chain decomposition $ \\mathcal{C} $ of $ P $ such that $ |A| = |\\mathcal{C}| $}\n\n\n\n\\theo{http://mathworld.wolfram.com/Erdos-SzekeresTheorem.html}{Erdos-Szekeres Theorem}{Any sequence of $ ab+1 $ real numbers contains either a monotonically decreasing subsequence of length $ a+1 $ or a monotonically increasing subsequence of length $ b+1 $. The more useful case is when $ a=b=n $. }\n\n\n\n\\prob{}{}{E}{Let $ n\\ge 1 $ be an integer and let $ X $ be a set of $ n^2+1 $ positive integers such that in any subset of $ X $ with $ n+1 $ elements there exist two elements $ x\\neq y $ such that $ x|y $. Prove that there exists a subset $ \\{x_1, x_2\\dots x_{n+1} \\in X $ such that $ x_i|x_{i+1} $ for all $ i=1, 2, \\dots n $.}\n\n\n\\den{Sperner Family}{\n    A family of sets in which none of the sets is a strict subset of another\n    is called a \\textbf{Sperner family}, that is, an antichain of sets.\n}\n\n\n\\theo{https://www.wikiwand.com/en/Lubell–Yamamoto–Meshalkin_inequality}\n{LYM Inequality}{\n    Let $U$ be a set of $n$ elements and $\\mathcal{S}$ is a Sperner family of\n    subsets of $U$. If $a_k$ is the number of $k$ element subsets of\n    $\\mathcal{S}$, then\n    \\[\\impeq{\\sum^{n}_{k=0}\\frac{a_k}{{n \\choose k}}\\le 1}\\] \n}\n\n\\begin{prooof}\n    Rewrite the inequality by \n    \\[\\sum^{n}_{k=0} a_k k!(n-k)! \\le n!\\]\n    The left hand side equals to \n    \\[\\sum^{}_{S\\in \\mathcal{S}} \\left|S\\right|!\n    \\left(n-\\left|S\\right|\\right)!\\] \n    For a $S \\in \\mathcal{S}$, $\\left|S\\right|!\\left(n-\\left|S\\right|\\right)!$\n    is the number of permutations of $[n]$ for which the first\n    $\\left|S\\right|$ terms are the elements of $S$. Since the sets of\n    $\\mathcal{S}$ doesn't include each other, all of these permutations are\n    different. And so if we count them together, we will get at most all the\n    permutatios of $[n]$, which gives us our desired result.\n\\end{prooof}\n\n\n\\theo{https://www.wikiwand.com/en/Sperner's_theorem}\n{Sperner's Theorem}{\n    Sperner's theorem bounds the number of sets in any Sperner family. For any\n    Sperner Family $\\mathcal{S}$, if the union of those sets is a set of $n$\n    elements, then \n    \\[\\left|\\mathcal{S}\\right|< {n \\choose \\left\\lfloor n/2 \\right\\rfloor}\\] \n    Where equality holds iff $\\mathcal{S}$ is consisted of all subsets of\n    $[n]$ with $\\left\\lfloor n/2 \\right\\rfloor$ or $\\left\\lceil\n    n/2  \\right\\rceil $ elements.\n}\n\n\\begin{prooof}\n    Let $a_k$ be the number of $k$ element subsets of $\\mathcal{S}$. Then\n    since ${n\\choose \\left\\lfloor n/2\\right\\rfloor} \\le {n\\choose k}$, we have\n    \\[\\frac{a_k}{{n \\choose \\left\\lfloor n/2\\right\\rfloor}} \\le\n    \\frac{a_k}{{n\\choose k}}\\] \n    And since the sets doesn't contain each other, we can sum them up and by\n    \\autoref{theorem:LYM Inequality}, we get\n    \\[\\sum^{n}_{k=0} \\frac{a_k}{{n\\choose \\left\\lfloor\n    n/2\\right\\rfloor}} \\le \\sum^{n}_{k=0} \\frac{a_k}{{n\\choose k}} \\le 1\\] \n\\end{prooof}\n\n\n\n\n\n\\newpage\n\\subsection{Problems}\n\n\\prob{https://artofproblemsolving.com/community/c6h148835p841269}{USA TST 2005 P1}{E}{\n    Let $ n $ be an integer greater than $ 1 $. For a positive integer\n    $ m $ , let $ S_{m}= \\{ 1,2,\\ldots, mn\\} $. Suppose that there exists a $\n    2n $ -element set $ T $ such that\n\n    \\begin{enumerate}\n        \\item each element of $ T $ is an $ m $ -element subset of $ S_{m} $\n        \\item each pair of elements of $ T $ shares at most one common element\n        \\item each element of $ S_{m} $ is contained in exactly two elements of $ T $\n    \\end{enumerate}\n\nDetermine the maximum possible value of $ m $ in terms of $ n$.\n\\index[cat]{Sets!Max-set with property!USA TST 2005 P1}\n\\index[strat]{Double Counting!USA TST 2005 P1}\n}\n\\label{problem:double_counting_5}\n\n\\solu{We use double counting to find the ans, after that the rest is easy.}\n\n\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h206650p1136980}{Iran TST 2008 D3P1}{E}{\n    Let $S$ be a set with $n$ elements, and $F$ be a family of subsets of $S$ with\n    $ 2^{n-1}$ elements, such that for each $A,B,C\\in F$, $A\\cap B\\cap C$ is not\n    empty. Prove that the intersection of all of the elements of $F$ is not empty.\n\n    \\index[cat]{Sets!Local!Iran TST 2008 D3P1}\n    \\index[strat]{Induction!Iran TST 2008 D3P1}\n}\\label{lemma:sets_lemma_1_1}\\label{problem:induction_type1_18}\n\n\\solu{Using Induction with \\hrf{lemma:sets_lemma_1}{this} lemma.}\n\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6t309f6h1538018}{Romanian TST\n2016 D1P2}{EM}{\nLet $n$ be a positive integer, and let $S_1, S_2,\\dots S_n$ be\na collection of finite non-empty sets such that \n\\[\\sum_{1\\leq i<j\\leq n}{\\frac{|S_i \\cap S_j|}{|S_i||S_j|}} <1\\]\n\nProve that there exist pairwise distinct elements $x_1, x_2\\dots x_n$ such that $x_i$ is a member of $S_i$ for each index $i$.\n\n\\index[cat]{Sets!Local!Romanian TST 2016 D1P2}\n\\index[strat]{Focus!Romanian TST 2016 D1P2}\n\\index[strat]{Induction!Romanian TST 2016 D1P2}\n}\n\\label{problem:induction_type1_25}\\label{problem:forget_and_focus_7}\n\n\\solu{The Inductive proof reduces the problem to\n    \\hrf{problem:induction_type1_26}{American Mathematical Monthly problem\nE2309}}\n\n\\solu{The other approach is to focus on the given weird condition, and interpolate it to something nice, like probabilistic condition.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h225275p1252232}{American Mathematical Monthly E2309}{EM}{If $ A_1$, $ A_2$,\\dots $ A_n$ are $ n$ nonempty subsets of the set $ \\left\\{1,2,...,n - 1\\right\\}$, then prove that\n\n\\[\\sum_{1\\leq i < j\\leq n}\\frac {\\left|A_i\\cap A_j\\right|}{\\left|A_i\\right|\\cdot\\left|A_j\\right|}\\geq 1\\]\n\n\\index[cat]{Sets!Subsets of $[N]$!American Mathematical Monthly E2309}\n}\n\\label{problem:induction_type1_26}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h362426p1986928}{CGMO 2010\n    P1}{E}{Let $n$ be an integer greater than two, and let $A_1,A_2, \\cdots ,\n    A_{2n}$ be pairwise distinct subsets of $\\{1, 2, \\dots n\\}$. Determine the maximum\n    value of\n    \\[\\sum_{i=1}^{2n} \\dfrac{|A_i \\cap A_{i+1}|}{|A_i| \\cdot |A_{i+1}|}\\]\n    Where $A_{2n+1}=A_1$ and $|X|$ denote the number of elements in $X.$\n\n    \\index[cat]{Sets!Subsets of $[N]$!CGMO 2010 P1}\n}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h17340p119108}{ISL 2002 C5}{M}{\n    Let $r\\geq2$ be a fixed positive integer, and let $F$ be an infinite\n    family of sets, each of size $r$, no two of which are disjoint. Prove that\n    there exists a set of size $r-1$ that meets each set in $F$.\n\n\\href{https://artofproblemsolving.com/community/c6h17340p7934669}{HMMT 2016\nTeam Round}:\n    Fix positive integers $r>s$, and let $\\mathcal F$ be an infinite\n    family of sets, each of size $r$, no two of which share fewer than $s$\n    elements. Prove that there exists a set of size $r-1$ that shares at least $s$\n    elements with each set in $F$.\n\n\\index[cat]{Sets!Local!ISL 2002 C5}\n\\index[strat]{Induction!ISL 2002 C5}\n\\index[strat]{Focus!ISL 2002 C5}\n\\index[strat]{Adding new stuffs!ISL 2002 C5}\n\n}\\label{problem:induction_type1_31}\n\n\n\n\n\\solu{[Focus on a set] If we take an arbitrary set, we can say that there\nexists infinitely many sets $ \\in \\mathbb{F} $ which includes a fixed element\nfrom our test set. If we do this argument for $ r-1 $ times, we get a set $ X\n$ of $ r-1 $ elements, and an infinte family of sets that contains $ X $\ncompletely. At this point the problem is trivial.}\n\n\n\\solu{[Adding Elements]Since it's tricky to work with one family, why not introduce another family, like the second monk. \\hrf{http://artofproblemsolving.com/community/c6h17340p3251745}{This} solution generalizes the problem as such.}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h57290p352698}{ISL 1988 P10}{M}{\n    Let $ N = \\{1,2 \\ldots, n\\}, n \\geq 2. $ \n\n    A collection $ F = \\{A_1, \\ldots,A_t\\} $ of subsets \n    $ A_i \\subseteq N, $  $ i = 1, \\ldots, t, $ is said to be\n    \\textbf{separating}, if for every pair $ \\{x,y\\} \\subseteq N, $ there is a set $ A_i\n    \\in F $ so that $ A_i \\cap \\{x,y\\} $ contains just one element. \n\n    $ F $ is said to be \\textbf{covering}, if every element of $ N $ is contained \n    in at least one set $ A_i \\in F. $ \n\n    What is the smallest value $ f(n) $ of $ t, $ so there is a set $\n    F = \\{A_1, \\ldots, A_t\\} $ which is simultaneously separating and covering.\n\n    \\index[cat]{Sets!Subsets of $[N]$!ISL 1988 P10}\n    \\index[strat]{Bijection!Binary Representation!ISL 1988 P10}\n} \\label{problem:binary_2}\n\n\n\\solu{[Binary Representation]Using \\hrf{binary}{Binary} Representations for the elements as in or not in, we get an easy bijection.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h530095p3024272}{Iran TST 2013 D1P2}{E}{\n    Find the maximum number of subsets from $\\left \\{ 1,...,n \\right \\}$ such\n    that for any two of them like $A,B$ if $A\\subset B$ then $\\left | B-A\n    \\right |\\geq 3$. (Here $\\left | X \\right |$ is the number of elements of\n    the set $X$.)\n    \\index[cat]{Sets!Max-set with property!Iran TST 2013 D1P2}\n    \\index[strat]{Roots of unity filtering!Iran TST 2013 D1P2}\n    \\index[strat]{Induction!$n$ is or isn't!Iran TST 2013 D1P2}\n}\n\n\n\\solu{By partitioning the maximum set of subsets into groups which contain the number $n$ and which don't and \\href{induction}{Induction} on $n$ we can show that the maximum number of subset is\n\\[\\frac{2^{n}-(-1)^{n}}{3}\\]. }\n\n\\prob{https://artofproblemsolving.com/community/c7h64445p383300}{Putnam 2005 B4}{E}{For positive integers $ m$ and $ n$, let $f\\left(m,n\\right)$ denote the number of $ n$-tuples $\\left(x_1,x_2,\\dots,x_n\\right)$ of integers such that $\\left|x_1\\right| + \\left|x_2\\right| + \\cdots + \\left|x_n\\right|\\le m$. Show that $ f\\left(m,n\\right) = f\\left(n,m\\right)$.}\n\n\n\n\\solu{Try to show \\href{bijection}{Bisection} between the result and choosing $m$ or $n$ objects from $m+n$ objects or show that the result is $\\binom{m+n}{n}$.}\n\n\n\\newpage\n\\subsection{Hamming Distance}\n\n\n\\begin{myitemize}\n    \\item \\href{https://dgrozev.wordpress.com/2019/11/09/hamming-distance-in-olympiad-problems/} {Blogpost by dgrozev}\n\\end{myitemize}\n\n\\vspace{1em}\n\n\\den{Hamming Distance}{\n    The Hamming distance between two equal-length strings of symbols is the\n    number of positions at which the corresponding symbols are different.\n}\n\nOccasionally we might be able to use the idea of Hamming distance to\n``partition'' a set into sets of equivalence classes. For example consider the\nfollowing problem:\n\n\\prob{}\n{}{}{\n    Suppose we have some real numbers $\\left(x_{n}\\right), n=1,2, \\ldots, N$\n    and consider the sums\n    \\[ \\sum_{i=1}^{N} b_{i} x_{i},\\quad b_{i} \\in\\{0,1\\}\\]\n    We want to estimate how many among those sums hit a fixed interval\n    $\\Delta$ with some length.\n\n    \\index[strat]{Hamming distance}\n}\n\n\\begin{solution}\n    Suppose a sum $\\sum_{i=1}^{N} b_{i} x_{i}$ is inside $\\Delta$. \\\\\n\n    Then changing any bit $b_{i}, i=1,2, \\ldots, N$ we leave $\\Delta$ if this\n    interval is smaller than the largest $\\left|x_{i}\\right|, i \\in[1 \\ldots\n    N]$.\\\\\n\n    So, for any $N$ -tuple of bits $b=\\left(b_{1}, b_{2}, \\ldots,\n    b_{N}\\right)$ with corresponding sum in $\\Delta$, all the other tuples of\n    bits that differ from $b$ in exactly one bit have sums outside $\\Delta$.\\\\\n\n    In fact the set of those bits is the unit sphere around $b$ with respect\n    to the Hamming distance. So no other set on this sphere has the sum in\n    $\\Delta$.\\\\\n\n    Now, we take the set $B$ of all tuples $b=\\left(b_{1}, b_{2}, \\ldots,\n    b_{N}\\right)$ with $\\sum_{i=1}^{N} b_{i} x_{i} \\in \\Delta$. Then for any $b\n    \\in B$ the unit sphere \n    {\\color{solC} \\[S(b):=\\left\\{b^{\\prime}: b^{\\prime} \\text{differs from } b\n    \\text{ in exactly one bit}\\right\\}\\]}\n    consists of tuples not in $B$. If it happens for $b \\in B$, $S(b)$ are\n    disjoint, we can estimate the number of elements in $B$ as\n    \\[ |B| \\leq \\frac{2^{N}}{N+1} \\]\n\\end{solution}\n\n\\newpage\n\\prob{https://artofproblemsolving.com/community/c6h1946999p13424041}\n{CIIM 2019 P3}{M}{\n    Let $\\{x_n\\}_{n\\in{}\\mathbb{N}}$ be a sequence of non-zero real numbers.\n    For every positive integer $m$, we define:\n    \\[X_m=\\left\\{A\\subseteq{}\\{0,1,...,m-1\\}\\left|\\quad\\left|\\sum_{a\\in{A}}\n    x_a\\right| >\\frac{1}{m}\\right.\\right\\}\\]\n    Prove that: \\[\\lim_{n\\to\\infty} \\frac{\\vert{}X_n\\vert{}}{2^n}=1\\]\n\n    \\index[strat]{Hamming distance!CIIM 2019 P3}\n}\n\n\\begin{Remark}\n    The idea roughly speaking is as follows.\n\n    {\\color{impC}For sufficiently large $m$ we map each $A$ having small sum $\\sum_{a\\in\n    A}x_a$ to a family $F(A)$ of many other sets with big sums.} If those\n    families do not intersect, we obtain that the number of $A$'s with small\n    sums is a small portion of the all subsets. \n\n    The vague idea is to mark some finite set of distinct elements\n    $x_n$ and for a fixed set $A$ we may add or remove any marked element,\n    depending if it's in $A$ or not. Thus we obtain another sets, but those\n    sets cannot have small sums if the marked elements are appropriately\n    taken.\n\\end{Remark}\n\n\\begin{solution}[dgrozev]\n    To apply this idea we consider two cases.\\\\\n\n    \\boxed{\\textbf{1.}} There are infinitely many distinct numbers among\n    $(x_n)_{n\\ge 0}$. \\\\\n\n    Let us fix some $N\\in\\mathbb{N}$ and $I$ be a set of $N$ non negative\n    integers (indices) such $x_i, i\\in I$ are all distinct. Denote by\n    $\\varepsilon$ any positive real number less than $\\min \\left\\{|x_i-x_j|,\\\n    |x_i|\\right\\}, i, j\\in I$. \\\\\n\n    We take any $m$ large enough such that $2/m<\\varepsilon$ and $m>\\max\\{i\\in\n    I\\}$. Let $A$ is any subset of $\\{0,1,\\dots,m\\}$ satisfying\n\n    \\begin{align*}\n        \\left|\\sum_{a\\in A}x_a\\right |\\leq \\frac{1}{m}\\qquad\\qquad (1) \n    \\end{align*}\n    For any $i\\in I$ we construct the set $A_i$ as\n    \\[A_i:=\\begin{cases} A\\cup {i}& \\text{if } i\\not\\in A\\\\\n    A\\setminus\\{i\\}&\\text{if } i\\in A \\end{cases} \\]\n    It can be easily seen\n    \\[\\displaystyle \\left|\\sum_{a\\in A_i}x_a\\right |> \\frac{1}{m}\\,,\\,\\forall\n    i\\in I\\]\n\n    By $F(A)$ we denote the family $\\{A_i:i\\in I\\}$. For any two subsets $A,B$\n    of $\\{0,1,\\dots,m\\}$ satisfying $(1)$, {\\color{impC}the corresponding families $F(A),\n    F(B)$ do not meet}.\\\\\n\n    Indeed, if $X\\in F(A)$ and $X\\in F(B)$, then $X$\n    differs from $A, B$ only in one element of $I$. That is, $A$\n    differs from $B$ only in two elements that are in $I$. Hence,\n    \\[\\left|\\sum_{a\\in A}x_a-\\sum_{a\\in B}x_a\\right|>2/m\\]\n    because of the choice of $m$. It means $A$ and $B$ cannot both satisfy\n    $(1)$.\\\\\n\n    To recap. Let $\\mathcal{A}$ be the family of all subsets $A$ of $\\left\\{0,\n    1,\\dots m-1\\right\\}$ satisfying $(1)$. Then for any $A\\in\\mathcal{A}$ all\n    sets in $F(A)$ are not in $\\mathcal{A}$. Further, $F(A), A\\in \\mathcal{A}$\n    are disjoint. Since $|F(A)|=N,\\forall A\\in\\mathcal{A}$, we have\n    \\[|\\mathcal{A}|\\leq \\frac{2^m}{N+1}\\]and henceh\n    \\[\\displaystyle \\frac{|X_m|}{2^m}\\geq \\frac{N}{N+1}\\]\n    Since $N$ could be chosen arbitrary large, the result follows.\\\\\n\n    \\boxed{\\textbf{2.}} Only finite values of $(x_n)_{n\\ge 0}$ are distinct.\\\\\n\n    So, suppose $x_n=a$ for infinitely many $n\\in \\mathbb{N}$. Let $I$ be a\n    finite set of such indices with $|I|=N$ and $m\\in \\mathbb{N}$ satisfies\n    $2/m<|a|$ and $m\\geq \\max\\{i:i\\in I\\}$. For any fixed subset $A\\subset\n    [0..m]\\setminus I$ there exists at most one $k\\in\\mathbb{N}$ with\n    $\\left|\\sum_{i\\in A}x_i+ka\\right|\\leq \\frac{1}{m}$. Hence the number of\n    subsets $A'\\subset I$ with $\\left|\\sum_{i\\in A\\cup A'}x_i+ka\\right|\\leq\n    \\frac{1}{m}$ are at most $\\dbinom{N}{\\lfloor N/2\\rfloor}$.\\\\\n\n    It means the number of sets $A\\subset [0..m]$ satisfying $(1)$ are at most\n    $2^{m-N}\\dbinom{N}{\\lfloor N/2\\rfloor}$, thus\n    \\[\\displaystyle \\frac{|X_m|}{2^m}\\geq 1-\\frac{\\lfloor N/2\\rfloor}{2^N}\\]\n    which proves the desired result.\n\\end{solution}\n\n\\begin{solution}[Sperner's theorem, IMD2]\n    We call a subset ``bad'' if it doesn't satisfy the inequality.\\\\\n\n    Now fix an integer $N$. Let $m$ be an integer such that \n    \\[\\frac{2}{m}< \\min \\left\\{\\left|x_1\\right|, \\left|x_2\\right|\\dots\n    \\left|x_N\\right|\\right\\}\\] \n    WLOG assume that there are as many positives in the first $N$ terms as\n    there are negatives. Let $P$ be the positive elements subset of\n    $\\left\\{x_1, x_2\\dots x_N\\right\\}$.\\\\\n\n    Define $S = \\left\\{x_1, x_2, \\dots x_m\\right\\} - P$. Then every subset of\n    the first $m$ terms can be written as ${A, B}$, where $A\\subseteq P,\n    B\\subseteq S$ and the subset is $A\\cup B$. \\\\\n\n    Using this notation, notice that if $A\\subset A' \\subseteq P$, then both\n    ${A, B}$ and ${A', B}$ can't be bad, because of our choice of $m$. So for\n    a fixed $B\\subseteq S$, the largest family of subsets of $P$ is a\n    \\emph{Sperner Family} of $P$. Which by Sperner's theorem has size at most\n    \\[t_p = {\\left|P\\right| \\choose \\left\\lfloor\\left|P\\right|/2\\right\\rfloor}\\] \n    So the probability of a subset of $\\left\\{x_1, x_2,\\dots x_m\\right\\}$\n    being bad is $\\frac{t_p}{2^p}$, which tends to $0$ for larger choice of\n    $N$.\n\\end{solution}\n", "meta": {"hexsha": "9ffcecf279a2f6f4f2fd472b5e95589fbef4ebb5", "size": 20578, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combi/sec3_sets.tex", "max_stars_repo_name": "M-Ahsan-Al-Mahir/BCS_Question_Bank", "max_stars_repo_head_hexsha": "83ff9b542999386ea182863e4f25f0b488d3984f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 48, "max_stars_repo_stars_event_min_datetime": "2020-10-14T17:15:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T19:47:04.000Z", "max_issues_repo_path": "combi/sec3_sets.tex", "max_issues_repo_name": "AnglyPascal/BCS_Question_Bank", "max_issues_repo_head_hexsha": "83ff9b542999386ea182863e4f25f0b488d3984f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "combi/sec3_sets.tex", "max_forks_repo_name": "AnglyPascal/BCS_Question_Bank", "max_forks_repo_head_hexsha": "83ff9b542999386ea182863e4f25f0b488d3984f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-10-15T08:59:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-27T15:19:26.000Z", "avg_line_length": 43.8763326226, "max_line_length": 446, "alphanum_fraction": 0.6594907182, "num_tokens": 7124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.9184802507195636, "lm_q1q2_score": 0.7212904314960817}}
{"text": "\\documentclass[]{report}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\graphicspath{ {images/} }\n\n\n\\title{CSCI 567 HW\\#2}\n\\author{Mohmmad Suhail Ansari\\\\USC ID: 8518586692}\n\n\\begin{document}\n\\maketitle\n\n\\newpage\n\n\t\\paragraph{Sol. 1.1}\n\n\t\tThe negative of log likelihood can be written as:\n\n\t\t\\[ \\mathcal{L}(\\textbf{w}) = - log\\bigg( \\prod_{i=1}^N P(Y= y_i|\\textbf{X}=x_i) \\bigg) \\]\n\t\t\\[ \\mathcal{L}(\\textbf{w}) =\n\t\t\t\\left\\{\n\t\t\t\t\\begin{array}{ll}\n\t\t\t\t\t{y_n = 1}  & - \\sum_{i = 0}^{N} log(\\sigma(b + \\textbf{w}^T \\textbf{x}_n))\\\\\n\t\t\t\t\t{y_n = 0}  & - \\sum_{i = 0}^{N} log(1 - \\sigma(b + \\textbf{w}^T \\textbf{x}_n))\n\t\t\t\t\\end{array}\n\t\t\t\\right.\n\t\t\\]\n\t\tcombining the two parts, we get\n\n\t\t\\begin{equation}\n\t\t\t\\mathcal{L}(\\textbf{w}) = - \\sum_{i = 0}^{N} y_n [log(\\sigma(b + \\textbf{w}^T \\textbf{x}_n))] + (1- y_{n})[log(1 - \\sigma(b + \\textbf{w}^T \\textbf{x}_n))]\n\t\t\\end{equation}\n\t\t\n\n\t\\paragraph{Sol. 1.2}\n\t\tFirst we will transform the eq(1) above by appending $1$ to $\\textbf{x}$ and $b$ to $\\textbf{w}$ i.e.\n\t\t\\[ \\textbf{x} = [1 \\quad x_i \\quad x_2 \\quad x_3 \\quad ... \\quad x_D ]\\]\n\t\t\\[ \\textbf{w} = [b \\quad w_1 \\quad w_2 \\quad w_3 \\quad ... \\quad w_D ]\\]\n\t\t\n\t\t$\\therefore$ the eq(1) can be written as \n\t\t\n\t\t\\begin{equation}\n\t\t\t\\mathcal{L}(\\textbf{w}) = - \\sum_{i = 0}^{N} y_n [log(\\sigma(\\textbf{w}^T \\textbf{x}_n))] + (1- y_{n})[log(1 - \\sigma(\\textbf{w}^T \\textbf{x}_n))]\n\t\t\\end{equation}\n\n\t\tNow, we know that the derivative of $\\sigma(a)$ is given as \n\t\t\\[ \\frac{d\\,\\sigma(a)}{d\\,a} = \\frac{1}{1 + e^{-a}} \\bigg( 1 - \\frac{1}{1 + e^{-a}} \\bigg) \\]\n\t\t\\[ = \\sigma(a)[1 - \\sigma(a)]\\]\n\t\tsimilarly we can write the derivative of $log(\\sigma(a))$ w.r.t $a$\n\t\t\\[ \\frac{d \\, log(\\sigma(a))}{d \\, \\sigma(a)} = 1 - \\sigma(a)\\]\n\n\t\tNow, using the above definitions and we can write the derivative of the loss function i eq(2) as\n\t\t\\[ \\frac{\\partial{\\mathcal{L}(\\textbf{w})}}{\\partial{\\textbf{w}}} = - \\sum_{i = 0}^{N} y_n ({ 1 - \\sigma(\\textbf{w}^T \\textbf{x}_n)})\\textbf{x}_n + (1-y_n){\\sigma(\\textbf{w}^T \\textbf{x}_n)}\\textbf{x}_n \\]\n\t\t\n\t\t\\begin{equation}\n\t\t\t\\frac{\\partial{\\mathcal{L}(\\textbf{w})}}{\\partial{\\textbf{w}}}= \\sum_{i = 0}^{N} \\{ \\sigma(\\textbf{w}^T \\textbf{x}_n) -y_n \\}\\textbf{x}_n\n\t\t\\end{equation}\n\t\t\n\t\tfrom eq(3) we get the error as \n\t\t\\[ e_n = {\\sigma(\\textbf{w}^T \\textbf{x}_n ) - y_n} \\]\n\t\tand the stationary point as \n\t\t\\[ \\sum_{i = 0}^{N} \\sigma(\\textbf{w}^T \\textbf{x}_n ) \\textbf{x}_n =  \\sum_{i = 0}^{N} \\textbf{x}_n y_n \\]\n\n\t\tNow, let $\\eta$ be the step size, then we can write the update rule for $\\textbf{w}$ as\n\t\t\\begin{equation}\n\t\t\t\\textbf{w}^{(t + 1)}  = \\textbf{w}^{(t)} - \\eta \\sum_{i = 0}^{N} \\{ \\sigma(\\textbf{w}^T \\textbf{x}_n) - y_n\\}x_n\n\t\t\\end{equation}\n\n\t\tYes, it would converge to a global minimum. Since, the curve is linear and the local minimum would be the global minimum itself, which we can reach through gradient descent while following along the curve.\n\n\t\\paragraph{Sol. 1.3}\n\t\tFor multi-class classification we are given the posterior probability as\n\t\t\\begin{equation}\n\t\t\t P(Y = k | \\textbf{X} = \\textbf{x}) = \\frac{exp(\\textbf{w}_k^T \\textbf{x})}{ 1 + \\sum_{t=1}^{K-1} exp(\\textbf{w}_t^T \\textbf{x})} \\quad for \\quad k = 1,\\, ...\\, {K-1}\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\tP(Y = k | \\textbf{X} = \\textbf{x}) = \\frac{1}{ 1 + \\sum_{t=1}^{K-1} exp(\\textbf{w}_t^T \\textbf{x})} \\quad for \\quad k = K\n\t\t\\end{equation}\n\t\t\n\t\tsince, $\\textbf{w}_K = 0$, we can simply write \n\t\t\\begin{equation}\n\t\t\tP(Y = k | \\textbf{X} = \\textbf{x}) = \\frac{exp(\\textbf{w}_k^T \\textbf{x})}{1 + \\sum_1^{K-1} exp(\\textbf{w}_t^T \\textbf{x})} \n\t\t\\end{equation}\n\n\n\t\tNow, using eq(7) we can write the negative log-likelihood as \n\t\t\\[ \\mathcal{L}(\\textbf{w}_1\\,...\\,\\textbf{w}_K) = - \\sum_n log(P(y_n | \\textbf{x}_n = \\textbf{x})) = - \\sum_n log( \\prod_k [P(y = k | \\textbf{x}_n)]) \\]\n\t\t\\[ \\mathcal{L}(\\textbf{w}_1\\,...\\,\\textbf{w}_K) = - \\sum_n \\sum_k log\\, P(y = k | \\textbf{x}_n)) \\]\n\n\t\tusing, eq(7), we can write the negative log-likelihood function as\n\t\t\\begin{equation}\n\t\t\t \\mathcal{L}(\\textbf{w}_1\\,...\\,\\textbf{w}_K) = - \\sum_n \\sum_k \\big[ \\textbf{w}_k^T \\textbf{x}_n - log(1 + \\sum_{k=1}^{K-1} exp(\\textbf{w}_t^T \\textbf{x}_n )) \\big]\n\t\t\\end{equation}\n\t\t\n\t\\paragraph{So. 1.4}\n\t\tTo find the maximum log-likelihood, we use eq(8) and take partial derivative w.r.t $\\textbf{w}_i$, we get\n\t\t\\[ \\frac{\\partial{\\mathcal{L}(\\textbf{w}_1\\,...\\,\\textbf{w}_K)}}{\\partial{\\textbf{w}_i}} = - \\sum_n \\big[ \\textbf{x}_i - \\frac{exp(\\textbf{w}_i^T \\textbf{x}_i)\\textbf{x}_i}{ 1 + \\sum_{k=1}^{K-1} exp(\\textbf{w}_t^T \\textbf{x}_n )} \\big] \\]\t\n\t\t\\[ = - \\sum_n \\big[ 1 - \\frac{exp(\\textbf{w}_i^T \\textbf{x}_i)}{ 1 + \\sum_{k=1}^{K-1} exp(\\textbf{w}_t^T \\textbf{x}_n)} \\big] \\textbf{x}_i \\]\n\t\t\\[ = - \\sum_n \\big[ 1 - P(y = i| \\textbf{x}_i) \\big] \\textbf{x}_i \\]\n\n\t\t$\\therefore$ we can define the error as\n\t\t\\[ e_i = 1 - P(y = i | \\textbf{x}_i )\\]\n\n\t\tlet $\\eta$ be the step function, then we can write the update rule as \n\t\t\\[ \\textbf{w}_{(i + 1)} = \\textbf{w}_{(i)} - \\eta \\sum_n \\big[ 1 - P(y = i| \\textbf{x}_i) \\big] \\textbf{x}_i \\]\n\n\n\t%% Linear/Gaussian Discriminant\n\n\t\\paragraph{Sol. 2.1}\n\t\tFrom the definition of $p(x_n, y_n)$ we can write the log-likelihood as \n\t\t\\[ \\mathcal{L}(D) =  \\sum_{n=1, y_n = 1}^N log(p_1 \\frac{1}{\\sqrt{2\\pi}\\sigma_1} exp(- \\frac{(x_n - \\mu_1)^2}{2\\sigma_1^2}))\\] \\[ + \\sum_{n=1, y_n = 2}^N log(p_2 \\frac{1}{\\sqrt{2\\pi}\\sigma_2} exp(- \\frac{(x_n - \\mu_2)^2}{2\\sigma_2^2}))\\]\n\n\t\t\\[ \\mathcal{L}(D) = \\sum_{n=1, y_n = 1}^N log(p_1) - log(\\sqrt{2\\pi}\\sigma_1) - \\frac{(x_n - \\mu_1)^2}{2\\sigma_1^2} \\]\n\t\t\\[ + \\sum_{n=1, y_n = 2}^N log(p_2) - log(\\sqrt{2\\pi}\\sigma_2) - \\frac{(x_n - \\mu_2)^2}{2\\sigma_2^2} \\]\n\n\t\tNow, we know that $p_1 + p_2 = 1$. Let, $N_1$ = no. of samples where $y_n = 1$ and $N_2$ = no. of samples where $y_n = 2$\n\t\twe'll first find the estimate of $p_1$ that minimizes $-\\mathcal{L}(D)$\n\n\t\t\\[ \\mathcal{L}(D) = \\sum_{n=1, y_n = 1}^N log(p_1) - log(\\sqrt{2\\pi}\\sigma_1) - \\frac{(x_n - \\mu_1)^2}{2\\sigma_1^2} \\]\n\t\t\\[ + \\sum_{n=1, y_n = 2}^N log(1 - p_1) - log(\\sqrt{2\\pi}\\sigma_2) - \\frac{(x_n - \\mu_2)^2}{2\\sigma_2^2} \\]\n\n\t\ttaking partial derivative w.r.t. $p_1$, we get\n\n\t\t\\[ \\frac{\\partial{\\mathcal{L}(D)}}{\\partial{p_1}} = \\sum_{n=1, y_n = 1}^N \\frac{1}{p_1} - \\sum_{n=1, y_n = 2}^N \\frac{1}{1 - p_1} \\]\n\t\tfrom definition of $N_1$ and $N_2$, we get\n\t\t\\[ \\frac{\\partial{\\mathcal{L}(D)}}{\\partial{p_1}} = 0 = \\frac{N_1}{p_1} + \\frac{N_2}{1 -p_1} \\]\n\t\t\\[ \\hat{p_1} = \\frac{N_1}{N_1 + N_2}\\]\n\t\tsimilarly, $\\hat{p_2}$ will be\n\t\t\\[ \\hat{p_2} = \\frac{N_2}{N_1 + N_2}\\]\n\n\t\tTo, estimate $\\mu_1$, we take the partial derivative of $\\mathcal{L}(D)$ w.r.t $\\mu_1$, we get\n\t\t\\[ \\frac{\\partial{\\mathcal{L}(D)}}{\\partial{\\mu_1}} = \\sum_{n=1, y_n = 1}^N (x_n - \\mu_1) = 0\\]\n\t\t\\[ \\hat{\\mu_1} = \\frac{1}{N_1} \\sum_{n=1, y_n = 1}^N x_n\\]\n\t\tsimilarly, estimate of $\\mu_2$ will be \n\t\t\\[ \\hat{\\mu_2} = \\frac{1}{N_2} \\sum_{n=1, y_n = 2}^N x_n\\]\n\n\t\tTo, estimate $\\sigma_1$, we take the partial derivative of $\\mathcal{L}(D)$ w.r.t $\\sigma_1$, we get\n\t\t\\[ \\frac{\\partial{\\mathcal{L}(D)}}{\\partial{\\sigma_1}} = \\sum_{n=1, y_n = 1}^N - \\frac{1}{\\sigma_1} + \\frac{(x_n - \\mu_1)^2}{\\sigma_i^3} = 0\\]\n\t\twhich gives us\n\t\t\\[ \\hat{\\sigma_1^2} = \\frac{\\sum_{n=1, y_n = 1}^N (x_n - \\mu_1)^2}{N_1} \\]\n\t\tsimilarly, estimate of $\\sigma_2^2$ will be \n\t\t\\[ \\hat{\\sigma_2^2} = \\frac{\\sum_{n=1, y_n = 2}^N (x_n - \\mu_2)^2}{N_2} \\]\n\n\t\\paragraph{Sol. 2.2}\n\t\tFrom Baye's formula we can write that \n\t\t\\[ P(y = k | x) = \\frac{P(x | y = k)\\, P(y = k)}{\\sum_k P(x | y = k)\\, P(y = k)} \\]\n\t\tNow, since $P(y = 1) + P(y = 2) = 1$, then let $P(y = 1) = \\pi$, $\\therefore P(y = 2) = 1 - \\pi$.\n\t\tWe'll first find the probability $P(y = 1| x)$\n\n\t\t\\[ P(y = 1| x) = \\frac{P(x|y = 1)\\, P(y = 1)}{ [P(x | y = 1)\\, P(y = 1)] + [P(x | y = 2)\\, P(y = 2)]} \\]\n\t\t\\[ = \\frac{\\pi \\mathcal{N}(\\mu_1, \\Sigma)}{\\pi \\mathcal{N}(\\mu_1, \\Sigma) + (1 - \\pi)\\pi \\mathcal{N}(\\mu_2, \\Sigma)} \\]\n\t\t\\[ = \\frac{1}{1 + \\frac{(1 - \\pi) \\mathcal{N}(\\mu_2, \\Sigma)}{\\pi \\mathcal{N}(\\mu_1, \\Sigma)}}\\]\n\n\t\tNow, \n\t\t\\[ \\frac{(1 - \\pi) \\mathcal{N}(\\mu_2, \\Sigma)}{\\pi \\mathcal{N}(\\mu_1, \\Sigma)} = exp(log(\\frac{(1 - \\pi) \\mathcal{N}(\\mu_2, \\Sigma)}{\\pi \\mathcal{N}(\\mu_1, \\Sigma)}))\\]\n\n\n\n\t\tSolving for $log(\\frac{(1 - \\pi) \\mathcal{N}(\\mu_2, \\Sigma)}{\\pi \\mathcal{N}(\\mu_1, \\Sigma)})$\n\t\t\\[ log(\\frac{(1 - \\pi) \\mathcal{N}(\\mu_2, \\Sigma)}{\\pi \\mathcal{N}(\\mu_1, \\Sigma)}) = \\]\n\t\t\\[ = - log(\\frac{\\pi}{1 - \\pi}) + log(\\frac{\\mathcal{N}(\\mu_2, \\Sigma)}{\\mathcal{N}(\\mu_1, \\Sigma)})\\]\n\n\t\t\\[ = -log(\\frac{\\pi}{1 - \\pi}) -\\frac{1}{2}(x- \\mu_2)^T \\Sigma^{-1}(x-\\mu_2) + \\frac{1}{2}(x- \\mu_1)^T \\Sigma^{-1}(x-\\mu_1) \\]\n\t\t\\[ = -log(\\frac{\\pi}{1 - \\pi}) - \\frac{1}{2}{x^T}{\\Sigma^{-1}}{x} + {\\mu_2^T}{\\Sigma^{-1}}{x} - \\frac{1}{2}{\\mu_2^T}{\\Sigma^{-1}}{\\mu_2} + \\frac{1}{2}{x^T}{\\Sigma^{-1}}{x} - {\\mu_1^T}{\\Sigma^{-1}}{x} + \\frac{1}{2}{\\mu_1^T}{\\Sigma^{-1}}{\\mu_1} \\]\n\t\t\\[ = (\\mu_2 - \\mu_1)^T \\Sigma^{-1} x - \\frac{1}{2}{\\mu_2^T}{\\Sigma^{-1}}{\\mu_2} + \\frac{1}{2}{\\mu_1^T}{\\Sigma^{-1}}{\\mu_1} - log(\\frac{\\pi}{1 - \\pi})\\]\n\t\t\n\t\t\\[ = - \\boldsymbol{\\theta}^{T} \\textbf{x} + b \\]\n\t\twhere,\n\t\t\\[ \\theta = \\Sigma^{-1}(\\mu_1 - \\mu_2)\\]\n\t\tand \n\t\t\\[ b = -\\frac{1}{2} \\mu_2^T \\Sigma^{-1} \\mu_2  +\\frac{1}{2} \\mu_1^T \\Sigma^{-1} \\mu_1 - log \\frac{\\pi}{1 - \\pi}\\]\n\n\t\\paragraph{Sol. 3.1}\n\t\tData Analysis\\\\ \n\t\t\n\t\t\\begin{center}\n\t\t\t\\includegraphics[scale=0.2]{hist_0}\\\\\n\t\t\t\\includegraphics[scale=0.2]{hist_1}\\\\\n\t\t\t\\includegraphics[scale=0.2]{hist_2}\\\\\n\t\t\t\\includegraphics[scale=0.2]{hist_3}\\\\\n\t\t\t\\includegraphics[scale=0.2]{hist_4}\\\\\n\t\t\t\\includegraphics[scale=0.2]{hist_5}\\\\\n\t\t\t\\includegraphics[scale=0.2]{hist_6}\\\\\n\t\t\t\\includegraphics[scale=0.2]{hist_7}\\\\\n\t\t\t\\includegraphics[scale=0.2]{hist_8}\\\\\n\t\t\t\\includegraphics[scale=0.2]{hist_9}\\\\\n\t\t\t\\includegraphics[scale=0.2]{hist_10}\\\\\n\t\t\t\\includegraphics[scale=0.2]{hist_11}\\\\\n\t\t\t\\includegraphics[scale=0.2]{hist_12}\\\\\n\t\t\\end{center}\n\n\t\\paragraph{Sol. 3.2}\n\t\tThe after applying Linear Regression to the training set, we get the results\n\n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{c|c}\n\t\t\t\tTest Data & MSE \\\\\n\t\t\t\t\\hline\n\t\t\t\ttest\\_data & 28.4644 \\\\\n\t\t\t\ttraining\\_data &20.9512 \\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\n\t\t%\\newline\n\t\n\t\tAfter applying Ridge regression for different $\\lambda$ we get the following results\n\t\t\\begin{center}\n\t\t\\begin{tabular}{c|c|c}\n\t\t\t\\hline\n\t\t\t   \t $\\lambda$ & Test Data    &     MSE \\\\\n\t\t\t\\hline\n\t\t\t     0.01 & test\\_data  & 28.4183 \\\\\n\t\t\t     0.01 & train\\_data & 20.9501 \\\\\n\t\t\t     0.1  & test\\_data  & 28.4217 \\\\\n\t\t\t     0.1  & train\\_data & 20.9502 \\\\\n\t\t\t     1    & test\\_data  & 28.4574 \\\\\n\t\t\t     1    & train\\_data & 20.9539 \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\t\\end{center}\n\n\t\t\n\n\t\t\\begin{center}\n\t\t\\begin{tabular}{c|c}\n\t\t\\hline\n\t\t   $\\lambda$ &     CVE \\\\\n\t\t\\hline\n\t\t    0.001 & 9.99383 \\\\\n\t\t    0.01  & 9.99273 \\\\\n\t\t    0.02  & 9.9915  \\\\\n\t\t    0.1   & 9.98177 \\\\\n\t\t    0.1   & 9.98177 \\\\\n\t\t    1     & 9.8773  \\\\\n\t\t    2     & 9.77169 \\\\\n\t\t    3     & 9.67664 \\\\\n\t\t    4     & 9.59175 \\\\\n\t\t    5     & 9.51671 \\\\\n\t\t    6     & 9.45125 \\\\\n\t\t    7     & 9.39513 \\\\\n\t\t    8     & 9.34814 \\\\\n\t\t    9     & 9.31007 \\\\\n\t\t   10     & 9.28075 \\\\\n\t\t\\hline\n\t\t\\end{tabular}\n\t\t\\end{center}\n\n\t\tAs we see that the cross-validation error is minimum for $\\lambda = 10$, therefore we choose $\\lambda = 10$ for out MSE calculation.\n\t\tFor \\textbf{Test Data set we get MSE = 28.98456207} and for \\textbf{Training Data set we get MSE = 21.28681485}.\n\t\t\n\t\t\\paragraph{Sol. 3.3.a}\n\t\tFirst, we will calculate the Pearson's Coefficient for each attribute with target values and we get \n\t\t\\begin{center}\n\t\t\\begin{tabular}{c | c}\n\t\t\t\\hline\n\t\t\t Feature   &   abs(r) \\\\\n\t\t\t\\hline\n\t\t\t CRIM      & 0.387697 \\\\\n\t\t\t ZN        & 0.362987 \\\\\n\t\t\t INDUS     & 0.483067 \\\\\n\t\t\t CHAS      & 0.2036   \\\\\n\t\t\t NOX       & 0.42483  \\\\\n\t\t\t RM        & 0.690923 \\\\\n\t\t\t AGE       & 0.390179 \\\\\n\t\t\t DIS       & 0.252421 \\\\\n\t\t\t RAD       & 0.385492 \\\\\n\t\t\t TAX       & 0.468849 \\\\\n\t\t\t PTRATIO   & 0.505271 \\\\\n\t\t\t B         & 0.343434 \\\\\n\t\t\t LSTAT     & 0.73997  \\\\\n\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\n\t\tWe see that the attributes with highest Pearson's Coefficients are INDUS, PTRATIO, RM, LSTAT.\\\\\n\n\t\tNow, applying \\textbf{Linear Regression}\n\t    \\begin{center}\n\t    \\begin{tabular}{c | c}\n\t        \\hline\n\t        Test Data & MSE \\\\\n\t        \\hline\n\t        test\\_data & 31.4962 \\\\\n\t        train\\_data & 26.4066\n\t    \\end{tabular}\n\t    \\end{center}\n\n\t    Now, applying Ridge Regression for different $\\lambda$ we get\n\n\t    \\begin{center}\n\t    \\begin{tabular}{c|c|c}\n\t\t\t\\hline\n\t\t\t   $\\lambda$ & Test Data    &     MSE \\\\\n\t\t\t\\hline\n\t\t\t     0.01 & test\\_data  & 31.496  \\\\\n\t\t\t     0.01 & train\\_data & 26.4066 \\\\\n\t\t\t     0.1  & test\\_data  & 31.4944 \\\\\n\t\t\t     0.1  & train\\_data & 26.4066 \\\\\n\t\t\t     1    & test\\_data  & 31.4806 \\\\\n\t\t\t     1    & train\\_data & 26.4094 \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t    \\end{center}\n\n\t    For K-Fold Ridge Regression we get the following values of CVE\n\n\t    \\begin{center}\n\t    \\begin{tabular}{c | c}\n\t\t\t\\hline\n\t\t\t   $\\lambda$ &    CVE \\\\\n\t\t\t\\hline\n\t\t\t    0.001 & 8.3003 \\\\\n\t\t\t    0.01  & 8.2992 \\\\\n\t\t\t    0.1   & 8.2885 \\\\\n\t\t\t    1     & 8.1855 \\\\\n\t\t\t    2     & 8.0791 \\\\\n\t\t\t    3     & 7.9811 \\\\\n\t\t\t    4     & 7.8915 \\\\\n\t\t\t    5     & 7.8099 \\\\\n\t\t\t    6     & 7.7363 \\\\\n\t\t\t    7     & 7.67   \\\\\n\t\t\t    8     & 7.6125 \\\\\n\t\t\t    9     & 7.562  \\\\\n\t\t\t   10     & 7.5189 \\\\\n\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t    \\end{center}\n\n\t  \tChoosing $\\lambda = 10$, we get the MSE as \n\t  \t\n\t\t\\begin{center}\n\t    \\begin{tabular}{c|c|c}\n\t\t\t\\hline\n\t\t\t   $\\lambda$ & Test Data    &     MSE \\\\\n\t\t\t\\hline\n\t\t\t     10 & test\\_data  & 31.5937  \\\\\n\t\t\t     10 & train\\_data & 26.6775 \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t    \\end{center}\n\n\t\\paragraph{Sol. 3.3.b}\n\t    From the previous exercise we know that the feature with the highest correlation coefficient with the target is LSTAT.\n\n\t    Now, calculating residue and correlation coefficient of the rest of the attributes with the residue we get\n\n\t    \\begin{center}\n\t    \\begin{tabular}{c|c}\n\t\t\t\\hline\n\t\t\t Feature & abs(r(residue, attr\\_vals)  \\\\\n\t\t\t\\hline\n\t\t\t CRIM    & 0.426588158091 \\\\\n\t\t\t ZN      & 0.398133315751 \\\\\n\t\t\t INDUS   & 0.537842703653 \\\\\n\t\t\t CHAS    & 0.175073939283 \\\\\n\t\t\t NOX     & 0.491958859016 \\\\\n\t\t\t RM      & 0.702473672384 \\\\\n\t\t\t AGE     & 0.469369575525 \\\\\n\t\t\t DIS     & 0.331853691887 \\\\\n\t\t\t RAD     & 0.436013562838 \\\\\n\t\t\t TAX     & 0.514184631153 \\\\\n\t\t\t PTRATIO & 0.496710217811 \\\\\n\t\t\t B       & 0.374589793897 \\\\\n\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t    \\end{center}\n\n\t    We get RM as the next feature with highest correlation coefficient. \\\\\n\n\t    After updating the residue, we get the correlation coeff. as\n\n\t    \\begin{center}\n\t    \\begin{tabular}{c|c}\n\t\t\t\\hline\n\t\t\t Feature & abs(r(residue, attr\\_vals)  \\\\\n\t\t\t\\hline\n\t\t\t CRIM    & 0.129554112358  \\\\\n\t\t\t ZN      & 0.0461901567406 \\\\\n\t\t\t INDUS   & 0.0561934824677 \\\\\n\t\t\t CHAS    & 0.249301273706  \\\\\n\t\t\t NOX     & 0.0109129511978 \\\\\n\t\t\t AGE     & 0.0159396362859 \\\\\n\t\t\t DIS     & 0.134713549718  \\\\\n\t\t\t RAD     & 0.087477994304  \\\\\n\t\t\t TAX     & 0.13681944445   \\\\\n\t\t\t PTRATIO & 0.297604744231  \\\\\n\t\t\t B       & 0.156620202695  \\\\\n\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t    \\end{center}\n\n\t    We get PTRATIO as the next feature with highest correlation coefficient. \\\\\n\n\t    Again,\n\t    \\begin{center}\n\t    \\begin{tabular}{c|c}\n\t\t\t\\hline\n\t\t\t Feature & abs(r(residue, attr\\_vals)  \\\\\n\t\t\t\\hline\n\t\t\t CRIM    & 0.0889293951571  \\\\\n\t\t\t ZN      & 0.0323063735902  \\\\\n\t\t\t INDUS   & 0.00214795182009 \\\\\n\t\t\t CHAS    & 0.2195949638     \\\\\n\t\t\t NOX     & 0.0198942311859  \\\\\n\t\t\t AGE     & 0.0435891823287  \\\\\n\t\t\t DIS     & 0.170389023828   \\\\\n\t\t\t RAD     & 0.0210281033187  \\\\\n\t\t\t TAX     & 0.0440426778355  \\\\\n\t\t\t B       & 0.144133379832   \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t    \\end{center}\n\n\t  \tFinally, we select the feature CHAS.\\\\\n\n\t  \tSo, finally our selected features (in-order) are LSTAT, RM, PTRATIO, CHAS. \\\\\n\n\t  \tNow, calculating MSE from previously fitted data, we get\n\n\t  \t\\begin{center}\n\t  \t\\begin{tabular}{c|c}\n\t\t\t\\hline\n\t\t\t Input Data   &     MSE \\\\\n\t\t\t\\hline\n\t\t\t test\\_data    & 34.5988 \\\\\n\t\t\t train\\_data   & 25.106  \\\\\n\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t  \t\\end{center}\n\n\t  \t\\textbf{Brute Force}: The best combination is B, RM, LSTAT, PTRATIO with $MSE = 30.09226$ with test data set.\n\n\t  \\paragraph{Sol. 3.4}\n\t  \tThe result after calculating the MSE using Linear Regression with the augmented data is\n\n\t  \t\\begin{center}\n\t  \t\\begin{tabular}{c|c}\n\t\t\t\\hline\n\t\t\t Input Data   &     MSE \\\\\n\t\t\t\\hline\n\t\t\t test\\_data    & 14.5553 \\\\\n\t\t\t train\\_data   & 5.05978 \\\\\n\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t  \t\\end{center}\n\n\\end{document}", "meta": {"hexsha": "032b692cc72364a249a5df2030a2c8587cdfceae", "size": 16523, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW2-6/HW2/HW2.tex", "max_stars_repo_name": "suhail-ansari/Machine-Learning-Algortihms", "max_stars_repo_head_hexsha": "e116c28848a2cb2132a09fcfdc0301ae89ebcf8b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW2-6/HW2/HW2.tex", "max_issues_repo_name": "suhail-ansari/Machine-Learning-Algortihms", "max_issues_repo_head_hexsha": "e116c28848a2cb2132a09fcfdc0301ae89ebcf8b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW2-6/HW2/HW2.tex", "max_forks_repo_name": "suhail-ansari/Machine-Learning-Algortihms", "max_forks_repo_head_hexsha": "e116c28848a2cb2132a09fcfdc0301ae89ebcf8b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6363636364, "max_line_length": 247, "alphanum_fraction": 0.5515947467, "num_tokens": 7082, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.721179861310837}}
{"text": "%auto-ignore\n\\providecommand{\\MainFolder}{..}\n\\documentclass[\\MainFolder/Text.tex]{subfiles}\n\\newcommand{\\TestF}{\\mathcal{D}}\n\\begin{document}\n\\section{Schwartz form and smooth extension to blow-up}\\label{Sec:SchwFrom}\n\\allowdisplaybreaks\n\nFor a smooth vector bundle $\\pi: E\\rightarrow M$, let $\\TestF(E)$ be the space of ``test sections of $E$'', and let $\\TestF'(E^*)$ be the space of distributions.  Let $\\langle\\cdot,\\cdot\\rangle: \\TestF'(E^*)\\otimes\\TestF(E)\\rightarrow \\R$ be the natural pairing. Proper definitions can be formulated easily based on \\cite[Section~6]{HormanderI}.\n\\begin{Proposition}[Schwartz kernel theorem, see {\\cite[Theorem~5.2.1]{HormanderI}} for the local version]\\label{Prop:SchwKer}\nLet $E_1$ and $E_2$ be smooth vector bundles over smooth manifolds $M_1$ and $M_2$, respectively. Then there is a one-to-one correspondence between continuous operators $\\TOp: \\TestF(E_1)\\rightarrow\\TestF'(E_2)$ and elements $\\KKer_\\TOp\\in\\TestF'(E_1\\boxtimes E_2^*)$ which is given by the equation\n$$ \\langle \\TOp s_1, \\psi_2 \\rangle = \\langle \\KKer_\\TOp, s_1 \\boxtimes \\psi_2 \\rangle\\quad\\text{for all }s_1\\in \\TestF(E_1)\\text{ and }\\psi_2\\in \\TestF(E_2^*). $$\nThe distributional section $\\KKer_{\\TOp}$ is called the \\emph{Schwartz kernel} of $\\TOp$. \n\\end{Proposition}\n\nAn $L^1_{\\text{loc}}$-integrable function $k: M\\times M \\rightarrow \\Hom(E_1,E_2)=E_1^*\\boxtimes E_2$ on an oriented Riemannian manifold $M$ defines the distribution $\\KKer\\in \\TestF'(E_1\\boxtimes E_2^*)$ by\n$$ \\langle\\KKer,s_1\\boxtimes \\psi_2\\rangle = \\int_{x_1, x_2} \\langle k(x_1,x_2)s_1(x_1),\\psi_2(x_2)\\rangle \\Vol(x_1)\\Vol(x_2) $$\n%$$ \\langle T s_1, \\psi_2 \\rangle = \\int_{x_1} \\langle t(s_1)(x_1),\\psi_2(x_1)\\rangle\\Vol(x_1) $$\nIn the case of exterior bundles, we introduce an equivalent notion of a Schwartz form. This name was proposed by Dr.~A.~Hermann in a discussion in Potsdam.\n\n\\begin{Proposition}[Schwartz kernel and Schwartz form]\\label{Prop:SchwForm}\nIn the setting of Proposition~\\ref{Prop:SchwKer}, suppose that $M_1 = M_2 = M$ is a smooth oriented Riemannian manifold and $E_1 = E_2 = \\Lambda T^* M$. We consider the isomorphism of vector bundles $\\Psi:\\Lambda T^*M\\boxtimes(\\Lambda T^*M)^*\\rightarrow\\Lambda T^*(M\\times M)$ which is for every $x_1$, $x_2\\in M$ given by\n\\begin{align*}\n \\Psi: \\Lambda T^*_{x_1}M\\otimes\\bigl(\\Lambda T_{x_2}^*M\\bigr)^* &\\longrightarrow \\Lambda T^*_{(x_1,x_2)}(M\\times M) \\\\\n \\omega_1\\otimes\\xi_2&\\longmapsto\\omega_1\\wedge\\sharp\\xi_2.\n\\end{align*}\nHere, $\\sharp: \\Lambda T^*M \\rightarrow \\bigl(\\Lambda T^*M \\bigr)^* $ denotes the musical isomorphism with respect to the natural pointwise inner product on $\\Lambda T^*M$. We obtain the isomorphism\n\\begin{align*}\n\\Psi_*:\\DR'(M\\times M)&\\longrightarrow\\TestF'(E_1^*\\boxtimes E_2)\\\\\n\\DR_\\TOp&\\longmapsto\\KKer_\\TOp,\n\\end{align*}\nwhere $\\DR'$ denotes the space of de Rham currents.\n\nIf $\\TOp$ is homogenous of degree~$\\Abs{\\TOp}$, then the degree of $\\DR_\\TOp$ satisfies \n$$ \\Deg(\\DR_\\TOp) = \\dim(M) + \\Abs{\\TOp}. $$\n\nIf $\\KKer_T$ is represented by an $L^1_{\\mathrm{loc}}$-integrable section of $\\Hom(E_1,E_2)\\simeq E_1^*\\boxtimes E_2$, then $\\DR_T$ is represented by an $L^1_{\\mathrm{loc}}$-integrable form, and the other way round. In this case, for all $\\omega_1 \\in \\DR(M)$, $\\omega_2\\in \\DR_c(M)$, we have\n\\begin{equation}\\label{Eq:SchwarzKerForm}\n\\begin{aligned}\n\\int_{x_2} \\bigl((\\TOp \\omega_1)(x_2)\\bigr)\\bigl[\\omega_2(x_2)\\bigr] &= \\int_{x_1, x_2} \\KKer_T(x_1,x_2)[\\omega_1(x_1)]\\wedge \\Vol(x_1)\\wedge \\omega_2(x_2)\\\\\n&= \\int_{x_1, x_2} \\DR_T(x_1,x_2)\\wedge\\omega_1(x_1)\\wedge\\omega_2(x_2).\n\\end{aligned}\n\\end{equation}\n\\end{Proposition}\n\\begin{proof}\nStraightforward computations similar to Example~\\ref{Ex:IdFE} below.\n\\end{proof}\n\n\\begin{Definition}[Schwartz form]\\label{Def:SDFDF}\nThe current $\\DR_\\TOp\\in \\DR'(M\\times M)$ from Proposition~\\ref{Prop:SchwForm} is called the \\emph{Schwartz form} of $\\TOp$.\n\\end{Definition}\n\nWe will consider pseudo-differential operators $\\TOp:\\DR(M)\\rightarrow\\DR(M)$ on a Riemannian manifold $M$; this class of operators generalizes differential operators and contains generalized inverses of elliptic operators (see \\cite{Hormander} for thorough treatment).\n\n\\begin{Proposition}[Schwartz form of pseudo-differential operators] \\label{Prop:ASD}\nLet $\\TOp: \\DR(M) \\rightarrow \\DR(M)$ be a pseudo-differential operator on a smooth oriented Riemannian manifold $M$. Then the Schwartz form $\\DR_{\\TOp}$ restricts to a smooth form on $M\\times M\\backslash\\Diag$.\n\\end{Proposition}\n\\begin{proof}\nWell known fact, proof based on \\cite{Hormander}.\n\\end{proof}\n \n\\begin{Example}[Schwartz form of $\\Id$]\\label{Ex:IdFE}The Schwartz form of the identity $\\Id: \\DR(\\R^n)\\rightarrow \\DR(\\R^n)$ reads\n\\begin{equation}\\label{Eq:SchwartzFormOfId}\n\\DR_{\\Id}(x,y) = \\delta(x-y)(\\Diff{x}^1 - \\Diff{y}^1)\\dotsb(\\Diff{x}^n-\\Diff{y}^n),\n\\end{equation}\nwhere $\\delta$ denotes the Dirac delta function on $\\R^n$ centered at $0$. In order to prove this, we start by rewriting\n\\begin{align*}\n(\\Diff{x}^1 - \\Diff{y}^1) \\dotsb (\\Diff{x}^n - \\Diff{y}^n) &=\\sum_{I}(-1)^{\\Abs{I}} \\varepsilon(I^c I \\mapsto[n])\\Diff{x}^{I^c} \\wedge \\Diff{y}^I \\\\\n&=\\sum_{I} (-1)^{n \\Abs{I}} (\\Star \\Diff{x}^I) \\wedge \\Diff{y}^I.\n\\end{align*}\nHere, the sum is over all multiindices $I\\subset \\{1,\\dotsc,n\\}$, and we use that $\\Star(\\Diff{x}^I) = \\varepsilon(I, I^c) \\Diff{x}^{I^c}$, where $\\varepsilon(I,I^c)$ denotes the sign to order $I I^c$ to $\\{1,\\dotsc,n\\}$. Now, for any $\\omega\\in \\DR_c(\\R^n)$, which we write as $\\omega(x) = \\sum_K \\omega_K(x)\\Diff{x}^K$, we compute using $\\Diff{x}^K\\wedge\\Star(\\Diff{x}^I)=(\\Diff{x}^K,\\Diff{x}^I)\\Vol(x) = \\delta^{KI}\\Vol(x)$ the following:\n\\begin{align*}\n&\\int_x \\delta(x-y)  (\\Diff{x}^1-\\Diff{y}^1)\\dotsb(\\Diff{x}^n-\\Diff{y}^n) \\omega(x)  \\\\\n&\\qquad=\\sum_{I,K} \\int_x \\delta(x-y)(-1)^{n\\Abs{I}}  \\omega_K(x)(\\Star \\Diff{x}^I)\\Diff{y}^I\\Diff{x}^K \\\\\n&\\qquad=\\sum_{I,K}\\int_x \\delta(x-y) (-1)^{n\\Abs{I} + n\\Abs{K}} \\delta(x-y)  \\omega_K(x) \\Diff{x}^K \\Star(\\Diff{x}^I) \\Diff{y}^I \\\\\n&\\qquad=\\sum_{I} \\int_x \\delta(x-y) \\omega_I(x)\\Vol(x) \\Diff{y}^I \\\\\n&\\qquad=\\omega(y).\n\\end{align*}\nThis shows \\eqref{Eq:SchwarzKerForm}, and \\eqref{Eq:SchwartzFormOfId} follows. Notice that\n$$ \\Restr{\\DR_\\Id}{\\R^n\\times \\R^n\\backslash \\Diag} = 0, $$\nand thus the smooth part of $\\DR_\\Id$ does not recover the data of the operator $\\Id$.\n\\end{Example}\n\n%\\begin{Definition}[Laplace Green kernel and standard Hodge propagator]\\label{Def:GKerHPr}\n%Let $M$ be a closed oriented Riemannian manifold, $\\DR(M)=\\Dd\\DR(M)\\oplus\\CoDd\\DR(M)\\oplus\\Harm(M)$ the Hodge decomposition, $\\pi: \\DR(M) \\rightarrow \\Harm(M)$ the harmonic projection and $\\Laplace= \\Dd\\circ\\CoDd + \\CoDd\\circ\\Dd$ the Hodge de Rham Laplacian. We define the \\emph{Laplace Green operator}  $\\GOp: \\DR(M)\\rightarrow \\DR(M)$ by\n%$$ .$$\n%We denote its Schwartz form by $\\GKer$ and call it the \\emph{Laplace Green kernel.}  We define the \\emph{standard Hodge homotopy} by\n%$$ \\StdHtp \\coloneqq - \\CoDd \\circ \\GOp : \\DR^\\bullet(M) \\longrightarrow \\DR^{\\bullet - 1}(M). $$\n%It satisfies $\\Dd\\circ\\StdHtp + \\StdHtp\\circ\\Dd = - \\Id$. We denote the Schwartz form of $\\StdHtp$ by $\\StdPrpg$ and call it the \\emph{standard Hodge propagator.}\n%\\end{Definition}\n\nWe consider the Green operator $\\GOp$ for the Laplacian $\\Laplace$ (see \\cite{Warner1983}) and the standard Hodge propagator $\\HtpStd$. They are both pseudo-differential operators, and it holds $\\HtpStd = - \\CoDd \\GOp$. We will study their Schwartz forms $\\GKer$ and $\\PrpgStd$, which are called the \\emph{Green kernel} and the \\emph{standard Hodge propagator,} respectively.\n\n\\begin{Proposition}[Basic facts about $\\GKer$ and $\\StdPrpg$]\\label{Prop:BasicFactsGP}\nThe Green kernel $\\GKer$ represents an $L^2$-integrable form.\nThe standard Hodge propagator $\\StdPrpg$ represent an $L^1$-integrable form.\n\\end{Proposition}\n\\begin{proof}\nThe fact that $\\GKer$ is $L^2$ is an exercise in \\cite{Warner1983}. The fact that~$\\StdPrpg$ defines an $L^1$-integrable form on $M\\times M$ for a compact manifold $M$ was proved in \\cite{Harris2004} using the heat kernel approximation (see the next section).\n\\end{proof}\n\nA consequence of Proposition~\\ref{Prop:BasicFactsGP} is that the Schwartz forms $\\GKer$ and $\\StdPrpg$ are determined by their smooth restrictions to $M\\times M\\backslash \\Diag$. This follows from \\eqref{Eq:SchwarzKerForm} because the integral does not depend on sets of zero measure. Therefore, we will write $\\GKer$, $\\StdPrpg \\in \\DR^{n-1}(M\\times M\\backslash\\Diag)$.\n\n\\begin{Definition}[Smooth extension to the blow-up]\\label{Def:Esdas}\nLet $M$ be a smooth manifold, and let $\\pi: \\Bl_\\Diag(M\\times M)\\rightarrow M\\times M$ be the spherical blow-up of $M\\times M$ at the diagonal $\\Diag$.\\footnote{Another name of this construction suggested to me by Dr.~Oliver Lindblad Petersen after explaining him our setting should be ``Melrose blow-up''.} Consider the blow-up diagram\n\\[\\begin{tikzcd}\n & \\Bl_\\Diag(M\\times M)\\arrow[two heads]{d}{\\pi} \\\\\n M\\times M\\backslash \\Diag \\arrow[hook]{r}{\\iota}\\arrow[hook]{ru}{\\tilde{\\iota}} & M\\times M,\n\\end{tikzcd}\\]\nwhere $\\iota$ is the inclusion and $\\tilde{\\iota}$ its unique smooth lift --- the embedding of the interior. We say that a smooth form $\\omega\\in\\DR(M\\times M\\backslash\\Diag)$ \\emph{extends smoothly to the blow-up} if there is a smooth form $\\tilde{\\omega}\\in \\DR(\\Bl_\\Diag(M\\times M))$ such that \n$$ \\tilde{\\iota}^*\\tilde{\\omega}=\\omega. $$\n\\end{Definition}\n\nNote that the extension, if it exists, is necessarily unique.\n\n\\begin{Question}\nDo $\\GKer$ and $\\StdPrpg$ extend smoothly to the blow-up?\nWe expect that $\\GKer$ does not and $\\StdPrpg$ does.\n\\end{Question}\n\\end{document}\n", "meta": {"hexsha": "90147caee807db4f9f94f7098d23c7760807ba9c", "size": 9661, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Subfiles/GrKer_Def.tex", "max_stars_repo_name": "p135246/phd-thesis", "max_stars_repo_head_hexsha": "0e124466a3d0ff988c012225400fadb0b170aa9e", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Subfiles/GrKer_Def.tex", "max_issues_repo_name": "p135246/phd-thesis", "max_issues_repo_head_hexsha": "0e124466a3d0ff988c012225400fadb0b170aa9e", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Subfiles/GrKer_Def.tex", "max_forks_repo_name": "p135246/phd-thesis", "max_forks_repo_head_hexsha": "0e124466a3d0ff988c012225400fadb0b170aa9e", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 79.8429752066, "max_line_length": 441, "alphanum_fraction": 0.7057240451, "num_tokens": 3480, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7211798576858307}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 10.4 Multi-Dimensional Real Fourier Transform\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nThis subroutine computes Real Fourier Transforms for real data in up to six\ndimensions using the fast Fourier transform. In ND dimensions, the relations\nbetween the values $x$ and the Fourier coefficients $\\xi $ have the form%\n\\begin{multline*}\nx(j_1,j_2,...,j_{ND})=\\sum_{k_1=0}^{N_1-1}\\cdots\\sum_{k_{ND}=0}^{N_{ND}-1}%\n\\xi (k_1,k_2,...,k_{ND})\\\\\n\\times W_1^{j_1k_1}\\cdots W_{ND}^{j_{ND}k_{ND}},\n\\end{multline*}\nwhere $N_\\ell=2^{\\text{M}(\\ell)}$, $W_\\ell=e^{2\\pi i/N_\\ell}$, 0 $\\leq $ $j_\\ell\n\\leq N_\\ell-1$, $x$ is real and $\\xi $ is complex.\n\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[\\bf REAL]  \\ {\\bf A}$(N_1$, $N_2$, ..., $\\geq N_{ND})$\\quad $%\n[N_k=2^{\\text{M}(k)}]$\n\n\\item[\\bf REAL]  \\ {\\bf S}$(\\geq \\max (\\nu _1$, $\\nu _2$, ..., $\\nu\n_{ND})-1)$\\  $[\\nu _k=2^{\\text{M}(k)}-^2]$\n\n\\item[\\bf INTEGER]  \\ {\\bf M}$(\\geq $ ND){\\bf , ND, MS}\n\n\\item[\\bf CHARACTER]  \\ {\\bf MODE}\n\\end{description}\nOn the initial call set MS to~0 to indicate the array S() does not yet\ncontain a sine table. Assign values to A(), MODE, M(), and ND.\n$$\n\\fbox{{\\bf CALL SRFT(A, MODE, M, ND, MS, S)}}\n$$\nOn return A() will contain computed results. S() will contain the sine table\nused in computing the Fourier transform. MS may have been changed.\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[A()]  [inout] If the argument MODE selects Analysis, A() contains\nvalues $x$ on entry and the Fourier coefficients $\\xi $ on exit. If MODE\nselects Synthesis, A() contains the Fourier coefficients $\\xi $ on entry and\nthe values $x$ on exit. The Functional Description below describes the way $x\n$ and $\\xi $ are stored in A().\n\n\\item[MODE]  [in] The character variable MODE selects Analysis or Synthesis.\n\n'A' or 'a' selects Analysis, transforming $x$'s to $\\xi ^{\\prime }s.\n$\n\n'S' or 's' selects Synthesis, transforming $\\xi $'s to $x^{\\prime\n}s.$\n\n\\item[M()]  [in] Defines $N_k=2^{\\text{M}(k)}$, the number of real data points in\nthe $k^{th}$ dimension. Require $0\\leq \\text{M}(k)\\leq 31$ for all $k$%\n, and M($1)=0$ only if M($k)\\equiv 0$ for all $k$. No action is taken with\nrespect to dimensions for which M($k)=0.$\n\n\\item[ND]  [in] Number of dimensions. Require 1 $\\leq $ ND $\\leq $ 6.\n\n\\item[MS]  [inout] Gives the state of the sine table in $S()$.  Let\n$\\text{MS}_{in}\\text{ and MS}_{out}$ denote the values of MS on entry\nand return respectively. If the sine table has not previously been\ncomputed, set $\\text{MS}_{in} = 0$ or $-$1 before the call. Otherwise\nthe value of $\\text{MS}_{out}$ from the previous call using the same\nS() array can be used as $\\text{MS}_{in}$ for the current call.\n\nCertain error conditions described in Section E cause the subroutine\nto set $\\text{MS}_{out} = -2$ and return.  Otherwise, with $\\max _i\n\\{\\text{M}(i)\\} > 0$, the subroutine sets $\\text{MS}_{out} = \\max\n($M(1), M(2), ..., M(ND), $\\text{MS}_{in}).$\n\nIf $\\text{MS}_{out} > \\max (2, \\text{MS}_{in}),$ the subroutine sets\nNT = $2^{\\text{MS}_{out}-2}$ and fills S() with NT $-$ 1 sine values.\n\nIf $\\text{MS}_{in}=-1$, the subroutine returns after the above\nactions, not transforming the data in A().  This is intended to allow\nthe use of the sine table for data alteration before a subsequent Fourier\ntransform, as discussed in Section G of Chapter~16.0.\n\n\\item[S()]  [inout] When the sine table has been computed, S($j)=\\sin \\pi\nj/(2\\times {\\textstyle NT})$, $j=1$, 2, ..., NT $-$ 1, see MS above.\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nChange SRFT to DRFT and the REAL type statements to DOUBLE PRECISION.\n\n\\subsection{Examples and Remarks}\n\nA ``smooth'' function that approximates%\n\\begin{equation*}\nA(i,j)=\n\\begin{cases}\n0 & \\text{if}\\ |9-i|+|9-j|>4 \\\\\n1 & \\text{if}\\ |9-i|+|9-j|\\leq 4\n\\end{cases}\n\\ 1\\leq i,\\ j\\leq 16.\n\\end{equation*}\nis desired. The example at the end of the chapter does this by computing\nthe two dimensional transform of A, applying sigma factors (see Section\nG of Chapter~16.0), and then transforming back. Results are printed only\nfor 1 $\\leq $ $i,\\ j\\leq 9$ since, to within round-off limitations, A($%\n9+m,9-n)={\\textstyle A}(9-m,9-n)$, $1\\leq 9\\pm m\\leq 16$ and $1\\leq $ $9\\pm\nn\\leq 16.$\n\n\\subsection{Functional Description}\n\nThe multi-dimensional real Fourier transform is done by changing it to a\nproblem in complex variables, doing a multi-dimensional complex Fourier\ntransform, and then adjusting the results to obtain the solution for the\noriginal problem.\n\nTaking complex conjugates in Eq.\\,(1) and using the fact that $x$ is real, it\ncan be verified that%\n\\begin{equation*}\n\\xi (N_1-k_1,\\;N_2-k_2,...,N_d-k_d)=\\overline{\\xi }(k_1,k_2,...,k_d),\n\\end{equation*}\nwhere $N_i-k_i$ is interpreted modulo $N_i$. (Thus $N_i-k_i=0$ if $k_i$ is\n0.) Using the above, it is possible to pack the nonredundant $\\xi ^{\\prime\n}s $ in the same space as is required for $x$.\n\nStorage of $\\xi $ in A() for the case $d=2$ is illustrated in Table~1. The\nrows and columns in the table correspond to rows and columns in the array\nA(). Only the subscripts $k_1$, $k_2$ of the $\\xi $'s are given.\nThe symbols $J_1$ and $J_2$ are used as abbreviations for $N_1/2$ and $N_2/2$\nrespectively. The coefficients with subscripts (0,0), $(J_1,0)$, $(0,J_2)$,\nand $(J_1,J_2)$ are real and occupy single array elements as shown. For the\nother coefficients, the subscript $``k_1,k_2\"$ identifies the location of\nthe real part of $\\xi (k_1$, $k_2)$, and an ``I'' immediately below such a\nsubscript gives the location of the imaginary part of $\\xi (k_1$,\\ $k_2).$\n\nThe first column (with the second subscript ignored) gives the storage\nscheme for the case $d=1$. For $d>2$, and with $\\nu =$ the smallest value of\n$i(>1)$ for which $k_i\\neq 0$ and $k_i\\neq N_\\nu /2$, the storage scheme\ngeneralizes as follows.\n\nIf $1 < k_1 < N_1$ (A$(2k_1+1$, $k_2+1$, ..., $k_d+1),$ A$(2k_1+2$,\n$k_2+1$, ..., $k_d+1))$ contains $\\xi (k_1,k_2,...,k_d)$.  Else\n(A(1, $k_2+1$, ..., $k_d+1),$ A(2, $k_2+1$, ..., $k_d+1))$ contains\n\\begin{alignat*}{2}\n&\\xi (0,k_2,...,k_d) &\\ &1\\leq k_\\nu <N_\\nu /2\\\\\n&\\xi (N_1/2,k_2,...,k_d)&\\ \\qquad &N_\\nu /2<k_\\nu <N_\\nu\n\\end{alignat*}\nand when $k_i$ is either 0 or $N_i/2$ for all i,\n(A(1, $k_2+1$, ..., $k_d+1),$ A(2, $k_2+1$, ..., $k_d+1))$ contains $(\\xi\n(0,k_2,...,k_d),~\\xi (N_1/2,k_2,...,k_d)).$ Note that in this last case both\n$\\xi $'s are real.\n\nMore details can be found in \\cite{Krogh:1970:RFT}.\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nRequire $0 \\leq \\text{M}(k)\\leq 31$ and $1 \\leq \\text{ND} \\leq $ 6.  MODE\nmust contain one of the allowed values.  If any of these conditions are\nviolated the subroutine will issue an error message using the error\nprocessing procedures of Chapter~19.2 with a severity level of~2 to cause\nexecution to stop.  A return is made with $\\text{MS}=-2$ instead of\nstopping if the statement ``CALL\\ ERMSET($-$1)'' is executed before\ncalling this subroutine.\n\nIf the sine table does not appear to have valid data, an error message is\nprinted, and the sine table and then the transform are computed.\n\n\\subsection{Supporting Information}\n\nThe source language is ANSI Fortran~77.\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt} \\\\\nDRFT & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\n DFFT, DRFT, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nSRFT & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\n ERFIN, ERMSG, IERM1, IERV1, SFFT, SRFT}\\\\\n\\end{tabular}\n\nSubroutine designed and written by: Fred T. Krogh, JPL, October~1969,\nrevised January~1988.\n\n\n\\end{multicols}\n\n\\begin{table} \\centering\n  \\begin{tabular}{cccccccc}\n     0,0 & 0,1 & $\\cdots$ & 0,$J_2-1$ & 0,$J_2$ & $J_1$,$J_2+1$ & $\\cdots$ & $J_1$,$N_2 -1$ \\\\\n     $J_1$, 0 & I & $\\cdots$ & I & $J_1$,$J_2$ & I & $\\cdots$ & I \\\\\n      1,0 & 1,1 & $\\cdots$ & 1,$J_2-1$ & 1,$J_2$ & 1,$J_2+1$ & $\\cdots$ & 1,$N_2 -1$ \\\\\n     I & I & $\\cdots$ & I & I & I & $\\cdots$ & I \\\\\n    $\\cdots$ & & & & $\\cdots$ & & & $\\cdots$ \\\\\n     $J_1 -1$,0 & $J_1-1$,1 & $\\cdots$ & $J_1-1$,$J_2-1$ & $J_1-1$, $J_2$ & $J_1-1$,$J_2+1$ & $\\cdots$ & $J_1-1$,$N_2 -1$ \\\\\n    I & I & $\\cdots$ & I & I & I & $\\cdots$ & I \\\\\n  \\end{tabular}\n  \\caption{Storage of $\\xi$ in A() for Two Dimensions}\n\\end{table}\n\n\\begcodenm\n\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSRFT}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{srft}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSRFT}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{srft}}\n\\end{document}\n", "meta": {"hexsha": "0c4091205509d7528985e41a913a5a4a31ecf31c", "size": 8877, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch10-04.tex", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "doc/doctex/ch10-04.tex", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "doc/doctex/ch10-04.tex", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 40.5342465753, "max_line_length": 124, "alphanum_fraction": 0.6661034133, "num_tokens": 3197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017535, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.721012503780939}}
{"text": "\\section{Modeling Coral Reef Dynamics}\n\n\\begin{frame}\n\\frametitle{Coral Reef Dynamics}\n\\includegraphics[scale=.175]{./coral-reef-triangle.png}\\\\ \\cite{Hastings}\n\\end{frame}\n\n\\begin{frame}\\frametitle{Coral Reef Dynamics}\nThe deterministic ordinary differential equation model:\n$$\\begin{cases}\\begin{array}{rl}\n\\frac{dM}{dt}\\hspace{-.8em}&=aMC - \\frac{gM}{M+T} + \\gamma M T, \\\\\n\\frac{dC}{dt}\\hspace{-.8em}&=rTC - dC - aMC, \\\\\n\\frac{dT}{dt}\\hspace{-.8em}&=\\frac{gM}{M + T} - \\gamma MT - rTC + dC. \n\\end{array}\\end{cases}$$ \n\nwhere \n\\begin{itemize}\\itemsep0pt\n\\item $r$ is the rate corals overgrow upon algal turfs\\\\\n\\item $d$ is the mortality rate of corals\\\\\n\\item $a$ is the rate that macroalgae overgrow upon corals\\\\\n\\item $\\gamma$ is the rate that macroalgae spread over algal turfs\\\\\n\\item $g$ is the indiscriminate grazing rate of scarid\n\\end{itemize} We also assume $a<d<\\gamma<r<2\\gamma$ and $0<g<\\gamma$. \\vspace{1em}\n\\cite{Hastings}\n\\end{frame}\n\n\\begin{frame}\\frametitle{Coral Reef Dynamics}\n\n\\hspace{1.57em}\n\n\\begin{itemize}\n\\item $\\frac{dT}{dt}=-\\frac{dM}{dt}-\\frac{dC}{dt}$ implies $M+C+T$ is\n  constant.\n\\item We assume that $M+C+T=1$.\n\\item This limits our scope to regions entirely covered by coral,\n  macroalgae, and algal turf. \n\\end{itemize}\n\nThus, we reduce our system to, \n$$\\begin{cases}\n\\begin{array}{rl}\n\\frac{dM}{dt}&= aMC-\\frac{gM}{1-C} + \\gamma M - \\gamma M^2 -\\gamma M C,\\\\\n\\frac{dC}{dt}&=rC - rC^2 - rCM - dC - aMC.\n\\end{array} \n\\end{cases}$$\n\\end{frame}\n\n\n\\begin{comment}\\frametitle{Equilibria and Stability}\nEquilibrium point\n\n\\end{comment}\n\n\\begin{frame}\\frametitle{Equilibria and Stability}\nTo find equilibrium points analytically we first set the derivatives equal to zero to obtain the nullclines:\n$$\\begin{cases}\n\\begin{array}{rl}\n0\\hspace{-.8em}&=M(aC + \\gamma-\\gamma M-\\gamma C - \\frac{g}{1-C}),\\\\\n0\\hspace{-.8em}&=C(r-Mr-Cr - d - aM).\n\\end{array}\n\\end{cases}$$\n\\end{frame}\n\n\n\n\\begin{frame}\\frametitle{Equilibria and Stability}\n\n  \\begin{itemize}\n  \\item $M'=0$ is satisfied when:\n    \\begin{itemize}\n    \\item $M=0$, or \n    \\item\n      $aC + \\gamma - \\gamma M - \\gamma C -\n      \\frac{g}{1-C}=0$.\n    \\end{itemize}\n  \\item $C'=0$ is satisfied when:\n    \\begin{itemize} \n    \\item$C=0$, or \n    \\item $r-Mr-Cr-d-aM=0$. \n    \\end{itemize}\n  \\end{itemize}\n\n\\end{frame}\n\n\n\\begin{frame}\\frametitle{Phase Plane} \n\n  %Our equilibrium points are located at the intersections of the nullclines:\\\\\n  \\includegraphics[scale=.325]{./nullclines.pdf}\n\n\\end{frame}\n\n\n\n\\begin{frame}\n\\frametitle{Time Delay in the Coral Ecosystem}\n\nWe can identify time delays in the coral ecosystem:\n\\begin{itemize}\n\\item the delay between overfishing of herbivores and growth of\n  macroalgae \\cite{Dinsdale},\n\\item the delay between the growth of algae and the effect of algae on\n  coral, \\cite{Mumby} \n\\item the delay between the grazing of macroalgae and growth of algal\n  turf \\cite{Hastings}.\n\\end{itemize} We focus on the third phenomena.\n\n\\end{frame}\n\n\n\\begin{frame}\\frametitle{Coral Reef Dynamics}\nScarid grazing has an impact for the macroalgae in the future:\n$$\\begin{cases}\n  \\begin{array}{rl}\n    \\frac{dM}{dt}\\hspace{-.8em}&=aMC - \\frac{gM(t-\\tau)}{1-C(t-\\tau)} + \\gamma M (1-M-C),\\\\\n    \\frac{dC}{dt}\\hspace{-.8em}&=rC(1-M-C) - dC - aMC,\\\\\n  \\end{array}\n\\end{cases}$$ where $\\tau$ is a fixed time delay.\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitle{Equilibria and Stability}\nThese are three equilibrium points of interest: \n\\begin{itemize}\n\\item $(0,0)$ (Unstable for all $\\tau\\geq0$)\\\\\n\\item $(0,1-\\frac{g}{\\gamma})$ (High Coral Cover)\\\\\n\\item $(1-\\frac{d}{r},0)$ (High Algae Cover).\n\\end{itemize} \nNotice that time delay does not affect the equilibria.\n\\end{frame}\n\n\n\\begin{frame}\\frametitle{Jacobian Matrices}\nWe linearize our delay model:\n\n\\begin{eqnarray}\n  \\label{eqn:linearizedDelayModel}\n  \\begin{bmatrix} \n    M'\\\\C'\n  \\end{bmatrix}=J_1\n  \\begin{bmatrix} \n    M \\\\\n    C\n  \\end{bmatrix} + \n  J_2\n  \\begin{bmatrix}\n    M(t-\\tau) \\\\\n    C(t-\\tau)\n  \\end{bmatrix},\n\\end{eqnarray}\n\nwhere \n\n\\begin{eqnarray*}\n  J_1 & = & \\begin{bmatrix}\n    \\gamma-2\\gamma M^* +(a-\\gamma)C^* & (a-\\gamma)M^*\\\\\n    -(a+r)C^* & r-d-(a+r)-2M^*C^* \n  \\end{bmatrix},  \\\\\n  J_2 & = & \n  \\begin{bmatrix} \n    \\frac{-g}{1-C^*} & \\frac{-gM^*}{(1-C^*)^2} \\\\ \n    0 & 0\n  \\end{bmatrix}.\n\\end{eqnarray*}\n\n\\end{frame}\n\n\\begin{comment}\n\n\\begin{frame}\\frametitle{Putting Jacobians to Use}\n{ Suppose $\\begin{bmatrix} x\\\\y\\end{bmatrix}=\\overrightarrow{v_1}e^{\\lambda t}$.}\\\\\\vspace{2em} \n{ Differentiating, setting equal to 1, and doing algebra stuff, we get $(J_1+J_2e^{-\\lambda t} -\\lambda I)\\overrightarrow{v_1}=0$.} \n\\end{frame}\n\\end{comment}\n\n\\begin{frame}\\frametitle{Putting Jacobians to Use}\nConsider the Jacobians evaluated at the origin:\n\n\\begin{eqnarray*}\n  J_1 & = & \n            \\begin{bmatrix}\n              \\gamma & 0\\\\\n              0 & r-d\n            \\end{bmatrix}, \\\\\n  J_2 & = & \n            \\begin{bmatrix}\n              -g & 0\\\\\n              0 & 0\n            \\end{bmatrix}.\n\\end{eqnarray*}\n\n\\end{frame}\n\n\n\\begin{frame}[c]\\frametitle{Putting Jacobians to Use}\n%Recall, $(J_1+J_2e^{-\\lambda t} -\\lambda I)\\overrightarrow{v_1}=0$. \\\\\\vspace{2em} Taking determinants, we find the characteristic polynomial of $(J_1+J_2e^{-\\lambda t} -\\lambda I)$ evaluated at $M=0$, $C=0$ to be \n\n  The characteristic polynomial of\n  $(J_1+J_2e^{-\\lambda \\tau})$ is,\n$$(\\lambda - r + d)(\\lambda -\\gamma + ge^{-\\lambda\\tau})=0.$$\n\n\\end{frame}\n\n  \\begin{frame}\\frametitle{Get Them Eigenvalues}\nHence, \n\\begin{itemize}{\\itemsep .5in}\n\\item $\\lambda = r-d>0$ is an eigenvalue with positive real part\n\\item Other eigenvalues satisfy $\\lambda=\\gamma-ge^{-\\lambda\\tau}$.\n\\item For $\\tau\\geq0$, our system has two eigenvalues with positive\n  real part. This implies our system is unstable at $(0,0)$ for all $\\tau\\geq0$.\n\\end{itemize}\n\\end{frame}\n\n\\begin{comment}\n\\begin{frame}\\frametitle{Get Them Eigenvalues}\nNow we consider positive $\\tau$.\n\\begin{itemize}\n\\item Let $\\lambda \\tau=(\\alpha+i\\omega)\\tau$.\n\\item Apply Euler's Formula: $\\gamma-g(e^{-\\lambda\\tau})=\\gamma-g(\\cos(\\lambda\\tau)-i\\sin(\\lambda\\tau))$.\n\\end{itemize}\n\\end{frame}\\end{comment}\n\n\\begin{frame}\\frametitle{Stochastic Coral Features}\nThe time delay model fails to account for stochastic features of the ecosystem:\n\\begin{itemize}\n\\item human activities (e.g. fishing and boating),\n\\item grazing habits of scarids, \n\\item hurricanes.\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Stochastic Model}\nTo account for these stochastic features we add noise!\n$$\\begin{cases}\n\\begin{array}{rl}\ndM\\hspace{-.8em}&=(aMC - \\frac{gM(t-\\tau)}{1-C(t-\\tau)+\\gamma M T})dt+{\\color{red}\\beta M(1-M)dW},\\\\\ndC\\hspace{-.8em}&=(rTC  - dC - aMC)dt.\\\\\n\\end{array}\n\\end{cases}$$\n\\end{frame}\n\n", "meta": {"hexsha": "ed6f027dcafbe73e4112198baa7cf15a261ce077", "size": 6723, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Presentations/Final/modeling.tex", "max_stars_repo_name": "SUNY-SDE-2015/REU15", "max_stars_repo_head_hexsha": "a54ace642d8696250c7fa0bf574b16a931ec91c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Presentations/Final/modeling.tex", "max_issues_repo_name": "SUNY-SDE-2015/REU15", "max_issues_repo_head_hexsha": "a54ace642d8696250c7fa0bf574b16a931ec91c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-06-04T17:55:32.000Z", "max_issues_repo_issues_event_max_datetime": "2015-07-09T15:38:17.000Z", "max_forks_repo_path": "Presentations/Final/modeling.tex", "max_forks_repo_name": "SUNY-SDE-2015/REU15", "max_forks_repo_head_hexsha": "a54ace642d8696250c7fa0bf574b16a931ec91c9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5532786885, "max_line_length": 215, "alphanum_fraction": 0.6611631712, "num_tokens": 2419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017535, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7210125001994432}}
{"text": "\n\n\\section{Preliminaries}\nAll rings mentioned are commutative and have a multiplicative identity, \nreferred to as $1$. \n\nWe will try not to assume that the reader knows everything, \nbut we will assume general knowledge of algebra and some introductory commutative algebra like definitions of rings, \nmodules, algebras etc. \n\n\\begin{theorem}[Noether's normalization lemma]\nLet $k$ be a field and $B$ a non-trivial finitely generated $k$-algebra. \nThen there exists a non-negative integer $d$ and algebraically independent elements $y_1, ..., y_d$, \ni.e. elements with no relations, \nin $B$ such that $B$ integral over the polynomial ring $k[y_1, ..., y_d]$.\n\\end{theorem}\n\\begin{proof}\nNote that the following proof is heavily based on the proof from Mumford's ``The red book''. \n\nSince $B$ is finitely generated the proof is done by induction on the number of generators, $m$. \n\n$m=0$: \nIn this case $A=k$ and we are done. \n\nAssume $m>0$ and that the lemma holds for all $k$-algebras generated by $m-1$ or fewer elements.\n\nNow, let $B$ be generated by $y_1, \\ldots, y_{m}$. \nIf there is no relations on the generators, \ni.e. they are algebraically independent, then\n\\begin{equation*}\n    B \\cong k[y_1, \\ldots, y_{m}]\n\\end{equation*}\nand we are done. \nHence we assume that $f$ is a relation on the $m$ generators, \ni.e. a polynomial equation\n\\begin{equation*}\n    f(y_1, \\ldots y_m) = 0. \n\\end{equation*}\nLet $r$ be an integer. \nWe are going to determine this later. \nSet $z_1 = y_1$ and $z_i = y_i - y_1^{r^{i-1}}$ for $2\\leq i \\leq m$.\nNote that the $z_i$'s also are generators of $B$.\nThen we can rewrite the relation as\n\\begin{equation*}\n    f(z_1, z_2+y_1^r, z_3+y_1^{r^2}, \\ldots z_m+y_1^{r^{m-1}}) = 0.\n\\end{equation*}\nFor $a\\in k$, \nthe highest term of $y_1$ appearing in $a\\prod_1^m (z_i + z_1^{r^{i-1}})^{\\alpha_i}$ looks like $ay_1^{\\alpha_1+r\\alpha_2+\\ldots+r^{m-1}\\alpha_m}$. \nHence, if $r$ is larger than all of the $\\alpha_i$'s appearing in $f$, \nthen the highest term of $y_1$ appearing in $f(z_1, z_2+y_1^r, z_3+y_1^{r^2}, \\ldots z_m+y_1^{r^{m-1}})$ also has the same form as the one above, \nwhich means that $y_1$ is integral over $k[y_2, \\ldots, y_m]$. \n\nSince $y_{i}=z_{i}+y_{1}^{r^{i-1}}$ are also integral over the same ring, \nthe $z_i$'s generate $B$, and being an integral extension is a transitive property, \nwe get that B is integral over $k[y_2, \\ldots, y_m]$. \nSince $k[y_2, \\ldots, y_m]$ is generated by $m-1$ elements, \nwe can apply the inductive hypothesis, and hence we are done.\n\\end{proof}\n\n%Note that Noether's normalization lemma also can be formulated, \n%and hence is equivalent to the statement that there exists a finite injective $k$-algebra homomorphism $k[y_1, \\ldots y_d]\\longrightarrow B$ for some $d\\in \\mathbb{N}$.\n\nWe want to apply Noether's normalization lemma to prove Zariski's lemma. \nIn the proof we present we use a result stating that integral ring extensions preserve Krull dimension. \nWe actually only use the fact that if a ring with Krull dimension zero is an integral ring extension of another ring, \nthen this ring also has Krull dimension zero. \nThe more general statement also is true, \nbut we only prove a more strict statement that we need. \n\nWe remind ourself what we mean by Krull dimension.\n\\begin{definition}[Krull dimension]\nLet $A$ be a ring. \nThe Krull dimension of $A$ is defined as the supremum over the length of all chains of prime ideals in $A$.\n\\end{definition}\n\n\\begin{proposition}\nLet $S$ be a ring and $T$ be an integral ring extension of $S$. \nThen the Krull dimension of $S$ is lower or equal to the Krull dimension of $T$. \n\\end{proposition}\n\\begin{proof}\nLet $\\mathfrak{p}_0\\subsetneq \\cdots \\subsetneq \\mathfrak{p}_n$ be a chain of prime ideals in $S$. \nBy the Going-up theorem we can extend any chain of length less than $n$, \n$\\mathfrak{q}_0\\subsetneq \\cdots \\subsetneq \\mathfrak{q}_m$ such that $\\mathfrak{q}_i\\cap S = \\mathfrak{p}_i$, \nfor $i=1,\\ldots, m$, \nto a chain of prime ideals $\\mathfrak{q}_0\\subsetneq \\cdots \\subsetneq \\mathfrak{q}_n$ in $T$, \nsuch that $\\mathfrak{q}_i\\cap S = \\mathfrak{p}_i$ for $i=1,\\ldots, n$. \nHence the Krull dimension of an integral ring extension can't get any lower than the Krull dimension of the ring it extends. \n\\end{proof}\n\nNote that we here used the so called Going-up theorem. \nThis theorem proves exactly what is stated in the proof of the proposition, \ni.e. that we can extend chains of prime ideals in integral extensions. \nWe will not prove this theorem, \nbut we refer the reader to the proof in Introduction to commutative algebra by Atiyah and MacDonald. \n\nThis immediately implies what we need, \ni.e. that if a ring with Krull dimension zero is an integral ring extension of another ring, \nthen this ring also has Krull dimension zero. \n\n\\begin{corollary}[Zariski's lemma]\nLet $k$ be a field, and $K$ be a field extension that is finitely generated as an algebra over $k$. \nThen $K$ is a finite field extension, \ni.e. a finite dimensional $k$-vectorspace. \n\\end{corollary}\n\\begin{proof}\nBy Noether's normalization lemma, \n$K$ is integral over the ring $k[y_1, \\ldots y_d]$, \nwhere $y_1, \\ldots y_d$ are the elements of $K$ that are algebraically independent over $k$. \nSince $K$ is a field, it has Krull dimension $0$, \nand since integral ring extensions preserve Krull dimension, \nthe polynomial ring $k[y_1, \\ldots y_d]$ must have Krull dimension zero, \ni.e. $d=0$. Hence $K$ is a finitely generated module over $k$, \ni.e. a finite dimensional $k$-vectorspace. \n\\end{proof}\n\nNow, before we tackle the actual proof of Hilbert's nullstellensatz, \nwe need to chose a formulation. \nThere are many formulations of the theorem, \nall hopefully equivalent, \nbut we have chosen one of the more standard and iconic ones. \nThe formulation is based on some language from algebraic geometry, \nhence we need some definitions. \n\n\\begin{definition}[Radical]\nLet A be a ring and $\\mathfrak{a}$ an ideal in A. \nWe define the radical of $\\mathfrak{a}$ to be the set\n\\begin{equation*}\n    \\sqrt{\\mathfrak{a}} = \\{ f\\in A \\ | \\ \\exists n \\in \\mathbb{N} \\text{ s.t. } f^n \\in \\mathfrak{a} \\}.\n\\end{equation*}\nWe say an ideal $\\mathfrak{a}$ is a radical ideal if $\\mathfrak{a}=\\sqrt{\\mathfrak{a}}$. \n\\end{definition}\n\n\\begin{definition}[Zero locus]\nLet $k$ be an algebraically closed field, \n$A$ be the polynomial ring $A = k[t_1, \\ldots, t_n]$ and let $S \\subset A$ be a subset. \nWe define the zero locus of $S$ to be the set \n\\begin{equation*}\n    Z(S) = \\{ x\\in k^n \\ | \\ f(x)=0, \\ \\forall f\\in S\\}.\n\\end{equation*}\n\\end{definition}\nIf a subset $V\\subset k^n$ has the form $V=Z(S)$ for some $S\\subset A$, \nthen we call $V$ an affine algebraic variety.\n\n\\begin{definition}[Vanishing set]\nLet $V\\subset k^n$. We define the vanishing set of $V$ to be the set\n\\begin{equation*}\n    I(V) = \\{ f\\in A \\ | \\ f(x)= 0, \\ \\forall x\\in V\\}.\n\\end{equation*}\n\\end{definition}", "meta": {"hexsha": "d4a73b83c2cbe7b40da2057c7f4fe86c0284f7b2", "size": 6883, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/preliminaries.tex", "max_stars_repo_name": "torgeiraamboe/hilberts-nullstellensatz", "max_stars_repo_head_hexsha": "9fb14841c0795a1466bf62ff851e94eb89149fa6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/preliminaries.tex", "max_issues_repo_name": "torgeiraamboe/hilberts-nullstellensatz", "max_issues_repo_head_hexsha": "9fb14841c0795a1466bf62ff851e94eb89149fa6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/preliminaries.tex", "max_forks_repo_name": "torgeiraamboe/hilberts-nullstellensatz", "max_forks_repo_head_hexsha": "9fb14841c0795a1466bf62ff851e94eb89149fa6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.1946308725, "max_line_length": 169, "alphanum_fraction": 0.7155310185, "num_tokens": 2202, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.8652240738888188, "lm_q1q2_score": 0.7210124940646288}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{hyperref}\n\\usepackage{parskip}\n\n\\newcommand{\\KL}[2]{\\mathrm{KL}(#1~\\|~#2)}\n\n\\begin{document}\n\nSuppose we wish to estimate $p(y \\mid x)$ when we observe $(x_i, y_i) \\sim p(y\n\\mid x) p_1(x) $ but care about achieving high accuracy under some other $p(x\n\\mid x) p_2(x)$ (the \\emph{covariate shift} problem). Suppose further that we\nhave some information about $y$ under the target distribution---namely that we\ncan sample from $p_2(y) := \\sum_x p_2(x) p(y \\mid x)$. How can we use this\ninformation to find some $p_\\theta(y \\mid x)$ that maximizes $E_{x \\sim p_2(x)} p(x\n\\mid y)$?\n\nIdea: optimize\n\\begin{align}\n  \\min_{\\theta,\\eta} ~~ &-\\sum_i \\log p_\\theta(y_i \\mid x_i) + \\lambda~\\KL{p_2}{p_\\eta(x)\n  p_\\theta(y \\mid x)}\n\\end{align}\nThis can be viewed as a form of posterior regularization and specifically\n\\textbf{expectation regularization} as in\n\\url{https://www.aclweb.org/anthology/D19-1004/}.\n\\begin{align}\n  &= -\\sum_i \\log p_\\theta(y_i \\mid x_i) + \\lambda H(p_2) - \\lambda E_{y \\sim p_2(y)}\n  [\\log E_{x \\sim p_\\eta} p_\\theta(y \\mid x)] \\\\\n  &\\leq -\\sum_i \\log p_\\theta(y_i \\mid x_i) + \\lambda H(p_2) -  \\lambda E_{y \\sim p_2(y)}\n  E_{x \\sim p_\\eta} \\log p_\\theta(y \\mid x) \\\\\n  \\intertext{(Jensen)}\n  \\min_{\\theta, \\eta, \\phi} ~~ &\\leq -\\sum_i \\log p_\\theta(y_i \\mid x_i) + \\lambda H(p_2) -  \\lambda E_{y \\sim p_2(y)}[\n  E_{x \\sim q_\\phi(x \\mid y)} [\\log p_\\theta(y \\mid x)] -\\KL{q_\\phi(x \\mid y)}\n  {p_\\eta(x)}]\n\\end{align}\n(ELBO)\n\nImportant special case of this model: \\textbf{backtranslation}, where we assume\nthat $q(x \\mid y)$ is the same under $p_1$ and $p_2$ and estimate it directly\nfrom training data. From this perpsective, backtranslation can be viewed not\njust as amortizing a noisy channel translation model but actually providing\nrobustness to the covariate shift implied by any difference between $p(y)$ on\nbilingual and monolingual data.\n\nClaim: we can get lots of ``NLP-flavored'' inductive biases in this framework\njust by setting $p(y)$ uniform over an appropriate set. Example:\n\n\\paragraph{Mutual exclusivity}\nLet $\\pi$ be a permutation on $[n]$ and $(x_i, y_i)$ be one-hot vectors $(e_i,\ne_{\\pi(i)}$ for $i \\in [n-1]$. Prove that a regularized logistic regression\nmodel has $p(y \\mid e_{n-1})$ uniform over classes when trained via MLE but\nmostly on $e_{\\pi(n-1)}$ when trained as in Equation 1.\n\n\\paragraph{Compositionality}\nAs above, but let each $x_i$ be a concatenation of two one-hot vectors and $y_i$\nbe the concatenation of their permuted values. Prove that if we hold out $k$ of\nthese vectors, Equation 1 still recovers the correct values but MLE doesn't.\n\n\\paragraph{Productivity}\nSomething about learning a weighted string transducer.\n\n\\end{document}\n", "meta": {"hexsha": "4461715b10978191087e64e0582148697124be87", "size": 2788, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/notes.tex", "max_stars_repo_name": "AnjaliRuban/lexical", "max_stars_repo_head_hexsha": "e120c8d9c094f427709b636d8df4a7de5742b7ce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-06-06T21:34:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T07:17:04.000Z", "max_issues_repo_path": "notes/notes.tex", "max_issues_repo_name": "AnjaliRuban/lexical", "max_issues_repo_head_hexsha": "e120c8d9c094f427709b636d8df4a7de5742b7ce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/notes.tex", "max_forks_repo_name": "AnjaliRuban/lexical", "max_forks_repo_head_hexsha": "e120c8d9c094f427709b636d8df4a7de5742b7ce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-08T04:48:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-22T13:49:20.000Z", "avg_line_length": 42.2424242424, "max_line_length": 119, "alphanum_fraction": 0.7065997131, "num_tokens": 924, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7210053271912954}}
{"text": "\\subsection{Branching Properties}\r\n$\\wp_\\Lambda$ has a unique pole in $\\mathbb C/\\Lambda$ of order $2$.\r\nThe other ramification points are at the zeros of $\\wp_\\Lambda^\\prime$.\r\nRecall that\r\n$$\\wp_\\Lambda^\\prime(z)=\\sum_{\\omega\\in\\Lambda}\\frac{-2}{(z-\\omega)^3}$$\r\nwhich is an odd function with degree $3$ and poles exactly at the lattice points.\r\nFor any $\\omega\\in\\Lambda$, we have $\\wp_\\Lambda^\\prime(\\omega/2)=\\wp_\\Lambda^\\prime(\\omega/2-\\omega)=\\wp_\\Lambda^\\prime(-\\omega/2)=-\\wp_\\Lambda^\\prime(\\omega/2)$ as $\\wp_\\Lambda^\\prime$ is odd, so $\\omega/2$ is either a zero or a pole.\r\nSo in the period parallelogram $P$, there are at least three zeros (up to $\\Lambda$) namely $\\omega_1/2,\\omega_2/2,(\\omega_1+\\omega_2)/2$.\r\nBut $\\deg\\wp_\\Lambda^\\prime=3$, so these are all the zeros and all of them are simple.\r\n\\begin{remark}\r\n    $\\wp_\\Lambda$ has $4$ ramification points in $\\mathbb C/\\Lambda$, namely $0,\\omega_1/2,\\omega_2/2,(\\omega_1+\\omega_2)/2$ each with multiplicity $2$.\r\n    So by the valency theorem, they must have distinct images $\\infty=\\wp_\\Lambda(0),e_1=\\wp_\\Lambda(\\omega_1/2),e_2=\\wp_\\Lambda(\\omega_2/2),e_3=\\wp_\\Lambda((\\omega_1+\\omega_2)/2)$.\r\n\\end{remark}\r\n\\begin{remark}\r\n    By plugging in, this is consistent with Riemann Hurwitz as $\\mathbb C/\\Lambda$ has genus $1$.\r\n\\end{remark}", "meta": {"hexsha": "7af142907c5c695fc573bca3cf499076b534cc1b", "size": 1308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14/branch.tex", "max_stars_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_stars_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "14/branch.tex", "max_issues_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_issues_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "14/branch.tex", "max_forks_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_forks_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 81.75, "max_line_length": 237, "alphanum_fraction": 0.6980122324, "num_tokens": 437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294214513915, "lm_q2_score": 0.7981867777396211, "lm_q1q2_score": 0.7209974984337039}}
{"text": "%---------------------------Stretch---------------------------\n\\section{Stretch}\n\nThe stretch is the ratio of the minimum edge length to the maximum diagonal, normalized\nso that a unit cube has a value of 1:\n\\[\n  q = \\sqrt{3}\\frac{L_{\\min}}{D_{\\max}}.\n\\]\n\nNote that if $D_{\\max} < DBL\\_MIN$, we set $q = DBL\\_MAX$.\n\n\\hexmetrictable{stretch}%\n{$1$}%                                        Dimension\n{$[0.25,1]$}%                                 Acceptable range\n{$[0,1]$}%                                    Normal range\n{$[0,DBL\\_MAX]$}%                             Full range\n{$1$}%                                        Cube\n{Adapted from \\cite{fimesh:xx}}%              Citation\n{v\\_hex\\_stretch}%                            Verdict function name\n", "meta": {"hexsha": "a36ffc3486976aae686f0508e2d8be4711c853b8", "size": 751, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexStretch.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexStretch.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexStretch.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 37.55, "max_line_length": 87, "alphanum_fraction": 0.4300932091, "num_tokens": 185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009642742806, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.7208790175095586}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\n\\def\\r{\\mathbf{r}}\n\\def\\q{\\mathbf{q}}\n\\def\\i{\\mathbf{i}}\n\\def\\j{\\mathbf{j}}\n\\def\\k{\\mathbf{k}}\n\n\n\\begin{document}\n\n\\section{Coordinate systems}\n\nLet $x,y,z$ be a coordinate system such that the camera is at the\norigin, the floor is some known constant $y$, and positive $z$ is the\ncurrent direction of motion of the robot. We write\n\\begin{equation}\n  \\r = x\\i + y\\j + z\\k\n\\end{equation}\nwhere $\\i,\\j,\\k$ can be considered unit vectors or quaternions.  These\ncan be conveniently represented as the complex matrices\n\\begin{equation}\n\\i = \\begin{pmatrix} 0 & i  \\\\ i & 0  \\end{pmatrix} \\qquad\n\\j = \\begin{pmatrix} 0 & -1 \\\\ 1 & 0  \\end{pmatrix} \\qquad\n\\k = \\begin{pmatrix} i & 0  \\\\ 0 & -i \\end{pmatrix}\n\\end{equation}\nbut other representations are also possible.\n\nThe camera is at some orientation given by the quaternion $\\q$ as\n\\begin{equation}\n\\r' = \\q \\, \\r \\, \\q^*\n\\end{equation}\nsuch that $z'$ is the forward direction of the camera.  Let $f$ be the\nfocal distance.  Then the camera-plane coordinates will be\n\\begin{equation}\n  \\begin{pmatrix} X' \\\\ Y' \\end{pmatrix} =\n  f \\begin{pmatrix} x'/z' \\\\ y'/z' \\end{pmatrix}\n\\end{equation}\nThe actual camera coordinates will, however, involve a nonlinear\ncalibration\n\\begin{equation}\n  X,Y = K(X',Y')\n\\end{equation}\n\nConsider two snapshots, between which the robot moves by $\\Delta z$.\nThat is, the world coordinate system moves by $-\\Delta z$.  This\nresults in visual vectors\n\\begin{equation}\n  \\begin{pmatrix} \\Delta X \\\\ \\Delta Y \\end{pmatrix}\n\\end{equation}\n\n\\section{Lens-calibrated case}\n\nWe assume that $K$ has been calibrated out to the identity.  Then\n\\begin{equation}\n  \\Delta\\r' = - \\q \\, \\k \\, \\q^* \\, \\Delta z\n\\end{equation}\n\nSuppose first that $\\q=1$.  Then\n\\begin{equation}\n   \\begin{pmatrix} \\Delta X \\\\ \\Delta Y \\end{pmatrix} =\n   f \\begin{pmatrix} x \\\\ y \\end{pmatrix}\n   \\left(1/z-1/(z-\\Delta z)\\right)\n\\end{equation}\nor (since $\\Delta z$ is small)\n\\begin{equation}\n   \\begin{pmatrix} \\Delta X \\\\ \\Delta Y \\end{pmatrix} =\n-f \\, \\frac{\\Delta z}z \\begin{pmatrix} X \\\\ Y \\end{pmatrix}\n\\end{equation}\nIn this expression, all the visual vectors point to the origin of the\ncamera plane.  If we now know $f$ and $\\Delta z$, we have $z$.\n\nIf $\\q\\neq1$ the visual vectors will still all point to a single\npoint, namely the vanishing point corresponding to the direction of\nmotion in camera coordinates.  This fact suggests a simple strategy\nfor calibrating the pitch and yaw of the camera: find $\\q$ so as to\nmove the vanishing point of the visual vectors to the origin.\nDetermining the roll (or the $\\k$ component of $\\q$) is harder, but\nmaybe not necessary.\n\n\\end{document}\n", "meta": {"hexsha": "131db4641bc4975554b91877a9297a69eded21ca", "size": 2680, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "perspec/text/notes.tex", "max_stars_repo_name": "UbiquityRobotics/nav_workshop", "max_stars_repo_head_hexsha": "4bc246f8b94fc90dba62b257269fab1e3af173db", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "perspec/text/notes.tex", "max_issues_repo_name": "UbiquityRobotics/nav_workshop", "max_issues_repo_head_hexsha": "4bc246f8b94fc90dba62b257269fab1e3af173db", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "perspec/text/notes.tex", "max_forks_repo_name": "UbiquityRobotics/nav_workshop", "max_forks_repo_head_hexsha": "4bc246f8b94fc90dba62b257269fab1e3af173db", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.9047619048, "max_line_length": 70, "alphanum_fraction": 0.6955223881, "num_tokens": 872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.7956580927949807, "lm_q1q2_score": 0.7208581366172329}}
{"text": "\\section{Proof of Theorem~\\ref{thm:less_than_total_degree}}\n\\label{app:proof_thm_less_than_total_degree}\nTo prove Theorem~\\ref{thm:less_than_total_degree} we need the following lemmas.\n  \\begin{lemma}\\label{lem:difference_to_p-1}\n    For all $(a,b)\\in\\Z^2$ we have:\n    \\[\n      (a - b)^{p-1} = \\sum_{i=0}^{p-1} a^i b^{p-1-i} \\mod p.\n    \\]\n  \\end{lemma}\n  \\begin{proof}\n    Using the binomial theorem we obtain\n    \\[\n      (a - b)^{p-1} = \\sum_{i=0}^{p-1} \\binom{p-1}{i} a^i (-b)^{p-1-i}.\n    \\]\n    Computing the binomial coefficient modulo $p$\n    \\begin{align*}\n      \\binom{p-1}{i} & = \\frac{(p-1)!}{i! (p-1-i)!} \\\\\n      & = \\frac{(p-1)(p-2)\\dots(i+1)}{1 \\cdot 2 \\dots (p-(1+i))} \\\\\n      &= (-1)^{p-1-i} \\mod p\\,,\n    \\end{align*}\n    we prove the lemma.\n  \\end{proof}\n\n  \\begin{lemma}\\label{lem:sum_poly}\n    Let $P(X)$ be a polynomial of degree $d$ less than $p-1$.\n    For any prime number $p > 2$, it holds\n    \\[\n      \\sum_{a=0}^{p-1} P(a) = 0 \\mod p.\n    \\]\n  \\end{lemma}\n  \\begin{proof}\n    Since $\\sum_{a=0}^{p-1} b = 0 \\mod p$ for any $b \\in \\F_p$, it is enough to prove that the sum $\\sum_{a=0}^{p-1} a^n = 0 \\mod p$ for any $0 \\leq n < p-1$.\n    Since the case $n=0$ is straightforward, let us assume $n>0$. \n    Let $g$ be a primitive element of $\\F_p$.\n    Since $p > 2$, we have $g \\ne 1$.\n    Thus, we can rewrite the above sum as follows.\n    \\begin{align*}\n      \\sum_{i=1}^{p-1} g^{in} = \\frac{g^{pn} - g^n}{g^n - 1}.\n    \\end{align*}\n    Since $g^{pn} \\equiv g^n \\mod p$, the sum turns into zero modulo $p$.\n  \\end{proof}\n  Now, we have all the ingredients to prove Theorem~\\ref{thm:less_than_total_degree}.\n  \\begin{proof}[Proof of Theorem \\ref{thm:less_than_total_degree}]\n    Assume that all computations are done modulo $p$.\n    Using Lemma~\\ref{lem:difference_to_p-1}, we obtain that $P_{\\LT_\\S}(X,Y)$ is equal to\n    \\begin{align*}\n      \\sum_{a = 0}^{p-2} \\left(1-\\sum_{i=0}^{p-1} X^i a^{p-1-i}\\right) \\sum_{b=a+1}^{p-1} \\left(1-\\sum_{j=0}^{p-1} Y^j b^{p-1-j}\\right)\n    \\end{align*}\n    Let us expand this expression distributively.\n    \\begin{align*}\n      \\sum_{a = 0}^{p-2} \\sum_{b=a+1}^{p-1} 1 - \\sum_{i=0}^{p-1} X^i a^{p-1-i} - \\sum_{i=0}^{p-1} Y^i b^{p-1-i} \\\\\n      + \\sum_{i=0}^{p-1} \\sum_{j=0}^{p-1} X^i Y^j a^{p-1-i} b^{p-1-j}.\n    \\end{align*}\n    Let us compute individual polynomial coefficients.\n    The constant term is equal to\n    \\begin{align*}\n      \\sum_{a = 0}^{p-2} \\sum_{b=a+1}^{p-1} 1 - a^{p-1} - b^{p-1} + a^{p-1} b^{p-1} \\\\\n      = \\sum_{a = 0}^{p-2} \\sum_{b=a+1}^{p-1} 1 - a^{p-1} - 1 + a^{p-1} = 0\\,. \n    \\end{align*}\n    Coefficients by $X^i$ with $i > 0$ can be computed as follows\n    \\begin{align*}\n      \\sum_{a = 0}^{p-2} \\sum_{b=a+1}^{p-1} \\left(-a^{p-1-i}\\right) + a^{p-1-i}b^{p-1} = 0\\,.\n    \\end{align*}\n    Next, we compute coefficients by $Y^i$ with $i > 0$.\n    \\begin{align*}\n      -\\sum_{a = 0}^{p-2} &\\sum_{b=a+1}^{p-1} b^{p-1-i} - a^{p-1} b^{p-1-i} \\\\\n      &= -\\sum_{b=1}^{p-1} b^{p-1-i} - \\sum_{a = 1}^{p-2} \\sum_{b=a+1}^{p-1} b^{p-1-i} - b^{p-1-i} \\\\\n      &= -\\sum_{b=1}^{p-1} b^{p-1-i}.\n    \\end{align*}\n    If $i = p-1$, this sum is equal to $1$.\n    According to Lemma~\\ref{lem:sum_poly}, it is $0$ if $i < p-1$.\n    \n    To compute coefficients by $X^i Y^j$ with $i, j > 0$, we will use Faulhaber's formula below\n    \\begin{align*}\n      \\sum_{k=1}^n k^e = \\frac{1}{e+1} \\sum_{i=1}^{e+1} (-1)^{\\delta_{ie}} \\binom{e+1}{i} B_{e+1-i} \\cdot n^i\\,,\n    \\end{align*}\n    where $\\delta_{ie}$ is the Kronecker delta and $B_{i}$ is the $i$th Bernoulli number.\n    This implies that there exist a polynomial $P(X) \\in \\F_p[X]$ of degree $e+1$ such that\n    \\begin{align}\\label{eq:faulhaber}\n      \\sum_{k=1}^n k^e = P(n).\n    \\end{align}\n    Note that $P(0) = 0$.\n    The coefficient by $X^i Y^j$ for some positive $i$ and $j$ is equal to\n    \\begin{align*}\n      \\sum_{a = 0}^{p-2} \\sum_{b=a+1}^{p-1} a^{p-1-i} b^{p-1-j} &= \\sum_{b = 1}^{p-1} b^{p-1-j} \\sum_{a=0}^{b-1} a^{p-1-i}\\,. \\\\\n    \\end{align*}\n    According to~(\\ref{eq:faulhaber}), there exist a polynomial $P_i(X)$ of degree $p-i$ such that $\\sum_{a=0}^{b-1} a^{p-1-i} = P_i(b)$.\n    Since $Q_{ij}(X) = X^{p-1-j} P_i(X)$ has degree $2p-1-i-j$, Lemma~\\ref{lem:sum_poly} implies that if $i+j > p$, then\n    \\begin{align*}\n      \\sum_{b = 1}^{p-1} b^{p-1-j} &\\sum_{a=0}^{b-1} a^{p-1-i} = \\sum_{b = 1}^{p-1} b^{p-1-j} P_i(b) \\\\ \n      &= \\sum_{b=1}^{p-1} Q_{ij}(b) = \\sum_{b=0}^{p-1} Q_{ij}(b) - Q_{ij}(0) = 0.\n    \\end{align*}\n    Thus, all the coefficient $X^i Y^j$ with $i + j > p$ are zero, which means that the total degree of $P_{\\LT_\\S}(X,Y)$ is at most $p$.\n\n    In addition, we consider the case when $i = j$ and $i,j \\le (p-1)/2$.\n    Let us consider the following sum\n    \\begin{align*}\n      \\sum_{a=0}^{p-1} a^{p-1-i} \\sum_{b=0}^{p-1} b^{p-1-i} = 0\\,.\n    \\end{align*}\n    We can rewrite it as follows\n    \\begin{align*}\n      \\sum_{a=0}^{p-1} & a^{p-1-i} \\sum_{b=0}^{p-1} b^{p-1-i} \\\\\n      &= 2\\sum_{a=0}^{p-2} a^{p-1-i} \\sum_{b=a+1}^{p-1} b^{p-1-i} + \\sum_{a=0}^{p-1} a^{2(p-1-i)}\\,.\n    \\end{align*}\n    This implies that\n    \\begin{align*}\n      \\sum_{a=0}^{p-2} a^{p-1-i} \\sum_{b=a+1}^{p-1} b^{p-1-i} = -\\frac{1}{2}\\sum_{a=0}^{p-1} a^{2(p-1-i)}\\,.\n    \\end{align*}\n    Note that the inverse of $2$ is well defined modulo $p$ since $p$ is an odd prime.\n    If $i < (p-1)/2$, then Lemma~\\ref{lem:sum_poly} says the sum on the right side is zero.\n    Thus, the coefficient by $X^i Y^i$, which is exactly the sum on the left side, is equal to zero.\n    If $i = (p-1)/2$, the above equality yields that the coefficient by $(XY)^{(p-1)/2}$ is equal to $-(p-1)/2$.\n  \\end{proof}\n\n\\section{Decomposition of $f(X,Y)$ for $3\\leq p \\leq 7$}\n\\label{app:decomposition-f}\nLet $Z = Y(X-Y)$. \nOne non-scalar multiplication is needed to compute $Z$.\n\n\\textbf{p=3.}\n$$f(X,Y) = 2\\,.$$\n\nSince the polynomial $f(X,Y)$ is constant, it can be computed without any homomorphic multiplication.\n\n\\textbf{p=5.}\n$$f(X,Y) = 4X^2 + 4X + Z\\,.$$\n\nTwo non-scalar multiplications are needed to compute $X^2$ and $Z$.\n\n\\textbf{p=7.}\n$$f(X,Y) = 1 + 4X(X+1) + 6[X(X+1)]^2 + (X^2+3X)Z + 6Z^2$$\n\nIn this case, four non-scalar multiplications are needed (indicated in bold) when rewritten as follows\n$$f(X,Y) = 1 + 2(\\bm{X}^2+X)\\bm{\\cdot}[2 + 3(X^2+X)] + \\bm{Z}\\bm{\\cdot}[(X^2+3X) + 6Z]\\,.$$\n\n\\section{Proof of Theorem~\\ref{th:univariate}}\n\\label{app:proof-lem-univariate}\n   Let $Z = X-Y$.\n    Thus we can rewrite $Q_{\\LT_\\S}(X,Y)$ as the univariate function $\\chi_{\\F_p^-}$, namely\n    \\begin{align*}\n      Q_{\\LT_\\S}(X,Y) = \\chi_{\\F_p^-}(Z) = \\sum_{a=-\\frac{p-1}{2}}^{-1} 1 - (Z - a)^{p-1}.\n    \\end{align*}\n    Thanks to Lemma~\\ref{lem:difference_to_p-1}, we can expand $(Z-a)^{p-1}$ and obtain\n    \\begin{align*}\n      \\sum_{a=-\\frac{p-1}{2}}^{-1} 1 - \\sum_{i=0}^{p-1} Z^i a^{p-1-i}\n      = \\sum_{i=1}^{p-1} Z^i \\sum_{a=-\\frac{p-1}{2}}^{-1} (-a^{p-1-i}).\n    \\end{align*}\n    If $i$ is even and $i < p-1$, then the $i$th coefficient is equal to\n    \\begin{align*}\n      -\\sum_{a=-\\frac{p-1}{2}}^{-1} a^{p-1-i} &= -\\sum_{a=1}^{\\frac{p-1}{2}} a^{p-1-i} = -\\frac{1}{2}\\sum_{a=-\\frac{p-1}{2}}^{\\frac{p-1}{2}} a^{p-1-i}.\n    \\end{align*}\n    This coefficient is equal to $0$ for any even $0<i < p-1$ thanks to Lemma~\\ref{lem:sum_poly}.\n    The $(p-1)$-th coefficient is equal to $-(p-1)/2 = (p+1)/2 \\bmod p$.\n    If $i$ is odd, then we can rewrite the $i$th coefficient in the following way\n    \\begin{align*}\n      -\\sum_{a=-\\frac{p-1}{2}}^{-1} a^{p-1-i} &= \\sum_{a=1}^{\\frac{p-1}{2}} a^{p-1-i},\n    \\end{align*}\n    which finishes the proof.\n \n\n%%%Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "f8b121d57c3365adfc5f6723f94c88bb97616a36", "size": 7633, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/appendix.tex", "max_stars_repo_name": "iliailia/comparison-circuit-over-fq", "max_stars_repo_head_hexsha": "bc48a9101278997f0847b6ace59c8f3b83884dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-03-24T07:58:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T00:41:08.000Z", "max_issues_repo_path": "paper/appendix.tex", "max_issues_repo_name": "iliailia/comparison-circuit-over-fq", "max_issues_repo_head_hexsha": "bc48a9101278997f0847b6ace59c8f3b83884dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-03-24T03:03:11.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-01T09:23:59.000Z", "max_forks_repo_path": "paper/appendix.tex", "max_forks_repo_name": "iliailia/comparison-circuit-over-fq", "max_forks_repo_head_hexsha": "bc48a9101278997f0847b6ace59c8f3b83884dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-19T16:28:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T16:28:37.000Z", "avg_line_length": 46.2606060606, "max_line_length": 158, "alphanum_fraction": 0.5476221669, "num_tokens": 3372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.795658090372256, "lm_q1q2_score": 0.7208581263436935}}
{"text": "\\section{Solution approach using a CNN}\r\n\\label{sec:ansatz}\r\nThe most successful approach to image recognition based an machine-learing algorithms is the use of \\textit{Convolutional Neural Networks} (CNN).\r\nCNNs can use multidimensional input arrays which is their main advantage for working with image data compared to \\enquote{normal} fully-connected neural networks, \r\nbecause the information about the position of each pixel compared to its neighbors is not lost by flattening the pixel-values in an one dimensional array.\r\nThis is done by repeatedly applying weight-matrices of size $N_\\text{kernel}\\times M_\\text{kernel}$ called \\textit{kernels} on the image, while moving the kernel from one edge of the image to the other, \r\nwhereby the steps size (referring to the number of pixel-rows/ -columns that the kernel is moved by in each step) is called \\textit{stride}.\r\nThis allows CNNs to learn geometric shapes within the images it is trained on.\r\nAs we want to classify the images into the eleven flower species, we also add a small fully-connected neural network after the CNN structure, so that the final output of our\r\nneural network are eleven scores for each image which describe how likely the image shows a flower(s) of each of the eleven species.\r\nA subsequent final assignment to one of the species is done by choosing the species with the highest score.\r\n\r\nOur problem represents a classification problem with $k = 11$ target classes.\r\nFor this type of problem the \\textit{categorical cross-entropy} is a good loss function\r\n\\begin{align}\r\n    CE = -\\frac{1}{n} \\sum_{i=1}^n \\sum_{k=1}^{11} p_{i,k} \\ln{y_{i,k}},\r\n\\end{align}\r\nwhere $n$ is the number of images used for training, $p_{i,k}$ the target vector with $p_{i,k} = 0$ for all classes but the true class $k'$ of the image $i$ ($p_{i,k'} = 1$) and \r\n$y_{i,k}$ the prediction vector with the predicted probabilities of the image being of class $k$.\r\nAs our goal is to correctly classify as many images as possible, the \\textit{accuracy} of the classification is the most fitting performance metric\r\n\\begin{align}\r\n    \\text{accuracy} = \\frac{n_\\text{correctly classified}}{n}.\r\n\\end{align}\r\n\r\n\r\n\\subsection{First network and manual hyperparameter tuning}\r\nFor constructing, training and applying a neural network we use the \\texttt{keras} API for Googles \\texttt{TensorFlow} deep-learning library \\cite{keras}, \r\nwhile some helper functions from the \\texttt{scikit-learn} library are used \\cite{scikit-learn}.\r\nDue to our preprocessing, the shape of the input data is $200\\times 200\\times 3$, where the last dimension represents the three RGB color channels.\r\n\r\nWe start by trying different structures for the network to get a basic of idea of which type of network works for our problem.\r\nThis leads to a network with three convolutional layers, each followed by a MaxPooling layer to stabilize the performance of the network against slight displacement or rotation of certain shapes \r\nin different images.\r\nMaxPooling layers take the maximal value of a $N_\\text{pool}\\times N_\\text{pool}$ subspace of each of the two-dimensional arrays (/image-channels) of the three-dimensional input and \r\nreturn it as the single output for each of those subspaces.\r\nAfter the convolutional part of the network we add two hidden fully-connected layers before the output layer (a second hidden layer improves the accuracy compared with only one hidden layer).\r\n\r\nAs \\textbf{activation functions} we use the \\textit{ReLU} function for all layers but the output layer, for which we use the \\textit{softmax} function.\r\nThis choice of activation functions makes it possible to interpret the output scores of the network as actual probabilities of the image showing a flower of the given species.\r\n\r\nRegarding the \\textbf{number of kernels} in each convolutional layer, an increasing number of kernels seems to work best and we choose to double the number of kernels in each layer\r\nstarting with 16 kernels in the first layer.\r\nFor the \\textbf{MaxPooling} layers we choose $N_\\text{pool} = 2$, as any larger number decreases the image size too quickly.\r\nThe combination of an increasing number and kernels with pooling layers after each convolutional layer effectively leads to a compression of the first two dimensions (height and width of the image) \r\nof the data while more information gets transformed into the third dimension (number of kernels (RGB channels) in the (input) layer).\r\n\r\nFor an image size of $200\\times 200$ the kernel must also be square ($N_\\text{kernel} = M_\\text{kernel}$) and a \\textbf{kernel size} of $N_\\text{kernel} = 4$ seems to work well.\r\nWe tried using non-unit \\textbf{stride}, but the best result is achieved by using the (default) unit stride which means moving the kernel one pixel-row/ -column at a time across the image.\r\n\r\nAn overview of the network structure we find based on these manual hyperparameter variations can be found in \\autoref{fig:first_model}. \r\n\r\nFor \\textbf{training} the network we use the \\textit{Adam} algorithm \\cite{adam} with the (default) initial learing rate of 0.001 and a batch size of 128.\r\nWe test initial learing rates of 0.01 and 0.0001 and batch sizes of 256 and 64, but these settings do perform significantly worse or slow the training down a lot.\r\n\r\nUsing the hyperparameter values described so far we achieve an accuracy of 0.753 in training epoch 17 and the loss and accuracy curves can be seen in \\autoref{fig:first_curves}. \r\nTo validate the performance of the model we split another $\\SI{15}{\\percent}$ of the images into a validation set.\r\nThe whole data is hereby split into $\\SI{70}{\\percent}$ training set, $\\SI{15}{\\percent}$ validation set and $\\SI{15}{\\percent}$ test set.\r\n\r\n\r\n\\subsection{Hyperparameter tuning via sequential grid searches}\r\nAfter finding a network structure which performs reasonably well, we perform four sequential grid searches.\r\nThe first search covers the number of nodes in the two hidden fully-connected layers.\r\n\\begin{align}\r\n    N_\\text{dense nodes} \\in \\{64, 96, 128, 160, 192, 224, 256\\}\r\n\\end{align}\r\nThe best accuracy on the validation set (0.770 in training epoch 22) is achieved by using 224 nodes in both layers and the loss and accuracy curves of the three best performing models \r\n(in regards to accuracy on the validation set) can be seen in \\autoref{fig:GS1}\r\n\r\nIn the second search we use more convolutional layers and vary the number of kernels in each layer (still doubling the number from layer to layer).\r\n\\begin{align}\r\n    N_\\text{conv. layers} &\\in \\{3, 4, 5, 6\\}, &\r\n    \\text{num}_\\text{kernels} &\\in \\{8, 16, 24, 32, 40, 48, 64, 80, 96\\}\r\n\\end{align}\r\nFor $N_\\text{conv. layers} = 3, 4, 5$ we still use a MaxPooling layer after each layer, but for $N_\\text{conv. layers} = 6$ we only include a MaxPooling layer every two layers and \r\nalso double the number of kernels only every two layers.\r\nThis search is done in three parts, because the first two tries result in the model with the largest $\\text{num}_\\text{kernels}$ performing the best.\r\nTherefore, it is necessary to increase the range of $\\text{num}_\\text{kernels}$ to test.\r\n$N_\\text{conv. layers} = 5$ is also not present in the first part of the search, but in the second part it performs better than $N_\\text{conv. layers} = 4$ (which performed best in the first part)\r\nfor all tested number of kernels, which is why only $N_\\text{conv. layers} = 5$ is tested in the third part.\r\nThe performance of the four best models in the third part of the search can be seen in \\autoref{fig:GS2_ext2}.\r\n\\begin{figure}\r\n    \\centering\r\n    \\includegraphics[width=\\textwidth]{../data/performance_plots/GS2_ext2.pdf}\r\n    \\caption{The loss and accuracy curves for the three best performing models in the third part of the second grid search ($N_\\text{conv. layers} = 5$).}\r\n    \\label{fig:GS2_ext2}\r\n\\end{figure}\r\nEven though the model with $\\text{num}_\\text{kernels} = 96$ performs the best we choose $\\text{num}_\\text{kernels} = 48$ as our optimal number of kernels (in the first layer),\r\nbecause it performs only slightly worse while representing a much less complex model. \r\nOn one hand less complex models are generally to be preferred over more complex ones, if they perform equally well (\\textit{Occam's razor}) and on the other hand training a model \r\nwith as big a capacity as the one with $\\text{num}_\\text{kernels} = 96$ is so slow, that it would make further hyperparameter tuning extremely difficult, because of our limited computing resources.\r\nIn the end, the model with $N_\\text{conv. layers} = 5$ and $\\text{num}_\\text{kernels} = 48$ achieves a validation accuracy of 0.829 in epoch 32.\r\n\r\nThe third gird search covers the kernel sizes\r\n\\begin{align}\r\n    N_\\text{kernel} \\in \\{2, 3, 4, 5, 6\\}.\r\n\\end{align}\r\n$N_\\text{kernel} = 6$ is the biggest kernel size that can be applied on the images in the fifth convolutional layer, because the image resolution is reduced to $6\\times 6$ in this layer \r\ndue to the five previous MaxPooling layers.\r\nConsidering that we use the same kernel size in all convolutional layers, this search covers the whole parameter space for this hyperparameter given the restrictions of our network structure,\r\nas chosen so far.\r\nThe performance of the three best models can be seen in \\autoref{fig:GS3} and we conclude, that our previous choice of $N_\\text{kernel} = 4$ still performs the best \r\nwith a validation accuracy of 0.820 in epoch 32.\r\n\\begin{figure}\r\n    \\centering\r\n    \\includegraphics[width=\\textwidth]{../data/performance_plots/GS3.pdf}\r\n    \\caption{The loss and accuracy curves for the three best performing models in the third gird search.}\r\n    \\label{fig:GS3}\r\n\\end{figure}\r\nEven though the best model in this search ends up using the exact same hyperparameter values as the optimal model in the previous search, its accuracy is $\\SI{0.9}{\\percent}$ worse.\r\nThis shows, that it is not possible (or at least within the scope of this project) to make the training results completely reproducible, even though we use fixed seeds for functions using\r\nrandom numbers wherever possible. \r\nIt would make sense to use \\textit{cross-validation} to mitigate these random fluctuations, however we do not have the computing resources to do so effectively.\r\n\r\nBy now the structure of the convolutional part of our network has changed so much, that we deem it necessary to reexamine the structure of the fully-connected part of the network, \r\nas it effectively receives quite different inputs compared to when we performed the first gird search.\r\nFor this reason, we once again try out different values for $N_\\text{dense nodes}$ and check if two hidden layers still provide a better accuracy than one.\r\n\\begin{align}\r\n    N_\\text{dense layers} &\\in \\{1, 2\\}, &\r\n    N_\\text{dense nodes} &\\in \\{64, 128, 192, 256\\}\r\n\\end{align}\r\nWe omitted a single layer with $N_\\text{dense nodes} = 64$ to speed up the search, because this combination performed much worse than others during the manual hyperparameter search.\r\nThe three models achieving the best validation accuracies can be seen in \\autoref{fig:GS4}.\r\n\\begin{figure}\r\n    \\centering\r\n    \\includegraphics[width=\\textwidth]{../data/performance_plots/GS4.pdf}\r\n    \\caption{The loss and accuracy curves for the three best performing models in the fourth gird search.}\r\n    \\label{fig:GS4}\r\n\\end{figure}\r\nThe model with a single hidden layer containing $N_\\text{dense nodes} = 128$ nodes performs the best with a validation accuracy of 0.824 in epoch 44.\r\n\r\n\r\n\\subsection{Regularization}\r\nAlthough the accuracy curves do not show signs of significant overfitting (diminishing validation accuracy in later training epochs), the loss curves show, that the validation loss \r\nincreases again in later epochs. \r\nTherefore, we now try introducing some regularization to our network in an afford to further improve the networks expected performance on new data by creating redundancy within the \r\nnetwork and forcing it to generalize more.\r\n\r\nAfter implementing one \\textit{Dropout} layer between the fifth convolutional and the hidden fully-connected layer and trying different dropout rates $r_\\text{dropout}$, we do not see an \r\nimproved validation accuracy compared to no dropout.\r\nNo dropout layer is implemented between the hidden layer and the output layer, as there are too few weights between those two layers.\r\nDropout is ineffective in small layers, because too much information gets lost, when some nodes are deactivated.\r\nThe next step is using \\textit{L2-regularization} in every layer instead and testing different L2-regularization rates\r\n\\begin{align}\r\n    r_\\text{L2} \\in \\{0, \\num{1e-6}, \\num{1e-5}, \\num{1e-4}, \\num{1e-3}\\}.\r\n\\end{align}\r\nThis shows the best result when using $r_\\text{L2} = \\num{1e-5}$ as can be seen in \\autoref{fig:l2}.\r\n\r\nFinally we try combining dropout and L2 regularization by fixing $r_\\text{L2} = \\num{1e-5}$ and testing the dropout rates\r\n\\begin{align}\r\n    r_\\text{dropout} \\in \\{0, 0.1, 0.2, 0.3, 0.4\\}.\r\n\\end{align}\r\nThe loss and accuracy curves for the three best models can be seen in \\autoref{fig:l2_dropout}.\r\nThe model with $r_\\text{dropout} = 0.3$ achieves the best validation accuracy of 0.844 in epoch 57.\r\n\\begin{figure}\r\n    \\centering\r\n    \\includegraphics[width=\\textwidth]{../data/performance_plots/dropout_l2.pdf}\r\n    \\caption{The loss and accuracy curves for the three best performing models during the search for a combination of L2 and dropout regularization.}\r\n    \\label{fig:l2_dropout}\r\n\\end{figure}\r\n", "meta": {"hexsha": "3c53ef8f5bf58bc7b5273828f42b9231547a8ad3", "size": 13503, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report_lukas/content/03_ansatz.tex", "max_stars_repo_name": "LukasBeiske/project_Flowers-299", "max_stars_repo_head_hexsha": "c2315f8ad8e197c49622649d469e2dab802d8305", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report_lukas/content/03_ansatz.tex", "max_issues_repo_name": "LukasBeiske/project_Flowers-299", "max_issues_repo_head_hexsha": "c2315f8ad8e197c49622649d469e2dab802d8305", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report_lukas/content/03_ansatz.tex", "max_forks_repo_name": "LukasBeiske/project_Flowers-299", "max_forks_repo_head_hexsha": "c2315f8ad8e197c49622649d469e2dab802d8305", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.39375, "max_line_length": 204, "alphanum_fraction": 0.76227505, "num_tokens": 3344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632916317103, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.7208393482754382}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage[english]{babel}\n\\usepackage[utf8x]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage[colorinlistoftodos]{todonotes}\n\n\\title{MATH 542 Homework 1}\n\\author{Saket Choudhary\\\\skchoudh@usc.edu}\n\n\\begin{document}\n\\maketitle \n\\section*{Problem 1}\n\\begin{align*}\n\\mathbf{1}_n = \\begin{pmatrix} 1\\\\\n1\\\\\n\\vdots\\\\\n1\\\\\n\\end{pmatrix}\n\\end{align*}\n\\subsection*{Problem 1.a}\nConsider $\\mathbf{a}' = \\begin{pmatrix}a_1 & a_2 & \\dots a_n \\end{pmatrix}$\n\nThus, $$\\mathbf{a}'\\mathbf{1}_n = \\begin{pmatrix}a_1 & a_2 & \\dots a_n \\end{pmatrix} \\times \\begin{pmatrix} 1\\\\\n1\\\\\n\\vdots\\\\\n1\\end{pmatrix} = a_1 + a_2 + a_3 + \\dots a_n \n$$\n$$\n1_n'a = \\begin{pmatrix} 1 & 1 & \\dots & 1 \\end{pmatrix} \\times \\begin{pmatrix} a_1\\\\\na_2 \\\\\n\\vdots \\\\\na_n\n\\end{pmatrix} = a_1+a_2+a_3+\\dots+a_n =  \\mathbf{a'} \\mathbf{1_n}\n$$\n\\subsection*{Problem 1.b}\n\\begin{align*}\nA_n I &=  \\begin{pmatrix} a_{11} & a_{12} & \\dots & a_{1n} \\\\\na_{21} & a_{22}  & \\dots & a_{2n}\\\\\n\\vdots\\\\\na_{n1} & a_{n2} & \\dots  & a_{nn}\n\\end{pmatrix}  \\times \\begin{pmatrix} 1 \\\\\n1\\\\\n\\vdots\\\\\n1\n\\end{pmatrix} = \\begin{pmatrix} \\sum_{j=1}^n a_{ij}\\\\\n\\sum_{j=1}^n a_{2j}\\\\\n\\vdots\\\\\n\\sum_{j=1}^n a_{nj}\n\\end{pmatrix}\\\\\n&= \\text{Column vector with row sums of }A\n\\end{align*}\n\n\\subsection*{Problem 1.c}\nRow sum of $j^{th}$ column of $A = \\sum_{i=1}^na_{ij}$\n\nColumn sum of $i^{th}$ row of $A= \\sum_{j=1}^n a_{ij}$\n\n\\begin{align*}\n1_n'A &= \\begin{pmatrix} 1 & 1 & \\dots 1 \\end{pmatrix} \\times \\begin{pmatrix} a_{11} & a_{12} & \\dots & a_{1n} \\\\\na_{21} & a_{22}  & \\dots & a_{2n}\\\\\n\\vdots\\\\\na_{n1} & a_{n2} & \\dots  & a_{nn}\n\\end{pmatrix}\\\\\n&= \\begin{pmatrix} \\sum_{i=1}^n a_{i1} & \\sum_{i=1}^n a_{i2} & \\sum_{i=1}^n a_{i3}  & \\dots \\sum_{i=1}^n a_{in} \\end{pmatrix}\\\\\n&= \\text{Row vector with elements as column sums of A}\n\\end{align*}\n\n\\section*{Problem 2}\n\n\\begin{align*}\na_1 &= \\begin{pmatrix}\n2\\\\\n3\\\\\n1\n\\end{pmatrix}\\\\\nA_2 &= \\begin{pmatrix}\n1 & 2\\\\\n2 & 0\\\\\n0 & 1\\\\\n\\end{pmatrix}\\\\\nb_1' &= \\begin{pmatrix}\n1 & 1 & 1 & 0\n\\end{pmatrix}\\\\\nB_2 &= \\begin{pmatrix}\n2 & 1 & 1 & 2\\\\\n2 & 3 & 1 & 2\n\\end{pmatrix}\n\\end{align*}\n\n\\begin{align*}\nAB &= a_1b_1' + A_2B_2\n\\end{align*}\n\n\\begin{align*}\na_1b_1' &= \\begin{pmatrix}\n2 &   2 & 2 &   0\\\\\n3 &   3  &  3 &   0\\\\\n1  &  1 &   1 &   0\n\\end{pmatrix}\n\\end{align*}\n\nSimilarly,\n\\begin{align*}\nA_2B_2 &= \\begin{pmatrix}\n6 &   7 &   3 &   6\\\\\n4 &   2  &  2  &  4\\\\\n2  &  3   & 1 &   2\n\\end{pmatrix}\n\\end{align*}\n\nAnd hence $AB = a_1b_1' + A_2B_2 = \\begin{pmatrix}\n6 &   7 &   3 &   6\\\\\n4  &  2  &  2  &  4\\\\\n2  &  3 &   1 &   2\\\\\n\\end{pmatrix}$\n\\section*{Problem 3}\n$A$ is $n \\times p$\n\\subsection*{Problem 3.a}\n$AA'$ is symmetric if $AA' = A'A$\n\nProof:\n$(AA')' = (A')'A' = AA'$ and hence $AA'_{n \\times n}$ is symmetric\n\nSimilarly, for $A'A$ consider the following:\n\n$(A'A)' = A'A''  = A'A$ and hence $A'A_{p \\times p}$ is symmetric too.\n\n\\subsection*{Problem 3.b}\n\n$(A'A)_{ij} = \\sum_{k=1}^n a_{ki}a_{kj}$ and hence any diagonal element of $A'A$ is a sum of perfect squares(the case when $i=j$ $\\implies$ $(A'A)_{ii} = \\sum_{k=1}^n a_{ki}^2$)\n\nIf $\\sum_{k=1}^n a_{ki}^2 =0$ $\\implies$ $a_{ki} =0\\  \\forall 1 \\leq k \\leq n\\  \\forall i$ Hence $A$ is a zero matrix.\n\n\\section*{Problem 4}\n\\subsection*{Problem 4.a}\n\n$$A_2 = \\begin{pmatrix} 1 & 1 \\\\\n1 & 1\\\\\n1 & 0\\\\\n0 & 0\n\\end{pmatrix}$$\n\n$$A_3 = \\begin{pmatrix} 1 & 1 & 1\\\\\n1 & 1 & 0\\\\\n1 & 0 & 0\\\\\n0 & 0 & 1\n\\end{pmatrix}$$\n\n\n$$A_4 = \\begin{pmatrix} 1 & 1 & 1\\\\\n1 & 1 & 0\\\\\n1 & 0 & 0\\\\\n0 & 0 & 1\n\\end{pmatrix}$$\n\\subsection*{Problem 4.b}\nRank of $V_2$:\n\\begin{align*}\nV_2 &= \\begin{pmatrix} 1 & 1 \\\\\n1 & 1\\\\\n1 & 0\\\\\n0 & 0\n\\end{pmatrix}\\\\\n&\\stackrel{\\text{C2-C1}}{\\longrightarrow}\\begin{pmatrix} 1 & 0 \\\\\n1 & 0\\\\\n1 & -1\\\\\n0 & 0\n\\end{pmatrix}\\\\ \n\\end{align*}\nwhich cannot be reduced further, hence rank = $min(3,2) = 2$\n\nRank of  $V_3$:\n\n\\begin{align*} A_3 &= \\begin{pmatrix} 1 & 1 & 1\\\\\n1 & 1 & 0\\\\\n1 & 0 & 0\\\\\n0 & 0 & 1\n\\end{pmatrix}\\\\\n&\\stackrel{\\text{R1-R2}}{\\longrightarrow} \\begin{pmatrix} 0 & 0 & 1\\\\\n1 & 1 & 0\\\\\n1 & 0 & 0\\\\\n0 & 0 & 1\n\\end{pmatrix}\\\\\n\\end{align*}\n\nThus rank of $V_3=3$\n\n\\subsection*{Problem 4.c}\n\nBasis for $V_2$(maximising zeroes by doing a $C1-C2$ operation):  $\\big(\\begin{pmatrix} 0 & 1 & 0 \\end{pmatrix}'$, $\\begin{pmatrix} 1 & 0 & 0\\end{pmatrix}'\\big)$ \n\nBasis for $V_3$ (maximised zeroes): $\\big(\\begin{pmatrix}1 & 0 & 0 \\end{pmatrix}',\\begin{pmatrix}1 & 1 & 0 \\end{pmatrix}',\\begin{pmatrix}0 & 0 & 1 \\end{pmatrix}'\\big)$\n\n\\end{document}", "meta": {"hexsha": "9feb753777c4cec055710818941961d85fd196ba", "size": 4439, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016_Spring/MATH-542/HW01/main.tex", "max_stars_repo_name": "NeveIsa/hatex", "max_stars_repo_head_hexsha": "c5cfa2410d47c7e43a476a8c8a9795182fe8f836", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2015-09-10T02:45:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T03:20:47.000Z", "max_issues_repo_path": "2016_Spring/MATH-542/HW01/main.tex", "max_issues_repo_name": "NeveIsa/hatex", "max_issues_repo_head_hexsha": "c5cfa2410d47c7e43a476a8c8a9795182fe8f836", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-09-16T23:11:00.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-23T21:21:52.000Z", "max_forks_repo_path": "2016_Spring/MATH-542/HW01/main.tex", "max_forks_repo_name": "saketkc/hatex", "max_forks_repo_head_hexsha": "c5cfa2410d47c7e43a476a8c8a9795182fe8f836", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-09-25T19:06:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T03:21:09.000Z", "avg_line_length": 22.7641025641, "max_line_length": 177, "alphanum_fraction": 0.5812119847, "num_tokens": 2133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7207481541194263}}
{"text": "\\documentclass{memoir}\n\\usepackage{linalg}\n\n\\begin{document}\n\\section{Algebraic Operations on $\\mathcal{L}(V,W)$}\t\n\t\n\\begin{defn}[Addition and scalar multiplication on linear maps]\nSuppose $S,T \\in \\mathcal{L}(V,W)$ and $\\lambda \\in F$. The  \\textbf{sum} $S+T$ and \\textbf{product} $\\lambda T$ are the linear maps from $V \\to W$ defined by\n\\begin{align*}\n\t(S+T)(v) = Sv + Tv \\\\\n\t(\\lambda T)(v) = \\lambda(Tv)\n\\end{align*}\nfor all $v \\in V$.\n\\end{defn}\nComposition of maps is also a map; $S(T(V))$ is similar to \"multiplying\" maps.\\\\ \n\nMoreso, these compositions are associative: ($T_3 \\circ (T_2\\circ T_1) = (T_3\\circ T_2) \\circ T_1$). It also has the identity: $Id_W \\circ T = T \\circ Id_V$.\\\\\n\nFinally, it is also distributive; $T \\circ (S_1+S_2) = T\\circ S_1 + T \\circ S_2$\\\\\n\nSay $T \\in L(V,W)$, $T:V\\to W$. Suppose that $V$ is a finite-dimensional vector space. Then $T$ is \\textit{determined} by what it does to a basis of $V$ :\\\\\n\nSay $v_1,\\ldots,v_n$ is a basis for $V$. Suppose we know the output of $T(v_1),\\ldots,T(v_n)$. Then let $v \\in V$. Know $v = a_1v_1+\\ldots+a_nv_n$. Then $T(v) = T(a_1v_1+\\ldots+a_nv_n) = T(a_1v_1)+\\ldots+T(a_nv_n) = a_1T(v_1) + \\ldots + a_n T(v_n)$\\\\\n\nTherefore, we can construct $T(v)$ for any $v$ from knowledge of how $T$ applies to the basis.\n\\color{black}\n\\begin{thm}[Linear maps and basis of domain]\n\tSuppose that $w_1,\\ldots,w_n \\in W$ are arbitrary vectors and $v_1,\\ldots,v_n$ is a basis of $V$. Then there is \\textbf{exactly} one linear map $T:V\\to W$ that sends $v_i$ to $w_i$.\n\\end{thm}\nNote that \\(\\left\\{ w_i \\right\\} \\) are not necessarily linearly independent or spanning!\n\n\\section{Kernels}\n\\begin{defn}[Kernel]\n\tLet $T \\in L(V,W)$, $T:V\\to W$. The \\textbf{kernel} of $T$ is \n\n\\begin{align*}\n\t\\textrm{ker}T := \\left\\{ v \\in V \\mid T(v) = \\vec{0})W \\right\\} \n\\end{align*}\n\\end{defn}\nNote: $T(\\vec{0}_V) = \\vec{0}_W$ and so  $\\vec{0}_V \\in \\text{ker}(T) $ automatically. We also refer to the kernel by Null$(T)$ sometimes.\n\\begin{exmp}[Examples of kernels]\n\t\\begin{itemize}\n\t\t\\item The zero map obviously has a kernel of the whole set\n\t\t\\item The kernel of $\\textrm{Id}_V$ is the set $\\left\\{ \\vec{0}_V \\right\\} $\n\t\t\\item Differentiation has a kernel consisting of constants\n\t\\end{itemize}\n\\end{exmp}\n\\begin{defn}[Injective]\n\tA map is \\textbf{injective} if $T(u) = T(v) \\implies u = v$\n\nIn other words, different inputs give different outputs.\n\\end{defn}\n\\begin{prop}\n\tLet $T \\in L(V,W)$. Then $T$ is injective if and only if $\\text{ker}(T) = \\left\\{ \\vec{0}_V \\right\\} $\n\\end{prop}\n\\section{Range and Surjectivity}\n\\begin{defn}[Range/Image]\n\tFor $T$ a function from $V\\to W$, the \\textbf{range} or \\textbf{image} of $T$ is the subset of $W$ defined by:\n\t\\begin{align*}\n\t\t\\text{range} T = \\textrm{Im}T = \\{Tv \\mid v \\in V \\} .\n\t\\end{align*}\n\\end{defn}\n\\end{document}\n", "meta": {"hexsha": "6926c0eead7971b347942c5f67f4eb7275040b7d", "size": 2819, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear Algebra/Notes/source/09-25-19-Kernels.tex", "max_stars_repo_name": "gjgress/Libera-Mentis", "max_stars_repo_head_hexsha": "d9f1bfd9e6ea62a9d56292f7890f99c450b54c9b", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-07-16T23:18:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-16T23:18:15.000Z", "max_issues_repo_path": "Linear Algebra/Notes/source/09-25-19-Kernels.tex", "max_issues_repo_name": "gjgress/Libera-Mentis", "max_issues_repo_head_hexsha": "d9f1bfd9e6ea62a9d56292f7890f99c450b54c9b", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2021-05-20T22:09:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-20T23:23:22.000Z", "max_forks_repo_path": "Linear Algebra/Notes/source/09-25-19-Kernels.tex", "max_forks_repo_name": "gjgress/LibreMath", "max_forks_repo_head_hexsha": "d9f1bfd9e6ea62a9d56292f7890f99c450b54c9b", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.046875, "max_line_length": 250, "alphanum_fraction": 0.661936857, "num_tokens": 1080, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711642563823, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.7207481395746275}}
{"text": "\\section{Cohomology, Ext, cup product}\nLet $R$ be a ring, probably a PID. It's often a field, but it could be $\\Z$. Let $N$ be an $R$-module. Define $S^n(X;N)=\\Map(\\Sin_n(X),N)$. There's a boundary map $d:S^n(X;N)\\to S^{n+1}(X;N)$ that takes a cochain $f$ to the map $df$ defined by $df(\\sigma)=(-1)^{n+1}f(d\\sigma)$ where $\\sigma\\in \\Sin_{n+1}(X)$. Now, $d^2=0$, so $ H^n(X;N):= H^n(S^\\ast(X;N))$. This is a contravariant functor from $\\mathbf{Top}$ to $\\mathbf{Ab}$ and it's covariant in the coefficients. \n\nWhen $n=0$, you have $0\\to S^0(X;N)\\xrightarrow{d} S^1(X;N)$. Thus $ H^0(X;N)=\\ker d$. Well, $S^0(X;N)=\\Map(X,N)$, and $d$ sends a $0$-cochain $f$ to $\\sigma\\mapsto\\pm f(d\\sigma)=\\pm(f(\\sigma(0))-f(\\sigma(1)))$. So a function is in the kernel of $d$ if its values on the ends of any path is the same. Thus $ H^0(X;N)=\\Map(\\pi_0(X),N)$.\n\nWe also talked about the Kronecker pairing. This gave an evaluation $ H^n(X;N)\\otimes_R H_n(X;R)\\to N$. Taking the adjoint gives a map $ H^n(X;N)\\xrightarrow{\\beta}\\Hom_R( H_n(X;R),N)$. We can try to understand cohomology in terms of homology. $\\beta$'ll often be an isomorphism, but not always.\n\\begin{theorem}[UCT for cohomology]\nThere is a natural sexseq:\n\\begin{equation*}\n0\\to\\Ext^1_R( H_{n-1}(X;R),N)\\to H^n(X;N)\\xrightarrow{\\beta}\\Hom_R( H_n(X;R),N)\\to 0\n\\end{equation*}\nthat splits, but not naturally. This also holds for relative cohomology.\n\\end{theorem}\nI will tell you what $\\Ext$ means now. I will prove this on Friday.\n\nThe problem that arises is that $\\Hom_R(-,N):\\mathbf{Mod}_R\\to\\mathbf{Mod}_R$ is not exact. More precisely, it preserves right exact sequences, but not left exact sequences. Consider $M^\\prime\\xrightarrow{i} M\\xrightarrow{p} M^{\\prime\\prime}\\to 0$ an exact sequence of $R$-modules. This gives a sequence $0\\to \\Hom_R(M^{\\prime\\prime},N)\\to\\Hom_R(M,N)\\to \\Hom_R(M^{\\prime},N)$. If I have $f:M^{\\prime\\prime}\\to N$, and I compose with $p$ to get a zero map, then is $f$ zero? Well, yes, because $p$ is surjective. Now suppose I have $g:M\\to N$, such that $i\\circ g=0$. So it facts through the cokernel, and you get a unique factorization $M^{\\prime\\prime}\\to N$ (unique because $M\\to M^{\\prime\\prime}$ is surjective).\n\nSuppose I have an injection $0\\to M^\\prime\\to M$. Is $\\Hom(M,N)\\to\\Hom(M^\\prime,N)$ surjective? If I have some map $M^\\prime\\to N$ and $M^\\prime\\hookrightarrow N$, then does this extend to a map $M\\to N$? No! For example, if you have $1:\\Z/2\\Z\\to\\Z/2\\Z$ and $\\Z/2\\Z\\hookrightarrow\\Z/4\\Z$, then you can't lift to a map $\\Z/4\\Z\\to\\Z/2\\Z$. This works, though, if the sexseq splits.\n\nHomological algebra now comes to the rescue! Pick a free resolution of $M$ given by $\\cdots\\to F_2\\to F_1\\to M\\to F_0\\to 0$. If I apply $\\Hom$, I get a chain complex $0\\to \\Hom(F_0,N)\\to \\Hom(F_1,N)\\to \\Hom(F_2,N)\\to\\cdots$.\n\\begin{definition}\nDefine $\\Ext_R^n(M,N)= H^n(\\Hom_R(F_\\bullet,N))$ as the $n$-dimensional homology of this chain complex.\n\\end{definition}\n\\begin{remark}\nIf $R$ is a PID, then $\\Ext^n=0$ if $n>1$. If $R$ is a field, then $\\Ext^n=0$ for $n>0$. Also, $\\Ext$ is well-defined and functorial (by the fundamental theorem of homological algebra). Another important point is that $\\Hom_R(-,N)$ takes chain homotopies to chain homotopies. This is a pretty important thing, and is something to think about for a minute. This is because if I have $M^\\prime\\to M$, I get an induced map $\\Hom_R(M^\\prime,N)\\leftarrow\\Hom_R(M,N)$, and this is actually an $R$-module map, and in particular, additive. And this means that the $dh-hd=f_1-f_0$ is preserved. Lastly, if $M$ is free or projective, then $\\Ext^n(M,-)=0$ for $n>0$. In addition, $\\Ext^0(M,N)=\\Hom_R(M,N)$.\n\\end{remark}\nRecall the trick that if I have a sexseq $0\\to A\\to B\\to C\\to 0$, and I have free resolutions $F^\\prime_\\bullet\\to A$ and $F^{\\prime\\prime}_\\bullet\\to 0$, I can get a free resolution $F_\\bullet\\to B$ to get a sexseq $0\\to F^\\prime_\\bullet\\to F_\\bullet\\to F^{\\prime\\prime}_\\bullet\\to 0$. I can now apply $\\Hom_R(-,N)$ to get a sexseq of cochain complexes, because this sequence splits in any given degree. Thus, I get a lexseq:\n\\begin{equation*}\n\\xymatrix{ & & 0\\ar[dll]\\\\\n\\Hom_R(M^{\\prime\\prime},N)\\ar[r] & \\Hom_R(M,N)\\ar[r] & \\Hom_R(M^{\\prime},N)\\ar[dll]\\\\\n\\Ext^1_R(M^{\\prime\\prime},N)\\ar[r] & \\Ext^1_R(M,N)\\ar[r] & \\Ext^1_R(M^{\\prime},N)\\ar[dll]\\\\\n\\cdots & &}\n\\end{equation*}\nIn this sense, $\\Ext$ is like a cohomology theory for $R$-modules.\n\nLet us use this to make a calculation.\n\\begin{example}\nLet $R=\\Z$, and look at the sexseq $0\\to \\Z\\xrightarrow{k}\\Z\\to\\Z/k\\Z\\to 0$. Here $N$ is some abelian group. So, our lexseq will look like:\n\\begin{equation*}\n\\xymatrix{ & & 0\\ar[dll]\\\\\n\\Hom_R(\\Z/k\\Z,N)\\ar[r] & \\Hom_R(\\Z,N)=N\\ar[r] & \\Hom_R(\\Z,N)=N\\ar[dll]\\\\\n\\Ext^1_R(\\Z/k\\Z,N)\\ar[r] & 0\\ar[r] & 0\\ar[dll]\\\\\n\\cdots & &}\n\\end{equation*}\nThe map $N\\to N$ in this lexseq is multiplication by $k$. Thus $\\Hom(\\Z/k\\Z,N)=\\ker(N\\xrightarrow{k}N)$. And, well, $\\Ext^1_\\Z(\\Z/k\\Z,N)=N/kN$.\n\\end{example}\nLet's get some consequences of cohomology from the UCT. Even independent of that, we get some properties.\n\\subsection{Properties of cohomology}\n\\begin{enumerate}\n\\item It's homotopy invariant. This means that if $f_0\\sim f_1:(X,A)\\to (Y,B)$, then $ H^\\ast(X,A;N)\\xleftarrow{f_0^\\ast,f_1^\\ast} H^\\ast(Y,B;N)$ are equal. I can't use the UCT to address this because the UCT only tells you that things are isomorphic (use the 5-lemma). But we did establish a chain homotopy $f_{0,\\ast}\\sim f_{1,\\ast}:S_\\ast(X,A)\\to S_\\ast(Y,B)$, and applying $\\Hom$ still retains this chain homotopy, and hence you get the same map on cohomology.\n\\item Excision. If $U\\subseteq A\\subseteq X$ such that $\\overline{U}\\subseteq\\mathrm{Int}(A)$, then $ H^\\ast(X,A;N)\\leftarrow H^\\ast(X-U,A-U;N)$ is an isomorphism. This follows from the UCT (in the relative form, which is also true).\n\\item Mayer-Vietoris sequence. If I have $A,B\\subseteq X$ such that their interiors cover $X$, then I have an lexseq:\n\\begin{equation*}\n\\xymatrix{ & & \\cdots\\ar[dll]\\\\\n H^n(X;N)\\ar[r] & H^n(A;N)\\oplus H^n(B;N)\\ar[r] & H^n(A\\cap B;N)\\ar[dll]\\\\\n H^{n+1}(X;N)\\ar[r] & \\cdots & }\n\\end{equation*}\n\\end{enumerate}\n", "meta": {"hexsha": "b5a5a907f548c2ef65d763cce2a4c8173afd7920", "size": 6130, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-27-ext-cup-product.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "old-905/lec-27-ext-cup-product.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "old-905/lec-27-ext-cup-product.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 103.8983050847, "max_line_length": 715, "alphanum_fraction": 0.6763458401, "num_tokens": 2237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603725, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.720703042875574}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel} \n\\usepackage{amsmath,amssymb,amsthm}\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{corollary}{Corollary}[theorem]\n\\newtheorem{lemma}[theorem]{Lemma}\n\\title{Mathematics Handout - Logaritmics}\n\\author{Daniel Frederico Lins Leite}\n\\date{July 2016}\n\\begin{document}\n\\section{Introduction}\n\\maketitle\n\n\\[{x_n}\\] is a sequence of real numbers\nTh sequence converge if:\n$$\\exists a \\in Re$$\n$$\\exists \\epsilon \\in R such that \\epsilon > 0$$\n$$\\exists N_a \\in I such that N_a > 0$$\n$$\\forall n > N_a, |a - x_n| < \\epsilon$$\n\nif for example exists another \n$$\\exists b \\in Re$$ such that\n$$\\exists N_b \\in I such that N_b > 0$$\n$$\\forall n > N_b, |b - x_n| < \\epsilon$$\n\nthen \n\n$$|a-b| = |a - x_n + x_n - b|$$\n\nGiven that the $$R^n$$, the space of the elements of the sequence is a normed vector space, we can apply the Triangle Inequality. So\n\n$$|a - x_n + x_n - b| <= |a - x_n| + |x_n - b|$$\n\ngiven that $$|x_n - b|$$ is a even function\n$$f(x) = f(-x)$$ we have that\n$$|x_n - b| = -1 * |x_n - b| = |-x_n + b| = |b - x_x|$$\n\nso we have\n\n$$|a - x_n| + |x_n - b| < |a - x_n| + |b - x_n| <= \\epsilon + \\epsilon <= 2\\epsilon$$\n\nSo\n\n$$ 0 <= |a - b| <= 2\\epsilon$$ \n\nSo $|a-b|$ is squeezed between this two function. Given that this is true for every $\\epsilon$, if $\\epsilon -> 0$\nwe will have that:\n$$|a-b| = 0$$ and $$a=b$$\n\nThe value a is called the limit of the sequence.\n\nThe \n\n$$S = \\sum_{i=0}^{\\inf} {x_i}$$ is called the series associated with se sequence.\n\nThe partial sum is\n\n$$S_n = \\sum_{i=0}^{n} {x_i}$$\n\nSo\n\n${S_n}$ is also a sequence. In the same way it can converge and have a limit.\nIf the sequence converge, we say that the series converge and that the limit is\n\n$$limit of {S_n} =  \\sum_{i=0}^{\\inf} {x_i}$$\n\nIf we have two convergent series:\n\n$$S_1 = \\sum_{i=0}^{\\inf} {a_i}$$\n$$S_2 = \\sum_{i=0}^{\\inf} {b_i}$$\n\nthen\n\n$$\\sum_{i=0}^{\\inf} {(a_i + b_i)} = \\sum_{i=0}^{\\inf} {a_i} + \\sum_{i=0}^{\\inf} {b_i}$$\n\n\n\n\n\n\n\\end{document}", "meta": {"hexsha": "82f6c04e8a8a9d8d5479e1affe234a1fb853efe8", "size": 2017, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "texts/math/Handout.Series.tex", "max_stars_repo_name": "xunilrj/sandbox", "max_stars_repo_head_hexsha": "f92c12f83433cac01a885585e41c02bb5826a01f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2017-04-01T17:18:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-12T05:23:23.000Z", "max_issues_repo_path": "texts/math/Handout.Series.tex", "max_issues_repo_name": "xunilrj/sandbox", "max_issues_repo_head_hexsha": "f92c12f83433cac01a885585e41c02bb5826a01f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2020-05-24T13:36:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-15T06:44:20.000Z", "max_forks_repo_path": "texts/math/Handout.Series.tex", "max_forks_repo_name": "xunilrj/sandbox", "max_forks_repo_head_hexsha": "f92c12f83433cac01a885585e41c02bb5826a01f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-09-20T01:07:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-22T14:55:38.000Z", "avg_line_length": 24.5975609756, "max_line_length": 132, "alphanum_fraction": 0.6232027764, "num_tokens": 757, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603725, "lm_q2_score": 0.8519528000888387, "lm_q1q2_score": 0.7207030381057988}}
{"text": "\\section{Fundamental Concepts}\n\n\\bx{\n  We will check $\\cup, \\cap$ in DeMorgan's laws.\n\n  Let's use\n  \\begin{itemize}\n    \\item $A = \\pbrac{1, 2, 3, 4}$\n    \\item $B = \\pbrac{-1, 2, 3, 5}$\n    \\item $C = \\pbrac{3, 9, 11}$\n  \\end{itemize}\n\n  Check\n  \\begin{align*}\n    A - (B \\cup C) &= \\pbrac{1, 2, 3, 4}  - \\pbrac{-1, 2, 3, 5, 9, 11}\\\\\n    &= \\pbrac{1, 4} \\\\\n    &= (A - B) \\cap (A - C) \\\\\n    &= \\pbrac{1, 4} \\cap \\pbrac{1, 2, 4} = \\pbrac{1, 4}\n  \\end{align*}\n\n  \\begin{align*}\n    A - (B \\cap C) &= \\pbrac{1, 2, 3, 4}  - \\pbrac{3}\\\\\n    &= \\pbrac{1, 2, 4} \\\\\n    &= (A - B) \\cup (A - C) \\\\\n    &= \\pbrac{1, 4} \\cup \\pbrac{1, 2, 4} = \\pbrac{1, 2, 4}\n  \\end{align*}\n}\n\n\\bx{\n  \\ea{\n    \\item $\\implies$ is true. $\\impliedby$ is not true, consider $A = \\pbrac{1, 2, 3}, B = \\pbrac{1, 3}, C = \\pbrac{2}$.\n    \\item $\\implies$ is true. $\\impliedby$ is not true, consider $A = \\pbrac{1, 2, 3}, B = \\pbrac{1, 3}, C = \\pbrac{2}$.\n    \\item True.\n    \\item $\\implies$ is not true. Consider $A = \\pbrac{1} \\subset B = \\pbrac{1, 2}, C = \\emptyset$. $\\impliedby$ is true.\n    \\item Not true. Consider $A = \\pbrac{1}, B = \\pbrac{2}$. I think $\\subset$ works.\n    \\item Not true. Consider $A = \\pbrac{1, 2}, B = \\pbrac{2, 3}$. LHS is equivalent to $A$, so this should be $\\supset$.\n    \\item True.\n    \\item $\\supset$\n    \\item True.\n    \\item True.\n    \\item Not true, if $A = \\emptyset$ for example, we have $(A \\times B)\n    \\subset (C \\times D) = \\emptyset \\subset (C \\times D)$, but we can set $B$\n    to whatever and this statement is still true, so we can make $B$ have an\n    element that is not in $D$, and therefore $B \\not\\subset D$.\n    \\item True.\n    \\item $\\subset$\n    \\item $\\subset$\n    \\item True.\n    \\item I think this is true at first glance...at least $\\subset$ looks good.\n    \\item $\\supset$\n  }\n}\n\n\\bx{\n  \\ea{\n    \\item\n    \\begin{itemize}\n      \\item \\textbf{Original}: If $x < 0$ then $x^2 - x > 0$. True.\n      \\item \\textbf{Contrapositive}: If $x^2 - x \\leq 0$ then $x \\geq 0$. True.\n      \\item \\textbf{Converse}: If $x^2 - x > 0$ then $x < 0$. False.\n    \\end{itemize}\n\n    \\begin{figure}[H]\n      \\centering\n      \\def\\domainSize{3}\n      \\begin{tikzpicture}\n        \\begin{axis}[\n          axis y line = middle,\n          axis x line = middle,\n        ]\n\n        \\addplot[\n          domain=-\\domainSize:\\domainSize,\n          samples=100\n        ]{\n          x^2 - x\n        };\n\n        \\end{axis}\n      \\end{tikzpicture}\n      \\caption{Showing how to visualize where $x^2 - x > 0 $}\n      \\label{chap1:fig:parabola}\n    \\end{figure}\n\n    \\item\n    \\begin{itemize}\n      \\item \\textbf{Original}: If $x > 0$ then $x^2 - x > 0$. False.\n      \\item \\textbf{Contrapositive}: If $x^2 - x \\leq 0$ then $x \\leq 0$. False.\n      \\item \\textbf{Converse}: If $x^2 - x > 0$ then $x > 0$. False.\n    \\end{itemize}\n  }\n}\n\n\\bx{\n  \\ea{\n    \\item $\\exists a \\in A$ such that $a^2 \\not\\in B$\n    \\item $\\forall a \\in A, a^2 \\not\\in B$\n    \\item $\\exists a \\in A$ such that $a^2 \\in B$.\n    \\item $\\exists a \\not\\in A$ such that $a^2 \\not\\in B$.\n  }\n}\n\n\\bx{\n  \\ea{\n    \\item True. True.\n    \\item False. True.\n    \\item True. False.\n    \\item True. True.\n  }\n}\n\n\\bx{\n  \\TODO too lazy\n}\n\n\\bx{\n  \\begin{align*}\n    D &= A \\cap (B \\cup C) \\\\\n    E &= (A \\cap B) \\cup C \\\\\n    F &= A\n  \\end{align*}\n\n  For $F$, I was thinking $x \\in B \\implies x \\in C$ means that either $x \\in B$\n  and $x \\in C$, or $x \\not\\in B$ and $x$ can be anything. This sounds like $x$\n  can be anything in the second case, so we have $A \\cap \\mathcal{U} = A$.\n}\n\n\\bx{\n  $A = \\pbrac{0, 1}$. $\\mathcal{P}(A) = \\pbrac{\\emptyset, \\pbrac{0}, \\pbrac{1}, \\pbrac{0, 1}}$.\n\n  If $A$ has one element, $\\abs{\\mathcal{P}(A)} = 2$. It is called the power set\n  because it contains all the subsets of $A$, and that $\\abs{\\mathcal{P}(A)} =\n  2^\\abs{A}$.\n}\n\n\\bx{\n  \\TODO: You can honestly find this everywhere online. Standard proof.\n}\n\n\\bx{\n  \\ea{\n    \\item $\\mathbb{Z} \\times \\mathbb{R}$\n    \\item $\\mathbb{R} \\times \\left(0, 1\\right]$\n    \\item No. You can do a contradiction proof with cases that the first and second set are disjoint, and then that they are not disjoint.\n    \\item Yes, $\\pa{\\mathbb{R} - \\mathbb{Z}} \\times \\mathbb{Z}$\n    \\item No. The cartesian product will produce a box, while this set is a circle.\n  }\n}", "meta": {"hexsha": "0efc2d97b067b278134f4ca7d808b82de15f94f2", "size": 4289, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter1/chapter1-1.tex", "max_stars_repo_name": "mikinty/Topology-Munkres-Solutions", "max_stars_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2021-07-02T05:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T04:11:03.000Z", "max_issues_repo_path": "chapters/chapter1/chapter1-1.tex", "max_issues_repo_name": "mikinty/Topology-Munkres-Solutions", "max_issues_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter1/chapter1-1.tex", "max_forks_repo_name": "mikinty/Topology-Munkres-Solutions", "max_forks_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.9797297297, "max_line_length": 138, "alphanum_fraction": 0.5409186291, "num_tokens": 1727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245617, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.7207030264599463}}
{"text": "\\input{../header_function}\r\n\r\n%---------- start document ---------- %\r\n \\section{factor.find -- find a factor}\\linkedzero{factor.find}\r\n%\r\n\\quad All methods in this module return one of a factor of given integer.\r\nIf it failes to find a non-trivial factor, it returns \\(1\\).\r\nNote that \\(1\\) is a factor anyway.\r\n\r\n\\param{verbose} boolean flag can be specified for verbose reports.\r\nTo receive these messages, you have to prepare a logger (see \\linklibrary{logging}).\r\n\r\n  \\subsection{trialDivision -- trial division}\\linkedone{factor.find}{trialDivision}\r\n   \\func{trialDivision}\r\n   {%\r\n     \\hiki{n}{integer},\\ %\r\n     **\\param{options}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return a factor of \\param{n} by trial divisions.\\\\\r\n   \\spacing\r\n   % input, output document\r\n   \\quad \\param{options} can be either one of the following:\r\n   \\begin{enumerate}\r\n   \\item \\param{start} and \\param{stop} as range parameters.\r\n         In addition to these, \\param{step} is also available.\r\n   \\item \\param{iterator} as an iterator of primes.\r\n   \\end{enumerate}\r\n   If \\param{options} is not given, the function divides \\param{n} by primes from \\(2\\) to the floor of the square root of \\param{n} until a non-trivial factor is found.\\\\\r\n   \\quad \\param{verbose} boolean flag can be specified for verbose reports.\\\\\r\n%\r\n  \\subsection{pmom -- $p-1$ method}\\linkedone{factor.find}{pmom}\r\n   \\func{pmom}{%\r\n     \\hiki{n}{integer},\\ %\r\n     **\\param{options}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return a factor of \\param{n} by the \\(p-1\\) method.\\\\\r\n   \\spacing\r\n   % added document\r\n   \\quad The function tries to find a non-trivial factor of \\param{n}\r\n   using Algorithm 8.8.2 (\\(p-1\\) first stage) of \\cite{Cohen1}.\r\n   In the case of \\(n = 2^{i}\\), the function will not terminate.\r\n   Due to the nature of the method, the method may return the\r\n   trivial factor only.\\\\\r\n   \\spacing\r\n   % input, output document\r\n   \\quad \\param{verbose} Boolean flag can be specified for verbose reports,\r\n   though it is not so verbose indeed.\\\\\r\n%\r\n   \\subsection{rhomethod -- $\\rho$ method}\\linkedone{factor.find}{rhomethod}\r\n   \\func{rhomethod}{%\r\n     \\hiki{n}{integer},\\ %\r\n     **\\param{options}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return a factor of \\param{n} by Pollard's \\(\\rho\\) method.\\\\\r\n   \\spacing\r\n   % added document\r\n   The implementation refers the explanation in \\cite{Pomerance}.\r\n   Due to the nature of the method, a factorization may return the\r\n   trivial factor only.\\\\\r\n   \\spacing\r\n   % input, output document\r\n   \\quad \\param{verbose} Boolean flag can be specified for verbose reports.\\\\\r\n\\begin{ex}\r\n>>> factor.find.trialDivision(1001)\r\n7\r\n>>> factor.find.trialDivision(1001, start=10, stop=32)\r\n11\r\n>>> factor.find.pmom(1001)\r\n91\r\n>>> import logging\r\n>>> logging.basicConfig()\r\n>>> factor.find.rhomethod(1001, verbose=True)\r\nINFO:nzmath.factor.find:887 748\r\n13\r\n\\end{ex}%Don't indent!(indent causes an error.)\r\n\\C\r\n\r\n%---------- end document ---------- %\r\n\r\n\\input{../footer}\r\n", "meta": {"hexsha": "8257b8ecddf5be5d2be2dc112cb54bced490da93", "size": 3151, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/en/factor.find.tex", "max_stars_repo_name": "turkeydonkey/nzmath3", "max_stars_repo_head_hexsha": "a48ae9efcf0d9ad1485c2e9863c948a7f1b20311", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-26T19:22:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T19:22:17.000Z", "max_issues_repo_path": "manual/en/factor.find.tex", "max_issues_repo_name": "turkeydonkey/nzmath3", "max_issues_repo_head_hexsha": "a48ae9efcf0d9ad1485c2e9863c948a7f1b20311", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "manual/en/factor.find.tex", "max_forks_repo_name": "turkeydonkey/nzmath3", "max_forks_repo_head_hexsha": "a48ae9efcf0d9ad1485c2e9863c948a7f1b20311", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.8817204301, "max_line_length": 172, "alphanum_fraction": 0.6490003174, "num_tokens": 869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.8459424295406087, "lm_q1q2_score": 0.7207030136114512}}
{"text": "\\chapter{Clustering}\n\\newpage\n\n\n\\section{K-Means}\n\\begin{itemize}\n    \\item Dataset: $H=\\{x^{(1)},x^{(2)},\\dots,x^{(n)}\\}$\n    \\item $d$ dimensions\n    \\item Want to divide $H$ into disjoint subsets $\\{H_1,H_2,\\dots,H_c\\}$\n\\end{itemize}\n\n\\subsection{Objective Function}\nFind an assignment such that the samples in the same class are as close to each other as possible.\n\\[ J_c \\triangleq \\sum_{i=1}^c\\sum_{x\\in H_i} \\|x-m_i\\|^2 \\]\nwhere $m_i$ is the centroid of each class.\n\n\\subsection{Before K-Means}\nLet\n\\[ J_i = \\sum_{x\\in H_i}\\|x-m_i\\|^2 \\]\n\n\\subsubsection{Framework}\n\\begin{enumerate}\n    \\item Initialize\n    \\item Re-assign data samples to make the loss smaller.\n\\end{enumerate}\n\n\\subsubsection{Update Rule}\nSuppose a sample $\\hat{x}$ is moved from $H_i$ to $H_j$. Let $n_j$ be the number of samples in $H_j$.\n\\[ m^*_j = \\frac{n_jm_j + \\hat{x}}{n_j+1} = m_j - m_j + \\frac{n_jm_j + \\hat{x}}{n_j+1} = m_j + \\frac{\\hat{x}-m_j}{n_j+1} \\]\n\\[ m^*_i = \\frac{n_im_i - \\hat{x}}{n_i-1} = m_i + \\frac{m_i - \\hat{x}}{n_i-1} \\]\n\n\\begin{align*}\n    J_j^* & = \\sum_{x\\in H_j}\\| x-m_j^* \\|^2 + \\| \\hat{x} - m_j^* \\|^2                                                \\\\\n          & = \\sum_{x\\in H_j}\\|x-m_j-\\frac{\\hat{x}-m_j}{n_j+1}\\|^2 + \\| \\frac{n_j}{n_j+1}(\\hat{x}-m_j) \\|^2           \\\\\n          & = \\sum_{x\\in H_j} \\| x - m_j \\|^2 - \\frac{2}{n_j+1}\\sum_{x\\in H_j}(\\hat{x}-m_j)^T(x-m_j)                  \\\\\n          & \\quad + \\frac{1}{(n_j+1)^2}\\sum_{x\\in H_j}\\| \\hat{x} -m_j \\|^2 + \\frac{n_j^2}{(n_j+1)^2}\\|\\hat{x}-m_j\\|^2 \\\\\n          & = J_j + \\frac{n_j}{(n_j+1)^2}\\|\\hat{x}-m_j\\|^2 + \\frac{n_j^2}{(n_j+1)^2}\\|\\hat{x}-m_j\\|^2\n\\end{align*}\nNotice that the second term is $0$ and the $\\|\\hat{x}-m_j\\|^2$ in the first term is constant w.r.t. $x$ in the summation.\n\nTherefore\n\\[ J^*_j = J_j + \\frac{n_j}{n_j+1}\\|\\hat{x}-m_j\\|^2 \\]\n\\[ J^*_i = J_i - \\frac{n_i}{n_i-1}\\|\\hat{x}-m_i\\|^2 \\]\n\n\\subsubsection{Convergence}\nAlways converges, because the loss function is always decreasing and has a lower bound $0$.\n\nBut it is SLOW.\n\n\\subsection{K-Means}\n\\subsubsection{Procedure}\n\\begin{enumerate}\n    \\item Update centroids\n    \\item Re-assign points\n\\end{enumerate}\n\n\\subsubsection{Mathematical Framework}\nLet $r_{ik} \\in \\{0,1\\}$ denote that the $i$-th sample is classified into the $k$-th class. $\\sum_kr_{ik} = 1$. Then the loss function is\n\\[ J = \\sum_i \\sum_k \\| x_i - m_k \\|r_{ik} \\]\n\n\\subsubsection{Convergence Analysis}\nIn E-Step, the loss always goes down because each sample finds the nearest centroid.\n\\[ J_c^{(old)} = \\sum_i\\sum_kr_{ik}^{(old)}\\|x_i-m_k\\| \\ge \\sum_i\\sum_k\\|x_i-m_k\\|r_{ik}^{(new)} = J_c^{(new)} \\]\n\nIn M-Step,\n\\begin{align*}\n    J_c^k(old) & = \\sum_{i\\in H_k}\\|x_i - m_k^{(old)}\\|^2                               \\\\\n               & = \\sum_{i\\in H_k}\\| x_i - m_k^{(new)} + m_k^{(new)} - m_k^{(old)} \\|^2 \\\\\n               & = \\sum_{i\\in H_k} \\|x_i - m_k^{(new)}\\|^2                              \\\\\n               & \\quad + \\sum_{i\\in H_k}\\|m_k^{(old)} - m_k^{(new)}\\|^2                 \\\\\n               & \\quad + \\sum_{i\\in H_k}(x_i-m_k^{(new)})^T(m_k^{(old)}-m_k^{(new)})\n\\end{align*}\nThe first term is $J_c^k(new)$, the second term is non-negative and the third term is zero.\n\n\\subsubsection{Remarks}\n\\begin{itemize}\n    \\item Generally K-Means has good performance.\n    \\item Initialization matters.\n    \\item The choice of $k$ matters.\n\\end{itemize}\n\n\\subsection{Agglomerative Clustering}\n\\begin{enumerate}\n    \\item Initialize: everypoint is its own cluster.\n    \\item Find the most similar pair of clusters.\n    \\item Merge.\n\\end{enumerate}\n\n\n\\section{Gaussian Mixture Model}\n    K-Means can be easily affected by outliers.\n\n    \\subsection{Multivariate Gaussian Distribution}\n        \\[ p(x) = \\frac{1}{(2\\pi|\\Sigma|)^{d/2}}\\exp\\left\\{ -\\frac{1}{2}(x-\\mu)^T\\Sigma^{-1}(x-\\mu) \\right\\} \\]\n\n    \\subsection{Gaussian Mixture Model}\n        Suppose the data has a distribution that can be modeled by the weighted sum of $K$ Gaussian distributions. Let $\\pi_k = p(x=k)$ be the likelihood of the $k$-th Gaussian.\n        \\[ p(x) = \\sum_{k=1}^Np(x=k)p(x|k) = \\sum_{k=1}^K\\pi_k \\mathcal{N}(x|\\mu_k,\\Sigma_k) \\]\n\n        So the parameters of a GMM are\n        \\begin{itemize}\n            \\item $\\pi_k$\n            \\item $\\mu_k$\n            \\item $\\Sigma_k$\n        \\end{itemize}\n\n        Given the parameters of a GMM, the probabilities can be calculated.\n        \\begin{itemize}\n            \\item Prior: $p(x=k)=\\pi_k$\n            \\item Likelihood: $p(x|x=k)=\\mathcal{N}(x|\\mu_k,\\Sigma_k)$\n            \\item Joint Distribution: $p(x,x=k)=p(x=k)p(x|x=k)=\\pi_k\\mathcal{N}(x|\\mu_k,\\Sigma_k)$\n            \\item Evidence: $p(x) = \\sum_{k=1}^Kp(x,x=k)=\\sum_{k=1}^K\\pi_k\\mathcal{N}(x|\\mu_k,\\Sigma_k)$\n            \\item Posterior: $p(x=k|x)=\\frac{p(x,x=k)}{p(x)}=\\frac{\\pi_k\\mathcal{N}(x|\\mu_k,\\Sigma_k)}{\\sum_{i=1}^K\\pi_i\\mathcal{N}(x|\\mu_i,\\Sigma_i)}$\n        \\end{itemize}\n\n    \\subsection{Estimating Parameters}\n        Clustering using a GMM is simply estimating the parameters of the model.\n\n        Suppose we have a dataset $D = \\{x^{(1)},x^{(2)},\\dots,x^{(N)}\\}$. We maximize the log likelihood\n        \\[ \\mathcal{L}(\\theta) = \\ln p(D|\\theta) = \\sum_{n=1}^N\\ln\\left\\{\\sum_{k=1}^K\\pi_k\\mathcal{N}(x^{(n)}|\\mu_k,\\Sigma_k)\\right\\} \\]\n\n        However, traditional MLE methods do not work due to the complexity of $\\mathcal{L}$. To illustrate this, we take derivative w.r.t. $\\mu_k$\n        \\[ \\frac{\\partial \\mathcal{L}}{\\partial \\mu_k} = -\\sum_{n=1}^N\\frac{\\pi_k\\mathcal{N}(x^{(n)}|\\mu_k,\\Sigma_k)}{\\sum_j\\pi_j\\mathcal{N}(x^{(n)}|\\mu_j,\\Sigma_j)}\\Sigma_k^{-1}(x_n-\\mu_k) \\]\n        but we cannot derive a closed-form solution of $\\mu_k$.\n\n        Instead, this is an exponential function that can be solved by iterative numerical methods, let\n        \\[ \\gamma(z_{nk}) = \\frac{\\pi_k\\mathcal{N}(x^{(n)}|\\mu_k,\\Sigma_k)}{\\sum_j\\pi_j\\mathcal{N}(x^{(n)}|\\mu_j,\\Sigma_j)} \\]\n        \\[ N_k = \\sum_{n=1}^N \\gamma(z_{nk}) \\]\n\n        To solve for $\\mu_k$, we run multiple iterations, in each iteration, we first fix $\\theta = (\\pi_k,\\mu_k,\\Sigma_k)$ and update $\\gamma(z_{nk})$, and then fix $\\gamma(z_{nk})$ and update $\\theta$.\n\n        \\subsubsection{Estimating Mean and Covariance Matrix}\n        Using previous conclusions,\n        \\[ \\mu_k = \\frac{1}{N_k}\\sum_{n=1}^N\\gamma(z_{nk})x^{(n)} \\]\n        Similarly if we solve for $\\Sigma_k$,\n        \\[ \\Sigma_k = \\frac{1}{N_k}\\sum_{n=1}^N\\gamma(z_{nk})(x^{(n)}-\\mu_k)(x^{(n)}-\\mu_k)^T \\]\n\n        \\subsubsection{Estimating Mixture Coefficients}\n        Notice that $\\sum_k\\pi_k = 1$, so maximizing w.r.t. $\\pi_k$ is an ECP.\n\n        The solution is given by\n        \\[ \\pi_k = \\frac{N_k}{N} \\]\n\n    \n\\section{Spectral Clustering}\n    K-Means and GMM may have poor performance when the data is non-convex.\n    \n    \\subsection{Graph-based Clustering}\n        We use a graph $G=(V,E)$ to represent the dataset. Each sample is a node in $V$ and each edge has a weight $w_{ij}=f(d(i,j))$.\n\n        \\begin{enumerate}\n            \\item Construct the graph\n            \\item Perform edge cuts.\n        \\end{enumerate}\n\n    \\subsection{Graph Cut}\n        \\subsubsection{Definitions and Notations}\n            \\begin{itemize}\n                \\item Degree of a node $d_i = \\sum_{j\\in \\mathcal{N}(i)}w_{ij}$.\n                \\item Degree of a subgraph $A_i = \\sum_{i \\in A}d_i$. There are two cases.\n                    \\begin{itemize}\n                        \\item $i \\in A$, $j \\in A$. In this case $w_{ij}$ is counted twice.\n                        \\item $i \\in A$, $j \\notin A$. In this case $w_{ij}$ is counted once.\n                    \\end{itemize}\n                \\item Cut of a graph $Cut(A, B) = \\sum_{i \\in A}\\sum_{j \\in B}w_{ij}$.\n            \\end{itemize}\n\n        We minimize\n        \\[ \\min Cut(A_1,A_2,\\dots,A_k) \\]\n\n        However, the algorithm may favor isolated clusters and outliers.\n\n        Can be mitigated by normalizing edge cuts.\n        \\[ NCut(A,B) = \\frac{Cut(A,B)}{d_A} + \\frac{Cut(A,B)}{d_B}\\]\n        Works. But it's NP-hard.\n\n    \\subsection{Optimizing Graph Cuts}\n        \\subsubsection{More Notations}\n            \\begin{itemize}\n                \\item Degree matrix $D_{ij} = \\text{$d_i$ if $i=j$ else $0$}$\n                \\item $L=D-W$\n                \\item Define an indicator vector $x$. $x_i = 1$ if $i \\in A$ and $x_i=0$ if $i \\notin A$, i.e. $i \\in B = V-A$. $x$ is unknown and we want to find $x$.\n            \\end{itemize}\n\n        We can represent $d_A$ and $d_B$ in matrix form\n        \\[ d_A = \\sum_{i\\in A}d_i = \\sum_i d_ix_i = x^TDx \\]\n        \\[ d_B = \\bar{x}^TD\\bar{x} \\]\n        where $\\bar{x}$ is the bitwise NOT of $x$.\n\n        \\[ Cut(A, V-A) = \\sum_{i\\in A}\\sum_{j\\in B}w_{ij} = \\sum_{i \\in A}d_i - \\sum_{i \\in A}\\sum_{j \\in A}w_{ij} = x^TDx - x^TWx = x^TLx \\]\n\n        Therefore\n        \\begin{align*}\n            \\min_x &\\quad x^TLx\\\\\n            \\text{s.t.} &\\quad x^TDx \\ge \\delta\n        \\end{align*}\n\n        Can be solved by Lagrangian multipliers\n        \\[ \\mathcal{L}(x, \\lambda_A, \\lambda_B) = x^TLx - \\lambda_A(x^TDx-\\delta) \\]\n        \\[ D^{-1}Lx = \\lambda_A x \\]\n        So we find the eigenvector of $D^{-1}L$ and take approximations to make elements of $x$ either $0$ or $1$.\n\n        \\subsubsection{Procedure}\n            \\begin{enumerate}\n                \\item Normalize $L = D^{-1/2}LD^{-1/2}$\n                \\item Compute the smallest $k_1$ eigenvalues and corresponding eigenvectors.\n                \\item Use eigenvectors to construct $N$ by $k_1$ matrix $P$.\n                \\item Use $P$ as the new input of some other clustering algorithm, where each sample has $k_1$ dimension.\n            \\end{enumerate}\n\n        \\subsubsection{Strengths and Weaknesses}\n        \\begin{itemize}\n            \\item Can handle non-convex datasets.\n            \\item Runs into trouble when new data samples comes. Cannot be easily extended.\n        \\end{itemize}\n", "meta": {"hexsha": "66635139fb313f8157e23fb540f4738f0283354d", "size": 9881, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Machine Learning/Clustering.tex", "max_stars_repo_name": "YBRua/CourseNotes", "max_stars_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-20T10:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T08:15:15.000Z", "max_issues_repo_path": "Machine Learning/Clustering.tex", "max_issues_repo_name": "YBRua/CourseNotes", "max_issues_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Machine Learning/Clustering.tex", "max_forks_repo_name": "YBRua/CourseNotes", "max_forks_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T11:31:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T11:31:00.000Z", "avg_line_length": 45.7453703704, "max_line_length": 203, "alphanum_fraction": 0.5702864083, "num_tokens": 3391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055544, "lm_q2_score": 0.8244619306896956, "lm_q1q2_score": 0.7206434129892095}}
{"text": "%%=========================\n%% Section 1.02: Origins of the Green's Functions and Roots of P\n%%=========================\n\n\\documentclass[../dissertation.tex]{subfiles}\n\n\\begin{document}\n\\section{Motivation of the Green's Functions}\\label{sec1:RootsOfP}\n\nTo motivate our choice of Green's function for this linear spectral\nproblem, suppose there exists a function $G$ satisfying \n$L_\\delta(G^+)(x) = \\delta_0(x)$, \nwhere $\\delta_0(x)$\\label{sym:dirac} denotes the Dirac delta function (not to be confused with \nthe parameter $\\delta$). Formally, by taking the Fourier \ntransform\\label{sym:fourier} of both \nsides of $L_\\delta(G^+)(x) = \\delta_0(x)$, we have\n\\[\n\t1 \n\t\t= \\xi \\, \\wh G^+ - \\zeta \\( \\wh G^+ - \\wh G^- \\)\n\t\t= \\big[ \\xi - \\zeta \\(1 - e^{-2\\delta\\xi}\\) \\big] \\wh G^+\n\t\t= p(\\xi; \\zeta, \\delta) \\, \\wh G^+,\n\\]\nwhere \n\\begin{align*}\n\tp(\\xi; \\lambda, \\delta) \n\t\t&= \\xi - \\zeta\\(1 - e^{-2\\delta \\xi}\\) \\\\\n\t\t&= \\( \\frac{\\xi}{1 - e^{-2\\delta \\xi}} - \\zeta \\)\\(1 - e^{-2\\delta \\xi}\\) \\\\\n\t\t&= \\big(\\zeta(\\xi) - \\zeta(\\lambda)\\big)\\(1 - e^{-2\\delta \\xi}\\).\n\\end{align*}\nHowever, this approach is somewhat problematic, given that the function $p$ has \nroots $\\xi = 0$ and $\\xi = \\lambda$ along the real line. So, instead defining \na single Green's function for the spectral problem \\eqref{eq:JostDE} based on \ntaking the inverse Fourier transform of $1/p$, we instead define two different \nGreen's functions $G_L^+$ and $G_R^+$ based on taking two different ``Fourier \ninverse like'' transforms of $1/p$ for which the respective contours of \nintegration avoids the roots of $p$. Specifically, \n\t\\begin{align*}\n\t\tG_L^+(x; \\lambda, \\delta)\n\t\t\t&:= \n\t\t\t\t\\frac{1}{2\\pi} \n\t\t\t\t\\int_{\\Gamma_L} \n\t\t\t\t\te^{i\\xi x} \\frac{1}{p(\\xi; \\lambda, \\delta)} \\, \n\t\t\t\td\\xi \\\\\n\t\tG_R^+(x; \\lambda, \\delta) \n\t\t\t&:= \n\t\t\t\t\\frac{1}{2\\pi} \n\t\t\t\t\\int_{\\Gamma_R} \n\t\t\t\t\te^{i\\xi x} \\frac{1}{p(\\xi; \\lambda, \\delta)} \n\t\t\t\t\\, \\mathrm{d}\\xi\n\t\\end{align*}\nwhere the contour ${\\Gamma_L}$ bypasses the roots $\\xi = 0$ and $\\xi = \\lambda$ \nfrom below, and the contour ${\\Gamma_R}$ bypasses the roots $\\xi = 0$ and \n$\\xi = \\lambda$ from above, as mentioned in the previous section. \n\n\nSince $p(\\xi; \\lambda)$ can be rewritten as\n\\[\n\tp(\\xi; \\lambda) \n\t\t= \\(\\frac{\\xi}{1-e^{-2 \\xi \\delta}}-\\zeta(\\lambda)\\)\\(1-e^{-2 \\xi \\delta}\\)\n\t\t= \\big( \\zeta(\\xi) - \\zeta(\\lambda) \\big)\\(1 - e^{-2\\xi \\delta}\\),\n\\]\nit is easy to check that both $\\xi = 0$ and $\\xi = \\lambda$ are roots of $p$. \nIn the remainder of this section, we argue that these are the only roots of \n$p$ in the strip\n\\[\n\t\\mathcal R_\\delta:= \\left\\{z\\in\\CC ~:~ -\\frac{\\pi}{\\delta}\\leq\\im z\\leq\\frac{\\pi}{\\delta} \\right\\}\n\\]\nas is defined in the Introduction of this chapter.\nThat is, we show that the equation\n\\begin{align} \\label{eq1:baseEqn}\n\t\\xi - \\zeta(\\lambda) + \\zeta(\\lambda) e^{-2 \\xi \\delta} = 0\n\\end{align}\nhas exactly two solutions (in $\\xi$) for $\\xi \\in \\mc R_\\delta$. With a little algebraic \nmanipulation, equation \\eqref{eq1:baseEqn} can be rewritten as \n\\begin{align} \\label{eq1:EqnToSolve}\n\t\\big(2 \\delta \\xi - 2 \\delta \\, \\zeta(\\lambda)\\big) \\, e^{2 \\delta \\xi - 2 \\delta \\, \\zeta(\\lambda)} \n\t\t= -2 \\delta \\, \\zeta(\\lambda) \\, e^{-2 \\delta \\, \\zeta(\\lambda)}.\n\\end{align}\nIn order to ``solve'' \\eqref{eq1:EqnToSolve}, recall that the Lambert $W$ function \n(which we henceforth refer to only as $W$) is defined to be the multivalued \n``inverse'' of the function $z e^z$. So, to determine the number\nof solutions \\eqref{eq1:EqnToSolve} has for $\\xi \\in \\mc R_\\delta$, we need to specify \nwhich branches of $W$ are appropriate to apply to both sides of \\eqref{eq1:EqnToSolve} \ngiven our restriction on $\\xi$. \n\nThe following discussion of the branches of the complex $W$\\label{sym1:Wk} function is heavily \ninspired by Section 4 from the 1996 R.M. Corless, G.H. Gonnet, D.E.G. Hare, D.J. \nJeffery and D.E. Knuth paper \\cite{Corless1996}. As is the case with the standard \ncomplex exponential \nand logarithmic functions, to define the branches of $W$, the canonical approach \nis to make a branch cut along the negative real axis of the range of $z e^z$, and \ndetermine which curves in the range of $W$ are mapped to the branch cut ({\\em i.e.} \nthe negative real axis).\n\nTo do so, set \n\\[\n\t\\begin{aligned}\n\t\tz &:= w e^w  & \\qquad w&:= W(z) \\\\\n\t\t  &:= x + i y & \\qquad &:= t + i s.\n\t\\end{aligned}\n\\]\nThen, using Euler's formula to simply the equation\n\\[\n\t( x + i y) = (t + i s) e^{t + i s}\n\\]\nand taking real and imaginary parts, we obtain the system\n\\[\n\t\\left\\{\n\t\t\\begin{aligned}\n\t\t\tx&= e^t \\(t \\cos s - s \\sin s\\) \\\\\n\t\t\ty&= e^t \\( t \\sin s + s \\cos s \\).\n\t\t\\end{aligned}\n\t\\right.\n\\]\nSo, if $y=0$, then either $s = 0$ or $t = - s \\cot s$. Further, $x < 0$ if and \nonly if $t \\cos s - s \\sin s < 0$. Now, since $t = - s \\cot s$ has asymptotes at \n$s = k \\pi$ ($k \\in \\ZZ \\sm \\{0\\}$), and the function $t \\cos s - s \\sin s$ has \nno roots, the inequality $t \\cos s - s \\sin s < 0$ holds precisely on the intervals\n\\[\n\t\\(\\bigcup_{-k \\in \\NN} \\big( (2k + 1) \\pi, \\, 2 k \\pi\\big)\\)\n\t\t\\cup (-\\pi, \\,  \\pi) \\cup\n\t\t\\( \\bigcup_{k \\in \\NN} \\big(2 k \\pi, \\,  (2k + 1) \\)\n\\]\nAs such, the only curves the function $z e^z$ maps to the negative real axis are \n\\[\n\t\\gamma_k(s) := - s \\cot s + i s, \\qquad k \\in \\ZZ,\n\\]\nwhose respective domains are given by \n\\begin{align*}\n\t\\text{domain} \\, \\gamma_k(s) := \n\t\t\\begin{cases}\n\t\t\t\\big( (2k + 1) \\pi, \\, 2 k \\pi\\big), & -k \\in \\NN \\\\\n\t\t\t(-\\pi, \\,  \\pi), & k = 0 \\\\\n\t\t\t\\big(2 k \\pi, \\,  (2k + 1) \\pi\\big), & k \\in \\NN\n\t\t\\end{cases}\n\\end{align*}\nand the curve whose graph is \n\\[\n\t(-\\infty, -1) \\cup \\{ \\gamma_0(s) + i s ~:~ -\\pi < s \\leq 0 \\}.\n\\]\nAs such, these curves form the boundary values between the ranges of \nthe different branches of $W$. In particular, the ranges for the \nthe principle branch $W_0$ and the $W_{-1}$ and $W_1$ branches are \nshown below in Figure \\ref{fig:BoundaryCurves}.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale = 0.25]\n\t\\def\\ticklength{0.35}\n\t\\def\\Pi{3.141592653589793}\n\t\\def\\ee{2.718281828459045}\n\n\t%% Draw w-axes\n\t\\draw[->, thick] (-15, 0) -- (16, 0) node[right] {$\\re w = t$};\n\t\\draw[->, thick] (0, -10) -- (0, 11) node[above] {$\\im w$ = s};\n\n\t%% Draw Branch Curves\n\t\\draw[red,smooth, samples=100, domain=-2.94756:2.94756, variable=\\s, thick] \n\t\tplot ({-\\s / tan(deg(\\s))}, {\\s} );\n\t\\draw[red,smooth, samples=200, domain=6.70346:8.88978, variable=\\s, thick] \n\t\tplot ({-\\s / tan(deg(\\s))}, {\\s} );\n\t\\draw[red,smooth, samples=200, domain=-8.88978:-6.70346, variable=\\s, thick] \n\t\tplot ({-\\s / tan(deg(\\s))}, {\\s} );\n\t\\draw[red, domain=-15:-1, variable=\\s, thick] \n\t\tplot ({\\s}, 0);\n\n\t%% Place Region Labels\n\t\\node (W0) at (4, 1) {$W_0$};\n\t\\node (W-1) at (4, -5) {$W_{-1}$};\n\t\\node (W1) at (4, 5) {$W_{1}$};\n\t\\node (W2) at (-7, {3*\\Pi}) {$W_2$};\n\t\\node (W-2) at (-7, {-3*\\Pi}) {$W_{-2}$};\n\n\t%% Draw im axis tiks\n\t\\foreach \\i in {-3, -2, -1, 1, 2, 3} {\n\t\t\\draw[thick] ({\\ticklength}, {\\i * \\Pi}) -- ({-\\ticklength}, {\\i * \\Pi})\n\t\t\tnode[left] {$\\i \\pi$};\n\t}\n\n\t%% Draw re axis tiks\n\t\\draw[thick] (-1, \\ticklength) -- (-1, -\\ticklength);\n\t\\node at (-1.6, -\\ticklength-0.9) {$-1$};\n\n\t\\end{tikzpicture}\n\t\\caption{Ranges for the $W_{\\pm2}$, $W_{\\pm1}$, and $W_0$ branches of the \n\t\t$W$ function.}\n\t\\label{fig:BoundaryCurves}\n\\end{figure}\n\nSince the map $w \\mapsto w e^w$ takes $w = -1$ to $z = -e^{-1}$, \non pages 17 and 18 in \\cite{Corless1996}, \nCorless {\\em et al.} proposetaking the branch cut which defines the \nprinciple branch of $W$ along $\\{ z \\in \\CC ~:~ -\\infty < z \\leq -e^{-1} \\}$, \nand taking all other branch cuts along the entire negative $\\re z$-axis.\nThey further take all branch cuts in such a way that\nthe branch cuts are closed ``on the top,'' as shown in Figures\n\\ref{fig:ClosedOnTop} and \\ref{fig:OtherBranches}.\n\n\\begin{figure}[h!]\n\t\\begin{tikzpicture}[scale=0.5]\n\t\t\\def\\yaxisshift{-4.6}\n\t\t\\def\\ybranchshift{0.05}\n\t\t\\def\\ticklength{0.2}\n\t\t\\def\\Pi{3.141592653589793}\n\t\t\\def\\ee{2.718281828459045}\n\n\t\t%% Draw z-axes\n\t\t\\draw[->, thick] (-22, 0) -- (-12, 0) node[right] {$\\re z = x$};\n\t\t\\draw[->, thick] (-17, -5) -- (-17, 5) node[above] {$\\im z = y$};\n\t\t%% Draw w-axes\n\t\t\\draw[->, thick] (-5, 0) -- (5, 0) \n\t\t\tnode[right] {$\\re w = t$};\n\t\t\\draw[->, thick] (0, -5) -- (0, 5) node[above] {$\\im w$ = s};\n\t\t%% Draw Map Arrows\n\t\t\\path[->, thick] (-11, 2.5) edge[bend left] node[auto] {$w = W(z)$} (-6, 2.5);\n\t\t\\path[->, thick] (-6, -2.5) edge[bend left] node[auto] {$z = w e^w$} (-11, -2.5);\n\n\t\t%% Draw Branch Cut on z-axes\n\t\t\\draw[very thick, red] \n\t\t\t(-22, {\\ybranchshift}) -- ({-17-1/\\ee}, {\\ybranchshift});\n\t\t\\draw[dashed, very thick, red] \n\t\t\t(-22, {-\\ybranchshift}) -- ({-17-1/\\ee}, {-\\ybranchshift});\n\n\t\t%% Draw Branch Cut along negative Re w axis\n\t\t\\draw[dashed, very thick, red] (-5, {\\ybranchshift}) -- (-1, {\\ybranchshift});\n\t\t\\draw[very thick, red] (-5, {-\\ybranchshift}) -- (-1, {-\\ybranchshift});\n\n\t\t%% Draw w Branch Curves\n\t\t\\draw[red,smooth, samples=100, domain=-2.65:-0.001, variable=\\s, very thick] \n\t\t\tplot ({-\\s / tan(deg(\\s)) -0.05}, {\\s} );\n\n\t\t\\draw[dashed, red,smooth, samples=100, domain=0.001:2.65, variable=\\s, very thick] \n\t\t\tplot ({-\\s / tan(deg(\\s)) -0.05}, {\\s} );\n\n\t\t%% Label Regions\n\t\t\\node at (2, 1) {$W_0$};\n\t\t\\node at (-3, 2) {$W_1$};\n\t\t\\node at (-3, -2) {$W_{-1}$};\n\n\t\t%% Draw im w tick marks \n\t\t\\foreach \\i in {-1, 1} {\n\t\t\t\\draw[thick] ({\\ticklength}, {\\i * \\Pi}) -- ({-\\ticklength}, {\\i * \\Pi})\n\t\t\t\tnode[left] {$\\i \\pi$};\n\t\t}\n\n\t\t%% Draw re w tick mark\n\t\t\\draw[thick] (-1, \\ticklength) -- (-1, -\\ticklength) node[below left] {$-1$};\n\t\t% \\node at (-1.6, -\\ticklength-0.9) {$-1$};\n\n\n\t\t%% Draw re z tick mark\n\t\t\\draw[thick] ({-17-1/\\ee}, \\ticklength) -- ({-17-1/\\ee}, -\\ticklength) \n\t\t\tnode[below left] {$-\\frac{1}{e}$};\n\n\t\\end{tikzpicture}\n\t\\caption{$W_0$ Branch Cut}\n\t\\label{fig:ClosedOnTop}\n\\end{figure}\n\n\n\n\\begin{figure}[h!]\n\t\\begin{tikzpicture}[scale=0.17]\n\t\t\\def\\xm{15}\n\t\t\\def\\ashift{1}\n\t\t\\def\\xmin{-\\xm}\n\t\t\\def\\xmax{\\xm+\\ashift}\n\t\t\\def\\ym{11}\n\t\t\\def\\ymin{-\\ym}\n\t\t\\def\\ymax{\\ym+\\ashift}\n\t\t\\def\\yaxisshift{-4.6}\n\t\t\\def\\xshift{51}\n\t\t\\def\\mapshift{3}\n\t\t\\def\\ybranchshift{0.1}\n\t\t\\def\\ticklength{0.5}\n\t\t\\def\\Pi{3.141592653589793}\n\t\t\\def\\ee{2.718281828459045}\n\n\t\t%% Draw z-axes\n\t\t\\draw[->, thick] (\\xmin-\\xshift, 0) -- (\\xmax-\\xshift, 0) \n\t\t\tnode[right] {$\\re z = x$};\n\t\t\\draw[->, thick] (-\\xshift, \\ymin) -- (-\\xshift, \\ymax) \n\t\t\tnode[above] {$\\im z = y$};\n\n\t\t%% Draw w-axes\n\t\t\\draw[->, thick] (\\xmin, 0) -- (\\xmax, 0) node[right] {$\\re w = t$};\n\t\t\\draw[->, thick] (0, \\ymin) -- (0, \\ymax) node[above] {$\\im w$ = s};\n\n\t\t%% Draw Map Arrows\n\t\t\\path[->, thick] (\\xmax-\\xshift+\\mapshift, \\ym/2) edge[bend left] \n\t\t\tnode[auto] {$w = W(z)$} (\\xmin - \\mapshift, \\ym/2);\n\t\t\\path[->, thick] (\\xmin - \\mapshift, -\\ym/2) edge[bend left] \n\t\t\tnode[auto] {$z = w e^w$} (\\xmax-\\xshift+\\mapshift, -\\ym/2);\n\n\t\t%% Draw Branch Cut on z-axes\n\t\t\\draw[very thick, red] \n\t\t\t({\\xmin-\\xshift}, {\\ybranchshift}) -- ({0-\\xshift}, {\\ybranchshift});\n\t\t\\draw[dashed, very thick, red] \n\t\t\t({\\xmin-\\xshift}, {-\\ybranchshift}) -- ({0-\\xshift}, {-\\ybranchshift});\n\n\t\t%% Draw the Branch Curves\n\t\t\\draw[red,smooth, samples=200, domain=6.70346:8.88978, variable=\\s, very thick] \n\t\t\tplot ({-\\s / tan(deg(\\s))}, {\\s+\\ybranchshift} );\n\t\t\\draw[dashed, red,smooth, samples=200, domain=6.70346:8.88978, variable=\\s, very thick] \n\t\t\tplot ({-\\s / tan(deg(\\s))}, {\\s-\\ybranchshift} );\n\t\t\\draw[red,smooth, samples=200, domain=-8.88978:-6.70346, variable=\\s, very thick] \n\t\t\tplot ({-\\s / tan(deg(\\s))}, {\\s+\\ybranchshift} );\n\t\t\\draw[dashed, red,smooth, samples=200, domain=-8.88978:-6.70346, variable=\\s, very thick] \n\t\t\tplot ({-\\s / tan(deg(\\s))}, {\\s-\\ybranchshift} );\n\n\t\t%% Draw im axis tiks\n\t\t\\foreach \\i in {-3, -2, -1, 1, 2, 3} {\n\t\t\t\\draw[thick] ({\\ticklength}, {\\i * \\Pi}) -- ({-\\ticklength}, {\\i * \\Pi})\n\t\t\t\tnode[left] {$\\i \\pi$};\n\t\t}\n\n\t\t%% Place Region Labels\n\t\t\\node (W2) at ({-2*\\xm/3}, {3*\\Pi}) {$W_2$};\n\t\t\\node (W-2) at ({-2*\\xm/3}, {-3*\\Pi}) {$W_{-2}$};\n\n\t\\end{tikzpicture}\n\t\\caption{$W_k$ ($k \\ne 0$) Branch Cuts}\n\t\\label{fig:OtherBranches}\n\\end{figure}\n\nCorless {\\em et al.} further argue in \\cite{Corless1996} that each branch\n$W_k : \\CC \\to \\ran W_k$ is bijective, which allows us to solve equation\n\\eqref{eq1:EqnToSolve} and find\n\\[\n\t\\xi = \\frac{1}{2\\delta} W_k\\big( -2 \\delta \\zeta(\\lambda) \\big) + \\zeta(\\lambda), \\qquad k \\in \\zeta.\n\\]\nConsequently, the only roots of $p(\\xi, \\lambda)$ which could have a chance of living \nin $\\mc R_\\delta$ are those corresponding to the $W_{-1}$, $W_0$, and $W_1$ branches.\nNow, if $\\xi = 0$, then \n\\[\n\tW_k\\big( -2 \\delta \\zeta(\\lambda) \\big) = -2 \\delta \\zeta(\\lambda).\n\\]\nSince $\\zeta$ is a positive, strictly increasing function with $\\zeta(0) = 1/(2\\delta)$, \nif $\\lambda < 0$, then $-1 < -2\\delta \\zeta(\\lambda) < 0$, and if $\\lambda \\geq 0$, then \n$-2 \\delta \\zeta(\\lambda) \\leq -1$. In other words, if $\\lambda < 0$ the $\\xi = 0$ root of $p$ \ncorresponds to the $W_0$ branch, but if $\\lambda \\geq 0$, then it corresponds to the \n$W_{-1}$ branch. \n\nOn the other hand, if $\\xi = \\lambda$, then\n\\[\n\tW_k\\big( -2 \\delta \\zeta(\\lambda) \\big) = 2\\delta \\lambda -2 \\delta \\zeta(\\lambda).\n\\]\nLet $g(\\lambda):= 2\\delta \\lambda -2 \\delta \\zeta(\\lambda)$. \nNote that\n\\begin{align*}\n\t\\begin{cases}\n\t\t0 < \\zeta'(\\lambda) < \\frac{1}{2}, & \\text{for } \\lambda < 0 \\\\\n\t\t\\zeta'(0) = \\frac{1}{2}, &  \\\\\n\t\t\\frac{1}{2} < \\zeta'(\\lambda) < 1, & \\text{for } \\lambda > 0\n\t\\end{cases}\n\\end{align*}\nwhich implies $g$ is a strictly increasing function. Moreover, since\n$\\lim_{\\lambda\\to \\infty} g(\\lambda) = 0$ and $g(0) = -1$, we see that \n\\[\n\t\\begin{cases}\n\t\t2\\delta \\lambda -2 \\delta \\zeta(\\lambda)  < -1, & \\lambda < 0 \\\\\n\t\t2\\delta \\lambda -2 \\delta \\zeta(\\lambda) = -1, & \\lambda = 0 \\\\\n\t\t-1 < 2\\delta \\lambda -2 \\delta \\zeta(\\lambda) < 0, & \\lambda > 0\n\t\\end{cases}\n\\]\nTherefore, if $\\lambda < 0$ then the $\\xi = \\lambda$ zero of $p$ corresponds to the \n$W_{-1}$ branch, but if $\\lambda \\geq 0$, it corresponds to the $W_{0}$. Moreover, \ngiven that $-2\\delta \\zeta(\\lambda)$ lies on the negative real axis and hence on the branch\ncut used for $W_k$, $k \\ne 0$, each value of \n$2\\delta\\xi-2\\delta\\zeta(\\lambda) = W_k\\big(-2\\delta\\zeta(\\lambda)\\big)$ ($k \\ne 0$) lies on the boundary\nbetween the respective ranges of the $W$ branches. In particular, given that \nthe strip $\\big\\{ z ~:~ -2\\pi \\leq \\im z \\leq 2 \\pi \\big\\}$ does not contain\nany part of the boundary between $\\ran W_{-2}$ and $\\ran W_{-1}$ or any part \nof the boundary between $\\ran W_1$ and $\\ran W_2$, this strip contains exactly \ntwo values of $W\\big(-2 \\delta \\zeta(\\lambda) \\big)$. Since\n\\[\n\t\\mc R_\\delta = \\frac{1}{2\\delta}\\big\\{ z ~:~ -2\\pi \\leq \\im z \\leq 2 \\pi \\big\\}+\\zeta(\\lambda),\n\\]\nthe strip $\\mc R\\delta$ contains exactly two roots of $p$\\textemdash{}precisely as claimed.\n\n\n\\end{document}", "meta": {"hexsha": "ce36a23f81ece70bcacbf94178e26ab51e6ccdce", "size": 14699, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter1-GF/1.1-RootsOfP.tex", "max_stars_repo_name": "ADGC/ilw-dsm-dissertation", "max_stars_repo_head_hexsha": "de0f27b6389ee55c24d155ff482743acbe6a35a1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapter1-GF/1.1-RootsOfP.tex", "max_issues_repo_name": "ADGC/ilw-dsm-dissertation", "max_issues_repo_head_hexsha": "de0f27b6389ee55c24d155ff482743acbe6a35a1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter1-GF/1.1-RootsOfP.tex", "max_forks_repo_name": "ADGC/ilw-dsm-dissertation", "max_forks_repo_head_hexsha": "de0f27b6389ee55c24d155ff482743acbe6a35a1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.4790575916, "max_line_length": 105, "alphanum_fraction": 0.5951425267, "num_tokens": 5865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055545, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7206434111042074}}
{"text": "\\chapter{The Definition of Groups}\n\\label{ch:the-definition-of-groups}\n%% FIXME: \\cite{Pinter2016}*{Chapter 3}\n\n\\begin{enumerate}[label={\\Alph*.},font={\\bfseries}]\n\\item {\\bf Examples of Abelian Groups}\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item $\\Group{\\mathbb{R}, x*y=x+y+k}$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is commutative:\n      $x*y=x+y+k = y+x+k=y*x$\n    \\item $*$ is associative.\n      \\begin{alignat*}{3}\n        & x(yz) &&= x(y+z+k) &&= x+y+z+2k \\\\\n        & (xy)z &&= (x+y+k)z &&= (xy)z \\\\\n        & x(yz) &&= (xy)z\n      \\end{alignat*}\n    \\item $\\mathbb{R}$ has an identity element with respect to $*$.\n      \\begin{align*}\n        xe &= x \\\\\n        x+e+k &= x \\\\\n        e &= -k \\\\\n        (-k)x &= x \\\\\n        -k+x+k &= x\n      \\end{align*}\n    \\item $\\forall x\\in\\mathbb{R}(\\exists x^\\prime\\in\\mathbb{R}(x*x^\\prime=-k))$\n      \\begin{alignat*}{3}\n        xx^\\prime &= -k \\\\\n        x+x^\\prime+k &= -k \\\\\n        x^\\prime &= -x-2k \\\\\n        x^{\\prime}x &= xx^\\prime & \\text{due to commutativity}\n      \\end{alignat*}\n    \\end{enumerate}\n  \\item $\\Group{\\mathbb{R}^*, x*y=\\frac{xy}{2}}$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is commutative:\n      $x*y=\\frac{xy}{2} = \\frac{yx}{2}=y*x$\n    \\item $*$ is associative.\n      \\begin{alignat*}{3}\n        x*(y*z) &= x*(\\frac{yz}{2}) &= \\frac{xyz}{4} \\\\\n        (x*y)*z &= (\\frac{xy}{2})*z &= \\frac{xyz}{4}\n      \\end{alignat*}\n    \\item $\\mathbb{R}^*$ has an identity element with respect to $*$.\n      \\begin{align*}\n        x*e &= \\frac{xe}{2} = \\frac{ex}{2}=e*x = x \\\\\n        e &= 2\n      \\end{align*}\n    \\item $\\forall x\\in\\mathbb{R}(\\exists x^\\prime\\in\\mathbb{R}(x*x^\\prime=2))$\n      \\begin{align*}\n        x*x^\\prime &= \\frac{xx^\\prime}{2} = \\frac{x^{\\prime}x}{2} = x^{\\prime}*x = e = 2 \\\\\n        x^\\prime = \\frac{4}{x}\n      \\end{align*}\n    \\end{enumerate}\n  \\item $\\Group{\\Set{x\\in\\mathbb{R} : x \\neq -1}, x*y=x+y+xy}$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is commutative: $x*y=x+y+xy = y+x+yx=y*x$\n    \\item $*$ is associative.\n      \\begin{alignat*}{3}\n        x*(y*z) &= x*(y+z+yz) = x+(y+z+yz)+x(y+z+yz) &= x+y+z+xy+xz+yz+xyz \\\\\n        (x*y)*z &= (x+y+xy)*z = (x+y+xy)+z+(x+y+xy)z &= x+y+z+xy+xz+yz+xyz\n      \\end{alignat*}\n    \\item $\\Set{x\\in\\mathbb{R} : x \\neq -1}$ has an identity element with respect to $*$.\n      \\begin{align*}\n        x*e &= x+e+xe = e+x+ex = e*x = x \\\\\n        e(x+1) &= 0 \\\\\n        e &= 0\n      \\end{align*}\n    \\item Every element of $\\Set{x\\in\\mathbb{R} : x \\neq -1}$ has an inverse with respect to $*$.\n      \\begin{align*}\n        x*x^\\prime &= x+x^\\prime+xx^\\prime=x^\\prime+x+x^{\\prime}x = e = 0 \\\\\n        x^{\\prime}(x+1) &= -x \\\\\n        x^\\prime &= -\\frac{x}{x+1}\n      \\end{align*}\n    \\end{enumerate}\n  \\item $\\Group{\\Set{x\\in\\mathbb{R} :-1 < x < 1}, x*y=\\frac{x+y}{xy+1}}$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is commutative: $x*y=\\frac{x+y}{xy+1}=\\frac{y+x}{yx+1}=y*x$\n    \\item $*$ is associative.\n      \\begin{alignat*}{4}\n        x*(y*z) &= x*(\\frac{y+z}{yz+1})\n        &= \\frac{x+(\\frac{y+z}{yz+1})}{x(\\frac{y+z}{yz+1})+1}\n        &= \\frac{xyz+x+y+z}{xy+xz+yz+1} \\\\\n        (x*y)*z &= \\frac{x+y}{xy+1}*z\n        &= \\frac{(\\frac{x+y}{xy+1})+z}{(\\frac{x+y}{xy+1})z+1}\n        &= \\frac{x+y+z+xyz}{xy+yz+xz+1}\n      \\end{alignat*}\n    \\item $\\Set{x\\in\\mathbb{R} : -1 < x < 1}$ has an identity element w.r.t. $*$.\n      \\begin{align*}\n        x*e &= \\frac{x+e}{xe+1} = x \\\\\n        x+e &= x(xe+1) \\\\\n        e &= ex^2 \\\\\n        e(1-x^2) &= 0 \\\\\n        e &= 0 \\\\\n        x*0 &= \\frac{x+0}{(x\\times0)+1} = x = \\frac{0+x}{0x+1} = 0*x\n      \\end{align*}\n    \\item Every element of $\\Set{x\\in\\mathbb{R} : -1 < x < 1}$ has an inverse with respect to $*$.\n      \\begin{align*}\n        x * x^\\prime &= \\frac{x+x^\\prime}{xx^\\prime+1} = 0; \\quad\n        x+x^\\prime = 0; \\quad\n        x^\\prime = -x \\\\\n        x*(-x) &= \\frac{x-x}{x(-x)+1} = 0 = \\frac{-x+x}{-x^2+1} = (-x)*x\n      \\end{align*}\n    \\end{enumerate}\n  \\end{enumerate}\n\\item {\\bf Groups on the Set $\\mathbb{R} \\times \\mathbb{R}$}\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item $(a,b) * (c,d) = (ad + bc, bd)$, on the set $\\Set{(x,y)\\in\\mathbb{R}\\times\\mathbb{R} : y \\ne 0}$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is commutative.\n      \\begin{align*}\n        (c,d) * (a,b) &= (cb+da,db) \\\\\n        &= (ad+bc,bd) \\\\\n        &= (a,b) * (c,d)\n      \\end{align*}\n    \\item $*$ is associative.\n      \\begin{align*}\n        (a,b) * \\left[(c,d) * (e,f)\\right] &= (a,b) * (cf+de,df) \\\\\n        &= (adf+bcf+bde,bdf) \\\\\n        &= (ad+bc, bd) * (e,f) \\\\\n        &= \\left[(a,b) * (c,d)\\right] * (e,f)\n      \\end{align*}\n    \\item $(e_1,e_2) = (0,1)$\n      \\begin{align*}\n        (a,b) * (e_1,e_2) &= (ae_2 + be_1, be_2) \\\\\n        &= (a,b) \\\\\n        \\\\\n        be_2 &= b \\\\\n        e_2 &= 1 \\\\\n        \\\\\n        ae_2 + be_1 &= a \\\\\n        a + be_1 &= a \\\\\n        e_1 &= 0\n      \\end{align*}\n    \\item $(a^\\prime,b^\\prime) = \\left(\\frac{-a}{b^2}, \\frac{1}{b}\\right)$\n      \\begin{align*}\n        (a,b) * (a^\\prime,b^\\prime) &= (ab^\\prime + ba^\\prime, bb^\\prime) \\\\\n        &= (0,1)\n      \\end{align*}\n      \\begin{align*}\n        bb^\\prime &= 1 \\\\\n        b^\\prime &= \\frac{1}{b} \\\\\n        \\\\\n        ab^\\prime + ba^\\prime &= 0 \\\\\n        \\frac{a}{b} + ba^\\prime &= 0 \\\\\n        ba^\\prime &= \\frac{-a}{b} \\\\\n        a^\\prime &= \\frac{-a}{b^2} \\\\\n        \\\\\n        (a,b) * \\left(\\frac{-a}{b^2}, \\frac{1}{b}\\right) &= \\left(\\frac{a}{b} + \\frac{-a}{b}, b\\left(\\frac{1}{b}\\right)\\right) \\\\\n        &= (0,1)\n      \\end{align*}\n    \\end{enumerate}\n  \\item $(a, b) * (c, d) = (ac, bc + d)$, on the set $\\Set{(x,y)\\in\\mathbb{R}\\times\\mathbb{R} : x \\ne 0}$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is not commutative: $(c,d) * (a,b) = (ca, da + b) \\ne (a,b) * (c,d)$\n    \\item $*$ is associative.\n      \\begin{align*}\n        \\left[(a,b) * (c,d)\\right] * (e,f) &= (ac, bc+d) * (e,f) \\\\\n        &= (ace, bce+de+f) \\\\\n        &= (a,b) * (ce, de+f) \\\\\n        &= (a,b) * \\left[(c,d) * (e,f)\\right]\n      \\end{align*}\n    \\item $(e_1,e_2) = (1,0)$\n      \\begin{align*}\n        (a,b) * (e_1,e_2) &= (ae_1, be_1+e_2) \\\\\n        &= (a, b) \\\\\n        \\\\\n        ae_1 &= a \\\\\n        e_1 &= 1 \\\\\n        \\\\\n        be_1+e_2 &= b \\\\\n        b+e_2 &= b \\\\\n        e_2 &= 0\n      \\end{align*}\n    \\item $(a^\\prime,b^\\prime) = (\\frac{1}{a},\\frac{-b}{a})$\n      \\begin{align*}\n        (a,b) * (a^\\prime,b^\\prime) &= (aa^\\prime, ba^\\prime + b^\\prime) \\\\\n        &= (1,0) \\\\\n        \\\\\n        aa^\\prime &= 1 \\\\\n        a^\\prime &= \\frac{1}{a} \\\\\n        \\\\\n        ba^\\prime + b^\\prime &= 0 \\\\\n        \\frac{b}{a} + b^\\prime &= 0 \\\\\n        b^\\prime &= \\frac{-b}{a}\n        \\\\\n        (a,b) * (\\frac{1}{a}, \\frac{-b}{a}) &= (\\frac{a}{a}, \\frac{b}{a} - \\frac{b}{a}) \\\\\n        &= (1,0)\n      \\end{align*}\n    \\end{enumerate}\n  \\item $(a, b) * (c, d) = (ac, bc + d)$, on the set $\\Set{(x,y)\\in\\mathbb{R}\\times\\mathbb{R}}$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is not commutative, as per 2(i).\n    \\item $*$ is associative, as per 2(ii).\n    \\item $(e_1,e_2) = (1,0)$, as per 2(iii).\n    \\item $a^\\prime$ is not defined $\\forall a\\in\\mathbb{R}$, notably when $a=0$.\n    \\end{enumerate}\n  \\item $(a, b) * (c, d) = (ac-bd,ad+bc)$, on the set $\\Set{(x,y)\\in(\\mathbb{R}\\times\\mathbb{R})\\setminus\\Set{(0,0)}}$\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $*$ is commutative.\n      \\begin{align*}\n        (c,d) * (a,b) &= (ca-db,cb+da) \\\\\n        &= (ac-db,ad+bc) \\\\\n        &= (a,b) * (c,d)\n      \\end{align*}\n    \\item $*$ is associative.\n      \\begin{align*}\n        (a,b) * \\left[(c,d) * (e,f)\\right] &= (ac-bd,ad+bc) * (ce-df,cf+de) \\\\\n        &= \\left(a(ce-df) - b(cf+de), a(cf+de)+b(ce-df)\\right) \\\\\n        &= (ace-adf-bcf-bde, acf+ade+bce-bdf) \\\\\n        &= \\left(e(ac-bd)-f(ad+bc), f(ac-bd)+e(ad+bc)\\right) \\\\\n        &= (ac-bd,ad+bc) * (e,f) \\\\\n        &= \\left[(a,b) * (c,d)\\right] * (e,f)\n      \\end{align*}\n    \\item $(e_1,e_2) = (?,?)$\n      \\begin{align*}\n        (a,b) * (e_1,e_2) &= (ae_1-be_2,ae_2+be_1) \\\\\n        &= (a,b) \\\\\n        \\\\\n        ae_2+be_1 &= b \\\\\n        be_1 &= b - ae_2 \\\\\n        e_1 &= 1 - \\frac{ae_2}{b} \\\\\n        \\\\\n        ae_1-be_2 &= a \\\\\n        -be_2 &= a-ae_1 \\\\\n        be_2 &= ae_1-a \\\\\n        e_2 &= \\frac{ae_1-a}{b}\n      \\end{align*}\n    \\end{enumerate}\n  \\end{enumerate}\n  \\newpage\n\\item {\\bf Groups of Subsets of a Subset}\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item The identity element with respect to the operation $+$ is $\\emptyset$.\n    \\begin{align*}\n      A+I &= (A-I) \\cup (I-A) = A \\\\\n      &= (A-\\emptyset) \\cup (I-\\emptyset) \\\\\n      \\\\\n      I &= \\emptyset\n    \\end{align*}\n  \\item $\\Group{\\powerset{D}, +}$ is a group, since\n    $\\forall A \\in \\powerset{D}, A\\inverse = A$.\n    \\begin{align*}\n      A+A\\inverse &= \\emptyset \\\\\n      (A-A\\inverse) \\cup (A\\inverse-A) &= \\emptyset \\\\\n      A-A\\inverse &= A\\inverse-A = \\emptyset \\\\\n      A\\inverse &= A\n    \\end{align*}\n  \\item Let $D = \\Set{a,b,c}$.\n    \\[\n    \\powerset{D} = \\Set{\n      \\emptyset,\n      \\Set{a}, \\Set{b}, \\Set{c},\n      \\Set{a,b}, \\Set{a,c}, \\Set{b,c},\n      \\Set{a,b,c}\n    }\n    \\]\n    \\begin{center}\n      \\captionof{table}{$\\Group{\\powerset{D}, +}$}\n      \\begin{tabular}{ c | c c c c c c c c}\n        $+$ & $\\emptyset$ & $\\Set{a}$ & $\\Set{b}$ & $\\Set{c}$ & $\\Set{a,b}$ & $\\Set{a,c}$ & $\\Set{b,c}$ & $\\Set{a,b,c}$ \\\\\n        \\hline\n        $\\emptyset$ & $\\emptyset$ & $\\Set{a}$ & $\\Set{b}$ & $\\Set{c}$ & $\\Set{a,b}$ & $\\Set{a,c}$ & $\\Set{b,c}$ & $\\Set{a,b,c}$ \\\\\n        $\\Set{a}$ & $\\Set{a}$ & $\\emptyset$ & $\\Set{a,b}$ & $\\Set{a,c}$ & $\\Set{b}$ & $\\Set{c}$ & $\\Set{a,b,c}$ & $\\Set{b,c}$ \\\\\n        $\\Set{b}$ & $\\Set{b}$ & $\\Set{a,b}$ & $\\emptyset$ & $\\Set{b,c}$ & $\\Set{a}$ & $\\Set{a,b,c}$ & $\\Set{c}$ & $\\Set{a,c}$ \\\\\n        $\\Set{c}$ & $\\Set{c}$ & $\\Set{a,c}$ & $\\Set{b,c}$ & $\\emptyset$ & $\\Set{a,b,c}$ & $\\Set{a}$ & $\\Set{b}$ & $\\Set{a,b}$ \\\\\n        $\\Set{a,b}$ & $\\Set{a,b}$ & $\\Set{b}$ & $\\Set{a}$ & $\\Set{a,b,c}$ & $\\emptyset$ & $\\Set{b,c}$ & $\\Set{a,c}$ & $\\Set{c}$ \\\\\n        $\\Set{a,c}$ & $\\Set{a,c}$ & $\\Set{c}$ & $\\Set{a,b,c}$ & $\\Set{a}$ & $\\Set{b,c}$ & $\\emptyset$ & $\\Set{a,b}$ & $\\Set{b}$ \\\\\n        $\\Set{b,c}$ & $\\Set{b,c}$ & $\\Set{a,b,c}$ & $\\Set{c}$ & $\\Set{b}$ & $\\Set{a,c}$ & $\\Set{a,b}$ & $\\emptyset$ & $\\Set{a}$ \\\\\n        $\\Set{a,b,c}$ & $\\Set{a,b,c}$ & $\\Set{b,c}$ & $\\Set{a,c}$ & $\\Set{a,b}$ & $\\Set{c}$ & $\\Set{b}$ & $\\Set{a}$ & $\\emptyset$\n      \\end{tabular}\n    \\end{center}\n  \\end{enumerate}\n\\item {\\bf A Checkerboard Game}\n  \\begin{center}\n    \\captionof{table}{$\\Group{G, *}$}\n    \\begin{tabular}{ c | c c c c }\n      $*$ & $I$ & $V$ & $H$ & $D$ \\\\\n      \\hline\n      $I$ & $I$ & $V$ & $H$ & $D$ \\\\\n      $V$ & $V$ & $I$ & $D$ & $H$ \\\\\n      $H$ & $H$ & $D$ & $I$ & $V$ \\\\\n      $D$ & $D$ & $H$ & $V$ & $I$\n    \\end{tabular}\n  \\end{center}\n  As shown in the \\gls{Cayley table} above, the identity element is $I$ and\n  every element is its own inverse. Having shown that and granting\n  associativity, $\\Group{G, *}$ is a group.\n\\item {\\bf A Coin Game}\n  \\begin{center}\n    \\captionof{table}{$\\Group{G, *}$}\n    \\begin{tabular}{ c | c c c c c c c c }\n      $*$ & $I$ & $M_1$ & $M_2$ & $M_3$ & $M_4$ & $M_5$ & $M_6$ & $M_7$ \\\\\n      \\hline\n      $I$ & $I$ & $M_1$ & $M_2$ & $M_3$ & $M_4$ & $M_5$ & $M_6$ & $M_7$ \\\\\n      $M_1$ & $M_1$ & $I$ & $M_3$ & $M_2$ & $M_5$ & $M_4$ & $M_7$ & $M_6$ \\\\\n      $M_2$ & $M_2$ & $M_3$ & $I$ & $M_1$ & $M_6$ & $M_7$ & $M_4$ & $M_5$ \\\\\n      $M_3$ & $M_3$ & $M_2$ & $M_1$ & $I$ & $M_7$ & $M_6$ & $M_5$ & $M_4$ \\\\\n      $M_4$ & $M_4$ & $M_6$ & $M_5$ & $M_7$ & $I$ & $M_2$ & $M_1$ & $M_3$ \\\\\n      $M_5$ & $M_5$ & $M_7$ & $M_4$ & $M_6$ & $M_1$ & $M_3$ & $I$ & $M_2$ \\\\\n      $M_6$ & $M_6$ & $M_4$ & $M_7$ & $M_5$ & $M_2$ & $I$ & $M_3$ & $M_1$ \\\\\n      $M_7$ & $M_7$ & $M_5$ & $M_6$ & $M_4$ & $M_3$ & $M_1$ & $M_2$ & $I$\n    \\end{tabular}\n  \\end{center}\n\n  As shown in the \\gls{Cayley table} above, the identity element is $I$ and\n  every element is invertible. Having shown that and granting associativity,\n  $\\Group{G, *}$ is a group. It is not commutative, because, for example\n  $M_6 * M_4 = M_2$, while $M_4 * M_6 = M_1$, so $M_6 * M_4 \\ne M_4 * M_6$.\n  \\newpage\n  \\captionof{figure}{$\\Group{r,s,t\\ |\\ r^2,s^2,t^2,(rs)^4,(st)^3,(rt)^2}$}\n  \\begin{figure}[h]\n    \\begin{tikzpicture}[line width=1pt]\n      \\node (I) at (0,4) { $I$ };\n      \\node (M3) at (4,0) { $M_3$ };\n      \\node (M5) at (3,3) { $M_5$ };\n      \\node (M6) at (1,1) { $M_6$ };\n      \\node (M7) at (3,1) { $M_7$ };\n\n      \\node[green] (M1) at (4,4) { $\\mathbf{M_1}$ };\n      \\node[blue] (M2) at (0,0) { $\\mathbf{M_2}$ };\n      \\node[red] (M4) at (1,3) { $\\mathbf{M_4}$ };\n\n      \\draw[green] (I)  -- (M1)\n                   (M1) -- (I)\n                   (M2) -- (M3)\n                   (M3) -- (M2)\n                   (M4) -- (M6)\n                   (M5) -- (M7)\n                   (M6) -- (M4)\n                   (M7) -- (M5);\n\n      \\draw[blue] (I)  -- (M2)\n                  (M1) -- (M3)\n                  (M2) -- (I)\n                  (M3) -- (M1)\n                  (M4) -- (M5)\n                  (M5) -- (M4)\n                  (M6) -- (M7)\n                  (M7) -- (M6);\n\n      \\draw[red] (I)  -- (M4)\n                 (M1) -- (M5)\n                 (M2) -- (M6)\n                 (M3) -- (M7)\n                 (M4) -- (I)\n                 (M5) -- (M1)\n                 (M6) -- (M2)\n                 (M7) -- (M3);\n    \\end{tikzpicture}\n  \\end{figure}\n\\item {\\bf Groups in Binary Codes}\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item $\\Seq{a_1,a_2,...,a_n} + \\Seq{b_1,b_2,...,b_n} = \\Seq{b_1,b_2,...,b_n} + \\Seq{a_1,a_2,...,a_n}$,\n    since the left-hand side is equivalent to $\\Seq{a_1+b_1,a_2+b_2,...,a_n+b_n}$,\n    which by commutativity is equivalent to $\\Seq{b_1+a_1,b_2+a_2,...,b_n+a_n}$,\n    which is equivalent to $\\Seq{b_1,b_2,...,b_n} + \\Seq{a_1,a_2,...,a_n}$.\n  \\item\n    \\begin{alignat*}{5}\n      &1 + (1 + 1) &&= 1 + 0 &&= 1 &&= 0 + 1 &&= (1 + 1) + 1 \\\\\n      &1 + (1 + 0) &&= 1 + 1 &&= 0 &&= 0 + 0 &&= (1 + 1) + 0 \\\\\n      &1 + (0 + 1) &&= 1 + 1 &&= 0 &&= 1 + 1 &&= (1 + 0) + 1 \\\\\n      &0 + (1 + 1) &&= 0 + 0 &&= 0 &&= 1 + 1 &&= (0 + 1) + 1 \\\\\n      &1 + (0 + 0) &&= 1 + 0 &&= 1 &&= 1 + 0 &&= (1 + 0) + 0 \\\\\n      &0 + (0 + 1) &&= 0 + 1 &&= 1 &&= 0 + 1 &&= (0 + 0) + 1 \\\\\n      &0 + (1 + 0) &&= 0 + 1 &&= 1 &&= 1 + 0 &&= (0 + 1) + 0 \\\\\n      &0 + (0 + 0) &&= 0 + 0 &&= 0 &&= 0 + 0 &&= (0 + 0) + 0\n    \\end{alignat*}\n  \\item\n    \\begin{align*}\n      \\Seq{a_1,a_2,...,a_n} + \\left[\\Seq{b_1,b_2,...,b_n} + \\Seq{c_1,c_2,...,c_n}\\right]\n      &= \\Seq{a_1,a_2,...,a_n} + \\Seq{b_1+c_1,b_2+c_2,...,b_n+c_n} \\\\\n      &= \\Seq{a_1+b_1+c_1,a_2+b_2+c_2,...,a_n+b_n+c_n} \\\\\n      &= \\Seq{a_1+b_1,a_2+b_2,...,a_n+b_n} + \\Seq{c_1,c_2,...,c_n} \\\\\n      &= \\left[\\Seq{a_1,a_2,...,a_n} + \\Seq{b_1,b_2,...,b_n}\\right] + \\Seq{c_1,c_2,...,c_n}\n    \\end{align*}\n    \\item The identity element of $\\mathbb{B}^n$, that is, the identity element\n      for adding words on length $n$, is $0^n$.\n    \\item The inverse, with respect to word addition, of any word\n      $(a_1,...,a_n)$ is $(a_1,...,a_n)$.\n    \\item $\\mathbf{a} + \\mathbf{b} = \\mathbf{a} + (-\\mathbf{b})$,\n      since $\\mathbf{b} = -\\mathbf{b}$.\n      Thus $\\mathbf{a} + \\mathbf{b} = \\mathbf{a} - \\mathbf{b}$.\n    \\item\n      \\begin{align*}\n        \\mathbf{a} + \\mathbf{b} &= \\mathbf{c} \\\\\n        \\mathbf{a} + (-\\mathbf{b}) &= \\mathbf{c} \\\\\n        \\mathbf{a} - \\mathbf{b} &= \\mathbf{c} \\\\\n        \\mathbf{a} &= \\mathbf{b} + \\mathbf{c}\n      \\end{align*}\n  \\end{enumerate}\n  \\newpage\n\\item {\\bf Theory of Coding: Maximum-Likelihood Decoding}\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item\n    \\begin{center}\n      \\captionof{table}{Parity check equations in $C_1$}\n      \\begin{tabular}{ c | c c c c c c c }\n        $C_1$ & $a_4$ & $a_1+a_3$ & $a_4=a_1+a_3$ & $a_5$ & $a_1+a_2+a_3$ & $a_5=a_1+a_2+a_3$ \\\\\n        \\hline\n        $00000$ & $0$ & $0+0$ & \\checkmark & $0$ & $0+0+0$ & \\checkmark \\\\\n        $00111$ & $1$ & $0+1$ & \\checkmark & $1$ & $0+0+1$ & \\checkmark \\\\\n        $01001$ & $0$ & $0+0$ & \\checkmark & $1$ & $0+1+0$ & \\checkmark \\\\\n        $01110$ & $1$ & $0+1$ & \\checkmark & $0$ & $0+1+1$ & \\checkmark \\\\\n        $10011$ & $1$ & $1+0$ & \\checkmark & $1$ & $1+0+0$ & \\checkmark \\\\\n        $10100$ & $0$ & $1+1$ & \\checkmark & $0$ & $1+0+1$ & \\checkmark \\\\\n        $11010$ & $1$ & $1+0$ & \\checkmark & $0$ & $1+1+0$ & \\checkmark \\\\\n        $11101$ & $0$ & $1+1$ & \\checkmark & $1$ & $1+1+1$ & \\checkmark\n      \\end{tabular}\n    \\end{center}\n  \\item\n    \\begin{enumerate}[label={(\\alph*)}]\n    \\item\n      \\[\n      C_2 = \\Set{\n        000000,\n        001001,\n        010111,\n        011110,\n        100011,\n        101010,\n        110000,\n        111101\n      }\n      \\]\n    \\item\n      \\begin{center}\n        \\captionof{table}{Distance in $C_2$}\n        \\begin{tabular}{ c | c c c c c c c c }\n          $d(\\mathbf{a}, \\mathbf{b})$ & 000000 & 001001 & 010111 & 011110 & 100011 & 101010 & 110000 & 111101 \\\\\n          \\hline\n          000000 &   & 2 & 4 & 4 & 3 & 3 & 2 & 5 \\\\\n          001001 & 2 &  & 4 & 4 & 3 & 3 & 4 & 3 \\\\\n          010111 & 4 & 4 &   & 2 & 3 & 5 & 4 & 3 \\\\\n          011110 & 4 & 4 & 2 &   & 5 & 3 & 4 & 3 \\\\\n          100011 & 3 & 3 & 3 & 5 &   & 2 & 3 & 4 \\\\\n          101010 & 3 & 3 & 5 & 3 & 2 &   & 3 & 4 \\\\\n          110000 & 2 & 4 & 4 & 4 & 3 & 3 &   & 3 \\\\\n          111101 & 5 & 3 & 3 & 3 & 4 & 4 & 3 &\n        \\end{tabular}\n      \\end{center}\n      The minimum distance of the code $C_2$ is $2$.\n      \\item Since the minimum distance is $C_2$, one error is sure to be\n        detected in any codeword of $C_2$.\n    \\end{enumerate}\n  \\item $C_3 = \\Set{0000,0101,1011,1110}$ where $a_3 = a_1$ and $a_4 = a_1+a_2$.\n    \\begin{center}\n      \\captionof{table}{Distance in $C_3$}\n      \\begin{tabular}{ c | c c c c }\n        $d(\\mathbf{a}, \\mathbf{b})$ & 0000 & 0101 & 1011 & 1110 \\\\\n        \\hline\n        0000 & 0 & 2 & 3 & 3 \\\\\n        0101 & 2 & 0 & 3 & 3 \\\\\n        1011 & 3 & 3 & 0 & 2 \\\\\n        1110 & 3 & 3 & 2 & 0\n      \\end{tabular}\n      \\end{center}\n    $$\\min_{\\mathbf{a} \\in C_3, \\mathbf{a}\\ne\\mathbf{b}} d(\\mathbf{a}, \\mathbf{b}) = 2$$\n  \\item\n    \\begin{itemize}\n    \\item $11111 \\to 11101$\n    \\item $00101 \\to 00111$\n    \\item $11000 \\to 11010$\n    \\item $10011 \\to 10011$\n    \\item $10001 \\to 10011$\n    \\item $10111 \\to 10011\\ or\\ 00111$\n    \\end{itemize}\n  \\end{enumerate}\n\\end{enumerate}\n", "meta": {"hexsha": "4fc187f1856d94f9dc64c87bd9e47d5ff38839bc", "size": 18526, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/ch3.tex", "max_stars_repo_name": "yurrriq/abstract-algebra-pinter", "max_stars_repo_head_hexsha": "58eed44088f29e2ddae9d7782f603562c04b0e37", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-09-24T23:35:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-08T20:26:03.000Z", "max_issues_repo_path": "src/ch3.tex", "max_issues_repo_name": "yurrriq/abstract-algebra-pinter", "max_issues_repo_head_hexsha": "58eed44088f29e2ddae9d7782f603562c04b0e37", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-01T07:16:00.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-19T06:01:56.000Z", "max_forks_repo_path": "src/ch3.tex", "max_forks_repo_name": "yurrriq/abstract-algebra-pinter", "max_forks_repo_head_hexsha": "58eed44088f29e2ddae9d7782f603562c04b0e37", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-24T23:35:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-24T23:35:51.000Z", "avg_line_length": 39.5010660981, "max_line_length": 130, "alphanum_fraction": 0.4304221095, "num_tokens": 7987, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7206433975820877}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=1}^\\infty \\frac{n^2+1}{n^4+7}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution 1}\r\n\r\n$\\displaystyle \\sum_{n=1}^\\infty \\frac1{n^2}$ is a $p$-series with $p=2$. Since $p > 1$, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac1{n^2}$ converges by the $p$-series test. If we use $a_n = \\frac{n^2+1}{n^4+7}$ and $b_n = \\frac1{n^2}$, then\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} \\frac{a_n}{b_n}\r\n&= \\lim_{n \\to \\infty} \\frac{n^2+1}{n^4+7} \\cdot \\frac{n^2}{1}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{n^4+n^2}{n^4+7} \\\\\r\n&= \\lim_{n \\to \\infty} \\frac{4n^3+2n}{4n^3} \\text{ using L'hopital}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{12n^2+2}{12n^2} \\text{ using L'hopital}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{24n}{24n} \\text{ using L'hopital}\\\\\r\n&= \\lim_{n \\to \\infty} 1\\\\\r\n&= 1\r\n\\end{align*}\r\nSo by the Limit Comparison Test, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{n^2+1}{n^4+7}$ converges.\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{n^2+1}{n^4+7}$ converges absolutely.\r\n\r\n\\subsection*{Solution 2}\r\n\r\nWe are looking for a fixed $K > 0$ such that \r\n\\[ \\frac{n^2+1}{n^4+7} \\leq \\frac{K}{n^2}\\]\r\nBy multiplying both sides by $n^2(n^4+7)$, we have\r\n\\[ n^4+n^2 \\leq K(n^4+7)\\]\r\n\\[ n^4+n^2 \\leq Kn^4+7K\\]\r\nand it appears we can use $K=2$, because then we'd have\r\n\\[ n^4+n^2 \\leq 2n^4+14\\]\r\n\\[ n^4+n^2 \\leq n^4+n^4+14\\]\r\nand $n^2 \\leq n^4$ (when comparing second terms).\r\nSo we are ready to present starting from true inequalities.\r\n\r\nWith the scratch work above done, since $n^2 \\leq n^4$, we have\r\n\\[ n^4+n^2 \\leq n^4+n^4+14\\]\r\n\\[ n^4+n^2 \\leq 2n^4+14\\]\r\n\\[ n^4+n^2 \\leq 2(n^4+7)\\]\r\nby dividing both sides by $n^2(n^4+7)$, we get\r\n\\[ \\frac{n^2+1}{n^4+7} \\leq \\frac{2}{n^2}\\]\r\n\r\nSince $\\displaystyle \\sum_{n=1}^\\infty \\frac2{n^2} = 2\\sum_{n=1}^\\infty \\frac1{n^2}$ converges by the $p$-test, the series \r\n$\\displaystyle \\sum_{n=1}^\\infty \\frac{n^2+1}{n^4+7}$ converges by the Direct Comparison Test.\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{n^2+1}{n^4+7}$ converges absolutely.\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\left|\\frac{a_{n+1}}{a_n}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\right|\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} a_n\r\n&= \\lim_{n \\to \\infty} \\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "ab138126db55e89f45c850c850db9b81e5fc4876", "size": 2997, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/n4.tex", "max_stars_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_stars_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "key/series/n4.tex", "max_issues_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_issues_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "key/series/n4.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 37.4625, "max_line_length": 248, "alphanum_fraction": 0.6116116116, "num_tokens": 1247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.8918110353738529, "lm_q1q2_score": 0.7206432583701541}}
{"text": "\\documentclass{article}\n\n\\usepackage{fullpage}\n\\usepackage{amsmath,amssymb}\n\n\\setlength{\\parindent}{0pt}\n\n\\begin{document}\n\n\\section*{The Birthday Problem}\n\n\\textsc{Q: What is the probability that, in a group of $n$ people, at least 2 have the same birthday?}\\\\[1em]\nLet us represent the days of the year by the integers 1, 2, \\ldots, 365. Then we choose our sample space $\\textsl{S}$ to be \\{all possible combinations of $n$ birthdays\\}. That is, we include all possible combinations of $n$ days, with repetition (up to $n$ repetitions of the same day, where all $n$ birthdays fall on the same day).\\\\[1ex]\nFor example, if $n=3$, we include:\n\\begin{itemize}\n\\item all the single days of the year (eg. (1, 1, 1), (2, 2, 2), (3, 3, 3), \\ldots), in the case that all 3 birthdays fall on the same day,\n\\item all combinations of 2 different days of the year (eg. (1, 1, 2), (1, 1, 3), (1, 1, 4), \\ldots), in the case that 2 of the birthdays fall on the same day, and\n\\item all combinations of 3 different days of the year (eg. (1, 2, 3), (1, 2, 4), (1, 2, 5), \\ldots), in the case that all 3 birthdays fall on different days\n\\end{itemize}\nSuppose that all birthdays are equally likely. Then, by the classical definition of probability,\n\\begin{equation*}\n\\boxed{\nP(\\{\\text{at least 2 people share a birthday}\\})=\\dfrac{|\\{\\text{at least 2\\ldots}\\}|}{|\\textsl{S}|}\n}\n\\end{equation*}\nWe know from counting principles that\n\\begin{align*}\n|\\textsl{S}|& =\\text{\\# of ways to select the first birthday $\\times$ \\# of ways to select the second birthday}\\\\\n& \\quad\\times\\ldots\\times\\text{\\# of ways to select the $n$th birthday}\\\\\n& =365\\times 365\\times\\ldots\\times 365\\\\\n& =365^n\n\\end{align*}\nand that\n\\begin{align*}\n|\\{\\text{at least 2\\ldots}\\}|& =\\text{\\# of arrangements of $n$ birthdays where 2 people share a birthday}\\\\\n& \\quad+\\text{\\# of arrangements of $n$ birthdays where 3 people share a birthday}\\\\\n& \\quad+\\ldots+\\text{\\# of arrangements of $n$ birthdays where $n$ people share a birthday}\n\\end{align*}\nSo\n\\begin{equation*}\n\\boxed{\nP(\\{\\text{at least 2 people share a birthday}\\})=\\dfrac{|\\{\\text{2 people share a birthday}\\}|+\\ldots+|\\{\\text{$n$ people share a birthday}\\}|}{365^n}\n}\n\\end{equation*}\nThen we consider that\n\\begin{align*}\n\\text{\\# of arrangements of $n$ birthdays}& \\\\\n\\text{where $r$ people share a birthday}& =\\text{\\# of ways to select the first unshared birthday}\\\\\n& \\quad\\times\\text{\\# of ways to select the second unshared birthday}\\\\\n& \\quad\\times\\ldots\\times\\text{\\# of ways to select the $(n-r)$th unshared birthday}\\\\\n& \\quad\\times \\text{\\# of ways to select the shared birthday}\\\\\n& \\quad\\times \\text{\\# of ways to arrange $n-r$ different birthdays and $r$ same birthdays}\\\\\n& =365\\times 364\\times\\ldots\\times(365-(n-r-1))\\times(365-(n-r))\\times \\dfrac{n!}{r!1!\\ldots 1!}\n\\end{align*}\nFor example, if $n=3$, \n\\begin{align*}\n\\text{\\# of arr. where 2 people share a birthday}& =\\text{\\# of ways to select the unshared birthday}\\\\\n& \\quad\\times \\text{\\# of ways to select the shared birthday}\\\\\n& \\quad\\times\\text{\\# of ways to arrange 1 unique birthday and 2 same birthdays}\\\\\n& =365\\times 364\\times \\frac{3!}{2!1!}\\\\\n& =398\\,580\n\\end{align*}\nand then\n\\begin{align*}\nP(\\{\\text{at least 2 people share a birthday}\\})&=\\dfrac{|\\{\\text{2 people share a birthday}\\}|+|\\{\\text{3 people share a birthday}\\}|}{365^3}\\\\\n& =\\dfrac{398\\,580+365}{365^3}\\\\\n& =\\dfrac{398\\,945}{365^3}\n\\end{align*}\n%\\textsc{In general,}\n%\\begin{align*}\n%|\\{\\text{at least 2\\ldots}\\}|& =(365\\times 364\\times\\ldots\\times(365-(n-2-1))\\times(365-(n-2)))\\times \\dfrac{n!}{2!1!\\ldots 1!}\\\\\n%& \\quad+(365\\times 364\\times\\ldots\\times(365-(n-3-1))\\times(365-(n-3)))\\times\\dfrac{n!}{3!1!\\ldots 1!}\\\\\n%& \\quad+\\ldots+365\\\\\n%& =\\sum\\limits_{i=2}^n \\left(\\dfrac{n!}{i!}\\prod\\limits_{j=i}^{n}(365-(n-j))\\right)\n%\\end{align*}\n%and so\n%\\begin{equation*}\n%\\boxed{\n%P(\\{\\text{at least 2 people share a birthday}\\})=\\dfrac{\\sum\\limits_{i=2}^n \\left(\\dfrac{n!}{i!}\\prod\\limits_{j=i}^{n}(365-(n-j))\\right)}{365^n}\n%}\n%\\end{equation*}\n\\textsc{However}, this seems very laborious to compute, particularly if $n$ is large.\\\\\nWe can instead use the complement rule to determine that\n\\begin{equation*}\n\\boxed{\\begin{split}\nP(\\{\\text{at least 2 people share a birthday}\\})& =1-P(\\{\\overline{\\text{at least 2 people share a birthday}}\\})\\\\\n& =1-P(\\{\\text{no shared birthdays}\\})\\\\\n& =1-\\dfrac{\\text{\\# of ways to select $n$ unshared birthdays}}{365^n}\\\\\n& =1-\\dfrac{365\\times 364\\times\\ldots\\times(365-n+1)}{365^n}\n\\end{split}}\n\\end{equation*}\nFor example, if $n=3$, \n\\begin{align*}\nP(\\{\\text{at least 2 people share a birthday}\\})\n& =1-\\dfrac{\\text{\\# of ways to select 3 unshared birthdays}}{365^n}\\\\\n& =1-\\dfrac{365\\times 364\\times 363}{365^3}\\\\\n& =1-\\dfrac{48\\,228\\,180}{365^3}\\\\\n& =\\dfrac{398\\,945}{365^3}\n\\end{align*}\n\\textsc{Notice} that, if $n>365$, the above calculation produces\n\\begin{align*}\nP(\\{\\text{at least 2\\ldots}\\})& =1-\\dfrac{365\\times(365-1)\\times\\ldots\\times(365-364)\\times(365-365)\\times\\ldots\\times(365-n+1)}{365^n}\\\\\n& =1-\\dfrac{365\\times\\ldots\\times 0\\times\\ldots\\times(365-n+1)}{365^n}\\\\\n& =1-\\dfrac{0}{365^n}\\\\\n& =1-0=1\n\\end{align*}\nWhy does this make sense?\\\\[1ex]\nBy the pigeonhole principle, if we have $n$ objects to place in fewer than $n$ pigeonholes, at least 1 pigeonhole will contain multiple objects. In this case, if there are more than 365 birthdays to distribute over 365 days, at least 2 birthdays will fall on the same day. Thus, the probability of at least 2 people sharing a birthday is 1, or absolutely certain.\\\\[1ex]\n\\textsc{Note} that this counting method counts \\textit{ordered} $n$-tuples: for example, where $n=3$, we consider (1, 1, 2) and (1, 2, 1) to be different combinations of birthdays.\\\\\nIf we were to instead consider unordered $n$-tuples, we could not use the classical definition of probability, since not all outcomes would be equally likely. For example, where $n=3$, the unordered combination (1, 1, 2) is more likely than the unordered combination (1, 2, 3), since there are more ways in which the former can occur.\n\n\n\n\\end{document}", "meta": {"hexsha": "e1ff237bb68e5c019bec343f75ca7abba9a2fcb7", "size": 6069, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "teaching/resources/birthdayProblem.tex", "max_stars_repo_name": "ozhanghe/ozhanghe.github.io", "max_stars_repo_head_hexsha": "7b58b8e325da2c788c4dd7cf5bec4d08d77c24fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-23T17:23:00.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-23T17:23:00.000Z", "max_issues_repo_path": "teaching/resources/birthdayProblem.tex", "max_issues_repo_name": "ozhanghe/ozhanghe.github.io", "max_issues_repo_head_hexsha": "7b58b8e325da2c788c4dd7cf5bec4d08d77c24fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2017-06-05T03:48:15.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-18T03:30:18.000Z", "max_forks_repo_path": "teaching/resources/birthdayProblem.tex", "max_forks_repo_name": "ozhanghe/ozhanghe.github.io", "max_forks_repo_head_hexsha": "7b58b8e325da2c788c4dd7cf5bec4d08d77c24fa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-11T13:35:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T05:34:01.000Z", "avg_line_length": 53.2368421053, "max_line_length": 370, "alphanum_fraction": 0.6826495304, "num_tokens": 2116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672043084051, "lm_q2_score": 0.8918110368115781, "lm_q1q2_score": 0.720643251287712}}
{"text": "\\section{Adjoints of bounded operators}\n\\label{sec:adjoints-bounded-operators}\n\n\\para \nThroughout this section, $\\hilbertH$ stands for a Hilbert space over the \nfield $\\fldK$ of real or complex numbers. \nLet $A \\in \\blinOps (\\hilbertH)$ that is let \n$A:\\hilbertH \\rightarrow \\hilbertH$ be linear and bounded. Then the map\n\\[\n b_A : \\hilbertH \\times \\hilbertH \\to \\fldK, \\: (v,w) \\mapsto \\inprod{v, Aw} \n\\]\nis sesquilinear and bounded with norm\n\\[\n\\norm{b_A} = \\sup \\big\\{ \\left| b_A(v,w)\\right| \\bigmid\n   v,w\\in \\hilbertH \\:\\&\\: \\norm{w}=\\norm{v}=1 \\big\\} = \n                \\norm{A} \\ .\n\\]\nBy \\Cref{thm:correspondence-bounded-sesquilinear-forms-bounded-operators} \nto the Riesz representation theorem there exists a unique element \n$A^* \\in \\blinOps(\\hilbertH)$ such that\n\\[\n b_A (v,w) = \\inprod{A^* v, w} \\quad \n \\text{for all } v,w \\in \\hilbertH \\ .\n\\]\nThis operator satisfies $\\norm{A^*}= \\norm{b_A} = \\norm{A}$. \n\\begin{definition}\nThe unique operator $A^*\\in \\blinOps (\\hilbertH)$ associated to some \n$A\\in \\blinOps(\\hilbertH)$ such that \n\\[\n \\inprod{v,Aw} = \\inprod{A^* v, w} \\quad \n \\text{for all } v,w \\in \\hilbertH \n\\]\nis called the \\emph{adjoint} of $A$.\n\\end{definition}\n\n\\begin{proposition}\nIf $A \\in \\blinOps (\\hilbertH)$, then so is its adjoint $A^* \\in \\blinOps (\\hilbertH)$.\n\\end{proposition}\n\n\\begin{proof}\nFirst we show that $A^*$ is linear. Given $v, w, w' \\in H$, we compute\n\\begin{align*}\n\\inprod{v, A^*(w + w')} &= \\mu_{A, w+w'}(v) = \\inprod{Av, w + w'} = \\inprod{Av, w} + \\inprod{Av, w'}\\\\\n&= \\mu_{A, w}(v) + \\mu_{A, w'}(v) = \\inprod{v, A^*w} + \\inprod{v, A^*w'} = \\inprod{v, A^*w + A^*w'}\n\\end{align*}\nSince this is true for all $v \\in H$, this implies that $A^*(w+w') = A^*w'$.  Furthermore, given $\\lambda \\in \\fldK$, we have\n\\begin{align*}\n\\inprod{v, A^*(\\lambda w)} &= \\mu_{A, \\lambda w}(v) = \\inprod{Av, \\lambda w} = \\widebar \\lambda \\inprod{Av, w}\\\\\n&= \\widebar \\lambda \\mu_{A, w}(v) = \\widebar \\lambda \\inprod{v, A^* w} = \\inprod{v, \\lambda A^*w}.\n\\end{align*}\nAgain, since this is true for all $v \\in H$, we know $A^*(\\lambda w) = \\lambda A^*w$. This proves that $A^*$ is linear.\n\nIt remains to show that $A^*$ is bounded. We know\n\\[\n\\norm{A^*} = \\sup_{\\norm{v} = \\norm{w} = 1} \\abs{\\inprod{v, A^* w}} = \\sup_{\\norm{v} = \\norm{w} = 1} \\abs{\\inprod{w, Av}} = \\norm{A} < \\infty,\n\\]\nwhich is what we wanted to show. Note that $\\norm{A^*} = \\norm{A}$.\n\\end{proof}\n\nWe leave it as an exercise to show that\n\\[\n\\norm{A} = \\sup_{\\norm{v} = \\norm{w} = 1} \\abs{\\inprod{v, Aw}}\n\\]\nfor all $A \\in \\linOps (\\hilbertH)$, as was used in the above proof.\n\n\n\\begin{definition}\nAn operator $A \\in \\linOps (\\hilbertH)$ is called \\emph{self-adjoint} if $A = A^*$, \\emph{unitary} if $A^* = A^{-1}$, and \\emph{normal} if $[A, A^*] = AA^* - A^*A = 0$.\n\\end{definition}\n\n\nWe note that self-adjoint and unitary operators are always normal, but normal operators do not have to be self-adjoint or unitary. In the remainder of these notes, we gather several results on self-adjoint and normal operators.\n\n\\begin{lemma}\nAn operator $A \\in \\linOps (\\hilbertH)$ is self-adjoint if and only if $\\inprod{Av, v} \\in \\R$ for all $v \\in H$.\n\\end{lemma}\n\n\\begin{proof}\n$\\Rightarrow$) If $A$ is self-adjoint, then\n\\[\n\\inprod{Av, v} = \\mu_{A,v}(v) = \\inprod{v, A^*v} = \\inprod{v, Av} = \\overline{\\inprod{Av,v}},\n\\]\nwhich implies that $\\inprod{Av,v} \\in \\R$.\n\n$\\Leftarrow$) Suppose that $\\inprod{Av, v} \\in \\R$ for all $v \\in H$. We know\n\\begin{align*}\n\\inprod{A(v+w), v+w} = \\inprod{Av, v} + \\inprod{Av, w} + \\inprod{Aw, v} + \\inprod{Aw, w}. \\tag{$*$}\n\\end{align*}\nBy assumption, $\\inprod{A(v+w), v+w}$, $\\inprod{Av, v}$, and $\\inprod{Aw, w}$ are all real. This implies that $\\inprod{Av, w} + \\inprod{Aw, v}$ is real as well, so\n\\[\n\\Im \\inprod{Av, w} = -\\Im \\inprod{Aw, v}= \\Im \\inprod{v, Aw}.\n\\]\nSince this holds for all $w \\in H$, it holds for $iw$ as well. Thus,\n\\[\n\\Re \\inprod{Av, w} = \\Im \\inprod{Av, -iw} = \\Im \\inprod{v, A(-iw)} = \\Im i\\inprod{v, Aw} = \\Re \\inprod{v, Aw}.\n\\]\nCombining the above two lines yields $\\inprod{Av, w} = \\inprod{v, Aw}$ for all $v, w \\in H$. Since the adjoint satisfies $\\inprod{Av, w} = \\inprod{v, A^*w}$, this implies that $A = A^*$.\n\\end{proof}\n\n\\begin{proposition}\nIf $A \\in \\linOps (\\hilbertH)$ and $\\inprod{Av, v} = 0$ for all $v \\in H$, then $A = 0$.\n\\end{proposition}\n\n\\begin{proof}\nSince $\\inprod{Av, v} = 0$ for all $v \\in H$, equation ($*$) from Lemma 4 reduces to\n\\[\n\\inprod{Av, w} = -\\inprod{Aw, v} = -\\inprod{w, Av} = -\\overline{\\inprod{Av, w}} \\quad \\text{for all } v, w \\in H \\ ,\n\\]\ni.e.\\ $\\inprod{Av,w}$ has no real part for all $v, w \\in H$. But then fixing $v$ and setting $w = Av$ implies $\\norm{Av}^2 = 0$ for all $v \\in H$, so $A = 0$.\n\\end{proof}\n\n\\begin{proposition}\nIf $A \\in \\linOps (\\hilbertH)$ is self-adjoint, then \n\\[\n\\norm{A} = \\sup_{\\norm{v} = 1} \\abs{\\inprod{Av, v}}.\n\\]\n\\end{proposition}\n\n\\begin{proof}\nWe know\n\\[\n\\norm{A} = \\sup_{\\norm{v} = \\norm{w} = 1} \\abs{\\inprod{Av, w}},\n\\]\nso we clearly have\n\\[\n\\sup_{\\norm{v} = 1} \\abs{\\inprod{Av, v}} \\leq \\norm{A}.\n\\]\n%I'M NOT SURE HOW TO PROVE THE OTHER DIRECTION.\n\\end{proof}\n\n\\begin{proposition}\nIf $A \\in \\linOps (\\hilbertH)$, then $A^*A$ is self-adjoint and $\\norm{A^*A} = \\norm{A}^2$.\n\\end{proposition}\n\n\\begin{proof}\nFor arbitrary $v \\in H$, we have\n\\[\n\\inprod{A^*Av, v} = \\inprod{Av, Av} = \\norm{Av}^2 \\in \\R,\n\\]\nso $A^*A$ is self-adjoint by Lemma 4. By Proposition 6,\n\\[\n\\norm{A^*A} = \\sup_{\\norm{v} = 1} \\abs{\\inprod{A^*Av, v}}  = \\sup_{\\norm{v} = 1} \\norm{Av}^2 = \\norm{A}^2. \n\\]\n\\end{proof}\n\n\\begin{proposition}\nIf $A \\in \\linOps (\\hilbertH)$, then there exist $B,C \\in \\linOps (\\hilbertH)$ self-adjoint such that $A = B+iC$. Furthermore, $A$ is normal if and only if $[B,C] = 0$.\n\\end{proposition}\n\n\\begin{proof}\nWe define\n\\[\nB = \\frac{1}{2}(A + A^*) \\quad \\text{ and } \\quad C = \\frac{i}{2}(A^* - A).\n\\]\nClearly $A = B + iC$. Note also that $A^* = B - iC$. Furthermore, for all $v \\in H$\n\\begin{align*}\n\\inprod{Bv, v} = \\frac{1}{2} \\inprod{Av, v} + \\frac{1}{2}\\inprod{A^*v, v} = \\frac{1}{2}\\inprod{Av, v} + \\frac{1}{2}\\overline{\\inprod{Av, v}} \\in \\R\n\\end{align*}\nand\n\\begin{align*}\n\\inprod{Cv, v} = \\frac{i}{2}\\inprod{A^*v, v} - \\frac{i}{2}\\inprod{Av, v} = \\frac{i}{2}\\overline{\\inprod{Av, v}} - \\frac{i}{2}\\inprod{Av, v} \\in \\R\n\\end{align*}\nThis implies that $B$ and $C$ are self-adjoint by Lemma 4.\n\nFinally, we compute\n\\begin{align*}\n[A, A^*] = [B + iC, B-iC] = -i[B, C] + i[C,B] = -2i[B,C],\n\\end{align*}\nClearly $A$ is normal if and only if $[B,C] = 0$. \n\\end{proof}\n\n\\begin{proposition}\nIf $A$ is normal, then $\\norm{Av} = \\norm{A^*v}$ for all $v \\in H$.\n\\end{proposition}\n\n\\begin{proof}\nUsing the fact that $A^*A = AA^*$, we compute\n\\begin{align*}\n\\norm{Av}^2 = \\inprod{Av, Av} = \\inprod{v, A^*Av} = \\inprod{v, AA^*v} = \\inprod{A^*v, A^*v} = \\norm{A^*v}^2.\n\\end{align*}\nTaking a square root yields the desired result.\n\\end{proof}\n", "meta": {"hexsha": "038d80d8197e899ca081453c2d6716bdba03edc5", "size": 6858, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Example/sections/adjoints-bounded-operators.tex", "max_stars_repo_name": "martinpflaum/latex_to_html", "max_stars_repo_head_hexsha": "65096594cb0891e56954627dc0abeb09bae6d2b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-11-13T15:10:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-21T14:08:26.000Z", "max_issues_repo_path": "Example/sections/adjoints-bounded-operators.tex", "max_issues_repo_name": "martinpflaum/latex_to_html", "max_issues_repo_head_hexsha": "65096594cb0891e56954627dc0abeb09bae6d2b1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2021-07-11T13:18:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-21T22:02:11.000Z", "max_forks_repo_path": "Example/sections/adjoints-bounded-operators.tex", "max_forks_repo_name": "martinpflaum/latex_to_html", "max_forks_repo_head_hexsha": "65096594cb0891e56954627dc0abeb09bae6d2b1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-13T15:22:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-13T15:22:47.000Z", "avg_line_length": 37.4754098361, "max_line_length": 227, "alphanum_fraction": 0.6048410615, "num_tokens": 2878, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.8670357649558007, "lm_q1q2_score": 0.7206307519139826}}
{"text": "\\chapter{Binary Collatz Tree}\n\\label{ch:binary_tree}\n\n\\section{Some essentials on binary trees}\nA binary tree is a rooted tree, where each node has at most two immediate successors. Those nodes, from which no edge goes out downward, are called leaves, the others are called internal nodes. In a full binary tree, all internal nodes have exactly two children \\cite[p.~102]{Ref_Higham_2015}. Full binary trees have an odd number $2n+1$ of nodes. Of these $n+1$ are leaves and $n$ are inner nodes \\cite[p.~134]{Ref_Kersting_Wakolbinger_2008}. Each node in a binary tree has a left subtree and a right subtree, which is why a binary tree is inherently recursive, since the left and right subtrees of the root are themselves binary trees \\cite[p.~246-247]{Ref_Mazur_2010}. As it often pops up in combinatorial problems, the famous $n$-th Catalan number, named after the Belgian mathematician Eugène Catalan, comes in connection with binary trees into play. For $n\\ge1$ it specifies the number of binary trees on $n$ vertices \\cite[p.~247]{Ref_Mazur_2010}:\n\\[\nB_n=\\sum_{i=0}^{n-1}B_iB_{n-1-i}=\\sum_{i=1}^{n}B_{i-1}B_{n-i}=\\frac{1}{n+1}\\binom{2n}{n}\n\\]\n\nThere is an interesting property that trees exhibit regarding abstract algebra. Let's have a look at the algebraic structure of magmas. Consider an element $x$ of a magma $(M,*)$ which is an iterated product of other elements in $M$. Such an element can be described by a planar (no edges cross each other) rooted binary tree whose $n$ leaves are labelled by these other elements $x_1,\\ldots,x_n\\in M$ \\cite[p.~96]{Ref_Kalka_2016}.\n\nBinary trees make well-suited data structures for storing information. With about $2^m$ data points (nodes), a search of a binary tree takes only about $m$ steps, compared to about $2^{m-1}$ steps which are required to search a simple list \\cite[p.~84]{Ref_Benjamin_2009}.\n\n\\section{Transforming the Collatz tree into a binary tree}\nJan Kleinnijenhuis and Alissa M. Kleinnijenhuis \\cite{Ref_Kleinnijenhuis_2020a} introduced a binary tree $T_{\\ge0}$ by transforming the original Collatz tree $H_U$ into the Syracuse tree $H_{C,3}$, which in turn is transformed into the binary tree $T_{\\ge0}$ as described next. The edges are changed according to the following procedure: whenever a parent node $w$ has edges to its child nodes $v_0,v_1,\\ldots,v_n$, on the tree $H_{C,3}$, we draw an edge from $w$ to $v_0$, and edges from $v_i$ to $v_{i+1}$ for each $i=1,\\ldots,n-1$, in the binary new tree. Note that the nodes $v_1,v_2,\\ldots,v_n$ are sorted in increasing order of label $v_0<v_1<\\ldots<v_n$, which is already given by \\ref{eq:n_fold_right_sibling_k}. Figure~\\ref{fig:bt3} and \\ref{fig:bt3_rot} display that tree -- once in our standard layout and once reversed (from bottom to top).\n\n\\begin{figure}[H]\n\t\\includegraphics[width=1.00\\textwidth]{figures/bt_3_t0.png}\n\t\\caption{The Collatz Tree transformed to the binary tree $T_{\\ge0}$}\n\t\\label{fig:bt3}\n\\end{figure}\n\n\\vspace{-2em}\n\\begin{figure}[H]\n\t\\includegraphics[width=1.00\\textwidth]{figures/bt_3_t0_rot.png}\n\t\\caption{The binary tree $T_{\\ge0}$ with \\textit{bottom-to-top} layout orientation}\n\t\\label{fig:bt3_rot}\n\\end{figure}\n\n\\begin{remark}\n\tTo clarify the terminology, it should be mentioned that Jan and Alissa M. Kleinnijenhuis in their manuscripts \\cite{Ref_Kleinnijenhuis_2020a}, \\cite{Ref_Kleinnijenhuis_2020b} denote the original Collatz tree $T_C$ while we call it $H_U$. They denote the Syracuse Tree $T_T$ which in our nomenclature is referred to as $H_{C,3}$.\n\\end{remark}\n\nNodes that are highlighted orange in figures~\\ref{fig:bt3},~\\ref{fig:bt3_rot} are called \\textit{prunable} and they are exactly those nodes resulting as output of the \\textit{Rightward} function. For navigating within this binary tree, Jan Kleinnijenhuis and Alissa M. Kleinnijenhuis \\cite{Ref_Kleinnijenhuis_2020a} defined an \\textit{Upward} function $U(n)$ and a \\textit{Rightward} function $R(n)$ as follows:\n\n\\begin{equation}\n\\label{eq:bintree_3_rightward_upward}\n\\setlength{\\arraycolsep}{1.6em}\n\\begin{array}{cc}\nU(n)=\\begin{cases}\n        4n+1\t&\tn\\equiv 1\\pmod 6\\\\\n        16n+5\t&\tn\\equiv 5\\pmod 6\n    \\end{cases} &\nR(n)=\\begin{cases}\n    \\nicefrac{(2^2n-1)}{3}\t&\tn\\in[1]_{18}\\cup[13]_{18}\\\\\n    \\nicefrac{(2^3n-1)}{3}\t&\tn\\in[5]_{18}\\\\\n    \\nicefrac{(2^4n-1)}{3}\t&\tn\\in[7]_{18}\\\\\n    \\nicefrac{(2^1n-1)}{3}\t&\tn\\in[11]_{18}\\cup[17]_{18}\n\\end{cases}\n\\end{array}\n\\end{equation}\n\nThe domain and codomain of both functions consist of the two residue classes $[1]_6,[5]_6$, which form the multiplicative (cyclic) group $\\mathbb{Z}^\\ast_6=\\{1,5\\}=\\left<5\\right>$. Consequently, the domain and codomain exclude all integers divisible by $2$ and $3$, which is due to the fact that this binary tree (just like our tree $H_{C,3}$) does not contain even numbers and additionally all leaves -- namely those nodes labeled with an integer divisible by three -- were deleted. The function $U(n)$ is very similar to the function~\\ref{eq:next_sibling_k3} and to the more general function~\\ref{eq:n_fold_right_sibling_k} (when setting $n=1,k=3$) which both calculate the right-sibling of a given vertex. This is clear, since siblings (parallel) in $H_{C,3}$ are successors (serial) in the binary tree $T_{\\ge0}$. In the end, for a node $v_0$ having a leaf as right-sibling in $H_{C,3}$, the function $U(v_0)$ is defined as $v_1=4v_0+1$ executed twice $v_1=4(4v_0+1)+1=16v_0+5$, because we must skip this leaf. Recall that all leafs in $H_{C,3}$ are excluded from the binary tree without exception. For any $n\\in[5]_6$ it applies that $U(n)\\equiv16n+5\\equiv\\boldsymbol{1}\\bmod(6)$ since $6\\mid16n+5-\\boldsymbol{1}$ resulting in $6\\mid16(5+k\\cdot6)+5-\\boldsymbol{1}$, see \\ref{eq:congruence}, and analogously for any $n\\in[1]_6$ it applies that $U(n)\\equiv4n+1\\equiv\\boldsymbol{5}\\bmod(6)$ since $6\\mid4n+1-\\boldsymbol{5}$ resulting in $6\\mid4(1+k\\cdot6)+1-\\boldsymbol{5}$. Therefore executing the Upward function twice in a row leads unconditionally to $U^2(n)=16(4n+1)+5=4(16n+5)+1=64n+21$.\n\n\\begin{remark}\n\tWhile we displayed trees from top to down, it is sometimes usual to draw trees in a bottom-to-top fashion as Kleinnijenhuis \\cite{Ref_Kleinnijenhuis_2020b} do. The Rightward function corresponds to what we call left-child and the Upward function relates to the right-child which is commonly used in the context of binary trees \\cite[p. 246]{Ref_Mazur_2010}.\n\\end{remark}\n\nJan and Alissa M. Kleinnijenhuis \\cite{Ref_Kleinnijenhuis_2020a} defined the set $N(T_C)=N(H_U)$ that contains the labels of all nodes, to which a path from the root in $H_U$ exists, in other words, this set contains all integers $n$ for which the orbit of $n$ under the (uncompressed) Collatz function~\\ref{eq:func_collatz} converges to $1$. Furthermore they introduced $S_{\\ge0}$ as the node set containing integers that are neither divisible by $2$ nor by $3$. The set $S_{-1}$ comprises on the contrary all numbers, which are divisible by $2$ or $3$. In order to comprehend the structure of these sets $S$, let us take a look at the following list showing which tree includes which node set, see also the ancillary files of \\cite{Ref_Kleinnijenhuis_2020a}, \\cite{Ref_Kleinnijenhuis_2020b}:\n\n\\[\\arraycolsep=0.6em\\def\\arraystretch{1.4}\n\\begin{array}{llll}\n\\text{Original Collatz tree} & N(T_C)=N(H_U)&=&\\mathbb{N^+} \\hspace{0.6em}\\text{if the Collatz conjecture holds}\\\\\n\\text{Syracuse tree} & N(T_T)=N(H_{C,3})&=&N(T_C)\\setminus2\\mathbb{N}\\\\\n\\text{Binary tree}\\hspace{0.6em}T_{\\ge0}& N(T_{\\ge0})=S_{\\ge0}&=&N(T_C)\\setminus S_{-1}\\hspace{2.1em}=S_{0}\\cup S_{1}\\cup S_{2}\\ldots\\\\\n\\text{Binary tree}\\hspace{0.6em}T_{\\ge1}& N(T_{\\ge1})=S_{\\ge1}&=&N(T_C)\\setminus \\bigcup_{i=-1}^{0}S_i=S_{1}\\cup S_{2}\\cup S_{3}\\ldots\\\\\n\\text{Binary tree}\\hspace{0.6em}T_{\\ge j} & N(T_{\\ge j})=S_{\\ge j}&=&N(T_C)\\setminus \\bigcup_{i=-1}^{j-1}S_i=\\bigcup_{i=j}^{\\infty}S_i\n\\end{array}\n\\]\n\n\\par\\medskip\nLet us describe these sets using multiplicative groups. The set $S_{\\ge0}=\\mathbb{Z}^\\ast_6$ can be understood as the multiplicative group modulo $6$ and the set $S_{-1}=\\mathbb{Z}/6\\mathbb{Z}\\setminus\\mathbb{Z}^\\ast_6=\\{0,2,3,4\\}$ as the set of all non-invertible elements (non-units) of $\\mathbb{Z}/6\\mathbb{Z}$.\n\nThe set $S_0$ consists of all nodes resulting as output of $R(n)$ within the binary tree $T_{\\ge0}$. These are the orange highlighted nodes displayed by figures~\\ref{fig:bt3},~\\ref{fig:bt3_rot}. In other words, $S_0$ is the codomain of the function $R(n)$ operating on nodes within $T_{\\ge0}$. The binary tree $T_{\\ge0}$ can be transformed to a (pruned) binary tree $T_{\\ge1}$. For this, the prunable nodes will be deleted and their neighbors reconnected. The upward neighbor of a pruned node will then be identified as pruning candidate for a later transformation of the resulting tree $T_{\\ge1}$ to a more pruned tree $T_{\\ge2}$.\n\nThe set $S_1$ contains all nodes that are (as per the description above) identified as pruning candidates for the next transformation of $T_{\\ge1}$ to $T_{\\ge2}$. After having transformed $T_{\\ge1}$ to $T_{\\ge2}$, the more pruned binary tree $T_{\\ge2}$ contains nodes that are identified as pruning candidates for another upcoming transformation of $T_{\\ge2}$ to $T_{\\ge3}$ -- these nodes are elements of the set $S_2$. This pruning algorithm is repeatedly applied in the same pattern. And in this way we obtain the sets $S_1,S_2,S_3,\\ldots$ and so forth. Generally, we can write these sets in the form $S_j=\\{n\\in N(T_{j-1})\\mid U^{-j}(n)\\in S_0\\}$. Kleinnijenhuis found out that the codomain $\\mathbb{N}^U$ of the Upward function contains $5$ residue classes modulo $96$, namely $\\{5, 29, 53, 77, 85\\}=\\mathbb{N}^U$ and the codomain $\\mathbb{N}^R$ of the Rightward function comprises $27$ residue classes modulo $96$, namely $\\{1, 7, 11, 13, 17, 19, 23, 25, 31, 35, 37, 41, 43, 47, 49, 55, 59, 61, 65, 67, 71, 73, 79, 83, 89, 91, 95\\}=\\mathbb{N}^R$. The union of both sets $\\mathbb{N}^U\\cup\\mathbb{N}^R$ forms the non-cyclic multiplicative group $\\mathbb{Z}^\\ast_{96}$, whose generating set is $\\{5, 17, 31\\}$ (see \\cite{Ref_Lang_2017}, \\cite{Ref_OESIS_A033949}). All elements of the Upward function's codomain have the same remainder $5$ when divided by $8$.\n\nFor each subset $X$ of a group $G$, the intersection over all subgroups (of $G$) that contain this subset $X$ is \\cite[p.~34]{Ref_Karpfinger_Meyberg_2017}:\n\\[\n\\left<X\\right>=\\bigcap_{X\\subseteq U\\le G}U\n\\]\n\nFirstly it applies $\\left<X\\right>\\le G$ meaning that this intersection is again a subgroup of $G$. It is generated by the \\textit{generating set} $X$ and it is the smallest subgroup of $G$ containing every element of $X$ \\cite[p.~35]{Ref_Karpfinger_Meyberg_2017}. Secondly, $\\left<X\\right>\\subseteq U$ for each subgroup $U$ (of $G$) containing $X$.  Thirdly, when there is only a single element $x$ in $X$, then $\\left<X\\right>$ is usually written as $\\left<x\\right>$ and in this case, $\\left<x\\right>$ is the cyclic subgroup of $G$ -- such situations we have already seen in section~\\ref{sec:left_child_right_sibling_3}. Let us refer back to $\\mathbb{Z}^\\ast_{96}$. In this example, $\\left<\\{5,17,31\\}\\right>$ is the subgroup generated by $\\{5,17,31\\}$ and therefore every element of $\\mathbb{Z}^\\ast_{96}$ is of the form $5^l17^m31^n$ where $l\\in\\{0,1,\\ldots,7\\}$ because the element $5$ has order $8$, and similarly $m,n\\in\\{0,1\\}$ since both elements $17$ and $31$ have order $2$. Non-cyclic groups can be cyclic decomposed, which is detailed by Gallian and Rusin \\cite{Ref_Gallian_Rusin_1980} and Cheng \\cite{Ref_Cheng_1989} using the concept of the external direct product \\cite[p.~79]{Ref_Karpfinger_Meyberg_2017}, \\cite[p.~156]{Ref_Gallian} and the internal direct product \\cite[p.~80]{Ref_Karpfinger_Meyberg_2017}, \\cite[p.~183]{Ref_Gallian}. A comprehensive table of cyclic decompositions of multiplicative non-cyclic groups of integers modulo $n$ up to $n=130$ is provided by Wolfdieter Lang \\cite{Ref_Lang_2017}.\n\n% http://mathonline.wikidot.com/the-internal-direct-product-of-two-groups\n\nLet us take a closer look at the (cyclic) multiplicative group $\\mathbb{Z}^\\ast_{18}=\\{1,5,7,11,13,17\\}=\\left<5\\right>$ which has an order $ord(\\mathbb{Z}^\\ast_{18})=6$. Having the generator $5$ coprime to the modulus $18$, we obtain the congruence $5^{\\phi(18)}\\equiv1\\pmod{18}$ in accordance with Euler's theorem \\ref{eq:eulers_theorem}. This allows us to infer from $5^6\\equiv5^{6(n+1)}\\equiv5^j5^{6n+6-j}\\equiv1\\pmod{18}$ the congruences given by \\ref{eq:homomorphism_congruences} (on the left).\n\nIf a natural number divides another, $m\\mid n$, as in our case $3\\mid18$, then for two integers $a,b$ the following implication holds, see \\cite[p.~21]{Ref_Mueller-Stach_2011}:\n\n\\begin{equation}\n\t\\label{eq:reduce_modulus}\n\ta\\equiv b\\pmod n\\rightarrow a\\equiv b\\pmod m\n\\end{equation}\n\nThis means in our case $w\\cdot5^{6n+6}\\equiv 1\\pmod{18}\\rightarrow w\\cdot5^{6n+6}\\equiv 1\\pmod 3$.\nIn fact, Euler's theorem (\\ref{eq:eulers_theorem}) gives us two congruences $5^{\\phi(18)}\\equiv1\\pmod{18}$ and $2^{\\phi(3)}\\equiv1\\pmod{3}$. The latter is obvious, because $\\mathbb{Z}_3^\\ast=\\left<2\\right>$. Since $\\phi(18)=6$ and $\\phi(3)=2$, every power of five with an exponent divisible by $6$ and every power of two with an exponent divisible by 2 belong to the residue classes $[1]_{18}$ and $[1]_3$.\n\nBecause of $[1]_{18}=[5^0]_{18},\\ldots,[13]_{18}=[5^4]_{18}$ and finally $[11]_{18}=[5^5]_{18}$ we obtain the congruences on the left side in \\ref{eq:homomorphism_congruences}. The exponents are indicated by the $j$. For example, it follows from $w\\in[13]_{18}$ that $[w\\cdot5^{6n+2}]_{18}=[w]_{18}\\cdot[5^{6n+2}]_{18}=[13]_{18}\\cdot[5^{6n+2}]_{18}=[5^4]_{18}\\cdot[5^{6n+2}]_{18}=[5^{6n+6}]_{18}=[1]_{18}$, because $6n+6$ is divisible by $6$ (Euler's theorem).\n\nFrom the equality of the residue classes modulo $18$ and modulo $3$ (according to equation~\\ref{eq:reduce_modulus}) it follows for $w\\in[13]_{18}$ from $[w]_{18}\\cdot[5^{6n+2}]_{18}=[13]_{18} \\cdot[5^{6n+2}]_{18}=[1]_{18}$ the following equation:\n\n\\begin{equation}\n\\label{eq:mod_18_3}\n[1]_3=[w]_3\\cdot[5^{6n+2}]_3=[13]_3\\cdot[5^{6n+2}]_3\n\\end{equation}\n\nJust replacing $18$ with $3$, that is the homomorphism given by the map $f:\\mathbb{Z}^\\ast_n\\rightarrow \\mathbb{Z}^\\ast_m$ with $f(r\\bmod n)=r\\bmod m$ as long as $\\gcd(r\\bmod n,n)=1$ leads to $\\gcd(r\\bmod m,m)=1$. By Euclid, we know that in the case $r$ is coprime to $n$ then it is also coprime to every factor $m$ of $n$. That is why a homomorphism exist to the congruences shown in \\ref{eq:homomorphism_congruences} (on the right).\n\nUsing the fact that $[5^{6n}]_{18}=[5^0]_{18}=[1]_{18}$ and thus $[5^{6n+k}]_{18}=[5^k]_{18}=[5]_{18}^k=[5]_3^k$, we obtain from equation~\\ref{eq:mod_18_3}:\n\n\\[\n[1]_3=[13]_3\\cdot[5]_3^2=[13]_3\\cdot[2]_3^2\n\\]\n\nTherefore $[13]_{18}\\cdot4=[13]_3\\cdot4\\equiv1\\pmod{3}$. The third and the last row in \\ref{eq:homomorphism_congruences} are obtained in the same way. The powers of two that appear in the other rows result from the fact that we can always add or remove even powers of two because $[2^2]_3=[1]_3$.\n\nBased on equation~\\ref{eq:congruence_reduction} we can state that $a\\equiv b\\pmod m$ implies $(a+m)\\equiv b\\pmod m$. Let us set $a=w\\cdot2^{2n+2}$ and $b=1$ and $m=3$, then we obtain $(w\\cdot2^{2n+2}+3)\\equiv1\\pmod3$ and using a factor $i\\in\\mathbb{N}$ we obtain the more general congruence $(w\\cdot2^{2n+2}+3i)\\equiv1\\pmod3$. As a consequence the congruences in \\ref{eq:homomorphism_congruences} are true, while $w\\cdot5^{6n+6}=w\\cdot2^{2n+2}+3\\cdot i$ or rather while $3\\mid(5^{6n+6}-2^{2n+2})$. These conditions continue $3\\mid(5^{6n+5}-2^{2n+3})$ and $3\\mid(5^{6n+4}-2^{2n+4})$ and so forth.\n\n\\begin{equation}\n\\label{eq:homomorphism_congruences}\n\\begin{array}{llllll}\n\tj=0, & w\\in [1]_{18} & \\hspace{1em} w\\cdot5^{6n+6}&\\equiv1\\pmod{18}&\\hspace{4em}w\\cdot2^{2n+2} &\\equiv1\\pmod{3}\\\\\n\tj=1, & w\\in [5]_{18} & \\hspace{1em} w\\cdot5^{6n+5}&\\equiv1\\pmod{18}&\\hspace{4em}w\\cdot2^{2n+3} &\\equiv1\\pmod{3}\\\\\n\tj=2, & w\\in [7]_{18} & \\hspace{1em} w\\cdot5^{6n+4}&\\equiv1\\pmod{18}&\\hspace{4em}w\\cdot2^{2n+4} &\\equiv1\\pmod{3}\\\\\n\tj=3, & w\\in [17]_{18} & \\hspace{1em} w\\cdot5^{6n+3}&\\equiv1\\pmod{18}&\\hspace{4em}w\\cdot2^{2n+1} &\\equiv1\\pmod{3}\\\\\n\tj=4, & w\\in [13]_{18} & \\hspace{1em} w\\cdot5^{6n+2}&\\equiv1\\pmod{18}&\\hspace{4em}w\\cdot2^{2n+2} &\\equiv1\\pmod{3}\\\\\n\tj=5, & w\\in [11]_{18} & \\hspace{1em} w\\cdot5^{6n+1}&\\equiv1\\pmod{18}&\\hspace{4em}w\\cdot2^{2n+1} &\\equiv1\\pmod{3}\n\\end{array}\n\\end{equation}\n\nThe inverse upward function, which can be understood as a downward function $U^{-1}(n)=D(n)$ is defined as follows:\n\n\\[\nD(n)=U^{-1}(n)=\\begin{cases}\n\t\\nicefrac{n-1}{4}\t&\tn\\equiv 5\\pmod{24}\\\\\n\t\\nicefrac{n-5}{16}\t&\tn\\equiv 85\\pmod{96}\n\\end{cases}\n\\]\n\nThe modular conditions are deduced as follows: We have $D(n)=\\nicefrac{n-1}{4}$ if $\\nicefrac{n-1}{4}\\equiv1\\pmod6$ and $D(n)=\\nicefrac{n-5}{16}$ if $\\nicefrac{n-5}{16}\\equiv5\\pmod6$. For $a,b\\in\\mathbb{Z}$ and $n,m\\in\\mathbb{N}$ we can apply the following modular arithmetic rule \\cite[p.~21]{Ref_Mueller-Stach_2011}:\n\n\\begin{equation}\na\\equiv b\\pmod n \\leftrightarrow m\\cdot a\\equiv m\\cdot b\\pmod{m\\cdot n}\n\\end{equation}\n\nThis leads to $D(n)=n-1$ if $n-1\\equiv4\\pmod{24}$ and $D(n)=n-5$ if $n-5\\equiv80\\pmod{96}$.\n\nNow we make the use of another modular arithmetic rule, which for two given congruences $a\\equiv b\\pmod n$ and $c\\equiv d\\pmod n$ states that \\cite[p.~19]{Ref_Mueller-Stach_2011}:\n\n\\begin{equation}\n\ta+c\\equiv b+d\\pmod n\\hspace{2em} \\text{and}\\hspace{2em}a\\cdot c\\equiv b\\cdot d\\pmod n\n\\end{equation}\n\nThis finally leads to $D(n)=n-1$ if $n\\equiv5\\pmod{24}$ and $D(n)=n-5$ if $n\\equiv85\\pmod{96}$.\n\nThe rightward function that operates on the tree of pruning level $1$, thus the tree $T_{\\ge1}$, is can be expressed as the right-to-left composition $R_{\\ge1}(n)=U\\circ R\\circ U^{-1}(n)=U\\circ R\\circ D(n)$ and it is defined as follows:\n\n\\[\nR_{\\ge1}(n)=\\begin{cases}\n\t\\nicefrac{(8D(n)-1)}{3}\t&\t2D(n)\\equiv4\\bmod{18}\\wedge D(n)\\in[11]_{18}\\cup[17]_{18}\\\\\n\t\\nicefrac{(16D(n)-1)}{3}\t&\t4D(n)\\equiv4\\bmod{18}\\wedge D(n)\\in[11]_{18}\\cup[13]_{18}\\\\\n\t\\nicefrac{(32D(n)-1)}{3}\t&\t2D(n)\\equiv16\\bmod{18}\\wedge D(n)\\in[11]_{18}\\cup[17]_{18}\\vee D(n)\\in[5]_{18}\\\\\n\t\\nicefrac{(64D(n)-1)}{3}\t&\t4D(n)\\equiv16\\bmod{18}\\wedge D(n)\\in[1]_{18}\\cup[13]_{18}\\vee D(n)\\in[7]_{18}\\end{cases}\n\\]\n\n\\[\nR_{\\ge2}(n)=\\begin{cases}\n\t\\nicefrac{(32D^2(n)-1)}{3}\t&\t2D^2(n)\\in[4]_{18}\\wedge D^2(n)\\in[11]_{18}\\vee8D^2(n)\\in[4]_{18}\\wedge D^2(n)\\in[17]_{18}\\\\\n\t\\nicefrac{(64D^2(n)-1)}{3}\t&\tD^2(n)\\in[1]_{18}\\cup[13]_{18}\\wedge4D^2(n),16D^2(n)\\in[4]_{18}\\\\\n\t\\nicefrac{(128D^2(n)-1)}{3}\t& \\parbox[t]{.7\\textwidth}{$\tD^2(n)\\in[11]_{18}\\cup[17]_{18}\\wedge(2D^2(n)\\in[4]_{18}\\wedge8D^2(n)\\in[16]_{18}\\vee2D^2(n)\\in[16]_{18}\\wedge32D^2(n)\\in[4]_{18})$}\\\\\n\t\\nicefrac{(256D^2(n)-1)}{3}\t&\tD^2(n)\\in[1]_{18}\\vee D^2(n)\\in[7]_{18}\\cup[13]_{18}\\wedge64D^2(n)\\in[4]_{18}\\\\\n\t\\nicefrac{(512D^2(n)-1)}{3}\t&\t32D^2(n)\\in[16]_{18}\\wedge(2D^2(n)\\in[16]_{18}\\wedge D^2(n)\\in[11]_{18}\\cup[17]_{18}\\vee D^2(n)\\in[5]_{18})\\\\\n\t\\nicefrac{(1024D^2(n)-1)}{3}\t&\t64D^2(n)\\in[16]_{18}\\wedge(D^2(n)\\in[7]_{18}\\vee4D^2(n)\\in[16]_{18}\\wedge D^2(n)\\in[1]_{18}\\cup[13]_{18})\\end{cases}\n\\]\n\n\\newpage\nFigure~\\ref{fig:tree_transformations} shows the complete chain of tree transformations, beginning from the original Collatz tree, over the Syracuse tree to the binary tree and pruned ones.\n\n% trim=left bottom right top\n\\begin{figure}[H]\n\t\\includegraphics[trim=1.1cm 10cm 2.6cm 0.2cm, \n\twidth=1.00\\textwidth,page=1]{figures/tree_transformations.pdf}\n\t\\caption{Transformation chain, beginning from the original Collatz tree up to pruned binary trees}\n\t\\label{fig:tree_transformations}\n\\end{figure}", "meta": {"hexsha": "486fb17e6f3845bf8ebae0d70a378d7f6419719f", "size": 19622, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01 Graph Theory/TeX/v6.0/chapter/03_binary_tree.tex", "max_stars_repo_name": "Sultanow/collatz", "max_stars_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-01T15:12:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T15:54:55.000Z", "max_issues_repo_path": "01 Graph Theory/TeX/v6.0/chapter/03_binary_tree.tex", "max_issues_repo_name": "Sultanow/collatz", "max_issues_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01 Graph Theory/TeX/v6.0/chapter/03_binary_tree.tex", "max_forks_repo_name": "Sultanow/collatz", "max_forks_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-06T20:44:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-06T20:44:07.000Z", "avg_line_length": 105.4946236559, "max_line_length": 1595, "alphanum_fraction": 0.7079808378, "num_tokens": 7315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8670357563664175, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.720630746588202}}
{"text": "\\chapter{The Hamiltonian Method}\n\\section{Basics}\n\\begin{definition}\nIf the determinant of the matrix \n\\begin{align}\na_{ik} = \\frac{\\partial^2 L(q_m,\\dot{q}_m)}{\\partial \\dot{q}_i \\partial \\dot{q}_k}\n\\end{align}\nvanishes, the Lagrangian is called degenerate. Otherwise, $L$ is nondegenerate or regular.\n\\end{definition}\nWhen the Lagrangian is degenerate, some of the velocities $\\dot{q}_i$ can disappear when we try to find $p_i(q_i,\\dot{q}_i)$. We are left with an equation depending on the coordinates and momenta, called a constraint.\n\\begin{definition}[Primary constraint]\nEquations of the form\n\\begin{align}\n\\phi_m(q_i,p_i) = 0, \n\\end{align}\nwhere $m = 1, ..., M$ is the number of constraints, are called primary constraints when they follow from the definition of the generalized momentum.\n\\end{definition}\nLet's illustrate what these constraints mean. One can visualize the state of a mechanical system with $n$ degrees of freedom as a point $(q_i,p_i)$ in a $2n$-dimensional phase space ($n$ coordinates and $n$ momenta). The coordinates of this point (the state) depend on time and evolve according to the Hamiltonian equations of motion. \n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=1.28]{img/constraint.pdf}\n\\end{center}\n\\caption{Two intersecting constraint surfaces. The system is only allowed to be in states in which both constraints are fulfilled.}\n\\label{fig:1}\n\\end{figure}\nIn general, the trajectory of this point can fill the whole phase space. When we have constraints, the system is only allowed to be in states in which the constraints are fulfilled. In phase space, they build hypersurfaces on which the point is allowed to move. If every constraint can be fulfilled, the point will move on the intersections of all constraints, like visualized in Fig. \\ref{fig:1}. But how to include this into the mathematical formalism? \\\\\nTo see, how the constraints enter into the Hamiltonian equations of motion\n\\begin{align}\n\\dot{q}_i &= \\frac{\\partial H}{\\partial p_i} \\label{eq:1} \\\\\n\\dot{p}_i &= - \\frac{\\partial H}{\\partial q_i} \\label{eq:2}\n\\end{align}\nand change the dynamics, it will be very useful to write them with Poisson brackets.\n\\begin{definition}[Poisson bracket]\n\\begin{align}\n\\left \\{ f(q_i, p_i),g(q_i, p_i) \\right \\} \\equiv \\sum_{i=1}^n \\left( \\frac{\\partial f}{\\partial q_i} \\frac{\\partial g}{\\partial p_i} - \\frac{\\partial g}{\\partial q_i} \\frac{\\partial f}{\\partial p_i} \\right).\n\\end{align}\n\\end{definition}\nSome properties of the Poisson bracket are:\n\\begin{enumerate}\n\\item \\(\n\\begin{aligned}[t]\n\\left \\{ f,g \\right \\} = - \\left \\{ g,f \\right \\}\n\\end{aligned} \\) \\ - \\ anticommutative\n\\item \\(\n\\begin{aligned}[t]\n\\left \\{ \\alpha f_1 + \\beta f_2,g \\right \\} = \\alpha \\left \\{ f_1,g \\right \\} + \\beta \\left \\{ f_2,g \\right \\} \n\\end{aligned} \\) \\ - \\ bilinear\n\\item \\(\n\\begin{aligned}[t]\n\\left \\{  f_1 f_2,g \\right \\} = f_1 \\left \\{ f_2,g \\right \\} + f_2 \\left \\{ f_1,g \\right \\} \n\\end{aligned} \\) \\ - \\ \"derivative\"\n\\item \\(\n\\begin{aligned}[t]\n\\left \\{ \\left \\{ f,g \\right \\},h \\right \\} + \\left \\{ \\left \\{ g,h \\right \\},f \\right \\} + \\left \\{ \\left \\{ h,f \\right \\},g \\right \\} = 0 \n\\end{aligned} \\) \\ - \\ Jacobi identity\n\\end{enumerate}\nThese rules hold for any three functions $f,g,h$ of phase space and time (observables).\n\\begin{theorem}\\label{theorem}\nThe time evolution for any observable $g(q_i,p_i)$ is\n\\begin{equation}\\label{eq:3}\n\\dot{g} = \\frac{dg}{dt} = \\left \\{ g,H \\right \\}. \n\\end{equation}\nIt is equivalent to the Hamiltonian equations of motion.\n\\end{theorem}\n\\begin{proof}\n\"$\\Rightarrow$\" By definition of the total derivative we have\n\\begin{align}\n\\frac{dg}{dt} = \\sum_{i=1}^n \\left( \\frac{\\partial g}{\\partial q_i} \\dot{q}_i + \\frac{\\partial g}{\\partial p_i} \\dot{p}_i \\right) = \\sum_{i=1}^n \\left( \\frac{\\partial g}{\\partial q_i} \\frac{\\partial H}{\\partial p_i} - \\frac{\\partial g}{\\partial p_i} \\frac{\\partial H}{\\partial q_i} \\right) = \\left \\{ g,H \\right \\},\n\\end{align}\nwhere we used the Hamiltonian equations of motion \\eqref{eq:1} and \\eqref{eq:2}. \\\\\n\"$\\Leftarrow$\" Choose $g = q_k$ and get\n\\begin{align}\n\\dot{q}_k = \\left \\{ q_k,H \\right \\} = \\frac{\\partial H}{\\partial p_k}.\n\\end{align}\nAnalog, with $g = p_k$ we get\n\\begin{align}\n\\dot{p}_k = \\left \\{ p_k,H \\right \\} = - \\frac{\\partial H}{\\partial q_k}.\n\\end{align}\n\\end{proof}\nFrom now on, we will use equation \\eqref{eq:3} when we talk about equation of motion. This notation has the big advantage that it can be generalized directly under quantization:\n\\begin{align}\n\\left \\{ f,g \\right \\} \\  \\longrightarrow \\ \\frac{1}{i \\hbar} \\ [\\hat{f},\\hat{g}].\n\\end{align}\nSo when we quantize our system and $\\hat{g}(\\hat{q}_i,\\hat{p}_i)$ is an operator, the equation of motion take the form\n\\begin{align}\n\\frac{d}{dt}\\hat{g} = \\frac{i}{\\hbar} \\ [\\hat{H} , \\hat{g}],\n\\end{align}\nwhich is equivalent to the Heisenberg and Schrödinger equation.\n\n\n\\section{From the Lagrangian to the Hamiltonian}\nSuppose we have a Lagrangian $L = L(q_i,\\dot{q}_i)$. The first step to get the Hamiltonian\n\\begin{align}\nq_i \\longrightarrow p_i \\equiv \\frac{\\partial L(q_i,\\dot{q}_i)}{\\partial \\dot{q}_i} = p_i(q_i,\\dot{q}_i)\n\\end{align}\nis always possible because one can still differentiate, even when $L$ is degenerate.\nFor the next step, to express the Hamiltonian only through $q_i$ and $p_i$, it can happen that some velocities $\\dot{q}_k$ vanish when we try to calculate the generalized momenta. In this case, it is not possible to express $\\dot{q}_k$ through the conjugated momentum $p_k$ and we are left with a primary constraint. So we have not set them by hand, they arised from the definition of the generalized momentum. But there is a nice theorem:\n\\begin{theorem}\nEven if we cannot invert the definition of the generalized momentum and express some velocities through their momenta, \n\\begin{align}\nH(q_i,\\dot{q}_i) = \\sum_{i=1}^{n} \\dot{q}_i p_i(q_i,\\dot{q}_i) - L(q_i,\\dot{q}_i), \n\\end{align}\nis still a function of the coordinates and momenta, all velocities can be eliminated.\n\\end{theorem}\n\\begin{proof}\nThe variation of this function is\n\\begin{align}\n\\delta H(q_i,\\dot{q}_i) &= \\sum_{k=1}^{n} \\left( \\frac{\\partial H}{\\partial q_k} \\delta q_k + \\frac{\\partial H}{\\partial \\dot{q}_k} \\delta \\dot{q}_k \\right) \\notag \\\\\n&= \\sum_{k=1}^{n} \\left( \\sum_{i=1}^n \\dot{q}_i \\frac{\\partial p_i}{\\partial q_k} - \\frac{\\partial L}{\\partial q_k} \\right) \\delta q_k + \\sum_{k=1}^n \\left( p_k + \\sum_{i=1}^n \\dot{q}_i \\frac{\\partial p_i}{\\partial \\dot{q}_k} - \\frac{\\partial L}{\\partial \\dot{q}_k} \\right) \\delta \\dot{q}_k \\notag \\\\\n&= \\sum_{i=1}^{n} \\dot{q}_i \\left( \\sum_{k=1}^n \\frac{\\partial p_i}{\\partial q_k} \\delta q_k + \\sum_{k=1}^n \\frac{\\partial p_i}{\\partial \\dot{q}_k} \\delta \\dot{q}_k \\right) - \\sum_{k=1}^n \\frac{\\partial L}{\\partial q_k} \\delta q_k \\notag \\\\\n&= \\sum_{i=1}^n \\dot{q}_i \\delta p_i - \\sum_{i=1}^n \\frac{\\partial L}{\\partial q_i} \\delta q_i.\n\\end{align}\nSince we can rewrite the variation in terms of $\\delta q_i$ and $\\delta p_i$, the Hamiltonian can be expressed as a function of the coordinates and momenta only.\n\\end{proof}\nComparing the terms in the last line with the variation of $H$ with respect to $\\delta q_i$ and $\\delta p_i$ and using the Euler-Lagrange-equation, one can find the Hamilton equations of motion. \\\\\nBut it is not so easy after all. Remember that we still can have primary constraints $\\phi_m$ with vanashing variation:\n\\begin{align}\n\\delta \\phi_m = 0 = \\sum_{i=1}^n \\left( \\frac{\\partial \\phi_m}{\\partial q_i} \\delta q_i + \\frac{\\partial \\phi_m}{\\partial p_i} \\delta p_i \\right).\n\\end{align}\nSo we could add this variation to the variation of the Hamiltonian without changing it. This is very useful because normally, $M$ constraints would result in $2n - M$ independent equations of motion but most times, it is easier just to add $M$ independent arbitrary coefficients/functions than reducing the number of equations. So we return the lost degrees of freedom by multiplying our constraints with arbitrary functions $u_m$ and adding them to our variation.\nContinuing this idea, since the variation of the constraints is zero, we can add\n\\begin{align}\n0 = \\sum_{m=1}^M u_m \\delta \\phi_m = \\sum_{m=1}^M u_m \\sum_{i=1}^n \\left( \\frac{\\partial \\phi_m}{\\partial q_i} \\delta q_i + \\frac{\\partial \\phi_m}{\\partial p_i} \\delta p_i \\right)\n\\end{align}\nto \n\\begin{align}\n\\sum_{i=1}^n \\left( \\frac{\\partial H}{\\partial p_i} - \\dot{q}_i \\right) \\delta p_i + \\sum_{i=1}^n \\left( \\frac{\\partial H}{\\partial q_i} + \\dot{p}_i \\right) \\delta q_i = 0,\n\\end{align}\nwhere we used the Hamilton equations of motion, and get\n\\begin{align}\n\\frac{\\partial H}{\\partial p_i} + \\sum_{m=1}^M u_m \\frac{\\partial \\phi_m}{\\partial p_i} &= \\dot{q}_i \\\\\n\\frac{\\partial H}{\\partial q_i} + \\sum_{m=1}^M u_m \\frac{\\partial \\phi_m}{\\partial q_i} &= - \\dot{p}_i,\n\\end{align}\nwhich are $2n$ equations with $M$ independent extra-functions. \nIt looks like these extra-functions were added to the Hamiltonian, so the following definition is reasonable:\n\\begin{definition}[Total Hamiltonian]\n\\begin{align}\nH_T(q_i,p_i) \\equiv H(q_i,p_i) + \\sum_{m=1}^M u_m(q_i,p_i) \\phi_m(q_i,p_i).\n\\end{align}\n\\end{definition}\nNow we want to adapt our results to the formulations of the equations of motion with Poisson brackets. We claim that\n\\begin{align}\n\\dot{g} = \\left \\{ g,H_T \\right \\} &= \\left \\{ g,H \\right \\} + \\sum_{m=1}^M u_m  \\left \\{ g,\\phi_m \\right \\} + \\sum_{m=1}^M \\left \\{ g,u_m \\right \\} \\phi_m \\notag \\\\\n&\\approx \\left \\{ g,H \\right \\} + \\sum_{m=1}^M u_m  \\left \\{ g,\\phi_m \\right \\},\n\\end{align}\nwhere we have used that all constraints are zero on the constraint surface in the last step. The proof is analog to the proof of Theorem~\\ref{theorem}. \\\\\n\nAt this point, we should say something about the usage of constraints and \\textit{weak equalities}. First of all, we are not allowed to use the constraints inside a Poisson bracket. We have to calculate the Poisson bracket first and then apply the constraint when it is outside the bracket. If two quantities $f,g$ differ only by a linear combination of constraints, we call them weakly equal (denoted by $f \\approx g$). We will use this notation sometimes to distinguish them from usual or strong equations.\n\n\\begin{example}\nConsider the Lagrangian\n\\begin{align}\nL = L(q,\\dot{q}) = q \\dot{q} - \\frac{q^2}{2}.\n\\end{align}\nFrom the definition of the generalized momentum follows a primary constraint:\n\\begin{align}\np = \\frac{\\partial L}{\\partial \\dot{q}} = q \\ \\ \\ \\Longrightarrow \\ \\ \\ \\phi_1 = p - q = 0.\n\\end{align}\nBecause of this constraint, the Hamiltonian is not unique:\n\\begin{align}\nH = \\dot{q} p - L = \\frac{q^2}{2} = \\frac{p^2}{2} = \\frac{q p}{2}.\n\\end{align}\nThis arbitrariness is included in the total Hamiltonian:\n\\begin{align}\nH_T = \\frac{q^2}{2} - u_1(q,p) (p-q).\n\\end{align}\nDepending on the choice of $u_1(q,p)$, we can switch from one form to another.\n\\end{example}\n\nRealizing the appearance of unknown functions in the Hamiltonian and the equations of motion, one might develop bad thoughts about determinism and the predictability of the future.\nIt turns out that everything keeps predictable and the unknown functions aren't a big problem after all. We will see later that they correspond to mathematical degrees of freedom, so called gauge transformations. \\\\\n\nFor now, let us focus on the consistency of our theory. When we choose the initial conditions, we have to assure ourself that they fulfill the constraints. After time, the equations of motion could lead to a point in phase space which is not on the constraint surface. How to ensure that the system doesn't leave the constraint surface?\nSince we want that the primary constraints are fulfilled at every moment, we require\n\\begin{align}\\label{eq:4}\n0 \\overset{!}{=} \\dot{\\phi}_k = \\left \\{ \\phi_k,H \\right \\} + \\sum_{m=1}^M u_m  \\left \\{ \\phi_k,\\phi_m \\right \\},\n\\end{align}\nfor $k=1,...,M$. This can lead to four cases. First, it could lead directly to an inconsistency saying that the Lagrangian describes no proper system. Second, it could be satisfied identically and we can be sure that everything will be fine. Third, it can lead to an equation that determines the unknown functions and reduces the degrees of gauge freedom. Fourth, it can lead to other constraints, called \\textit{secondary constraints}:\n\\begin{align}\\label{eq:5}\n0 = \\dot{\\phi}_1 = \\left \\{ \\phi_1,H \\right \\} + \\sum_{m=1}^M u_m  \\left \\{ \\phi_1,\\phi_m \\right \\} = \\left \\{ \\phi_1,H \\right \\} = \\chi(q,p).\n\\end{align}\nThey differ from the primary constraints in the fact that the primary constraints are merely a consequence of the definition of the generalized momenta, while for the secondary constraints, one has to make use of the Lagrangian equations of motion as well. \\\\\nIf we have a secondary constraint, then we get another consistency condition because we can work out again $\\dot{\\chi}$ according to the equation of motion and require that $\\dot{\\chi} = 0$. This equation has to be treated on the same footing as \\eqref{eq:4}. One must again see to which case it leads. If it leads to another secondary constraint, we have to push the process one stage further and check the consistency condition again. \\\\\nWe carry on like that until we have exhausted all the consistency conditions, and the final result will be that we are left with a number of secondary constraints together with a number of conditions on the functions $u_m$. The process \\footnote{It should be mentioned that it is a controversial topic whether every new constraint should be added to the total Hamiltonian with an undetermined function after each step or not. It only makes a difference when we generate second-class constraints during our procedure. For the most cases, Dirac's procedure (without adding the secondary constraints to the Hamiltonian) works out and leads to the right physics. If one has second-class constraints, one should pay attention and ponder what to do. There are even examples where adding secondary constraints to the Hamiltonian leads to wrong results. That's why we will stick to Dirac and describe his method.} is described in detail by Dirac in his lectures on quantum mechanics \\cite{1}. \\\\\n\nLet's take a closer look on the secondary constraints now. Since they are treated for many purposes like primary constraints, we will denote them like\n\\begin{align}\n\\phi_{M+1}(q_i,p_i), ... , \\phi_J(q_i,p_i)\n\\end{align}\nand require now \n\\begin{align}\\label{eq:6}\n\\dot{\\phi}_j = \\left \\{ \\phi_j,H \\right \\} + \\sum_{m=1}^M u_m  \\left \\{ \\phi_j,\\phi_m \\right \\} = 0, \n\\end{align}\nfor $j=1,...,M,M+1,...,J$. These are a number of non-homogeneous linear equations for the unknown functions $u_m$. Let us investigate the solvability of this system. Suppose that we are at the beginning of our procedure and have no secondary constraints yet. Then we can introduce the matrix $\\hat{a}$ with components\n\\begin{align}\na_{jm} = \\left \\{ \\phi_j,\\phi_m \\right \\}, \\ \\ j,m = 1, \\dots, M.\n\\end{align}\nWith equation \\eqref{eq:6} it follows that\n\\begin{align}\n\\sum_{m=1}^M a_{jm} u_m = b_j = - \\left \\{ \\phi_j,H \\right \\},\n\\end{align}\nwhich expresses the linear equation system in matrix form. Since the rank of this matrix can be between 0 and $M$:\n\\begin{align}\n0 \\leq \\text{rank} (\\hat{a}) \\leq M,\n\\end{align}\nthere are two options for solutions of this system. \n\n\\pagebreak\n\n\\begin{enumerate}\n\\item If the rank of the $M \\times M$ matrix is maximal, then one has a minimal system of $M$ equations with $M$ variables.\nThere exists a unique solution \n\\begin{align}\nu_m = U_m(q_i,p_i).\n\\end{align}\n\\item If the rank of the $M \\times M$ matrix is $\\leq M-1$, then there exist eigenvectors\n\\begin{align}\\label{eq:7}\nu_m = U_m(q_i,p_i) + \\sum_{a=1}^A v_a(q_i,p_i) V_m^{(a)}(q_i,p_i),\n\\end{align}\nwhere $A = M - \\text{rank} (\\hat{a})$ with arbitrary coefficients $v_a$ and any solution $V_m^{(a)}(q_i,p_i)$ of the homogeneous equations. They satisfy \n\\begin{align}\n\\sum_{m=1}^M a_{jm} U_m = b_j \\ \\ \\ \\text{and} \\ \\ \\ \\sum_{m=1}^M a_{jm} V_m^{(a)} = 0.\n\\end{align}\nThe solution is not unique.\n\\end{enumerate}\n\nInserting \\eqref{eq:7} in the total Hamiltonian, we get\n\\begin{align}\\label{eq:8}\nH_T(q_i,p_i) &= H + \\sum_{m=1}^M U_m \\phi_m + \\sum_{a=1}^A v_a \\left( \\sum_{m=1}^M V_m^{(a)} \\phi_m \\right) \\notag \\\\\n&= H' + \\sum_{a=1}^A v_a \\tilde{\\phi}_a.\n\\end{align}\nDepending on how much the rank of the matrix $\\hat{a}$ is smaller than $M$, we are left with $A = M - \\text{rank} (\\hat{a})$ constraints. So after the procedure, we can find some unknown functions $u_m$ and reduce their degree of freedom in some cases. The general rules are:\n\\begin{enumerate}\n\\item If the $u$'s vanish $\\longrightarrow$ introduce secondary constraints\n\\item If not $\\longrightarrow$ find conditions on the $u$'s and reduce their degree of freedom.\n\\end{enumerate}\n\n\nFor the following analysis, we introduce a useful terminology:\n\\begin{definition}[First-class quantity]\nA quantity $R(q_i,p_i)$ is first-class, if it has zero Poisson brackets with all the $\\phi$'s:\n\\begin{align}\n\\left \\{ R,\\phi_j \\right \\} = \\sum_{j' = 1}^J r_{j j'} \\phi_{j'} \\approx 0,\n\\end{align}\nwhere $j = 1, ... , J$. Otherwise, $R$ is second-class.\n\\end{definition}\nIt is important to find all constraints first and then talk about what is first-class and second-class. The following theorem shows a nice property of first-class quantities.\n\n\\pagebreak\n\n\\begin{theorem}\nThe Poisson bracket of two first-class quantities is also first-class.\n\\end{theorem}\n\\begin{proof}\nLet $R,S$ be first-class. Then we have \n\\begin{align}\n\\left \\{ R,\\phi_j \\right \\} &= \\sum_{j' = 1}^J r_{j j'} \\phi_{j'} \\approx 0 \\\\\n\\left \\{ S,\\phi_j \\right \\} &= \\sum_{j' = 1}^J s_{j j'} \\phi_{j'} \\approx 0.\n\\end{align}\nUsing the Jacobi identity and the Einstein summation convention, we have\n\\begin{align}\n\\left \\{ \\left \\{ R,S \\right \\},\\phi_j \\right \\} &= \\left \\{ \\left \\{ R,\\phi_j \\right \\},S \\right \\} - \\left \\{ \\left \\{ S,\\phi_j \\right \\},R \\right \\} \\notag \\\\\n&= \\left \\{ r_{j j'} \\phi_{j'},S \\right \\} - \\left \\{ s_{j j'} \\phi_{j'},R \\right \\} \\notag \\\\\n&= r_{j j'} \\left \\{ \\phi_{j'},S \\right \\} + \\left \\{ r_{j j'},S \\right \\} \\phi_{j'} - s_{j j'} \\left \\{ \\phi_{j'},R \\right \\} - \\left \\{ s_{j j'},R \\right \\} \\phi_{j'} \\notag \\\\\n&\\approx 0.\n\\end{align}\n\\end{proof}\n\nIt turns out that our Hamiltonian in equation \\eqref{eq:8} is first-class. To see this, check that every term is first-class:\n\\begin{itemize}\n\\item \\(\n\\begin{aligned}[t]\n\\left \\{ H',\\phi_j \\right \\} &= \\left \\{ H + \\sum_{m=1}^M U_m \\phi_m ,\\phi_j \\right \\} \\approx  \\left \\{ H ,\\phi_j \\right \\} + \\sum_{m=1}^M U_m \\left \\{ \\phi_m ,\\phi_j \\right \\} \\notag \\\\\n&= b_j - \\sum_{m=1}^M a_{jm} U_m = b_j - b_j = 0.\n\\end{aligned} \\)\n\\item \\(\n\\begin{aligned}[t]\n\\left \\{ v_a \\tilde{\\phi}_a,\\phi_j \\right \\} \\approx v_a \\left \\{\\tilde{\\phi}_a,\\phi_j \\right \\} = v_a \\sum_{m=1}^M V_m^{(a)} \\left \\{ \\phi_m ,\\phi_j \\right \\} = - v_a \\sum_{m=1}^M a_{jm} V_m^{(a)} = 0.\n\\end{aligned} \\)\n\\end{itemize}\n\n\n\\section{Examples}\n\nNow, we present two typical exersices. Consider the Lagrangian\n\\begin{align}\nL = \\frac{1}{2} \\left[ \\left( \\frac{d}{dt} - y \\right) x \\right]^2 = \\frac{1}{2} \\left(\\dot{x} - xy \\right)^2.\n\\end{align}\nFirst, calculate the conjugate momentum:\n\\begin{align}\np_x &= \\frac{\\partial L}{\\partial \\dot{x}} = \\dot{x} - xy \\\\\np_y &= \\frac{\\partial L}{\\partial \\dot{y}} = 0.\n\\end{align}\nFrom here, we get our first constraint: $\\phi_1 = p_y = 0$. \\\\\n\nThe Hamiltonian is given by\n\\begin{align}\nH &= \\dot{x} p_x + \\dot{y} p_y - \\frac{1}{2} \\left(\\dot{x} - xy \\right)^2 \\notag \\\\\n&= (p_x + xy)p_x - \\frac{1}{2} p_x^2 \\notag \\\\\n&= \\frac{1}{2} p_x^2 + xy p_x.\n\\end{align}\nBut it is not unique. The full Hamiltonian is\n\\begin{align}\nH_T = H + u(x,p_x,y,p_y) \\phi_1.\n\\end{align}\nIn the following, we will write $u = u(x,p_x,y,p_y)$ but keep in mind that it depends on all these variables. We get the equation of motion by\n\\begin{align}\n\\dot{g} = \\left \\{ g,H \\right \\} + u \\left \\{ g,\\phi_1 \\right \\}.\n\\end{align}\nWe notice that\n\\begin{align}\n0 = \\dot{\\phi}_1 = \\left \\{ \\phi_1,H \\right \\} + u \\left \\{ \\phi_1,\\phi_1 \\right \\} = \\left \\{ p_y,\\frac{1}{2} p_x^2 + xy p_x \\right \\} = \\left \\{ p_y,y \\right \\} x p_x = - x p_x.\n\\end{align}\nWhich leads to a secondary constraint:\n\\begin{align}\n\\left.\n\\begin{array}{llll}\n      \\text{Either:} & x = 0 & \\Rightarrow &  p_x = 0 \\\\\n      \\text{Or:} & p_x = 0\n\\end{array}\n\\right \\} \\Longrightarrow \\phi_2 = p_x = 0.\n\\end{align}\nLet's check whether it satisfies the condition that we required for a constraint: \n\\begin{align}\n0 \\overset{?}{=} \\dot{\\phi}_2 = \\left \\{ \\phi_2,H \\right \\} + u \\left \\{ \\phi_2,\\phi_1 \\right \\} = \\left \\{ p_x,\\frac{1}{2} p_x^2 + xy p_x \\right \\} = \\left \\{ p_x,x \\right \\} y p_x = - y p_x \\approx 0.\n\\end{align}\nSo it is consistent and we get no more constraints. We can also check that $\\phi_1, \\phi_2$ and $H$ are first-class. We show it only for $H$:\n\\begin{align}\n\\left \\{ H,\\phi_1 \\right \\} &= \\left \\{ \\frac{1}{2} p_x^2 + xyp_x, p_x \\right \\} = y p_x \\approx 0 \\\\\n\\left \\{ H,\\phi_2 \\right \\} &= \\left \\{ \\frac{1}{2} p_x^2 + xyp_x, p_y \\right \\} = x p_x \\approx 0.\n\\end{align}\n\n\nAnother example which is quite similar to string theory, is the following. \n\\begin{align}\nL = q_1 q_2 (\\dot{q}_1 + \\dot{q}_2).\n\\end{align}\nFollowing the procedure, we get two primary constraints:\n\\begin{align}\np_1 &= \\frac{\\partial L}{\\partial \\dot{q}_1} = q_1 q_2 \\ \\ \\ \\Longrightarrow \\ \\ \\ \\phi_1 = p_1 - q_1 q_2 = 0. \\\\\np_2 &= \\frac{\\partial L}{\\partial \\dot{q}_2} = q_1 q_2 \\ \\ \\ \\Longrightarrow \\ \\ \\ \\phi_2 = p_2 - q_1 q_2 = 0.\n\\end{align}\nThe Hamiltonian is\n\\begin{align}\nH = \\dot{q}_1 p_1 + \\dot{q}_2 p_2 - q_1 q_2 (\\dot{q}_1 + \\dot{q}_2) = 0.\n\\end{align}\nAt this point, it is useful to notice the following theorem. \\\\\n\n\\begin{theorem}\n\\label{Theorem}\nIf the Lagrangian $L$ is homogeneous of degree $1$ in the velocities  \n\\begin{align}\nL(q_i,\\lambda \\dot{q}_i) = \\lambda L(q_i,\\dot{q}_i), \\label{eq:9}\n\\end{align}\nthen $H(q_i,p_i) = 0$.\n\\end{theorem}\n\\begin{proof}\nThe proof of this theorem is analog to the proof of Euler's homogeneous function theorem. \nDifferentiating both sides of equation \\eqref{eq:9} with respect to $\\lambda$ yields\n\\begin{align}\nL(q_i,\\dot{q}_i) = \\frac{\\partial L(q_i,\\lambda \\dot{q}_i)}{\\partial \\lambda} = \\sum_k \\dot{q}_k \\frac{\\partial L(q_i,\\lambda \\dot{q}_i)}{\\partial (\\lambda \\dot{q}_k)} .\n\\end{align}\nBy setting $\\lambda = 1$, we obtain\n\\begin{align}\n\\sum_k \\dot{q}_k \\frac{\\partial L(q_i,\\dot{q}_i)}{\\partial \\dot{q}_k} - L(q_i,\\dot{q}_i) = H(q_i,p_i) = 0.\n\\end{align}\n\\end{proof}\n\nSo we didn't even have to calculate the Hamiltonian because our Lagrangian is homogeneous of degree $1$. \\\\\n\nThe total Hamiltonian is\n\\begin{align}\nH_T = 0 + u_1 \\phi_1 + u_2 \\phi_2\n\\end{align}\nand the equation of motion is\n\\begin{align}\n\\dot{g} = u_1 \\left \\{ g, \\phi_1 \\right \\} + u_2 \\left \\{ g, \\phi_2 \\right \\}.\n\\end{align}\n\nWith the identity $\\{ q_i, p_k \\} = \\delta_{ik}$, we get $\\{ \\phi_1 , \\phi_2 \\} = q_2 - q_1$ and obtain a new (secondary) constraints out of the requirement that\n\\begin{align}\n0 \\overset{!}{=} \\dot{\\phi}_1 &= u_1 \\left \\{ \\phi_1, \\phi_1 \\right \\} + u_2 \\left \\{ \\phi_1, \\phi_2 \\right \\} = u_2 (q_2 - q_1) \\\\\n0 \\overset{!}{=} \\dot{\\phi}_2 &= u_1 \\left \\{ \\phi_2, \\phi_1 \\right \\} + u_2 \\left \\{ \\phi_2, \\phi_2 \\right \\} = u_1 (q_1 - q_2).\n\\end{align}\n\\textit{First case $\\phi_3 = q_1 - q_2 = 0$.} \\\\\nWe have to check that this constraint fulfills our requirement too:\n\\begin{align}\n0 \\overset{!}{=} \\dot{\\phi}_3 &= u_1 \\left \\{ \\phi_3, \\phi_1 \\right \\} + u_2 \\left \\{ \\phi_3, \\phi_2 \\right \\} = u_1 - u_2.\n\\end{align}\nThis is just an additional condition on the functions $u_1$ and $u_2$, saying that $u_1 = u_2 = v$. \\\\\n\nThe total Hamiltonian is therefore\n\\begin{equation}\nH_T = v ( \\phi_1 + \\phi_2 ).\n\\end{equation}\nNow, we want to see whether the Hamiltonian is first-class or second-class. But have we found already all constraints? There is a theorem saying that there is always an even number of second-class constraints, if one cannot combine all secondary constraints to get a new primary constraint. We will proof it later but for now, in our case, we only have one secondary constraint, so we have to find more constraints by combining the old ones:\n\\begin{align}\n\\tilde{\\phi}_1 &= \\phi_1 + \\phi_2 = 0 \\\\\n\\tilde{\\phi}_2 &= \\phi_1 - \\phi_2 = 0.\n\\end{align}\nAnd now check which of them are first-class or second-class:\n\\begin{itemize}\n\\item \\(\n\\begin{aligned}[t]\n\\left \\{ \\tilde{\\phi}_1,\\tilde{\\phi}_2 \\right \\} = \\left \\{ p_1 + p_2 - 2 q_1 q_2, p_1 - p_2 \\right \\} = 2 (q_1 - q_2) = 0.\n\\end{aligned} \\)\n\\item \\(\n\\begin{aligned}[t]\n\\left \\{ \\tilde{\\phi}_1,\\phi_3 \\right \\} = \\left \\{ p_1 + p_2 - 2 q_1 q_2, q_1 - q_2 \\right \\} = -1 + 1 = 0.\n\\end{aligned} \\)\n\\item \\(\n\\begin{aligned}[t]\n\\left \\{ \\tilde{\\phi}_2,\\phi_3 \\right \\} = \\left \\{ p_1 - p_2, q_1 - q_2 \\right \\} = -2.\n\\end{aligned} \\)\n\\end{itemize}\nSo $\\tilde{\\phi}_1$, and therefore our Hamiltonian, is first-class and $\\tilde{\\phi}_2,\\phi_3$ are second-class like we expected. We notice:\n\\begin{definition}\nTrue secondary constraints are secondary constraints which one cannot combine to first-class quantities.\n\\end{definition}\n\n\\textit{Second case $q_1 \\neq q_2 \\Longrightarrow u_1 = u_2 = 0$.} \\\\\nAnd the total Hamiltonian is zero.\n\n\n\n\\section{Gauge Transformations}\nIn this section, we will see the meaning of the arbitrary coefficients in the total Hamiltonian \\eqref{eq:8}.\nWith the equation of motion, one can express little changes in the function $g$:\n\\begin{align}\\label{eq:10}\n\\frac{\\Delta g}{\\Delta t} = \\dot{g} = \\left \\{ g,H' \\right \\} + \\sum_{a=1}^A v_a \\left \\{ g,\\tilde{\\phi}_a \\right \\}.\n\\end{align}\nSince the $v_a$ are arbitrary, there are many possible results for $\\Delta g$. The situation is illustrated in Fig.~\\ref{fig:2}.\n\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=1.4]{img/gauge1.pdf}\n\\end{center}\n\\caption{Evolution of the observable $g$ in phase space.}\n\\label{fig:2}\n\\end{figure}\n\nThe time evolution of the observable $g$ for small intervals $\\Delta t$ can be estimated as\n\\begin{align}\ng(t + \\Delta t) = g_0 + \\Delta g,\n\\end{align}\nwhere $\\Delta g$ is given by equation \\eqref{eq:10}:\n\\begin{align}\n\\Delta g = \\left \\{ g,H' \\right \\} \\Delta t + \\sum_{a=1}^A \\left( v_a \\Delta t \\right) \\left \\{ g,\\tilde{\\phi}_a \\right \\}.\n\\end{align}\n\nLet's choose two different $v_a^{(1)}$ and $v_a^{(2)}$ with which we land eather on $g_1$ or $g_2$, the corresponding change $\\Delta g_i$ can be written as:\n\\begin{align}\n\\Delta g_1 &= \\left \\{ g,H' \\right \\} \\Delta t + \\sum_{a=1}^A \\left( v_a^{(1)} \\Delta t \\right) \\left \\{ g,\\tilde{\\phi}_a \\right \\} \\\\\n\\Delta g_2 &= \\left \\{ g,H' \\right \\} \\Delta t + \\sum_{a=1}^A \\left( v_a^{(2)} \\Delta t \\right) \\left \\{ g,\\tilde{\\phi}_a \\right \\}.\n\\end{align}\n\nDifferent functions $v_a^{(i)}$ lead to different results $\\Delta g_i$. This means that $g(t + \\Delta t)$ is not well defined and depends on the functions $v_a^{(i)}$. The key to the solution of this problem is to say that all \\textit{mathematical states} $g_i$ correspond to the same \\textit{physical state} $g(t + \\Delta t)$. Like in electrodynamics, where $\\vec{A} \\longrightarrow \\vec{A}' = \\vec{A} + \\nabla f$ leaves the magnetic field unchanged. \\\\\n\nThe transformation which leads from $g_1$ to $g_2$ is called a \\textit{gauge transformation}:\n\\begin{align}\ng_1 \\longrightarrow g_2 =  g_1 + \\delta g.\n\\end{align}\n\nLet us calculate the explicit form of $\\delta g$:\n\\begin{align}\n\\delta g = \\Delta g_2 - \\Delta g_1 = \\sum_{a=1}^A \\left( v_a^{(2)} - v_a^{(1)} \\right) \\Delta t \\left \\{ g,\\tilde{\\phi}_a \\right \\} \\equiv \\sum_{a=1}^A \\varepsilon_a \\left \\{ g,\\tilde{\\phi}_a \\right \\},\n\\end{align}\nwhere $\\varepsilon_a$ is a small, arbitrary parameter since $\\Delta t$ is small.\n\\label{sec:gauge_transformations}\nWe see that this \\textit{infinitesimal} change can be expressed as the Poisson bracket of $g$ with the primary constraints. We therefore say that primary constraints are generators of \\textit{infinitesimal} gauge transforations. \\\\\nMore exactly, the first-class primary constraints are generators of gauge transformation since we started with a first-class total Hamiltonian. Later, we will learn more about the role of first-class quantities for gauge transformations. \\\\\n\nBefore continuing, we would like to illustrate gauge transformations with the following example.\nConsider the Lagrangian\n\\begin{align}\nL = \\frac{1}{2} (x \\dot{x} + y \\dot{y})^2.\n\\end{align}\nThe definition of the generalized momentum \n\\begin{align}\np_x &= \\frac{\\partial L}{\\partial \\dot{x}} =  x (x \\dot{x} + y \\dot{y}) \\\\\np_y &= \\frac{\\partial L}{\\partial \\dot{y}} = y (x \\dot{x} + y \\dot{y})\n\\end{align}\nleads to the primary constraint\n\\begin{align}\n\\phi_1 = p_x y - p_y x = 0.\n\\end{align}\nSo again, the Hamiltonian is not unique:\n\\begin{align}\nH &= \\dot{x} p_x + \\dot{y} p_y - \\frac{1}{2} (x \\dot{x} + y \\dot{y})^2 \\notag \\\\\n&= x \\dot{x} (x \\dot{x} + y \\dot{y}) + y \\dot{y} (x \\dot{x} + y \\dot{y}) - \\frac{1}{2} (x \\dot{x} + y \\dot{y})^2 \\notag \\\\\n&= (x \\dot{x} + y \\dot{y})^2 - \\frac{1}{2} (x \\dot{x} + y \\dot{y})^2 \\notag \\\\\n&= \\frac{1}{2} (x \\dot{x} + y \\dot{y})^2  \\notag \\\\\n&= \\frac{p_x^2}{2 x^2} = \\frac{p_y^2}{2 y^2} = \\frac{p_x p_y}{2 x y}.\n\\end{align}\nWe therefore build the total Hamiltonian\n\\begin{align}\nH_T = \\frac{p_x^2}{2 x^2} + u_1 (p_x y - p_y x),\n\\end{align}\nwhere the arbitrariness lies completely in the function $u_1$ now. By choosing $u_1$, one can change between the different variants. The equation of motion is given by\n\\begin{align}\n\\dot{g} = \\left \\{ g,H \\right \\} + u_1 \\left \\{ g,\\phi_1 \\right \\}.\n\\end{align}\nLet's check whether the consistency condition holds:\n\\begin{align}\n0 = \\dot{\\phi}_1 &= \\left \\{ \\phi_1,H \\right \\} + u_1 \\left \\{ \\phi_1,\\phi_1 \\right \\} = \\left \\{ p_x y - p_y x,\\frac{p_x^2}{2 x^2} \\right \\} \\notag \\\\\n&= \\frac{p_x^2 y}{2} \\left \\{ p_x,\\frac{1}{x^2} \\right \\} - \\frac{p_y}{2 x^2} \\left \\{ x,p_x^2 \\right \\} \\notag \\\\\n&= \\frac{p_x^2 y}{2} \\left(-(-2) \\frac{1}{x^3}\\right) - \\frac{p_y}{2 x^2} 2 p_x \\notag \\\\\n&= \\frac{p_x (p_x y - p_y x)}{x^3} \\notag \\\\\n&= \\frac{p_x \\phi_1}{x^3} \\approx 0. \\ \\ \\ \\surd\n\\end{align}\nSo $u_1$ remains arbitrary and we have no secondary constraints. It follows that $\\phi_1 = \\phi$ is first-class (which is always the case when we only have one constraint) and act as a generator of gauge transformations:\n\\begin{align}\n\\Delta g = \\varepsilon \\left \\{ g,\\phi \\right \\}.\n\\end{align}\nLet us insert $\\phi$ and see which transformations don't change the physical state of the observables:\n\\begin{itemize}\n\\item $\\Delta x = \\varepsilon \\left \\{ x,\\phi \\right \\} = \\varepsilon \\left \\{ x,p_x y - p_y x \\right \\}= \\varepsilon y$\n\\item $\\Delta y = \\varepsilon \\left \\{ y,\\phi \\right \\} = - \\varepsilon x$\n\\item $\\Delta p_x = \\varepsilon \\left \\{ p_x,\\phi \\right \\} = \\varepsilon p_y$\n\\item $\\Delta p_y = \\varepsilon \\left \\{ p_y,\\phi \\right \\} = - \\varepsilon p_x$.\n\\end{itemize}\nThese transformations do look like the infinitesimal version of rotations in $2$ dimensional space. So let us work out the connection. We will show it for the space part and the momentum is completely analogous.\nThe equations \n\\begin{align}\nx' &= x + \\varepsilon y \\\\\ny' &= y - \\varepsilon x\n\\end{align}\ncan be written in matrix form like \n\\begin{align}\n\\bar{r} \\ ' = \\bar{r} + \\varepsilon \\hat{\\omega} \\bar{r},\n\\end{align}\nwhere\n\\begin{align}\n\\bar{r} = \n\\begin{pmatrix}\n    x \\\\\n    y\n\\end{pmatrix} \\ \\ \\ \\text{and} \\ \\ \\\n\\hat{\\omega} = \n\\begin{pmatrix}\n    0 & 1 \\\\\n    -1 & 0\n\\end{pmatrix}.\n\\end{align}\nIt follows that\n\\begin{align}\n\\Delta \\bar{r} = \\varepsilon \\hat{\\omega} \\bar{r}.\n\\end{align}\nRedefine the small parameter $\\varepsilon \\longrightarrow \\Delta \\alpha$ and solve the differential equation:\n\\begin{align}\n\\frac{\\Delta \\bar{r}}{\\Delta \\alpha} = \\hat{\\omega} \\bar{r} \\ \\ \\Longrightarrow \\ \\ \\bar{r}(\\alpha) = \\exp(\\hat{\\omega} \\alpha) \\bar{r}(0).\n\\end{align}\nTo get a better feeling for what this means, we expand the solution into the Taylor series and note that\n\\begin{align}\n\\hat{\\omega} = \n\\begin{pmatrix}\n    0 & 1 \\\\\n    -1 & 0\n\\end{pmatrix}, \\ \\\n\\hat{\\omega}^2 = - I, \\ \\\n\\hat{\\omega}^3 = - \\hat{\\omega}, \\ \\\n\\hat{\\omega}^4 = I, \\ \\\n\\hat{\\omega}^5 = \\hat{\\omega}, \\ \\dots .\n\\end{align}\nSo \n\\begin{align}\n\\bar{r}(\\alpha) &= \\left( I + \\alpha \\hat{\\omega} + \\frac{\\alpha^2 \\hat{\\omega}^2}{2} + \\frac{\\alpha^3 \\hat{\\omega}^3}{3 !} + \\frac{\\alpha^4 \\hat{\\omega}^4}{4 !} + \\dots  \\right) \\bar{r}(0) \\notag \\\\\n&= \\Bigg [  \\Big ( \\underbrace{1 - \\frac{\\alpha^2}{2} + \\frac{\\alpha^4}{4 !} - \\dots}_{\\Large = \\ \\cos \\alpha} \\Big ) I + \\Big ( \\underbrace{\\alpha - \\frac{\\alpha^3}{3 !} + \\frac{\\alpha^5}{5 !} - \\dots}_{\\Large = \\ \\sin \\alpha} \\Big ) \\hat{\\omega} \\Bigg ] \\bar{r}(0) .\n\\end{align}\n\\begin{align}\n\\Longrightarrow \\ \n\\begin{pmatrix}\n    x' \\\\\n    y'\n\\end{pmatrix} =\n\\begin{pmatrix}\n    \\cos \\alpha & \\sin \\alpha \\\\\n    - \\sin \\alpha & \\cos \\alpha\n\\end{pmatrix}\n\\begin{pmatrix}\n    x \\\\\n    y\n\\end{pmatrix}.\n\\end{align}\nSo our suggestion was right, the gauge transformations are really rotations.\nWe can illustrate this as follows:\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=1.4]{img/rotation.pdf}\n\\end{center}\n\\caption{Rotations as gauge transformations.}\n\\label{fig:3}\n\\end{figure}\nSo the quantity \n\\begin{align}\nR = x^2 + y^2 \n\\end{align}\nwill not change under these gauge transformations. To see this, notice that\n\\begin{align}\n\\delta R = \\varepsilon \\left \\{ x^2 + y^2 , \\phi \\right \\} = \\varepsilon \\left \\{ x^2 + y^2 , p_x y - p_y x \\right \\} = \\varepsilon (2xy - 2yx) = 0.\n\\end{align}\n\nWith a bit of imagination, one could see this faster. The Lagrangian depends only on the radius $R$, not the angle:\n\\begin{align}\nL = \\frac{1}{2} (x \\dot{x} + y \\dot{y})^2 = \\frac{1}{8} \\left( \\frac{d}{dt} (x^2 + y^2) \\right)^2 = \\frac{1}{8} \\left( \\frac{d R^2}{dt} \\right)^2 = \\frac{1}{8} (2 R \\dot{R})^2 = \\frac{1}{2} R^2 \\dot{R}^2.\n\\end{align}\n\n\\label{sec:finite_gauge_transformations}\nHow to get from infinitesimal transformations to finite transformations in general? \\\\\n\nWe claim that \n\\begin{align}\ng(\\alpha) = \\sum_{n=0}^{\\infty} \\frac{\\alpha^n}{n !} \\underbrace{\\Large \\{ \\dots \\left \\{ \\left \\{ g_0 , \\phi \\right \\} , \\phi \\right \\} \\dots \\ , \\phi \\Large \\}}_{n \\ \\text{times}}\n\\end{align}\nis the general solution.\n\\begin{proof}\n\\begin{align}\n\\frac{d g}{d \\alpha} &= \\sum_{n=1}^{\\infty} \\frac{\\alpha^{n-1}}{(n-1) !} \\underbrace{\\Large \\{ \\dots \\left \\{ \\left \\{ g_0 , \\phi \\right \\} , \\phi \\right \\} \\dots \\ , \\phi \\Large \\}}_{n \\ \\text{times}} \\notag \\\\\n&= \\sum_{\\bar{n}=0}^{\\infty} \\frac{\\alpha^{\\bar{n}}}{\\bar{n} !} \\underbrace{\\Large \\{ \\dots \\left \\{ \\left \\{ g_0 , \\phi \\right \\} , \\phi \\right \\} \\dots \\ , \\phi \\Large \\}}_{\\bar{n} + 1 \\ \\text{times}} \\notag \\\\\n&= \\left \\{ g , \\phi \\right \\}.\n\\end{align}\n\\end{proof}\nSo, one gets the full transformation out of the constraint $\\phi$ by \n\\begin{align}\\label{eq:11}\ng(\\alpha) = g_0 + \\alpha \\left\\{ g_0 , \\phi \\right \\} + \\frac{\\alpha^2}{2} \\left \\{ \\left \\{ g_0 , \\phi \\right \\} , \\phi \\right \\} + \\dots \\ .\n\\end{align}\nWith this method we can again derive the same result of the last example:\n\\begin{itemize}\n\\item $\\left\\{ x , \\phi \\right \\} = y$\n\\item $\\left \\{ \\left\\{ x , \\phi \\right \\} , \\phi \\right \\} = \\left\\{ y , \\phi \\right \\} = - x$\n\\item $\\left \\{ \\left \\{ \\left\\{ x , \\phi \\right \\} , \\phi \\right \\} , \\phi \\right \\} = \\left\\{ -x , \\phi \\right \\} = - y$\n\\item $\\left \\{ \\left \\{ \\left \\{ \\left\\{ x , \\phi \\right \\} , \\phi \\right \\}, \\phi \\right \\}, \\phi \\right \\} = \\left\\{ -y , \\phi \\right \\} = x$.\n\\end{itemize}\nSo we see that\n\\begin{align}\nx(\\alpha) &= \\sum_{n=0}^{\\infty} \\frac{\\alpha^n}{n !} \\Large \\{ \\dots \\left \\{ \\left \\{ x , \\phi \\right \\} , \\phi \\right \\} \\dots \\ , \\phi \\Large \\} \\notag \\\\\n&= \\left( x + \\frac{\\alpha^2}{2} (-x) + \\frac{\\alpha^4}{4 !} (x) + \\dots \\right) + \\left( \\alpha y + \\frac{\\alpha^3}{3 !} (-y) + \\frac{\\alpha^5}{5 !} (y) + \\dots \\right) \\notag \\\\\n&= x \\cos \\alpha + y \\sin \\alpha.\n\\end{align}\n\n\n\\pagebreak\n\n\\textbf{General Case} \\\\\n\nWe already know that first-class primary constraints generate gauge transformations, but what about secondary constraints? Will they also be first-class and generate gauge transformations?\nDirac could not show this in general but for all physical situations.\n\n\\begin{proof}\nLet $\\phi_1$ and $\\phi_2$ be two constraints.\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=1.2]{img/gauge2.pdf}\n\\end{center}\n\\caption{Different constraints generate different transformations.}\n\\label{fig:4}\n\\end{figure}\nFirst, we want to show that transformations between $g_{12}$ and $g_{21}$ are generated by $\\left\\{ \\phi_1 , \\phi_2 \\right \\}$.\nWe use equation \\eqref{eq:11} to the second order to get\n\\begin{itemize}\n\\item $g_1 = g_0 + \\alpha \\left\\{ g_0 , \\phi_1 \\right \\} + \\frac{\\alpha^2}{2} \\left \\{ \\left \\{ g_0 , \\phi_1 \\right \\} , \\phi_1 \\right \\} $\n\\item $g_{12} = g_1 + \\beta \\left\\{ g_1 , \\phi_2 \\right \\} + \\frac{\\beta^2}{2} \\left \\{ \\left \\{ g_1 , \\phi_2 \\right \\} , \\phi_2 \\right \\}  $\n\\item $g_2 = g_0 + \\beta \\left\\{ g_0 , \\phi_2 \\right \\} + \\frac{\\beta^2}{2} \\left \\{ \\left \\{ g_0 , \\phi_2 \\right \\} , \\phi_2 \\right \\} $\n\\item $g_{21} = g_2 + \\alpha \\left\\{ g_2 , \\phi_1 \\right \\} + \\frac{\\alpha^2}{2} \\left \\{ \\left \\{ g_2 , \\phi_1 \\right \\} , \\phi_1 \\right \\} .$ \n\\end{itemize}\nSo \n\\begin{align}\n\\Delta g = g_{12} - g_{21} = \\dots  = \\alpha \\beta \\left \\{ g_0 , \\left \\{ \\phi_1 , \\phi_2 \\right \\} \\right \\}.\n\\end{align}\nWhen secondary constraints are first-class then this works out and $\\left \\{ \\phi_1 , \\phi_2 \\right \\}$ is a generator. \n\n\\pagebreak\n\nNow, we want to show that $\\left\\{ H , \\phi_a \\right \\}$ is also a generator of gauge transformations. \n\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=1.1]{img/gauge3.pdf}\n\\end{center}\n\\caption{Physical and mathematical changes of the quantity $g_0$.}\n\\label{fig:5}\n\\end{figure}\nConsider again\n\\begin{align}\n\\frac{\\Delta g}{\\Delta t} = \\left\\{ g , H' \\right \\} + \\sum_{a=1}^A v_a \\left\\{ g , \\phi_a \\right \\}.\n\\end{align}\nWe can analyse which part is responsible for which action:\n\\begin{align}\ng' = g(t + \\Delta t) = g_0 + \\underbrace{\\left\\{ g_0 , H' \\right \\} \\Delta t}_{\\begin{subarray}{l}\\text{corresponds to a}\\\\ \\text{physical change}\\\\\n    \\text{from layer \\ $t \\ \\rightarrow \\ t + \\Delta t$.}\\end{subarray}}\n+ \\underbrace{\\sum_{a=1}^A \\varepsilon_a \\left\\{ g_0 , \\phi_a \\right \\}}_{\\begin{subarray}{2}\\text{corresponds to a shift}\\\\\n    \\text{within a layer of constant time,}\\\\\n    \\text{not physical change.}\\end{subarray}}.\n\\end{align}\nPerforming a gauge transformation on $g'$ yields:\n\\begin{align}\ng'' = g' + \\varepsilon_a \\left\\{ g' , \\phi_a \\right \\} = g_0 + \\left\\{ g_0 , H' \\right \\} \\Delta t + 2 \\varepsilon_a \\left\\{ g_0 , \\phi_a \\right \\} + \\varepsilon_a \\left\\{ \\left\\{ g_0 , H' \\right \\} \\Delta t, \\phi_a \\right\\}.\n\\end{align}\nNow, perform a gauge transformation first\n\\begin{align}\ng_0' = g_0 + \\varepsilon_a \\left\\{ g_0 , \\phi_a \\right \\}\n\\end{align}\nand then calculate the physical change\n\\begin{align}\ng_0'' &= g_0' + \\left\\{ g_0' , H' \\right \\} \\Delta t + \\varepsilon_a \\left\\{ g_0' , \\phi_a \\right \\} \\notag \\\\\n&= g_0 + \\left\\{ g_0 , H' \\right \\} \\Delta t + 2 \\varepsilon_a \\left\\{ g_0 , \\phi_a \\right \\} + \\varepsilon_a \\left\\{ \\left\\{ g_0 , \\phi_a \\right \\} , H' \\right \\} \\Delta t.\n\\end{align}\nThe difference is \n\\begin{align}\n\\Delta g = g'' - g_0'' &= \\varepsilon_a  \\left\\{ \\left\\{ g_0 , H' \\right \\} , \\phi_a \\right \\} \\Delta t - \\varepsilon_a  \\left\\{ \\left\\{ g_0 , \\phi_a \\right \\} , H' \\right \\} \\Delta t \\notag \\\\\n&= \\varepsilon_a \\left\\{ g_0 ,  \\left\\{  H' , \\phi_a \\right \\} \\right \\} \\Delta t ,\n\\end{align}\nwhich shows that $\\left\\{  H' , \\phi_a \\right \\}$ is a generator. Both $H'$ and $\\phi_a$ are first-class.\n\\end{proof}\n\nNow that we showed that all first-class quantities generate some kind of gauge transformations, it is reasonable to introduce the following definitions:\n\\begin{definition}[Total Hamiltonian]\n\\begin{align}\nH_T = H + \\sum {\\begin{subarray}{l}\\text{primary constraints}\\\\ \\text{(first-class)}\\end{subarray}}.\n\\end{align}\n\\end{definition}\n\n\\begin{definition}[Generalized Hamiltonian]\n\\begin{align}\nH_E = H_T + \\sum {\\begin{subarray}{l}\\text{secondary constraints}\\\\ \\text{(first-class)}\\end{subarray}}.\n\\end{align}\n\\end{definition}\n\nThe following example shows a case where all constraints are first-class:\n\\begin{example}\n\\begin{align}\nL = \\frac{1}{2} (\\dot{x} - xy)^2\n\\end{align}\nFrom the definition of the generalized momentum we get the primary constraint\n\\begin{align}\n\\phi_1 = p_y = 0\n\\end{align}\nand a secondary constraint from the consistency condition:\n\\begin{align}\n0 = \\dot{\\phi}_1 \\ \\ \\ \\Longrightarrow \\ \\ \\ \\phi_2 = p_x = 0.\n\\end{align}\nThere are no more constraints. Since both constraints are first-class, we can write the generalized Hamiltonian \n\\begin{align}\nH_E &= \\frac{p_x^2}{2} + xy p_x + v p_y + V p_x \\notag \\\\\n&= v p_y + \\tilde{V} p_x.\n\\end{align}\nThe first constraint $\\phi_1 = p_y = 0$ lead to gauge transformations of the form\n\\begin{align}\n\\delta y = \\varepsilon_1 \\left \\{ y, p_y \\right \\} = \\varepsilon_1 \\\\\ny \\ \\longrightarrow \\ y' = y + \\varepsilon_1\n\\end{align}\nand the second constraint $\\phi_2 = p_x = 0$ analogous\n\\begin{align}\n\\delta x = \\varepsilon_2 \\left \\{ x, p_x \\right \\} = \\varepsilon_2 \\\\\nx \\ \\longrightarrow \\ x' = x + \\varepsilon_2.\n\\end{align}\n\\end{example}\n\n\\pagebreak\n\n\\section{Quantization}\n\nIn this section we want to discuss which problems can occur when we try to quantize a Hamiltonian system with constraints.\nWe will focus on the canonical quantization where we replace every physical observable with an operator and change the Poisson bracket into the commutator:\n\n\\begin{align}\nq_i \\ \\longrightarrow \\ \\hat{q}_i \\ \\ \\ , \\ \\ \\ p_i \\ \\longrightarrow \\ \\hat{p}_i.\n\\end{align}\n\\begin{align}\n\\left \\{ q_i , p_k \\right \\} = \\delta_{ik} \\ \\ \\longrightarrow \\ \\ \\frac{1}{i \\hbar} \\left[ \\hat{q}_i ,\\hat{p}_k \\right] = \\delta_{ik}.\n\\end{align}\n\\begin{align}\n\\forall g \\rightarrow \\hat{g} : \\ \\ \\frac{d}{dt} \\hat{g} = \\frac{1}{i \\hbar} \\left[ \\hat{g} ,\\hat{H} \\right]  \\ \\ \\Longrightarrow \\ \\ \\hat{H} \\psi(q_1, \\dots, q_n) = E \\psi(q_1, \\dots, q_n).\n\\end{align}\n\nWhat happens with the constraints? \n\nThey are also replaced by operators and if we act on a wavefunction $\\psi$, they will vanish since they vanish on the constraint surface. For first-class constraints this leads to the vanishing of the commutator on the constraint surface:\n\\begin{align}\n\\left.\n\\begin{array}{l}\n\\hat{\\phi}_b \\hat{\\phi}_a \\psi(q_1, \\dots, q_n) = 0 \\\\\n\\hat{\\phi}_a \\hat{\\phi}_b \\psi(q_1, \\dots, q_n) = 0\n\\end{array} \\ \\right \\} \\ \\\n\\Longrightarrow \\ \\ \\left[ \\hat{\\phi}_a ,\\hat{\\phi}_b \\right] \\psi = 0.\n\\end{align}\nSo for first-class constraints, we can make the transition\n\\begin{align}\n\\left \\{ \\phi_a ,\\phi_b \\right \\} = 0 \\ \\ \\longrightarrow \\ \\ \\left[ \\hat{\\phi}_a ,\\hat{\\phi}_b \\right] = 0\n\\end{align}\nwithout problems. \nBut if we have second-class constraints, for instance\n\\begin{align}\n\\left.\n\\begin{array}{l}\n\\chi_1 = q_1 = 0 \\\\\n\\chi_2 = p_1 = 0\n\\end{array} \\ \\right \\} \\ \\\n\\Longrightarrow \\ \\ \\left \\{ \\chi_1 ,\\chi_2 \\right \\} = 1,\n\\end{align}\nit won't work that way and will lead to contradictions:\n\\begin{align}\n\\left.\n\\begin{array}{l}\n\\hat{p}_1 \\hat{q}_1 \\psi(q_1, \\dots, q_n) = 0 \\\\\n\\hat{q}_1 \\hat{p}_1 \\psi(q_1, \\dots, q_n) = 0\n\\end{array} \\ \\right \\} \\ \\\n\\Longrightarrow \\ \\ \\underbrace{\\left[ \\hat{q}_1 ,\\hat{p}_1 \\right]}_{= i \\hbar} \\psi = 0 \\ \\ \\Longrightarrow \\ \\ \\psi = 0.\n\\end{align}\n\nWe can do calculations with the commutator of first-class constraints but not of second-class constraints. \n\\begin{align}\nH_E = H' + \\underbrace{\\sum_{a=1}^A v_a \\  \\tilde{\\phi}_a}_{\\begin{subarray}{l}\\text{primary constraints}\\\\ \\text{(first-class)}\\end{subarray}} + \\underbrace{\\sum v_b \\ \\tilde{\\tilde{\\phi}}_b}_{\\begin{subarray}{l}\\text{secondary constraints}\\\\ \\text{(first-class)}\\end{subarray}}.\n\\end{align}\nFirst-class constraints are generators of gauge transforations and don't change the physical state.\nThe commutator shows that they are problems with second-class constraints. Let us see how to quantize a Hamiltonian system with second-class constraints. \n\n\\pagebreak\n\nFirst, we will show that there is always an even number of true second-class constraints (which one cannot combine to first-class constraints). This is good, since every two second-class constraints will lead to a reduction of one degree of freedom.\nMathematically, we will replace the Poisson bracket with the Dirac bracket (which is a generalized Poisson bracket) to fix the problem of second-class constraints.\n\n\\label{sec:number_secondary_constraints}\n\\begin{theorem}\nLet $\\chi_1, \\chi_2, \\dots, \\chi_S$ be true second-class constraints. Then $S$ is even.\n\\end{theorem}\n%komischer abstand hier ...\n\\begin{proof}\nIntroduce the  matrix\n\\begin{align}\n\\hat{a}_{ik} = \\left \\{ \\chi_i , \\chi_k \\right \\}, \\ \\ \\ 1 \\leq i,k \\leq S,\n\\end{align}\nwhich is obviously antisymmetric because of the antisymmetry of the Poisson bracket. Since the determinant of an odd dimensional antisymmetric matrix is automatically zero, we have to show that $\\det (\\hat{a}) \\neq 0$ which would imply that $S$ is even. \\\\\nSuppose $S$ is odd and $\\det (\\hat{a}) = 0$. Then $\\text{rank}(\\hat{a}) = T < S$. \\\\\nFind a minor of $\\hat{a}$ which has $\\text{rank} = T$ and $\\det \\neq 0$ and build the \\\\ $(T+1) \\times (T+1)$ - matrix\n\\begin{align}\n\\hat{b} =\n\\left( \n\\arraycolsep=1.4pt\\def\\arraystretch{1.4}\n\\begin{array}{c|cccc}\n\\chi_1 & \\left\\{ \\chi_1,\\chi_{k_1} \\right\\} & \\left\\{ \\chi_1,\\chi_{k_2} \\right\\} & \\cdots & \\left\\{ \\chi_1,\\chi_{k_T} \\right\\} \\\\\n\\chi_2 & \\left\\{ \\chi_2,\\chi_{k_1} \\right\\} & \\left\\{ \\chi_2,\\chi_{k_2} \\right\\} & \\cdots & \\left\\{ \\chi_2,\\chi_{k_T} \\right\\} \\\\\n\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n\\chi_T & \\left\\{ \\chi_T,\\chi_{k_1} \\right\\} & \\left\\{ \\chi_T,\\chi_{k_2} \\right\\} & \\cdots & \\left\\{ \\chi_T,\\chi_{k_T} \\right\\} \\\\ \\cline{1-5}\n\\chi_{T+1} & \\left\\{ \\chi_{T+1},\\chi_{k_1} \\right\\} & \\left\\{ \\chi_{T+1},\\chi_{k_2} \\right\\} & \\cdots & \\left\\{ \\chi_{T+1},\\chi_{k_T} \\right\\} \n\\end{array} \\right),\n\\end{align}\nwhere $\\chi_{T+1}$ is an arbitrary constraint which is left. We claim that $\\det (\\hat{b})$ is first-class. This would lead to a contradiction since we can't reach a first-class quantity with true second-class constraints.\nLet's show this: \\\\\n\\begin{align}\n\\left\\{ \\det (\\hat{b}),\\phi_j \\right\\} &= \n\\det \\left( \n\\arraycolsep=1.4pt\\def\\arraystretch{1.4}\n\\begin{array}{c|cccc}\n\\left\\{ \\chi_1,\\phi_j \\right\\} & \\left\\{ \\chi_1,\\chi_{k_1} \\right\\} & \\left\\{ \\chi_1,\\chi_{k_2} \\right\\} & \\cdots & \\left\\{ \\chi_1,\\chi_{k_T} \\right\\} \\\\\n\\left\\{ \\chi_2,\\phi_j \\right\\} & \\left\\{ \\chi_2,\\chi_{k_1} \\right\\} & \\left\\{ \\chi_2,\\chi_{k_2} \\right\\} & \\cdots & \\left\\{ \\chi_2,\\chi_{k_T} \\right\\} \\\\\n\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n\\left\\{ \\chi_T,\\phi_j \\right\\} & \\left\\{ \\chi_T,\\chi_{k_1} \\right\\} & \\left\\{ \\chi_T,\\chi_{k_2} \\right\\} & \\cdots & \\left\\{ \\chi_T,\\chi_{k_T} \\right\\} \\\\\n\\left\\{ \\chi_{T+1},\\phi_j \\right\\} & \\left\\{ \\chi_{T+1},\\chi_{k_1} \\right\\} & \\left\\{ \\chi_{T+1},\\chi_{k_2} \\right\\} & \\cdots & \\left\\{ \\chi_{T+1},\\chi_{k_T} \\right\\} \n\\end{array} \\right) \\notag \\\\[14pt] \n&+ \n\\det \\left( \n\\arraycolsep=1.4pt\\def\\arraystretch{1.4}\n\\begin{array}{c|c|ccc}\n\\chi_1 & \\left\\{ \\left\\{ \\chi_1,\\chi_{k_1} \\right\\},\\phi_j \\right\\} & \\left\\{ \\chi_1,\\chi_{k_2} \\right\\} & \\cdots & \\left\\{ \\chi_1,\\chi_{k_T} \\right\\} \\\\\n\\chi_2 & \\left\\{ \\left\\{ \\chi_2,\\chi_{k_1} \\right\\},\\phi_j \\right\\} & \\left\\{ \\chi_2,\\chi_{k_2} \\right\\} & \\cdots & \\left\\{ \\chi_2,\\chi_{k_T} \\right\\} \\\\\n\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n\\chi_T & \\left\\{ \\left\\{ \\chi_T,\\chi_{k_1} \\right\\},\\phi_j \\right\\} & \\left\\{ \\chi_T,\\chi_{k_2} \\right\\} & \\cdots & \\left\\{ \\chi_T,\\chi_{k_T} \\right\\} \\\\\n\\chi_{T+1} & \\left\\{ \\left\\{ \\chi_{T+1},\\chi_{k_1} \\right\\},\\phi_j \\right\\} & \\left\\{ \\chi_{T+1},\\chi_{k_2} \\right\\} & \\cdots & \\left\\{ \\chi_{T+1},\\chi_{k_T} \\right\\} \n\\end{array} \\right) \\notag \\\\[14pt] \n&+ \\dots \\ .\n\\end{align}\nOnly the first term is really interesting because we can Laplace expand every other term with respect to the first column and use the fact that $\\chi_1, \\chi_2, \\dots, \\chi_{T+1}$ vanish on the constraint surface. \\\\\n\nNow, there can be several cases: \n\\begin{itemize}\n\\item If $\\phi_j$ is first-class, then the Poisson brackets $\\left\\{ \\chi_i,\\phi_j \\right\\}$ will vanish and we are done.\n\\item If $\\phi_j$ is second-class, then it is one of $\\chi_1, \\dots, \\chi_S$ and there are two options:\n\\begin{enumerate}\n\\item $\\phi_j \\in \\{ \\chi_{k_1}, \\dots, \\chi_{k_T} \\}$, then there will be two equal columns $\\Rightarrow \\det =0$.\n\\item $\\phi_j \\in \\{ \\chi_{k_{T+1}}, \\dots, \\chi_{k_S} \\}$, then the matrix will be a $(T+1) \\times (T+1)$ - minor of the matrix $\\hat{a}$ but we fixed $\\text{rank} (\\hat{a}) = T$, so again $\\det = 0$.\n\\end{enumerate}\n\\end{itemize}\nWe showed that $\\left\\{ \\det (\\hat{b}),\\phi_j \\right\\} = 0, \\ \\forall \\phi_j$. \\\\\n$\\Longrightarrow  \\det (\\hat{b})$ is a first-class quantity.\n\\end{proof}\n\nFor being able to quantize a Hamiltonian system with second-class constraints, Dirac invented the Dirac bracket:\n\\label{sec:dirac_bracket}\n\n\\begin{definition}[Generalized Dirac bracket]\n\\begin{align}\n\\left\\{ f,g \\right\\}_D = \\left\\{ f,g \\right\\} - \\sum_{i,j = 1}^S \\left\\{ f,\\chi_i \\right\\} (\\hat{a}^{-1})_{ij} \\left\\{ \\chi_j,g \\right\\}.\n\\end{align}\n\\end{definition}\n\nThe Dirac bracket has all the properties of the Poisson bracket $+$ fixes the problems:\n\\begin{enumerate}\n\\item \\(\n\\begin{aligned}[t]\n\\left \\{ f,g \\right \\}_D = - \\left \\{ g,f \\right \\}_D\n\\end{aligned} \\) \\ - \\ anticommutative\n\\item \\(\n\\begin{aligned}[t]\n\\left \\{ \\alpha f_1 + \\beta f_2,g \\right \\}_D = \\alpha \\left \\{ f_1,g \\right \\}_D + \\beta \\left \\{ f_2,g \\right \\}_D \n\\end{aligned} \\) \\ - \\ bilinear\n\\item \\(\n\\begin{aligned}[t]\n\\left \\{  f_1 f_2,g \\right \\}_D = f_1 \\left \\{ f_2,g \\right \\}_D + f_2 \\left \\{ f_1,g \\right \\}_D \n\\end{aligned} \\) \\ - \\ \"derivative\"\n\\item \\(\n\\begin{aligned}[t]\n\\left \\{ \\left \\{ f,g \\right \\}_D,h \\right \\}_D + \\left \\{ \\left \\{ g,h \\right \\}_D,f \\right \\}_D + \\left \\{ \\left \\{ h,f \\right \\}_D,g \\right \\}_D = 0 \n\\end{aligned} \\) \\ - \\ Jacobi identity\n\\end{enumerate}\n\nMoreover the equation of motion doesn't change:\n\\begin{align}\n\\dot{g} = \\left \\{ g,H_T \\right \\}_D = \\left \\{ g,H_T \\right \\}\n\\end{align}\nbecause $H_T$ is a first-class quantity.\nThe advantage is that every quantity is first-class with the Dirac bracket because the second-class constraints turn to first-class constraints:\n\\begin{align}\n\\left \\{ g, \\chi_j \\right \\}_D &= \\left\\{ g,\\chi_j \\right\\} - \\sum_{i,k = 1}^S \\left\\{ g,\\chi_i \\right\\} (\\hat{a}^{-1})_{ij} \\left\\{ \\chi_k,\\chi_j \\right\\} \\notag \\\\\n&= \\left\\{ g,\\chi_j \\right\\} - \\sum_{i,k = 1}^S \\left\\{ g,\\chi_i \\right\\} \\delta_{ij} \\notag \\\\\n&= 0.\n\\end{align}\nIn the last section, we said that we have to find all constraints before classifying them. But with the proofed theorem in mind, we don't have to do it anymore since every constraint will be first-class. \n\n\\pagebreak\n\nThe following example shows how every two (initially) second-class constraints reduce the degree of freedom by one.\n\n\\begin{example}\nConsider two second-class constraints:\n\\begin{align}\n\\chi_1 &= q_1 = 0 \\\\\n\\chi_2 &= p_1 = 0\n\\end{align}\nThen the Dirac bracket is just\n\\begin{align}\n\\left \\{ f,g \\right \\}_D &= \\left \\{ f,g \\right \\} - \\sum_{i,j = 1}^2 \\left\\{ f,\\chi_i \\right\\} (\\hat{a}^{-1})_{ij} \\left\\{ \\chi_j,g \\right\\} \\notag \\\\\n&= \\left \\{ f,g \\right \\} - \\left\\{ f,\\chi_1 \\right\\} (\\hat{a}^{-1})_{12} \\left\\{ \\chi_2,g \\right\\} - \\left\\{ f,\\chi_2 \\right\\} (\\hat{a}^{-1})_{21} \\left\\{ \\chi_1,g \\right\\} \\notag \\\\\n&= \\sum_{i=1}^n \\left( \\frac{\\partial f}{\\partial q_i} \\frac{\\partial g}{\\partial p_i} - \\frac{\\partial g}{\\partial q_i} \\frac{\\partial f}{\\partial p_i} \\right) - \\left( - \\frac{\\partial f}{\\partial p_1} \\right) (-1) \\left( - \\frac{\\partial g}{\\partial q_1} \\right) - \\left( \\frac{\\partial f}{\\partial q_1} \\right) (+1) \\left( \\frac{\\partial g}{\\partial p_1} \\right) \\notag \\\\\n&= \\sum_{i=2}^n \\left( \\frac{\\partial f}{\\partial q_i} \\frac{\\partial g}{\\partial p_i} - \\frac{\\partial g}{\\partial q_i} \\frac{\\partial f}{\\partial p_i} \\right).\n\\end{align}\n\\end{example}\n\nSince there is always an even number of true second-class constraints, the Dirac bracket will always reduce to the normal Poisson bracket with fewer degrees of freedom.", "meta": {"hexsha": "a7faf1323d4fbdda6e36041ca9b22bc37bfa7a66", "size": 52317, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03_hamilton.tex", "max_stars_repo_name": "Spektralzerleger/Hamilton-Systems", "max_stars_repo_head_hexsha": "53ba6a624bda7a6e03acdecbd48d43f79e221823", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-11T22:55:50.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-11T22:55:50.000Z", "max_issues_repo_path": "03_hamilton.tex", "max_issues_repo_name": "Spektralzerleger/Hamilton-Systems", "max_issues_repo_head_hexsha": "53ba6a624bda7a6e03acdecbd48d43f79e221823", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "03_hamilton.tex", "max_forks_repo_name": "Spektralzerleger/Hamilton-Systems", "max_forks_repo_head_hexsha": "53ba6a624bda7a6e03acdecbd48d43f79e221823", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.1285563751, "max_line_length": 987, "alphanum_fraction": 0.6671445228, "num_tokens": 18384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587158, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7206128083408443}}
{"text": "\\section{Lecture 1 - Reduction to SAT}\n\n\\begin{frame}\n  \\frametitle{Solving SMT \\formulae by reduction to SAT}\n\n  \\scriptsize\n\n  Approaches to solve SMT \\formulae are based on the observation\n  that SMT can be {\\bf reduced} to SAT, i.e., the purely Boolean\n  Satisfiability Problem\n  \\vfill\n  Consider for instance the \\Lia formula\n  $$\n  \\varphi\\ \\equiv\\ (x - y \\leq 0)\\ \\wedge\\ (y - z \\leq 0)\\ \\wedge\\ ((z - x \\leq -1)\\ \\vee\\ (z - x \\leq -2))\n  $$\n  We may use a Boolean variable $a$ to mean ``$x - y \\leq 0$'' evaluates to $\\top$\n  in the model. Similarly we could use $b, c, d$ for the other \\tatoms, obtaining\n  $$\n  \\psi\\ \\equiv\\ a \\wedge b \\wedge (c \\vee d)\n  $$\n  \\vfill\n  \\pause\n  However we are not done with the encoding ! In fact altough $\\mu^\\Boo \\equiv \\{ a, b, c \\}$ \n  is a (Boolean) model for $\\psi$, the correspondent set of \\tatoms $\\{ x - y \\leq 0, y - z \\leq 0, z - x \\leq -1 \\}$\n  is not consistent in \\Lia: we cannot extend $\\mu^\\Boo$ to a model $\\mu$ that satisfies $\\varphi$.\n  \\pause\n  \\vfill\n  This information can be added to the encoding in the following form\n  $$ \\neg( a \\wedge b \\wedge c )$$\n  \\pause\n  \\vfill\n  Similarly we may derive {\\bf all} the remaining incompatibilities\n  $$ \\neg( a \\wedge b \\wedge d )\\quad\\quad \\neg( \\neg a \\wedge \\neg b \\wedge \\neg c )\\quad\\quad \\neg( \\neg a \\wedge \\neg b \\wedge \\neg d )$$\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Solving SMT \\formulae by reduction to SAT}\n\n  \\scriptsize\n\n  Initial \\Lia formula\n  $$\n  \\varphi \\equiv (x - y \\leq 0) \\wedge (y - z \\leq 0) \\wedge ((z - x \\leq -1) \\vee (z - x \\leq -2))\n  $$\n  Putting all the conditions together we get the Boolean formula\n  $$ \n  \\psi \\equiv\\ a \\wedge b \\wedge (c \\vee d)\\ \\wedge\\ \\neg( a \\wedge b \\wedge c )\\ \\wedge\\ \\neg( a \\wedge b \\wedge d )\\ \\wedge\\\n  \\neg( \\neg a \\wedge \\neg b \\wedge \\neg c )\\ \\wedge\\ \\neg( \\neg a \\wedge \\neg b \\wedge \\neg d )\n  $$ \\pause\n  \\vfill\n  Starting from $\\varphi$ we have\n  \\begin{enumerate}[$(i)$]\n    \\item encoded the structure of $\\varphi$\n    \\item {\\bf exhaustively} encoded all incompatible relations between \\tatoms \n  \\end{enumerate} \n  \\vfill\n  \\begin{theorem}[Exercise 4 - correctness of the encoding]\n    $\\varphi$ is \\T-satisfiable $\\Leftrightarrow$ $\\psi$ is satisfiable,\n    where $\\psi$ is obtained from $\\varphi$ with the steps $(i)$-$(ii)$\n  \\end{theorem}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Exercise 4 - Proof}\n\n  ($a_i$ is the Boolean variable corresponding to a \\tatom $P_i$)\n  \\vfill\n\n  ($\\Rightarrow$)\n  \\medskip \\\\\n  If $\\varphi$ is \\T-satisfiable, then it means that a model $\\mu$ exists.\n  A model $\\mu^\\Boo$ for $\\psi$ can be defined with $\\mu^\\Boo(a_i) = \\mu(P_i)$.\n  \\vfill\\pause\n  \n  ($\\Leftarrow$)\n  \\medskip \\\\\n  Suppose that $\\psi$ is satisfiable but $\\varphi$ is not. If so, then\n  there is a model $\\mu^\\Boo$ (e.g., $\\{ \\neg a_1, a_3 \\}$) such that \n  its encoding (e.g., $(\\neg P_1 \\wedge P_3)$) represents an incompatible relation\n  of \\tatoms. But if it is an incompatible relation, than its negation was\n  added to $\\psi$ (e.g, $\\neg ( a_1 \\wedge a_3 )$), and it should not be satisfied\n  by $\\mu^\\Boo$. Contradiction.\n  \n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Exercize 2}\n\n  \\scriptsize\n\n  Given the unsatisfiable formula \n  $$\n  \\psi \\equiv\\ a \\wedge b \\wedge (c \\vee d)\\ \\wedge\\ \\neg( a \\wedge b \\wedge c )\\ \\wedge\\ \\neg( a \\wedge b \\wedge d )\\ \\wedge\\\n  \\neg( \\neg a \\wedge \\neg b \\wedge \\neg c )\\ \\wedge\\ \\neg( \\neg a \\wedge \\neg b \\wedge \\neg d )\n  $$\n  show that $\\neg( \\neg a \\wedge \\neg b \\wedge \\neg c )$ and $\\neg( \\neg a \\wedge \\neg b \\wedge \\neg d )$ are redundant.\n  \\vfill\\pause\n  The last two clauses are redundant if \n  $$a \\wedge b \\wedge (c \\vee d)\\ \\wedge\\ \\neg( a \\wedge b \\wedge c )\\ \\wedge\\ \\neg( a \\wedge b \\wedge d )$$\n  is already unsatisfiable on its own. \\pause In every model $a$ and $b$ must be assigned to $\\top$. This simplifies\n  the formula to\n  $$(c \\vee d)\\ \\wedge\\ \\neg( c )\\ \\wedge\\ \\neg( d )$$\\pause\n  Now in every model $c$ and $d$ must be assigned to $\\bot$. This simplifies the formula to\n  $$\\bot$$\n\n\\end{frame}\n", "meta": {"hexsha": "d30f298a21d58a74c56cc00a2d8e6d4021cdc851", "size": 4065, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture10/reduction.tex", "max_stars_repo_name": "formalmethods/smtlectures", "max_stars_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-11-07T19:34:12.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-24T08:05:50.000Z", "max_issues_repo_path": "lecture10/reduction.tex", "max_issues_repo_name": "formalmethods/smtlectures", "max_issues_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture10/reduction.tex", "max_forks_repo_name": "formalmethods/smtlectures", "max_forks_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-06T00:40:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-06T00:40:41.000Z", "avg_line_length": 37.2935779817, "max_line_length": 140, "alphanum_fraction": 0.6317343173, "num_tokens": 1500, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048443, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7206127946081425}}
{"text": "\n\\subsection{Chapter 2}\n\n\\begin{p}\n%{\\bf 2} {\\em \nShow that the two definitions of continuity are equivalent: \n \\begin{itemize}\n\\item Topological definition: $f$ is continuous if for any open $U\\subset Y$, $f^{-1}(U)\\subset X$ is also open\n \\item $\\epsilon-\\delta$ definition: $f$ is continuous when for all $x$ and $\\epsilon>0$, there exists a $\\delta>0$ such that $||x-x'||<\\delta$ implies $||f(x)-f(x')||<\\epsilon$. \n\\end{itemize}\n\\end{p}\n{\n \\begin{itemize}\n\\item[$\\Rightarrow$] Pick $f(x)\\in Y$ and $\\epsilon>0$. Set $U=\\{y:||y-f(x)||<\\epsilon\\}$, which is an open set . Thus $f^{-1}(U)$ is also an open set. This means that for all $x\\in f^{-1}(U)$ all points sufficiently close to $x$ are also in $f^{-1}(U)$ or, put differently, for all $x$ there exists $\\delta>0$ such that $N_\\delta(x)=\\{x':||x-x'||<\\delta\\}\\subset f^{-1}(U)$. Thus, $f(x')\\in U$ for all $x'\\in N_\\delta(x)$, which means there exists a $\\delta>0$ such that $||x-x'||<\\delta$ implies $||f(x)-f(x')||<\\epsilon$\n\n \\item[$\\Leftarrow$] Pick any open $U$. Now we must show that $f^{-1}(U)$ is open. For any $f(x)\\in U$ there exists $\\delta>0$ such that $||x-x'||<\\delta$ means $||f(x)-f(x')||<\\epsilon$, so we can pick $\\epsilon$ small enough to ensure that $\\{f(x'):||f(x)-f(x')||<\\epsilon\\}\\subset U$. Hence, for any point $x\\in f^{-1}(U)$, points sufficiently close are also in $f^{-1}(U)$: $f^{-1}(U)$ is open. \n\\end{itemize}\n}\n\n\\begin{p}\nShow that $S^n\\subset \\R^{n+1}$ with its induced topology is a manifold.\n\\end{p}\nWe need to check that the transition functions are smooth. This can be ensured by \nmapping each of the subsets of the sphere back into $\\R^{n+1}$ and\napplying the transition function there (it's the identity function there).\n\n\n\\begin{p}\nShow that if $M$ is a manifold and $U$ is an open subset of $M$, then $U$ with its \ninduced topology is a manifold.\n\\end{p}\n{\nThe only thing one really needs to check is the smoothness of the transition functions\n$\\varphi_\\alpha \\circ \\varphi_\\beta^{-1}$. But this property is directly inherited from $M$,\nsince subsets of the form $U \\cap S$ where $S$ is open in $M$ are themselves open\nsubsets of $M$.\n}\n\n\\begin{p}\nGiven topological spaces $X$ and $Y$, we give $X\\times Y$ the product topology in which a set is open if and only if it is a union of sets of the form $U\\times V$,where $U$ is open in $X$ and $V$ is open in $Y$. Show that if $M$ is an $m$-dimensional manifold and $N$ is an $n$-dimensional manifold, $M \\times  N$ is an $(m + n)$-dimensional manifold.\n\\end{p}\n{...}\n\\begin{p}\nGiven topological spaces $X$ and $Y$, we give $X\\times Y$ the disjoint union topology in which a set is open if and only if it is the union of an open subset of $X$ and an open subset of $Y$. Show that if $M$ and $N$ are $n$-dimensional manifolds the disjoint union $M \\cup N$ is an $n$-dimensional manifold.\n\\end{p}\n{...}\n\n\n", "meta": {"hexsha": "7eed0951aacd3fa2da076e3a7c50d0afaaaacc05", "size": 2849, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/I2.tex", "max_stars_repo_name": "joerenes/Baez-Muniain-solutions", "max_stars_repo_head_hexsha": "e1e38de9acab877bc4200af59c7910d42de748ca", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-04-13T12:10:03.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-19T18:18:34.000Z", "max_issues_repo_path": "src/I2.tex", "max_issues_repo_name": "joerenes/Baez-Muniain-solutions", "max_issues_repo_head_hexsha": "e1e38de9acab877bc4200af59c7910d42de748ca", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-04-13T12:15:30.000Z", "max_issues_repo_issues_event_max_datetime": "2017-04-13T20:19:44.000Z", "max_forks_repo_path": "src/I2.tex", "max_forks_repo_name": "joerenes/Baez-Muniain-solutions", "max_forks_repo_head_hexsha": "e1e38de9acab877bc4200af59c7910d42de748ca", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.1428571429, "max_line_length": 523, "alphanum_fraction": 0.661986662, "num_tokens": 936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950986284991, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7206127837349515}}
{"text": "\n\\subgroup{4}{Rob Ruigrok}\n\n\\paragraph{Description}\nThis chapter will cover the derivation of the dynamics of a heavy chain with uniform density $\\rho$, length $L$ and a point mass on the end with mass $m$. The top of the chain will be suspended on a rolling trolley, where the lateral speed can be controlled. First, we will derive the dynamics, and later go into more detail on the \"flatness\" of the system and several control inputs.\n\n\\paragraph{Model}\n\nAn overview of the system is provided in figure \\ref{fig:heavychainoverview}. Let $x$ be coordinate along the length of the chain, where the chain is attached to the trolley at $x=L$. The lateral displacement of the chain is denoted by $y(x,t)$. The problem can be made more complex by adding a point mass $m$ to the end of the chain.\n\n\\begin{figure}[h]\n\\label{fig:heavychainoverview}\n\\centering\n\\includegraphics[width = 4cm]{Overview.png}\n\\end{figure}\n\nThe derivation of the dynamics goes largely the same as the derivation of the vibrating spring. Here, however, the tension in the chain will be depending on $x$, and there will now be different boundary conditions linked to the trolley at the top and the attached mass at the bottom. Figure \\ref{fig:heavychaindx} illustrates the forces acting on a finite chain element of length $dx$, which is the basis in the derivation of the PDE.\\newline\n\n\\begin{figure}[h]\n\\label{fig:heavychaindx}\n\\centering\n\\includegraphics[width = 5cm]{SmallElement.png}\n\\end{figure}\n\nWe start with defining the tension in the chain as a function of $x$:\n\n\\begin{equation}\n\\label{eq:chaintension}\nT = (m + x\\rho)g\n\\end{equation}\n\nTo analyze the dynamics, we are interested of the lateral component of this tension. When examining an infinitesimal chain element of length $\\Delta x$, we are interested in the net lateral force. Instead of defining the force on both sides of element $\\Delta x$, we here determining the difference by using a first order Taylor approximation, together with a small angle approximation:\n\n\\begin{equation}\n\\label{eq:chainapprox}\nsin(\\theta)T \\approx tan(\\theta)T = \\frac{\\partial y}{\\partial x}T\n\\end{equation}\n\n\\begin{equation}\n\\label{eq:chainforce}\n\\Delta F \\approx F_x \\Delta x = \\big[\\frac{\\partial y}{\\partial x}T\\big]_x \\Delta x\n\\end{equation}\n\nThe lateral motion of an infinitesimal chain element can now be described with Newtons second law of motion, $F = ma$, for which the net force is defined in equation \\ref{eq:chainforce}. The mass of the chain element is $\\rho \\Delta x$, and the acceleration is $\\frac{\\partial^2 y}{\\partial t^2}$\n\n\\begin{equation}\n\\begin{aligned}\n    F &= ma \\\\\n    \\big[\\frac{\\partial y}{\\partial x}T\\big]_x \\Delta x &= \\rho \\Delta x \\frac{\\partial^2 y}{\\partial t^2} \\\\\n    \\big[\\frac{\\partial y}{\\partial x} (m + x\\rho)g \\big]_x &= \\rho \\frac{\\partial^2 y}{\\partial t^2}\n\\end{aligned}\n\\end{equation}\n\nWhen there is no mass suspended to end of the chain, the dynamics can be further written out:\n\n\\begin{eqnarray}\n\\label{eq:chainPDE}\n    \\big[\\frac{\\partial y}{\\partial x} x \\rho g \\big]_x &=& \\rho \\frac{\\partial^2 y}{\\partial t^2} \\\\\n    g \\big[\\frac{\\partial y}{\\partial x} x \\big]_x &=& \\frac{\\partial^2 y}{\\partial t^2} \\\\\n    g \\big[x \\frac{\\partial^2 y}{\\partial x^2} + \\frac{\\partial y}{\\partial x} \\big] &=& \\frac{\\partial^2 y}{\\partial t^2}\n\\end{eqnarray}\nwith boundary condition: $y(L,t) = u(t) $.\n\n\n\\paragraph{Solving the PDE}\n\\bigskip\n\\emph{\\textbf{TODO: move part of it to control section\n}}\\bigskip\n\nIt is difficult to directly find a solution for the partial differential equation in equation~5\\ref{eq:chainPDE}). For this particular problem, we assume that we know that we can rewrite to a Bessel function. Bessel functions are mainly used to describe wave propagation, and have the following format, where $\\alpha$ denotes the order of the Bessel function:\n\n\\begin{equation}\n\\label{eq:Bessels}\nx^2\\frac{d^2 y}{dx^2} + x\\frac{dy}{dx} + (x^2 - \\alpha^2)y = 0\n\\end{equation}\n\nIn order to make the formulation in equation \\ref{eq:chainPDE} fit this a zero-order Bessel function, we have to do certain changes of variables and convert the problem to the Laplace domain. In the Laplace domain, we can find solutions for our type of Bessel function, after which we need to transform it back to the time domain and reverse the variable changes. \\newline\n\n\\paragraph{Step 1: substitution}\n\nFirst step, do a substitution with $p = 2\\sqrt{\\frac{x}{g}}$. This will change the dependency from y(x,t) to y(p,t). Use the chain rule and find fill out the new values:\n\n\\begin{equation}\n\\label{eq:ChainRule}\n\\begin{aligned}\n\\frac{\\partial p}{\\partial x} &= \\frac{1}{g}\\bigg(\\frac{x}{g}\\bigg)^{-\\frac{1}{2}} = \\frac{1}{g\\sqrt{\\frac{x}{g}}} = \\frac{2}{gp}\\\\\n\\frac{\\partial y}{\\partial x} &=  \\frac{\\partial y}{\\partial p} \\frac{\\partial p}{\\partial x} + \\frac{\\partial y}{\\partial t} \\cancelto{0}{\\frac{\\partial t}{\\partial x}} = \\frac{\\partial y}{\\partial p} \\frac{2}{gp}\n\\end{aligned}\n\\end{equation}\n\nWhen we fill everything out in the left part of equation \\ref{eq:chainPDE}, we get the following expression:\n\n\\begin{equation}\n\\label{eq:chaincombination1}\n\\begin{aligned}\ng \\frac{\\partial}{\\partial x}\\big[\\frac{\\partial y}{\\partial x} x \\big] &= g \\frac{\\partial}{\\partial x}\\big[\\frac{\\partial y}{\\partial p} \\frac{2}{gp} \\frac{1}{4}gp^2 \\big] = g \\frac{\\partial}{\\partial x}\\big[\\frac{\\partial y}{\\partial p} \\frac{p}{2} \\big] \\\\\n&= g \\frac{\\partial}{\\partial p}\\big[\\frac{\\partial y}{\\partial p} \\frac{p}{2} \\big]\\frac{\\partial p}{\\partial x} = g \\big[\\frac{\\partial^2 y}{\\partial p^2} \\frac{p}{2} + \\frac{1}{2} \\frac{\\partial y}{\\partial p}\\big] \\frac{2}{gp} \\\\\n&= \\frac{\\partial^2 y}{\\partial p^2} + \\frac{1}{p} \\frac{\\partial y}{\\partial p}\n\\end{aligned}\n\\end{equation}\n\nSo the total equation can be written as:\n\\begin{eqnarray}\n\\label{eq:chaincombination2}\n g \\big[\\frac{\\partial y}{\\partial x} x \\big]_x - \\frac{\\partial^2 y}{\\partial t^2} &=& 0 \\\\\n  \\frac{\\partial^2 y}{\\partial p^2} + \\frac{1}{p} \\frac{\\partial y}{\\partial p} - \\frac{\\partial^2 y}{\\partial t^2} &=& 0 \\\\\n p \\frac{\\partial^2 y}{\\partial p^2} +\n  \\frac{\\partial y}{\\partial p} - p \\frac{\\partial^2 y}{\\partial t^2} &=& 0\n\\end{eqnarray}\n\n\\paragraph{Step 2: transform to Laplace domain}\n\nWhen converting the from the time domain, we use the following notation:\n\\begin{center}\n$y(x,t) \\xrightarrow{\\mathcal{L}} Y(x,s)$\n\\end{center}\nFurther, to get the Laplace transform in the desired format, we require that the systems is initially \\textit{at rest}, which means that $y(x,0)=0$ and $\\dot{y}(x,0)=0$.\n\n\\begin{equation}\n\\label{eq:heavychainlaplace}\n\\begin{aligned}\n p \\frac{\\partial^2 y(x,t)}{\\partial p^2} +\n  \\frac{\\partial (x,t)}{\\partial p} - p \\frac{\\partial^2 y(x,t)}{\\partial t^2} = 0 \\\\\n  \\xrightarrow{\\mathcal{L}}\n p \\frac{\\partial^2 Y(x,s)}{\\partial p^2} +\n  \\frac{\\partial Y(x,s)}{\\partial p} - p s^2 Y(x,s) = 0\n\\end{aligned}\n\\end{equation}\n\nNEW CHANGE OF VARIABLES (did it myself on paper, still need to isert)\\newline\nBessel function!\n\n\n", "meta": {"hexsha": "e9606c846174405a60ea34e231a92750815db9a1", "size": 6977, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modeling-HeavyChain.tex", "max_stars_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_stars_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-08T02:54:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-29T06:19:28.000Z", "max_issues_repo_path": "modeling-HeavyChain.tex", "max_issues_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_issues_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "modeling-HeavyChain.tex", "max_forks_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_forks_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-16T17:29:03.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-16T17:29:03.000Z", "avg_line_length": 52.0671641791, "max_line_length": 442, "alphanum_fraction": 0.7073240648, "num_tokens": 2169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8418256631249077, "lm_q2_score": 0.8558511506439707, "lm_q1q2_score": 0.7204774624270759}}
{"text": "\n\\subsection{Simple iterations}\n\n\\begin{Algorithm*}{vector-iteration}{Vector iteration (power method)}\n  \n\\end{Algorithm*}\n\n\\begin{Theorem}{vector-iteration}\n  Lat $\\mata\\in\\Cnn$ be diagonalizable such that $\\lambda_1$ is the\n  unique eigenvalue with maximal modulus. Let furthermore the\n  component of $v^{(0)}$ in direction of the first eigenvector be\n  nonzero. Then, the factors $\\alpha_k$ and vectors $v^{(k)}$ of the\n  vector iteration converge to the eigenvalue $\\lambda_1$ and its\n  associated eigenvector. Moreover, there holds\n  \\begin{align}\n    \\abs{\\alpha_{k+1}-\\lambda_1}\n    &\\le \\frac{\\abs{\\lambda_1}}{\\abs{\\lambda_2}} \\abs{\\alpha_{k}-\\lambda_1}\\\\\n    \\norm{v^{(k+1)}-u_1}\n    &\\le \\frac{\\abs{\\lambda_1}}{\\abs{\\lambda_2}} \\norm{v^{(k)}-u_1}\n  \\end{align}\n\\end{Theorem}\n\n\\begin{Remark}{vector-iteration}\n  The proof actually requires, that the entry defining $\\alpha_k$\n  remains the same during the iteration, at least during the steps\n  used for detecting convergence.\n\n  The result does not actually require that $\\mata$ is diagonalizable,\n  as long as $\\lambda_1$ is single and of largest modulus.\n\\end{Remark}\n\n\\begin{Algorithm*}{shifted-vector-iteration}{Shifted vector iteration}\n  The vector iteration can be applied to the matrix $\\mata-\\sigma\\id$\n  for some $\\sigma\\in\\C$.\n\n  Then, $\\alpha_k$ converges to the eigenvalue $\\lambda$ such that\n  $\\lambda-\\sigma$ has largest modulus. $v^{(k)}$ converges to an\n  eigenvector for this eigenvalue.\n\\end{Algorithm*}\n\n\\begin{Algorithm*}{inverse-iteration}{The inverse power method}\n  \n\\end{Algorithm*}\n\n\\begin{Algorithm*}{Rayleigh-iteration}{The Rayleigh quotient iteration}\n  \n\\end{Algorithm*}\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "442d62546605e5ec95fb51853dbae1bca0a48b2b", "size": 1733, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nla/vector-iterations.tex", "max_stars_repo_name": "guidokanschat/notes", "max_stars_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "nla/vector-iterations.tex", "max_issues_repo_name": "guidokanschat/notes", "max_issues_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-05-24T07:31:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-31T12:58:14.000Z", "max_forks_repo_path": "nla/vector-iterations.tex", "max_forks_repo_name": "guidokanschat/notes", "max_forks_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-05-15T19:28:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-05T19:07:29.000Z", "avg_line_length": 32.0925925926, "max_line_length": 77, "alphanum_fraction": 0.7137911137, "num_tokens": 507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741042, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7204774564291574}}
{"text": "\\section{Quadratic Hamiltonians and the Equipartition Function}\n\\begin{align}\n    H &= \\sum_{i=1}^{N}\\left( \n    \\frac{p_i^2}{2m_i} + \\frac{m_i\\omega_i^2}{2}x_1^2\n    \\right)\n\\end{align}\nThe partition function is\n\\begin{align}\n    Z &= \\int_{-\\infty}^{\\infty} \\prod_{i=1}^{N} \\frac{dx_i\\, dp_i}{h^N}\n    e^{-\\beta\\sum_{i}\\left( \n    \\frac{p_i^2}{2m_i}\n    + \\frac{m_i\\omega_i^2}{2} x_i^2\n    \\right)}\\\\\n    &=\n    \\prod_{i=1}^{N}\\frac{1}{h}\\int_{-\\infty}^{\\infty} e^{%\n    -\\frac{\\beta m_i\\omega_i^2}{2}x_i^2\n    }\n    \\int_{-\\infty}^{\\infty} dp_i\\,\n    e^{-\\beta \\frac{p_i^2}{2m_i}}\\\\\n    &= {\\left(\\frac{k_B T}{\\hbar}\\right)}^{N} \\frac{1}{\\prod_{i=1}^{N}\\omega_i}\n\\end{align}\nThen the free energy is\n\\begin{align}\n    F &= -k_B T \\ln Z \\\\\n    &=\n    -N k_B T \\ln\\left( \\frac{k_B T}{2} \\right)\n    +\n    k_B T \\sum_{i=1}^{N} \\ln\\omega_i\n\\end{align}\nThe energy is\n\\begin{align}\n    E &= F + TS\n\\end{align}\nwhere\n\\begin{align}\n    S &= \\frac{\\partial F}{\\partial T}\\\\\n    &= Nk_B \\ln\\left( \\frac{k_B T}{\\hbar}  \\right)\n    + \\frac{N k_B T}{T}\n    - k_B \\sum_{i=1}^{N}\\ln \\omega_i\n\\end{align}\nand so the energy is\n\\begin{align}\n    E &= Nk_B T =\n    \\left(\n    \\frac{k_B T}{2}\n    + \\frac{k_B T}{2}\n    \\right) N\n\\end{align}\nTextbooks are confusing and students fall for it.\nI think a 1D harmonic oscillator has 1 degree of freedom.\nI think a 1D free particle also has 1 degree of freedom.\nForget degrees of freedom,\nwhat matters is the number of quadratic terms in the Hamiltonian.\n\nEach quadratic term in the Hamiltonian has energy $\\frac{1}{2}k_B T$.\n\n\\begin{example}\n    1D array of masses connected by springs with periodic boundary conditions.\n\\end{example}\nThe Hamiltonian is\n\\begin{align}\n    H &=\n    \\sum_{i=1}^{N}\\left[ \n    \\frac{p_i^2}{2m}\n    + \\frac{k}{2} {\\left( x_i - x_{i-1} \\right)}^2\n    \\right]\n\\end{align}\nSo this is quadratic but a slightly more complicated quadratic.\nYou see there are cross-terms like $-2x_2x_3 + \\cdots$ in there.\nYou have to account for boundary conditions too.\nYou have to say that $x_N = x_0$,\nincluding the one that wraps around.\nThere are 3 terms and they are all there.\n\nWhat you learn in Chacko's class is that you can do a change of variables that's\ngoing to make this quadratic Hamiltonian that is decoupled.\nThis is called finding the normal modes.\nIt's something you're going to relearn in Chacko's class.\n\nI'm going to state here that you can do a change in variables.\nThat's going to be equivalent to this\n\\begin{align}\n    H &=\n    \\sum_{i=0}^{N-1}\\left[ \n    \\frac{p_i^2}{2m}\n    + \\frac{m\\omega_1^2}{2} q_i^2\n    \\right]\n\\end{align}\nBasically the $q_i$s are Fourier transforms of the $x_i$'s.\nYou will find that the magic works and the $q$'s are independent of one another.\n\nIf there s one canonical transformation to learn,\nit's this one.\nThe range of applicability of this calculation is huge.\nBasically physics is to do more and more complicated cases of harmonic\noscillators.\n\nNow I can complete the partition function of these guys,\ntaking both terms and just writing the answer.\n\nWhat is the average energy of this guy of temperature $T$?\n\nIt's $\\frac{1}{2}k_B T$ for every quadratic term.\nThere are $2N$ terms.\nThis is going to be again\n\\begin{align}\n    E &= \\frac{1}{2}k_B T \\times 2 \\times N = Nk_BT\n\\end{align}\nAll you needed to know how many normal modes.\nYou didn't even need to find the frequency.\nIn physics 101,\nthey shake a slinky.\nThere are transverse modes,\nlongitudinal modes,\nand more complicated modes I can't do with my hands.\nEach one has different frequencies.\nSome long wavelength ones move fast or slow,\nbut it doesn't matter for the average energy $E$,\nit's just $\\frac{1}{2}k_BT$ for every quadratic term in the Hamiltonian.\n\nWe can now state the equipartition theorem.\n\n\\begin{question}\n    How do you know how many terms?\n\\end{question}\nIf you start with $N$ coordinates,\nyou get $N$ normal modes no matter how complicated.\n\n\\begin{theorem}[Equipartition]\n    The thermal average energy of a Hamiltonian $H$ is\n    \\begin{align}\n        E &= \\frac{1}{2} k_B T N\n    \\end{align}\n    where $N$ is hte numbero f quadratic terms in $H$.\n\\end{theorem}\nThis is true for classical systems.\n\nLet's consider a few systems now for examples.\n\n\\begin{example}\n    Imagine you have a solid insulator.\n    what is the average enregy of an insulating solid?\n\\end{example}\nPlease give an example of a solid.\nYou give 5 things that re not solids with crystal structures.\nGlass, styrofoam, plastic.\nThey're all rigid,\nbut they're not solids.\nThe reason I'm not talking about insulators,\nis because they have electrons that move around adn that changes the energy.\nI'm thinking of an insulator solid,\njust a bunch of molecules in a lattice that shake.\n\nThe modules have an equilibrium position,\nandthey shake around in a complicated way.\nTo first approximation,\nthey have some quadratic terms,\nand you expand in powers like the distance between the atoms,\nand the energy is quadratic.\n\nYou want to know how many modules htere are.\nSupposey ou have $N$ modules on my chunck of rock.\nHow many quadratic terms do I have in the Hamiltnian?\n\nThere's a 3D knietic term,\nso that's 3 quadratic terms for the kinetic enregy.\nWhata bout the potential energy?\nAgain every module has 3 coordiantes $x,y,z$,\nso there are 3 quadratic terms per molecule.\nSo the energy should be\n\\begin{align}\n    E &= \\left( \n    \\underbrace{3N}_{\\text{kinetic}}\n    + \\underbrace{3N}_{potential}\n    \\right)\n    \\frac{1}{2}k_B T\\\\\n    &= 3Nk_B T\n\\end{align}\n\n\\begin{question}\n    Are you assuming a cubic lattice?\n\\end{question}\nNo, it could bea really complicated crystal structure,\nbut you still have the same number of normal modes.\n\nThe specific heat of the substance is\n\\begin{align}\n    c &= \\frac{1}{N}\\frac{\\partial E}{\\partial T} = 3k_B\n\\end{align}\n\nWe could check this.\nEvery insulating solid should have exactly the same specific heat.\nThat's amazing.\nAndi t's not just any number,\nnad it's a specific number.\n\nYou can see this thing here\nWhat I have here isa bunch of pure elements,\nandh ere I have a specific heat of hte number.\nThe line in  the middle is $3k_B$.\n\nThis starts from 30,\nand they're all around 23.\nSo you know there are bad ones like potassium 29,\nthere's another one 23.\n\nIt's an amazing result.\nSee the work we did.\n\n\\begin{question}\n    Are we assuming only neighbouring particles are talking to each other?\n\\end{question}\nNo, I could have $x_1$ connected to $x_{42}$.\nAs long as the energy is quadratic in distance,\nit doesn't matter.\nYou could find the normal modes,\nand you find there are $3N$ normal modes,\nand that's the only thing that matters.\n\n\\begin{question}\n    At higher temperatures in a crystal lattice,\n    you'l have anharonic effects \n    like thermal expansion,\n    does that influene the specifi heat?\n\\end{question}\nThere's no non-linear effects that contribute at high temperature.\nHow much does a rock expand when you heat a rock.\n\nThis is the Dulong-Petit law.\nValidity because it really cnovineced people that convineced people statistical\nmechanics was right.\nIt's failure is that it suggested quantum mechanics.\n\nBefore we dothat,\nlet's do a really classic case.\nClassic in classical mechanics and classic in that you do it in high school.\n\n\\begin{example}[diatomic gas]\n    Ideal, nonrelativistic, classical gas.\n    What if it's diatomic?\n\\end{example}\nThe molecules now look like this.\n[picture]\nSo what's the answer?\nIf there are $N$ molecules,\nhow many quadratic terms are you going to have?\n\nEvery particle can move in the $x,y,z$ directions,\nbut the two particles don't move independently,\nso that's $6N$ terms.\nBut there is a potential term for the spring between the two particles,\nso\n\\begin{align}\n    E &= (6N + N)\\frac{1}{2}k_B T = \\frac{7}{2}Nk_B T\n\\end{align}\n", "meta": {"hexsha": "099d1654580d1f6942903024726bdecb9f6fd243", "size": 7770, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys612/lecture20.tex", "max_stars_repo_name": "ehua7365/umdphysnotes", "max_stars_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-11T12:53:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-11T12:53:46.000Z", "max_issues_repo_path": "phys612/lecture20.tex", "max_issues_repo_name": "ehua7365/umdphysnotes", "max_issues_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "phys612/lecture20.tex", "max_forks_repo_name": "ehua7365/umdphysnotes", "max_forks_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3515625, "max_line_length": 80, "alphanum_fraction": 0.7120978121, "num_tokens": 2294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256512199033, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7204774537857391}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS622: Theory of Formal Languages\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 3}\n\nConsider the context-free grammar $ G = (\\{S,X_1,X_2,X_3\\},\\{a,b\\},S,\\{S\\rightarrow X_1 S X_2 X_3, S\\rightarrow \\lambda, X_1 \\rightarrow ab, X_1 \\rightarrow X_1 X_2 X_3, X_2 \\rightarrow a X_1 b, X_2 \\rightarrow \\lambda, X_3 \\rightarrow X_2 X_1 a b, X_3 \\rightarrow b, X_3 \\rightarrow \\lambda \\})$.\nConstruct an equivalent grammar without erasure productions.\n\n\\subsection*{Solution}\n\nWe use the procedure described in Theorem 4.5.4 given in \\cite{simovici1999theory}.\n$G$ is reconstructed as $ G = (\\{S,X_1,X_2,X_3, X_a, X_b\\},\\{a,b\\},S,\\{S\\rightarrow X_1 S X_2 X_3, S\\rightarrow \\lambda, X_1 \\rightarrow X_aX_b, X_1 \\rightarrow X_1 X_2 X_3, X_2 \\rightarrow X_a X_1 X_b, X_2 \\rightarrow \\lambda, X_3 \\rightarrow X_2 X_1 X_a X_b, X_3 \\rightarrow X_b, X_3 \\rightarrow \\lambda, X_a \\rightarrow a, X_b \\rightarrow b \\})$.\n\nThe sequence of subsets of $\\{S,X_1,X_2,X_3, X_a, X_b\\}$ constructed in Theorem 4.5.4 would be,\n\n\\begin{equation}\n\\begin{aligned}\nU_0 &= \\{X | X\\in A_N, X\\rightarrow \\lambda \\in P\\}\\\\\n&= \\{S, X_2, X_3\\}\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\nU_{1} &= U_{0} \\cup \\{X\\in A_N | X\\rightarrow \\alpha \\in P, \\alpha \\in U^*_0\\}\\\\\n&= \\{S, X_2, X_3\\} \\cup \\emptyset\\\\\n&= U_{0}\n\\end{aligned}\n\\end{equation}\n\nTherefore, the set of productions $P^\\prime$ constructed is given by\n\n\\begin{equation}\n\\begin{aligned}\nP^\\prime =\\ & \\{S\\rightarrow X_1SX_2X_3,\\ S\\rightarrow X_1SX_2,\\ S\\rightarrow X_1SX_3,\\ S\\rightarrow X_1X_2X_3,\\\\\n& S\\rightarrow X_1S,\\ S\\rightarrow X_1X_2,\\ S\\rightarrow X_1X_3,\\ S\\rightarrow X_1,\\\\\n& X_1 \\rightarrow X_aX_b,\\ X_1\\rightarrow X_1X_2X_3,\\ X_1 \\rightarrow X_1X_2,\\ X_1 \\rightarrow X_1X_3\\\\\n& X_2 \\rightarrow X_aX_1X_b,\\ X_3\\rightarrow X_2X_1X_aX_b,\\ X_3\\rightarrow X_1X_aX_b,\\\\\n& X_3 \\rightarrow X_b,\\ X_a\\rightarrow a,\\ X_b \\rightarrow b\\}\n\\end{aligned}\n\\end{equation}\n\nAnd the equivalent grammar $G^\\prime=(A_N, A_T, S, P^\\prime)$ would be the equivalent grammar of $G$ without erasure productions.\n", "meta": {"hexsha": "60f70acecdfc5bf1b8cadac907edf03526be74bd", "size": 2341, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs622-2015f/src/tex/hw03/hw03q03.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs622-2015f/src/tex/hw03/hw03q03.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs622-2015f/src/tex/hw03/hw03q03.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 48.7708333333, "max_line_length": 349, "alphanum_fraction": 0.6753524135, "num_tokens": 871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138366, "lm_q2_score": 0.8418256492357359, "lm_q1q2_score": 0.7204774412545625}}
{"text": "\\documentclass[12pt]{article}\n\\setlength\\parindent{0pt}\n\\usepackage{graphicx}\n\\usepackage[margin=1.0in]{geometry}\n\\usepackage{amsmath}\n\\usepackage{ulem}\n\\usepackage{color}\n\\usepackage{hyperref}\n\\setlength{\\parindent}{2em}\n\\graphicspath{ {./images/} }\n\\title{CTA200H Assignment 2}\n\\author{Sarah Thiele}\n\\date{\\today}\n\n\\begin{document}\n\\maketitle\n\n\\section{Question 1:}\n\\subsection{Methods}\nThis question studied the divergence of the magnitude-squared of the function \n\\begin{align}\n    z_{i+1}=z_i + c\n\\end{align} \nfor numbers $c$ in the complex plane with real and imaginary parts $-2 \\leq x,y \\leq 2$. Here the magnitude, or absolute value, squared is defined as $|z_{i+1}|^2=(Re[z_{i+1}])^2+(Im[z_{i+1}])^2$. In order to work with every combination of $x$ and $y$ values, I defined 400-element arrays of each, and used numpy's function \"meshgrid\" which created a 2-dimensional array filled with the $x$ and $y\\cdot i$ arrays. I then defined my complex array ``c\" to be the sum of the zeroth and first dimension of the mesh such that we get a $400^2$ length array of the form $x+iy$. I arbitrarily defined an epsilon value of $\\epsilon=100.0$ to use as a divergence measure, and a maximum iteration count of $i=1000$. We were given $z_0 = 0.0$. \n\nI next defined a function $recursion(c)$ which takes in the mesh c and uses a for loop to iterate Function (1). At each iteration, it takes the magnitude squared of the updated $z$ value, i.e $|z_{i+1}|^2$. If this value is greater than epsilon, then that element of the c array is said to be divergent. The function than adds the divergent values from that iteration to an array of divergent numbers, and adds the iteration number to another array the same number of times as the amount of divergent $z$ values there are for the iteration. e.g if three numbers diverge at iteration $i$, then those three numbers will be appended to the array defined as ``z\\_div\", and the iteration number $i$ will be appended three times to the array ``i\\_div\". This allows for every divergent element to have an iteration number associated with it when we plot the colour dimension, dependent on this quantity. The function then gets rid of values from the c array and the $z_i$ array which are divergent using a Boolean mask, and then moves on to the next iteration. Once we hit the maximum iteration number, the function defines all the remaining numbers to be those that remain bounded, and returns the arrays of bounded and divergent numbers as well as the iteration number array. We can then plot the complex plane with two colours defining the bound vs. divergent values, as we see in Figure 1, or with a colour scale which depends on the iteration number of divergence, like in Figure 2 and zoomed in version Figure 3, using matplotlib.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.80]{Q1plot3_CITA200HA2.png}\n    \\caption{The divergence of complex magnitudes for $c = x + iy$ with $-2\\leq x,y \\leq 2$. The light blue region represents values that remain bounded, and the dark blue values diverge. Divergence was defined to be when $|z_{i+1}|^2 \\geq 100.0$.}\n    \\label{fig:my_label}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.73]{Q1plot1_CITA200HA2.png}\n    \\caption{The same procedure as Figure 1, now coloured according to the value at which the number diverged, which is shown according to the colour bar. The light purple inner region again represents values which stay bounded.}\n    \\label{fig:my_label}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.73]{Q1plot2_CITA200HA2.png}\n    \\caption{A closer look at our plot from Figure 2.}\n    \\label{fig:my_label}\n\\end{figure}\n\n\\pagebreak \n\\subsection{Analysis}\n\nWhat arises from the results of this question is the \\href{https://en.wikipedia.org/wiki/Mandelbrot_set}{\\color{blue}\\uline{Mandelbrot Set}}, which would become increasingly intricate if we were to iterate with arrays of a smaller step size. Unfortunately, the computation time increases extremely fast for this function. We see that values closest to and on the boundary of the bounded region diverge much later than values further away from the bounded region. Outside the boundary, the values diverge almost immediately. We see that besides the main cardioid, the pattern is periodic with various sized circular bulbs. Furthermore the pattern is symmetric when flipped across the $x$-axis. When we zoom in, we can see there are small trails of slightly larger divergence iteration numbers that seep into the outer regions. These trails are lighter (diverge later) than those on the boundary. There is also a very faint tail that points straight leftwards from the smallest leftside bulb of the pattern and connects in a straight line to a small dot at ~(-1.75, 0.00). \n\nThe zoomed-in plot had higher resolution, as it was along a smaller range of values ($-1.30 \\leq x \\leq -0.50$ and $0.00 \\leq y \\leq 0.65$), and the $x$ and $y$ arrays were each 600 elements in length. The faint trails are more pronounced and we can see some of the finer detail along the boundary.\n\n\\section{Question 2:}\n\\subsection{Methods}\n\\subsubsection{SIR Model}\nIn this question we were investigating the SIR Model in epidemeology which models the spread of disease for a given population. It is based on the following set of three ordinary differential equations:\n\n\\begin{align}\n    \\frac{dS}{dt} &= -\\frac{\\beta S I}{N} \\\\\n    \\frac{dI}{dt} &= \\frac{\\beta S I}{N} - \\gamma I \\\\\n    \\frac{dR}{dt} &= \\gamma I\n\\end{align}\n\nAs we can see, $\\frac{dS}{dt} + \\frac{dI}{dt} + \\frac{dR}{dt} = 0$. Here $S(t)$ is the amount of the population susceptible to the disease and $I(t)$ is the number of infected individuals. In our homework it states that $R(t)$ is the number of recovered individuals who are now immune, but often $R(t)$ in the SIR model is simply the removed population, i.e those which are no longer susceptible or infected. It does not differentiate between those who are deceased and those that are recovered and now immune. For our purposes we will assume a death rate of 0\\% such that $R(t)$ is the number of recovered individuals.\n\nFor the SIR Model, $\\beta$ is the average number of contacts per person per time, i.e the infection rate, and $\\gamma$ is often defined as $\\frac{1}{T}$, where $T$ is the amount of time an individual is infectious for before an outcome occurs. N is the population number. \n\nThe mathematical term $R_0$ to used to describe how contagious a disease is. It tells us how many people one individual will infect on average. It is also described with $R_0 = \\frac{\\beta}{\\gamma}$. I chose $R_0 = 5$, and then calculated three values for $\\beta$ from three values of $\\gamma$ I chose from common ranges I saw online. We were also given initial values for S, I and R as 999, 1, and 0 respectively. The population number N is 1000.\n\nTo solve the system of ODEs, I used scipy.integrate's solve\\_ivp. I first defined a model function which takes in a time array, a vector of S, I, and R for a particular time step, and the two parameters $\\beta$ and $\\gamma$. It calculates the current rate of change from the three equations and returns them in a list. For various values of $\\beta$ and $\\gamma$, solve\\_ivp solves the system of ODEs for the defined time span of 0 to 200 and outputs a time array and the values of S, I, and R as a function of time. I then plotted the various curves.\n\n\\subsubsection{SIRD Model}\n\nWe now switch to the SIRD Model. S is again the number of people susceptible, and I those infected, to a disease as a function of time. The SIRD model is important as it differentiates the old R, the removed population from the SIR model, into either being recovered/immune (R) or deceased (D). $\\beta$ is the infection rate, $\\gamma$ is the recovery rate, and we add $\\mu$, the now non-zero mortality rate. The ODEs change now to accommodate this: \n\n\\begin{align}\n    \\frac{dS}{dt} &= - \\frac{\\beta S I}{N} \\\\\n    \\frac{dI}{dt} &= \\left(\\frac{\\beta S}{N} - \\gamma - \\mu\\right) \\cdot I \\\\\n    \\frac{dR}{dt} &= \\gamma I \\\\\n    \\frac{dD}{dt} &= \\mu I\n\\end{align}\n\nI assumed a mortality rate of 1\\% and an initial death number of 0. The rest of the solution is the same as for the SIR Model, just with an extra ODE to solve. The other initial values, population number, and arrays for $\\beta$ and $\\gamma$ also remain the same. See \\hyperref[subsec:AnalysisQ2]{\\color{blue}\\uline{here}} for analysis of Figure 4 and 5.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.35]{SIR_Model_CTA200HQ2.png}\n    \\caption{Caption}\n    \\label{fig:my_label}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.35]{SIRD_Model_CTA200HQ2.png}\n    \\caption{Caption}\n    \\label{fig:my_label}\n\\end{figure} \n\n\\pagebreak\n\n\\subsection{Analysis}\n\\label{subsec:AnalysisQ2}\n\n\\subsubsection{SIR Model: Figure 4}\nWe see the expected general trends: the susceptible population decreases as people are moved into either the infected or recovered category over time; the number of infected individuals increases rapidly, and decreases quite quickly as well for our parameters, with the decline of infection mirrored by a steep incline in recovered, or in general removed, individuals; All three curves asymptotically approach a single value. We see that the peak of the number of infected individuals occurs at about the same time where the curves pertaining to the susceptible and recovered populations intersect. This makes sense intuitively: to the right of this peak, the number of removed individuals overtakes the number of susceptible and continues increasing, and so the number of infected individuals decreases as we move forward in time. To the left of the peak, the number of susceptible individuals is higher than those recovered, so there are more people able to become infected and hence the number of infected is increasing, creating this global maximum. \n\nThe amplitude of the curves and their decay times depend on the $\\beta$ and $\\gamma$ values. For constant $\\beta$, across a row in Figure 4, the amplitude of the peak of infection becomes lower, and not all individuals become infected for higher values of $\\gamma$ over the investigated time span, such that the susceptible population curve does not reach zero. Since $\\gamma$ is the inverse of the average time an individual is infected, a higher $\\gamma$ means a fast recovery time, and so for constant infection rate this means the disease will be less aggressive but for a longer period of time. The decay rate of the curves, or their slope trend, remains similar across the figure's rows. For constant $\\gamma$, down the figure columns, we see that the amplitude of the infection curve increases, as well as becomes steeper, i.e a smaller standard deviation. The slopes of the other curves also become much steeper. This is because for a constant recovery rate, an increase in the infection rate means that a disease will spread rapidly, hence the fast spike, and then decay as people recover. \n\n\\subsection{SIRD Model: Figure 5}\nFor this model, we see the same trends as for the SIR Model. The only difference is that we now have a curve for the deceased individuals. It approaches a singular value which is a certain percentage of the population based on the mortality rate $\\mu$ and the other parameters. The deceased curve increases faster for higher infection rates as expected. We also see the recovered line approach a lower value than for the previous model because not all individuals who's cases were resolved resulted in recovery - the disease also has a death rate now. \n\nWe can interpret the two models as either that the SIR Model is working with a disease with a mortality rate $\\mu=0$, and the SIRD model has $\\mu \\neq 0$, or that the SIR Model simply does not differentiate between recovered and deceased individuals. Either way, this explains the changes in amplitude of the recovered population. \n\n\\end{document}", "meta": {"hexsha": "3468c1dbb70dc93df3c41936bfc8ecc9d0ad9bfd", "size": 11960, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_2/Assign2Latex/main.tex", "max_stars_repo_name": "sthiele483/CTA200", "max_stars_repo_head_hexsha": "9567594c01e158175ffc632708a6c684b5da18c2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_2/Assign2Latex/main.tex", "max_issues_repo_name": "sthiele483/CTA200", "max_issues_repo_head_hexsha": "9567594c01e158175ffc632708a6c684b5da18c2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_2/Assign2Latex/main.tex", "max_forks_repo_name": "sthiele483/CTA200", "max_forks_repo_head_hexsha": "9567594c01e158175ffc632708a6c684b5da18c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 102.2222222222, "max_line_length": 1529, "alphanum_fraction": 0.7622909699, "num_tokens": 2989, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.810478913248044, "lm_q2_score": 0.8887587964389112, "lm_q1q2_score": 0.7203202634774483}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\n\\title{MAT257 Notes}\n\\author{Jad Elkhaleq Ghalayini}\n\\date{October 15 2018}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{mathtools}\n\\usepackage{enumitem}\n\\usepackage{graphicx}\n\\usepackage{cancel}\n\n\\usepackage[margin=1in]{geometry}\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{lemma}{Lemma}\n\\newtheorem{definition}{Definition}\n\\newtheorem*{corollary}{Corollary}\n\\newtheorem{exercise}{Exercise}\n\n\\newcommand{\\reals}[0]{\\mathbb{R}}\n\\newcommand{\\nats}[0]{\\mathbb{N}}\n\\newcommand{\\ints}[0]{\\mathbb{Z}}\n\\newcommand{\\rationals}[0]{\\mathbb{Q}}\n\\newcommand{\\brac}[1]{\\left(#1\\right)}\n\\newcommand{\\sbrac}[1]{\\left[#1\\right]}\n\\newcommand{\\mc}[1]{\\mathcal{#1}}\n\\newcommand{\\eval}[3]{\\left.#3\\right|_{#1}^{#2}}\n\\newcommand{\\ip}[2]{\\left\\langle#1,#2\\right\\rangle}\n\\newcommand{\\prt}[2]{\\frac{\\partial #1}{\\partial #2}}\n\n\\begin{document}\n\n\\maketitle\n\n\\section*{Implicit Function Theorem}\n\nAssume we have a function \\(F(x, y) = 0\\). Can we solve for \\(y\\) as a function \\(y = g(x)\\) near a point \\((a, b)\\) such that \\(F(a, b) = 0\\)?\nFor example, assume \\(f(x, y) = x^2 + y^2 - 1\\).\nThis relationship, of course, defines the unit circle. Can we solve for \\(y\\) at a function of \\(x\\) at any point on the unit circle? No: we can't do so where \\(y = 0\\), we can only get \\(x\\) as a function of \\(y\\).\nIf we pick a point \\((a, b) \\in \\reals^2\\) however, and assume \\(a \\neq \\pm 1\\), then there are open intervals \\(I, J\\) such that for every \\(x \\in I\\), there is a unique \\(y = g(x) \\in J\\) such that \\(f(x, y) = 0\\).\n\nLet's restrict our attention to a small enough interval such that \\(b > 0\\). Of course, then, we can explicitly write down what the solution is:\n\\[g(x) = \\sqrt{1 - x^2}\\]\n\nSometimes in this context people say that one of the variables is dependent and the other is independent. Which is which? How should you understand that language? Well, the dependent variable is the one that is determined by the independent one you specify. But that notion, it depends on where you are: at the poles \\(x = \\pm 1\\), we can only solve for \\(x\\), whereas at the poles \\(y \\pm 1\\), we can only solve for \\(y\\).\n\nFurthermore, we may not be able to find a nice formula for \\(g\\). However, by what's known as ``implicit differentiation,'' we can find a formula for the \\textit{derivative of} \\(g\\).\n\n\\section*{Implicit Differentiation}\nLet's assume we have a function\n\\[F(x, g(x)) = 0\\]\nWhether or not we have a formula for \\(g\\), we can use the chain rule to obtain\n\\[\\frac{d}{dx}F(x, g(x)) = \\partial_1(x, g(x)) + \\partial_2(x, g(x))g'(x) = 0\\]\nSo we find that\n\\[g'(x) = -\\frac{\\partial_1(x, g(x))}{\\partial_2(x, g(x))}\\]\nNow this formula depends on \\(g\\). Is this weird or expected? Well, it makes sense. Consider the example above: we might have two solutions (points on the circle) on top of each other for a given \\(x\\)-coordinate. This formula works for \\textit{both} of them.\n\n\\end{document}\n", "meta": {"hexsha": "0c4c41abded3a8feab5e45ad4a5198da30f8bb1d", "size": 2963, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/october15.tex", "max_stars_repo_name": "imbrem/mat257-notes", "max_stars_repo_head_hexsha": "965b1a0e5e5aae44577c5ed58e98623af1f4560d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/october15.tex", "max_issues_repo_name": "imbrem/mat257-notes", "max_issues_repo_head_hexsha": "965b1a0e5e5aae44577c5ed58e98623af1f4560d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/october15.tex", "max_forks_repo_name": "imbrem/mat257-notes", "max_forks_repo_head_hexsha": "965b1a0e5e5aae44577c5ed58e98623af1f4560d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.0317460317, "max_line_length": 423, "alphanum_fraction": 0.6864664192, "num_tokens": 964, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8887587949656841, "lm_q1q2_score": 0.7203202582149385}}
{"text": "\\chapter{Einstein's Field Equations}\nWe will derive Einsteins Equations by physical considerations. Remember that the\nPoisson equation reads \n\\begin{equation}\n\\Delta\\Phi=4\\pi\\varrho\\, .\n\\end{equation}\nSo matter (energy) is the source of the gravitational field $\\Phi$.  From SR we\nknow that the energy momentum tensor $\\tensor{T}{_\\mu_\\nu}$ is an adequate\ngeneralisation of energy.\nWe therefore put $\\tensor{T}{_\\mu_\\nu}$ as the right hand side of a yet to be\nfound equation, and ask for the left hand side. We would like a tensor\n$\\tensor{S}{_\\mu_\\nu}$, related to the geometry, so that we can express\n\\begin{equation}\n\\tensor{S}{_\\mu_\\nu}=\\tensor{T}{_\\mu_\\nu}\n\\,.\n\\end{equation}\nIn SR, the energy momentum tensor $\\tensor{T}{_\\mu_\\nu}$ is conserved i.e.\n$\\tensor{T}{_\\mu_\\nu^{,\\nu}}=0$. As a natural extension, we demand that the\nenergy momentum tensor of general relativity is \\emph{covariantly} conserved\n\\begin{equation}\n\\tensor{\\nabla}{^\\nu}\\tensor{T}{_\\mu_\\nu}=\\tensor{T}{_\\mu_\\nu^{;\\nu}}=0\n\\end{equation}\n\\begin{theorem}[Lovelock]\nFor a four dimensional space\n\\footnotemark{} the most general divergence free tensor $\\tensor{A}{_\\mu_\\nu}$ is\ngiven by\n\\begin{equation}\n\\tensor{A}{_\\mu_\\nu}= c_1\\tensor{G}{_\\mu_\\nu}+c_2\\tensor{g}{_\\mu_\\nu}\\, .\n\\end{equation}\nWhere $\\tensor{G}{_\\mu_\\nu}$ is the \\emph{Einstein tensor}\n$\\tensor{G}{_\\mu_\\nu}:=\\tensor{R}{_\\mu_\\nu}-\\frac{1}{2}\\tensor{g}{_\\mu_\\nu}R$.\n\\end{theorem}\n\\footnotetext{this does certainly not hold true for\n$d>4$}\nThe theorem immediately implies \\emph{Einstein's field equations}\n\\begin{equation}\n\\tensor{R}{_\\mu_\\nu}-\\frac{1}{2}R\\tensor{g}{_\\mu_\\nu}-\\Lambda\\tensor{g}{_\\mu_\\nu}\n=\\kappa\\tensor{T}{_\\mu_\\nu}\\, ,\\label{eq:EinstFG}\n\\end{equation}\nwith some constants $\\kappa$, $\\Lambda$.\nOf course we identify Einsteins constant $\\kappa=\\frac{8\\pi\nG\\textsubscript{N}}{c^2}$ and the cosmological constant $\\Lambda$. As a slight\nvariation, we can rewrite equation \\eqref{eq:EinstFG} as\n\\begin{equation}\n\\tensor{R}{_\\mu_\\nu}-\\frac{1}{2}R\\tensor{g}{_\\mu_\\nu}\n=\\kappa\\left(\\tensor{T}{_\\mu_\\nu}-\\frac{\\Lambda}{\\kappa}\\tensor{g}{_\\mu_\\nu}\\right)\n\\end{equation}\nso that the left hand side represents the geometrical part and the right hand\nside the matter content and we identify $\\Lambda$ with an vacuum energy.\nWheeler condenses this in the statement:\n\\begin{quote}\nGeometry tells matter how to move, matter tells geometry how to\ncurve.\n\\end{quote}\n\\begin{sidenote}\nIn the time of the inflation the cosmological constant must have been large.\nSince it is small today it has do decay with time.\n\\end{sidenote}\nThere is also an variational derivation dating back to Hilbert that is\nsimpler than Einsteins initial derivation. We start by considering a general action\n\\begin{equation}\nS\\textsubscript{g}=\\fourint  \\tilde{\\mathcal{L}}\\, \n\\end{equation}\nwhere $\\tilde{\\mathcal{L}}$ must transform as a (scalar) density. Therefore we\ndefine a scalar $\\mathcal{L}=\\frac{\\tilde{\\mathcal{L}}}{\\sqrt{-g}}$\n\\begin{equation}\nS\\textsubscript{g}=\\fourint \\sqrt{-g}\\mathcal{L}\n\\end{equation}\nOne can think of various contributions to $\\mathcal{L}$, e.g.\n\\begin{equation*}\nR,\\, \\square\nR,\\,\\tensor{\\nabla}{^\\mu}\\tensor{\\nabla}{^\\mu}\\tensor{R}{_\\mu_\\nu},\\,\n\\tensor{R}{_\\mu_\\nu}\\tensor{R}{^\\mu^\\nu}\n,\\,\\tensor{R}{_\\mu_\\nu_\\sigma_\\varrho}\\tensor{R}{^\\mu^\\nu^\\sigma^\\varrho}\\dots\\,,\n\\end{equation*}\nwhich are contractions, so that the resulting quantity becomes a scalar.\nWe have no contributions of the metric alone, because\n$\\tensor{g}{_\\mu_\\nu_{;\\sigma}}=0$. From Yang-Mills theory one would expect a\nstructure\n\\begin{equation}\n\\mathcal{L}\\sim\\tensor{F}{_\\mu_\\nu}\\tensor{F}{^\\mu^\\nu}\\,,\n\\end{equation}\nbut $\\Gamma$ is not the fundamental field but $g$ is. If we demand that we only\nhave up to second derivatives of $g$ the only allowed term in the Lagrangian is\n$R$.\n\\begin{sidenote}[On higher derivatives]\nIf we include higher order derivatives of $g$ in the right way we can make the\nresulting theory renormalizable. However we violate unitarity and introduce\nso-called ghost fields which are associated with the additional degrees of freedom we get.\n\\end{sidenote}\n\\begin{remark}[Dimensions]\nIn natural units\\footnote{So that length has dimension of inverse mass.} the\nline element $\\dif s^2$ has dimension, \\\\${[\\dif\ns^2]=\\textrm{M}^{-2}}$.\\footnote{Where M refers to the dimension of mass.} \nSince further ${\\left[\\tensor{x}{^\\mu}\\right]=\\textrm{M}^{-1}}$,\nthe Lagrange density must have Dimension\n${\\left[\\mathcal{L}\\right]=\\textrm{M}^{4}}$.\n\\end{remark}\nThis constraint leads to the \\emph{Einstein-Hilbert-action}\n\\begin{equation}\nS\\textsubscript{EH}=\\frac{1}{2\\kappa}\\fourint \\sqrt{-g}(R-2\\Lambda)\n\\end{equation}\nWe now check that its variation indeed reproduces Einstein's equations. To do\nso we introduce the formalism of \\emph{functional derivation}. Let therefore\n$\\Phi=\\{\\varphi,\\tensor{A}{^\\mu},\\Psi,\\dots\\}$ be a collection of fields.\n$F[\\Phi]$ a functional.\nWe define the variation of $F$ as\n\\begin{equation}\n\\delta F:=\\int \\dif x\\, \\frac{\\delta F}{\\delta\\Phi^i}\\delta\\Phi^i\\,.\n\\end{equation}\nTypically the functionals are given in the form\n\\begin{equation}\nS[\\Phi]=\\int \\dif x\\, L(x,\\Phi)\\, ,\n\\end{equation}\nwhere $L$ is some local function.\n\\begin{equation}\n\\frac{\\delta\\tensor{g}{_\\varrho_\\sigma}(x)}{\\delta\\tensor{g}{_\\mu_\\nu}(x')}=\\tensor*{\\delta}{*^\\mu*^\\nu*_\\varrho*_\\sigma}\\delta(x,x')\\\n\\end{equation}\nWhere\n$\\tensor*{\\delta}{*^\\mu*^\\nu*_\\varrho*_\\sigma}=\\frac{1}{2}\\left(\\tensor*{\\delta}{^\\nu_\\varrho}\\tensor*{\\delta}{^\\mu_\\sigma}+\\tensor*{\\delta}{^\\mu_\\varrho}\\tensor*{\\delta}{^\\nu_\\sigma}\\right)$\nis the unity of the space of symmetric rank two tensors\n\\begin{remark}\nIn general $\\delta(x,x')\\neq \\delta(x-x')$\n\\end{remark}\nWe transform to the origin of an RNCS, so that the Christoffel symbols vanish.\nIn that coordinate system the covariant and the partial derivative coincide:\n$\\tensor{\\partial}{_\\mu}=\\tensor{\\nabla}{_\\mu}$.\n\\begin{equation}\n\\begin{split}\n\\delta \\tensor{R}{^\\rho_\\mu_\\nu_\\sigma}\n&=\\delta \\tensor{\\partial}{_\\nu}\\cSym{\\rho}{\\mu}{\\sigma}\n-\\delta \\tensor{\\partial}{_\\mu}\\cSym{\\rho}{\\nu}{\\sigma}\\\\\n&=\\tensor{\\partial}{_\\nu}\\delta \\cSym{\\rho}{\\mu}{\\sigma}\n-\\tensor{\\partial}{_\\mu}\\delta \\cSym{\\rho}{\\nu}{\\sigma}\\\\\n\\end{split}\n\\end{equation}\nAttention: i.A. $\\delta\\tensor{\\partial}{_\\mu}\\neq\\tensor{\\partial}{_\\mu}\\delta$\n\\begin{equation}\n\\begin{split}\n\\delta \\tensor{R}{_\\mu_\\nu}\n&=\\delta \\tensor{R}{^\\rho_\\mu_\\rho_\\nu}\\\\\n&=\\tensor{\\partial}{_\\rho}\\delta \\cSym{\\rho}{\\mu}{\\nu}\n-\\tensor{\\partial}{_\\mu}\\delta \\cSym{\\rho}{\\rho}{\\nu}\\\\\n&=\\tensor{\\nabla}{_\\rho}\\delta \\cSym{\\rho}{\\mu}{\\nu}\n-\\tensor{\\nabla}{_\\mu}\\delta \\cSym{\\rho}{\\rho}{\\nu}\\\\\n\\end{split}\n\\end{equation}\nThis holds in a general frame since it is a tensor equation.\n\\begin{equation}\n\\begin{split}\n\\delta R &=\\delta \\left(\\tensor{g}{^\\mu^\\nu}\\tensor{R}{_\\mu_\\nu}\\right)\\\\\n&=\\tensor{R}{_\\mu_\\nu}\\delta\\tensor{g}{^\\mu^\\nu}\n+\\tensor{g}{^\\mu^\\nu}\\delta\\tensor{R}{_\\mu_\\nu}\\\\\n\\end{split}\n\\end{equation}\nUse \\eqref{eq:grels}\n\\begin{equation}\n\\begin{split}\n2\\kappa\\delta S\\textsubscript{EH}\n&=\\fourint \\left[\n(R-2\\Lambda)\\delta\\sqrt{-g}+\\sqrt{-g}\\delta R\\right]\\\\\n&=\\fourint \\left[\n\\frac{1}{2}\\sqrt{-g}\\tensor{g}{^\\mu^\\nu}\\delta\\tensor{g}{_\\mu_\\nu}\n(R-2\\Lambda)+\\sqrt{-g}\\left(\\tensor{R}{_\\mu_\\nu}\\delta\\tensor{g}{^\\mu^\\nu}\n+\\tensor{g}{^\\mu^\\nu}\\delta\\tensor{R}{_\\mu_\\nu}\\right)\\right]\\\\\n&=\\fourint \\sqrt{-g}\\left[\n\\frac{1}{2}\\tensor{g}{^\\mu^\\nu}\n(R-2\\Lambda)+\\tensor{R}{^\\mu^\\nu}\\right]\\delta\\tensor{g}{_\\mu_\\nu}\n+\\fourint \\sqrt{-g}\\tensor{g}{^\\mu^\\nu}\\delta\\tensor{R}{_\\mu_\\nu}\n\\\\\n\\end{split}\n\\end{equation}\nWe treat both occurring terms separately\n\\begin{equation}\n\\begin{split}\n\\fourint \\sqrt{-g}\\tensor{g}{^\\mu^\\nu}\\delta\\tensor{R}{_\\mu_\\nu}\n&=\\fourint \\sqrt{-g}\\tensor{g}{^\\mu^\\nu}\\left(\\tensor{\\nabla}{_\\rho}\\delta\n\\cSym{\\rho}{\\mu}{\\nu} -\\tensor{\\nabla}{_\\mu}\\delta \\cSym{\\rho}{\\rho}{\\nu}\\right)\n\\\\\n&=\\fourint \\tensor{\\nabla}{_\\rho}\\left(\\sqrt{-g}\\tensor{g}{^\\mu^\\nu}\\delta\n\\cSym{\\rho}{\\mu}{\\nu}\\right)\\\\\n&\\phantom{=}-\\int\\dif{}^4 x \\tensor{\\nabla}{_\\mu}\\left(\\sqrt{-g}\\tensor{g}{^\\mu^\\nu}\\delta\n\\cSym{\\rho}{\\rho}{\\nu}\\right)\n\\end{split}\n\\end{equation}\nThe Integrals vanish by \\name{Gauß} law (neglecting surface Terms). We are left\nwith\n\\begin{equation}\n\\begin{split}\n2\\kappa\\delta S\\textsubscript{EH}\n&=\\fourint \\sqrt{-g}\\left[\n\\frac{1}{2}\\tensor{g}{^\\mu^\\nu}\n(R-2\\Lambda)+\\tensor{R}{^\\mu^\\nu}\\right]\\delta\\tensor{g}{_\\mu_\\nu}\n\\end{split}\n\\end{equation}\nSo that we can now finally calculate the variation with respect to the metric\nfield\n\\begin{equation}\n\\frac{\\delta\nS\\textsubscript{EH}[\\tensor{g}{_\\mu_\\nu}(x)]}{\\delta\\tensor{g}{_\\mu_\\nu}(x')}\n=\\sqrt{-g}\\left[\\frac{1}{2}\\tensor{g}{^\\mu^\\nu}\n(R-2\\Lambda)+\\tensor{R}{^\\mu^\\nu}\\right]\n\\end{equation}\nIt vanishes if \n\\begin{equation}\n\\tensor{R}{^\\mu^\\nu}+\\frac{R}{2}\\tensor{g}{^\\mu^\\nu}\n-\\Lambda\\tensor{g}{^\\mu^\\nu}=0\\, .\n\\end{equation}\nso we have finally derived Einsteins field equations from an variational\nprinciple.\n%TODO add some text, to much formulas\n\\section{Introduction of Matter}\nIn the gravitational context we mean be \\emph{matter} any non gravitational\nfields this include scalar fields $\\varphi$, spinor fields $\\Psi$, gauge fields\n$\\tensor{A}{^\\mu}$,\\dots. We collect all of them in a multivariable $\\Phi$.\nA local action can be written as\n\\begin{equation}\nS\\textsubscript{m}[\\Phi,g]=\\fourint  \\sqrt{-g}\nL\\textsubscript{m}\\left(\\Phi,\\tensor{\\nabla}{_\\mu}\\Phi,g\\right)\n\\end{equation}\n$\\tensor{g}{^\\mu^\\nu}$ appears in $L\\textsubscript{m}$ because the derivatives\n$\\tensor{\\nabla}{_\\mu}, \\tensor{\\partial}{_\\mu}$ must be contracted.\nAdditionally it enters via $\\sqrt{-g}$.\n\\begin{example}[Free scalar field]\nThe action of a free scalar field in Minkovski space has the form\n\\begin{equation}\nS\\textsubscript{m}=\\fourint  \\left(-\\frac{1}{2}\\tensor{\\eta}{^\\mu^\\nu}\n\\tensor{\\partial}{_\\mu}\\varphi\\tensor{\\partial}{_\\nu}\\varphi-\\frac{1}{2}m^2\\varphi^2\\right)\\,.\n\\end{equation}\nThe minus sign in front of the partial derivative should come as no surprise\nsince we have $\\tensor{\\eta}{^0^0}=-1\\, \\dot{\\varphi}^2>0$. In a non inertial\nframe we have to make the usual replacements\n\\begin{equation}\n\\tensor{\\eta}{_\\mu_\\nu}\\to \\tensor{g}{_\\mu_\\nu}\\, , \\quad\n\\tensor{\\partial}{_\\mu}\\to\n\\tensor{\\nabla}{_\\mu}\\,, \\quad \\dif{}^4 x \\to \\dif{}^4 x\\, \\sqrt{-g}\\, ,\n\\end{equation}\nwhich is also known as a \\emph{minimal coupling description}. The action for a\nscalar $\\varphi$ in the presence of gravity, \ni.e. a dynamical $\\tensor{g}{_\\mu_\\nu}(x)$, reads as\n\\begin{equation}\nS\\textsubscript{m}=\\fourint\\, \n\\sqrt{-g}\\left(-\\frac{1}{2}\\tensor{g}{^\\mu^\\nu} \\tensor{\\nabla}{_\\mu}\\varphi\\tensor{\\nabla}{_\\nu}\\varphi\n-\\frac{1}{2}m^2\\varphi^2\\right)\\,.\n\\end{equation}\n The combined action of scalar field and\ngravity is given as\n\\begin{equation}\nS[g,\\varphi]=S\\textsubscript{g}[g]+S\\textsubscript{m}[g,\\varphi]\\,.\n\\end{equation}\nThe variation with respect to the field $\\varphi$ is \n\\begin{equation}\n\\begin{split}\n\\frac{\\delta S[g,\\varphi]}{\\delta\n\\varphi\\left(x'\\right)}&=\\frac{\\delta S\\textsubscript{m}[g,\\varphi]}{\\delta\n\\varphi\\left(x'\\right)}\\\\\n&=\\fourint\\sqrt{-g}\\left[-\\tensor{g}{^\\mu^\\nu}\n\\tensor{\\nabla}{_\\mu}\\varphi\\tensor{\\nabla}{_\\nu}\\left(\\frac{\\delta\n\\varphi(x)}{\\delta \\varphi\\left(x'\\right)}\\right)-m^2\\varphi\\frac{\\delta\n\\varphi(x)}{\\delta \\varphi\\left(x'\\right)}\\right]\\,,\n\\end{split}\n\\end{equation}\nwhere we used that the $\\delta$ and $\\tensor{\\nabla}{_\\mu}$ commute. Partial\nintegration yields\n\\begin{equation}\n\\begin{split}\n\\frac{\\delta S\\textsubscript{m}[g,\\varphi]}{\\delta \\varphi\\left(x'\\right)}&=\\fourint \\sqrt{-g}\\left(\\square_{g}-m^2\\right)\\varphi\\delta(x,x')\\\\\n&=\\sqrt{-g}\\left(\\square_{g}-m^2\\right)\\varphi\\, ,\n\\end{split}\n\\end{equation}\nwith $\\square_{g}:=\\tensor{g}{^\\mu^\\nu}\n\\tensor{\\nabla}{_\\mu}\\tensor{\\nabla}{_\\nu} $ the\n\\emph{\\name{Laplace–Beltrami} operator}, a generalisation of the ordinary\nLaplacian to curved space.\nDemanding that the variation with respect to $\\varphi$ vanishes implies the\n\\emph{Klein-Gordon equation}\n\\begin{equation}\n\\left(\\square_g-m^2\\right)\\varphi=0\n\\end{equation}\nWe can also vary the action with respect to the metric\nfield $\\tensor{g}{_\\mu_\\nu}$ resulting in \n\\begin{equation}\n\\frac{\\delta S[g,\\varphi]}{\\delta\n\\tensor{g}{_\\mu_\\nu}\\left(x'\\right)}=\n\\frac{\\delta S\\textsubscript{g}[g]}{\\delta\n\\tensor{g}{_\\mu_\\nu}\\left(x'\\right)}\n+\\frac{\\delta S\\textsubscript{m}[g,\\varphi]}{\\delta\n\\tensor{g}{_\\mu_\\nu}\\left(x'\\right)}\n=\\frac{\\sqrt{-g}}{2\\kappa}\\left(\\tensor{G}{^\\mu^\\nu}+\\Lambda\\tensor{g}{^\\mu^\\nu}\n\\right)+\\frac{\\delta S\\textsubscript{m}[g,\\varphi]}{\\delta\n\\tensor{g}{_\\mu_\\nu}\\left(x'\\right)}\\,.\n\\end{equation}\nTo recover the Einstein equations it is convenient to define the\nenergy-momentum tensor \n\\begin{equation}\n\\tensor{T}{^\\mu^\\nu}:=-\\frac{2}{\\sqrt{-g}}\\frac{\\delta\nS\\textsubscript{m}[g,\\varphi]}{\\delta \\tensor{g}{_\\mu_\\nu}\\left(x'\\right)}\\,.\n\\end{equation}\nWe can now proceed in calculating the quantity we have just introduced for a\nscalar field\n\\begin{equation}\n\\begin{split}\n\\frac{\\delta\nS\\textsubscript{m}[g,\\varphi]}{\\delta \\tensor{g}{_\\mu_\\nu}\\left(x'\\right)}\n&=\\int \\dif{}^4x \\frac{\\delta\\sqrt{-g}}{\\delta\n\\tensor{g}{_\\mu_\\nu}}\\left(-\\frac{1}{2}\\tensor{g}{^\\mu^\\nu}\n\\tensor{\\nabla}{_\\mu}\\varphi\\tensor{\\nabla}{_\\nu}\\varphi-\\frac{1}{2}m^2\\varphi^2\\right)\\\\\n&\\phantom{=}+\n\\sqrt{-g}\\left(-\\frac{1}{2}\\tensor{g}{^\\alpha^\\varrho}\\tensor{g}{^\\beta^\\sigma} \\tensor{\\nabla}{_\\alpha}\\varphi\\tensor{\\nabla}{_\\beta}\\varphi\\frac{\\delta\n\\tensor{g}{_\\varrho_\\sigma}}{\\delta \\tensor{g}{_\\mu_\\nu}}\\right)\\\\\n&=\\frac{1}{2}\\int \\dif{}^4 x\n\\sqrt{-g}\\left(-\\frac{1}{2}\\tensor{g}{^\\mu^\\nu}\\tensor{\\nabla}{_\\varrho}\\varphi\\tensor{\\nabla}{^\\varrho}\\varphi-\\frac{1}{2}\\tensor{g}{^\\mu^\\nu}m^2\\varphi^2\n+\\tensor{\\nabla}{^\\mu}\\varphi\\tensor{\\nabla}{^\\nu}\\varphi\\right)\\delta(x,x')\\\\\n&=\\frac{1}{2}\\sqrt{-g}\\left(-\\frac{1}{2}\\tensor{g}{^\\mu^\\nu}\\tensor{\\nabla}{_\\varrho}\\varphi\\tensor{\\nabla}{^\\varrho}\\varphi-\\frac{1}{2}\\tensor{g}{^\\mu^\\nu}m^2\\varphi^2\n+\\tensor{\\nabla}{^\\mu}\\varphi\\tensor{\\nabla}{^\\nu}\\varphi\\right)\n\\end{split}\n\\end{equation}\nSo that\n\\begin{equation}\n\\tensor{T}{^\\mu^\\nu}(\\varphi)\n=-\\frac{1}{2}\\tensor{g}{^\\mu^\\nu}\\tensor{\\nabla}{_\\varrho}\\varphi\\tensor{\\nabla}{^\\varrho}\\varphi\n+\\tensor{\\nabla}{^\\mu}\\varphi\\tensor{\\nabla}{^\\nu}\\varphi\n-\\frac{1}{2}\\tensor{g}{^\\mu^\\nu}m^2\\varphi^2\n\\end{equation}\nAs we have noticed, the Einstein Tensor is covariantly conserved (contracted\nBianci identities). The Einstein equation then implies that also\n$\\tensor{T}{^\\mu^\\nu_{;\\nu}}=0$ this can be checked for the given Tensor\n\\begin{equation}\n\\begin{split}\n\\tensor{\\nabla}{_\\mu}\\tensor{T}{^\\mu^\\nu}\n&=\\tensor{g}{^\\mu^\\nu}\\tensor{\\nabla}{_\\mu}\\tensor{\\nabla}{_\\varrho}\\varphi\\tensor{\\nabla}{^\\varrho}\\varphi+\\square\\varphi\\tensor{\\nabla}{^\\nu}\\varphi+\\tensor{\\nabla}{^\\mu}\\varphi\\tensor{\\nabla}{_\\mu}\\tensor{\\nabla}{^\\nu}\\varphi\n-\\tensor{g}{^\\mu^\\nu}m^2\\varphi\\tensor{\\nabla}{_\\mu}\\varphi\\\\\n&=\\tensor{\\nabla}{^\\nu}\\varphi\\left(\\square-m^2\\right)\\varphi\\\\\n&=0\n\\end{split}\n\\end{equation}\nWhere the last equality holds because $\\varphi$ satisfies the Klein-Gordon\nequation. \n\\end{example}\nThe Einstein equations are ten quasi linear, i.e. the highest order\nderivative appears only linear, differential equations for the metric field\n$\\tensor{g}{_\\mu_\\nu}$. Strictly speaking the Einstein equations are\n\\emph{nonlinear}.\n% \\begin{sidenote}\n% If you substract the constrains imposed by the Bianci identities you end with\n% two DOFs, which are associated with the polarisation states of the graviton.\n% \\end{sidenote}\nHow do we find a solution to this equations?\n\\begin{enumerate}\n  \\item Prescribe $\\tensor{T}{_\\mu_\\nu}$. This is only possible for high\n  symmetry problems, e.g. the \\name{Schwazschild} solution and the cosmological\n  solutions (\\name{Friedmann}'s equations)\n  \\item Assume $\\tensor{g}{_\\mu_\\nu}$, then compute $\\tensor{T}{_\\mu_\\nu}$ and\n  (try!) to interpret this.\n\\end{enumerate}\n%TODO part about Intrinsic vs extrinsic curvature, image??\n\\subsection{ADM-Decomposition}\n\\begin{figure}[hbtp]\n\\centering\n \\includegraphics{foliation.pdf}\n\\caption{Foliation of spacetime into spatial hypersurfaces $\\Sigma_t$.}\n\\end{figure}\nThe formulation of initial value problems is not as easy as it is in classical\nphysics.\\footnote{In fact, depending on the setting, a well defined formulation\ncan be impossible.} Assume we know either\n\\begin{itemize}\n  \\item $\\tensor{g}{_\\mu_\\nu}$ on $\\Sigma_{t_0}$\n  \\item $\\tensor{g}{_\\mu_\\nu_{;j}}$, $\\tensor{g}{_\\mu_\\nu_{;0}}$ on\n  $\\Sigma_{t_0}$\n\\end{itemize}\nWe then see the spacetime as a\ncollection of spacelike hypersurfaces\nat time $t$ $\\Sigma_t=\\left\\{\\tensor{x}{^0}=t\\right\\}$. For simplicity we\nconsider a vacuum solution to the Einstein equations, i.e. \n\\begin{equation}\n0=G=R-2R\\implies\\tensor{R}{_\\mu_\\nu}=0\\,.\n\\end{equation}\nDivided into the respective parts the field equations are\n\\begin{align}\n0&=\\tensor{R}{_0_0}=-\\frac{1}{2}\\tensor{g}{^i^j}\\tensor{g}{_i_j_{,00}}+\\tensor{M}{_0_0}\\,,\\\\\n0&=\\tensor{R}{_0_i}=-\\frac{1}{2}\\tensor{g}{^0^j}\\tensor{g}{_i_j_{,00}}+\\tensor{M}{_0_i}\\,,\\\\\n0&=\\tensor{R}{_i_j}=-\\frac{1}{2}\\tensor{g}{^0^0}\\tensor{g}{_i_j_{,00}}+\\tensor{M}{_i_j}\\,.\n\\end{align}\nWhere $\\tensor{M}{_\\mu_\\nu}$ is a rest term containing lower order\ntime derivatives.\nThis shows that there are no second order time derivatives of\n$\\tensor{g}{_0_\\mu}$. We have 10 equations and 6 undetermined functions. The\nDOFs can be used for a coordinate transformation, so that\n$\\tensor{g}{_0_\\mu_{,00}}=0$ on $\\Sigma_{t_0}$. This is always possible but we\nwill not proof this. It can be further shown, by means of the contracted Bianci\nidentities, that this implies $\\tensor{g}{_0_\\mu_{,00}}=0$ on \\emph{all}\nhypersurfaces $\\Sigma_{t}$.\n% \\begin{equation}\n% \\tensor{\\partial}{_0}\\tensor{G}{^0^\\nu}=\n% \\tensor{\\partial}{_i}\\tensor{G}{^i^\\nu}\n% -\\cSym{\\nu}{0}{\\lambda}\\tensor{G}{^\\lambda^\\nu}\n% -\\cSym{0}{\\nu}{\\lambda}\\tensor{G}{^\\mu^\\lambda}\\,.\n% \\end{equation}\nSince we have to much freedom the solution will not be unique. We have the\nfreedom to choose four coordinates\n\\begin{equation}\n\\tensor{x}{^{\\mu^\\prime}}=\\tensor{f}{^{\\mu^\\prime}}\\left(\\tensor{x}{^\\mu}\\right)\\,.\n\\end{equation}\nOne typical choice is the \\emph{harmonic\\footnote{A function $f$ is said to be\nharmonic if it satisfies $\\square f = 0$.} gauge}\n\\begin{equation}\n\\square\\tensor{x}{^\\mu}=0\\,.\n\\end{equation}\nWe can expand the d'Alembertian, using \\eqref{eq:quabla}, to\n\\begin{equation}\n\\begin{split}\n\\square\\tensor{x}{^\\mu}&=g^{-\\nicefrac{1}{2}}\\tensor{\\partial}{_\\varrho}\\left(g^{\\nicefrac{1}{2}}\\tensor{g}{^\\varrho^\\sigma}\\tensor{\\partial}{_\\sigma}\\tensor{x}{^\\mu}\\right)\\\\\n&=g^{-\\nicefrac{1}{2}}\\tensor{\\partial}{_\\varrho}\\left(g^{\\nicefrac{1}{2}}\\tensor{g}{^\\varrho^\\sigma}\\tensor{\\delta}{_\\sigma^\\mu}\\right)\\\\\n&=g^{-\\nicefrac{1}{2}}\\tensor{\\partial}{_\\varrho}\\left(g^{\\nicefrac{1}{2}}\\tensor{g}{^\\varrho^\\mu}\\right)\\,,\\\\\n\\end{split}\n\\end{equation}\nthe harmonic gauge is therefore equivalent to\n\\begin{equation}\n\\tensor{\\partial}{_\\varrho}\\left(g^{\\nicefrac{1}{2}}\\tensor{g}{^\\varrho^\\mu}\\right)=0\\,\n.\\\\\n\\end{equation}\nThe equation can be divided into spatial and time components and derive by the\nzero component, so that\n\\begin{equation}\n\\tensor*{\\partial}{*_0^2}\\left(g^{\\nicefrac{1}{2}}\\tensor{g}{^0^\\mu}\\right)\n=\n-\\tensor{\\partial}{_i}\\left[\\tensor{\\partial}{_0}\\left(g^{\\nicefrac{1}{2}}\\tensor{g}{^0^\\mu}\\right)\\right]\\,\n,\\end{equation}\nwhich fixes the second order time derivatives of the relevant components\n$\\tensor{g}{^0^\\mu}$. Therefore now the time evolution can be solved. \n%TODO Missing part?\n\\subsubsection{Degrees of freedom}\n\\begin{itemize}\n  \\item[\\textsf{\\textbf{10}}]\n  componnents for every spacetime point from the symmetric $\\tensor{g}{_\\mu_\\nu}$\n  \\item[\\textsf{\\textbf{-4}}] from the\n  constraint equation $\\tensor{G}{_\\mu_\\nu^{;\\nu}}=0$\n  \\begin{itemize}\n    \\item\n    $\\tensor{G}{^0^0}=\\kappa \\tensor{T}{^0^0}$ ensures that the\n    evolution is independent of the choice of spatial coordinates on\n    $\\Sigma_{t_0}$.\n    \\item\n    $\\tensor{G}{^i^0}=\\kappa \\tensor{T}{^i^0}$ ensures that the time\n    evolution is independent of the way we foliated spacetime into spacial\n    hypersurfaces $\\Sigma_{t}.    $\n  \\end{itemize}\n  \\item[\\textsf{\\textbf{-4}}] due to the freedom\n  to choose coordinates (i.e. a gauge).\n\\end{itemize}\nWe are left with two physical degrees of freedom which may be interpreted as the\npolarisation states of the graviton field.\n\\subsubsection{Comparison with electrodynamics in flat spacetime}\nIn electrodynamics instead of \\name{Einstein}'s equations we have the field\nequations for the four potential $\\tensor{A}{_\\mu}$:\n\\begin{equation}\n\\square\\tensor{A}{_\\mu}-\\partial_\\mu\\left(\\partial_\\nu\\tensor{A}{^\\nu}\n\\right)=0\\,.\n\\end{equation}\nAs we did for the gravitational field, we take a look\nat the zero component. We find\n\\begin{equation}\n\\begin{split} \n0&=-\\partial_0^2\\tensor{A}{_0}+\\partial_i\\partial^i\\tensor{A}{_0}\n-\\partial_0\\left(-\\partial_0\\tensor{A}{_0}+\\partial_iA^i\\right)\\\\\n&= \\partial_i\\partial^i\\tensor{A}{_0}-\\partial_0\\partial_iA^i\n\\end{split}\n\\end{equation}\nThis equation is equivalent to $\\nabla\\vec{E}=0$ and the Bianchi identities.\nSo once again $\\tensor{A}{_0}$ is \\emph{not} determined by the dynamical\nevolution equation because there is no second order time derivative analogous to\n$\\tensor{g}{_0_0}$. Since $\\tensor{A}{_0}$ is not determined and cannot be\nspecified on the initial time slice. This reflects some internal redundancy\nnamely gauge invariance of the theory. For any scalar function $\\Lambda$, the\ntransformation\n\\begin{equation}\n\\tensor{A}{_\\mu}\\to\\tensor*{A}{*_\\mu^\\prime}=\n\\tensor{A}{_\\mu}+\\partial_\\mu\\Lambda\\,,\n\\end{equation}\nleaves the physics invariant. It is trivial to check that\nthe field strength tensor \\\\\n${\\tensor{F}{_\\mu_\\nu}=\\partial_\\mu\\tensor{A}{_\\nu}-\\partial_\\nu\\tensor{A}{_\\mu}}$ stays invariant. Perhaps more\ninteresting the field equation is also gauge invariant:\n\\begin{equation}\n\\begin{split}\n\\square\\tensor*{A}{*_\\mu^\\prime}-\\partial_\\mu\\left(\\partial_\\nu\\tensor*{A}{*^\\nu^\\prime}\n\\right)\n&=\n\\square\\tensor{A}{_\\mu}+\\square\\partial_\\mu\\Lambda-\\partial_\\mu\\left(\\partial_\\nu\\tensor{A}{^\\nu}\n\\right)-\\partial_\\mu\\square\\Lambda\\\\\n&=\n\\square\\tensor{A}{_\\mu}-\\partial_\\mu\\left(\\partial_\\nu\\tensor{A}{^\\nu}\n\\right)\\,.\n\\end{split}\n\\end{equation}\nThus if $\\tensor{A}{_\\mu}$ is a solution to the field\nequation $\\tensor*{A}{*_\\mu^\\prime}$ is and therefore both are physically\nindistinguishable. We can also fix a gauge for example the \\emph{Lorentz gauge}:\n\\begin{equation}\n\\partial_\\mu\\tensor{A}{^\\mu}=0\\, .\n\\end{equation}\nIf we derive this by the zero component we get\n\\begin{equation}\n\\partial_{0}^2\\tensor{A}{^0}=-\\partial_i\\partial_0\\tensor{A}{^i}\\, ,\n\\end{equation}\nso as with $\\tensor{g}{_0_0}$ the evolution of the zero component is now related\nto the other components. There is still one residual gauge condition, namely we can\nstill transform\n\\begin{equation}\n\\tensor{A}{_\\mu}\\to\\tensor*{A}{*_\\mu^\\prime}=\n\\tensor{A}{_\\mu}+\\partial_\\mu\\Lambda\\, ,\n\\end{equation}\nbut to keep the gauge, we have to demand that $\\square\\Lambda=0$.\nAgain we count the DOFs:\n\\begin{itemize}\n  \\item[\\textsf{\\textbf{4}}] components of the potential\n  $\\tensor{A}{_\\mu}$.\n  \\item[\\textsf{\\textbf{-1}}] from constraint\n  $\\nabla\\vec{E}=0$.\n  \\item[\\textsf{\\textbf{-1}}] from gauge freedom\n  $\\Lambda$.\n\\end{itemize}\nThis leaves two physical degrees of freedom, the polarisation states of a\nphoton.\n\n\\begin{remark}\nAs we have have seen there is a direct correspondence between the gauge freedom\nin electrodynamics and the freedom of choice of coordinates of coordinates in\nGR.\n\\end{remark}\n", "meta": {"hexsha": "739aa252f4a18d16db594ea184f60812ec70c313", "size": 23534, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/05-einsteins-field-equations.tex", "max_stars_repo_name": "Bigben37/GeneralRelativity", "max_stars_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-31T13:18:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-31T13:18:57.000Z", "max_issues_repo_path": "src/05-einsteins-field-equations.tex", "max_issues_repo_name": "QuantumDancer/GeneralRelativity", "max_issues_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/05-einsteins-field-equations.tex", "max_forks_repo_name": "QuantumDancer/GeneralRelativity", "max_forks_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.3201506591, "max_line_length": 228, "alphanum_fraction": 0.7016656752, "num_tokens": 8189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7203202518910466}}
{"text": "\n\\subsection{Creating statistics}\n\nWe take a sample from the distribution.\n\n\\(x=(x_1, x_2,...,x_n)\\)\n\nA statistic is a function on this sample.\n\n\\(S=S(x_1, x_2,...,x_n)\\).\n\n", "meta": {"hexsha": "ccec7ae57b7e120e3a12f332691d88fa7df74d96", "size": 173, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/stats/01-01-creating.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/stats/01-01-creating.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/stats/01-01-creating.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.4166666667, "max_line_length": 41, "alphanum_fraction": 0.6589595376, "num_tokens": 56, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797148356994, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.7203151993278074}}
{"text": "\\section{Complex analysis}\\label{sec:complex_analysis}\n\nComplex analysis an extension of \\fullref{sec:real_analysis}, which is concerned with studying functions with values in \\hyperref[def:vector_space_dimension]{finite-dimensional} \\hyperref[def:set_of_complex_numbers]{complex} \\hyperref[def:hilbert_space]{Hilbert spaces} \\( \\BbbC^n \\) rather than Euclidean spaces \\( \\BbbR^n \\). A lot of results are different, however much of \\fullref{sec:real_analysis} is delegated here because it holds in greater generality. For these general results, through the section, \\( \\BbbK \\) will refer to either \\( \\BbbR \\) or \\( \\BbbC \\).\n\nDespite complex analysis being a very rich field, we are mostly concerned with special functions, to which we dedicate the following sections:\n\\begin{itemize}\n  \\item \\Fullref{subsec:power_series}\n  \\item \\Fullref{subsec:trigonometric_functions}\n  \\item \\Fullref{subsec:exponential_function}\n  \\item \\Fullref{subsec:trigonometric_polynomials}\n  \\item \\Fullref{subsec:special_functions}\n\\end{itemize}\n", "meta": {"hexsha": "bcefa0116617e6eaf26a53f0f16984b6ed257b04", "size": 1028, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/complex_analysis.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/complex_analysis.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/complex_analysis.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 79.0769230769, "max_line_length": 570, "alphanum_fraction": 0.7869649805, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7203151811424924}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage{hyperref}\n\n% Set up page size\n\\usepackage[margin=1.5cm, includefoot, footskip=30pt]{geometry}\n\n% Nice way to display code\n\\usepackage{minted}\n\n% Import images\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{multicol}\n\n\\usepackage{tikz}\n\\usetikzlibrary{calc}\n\n\\title{Modelling the effect of vaccinations using differential equations}\n\\author{Vince Knight}\n\\date{}\n\n\n\\begin{document}\n\\maketitle\n\n\n\\section{Introduction}\\label{sec:introduction}\n\n\nThe World Health Organisation estimates that the measles vaccination has saved\nmore than 17 million lives since 2000~\\cite{who}.  It is possible to model the\neffect of vaccination using differential equations. The model considered here is\ncalled an SIR model which is a compartementalised model of infection where\nindividuals can be in one of 3 states:\n\n\\begin{itemize}\n    \\item Susceptible (S): members of the population who may become infected;\n    \\item Infected (I): infected members of the population who will eventually\n        recover;\n    \\item Recovered (R): recovered members of the population, not that\n        mathematically death is here equivalent to recovery.\n\\end{itemize}\n\nFigure~\\ref{fig:sir_model} shows this diagrammatically.\n\n\\begin{figure}[!hbtp]\n    \\begin{center}\n        \\begin{tikzpicture}\n            \\node [draw, fill=blue!20] (S) at (0, 0) {S};\n            \\node [draw, fill=red!20] (I) at ($(S) + (2, 0)$) {I};\n            \\node [draw, fill=green!20] (R) at ($(I) + (2, 0)$) {R};\n\n            \\draw [->] (S) edge [out=45, in=135] node [above] {\\(\\alpha\\)} (I);\n            \\draw [->] (I) edge [out=45, in=135] node [above] {\\(\\beta\\)} (R);\n            \\draw [->] (S) edge [out=-45, in=-135] node [above] {\\(\\mu\\)} (R);\n        \\end{tikzpicture}\n    \\end{center}\n    \\caption{The SIR model}\n    \\label{fig:sir_model}\n\\end{figure}\n\nThe parameters of the model shown in Figure~\\ref{fig:sir_model} are:\n\n\\begin{itemize}\n    \\item \\(\\alpha\\) the infection rate;\n    \\item \\(\\beta\\) the recovery rate;\n    \\item \\(\\mu\\) the vaccination percentage;\n\\end{itemize}\n\nThis can be expressed mathematically:\n\n\\begin{align}\n    \\frac{dS}{dt} &= - \\alpha I S - \\mu S\\\\\n    \\frac{dI}{dt} &=  \\alpha I S - \\beta I\\\\\n    \\frac{dR}{dt} &=  \\mu S + \\beta I\n\\end{align}\n\nIn the next section we will use Sympy to attempt to solve these equations\nanalytically:\n\n\\section{(Not) finding an exact solution}\n\nIt is possible to use Sympy to solve systems of differential equations, however\nwhen attempting to do this here it appears to fail:\n\n\\begin{minted}{python}\n>>> import sympy as sym\n>>> S, I, R = sym.Function(\"S\"), sym.Function(\"I\"), sym.Function(\"V\")\n>>> N, mu, alpha, beta, t = sym.symbols(\"N, mu, alpha, beta, t\")\n>>> eq1 = sym.Derivative(S(t), t) - (- alpha * S(t) * I(t) - mu * R(t))\n>>> eq2 = sym.Derivative(I(t), t) - (alpha * I(t) * S(t) / N  - beta * I(t))\n>>> eq3 = sym.Derivative(R(t), t) - (beta * I(t) + mu * R(t))\n>>> sym.dsolve((eq1, eq2, eq3))\nNotImplementedError                       Traceback (most recent call last)\n...\n\\end{minted}\n\nI believe that this is due to the complexity of the differential equations that\nSympy is unable to handle analytically. An exact solution of the model without\nvaccination is obtained in~\\cite{harko2014exact}.\nIn the next section we will however solve these equations numerically.\n\n\\section{Solving the equations numerically and the effect of vaccination rates}\n\nWe can use a numerical integration technique to solve these equations\nnumerically. The technical publication describing the specific algorithm used is\ndescribed in~\\cite{radhakrishnan1993description}.\n\nFirst we create a function that gives expressions for the\nderivatives at any given point in time:\n\n\\begin{minted}{python}\n>>> def dx(x, t, alpha, beta, mu):\n...     return (- alpha * x[1] * x[0] - mu * x[0],\n...             alpha * x[1] * x[0]  - beta * x[1],\n...             beta * x[1] + mu * x[0])\n\\end{minted}\n\nWe can then plot a number of different scenarios as shown in\nFigure~\\ref{fig:scenarios}. Here is the code that corresponds to the first plot:\n\n\\begin{minted}{python}\n>>> alpha = 1 / 1000  # Every 1000 interactions leads to infection\n>>> beta = 1 / 5  # take 5 time units to recover\n>>> N = 10 ** 4  # Population of 10 thousand people\n>>> mu = 0  # 0 vaccination rate\n>>> ts = np.linspace(0, 10, 5000)\n>>> xs = integrate.odeint(func=dx, y0=np.array([N - 1, 1, 0]), t=ts, args=(alpha, beta, mu))\n>>> S, I, R = xs.T\n>>> plt.figure()\n>>> plt.plot(ts, S, label=\"Susceptibles\")\n>>> plt.plot(ts, I, label=\"Infected\")\n>>> plt.plot(ts, R, label=\"Recovered\")\n>>> plt.legend()\n>>> plt.title(f\"$\\max(I)={round(max(I))}$ ($\\\\alpha={alpha}$, $\\\\beta={beta}$,\n$\\mu={mu}$)\");\n\\end{minted}\n\n\\begin{figure}[!hbtp]\n    \\begin{center}\n        \\includegraphics[width=.3\\textwidth]{base_scenario.pdf}\n        ~\n        \\includegraphics[width=.3\\textwidth]{moderate_vaccination_rate.pdf}\n        ~\n        \\includegraphics[width=.3\\textwidth]{high_vaccination_rate.pdf}\n        \\caption{The evolution of the population for different vaccination rates}\n        \\label{fig:scenarios}\n    \\end{center}\n\\end{figure}\n\nIt is also possible to compute the maximum percentage of infection as a function\nof the vaccination rate:\n\n\\begin{minted}{python}\n>>> vaccination_rates = np.linspace(0, 1, 500)\n>>> max_percent_of_infected = []\n>>> for mu in vaccination_rates:\n...     xs = integrate.odeint(func=dx, y0=np.array([N - 1, 1, 0]), t=ts, args=(alpha, beta, mu))\n>>> S, I, R = xs.T\n>>> max_percent_of_infected.append(max(I) / N)\n>>> plt.figure()\n>>> plt.plot(vaccination_rates, max_percent_of_infected)\n>>> plt.xlabel(\"Vaccination rate\")\n>>> plt.ylabel(\"% of population infected\");\n\\end{minted}\n\nThis is shown in Figure~\\ref{fig:effect_of_vaccination_rate}.\n\n\\begin{figure}[!hbtp]\n    \\begin{center}\n        \\includegraphics[width=.6\\textwidth]{effect_of_vaccination_rate.pdf}\n        \\caption{The effect of vaccination rate on maximum infection percentage}\n        \\label{fig:effect_of_vaccination_rate}\n    \\end{center}\n\\end{figure}\n\n\\section{Conclusion}\n\nWe see in our model that a large vaccination rate is required to ensure a high\nlevel of immunity (ie a low maximum level of total infection). This type of\napproach uses differential equations to model the interactions of individuals\nand the spread of disease, finally we solve these equations using techniques\nfrom numerical analysis.\n\n\\bibliographystyle{plain}\n\\bibliography{bibliography.bib}\n\n\n\\end{document}\n", "meta": {"hexsha": "22d21214baed97c6d8e62a7726c74ef462119068", "size": 6477, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/rsc/sir/main.tex", "max_stars_repo_name": "geraintpalmer/cfm", "max_stars_repo_head_hexsha": "fa3f98cf45b225015f28be461e8ae661fa966b61", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assets/rsc/sir/main.tex", "max_issues_repo_name": "geraintpalmer/cfm", "max_issues_repo_head_hexsha": "fa3f98cf45b225015f28be461e8ae661fa966b61", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assets/rsc/sir/main.tex", "max_forks_repo_name": "geraintpalmer/cfm", "max_forks_repo_head_hexsha": "fa3f98cf45b225015f28be461e8ae661fa966b61", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.9109947644, "max_line_length": 96, "alphanum_fraction": 0.6776285317, "num_tokens": 1885, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.9111796997610798, "lm_q1q2_score": 0.7203151694240663}}
{"text": "% !TEX program = pdflatex\n\n\\documentclass[11pt]{article}\n\\usepackage{amsmath,amsfonts,amsthm,amssymb,geometry,dsfont}\n\\usepackage[usenames,dvipsnames,svgnamesable]{xcolor}\n\\usepackage[capitalise,noabbrev]{cleveref} %\n\\usepackage[round]{natbib}\n\\usepackage{natbib}\n\\crefname{equation}{}{} %\n\\crefname{assumption}{Assumption}{Assumptions}\n\\crefname{property}{Property}{Properties}\n\\geometry{left=1in,right=1in,top=0.6in,bottom=1in}\n\n\\newcommand{\\D}[1][]{\\ensuremath{\\boldsymbol{\\partial}_{#1}}}\n\\newcommand{\\R}{\\ensuremath{\\mathbb{R}}}\n\\newcommand{\\diff}{\\ensuremath{\\mathrm{d}}}\n\\newcommand{\\set}[1]{\\ensuremath{\\left\\{{#1}\\right\\}}}\n\\newcommand{\\indicator}[1]{\\ensuremath{\\mathds{1}\\left\\{{#1}\\right\\}}}\n\\newcommand{\\condexpec}[3][]{\\ensuremath{\\mathbb{E}_{#1}\\left[{#2} \\; \\middle| \\; {#3} \\right]}}\n\\newcommand{\\expec}[2][]{\\ensuremath{\\mathbb{E}_{{#1}}\\left[ {#2} \\right]}}\n\\geometry{left=1in,right=1in,top=0.6in,bottom=1in}\n\\newenvironment{psmallmatrix}\n{\\left(\\begin{smallmatrix}}\n\t{\\end{smallmatrix}\\right)}\n\n\\begin{document}\n\\title{Derivation on discretized differential operators on (ir)regular grids with reflecting barrier conditions}\n\\author{@chiyahn}\n\\maketitle\n\n\n\\section{Setup}\n\n\\begin{itemize}\n\t\\item Define an irregular grid $\\set{z_i}_{i=1}^P$ with $z_1 = \\underline{z}$ and $z_P = \\bar{z}$. Denote the grid with the variable name, i.e. $z \\equiv \\set{z_i}_{i=1}^P$.\n\t\\item Denote the distance between the grid points as the \\textit{backwards} difference\n\t\\begin{align}\n\t\\Delta_{i,-} &\\equiv z_i - z_{i-1},\\, \\text{for } i = 2,\\ldots, P\\\\\n\t\\Delta_{i,+} &\\equiv z_{i+1} - z_i,\\, \\text{for } i = 1,\\ldots, P-1\n\t\\end{align}\n\t\n\t\\item Assume $\\Delta_{1, -} = \\Delta_{1, +}$ and $\\Delta_{P, +} = \\Delta_{P, -}$, due to ghost points, $z_0$ and $z_{P+1}$ on both boundaries. (i.e.he distance to the ghost nodes are the same as the distance to the closest nodes).  Then define the vector of backwards and forwards first differences as\n\t\\begin{align}\n\t\\Delta_{-} &\\equiv \\begin{bmatrix} z_2 - z_1 \\\\\n\t\\text{diff}(z)\n\t\\end{bmatrix}\\\\\n\t\\Delta_{+} &\\equiv \\begin{bmatrix} \\text{diff}(z)\\\\\n\tz_P - z_{P-1}\n\t\\end{bmatrix}\n\t\\end{align}\n\t\\item Reflecting barrier conditions:\n\t\\begin{align}\n\t\\xi v(\\underline{z}) + \\D[z]v(\\underline{z} ) &= 0\\label{eq:new-BC1}\\\\\n\t\\xi v(\\bar{z}) + \\D[z]v(\\bar{z}) &= 0\\label{eq:new-BC2}\n\t\\end{align}\n\\end{itemize}\n\nLet $L_1^{-}$ be the discretized backwards first differences and $L_2$ be the discretized central differences subject to the Neumann boundary conditions in \\cref{eq:new-BC1,eq:new-BC2} such that $L_1^{-} v(z)$ and $L_2 v(z)$ represent the first and second derivatives of $v(z)$ respectively at $z$. For second derivatives, we use the following numerical scheme from \\cite{achdou17}:\n\n\\begin{equation}\nv''(z_i) \\approx \\dfrac{ \\Delta_{i,-} v( z_i + \\Delta_{i,+}) - (\\Delta_{i,+} + \\Delta_{i,-}) v( z_i ) + \\Delta_{i,+} v( z_i - \\Delta_{i,-})}{\\frac{1}{2}(\\Delta_{i,+} + \\Delta_{i,-}) \\Delta_{i,+} \\Delta_{i,-} }, \\text{for } i = 1, \\ldots, P\n\\end{equation}\n\n\n\n\n\n\\subsection{Regular grids}\nSuppose that the grids are regular, i.e., elements of $\\text{diff}(z)$ are all identical with $\\Delta$ for some $\\Delta > 0$.\n\nUsing the backwards first-order difference, \\eqref{eq:new-BC1} implies\n\\begin{align}\n\\dfrac{v(\\underline{z}) - v(\\underline{z}-\\Delta)}{\\Delta} &= - \\xi v(\\underline{z})\n\\end{align}\nat the lower bound.\n\nLikewise, \\eqref{eq:new-BC2} under the forwards first-order difference yields\n\\begin{align}\n\\dfrac{v(\\overline{z} + \\Delta) - v(\\overline{z})}{\\Delta} &= - \\xi v(\\overline{z})\n\\end{align}\nat the upper bound.\n\nThe discretized central difference of second order under \\eqref{eq:new-BC1} at the lower bound is\n\\begin{align}\n\\dfrac{v (\\underline{z} + \\Delta) - 2 v(\\underline{z}) + v(\\underline{z}-\\Delta)}{\\Delta^2} &=   \\dfrac{v(\\underline{z} + \\Delta) - v(\\underline{z})}{\\Delta^2} - \\dfrac{1}{\\Delta}\\dfrac{v (\\underline{z}) - v(\\underline{z}-\\Delta) }{\\Delta}  \\\\\n&= \\dfrac{v(\\underline{z} + \\Delta) - v(\\underline{z})}{\\Delta^2} + \\dfrac{1}{\\Delta} \\xi v(\\underline{z})  \\\\ \n&= \\dfrac{1}{\\Delta^2}  (- 1 + \\Delta \\xi) v(\\underline{z})  + \\dfrac{1}{\\Delta^2}  v(\\underline{z} + \\Delta)  \n\\end{align}\nSimilarly, by \\eqref{eq:new-BC2}, we have\n\\begin{align}\n\\dfrac{v (\\bar{z} + \\Delta) - 2 v(\\bar{z} ) + v(\\bar{z} -\\Delta)}{\\Delta^2} &=   \\dfrac{v(\\bar{z} - \\Delta) - v(\\bar{z})}{\\Delta^2} + \\dfrac{1}{\\Delta}\\dfrac{ v(\\bar{z}+\\Delta) - v (\\bar{z}) }{\\Delta}  \\\\\n&= \\dfrac{v(\\bar{z} - \\Delta) - v(\\bar{z})}{\\Delta^2}  - \\dfrac{1}{\\Delta} \\xi v(\\bar{z})  \\\\ \n&= \\dfrac{1}{\\Delta^2}  (- 1 - \\Delta \\xi) v(\\bar{z})  + \\dfrac{1}{\\Delta^2}  v(\\bar{z} - \\Delta)  \n\\end{align}\nat the upper bound.\n\nThus, the corresponding discretized differential operator $L_1^{-}$, $L_1^{+}$, and $L_2$ are defined as \n\n\\begin{align}\nL_1^{-} &\\equiv \\frac{1}{\\Delta}\\begin{pmatrix}\n1 - (1 + \\xi \\Delta) &0&0&\\dots&0&0&0\\\\\n-1&1&0&\\dots&0&0&0\\\\\n\\vdots&\\vdots&\\vdots&\\ddots&\\vdots&\\vdots&\\vdots\\\\\n0&0&0&\\dots&-1&1&0\\\\\n0&0&0&\\cdots&0&-1&1\n\\end{pmatrix}_{P\\times P}\\label{eq:L-1-regular} \\\\\nL_1^{+} &\\equiv \\frac{1}{\\Delta}\\begin{pmatrix}\n-1&1&0&\\dots&0&0&0\\\\\n0&-1&1&\\dots&0&0&0\\\\\n\\vdots&\\vdots&\\vdots&\\ddots&\\vdots&\\vdots&\\vdots\\\\\n0&0&0&\\dots&0&-1&1\\\\\n0&0&0&\\cdots&0&0&-1+(1-\\xi \\Delta)\n\\end{pmatrix}_{P\\times P}\\label{eq:L-1-plus-regular} \\\\\nL_2 &\\equiv \\frac{1}{\\Delta^2}\\begin{pmatrix}\n-2 + (1 + \\xi\\Delta) &1&0&\\dots&0&0&0\\\\\n1&-2&1&\\dots&0&0&0\\\\\n\\vdots&\\vdots&\\vdots&\\ddots&\\vdots&\\vdots&\\vdots\\\\\n0&0&0&\\dots&1&-2&1\\\\\n0&0&0&\\cdots&0&1&-2 + (1- \\xi\\Delta)\n\\end{pmatrix}_{P\\times P}\\label{eq:L-2-regular}\n\\end{align}\n\n\\subsection{Irregular grids}\nUsing the backwards first-order difference, \\eqref{eq:new-BC1} implies\n\\begin{align}\n\\dfrac{v(\\underline{z}) - v(\\underline{z}-\\Delta_{1, -})}{\\Delta_{1, -}} &= - \\xi v(\\underline{z})\n\\end{align}\n\nat the lower bound. Likewise, the forwards first-order difference under \\eqref{eq:new-BC2} yields\n\\begin{align}\n\\dfrac{v(\\overline{z} + \\Delta_{P, +}) - v( \\overline{z})}{\\Delta_{P, +}} &= - \\xi v(\\overline{z})\n\\end{align}\nat the upper bound.\n\nNote that we have assumed that $\\Delta_{1,-} = \\Delta_{1,+}$ and $\\Delta_{P,+} = \\Delta_{P,-}$ for the ghost notes. The discretized central difference of second order scheme at the lower bound under \\eqref{eq:new-BC1} is \n\\begin{align}\n&\\dfrac{\\Delta_{1,-} v( \\underline{z} + \\Delta_{1,+}) - (\\Delta_{1,+} + \\Delta_{1,-}) v(\\underline{z}) + \\Delta_{1,+}  v( \\underline{z} - \\Delta_{1,-})}{\\frac{1}{2}(\\Delta_{1,+} + \\Delta_{1,-}) \\Delta_{1,+} \\Delta_{1,-} } \\\\\n&=\n\\dfrac{v (\\Delta_{1, +}) - 2 v(\\underline{z}) + v(-\\Delta_{1, +})}{\\Delta_{1, +}^2} \\\\ \n&= \\dfrac{v(\\underline{z} + \\Delta_{1, +}) - v(\\underline{z})}{\\Delta_{1, +}^2} - \\dfrac{1}{\\Delta_{1, +}}\\dfrac{v(\\underline{z}) - v(\\underline{z}-\\Delta_{1, +}) }{\\Delta_{1, +}}  \\\\\n&= \\dfrac{v(\\underline{z} + \\Delta_{1, +}) - v(\\underline{z})}{\\Delta_{1, +}^2} + \\dfrac{1}{\\Delta_{i,+}} \\xi v(\\underline{z})  \\\\ \n&= \\dfrac{1}{\\Delta_{1, +}^2}  (- 1 + \\Delta_{1, +} \\xi) v(\\underline{z})  + \\dfrac{1}{\\Delta_{1, +}^2}  v(\\underline{z} + \\Delta_{1, +})  \n\\end{align}\nSimilarly, by \\eqref{eq:new-BC2}, we have\n\\begin{align}\n&\\dfrac{\\Delta_{P,-} v( \\bar{z} + \\Delta_{P,+}) - (\\Delta_{P,+} + \\Delta_{P,-}) v(\\bar{z} ) + \\Delta_{P,+}  v( \\bar{z} - \\Delta_{P,-})}{\\frac{1}{2}(\\Delta_{P,+} + \\Delta_{P,-}) \\Delta_{P,+} \\Delta_{P,-} } \\\\\n&=\\dfrac{v (\\bar{z} + \\Delta_{P,-}) - 2 v(\\bar{z} ) + v(\\bar{z} -\\Delta_{P,-})}{\\Delta_{P,-}^2} \\\\\n&=   \\dfrac{v(\\bar{z} - \\Delta_{P,-}) - v(\\bar{z})}{\\Delta_{P,-}^2} + \\dfrac{1}{\\Delta_{P,-}}\\dfrac{ v(\\bar{z}+\\Delta_{P,-}) - v (\\bar{z}) }{\\Delta_{P,-}}  \\\\\n&= \\dfrac{v(\\bar{z} - \\Delta_{P,-}) - v(\\bar{z})}{\\Delta_{P,-}^2}  - \\dfrac{1}{\\Delta_{P,-}} \\xi v(\\bar{z})  \\\\ \n&= \\dfrac{1}{\\Delta_{P,-}^2}  (- 1 - \\Delta_{P,-} \\xi) v(\\bar{z})  + \\dfrac{1}{\\Delta_{P,-}^2}  v(\\bar{z} - \\Delta_{P,-})  \n\\end{align}\nat the upper bound.\n\nThus, the corresponding discretized differential operator $L_1^{-}$, $L_1^{+}$, and $L_2$ are defined as \n\n\\begin{align}\nL_1^{-} &\\equiv \\begin{pmatrix}\n\\Delta^{-1}_{1,-} [1 - (1 + \\xi \\Delta_{1,-})] &0&0&\\dots&0&0&0\\\\\n-\\Delta_{2,-}^{-1}&\\Delta_{2,-}^{-1}&0&\\dots&0&0&0\\\\\n\\vdots&\\vdots&\\vdots&\\ddots&\\vdots&\\vdots&\\vdots\\\\\n0&0&0&\\dots&-\\Delta_{P-1,-}^{-1}&\\Delta_{P-1,-}^{-1}&0\\\\\n0&0&0&\\cdots&0&-\\Delta_{P,-}^{-1}&\\Delta_{P,-}^{-1}\n\\end{pmatrix}_{P\\times P}\\label{eq:L-1} \\\\\nL_1^{-} &\\equiv \\begin{pmatrix}\n-\\Delta_{1,+}^{-1}&\\Delta_{1,+}^{-1}&0&\\dots&0&0&0\\\\\n0&-\\Delta_{2,+}^{-1}&\\Delta_{2,+}^{-1}&\\dots&0&0&0\\\\\n\\vdots&\\vdots&\\vdots&\\ddots&\\vdots&\\vdots&\\vdots\\\\\n0&0&0&\\cdots&0&-\\Delta_{P-1,+}^{-1}&\\Delta_{P-1,+}^{-1}\\\\\n0&0&0&\\dots&0&0&\\Delta_{P,+}^{-1}  [-1 + (1 - \\xi \\Delta_{P,+})]  \\\\\n\\end{pmatrix}_{P\\times P}\\label{eq:L-1-plus} \\\\\nL_2 &\\equiv \\begin{psmallmatrix}\n\\Delta_{1,+}^{-2}[-2 + (1+\\xi \\Delta_{1,+})] &\\Delta_{1,+}^{-2}&0&\\cdots&0&0&0 \\\\\n\\vdots&\\ddots&\\ddots&\\ddots&\\ddots&\\vdots&\\vdots\\\\\n0&\\cdots&2(\\Delta_{i,+}+\\Delta_{i,-})^{-1} \\Delta_{i,-}^{-1} &-2\\Delta_{i,-}^{-1} \\Delta_{i,+}^{-1}  & 2 (\\Delta_{i,+}+\\Delta_{i,-})^{-1} \\Delta_{i,+}^{-1}&\\cdots&0 \\\\\n\\vdots&\\vdots&\\vdots&\\ddots&\\ddots&\\ddots&\\vdots\\\\\n0&0&0&\\cdots&0&\\Delta_{P,-}^{-2}&\\Delta_{P,-}^{-2} [-2 + (1- \\xi\\Delta_{P,-})]\n\\end{psmallmatrix}_{P\\times P}\\label{eq:L-2}\n\\end{align}\n\n\\subsection{Differential operators by basis}\nDefine the following basis matrices:\n\n\\begin{align}\nU_1^{-} &\\equiv \\begin{pmatrix}\n1  &0&0&\\dots&0&0&0\\\\\n-1&1&0&\\dots&0&0&0\\\\\n\\vdots&\\vdots&\\vdots&\\ddots&\\vdots&\\vdots&\\vdots\\\\\n0&0&0&\\dots&-1&1&0\\\\\n0&0&0&\\cdots&0&-1&1\n\\end{pmatrix}_{P\\times P}\\label{eq:L-1-basis} \\\\\nU_1^{+} &\\equiv \\begin{pmatrix}\n-1  &1&0&\\dots&0&0&0\\\\\n0&-1&1&\\dots&0&0&0\\\\\n\\vdots&\\vdots&\\vdots&\\ddots&\\vdots&\\vdots&\\vdots\\\\\n0&0&0&\\dots&0&-1&1\\\\\n0&0&0&\\cdots&0&0&-1\n\\end{pmatrix}_{P\\times P}\\label{eq:L-1+-basis} \\\\\n\\end{align}\n\nand the boundary conditions for the reflecting conditions:\n\n\\begin{align}\nB_{1}  &\\equiv \\begin{pmatrix}\n(1 + \\xi \\Delta^{-1}_{1,-}) &0&\\dots&0&0\\\\\n0&0&\\dots&0&0\\\\\n\\vdots&\\vdots&\\ddots&\\vdots&\\vdots\\\\\n0&0&\\cdots&0&0\\\\\n0&0&\\cdots&0&0\n\\end{pmatrix}_{P\\times P} \\\\\nB_{P}  &\\equiv \\begin{pmatrix}\n0 &0&\\dots&0&0\\\\\n0&0&\\dots&0&0\\\\\n\\vdots&\\vdots&\\ddots&\\vdots&\\vdots\\\\\n0&0&\\cdots&0&0\\\\\n0&0&\\cdots&0&(1 - \\xi \\Delta^{-1}_{P,+})\n\\end{pmatrix}_{P\\times P}\n\\end{align}\n\n\\subsubsection{Regular grids}\nFor regular grids with the uniform distance of $\\Delta > 0$, \\eqref{eq:L-1-regular} and \\eqref{eq:L-2-regular} can be represented by\n\n\\begin{align}\nL_1^{-} &= \\dfrac{1}{\\Delta} U_1^{-} - B_1 \\\\\nL_1^{+} &= \\dfrac{1}{\\Delta} U_1^{+} + B_P \\\\\nL_2 &= \\dfrac{1}{\\Delta^2} (U_1^+ - U_1^-) + B_1 + B_P\n\\end{align}\n\n\\subsubsection{Irregular grids}\nFor notational brevity, for vectors with the same size, $x_1, x_2$, define $x_1 x_2$ as the elementwise-multiplied vector. Then, we have\n\\begin{align}\nL_1^{-} &= \\text{diag}(\\Delta_{-} )^{-1} U_1^{-} - B_1 \\\\\nL_1^{+} &= \\text{diag}(\\Delta_{+} )^{-1} U_1^{+} + B_P \\\\\nL_2 &= \\text{diag} \\left[ \\frac{1}{2} ( \\Delta_+ + \\Delta_- ) \\Delta_+ \\right]^{-1}  U_1^{+} - \n \\text{diag} \\left[ \\frac{1}{2} ( \\Delta_+ + \\Delta_- ) \\Delta_- \\right]^{-1}  U_1^{-} \n+ B_1 + B_P \n\\end{align}\nWe can simplify this expression further by introducing a new notation. Let $x^{-1}$ be defined as the elementwise inverse of a vector $x$ that contains no zero element. Then, $L_2$ can be represented as\n\\begin{align}\nL_2 &=\n2\\left[ \\text{diag} \\left( ( \\Delta_+ + \\Delta_- )^{-1} \\Delta_+^{-1} \\right) U_1^{+} - \n\\text{diag} \\left( ( \\Delta_+ + \\Delta_- )^{-1} \\Delta_-^{-1} \\right) U_1^{-}  \\right]\n+ B_1 + B_P \\\\ \\label{eq:L-2-by-basis}\n&= 2 \\text{diag} \\left( ( \\Delta_+ + \\Delta_- )^{-1} \\right) \\left[ \\text{diag} \\left(  \\Delta_+^{-1} \\right) U_1^{+} - \n\\text{diag} \\left(  \\Delta_-^{-1} \\right) U_1^{-}  \\right]\n+ B_1 + B_P\n\\end{align}\n\n\nThe diagonal elements of \\eqref{eq:L-2-by-basis} are also identical with the one provided in \\eqref{eq:L-2} -- to see this, note that the diagonal elements of \\eqref{eq:L-2-by-basis}, modulo $B_1$ and $B_P$, are\n\\begin{align}\n-2 \\left[ (\\Delta_+ + \\Delta_-)^{-1} \\Delta_+^{-1} + (\\Delta_+ + \\Delta_-)^{-1} \\Delta_-^{-1} \\right] &= -2 (\\Delta_+ + \\Delta_-)^{-1}  ( \\Delta_+^{-1} + \\Delta_-^{-1} ) \\\\\n&= -2(\\Delta_+ + \\Delta_-)^{-1} (\\Delta_+^{-1} \\Delta_-^{-1}) (\\Delta_+ + \\Delta_- )  \\\\\n&= -2 (\\Delta_+^{-1} \\Delta_-^{-1})\n\\end{align}\nwhich is identical with $\\text{diag} (L_2)$ with $L_2$ from \\eqref{eq:L-2} except the first row and last row that are affected by $B_1$ and $B_P$.\n\n\\bibliographystyle{mnras}\n\\bibliography{hact}\n\\end{document}\n", "meta": {"hexsha": "7e84305c526031e969d5fea5064b89d0d3648225", "size": 12440, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "continuous_time_methods/notes/discretized-differential-operator-derivation.tex", "max_stars_repo_name": "ajozefiak/computing_and_datascience", "max_stars_repo_head_hexsha": "ecc5a369adc5784e85614f3f74ae25ca1aede1f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-07-27T00:56:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-15T00:20:26.000Z", "max_issues_repo_path": "continuous_time_methods/notes/discretized-differential-operator-derivation.tex", "max_issues_repo_name": "ajozefiak/computing_and_datascience", "max_issues_repo_head_hexsha": "ecc5a369adc5784e85614f3f74ae25ca1aede1f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 96, "max_issues_repo_issues_event_min_datetime": "2017-12-22T18:26:34.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-13T22:53:47.000Z", "max_forks_repo_path": "continuous_time_methods/notes/discretized-differential-operator-derivation.tex", "max_forks_repo_name": "ajozefiak/computing_and_datascience", "max_forks_repo_head_hexsha": "ecc5a369adc5784e85614f3f74ae25ca1aede1f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-01-05T19:05:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-19T17:01:09.000Z", "avg_line_length": 47.8461538462, "max_line_length": 382, "alphanum_fraction": 0.6081189711, "num_tokens": 5403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7202970236928408}}
{"text": "\\section{Metric Spaces: Examples and Definitions}\n\nA \\emph{metric space} is a set equipped with a notion of distance between points. Such\nspaces arise in many contexts. We begin by considering a few examples.\n\n\\vspace{0.2in}\n\\noindent Examples:\n\n\\begin{enumerate}\n\\item\n\\item\n\\end{enumerate}\n\n\\begin{defn}\n\nLet X be a non-empty set and $x, y \\in X$ . Let $d: X\\times X \\rightarrow \\mathbb{R}$\nsuch that it satisfies\n\n\\begin{enumerate}\n    \\item Positivity:\n    \\begin{enumerate}\n        \\item $d(x,y) \\geq 0$\n        \\item $d(x,x) = 0$\n        \\item $d(x,y) = 0 \\ \\Rightarrow\\ x = y$\n    \\end{enumerate}\n    \\item Symmetry:  $d(x,y) = d(y, x)$\n    \\item Triangle Inequality: $d(x,y)+d(y,z) \\geq d(x,z)$\n\n\\end{enumerate}\n\n\\noindent Then $X$ is called a metric space with the metric $d$.\n\n\\end{defn}\n\n\\vspace{0.1in}\n\n\\noindent Some more examples:\n\n\\begin{enumerate}\n\\item\n\\item\n\\item\n\\item\n\\end{enumerate}\n\n\\begin{rmk}\n    We would often like to allow $d(x,y)=\\infty$ so $d:X\\times X \\Rightarrow [0, \\infty]$\n\\end{rmk}\n\n\\vspace{0.1in}\n\n\\begin{exr}\nLet $d_{n} : X\\times X \\rightarrow \\mathbb{R}$ is a metric on X, $\\forall n \\in \\mathbb{N}$.\nProve that $d(x, y) = \\operatorname*{inf}\\limits_{n \\in \\mathbb{N}}\\{d_{n}(x,y)\\}$ satisfies\nall conditions except 1(c).\n\\end{exr}\n\n\\begin{exr}\nLet $d : X\\times X \\rightarrow \\mathbb{R}$ satisfies all properties of a metric\nexpect 1(c) in Definition 1.1.\n\n\\begin{enumerate}\n\\item Show that the relation  $$x \\sim y \\xLeftrightarrow[]{Defn} d(x,y) = 0$$\n  is an equivalence realtion on X.\n\n\\item Show that there is a well defined function\n  $\\bar{d} : \\bigslant{X}{\\sim} \\times \\bigslant{X}{\\sim} \\rightarrow \\mathbb{R} $\n  given by $$ \\bar{d}([x], [y]) = d(x, y) $$\n  where $[x]$ is an equivalence class of $X$ under $\\sim$.\n\n\\item Show that $\\bar{d}$ is a metric on $\\bigslant{X}{\\sim}$.\n\\end{enumerate}\n\\end{exr}\n", "meta": {"hexsha": "747de60e078ba29280ad15d01f632b952c1c4696", "size": 1854, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/MetricSpaces.tex", "max_stars_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_stars_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-12-28T05:53:38.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-20T05:56:59.000Z", "max_issues_repo_path": "src/MetricSpaces.tex", "max_issues_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_issues_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/MetricSpaces.tex", "max_forks_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_forks_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0540540541, "max_line_length": 92, "alphanum_fraction": 0.6504854369, "num_tokens": 659, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7202042288610015}}
{"text": "\\subsection{Sketch Proofs}\r\n\\begin{proof}[Proof of Divergence Theorem in Convex Domains]\r\n    Consider $\\underline{F}=F_z\\underline{e_z}$ and a volume $V$ with $\\partial V=S_+\\cup S_-$ divided by a surface such that both $S_+,S_-$ project to the same surface $A$ on the $x-y$ plane (which is possible since the domain is convex).\r\n    We describe the surfaces as\r\n    $$S_{\\pm}=\\{\\underline{x}=\\underline{x}(x,y)=\\begin{pmatrix}\r\n        x\\\\\r\n        y\\\\\r\n        g_{\\pm}(x,y)\r\n    \\end{pmatrix}:(x,y)\\in A\\}$$\r\n    Therefore\r\n    \\begin{align*}\r\n        \\int_V\\frac{\\partial F_z}{\\partial z}\\,\\mathrm dV&=\\iint_A\\left( \\int_{g_-(x,y)}^{g_+(x,y)} \\frac{\\partial F_z}{\\partial z}\\,\\mathrm dz\\right)\\,\\mathrm dx\\,\\mathrm dy\\\\\r\n        &=\\iint_A(F_z(x,y,g_+(x,y))-F_z(x,y,g_-(x,y)))\\,\\mathrm dx\\,\\mathrm dy\r\n    \\end{align*}\r\n    Now note that\r\n    $$\\mathrm d\\underline{S}=\\frac{\\partial\\underline{x}}{\\partial x}\\times\\frac{\\partial\\underline{x}}{\\partial y}\\,\\mathrm dx\\,\\mathrm dy=\\begin{pmatrix}\r\n        -\\partial g_\\pm/\\partial x\\\\\r\n        -\\partial g_\\pm/\\partial y\\\\\r\n        1\r\n    \\end{pmatrix}\\,\\mathrm dx\\,\\mathrm dy$$\r\n    Now we need the normal to point out of $V$, hence on $S_\\pm$.\r\n    $$\\mathrm d\\underline{S}=\\pm\\begin{pmatrix}\r\n        -\\partial g_\\pm/\\partial x\\\\\r\n        -\\partial g_\\pm/\\partial y\\\\\r\n        1\r\n    \\end{pmatrix}\\,\\mathrm dx\\,\\mathrm dy$$\r\n    So\r\n    $$\\int_{\\partial V}F_z\\underline{e_z}\\cdot\\mathrm d\\underline{S}=\\iint_A(F_z(x,y,g_+(x,y))-F_z(x,y,g_-(x,y)))\\,\\mathrm dx\\,\\mathrm dy=\\int_V\\frac{\\partial F_z}{\\partial z}\\,\\mathrm dV$$\r\n    Now we can do the same thing on $F_y\\underline{e_y}$ and $F_x\\underline{e_x}$, so adding them up gives the theorem by linearity.\r\n\\end{proof}\r\nNote that the same proof works for two dimensional case.\r\nNow we want to proof Green's Theorem by the divergence theroem in two dimensions.\r\nAfter that we shall prove that Green's Theorem implies Stokes' Theorem.\r\n\\begin{proof}[Proof of Green's using Divergence]\r\n    Consider the vector field $\\underline{F}=(Q,-P)$, so by Divergence Theorem,\r\n    \\begin{align*}\r\n        \\iint_A\\left( \\frac{\\partial Q}{\\partial x}-\\frac{\\partial P}{\\partial y} \\right)\\,\\mathrm dx\\,\\mathrm dy\r\n        &=\\int_A\\nabla\\cdot\\underline{F}\\,\\mathrm dA\\\\\r\n        &=\\oint_{\\partial A}\\underline{F}\\cdot\\underline{n}\\,\\mathrm ds\\\\\r\n        &=\\oint_{\\partial A}\\begin{pmatrix}\r\n            Q\\\\\r\n            -P\r\n        \\end{pmatrix}\\cdot\\begin{pmatrix}\r\n            y^\\prime(s)\\\\\r\n            -x^\\prime(s)\r\n        \\end{pmatrix}\\,\\mathrm ds\\\\\r\n        &=\\oint_{\\partial A}P\\,\\mathrm dx+Q\\,\\mathrm dy\r\n    \\end{align*}\r\n    which is precisely Green's.\r\n\\end{proof}\r\n\\begin{proof}[Proof of Stokes' by Green's]\r\n    For $A\\subset\\mathbb R^2,Q=Q(u,v),P=P(u,v)$, we have\r\n    $$\\iint_A\\left( \\frac{\\partial Q}{\\partial u}-\\frac{\\partial P}{\\partial v} \\right)\\,\\mathrm du\\,\\mathrm dv=\\oint_{\\partial A}P\\,\\mathrm du+Q\\,\\mathrm dv$$\r\n    Consider the surface $S=\\{\\underline{x}(u,v):(u,v)\\in A\\}$ and boundary $\\partial S=\\{\\underline{x}(u,v):(u,v)\\in\\partial A\\}$.\r\n    Choose\r\n    $$\\begin{cases}\r\n        P=\\underline{F}(\\underline{x}(u,v))\\cdot\\partial\\underline{x}/\\partial u\\\\\r\n        Q=\\underline{F}(\\underline{x}(u,v))\\cdot\\partial\\underline{x}/\\partial v\r\n    \\end{cases}$$\r\n    Note that\r\n    \\begin{align*}\r\n        P\\,\\mathrm du+Q\\,\\mathrm dv\r\n        &=\\underline{F}(\\underline{x}(u,v))\\cdot\\frac{\\partial\\underline{x}}{\\partial u}\\,\\mathrm du+\\underline{F}(\\underline{x}(u,v))\\cdot\\frac{\\partial\\underline{x}}{\\partial v}\\,\\mathrm dv\\\\\r\n        &=\\underline{F}(\\underline{x}(u,v))\\cdot\\left( \\frac{\\partial\\underline{x}}{\\partial u}\\,\\mathrm du+\\frac{\\partial\\underline{x}}{\\partial v}\\,\\mathrm dv \\right)\\\\\r\n        &=\\underline{F}(\\underline{x}(u,v))\\cdot\\mathrm d\\underline{x}(u,v)\\\\\r\n        \\implies \\oint_{\\partial A}P\\,\\mathrm du+Q\\,\\mathrm dv&=\\oint_{\\partial S}\\underline{F}\\cdot\\mathrm d\\underline{x}\r\n    \\end{align*}\r\n    On the other hand, we can differentiate to get\r\n    \\begin{align*}\r\n        \\frac{\\partial Q}{\\partial u}&=\\frac{\\partial}{\\partial u}\\left( \\underline{F}(\\underline{x}(u,v))\\cdot\\partial\\underline{x}/\\partial v \\right)\\\\\r\n        &=\\frac{\\partial x_j}{\\partial u}\\frac{\\partial F_i}{\\partial x_j}\\frac{\\partial x_i}{\\partial v}+F_i(\\underline{x}(u,v))\\frac{\\partial^2 x_i}{\\partial u\\partial v}\r\n    \\end{align*}\r\n    Similarly\r\n    $$\\frac{\\partial P}{\\partial v}=\\frac{\\partial x_j}{\\partial v}\\frac{\\partial F_i}{\\partial x_j}\\frac{\\partial x_i}{\\partial u}+F_i(\\underline{x}(u,v))\\frac{\\partial^2 x_i}{\\partial v\\partial u}$$\r\n    Now combining these two and using the symmetries in second partial derivatives,\r\n    \\begin{align*}\r\n        \\left(\\frac{\\partial Q}{\\partial u}-\\frac{\\partial P}{\\partial v}\\right)\\,\\mathrm du\\,\\mathrm dv&=\\left(\\frac{\\partial x_j}{\\partial u}\\frac{\\partial F_i}{\\partial x_j}\\frac{\\partial x_i}{\\partial v}-\\frac{\\partial x_j}{\\partial v}\\frac{\\partial F_i}{\\partial x_j}\\frac{\\partial x_i}{\\partial u}\\right)\\,\\mathrm du\\,\\mathrm dv\\\\\r\n        &=(\\nabla\\times\\underline{F})\\cdot\\left( \\frac{\\partial\\underline{x}}{\\partial u}\\times\\frac{\\partial\\underline{x}}{\\partial v} \\right)\\,\\mathrm du\\,\\mathrm dv\\\\\r\n        &=(\\nabla\\times\\underline{F})\\cdot\\mathrm d\\underline{S}\r\n    \\end{align*}\r\n    Combining this with Green's Theorem gives the result.\r\n\\end{proof}", "meta": {"hexsha": "0e99fa030e52767c63893bc4dd3274f010fb074f", "size": 5346, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/proofs.tex", "max_stars_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_stars_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/proofs.tex", "max_issues_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_issues_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/proofs.tex", "max_forks_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_forks_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.1951219512, "max_line_length": 337, "alphanum_fraction": 0.6230826786, "num_tokens": 1771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.828938799869521, "lm_q2_score": 0.8688267745399466, "lm_q1q2_score": 0.7202042237816503}}
{"text": "\\subsection{Example: R-RTR-RTR mechanism}\n\n\\begin{frame}\n\t\\begin{block}{Example 4: R-RTR-RTR mechanism}\n\t\t\\begin{table}\n\t\t\t\\begin{minipage}{0.5\\linewidth}\n\t\t\t\t\\begin{tabular}{l|l}\n\t\t\t\t\t& $l_{AB}=l_1=0.15m$\\\\\n\t\t\t\t\t& $l_{AC}=l_2=0.1m$\\\\\n\t\t\t\t\tGiven & $l_{CD}=l_3=0.15m$\\\\\n\t\t\t\t\t& $l_{DF}=l_4=0.4m$\\\\\n\t\t\t\t\t& $l_{AG}=l_5=0.3m$\\\\\n\t\t\t\t\t& $\\theta_1=30^{\\circ}$\\\\ \\hline\n\t\t\t\t\tFind & $\\vb{r}{B}$, $\\vb{r}{D}$, $\\vb{r}{G}$\n\t\t\t\t\\end{tabular}\n\t\t\t\\end{minipage}\\hfill\n\t\t\t\\begin{minipage}{0.5\\linewidth}\n\t\t\t\t\\begin{figure}\n\t\t\t\t\t\\includegraphics[width=55mm]{images/R-RTR-RTR.png}\n\t\t\t\t\\end{figure}\n\t\t\t\\end{minipage}\n\t\t\\end{table}\t\n\t\\end{block}\n\\emph{Solution}\\vskip2.5mm\nPosition of joint B:  $\\displaystyle \\vb{r}{B} = x_B\\ih + y_B\\jh = l_1\\cos{\\theta_1}\\ih + l_1\\sin{\\theta_1}\\jh$\\\\\nPosition of joint C:  $\\displaystyle \\vb{r}{C} = x_C\\ih + y_C\\jh = 0.1\\jh$\\\\\nPosition of joint D:  $\\displaystyle \\vb{r}{D} = x_D\\ih + y_D\\jh$\\\\\n\\end{frame}\n\n\\begin{frame}\nPosition of joint E: $\\displaystyle \\vb{r}{E} = x_E\\ih + y_E\\jh$\\\\\nPosition of joint G: $\\displaystyle \\vb{r}{G} = x_G\\ih + y_G\\jh$\n\n\t\\[\\Rightarrow \\begin{cases}\n\tx_D^2 + (y_D-x_C)^2 = l_3^2\\\\\n\t\\displaystyle \\frac{y_D-y_C}{x_D-x_C} = \\frac{y_D-y_B}{x_D-x_B}\n\t\\end{cases} \\]\n\t\n\tSolving the system of equations yields $x_{D_1}$ and $x_{D_2}$. Since $\\theta_1\\in [0,90)$, the condition is $x_D\\leq x_C$\n\t\n\t\\[\\Rightarrow\\begin{cases}\n\t\\displaystyle \\theta_2=\\arctan{\\frac{y_B-y_C}{x_B-x_C}}\\\\\n\t\\displaystyle\\theta_3=\\theta_2\\\\\n\t\\displaystyle\\theta_4=\\arctan{\\frac{y_D}{x_D}}\\\\\n\t\\displaystyle\\theta_5=\\theta_4\n\t\\end{cases}\\]\n\nFor other an arbitrary angle $\\theta_1$, finding the right condition is tricky (\\textit{4 conditions} corresponding to 4 quadrants of 1 full rotation).\n\\end{frame}\n\n\\begin{frame}\n\t\\begin{table}\n\t\t\\centering\n\t\t\\begin{tabular}{l|l|l|l}\n\t\t\t$1^{st}$ quadrant & $2^{nd}$ quadrant & $3^{rd}$ quadrant & $4^{th}$ quadrant \\\\\\hline\n\t\t\t$x_D\\leq x_C=0$   & $x_D\\geq x_C=0$   & $x_D\\geq x_C=0$   & $x_D\\leq x_C=0$\n\t\t\\end{tabular}\n\t\t\\caption{4 conditions to find $x_D$ from $[0,2\\pi]$}\n\t\\end{table}\n\n\tFor this mechanism, observe that for any $\\theta_1$:\n\t\n\t\\begin{itemize}\n\t\t\\item $x_Dx_B<0$\n\t\t\\item $\\vb{r}{{DC}}$ and $\\vb{r}{{DF}}$ have the same angle \n\t\t\\item $\\vb{r}{D}$ and $\\vb{r}{G}$ have the same angle\n\t\\end{itemize}\n\n\tUsing these properties, we can obtain direct solution of position analysis for the mechanism:\\\\\n\t\n\t\\begin{itemize}\n\t\t\\item Find $\\vb{r}{D}$\n\t\t\\[\\begin{cases}\n\t\t\\displaystyle\\langle \\vb{Ox},\\vb{r}{CD}\\rangle = \\arctan{\\frac{y_B-y_C}{x_B-x_C}} + \\pi\\\\\n\t\t\\displaystyle\\vb{r}{D} = \\vb{r}{C} + sign(x_B)l_3\\left(\\cos{\\langle\\vb{Ox},\\vb{r}{CD}\\rangle}\\ih + \\sin{\\langle \\vb{Ox},\\vb{r}{CD}\\rangle}\\jh\\right)\n\t\t\\end{cases}\\]\n\t\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\t\\begin{itemize}\n\t\t\\item Find $\\vb{r}{F}$\n\t\t\\[\\begin{cases}\n\t\t\\displaystyle \\langle \\vb{Ox}, \\vb{r}{FC}\\rangle = \\arctan{\\frac{y_C-y_D}{x_C-x_D}}\\\\\n\t\t\\displaystyle\\vb{r}{F} = \\vb{r}{C}+sign(x_B)(l_4-l_3)\\left(\\cos{\\langle \\vb{Ox},\\vb{r}{FC}\\rangle\\ih} + \\sin{\\langle \\vb{Ox},\\vb{r}{FC}\\rangle\\jh}\\right)\n\t\t\\end{cases}\\]\n\t\t\\item Find $\\vb{r}{G}$\n\t\t\\[\\begin{cases}\n\t\t\\displaystyle \\langle \\vb{Ox}, \\vb{r}{G}\\rangle = \\arctan{\\frac{y_D}{x_D}}\\\\\n\t\t\\displaystyle\\vb{r}{G} = -sign(x_B)l_5\\left(\\cos{\\langle \\vb{Ox},\\vb{r}{G}\\rangle\\ih}+\\sin{\\langle \\vb{Ox},\\vb{r}{G}\\rangle\\jh}\\right)\n\t\t\\end{cases}\\]\n\t\\end{itemize}\nNote that $\\arctan{\\theta}\\in(-\\frac{\\pi}{2}, \\frac{\\pi}{2})$, which leads to the presence of $sign(x_B)$.\n\\end{frame}\n\n\n\\begin{frame}{MATLAB R2019a code}\n\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/RRTRRTR-position01.m}\n\\end{frame}\n\n\\begin{frame}{MATLAB R2019a code}\n\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/RRTRRTR-position02.m}\n\\end{frame}\n\\begin{frame}{MATLAB R2019a code (direct solution)}\n\t\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/RRTRRTR-position1.m}\n\\end{frame}\n\\begin{frame}{MATLAB R2019a code (direct solution)}\n\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/RRTRRTR-position2.m}\n\\end{frame}\n\\begin{frame}{Plotting using MATLAB R2019a}\n\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/RRTRRTR-plot.m}\n\\end{frame}\n\\begin{frame}{Output figure}\n\\centering\n\\includegraphics[width=100mm]{images/RRTRRTR-plot.png}\n\\end{frame}\n\\begin{frame}{Trajectory plotting using MATLAB R2019a}\n\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/RRTRRTR-trajectory.m}\n\\end{frame}\n\\begin{frame}{Output figure}\n\\centering\n\\includegraphics[width=100mm]{images/RRTRRTR-trajectory.png}\n\\end{frame}\n", "meta": {"hexsha": "6c2454ba633ca906b897407f465409abd713d4b8", "size": 4563, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Finished/position_analysis_pdf/Sections/Examples/RRTRRTR.tex", "max_stars_repo_name": "HungNguyenDang/literate-meme", "max_stars_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Finished/position_analysis_pdf/Sections/Examples/RRTRRTR.tex", "max_issues_repo_name": "HungNguyenDang/literate-meme", "max_issues_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Finished/position_analysis_pdf/Sections/Examples/RRTRRTR.tex", "max_forks_repo_name": "HungNguyenDang/literate-meme", "max_forks_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.7983870968, "max_line_length": 155, "alphanum_fraction": 0.6635985098, "num_tokens": 1882, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7201172077031269}}
{"text": "\\subsection{Double Fourier representation}\nSuppose $\\Omega$ is bounded and $R$ is the maximum norm of an element of $\\Omega$. Then\n\\begin{equation}\n\\left|\\frac{\\omega}{a} \\cdot x+b\\right| \\geq \\max \\left(0,|b|-\\frac{R|\\omega|}{|a|}\\right).\n\\end{equation}\nSuppose $\\boldsymbol{\\sigma} \\in W^{m, \\infty}(\\mathbb{R})$ is non-zero and it satisfies the polynomial decay condition\n\\begin{equation}\\label{eq:assdecay}\n\\left|\\sigma^{(k)}(s)\\right| \\leq C_{p}(1+|s|)^{-p}\n\\end{equation}\nfor $0\\le k\\le m+1$ and some $p> 1$. \nDefine\n\\begin{equation}\nh(b,\\omega)=\\bigg (1+ \\max \\bigg(0, |b|-{R|\\omega|\\over |a|}\\bigg )\\bigg )^{-p}.\n\\end{equation}\nIt follows that\n\\begin{equation}\\label{eq:decaypro}\n\\left|\\sigma^{(k)}\\left(\\frac{\\omega}{a} \\cdot x+b\\right)\\right| \\leq C_{p}\\left(1+\\left|\\frac{\\omega}{a} \\cdot x+b\\right|\\right)^{-p} \\leq C_{p}h(b,\\omega)\n\\end{equation}\nMoreover,\n\\begin{equation}\n\\begin{aligned}\n\\int_{\\mathbb{R}} h(b, \\omega) d b &=\\int_{|b| \\leq \\frac{R|\\omega|}{|a|}} d b+2 \\int_{b>\\frac{R|\\omega|}{|a|}}\\left(1+b-\\frac{R|\\omega|}{|a|}\\right)^{-p} d b \\\\\n&=2 R|a|^{-1}|\\omega|+2\\left[(1-p)^{-1}\\left(1+b-\\frac{R|\\omega|}{|a|}\\right)^{1-p}\\right]^{\\infty} \\\\\n&=2 R|a|^{-1}|\\omega|+\\frac{2}{p-1} \\leq C_{1}(p, \\operatorname{diam}(\\Omega), \\sigma)(1+|\\omega|)\n\\end{aligned}\n\\end{equation} \n\n\\begin{theorem}\nLet $\\Omega\\subset \\mathbb{R}^d$ be a bounded domain. If the activation function  $\\boldsymbol{\\sigma} \\in W^{m, \\infty}(\\mathbb{R})$ is non-zero and it satisfies the polynomial decay condition\n\\begin{equation}\\label{eq:assdecay}\n\\left|\\sigma^{(k)}(s)\\right| \\leq C_{p}(1+|s|)^{-p}\n\\end{equation}\nfor $0\\le k\\le m+1$ and some $p> 1$, we have\n\\begin{equation}\n\\inf _{f_{n} \\in \\Sigma_{d}^{n}(\\sigma)}\\left\\|f-f_{n}\\right\\|_{H^{m}(\\Omega)} \\leq|\\Omega|^{\\frac{1}{2}} C(p, m, \\operatorname{diam}(\\Omega), \\sigma) n^{-\\frac{1}{2}-\\frac{t}{(2+t)(d+1)}}\\|f\\|_{\\mathscr{B}^{m+1+\\varepsilon}}\n\\end{equation}\nwhere $t=\\min (p-1, \\varepsilon),$ for any $f \\in \\mathscr{B}^{m+1+\\varepsilon}$\n\\end{theorem}\n\\begin{proof}\nLet $\\theta=(\\omega, b)$, $\\hat f(\\omega)=|\\hat f(\\omega)| e^{ib(\\theta)}$,\n\\begin{equation}\n\\lambda(\\theta) = {\\rho(\\theta)\\over \\|\\rho(\\theta)\\|_{L^1(G)}} \\qquad \\text{with}\\qquad \\rho(\\theta) = (1+|\\omega|)^mh(b,\\omega)|\\cos b(\\theta)| |\\hat f(\\omega)|.\n\\end{equation}\nThe polynomial decay condition \\eqref{eq:assdecay} implies that\n\\begin{equation}\\label{eq:rhostratify}\n\\|\\rho(\\theta)\\|_{L^1(G)}\\le  C_1(p, {\\rm diam}(\\Omega), \\sigma)\\|f\\|_{\\mathcal{B}^{m+1}}.\n\\end{equation}\nDefine\n\\begin{equation}\ng(x,\\theta) = {\\|\\rho(\\theta)\\|_{L^1(\\Theta)}\\over 2\\pi |\\hat \\sigma (a)|(1+|\\omega|)^{m}h(b,\\omega)} {\\rm sgn} (\\cos b(\\theta))\\sigma ({\\omega\\over a}\\cdot x+b).\n\\end{equation}\nThus\n\\begin{equation}\nf(x)=\\int_G g(x,\\theta)\\lambda(\\theta)d\\theta\n\\end{equation}\nwith $G=\\mathbb{R}^d\\times \\mathbb{R}$. \n\nLet $G = G_A\\cup G_A^c$ with\n$$\nG_A=\\big \\{(\\omega, b): |b|\\le A,\\ |\\omega|\\le {A|a|\\over 2R}\\big \\}.\n$$\nThe interval $[-A,A]$ can be divided into $n_b$ subintervals  $\\{G_i^b\\}_{i=1}^{n_b}$ such that \n$$\n|b - b'|<An^{-{1\\over d+1}}\\quad b, b'\\in G_i^b,\\quad 1\\leq i\\leq n_b\n$$ \nfor $n_b\\ge 2\\lceil  n^{1\\over d+1}\\rceil$. \nThe interval $[-{A|a|\\over 2R}, {A|a|\\over 2R}]$ can be divided into $n_\\omega$ subintervals $\\{G_i^\\omega \\}_{i=1}^{n_\\omega}$ such that\n$$\n|\\omega_j - \\omega'_j| \\leq {A|a|\\over R}n^{-{1\\over d+1}}\\qquad  \\omega,   \\omega' \\in G_i^\\omega,\\quad 1\\leq i\\leq n_\\omega\n$$\nfor $n_\\omega\\ge \\lceil n^{1\\over d+1}\\rceil$.\nThe product of these intervals gives the following decomposition \n$$\nG_A=\\tilde G_1\\cup \\tilde G_2\\cup \\cdots \\cup \\tilde G_M\n$$\nsuch that for any $\\theta=(\\omega, b)$ and $\\theta'=(\\omega',b')$ in $\\tilde G_i$,\n\\begin{equation}\n|b - b'|<An^{-{1\\over d+1}}, \\quad \\|\\omega - \\omega'\\|_{\\ell^\\infty} \\leq {A|a|\\over R}n^{-{1\\over d+1}}.\n\\end{equation}\nEach $\\tilde G_i$ can be divided into two subsets:\n\\begin{equation}\n\\tilde G_i^1 = \\{\\theta\\in \\tilde G_i: \\cos (b(\\theta))\\ge 0\\}\\quad \\tilde G_i^2 = \\{\\theta\\in \\tilde G_i: \\cos (b(\\theta))\\le 0\\}.\n\\end{equation}\nThis leads to a decomposition of $G_A$ by $G_A=\\cup_{i=1}^{2M} G_i$. For any $ \\theta, \\theta'\\in G_i$, \n\\begin{equation}\n|b - b'|<An^{-{1\\over d+1}}, \\quad \\|\\omega - \\omega'\\|_{\\ell^\\infty} \\leq {A|a|\\over R}n^{-{1\\over d+1}}, {\\rm sgn} (\\cos b(\\theta))={\\rm sgn} (\\cos b(\\theta')).\n\\end{equation} \nDenote $G_A^c = G_{2M+1}$. Let $n_i=\\lceil \\lambda(G_i)n\\rceil$ and \n\\begin{equation}\nf_{n}(x)=\\sum_{i=1}^{2 M+1} \\frac{\\lambda(G_{i})}{n_{i}} \\sum_{j=1}^{n_{i}}g(x,\\theta_{i,j}).\n\\end{equation}\nAccording to Theorem \\ref{lem:stratifiedapprox},  \n\\begin{equation} \n\\mathbb{E}\\left(\\left\\|f - f_{n}\\right\\|_{H^{m}(\\Omega)}^{2}\\right)\\le\n \\sum_{i=1}^{2M+1}  \\frac{\\lambda^2(G_i)}{n_{i}}  \\sup_{\\theta_{i},\\theta_{i}'\\in G_i} \\| g(x,\\theta_i) - g(x,\\theta_i')\\|^2_{H^m(\\Omega)}  \n\\end{equation}\n\nNotice that\n\\begin{equation}\nD_x^\\alpha g(x,\\theta) = {\\|\\rho(\\theta)\\|_{L^1(G)}\\over 2\\pi |\\hat \\sigma (a)|(1+|\\omega|)^{m}h(b,\\omega)|a|^{|\\alpha|} }{\\rm sgn} (\\cos b(\\theta))  \\omega^\\alpha \\sigma^{(|\\alpha|)} ({\\omega\\over a}\\cdot x+b).\n\\end{equation}\nWe first consider $\\sup_{\\theta,\\theta'\\in G_i} \\| g(x,\\theta_i) - g(x,\\theta_i')\\|^2_{H^m(\\Omega)} $ ($1\\le i\\le 2M$). \n\\begin{equation}\n| D_x^\\alpha \\big (g(x,\\theta_i) - g(x,\\theta_i')\\big )|\\le |a|^{-|\\alpha|}| q(x, \\theta_i) - q(x, \\theta_i')|\n\\end{equation}\nwith \n\\begin{equation}\nq(x, \\theta)=(2 \\pi|\\hat{\\sigma}(a)|)^{-1} \\|\\rho(\\theta)\\|_{L^1(G)} \\omega^{\\alpha}(1+|\\omega|)^{-m} h(b, \\omega)^{-1} \\sigma^{(|\\alpha|)}\\left(\\frac{\\omega}{a} \\cdot x+b\\right).\n\\end{equation}\nWe now differentiate $D_x^\\alpha g(x,\\theta)$ with respect to $\\omega$ and $b$, noting that for $|\\alpha|\\le m$,\n\\begin{equation}\n| (1 + |\\omega|)^{-m}\\omega^\\alpha|,\\ |D_\\omega \\big((1 + |\\omega|)^{-m}\\omega^\\alpha\\big ) | \\lesssim 1\n\\end{equation}\n\\begin{equation}\n| h(\\omega, b)^{-1}|\\le \\bigg (1+ \\max \\bigg(0, |b|-{R|\\omega|\\over |a|}\\bigg )\\bigg )^{p}\n\\end{equation}\n\\begin{equation}\n|D_\\omega h(\\omega, b)^{-1}|,\\ |D_b h(\\omega, b)^{-1}|\\le \\bigg (1+ \\max \\bigg(0, |b|-{R|\\omega|\\over |a|}\\bigg )\\bigg )^{p-1}\\le \\bigg (1+ \\max \\bigg(0, |b|-{R|\\omega|\\over |a|}\\bigg )\\bigg )^{p}.\n\\end{equation}\nIt follows from \\eqref{eq:assdecay} that\n\\begin{equation}\n\\left|D_{b} q(x, \\omega, b)\\right| \\lesssim C_{p}\\left(1+\\left|\\frac{\\omega}{a} \\cdot x+b\\right|\\right)^{-p}\\left(1+\\max \\left(0,|b|-\\frac{R|\\omega|}{|a|}\\right)\\right)^{p}\\|f\\|_{\\mathscr{B}^{m+1}}\n\\lesssim C_{p}\\|f\\|_{\\mathscr{B}^{m+1}}\n\\end{equation} \nSimilarly, we obtain, since $|x| \\leq R$\n\\[\n\\left|D_{\\omega} q(\\omega, b, x)\\right| \\lesssim \\frac{R}{|a|}\\|f\\|_{\\mathscr{B}^{m+1}}  \n\\]\nThus,\n\\begin{equation}\n| D_x^\\alpha \\big (g(x,\\theta_i) - g(x,\\theta_i')\\big )|\\lesssim   A n^{-1 /(d+1)}\\|f\\|_{\\mathscr{B}^{m+1}},\n\\end{equation}\nand\n\\begin{equation}\n\\sup_{\\theta,\\theta'\\in G_i} \\| g(x,\\theta_i) - g(x,\\theta_i')\\|^2_{H^m(\\Omega)} \\lesssim   A^2 n^{-2 /(d+1)}|\\Omega|^{\\frac{1}{2}}\\|f\\|_{\\mathscr{B}^{m+1}},\n\\end{equation}\n \nConsider $\\sup_{\\theta,\\theta'\\in G_{2M+1}} \\| g(x,\\theta_i) - g(x,\\theta_i')\\|^2_{H^m(\\Omega)} $. By \\eqref{eq:decaypro},\n\\begin{equation}\n\\| D_x^\\alpha g(x,\\theta)\\|_{L^\\infty(\\Omega)} \\le  {\\|\\rho(\\theta)\\|_{L^1(G)}\\over 2\\pi |\\hat \\sigma (a)||a|^{|\\alpha|} } \\|{1\\over (1+|\\omega|)^{m}h(b,\\omega)} \\omega^\\alpha \\sigma^{(|\\alpha|)} ({\\omega\\over a}\\cdot x+b)\\|_{L^\\infty(\\Omega)}\n\\le  C_p{\\|\\rho(\\theta)\\|_{L^1(G)}\\over 2\\pi |\\hat \\sigma (a)||a|^{|\\alpha|} }.\n\\end{equation}\nThus,\n\\begin{equation}\n\\sup_{\\theta,\\theta'\\in G_{2M+1}} \\| g(x,\\theta_i) - g(x,\\theta_i')\\|^2_{H^m(\\Omega)}  \n\\le \n2\\sup_{\\theta,\\in G_{2M+1}} \\| g(x,\\theta) \\|^2_{H^m(\\Omega)}\n\\le  \n2C_p{\\|\\rho(\\theta)\\|_{L^1(G)}\\over 2\\pi |\\hat \\sigma (a)| }\\sum_{|\\alpha|\\le m}|a|^{-|\\alpha|}.\n\\end{equation}\nBy \\eqref{eq:rhostratify},\n\\begin{equation}\n\\sup_{\\theta,\\theta'\\in G_{2M+1}} \\| g(x,\\theta_i) - g(x,\\theta_i')\\|^2_{H^m(\\Omega)} \n\\le |\\Omega|  C(p, m, \\operatorname{diam}(\\Omega), \\sigma)\\|f\\|_{\\mathscr{B}^{m+1}}^2.\n\\end{equation}\n\n\nThe final ingradient we need is a bound on the probability measure of $G_{2M+1}.$ To do this, we break the set $G_{A}^{c}$ into two pieces, $A_{1},$ where $|\\omega|>\\frac{A|a|}{2 R},$ and $A_{2},$ where $|\\omega| \\leq \\frac{A|a|}{2 R}$ and $|b|>A .$ We get\n\\[\n\\lambda(G_{2M+1} ) \\leq \\frac{1}{I(p, \\Omega, \\sigma, f)}\\left[\\int_{A_{1}}(1+|\\omega|)^{m} h(b, \\omega)|\\hat{f}(\\omega)| d b d \\omega+\\int_{A_{2}}(1+|\\omega|)^{m} h(b, \\omega)|\\hat{f}(\\omega)| d b d \\omega \\right]\n\\]\nBy integrating out $b,$ we immediately obtain\n\\[\n\\int_{A_{1}}(1+|\\omega|)^{m} h(b, \\omega)|\\hat{f}(\\omega)| d b d \\omega \\leq \\int_{|\\omega|>\\frac{A|a|}{2 R}} C_{p}(1+|\\omega|)^{m+1}|\\hat{f}(\\omega)| d \\omega \\lesssim\\|f\\|_{\\mathscr{B}^{m+1+\\varepsilon} }A^{-\\varepsilon}\n\\]\nOn the other hand, on $A_{2}$ we have $|\\omega| \\leq \\frac{A|a|}{2 R}$ and $|b|>A .$ This implies that\n\\[\n|b|-\\frac{R|\\omega|}{|a|} \\geq \\frac{A}{2}\n\\]\nso that for $|\\omega| \\leq \\frac{A|a|}{2 R},$ we have\n\\[\n\\int_{|b|>A} h(\\omega, b)=\\int_{|b|>A}\\left(1+\\max \\left(0,|b|-\\frac{R|\\omega|}{|a|}\\right)\\right)^{-p} \\leq \\int_{|x|>\\frac{A}{2}}(1+x)^{-p} \\lesssim\\left(1+\\frac{A}{2}\\right)^{1-p}\n\\]\nIntegrating in $b \\text { and then } \\omega, \\text { we obtain (recall } A \\geq 1)$\n\\[\n\\int_{A_{2}}(1+|\\omega|)^{m} h(b, \\omega)|\\hat{f}(\\omega)| d b d \\omega \\lesssim\\left(1+\\frac{A}{2}\\right)^{1-p} \\int_{|\\omega| \\leq \\frac{A|a|}{2 R} |}(1+|\\omega|)^{m}|\\hat{f}(\\omega)| d \\omega \\lesssim\\|f\\|_{\\mathscr{B}^{m+1+\\varepsilon}} A^{1-p}\n\\]\nThus,\n\\[\n\\lambda(G_{2M+1} )  \\lesssim A^{-\\min (p-1, \\varepsilon)}\n\\]\nAll these estimates lead to\n\\[\n\\mathbb{E}(\\|f_{n}-f\\|_{H^{m}(\\Omega)}^{2}) \\lesssim\n|\\Omega| \\frac{\\|f\\|_{\\mathscr{B}^{m+1+\\varepsilon}}^{2}}{n}\\left[A^{-\\min (p-1, \\varepsilon)}+A^{2} n^{-2 /(d+1)}\\right]\n\\]\nOptimizing over $A,$ we obtain, for $A=n^{2 /[(d+1)(2+\\min (p-1, \\varepsilon))]}$\n\\[\n\\mathbb{E} (\\|f_{n}-f\\|_{H^{m}(\\Omega)}^{2} ) \\lesssim \n| \\Omega\\|\\| f \\|_{\\mathscr{S}^{m+1+\\varepsilon}}^{2} n^{-1-} \\frac{2 \\sin (p-1, \\varepsilon)}{(d+1)(2+\\min (p-1, \\varepsilon))}\n\\]\nThis bound on the expectation means that there must exist samples $\\left(\\omega_{i j}, b_{i j}, \\eta_{i j}\\right)$ such that $\\tilde{f}_{n}$ defined by\n\\[\n\\|f_{n}-f \\|_{H^{m}(\\Omega)}^{2} \\lesssim\n|\\Omega|\\|f\\|_{\\mathscr{S}^{m+1+\\varepsilon}}^{2} n^{-1-\\frac{2 \\min (p-1, \\varepsilon)}{(d+1)(2+\\min (p-1, \\varepsilon))}}\n\\]\nThus we finally get\n\\[\n\\inf _{f_{n} \\in \\Sigma_{d}^{3+1}(\\sigma)}\\left\\|f_{n}-f\\right\\|_{H^{m}(\\Omega)} \\leq|\\Omega|^{\\frac{1}{2}} C(p, m, \\operatorname{diam}(\\Omega), \\sigma)\\|f\\|_{\\mathscr{B}^{m+1+\\varepsilon} }n^{{-\\frac{1}{2}}-\\frac{\\min (p-1, \\varepsilon)}{(d+1)(2+\\min (p-1, \\varepsilon))}}\n\\]\nas desired.\n\n\n\\end{proof}\n\n\n", "meta": {"hexsha": "65d26dd96200614973277fd2d2dc5103d8a1fa47", "size": 10665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/DoubleFourier2.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/DoubleFourier2.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/DoubleFourier2.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.5217391304, "max_line_length": 273, "alphanum_fraction": 0.5885607126, "num_tokens": 4795, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7201172077031269}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsfonts}\n\\usepackage{amsmath}\n\n\\title{Lines in the projective plane $\\mathbb{P}^2$}\n\\author{Dave Neary}\n\\date{June 2021}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Introduction}\n\nThe projective plane $\\mathbb{P}^2$ is the set of points on the affine plane, plus\nthe points at infinity representing different slopes. The addition of the points at\ninfinity guarantees that any two distinct lines intersect at one point exactly. It can\nalso be describes by the set of triples $[X; Y; Z]$ not all zero, which are equivalent\nup to multiplication by a scalar - $[1; 2; 3]$ and $[2; 4; 6]$ refer to the same point.\n\nFor a point $[X;Y;Z] \\in \\mathbb{P}^2$, if $Z \\neq 0$ then this maps to the point in\nthe Cartesian (or affine) plane $(\\frac{X}{Z}, \\frac{Y}{Z})$. If $Z=0$, the point\ncorresponds to a point at infinity (the intersection point of all lines with the\nslope $-\\frac{X}{Y}$).\n\n\\section{Lines in the projective plane}\n\nCommon results in Euclidean geometry hold also in the projective plane, with some differences.\n\n\\begin{itemize}\n    \\item Given two distinct points in the projective plane $P_1=[a_1; a_2; a_3],\n    P_2=[b_1; b_2; b_3]$ there is a unique line $L: \\alpha X + \\beta Y + \\gamma Z = 0$\n    which goes through both points.\n    \\item Given two distinct lines in the projective plane, they intersect at exactly one point.\n\\end{itemize}\n\nRecall that if $P_1 = \\lambda P_2$ for some scalar factor then $P_1=P_2$ (if it helps, think\nof these as equivalence classes like fractions: $\\frac{4}{2} = \\frac{6}{3}$). So the triples\n$(a_1, a_2, a_3), (b_1, b_2, b_3)$ are linearly independent if they are distinct points in $\\mathbb{P}^2$.\n\nThen:\n\\[\n\\begin{pmatrix}\na_1 & a_2 & a_3 \\\\\nb_1 & b_2 & b_3\n\\end{pmatrix} \\begin{pmatrix}\n\\alpha \\\\ \\beta \\\\ \\gamma\n\\end{pmatrix} = \\begin{pmatrix}\n0 \\\\ 0\n\\end{pmatrix} \n\\]\nhas a solution, unique up to multiplication by a scalar, with $[\\alpha; \\beta; \\gamma] \\in \\mathbb{P}^2$.\nAs we have seen, a point in $\\mathbb{P}^2$ is essentially the same as a line through the\norigin in $\\mathbb{A}^3$. Given $P=[X;Y;Z]$ we can write that line in parametric form with:\n\\[ L: \\vec{p} = \\lambda \\begin{pmatrix} X \\\\ Y \\\\ Z \\end{pmatrix} \\]\n\nGiven this, you can see that the two linearly independent vectors $P_1, P_2$ define a plane \nthrough the origin in $\\mathbb{A}^3$ defined by:\n\\[ C: \\vec{p} = \\lambda_1 \\begin{pmatrix} a_1 \\\\ a_2 \\\\ a_3 \\end{pmatrix} \n+ \\lambda_2 \\begin{pmatrix} b_1 \\\\ b_2 \\\\ b_3 \\end{pmatrix}\\]\n\nThis maps to the line in $\\mathbb{P}^2$:\n\\[ L: \\alpha X + \\beta Y + \\gamma Z = 0 \\]\n\nwhere the vector \n\\[P_3 = \\begin{pmatrix} \\alpha \\\\ \\beta \\\\ \\gamma \\end{pmatrix} \\]\n\nsatisfies the relationships $P_1 \\cdot P_3 = 0$ and $P_2 \\cdot P_3 = 0$ - that is,\n$P_3$ is orthogonal to both $P_1$ and $P_2$. In other words, it is a scalar multiple\nof $P_1 \\times P_2$.\n\nWe can calculate $\\alpha, \\beta, \\gamma$ with:\n\\[ \\begin{vmatrix} \\alpha & \\beta & \\gamma \\\\\na_1 & a_2 & a_3 \\\\\nb_1 & b_2 & b_3 \\end{vmatrix} = 0 \\]\nor:\n\\[L: \\alpha \\begin{vmatrix} a_2 & a_3 \\\\ b_2 & b_3 \\end{vmatrix}\n- \\beta  \\begin{vmatrix} a_1 & a_3 \\\\ b_1 & b_3 \\end{vmatrix}\n+ \\gamma \\begin{vmatrix} a_1 & a_2 \\\\ b_1 & b_2 \\end{vmatrix} = 0\\]\n\nSimilarly, given two lines $L_1: \\alpha_1 X + \\beta_1 Y + \\gamma_1 Z = 0,\nL_2: \\alpha_2 X + \\beta_2 Y + \\gamma_2 Z = 0$, $L_1, L_2$ are linearly independent, and\nthere is a unique solution $[X_1; Y_1; Z_1]$ (up to multiplication by a scalar) for the system:\n\\[\n\\begin{pmatrix}\n\\alpha_1 & \\beta_1 & \\gamma_1 \\\\\n\\alpha_2 & \\beta_2 & \\gamma_2\n\\end{pmatrix} \\begin{pmatrix}\nX_1 \\\\ Y_1 \\\\ Z_1\n\\end{pmatrix} = \\begin{pmatrix}\n0 \\\\ 0\n\\end{pmatrix}\n\\]\n\nwhich means that any two homogeneous lines intersect at exactly one point in $\\mathbb{P}^2$.\n\n\\end{document}\n", "meta": {"hexsha": "62fd7cdb9688c77eb801ba1bad788bd20720037d", "size": 3781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "line_in_projective_plane.tex", "max_stars_repo_name": "dneary/math", "max_stars_repo_head_hexsha": "129b2093c01b12ddc2e61abd331c95da2177803c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "line_in_projective_plane.tex", "max_issues_repo_name": "dneary/math", "max_issues_repo_head_hexsha": "129b2093c01b12ddc2e61abd331c95da2177803c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "line_in_projective_plane.tex", "max_forks_repo_name": "dneary/math", "max_forks_repo_head_hexsha": "129b2093c01b12ddc2e61abd331c95da2177803c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.1919191919, "max_line_length": 106, "alphanum_fraction": 0.6805078022, "num_tokens": 1379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7201172057455948}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Written By Michael Brodskiy\n% Class: Analytic Geometry & Calculus III (Math-292)\n% Professor: V. Cherkassky\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\documentclass[12pt]{article} \n\\usepackage{alphalph}\n\\usepackage[utf8]{inputenc}\n\\usepackage[russian,english]{babel}\n\\usepackage{titling}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{enumitem}\n\\usepackage{amssymb}\n\\usepackage[super]{nth}\n\\usepackage{everysel}\n\\usepackage{ragged2e}\n\\usepackage{geometry}\n\\usepackage{fancyhdr}\n\\geometry{top=1.0in,bottom=1.0in,left=1.0in,right=1.0in}\n\\newcommand{\\subtitle}[1]{%\n  \\posttitle{%\n    \\par\\end{center}\n    \\begin{center}\\large#1\\end{center}\n    \\vskip0.5em}%\n\n}\n\\usepackage{hyperref}\n\\hypersetup{\ncolorlinks=true,\nlinkcolor=blue,\nfilecolor=magenta,      \nurlcolor=blue,\ncitecolor=blue,\n}\n\n\\urlstyle{same}\n\n\n\\title{Lecture VI Notes}\n\\date{June 23, 2020}\n\\author{Michael Brodskiy\\\\ \\small Professor: V. Cherkassky}\n\n% Mathematical Operations:\n\n% Sum: $$\\sum_{n=a}^{b} f(x) $$\n% Integral: $$\\int_{lower}^{upper} f(x) dx$$\n% Limit: $$\\lim_{x\\to\\infty} f(x)$$\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Arc Length and Curvature of Three Dimensional Functions $-$ 13.3}\n\nAs the arc length of a two dimensional function is defined by: $\\int_{a}^{b} \\sqrt{f'(t)^2 + g'(t)^2} dt$, the arc length of a three dimensional function is defined by: $\\int_{a}^{b} \\sqrt{f'(t)^2 + g'(t)^2 + h'(t)^2} dt$, or more simply: $\\int_{a}^{b} |\\overrightarrow{r}'(t)|dt$\\\\\n\nThe curvature, $\\kappa$, of a vector function may be found using the formula: $\\kappa(t)=\\frac{|\\overrightarrow{r}'(t)\\text{ x } \\overrightarrow{r}''(t)|}{|\\overrightarrow{r}'(t)|^3}$\n\n\\end{document}\n", "meta": {"hexsha": "8febb2f6a54951a9b9bbe53b6d419cb3e740f67b", "size": 1990, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture Notes/Lecture6.tex", "max_stars_repo_name": "MDBrodskiy/Vector_Calculus", "max_stars_repo_head_hexsha": "d4820f31c0c585ae65e6d61249d8c725077005eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-15T15:51:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-15T15:51:52.000Z", "max_issues_repo_path": "Lecture Notes/Lecture6.tex", "max_issues_repo_name": "MDBrodskiy/Vector_Calculus", "max_issues_repo_head_hexsha": "d4820f31c0c585ae65e6d61249d8c725077005eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture Notes/Lecture6.tex", "max_forks_repo_name": "MDBrodskiy/Vector_Calculus", "max_forks_repo_head_hexsha": "d4820f31c0c585ae65e6d61249d8c725077005eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.0967741935, "max_line_length": 282, "alphanum_fraction": 0.5653266332, "num_tokens": 584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7201172033427885}}
{"text": "\\section{Logarithms}\n\n\\begin{frame}{Base of Logarithms}\n  \\begin{block}{Logarithm to different bases:}\n    \\begin{displaymath}\n      \\log_a n = \\dfrac{\\log_b n}{\\log_b a}\n      = \\log_b n \\cdot \\dfrac{1}{\\log_b a}\n    \\end{displaymath}\\\\[0.5em]\n    The only difference is a constant coefficient $\\frac{1}{\\log_b a}$\n  \\end{block}\n  \\textbf{Examples:}\n  \\begin{itemize}\n    \\item\n      \\begin{math}\n        \\log_2 4\n        = \\log_{10} 4 \\cdot \\frac{1}{\\log_2 10}\n        = 0.602 \\ldots \\cdot 3.322 \\ldots\n        = 2 ~{\\color{Mittel-Blau}\\checkmark}\n      \\end{math}\n    \\item\n      \\begin{math}\n        \\log_{10} 1000\n        = \\log_{\\mathrm{e}} 1000 \\cdot \\frac{1}{\\log_{\\mathrm{e}} 10}\n        = \\ln 1000 \\cdot \\frac{1}{\\ln 10}\n        = 3 ~{\\color{Mittel-Blau}\\checkmark}\n      \\end{math}\n  \\end{itemize}\n\\end{frame}\n\n%-------------------------------------------------------------------------------\n\n\\begin{frame}{Runtime Example}\n  \\textbf{Runtime of $n \\; \\log_2 n$:}\n  \\begin{itemize}\n    \\item<1- |handout:1>\n      Assume we have constants $\\color{MainA}C_1$ and $\\color{MainA}C_2$\n      with\n      \\begin{displaymath}\n        \\textcolor{MainA}{\n          C_1 \\cdot n \\cdot \\log_2 n \\leq T(n) \\leq C_2 \\cdot n \\cdot log_2 n\n          \\hspace{1.5em}\\text{for}~n \\geq 2\n        }\n      \\end{displaymath}\n    \\item<2- |handout:1>\n      $2\\, \\times$ elements\n      $\\Rightarrow$ only slightly larger than $2\\, \\times$ runtime\\\\\n      \\begin{itemize}\n        \\item<3- |handout:1>\n          $C = \\SI{1}{\\nano\\second}$\n          (1 simple instruction $\\approx \\SI{1}{\\nano\\second}$)\n        \\item<4- |handout:1>\n          $n = 2^{20}$ (1 million numbers = $\\SI{4}{\\mega\\byte}$\n          with $\\SI{4}{\\byte\\per number}$)\n          \\begin{itemize}\n            \\item\n              $C \\cdot n \\cdot log_2 n = \\SI{e-9}{\\second} \\cdot 2^{20} \\cdot 20\n              = \\SI{21.0}{\\milli\\second}$\n          \\end{itemize}\n        \\item<5- |handout:1>\n          $n = 2^{30}$ (1 billion numbers = $\\SI{4}{\\giga\\byte}$)\n          \\begin{itemize}\n            \\item\n              $C \\cdot n \\cdot log_2 n = \\SI{e-9}{\\second} \\cdot 2^{30} \\cdot 30\n              = \\SI{32}{\\second}$\n          \\end{itemize}\n      \\end{itemize}\n    \\item<6- |handout:1>\n      \\textbf{Runtime $n \\; \\log_2 n$ is nearly as good as linear!}\n  \\end{itemize}\n\\end{frame}\n", "meta": {"hexsha": "0fecc92c56cf899a8e4941cf760f618bbf677e0a", "size": 2331, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-2/Chapter/eng/090_Logarithm.tex", "max_stars_repo_name": "TobiOnline/AlgoDat", "max_stars_repo_head_hexsha": "565a9f03a9ed7ef354cb4f143959df77df89b726", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2016-12-16T17:42:34.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-26T11:07:16.000Z", "max_issues_repo_path": "Lecture-2/Chapter/eng/090_Logarithm.tex", "max_issues_repo_name": "TobiOnline/AlgoDat", "max_issues_repo_head_hexsha": "565a9f03a9ed7ef354cb4f143959df77df89b726", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2016-10-08T09:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-20T15:40:10.000Z", "max_forks_repo_path": "Lecture-2/Chapter/eng/090_Logarithm.tex", "max_forks_repo_name": "TobiOnline/AlgoDat", "max_forks_repo_head_hexsha": "565a9f03a9ed7ef354cb4f143959df77df89b726", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2016-10-07T11:55:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-05T08:36:38.000Z", "avg_line_length": 32.8309859155, "max_line_length": 80, "alphanum_fraction": 0.5122265122, "num_tokens": 846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7201171980708937}}
{"text": "\\chapter{Newtonian Gravity}\nIn \\name{Newton}ian physics we assume that we have absolute space and time\nthat can be described by the a set of numbers $x^1,x^2,x^3,t$.\nWe express the coordinates as functions of time.\n\\section{Forces}\nThe force $\\vec{F}_{AB}$, which a massive body $A$ with mass $m_A$ exerts on another massive body $B$ with mass $m_B$, is given by\n\\begin{equation}\n    \\vec{F}_{AB}=-m_B\\frac{G\\textsubscript{N}m_A}{r^2}\\vec{e}_r\\, ,\n\\end{equation}\nwhere $G\\textsubscript{N}$ denotes \\emph{\\name{Newton}'s constant},\nnumerically equal to $G\\textsubscript{N}\\approx \\unitfrac[6.673\\cdot 10^{-11}]{m^3}{kg\\,s}$.\nAlthough there is no need for $G\\textsubscript{N}$ to be constant over time,\nthere is evidence that the relative variation is less than $10^{-12}$ per year.\nThe force can be expressed in terms of \\emph{gravitational potential} $\\Phi$:\n\\begin{equation}\n    \\vec{F}_{AB}=-m_B\\nabla\\left(-\\frac{G\\textsubscript{N}m_A}{r}\\right)=:\n    -m_B\\nabla\\Phi(\\vec{r}_B)\\, .\n\\end{equation}\nGiven $N$ particles labeled by $n$, the total force $B$ experiences is\n\\begin{equation}\n    \\vec{F}_{B}=-\\sum_n \\vec{F}_{nB}\\, .\n\\end{equation}\nThe potential at $\\vec{r}$ is then easily found to be\n\\begin{equation}\n    \\Phi(\\vec{r})=-G\\textsubscript{N}\\sum_n\\frac{m_n}{|\\vec{r}-\\vec{r}_n|}\\, .\n\\end{equation}\nIn general, we assume a mass distribution $\\varrho(\\vec{r})$ and the sum is\nreplaced by an integral:\n\\begin{equation}\n    \\Phi(\\vec{r}) = -G\\textsubscript{N}\\int_{\\Reals^3}\\dif{\\vec{r}^{\\prime}}\n    \\frac{\\varrho(\\vec{r}^{\\prime})}{|\\vec{r}-\\vec{r}^{\\prime}|}\\,.\n\\end{equation}\n\\section{Comparison with electrostatics}\nThe classical theory of gravity bears a striking similarity to electrostatics.\nTo make this clearer, we introduce the gravitational field\n$\\vec{g}(\\vec{r}):= -\\nabla\\Phi(\\vec{r})$.\n\\begin{table}[htb]\n    \\caption{Comparison of electrostatics and \\name{Newton}ian gravity.}\n    \\begin{center}\n        \\begin{tabulars}{lll}\n            \\toprule\n            &\\name{Newton}ian Gravity&Electrostatics\\\\\n            \\midrule\n            Force&$\\displaystyle\\vec{F}=q\\frac{kQ}{r^2}\\vec{e}_r$&$\\vec{F}=m\\frac{G\\textsubscript{N}M}{r^2}\\vec{e}_r$\\\\\n            Potential\n            &$\\Phi\\textsubscript{el}(\\vec{r})=q\\frac{kQ}{r}$\n            &$\\Phi\\textsubscript{g}(\\vec{r})=m\\frac{G\\textsubscript{N}M}{r}$\\\\\n            Field\n            &$\\vec{E}(\\vec{r})=-\\nabla\\Phi\\textsubscript{el}(\\vec{r})$\n            &$\\vec{g}(\\vec{r})=-\\nabla\\Phi\\textsubscript{g}(\\vec{r})$\\\\\n            \\name{Laplace} equation\n            &$\\Delta\\Phi\\textsubscript{el}=-4\\pi k\\varrho\\textsubscript{el}(\\vec{r})$&\n            $\\Delta\\Phi\\textsubscript{g}=4\\pi\n            G\\textsubscript{N}\\varrho\\textsubscript{g}(\\vec{r})$\n            \\\\\n            \\bottomrule\n        \\end{tabulars}\n    \\end{center}\n\\end{table}\n\\begin{example}[Field of a spherical mass distribution]\nAssume we have a spherical mass distribution, i.e.\\ $\\varrho(\\vec{r})=\\varrho(r)$.\nBy symmetry considerations it follows, that the gravitational field can be\nexpressed by\n\\begin{equation}\n    \\vec{g}(\\vec{r})=g(r)\\vec{e}_r\\, .\n\\end{equation}\nWe integrate the divergence of the field over a ball $B$ of radius $r$\n\\begin{equation}\n    \\int_B\\dif{\\vec{r}}\\,\\nabla\\vec{g}=-\\int_B\\dif{\\vec{r}}\\, \\Delta\\Phi\n    = -4\\pi G\\textsubscript{N}\\int_B\\dif{\\vec{r}}\\,\\varrho(r)= -4\\pi\n    G\\textsubscript{N} M\\, ,\n\\end{equation}\nwhere $M$ is the mass enclosed in $B$. On the other hand we can use Gauss's theorem to deduce\n\\begin{equation}\n    \\int_B\\dif{\\vec{r}}\\,\\nabla\\vec{g}=\\oint_{\\partial B}\\dif{\\vec{A}}\\cdot\n    \\vec{g} = \\oint_{\\Omega}\\dif{\\Omega}\\, g(r)r^2=4\\pi r^2g(r)\\, .\n\\end{equation}\nTogether the gravitational field is given by\n\\begin{equation}\n    \\vec{g}(r)=-\\frac{G\\textsubscript{N}M}{r^2}\\vec{e}_{r}\\, .\n\\end{equation}\n\\end{example}\n% \\subsection{Inertial systems}\n% \\begin{definition}\n% An inertial system is a system in which force-free particles move with constant uniform velocity on straight lines.\n% \\end{definition}\n\\subsection*{Weak Equivalence Principle (WEP)}\n\\name{Newton}'s first law reads\n\\begin{equation}\n    \\vec{F}=m\\textsubscript{I} \\vec{\\ddot{x}} \\, ,\n\\end{equation}\nwhere $m\\textsubscript{I}$ is the inertial mass that works against the acceleration of the body.\nThe force which a body with ``active'' mass $m\\textsubscript{g,a}$ exerts on\nanother body with mass $m\\textsubscript{g,p}$ is given by \n\\begin{equation}\n    \\vec{F}=m\\textsubscript{g,p}\\frac{G\\textsubscript{N}m\\textsubscript{g,a}}{r^2}\\vec{e}_r \\, .\n\\end{equation}\n\\begin{figure}[hbtp!]\n\\centering\n \\includegraphics{NewtonForce.pdf}\n\\caption{}\n%TODO Caption\n\\end{figure}\n\nA priori, there is no reason to assume any relation between this masses.\nThe first question one might ask is whether the active and the passive mass are equal.\nSuppose we have two masses $A$ and $B$. Using \\name{Newton}'s first law, we\ncan explicitly write\n\\begin{align}\n    m^{B}_{\\text{I}}\\vec{\\ddot{x}}&=\\vec{F}_{AB}=-\n    m^{B}_{\\text{g,p}}\\frac{G\\textsubscript{N}m^{A}_{\\text{g,a}}}{r^2}\\vec{e}_r\n    \\, ,\\\\\n    m^{A}_{\\text{I}}\\vec{\\ddot{x}}&=\\vec{F}_{BA}=-\n    m^{A}_{\\text{g,p}}\\frac{G\\textsubscript{N}m^{B}_{\\text{g,a}}}{r^2}\\vec{e}_r\n    \\, .\n\\end{align}\nBy the third law $\\vec{F}_{AB}=-\\vec{F}_{BA}$ we have\n\\begin{equation}\n\\frac{m^{B}_{\\text{g,p}}}{m^{B}_{\\text{g,a}}}=\\frac{m^{B}_{\\text{g,p}}}{m^{B}_{\\text{g,a}}}\\,.\n\\end{equation}\nBy proper choice of mass units we can set this quotient to one so that \n\\begin{equation}\nm\\textsubscript{g,a}=m\\textsubscript{g,p}=:m\\textsubscript{g}\n\\end{equation}\nThe next question is weather the inertial mass equivalent to the gravitational\nmass.\nBy \\name{Newton}'s first law we have\n\\begin{equation}\nm\\textsubscript{I}\\vec{\\ddot{x}}\n=-m_{\\text{g}}\\frac{G\\textsubscript{N}M_{\\text{g}}}{r^2}\\vec{e}_r \n=-m_{\\text{g}}\\vec{g}\\,.\n\\end{equation}\nAs a experimental result that has been measured up to a high accuracy (compare\ntabular~\\ref{tab:WEPExp}) all bodys recive the same acceleration due to gravity\n$\\ddot{\\vec{x}}\\sim \\vec{g}$. By a 'proper' choice of units of the flight-time $t=\\sqrt{\\frac{m\\textsubscript{I}}{m\\textsubscript{g}}}\\sqrt{\\frac{2h}{g}}$,\nwe get\n\\begin{equation}\nm\\textsubscript{I}=m\\textsubscript{g}=:m\\,.\n\\end{equation}\n\\begin{table}\n\\centering\n\\begin{tabulars}{rllr}\n\\toprule\nYear&Experimenter&Experiment&Accuracy\\\\\n\\midrule\n1636&\\name{Galilei}&inclined planes&$10^{-2}$\\\\\n1689&\\name{Newton}&pendulum&$10^{-3}$\\\\\n1832&\\name{Bessel}&pendulum&$10^{-5}$\\\\\n1922&\\name{Eötvös}&pendulum&$10^{-9}$\\\\\n1922&\\name{Shapro} et al.&pendulum&$10^{-12}$\\\\\n1999&\\name{Baesler}&torsion balance&$10^{-14}$\\\\\n\\bottomrule\n\\end{tabulars}\n\\caption{Experiments measuring the ratio\n$\\frac{m\\textsubscript{I}}{m\\textsubscript{g}}$.\\label{tab:WEPExp}}\n\\end{table}\n\\subsection{Tidal Forces}\nAssume we have a body of finite extension in a gravitational\npotential $\\Phi$, an example being the earth in the potential of the moon.\nOn the center of the body we have \n\\begin{equation}\nm \\dod[2]{\\tensor{x}{^i}}{t}=-\\dpd{\\Phi}{\\tensor{x}{_i}}\\,.\n\\end{equation}\nIf we consider a point shifted by $\\tensor{\\chi}{^i}$ from the center then the\nacceleration is given as\n\\begin{equation}\n\\begin{split}\nm \\dod[2]{}{t}\\left(\\tensor{x}{^i}+\\tensor{\\chi}{^i}\\right)\n&=-\\dpd{\\Phi\\left(\\tensor{x}{^i}+\\tensor{\\chi}{^i}\\right)}{\\tensor{x}{_i}}\\\\\n&\\simeq-\\dpd{\\Phi\\left(\\tensor{x}{^i}\\right)}{\\tensor{x}{_i}}\n-\\dmd{\\Phi\\left(\\tensor{x}{^i}\\right)}{2}{\\tensor{x}{_i}}{}{\\tensor{x}{_j}}{}\\tensor{\\chi}{^j}\\,.\n\\end{split}\n\\end{equation}\nSubtracting the previous equations yields the tidal force\n\\begin{equation}\nm \\dod[2]{\\tensor{\\chi}{^i}}{t}=-\\dmd{\\Phi\\left(\\tensor{x}{^i}\\right)}{2}{\\tensor{x}{_i}}{}{\\tensor{x}{_j}}{}\\tensor{\\chi}{^j}\\,.\n\\end{equation}\nThe tidal force tensor $\\dmd{\\Phi}{2}{\\tensor{x}{_i}}{}{\\tensor{x}{_j}}{}$ is of\nthe form\n\\begin{equation}\n\\dmd{\\Phi}{2}{\\tensor{x}{_i}}{}{\\tensor{x}{_j}}{}\n=\\frac{G\\textsubscript{N}M}{r^3}\\left(\\tensor{\\delta}{_i_j}-3\\frac{\\tensor{x}{_i}\\tensor{x}{_j}}{r^2}\\right)\\,.\n\\end{equation}\n%TODO newtons laws?\n%TODO picture", "meta": {"hexsha": "46f7a657678d67b0c65635c1bfd8f04998e7d8ea", "size": 8025, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/01-newtonian-gravity.tex", "max_stars_repo_name": "Bigben37/GeneralRelativity", "max_stars_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-31T13:18:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-31T13:18:57.000Z", "max_issues_repo_path": "src/01-newtonian-gravity.tex", "max_issues_repo_name": "QuantumDancer/GeneralRelativity", "max_issues_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/01-newtonian-gravity.tex", "max_forks_repo_name": "QuantumDancer/GeneralRelativity", "max_forks_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.3783783784, "max_line_length": 155, "alphanum_fraction": 0.6657943925, "num_tokens": 2949, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637541053281, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7200715274196281}}
{"text": "\\section{Relative Hurewicz and J.~H.~C.~Whitehead}\nHere is an ``alternative definition'' of connectedness:\n\\begin{definition}\n    Let $n\\geq 0$.\n    The space $X$ is said to be \\emph{$(n-1)$-connected} if, for all $0\\leq k\\leq n$, any map $f:S^{k-1}\\to X$ extends:\n    \\begin{equation*}\n\t\\xymatrix{\n\tS^{k-1}\\ar[d]\\ar[r] & X\\\\\n\tD^k\\ar@{-->}[ur]_\\exists & \n\t}\n    \\end{equation*}\n\\end{definition}\nWhen $n=0$, we know that $S^{-1} = \\emptyset$, and $D^0 = \\ast$.\nThus being $(-1)$-connected is equivalent to being nonempty.\nWhen $n=1$, this is equivalent to path connectedness. You can check that this is exactly the same as what we said before, using homotopy groups.\n\nAs is usual in homotopy theory, there is a relative version of this definition.\n\\begin{definition}\n    Let $n\\geq 0$. Say that a pair $(X,A)$ is \\emph{$n$-connected} if, for all $0\\leq k\\leq n$, any map $f:(D^k,S^{k-1}) \\to (X,A)$ extends:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    (D^k,S^{k-1})\\ar[r]^f\\ar@{-->}[d] & (X,A)\\\\\n\t    (A,A)\\ar[ur] & \n\t    }\n    \\end{equation*}\n    up to homotopy.\n    In other words, there is a homotopy between $f$ and a map with image in $A$, such that $f|_{S^{k-1}}$ remains unchanged.\n\\end{definition}\n$0$-connectedness implies that $A$ meets every path component of $X$.\nEquivalently:\n    \\begin{definition}\n\t$(X,A)$ is $n$-connected if:\n\t\\begin{itemize}\n\t    \\item when $n=0$, the map $\\pi_0(A)\\to \\pi_0(X)$ surjects.\n\t    \\item when $n>0$, the canonical map $\\pi_0(A)\\xrightarrow{\\simeq}\\pi_0(X)$ is an isomorphism,\n\t\tand for all $a\\in A$, the group $\\pi_k(X,A,a)$ vanishes for $1\\leq k\\leq n$.\n\t\t(Equivalently, $\\pi_0(A)\\xrightarrow{\\simeq}\\pi_0(X)$ and $\\pi_k(A,a)\\to\\pi_k(X,A)$ is an isomorphism for $1\\leq k<n$ and is onto for $k=n$.)\n\t\\end{itemize}\n    \\end{definition}\n\\subsection{The relative Hurewicz theorem}\n    Assume that $\\pi_0(A) = \\ast = \\pi_0(X)$, and pick $a\\in A$.\n    Then, we have a comparison of long exact sequences, arising from the classical (i.e., non-relative) Hurewicz map:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    \\cdots\\ar[r] & \\pi_1(A)\\ar[r]\\ar[d]^h & \\pi_1(X)\\ar[r]\\ar[d]^h & \\pi_1(X,A)\\ar[r]\\ar[d]^h & \\pi_0(A)\\ar[r]\\ar[d]^h & \\pi_0(X)\\ar[d]^h & \\\\\n\t    \\cdots\\ar[r] & H_1(A)\\ar[r] & H_1(X)\\ar[r] & H_1(X,A)\\ar[r] & H_0(A)\\ar[r] & H_0(X)\\ar[r] & H_0(X,A)\n\t    }\n    \\end{equation*}\nTo define the relative Hurewicz map, let $\\alpha\\in \\pi_n(X,A)$, so that $\\alpha:(D^n,S^{n-1})\\to (X,A)$;\npick a generator of $H_n(D^n,S^{n-1})$, and send it to an element of $H_n(X,A)$ via the induced map\n$\\alpha_\\ast:H_n(D^n,S^{n-1})\\to H_n(X,A)$.\n\nBecause $H_n(X,A)$ is abelian, the group $\\pi_1(A)$ acts trivially on $H_n(X,A)$; in other words,\n$h(\\omega(\\alpha)) = h(\\alpha)$.\nConsequently, the relative Hurewicz map factors through the group $\\pi_n^\\dagger(X,A)$, defined to be\nthe quotient of $\\pi_n(X,A)$ by the normal subgroup generated by $(\\omega\\alpha)\\alpha^{-1}$,\nwhere $\\omega\\in\\pi_1(A)$ and $\\alpha\\in \\pi_n(X,A)$.\nThis begets a map $\\pi_n^\\dagger(X,A)\\to H_n(X,A)$.\n\\begin{theorem}[Relative Hurewicz]\n    Let $n\\geq 1$, and assume $(X,A)$ is $n$-connected.\n    Then $H_k(X,A) = 0$ for $0\\leq k\\leq n$, and the map $\\pi_{n+1}^\\dagger(X,A)\\to H_{n+1}(X,A)$ constructed above\n    is an isomorphism.\n\\end{theorem}\nWe will prove this later using the Serre spectral sequence.\n\\subsection{The Whitehead theorems}\nJ.~H.~C.~Whitehead was a rather interesting character. He raised pigs.\n\nWhitehead was interested in determining when a continuous map $f:X\\to Y$ that is an isomorphism in homology or homotopy\nis a homotopy equivalence.\n\\begin{definition}\n    Let $f:X\\to Y$ and $n\\geq 0$. Say that $f$ is a \\emph{$n$-equivalence}\\footnote{Some sources sometimes use ``$n$-connected''.}\n    if, for every $\\ast\\in Y$, the homotopy fiber $F(f,\\ast)$ is $(n-1)$-connected.\n\\end{definition}\nFor instance, $f$ being a $0$-equivalence simply means that $\\pi_0(X)$ surjects onto $\\pi_0(Y)$ via $f$.\nFor $n>0$, this says that $f:\\pi_0(X)\\to \\pi_0(Y)$ is a bijection, and that for every $\\ast\\in X$:\n\\begin{equation*}\n    \\pi_k(X,\\ast)\\to\\pi_k(Y,f(\\ast)) \\text{ is }\\begin{cases}\n\t\\text{an isomorphism } & 1\\leq k<n\\\\\n\t\\text{onto } & k = n.\n    \\end{cases}\n\\end{equation*}\nUsing the ``mapping cylinder'' construction (see Exercise \\ref{cofibrep}), we can always assume $f:X\\to Y$ is a cofibration;\nin particular, that $X\\hookrightarrow Y$ is a closed inclusion.\nThen, $f:X\\to Y$ is an $n$-equivalence if and only if $(Y,X)$ is $n$-connected.\n\\begin{theorem}[Whitehead]\n    Suppose $n\\geq 0$, and $f:X\\to Y$ is $n$-connected. Then:\n    \\begin{equation*}\n\tH_k(X)\\xar{f} H_k(Y) \\text{ is }\\begin{cases}\n\t    \\text{an isomorphism } & 1\\leq k<n\\\\\n\t    \\text{onto } & k = n.\n\t\\end{cases}\n    \\end{equation*}\n\\end{theorem}\n\\begin{proof}\n    When $n=0$, because $\\pi_0(X)\\to \\pi_0(Y)$ is surjective, we learn that\n    $H_0(X)\\simeq \\Z[\\pi_0(X)]\\to \\Z[\\pi_0(Y)]\\simeq H_0(Y)$ is surjective.\n    To conclude, use the relative Hurewicz theorem.\n    (Note that the relative Hurewicz dealt with $\\pi_n^\\dagger(X,A)$, but the map $\\pi_n(X,A)\\to\\pi_n^\\dagger(X,A)$ is surjective.)\n\\end{proof}\nThe case $n=\\infty$ is special.\n\\begin{definition}\n    $f$ is a \\emph{weak equivalence} (or an $\\infty$-equivalence, to make it sound more impressive) if it's an $n$-equivalence for all $n$, i.e., it's a $\\pi_\\ast$-isomorphism.\n\\end{definition}\nPutting everything together, we obtain:\n\\begin{corollary}\n    A weak equivalence induces an isomorphism in integral homology.\n\\end{corollary}\nHow about the converse?\n\nIf $H_0(X)\\to H_0(Y)$ surjects, then the map $\\pi_0(X)\\to \\pi_0(Y)$ also surjects.\nNow, assume $X$ and $Y$ path connected,  and that $H_1(X)$ surjects onto $H_1(Y)$.\nWe would like to conclude that $\\pi_1(X)\\to\\pi_1(Y)$ surjects.\nUnfortunately, this is hard, because $H_1(X)$ is the abelianization of $\\pi_1(X)$.\nTo forge onward, we will simply give up, and assume that $\\pi_1(X)\\to \\pi_1(Y)$ is surjective.\n\nSuppose $H_2(X)\\to H_2(Y)$ surjects, and that $f_\\ast:H_1(X)\\xrightarrow{\\simeq}H_1(Y)$.\nWe know that $H_2(Y,X) = 0$.\nOn the level of the Hurewicz maps, we are still stuck, because we only obtain information about $\\pi_2^\\dagger$.\nLet us assume that $\\pi_1(X)$ is trivial\\footnote{This is a pretty radical assumption; for the following argument to work,\nit would technically be enough to ask that $\\pi_1(X)$ acts trivially on $\\pi_2(Y,X)$: but this is basically impossible to check.}.\nUnder this assumption, we find that $\\pi_1(Y) = 0$.\nThis implies $\\pi_2(Y,X)$ is trivial.\nArguing similarly, we can go up the ladder.\n\\begin{theorem}[Whitehead]\n    Let $n\\geq 2$, and assume that $\\pi_1(X) = 0 = \\pi_1(Y)$.\n    Suppose $f:X\\to Y$ such that:\n    \\begin{equation*}\n\tH_k(X)\\to H_k(Y) \\text{ is }\\begin{cases}\n\t    \\text{an isomorphism } & 1\\leq k<n\\\\\n\t    \\text{onto } & k = n;\n\t\\end{cases}\n    \\end{equation*}\n    then $f$ is an $n$-equivalence.\n\\end{theorem}\nSetting $n=\\infty$, we obtain:\n\\begin{corollary}\n    Let $X$ and $Y$ be simply-connected.\n    If $f$ induces an isomorphism in homology, then $f$ is a weak equivalence.\n\\end{corollary}\nThis is incredibly useful, since homology is actually computable!\nTo wrap up the story, we will state the following result, which we will prove in a later section.\n\\begin{theorem}\\label{weakhtpyequiv}\n    Let $Y$ be a CW-complex.\n    Then a weak equivalence $f:X\\to Y$ is in fact a homotopy equivalence.\n\\end{theorem}\n", "meta": {"hexsha": "e39fe57762fd9ca5698af0e6baa28a8af09b4a2b", "size": 7371, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-49-relative-hurewicz.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "906/lec-49-relative-hurewicz.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "906/lec-49-relative-hurewicz.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 50.4863013699, "max_line_length": 176, "alphanum_fraction": 0.6606973274, "num_tokens": 2647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8757869867849166, "lm_q1q2_score": 0.7200625411871294}}
{"text": "%!TEX root = Calculus_I.tex\n\\chapter{A Library of Functions}\n\\section{Functions and Change}\n\n\\textbf{\\textit{function}} -- An item used to represent the dependence of one quantity upon another. $f(x)$ means $f$ is a function of $x$.\n\n\\textbf{\\textit{domain}} -- The input values of a function ($x$ part of $f(x)$). Also referred to as the \\textbf{\\textit{independent variable}}.\n\n\\textbf{\\textit{range}} -- The output values of a function ($y$ part of $y = f(x)$). Also referred to as the \\textit{dependent variable} because it depends on $x$.\n\\vspace{0.1in}\nSome variables assume discrete values, while others are continuous. Some examples of discrete variables are listed below.\n\\begin{enumerate}\n\\item Date\\\\\n\\vspace{-0.25in}\n\\item Cost\\\\\n\\vspace{-0.25in}\n\\item Number of ...\n\\end{enumerate}\n\nNote that some quantities, such as ``Date\" in the above list, are discretized values from a continuous variable, time. Measurement of a continuous variable results in a set of discrete values.\n\n\\vspace{0.1in}\nDomain and Range values are often written using \\textbf{\\textit{Interval Notation}}. This notation is used to describe the extrema of a set of numbers. The following cases are used to describe numeric sets using this notation:\n\n\\begin{equation}\na \\leq x \\leq b = [a, b]\n\\end{equation}\n\n\\begin{equation}\na \\leq x < b = [a, b)\n\\end{equation}\n\n\\begin{equation}\na < x \\leq b = (a, b]\n\\end{equation}\n\n\\begin{equation}\na < x < b = (a, b)\n\\end{equation}\n \n\\vspace{0.1in}\nIf the domain is not specified, it is usually assumed to be the the set of real numbers, that is $x \\in \\mathbb{R}$.\n\n\\vspace{0.25in}\n\\textbf{\\textit{Linear Function}} -- A function is linear if the \\textbf{\\textit{slope}}, or rate of change of the function, is constant.\n\\textbf{\\textit{slope}} -- The rate that the dependent variable changes with respect to the independent variable.\n\n\\vspace{0.1in}\nWith this, certain assumptions about the function hold:\n\\begin{enumerate}\n\\item The Principle of Superposition applies\\\\\n\\vspace{-0.25in}\n\\item Highest degree of function is 1\\\\\n\\end{enumerate}\n\n\\vspace{0.1in}\nThe Greek letter $\\bm{\\Delta}$ is used to indicate ``change in\" a particular variable; thus, $\\bm{\\Delta} x$ means ``Change in $x$.\" This is commonly used to express the \\textbf{\\textit{slope}} of a function, $m$:\n\\begin{equation}\nm = \\frac{Rise}{Run} = \\frac{\\Delta y}{\\Delta x} = \\frac{f\\left(x_2\\right) - f\\left(x_1\\right)}{x_2 - x_1}\n\\end{equation}\n\n\\vspace{0.1in}\nIf the magnitude of $f(x)$ increases as $x$ increases, then $f(x)$ is classified as an \\textbf{\\textit{Increasing Function}}. Contrarily, if the magnitude of $f(x)$ decreases as $x$ increases, then $f(x)$ is classified as a \\textbf{\\textit{Decreasing Function}}. If this is true $\\forall x$ (for all values of $x$), then the function can also be classified as \\textbf{\\textit{monotonic}}.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Exponential Functions}\n\\textbf{\\textit{Exponential Functions}} are a class of functions that can be described by:\n\\begin{equation}\nP = P_0 a^t\n\\end{equation}\nwhere $P_0$ is some initial quantity (value at $t=0$), and $a$ is the factor by which $P$ changes when $t$ is increased by 1. If $a > 1$, then exponential growth occurs. If $0 < a < 1$, then exponential decay is present. These functions can also be described by their concavity. If the ``opening\" of the function points toward the positive $Y$-axis, then the function is \\textbf{\\textit{concave up}}. Similarly, if it points toward the negative $Y$-axis, then the function is \\textbf{\\textit{concave down}}.\n\n\\vspace{0.1in}\n\\textbf{\\textit{Half-Life}} -- The time required for an exponentially decaying quantity to reach 50\\% of the initial value, $P_0$.\n\n\\textbf{\\textit{Doubling Time}} -- The time required for an exponentially growing quantity to reach 200\\% of the initial value, $P_0$.\n\n\\vspace{0.1in}\nSome exponential functions use the natural number, $e \\approx 2.71828$ as the base of the exponential quantity. Because this ensures the base is positive, then exponential growth may also occur when:\n\\begin{equation}\nP = P_0 e^{kt}\n\\end{equation}\nand exponential decay may occur when:\n\\begin{equation}\nP = P_0 e^{-kt}\n\\end{equation}\nThis is true if $k>0$ and $t > 0$.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{New Functions from Old}\n\\textbf{\\textit{Translations}} of functions occur though additive operations. \\textbf{\\textit{Stretches}} occur when a function is multiplied by a factor, $k$, when $k$ is not 0 or 1. \\textbf{\\textit{Reflections}} occur when a function is multiplied by a factor, $k$, when $k < 0$.\n\n\\vspace{0.1in}\n\\textbf{\\textit{Composite Functions}} are functions that depend on quantities that can be described by other functions. The example given in the text is the following:\n\\begin{align}\n\\nonumber\nA = f(&r) = \\pi r^2\\\\\n\\nonumber\nr = g(t&) = 1+t\\\\\n\\nonumber\n A = \\pi r^2 &= \\pi \\left(1 + t\\right)^2\\\\\n\\nonumber\nA = f\\left(g\\left(t\\right)\\right) = \\pi &\\left(g\\left(t\\right)\\right)^2 = \\pi \\left(1 + t\\right)^2\n\\end{align}\nHere, the area of a circle, which is mathematically defined by $\\pi r^2$, is used as the \\textit{outside function}. $r\\left(t\\right)$ is the \\textit{inside function} describes the radius as a \\textbf{\\textit{monotonically increasing}} quantity with time. Therefore, the area can also be described in terms of time using the definition of the \\textbf{\\textit{composite function}}.\n\n\\vspace{0.1in}\nA function can be classified as \\textbf{\\textit{even}} or \\textbf{\\textit{odd}} if it is symmetrical about the $Y$-axis. \\textbf{\\textit{Even}} functions have the property of:\n\\begin{equation}\nf(-x) = f(x)\\hphantom{-} \\forall x\n\\end{equation}\nAn example of this type of function is $\\cos\\left(x\\right)$. On the other hand, \\textbf{\\textit{odd}} functions follow:\n\\begin{equation}\nf(-x) =- f(x)\\hphantom{-} \\forall x\n\\end{equation}\nAn example of this type of function is  $\\sin\\left(x\\right)$. Many functions are neither \\textbf{\\textit{even}} nor \\textbf{\\textit{odd}}.\n\n\\vspace{0.1in}\nFor a given function $f(x)$, the inverse of the function, $f^{-1}(x)$, is given by:\n\\begin{equation}\nf^{-1}(y) = x\\hphantom{-} ==\\hphantom{-} y = f(x)\n\\end{equation}\nNot all functions are invertible. For this to be true, $f(x)$ must be \\textit{single-valued}, or each $y$ value uniquely corresponds to one $x$ value. More specifically, a function has an inverse if, and only if, it intersects any horizontal line at most once. Thus, lines of constant $y$ values cannot correspond to multiple $x$ values for the inverse to exist.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Logarithmic Functions}\n\\textbf{\\textit{Logarithmic Functions}} are the inverse of an exponential function, provided both functions share a common base. These functions are written out as:\n\\begin{equation}\n\\log_{10}x = k \\hphantom{-} == \\hphantom{-} 10^k = x\n\\end{equation}\nwhere $k$ is a real number. Here, 10 is the common base of the logarithmic and exponential functions. The \\textbf{\\textit{Natural Logarithm}} uses the natural number, $e$, as its base. It is written as:\n\\begin{equation}\n\\ln x = k \\hphantom{-} == \\hphantom{-} e^c = x\n\\end{equation}\nIn logarithmic functions, $x > 0$ because no power of a real number results in zero, and negative values of $x$ are infeasible for positive bases with real exponents.\n\n\\vspace{0.1in}\nThe following table outlines the properties of \\textbf{\\textit{logarithmic functions}}:\n\\begin{table*}[h]\n\\begin{center}\n\\begin{tabular}{lll}\n& \\textbf{Base} $A$ & \\textbf{Natural Logarithm}\\\\\n\\hline\n1. & $\\log\\left(AB\\right) = \\log A + \\log B$ & $\\ln\\left(AB\\right) = \\ln A + \\ln B$\\\\\n2. &  $\\log\\left(\\frac{A}{B}\\right) = \\log A - \\log B$ & $\\ln\\left(\\frac{A}{B}\\right) = \\ln A - \\ln B$\\\\\n3. & $\\log\\left(A^p\\right) = p \\log A$ & $\\ln \\left(A^p\\right) = p \\ln A$\\\\\n4. & $\\log_A\\left(A^x\\right) = x$ & $\\ln e^x = x$\\\\\n5. & $10^{\\log x} = x$ & $e^{\\ln x} = x$\n\\end{tabular}\n\\end{center}\n\\end{table*}\n\nThese types of equations are useful when solving for unknown exponents.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Trigonometric Functions}\nThe input of the basic trigonometric functions, $\\sin$, $\\cos$, and $\\tan$ are angles, which are measured in \\textbf{\\textit{radians}} or \\textbf{\\textit{degrees}}. To convert between the two, this relationship is used:\n\\begin{equation}\n1 \\hphantom{-} \\text{radian} = \\frac{\\pi}{180} \\hphantom{-} \\text{degrees}\n\\end{equation}\nThe angle of 1 \\textbf{\\textit{radian}} on a unit circle has an arc length of 1. Often, if no units are prescribed for an angular measurement, it is understood to be in \\textit{\\textbf{radians}}. The arclength equation is given by:\n\\begin{equation}\ns = r\\theta\n\\end{equation}\nwhere $s$ is the arc length, $r$ is the radius of the circle, and $\\theta$ is the angular measurement in radians. If a point $P$ on a circle has coordinates in an $(x, y)$ coordinate frame, then we can use the trigonometric functions to relate it's position with the angle $\\theta$ by:\n\\begin{align}\n\\cos\\theta &= x\\\\\n\\sin\\theta &= y\n\\end{align}\nBecause the equation of a circle is given by:\n\\begin{equation}\nx^2 + y^2 = r^2\n\\end{equation}\na substitution using the trigonometric functions can be made:\n\\begin{equation}\n\\cos^2 \\theta + \\sin^2 \\theta = r^2\n\\end{equation}\nFor a unit circle, which as a radius $r = 1$, this reduces to the trigonometric identity:\n\\begin{equation}\n\\cos^2 \\theta + \\sin^2 \\theta = 1\n\\end{equation}\nAs $\\theta$ increases, the values of $\\sin\\theta$ and $\\cos\\theta$ oscillate between $\\left[-1, 1\\right]$, and repeats every $2\\pi$ \\textbf{\\textit{radians}} or $360^\\circ$. Thus, $\\sin \\theta$ and $\\cos \\theta$ are \\textit{periodic functions}, or functions that repeat their values after a regular interval.\n\n\\vspace{0.1in}\nThe \\textbf{\\textit{period}} of a \\textit{periodic function} is the length of that regular interval. The \\textbf{\\textit{amplitude}} of the function is $\\frac{1}{2}$ the distance between the function's maximum and minimum values. It should be noted that the $\\sin$ and $\\cos$ functions can be related through a \\textbf{\\textit{phase shift}}, or angular \\textbf{\\textit{translation}}:\n\\begin{equation}\n\\cos \\theta = \\sin\\left(\\theta + \\frac{\\pi}{2}\\right)\n\\end{equation}\nFunctions whose shape can be described using $\\sin\\theta$ and $\\cos\\theta$ are given the name \\textbf{\\textit{sinusoidal functions}}. To summarize their properties:\n\\begin{equation}\nf(\\theta) = A\\sin\\left(B\\theta\\right) \\hphantom{-} g(\\theta) = A \\cos\\left(B\\theta\\right)\n\\end{equation}\nwhere $|A|$ is the \\textbf{\\textit{amplitude}}, $\\frac{2\\pi}{|B|}$ is the period. Horizontal \\textbf{\\textit{translations}} occur when the argument $B\\theta$ is replaced by $B\\theta \\pm h$. Vertical \\textbf{\\textit{translations}} occur when a constant $C$ is added to the functions:\n\\begin{equation}\nf(\\theta) = A\\sin\\left(B\\theta\\right) + C \\hphantom{-} g(\\theta) = A \\cos\\left(B\\theta\\right) + C\n\\end{equation}\nThe \\textit{tangent function} is used as a relationship between \\textit{sine} and \\textit{cosine} functions. It is defined as:\n\\begin{equation}\n\\tan\\theta=\\frac{\\sin\\theta}{\\cos\\theta}\n\\end{equation}\nThis function has vertical \\textit{asymptotes} at points where $\\cos\\theta = 0$, or $\\forall \\theta$ defined as $\\pm \\frac{(2n-1)\\pi}{2}$, where $n \\in \\mathbb{N}$, or the set of \\textit{Natural Numbers}. The $\\tan$ function has a period of $\\pi$ \\textbf{\\textit{radians}}.\n\n\\vspace{0.1in}\nTrigonometric functions also have \\textbf{\\textit{inverse functions}}. These are used to find an angular value given the $(x,y)$ coordinates of a point:\n\\begin{equation}\n\\sin x = 0.45\n\\end{equation}\nFor the inverse $\\sin$ function, which is commonly written as $\\arcsin\\theta$, $\\text{a}\\sin\\theta$ or $\\sin^{-1}\\theta$, a domain of $\\left[-\\frac{\\pi}{2}, \\frac{\\pi}{2}\\right]$ is used. Thus, for $y \\in \\left[-1, 1\\right]$:\n\\begin{equation}\n\\arcsin y = x \\hphantom{-} == \\hphantom{-} \\sin x = y, \\hphantom{-} x\\in \\left[-\\frac{\\pi}{2}, \\frac{\\pi}{2}\\right]\n\\end{equation}\nFor the inverse $\\cos$ function, which is commonly written as $\\arccos\\theta$, $\\text{a}\\cos\\theta$ or $\\cos^{-1}\\theta$, the domain is also $\\left[-\\frac{\\pi}{2}, \\frac{\\pi}{2}\\right]$, but the range is $x \\in \\left[0, \\pi\\right]$. Lastly, for the inverse $\\tan$ function, commonly written as $\\arctan\\theta$, $\\text{a}\\tan\\theta$ or $\\tan^{-1}\\theta$, a domain of $\\left[-\\frac{\\pi}{2}, \\frac{\\pi}{2}\\right]$ is used, but has a range $y \\in \\mathbb{R}$.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Powers, Polynomials, and Rational\\\\Functions}\nA \\textbf{\\textit{power function}} is a function $f(x)$ where the \\textbf{\\textit{dependent variable}}, $y$ is proportional to a power of the \\textbf{\\textit{independent variable}}, $x$:\n\\begin{equation}\nf(x) = kx^p\n\\end{equation}\nwhere $k$ and $p$ are constant. Examples of these functions are the volume of a sphere:\n\\begin{equation}\nV = \\frac{4}{3}\\pi r^3\n\\end{equation}\nor Newton's Law of Gravitation:\n\\begin{equation}\nF = kr^{-2} = \\frac{k}{r^2}\n\\end{equation}\nFor functions of the form $x^n$, where $n$ is a positive integer, odd values of $n>1$ pass through the origin and can assume negative values these are \\textbf{\\textit{monotonically increasing functions}}. Even values of $n > 1$ also pass through the origin, but $\\forall x < 0$, $f(x)$ is a \\textbf{\\textit{decreasing}} function, and $\\forall x > 0$, $f(x)$ is \\textbf{\\textit{increasing}}. For large exponents $n$, the function value grows faster. Though \\textbf{\\textit{power functions}} may equal values greater than some arbitrary \\textbf{\\textit{exponential funtion}}, \\textit{every} \\textbf{\\textit{exponential function}} will eventually dominate \\textit{every} \\textbf{\\textit{power function}} at some value of $x$ if the base of the \\textbf{\\textit{exponential function}}, $a$, is greater than 1.\n\n\\vspace{0.1in}\n\\textbf{\\textit{Polynomials}} are the sum of \\textbf{\\textit{power functions}} with non-negative integer exponents:\n\\begin{equation}\ny = p(x) = a_nx^n + a_{n-1} x^{n-1} + ... + a_1 x + a_0\n\\end{equation}\nThe highest exponent $n$ in a \\textbf{\\textit{polynomial}} is referred to as the\\textbf{\\textit{degree}} of the polynomial.\n\n\\vspace{0.1in}\n\\textbf{\\textit{Rational Functions}} are ratios of \\textbf{\\textit{polynomials}}, $p(x)$ and $q(x)$:\n\\begin{equation}\nf(x) = \\frac{p(x)}{q(x)}\n\\end{equation}\nThese functions may have \\textbf{\\textit{horizontal or vertical asymptotes}} which occur when:\n\\begin{equation}\nf(x) \\rightarrow L \\hphantom{-} \\text{as} \\hphantom{-} x \\rightarrow \\pm \\infty\n\\end{equation}\nfor \\textbf{\\textit{horizontal asymptotes}} or\n\\begin{equation}\ny \\rightarrow \\pm \\infty \\hphantom{-} \\text{as} \\hphantom{-} x \\rightarrow K\n\\end{equation}\nfor \\textbf{\\textit{vertical asymptotes}}. Here, the horizontal asymptote is $y = L$, and the \\textbf{\\textit{vertical asymptote}} is $x = K$.\nThe function behavior as $x \\rightarrow \\pm \\infty$ is referred to as \\textbf{\\textit{end behavior}}.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Introduction to Continuity}\nThis section focuses on the idea of \\textbf{\\textit{continuity}} along an interval, $[a, b]$, and at a point, $p$. \\textbf{\\textit{Continuous Functions}} have many desirable properties. For functions along an interval, a general rule of continuity is that a function is continuous along an interval $[a, b]$ if it has no breaks, jumps, or holes within that interval. Many functions are not continuous $\\forall x$, such as $\\frac{1}{x}$ , which is undefined at $x = 0$, but is continuous for any interval $[a, b]$ that does not contain 0. \\textbf{\\textit{Exponential}}, \\textbf{\\textit{power}}, and the \\textit{sine} and \\textit{cosine} functions are continuous along any interval $[a, b]$. \\textbf{\\textit{Rational functions}} are continuous on any interval that the denominator is non-zero. Functions derived via addition or multiplication of other continuous functions, and \\textbf{\\textit{composite functions}} are continuous if the functions used to create them are continuous.\n\n\\vspace{0.1in}\n\\textbf{\\textit{Intermediate Value Theorem}} -- Assume $f(x)$ is continuous on a closed interval $[a, b]$. If $k$ is any number between $f(a)$ and $f(b)$, then $\\exists$ at least one number $c \\in [a, b]$ such that $f(c) = k$.\n\n\\vspace{0.1in}\nA function is continuous if nearby values of the independent variable, $x$, give nearby values of the dependent variable, $y$. Continuity is important because it implies that small perturbations in $x$ do not result in large changes in $y$. To check continuity at a point, for example, $x = 2$, check nearby values to the left and right of that point, $x = 1.99, 1.98$ and $x = 2.01, 2.02$. If $f(x)$ changes significantly, then the function has a discontinuity at $x =2$.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Limits}\nThe idea of the \\textbf{\\textit{limit}} is fundamental to the study of Calculus. The \\textbf{\\textit{limit}} makes sense of a function ``approaching\" a value. Limit notation is defined as:\n\\begin{equation}\n\\lim_{x \\rightarrow c} f(x) = L\n\\end{equation}\nwhich means the function $f(x)$ approaches the value $L$ as the independent variable, $x$ approaches the value $c$. $x$ is never equals $c$, but is infinitesimally close to it.\n\n\\vspace{0.1in}\nA function $f$ is defined on an interval around $c$, except at the point $x = c$. The \\textbf{\\textit{limit}} of the function $f(x)$ as $x$ approaches $c$ is equal to a number $L$, should such a limit exist, such that $f(x)$ is as close to $L$ as we want whenever $x$ is sufficiently close to $c$. The distance between $f(x)$ and $L$ is given by:\n\\begin{equation}\n\\text{Distance} = |f(x) - L|\n\\end{equation}\nwhich we want to be sufficiently close. The Greek letter $\\epsilon$ is used to refer to small numbers; thus, we want:\n\\begin{equation}\n|f(x) - L| < \\epsilon\n\\end{equation}\nto show limit convergence. Similarly, we want the following to be true:\n\\begin{equation}\n|x - c| < \\delta\n\\end{equation}\nfor a chosen value of $\\delta$. The definition of the limit can then be rewritten as:\n\n\\vspace{0.1in}\n\\textbf{\\textit{Limit}} -- The limit $\\lim_{x\\rightarrow c} f(x)$ is equal to the number $L$, if one exists, such that $\\forall \\epsilon > 0$ (as small as we want), there is a $\\delta > 0$ (sufficiently small) such that if $|x - c| < \\delta$ and $x \\neq c$, then $|f(x) - L| < \\epsilon$.\n\n\\vspace{0.1in}\n\\textbf{\\textit{Limits}} have the following properties, assuming all the limits on the right-hand side exist:\n\\begin{enumerate}\n\\item If $b$ is constant, then $\\lim_{x\\rightarrow c}\\left(bf(x)\\right) = b\\left(\\lim_{x \\rightarrow c}f(x)\\right)$\\\\\n\\vspace{-0.25in}\n\\item $\\lim_{x\\rightarrow c}\\left(f(x) + g(x)\\right) = \\lim_{x \\rightarrow c} f(x) + \\lim_{x \\rightarrow c} g(x)$\\\\\n\\vspace{-0.25in}\n\\item  $\\lim_{x\\rightarrow c}\\left(f(x) g(x)\\right) =  \\left(\\lim_{x\\rightarrow c}f(x)\\right)\\left(\\lim_{x\\rightarrow c}g(x)\\right)$\\\\\n\\vspace{-0.25in}\n\\item  $\\lim_{x\\rightarrow c} \\frac{f(x)}{g(x)} = \\frac{\\lim_{x\\rightarrow c}f(x)}{\\lim_{x\\rightarrow c}g(x)}$, provided $\\lim_{x\\rightarrow c}g(x) \\neq 0$\\\\\n\\vspace{-0.25in}\n\\item For any constant $k$, $\\lim_{x\\rightarrow c} k = k$\\\\\n\\vspace{-0.25in}\n\\item $\\lim_{x\\rightarrow c} x = c$\n\\end{enumerate}\n\n\\vspace{0.1in}\n\\textbf{\\textit{Limits}} can be taken from both the right and the left. The general form:\n\\begin{equation}\n\\lim_{x\\rightarrow c} f(x) = L\n\\end{equation}\nmeans that $f(x) \\rightarrow L$ as $x \\rightarrow c$ \\textit{from both directions}. Piecewise-defined functions may have different values from the right or the left if the limit is taken at a jump discontinuity. To indicate a limit from the left, the following notation is used:\n\\begin{equation}\n\\lim_{x\\rightarrow c^-} f(x) = L^-\n\\end{equation}\nand from the right:\n\\begin{equation}\n\\lim_{x\\rightarrow c^+} f(x) = L^+\n\\end{equation}\nAgain, the limit from the right or left is not guaranteed to converge to the same value, so $L^-$ and $L^+$ are used, but  $L^-$ may equal $L^+$.\n\n\\vspace{0.1in}\n\\textbf{\\textit{Limits}} do not exist when there is no finite number $L$ that the function value assumes at the point the limit is taken. Sometimes, limits are taken at $\\pm\\infty$ to understand the \\textbf{\\textit{end behavior}} of a function $f(x)$. Here $\\infty$ does not represent a number, just sufficiently large values of $x$. These limits are written as:\n\\begin{equation}\n\\lim_{x\\rightarrow \\pm\\infty} f(x) = L\n\\end{equation}\nif the limit, $L$, exists.\n\n\\vspace{0.1in}\nUsing this definition of the limit, \\textbf{\\textit{continuity}} of a function can be formally defined as:\n\\textbf{\\textit{Continuity}} -- A function $f(x)$ is continuous at $x = c$ if $f$ is defined at $x = c$ and if:\n\\begin{equation}\n\\lim_{x \\rightarrow c} f(x) = f(c)\n\\end{equation}\nIf $c$ is an endpoint of an interval $[a, b]$, then a one-sided limit is used.\n\n\\vspace{0.1in}\nUsing the continuity of sums of products, we can show that any \\textbf{\\textit{polynomial}} is a continuous function. The following rules can be used to determine of more complicated functions, such as $\\sin\\theta$, $\\cos\\theta$, or $e^x$ are continuous, provided $f$ and $g$ are continuous on an interval $[a, b]$ and $b$ is constant:\n\\begin{enumerate}\n\\item $bf(x)$ is continuous\\\\\n\\vspace{-0.25in}\n\\item $f(x) + g(x)$ is continuous\\\\\n\\vspace{-0.25in}\n\\item $f(x)g(x)$ is continuous\\\\\n\\vspace{-0.25in}\n\\item $\\frac{f(x)}{g(x)}$ is continuous, provided $g(x) \\neq 0$ on the interval $[a,b]$.\n\\end{enumerate}\n\nFor \\textbf{\\textit{composite functions}}, if $f$ and $g$ are continuous and if the \\textbf{\\textit{composite function}} $f(g(x))$ is defined on an interval $[a, b]$, then $f(g(x))$ is continuous on $[a, b]$.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}", "meta": {"hexsha": "3d3f37b43ba5dd8e001f5f09705eac23d40612ae", "size": 21972, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus I/Notes/chapter1.tex", "max_stars_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_stars_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-06T01:05:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-06T01:05:34.000Z", "max_issues_repo_path": "Calculus I/Notes/chapter1.tex", "max_issues_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_issues_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Calculus I/Notes/chapter1.tex", "max_forks_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_forks_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.8210526316, "max_line_length": 981, "alphanum_fraction": 0.7086291644, "num_tokens": 6906, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.720062532222875}}
{"text": "\\subsection{Generalized Linear Models (GLM)}\n\n\\noindent{\\bf Description}\n\\smallskip\n\nGeneralized Linear Models~\\cite{Gill2000:GLM,McCullagh1989:GLM,Nelder1972:GLM}\nextend the methodology of linear and logistic regression to a variety of\ndistributions commonly assumed as noise effects in the response variable.\nAs before, we are given a collection\nof records $(x_1, y_1)$, \\ldots, $(x_n, y_n)$ where $x_i$ is a numerical vector of\nexplanatory (feature) variables of size~\\mbox{$\\dim x_i = m$}, and $y_i$ is the\nresponse (dependent) variable observed for this vector.  GLMs assume that some\nlinear combination of the features in~$x_i$ determines the \\emph{mean}~$\\mu_i$\nof~$y_i$, while the observed $y_i$ is a random outcome of a noise distribution\n$\\Prob[y\\mid \\mu_i]\\,$\\footnote{$\\Prob[y\\mid \\mu_i]$ is given by a density function\nif $y$ is continuous.}\nwith that mean~$\\mu_i$:\n\\begin{equation*}\nx_i \\,\\,\\,\\,\\mapsto\\,\\,\\,\\, \\eta_i = \\beta_0 + \\sum\\nolimits_{j=1}^m \\beta_j x_{i,j} \n\\,\\,\\,\\,\\mapsto\\,\\,\\,\\, \\mu_i \\,\\,\\,\\,\\mapsto \\,\\,\\,\\, y_i \\sim \\Prob[y\\mid \\mu_i]\n\\end{equation*}\n\nIn linear regression the response mean $\\mu_i$ \\emph{equals} some linear combination\nover~$x_i$, denoted above by~$\\eta_i$.\nIn logistic regression with $y\\in\\{0, 1\\}$ (Bernoulli) the mean of~$y$ is the same\nas $\\Prob[y=1]$ and equals $1/(1+e^{-\\eta_i})$, the logistic function of~$\\eta_i$.\nIn GLM, $\\mu_i$ and $\\eta_i$ can be related via any given smooth monotone function\ncalled the \\emph{link function}: $\\eta_i = g(\\mu_i)$.  The unknown linear combination\nparameters $\\beta_j$ are assumed to be the same for all records.\n\nThe goal of the regression is to estimate the parameters~$\\beta_j$ from the observed\ndata.  Once the~$\\beta_j$'s are accurately estimated, we can make predictions\nabout~$y$ for a new feature vector~$x$.  To do so, compute $\\eta$ from~$x$ and use\nthe inverted link function $\\mu = g^{-1}(\\eta)$ to compute the mean $\\mu$ of~$y$;\nthen use the distribution $\\Prob[y\\mid \\mu]$ to make predictions about~$y$.\nBoth $g(\\mu)$ and $\\Prob[y\\mid \\mu]$ are user-provided.  Our GLM script supports\na standard set of distributions and link functions, see below for details.\n\n\\smallskip\n\\noindent{\\bf Usage}\n\\smallskip\n\n{\\hangindent=\\parindent\\noindent\\it%\n{\\tt{}-f }path/\\/{\\tt{}GLM.dml}\n{\\tt{} -nvargs}\n{\\tt{} X=}path/file\n{\\tt{} Y=}path/file\n{\\tt{} B=}path/file\n{\\tt{} fmt=}format\n{\\tt{} O=}path/file\n{\\tt{} Log=}path/file\n{\\tt{} dfam=}int\n{\\tt{} vpow=}double\n{\\tt{} link=}int\n{\\tt{} lpow=}double\n{\\tt{} yneg=}double\n{\\tt{} icpt=}int\n{\\tt{} reg=}double\n{\\tt{} tol=}double\n{\\tt{} disp=}double\n{\\tt{} moi=}int\n{\\tt{} mii=}int\n\n}\n\n\\smallskip\n\\noindent{\\bf Arguments}\n\\begin{Description}\n\\item[{\\tt X}:]\nLocation (on HDFS) to read the matrix of feature vectors; each row constitutes\nan example.\n\\item[{\\tt Y}:]\nLocation to read the response matrix, which may have 1 or 2 columns\n\\item[{\\tt B}:]\nLocation to store the estimated regression parameters (the $\\beta_j$'s), with the\nintercept parameter~$\\beta_0$ at position {\\tt B[}$m\\,{+}\\,1$, {\\tt 1]} if available\n\\item[{\\tt fmt}:] (default:\\mbox{ }{\\tt \"text\"})\nMatrix file output format, such as {\\tt text}, {\\tt mm}, or {\\tt csv};\nsee read/write functions in SystemML Language Reference for details.\n\\item[{\\tt O}:] (default:\\mbox{ }{\\tt \" \"})\nLocation to write certain summary statistics described in Table~\\ref{table:GLM:stats},\nby default it is standard output.\n\\item[{\\tt Log}:] (default:\\mbox{ }{\\tt \" \"})\nLocation to store iteration-specific variables for monitoring and debugging purposes,\nsee Table~\\ref{table:GLM:log} for details.\n\\item[{\\tt dfam}:] (default:\\mbox{ }{\\tt 1})\nDistribution family code to specify $\\Prob[y\\mid \\mu]$, see Table~\\ref{table:commonGLMs}:\\\\\n{\\tt 1} = power distributions with $\\Var(y) = \\mu^{\\alpha}$;\n{\\tt 2} = binomial or Bernoulli\n\\item[{\\tt vpow}:] (default:\\mbox{ }{\\tt 0.0})\nWhen {\\tt dfam=1}, this provides the~$q$ in $\\Var(y) = a\\mu^q$, the power\ndependence of the variance of~$y$ on its mean.  In particular, use:\\\\\n{\\tt 0.0} = Gaussian,\n{\\tt 1.0} = Poisson,\n{\\tt 2.0} = Gamma,\n{\\tt 3.0} = inverse Gaussian\n\\item[{\\tt link}:] (default:\\mbox{ }{\\tt 0})\nLink function code to determine the link function~$\\eta = g(\\mu)$:\\\\\n{\\tt 0} = canonical link (depends on the distribution family), see Table~\\ref{table:commonGLMs};\\\\\n{\\tt 1} = power functions,\n{\\tt 2} = logit,\n{\\tt 3} = probit,\n{\\tt 4} = cloglog,\n{\\tt 5} = cauchit\n\\item[{\\tt lpow}:] (default:\\mbox{ }{\\tt 1.0})\nWhen {\\tt link=1}, this provides the~$s$ in $\\eta = \\mu^s$, the power link\nfunction; {\\tt lpow=0.0} gives the log link $\\eta = \\log\\mu$.  Common power links:\\\\\n{\\tt -2.0} = $1/\\mu^2$,\n{\\tt -1.0} = reciprocal,\n{\\tt 0.0} = log,\n{\\tt 0.5} = sqrt,\n{\\tt 1.0} = identity\n\\item[{\\tt yneg}:] (default:\\mbox{ }{\\tt 0.0})\nWhen {\\tt dfam=2} and the response matrix $Y$ has 1~column,\nthis specifies the $y$-value used for Bernoulli ``No'' label.\nAll other $y$-values are treated as the ``Yes'' label.\nFor example, {\\tt yneg=-1.0} may be used when $y\\in\\{-1, 1\\}$;\neither {\\tt yneg=1.0} or {\\tt yneg=2.0} may be used when $y\\in\\{1, 2\\}$.\n\\item[{\\tt icpt}:] (default:\\mbox{ }{\\tt 0})\nIntercept and shifting/rescaling of the features in~$X$:\\\\\n{\\tt 0} = no intercept (hence no~$\\beta_0$), no shifting/rescaling of the features;\\\\\n{\\tt 1} = add intercept, but do not shift/rescale the features in~$X$;\\\\\n{\\tt 2} = add intercept, shift/rescale the features in~$X$ to mean~0, variance~1\n\\item[{\\tt reg}:] (default:\\mbox{ }{\\tt 0.0})\nL2-regularization parameter (lambda)\n\\item[{\\tt tol}:] (default:\\mbox{ }{\\tt 0.000001})\nTolerance (epsilon) used in the convergence criterion: we terminate the outer iterations\nwhen the deviance changes by less than this factor; see below for details\n\\item[{\\tt disp}:] (default:\\mbox{ }{\\tt 0.0})\nDispersion parameter, or {\\tt 0.0} to estimate it from data\n\\item[{\\tt moi}:] (default:\\mbox{ }{\\tt 200})\nMaximum number of outer (Fisher scoring) iterations\n\\item[{\\tt mii}:] (default:\\mbox{ }{\\tt 0})\nMaximum number of inner (conjugate gradient) iterations, or~0 if no maximum\nlimit provided\n\\end{Description}\n\n\n\\begin{table}[t]\\small\\centerline{%\n\\begin{tabular}{|ll|}\n\\hline\nName & Meaning \\\\\n\\hline\n{\\tt TERMINATION\\_CODE}  & A positive integer indicating success/failure as follows: \\\\\n                         & $1 = {}$Converged successfully;\n                           $2 = {}$Maximum \\# of iterations reached; \\\\\n                         & $3 = {}$Input ({\\tt X}, {\\tt Y}) out of range;\n                           $4 = {}$Distribution/link not supported \\\\\n{\\tt BETA\\_MIN}          & Smallest beta value (regression coefficient), excluding the intercept \\\\\n{\\tt BETA\\_MIN\\_INDEX}   & Column index for the smallest beta value \\\\\n{\\tt BETA\\_MAX}          & Largest beta value (regression coefficient), excluding the intercept \\\\\n{\\tt BETA\\_MAX\\_INDEX}   & Column index for the largest beta value \\\\\n{\\tt INTERCEPT}          & Intercept value, or NaN if there is no intercept (if {\\tt icpt=0}) \\\\\n{\\tt DISPERSION}         & Dispersion used to scale deviance, provided in {\\tt disp} input argument \\\\\n                         & or estimated (same as {\\tt DISPERSION\\_EST}) if {\\tt disp} argument is${} \\leq 0$ \\\\\n{\\tt DISPERSION\\_EST}    & Dispersion estimated from the dataset \\\\\n{\\tt DEVIANCE\\_UNSCALED} & Deviance from the saturated model, assuming dispersion${} = 1.0$ \\\\\n{\\tt DEVIANCE\\_SCALED}   & Deviance from the saturated model, scaled by {\\tt DISPERSION} value \\\\\n\\hline\n\\end{tabular}}\n\\caption{Besides~$\\beta$, GLM regression script computes a few summary statistics listed above.\nThey are provided in CSV format, one comma-separated name-value pair per each line.}\n\\label{table:GLM:stats}\n\\end{table}\n\n\n\n\n\n\n\\begin{table}[t]\\small\\centerline{%\n\\begin{tabular}{|ll|}\n\\hline\nName & Meaning \\\\\n\\hline\n{\\tt NUM\\_CG\\_ITERS}     & Number of inner (Conj.\\ Gradient) iterations in this outer iteration \\\\\n{\\tt IS\\_TRUST\\_REACHED} & $1 = {}$trust region boundary was reached, $0 = {}$otherwise \\\\\n{\\tt POINT\\_STEP\\_NORM}  & L2-norm of iteration step from old point ($\\beta$-vector) to new point \\\\\n{\\tt OBJECTIVE}          & The loss function we minimize (negative partial log-likelihood) \\\\\n{\\tt OBJ\\_DROP\\_REAL}    & Reduction in the objective during this iteration, actual value \\\\\n{\\tt OBJ\\_DROP\\_PRED}    & Reduction in the objective predicted by a quadratic approximation \\\\\n{\\tt OBJ\\_DROP\\_RATIO}   & Actual-to-predicted reduction ratio, used to update the trust region \\\\\n{\\tt GRADIENT\\_NORM}     & L2-norm of the loss function gradient (omitted if point is rejected) \\\\\n{\\tt LINEAR\\_TERM\\_MIN}  & The minimum value of $X \\pxp \\beta$, used to check for overflows \\\\\n{\\tt LINEAR\\_TERM\\_MAX}  & The maximum value of $X \\pxp \\beta$, used to check for overflows \\\\\n{\\tt IS\\_POINT\\_UPDATED} & $1 = {}$new point accepted; $0 = {}$new point rejected, old point restored \\\\\n{\\tt TRUST\\_DELTA}       & Updated trust region size, the ``delta'' \\\\\n\\hline\n\\end{tabular}}\n\\caption{\nThe {\\tt Log} file for GLM regression contains the above \\mbox{per-}iteration\nvariables in CSV format, each line containing triple (Name, Iteration\\#, Value) with Iteration\\#\nbeing~0 for initial values.}\n\\label{table:GLM:log}\n\\end{table}\n\n\\begin{table}[t]\\hfil\n\\begin{tabular}{|ccccccc|}\n\\hline\n\\multicolumn{4}{|c}{INPUT PARAMETERS}              & Distribution  & Link      & Cano- \\\\\n{\\tt dfam} & {\\tt vpow} & {\\tt link} & {\\tt\\ lpow} & family        & function  & nical?\\\\\n\\hline\n{\\tt 1}    & {\\tt 0.0}  & {\\tt 1}    & {\\tt -1.0}  & Gaussian      & inverse   &       \\\\\n{\\tt 1}    & {\\tt 0.0}  & {\\tt 1}    & {\\tt\\ 0.0}  & Gaussian      & log       &       \\\\\n{\\tt 1}    & {\\tt 0.0}  & {\\tt 1}    & {\\tt\\ 1.0}  & Gaussian      & identity  & Yes   \\\\\n{\\tt 1}    & {\\tt 1.0}  & {\\tt 1}    & {\\tt\\ 0.0}  & Poisson       & log       & Yes   \\\\\n{\\tt 1}    & {\\tt 1.0}  & {\\tt 1}    & {\\tt\\ 0.5}  & Poisson       & sq.root   &       \\\\\n{\\tt 1}    & {\\tt 1.0}  & {\\tt 1}    & {\\tt\\ 1.0}  & Poisson       & identity  &       \\\\\n{\\tt 1}    & {\\tt 2.0}  & {\\tt 1}    & {\\tt -1.0}  & Gamma         & inverse   & Yes   \\\\\n{\\tt 1}    & {\\tt 2.0}  & {\\tt 1}    & {\\tt\\ 0.0}  & Gamma         & log       &       \\\\\n{\\tt 1}    & {\\tt 2.0}  & {\\tt 1}    & {\\tt\\ 1.0}  & Gamma         & identity  &       \\\\\n{\\tt 1}    & {\\tt 3.0}  & {\\tt 1}    & {\\tt -2.0}  & Inverse Gauss & $1/\\mu^2$ & Yes   \\\\\n{\\tt 1}    & {\\tt 3.0}  & {\\tt 1}    & {\\tt -1.0}  & Inverse Gauss & inverse   &       \\\\\n{\\tt 1}    & {\\tt 3.0}  & {\\tt 1}    & {\\tt\\ 0.0}  & Inverse Gauss & log       &       \\\\\n{\\tt 1}    & {\\tt 3.0}  & {\\tt 1}    & {\\tt\\ 1.0}  & Inverse Gauss & identity  &       \\\\\n\\hline\n{\\tt 2}    & {\\tt  *}   & {\\tt 1}    & {\\tt\\ 0.0}  & Binomial      & log       &       \\\\\n{\\tt 2}    & {\\tt  *}   & {\\tt 1}    & {\\tt\\ 0.5}  & Binomial      & sq.root   &       \\\\\n{\\tt 2}    & {\\tt  *}   & {\\tt 2}    & {\\tt\\  *}   & Binomial      & logit     & Yes   \\\\\n{\\tt 2}    & {\\tt  *}   & {\\tt 3}    & {\\tt\\  *}   & Binomial      & probit    &       \\\\\n{\\tt 2}    & {\\tt  *}   & {\\tt 4}    & {\\tt\\  *}   & Binomial      & cloglog   &       \\\\\n{\\tt 2}    & {\\tt  *}   & {\\tt 5}    & {\\tt\\  *}   & Binomial      & cauchit   &       \\\\\n\\hline\n\\end{tabular}\\hfil\n\\caption{Common GLM distribution families and link functions.\n(Here ``{\\tt *}'' stands for ``any value.'')}\n\\label{table:commonGLMs}\n\\end{table}\n\n\\noindent{\\bf Details}\n\\smallskip\n\nIn GLM, the noise distribution $\\Prob[y\\mid \\mu]$ of the response variable~$y$\ngiven its mean~$\\mu$ is restricted to have the \\emph{exponential family} form\n\\begin{equation}\nY \\sim\\, \\Prob[y\\mid \\mu] \\,=\\, \\exp\\left(\\frac{y\\theta - b(\\theta)}{a}\n+ c(y, a)\\right),\\,\\,\\textrm{where}\\,\\,\\,\\mu = \\E(Y) = b'(\\theta).\n\\label{eqn:GLM}\n\\end{equation}\nChanging the mean in such a distribution simply multiplies all \\mbox{$\\Prob[y\\mid \\mu]$}\nby~$e^{\\,y\\hspace{0.2pt}\\theta/a}$ and rescales them so that they again integrate to~1.\nParameter $\\theta$ is called \\emph{canonical}, and the function $\\theta = b'^{\\,-1}(\\mu)$\nthat relates it to the mean is called the~\\emph{canonical link}; constant~$a$ is called\n\\emph{dispersion} and rescales the variance of~$y$.  Many common distributions can be put\ninto this form, see Table~\\ref{table:commonGLMs}.  The canonical parameter~$\\theta$\nis often chosen to coincide with~$\\eta$, the linear combination of the regression features;\nother choices for~$\\eta$ are possible too.\n\nRather than specifying the canonical link, GLM distributions are commonly defined\nby their variance $\\Var(y)$ as the function of the mean~$\\mu$.  It can be shown\nfrom Eq.~(\\ref{eqn:GLM}) that $\\Var(y) = a\\,b''(\\theta) = a\\,b''(b'^{\\,-1}(\\mu))$.\nFor example, for the Bernoulli distribution $\\Var(y) = \\mu(1-\\mu)$, for the Poisson\ndistribution \\mbox{$\\Var(y) = \\mu$}, and for the Gaussian distribution\n$\\Var(y) = a\\cdot 1 = \\sigma^2$.\nIt turns out that for many common distributions $\\Var(y) = a\\mu^q$, a power function.\nWe support all distributions where $\\Var(y) = a\\mu^q$, as well as the Bernoulli and\nthe binomial distributions.\n\nFor distributions with $\\Var(y) = a\\mu^q$ the canonical link is also a power function,\nnamely $\\theta = \\mu^{1-q}/(1-q)$, except for the Poisson ($q = 1$) whose canonical link is\n$\\theta = \\log\\mu$.  We support all power link functions in the form $\\eta = \\mu^s$,\ndropping any constant factor, with $\\eta = \\log\\mu$ for $s=0$.  The binomial distribution\nhas its own family of link functions, which includes logit (the canonical link),\nprobit, cloglog, and cauchit (see Table~\\ref{table:binomial_links}); we support these\nonly for the binomial and Bernoulli distributions.  Links and distributions are specified\nvia four input parameters: {\\tt dfam}, {\\tt vpow}, {\\tt link}, and {\\tt lpow} (see\nTable~\\ref{table:commonGLMs}).\n\n\\begin{table}[t]\\hfil\n\\begin{tabular}{|cc|cc|}\n\\hline\nName & Link function & Name & Link function \\\\\n\\hline\nLogit   & $\\displaystyle \\eta = 1 / \\big(1 + e^{-\\mu}\\big)^{\\mathstrut}$ &\nCloglog & $\\displaystyle \\eta = \\log \\big(\\!- \\log(1 - \\mu)\\big)^{\\mathstrut}$ \\\\\nProbit  & $\\displaystyle \\mu  = \\frac{1}{\\sqrt{2\\pi}}\\int\\nolimits_{-\\infty_{\\mathstrut}}^{\\,\\eta\\mathstrut}\n          \\!\\!\\!\\!\\! e^{-\\frac{t^2}{2}} dt$ & \nCauchit & $\\displaystyle \\eta = \\tan\\pi(\\mu - 1/2)$ \\\\\n\\hline\n\\end{tabular}\\hfil\n\\caption{The supported non-power link functions for the Bernoulli and the binomial\ndistributions.  (Here $\\mu$~is the Bernoulli mean.)}\n\\label{table:binomial_links}\n\\end{table}\n\nThe observed response values are provided to the regression script as matrix~$Y$\nhaving 1 or 2 columns.  If a power distribution family is selected ({\\tt dfam=1}),\nmatrix $Y$ must have 1~column that provides $y_i$ for each~$x_i$ in the corresponding\nrow of matrix~$X$.  When {\\tt dfam=2} and $Y$ has 1~column, we assume the Bernoulli\ndistribution for $y_i\\in\\{y_{\\mathrm{neg}}, y_{\\mathrm{pos}}\\}$ with $y_{\\mathrm{neg}}$\nfrom the input parameter {\\tt yneg} and with $y_{\\mathrm{pos}} \\neq y_{\\mathrm{neg}}$.  \nWhen {\\tt dfam=2} and $Y$ has 2~columns, we assume the\nbinomial distribution; for each row~$i$ in~$X$, cells $Y[i, 1]$ and $Y[i, 2]$ provide\nthe positive and the negative binomial counts respectively.  Internally we convert\nthe 1-column Bernoulli into the 2-column binomial with 0-versus-1 counts.\n\nWe estimate the regression parameters via L2-regularized negative log-likelihood\nminimization:\n\\begin{equation*}\nf(\\beta; X, Y) \\,\\,=\\,\\, -\\sum\\nolimits_{i=1}^n \\big(y_i\\theta_i - b(\\theta_i)\\big)\n\\,+\\,(\\lambda/2) \\sum\\nolimits_{j=1}^m \\beta_j^2\\,\\,\\to\\,\\,\\min\n\\end{equation*}\nwhere $\\theta_i$ and $b(\\theta_i)$ are from~(\\ref{eqn:GLM}); note that $a$\nand $c(y, a)$ are constant w.r.t.~$\\beta$ and can be ignored here.\nThe canonical parameter $\\theta_i$ depends on both $\\beta$ and~$x_i$:\n\\begin{equation*}\n\\theta_i \\,\\,=\\,\\, b'^{\\,-1}(\\mu_i) \\,\\,=\\,\\, b'^{\\,-1}\\big(g^{-1}(\\eta_i)\\big) \\,\\,=\\,\\,\n\\big(b'^{\\,-1}\\circ g^{-1}\\big)\\left(\\beta_0 + \\sum\\nolimits_{j=1}^m \\beta_j x_{i,j}\\right)\n\\end{equation*}\nThe user-provided (via {\\tt reg}) regularization coefficient $\\lambda\\geq 0$ can be used\nto mitigate overfitting and degeneracy in the data.  Note that the intercept is never\nregularized.\n\nOur iterative minimizer for $f(\\beta; X, Y)$ uses the Fisher scoring approximation\nto the difference $\\varDelta f(z; \\beta) = f(\\beta + z; X, Y) \\,-\\, f(\\beta; X, Y)$,\nrecomputed at each iteration:\n\\begin{gather*}\n\\varDelta f(z; \\beta) \\,\\,\\,\\approx\\,\\,\\, 1/2 \\cdot z^T A z \\,+\\, G^T z,\n\\,\\,\\,\\,\\textrm{where}\\,\\,\\,\\, A \\,=\\, X^T\\!\\diag(w) X \\,+\\, \\lambda I\\\\\n\\textrm{and}\\,\\,\\,\\,G \\,=\\, - X^T u \\,+\\, \\lambda\\beta,\n\\,\\,\\,\\textrm{with $n\\,{\\times}\\,1$ vectors $w$ and $u$ given by}\\\\\n\\forall\\,i = 1\\ldots n: \\,\\,\\,\\,\nw_i = \\big[v(\\mu_i)\\,g'(\\mu_i)^2\\big]^{-1}\n\\!\\!\\!\\!\\!\\!,\\,\\,\\,\\,\\,\\,\\,\\,\\,\nu_i = (y_i - \\mu_i)\\big[v(\\mu_i)\\,g'(\\mu_i)\\big]^{-1}\n\\!\\!\\!\\!\\!\\!.\\,\\,\\,\\,\n\\end{gather*}\nHere $v(\\mu_i)=\\Var(y_i)/a$, the variance of $y_i$ as the function of the mean, and\n$g'(\\mu_i) = d \\eta_i/d \\mu_i$ is the link function derivative.  The Fisher scoring\napproximation is minimized by trust-region conjugate gradient iterations (called the\n\\emph{inner} iterations, with the Fisher scoring iterations as the \\emph{outer}\niterations), which approximately solve the following problem:\n\\begin{equation*}\n1/2 \\cdot z^T A z \\,+\\, G^T z \\,\\,\\to\\,\\,\\min\\,\\,\\,\\,\\textrm{subject to}\\,\\,\\,\\,\n\\|z\\|_2 \\leq \\delta\n\\end{equation*}\nThe conjugate gradient algorithm closely follows Algorithm~7.2 on page~171\nof~\\cite{Nocedal2006:Optimization}.\nThe trust region size $\\delta$ is initialized as $0.5\\sqrt{m}\\,/ \\max\\nolimits_i \\|x_i\\|_2$\nand updated as described in~\\cite{Nocedal2006:Optimization}.\nThe user can specify the maximum number of the outer and the inner iterations with\ninput parameters {\\tt moi} and {\\tt mii}, respectively.  The Fisher scoring algorithm\nterminates successfully if $2|\\varDelta f(z; \\beta)| < (D_1(\\beta) + 0.1)\\hspace{0.5pt}\\eps$\nwhere $\\eps > 0$ is a tolerance supplied by the user via {\\tt tol}, and $D_1(\\beta)$ is\nthe unit-dispersion deviance estimated as\n\\begin{equation*}\nD_1(\\beta) \\,\\,=\\,\\, 2 \\cdot \\big(\\Prob[Y \\mid \\!\n\\begin{smallmatrix}\\textrm{saturated}\\\\\\textrm{model}\\end{smallmatrix}, a\\,{=}\\,1]\n\\,\\,-\\,\\,\\Prob[Y \\mid X, \\beta, a\\,{=}\\,1]\\,\\big)\n\\end{equation*}\nThe deviance estimate is also produced as part of the output.  Once the Fisher scoring\nalgorithm terminates, if requested by the user, we estimate the dispersion~$a$ from\nEq.~\\ref{eqn:GLM} using Pearson residuals\n\\begin{equation}\n\\hat{a} \\,\\,=\\,\\, \\frac{1}{n-m}\\cdot \\sum_{i=1}^n \\frac{(y_i - \\mu_i)^2}{v(\\mu_i)}\n\\label{eqn:dispersion}\n\\end{equation}\nand use it to adjust our deviance estimate: $D_{\\hat{a}}(\\beta) = D_1(\\beta)/\\hat{a}$.\nIf input argument {\\tt disp} is {\\tt 0.0} we estimate $\\hat{a}$, otherwise we use its\nvalue as~$a$.  Note that in~(\\ref{eqn:dispersion}) $m$~counts the intercept\n($m \\leftarrow m+1$) if it is present.\n\n\\smallskip\n\\noindent{\\bf Returns}\n\\smallskip\n\nThe estimated regression parameters (the $\\hat{\\beta}_j$'s) are populated into\na matrix and written to an HDFS file whose path/name was provided as the ``{\\tt B}''\ninput argument.  What this matrix contains, and its size, depends on the input\nargument {\\tt icpt}, which specifies the user's intercept and rescaling choice:\n\\begin{Description}\n\\item[{\\tt icpt=0}:] No intercept, matrix~$B$ has size $m\\,{\\times}\\,1$, with\n$B[j, 1] = \\hat{\\beta}_j$ for each $j$ from 1 to~$m = {}$ncol$(X)$.\n\\item[{\\tt icpt=1}:] There is intercept, but no shifting/rescaling of~$X$; matrix~$B$\nhas size $(m\\,{+}\\,1) \\times 1$, with $B[j, 1] = \\hat{\\beta}_j$ for $j$ from 1 to~$m$,\nand $B[m\\,{+}\\,1, 1] = \\hat{\\beta}_0$, the estimated intercept coefficient.\n\\item[{\\tt icpt=2}:] There is intercept, and the features in~$X$ are shifted to\nmean${} = 0$ and rescaled to variance${} = 1$; then there are two versions of\nthe~$\\hat{\\beta}_j$'s, one for the original features and another for the\nshifted/rescaled features.  Now matrix~$B$ has size $(m\\,{+}\\,1) \\times 2$, with\n$B[\\cdot, 1]$ for the original features and $B[\\cdot, 2]$ for the shifted/rescaled\nfeatures, in the above format.  Note that $B[\\cdot, 2]$ are iteratively estimated\nand $B[\\cdot, 1]$ are obtained from $B[\\cdot, 2]$ by complementary shifting and\nrescaling.\n\\end{Description}\nOur script also estimates the dispersion $\\hat{a}$ (or takes it from the user's input)\nand the deviances $D_1(\\hat{\\beta})$ and $D_{\\hat{a}}(\\hat{\\beta})$, see\nTable~\\ref{table:GLM:stats} for details.  A log file with variables monitoring\nprogress through the iterations can also be made available, see Table~\\ref{table:GLM:log}.\n\n\\smallskip\n\\noindent{\\bf Examples}\n\\smallskip\n\n{\\hangindent=\\parindent\\noindent\\tt\n\\hml -f GLM.dml -nvargs X=/user/biadmin/X.mtx Y=/user/biadmin/Y.mtx\n  B=/user/biadmin/B.mtx fmt=csv dfam=2 link=2 yneg=-1.0 icpt=2 reg=0.01 tol=0.00000001\n  disp=1.0 moi=100 mii=10 O=/user/biadmin/stats.csv Log=/user/biadmin/log.csv\n\n}\n\n\\smallskip\n\\noindent{\\bf See Also}\n\\smallskip\n\nIn case of binary classification problems, consider using L2-SVM or binary logistic\nregression; for multiclass classification, use multiclass~SVM or multinomial logistic\nregression.  For the special cases of linear regression and logistic regression, it\nmay be more efficient to use the corresponding specialized scripts instead of~GLM.\n", "meta": {"hexsha": "e4d13bf9e72d9b4c164408b806d802351a9e2991", "size": 21238, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "system-ml/docs/Algorithms Reference/GLM.tex", "max_stars_repo_name": "dusenberrymw/IBM-SystemML", "max_stars_repo_head_hexsha": "fc41ec4f0bd3bc6701c56103afdb409f8b0d9a04", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-18T06:10:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-18T06:10:37.000Z", "max_issues_repo_path": "system-ml/docs/Algorithms Reference/GLM.tex", "max_issues_repo_name": "dusenberrymw/IBM-SystemML", "max_issues_repo_head_hexsha": "fc41ec4f0bd3bc6701c56103afdb409f8b0d9a04", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "system-ml/docs/Algorithms Reference/GLM.tex", "max_forks_repo_name": "dusenberrymw/IBM-SystemML", "max_forks_repo_head_hexsha": "fc41ec4f0bd3bc6701c56103afdb409f8b0d9a04", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.8, "max_line_length": 111, "alphanum_fraction": 0.6481777945, "num_tokens": 7197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7199193064366078}}
{"text": "In this problem we are going t approximate the function \n$$ f(x)=e^{\\sin(5x)}$$\nusing Chebyshev's interpolation of degree ten (using eleven points) and using the orthonormal basis provided by the \\textit{Legendre polynomials}. It will be shown that the Legendre polynomials, which we show in the figure 1, give the best approximation of that degree as we proved in Problem 1.\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.75]{LegendrePols.eps}}\n\\caption{Legendre Polynomials.}\n\\end{figure}\n\nIn the following figure we show the function $f$ and the two approximations made. To the naked eye both of them seem very accurate, however we can see how the Legendre polynomials give us a better approximation by looking at the error in figure 3. \n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.6]{Approximations_p2.eps}}\n\\caption{Approximations using Chebyshev and Legendre polynomials.}\n\\end{figure}\nThe sudden drops in the error are in fact the points used to do the approximation, so the error is indeed zero. Since we are using logarithmic scale we see thos drops. We can see how the error of Chebyshev's method is higher. We can compute the $L_2$ error of the two methods,\n\\begin{align*}\ne_{Chebyshev}=0.07800109011,~~~~~~e_{Legendre}=0.05183155462,\n\\end{align*}\nand see how the Legendre polynomials, as proved in problem 1, give us the best approximation.\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.6]{Error_p2.eps}}\n\\caption{Error of the approximations.}\n\\end{figure}\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 2\nclear all\nclose all\nclc\nformat long\nlegendfontsize=12;\nlabelfontsize=14;\nf = @(x) exp(sin(5*x));\nf= chebfun(f);\nf_cheb = chebfun(f,11);\nxx=linspace(-1,1,1000);\nP=legpoly(0:10,'norm');\n\nfigure\nplot(P)\ngrid on\nxlabel('$x$','fontsize',labelfontsize,'interpreter','latex')\nsaveas(gcf,'Latex/FIGURES/LegendrePols','epsc')\nsaveas(gcf,'Latex/FIGURES/LegendrePols','fig')\n\nf_N=0;\nfor k=1:11\n    f_N=f_N+(f'*P(:,k))*P(:,k);\nend\n%%\nfigure\nplot(f,'linewidth',2)\nhold on\nplot(f_N,'linewidth',2)\nplot(f_cheb,'linewidth',2)\ngrid on\nlegend({'$f(x)=e^{\\sin(5x)}$','Legendre','Chebishev'}...\n    ,'fontsize',legendfontsize,'interpreter','latex','location','north')\nxlabel('$x$','fontsize',labelfontsize,'interpreter','latex')\nsaveas(gcf,'Latex/FIGURES/Approximations_p2','epsc')\nsaveas(gcf,'Latex/FIGURES/Approximations_p2','fig')\n\nError_cheb=norm(f-f_cheb,2)\nError_app=norm(f-f_N,2)\n%%\nfigure\nsemilogy(abs(f-f_cheb))\nhold on\nsemilogy(abs(f-f_N))\ngrid on\naxis([-1 1 1e-4 0.35])\nlegend({'$e_{Cheb}$','$e_{Leg}$'},'fontsize',legendfontsize,'interpreter','latex')\nxlabel('$x$','fontsize',labelfontsize,'interpreter','latex')\nsaveas(gcf,'Latex/FIGURES/Error_p2','epsc')\nsaveas(gcf,'Latex/FIGURES/Error_p2','fig')\n\n\\end{verbatim}", "meta": {"hexsha": "f7ea6019cacc5b2a217765016376b00cb96fe238", "size": 2838, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 2/Latex/problem2.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 2/Latex/problem2.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 2/Latex/problem2.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.475, "max_line_length": 295, "alphanum_fraction": 0.7350246653, "num_tokens": 872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8991213705121083, "lm_q1q2_score": 0.7199192902825984}}
{"text": "% 18ConnectionsandAssociatedBundles.tex\n\n\\subsection{ 18.1. Forms with Values in a Lie Algebra}\n\n\\begin{quote}\n  What do we mean by $g^{-1} dg$?\n\\end{quote}\n\n\\subsubsection{ 18.1.a. The Maurer-Cartan Form }\n\nIf we think of $\\omega$ as being a form that takes its values in the fixed vector space $\\mathfrak{g}$, rather than as a matrix of 1-forms, we shall have an equivalent picture that is in many ways more closely related to the terminology used in physics.  \n\nexterior form is differential form\n\n\\textbf{ Maurer-Cartan 1-form on $G$}\n\nLet $\\lbrace E_R \\rbrace$ basis for $\\mathfrak{g}$  \\\\\n\\phantom{Let} $\\lbrace X_R \\rbrace$ left invariant fields on $G$ obtained by left translating $E$'s  \\\\ \n\\phantom{Let} $\\lbrace \\sigma^R \\rbrace$ left invariant 1-forms on $G$ forming, $\\forall \\, g \\in G$, basis dual to $\\lbrace X_R \\rbrace$  \\\\\n\n$\\sigma^R(X_S) = \\delta^R_{ \\, \\, S}$\n\nThen \n\\begin{equation}\n  \\Omega \\equiv E_R \\otimes \\sigma^R \\quad \\quad \\quad \\, (18.1)\n\\end{equation} \n\\[\n\\Omega(Y_g) = E_R \\sigma^R(Y_g) = E_R Y^R \n\\]\n$Y = X_R Y^R$ at $g\\in G$, left translates back to 1\n\n$\\Omega : T_gG \\to T_e G$\n\ncf. Nakahara\n\\[\n\\Omega : Y \\mapsto (L_{g^{-1}})_* Y = (L_g)^{-1}_* Y, \\, Y \\in T_g G\n\\]\n\nClassically, Cartan wrote $\\forall \\, p \\in M$, vector valued 1 form taking each $Y$ vector at $p$ into itself\n\\[\ndp = \\partial_i \\otimes dx^i = \\partial_i \\otimes \\delta^i_{ \\, \\, j }dx^j\n\\]\n\\begin{equation}\n  \\Omega = g^{-1} dg \\quad \\quad \\quad \\, (18.2)\n\\end{equation}\n\n$dg$ takes $Y$ at $g$ into $Y$, $g^{-1}$ left transltates $Y$ back to $e$\n\n\n", "meta": {"hexsha": "dd28b679dd3325e9dd21c91c18af6d4bcb3cebe9", "size": 1555, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX_and_pdfs/the geometry of physics problems/18ConnectionsandAssociatedBundles.tex", "max_stars_repo_name": "wacfeldwang333/mathphysics", "max_stars_repo_head_hexsha": "59eb794dfa46e2b80e43df0440bb8ec3c472d973", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2017-01-10T14:24:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T11:19:23.000Z", "max_issues_repo_path": "LaTeX_and_pdfs/the geometry of physics problems/18ConnectionsandAssociatedBundles.tex", "max_issues_repo_name": "wacfeldwang333/mathphysics", "max_issues_repo_head_hexsha": "59eb794dfa46e2b80e43df0440bb8ec3c472d973", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-09-29T09:29:53.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-12T03:12:29.000Z", "max_forks_repo_path": "LaTeX_and_pdfs/the geometry of physics problems/18ConnectionsandAssociatedBundles.tex", "max_forks_repo_name": "wacfeldwang333/mathphysics", "max_forks_repo_head_hexsha": "59eb794dfa46e2b80e43df0440bb8ec3c472d973", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 25, "max_forks_repo_forks_event_min_datetime": "2018-01-21T05:33:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T20:15:13.000Z", "avg_line_length": 31.1, "max_line_length": 255, "alphanum_fraction": 0.6533762058, "num_tokens": 560, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7199008876300556}}
{"text": "\\documentclass[]{article}\n\n\\usepackage{amsmath}\n\\usepackage{bm}\n\n\\usepackage{siunitx}\n\n\\newcommand{\\cp}{c_{p}}\n\\newcommand{\\xd}[4]{%\n\t\\def\\temp{#1}\\ifx\\temp\\empty\n\t\t\\frac{#4 #2}{#4 #3}\n\t\\else\n\t\t\\frac{#4^{#1} #2}{#4 #3^{#1}}\n\t\\fi\n\t}\n\\newcommand{\\pd}[3][]{\\xd{#1}{#2}{#3}{\\partial}}\n\\newcommand{\\Dd}[3][]{\\xd{#1}{#2}{#3}{\\Delta}}\n\\newcommand{\\D}[2][]{%\n\t\\def\\temp{#1}\\ifx\\temp\\empty\n\t\t\\Delta #2\n\t\\else\n\t\t\\Delta^{#1} #2\n\t\\fi\n\t}\n\\newcommand{\\id}[1]{\\:d#1}\n\\newcommand{\\dq}{\\dot{q}}\n\\newcommand{\\vdq}{\\bm{\\dq}}\n\\newcommand{\\cnm}{\\bm{M}}\n\\newcommand{\\cnb}{\\bm{b}}\n\\newcommand{\\cnd}{\\bm{d}}\n\n%opening\n\\title{A 3D Finite Volume Method Solver for Arbitrary Solidification Boundary-Value Problems}\n\\author{William E Warriner}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{The Heat Equation}\n\nConsider a point in Euclidean space and let the temperature of that point be \\(u\\), its density \\(\\rho\\) and constant-pressure specific heat capacity \\(\\cp\\). It is assumed that all properties are temperature dependent. Then the heat equation may be formulated as\n\\begin{align}\n\\rho \\cp \\pd{u}{t} &= \\nabla \\cdot \\vdq\n\\end{align}\nwhere \\(\\vdq\\) is the heat flux vector across the point. The equation states that the temperature of a point changes proportionally to the net heat flux through it. Both sides of the equation have units of \\(\\si{W.m^{-3}}\\).\n\nThere are three types of heat flux: conductive, convective, and radiative. It is assumed that a boundary cannot experience both conductive and convective heat transfer. Conductive heat transfer is reserved for boundaries between points with the same material, while convective is for different materials. Radiative heat transfer occurs in both cases and is added to both. The heat flux equations are\n\\begin{align}\n\\vdq_{k} &= -k \\nabla u \\\\\n\\vdq_{h} &= \\bm{h} \\circ \\left( \\bm{u}_{\\infty} - u \\right) \\\\\n\\vdq_{\\sigma} &= \\sigma \\varepsilon \\left( \\bm{u}^{4}_{\\infty} - u^{4} \\right)\n\\end{align}\nwhere \\(k\\) is thermal conductivity, \\(\\bm{h}\\) is the vector convective heat transfer coefficient at the boundary, \\(u_{\\infty}\\) is the ambient temperature, \\(\\sigma\\) is the Stefan-Boltzmann constant and \\(\\varepsilon\\) is a constant dependent on emissivity. The symbol ``\\(\\circ\\)'' is the Hadamard product, and is performed element-wise. The scalar temperature \\(u\\) at a point is implicitly expanded to a vector with an appropriate number of elements whose values are identical. All of these have units of \\(\\si{W.m^{-2}}\\).\n\nThe heat equation in the case of pure conductivity becomes the more familiar\n\\begin{align}\n\\rho \\cp \\pd{u}{t} &= -\\nabla \\cdot k \\nabla u \\\\\n&= -\\nabla k \\cdot \\nabla u - k \\nabla^2 u\n\\end{align}\nwhereas in the case of pure convection it becomes\n\\begin{align}\n\\rho \\cp \\pd{u}{t} = \\nabla \\cdot \\bm{h} \\circ \\left( \\bm{u}_{\\infty} - u \\right)\n\\end{align}\nwith the assumption that heat transfer modes can be freely mixed provided the point is replaced by a differential element. Such a replacement naturally leads to a finite volume method formulation for numerical solutions to the heat equation.\n\n\\section{Finite Volume Method}\n\nSuppose that the problem domain is subdivided into axially-aligned rectangular prisms---or elements---whose side lengths are \\(\\Delta x\\), \\(\\Delta y\\) and \\(\\Delta z\\) along the \\(X\\)-, \\(Y\\)- and \\(Z\\)-axes, respectively. Then the volume of the cell is \\(V = \\Delta x \\Delta y \\Delta z\\), and the surface area components are \\(S_{yz} = \\Delta y \\Delta z\\), \\(S_{zx} = \\Delta z \\Delta x\\), \\(S_{xy} = \\Delta x \\Delta y\\) for boundaries normal to the \\(X\\)-, \\(Y\\)- and \\(Z\\)-axes respectively. Note the side lengths may vary along each axis without changing the following. Let \\(n\\) denote the sequence of axes \\(\\left\\{ x,y,z \\right\\}\\). Assume each cell has uniform temperature and properties. Then the convective heat equation for a cell then becomes\n\\begin{align}\n\\rho \\cp \\Dd{u}{t} &= -\\sum_{n} \\Dd{k_{n}}{n} \\Dd{u}{n} - \\sum_{n} k_{n} \\Dd[2]{u}{n} \\\\\n\\Dd{u}{t} &= -\\sum_{n} \\frac{1}{\\rho_{n} c_{p,n}} \\Dd{k_{n}}{n} \\Dd{u}{n} - \\sum_{n} \\frac{k_{n}}{\\rho_{n} c_{p,n}} \\Dd[2]{u}{n} \\\\\n\\D{u} &= -\\sum_{n} \\frac{\\D{t}}{\\rho_{n} c_{p,n} \\D{n}^{2}}\\D{k}_{n}\\D{u} - \\sum_{n} \\frac{k_{n} \\D{t}}{\\rho_{n} c_{p,n} \\D{n^{2}}}\\D[2]{u} \\\\\n\\D{u} &= -\\sum_{n} \\frac{\\D{t}}{\\rho_{n} c_{p,n}\\D{n}^{2}} \\left( \\D{k}_{n}\\D{u} + k_{n}\\D[2]{u} \\right)\n\\end{align}\nwhere the thermal conductivity of the face \\(i+1/2\\) between cells \\(i\\) and \\(i+1\\) is computed as\n\\begin{align}\nk_{n,i+1/2} &= \\left( \\frac{\\Delta n_{i}}{\\Delta n_{i} + \\Delta n_{i+1}} \\cdot \\frac{1}{k_{i}} + \\frac{\\Delta n_{i+1}}{\\Delta n_{i} + \\Delta n_{i+1}} \\cdot \\frac{1}{k_{i+1}} \\right)^{-1} \\\\\n&= \\left(\\Delta n_{i} + \\Delta n_{i+1}\\right) \\left( \\frac{\\Delta n_{i}}{k_{i}} + \\frac{\\Delta n_{i+1}}{k_{i+1}} \\right)^{-1}\n\\end{align}\nso that the conductivity between cells is the half-length-weighted harmonic mean of their respective conductivities. If the cells have uniform thickness, then the weighting becomes half for each contribution, and the result is simply double the harmonic mean.\n\nSimilarly, the value of \\(\\rho \\cp\\) for boundary \\(i+1/2\\) may be determined as the volume-weighted atrithmetic mean of cells \\(i\\) and \\(i+1\\) as\n\\begin{align}\n\\rho_{i+1/2} c_{p,i+1/2} &= \\frac{\\left( \\Delta n_{i} \\rho_{i} + \\Delta n_{i+1} \\rho_{i+1} \\right) \\left( \\Delta n_{i} c_{p,i} + \\Delta n_{i+1} c_{p,i+1} \\right)}{\\Delta n_{i} + \\Delta n_{i+1}} \n\\end{align}\nwhere the areas cancel and the volume-weighting becomes length-weighting. If the cells have uniform thickness then the weighted average becomes a simple arithmetic mean.\n\nThe convective heat equation becomes\n\\begin{align}\n\\rho \\cp \\Dd{u}{t} &= \\sum_{n} h_{n} \\Dd{\\left( u_{\\infty,n} - u \\right )}{n} \\\\\n\\D{u} &= \\sum_{n} \\frac{h_{n}\\D{t}}{2 \\rho_{n} c_{p,n}\\D{n}} \\Delta u\n\\end{align}\nbecause the ambient temperature at boundary \\(i+1/2\\) may be expressed as\n\\begin{align}\nu_{\\infty,n,i+1/2} &= \\frac{u_{i} + u_{i+1}}{2}\n\\end{align}\nwhich is the arithmetic mean of the temperature in cells \\(i\\) and \\(i+1\\). The unweighted arithmetic mean is reasonable because it is symmetric and because it uses the average temperature at exactly the boundary. Note the convection coefficient need not be averaged because it is empirically determined for the boundary in question. Every pair of materials which have an interface must have a well-defined convection coefficient.\n\n\\section{Discretization Approach}\n\nBecause the conductive heat equation is second order and the governing partial differential equation is parabolic we choose to use a generalized Crank-Nicolson approach. The approach can be thought of as a linear interpolation of a fully explicit and fully implicit second-order central difference. Because the next time step is implicitly dependent on the previous time step, a system of equations must be solved. The overall system may be expressed as\n\\begin{align}\n\\cnm^{j+1}_{m} u^{j+1} + \\cnb^{j+1}_{m} &= \\cnm^{j}_{e} u^{j} + \\cnb^{j}_{e} + \\cnd^{j}\n\\end{align}\nwhere \\(\\cnm\\) are the coefficient matrices, \\(u^{j}\\) is the temperature vector of the \\(j\\)-th time step, \\(\\cnb\\) are the global boundary conditions and subscripts \\(m\\) and \\(e\\) represent implicit and explicit parts of the Crank-Nicolson equations. The term \\(\\cnd^{j}\\) is the \\(-\\nabla k \\cdot \\nabla u\\) and will be discussed in more detail later. The solution to the system of equations is given by\n\\begin{align}\nu^{j+1} &= \\left(\\cnm^{j+1}_{m}\\right)^{-1} \\left( \\cnm^{j}_{e} u^{j} + \\cnb^{j}_{e} - \\cnb^{j+1}_{m} + \\cnd^{j} \\right)\n\\end{align}\nprovided \\(\\cnm_{m}^{j+1}\\) is invertible, and is the next time-step of the temperature field.\n\nThe matrix \\(\\cnm_{e}\\) has one row per cell in the domain. The matrix is zero everywhere except on the primary diagonal and six off-diagonals. The primary diagonal entries correspond to the cells of the domain, while the off-diagonals correspond to the contributions from each cell's six neighbors. The off-diagonal entries in the upper-triangular portion are equal to \\(\\left( 1 - \\theta \\right) \\alpha_{n,i}\\) where \\(n \\in \\left\\{x,y,z\\right\\}\\) and \\(i\\) is the \\(i\\)-th row of the matrix. The coefficient \\(\\theta\\) is implicitness parameter, and may take any value in \\(\\left[0,1\\right]\\). The value \\(0\\) implies the system is fully explicit, \\(1\\) fully implicit, and \\(0.5\\) the Crank-Nicolson method proper. The values of the \\(\\alpha\\) may be computed as\n\\begin{align}\n\\alpha_{k,n,i} &= \\frac{k_{n,i+1/2}\\D{t}}{\\rho_{n,i+1/2} c_{p,n,i+1/2}\\D{n}^2} = \\frac{k \\D{t}}{\\rho \\cp \\D{n}^2} \\\\\n\\alpha_{h,n,i} &= \\frac{h_{n,i+1/2}\\D{t}}{\\rho_{n,i+1/2} c_{p,n,i+1/2}\\D{n}} = \\frac{h \\D{t}}{\\rho \\cp \\D{n}}\n\\end{align}\nwhere the subscript \\(k\\) denotes a conductivity heat flux and \\(h\\) denotes convection. The sign of the half-index is flipped for the lower-triangular portion. All of the alphas are symmetric with respect to the sign of the half-indiex, so the matrix will be symmetric.\n\nMatrix symmetry implies that diffusivity between elements \\(i\\) and \\(i'\\) is the same as between \\(i'\\) and \\(i\\), which must hold by physical symmetry. Because the matrix is symmetric, the lower-triangular portion may be constructed directly from the upper portion. The diagonal indices of the upper-triangular portion containing non-zero entries are the strides of the underlying discretization of the domain. The stride along the \\(X\\)-axis is \\(1\\), along the \\(Y\\)-axis is the number of elements along the \\(X\\)-axis, and along the \\(Z\\)-axis is the product of the number of elements along the \\(X\\)- and \\(Y\\)-axes.\n\nOff-diagonal entries which imply the neighboring cell lies outside the domain are set to zero in \\(\\cnm_{e}\\). These entries require application of the global boundary condition, which is the origin of the \\(\\cnb\\) terms. For some elements these values are implicit in the matrix. For other elements they lie in rows or columns outside the choice of matrix. Rather than expanding the matrix, which is unwieldy and destroys the regularity of the band structure, instead all such entries are set to zero. As a result the boundary conditions must be exported to a vector \\(\\cnb_{e}\\). The vector is the product of \\(u_{\\infty}\\) with \\(\\left( 1 - \\theta \\right) \\alpha_{\\infty,n,i}\\) for each such boundary entry. The boundary entries for a given cell are summed together in the vector. For an element at the vertex of the domain there are thus three \\(\\alpha_{\\infty,n,i}\\) terms, at an edge two, on a face one, and zero everywhere else. For the vector \\(\\cnb_{m}\\) the elements are sums of \\(-\\theta \\alpha_{\\infty,n,i}\\).\n\nThe values on the primary diagonal of \\(\\cnm_{e}\\) are equal to \\(p_{i} = 2 - 2 \\left( 1 - \\theta \\right) \\sum_{n} \\alpha_{n,i} - 2 \\left( 1 - \\theta \\right) \\alpha_{\\infty,n,i}\\) where \\(\\alpha_{n,i}\\) is the upper diagonal element associated with axis \\(n\\) in the \\(i\\)-th row and \\(\\alpha_{\\infty,n,i}\\) is the \\(i\\)-th ambient diffusivity as used in \\(\\cnb_{e}\\). The doubling of the boundary and vector contributions is due to matrix symmetry. The matrix \\(\\cnm_{m}\\) is identical to \\(\\cnm_{e}\\) except off-diagonal entries are \\(-\\alpha_{n,i}\\) and primary diagonal entries are \\(p_{i} = 2 + 2 \\theta \\sum_{n} \\alpha_{n,i} + 2 \\theta \\alpha_{\\infty,n,i}\\), where the entries of the last term come from \\(\\cnb_{m}\\).\n\nUp to this point only the convective heat flux and second term of the conductive heat flux have been considered. It is believed the value of \\(\\cnd\\) will be largest between liquid and solid because there is often a sharp change in conductivity with solidification. A product of central difference schemes will be used to compute those values where possible. If a convective boundary exists on one face of an element along a direction, then that element will use the forward or backward difference for that direction instead, as appropriate. If the element has two convective boundaries on the same axis, then the value of the term is assumed to be zero along that axis. While it is possible to incorporate the term into the general Crank-Nicolson solver with additional mathematical effort, it is simpler to assume the term acts like an additional boundary condition and add the term to the right-hand side.\n\n\\section{Adaptive Time-stepping}\n\nThe previous section dealt with the solution to a single time-step. Determining how large that time-step must be is another matter. Adaptive time-stepping is used based on a target heat extraction rate. An initial guess is made at a time step, and a candidate temperature field computed using the method described in the previous section. The enthalpy of every point in the previous temperature field and candidate field are computed. The enthalpy change of every point is computed. If the largest enthalpy change over the domain is within some tolerance of a target value, then the candidate is accepted as the next time step. If not, then a modified bisection method is used to find the next candidate time step. The initial range of the bisection method is zero to infinity. If the enthalpy change is smaller than the target and the upper limit is still infinity, then the next guess is double the current guess. Otherwise the bisection proceeds as usual.\n\n\\section{Numerical Methods}\n\nTo solve the system of equations it is possible to use any linear system solver. The choice made here is a preconditioned conjugate gradient method using an initial guess. The preconditioner is an incomplete Cholesky factorization of \\(\\cnm_{m}\\). The initial guess is whichever previous candidate temperature field is closest to the target while determining the next time step.\n\nIt is common for the system to be stiff when real solidification properties are used due to the larger latent heat evolution over short time frames. A regularization procedure is used when calculating \\(\\cp\\). The values of enthalpy are precomputed from the values of \\(\\cp\\) for each temperature. The values of enthalpy are looked up using the current and previous time steps. The difference in enthalpy divided by difference in temperature is a linear approximation to \\(\\cp\\). Note that the properties are lagged in time by one step. Other methods are available but require considerably more effort to implement. For the first time step, there is not yet a previous time step. In that case \\(\\cp\\) is used directly.\n\n\\end{document}\n", "meta": {"hexsha": "d52407e2f46e4fbf74d23cf518459530e2097e25", "size": 14341, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/solidification_fdm/doc/motivation.tex", "max_stars_repo_name": "wwarriner/casting_geometric_toolsuite", "max_stars_repo_head_hexsha": "083299fa24c0dd30d896516c45c650c7a0d70743", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-11-23T00:01:08.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-01T17:58:14.000Z", "max_issues_repo_path": "doc/motivation.tex", "max_issues_repo_name": "wwarriner/solidification_fdm_solver", "max_issues_repo_head_hexsha": "f144a8423d423fa572fc09a9a3f5490eef965f20", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2018-11-29T22:46:54.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-29T20:05:39.000Z", "max_forks_repo_path": "doc/motivation.tex", "max_forks_repo_name": "wwarriner/solidification_fdm_solver", "max_forks_repo_head_hexsha": "f144a8423d423fa572fc09a9a3f5490eef965f20", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-05-20T15:49:54.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-18T21:47:18.000Z", "avg_line_length": 103.9202898551, "max_line_length": 1021, "alphanum_fraction": 0.7179415661, "num_tokens": 4189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314707995588, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.719900880268822}}
{"text": "%!TEX root = da2020-11.tex\n\n\\Chapter{11}{Hardness of Coloring}\n\n\\noindent\nThis week we will apply round elimination to coloring. We will show that 3-coloring paths requires $\\Omega(\\log^* n)$ rounds. This matches the fast coloring algorithms that we saw in Chapter~\\chapterref{1}.\n\nTo prove this result, we will see how to apply round elimination to randomized algorithms. Previously round elimination was purely deterministic: a $T$-round deterministic algorithm would imply a $(T-1)$-round deterministic algorithm for the output problem. With randomized algorithms, round elimination affects the success probability of the algorithm: a $T$-round randomized algorithm implies a $(T-1)$-round randomized algorithm for the output problem with a worse success probability.\n\nWe will see how round elimination can be applied in the presence of inputs. These inputs can be, in addition to randomness, e.g.\\ a coloring or an orientation of the edges. The critical property for round elimination is that there are no \\emph{long range dependencies} in the input.\n\n\\section{Coloring and Round Elimination}\n\nWe begin by applying round elimination to coloring on paths, or $(2,2)$-biregular trees. For technical reasons, we also encode a consistent orientation in the coloring. That is, in addition to computing a coloring, we require that the nodes also orient the path consistently from one endpoint to the other. This is a hard problem, as we saw in the previous chapter; therefore we will assume that the input is \\emph{already oriented}. We will show that $3$-coloring a path requires $\\Omega(\\log^* n)$ rounds \\emph{even if the path is consistently oriented}.\n\n\\subsection{Encoding Coloring}\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[page=\\PEncodingThreeColoring,scale=0.4]{figs.pdf}\n\t\\caption{Encoding of 3-coloring in the bipartite formalism. On top, a 3-coloring of a path fragment. Below, the corresponding 3-coloring as a bipartite locally verifiable problem. The path is assumed to be consistently oriented, so each node has an incoming and an outgoing edge. They use the regular label on the incoming edge, and the barred label on the outgoing edge. Passive nodes verify that the colors differ and have different type.} \\label{fig:3col-encoding}\n\\end{figure}\n\nWe will study the problem of $3$-coloring the \\emph{active nodes} of a $(2,2)$-biregular tree. We will say that two active nodes are \\emph{adjacent} if they share a passive neighbor. \n\nTo encode the orientation, we use two versions of each color label: e.g.\\ 1 and $\\bar{1}$. We call these \\emph{regular} and \\emph{barred} labels, respectively. For 3-coloring, we have the following problem $\\Pi_0 = (\\Sigma_0, \\collA_0, \\collP_0)$:\n\\begin{align*}\n\t\\Sigma_0 &= \\{ 1,\\bar{1},2,\\bar{2},3,\\bar{3} \\}, \\\\\n\t\\collA_0 &= \\bigl\\{ [ 1, \\bar{1} ],\\, [2,\\bar{2}],\\, [3,\\bar{3}] \\bigr\\}, \\\\\n\t\\collP_0 &= \\bigl\\{ [ 1, \\bar{2}],\\, [1, \\bar{3}],\\, [2, \\bar{1}],\\, [2, \\bar{3}],\\,[3,\\bar{1}],\\,[3,\\bar{2}] \\bigr\\}.\n\\end{align*}\nThe encoding of 3-coloring is shown in Figure~\\ref{fig:3col-encoding}. The active configurations ensure that each node chooses a color and an orientation of its edges: we can think of the edges labeled with $\\bar{1}$, $\\bar{2}$ or $\\bar{3}$ as outgoing edges, and the regular labels as incoming edges. The passive configurations ensure that adjacent active nodes are properly colored and that the passive node is properly oriented (has incident labels of different types).\n\nWe will also need to define coloring with more colors. We say that a label \\emph{matches} with its barred version: $1 \\sim \\bar{1}$, $2 \\sim \\bar{2}$ and so on. A label \\emph{does not match} with the other labels: e.g.\\ $1 \\nsim \\bar{2}$. \n\nWe define $c$-coloring as the following problem $\\Pi = (\\Sigma, \\collA, \\collP)$:\n\\begin{align*}\n\t\\Sigma &= \\{ 1,\\bar{1},2,\\bar{2},\\dots,c,\\bar{c} \\}, \\\\\n\t\\collA &= \\bigl\\{ [ x, \\bar x ] \\bigm| x \\in \\{1,2,\\dots,c\\} \\bigr\\}, \\\\\n\t\\collP &= \\bigl\\{ [ x, \\bar y ] \\bigm| x, y \\in \\{1,2,\\dots,c\\},\\, x \\nsim \\bar y \\bigr\\}.\n\\end{align*}\n\n\\subsection{Output Problem of Coloring}\n\nWe start by assuming that we have a fast algorithm that solves the $3$-coloring problem $\\Pi_0$. Let us now compute the output problem $\\Pi_1 = \\re(\\Pi_0)$ of $3$-coloring~$\\Pi_0$.\n\nLet $\\Pi_1 = (\\Sigma_1, \\collA_1, \\collP_1)$ denote the output problem. For now, we will let $\\Sigma_1$ consist of all non-empty subsets of $\\Sigma_0$, and prune it later.\n\nRecall that passive configurations $\\collP_0$ consist of all non-matching pairs of a regular and barred label. Therefore the active configurations in $\\Pi_1$ consist of all pairs of sets such that\n\\begin{itemize}[noitemsep]\n\t\\item one set consists of regular and one of barred labels, and\n\t\\item there are no matching labels.\n\\end{itemize}\nWe get that\n\\[\n\t\\collA_1 = \\bigl\\{ [X,Y] \\bigm| X \\subseteq \\{1,2,3\\}, Y \\subseteq \\{\\bar{1},\\bar{2},\\bar{3}\\}, \\forall x \\in X, y \\in Y: x \\nsim y \\bigr\\}.\n\\]\n\nNext we make the sets maximal: when neither the regular or the barred version of a label is contained in either set, we can add the corresponding variant to either set. Thus the maximal active configurations \\emph{split} the color set over their edges:\n\\[\\begin{split}\n\t\\collA_1 = \\Bigl\\{& \n\t\\bigl[\\{1\\},\\{\\bar{2},\\bar{3}\\}\\bigr],\\,\n\t\\bigl[\\{2\\},\\{\\bar{1},\\bar{3}\\}\\bigr],\\,\n\t\\bigl[\\{3\\},\\{\\bar{1},\\bar{2}\\}\\bigr],\\, \\\\\n\t&\\bigl[\\{\\bar{1}\\},\\{2,3\\}\\bigr],\\,\n\t\\bigl[\\{\\bar{2}\\},\\{1,3\\}\\bigr],\\,\n\t\\bigl[\\{\\bar{3}\\},\\{1,2\\}\\bigr] \n\t\\Bigr\\}\n\\end{split}\\]\nNo label can be added to any of the configurations, and the above labels contain all active configurations.\n\nWe have the following alphabet: \n\\[\\begin{split}\n\t\\Sigma_1 = \\bigl\\{& \n\t\\{1\\}, \\{2\\}, \\{3\\}, \\{1,2\\},\\{1,3\\}, \\{2,3\\}, \\\\\n\t&\\{\\bar{1}\\}, \\{\\bar{2}\\}, \\{\\bar{3}\\}, \\{\\bar{1},\\bar{2}\\},\\{\\bar{1},\\bar{3}\\}, \\{\\bar{2},\\bar{3}\\} \\bigr\\}.\n\\end{split}\\]\n\nFinally, the passive configurations consist of all pairs such that it is possible to pick matching regular and barred labels, forming a configuration in $\\collA_0$:\n\\[\n\t\\collP_1 = \\bigl\\{ [X,Y] \\bigm| (1 \\in X, \\bar{1} \\in Y) \\vee (2 \\in X, \\bar{2} \\in Y) \\vee (3 \\in X, \\bar{3} \\in Y) \\bigr\\}.\n\\]\n\n\\subsection{Simplification}\n\nThe output problem of 3-coloring looks much more complicated than the problem we started with. If we kept applying round elimination, it would become extremely difficult to understand the structure of the problem. Therefore we will \\emph{simplify} the problem: we will map it back to a coloring with a \\emph{larger number of colors}.\n\nThe intuition is the following. Assume that our original labels consist of some set of $c$ colors, and the output problem has sets of these colors as labels. Then there are at most $2^c$ different sets. If adjacent nodes have always different sets, we can treat it as a coloring with $2^c$ colors by mapping the sets to the labels $1,2,\\dots, 2^c$.\n\nNow consider the output problem of 3-coloring, $\\Pi_1$. We will treat the different sets of the regular labels as the color classes. Each of them is paired with a unique set of barred labels. Enumerating all options, we rename the labels as follows to match the alphabet of $6$-coloring:\n\\begingroup\n\\allowdisplaybreaks\n\\begin{alignat*}{2}\n\t\\{ 1 \\} &\\mapsto 1, & \\quad\\{\\bar{2},\\bar{3} \\} &\\mapsto \\bar{1}, \\\\\n\t\\{ 2 \\} &\\mapsto 2, & \\{\\bar{1},\\bar{3} \\} &\\mapsto \\bar{2}, \\\\\n\t\\{ 3 \\} &\\mapsto 3, & \\{\\bar{1},\\bar{2} \\} &\\mapsto \\bar{3}, \\\\\n\t\\{ 1,2 \\} &\\mapsto 4, & \\{\\bar{3}\\} &\\mapsto \\bar{4}, \\\\\n\t\\{ 1,3 \\} &\\mapsto 5, & \\{ \\bar{2} \\} &\\mapsto \\bar{5}, \\\\\n\t\\{ 2,3 \\} &\\mapsto 6, & \\{ \\bar{1} \\} &\\mapsto \\bar{6}.\n\\end{alignat*}\n\\endgroup\n\nNow let us verify that this is indeed a 6-coloring. After renaming, the active configurations are\n\\begin{align*}\n\t\\collA_1 = \\bigl\\{& \n\t[1,\\bar{1}],\\,\n\t[2,\\bar{2}],\\,\n\t[3,\\bar{3}],\\, \\\\\n\t&[\\bar{6},6],\\,\n\t[\\bar{5},5],\\,\n\t[\\bar{4},4] \n\t\\bigr\\}.\n\\end{align*}\nBy rearrangement we can see that these match exactly the definition of $6$-coloring. The passive configurations, before renaming, were the pairs of sets, one consisting of the regular labels and the other of the barred labels, that contained a matching label. We get that \n\\begin{align*}\n\t\\collP_1\n\t      = {}&\\bigl\\{ [1, x] \\bigm| x \\in \\{ \\bar{2}, \\bar{3}, \\bar{6} \\} \\bigr\\} \\\\\n\t{} \\cup {}&\\bigl\\{ [2, x] \\bigm| x \\in \\{ \\bar{1}, \\bar{3}, \\bar{5} \\} \\bigr\\} \\\\\n\t{} \\cup {}&\\bigl\\{ [3, x] \\bigm| x \\in \\{ \\bar{1}, \\bar{2}, \\bar{4} \\} \\bigr\\} \\\\\n\t{} \\cup {}&\\bigl\\{ [4, x] \\bigm| x \\in \\{ \\bar{1}, \\bar{2}, \\bar{3}, \\bar{5}, \\bar{6} \\} \\bigr\\} \\\\\n\t{} \\cup {}&\\bigl\\{ [5, x] \\bigm| x \\in \\{ \\bar{1}, \\bar{2}, \\bar{3}, \\bar{4}, \\bar{6} \\} \\bigr\\} \\\\\n\t{} \\cup {}&\\bigl\\{ [6, x] \\bigm| x \\in \\{ \\bar{1}, \\bar{2}, \\bar{3}, \\bar{4}, \\bar{5} \\} \\bigr\\}.\n\\end{align*}\n\nWe notice that these are a subset of the passive configurations of 6-coloring: colors 1, 2, and 3 cannot be paired with some of the non-matching colors. This means that $\\Pi_1$ is \\emph{at least as hard} to solve as 6-coloring.\n\nWe may \\emph{relax} the output problem $\\Pi_1$ and construct a new problem $\\Pi'_1 = (\\Sigma'_1, \\collA'_1, \\collP'_1)$ as follows:\n\\begingroup\n\\allowdisplaybreaks\n\\begin{align*}\n \\collA'_1 = {}&\\collA_1,\\\\\n \\collP'_1\n       = {}&\\bigl\\{ [1, x] \\bigm| x \\in \\{ \\bar{2}, \\bar{3}, \\bar{4}, \\bar{5}, \\bar{6} \\} \\bigr\\} \\\\\n {} \\cup {}&\\bigl\\{ [2, x] \\bigm| x \\in \\{ \\bar{1}, \\bar{3}, \\bar{4}, \\bar{5}, \\bar{6} \\} \\bigr\\} \\\\\n {} \\cup {}&\\bigl\\{ [3, x] \\bigm| x \\in \\{ \\bar{1}, \\bar{2}, \\bar{4}, \\bar{5}, \\bar{6} \\} \\bigr\\} \\\\\n {} \\cup {}&\\bigl\\{ [4, x] \\bigm| x \\in \\{ \\bar{1}, \\bar{2}, \\bar{3}, \\bar{5}, \\bar{6} \\} \\bigr\\} \\\\\n {} \\cup {}&\\bigl\\{ [5, x] \\bigm| x \\in \\{ \\bar{1}, \\bar{2}, \\bar{3}, \\bar{4}, \\bar{6} \\} \\bigr\\} \\\\\n {} \\cup {}&\\bigl\\{ [6, x] \\bigm| x \\in \\{ \\bar{1}, \\bar{2}, \\bar{3}, \\bar{4}, \\bar{5} \\} \\bigr\\}.\n\\end{align*}\n\\endgroup\nNote that $\\Pi'_1$ is exactly the $6$-coloring problem. As we have got that $\\collA'_1 = \\collA_1$ and $\\collP'_1 \\supseteq \\collP_1$, any solution to $\\Pi_1$ is also a solution to $\\Pi'_1$. We conclude that if we can solve problem $\\Pi_0$ in $T$ rounds, we can solve $\\Pi_1 = \\re(\\Pi_0)$ \\emph{exactly} one round faster, and we can solve its relaxation $\\Pi'_1$ \\emph{at least} one round faster.\n\n\\subsection{Generalizing Round Elimination for Coloring}\n\nLet us now see how to generalize the first round elimination step. In the first step, we saw that 6-coloring is at least as easy to solve as the output problem of 3-coloring.\n\nNow consider applying round elimination to the $c$-coloring problem. Let $\\re(\\Pi_0) = \\Pi_1 = (\\Sigma_1,\\collA_1, \\collP_1)$ denote the output problem of $c$-coloring $\\Pi_0$.\n\nAgain, the active configurations in $\\collA_1$ consist of all splits of the colors. For a set $X \\subseteq \\{1,2,\\dots,c\\}$, let $\\bar{X}$ denote the \\emph{barred complement of $X$}:\n\\[\n\t\\bar{X} = \\{ \\bar{x} \\bigm| x \\in \\{ 1,2,\\dots,c\\} \\setminus X \\}.\n\\]\nThen the active configurations are \n\\[\n\t\\collA_1 = \\bigl\\{ [X, \\bar{X}] \\bigm| \\emptyset \\ne X \\subsetneq \\{1,2,\\dots,c\\} \\bigr\\}.\n\\]\nThe labels are all non-empty and non-full subsets of the regular and barred labels, respectively. The passive configurations in $\\collP_1$ consists of pairs of sets such that it is possible to pick matching regular and barred labels from them:\n\\[\n\t\\collP_1 = \\bigl\\{ [X,Y] \\bigm| x \\in X, \\bar{x} \\in Y: x \\sim \\bar{x} \\bigr\\}.\n\\]\nWe do the exact same renaming trick as in the previous section. There are a total of $2^c - 2$ different sets on regular labels. We rename them in some order with the integers from $1$ to $2^c-2$. For each set $X$ renamed to integer $y$, we rename the unique barred complement $\\bar{X}$ to $\\bar{y}$. The active configurations after renaming are\n\\[\n\t\\collA_1 = \\bigl\\{ [x,\\bar{x}] \\bigm| x \\in \\{1,2,\\dots, 2^c-2 \\} \\bigr\\}.\n\\]\nWe note that passive configurations never include $[x,\\bar{x}]$ for any $x$. This is because $\\bar{x}$ represents the complement of $x$ as a set: it is not possible to pick a matching element from $x$ and $\\bar{x}$. Therefore we may again \\emph{relax} the passive configurations to be the configurations for $c$-coloring:\n\\[\n\t\\collP_1 = \\bigl\\{ [x,\\bar y] \\bigm| x, y \\in \\{1,2,\\dots,2^c-2\\},\\, x \\nsim \\bar y \\bigr\\}.\n\\]\nThe resulting problem is \\emph{at least as easy} as the output problem of $c$-coloring: if $c$-coloring can be solved in $T$ rounds, then coloring with $2^c-2$ colors can be solved in \\emph{at most} $T-1$ rounds.\n\nNow in what follows, it will be awkward to use the expression $2^c-2$, so we will simply round it up to $2^c$. Clearly, coloring with $2^c$ colors is at least as easy as coloring with $2^c-2$ colors.\n\n\\subsection{Sequence of Output Problems}\n\nWe have shown that $2^c$-coloring is \\emph{at least as easy} as the output problem of $c$-coloring. \nNow if we were to iteratively apply round elimination $k$ times in the $\\PN$-model we would get the following sequence of problems:\n\\[\\begin{split}\n\t\\Pi_0 = 3\\text{-coloring}\n\t&\\to \\Pi_1 = 2^3\\text{-coloring} \\\\\n\t&\\to \\Pi_2 = 2^{2^3}\\text{-coloring} \\\\\n\t&\\to \\Pi_3 = 2^{2^{2^3}}\\text{-coloring} \\\\\n\t&\\phantom{{}\\to{}} {\\cdots} \\\\\n\t&\\to \\Pi_k = C(k)\\text{-coloring},\n\\end{split}\\]\nwhere\n\\[\n\tC(k) = \\underbrace{\\,2^{2^{\\scriptstyle\\cdot^{\\scriptstyle\\cdot^{\\scriptstyle\\cdot^{\\scriptstyle 2^{\\scriptstyle 3}}}}}}}_{\\text{\\makebox[0pt]{$k$ times $2$ and one $3$}}}.\n\\]\nNow if we show that coloring with $C(k)$ colors cannot be solved in $0$ rounds in the $\\PN$ model with deterministic algorithms, it would imply that $3$-coloring cannot be solved in $k$ rounds in the $\\PN$ model. This result, however, would not be very meaningful. As we have already seen in Chapter~\\chapterref{7}, the vertex coloring problem cannot be solved at all in the $\\PN$-model! Therefore we must strengthen the round elimination technique itself to apply in the $\\LOCAL$ model.\n\n\\section{Round Elimination with Inputs}\n\nIf we try to do round elimination in the $\\LOCAL$ model, we run into a technical challenge. In round elimination, the nodes simulate the outputs of their neighbors. It is crucial that the inputs of the neighbors are independent: for each combination of possible outputs, there must exist a network in which the algorithm actually produces those outputs. This step no longer holds in the $\\LOCAL$ model: the identifiers are globally unique, and therefore do not repeat. The inputs of the neighbors \\emph{are dependent}: if one of the regions contains, e.g., a node with identifier 1, then another region cannot contain identifier 1, and vice versa.\n\nTo overcome this difficulty, we will consider \\emph{randomized algorithms}. In Exercise~\\longref{6.2}{ex:randomness-to-unique-ids} we saw that randomness can be used to generate unique identifiers. Therefore the $\\PN$-model, equipped with randomness, is at least as powerful as the $\\LOCAL$ model: if a problem $\\Pi$ can be solved in time $T(n)$ in the $\\LOCAL$ model, then we can generate unique identifiers with high probability and simulate the $\\LOCAL$-algorithm in $T(n)$ rounds. This clearly succeeds if the random identifiers were unique. Therefore any impossibility results we prove for randomized algorithms also hold for the $\\LOCAL$ model.\n\nFor the remainder of the chapter, we assume that the nodes receive two types of inputs.\n\\begin{enumerate}\n\t\\item Random inputs. Each node receives some arbitrary but finite number of uniform random bits as input. In addition, to simplify the proof, we will assume that the port numbers are assigned randomly. This latter assumption is made only for the purposes of this proof, we do not change the standard assumptions about the models.\n\t\\item Consistent orientation. As we mentioned in the beginning, for technical reasons we consider a variant of coloring that includes an orientation. To solve this part of the problem easily, we include the required orientation as input.\n\\end{enumerate}\nIt is crucial that we can apply round elimination in the presence of these inputs. First, consider the orientation. In the round elimination step, each node must simulate the outputs of its neighbors over all possible inputs. Now we add the promise that each node, in addition to its usual inputs, receives an orientation of its edges as input. In particular, they form a \\emph{consistent orientation} of the whole path from one end to the other. Clearly nodes can include this input in their simulation, as the orientation of the remaining edges is fixed after seeing the orientation of just one edge. Similarly, random inputs do not have any long-range dependencies. They do, however, affect the simulation step. We will discuss randomized round elimination in the next section.\n\n\\subsection{Randomized Round Elimination Step} \\label{ssec:rand-re}\n\nWe will now introduce a variant of the Round Elimination Lemma that we proved in Chapter~\\chapterref{9}. Assume that we have a randomized algorithm that solves problem $\\Pi$ in $T(n)$ rounds with \\emph{local failure probability $q$}: that is, each active node chooses an active configuration of $\\Pi$ with probability \\emph{at least} $1-q$, and each passive node is labeled according to some passive configuration of $\\Pi$ with probability \\emph{at least} $1-q$. Then we want to show that there is an algorithm that solves the output problem $\\re(\\Pi)$ in $T(n)-1$ rounds with some local failure probability at most $f(q)$ for some function $f$.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[page=\\PRandomizedRE,scale=0.4]{figs.pdf}\n\t\\caption{The randomized round elimination step. Assume an algorithm $A$ for $c$-coloring with running time $T = 3$. The simulation functions as follows. The active node gathers its $(T-1)$-neighborhood, including the assignment of random port numbers and random bits $r_1, r_2, r_3, r_4$ and $r_5$. Then it simulates $A$ on its right and left neighbor. On the right, over all possible assignments of ports $A, B, C$, $D$ and random bit strings $X, Y$. On the left, over all possible assignments of ports $E,F,G,H$ and random bit strings $Z,W$. For each edge, it outputs the set of labels that appear as outputs for at least fraction $t(q)$ of inputs.} \\label{fig:rand-re}\n\\end{figure}\n\nThe round elimination step works essentially as in the $\\PN$-model. Each $\\re(\\Pi)$-active node simulates the outputs of its $\\Pi$-active nodes over all possible inputs, including the random bits. We make one modification to the model: we assume that the port numbers are assigned randomly instead of being assigned by an adversary. This modification is made to simplify the analysis that follows. It does not affect the power of the model: the nodes could use their local randomness to shuffle the ports and any algorithm designed for the worst-case port numbering also works, by definition, with a random port numbering. We will also only consider nodes that are internal nodes in the $(2,2)$-biregular tree: we assume that $T$-neighborhoods of the neighbors of $\\re(\\Pi)$-active nodes do not contain the endpoints of the path.\n\nIt no longer makes sense to construct the set of \\emph{all possible} outputs. We can imagine an algorithm that tries to make round elimination hard: it always uses each possible output label with at least one specific random input labeling. These outputs would make no sense, but would cause the set of \\emph{possible} output labels to always be the full set of labels. Since the random inputs can be arbitrarily large (but finite!), the failure probability this would add to the algorithm would be small.\n\nTo avoid this issue, we will define a \\emph{threshold $t(q)$}: an output label $\\sigma \\in \\Sigma$ is \\emph{frequent} if it appears as the output label with probability at least $t(q)$. \nMore formally, for a fixed $\\re(\\Pi)$-active node $u$, an assignment of random inputs to $\\ball_N(u,T-1)$, and a neighbor $v$, label $\\sigma \\in \\Sigma$ is frequent for the edge $\\{ u, v \\}$ if the probability that $v$ outputs $\\sigma$ on $\\{u,v\\}$, conditioned on fixing the random inputs in $\\ball_N(u, T-1)$, is at least $t(q)$. We will fix the value of this threshold later.\n\nThe randomized simulation step is defined as follows. Each $\\Pi_1$-active node $u$ gathers its $(T-1)$-neighborhood. Then it computes for each edge $\\{u,v\\}$ the set of frequent labels $S(u,v)$ and outputs that set on $\\{u,v\\}$. See Figure~\\ref{fig:rand-re} for an illustration.\n\nWe will prove that randomized round elimination works for the special case of $c$-coloring $(2,2)$-biregular trees. This can be generalized to cover all bipartite locally verifiable problems in $(d,\\delta)$-biregular trees, for any parameters $d$ and $\\delta$.\n\n\\begin{lemma}[Randomized Round Elimination Lemma] \\label{lem:rand-re}\n\tAssume that there is an algorithm that solves the $c$-coloring problem on $(2,2)$-biregular trees in the randomized $\\PN$-model in $T(n)$ rounds with local failure probability at most $q$. Then there exists an algorithm that solves the $2^c$-coloring problem in $T(n)-1$ rounds with local failure probability at most $3cq^{1/3}$.\n\\end{lemma}\n\nIntuitively the lemma is true, as in most neighborhoods the true outputs must also appear frequently in the simulation. Similarly, combinations of non-configurations cannot be frequent too often, as this would imply that the original algorithms also fails often.\n\nWe prove the lemma in Section~\\ref{ssec:rand-re-proof}. Next we will see how to apply it to prove an impossibility result for 3-coloring.\n\n\\section{Iterated Randomized Round Elimination}\n\nGiven the randomized round elimination lemma, we will proceed as follows.\n\\begin{enumerate}[label=(\\arabic*)]\n\t\\item Assume there is a randomized $(\\log^* n - 4)$-round algorithm for solving 3-coloring on \\emph{consistently oriented} $(2,2)$-biregular trees. Since randomized algorithms are assumed to succeed \\emph{with high probability}, the local failure probability $q_0$ must be at most $1/n^k$ for some constant $k$.\n\t\\item Apply randomized round elimination $T(n) = \\log^* n - 4$ times to get a $0$-round randomized algorithm for $c_{T(n)}$-coloring with some local failure probability $q_{T(n)}$. For the chosen value of $T(n)$ show that we have $q_{T(n)} < 1/c_{T(n)}$. \\label{item:part2}\n\t\\item Prove that there are no 0-round algorithms for solving $c_{T(n)}$-coloring with local failure probability $q_{T(n)} < 1/c_{T(n)}$. \\label{item:part3} \n\\end{enumerate}\n\nWe must show that fast coloring algorithms imply 0-round coloring algorithms that do not fail with large enough probability. In Section~\\ref{ssec:prob-re} we will prove the following lemma.\n\n\\begin{lemma} \\label{lem:color-re}\n\tAssume that there is a $(\\log^* n - 4)$-round 3-coloring algorithm in the randomized $\\PN$-model. Then there is a 0-round $c$-coloring algorithm with local failure probability $q < 1/c$.\n\\end{lemma}\n\nWe must also show that any 0-round $c$-coloring algorithm fails locally with probability at least $1/c$.\n\n\\begin{lemma} \\label{lem:0round-ccol}\n\tAny 0-round $c$-coloring algorithm fails locally with probability at least $1/c$.\n\\end{lemma}\n\n\\begin{proof}\n\tAny 0-round $c$-coloring algorithm defines a probability distribution over the possible output colors. This distribution is the same for each active node inside a path: they are indistinguishable from each other in 0 rounds. The algorithm fails if two adjacent nodes select the same color. \n\t\n\tLet $p_i = b_i + 1/c$ denote the probability that the algorithm outputs color $i$. The terms $b_i$ denote the deviation of each probability $p_i$ from the average: we must have that\n\t\\[\n\t\t\\sum_{i=1}^c b_i = 0.\n\t\\] \n\tThe local failure probability is at least\n\t\\begin{align*}\n\t\t\\sum_{i=1}^c p_i^2 &= \\sum_{i=1}^c (b_i + 1/c)^2 \\\\\n\t\t&= \\sum_{i=1}^c \\bigl(b_i^2 + 2b_i/c + 1/c^2\\bigr) \\\\\n\t\t&= 1/c + \\biggl(\\sum_{i=1}^c b_i^2\\biggr) + 2/c \\cdot \\biggl(\\sum_{i=1}^c b_i\\biggr) \\\\\n\t\t&= 1/c + \\biggl(\\sum_{i=1}^c b_i^2\\biggr) + 0.\n\t\\end{align*}\n\tThis is clearly minimized by setting $b_i = 0$ for all $i$. Thus the local failure probability is minimized when $p_i = 1/c$ for all $i$, and we get that it is at least $1/c$.\n\\end{proof}\n\nThe bound on the failure probability of 0-round coloring algorithms combined with Lemma~\\ref{lem:color-re} shows that there is no 3-coloring algorithm that runs in at most $\\log^* n - 4$ rounds in the randomized $\\PN$-model, even if we know $n$ and the path is consistently oriented. Since the randomized $\\PN$-model can simulate the $\\LOCAL$ model with high probability, this implies that there is no (randomized) 3-coloring algorithm in the $\\LOCAL$ model that runs in at most $\\log^* n - 4$ rounds.\n\n\\begin{theorem}\n\t3-coloring (in the bipartite formalism) cannot be solved in the $\\LOCAL$ model in less than $\\log^* n - 4$ rounds.\n\\end{theorem}\n\n\\begin{corollary}\n\t3-coloring (in the usual sense) cannot be solved in the $\\LOCAL$ model in less than $\\frac{1}{2} \\log^* n - 2$ rounds.\n\\end{corollary}\n\\begin{proof}\n\tDistances between nodes increase by a factor of $2$ when we switch to the bipartite encoding (see Figure~\\ref{fig:3col-encoding}).\n\\end{proof}\n\nThis result is asymptotically optimal: already in Chapter~\\chapterref{1} we saw that paths \\emph{can be colored} with 3 colors in time $O(\\log^* n)$.\n\nIn the final two sections we give the proofs for Lemmas~\\ref{lem:rand-re}~and~\\ref{lem:color-re}.\n\n\\subsection{Proof of Lemma~\\ref{lem:rand-re}} \\label{ssec:rand-re-proof}\n\nIn this section we prove Lemma~\\ref{lem:rand-re}. The proof consists of bounding the local failure probability of the simulation algorithm given in Section~\\ref{ssec:rand-re}.\n\n\\begin{proof}[Proof of Lemma~\\ref{lem:rand-re}]\nLet $\\Pi_0 = (\\Sigma_0, \\collA_0, \\collP_0)$ denote the $c$-coloring problem for some $c$, and let $\\Pi_1 = \\re(\\Pi_0) = (\\Sigma_1, \\collA_1, \\collP_1)$ denote the output problem of $c$-coloring. Assume that there is a $T$-round randomized algorithm $A$ for solving $\\Pi_0$ with local failure probability $q$. \nConsider an arbitrary $\\Pi_1$-active node $u$ with some fixed $(T-1)$-neighborhood $\\ball_N(u,T-1)$ (including the random inputs).\n\nThe passive configurations $\\collP_0$ consist of pairs $[x, \\bar{y}]$ that do not match. The algorithm $A$ fails if it outputs any $x$ and $\\bar{x}$, or two labels of the same type on the incident edges of a $\\Pi_0$-passive node. We say that the $(T-1)$-neighborhood $\\ball_N(u,T-1)$ is \\emph{lucky}, if the algorithm $A$ fails in labeling the incident edges of $u$, given $\\ball_N(u,T-1)$, with probability less than $t^2$. Here $t$ is the probability threshold for frequent labels; we will choose the value of $t$ later.\n\nWe want to prove that most random bit assignments must be lucky, and that in lucky neighborhoods the simulation succeeds with a good probability. We will ignore the other cases, and simply assume that in those cases the simulation can fail.\n\nConsider any fixed $\\ball_N(u,T+1)$ \\emph{without} the random bits and the random port numbering: since we consider nodes inside the path, the remaining structure is the same for all nodes. The randomness determines whether $A$ succeeds around $u$. Let $L$ denote the event that $\\ball_N(u,T-1)$ is lucky. Since we know that $A$ fails in any neighborhood with probability at most $q$, we can bound the probability of a neighborhood \\emph{not being lucky} as follows:\n\\begin{align*}\n\t\\Pr[A \\text{ fails at } u] &\\geq  \n\t\\Pr[A \\text{ fails at } u \\mid \\text{not } L]\\cdot\\Pr[\\text{not } L] \\\\\n\t\\implies \\Pr[\\text{not } L] &\\leq \\frac{\\Pr[A \\text{ fails at } u]}{\\Pr[A \\text{ fails at } u \\mid \\text{not } L]}\n\t< \\frac{q}{t^2}.\n\\end{align*}\n\nFrom now on we will assume that $\\ball_N(u,T-1)$ is lucky. Let $v$ and $w$ denote the passive neighbors of $\\re(\\Pi)$-active node $u$. The simulation fails if and only if the sets $S(u,v)$ and $S(u,w)$ contain labels $x$ and $y$ such that $[x,y] \\notin \\collP_0$ (all choices do not yield a configuration in $\\collP_0$). Since both of these labels are frequent (included in the output), each of them must appear with probability at least $t$ given $\\ball_N(u,T-1)$. But since these labels are frequent, we have that the original algorithm fails, given $\\ball_N(u,T-1)$ with probability at least $t^2$, and the neighborhood cannot be lucky. We can deduce that the simulation \\emph{always succeeds in lucky neighborhoods}. Therefore we have that\n\\[\n\t\\Pr[\\text{simulation fails}] \\leq \\Pr[\\text{not } L] < \\frac{q}{t^2}.\n\\]\n\nNext we must determine the failure probability of the simulation around \\emph{passive nodes}. The $\\re(\\Pi)$-passive nodes succeed when the \\emph{true output} of the algorithm is contained in the sets of frequent outputs. For a $\\re(\\Pi)$-passive neighbor $v$, consider the event that its output on edge $\\{u,v\\}$ in the original algorithm is not contained in the set of frequent outputs $S(u,v)$ based on $\\ball_N(u,T-1)$. By definition, for each fixed $\\ball_N(u,T-1)$ each infrequent label is the true output with probability at most $t$. There are $c$ colors, so by union bound one of these is the true output color with probability at most $ct$. There are two neighbors, so by another union bound the total failure probability for a passive node is at most $2ct$. Since the simulation can also fail when the original algorithm fails, we get for each passive node that\n\\[\n\t\\Pr[\\text{simulation fails}] \\leq q + 2ct.\n\\]\nTo minimize the maximum of the two failure probabilities, we can for example set $t = q^{1/3}$ and get that\n\\[\n\t\\frac{q}{t^2} = q^{1/3} \\leq q + 2cq^{1/3} \\leq 3cq^{1/3}. \\qedhere\n\\]\n\\end{proof}\n\n\\subsection{Proof of Lemma~\\ref{lem:color-re}} \\label{ssec:prob-re}\n\nIt remains to show that a fast 3-coloring algorithm implies a 0-round $c$-coloring algorithm that fails locally with a probability less than $1/c$.\n\n\\begin{proof}[Proof of Lemma~\\ref{lem:color-re}]\nAssume there is a $T$-round 3-coloring algorithm that succeeds with high probability. This implies that it has a local failure probability $q_0 \\leq 1/n^k$ for some constant $k \\ge 1$. Applying the round elimination lemma, this implies the following coloring algorithms and local failure probabilities $q_i$:\n\\begin{align*}\n\tC(0) &= 3 \\text{ colors: }&& q_0 \\leq 1/n^k \\leq 1/n, \\\\\n\tC(1) &= 2^3 \\text{ colors: }&& q_1 \\leq 3 C(0) \\cdot q_0^{1/3}, \\\\\n\tC(2) &= 2^{2^3} \\text{ colors: }&& q_2 \\leq 3 C(1) \\cdot q_1^{1/3} = 3 C(1) \\cdot \\bigl(3 C(0) \\cdot q_0^{1/3}\\bigr)^{1/3}.\n\\end{align*}\nGeneralizing, we see that after $T$ iterations, the local failure probability is bounded by\n\\[\n\tq_T \\leq \\Biggl( \\prod_{i=0}^T 3^{1/3^i} \\Biggr)\\Biggl( \\prod_{i=0}^T C(T-i)^{1/3^i} \\Biggr) \\cdot n^{-1/3^T},\n\\]\nand the algorithm uses\n\\[\n\tC(T) \\,=\\, \n\t\\underbrace{\\,2^{2^{\\scriptstyle\\cdot^{\\scriptstyle\\cdot^{\\scriptstyle\\cdot^{\\scriptstyle 2^{\\scriptstyle 3}}}}}}}_{\\text{\\makebox[0pt]{\\parbox{3cm}{\\centering $T$ times $2$\\\\[-5pt]and one $3$}}}}\n\t\\,<\\,\n\t\\underbrace{\\,2^{2^{\\scriptstyle\\cdot^{\\scriptstyle\\cdot^{\\scriptstyle\\cdot^{\\scriptstyle 2^{\\scriptstyle 2^{\\scriptstyle 2}}}}}}}}_{\\text{\\makebox[0pt]{$T+2$ times $2$}}}\n\t\\,=\\, {}^{T+2} 2\n\\]\ncolors. To finish the proof, we must show that for any $T(n) \\leq \\log^* n - 4$ and for a sufficiently large $n$ we have that $q_T < 1/C(T)$, or, equivalently, $q_T \\cdot C(T) < 1$ or\n\\begin{equation} \\label{eq:prob}\n\t\\log q_T + \\log C(T) < 0;\n\\end{equation}\nhere all logarithms are to the base $2$.\nEvaluating the expression $\\log q_T$, we get that\n\\begin{align*}\n\t\\log q_T &\\leq \\sum_{i=0}^T \\frac{1}{3^i} \\log 3 + \\sum_{i=0}^T \\frac{1}{3^i} \\log C(T-i) - 3^{-T} \\log n \\\\\n\t&\\leq \\frac{3}{2}\\log 3 + \\frac{3}{2}\\log C(T) - 3^{-T} \\log n,\n\\end{align*}\nsince the sums are converging geometric sums. Therefore\n\\begin{equation}\\label{eq:logqTlogCT}\n\t\\log q_T + \\log C(T) \\le \\frac{3}{2}\\log 3 + \\frac{5}{2}\\log C(T) - 3^{-T} \\log n.\n\\end{equation}\nNote that\n\\[\n\tn \\le {}^{\\log^* n} 2 < 2^n.\n\\]\nTherefore for $T = \\log^* n - 4$ we have that\n\\begin{equation}\\label{eq:logCT}\n\t\\log C(T) < \\log {}^{T+2} 2 = \\log \\log \\log {}^{T+4} 2 < \\log \\log n.\n\\end{equation}\nOn the other hand, for a large enough $n$ we have that\n\\[\n\t3^T < 3^{\\log^* n} < 3^{\\log_3 \\log \\log n} < \\log \\log n,\n\\]\nand therefore\n\\begin{equation}\\label{eq:fact3Tlogn}\n\t3^{-T} \\log n > \\frac{\\log n}{\\log \\log n}.\n\\end{equation}\nNow \\eqref{eq:logCT} and \\eqref{eq:fact3Tlogn} imply that for a sufficiently large $n$, term $3^{-T} \\log n$ will dominate the right hand side of \\eqref{eq:logqTlogCT}, and we will eventually have\n\\[\n\t\\log q_T + \\log C(T) < 0,\n\\]\nwhich is exactly what we needed for Equation~\\eqref{eq:prob}.\n\\end{proof}\n\n\\section{Quiz}\n\t\nConstruct the \\emph{smallest possible} (i.e., fewest nodes) properly 4-colored cycle $C$ such that the following holds: if you take \\emph{any} deterministic 0-round $\\PN$-algorithm $A$ and apply it to $C$, then the output of $A$ is not a valid 3-coloring of $C$.\n\nPlease note that here we are working in the usual $\\PN$ model, exactly as it was originally specified in Chapter~3, and we are doing graph coloring in the usual sense (we do not use the bipartite formalism here).\nPlease give the answer by listing the $n$ colors of the $n$-cycle $C$.\n\n\\section{Exercises}\n\n\\begin{ex}[randomized 2-coloring]\n\tProve that solving 2-coloring paths in the randomized $\\PN$-model requires $\\Omega(n)$ rounds.\n\\end{ex}\n\n\\begin{ex}[coloring grids]\n\tProve that 5-coloring 2-dimensional grids in the deterministic $\\LOCAL$ model requires $\\Omega(\\log^* n)$ rounds.\n\t\n\tA 2-dimensional grid $G = (V,E)$ consists of $n^2$ nodes $v_{i,j}$ for $i,j \\in \\{1,\\dots, n\\}$ such that if $i < n$,  add $\\{ v_{i,j}, v_{i+1,j} \\}$ to $E$ for each $j$, and if $j < n$ add $\\{v_{i,j},v_{i,j+1}\\}$ to $E$ for each $i$.\n\t\\hint{Show that a fast 5-coloring algorithm could be simulated on any path to 5-color it. Then turn a 5-coloring into a 3-coloring yielding an algorithm that contradicts the 3-coloring lower bound.} \n\\end{ex}\n\n\\begin{ex}[more colors]\n\tProve that cycles cannot be colored with $O(\\log^* n)$ colors in $o(\\log^* n)$ rounds in the deterministic $\\LOCAL$ model.\n\t\\hint{Show that an $O(\\log^* n)$-coloring could be used to color cycles fast, which contradicts the lower bound for 3-coloring. Note that our lower bound is for paths: why does it also apply to cycles?}\n\\end{ex}\n\n\\begin{ex}[lying about $n$]\n\tShow that if a bipartite locally verifiable labeling problem can be solved in $o(\\log n)$ rounds in the deterministic $\\PN$-model in $(d,\\delta)$-biregular trees, then it can be solved in $O(1)$ rounds.\n\t\\hint{Show that we can run an algorithm for graphs of size $n_0$, for some constant $n_0$, on all networks of size $n \\geq n_0$, and get a correct solution. In particular, show that for any $T(n) = o(\\log n)$ and a sufficiently large $n_0$, networks on $n_0$ nodes are locally indistinguishable from networks on $n$ nodes, for $n \\geq n_0$, in $O(T(n))$ rounds.}\n\\end{ex}\n\n\\begin{ex}[hardness of sinkless orientation]\n\tLet $\\Pi$ denote the sinkless orientation problem as defined in Chapter~\\chapterref{10}.\n\tProve the following.\n\t\\begin{subex}\n\t\t\\item Sinkless orientation requires $\\Omega(\\log \\log n)$ rounds in the randomized $\\PN$-model. \\label{hint:so-a}\n\t\t\\item Sinkless orientation requires $\\Omega(\\log \\log n)$ rounds in the deterministic and randomized $\\LOCAL$ model. \\label{hint:so-b}\n\t\\end{subex}\n\t\\hint{\\ref{hint:so-a} Show that if $\\re(\\Pi)$ can be solved by a randomized $\\PN$-algorithm in $T$ rounds with local failure probability $q$, then it can be solved in $T-1$ rounds with local failure probability $\\poly(q)$. Analyze the failure probability over $T$ iterations for $T = o(\\log \\log n)$ and show that it is $\\omega(1)$.}\n\\end{ex}\n\n\\begin{exs}\n\tShow that sinkless orientation requires $\\Omega(\\log n)$ rounds in the deterministic $\\LOCAL$ model.\n\t\\hint{One approach is the following. Prove that any \\emph{deterministic} $o(\\log n)$-time algorithm for sinkless orientation implies an $O(\\log^* n)$-time deterministic algorithm for sinkless orientation. To prove this speedup, ``lie'' to the algorithm about the size of the graph. Take an algorithm $A$ for $(3,3)$-biregular trees on $n_0$ nodes, for a sufficiently large constant $n_0$. On any network $N$ of size $n > n_0$, compute a coloring of $N$ that \\emph{locally} looks like an assignment of unique identifiers in a network of size $n_0$. Then simulate $A$ given this identifier assignment to find a sinkless orientation.}\n\\end{exs}\n\n\n\\section{Bibliographic Notes}\n\nLinial~\\cite{linial92locality} showed that $3$-coloring cycles with a deterministic algorithm is not possible in $o(\\log^* n)$ rounds, and Naor~\\cite{Naor1991} proved the same lower bound for randomized algorithms. Our presentation uses the ideas from these classic proofs, but in the modern round elimination formalism.\n\n\n", "meta": {"hexsha": "ecd66120d83331effc6267c4e3e77abc2249791b", "size": 36548, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "book/ch11.tex", "max_stars_repo_name": "suomela/da2020", "max_stars_repo_head_hexsha": "874238b4e1d395769fc89d0d3a9453366056ad1d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-12-11T00:47:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T15:46:43.000Z", "max_issues_repo_path": "book/ch11.tex", "max_issues_repo_name": "suomela/da2020", "max_issues_repo_head_hexsha": "874238b4e1d395769fc89d0d3a9453366056ad1d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-11-17T18:31:27.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-17T18:42:16.000Z", "max_forks_repo_path": "book/ch11.tex", "max_forks_repo_name": "suomela/da2020", "max_forks_repo_head_hexsha": "874238b4e1d395769fc89d0d3a9453366056ad1d", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-06-22T03:53:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:33:40.000Z", "avg_line_length": 84.2119815668, "max_line_length": 872, "alphanum_fraction": 0.7062219547, "num_tokens": 11372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314707995591, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7199008762539433}}
{"text": "% jam 2004-09-02\n\n\\section{Derivatives}\n\\label{sec:Derivatives}\n\nOne way to view the derivative of a function\n$\\f:\\Vspace \\mapsto \\Wspace$,\nat a point $\\v$,\nis as the linear transformation $\\Lmap:\\Vspace \\mapsto \\Wspace$,\nthat best approximates the local 'slope' of $\\f$ at $\\v$.\n(In the following, $\\v$, $\\u$, and $\\t$ are elements of $\\Vspace$.)\nTo be a little more precise, we want\n\\begin{equation}\n\\lim_{ \\|{\\bf \\delta}  \\| \\mapsto 0}\n\\frac{ \\| \\f(\\v + {\\bf \\delta}) - (\\f(\\v) + \\Lmap({\\bf\\delta})) \\|}\n{\\|{\\bf \\delta}  \\| }\n = 0\n\\end{equation}\nFor a concise discussion, see Spivak \\cite{spivak-1965}.\n\nNote that for a linear map $\\Lmap$,\nthe derivative is constant over the domain\nand the value is $\\Lmap$ itself.\n\n\\begin{itemize}\n\n\\item $\\Da{\\f}$\n\nIn its most general form,\nI denote the derivative of $\\f$ by $\\Da{\\f}$.\nNote that this is linear-map-valued function of the domain of $\\f$.\n\n\\item $\\Db{\\f}{\\u}$\n\nI denote the derivative of $\\f$ at $\\u$ by $\\Db{\\f}{\\u}$.\n$\\Db{\\f}{\\u}$ is a specific linear transformation from\nthe domain of $\\f$ to the codomain of $\\f$.\n\n\\item $\\Dc{\\f}{\\u}{\\t}$\n\nThe derivative is most often represented by the {\\it Jacobian},\nthe $m \\times n$ matrix of partial derivatives\nwith respect to some bases for $\\Vspace$ and $\\Wspace$.\nHowever, it's often easier to express the derivative clearly if we\nexplicitly include the argument of the linear transformation.\nIn this case, I write $\\Dc{\\f}{\\u}{\\t}$\nfor the derivative of $f$ at the point $\\u$\napplied to the vector $\\t$.\n\n\\item $\\Dd{\\v_i}{\\f}{(\\u_0 \\ldots \\u_{n-1})}{\\t_i}$\n\nFor functions on direct sum spaces,\n$\\f(\\v_0,\\v_1 \\ldots \\v_{n-1})$, $\\v_i \\in \\Vspace_i$,\nit's often easier to consider the derivative\nwith respect to one argument at a time.\nI write $\\Dd{\\v_i}{\\f}{(\\u_0 \\ldots \\u_{n-1})}{\\t_0 \\ldots \\t_{n-1}}$\nfor the derivative of $\\f$ with respect to $\\v_i$,\nat the point $(\\u_0 \\ldots \\u_{n-1}) \\in \\oplus_{i=0}^{n-1} \\Vspace_i$,\napplied to the vector $\\t_i \\in \\Vspace_i$.\n\n\\item $\\da{j}{\\f} = \\da{v_j}{\\f}$\n\nThe traditional partial derivative of $\\f$ is with respect to\na single coordinate $v_j$ of the domain.\nMore formally, this is the directional derivative of $\\f$\nin the direction of the $j$-th canonical basis vector $\\e_j^{\\Vspace}$.\n\n$\\da{j}{\\f}$ is a map from the domain of $\\f$ to the co-domain of $\\f$.\n$\\db{j}{\\f}{\\u}$ is the value of that map at $\\u$.\nThe partial derivative is related to the derivative by\n\\begin{eqnarray}\n\\label{eq:partial-full-dervatives}\n\\Db{\\f}{\\u}\n& = &\n\\sum_{j=0}^{m-1} \\db{j}{\\f}{\\u} \\otimes \\e_j^{\\Vspace}\n\\\\\n\\db{j}{\\f}{\\u}\n& = &\n\\Db{\\f}{\\u} \\e_j^{\\Vspace}\n\\nonumber\n\\end{eqnarray}\n\n\\item $\\da{j}{\\f_i}$\n\nThe Jacobian partial derivatives are the derivatives of\na particular coordinate of $\\f$, $\\f_i$, with respect to\na single coordinate $v_j$ of the domain.\n$\\da{j}{\\f_i}$ is a real-valued function on the domain of $\\f$.\n$\\db{j}{\\f_i}{\\u}$ is the value of that function at $\\u$.\nThe Jacobian partial derivatives form the 'matrix' representation of the derivative:\n\\begin{equation}\n\\Db{\\f}{\\u} =\n\\sum_{i=0}^{m-1}\n\\sum_{j=0}^{n-1}\n\\db{j}{\\f_i}{\\u} \\left( \\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace} \\right)\n\\end{equation}\n\n\\end{itemize}\n\nIn minimizing a real-valued function, $f(\\v)$, $\\v \\in \\Vspace$,\nwe frequently need to know both the direction of maximum increase of $f$\nthe rate of increase, or slope, of $f$ in that direction.\n\n$\\Ga{f}$ is the {\\it gradient} of $f$.\nThe gradient has a close relationship to the derivative, $\\Da{f}$,\nand the two are often confused.\nRecall that the derivative is a linear transformation\nfrom the domain of $f$ to its codomain.\nIn the case of real-valued functions,\nthis means the derivative is a linear function on $\\Vspace$,\nan element of the dual space of $\\Vspace$, a 'row' vector.\nIt's easy to see that the gradient is simply the dual (the 'transpose')\nof the derivative, $\\Ga{f} = (\\Da{f})^{\\dagger}$\n(see Spivak \\cite[p.~96, ex.~4-18]{spivak-1965}).\n\n$\\Ga{f}$ maps $\\Vspace \\mapsto \\Vspace$.\n$\\Gb{f}{\\u} \\in \\Vspace$ is the gradient of $f$ at $\\u \\in \\Vspace$;\nit points in the direction of most rapid increase of\n$f$ and its magnitude $\\| \\Gb{f}{\\u} \\|$ is the\nslope of $f$ in that direction.\n\nNotation for the various versions of the gradient\nfollows that for derivatives:\n$\\Gc{\\v_i}{f}{\\u}$ is the partial gradient of $f$ with respect to $\\v_i$ at\n$\\u = \\left( \\u_0 \\ldots \\u_{n-1} \\right) \\in \\Vspace = \\oplus_{i=0}^{n-1} \\Vspace_i$\n$\\Gc{\\v_i}{f}{\\u}$ is an element of $\\Vspace_i$.\n\n$(\\Gb{f}{\\u}) \\bullet  \\t$\nand\n$(\\Gc{\\v_i}{f}{\\u}) \\bullet \\t_i$\nare the analogs to exressing the derivative as a linear transformation\nwith an explicit argument.\n$(\\Gb{f}{\\u}) \\bullet  \\t$ is a real number.\nIf we take $t$ to be the canonical basis for $\\Vspace$\nwe get an expression for $\\Ga{f}$ in terms of the partial derivatives of $f$:\n\\begin{equation}\n\\label{eq:gradient-from-partials}\n\\Gb{f}{\\u} = \\sum_{j=0}^{m-1} \\left( \\db{j}{f}{\\u} \\right) \\e_j^{\\Vspace}\n\\end{equation}\n\n$\\Ga{\\f_i}$ is the gradient of a particular (real-valued) coordinate\nof a vector-valued map. It is related to the derivative $\\Da{\\f}$\nin a way simlilar to the relationship between $\\Da{\\f}$ and its partials $\\da{j}{\\f}$.\n\\begin{equation}\n\\Db{\\f}{\\u} = \\sum_{i=0}^{n-1}  \\e_i^{\\Wspace} \\otimes \\Gb{\\f_i}{\\u}\n\\end{equation}\n\nThe most general identity used in computing derivatives is the {\\it chain rule.}\nSuppose\n$\\f:\\Uspace \\mapsto \\Vspace$,\n$\\g:\\Vspace \\mapsto \\Wspace$,\nand\n$\\h = \\g \\circ \\f : \\Uspace_0 \\mapsto \\Wspace$\nThen\n\\begin{equation}\n\\label{eq:chain-rule}\n\\Db{\\h}{\\u}\n=  \\Db{(\\g \\circ \\f)}{\\v}\n=  \\Db{\\g}{\\f(\\v)}  \\circ  \\Db{\\f} {\\v}.\n\\end{equation}\n\nIt is sometimes useful to express this in terms of the partial derivatives:\n\\begin{equation}\n\\label{eq:chain-rule_partials}\n\\Db{\\h}{\\u} =  \\sum_{i=0}^{n-1} \\db{i}{\\g}{\\f(\\u)} \\otimes  \\Gb{\\f_i}{\\u}.\n\\end{equation}\n\nSee Spivak \\cite[Theorem~2-2]{spivak-1965}.\n\n\n%------------------------------------------------------------------\n\n\\subsection{Vector-valued maps}\n\n%------------------------------------------------------------------\n\n\\subsubsection{Multilinear maps}\n\\label{sec:Multilinear-maps}\n\nA map $\\f(\\v_0 \\ldots \\v_k):\\Vspace_0 \\oplus \\ldots \\oplus \\Vspace_k \\mapsto \\Wspace$\nis {\\it multilinear} if\n\\begin{equation}\n\\f(a_{00} \\v_{00} + a_{01} \\v_{01}, \\ldots, a_{k0} \\v_{k0} + a_{k1} \\v_{k1})\n =  \\sum_{i_0 \\ldots i_k = 0,1} (a_{0i_0} \\ldots a_{ki_k}) \\f(\\v_{0i_0} \\ldots \\v_{ki_k}).\n\\end{equation}\n\nThe derivative of $\\f$\nat the point $(\\v_0 \\ldots \\v_k)$, applied to the vector $(\\u_0 \\ldots \\u_k)$ is\n\n\\begin{equation}\n\\Dc{\\f}{(\\v_0 \\ldots \\v_k)}{\\u_0 \\ldots \\u_k}\n =  \\sum_{i=0,k} \\f(\\v_0 \\ldots \\v_{i-1},\\u_i,\\v_{i+1} \\ldots \\v_k).\n\\end{equation}\n\nSee Spivak \\cite[ex.~2-14]{spivak-1965}.\n\n\n%------------------------------------------------------------------\n\n\\subsubsection{Bilinear maps}\n\\label{sec:Bilinear-maps}\n\nBilinear maps are a useful special case of multilinear maps.\n\nA map $\\f(\\v,\\u):\\Vspace_0 \\oplus \\Vspace_1 \\mapsto \\Wspace$\nis {\\it bilinear} if\n\\begin{eqnarray}\n\\f(a_0 \\v_0 + a_1 \\v_1, b_0 \\u_0 + b_1 \\u_1)\n& =  & a_0 b_0 f(\\v_0,\\u_0)\n+  a_0 b_1 f(\\v_0,\\u_1)\n\\\\\n& +  & a_1 b_0 f(\\v_q,\\u_0)\n +  a_1 b_1 f(\\v_q,\\u_1).\n\\nonumber\n\\end{eqnarray}\n\nThe derivative of $\\f$\nat the point $(\\v_0,\\u_0)$, applied to the vector $(\\v,\\u)$ is\n\\begin{equation}\n\\label{eq:bilinear-derivative}\n\\Dc{\\f}{(\\v_0,\\u_0)}{\\v,\\u} = \\f(\\v_0,\\u) + \\f(\\v,\\u_0).\n\\end{equation}\n\nSee Spivak \\cite[ex.~2-12]{spivak-1965}.\n\n\n%------------------------------------------------------------------\n\n\\subsubsection{Cross products}\n\\label{sec:Derivatives-of-cross-products}\n\nWe can view the 3-dimensional cross product\n$ \\times $\nas a bilinear map\n$\\times(\\v,\\u) = \\v \\times \\u : \\Reals^3 \\oplus \\Reals^3 \\mapsto \\Reals^3$.\nFrom equation \\ref{eq:bilinear-derivative},\n$\\Dc{\\times}{(\\v_0,\\u_0)}{\\v,\\u} = \\v_0 \\times \\u + \\v \\times \\u_0$.\n\nSuppose\n$\\f:\\Vspace \\mapsto \\Reals^3$, and\n$\\g:\\Vspace \\mapsto \\Reals^3$.\nThe derivative of $\\f \\times \\g$ is:\n\\begin{eqnarray}\n\\Dc{(\\f \\times \\g)}{\\v_0}{\\v}\n& =\n& \\Db{\\times}{(\\f(\\v_0),\\g(\\v_0))} \\circ (\\Dc{\\f}{\\v_0}{\\v}, \\Dc{\\g}{\\v_0}{\\v})\n\\\\\n& =\n& \\f(\\v_0) \\times \\Dc{\\g}{\\v_0}{\\v} + \\Dc{\\f}{\\v_0}{\\v} \\times \\g(\\v_0) \\nonumber\n\\end{eqnarray}\n\n%------------------------------------------------------------------\n\n\\subsubsection{Scalar products}\n\\label{sec:Derivatives-of-scalar-products}\n\nSuppose\n$f:\\Vspace \\mapsto \\Reals$, and\n$\\g:\\Vspace \\mapsto \\Wspace$.\nIt follows from the chain rule that the derivative of $\\h = f\\g$ is:\n\\begin{equation}\n\\label{eq:scalar_product_derivative}\n\\Db{(f\\g)}{\\v} =  f(\\v) \\Db{\\g}{\\v} + \\g(\\v) \\otimes \\Gb{f}{\\v}\n\\end{equation}\n\n\n%------------------------------------------------------------------\n\n\\subsubsection{Normalized maps}\n\\label{sec:Normalized-maps}\n\nLet $\\tilde{\\f}$ be the normalized version of $\\f$:\n$\\tilde{\\f}  =  \\frac{\\f}{\\| \\f \\|}$.\nThen, from equations \\ref{eq:scalar_product_derivative}\nand \\ref{eq:norm_derivative}:\n\\begin{eqnarray}\n\\Dc{\\tilde{\\f}}{\\v}{\\u}\n& = &\n\\Dc{\\left( \\frac{\\f}{\\| \\f \\|}\\right)}{\\v}{\\u}\n\\\\\n& = &\n\\frac{\\Dc{\\f}{\\v}{\\u}}{ \\| \\f(\\v) \\|}\n +\n\\f(\\v)  \\Dc{ \\left( \\frac{1}{\\| \\f \\|} \\right) }{\\v}{\\u} \\nonumber \\\\\n& = &\n\\frac{\\Dc{\\f}{\\v}{\\u}}\n{\\| \\f(\\v) \\|}\n -\n\\f(\\v)\n\\frac{\\Dc{\\| \\f \\|}{\\v}{\\u}}\n{\\|\\f(\\v)\\|^2} \\nonumber \\\\\n& = &\n\\frac{\\Dc{\\f}{\\v}{\\u}}{ \\| \\f(\\v) \\| }\n -\n\\f(\\v) \\left( \\frac{\\f(\\v)^\\dagger}{\\| \\f(\\v) \\|^3}  \\Dc{\\f}{\\v}{\\u} \\right) \\nonumber \\\\\n& = &\n\\frac{\n\\| \\f(\\v) \\|^2 \\Dc{\\f}{\\v}{\\u}\n -\n\\f(\\v)\\left( \\f(\\v) \\bullet \\Dc{\\f}{\\v}{\\u} \\right)\n}\n{\\| \\f(\\v) \\|^3}  \\nonumber \\\\\n& = &\n\\frac{\\| \\f(\\v) \\|^2 \\Identity_{\\Wspace} - \\left( \\f(\\v) \\otimes \\f(\\v) \\right)  }\n{ \\| \\f(\\v) \\|^3 }\n\\Dc{\\f}{\\v}{\\u} \\nonumber \\\\\n& = &\n\\frac{\\Identity_{\\Wspace} - \\left( \\tilde{\\f}(\\v) \\otimes \\tilde{\\f}(\\v) \\right)  }\n{\\| \\f(\\v) \\|}\n\\Dc{\\f}{\\v}{\\u} \\nonumber\n\\end{eqnarray}\n\n\nWe can write the derivative above without reference to the argument $\\u$:\n\\begin{equation}\n\\label{eq:normalized_function_derivative}\n\\Db{\\tilde{\\f}}{\\v}\n =\n\\Db{\\left( \\frac{\\f}{\\| \\f \\|} \\right)}{\\v}\n =\n\\frac{\\Identity_{\\Wspace} - \\left( \\tilde{\\f}(\\v) \\otimes \\tilde{\\f}(\\v) \\right) }\n{ \\| \\f(\\v) \\| }\n\\Db{\\f}{\\v}\n\\end{equation}\n\nA common, trivial, normalized function is the normalized version of\na vector: $\\tilde{\\v} =  \\frac{\\v}{ \\| \\v \\| }$.\n\nFrom equation \\ref{eq:normalized_function_derivative}\nit follows that:\n\\begin{equation}\n\\label{eq:normalized_vector_derivative}\n\\Db{\\tilde{\\v}}{\\u}\n =\n\\Db{ \\left( \\frac{\\v}{ \\| \\v \\| } \\right) }{\\u}\n =\n\\frac{\\Identity_{\\Vspace} - \\left( \\tilde{\\u} \\otimes \\tilde{\\u} \\right) }\n{ \\| \\u \\| }\n =\n\\frac{\\| \\u \\|^2 \\Identity_{\\Vspace} - \\left( \\u \\otimes \\u \\right) }\n{\\| \\u \\|^3}\n\\end{equation}\n\n%------------------------------------------------------------------\n\n\\subsection{Real-valued functions}\n\\label{sec:derivatives-of-real-valued-functions}\n\n%------------------------------------------------------------------\n\n\\subsubsection{Inner products}\n\\label{sec:derivatives-of-inner-products}\n\nWe can view the inner product on $\\Vspace$, $\\v \\bullet \\u$,\nas a bilinear function $\\bullet(\\v,\\u) : \\Vspace \\oplus \\Vspace \\mapsto \\Reals$.\nThus\n\\begin{equation}\n\\Dc{\\bullet}{(\\v_0,\\u_0)}{\\v,\\u} = \\v_0 \\bullet \\u + \\v \\bullet \\u_0.\n\\end{equation}\n\nSuppose\n$\\f:\\Vspace \\mapsto \\Vspace$, and\n$\\g:\\Vspace \\mapsto \\Vspace$.\nThe derivative of $\\f \\bullet \\g$ is:\n\\begin{eqnarray}\n\\label{eq:dot_derivative}\n\\Dc{(\\f \\bullet \\g)}{\\v_0}{\\v}\n& =\n& \\Db{\\bullet}{(\\f(\\v_0),\\g(\\v_0))} \\circ (\\Dc{\\f}{\\v_0}{\\v}, \\Dc{\\g}{\\v_0}{\\v})\n\\\\\n& =\n& \\f(\\v_0) \\bullet \\Dc{\\g}{\\v_0}{\\v}  +  \\g(\\v_0) \\bullet \\Dc{\\f}{\\v_0}{\\v} \\nonumber\n\\end{eqnarray}\n\nSee Spivak \\cite[ex.~2-13]{spivak-1965}.\n\n%------------------------------------------------------------------\n\n\\subsubsection{Angles}\n\\label{sec:derivatives-of-angles}\n\nThe angle between 2 vectors $\\v_0, \\v_1 \\in \\Vspace$,\nis the inverse cosine of their normalized inner product:\n$\\theta(\\v_0,\\v_1)\n=\n\\cos^{-1} \\left( \\frac{ \\v_0 \\bullet \\v_1 } {\\|\\v_0\\| \\|\\v_1\\|} \\right)$.\nRecall that the derivative of the $\\cos^{-1}$ is\n$\\frac{\\mathrm d}{\\mathrm dx} \\cos^{-1}(x) = \\frac{-1}{\\sqrt{1 - x^2} }$.\nIt follows that:\n\\begin{eqnarray*}\n\\Gc{\\v_0}{\\theta(\\v_0,\\v_1)}{\\u}\n& = &\n\\frac{-1}\n{ \\sqrt{1 - \\left( \\frac{\\u_0 \\bullet \\u_1}{\\| \\u_0 \\| \\| \\u_1 \\|} \\right)^2 }}\n\\Gc{\\v_0}{\\left( \\frac{\\u_0 \\bullet \\u_1}{\\| \\u_0 \\| \\| \\u_1 \\|} \\right)}{\\u}\n\\\\\n& = &\n\\frac{-\\|\\u_0\\|\\|\\u_1\\|}\n{ \\sqrt{\\|\\u_0\\|^2\\|\\u_1\\|^2 - \\left( \\u_0 \\bullet \\u_1 \\right)^2 }}\n\\left[\n\\frac{\\u_1}{\\|\\u_0\\|\\|\\u_1\\|}\n+\n\\frac{\\left( \\u_0 \\bullet \\u_1 \\right)}{\\| \\u1 \\|}\n\\Gc{\\v_0}{\\left( \\frac{1}{\\| \\v_0 \\|} \\right)} {\\u}\n\\right]\n\\nonumber\n\\\\\n& = &\n\\frac{-\\|\\u_0\\|\\|\\u_1\\|}\n{ \\sqrt{\\|\\u_0\\|^2\\|\\u_1\\|^2 - \\left( \\u_0 \\bullet \\u_1 \\right)^2 }}\n\\left[\n\\frac{\\u_1}{\\|\\u_0\\|\\|\\u_1\\|}\n-\n\\frac{\\left( \\u_0 \\bullet \\u_1 \\right) \\u0}{\\| \\u1 \\| \\|\\u_0\\|^3}\n\\right]\n\\nonumber\n\\\\\n& = &\n\\frac{-1}\n{ \\sqrt{\\|\\u_0\\|^2\\|\\u_1\\|^2 - \\left( \\u_0 \\bullet \\u_1 \\right)^2 }}\n\\left[\n\\u_1\n-\n\\frac{\\left( \\u_0 \\bullet \\u_1 \\right) \\u0}{\\|\\u_0\\|^2}\n\\right]\n\\nonumber\n\\end{eqnarray*}\nwhich results in\n\\begin{eqnarray}\n\\label{eq:angle_gradient}\n\\Gc{\\v_0}{\\theta(\\v_0,\\v_1)}{\\u}\n& = &\n\\frac{- \\u_1 \\perp \\u_0}\n{ \\sqrt{\\|\\u_0\\|^2\\|\\u_1\\|^2 - \\left( \\u_0 \\bullet \\u_1 \\right)^2 }}\n\\\\\n\\Gc{\\v_1}{\\theta(\\v_0,\\v_1)}{\\u}\n& = &\n\\frac{- \\u_0 \\perp \\u_1}\n{ \\sqrt{\\|\\u_0\\|^2\\|\\u_1\\|^2 - \\left( \\u_0 \\bullet \\u_1 \\right)^2 }}\n\\nonumber\n\\end{eqnarray}\n\n%------------------------------------------------------------------\n\n\\subsubsection{Euclidean norm}\n\\label{sec:derivatives-of-euclidean-norm}\n\nLet $l_2(\\v) = \\| \\v  \\|: \\Vspace \\mapsto \\Reals$\nbe the usual euclidean norm on $\\Vspace$.\nLet $l_2^2(\\v) = \\| \\v  \\|^2 $\nbe its square and $ \\| \\v  \\|^3$ the cube.\n\\begin{eqnarray}\n\\label{eq:l2-gradient}\n\\Gb{l_2}{\\v} = \\frac{ \\v }{ \\| \\v  \\|} &\n\\Gb{l_2^2}{\\v} =  2\\v &\n\\Gb{l_2^3}{\\v} = 3 \\| \\v  \\| \\v \\\\\n\\Db{l_2}{\\v} = \\frac{ \\v^\\dagger }{ \\| \\v  \\|} &\n\\Db{l_2^2}{\\v} = 2\\v{^\\dagger} &\n\\Db{l_2^3}{\\v} = 3 \\| \\v  \\| \\v^\\dagger \\nonumber\n\\end{eqnarray}\n\nLet $\\f(\\v) : \\Vspace \\mapsto \\Wspace$.\nBy the chain rule:\n$\\Db{\\| \\f \\|^2}{\\v}  =  2 {\\f(\\v)}^{\\dagger} \\Db{\\f}{\\v} $\nand\n$\\Gb{\\| \\f \\|^2}{\\v}  =  2 \\Db{\\f}{\\v}^\\dagger \\circ \\f(\\v)$.\n\\begin{eqnarray}\n\\label{eq:norm_derivative}\n\\Db{\\| \\f \\|}{\\v}\n& = &\n\\frac{\\f(\\v)^\\dagger}{\\| \\f(\\v) \\|} \\Db{\\f}{\\v}  \\\\\n\\Gb{\\| \\f \\|}{\\v}\n& = &\n\\left(\\Db{\\f}{\\v}\\right)^\\dagger \\circ  \\frac{\\f(\\v)}{ \\| \\f(\\v)  \\|}\n\\label{eq:norm_gradient}\n\\end{eqnarray}\n\n%------------------------------------------------------------------\n\n\\subsection{Linear-map-valued maps}\n\\label{sec:Linear-map-valued-maps}\n\nThe set of linear maps between two inner product spaces\n$\\{ \\Lmap : \\Vspace \\mapsto \\Wspace \\}$\nis itself a inner product space $\\Lspace(\\Vspace,\\Wspace)$,\nwith the inner product defined by\n$\\Lmap \\bullet \\Mmap = \\sum_{i=0}^{m-1} \\sum_{j=0}^{n-1} \\Lmap_{ij} \\Mmap_{ij}$.\nThe set of linear maps\n$\\Emap_{ij}^{\\Lspace(\\Vspace,\\Wspace)}  = \\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace}$\nare the canonical basis vectors for $\\Lspace(\\Vspace,\\Wspace)$.\n\nIf $\\f$ is a map between spaces of linear maps,\n$\\f : \\Lspace(\\Vspace_0,\\Wspace_0) \\mapsto \\Lspace(\\Vspace_1,\\Wspace_1)$,\nits derivative, $\\Da{\\f}$,\nis a map from a space of linear maps\nto a space of linear maps between two\nspaces of linear maps:\n$\\Da{\\f} : \\Lspace(\\Vspace_0,\\Wspace_0) \\mapsto\n\\Lspace(\\Lspace(\\Vspace_0,\\Wspace_0), \\Lspace(\\Vspace_1,\\Wspace_1))$.\nThis can get a little confusing,\nand it often helps to consider both the partial derivatives of $\\f$\nand the gradients of the coordinates of $\\f$,\nwhich can make it easier to apply the chain rule to\ncompositions of maps of maps via equation \\ref{eq:chain-rule_partials}.\n\n$\\da{ij}{\\f}$ is the partial derivative with respect to its $ij$-th matrix coordinate,\nthat is, the directional derivative of $\\f$ in the direction\nof the $ij$-th canonical basis vector, $\\Emap_{ij}^{\\Lspace(\\Vspace_0,\\Wspace_0)}$.\nAs usual the value of the partial derivative at a specific\n$\\Lmap_0 \\in  \\Lspace(\\Vspace_0,\\Wspace_0)$,\n$\\db{ij}{\\f}{\\Lmap_0}$ is an element of the co-domain of $\\f$,\na linear map in  $\\Lspace(\\Vspace_1,\\Wspace_1)$.\n\n$\\Ga{\\f_{kl}}$ is the gradient of the $kl$-th matrix coordinate of the value of $\\f$.\nAs usual, the value of the gradient at a specific $\\Lmap_0$,\n$\\Gb{\\f_{kl}}{\\Lmap_0}$ is an element of the domain of $\\f$,\na linear map in $\\Lspace(\\Vspace_0,\\Wspace_0)$.\n\nNote that nether of these are elements of the Jacobian of $\\f$,\nwhich needs 4 indexes: $\\da{ij}{\\f_{kl}}$.\n\nI am particularly interested in computing the derivative of the\npseudo-inverse: $\\Pseudoinverse(\\Lmap) \\equiv \\Lmap^{-}$.\nThe set of full rank linear maps is an open set,\nand we can define the derivative of $\\Pseudoinverse(\\Lmap)$ there.\nFor full rank map,\nwe can use the chain rule and the identity\n$\\Lmap^{-} = \\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1} \\Lmap^{\\dagger}$\n(equation \\ref{eq:full-rank-pseudo-inverse})\nto compute the derivative of the pseudo-inverse\n(\\autoref{sec:Derivative-of-pseudo-inverse}).\n\nTo do this I will first establish partial derivatives and gradients of:\n\\begin{equation}\n\\begin{aligned}\n\\label{eq:transpose-derivative}\n&\\Transpose(\\Lmap) \\equiv \\Lmap^{\\dagger}\n&&\\db{ij}{\\Transpose}{\\Lmap} =  \\e_j^{\\Vspace} \\otimes \\e_i^{\\Wspace}\n\\forall \\Lmap\n\\\\\n&\\h( \\Lmap ) = \\f ( \\Lmap ) \\g ( \\Lmap )\n&&\\text{Section \\ref{sec:Derivatives-of-function-products} }\n\\\\\n&\\LTL(\\Lmap) \\equiv \\Lmap^{\\dagger} \\Lmap\n&&\\text{Section \\ref{sec:Derivatives-of-LTL} }\n\\\\\n&\\Inverse(\\Lmap) \\equiv \\Lmap^{-1}\n&&\\text{Section \\ref{sec:Derivative-of-inverse} }\n\\end{aligned}\n\\end{equation}\n\n%------------------------------------------------------------------\n\n\\subsubsection{Map product}\n\\label{sec:Derivatives-of-function-products}\n\nLet\n$\\f : \\Lspace(\\Vspace_0,\\Wspace_0) \\mapsto \\Lspace(\\Vspace_1,\\Wspace_1)$,\n$\\g : \\Lspace(\\Vspace_0,\\Wspace_0) \\mapsto \\Lspace(\\Uspace_1,\\Vspace_1)$,\nand\n$\\h = \\f\\g : \\Lspace(\\Vspace_0,\\Wspace_0) \\mapsto \\Lspace(\\Uspace_1,\\Wspace_1)$.\nNote that\n$\\db{ij}{\\f}{\\Lmap} \\in  \\Lspace(\\Vspace_1,\\Wspace_1)$,\n$\\db{ij}{\\g}{\\Lmap} \\in  \\Lspace(\\Uspace_1,\\Vspace_1)$,\nand\n$\\db{ij}{\\h}{\\Lmap} \\in  \\Lspace(\\Uspace_1,\\Wspace_1)$.\nConsider the matrix representation of $\\db{ij}{\\h}{\\Lmap}$:\n\\begin{eqnarray}\n\\left( \\db{ij}{\\h}{\\Lmap} \\right)_{kl}\n& = &\n\\db{ij}{\\h_{kl}}{\\Lmap}\n\\\\\n& = &\n\\db{ij}{\\left( \\sum_{m} \\f_{km} \\g_{ml} \\right)}{\\Lmap}\n\\nonumber\n\\\\\n& = &\n\\sum_{m}  \\left[\n\\left( \\db{ij}{\\f_{km}}{\\Lmap} \\right) \\g_{ml}(\\Lmap)\n+\n\\f_{km}(\\Lmap) \\left( \\db{ij}{\\g_{ml}}{\\Lmap} \\right)\n\\right]\n\\nonumber\n\\\\\n& = &\n\\left[\n\\left( \\db{ij}{\\f}{\\Lmap} \\right) \\g(\\Lmap)\n+\n\\f(\\Lmap) \\left( \\db{ij}{\\g}{\\Lmap} \\right)\n\\right]_{kl}\n\\nonumber\n\\end{eqnarray}\nTherefore\n\\begin{equation}\n\\label{eq:map-product-derivative}\n\\db{ij}{\\h}{\\Lmap}\n =\n\\left( \\db{ij}{\\f}{\\Lmap} \\right) \\g(\\Lmap)\n+\n\\f(\\Lmap) \\left( \\db{ij}{\\g}{\\Lmap} \\right)\n\\end{equation}\n\n%------------------------------------------------------------------\n\n\\subsubsection{$\\Lmap^{\\dagger} \\Lmap$}\n\\label{sec:Derivatives-of-LTL}\n\nA common simple map transformation\nis $\\LTL(\\Lmap) \\equiv \\Lmap^{\\dagger} \\Lmap\n: \\Lspace(\\Vspace,\\Wspace) \\mapsto \\Lspace(\\Vspace,\\Vspace)$.\n\nThe partial derivative is computed using equations\n\\ref{eq:transpose-derivative}\nand\n\\ref{eq:map-product-derivative}:\n\n\\begin{equation}\n\\db{ij}{\\LTL}{\\Lmap}\n=\n\\left( \\e_j^{\\Vspace} \\otimes \\e_i^{\\Wspace} \\right) \\Lmap\n+\n\\Lmap^{\\dagger} \\left( \\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace} \\right)\n=\n\\left( \\e_j^{\\Vspace} \\otimes \\r_i^{\\Lmap} \\right)\n+\n\\left( \\r_i^{\\Lmap} \\otimes \\e_j^{\\Vspace} \\right)\n\\end{equation}\nwhere $\\r_i^{\\Lmap} \\in \\Vspace$ is the $i$th 'row' of $\\Lmap$\nin the representation $\\Lmap = \\sum_{i=0}^{m-1} \\e_i^{\\Wspace} \\otimes \\r_i^{\\Lmap}$.\n\nThe Jacobian, which has 4 indexes here, is given by:\n\\begin{equation}\n\\db{ij}{\\LTL_{kl}}{\\Lmap}\n =\n\\left( \\db{ij}{\\LTL}{\\Lmap} \\right)_{kl}\n=\n\\delta_{jl} \\Lmap_{ik}\n+\n\\delta_{jk} \\Lmap_{il}\n\\end{equation}\nwhere, as usual, $\\delta_{ij} = 1$ if $i=j$ and  $0$ if $i \\neq j$.\nFrom the Jacobian, we can compute the gradients of $\\LTL_{kl}$\nusing equation \\ref{eq:gradient-from-partials}\nand the fact that\n$\\Emap_{ij}^{\\Lspace(\\Vspace,\\Wspace)}  = \\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace}$\nare the canonical basis vectors for $\\Lspace(\\Vspace,\\Wspace)$:\n\\begin{eqnarray}\n\\Gb{\\LTL_{kl}}{\\Lmap}\n& = &\n\\sum_{ij}\n\\left( \\db{ij}{\\LTL_{kl}}{\\Lmap} \\right)\n\\left( \\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace} \\right)\n\\\\\n& = &\n\\sum_{ij}\n\\left( \\delta_{jl} \\Lmap_{ik} + \\delta_{jk} \\Lmap_{il} \\right)\n\\left( \\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace} \\right)\n\\nonumber\n\\\\\n& = &\n\\sum_{i}\n\\left(\n\\Lmap_{ik}  \\e_i^{\\Wspace} \\otimes \\e_l^{\\Vspace}\n\\right)\n+\n\\sum_{i}\n\\left(\n\\Lmap_{il}  \\e_i^{\\Wspace} \\otimes \\e_k^{\\Vspace}\n\\right)\n\\nonumber\n\\\\\n& = &\n\\left(\n\\c_k^{\\Lmap} \\otimes \\e_l^{\\Vspace}\n\\right)\n+\n\\left(\n\\c_l^{\\Lmap} \\otimes \\e_k^{\\Vspace}\n\\right)\n\\nonumber\n\\end{eqnarray}\nwhere $\\c_j^{\\Lmap} \\in \\Wspace$ is the $j$th 'column' of $\\Lmap$\nin the representation\n$\\Lmap = \\sum_{j=0}^{n-1} \\c_j^{\\Lmap} \\otimes \\e_j^{\\Vspace}$.\n\n%------------------------------------------------------------------\n\n\\subsubsection{Inverse}\n\\label{sec:Derivative-of-inverse}\n\n$\\Inverse()$ here is interpreted in the traditional sense:\n$\\Lmap^{-1}(\\w) = \\v$ if there exists a unique $\\v$ such that $\\w = \\Lmap(\\v)$,\nand is either considered undefined, or assigned an arbitrary\nvalue, such as $\\0$, otherwise.\nA map $\\Lmap : \\Vspace \\mapsto \\Wspace$ is {\\it invertible}\nif, for all $\\w \\in \\Wspace$, there exists a $\\v$ such that\n$\\w = \\Lmap \\v$.\nIn any reasonable topology,\nthe set of invertible linear maps $\\Vspace \\mapsto \\Wspace$\nis an open subset of the set of all linear maps,\nand $\\Inverse()$ is continuous and differentiable there.\n\nThe partial derivative is the value of the following, when the limit exists:\n\\begin{displaymath}\n\\db{ij}{\\Inverse()}{\\Lmap}\n =\n\\lim_{ h \\mapsto 0}\n\\frac{ \\left( \\Lmap + h (\\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace}) \\right)^{-1} - \\Lmap^{-1} }{h}\n\\end{displaymath}\nNote that\n\\begin{displaymath}\n\\Lmap + h (\\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace})\n =\n\\left( \\Identity^{\\Wspace} - ( -h ( \\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace} )) \\Lmap^{-1} \\right) \\Lmap\n\\end{displaymath}\nand\n\\begin{eqnarray*}\n\\left( \\Lmap + h (\\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace}) \\right)^{-1}\n& = &\n\\Lmap^{-1} \\left( \\Identity^{\\Wspace} - ( -h )( \\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace} ) \\Lmap^{-1} \\right)^{-1}\n\\\\\n& = &\n\\Lmap^{-1} \\sum_{k=0}^{\\infty} \\left( -h ( \\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace} ) \\Lmap^{-1} \\right)^{k}\n\\nonumber\n\\end{eqnarray*}\nTherefore\n\\begin{displaymath}\n\\frac{ \\left( \\Lmap + h (\\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace}) \\right)^{-1} - \\Lmap^{-1} }{h}\n =\n- \\Lmap^{-1} ( \\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace} )  \\Lmap^{-1} + O(h)\n\\end{displaymath}\nwhich implies\n\\begin{equation}\n\\da{ij}{\\Lmap^{-1}}\n =\n- \\left[\n\\Lmap^{-1}\n\\left( \\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace} \\right)\n\\Lmap^{-1}\n\\right]\n\\end{equation}\n\n\n\\subsubsection{Pseudo-inverse}\n\\label{sec:Derivative-of-pseudo-inverse}\n\n$\\Pseudoinverse(\\Lmap) \\equiv \\Lmap^{-}$\n\nIf $\\kernel(\\Lmap) = \\0$, $\\Lmap$ is said to have {\\it full rank}.\nThe set of full rank linear maps is an open set,\nand we can define the derivative of $\\Pseudoinverse(\\Lmap)$ there.\nFor a full rank map,\n$\\Lmap^{-} = \\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1} \\Lmap^{\\dagger}$\n(see equation \\ref{eq:full-rank-pseudo-inverse}).\nIt follows from equation \\ref{eq:map-product-derivative} that\n\\begin{eqnarray}\n\\db{ij}{\\Pseudoinverse}{\\Lmap}\n& = &\n\\db{ij}{\\Inverse(\\LTL())\\Transpose()}{\\Lmap}\n\\\\\n& = &\n\\left[\n\\left( \\db{ij}{\\Inverse(\\LTL())}{\\Lmap} \\right)\n\\Lmap^{\\dagger}\n\\right]\n+\n\\left[\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\db{ij}{\\Transpose()}{\\Lmap}\n\\right]\n\\nonumber\n\\\\\n& = &\n\\left[\n\\left( \\db{ij}{\\Inverse(\\LTL())}{\\Lmap} \\right)\n\\Lmap^{\\dagger}\n\\right]\n+\n\\left[\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\left( \\e_j^{\\Vspace} \\otimes \\e_i^{\\Wspace} \\right)\n\\right]\n\\nonumber\n\\end{eqnarray}\n\nBy the chain rule\n\\begin{eqnarray}\n\\Db{\\Inverse(\\LTL())}{\\Lmap}\n& = &\n\\sum_{kl}\n\\db{kl}{\\Inverse}{\\Lmap^{\\dagger}\\Lmap}\n\\otimes\n\\Gb{\\LTL_{kl}}{\\Lmap}\n\\\\\n& = &\n\\sum_{kl}\n- \\left[\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\left( \\e_k^{\\Vspace} \\otimes \\e_l^{\\Vspace} \\right)\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\right]\n\\otimes\n\\left[\n\\left( \\c_k^{\\Lmap} \\otimes \\e_l^{\\Vspace} \\right)\n+\n\\left( \\c_l^{\\Lmap} \\otimes \\e_k^{\\Vspace} \\right)\n\\right]\n\\nonumber\n\\end{eqnarray}\n\nTo minimize confusion,\nrecall that $\\Db{\\Inverse(\\LTL())}{\\Lmap}$ is\na linear map from $\\Lspace(\\Vspace,\\Wspace) \\mapsto \\Lspace(\\Vspace,\\Vspace)$.\nNote that the central tensor product ($\\otimes$) above\nis a product of\n$\n- \\left[\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\left( \\e_k^{\\Vspace} \\otimes \\e_l^{\\Vspace} \\right)\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\right]\n$,\nan element of $\\Lspace(\\Vspace,\\Vspace)$\nand\n$\n\\left[\n\\left( \\c_k^{\\Lmap} \\otimes \\e_l^{\\Vspace} \\right)\n+\n\\left( \\c_l^{\\Lmap} \\otimes \\e_k^{\\Vspace} \\right)\n\\right]\n$,\nan element of $\\Lspace(\\Vspace,\\Wspace)$.\n\nIt follows from equation \\ref{eq:partial-full-dervatives} that\n\\begin{eqnarray}\n\\db{ij}{\\Inverse(\\LTL())}{\\Lmap}\n& = &\n\\Db{\\Inverse(\\LTL())}{\\Lmap}\n\\left( \\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace} \\right)\n\\\\\n& = &\n\\sum_{kl}\n- \\left[\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\left( \\e_k^{\\Vspace} \\otimes \\e_l^{\\Vspace} \\right)\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\right]\n\\otimes\n\\left[\n\\left( \\c_k^{\\Lmap} \\otimes \\e_l^{\\Vspace} \\right)\n+\n\\left( \\c_l^{\\Lmap} \\otimes \\e_k^{\\Vspace} \\right)\n\\right]\n\\left( \\e_i^{\\Wspace} \\otimes \\e_j^{\\Vspace} \\right)\n\\nonumber\n\\\\\n& = &\n\\sum_{kl}\n- \\left[\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\left( \\e_k^{\\Vspace} \\otimes \\e_l^{\\Vspace} \\right)\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\right]\n\\left[\n\\delta_{jl}\n\\Lmap_{ik}\n+\n\\delta_{jk}\n\\Lmap_{il}\n\\right]\n\\nonumber\n\\\\\n& = &\n-\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\left[\n\\sum_{k}\n\\Lmap_{ik}\n\\left(\n\\left( \\e_k^{\\Vspace} \\otimes \\e_j^{\\Vspace} \\right)\n+\n\\left( \\e_j^{\\Vspace} \\otimes \\e_k^{\\Vspace} \\right)\n\\right)\n\\right]\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\nonumber\n\\\\\n& = &\n-\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\left[\n\\left( \\r_i^{\\Lmap} \\otimes \\e_j^{\\Vspace} \\right)\n+\n\\left( \\e_j^{\\Vspace} \\otimes \\r_i^{\\Lmap} \\right)\n\\right]\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\nonumber\n\\end{eqnarray}\n\nPutting it all together:\n\\begin{eqnarray}\n\\db{ij}{\\Pseudoinverse}{\\Lmap}\n& = &\n\\left[\n-\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\left[\n\\left( \\r_i^{\\Lmap} \\otimes \\e_j^{\\Vspace} \\right)\n+\n\\left( \\e_j^{\\Vspace} \\otimes \\r_i^{\\Lmap} \\right)\n\\right]\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\Lmap^{\\dagger}\n\\right]\n+\n\\left[\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\left( \\e_j^{\\Vspace} \\otimes \\e_i^{\\Wspace} \\right)\n\\right]\n\\nonumber\n\\\\\n& = &\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\left[\n\\left( \\e_j^{\\Vspace} \\otimes \\e_i^{\\Wspace} \\right)\n-\n\\left(\n\\left[\n\\left( \\r_i^{\\Lmap} \\otimes \\e_j^{\\Vspace} \\right)\n+\n\\left( \\e_j^{\\Vspace} \\otimes \\r_i^{\\Lmap} \\right)\n\\right]\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\Lmap^{\\dagger}\n\\right)\n\\right]\n\\nonumber\n\\\\\n& = &\n\\left( \\Lmap^{\\dagger} \\Lmap \\right)^{-1}\n\\left[\n\\left( \\e_j^{\\Vspace} \\otimes \\e_i^{\\Wspace} \\right)\n-\n\\left(\n\\left( \\r_i^{\\Lmap} \\otimes \\e_j^{\\Vspace} \\right)\n+\n\\left( \\e_j^{\\Vspace} \\otimes \\r_i^{\\Lmap} \\right)\n\\right)\n\\Lmap^{-}\n\\right]\n\\end{eqnarray}\n", "meta": {"hexsha": "166542c8faef398a40698b6f67525be59fc0fdbb", "size": 27212, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fosm/derivatives.tex", "max_stars_repo_name": "palisades-lakes/les-elemens", "max_stars_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/old/fosm/derivatives.tex", "max_issues_repo_name": "palisades-lakes/les-elemens", "max_issues_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/old/fosm/derivatives.tex", "max_forks_repo_name": "palisades-lakes/les-elemens", "max_forks_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.5840336134, "max_line_length": 111, "alphanum_fraction": 0.6008378656, "num_tokens": 10823, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.7198456245269955}}
{"text": "\\newpage\n\\subsection{Algorithms in Graph}\n\n\n\\begin{minipage}{.5\\linewidth}\n    \\den{Cut}{\n        A cut is a partition of the vertices of a graph into two disjoint subsets.\n        Any cut determines a cut-set, the set of edges that have one endpoint in\n        each subset of the partition. These edges are said to cross the cut. In a\n        connected graph, each cut-set determines a unique cut, and in some cases\n        cuts are identified with their cut-sets rather than with their vertex\n        partitions.\n    }\\label{definition:cut_graph_theory}\n\\end{minipage}\\hfill%\n\\begin{minipage}{.49\\linewidth}\n    \\begin{figure}[H]\n        \\begin{center}\n            \\subfloat[Minimum Cut]{\\includegraphics[width=.4\\textwidth]{Min-cut.pdf}}\n            \\hspace{1em}\n            \\subfloat[Maximum Cut]{\\includegraphics[width=.47\\textwidth]{Max-cut.pdf}}\n        \\end{center}\n    \\end{figure}\n\\end{minipage}\n\n\n\n\\begin{minipage}{.55\\linewidth}\n    \\theo{https://en.wikipedia.org/wiki/Prufer_sequence}\n    {Prufer sequence}{\n        Consider a labeled tree $ T $ with vertices's $ \\{1, 2, ..., n\\} $. At\n        step $ i $, remove the leaf with the smallest label and set the $ i $th\n        element of the \\textit{Prüfer sequence} to be the label of this leaf's\n        neighbour. Prove that a Prüfer sequence of length $ n-2 $ defines a Tree\n        with length $ n $.\n\n    }\n\\end{minipage}\\hfill%\n\\begin{minipage}{.45\\linewidth}\n    \\figdf{.4}{prufer_code_example}{${4,4,4,5}$}\n\\end{minipage}\n\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h5976p20088}\n{German TST 2004 E7P3}{M}{\n    We consider graphs with vertices colored black or white. ``Switching\" a\n    vertex means: coloring it black if it was formerly white, and coloring it\n    white if it was formerly black.\n\n    Consider a finite graph with all vertices colored white. Now, we can do the\n    following operation: Switch a vertex and simultaneously switch all of its\n    neighbours (i.e. all vertices connected to this vertex by an edge). Can we,\n    just by performing this operation several times, obtain a graph with all\n    vertices colored black?\n\n    \\index[strat]{Induction!German TST 2004 P3}\n    \\index[strat]{Constructive Algorithm!Compound moves!German TST 2004 P3}\n}\\label{problem:induction_type1_30}\n\n\\solu{A classical example of creating complex moves from counter cases.}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h589936p3493453}\n{ARO 2014 P9.8}{H}{\n    In a country of $n$ cities, an express train runs both ways between any\n    two cities. For any train, ticket prices either direction are equal, but\n    for any different routes these prices are different. Prove that the\n    traveler can select the starting city, leave it and go on, successively,\n    $n-1$ trains, such that each fare is smaller than that of the previous\n    fare. (A traveler can enter the same city several times.)\n\n    \\index[strat]{Global!Pigeonhole!ARO 2014 P9.8}\n}\n\n\\prob{https://artofproblemsolving.com/community/c6h364267}\n{Generalization of ARO 2014 P9.8}{H}{\n    Let $ A $ be a set of $ n $ points in the space. From the family of all\n    segments with endpoints in $ A $ , $ q $ segments have been selected and\n    colored yellow. Suppose that all yellow segments are of different length.\n    Prove that there exists a polygonal line composed of $ m $ yellow\n    segments, where $ m\\geq\\frac{2q}{n}$, arranged in order of increasing\n    length.\n\n    \\index[strat]{Global!Pigeonhole!ARO 2014 P9.8 Gene}\n    \\index[strat]{Constructive Algorithm!Deletetion!ARO 2014 P9.8 Gene}\n}\n\n\n\\begin{solution}\n    There are no local information given that we can use to consturct a way,\n    so our only bet is to try some global approach. We want at least one path\n    of length more than $n-1$, and there are a total of $\\frac{n(n-1)}{2}$\n    edges. So either we want to partition the edges in $\\frac{n}{2}$ paths, or\n    we count each edge twice and then partition then in $n$ paths, giving us\n    our desired result.\\\\\n\n    We figure out the second approach works. So we want to find $n$ paths that\n    begin at each of the $n$ vertices and cover all the edges twice. This idea\n    soon lead us to the magical solution:\\\\\n\n    \\textit{\\color{solC}Let one traveller go to each of the $n$ cities. Then we select the\n        costliest train and swap the two travellers on its two ends. We keep doing\n    this until all the trains have been used.\\\\}\n\n    This works because every traveller follows a path of gradually decreasing\n    train cost, and every edge is used exactly twice.\n\\end{solution} \n\n\\begin{solution}[ninjaturtle]\n    Consider the direct graph where each edge has two directions ($2q$\n    edges). A directed edge $e$ is called \\emph{terminal} if there isn't an edge $f$\n    with larger value such that the end vertex of $e$ is the same as the start\n    vertex of $f$.\\\\\n\n    At step $i$, we remove all terminal edges in the remaining\n    graph. If we can show that each step removes at most $n$ direct edges,\n    then $2q/n$ steps are required to remove all edges, implying there exists\n    a polygonal line of increasing length of length at least $2q/n$.\\\\\n\n    Let $I_i(a), O_i(a)$ be the in-degree and out-degree of $a$ before step\n    $i$. Assume we are at the time before step $k$. Put $m = O_k(a)$, and let\n    $e$ be the outgoing edge of $a$ with the largest value $v$. Then $v \\geq\n    m$. After step $k$, only incoming edges of $a$ with value $ \\geq m$ will\n    have possibly been removed. Thus $I_{k+1}(a) \\geq m-1 = O_k(a)-1$. Sum it\n    over all $a$\n    \\[\\#\\text{edges before step k+1} = \\sum_a I_{k+1}(a) \\geq \\sum_a O_k(a) -n\n    = \\#\\text{edges before step k}\\] \n    and we have shown the number of edges\n    after each step decreases by at most $n$.\n\\end{solution}\n\n\n\n\\prob{}\n{}{E}{\n    Given a bipartite graph, prove that the minimum number of colors required\n    to color the edges of the graph such that no node is adjacent to $ 2 $\n    edges of same color is the maximum degree of the graph.\n}\\label{problem:bipartite_graph_3}\n\n\n\\prob{}\n{}{E}{\n    For every bipartite graph prove that it's edges can be bicolored so that each\n    node is adjacent to atmost $ \\ceil{\\dfrac{deg}{2}} $ edges of  any color.\n}\\label{problem:bipartite_graph_4}\n\n\n\\solu{Using the main property of a bipartite graph.}\n\n\n\\solu{After finding the cycle solution, to optimize it, we recall that we can find a Eulerian Path (if it exists) in $ O(V+E) $. Now we want to make the graph have a Eulerian path, so we add a vertice to both sides of the graph, and join them with odd vertices from the other side.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h446932}\n{Turkey National MO 2002 P3}{HM}{\n    Graph Airlines $(GA)$ operates flights between some of the cities\n    of the Republic of Graphia. There are at least three $GA$ flights from each\n    city, and it is possible to travel from any city in Graphia to any city in\n    Graphia using $GA$ flights. $GA$ decides to discontinue some of its flights.\n    Show that this can be done in such a way that it is still possible to travel\n    between any two cities using $GA$ flights, yet at least $2/9$ of the cities\n    have only one flight.\n\n    \\textbf{\\Share\\color{probC}Simplified:} In a connected graph, every\n    vertex has degree at least $3$. Prove that some edges can be deleted to\n    turn that graph into a tree with at least $\\frac{2}{9}$ leaves. \n\n    \\textbf{\\Share\\color{probC}Better Approximation:} We can actually achieve\n    $\\frac{1}{4}$ with careful construction.\n\n    \\index[strat]{Constructive Algorithm!Inclusion!Turkey NMO 2002 P3}\n    \\index[strat]{Bounding!Cost function!Turkey NMO 2002 P3}\n}\n\n\\begin{solution}[dgrozev]\n    First we construct a spanning tree $T$ that maximizes the number of leaves,\n    then we bound the number. We define $G(V, E), n = \\left|V\\right| $ with\n    the usual notations.\\\\\n\n    Let $f: V \\to V$. We initialize the tree by selecting a vertex $v$ by\n    random, and adding it to $T$. We inductively add the vertices according to\n    the following priority checks:\n\n    \\begin{enumerate}[label=\\textbf{\\boxed{\\arabic*.}}, itemsep=5pt]\n        \\item If there is a vertex $v\\not \\in T$ that is connected to $u\\in T$\n            such that $u$ is not a leaf, then add $v, uv$ to $T$.\n        \\item If $u\\in T$ is a leaf and there are two $v_1, v_2$ not in $T$\n            that are connected to $u$, add $v_1, v_2$ and $uv_1, uv_2$ to $T$.\n        \\item If $u\\in T$ is a leaf, and there is a $v$ which has two\n            neighbors outside of $T$, then add $v, uv$ to $T$, and let $f(u)=v$.\n        \\item If $u\\in T$ is a leaf, there is a $v \\not \\in T$ which is\n            connected to at most one vertex outside $T$, and connected to\n            $u'\\in T$, then add $v, uv$ to $T$ and let $f(u) = u'$.\n    \\end{enumerate}\n    This algorithm will add all the vertices to the tree. We now need to bound\n    the number of leaves.\\\\\n\n    Let $n_1, n_2, n_3$ be the set of vertices that have $1, 2$ and more than\n    $3$ neighbors respectively. Since $f$ is a injection from the set $n_2$ to\n    either $n_1$ or $n_3$, we have since $n = n_1+n_2+n_3$,\n    \\[n_2 \\le n_1 + n_3,\\quad n_2 \\le \\frac{n}{2}\\]\n    Bounding the number of edges gives us:\n    \\[\\begin{aligned}\n        2n-2 &\\ge n_1 + 2n_2 + 3n_3\\\\\n             &= n_1 + 3(n-n_1) - n_2\\\\\n             &\\ge 3n - 2n_1 - \\frac{n}{2}\\\\\n        \\implies n_1 &\\ge \\frac{n}{4}+1\n    \\end{aligned}\\]\n\\end{solution}\n\n\\begin{solution}[\\href{http://wwwmayr.in.tum.de/konferenzen/Jass08/courses/1/gravin/Gravin_Slides.pdf}{Paper}]\n    The construction is the same as before. But we define a different cost\n    fuction $f$ to bound our leaves count. Let $D(T)$ be the number of leaves in\n    $T$ which doesn't have a neighbor outside of $T$. Let $L(T)$ be the number of\n    all leaves, and $V(T)$ is the number of vertices of $T$. Then consider \n    \\[\\boxed{f(T) = 3L(T) + D(T) - V(T)}\\] \n    We show that $f(T)$ is non decreasing in our construction. If it is, we\n    will get by setting $f(T_0)$ for a one vertex and its neighbor tree $T_0$, \n    \\[f(T) \\ge f(T_0) \\ge 3\\times 3 +0 -4 = 5 \\] \n    And since $D(T') = L(T')$ for a spanning tree $T'$, \\[L(T') \\ge \\frac{N+5}{4}\\] \n    We now check that for all of your steps in construction, $f(T)$ is non\n    decreasing.\n\\end{solution}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h100733p568964}{ISL 2005 C1}{E}{A house has an even number of lamps distributed among its rooms in such a way that there are at least three lamps in every room. Each lamp shares a switch with exactly one other lamp, not necessarily from the same room. Each change in the switch shared by two lamps changes their states simultaneously. Prove that for every initial state of the lamps there exists a sequence of changes in some of the switches at the end of which each room contains lamps which are on as well as lamps which are off.}\\label{problem:divide_and_conquer_4}\\label{problem:induction_type1_10}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h597130p3543398}{ISL 2013 C3}{M}{A crazy physicist discovered a new kind of particle which he called an $ i $ -mon, after some of them mysteriously appeared in his lab. Some pairs of $ i $ -mons in the lab can be entangled, and each $ i $ -mon can participate in many entanglement relations. The physicist has found a way to perform the following two kinds of operations with these particles, one operation at a time.\n\n    \\begin{enumerate}\n\n        \\item If some $ i $ -mon is entangled with an odd number of other $ i $ -mons in the lab, then the physicist can destroy it.\n\n        \\item At any moment, he may double the whole family of $ i $ -mons in the lab by creating a copy $ I' $ of each $ i $ -mon $ I $. During this procedure, the two copies $ I' $ and $ J' $ become entangled if and only if the original $ i $ -mons $ I $ and $ J $ are entangled, and each copy $ I' $ becomes entangled with its original $ i $ -mon $ I $ ; no other entanglements occur or disappear at this moment.\n\n    \\end{enumerate}\n\n    Prove that the physicist may apply a sequence of much operations resulting in a family of $ i $ -mons, no two of which are entangled.\n}\\label{problem:induction_type1_9}\n\n\n\\solu{As there are an integer number of $ i $ -mons, it is quite natural to use induction. We try to find an algorithm to reduce the number of particles.\n\nAnother way to do this is to consider the chromatic number of the graph. If we can show that this number reduces after some move, then we are done by induction.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h104152p586762}{ISL 2005 C2}{E}{A forest consists of rooted (i. e. oriented) trees. Each vertex of the forest is either a leaf or has two successors. A vertex $ v $ is called an extended successor of a vertex $ u $ if there is a chain of vertices's $ u_{0}=u , u_{1}, u_{2} \\dots u_{t-1} , u_{t}=v $ with $ t>0 $ such that the vertex $ u_{i+1} $ is a successor of the vertex $ u_{i} $ for every integer $ i $ with $ 0\\leq i\\leq t-1 $.\\\\\n\n    Let $ k $ be a nonnegative integer. A vertex is called dynastic if it has two successors and each of these successors has at least $ k $ extended successors.\\\\\n\nProve that if the forest has $ n $ vertices, then there are at most $ \\frac{n}{k+2} $ dynastic vertices.}\\label{problem:induction_type1_8}\n\n\\solu{Trying to apply induction, we realize the bound is very loosy. That's why when we try to add in the inductive step, the value becomes larger than the bound. To stop that overflow, we tighten the bound.}\n\n\\solu{The second and dummy approach is to first doing some smaller cases, finding small infos, taking the root, seeing that the bound doesnt work, but it would work if one of the successors of the root would have exactly or less than $ 2k+3 $ successors. As we can't always guarantee that, we look for such a vertex with $ 2k+3 $ successors. We do some work with it and by induction its done.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1441121p8200413}{All Russia 2017 9.1}{E}{In a country some cities are connected by oneway flights (There are no more then one flight between two cities). City $ A $ called \"available\" for city $ B $ , if there is flight from $ B $ to $ A $ , maybe with some transfers. It is known, that for every 2 cities $ P $ and $ Q $ exist city $ R $ , such that $ P $ and $ Q $ are available from $ R $. Prove, that exist city $ A $ , such that every city is available for $ A $.}\\label{problem:induction_type1_17}\n\n\n\n\\prob{www.google.com}{Jacob Tsimerman Induction}{E}{There are $ 2010 $ ninjas in the village of Konoha (what? Ninjas are cool.) Certain ninjas are friends, but it is known that there do not exist $ 3 $ ninjas such that they are all pairwise friends. Find the maximum possible number of pairs of friends.(If ninja $ A $ is friends with ninja $ B $ , then ninja $ B $ is also friends with ninja $ A $.)}\\label{problem:induction_type1_16}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h420430p2374818}{USA TST 2011 D3P2}{M}{Let $n \\geq 1$ be an integer, and let $S$ be a set of integer pairs $(a,b)$ with $1 \\leq a < b \\leq 2^n$. Assume $|S| > n \\cdot 2^{n+1}$. Prove that there exists four integers $a < b < c < d$ such that $S$ contains all three pairs $(a,c)$, $(b,d)$ and $(a,d)$.}\\label{problem:induction_type1_19}\n\n\\solu{Using Induction to the first and last half of the set $ S $ shows us the \\hrf{finding_the_tough_nut}{hardest part} of the problem. Then ordering the left and right elements with some sort of hierarchy is all the work left to do.}\n\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1480703p8639274}{ISL 2016 C6}{H}{There are $ n \\geq 3 $ islands in a city. Initially, the ferry company offers some routes between some pairs of islands so that it is impossible to divide the islands into two groups such that no two islands in different groups are connected by a ferry route.\\\\\n\n    After each year, the ferry company will close a ferry route between some two islands $ X $ and $ Y $. At the same time, in order to maintain its service, the company will open new routes according to the following rule: for any island which is connected to a ferry route to exactly one of $ X $ and $ Y $, a new route between this island and the other of $ X $ and $ Y $ is added.\\\\\n\nSuppose at any moment, if we partition all islands into two nonempty groups in any way, then it is known that the ferry company will close a certain route connecting two islands from the two groups after some years. Prove that after some years there will be an island which is connected to all other islands by ferry routes.}\\label{problem:induction_type1_11}\n\n\\solu{It is only natural to use induction on this kinda problems. After some trying, we see that if we remove $ 1 $ node, We get to nowhere, but if we remove $ 2 $ nodes, we get something interesting. So now focus on those two nodes and the rest of the nodes separately. Its not hard from there.}\n\n\\solu{As it seems, the separation of the graph was the main observation. We can call this trick \\hl{Bringing Order in the Chaos}.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h535003p3067563}{ARO 2013 P9.5}{M (8/10)}{$ 2n $ real numbers with a positive sum are aligned in a circle. For each of the numbers, we can see there are two sets of $ n $ numbers such that this number is on the end. Prove that at least one of the numbers has a positive sum for both of these two sets.}\\label{problem:graph_representation_4}\\label{problem:minus_constant_2}\n\n\\solu{Since there is nothing specfic about the sum, we may safely assume that it is $ 0 $, because (1) probably it works, and (2) it makes things more convenient. How we do that? we decrease every number by the average.\\\\\n\n    Now, Consider every block of $ n $ consecutive blockes of numbers. When are two blocks connected? When they share the same end. What if we consider them as vertices, and this ``connectivity'' as edges? We see that cycles pop out.\\\\\n\nAnd we make use of the fact that our sum is $ 0 $. So signs are sure to bet flipped at the opposite side, and there are odd and even -ness in cycles that we can use.}\n\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h420424p2374799}{USA TST 2011 P2}{HM (9/10)}{In the nation of Onewaynia, certain pairs of cities are connected by roads. Every road connects exactly two cities (roads are allowed to cross each other, e.g., via bridges). Some roads have a traffic capacity of 1 unit and other roads have a traffic capacity of $ 2 $ units. However, on every road, traffic is only allowed to travel in one direction. It is known that for every city, the sum of the capacities of the roads connected to it is always odd. The transportation minister needs to assign a direction to every road. Prove that he can do it in such a way that for every city, the difference between the sum of the capacities of roads entering the city and the sum of the capacities of roads leaving the city is always exactly one.}\\label{problem:divide_and_conquer_1}\\label{problem:induction_type2_3}\n\n\\solu{As there are two types of subgraph, $ 1 $ -type and $ 2 $ -type. By some work-arounds, we see that we have to work distinctly in both types of graphs. Firstly, if we work in type- $ 1 $ , we see after making a path from node $ x, y $ , the degrees of $ x, y $ will be $ \\{1, -1\\} $ and the degrees of other nodes on the path will be the same. After that, we make every nodes have degree either $ \\{1, -1\\} $. So after this operation we remove the $ 1 $ -edges. Now, when dealing with the type- $ 2 $ sub-graph. Start over from zero, we see that when making a path between nodes $ x, y $ the degree of those two changes parity, and other nodes on the path stays the same. So select two odd nodes.... }\n\n\\solu{Dealing with two different kind of edges simultaneously is messy, so we work with graph $ 1 $ and graph $ 2 $ differently. Now on both graphs, we can remove cycles. And in graph $ 2 $ , we see that we can remove any big paths if there is a edge $ 1 $ joining the two endpoints. Since if the new graph works then the previous graph works too. [Several cases to show here] And if there is no edge joining the two endpoints, replace the path by joining the two endpoints by a edge $ 2 $.\\\\\n\nNow there are only edge $ 1 $ s, and lone edge $ 2 $ s. Now dividing the graph $ 1 $ into paths of edge $ 1 $ , and dealing with several small cases, we are done.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h276187p1494557}\n{Iran TST 2009 P6}{E-M (9/10)}{\n    We have a closed path that goes from one vertex to another neighboring\n    vertex, on the vertices of a $ n\\times n$ square which pass throgugh each\n    vertex exactly once. Prove that we have two adjacent vertices such that if\n    we cut the path at these two points then the length of each open paths is\n    at least $ n^2/4 $.\n\n    \\index[strat]{Different representation!Graph!Iran TST 2009 P6}\n}\n\n\\begin{solution}[grobber]\n    After drawing the closed path we notice that it divides the grid into a\n    tree like structure, which we definitely need to explore!\\\\\n\n    After drawing the tree with the unit squares as vertices, we try to\n    reformulate our problem in our new tree. We want to find an edge of\n    this tree that will divide the tree into two parts, and those two part\n    should have perimeter more than $\\frac{n^2}{4}$. \\\\\n\n    We know of \\hrf{theorem:Pick's Theorem}{Pick's Theorem} which lets us\n    relate area with perimiter of such polygons. Which we use to do some\n    bounding. We also need to show that if every vertex in a tree has degree \n    at most $4$, then there is an edge that divides the tree into two ``big''\n    portions, which we will use.\n\\end{solution}\n\n\\prob{https://artofproblemsolving.com/community/c6h85771p499536}\n{Iran TST 2006}{E}{\n    Suppose we have a simple polygon (that is it does not intersect itself,\n    but not necessarily convex). Show that this polygon has a diagonal which\n    is completely inside the polygon and the two arcs it creates on the\n    polygon perimeter (the two arcs have 2 vertices in common) both have at\n    least one third of the vertices of the polygon.\n\n    \\index[strat]{Different representation!Graph!Iran TST 2006}\n    \\index[strat]{Extremal!Iran TST 2006}\n    \\index[strat]{Induction!Iran TST 2006}\n}\n\n\\begin{solution}[grobber]\n    First we triangulate the polygon. Now we take the diagonal that divides\n    the polygon into two arcs whose difference in length is the least. We show\n    that it satisfies the requirement.\n\\end{solution}\n\n\\begin{solution}[induction]\n    After the triangulation, we can also do induction on the number of\n    triangles, by removing a ``outer'' triangle.\n\\end{solution}\n\n\\begin{solution}[graph transformation]\n    We can convert the problem into a graph by considering the triangles as\n    vertices and joining two vertices if they share a common side. Then this\n    graph is a tree of which all vertices have degree at most $3$. And we know\n    that in any graph with maximum degree $3$, there is way to remove an edge\n    to divide the graph into two subgraphs with at least $\\frac{n}{3}$\n    vertices.\n\\end{solution}\n\n\n\n\\prob{https://math.stackexchange.com/questions/1439430/algorithm-to-uniquely-determine-a-number-using-two-adjacent-digits}\n{OC Chap2 P2}{M (6/10)}{\\label{problem:bijection_2}\\label{problem:hall_marriage_1}\n    Arutyun and Amayak perform a magic trick as follows. A spectator writes\n    down on a board a sequence of $ N $ (decimal) digits. Amayak covers two\n    adjacent digits by a black disc. Then Arutyun comes and says both closed\n    digits (and their order). For which minimal $ N $ can this trick always\n    work? NOTE: Arutyun and Amayak have a strategy determined beforehand.\n\n    \\index[strat]{Graph!Matching!OC Chap2 P2}\n    \\index[strat]{Construction!OC Chap2 P2}\n}\n\n\\solu{\n    We have to actually find a bijection between all of the combinations the\n    spectator can create, and all of the combinations that Arutyun might see\n    when he comes back. Which tells us to use ``Perfect Matching\" tricks.\n}\n\n\\solu{[Existence]\n    For this trick to always work, they have to make a bijection from a set of\n    $N$ digits with two covered, to an unique set of $N$ digits. Consider a\n    bijection from the set of $0-9$ strings with length $N$ to the set of\n    $0-9$ strings with length $N$ with $2$ adjacent digits unknown.  There\n    exist a bijection iff the two sets satisfy Hall's Marriage Theorem.  By\n    double counting we get the value of $N$ from here.\n}\n\n\n\\prob{}\n{Simurgh 2019 P3}{E}{\n    Call a graph \\textit{symmetric}, if one can put its vertices on the plane\n    such that it becomes symmetric wrt a line (which doesn't pass through any\n    vertex). Find the minimum value of $ k $ such that (the edges of) every\n    graph on $ 100 $ vertices, can be decomposed into $ k $ symmetric\n    subgraph.\n\n    \\index[strat]{Construction!Simurgh 2019 P3}\n}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h2019175p14186360}\n{RMM 2020 P3}{MH}{\n    Let $n\\ge 3$ be an integer. In a country there are $n$ airports and $n$\n    airlines operating two-way flights. For each airline, there is an odd\n    integer $m\\ge 3$, and $m$ distinct airports $c_1, \\dots, c_m$, where the\n    flights offered by the airline are exactly those between the following\n    pairs of airports: $c_1$ and $c_2$; $c_2$ and $c_3$; $\\dots$ ; $c_{m-1}$\n    and $c_m$; $c_m$ and $c_1$.\n\n    Prove that there is a closed route consisting of an odd number of flights\n    where no two flights are operated by the same airline.\n\n    \\index[strat]{Induction!RMM 2020 P3}\n    \\index[strat]{Construction!Greedy!RMM 2020 P3}\n    \\index[strat]{Graph!Hall Marriage!RMM 2020 P3}\n    \\index[strat]{Graph!Bipartite!RMM 2020 P3}\n}\n\n\\solu{[Weird Induction]\n    Fix one vertice, merge all neighbors with it that has a unique airline between them.\n}\n\n\\solu{[Element of Time]\n    Add one edge from each cycle one at a time, without creating a cycle. Our\n    objective is to show that when we reach the maximum stage where one edge\n    creates a cycle, that cycle is of odd length.\n}\n", "meta": {"hexsha": "4af65fcb2fd077efd5867b045016e7658a99ee1d", "size": 26097, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combi/sec5_2_graph_alogrithm.tex", "max_stars_repo_name": "M-Ahsan-Al-Mahir/BCS_Question_Bank", "max_stars_repo_head_hexsha": "83ff9b542999386ea182863e4f25f0b488d3984f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 48, "max_stars_repo_stars_event_min_datetime": "2020-10-14T17:15:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T19:47:04.000Z", "max_issues_repo_path": "combi/sec5_2_graph_alogrithm.tex", "max_issues_repo_name": "AnglyPascal/BCS_Question_Bank", "max_issues_repo_head_hexsha": "83ff9b542999386ea182863e4f25f0b488d3984f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "combi/sec5_2_graph_alogrithm.tex", "max_forks_repo_name": "AnglyPascal/BCS_Question_Bank", "max_forks_repo_head_hexsha": "83ff9b542999386ea182863e4f25f0b488d3984f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-10-15T08:59:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-27T15:19:26.000Z", "avg_line_length": 59.0429864253, "max_line_length": 904, "alphanum_fraction": 0.7116526804, "num_tokens": 7257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.7198009931681624}}
{"text": "\\section{Higher Order Heterogeneous Equations}\r\n\\noindent\r\nIf we modify our equation for free vibrations to have a function as the net force, then out equations becomes\r\n\\begin{equation*}\r\n\tmy'' + by' + ky = b(x).\r\n\\end{equation*}\r\nDepending on the form of $b(x)$, like a $\\sin$ or $\\cos$ curve or an exponential, we might be able to guess the form of the solution.\r\nHowever, there is an important thing to keep in mind.\r\n\r\n\\begin{theorem}\r\n\tIf $f(x)$ is a solution to the above equation, and $g(x)$ is a solution to the homogeneous form of the equation $b(x) = 0$, then $f(x) + g(x)$ is also a solution to the above equation.\r\n\\end{theorem}\r\n\\begin{proof}\r\n\tIf $f(x) + g(x)$ is a solution, then\r\n\t\\begin{equation*}\r\n\t\tm\\left(f(x) + g(x)\\right)'' + b\\left(f(x) + g(x)\\right)' + k\\left(f(x) + g(x)\\right) = b(x).\r\n\t\\end{equation*}\r\n\tRearranging,\r\n\t\\begin{equation*}\r\n\t\t\\left(mf''(x) + bf'(x) + kf(x)\\right) + \\left(mg''(x) + bg'(x) + kg(x)\\right) = 0.\r\n\t\\end{equation*}\r\n\tUsing the definitions of $f(x)$ and $g(x)$,\r\n\t\\begin{equation*}\r\n\t\tb(x) + 0 = b(x).\r\n\t\\end{equation*}\r\n\\end{proof}\r\n\r\n\\noindent\r\n$f(x)$ and $g(x)$ actually have special meanings in terms of solving these higher-order equations.\r\n\\begin{definition}\r\n\t$f(x)$ is called the particular solution to the heterogeneous equation, and $g(x)$ is called a homogeneous solution.\r\n\\end{definition}\r\n\r\n\\input{./higherOrder/nonHomeg/undeterminedCoeffs.tex}\r\n\\input{./higherOrder/nonHomeg/variationParameters.tex}", "meta": {"hexsha": "0f111fdcb992fd3ea1279c1e87d899f111358a50", "size": 1468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/nonHomeg/nonHomeg.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/higherOrder/nonHomeg/nonHomeg.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/higherOrder/nonHomeg/nonHomeg.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 41.9428571429, "max_line_length": 186, "alphanum_fraction": 0.6689373297, "num_tokens": 457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7197330296789036}}
{"text": "\\section{Task A}\n\\label{sec:task-a}\n\nThe 2nd Piola-Kirchhoff stress can be obtained from free energy using\nequation \\eqref{eq:PK2} in \\cite{Bonet2008}:\n\\begin{equation} \\tag{6.18}\n  \\label{eq:PK2}\n  \\utilde{S} = 2 \\frac{\\partial \\Psi}{\\partial \\utilde{C}} =\n  2 \\frac{\\partial \\Psi}{\\partial I_{C}} \\frac{\\partial I_{C}}{\\partial \\utilde{C}} +\n  2 \\frac{\\partial \\Psi}{\\partial II_{C}} \\frac{\\partial II_{C}}{\\partial \\utilde{C}}+\n  2 \\frac{\\partial \\Psi}{\\partial III_{C}} \\frac{\\partial III_{C}}{\\partial \\utilde{C}}\n\\end{equation}\nwith derivatives of invariants of Green-Lagrange deformation tensor defined as\n(\\(J = \\det \\left( \\utilde{F} \\right)\\))\n\\begin{align}\n  \\frac{\\partial I_{C}}{\\partial \\utilde{C}} &= \\utilde{I} \\tag{6.19a} \\\\\n  \\frac{\\partial II_{C}}{\\partial \\utilde{C}} &= 2 \\utilde{C} \\tag{6.19b} \\\\\n  \\frac{\\partial III_{C}}{\\partial \\utilde{C}} &= J^{2} \\utilde{C}^{-1} \\tag{6.22}\n\\end{align}\nFind the missing derivatives of the free energy (given in the task) with respect\nto the invariants:\n\\begin{align}\n  \\frac{\\partial \\Psi}{\\partial I_{C}} &= \n  \\frac{\\mu}{2} + 2 c_{2}\\left( I_{C} - 3 \\right) + 3c_{3}\\left( I_{C} - 3 \\right)^{2}\\\\\n  \\frac{\\partial \\Psi}{\\partial II_{C}} &= 0 \\\\\n  \\frac{\\partial \\Psi}{\\partial III_{C}} &= \\frac{\\lambda \\ln{J} - \\mu}{2 J^{2}}\n\\end{align}\nLastly, the expression for the 2nd Piola-Kirchhoff stress yields\n\\begin{equation}\n  \\label{eq:PK2yeoh}\n  \\utilde{S} = \\left[ \\mu + 4c_{2}\\left( I_{C} - 3 \\right) +\n    6c_{3}\\left( I_{C} - 3 \\right)^{2}\\right] \\utilde{I} + \n  \\left( \\lambda \\ln{J} - \\mu \\right) \\utilde{C}^{-1}\n\\end{equation}\nThe Lagrangian elasticity tensor can be obtained using equation \n\\eqref{eq:elast-tensor-Lagrange}:\n\\begin{equation} \\tag{6.11}\n  \\label{eq:elast-tensor-Lagrange}\n  \\uutilde{C} = \\frac{\\partial \\utilde{S}}{\\partial \\utilde{E}} = \n  2 \\frac{\\partial \\utilde{S}}{\\partial \\utilde{C}}\n\\end{equation}\nExpanding invariants to have explicit dependence on \\(\\utilde{C}\\) yields\n(\\textit{note the overbar open product})\n\\begin{equation}\n  \\label{eq:dSdC}\n  \\frac{\\partial \\utilde{S}}{\\partial \\utilde{C}} = \n  \\left[ 4c_{2} + 12c_{3}\\left( I_{C} - 3 \\right) \\right] \n      \\utilde{I} \\otimes \\utilde{I} + \n      \\frac{\\lambda}{2} \\utilde{C}^{-1} \\otimes \\utilde{C}^{-1} +\n      \\left( \\mu - \\lambda \\ln{J} \\right) \\utilde{C}^{-1} \\overline{\\otimes}\n      \\utilde{C}^{-1}\n\\end{equation}\nCauchy stress is a push-forward of the 2nd Piola-Kirchhoff:\n\\begin{equation} \\tag{5.45b}\n  \\label{eq:cauchy-push}\n  \\utilde{\\sigma} = J^{-1} \\utilde{F} \\cdot \\utilde{S} \\cdot \\utilde{F}^{T}\n\\end{equation}\nFigure~\\ref{fig:sigma-eps} shows component of Cauchy stress plotted against\nengineering strain for the situation of uniaxial strain control\n\\(\\utilde{F} = F_{11} \\ubar{\\bm{e}}_{1} \\otimes \\ubar{\\bm{E}}_{1}\\).\nIt is evident that the curve is nonlinear.\n\\begin{figure}[th]\n  \\pgfplotstableset{\n    create on use/Y/.style={create col/copy column from table={data/task_a_sig11.dat}{0}}\n  }\n  \\centering\n  \\begin{tikzpicture}\n    \\begin{axis}[\n      width = 0.95\\textwidth,\n      height=\\axisdefaultheight,\n%      tick label style={/pgf/number format/fixed},\n      try min ticks=6,\n      minor tick num=1,\n      grid=both,\n      xmin=0, xmax=1.5,\n      xlabel = {\\( \\varepsilon_{11}\\), [-]},\n      ylabel = {\\( \\sigma_{11} \\), [MPa]},\n      ]\n      \\addplot table[y=Y,skip first n=1] {data/task_a_eps11.dat};\n    \\end{axis}\n  \\end{tikzpicture}  \n  \\caption{Cauchy stress component \\(\\sigma_{11}\\) versus strain\n    \\(\\varepsilon_{11} = F_{11} - 1\\).}\n  \\label{fig:sigma-eps}\n\\end{figure}\n\nThe Matlab implementation of this task can be found in \\texttt{yeoh.m}\n(see section \\ref{app:matlab-code}).\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../main\"\n%%% End:\n", "meta": {"hexsha": "a18c6f2664e7fac61b93ca82a91510799018cf0e", "size": 3741, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/sec/task_a.tex", "max_stars_repo_name": "iamrosk/hyperelasticity", "max_stars_repo_head_hexsha": "b4f33e0c4f79473df47f29cce398b61e264f204b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-14T00:14:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-14T00:14:05.000Z", "max_issues_repo_path": "doc/sec/task_a.tex", "max_issues_repo_name": "iamrosk/hyperelasticity", "max_issues_repo_head_hexsha": "b4f33e0c4f79473df47f29cce398b61e264f204b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/sec/task_a.tex", "max_forks_repo_name": "iamrosk/hyperelasticity", "max_forks_repo_head_hexsha": "b4f33e0c4f79473df47f29cce398b61e264f204b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-14T03:19:55.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-14T03:19:55.000Z", "avg_line_length": 39.7978723404, "max_line_length": 89, "alphanum_fraction": 0.6396685378, "num_tokens": 1415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.7196788207786509}}
{"text": "\\section{Points, products and orientation}\nIn this first section, we define our point representation, we explain how the dot and cross products we saw in 2D translate into 3D, and we show how a combination of the two, the \\emph{mixed product}, can help us define a 3D analog of the \\lstinline|orient()| function.\n\n\\subsection{Point representation}\nWe will define points and vectors in space by their coordinates $(x,y,z)$: their positions along three perpendicular axes.\n\n\\centerFig{p3-0}\n\nAs we did in 2D, we start with some basic operators.\n\\begin{lstlisting}\ntypedef double T;\nstruct p3 {\n    T x,y,z;\n    \n    // Basic vector operations\n    p3 operator+(p3 p) {return {x+p.x, y+p.y, z+p.z};}\n    p3 operator-(p3 p) {return {x-p.x, y-p.y, z-p.z};}\n    p3 operator*(T d) {return {x*d, y*d, z*d};}\n    p3 operator/(T d) {return {x/d, y/d, z/d};} // only for floating-point\n    \n    // Some comparators\n    bool operator==(p3 p) {return tie(x,y,z) == tie(p.x,p.y,p.z);}\n    bool operator!=(p3 p) {return !operator==(p);}\n};\n\\end{lstlisting}\nChoosing the scalar type \\lstinline|T| is done the same way as in 2D, see \\ref{ss:point-representation} for our remarks on that.\n\nFor convenience, we also define a zero vector $\\vv{0}=(0,0,0)$:\n\\begin{lstlisting}\np3 zero{0,0,0};\n\\end{lstlisting}\n\n\\subsection{Dot product}\nThe dot product is exactly the same as in 2D. It is defined as \\[\\dotv{v}{w} = \\normv{v}\\normv{w} \\cos\\theta\\] where $\\normv{v}$ and $\\normv{w}$ are the lengths of the vectors and $\\theta$ is amplitude of the angle between $\\vv{v}$ and $\\vv{w}$.\n%This amplitude $\\theta$ is measured on the plane that contains both $\\vv{v}$ and $\\vv{w}$.\nSo in other words, the 3D dot product of $\\vv{v}$ and $\\vv{w}$ is equal to the 2D dot product they would have on a plane that contains them both.\n\nWe recall the possible cases for the sign of the dot product:\n\\centerFig{products0}\n\n%Since 3D geometry requires a very good mastery of the properties of dot and cross product, we recall all of them here and add a few:\nWe recall some properties of dot product and add a few:\n\\begin{itemize}\n%\\item $\\dotv{v}{w}$ is a measure of how parallel $\\vv{v}$ and $\\vv{w}$ are;\n\\item symmetry: $\\dotv{v}{w} = \\dotv{w}{v}$;\n\\item linearity: $(\\vv{v_1}+\\vv{v_2})\\cdot\\vv{w} = \\dotv{v_1}{w} + \\dotv{v_2}{w}$ (also on the right);\n%\\vv{v}\\cdot(\\vv{w_1}+\\vv{w_2}) &= \\dotv{v}{w_1} + \\dotv{v}{w_2}\n%\\end{align*}\n\\item $\\dotv{v}{w} = 0$ iff $\\vv{v}$ and $\\vv{w}$ are perpendicular;\n\\item $\\dotv{v}{w}$ stays constant if $\\vv{w}$ moves perpendicular to $\\vv{v}$.\n%\\item in physics, if $\\vv{F}$ is a force applied along displacement $\\vv{s}$, the work done is $W=\\dotv{F}{s}$.\n\\end{itemize}\n\nLike in 2D, dot product is very simple to implement:\n\\begin{lstlisting}\nT operator|(p3 v, p3 w) {return v.x*w.x + v.y*w.y + v.z*w.z;}\n\\end{lstlisting}\n\nSince 3D geometry uses dot and cross product a lot, to shorten notations we will be using operator \\lstinline{|} for dot product and operator \\lstinline{*} for cross product. We chose them for these mostly arbitrary reasons:\n\\begin{itemize}\n\\item \\lstinline{|} has a lower precedence than \\lstinline|*| which is desirable, it kind of looks like a ``parallel'' operator, and since it most often has to be parenthesized (e.g. \\ttt{(v|w) == 0}), it can be a bit reminiscent of the inner product notation $\\langle v,w \\rangle$;\n\\item \\lstinline|*| is the closest thing to a cross in overloadable R++ operators, and the compiler doesn't produce a warning if you don't paranthesize \\lstinline|b*c| in expressions such as \\lstinline{a|b*c}, which we will use a lot.\n\\end{itemize}\n\nWe define the usual \\lstinline{sq()} and \\lstinline{abs()} based on dot product and add a \\lstinline|unit()| function that makes the norm of a vector equal to 1 while preserving its direction.\n\\begin{lstlisting}\nT sq(p3 v) {return v|v;}\ndouble abs(p3 v) {return sqrt(sq(v));}\np3 unit(p3 v) {return v/abs(v);}\n\\end{lstlisting}\n\nLike in 2D, we can also use dot product to find the amplitude in $[0,\\pi]$ of the angle between vectors $\\vv{v}$ and $\\vv{w}$, see secton~\\ref{ss:dot} for more details.\n\\begin{lstlisting}\ndouble angle(p3 v, p3 w) {\n    double cosTheta = (v|w) / abs(v) / abs(w);\n    return acos(max(-1.0, min(1.0, cosTheta)));\n}\n\\end{lstlisting}\n\n\\subsection{Cross product}\nWhile the cross product in 2D is a scalar, in 3D it is a vector. If $\\vv{v}$ and $\\vv{w}$ are parallel, $\\crossv{v}{w} = \\vv{0}$, and otherwise it is defined as\n\\[\\crossv{v}{w} = (\\normv{v}\\normv{w} \\sin\\theta)\\vv{n}\\]\nwhere $\\normv{v}$ and $\\normv{w}$ are the lengths of the vectors, $\\theta$ is amplitude of the angle between $\\vv{v}$ and $\\vv{w}$, and $\\vv{n}$ is a unit vector perpendicular to both $\\vv{v}$ and $\\vv{w}$ chosen using the right-hand rule. Note that the norm of the 3D cross product is equal to the absolute value of the 2D cross product.\n\n\\centerFig{p3-1}\n\nThe right-hand rule says this: if you take your right hand, align your thumb with $\\vv{v}$ and your extended index $\\vv{w}$, and fold your middle finger at a $90\\degree$ angle, then it will point in the direction of $\\crossv{v}{w}$. Another way to express it is to say that if you draw $\\vv{v}$ and $\\vv{w}$ on a sheet of paper and look at the sign of their 2D cross product, if it is positive $\\crossv{v}{w}$ will point up from the sheet, and if it is negative $\\crossv{v}{w}$ will point down through the sheet.\n\n\\centerFig{p3-2}\n\nWe summarize some key properties of the cross product:\n\\begin{itemize}\n\\item anti-symmetry: $\\crossv{v}{w} = -\\crossv{w}{v}$;\n\\item linearity: $(\\vv{v_1}+\\vv{v_2})\\times\\vv{w} = \\crossv{v_1}{w} + \\crossv{v_2}{w}$ (also on the right);\n\\item $\\crossv{v}{w}$ is perpendicular to both $\\vv{v}$ and $\\vv{w}$;\\footnote{\\label{f:if-not-zero}if $\\crossv{v}{w} \\neq \\vv{0}$}\n\\item $\\crossv{v}{w}$ is perpendicular to the plane containing $\\vv{v}$ and $\\vv{w}$;\\cref{f:if-not-zero}\n\\item $\\crossv{v}{w} = \\vv{0}$ iff $\\vv{v}$ and $\\vv{w}$ are parallel;\n\\item $\\crossv{v}{w}$ stays constant if $\\vv{w}$ moves parallel to $\\vv{v}$.\n%\\item in physics, if $\\vv{F}$ is a force applied with a lever arm vector $\\vv{r}$, the resulting torque is $\\vv{\\tau} = \\crossv{r}{F}$.\n\\end{itemize}\n\nAmong those, the one which we will use most often is the fact that it is perpendicular to $\\vv{v}$ and $\\vv{w}$.\n\nThe cross product can be computed this way:\n\\begin{lstlisting}\np3 operator*(p3 v, p3 w) {\n    return {v.y*w.z - v.z*w.y,\n            v.z*w.x - v.x*w.z,\n            v.x*w.y - v.y*w.x};\n}\n\\end{lstlisting}\nIndeed, it is easy to check that this vector is perpendicular to both $\\vv{v}$ and $\\vv{w}$ using dot product. Here it is for $\\vv{v}$:\n\\begin{align*}\n(\\crossv{v}{w})\\cdot \\vv{v}\n&= (v_yw_z - v_zw_y, v_zw_x - v_xw_z, v_xw_y - v_yw_x) \\cdot (v_x,v_y,v_z) \\\\\n&= v_xv_yw_z - v_xv_zw_y + v_yv_zw_x - v_yv_xw_z + v_zv_xw_z - v_zv_yw_x \\\\\n&= 0\n\\end{align*}\n\nNote that the $z$-coordinate is the same expression as the 2D cross product: indeed, it is the value of the 2D cross product if $\\vv{v}$ and $\\vv{w}$ are projected onto plane $z=0$.\n\n\\subsection{Mixed product and orientation}\\label{ss:mixed-orient}\nA very useful combination of dot product and cross product is the \\emph{mixed product}. We define the mixed product of three vectors $\\vv{u}$, $\\vv{v}$ and $\\vv{w}$ as\n\\[(\\crossv{u}{v})\\cdot\\vv{w}\\]\n\nLet $\\Pi$ be the plane containing $\\vv{u}$ and $\\vv{v}$. We know that $\\vv{n}=\\crossv{u}{v}$ is perpendicular to $\\Pi$, and $\\dotv{n}{w}$ will be positive if the angle between $\\vv{n}$ and $\\vv{w}$ is less than $90\\degree$. This will happen if $\\vv{w}$ points to the same side of $\\Pi$ as $\\vv{n}$, while when $\\dotv{n}{w}$ is negative $\\vv{w}$ will point to the opposite side.\n\nThe two cases are illustrated in the drawings below. The plane containing $\\vv{u}$ and $\\vv{v}$ is viewed from the side:\n\\centerFig{p3-3}\n\nNote that this is similar to how the 2D cross product $\\crossv{v}{w}$ tells us to which side of to line containing $\\vv{v}$ vector $\\vv{w}$ points. So, we similarly define an \\lstinline|orient()| function based on it:\n\\[\\orient(P,Q,R,S) = \\left(\\crossv{PQ}{PR}\\right)\\cdot\\vv{PS}\\]\nIt is positive if $S$ is on the side of plane $PQR$ in the direction of $\\crossv{PQ}{PR}$, negative if $S$ is on the other side, and zero if $S$ is on the plane.\n\n%To simplify the discussion, we will say that $S$ is on the positive side of $PQR$ when $\\orient(P,Q,R,S)>0$, and on its negative side when $\\orient(P,Q,R,S)<0$.\n\n\\centerFig{p3-4}\n\nThis $\\orient()$ function has several very nice properties. First, it stays the same if we swap any three arguments in a circular way: for example let's take $P,Q,S$, then $\\orient(P,Q,R,S) = \\orient(Q,S,R,P)$. On the other hand, swapping any two arguments changes its sign: for example, $\\orient(P,Q,R,S) = -\\orient(P,S,R,Q)$.\n\n\\newcommand{\\mixedPropsExoQ}{\n    Show that those properties also apply to the mixed product. For example, $(\\crossv{u}{v})\\cdot\\vv{w} = (\\crossv{v}{w})\\cdot\\vv{u}$ and $(\\crossv{u}{v})\\cdot\\vv{w} = -(\\crossv{u}{w})\\cdot\\vv{v}$.\n}\n\\newcommand{\\mixedPropsExoA}{\n    This can be derived from the properties of $\\orient(P,Q,R,S)$ by setting $P=\\vv{0}$, $Q=\\vv{u}$, $R=\\vv{v}$ and $S=\\vv{w}$. Indeed, in this case\n    \\begin{align*}\n    \\orient(P,Q,R,S)\n    &= \\left(\\crossv{PQ}{PR}\\right)\\cdot\\vv{PS} \\\\\n    &= \\left[\\left(\\vv{u}-\\vv{0}\\right)\\times\\left(\\vv{v}-\\vv{0}\\right)\\right]\\cdot\\left(\\vv{w}-\\vv{0}\\right) \\\\\n    &= (\\crossv{u}{v})\\cdot\\vv{w}\n    \\end{align*}\n}\n\\exoWithSolution{\\protect\\mixedPropsExoQ}{\\protect\\mixedPropsExoA}{mixed-props}\n\nEarlier, we implicitly assumed that $P,Q,R$ were not collinear, but in general $\\orient(P,Q,R,S)$ is zero if and only if $P,Q,R,S$ are coplanar, so when any three points are collinear it is always zero. We can also say that it is nonzero if and only if lines $PQ$ and $RS$ are skew, that is, neither intersecting nor parallel.\n\nFinally, $|\\!\\orient(P,Q,R,S)|$ is equal to six times the volume of tetrahedron $PQRS$.% (just like in 2D $|\\orient(P,Q,R)|$ is equal to two times the area of triangle $PQR$).\n\nIt is implemented by simply writing down the definition:\n\\begin{lstlisting}\nT orient(p3 p, p3 q, p3 r, p3 s) {return (q-p)*(r-p)|(s-p);}\n\\end{lstlisting}\n\n\\newcommand{\\skewExpressionExoStatement}{\n    A convenient way to check whether two lines $PQ$ and $RS$ are skew is to check whether $\\left(\\crossv{PQ}{RS}\\right)\\cdot\\vv{PR} \\neq 0$: in fact you can replace $PR$ by any vector going from $PQ$ to $RS$.\n\n    Using the properties of dot product, cross product and $\\orient()$, prove that\n    \\[\\left(\\crossv{PQ}{RS}\\right)\\cdot\\vv{PR} = -\\orient(P,Q,R,S)\\]\n}\n\\newcommand{\\skewExpressionExoSol}{\n    Note that for any vectors $\\vv{v}$ and $\\vv{w}$ we have $(\\crossv{v}{w})\\cdot\\vv{w} = 0$. This is because $\\crossv{v}{w}$ is perpendicular to $\\vv{w}$ and the dot product is zero for perpendicular vectors.\n    \n    We develop:\n    \\begin{align*}\n        \\left(\\crossv{PQ}{RS}\\right)\\cdot\\vv{PR}\n        &= \\left(\\vv{PQ}\\times\\left(\\vv{PS}-\\vv{PR}\\right)\\right)\\cdot\\vv{PR} \\\\\n        &= \\left(\\crossv{PQ}{PS} - \\crossv{PQ}{PR}\\right)\\cdot\\vv{PR} \\\\\n        &= \\left(\\crossv{PQ}{PS}\\right)\\cdot\\vv{PR} - \\left(\\crossv{PQ}{PR}\\right)\\cdot\\vv{PR} \\\\\n        &= \\left(\\crossv{PQ}{PS}\\right)\\cdot\\vv{PR} \\\\\n        &= \\orient(P,Q,S,R) \\\\\n        &= -\\orient(P,Q,R,S)\n    \\end{align*}\n}\n\n\\exoWithSolution{\\protect\\skewExpressionExoStatement}{\\protect\\skewExpressionExoSol}{skew-expression}\n\nLet's say we have a plane $\\Pi$ and a vector $\\vv{n}$ perpendicular to it (a \\emph{normal} to the plane).\nThen an interesting variant is to replace $\\vv{PS}$ by $\\vv{n}$, giving the expression\n\\[\\left(\\crossv{PQ}{PR}\\right)\\cdot\\vv{n}\\]\nThis is equivalent to computing the 2D $\\orient(P',Q',R')$ on $\\Pi$, where $P',Q',R'$ are the projections of $P,Q,R$ on $\\Pi$.\n\n\\centerFig{p3-5}\n\n\\begin{lstlisting}\nT orientByNormal(p3 p, p3 q, p3 r, p3 n) {return (q-p)*(r-p)|n;}\n\\end{lstlisting}\n", "meta": {"hexsha": "4386d3d3025e0cc7c768e37503e21469cb301765", "size": 11876, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/3d/p3.tex", "max_stars_repo_name": "cbarnson/UVa", "max_stars_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_stars_repo_licenses": ["Unlicense", "MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-07T17:00:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-05T02:08:35.000Z", "max_issues_repo_path": "archives/codelibraries/cp-geo-master/3d/p3.tex", "max_issues_repo_name": "cbarnson/UVa", "max_issues_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_issues_repo_licenses": ["Unlicense", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "archives/codelibraries/cp-geo-master/3d/p3.tex", "max_forks_repo_name": "cbarnson/UVa", "max_forks_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_forks_repo_licenses": ["Unlicense", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.2842639594, "max_line_length": 512, "alphanum_fraction": 0.6710171775, "num_tokens": 3935, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7193838707445784}}
{"text": "\\section{The matrix of a linear transformation}\n\\label{sec:matrix-of-transformation}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find the matrix corresponding to a linear transformation\n    $T:\\R^n\\to\\R^m$.\n  \\end{enumerate}\n\\end{outcome}\n\nAn important example of linear transformations are the so-called\n\\textbf{matrix transformations}%\n\\index{matrix transformation}%\n\\index{linear transformation!matrix transformation}.\n\n\\begin{proposition}{Matrix transformations are linear transformations}{matrix-are-linear}\n  Let $A$ be an $m\\times n$-matrix, and consider the vector function\n  $T:\\R^n\\to \\R^m$ defined by $T(\\vect{v}) = A\\vect{v}$. Then $T$\n  is a linear transformation.\n\\end{proposition}\n\n\\begin{proof}\n  This follows from the laws of matrix multiplication. Namely, by the\n  distributive law, we have\n  $A(\\vect{v}+\\vect{w}) = A\\vect{v} + A\\vect{w}$, showing that $T$\n  preserves addition. And by the compatibility of matrix multiplication\n  and scalar multiplication, we have $A(k\\vect{v}) = k(A\\vect{v})$,\n  showing that $T$ preserves scalar multiplication.\n\\end{proof}\n\nIn fact, matrix transformations are not just an example of linear\ntransformations, but they are essentially the {\\em only} example. One\nof the central theorems in linear algebra is that all linear\ntransformations $T:\\R^n\\to\\R^m$ are in fact matrix transformations.\nTherefore, a matrix can be regarded as a notation for a linear\ntransformation, and vice versa. This is the subject of the following\ntheorem.\n\n\\begin{theorem}{Linear transformations are matrix transformations}{matrix-of-linear-transformation}\n  Let $T:\\R^n\\to\\R^m$ be any linear transformation. Then there exists\n  an $m\\times n$-matrix $A$%\n  \\index{linear transformation!matrix of!in Rn@in $\\R^n$}%\n  \\index{matrix!of a linear transformation!in Rn@in $\\R^n$} such that for all\n  $\\vect{v}\\in\\R^n$,\n  \\begin{equation*}\n    T(\\vect{v}) = A\\vect{v}.\n  \\end{equation*}\n  In other words, $T$ is a matrix transformation.\n\\end{theorem}\n\n\\begin{proof}\n  Suppose $T:\\R^n\\to \\R^m$ is a linear transformation and consider\n  the standard basis $\\set{\\vect{e}_1,\\ldots,\\vect{e}_n}$ of $\\R^n$.\n  For all $i$, define $\\vect{u}_i = T(\\vect{e}_i)$, and let $A$ be the\n  matrix that has $\\vect{u}_1,\\ldots,\\vect{u}_n$ as its columns. We\n  claim that $A$ is the desired matrix, i.e., that\n  $T(\\vect{v}) = A\\vect{v}$ holds for all $\\vect{v}\\in\\R^n$.\n\n  To see this, let\n  \\begin{equation*}\n    \\vect{v} =\n    \\begin{mymatrix}{c} x_1 \\\\ \\vdots \\\\ x_n \\end{mymatrix}\n  \\end{equation*}\n  be some arbitrary element of $\\R^n$. Then\n  $\\vect{v} = x_1\\vect{e}_1 + \\ldots + x_n\\vect{e}_n$, and we have:\n  \\begin{equation*}\n    \\begin{array}{rcl@{\\quad}l}\n      T(\\vect{v})\n      &=& T(x_1\\vect{e}_1 + \\ldots + x_n\\vect{e}_n)\n      \\\\\n      &=& T(x_1\\vect{e}_1) + \\ldots + T(x_n\\vect{e}_n)\n      & \\mbox{by linearity} \\\\\n      &=& x_1T(\\vect{e}_1) + \\ldots + x_nT(\\vect{e}_n)\n      & \\mbox{by linearity} \\\\\n      &=& x_1\\vect{u}_1 + \\ldots + x_n\\vect{u}_n\n      & \\mbox{by definition of $\\vect{u}_i$} \\\\\n      &=& A\\vect{v}\n      & \\mbox{by the column method of matrix multiplication.}\n    \\end{array}\n  \\end{equation*}\n\\end{proof}\n\nIn summary, the matrix corresponding to the linear transformation $T$\nhas as its columns the vectors $T(\\vect{e}_1),\\ldots,T(\\vect{e}_n)$,\ni.e., the images of the standard basis vectors. We can visualize this\nmatrix as follows:\n\\begin{equation*}\n  A=\n  \\begin{mymatrix}{ccc}\n    | &  & | \\\\\n    T(\\vect{e}_1) & \\cdots & T(\\vect{e}_n) \\\\\n    | &  & |\n  \\end{mymatrix}.\n\\end{equation*}\n\n\\begin{example}{The matrix of a linear transformation}{matrix-of-linear-transformation}\n  Suppose $T:\\R^3\\rightarrow \\R^2$ is a linear transformation where\n  \\begin{equation*}\n    T\\paren{\\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 0 \\end{mymatrix}}\n    = \\begin{mymatrix}{r} 1 \\\\ 2 \\end{mymatrix},\\quad\n    T\\paren{\\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix}}\n    = \\begin{mymatrix}{r} 9 \\\\ -3 \\end{mymatrix},\\quad\\mbox{and}\\quad\n    T\\paren{\\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 1 \\end{mymatrix}}\n    = \\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Find the matrix $A$ such that $T(\\vect{v})=A\\vect{v}$ for all\n  $\\vect{v}$.\n\\end{example}\n\n\\begin{solution}\n  By Theorem~\\ref{thm:matrix-of-linear-transformation}, the columns of\n  $A$ are $T(\\vect{e}_1)$, $T(\\vect{e}_2)$, and $T(\\vect{e}_3)$. Therefore,\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rrr}\n      1 & 9 & 1 \\\\\n      2 & -3 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{The matrix of a linear transformation}{matrix-of-linear-transformation2}\n  Let $T:\\R^3\\to\\R^2$ be the linear transformation defined by\n  \\begin{equation*}\n    T\\paren{\\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}}\n    =\n    \\begin{mymatrix}{c} x+y \\\\ x+2y-z \\end{mymatrix},\n  \\end{equation*}\n  for all $x,y,z\\in\\R$. Find the matrix of this linear transformation.\n\\end{example}\n\n\\begin{solution}\n  We compute the images of the standard basis vectors:\n  \\begin{eqnarray*}\n    T(\\vect{e}_1)\n    &=& T\\paren{\\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\end{mymatrix}}\n    ~=~ \\begin{mymatrix}{c} 1 \\\\ 1 \\end{mymatrix}, \\\\\n    T(\\vect{e}_2)\n    &=& T\\paren{\\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 0 \\end{mymatrix}}\n    ~=~ \\begin{mymatrix}{c} 1 \\\\ 2 \\end{mymatrix}, \\\\\n    T(\\vect{e}_3)\n    &=& T\\paren{\\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 1 \\end{mymatrix}}\n    ~=~ \\begin{mymatrix}{c} 0 \\\\ -1 \\end{mymatrix}.\n  \\end{eqnarray*}\n  The matrix $A$ has $T(\\vect{e}_1)$, $T(\\vect{e}_2)$, and\n  $T(\\vect{e}_3)$ as its columns. Therefore,\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rrr}\n      1 & 1 & 0 \\\\\n      1 & 2 & -1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Matrix of a projection map}{projection-matrix}\n  Let $\\vect{u} = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 3 \\end{mymatrix}$ and\n  let $T: \\R^3 \\to \\R^3$ be the projection%\n  \\index{projection!as a linear transformation} map defined by\n  \\begin{equation*}\n    T(\\vect{v}) = \\proj_{\\vect{u}}(\\vect{v})\n  \\end{equation*}\n  for all $\\vect{v} \\in \\R^3$.\n  \\begin{enumerate}\n  \\item[(a)] Is $T$ a linear transformation?\n  \\item[(b)] If yes, find the matrix of $T$.\n  \\end{enumerate}\n\\end{example}\n\n\\begin{solution}\n  \\begin{enumerate}\n  \\item[(a)] Recall the formula for the projection of $\\vect{v}$ onto\n    $\\vect{u}$:\n    \\begin{equation*}\n      \\proj_{\\vect{u}}(\\vect{v})\n      = \\frac{\\vect{u}\\dotprod \\vect{v}}{\\vect{u}\\dotprod \\vect{u}}\\,\\vect{u}.\n    \\end{equation*}\n    In the situation we are interested in, $\\vect{u}$ is a fixed vector,\n    and $\\vect{v}$ is the input to the function $T$. Given any two\n    vectors $\\vect{v},\\vect{w}$, and using the distributive laws of the dot\n    product and scalar multiplication, we have:\n    \\begin{equation*}\n      \\proj_{\\vect{u}}(\\vect{v}+\\vect{w})\n      = \\frac{\\vect{u}\\dotprod(\\vect{v}+\\vect{w})}{\\vect{u}\\dotprod \\vect{u}}\\,\\vect{u}\n      = \\paren{\\frac{\\vect{u}\\dotprod \\vect{v}}{\\vect{u}\\dotprod \\vect{u}}\n        + \\frac{\\vect{u}\\dotprod \\vect{w}}{\\vect{u}\\dotprod \\vect{u}}}\\,\\vect{u}\n      = \\frac{\\vect{u}\\dotprod \\vect{v}}{\\vect{u}\\dotprod \\vect{u}}\\,\\vect{u}\n      + \\frac{\\vect{u}\\dotprod \\vect{w}}{\\vect{u}\\dotprod \\vect{u}}\\,\\vect{u}\n      = \\proj_{\\vect{u}}(\\vect{v})\n      + \\proj_{\\vect{u}}(\\vect{w}).\n    \\end{equation*}\n    Therefore, the function\n    $T(\\vect{v}) = \\proj_{\\vect{u}}(\\vect{v})$ preserves\n    addition. Also, given any scalar $k$, we have\n    \\begin{equation*}\n      \\proj_{\\vect{u}}(k\\vect{v})\n      = \\frac{\\vect{u}\\dotprod (k\\vect{v})}{\\vect{u}\\dotprod \\vect{u}}\\,\\vect{u}\n      = \\paren{k\\frac{\\vect{u}\\dotprod \\vect{v}}{\\vect{u}\\dotprod \\vect{u}}}\\,\\vect{u}\n      = k\\paren{\\frac{\\vect{u}\\dotprod \\vect{v}}{\\vect{u}\\dotprod \\vect{u}}\\,\\vect{u}}\n      = k\\,\\proj_{\\vect{u}}(\\vect{v}).\n    \\end{equation*}\n    Therefore, the function $T$ preserves scalar multiplication. It\n    follows that $T$ is a linear transformation.\n\n  \\item[(b)] To find the matrix of $T$, we must compute the images of\n    the standard basis vectors $T(\\vect{e}_1),\\ldots,T(\\vect{e}_3)$. We compute\n    \\begin{eqnarray*}\n      T(\\vect{e}_1)\n      &=& \\proj_{\\vect{u}}(\\vect{e}_1)\n      ~=~ \\frac{\\vect{u}\\dotprod\\vect{e}_1}{\\vect{u}\\dotprod \\vect{u}}\\,\\vect{u}\n      ~=~ \\frac{1}{14}\\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 3 \\end{mymatrix}, \\\\\n      T(\\vect{e}_2)\n      &=& \\proj_{\\vect{u}}(\\vect{e}_2)\n      ~=~ \\frac{\\vect{u}\\dotprod\\vect{e}_2}{\\vect{u}\\dotprod \\vect{u}}\\,\\vect{u}\n      ~=~ \\frac{2}{14}\\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 3 \\end{mymatrix}, \\\\\n      T(\\vect{e}_3)\n      &=& \\proj_{\\vect{u}}(\\vect{e}_3)\n      ~=~ \\frac{\\vect{u}\\dotprod\\vect{e}_3}{\\vect{u}\\dotprod \\vect{u}}\\,\\vect{u}\n      ~=~ \\frac{3}{14}\\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 3 \\end{mymatrix}.\n    \\end{eqnarray*}\n    Hence the matrix of $T$ is\n    \\begin{equation*}\n      A = \\frac{1}{14}\\begin{mymatrix}{rrr}\n        1 & 2 & 3 \\\\\n        2 & 4 & 6 \\\\\n        3 & 6 & 9\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{enumerate}\n\\end{solution}\n\n", "meta": {"hexsha": "59fde17452d1059cb540cb6a950d499cdc8c27e5", "size": 8910, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/LinearTransformationsRn-Matrix.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/LinearTransformationsRn-Matrix.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/LinearTransformationsRn-Matrix.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 38.7391304348, "max_line_length": 99, "alphanum_fraction": 0.6182940516, "num_tokens": 3297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324893519999, "lm_q2_score": 0.8824278618165526, "lm_q1q2_score": 0.7193838624622708}}
{"text": "%---------------------------Aspect Frobenius-----------------------------\n\\section{Aspect Frobenius\\label{s:tet-aspect-Frobenius}}\n\nThe edge matrix of the tetrahedral element is defined as\nfollows:\n\\[\nT_0 = (\\vec{L_0}\\;\\vec{L_1}\\;\\vec{L_2})\n\\]\nand let $W$ be the edge matrix of the reference regular tetrahedron.\nConsider the matrix that maps $W$ into $T_0$:\n\\[\nA_0 = T_0 W^{-1}.\n\\]\nThe Frobenius norm of $A_0$ is\n\\[\n|A_0|_F = \\sqrt{\\mathrm{tr}(A_0^T\\, A_0)},\n\\]\nand the Frobenius condition number is the condition number associated\nwith this norm.\n\nThe aspect Frobenius of the element is defined as the normalized\n(equal to $1$ when the element is regular) Frobenius condition number of $A_0$.\n\n\\tetmetrictable{aspect Frobenius}%\n{$1$}%                                                Dimension\n{$[1,1.3]$}%                                          Acceptable range\n{$[1,DBL\\_MAX]$}%                                     Normal range\n{$[1,DBL\\_MAX]$}%                                     Full range\n{$1$}%                                                Unit equilateral triangle value\n{\\cite{knu:00}}%                                      Reference(s)                   \n{v\\_tet\\_aspect\\_frobenius}%                            Verdict function name\n", "meta": {"hexsha": "67e7a1ccd206d6ee61d13531e9e4d62a53df027b", "size": 1248, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetAspectFrobenius.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetAspectFrobenius.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetAspectFrobenius.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 39.0, "max_line_length": 85, "alphanum_fraction": 0.5176282051, "num_tokens": 320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099069962657177, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7193090654724951}}
{"text": "\n\\section{The \\issorted algorithm}\n\\Label{sec:issorted}\n\nOur version of the \\issorted algorithm compared to the \\cxx Standard\nLibrary \\cite[\\S 28.7.1.5]{cxx-17-draft} has the signature\n\\begin{lstlisting}[style = acsl-block]\n\n  bool is_sorted(const value_type* a, size_type n);\n\\end{lstlisting}\n\nIt returns \\inl{true} if the given array is in increasing order, and\n\\inl{false} otherwise.\n\n\\FloatBarrier\n\n\\subsection{Formal specification of \\issorted}\n\nThe following listing shows the acsl specification of \\issorted.\n%\nIn the contract, we use the predicate \\logicref{Increasing},\nwhich states that any array element is always less or equal to any other element right of it.\n%\nWe'll use an easier-to-handle predicate in the implementation of \\implref{issorted}.\n\n\\input{Listings/is_sorted.h.tex}\n\n\\clearpage\n\n\\subsection{Implementation of \\issorted}\n\nThe implementation of \\issorted is shown in the next Listing.\n%\nAs usual, \\issorted doesn't compare every array element to all that are right\nto it, but only to the immediately adjacent one, which is of course\nmore efficient.\nFor this, we use the predicate \\logicref{WeaklyIncreasing}\nin the loop invariant of the implementation.\n\n\\input{Listings/is_sorted.c.tex}\n\nSince our implementation uses \\WeaklyIncreasing in its loop invariant, and\nfollows the same principle in its code, its verification is\nstraight-forward---except for the final reasoning that\n\\inl{WeaklyIncreasing(a,n)} implies \\inl{Increasing(a,n)}.\n\nWe have the lemma \\logicref{WeaklyIncreasingIncreasing} for that step,\nwhich needs to be proven manually with \\coq.\n%\nThe converse lemma \\logicref{IncreasingWeaklyIncreasing}\nis proven automatically, but isn't actually needed to verify our\n\\issorted implementation.\nAlternatively, we could have dragged the predicate \\Increasing along the\nloop, which happens to cause no particular problems in this case.\n\n\\clearpage\n\n", "meta": {"hexsha": "d261a2616fb344aa8a8382a192820d3ead205524", "size": 1882, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/sorting/is_sorted.tex", "max_stars_repo_name": "fraunhoferfokus/acsl-by-example", "max_stars_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2017-06-14T04:17:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T06:07:36.000Z", "max_issues_repo_path": "Informal/sorting/is_sorted.tex", "max_issues_repo_name": "fraunhoferfokus/acsl-by-example", "max_issues_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-10-18T13:30:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T07:10:16.000Z", "max_forks_repo_path": "Informal/sorting/is_sorted.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 32.4482758621, "max_line_length": 93, "alphanum_fraction": 0.7906482465, "num_tokens": 453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503206, "lm_q2_score": 0.8723473846343393, "lm_q1q2_score": 0.719217197680104}}
{"text": "\\chapter{Shapes}\n\n\\section{Angles}\n\nTwo intersecting lines form an angle\\footnote{\\url{https://en.wikipedia.org/wiki/Angle}}.\n\nTwo lines are parallel iff they don't intersect.\n\nTwo lines coincide iff the angle between them is zero.\n\nTwo lines are orthogonal iff the angle between them is a right angle.\n\nWe use a protractor\\footnote{\\url{https://en.wikipedia.org/wiki/Protractor}} to measure an angle in degrees.\nA full circle is 360 degrees,\na half circle is 180 degrees,\na quarter circle is 90 degrees,\nand so on.\n\nA full turn is 360 degrees,\na half turn is 180 degrees,\na quarter turn is 90 degrees,\nand so on.\n\n\\section*{Degrees and radians}\n\nDegrees are convenient for manual calculation\nbecause 360 is divisible by several small integers.\n\nRadians\\footnote{\\url{https://en.wikipedia.org/wiki/Radian}} simplify formulas.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Radian\\#Advantages_of_measuring_in_radians}}\nFor example,\nlet \\(c\\) be the circumference of\na circular sector of angle \\(a\\) and radius \\(r\\).\nIf \\(a\\) is in radians, then \\(c\\) has the simple formula \\(c = a \\cdot r\\),\nbut if \\(a\\) is in degrees, the formula becomes \\(c = (a / \\ang{360}) \\cdot r\\).\n\nWe prefer the unit that simplifies our jobs.\nEngineers prefer degrees.\nMathematicians prefer radians.\nBoth units are widely used,\nso let's learn to convert one to the other.\n\nAn angle of \\(2\\pi\\) radians is equal to an angle of \\(360\\) degrees.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Radian\\#Conversion_between_radians_and_degrees}}\nBoth of them are equal to one full turn:\n\\Formula{\n    \\frac{d}{360} = \\frac{r}{2\\pi}\n}\n\nTo convert \\(r\\) radians to \\(d\\) degrees:\n\\Formula{\n    d = \\frac{360}{2\\pi} \\cdot r\n}\n\nTo convert \\(d\\) degrees to \\(r\\) radians:\n\\Formula{\n    r = \\frac{2\\pi}{360} \\cdot d\n}\n\n\\ExerciseAnswer{Convert \\ang{360} to radians?}{\\(2\\pi/1\\) radians.}\n\\ExerciseAnswer{Convert \\ang{180} to radians?}{\\(2\\pi/2\\) radians.}\n\\ExerciseAnswer{Convert \\ang{90} to radians?}{\\(2\\pi/4\\) radians.}\n\\ExerciseAnswer{Convert \\ang{45} to radians?}{\\(2\\pi/8\\) radians.}\n\n\\ShowAnswers\n\n\\section{Circles}\n\n\\footnote{\\url{https://en.wikipedia.org/wiki/Circular_sector}}\n\n\\section{Triangles}\n\nA vertex is a point where two sides meet.\n\nA triangle is called a triangle because it has three angles.\nA triangle also has three vertices and three sides.\n\nThe sum of all interior angles of a triangle is 180 degrees.\n\nAn equilateral triangle is a triangle whose sides have the same length.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Equilateral_triangle}}\nEach interior angle of such triangle is \\ang{60}.\n\n\\enquote{Equilateral} is the Latinate of \\enquote{same-sided}.\n\nThe study of triangles is called \\enquote{trigonometry}.\n\n\\paragraph{Labeling a triangle}\n\nA capital letter labels an interior angle.\nThe corresponding small letter labels the side across the angle.\nFor example, \\(a\\) is the side across the angle \\(A\\).\n\n\\subsection*{Drawing a standard right triangle}\n\nA right angle is 90 degrees.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Right_angle}}\n\nA right triangle is a triangle that has a \\ang{90} interior angle.\n\nSee the footnote\\footnote{\\url{https://commons.wikimedia.org/wiki/File:Rtriangle.svg}}\nfor the picture of a standard right triangle.\nHere we describe that triangle.\n\nLet there be a triangle \\(ABC\\).\n\nLet the angle \\(C\\) be a right angle.\n\nLet \\(a\\) be the side across angle \\(A\\).\n\nLet \\(b\\) be the side across angle \\(B\\).\n\nLet \\(c\\) be the side across angle \\(C\\).\nThus, \\(c\\) is the hypotenuse\\footnote{\\url{https://en.wikipedia.org/wiki/Hypotenuse}},\nthe longest side of a right triangle,\nthe side across the right angle.\n\nSuch triangle is called a standard right triangle.\n\n\\section*{Triangle side ratios}\n\nConsider a standard right triangle.\n\nThe sine of the angle \\(A\\) is \\(\\sin(A) = a/c\\).\n\nThe cosine of the angle \\(A\\) is \\(\\cos(A) = b/c\\).\n\nThe tangent of the angle \\(A\\) is \\(\\tan(A) = a/b\\).\n\n\\section*{Trigonometric identities}\n\nWe can show these by drawing:\n\\( \\sin(0) = 0 \\),\nand \\( \\cos(0) = 1 \\),\nand \\( \\sin(\\pi/2) = 1 \\),\nand \\( \\cos(\\pi/2) = 0 \\).\n\nThe Pythagorean theorem implies \\((\\sin(A))^2 + (\\cos(A))^2 = 1\\).\n\nThe sine function has a period of \\(2\\pi\\).\nIt means that \\(\\sin(a + 2\\pi) = \\sin(a)\\) for every real number \\(a\\).\n\nWe have \\(\\cos A = \\sin\\left(\\frac{\\pi}{2}-A\\right)\\)\nbecause \\(A+B+C = \\pi\\) and \\(C = \\pi/2\\) and \\(A+B = \\pi/2\\).\n\nSee also Wikipedia\\footnote{\\url{https://en.wikipedia.org/wiki/Special_right_triangle}}%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Right_triangle}}.\n\n\\section*{Inverse trigonometric functions}\n\nWe can measure an angle by the ratio of the sides of the right triangle formed by the angle.\nWe use inverse trigonometric functions (inverse sine, inverse cosine, inverse tangent).\n", "meta": {"hexsha": "4340a3db37a354d07e8f9f5b79adb137a00103ec", "size": 4759, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/shape.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/physics/shape.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/physics/shape.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 31.1045751634, "max_line_length": 108, "alphanum_fraction": 0.7144358058, "num_tokens": 1314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594992, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7192171942605904}}
{"text": "\\section*{Appendix D: Regularization parameter derivative}\n\\addcontentsline{toc}{section}{Appendix D: Regularization parameter derivative}\nUsing the gradient method, the solution $x_{n+1}$ at iteration $n+1$ is found \nfrom the solution $x_n$ at iteration $n$ by\n\\begin{eqnarray}\nx_{n+1} = x - d_s -  \\alpha d_n\n\\end{eqnarray}\nwith $d_s = \\frac{\\partial h_s(y-x)}{\\partial x}$ and $d_n = \\frac{\\partial h_n(x)}{\\partial x}$.\n\nand the final solution $x$ should verify\n\\begin{eqnarray}\n\\frac{1}{N} \\sum_{pix} (\\frac{y-x}{\\sigma})^2 = 1\n\\end{eqnarray}\nwhere $N$ is the number of pixels. If $\\alpha$ is too high, the solution will\nbe oversmoothed and the residual standard deviation will be greater than the \nnoise, when a too small $\\alpha$ will generate a noisy solution, and the \nresidual standard deviation will be smaller than the noise.\nNoting $R_{\\sigma}  = \\frac{1}{N} \\sum_{pix} (\\frac{y-x_{n+1}}{\\sigma})^2 - \\sigma$,\nthe difference between the standard deviation of the residual and the noise,\nthe optimal $\\alpha$ at iteration $n$ is found by minimizing the functional:\n\\begin{eqnarray}\nK(\\alpha) & = & \\mid  R_{\\sigma} \\mid \\\\\n          & = & \\mid \\frac{1}{\\sigma^2}\\sum_{pix} (y^2  +  x_{n+1}^2 - 2 x_{n+1} y - N) \\mid\n\\end{eqnarray}\nand \n\\begin{eqnarray}\n\\frac{\\partial K}{\\partial \\alpha} = \\frac{2}{N\\sigma^2} \\sum_{pix}  \n (\\frac{\\partial x_{n+1}}{\\partial \\alpha} x_{n+1} \n   - 2y \\frac{\\partial x_{n+1}}{\\partial \\alpha})\n\\end{eqnarray}\nwhen $R_{\\sigma} > 0$, and the opposite otherwise.\nAs $\\frac{\\partial x_{n+1}}{\\partial \\alpha} = - d_n$, we have\n\\begin{eqnarray}\n\\frac{\\partial K}{\\partial \\alpha} & = & \\frac{2}{N\\sigma^2} \\sum_{pix} (y d_n - d_n x_{n+1})) \\\\\n                                   & = & \\frac{2d_n }{N\\sigma^2}\\sum_{pix}  (y - x_{n+1})\n\\end{eqnarray}\nThen the $\\alpha$ parameter is recalculated at each iteration by:\n\\begin{eqnarray}\n\\alpha_{n+1} = \\alpha_n - sgn(R_{\\sigma}) \\frac{2d_n }{N\\sigma^2} \\sum_{pix} (y - x_{n+1})\n\\end{eqnarray}\n\n  \n", "meta": {"hexsha": "d0babfad386f97cae8f1addcc1f2bdf4cd65d7b1", "size": 1979, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr2/old_annexD.tex", "max_stars_repo_name": "sfarrens/cosmostat", "max_stars_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/doc/doc_mra/doc_mr2/old_annexD.tex", "max_issues_repo_name": "sfarrens/cosmostat", "max_issues_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/doc/doc_mra/doc_mr2/old_annexD.tex", "max_forks_repo_name": "sfarrens/cosmostat", "max_forks_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.023255814, "max_line_length": 97, "alphanum_fraction": 0.6563921172, "num_tokens": 703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7192171915244402}}
{"text": "\n\\subsection{Identification through exogeneous variables}\n\nPreviously our structural model was:\n\n\\(Q=\\alpha_1 + \\beta_1 P + \\epsilon_1 \\)\n\n\\(Q=\\alpha_2 + \\beta_2 P + \\epsilon_2 \\)\n\nAnd our reduced form:\n\n\\(P =\\dfrac{\\alpha_2-\\alpha_1 }{\\beta_1-\\beta_2}+\\dfrac{\\epsilon_2-\\epsilon_1 }{\\beta_1-\\beta_2}\\)\n\n\\(Q =\\dfrac{\\alpha_2\\beta_1-\\alpha_1\\beta_2 }{\\beta_1-\\beta_2}+\\dfrac{\\beta_1\\epsilon_2 -\\beta_2\\epsilon_1}{\\beta_1-\\beta_2}\\)\n\nOr:\n\n\\(P=\\pi_1 + \\tau_1 \\)\n\n\\(Q= \\pi_2 + \\tau_2\\)\n\n\\subsubsection{Adding another variable}\n\nThis time we add another measured variable, \\(I\\).\n\n\\(Q=\\alpha_1 + \\beta_1 P + \\theta_1 I + \\epsilon_1 \\)\n\n\\(Q=\\alpha_2 + \\beta_2 P + \\theta_2 I + \\epsilon_2 \\)\n\nThe reduced form is now:\n\n\\(P =\\dfrac{\\alpha_2 -alpha_1 }{\\beta_1-\\beta_2}+\\dfrac{\\theta_2-\\theta_1 }{\\beta_1-\\beta_2}I+\\dfrac{\\epsilon_2-\\epsilon_1}{\\beta_1-\\beta_2}\\)\n\n\\(Q =\\dfrac{\\alpha_2\\beta_1-\\alpha_1\\beta_2 }{\\beta_1-\\beta_2}+\\dfrac{\\theta_2\\beta_1-\\theta_1\\beta_2}{\\beta_1-\\beta_2}I+\\dfrac{\\beta_1\\epsilon_2 -\\beta_2\\epsilon_1}{\\beta_1-\\beta_2}\\)\n\nOr:\n\n\\(P =\\pi_{11} +\\pi_{12}I + \\tau_1 \\)\n\n\\(Q= \\pi_{21} +\\pi_{22}I + \\tau_2 \\)\n\nWe can estimate \\(\\pi_1 \\) and \\(\\pi_2 \\) as \\(\\hat \\pi_1\\) and \\(\\hat \\pi_2\\) respectively.\n\nWe can now create estimators \\(\\hat \\pi_{11}\\), \\(\\hat \\pi_{12}\\), \\(\\hat \\pi_{21}\\) and \\(\\hat \\pi_{22}\\).\n\n\\subsubsection{Identification with an exogeneous variable}\n\nWe now have \\(4\\) estimators and \\(6\\) parameters, meaning that we still cannot identify the model.\n\n\\subsubsection{Partial identification}\n\nCan we use \\(\\hat \\pi \\) to identify any of the structural parameters?\n\nWe know that:\n\n\\begin{itemize}\n\\item \\(\\pi_{11} =\\dfrac{\\alpha_2 -\\alpha_1 }{\\beta_1-\\beta_2}\\)\n\\item \\(\\pi_{12} =\\dfrac{\\theta_2-\\theta_1}{\\beta_1-\\beta_2}\\)\n\\item \\(\\pi_{21} =\\dfrac{\\alpha_2\\beta_1-\\alpha_1\\beta_2}{\\beta_1-\\beta_2}\\)\n\\item \\(\\pi_{22} =\\dfrac{\\theta_2\\beta_1-\\theta_1\\beta_2}{\\beta_1-\\beta_2} \\)\n\\end{itemize}\n\nIf the exogenous variable only affects one side of the equation, so \\(\\theta_1=0\\), we have:\n\n\\begin{itemize}\n\\item \\(\\pi_{11} =\\dfrac{\\alpha_2 -\\alpha_1 }{\\beta_1-\\beta_2}\\)\n\\item \\(\\pi_{12} =\\dfrac{\\theta_2}{\\beta_1-\\beta_2}\\)\n\\item \\(\\pi_{21} =\\dfrac{\\alpha_2\\beta_1-\\alpha_1\\beta_2}{\\beta_1-\\beta_2}\\)\n\\item \\(\\pi_{22} =\\dfrac{\\theta_2\\beta_1}{\\beta_1-\\beta_2} \\)\n\\end{itemize}\n\nSo we can see that:\n\n\\(\\hat \\beta_1 = \\dfrac{\\hat \\pi_{22}}{\\hat \\pi_{12}}\\)\n\nThis means we now have:\n\n\\begin{itemize}\n\\item \\(\\pi_{11} =\\dfrac{\\pi_{12}(\\alpha_2 -\\alpha_1 )}{\\pi_{22}-\\pi_{12}\\beta_2}\\)\n\\item \\(\\pi_{12} =\\dfrac{\\pi_{12}\\theta_2}{\\pi_{22}-\\pi_{12}\\beta_2}\\)\n\\item \\(\\pi_{21} =\\dfrac{\\pi_{12}(\\alpha_2\\beta_1-\\alpha_1\\beta_2)}{\\pi_{22}-\\pi_{12}\\beta_2}\\)\n\\item \\(\\pi_{22} =\\dfrac{\\pi_{12}\\theta_2\\beta_1}{\\pi_{22}-\\pi_{12}\\beta_2}\\)\n\\end{itemize}\n\nWe can use this to also identify \\(\\alpha_1\\).\n\n\\subsubsection{Complete identification}\n\nIf we have independent variables for each of the two equations, we can fully identify the model.\n\nWe will have \\(6\\) estimators and \\(6\\) parameters.\n\nWe are estimating:\n\n\\(Q=\\alpha_1 + \\beta_1 P + \\theta_1 I + \\epsilon_1 \\)\n\n\\(Q=\\alpha_2 + \\beta_2 P + \\theta_2 J + \\epsilon_2 \\)\n\n\\(I\\) and \\(J\\) are essentially instrumental variables for the model.\n\n\\(I\\) is an instrumental variable for demand shocks, and \\(J\\) is an instrumental variable for supply shocks.\n\n", "meta": {"hexsha": "24ed654aa29993a403724a19ad478c1dd5185e48", "size": 3326, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/olsMore/04-01-identification.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/olsMore/04-01-identification.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/olsMore/04-01-identification.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2912621359, "max_line_length": 184, "alphanum_fraction": 0.6683704149, "num_tokens": 1311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619220634457, "lm_q2_score": 0.8723473680407889, "lm_q1q2_score": 0.7192171877618969}}
{"text": "\\subsection{Writing an invertible matrix as a product of elementary matrices}\n\nRecall from Algorithm~\\ref{algo:matrix-inversion-algorithm} that an\n$n\\times n$-matrix $A$ is invertible if and only if $A$ can be carried\nto the $n\\times n$ identity matrix using elementary row\noperations. Combining this with our discussion of elementary matrices\nwe see that $A$ is invertible if and only if it can be written as a\nproduct of elementary matrices. This is the content of the following\ntheorem.\n\n\\begin{theorem}{Product of elementary matrices}{prod-elementary}\n  Let $A$ be an $n \\times n$-matrix. Then $A$ is invertible if and\n  only if it can be written as a product of elementary matrices.\n\\end{theorem}\n\n\\begin{proof}\n  If $A$ is an invertible $n\\times n$-matrix, then its {\\rref} is the\n  $n\\times n$ identity matrix $I$. By Theorem~\\ref{thm:form-rua}, we\n  can write $I=UA$, where $U = E_k\\cdots E_2E_1$ is a product of\n  elementary matrices. Then\n  \\begin{equation*}\n    A ~=~ U^{-1} ~=~ E_1^{-1}E_2^{-1}\\cdots E_k^{-1}.\n  \\end{equation*}\n  By Theorem~\\ref{thm:inverse-elementary-matrix}, if $E_i$ is an\n  elementary matrix, then so is $E_i^{-1}$. Therefore, $A$ has been\n  written as a product of elementary matrices. Conversely, if $A$ can\n  be written as a product of elementary matrices, then $A$ is clearly\n  invertible, because each elementary matrix is invertible.\n\\end{proof}\n\n\\begin{example}{Product of elementary matrices}{prod-elementary}\n  Let $A = \\begin{mymatrix}{rrr}\n    0 &  1 & 0 \\\\\n    1 &  1 & 0 \\\\\n    0 & -2 & 1\n  \\end{mymatrix}$.\n  Write $A$ as a product of elementary matrices.\n\\end{example}\n\n\\begin{solution}\n  Following the process of Theorem~\\ref{thm:prod-elementary}, we first\n  row-reduce $A$ to its {\\rref}, recording each row operation as an\n  elementary matrix.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      0 & 1 & 0 \\\\\n      1 & 1 & 0 \\\\\n      0 & -2 & 1 \\\\\n    \\end{mymatrix}\n    \\quad\\stackrel{R_1\\rowswap R_2}{\\roweq}\\quad\n    \\begin{mymatrix}{rrr}\n      1 & 1 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & -2 & 1 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{with elementary matrix}\\quad\n    E_1 ~=~ \\begin{mymatrix}{rrr}\n      0 & 1 & 0 \\\\\n      1 & 0 & 0 \\\\\n      0 & 0 & 1\n    \\end{mymatrix},\n  \\end{equation*}\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 1 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & -2 & 1 \\\\\n    \\end{mymatrix}\n    \\quad\\stackrel{R_1\\rowop R_1-R_2}{\\roweq}\\quad\n    \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & -2 & 1 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{with elementary matrix}\\quad\n    E_2 ~=~  \\begin{mymatrix}{rrr}\n      1 & -1 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & 0 & 1\n    \\end{mymatrix},\n  \\end{equation*}\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & -2 & 1 \\\\\n    \\end{mymatrix}\n    \\quad\\stackrel{R_3\\rowop R_3+2R_2}{\\roweq}\\quad\n    \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & 0 & 1 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{with elementary matrix}\\quad\n    E_3 ~=~ \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & 2 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Notice that the {\\rref} of $A$ is $I$. Hence $I = UA$ where\n  $U=E_3E_2E_1$. It follows that\n  $A = U^{-1} = E_1^{-1}E_2^{-1}E_3^{-1}$, and so we have succeeded in\n  writing $A$ as a product of elementary matrices\n  \\begin{equation*}\n    A\n    ~=~ E_1^{-1}E_2^{-1}E_3^{-1}\n    ~=~\n    \\begin{mymatrix}{rrr}\n      0 & 1 & 0 \\\\\n      1 & 0 & 0 \\\\\n      0 & 0 & 1\n    \\end{mymatrix}\n    \\begin{mymatrix}{rrr}\n      1 & 1 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & 0 & 1\n    \\end{mymatrix}\n    \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & -2 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n  In particular, it follows that $A$ is invertible.\n\\end{solution}\n", "meta": {"hexsha": "71628e3a336528882f68b33008b0f5fd8cd35eb7", "size": 3807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-ElementaryMatrices-Product.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-ElementaryMatrices-Product.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-ElementaryMatrices-Product.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 29.9763779528, "max_line_length": 77, "alphanum_fraction": 0.5820856317, "num_tokens": 1472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82446190912407, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.7192171805784918}}
{"text": "\\documentclass[12pt]{pylatex}\n\\usepackage{examples}\n\\usepackage{caption}\n\\usepackage{pgfplots}\n\n\\begin{document}\n\n\\section*{Plotting Bessel functions}\n\n\\vspace{-5pt}\n\nThis simple example uses {\\tt\\small numpy, scipy} and {\\tt\\small Matplotlib} to produce a plot\nof the first six Bessel functions. Two plots are shown, one created by {\\tt\\small Matplotlib}\nand a second created by LaTeX using the plotting package {\\tt\\small pgfplots} and the data\nexported from {\\tt\\small Matplotlib}.\n\nIf you are using macOS, you may need to use the {\\tt\\small -Ppythonw} option when running\n{\\tt\\small pylatex.sh}. This is a known problem with macOS and {\\tt\\small Matplotlib}, see\\\n\\url{https://matplotlib.org/faq/osx_framework.html}.\n\n\\vspace{-10pt}\n\n\\begin{minipage}[t]{0.60\\textwidth}\n\\begin{python}\n   import numpy as np\n   import scipy.special as sp\n   import matplotlib.pyplot as plt\n\n   plt.matplotlib.rc('text', usetex = True)\n   plt.matplotlib.rc('grid', linestyle = 'dotted')\n   plt.matplotlib.rc('figure', figsize = (6.4,4.8)) # (width,height) inches\n\n   x = np.linspace(0, 15, 500)\n\n   for v in range(0, 6):\n       plt.plot(x, sp.jv(v, x))\n\n   plt.xlim((0, 15))\n   plt.ylim((-0.5, 1.1))\n   plt.legend(('${J}_0(x)$', '${J}_1(x)$', '${J}_2(x)$',\n               '${J}_3(x)$', '${J}_4(x)$', '${J}_5(x)$'), loc = 0)\n   plt.xlabel('$x$')\n   plt.ylabel('${J}_n(x)$')\n   plt.grid(True)\n   plt.tight_layout(0.5)\n\n   plt.savefig('example-04-fig.pdf')\n\n   # save the data for later use by pgfplots\n   np.savetxt('example-04.txt',list(zip(x,sp.jv(0,x),sp.jv(1,x),sp.jv(2,x),\n                                          sp.jv(3,x),sp.jv(4,x),sp.jv(5,x))),\n                               fmt=\"% .10e\")\n\\end{python}\n\\end{minipage}\n\n\\clearpage\n\n\\begin{minipage}{\\textwidth}\n   \\centering\n   \\IfFileExists{example-04-fig.pdf}%\n   {\\includegraphics[width=6.4in]\n      {example-04-fig.pdf}}{Failed to create pdf plot.}\n   \\captionof{figure}{The first six Bessel functions.}\n\\end{minipage}\n\n\\vfill\n\n\\begin{latex}\n   \\IfFileExists{example-04-fig.pdf}%\n   {\\includegraphics[width=6.4in]\n      {example-04-fig.pdf}}{Failed to create pdf plot.}\n   \\captionof{figure}{The first six Bessel functions.}\n\\end{latex}\n\n\\vfill\n\n\\clearpage\n\n\\pgfplotsset{compat=newest}\n\\pgfplotsset{width=0.45\\textwidth,height=0.34\\textwidth}\n\n\\subsection*{Using pgfplots}\n\n\\begin{minipage}[t]{\\textwidth}\n   \\centering\n   \\begin{tikzpicture}\n      \\begin{axis}\n         [xmin= 0.0,  xmax=15.0,\n          ymin=-0.45, ymax=1.05,\n          xlabel=$x$, ylabel=$J_n(x)$,\n          grid=major, grid style={dashed,gray!30},\n          legend entries = {$J_0$, $J_1$, $J_2$, $J_3$, $J_4$, $J_5$}]\n          \\addplot[blue]   table [x index=0, y index=1]{example-04.txt};\n          \\addplot[red]    table [x index=0, y index=2]{example-04.txt};\n          \\addplot[green]  table [x index=0, y index=3]{example-04.txt};\n          \\addplot[teal]   table [x index=0, y index=4]{example-04.txt};\n          \\addplot[orange] table [x index=0, y index=5]{example-04.txt};\n          \\addplot[purple] table [x index=0, y index=6]{example-04.txt};\n      \\end{axis}\n   \\end{tikzpicture}\n   \\captionof{figure}{The first six Bessel functions.}\n\\end{minipage}\n\n\\vfill\n\n\\begin{latex}\n   \\begin{tikzpicture} % requires \\usepackage{pgfplots}\n      \\begin{axis}\n         [xmin= 0.0,  xmax=15.0,\n          ymin=-0.45, ymax=1.05,\n          xlabel=$x$, ylabel=$J_n(x)$,\n          grid=major, grid style={dashed,gray!30},\n          legend entries = {$J_0$, $J_1$, $J_2$, $J_3$, $J_4$, $J_5$}]\n          \\addplot[blue]   table [x index=0, y index=1]{example-04.txt};\n          \\addplot[red]    table [x index=0, y index=2]{example-04.txt};\n          \\addplot[green]  table [x index=0, y index=3]{example-04.txt};\n          \\addplot[teal]   table [x index=0, y index=4]{example-04.txt};\n          \\addplot[orange] table [x index=0, y index=5]{example-04.txt};\n          \\addplot[purple] table [x index=0, y index=6]{example-04.txt};\n      \\end{axis}\n   \\end{tikzpicture}\n   \\captionof{figure}{The first six Bessel functions.} % requires \\usepackage{caption}\n\\end{latex}\n\n\\end{document}\n", "meta": {"hexsha": "71db333c2f38b698a225dfab08e184cc4bf19a64", "size": 4098, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "python/examples/example-04.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "python/examples/example-04.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "python/examples/example-04.tex", "max_forks_repo_name": "leo-brewin/hybrid-latex", "max_forks_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-27T03:29:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:17:18.000Z", "avg_line_length": 32.5238095238, "max_line_length": 94, "alphanum_fraction": 0.6185944363, "num_tokens": 1376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234878, "lm_q2_score": 0.8652240930029117, "lm_q1q2_score": 0.7191249969766353}}
{"text": "\r\n\\chapter{Basic Concepts}\r\n\\section{Important/Useful Theorems}\r\n\\subsection{Stirling's Formula}\r\n\\begin{equation}\r\n\tn! \\approx \\sqrt{2 \\pi n} n^n e^{-n}\r\n\\end{equation}\r\n\\section{Answers to Problems}\r\n\r\n%%answer template\r\n%\\subsection{}\r\n%%problem n.n\r\n%\r\n%\r\n%\\begin{equation}\r\n%\t\r\n%\\label{answern.n}\r\n%\\end{equation}\r\n%\\textbf{Answer [not] verified}\r\n\r\n\\subsection{}\r\n%problem 1.1\r\nIf you have four volumes, and the question is what order to place them in, the question is a simple permutation problem.  There are 4 possibilities for the first, 3 for the second, 2 for the third and only one for the last, making the number of permutations of the books 24.  Only one order has them in ascending order and only one order will have them in descending order.  Thus:\r\n\\begin{equation}\r\n\tP=\\frac{2}{24}=\\frac{1}{12}\r\n\\label{answer1.1}\r\n\\end{equation}\r\n\\textbf{Answer not verified}\r\n\r\n\\subsection{}\r\n%problem 1.2\r\nThe wooden cube is made of $10^3$ cubes implying a 10x10x10 cube.  The cubes that have two faces painted will be the edges which are not on a corner.  Thus, since there are 12 edges of 10 cubes each, 8 of which are not corners, that implies we have 96 edges.  96 thus becomes our number of desireable outcomes and 1000 has always been the total number of outcomes:\r\n\\begin{equation}\r\n\tP=\\frac{96}{1000} = 0.096\r\n\\label{answer1.2}\r\n\\end{equation}\r\n\\textbf{Answer verified}\r\n\r\n\r\n\\subsection{}\r\n%problem 1.3\r\n\r\nIf there are $n$ total items and $k$ of them are defective.  We select $m$ and want to know the probability of $l$ of them being defective ones.\r\n\r\nThere are $\\binom{n}{m}$ possible ways to chose $m$ different items from the population of $n$ items which will be our denominator.  Now we need to know how many of those possibilities have $l$ bad ones in them for our numerator.  If there's $k$ total defective ones, then there are $\\binom{k}{l}$\r\n\r\n\\begin{equation}\r\n\tP = \\frac{\\binom{k}{l}}{\\binom{n}{m}}\r\n\\label{answer1.3}\r\n\\end{equation}\r\n\\textbf{Answer not verified}\r\n\r\n\r\n\\subsection{}\r\n%problem 1.4\r\n\r\nThere are $10!$ possible ways to order the ten books.  You can imagine that since the three books have to take up three adjacent positions, there are 8 possible locations for the three books to be ordered.  Taking just the first position (that being the first three ``Slots''), there are 6 ways to order the desired books and then $7!$ ways to order the remaining books.  Thus there are $8 \\cdot{} 6 \\cdot{} 7!$ desirable orders giving us a probability of\r\n\r\n\\begin{equation}\r\n\tP=\\frac{8 \\cdot{} 6 \\cdot{} 7!}{10!}=\\frac{1}{15}\r\n\\label{answer1.4}\r\n\\end{equation}\r\n\\textbf{Answer  verified}\r\n\r\n%answer template\r\n\\subsection{}\r\n%problem 1.5\r\n\r\nThere are 4 possibilities to consider here: neither hits, one or the other hits and both hits.  While it may be tempting to calculate the probability of each event, since we only care about the probability of at least one hitting the target, we need only calculate the probability that no one hits and subtract that from 1.  The first marksman has an $.8$ probability of hitting meaning he has a missing probability of .2; similarly the second marksman has a .7 chance of hitting and a .3 chance of missing.  Thus, the probability of both one and two missing is the product of the two missing probabilities: $.2*.3=.06$\r\n\r\n\\begin{equation}\r\n\tP=1-.06=.94\r\n\\label{answer1.5}\r\n\\end{equation}\r\n\\textbf{Answer verified}\r\n\r\n\r\n\\subsection{}\r\n%problem 1.6\r\nThe total number of ways $n+k$ seats can be occupied by $n$ people is $\\binom{n+k}{n}=\\frac{(n+k)!}{n!k!}$ but once again the difficult part is finding the total number of desirable outcomes. If you were to specify $m$ seats, you effectively divide the auditorium into two buckets so we need to find the number of ways to partition people into those two buckets which will give us the numerator, $\\binom{n+k}{m}=\\frac{(n+k)!}{m!(n+k-m)!}$\r\n\r\n\\begin{equation}\r\n\tP=\\frac{(n+k)!}{m!(n+k-m)!}\\frac{n!k!}{(n+k)!}=\\frac{{n!k!}}{m!(n+k-m)!}\r\n\\label{answer1.6}\r\n\\end{equation}\r\n\\textbf{Answer not verified}\r\n\r\n\r\n\\subsection{}\r\n%problem 1.7\r\n\r\nAgain, the number of ways to get three cards from a 52 card deck is $\\binom{52}{3}$.  Since there are 4 each of sevens, threes and aces, there are $4^3$ desirable hands.\r\n\r\n\\begin{equation}\r\n\tP=\\frac{4^3}{\\frac{52!}{3!49!}}=\\frac{16}{5525}=0.00289593\r\n\\label{answer1.7}\r\n\\end{equation}\r\nWhich it is worth pointing out, is no different than any other 3-card hand of three different cards.\r\n\\textbf{Answer not verified}\r\n\r\n\\subsection{}\r\n%problem 1.8\r\nIf you indiscriminately chose 3 line segments from our bank of 5, you have $\\binom{5}{3}=10$ total possibilities for triangles.  When you look at the bank (1, 3, 5, 7, 9), however, you have to make sure that any two segments are longer than the third segment, otherwise making a triangle is impossible.  The brute-force way to do this is start with 1 and realize that no triangle can be formed with it.  Then, looking at 3, you realize that you can do (3, 5, 7) and (3, 7, 9).  Starting now with 5, you can do (5, 7, 9) but that's the only triangle that hasn't already been enumerated.  At this point, you realize you're done and that the answer is plain to see\r\n\r\n\\begin{equation}\r\n\tP=\\frac{3}{10}=.3\r\n\\label{answer1.8}\r\n\\end{equation}\r\n\\textbf{Answer not verified}\r\n\r\n\\subsection{}\r\n%problem 1.9\r\n\r\nWe could do this problem in 5 minutes of programming and an instant of computation but that's not the point!  We need to think our way through this one.  How many cubes of the numbers between 1 and 1000, have 11 for the last two digits.  Luckily, each cube is unique so there's no complications there: only 1000 possibilities.  \r\n\r\nLet's break down the number we're cubing into two parts, one that encapsulates the part less than 100 and then the rest of the number\r\n\\begin{equation}\r\n\tn=a+b=100c+b\r\n\\end{equation}\r\nNow, just for fun, let's cube than number\r\n\\begin{equation}\r\n\tn^3=(100c+b)^3=b^3+300 b^2 c+30000 b c^2+1000000 c^3\r\n\\end{equation}\r\nClearly the only term here that will matter to the last two digits of the cube is $b$, the part less than 100.  Now we can reduce our now size 100 subspace by a great deal if you realize that in order for a number's cube to end in 1, the last number in the cube will need to be 1, leaving us: (1, 11, 21, 31, 41, 51, 61, 71, 81, 91).  At this point I recommend just cubing all the numbers and realizing that only $71^3=357911$ fulfills the requirements giving only one desirable outcome per century(71, 171, 271 etc.)\r\n\r\n\\begin{equation}\r\n\tP=\\frac{10}{1000}=.01\r\n\\label{answer1.9}\r\n\\end{equation}\r\n\\textbf{Answer verified}\r\n\r\n\\subsection{}\r\n%problem 1.10\r\nNow we want to know about all positive integers but just the last digit and the probability that the last digit is one.  To prove that we can use the hint given, we'll split the integer into the past less than 10 and the part greater than 10.\r\n\\begin{equation}\r\n\tn=10a+b\r\n\\end{equation}\r\n\\subsubsection{a--Squared}\r\n\\begin{equation}\r\n\tn^2=100a^2+10ab+b^2\r\n\\end{equation}\r\nOK, so clearly only $b^2$ contributes to the last digit.  At this point... just do the squaring especially since it's something you can do in your head. (1, 2, 3, 4, 5, 6, 7, 8, 9)$\\rightarrow$(1, 4, 9, 16, 25, 36, 49, 64, 81) therefore there are two desireable outcomes for every decade of random positive integers.\r\n\\begin{equation}\r\n\tP=\\frac{2}{10}=.2\r\n\\label{answer1.10a}\r\n\\end{equation}\r\n\r\n\\subsubsection{b--fourth-powered}\r\n\\begin{equation}\r\n\tn^4=100000000 a^4+4000000 a^3 b+60000 a^2 b^2+400 a b^3+b^4\r\n\\end{equation}\r\nGreat, once again, just $b^4$.  Now, doing the forth power is a little harder so let's reason through and reduce the subspace.  Clearly, only odd numbers will contribute since any power of an even number is again an even number. Now, let's just do the arithmetic. (1, 3, 5, 7, 9)$\\rightarrow$(1, 81, 625, 2401, 6561) giving us 4 desirable outcomes per decade of random numbers\r\n\\begin{equation}\r\n\tP=\\frac{4}{10}=.4\r\n\\label{answer1.10a}\r\n\\end{equation}\r\n\r\n\\subsubsection{b--multiplied by random positive number}\r\n\\begin{equation}\r\n\tn*r=(10a+b)r\r\n\\end{equation}\r\nNow let's let $r$ be a similar integer as n\r\n\\begin{equation}\r\n\tn*r=(10a+b)(10c+d)=100ac+10(bc+ad)+bd\r\n\\end{equation}\r\n\r\nSo we just need to consider the first two digits of both the random number and the arbitrary number.  This leaves us with $10^2$ possibilities; $5^2$ possible desirable outcomes once we exclude even numbers: (1, 3, 5, 7, 9).  Once again we resort to brute force by just defining the above as a vector and multiplying the transpose of that vector by the vector.  The only desirable outcomes turn out to be (1*1, 9*9, 7*3, 3*7), giving four desirable outcomes per century.\r\n\r\n\\begin{equation}\r\n\tP=\\frac{4}{100}=.04\r\n\\label{answer1.10b}\r\n\\end{equation}\r\n\r\n\\textbf{Answers all verified}\r\n\r\n\\subsection{}\r\n%problem 1.11\r\nHere we are given 8 possible numbers (2, 4, 6, 7, 8, 11, 12, 13) and are told that it making a random fraction out of two of the numbers.  There are $\\binom{8}{2}=28$ possible pairs but since $\\frac{a}{b} \\neq \\frac{b}{a}$, we multiply that by two to get the total number of fractions we can get from these numbers as being 56.  \r\n\r\nLooking at the numbers given, 7, 11 and 13 are all prime and all the others are divisible by two; therefore only the fractions that contain one or more prime numbers will be in lowest terms.  The number 7 can be in 7 different pairs with the other numbers which makes for 14 fractions.  11 can be in 6 pairs or 12 fractions (since we already counted 7) and similarly, 13 can be in 10 uncounted fractions giving 36 possible fractions in lowest terms.\r\n\r\n\\begin{equation}\r\n\tP=\\frac{36}{56}=\\frac{9}{14}\r\n\\label{answer1.11}\r\n\\end{equation}\r\n\\textbf{Answer verified}\r\n\r\n\\subsection{}\r\n%problem 1.12\r\nThe word drawer has 6 letters and there are $6!=720$ possible ways of arranging the letters.  It is then natural to say there's only one way to spell reward correctly and thus the probability of spelling it correctly after a random reordering is $1/720$ BUT there is a complication in that the two of our letters are the same, meaning there are to distinct arrangement of our distinguishable tiles that will give us the proper spelling.\r\n\r\n\\begin{equation}\r\n\tP=\\frac{2}{720} = \\frac{1}{360}\r\n\\label{answer1.12}\r\n\\end{equation}\r\n\\textbf{Answer verified}\r\n\r\n\\subsection{}\r\n%problem 1.13\r\nFor any die, there are 6 different possibilities.  Since one dice's outcome does not depend on another's, that means that for a roll of $6n$ die, there are $6^{6n}$ different possible outcomes for the dice rolls.  \r\n\r\nNow for desirable outcomes, we want each of the 6 faces to show up n times.  To accomplish this, we just count the number of ways to apportion $6n$ things into 6 groups of $n$ each or\r\n\\begin{equation}\r\n\t\\frac{(6n)!}{(n!)^6}\r\n\\end{equation}\r\nwhich, given Stirling's approximation\r\n\\begin{equation}\r\n\tn! \\approx \\sqrt{2 \\pi n} n^n e^{-n}\r\n\\end{equation}\r\ngives us for large $n$\r\n\\begin{equation}\r\n\t\\frac{(6n)!}{(n!)^6} \\approx \\sqrt{2 \\pi 6n} (6n)^{6n} e^{-6n} * \\frac{1}{(\\sqrt{2 \\pi n} n^n e^{-n})^6} = \\frac{3 \\cdot 6^{6n}}{4 (\\pi n)^{5/2}}\r\n\\end{equation}\r\n\r\n\\begin{equation}\r\n\tP=\\frac{(6n)!}{(n!)^6 6^{6n}} \\approx \\frac{3}{4 (\\pi n)^{5/2}}\r\n\\label{answer1.13}\r\n\\end{equation}\r\n\\textbf{Answer verified}\r\n\r\n\r\n\r\n\\subsection{}\r\n%problem 1.14\r\nTo figure out the total number of possibilities, we must realize that one draw of half a deck, implies the other half of the deck implicitly, therefore there are $\\binom{52}{26}$ total 26 card draws.  Then, to get 13 red cards, there are $\\binom{26}{13} = 10400600$ ways to get 13 red cards and the same number for black cards making $10400600^2$ the number of total possible desirable outcomes.\r\n\r\n\\begin{equation}\r\n\tP=\\frac{16232365000}{74417546961}=0.218126\r\n\\label{answer1.14}\r\n\\end{equation}\r\nBecause we're cool and modern and have Mathematica, we don't NEED to do the Stirling's formula approximation but it'll be good for us so we shall.\r\n\\begin{equation}\r\n\tP=\\frac{\\binom{26}{13}^2}{\\binom{52}{26}} = \\frac{(26!)^4}{(13!)^4 52!}=\\frac{((2n)!)^4}{(n!)^4 (4n)!}\r\n\\end{equation}\r\nwhere $n=13$.\r\n\\begin{equation}\r\n\tP=\\frac{(\\sqrt{4 \\pi n}(2n)^{2n}e^{-2n})^4}{(\\sqrt{2 \\pi n}n^{n}e^{-n})^4 (\\sqrt{8 \\pi n}(4n)^{4n}e^{-4n})}\r\n\\end{equation}\r\n\\begin{equation}\r\n\tP=\\frac{(4 \\pi n)^2}{(2 \\pi n)^2 \\sqrt{8 \\pi n}} \\frac{(2n)^{8n}}{n^{4n}(4n)^{4n}} = \\frac{4}{\\sqrt{8 \\pi n}} \\frac{2^{8n}}{4^{4n}}\r\n\\end{equation}\r\n\\begin{equation}\r\n\tP=\\frac{2}{\\sqrt{26 \\pi}} = 0.221293\r\n\\end{equation}\r\nwhich when you take the ratio of approximate to exact, you get $1.01452$ so the approximation is less than $2\\%$ off... not bad!\r\n\r\n\\textbf{Answer verified}\r\n\r\n\\subsection{}\r\n%problem 1.15\r\nThere are 100 senators at any given time.  Much like the previous problem, there are $\\binom{100}{50}=100891344545564193334812497256$ different 50 senator committees.  Much like the previous problem, there are $\\binom{2}{1}=2$ ways for California to be represented on the committee making for 50 states $2^{50}$ possible even committees\r\n\r\n\\begin{equation}\r\n\tP=\\frac{2^{50}}{\\binom{100}{50}} = \\text{1.115952921347132$\\grave{ }$*${}^{\\wedge}$-14}\r\n\\label{answer1.15}\r\n\\end{equation}\r\n\\textbf{Answer verified}\r\n\r\n\\subsection{}\r\n%problem 1.16\r\nFor $2n$ people, there are $(2n)!$ different possible lines; we want the number of lines where at any given point in the line, there are more people with 5 dollar bills than 10 dollar bills.\r\n\r\nThe given reference (freely available on Google books) has a fascinating geometrical argument about how $\\binom{2n}{n+1}$ is the number of lines that have one or more too many people with tens in front of people with fives.  Also, in this argument, there are $\\binom{2n}{n}$ trajectories instead of $(2n)!$ lines.\r\n\r\n\\begin{equation}\r\n\tP=\\frac{\\binom{2n}{n}-\\binom{2n}{n+1}}{\\binom{2n}{n}} = \\frac{1}{n+1}\r\n\\label{answer1.16}\r\n\\end{equation}\r\n\\textbf{Answer verified}\r\n\r\n\\subsection{}\r\n%problem 1.17\r\nWe wish to prove that\r\n\r\n\\begin{equation}\r\n\t\\sum_{k=0}^{n} \\binom{n}{k}^2 = \\binom{2n}{n}\r\n\\label{answer1.17}\r\n\\end{equation}\r\n\r\nThis is easies if we listen to the hint and consider that $\\binom{2n}{n}$ is the coefficient of $x^n$ in the polynomial $(x+1)^{2n}$ which is also equivalent to $(x+1)^n(x+1)^n$\r\n\r\nWe make use of:\r\n\\begin{equation}\r\n\t(x+1)^n = \\sum_{k=0}^{n} \\binom{n}{k} x^k\r\n\\end{equation}\r\n\\begin{equation}\r\n\t(x+1)^n(x+1)^n = \\sum_{k=0}^{n}\\sum_{j=0}^{n} \\binom{n}{k} \\binom{n}{j} x^k x^j\r\n\\end{equation}\r\nWe want the $x^n$ term: where $k+j=n$ or, put another way, where $k=n-j$...\r\n\\begin{equation}\r\n\t\\sum_{j=0}^{n} \\binom{n}{n-j} \\binom{n}{j} = \\sum_{j=0}^{n} \\frac{n!}{j!(n-j)!}\\frac{n!}{(n-j)!j!} = \\sum_{j=0}^{n} \\binom{n}{j}^2\r\n\\end{equation}\r\nQED\r\n\r\n\r\n\\textbf{Answer not verified}\r\n\r\n\r\n%%answer template\r\n%\\subsection{}\r\n%%problem n.n\r\n%\r\n%\r\n%\\begin{equation}\r\n%\t\r\n%\\label{answern.n}\r\n%\\end{equation}\r\n%\\textbf{Answer [not] verified}\r\n", "meta": {"hexsha": "e253496807291d44f72c685f520362e54b4dd702", "size": 14848, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter1.tex", "max_stars_repo_name": "stefk/Rozanov_ptcc_solutions", "max_stars_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter1.tex", "max_issues_repo_name": "stefk/Rozanov_ptcc_solutions", "max_issues_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter1.tex", "max_forks_repo_name": "stefk/Rozanov_ptcc_solutions", "max_forks_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.0517799353, "max_line_length": 662, "alphanum_fraction": 0.7029903017, "num_tokens": 4683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409024, "lm_q2_score": 0.8652240773641087, "lm_q1q2_score": 0.7191249803596792}}
{"text": "\\subsection{Magma ideals}\\label{sec:magma_ideals}\n\n\\begin{definition}\\label{def:magma_ideal}\\mimprovised\n  Let \\( \\mscrM \\) be a \\hyperref[def:magma]{magma} and \\( I \\) be a subset of \\( \\mscrM \\). We say that \\( I \\) is a \\term{left ideal} of \\( \\mscrM \\) if the inclusion \\( I\\mscrM \\subseteq I \\) holds in the \\hyperref[def:magma/power_set]{power set magma}. That is,\n  \\begin{equation*}\n    I \\mscrM = \\set{ x \\cdot y | x \\in \\mscrM, y \\in I } \\subseteq \\mscrM.\n  \\end{equation*}\n\n  Right ideals are defined analogously. If \\( I \\) is both a left ideal and a right ideal, we say that it is a \\term{two-sided ideal}.\n\n  As shown in \\fullref{thm:commutative_magma_ideals}, for \\hyperref[def:magma/commutative]{commutative} magmas left and right ideals coincide, and thus we can speak simply about ideals.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:magma_ideal_is_submagma}\n  Every two-sided magma ideal is a submagma.\n\\end{proposition}\n\\begin{proof}\n  Let \\( I \\) be a two-sided ideal for the magma \\( \\mscrM \\). For every pair \\( x, y \\in I \\), we have \\( xy \\in I \\) since \\( I \\) is a left ideal and \\( yx \\in I \\) since \\( I \\) is a right ideal. Thus, \\( II = I \\), and \\( I \\) is a submagma of \\( \\mscrM \\).\n\\end{proof}\n\n\\begin{example}\\label{ex:subgroup_is_not_ideal}\n  We explicitly give a counterexample to the converse of \\fullref{thm:magma_ideal_is_submagma}. Define \\( \\mscrG \\coloneqq \\BbbZ \\times \\BbbZ \\) as a \\hyperref[def:group_direct_sum]{direct sum} of two copies of the \\hyperref[def:set_of_integers]{integers}. Define also the subset\n  \\begin{equation*}\n    \\mscrH \\coloneqq \\set{ (n, n) \\colon n \\in \\BbbZ }.\n  \\end{equation*}\n\n  The set \\( \\mscrH \\) is a subgroup of \\( \\mscrG \\), since it is closed under addition, and since it contains the identity element \\( (0, 0) \\). It is not an ideal, however, because\n  \\begin{equation*}\n    (n, n) + (n, 0) = (2n, n) \\not\\in \\mscrH.\n  \\end{equation*}\n\\end{example}\n\n\\begin{proposition}\\label{thm:commutative_magma_ideals}\n  In a \\hyperref[def:magma/commutative]{commutative magma} \\( \\mscrM \\), a subset \\( I \\subseteq M \\) is a left ideal if and only if it is a right ideal. That is, in commutative magmas, it makes no sense to distinguish between left, right and two-sided ideals.\n\\end{proposition}\n\\begin{proof}\n  For \\( x \\in M \\) and \\( y \\in I \\), by commutativity we have \\( yx = xy \\), thus \\( \\mscrM I = I \\mscrM \\) and \\( I \\) is a left ideal if and only if it is a right ideal.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:proper_ideals_containing_identity}\n  A left or right ideal of a \\hyperref[def:unital_magma]{unital magma} contains the identity if and only if it is not proper.\n\\end{proposition}\n\\begin{proof}\n  Let \\( \\mscrM \\) be a unital magma and \\( I \\) be a left ideal of \\( \\mscrM \\). We will prove that \\( e \\in I \\iff I = \\mscrM \\).\n\n  \\SufficiencySubProof Let \\( e \\in I \\). Then \\( ex = x \\) for any \\( x \\in M \\), thus \\( I\\mscrM = \\mscrM \\). But \\( I \\) is an ideal, hence we have that \\( I\\mscrM = I \\), thus \\( I = I\\mscrM = \\mscrM \\).\n\n  \\NecessitySubProof If \\( I = \\mscrM \\), then obviously \\( e \\in I \\).\n\n  An analogous proof follows for the case when \\( I \\) is a right ideal.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:unital_magma_ideal_is_submagma_iff_contains_identity}\n  A two-sided ideal of a unital magma is a unital submagma if and only if it contains the identity.\n\\end{corollary}\n\\begin{proof}\n  Follows from \\fullref{thm:magma_ideal_is_submagma} and \\fullref{thm:proper_ideals_containing_identity}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:product_of_semigroup_ideals_is_in_intersection}\n  Fix a \\hyperref[def:magma/associative]{semigroup} \\( \\mscrM \\). If \\( I \\) and \\( J \\) are two-sided ideals, so are \\( IJ \\) and \\( I \\cap J \\) and, furthermore,\n  \\begin{equation*}\n    IJ \\subseteq I \\cap J.\n  \\end{equation*}\n\\end{proposition}\n\\begin{proof}\n  We first show that \\( IJ \\) is an ideal.\n\n  Take \\( x \\in I \\), \\( y \\in J \\). If \\( z \\in M \\), then associativity gives us\n  \\begin{equation*}\n    z(xy) = (zx)y \\in (zx)J \\subseteq IJ\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    (xy)z = x(yz) \\in I(yz) \\subseteq IJ.\n  \\end{equation*}\n\n  Hence, \\( IJ \\) is closed under the semigroup operation. This makes \\( IJ \\) a two-sided ideal.\n\n  If \\( x \\in I \\cap J \\) and \\( z \\in M \\), obviously \\( xz \\in I \\) and \\( xz \\in J \\), hence \\( xz \\in I \\cap J \\). Then \\( I \\cap J \\) is also a two-sided ideal.\n\n  To obtain the inclusion\n  \\begin{equation*}\n    IJ \\subseteq I \\cap J,\n  \\end{equation*}\n  observe that \\( xy \\in IJ \\) means that \\( xy \\in xJ = J \\) and \\( xy \\in Iy = I \\), thus \\( xy \\in I \\cap J \\).\n\\end{proof}\n", "meta": {"hexsha": "4fc8094ec6687e1ca2d7657d48f35c935b032b5b", "size": 4645, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/magma_ideals.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/magma_ideals.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/magma_ideals.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.7840909091, "max_line_length": 279, "alphanum_fraction": 0.6626480086, "num_tokens": 1607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.7191249752799834}}
{"text": "\n% This LaTeX was auto-generated from an M-file by MATLAB.\n% To make changes, update the M-file and republish this document.\n\n%%% \\documentclass{article}\n%%% \\usepackage{graphicx}\n%%% \\usepackage{color}\n\n%%% \\sloppy\n%%% \\definecolor{lightgray}{gray}{0.5}\n\\setlength{\\parindent}{0pt}\n\n%%% \\begin{document}\n\n    \n    \n\\subsection*{3-point interpolated DFT frequency estimator}\n\n\\begin{par}\nExample for algorithm iDFT3p.\n\\end{par} \\vspace{1em}\n\\begin{par}\niDFT3p is an algorithm for estimating the frequency, amplitude, phase and offset of the fundamental component using interpolated discrete Fourier transform. Rectangular or Hann window can be used for DFT.'; See also Krzysztof Duda: Interpolation algorithms of DFT for parameters estimation of sinusoidal and damped sinusoidal signals. In S. M. Salih, editor, Fourier Transform - Signal Processing, chapter 1, pages 3-32, InTech, 2012. \\url{http://www.intechopen.com/books/fourier-transform-signal-processing/interpolated-dft} Implemented by Rado Lapuh, 2016.';\n\\end{par} \\vspace{1em}\n\n\\subsubsection*{Contents}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item Generate sample data\n   \\item Call algorithm\n   \\item Display results\n\\end{itemize}\n\n\n\\subsubsection*{Generate sample data}\n\n\\begin{par}\nTwo quantities are prepared: \\lstinline{Ts} and \\lstinline{y}, representing 0.5 second of sinus waveform of nominal frequency 100 Hz, nominal amplitude 1 V and nominal phase 1 rad, sampled with sampling time 0.1 ms, with offset 0.1 V. The sampling is not coherent.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDI = [];\nAnom = 1; fnom = 100; phnom = 1; Onom = 0.1;\nDI.Ts.v = 1e-4;\nt = [0:DI.Ts.v:0.5];\nDI.y.v = Anom*sin(2*pi*fnom*t + phnom) + Onom;\n\\end{lstlisting}\n\n\n\\subsubsection*{Call algorithm}\n\n\\begin{par}\nFirst a rectangular window will be selected to estimate main signal properties. Use QWTB to apply algorithm \\lstinline{iDFT3p} to data \\lstinline{DI} and put results into \\lstinline{DOr}.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDI.window.v = 'rectangular';\nDOr = qwtb('iDFT3p', DI);\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nQWTB: no uncertainty calculation\n\\end{lstlisting} \\color{black}\n    \\begin{par}\nNext a Hann window will be selected to estimate main signal properties Results will be put into \\lstinline{DOh}.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDI.window.v = 'Hann';\nDOh = qwtb('iDFT3p', DI);\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nQWTB: no uncertainty calculation\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Display results}\n\n\\begin{par}\nResults is the amplitude, frequency and phase of sampled waveform. For rectangular window, the error from nominal in parts per milion is:\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nf_re = (DOr.f.v - fnom)./fnom .* 1e6\nA_re = (DOr.A.v - Anom)./Anom .* 1e6\nph_re = (DOr.ph.v - phnom)./phnom .* 1e6\nO_re = (DOr.O.v - Onom)./Onom .* 1e6\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\n\nf_re =\n\n    0.0166\n\n\nA_re =\n\n   41.2567\n\n\nph_re =\n\n   88.3681\n\n\nO_re =\n\n   1.6826e+03\n\n\\end{lstlisting} \\color{black}\n    \\begin{par}\nFor Hann window:\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nf_he = (DOh.f.v - fnom)./fnom .* 1e6\nA_he = (DOh.A.v - Anom)./Anom .* 1e6\nph_he = (DOh.ph.v - phnom)./phnom .* 1e6\nO_he = (DOh.O.v - Onom)./Onom .* 1e6\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\n\nf_he =\n\n  -3.7790e-06\n\n\nA_he =\n\n   3.9679e-07\n\n\nph_he =\n\n    6.2737\n\n\nO_he =\n\n   -0.6862\n\n\\end{lstlisting} \\color{black}\n    \n\n\n%%% \\end{document}\n    \n", "meta": {"hexsha": "13160de9fb4c3ad79ebd8f1877a9faa0aa48cef5", "size": 3579, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/algs_examples_published/doc_iDFT3p.tex", "max_stars_repo_name": "qwtb/qwtb", "max_stars_repo_head_hexsha": "f6c79c7dca4065fd85d6f1c05257c1af34e85e34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-12-09T13:18:54.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-09T13:18:54.000Z", "max_issues_repo_path": "doc/algs_examples_published/doc_iDFT3p.tex", "max_issues_repo_name": "qwtb/qwtb", "max_issues_repo_head_hexsha": "f6c79c7dca4065fd85d6f1c05257c1af34e85e34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2015-12-09T13:08:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-13T11:33:41.000Z", "max_forks_repo_path": "doc/algs_examples_published/doc_iDFT3p.tex", "max_forks_repo_name": "qwtb/qwtb", "max_forks_repo_head_hexsha": "f6c79c7dca4065fd85d6f1c05257c1af34e85e34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-11-11T02:12:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-17T12:59:18.000Z", "avg_line_length": 24.3469387755, "max_line_length": 560, "alphanum_fraction": 0.7041072925, "num_tokens": 1176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240721511739, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7191249669798003}}
{"text": "\\documentclass[namecite, fleqn]{goose-article}\n\n\\title{Linear elasticity}\n\n\\author{Tom W.J.\\ de Geus}\n\n\\hypersetup{pdfauthor={T.W.J. de Geus}}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Constitutive model}\n\nThe stress, $\\bm{\\sigma}$, is set by to the strain, $\\bm{\\varepsilon}$,\nthrough the following linear relation:\n\\begin{equation}\n    \\bm{\\sigma}\n    \\equiv K \\mathrm{tr}\\left( \\bm{\\varepsilon} \\right)\n    + 2 G \\bm{\\varepsilon}_\\mathrm{d}\n    \\equiv \\mathbb{C} : \\bm{\\varepsilon}\n\\end{equation}\nwherein $\\mathbb{C}$ is the elastic stiffness, which reads:\n\\begin{align}\n    \\mathbb{C}\n    &\\equiv K \\bm{I} \\otimes \\bm{I}\n    + 2 G (\\mathbb{I}_\\mathrm{s} - \\tfrac{1}{3} \\bm{I} \\otimes \\bm{I} )\n    \\\\\n    &= K \\bm{I} \\otimes \\bm{I}\n    + 2 G \\, \\mathbb{I}_\\mathrm{d}\n\\end{align}\nwith $K$ and $G$ the bulk and shear modulus respectively.\nSee \\cref{sec:ap:nomenclature} for nomenclature, including definitions of the unit tensors.\n\n\\section{Consistency check}\n\nTo check if the derived tangent $\\mathbb{C}$ a \\emph{consistency check} can be performed.\nA (random) perturbation $\\delta \\bm{\\varepsilon}$ is applied.\nThe residual is compared to that predicted by the tangent.\nFor the general case of linearisation, the following holds:\n\\begin{equation}\n    \\bm{\\sigma}\\big( \\bm{\\varepsilon}_\\star + \\delta \\bm{\\varepsilon} \\big)\n    = \\bm{\\sigma}\\big( \\bm{\\varepsilon}_\\star \\big)\n    + \\mathbb{C} \\big( \\bm{\\varepsilon}_\\star \\big) : \\delta \\bm{\\varepsilon}\n    + \\mathcal{O}(\\delta \\bm{\\varepsilon}^2)\n\\end{equation}\nor\n\\begin{equation}\n    \\underbrace{\n        \\bm{\\sigma}\\big( \\bm{\\varepsilon}_\\star + \\delta \\bm{\\varepsilon} \\big)\n        - \\bm{\\sigma}\\big( \\bm{\\varepsilon}_\\star \\big)\n    }_{\n        \\displaystyle \\delta \\bm{\\sigma}\n    }\n    - \\mathbb{C} \\big( \\bm{\\varepsilon}_\\star \\big) : \\delta \\bm{\\varepsilon}\n    = \\mathcal{O}(\\delta \\bm{\\varepsilon}^2)\n\\end{equation}\nThis allows the introduction of a relative error\n\\begin{equation}\n    \\eta =\n    \\Big|\\Big|\n        \\delta \\bm{\\sigma}\n        - \\mathbb{C}(\\bm{\\varepsilon}_\\star) : \\delta \\bm{\\varepsilon}\n    \\Big|\\Big|\n    /\n    \\Big|\\Big| \\delta \\bm{\\sigma} \\Big|\\Big|\n\\end{equation}\nThis \\emph{truncation error} thus scales as $\\eta \\sim || \\delta \\bm{\\varepsilon} ||^2$\nas depicted in \\cref{fig:consistency:expected}.\nAs soon as the error becomes sufficiently small the numerical \\emph{rounding error}\nbecomes more dominant, the scaling thereof is also included in \\cref{fig:consistency:expected}.\n\n\\begin{figure}[htp]\n    \\centering\n    \\includegraphics[width=.5\\textwidth]{figures/consistency}\n    \\caption{Expected behaviour of the consistency check, see \\citet[p.~9]{Heath2002}.}\n    \\label{fig:consistency:expected}\n\\end{figure}\n\nBecause this model is linear there is no truncation error, the measurement of $\\eta$ and a\nfunction of $|| \\delta \\bm{\\varepsilon} ||$ thus only displays a rounding error,\nas depicted in \\cref{fig:consistency}.\n\n\\begin{figure}[htp]\n    \\centering\n    \\includegraphics[width=.5\\textwidth]{examples/consistency}\n    \\caption{Measured consistency check, cf.\\ \\cref{fig:consistency:expected}.}\n    \\label{fig:consistency}\n\\end{figure}\n\n\\appendix\n\n\\section{Nomenclature}\n\\label{sec:ap:nomenclature}\n\n\\paragraph{Tensor products}\n\\vspace*{.5eM}\n\n\\begin{itemize}\n\n    \\item Dyadic tensor product\n    \\begin{align}\n        \\mathbb{C} &= \\bm{A} \\otimes \\bm{B} \\\\\n        C_{ijkl} &= A_{ij} \\, B_{kl}\n    \\end{align}\n\n    \\item Double tensor contraction\n    \\begin{align}\n        C &= \\bm{A} : \\bm{B} \\\\\n        &= A_{ij} \\, B_{ji}\n    \\end{align}\n\n\\end{itemize}\n\n\\paragraph{Tensor decomposition}\n\\vspace*{.5eM}\n\n\\begin{itemize}\n\n    \\item Deviatoric part $\\bm{A}_\\mathrm{d}$ of an arbitrary tensor $\\bm{A}$:\n    \\begin{equation}\n        \\mathrm{tr}\\left( \\bm{A}_\\mathrm{d} \\right) \\equiv 0\n    \\end{equation}\n    and thus\n    \\begin{equation}\n        \\bm{A}_\\mathrm{d} = \\bm{A} - \\tfrac{1}{3} \\mathrm{tr}\\left( \\bm{A} \\right)\n    \\end{equation}\n\n\\end{itemize}\n\n\\paragraph{Fourth order unit tensors}\n\\vspace*{.5eM}\n\n\\begin{itemize}\n\n    \\item Unit tensor:\n    \\begin{equation}\n        \\bm{A} \\equiv \\mathbb{I} : \\bm{A}\n    \\end{equation}\n    and thus\n    \\begin{equation}\n        \\mathbb{I} = \\delta_{il} \\delta{jk}\n    \\end{equation}\n\n    \\item Right-transposition tensor:\n    \\begin{equation}\n        \\bm{A}^T \\equiv \\mathbb{I}^{RT} : \\bm{A} = \\bm{A} : \\mathbb{I}^{RT}\n    \\end{equation}\n    and thus\n    \\begin{equation}\n      \\mathbb{I}^{RT} = \\delta_{ik} \\delta_{jl}\n    \\end{equation}\n\n    \\item Symmetrisation tensor:\n    \\begin{equation}\n        \\mathrm{sym} \\left( \\bm{A} \\right) \\equiv \\mathbb{I}_\\mathrm{s} : \\bm{A}\n    \\end{equation}\n    whereby\n    \\begin{equation}\n        \\mathbb{I}_\\mathrm{s} = \\tfrac{1}{2} \\left( \\mathbb{I} + \\mathbb{I}^{RT} \\right)\n    \\end{equation}\n    This follows from the following derivation:\n    \\begin{align}\n        \\mathrm{sym} \\left( \\bm{A} \\right) &= \\tfrac{1}{2} \\left( \\bm{A} + \\bm{A}^T \\right)\n        \\\\\n        &= \\tfrac{1}{2} \\left( \\mathbb{I} : \\bm{A} + \\mathbb{I}^{RT} : \\bm{A} \\right)\n        \\\\\n        &= \\tfrac{1}{2} \\left( \\mathbb{I} + \\mathbb{I}^{RT} \\right) : \\bm{A}\n        \\\\\n        &= \\mathbb{I}_\\mathrm{s} : \\bm{A}\n    \\end{align}\n\n    \\item Deviatoric and symmetric projection tensor\n    \\begin{equation}\n        \\mathrm{dev} \\left( \\mathrm{sym} \\left( \\bm{A} \\right) \\right)\n        \\equiv \\mathbb{I}_\\mathrm{d} : \\bm{A}\n    \\end{equation}\n    from which it follows that:\n    \\begin{equation}\n        \\mathbb{I}_\\mathrm{d}\n        = \\mathbb{I}_\\mathrm{s} - \\tfrac{1}{3} \\bm{I} \\otimes \\bm{I}\n    \\end{equation}\n\n\\end{itemize}\n\n\\bibliography{library}\n\n\\end{document}\n", "meta": {"hexsha": "c48b3d7aa10ef031b819e7848150ee9190eeab09", "size": 5629, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/readme.tex", "max_stars_repo_name": "tdegeus/LinearElastic", "max_stars_repo_head_hexsha": "9ef8e50ec457ed99032900bc25345ed332e5c1bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/readme.tex", "max_issues_repo_name": "tdegeus/LinearElastic", "max_issues_repo_head_hexsha": "9ef8e50ec457ed99032900bc25345ed332e5c1bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-11-13T08:41:59.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-13T08:42:11.000Z", "max_forks_repo_path": "docs/readme.tex", "max_forks_repo_name": "tdegeus/LinearElastic", "max_forks_repo_head_hexsha": "9ef8e50ec457ed99032900bc25345ed332e5c1bb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.7830687831, "max_line_length": 95, "alphanum_fraction": 0.6256883994, "num_tokens": 1985, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046026642944, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7190606120425808}}
{"text": "\\documentclass{article}\n\\title{Homework1}\n\\author{Hao Cui}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{geometry}\n\\geometry{a4paper,scale=0.8}\n\\begin{document}\n\\maketitle\n\\section{Prove $2n+\\Theta(n^2)=\\Theta(n^2)$}\nLet $f(n)\\in\\Theta(n^2)$, we can find $c_1,c_2,n_0$ such that $\\forall n\\ge n_0, 0\\le c_1n^2 \\le f(n) \\le c_2n^2$, that is\n$c_1n^2 + 2n \\le f(n)+2n \\le c_2n^2+2n$.\\\\\nSo we only need to prove $f(n)+2n\\in \\Theta(n^2)$, that means we need to find $c_3,c_4$ so that $\\forall n\\ge n_0, 0\\le c_3n^2 \\le f(n)+ 2n \\le c_4n^2$.\\\\\nSolve inequations:$\n\\left\\{\n\\begin{aligned}\nc_3n^2 \\le c_1n^2 + 2n \\\\\nc_4n^2 \\ge c_2n^2+2n \\\\\n\\end{aligned}\\right.$,\nWe can find $\n\\left\\{\n\\begin{aligned}\nc_3<c_1 \\\\\nc_4>2/n_0 + c_2 \\\\\n\\end{aligned}\\right. $ such that $\\forall n\\ge n_0, 0\\le c_3n^2 \\le f(n)+ 2n \\le c_4n^2$.\\\\\nThus $f(n)+2n\\in \\Theta(n^2)$, and $2n+\\Theta(n^2)=\\Theta(n^2)$.\n\\section{Prove $\\Theta(g(n))\\cap o(g(n))=\\emptyset$}\nAssume $\\Theta(g(n))\\cap o(g(n))\\neq\\emptyset$, then exists $f(n) \\in\\Theta(g(n))$ and $f(n)\\in o(g(n))$ ,\nso $\\exists c_1>0,c_2>0,n_0>0$ for that $\\forall n \\ge n_0,\\forall c>0$,$\n\\left\\{\n\\begin{aligned}\n0\\le c_1g(n) \\le f(n) \\le c_2g(n) \\\\\n0\\le f(n) < cg(n) \\\\\n\\end{aligned}\\right.$,\nlet c = $\\frac{c_1}{2}$, so $c_1g(n)\\le f(n)<cg(n)=\\frac{c_1}{2}g(n), c_1 < 0$.\\\\\nThis is a contradiction, thus $\\Theta(g(n))\\cap o(g(n))=\\emptyset$.\n\\section{Prove $\\Theta(g(n))\\cup o(g(n))\\neq O(g(n))$}\nLet $\nf(n)=\\left\\{\n\\begin{aligned}\ng(n) \\ when\\ n\\ is\\ even  \\\\\n0  \\qquad \\qquad otherwise\\\\\n\\end{aligned}\\right.$,\n$\\exists c=1, n_0>0, s.t. \\forall n\\ge n_0,0\\le f(n)\\le cg(n)$,so $f(n)\\in O(g(n))$.\\\\\nIf $0<c<1$ and n is even number, $f(n)>cg(n)$, so $f(n)\\notin o(g(n))$.\\\\\nIf n is not even number, f(n)=0, there is not a $c_1>0$ so that $0\\le c_1g(n) \\le f(n)$, so $f(n)\\notin \\Theta(g(n))$.\\\\\nThus $f(n)\\notin \\Theta(g(n))\\cup o(g(n))$.\nThus $\\Theta(g(n))\\cup o(g(n))\\neq O(g(n))$.\n\\section{Prove $max(f(n),g(n))=\\Theta(f(n)+g(n))$}\nTo show that $max(f(n),g(n))=\\Theta(f(n)+g(n))$, we want to find constants $c_1,c_2,n_0>0$ such that $0 \\le c_1(f(n)+g(n)) \\le max(f(n),g(n)) \\le c_2(f(n)+g(n))$ for all $n \\ge n_0$.\\\\\nNote that $max(f(n),g(n)) \\le f(n)+g(n)$, we can find $c_2=1$ such that $ max(f(n),g(n)) \\le c_2(f(n)+g(n))$.\\\\\nAssume $f(n)\\le g(n)$, and let $c_1=\\frac{1}{2}$, we can find $\\frac{1}{2}(f(n)+g(n)) \\le f(n) \\le g(n) = max(f(n),g(n))$.\\\\\nSo when $c_1=\\frac{1}{2}, c_2=1$, we can find $n_0>0$ such that $0 \\le c_1(f(n)+g(n)) \\le max(f(n),g(n)) \\le c_2(f(n)+g(n))$ for all $n \\ge n_0$.\\\\\nThus $max(f(n),g(n))=\\Theta(f(n)+g(n))$.\n\\section{Solve the recurrence $T(n)=2T(\\sqrt{n})+1$}\nLet $m=lgn$, then $T(2^m)=2T(2^\\frac{m}{2})+1$.\\\\\nLet $S(m)=T(2^m)$, then $S(m)=2S(\\frac{m}{2})+1$.\\\\\nAccording to the master method, $f(m)=1=O(m^{\\log _{2}{2-1}})$, so that $S(m)=\\Theta(m)$.\\\\\nThus $T(n)=T(2^m)=S(m)=\\Theta(m)=\\Theta(lgn)$.\n\\section{Solve the recurrence $nT(n)=(n-2)T(n-1)+2$}\n$T(n)=1$ when $n \\ge 2.$\\\\\nProve:\\\\\n1. n=2,2T(2)=2, T(2)=1.\\\\\n2. Assume T(k)=1,$k>2$, then (k+1)T(k+1)=(k-1)+2, then T(k+1)=1.\\\\\nThus $T(n)=1=\\Theta(1)$.\n\\section{CLRS,pp61,3-3}\n\\subsection{Rank the following functions by order of growth}\nFunctions on the same line are in the same equivalence class.\\\\\n\\begin{center}\n$2^{2^{n+1}}$\\\\\n$2^{2^n}$\\\\\n$(n+1)!$\\\\\n$n!$\\\\\n$e^n$\\\\\n$n\\cdot 2^n$\\\\\n$2^n$\\\\\n$(\\frac{3}{2})^n$\\\\\n$(lgn)^{lgn},n^{lglgn}$\\\\\n$(lgn)!$\\\\\n$n^3$\\\\\n$n^2,4^{lgn}$\\\\\n$nlgn,lg(n!)$\\\\\n$n,2^{lgn}$\\\\\n$\\sqrt{2}^{lgn}$\\\\\n$2^{\\sqrt{2lgn}}$\\\\\n$lg^2n$\\\\\n$ln{n}$\\\\\n$\\sqrt{lgn}$\\\\\n$lnlnn$\\\\\n$2^{lg^*n}$\\\\\n$lg^*n,lg^*(lgn)$\\\\\n$lg(lg^*)n$\\\\\n$n^{\\frac{1}{lgn}},1$\n\\end{center}\n\\subsection{F(n) is neither $O(g_i(n))$ nor $\\Theta(g_i(n))$}\n$$\nf(n)=\\left\\{\n\\begin{aligned}\n2^{2^{2^{n+1}}} \\ if\\ n\\ is\\ even  \\\\\n0  \\qquad \\ if\\ n\\ is\\ odd\\\\\n\\end{aligned}\\right.\n$$\n\\end{document}\n\n\n\n\n\n", "meta": {"hexsha": "cb45f62849ed41b2d00e282b7cbe43393e6f2630", "size": 3806, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework1/homework1.tex", "max_stars_repo_name": "cuiods/Arithmetic", "max_stars_repo_head_hexsha": "1d922a0f5cc2acb9da6a23f229af0fac212d96c3", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Homework1/homework1.tex", "max_issues_repo_name": "cuiods/Arithmetic", "max_issues_repo_head_hexsha": "1d922a0f5cc2acb9da6a23f229af0fac212d96c3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework1/homework1.tex", "max_forks_repo_name": "cuiods/Arithmetic", "max_forks_repo_head_hexsha": "1d922a0f5cc2acb9da6a23f229af0fac212d96c3", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.9174311927, "max_line_length": 184, "alphanum_fraction": 0.5643720441, "num_tokens": 1849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171067, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7190606068217618}}
{"text": "\\section{Dynamic Programming}\n\nDynamic programming is a technique from optimization field, specally it's a\nmethod to solve problem if the problem exhibits \\textbf{optimal substructure}\nand \\textbf{overlapping subproblems}.\n\n\\begin{definition*}\n\nA problem is said to have \\textbf{optimal substructure} if it can be constructed\nfrom optimal solutions of its subproblems. \n\nFor an example, suppose $T$ a tree and consider the problem where $\\forall v \\in\nT$, you want to compute a field $\\min$ such that $\\min[v] = \\min\\{w.val : w \\in\nST(v)\\}$ where $ST(v)$ denotes the subtree rooted by $v$. This problem exhibits\noptimal substructure, as for arbitrary vertex $v$, you have $\\min[w]$ computed\nfor all $w \\in Children[v]$, then you can construct $\\min[v]$ as the minimum of\nyour childrens answers and your own.\n\n\\end{definition*}\n\n\\begin{definition*}\n\nA problem is said to have \\textbf{overlapping subproblems} if the problem can be\nbroken down into subproblems which are reused several times.\n\nFor an example, consider the Fibonnacci number sequence $a_n = a_{n-1} +\na_{n-2}, a_2 = a_1 = 1$. Consider the value $a_5$. Notice that we can express it\nas a graph (see figure 2) with many incoming edges (in particular a DAG).\nWhereas problems with optimal substructure but not overlapping subproblems look\nlike the problem $\\min[v]$ problem, and can be modeled by trees.\n\n\\end{definition*}\n\nThe idea behind the dynamic programming problems we deal with is that if we\nremember problems as we do it, we can elimate the \"overlapping\" problems and\nreduce our computational cost as much as possible.\n\nWe've discussed three problems that we call \"representative\" of a lot of dynamic\nprogramming techniques: GCD, Woodcut, and Matrix Chain. We find that many\ndynamic programming problems reduce down to similar techniques needed to solve\nthese. In this section we discuss how to tackle these problems fully, but before\nthat we introduce \\textbf{memoization}.\n\n\\subsection{Memoization through Fibbonacci}\n\nAs discussed above, the Fibbonacci sequence $F_n = F_{n-1} + F_{n-2}, F_2 = F_1\n= 1$, is a prime example of a dynamic programming problem, since it has both\noptimal substructure and overlapping subproblems. Using the recurrence\nrelationship defined above we can write recursive code to solve this problem:\n\n\\begin{algorithmic}[1]\n\\Procedure{F}{$n$}\\Comment{$a_1 = 1, a_2 = 1, a_n = a_{n-1}+a_{n-2}$}\n\t\\If{$n \\leq 2$}\n\t\t\\State Return $1$\n\t\\Else\n\t\t\\State Return $F(n-1)+F(n-2)$\n\t\\EndIf\n\\EndProcedure\n\\end{algorithmic}\n\nHowever, if we were to run just this we would find ourselves choked by the\nruntime cost almost immediately. This is a consequence of the overlapping\nsubproblems portion of Fibbonacci, i.e. we're repeatedly computing the same\npieces of data. How do we resolve this? We implement \\textbf{memoization}.\n\n\\begin{definition*}\n\\textbf{Memoization} is an optimization technique where we store and cache the\nresults of expensive function calls. The idea is that if we want to compute said\nfunction again, we look in our cache first. (Memoization $\\gets$ making a memo.)\n\\end{definition*}\n\nLet's take a look at this implemented in the Fibbonacci sequence.\n\n\\begin{algorithmic}[1]\n\\State Let Memo[1..n] be a integer valued array initialized to $-1$.\n\\Procedure{F}{$n$}\\Comment{Recursive or top down}\n\t\\If{$n \\leq 2$}\n\t\t\\State Return $1$.\n\t\\ElsIf{$Memo[n] \\neq -1$} \\Comment{If we have computed $n$, use that result}\n\t\t\\State Return $Memo[n]$. \n\t\\Else \\Comment{Otherwise, compute it, store it, and return it.}\n\t\t\\State $Memo[n] = F(n-1)+F(n-2)$.\n\t\t\\State Return $Memo[n]$. \n\t\\EndIf\n\\EndProcedure\n\\end{algorithmic}\n\nWe can also implement this iteratively using a lookup table:\n\n\\begin{algorithmic}[1]\n\\Procedure{F}{$n$}\\Comment{Iterative or bottom up}\n\t\\State Let Memo[1..n] be a integer valued array.\n\t\\State Let $Memo[1], Memo[2] = 1$.\n\t\\For{$i = 3 \\to n$}\n\t\t\\State $Memo[i] = Memo[i-1] + Memo[i-2]$\n\t\\EndFor\n\\EndProcedure\n\\end{algorithmic}\n\nWithout the memoization table, our runtime was exponential, but what about now?\nIt's clear by the iterative version that our usage of memoization brings us to\n$\\theta(n)$ work, which is basically a night and day difference. In general we\ncan examing the new runtime of our dynamic programming problem by looking at the\nmemoization table, and trying to figure out how long it would take to fill it.\n\n\\subsection{Greatest Common Subsequence}\n\nThe problem is as follows: Suppose you are given two sequence $A$ and $B$. Your\nobjective is to find a subsequence $S \\subseteq A, B$ such that the length of\n$S$ is maximized. We want to write code to solve for $len(S)$. This is a\nclassic problem for applications in revision control, the diff utility on your\ncomputer, and many more NLP like reasons.\n\nSo how do we solve this problem using dynamic programming? Well first we try to\nfit it to the constraints of optimal substructure and overlapping subproblems.\nTo that end, consider placing points $i,j$ at the end of $A,B$:\n\n\\begin{align*}\nA = a_1 a_2 a_3 \\dots a_n & \\gets i \\\\\nB = b_1 b_2 b_3 \\dots b_m & \\gets j \\\\\n\\end{align*}\n\nConsider the local problem of whether $a_i$ and $b_j$ should be considered in\nour greatest subsequence:\n\n\\begin{enumerate}[(1)]\n\n\\item Suppose $a_i = b_j$. Then we know that the element $a_i \\in A$ and $a_i\n\\in B$, therefore being a candidate to go in $S$. Do we ever have reason to\nexclude something from $S$? In this problem no! Therefore we decide to add $1$\nto our length. But then how can we continue processing after selecting $a_i$ and\n$b_j$? Well we still need to select the best subsequence from $A[1..i-1]$ and\n$B[1..j-1$. This sounds like a subproblem with the last character of each\nsequence excluded!\n\n\\item Suppose $a_i \\neq b_j$. Here's where things get a little bit more\ncomplicated. Before when they were equal, we could conclude that we can take\nboth, but here we can't just say skip past this element. Take for example the\nstrings:\n\n$$\nA = aaaab, B = bbbba\n$$\n\nConsidering the last element, if we choose to ignore them because they're not\nequal, we reduce our problem to $aaaa, bbbb$, which has no GCS. However,\nclearly $\\{a\\}$ or $\\{b\\}$ solves our problem.\n\nInstead what we decide to do is not blindly skip past $a_i$ or $b_j$. We say\ninstead that we skip past \\textit{either} $a_i$ \\textit{or} $b_j$. How do we\ndecide which one? The one which produces the longer subsequence.\n\n\\end{enumerate}\n\nUsing the above analysis we then conclude that a solution to the GCS problem is:\n\n$$\nGCS(i,j) = \\begin{cases}\n0, & ij = 0 \\\\\n1 + GCS(i-1,j-1), & A[i] = A[j] \\\\\n\\max(GCS(i-1,j),GCS(i,j-1)), & \\text{otherwise}\n\\end{cases}\n$$\n\nwhere intially $i = n, j = m$.\n\n\\begin{algorithmic}[1]\n\\State Let $A[1..n]$ and $B[1..m]$ be two character arrays.\n\\Procedure{GCS}{$i,j$}\n\t\\If{$ij = 0$}\n\t\t\\State Return $0$.\n\t\\ElsIf{$A[i] = B[j]$}\n\t\t\\State Return $1 + GCS(i-1,j-1)$.\n\t\\Else \n\t\t\\State Return $\\max(GCS(i-1,j),GCS(i,j-1))$.\n\t\\EndIf\n\\EndProcedure\n\\end{algorithmic}\n\\begin{algorithmic}[1]\n\\State Let $A[1..n]$ and $B[1..m]$ be two character arrays.\n\\State Let $Memo[1..n,1..m]$ be a 2d array initialized to $-1$.\n\\Procedure{GCS}{$i,j$}\n\t\\If{$ij = 0$}\n\t\t\\State Return $0$.\n\t\\ElsIf{$Memo[i,j] \\neq -1$}\n\t\t\\State Return $Memo[i,j]$.\n\t\\ElsIf{$A[i] = B[j]$}\n\t\t\\State $Memo[i,j] = 1 + GCS(i-1,j-1)$.\n\t\\Else \n\t\t\\State $Memo[i,j] = \\max(GCS(i-1,j),GCS(i,j-1))$.\n\t\\EndIf\n\t\\State Return $Memo[i,j]$.\n\\EndProcedure\n\\end{algorithmic}\n\\begin{algorithmic}[1]\n\\State Let $A[1..n]$ and $B[1..m]$ be two character arrays.\n\\State Let $Memo[1..n,1..m]$ be a 2d array initialized to $-1$.\n\\State Let $Decisions[1..n,1..m]$ be a 2d array.\n\\Procedure{GCS}{$i,j$}\n\t\\If{$ij = 0$}\n\t\t\\State Return $0$.\n\t\\ElsIf{$Memo[i,j] \\neq -1$}\n\t\t\\State Return $Memo[i,j]$.\n\t\\ElsIf{$A[i] = B[j]$}\n\t\t\\State $Memo[i,j] = 1 + GCS(i-1,j-1)$.\n\t\t\\State $Decisions[i,j] = (i-1,j-1)$.\n\t\\Else \n\t\t\\State $v_1, v_2 = GCS(i-1,j), GCS(i,j-1)$.\n\t\t\\If{$v_1 > v_2$}\n\t\t\t\\State $Memo[i,j] = v_1$.\n\t\t\t\\State $Decisions[i,j] = (i-1,j)$.\n\t\t\\Else\n\t\t\t\\State $Memo[i,j] = v_2$.\n\t\t\t\\State $Decisions[i,j] = (i,j-1)$.\n\t\t\\EndIf\n\t\\EndIf\n\t\\State Return $Memo[i,j]$.\n\\EndProcedure\n\\end{algorithmic}\n", "meta": {"hexsha": "94824178b74259268ce4368118b60b894559ab76", "size": 8097, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/src/src/dynamicprog.tex", "max_stars_repo_name": "abhijit-c/AlgorithmsTopicReview", "max_stars_repo_head_hexsha": "cc22f5f19a99271a1a784af09df8de4f8c4bcdcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Notes/src/src/dynamicprog.tex", "max_issues_repo_name": "abhijit-c/AlgorithmsTopicReview", "max_issues_repo_head_hexsha": "cc22f5f19a99271a1a784af09df8de4f8c4bcdcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/src/src/dynamicprog.tex", "max_forks_repo_name": "abhijit-c/AlgorithmsTopicReview", "max_forks_repo_head_hexsha": "cc22f5f19a99271a1a784af09df8de4f8c4bcdcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.8045454545, "max_line_length": 80, "alphanum_fraction": 0.7080400148, "num_tokens": 2552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.7190493322801166}}
{"text": "\\subsection{Approximating cardinalities of huge sets}\n\\label{subsec:wcountproblem}\nThe Count-Distinct or Word Count Problem can be formulated as follows: given a sequence of elements $s_{1}, ..., s_{n}$ compute the amount of \\textbf{distinct} elements in it. For example, for the sequence dog, cat, dog, bird, bird the answer is 3 (the distinct elements are bird, cat, and dog).\n\nIf the sequence is not too large this problem can be easily solved in expected linear time and space using hash tables, or $\\mathcal{O}(nlogn)$ time and linear space using some data structures as Red-Black trees. However, this bound on space starts to become unacceptable when datasets are too large. In this section we will describe a probabilistic algorithm named as HyperLogLog \\cite{Flajolet07hyperloglog:the}.\\\\\n\\\\\nThis algorithm is very simple and yet very powerful. The core idea is the following: for each element $s_{i}$ of our sequence, use a hash function $h: \\{0, 1\\}^{*} \\mapsto \\{0, 1\\}^b$ to compute a value $h(s_{i})$ and estimate the cardinality as $2^m$, where $m$ is the maximum number of leading zeros among all $h(s_{i})$. We must note that if all $h(x)$ have the same probability $\\frac{1}{2^{b}}$ then the probability for some value to have $k$ leading zeros is $2^{-k}$. This means that the expected number of observations that are needed to find a number with $k$ leading zeros is $2^{k}$. Given that having a single hash value is not precise enough but computing multiple hash functions is too expensive, what is done is the following: \n\\begin{enumerate}\n\\item Given a token $t$, compute $h(t)$\n\\item Take the first $p$ bits and use them to refer to a position in an array consisting of $2^p$ elements $a_{0}, ..., a_{2^p - 1}$\n\\item Update this position according to the other $b - p$ bits so it keeps the maximum amount of leading zeros seen so far\n\\item Once all tokens are processed output the harmonic mean of $2^{a_{0}}, ..., 2^{a_{2^p - 1}}$ as the answer.\n\\end{enumerate}\nAn interesting trivia fact is that if we need $\\mathcal{O}(\\log n)$ bits for our hash function to be able to count until $n$ then we only need $\\mathcal{O}(\\log \\log n)$ to store the number of leading zeros of some hash value. This is why HyperLogLog is called that way.\\\\\n\\\\\nA very nice property of HyperLogLog is that two distinct runs on two different datasets can be merged if they have used the same parameters (hash function, $b$, and $p$) in such a way that it approximates the cardinality of the union of the two datasets. Given two arrays $a$ and $b$, each corresponding to a run of HyperLogLog we can get a fictional run of HyperLogLog $c$ that represents the union of both datasets by computing $c_{i} =\\max(a_{i}, b_{i})$ for all of the $2^{p}$ positions. This makes sense, as it produces the same result as running a single HyperLogLog on the concatenation of the two datasets. This property allows us to parallelize or to distribute this algorithm, giving us a potential performance boost. The source code we will use for our experiments can be found in appendix \\ref{subsec:hyperloglog_source_code}.\\\\\n\\\\\nNote that this application is a classical \\textit{map-reduce} workflow. Without collections we are forced to implement any reduce function as \\verb|reduce(f, *args)|. Each extra argument is passed as an input parameter via socket and pipe, implying a huge overhead. With collections only the collection object, and the list of identifiers, are transferred. The other properties of the contents, such as direction, locations and so on, are deduced or requested in the destination node.\\\\\n\\\\\nThe elimination of this overhead is noticeable even with a very small number of parameters. As we can see in figure \\ref{fig:collection_vs_normal}, the collection feature reduces the overhead drastically. An important observation is that a PyCOMPSs task of the form \\verb|f(*args)| usually starts to show problems and crashes when more than $60$ arguments are passed, as each argument represents a lot of metadata to be transferred via socket and pipe.\n\\begin{figure}[ht!]\n\\centering\n\\includegraphics[scale = 0.5]{figures/collection_vs_normal.png}\n\\caption{Execution time of the reduce functions with and without collections. Each point is the average of 5 executions. Although the samples are noisy, as they are small, a consistent improvement by the collection feature can be appreciated. The non-collections versions started to crash and to show strange behaviours around the 60 parameters}\n\\label{fig:collection_vs_normal}\n\\end{figure}\\\\\n\\\\\nA comparison between the amount of meta-data generated and sent by the classical reduce implementation and by the collections version can be found in appendix \\ref{subsec:reduce_data_comparison}.\n\nThis improvement benefits many applications, as the map-reduce scheme is very common.", "meta": {"hexsha": "c994da9a3c6ae244ac53344cecda1afd78f72995", "size": 4823, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hyperloglog.tex", "max_stars_repo_name": "srgrr/TFM", "max_stars_repo_head_hexsha": "f6c302547fdfc9b1df3423cc4e927cd6bb83b345", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-01-02T10:39:32.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-22T14:01:41.000Z", "max_issues_repo_path": "hyperloglog.tex", "max_issues_repo_name": "srgrr/TFM", "max_issues_repo_head_hexsha": "f6c302547fdfc9b1df3423cc4e927cd6bb83b345", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hyperloglog.tex", "max_forks_repo_name": "srgrr/TFM", "max_forks_repo_head_hexsha": "f6c302547fdfc9b1df3423cc4e927cd6bb83b345", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 160.7666666667, "max_line_length": 840, "alphanum_fraction": 0.7702674684, "num_tokens": 1168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424528443251, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7190267060051199}}
{"text": "\\section*{Chapter 12: Extensions of GCD}\n\n\\paragraph{Exercise 12.2}\n\\begin{enumerate}\n    \\item Prove that an ideal $I$ is closed under subtraction.\n    \\item Prove that $I$ contains $0$.\n\\end{enumerate}\n\n\\begin{proof}  \n$ $\\newline\n\\vspace{-0.1in}\n\\begin{enumerate}\n    \\item\n    Let $R$ be the ring such that $I \\subseteq R$. We know that\n    the additive inverse of $1$, $-1$, is in $R$. Let $x \\in I$. Thus,\n    $-1 \\, x = -x \\in I$. Now, let $y \\in I$. Then, $y - x = y + (-x)\n    \\in I$. \n\n    \\item The first part of the previous argument shows that $I$ is closed\n    under additive inverses. Thus, given $x \\in I$ (at least we have one\n    since $I$ is nonempty), $x + (-x) = x - x = 0 \\in I$. \n\\end{enumerate}\n\\end{proof}\n\n\n\\paragraph{Exercise 12.3}\nProve that all the elements of a linear combination ideal are divisible by\nany of the common divisors of $a$ and $b$.\n\n\\begin{proof}  \nLet $I = \\{xa + yb \\, / \\, x,y \\in R \\}$ be a linear combination ideal, \nlet $e = x_0 a + y_0 b \\in I$ and let $d$ be a common divisor of $a$ and $b$.\nThat is, $a = d q_1$ and $b = d q_2$. Thus,\n\\begin{eqnarray*}\n    e &=& x_0 a + y_0 b \\\\\n      &=& x_0 (d q_1) + y_0 (d q_2) \\\\\n      &=& d (x_0 q_1 + y_0 q_2) \\\\\n      &=& d q\n\\end{eqnarray*}\nIn other words, $e$ is divisible by $d$.\n\\end{proof}\n\n\n\\paragraph{Exercise 12.4}\nProve that any element in a principal ideal is divisible by the principal element.\n\n\\begin{proof}  \nFollows immediately from the definition of principal ideal and principal element.\n\\end{proof}\n\n\n\\paragraph{Exercise 12.5}\nUsing B\\'ezout's identity, prove that if $p$ is prime, then any $0 < a <p$ has\nmultiplicative inverse modulo $p$.\n\n\\begin{proof}  \nActually, this is an immediate corollary of the invertibility lemma: being $p$ \nprime, any $0 < a < p$ is such that $\\GCD{a}{p} = 1$. Thus, there exists an $x \\in\n\\Zn{p}$ such that $a x = x a = 1 \\MOD{p}$. An ad-hoc proof can be done\nusing essentially the same argument that proves the inveritibility lemma. \n\\end{proof}\n", "meta": {"hexsha": "ffe821df12ad899c3b574432047922088c62a98a", "size": 1993, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/src/chapter12.tex", "max_stars_repo_name": "lukius/fmtgp", "max_stars_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-10-12T17:40:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T03:00:43.000Z", "max_issues_repo_path": "math/src/chapter12.tex", "max_issues_repo_name": "lukius/fmtgp", "max_issues_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/src/chapter12.tex", "max_forks_repo_name": "lukius/fmtgp", "max_forks_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-05-15T07:07:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-29T14:01:30.000Z", "avg_line_length": 32.1451612903, "max_line_length": 82, "alphanum_fraction": 0.6407425991, "num_tokens": 689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587667, "lm_q2_score": 0.8459424353665382, "lm_q1q2_score": 0.7190266959718805}}
{"text": "\\documentclass[class=report, float=false, crop=false]{standalone}\n\n\\input{preamble}\n\n\\graphicspath{{figures/images/}{figures/figs/}}\n\n\\begin{document}\n\n\\chapter{Calculation details}\n\\label{appendix:calculation}\n\n\\section{Field auto-correlation}\n\\label{field_auto_correlation}\n\nLet $\\vec{v}(\\vec{r})$ be a vector -- or scalar -- field with $\\vec{r} \\in \\mathbb{R}^2$, then we define its auto-correlation function as\n\\begin{equation}\nC_{vv}(\\Delta \\vec{r}) = \\frac{\\int d^2\\vec{r}~ \\vec{v}(\\vec{r})^*\\cdot\\vec{v}(\\vec{r}+\\Delta \\vec{r})}{\\int d^2\\vec{r}~ |\\vec{v}(\\vec{r})|^2}\n\\end{equation}\nwhich can be efficiently calculated with the help of Fourier transforms.\\\\\n\nWe define\n\\begin{equation}\n\\begin{aligned}\n\\mathcal{F} : \\cdot \\mapsto \\int d^2\\vec{k}~ e^{-i\\vec{k}\\cdot\\vec{r}} ~\\cdot  &\\Leftrightarrow \\mathcal{F}^{-1} : \\cdot \\mapsto \\int d^2\\vec{k}~ e^{i\\vec{k}\\cdot\\vec{r}}\\\\\n\\tilde{\\vec{v}} = \\mathcal{F}\\{\\vec{v}\\} &\\Leftrightarrow \\vec{v} = \\mathcal{F}^{-1}\\{\\tilde{\\vec{v}}\\}\n\\end{aligned}\n\\end{equation}\nthen\n\\begin{equation}\n\\begin{aligned}\n\\int d^2\\vec{r}~ \\vec{v}(\\vec{r})^*\\cdot\\vec{v}(\\vec{r}+\\Delta \\vec{r}) &= \\int d^2\\vec{r} \\left(\\int d^2\\vec{k}~ e^{i\\vec{k}\\cdot\\vec{r}}\\tilde{\\vec{v}}(\\vec{k})\\right)^*\\cdot\\left(\\int d^2\\vec{k}^{\\prime}~ e^{i\\vec{k}^{\\prime}\\cdot(\\vec{r}+\\Delta \\vec{r})}\\tilde{\\vec{v}}(\\vec{k}^{\\prime})\\right)\\\\\n&= \\int d^2\\vec{k} \\int d^2\\vec{k}^{\\prime}~ e^{i\\vec{k}^{\\prime}\\cdot\\Delta \\vec{r}} \\tilde{\\vec{v}}(\\vec{k})^*\\cdot\\tilde{\\vec{v}}(\\vec{k}^{\\prime}) \\int d^2\\vec{r}~ e^{-i(\\vec{k}-\\vec{k}^{\\prime})\\cdot\\vec{r}}\\\\\n&= \\int d^2\\vec{k} \\int d^2\\vec{k}^{\\prime}~ e^{i\\vec{k}^{\\prime}\\cdot\\Delta \\vec{r}} \\tilde{\\vec{v}}(\\vec{k})^*\\cdot\\tilde{\\vec{v}}(\\vec{k}^{\\prime}) \\delta(\\vec{k}-\\vec{k}^{\\prime})\\\\\n&=  \\int d^2\\vec{k}~ e^{i\\vec{k}\\cdot\\Delta \\vec{r}} \\tilde{\\vec{v}}(\\vec{k})^*\\cdot\\tilde{\\vec{v}}(\\vec{k})\\\\\n&= \\mathcal{F}^{-1}\\{\\mathcal{F}\\{\\vec{v}\\}^*(\\vec{k})\\cdot\\mathcal{F}\\{\\vec{v}\\}(\\vec{k})\\}(\\Delta\\vec{r})\n\\end{aligned}\n\\end{equation}\nthus showing that $C_{vv}$ can be easily expressed in terms of the Fourier transform of $\\vec{v}$ field.\n\n\\end{document}\n", "meta": {"hexsha": "0387e55c5210b857e3ea674fa335e73e49572421", "size": 2124, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/appendices/app_calculation.tex", "max_stars_repo_name": "yketa/UBC---Spring-2018---Wiki", "max_stars_repo_head_hexsha": "5f68e704111c5c1802afa880950c8520cc8acc9a", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/appendices/app_calculation.tex", "max_issues_repo_name": "yketa/UBC---Spring-2018---Wiki", "max_issues_repo_head_hexsha": "5f68e704111c5c1802afa880950c8520cc8acc9a", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/appendices/app_calculation.tex", "max_forks_repo_name": "yketa/UBC---Spring-2018---Wiki", "max_forks_repo_head_hexsha": "5f68e704111c5c1802afa880950c8520cc8acc9a", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.8048780488, "max_line_length": 300, "alphanum_fraction": 0.6162900188, "num_tokens": 913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7190266863271285}}
{"text": "% !TEX root = index.tex\n\n\\section{Linear transformations}\n\\label{section:linearTransformation}\n\\setlength{\\epigraphwidth}{0.6\\textwidth}\n\\epigraph{\\it The unknown thing to be known appeared to me as some stretch of earth or hard marl, resisting penetration... the sea advances insensibly in silence, nothing seems to happen, nothing moves, the water is so far off you hardly hear it... yet it finally surrounds the resistant substance. }{Alexander Grothendieck}\n\n\\begin{mdframed}\n  {\\bf Notation: } From now on, we will use the term \\emph{vector space} to mean a \\emph{subspace of $\\bbr^n$}.\\tablefootnote{This is because all of our theorems are also true for finite dimensional abstract vector spaces i.e. abstract vector spaces for which a finite basis exists.}\n\\end{mdframed}\n\nThe ``category theory'' philosophy in mathematics says that in order to understand structured objects one must study structured maps between them.\nThe structured maps between vector spaces are the ones that preserve linearity.\n\n\\begin{definition}\n  A \\emph{linear transformation} is a map $\\call: V \\rightarrow W$ between vector spaces $V$ and $W$ satisfying\n  \\begin{enumerate}\n    \\item $\\call(c \\vec{v}) = c \\call (\\vec{v})$,\n    \\item $\\call(\\vec{v} + \\vec{w}) = \\call (\\vec{v}) + \\call (\\vec{w})$.\n  \\end{enumerate}\n  for all scalars $c \\in \\bbr$ and all vectors $\\vec{v}$, $\\vec{w} \\in V$.\n\n  A linear transformation  $\\call: V \\rightarrow W$ is a (vector space) \\emph{isomorphism} if it is a bijection of sets, in which case we say that the two vector spaces $V$ and $W$ are \\emph{isomorphic}.\n\\end{definition}\n\n\\begin{qbox}\n  \\begin{enumerate}\n    \\item Show that if $\\call: V \\rightarrow W$ and $\\call': W \\rightarrow U$ are linear transformations, then so is their composition $\\call' \\circ \\call: V \\rightarrow U$.\n    \\begin{equation*}\n      \\begin{tikzcd}\n        V \\ar[r,\"\\call\"] & W \\ar[r,\"\\call'\"] & U\n      \\end{tikzcd}\n    \\end{equation*}\n    \\item Show that if $\\call: V \\rightarrow W$ is an isomorphism, then the set-theoretic inverse map $\\call^{-1}: W \\rightarrow V$ is also a linear transformation.\n    \\begin{equation*}\n      \\begin{tikzcd}\n        V \\ar[r,\"\\call\", bend left] & W \\ar[l,\"\\call^{-1}\", bend left]\n      \\end{tikzcd}\n    \\end{equation*}\n  \\end{enumerate}\n\n\\end{qbox}\n\n\n\n\\subsection{Examples in low dimensions}\n\n\\begin{definition}\n    A linear transformation where the source and target is the same, $\\call: V \\rightarrow V$, is called a \\emph{linear operator} on $V$.\n\\end{definition}\n\n\\begin{qbox}\n  \\label{q:rotationReflection}\n  Use the Parallelogram Law to prove that the following maps are linear operators on $\\bbr^2$.\n  \\begin{enumerate}\n    \\item $\\rot: \\bbr^2 \\rightarrow \\bbr^2$, rotation by an angle $\\theta$ in the counterclockwise direction.\n    \\item $\\refl: \\bbr^2 \\rightarrow \\bbr^2$, reflection about a line that forms an angle $\\theta$ with the $x$-axis.\n    \\item $\\proj: \\bbr^2 \\rightarrow \\bbr^2$, orthogonal projection onto a line that forms an angle $\\theta$ with the $x$-axis.\n  \\end{enumerate}\n  Which of the above maps are isomorphisms? For the ones that are isomorphisms, what are the inverses?\n\\end{qbox}\n\n\\begin{figure}[H]\n\\minipage{0.3\\textwidth}\n  \\centering\n  \\begin{tikzpicture}[scale=2]\n    % \\draw [dashed] (-1,0)--(4,0);\n    \\draw [dashed] (-0.1,-0.1)--(1.5,1.5);\n    \\draw [->, thick] (0,0)--(1,0) node [below] {$\\vec{v}$};\n    \\draw [->, thick] (0,0)--(0.707,0.707) node [above left] {$\\rot \\vec{v}$};\n    % \\pic [draw, ->, \"$\\theta$\", angle eccentricity=1.5] {angle = mary--origo--bob};\n  \\end{tikzpicture}\n  % \\caption*{$\\rot$}\n\\endminipage\\hfill\n\\minipage{0.3\\textwidth}\n\\begin{tikzpicture}[scale=2]\n  \\draw [dashed] (-0.1,-0.1)--(1.5,1.5);\n  \\draw [->, thick] (0,0)--(1,0) node [below] {$\\vec{v}$};\n  \\draw [->, thick] (0,0)--(0,1) node [above] {$\\refl \\vec{v}$};\n\\end{tikzpicture}\n\\endminipage\\hfill\n\\minipage{0.3\\textwidth}\n\\begin{tikzpicture}[scale=2]\n  \\draw [dashed] (-0.1,-0.1)--(1.5,1.5);\n  \\draw [->, thick] (0,0)--(1,0) node [below] {$\\vec{v}$};\n  \\draw [->, thick] (0,0)--(0.6, 0.6) node [above left] {$\\proj \\vec{v}$};\n  \\draw [dashed] (1,0)--(0.6, 0.6);\n\\end{tikzpicture}\n\\endminipage\n\\end{figure}\n\n\\begin{qbox}\n  Is translation along the $x$-axis, $\\begin{bmatrix} x \\\\ y \\end{bmatrix} \\mapsto \\begin{bmatrix} x +1 \\\\ y \\end{bmatrix}$, a linear operator on $\\bbr^2$?\n\\end{qbox}\n\n\\begin{qbox}\n  \\label{q:linearTransformBetweenR1}\n  What maps $\\call: \\bbr^1 \\rightarrow \\bbr^1$ are linear operators on $\\bbr^1$?\\hint{$\\call$ is completely determined by $\\call([1])$.}\n\\end{qbox}\n\n\\begin{qbox}\n  Show that the identity map $\\id: V \\rightarrow V$ is a linear operator on any vector space $V$.\n\\end{qbox}\n\n\n\n\n\n\n\n\n\n\\subsection{Linear transformations and matrices}\nWe will see in Section \\ref{section:linearTransformationsBases} that linear transformations are intricately related to bases.\nIn this section, we will use bases and generalized coordinates to derive the formula for matrix multiplication.\n\nConsider a linear transformation between vector spaces\n\\begin{align*}\n  \\call: V \\rightarrow W\n\\end{align*}\nLet $\\calb = \\{ \\vec{v}_1 , \\dots, \\vec{v}_k \\}$ and $\\calb'= \\{ \\vec{w}_1 , \\dots, \\vec{w}_\\ell \\}$ be bases of $V$ and $W$ respectively.\nFor any $\\vec{v} \\in V$, as $\\call(\\vec{v})$ is a vector in $W$, and the set $\\{ \\vec{w}_1 , \\dots, \\vec{w}_\\ell \\}$ is a basis of $W$, we can write $\\call(\\vec{v})$ as a linear combination of the $\\vec{w}_i$.\nSuppose\n\\begin{align*}\n  \\call (\\vec{v}_1) &= A_{11} \\vec{w}_1 + A_{21} \\vec{w}_2 + \\dots + A_{\\ell 1} \\vec{w}_\\ell\\\\\n  \\call (\\vec{v}_2) &= A_{12} \\vec{w}_1 + A_{22} \\vec{w}_2  \\dots + A_{\\ell 2} \\vec{w}_\\ell \\\\\n  & \\vdots \\\\\n  \\call (\\vec{v}_k) &= A_{1 k} \\vec{w}_1 + + A_{2k} \\vec{w}_2 \\dots + A_{\\ell k} \\vec{w}_\\ell\n\\end{align*}\nwhere $A_{ij}$ are scalars, for $1 \\le i \\le \\ell$ and $1 \\le j \\le k$.\nIn generalized coordinates, these can be written as column vectors.\n\\begin{align*}\n  [\\call (\\vec{v}_1)]_{\\calb'} = \\begin{bmatrix} A_{11} \\\\\\\\ \\vdots \\\\\\\\ A_{\\ell 1} \\end{bmatrix} \\quad\n  [\\call (\\vec{v}_2)]_{\\calb'} = \\begin{bmatrix} A_{12} \\\\\\\\ \\vdots \\\\\\\\ A_{\\ell 2} \\end{bmatrix} \\quad\n  \\cdots \\quad\n  [\\call (\\vec{v}_k)]_{\\calb'} = \\begin{bmatrix} A_{1k} \\\\\\\\ \\vdots \\\\\\\\ A_{\\ell k} \\end{bmatrix}\n\\end{align*}\n\nWe then place the coordinate vectors $[\\: \\call \\vec{v}_1 \\:]_{\\calb'}$, $[\\: \\call \\vec{v}_2 \\:]_{\\calb'}$, $\\ldots$, $[\\: \\call \\vec{v}_k \\:]_{\\calb'}$ next to each other to form a grid with $\\ell$ rows and $k$ columns, called an \\emph{$\\ell \\times k$ matrix} which we will denote by $[\\call]_{\\calb \\rightarrow \\calb'}$.\n\\begin{align*}\n  [\\call]_{\\calb \\rightarrow \\calb'}\n  := \\begin{bmatrix}\n    A_{11} & A_{12} & \\cdots & A_{1k} \\\\\n    A_{21} & A_{22} & \\cdots & A_{2k} \\\\\\\\\n    \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n    A_{\\ell 1} & A_{\\ell 2} & \\cdots & A_{\\ell k}\n  \\end{bmatrix}.\n\\end{align*}\nThis is the {matrix associated to/corresponding to} $\\call$ for the bases $\\calb$ and $\\calb'$.\n\n\nWhen $V = \\bbr^k$ and $W = \\bbr^\\ell$ and $\\calb$ and $\\calb'$ are the standard bases, we drop the basis symbols and denote the matrix by $[\\call]$.\n\n\\textbf{``Theorem.''}\\emph{ Matrices are the same as linear transformations between Euclidean spaces. More generally, matrices are the same as linear transformations between vector spaces ``once we have chosen bases for the source and target''.}\n\n\\begin{qbox}\n  Find matrices corresponding to the following linear operators on $\\bbr^2$ in the standard bases.\n  \\begin{multicols}{2}\n    \\begin{enumerate}\n      \\item $\\id_{\\bbr^2}$\n      \\item $\\rot$\n      \\item $\\refl$\n      \\item $\\proj$\n    \\end{enumerate}\n  \\end{multicols}\n\\end{qbox}\n\nFor a general vector $\\vec{v} = c_1 \\vec{v}_1 + \\dots + c_k \\vec{v}_k$ in $V$ by linearity, we have\\\\\n\\begin{align*}\n  \\call (\\vec{v}) = c_1 \\call (\\vec{v}_1) + \\dots + c_k \\call (\\vec{v}_k)\\\\\n\\end{align*}\nRewriting this equation using the bases and the generalized coordinate vectors we get\\\\\n\\begin{align*}\n  [\\call]_{\\calb \\rightarrow \\calb'} [\\vec{v}]_{\\calb}\n  &= c_1 [\\call (\\vec{v}_1)]_{\\calb'} + \\dots + c_k [\\call (\\vec{v}_k)]_{\\calb'} \\\\\\\\\\\\\n  \\begin{bmatrix}\n    A_{11} & A_{12} & \\cdots & A_{1k} \\\\\n    A_{21} & A_{22} & \\cdots & A_{2k} \\\\\\\\\n    \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n    A_{\\ell 1} & A_{\\ell 2} & \\cdots & A_{\\ell k}\n  \\end{bmatrix}\n  \\begin{bmatrix} c_1 \\\\ c_2 \\\\ \\vdots \\\\ c_k \\end{bmatrix}\n    &=\n    c_1 \\begin{bmatrix}\n      A_{11} \\\\\n      A_{21} \\\\\\\\\n      \\vdots \\\\\\\\\n      A_{\\ell 1}\n    \\end{bmatrix}\n    + c_2 \\begin{bmatrix}\n      A_{12} \\\\\n      A_{22} \\\\\\\\\n      \\vdots \\\\\\\\\n      A_{\\ell 2}\n    \\end{bmatrix}\n    + \\dots +\n    c_k \\begin{bmatrix}\n      A_{1k} \\\\\n      A_{2k} \\\\\\\\\n      \\vdots \\\\\\\\\n      A_{\\ell k}\n    \\end{bmatrix}\n    \\\\\n\\end{align*}\n\nAnd, we have derived the formula for matrix multiplication!!!?!?!???!!\n\n\\begin{qbox}\n  Compute the following using the formula for matrix multiplication in the standard basis.\n  \\begin{multicols}{2}\n    \\begin{enumerate}\n      \\item $[\\id_{\\bbr^2}]\\begin{bmatrix} x \\\\ y \\end{bmatrix}$\n      \\item $[\\rot] \\begin{bmatrix} x \\\\ y \\end{bmatrix}$\n      \\item $[\\refl] \\begin{bmatrix} x \\\\ y \\end{bmatrix}$\n      \\item $[\\proj] \\begin{bmatrix} x \\\\ y \\end{bmatrix}$\n    \\end{enumerate}\n  \\end{multicols}\n\\end{qbox}\n\n\n\n\n\n% By Q.\\ref{q:linearTransformBetweenR1} every linear transformation $\\call: \\bbr^1 \\rightarrow \\bbr^1$ is just multiplication by a real number.\n% We can in general classsify all linear transformations between Euclidean spaces.\n%\n% A \\emph{matrix} of size $m \\times n$ is simply a grid of scalars with $m$ rows and $n$ columns. For a matrix $A$, we denote the entry in the $i^{th}$ row and $j^{th}$ column by $A_{ij}$.\n% \\begin{align*}\n%   A = \\begin{bmatrix}\n%     A_{11} & A_{12} & \\cdots & A_{1n} \\\\\n%     A_{21} & A_{22} & \\cdots & A_{2n} \\\\\n%     \\vdots & \\vdots & \\ddots & \\vdots \\\\\n%     A_{m1} & A_{m2} & \\cdots & A_{mn}\n%   \\end{bmatrix}.\n% \\end{align*}\n% Denote by $\\mat_{m \\times n}(\\bbr)$ the collection of matrices of size $m \\times n$.\n%\n% % \\begin{qbox}\n% %   Convince yourself that $\\mat_{m \\times n}(\\bbr)$ is a vector space over the real numbers.\n% % \\end{qbox}\n%\n% We can multiply an $m \\times n$ matrix $A$ and a vector $\\vec{v}$ of size $n$ to produce a vector $A \\vec{v}$ of size $m$ as follows.\n%\n% There are two to understand what is going on:\n% \\begin{enumerate}\n%   \\item The fast method is to ``dot'' the $i^{th}$ row with $\\vec{v}$ to produce the $i^{th}$ entry of $A \\vec{v}$.\n%   \\begin{equation}\\label{eq:appendrow}\n%   \\newcommand\\x{\\times}\n%     \\left[ \\begin{array}{cccc}\n%           A_{11} & A_{12} & \\cdots & A_{1n} \\\\\n%           \\colorbox{green}{$A_{21}$} & \\colorbox{green}{$A_{22}$} & \\cdots & \\colorbox{green}{$A_{2n}$} \\\\\n%           \\vdots & \\vdots & \\ddots & \\vdots \\\\\n%           A_{m1} & A_{m2} & \\cdots & A_{mn}\n%         \\end{array}\\right]\n%     \\left[  \\begin{array}{c}\n%               \\colorbox{green}{$v_1$} \\\\\n%               \\colorbox{green}{$v_2$} \\\\\\\\\n%               \\vdots \\\\\\\\\n%               \\colorbox{green}{$v_n$}\n%             \\end{array} \\right]\n%           =\n%     \\left[      \\begin{array}{c}\n%                 A_{11} v_1 + A_{12} v_2 + \\dots + A_{1n} v_n \\\\\n%                 \\colorbox{green}{$A_{21} v_1 + A_{22} v_2 + \\dots + A_{2n} v_n$} \\\\\n%                 \\vdots \\\\\n%                 A_{m1} v_1 + A_{m2} v_2 + \\dots + A_{mn} v_n\n%               \\end{array} \\right]\n%   \\end{equation}\n%   \\item The \\emph{span method} is to write the result as a span of the columns.\n%   \\begin{align*}\n%       \\begin{bmatrix}\n%         A_{11} & A_{12} & \\cdots & A_{1n} \\\\\n%         {A_{21}} & A_{22} & \\cdots & A_{2n} \\\\\n%         \\vdots & \\vdots & \\ddots & \\vdots \\\\\n%         A_{m1} & A_{m2} & \\cdots & A_{mn}\n%       \\end{bmatrix}\n%       \\begin{bmatrix}\n%         v_1 \\\\\n%         v_2 \\\\\\\\\n%         \\vdots \\\\\\\\\n%         v_n\n%       \\end{bmatrix}\n%       &=\n%       v_1 \\begin{bmatrix}\n%         A_{11}\\\\\n%         {A_{21}}\\\\\n%         \\vdots \\\\\n%         A_{m1}\n%       \\end{bmatrix}\n%       +\n%       v_2 \\begin{bmatrix}\n%         A_{12}\\\\\n%         {A_{22}}\\\\\n%         \\vdots \\\\\n%         A_{m2}\n%       \\end{bmatrix}\n%       +\n%       \\dots\n%       +\n%       v_n \\begin{bmatrix}\n%         A_{1n}\\\\\n%         {A_{2n}}\\\\\n%         \\vdots \\\\\n%         A_{mn}\n%       \\end{bmatrix}\n%       \\\\\\\\\n%       &=\n%       \\begin{bmatrix}\n%         A_{11} v_1 + A_{12} v_2 + \\dots + A_{1n} v_n \\\\\n%         A_{21} v_1 + A_{22} v_2 + \\dots + A_{2n} v_n \\\\\n%         \\vdots \\\\\n%         A_{m1} v_1 + A_{m2} v_2 + \\dots + A_{mn} v_n\n%       \\end{bmatrix}\n%   \\end{align*}\n%   Note that in order to be able to multiply $A$ to $\\vec{v}$ we must have\n%   \\begin{equation*}\n%     \\mbox{number of rows of } A = \\mbox{size of } \\vec{v}\n%   \\end{equation*}\n% \\end{enumerate}\n%\n% \\begin{qbox}[Practice problems]\n%   Compute $A \\vec{v}$ for the following.\n%   \\begin{enumerate}\n%     \\item\n%     \\item\n%     \\item\n%     \\item\n%   \\end{enumerate}\n% \\end{qbox}\n%\n% Given a matrix $A \\in \\mat_{m \\times n}(\\bbr)$ the (left) multiplication by $A$ defines a map\n% \\begin{align*}\n%   \\call_A : \\bbr^n &\\longrightarrow \\bbr^m \\\\\n%   \\vec{v} &\\longmapsto A \\vec{v}\n% \\end{align*}\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n% \\iffalse\n%\n%\n% Another way of saying the same thing is that $A\\vec{v}$ is a vector of size $m$ whose $i^{th}$ entry is given by\n% \\begin{align*}\n%     (A \\vec{v})_{i} &= \\sum \\limits_{j=1}^n A_{ij}v_j.\n% \\end{align*}\n%\n% \\begin{qbox}[Practice problems]\n%   Practice problems of matrix mult.\n%   For $A \\in \\mat_{m \\times n}(\\bbr)$, what is $\\call_A(\\vec{e}_i)$, where $\\vec{e}_i$ is a standard basis vector of $\\bbr^n$.\n% \\end{qbox}\\todo{Practice problems of matrix mult.}\n%\n% (Left) Multiplication by $A \\in \\mat_{m \\times n}(\\bbr)$ defines a map\n% \\begin{align*}\n%   \\call_A : \\bbr^n &\\rightarrow \\bbr^m \\\\\n%   v &\\mapsto Av\n% \\end{align*}\n%\n% \\begin{qbox}\n%   Show that $\\call_A$ is a linear transformation.\n% \\end{qbox}\n%\n% This definition further extends to multiplication of matrices. Let $B$ be a matrix of size $n \\times k$. Each column of $B$ is a vector of size $n$, so we can think of $B$ as a row of size $k$ of vectors of size $n$.\n% \\begin{align*}\n%   B\n%   &= \\begin{bmatrix}\n%     B_{11} & B_{12} & \\cdots & B_{1k} \\\\\n%     B_{21} & B_{22} & \\cdots & B_{2k} \\\\\n%     \\vdots & \\vdots & \\ddots & \\vdots \\\\\n%     B_{n1} & B_{n2} & \\cdots & B_{nk}\n%   \\end{bmatrix}\\\\\n%   &= \\begin{bmatrix}\n%     \\vec{B}_{*1} & \\vec{B}_{*2} & \\cdots &\\vec{B}_{*k}\n%     \\end{bmatrix}\n% \\end{align*}\n% where $\\vec{B}_{*i} = \\begin{bmatrix} B_{1i} \\\\ \\vdots \\\\ B_{ni} \\end{bmatrix}$ is the $i^{th}$ column.\n% For $A\\in \\mat_{m \\times n}(\\bbr)$, define the product $AB$ to be a matrix of size $m \\times k$ whose columns are $A\\vec{B}_{*1}$, $A\\vec{B}_{*2}$, $\\dots$, $A\\vec{B}_{*k}$.\n% \\begin{align*}\n%   AB\n%   :=&\n%     \\begin{bmatrix}\n%     A\\vec{B}_{*1} & A\\vec{B}_{*2} & \\cdots & A\\vec{B}_{*k}\n%     \\end{bmatrix}\n% \\end{align*}\n%\n% \\begin{qbox}\n%   Practice matrix multiplication.\n%   \\begin{enumerate}\n%     \\item\n%     \\item\n%     \\item\n%     \\item\n%   \\end{enumerate}\n% \\end{qbox}\n%\n% \\begin{qbox}[Explicit formula for multiplication]$ \\: $\n%    Let $A \\in \\mat_{m \\times n}(\\bbr)$, $B \\in \\mat_{n \\times k}(\\bbr)$, $C \\in \\mat_{k \\times \\ell}(\\bbr)$.\n%   \\begin{enumerate}\n%     \\item Show that the entry in the $i^{th}$ row and $j^{th}$ column of $AB$ is given by\n%     \\begin{align*}\n%       (AB)_{ij} = \\sum \\limits_{k = 1}^n A_{ik} B_{kj}.\n%     \\end{align*}\n%     \\item Show that $(AB) \\vec{v} = A(B \\vec{v})$ and hence $\\call_{A} \\circ \\call_{B} = \\call_{AB}$ i.e. the composition of linear transformations correspond to matrix multiplication.\n%     \\item Show that\n%           \\begin{align*}\n%             (AB)C = A(BC).\n%           \\end{align*}\n%           We say that matrix multiplication is \\textit{associative}.\n%   \\end{enumerate}\n% \\end{qbox}\n% A linear transformation $\\call: V \\rightarrow V$ with the same source and target is called a \\textit{linear operator} on $V$. A square matrix $A \\in \\mat_{n \\times n}(\\bbr)$ defines a linear operator on $\\bbr^n$.\n% Linear operators are especially important because you can always compose two linear operators. (In the language of abstract algebra, linear operators on a vector space form a ring.)\n%\n% \\begin{qbox}\n%   Let $A$, $B$ be square matrices of size $n \\times n$.\n%   \\begin{enumerate}\n%     \\item Define the \\textit{trace} of $A$ to be the sum of diagonal entries of $A$.\n%           \\begin{align*}\n%             \\tr(A) = \\sum \\limits_{i = 1}^{n} A_{ii}\n%           \\end{align*}\n%           Show that $\\tr(AB) = \\tr(BA)$.\n%     \\item Find matrices $A$, $B$ such that $\\tr(AB) \\neq \\tr(A)\\tr(B)$.\n%     \\end{enumerate}\n% \\end{qbox}\n%\n%\n% \\begin{qbox}[Invertible matrices]\n%   Let $A$, $B$ be square matrices of size $n \\times n$.\n%   \\begin{enumerate}\n%     \\item Find matrices $A$, $B$ such that $AB \\neq BA$ i.e. matrix multiplication is, in general, \\emph{non-commutative}.\n%     \\item Find $A$, $B$ such that neither $A$ nor $B$ is 0 but $AB = 0$.\n%     \\item What is the linear transformation associated to the identity matrix,\n%     \\begin{align*}\n%       \\id\n%       &:= \\begin{bmatrix}\n%         1 & 0 & \\cdots & 0 \\\\\n%         0 & 1 & \\cdots & 0 \\\\\n%         \\vdots & \\vdots & \\ddots & \\vdots \\\\\n%         0 & 0 & \\cdots & 1\n%       \\end{bmatrix}.\n%     \\end{align*}\n%     \\item The matrix $A$ is said to be \\emph{invertible} if there exists a matrix $B$ such that $AB = \\id$. Show that in this case $BA$ also equals $\\id$. Further show that such a $B$ is unique. The matrix $B$ is called the inverse of $A$, denoted $B = A^{-1}$.\n%     \\item $A$ is called a \\emph{diagonal matrix} if $A_{ij} = 0 $ if $i \\neq j$.\n%     \\begin{align*}\n%       A\n%       &:= \\begin{bmatrix}\n%         A_{11} & 0 & \\cdots & 0 \\\\\n%         0 & A_{22} & \\cdots & 0 \\\\\n%         \\vdots & \\vdots & \\ddots & \\vdots \\\\\n%         0 & 0 & \\cdots & A_{nn}\n%       \\end{bmatrix}\n%     \\end{align*}\n%     Determine when such an $A$ is invertible and find the inverse.\n%     \\item (Optional) $A$ is called an \\emph{upper-triangular matrix} if $A_{ij} = 0 $ if $i > j$.\n%     \\begin{align*}\n%       A\n%       &:= \\begin{bmatrix}\n%         A_{11} & A_{12} & \\cdots & A_{1n} \\\\\n%         0 & A_{22} & \\cdots & A_{2n} \\\\\n%         \\vdots & \\vdots & \\ddots & \\vdots \\\\\n%         0 & 0 & \\cdots & A_{nn}\n%       \\end{bmatrix}\n%     \\end{align*}\n%     Determine when such an $A$ is invertible and show that the inverse is also upper-triangular.\n%   \\end{enumerate}\n% \\end{qbox}\n%\n% \\begin{qbox}\n%   \\begin{enumerate}\n%     \\item Show that $\\mat_{m \\times n}(\\bbr)$ is a vector space. What is its dimension? Can you find a basis for it?\n%     \\item Let $A \\in \\mat_{k \\times m}(\\bbr)$.\n%     Show that the left multiplication map\n%     \\begin{align*}\n%       \\call_A : \\mat_{m \\times n}(\\bbr) &\\rightarrow \\mat_{k \\times n}(\\bbr) \\\\\n%       B &\\mapsto AB\n%     \\end{align*}\n%     is a linear transformation.\n%   \\end{enumerate}\n% \\end{qbox}\n%\n% \\begin{qbox}\n%   The \\emph{transpose} $A^T$ of a matrix $A$ is obtained by swapping the rows and columns of $A$,\n%   \\begin{align*}\n%     (A^T)_{ij} = A_{ji}.\n%   \\end{align*}\n%   \\begin{enumerate}\n%     \\item Show that {transpose} map\n%     \\begin{align*}\n%       (-)^T : \\mat_{m \\times n}(\\bbr) &\\rightarrow \\mat_{n \\times m}(\\bbr)  \\\\\n%       A &\\mapsto A^T\n%     \\end{align*}\n%     is a vector space isomorphism.\n%     \\item Show that $A^T A$ and $AA^T$ are always well defined, and are square matrices.\n%     \\item For column vectors $\\vec{w}$, $\\vec{v}$, thought of as a $n \\times 1$ matrices, $\\vec{v}^T \\cdot \\vec{w}$ is called the \\emph{dot product}, denoted $\\vec{v} \\cdot \\vec{w}$. Find an explicit formula for $\\vec{v} \\cdot \\vec{w}$.\n%   \\end{enumerate}\n% \\end{qbox}\n% \\todo{Break this problem up. Create a subsection on dot products.}\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n% \\subsection{Optional section: Determinant}\n% The determinant is a map\n% \\begin{align*}\n%   \\det: \\mat_{n \\times n}(\\bbr) \\rightarrow \\bbr\n% \\end{align*}\n% defined recursively as follows.\n% Let $A \\in \\mat_{n \\times n}(\\bbr)$.\n% Let $\\widetilde{A}_{ij}$ be the $(n-1) \\times (n-1)$ matrix obtained by removing the $i^{th}$ row and the $j^{th}$ column.\n% This matrix is called an $(n-1)\\times(n-1)$ \\textit{minor} of $A$.\n% \\begin{definition}\n%   Pick a row or a column of $A$. Assume that we have picked the $i^{th}$ row so that the entries of this row are $A_{i1}$, $\\dots$, $A_{in}$.\n%   Define the \\emph{determinant} of $A$ to be\n%   \\begin{align*}\n%     \\det A\n%     &:=\n%     \\sum \\limits_{j = 1}^n  (-1)^{i+j} A_{ij} \\det \\widetilde{A}_{ij} \\\\\n%     &:=\n%     (-1)^{i+1} A_{i1} \\det \\widetilde{A}_{i1} +(-1)^{i+2} A_{i2} \\det \\widetilde{A}_{i2} + \\dots + (-1)^{i+n} A_{in} \\det \\widetilde{A}_{in} .\n%   \\end{align*}\n% \\end{definition}\n%\n% The proof of the following theorem is beyond the scope of this class.\n% \\begin{theorem}\n%   Let $A \\in \\mat_{n \\times n}(\\bbr)$.\n%   \\begin{enumerate}\n%     \\item Determinant is well-defined i.e. it does not depend on our starting choice of row or column.\n%     \\item $\\det (AB) = \\det A \\det B$.\n%   \\end{enumerate}\n% \\end{theorem}\n%\n% \\begin{qbox}\n%   \\begin{enumerate}\n%     \\item Compute the determinant of $A = \\begin{bmatrix}\n%       A_{11} & A_{12} \\\\ A_{21} & A_{22}\n%     \\end{bmatrix}$.\n%     \\item Compute the determinant of $A = \\begin{bmatrix}\n%       A_{11} & A_{12} & A_{13} \\\\\n%       A_{21} & A_{22} & A_{23} \\\\\n%       A_{31} & A_{32} & A_{33}\n%     \\end{bmatrix}$.\n%     \\item Compute the determinant of an upper triangular matrix.\n%     \\item Show that $\\det A = \\det A^{T}$.\n%     \\item Show that similar matrices have the same determinant.\n%     \\item Show that if $A$ is invertible then $\\det A \\neq 0$.\\tablefootnote{A most remarkable fact is that the converse of this statement is also true.}\n%   \\end{enumerate}\n% \\end{qbox}\n% \\todo{break this problem up.}\n% \\fi\n\n\\subsection{Linear transformations and bases}\n\\label{section:linearTransformationsBases}\nAs it turns out, in order to study linear transformations between vector spaces, it suffices to study maps on the basis of the source.\n\n% Let $V$ be a vector space. Using a basis $\\calb = \\{ \\vec{v}_1, \\dots, \\vec{v}_k \\}$ we can define maps\n% \\begin{align*}\n%   [-]_\\calb : V & \\longrightarrow \\bbr^k\n%   &&&\n%   [-]^{-1}_\\calb : \\bbr^k & \\longrightarrow V\n%     \\\\\n%   \\vec{v} &\\longmapsto [\\: \\vec{v} \\: ]_\\calb\n%   &&&\n%   \\begin{bmatrix} c_1 \\\\ \\vdots \\\\ c_k \\end{bmatrix}\n%     &\\longmapsto\n%     c_1 \\vec{v}_1 + \\dots + c_k \\vec{v}_k\n% \\end{align*}\n%\n%\n% \\begin{proposition}\n%   \\label{proposition:BasisIsomorphism}.\n%   The maps $[-]_\\calb$ and $[-]^{-1}_\\calb$ are linear transformations and hence define vector-space isomorphisms between $V$ and $\\bbr^k$.\n% \\end{proposition}\n% \\begin{qbox}\n%   Prove Proposition \\ref{proposition:BasisIsomorphism}.\n% \\end{qbox}\n\n\nLet $V$ and $W$ be vector spaces.\nLet $\\calb = \\{ \\vec{v}_1 , \\dots, \\vec{v}_k \\}$ be a basis of $V$.\n\n\n\\begin{proposition}\n  An arbitrary map $\\varphi: \\calb \\rightarrow W$ can be  extended to a linear transformation $\\call: V \\rightarrow W$.\n\\end{proposition}\n\\begin{proof}\n  Consider an arbitrary map \\begin{align*}\n    \\varphi: \\calb &\\longrightarrow W, \\\\\n    \\vec{v}_i &\\longmapsto \\varphi(\\vec{v}_i).\n  \\end{align*}\n      For any vector $\\vec{v} \\in V$, there exist unique scalars $c_1, \\dots, c_k$ such that\n      $\\vec{v} = c_1 \\vec{v}_1 + \\dots + c_k \\vec{v}_k$.\n      Define a new map $\\call_\\varphi: V \\rightarrow W$ as, \\begin{align*}\n        \\call_\\varphi(\\vec{v}) = c_1 \\varphi(\\vec{v}_1) + \\dots + c_k \\varphi(\\vec{v}_k).\n    \\end{align*}\n    \\begin{qbox}\n      Prove that $\\call_\\varphi$ is a linear transformation.\n    \\end{qbox}\n\\end{proof}\n\n\\begin{proposition}\n  Two linear transformations $\\call$, $\\call': V \\rightarrow W$ which agree on $\\calb$ are the same. More precisely,\n  \\begin{align*}\n    \\mbox{if $\\:\\call \\vec{v}_i = \\call' \\vec{v}_i\\:$ for all $\\vec{v}_i$ in $\\calb$,}\\\\ \\mbox{then $\\:\\call \\vec{v} = \\call' \\vec{v}\\:$ for all $\\vec{v}$ in $V$.}\n  \\end{align*}\n\\end{proposition}\n\\begin{qbox}\n  Prove this using Theorem \\ref{theorem:generalizedCoordinates}.\n\\end{qbox}\n\nCombining the previous two propositions we get the following correspondence.\n\\begin{theorem}\n  Let $V$ and $W$ be vector spaces. Let $\\calb$ be a basis of $V$.\n  There is a 1-1 correspondence between set maps $\\calb \\rightarrow W$ and linear transformations $V \\rightarrow W$.\n  \\begin{align*}\n    \\set{\\mbox{set maps $\\calb \\rightarrow W$}}\n    &{\\longleftrightarrow}\n    \\set{\\mbox{linear transformations $V \\rightarrow W$}} \\\\\n    \\varphi &\\longmapsto \\call_\\varphi \\\\\n    \\call|_{\\calb} &\\longmapsfrom \\call\n  \\end{align*}\n\\end{theorem}\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Optional: Eigenvalues and eigenvectors}\n\\begin{definition}\n  For a linear operator $\\call: V \\rightarrow V$ a non-zero vector $\\vec{v}$ in $V$ is called an \\emph{eigenvector} with \\emph{eigenvalue} $\\lambda \\in \\bbr$ if\n  \\begin{align*}\n    \\call (\\vec{v}) = \\lambda \\vec{v}.\n  \\end{align*}\n  The collection of all eigenvalues is called the \\emph{spectrum} of $\\call$.\n\\end{definition}\n\n\\begin{qbox}\n  Let $V_\\lambda$ be the set of eigenvectors with eigenvalue $\\lambda$ along with the vector $\\vec{0}$.\n  \\begin{equation*}\n    V_\\lambda = \\{ \\vec{v} \\in V \\: \\mid \\: \\call (\\vec{v}) = \\lambda \\vec{v}, \\: \\vec{v} \\neq \\vec{0}\\} \\cup \\{ \\vec{0}\\}\n  \\end{equation*}\n  Show that $V_\\lambda$ is a vector space.\n\\end{qbox}\n$V_\\lambda$ is called the \\emph{eigenspace} for the eigenvalue $\\lambda$.\nIf the total dimensions of all the eigenspaces equals the dimension of $V$ then we say that $\\call$ is \\emph{diagonalizable}.\n\n\\begin{qbox}\n  For each of the following linear operators on $\\bbr^2$, find the spectrum and eigenspaces.\n  \\begin{multicols}{2}\n    \\begin{enumerate}\n      \\item $\\id_{\\bbr^2}$\n      \\item $\\rot$\n      \\item $\\refl$\n      \\item $\\proj$\n    \\end{enumerate}\n  \\end{multicols}\n\\end{qbox}\n\nWhy care about eigenvalues and eigenvectors?\nThere are far too many answers for this, here is just one.\nOftentimes, a quantum mechanical system is modelled using a linear opearator (called the Hamiltonian of the system) on a vector space of possible states.\nThe spectrum then is the possible energy values the system can attain and the vectors in the eigenspaces are the steady states for the system i.e. states which do not change over time.\nIf the linear operator is diagonalizable, then the system simplifies drastically and one can study each eigenspace separately.\n\nTo learn more about eigenvalues and eigenvectors consider taking Mark's class in W2 and to learn more about their use in Quantum Mechanics, consider taking Nic Ford's class in W3.\n\n% \\begin{qbox}\n%   \\begin{enumerate}\n%     \\item Find eigenvalues and eigenvectors of diagonal matrices.\n%     \\item Find the eigenvalues and eigenvectors (if any) of the rotation, reflection, and orthogonal projection maps in Q.\n%     \\ref{q:rotationReflection}.\n%   \\end{enumerate}\n% \\end{qbox}\n%\n% \\begin{qbox}\n%   Show that if $\\vec{v} \\neq 0 \\in \\ker \\call$ then $\\vec{v}$ is an eigenvector is an eigenvector of $\\call$. What is the corresponding eigenvalue?\n% \\end{qbox}\n%\n% The above problem provides us the method of computing eigenvectors and eigenvalues.\n% \\begin{theorem}\n%   Let $\\lambda$ be a real number.\n%   If $\\vec{v} \\in \\ker (\\call - \\lambda \\id)$ then $\\vec{v}$ is an eigenvector of $\\call$ with eigenvalue $\\lambda$.\n% \\end{theorem}\n% By Theorem \\ref{theorem:determinantInvertibility} we further get\n% \\begin{corollary}\n%   If $\\det (\\call - \\lambda \\id) = 0$ then $\\call$ has an eigenvector with eigenvalue $\\lambda$.\n% \\end{corollary}\n%\n% \\begin{qbox}\n%   Show that similar matrices have the same eigenvalues.\n% \\end{qbox}\n%\n% What's the point of eigenvectors?\n%\n% \\begin{theorem}\n%   If $A$ has $n$ linearly independent eigenvectors $\\vec{b}_1, \\dots, \\vec{b}_n$ with eigenvalues $\\lambda_1, \\dots, \\lambda_n$ then upon changing the basis (from the stardand basis) to $\\calb = \\{ \\vec{b}_1, \\dots, \\vec{b}_n\\}$ the matrix $A$ becomes a diagonal matrix!\n% \\end{theorem}\n%\n% \\begin{qbox}\n%   Check this.\n% \\end{qbox}\n%\n% \\begin{definition}\n%   A matrix $A \\in \\mat_{n \\times n}(\\bbr)$ is said to be diagonalizable if it has $n$ linearly independent eigenvectors.\n%   Such a collection of eigenvectors is called an \\emph{eigenbasis}.\n% \\end{definition}\n%\n% This phenomenon has innumerable applications in math.\n% If we think of a matrix as a system of $n$ equations, then having $n$ linearly independent eigenvectors means that we can ``decouple'' the system of equations by a suitable change of basis.\n%\n%\n% The set of eigenvalues of a linear operator $\\call$ is called its \\emph{spectrum}.\n% The Spectral Theorem garauntees the existence of an eigenbasis for certain kinds of linear operators (normal, unitary, orthogonal)...\n", "meta": {"hexsha": "2268936f3549910cd0679a862da2b5040f81ff8d", "size": 28840, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03.tex", "max_stars_repo_name": "apurvnakade/mc2019-linear-algebra", "max_stars_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "03.tex", "max_issues_repo_name": "apurvnakade/mc2019-linear-algebra", "max_issues_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "03.tex", "max_forks_repo_name": "apurvnakade/mc2019-linear-algebra", "max_forks_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9203778677, "max_line_length": 324, "alphanum_fraction": 0.6088072122, "num_tokens": 10183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.7190266813752565}}
{"text": "\\documentclass{article}\n\\title{Linear Algebra}\n\\author{Jonny Evans}\n\\include{head}\n\\begin{document}\n\\maketitle\n\\tableofcontents\n\n\n\\vspace{1cm}\n\n\nThe intention is that each section corresponds to a single\nlecture. The course comprises 19 lectures plus an in-class test in\nlecture 20. I have therefore left two hours leeway, which will get\nfilled up with more examples if it becomes clear it is not needed.\n\n\nSections marked with an asterisk I consider to be nonexaminable.\n\n\nWorkshops are scheduled to happen after lectures 2, 6, 10, 14, 18 and\nthe first four will have assessed questions.\n\n\n\\clearpage\n\\section{Matrices and transformations}\n\\subsection{Angles and rotations}\n\n\nA vector \\(v=\\ma x \\\\ y \\mz\\) in the plane is an arrow pointing \\(x\\)\nunits to the right and \\(y\\) units up. By Pythagoras's theorem, the\nlength of \\(v\\) is \\(|v|=\\sqrt{x^2+y^2}\\). If it makes an angle\n\\(\\theta\\) with the horizontal then \\(x=|v|\\cos\\theta\\) and\n\\(y=|v|\\sin\\theta\\).\n\n\n\\tka\n\\draw[thick,->] (0,0) -- (5,3);\n\\draw[dotted,thick] (0,0) -- (5,0);\n\\draw[dotted,thick] (5,0) -- (5,3);\n\\node at (2.5,0) [below] {\\(x=|v|\\cos\\theta\\)};\n\\node at (5,1.5) [right] {\\(y=|v|\\sin\\theta\\)};\n\\node[rotate=30] at (2.3,1.8) {\\(|v|=\\sqrt{x^2+y^2}\\)};\n\\draw (0.7,0) arc [radius=0.7,start angle=0,end angle=30];\n\\node at (0.85,0.25) {\\(\\theta\\)};\n\\tkz\n\n\n\\begin{Theorem}\\label{thm:rotmat2}\nLet \\(v=\\ma x \\\\ y \\mz\\) be a vector and let \\(w\\) be the vector\nobtained by rotating \\(v\\) an angle \\(\\phi\\) around its\nbasepoint. Then \\[w=\\ma x\\cos\\phi - y\\sin\\phi \\\\ x\\sin\\phi +\ny\\cos\\phi \\mz.\\]\n\\end{Theorem}\n\\begin{Proof}\nWe know that \\(v=\\ma x \\\\ y \\mz=\\ma |v|\\cos\\theta\n\\\\ |v|\\sin\\theta\\mz\\) where \\(\\theta\\) is the angle \\(v\\) makes with\nthe horizontal. After rotation, we know the following things about\n\\(w\\):\n\\begin{itemize}\n\\item its length agrees with the length of \\(v\\), i.e. \\(|w|=|v|\\).\n\\item the angle \\(w\\) makes with the horizontal is \\(\\theta+\\phi\\).\n\\end{itemize}\nTherefore\n\\begin{align*}\nw&=\\ma |w|\\cos(\\theta+\\phi) \\\\ |w|\\sin(\\theta+\\phi)\\mz\\\\\n&=\\ma |v|\\cos(\\theta+\\phi) \\\\ |v|\\sin(\\theta+\\phi)\\mz\\\\\n&=\\ma |v|\\cos\\theta\\cos\\phi-|v|\\sin\\theta\\sin\\phi \\\\\n|v|\\sin\\theta\\cos\\phi+|v|\\cos\\theta\\sin\\phi\\mz\\\\\n&=\\ma x\\cos\\phi-y\\sin\\phi \\\\ x\\cos\\phi+y\\sin\\phi\\mz.\\qedhere\n\\end{align*}\n\n\n\\end{Proof}\n\\subsection{Matrix notation}\n\n\nInspired by \\cref{thm:rotmat2}, we introduce a new piece of notation\nwhich allows us to separate out the dependence of a rotated vector\n\\(w\\) on the initial vector \\(v\\) and on the rotation angle \\(\\phi\\).\n\n\n\\begin{Definition}\nA {\\em 2-by-2 matrix} is a 2-by-2 array of numbers, like \\(A=\\ma a &\nb \\\\ c& d\\mz\\). Given a matrix and a vector \\(v=\\ma x \\\\ y\\mz\\), we\ndefine \\(Av\\) to be the new\nvector \\begin{equation}\\label{eq:mmult2}Av=\\ma a & b \\\\ c & d\\mz\\ma\nx \\\\ y \\mz:=\\ma ax+by \\\\ cx+dy\\mz .\\end{equation} We say that \\(Av\\)\nis obtained from \\(v\\) by the action of \\(A\\), in other words that\nmatrices {\\em act on} vectors.\n\n\n\\end{Definition}\nIn the context of \\cref{thm:rotmat2}, the matrix of the rotation by\nangle \\(\\phi\\) is \\begin{equation}\\label{eq:rotmat2}A=\\ma \\cos\\phi &\n-\\sin\\phi\\\\ \\sin\\phi & \\cos\\phi\\mz\\end{equation} and the rotated\nvector is \\(w=Av\\).\n\n\n\\begin{Remark}\nVector notation lets us think of arrows as pairs of numbers. Matrix\nnotation lets us think of transformations (rotations, reflections,\netc) as grids of numbers.\n\n\n\\end{Remark}\n\\begin{Remark}\nHow do you remember a formula like \\cref{eq:mmult2}? The mnemonic I\nlike is as follows. To get the first entry of \\(Av\\), you ``multiply\nthe top row of \\(A\\) into \\(v\\)'', that is you perform the\nmultiplications \\(ax\\) and \\(by\\) (working across the top row of\n\\(A\\) and down the column of \\(v\\)) and sum them.\n\n\n\\tka\n\\node at (0,0) {\\(\\ma a & b \\\\ c & d\\mz\\ma x \\\\ y\\mz\\)};\n\\draw[->] (-0.8,0.2) -- (0.1,0.2);\n\\draw[->] (0.65,0.4) -- (0.65,-0.5);\n\\node at (2.5,0) {\\(=\\quad ax+by\\)};\n\\tkz\n\n\nTo get the second\nentry, you multiply the second row of \\(A\\) into \\(v\\).\n\n\n\\tka\n\\node at (0,0) {\\(\\ma a & b \\\\ c & d\\mz\\ma x \\\\ y\\mz\\)};\n\\draw[->] (-0.8,-0.22) -- (0.1,-0.22);\n\\draw[->] (0.65,0.4) -- (0.65,-0.5);\n\\node at (2.5,0) {\\(=\\quad cx+dy\\)};\n\\tkz\n\n\n\\end{Remark}\n\\subsection{Linear maps}\n\n\nNow, given any 2-by-2 array of numbers, we get a geometric\ntransformation of the plane \\(\\RR^2\\to\\RR^2\\), \\(v\\mapsto Av\\). We\ncall such a transformation arising from a matrix a {\\em linear\nmap}\\footnote{We will see an equivalent definition of linear maps\nlater, which makes no reference to matrices.}.\n\n\n\\begin{Example}\nThe matrix \\(I=\\ma 1 & 0 \\\\ 0 & 1\\mz\\) represents the {\\em identity\ntransformation}, that is the map which sends the vector \\(\\ma x \\\\ y\n\\mz\\) to itself. For this reason, this matrix is usually called the\nidentity matrix. It plays the same role in the theory of matrices\nthat the number \\(1\\) plays in usual arithmetic, so sometimes I may\nend up writing \\(1\\) instead of \\(I\\) (in my research I always write\n\\(1\\)).\n\n\n\\end{Example}\n\\begin{Example}\nThe matrix \\(A=\\ma -1 & 0 \\\\ 0 & 1 \\mz\\) defines a reflection in the\n\\(y\\)-axis: the vector \\(\\ma 0 \\\\ 1\\mz\\), pointing along the\n\\(y\\)-axis, is fixed; the vector \\(\\ma 1 \\\\ 0 \\mz\\) pointing along\nthe \\(x\\)-axis goes to \\(\\ma -1 \\\\ 0 \\mz\\).\n\n\n\\end{Example}\n\\begin{Example}\nRotation by \\(\\pi/2\\) radians (90 degrees) is represented by the\nmatrix in \\cref{eq:rotmat2} with \\(\\phi=\\pi/2\\), that is \\(\\ma 0 &\n-1\\\\ 1 & 0\\mz\\).\n\n\n\\end{Example}\n\\begin{Example}\nThe matrix \\(\\ma 1 & 1 \\\\ 0 & 1\\mz\\) represents a {\\em shear} in the\n\\(x\\)-direction. For example, vectors along the \\(x\\)-axis are\nfixed:\n\\[\\ma 1 & 1\\\\0 & 1\\mz\\ma x \\\\ 0\\mz =\\ma x \\\\ 0\\mz;\\]\nvectors at height \\(y\\) shear \\(y\\) units to the right:\n\\[\\ma 1 & 1\\\\0 & 1\\mz\\ma x \\\\ y\\mz =\\ma x+y \\\\ y\\mz.\\]\n\n\n\\tka\n\\draw[->,thick,red] (0,0) -- (2,0);\n\\draw[->,thick,blue] (0,0) -- (0,2);\n\\draw[->,thick,purple] (0,0) -- (2,2);\n\\draw[dotted,->,thick] (0,2) -- (1.8,2);\n\\tkz\n\n\n\\end{Example}\n\\begin{Example}\nConsider the matrix \\(A=\\ma 0 & 1 \\\\ 1 & 0 \\mz\\). This has a fixed\nvector \\(v=\\ma 1 \\\\ 1\\mz\\) such that \\(Av=v\\) (indeed, if \\(v=\\ma\nx\\\\y\\mz\\) and \\(Av=v\\) then \\[\\ma x\\\\ y\\mz=\\ma 0 & 1 \\\\ 1 & 0 \\mz\\ma\nx \\\\ y\\mz=\\ma y \\\\ z\\mz,\\] so any vector with \\(x=y\\) is\nfixed. Moreover, \\(Aw=-w\\) where \\(w=\\ma 1 \\\\ -1\\mz\\), which is\northogonal to \\(v\\). Therefore \\(A\\) represents a reflection in the\nline containing \\(v\\).\n\n\n\\tka\n\\draw[red,->,thick] (0,0) -- (2,2) node [above right] {\\(u=\\ma 1\\\\ 1\\mz\\)};\n\\draw[blue,->,thick] (0,0) -- (2,-2) node [below right] {\\(v=\\ma 1\\\\ -1\\mz\\)};\n\\draw[purple,->,thick] (0,0) -- (-2,2) node [above left] {\\(Av=\\ma -1\\\\ 1\\mz\\)};\n\\draw[dotted,->,thick] (2,-2) to[bend right] (-1.8,2);\n\\tkz\n\n\n\n\n\\end{Example}\n\\begin{Example}\nIf \\(A=\\ma 1 & 1 \\\\ -1 & 1 \\mz\\) then we see \\(A\\ma 1 \\\\ 0\\mz=\\ma 1\n\\\\ -1\\mz\\) and \\(A\\ma 0 \\\\ 1\\mz=\\ma 1 \\\\ 1\\mz\\). Plotting these\nvectors, we can see that \\(A\\) represents a rotation by \\(-\\pi/4\\)\nradians followed by a rescaling by \\(\\sqrt{2}\\).\n\\tka\n\\draw[->,thick] (0,0) -- (1,0) node [right] {\\(\\ma 1 \\\\ 0\\mz\\)};\n\\draw[->,thick] (0,0) -- (0,1) node [above] {\\(\\ma 0 \\\\ 1\\mz\\)};\n\\draw[dotted,->,thick] (0,0) -- (1,-1) node [right] {\\(A\\ma 1 \\\\ 0 \\mz\\)};\n\\draw[dotted,->,thick] (0,0) -- (1,1) node [right] {\\(A\\ma 0 \\\\ 1\\mz\\)};\n\\tkz\n\n\n\\end{Example}\n\\begin{Example}\nThe matrix \\(\\ma 1 & 0 \\\\ 0 & 0\\mz\\). This gives the map \\(\\ma x\n\\\\ y \\mz\\mapsto \\ma x \\\\ 0 \\mz\\), which projects the plane\nvertically down to the \\(x\\)-axis.\n\n\n\\end{Example}\n\\begin{Example}\nThe matrix \\(A=\\ma 1 & 1 \\\\ 1 & 1 \\mz\\) sends both \\(\\ma 1 \\\\ 0 \\mz\\) and\n\\(\\ma 0 \\\\ 1\\mz\\) to the vector \\(\\ma 1 \\\\ 1\\mz\\). This means that the\ntransformation defined by \\(A\\) is an orthogonal projection to the\n\\(\\ma 1 \\\\ 1\\mz\\)-line, followed by a rescaling by a factor of\n\\(2\\sqrt{2}\\).\n\\tka\n\\draw (-1,0) -- (2,0);\n\\draw (0,-1) -- (0,2);\n\\draw[->,thick] (0,0) -- (1,0) node [below] {\\(\\ma 1 \\\\ 0\\mz\\)};\n\\draw[->,thick] (0,0) -- (0,1) node [left] {\\(\\ma 0 \\\\ 1\\mz\\)};\n\\draw[dotted,->,thick] (0,0) -- (1,1) node [above right] {\\(A\\ma 1 \\\\ 0\\mz=A\\ma 0 \\\\ 1\\mz\\)};\n\\draw[dotted,->,red,thick] (1,0) -- (1/2+0.1,1/2-0.1);\n\\draw[dotted,->,red,thick] (0,1) -- (1/2-0.1,1/2+0.1);\n\\draw[dotted,->,red,thick] (1/2,1/2) -- (1,1);\n\\tkz\n\n\n\\end{Example}\n\\subsection{Bigger matrices}\n\n\nEverything we've said so far generalises to higher dimensions.\n\n\n\\begin{Definition}\nAn \\(n\\)-vector is a column of \\(n\\) numbers. We write \\(\\RR^n\\) for\nthe set of all \\(n\\)-vectors\\footnote{We could also work with\nvectors of complex numbers, in which case we'd write \\(\\CC^n\\), or\nvectors of rational numbers, in which case we'd write \\(\\QQ^n\\), or\nsomething else entirely.}. An \\(m\\)-by-\\(n\\) matrix is a rectangular\narray of numbers with \\(m\\) rows and \\(n\\) columns. Given an\n\\(n\\)-vector \\(v\\) and an \\(m\\)-by-\\(n\\) matrix \\(A\\), we get an\n\\(m\\)-vector \\(Av\\), whose \\(i\\)th entry is the result of\nmultiplying the \\(i\\)th row of \\(A\\) into the column vector \\(v\\).\n\n\n\\end{Definition}\n\\begin{Example}\nA \\(3\\)-by-\\(3\\) matrix \\(\\ma a & b & c \\\\ d & e & f \\\\ g & h &\ni\\mz\\) defines a linear map \\(\\RR^3\\to\\RR^3\\), which takes the\n3-vector \\(\\ma x \\\\ y \\\\ z\\mz\\) to \\[\\ma a & b & c \\\\ d & e & f \\\\ g\n& h & i\\mz\\ma x \\\\ y\\\\ z\\mz=\\ma ax+by+cz\\\\ dx+ey+fz\\\\ gx+hy+iz\\mz.\\]\nAgain, the action of the matrix on the vector is defined by\nmultiplying the rows of the matrix into the column vector. For\nexample, the matrix \\(\\ma \\cos\\phi & -\\sin\\phi & 0 \\\\ \\sin\\phi &\n\\cos\\phi & 0 \\\\ 0 & 0 & 1\\mz\\) defines a rotation by \\(\\phi\\) around\nthe \\(z\\)-axis.\n\n\n\\end{Example}\n\\begin{Example}\nA \\(2\\)-by-\\(3\\) matrix \\(\\ma a & b & c \\\\ d & e & f\\mz\\) defines a\nlinear map \\(\\RR^3\\to\\RR^2\\): \\[\\ma x \\\\ y\\\\ z\\mz\\mapsto \\ma\nax+by+cz\\\\ dx+ey+fz\\mz.\\] For example, the matrix \\(\\ma 1 & 0 & 0\n\\\\ 0 & 1 & 0\\mz\\) represents the map \\(\\ma x \\\\ y \\\\ z\\mz\\mapsto\\ma\nx \\\\ y\\mz\\), which is the projection from 3-dimensional space onto\nthe \\(xy\\)-plane.\n\n\n\\end{Example}\n\\begin{Example}\nIn practice, matrices can be bigger than this. In special\nrelativity, the maps which change from one spacetime reference frame\nto another are given by \\(4\\)-by-\\(4\\) matrices called {\\em Lorentz\nmatrices}; in statistics, in linear regression models, you work with\nmatrices which have one row for each sample, so that could be very\nlarge.\n\n\n\\end{Example}\n\\begin{Example}\\label{exm:3by2}\nThe \\(3\\)-by-\\(2\\) matrix \\(\\ma 1 & 1 \\\\ 2 & 0 \\\\ 0 & 1 \\mz\\)\ndefines a linear map from \\(\\RR^2\\) to \\(\\RR^3\\) (an embedding from\nthe plane into 3-dimensional space): \\[\\ma 1 & 1 \\\\ 2 & 0 \\\\ 0 & 1\n\\mz\\ma v_1 \\\\ v_2\\mz=\\ma v_1+v_2\\\\ 2v_1 \\\\ v_2\\mz.\\] This sends the\nvector \\(\\ma 1 \\\\ 0\\mz\\) to \\(\\ma 1 \\\\ 2 \\\\ 0\\mz\\) and \\(\\ma 0\n\\\\ 1\\mz\\) to \\(\\ma 1 \\\\ 0 \\\\ 1\\mz\\). In the picture below we can see\nthe image of the plane under this linear map.\n\n\n\\tka\n\\draw[->] (0,0) -- (0,2) node [above] {\\(z\\)};\n\\draw[->] (0,0) -- (-1,-1) node [left] {\\(x\\)};\n\\draw[->] (0,0) -- (2,0) node [above] {\\(y\\)};\n\\draw[red,thick,->] (0,0) -- (-1,1) node [left] {\\(\\ma 1 \\\\ 0 \\\\ 1\\mz\\)};\n\\draw[red,thick,->] (0,0) -- (3,-1) node [below] {\\(\\ma 1\\\\ 2 \\\\ 0\\mz\\)};\n\\filldraw[fill=red,opacity=0.5,draw=none] (0,0) -- (-2,2) -- (2,2-4/3) -- (4,-4/3) -- cycle;\n\\tkz\n\n\n\\end{Example}\n\\begin{Example}\nThe matrix \\(\\ma 1 & 0 & -1\\\\ 0 & 1 & -1\\mz\\) defines a linear map\nfrom \\(\\RR^3\\) to \\(\\RR^2\\) (a projection from 3-dimensional space\nto the plane) which sends the basis vectors \\(\\ma 1 \\\\ 0 \\\\ 0\\mz\\),\n\\(\\ma 0 \\\\ 1 \\\\ 0\\mz\\) and \\(\\ma 0 \\\\ 0 \\\\ 1\\mz\\) to the vectors\n\\(\\ma 1 \\\\ 0\\mz\\), \\(\\ma 0 \\\\ 1\\mz\\) and \\(\\ma -1 \\\\ -1\\mz\\)\nrespectively. Try to represent this projection in the picture\nbelow. The blue vectors point along the coordinate axes in 3-d. The\nred vectors are the images of the blue vectors under the projection\n(in two cases, the projection does nothing, so the blue and red\nvectors coincide; we draw them as purple). The dotted lines are the\nlines along which we're projecting. The grey shaded region is the\nplane onto which we're projecting.\n\n\n\\tka\n\\draw[blue,->,thick] (0,0) -- (0,2) node [above] {\\(z\\)};\n\\draw[purple,->,thick] (0,0) -- (-0.5,-1) node [left] {\\(x\\)};\n\\draw[purple,->,thick] (0,0) -- (2,0) node [above] {\\(y\\)};\n\\draw[red,thick,->] (0,0) -- (-1,1);\n\\filldraw[draw=none,fill=gray,opacity=0.5] (-3,-1.5) -- (-2,1.5) -- (3,1.5) -- (2,-1.5) -- cycle;\n\\draw[dotted,->,thick] (0.5,2.5) -- (-1,1);\n\\draw[dotted,<-,thick] (0,0) -- (2,2);\n\\draw[dotted,<-,thick] (-0.5,-1) -- (1.5,1);\n\\draw[dotted,<-,thick] (2,0) -- (3,1);\n\\tkz\n\n\n\\end{Example}\n\\begin{Example}\nThe matrix \\(A=\\ma -1 & 0 & 0\\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1\\mz\\) defines\na linear map \\(\\RR^3\\to\\RR^3\\). We can see that \\[A\\ma 0 \\\\ y\n\\\\ z\\mz=\\ma 0 \\\\ y \\\\ z\\mz,\\qquad A\\ma x \\\\ 0 \\\\ 0\\mz=\\ma -x \\\\ 0\n\\\\ 0\\mz.\\] This means that \\(A\\) can be interpreted as a {\\em\nreflection} in the \\(yz\\)-plane.\n\n\n\\end{Example}\n\\begin{Example}\\label{exm:rot3d}\nThe matrix \\(A=\\ma 0 & -1 & 0 \\\\ 1 & 0 & 0 \\\\ 0 & 0 & 1\\mz\\) defines\na linear map \\(\\RR^3\\to\\RR^3\\) which fixes the vector \\(\\ma 0 \\\\ 0\n\\\\ 1\\mz\\) and effects a 90 degree rotation in the\n\\(xy\\)-plane. Similarly, the matrix \\(B=\\ma 1 & 0 & 0 \\\\ 0 & 0 & -1\n\\\\ 0 & 1 & 0 \\mz\\) fixes the vector \\(\\ma 1 \\\\ 0 \\\\ 0\\mz\\) and\neffects a 90 degree rotation in the \\(yz\\)-plane, and the matrix\n\\(C=\\ma 0 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ -1 & 0 & 0\\mz\\) fixes the vector\n\\(\\ma 0 \\\\ 1 \\\\ 0\\mz\\) and effects a 90 degree rotation in the\n\\(xz\\)-plane.\n\n\n\\end{Example}\nIt is much harder (though still possible) to write down a general\nrotation matrix in three dimensions. We will revisit some\nthree-dimensonal rotation matrices later in the week.\n\n\n\\clearpage\n\\section{Matrix algebra}\n\\subsection{Matrix multiplication}\nSuppose we are given two matrices \\(A=\\ma A_{11} & A_{12} \\\\ A_{21} &\nA_{22}\\mz\\), and \\(B=\\ma B_{11} & B_{12} \\\\ B_{21} & B_{22}\\mz\\). They\neach define a transformation of the plane. What happens if we {\\em\nfirst} do the transformation associated to \\(B\\), and {\\em then} do\nthe transformation associated to \\(A\\)? We get a new transformation\nassociated to a new matrix, which we call \\(AB\\).\n\\begin{align*}\nA(B(v))&=\\ma A_{11} & A_{12} \\\\ A_{21} & A_{22}\\mz\\ma B_{11} & B_{12} \\\\ B_{21} & B_{22}\\mz\\ma x \\\\ y\\mz\\\\\n&=\\ma A_{11} & A_{12} \\\\ A_{21} & A_{22}\\mz\\ma B_{11}x+B_{12}y \\\\ B_{21}x+B_{22}y\\mz\\\\\n&=\\ma A_{11}B_{11}x+A_{11}B_{12}y+A_{12}B_{21}x+A_{12}B_{22}y \\\\ A_{21}B_{11}x+A_{21}B_{12}y+A_{22}B_{21}x+A_{22}B_{22}y\\mz\\\\\n&=\\ma A_{11}B_{11}+A_{12}B_{21} & A_{11}B_{12}+A_{12}B_{22}\\\\ A_{21}B_{11}+A_{22}B_{21} & A_{21}B_{12}+A_{22}B_{22}\\mz\\ma x \\\\ y\\mz\\\\\n&=:(AB)v\n\\end{align*}\n\n\n\\begin{Definition}[Matrix multiplication]\\label{dfn:matmult}\nGiven matrices \\(A=\\ma A_{11} & A_{12} \\\\ A_{21} & A_{22}\\mz\\), and\n\\(B=\\ma B_{11} & B_{12} \\\\ B_{21} & B_{22}\\mz\\), we define the\nmatrix product\n\\[AB=\\ma A_{11}B_{11}+A_{12}B_{21} & A_{11}B_{12}+A_{12}B_{22}\\\\ A_{21}B_{11}x+A_{22}B_{21} & A_{21}B_{12}+A_{22}B_{22}\\mz.\\]\n\n\n\\end{Definition}\nHow on earth can we remember this formula? Here are two mnemonics.\n\\begin{itemize}\n\\item Just like when we act on a vector using a matrix, we can think of\nthe entries of \\(AB\\) as ``multiplying a row of \\(A\\) into a column\nof \\(B\\)''. More specifically, to get the \\(ij\\)th entry of \\(AB\\)\n(i.e. \\(i\\)th row and \\(j\\)th column) we multiply the \\(i\\)th row of\n\\(A\\) into the \\(j\\)th column of \\(B\\):\n\n\n\\tka\n\\draw[thick] (-4.3,-1.3) to[bend left] (-4.3,1.3);\n\\draw[thick] (4.3,-1.3) to[bend right] (4.3,1.3);\n\\begin{scope}[shift={(-2.3,1)}]\n\\node at (0,0) {\\(\\ma A_{11} & A_{12} \\\\ A_{21} & A_{22}\\mz\\ma B_{11} & B_{12} \\\\ B_{21} & B_{22}\\mz\\)};\n\\draw[->] (-1.8,0.2) -- (0,0.2);\n\\draw[->] (0.65,0.4) -- (0.65,-0.5);\n\\end{scope}\n\\begin{scope}[shift={(2.3,1)}]\n\\node at (0,0) {\\(\\ma A_{11} & A_{12} \\\\ A_{21} & A_{22}\\mz\\ma B_{11} & B_{12} \\\\ B_{21} & B_{22}\\mz\\)};\n\\draw[->] (-1.8,0.2) -- (0,0.2);\n\\draw[->] (1.4,0.4) -- (1.4,-0.5);\n\\end{scope}\n\\begin{scope}[shift={(-2.3,-1)}]\n\\node at (0,0) {\\(\\ma A_{11} & A_{12} \\\\ A_{21} & A_{22}\\mz\\ma B_{11} & B_{12} \\\\ B_{21} & B_{22}\\mz\\)};\n\\draw[->] (-1.8,-0.25) -- (0,-0.25);\n\\draw[->] (0.65,0.4) -- (0.65,-0.5);\n\\end{scope}\n\\begin{scope}[shift={(2.3,-1)}]\n\\node at (0,0) {\\(\\ma A_{11} & A_{12} \\\\ A_{21} & A_{22}\\mz\\ma B_{11} & B_{12} \\\\ B_{21} & B_{22}\\mz\\)};\n\\draw[->] (-1.8,-0.25) -- (0,-0.25);\n\\draw[->] (1.4,0.4) -- (1.4,-0.5);\n\\end{scope}\n\\tkz\n\\item We can also write a formula for the \\(ij\\)th entry:\n\\[(AB)_{ij}=\\sum_{k=1}^2 A_{ik}B_{kj}.\\] For example, when \\(i=1\\),\n\\(j=2\\), this equation gives the entry of the product \\(AB\\) in the\nfirst row and second column as\n\\[(AB)_{12}=A_{11}B_{12}+A_{12}B_{22}.\\]\n\n\n\\end{itemize}\n\\begin{Example}\nConsider the 90 degree rotation matrix \\(A=\\ma 0 & -1 \\\\ 1 & 0\n\\mz\\). We have\n\\begin{align*}\nA^2&=\\ma 0 & -1 \\\\ 1 & 0 \\mz\\ma 0 & -1 \\\\ 1 & 0 \\mz\\\\\n&=\\ma -1 & 0 \\\\ 0 & -1 \\mz.\n\\end{align*}\nThis makes sense: two 90 degree rotations compose to give a 180\ndegree rotation, which sends every point \\(\\ma x \\\\ y\\mz\\) to its\nopposite point \\(\\ma -x \\\\ -y\\mz\\).\n\n\n\\end{Example}\n\\begin{Example}\nMore generally, if \\[R_{\\theta_1}=\\ma \\cos\\theta_1 & -\\sin\\theta_1\n\\\\ \\sin\\theta_1 & \\cos\\theta_1\\mz\\,\\qquad R_{\\theta_2}=\\ma\n\\cos\\theta_2 & -\\sin\\theta_2 \\\\ \\sin\\theta_2 & \\cos\\theta_2\\mz\\] are\ntwo rotations then the composite is\n\\begin{align*}\nR_{\\theta_1}R_{\\theta_2}&=\\ma \\cos\\theta_1 & -\\sin\\theta_1 \\\\ \\sin\\theta_1 & \\cos\\theta_1\\mz\\ma \\cos\\theta_2 & -\\sin\\theta_2 \\\\ \\sin\\theta_2 & \\cos\\theta_2\\mz\\\\\n&=\\ma \\cos\\theta_1\\cos\\theta_2-\\sin\\theta_1\\sin\\theta_2 & -\\cos\\theta_1\\sin\\theta_2-\\sin\\theta_1\\cos\\theta_2\\\\ \\sin\\theta_1\\cos\\theta_2+\\cos\\theta_1\\sin\\theta_2 & -\\sin\\theta_1\\sin\\theta_2+\\cos\\theta_1\\cos\\theta_2\\mz\\\\\n&=\\ma \\cos(\\theta_1+\\theta_2) & -\\sin(\\theta_1+\\theta_2) \\\\ \\sin(\\theta_1+\\theta_2) & \\cos(\\theta_1+\\theta_2)\\mz\\\\\n&=R_{\\theta_1+\\theta_2}.\n\\end{align*}\n(using trigonometric addition formulas). This is what we expect, of\ncourse: rotating by \\(\\theta_2\\) and then \\(\\theta_1\\) amounts to\nrotating by \\(\\theta_1+\\theta_2\\).\n\n\n\\end{Example}\n\\begin{Example}\nLet \\(I=\\ma 1 & 0 \\\\ 0 & 1\\mz\\) be the identity matrix and \\(A\\) be\nany matrix. Then\n\\begin{align*}\nIA&=\\ma 1 & 0 \\\\ 0 & 1\\mz\\ma A_{11} & A_{12} \\\\ A_{21} & A_{22}\\mz\\\\\n&=\\ma A_{11} & A_{12} \\\\ A_{21} & A_{22}\\mz\\\\\n&=A.\n\\end{align*}\nSimilarly, \\(AI=A\\). As you can see, the identity matrix really\nplays the role of the number \\(1\\) here.\n\n\n\\end{Example}\n\\subsection{Noncommutativity}\n\n\n\\begin{Remark}\nYou might be confused about why we write \\(AB\\) for the\ntransformation which {\\em first} applies \\(B\\) and {\\em then}\napplies \\(A\\). This actually makes perfect sense if you think of\n\\(A\\) and \\(B\\) as functions acting on vectors: remember that\n\\(f(g(x))\\) means ``apply \\(f\\) to the result of first applying\n\\(g\\) to \\(x\\)''.\n\n\n\\end{Remark}\n\\begin{Remark}\nOrder matters: most of the time, \\(AB\\) is {\\em not equal to}\n\\(BA\\). In other words, {\\em matrix multiplication is not\ncommutative}. This makes matrices significantly more interesting\nalgebraic objects than numbers.\n\n\n\\end{Remark}\n\\subsection{Bigger matrices}\nFrom these examples, and what we've seen for 2-by-2 matrices,\nhopefully you can guess the definition of matrix multiplication.\n\n\n\\begin{Definition}\nIf \\(A\\) is an \\(m\\)-by-\\(n\\) matrix and \\(B\\) is a \\(n\\)-by-\\(p\\)\nmatrix then \\(AB\\) is the \\(m\\)-by-\\(p\\) matrix whose \\(ij\\)th entry\nis \\[(AB)_{ij}=\\sum_{k=1}^nA_{ik}B_{kj}.\\] In other words, the entry\nin the \\(i\\)th row and \\(j\\)th column is obtained by multiplying the\n\\(i\\)th row of \\(A\\) into the \\(j\\)th column of \\(B\\). Because \\(A\\)\nhas \\(n\\) columns and \\(B\\) has \\(n\\) rows, this multiplication\nmakes sense.\n\n\n\\end{Definition}\n\\begin{Remark}\nThis kind of notation where you see entries of the matrix written\nout with subscripts and sums all over the place is called {\\em index\nnotation}. It is extremely useful for when you would otherwise run\nout of letters to write your matrices (for example, if your matrix\nwas \\(n\\)-by-\\(n\\) and you didn't know what \\(n\\) was). If you want\nto see it being used to great effect, open any textbook on general\nrelativity, and glory in the ``d\\'{e}bauches des indices''.\n\n\n\\end{Remark}\n\\begin{Example}\nHere are some examples of matrix multiplications:\n\\begin{align*}\n\\ma 0 & 0 & 1 \\\\ 1 & 0 & 0 \\\\ 0 & 1 & 0\\mz \\ma x \\\\ y \\\\ z\\mz&=\\ma z \\\\ x \\\\ y\\mz\\\\\n\\ma 1 & 2 & 3 \\\\ -1 & 1/2 & 0\\mz \\ma 2 & -3 \\\\ -1 & 0 \\\\ 0 & 1\\mz&=\\ma 0 & 0 \\\\ -5/2 & 3\\mz\\\\\n\\ma 1 & -1 & 1 & -1\\mz\\ma 1 \\\\ 2 \\\\ 3 \\\\ 4\\mz&=\\ma -2\\mz\\\\\n\\ma 1 \\\\ 2 \\\\ 3 \\\\ 4\\mz\\ma 1 & -1 & 1 & -1\\mz&=\\ma 1 & -1 & 1 & -1\\\\ 2 & -2 & 2 & -2\\\\ 3 & -3 & 3 & -3\\\\4 & -4 & 4 & -4\\mz\n\\end{align*}\n\n\n\\end{Example}\n\\subsection{Other operations}\n\n\nWe have now seen that you can define the product of two matrices. In\nfact, you can do lots of other operations.\n\n\n\\begin{Definition}\nGiven two \\(m\\)-by-\\(n\\) matrices \\(A\\) and \\(B\\), we define their\n{\\em sum} \\(A+B\\) to be the \\(m\\)-by-\\(n\\) matrix \\(A+B\\) whose\n\\(ij\\)th entry is \\[(A+B)_{ij}=A_{ij}+B_{ij}.\\] That is, the entry\nin the \\(i\\)th row and \\(j\\)th column of \\(A+B\\) is the sum of the\ncorresponding entries for \\(A\\) and \\(B\\).\n\n\n\\end{Definition}\n\\begin{Remark}\nMatrix addition is kind of boring in comparison to matrix\nmultiplication. Nonetheless, it plays an important role.\n\n\n\\end{Remark}\n\\begin{Definition}[Scaling]\\label{dfn:scaling}\nGiven a matrix \\(A\\) and a number \\(\\lambda\\), we define \\(\\lambda\nA\\) to be the matrix \\[\\lambda A\\] whose \\(ij\\)th entry is\n\\((\\lambda A)_{ij}=\\lambda A_{ij}\\). If \\(A\\) corresponds to some\ngeometric transformation then \\(\\lambda A\\) corresponds to the same\ngeometric transformation followed by a rescaling by a factor of\n\\(\\lambda\\).\n\n\n\\end{Definition}\nMore interestingly, we can define exponentials of matrices.\n\n\n\\begin{Definition}\nGiven an \\(n\\)-by-\\(n\\) matrix \\(A\\), we define its {\\em\nexponential} \\(\\exp(A)\\) to be the infinite sum\n\\[\\exp(A)=I+A+\\frac{1}{2}A^2+\\frac{1}{3!}A^3+\\cdots=\\sum_{n\\geq\n0}\\frac{1}{n!}A^n,\\] where we define \\(A^0=I\\).\n\n\n\\end{Definition}\n\\begin{Example}\nLet \\(A=\\ma 0 & 1 \\\\ 0 & 0\\mz\\). Then\n\\begin{align*}\nA^2&=\\ma 0 & 1 \\\\ 0 & 0\\mz\\ma 0 & 1 \\\\ 0 & 0\\mz\\\\\n&=\\ma 0 & 0 \\\\ 0 & 0\\mz,\n\\end{align*}\nso \\(0=A^3=A^4=\\cdots\\) and the infinite sum reduces to:\n\\begin{align*}\n\\exp(A)&=I+A+0+0+\\cdots\\\\\n&=\\ma 1 & 1 \\\\ 0 & 1\\mz.\n\\end{align*}\n\n\n\\end{Example}\n\\begin{Example}\nLet \\(A=\\ma 0 & -\\theta \\\\ \\theta & 0\\mz\\). Then\n\\begin{align*}\nA^2&=\\ma 0 & -\\theta \\\\ \\theta & 0\\mz\\ma 0 & -\\theta \\\\ \\theta & 0\\mz\\\\\n&=\\ma -\\theta^2 & 0 \\\\ 0 & -\\theta^2\\mz\\\\\n&=-\\theta^2I.\n\\end{align*}\nTherefore\n\\begin{align*}\nA^3&=-\\theta^2IA=-\\theta^2A\\\\\nA^4&=-\\theta^2A^2=(-\\theta^2)^2I=\\theta^4I\\\\\nA^5&=\\theta^4IA=\\theta^4A\\\\\nA^6&=\\theta^4A^2=-\\theta^6I.\n\\end{align*}\nFollowing this pattern, we get \\(A^{2n}=(-1)^{2n}\\theta^{2n}\\) and\n\\(A^{2n}=(-1)^{2n}\\theta^{2n}A\\). This means\n\\begin{align*}\n\\exp(A)&=\\left(I+\\frac{1}{2}A^2+\\frac{1}{4!}A^4+\\cdots\\right)+\\left(A+\\frac{1}{3!}A^3+\\cdots\\right)\\\\\n&=\\left(1-\\frac{\\theta^2}{2}+\\frac{\\theta^4}{4!}+\\cdots\\right)I+\\left(\\theta-\\frac{\\theta^3}{3!}+\\cdots\\right)A\\\\\n&=\\cos\\theta I+\\sin\\theta A\\\\\n&=\\ma \\cos\\theta & -\\sin\\theta \\\\ \\sin\\theta & \\cos\\theta\\mz.\n\\end{align*}\nThis is, remarkably, the formula for a rotation matrix by an angle\n\\(\\theta\\). Starting from a very simple matrix \\(\\ma 0 & -\\theta\n\\\\ \\theta & 0\\mz\\) and using the exponential function, we have ended\nup with the general formula for a rotation matrix in the plane. You\ncan probably imagine that this becomes even more useful as a way of\nencoding rotations in 3-dimensions.\n\n\n\\end{Example}\n\\clearpage\n\n\n\\section{Dot products and orthogonal matrices}\n\\subsection{Dot product}\n\n\nGiven two vectors \\(v,w\\in\\RR^n\\), how do you figure out the angle\nbetween them?\n\n\n\\begin{Definition}[Dot product]\\label{dfn:dotproduct}\nGiven two vectors \\(v=\\ma v_1\\\\ \\vdots\\\\ v_n\\mz\\) and \\(w=\\ma\nw_1\\\\ \\vdots\\\\ w_n\\mz\\), we define the {\\em dot product} of \\(v\\)\nand \\(w\\) to be the number \\[v\\cdot w:=v_1w_1+\\cdots+v_nw_n.\\]\n\n\n\\end{Definition}\n\\begin{Theorem}\\label{thm:dot}\nIf \\(v\\) and \\(w\\) are separated by an angle \\(\\phi\\) then \\(v\\cdot\nw=|v||w|\\cos\\phi\\).\n\n\n\\end{Theorem}\nWe will prove the theorem momentarily. Let us first explore it a\nlittle.\n\n\n\\begin{Example}\nThe vectors \\(v=\\ma 1 \\\\ 0 \\mz\\) and \\(w=\\ma 0 \\\\ 1 \\mz\\) satisfy\n\\(v\\cdot w=1\\times 0+0\\times 1=0\\). Indeed, they are {\\em\northogonal} to one another (i.e. at right-angles), so are separated\nby an angle \\(\\pi/2\\) radians, and \\(\\cos(\\pi/2)=0\\).\n\n\n\\end{Example}\n\\begin{Example}\nThe vectors \\(v=\\ma 1 \\\\ 1 \\mz\\) and \\(w=\\ma 1 \\\\ 0 \\mz\\) satisfy\n\\(v\\cdot w=1\\), \\(|v|=\\sqrt{2}\\), \\(|w|=1\\), so if \\(\\phi\\) is the\nangle separating them then \\[1=v\\cdot\nw=|v||w|\\cos\\phi=\\sqrt{2}\\cos\\phi,\\] so\n\\(\\cos\\phi=\\frac{1}{\\sqrt{2}}\\), and \\(\\phi=\\pi/4\\) radians.\n\n\n\\end{Example}\n\\begin{Remark}\nYou may be worried that \\(\\cos\\phi\\) doesn't determine \\(\\phi\\)\ncompletely, for example \\(\\cos(\\pi/2)=\\cos(3\\pi/2)=0\\). However, the\nambiguity is precisely whether you are measuring the angle from\n\\(v\\) to \\(w\\) clockwise or anticlockwise, so don't worry unless\nthat distinction is important to you.\n\n\n\\end{Remark}\nWe now move in the direction of proving \\cref{thm:dot}. Notice that\nthe definition of dot product looks a lot like matrix\nmultiplication. In fact, \\[\\ma v_1\\\\ \\vdots\\\\v_n\\mz\\cdot\\ma\nw_1\\\\\\vdots\\\\ w_n\\mz=\\ma v_1 & \\cdots & v_n\\mz\\ma\nw_1\\\\\\vdots\\\\ w_n\\mz.\\] In other words, we have turned one of our\ncolumn vectors on its side to make it into a row vector. This\noperation is called {\\em transposition}.\n\n\n\\begin{Definition}\nGiven an \\(m\\)-by-\\(n\\) matrix \\(A\\) with entries \\(A_{ij}\\), its\n{\\em transpose} \\(A^T\\) is defined to be the \\(n\\)-by-\\(m\\) matrix\nwith entries \\(A_{ji}\\). For example\n\\begin{align*}\n\\ma 1 & 2\\\\ 3 & 4\\mz^T&=\\ma 1 & 3 \\\\2 & 4\\mz\\\\\n\\ma 1 \\\\ 2 \\\\ 3 \\\\ 4\\mz^T&=\\ma 1 & 2 & 3 &4\\mz.\n\\end{align*}\n\n\n\\end{Definition}\nIn other words, we can write dot product as \\(v\\cdot w=v^Tw\\).\n\n\n\\begin{Lemma}\nWe have \\((AB)^T=B^TA^T\\).\n\\end{Lemma}\n\\begin{Proof}\nSince \\(A^T_{kj}=A_{jk}\\) and \\(B^T_{ik}=B_{ki}\\), we have\n\\begin{align*}\n(AB)^T_{ij}&=(AB)_{ji}\\\\\n&=\\sum_kA_{jk}B_{ki}\\\\\n&=\\sum_k A^T_{kj}B^T_{ik}\\\\\n&=\\sum_k B^T_{ik}A^T_{kj}\\\\\n&=(B^TA^T)_{ij}.\n\\end{align*}\nTherefore \\((AB)^T=B^TA^T\\), because all the entries agree. \\qedhere\n\n\n\\end{Proof}\n\\begin{Remark}\nYou may complain that matrix multiplication is not commutative, so\nthe step where we switch \\(A^T_{kj}B^T_{ik}=B^T_{ik}A^T_{kj}\\) is\nnot valid. Fortunately your objection is invalid: \\(A^T_{kj}\\) and\n\\(B^T_{ik}\\) are matrix {\\em entries} (i.e. numbers!) not matrices\nthemselves.\n\n\n\\end{Remark}\n\\subsection{Orthogonal matrices}\n\n\n\\begin{Definition}\nAn \\(n\\)-by-\\(n\\) matrix \\(A\\) is called {\\em orthogonal} if\n\\(A^TA=I\\).\n\n\n\\end{Definition}\n\\begin{Example}\nThe rotation matrix \\(R_{\\theta}=\\ma \\cos\\theta & -\\sin\\theta\n\\\\ \\sin\\theta & \\cos\\theta\\mz\\) is orthogonal. To see this, note\nthat \\(R_{\\theta}^T=\\ma \\cos\\theta & \\sin\\theta \\\\ -\\sin\\theta &\n\\cos\\theta\\mz=R_{-\\theta}\\), so\n\\(R_{\\theta}^TR_{\\theta}=R_{\\theta-\\theta}=I\\). In general, you\nshould think of an orthogonal matrix as giving a higher-dimensional\nversion of a rotation or reflection.\n\n\n\\end{Example}\n\\begin{Lemma}\nIf \\(A\\) is an orthogonal matrix then \\((Av)\\cdot(Aw)=v\\cdot w\\). In\nparticular, the action of an orthogonal matrix doesn't change the\nlengths of vectors.\n\\end{Lemma}\n\\begin{Proof}\nWe have\n\\begin{align*}\n(Av)\\cdot(Aw)&=(Av)^TAw\\\\\n&=v^TA^TAw\\\\\n&=v^TIw\\\\\n&=v^Tw\\\\\n&=v\\cdot w.\n\\end{align*}\nThe length of a vector \\(v\\) is \\(\\sqrt{v\\cdot\nv}=\\sqrt{v_1^2+\\cdots+v_n^2}\\) by Pythagoras's theorem, so\n\\(|Av|=\\sqrt{(Av)\\cdot(Av)}=\\sqrt{v\\cdot v}=|v|\\). \\qedhere\n\n\n\\end{Proof}\n\\begin{Proof}[Proof of \\cref{thm:dot}]\\label{prf:thm:dot}\nBecause we're only interested in the two vectors \\(v\\) and \\(w\\), we\ncan look at the plane which contains them, and we reduce to the case\nwhere \\(v\\) and \\(w\\) are 2-dimensional. Moreover, we can rotate so\nthat \\(v\\) points in the positive \\(x\\)-direction. Rotation is given\nby the action of an orthogonal matrix, so \\(v\\cdot w\\) is unchanged\nby this. If \\(v\\) points in the positive \\(x\\)-direction then\n\\(v=\\ma |v| & 0\\mz\\) and \\(v\\cdot w=|v|w_1\\), where \\(w=\\ma\nw_1\\\\ w_2\\mz\\). Since \\(w\\) makes an angle \\(\\phi\\) with \\(v\\),\n\\(w=\\ma |w|\\cos\\phi \\\\ |w|\\sin\\phi\\mz\\), so the formula\nfollows. \\qedhere\n\n\n\\end{Proof}\n\\clearpage\n\\section{3-dimensional rotations}\n\\subsection{3-dimensional rotations}\n\n\nArmed with our newfound understanding of angles, let's take a look at\nsome 3-by-3 rotation matrices and figure out what rotation is being\nrepresented.\n\n\n\\begin{Example}\nThe matrix \\(A=\\ma \\cos\\phi & -\\sin\\phi & 0 \\\\ \\sin\\phi & \\cos\\phi &\n0 \\\\ 0 & 0 & 1\\mz\\) is a rotation matrix; just by looking at it, we\ncan see that the \\(z\\)-axis is fixed: \\[A\\ma 0 \\\\ 0 \\\\ 1\\mz=\\ma 0\n\\\\ 0 \\\\ 1\\mz\\] and the \\(xy\\)-plane gets rotated by \\(\\phi\\); for\nexample, the unit vector \\(v=\\ma 1 \\\\ 0 \\\\ 0 \\mz\\) goes to the unit\nvector \\(w=\\ma \\cos\\phi \\\\ \\sin\\phi \\\\ 0 \\mz\\), and \\(v\\cdot\nw=\\cos\\phi\\), so \\(v\\) gets rotated by an angle \\(\\phi\\).\n\n\n\\end{Example}\n\\begin{Example}\nIn \\cref{exm:rot3d}, I claimed that \\(C=\\ma 0 & 0 & 1 \\\\ 0 & 1 & 0\n\\\\ -1 & 0 & 0\\mz\\) is a rotation matrix for \\(\\RR^3\\). That means\nthere's a fixed vector (the axis) and the plane orthogonal to the\naxis is rotated by some angle. Let's figure out what the axis is and\nwhat the angle is.\n\n\nIf \\(u=\\ma x \\\\ y\\\\z\\mz\\) is a fixed vector then \\(u=Cu\\), which in\nthis case means\n\\[\\ma\nx \\\\y \\\\ z\\mz=\\ma 0 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ -1 & 0 & 0 \\mz\\ma x \\\\ y\n\\\\ z\\mz=\\ma z \\\\ y \\\\ -x\\mz.\\]\nThis implies \\(-x=z=x\\), so \\(x=z=0\\), and we see that the\n\\(y\\)-axis is fixed.\n\n\nThe \\(xz\\)-plane is orthogonal to the \\(y\\)-axis, so the next task\nis to find by what angle it is rotated. Let us pick a vector (say\n\\(v=\\ma 1 \\\\ 0 \\\\ 0\\mz\\)) in that plane and act using \\(C\\) to get a\nnew vector \\(Cv=\\ma 0 \\\\ 0 \\\\ -1\\mz\\). We note that \\(v\\cdot Cv=0\\),\nso in this case the rotation must be through 90 degrees.\n\n\n\\end{Example}\n\\begin{Example}\nHere is a more involved example. The matrix \\(D=\\ma 0 & 0 & 1 \\\\ 1 &\n0 & 0 \\\\ 0 & 1 & 0\\mz\\) defines a rotation in 3 dimensions. To find\nthe axis \\(u\\) we need to solve \\(u=Du\\): \\[\\ma x \\\\ y \\\\ z \\mz=\\ma\n0 & 0 & 1 \\\\ 1 & 0 & 0 \\\\ 0 & 1 & 0\\mz\\ma x \\\\ y\\ \\\\ z\\mz=\\ma z \\\\ x\n\\\\ y\\mz,\\] which means \\(x=y=z\\), so the axis points in the\ndirection of \\(u=\\ma 1 \\\\ 1 \\\\ 1 \\mz\\). Now pick \\(v=\\ma 1 \\\\ -1\n\\\\ 0\\mz\\) orthogonal to \\(u\\) (\\(u\\cdot v=1-1=0\\)). Compute \\(Av=\\ma\n0 \\\\ 1 \\\\ -1\\mz\\), and \\[v\\cdot Av=\\ma 1 \\\\ -1 \\\\ 0\\mz\\cdot \\ma 0\n\\\\ 1 \\\\ -1\\mz=-1.\\] Now \\(|v|=|Av|=\\sqrt{2}\\), so\n\\(\\cos\\phi=\\frac{v\\cdot Av}{\\sqrt{2}\\sqrt{2}}=-\\frac{1}{2}\\), so\n\\(\\cos(\\phi)=-1/2\\) and \\(\\phi=2\\pi/3\\).\n\n\n\\end{Example}\n\\begin{Remark}\nHow do I recognise when a matrix is a rotation matrix? It turns out\nthat the rotations are precisely the orthogonal matrices with\ndeterminant one (we will define the determinant of a matrix later).\n\n\n\\end{Remark}\n\\subsection{Logarithms of rotations*}\n\n\nWe saw earlier that \\(\\exp\\ma 0 & -\\theta \\\\ \\theta & 0 \\mz=\\ma\n\\cos\\theta & -\\sin\\theta \\\\ \\sin\\theta & \\cos\\theta\\mz\\). This is a\nspecial case of a beautiful general fact.\n\n\n\\begin{Definition}\nWe say that a matrix is symmetric (respectively antisymmetric) if\n\\(A^T=A\\) (respectively \\(A^T=-A\\)).\n\n\n\\end{Definition}\n\\begin{Theorem}\nIf \\(A\\) is an antisymmetric matrix then \\(\\exp(tA)\\) is\northogonal for all \\(t\\). Conversely, if \\(\\exp(tA)\\) is\northogonal for all \\(t\\) then \\(A\\) is antisymmetric.\n\\end{Theorem}\n\\begin{Proof}\nIf \\(A\\) is antisymmetric then\n\\(\\exp(tA)^T=\\exp(tA^T)=\\exp(-tA)\\). We will see below that\n\\[\\exp(-B)\\exp(B)=I\\] for any matrix \\(B\\), so this shows that\n\\(\\exp(tA)\\) is orthogonal for all \\(t\\).\n\n\nFor the converse, you can differentiate the expression \\(\\exp(tA)\\)\nwith respect to \\(t\\). This is nothing scary: \\(\\exp(tA)\\) is just a\nmatrix whose coefficients are functions of \\(t\\), and\ndifferentiation just means differentiating the entries. Here are\nsome properties of the matrix exponential which we need:\n\\begin{itemize}\n\\item \\(\\frac{d}{dt}\\exp(tA)=A\\exp(tA)\\)\n\\item \\(\\exp(tA)^T=\\exp(tA^T)\\)\n\\item \\(\\frac{d}{dt}(M(t)N(t))=\\frac{dM(t)}{dt}N+M(t)\\frac{dN(t)}{dt}\\)\n(Leibniz rule).\n\\end{itemize}\nAssuming these properties, we have\n\\[0=\\left.\\frac{d}{dt}\\right|_{t=0}I=\n\\left.\\frac{d}{dt}\\right|_{t=0}(\\exp(tA)\\exp(tA)^T)=A+A^T,\\]\nso \\(A\\) is antisymmetric. \\qedhere\n\n\n\\end{Proof}\nLet's prove all the properties we wanted. I'll just assume we don't\nhave to worry about convergence issues for the power series defining\n\\(\\exp\\) (it's one of the nicest power series around and you can\nalways rely on it behaving the way you want it to).\n\n\n\\begin{Lemma}\nIf \\(B\\) is a matrix then \\(\\exp(B)\\exp(-B)=I\\).\n\\end{Lemma}\n\\begin{Proof}\nWe have\n\\begin{align*}\n\\exp(B)\\exp(-B)&=\\sum_{m\\geq 0}\\sum_{n\\geq 0}\\frac{1}{m!n!}B^m(-B)^n\\\\\n&=\\sum_{p\\geq 0}\\sum_{m=0}^p\\frac{1}{m!(p-m)!}B^m(-B)^n\\\\\n&=\\sum_{p\\geq 0}\\frac{1}{p!}\\sum_{m=0}^p\\frac{p!}{m!(p-m)!}B^m(-B)^n\\\\\n&=\\sum_{p\\geq 0}\\frac{1}{p!}(B-B)^p\\\\\n&=\\exp(0)=I\n\\end{align*}\nwhere we substituted \\(p=m+n\\) and rearranged the infinite sum on\nline 2, multiplied by \\(p!/p!\\) on line 3, and used the binomial\ntheorem on line 4. \\qedhere\n\n\n\\end{Proof}\n\\begin{Lemma}\n\\[\\frac{d}{dt}\\exp(tA)=A\\exp(tA).\\]\n\\end{Lemma}\n\\begin{Proof}\n\\begin{align*}\n\\frac{d}{dt}\\exp(tA)&=\\frac{d}{dt}\\sum_{n\\geq 0}\\frac{t^n}{n!}A^n\\\\\n&=\\sum_{n\\geq 1}\\frac{t^{n-1}}{(n-1)!}A^n\\\\\n&=A\\sum_{m\\geq 0}\\frac{t^m}{m!}A^m\\mbox{ relabelling }m=n-1. \\qedhere\n\\end{align*}\n\n\n\\end{Proof}\n\\begin{Lemma}\n\\[\\exp(B)^T=\\exp(B^T).\\]\n\\end{Lemma}\n\\begin{Proof}\nClearly we have \\((B_1+B_2)^T=B_1^T+B_2^T\\), and we also have\n\\((B^n)^T=(B^T)^n\\) (using \\((AB)^T=B^TA^T\\) and\ninduction). Therefore\n\\[\\exp(B)^T=\\left(\\sum_{n\\geq 0}\\frac{1}{n!}B^n\\right)^T=\\sum_{n\\geq 0}\\frac{1}{n!}(B^n)^T=\\sum_{n\\geq 0}\\frac{1}{n!}(B^T)^n=\\exp(B^T). \\qedhere\\]\n\n\n\\end{Proof}\n\\begin{Lemma}\n\\[\\frac{d}{dt}(M(t)N(t))=\\frac{dM(t)}{dt}N+M(t)\\frac{dN(t)}{dt}.\\]\n\\end{Lemma}\n\\begin{Proof}\nLet's use index notation. The \\(ij\\) entry of \\(M(t)N(t)\\) is\n\\(\\sum_kM_{ik}(t)N_{kj}(t)\\), so\n\\begin{align*}\n\\frac{d}{dt}(M(t)N(t))_{ij}&=\\frac{d}{dt}\\left(\\sum_kM_{ik}(t)N_{kj}(t)\\right)\\\\\n&=\\sum_k\\frac{dM_{ik}(t)}{dt}N_{kj}(t)+\\sum_kM_{ik}(t)\\frac{dN_{kj}(t)}{dt}\\\\\n&\\qquad\\qquad\\mbox{ using the usual Leibniz rule}\\\\\n&=\\left(\\frac{dM(t)}{dt}N+M(t)\\frac{dN(t)}{dt}\\right)_{ij}. \\qedhere\n\\end{align*}\n\n\n\\end{Proof}\n\\begin{Example}\nThe general 3-d rotation matrix is therefore \\(\\exp\\ma 0 & \\alpha &\n\\gamma \\\\ -\\alpha & 0 & \\beta \\\\ -\\gamma & -\\beta & 0\\mz\\).\n\n\n\\end{Example}\n\\clearpage\n\\section{Simultaneous equations}\n\\subsection{Simultaneous equations}\nA system of simultaneous linear equations, like\n\\begin{align*}\nx-y&=-1\\\\\nx+y&=3\n\\end{align*}\ncan be written as a single matrix equation \\(Av=b\\), like\n\\[\\ma 1 & -1 \\\\ 1 & 1 \\mz\\ma x \\\\ y \\mz=\\ma -1 \\\\ 3\\mz.\\]\nIn fact, we often omit the \\(x\\)s and \\(y\\)s completely, and write\ninstead the {\\em augmented matrix}\n\\[\\begin{pmatrix}[cc|c]\n1 & -1 & -1 \\\\ 1 & 1 & 3\n\\end{pmatrix}\\]\n\n\n\\subsection{Row operations}\n\n\nWhen we try to solve a system of equations like this, there are a\nbunch of operations we perform, like ``add the second equation to the\nfirst'' or ``multiply the first equation by 5'', and we can interpret\nthese in terms of matrices. We illustrate this using the above\nexample.\n\n\n\\begin{longtable}{p{5.6cm}p{5.7cm}}\nStart with:\n{\\begin{align*}x-y&=-1\\\\ x+y&=3.\\end{align*}}\n&\nWrite the {\\em augmented matrix}\n{\\[\\begin{pmatrix}[cc|c] 1 & -1 & -1\\\\ 1 & 1 & 3\\end{pmatrix}.\\]}\n\\\\\nSubtract eq. 1 from eq. 2: {\\begin{align*}x-y&=-1\\\\2y&=4.\\end{align*}}\n&\nSubtract row 1 from row 2: {\\[\\begin{pmatrix}[cc|c] 1 & -1 & -1\\\\ 0 & 2 & 4\\end{pmatrix}.\\]}\n\\\\\nHalve eq. 2 {\\begin{align*}x-y&=-1\\\\y&=2\\end{align*}}\n&\nHalve row 2: {\\[\\begin{pmatrix}[cc|c] 1 & -1 & -1\\\\ 0 & 1 & 2\\end{pmatrix}\\]}\n\\\\\nAdd eq. 2 to eq. 1: {\\begin{align*}x&=1\\\\y&=2,\\end{align*}}\n&\nAdd row 2 to row 1: {\\[\\begin{pmatrix}[cc|c] 1 & 0 & 1\\\\ 0 & 1 & 2\\end{pmatrix}\\]}\n\\\\\nand we're done.\n&\ni.e. {\\[\\ma 1 & 0 \\\\ 0 & 1 \\mz\\ma x \\\\ y \\mz=\\ma 1 \\\\ 2\\mz,\\]} or \\(x=1\\), \\(y=2\\).\n\\end{longtable}\n\n\n\\begin{Definition}[Row operations]\\label{dfn:rowops}\nGiven a matrix (possibly augmented with a vertical bar somewhere),\nwe define the {\\em row operations}:\n\\begin{itemize}\n\\item (Type I) \\(R_i\\mapsto R_i+\\lambda R_j\\): ``add \\(\\lambda\\) times\nthe \\(j\\)th row to the \\(i\\)th row''.\n\\item (Type II) \\(R_i\\mapsto \\lambda R_i\\): ``multiply the \\(i\\)th row\nby \\(\\lambda\\)''.\n\n\n\\end{itemize}\n\\end{Definition}\nSo the sequence of row operations used in the above example was:\n\\(R_2\\mapsto R_2-R_1\\), \\(R_2\\mapsto \\frac{1}{2}R_2\\), \\(R_1\\mapsto\nR_1+R_2\\).\n\n\n\\subsection{Echelon forms}\n\n\nThe dream goal of solving simultaneous equations is to reduce to a\nsystem of the form \\[x=\\mbox{something},\\quad y=\\mbox{something\nelse},\\ldots\\] If you can achieve this (which is not always possible,\nfor example if your system has no solutions, or has many solutions)\nthen, in terms of matrices, you have reduced the left-block of your\naugmented matrix to the identity matrix. In general, the best we can\nhope for is to reduce our matrix to so-called {\\em reduced echelon\nform}.\n\n\n\\begin{Definition}[Echelon forms]\\label{dfn:rowech}\nGiven a nonzero row \\(R\\) of a matrix \\(M\\), we define its {\\em\nleading entry} to be the leftmost nonzero entry.\n\\begin{itemize}\n\\item We say that \\(M\\) is in {\\em echelon form} if, for every nonzero\nrow \\(R_i\\), the row \\(R_{i-1}\\) immediately above it is nonzero\nand the leading entry of \\(R_{i-1}\\) sits to the left of the\nleading entry of \\(R_i\\). In other words, the bottom-left chunk of\n\\(M\\) consists of zeros sitting in a configuration like a set of\nsteps\\footnote{The word ``echelon'' comes from the French word\n``\\'{e}chelle'' meaning ``ladder''.}.\n\\item We say that \\(M\\) is in {\\em reduced echelon form} if it is in\nechelon form, every leading entry is a \\(1\\) and every other entry\nin a column containing a leading entry vanishes. If the \\(i\\)th\nrow of \\(M\\) has leading entry \\(M_{ij}=1\\) then we will call\n\\(j\\) the \\(i\\)th {\\em leading index}. We call the other indices\n{\\em free} and write \\(F\\) for the set of free indices.\n\n\n\\end{itemize}\n\\end{Definition}\n\\begin{Example}\nConsider the following matrices\n\\begin{align*}\nA&=\\ma 1 & 2 & 3 \\\\ 0 & 1 & 2 \\\\ 0 & 0 & 1\\mz,& B&=\\ma 1 & 1\\mz,& C&=\\ma 1 & 0 & 1 & 1\\\\ 0 & 1 & 2 & -1\\mz,\\\\\nD&=\\ma 0 & 0 & 1 & 0 \\\\ 0 & 0 & 1 & 0\\mz& E&=\\ma 2 & 0 & 1 \\\\ 0 & 3 & 0 \\\\ 0 & 0 & 0 \\mz& F&=\\ma 0 & 1 \\\\ 1 & 0\\mz,\\\\\nG&=\\ma 1 & 2 & 0 & 1 \\\\ 0 & 0 & 1 & 8 \\\\ 0 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0\\mz&H&=\\ma 0 & 1 & 0 & 0 & 0\\\\ 0 & 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 0 & 1 \\mz&J&=\\ma 0 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 0\\mz\n\\end{align*}\n\\(A,B,C,E,G,H\\) are in echelon form. \\(B,C,G,H\\) are in reduced\nechelon form. \\(D,F,J\\) are in neither. For the matrices in reduced\nechelon form:\n\\begin{itemize}\n\\item \\(B\\) has one leading index, \\(1\\), and one free index \\(2\\).\n\\item the leading indices of \\(C\\) are \\(1,2\\); the free indices are\n\\(3,4\\).\n\\item the leading indices of \\(G\\) are \\(1,3\\); the free indices are\n\\(2,4\\).\n\\item the leading indices of \\(H\\) are \\(2,3,5\\); the free indices are\n\\(1,4\\).\n\n\n\\end{itemize}\n\\end{Example}\n\\subsection{Echelon form and simultaneous equations}\n\n\nIf \\(M\\) is in reduced echelon form then it is very easy to understand\nthe corresponding system of simultaneous equations \\(Mv=b\\). Here are\nsome illustrative examples.\n\n\n\\begin{Example}\nSuppose that \\(M=\\ma 1 & 0 & 1 & 1 \\\\ 0 & 1 & 2 & -1\\mz\\) and\n\\(b=\\ma b_1 \\\\ b_2\\mz\\). The system of simultaneous equations\n\\(Mv=b\\) we get is\n\\begin{align*}\nx_1+x_3+x_4&=b_1\\\\\nx_2+2x_3-x_4&=b_2.\n\\end{align*}\nWe can rearrange:\n\\begin{align*}\nx_1&=b_1-x_3-x_4\\\\\nx_2&=b_2-2x_3+x_4.\n\\end{align*}\nIn other words, for every value of the variables \\(x_3,x_4\\), we get\na solution \\(v=\\ma b_1-x_3-x_4\\\\ b_2-2x_3+x_4\\\\ x_3\\\\ x_4\\mz\\). The\n``free variables'' \\(x_3,x_4\\) are associated with free indices\n\\(3,4\\) and the ``dependent variables'' \\(x_1,x_2\\) are associated\nwith leading indices. Here, {\\em dependent} means that the values of\n\\(x_1,x_2\\) are determined by \\(x_3,x_4\\) via the equations.\n\n\n\\end{Example}\n\\begin{Example}\nSuppose that \\(M=\\ma 1 & 2 & 0 & 1 \\\\ 0 & 0 & 1 & 8 \\\\ 0 & 0 & 0 & 0\n\\\\ 0 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0\\mz\\) and \\(b=\\ma\nb_1\\\\ b_2\\\\ b_3\\\\ b_4\\\\ b_5\\mz\\). The system of simultaneous\nequations \\(Mv=b\\) we get is\n\\begin{align*}\nx_1+2x_2+x_4&=b_1\\\\\nx_3+8x_4&=b_2\\\\\n0&=b_3\\\\\n0&=b_4\\\\\n0&=b_5.\n\\end{align*}\nThis has solutions if and only if \\(b_3=b_4=b_5=0\\). In the case\nwhen this condition holds, there are free variables \\(x_2,x_4\\) (for\nthe free indices) and dependent variables \\(x_1=b_1-2x_2-x_4\\),\n\\(x_3=b_2-8x_4\\). The general solution is then \\(v=\\ma\nb_1-2x_2-x_4\\\\ x_2\\\\b_2-8x_4\\\\x_4\\mz\\) (provided \\(b_3=b_4=b_5=0\\)).\n\n\n\\end{Example}\nMore generally, the same reasoning shows:\n\n\n\\begin{Theorem}\nSuppose that:\n\\begin{itemize}\n\\item \\(M\\) is an \\(m\\)-by-\\(n\\) matrix in reduced echelon form,\n\\item the first \\(k\\leq m\\) rows of \\(M\\) are non-zero and the final\n\\(m-k\\) rows are zero,\n\\item the leading entry in row \\(i\\leq k\\) is in column \\(j_i\\) (so the\nleading indices are \\(j_1,\\ldots,j_k\\)).\n\\end{itemize}\nThen the general solution \\(v=\\ma x_1\\\\ \\vdots\\\\x_n\\mz\\) exists if\nand only if \\(b_{k+1}=\\cdots=b_m=0\\) and has free variables \\(x_p\\)\n(where \\(p\\) runs over the set \\(F\\) of free indices), dependent\nvariables \\(x_{j_i}=b_i-\\sum_{p\\in F} M_{ip}x_p\\).\n\n\n\\end{Theorem}\n\\begin{Remark}\nIn particular, the space of solutions has dimension equal to the\nnumber of free indices.\n\n\n\\end{Remark}\n\\begin{Example}\nConsider the matrix\n\\(A=\\ma 1 & 0 & 2\\\\ 0 & 1 & 1\\mz\\). This is in reduced echelon\nform. If it is used to form a system of equations \\(Av=b\\) then\nthese equations have the form\n\\begin{align*}\nx_1+2x_3&=b_1\\\\\nx_2+x_3&=b_2\n\\end{align*}\nwhich can be solved immediately: \\[x_1=b_1-2x_3,\\qquad\nx_2=b_2-x_3.\\] In other words, for each \\(x_3\\), we get a solution\n\\(v=\\ma b_1-2x_3\\\\ b_2-x_3\\\\ x_3\\mz\\).\n\n\n\\end{Example}\n\\begin{Example}\nConsider the matrix\n\\(A=\\ma 1 & 0 & 0 \\\\ 0 & 1 & 0\\\\ 0 & 0 & 0\\mz\\). This is in reduced\nechelon form. If it is used to form a system of equations \\(Av=b\\)\nthen these equations have the form\n\\begin{align*}\nx_1&=b_1\\\\\nx_2&=b_2\\\\\n0&=b_3\n\\end{align*}\nThis system can be solved if and only if \\(b_3=0\\), in which case it\nhas a solution \\(v=\\ma b_1 \\\\ b_2 \\\\ x_3\\mz\\) for every possible\nvalue of \\(x_3\\).\n\n\n\\end{Example}\n\\begin{Example}\nConsider the \\(n\\)-by-\\(n\\) identity matrix \\(I\\). This is in\nreduced echelon form. If it is used to form a system of equations\n\\(Iv=b\\) then these equations have the unique solution \\(v=\\ma\nb_1\\\\ \\vdots\\\\ b_n\\mz\\). (Duh\\footnote{This is a colloquial form of\nthe Latin QED.}.)\n\n\n\\end{Example}\n\\begin{Example}\nConsider the \\(n\\)-by-\\(n\\) zero matrix. This is in reduced echelon\nform. If it is used to form a system of equations \\(0v=b\\) then\nthese equations have solutions if and only if \\(b=0\\); if \\(b=0\\)\nthen any \\(v\\) is a solution.\n\n\n\\end{Example}\nIn other words, once a matrix is in reduced echelon form, it becomes\nvery transparent how to solve the corresponding system of simultaneous\nequations.\n\n\n\\clearpage\n\\section{Echelon form theorems}\n\\subsection{Putting a matrix into echelon form}\n\n\nWe will soon see that any matrix can be put into echelon form by row\noperations of type I, and further into reduced echelon form by row\noperations of types I and II. Let's see some examples.\n\n\n\\begin{Example}\nConsider the matrix \\[\\begin{pmatrix} 2 & 0 & 2 & 0 \\\\ 0 & 1 & 1 & 1\n\\\\ 2 & 0 & 5 & 0 \\\\ 1 & 1 & 1 & 2 \\end{pmatrix}\\] Clear column\n\\(1\\), row \\(3\\) using \\(R_3\\mapsto R_3-R_1\\)\\[\\begin{pmatrix} 2 & 0\n& 2 & 0 \\\\ 0 & 1 & 1 & 1 \\\\ 0 & 0 & 3 & 0 \\\\ 1 & 1 & 1 & 2\n\\end{pmatrix}\\] Clear column \\(1\\), row \\(4\\) using \\(R_4\\mapsto\nR_4-\\frac{1}{2}R_1\\)\\[\\begin{pmatrix} 2 & 0 & 2 & 0 \\\\ 0 & 1 & 1 & 1\n\\\\ 0 & 0 & 3 & 0 \\\\ 0 & 1 & 0 & 2 \\end{pmatrix}\\] Clear column\n\\(2\\), row \\(4\\) using \\(R_4\\mapsto R_4-R_2\\)\\[\\begin{pmatrix} 2 & 0\n& 2 & 0 \\\\ 0 & 1 & 1 & 1 \\\\ 0 & 0 & 3 & 0 \\\\ 0 & 0 & -1 & 1\n\\end{pmatrix}\\] Clear column \\(3\\), row \\(4\\) using \\(R_4\\mapsto\nR_4+\\frac{1}{3}R_3\\)\\[\\begin{pmatrix} 2 & 0 & 2 & 0 \\\\ 0 & 1 & 1 & 1\n\\\\ 0 & 0 & 3 & 0 \\\\ 0 & 0 & 0 & 1 \\end{pmatrix}\\] This is now in\nechelon form. We can go further to reduced echelon form.\n\n\nMake leading entries in rows 1 and 3 equal to 1 using \\(R_1\\mapsto\n\\frac{1}{2}R_1\\) and \\(R_3\\mapsto\\frac{1}{3}R_3\\). \\[\\begin{pmatrix}\n1 & 0 & 1 & 0 \\\\ 0 & 1 & 1 & 1 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1\n\\end{pmatrix}\\] Clear column 3 using \\(R_1\\mapsto R_1-R_3\\) and\n\\(R_2\\mapsto R_2-R_3\\)\\[\\begin{pmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 &\n1 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{pmatrix}\\] Clear column 4\nusing \\(R_2\\mapsto R_2-R_4\\)\\[\\begin{pmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 1\n& 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{pmatrix}\\]\n\n\n\\end{Example}\nThis means that for any \\(b\\) there is a unique solution to \\(Mv=b\\)\n(no free variables and no constraints on \\(b\\)).\n\n\n\\begin{Example}\nIn this example, we'll keep track of the augmented column. We start\nwith the matrix \\[\\begin{pmatrix}[ccc|c] 1 & -1 & 0 & b_1 \\\\ 1 & 1 &\n-1 & b_2 \\\\ 4 & 0 & -2 & b_3 \\\\ 0 & 2 & -1 & b_4 \\end{pmatrix}\\]\n\n\nClear column \\(1\\), using \\(R_2\\mapsto R_2-R_1\\) and \\(R_3\\mapsto\nR_3-4R_1\\)\\[\\begin{pmatrix}[ccc|c] 1 & -1 & 0 & b_1\\\\ 0 & 2 & -1\n&b_2-b_1 \\\\ 0 & 4 & -2 & b_3-4b_1\\\\ 0 & 2 & -1 &b_4 \\end{pmatrix}\\]\nClear column \\(2\\), using \\(R_3\\mapsto R_3-2R_2\\) and \\(R_4\\mapsto\nR_4-R_2\\) \\[\\begin{pmatrix}[ccc|c] 1 & -1 & 0 & b_1 \\\\ 0 & 2 & -1 &\nb_2-b_1 \\\\ 0 & 0 & 0 & b_3-4b_1-2(b_2-b_1) \\\\ 0 & 0 & 0 &\nb_4-(b_2-b_1) \\end{pmatrix}\\] Make leading entry in row 2 equal to 1\nusing \\(R_2\\mapsto\\frac{1}{2}R_2\\). \\[\\begin{pmatrix}[ccc|c] 1 & -1\n& 0 & b_1 \\\\ 0 & 1 & -1/2 & (b_2-b_1)/2 \\\\ 0 & 0 & 0 & b_3-2b_1-2b_2\n\\\\ 0 & 0 & 0 & b_4+b_1-b_2 \\end{pmatrix}\\] Clear column 2 using\n\\(R_1\\mapsto R_1+R_2\\)\\[\\begin{pmatrix}[ccc|c] 1 & 0 & -1/2 &\n(b_1+b_2)/2 \\\\ 0 & 1 & -1/2 & (b_2-b_1)/2 \\\\ 0 & 0 & 0 &\nb_3-2b_1-2b_2 \\\\ 0 & 0 & 0 & b_4+b_1-b_2\\end{pmatrix}\\]\n\n\nWe see that the general solution exists if \\(b_4+b_1-b_2=0\\) and\n\\(b_3-2b_1-2b_2=0\\), in which case there is one free variable\n\\(x_3\\) and two dependent variables \\[x_1=(b_1+b_2+x_3)/2,\\qquad\nx_2=(b_2-b_1+x_3)/2.\\] For example, if \\(b=\\ma -3 \\\\ 0 \\\\ -6\n\\\\ 3\\mz\\) then \\(b_4+b_1-b_2=3-3-0=0\\) and\n\\(b_3-2b_1-2b_2=-6+6-0=0\\), and we get the general solution \\(\\ma\n(x_3-3)/2 \\\\ (x_3+3)/2 \\\\ x_3\\mz\\).\n\n\n\\end{Example}\n\\begin{Example}\nAgain, we'll keep track of the augmented column. We start with the\nmatrix \\[\\begin{pmatrix}[cccc|c] 3 & -2 & -1 & -5 & b_1 \\\\ -5 & 3 &\n2 & -3 & b_2 \\\\ 0 & -2 & -1 & 1 & b_3\\end{pmatrix}\\] Clear column\n\\(1\\), row \\(2\\) using \\(R_2\\mapsto\nR_2+\\frac{5}{3}R_1\\)\\[\\begin{pmatrix}[cccc|c] 3 & -2 & -1 & -5 &\nb_1\\\\ 0 & -1/3 & 1/3 & -34/3 & \\frac{5}{3}b_1+b_2 \\\\ 0 & -2 & -1 & 1\n& b_3 \\end{pmatrix}\\] Clear column \\(2\\), row \\(3\\) using\n\\(R_3\\mapsto R_3-6R_2\\)\\[\\begin{pmatrix}[cccc|c] 3 & -2 & -1 & -5 &\nb_1 \\\\ 0 & -1/3 & 1/3 & -34/3 & \\frac{5}{3}b_1+b_2 \\\\ 0 & 0 & -3 &\n69 & -10b_1-6b_2+b_3 \\end{pmatrix}\\] Make leading entries in rows 1\nand 2 equal to 1 using \\(R_1\\mapsto \\frac{1}{3}R_1\\) and\n\\(R_2\\mapsto -3R_2\\). \\[\\begin{pmatrix}[cccc|c] 1 & -2/3 & -1/3 &\n-5/3 & \\frac{1}{3}b_1 \\\\ 0 & 1 & -1 & 34 & -5b_1-3b_2 \\\\ 0 & 0 & -3\n& 69 & -10b_1-6b_2+b_3 \\end{pmatrix}\\] Clear column 2 using\n\\(R_1\\mapsto R_1+\\frac{2}{3}R_2\\)\\[\\begin{pmatrix}[cccc|c] 1 & 0 &\n-1 & 21 &-3b_1-2b_2 \\\\ 0 & 1 & -1 & 34 & -5b_1-3b_2 \\\\ 0 & 0 & -3 &\n69 & -10b_1-6b_2+b_3 \\end{pmatrix}\\] Make leading entry in row 3\nequal to 1 using \\(R_3\\mapsto -\\frac{1}{3}R_3\\).\n\\[\\begin{pmatrix}[cccc|c] 1 & 0 & -1 & 21 & -3b_1-2b_2\\\\ 0 & 1 & -1\n& 34 & -5b_1-3b_2 \\\\ 0 & 0 & 1 & -23 &\n\\frac{10}{3}b_1+2b_2-\\frac{1}{3}b_3 \\end{pmatrix}\\] Clear column 3\nusing \\(R_1\\mapsto R_1+R_3\\) and \\(R_2\\mapsto R_2+R_3\\)\n\\[\\begin{pmatrix}[cccc|c] 1 & 0 & 0 & -2 & \\frac{1}{3}(b_1-b_3) \\\\ 0\n& 1 & 0 & 11 & -\\frac{1}{3}(5b_1+3b_2+b_3) \\\\ 0 & 0 & 1 & -23 &\n\\frac{10}{3}b_1+2b_2-\\frac{1}{3}b_3 \\end{pmatrix}\\] We see that this\nalways has a solution, and the general solution is \\[\\ma\n\\frac{1}{3}(b_1-b_3)+2x_4\\\\ -\\frac{1}{3}(5b_1+3b_2+b_3)-11x_4\\\\ \\frac{10}{3}b_1+2b_2-\\frac{1}{3}b_3+23x_4\\\\ x_4\\mz\\]\nwith one free variable \\(x_4\\).\n\n\n\\end{Example}\n\\subsection{Echelon form theorems}\n\n\n\\begin{Theorem}[Echelon form]\\label{thm:echelonform}\nEvery \\(m\\)-by-\\(n\\) matrix \\(A\\) can be put into echelon form using\nonly the row operations \\(R_i\\mapsto R_i+\\lambda R_j\\).\n\\end{Theorem}\n\\begin{Proof}\nWe will prove the theorem by induction on the size of the\nmatrix. Suppose we have proved the theorem for all \\(m'\\)-by-\\(n\\)\nmatrices with \\(m'<m\\). The base case for induction is then \\(m=1\\)\nbut if there is only one row then the matrix is automatically in\nechelon form, which proves the base case. Now for the induction\nstep.\n\n\nIf your matrix is zero then it's already in echelon form, so without\nloss of generality, assume that there is a nonzero row.\n\\begin{itemize}\n\\item Of all the nonzero rows, pick the row \\(R_i\\) whose leading entry\n\\(A_{ij}\\) is furthest to the left (i.e. \\(j\\) is minimal); if\nthere are several such rows, pick the topmost (i.e. with \\(i\\)\nminimal).\n\\item If \\(i\\neq 1\\) (i.e. if \\(R_i\\) is not the top row) then apply the\nrow operation \\(R_1\\mapsto R_1+R_i\\) so that the top row also has\nleading entry \\(A_{ij}\\).\n\\item For \\(k=2,\\ldots,m\\), apply the row operation \\(R_k\\mapsto\nR_k-\\frac{A_{kj}}{A_{ij}}R_1\\). This ensures that the leading\nentries of all nonzero rows below the top are to the right of the\nleading entry of the top row.\n\\end{itemize}\nNow consider the \\((m-1)\\)-by-\\(n\\) submatrix \\(A'\\) you get by\nerasing the top row \\(R_1\\). By induction, we can put this into\nechelon form using only row operations \\(R'_i\\mapsto R'_i+\\lambda\nR'_j\\). Such operations don't introduce any leading entries in\ncolumn \\(j\\) or to the left of it because our submatrix \\(A'\\) has\nzero entries in all these columns. Therefore, if we pop \\(R_1\\) back\non top of \\(A'\\), the result in in echelon form. Since the row\noperations didn't affect \\(R_1\\), we can think of them as row\noperations on \\(A\\), so we have put \\(A\\) into echelon form using\nonly row operations of the specified type. \\qedhere\n\n\n\\end{Proof}\n\\begin{Theorem}[Reduced echelon form]\\label{thm:reducedechelonform}\nEvery \\(m\\)-by-\\(n\\) matrix \\(A\\) can be put into reduced echelon\nform by a sequence of row operations \\(R_i\\mapsto R_i+\\lambda R_j\\)\nand \\(R_k\\mapsto \\lambda R_k\\) (\\(\\lambda\\neq 0\\)).\n\\end{Theorem}\n\\begin{Proof}\nFirst, use \\cref{thm:echelonform} to put \\(A\\) into echelon\nform. Now, for each nonzero row \\(R_i\\), with leading entry\n\\(A_{ij}\\), perform the row operation\n\\(R_i\\mapsto\\frac{1}{A_{ij}}R_i\\) to make the leading entry equal to\n\\(1\\). Finally, for every nonzero row \\(R_i\\) and every row \\(R_k\\)\nwith \\(k\\neq i\\), perform the row operation \\(R_k\\mapsto\nR_k-A_{kj}R_i\\). This clears out the nonzero entries in columns\nabove and below the leading entry \\(A_{ij}\\) of \\(R_i\\). The result\nis in reduced echelon form. \\qedhere\n\n\n\\end{Proof}\n\\clearpage\n\\section{Inverses}\n\\subsection{Definition and basic properties}\n\n\nWe've seen how to multiply and even exponentiate matrices. Can we\n``divide'' by a matrix?\n\n\n\\begin{Theorem}\nIf \\(A=\\ma a & b \\\\ c & d \\mz\\) is a \\(2\\)-by-\\(2\\) matrix with\n\\(ad-bc\\neq 0\\) then the matrix \\[A^{-1}:=\\frac{1}{ad-bc}\\ma d & -b\n\\\\ -c & a\\mz\\] is an {\\em inverse} for \\(A\\) in the sense that\n\\(AA^{-1}=A^{-1}A=I\\).\n\\end{Theorem}\n\\begin{Proof}\nWe'll just check \\(A^{-1}A=I\\).\n\\begin{align*}\nA^{-1}A&=\\frac{1}{ad-bc}\\ma d & -b \\\\ -c & a\\mz\\ma a & b \\\\ c & d\\mz\\\\\n&=\\frac{1}{ad-bc}\\ma da-bc & db-bd \\\\ -ca+ac & -cb+ad\\mz\\\\\n&=\\frac{1}{ad-bc}\\ma ad-bc & 0 \\\\ 0 & ad-bc\\mz\\\\\n&=I. \\qedhere\n\\end{align*}\n\n\n\\end{Proof}\n\\begin{Remark}\nThis is great. However, you should never write \\(A^{-1}\\) as\n\\(\\frac{1}{A}\\). The reason is that \\(\\frac{B}{A}\\) could mean\n\\(A^{-1}B\\) or \\(BA^{-1}\\) and these are in general different\nmatrices (because matrix multiplication is not commutative).\n\n\n\\end{Remark}\nWe want to generalise this idea to \\(n\\)-by-\\(n\\) matrices.\n\n\n\\begin{Definition}\nLet \\(A\\) be an \\(n\\)-by-\\(n\\) (square!) matrix. We say that \\(A\\)\nis {\\em invertible} if there exists a matrix \\(A^{-1}\\) such that\n\\(A^{-1}A=AA^{-1}=I\\).\n\n\n\\end{Definition}\n\\begin{Remark}\nNote that if an inverse exists, it is unique because if \\(B,C\\) are\ntwo inverses for \\(A\\) then \\(AB=AC=I\\) and so\n\\(B=BI=BAB=BAC=IC=C\\).\n\n\n\\end{Remark}\n\\begin{Lemma}\\label{lma:prodinv}\nIf \\(A\\) and \\(B\\) are invertible with inverses \\(A^{-1}\\) and\n\\(B^{-1}\\) then \\(AB\\) is invertible with inverse \\(B^{-1}A^{-1}\\)\n(note the order is reversed!)\n\\end{Lemma}\n\\begin{Proof}\nWe have\n\\[(AB)(B^{-1}A^{-1})=A(BB^{-1})A^{-1}=AIA^{-1}=AA^{-1}=I.\\]\nSimilarly, one can show \\((B^{-1}A^{-1})(AB)=I\\). \\qedhere\n\n\n\\end{Proof}\nIn this section, we will see an algorithm to test if a matrix is\ninvertible and, if it is, compute its inverse. We will later introduce\na quantity called the {\\em determinant} of a square matrix which is\nthe analogue of \\(ad-bc\\) for \\(2\\)-by-\\(2\\) matrices in the sense\nthat a matrix is invertible if and only if its determinant is nonzero\n(and there's a formula for the inverse in terms of determinants).\n\n\n\\subsection{Inverse matrices and reduced echelon form}\n\n\nObserve that finding \\(A^{-1}\\) is equivalent to solving the\nsimultaneous equations associated to \\(Av=b\\). Indeed, if \\(A\\) is\ninvertible then \\(v=A^{-1}b\\) is a solution to \\(Av=b\\). Since we know\nhow to solve simultaneous equations, we also know how to find\ninverses! In fact, we were secretly doing this already in the chapter\non simultaneous equations.\n\n\nThe following theorem makes this precise.\n\n\n\\begin{Theorem}\\label{thm:invech}\nGiven an \\(n\\)-by-\\(n\\) matrix \\(A\\), form the {\\em augmented\nmatrix} \\((A|I_n)\\) (where \\(I_n\\) is the \\(n\\)-by-\\(n\\) identity\nmatrix). Use row operations on the augmented matrix to put \\(A\\)\ninto reduced echelon form. Then \\(A\\) is invertible if and only if\nthe reduced echelon form of \\(A\\) is \\(I_n\\), and in this case, the\nresult of putting \\((A|I_n)\\) into reduced echelon form is\n\\((I_n|A^{-1})\\).\n\n\n\\end{Theorem}\nWe will first use the theorem to compute some examples of inverse\nmatrices, then we will develop a little more theory and prove the\ntheorem.\n\n\n\\subsection{Examples}\n\n\n\\begin{Example}\nLet's invert the matrix \\(\\ma -3 & -2 & -4 \\\\ 2 & 3 & 3 \\\\ -1 & 4 &\n-4\\mz\\). We start by writing the augmented matrix \\[\\begin{pmatrix}[\nc c c | c c c ] -3 & -2 & -4 & 1 & 0 & 0 \\\\ 2 & 3 & 3 & 0 & 1 & 0\n\\\\ -1 & 4 & -4 & 0 & 0 & 1 \\end{pmatrix}\\] Clear column \\(1\\), row\n\\(2\\) using \\(R_2\\mapsto R_2+(2/3)R_1\\)\\[\\begin{pmatrix}[ c c c | c\nc c ] -3 & -2 & -4 & 1 & 0 & 0 \\\\ 0 & 5/3 & 1/3 & 2/3 & 1 & 0 \\\\ -1\n& 4 & -4 & 0 & 0 & 1 \\end{pmatrix}\\] Clear column \\(1\\), row \\(3\\)\nusing \\(R_3\\mapsto R_3+(-1/3)R_1\\) \\[\\begin{pmatrix}[ c c c | c c c\n] -3 & -2 & -4 & 1 & 0 & 0 \\\\ 0 & 5/3 & 1/3 & 2/3 & 1 & 0 \\\\ 0 &\n14/3 & -8/3 & -1/3 & 0 & 1 \\end{pmatrix}\\] Clear column \\(2\\), row\n\\(3\\) using \\(R_3\\mapsto R_3+(-14/5)R_2\\) \\[\\begin{pmatrix}[ c c c |\nc c c ] -3 & -2 & -4 & 1 & 0 & 0 \\\\ 0 & 5/3 & 1/3 & 2/3 & 1 & 0 \\\\ 0\n& 0 & -18/5 & -11/5 & -14/5 & 1 \\end{pmatrix}\\] Make leading entry\nin row 1 equal to 1 using \\(R_1\\mapsto\n(-1/3)R_1\\). \\[\\begin{pmatrix}[ c c c | c c c ] 1 & 2/3 & 4/3 & -1/3\n& 0 & 0 \\\\ 0 & 5/3 & 1/3 & 2/3 & 1 & 0 \\\\ 0 & 0 & -18/5 & -11/5 &\n-14/5 & 1 \\end{pmatrix}\\] Make leading entry in row 2 equal to 1\nusing \\(R_2\\mapsto (3/5)R_2\\). \\[\\begin{pmatrix}[ c c c | c c c ] 1\n& 2/3 & 4/3 & -1/3 & 0 & 0 \\\\ 0 & 1 & 1/5 & 2/5 & 3/5 & 0 \\\\ 0 & 0 &\n-18/5 & -11/5 & -14/5 & 1 \\end{pmatrix}\\] Clear column 2 using\n\\(R_1\\mapsto R_1+(-2/3)R_2\\)\\[\\begin{pmatrix}[ c c c | c c c ] 1 & 0\n& 6/5 & -3/5 & -2/5 & 0 \\\\ 0 & 1 & 1/5 & 2/5 & 3/5 & 0 \\\\ 0 & 0 &\n-18/5 & -11/5 & -14/5 & 1 \\end{pmatrix}\\]Make leading entry in row 3\nequal to 1 using \\(R_3\\mapsto (-5/18)R_3\\). \\[\\begin{pmatrix}[ c c\nc | c c c ] 1 & 0 & 6/5 & -3/5 & -2/5 & 0 \\\\ 0 & 1 & 1/5 & 2/5 & 3/5\n& 0 \\\\ 0 & 0 & 1 & 11/18 & 7/9 & -5/18 \\end{pmatrix}\\]Clear column 3\nusing \\(R_1\\mapsto R_1+(-6/5)R_3\\)\\[\\begin{pmatrix}[ c c c | c c c ]\n1 & 0 & 0 & -4/3 & -4/3 & 1/3 \\\\ 0 & 1 & 1/5 & 2/5 & 3/5 & 0 \\\\ 0 &\n0 & 1 & 11/18 & 7/9 & -5/18 \\end{pmatrix}\\] Clear column 3 using\n\\(R_2\\mapsto R_2+(-1/5)R_3\\)\\[\\begin{pmatrix}[ c c c | c c c ] 1 & 0\n& 0 & -4/3 & -4/3 & 1/3 \\\\ 0 & 1 & 0 & 5/18 & 4/9 & 1/18 \\\\ 0 & 0 &\n1 & 11/18 & 7/9 & -5/18 \\end{pmatrix}\\] Now the right-hand block is\nthe inverse of the matrix we started with.\n\n\n\\end{Example}\n\\begin{Example}\nWe start with the matrix \\[\\begin{pmatrix}[ c c c c | c c c c ] 1 &\n-1 & 0 & 3 & 1 & 0 & 0 & 0 \\\\ -1 & 2 & 1 & 0 & 0 & 1 & 0 & 0 \\\\ -1 &\n1 & 1 & -3 & 0 & 0 & 1 & 0 \\\\ 1 & 0 & 1 & 7 & 0 & 0 & 0 & 1\n\\end{pmatrix}\\] Clear column \\(1\\), row \\(2\\) using \\(R_2\\mapsto\nR_2+(1)R_1\\)\\[\\begin{pmatrix}[ c c c c | c c c c ] 1 & -1 & 0 & 3 &\n1 & 0 & 0 & 0 \\\\ 0 & 1 & 1 & 3 & 1 & 1 & 0 & 0 \\\\ -1 & 1 & 1 & -3 &\n0 & 0 & 1 & 0 \\\\ 1 & 0 & 1 & 7 & 0 & 0 & 0 & 1 \\end{pmatrix}\\]Clear\ncolumn \\(1\\), row \\(3\\) using \\(R_3\\mapsto\nR_3+(1)R_1\\)\\[\\begin{pmatrix}[ c c c c | c c c c ] 1 & -1 & 0 & 3 &\n1 & 0 & 0 & 0 \\\\ 0 & 1 & 1 & 3 & 1 & 1 & 0 & 0 \\\\ 0 & 0 & 1 & 0 & 1\n& 0 & 1 & 0 \\\\ 1 & 0 & 1 & 7 & 0 & 0 & 0 & 1 \\end{pmatrix}\\]Clear\ncolumn \\(1\\), row \\(4\\) using \\(R_4\\mapsto\nR_4+(-1)R_1\\)\\[\\begin{pmatrix}[ c c c c | c c c c ] 1 & -1 & 0 & 3 &\n1 & 0 & 0 & 0 \\\\ 0 & 1 & 1 & 3 & 1 & 1 & 0 & 0 \\\\ 0 & 0 & 1 & 0 & 1\n& 0 & 1 & 0 \\\\ 0 & 1 & 1 & 4 & -1 & 0 & 0 & 1 \\end{pmatrix}\\]Clear\ncolumn \\(2\\), row \\(4\\) using \\(R_4\\mapsto\nR_4+(-1)R_2\\)\\[\\begin{pmatrix}[ c c c c | c c c c ] 1 & -1 & 0 & 3 &\n1 & 0 & 0 & 0 \\\\ 0 & 1 & 1 & 3 & 1 & 1 & 0 & 0 \\\\ 0 & 0 & 1 & 0 & 1\n& 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 & -2 & -1 & 0 & 1 \\end{pmatrix}\\]Clear\ncolumn 2 using \\(R_1\\mapsto R_1+(1)R_2\\)\\[\\begin{pmatrix}[ c c c c |\nc c c c ] 1 & 0 & 1 & 6 & 2 & 1 & 0 & 0 \\\\ 0 & 1 & 1 & 3 & 1 & 1 & 0\n& 0 \\\\ 0 & 0 & 1 & 0 & 1 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 & -2 & -1 & 0\n& 1 \\end{pmatrix}\\]Clear column 3 using \\(R_1\\mapsto\nR_1+(-1)R_3\\)\\[\\begin{pmatrix}[ c c c c | c c c c ] 1 & 0 & 0 & 6 &\n1 & 1 & -1 & 0 \\\\ 0 & 1 & 1 & 3 & 1 & 1 & 0 & 0 \\\\ 0 & 0 & 1 & 0 & 1\n& 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 & -2 & -1 & 0 & 1 \\end{pmatrix}\\]Clear\ncolumn 3 using \\(R_2\\mapsto R_2+(-1)R_3\\)\\[\\begin{pmatrix}[ c c c\nc | c c c c ] 1 & 0 & 0 & 6 & 1 & 1 & -1 & 0 \\\\ 0 & 1 & 0 & 3 & 0 &\n1 & -1 & 0 \\\\ 0 & 0 & 1 & 0 & 1 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 & -2 &\n-1 & 0 & 1 \\end{pmatrix}\\]Clear column 4 using \\(R_1\\mapsto\nR_1+(-6)R_4\\)\\[\\begin{pmatrix}[ c c c c | c c c c ] 1 & 0 & 0 & 0 &\n13 & 7 & -1 & -6 \\\\ 0 & 1 & 0 & 3 & 0 & 1 & -1 & 0 \\\\ 0 & 0 & 1 & 0\n& 1 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 & -2 & -1 & 0 & 1\n\\end{pmatrix}\\]Clear column 4 using \\(R_2\\mapsto\nR_2+(-3)R_4\\)\\[\\begin{pmatrix}[ c c c c | c c c c ] 1 & 0 & 0 & 0 &\n13 & 7 & -1 & -6 \\\\ 0 & 1 & 0 & 0 & 6 & 4 & -1 & -3 \\\\ 0 & 0 & 1 & 0\n& 1 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 & -2 & -1 & 0 & 1\n\\end{pmatrix}\\]Now the right-hand block is the inverse of the matrix\nwe started with.\n\n\n\\end{Example}\n\\clearpage\n\\section{Inverses from echelon form}\n\\subsection{Elementary matrices}\n\n\n\\begin{Definition}[Elementary matrices I]\\label{dfn:elematrix}\nIf \\(i\\neq j\\), we write \\(E_{ij}(\\lambda)\\) for the matrix with\nones on the diagonal and zeros elsewhere, except for a \\(\\lambda\\)\nin position \\(ij\\) (\\(i\\)th row, \\(j\\)th column). For example, if\nwe're working with \\(3\\)-by-\\(3\\) matrices then \\[E_{12}(2)=\\ma 1 &\n2 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1\\mz,\\quad E_{32}(7)=\\ma 1 & 0 & 0\n\\\\ 0 & 1 & 0 \\\\ 0 & 7 & 1\\mz,\\quad E_{13}(t)=\\ma 1 & 0 & t\\\\ 0 & 1 &\n0 \\\\ 0 & 0 & 1\\mz.\\]\n\n\n\\end{Definition}\n\\begin{Lemma}\nIf \\(A\\) and \\(E_{ij}(\\lambda)\\) are \\(n\\)-by-\\(n\\) matrices then\n\\(E_{ij}(\\lambda)A\\) is the matrix obtained from \\(A\\) by the row\noperation \\(R_i\\mapsto R_i+\\lambda R_j\\).\n\\end{Lemma}\n\\begin{Proof}\nLet's consider the case \\(i<j\\) (the other case is similar so we\nomit it). Consider the product\n\\[\\ma\n1 & & \\mbox{col }i & & \\mbox{col }j & & \\\\\n& \\ddots & \\downarrow & & \\downarrow & & \\\\\n\\mbox{row }i&\\rightarrow & 1 & & \\lambda & &\\\\\n& & & \\ddots & & & \\\\\n& & & & 1 & & \\\\\n& & & & & \\ddots &\\\\\n& & & & & & 1\n\\mz\n\\ma\nA_{11} & \\cdots & \\cdots & & \\cdots & \\cdots & A_{1n} \\\\\n\\vdots & & & & & & \\vdots \\\\\nA_{i1} & & & & & & A_{in} \\\\\n\\vdots & & & & & & \\vdots \\\\\nA_{j1} & & & & & & A_{jn} \\\\\n\\vdots & & & & & & \\vdots \\\\\nA_{n1} & \\cdots & \\cdots & & \\cdots & \\cdots & A_{nn}\n\\mz\\]\nThe only difference the \\(\\lambda\\) makes is when we multiply the\n\\(i\\)th row into a column of \\(A\\) (say the \\(k\\)th column). Instead\nof just picking up \\(1\\times A_{ik}\\), we get \\(1\\times\nA_{ik}+\\lambda\\times A_{jk}\\). In other words, the result\n\\(E_{ij}(\\lambda)A\\) is obtained from \\(A\\) by adding \\(\\lambda\\)\ntimes row \\(j\\) to row \\(i\\).\\qedhere\n\n\n\\end{Proof}\n\\begin{Definition}[Elementary matrices II]\\label{dfn:elematrix2}\nWe define the elementary matrix \\(E_i(\\lambda)\\) to be the matrix\nwith \\(1\\)s on the diagonal and zeros elsewhere, except that the\n\\(ii\\) entry is \\(\\lambda\\). For example, if we're working with\n\\(4\\)-by-\\(4\\) matrices then \\[E_1(5)=\\ma 5 & 0 & 0 & 0 \\\\ 0 & 1 & 0\n& 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1\\mz, E_3(F)=\\ma 1 & 0 & 0 & 0\n\\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & F & 0 \\\\ 0 & 0 & 0 & 1\\mz.\\]\n\n\n\\end{Definition}\n\\begin{Lemma}\nIf \\(A\\) and \\(E_i(\\lambda)\\) are \\(n\\)-by-\\(n\\) matrices then\n\\(E_i(\\lambda)A\\) is the matrix obtained from \\(A\\) by the row\noperation \\(R_i\\mapsto\\lambda R_i\\).\n\\end{Lemma}\n\\begin{Proof}\nThe only difference between multiplying by the identity and\nmultiplying by \\(E_i(\\lambda)\\) is that when you multiply the\n\\(i\\)th row of \\(E_i(\\lambda)\\) into the \\(j\\)th column of \\(A\\),\nyou pick up a factor of \\(\\lambda\\). Therefore \\(E_i(\\lambda)A\\)\ndiffers from \\(A\\) only in that every element on the \\(i\\)th row is\nmultiplied by \\(\\lambda\\). For example, if \\(A=\\ma a & b \\\\ c &\nd\\mz\\) then \\[E_1(\\lambda)A=\\ma \\lambda & 0 \\\\ 0 & 1 \\mz\\ma a & b\n\\\\ c & d\\mz=\\ma \\lambda a & \\lambda b \\\\ c & d\\mz.\\qedhere\\]\n\n\n\\end{Proof}\n\\begin{Lemma}\nAn elementary matrix \\(E_{ij}(\\lambda)\\) is invertible with inverse\n\\(E_{ij}(-\\lambda)\\). An elementary matrix \\(E_i(\\lambda)\\) is\ninvertible if \\(\\lambda\\neq 0\\), in which case its inverse is\n\\(E_i(1/\\lambda)\\).\n\\end{Lemma}\n\\begin{Proof}\nConsider the product\n\\[\\ma\n1 & & & & & & \\\\\n& \\ddots & & & & & \\\\\n& & 1 & & \\lambda & &\\\\\n& & & \\ddots & & & \\\\\n& & & & 1 & & \\\\\n& & & & & \\ddots &\\\\\n& & & & & & 1\n\\mz\n\\ma\n1 & & & & & & \\\\\n& \\ddots & & & & & \\\\\n& & 1 & & -\\lambda & &\\\\\n& & & \\ddots & & & \\\\\n& & & & 1 & & \\\\\n& & & & & \\ddots &\\\\\n& & & & & & 1\n\\mz\n\\]\nThe only difference between this and \\(II=I\\) is when you multiply\nrow \\(i\\) into column \\(j\\), when you get\n\\(1\\times(-\\lambda)+\\lambda\\times 1=0\\). Therefore this product\nequals \\(I\\).\n\n\nConsider the product\n\\[\\ma\n1 & & & & \\\\\n& \\ddots & & &\\\\\n& & \\lambda & &\\\\\n& & & \\ddots & \\\\\n& & & & 1\n\\mz\\ma\n1 & & & & \\\\\n& \\ddots & & &\\\\\n& & 1/\\lambda & &\\\\\n& & & \\ddots & \\\\\n& & & & 1\n\\mz\\]\nThe only difference between this product and \\(II=I\\) is when you\nmultiply row \\(i\\) into column \\(i\\), at which point you get\n\\(\\lambda\\times(1/\\lambda)=1\\), so this product equals \\(I\\).\n\\qedhere\n\n\n\\end{Proof}\n\\subsection{Proof of \\cref{thm:invech}}\n\n\n\\begin{Proof}[Proof of \\cref{thm:invech}]\\label{prf:invech}\nSuppose we have put \\(A\\) into reduced echelon form using a sequence\nof row operations \\(r_1,\\ldots,r_k\\). Each row operation is\nequivalent to multiplying (on the left) by some elementary matrix\n\\(M_1,\\ldots,M_k\\). Therefore the reduced echelon form of \\(A\\) is\n\\[C:=M_kM_{k-1}\\cdots M_1A.\\]\n\n\nIf \\(C\\) is the identity then \\(M_k\\cdots M_1A=I\\), so \\(M_k\\cdots\nM_1=A^{-1}\\). If we perform the same row operations to the identity\nmatrix (sitting on the right hand side of the augmented matrix\n\\((A|I_n)\\)) then we get \\(M_k\\cdots M_1I=A^{-1}\\).\n\n\nIf \\(C\\) is not the identity matrix, then, since \\(C\\) is a square\nmatrix in reduced echelon form, there must be a row of \\(C\\) which\nvanishes. Say this is the \\(i\\)th row. If \\(v\\) is the vector with\nzeros everywhere except a \\(1\\) in the \\(i\\)th row then\n\\(Cv=0\\). Now \\(Cv=M_k\\cdots M_1Av=0\\), and \\(M_1,\\ldots,M_k\\) are\ninvertible, so \\(Av=M_1^{-1}\\cdots M_k^{-1}0=0\\). Therefore \\(A\\)\nhas nontrivial kernel. If \\(A\\) were invertible then the only\nsolution to \\(Av=0\\) is \\(v=A^{-1}0=0\\), so the kernel would be\ntrivial. Therefore \\(A\\) is only invertible if its reduced echelon\nform is the identity matrix. \\qedhere\n\n\n\\end{Proof}\n\\begin{Corollary}\\label{cor:invprodelem}\nA product of elementary matrices is invertible and, conversely, any\ninvertible matrix is a product of elementary matrices.\n\\end{Corollary}\n\\begin{Proof}\nEach elementary matrix is invertible, so in for a product\n\\(M_k\\cdots M_1\\) of elementary matrices, the inverse is\n\\(M_1^{-1}\\cdots M_k^{-1}\\). Conversely, if \\(A\\) is invertible then\nits reduced echelon form is the identity and its inverse is a\nproduct of elementary matrices \\(M_k\\cdots M_1\\) by\n\\cref{thm:invech}. The inverse of an elementary matrix is again\nelementary, therefore \\(A=M_1^{-1}\\cdots M_k^{-1}\\) is a product of\nelementary matrices. \\qedhere\n\n\n\\end{Proof}\n\\clearpage\n\\section{Determinants}\n\\subsection{Definition and basic examples}\n\n\nWe have seen that a 2-by-2 matrix \\(A=\\ma a & b \\\\ c & d \\mz\\) is\ninvertible if and only if \\(ad-bc\\neq 0\\). We would like a similarly\nnice characterisation of invertibility for \\(n\\)-by-\\(n\\) matrices.\nWe will see that {\\bf a matrix is invertible if and only if its {\\em\ndeterminant} is nonzero}.\n\n\n\\begin{Definition}[Determinant]\\label{dfn:det}\nIf \\(A\\) is an \\(n\\)-by-\\(n\\) matrix with entries \\(A_{ij}\\) then we\ndefine the {\\em determinant} \\(\\det(A)\\) to be the number obtained\nas follows.\n\\begin{itemize}\n\\item Pick \\(n\\) entries of \\(A\\) with no two in the same row and no two\nin the same column. If we write the entry from the \\(i\\)th row as\n\\(A_{i\\sigma(i)}\\) (i.e. it's in the \\(\\sigma(i)\\)th column) then\nthis means that the map \\(i\\mapsto\\sigma(i)\\) is a permutation of\n\\(\\{1,\\ldots,n\\}\\); there are \\(n!\\) ways of making such a choice.\n\\item Multiply these entries together to get the number \\(\\pm\nA_{1\\sigma(1)}\\cdots A_{n\\sigma(n)}\\). The sign in this expression\nis taken to be \\(-1\\) if your permutation is ``odd'' (i.e. if it\ninvolves an odd number of swaps) and \\(+1\\) if your permutation is\n``even'' (involves an even number of swaps). We will write\n\\(sgn(\\sigma)\\) for this sign.\n\\item Repeat this for every possible choice \\(\\sigma\\) and sum the\nnumbers that you get.\n\\end{itemize}\nIn brief: \\[\\det(A)=\\sum_{\\sigma}sgn(\\sigma)A_{1\\sigma(1)}\\cdots\nA_{n\\sigma(n)},\\] where the sum is taken over all permutations\n\\(\\sigma\\).\n\n\n\\end{Definition}\n\\begin{Example}\\label{exm:det2}\nIf \\(n=2\\) then there are \\(n!=2\\) choices:\n\\begin{itemize}\n\\item \\(\\sigma\\) could be the identity permutation \\(1\\mapsto 1\\),\n\\(2\\mapsto 2\\). This is an even permutation (it involves zero\nswaps and zero is even) so we get\n\\(A_{1\\sigma(1)}A_{2\\sigma(2)}=A_{11}A_{22}\\).\n\\item \\(\\sigma\\) could be the swap \\(1\\leftrightarrow 2\\). This is an\nodd permutation (it involves one swap and one is odd) so we get\n\\(-A_{1\\sigma(1)}A_{2\\sigma(2)}=-A_{12}A_{21}\\).\n\\end{itemize}\nIf \\(A=\\ma a & b \\\\ c & d\\mz\\) then this translates into the two\nterms \\(ad\\) and \\(-bc\\), which we sum to get \\(\\det(A)=ad-bc\\).\n\n\n\\end{Example}\n\\begin{Example}\\label{exm:det3}\nIf \\(n=3\\) and \\(A=\\ma a & b & c \\\\ d & e & f \\\\ g & h & i \\mz\\)\nthen we get \\(n!=6\\) choices:\n\n\n\\begin{tabular}{c|ccccccc}\n\\hline\n\\(\\sigma\\) & identity & \\(1\\leftrightarrow 2\\) & \\(1\\leftrightarrow 3\\) & \\(2\\leftrightarrow 3\\) & cyclic \\((123)\\) & cyclic \\((132)\\) \\\\\n\\hline\ncontribution & \\(aef\\) & \\(-bdi\\) & \\(-ceg\\) & \\(-afh\\) & \\(bfg\\) & \\(cdh\\)\\\\\n\\hline\n\\end{tabular}\n\n\nso\n\\[\\det(A)=aei+bfg+cdh-bdi-ceg-afh.\\]\n\n\n\\end{Example}\n\\begin{Example}[Diagonal matrices]\\label{exm:diagonal}\nIf \\(D\\) is a diagonal matrix with entries\n\\(\\lambda_1,\\ldots,\\lambda_n\\):\n\\[\\ma \\lambda_1 & 0 & \\cdots & 0\\\\ 0 & \\lambda_2 & & \\vdots\n\\\\ \\vdots & & \\ddots & 0 \\\\ 0 & \\cdots & 0 &\\lambda_n\\mz\\]\nthen there is only one way to pick a\nnonzero entry from each row, which gives\n\\(\\det(D)=\\lambda_1\\cdots\\lambda_n\\).\n\n\n\\end{Example}\n\\begin{Example}[Upper triangular matrices]\\label{exm:uppertriangular}\nSuppose that \\(T\\) is an {\\em upper triangular matrix}, in other\nwords all the entries below the diagonal are zero: \\[\\ma A_{11} &\nA_{12} & \\cdots & A_{1n}\\\\ 0 & A_{22} & & A_{2n} \\\\ \\vdots & &\n\\ddots & \\vdots \\\\ 0 & \\cdots & 0 & A_{nn}\\mz\\] Then we need to pick\nsomething from the first column, which has to be \\(A_{11}\\), then\nsomething from the second column but this may not be on the first\nrow as we already picked something from the first row, so this must\nbe \\(A_{22}\\), then something from the third column, but this cannot\nbe on the first or second rows, so it must be \\(A_{33}\\), and so on,\nso we see that \\(\\det(A)=A_{11}\\cdots A_{nn}\\) (i.e. \\(\\det(A)\\) is\nthe product of the diagonal entries). Similarly if \\(A\\) is\nlower-triangular.\n\n\n\\end{Example}\n\\begin{Example}\\label{exm:detelemI}\nIf \\(E_{ij}(\\lambda)\\) is an elementary matrix with ones on the\ndiagonal and zeros elsewhere except for a \\(\\lambda\\) in position\n\\(ij\\) then \\(\\det(E_{ij}(\\lambda))=1\\). This is because\n\\(E_{ij}(\\lambda)\\) is upper (respectively lower) triangular (when\n\\(i<j\\) or \\(i>j\\) respectively).\n\n\n\\end{Example}\n\\begin{Example}\\label{exm:detelemII}\nIf \\(E_i(\\lambda)\\) is the elementary matrix with ones on the\ndiagonal and zeros elsewhere except for a \\(\\lambda\\) in position\n\\(ii\\), then \\(E_i(\\lambda)\\) is diagonal and its determinant is\n\\(\\lambda\\).\n\n\n\\end{Example}\n\\subsection{Some properties of the determinant}\n\n\n\\begin{Lemma}\\label{lma:detantisym}\nIf two rows of \\(A\\) coincide (that is, for some \\(i\\neq j\\), we\nhave \\(A_{ik}=A_{jk}\\) for all \\(k\\)) then \\(\\det(A)=0\\).\n\\end{Lemma}\n\\begin{Proof}\nIf two rows coincide then each term\n\\[sgn(\\sigma)(\\cdots)A_{i\\sigma(i)}(\\cdots)A_{j\\sigma(j)}(\\cdots)\\]\ncancels with the term\n\\[sgn(\\sigma')(\\cdots)A_{i\\sigma'(i)}(\\cdots)A_{j\\sigma'(j)}(\\cdots)\\]\nwhere \\(\\sigma'\\) is the permutation obtained by performing\n\\(\\sigma\\) and then switching \\(i\\leftrightarrow j\\). The point is\nthat this doesn't change the value of the product (because\n\\(A_{i\\sigma(i)}=A_{j\\sigma(i)}\\) and\n\\(A_{i\\sigma(j)}=A_{j\\sigma(j)}\\)) but it does change the sign of\nthe permutation (it introduces an extra swap). \\qedhere\n\n\n\\end{Proof}\n\\begin{Lemma}\\label{lma:detrowI}\nIf \\(A'\\) is obtained from \\(A\\) by a row operation \\(R_i\\mapsto\nR_i+\\lambda R_j\\) then \\(\\det(A')=\\det(A)\\).\n\\end{Lemma}\n\\begin{Proof}\nWe have\n\\begin{align*}\n\\det(A')&=\\sum_{\\sigma}sgn(\\sigma)(\\cdots)(A_{i\\sigma(i)}+\\lambda A_{j\\sigma(i)})(\\cdots)\\\\\n&=\\sum_{\\sigma}sgn(\\sigma)(\\cdots)A_{i\\sigma(i)}(\\cdots)+\\lambda\\sum_{\\sigma}sgn(\\sigma)(\\cdots)A_{j\\sigma(i)}(\\cdots)\\\\\n&=\\det(A)+\\lambda\\det(B),\n\\end{align*}\nwhere \\(B\\) is the matrix obtained from \\(A\\) by replacing the\n\\(i\\)th row with the \\(j\\)th row. Since \\(B\\) has two rows equal,\nits determinant vanishes, so \\(\\det(A')=\\det(A)\\). \\qedhere\n\n\n\\end{Proof}\n\\begin{Theorem}\\label{thm:detech}\nSuppose we put \\(A\\) into echelon form using only row operations\n\\(R_i\\mapsto R_i+\\lambda R_j\\). Then \\(\\det(A)\\) is the product of\nthe diagonal entries in the echelon form.\n\\end{Theorem}\n\\begin{Proof}\nThese row operations do not change the determinant, so if \\(C\\) is\nthe echelon form of \\(A\\) thus obtained, we have\n\\(\\det(A)=\\det(C)\\). By definition, matrices in echelon form are\nupper triangular, so \\(\\det(C)\\) is just the product of its diagonal\nentries, by \\cref{exm:uppertriangular}. \\qedhere\n\n\n\\end{Proof}\n\\begin{Lemma}\nIf \\(A'\\) is obtained by swapping two of the rows of \\(A\\) then\n\\(\\det(A')=-\\det(A)\\).\n\\end{Lemma}\n\\begin{Proof}\nEach term (for a permutation \\(\\sigma\\)) in \\(\\det(A')\\) also\nappears in \\(\\det(A)\\) for a permutation \\(\\sigma\\) followed by the\nswap, and hence with the opposite sign. \\qedhere\n\n\n\\end{Proof}\n\\begin{Remark}\nThis means you can also swap rows around to reach echelon form and\ncompute the determinant, {\\em provided you multiply by \\(-1\\) each\ntime you swap two rows}. This can be useful, for example: \\[\\det\\ma\n0 & 0 & 0 & 1 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 1 & 0 & 0 &\n0\\mz=-1\\] immediately without the mess of adding row 4 to row 1 and\nsubtracting row 1 from row 4.\n\n\n\\end{Remark}\n\\clearpage\n\\section{Computing determinants}\n\\subsection{Examples of computing determinants}\n\n\n\n\n\\begin{Example}\nLet \\(A=\\begin{pmatrix} 1 & 4 & -4 \\\\ -2 & -2 & -4 \\\\ 3 & -3 & 3\n\\end{pmatrix}\\).\n\n\nClear row \\(2\\) using \\(R_2\\mapsto R_2+(2)R_1\\)\\[\\begin{pmatrix} 1 &\n4 & -4 \\\\ 0 & 6 & -12 \\\\ 3 & -3 & 3 \\end{pmatrix}\\] Clear row \\(3\\)\nusing \\(R_3\\mapsto R_3+(-3)R_1\\)\\[\\begin{pmatrix} 1 & 4 & -4 \\\\ 0 &\n6 & -12 \\\\ 0 & -15 & 15 \\end{pmatrix}\\] Clear row \\(3\\) using\n\\(R_3\\mapsto R_3+(5/2)R_2\\)\\[\\begin{pmatrix} 1 & 4 & -4 \\\\ 0 & 6 &\n-12 \\\\ 0 & 0 & -15 \\end{pmatrix}\\] This is now in echelon form and\nhas the same determinant as the matrix we began with, so the\ndeterminant is the product of the diagonal entries, which is\n\\(-90\\).\n\n\n\\end{Example}\n\\begin{Example}\nLet \\(B=\\begin{pmatrix} 2 & -3 & -1 & 4 \\\\ 2 & -3 & 2 & 4 \\\\ 2 & -1\n& -4 & -3 \\\\ 2 & -3 & 4 & 2 \\end{pmatrix}\\).\n\n\nClear row \\(2\\) using \\(R_2\\mapsto R_2+(-1)R_1\\)\\[\\begin{pmatrix} 2\n& -3 & -1 & 4 \\\\ 0 & 0 & 3 & 0 \\\\ 2 & -1 & -4 & -3 \\\\ 2 & -3 & 4 & 2\n\\end{pmatrix}\\] Clear row \\(3\\) using \\(R_3\\mapsto\nR_3+(-1)R_1\\)\\[\\begin{pmatrix} 2 & -3 & -1 & 4 \\\\ 0 & 0 & 3 & 0 \\\\ 0\n& 2 & -3 & -7 \\\\ 2 & -3 & 4 & 2 \\end{pmatrix}\\] Clear row \\(4\\) using\n\\(R_4\\mapsto R_4+(-1)R_1\\)\\[\\begin{pmatrix} 2 & -3 & -1 & 4 \\\\ 0 & 0\n& 3 & 0 \\\\ 0 & 2 & -3 & -7 \\\\ 0 & 0 & 5 & -2 \\end{pmatrix}\\]Add row\n\\(3\\) to row \\(2\\)\\[\\begin{pmatrix} 2 & -3 & -1 & 4 \\\\ 0 & 2 & 0 &\n-7 \\\\ 0 & 2 & -3 & -7 \\\\ 0 & 0 & 5 & -2 \\end{pmatrix}\\] Clear row\n\\(3\\) using \\(R_3\\mapsto R_3+(-1)R_2\\)\\[\\begin{pmatrix} 2 & -3 & -1\n& 4 \\\\ 0 & 2 & 0 & -7 \\\\ 0 & 0 & -3 & 0 \\\\ 0 & 0 & 5 & -2\n\\end{pmatrix}\\] Clear row \\(4\\) using \\(R_4\\mapsto\nR_4+(5/3)R_3\\)\\[\\begin{pmatrix} 2 & -3 & -1 & 4 \\\\ 0 & 2 & 0 & -7\n\\\\ 0 & 0 & -3 & 0 \\\\ 0 & 0 & 0 & -2 \\end{pmatrix}\\]This is now in\nechelon form and has the same determinant as the matrix we began\nwith, so the determinant is the product of the diagonal entries,\nwhich is 24.\n\n\n\\end{Example}\n\\begin{Example}\nLet \\(C=\\begin{pmatrix} 3 & -3 & -5 & -4 \\\\ 2 & -5 & 2 & 0 \\\\ 2 & 3\n& -5 & -2 \\\\ 0 & 3 & -1 & 0 \\end{pmatrix}\\).\n\n\nClear row \\(2\\) using \\(R_2\\mapsto R_2+(-2/3)R_1\\)\\[\\begin{pmatrix}\n3 & -3 & -5 & -4 \\\\ 0 & -3 & 16/3 & 8/3 \\\\ 2 & 3 & -5 & -2 \\\\ 0 & 3\n& -1 & 0 \\end{pmatrix}\\] Clear row \\(3\\) using \\(R_3\\mapsto\nR_3+(-2/3)R_1\\)\\[\\begin{pmatrix} 3 & -3 & -5 & -4 \\\\ 0 & -3 & 16/3 &\n8/3 \\\\ 0 & 5 & -5/3 & 2/3 \\\\ 0 & 3 & -1 & 0 \\end{pmatrix}\\] Clear\nrow \\(3\\) using \\(R_3\\mapsto R_3+(5/3)R_2\\)\\[\\begin{pmatrix} 3 & -3\n& -5 & -4 \\\\ 0 & -3 & 16/3 & 8/3 \\\\ 0 & 0 & 65/9 & 46/9 \\\\ 0 & 3 &\n-1 & 0 \\end{pmatrix}\\] Clear row \\(4\\) using \\(R_4\\mapsto\nR_4+(1)R_2\\)\\[\\begin{pmatrix} 3 & -3 & -5 & -4 \\\\ 0 & -3 & 16/3 &\n8/3 \\\\ 0 & 0 & 65/9 & 46/9 \\\\ 0 & 0 & 13/3 & 8/3 \\end{pmatrix}\\]\nClear row \\(4\\) using \\(R_4\\mapsto R_4+(-3/5)R_3\\)\\[\\begin{pmatrix}\n3 & -3 & -5 & -4 \\\\ 0 & -3 & 16/3 & 8/3 \\\\ 0 & 0 & 65/9 & 46/9 \\\\ 0\n& 0 & 0 & -2/5 \\end{pmatrix}\\]This is now in echelon form and has\nthe same determinant as the matrix we began with, so the determinant\nis the product of the diagonal entries, which is \\(26\\).\n\n\n\\end{Example}\n\\clearpage\n\\section{Formulas for determinants and for inverses}\n\\subsection{Inductive formula for determinants}\n\n\nWe can expand the determinant as follows. First make your choice of\nentry from the first row, say in the \\(j\\)th column. Now remove the\nfirst row and the \\(j\\)th column. You're left with a smaller square\nmatrix, which we'll call \\(C_{1j}\\), from which you have to select the\nremaining entries. The picture below shows how to extract \\(C_{12}\\)\nfrom a \\(4\\)-by-\\(4\\) matrix.\n\n\n\\tka[decoration=snake]\n\\node at (0,0) {\\(\\ma A_{11} & A_{12} & A_{13} & A_{14} \\\\ A_{21} & A_{22} & A_{23} & A_{24} \\\\ A_{31} & A_{32} & A_{33} & A_{34} \\\\ A_{41} & A_{42} & A_{43} & A_{44} \\mz\\)};\n\\draw[thick] (-1.8,0.65) -- (1.8,0.65);\n\\draw[thick] (-0.48,0.8) -- (-0.48,-0.8);\n\\draw[red] (-1.7,-0.85) -- (-1,-0.85) -- (-1,0.45) -- (-1.7,0.45) -- cycle;\n\\draw[red] (0.2,-0.85) -- (1.7,-0.85) -- (1.7,0.45) -- (0.2,0.45) -- cycle;\n\\draw[->,thick,decorate] (2,0) -- (2.9,0);\n\\node at (5,0) {\\(C_{12}=\\ma A_{21} & A_{23} & A_{24} \\\\ A_{31} & A_{33} & A_{34} \\\\ A_{41} & A_{43} & A_{44}\\mz\\)};\n\\draw[red] (4.3,-0.6) -- (6.7,-0.6) -- (6.7,0.6) -- (4.3,0.6) -- cycle;\n\\tkz\n\n\nAs you run over these choices, you obtain the\ndeterminant of this submatrix \\(C_{1j}\\). Now allow the choice of\n\\(j\\) to vary, and you obtain the following useful inductive formula\nfor the determinant:\n\\[\\det(A)=A_{11}\\det(C_{11})-A_{12}\\det(C_{12})+A_{13}\\det(C_{13})+\\cdots+(-1)^nA_{1n}\\det(C_{1n}).\\]\nIn fact, we could have started from any row (say the \\(i\\)th) and\nobtained a similar expression\n\\[\\det(A)=(-1)^{i+1}\\left(A_{i1}\\det(C_{i1})-A_{i2}\\det(C_{i2})+A_{i3}\\det(C_{i3})+\\cdots+(-1)^nA_{in}\\det(C_{in})\\right),\\]\nwhere \\(C_{ij}\\) is the submatrix obtained by deleting the \\(i\\)th row\nand the \\(j\\)th column.\n\n\nIn fact, we could have expanded by going down the \\(j\\)th column\ninstead:\n\\[\\det(A)=(-1)^{j+1}\\left(A_{1j}\\det(C_{1j})-A_{2j}\\det(C_{2j})+\\cdots+(-1)^nA_{nj}\\det(C_{nj})\\right)\\]\nThe only non-obvious thing about these formulas is how to get the\nsigns. The contribution to \\(A_{ij}\\det(C_{ij})\\) to one of these\nformulas is the sign \\((-1)^{i+j}\\) in the \\(ij\\) position of the grid\nbelow: \\[\\ma + & - & + & \\cdots \\\\ - & + & - & \\cdots \\\\+ & - & + &\n\\cdots \\\\ \\vdots & \\vdots & \\vdots & \\mz.\\] You can prove this using\nindex notation if you start from our formula for the determinant, but\nrather than go through this, we will simply use the formula to compute\nsome determinants.\n\n\n\\begin{Remark}\nThe determinants of submatrices are called {\\em\nminors}. Historically, the mathematician Sylvester introduced the\nword ``matrix'' (the Latin word for {\\em womb}) because...\n\n\n\\begin{quotation}\nI have in previous papers defined a ``Matrix'' as a rectangular array of\nterms, out of which different systems of determinants may be\nengendered as from the womb of a common parent.\n\\end{quotation}\n\n\nLet it never be said that mathematicians don't have vivid\nimaginations.\n\n\n\\end{Remark}\n\\begin{Example}\nLet's calculate the determinant of \\[A=\\ma 1 & 2 & 3 \\\\ 4 & 5 & 6\n\\\\ 7 & 8 & 9\\mz\\] using this inductive formula. We have\n\\begin{align*}\n\\det(A)&=\\det\\ma 5 & 6 \\\\ 8 & 9\\mz-2\\det\\ma 4 & 6 \\\\ 7 &\n9\\mz+3\\det\\ma 4 & 5 \\\\ 7 & 8 \\mz\\\\\n&=(5\\times 9-6\\times 8)-2(4\\times 9-6\\times 7)+3(4\\times 8-5\\times 7)\\\\\n&=(45-48)-2(36-42)+3(32-35)\\\\\n&=-3+12-9\\\\\n&=0.\n\\end{align*}\n\n\n\\end{Example}\n\\begin{Example}\nLet's calculate the determinant of \\[B=\\ma 1 & 1 & 2 & 3 \\\\ 0 & 0 &\n4 & 5 \\\\ -1 & 2 & 1 & 1 \\\\ 0 & 0 & 2 & 3\\mz\\] using the inductive\nformula. Note that every entry on the first row is nonzero, so\nexpanding along the first row would involve calculating four 3-by-3\nminors. If, instead, we expand along the second {\\em column} then we\nonly have two nonzero entries, so only need to compute two 3-by-3\nminors (first column, second row or fourth row would also have this\nadvantage; I picked the second column because it makes the signs\nmore interesting). This gives\n\\begin{align*}\n\\det(B)&=-\\det\\ma 0 & 4 & 5 \\\\ -1 & 1 & 1\\\\ 0 & 2 & 3\\mz - 2\\det\\ma 1 & 2 & 3 \\\\ 0 & 4 & 5 \\\\ 0 & 2 & 3 \\mz\\\\\n&=-\\left(-\\left(-\\det\\ma 4 & 5 \\\\ 2 & 3\\mz\\right)\\right)-2\\det\\ma 4 & 5 \\\\ 2 & 3\\mz\\\\\n&=-3(4\\times 3-5\\times 2)\\\\\n&=-6.\n\\end{align*}\nLet's check we did it right using row operations. Add row 1 to row\n3: \\[\\ma 1 & 1 & 2 & 3 \\\\ 0 & 0 & 4 & 5 \\\\ 0 & 3 & 3 & 4 \\\\ 0 & 0 &\n2 & 3\\mz\\] Switch rows 2 and 3 (picking up a minus sign in the\ndeterminant) \\[\\ma 1 & 1 & 2 & 3 \\\\ 0 & 3 & 3 & 4 \\\\ 0 & 0 & 4 & 5\n\\\\ 0 & 0 & 2 & 3\\mz\\] Subtract twice row 4 from row 3, then switch\nthem (another sign, which cancels the previous one). \\[\\ma 1 & 1 &\n2 & 3 \\\\ 0 & 3 & 3 & 4 \\\\ 0 & 0 & 2 & 3\\\\ 0 & 0 & 0 & -1 \\mz\\] The\ndeterminant is the product of the diagonal entries, which is indeed\n\\(-6\\).\n\n\n\n\n\\end{Example}\n\\subsection{Inverses in terms of determinants}\n\n\n\\begin{Definition}\nDefine the {\\em adjugate matrix} of \\(A\\) to be the matrix\n\\[\\adj(A):=\\ma +\\det(C_{11}) & -\\det(C_{12}) & +\\det(C_{13}) & \\cdots\n\\\\ \\det(C_{21}) & +\\det(C_{22}) & -\\det(C_{23}) & \\cdots\n\\\\+\\det(C_{31}) & -\\det(C_{32}) & +\\det(C_{33}) & \\cdots \\\\ \\vdots &\n\\vdots & \\vdots & \\mz^T.\\]\n\n\n\\end{Definition}\n\\begin{Theorem}\nIf \\(\\det(A)\\neq 0\\) then \\(A^{-1}=\\frac{1}{\\det(A)}\\adj(A)\\).\n\\end{Theorem}\n\\begin{Proof}\nWe can compute \\(A \\adj(A)\\). The \\(ij\\)th entry is precisely the\nexpression \\[\\pm(A_{i1}\\det(C_{j1})-A_{i2}\\det(C_{j2})+\\cdots\\pm\nA_{in}\\det(C_{jn}))\\] which equals \\(\\det(A)\\) if \\(i=j\\). If\n\\(i\\neq j\\) then this expression is the determinant of the matrix\nobtained from \\(A\\) by replacing the \\(j\\)th row with the \\(i\\)th\nrow, so two rows coincide and the determinant vanishes. Therefore\n\\(A \\adj(A)=\\ma \\det(A) & 0 & \\cdots & 0 \\\\ 0 & \\det(A) & &\n0\\\\ \\vdots & & \\ddots & 0\\\\ 0 & \\cdots & 0 & \\det(A)\\mz\\), and so\n\\(\\frac{1}{\\det(A)}\\adj A\\) is an inverse for \\(A\\). \\qedhere\n\\end{Proof}\n\\clearpage\n\\section{More on determinants}\n\\subsection{Further properties of determinants}\n\n\n\\begin{Lemma}\\label{lma:detrowII}\nIf \\(A'\\) is obtained from \\(A\\) by a row operation of the form\n\\(R_i\\mapsto \\lambda R_i\\) then \\(\\det(A')=\\lambda\\det(A)\\).\n\\end{Lemma}\n\\begin{Proof}\n\\begin{align*}\n\\det(A')&=\\sum_{\\sigma}sgn(\\sigma)A_{1\\sigma(1)}\\cdots(\\lambda A_{i\\sigma(i)})\\cdots A_{n\\sigma(n)}\\\\\n&=\\lambda\\sum_{\\sigma}sgn(\\sigma)A_{1\\sigma(1)}\\cdots A_{i\\sigma(i)}\\cdots A_{n\\sigma(n)}\\\\\n&=\\lambda\\det(A). \\qedhere\n\\end{align*}\n\n\n\\end{Proof}\n\\begin{Theorem}\\label{thm:detinv}\nAn \\(n\\)-by-\\(n\\) matrix \\(A\\) is invertible if and only if its\ndeterminant is nonzero.\n\\end{Theorem}\n\\begin{Proof}\nPut \\(A\\) into echelon form using only row operations of type\n\\(R_i\\mapsto R_i+\\lambda R_j\\). You don't change the\ndeterminant. Now use row operations of type \\(R_i\\mapsto\\lambda\nR_i\\) (\\(\\lambda\\neq 0\\)) to put \\(A\\) into reduced echelon\nform. You change the determinant by a nonzero factor (the product of\nall the \\(\\lambda\\)s that you used in the row operations). By\n\\cref{thm:invech}, a matrix is invertible if and only if its reduced\nechelon form is the identity matrix, which has determinant \\(1\\),\nso:\n\\begin{itemize}\n\\item if \\(A\\) is invertible then its determinant differs from \\(1\\) by\na nonzero factor, and\n\\item if \\(A\\) is not invertible then its reduced echelon form has a\nzero row somewhere, so the reduced echelon form has determinant\nzero and \\(\\det(A)\\) is a multiple of zero, hence zero. \\qedhere\n\n\n\\end{itemize}\n\\end{Proof}\n\\begin{Theorem}\\label{thm:detmult}\nIf \\(A\\) and \\(B\\) are \\(n\\)-by-\\(n\\) matrices then\n\\[\\det(AB)=\\det(A)\\det(B).\\]\n\\end{Theorem}\n\\begin{Proof}\nFirst, we show this under the assumption that \\(A\\) is an elementary\nmatrix.\n\\begin{itemize}\n\\item If \\(A=E_{ij}(\\lambda)\\) then \\(AB\\) is the result of the row\noperation \\(R_i\\mapsto R_i+\\lambda R_j\\) on \\(B\\), so\n\\(\\det(AB)=\\det(B)\\) by \\cref{lma:detrowI}. Moreover,\n\\(\\det(A)=1\\) by \\cref{exm:detelemI}. Therefore\n\\(\\det(A)\\det(B)=\\det(B)\\) too, so the theorem is proved in this\ncase.\n\\item If \\(A=E_i(\\lambda)\\) then \\(AB\\) is the result of the row\noperation \\(R_i\\mapsto \\lambda R_i\\) on \\(B\\), so\n\\(\\det(AB)=\\lambda\\det(B)\\) by \\cref{lma:detrowI}. Moreover,\n\\(\\det(A)=\\lambda\\) by \\cref{exm:detelemII}. Therefore\n\\(\\det(A)\\det(B)=\\lambda\\det(B)\\) too, so the theorem is proved in\nthis case.\n\\end{itemize}\nNow, if we assume that \\(A\\) is a product of elementary matrices\nthen the theorem follows from these two special cases by induction.\n\n\nIf \\(A\\) is not a product of elementary matrices then \\(A\\) is not\ninvertible, so its determinant is zero by\n\\cref{thm:detinv}. Moreover, \\(AB\\) is also noninvertible because\n\\(A\\) is not invertible, so \\(\\det(AB)=0\\) by \\cref{thm:detinv}, so\n\\(\\det(AB)=0=\\det(A)\\det(B)\\), and the theorem is proved in this\ncase too. \\qedhere\n\n\n\\end{Proof}\n\\subsection{Geometric interpretation of determinants}\n\n\n\\begin{Theorem}\nSuppose that \\(A=\\ma a & b \\\\ c & d \\mz\\). Let \\(S\\) be the unit\nsquare sitting in the plane and let \\(A(S)\\) denote the image of\n\\(S\\) under the linear map defined by \\(A\\). Then \\(|\\det(A)|\\) is\nthe area of \\(A(S)\\).\n\\end{Theorem}\n\\begin{Proof}\nThe shape \\(A(S)\\) is a parallelogram with sides parallel to the\nvectors \\(\\ma a \\\\ c\\mz\\) and \\(\\ma b \\\\ d\\mz\\). This parallelogram\nhas area \\(ad-bc\\) as we can see by dissection, using the following\npicture:\n\n\n\\tka\n\\begin{scope}[shift={(-4,0)}]\n\\filldraw[gray,opacity=0.7] (0,0) -- (1,2) -- (3,3) -- (2,1) -- cycle;\n\\filldraw[red,opacity=0.5] (0,0) -- (2,0) -- (2,2) -- (0,2) -- cycle;\n\\end{scope}\n\\filldraw[red] (0,0) -- (1,2) -- (2,2) -- (2,1) -- cycle;\n\\filldraw[blue] (0,0) -- (1,2) -- (0,1) -- cycle;\n\\filldraw[green] (0,0) -- (1,0) -- (2,1) -- cycle;\n\\filldraw[purple] (0,1) -- (0,2) -- (1,2) -- cycle;\n\\filldraw[purple] (1,0) -- (2,0) -- (2,1) -- cycle;\n\\filldraw[green] (1,2) -- (3,3) -- (2,2) -- cycle;\n\\filldraw[blue] (2,1) -- (3,3) -- (2,2) -- cycle;\n\\tkz\n\n\nTake the grey parallelogram \\(A(S)\\), draw the rectangle with\nsidelengths \\(a\\) (along) and \\(d\\) (up) over it. Move the green\nand blue pieces of the parallelogram inside the rectangle as\nshown. Now the red, green and blue areas inside the square have the\nsame area as \\(A(S)\\). The remaining (purple) part comprises two\ntriangles which have height \\(c\\) and base \\(b\\), so the area of\n\\(A(S)\\) is \\(ad-bc\\). \\qedhere\n\n\n\\end{Proof}\nIt is much harder to see the following theorems, but they are true:\n\n\n\\begin{Theorem}\nIf \\(A\\) is an \\(n\\)-by-\\(n\\) matrix then \\(|\\det(A)|\\) is the\nvolume of \\(A(S)\\), where \\(S\\) is the unit cube in\n\\(n\\)-dimensions.\n\n\n\\end{Theorem}\n\\begin{Remark}\nThe shape \\(A(S)\\) is called a {\\em parallelopiped}, the\nhigher-dimensional analogue of a parallelogram.\n\n\n\\end{Remark}\n\\begin{Theorem}\nLet \\(a_1,\\ldots,a_n\\) be \\(n\\) vectors in \\(\\RR^n\\). Consider the\n{\\em simplex} with vertices at the origin and at\n\\(a_1,\\ldots,a_n\\). The volume of this simplex is\n\\(\\frac{1}{n!}|\\det(A)|\\), where \\(A\\) is the matrix with columns\n\\(a_1,\\ldots,a_n\\).\n\n\n\\end{Theorem}\n\\begin{Example}\nIf \\(A=\\ma 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1\\mz\\) then the simplex\nwe get is the tetrahedron shown below. Its volume is \\(1/6\\)\n(because of the above formula, but also because you can dissect and\nrearrange a cube into six such tetrahedra).\n\n\n\\tka\n\\filldraw[fill=lightgray,draw=black,thick,opacity=0.5] (1.5,-0.5) -- (1.8,0.3) -- (0,0) -- cycle;\n\\filldraw[fill=lightgray,draw=black,thick,opacity=0.5] (1.8,0.3) -- (0,0) -- (0,2) -- cycle;\n\\filldraw[fill=lightgray,draw=black,thick,opacity=0.5] (1.5,-0.5) -- (0,0) -- (0,2) -- cycle;\n\\filldraw[fill=lightgray,draw=black,thick,opacity=0.5] (1.5,-0.5) -- (1.8,0.3) -- (0,2) -- cycle;\n\\tkz\n\n\n\\end{Example}\n\\begin{Example}\nThe regular tetrahedron (or d4, for any Dungeons \\& Dragons fans out\nthere) has vertices \\[a_0=\\ma 1/2 \\\\ 0 \\\\ 1/\\sqrt{2}\\mz,\\quad\na_1=\\ma -1/2 \\\\ 0 \\\\ -1/\\sqrt{2}\\mz,\\quad a_2\\ma 0 \\\\ 1/2\n\\\\ -1/\\sqrt{2}\\mz,\\quad a_3\\ma 0 \\\\ -1/2 \\\\ 1/\\sqrt{2}\\mz.\\] By\ntranslating this so that the vertex \\(a_0\\) is at the origin, we get\nthe vertices \\[a_1-a_0,\\quad a_2-a_0,\\quad a_3-a_0,\\] so the volume\nis \\[\\frac{1}{6}|\\det(a_1-a_0,a_2-a_0,a_3-a_0)|,\\] or\n\\[\\frac{1}{6}\\left|\\det\\ma -1 & -1/2 & -1/2 \\\\ 0 & 1/2 & -1/2 \\\\ 0 &\n\\sqrt{2} & \\sqrt{2} \\mz\\right|=\\frac{1}{6\\sqrt{2}}.\\]\n\n\n\\end{Example}\n\\begin{Remark}\nFrom this geometric point of view, the fact that\n\\(\\det(AB)=\\det(A)\\det(B)\\) is obvious: \\(\\det(M)\\) is the scaling\nfactor for volumes under the linear map \\(M\\), so under the\ncomposite \\(AB\\) we first scale by \\(\\det(B)\\) and then by\n\\(\\det(A)\\), so \\(\\det(AB)=\\det(A)\\det(B)\\). Unfortunately, we\nhaven't proved the theorems above which establish the connection\nbetween determinants and scaling of volumes.\n\n\n\\end{Remark}\n\\clearpage\n\\section{Eigenvectors and eigenvalues}\n\\subsection{Definition and basic ideas}\n\n\nIf someone gives you a complicated matrix \\(A\\), it can be very\ndifficult to determine salient information about the underlying linear\nmap associated to \\(A\\). For example, \\(A\\) could be a very simple\ntransformation like a rotation, but happening around an axis that\npoints in some random direction, which makes the matrix very\ncomplicated. For this reason, we want to look for geometric features\nlike fixed vectors of \\(A\\), just as we did for 2-by-2 matrices. It\nturns out that the most fruitful thing to study is the following\nnotion.\n\n\n\\begin{Definition}[Eigenvectors, eigenvalues]\\label{dfn:eigenvector}\nLet \\(A\\) be a matrix. A vector \\(v\\) is called an {\\em eigenvector}\nfor \\(A\\) with {\\em eigenvalue} \\(\\lambda\\) if \\(v\\neq 0\\) and\n\\[Av=\\lambda v.\\]\n\n\n\\end{Definition}\nFor example, a fixed vector is an eigenvector with eigenvalue\n\\(1\\). ``Eigen'' is a German prefix meaning ``self''. An eigenvector\nis mapped by \\(A\\) back to itself rescaled by its eigenvalue.\n\n\n\\begin{Remark}\nIt is hard to overemphasise the importance of eigenvectors and\neigenvalues. We will see some fun applications in this course, but\nyou will encounter them again and again in courses throughout your\ntime as an undergraduate. They are one of the most important notions\nin mathematics and science. For example, in quantum mechanics the\nmost important equation is the Schr\\\"{o}dinger equation, which is\nthe eigenvector equation\\footnote{Caveat: \\(H\\) is more like an\ninfinite-by-infinite matrix, i.e. an operator on a Hilbert space,\nwhich makes the Schr\\\"{o}dinger equation into a differential\nequation.} \\(H\\psi=E\\psi\\). Here \\(H\\) is a linear map called the\nHamiltonian, \\(\\psi\\) is a vector describing the state of the\nquantum system, and \\(E\\) is the energy of the state \\(\\psi\\). For\nexample, if \\(H\\) is the Hamiltonian for the hydrogen atom then the\neigenvalues of \\(H\\) are the possible energies of light that can be\nabsorbed/emitted by hydrogen (the {\\em spectrum} of the hydrogen\natom). The fact that Schr\\\"{o}dinger's equation predicts the\nhydrogen spectrum so well was an early confirmation that quantum\nmechanics was on the right track.\n\n\n\\end{Remark}\n\\subsection{Finding the eigenvectors}\n\n\nSuppose someone tells you that some matrix \\(A\\) (say \\(\\ma 2 & -1\n\\\\ 1 & 0 \\mz\\)) has some eigenvectors with eigenvalue \\(\\lambda\\) (say\n\\(1\\)). It's now very easy to find all the eigenvectors with this\neigenvalue: you just need to solve the simultaneous equations\n\\(Av=\\lambda v\\), in our case\n\\[\\ma 2 & -1 \\\\ 1 & 0 \\mz\\ma x \\\\ y \\mz=\\ma x \\\\ y\\mz,\\]\nor\n\\begin{align*}\n2x-y&=x\\\\\nx&=y.\n\\end{align*}\nThese equations both reduce to \\(y=x\\), so the eigenvectors must be\n\\(\\ma x \\\\ x \\mz\\).\n\n\n\\begin{Remark}\nNote that if \\(v\\) is an eigenvector with eigenvalue \\(\\lambda\\)\nthen any rescaling \\(\\mu v\\) is also an eigenvector with eigenvalue\n\\(\\lambda\\) because \\[A(\\mu v)=\\mu Av=\\mu\\lambda v\\Rightarrow A(\\mu\nv)=\\lambda(\\mu v).\\] Therefore you shouldn't be surprised that we\nhave found a one-parameter family of eigenvectors instead of just\none!\n\n\n\\end{Remark}\n``By George!'' you might say, ``the fellow is right, there is indeed\nan eigenvector with eigenvalue \\(\\lambda\\)... but how did he know\nwhich \\(\\lambda\\) to tell me?'' For example, if we tried\n\\(\\lambda=2\\), we would fail:\n\\begin{align*}\n2x-y&=2x\\\\\nx&=2y\n\\end{align*}\nhave no solution other than \\(x=y=0\\), because the first implies\n\\(y=0\\) and the second implies \\(x=y=0\\). Remember than eigenvectors\nare required to be nonzero. Therefore there is no eigenvector of \\(\\ma\n2 & -1 \\\\ 1 & 0\\mz\\) with eigenvalue \\(2\\).\n\n\n\\subsection{Finding the eigenvalues}\n\n\n\\begin{Theorem}[Characteristic polynomial]\\label{thm:charpoly}\nThe eigenvalues of a matrix \\(A\\) are the roots of the {\\em\ncharacteristic polynomial} \\(\\chi_A(t)\\) of \\(A\\). This is the\npolynomial defined by \\(\\chi_A(t)=\\det(A-tI)\\).\n\\end{Theorem}\n\\begin{Proof}[Proof of \\cref{thm:charpoly}]\\label{prf:thm:charpoly}\nIf \\(v\\neq 0\\) and \\(Av=\\lambda v\\) then \\((A-\\lambda I)v=0\\), so\n\\(A-\\lambda I\\) has nontrivial kernel and fails to be invertible. In\nparticular, \\(\\det(A-\\lambda I)=0\\). Conversely, if \\(\\det(A-\\lambda\nI)=0\\) then \\(A-\\lambda I\\) has nontrivial kernel, so there exists a\nvector \\(v\\) such that \\(Av-\\lambda v=0\\). \\qedhere\n\n\n\\end{Proof}\n\\begin{Example}\nFor the matrix \\(A=\\ma 2 & -1 \\\\ 1 & 0 \\mz\\) above, we have\n\\begin{align*}\n\\chi_A(t)&=\\det\\ma 2 & -1 \\\\ 1 & 0 \\mz-\\ma t & 0 \\\\ 0 & t\\mz\\\\\n&=\\det\\ma 2-t & -1 \\\\ 1 & -t\\mz\\\\\n&=-t(2-t)+1\\\\\n&=t^2-2t+1.\n\\end{align*}\nThis polynomial has \\(1\\) as a repeated root, so the only eigenvalue\nis \\(1\\) and, as we saw above, the only eigenvector (up to scaling)\nis \\(\\ma 1 \\\\ 1\\mz\\).\n\n\n\\end{Example}\n\\begin{Example}\\label{exm:cat}\nThe matrix \\(A=\\ma 2 & 1 \\\\ 1 & 1 \\mz\\) has characteristic\npolynomial \\[\\det(A-tI)=\\det\\ma 2-t & 1 \\\\ 1 &\n1-t\\mz=(2-t)(1-t)-1=t^2-3t+1,\\] which has roots\n\\(\\lambda_1=\\frac{3+\\sqrt{5}}{2}\\) and\n\\(\\lambda_2=\\frac{3-\\sqrt{5}}{2}\\). As eigenvectors, we can take\n\\[v_1=\\ma 1\\\\ \\frac{1+\\sqrt{5}}{2}\\mz,\\qquad v_2=\\ma 1\n\\\\ \\frac{1-\\sqrt{5}}{2}\\mz.\\]\n\n\n\\end{Example}\n\\begin{Example}\nThe matrix \\(A=\\ma \\frac{3}{2} & \\frac{5}{2} & 3 \\\\ -\\frac{1}{2} &\n-\\frac{3}{2} & -3 \\\\ 1 & 1 & 2 \\mz\\) has characteristic polynomial\n\\begin{align*}\n\\det(A-tI)&=\\det\\ma \\frac{3}{2}-t & \\frac{5}{2} & 3 \\\\ -\\frac{1}{2} &\n-\\frac{3}{2}-t & -3 \\\\ 1 & 1 & 2-t\\mz\\\\\n&=\\left(\\frac{3}{2}-t\\right)\\det\\ma -\\frac{3}{2}-t & -3 \\\\ 1 & 2-t\\mz -\\frac{5}{2}\\det\\ma -\\frac{1}{2} & -3 \\\\ 1 & 2-t\\mz\\\\\n&\\qquad\\qquad +3\\det\\ma -\\frac{1}{2} & -\\frac{3}{2}-t \\\\ 1 & 1\\mz\\\\\n&=\\left(\\frac{3}{2}-t\\right)\\left(-\\left(\\frac{3}{2}+t\\right)\\left(2-t\\right)+3\\right)-\\frac{5}{2}\\left(-\\frac{1}{2}(2-t)+3\\right)\\\\\n&\\qquad\\qquad+3\\left(-\\frac{1}{2}+\\frac{3}{2}+t\\right)\\\\\n&=\\left(\\frac{3}{2}-t\\right)(t^2-t/2)-\\frac{5}{2}(t/2+2)+3t+3\\\\\n&=-t^3+2t^2+t-2.\n\\end{align*}\nWhat are the roots of this polynomial? With cubics, the easiest\nmethod is to guess one of the roots (say \\(\\alpha\\)), divide the\npolynomial by \\(t-\\alpha\\) (using polynomial long division) and then\nsolve the quadratic equation you get. Here, we can see that \\(t=1\\)\nis a solution\\footnote{You'd be surprised how often that happens in\ncarefully-constructed examples.} and dividing \\(-t^3+2t^2+t-2\\) by\n\\(t-1\\) gives \\(-t^2+t+2\\), which has solutions \\(\\frac{-1\\pm\n\\sqrt{3}}{-2}=-1,2\\). Therefore the eigenvalues are \\(-1,1,2\\). The\ncorresponding eigenvectors are \\(\\ma -1 \\\\ 1 \\\\ 0\\mz\\), \\(\\ma 1\n\\\\ -5 \\\\ 4 \\mz\\) and \\(\\ma 1 \\\\ -1 \\\\ 1 \\mz\\). For example, to get\nthe \\(1\\)-eigenvector, we solve \\(v=Av\\) \\[\\ma x \\\\ y \\\\ z\\mz=\\ma\n\\frac{3}{2} & \\frac{5}{2} & 3 \\\\ -\\frac{1}{2} & -\\frac{3}{2} & -3\n\\\\ 1 & 1 & 2 \\mz\\ma x \\\\ y \\\\ z\\mz,\\] that is\n\\begin{align*}\n\\frac{3x}{2}+\\frac{5y}{2}+3z&=x\\\\\n-\\frac{1}{2}x-\\frac{3}{2}y-3z&=y\\\\\nx+y+2z&=z.\n\\end{align*}\nThese equations imply \\(x+5y+6z=0\\) and \\(x+y+z=0\\), so \\(4y+5z=0\\),\ntherefore if we pick \\(y=-5\\) we get \\(z=4\\) and \\(x=-y-z=1\\).\n\n\n\\end{Example}\n\\clearpage\n\\section{Applications of eigenvectors}\n\\subsection{Application I: Differential equations}\n\n\nLet \\(v(t)=\\ma x_1(t)\\\\ \\vdots \\\\ x_n(t)\\mz\\) be a vector-valued\nfunction, let \\(A\\) be an \\(n\\)-by-\\(n\\) matrix, and consider the\nsystem of differential equations\n\\begin{align*}\n\\dot{x}_1&=A_{11}x_1+\\cdots+A_{1n}x_n\\\\\n&\\vdots\\\\\n\\dot{x}_n&=A_{n1}x_1+\\cdots+A_{nn}x_n,\n\\end{align*}\nor, more succinctly,\n\\[\\dot{v}=Av.\\]\n\n\n\\begin{Example}\\label{exm:odeexm}\nConsider the system of differential equations\n\\begin{align*}\n\\dot{x}&=2x+y\\\\\n\\dot{y}&=x+y.\n\\end{align*}\nWe can rewrite this as \\[\\frac{d}{dt}\\ma x \\\\ y \\mz=\\ma 2 & 1\\\\ 1 &\n1\\mz\\ma x \\\\ y \\mz.\\]\n\n\n\\end{Example}\nSuppose that \\(A\\) has \\(n\\) eigenvalues\n\\(\\lambda_1,\\ldots,\\lambda_n\\) with eigenvectors\n\\(v_1,\\ldots,v_n\\). We can write \\(v\\) in terms of the basis of\neigenvectors: \\[v=\\sum_{i=1}^nf_iv_i\\] for some collection of numbers\n\\(f_1,\\ldots,f_n\\). We have \\[\\dot{v}=\\sum_{i=1}^n\\dot{f}_iv_i\\] and\n\\[Av=A\\sum_{i=1}^nf_iv_i=\\sum_{i=1}^nf_iAv_i=\\sum_{i=1}^nf_i\\lambda_iv_i.\\]\nSince \\(\\dot{v}=Av\\), we can equate the coefficients of the vectors\n\\(v_1,\\ldots,v_n\\) in these two expressions. We get the much simpler\nequation \\[\\dot{f}_i=\\lambda_i f_i,\\] with solution\n\\(f_i(t)=C_ie^{\\lambda_i t}\\) for some constant \\(C_i\\). The general\nsolution to the differential equation is therefore\n\\[v=\\sum_{i=1}^nC_ie^{\\lambda_it}v_i.\\] Let's apply this to solve the\ndifferential equations from \\cref{exm:odeexm}\n\n\n\\begin{Example}\nThe matrix \\(A=\\ma 2 & 1 \\\\ 1 & 1 \\mz\\) has eigenvalues\n\\(\\lambda_1=\\frac{3+\\sqrt{5}}{2}\\),\n\\(\\lambda_2=\\frac{3-\\sqrt{5}}{2}\\) and eigenvectors \\(v_1=\\ma\n1\\\\ \\frac{1+\\sqrt{5}}{2}\\mz\\) and \\(v_2=\\ma 1\n\\\\ \\frac{1-\\sqrt{5}}{2}\\mz\\). Therefore, the general solution is\n\\[C_1e^{(3+\\sqrt{5})t/2}\\ma\n1\\\\ \\frac{1+\\sqrt{5}}{2}\\mz+C_2e^{(3-\\sqrt{5})t/2}\\ma 1\n\\\\ \\frac{1-\\sqrt{5}}{2}\\mz,\\] or\n\\begin{align*}\nx(t)&=C_1e^{(3+\\sqrt{5})t/2}+C_2e^{(3-\\sqrt{5})t/2},\\\\\ny(t)&=\\frac{1+\\sqrt{5}}{2}C_1e^{(3+\\sqrt{5})t/2}+\\frac{1-\\sqrt{5}}{2}C_2e^{(3-\\sqrt{5})t/2}.\n\\end{align*}\n\n\n\\end{Example}\n\\begin{Example}\nConsider the system of differential equations\n\\begin{align*}\n\\dot{x}&=2x+y\\\\\n\\dot{y}&=2y-x.\n\\end{align*}\nWe can rewrite this as \\[\\frac{d}{dt}\\ma x \\\\ y \\mz=\\ma 2 & 1\\\\ -1 &\n2\\mz\\ma x \\\\ y \\mz.\\] The matrix \\(A=\\ma 2 & 1 \\\\ -1 & 2 \\mz\\) has\ncharacteristic polynomial \\[\\det(A-tI)=\\det\\ma 2-t & 1 \\\\ -1 &\n2-t\\mz=(2-t)(2-t)+1=t^2-4t+5,\\] which has roots \\(2\\pm i\\). The\neigenvectors for these eigenvalues are the solutions to \\[\\ma (2+i)x\n\\\\ (2+i)y\\mz=\\ma 2x+y\\\\2y-x\\mz,\\] (i.e. \\(\\ma 1 \\\\ i\\mz\\)) and \\[\\ma\n(2-i)x \\\\ (2-i)y\\mz=\\ma 2x+y\\\\2y-x\\mz\\] (i.e. \\(\\ma 1\n\\\\ -i\\mz\\)). Therefore the general solution to the system of\ndifferential equations in this example is \\[C_1e^{(2+i)t}\\ma 1 \\\\ i\n\\mz+C_2e^{(2-i)t}\\ma 1 \\\\ -i\\mz,\\] or\n\\[x(t)=C_1e^{(2+i)t}+C_2e^{(2-i)t},\\quad\ny(t)=iC_1e^{(2+i)t}-iC_2e^{(2-i)t}.\\] You should not worry about the\nappearance of imaginary numbers here: if the initial condition you\npick is real then all the imaginary terms will group together to\ngive trigonometric functions, using the facts that\n\\[\\cos(t)=\\frac{e^{it}+e^{-it}}{2},\\qquad\\sin(t)=\\frac{e^{it}-e^{-it}}{2i}.\\]\nFor example, let's try and find the solution for the initial\ncondition \\(x(0)=0\\), \\(y(0)=1\\). This means \\[C_1+C_2=0,\\qquad\ni(C_1-C_2)=1,\\] that is, \\(C_1=-C_2=-i/2\\). Substituting these\nvalues for \\(C_1,C_2\\) we get\n\\[x(t)=-\\frac{i}{2}(e^{(2+i)t}-e^{(2-i)t})=e^{2t}\\frac{e^{it}-e^{-it}}{2i}=e^{2t}\\sin(t)\\]\nand \\[y(t)=\\frac{1}{2}(e^{(2+i)t}+e^{(2+it)})=e^{2t}\\cos(t).\\]\n\n\n\\end{Example}\nFinally, we should investigate what happens when \\(A\\) has fewer\nthan \\(n\\) eigenvectors.\n\n\n\\begin{Example}\nSuppose that \\(A=\\ma 1 & 1 \\\\ 0 & 1\\mz\\). The differential equations\nwe get out of \\(A\\) are\n\\begin{align*}\n\\dot{x}&=x+y\\\\\n\\dot{y}&=y.\n\\end{align*}\nWe can solve the second equation immediately and get\n\\(y=C_1e^{t}\\). Substituting back into the first, we get\n\\[\\dot{x}=x+C_1e^t.\\] Rearranging gives\n\\[\\dot{x}e^{-t}-xe^{-t}=C_1,\\] and we note (using the Leibniz rule\nfor differentiation) that\n\\[\\frac{d}{dt}(xe^{-t})=\\dot{x}e^{-t}-xe^{-t},\\] so\n\\[\\frac{d}{dt}(xe^{-t})=C_1,\\] which gives \\[x=(C_1t+C_2)e^t.\\]\n\n\n\\end{Example}\nIn a later course on linear algebra, you will see the {\\em Jordan\nnormal form} theorem for matrices, which tells you that, as long as\nyou work over \\(\\CC\\), viewed in suitable coordinates, your matrix\nalways looks like a bunch of blocks which look like this: \\[\\ma\n\\lambda & 1 & 0 & \\cdots & 0 \\\\ 0 & \\lambda & 1 & &\\vdots \\\\ 0&\n&\\ddots &\\ddots & 0\\\\ \\vdots & & & \\lambda & 1 \\\\ 0 & \\cdots &0 &0 &\n\\lambda\\mz.\\] For such matrices, you can do something similar to the\nprevious example.\n\n\n\\subsection{Application II: Ellipsoids}\n\n\n\\begin{Definition}\nWe say that \\(A\\) is a {\\em positive definite matrix} if \\(v^TAv>0\\)\nfor any vector \\(v\\neq 0\\).\n\n\n\\end{Definition}\n\\begin{Example}\nThe identity matrix is positive definite because \\(v^TIv=v\\cdot\nv\\geq 0\\) with equality if and only if \\(v=0\\).\n\n\n\\end{Example}\n\\begin{Example}\nThe matrix \\(A=\\ma 1 & 0 \\\\ 0 & -1\\mz\\) is not positive definite\nbecause \\(\\ma 0 & 1 \\mz A\\ma 0\\\\ 1\\mz=-1\\).\n\n\n\\end{Example}\n\\begin{Definition}\nAn {\\em ellipsoid} is a subset in \\(n\\)-dimensional space having the\nform \\[\\{v\\in\\RR^n\\ :\\ v^TAv=c\\},\\] where \\(A\\) is a positive\ndefinite symmetric matrix with real entries and \\(c>0\\) is a\npositive real constant.\n\n\n\\end{Definition}\n\\begin{Example}\nGiven two numbers \\(a,b\\in\\RR\\), the matrix \\[A=\\ma\\frac{1}{a^2} & 0\n\\\\ 0 & \\frac{1}{b^2}\\mz\\] is positive definite. If \\(c=1\\) then the\ncorresponding ellipsoid is the ellipse \\[\\left\\{(x,y)\\in\\RR^2\\ :\\\n\\frac{x^2}{a^2}+\\frac{y^2}{b^2}=1\\right\\}\\] having semimajor axis\n\\(a\\) and semiminor axis \\(b\\).\n\n\n\\tka\n\\draw (0,0) circle [x radius=2cm,y radius=1cm];\n\\draw[->] (0,0) -- (2,0) node [right] {\\(a\\)};\n\\draw[->] (0,0) -- (0,1) node [above] {\\(b\\)};\n\\tkz\n\n\n\\end{Example}\n\\begin{Theorem}\\label{thm:ellipsoid}\nAn ellipsoid defined by a positive definite symmetric matrix \\(A\\)\ncan be rotated to the ellipsoid \\[\\{(u_1,\\ldots,u_n)\\in\\RR^n\\ :\\\n\\sum_{i=1}^n\\lambda_iu_i^2=c\\}\\] where\n\\(\\lambda_1,\\ldots,\\lambda_n\\) are the eigenvalues of \\(A\\) and\n\\(c\\) is some positive number.\n\n\n\\end{Theorem}\nWe won't prove this theorem in full, because it relies on the fact\nthat a positive definite symmetric matrix has a basis of eigenvectors\n(which is beyond what we have time for). But we'll at least check that\n{\\em if} \\(A\\) has a basis of eigenvectors then the result\nholds. First, an important lemma.\n\n\n\\begin{Lemma}\nSuppose that \\(A\\) is a symmetric matrix with real entries. Then the\neigenvalues of \\(A\\) are real and if \\(\\lambda,\\mu\\) are distinct\neigenvalues with eigenvectors \\(v,w\\) respectively then \\(v\\cdot\nw=0\\).\n\\end{Lemma}\n\\begin{Proof}\nSuppose that \\(Av=\\lambda v\\). Consider the expression\n\\(\\bar{v}^TAv\\), where \\(\\bar{v}\\) denotes complex\nconjugation. Then, because \\(A=A^T=\\bar{A}^T\\), we have\n\\[\\bar{\\lambda}\\bar{v}^Tv=(\\overline{Av})^{T}v=\\bar{v}^TAv=\\lambda\\bar{v}^Tv.\\]\nNote that if \\(v=\\ma x_1\\\\ \\vdots\\\\ x_n\\mz\\) then\n\\(\\bar{v}^Tv=\\sum |x_1|^2+\\cdots+|x_n|^2>0\\) if \\(v\\neq 0\\), so\ndividing through by \\(\\bar{v}^Tv\\) we get \\(\\bar{\\lambda}=\\lambda\\)\nand deduce that \\(\\lambda\\) is real.\n\n\nIf \\(v\\) and \\(w\\) are two eigenvectors for distinct eigenvalues\n\\(\\lambda,\\mu\\) then\n\\begin{align*}\n\\lambda w^Tv&=w^T(Av)\\\\\n&=(Aw)^Tv\\\\\n&=\\mu w^Tv\\\\\n\\end{align*}\nso, since \\(\\lambda\\neq\\mu\\), we must have \\(w^Tv=0\\), i.e. \\(v\\cdot\nw=0\\). \\qedhere\n\n\n\\end{Proof}\nNow suppose that \\(A\\) is a real symmetric matrix which has a basis of\n\\(n\\) eigenvectors \\(v_1,\\ldots,v_n\\) with eigenvalues\n\\(\\lambda_1,\\ldots,\\lambda_n\\). By the lemma above, these eigenvalues\nare all real and the eigenvectors are orthogonal. Let's rescale the\neigenvectors so that they each have unit length. If we write a vector\n\\(v\\) as \\(\\sum_{i=1}^nu_iv_i\\) then we have\n\\[v^TAv=\\sum_{i=1}^n\\sum_{j=1}^nu_ix_jv_i^TAv_j=\\sum_{i,j=1}^n\\lambda_i\nu_i^2,\\] since \\(v_i^Tv_j=\\delta_{ij}\\). These \\(u_1,\\ldots,u_n\\) are\nthe coordinates referred to in \\cref{thm:ellipsoid}. In particular,\nthe {\\em principal axes} (the higher-dimensional analogues of the\nsemi-major and semi-minor axes) are the eigenvectors of \\(A\\) and the\nprincipal radii are \\(\\frac{1}{\\sqrt{\\lambda_i}}\\), \\(i=1,\\ldots,n\\).\n\n\n\\begin{Example}\nLet \\(A=\\ma 3/2 & -1/2 \\\\ -1/2 & 3/2\\mz\\). This defines an ellipse\n\\(v^TAv=1\\), in other words \\[\\frac{3}{2}(x^2+y^2)=1+xy.\\] The\ncharacteristic polynomial of \\(A\\) is \\[\\det\\ma 3/2-t & -1/2 \\\\ -1/2\n& 3/2-t\\mz=t^3-3t+2,\\] so the eigenvalues are \\(1\\) and \\(2\\). The\n(unit length) eigenvectors are \\(v_1=\\ma 1/\\sqrt{2}\n\\\\ 1/\\sqrt{2}\\mz\\) and \\(v_2\\ma 1/\\sqrt{2} \\\\ -1/\\sqrt{2}\\mz\\). If\nwe work with coordinates \\(u_1,u_2\\) related to \\(x,y\\) via \\[\\ma x\n\\\\ y \\mz=u_1\\ma 1/\\sqrt{2} \\\\ 1/\\sqrt{2} \\mz+u_2\\ma 1/\\sqrt{2}\n\\\\ -1/\\sqrt{2}\\mz\\] (that is, \\(x=\\frac{u_1+u_2}{\\sqrt{2}}\\),\n\\(y=\\frac{u_1-u_2}{\\sqrt{2}}\\)) then the equation of the ellipse\n\\(v^TAv=1\\) becomes \\(u_1^2+2u_2^2=1\\). We see that the change of\ncoordinates between \\(x,y\\) and \\(u_1,u_2\\) is actually a 45 degree\nrotation.\n\n\n\\end{Example}\n\\subsection{Application III: Dynamics}\n\n\nConsider the matrix \\(\\ma 2 & 1 \\\\ 1 & 1\\mz\\). We have seen\n(\\cref{exm:cat}) that its eigenvalues are \\(\\lambda_{\\pm}:=\\frac{3\\pm\n\\sqrt{5}}{2}\\), with eigenvectors \\(v_{\\pm}=\\ma\n1\\\\ \\frac{1\\pm\\sqrt{5}}{2}\\mz\\).\n\n\nSuppose we pick a point \\(v\\in\\RR^2\\) and write it as\n\\(v=av_++bv_-\\). Then \\(Av=\\lambda_+av_++\\lambda_-bv_-\\). Suppose that\n\\(a\\neq 0\\) and \\(b\\neq 0\\). Since \\(\\lambda_+>1\\) and\n\\(\\lambda_-<1\\), this means that the point moves inwards along \\(v_-\\)\nand outwards along \\(v_+\\). If we apply \\(A\\) again and again, we get\n\\[A^nv=\\lambda_+^nav+\\lambda_-^nbv_-.\\] As \\(n\\to\\infty\\),\n\\(\\lambda_+^n\\to\\infty\\) and \\(\\lambda_-^n\\to 0\\), so the point gets\ncloser and closer to the \\(v_+\\)-eigenline, but gets pushed outwards\nalong the eigenline. If we draw a rectangle in \\(\\RR^2\\) and apply\n\\(A\\) many times, this square will get stretched outwards in the\n\\(v_+\\) direction and squished inwards in the \\(v_-\\)-direction.\n\n\n\\tka\n\\draw[thick,->] (0,0) -- (2*1.618,2) node [below right] {\\(v_+\\)};\n\\draw[thick,->] (0,0) -- (-2*0.618,2) node [left] {\\(v_-\\)};\n\\draw[thick,red] (1/3,2/3) -- (0.745,0) -- (-1/3,-2/3) -- (-0.745,0) -- cycle;\n\\draw[thick,orange] (4/3,1) -- (2*0.745,0.745) -- (-4/3,-1) -- (-2*0.745,-0.745) -- cycle;\n\\draw[thick,yellow] (11/3,7/3) -- (5*0.745,3*0.745) -- (-11/3,-7/3) -- (-5*0.745,-3*0.745) -- cycle;\n\\tkz\n\n\nThis is typical behaviour of a ``hyperbolic'' dynamical system. Here\nare two fun facts which are not unrelated to this.\n\n\n\\begin{Example}[Fibonacci numbers]\\label{exm:fib}\nThe Fibonacci sequence\n\\[F_1,F_2,F_3,F_4,F_5,F_6,F_7,\\ldots=1,1,2,3,5,8,13,\\ldots\\]\nsatisfies the recursion \\(F_{n+2}=F_{n+1}+F_n\\), which we can write\nas a matrix equation: \\[\\ma F_1 \\\\ F_2\\mz=\\ma 1 \\\\ 1\\mz,\\qquad\\ma\nF_{n+1} \\\\ F_{n+2}\\mz=\\ma 0 & 1 \\\\ 1 & 1 \\mz\\ma F_n \\\\ F_{n+1}\n\\mz.\\] The eigenvalues of \\(\\ma 0 & 1 \\\\ 1 & 1 \\mz\\) are\n\\(\\lambda_{\\pm}=\\frac{1\\pm\\sqrt{5}}{2}\\) with eigenvectors\n\\(v_{\\pm}=\\ma 1\n\\\\ \\frac{1\\pm\\sqrt{5}}{2}\\mz\\). Although \\(\\lambda_-\\) is negative,\nits magnitude is nonetheless \\(<1\\), so \\(\\lambda_-^n\\to 0\\). Also,\n\\(\\lambda_+^n\\to\\infty\\). Therefore \\(\\ma F_n \\\\ F_{n+1}\\mz=A^n\\ma 1\n\\\\ 1 \\mz\\) tends in the limit \\(n\\to\\infty\\) to a vector pointing\nalong the \\(v_+\\)-eigenline, which has slope\n\\(\\frac{1+\\sqrt{5}}{2}\\). This means\n\\[\\lim_{n\\to\\infty}\\frac{F_{n+1}}{F_n}=\\frac{1+\\sqrt{5}}{2}.\\]\nThis number is known as the golden ratio.\n\n\n\\end{Example}\n\\begin{Example}[Arnol'd's cat map]\\label{exm:arncat}\nLet \\(A\\) be the example above. If you take a square picture of a\ncat and use it to tile the plane, then you apply \\(A^n\\) to the\nplane and let \\(n\\) increase, the picture will get distorted very\nquickly. However, at some point, the picture will reappear\nmore-or-less exactly as you had it to begin with. In fact, if you\nhave a digital image, it will reappear exactly how it started\n(because there's only a finite number of pixels involved). This is\ndue to a phenomenon called {\\em ergodicity} of the flow, whereby\nevery point, at some time, comes back close to where it started\n(except possibly in a different tile). Eventually, many points come\nback close to where they started (except possibly in a different\ntile) and you see something resembling the image you started with.\n\n\n\\end{Example}\nYou can see dramatic realisations of this in videos and applets\nonline.\n\n\n\\clearpage\n\\section{Subspaces I}\n\\subsection{Subspaces}\n\n\n\\begin{Definition}[Subspaces]\\label{dfn:subspace}\nA subset \\(V\\subset\\RR^n\\) is called a {\\em linear subspace} (or\njust subspace) if it satisfies the following conditions:\n\\begin{itemize}\n\\item \\(v,w\\in W\\) implies \\(v+w\\in V\\).\n\\item \\(v\\in V\\), \\(\\lambda\\in\\RR\\) implies \\(\\lambda v\\in V\\).\n\\end{itemize}\nIn other words, \\(V\\) is closed under addition and\nrescaling. Subspaces are the natural higher-dimensional\ngeneralisation of lines and planes through the origin in 3-d.\n\n\n\\end{Definition}\nSometimes you want to consider lines or planes which don't pass\nthrough the origin, in which case the following definition comes in\nhandy:\n\n\n\\begin{Definition}[Affine subspaces]\\label{dfn:affinesubspace}\nA subset \\(V\\subset\\RR^n\\) is called an {\\em affine subspace} if\nthere exists a vector \\(w\\in\\RR^n\\) and a linear subspace\n\\(V'\\subset\\RR^n\\) such that \\(V=\\{w+v\\ :\\ v\\in V'\\}\\). In other\nwords, \\(V\\) is obtained by translating \\(V'\\) by the vector \\(w\\).\n\n\n\\end{Definition}\n\\begin{Remark}\nA {\\em line} is a 1-dimensional subspace. A {\\em plane} is a\n2-dimensional subspace.\n\n\n\\end{Remark}\n\\begin{Definition}[Codimension]\\label{dfn:codimension}\nThe {\\em codimension} of a subspace \\(V\\subset\\RR^n\\) is \\(p\\) if\n\\(\\dim V=n-p\\).\n\n\n\\end{Definition}\n\\begin{Example}\nA line in \\(\\RR^3\\) has codimension 2. A plane in \\(\\RR^4\\) has\ncodimension 2, while a line in \\(\\RR^4\\) has codimension 3.\n\n\n\\end{Example}\n\\begin{Definition}\nA {\\em hyperplane} is a subspace of codimension 1. For example, a\nline in \\(\\RR^2\\), or a plane in \\(\\RR^3\\).\n\n\n\\end{Definition}\nSuppose someone asks you to give them a subspace of \\(\\RR^n\\). You can\nanswer them in one of two ways:\n\\begin{itemize}\n\\item You can write down equations for the subspace, for example you can\nsay something like:\n\\begin{itemize}\n\\item ``it's the line \\(x+y=0\\) in \\(\\RR^2\\)'',\n\\item ``it's the plane in \\(\\RR^3\\) cut out by the equation \\(z=0\\)''.\n\\end{itemize}\n\\item You can give them a collection of vectors which ``span'' the\nsubspace, for example you can say something like:\n\\begin{itemize}\n\\item ``it's the line through the origin pointing in the \\(\\ma 1 \\\\ -1\\mz\\)-direction''.\n\\item ``it's the plane in \\(\\RR^3\\) spanned by the vectors \\(\\ma 1 \\\\ 2 \\\\ 0\\mz\\) and \\(\\ma 1 \\\\ 0 \\\\ 1\\mz\\)''.\n\\end{itemize}\n\\end{itemize}\nWe'll focus on these two methods in order, then talk about how to\nrelate them.\n\n\n\\subsection{Equations for subspaces; kernel}\n\n\n\\begin{Example}\nA linear hyperplane is cut out by a single linear equation. More\nprecisely, a row vector \\(r=\\ma r_1 & \\cdots & r_n\\mz\\) defines a\nlinear hyperplane in \\(\\RR^n\\), namely: \\[\\left\\{x=\\ma x_1 \\\\ \\vdots \\\\\nx_n\\mz\\in\\RR^n\\ :\\ rx=0\\right\\}.\\] Equivalently, this is the\nhyperplane orthogonal to the column vector \\(r^T\\).\n\n\n\\end{Example}\n\\begin{Definition}\nGiven a linear subspace \\(V\\subset\\RR^n\\) and a vector \\(w\\), we\ndefine the {\\em translate} \\(w+V=\\{v+w\\in\\RR^n\\ :\\ v\\in V\\}\\) of\n\\(V\\) by \\(w\\) to be the affine subspace obtained by translating the\nelements of \\(V\\) along the vector \\(w\\).\n\n\n\\end{Definition}\n\\begin{Example}\nA row vector \\(r=\\ma r_1 & \\cdots & r_n\\mz\\) together with a number\n\\(b\\) defines an {\\em affine hyperplane} in \\(\\RR^n\\), namely:\n\\[\\left\\{x=\\ma x_1\\\\ \\vdots\\\\ x_n\\mz\\in\\RR^n\\ :\\ rx=b\\right\\}.\\]\nEquivalently, this is the hyperplane orthogonal to \\(r^T\\)\ntranslated by \\(\\frac{br^T}{|r|^2}\\), i.e. translated a certain\namount in the \\(r^T\\) direction. Note that this is a linear subspace\nif and only if \\(b=0\\).\n\n\n\\end{Example}\n\\begin{Example}\nAn \\(m\\)-by-\\(n\\) matrix \\(A\\) define \\(m\\) linear hyperplanes, cut\nout by the equations\n\\begin{align*}\nA_{11}x_1+\\cdots+A_{1n}x_n&=0\\\\\n\\vdots\\qquad\\qquad\\vdots\\qquad\\qquad&\\vdots\\\\\nA_{m1}x_1+\\cdots+A_{mn}x_n&=0.\n\\end{align*}\nA {\\em solution} \\(v=\\ma x_1 \\\\ \\vdots \\\\ x_n\\mz\\) to this system of\nequations is then a vector \\(v\\in\\RR^n\\) satisfying \\(Av=0\\); in\nother words a vector \\(v\\) which belongs to all \\(m\\) of the\nhyperplanes; in other words a point where the hyperplanes intersect.\n\n\n\\end{Example}\n\\begin{Definition}\nThere is a fancy name for the linear subspace given by\n\\(\\{v\\in\\RR^n\\ :\\ Av=0\\}\\). It is called the kernel of \\(A\\),\nwritten \\(\\ker(A)\\).\n\n\n\\end{Definition}\n\\begin{Example}\nAn \\(m\\)-by-\\(n\\) matrix \\(A\\) and a vector \\(b\\in\\RR^m\\) define\n\\(m\\) affine hyperplanes, cut out by the equations\n\\begin{align*}\nA_{11}x_1+\\cdots+A_{1n}x_n&=b_1\\\\\n\\vdots\\qquad\\qquad\\vdots\\qquad\\qquad&\\vdots\\\\\nA_{m1}x_1+\\cdots+A_{mn}x_n&=b_m.\n\\end{align*}\nThe set of solutions to \\(Av=b\\) is the intersection of these affine\nhyperplanes.\n\n\n\\end{Example}\n\\begin{Example}\\label{exm:threelines1}\nConsider the matrix \\(A=\\ma 1 & 1 \\\\ 1 & -1 \\\\ 0 & 1\\mz\\) and the\nvector \\(b=\\ma 1 \\\\ 1 \\\\ 1\\mz\\). The equations \\(Av=b\\) define three\n{\\em lines} (hyperplanes in \\(\\RR^2\\)):\n\\[x+y=1,\\quad x-y=1,\\quad y=1\\]\ndrawn red, purple and blue respectively in the diagram below.\n\n\n\\tka\n\\draw[->] (-2,0) -- (3,0) node [right] {\\(x\\)};\n\\draw[->] (0,-2) -- (0,2) node [above] {\\(y\\)};\n\\draw[red,thick] (-1,2) -- (2,-1) node [right] {\\(x+y=1\\)};\n\\draw[purple,thick] (-1,-2) -- (3,2) node [above] {\\(x-y=1\\)};\n\\draw[blue,thick] (-2,1) -- (3,1) node [right] {\\(y=1\\)};\n\\tkz\n\n\nSince the lines don't have a common intersection, we know the system\nof equations has no solutions (the lines intersect in pairs, so any\ntwo of the equations admit a solution, but there is no one point\ncontained in all three lines).\n\n\n\\end{Example}\nWe see that the intuition that an overdetermined system (more\nhyperplanes than dimensions) has no solutions is justified, because\nyou need your \\(n+1\\) hyperplanes in \\(\\RR^n\\) to be in very special\nposition to make them have a common intersection. Nonetheless, it can\nhappen.\n\n\n\\begin{Example}\\label{exm:threelines2}\nLet \\(A\\) be as before but \\(b=\\ma 3 \\\\ 1 \\\\ 1\\mz\\). This has the\neffect of translating one of the lines from \\cref{exm:threelines1}\nso that it becomes \\(x+y=3\\). As we see below, these lines below\nhave a common intersection at \\(\\ma 2 \\\\ 1\\mz\\), so the\noverdetermined system has a solution \\(x=2\\), \\(y=1\\) (marked with a\ndot below).\n\n\n\\tka\n\\draw[->] (-2,0) -- (3,0) node [right] {\\(x\\)};\n\\draw[->] (0,-2) -- (0,2) node [above] {\\(y\\)};\n\\draw[red,thick] (1,2) -- (4,-1) node [right] {\\(x+y=3\\)};\n\\draw[purple,thick] (-1,-2) -- (3,2) node [above] {\\(x-y=1\\)};\n\\draw[blue,thick] (-2,1) -- (3,1) node [right] {\\(y=1\\)};\n\\node at (2,1) {\\(\\bullet\\)};\n\\tkz\n\n\n\\end{Example}\n\\begin{Remark}\nGiven a subspace \\(V\\subset\\RR^n\\) of dimension \\(n-p\\) (codimension\n\\(p\\)) and a subspace \\(W\\subset\\RR^n\\) of dimension \\(n-q\\)\n(codimension \\(q\\)), we ``expect'' the intersection \\(V\\cap W\\) to\nhave dimension \\(n-p-q\\) (codimension \\(p+q\\)). In other words,\ncodimension is {\\em usually} additive under intersection. For\nexample, in \\(\\RR^3\\), a plane (codimension 1) and a line\n(codimension 2) will usually intersect at a point (codimension 3),\nunless you're in the exceptional situation that the line is\ncontained inside the plane. As a corollary of this, we {\\em expect}\nthe space of solutions to a system of \\(m\\) equations in \\(n\\)\nunknowns to be \\(n-m\\) (each equation cuts down the set of solutions\nby one dimension)...except when it isn't!\n\n\n\\end{Remark}\nHaving made this remark, let us give a more precise characterisation\nof the dimension of the space of solutions.\n\n\n\\begin{Theorem}\nLet \\(A\\) be an \\(m\\)-by-\\(n\\) matrix and \\(b\\in\\RR^m\\) be a\nvector. Suppose that \\(\\ker(A)\\) has dimension \\(k\\) (this number is\ncalled the {\\em nullity} of \\(A\\)). Then, the dimension of the space\nof solutions to \\(Av=b\\), assuming it is nonempty, is equal to\n\\(k\\). Indeed, the space of solutions is a translate of \\(\\ker(A)\\).\n\\end{Theorem}\n\\begin{Proof}\nIf \\(v_1,v_2\\) are solutions to \\(Av=b\\) then \\(A(v_1-v_2)=b-b=0\\),\nso the difference \\(v_1-v_2\\) is in the kernel of \\(A\\). Similarly,\nif \\(Av_1=b\\) and \\(Av=0\\) then \\(A(v_1+v)=b+0=b\\), so adding\nelements of the kernel to a solution gives another\nsolution. Therefore, if we fix one solution \\(v_1\\), the space of\nsolutions is \\(v_1+\\ker(A)=\\{v_1+v\\ :\\ v\\in\\ker(A)\\}\\), i.e. a\ntranslate of \\(\\ker(A)\\). \\qedhere\n\n\n\\end{Proof}\n\\begin{Theorem}\\label{thm:nullity}\nGiven a matrix \\(A\\), its nullity is equal to the number of free\nindices once \\(A\\) has been put into reduced echelon form.\n\\end{Theorem}\n\\begin{Proof}\nWe saw that the general solution to \\(Av=b\\) has one parameter for\neach free index. Therefore it is a space with dimension equal to the\nnumber of free indices. \\qedhere\n\n\n\\end{Proof}\n\\clearpage\n\\section{Subspaces II}\n\\subsection{Spanning sets for subspaces}\n\n\n\\begin{Definition}\nGiven a collection of vectors \\(v_1,\\ldots,v_k\\), a {\\em linear\ncombination} of these vectors is an expression of the form\n\\[v=\\lambda_1v_1+\\cdots+\\lambda_k v_k\\] for some choice of\ncoefficients \\(\\lambda_1,\\ldots,\\lambda_k\\). We define the {\\em\nlinear subspace spanned by} \\(v_1,\\ldots,v_k\\) (or the span of\n\\(v_1,\\ldots,v_k\\), written \\(\\mathrm{span}(v_1,\\ldots,v_k)\\)) to be\nthe set of all linear combinations of \\(v_1,\\ldots,v_k\\).\n\n\n\\end{Definition}\n\\begin{Lemma}\nFor any collection of vectors \\(v_1,\\ldots,v_k\\in\\RR^n\\), the set\n\\(\\mathrm{span}(v_1,\\ldots,v_k)\\) is a linear subspace of \\(\\RR^n\\).\n\\end{Lemma}\n\\begin{Proof}\nIf we rescale a linear combination \\(\\sum_i\\lambda_iv_i\\) by \\(\\mu\\)\nthen we get the linear combination \\(\\sum_i(\\mu\\lambda_i)v_i\\). If\nwe add two linear combinations \\(\\sum_i\\lambda_iv_i\\) and\n\\(\\sum_i\\mu_iv_i\\) then we get the linear combination\n\\(\\sum_i(\\lambda_i+\\mu_i)v_i\\). Therefore linear combinations form a\nlinear subspace. \\qedhere\n\n\n\\end{Proof}\n\\begin{Example}\nThe set of all linear combinations of \\(v_1\\) is just the set of all\nvectors \\(\\lambda_1 v_1\\), \\(\\lambda_1\\in\\RR\\). In other words, it's\nthe set of all rescalings of \\(v_1\\), otherwise known as the line\nthat points in the \\(v_1\\)-direction.\n\n\n\\end{Example}\n\\begin{Example}\nLet \\(v_1=\\ma 1 \\\\ 0 \\\\ 0 \\mz\\) and \\(v_2=\\ma 0 \\\\ 1 \\\\ 0\\mz\\). The\nsubspace spanned by \\(v_1,v_2\\) is the set of all vectors\n\\(\\lambda_1v_1+\\lambda_2v_2=\\ma \\lambda_1 \\\\ \\lambda_2 \\\\ 0\\mz\\), in\nother words, it is the \\(xy\\)-plane.\n\n\n\\end{Example}\n\\begin{Example}\nThe plane spanned by \\(v_1=\\ma 1 \\\\ 0 \\\\ 0 \\mz\\), \\(v_2=\\ma 0 \\\\ 1 \\\\ 0\\mz\\)\nand \\(v_3=\\ma 1 \\\\ 1 \\\\ 0\\mz\\) is {\\em also} the \\(xy\\)-plane, because\nadding multiples of \\(v_3\\) doesn't take you out of this plane. The\nissue here is that \\(v_3\\) is itself a linear combination of \\(v_1\\)\nand \\(v_2\\) (\\(v_3=v_1+v_2\\)) so it doesn't change the spanning set.\n\n\n\\end{Example}\n\\begin{Definition}\nA spanning set is called a {\\em basis} if it has minimal size.\n\n\n\\end{Definition}\n\\begin{Theorem}\nAll bases for the same subspace have the same size. This size is\ncalled the dimension of the subspace. (I haven't actually given you\na formal definition of dimension until now).\n\\end{Theorem}\n\\begin{Proof}\nThis will be proved in your next course on linear algebra, next\nyear. \\qedhere\n\n\n\\end{Proof}\n\\subsection{Image of a matrix}\n\n\n\\begin{Definition}\nThe {\\em image} of an \\(m\\)-by-\\(n\\) matrix \\(A\\) is the set of all\n\\(b\\in\\RR^m\\) such that \\(Av=b\\) has a solution \\(v\\in\\RR^n\\).\n\n\n\\end{Definition}\n\\begin{Lemma}\nThe image of \\(A\\) is spanned by the columns of \\(A\\).\n\\end{Lemma}\n\\begin{Proof}\nIf the columns of \\(A\\) are \\(a_1,\\ldots,a_n\\in\\RR^m\\) then \\[A\\ma\nx_1 \\\\ \\vdots \\\\ x_n\\mz=x_1a_1+\\cdots+x_na_n,\\] so the image of\n\\(A\\) is the set of linear combinations of the columns, as\nrequired. \\qedhere\n\n\n\\end{Proof}\n\\begin{Example}\nIf \\(A=\\ma 1 & 1 \\\\ 2 & 0 \\\\ 0 & 1\\mz\\) then the image of \\(A\\) is\nthe plane spanned by \\(\\ma 1 \\\\ 2 \\\\ 0\\mz\\) and \\(\\ma 1 \\\\ 0\n\\\\ 1\\mz\\) (see \\cref{exm:3by2}).\n\n\n\\end{Example}\n\\begin{Definition}\nThe {\\em rank} of \\(A\\) is defined to be the dimension of the\nimage.\n\n\n\\end{Definition}\n\\begin{Theorem}\\label{thm:rank}\nThe rank of \\(A\\) is equal to the number of leading indices when\n\\(A\\) is put into reduced echelon form.\n\\end{Theorem}\n\\begin{Proof}\nFirst note that row operations do not change the rank: if \\(A\\) and\n\\(A'\\) are related by a row operation then \\(A'=EA\\) for some\nelementary matrix \\(E\\), and now the map \\(b\\mapsto Eb\\) gives an\nisomorphism between the image of \\(A\\) and the image of \\(A'\\)\n(isomorphism in the sense that \\(E\\) is an invertible linear\nmap). Therefore we may assume that \\(A\\) is in reduced echelon form\nby \\cref{thm:reducedechelonform}.\n\n\nSo suppose that \\(A\\) is in reduced echelon form with the first\n\\(k\\) rows nonzero (so that \\(k\\) equals the number of leading\nindices). The equation \\(Av=b\\) has a solution if and only if\n\\(b_{k+1}=\\cdots=b_m=0\\), so the image of \\(A\\) is equal to the\nsubspace spanned by the first \\(k\\) basis vectors, which has\ndimension \\(k\\). \\qedhere\n\n\n\\end{Proof}\nHere is a useful theorem relating the rank and the nullity of an\n\\(m\\)-by-\\(n\\) matrix:\n\n\n\\begin{Theorem}[Rank-nullity theorem]\\label{thm:ranknullity}\nIf \\(A\\) is an \\(m\\)-by-\\(n\\) matrix, the rank and the nullity of\n\\(A\\) sum to \\(n\\).\n\\end{Theorem}\n\\begin{Proof}\nIn reduced echelon form, the number of leading indices and free\nindices sum to \\(n\\) (number of columns), so this follows from\n\\cref{thm:nullity} and \\cref{thm:rank}. \\qedhere\n\n\n\\end{Proof}\n\\subsection{Kernel, image and simultaneous equations}\n\n\nTo relate this to what we said about simultaneous equations, we can\nsummarise everything we've said as follows:\n\n\n\\begin{Theorem}\nLet \\(A\\) be an \\(m\\)-by-\\(n\\) matrix and \\(b\\in\\RR^m\\) be a\nvector. Then \\(Av=b\\) has a solution if and only if\n\\(b\\in\\mathrm{im}(A)\\). If \\(Av=b\\) has a solution then the space of\nsolutions is a translate of \\(\\ker(A)\\).\n\n\n\\end{Theorem}\nThe following diagram may help you to remember whereabouts the kernel\nand image of an \\(m\\)-by-\\(n\\) matrix \\(A\\) live:\n\n\n\\tka\n\\node (A) at (0,0) {\\(\\RR^n\\)};\n\\node (B) at (2,0) {\\(\\RR^m\\)};\n\\node at (0,-1) {\\(\\ker(A)\\)};\n\\node at (2,-1) {\\(\\mathrm{im}(A)\\)};\n\\draw[thick,->] (A) -- (B) node [midway,above] {\\(A\\)};\n\\node[rotate=90] at (0,-1/2) {\\(\\subseteq\\)};\n\\node[rotate=90] at (2,-1/2) {\\(\\subseteq\\)};\n\\tkz\n\n\n\\clearpage\n\\section{Linear maps}\n\n\nThis lecture is intended as a foretaste of things to come. We\nintroduce an extra layer of abstraction, which suddenly elevates us\nabove the clouds and we see how to apply linear algebra in contexts we\nhad not formerly imagined.\n\n\n\\subsection{Linearity}\n\n\nWe defined a linear map \\(\\RR^n\\to\\RR^m\\) to be a map of the form\n\\(v\\mapsto Av\\) where \\(A\\) is an \\(m\\)-by-\\(n\\) matrix. There is a\ndifferent way to characterise linear maps, which we now discuss.\n\n\n\\begin{Definition}\nAn (\\(\\RR\\)-)vector space\\footnote{You can replace \\(\\RR\\) by any\nfield \\(k\\) (like \\(\\QQ\\) or \\(\\CC\\)) in this definition and get a\n\\(k\\)-vector space. Usually we just omit the field from the notation\nand call it a {\\em vector space}.} is a set \\(V\\) together with:\n\\begin{itemize}\n\\item a map \\(V\\times V\\to V\\), written \\((v,w)\\mapsto v+w\\),\n\\item a map \\(\\RR\\times V\\to V\\), written \\((\\lambda,v)\\mapsto \\lambda\nv\\),\n\\item an element \\(0\\in V\\),\n\\end{itemize}\nsuch that:\n\\begin{align*}\nu+(v+w)&=(u+v)+w& v+w&=w+v\\\\\nv&=0+v=v+0,&v+(-v)&=0\\\\\n1v&=v&\\lambda(\\mu v)&=(\\lambda\\mu)v\\\\\n(\\lambda+\\mu)v&=\\lambda v+\\mu v&\\lambda(v+w)&=\\lambda v+\\lambda w\\\\\n\\end{align*}\nfor all \\(u,v,w\\in V\\) and \\(\\lambda,\\mu\\in\\RR\\).\n\n\n\\end{Definition}\nFor example, \\(\\RR^n\\) equipped with the usual addition and rescaling\naction of \\(\\RR\\) is a vector space.\n\n\n\\begin{Definition}\nLet \\(V,W\\) be vector spaces. A map \\(T\\colon V\\to W\\) is called\n{\\em linear}\\footnote{Again, if we're working with \\(k\\)-vector\nspaces (e.g \\(k=\\QQ,\\CC\\)) then you need to talk about \\(k\\)-linear\nmaps and replace \\(\\RR\\) with \\(k\\) everywhere in this definition.}\nif the following conditions are satisfied:\n\\begin{itemize}\n\\item for all \\(v,w\\in\\RR^n\\) and we have \\(T(v+w)=T(v)+T(w)\\).\n\\item for all \\(\\lambda\\in\\RR\\) and \\(v\\in\\RR^n\\), we have \\(T(\\lambda\nv)=\\lambda T(v)\\).\n\n\n\\end{itemize}\n\\end{Definition}\n\\begin{Theorem}\nIf \\(T\\colon\\RR^n\\to\\RR^m\\) is linear then there exists an\n\\(n\\)-by-\\(m\\) matrix \\(A\\) such that \\(T(v)=Av\\) for all\n\\(v\\in\\RR^n\\). Conversely, if \\(A\\) is an \\(m\\)-by-\\(n\\) matrix then\na map \\(\\RR^n\\to\\RR^m\\) of the form \\(v\\mapsto Av\\) is linear.\n\\end{Theorem}\n\\begin{Proof}\nIf \\(T\\) is linear then it is determined by its values on the basis\nvectors \\(e_1,\\ldots,e_n\\). To see this, observe that if \\(v=\\ma\nv_1\\\\ \\vdots\\\\ v_n\\mz=\\sum_{i=1}^nv_ie_i\\) then\n\\(T(v)=T(\\sum_{i=1}^nv_ie_i)=\\sum_{i=1}^nv_iT(e_i)\\) by linearity,\nso the vectors \\(T(e_1),\\ldots,T(e_n)\\) determine \\(T\\)\ncompletely. If we pick \\(A\\) to be the matrix whose columns are\n\\(T(e_1),\\ldots,T(e_n)\\) then \\(Av=\\sum_{i=1}^nv_iT(e_i)=T(v)\\), so\nthe matrix we were looking for exists (and is uniquely specified by\n\\(T\\)).\n\n\nConversely, if \\(A\\) is a matrix then the identity \\(A(v+w)=Av+Aw\\)\nis just the distributivity of matrix multiplication and \\(A(\\lambda\nv)=\\lambda Av\\) is easy to check. \\qedhere\n\n\n\\end{Proof}\nIn fact, one can prove that any finite-dimensional vector space \\(V\\) is\nisomorphic to \\(\\RR^n\\) for some \\(n\\). (Isomorphic here means that\nthere is an invertible linear map \\(V\\to\\RR^n\\); finite-dimensional\nmeans that there is a finite spanning set). However, there's nothing\nto stop you using {\\em infinite-dimensional} vector spaces, and then\nthings get interesting.\n\n\n\\begin{Example}\nThe space of continuous functions \\(f\\colon\\RR\\to\\RR\\) is a vector\nspace, usually called \\(\\mathcal{C}^0(\\RR)\\). You can add two\nfunctions \\((f+g)(x)=f(x)+g(x)\\) and you can rescale a function\n\\((\\lambda f)(x)=\\lambda f(x)\\) and these operations satisfy the\nconditions required of a vector space (the zero function is\n\\(f(x)=0\\)).\n\n\n\\end{Example}\n\\begin{Example}\nThe space of once-continuously-differentiable functions is a\nsubspace of \\(\\mathcal{C}^0(\\RR)\\), usually written\n\\(\\mathcal{C}^1(\\RR)\\subset\\mathcal{C}^0(\\RR)\\).\n\n\n\\end{Example}\n\\begin{Example}\nDifferentiation defines a linear map\n\\(\\frac{d}{dx}\\colon\\mathcal{C}^1(\\RR)\\to\\mathcal{C}^0(\\RR)\\). It is\nlinear because\n\\[\\frac{d}{dx}(f+g)(x)=\\frac{df}{dx}(x)+\\frac{dg}{dx}(x),\\qquad\\frac{d}{dx}(\\lambda\nf)(x)=\\lambda\\frac{df}{dx}(x).\\]\n\n\n\\end{Example}\nCan we write a matrix for differentiation? We need to pick a basis for\n\\(\\mathcal{C}^1(\\RR)\\), which is a highly nontrivial task. Let's be a\nlittle less ambitious and restrict to the subspace of {\\em analytic\nfunctions}, i.e. functions \\(f\\) whose Taylor series converges to\n\\(f\\). This is usually written \\(\\mathcal{C}^{\\omega}(\\RR)\\). The\nfunctions \\(f_n(x)=x^n\\), \\(n=0,1,2,\\ldots\\), form a {\\em Schauder\nbasis} for this space, which means that any function\n\\(f\\in\\mathcal{C}^{\\omega}(\\RR)\\) can be written as an infinite sum of\nthese functions (namely its Taylor series!). In other words, we are\nthinking of the coefficients of the Taylor expansion as coordinates on\nthe space \\(\\mathcal{C}^{\\omega}(\\RR)\\). That is, a function \\(f\\) can\nbe thought of as an infinite vector \\(\\ma f(0) \\\\ \\frac{df}{dx}(0)\n\\\\ \\frac{1}{2}\\frac{d^2f}{dx^2}(0)\n\\\\ \\frac{1}{3!}\\frac{d^3f}{dx^3}(0)\\\\\\vdots\\mz\\).\n\n\nIf \\(f(x)=\\sum_{n\\geq 0}a_nx^n\\) then \\(\\frac{df}{dx}=\\sum_{n\\geq 1}\nna_nx^{n-1}=\\sum_{n\\geq 0}(n+1)a_{n+1}x^n\\), so our ``matrix'' for\ndifferentiation is\n\\[\\ma 0 & 1 & 0 & 0 & \\cdots \\\\ 0 & 0 & 2 & 0 & \\cdots \\\\0 & 0 & 0 & 3 &\n\\\\ \\vdots & \\vdots & \\vdots & & &\\mz\\ma a_0 \\\\ a_1 \\\\ a_2\n\\\\ \\vdots\\mz=\\ma a_1 \\\\ 2a_2 \\\\ 3a_3\\\\\\vdots\\mz.\\]\nIf one restricts instead to {\\em periodic functions}\n\\(f(x+2\\pi)=f(x)\\) then there is an alternative basis, coming from the\nfunctions \\(\\sin(nx),\\cos(nx)\\). The expansion of a function in terms\nof this basis is called its Fourier expansion, and again\ndifferentiation of a function can be thought of as a linear\ntransformation of its Fourier series. This leads to the powerful\nmethod of {\\em Fourier transform}, which allows you to convert\ndifferential equations into much simpler linear equations.\n\n\n\\begin{Example}\nWhat is the kernel of differentiation? It is the set of functions\nwhose derivative is identically zero, in other words, the constant\nfunctions. What is the inverse of differentiation? Well, because\nthere is a kernel it has no inverse, strictly speaking, but clearly\nintegration should define an inverse in some sense. This is why it\ndoesn't make sense to say ``the integral of \\(f\\)'' unless you also\nsay ``plus an unknown constant''.\n\n\n\\end{Example}\n\\begin{Example}\nConsider the linear map\n\\(\\frac{d}{dx}\\colon\\mathcal{C}^{\\omega}(\\RR)\\to\\mathcal{C}^{\\omega}(\\RR)\\). What\nare the eigenvalues and eigenvectors of this map? A\n\\(\\lambda\\)-eigenvector will be a function \\(f\\) which solves the\nequation \\[\\frac{df}{dx}=\\lambda f.\\] We can solve this by dividing\nthrough by \\(f\\) and integrating: \\[\\ln\nf=\\int\\frac{df}{f}=\\int\\lambda dx=\\lambda x+c,\\]\ni.e. \\(f=Ce^{\\lambda x}\\). So the \\(\\lambda\\)-eigenline is spanned\nby \\(f(x)=e^{\\lambda x}\\) and every \\(\\lambda\\in\\RR\\) arises as an\neigenvalue.\n\n\n\\end{Example}\n\\begin{Example}\nSimilarly, \\(\\cos(x\\sqrt{-\\lambda})\\) and \\(\\sin(x\\sqrt{-\\lambda})\\)\nare \\(\\lambda\\)-eigenvectors for \\(\\frac{d^2}{dx^2}\\), that is they\nsolve the differential equation\n\\[\\frac{d^2f}{dx^2}=\\lambda f.\\]\n\n\n\\end{Example}\nWe often say ``eigenfunction'' rather than eigenvector in this\ncontext. Finding eigenfunctions and eigenvalues of differential\noperators is an incredibly important problem; essentially all of\nquantum mechanics boils down to solving this problem for particular\noperators.\n\\end{document}\n", "meta": {"hexsha": "80f02b12d2b41b0739e3b218f2fc09030a970360", "size": 128239, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "static/stat671/sheet/la.tex", "max_stars_repo_name": "UrbanStudy/stat2019_website", "max_stars_repo_head_hexsha": "9d41d5caf4ece4c62bf0c301eb8c90429b17ce7d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-29T12:51:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-29T12:51:19.000Z", "max_issues_repo_path": "static/stat671/sheet/la.tex", "max_issues_repo_name": "UrbanStudy/stat2019_website", "max_issues_repo_head_hexsha": "9d41d5caf4ece4c62bf0c301eb8c90429b17ce7d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "static/stat671/sheet/la.tex", "max_forks_repo_name": "UrbanStudy/stat2019_website", "max_forks_repo_head_hexsha": "9d41d5caf4ece4c62bf0c301eb8c90429b17ce7d", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.4639205375, "max_line_length": 218, "alphanum_fraction": 0.6324363103, "num_tokens": 49979, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727027, "lm_q2_score": 0.8499711832583695, "lm_q1q2_score": 0.7190266812025948}}
{"text": "\\section{Applications of Riemann-Hurwitz}\r\n\\subsection{Immediate Consequences}\r\nWe can rearrange Riemann-Hurwitz to\r\n$$2g_R-2=n(2g_S-2)+\\sum_{p\\in R}(m_f(p)-1)$$\r\nwhere $g_R,g_S$ are the genera of $R,S$ respectively and $n$ is the degree of $f$.\r\nWe can use it to calculate genera of Riemann surfaces.\r\n\\begin{example}\r\n    Consider the compactification $\\hat{R}$ of the Riemann surface associated with $w=\\sqrt{z^3-z}$ equipped with a meromorphic function $\\hat{\\pi}:\\hat{R}\\to\\mathbb C_\\infty$.\r\n    We shall calculate the genus of $\\hat{R}$ by Riemann-Hurwitz.\r\n    Take $f=\\hat\\pi$, then $n=\\deg\\hat\\pi=2$ by valency theorem.\r\n    The branch points are $0,\\pm 1,\\infty$ and each of them has exactly $1$ preimage (branch points like this are called ``totally ramified''), hence has multiplicity $2$.\r\n    Plugging these information into Riemann-Hurwitz yields\r\n    $$2g_{\\hat{R}}-2=2(0-2)+4(2-1)\\implies g_{\\hat{R}}=1$$\r\n    which is consistent with the fact that $\\hat{R}$ is topologically a torus.\r\n\\end{example}\r\n\\begin{remark}\r\n    The correction term $\\sum_{p\\in R}(m_f(p)-1)$ is always even.\r\n    This is obvious but quite useful from time to time.\r\n    We obtained our compact Riemann surface in the above example from gluing $\\hat{R}=R_1\\cup_\\Phi R_2$.\r\n    Imagine we know nothing about $\\hat\\pi^{-1}(\\{\\infty\\})\\subset R_2$ and write the correction term as\r\n    $$3(2-1)+\\sum_{p\\in\\hat\\pi^{-1}(\\infty)}(m_{\\hat\\pi}(p)-1)=3+C,C=\\sum_{p\\in\\hat\\pi^{-1}(\\infty)}(m_{\\hat\\pi}(p)-1)$$\r\n    If $\\infty$ is not a ramification point, then $C=0$, which gives an odd correction point which is impossible.\r\n    Therefore it has to be the case that $\\infty$ is a ramification point (which has to be totally ramified) and $C=1$.\r\n    Therefore we can go directly from there to obtain $g_{\\hat{R}}=1$.\r\n    Hence, when $\\deg f=2$, then we can obtain the branching at $\\infty$ for free from this parity argument.\r\n\\end{remark}\r\n\\begin{remark}\r\n    In the case when $f$ is a covering map (aka unramified), then the correction term vanished, therefore $g_R-1=n(g_S-1)$.\r\n    There are three cases:\\\\\r\n    (i) If $g_S=0$, then $g_R-1<0$, which means actually $g_R=0,n=1$.\r\n    But degree $1$ maps have to be conformal equivalences, therefore $R\\cong S$.\r\n    Also genus $0$ surfaces are simply the Riemann sphere, so $f$ is just a M\\\"obius transformation.\\\\\r\n    (ii) If $g_S=1$, then necessarily $g_R=1$, but then $n$ is not restricted.\\\\\r\n    (iii) If $g_S>1$, then either $g_R=g_S$ and $n=1$ (in which case $f$ is a conformal equivalence) or $g_R>g_S$ and $n>1$.\r\n\\end{remark}\r\n\\begin{example}\r\n    Consider the family of lattices $\\Lambda_n=\\langle n,i\\rangle\\le\\mathbb C$ for $n\\in\\mathbb Z_{>0}$.\r\n    Then $\\Lambda_n\\le \\lambda_1$ for all $n$ which induces a covering map $\\mathbb C/\\Lambda_n\\to\\mathbb C/\\Lambda_1$ which has degree $n$.\r\n    Therefore when $g_S=1$ there is truly no restriction on the degree of $f$.\r\n\\end{example}", "meta": {"hexsha": "7e3b97e3595d9dd220f7cc3bddbb0f033a4838ae", "size": 2933, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "12/direct.tex", "max_stars_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_stars_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "12/direct.tex", "max_issues_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_issues_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "12/direct.tex", "max_forks_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_forks_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.325, "max_line_length": 177, "alphanum_fraction": 0.6808728265, "num_tokens": 970, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727027, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7190266699503841}}
{"text": "%!TEX root = TTK4150-Summary.tex\n\\section{Seconds-order systems}\n\\begin{equation}\\label{eq:autonomous}\n\t\\dot{x} = f(x), \\quad x \\in \\mathbb{R}^2\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Behaviour near equilibria}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nLinearise and find eigenvalues at each equilibrium:\n\\begin{itemize}\n\t\\item Real $\\lambda$\n\t\\begin{itemize}\n\t\t\\item $\\lambda_1 < \\lambda_2 < 0 \\implies$ Stable node.\n\t\t\\item $0 < \\lambda_1 < \\lambda_2 \\implies$ Unstable node.\n\t\t\\item $\\lambda_1 < 0 < \\lambda_2 \\implies$ Saddle point.\n\t\\end{itemize}\n\t\\item Complex $\\lambda_{1,2} = \\alpha \\pm \\beta \\imath$\n\t\\begin{itemize}\n\t\t\\item $\\alpha = 0 \\implies$ Center.\n\t\t\\item $\\alpha < 0 \\implies$ Stable focus.\n\t\t\\item $\\alpha > 0 \\implies$ Unstable focus.\n\t\\end{itemize}\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Periodic orbits}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{Lemma 2.1 (Poincaré-Bendixson criterion)}\n\\begin{sloppypar}\n\tConsider \\eqref{eq:autonomous}. Let $M$ be a bounded, closed subset of the plane such that\n\\end{sloppypar}\n\\begin{itemize}\n\t\\item $M$ contains no equilibria, or \\emph{one} equilibrium for which the eigenvalues of the Jacobian has positive real parts,\n\t\\item All trajectories in $M$ stay in $M$.\n\\end{itemize}\nThen, $M$ contains a periodic orbit.\n\n\\paragraph{Lemma 2.2 (Bendixson (negative) criterion)}\nIf\n\\begin{equation}\n\t\\pd{f_1}{x_1} + \\pd{f_2}{x_2}\n\\end{equation}\nis not zero and does not change sign on a simply connected region $\\mathbb{D}$, then \\eqref{eq:autonomous} has no periodic orbits in $\\mathbb{D}$.\n\n\\paragraph{Corollary 2.1 (The index method)}\n\\begin{itemize}\n\t\\item Nodes, foci, and centers have index 1.\n\t\\item Saddle points have index -1.\n\\end{itemize}\nThe sum of indices of all equilibria within a periodic orbit is always 1.", "meta": {"hexsha": "45480b6c0946168d64c9563d7bc6dcbdc23f21f1", "size": 1802, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK4150 Nonlinear control systems/sec-second-order-systems.tex", "max_stars_repo_name": "jakoblover/ntnu-course-summaries", "max_stars_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-11T02:42:40.000Z", "max_issues_repo_path": "TTK4150 Nonlinear control systems/sec-second-order-systems.tex", "max_issues_repo_name": "jakoblover/ntnu-course-summaries", "max_issues_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TTK4150 Nonlinear control systems/sec-second-order-systems.tex", "max_forks_repo_name": "jakoblover/ntnu-course-summaries", "max_forks_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.3333333333, "max_line_length": 146, "alphanum_fraction": 0.6709211987, "num_tokens": 594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7189588132220978}}
{"text": "\\section{Financing, Part I}\n\n\\subsection*{Capital structure theory I}\n\n{\\bf Modigliani-Miller I aka MM-I} Theorem: Capital structure is irrelevant (under \"ideal conditions\").\n\n$CF_D + CF_D = CF_A \\implies PV(CF_D) + PV(CF_D) = PV(CF_A) \\implies D+E=A $.  A firm’s value is determined by the total cash flow on its assets.\nCapital structure only determines how total cash flow is split between debt\nand equity holders. Given its assets, capital structure won’t affect a firm’s total value.\n\n\\subsection*{WACC - weighted average cost of capital}\n$WACC=\\frac{D}{D+E}r_D + \\frac{E}{D+E}r_E = w_D r_D + w_E + r_E$\n\n\\subsection*{Leverage and financial risk}\n\n{\\bf MM-II}  $r_E = r_A + \\frac{D}{E} (r_A-r_D)$\n\nif CAPM holds then:  $\\beta_A =w_D \\beta_D + (1-w_D) \\beta_E \\implies \\beta_E = \\frac{1}{1-w_DD}\\beta_A$ or \\\\\n$\\beta_E = (1+\\frac{D}{E})\\beta_A$ if debt is risk-less. \\\\\nIf debt is not risk-less then $\\beta_E = \\beta_A +\\frac{D}{E}(\\beta_A-\\beta_D)$\n\n\n\\subsection*{Default premium and risk premium}\n\n{\\bf Promised YTM}: the yield if default does not occur.\n{\\bf Expected YTM}: the probability-weighted average of all possible yields.\n{\\bf Default premium}: the difference between promised yield and expected yield.\n{\\bf Risk premium}: the difference between the expected yield on a risky bond and the yield on a risk-free bond of similar maturity and coupon rate.\n\n\\usetikzlibrary{decorations.pathreplacing}\n\n\\begin{tikzpicture}[scale=0.5]\n\t%\\draw[thick] (-1,0) rectangle +(11,6);\n\t\\filldraw[thick, top color=white,bottom color=red!50!] (3.5,0.5) rectangle node{$r_f$} +(2,3);\n\t\\filldraw[top color=white,bottom color=blue!50!] (3.5,3.5) rectangle node{risk} +(2,1);\n\t\\filldraw[top color=white,bottom color=blue!50!] (3.5,4.5) rectangle node{default} +(2,1);\n\t\\draw [decorate,decoration={brace,amplitude=5pt},xshift=-4pt,yshift=0pt]\n\t(3.5,0.5) -- (3.5,3.5) node [black,midway,xshift=-1cm] \n\t{\\footnotesize risk-free rate};\n\t\\draw [decorate,decoration={brace,amplitude=5pt},xshift=-4pt,yshift=0pt]\n\t(3.5,3.5) -- (3.5,5.5) node [black,midway,xshift=-1cm] \n\t{\\footnotesize Yield Spread};\n\t\n\t\\draw [-latex, ,xshift=5pt, right](6,3.5)--(5.5,3.5) node [right, ,xshift=5pt] {\\footnotesize Default-free YTM};\n\t\\draw [-latex, ,xshift=5pt, right](6,4.5)--(5.5,4.5) node [right, ,xshift=5pt] {\\footnotesize Expected YTM};\n\t\\draw [-latex, ,xshift=5pt, right](6,5.5)--(5.5,5.5) node [right, ,xshift=5pt] {\\footnotesize Promised YTM};\n\\end{tikzpicture}\n\nGiven recovery rate of $RR$ and probability of default $PD$, expected yield $\\bar{y}$ and promised yield $y$, then: $1 + \\bar{y} = (1-PD)(1+y)+PD[(1-RR)(1+y)]$, solve for $y$ to know coupon to issue at par.", "meta": {"hexsha": "391d4a138748c5b14aebb607aca0a454d4863933", "size": 2649, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15.415.2x/assets/week_17.tex", "max_stars_repo_name": "j053g/cheatsheets", "max_stars_repo_head_hexsha": "22f7a84879c04d44de40467ddcc0f6e551b812c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-12-14T08:49:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T17:26:15.000Z", "max_issues_repo_path": "15.415.2x/assets/week_17.tex", "max_issues_repo_name": "j053g/cheatsheets", "max_issues_repo_head_hexsha": "22f7a84879c04d44de40467ddcc0f6e551b812c7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "15.415.2x/assets/week_17.tex", "max_forks_repo_name": "j053g/cheatsheets", "max_forks_repo_head_hexsha": "22f7a84879c04d44de40467ddcc0f6e551b812c7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.0612244898, "max_line_length": 206, "alphanum_fraction": 0.697999245, "num_tokens": 918, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528094861981, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.7189588102225932}}
{"text": "The goal of this chapter is to provide a comprehensive treatment of the most relevant\ngradient and subgradient methods for convex optimization. \nWe intend to cover\nthe most robust methods with the fewest assumptions first, and then later move to\nmethods which require more assumptions but have much better convergence rates.\n%Since we will be most interested in stochastic methods for machine learning, it\n%is the robust methods with few assumptions (but poor convergence rates) which will\n%be most relevant.\n\n\\section{Convex Lipschitz Functions}\nIn this section, we consider methods for optimizing convex, lipschitz functions. This is a very large function\nclass, since we make no assumptions on the objective other than assuming bounded subgradients (which is\nequivalent to the lipschitz property). In particular, we assume no smoothness, i.e. the objective need not\nbe differentiable, and no strong convexity.\n\nConsequently, the convergence results we obtain are rather weak. They require averaging the iterates of our method\n(or choosing the best one), i.e. we cannot simply take the last iterate, and the convergence rates obtained are\nquite slow. However, these methods are robust. In particular, they obtain the same convergence rate\nin the stochastic setting, as we will see.\n\nIn later sections we will detail precisely\nhow stronger assumptions on the objective yield better convergence results. We find it useful to\nbegin with the weakest assumptions and weakest convergence results first, and then to explain how everything relates to\nthese.\n\n\\subsection{Subgradient Descent}\nThe simplest version of subgradient descent (with a fixed step size) is the following iteration\n\\begin{equation}\\label{subgradient_descent}\n x_{n+1} = x_n - sg_n\n\\end{equation}\nwhere $g_n\\in \\partial f(x_n)$ (the subdifferential of a convex function $f$ to be optimized) and $s$ is the \nstep size.\n\nWith a fixed step size, this method will not converge for an arbitrary choice of subgradient $g_n$. \nHowever, if we are given a tolerance beforehand, we can choose\na small enough step size to obtain an appropriate objective error, as the following well-known result shows.\n\n\\begin{theorem}\\label{original_subgradient}\n Assume that $f$ is convex with bounded subgradient, meaning that $\\|g\\|_2 \\leq M$ for all $g\\in \\partial f(x)$ (for any point $x$).\n \n Additionally, let $x^*\\in \\arg\\min_x f(x)$ and assume that $\\|x_1 - x^*\\|_2 \\leq R$ (note: here we are implicitly assuming that\n $f$ is bounded below and achieves its minimum). \n \n Then, setting the step size $s = \\frac{R}{M\\sqrt{n}}$,\n the iterates of (\\ref{subgradient_descent}) satisfy\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{RM}{2\\sqrt{n}}\n \\end{equation}\n where $\\bar{x}_n = \\frac{1}{n}\\sum_{i = 1}^n x_i$ is the average of the first $n$ iterates, and\n \\begin{equation}\n  \\min_{i=1,...,n} f(x_i) - f(x^*) \\leq \\frac{RM}{2\\sqrt{n}}\n \\end{equation}\n\n\n\\end{theorem}\n\\begin{proof}\n Consider first $\\bar{x}_n = \\frac{1}{n}\\sum_{i = 1}^n x_i$, the average of the iterates encountered so\n far. By convexity and the definition of the subgradient, we have\n \\begin{equation}\\label{eqn11}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*))\\leq \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n \n  \\langle g_i, x_i - x^*\\rangle\n \\end{equation}\n From iteration (\\ref{subgradient_descent}), we see that $g_i = \\frac{1}{s}(x_i - x_{i+1})$. Plugging this into equation\n (\\ref{eqn11}), we obtain\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{1}{ns} \\displaystyle\\sum_{i = 1}^n \\langle x_i - x_{i+1}, x_i - x^*\\rangle\n \\end{equation}\n Setting $y_i = x_i - x^*$, this sum becomes\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^n \\langle y_i - y_{i+1}, y_i\\rangle = \\frac{1}{2}\\displaystyle\\sum_{i = 1}^n\n  \\left(\\|y_i\\|_2^2 - \\|y_{i+1}\\|_2^2 + \\|y_i - y_{i+1}\\|_2^2\\right)\n \\end{equation}\n This sum telescopes, and we get (noting that $y_i - y_{i+1} = x_i - x_{i+1}$)\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{1}{2ns}\\left(\\|y_1\\|_2^2 - \\|y_{n+1}\\|_2^2 + \\displaystyle\\sum_{i = 1}^n \\|x_i - x_{i+1}\\|_2^2\\right)\n \\end{equation}\n Using the iteration (\\ref{subgradient_descent}), we see (reversing our previous substitution) that\n $x_i - x_{i + 1} = sg_i$. Our assumption that the subgradient of $f$ is bounded implies that $\\|g_i\\|_2^2 \\leq M^2$,\n so that\n $$\\displaystyle\\sum_{i = 1}^n \\|x_i - x_{i+1}\\|_2^2 = \\displaystyle\\sum_{i = 1}^n \\|sg_i\\|_2^2 \\leq ns^2M^2\n $$\n and we obtain (dropping the negative $-\\|y_{n+1}\\|_2^2$)\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{1}{2}\\left(\\frac{\\|x_1 - x^*\\|_2^2}{ns} + M^2s\\right) \\leq \\frac{1}{2}\\left(\\frac{R^2}{ns} + M^2s\\right)\n \\end{equation}\n This bound is optimized when $s = \\frac{R}{M\\sqrt{n}}$ and we get\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{RM}{2\\sqrt{n}}\n \\end{equation}\n For the second part of the theorem, we simply note that the minimum is smaller than the average, i.e. that\n \\begin{equation}\n  \\min_{i = 1,...,n} f(x_i) - f(x^*) \\leq \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*))\n \\end{equation}\n and repeat the same argument.\n\n\\end{proof}\n\nIt is a bit of a nuisance to choose the step size based on the total number of iterations, since it means that\nwe need to specify the total number of iterations in advance. For various reasons, it may be desirable to have a \nmethod which we can run for\nan a priori unspecified number of steps.\n\nThis is possible if we allow ourselves a varying step size, i.e. an iteration\nof the form\n\\begin{equation}\\label{subgradient_descent_variable}\n x_{n+1} = x_n - s_ng_n\n\\end{equation}\nAs we show below, we can obtain the same convergence rate (up to logarithmic factors) without specifying the\nnumber of iterations in advance.\n\n\\begin{theorem}\\label{variable_subgradient_descent_thm}\n Assume that $f$ is convex with bounded subgradient, meaning that $\\|g\\|_2 \\leq M$ for all $g\\in \\partial f(x)$ (for any point $x$).\n \n Additionally, let $x^*\\in \\arg\\min_x f(x)$ and assume that $\\|x_1 - x^*\\|_2 \\leq R$. \n \n Then, setting the variable step size $s_i = \\frac{R}{M\\sqrt{i}}$,\n the iterates of (\\ref{subgradient_descent_variable}) satisfy\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{DM(\\log(n) + 1)}{2\\sqrt{n}}\n \\end{equation}\n where $\\bar{x}_n$ is the step size weighted average of the iterates, i.e.\n \\begin{equation}\n  \\bar{x}_n = \\left(\\displaystyle\\sum_{i = 1}^n s_i\\right)^{-1} \\displaystyle\\sum_{i=1}^n s_ix_i\n \\end{equation}\n Additionally, we get\n \\begin{equation}\n  \\min_{i=1,...,n} f(x_i) - f(x^*) \\leq \\frac{DM(\\log(n) + 1)}{2\\sqrt{n}}\n \\end{equation}\n\n\\end{theorem}\n\\begin{proof}\n We first consider the step size weighted average\n $$\\bar{x}_n = \\left(\\displaystyle\\sum_{i = 1}^n s_i\\right)^{-1} \\displaystyle\\sum_{i=1}^n s_ix_i\n $$\n and note that by the convexity of $f$ (Jensen's inequality)\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq D_n^{-1} \\displaystyle\\sum_{i=1}^n s_i(f(x_i) - f(x^*))\n \\end{equation}\n where we have written $D_n = \\sum_{i = 1}^n s_i$.\n \n The fact that $g_i\\in \\partial f(x_i)$ means that $f(x_i) - f(x^*) \\leq \\langle g_i, x_i - x^*\\rangle$ so that\n \\begin{equation}\\label{eq22}\n  f(\\bar{x}_n) - f(x^*) \\leq D_n^{-1} \\displaystyle\\sum_{i=1}^n s_i\\langle g_i, x_i - x^*\\rangle\n \\end{equation}\n From the iteration (\\ref{subgradient_descent_variable}) we have $s_ig_i = x_i - x_{i+1}$. Plugging this into\n (\\ref{eq22}) we get\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq D_n^{-1} \\displaystyle\\sum_{i=1}^n \\langle x_i - x_{i+1}, x_i - x^*\\rangle\n \\end{equation}\n The sum on the right hand side of this inequality can now be rewritten in the same way as in the proof of Theorem\n \\ref{original_subgradient}. The right hand side of the inequality becomes\n \\begin{equation}\n  \\frac{1}{2D_n}\\left(\\|x_1 - x^*\\|_2^2 - \\|x_{n+1} - x^*\\|_2^2 + \\displaystyle\\sum_{i=1}^n\\|x_i - x_{i+1}\\|_2^2\\right)\n \\end{equation}\n Dropping the negative term $-\\|x_{n+1} - x^*\\|_2^2$ we thus see that\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{1}{2D_n}\\left(\\|x_1 - x^*\\|_2^2 + \\displaystyle\\sum_{i=1}^n\\|x_i - x_{i+1}\\|_2^2\\right)\n \\end{equation}\n Using the iteration (\\ref{subgradient_descent_variable}), we undo our previous substitution to obtain\n $x_i - x_{i+1} = s_ig_i$. This, combined with the bound on the subgradients of $f$, i.e. $\\|g_i\\|_2 \\leq M$, implies\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{1}{2D_n}\\left(\\|x_1 - x^*\\|_2^2 + M^2\\displaystyle\\sum_{i=1}^n s_i^2\\right)\n \\end{equation}\n The assumption that $\\|x_1 - x^*\\|_2 \\leq D$ gives us\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{D^2 + M^2\\displaystyle\\sum_{i=1}^n s_i^2}{2\\displaystyle\\sum_{i=1}^n s_i}\n \\end{equation}\n This bound is optimized when $s_i = \\frac{D}{M\\sqrt{i}}$ and we obtain\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{DM\\displaystyle\\sum_{i=1}^n \\frac{1}{i}}{2\\displaystyle\\sum_{i=1}^n \\frac{1}{\\sqrt{i}}}\n \\end{equation}\n we now use the fact that $\\displaystyle\\sum_{i=1}^n \\frac{1}{i} \\leq \\log(n) + 1$ and $\\displaystyle\\sum_{i=1}^n \\frac{1}{\\sqrt{i}} \\geq \\sqrt{n}$\n to get\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{DM(\\log(n) + 1)}{2\\sqrt{n}}\n \\end{equation}\n This proves the first result. As in the proof of Theorem \\ref{original_subgradient}, we can use the fact that the minimum\n is bounded by the average to get\n \\begin{equation}\n  \\min_{i=1,...,n} f(x_i) - f(x^*) \\leq D_n^{-1} \\displaystyle\\sum_{i=1}^n s_i(f(x_i) - f(x^*))\n \\end{equation}\n and so (by the exact same logic)\n \\begin{equation}\n   \\min_{i=1,...,n} f(x_i) - f(x^*) \\leq \\frac{DM(\\log(n) + 1)}{2\\sqrt{n}}\n \\end{equation}\n which is the second inequality. This completes the proof.\n\n\\end{proof}\n\nWe note again that these results are fairly weak. Notably, the convergence rates are very slow and we must take an average of\nour iterates (or the minimum over the iterates) to obtain them. We will see later how stronger assumptions\non the function $f$ to be optimized result in better convergence results. \n\n\\subsection{Stochastic Subgradient Descent}\n\nA beneficial consequence of the weak assumptions we have made is that these results are very robust. \nMost notably, they remain true\nif we replace the subgradient elements $g_n$ in iterations (\\ref{subgradient_descent}) and (\\ref{subgradient_descent_variable})\nby unbiased samples of an element of the subgradient, i.e. we consider\n\\begin{equation}\\label{random_subgradient_descent}\n x_{n+1} = x_n - sg(x_n,\\xi_n)\n\\end{equation}\nand\n\\begin{equation}\\label{random_subgradient_descent_variable}\n x_{n+1} = x_n - s_ng(x_n,\\xi_n)\n\\end{equation}\nwhere the $\\xi_n$ are independent random variables underlying the sampling process and the samples \n$g(x_n,\\xi_n)$ satisfy $\\mathbb{E}_{\\xi_n}(g(x_n,\\xi_n))\\in \\partial f(x_n)$. We must now assume that\nthe subgradient samples $g(x_n,\\xi_n)$ are bounded. In particular, we have the\nfollowing results.\n\\begin{theorem}\\label{random_subgradient_descent_thm}\n Assume that $f$ is convex and its subgradient samples are bounded, \n meaning that $\\|g(x,\\xi)\\|_2 \\leq M$ for all $x$ and $\\xi$.\n \n Additionally, let $x^*\\in \\arg\\min_x f(x)$ and assume that $\\|x_1 - x^*\\|_2 \\leq R$. \n \n Then, setting the step size $s = \\frac{R}{M\\sqrt{n}}$,\n the iterates of (\\ref{random_subgradient_descent}) satisfy\n \\begin{equation}\n  \\mathbb{E}(f(\\bar{x}_n) - f(x^*)) \\leq \\frac{RM}{2\\sqrt{n}}\n \\end{equation}\n where $\\bar{x}_n = \\frac{1}{n}\\sum_{i = 1}^n x_i$ is the average of the first $n$ iterates, and\n \\begin{equation}\n  \\mathbb{E}\\left(\\min_{i=1,...,n} f(x_i) - f(x^*)\\right) \\leq \\frac{RM}{2\\sqrt{n}}\n \\end{equation}\n \n\\end{theorem}\n\\begin{proof}\n We consider first the average of the iterates. We have\n \\begin{equation}\n  \\mathbb{E}(f(\\bar{x}_n) - f(x^*)) \\leq \\mathbb{E}\\left(\\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*))\\right)\n \\end{equation}\n by Jensen's inequality. By the linearity of the expectation and the fact that $x_i$ only depends on $\\xi_1,...,\\xi_{i-1}$\n we have\n \\begin{align}\n  \\mathbb{E}\\left(\\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*))\\right)& = \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n \\mathbb{E}(f(x_i) - f(x^*)) \\\\\n   & = \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n \\mathbb{E}_{\\xi_1,...,\\xi_{i-1}}(f(x_i) - f(x^*))\n   \\end{align}\n Now we use the assumption that $\\mathbb{E}_{\\xi_n}(h(x_n,\\xi_n))\\in \\partial f(x_n)$ to get\n $$\n  \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n \\mathbb{E}_{\\xi_1,...,\\xi_{i-1}}(f(x_i) - f(x^*)) \\leq \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n \\mathbb{E}_{\\xi_1,...,\\xi_{i-1}}(\\langle \\mathbb{E}_{\\xi_i}g(x_i,\\xi_i),x_i - x^*\\rangle)\n $$\n Since $x_i$ is independent of $\\xi_i,\\xi_{i+1},...,\\xi_n$, we can pull the inner expectation out of the inner product and\n rewrite this as\n \\begin{equation}\n  \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n \\mathbb{E}_{\\xi_1,...,\\xi_{i-1},\\xi_i}(\\langle g(x_i,\\xi_i),x_i - x^*\\rangle) = \n  \\mathbb{E}\\left(\\frac{1}{n}\\displaystyle\\sum_{i = 1}^n \\langle g(x_i,\\xi_i),x_i - x^*\\rangle\\right)\n \\end{equation}\n The iteration \\ref{random_subgradient_descent} means that $g(x_i,\\xi_i) = \\frac{1}{s}(x_i - x_{i+1})$ and we obtain\n \\begin{equation}\n  \\mathbb{E}(f(\\bar{x}_n) - f(x^*)) \\leq \\mathbb{E}\\left(\\frac{1}{ns}\\displaystyle\\sum_{i = 1}^n \\langle x_i - x_{i+1},x_i - x^*\\rangle\\right)\n \\end{equation}\n We can now repeat the argument used in Theorem \\ref{original_subgradient} to rewrite the right hand side as\n \\begin{equation}\n  \\frac{1}{2ns}\\mathbb{E}\\left(\\|x_1 - x^*\\|^2_2 - \\|x_{n+1} - x^*\\|^2_2 + \\displaystyle\\sum_{i = 1}^n \\|x_i - x_{i+1}\\|_2^2\\right)\n \\end{equation}\n Now $\\|x_i - x_{i+1}\\|_2^2 = \\|sg(x_i,\\xi_i)\\|_2^2 \\leq s^2M^2$ and $\\|x_1 - x^*\\|_2^2 \\leq R^2$ so we get\n \\begin{equation}\n  \\mathbb{E}(f(\\bar{x}_n) - f(x^*)) \\leq \\frac{1}{2}\\left(\\frac{R^2}{ns} + M^2s\\right)\n \\end{equation}\n Optimizing over $s$ now yields the same result as in Theorem \\ref{original_subgradient}.\n\n For the second part, we again use the fact that the minimum is bounded by the average\n \\begin{equation}\n  \\mathbb{E}\\left(\\min_{i=1,...,n} f(x_i) - f(x^*)\\right) \\leq \\mathbb{E}\\left(\\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*))\\right)\n \\end{equation}\n and the rest of the proof is the same as before.\n \n\\end{proof}\n\n\\begin{theorem}\n Assume that $f$ is convex and its subgradient samples are bounded, \n meaning that $\\|h(x,\\xi)\\|_2 \\leq M$ for all $x$ and $\\xi$.\n \n Additionally, let $x^*\\in \\arg\\min_x f(x)$ and assume that $\\|x_1 - x^*\\|_2 \\leq R$. \n \n Then, setting the step size $s_i = \\frac{R}{M\\sqrt{i}}$,\n the iterates of (\\ref{random_subgradient_descent_variable}) satisfy\n \\begin{equation}\n  \\mathbb{E}(f(\\bar{x}_n) - f(x^*)) \\leq \\frac{DM(\\log(n) + 1)}{2\\sqrt{n}}\n \\end{equation}\n where $\\bar{x}_n$ is the step size weighted average of the iterates, i.e.\n \\begin{equation}\n  \\bar{x}_n = \\left(\\displaystyle\\sum_{i = 1}^n s_i\\right)^{-1} \\displaystyle\\sum_{i=1}^n s_ix_i\n \\end{equation}\n Additionally, we get\n \\begin{equation}\n  \\mathbb{E}\\left(\\min_{i=1,...,n} f(x_i) - f(x^*)\\right) \\leq \\frac{DM(\\log(n) + 1)}{2\\sqrt{n}}\n \\end{equation}\n \n\\end{theorem}\n\\begin{proof}\n The proof is a straightforward combination of the arguments in Theorems \\ref{random_subgradient_descent_thm} and\n \\ref{variable_subgradient_descent_thm}.\n\\end{proof}\n\n\\subsection{Forward-Backward Subgradient Descent}\nFinally, we cover a very useful and interesting variation on subgradient descent, which we call\nforward-backward subgradient descent. \n\nThe relevant setting is an optimization problem whose objective can be\nsplit as a sum of two objectives\n\\begin{equation}\\label{split_problem}\n f(x) = f_1(x) + f_2(x)\n\\end{equation}\nwhere $f_1$ is a function for which we can easily find elements in the subgradient and $f_2$ is a function for\nwhich we can efficiently solve the `backward' or `proximal' problem\n\\begin{equation}\n p_{\\lambda f_2}(x) = \\arg\\min_{y} \\frac{1}{2}\\|y - x\\|_2^2 + \\lambda f_2(y)\n\\end{equation}\nNotice that optimality condition that the solution $y$ satisfies is\n$$0\\in \\partial_y\\left(\\frac{1}{2}\\|y - x\\|_2^2 + \\lambda f_2(y)\\right) = y - x + \\lambda\\partial f_2(y)\n$$\nIn other words, $y = x - \\lambda g$ for some $g\\in \\partial f_2(y)$. Thus solving the proximal problem\nessentially corresponds to a step of backward Euler for the equation $\\dot{x} \\in \\partial f_2(x)$ in the\nsame sense that a (forward) subgradient step corresponds to a step of forward Euler for the same equation.\n\nTwo very common choices for $f_2$ are the indicator function of a convex set $A$\n\\begin{equation}\n f_2(x) = i_A(x) = \n \\begin{cases}\n                    0 &~ \\text{if $x\\in A$} \\\\\n\t\t    +\\infty &~ \\text{if $x\\notin A$}\n \\end{cases}\n\\end{equation}\nand the l$1$-norm $f_2(x) = \\|x\\|_1$. In the former case, the proximal map is just a projection onto the set $A$ and\nthe forward-backward method simply recovers projected subgradient descent. In the latter case, the\nproximal map is known as soft-thresholding and can be given in closed form.\n\nThe method we will analyze for optimizing (\\ref{split_problem}) is the `forward-backward' splitting method\n\\begin{equation}\\label{subgradient_forward_backward}\n x_{n+\\frac{1}{2}} = x_n - sg_n,~x_{n+1} = p_{sf_2}(x_{n+\\frac{1}{2}})\n\\end{equation}\nwhere $g_n\\in \\partial f_1(x_n)$. This is just a forward step for $f_1$ followed by a backward step for\n$f_2$.\n\nTo aid in our analysis of this algorithm we introduce the Bregman distance, defined as follows\n\\begin{definition}\n Let $f$ be a l.s.c convex function, $x, y\\in \\mathbb{R}^n$, and $g\\in \\partial f(x)$ (which implies that\n $f(x) < \\infty$). The $f$-Bregman distance from $x$ to $y$ with respect to $g$ is\n \\begin{equation}\n  B_f(y,x;g) = f(y) - f(x) - \\langle g, y - x\\rangle\n \\end{equation}\n\n\\end{definition}\\label{bregman_distance}\nThe Bregman distance is simply the difference between $f(y)$ and the linear approximation\n$f(x) + \\langle g, y - x\\rangle$. The convexity of $f$ means that this quantity is always positive.\n\nOne can check that if $f = \\frac{1}{2}\\|x\\|_2^2$, then the Bregman distance corresponds to $\\frac{1}{2}\\|x - y\\|_2^2$,\nfor instance. In general, symmetry is not guaranteed though.\n\nWe will need the following lemma regarding the Bregman distance\n\\begin{lemma}\\label{bregman_equation_1}\n Let $x,y,z\\in \\mathbb{R}^n$, $g_x\\in \\partial f(x)$, $g_y\\in \\partial f(y)$. Then\n \\begin{equation}\n  \\langle g_x - g_y, x - z\\rangle = B_f(z,x;g_x) - B_f(z,y;g_y) + B_f(x,y;g_y)\n \\end{equation}\n \n\\end{lemma}\n\n\\begin{proof}\n From the definition \\ref{bregman_distance}, we see that\n  \\begin{align}\n   &B_f(z,x;g_x) = f(z) - f(x) - \\langle g_x, z - x\\rangle \\\\\n   &-B_f(z,y;g_y) = -f(z) + f(y) + \\langle g_y, z - y\\rangle \\\\\n   & B_f(x,y;g_y) = f(x) - f(y) - \\langle g_y, x - y\\rangle\n  \\end{align}\n\n  Adding these quantities, we obtain\n  \\begin{equation}\n   \\langle g_y, z - y\\rangle - \\langle g_y, x - y\\rangle - \\langle g_x, z - x\\rangle = \\langle g_x - g_y, x - z\\rangle\n  \\end{equation}\n  as desired.\n\\end{proof}\n\nWe will now prove the following convergence result for the forward-backward iteration (\\ref{subgradient_forward_backward}). \n%has similar convergence\n%properties as subgradient descent (\\ref{subgradient_descent}).\n\n\\begin{theorem}\\label{forward_backward_subgradient_thm}\n Assume that $f_1$ is convex with bounded subgradient, meaning that $\\|g\\|_2 \\leq M$ for all $g\\in \\partial f_1(x)$ (for any point $x$).\n \n Set $x_1 \\in \\arg\\min_xf_2(x)$, let $x^*\\in \\arg\\min_x f(x)$, and assume that $\\|x_1 - x^*\\|_2 \\leq R$. \n \n Then, setting the step size $s = \\frac{R}{M\\sqrt{n}}$,\n the iterates of (\\ref{subgradient_forward_backward}) satisfy\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{RM}{2\\sqrt{n}} + \\frac{f_2(x^*) - \\min_x f_2(x)}{n}\n \\end{equation}\n where $\\bar{x}_n = \\frac{1}{n}\\sum_{i = 1}^n x_i$ is the average of the first $n$ iterates, and\n \\begin{equation}\n  \\min_{i=1,...,n} f(x_i) - f(x^*) \\leq \\frac{RM}{2\\sqrt{n}} + \\frac{f_2(x^*) - \\min_x f_2(x)}{n}\n \\end{equation}\n\n\\end{theorem}\nThe whole point of this theorem is that the convergence rate only depends on the Lipschitz constant\nof $f_1$ and not on the Lipschitz constant of $f_2$ (in fact, we don't need $f_2$ to be Lipschitz at all).\n%In practice this method is very useful if $f_1$ has a small Lipschitz constant and $f_2$ isn't Lipschitz\n%of has a very large Lipshchitz constant.\n\n\\begin{proof}\n We consider first the average $\\bar{x}_n = \\frac{1}{n}\\sum_{i = 1}^n x_i$ of the first $n$ iterates.\n We have by Jensen's inequality that\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*))\n \\end{equation}\n The forward iteration gives us \n $$\\frac{1}{s}(x_i - x_{i + \\frac{1}{2}}) \\in \\partial f_1(x_i)$$ \n and the backward iteration means that \n $$\\frac{1}{s}(x_{i - \\frac{1}{2}} - x_i)\\in\\partial f_2(x_i)$$ \n (for $i = 1$ we set $x_{\\frac{1}{2}} = x_1$ and\n use that $x_1\\in \\arg\\min f_2$ so that $0\\in \\partial f_2(x_1)$).\n \n This implies that\n \\begin{equation}\\label{eq373}\n  \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*)) \\leq \\frac{1}{ns}\\displaystyle\\sum_{i = 1}^n \\langle x_{i - \\frac{1}{2}} - x_{i + \\frac{1}{2}}, x_i - x^*\\rangle\n \\end{equation}\n We rewrite the right-hand side as\n \\begin{equation}\\label{eq377}\n  \\frac{1}{ns}\\displaystyle\\sum_{i = 1}^n \\langle x_i - x_{i + 1}, x_i - x^*\\rangle + \\frac{1}{n} \\displaystyle\\sum_{i = 1}^n\\langle h_i - h_{i+1}, x_i - x^*\\rangle\n \\end{equation}\n where $h_i = \\frac{1}{s}(x_{i - \\frac{1}{2}} - x_i)\\in\\partial f_2(x_i)$.\n \n The first sum in equation (\\ref{eq377}) can be rewritten in exactly the same way as in the proof of Theorem \\ref{original_subgradient}\n to obtain\n \\begin{equation}\\label{eq384}\n  \\frac{1}{2ns}\\left(\\|x_1 - x^*\\|_2^2 - \\|x_{n+1} - x^*\\|_2^2 + \\displaystyle\\sum_{i = 1}^n \\|x_i - x_{i+1}\\|_2^2\\right)\n \\end{equation}\n\n We now consider the second sum in equation (\\ref{eq377}). For this we use Lemma \\ref{bregman_equation_1} to rewrite\n $\\langle h_i - h_{i+1}, x_i - x^*\\rangle$ as\n \\begin{equation}\n  D_{f_2}(x^*,x_i;h_i) - D_{f_2}(x^*,x_{i+1};h_{i+1}) + D_{f_2}(x_i,x_{i+1};h_{i+1})\n \\end{equation}\n and note that the relevant sum now telescopes to yield\n \\begin{equation}\\label{eq394}\n  \\frac{1}{n}\\left(D_{f_2}(x^*,x_1;h_1) - D_{f_2}(x^*,x_{n+1};h_{n+1}) + \n  \\displaystyle\\sum_{i = 1}^n D_{f_2}(x_i,x_{i+1};h_{i+1})\\right)\n \\end{equation}\n We continue by considering the sums in equations (\\ref{eq384}) and (\\ref{eq394}) together\n \\begin{equation}\\label{eq402}\n  \\frac{1}{ns}\\left(\\displaystyle\\sum_{i = 1}^n \\frac{1}{2}\\|x_i - x_{i+1}\\|_2^2 + sD_{f_2}(x_i,x_{i+1};h_{i+1})\\right)\n \\end{equation}\n and consider the term\n $$\\frac{1}{2}\\|x_i - x_{i+1}\\|_2^2 + sD_{f_2}(x_i,x_{i+1};h_{i+1})\n $$\n Recalling the definition of the Bregman distance and the fact that $x_i - x_{i+1} = sg_i + sh_{i+1}$ (recall that\n $g_i\\in\\partial f_1(x_i)$ is the subgradient in the forward step), this term becomes\n $$\\frac{1}{2}\\|sg_i + sh_{i+1}\\|_2^2 - \\langle sh_{i+1}, sg_i + sh_{i+1}\\rangle + s(f_2(x_i) - f_2(x_{i+1})) \n $$\n which is equal to\n \\begin{equation}\n  \\frac{1}{2}(\\|sg_i\\|_2^2 - \\|sh_{i + 1}\\|_2^2) + s(f_2(x_i) - f_2(x_{i+1})) \n \\end{equation}\n Plugging this into equation (\\ref{eq402}) we get\n \\begin{equation}\n  \\frac{1}{n}(f_2(x_1) - f_2(x_{n+1})) + \\frac{1}{2ns}\\left(\\displaystyle\\sum_{i = 1}^n\\|sg_i\\|_2^2 - \\|sh_{i + 1}\\|_2^2\\right)\n \\end{equation}\n Plugging all of this into equation (\\ref{eq373}), noting that $f_2(x_1) - f_2(x_{n+1}) \\leq 0$ (since $x_1\\in \\arg\\min f_2$),\n dropping all of the negative norm squared terms, and recalling that $D_{f_2}(x^*,x_{n+1};h_{n+1}) \\geq 0$, we obtain\n \\begin{equation}\n  \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*)) \\leq \\frac{1}{2ns}\\left(\\|x_1 - x^*\\|_2^2 + \\displaystyle\\sum_{i = 1}^n\\|sg_i\\|_2^2\\right)\n  + \\frac{1}{n}D_{f_2}(x^*,x_1;h_1)\n \\end{equation}\n The first term in this sum is the same as the bound in the proof of Theorem \\ref{original_subgradient}, and by choosing $s = \\frac{R}{M\\sqrt{n}}$\n we obtain as before\n \\begin{equation}\n  \\frac{1}{2ns}\\left(\\|x_1 - x^*\\|_2^2 + \\displaystyle\\sum_{i = 1}^n\\|sg_i\\|_2^2\\right) \\leq \\frac{RM}{2\\sqrt{n}}\n \\end{equation}\n Finally, we note that since we set $x_{\\frac{1}{2}} = x_1$, we have $h_1 = 0$ and so\n $$D_{f_2}(x^*,x_1;h_1) = f_2(x^*) - f_2(x_1) = f_2(x^*) - \\min_x f_2(x)\n $$\n This then gives\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{RM}{2\\sqrt{n}} + \\frac{f_2(x^*) - \\min_x f_2(x)}{n}\n \\end{equation}\n as desired.\n\n As usual, we deal with the minimum by noting that the minimum is bounded by the average.\n\\end{proof}\n\nWe can also obtain a version of this method with a variable step size, for which the number of iterations\nneed not be specified in advance, we leave this as an exercise.\n\nIn addition, we obtain the same result in the stochastic setting, where the subgradient elements $g_n$ are replaced by an unbiased \nsample, i.e. where we consider the iteration\n\\begin{equation}\\label{forward_backward_stochastic_subgradient}\n x_{n+\\frac{1}{2}} = x_n - sg(x_n,\\xi_n),~x_{n+1} = p_{sf_2}(x_{n+\\frac{1}{2}})\n\\end{equation}\nwhere $\\mathbb{E}_{\\xi_n}(g(x_n,\\xi_n))\\in \\partial f_1(x_n)$.\n\\begin{theorem}\n Assume that $f_1$ is convex with bounded subgradient samples, meaning that $\\|g(x,\\xi)\\|_2 \\leq M$ for all $x$ and $\\xi$.\n \n Set $x_1 \\in \\arg\\min_xf_2(x)$, let $x^*\\in \\arg\\min_x f(x)$, and assume that $\\|x_1 - x^*\\|_2 \\leq R$. \n \n Then, setting the step size $s = \\frac{R}{M\\sqrt{n}}$,\n the iterates of (\\ref{forward_backward_stochastic_subgradient}) satisfy\n \\begin{equation}\n  \\mathbb{E}(f(\\bar{x}_n) - f(x^*)) \\leq \\frac{RM}{2\\sqrt{n}} + \\frac{f_2(x^*) - \\min_x f_2(x)}{n}\n \\end{equation}\n where $\\bar{x}_n = \\frac{1}{n}\\sum_{i = 1}^n x_i$ is the average of the first $n$ iterates, and\n \\begin{equation}\n  \\mathbb{E}(\\min_{i=1,...,n} f(x_i) - f(x^*)) \\leq \\frac{RM}{2\\sqrt{n}} + \\frac{f_2(x^*) - \\min_x f_2(x)}{n}\n \\end{equation}\n\\end{theorem}\n\\begin{proof}\n  The proof is a straightforward combination of the arguments in Theorems \\ref{random_subgradient_descent_thm} and\n \\ref{forward_backward_subgradient_thm}.\n\\end{proof}\n\n\\subsection{Dual Averaging}\nIn this section, we introduce Nesterov's method of dual averaging. In order to best explain where this method comes from,\nwe first start with a different perspective on subgradient descent. Notice that the subgradient descent iteration\n(\\ref{subgradient_descent}) can also be written as\n\\begin{equation}\\label{subgradient_descent_argmin}\n x_{n+1} = \\arg\\min_x \\left(f(x_n) + \\langle g_n, x - x_n\\rangle + \\frac{1}{2s}\\|x - x_n\\|_2^2\\right)\n\\end{equation}\nNotice that $f(x_n) + \\langle g_n, x - x_n\\rangle$ is a lower bound on the objective $f(x)$, and \n$\\frac{1}{2s}\\|x - x_n\\|_2^2$ can be thought of as a regularization term which prevents $x_{n+1}$\nfrom moving too far away from $x_n$.\n\nSo for subgradient descent, the next iterate can be obtained by minimizing a regularized lower bound on the objective.\nIn fact, many optimization methods can be thought of as minimizing regularized approximations to the objective in \nevery step.\n\nIn equation (\\ref{subgradient_descent_argmin}), the lower bound $f(x_n) + \\langle g_n, x - x_n\\rangle$ only depends on\nthe previous point $x_n$ and the previous gradient $g_n$. The idea behind dual averaging is to replace this\nlower bound by its average over all previous iterates\n\\begin{equation}\n \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) + \\langle g_i, x - x_i\\rangle)\n\\end{equation}\nSince each of these terms is a lower bound on $f$, so is their average. We now need to add a regularization term\nto obtain the next iterate $x_{n+1}$. For the purposes of this exposition, we choose $\\frac{1}{2}\\|x\\|^2_2$ as a regularizer,\nalthough any strongly convex function can be used. This leads to the following subproblem for $x_{n+1}$\n\\begin{equation}\n x_{n+1} = \\arg\\min_x\\left(\\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) + \\langle g_i, x - x_i\\rangle) + \\frac{\\gamma_n}{2}\\|x\\|_2^2\\right)\n\\end{equation}\nwhere $g_i\\in \\partial f(x_i)$ and the sequence $\\gamma_n > 0$ must be chosen appropriately to make the method converge. \n\nIn order to simplify notation, we drop terms not depending on $x$, multiply by $n$, and define $\\alpha_{n+1} = n\\gamma_n$,\nto rewrite the above problem as\n\\begin{equation}\\label{SDA_iteration}\n x_{n+1} = \\arg\\min_x\\left(\\displaystyle\\sum_{i = 1}^n \\langle g_i, x\\rangle + \\frac{\\alpha_{n+1}}{2}\\|x\\|_2^2\\right)\n\\end{equation}\n(again $g_i\\in \\partial f(x_i)$) whose solution is given by\n\\begin{equation}\n x_{n+1} = -\\frac{1}{\\alpha_{n+1}}\\displaystyle\\sum_{i = 1}^n g_i\n\\end{equation}\nAdditionally, we set $x_1 = 0$ and $\\alpha_1 > 0$ so that\n\\begin{equation}\n x_1 = \\arg\\min_x \\frac{\\alpha_1}{2}\\|x\\|_2^2\n\\end{equation}\n\n\nWe begin by using the definition of $x_{n+1}$ as the minimizer in (\\ref{SDA_iteration}) to obtain two simple lemmas which will\nbe crucial in our convergence analysis.\n\\begin{lemma}\\label{lemma558}\n For any $z$ and any $n \\geq 1$, we have\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^{n-1} \\langle g_i, x_n - z\\rangle \\leq \\frac{\\alpha_n}{2}(\\|z\\|_2^2 - \\|x_n\\|_2^2)\n \\end{equation}\n\n\\end{lemma}\n\\begin{proof}\n Since $x_{n+1}$ is the minimizer in (\\ref{SDA_iteration}), we have\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_{n+1}\\rangle + \\frac{\\alpha_{n+1}}{2}\\|x_{n+1}\\|_2^2 \\leq \\displaystyle\\sum_{i = 1}^n \\langle g_i, z\\rangle + \\frac{\\alpha_{n+1}}{2}\\|z\\|_2^2\n \\end{equation}\n Rearranging this and shifting the index yields the desired inequality (we can also easily verify the conclusion for $n = 1$).\n\\end{proof}\n\n\\begin{lemma}\\label{lemma573}\n Let $x_n$ be defined by (\\ref{SDA_iteration}). Then we have\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_n - x_{n+1}\\rangle \\leq \\frac{\\alpha_{n}}{2}(\\|x_{n+1}\\|_2^2 - \\|x_n\\|_2^2) + \\frac{1}{2\\alpha_{n}} \\|g_n\\|_2^2\n \\end{equation}\n\n\\end{lemma}\n\\begin{proof}\n Define $f_n(x) = \\sum_{i = 1}^{n-1} \\langle g_i, x\\rangle + \\frac{\\alpha_{n}}{2}\\|x\\|_2^2$, so that\n $$x_n = \\arg\\min_x f_n(x)\n $$\n and $f_n(x)$ is strongly convex with convexity parameter $\\alpha_{n}$.\n \n This means that $f^\\prime_n(x) = f_n(x) + \\langle g_n, x\\rangle$ is also strongly convex with the same convexity parameter $\\alpha_{n}$.\n \n Note that since $x_n = \\arg\\min_x f_n(x)$, we have $0\\in \\partial f_n(x_n)$ and so $g_n\\in \\partial f^\\prime_n(x_n)$. Using the strong\n convexity, we thus obtain\n \\begin{equation}\n  f_n^\\prime(x_{n+1}) \\geq f_n^\\prime(x_n) + \\langle g_n, x_{n+1} - x_n\\rangle + \\frac{\\alpha_{n}}{2}\\|x_{n+1} - x_n\\|_2^2\n \\end{equation}\n so that (rearranging and using Cauchy-Schwartz)\n \\begin{align}\n  f_n^\\prime(x_n) - f_n^\\prime(x_{n+1}) &\\leq \\|g_n\\|_2\\|x_{n+1} - x_n\\|_2 - \\frac{\\alpha_{n}}{2}\\|x_{n+1} - x_n\\|_2^2 \\\\\n  &\\leq \\frac{1}{2\\alpha_{n}} \\|g_n\\|_2^2\n \\end{align}\n This means that\n \\begin{equation}\n  f_n^\\prime(x_n) \\leq f_n^\\prime(x_{n+1}) + \\frac{1}{2\\alpha_{n}} \\|g_n\\|_2^2\n \\end{equation}\n We now recall the definition of $f^\\prime_n(x)$ to see that\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^{n} \\langle g_i, x_n\\rangle + \\frac{\\alpha_{n}}{2}\\|x_n\\|_2^2 \\leq \n  \\displaystyle\\sum_{i = 1}^{n} \\langle g_i, x_{n+1}\\rangle + \\frac{\\alpha_{n}}{2}\\|x_{n+1}\\|_2^2 + \\frac{1}{2\\alpha_{n}} \\|g_n\\|_2^2\n \\end{equation}\n Rearranging this, we get\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^{n} \\langle g_i, x_n - x_{n+1}\\rangle \\leq \\frac{\\alpha_{n}}{2}(\\|x_{n+1}\\|_2^2 - \\|x_n\\|_2^2) + \\frac{1}{2\\alpha_{n}} \\|g_n\\|_2^2\n \\end{equation}\n as desired.\n\n\\end{proof}\n\nWe now prove convergence of the dual averaging method.\n\\begin{theorem}\\label{SDA_convergence_thm}\n Assume that $f$ is convex with bounded subgradient (i.e. Lipschitz), meaning that $\\|g\\|_2 \\leq M$ for all $g\\in \\partial f(x)$ (for any point $x$).\n \n Additionally, let $x^*\\in \\arg\\min_x f(x)$.\n \n Then if $x_n$ is given by the iteration (\\ref{SDA_iteration}) with $\\alpha_n = c\\sqrt{n}$, we have\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{1}{\\sqrt{n}}\\left(\\frac{c}{2}\\|x^*\\|_2^2 + \\frac{M^2}{c}\\right)\n \\end{equation}\n where $\\bar{x}_n$ is the average of the first $n$ iterates. Additionally, we have\n \\begin{equation}\n  \\min_{i = 1,...,n} (f(x_i) - f(x^*)) \\leq \\frac{1}{\\sqrt{n}}\\left(\\frac{c}{2}\\|x^*\\|_2^2 + \\frac{M^2}{c}\\right)\n \\end{equation}\n\\end{theorem}\n\n\\begin{proof}\n As before, we begin by noting that (by convexity)\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*))\n \\end{equation}\n and\n \\begin{equation}\n  \\min_{i = 1,...,n} (f(x_i) - f(x^*)) \\leq \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*))\n \\end{equation}\n Thus it suffices to bound the `average regret.' We begin by using the subdifferential property to get\n \\begin{equation}\n  \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*)) \\leq \n  \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle\n \\end{equation}\n The trick is now to rewrite this sum as\n \\begin{equation}\\label{eq646}\n  \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle = \n  \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_{n+1} - x^*\\rangle + \\displaystyle\\sum_{i = 1}^n \\displaystyle\\sum_{j = 1}^i\\langle g_j, x_i - x_{i+1}\\rangle\n \\end{equation}\n and to use Lemmas \\ref{lemma573} and \\ref{lemma558} to bound\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_{n+1} - x^*\\rangle \\leq \\frac{\\alpha_{n+1}}{2}(\\|x^*\\|_2^2 - \\|x_{n+1}\\|_2^2)\n \\end{equation}\n and\n \\begin{equation}\n  \\displaystyle\\sum_{j = 1}^i\\langle g_j, x_i - x_{i+1}\\rangle \\leq \\frac{\\alpha_{i}}{2}(\\|x_{i+1}\\|_2^2 - \\|x_i\\|_2^2) + \\frac{1}{2\\alpha_{i}} \\|g_i\\|_2^2\n \\end{equation}\n Utilizing our bound on the subgradients $\\|g_i\\|_2\\leq M$, plugging this into equation (\\ref{eq646}), and rearranging\n the (almost) telescoping sum, we get\n \\begin{align}\n  \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle &\\leq \\frac{\\alpha_{n+1}}{2}\\|x^*\\|_2^2 - \\frac{\\alpha_1}{2}\\|x_1\\|_2^2 \\\\\n  &+ \\frac{1}{2}\\displaystyle\\sum_{i = 2}^{n+1}(\\alpha_{i - 1} - \\alpha_{i}) \\|x_i\\|_2^2 + \\frac{M^2}{2}\\displaystyle\\sum_{i = 1}^n\\frac{1}{\\alpha_{i}} \n \\end{align}\n The above inequality is true for any choice of $\\alpha_1,...,\\alpha_{n+1}$ as long as the $x_i$ are given by the iteration\n (\\ref{SDA_iteration}). Since the left hand side of the inequality only depends upon $x_1,...,x_n$, we are free to choose\n $\\alpha_{n+1} = \\alpha_n$ (without changing the left hand size), and we get\n \\begin{align}\n  \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle &\\leq \\frac{\\alpha_{n}}{2}\\|x^*\\|_2^2 - \\frac{\\alpha_1}{2}\\|x_1\\|_2^2 \\\\\n  &+ \\frac{1}{2}\\displaystyle\\sum_{i = 2}^{n}(\\alpha_{i - 1} - \\alpha_{i}) \\|x_i\\|_2^2 + \\frac{M^2}{2}\\displaystyle\\sum_{i = 1}^n\\frac{1}{\\alpha_{i}} \n \\end{align}\n Now we note that if $\\alpha_n$ is an increasing sequence (which it is for our particular choice $\\alpha_n = c\\sqrt{n}$), we can use \n $\\alpha_{i-1} - \\alpha_i \\leq 0$ to get\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle \\leq\\frac{\\alpha_{n}}{2}\\|x^*\\|_2^2 + \\frac{M^2}{2}\\displaystyle\\sum_{i = 1}^n\\frac{1}{\\alpha_{i}} \n \\end{equation}\n Plugging in our choice of $\\alpha_n = c\\sqrt{n}$ and noting that $\\sum_{i = 1}^n \\frac{1}{\\sqrt{i}} \\leq 2\\sqrt{n}$ gives\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle \\leq\\left(\\frac{c}{2}\\|x^*\\|_2^2 + \\frac{M^2}{c}\\right)\\sqrt{n}\n \\end{equation}\n Dividing this by $n$ completes the proof.\n\n\\end{proof}\n\nSo the dual averaging method achieves the same asymptotic convergence rate as subgradient descent. A straightforward modification\nof the above argument can be used to obtain the convergence of a stochastic version of the dual average algorithm. As before,\nwe need to replace the Lipschitz assumption on $f$ by the assumption that our subgradient samples are bounded. We state the\nrelevant result without proof.\n\n\\begin{theorem}\n Assume that $f$ is convex and assume that $x_n$ are given by the iteration (\\ref{SDA_iteration}) where $g_i$ is replaced by\n an unbiased sample $g(x_i,\\xi_i)$ of an element in the subgradient \n (i.e. $\\xi_i$ is a random variable and $\\mathbb{E}_{\\xi_i}g(x_i,\\xi_i) \\in \\partial f(x_i)$). Assume additionally that the \n subgradient samples are bounded, i.e. that $\\|g(x,\\xi)\\|_2 \\leq M$.\n \n Let $x^*\\in \\arg\\min_x f(x)$.\n \n Then with $\\alpha_n = c\\sqrt{n}$, we have\n \\begin{equation}\n  \\mathbb{E}(f(\\bar{x}_n) - f(x^*)) \\leq \\frac{1}{\\sqrt{n}}\\left(\\frac{c}{2}\\|x^*\\|_2^2 + \\frac{M^2}{c}\\right)\n \\end{equation}\n where $\\bar{x}_n$ is the average of the first $n$ iterates. Additionally, we have\n \\begin{equation}\n  \\mathbb{E}\\left(\\min_{i = 1,...,n} (f(x_i) - f(x^*))\\right) \\leq \\frac{1}{\\sqrt{n}}\\left(\\frac{c}{2}\\|x^*\\|_2^2 + \\frac{M^2}{c}\\right)\n \\end{equation}\n\\end{theorem}\n\n\\subsection{Regularized Dual Averaging}\n\nIn this subsection, we introduce a version of the dual averaging method which is designed for solving composite\noptimization problems of the form\n\\begin{equation}\n f(x) = f_1(x) + f_2(x)\n\\end{equation}\nwhere $f_1(x)$ is a convex function whose subgradient can be readily calculated and $f_2(x)$ is a convex function\nfor which a proximal (or backward) step\n\\begin{equation}\n p_{\\lambda f_2}(x) = \\arg\\min_y \\frac{1}{2}\\|y - x\\|_2^2 + \\lambda f_2(y)\n\\end{equation}\ncan efficiently be calculated. The proximal step and functions $f_2$ for which it can efficiently be evaluated were\ndiscussed in more detail in the section on forward backward subgradient descent.\n\nWe begin the discussion by noting that forward-backward subgradient descent (\\ref{subgradient_forward_backward}) can be written\nas\n\\begin{equation}\n x_{n+1} = \\arg\\min_x \\left(f_1(x_n) + \\langle g_n, x - x_n\\rangle + f_2(x) + \\frac{1}{2s}\\|x - x_n\\|_2^2\\right)\n\\end{equation}\nwhere $g_n\\in \\partial f(x_n)$. We note that $f_1(x_n) + \\langle g_n, x - x_n\\rangle + f_2(x)$ is a lower bound on\n$f(x)$ and thus this method can be thought of as minimizing a regularized lower bound on the objective.\n\nThe regularized dual average method replaces the above lower bound by an average over all of the previous iterates\n\\begin{equation}\n \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f_1(x_n) + \\langle g_n, x - x_n\\rangle + f_2(x))\n\\end{equation}\nand as for the dual averaging method, we add $\\frac{1}{2}\\|x\\|_2^2$ as a regularizer (although any strongly convex\nfunction will do) to obtain the following method\n\\begin{equation}\n x_{n+1} = \\arg\\min_x\\left(\\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f_1(x_n) + \\langle g_n, x - x_n\\rangle + f_2(x)) + \\frac{\\gamma_n}{2}\\|x\\|_2^2\\right)\n\\end{equation}\nIn order to simplify notation, we rewrite this in the same way we rewrote the dual averaging method to get\n\\begin{equation}\\label{RDA_iteration}\n x_{n+1} = \\arg\\min_x \\left(\\displaystyle\\sum_{i = 1}^n \\langle g_n, x\\rangle\\right) + nf_2(x) + \\frac{\\alpha_{n+1}}{2}\\|x\\|_2^2\n\\end{equation}\nwhere $\\alpha_{n+1} = n\\gamma_n$. More explicitly, we can split this subproblem into two steps to get\n\\begin{equation}\n x_{n+\\frac{1}{2}} = -\\frac{1}{\\alpha_{n+1}}\\displaystyle\\sum_{i = 1}^n g_n,~x_{n+1} = p_{\\lambda_nf_2}(x_{n+\\frac{1}{2}})\n\\end{equation}\nwhere $\\lambda_n = \\frac{n}{\\alpha_{n+1}}$. Also, we set $x_1 = 0$ and $\\alpha_1 > 0$ so that\n\\begin{equation}\n x_1 = \\arg\\min_x \\frac{\\alpha_1}{2}\\|x\\|_2^2\n\\end{equation}\n\nThe convergence analysis of this method is very similar to that of the dual averaging method. We begin by using the\ndefinition of $x_{n+1}$ as the minimizer in (\\ref{RDA_iteration}) to obtain the following two lemmas.\n\n\\begin{lemma}\\label{lemma751}\n For any $z$ and any $n \\geq 1$, we have\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^{n-1} \\langle g_i, x_n - z\\rangle \\leq \\frac{\\alpha_n}{2}(\\|z\\|_2^2 - \\|x_n\\|_2^2) + (n-1)(f_2(z) - f_2(x_n))\n \\end{equation}\n\n\\end{lemma}\n\\begin{proof}\n Since $x_{n+1}$ is the minimizer in (\\ref{RDA_iteration}), we have\n \\begin{align}\n  &\\displaystyle\\sum_{i = 1}^n \\langle g_i, x_{n+1}\\rangle + \\frac{\\alpha_{n+1}}{2}\\|x_{n+1}\\|_2^2 + nf_2(x_{n+1}) \\\\\n  &\\leq \\displaystyle\\sum_{i = 1}^n \\langle g_i, z\\rangle + \\frac{\\alpha_{n+1}}{2}\\|z\\|_2^2+ nf_2(z)\n \\end{align}\n Rearranging this and shifting the index yields the desired inequality (we can also easily verify the conclusion for $n = 1$).\n\\end{proof}\n\n\\begin{lemma}\\label{lemma767}\n Let $x_n$ be defined by (\\ref{SDA_iteration}). Then we have\n \\begin{align}\n  \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_n - x_{n+1}\\rangle &\\leq \\frac{\\alpha_{n}}{2}(\\|x_{n+1}\\|_2^2 - \\|x_n\\|_2^2) \\\\\n  &+ (n-1)(f_2(x_{n+1}) - f_2(x_n)) + \\frac{1}{2\\alpha_{n}} \\|g_n\\|_2^2\n \\end{align}\n\n\\end{lemma}\n\\begin{proof}\n The proof is exactly the same as the proof of Lemma \\ref{lemma573}, except that we set\n \\begin{equation}\n  f_n(x) = \\left(\\displaystyle\\sum_{i = 1}^{n-1} \\langle g_n, x\\rangle\\right) + (n-1)f_2(x) + \\frac{\\alpha_{n}}{2}\\|x\\|_2^2\n \\end{equation}\n\n\\end{proof}\n\nWe now prove the convergence of the regularized dual averaging method (\\ref{RDA_iteration}).\n\\begin{theorem}\n Assume that $f_1$ is convex with bounded subgradient (i.e. Lipschitz), meaning that $\\|g\\|_2 \\leq M$ for all $g\\in \\partial f_1(x)$ (for any point $x$).\n \n Let $x^*\\in \\arg\\min_x f(x)$.\n \n Then if $x_n$ is given by the iteration (\\ref{RDA_iteration}) with $\\alpha_n = c\\sqrt{n}$, we have\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{1}{\\sqrt{n}}\\left(\\frac{c}{2}\\|x^*\\|_2^2 + \\frac{M^2}{c}\\right) + \\frac{f_2(x_1) - \\inf_x f_2(x)}{n}\n \\end{equation}\n where $\\bar{x}_n$ is the average of the first $n$ iterates. Additionally, we have\n \\begin{equation}\n  \\min_{i = 1,...,n} (f(x_i) - f(x^*)) \\leq \\frac{1}{\\sqrt{n}}\\left(\\frac{c}{2}\\|x^*\\|_2^2 + \\frac{M^2}{c}\\right) + \\frac{f_2(x_1) - \\inf_x f_2(x)}{n}\n \\end{equation}\n\\end{theorem}\n\\begin{proof}\n The proof is very similar to the proof of Theorem \\ref{SDA_convergence_thm}. We begin by noting that (by convexity)\n \\begin{equation}\n  f(\\bar{x}_n) - f(x^*) \\leq \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*))\n \\end{equation}\n and\n \\begin{equation}\n  \\min_{i = 1,...,n} (f(x_i) - f(x^*)) \\leq \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*))\n \\end{equation}\n Thus it suffices to bound the `average regret.' We begin by decomposing $f = f_1 + f_2$ and using the subdifferential property to get\n \\begin{equation}\\label{eq808}\n  \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*)) \\leq \n  \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle + \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (f_2(x_i) - f_2(x^*))\n \\end{equation}\nWe now proceed to rewrite and bound the first sum above as in the proof of Theorem \\ref{SDA_convergence_thm}. We get\n\\begin{equation}\n \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle = \n  \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_{n+1} - x^*\\rangle + \\displaystyle\\sum_{i = 1}^n \\displaystyle\\sum_{j = 1}^i\\langle g_j, x_i - x_{i+1}\\rangle\n\\end{equation}\nand use Lemmas \\ref{lemma751} and \\ref{lemma767} to bound\n\\begin{equation}\n \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_{n+1} - x^*\\rangle \\leq \\frac{\\alpha_{n+1}}{2}(\\|x^*\\|_2^2 - \\|x_{n+1}\\|_2^2) + n(f_2(x^*) - f_2(x_{n+1}))\n\\end{equation}\nand\n \\begin{align}\n  \\displaystyle\\sum_{j = 1}^i\\langle g_j, x_i - x_{i+1}\\rangle &\\leq \\frac{\\alpha_{i}}{2}(\\|x_{i+1}\\|_2^2 - \\|x_i\\|_2^2) \\\\\n  &+ (n-1)(f_2(x_{i+1}) - f_2(x_i)) + \\frac{1}{2\\alpha_{i}} \\|g_i\\|_2^2\n \\end{align}\n Utilizing our bound on the subgradients $\\|g_i\\|_2\\leq M$, plugging this into equation (\\ref{eq646}), and rearranging\n the (almost) telescoping sums, we get\n \\begin{align}\n  \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle &\\leq \\frac{\\alpha_{n+1}}{2}\\|x^*\\|_2^2 - \\frac{\\alpha_1}{2}\\|x_1\\|_2^2 + nf_2(x^*) - \\displaystyle\\sum_{i = 2}^{n+1} f_2(x_i) \\\\\n  &+ \\frac{1}{2}\\displaystyle\\sum_{i = 2}^{n+1}(\\alpha_{i - 1} - \\alpha_{i}) \\|x_i\\|_2^2 + \\frac{M^2}{2}\\displaystyle\\sum_{i = 1}^n\\frac{1}{\\alpha_{i}} \n \\end{align}\n Plugging this into equation (\\ref{eq808}) we obtain\n \\begin{align}\n  \\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*)) &\\leq \\frac{\\alpha_{n+1}}{2}\\|x^*\\|_2^2 - \\frac{\\alpha_1}{2}\\|x_1\\|_2^2 + (f_2(x_1) - f_2(x_{n+1})) \\\\\n  &+ \\frac{1}{2}\\displaystyle\\sum_{i = 2}^{n+1}(\\alpha_{i - 1} - \\alpha_{i}) \\|x_i\\|_2^2 + \\frac{M^2}{2}\\displaystyle\\sum_{i = 1}^n\\frac{1}{\\alpha_{i}} \n \\end{align}\n which gives the bound\n \\begin{align}\n  \\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*)) &\\leq \\frac{\\alpha_{n+1}}{2}\\|x^*\\|_2^2 - \\frac{\\alpha_1}{2}\\|x_1\\|_2^2 + (f_2(x_1) - \\inf_x f_2(x)) \\\\\n  &+ \\frac{1}{2}\\displaystyle\\sum_{i = 2}^{n+1}(\\alpha_{i - 1} - \\alpha_{i}) \\|x_i\\|_2^2 + \\frac{M^2}{2}\\displaystyle\\sum_{i = 1}^n\\frac{1}{\\alpha_{i}} \n \\end{align}\n As before, the above inequality is true for any choice of $\\alpha_1,...,\\alpha_{n+1}$ as long as the $x_i$ are given by the iteration\n (\\ref{RDA_iteration}). Since the left hand side of the inequality only depends upon $x_1,...,x_n$, we are free to choose\n $\\alpha_{n+1} = \\alpha_n$ (without changing the left hand size), and we get\n \\begin{align}\n  \\displaystyle\\sum_{i = 1}^n (f(x_i) - f(x^*)) &\\leq \\frac{\\alpha_{n}}{2}\\|x^*\\|_2^2 - \\frac{\\alpha_1}{2}\\|x_1\\|_2^2 + (f_2(x_1) - \\inf_x f_2(x)) \\\\\n  &+ \\frac{1}{2}\\displaystyle\\sum_{i = 2}^{n}(\\alpha_{i - 1} - \\alpha_{i}) \\|x_i\\|_2^2 + \\frac{M^2}{2}\\displaystyle\\sum_{i = 1}^n\\frac{1}{\\alpha_{i}} \n \\end{align}\n Now we note that if $\\alpha_n$ is an increasing sequence (which it is for our particular choice $\\alpha_n = c\\sqrt{n}$), we can use \n $\\alpha_{i-1} - \\alpha_i \\leq 0$ to get\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle \\leq\\frac{\\alpha_{n}}{2}\\|x^*\\|_2^2 + \\frac{M^2}{2}\\displaystyle\\sum_{i = 1}^n\\frac{1}{\\alpha_{i}} + (f_2(x_1) - \\inf_x f_2(x)) \n \\end{equation}\n Plugging in our choice of $\\alpha_n = c\\sqrt{n}$ and noting that $\\sum_{i = 1}^n \\frac{1}{\\sqrt{i}} \\leq 2\\sqrt{n}$ gives\n \\begin{equation}\n  \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle \\leq\\left(\\frac{c}{2}\\|x^*\\|_2^2 + \\frac{M^2}{c}\\right)\\sqrt{n} + (f_2(x_1) - \\inf_x f_2(x))\n \\end{equation}\n Dividing this by $n$ completes the proof.\n \\end{proof}\n \n A straightforward modification of the above argument provides a proof that the stochastic version of the above algorithm\n converges. We state the relevant theorem but omit the proof.\n \\begin{theorem}\n Assume that $f$ is convex and assume that $x_n$ are given by the iteration (\\ref{RDA_iteration}) where $g_i$ is replaced by\n an unbiased sample $g(x_i,\\xi_i)$ of an element in the subgradient \n (i.e. $\\xi_i$ is a random variable and $\\mathbb{E}_{\\xi_i}g(x_i,\\xi_i) \\in \\partial f(x_i)$). Assume additionally that the \n subgradient samples are bounded, i.e. that $\\|g(x,\\xi)\\|_2 \\leq M$.\n \n Let $x^*\\in \\arg\\min_x f(x)$.\n \n Then with $\\alpha_n = c\\sqrt{n}$, we have\n \\begin{equation}\n  \\mathbb{E}(f(\\bar{x}_n) - f(x^*)) \\leq \\frac{1}{\\sqrt{n}}\\left(\\frac{c}{2}\\|x^*\\|_2^2 + \\frac{M^2}{c}\\right) + \\frac{f_2(x_1) - \\inf_x f_2(x)}{n}\n \\end{equation}\n where $\\bar{x}_n$ is the average of the first $n$ iterates. Additionally, we have\n \\begin{equation}\n  \\mathbb{E}\\left(\\min_{i = 1,...,n} (f(x_i) - f(x^*))\\right) \\leq \\frac{1}{\\sqrt{n}}\\left(\\frac{c}{2}\\|x^*\\|_2^2 + \\frac{M^2}{c}\\right) + \\frac{f_2(x_1) - \\inf_x f_2(x)}{n}\n \\end{equation}\n \\end{theorem}\n\n \n%-------------------------------------------------------------------------------------------------------------------\n\n\\section{Smooth Convex Functions}\nIn this section, we consider methods for optimizing $L$-smooth convex functions, i.e. differentiable convex functions\nwhose gradients are Lipschitz with constant $L$\n\\begin{equation}\n \\|\\nabla f(x) - \\nabla f(y)\\|_2 \\leq L\\|x - y\\|_2\n\\end{equation}\nIt is a simple exercise to show that such a function satisfies a quadratic upper bound\n\\begin{equation}\n f(x)\\leq f(y) + \\langle\\nabla f(x), y - x\\rangle + \\frac{L}{2}\\|y - x\\|_2^2\n\\end{equation}\n\nWe will see that with this stronger assumption on the objective, we remove the need to average the iterates in \naddition to obtaining a significantly better convergence rate in the deterministic setting.\n\\subsection{Gradient Descent}\nIn this subsection, we analyze the well-known gradient descent method for smooth convex functions\n\\begin{equation}\\label{gradient_descent_smooth}\n x_{n+1} = x_n - s\\nabla f(x_n)\n\\end{equation}\nWe also find it instructive to consider the behavior of the continuous gradient descent dynamics\n\\begin{equation}\\label{gradient_descent_dynamics_smooth}\n \\dot{x}(t) = -\\nabla f(x(t))\n\\end{equation}\n\nUsing a Lyapunov argument, we can show that the continuous dynamics (\\ref{gradient_descent_dynamics_smooth}) obtains\nan (objective) convergence rate of $O(\\frac{1}{t})$, as the following theorem shows.\n\n\\begin{theorem}\\label{smooth_gradient_dynamics_thm} \n Assume that $f$ is convex and smooth and let $x^*\\in \\arg\\min_x f(x)$. \n Then the dynamics (\\ref{gradient_descent_dynamics_smooth}) satisfies\n \\begin{equation}\n  f(x(t)) - f(x^*) \\leq \\frac{1}{2t}\\|x(0) - x^*\\|_2^2\n \\end{equation}\n\n\\end{theorem}\n\\begin{proof}\n Consider the following Lyapunov function\n \\begin{equation}\n  L(t) = t(f(x(t)) - f(x^*)) + \\frac{1}{2}\\|x(t) - x^*\\|_2^2\n \\end{equation}\n We calculate the derivative of $L$\n \\begin{equation}\n  L^\\prime(t) = (f(x(t)) - f(x^*)) + t\\langle\\nabla f(x(t)), \\dot{x}(t)\\rangle + \\langle\\dot{x}(t), (x(t) - x^*)\\rangle\n \\end{equation}\n substituting $\\dot{x}(t) = -\\nabla f(x(t))$ in the above equation, we see\n \\begin{equation}\n  L^\\prime(t) = (f(x(t)) - f(x^*)) - \\langle\\nabla f(x(t)), x(t) - x^*\\rangle - t\\|\\nabla f(x(t))\\|_2^2\n \\end{equation}\n The convexity of $f$ implies that $(f(x(t)) - f(x^*)) - \\langle\\nabla f(x(t)), x(t) - x^*\\rangle \\leq 0$ so we get\n \\begin{equation}\n  L^\\prime(t) \\leq 0\n \\end{equation}\n This means that $L(t) \\leq L(0)$, so we get\n \\begin{equation}\n  t(f(x(t)) - f(x^*)) \\leq L(t) \\leq L(0) = \\frac{1}{2}\\|x(0) - x^*\\|_2^2\n \\end{equation}\n as desired.\n\n\\end{proof}\n\nInterestingly, we can adapt the above Lyapunov argument to the discrete case as long as our step size is small enough.\nThis provides an intuitive and simple derivation of the following convergence result.\n\\begin{theorem}\\label{gradient_descent_convergence_smooth}\n Let $f$ be an $L$-smooth, convex function and let $x^*\\in\\arg\\min_x f(x)$. \n Then the gradient descent iteration (\\ref{gradient_descent_smooth}) with\n step size $s = \\frac{1}{L}$ satisfies\n \\begin{equation}\n  f(x_n) - f(x^*) \\leq \\frac{L}{2n}\\|x_0 - x^*\\|_2^2\n \\end{equation}\n\n\\end{theorem}\n Note that the convergence rate is significantly improved over subgradient descent and we also\n don't need to average the iterates, we can simply take the last one. This is the improvement that\n smoothness buys us.\n \\begin{proof}\n  Consider the discrete Lyapunov function\n  \\begin{equation}\n   L(n) = n(f(x_n) - f(x^*)) + \\frac{L}{2}\\|x_n - x^*\\|_2^2\n  \\end{equation}\n  We calculate the change in $L$ as follows\n  \\begin{align}\n   L(n+1) - L(n) &= f(x_n) - f(x^*) + (n+1)(f(x_{n+1}) - f(x_n))\\\\\n   & + L\\langle(x_{n+1} - x_n), x_n - x^*\\rangle + \\frac{L}{2}\\|x_{n+1} - x_n\\|_2^2\n  \\end{align}\n Substituting $x_{n+1} - x_n = -s\\nabla f(x_n) = \\frac{-1}{L}\\nabla f(x_n)$ into the above equation\n we obtain\n  \\begin{align}\n   L(n+1) - L(n) &= f(x_n) - f(x^*) + (n+1)(f(x_{n+1}) - f(x_n))\\\\\n   & - \\langle\\nabla f(x_n), x_n - x^*\\rangle + \\frac{1}{2L}\\|\\nabla f(x_n)\\|_2^2\n  \\end{align}\n  The smoothness allows us to bound $f(x_{n+1}) - f(x_n)$, i.e. show that we attain a sufficient decrease as follows.\n  By substituting $x_{n+1} - x_n = \\frac{-1}{L}\\nabla f(x_n)$ into\n  \\begin{equation}\n   f(x_{n+1}) - f(x_n) \\leq \\langle\\nabla f(x_n), x_{n+1} - x_n\\rangle + \\frac{L}{2}\\|x_{n+1} - x_n\\|_2^2\n  \\end{equation}\n  we get\n  \\begin{equation}\n   f(x_{n+1}) - f(x_n) \\leq \\frac{-1}{2L}\\|\\nabla f(x_n)\\|_2^2\n  \\end{equation}\n  Combining this with the convexity of $f$, which implies that\n  \\begin{equation}\n   f(x_n) - f(x^*) \\leq \\langle\\nabla f(x_n), x_n - x^*\\rangle\n  \\end{equation}\n  we get\n  \\begin{equation}\n   L(n+1) - L(n) \\leq \\frac{-n}{2L}\\|\\nabla f(x_n)\\|_2^2 \\leq 0\n  \\end{equation}\n  This means that $L(n+1)\\leq L(n)$ and thus $L(n) \\leq L(0)$. So we have\n  \\begin{equation}\n   n(f(x_n) - f(x^*)) \\leq L(n) \\leq L(0) = \\frac{L}{2}\\|x_0 - x^*\\|_2^2\n  \\end{equation}\n  as desired.\n\n \\end{proof}\n \n To conclude this subsection, we address the practical issue that the smoothness parameter $L$ may not be known a priori.\n It turns out that we can achieve the same convergence rate by using a variable step size, which potentially decreases \n in each iteration, to ensure that the Armijo condition\n \\begin{equation}\\label{armijo_condition}\n  f(x_n - s_n\\nabla f(x_n)) \\leq f(x_n) - \\frac{s_n^2}{2}\\|\\nabla f(x_n)\\|_2^2\n \\end{equation}\n is satisfied. In a practical algorithm, we would start with an initial step size $s_0$ and decrease it appropriately whenever\n (\\ref{armijo_condition}) isn't satified. If $f$ is $L$-smooth, we never need to take $s_n$ smaller than $\\frac{1}{L}$.\n \n We have the following convergence result in this case.\n \\begin{theorem}\n  Suppose that $f(x)$ is convex and differentiable. Let the iterates $x_n$ be given by\n  \\begin{equation}\n   x_{n+1} = x_n - s_n\\nabla f(x_n)\n  \\end{equation}\n  where $s_n \\leq s_{n-1}$ is chosen so that (\\ref{armijo_condition}) holds. Then\n  \\begin{equation}\n   f(x_n) - f(x^*) \\leq \\frac{1}{2ns_n}\\|x_0 - x^*\\|_2^2\n  \\end{equation}\n \\end{theorem}\n The proof is very similar to the proof of Theorem \\ref{gradient_descent_convergence_smooth} and we omit it. The relevant\n (discrete) Lyapunov function is\n \\begin{equation}\n  L(n) = ns_n(f(x_n) - f(x^*)) + \\frac{1}{2}\\|x_n - x^*\\|_2^2\n \\end{equation}\n\n \n\\subsection{Adding Momentum}\nIn this subsection, we introduce the idea of `adding momentum' to the gradient descent method (\\ref{gradient_descent_smooth}).\nWe will explain what adding momentum means and which effect it has by consider the corresponding \ncontinuous dynamics.\n\nThe physical intuition behind `adding momentum' is to consider a particle (of unit mass) trapped in a potential given\nby the objective $f(x)$. Such a particle would follow the Newtonian dynamics with acceleration given by $-\\nabla f$\n\\begin{equation}\n \\dot{x} = v,~\\dot{v} = - \\nabla f(x)\n\\end{equation}\nThis motion preserves the total energy, or Hamiltonian, given by\n\\begin{equation}\\label{hamiltonian}\n H(x,v) = \\frac{1}{2}\\|v\\|_2^2 + (f(x) - f(x^*))\n\\end{equation}\nwhere $x^*\\in \\arg\\min_x f(x)$.\n\nConsequently, unless the particle starts at $x^*$ with $v = 0$, the dynamics will continually oscillate around the\nminimizer $x^*$. Of course, we want out particle to settle at the minimizer $x^*$. To affect this, we add `friction'\nto the dynamics to get the following damped Hamiltonion dynamics\n\\begin{equation}\\label{momentum_descent_dynamics_smooth}\n \\dot{x} = v,~\\dot{v} = -\\alpha v - \\nabla f(x)\n\\end{equation}\nwhich can also be written as\n\\begin{equation}\n \\ddot{x}(t) + \\alpha \\dot{x}(t) + \\nabla f(x(t)) = 0\n\\end{equation}\nwhere $\\alpha$ is the damping rate, which determines how much friction there is.\n\nUnder this damped Hamiltonian dynamics, the Hamiltonian (\\ref{hamiltonian}) decays, as the following lemma shows.\n\\begin{lemma}\\label{hamiltonian_decay}\n Suppose that $x$ and $v$ satisfy the dynamics (\\ref{momentum_descent_dynamics_smooth}). Then\n \\begin{equation}\n  \\frac{d}{dt}H(x(t),v(t)) = -\\alpha\\|v(t)\\|_2^2\n \\end{equation}\n where $H(x,v)$ is the Hamiltonian in (\\ref{hamiltonian}).\n\n\\end{lemma}\n\\begin{proof}\n We calculate\n \\begin{align}\n  \\frac{d}{dt}H(x(t),v(t)) &= \\left\\langle\\frac{d}{dx}H(x(t),v(t)), \\dot{x}(t)\\right\\rangle + \n  \\left\\langle\\frac{d}{dv}H(x(t),v(t)), \\dot{v}(t)\\right\\rangle \\\\\n   &= \\langle \\nabla f(x(t)), v(t)\\rangle + \\langle v(t), -\\alpha v(t) - \\nabla f(x(t))\\rangle \\\\\n   &= -\\alpha\\|v(t)\\|_2^2\n \\end{align}\n  as desired.\n\\end{proof}\n\nIt is not a priori clear why following the dynamics (\\ref{momentum_descent_dynamics_smooth}) is better than following the\ngradient flow dynamics (\\ref{gradient_descent_dynamics_smooth}). We will see in later sections on accelerated gradient\ndescent for convex and strongly convex functions why the dynamics (\\ref{momentum_descent_dynamics_smooth}) leads to\nvery useful methods. \n\nFor now, we begin by considering the behavior of the damped Hamiltonian dynamics for smooth, convex\nobjectives. Using a Lyapunov argument, we obtain the following convergence result.\n\\begin{theorem}\\label{continuous_hamiltonian_convergence_smooth}\n Suppose that $x(t)$ and $y(t)$ satisfy the damped Hamiltonian dynamics (\\ref{momentum_descent_dynamics_smooth}) with $\\alpha > 0$ and\n let $H(x,v)$ be the Hamiltonian in (\\ref{hamiltonian}). Suppose also that $v(0) = 0$. Then if $f$ is convex and smooth, we have\n \\begin{equation}\\label{hamiltonian_decay_bound_smooth}\n  H(x(t),v(t)) \\leq \\left(t + \\frac{1}{2\\alpha}\\right)^{-1}\\left[\\frac{3}{2\\alpha}(f(x(0)) - f(x^*)) + \\frac{\\alpha}{2}\\left\\|x(0) - x^*\\right\\|_2^2\\right]\n \\end{equation}\n\n\\end{theorem}\nThe proof of this theorem will also provide a result for $v(0) \\neq 0$, but it is messier and we don't write it out explicitly.\n\\begin{proof}\n Consider the Lyapunov function\n $$\n  L(t) = \\left(t + \\frac{1}{2\\alpha}\\right)H(x(t),v(t)) + \\frac{1}{\\alpha}(f(x(t)) - f(x^*)) + \\frac{\\alpha}{2}\\|(x - x^*) + \\frac{1}{\\alpha}v\\|_2^2\n $$\n We calculate the derivative of $L(t)$ as follows. First we note that\n $$\n  \\frac{d}{dt}\\left[\\left(t + \\frac{1}{2\\alpha}\\right)H(x(t),v(t))\\right] = H(x(t),v(t)) + \\left(t + \\frac{1}{2\\alpha}\\right)\\frac{d}{dt}H(x(t),v(t))\n $$\n Using Lemma \\ref{hamiltonian_decay} we get\n \\begin{equation}\\label{eq700}\n  \\frac{d}{dt}\\left[\\left(t + \\frac{1}{2\\alpha}\\right)H(x(t),v(t))\\right] = H(x(t),v(t)) - \\alpha\\left(t + \\frac{1}{2\\alpha}\\right)\\|v(t)\\|_2^2\n \\end{equation}\n We also have\n \\begin{equation}\\label{eq704}\n  \\frac{d}{dt}\\left(\\frac{1}{\\alpha}(f(x(t)) - f(x^*))\\right) = \\frac{1}{\\alpha}\\langle\\nabla f(x(t)), \\dot{x}(t)\\rangle = \\frac{1}{\\alpha}\\langle\\nabla f(x(t)), v(t)\\rangle\n \\end{equation}\n and\n $$\n  \\frac{d}{dt}\\left(\\frac{\\alpha}{2}\\|(x - x^*) + \\frac{1}{\\alpha}v\\|_2^2\\right) = \\alpha\\left\\langle \\dot{x}(t) + \\frac{1}{\\alpha}\\dot{v}(t), (x - x^*) + \\frac{1}{\\alpha}v(t)\\right\\rangle\n $$\n Pluggin the dynamics (\\ref{momentum_descent_dynamics_smooth}) into this, we see that $\\dot{x}(t) + \\frac{1}{\\alpha}\\dot{v}(t) = -\\frac{1}{\\alpha}\\nabla f(x(t))$, and so\n \\begin{equation}\\label{eq712}\n  \\frac{d}{dt}\\left(\\frac{\\alpha}{2}\\|(x - x^*) + \\frac{1}{\\alpha}v\\|_2^2\\right) = -\\left\\langle\\nabla f(x(t)), x(t) - x^* + \\frac{1}{\\alpha}v(t)\\right\\rangle\n \\end{equation}\n Adding equations (\\ref{eq700}), (\\ref{eq704}), and (\\ref{eq712}), and noting that the convexity of $f$ implies\n \\begin{align}\n H(x(t),v(t)) &= \\frac{1}{2}\\|v(t)\\|_2^2 + (f(x(t)) - f(x^*)) \\\\\n &\\leq \\frac{1}{2}\\|v(t)\\|_2^2 + \\langle\\nabla f(x(t)), x(t) - x^*\\rangle\n \\end{align}\n we get\n \\begin{equation}\n  L^\\prime(t) \\leq -\\alpha t\\|v(t)\\|_2^2 \\leq 0\n \\end{equation}\n This means that $L(t) \\leq L(0)$ and so (using the assumption that $v(0) = 0$) we get\n \\begin{align}\n  &\\left(t + \\frac{1}{2\\alpha}\\right)H(x(t),v(t)) \\leq L(t)\\leq L(0) \\\\\n   &= \\frac{3}{2\\alpha}(f(x(0)) - f(x^*)) + \\frac{\\alpha}{2}\\left\\|x(0) - x^*\\right\\|_2^2\n \\end{align}\n as desired.\n\n\\end{proof}\n\nSo the damped Hamiltonian dynamics (\\ref{momentum_descent_dynamics_smooth}) obtains an $O(\\frac{1}{t})$ convergence rate\nsimilar to the gradient flow dynamics (\\ref{gradient_descent_dynamics_smooth}). We can actually relate these two dynamics more \nprecisely as follows. We consider the following form of equation (\\ref{momentum_descent_dynamics_smooth})\n$$ \\ddot{x}(t) + \\alpha \\dot{x}(t) + \\nabla f(x(t)) = 0\n$$\nWe first rescale time, setting $t^\\prime = t / \\alpha$ this becomes\n$$ \\frac{1}{\\alpha^2}\\ddot{x}(t^\\prime) + \\dot{x}(t^\\prime) + \\nabla f(x(t^\\prime)) = 0\n$$\nNow sending $\\alpha\\rightarrow \\infty$ recovers the gradient flow dynamics\n$$\\dot{x}(t^\\prime) + \\nabla f(x(t^\\prime)) = 0\n$$\nSo one way of thinking about the relationship between the gradient flow and damped Hamiltonian dynamics is that the\ngradient flow arises as the overdamped and time rescaled limit of the Hamiltonian dynamics. \n\nWe can use this perspective to\nrelate Theorems \\ref{continuous_hamiltonian_convergence_smooth} and \\ref{smooth_gradient_dynamics_thm}. In particular,\nif we substitute $t = \\alpha t^\\prime$ into the bound\n$$H(x(t),v(t)) \\leq \\left(t + \\frac{1}{2\\alpha}\\right)^{-1}\\left[\\frac{3}{2\\alpha}(f(x(0)) - f(x^*)) + \\frac{\\alpha}{2}\\left\\|x(0) - x^*\\right\\|_2^2\\right]\n$$\nand take a limit as $\\alpha\\rightarrow \\infty$, we recover the bound from Theorem \\ref{smooth_gradient_dynamics_thm}\n$$f(x(t^\\prime)) - f(x^*) \\leq H(x(t^\\prime),v(t^\\prime)) \\leq \\frac{1}{2t^\\prime}\\|x(0) - x^*\\|_2^2\n$$\n\nTo conclude this subsection, we consider the problem of discretizing the dynamics (\\ref{momentum_descent_dynamics_smooth}).\nWe saw that the simple gradient descent discretization (\\ref{gradient_descent_smooth}) of the gradient flow achieved\nthe same convergence rate\n(as long as the step size was sufficiently small, see Theorem \\ref{gradient_descent_convergence_smooth}). \nWe wish to find an analogous discretization\nof (\\ref{momentum_descent_dynamics_smooth}).\n\nThere are many discrete schemes that correspond to the Hamiltonian dynamics (\\ref{momentum_descent_dynamics_smooth}). However,\none of the most robust schemes for the purpose of convex optimization is\n\\begin{equation}\\label{momentum_gradient_descent_smooth}\n x_{n+1} = y_n - s\\nabla f(y_n),~y_{n+1} = x_{n+1} + s\\alpha (x_{n+1} - x_n),~x_0 = y_0\n\\end{equation}\n\n\\section{Strongly Convex Functions}\nIn this section we strengthen our assumptions on the objective function $f$ and examine how this impacts the convergence rate we\ncan obtain. \n\nIn particular, we assume that the function $f$ is $\\alpha$-strongly convex. This means that \n$f - \\frac{\\alpha}{2}\\|x\\|_2^2$ is convex and is equivalent to the bound\n\\begin{equation}\n f(y) \\geq f(x) + \\langle g, y - x\\rangle + \\frac{\\alpha}{2}\\|y-x\\|_2^2\n\\end{equation}\n\n\n\\input{6DL/DualAveraging}\n\\input{6DL/RegularizedDualAveraging}", "meta": {"hexsha": "d4c12aed9a42b8e5e5fc4fa0dd15ba68a98fddba", "size": 61635, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/SubgradientMethods.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/SubgradientMethods.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/SubgradientMethods.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.100591716, "max_line_length": 224, "alphanum_fraction": 0.6698953517, "num_tokens": 22912, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7189588018605838}}
{"text": "\\subsection{Propositional logic}\\label{subsec:propositional_logic}\n\n\\begin{remark}\\label{rem:propositional_language_is_alphabet}\n  The \\hyperref[def:propositional_language]{language of propositional logic} is, strictly speaking, an \\hyperref[def:formal_language/alphabet]{alphabet} rather than a \\hyperref[def:formal_language/language]{language}. Nonetheless, this is the established terminology.\n\\end{remark}\n\n\\begin{definition}\\label{def:propositional_language}\\mcite[sec. 7.2]{OpenLogicFull}\n  The \\term{language of propositional logic} consists of:\n\n  \\begin{thmenum}\n    \\thmitem{def:propositional_language/prop} A nonempty, \\hyperref[def:set_countability/at_most_countable]{at most countable} set \\( \\boldop{Prop} \\) of \\term{propositional variables}. Technically, we can have different languages with different variables, but it is safe to assume that there is only one single language of propositional language.\n\n    \\thmitem{def:propositional_language/constants} Two \\term{propositional constants} (also known as \\term{truth values}):\n    \\begin{thmenum}\n      \\thmitem{def:propositional_language/constants/verum} The \\term{verum} \\( \\top \\).\n      \\thmitem{def:propositional_language/constants/falsum} The \\term{falsum} \\( \\bot \\).\n    \\end{thmenum}\n\n    \\thmitem{def:propositional_language/negation} \\term{Negation} \\( \\neg \\).\n    \\thmitem{def:propositional_language/connectives} The set \\( \\Sigma \\) of \\term{propositional connectives}, namely\n    \\begin{thmenum}\n      \\thmitem{def:propositional_language/connectives/conjunction} \\term{Conjunction} \\( \\wedge \\) (also known as \\hyperref[def:standard_boolean_operators]{\\term{and}} and \\hyperref[def:semilattice/meet]{\\term{meet}}).\n      \\thmitem{def:propositional_language/connectives/disjunction} \\term{Disjunction} \\( \\vee \\) (also known as \\hyperref[def:standard_boolean_operators]{\\term{or}} and \\hyperref[def:semilattice/join]{\\term{join}}).\n      \\thmitem{def:propositional_language/connectives/conditional} \\term{Conditional} \\( \\rightarrow \\) (also known as \\term{if\\ldots then} and \\hyperref[def:material_implication]{\\term{material implication}}).\n      \\thmitem{def:propositional_language/connectives/biconditional} \\term{Biconditional} \\( \\leftrightarrow \\) (also known as \\term{iff} and \\term{material equivalence}).\n    \\end{thmenum}\n\n     Note that \\enquote{conditional} and \\enquote{biconditional} are nouns in this context.\n\n    \\thmitem{def:propositional_language/parentheses} Parentheses \\( ( \\) and \\( ) \\) for defining the order of operations unambiguously (see \\fullref{rem:propositional_formula_parentheses}).\n  \\end{thmenum}\n\n  \\Fullref{rem:smaller_propositional_language} shows we can actually utilize a smaller propositional language without losing any of its semantics.\n\\end{definition}\n\n\\begin{definition}\\label{def:propositional_syntax}\n  The following related definitions constitute what is called the \\term{syntax of propositional logic}.\n\n  \\begin{thmenum}\n    \\thmitem{def:propositional_syntax/grammar_schema} Consider the following \\hyperref[ex:natural_number_arithmetic_grammar/backus_naur_form]{grammar schema}:\n    \\begin{bnf*}\n      \\bnfprod{variable}   {P \\in \\boldop{Prop}} \\\\\n      \\bnfprod{connective} {\\circ \\in \\Sigma} \\\\\n      \\bnfprod{formula}    {\\bnfpn{variable} \\bnfor} \\\\\n      \\bnfmore             {\\bnfts{\\( \\top \\)} \\bnfor \\bnfts{\\( \\bot \\)} \\bnfor} \\\\\n      \\bnfmore             {\\bnfts{\\( \\neg \\)} \\bnfpn{formula} \\bnfor} \\\\\n      \\bnfmore             {\\bnfts{(} \\bnfsp \\bnfpn{formula} \\bnfsp \\bnfpn{connective} \\bnfsp \\bnfpn{formula} \\bnfsp \\bnfts{)}}\n    \\end{bnf*}\n\n    Note that \\( \\boldop{Prop} \\) may be infinite, in which case the grammars may have infinitely many rules. If needed, we can circumvent this by introducing an appropriate naming convention for variables, for example by allowing arbitrary strings of alphanumeric characters for variable names.\n\n    For the sake of readability, we will be using the conventions in \\fullref{rem:propositional_formula_parentheses} regarding parentheses.\n\n    \\thmitem{def:propositional_syntax/formula} The set \\( \\boldop{Form} \\) of \\term{propositional formulas} is the language \\hyperref[def:grammar_derivation/grammar_language]{generated} by this grammar schema with \\( \\bnfpn{formula} \\) as a starting rule. Propositional formulas are also called sentenced unlike in first-order logic where only specific formulas are called sentences --- see \\fullref{def:first_order_syntax/ground_formula}.\n\n    The grammar of propositional formulas is unambiguous as shown by \\fullref{thm:propositional_formulas_are_unambiguous}, which makes it possible to perform proofs via \\fullref{thm:structural_induction_on_unambiguous_grammars}.\n\n    \\thmitem{def:propositional_syntax/subformula} If \\( \\varphi \\) and \\( \\psi \\) are formulas and \\( \\psi \\) is a \\hyperref[def:formal_language/subword]{subword} of \\( \\varphi \\), we say that \\( \\psi \\) is a \\term{subformula} of \\( \\varphi \\).\n\n    \\thmitem{def:propositional_syntax/variables} For each formula \\( \\varphi \\), we inductively define its \\term{variables} to be elements of the set\n    \\begin{equation}\\label{eq:def:propositional_syntax/varables}\n      \\boldop{Var}(\\varphi) \\coloneqq \\begin{cases}\n        \\varnothing,                                  &\\varphi \\in \\set{ \\top, \\bot } \\\\\n        \\set{ P },                                    &\\varphi = P \\in \\boldop{Prop} \\\\\n        \\boldop{Var}(\\psi),                           &\\varphi = \\neg \\psi \\\\\n        \\boldop{Var}(\\psi) \\cup \\boldop{Var}(\\theta), &\\varphi = \\psi \\bincirc \\theta, \\bincirc \\in \\Sigma.\n      \\end{cases}\n    \\end{equation}\n\n    Note that \\( \\boldop{Var}(\\varphi) \\) can naturally be totally ordered by the position of the first occurrence of a variable.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:propositional_formulas_are_unambiguous}\n  The grammar of \\hyperref[def:propositional_syntax/formula]{propositional formulas} is \\hyperref[def:grammar_derivation/unambiguous]{unambiguous}.\n\\end{proposition}\n\\begin{proof}\n  The proof is analogous to \\fullref{ex:natural_number_arithmetic_grammar/derivation}.\n\\end{proof}\n\n\\begin{remark}\\label{rem:propositional_formula_parentheses}\n  We use the following two \\enquote{abuse-of-notation} conventions regarding parentheses:\n  \\begin{thmenum}\n    \\thmitem{rem:propositional_formula_parentheses/outermost} We may skip the outermost parentheses in formulas with top-level \\hyperref[def:propositional_language/connectives]{connectives}, e.g. we may write \\( P \\wedge Q \\) rather than \\( (P \\wedge Q) \\).\n\n    \\thmitem{rem:propositional_formula_parentheses/associative} Because of the associativity of \\( \\wedge \\) and \\( \\vee \\) (see \\fullref{def:propositional_formula_induced_function} and \\fullref{def:standard_boolean_operators}), we may skip the parentheses in chains like\n    \\begin{equation*}\n      ( \\ldots ((P_1 \\wedge P_2) \\wedge P_3) \\wedge \\ldots \\wedge P_{n-1} ) \\wedge P_n.\n    \\end{equation*}\n    and instead write\n    \\begin{equation*}\n      P_1 \\wedge P_2 \\wedge \\ldots \\wedge P_{n-1} \\wedge P_n.\n    \\end{equation*}\n\n    \\thmitem{rem:first_order_formula_parentheses/additional} Although not formally necessary, for the sake of readability we may choose to add parentheses around certain formulas like\n    \\begin{equation*}\n      \\neg P \\vee \\neg Q.\n    \\end{equation*}\n    and instead write\n    \\begin{equation*}\n      (\\neg P) \\vee \\neg Q.\n    \\end{equation*}\n\n    This latter convention is more useful for quantifiers in \\hyperref[def:first_order_syntax/formula]{first-order formulas}.\n  \\end{thmenum}\n\n  These are only notations shortcuts in the \\hyperref[rem:metalogic]{metalanguage} and the formulas themselves (as abstract mathematical objects) are still assumed to contain parentheses that help them avoid syntactic ambiguity (see \\fullref{thm:propositional_formulas_are_unambiguous}).\n\\end{remark}\n\n\\begin{definition}\\label{def:material_implication}\n  Theorems in mathematics usually have the form \\( P \\rightarrow Q \\). Formulas of this form are called \\term{material implications} in order to distinguish them from logical implication, which relates to the metatheoretic concept of \\hyperref[def:propositional_semantics/entailment]{entailment} (see \\cite{MathSE:material_vs_logical_implication}). Note that the term \\enquote{material implication} sometimes also refers to the \\hyperref[def:propositional_language/connectives/conditional]{conditional connective \\( \\rightarrow \\)} itself.\n\n  We introduce terminology that is conventionally used when dealing with theorems.\n\n  \\begin{thmenum}\n    \\thmitem{def:material_implication/sufficient_condition} \\( P \\) is a \\term{sufficient condition} for \\( Q \\).\n\n    \\thmitem{def:material_implication/necessary_condition} \\( Q \\) is a \\term{necessary condition} for \\( P \\).\n\n    \\thmitem{def:material_implication/antecedent} \\( P \\) the \\term{antecedent} of \\( \\varphi \\).\n\n    \\thmitem{def:material_implication/consequent} \\( Q \\) the \\term{consequent} of \\( \\varphi \\).\n\n    \\thmitem{def:material_implication/inverse} The formula \\( \\neg P \\rightarrow \\neg Q \\) is the \\term[bg=противоположна,ru=противоположная]{inverse} of \\( \\varphi \\).\n\n    \\thmitem{def:material_implication/converse} The formula \\( Q \\rightarrow P \\) is the \\term[bg=обратна,ru=обратная]{converse} of \\( \\varphi \\).\n\n    \\thmitem{def:material_implication/contrapositive} The formula \\( \\neg Q \\rightarrow \\neg P \\) is the \\term{contrapositive} of \\( \\varphi \\). In classical logic, it is \\hyperref[def:propositional_semantics/equivalence]{equivalent} to the original formula due to \\fullref{thm:boolean_equivalences/contrapositive}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:propositional_valuation}\n  We define \\term[bg=оценка,ru=оценка]{valuations} for propositional formulas. It is possible to define different valuations, so in case of doubt, we will refer to the one defined here as the \\term{classical valuation} giving \\term{classical semantics}.\n\n  This valuation implicitly depends on the \\hyperref[def:boolean_algebra]{Boolean algebra} fixed in \\fullref{def:boolean_function}. When dealing with Heyting semantics (see \\fullref{def:propositional_heyting_algebra_semantics}), we use more general Heyting algebras where not only the top and bottom, but also other values are utilized.\n\n  \\begin{thmenum}\n    \\thmitem{def:propositional_valuation/interpretation} A \\term{propositional interpretation} is a function with signature \\( I: \\boldop{Prop} \\to \\set{ T, F } \\). See \\fullref{def:boolean_value} for remarks regarding the \\hyperref[def:boolean_algebra]{Boolean algebra} \\( \\set{ T, F } \\) and the \\fullref{def:standard_boolean_operators} for a list of some standard Boolean operators.\n\n    \\thmitem{def:propositional_valuation/formula_valuation} Given an interpretation \\( I \\), we define the \\term{valuation} of a formula \\( \\varphi \\) inductively as\n    \\begin{equation}\\label{eq:def:propositional_valuation/formula_interpretation}\n      \\varphi\\Bracks{I} \\coloneqq \\begin{cases}\n        T,                                         &\\varphi = \\top \\\\\n        F,                                         &\\varphi = \\bot \\\\\n        I(P),                                      &\\varphi = P \\in \\boldop{Prop} \\\\\n        \\overline{\\psi\\Bracks{I}},                 &\\varphi = \\neg \\psi \\\\\n        \\psi_1\\Bracks{I} \\bincirc \\psi_2\\Bracks{I} &\\varphi = \\psi_1 \\bincirc \\psi_2, \\bincirc \\in \\Sigma,\n      \\end{cases}\n    \\end{equation}\n  \\end{thmenum}\n  where \\( \\bincirc \\) on the left denotes the \\hyperref[def:standard_boolean_operators]{Boolean operator} corresponding to the connective \\( \\bincirc \\) on the right.\n\\end{definition}\n\n\\begin{remark}\\label{rem:propositional_formula_valuation_without_variable_assignment}\n  If we know that \\( \\boldop{Var}(\\varphi) \\subseteq \\{ P_1, \\ldots, P_n \\} \\), it follows that the \\hyperref[def:first_order_valuation/formula_valuation]{valuation} \\( \\varphi\\Bracks{I} \\) only depends on the particular values \\( I(P_1), \\ldots, I(P_n) \\) of \\( I \\).\n\n  Let \\( x_1, \\ldots, x_n \\in \\set{ F, T } \\) and let \\( I \\) be such that \\( I(P_k) = x_k \\) for \\( k = 1, \\ldots, n \\). We introduce the notation\n  \\begin{equation}\\label{eq:rem:propositional_formula_valuation_without_variable_assignment/short_semantic}\n    \\varphi\\Bracks{x_1, \\ldots, x_n}\n  \\end{equation}\n  for \\( \\varphi\\Bracks{I} \\) because the rest of the interpretation \\( I \\) plays no role here. We may also use\n  \\begin{equation}\\label{eq:rem:propositional_formula_valuation_without_variable_assignment/short_syntactic}\n    \\varphi[\\psi_1, \\ldots, \\psi_n]\n  \\end{equation}\n  to denote \\hyperref[def:propositional_substitution]{substitution}.\n\n  When using this notation, we implicitly assume that \\( \\boldop{Var}(\\varphi) \\subseteq \\set{ P_1, \\ldots, P_n } \\).\n\\end{remark}\n\n\\begin{definition}\\label{def:propositional_formula_induced_function}\n  Let \\( \\varphi \\) be a propositional formula and let \\( \\boldop{Var}(\\varphi) = \\set{ P_1, \\ldots, P_n } \\) be an ordering of the free variables of \\( \\varphi \\). We define the \\hyperref[def:boolean_function]{Boolean function}\n  \\begin{equation}\\label{eq:def:propositional_formula_induced_function}\n    \\begin{split}\n      &\\fun_\\varphi: \\set{ T, F }^n \\to \\set{ T, F } \\\\\n      &\\fun_\\varphi(x_1, \\ldots, x_n) \\coloneqq \\varphi\\Bracks{x_1, \\ldots, x_n}.\n    \\end{split}\n  \\end{equation}\n\\end{definition}\n\n\\begin{definition}\\label{def:propositional_semantics}\n  We now define \\term{semantical} properties of propositional formulas. Because of the connection with \\hyperref[def:boolean_function]{Boolean functions} given in \\fullref{def:propositional_formula_induced_function}, we also formulate some of the properties using Boolean functions.\n\n  \\begin{thmenum}\n    \\thmitem{def:propositional_semantics/satisfiability}\\mcite[def. 7.14]{OpenLogicFull} Given an interpretation \\( I \\) and a set \\( \\Gamma \\) of formulas, we say that \\( I \\) \\term{satisfies} \\( \\Gamma \\) if, for every formula \\( \\varphi \\in \\Gamma \\) we have \\( \\varphi\\Bracks{I} = T \\).\n\n    We also say that \\( I \\) is a \\term{model} of \\( \\Gamma \\) and write \\( I \\vDash \\Gamma \\).\n\n    If \\( \\Gamma = \\set{ \\gamma_1, \\ldots, \\gamma_n } \\) is a finite ordered set, we use the shorthand \\( I \\vDash \\gamma_1, \\ldots, \\gamma_n \\) rather than \\( I \\vDash \\set{ \\gamma_1, \\ldots, \\gamma_n } \\). In particular, if \\( \\Gamma = \\set{ \\varphi } \\) we write \\( I \\vDash \\varphi \\).\n\n    Note that every interpretation vacuously satisfies the empty set \\( \\Gamma = \\varnothing \\) of formulas.\n\n    We say that \\( \\Gamma \\) is \\term{satisfiable} if there exists a model for \\( \\Gamma \\).\n\n    \\thmitem{def:propositional_semantics/entailment} We say that the set of formulas \\( \\Gamma \\) \\term{entails} the set of formulas \\( \\Delta \\) and write \\( \\Gamma \\vDash \\Delta \\) if either of the following hold:\n    \\begin{itemize}\n      \\thmitem{def:propositional_semantics/entailment/direct} Every model of \\( \\Gamma \\) is also a model of \\( \\Delta \\).\n      \\thmitem{def:propositional_semantics/entailment/functional} The following \\hyperref[thm:def:function/properties/preimage]{preimage} inclusion holds:\n      \\begin{equation*}\n        \\bigcap_{\\varphi \\in \\Gamma} \\fun_\\varphi^{-1}(T) \\subseteq \\bigcap_{\\psi \\in \\Delta} \\fun_\\psi^{-1}(T).\n      \\end{equation*}\n    \\end{itemize}\n\n    \\thmitem{def:propositional_semantics/tautology} The formula \\( \\varphi \\) is a (semantic) \\term{tautology} if either:\n    \\begin{itemize}\n      \\thmitem{def:propositional_semantics/tautology/interpretations} Every interpretation satisfies \\( \\varphi \\).\n      \\thmitem{def:propositional_semantics/tautology/entailment} The empty set \\( \\Gamma = \\varnothing \\) of formulas entails \\( \\varphi \\), i.e. \\( \\vDash \\varphi \\).\n      \\thmitem{def:propositional_semantics/tautology/functional} The function \\( \\fun_\\varphi \\) is canonically true.\n    \\end{itemize}\n\n    We also say that \\( \\varphi \\) is \\term{valid}.\n\n    \\thmitem{def:propositional_semantics/contradiction} Dually, \\( \\varphi \\) is a (semantic) \\term{contradiction} if either:\n    \\begin{itemize}\n      \\thmitem{def:propositional_semantics/contradiction/interpretations} No interpretation satisfies \\( \\varphi \\).\n      \\thmitem{def:propositional_semantics/contradiction/entailment} The formula \\( \\varphi \\) entails \\( \\bot \\), i.e. \\( \\varphi \\vDash \\bot \\).\n      \\thmitem{def:propositional_semantics/contradiction/functional} The function \\( \\fun_\\varphi \\) is canonically false.\n    \\end{itemize}\n\n    \\thmitem{def:propositional_semantics/equivalence} We say that \\( \\varphi \\) and \\( \\psi \\) are \\term{semantically equivalent} and write \\( \\varphi \\gleichstark \\psi \\) if either:\n    \\begin{itemize}\n      \\thmitem{def:propositional_semantics/equivalence/interpretations} We have \\( \\varphi\\Bracks{I} = \\psi\\Bracks{I} \\) for every interpretation \\( I \\).\n      \\thmitem{def:propositional_semantics/equivalence/entailment} Both \\( \\varphi \\vDash \\psi \\) and \\( \\psi \\vDash \\varphi \\).\n    \\end{itemize}\n\n    \\thmitem{def:propositional_semantics/equisatisfiability} A weaker notion than that of semantic equivalence is that of \\term{equisatisfiability}. We say that the families \\( \\Gamma \\) and \\( \\Delta \\) are equisatisfiable if the following holds: \\enquote{\\( \\Gamma \\) is satisfiable if and only if \\( \\Delta \\) is satisfiable}. For single-formula families \\( \\Gamma = \\set{ \\varphi } \\) and \\( \\Delta = \\set{ \\psi } \\), the following are equivalent conditions for equisatisfiability:\n    \\begin{itemize}\n      \\thmitem{def:propositional_semantics/equisatisfiability/interpretations} There exist interpretations \\( I \\) and \\( J \\) such that \\( \\varphi\\Bracks{I} = \\psi\\Bracks{J} \\).\n      \\thmitem{def:propositional_semantics/equisatisfiability/functional} We have \\( \\fun_\\varphi = \\fun_\\psi \\) for the induced functions.\n    \\end{itemize}\n\n    A trivial example of equisatisfiable, but not equivalent formulas are \\( \\varphi = P \\) and \\( \\psi = Q \\) for \\( P \\neq Q \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{theorem}\\label{thm:lindenmaum_tarski_algebra_of_full_propositional_logic}\n  We give an explicit connection between \\hyperref[def:propositional_syntax/formula]{propositional formulas} and \\hyperref[def:boolean_function]{Boolean functions}.\n\n  \\begin{thmenum}\n    \\thmitem{thm:lindenmaum_tarski_algebra_of_full_propositional_logic/equivalence_classes} The \\hyperref[def:propositional_semantics/equivalence]{semantic equivalence} \\( \\gleichstark \\) is an equivalence relation on the set \\( \\boldop{Form} \\) of all propositional formulas.\n\n    \\thmitem{thm:lindenmaum_tarski_algebra_of_full_propositional_logic/bijection} The \\hyperref[def:lindenbaum_tarski_algebra]{Lindenbaum-Tarski algebra}  \\( \\boldop{Form} / {{}\\gleichstark} \\) of all propositional formulas with respect to semantic equivalence is bijective with the set of all \\hyperref[def:boolean_function]{Boolean functions} of arbitrary arity.\n\n    Both are provably Boolean algebras, but with very different proofs --- the Lindenbaum-Tarski algebra is Boolean due to the purely syntactic \\fullref{thm:intuitionistic_lindenbaum_tarski_algebra} and the set of all Boolean functions is a Boolean algebra due to the semantic \\fullref{thm:functions_over_model_form_model}. This is another demonstration of \\fullref{thm:classical_propositional_logic_is_sound_and_complete}.\n\n    See \\fullref{rem:thm:intuitionistic_lindenbaum_tarski_algebra/syntactic_proof}.\n  \\end{thmenum}\n\\end{theorem}\n\\begin{proof}\n  \\SubProofOf{thm:lindenmaum_tarski_algebra_of_full_propositional_logic/equivalence_classes} Follows from the equivalences in \\fullref{def:equivalence_relation}.\n\n  \\SubProofOf{thm:lindenmaum_tarski_algebra_of_full_propositional_logic/bijection} Follows from the equivalences in \\fullref{def:propositional_semantics/equivalence}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:boolean_equivalences}\n  The following (and many more) are called \\term{Boolean equivalences} because they are actually statements about our choice of \\hyperref[def:standard_boolean_operators]{standard Boolean operators}. They are formulated here because the framework of propositional logic is more convenient for stating the equivalences. Note that most of these equivalences fail in \\hyperref[def:intuitionistic_propositional_deductive_systems]{intuitionistic logic}.\n\n  For arbitrary propositional formulas \\( \\varphi \\) and \\( \\psi \\), the following semantic equivalences hold:\n  \\begin{thmenum}\n    \\thmitem{thm:boolean_equivalences/negation_bottom} \\hyperref[def:propositional_language/negation]{Negation} can be expressed via the \\hyperref[def:propositional_language/constants/falsum]{falsum}:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/negation_bottom}\n      \\begin{split}\n        \\mathllap{\\neg \\varphi} &\\gleichstark \\mathrlap{\\varphi \\rightarrow \\bot}.\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/double_negation} \\hyperref[def:propositional_language/negation]{Negation} is an \\hyperref[def:set_with_involution]{involution}:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/double_negation}\n      \\begin{split}\n        \\mathllap{\\neg \\neg \\varphi} &\\gleichstark \\mathrlap{\\varphi}.\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/contrapositive} A \\hyperref[def:material_implication]{material implication} is equivalent to its \\hyperref[def:material_implication/contrapositive]{contrapositive}:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/contrapositive}\n      \\begin{split}\n        \\mathllap{\\varphi \\rightarrow \\psi} &\\gleichstark \\mathrlap{\\neg \\psi \\rightarrow \\neg \\varphi.}\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/conditional_as_disjunction} A \\hyperref[def:propositional_language/connectives/conditional]{conditional} is a \\hyperref[def:propositional_language/connectives/disjunction]{disjunction} with the \\hyperref[def:material_implication/antecedent]{antecedent} negated:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/conditional_as_disjunction}\n      \\begin{split}\n        \\mathllap{\\varphi \\rightarrow \\psi} &\\gleichstark \\mathrlap{ \\neg \\varphi \\vee \\psi. }\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/biconditional_via_conditionals} A \\hyperref[def:propositional_language/connectives/biconditional]{biconditional} is a \\hyperref[def:propositional_language/connectives/conjunction]{conjunction} of \\hyperref[def:propositional_language/connectives]{conditionals}:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/biconditional_via_conditionals}\n      \\begin{split}\n        \\mathllap{\\varphi \\leftrightarrow \\psi} &\\gleichstark \\mathrlap{(\\varphi \\rightarrow \\psi) \\wedge (\\psi \\rightarrow \\varphi).}\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/biconditional_as_conjunction} The \\hyperref[def:propositional_language/connectives/biconditional]{biconditional} is a \\hyperref[def:propositional_language/connectives/disjunction]{conjunction} of \\hyperref[def:propositional_language/connectives/conjunction]{disjunctions}:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/biconditional_as_conjunction}\n      \\begin{split}\n        \\mathllap{\\varphi \\leftrightarrow \\psi} &\\gleichstark \\mathrlap{(\\neg \\varphi \\vee \\psi) \\wedge (\\neg \\varphi \\vee \\psi).}\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/biconditional_as_disjunction} The \\hyperref[def:propositional_language/connectives/biconditional]{biconditional} is a \\hyperref[def:propositional_language/connectives/disjunction]{disjunction} of \\hyperref[def:propositional_language/connectives/conjunction]{conjunctions}:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/biconditional_as_disjunction}\n      \\begin{split}\n        \\mathllap{\\varphi \\leftrightarrow \\psi} &\\gleichstark \\mathrlap{(\\varphi \\wedge \\psi) \\vee (\\neg \\varphi \\wedge \\neg \\psi).}\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/biconditional_member_negation} A \\hyperref[def:propositional_language/connectives/biconditional]{biconditional} is equivalent its termwise negation:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/biconditional_member_negation}\n      \\begin{split}\n        \\mathllap{\\neg \\varphi \\leftrightarrow \\neg \\psi} &\\gleichstark \\mathrlap{\\varphi \\leftrightarrow \\psi.}\n      \\end{split}\n    \\end{equation}\n\n    \\thmitem{thm:boolean_equivalences/biconditional_negation} A negation of a \\hyperref[def:propositional_language/connectives/biconditional]{biconditional} is again a biconditional with one of the terms negated:\n    \\begin{equation}\\label{eq:thm:boolean_equivalences/biconditional_negation}\n      \\begin{split}\n        \\mathllap{\\neg \\parens{\\varphi \\leftrightarrow \\psi}}\n        &\\gleichstark\n        \\mathrlap{\\neg \\varphi \\leftrightarrow \\psi \\gleichstark}\n        \\\\ &\\gleichstark\n        \\mathrlap{\\varphi \\leftrightarrow \\neg \\psi.}\n      \\end{split}\n    \\end{equation}\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  The proofs follow directly from the table in \\fullref{def:standard_boolean_operators}.\n\\end{proof}\n\n\\begin{definition}\\label{def:propositional_substitution}\n  We sometimes want to substitute a propositional variable with another variable or even with a formula. This is akin to applying a \\hyperref[def:boolean_function]{Boolean function} like \\( x \\vee y \\) to different variables (e.g. to obtain \\( x \\vee x \\)) or even concrete values (e.g. \\( F \\vee T \\)), except that it is done on a purely syntactic level without involving any semantics involved.\n\n  It does not pose any technical difficulty to extend this definition beyond replacing a variable like it is usually done (e.g. \\cite[def. 7.8]{OpenLogicFull}). Not only that, we can then use this mechanism to define complicated rewriting rules as in \\fullref{alg:conjunctive_normal_form_reduction} and have semantic equivalence automatically follow from \\fullref{thm:propositional_substitution_equivalence}.\n\n  \\begin{thmenum}\n    \\thmitem{def:propositional_substitution/single} We define the \\term{substitution} of the propositional formula \\( \\theta \\) with \\( \\chi \\) in \\( \\varphi \\) as\n    \\begin{equation}\\label{eq:def:propositional_substitution/single}\n      \\varphi[\\theta \\mapsto \\chi] \\coloneqq \\begin{cases}\n        \\chi,                                                             &\\varphi = \\theta \\\\\n        \\varphi,                                                          &\\varphi \\neq \\theta \\T{and} \\varphi \\in \\set{ \\top, \\bot } \\cup \\boldop{Prop} \\\\\n        \\neg \\psi[\\theta \\mapsto \\chi],                                   &\\varphi \\neq \\theta \\T{and} \\varphi = \\neg \\psi \\\\\n        \\psi_1[\\theta \\mapsto \\chi] \\bincirc \\psi_2[\\theta \\mapsto \\chi], &\\varphi \\neq \\theta \\T{and} \\varphi = \\psi_1 \\bincirc \\psi_2, \\circ \\in \\Sigma.\n      \\end{cases}\n    \\end{equation}\n\n    Note that it is not strictly necessary for \\( \\theta \\) to be a subformula of \\( \\varphi \\).\n\n    In the case where \\( \\theta \\) is a single variable, if \\( P \\in \\boldop{Var}(\\varphi) \\), then \\( \\varphi[P \\mapsto \\chi] \\) is said to be an \\term{instance} of \\( \\varphi \\).\n\n    \\thmitem{def:propositional_substitution/simultaneous} We will now define \\term{simultaneous substitution} of \\( \\theta_1, \\ldots, \\theta_n \\) with \\( \\chi_1, \\ldots, \\chi_n \\). We wish to avoid the case where \\( \\theta_k \\) is a subformula of \\( \\chi_{k-1} \\) and it accidentally gets replaced during \\( \\varphi[\\theta_{k-1} \\mapsto \\chi_{k-1}][\\theta_k \\mapsto \\chi_k] \\).\n\n    Define\n    \\begin{equation*}\n      \\cat{Bound} \\coloneqq \\boldop{Var}(\\chi_1) \\cup \\ldots \\cup \\boldop{Var}(\\chi_n).\n    \\end{equation*}\n    and, for each variable \\( P_k \\) in \\( \\cat{Bound} \\), pick a variable \\( Q_k \\) from \\( \\boldop{Prop} \\setminus \\boldop{Bound} \\) (we implicitly assume the existence of enough variables in \\( \\boldop{Prop} \\)). Let \\( m \\) be the \\hyperref[def:cardinal]{cardinality} of \\( \\boldop{Bound} \\). The simultaneous substitution can now be defined as\n    \\begin{align*}\n      \\varphi[\\theta_1 \\mapsto \\chi_1, \\ldots, \\theta_n \\mapsto \\chi_n] \\coloneqq \\varphi\n      [\\theta_1 \\mapsto \\chi_1[P_1 \\mapsto Q_1, \\ldots, P_m \\mapsto Q_m]] \\\\\n      \\vdots \\hspace{3cm} \\\\\n      [\\theta_n \\mapsto \\chi_n[P_1 \\mapsto Q_1, \\ldots, P_m \\mapsto Q_m]] \\\\\n      [Q_1 \\mapsto P_1, \\ldots, Q_m \\mapsto P_m].\n    \\end{align*}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:propositional_substitution_equivalence}\n  If \\( \\theta \\) is a subformula of \\( \\varphi \\) and if \\( \\theta \\gleichstark \\chi \\), then\n  \\begin{equation}\\label{eq:thm:propositional_substitution_equivalence}\n    \\varphi[\\theta \\mapsto \\chi] \\gleichstark \\varphi.\n  \\end{equation}\n\n  By induction, this also holds for \\hyperref[def:propositional_substitution/simultaneous]{simultaneous substitution}.\n\\end{proposition}\n\\begin{proof}\n  We use structural induction on \\( \\varphi \\):\n\n  \\begin{itemize}\n    \\item If \\( \\varphi = \\theta \\), then \\( \\varphi[\\theta \\mapsto \\chi] = \\chi \\) and, by definition,\n    \\begin{equation*}\n      \\varphi = \\theta \\gleichstark \\chi = \\varphi[\\theta \\mapsto \\chi].\n    \\end{equation*}\n\n    \\item If \\( \\varphi \\neq \\theta \\) and \\( \\varphi \\in \\set{ \\top, \\bot } \\cup \\boldop{Prop} \\), then \\( \\varphi[\\theta \\mapsto \\chi] = \\varphi \\) and \\eqref{eq:thm:propositional_substitution_equivalence} again holds trivially.\n\n    \\item If \\( \\varphi \\neq \\theta \\) and \\( \\varphi = \\neg \\chi \\) and if the inductive hypothesis holds for \\( \\chi \\), then \\( \\varphi[\\theta \\mapsto \\chi] = \\neg \\psi[\\theta \\mapsto \\chi] \\). For any interpretation \\( I \\),\n    \\begin{equation*}\n      \\parens[\\Big]{ \\varphi[\\theta \\mapsto \\chi] }\\Bracks{I}\n      =\n      \\overline{\\parens[\\Big]{ \\psi[\\theta \\mapsto \\chi] }\\Bracks{I}}\n      \\reloset {\\T{ind.}} =\n      \\overline{\\psi\\Bracks{I}}\n      =\n      \\varphi\\Bracks{I}.\n    \\end{equation*}\n\n    Therefore, \\eqref{eq:thm:propositional_substitution_equivalence} holds in this case.\n\n    \\item If \\( \\varphi \\neq \\theta \\) and \\( \\varphi = \\psi_1 \\bincirc \\psi_2, \\bincirc \\in \\Sigma \\) and if the inductive hypothesis holds for both \\( \\psi_1 \\) and \\( \\psi_2 \\), then for any interpretation \\( I \\),\n    \\begin{equation*}\n      \\parens[\\Big]{ \\varphi[\\theta \\mapsto \\chi] }\\Bracks{I}\n      =\n      \\parens[\\Big]{ \\psi_1[\\theta \\mapsto \\chi] }\\Bracks{I} \\bincirc \\parens[\\Big]{ \\psi_2[\\theta \\mapsto \\chi] }\\Bracks{I}\n      \\reloset {\\T{ind.}} =\n      \\psi_1\\Bracks{I} \\bincirc \\psi_2\\Bracks{I}\n      =\n      \\varphi\\Bracks{I}.\n    \\end{equation*}\n\n    Therefore, \\eqref{eq:thm:propositional_substitution_equivalence} holds in this case also.\n  \\end{itemize}\n\n  We have verified that \\eqref{eq:thm:propositional_substitution_equivalence} holds in all cases.\n\\end{proof}\n\n\\begin{remark}\\label{rem:smaller_propositional_language}\n  For \\hyperref[def:propositional_semantics]{semantical} concepts, it is immaterial which element of an equivalence class we consider. \\hyperref[def:boolean_closure]{Complete sets of Boolean operations} allow us to represent each formula using a strict subset of the \\hyperref[def:propositional_language/constants]{propositional constants}, \\hyperref[def:propositional_language/negation]{negation} and \\hyperref[def:propositional_language/connectives]{connectives}. \\Fullref{ex:posts_completeness_theorem} shows some concrete commonly used complete sets of Boolean operations. This is also the motivation for studying \\hyperref[def:lindenbaum_tarski_algebra]{Lindenbaum-Tarski algebras}.\n\n  This is useful in\n  \\begin{itemize}\n    \\item Reduction to normal forms such as the \\hyperref[def:conjunctive_disjunctive_normal_form]{conjunctive normal form} in \\fullref{alg:conjunctive_normal_form_reduction}.\n\n    \\item \\hyperref[def:propositional_semantics/satisfiability]{Satisfiability} proofs that rely on \\hyperref[rem:structural_recursion_and_induction]{structural induction} because it allows us to consider less cases in the induction.\n\n    \\item Having fewer rules in \\hyperref[alg:conjunctive_normal_form_reduction]{deductive systems}. For example, we may choose to add \\eqref{eq:thm:minimal_propositional_negation_laws/pierce} to the axioms of the \\hyperref[def:positive_implicational_deductive_system]{positive implicational derivation system} and due to \\fullref{thm:minimal_propositional_negation_laws} this derivation system would be able to emulate the \\hyperref[def:classical_propositional_deductive_systems]{classical derivation system}.\n  \\end{itemize}\n\\end{remark}\n\n\\begin{definition}\\label{def:conjunctive_disjunctive_normal_form}\n  We will now introduce the conjunctive and disjunctive normal forms.\n\n  \\begin{thmenum}\n    \\thmitem{def:conjunctive_disjunctive_normal_form/literal} A \\term{literal} is either a propositional variable \\( L = P \\) or a negation \\( L = \\neg P \\) of a propositional variable. These are called \\term{positive} and \\term{negative} literals, correspondingly.\n\n    \\thmitem{def:conjunctive_disjunctive_normal_form/normal_form} A propositional formula \\( \\varphi \\) is in \\term{conjunctive normal form} (resp. \\term{disjunctive normal form}) if \\( \\varphi \\) is a finite conjunction of disjunctions (resp. finite disjunction of conjunctions) of literals. That is, if \\( \\varphi \\) is in conjunctive normal form, it has the form\n    \\begin{equation*}\n      (L_{1,1} \\vee \\ldots \\vee L_{1,n_1}) \\wedge \\cdots \\wedge (L_{k,1} \\vee \\ldots \\vee L_{k,n_k}).\n    \\end{equation*}\n\n    \\thmitem{def:conjunctive_disjunctive_normal_form/conjunct_disjunct} A \\term{disjunct} (resp. a \\term{conjunct}) is a set of literals, the difference between the two being the context in which they are used. To each formula in conjunctive normal form there corresponds a set of disjuncts and to each formula in disjunctive normal form there corresponds a set of conjuncts.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{algorithm}\\label{alg:conjunctive_normal_form_reduction}\n  Let \\( \\varphi \\) be any formula. We explicitly derive a formula in conjunctive normal form that is \\hyperref[def:propositional_semantics/equivalence]{semantically equivalent} to \\( \\varphi \\). In a software implementation, we can easily construct an efficient recursive procedure based on the following steps.\n\n  \\begin{thmenum}\n    \\thmitem{alg:conjunctive_normal_form_reduction/constants} Pick any variable \\( P \\) and substitute\n    \\begin{align*}\n      \\top \\T{with} P \\vee \\neg P, && \\bot \\T{with} P \\wedge \\neg P\n    \\end{align*}\n    to get rid of the \\hyperref[def:propositional_language/constants]{propositional constants}.\n\n    \\thmitem{alg:conjunctive_normal_form_reduction/iff} For any subformulas \\( \\psi \\) and \\( \\theta \\) of \\( \\varphi \\), perform the substitution\n    \\begin{equation*}\n      \\psi \\leftrightarrow \\theta \\T{with} (\\psi \\rightarrow \\theta) \\wedge (\\theta \\rightarrow \\psi)\n    \\end{equation*}\n    to get rid of \\hyperref[def:propositional_language/connectives/biconditional]{biconditional connectives}. Semantic equivalence with \\( \\varphi \\) is then justified by \\fullref{thm:boolean_equivalences/biconditional_via_conditionals}.\n\n    \\thmitem{alg:conjunctive_normal_form_reduction/implies} For any subformulas \\( \\psi \\) and \\( \\theta \\) of \\( \\varphi \\), perform the substitution\n    \\begin{equation*}\n      \\psi \\rightarrow \\theta \\T{with} \\neg \\psi \\vee \\theta.\n    \\end{equation*}\n    to get rid of \\hyperref[def:propositional_language/connectives/conditional]{conditional connectives}. Equivalence with \\( \\varphi \\) is justified by \\fullref{thm:boolean_equivalences/conditional_as_disjunction}.\n\n    \\thmitem{alg:conjunctive_normal_form_reduction/de_morgan} For any subformulas \\( \\psi \\) and \\( \\theta \\) of \\( \\varphi \\), use \\fullref{thm:de_morgans_laws} to justify the substitution\n    \\begin{align*}\n      \\neg(\\psi \\vee \\theta) \\T{with} \\neg \\psi \\wedge \\neg \\theta\n      &&\n      \\neg(\\psi \\wedge \\theta) \\T{with} \\neg \\psi \\vee \\neg \\theta.\n    \\end{align*}\n\n    In order to ensure that \\hyperref[def:propositional_language/negation]{negation} is only present before propositional variables, repeat \\ref{alg:conjunctive_normal_form_reduction/de_morgan} until we reach a fixed point, i.e. until nothing is substituted anymore.\n\n    \\thmitem{alg:conjunctive_normal_form_reduction/double_negation} For any variable \\( P \\) of \\( \\varphi \\), use \\fullref{eq:thm:boolean_equivalences/double_negation} to justify the substitution\n    \\begin{equation*}\n      \\neg \\neg P \\T{with} P.\n    \\end{equation*}\n\n    \\thmitem{alg:conjunctive_normal_form_reduction/distributivity} Finally, for any subformulas \\( \\psi \\), \\( \\theta \\) and \\( \\chi \\) of \\( \\varphi \\), use \\hyperref[eq:def:semilattice/distributive_lattice/finite/join_over_meet]{distributivity} of \\( \\vee \\) over \\( \\wedge \\) to justify the substitution\n    \\begin{equation*}\n      \\psi \\vee (\\theta \\wedge \\chi) \\T{with} (\\psi \\vee \\theta) \\wedge (\\theta \\vee \\chi).\n    \\end{equation*}\n\n    In order to ensure that conjunction is always one level higher than disjunction, repeat \\ref{alg:conjunctive_normal_form_reduction/distributivity} until we reach a fixed point.\n  \\end{thmenum}\n\n  The resulting formula is in conjunctive normal form. As a consequence of \\fullref{thm:propositional_substitution_equivalence}, it is equivalent to \\( \\varphi \\).\n\\end{algorithm}\n", "meta": {"hexsha": "cf6187842cd94261ebe37648d42bceef430e0826", "size": 37261, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/propositional_logic.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/propositional_logic.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/propositional_logic.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 75.8879837067, "max_line_length": 687, "alphanum_fraction": 0.7291269692, "num_tokens": 11018, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7189587843274104}}
{"text": "\\section{Stokes's Theorem}\r\n\\noindent\r\nLet $C$ be a closed, counter-clockwise oriented curve in $\\mathbb{R}^2$, and let $D$ be the region contained within $C$. Let $S$ be an open surface with opening boundary $C$, and let $V$ be the region contained inside $\\tilde{S} = D \\cup S$.\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nFinding the flux of $\\nabla \\times \\vec{F}$,\r\n\\begin{equation*}\r\n\t\\oint\\limits_{\\tilde{S}}\\oint{\\nabla \\times \\vec{F}} = \\iiint\\limits_{V}{\\nabla \\cdot (\\nabla \\times \\vec{F})\\mathrm{d}V}\r\n\\end{equation*}\r\nby Divergence Theorem. Since $\\nabla \\cdot (\\nabla \\times \\vec{F}) = 0$, \r\n\\begin{equation*}\r\n\t\\iint\\limits_{D}{\\nabla \\times \\vec{F}\\mathrm{d}A} = \\iint\\limits_{S}{\\nabla \\times \\vec{F} \\cdot \\mathrm{d}\\vec{s}}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\oint\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}} = \\iint\\limits_{S}{\\nabla \\times \\vec{F} \\cdot \\mathrm{d}\\vec{s}}\r\n\\end{equation*}\r\nby Green's Theorem for Circulation. This is Stokes's Theorem.\\\\\r\n\r\n\\noindent\r\nFor example, let's use Stokes's Theorem to evaluate $\\iint\\limits_{S}{\\nabla \\times \\vec{F} \\cdot \\mathrm{d}\\vec{s}}$ where $S$ is the hemisphere $x^2 + y^2 + z^2 = 4, x \\geq 0$ and $\\vec{F}(x,y,z) = \\langle yz, x\\sin{z}, xyz^2 \\rangle$.\r\n\\begin{equation*}\r\n\tS = \\left\\{(x,y,z) \\mid x^2 + y^2 + z^2 = 2^2, x \\geq 0 \\right\\}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\tC = \\left\\{(y,z) \\mid y^2 + z^2 = 2^2 \\right\\} = \\left\\{(r,\\theta) \\mid r = 2, 0 \\leq \\theta \\leq 2\\pi \\right\\}\r\n\\end{equation*}\r\nwhere $\\theta$ is in the yz-plane.\r\n\\begin{equation*}\r\n\tC = \\vec{r}(t) = \\langle 0, 2\\cos{t}, 2\\sin{t} \\rangle, 0 \\leq t \\leq 2\\pi\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\vec{F}\\circ\\vec{r} = \\langle 4\\cos{t}\\sin{t}, 0, 0 \\rangle\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\vec{r^\\prime}(t) = \\langle 0, -2\\sin{t}, 2\\cos{t}\\rangle\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\left(\\vec{F}\\circ\\vec{r}\\right) \\cdot \\vec{r^\\prime} = 0.\r\n\\end{equation*}\r\nSo, \r\n\\begin{equation*}\r\n\t\\iint\\limits_{S}{\\nabla \\times \\vec{F}\\mathrm{d}A} = \\oint_{0}^{2\\pi}{0\\mathrm{d}t} = 0\r\n\\end{equation*}\r\n\r\n\\input{./vectorAnalysis/faradaysLawInductionAmperesLaw}", "meta": {"hexsha": "338ba71b66d36232e8cb1747a0c8a7a6dda961cc", "size": 2102, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorAnalysis/stokesTheorem.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorAnalysis/stokesTheorem.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorAnalysis/stokesTheorem.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 44.7234042553, "max_line_length": 242, "alphanum_fraction": 0.6289248335, "num_tokens": 894, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325346, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.718958781155256}}
{"text": "\\subsection{Estimated State}\n\\workinprogress\nSince the agent operates in a partially observable environment, the agent's internal state representation of the environment needs to take into account the fact that the current environment state is not certain. For this reason, a probability distribution over possible environment states is used by the agent to internally represent the environment state. The internal agent state is described mathematically by \n\\[p(x_t | e_{1:t}, u_{1:t})\\]\nwhich is the distribution of possible world states given all evidence and control actions up to the current time step, where $x_t$, $e_t$ and $u_t$ follow the conventions of being the hidden state variables, the evidence variables and the control action variables respectively. The agent updates this state using the world model specified in the preceding chapter, using the filtering algorithm explained in Section \\ref{subsec:BGInfAlgos}. There are a couple of noteworthy points:\n\\begin{itemize}\n    \\item A distribution that has a single sharp peak would indicate that the agent believes that the target is at a specific location with high confidence. This is clearly preferred to a flat, uniform distribution representing uncertainty in relation to where the target might be.\n    \\item The only true source of uncertainty in the world state is introduced by the sensor. Therefore, analysis of this state representation in relation to the sensor model should provide insight into how the system performs.\n\\end{itemize}\n\\par In order to update the estimated state of the agent, the below equations are used, which are described in their general form in Section \\ref{subsec:BGInfAlgos}. For brevity $x_t$ denotes the hidden state variables, $e_t$ denotes the evidence variables and $u_t$ denotes the control action taken by the agent. The equations only describe the estimated state update for move actions, since if the agent terminates the search a terminal state is deterministically entered. The $SearchStatus$ variable is omitted from the equations since it only effects the equations if the $Action$ variable is to terminate the search.\n%\\footnotesize\n%\\begin{equation}\n\\scriptsize\n%\\begin{equation}\\label{eqn:SearchStatus}\n%\\[\n    %\\begin{cases}\\label{eqn:AgentUpdateEquation}\n    \\begin{center}\n    \\begin{align}\n    \\begin{split}\n    %\\centering\n        p(AgentLoc_t = x, TargetLoc_t = y | e_{1:t}, u_{1:t}) = &\\\\\n       \\begin{cases}\n            \\eta \\alpha p(AgentLoc_{t-1} = x, TargetLoc_t = y | e_{1:t-1}, u_{1:t-1}) \\text{ if $e_t$ is a positive reading and $AgentLoc_t \\neq TargetLoc_t$} \\\\\n            \\eta \\beta p(X_{t-1}=x_t | e_{1:t-1}, u_{1:t-1}) \\text{ if $e_t$ is a negative reading and $Agent_loc_t$ = $TargetLoc_t$} \\\\\n            \\eta (1-\\alpha) p(X_{t-1}=x_t | e_{1:t-1}, u_{1:t-1}) \\text{ if $e_t$ is a negative reading and $Agent_loc_t \\neq TargetLoc_t$} \\\\\n            \\eta (1-\\beta) p(X_{t-1}=x_t | e_{1:t-1}, u_{1:t-1}) \\text{ if $e_t$ is a positive reading and $Agent_loc_t$ = $TargetLoc_t$}\n        %\\end{cases}\n%\\eta O_{t} T^{T} f_{1:t-1} \n    \\end{cases}\n    \\end{split}\n    \\end{align}\n    \\end{center}\n%\\]\n%\\end{equation}\n\\normalsize\n\n$\\eta$ is a normalising factor, $\\alpha$ is the probability of a sensor false positive detection and $\\beta$ is the probability of a sensor false negative detection.", "meta": {"hexsha": "74d369f0e3c2477655dc8981a5b13b3c9a60c836", "size": 3327, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/MultiAgentTargetDetection/InitialAgentDesign/EstimatedState.tex", "max_stars_repo_name": "DavidLSmyth/ResearchMScThesis", "max_stars_repo_head_hexsha": "754d975535e0da9a8e99cf31b651021698155c5b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/MultiAgentTargetDetection/InitialAgentDesign/EstimatedState.tex", "max_issues_repo_name": "DavidLSmyth/ResearchMScThesis", "max_issues_repo_head_hexsha": "754d975535e0da9a8e99cf31b651021698155c5b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-06-18T11:59:42.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-18T11:59:42.000Z", "max_forks_repo_path": "Chapters/MultiAgentTargetDetection/InitialAgentDesign/EstimatedState.tex", "max_forks_repo_name": "DavidLSmyth/ResearchMScThesis", "max_forks_repo_head_hexsha": "754d975535e0da9a8e99cf31b651021698155c5b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 89.9189189189, "max_line_length": 621, "alphanum_fraction": 0.7373008717, "num_tokens": 864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761566, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.7189376476907916}}
{"text": "\\chapter{Relativistic quantum mechanism}\n\\section{Klein Gordon equation}\nIn this chapter we consider two types of wave equations which have been proposed for the description of particles traveliing at speeds-close to that of light.At these speeds, the Iamiltonian of the (free) particle is no longer given by $\\left(\\mathbf{p}^{2} / 2 m\\right)$; hence Schrödinger's equation, obtained from such a Hamiltonian by the prescription of Sec. $2.1$, is not applicable to relativistic particles. One could try to generalize the equation by using, instead of $\\left(\\mathbf{p}^{2} / 2 m\\right)$, the relativistic expression for the energy, namely $E=\\left(c^{2} \\mathbf{p}^{2}+m^{2} c^{4}\\right)^{1 / 2}$. The operator replacement $E \\rightarrow i \\hbar \\partial_{i} t, \\mathbf{p} \\rightarrow-i \\hbar \\nabla$ would then lead to $i \\hbar \\partial \\psi / \\partial t=\\left(-\\hbar^{2} i^{2} \\nabla^{2}+m^{2} c^{4}\\right)^{1 / 2} \\psi$ This equation has some obviously unattractive features. The space and time differential operators enter in it in very different ways. This is in contrast with the quite symmetric role of the space and time coordinates (as different components of a single four-vector) in relativity theory. The meaning of the operator$\\left(-\\hbar^{2} c^{2} \\nabla^{2}+m^{2} c^{4}\\right)^{1 / 2}$ is itself unclear. One could get around this by passing to the momentum representation. But even this possibility would disappear if the quantity under the square root were to be modified to include functions of $\\mathbf{x}:$ for example, through the replacement $\\mathbf{p} \\rightarrow(\\mathbf{p}-e \\mathbf{A} / c)$ which becomes necessary when electromagnetic fields are present (assuming that the particle has charge $e$ ). Schrodinger suggested (immediately after his formulation of nonrelativistic quantum mechanics) that in order to avoid the difficulties arising from the square root, the operator replacement of $\\mathbf{p}$ and $E$ be made in the relativistic expression for $E^{2}$ :\n$$\nE^{2}=c^{2} p^{2}+m^{2} c^{4}\n$$\nThe resulting equation is\n$$\n-\\hbar^{2} \\frac{\\partial^{2} \\psi}{\\partial t^{2}}=-\\hbar^{2} c^{2} \\nabla^{2} \\psi+m^{2} c^{4} \\psi\n$$\nor\n$$\n\\frac{1}{c^{2}} \\frac{\\partial^{2} \\psi}{\\partial t^{2}}-\\nabla^{2} \\psi+\\left(\\begin{array}{c}\nm c \\\\\n\\hbar\n\\end{array}\\right)^{2} \\psi=0\n$$\nThis equation is konwn is as Klein Gordon equation .\\\\\n Meanwhile Dirac succeeded in constructing another equation which is of the first order in $(\\partial / \\partial t)$ and $\\nabla$, unlike Eq. 10.2, and yet involves these operators in a fully symmetric way. The Dirac equation constrains the spin of the particle to be $\\frac{1}{2}$. Its application to the electron was phenomenally successful, not only in helping to understand its propertics in a natural way, but more spectacularly, in the prediction of its anti-particle, the positron (which was later discovered in cosmic rays). The Klein-Gordon equation has nothing to say about the spin of the particle; it is ribe ane to be used for particles of spin 0 , like the $\\pi$-and $K$-mesons.\\\\\n \\subsubsection{plane wave Solution}\n $$\n \\frac{1}{c^{2}} \\frac{\\partial^{2} \\psi}{\\partial t^{2}}-\\nabla^{2} \\psi+\\left(\\begin{array}{c}\n m c \\\\\n \\hbar\n \\end{array}\\right)^{2} \\psi=0\n $$\n Solutions to this equation corresponding to particles of definite momentum $\\mathbf{p}=\\hbar \\mathbf{k}$ may be obtained by substituting $\\psi(\\mathbf{x}, t)=f(t) e^{i \\mathbf{k} \\cdot \\mathbf{x}} .$ This leads to $d^{2} f \\mid d t^{2}=\\left[c^{2} \\mathbf{k}^{2}+\\left(m c^{2} / \\hbar\\right)^{2}\\right] f$. Solving this we obtain (apart from a constant normalization factor), the plane wave solutions:\n $$\n \\begin{aligned}\n \\psi(\\mathbf{x}, t) &=e^{i\\left(\\mathbf{k}_{\\mathbf{x}} \\mathbf{x} \\mp \\omega t\\right)}=e^{i(\\mathbf{p} \\cdot \\mathbf{x}-E t) / \\hbar} \\\\\n E &=\\pm \\hbar \\omega=\\pm\\left(c^{2} \\mathbf{p}^{2}+m^{2} c^{4}\\right)^{1 / 2}\n \\end{aligned}\n $$\n In contrast to the nonrelativistic case where the coefficient $(E / \\hbar)$ of $(-i t)$ in the exponent is the positive quantity $\\left(\\mathbf{p}^{2} / 2 m \\hbar\\right)$, here we have solutions with - $\\omega$ as well as with $+\\omega$. The appearance of the 'negative energy' solutions (characterized by $+\\omega t$ in the exponent) is typical of relativistic wave equations;\n \\subsubsection{Charge and current densities}\n Another difference from the nonrelativistic case is that $\\psi^{*} \\psi$ cannot be interpreted as the probability density $P(\\mathbf{x}, t) .$ We expect $P(\\mathbf{x}, \\bar{t})$ to satisfy a continuity equation of the form  namely $\\partial P \\mid \\partial t+\\operatorname{div} \\mathbf{S}=0$, which would ensure that $\\int P(\\mathbf{x}, t) d^{2} x$ is time-independent. To obtain such an equation we multiply klein gordon equation on the left by $\\psi^{*}$, its complex conjugate equation by $\\psi$, and subtract.\n The resulting equation can be written as\n $$\n \\frac{1}{c^{2}} \\frac{\\partial}{\\partial t}\\left(\\psi^{*} \\frac{\\partial \\psi}{\\partial t}-\\psi \\frac{\\partial \\psi^{*}}{\\partial t}\\right)-\\nabla \\cdot\\left(\\psi^{*} \\nabla \\psi-\\psi \\nabla \\psi^{*}\\right)=0\n $$\n This is a continuity cquation, with\n $$\n \\begin{aligned}\n &P(\\mathbf{x}, t)=\\frac{i \\hbar}{2 m c^{2}}\\left(\\psi^{*} \\frac{\\partial \\psi}{\\partial t}-\\psi \\frac{\\partial \\psi^{*}}{\\partial t}\\right) \\\\\n &{\\mathbf{S}(\\mathbf{x}, t)=-\\frac{i \\hbar}{2 m}\\left(\\psi^{*} \\nabla \\psi-\\psi \\nabla \\psi^{*}\\right)}\n \\end{aligned}\n $$\n A convenient choice of a common constant factor in $P$ and $S$ has been made here. With this choice, S coincides exactly with the corresponding nonrelativistic expression. However, $P$ is quite different. It vanishes identically if $\\psi$ is real, and in the case of complex wave functions, $P$ can even be made negative by choosing $\\partial \\psi / \\partial t$ appropriately. Clearly, $P$ cannot be a probability density. One could multiply $P$ by a charge $e$ and then interpret it as a charge density (which can be positive or negative) and $S$ as the corresponding electric current density.\n \\section{Dirac equation}\n The occurance of negative probability density is due to the presence of time derivatives in the expression for $P(r, t)$. This can be avoided by not allowing any time derivative other than the first order to appear in the wave equation. When the wave equation is of first order in time, it must be first order in space coordinates too. Dirac was probably influenced by the Maxwell's equations as they are first order equations in both space and time coordinates.\\\\\n As in Klein-Gordon equation, we can start from the basic energy equation, equation \n Replacing $E$ by $i \\hbar \\partial / \\partial t$ and $p$ by $-i \\hbar \\nabla$ and allowing the $$E=\\pm\\left(c^{2} p^{2}+m^{2} c^{4}\\right)^{1 / 2}$$\n Replacing $E$ by $i \\hbar \\partial / \\partial t$ and $p$ by $-i \\hbar \\nabla$ and allowing the resulting operator equation to operate on the wavefunction $\\Psi(r, t)$, we get\\\\\n $$i \\hbar \\frac{\\partial \\Psi(r, t)}{\\partial t}=\\pm\\left(-c^{2} \\hbar^{2} \\nabla^{2}+m^{2} c^{4}\\right)^{1 / 2} \\Psi(r, t)$$\n To proceed further, we have to define the square root of an operator which is not yet defined. However, Dirac boldly wrote\n $$c^{2} p^{2}+m^{2} c^{4}=\\left[c\\left(\\alpha_{x} p_{x}+\\alpha_{y} p_{y}+\\alpha_{z} p_{z}+\\beta m c\\right)\\right]^{2}$$\n and then searched for conditions to be placed on the $\\alpha$ 's and $\\beta$ so that the equation is valid. For equation above to hold true, we must have\n$$\\left.\\begin{array}{r}\n\t\\alpha_{x}^{2}=\\alpha_{y}^{2}=\\alpha_{z}^{2}=\\beta^{2}=1 \\\\\n\t\\alpha_{x} \\alpha_{y}+\\alpha_{y} \\alpha_{x}=\\alpha_{y} \\alpha_{z}+\\alpha_{z} \\alpha_{y}=\\alpha_{z} \\alpha_{x}+\\alpha_{x} \\alpha_{z}=0 \\\\\n\t\\alpha_{x} \\beta+\\beta \\alpha_{x}=\\alpha_{y} \\beta+\\beta \\alpha_{y}=\\alpha_{z} \\beta+\\beta \\alpha_{2}=0\n\\end{array}\\right\\}$$\nThat is, the $\\alpha$ 's and $\\beta$ anticommute in pairs and their squares are unity. These properties immediately suggest that they cannot be numbers. Already, we have a set of anticommuniting matrices, the Pauli's spin matrices. Hence, it is convenient to express them in terms of matrices. The energy can now be written as\n$$E=\\pm c\\left(\\alpha_{x} p_{x}+\\alpha_{y} p_{y}+\\alpha_{z} p_{z}+\\beta_{m c}\\right)$$\nThe positive or negative sign can be taken since replacement of $\\alpha$ by $-\\alpha$ and $\\beta$ by $-\\beta$ does not change the relationships between $\\alpha$ 's and $\\beta$. Hence the relativistic Hamiltonian of a particle can be taken as $$E=H=c \\alpha \\cdot p+\\beta m c^{2}$$\nReplacing $E$ and $p$ by their operators and allowing the resulting operator equation to operate on $\\Psi(r, t)$, we\n$$i \\hbar \\frac{\\partial \\Psi(r, t)}{\\partial t}=-i c \\hbar\\left(\\alpha_{x} \\frac{\\partial}{\\partial x}+\\alpha_{y} \\frac{\\partial}{\\partial y}+\\alpha_{z} \\frac{\\partial}{\\partial z}\\right) \\Psi(r, t)+\\beta m c^{2} \\Psi(r, t)$$\nwhich is Dirac's relativistic equation for a free particle.\n\\newpage\n\\begin{abox}\n\tPractice set 1\n\t\\end{abox}\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\t\\item The Dirac Hamiltonian $H=c \\vec{\\alpha} \\cdot \\vec{p}+\\beta m c^{2}$ for a free electron corresponds to the classical relation $E^{2}=p^{2} c^{2}+m^{2} c^{4}$. The classical energy-momentum relation of a piratical of charge $q$ in a electromagnetic potential $(\\phi, \\vec{A})$ is $(E-q \\phi)^{2}=c^{2}\\left(\\vec{p}-\\frac{q}{c} \\vec{A}\\right)^{2}+m^{2} c^{4}$.\n\t\tTherefore, the Dirac Hamiltonian for an electron in an electromagnetic field is\n\t\t\\exyear{NET JUNE 2015}\n\t\\end{minipage}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $c \\vec{\\alpha} \\cdot p+\\frac{e}{C} \\vec{A} \\cdot \\vec{A}+\\beta m c^{2}-e \\phi$\n\t\t\\task[\\textbf{B.}]$c \\vec{\\alpha} \\cdot\\left(\\vec{p}+\\frac{e}{c} \\vec{A}\\right)+\\beta m c^{2}+e \\phi$\n\t\t\\task[\\textbf{C.}]$c\\left(\\vec{\\alpha} \\cdot \\vec{p}+e \\phi+\\frac{e}{c}|\\vec{A}|\\right)+\\beta m c^{2}$\n\t\t\\task[\\textbf{D.}]$c \\vec{\\alpha} \\cdot\\left(\\vec{p}+\\frac{e}{c} \\vec{A}\\right)+\\beta m c^{2}-e \\phi$\n\t\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The dynamics of a free relativistic particle of mass $m$ is governed by the Dirac Hamiltonian $H=c \\vec{\\alpha} \\cdot \\vec{p}+\\beta m c^{2}$, where $\\vec{p}$ is the momentum operator and $\\vec{\\alpha}=\\left(\\alpha_{x}, \\alpha_{y}, \\alpha_{z}\\right)$ and $\\beta$ are four $4 \\times 4$ Dirac matrices. The acceleration operator can be expressed as\n\t\\exyear{NET DEC 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{2 i c}{\\hbar}(c \\vec{p}-\\vec{\\alpha} H)$\n\t\\task[\\textbf{B.}]$2 \\mathrm{ic}^{2} \\vec{\\alpha} \\beta$\n\t\\task[\\textbf{C.}]$\\frac{i c}{\\hbar} H \\vec{\\alpha}$\n\t\\task[\\textbf{D.}]$-\\frac{2 i c}{\\hbar}(c \\vec{p}+\\vec{\\alpha} H)$\n\\end{tasks}\n\\end{enumerate}\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{d}&2&\\textbf{a}\\\\\\hline\n\t\\end{tabular}\n\\end{table}", "meta": {"hexsha": "128cb904d651c9ee9912466c0dbd4c7248ca2a56", "size": 11042, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "QM -CSIR/chapter/relativistic qm.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "QM -CSIR/chapter/relativistic qm.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "QM -CSIR/chapter/relativistic qm.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 101.3027522936, "max_line_length": 1923, "alphanum_fraction": 0.6911791342, "num_tokens": 3646, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.718878469596298}}
{"text": "\\section{Formulation of the isogeometric SBFEM}\n\\label{iso_section:formulation}\n\\paragraph{}\nThe nodal coordinates on the boundary are denoted as $\\mathbf{x}_b$. As in a standard 1D iso-parametric finite element, the geometry of the element described by the coordinates $\\mathbf{x}_b(\\eta)$ as shown in Fig.~\\ref{lr_fig:sbfem_intro}, is expressed as\n\\begin{equation}\n    \\mathbf{x}_b(\\eta) = \\mathbf{N}(\\eta) \\mathbf{x}_b\n    \\label{lr_eq:sbfem_boundary_interpolate}\n\\end{equation}\n%\nwhere $\\mathbf{N}(\\eta)$ is the shape function matrix.\nWithout loss of generality, the origin of the Cartesian coordinate system is chosen at the scaling center.\nThe geometry of the subdomain, described by $x$, is formed by scaling the boundary (Eq.~\\ref{lr_eq:sbfem_boundary_interpolate})\n\\begin{equation}\n    \\mathbf{x} = \\xi \\mathbf{x}_b (\\eta)\n    \\label{lr_eq:sbfem_scaling}\n\\end{equation}\n%\nwhere $\\xi$ is the normalized radial coordinate running from the scaling center towards the boundary, with $\\xi=0$ at the scaling center and $\\xi=1$ on the boundary.\nThe coordinates $\\xi$ and $\\eta$ are the so-called scaled boundary coordinates.\nThey are related to the polar coordinates $r$ and $\\theta$.\nThe transformation is expressed as\n\\begin{equation}\n\\begin{aligned}\n    r(\\xi,\\eta) &= \\xi r_b(\\eta)     \\\\\n    \\theta(\\eta) &= \\arctan \\frac{y(\\eta)}{x(\\eta)}\n    \\label{lr_eq:sbfem_transform}\n\\end{aligned}\n\\end{equation}\n%\nwhere $r_b$ is the distance from the scaling center to a point on the boundary.\nThe transformation between the Cartesian coordinates and the scaled boundary coordinates is similar to the coordinate transformation in the constructing iso-parametric finite elements.\nThe scaling center must be placed at the position so that all boundary of the domain is visible from the point.\nThis limitation can be easily solved by using a mesh generation algorithm described in Sec.~\\ref{qdt_sec:main}.\nThe displacement at any point are approximated by\n\\begin{equation}\n    \\mathbf{u}(\\xi,\\eta) = \\mathbf{N}(\\eta) \\mathbf{u}(\\xi)\n    \\label{lr_eq:sbfem_disp_interpolation}\n\\end{equation}\n%\nwhere $\\mathbf{N}(\\eta)$ are the shape functions of elements on the boundary and $\\mathbf{u}(\\xi)$ is the displacement along the radial lines, represented by a set of N analytical functions.\nBy substituting Eq.~\\ref{lr_eq:sbfem_disp_interpolation} into the definition of strain-displacement relations, the strain $\\epsilon(\\xi,\\eta)$ are expressed as\n\\begin{equation}\n    \\epsilon(\\xi,\\eta) = \\mathbf{Lu}(\\xi,\\eta)\n    \\label{lr_eq:sbfem_strain_disp_relation}\n\\end{equation}\n%\nwhere $\\mathbf{L}$ is a linear operator matrix formulated in the scaled boundary coordinates\n\\begin{equation}\n    \\mathbf{L} =    \\mathbf{b}_1(\\eta) \\frac{\\partial}{\\partial \\xi} +\n                    \\frac{1}{\\xi} \\mathbf{b}_2(\\eta)\n    \\label{lr_eq:sbfem_l_operator}\n\\end{equation}\n%\nand\n\\begin{equation}\n    \\begin{aligned}\n    \\mathbf{b}_1(\\eta) & = \\frac{1}{|J|}\n            \\begin{bmatrix}\n                y_b(\\eta),_{\\eta}   &   0   \\\\\n                0   &   -x_b(\\eta),_{\\eta}  \\\\\n                -x_b(\\eta),_{\\eta} & y_b(\\eta),_{\\eta}\n            \\end{bmatrix} \\\\\n    \\mathbf{b}_2(\\eta) & = \\frac{1}{|J|}\n            \\begin{bmatrix}\n                -y_b    &   0   \\\\\n                0       &   x_b \\\\\n                x_b     &   y_b\n            \\end{bmatrix}\n    \\end{aligned}\n    \\label{lr_eq:sbfem_little_b}\n\\end{equation}\n%\nThe determinant of the Jacobian matrix is\n\\begin{equation}\n    |J| = x_b(\\eta)y_b(\\eta),_{\\eta}\n        - y_b(\\eta)x_b(\\eta),_{\\eta}\n    \\label{lr_eq:sbfem_Jdet}\n\\end{equation}\n%\nwhere $x_b(\\eta)$ and $y_b(\\eta)$ are given by Eq.~\\ref{lr_eq:sbfem_boundary_interpolate}.\nThe stresses $\\sigma(\\xi,\\eta)$ are given by:\n\\begin{equation}\n    \\sigma(\\xi,\\eta) =  \\mathbf{DB}_1(\\eta) \\mathbf{u}(\\xi),_{\\xi} +\n                        \\frac{1}{\\xi} \\mathbf{DB}_2(\\eta) \\mathbf{u}(\\xi)\n    \\label{lr_eq:sbfem_stress}\n\\end{equation}\n%\nwhere in the above equation, the definition of strain and the linear operator matrix given by Eq.~\\ref{lr_eq:sbfem_strain_disp_relation} and Eq.~\\ref{lr_eq:sbfem_l_operator} are used with\n\\begin{equation}\n    \\begin{aligned}\n        \\mathbf{B}_1(\\eta) &= \\mathbf{b}_1(\\eta) \\mathbf{N}(\\eta)    \\\\\n        \\mathbf{B}_2(\\eta) &= \\mathbf{b}_2(\\eta) \\mathbf{N}(\\eta),_{\\eta}\n        \\label{lr_eq:sbfem_captial_b}\n    \\end{aligned}\n\\end{equation}\n%\nsubstituting Eq.~\\ref{lr_eq:sbfem_strain_disp_relation} and Eq.~\\ref{lr_eq:sbfem_stress} in the virtual work statement for elastostatics \\citep{Deeks2002} and following the derivation\n\\begin{equation}\n    \\begin{aligned}\n        \\delta \\mathbf{u}(\\xi)^{T} \\left(\n            (\\mathbf{E}_0 \\xi \\mathbf{u}(\\xi),_{\\xi}\n            + \\mathbf{E}_1^T \\mathbf{u}(\\xi))|_{\\xi=1}\n            - \\mathbf{F}\n        \\right) - \\\\\n        \\int_0^1 \\delta u(\\xi)^T\\left(\n            \\mathbf{E}_0 \\xi^2 \\mathbf{u}(\\xi),_{\\xi\\xi} + (\\mathbf{E}_0 + \\mathbf{E}_1^T - \\mathbf{E}_1) \\xi \\mathbf{u}(\\xi),_{\\xi}\n            - \\mathbf{E}_2 u(\\xi)\n        \\right) d\\xi = 0\n    \\end{aligned}\n    \\label{lr_eq:sbfem_virtual_work}\n\\end{equation}\n%\nwhere $\\mathbf{u}(\\xi)$ is the nodal displacement vector and $\\mathbf{F}$ is the vector of equivalent boundary nodal forces, given by:\n\\begin{equation}\n    \\mathbf{F} = (\\mathbf{E}_0 \\xi \\mathbf{u}(\\xi),_{\\xi} + \\mathbf{E}_1^T \\mathbf{u}(\\xi))|_{\\xi=1}\n    \\label{lr_eq:sbfem_nodal forces}\n\\end{equation}\n%\nBy considering the arbitrariness of $\\delta \\mathbf{u}(\\xi)$, the following ODE is obtained:\n\\begin{equation}\n    \\mathbf{E}_0 \\xi^2 \\mathbf{u}(\\xi),_{\\xi\\xi} + (\\mathbf{E}_0 + \\mathbf{E}_1^T - \\mathbf{E}_1)\\xi \\mathbf{u}(\\xi),_{\\xi} - \\mathbf{E}_2 \\mathbf{u}(\\xi) = 0\n    \\label{lr_eq:sbfem_ODE}\n\\end{equation}\n%\nwhere $\\mathbf{E}_0$, $\\mathbf{E}_1$ and $\\mathbf{E}_2$ are known as the coefficient matrices and are given by:\n\\begin{equation}\n    \\begin{aligned}\n        \\mathbf{E}_0 &= \\int_\\eta \\mathbf{B}_1(\\eta)^T \\mathbf{DB}_1(\\eta)|J|d\\eta \\\\\n        \\mathbf{E}_1 &= \\int_\\eta \\mathbf{B}_2(\\eta)^T \\mathbf{DB}_1(\\eta)|J|d\\eta \\\\\n        \\mathbf{E}_2 &= \\int_\\eta \\mathbf{B}_2(\\eta)^T \\mathbf{DB}_2(\\eta)|J|d\\eta\n    \\end{aligned}\n    \\label{lr_eq:sbfem_coe_matrix}\n\\end{equation}\n%\nEq.~\\ref{lr_eq:sbfem_ODE} is a homogeneous second-order differential equation.\nIts solution is obtained by introducing the variable $\\mathbf{\\chi}(\\xi)$\n\\begin{equation}\n    \\mathbf{\\chi} = \\left\\{\n        \\begin{matrix}\n            \\mathbf{u}(\\xi)  \\\\\n            \\mathbf{q}(\\xi)\n        \\end{matrix}\n    \\right\\}\n    \\label{lr_eq:sbfem_ODE_soltion}\n\\end{equation}\n%\nwhere $\\mathbf{q}(\\xi)$ is the internal force vector\n\\begin{equation}\n    \\mathbf{q}(\\xi) =   \\mathbf{E}_0 \\xi \\mathbf{u}(\\xi),_{\\xi} +\n                        \\mathbf{E}_1^T \\mathbf{u}(\\xi)\n    \\label{lr_eq:sbfem_internal_force}\n\\end{equation}\n%\nThe boundary nodal forces are related to the displacement functions by:\n\\begin{equation}\n    \\mathbf{F} = \\mathbf{q}(\\xi=1) = (\\mathbf{E}_0\\xi \\mathbf{u}(\\xi),_{\\xi} + \\mathbf{E}_1^T\\mathbf{u}(\\xi))|_{\\xi=1}\n    \\label{lr_eq:sbfem_boundary_nodal_force}\n\\end{equation}\n%\nThis allows Eq.~\\ref{lr_eq:sbfem_ODE} to be transformed into a first order ordinary differential equation with twice the number of unknowns as:\n\\begin{equation}\n    \\xi \\mathbf{\\chi}(\\xi),_{\\xi} = -\\mathbf{Z} \\mathbf{\\chi}(\\xi)\n    \\label{lr_eq:sbfem_1stODE}\n\\end{equation}\n%\nwhere $\\mathbf{Z}$ is a Hamiltonian matrix\n\\begin{equation}\n    \\mathbf{Z} = \\begin{bmatrix}\n        \\mathbf{E}_0^{-1} \\mathbf{E}_1^T    &  -\\mathbf{E}_0^{-1}   \\\\\n        \\mathbf{E}_1 \\mathbf{E}_0^{-1} \\mathbf{E}_1^T - \\mathbf{E}_2    &   -\\mathbf{E}_1 \\mathbf{E}_0^{-1}\n    \\end{bmatrix}\n    \\label{lr_eq:sbfem_zmatrix}\n\\end{equation}\n%\nAn eigenvalue decomposition of $\\mathbf{Z}$ is performed and it yields:\n\\begin{equation}\n    \\mathbf{Z} \\begin{bmatrix}\n        \\mathbf{\\Phi}_u \\\\\n        \\mathbf{\\Phi}_q\n    \\end{bmatrix} = \\begin{bmatrix}\n        \\mathbf{\\Phi}_u  \\\\\n        \\mathbf{\\Phi}_q\n    \\end{bmatrix} \\mathbf{\\Lambda}_n\n    \\label{lr_eq:sbfem_eigen_decomp}\n\\end{equation}\n%\nIn Eq.~\\ref{lr_eq:sbfem_eigen_decomp}, $\\mathbf{\\Lambda}_n$ $=$ diag$(\\lambda_1$, $\\lambda_2$, $\\dots$, $\\lambda_n)$ contains only the eigenvalues with negative real part.\n$\\mathbf{\\Phi}_u$ and $\\mathbf{\\Phi}_q$ are the subsets of the eigenvectors corresponding to $\\mathbf{\\Lambda}_n$.\nThey represent the modal displacements and forces, respectively.\nThe general solution of Eq.~\\ref{lr_eq:sbfem_1stODE} is given by:\n\\begin{align}\n    \\mathbf{u}(\\xi) &= \\mathbf{\\Phi}_u \\xi^{-\\mathbf{\\Lambda_n}} \\mathbf{c}\n    \\label{lr_eq:sbfem_general_sol_disp} \\\\\n    \\mathbf{q}(\\xi) &= \\mathbf{\\Phi}_q \\xi^{-\\mathbf{\\Lambda_n}} \\mathbf{c}\n    \\label{lr_eq:sbfem_general_sol_str}\n\\end{align}\n%\nwhere $\\mathbf{c}$ are integration constants that are obtained from the nodal displacements $\\mathbf{u}_b = \\mathbf{u}(\\xi=1)$ as:\n\\begin{equation}\n    \\mathbf{c} = \\mathbf{\\Phi}_u^{-1} \\mathbf{u}_b\n    \\label{lr_eq:sbfem_int_constant}\n\\end{equation}\n%\nThe complete displacement field of a point defined by the sector covered by a line element on the boundary is obtained by substituting Eq.~\\ref{lr_eq:sbfem_general_sol_str} into Eq.~\\ref{lr_eq:sbfem_disp_interpolation} resulting in:\n\\begin{equation}\n    \\mathbf{u}(\\xi,\\eta) = \\mathbf{R}(\\eta) \\mathbf{\\Phi}_u \\xi ^{-\\mathbf{\\Lambda}_n} c\n    \\label{lr_eq:sbfem_displacement_field}\n\\end{equation}\n%\nTaking the derivative of $\\mathbf{u}(\\xi)$ with respect to $\\xi$ and substituting into Eq.~\\ref{lr_eq:sbfem_stress} the stress field $\\sigma(\\xi,\\eta)$ can be expressed as:\n\\begin{equation}\n    \\sigma(\\xi,\\eta) = \\mathbf{\\Psi}_\\alpha (\\eta) \\xi^{-\\mathbf\\Lambda}_n - \\mathbf{I} \\mathbf{c}\n    \\label{lr_eq:sbfem_stress_field}\n\\end{equation}\n%\nwhere the stress mode $\\mathbf{\\Psi}_\\sigma(\\eta)$ is defined as:\n\\begin{equation}\n    \\mathbf{\\Psi}_\\alpha(\\eta) =    \\mathbf{D}(\n                                       -\\mathbf{B}_1(\\eta) \\mathbf{\\Phi}_u \\mathbf{\\Lambda}_n +\n                                        \\mathbf{B}_2(\\eta) \\mathbf{\\Phi}_u\n                                    )\n    \\label{lr_eq:sbfem_stress_mode}\n\\end{equation}\n%\nThe stiffness matrix of an element is obtained by first substituting Eq.~\\ref{lr_eq:sbfem_int_constant} into Eq.~\\ref{lr_eq:sbfem_general_sol_str} at $\\xi=1$.\nThis results in:\n\\begin{equation}\n    \\mathbf{F} = \\mathbf{\\Phi}_q \\mathbf{\\Phi}_u^{-1} \\mathbf{u}_b\n    \\label{lr_eq:sbfem_kmat_previous}\n\\end{equation}\n%\nFrom Eq.~\\ref{lr_eq:sbfem_kmat_previous}, the stiffness matrix $\\mathbf{K}$ can be identified to be given by the expression\n\\begin{equation}\n    \\mathbf{K} = \\mathbf{\\Phi}_q \\mathbf{\\Phi}_u^{-1}\n    \\label{lr_eq:sbfem_kmat}\n\\end{equation}\n%\nThe SBFEM has recently been extended to dynamic analysis in bounded domains \\citep{Song2009}.\nAssuming time-harmonic behavior, the scaled boundary equation in displacement is extended as:\n\\begin{equation}\n    \\mathbf{E}_0 \\xi^2 \\mathbf{u}(\\xi),_{\\xi\\xi} +\n    (\\mathbf{E}_0 + \\mathbf{E}_1^T - \\mathbf{E}_1)\\xi \\mathbf{u}(\\xi),_{\\xi} -\n    \\mathbf{E}_2 \\mathbf{u}(\\xi) + \\omega^2 \\mathbf{M}_0 \\xi^2 \\mathbf{u}(\\xi) = 0\n    \\label{lr_eq:sbfem_dynamic}\n\\end{equation}\n%\nWhere $\\mathbf{M}_0$ is a coefficient matrix defined as\n\\begin{equation}\n    \\mathbf{M}_0 = \\int_\\eta \\mathbf{N}^T \\rho \\mathbf{N}|J| d\\eta\n    \\label{lr_eq:sbfem_dynamic_mass}\n\\end{equation}\n%\nUsing Eq.~\\ref{lr_eq:sbfem_internal_force} and Eq.~\\ref{lr_eq:sbfem_boundary_nodal_force}, Eq.~\\ref{lr_eq:sbfem_dynamic_mass} can be transformed into an equivalent first-order non-linear differential equation in dynamic stiffness $\\mathbf{S}(\\omega)$,\n\\begin{equation}\n    (\\mathbf{S}(\\omega)-\\mathbf{E}_1)\\mathbf{E}_0^{-1}\n    (\\mathbf{S}(\\omega)-\\mathbf{E}_1^T) - \\mathbf{E}_2 +\n    \\omega \\mathbf{S}(\\omega),_\\omega + \\omega^2 \\mathbf{M}_0 = 0\n    \\label{lr_eq:sbfem_dynamic_1stODE}\n\\end{equation}\n%\nThe dynamic stiffness matrix $\\mathbf{S}(\\omega)$ relates the nodal forces to the displacements at the boundary as,\n\\begin{equation}\n    \\mathbf{F} = \\mathbf{S}(\\omega) \\mathbf{u}(\\xi=1)\n    \\label{lr_eq:sbfem_dynamic_nodal_force}\n\\end{equation}\n%\nEq.~\\ref{lr_eq:sbfem_dynamic_1stODE} is solved by expanding the dynamic stiffness into a series of continued fractions.\nFor this purpose, it is expressed as\n\\begin{equation}\n    \\mathbf{S}(\\omega) = \\mathbf{K} - \\omega^2 \\mathbf{M} + \\omega^4 \\left[\n        \\mathbf{R}^{(1)}    \n    \\right]^{-1}\n    \\label{lr_eq:sbfem_dynamic_stiffness}\n\\end{equation}\n%\nIn Eq.~\\ref{lr_eq:sbfem_dynamic_stiffness}, the first two terms represent the low-frequency expansion of the dynamic stiffness, whereas the third term corresponds to the residual of the low-frequency approximation.\nSubstituting Eq.~\\ref{lr_eq:sbfem_dynamic_stiffness} in Eq.~\\ref{lr_eq:sbfem_dynamic_1stODE} and equating terms in increasing order of powers of $\\omega$ to zero yields equations for $\\mathbf{K}$ ,$\\mathbf{M}$  and $\\mathbf{R}^{(1)}$.\nSetting the constant terms equal to zero yields an algebraic Riccati equation for the static stiffness matrix $\\mathbf{K}$, which is equivalent to the solution process described earlier.\nSetting all terms in $\\omega^2$ equal to zero yields a Lyapunov equation for the low-order mass matrix $\\mathbf{M}$.\nThe solution procedure of that Lyapunov equation is described in detail in \\citep{Son1997}.\nThe remaining equation for the residual is solved by expanding  $\\mathbf{R}^{(1)}$ as\n\\begin{equation}\n    \\mathbf{R}^{(1)} = \\mathbf{S}_0^{(1)} - \\omega^2 \\mathbf{S}_1^{(1)} + \\omega^4 [\\mathbf{R}^{(2)}]^{-1}\n    \\label{lr_eq:sbfem_dynamic_R}\n\\end{equation}\n%\nEq.~\\ref{lr_eq:sbfem_dynamic_R} is analogous to the expansion of the dynamic stiffness, Eq.~\\ref{lr_eq:sbfem_dynamic_stiffness}, where the coefficients $\\mathbf{S}^{(1)}_0$ and $\\mathbf{S}^{(1)}_1$ correspond to the `stiffness' and `mass' term of $\\mathbf{R}^{(1)}$, respectively.\nEquations for $\\mathbf{S}^{(1)}_0$ and $\\mathbf{S}^{(1)}_1$ are found by substituting Eq.~\\ref{lr_eq:sbfem_dynamic_R} into the equation for $\\mathbf{R}^{(1)}$.\nThis procedure is continued until the residual $\\mathbf{R}^{M_{cf}+1}$ can be neglected.\nThe symbol of $M_{cf}$ denotes the order of continued-fraction expansion.\nSubstituting all terms of the expansion back into Eq.~\\ref{lr_eq:sbfem_dynamic_stiffness} yields:\n\\begin{dmath}\n    \\mathbf{S}(\\omega) =    \\mathbf{K} - \\omega^2 \\mathbf{M} + \\omega^4 \\left(\n                                \\mathbf{S}_0^{(1)} - \\omega^2 \\mathbf{S}^{(1)} + \\omega^4 \\left(\n                                    \\mathbf{S}_0^{(2)} - \\omega^2 \\mathbf{S}^{(2)} + \\dots + \n                                    \\omega^4 \\left(\n                                        \\mathbf{S}_0^{(M_{cf})} - \\omega^2 \\mathbf{S}_1^{(M_{cf})}\n                                    \\right)^{-1}\n                                \\right)^{-1}\n                            \\right)^{-1}\n\\label{lr_eq:sbfem_dynamic_s_full}\n\\end{dmath}\n%\nThe coefficients $\\mathbf{S}^{(i)}_0$ and $\\mathbf{S}^{(i)}_1$ in Eq.~\\ref{lr_eq:sbfem_dynamic_s_full} are calculated following a recursive procedure.\nA more detailed derivation can be found in \\citep{Song2009}.", "meta": {"hexsha": "073016580c0d1c1cb5bb67f6de29ea0b55c3c7d6", "size": 15069, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "isogeometric_sbfem/sbfem_formulation.tex", "max_stars_repo_name": "fa93hws/thesis", "max_stars_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-30T12:14:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-30T12:14:47.000Z", "max_issues_repo_path": "isogeometric_sbfem/sbfem_formulation.tex", "max_issues_repo_name": "fa93hws/thesis", "max_issues_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "isogeometric_sbfem/sbfem_formulation.tex", "max_forks_repo_name": "fa93hws/thesis", "max_forks_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.406557377, "max_line_length": 280, "alphanum_fraction": 0.658836021, "num_tokens": 5125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.7188600229116708}}
{"text": "\\lab{Facial Recognition using Eigenfaces}{Facial Recognition using Eigenfaces}\n\\label{lab:FacialRecognition}\n\n\\objective{In this lab we use the singular value decomposition to build a facial recognition system.}\n\nSuppose we have a large database containing images of human faces together with identification information for each face.\nGiven an unidentified facial image, we would like to find a matching face in the database, thereby identifying the person in the image.\nSuch a task is known as \\emph{facial recognition}.\nThis task may come up, for example, in law enforcement, when attempting to identify unknown persons in surveillance footage.\nAs humans, it is generally easy to compare two face images and determine whether the faces belong to the same person.\nHowever, it becomes impractical for humans to visually compare one face image with several thousand other face images in a database.\nHence, we need a computational technique that automates the process of facial recognition.\nOne particularly simple and effective technique is known as \\emph{eigenfaces}, which we now explore.\n\n\\section*{Eigenfaces}\nThe method of eigenfaces provides a mathematical and computational technique for efficiently storing and querying a database of face images.\nAs the name suggests, this method involves eigenvalues and eigenvectors of matrices related to the collection of face images at hand.\nAt its core, the method of eigenfaces maps each face image to a low-dimensional representation in a way that highlights the distinguishing\ncharacteristics of the face while suppressing the irrelevant and unnecessary details.\nIn this light, eigenfaces can be viewed as a means of dimensionality reduction.\nLet's get into the nuts and bolts of how this works.\n\nSuppose we have a collection of $k$ face images represented as vectors $f_1, f_2, \\ldots, f_k$ of length $l$.\n(A digital image is normally represented by a $m \\times n$ array of pixel values, but we can represented as a vector in $\\mathbb{R}^{mn}$ by simply concatenating the rows of the array.)\nDefine the \\emph{mean face} $\\mu$ to be the average of each face vector:\n\\[\n\\mu = \\frac{1}{k}\\sum_{i=1}^k f_i.\n\\]\n\\begin{figure}\n\\includegraphics[width=0.3\\textwidth]{meanFace.png}\n\\caption{The mean face.}\n\\label{facialRecognition:meanFace}\n\\end{figure}\n\n\n\n\\begin{problem}\n\\label{prob:getTrainingFaces}\nDownload the \\li{faces94} face image database found at \\url{http://cswww.essex.ac.uk/mv/allfaces/faces94.html} and extract the files.\nYou should now have a directory named ``faces94\", which contains multiple face images each of a large collection of individuals.\nWe will construct a database of face images by selecting exactly one face image for each person in the directory.\nExecute the following code to construct the collection of faces (you may need to change the variable \\li{path} to point to the location\nof the \\li{faces94} directory on your machine):\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from os import walk\n>>> from scipy.ndimage import imread\n>>> # these are the dimensions of the images\n>>> w = 200\n>>> h = 180\n>>> # traverse the directory, get one image per subdirectory\n>>> path = \"./faces94\"\n>>> faces = []\n>>> for (dirpath, dirnames, filenames) in walk(path):\n>>>     for f in filenames:\n>>>         if f[-3:]==\"jpg\": # only get jpg images\n>>>             # load image, convert to grayscale, flatten into vector\n>>>             face = imread(dirpath+\"/\"+f).mean(axis=2).ravel()\n>>>             faces.append(face)\n>>>             break\n>>> # put all the face vectors column-wise into a matrix\n>>> F = np.array(faces).T\n\\end{lstlisting}\nThe array \\li{F} should be a $360000 \\times 153$ matrix whose columns consist of 153 face images.\n\\end{problem}\n\\begin{problem}\n\\label{prob:meanFace}\nCalculate the mean face image \\li{mu} from the face image array \\li{F} that you obtained in problem \\ref{prob:getTrainingFaces}.\nThis can be done easily using \\li{np.mean} and specifying the correct axis.\n\nPlot the mean face.\nAs a convenience, you may use the following function to plot the image given just the flat vector representation:\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n>>> import matplotlib.cm as cm\n>>> def show(im, w=200, h=180):\n>>>     \"\"\"\n>>>     Plot the w by h image whose pixel values are given by the array im.\n>>>     \"\"\"\n>>>     plt.imshow(im.reshape((w,h)), cmap=cm.Greys_r)\n>>>     plt.show()\n>>> # given that you have calculated the mean face mu, show it\n>>> show(mu)\n\\end{lstlisting}\nYour mean face should match that shown in Figure \\ref{facialRecognition:meanFace}.\n\\end{problem}\n\\begin{figure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{differenceFace0.png}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{differenceFace1.png}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{differenceFace2.png}\n\\end{subfigure}\n\\caption{Three mean-shifted faces from the dataset.}\n\\label{facialRecognition:differenceFaces}\n\\end{figure}\nFor each $i = 1,\\ldots, k$, define $\\bar{f}_i := f_i - \\mu$.\nThe mean-shifted face vector $\\bar{f}_i$ represents how the $i$-th face deviates from the average, and thus captures more directly the unique and distinguishing features of the face.\nNow form the $l \\times K$ matrix $A$ whose columns are given by the mean-shifted face vectors, i.e.\n\\[\nA = \\begin{bmatrix}\n\\bar{f}_1 & \\bar{f}_2 & \\cdots & \\bar{f}_k\n\\end{bmatrix}.\n\\]\n\\begin{problem}\nUsing the face matrix \\li{F} and the mean face \\li{mu} from problems \\ref{prob:getTrainingFaces} and \\ref{prob:meanFace}, calculate the\nmatrix of mean-shifted face vectors \\li{A}.\n(This can be done in a nice, vectorized manner using array broadcasting.)\nPlot the first mean-shifted face, i.e. the first column of the matrix \\li{A}.\nIt should match the first face in Figure \\ref{facialRecognition:differenceFaces}.\n\\end{problem}\n\nThus far, we have obtained the mean face vector $\\mu$ and a representation of our collection of face images via the matrix $A$.\nWith just this matrix and the mean vector, how might we go about searching our collection of face images for the closest match to a new face image $g$?\nA straightforward approach is to subtract the mean face vector from $g$, obtaining $\\bar{g} = g-\\mu$, and then compute the Euclidean distance from\n$\\bar{g}$ to each mean-shifted face vector $\\bar{f}_i$, i.e. compute the Euclidean distance between $\\bar{g}$ and each column of $A$.\nHaving done so, we can then choose the index $i$ where this distance $\\|\\bar{g}-\\bar{f}_i\\|_2$ is smallest, and return the $i$-th face image as the best match.\nAlthough this approach is quite sensible, it become computationally expensive as the number and size of our face images increases.\nWhat we need, then, is a way to reduce the dimensionality of our images.\n\n\\begin{comment}\nThe discussion in the paragraph below needs some work.\nI need to better understand why the eigenfaces basis works so well.\n\nAlthough this approach is quite sensible, there are a few issues.\nFirstly, as the number of face images in our database grows large, both storing the full matrix $A$ and computing $\\|\\bar{g}-\\bar{f}_i\\|_2$ for all $i$\nbecome increasingly difficult from a computational standpoint.\nSecondly -- and this is the more important point -- calculating the Euclidean distance between two face images in the standard basis may not be the best measure\nof how similar the two faces are (and empirical evidence supports this).\nFor example, if we have two images of the same face but with different backgrounds, the Euclidean distance between the face vectors may be very large,\nsince in the standard basis, every pixel is weighted equally.\nGiven these issues, it is natural to ask ourselves whether there exists a low-dimensional subspace with a basis in which we can represent our\nface images with minimal error and where the Euclidean distance is a more robust measure of face similarity.\n\\end{comment}\n\nSince the face images all have much in common, we have reason to hope that they all lie (nearly) in a low-dimensional subspace of $\\mathbb{R}^l$.\nThe singular value decomposition of $A$ gives us just such a subspace.\nIn particular, if we write the singular value decomposition as\n\\[\nA = U\\Sigma V^H,\n\\]\nthen the columns of $U$ corresponding to the positive singular values form an orthonormal basis for the columns of $A$.\nRecall that there are $r$ positive singular values, where $r$ is the rank of $A$.\nHence, if $r \\ll l$, then we have found a low-dimensional subspace in which to represent our face vectors.\nWe call this subspace the \\emph{eigenface subspace}, and we call each basis vector (i.e. each column of $U$ corresponding\nto a positive singular value) an \\emph{eigenface}.\n\\begin{figure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{eigenface0.png}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{eigenface1.png}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{eigenface2.png}\n\\end{subfigure}\n\\caption{The top three eigenfaces.}\n\\label{facialRecognition:eigenfaces}\n\\end{figure}\n\\begin{problem}\n\\label{prob:svd}\nCalculate the singular value decomposition of the matrix \\li{A} as follows:\n\\begin{lstlisting}\n>>> from scipy imort linalg as la\n>>> U,Sig,Vh = la.svd(A, full_matrices=False)\n\\end{lstlisting}\nThe keyword argument \\li{full_matrices=False} cause the function to only return the columns of $U$ and $V$ corresponding\nto positive singular values. Hence, \\li{U} should be a $36000\\times 153$ matrix whose columns are the eigenfaces.\nPlot the first eigenface (i.e. the first column of \\li{U}).\nIt should match the first eigenface shown in Figure \\ref{facialRecognition:eigenfaces}.\nBy plotting some of the other eigenfaces, note that each has face-like properties, and different eigenfaces tend to capture different\ntypes of facial structures.\n\\end{problem}\n\nNot all of the eigenfaces are equally important, however.\nIn particular, the eigenfaces corresponding to the singular values closest to 0 contribute the least, on average, to the face vectors in $A$.\nThus, we can get away with only using the eigenfaces corresponding to the $n$ largest singular values (call these the top $n$ eigenfaces).\nThis is important when the rank $r$ is still too large to be practical.\nDefine $U_n$ to be the $l \\times n$ matrix whose columns consist of the top $n$ eigenfaces.\nThe the coordinate vector of $\\bar{f}_i$ in terms of these top $n$ eigenfaces is given by\n\\[\n\\hat{f}_i := U_n^H\\bar{f}_i.\n\\]\nHence the matrix $\\hat{A}$ defined by\n\\[\n\\hat{A}_n = \\begin{bmatrix}\n\\hat{f}_1 & \\hat{f}_2 & \\ldots & \\hat{f}_k\n\\end{bmatrix}\n= U_n^HA\n\\]\ncontains as its columns the coordinate vectors of the face images in the top $n$ eigenfaces basis.\nNote that $\\hat{A}$ is an $n \\times k$ matrix, and is therefore much smaller than the original $l \\times k$ matrix $A$.\n\\begin{problem}\n\\label{prob:top_n}\nThe columns of the matrix \\li{U} that you computed in problem \\ref{prob:svd} are already ordered according to descending singular values.\nThus, the first $n$ columns of \\li{U} give the top $n$ eigenfaces.\nWrite a function \\li{nEigenfaces} that takes as input \\li{U}, \\li{A}, and an integer $n$, and returns the matrices $U_n$ and $\\hat{A}_n$ as described above.\n\\end{problem}\n\\begin{figure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{rebuiltAll.png}\n\\caption{All of the eigenfaces.}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{rebuiltHalf.png}\n\\caption{1/2 of the eigenfaces.}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{rebuiltFourth.png}\n\\caption{1/4 of the eigenfaces.}\n\\end{subfigure}\n\\caption{Image rebuilt with varying number of eigenfaces}\n\\label{facialRecognition:rebuiltImage}\n\\end{figure}\nOf course, moving to a lower-dimensional subspace by using only the top $n$ eigenfaces introduces some error, in the sense that we cannot perfectly\nreconstruct the face images from their coordinate vectors.\nHowever, this error is tolerable, provided $n$ is not \\emph{too} small.\nNote that we can approximately reconstruct $\\bar{f}_i$ from the coordinate vector $\\hat{f}_i$ by\n\\[\n\\bar{f}_i \\approx U_n\\hat{f}_i.\n\\]\nSee Figure \\ref{facialRecognition:rebuiltImage} for examples of reconstructed face images giving different numbers of eigenfaces.\n\nWe now have a low-dimensional representation of our database of face images given by $\\hat{A}_n$, an array of eigenfaces given by $U_n$,\nand the mean face $\\mu$. Using just these objects, we can now perform facial recognition.\nLet $g$ be a face vector.\nWe seek to find the face vector $f_i$ in the database that is closest to $g$.\nIn order to do so, we must process $g$ just as we processed each $f_i$, namely by subtracting out the mean face and then projecting onto the\neigenfaces basis.\nDoing so yields the low-dimensional representation $\\hat{g}$, given by\n\\[\n\\hat{g} = U_n^H(g-\\mu).\n\\]\nWe then return the matching face image $f_{i^*}$, where\n\\[\ni^* = \\text{argmin}_i \\|\\hat{f}_i - \\hat{g}\\|_2.\n\\]\n\\begin{problem}\n\\label{prob:nearest}\nWrite a function \\li{findNearest} that accepts a matrix $M$ of shape $a \\times b$ and a vector $x$\nof length $a$, and returns the index of the column of $M$ that is closest to $x$ with respect to Euclidean distance.\nUsing the NumPy functions \\li{np.linalg.norm} and \\li{np.argmin} will be useful here.\n\\end{problem}\n\n\\begin{problem}\n\\label{prob:match}\nWe will perform facial recognition on additional images from the \\li{faces94} dataset.\n\n\nUse the following code to build an array of additional images from the dataset:\n\\begin{lstlisting}\n>>> # let's gather some random images from the directory, and try to recognize them!\n>>> n_tests = 10\n>>> test_files = []\n>>> for (dirpath, dirnames, filenames) in walk(path):\n>>>     for f in filenames:\n>>>         if f[-3:]==\"jpg\": # only get jpg images\n>>>             test_files.append(dirpath+\"/\"+f)\n>>> test_files = sample(test_files, n_tests)\n>>> test_images = np.array([imread(f).mean(axis=2).ravel() for f in test_files]).T\n\\end{lstlisting}\nYou can change the variable \\li{n_tests} to increase or decrease the number of face images to test.\n\nUsing your function \\li{findNearest} from problem \\ref{prob:nearest}, loop through the test images and find\nthe index of best matching image from the database.\nAs you do so, plot the test face alongside the matching face from the database to determine whether your system\nreally is properly recognizing the faces.\nUse the following code to conveniently plot two face vectors side-by-side:\n\\begin{lstlisting}\n>>> def show2(im1, im2, w=200, h=180):\n>>>     \"\"\"Plot face vectors im1 and im2 side-by-side.\"\"\"\n>>>     plt.subplot(121)\n>>>     plt.imshow(im1.reshape((w,h)), cmap=cm.Greys_r)\n>>>     plt.subplot(122)\n>>>     plt.imshow(im2.reshape((w,h)), cmap=cm.Greys_r)\n>>>     plt.show()\n\\end{lstlisting}\n\nRepeat this experiment for different values of $n$, the number of eigenfaces to include.\nThe system should improve as $n$ gets larger.\n\\end{problem}\n\nBy this point, you have created a basic facial recognition system.\nWe can extend the system to detect when a face doesn't match anything currently in the database, and then add this new face into the database.\nWe can also make the system more robust by including multiple pictures of the same face with different expressions and lighting conditions.\nAlthough there are other approaches to facial recognition that utilize more complex techniques, the method of eigenfaces remains\na wonderfully simple and effective solution and provides another illustration of the usefulness of the singular value decomposition in a variety of applications.\n\n\\begin{comment}\nWhat remains is some old content.\n\n\\section*{Preparing the data}\n\nThrough the course of this lab we will be building a class called \\li{FacialRec} to handle everything in the facial recognition system.\nIn the \\li{specs.py} file included with this lab there is an outline of this class along with some helper functions to help us test our system.\n\nTo populate our database, we will need some images of faces.\nThere are many databases available online, many of which would work with our project.\nHowever, the algorithm which we will use is not completely robust, it requires the images to have similar lighting conditions and head positions.\nTilted head, dark lighting, wearing glasses, and different hairstyles can disrupt the algorithm.\nTherefore, we need a database that contains images with consistent lighting and head posistions.\nAlso, to make the programming easier, we would like the images to be of the same file type and size.\nThe University of Essex has such a database at http://cswww.essex.ac.uk/mv/allfaces/index.html, (as well as other databases with varied head positions and lighting conditions) which we will use.\n\nThe function \\li{getImages} included in the specifications file loads all the JPG files from a directory into a 3 dimensional array.\nThe first dimension specifices the image while the other two give the grayscale image in a 2D array.\nWe can also use the function \\li{showImage} to display the 2D grayscale images.\nThis will be useful for testing the database.\n\n\\begin{problem}\nDownload the faces94 database from the University of Essex from http://cswww.essex.ac.uk/mv/allfaces/index.html.\nInitialize a \\li{FacialRec} object using the file path to the directory and have it use every 50$^{th}$ face in the database.\nAlso, for testing purposes, use the function \\li{getImages} to put the whole database into an array of images.\nThen use \\li{showImage} to show the first image.\n\\end{problem}\n\nNow that we have images, we need to calculate a few things before we can compute the eigenfaces from the covariance matrix.\nWe have already reduced the images to grayscale images in \\li{getImages} to make computations easier.\nNow we need the mean face of all the faces in the database. The mean face is a 2D array of each pixel average across the database.\nNext we need to zero out the images using the mean face.\nWe will substract the mean face from each face in the database, giving the the difference faces.\nThen we flatten the each 2D image into a one dimensional vector so that we have each image described in single vector space.\n\n\\begin{problem}\nImplement the functions \\li{initMeanImage} and \\li{initDifferences}.\n\\li{initMeanImage} should store in \\li{self.meanImage} the image of the means across each pixel in the entire database.\n\\li{initDifferences} should first initilize \\li{self.differenceFaces} to be an array of each image in the database minus the mean image.\n\\li{self.differenceVectors} should be the matrix with the flattened vector of each image in the database as its rows.\nIf the database has 75 images each of size $200 \\times 180$, then \\li{self.differenceVectors} should be $75 \\times 36000$.\nAlso, plot the mean face and the first difference face.\n\\end{problem}\n\n\n\\section*{Computing the Eigenfaces with SVD}\n\nWith these pelimanaries ready, we are now able to construct the Eigenfaces of the system from the covariance matrix.\nAt this point we have each image descibed in a vector space with as many pixels as there are in each image.\nWith the database we are using, this is a 36000 dimensional vector space.\nThere are too many random variables to work with at this point to work with, so we need to find some way to simplify the vector space.\n\nWe do this using the eigenvectors of the covariance matrix (which we call the eigenfaces).\nThe eigenfaces form a basis of all possible faces, so all faces could be expressed as a linear combination of eigenfaces from the covariance matrix gathered from faces in the database.\nThe corresponding eigenvalues of the eigenfaces give the weight or importance of each eigenface.\nNow there the covariance matrix is still very large 36000 and could have many distinct eigenvectors.\nHowever, only eigenfaces corresponding to higher eigenvalues really make a difference.\nInfact, it turns out that there are only as many eigenvalues as there are images in the database.\n\nRecall that taking the SVD of a real valued matrix $A$ gives us the eigenvectors of the matrix $AA^T$ in the columns of $V$.\nIf the difference vectors are denoted by $E$, then the covariance matrix is $C = EE^T$.\nIt then follows that we can use the SVD of $E$ to compute the eigenvectors of $C = EE^T$.\n\nThe \\li{svd} function from \\li{scipy.linalg} returns $U,V,V^T$. You can then get the eigenfaces with a call like\n\\begin{lstlisting}\nu,s,vT = la.svd(self.differenceVectors,full_matricies=False)\nself.eigenfaces = vT\n\\end{lstlisting}\nThis will put into \\li{eigenfaces} the eigenfaces of the database as its rows.\n\n\\begin{problem}\nImplement the function \\li{initEigenfaces} by computing the eigenfaces of the images in the database using the SVD and storing them in \\li{self.eigenfaces}.\nThe eigenfaces should be in the columns of \\li{self.eigenfaces} so that it becomes a $36000 \\times 75$ matrix.\nPlot the first three eigenfaces.\n\\end{problem}\n\n\n\nWith the eigenfaces computed, we can now convert vectors representing faces into the eigenface space and back.\nTo convert to the eigenface space we first subtract off the mean face, flatten the vector, then project the vector on the eigenfaces.\nTo rebuild an image from its representation in eigenfaces, we simply add up the linear combination of eigenfaces then add back in the mean.\n\n\\begin{problem}\nImplement the functions \\li{projectToImageFaceSpace} and \\li{rebuildFromEigenfaces}.\n\\li{projectToImageFaceSpace} should project an image into its coordinates in the basis of the eigenfaces.\n\\li{rebuildFromEigenfaces} should undo that projection by taking the coordinates in the eigenface space, projecting them back, and reshaping the image.\n\\end{problem}\n\n\n\n\\section*{Creating the Facial Recognition System}\n\nThe facial recognition database is almost done.\nGiven a face to seach for, we only have to project it into the eigenface basis and then perform a nearest neighbor seach for the closest image.\n\n\\begin{problem}\nImplement the functions \\li{initClassifier}, and \\li{findNearest}.\n\\li{initClassifier} should initialize \\li{self.nbrs} as a \\li{sklearn.neighbors.KNearestNeighbors} with \\li{nearest_neighbors=1}.\nCreate a set of training points from the images in the database projected into the eigenface basis and use the first \\li{searchOrder} number of coefficeints in the \\li{self.nbrs.fit} function.\nFor the labels give the indicies of the labels in the database (this can be done with \\li{range})\n\nImplement \\li{findNearest} by subtracting off the mean face from the image and then projecting it into the eigenface basis.\nThen perform a nearest neighbor search with the coefficeints up to \\li{searchOrder} using \\li{self.nbrs.predict}.\nThis will return an index to the matching image.\n\nWe also want to compute the distance of the image to the matching image to see if it's really a good match.\nDo this by projecting the matching image to the eigenface basis and then taking the norm of its difference from the image passed in but in the eigenface basis.\n\\end{problem}\n\n\\begin{problem}\nVerification\n\nYour facial recognition database should be working now.\nTry it on some exact images that are in the database, some faces that are in the database but that aren't exact copies, and faces that aren't in the database at all.\n(Pick a random image from the full set, it probably won't be in the database.\n All images that are a multiple of \\li{fileStep} are in the database.\n Indicies close to these are probably of the same person but a different picture.\n As you do all of these take note of the distance between the match and the image.\n Chose a reasonable limiting distance to designate a match or false match and add whether this condition is satisfied as a boolean.\n\\end{problem} \n\\end{comment}", "meta": {"hexsha": "3bdaed86b0b9c72b07a993d1bfde37a4567d4ff2", "size": 23875, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/FacialRecognition/FacialRecognition.tex", "max_stars_repo_name": "rachelwebb/numerical_computing", "max_stars_repo_head_hexsha": "e7416b43b97976060f6875fa46c7dca20a9f635f", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/FacialRecognition/FacialRecognition.tex", "max_issues_repo_name": "rachelwebb/numerical_computing", "max_issues_repo_head_hexsha": "e7416b43b97976060f6875fa46c7dca20a9f635f", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/FacialRecognition/FacialRecognition.tex", "max_forks_repo_name": "rachelwebb/numerical_computing", "max_forks_repo_head_hexsha": "e7416b43b97976060f6875fa46c7dca20a9f635f", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-12-08T01:19:23.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T01:19:23.000Z", "avg_line_length": 57.9490291262, "max_line_length": 194, "alphanum_fraction": 0.7673298429, "num_tokens": 5923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256591565729, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7188456708102721}}
{"text": "\\section{Errors}\n\nThe error boundaries for the classifiers were obtained\nfor both the Chernoff and Bhattacharyya Bounds \\cite{duda2012pattern}.\n\nFor the Chernoff Bounds, the following equations were employed.\n\n\\begin{align*}\n \\min[a,b] & \\leq a^\\beta b^{1-\\beta}  \\quad \\text{for } a,b \\geq 0 \\text{ and } 0\\leq \\beta \\leq 1  \\\\\n P(\\text{error}) & \\leq P^\\beta (\\omega_1) P^{1-\\beta} (\\omega_2) \\int p^\\beta (x | \\omega_1)p^{1-\\beta}(x|\\omega_2)dx  \\text{ for } 0 \\leq \\beta \\leq 1\\\\\n\\int p^\\beta &(x | \\omega_1)p^{1-\\beta}(x|\\omega_2)dx  = \\exp(-k(\\beta)) \\\\\nk(\\beta) &= \\frac{\\beta(1-\\beta)}{2} (\\mu_2 - \\mu_1)^T \\det(\\beta  \\Sigma_1 + (1-\\beta)\\Sigma_2)^{-1} (\\mu_2 - \\mu_1) \\\\\n& \\quad + \\frac{1}{2} \\ln \\frac{\\det(\\beta \\Sigma_1  + (1-\\beta)\\Sigma_2)}{\\det(\\Sigma_1)^\\beta \\det(\\Sigma_2)^{1-\\beta}}\n \\end{align*}\n\n Likewise, for the Bhattacharyya Bounds another set of equations was utilized\n\n\\begin{align*}\n P(\\text{error}) & \\leq \\sqrt{P{\\omega_1} P(\\omega_2)} \\int \\sqrt{p(x | \\omega_1) p(x|\\omega_2)} dx\\\\\n &= \\sqrt{P{\\omega_1} P(\\omega_2)} \\exp{-k(1/2)}\\\\\n k(1/2) &= \\frac{1}{8}(\\mu_2 - \\mu_1)^T \\det(\\frac{\\Sigma_1 + Sigma_2}{2})^{-1} (\\mu_2 + mu_1) \\\\\n & \\quad + \\frac{1}{2} \\ln \\frac{\\det(\\frac{\\Sigma_1 + \\Sigma_2}{2})}{\\sqrt{\\det(\\Sigma_1)\\det(\\Sigma_2)}}\n\\end{align*}\n\n\n\\subsection{Case A}\n\nFor this case, the Chernoff bounds were determined to be\n\n\\begin{table}[htb]\n\\begin{center}\n\\begin{tabular}{ll}\n$P_{12}$ & 0.3712\\%\\\\\n$P_{23}$ & 11.3240\\%\\\\\n$P_{31}$ & 0.0016\\%\n\\end{tabular}\n\\end{center}\n\\caption{Case A - Chernoff Bound}\n\\label{tab: case a chernoff}\n\\end{table}\n\nLikewise the Bhattacharyya bounds were determined\n\n\n\\begin{table}[htb]\n\\begin{center}\n\\begin{tabular}{ll}\n$P_{12}$ & 0.3712\\%\\\\\n$P_{23}$ & 11.3240\\%\\\\\n$P_{31}$ & 0.0016\\%\n\\end{tabular}\n\\end{center}\n\\caption{Case A - Bhattacharyya Bound}\n\\label{tab: case a bhatt}\n\\end{table}\n\n\\begin{figure}\n \\centering\n \\includegraphics{errorCaseA}\n \\caption{Case A - Error bound}\n \\label{case a error}\n\\end{figure}\n\nThe experimental error was also examined for the data set.\n\n\\begin{table}[htb]\n\\begin{center}\n\\begin{tabular}{ll}\n$P_{12}$ & 0.000\\%\\\\\n$P_{23}$ & 4.000\\%\\\\\n$P_{31}$ & 0.000\\%\n\\end{tabular}\n\\end{center}\n\\caption{Case A - Experimental error}\n\\label{tab: case a experiment}\n\\end{table}\n\n\n% errorExp =\n%\n%          0    0.0400         0\n\n\\newpage\n\\pagebreak\n\n\\subsection{Case B}\n\nFor this case, the Chernoff bounds were determined to be\n\n\\begin{table}[htb]\n\\begin{center}\n\\begin{tabular}{ll}\n$P_{12}$ & 0.0049\\%\\\\\n$P_{23}$ & 6.3073\\%\\\\\n$P_{31}$ & 0.0000\\%\n\\end{tabular}\n\\end{center}\n\\caption{Case B - Chernoff Bound}\n\\label{tab: case b chernoff}\n\\end{table}\n\nLikewise the Bhattacharyya bounds were determined\n\n\n\\begin{table}[htb!]\n\\begin{center}\n\\begin{tabular}{ll}\n$P_{12}$ & 0.0049\\%\\\\\n$P_{23}$ & 6.3073\\%\\\\\n$P_{31}$ & 0.0000\n\\end{tabular}\n\\end{center}\n\\caption{Case B - Bhattacharyya Bound}\n\\label{tab: case b bhatt}\n\\end{table}\n\n\n\\begin{figure}\n \\centering\n \\includegraphics{errorCaseB}\n \\caption{Case B - Error bound}\n \\label{case b error}\n\\end{figure}\n\n\nThe experimental error was also examined for the data set.\n\n\\begin{table}[htb]\n\\begin{center}\n\\begin{tabular}{ll}\n$P_{12}$ & 0.000\\%\\\\\n$P_{23}$ & 8.000\\%\\\\\n$P_{31}$ & 0.000\\%\n\\end{tabular}\n\\end{center}\n\\caption{Case B - Experimental error}\n\\label{tab: case b experiment}\n\\end{table}\n\n% errorExp =\n%\n%          0    0.0800         0\n\n\\newpage\n\\pagebreak\n\n\\subsection{Case C}\n\nFor this case, the Chernoff bounds were determined to be\n\n\\begin{table}[htb!]\n\\begin{center}\n\\begin{tabular}{ll}\n$P_{12}$ & 0.0012\\%\\\\\n$P_{23}$ & 7.9909\\%\\\\\n$P_{31}$ & 0.0000\\%\n\\end{tabular}\n\\end{center}\n\\caption{Case C - Chernoff Bound}\n\\label{tab: case c chernoff}\n\\end{table}\n\nLikewise the Bhattacharyya bounds were determined\n\n\n\\begin{table}[htb!]\n\\begin{center}\n\\begin{tabular}{ll}\n$P_{12}$ & 0.0074\\%\\\\\n$P_{23}$ & 8.0726\\%\\\\\n$P_{31}$ & 0.0000\\%\n\\end{tabular}\n\\end{center}\n\\caption{Case C - Bhattacharyya Bound}\n\\label{tab: case c bhatt}\n\\end{table}\n\n\\begin{figure}\n \\centering\n \\includegraphics{errorCaseC}\n \\caption{Case C - Error bound}\n \\label{case c error}\n\\end{figure}\n\nThe experimental error was also examined for the data set.\n\n\\begin{table}[htb]\n\\begin{center}\n\\begin{tabular}{ll}\n$P_{12}$ & 0.000\\%\\\\\n$P_{23}$ & 3.333\\%\\\\\n$P_{31}$ & 0.000\\%\n\\end{tabular}\n\\end{center}\n\\caption{Case C - Experimental error}\n\\label{tab: case c experiment}\n\\end{table}\n\n\n% errorExp =\n%\n%          0    0.0333         0\n", "meta": {"hexsha": "5ee13717ab29dbfd70b80415dc381c9729580ae2", "size": 4432, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/error.tex", "max_stars_repo_name": "der-coder/CINVESTAV-Mathematics-II-2020", "max_stars_repo_head_hexsha": "ccd3364818c673f7a6bf13d495004034d2c6ecc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/error.tex", "max_issues_repo_name": "der-coder/CINVESTAV-Mathematics-II-2020", "max_issues_repo_head_hexsha": "ccd3364818c673f7a6bf13d495004034d2c6ecc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/error.tex", "max_forks_repo_name": "der-coder/CINVESTAV-Mathematics-II-2020", "max_forks_repo_head_hexsha": "ccd3364818c673f7a6bf13d495004034d2c6ecc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.8325123153, "max_line_length": 154, "alphanum_fraction": 0.6444043321, "num_tokens": 1746, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7188456642919939}}
{"text": "\\chapter{Physically-Inspired Excitations}\\label{ch:physInspExcitations}\nThis short chapter introduces several simple ways to excite the different resonators presented in Part \\ref{part:resonators}. First, various ways to excite resonators using initial conditions will be given, after which examples of time-varying excitations will be given, such that the systems can also be excited later during the simulation.\n\n\\section{Initial conditions}\\label{sec:initConditionsPhysInsp}\nThe easiest way to excite a system is to set its initial conditions to non-zero values. This has been done several times before using a raised cosine (see e.g. Section \\ref{sec:output1DWave}). To give the system an initial displacement, not an initial velocity, one initialises both $u^0_l$ and $u^1_l$ with the same values. In the following, the 1D wave equation will be used as an example (Eq. \\eqref{eq:1DwavePDE}):\n\\begin{equation}\n    \\ptt u = c^2 \\pxx u\n\\end{equation}\nwhere $u=u(x,t)$ is the state of the system defined for $t\\geq 0$ and $x\\in D$ with domain $\\D = [0, L]$ and length $L$ (in m). Furthermore, $c = 735$ m/s. Following \\ref{sec:gridFunctions}, the state variable can be discretised to $\\uln$ where $n\\in \\mathbb{N}^0$ and $l\\in d$ with discrete domain $d = \\{0, \\hdots, N\\}$ and number of grid points $N+1$. The FD scheme is (Eq. \\eqref{eq:1DwaveFDS}\n\\begin{equation}\n    \\dtt \\uln = c^2 \\dxx \\uln.\n\\end{equation}\n\n\\subsection{Impulse}\nThe simplest way to excite a system is to set the value of one grid point to non-zero, which is referred to as an \\textit{impulse} excitation. Figure \\ref{fig:impulse} shows an implementation of the 1D wave equation where $u_l^0 = u_l^1 = 1$ at $l = \\floor[0.5 N]$. One can observe that the variations between two neighbouring grid points are extremely high. If the CFL condition in Eq. \\eqref{eq:CFL} is satisfied with equality, the the system will exhibit frequencies around the Nyquist frequency, which is generally unwanted.\n\n\\def\\figWidth{0.32}\n\\begin{figure}[h]\n    \\centering\n    \\subfloat[$n = 1$.\\label{fig:impulse1}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/exciters/physInsp/impulse1.eps}}\\hfill\n    \\subfloat[$n = 6$.\\label{fig:impulse2}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/exciters/physInsp/impulse2.eps}}\\hfill\n    \\subfloat[$n = 11$.\\label{fig:impulse3}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/exciters/physInsp/impulse3.eps}}\n    \\caption{The 1D wave equation initialised with an impulse at $l=\\floor[0.5N]$.\\label{fig:impulse}}\n\\end{figure}\n\n\\subsection{Raised cosine}\\label{sec:raisedCosine}\nTo avoid the high-frequency behaviour caused by the impulse is to using a spatially smooth excitation. To achieve this, a \\textit{raised cosine} is most often used due to this property and is extensively used throughout the literature \\cite{theBible}. Initialising the displacement of a distributed system with a raised cosine can be interpreted as a pluck. A different pluck excitation is presented in Section \\ref{sec:pluck}.\n\nA raised cosine is parametrised by its amplitude $e_\\text{amp}$, its center location $x_0$ and its width $x_\\text{w}$. Applied to a distributed 1D system defined over domain $x\\in \\D$, the (continuous-time) excitation function containing a raised cosine is defined as \n\\begin{equation}\\label{eq:raisedCosCont}\n    e_\\text{rc}(x) = \n    \\begin{cases}\n        \\frac{e_\\text{amp}}{2}\\left(1 - \\cos\\left(\\frac{2\\pi (x - x_\\stxt)}{x_\\text{w}}\\right)\\right), & \\text{if } x_\\stxt \\leq x \\leq x_\\etxt,\\\\\n        0, & \\text{otherwise},\n    \\end{cases}\n\\end{equation}\nwhere \n\\begin{equation}\\label{eq:xsxe}\n    x_\\stxt = x_0 - \n    \\frac{x_\\text{w}}{2}, \\qaq x_\\etxt = x_0 + \\frac{x_\\text{w}}{2}\n\\end{equation}\nare the start and end locations of the excitation. Furthermore, $x_\\stxt, x_\\etxt \\in \\D$, which puts a constraint on the width and location of the excitation. \n\nIn discrete time, the center location is defined as $l_0 = \\floor[x_0 / h]$, where $\\floor[\\cdot]$ denotes the flooring operation, $h$ is the grid spacing. The discrete start and end locations of the raised cosine are\n\\begin{equation}\\label{eq:lsle}\n    l_\\text{s} = l_0 - \\floor[w/2]\\qaq l_\\etxt = l_0 + \\floor[w/2],\n\\end{equation}\nwith $l_\\stxt, l_\\etxt\\in d$ and, finally, $w = \\floor[x_\\text{w} / h]$.\\footnote{Notice that the width is given in `grid spacings' and will thus affect $w+1$ grid points. This is also why the range in \\eqref{eq:raisedCosDisc} includes both end points.} Equation \\eqref{eq:raisedCosCont} can then be discretised as\n\\begin{equation}\\label{eq:raisedCosDisc}\n    E_{l, \\text{rc}} =\n    \\begin{cases}\n        \\frac{e_\\text{amp}}{2}\\left(1 - \\cos\\left(\\frac{2\\pi (l - l_\\stxt)}{w}\\right)\\right), & \\text{if } l_\\stxt \\leq l \\leq l_\\etxt,\\\\\n        0, & \\text{otherwise}.\n    \\end{cases}\n\\end{equation}\nFigure \\ref{fig:raisedCos} shows the 1D wave equation initialised with a raised cosine with $e_\\text{amp} = 1$, $l_0 = \\floor[0.5N]$ and $w = \\floor[0.1N]$. Notice that the behaviour is much more smooth than the impulse shown in Figure \\ref{fig:impulse}.\n\n\\def\\figWidth{0.32}\n\\begin{figure}[h]\n    \\centering\n    \\subfloat[$n = 1$.\\label{fig:raisedCos1}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/exciters/physInsp/raisedCos1.eps}}\\hfill\n    \\subfloat[$n = 6$.\\label{fig:raisedCos2}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/exciters/physInsp/raisedCos2.eps}}\\hfill\n    \\subfloat[$n = 11$.\\label{fig:raisedCos3}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/exciters/physInsp/raisedCos3.eps}}\n    \\caption{The 1D wave equation initialised with a raised cosine at the center of the system.\\label{fig:raisedCos}}\n\\end{figure}\n\n\\subsubsection{Strike}\\label{sec:strike}\nIf one initialises the system with an initial velocity, i.e., only setting a displacement at $n=1$, and leaving $u^0_l = 0$ for $l\\in d$, one can use the raised cosine to model a strike. Figure \\ref{fig:strike} shows a strike using the same values as for the pluck in Figure \\ref{fig:raisedCos} at $n=1$, but leaving $u_l^0 = 0$. One can observe that, for the pluck, the displacement of the system stays high rather than going back to 0 as in the case of the pluck. Furthermore, the amplitude of the displacement is higher than for the pluck (notice the scaling of the y-axis).%\\footnote{In the case of the 1D wave equation struck using a raised cosine, the maximum amplitude can be calculated to be half of the summed values of the excitation.}\n\n\\def\\figWidth{0.32}\n\\begin{figure}[h]\n    \\centering\n    \\subfloat[$n = 1$.\\label{fig:strike1}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/exciters/physInsp/strike1.eps}}\\hfill\n    \\subfloat[$n = 6$.\\label{fig:strike2}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/exciters/physInsp/strike2.eps}}\\hfill\n    \\subfloat[$n = 11$.\\label{fig:strike3}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/exciters/physInsp/strike3.eps}}\n    \\caption{The 1D wave equation initialised with a strike at the center of the system. Notice the scaling of the y-axis compared to the other figures. \\label{fig:strike}}\n\\end{figure}\n\n\\subsection{Triangular pluck}\\label{sec:pluck}\nAnother way to initialise the string, which is closer to reality, is to use a triangular shape to model a pluck \\cite{Fletcher1998, theBible}.%, where the authors analytically decompose the system into its modes of vibration as well as their respective amplitudes depending on the plucking position. \n%\nUsing $e_\\text{amp}$ as the maximum displacement -- at the corner of the triangle -- and $x_0\\in \\D$ as the plucking position, the triangular excitation can be defined as\n\\begin{equation}\\label{eq:triangleCont}\n    e_\\text{tri}(x) = \\begin{cases}\n        \\frac{e_\\text{amp}}{x_0} x, & \\text{if } 0\\leq x \\leq x_0,\\\\\n        \\frac{e_\\text{amp}}{x_0 - L} (x - L), &\\text{if } x_0 < x \\leq L.\n    \\end{cases}\n\\end{equation}\n\nIn discrete time, Eq. \\eqref{eq:triangleCont} becomes \n\\begin{equation}\n    E_{l, \\text{tri}} = \\begin{cases}\n        \\frac{e_\\text{amp}}{l_0} l, & \\text{if } 0\\leq l \\leq l_0,\\\\\n        \\frac{e_\\text{amp}}{l_0 - N} (l - N), &\\text{if } l_0 < l \\leq N.\n    \\end{cases}\n\\end{equation}\nDue to the spatial discontinuity at the corner, some high-frequency oscillations (similar to the impulse) might emerge. Figure \\ref{fig:pluck} shows an implementation of the 1D wave equation initialised with a triangular pluck excitation. The sample rate is 10x the usual one to prevent these high-frequency oscillations from appearing in the plot (though they still exist to some degree). \n\n\\def\\figWidth{0.32}\n\\begin{figure}[h]\n    \\centering\n    \\subfloat[$n = 1$.\\label{fig:pluck1}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/exciters/physInsp/triangle1.eps}}\\hfill\n    \\subfloat[$n = 101$.\\label{fig:pluck2}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/exciters/physInsp/triangle2.eps}}\\hfill\n    \\subfloat[$n = 201$.\\label{fig:pluck3}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/exciters/physInsp/triangle3.eps}}\n    \\caption{The 1D wave equation initialised with a triangular pluck with $l_0=\\floor[0.2N]$. Note that sample rate has been set to $\\fs = 441000$ Hz to show more ideal triangular motion. \\label{fig:pluck}}\n\\end{figure}\n\n\\subsection{2D raised cosine}\\label{sec:2DraisedCos}\nIntroducing an extra coordinate $y$, one can extend the raised cosine presented in Section \\ref{sec:raisedCosine} to 2D according to \n\\begin{equation}\\label{eq:raisedCosCont2D}\n    e_\\text{rc}(x,y)\\! =\\! \n    \\begin{cases}\n        \\!\\frac{e_\\text{amp}}{2}\\left(1 - \\cos\\left(\\frac{2\\pi (x - x_\\stxt)}{r_\\text{w}}\\right)\\right)\\left(1 - \\cos\\left(\\frac{2\\pi (y - y_\\stxt)}{r_\\text{w}}\\right)\\right), & \n        \\!\\!\\!\\begin{aligned}\n            &\\text{if } x_\\stxt \\leq x \\leq x_\\etxt, \\\\\n            &\\text{and } y_\\stxt \\leq y \\leq y_\\etxt,\n        \\end{aligned}\\\\[1.25em]\n        \\!0, &\\!\\! \\text{otherwise},\n    \\end{cases}\n\\end{equation}\nwhere $r_\\text{w}$ is the excitation radius. Similar to Eq. \\eqref{eq:xsxe}, the start and end locations of the raised cosine in the $x$ and $y$ direction can be calculated as\n\\begin{equation*}\n    x_\\stxt = x_0 - \n    \\frac{r_\\text{w}}{2}, \\quad x_\\etxt = x_0 + \\frac{r_\\text{w}}{2}, \\quad y_\\stxt = y_0 - \n    \\frac{r_\\text{w}}{2}, \\qaq y_\\etxt = y_0 + \\frac{r_\\text{w}}{2},\n\\end{equation*}\nwhere $(x_0, y_0)$ is the center coordinate and $x_\\stxt, x_\\etxt, y_\\stxt,  y_\\text{e}\\in \\D$ for a 2D domain $\\D$.\n\nIn discrete time, Eq. \\eqref{eq:raisedCosCont2D} becomes\n\\begin{equation}\n    E_{(l,m), \\text{rc}} = \n    \\begin{cases}\n        \\!\\frac{e_\\text{amp}}{2}\\left(1 - \\cos\\left(\\frac{2\\pi (l \\!-\\! l_\\stxt)}{r}\\right)\\right)\\!\\left(1\\! -\\! \\cos\\left(\\frac{2\\pi (m - m_\\stxt)}{r}\\right)\\right)\\!, & \\!\\!\\!\\!\n        \\begin{aligned}\n            &\\text{if } l_\\stxt \\leq l \\leq l_\\etxt, \\text{ and}\\\\\n            & m_\\stxt \\leq m \\leq m_\\etxt,\n        \\end{aligned}\\\\\n        \\!0, &\\!\\!\\!\\! \\text{otherwise},\n    \\end{cases}\n\\end{equation}\nwhere $r = \\floor[r_\\text{w} / h]$ is the discrete excitation radius (in `grid spacings')\\todo{look at this}. Furthermore, similar to Eq. \\eqref{eq:lsle},\n\\begin{equation}\n    l_\\text{s} = l_0 - \\floor[r/2],\\ l_\\etxt = l_0 + \\floor[r/2],\\ m_\\text{s} = m_0 - \\floor[r/2], \\ \\text{and} \\ m_\\etxt = m_0 + \\floor[r/2]\n\\end{equation}\nfor discrete center coordinate $(l_0, m_0)$ and $l_\\stxt, l_\\etxt, m_\\stxt,  m_\\text{e}\\in d$ for a discrete 2D domain $d$. \nAs in the 1D case, this excitation can be used to model a simple `pluck' and strike for a 2D system. \n\nA simple way to implement the 2D raised cosine in \\texttt{MATLAB} using the \\texttt{hann} function is shown in Algorithm \\ref{alg:2DraisedCos}.\n\\\\\n\\begin{lstlisting}[caption={A \\texttt{MATLAB} implementation of a 2D raised cosine.}, label=alg:2DraisedCos]\n% Assuming Dirichlet boundary conditions and having initialised the following\n% - center locations for the x and y-directions: l0 and m0\n% - radius of the excitation r (in grid points)\n\nls = l0 - floor(r/2); % start location x-direction\nle = l0 + floor(r/2); % end location x-direction\nms = m0 - floor(r/2); % start location y-direction\nme = m0 + floor(r/2); % end location x-direction\n\n% Create excitation matrix\ne = zeros(Ny-1, Nx-1);\n\n% Add one to hann function as the width is given in `grid spacings'\n% and affects r+1 grid points\ne(ms:me, ls:le) = hann(r+1) * hann(r+1)';\n\n% Applying excitation to stacked matrix form as in Section %*\\refMatlab[sec:2DwaveImplementation]*)\nu = reshape(e, (Nx-1) * (Ny-1), 1);\n\\end{lstlisting} \n\n\\section{Time-varying excitations}\nAlthough various types of excitation can already be modelled using the initial conditions presented in the previous section, they are temporally rigid. In other words, the time of excitation is fixed to be at the start of the simulation. In order to excite the system while the simulation is running, one can create excitations that -- on top of being spatially distributed -- have temporal profile as well.\n\nFor the following, consider the ideal string of length $L$ (in m), its transverse displacement described by $u = u(x,t)$ (in m). The system is defined for $t\\geq 0$ and $x\\in\\D$ with domain $\\D = [0, L]$. The PDE of the ideal string with a time varying external force $f(t)$ (in N) is defined as (Eq. \\eqref{eq:1DwavePDE})\n\\begin{equation}\n    \\rho A\\ptt u = T \\pxx u + e(x)f(t)\n\\end{equation}\nwhere $e(x)$ is a spatial distribution function such as those presented in Section \\ref{sec:initConditionsPhysInsp} (in m$^{-1}$).\n\n\\subsection{Raised cosine}\\label{sec:timeVaryingRaisedCos}\nTo yield a smooth excitation over time, one can, similar to the spatially distributed raised cosine in Eq. \\ref{sec:raisedCosine}, define a temporally distributed raised cosine. Using the time of excitation $t_0\\geq 0$ and excitation duration $t_\\text{d}>0$ (both in s) the temporal raised cosine can be used as a force function, as\n\\begin{equation}\\label{eq:raisedCosTemp}\n    f(t) = \n    \\begin{cases}\n        \\frac{f_\\text{amp}}{2} \\left(1 - \\cos\\left(\\frac{q\\pi (t - t_0)}{t_\\text{d}}\\right)\\right), & t_\\stxt \\leq t \\leq t_0 + t_\\text{d}\\\\\n        0, &\\text{otherwise}.\n    \\end{cases}\n\\end{equation} \nAs done in \\cite{Webb2015}, $q$ that alters the excitation to be a pluck when $q=1$ and a strike when $q=2$. Finally, $f_\\text{amp}$ is the maximum force (in N). \n\nAs done in papers \\citeP[A] and \\citeP[B], the force function can be used in conjunction with the distribution functions shown in Section \\ref{sec:initConditionsPhysInsp}. When used to scale a spatially distributed raised cosine as in Eq. \\eqref{eq:raisedCosCont}, one can model a pluck or a strike, by setting $q=1$ or $q=2$ respectively. These alternatives are visualised in Figure \\ref{fig:timeVaryingRaisedCos}. Note, that if one would like $f_\\text{amp}$ to be the maximum force, one must set $e_\\text{amp} = 1$ in Eq. \\eqref{eq:raisedCosCont}. \n\nIn discrete time, the force function in Eq. \\eqref{eq:raisedCosTemp} becomes\n\\begin{equation}\\label{eq:discExcitation}\n    f^n = \n    \\begin{cases}\n        \\frac{f_\\text{amp}}{2}\\left(1-\\cos\\left(\\frac{q\\pi (n - n_0)}{n_\\text{d}}\\right)\\right), & n_0 \\leq n \\leq n_0+n_\\text{d},\\\\\n        0, &\\text{otherwise}.\n    \\end{cases}\n\\end{equation}\nwhere $n_\\text{d} = \\floor[t_\\text{d}/k]$ is the duration of the excitation in samples.\n\n\n\\def\\figWidth{0.8}\n\\begin{figure}[h]\n    \\centering\n    \\subfloat[Pluck ($q=1$).\\label{fig:timeVaryingRaisedCosPluck}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/exciters/physInsp/timeVaryingRaisedCos.eps}}\\\\\n    \\subfloat[Strike ($q=2$).\\label{fig:timeVaryingRaisedCosStrike}]{\\includegraphics[width=\\figWidth\\textwidth]{figures/exciters/physInsp/timeVaryingRaisedCosHammer.eps}}\\hfill\n    \\caption{The time-varying raised cosine showing a (a) pluck and a (b) strike. The location of excitation $x_0$ is shown in green, the width $x_\\text{w}$ in red and the excitation start $t_0$ and duration $t_\\text{d}$ in blue.\\label{fig:timeVaryingRaisedCos}}\n\\end{figure}\n\n\\subsection{Pulse train}\\label{sec:pulseTrain}\nAs already briefly introduced in Section \\ref{sec:webstersExcitation}, one can create a pulse train to excite an acoustic tube. This is inspired by \\cite{theBible} where the signal represents the opening and closing of the glottis. As the characteristics of the lip reed are similar to the vocal folds \\cite{Richards2003}, the pulse train has been used as a test signal here (also see Section \\ref{sec:lipreedTube}). A more complete model of the lip reed can be found in Chapter \\ref{ch:lipreed}.\n\nThe pulse train can be created using a clipped sinusoid which can be used as the input velocity to an acoustic tube. Algorithm \\ref{alg:pulseTrain} shows an example of how to generate a pulse train. The frequency as well as the duty cycle (how much of the signal is non-zero) can be set. Figure \\ref{fig:pulseTrain} shows the output of the algorithm.\n\\begin{minipage}{\\textwidth}\n\\setlstMAT\n\\begin{lstlisting}[caption={\\texttt{MATLAB} code to generate a pulse train}, label=alg:pulseTrain]\n%% Pulse train generator\n\nfs = 44100;             % Sample rate [Hz]\nlengthSound = fs;       % Length of the sound [samples]\nf = 440;                % Pulse train frequency\ndutyC = 0.75;           % Duty cycle [0-1]\namp = 1;                % Amplitude\n\n%% Create input signal\nfor n = 0:lengthSound\n    if mod(n, fs / f) <= fs / f * dutyC\n        vIn(n+1) = amp * sin(f * pi / dutyC * mod(n, fs / f) / fs);\n    else\n        vIn(n+1) = 0;\n    end\nend\n\\end{lstlisting}\n\\end{minipage}\n\n% For a pulse train with a maximum amplitude of 1 and a frequency $f$ (in Hz), the following is proposed\n% \\def\\depth{c_\\text{d}}\n% \\begin{equation}\\label{eq:pulseTrain}\n%     v_\\text{in} = \\left[\\frac{\\sin(2\\pi f t) - (1-2\\depth)}{2\\depth}\\right]_+,\n% \\end{equation}\n% where $0< \\depth \\leq 0.5$ is the clipping depth, and determines the duty cycle, i.e. the distance between the pulses. Finally, the $[\\cdot]_+$ operator specifies `the positive part of' and is used for clipping (see Chapter \\ref{ch:collisions}). \n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/exciters/physInsp/pulseTrain.eps}\n    \\caption{The pulse train generated using Algorithm \\ref{alg:pulseTrain} ($f = 440$ Hz, duty cycle $ = 75\\%$).\n    \\label{fig:pulseTrain}}\n\\end{figure}", "meta": {"hexsha": "e9d732177572e26d0ce2e774eda0d3ec4f57c615", "size": 18251, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "aauPhdCollectionThesis/exciters/physicallyInspired.tex", "max_stars_repo_name": "SilvinWillemsen/phdThesis", "max_stars_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aauPhdCollectionThesis/exciters/physicallyInspired.tex", "max_issues_repo_name": "SilvinWillemsen/phdThesis", "max_issues_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aauPhdCollectionThesis/exciters/physicallyInspired.tex", "max_forks_repo_name": "SilvinWillemsen/phdThesis", "max_forks_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.297188755, "max_line_length": 745, "alphanum_fraction": 0.7097145362, "num_tokens": 5844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7188456642919939}}
{"text": "\\subsection{Branching}\r\nAs observed, when we compactify a surface, something that used to be a covering map no longer has that property.\r\n\\begin{example}\r\n    The map $p_k:\\mathbb C_\\star\\to\\mathbb C_\\star$ via $z\\mapsto z^k$ is a covering map, but $\\hat{p}_k:\\mathbb C_\\infty\\to\\mathbb C_\\infty$ is not (if $k\\ge 2$).\r\n\\end{example}\r\n\\begin{definition}\r\n    let $f:R\\to S$ be analytic.\r\n    For $p\\in R$, recall that we can find charts that put $f$ into a standard local form $\\psi\\circ f\\circ\\phi^{-1}(z)=z^n$ near $p$ for some $n\\in\\mathbb Z_{\\ge 0}$ by Proposition \\ref{local_p_k}.\r\n    The integer $n$ does not depend on the choice of charts (as we can alternatively define it to be the size of $f^{-1}(\\{f(p)\\})$, and is called the multiplicity $m_f(p)$ of $f$ at $p$.\r\n\\end{definition}\r\nMost points have multiplicity $1$, the remaining ones are especially interesting.\r\n\\begin{definition}\r\n    If $m_f(p)>1$, then $p$ is called the ramification point of $f$ and $f(p)$ is called a branch point of $f$.\r\n    In this case, $m_f(p)$ is sometimes also called the ramification index.\r\n\\end{definition}\r\n\\begin{example}\r\n    The map $\\hat{p}_k:\\mathbb C_\\infty\\to\\mathbb C_\\infty$ via $z\\mapsto z^k$ and $0\\mapsto 0,\\infty\\mapsto\\infty$.\r\n    Then the ramification points are $z=0,\\infty$ and the branch points are $w=0,\\infty$.\\\\\r\n    More generally, for polynomials $f:\\mathbb C_\\infty\\to\\mathbb C_\\infty$, $f(z)=a_dz^d+\\cdots+a_0$ ($a_d\\neq 0$) for $z\\neq\\infty$ and $f(\\infty)=\\infty$, changing the variable $w=1/z$ gives\r\n    $$\\frac{1}{f(z)}=\\frac{1}{a_dz^d+\\cdots+a_0}=\\frac{w^d}{a_d+\\cdots+a_0w^d}=w^dg(w)$$\r\n    where $g$ is (locally) analytic and nonzero, hence $m_\\infty(f)=d$.\r\n\\end{example}\r\n\\begin{remark}\r\n    Let $f:R\\to\\mathbb C$ be an analytic function, $p\\in R$ and $(\\phi,U)$ a chart containing $p$.\r\n    Then\r\n    $$F(z)=f\\circ\\phi^{-1}(z)=(z-z_0)^mg(z),z_0=\\phi(p)$$\r\n    where $m=m_f(p)$ by definition.\r\n    So $F^\\prime(z)=(mg(z)+(z-z_0)g^\\prime(z))(z-z_0)^{m-1}$.\r\n    If $m=1$, then $F^\\prime(z_0)=g(z_0)\\neq 0$.\r\n    But if $m>1$, then $F^\\prime(z_0)=mg(z_0)(z_0-z_0)^{m-1}=0$.\r\n    Therefore the ramification points are exactly the zeros of $F^\\prime$.\r\n\\end{remark}\r\n\\begin{lemma}\r\n    If $f:R\\to S$ and $g:S\\to T$ are analytic, then $m_{g\\circ f}(p)=m_g(f(p))m_f(p)$ for any $p\\in R$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Find the respective local coordinates such that $f$ corresponds to $z\\mapsto z^{m_f(p)}$ and $g$ corresponds to $w\\mapsto w^{m_g(f(p))}$, then in those local coordinates $g\\circ f$ is $z\\mapsto(z^{m_f(p)})^{m_g(f(p))}=z^{m_g(f(p))m_f(p)}$.\r\n    The equality follows.\r\n\\end{proof}", "meta": {"hexsha": "3a8400ebfe0bab13092991447e300bec4985ae3b", "size": 2628, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10/branch.tex", "max_stars_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_stars_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "10/branch.tex", "max_issues_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_issues_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "10/branch.tex", "max_forks_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_forks_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.3846153846, "max_line_length": 244, "alphanum_fraction": 0.6476407915, "num_tokens": 972, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256512199033, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7188456640330486}}
{"text": "\\chapter{Basics of Recursive Bayesian Estimation}\n\nIn following sections the problem of recursive Bayesian estimation (Bayesian filtering) is\nstated and its analytical solution is derived. Later on, due to practical intractability of the\nsolution in its general form, a few methods that either simplify the problem or approximate the\nsolution are shown.\n\n\\section{Problem Statement}\n\nAssume a dynamic system described by a hidden real-valued \\emph{state vector} \\(x\\) which evolves at\ndiscrete time steps according to a known function \\(f_t\\) (in this text called \\emph{process model})\nas described by \\eqref{eq:DynSysFt}.\n\\begin{equation} \\label{eq:DynSysFt}\n\tx_t = f_t(x_{t-1}, v_{t-1})\n\\end{equation}\n\nVariable \\(v_t\\) in \\eqref{eq:DynSysFt} denotes random \\emph{process noise}, which may come from various\nsources and is often inevitable. Sequence of \\(v_t\\) is assumed to be identically independently\ndistributed random variable sequence.\n\nThe state of the system is hidden and can only be observed though a real-valued \\emph{observation vector}\n\\(y\\) that relates to the state \\(x\\) as in \\eqref{eq:DynSysHt}, but adds further \\emph{observation\nnoise} \\(w\\).\n\\begin{equation} \\label{eq:DynSysHt}\n\ty_t = h_t(x_t, w_t)\n\\end{equation}\n\nIn \\eqref{eq:DynSysHt} \\(h_t\\) is known function called \\emph{observation model} in this text and \\(w_t\\) is\nidentically independently distributed random variable sequence that denotes observation noise.\n\nThe goal of recursive\\footnote{by the word recursive we mean that it is not needed to keep track of\nthe whole batch of previous observations in practical methods, only appropriate quantities from time\nmoments \\(t-1\\) and \\(t\\) are needed to estimate \\(x_t\\). However, this does not apply to the\nderivation of the solution, where the notation of whole batch of observations \\(y_{1:t}\\) is used.}\nBayesian estimation is to give an estimate of the state \\(x_t\\) given the\nobservations \\(y_{1:t}\\) provided the knowledge of the functions \\(f_t\\) and \\(h_t\\).\nMore formally, the goal is to find the {\\pdf} \\(p(x_t | y_{1:t})\\).\nTheoretical solution to this problem is known and is presented in next section.\n\n\\section{Theoretical solution}\n\nAt first, we observe that {\\pdf} \\(p(x_t|x_{t-1})\\) can be derived from the process model\n\\eqref{eq:DynSysFt} (given the distribution of \\(v_k\\)) and that \\(p(y_t|x_t)\\) can be derived from\nthe observation model \\eqref{eq:DynSysHt} respectively. (given the distribution of \\(w_k\\))\n\nBecause recursive solution is requested, suppose that \\(p(x_{t-1}|y_{1:t-1})\\) and\n\\(p(x_0)\\) are known\\footnote{\\(p(x_0)\\) can be called initial {\\pdf} of the state vector.} in\norder to be able to make the transition \\(t-1 \\; \\rightarrow \\; t\\).\n\nIn the first stage that can be called \\emph{prediction}, \\emph{prior} {\\pdf}\n\\(p(x_t | y_{1:t-1})\\) is calculated without knowledge of \\(y_t\\). We begin the derivation by\nperforming the reverse of the marginalization over \\(x_{k-1}\\).\n\\begin{equation*}\n\tp(x_t | y_{1:t-1}) = \\int_{-\\infty}^{\\infty} p(x_t, x_{t-1} | y_{1:t-1}) \\; \\dx_{t-1}\n\\end{equation*}\n\nUsing chain rule for {\\pdfs}, the element of integration can be split.\n\\begin{equation*}\n\tp(x_t | y_{1:t-1}) = \\int_{-\\infty}^{\\infty} p(x_t | x_{t-1}, y_{1:t-1}) p(x_{t-1} | y_{1:t-1}) \\; \\dx_{t-1}\n\\end{equation*}\n\nWith an assumption that the modelled dynamic system \\eqref{eq:DynSysFt} possesses \\emph{Markov\nProperty}\\footnote{an assumption of independence that states that system state in time \\(t\\) only\ndepends on system state in \\(t-1\\) (and is not directly affected by previous states).},\n\\(p(x_t | x_{t-1}, y_{1:t-1})\\) equals \\(p(x_t | x_{t-1})\\).~\\cite{AruMasGor:02}\nThis leaves us with the result \\eqref{eq:PriorPdf}.\n\\begin{equation} \\label{eq:PriorPdf}\n\tp(x_t | y_{1:t-1}) = \\int_{-\\infty}^{\\infty} p(x_t | x_{t-1}) p(x_{t-1} | y_{1:t-1}) \\; \\dx_{t-1}\n\\end{equation}\n\nAs we can see, prior {\\pdf} only depends on previously known functions and therefore can be\ncalculated.\n\nWe continue with the second stage that could be named \\emph{update}, where new observation \\(y_t\\) is taken into\naccount and \\emph{posterior} {\\pdf} \\(p(x_t | y_{1:t})\\) is calculated. Bayes' theorem can be used\nto derive posterior {\\pdf} \\eqref{eq:PosteriorPdfRaw}.\n\\begin{equation} \\label{eq:PosteriorPdfRaw}\n\tp(x_t | y_{1:t}) = \\frac{p(y_t | x_t, y_{1:t-1}) p(x_t | y_{1:t-1})}{p(y_t | y_{1:t-1})}\n\\end{equation}\n\nAccording to the observation model \\eqref{eq:DynSysHt} and assuming Markov property, \\(y_t\\) only\ndepends on \\(x_t\\). That is \\(p(y_t | x_t, y_{1:t-1}) = p(y_t | x_t)\\). Therefore posterior\n{\\pdf} can be further simplified into \\eqref{eq:PosteriorPdf}.\n\\begin{equation} \\label{eq:PosteriorPdf}\n\tp(x_t | y_{1:t}) = \\frac{p(y_t | x_t) p(x_t | y_{1:t-1})}{p(y_t | y_{1:t-1})}\n\\end{equation}\n\nWhile both {\\pdfs} in the numerator of \\eqref{eq:PosteriorPdf} are already known, \\(p(y_t|y_{1:t-1})\\)\nfound in the denominator can be calculated using the formula \\eqref{eq:MargLikelihood}, where\nmarginalization over \\(x_t\\) is preformed. Quantity \\eqref{eq:MargLikelihood} can also be interpreted as\n\\emph{marginal likelihood} (sometimes called \\emph{evidence}) of observation.~\\cite{Smi:10}\n\\begin{equation} \\label{eq:MargLikelihood}\n\tp(y_t | y_{1:t-1}) = \\int_{-\\infty}^{\\infty} p(y_t | x_t) p(x_t | y_{1:t-1}) \\; \\dx_{t}\n\\end{equation}\n\nComputing \\eqref{eq:MargLikelihood} isn't however strictly needed as it does not depend on \\(x_t\\) and\nserves as a normalising constant in \\eqref{eq:PosteriorPdf}. Depending on use-case the normalising\nconstant may not be needed at all or may be computed alternatively using the fact that \\(p(x_t | y_{1:y})\\)\nintegrates to \\(1\\).\n\nWe have shown that so called \\emph{optimal Bayesian solution}\\cite{AruMasGor:02} can be easily\nanalytically inferred using only \\emph{chain rule for {\\pdfs}}, \\emph{marginalization} and\n\\emph{Bayes' theorem}. (equations \\eqref{eq:PriorPdf}, \\eqref{eq:PosteriorPdf} and\n\\eqref{eq:MargLikelihood} forming the main steps of the solution) On the other hand, using this\nmethod directly in practice proves difficult because at least one parametric multidimensional\nintegration has to be performed (in \\eqref{eq:PriorPdf}), which is (in its general form) hardly\ntractable for greater than small state vector dimensions.\n\nThis is a motivation for various simplifications and approximations among which we have chosen\na Kalman filter described in the next section and a family of particle filters described later.\n\n\\section{Kalman Filter}\n\nThe Kalman filter\\footnote{first presented by Rudolf Emil Kalman in 1960.} poses additional set of strong\nassumptions on modelled dynamic system, but greatly\nsimplifies the optimal Bayesian solution \\eqref{eq:PriorPdf}, \\eqref{eq:PosteriorPdf} into a\nsequence of algebraic operations with matrices. On the other hand, when these requirements can be\nfulfilled, there is no better estimator in the Bayesian point of view because the Kalman filter computes\n\\(p(x_t | y_{1:t})\\) \\emph{exactly.}\\footnote{not accounting for numeric errors that arise in\npractical implementations.}\n\nAssumptions additionally posed on system by the the Kalman filter are:\n\\begin{enumerate}\n\t\\item \\(f_t\\) in the process model \\eqref{eq:DynSysFt} is a linear function of \\(x_t\\) and\n\t\\(v_t\\).\n\t\\item \\(v_t \\sim \\mathcal{N}(0, Q_t)\\) meaning that process noise \\(v_t\\) is normally\n\tdistributed with zero mean\\footnote{zero mean assumption is not strictly needed, it is however\n\tcommon in many implementations.} and with known covariance matrix \\(Q_t\\).\n\t\\item \\(h_t\\) in the observation model \\eqref{eq:DynSysHt} is a linear function of \\(x_t\\) and\n\t\\(w_t\\).\n\t\\item \\(w_t \\sim \\mathcal{N}(0, R_t)\\) meaning that observation noise \\(w_t\\) is normally distributed\n\twith zero mean and with known covariance matrix \\(R_t\\).\n\t\\item initial state {\\pdf} is Gaussian.\n\\end{enumerate}\n\nIt can be proved that if the above assumptions hold, \\(p(x_t|y_{1:t})\\) is Gaussian for all\n\\(t > 0\\).~\\cite{Pet:81} Furthermore, given assumptions 1. and 2. the process model\n\\eqref{eq:DynSysFt} can be reformulated as \\eqref{eq:LinSysAt}, where \\(A_t\\) is real-valued matrix\nthat represents \\(f_t\\).\nUsing the same idea and assumptions 3. and 4. the observation model \\eqref{eq:DynSysHt} can be\nexpressed as \\eqref{eq:LinSysCt}, \\(C_t\\) being real-valued matrix representing \\(h_t\\). Another\ncommon requirement used below in the algorithm description is that \\(v_t\\) and \\(w_t\\) are\nstochastically independent.\n\\begin{align}\n\tx_t &= A_t x_{t-1} + \\hat{v}_{t-1} & A_t &\\in \\mathbb{R}^{n,n} \\;\\; n \\in \\mathbb{N} \\label{eq:LinSysAt} \\\\\n\ty_t &= C_t x_t + \\hat{w}_t & C_t &\\in \\mathbb{R}^{j,n} \\;\\; j \\in \\mathbb{N} \\;\\; j \\leq n \\label{eq:LinSysCt}\n\\end{align}\n\nNote that we have marked the noises \\(v_t\\) and \\(w_t\\) as \\(\\hat{v}_t\\) and \\(\\hat{w}_t\\) when they\nare transformed through \\(A_t\\), respectively \\(C_t\\) matrix. Let also \\(\\hat{Q}_t\\) denote the\ncovariance matrix of \\(\\hat{v}_t\\) and \\(\\hat{R}_t\\) denote the covariance matrix of \\(\\hat{w}_t\\)\nin further text.\n\nAt this point we can describe the algorithm of the Kalman filter. As stated above, posterior {\\pdf}\nis Gaussian and thus can be parametrised by mean vector \\(\\mu\\) and covariance matrix \\(P\\). Let us\ndenote posterior mean from previous iteration by \\(\\mu_{t-1|t-1}\\) and associated covariance by\n\\(P_{t-1|t-1}\\) as in \\eqref{eq:KalmanPreAPost}.\n\\begin{equation} \\label{eq:KalmanPreAPost}\n\tp(x_{t-1} | y_{1:t-1}) = \\mathcal{N}(\\mu_{t-1|t-1}, P_{t-1|t-1})\n\\end{equation}\n\nPrior {\\pdf} \\eqref{eq:KalmanAPrior} can then be calculated as follows:~\\cite{AruMasGor:02}\n\\begin{align}\n\tp(x_t | y_{1:t-1}) &= \\mathcal{N}(\\mu_{t|t-1}, P_{t|t-1}) \\label{eq:KalmanAPrior} \\\\\n\t\\mu_{t|t-1} &= A_t \\mu_{t-1|t-1} \\notag \\\\\n\tP_{t|t-1} &= A_t P_{t-1|t-1} A_t^T + \\hat{Q}_{t-1} \\notag\n\\end{align}\n\nBefore introducing posterior {\\pdf} it is useful to establish another Gaussian {\\pdf}\n\\eqref{eq:KalmanEvidence} that is not necessarily needed, but is useful because it represents\nmarginal likelihood \\eqref{eq:MargLikelihood}. % TODO: citation for this!\n\\begin{align}\n\tp(y_t|y_{1:t-1}) &= \\mathcal{N}(\\nu_{t|t-1}, S_{t|t-1}) \\label{eq:KalmanEvidence} \\\\\n\t\\nu_{t|t-1} &= C_t \\mu_{t|t-1} \\notag \\\\\n\tS_{t|t-1} &= C_t P_{t|t-1} C_t^T + \\hat{R}_t \\notag\n\\end{align}\n\nThe update phase of the Kalman filter can be performed by computing so-called \\emph{Kalman gain} matrix\n\\eqref{eq:KalmanGain}, posterior {\\pdf} \\eqref{eq:KalmanAPost} is then derived from prior one\nusing the Kalman gain \\(K_t\\) and observation \\(y_t\\).~\\cite{AruMasGor:02}\n\\begin{align}\n\tK_t &= P_{t|t-1} C_t^T S_{t|t-1}^{-1} \\label{eq:KalmanGain} \\\\[\\parskip]\n\tp(x_t|y_{1:t}) &= \\mathcal{N}(\\mu_{t|t}, P_{t|t}) \\label{eq:KalmanAPost} \\\\\n\t\\mu_{t|t} &= \\mu_{t|t-1} + K_t(y_t - \\nu_{t|t-1}) \\notag \\\\\n\tP_{t|t} &= P_{t|t-1} - K_t C_t P_{t|t-1} \\notag\n\\end{align}\n\nIn all formulas above \\(A^T\\) denotes a transpose of matrix \\(A\\) and \\(A^{-1}\\) denotes inverse\nmatrix to \\(A\\). As can be seen, formulas \\eqref{eq:PriorPdf} and \\eqref{eq:PosteriorPdf} have\nbeen reduced to tractable algebraic operations, computing inverse matrix\\footnote{it can be shown\nthat \\(S_{t|t-1}\\) is positive definite given that \\(C_t\\) is full-ranked,\ntherefore the inverse in \\eqref{eq:KalmanGain} exists.} being the most costly one.\n\nIt should be further noted that the Kalman filter and described algorithm can be easily enhanced to\nadditionally cope with an \\emph{intervention} (or control) vector applied to the system, making it\nsuitable for the theory of decision-making. Numerous generalisations of the Kalman filter exist, for\nexample an \\emph{extended Kalman filter} that relaxes the requirement of the linear system by locally\napproximating a non-linear system with Taylor series. These are out of scope of this\ntext, but provide areas for subsequent consideration.\n\nOn the other hand, the assumption of Gaussian posterior {\\pdf} cannot be easily overcome and for\nsystems that show out non-Gaussian distributions of the state vector another approach have to be\ntaken.~\\cite{AruMasGor:02} One such approach can be a Monte Carlo-based \\emph{particle filter}\npresented in the next section.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\textwidth,keepaspectratio=true]{KF.pdf}\n\t\\caption[Example run of the Kalman filter]{Example run of the Kalman filter. Lines are actual\n\t(hidden) state, dots estimation means of various implementations (all yielding the same values).}\n\t\\label{fig:KF}\n\\end{figure}\n\n\\section{Particle Filter} \\label{sec:ParticleFilter}\n\nParticle filters represent an approximate solution of the problem of the recursive Bayesian\nestimation,\nthus can be considered \\emph{suboptimal} methods. The underlying algorithm described below is most\ncommonly named \\emph{sequential importance sampling (SIS)}. The biggest advantage of the particle filtering\nis that requirements posed on the modelled system are much weaker than those assumed by optimal methods\nsuch as the Kalman filter. Simple form of the particle filter presented in this section (that assumes that\nmodelled system has Markov property) requires only the knowledge of {\\pdf} \\(p(x_t|x_{t-1})\\)\nrepresenting the process model and the knowledge of \\(p(y_t|x_t)\\) representing the observation\nmodel.\\footnote{both {\\pdfs} are generally time-varying and their knowledge for all \\(t\\) is needed,\nbut their representation (parametrised by conditioning variable) is frequently constant in time in\npractical applications.}\n\nThe sequential importance sampling approximates the posterior density by a weighted empirical\n{\\pdf} \\eqref{eq:PFAPost}.\n\\begin{align}\n\tp(x_t | y_{1:t}) \\approx \\sum_{i=1}^N \\omega_t^{(i)} \\delta(x_t - x_t^{(i)}) \\label{eq:PFAPost} \\\\\n\t\\forall i \\in \\mathbb{N} \\;\\; i \\leq N: \\omega_i \\geq 0 \\quad\\quad \\sum_{i=1}^N \\omega_i = 1 \\notag\n\\end{align}\n\nIn \\eqref{eq:PFAPost} \\(x_t^{(i)}\\) denotes value of i-th \\emph{particle}: possible state of the\nsystem at time \\(t\\);\n\\(\\omega_t^{(i)}\\) signifies weight of i-th particle at time \\(t\\): scalar value proportional to\nexpected probability of the system being in state in small neighbourhood of \\(x_t^{(i)}\\);\n\\(N\\) denotes total number of particles\\footnote{\\(N\\) is assumed to be\narbitrary but fixed positive integer for our uses. Variants of the particle filter exist that use\nadaptive number of particles, these are not discussed here.}, a significant tunable parameter\nof the filter.\n\nAs the initial step of the described particle filter, \\(N\\) random particles are sampled\nfrom the initial {\\pdf}\n\\(p(x_0)\\). Let \\(i \\in \\mathbb{N} \\;\\; i \\leq N\\), transition \\(t-1 \\; \\rightarrow \\; t\\) can be\nperformed as follows:\n\\begin{enumerate}\n\t\\item for each \\(i\\) compute \\(x_t^{(i)}\\) by random sampling from conditional {\\pdf}\n\t\t\\(p(x_t|x_{t-1})\\) where \\(x_{t-1}^{(i)}\\) substitutes \\(x_{t-1}\\) in condition. This step\n\t\tcan be interpreted as a simulation of possible system state developments.\n\t\\item for each \\(i\\) compute weight \\(\\omega_t^{(i)}\\) using \\eqref{eq:PFWeightUpdate}\n\t\tby taking observation \\(y_t\\) into account. \\(x_t\\) is substituted by \\(x_t^{(i)}\\) in\n\t\tcondition in \\eqref{eq:PFWeightUpdate}. Simulated system states are confronted with reality\n\t\tthrough observation.\n\t\t\\begin{equation} \\label{eq:PFWeightUpdate}\n\t\t\t\\omega_t^{(i)} = p(y_t | x_t) \\omega_{t-1}^{(i)}\n\t\t\\end{equation}\n\t\\item normalise weights according to \\eqref{eq:PFWeightNormalise} so that approximation of\n\t\tposterior {\\pdf} integrates to one.\n\t\t\\begin{equation} \\label{eq:PFWeightNormalise}\n\t\t\t\\omega_t^{(i)} = \\frac{\\omega_t^{(i)}}{\\sum_{j=1}^N \\omega_t^{(j)}}\n\t\t\\end{equation}\n\\end{enumerate}\n\nRelative computational ease of described algorithm comes with\ncost: first, the particle filter is in principle non-deterministic because of the random sampling in\nstep~1, in other words, the particle filter is essentially a Monte Carlo method; second, appropriate\nnumber of particles \\(N\\) has to be chosen --- too small \\(N\\) can lead to significant approximation\nerror while inadequately large \\(N\\) can make the particle filter infeasibly time-consuming. It can be\nproved that the particle filter converges to true posterior density as \\(N\\) approaches\ninfinity and certain other assumptions hold~\\cite{CriDou:02}, therefore the number of particles\nshould be chosen as a~balance of accuracy and speed.\n\nOnly two operations with {\\pdfs} were needed: sampling from \\(p(x_t|x_{t-1})\\) and evaluating\n\\(p(y_t | x_t)\\) in known point. Sometimes sampling from \\(p(x_t|x_{t-1})\\) is not\nfeasible\\footnote{but can be replaced by evaluation in known point.} and/or better results are\nexpected by taking an observation \\(y_t\\) into account during sampling (step~1). This can be\nachieved by introducing so-called \\emph{proposal density} (sometimes \\emph{importance density})\n\\(q(x_t|x_{t-1}, y_t)\\). Sampling in step~1 then uses \\(q(x_t|x_{t-1}, y_t)\\) instead, where \\(x_{t-1}\\) in\ncondition is substituted by \\(x_{t-1}^{(i)}\\). Weight computation in step~2 have to be replaced with\n\\eqref{eq:PFWeightUpdateProp} that compensates different sampling distribution (every occurrence of\n\\(x_t\\), \\(x_{t-1}\\) in the mentioned formula has to be substituted by \\(x_t^{(i)}\\) and \\(x_{t-1}^{(i)}\\)\nrespectively). See \\cite{AruMasGor:02} for a derivation of these formulas and for a discussion about\nchoosing adequate proposal density.\n\\begin{equation} \\label{eq:PFWeightUpdateProp}\n\t\\omega_t^{(i)} = \\frac{p(y_t|x_t)p(x_t|x_{t-1})}{q(x_t|x_{t-1}, y_t)} \\omega_{t-1}^{(i)}\n\\end{equation}\n\nParticle filters also suffer from a phenomenon known as \\emph{sample impoverishment} or\n\\emph{degeneracy problem}: after a few iterations all but one particles' weight falls close to\nzero.\\footnote{it has been shown that variance of particle weights continually raises as algorithm\nprogresses.~\\cite{AruMasGor:02}}\nOne technique to diminish this is based on careful choice of proposal density (as explained in\n\\cite{AruMasGor:02}), a second one is to add additional \\emph{resample} step to the above\nalgorithm:\n\\begin{enumerate}[resume] % so that enumeration starts with number 4\n\t\\item for each \\(i\\) resample \\(x_t^{(i)}\\) from approximate posterior {\\pdf}\n\t\t\\(\\sum_{i=1}^N \\omega_t^{(i)} \\delta(x_t - x_t^{(i)})\\) and reset all weights to \\(\\frac{1}{N}\\).\n\t\tGiven that sampling is truly random and independent this means that each particle is in\n\t\taverage copied \\(n_i\\) times, where \\(n_i\\) is roughly proportional to particle weight:\n\t\t\\(n_i \\approx \\omega_t^{(i)} N\\). Statistics of posterior {\\pdf} are therefore (roughly and\n\t\ton average) maintained while low-weight particles are eliminated.\n\\end{enumerate}\nStep~4 therefore facilitates avoidance of particles with negligible weight by replacing them with more weighted\nones. Such enhanced algorithm is known as \\emph{sequential importance resampling (SIR)}.\n\nBecause particle resampling is computationally expensive operation, a technique can be used where\nresampling is skipped in some iterations, based on the following idea:\na measurement of degeneracy can be obtained by computing an\napproximate of \\emph{effective sample size} \\(N_{\\text{eff}}\\) at given time \\(t\\) using\n\\eqref{eq:PFNeff}.~\\cite{AruMasGor:02}\n\\begin{equation} \\label{eq:PFNeff}\n\tN_{\\text{eff}} \\approx \\left( \\sum_{i=1}^N \\left( \\omega_t^{(i)} \\right)^2 \\right)^{-1}\n\\end{equation}\nVery small \\(N_{\\text{eff}}\\) compared to \\(N\\) signifies a substantial loss of ``active'' particles,\nwhich is certainly undesirable as it hurts accuracy while leaving computational demands unchanged.\nStep~4 is then performed only when \\(N_{\\text{eff}}\\) falls below certain threshold.\n\nRecursive Bayesian estimation using SIR methods can be applied to a wide range of dynamic systems\n(even to those where more specialised methods fail) and can be tuned with number of particles \\(N\\) and\nproposal density \\(q\\). On the other hand a method specially designed for a given system easily\noutperforms general particle filter in terms of speed and accuracy.\n\n\\section{Marginalized Particle Filter}\n\nMain sources of this section are \\cite{SchGusNor:05} and \\cite{SchKarGus:06}.\n\nThe marginalized particle filter (sometimes \\emph{Rao-Blackwellized particle filter}) is an\nextension to the particle filter that more accurately approximates the optimal Bayesian solution\nprovided that the {\\pdf} representing the process model \\(p(x_t|x_{t-1})\\) can be obtained in\na special form. Suppose that the state vector can be divided into two parts \\(a_t\\) and \\(b_t\\)\n\\eqref{eq:MPFStateVec} and that the process model {\\pdf} can be expressed as a product of two\n{\\pdfs} \\eqref{eq:MPFProcessMod}, where \\(p(a_t|a_{t-1} b_t)\\) is analytically tractable (in general).\nWe present a simple variant of the marginalized particle filter where, given \\(b_t\\), process and\nobservation model of the \\(a_t\\) part are linear with normally-distributed noise. The Kalman filter\ncan be used to estimate \\(a_t\\) part of the state vector in this case.\n\\begin{align}\n\tx_t &= (a_t, b_t) \\label{eq:MPFStateVec} \\\\\n\tp(x_t|x_{t-1}) &= p(a_t, b_t|a_{t-1}, b_{t-1}) = p(a_t|a_{t-1}, b_t) p(b_t | b_{t-1}) \\label{eq:MPFProcessMod}\n\\end{align}\n\nThe posterior {\\pdf} \\eqref{eq:MPFPosterior} can be represented as a product of a weighted empirical\ndistribution and a normal distribution. Each (i-th) particle is thus associated with its Kalman filter\n(representing \\(a_t^{(i)}\\) part) and \\(b_t^{(i)}\\) quantity.\n\\begin{equation} \\label{eq:MPFPosterior}\n\tp(a_t, b_t | y_t) = \\sum_{i=1}^N \\omega_i p(a_t|y_{1:t},b_{1:t}^{(i)}) \\; \\delta(b_t - b_t^{(i)})\n\\end{equation}\n\nIn \\eqref{eq:MPFPosterior} \\(N\\) denotes the total number of particles, \\(\\omega_i\\) denotes weight\nof i-th particle, \\(p(a_t|y_{1:t},b_{1:t}^{(i)})\\) is posterior {\\pdf} of i-th Kalman\nfilter and \\(b_t^{(i)}\\) is a value of the \\(b_t\\) part of i-th particle.\n\nThe algorithm of the described variant of the marginalized particle filter follows, note the\nsimilarities with the ordinary particle filter: at first, generate \\(N\\) \\(b_t\\) random samples from\nthe initial distribution \\(p(b_0)\\). Then the following procedure can be repeated for each measurement\n\\(y_t\\):\n\\begin{enumerate}\n\t\\item for each \\(i\\) compute \\(b_t^{(i)}\\) by random sampling from conditional {\\pdf}\n\t\t\\(p(b_t|b_{t-1})\\) where \\(b_{t-1}^{(i)}\\) substitutes \\(b_{t-1}\\) in condition.\n\t\\item for each \\(i\\) compute the posterior {\\pdf} \\(p(a_t|y_{1:t},b_{1:t}^{(i)})\\) of the i-th\n\t\tKalman filter using \\(y_t\\) and \\(b_t^{(i)}\\).\n\t\\item for each \\(i\\) update weight \\(\\omega_i\\) using the formula \\eqref{eq:MPFWeightUpdate} where\n\t\tmarginal likelihood of the i-th Kalman filter \\eqref{eq:KalmanEvidence} is used.\n\t\t\\begin{equation} \\label{eq:MPFWeightUpdate}\n\t\t\t\\omega_i = p(y_t|y_{1:t-1},b_{1:t}^{(i)}) \\; \\omega_i\n\t\t\\end{equation}\n\t\\item normalise weights (as described in the previous section).\n\t\\item resample particles (as described in the previous section).\n\\end{enumerate}\n\nIt has been demonstrated in various publications that the marginalised particle filter outperforms\nthe ordinary particle filter in both better accuracy and lower computational demands. Where\napplicable, it therefore forms an excellent alternative to traditional particle filtering.\n", "meta": {"hexsha": "4f8baacf897b3bdf2bc08153c53c542c587f42e5", "size": 23095, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chap1-theory.tex", "max_stars_repo_name": "strohel/PyBayes", "max_stars_repo_head_hexsha": "76d3ad12c20e29c5aadb688c4323fb0f1784f8ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 66, "max_stars_repo_stars_event_min_datetime": "2015-01-05T13:36:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-15T18:26:28.000Z", "max_issues_repo_path": "thesis/chap1-theory.tex", "max_issues_repo_name": "strohel/PyBayes", "max_issues_repo_head_hexsha": "76d3ad12c20e29c5aadb688c4323fb0f1784f8ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-02-23T19:45:11.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-21T08:21:52.000Z", "max_forks_repo_path": "thesis/chap1-theory.tex", "max_forks_repo_name": "strohel/PyBayes", "max_forks_repo_head_hexsha": "76d3ad12c20e29c5aadb688c4323fb0f1784f8ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 22, "max_forks_repo_forks_event_min_datetime": "2015-02-11T23:45:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-16T18:53:25.000Z", "avg_line_length": 61.5866666667, "max_line_length": 112, "alphanum_fraction": 0.7333189002, "num_tokens": 6947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127603871312, "lm_q2_score": 0.8418256492357359, "lm_q1q2_score": 0.7188456639035761}}
{"text": "\\section{The Laplace Equation}\r\nWe already encountered Laplace equation $\\Delta^2\\phi=0$ several times.\r\nIt has very wide applications in mathematical physics, applied mathematics and pure mathematics.\r\nIn physics, it often describes some physical systems (e.g. heat flow) that is in stationary state as it does not depend on time.\r\nWe can also see this (possibly with a forcing term) in potential theory.\r\nFor example, Laplace used it to describe gravitational systems.\r\nIt also appears in the study of incompressible fluid flow.\\\\\r\nWe often want to solve Laplace's equation in a domain $D$ subject to boundary conditions.\r\nThe most common ones are the dirichlet conditions where we are given the value of $\\phi$ on $\\partial D$ and the Neumann conditions where we specify $\\underline{\\hat{n}}\\cdot\\nabla\\phi$ on $\\partial D$.\r\n\\subsection{3D Cartesian Coordinates}\r\nIn 3D Cartesian coordinates, the equation becomes\r\n$$\\frac{\\partial^2\\phi}{\\partial x^2}+\\frac{\\partial^2\\phi}{\\partial y^2}+\\frac{\\partial^2\\phi}{\\partial z^2}=0$$\r\nThe seperation of variables $\\phi(x,y,z)=X(x)Y(y)Z(z)$ gives the systems\r\n$$X^{\\prime\\prime}=-\\lambda_lX,Y^{\\prime\\prime}=-\\lambda_mY,Z^{\\prime\\prime}=-\\lambda_nZ=(\\lambda_l+\\lambda_m)Z$$\r\nwhere $\\lambda_l,\\lambda_m$ are seperation constants.\r\nTherefore the general solution arising from this way is\r\n$$\\phi(x,y,z)=\\sum_{l,m,n}a_{l,m,n}X_l(x)Y_m(y)Z_n(z)$$\r\n\\begin{example}[Steady Heat Conduction]\r\n    Consider a semi-infinite rectangular bar $[0,a]\\times [0,b]\\times [0,\\infty]$ as the domain with boundary conditions $\\phi=0$ at $x=0,a$ and $y=0,b$, $\\phi=1$ at $z=0$ and $\\phi\\to 0$ as $z\\to\\infty$.\r\n    We shall try to find the eigenmodes.\r\n    For $X^{\\prime\\prime}=-\\lambda_lX$ with $X(0)=X(a)=0$ we get $\\lambda_l=l^2\\pi^2/a^2$ and $X_l(x)=\\sin(l\\pi x/a)$ for $l=1,2,3,\\ldots$.\r\n    For $Y^{\\prime\\prime}=-\\lambda_mY$ we have $\\lambda_m=m^2\\pi^2/b^2$ and $Y_m(y)=\\sin(m\\pi y/b)$ again for $m=1,2,3,\\ldots$.\r\n    For $Z$, the equation would be\r\n    $$Z^{\\prime\\prime}=-\\lambda_nZ=(\\lambda_l+\\lambda_m)Z=\\pi^2\\left( \\frac{l^2}{a^2}+\\frac{m^2}{b^2} \\right)Z$$\r\n    which has exponential solutions.\r\n    But $Z$ is bounded at infinity, therefore necessarily\r\n    $$Z_n=Z_{l,m}=\\exp\\left( -\\sqrt{\\frac{l^2}{a^2}+\\frac{m^2}{b^2}}\\pi z \\right)$$\r\n    which gives the general solution\r\n    $$\\phi(x,y,z)=\\sum_{l,m}a_{l,m}\\sin\\frac{l\\pi x}{a}\\sin\\frac{m\\pi y}{b}\\exp\\left( -\\sqrt{\\frac{l^2}{a^2}+\\frac{m^2}{b^2}}\\pi z \\right)$$\r\n    Now the condition $\\phi(x,y,0)=1$ gives\r\n    $$a_{l,m}=\\frac{2}{b}\\int_0^b\\frac{2}{a}\\int_0^a\\sin\\frac{l\\pi x}{a}\\sin\\frac{m\\pi y}{b}\\,\\mathrm dx\\mathrm dy=\\frac{16}{\\pi^2lm}$$\r\n    for odd $l,m$ and $0$ if any of them is even.\r\n    Therefore the heat flow solution is\r\n    $$\\phi(x,y,z)=\\sum_{l,m\\text{ odd}}\\frac{16}{\\pi^2lm}\\sin\\frac{l\\pi x}{a}\\sin\\frac{m\\pi y}{b}\\exp\\left( -\\sqrt{\\frac{l^2}{a^2}+\\frac{m^2}{b^2}}\\pi z \\right)$$\r\n    This may look complicated, and yes it is complicated.\r\n    However, for large $l,m$ (and large $z$), the exponential term would be very much close to $0$.\r\n    This allows us to get a very nice approximation by considering just lower order terms.\r\n\\end{example}\r\n\\subsection{2D Plane Polar Coordinates}\r\nIn plane polar, Laplace's equation translates to\r\n$$0=\\nabla^2\\phi=\\frac{1}{r}\\frac{\\partial}{\\partial r}\\left( r\\frac{\\partial\\phi}{\\partial r} \\right)+\\frac{1}{r^2}\\frac{\\partial^2\\phi}{\\partial\\theta^2}$$\r\nAgain we do a seperation of variables $\\phi(r,\\theta)=R(r)\\Theta(\\theta)$ to get\r\n$$\\begin{cases}\r\n    \\Theta^{\\prime\\prime}+\\mu\\Theta=0\\\\\r\n    r(rR^\\prime)^\\prime-\\mu R=0\r\n\\end{cases}$$\r\nwhere $\\mu$ is the seperation constant.\r\nAssuming periodic boundary conditions, then the polar equation yields $\\mu=m^2$ and $\\Theta_m(\\theta)$ is a superposition of $\\cos(m\\theta)$ and $\\sin(m\\theta)$.\r\nSo the radial equation becomes $r(rR^\\prime)^\\prime-m^2R=0$.\r\nFor $m\\neq 0$, trying $R=\\alpha r^\\beta$ shows that $\\beta=\\pm m$ works, so $R_m$ is composed of $r^m$ and $r^{-m}$.\r\nIf $m=0$, $R_0$ is a linear combination of constant and $\\log r$ by just integrating.\r\nSo the general solution is just\r\n\\begin{align*}\r\n    \\phi(r,\\theta)&=\\frac{a_0}{2}+c_0\\log r\\\\\r\n    &\\quad+\\sum_{m=1}^\\infty(a_m\\cos(m\\theta)+b_n\\sin(m\\theta))r^m\\\\\r\n    &\\quad+\\sum_{m=1}^\\infty(c_m\\cos(m\\theta)+d_m\\sin(m\\theta))r^{-m}\r\n\\end{align*}\r\nFor constants $a_m,b_m,c_m,d_m$.\r\n\\begin{example}[Soap Film on a Unit Disk]\r\n    We want to solve Laplace's equation on the unit disk, where the boundary condition is given a distorted circular wire $\\phi(1,\\theta)=f(\\theta)$.\r\n    Of course we want our solution to be continuous in the inside of the disk, in particular at $0$, therefore $c_m=d_m=0$ for all $m$.\r\n    Therefore we just got\r\n    $$\\phi(r,\\theta)=\\frac{a_0}{2}+\\sum_{m=1}^\\infty(a_m\\cos(m\\theta)+b_m\\sin(m\\theta))r^m$$\r\n    left.\r\n    But then $f(\\theta)=\\phi(1,\\theta)$ gives a Fourier series (again!), so\r\n    $$a_m=\\frac{1}{\\pi}\\int_0^{2\\pi}f(\\theta)\\cos(m\\theta)\\,\\mathrm d\\theta,b_m=\\frac{1}{\\pi}\\int_0^{2\\pi}f(\\theta)\\sin(m\\theta)\\,\\mathrm d\\theta$$\r\n    For a nontrivial distortion, the term $r^m$ then tells us that the high harmonics are concentrated near the edge of the wire.\r\n\\end{example}\r\n\\subsection{3D Cylindrical Polar Coordinates}\r\nHere Laplace's equation become\r\n$$0=\\nabla^2\\phi=\\frac{1}{r}\\frac{\\partial}{\\partial r}\\left( r\\frac{\\partial\\phi}{\\partial r} \\right)+\\frac{1}{r^2}\\frac{\\partial^2\\phi}{\\partial\\theta^2}+\\frac{\\partial^2\\phi}{\\partial z^2}$$\r\nSeperation of variables $\\phi(r,\\theta,z)=R(r)\\Theta(\\theta)Z(z)$ gives\r\n$$\\begin{cases}\r\n    \\Theta^{\\prime\\prime}=-\\mu\\Theta\\\\\r\n    Z^{\\prime\\prime}=\\lambda Z\\\\\r\n    r(rR^\\prime)^\\prime+(\\lambda r^2-\\mu)R=0\r\n\\end{cases}$$\r\nwhere $\\mu,\\lambda$ are the seperation constants.\r\nFor the polar equation, periodic boundary conditions give $\\mu_m=m^2$ and $\\Theta_m(\\theta)$ is a superposition of $\\sin(m\\theta)$ and $\\cos(m\\theta)$.\r\nThe radial equation is Bessel's equation (surprise?) with eigenfunctions $R_{mn}=J_m(j_{mn}r/a)$ under boundary condition $R(a)=0$ and the requirement of it not being singular (so we can exclude the Neumann functions).\r\nThe $Z$ equation then becomes $Z^{\\prime\\prime}=kZ$ where $k=j_{mn}/a$ which gives $Z=e^{-kz}$ (the $e^{kz}$ solution is eliminated by the boundary condition $Z\\to 0$ as $z\\to\\infty$).\r\nSo the general solution is\r\n$$\\phi(r,\\theta,z)=\\sum_{m=0}^\\infty\\sum_{n=1}^\\infty(a_{mn}\\cos(m\\theta)+b_{mn}\\sin(m\\theta))J_m(j_{mn}r/a)\\exp(-j_{mn}r/a)$$\r\n\\begin{example}\r\n    The boundary condition $\\phi=0$ at $r=a$, $\\phi=T_0$ at $z=0$ and $\\phi\\to 0$ as $z\\to\\infty$ gives the solution\r\n    $$\\phi(r,\\theta,z)=\\sum_{n=1}^\\infty\\frac{2T_0}{j_{0n}J_1(j_{0n})}J_0(j_{0n}r/a)\\exp(-j_{0n}z/a)$$\r\n\\end{example}\r\n\\subsection{3D Spherical Polar Coordinates}\r\nRecall that the spherical polar coordinate transforms from Cartesian coordinates by\r\n$$x=r\\sin\\theta\\cos\\phi,y=r\\sin\\theta\\sin\\phi,z=r\\cos\\theta$$\r\nfor $r\\in\\mathbb R_{\\ge 0},\\theta\\in [0,\\pi],\\phi\\in[0,2\\pi]$ where we have $\\mathrm dV=r^2\\sin\\theta\\,\\mathrm dr\\mathrm d\\theta\\mathrm d\\phi$.\r\nLaplace's equation transforms into\r\n$$0=\\nabla^2\\Phi=\\frac{1}{r^2}\\frac{\\partial}{\\partial r}\\left( r^2\\frac{\\partial\\Phi}{\\partial r} \\right)+\\frac{1}{r^2\\sin\\theta}\\frac{\\partial}{\\partial\\theta}\\left( \\sin\\theta\\frac{\\partial\\Phi}{\\partial\\theta} \\right)+\\frac{1}{r^2\\sin^2\\theta}\\frac{\\partial^2\\Phi}{\\partial\\phi^2}$$\r\nWe only consider the axis-symmetric case where $\\partial\\Phi/\\partial\\phi=0$.\r\nAgain seperate the variables $\\Phi(r,\\theta,\\phi)=R(r)\\Theta(\\theta)$ gives\r\n$$\\begin{cases}\r\n    ((\\sin\\theta)\\Theta^\\prime)^\\prime+\\lambda(\\sin\\theta)\\Theta=0\\\\\r\n    (r^2R^\\prime)^\\prime-\\lambda R=0\r\n\\end{cases}$$\r\nwhere $\\lambda$ is the seperation constant.\r\nThe substitution $x=\\cos\\theta$ transforms the polar equation into\r\n$$\\frac{\\mathrm d}{\\mathrm dx}\\left( (1-x^2)\\frac{\\mathrm d\\Theta}{\\mathrm dx} \\right)+\\lambda\\Theta=0$$\r\nwhich is exactly Legendre's equation.\r\nSo we obtain the eigenvalues $\\lambda_l=l(l+1)$ with eigenfunctions $\\Theta_l(\\theta)=P_l(x)=P_l(\\cos\\theta)$ where $P_l$ is the $l^{th}$ Legendre polynomial.\r\nPutting it into the radial equation gives $(r^2R^\\prime)^\\prime-l(l+1)R=0$, which gives (by educated guess) the solution $R_l$ being a superposition of $r^l$ and $r^{-l-1}$.\r\nThe general axis-symmetric solution is then\r\n$$\\Phi=\\sum_{l=0}^\\infty(a_lr^l+b_lr^{-l-1})P_l(\\cos\\theta)$$\r\nwhere $a_l,b_l$ can be determined by boundary conditions.\r\n\\begin{example}\r\n    Consider the boundary condition $\\Phi(1,\\theta,\\phi)=f(\\theta)$ for some $f$.\r\n    Regularity implies $b_l=0$ for any $l$.\r\n    So we have\r\n    $$f(\\theta)=\\sum_{l=0}^\\infty a_lP_l(\\cos\\theta)\\implies F(x)=\\sum_{l=0}^\\infty a_lP_l(x)$$\r\n    with $f(\\theta)=F(\\cos\\theta)$.\r\n    This gives\r\n    $$a_l=\\frac{2l+1}{2}\\int_{-1}^1F(x)P_l(x)\\,\\mathrm dx$$\r\n    in the special case where $f(\\theta)=\\sin^2\\theta$ we have $\\Phi=2(1-P_2(\\cos\\theta)r^2)/3$.\r\n\\end{example}\r\nConsider a charge on $z$-axis at $\\underline{r}_0=(0,0,1)$ and the potential at $P$ is defined by\r\n$$\\Phi(\\underline{r})=\\frac{1}{|\\underline{r}-\\underline{r}_0|}=\\frac{1}{\\sqrt{r^2-2r\\cos\\theta+1}}=\\frac{1}{\\sqrt{r^2-2rx+1}}$$\r\nwhere $x=\\cos\\theta$.\r\nIt is easy to see that $\\Phi$ satisfies $\\nabla^2\\Phi=0$ in $\\mathbb R^3\\setminus\\{\\underline{r}_0\\}$.\r\nTherefore there is some $a_l$ such that\r\n$$\\frac{1}{\\sqrt{r^2-2rx+1}}=\\sum_{l=0}^\\infty a_lP_l(x)r^l$$\r\nWe have $P_l(1)=1$ at $x=1$, therefore plugging in $x=1$ gives $a_l=1$ for any $l$, therefore\r\n$$\\frac{1}{\\sqrt{r^2-2rx+1}}=\\sum_{l=0}^\\infty P_l(x)r^l$$\r\nis the generating function of the Legendre polynomials.\r\n\\begin{example}[Electric Multipoles]\r\n    Consider the case where we put charges along $z$-axis at $z=\\pm a,0$ viewed from a large distance $r>>a$ with $\\Phi\\to 0$ as $r\\to\\infty$.\r\n    Therefore $a_n=0$ for all $n$.\r\n    When $l=0$, we just get a point charge and thus $\\Phi\\propto 1/r$\r\n    This is called the monopole field of the point charge $q$.\r\n    When $l=1$, we get the dipole (i.e. opposite charges sitting opposite each other) $\\Phi\\propto(\\cos\\theta)/r^2$ for two opposite charges.\r\n    When $l=2$, it is like putting a charge $2q$ at the origin and $-q$ at opposite position across the origin, in which case $\\Phi\\propto(3\\cos^2\\theta-1)/(2r^3)$ gives the quadruple field.\r\n\\end{example}", "meta": {"hexsha": "3f5e23504f2b2349e551e0c833603ee89cdef35e", "size": 10292, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/laplace.tex", "max_stars_repo_name": "david-bai-notes/IB-Methods", "max_stars_repo_head_hexsha": "b60135106d09d1e24d2f7b9c7e3eee1ca69f6907", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/laplace.tex", "max_issues_repo_name": "david-bai-notes/IB-Methods", "max_issues_repo_head_hexsha": "b60135106d09d1e24d2f7b9c7e3eee1ca69f6907", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/laplace.tex", "max_forks_repo_name": "david-bai-notes/IB-Methods", "max_forks_repo_head_hexsha": "b60135106d09d1e24d2f7b9c7e3eee1ca69f6907", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 76.237037037, "max_line_length": 287, "alphanum_fraction": 0.6709094442, "num_tokens": 3641, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7188456606444368}}
{"text": "\\subsection{The Rayleigh-Ritz Method}\n\nThe method presented in this subsection is not really an\nstep forward from the Power Method, but rather a parallel development\n(both will be merged in the Lanczos Algorithm of further\nsubsections). It is actually an auxiliary tool that many eigenproblem\nsolvers need; not necessarily for symmetric matrices (although we\nstill assume that, it order to maintain our desired scope). \\\\ \n\nSuppose that, in order to find the eigenpairs \\footnote {An eigenpair\n  is the tuple $(\\lambda_i,\\vec{v})$ of an eigenvalue and its\n  corresponding eigenvector} of a given matrix $A$,\nwe generate a sequence of matrices ${ W_k }$ which contain\nprogressively better approximations of such eigenpairs. A common\nproblem for any procedure that goes that way, is how to ``extract''\nthe actual eigenvectors from such subspace (the eigenvalues are the\nsame, so those do not require further calculations). The\nRayleigh-Ritz \\footnote{Leissa argues that the method should not\n  really be attributed to Rayleigh but only to Ritz, (see\n  \\cite{leissa05}).} method addresses precisely this common need. \\\\\n\nBefore providing the pseudocode, let us explain a bit better what we\nmean by having ``calculated subspaces'' $W_k$; as that is a rather\nvague expression (though is quite common in the literature). What we\nreally mean, is that we have a \\emph{characterization} of the\nsubspace; which is nothing more than a basis for it. The vectors of\nsuch basis are arranged as columns of the matrix $W_k$, and then, we\nare basically asking for the eigen decomposition of that matrix. \\\\\n\nDoes not the above sound a bit circular? We start with the generic\nproblem of finding eigenvalues and eigenvectors of symmetric matrix\n$A$; then we calculate through an iterative process another matrix\n$W_k$, which contains the basis of a subspace that we know has good\napproximations to the eigenpairs of our original matrix $A$. Then, we\nproceed to solve the eigenproblem for that new matrix $W_k$ ... looks\nlike we finish right where we began! Of course that, though not\nmentioned always in literature, the intuitive idea is that the new\nmatrix $W_k$ is a less generic than $A$. It is expected to have certain\nqualities that make the solution of its eigenproblem an easier task\n(compared to solving that for original matrix $A$).  \\\\\n\nHaving clarified a bit the main idea of subspace eigenproblem solvers,\nlet us continue to list the pseudocode for the Rayleigh-Ritz Method; which\noffers a way to ``extract'' the eigenvectors of original matrix $A$,\nout of the approximation matrix $W_k$. We based our procedure in\n\\cite{jia01}: \n\n\\begin{algorithm}\n  \\label{alg:ritz}\n  \\caption{The Rayleigh-Ritz Method}\n%\n  \\setstretch{1.5}\n  \\SetKwInOut{Input}{Input}\n  \\SetKwInOut{Output}{Output}\n  \\DontPrintSemicolon\n%\n    \\Input{Approximation subspace matrix $W_k$, symmetric matrix $A$}\n%\n    \\Output{Set of desired (approximated) eigenpairs}\n%\n    $B \\gets \\trans{W} A W $ \\;\n%\n    \\For {each desired eigenpair $(\\lambda_i,\\vec{v_i})$ of $A$}\n    {\n%\n      Solve eigen equation $B\\vec{x_i} = \\tilde{\\lambda_i} \\vec{x_i}$ (where\n      $\\tilde{\\lambda_i} \\simeq \\lambda_i$) \\;\n%\n      $(\\tilde{\\lambda_i}, \\avec{v_i}) \\gets (\\lambda_i, W\\vec{x_i})$,\n      where $\\avec{v_i} \\approx \\vec{v_i}$ \\;\n    }\n%\n    return $\\{(\\tilde{\\lambda_1},\\avec{v_1}),(\\tilde{\\lambda_2},\\avec{v_2}),\\cdots,\\}$ \\;\n\\end{algorithm}\n\nIf $W_k$ was the orthogonal matrix with the eigenvectors of $A$, then\nmatrix $B$ would be diagonal (containing the eigenvalues). As $W_k$ is\nrather an approximation to such matrix, is usually the case that is\nsomething close to a diagonal (like a tridiagonal or bidiagonal); from\nthere comes the fact that calculating its eigenpairs, is much easier\nthan for original matrix $A$. \\\\\n\nProbably the less intuitive step from the algorithm is the assignment\n$\\avec{v_i} = W\\vec{v_i}$; but is not hard to prove its validity: \n\n\\begin{align*}\n\\setstretch{10}\n& &B\\vec{x_i} = \\tilde{\\lambda_i} \\vec{x_i} \\\\\\\\\n& \\iff &(\\trans{W} A W)\\vec{x_i} = \\tilde{\\lambda_i} \\vec{x_i} \\\\\\\\\n& \\iff &\\trans{W} A (W\\vec{x_i}) = \\tilde{\\lambda_i} \\vec{x_i} \\\\\\\\\n& \\iff &A (W\\vec{x_i}) = \\tilde{\\lambda_i} (W \\vec{x_i}) \\\\\\\\\n& \\therefore & W\\vec{x_i} \\text{ is an (approx.) eigenvector of $A$} \\xqed\n\\end{align*}\n\\hfill\n\nThe vector \\vec{v_i} is called a Ritz vector, and we will refer to it\nin such a way when we review the complete Lanczos algorithm.\\\\\n\nFor further details of convergence or error analysis, please refer to\nJian \\cite{jia01}. \n\n", "meta": {"hexsha": "593432dd8baa065742274aa70c6753c76f8d64ac", "size": 4515, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-lanczos-serial-ritz.tex", "max_stars_repo_name": "rzavalet/svd-lsi-project-master", "max_stars_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "svd-lanczos-serial-ritz.tex", "max_issues_repo_name": "rzavalet/svd-lsi-project-master", "max_issues_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "svd-lanczos-serial-ritz.tex", "max_forks_repo_name": "rzavalet/svd-lsi-project-master", "max_forks_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.2647058824, "max_line_length": 89, "alphanum_fraction": 0.7337763012, "num_tokens": 1273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7188456377009893}}
{"text": "\\subsection{Projection of monomer orbitals on dimer orbitals (DIPRO)}\n\\label{sec:dipro}\nAn approach for the determination of the transfer integral that can be used for any single-particle electronic structure method (Hartree-Fock, DFT, or semiempirical methods) is based on the projection of monomer orbitals on a manifold of explicitly calculated dimer orbitals. This dimer projection (DIPRO) technique including an assessment of computational parameters such as the basis set, exchange-correlation functionals, and convergence criteria is presented in detail in ref.~\\cite{baumeier_density-functional_2010}. A brief summary of the concept is given below.\n\nWe start from an effective Hamiltonian~\\footnote{we use following notations: $a$ - number, $\\vctr{a}$ - vector, $\\matr{A}$ - matrix, $\\oper{A}$ - operator}\n%\n\\begin{equation}\n  \\oper{H}^\\text{eff} = \\sum_i \\epsilon_i \\oper{a}_i^\\dagger \\oper{a}_i + \\sum_{j \\neq i} J_{ij} \\oper{a}_i^\\dagger \\oper{a}_j + c.c.\n  \\label{equ:dipro_eq1}\n\\end{equation}\n%\nwhere $\\oper{a}_i^\\dagger$ and $\\oper{a}_i$ are the creation and annihilation operators for a charge carrier located at the molecular site $i$.\nThe electron site energy is given by $\\epsilon_i$, while $J_{ij}$  is the transfer integral between two sites $i$ and $j$. We label their frontier orbitals (HOMO for hole transfer, LUMO for electron transfer) $\\phi_i$ and $\\phi_j$, respectively. Assuming that the frontier orbitals of a dimer (adiabatic energy surfaces) result exclusively from the interaction of the frontier orbitals of monomers, and consequently expand them in terms of $\\phi_i$ and $\\phi_j$. The expansion coefficients, $\\vctr{C}$, can be determined by solving the secular equation\n%\n\\begin{equation}\n  (\\matr{H} - E \\matr{S})\\vctr{C} = 0\n  \\label{equ:dipro_eq2}\n\\end{equation}\n%\nwhere $\\matr{H}$ and $\\matr{S}$ are the Hamiltonian and overlap matrices of the system, respectively. \n%\n%Since it is easier to work in matrix form, the following\n%equation also holds (equation (\\ref{eq:dipro_eq2}) in matrix form):\n%\n%\\begin{equation}\n% \\matr{H}\\matr{U} = \\matr{S}\\matr{U}\\matr{E}\n%  \\label{eq:dipro_eq3}\n% \\end{equation}\n%\nThese matrices can be written explicitly as\n%\n\\begin{equation}\n% \\begin{aligned}\n  \\matr{H} = \n  \\begin{pmatrix}\n    e_i    &  H_{ij} \\\\\n    H_{ij}^* &  e_j  \n  \\end{pmatrix} \\hspace{2cm}\n  \\matr{S} = \n  \\begin{pmatrix}\n    1    &  S_{ij} \\\\\n    S_{ij}^* &  1  \n  \\end{pmatrix}\n%  \\end{aligned}\n  \\label{equ:dipro_eq3}\n\\end{equation}\n%\nwith \n%\n\\begin{equation}\n \\begin{aligned}\n  e_i &= \\Bra{\\phi_i}\\oper{H} \\Ket{\\phi_i} \\hspace{2cm}  H_{ij} = \\Bra{\\phi_i}\\oper{H} \\Ket{\\phi_j}\\\\\n  e_j &= \\Bra{\\phi_j}\\oper{H} \\Ket{\\phi_j} \\hspace{2cm}  S_{ij} = \\Bra{\\phi_j} \\phi_j\\rangle %S \n \\end{aligned}\n  \\label{equ:dipro_eq4}\n\\end{equation}\nThe matrix elements $e_{i(j)}$, $H_{ij}$, and $S_{ij}$ entering \\equ{dipro_eq3} can be calculated via projections on the dimer orbitals (eigenfunctions of $\\hat{H}$) $\\left\\{\\Ket{\\phi^\\text{D}_n}\\right\\}$ by inserting $\\oper{1} = \\sum_n \\Ket{\\phi^\\text{D}_n}\\Bra{\\phi^\\text{D}_n}$ twice. We exemplify this explicitly for $H_{ij}$ in the following\n%\n\\begin{equation}\n  H_{ij} = \\sum_{nm}{\\Braket{\\phi_i|\\phi^\\text{D}_n} \\Bra{\\phi^{D}_n}\\hat{H}\\Ket{\\phi^\\text{D}_m}\\Braket{\\phi^\\text{D}_m|\\phi_j}} .\n  \\label{eq:dipro_eq16}\n\\end{equation}\n%\nThe Hamiltonian is diagonal in its eigenfunctions, $\\Bra{\\phi^\\text{D}_n}\\oper{H}\\Ket{\\phi^\\text{D}_m} = E_n \\delta_{nm}$. Collecting the projections of the frontier orbitals  $\\Ket{\\phi_{i(j)}}$ on the $n$-th dimer state $\\left(\\vctr{V}_{(i)}\\right)_n= \\Braket{\\phi_i|\\phi^\\text{D}_n}$ and $\\left(\\vctr{V}_{(j)}\\right)_n=\\Braket{\\phi_j|\\phi^\\text{D}_n}$ respectively, into vectors we obtain\n\n\\begin{equation}\n   H_{ij} = \\vctr{V}_{(i)} \\matr{E}   \\vctr{V}_{(j)}^\\dagger .\n  \\label{eq:dipro_eq17}\n\\end{equation}\n%\nWhat is left to do is determine these projections $\\vctr{V}_{(k)}$. In all practical calculations the molecular orbitals are expanded in basis sets of either plane waves or of localized atomic orbitals $\\Ket{\\varphi_\\alpha}$. We will first consider the case that the calculations for\nthe monomers are performed using a counterpoise basis set that is commonly used to deal with the basis set superposition error (BSSE). The basis set of atom-centered orbitals of a monomer is extended to the one of the dimer by adding the respective atomic orbitals at virtual coordinates of the second monomer. We can then write the respective expansions as\n\n\\begin{equation}\n %\\begin{aligned}\n  \\Ket{\\phi_{k}} = \\sum_{\\alpha} \\lambda^{(k)}_\\alpha \\Ket{\\varphi_\\alpha} \\hspace{1cm}\\text{and}\\hspace{1cm}\n  \\Ket{\\phi^\\text{D}_n} = \\sum_{\\alpha} D^{(n)}_\\alpha \\Ket{\\varphi_\\alpha}\n  \\label{eq:dipro_eq18}\n\\end{equation}\n%\nwhere $k=i,j$. The projections can then be determined within this common basis set as\n\n \\begin{equation}\n  \\begin{aligned}\n     \\left(\\vctr{V}_k\\right)_n=\\Braket{\\phi_k|\\phi^\\text{D}_n} = \\sum_{\\alpha} \\lambda^{(k)}_{\\alpha} \\Bra{\\alpha} \\sum_{\\beta} D^{(n)}_{\\beta} \\Ket{\\beta} = \n     \\vctr{\\boldsymbol{\\lambda}}_{(k)}^\\dagger \\matr{\\mathcal{S}} \\vctr{D}_{(n)} \n%     %\\\\\n% %    \\Braket{B|i} = \\sum_{\\alpha} B_{\\alpha} \\Bra{\\alpha}\n% %    \\sum_{\\beta} D^{(i)}_{\\beta} \\Ket{\\beta} = \n% %    \\vctr{B}^\\dagger \\matr{S} \\vctr{D}^{(i)} \\\\\n  \\end{aligned}\n   \\label{eq:dipro_eq19}\n \\end{equation}\nwhere $\\matr{\\mathcal{S}}$ is the overlap matrix of the atomic basis functions. This allows us to finally write the elements of the Hamiltonian and overlap matrices in \\equ{dipro_eq3} as:\n\n \\begin{equation}\n  \\begin{aligned}\n     H_{ij} &= \\vctr{\\boldsymbol{\\lambda}}_{(i)}^\\dagger \\matr{\\mathcal{S}} \\matr{D} \\matr{E} \\matr{D}^\\dagger \\matr{\\mathcal{S}}^\\dagger \\vctr{\\boldsymbol{\\lambda}}_{(j)}  \\\\\n     S_{ij} &= \\vctr{\\boldsymbol{\\lambda}}_{(i)}^\\dagger \\matr{\\mathcal{S}} \\matr{D}  \\matr{D}^\\dagger \\matr{\\mathcal{S}}^\\dagger \\vctr{\\boldsymbol{\\lambda}}_{(j)} \n  \\end{aligned}\n   \\label{eq:dipro_eq20}\n \\end{equation}\n%\nSince the two monomer frontier orbitals that form the basis of this expansion are not orthogonal in general ($\\matr{S} \\neq \\matr{1}$), it is necessary to transform \\equ{dipro_eq2} into a standard eigenvalue problem of the form\n%\n\\begin{equation}\n  \\matr{H}^{\\mathrm{eff}} \\vctr{C}^{\\mathrm{eff}} =   E \\vctr{C}^{\\mathrm{eff}} \n  \\label{eq:dipro_eq7}\n\\end{equation}\n%\nto make it correspond to \\equ{dipro_eq1}. According to L\\\"owdin such a transformation can be achieved by\n%\n\\begin{equation}\n  \\matr{H^\\mathrm{eff}} = \\matr{S}^{\\left. {-1} \\middle/ {2} \\right.}\n  \\matr{H}\\matr{S}^{\\left. {-1} \\middle/ {2} \\right.}.\n  \\label{eq:dipro_eq9}\n\\end{equation}\n%\nThis then yields an effective Hamiltonian matrix in an orthogonal basis, and its entries can directly be identified with the site energies $\\epsilon_i$ and transfer integrals $J_{ij}$:\n%\n\\begin{equation}\n \\begin{aligned}\n  \\matr{H}^{\\mathrm{eff}} &= \n    \\begin{pmatrix}\n      e_i^{\\mathrm{eff}}    &  H_{ij}^\\mathrm{eff} \\\\\n      H_{ij}^{*,\\mathrm{eff}}   &  e_j^\\mathrm{eff}  \n    \\end{pmatrix} =\n    \\begin{pmatrix}\n      \\epsilon_i    &  J_{ij} \\\\\n      J_{ij}^*      &  \\epsilon_j  \n    \\end{pmatrix} \n \\end{aligned}\n  \\label{eq:dipro_eq11}\n\\end{equation}\n\n \\begin{figure}[htb]\n     \\center\n     \\includegraphics[width=\\linewidth]{fig/coupling}\n     \\caption{Schematics of the DIPRO method. (a) General workflow of the projection technique. (b) Strategy of the efficient noCP+noSCF implementation, in which the monomer calculations are performed independently form the dimer configurations (noCP), using the \\calc{edft} \\calculator. The dimer Hamiltonian is subsequently constructed based on an initial guess formed from monomer orbitals and only diagonalized once (noSCF) before the transfer integral is calculated by projection. This second step is performed by the \\calc{idft} \\calculator. }\n     \\label{fig:dipro_scheme}\n \\end{figure}\n\n", "meta": {"hexsha": "36c2ab98275957c5a7db13ce0e824f281db9c4e3", "size": 7853, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/theory/dipro.tex", "max_stars_repo_name": "mbarbry/ctp", "max_stars_repo_head_hexsha": "8461ba9d012c7e171a05e0b114b59d0523fc9a56", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "manual/theory/dipro.tex", "max_issues_repo_name": "mbarbry/ctp", "max_issues_repo_head_hexsha": "8461ba9d012c7e171a05e0b114b59d0523fc9a56", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "manual/theory/dipro.tex", "max_forks_repo_name": "mbarbry/ctp", "max_forks_repo_head_hexsha": "8461ba9d012c7e171a05e0b114b59d0523fc9a56", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.9160839161, "max_line_length": 568, "alphanum_fraction": 0.6928562333, "num_tokens": 2649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266014, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.7187909724708513}}
{"text": "\\section{Green functions}\nUp to now we have left the boundary conditions that $G$ has to satisfy\nunspecified.\n\nWhich boundary conditions we choose depends on convenience.\n\\begin{align}\n    \\phi(\\vec{x})\n    &=\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\int_V \\rho\\left( \\vec{x}' \\right) G\\left( \\vec{x}', \\vec{x} \\right)\\,\n    d^3\\vec{x}'\\\\\\nonumber\n    &\\qquad\n    + \\frac{1}{4\\pi}\n    \\oint_S\\left[ \n    G\\left( \\vec{x}', \\vec{x} \\right)\n    \\left( \n    \\vec{\\nabla}' \\phi\\left( \\vec{x}' \\right)\n    \\cdot \\hat{n}'\n    \\right)\n    -\n    \\phi\\left( \\vec{x}' \\right)\n    \\left( \n    \\vec{\\nabla}' G\\left( \\vec{x}', \\vec{x} \\right)\n    \\right)\n    \\right]\\, dS'\n\\end{align}\n\nThe simplest consistent choice is\n\\begin{align}\n    \\vec{\\nabla}' G_N \\left( \\vec{x}', \\vec{x} \\right)\n    &=\n    -\\frac{4\\pi}{S}\n\\end{align}\nwhere $S$ is the teal area of the boundary surface.\n\\begin{align}\n    \\phi\\left( \\vec{x} \\right)\n    &=\n    \\langle \\phi\\rangle_S\n    +\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\int_V \\rho\\left( \\vec{x}' \\right)\n    G_N\\left( \\vec{x}', \\vec{x} \\right)\n    \\, d^3 \\vec{x}'\n    +\n    \\frac{1}{4\\pi}\n    \\oint_S G_N\\left( \\vec{x}', \\vec{x} \\right)\n    \\left( \n    \\vec{\\nabla}' \\phi\\left( \\vec{x}' \\right)\n    \\cdot\n    \\hat{n}'\n    \\right)\\, dS'\n\\end{align}\nwhere $\\langle \\phi\\rangle_S$\nis the average of $\\phi$ over the bounding surface.\n\nFinding the Green function is the hard part.\nEverything else is easy.\n\n\\subsection{Example: Two hemispheres}\nLet's do an example.\n\nConsider a sphere made up of two conducting hemispheres that are kept at\ndifferent potentials.\nAnd the centre of the sphere is the origin.\nThe upper sphere is at potential $+V$ and the lower potential is at potential\n$-V$.\n\nThe problem is to find the potential due to the sphere everywhere in space.\nA very standard problem.\nIt doesn't look very much like a Greens function problem.\nWhy are we able to solve this?\nBecause using them method of images,\nwe found the Green's function for a grounded conducting sphere.\n\nRecall that using them method of images,\nwe found the potential due to a point charge near a conducting sphere,\nand from just that we can obtain the Greens function.\n\\begin{align}\n    G_0\\left( \\vec{x}', \\vec{x} \\right)\n    &=\n    \\frac{1}{\\left| \\vec{x} - \\vec{x}'\\right|}\n    -\n    \\frac{a}{r'\\left|\n    \\vec{x}\n    -\n    \\frac{a^2}{r'^2}\\vec{x}'\n    \\right|}\n\\end{align}\nHere is the magic.\nWe didn't solve this for an arbitrary potential,\nwe solved it for a conducting sphere grounded.\nBut that is the boundary condition for the Dirichlet Green function,\nwhich is chosen so that $G=0$ on the surface.\nSo it happens that when we solve this problem for the grounded conducting\nsphere,\nwe were actually finding the Dirichlet Greens function.\nZero potential on the bounded surface,\nso it's grounded.\nThat is exactly the Greens function.\nWhat we were solving the problem,\nwhat we were really solving is the Dirichlet Greens function.\nSo we know the answer.\nThat's the Dirichlet greens function.\nNow you might say what does that have to do with  completely different\nproblem where the potential nd boundary have nothing to do with the grounded\nsphere we originally solved.\nThat's the magic of the Greens function method.\n\nOnce you know the Greens function of the Dirichlet function,\nthen for any Dirichlet boundary function of the potential,\nthe answer is given in terms of these integral.s\n\nRecall that\n\\begin{align}\n    \\phi\\left( \\vec{x} \\right)\n    &=\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\int_V \n    \\rho\\left( \\vec{x}' \\right)\n    G_D\\left( \\vec{x},\\vec{x}' \\right)\n    \\, d^3\\vec{x}'\n    -\n    \\frac{1}{4\\pi}\n    \\oint_S\n    \\phi\\left( \\vec{x}' \\right)\n    \\left\\{ \n    \\vec{\\nabla}' G_D \\left( \\vec{x}', \\vec{x} \\right)\n    \\cdot \\hat{n}'\n    \\right\\}\n    \\,dS'\n\\end{align}\nNow here's the thing.\nWhat is $\\rho\\left( \\vec{x}' \\right)$?\nIt's zero, because there are no charges.\nWe know the Greens function,\nso we can calculate this gradient.\nAnd $\\phi(\\vec{x}')$ is specified on the surfaces.\n\nAnd then we can do the problem we want to solve by evaluating this integral.\nYou see the power of this method.\nThe problem you originally solved looks noting like this problem.\nThe only thing the same is the surface.\nThis is a sphere\nthat's a sphere.\nEverything else is changed.\nCharges are changed,\nboundary conditions have changed.\n\nOnce you know the Greens function for that surface,\nthen it just doesn't matter.\nIt's the surface that matters.\nOnce you have solved the Greens function for that surface with Dirichlet\nboundary conditions,\nyou're done.\nJust plug it into this formula.\nThat's the magic.\nThen of course you may say this is a messy integral,\nbut that's completely different.\nThat's not the hard work.\nThe real hard work was finding the Greens function.\n\nIt was easy with the method of images here,\nbut for more general geometries it's much harder.\n\nAny problem you can solve by the method of images you can use this method.\n\nIn spherical coordinates\n\\begin{align}\n    \\left|\n    \\vec{x} - \\vec{x}'\n    \\right|\n    &=\n    \\sqrt{%\n    r^2 + {r'}^2\n    - 2rr' \\cos\\gamma\n    }\n\\end{align}\nwhere $\\gamma$ is the angle between $\\vec{x}$ and $\\vec{x}'$.\n\nThen\n\\begin{align}\n    r'\n    \\left|\n    \\vec{x}\n    -\n    \\frac{a^2}{r'^2}\\vec{x}'\n    \\right|\n    &=\n    \\sqrt{\n    r^2 r'^2 - 2a^2 rr' \\cos\\gamma\n    + a^4\n    }\n\\end{align}\nand\n\\begin{align}\n    \\cos \\gamma &= \\hat{e}_r \\hat{e}_{r'}\n\\end{align}\nwhere\n\\begin{align}\n    \\hat{e}_r\n    &=\n    \\sin\\theta \\cos\\phi \\hat{e}_x\n    + \\sin\\theta \\sin\\phi \\hat{e}_\\phi\n    + \\cos\\theta \\hat{e}_z\\\\\n    \\hat{e}_{r'}\n    &=\n    \\sin\\theta' \\cos\\phi' \\hat{e}_x\n    + \\sin\\theta' \\sin\\phi' \\hat{e}_\\phi\n    + \\cos\\theta' \\hat{e}_z\\\\\n\\end{align}\nAnd in spherical coordinates\n\\begin{align}\n    \\cos\\gamma\n    &=\n    \\cos\\theta \\cos\\theta'\n    + \\sin\\theta \\sin\\theta' \\cos\\left( \\phi - \\phi' \\right)\\\\\n    G_D\\left( \\vec{x}, \\vec{x}' \\right)\n    &=\n    \\frac{1}{\\sqrt{\n    r^2 + r'^2 + 2r r' \\cos\\gamma\n    }}\n    -\n    \\frac{1}{\\sqrt{\n    \\frac{r^2 r'^2}{a^2} \n    + a^2\n    - 2 r r' \\cos\\gamma\n    }}\n\\end{align}\nWe need to calculate $\\vec{\\nabla}'G_D$.\nYou can check that the Green function is symmetric\n\\begin{align}\n    G\\left( \\vec{x}, \\vec{x}' \\right)\n    &=\n    G\\left( \\vec{x}', \\vec{x}' \\right)\n\\end{align}\nComing back to this,\nwhat is $\\hat{n}'$.\nWhat should I choose for it in the coordinate systems I've chosen.\nYou should choose\n\\begin{align}\n    \\hat{n}' &= -\\hat{e}_{r'}\n\\end{align}\nBut why the minus sign?\nRemember,\nwe're living in the volume outside the sphere.\n$\\hat{n}'$ is the unit vector going \\emph{out} of our volume\nwhere we are trying to solve for the potential,\nso it should be going into the sphere.\nThat's a common thing to mess up.\n\nSo then this becomes\n\\begin{align}\n    \\vec{\\nabla}' G_D \\left( \\vec{x}', \\vec{x} \\right)\n    \\cdot \\hat{n}'\n    &=\n    - \\frac{\\partial G_D}{\\partial r'}\n\\end{align}\nand it's just a lot of algebra,\nbut all the steps are given in my notes.\nWhen all the dust settles,\n\\begin{align}\n    - \\frac{\\partial G_D}{\\partial r'}\n    &=\n    \\frac{-\\left( r^2 - a^2 \\right)}{\n    \\left( r^2 + a^2 - 2ar\\cos\\gamma \\right)^{3/2}\n    }\n\\end{align}\n\nSo after doing some steps,\n\\begin{align}\n    \\phi\\left( \\vec{x} \\right)\n    &=\n    \\frac{1}{4\\pi}\n    \\int_S\n    \\phi\\left( a, \\theta', \\phi' \\right)\n    \\frac{-\\left( r^2 - a^2 \\right)}{\n    \\left( r^2 + a^2 - 2ar\\cos\\gamma \\right)^{3/2}\n    }\n    d\\Omega'\n\\end{align}\nwhere $d\\Omega' = \\sin\\hteta' \\, d\\theta'\\, d\\phi$\nis the solid angle,\nwith $dS' = a^2 d\\Omega'$.\n\nThis thing reduces to\n\\begin{align}\n    \\phi\\left( \\vec{x} \\right)\n    &=\n    \\frac{V a^2\\left( r^2 - a^2 \\right)}{4\\pi a}\n    \\int_{0}^{2\\pi}\n    d\\phi'\n    \\left[\n    \\int_{0}^{1}\n    d\\left( \\cos\\theta' \\right)\n    -\n    \\int_{-1}^{0}\n    d\\left( \\cos\\theta' \\right)\n    \\right]\n    \\frac{1}{\\left( a^2 + r^2 - 2ar\\cos\\gamma \\right)^{1/2}}\n\\end{align}\nAt this point the physics is kind of done.\nIn other words,\nknowing this Greens function,\nyou can find the potential for this sphere,\nreduced to some integral,\nwhich we may not do in closed form,\nbut the answer is here.\n\n\\begin{question}\n    What if there are multiple surfaces?\n\\end{question}\nThen you have many integrals.\n\nBut this is about as an easy of a problem as you can get with Green's function.\nThat was a very easy problem.\n\n\\section{Method of Orthogonal Basis Functions}\nSuppose you know the Greens function for some boundary,\nfor arbitrary boundary conditions you can find the potential.\nBut how do you find the Green's function?\nIn general it's hard.\n\nThe method of images works some times.\n\nI will now discuss another method.\n\nThe idea here is that in the end,\nsolving a partial differential equation,\nlike Poisson's equation or Laplace's equation,\nthe physicist favorite method is separation of variables.\nThere are certain geometries where the Laplacian geometry is separable.\nThere are a dozen or so where Laplace's equation is separable.\nWe're not going to do all the dozen.\nIf you took the math methods class 40 years ago,\nyou would learn a whole dozen.\nNowadays you only have to study 3,\nwhich are Cartesian, spherical and cylindrical.\nThat's pretty much the rest of the course.\n\nSo we're just going to do a couple of examples with Cartesian,\nspherical, cylindrical.\nFor some reason,\nthe number of cylindrical examples in the books is fewer,\neven though it's harder.\n\nLet's start with the easy case of Cartesian.\n\nHere's the problem.\nNot sure if you've solved this as an undergraduate.\nThe problem is that you have a rectangular box\nwith sides $\\Delta x = a$,\n$\\Delta y = b$ and $\\Delta z = c$.\nThis box is sitting with one of its corners in the origin.\nThis height is $c$,\nthis distance is $a$ and this distance if $b$.\nIt's a rectangular box.\nSo you understand this geometry or is it mysterious?\nAnyway that's what it is.\n\nAll the sides of the box are at zero potential except the top\n$z=c$,\nwhich is at potential $V(x, y)$,\nwhich is some specific function that is specified.\nYou're told that at the top of the box,\nthe potential satisfies this.\n\nThe problem is to solve for $\\phi$ everywhere inside the box.\nThis is not particularly hard.\nYou just have to solve Laplace's equation inside the box.\nSince the sides of the box parallel to $xyz$,\nit's most convenient to use Cartesian coordinates.\n\\begin{align}\n    \\frac{\\partial^2 \\phi}{\\partial x^2}\n    +\n    \\frac{\\partial^2 \\phi}{\\partial y^2}\n    +\n    \\frac{\\partial^2 \\phi}{\\partial z^2}\n    &=\n    0\n\\end{align}\nWe're going to solve this using the method of separation of variables.\n\nHere's the idea.\nWe begin by looking for a solution\nof very specific form.\n\\begin{align}\n    \\hat{\\phi}\\left( x, y, z \\right)\n    &=\n    X(x) Y(y) Z(z)\n\\end{align}\nIn the end the final solution will not be of this form,\nbut it will be a superposition of solutions of this form.\nSo you find solutions like this and then you add them up to satisfy the boundary\nconditions.\nSubstituting into Laplace's equation,\n\\begin{align}\n    \\frac{1}{X}\\frac{d^2 X}{d x^2}\n    +\n    \\frac{1}{Y}\\frac{d^2 Y}{d y^2}\n    +\n    \\frac{1}{Z}\\frac{d^2 Z}{d z^2}\n    &=\n    0\n\\end{align}\nBefore they were partial derivatives,\nbut here they are ordinary derivatives.\nRewrite this as\n\\begin{align}\n    \\frac{1}{X} \\frac{d^2 X}{dx^2}\n    + \\frac{1}{Y} \\frac{d^2 Y}{dx^2}\n    &=\n    -\\frac{1}{Z}\n    \\frac{d^2 Z}{dz^2}\n\\end{align}\nNow comes the crucial step.\nThe right side of the equation only depends on $z$.\nThe left side depends on $x,y$ but not on $z$.\nSuppose I change $z$,\nthe right hand side should change,\nbut the left hand side can't change,\nand the only way that can be true is if the right side doesn't actually depend\non $z$ at all.\nHence\n\\begin{align}\n    -\\frac{1}{Z}\n    \\frac{d^2 Z}{dz^2}\n    =\n    \\text{constant}\n\\end{align}\nthat is independent of $z$\nLet's give this constant a name.\n\\begin{align}\n    -\\frac{1}{Z}\n    \\frac{d^2 Z}{dz^2}\n    =\n    -\\gamma^2.\n\\end{align}\nWhy the minus sign?\nBecause I know the answer.\nSometimes you can get the solution and find the sign is not nice and you have to\ngo back to this step to change the sign.\nI know the answer and this choice is good.\n\nSimilarly,\nyou can say the same thing about the other side,\nwith $x$ and $y$.\n\nThen we have two equations.\nWe started wiht one equation,\nbut now we have 2 equations.\n\\begin{align}\n    \\frac{1}{X}\\frac{d^2 X}{dx^2}\n    +\n    \\frac{1}{Y}\\frac{d^2 Y}{dy^2}\n    &=\n    -\\gamma^2\n\\end{align}\nand we have\n\\begin{align}\n    -\\frac{1}{Z} \\frac{d^2 Z}{dz^2} &= -\\gamma^2\n\\end{align}\nSo now we can rewrite the first equation as\n\\begin{align}\n    \\frac{1}{X} \\frac{d^2 X}{dx^2}\n    &=\n    -\\frac{1}{Y} \\frac{d^2 Y}{dy^2}\n    - \\gamma^2\n\\end{align}\nand now we apply the same logic as before.\nIf I change $x$,\nI should expect the left hand side ot chnage,\nbut the right side dosn't change,,\nand the only way for that to be possible is that the left doesn't actually\ndepend on $x$ and so it's some constant independent of $x$ and $y$,\nand let's call it $-\\alpha^2$.\nOnce again there's a sign because I know the answer.\n\\begin{align}\n    \\frac{1}{X} \\frac{d^2 X}{dx^2}\n    &=\n    -\\alpha^2.\n\\end{align}\nWe can then define a parameter\n\\begin{align}\n    \\beta^2 &:= \\gamma^2 - \\alpha^2\n\\end{align}\nand now we have 3 equations.\n\\begin{align}\n    \\frac{1}{X} \\frac{d^2 X}{dx^2}\n    &=\n    -\\alpha^2\\\\\n    \\frac{1}{Y}\n    \\frac{d^2 Y}{dy^2} &=\n    -\\beta^2\\\\\n    \\frac{1}{Z}\\frac{d^2 Z}{dz^2} &=\n    + \\gamma^2.\n\\end{align}\nSo we have 3 ODEs and we know the boundary conditions\n\\begin{align}\n    X(x) &= 0 &\\text{at }x = 0 \\text{ and } x = a\\\\\n    Y(y) &= 0 &\\text{at }y = 0 \\text{ and } y = b\n\\end{align}\nThen\n\\begin{align}\n    X(x) &=\n    \\sin\\left( \\frac{n\\pi x}{a} \\right)\\\\\n    Y(y) &=\n    \\sin\\left( \\frac{m\\pi y}{b} \\right)\n\\end{align}\nwhere $n,m$ are integers\nand we know\n\\begin{align}\n    Z(z) &= 0 &\\text{at } z = 0\n\\end{align}\nso then\n\\begin{align}\n    Z(z) &= \\sinh\\left( \\gamma_{nm} z \\right)\n\\end{align}\nwhere\n\\begin{align}\n    \\gamma_{nm} &=\n    \\pi \\sqrt{\n    \\left( \\frac{n}{a} \\right)^2\n    +\n    \\left( \\frac{m}{b} \\right)^2\n    }\n\\end{align}\nThere's still one boundary condition at the top we haven't used yet.\nThe thing about the hyperbolic sine is that it's monotonic.\nIf $\\phi$ is zero at the top,\nthen I just get $\\phi(z)=0$ everywhere,\nso it's important I have some interesting boundary conditions.\n\nTo satisfy boundary conditions at $z=c$ for a linear superposition,\n\\begin{align}\n    \\ph(x, y, z)\n    &=\n    \\sum_{n,m=1}^\\infy\n    A_{mn}\n    \\sin\\left( \\frac{n \\pi x}{a} \\right)\n    \\sin\\left( \\frac{m \\pi y}{b} \\right)\n    \\sinh\\left( \\gamma_{mn} z \\right)\n\\end{align}\nand we require that\n\\begin{align}\n    \\phi\\left( x, y, c \\right) &= V\\left( x, y \\right)\n\\end{align}\nThis is really just double Fourier seris for $V(x, y)$.\nWhat we need to do is invert this and find the Foufier coefficients \n$A_{nm}$.\nUse the identity\n\\begin{align}\n    \\frac{2}{L}\\int_{0}^{L} dx\\,\n    \\sin\\left( \\frac{n\\pi x}{L} \\right)\n    \\sin\\left( \\frac{n'\\pi x}{L} \\right)\n    &=\n    \\delta_{n,n'}\n\\end{align}\niSo then\n\\begin{align}\n    \\int_{0}^{a}dx\\,\n    \\left( \\frac{z}{a} \\right)\n    \\sin\\left( \\frac{n'\\pi x}{a} \\right)\n    \\int_{0}^{b}dy\\,\n    \\left( \\frac{z}{b} \\right)\n    \\sin\\left( \\frac{m' \\pi y}{b} \\right)\n    V\\left( x, y \\right)\n    &=& \n    \\sum_{n,m}\n    A_{nm} \\delta_{nn'} \\delta_{mm'}\n    \\sin\\left( \\Gamma_{nm} z \\right)\n\\end{align}\nwhich gives\n\\begin{align}\n    A_{nm}\n    &=\n    \\frac{4}{ab}\n    \\frac{1}{\\sinh\\left( \\gamma_{nm} z \\right)}\n    \\int_{0}^{a} dx\n    \\int_{0}^{L} dy\\,\n    \\sin\\left( \\frac{n\\pi x}{a} \\right)\n    \\sin\\left( \\frac{m\\pi y}{b} \\right)\n    V\\left( x, y \\right)\n\\end{align}\n\nMeake sure you can solve the problems in hte homework chop chop.\nThe problems aresimliar but not the same.\nYou need to do those right quicklky.\nSome questions are straightforward but longer,\nbut you can do those later once you've finished the fast ones.\nYou guys should do well in this exam.\nEM no matter how easy is going to be a hard exame.\n", "meta": {"hexsha": "5eed39731c8a35ff7a568f5f928b650776c953c1", "size": 15944, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys610/lecture24.tex", "max_stars_repo_name": "ehua7365/umdphysnotes", "max_stars_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-11T12:53:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-11T12:53:46.000Z", "max_issues_repo_path": "phys610/lecture24.tex", "max_issues_repo_name": "ehua7365/umdphysnotes", "max_issues_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "phys610/lecture24.tex", "max_forks_repo_name": "ehua7365/umdphysnotes", "max_forks_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.9324324324, "max_line_length": 80, "alphanum_fraction": 0.6511540391, "num_tokens": 5171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388209992571, "lm_q2_score": 0.8670357598021707, "lm_q1q2_score": 0.7187196004946065}}
{"text": "\\chapter{Cylindrical function decomposition of a tilted incident plane wave}\\label{Ch:PlanewaveDecomposition}\nAs an example of applying the mode decomposition technique we used above to find the projected bounded and unbounded modes under cylindrical boundary conditions, below, we demonstrate a simple case on decomposing a tilted incident plane wave into corresponding cylindrical modes. The solution might be useful to give us some insights on solving the corresponding nanofiber problem when an external field presents, which is the case for some cooling and state preparation protocols demonstrated in experiments~\\cite{Meng2017ground,Ostfeldt2017Dipole}. \n\nThe key to solve this kind of problems is to decompose all field functions into cylindrical functions. The bare nanofiber modes have already been decomposed into cylindrical functions in the last section; therefore, here, we only need to decompose the incident field as cylindrical functions. \n\nWe assume the incident plane wave is given by\n\\begin{equation}\n\\mathbf{E}(\\br,t)=\\re\\left[\\mathbf{U}(\\br,t) \\right]=\\mathbf{E}_0 \\cos (\\mathbf{k}\\cdot\\mathbf{r}-\\omega t + \\phi_0),\n\\end{equation}\nwhere the forward propagating wave can be given by\n\\begin{align}\n\\mathbf{U}(\\br,t) &= \\mathbf{U}_0e^{i(\\mathbf{k}\\cdot\\mathbf{r}-\\omega t + \\phi_0)}\\\\\n&= \\mathbf{U}_0e^{i\\mathbf{k}\\cdot\\mathbf{r}}e^{i(\\phi_0-\\omega t )}.\n\\end{align}\nwith the initial phase, $\\phi_0$, and the vector amplitude of $\\mathbf{U}_0$. We can ignore the phase offset, and separate the spatial and temporal parts for the forward-propagating field. We want to expand the plane wave function into cylindrical functions, and thus we can apply the technique we used in the last appendix to solve the boundary condition problem and decompose the bound and radiation modes. The only term that needs to be expanded is the $ e^{i\\mathbf{k}\\cdot\\mathbf{r}} $ factor. \n\nWe define $ \\mathbf{k}\\cdot\\mathbf{r}=(k\\!_{\\perp}\\mathbf{e}\\!_{k\\!_\\perp}+k_z\\mathbf{e}_{z}) \\cdot(r\\!_{\\perp}\\mathbf{e}\\!_{r\\!_\\perp}+z\\mathbf{e}_{z}) = k\\!_{\\perp}r\\!_{\\perp}\\cos(\\phi_{k}-\\phi_{r})+k_{z}{z}= k\\!_\\perp r\\!_\\perp \\cos \\Delta\\phi +k_{z}{z}$, where $ \\Delta\\phi=\\phi_{k}-\\phi_{r} \\in [0,2\\pi)$ is the angle between $ \\mathbf{e}_{k\\!_\\perp} $ and $ \\mathbf{e}_{r\\!_\\perp} $. Thus\n\\begin{align}\ne^{i\\mathbf{k}\\cdot \\mathbf{r}}=e^{ik\\!_\\perp r\\!_\\perp\\cos\\Delta\\phi}e^{ik_{z}{z}}\n\\end{align}\nis a periodic function of $ \\Delta\\phi $ and hence can be expanded into a Fourier series given below. \n\\begin{align}\ne^{i\\mathbf{k}\\cdot \\mathbf{r}} &= \\sum_{m=-\\infty}^{\\infty}c_{m}(k\\!_\\perp r\\!_\\perp)e^{im\\Delta\\phi}e^{ik_{z}{z}},\n\\end{align}\nwhere the coefficients $ c_{m}(k\\!_\\perp r\\!_\\perp) $ is associated with Bessel's first integral\\index{Bessel function!Bessel's first integral}~\\footnote{see Jackson's E\\&M of Ref.~\\cite{Jackson1975}, on page 140.}\n\\begin{align}\nc_{m}(k\\!_\\perp r\\!_\\perp)&= \\frac{1}{2\\pi} \\int_0^{2\\pi} e^{ik\\!_\\perp r\\!_\\perp\\cos \\Delta\\phi}e^{-im\\Delta\\phi}\\mathrm{d}\\Delta\\phi\\\\\n&=i^mJ_m(k\\!_\\perp r\\!_\\perp).\n\\end{align}\nTherefore, we have\n\\begin{align}\ne^{i\\mathbf{k}\\cdot \\mathbf{r}} &=\\sum_{m=-\\infty}^{\\infty}i^me^{im\\Delta\\phi}e^{ik_{z}{z}}J_m(k\\!_\\perp r\\!_\\perp).\n\\end{align}\n\nNotice that the first kind of Bessel's function\\index{Bessel function!Bessel function of the first kind} usually represent standing radial waves, while Hankel functions\\index{Hankel function} usually describe traveling waves. Using the relationships that $ J_{m}(k\\!_\\perp r\\!_\\perp)=H_{m}^{(1)}(k\\!_\\perp r\\!_\\perp)+H_{m}^{(2)}(k\\!_\\perp r\\!_\\perp) $, we can re-express the plane wave in terms of incoming (at negative r) and outgoing (at positive r) as below.\n\\begin{align}\ne^{i\\mathbf{k}\\cdot \\mathbf{r}} &=\\sum_{m=-\\infty}^{\\infty}i^me^{im\\Delta\\phi}e^{ik_{z}{z}} H_{m}^{(1)}(k\\!_\\perp r\\!_\\perp)+\\sum_{m=-\\infty}^{\\infty}i^me^{im\\Delta\\phi}e^{ik_{z}{z}} H_{m}^{(2)}(k\\!_\\perp r\\!_\\perp).\n\\end{align}\n\nThis result shows that only when $ k_z=\\beta $ can the tilted plane wave contributes to nanofiber modes be with wavenumber $ \\beta $, since both $ k_z $ and $ \\beta $ have consistent physics meaning. Therefore, when a plane wave comes perpendicular to the fiber axis, the wave can rarely couple to the fiber's guided modes, which is good for minimizing the influence of the incident external field directly mixed into the detected signal at the end of the fiber. ", "meta": {"hexsha": "0f60e3e2f772a50d5352bc9aba55fefae112434c", "size": 4380, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "append/PlanewaveDecomposition.tex", "max_stars_repo_name": "i2000s/PhD_Thesis", "max_stars_repo_head_hexsha": "a9bc6bc4213896c70c90cbb3d9b533782d428761", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-26T01:58:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-27T19:11:43.000Z", "max_issues_repo_path": "append/PlanewaveDecomposition.tex", "max_issues_repo_name": "i2000s/PhD_Thesis", "max_issues_repo_head_hexsha": "a9bc6bc4213896c70c90cbb3d9b533782d428761", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-07-18T01:47:21.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-18T01:47:21.000Z", "max_forks_repo_path": "append/PlanewaveDecomposition.tex", "max_forks_repo_name": "i2000s/PhD_Thesis", "max_forks_repo_head_hexsha": "a9bc6bc4213896c70c90cbb3d9b533782d428761", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-07-17T21:55:09.000Z", "max_forks_repo_forks_event_max_datetime": "2018-07-17T21:55:09.000Z", "avg_line_length": 109.5, "max_line_length": 551, "alphanum_fraction": 0.7219178082, "num_tokens": 1469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.8289388146603364, "lm_q1q2_score": 0.7187195921505062}}
{"text": "\\lesson{1}{Sep 07 2021 Tue (16:52:35)}{Rational Exponents}{Unit 1}\n\n\\subsubsection*{Rational Exponents become $\\rightarrow$ Radical Expressions}\n\nThe \\bf{numerator} of the \\bf{rational exponent} becomes the \\bf{exponent} on the \\bf{radicand}.\nThe \\bf{denominator} of the \\bf{rational exponent} becomes the \\bf{index}, or \\bf{root}, of the \\bf{radical}.\n\n\\begin{align}\n    t^{\\frac{3}{4}} = \\sqrt[4]{t^3}\n\\end{align}\n\n\\subsubsection*{Radical Expressions become $\\rightarrow$ Rational Exponents}\n\nThe \\bf{exponent} on the \\bf{radicand} becomes the \\bf{numerator} of the \\bf{rational exponent}. The \\bf{index}, or \\bf{root}, of the \\bf{radical} becomes the \\bf{denominator} of the \\bf{rational exponent}.\n\n\\begin{align}\n    \\sqrt[8]{w^5} = w^{\\frac{5}{8}}\n\\end{align}\n\n\\newpage\n", "meta": {"hexsha": "e313bac78a7f9178d52bc3db61d20f9e8385ac9c", "size": 775, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-1/lesson-1.tex", "max_stars_repo_name": "SingularisArt/notes", "max_stars_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-08-31T12:45:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T07:29:05.000Z", "max_issues_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-1/lesson-1.tex", "max_issues_repo_name": "SingularisArt/notes", "max_issues_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-1/lesson-1.tex", "max_forks_repo_name": "SingularisArt/notes", "max_forks_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.9047619048, "max_line_length": 206, "alphanum_fraction": 0.704516129, "num_tokens": 269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.8670357666736773, "lm_q1q2_score": 0.718719587870428}}
{"text": "\\chapter{Spaces and Tensors}\n\\pagebreak[4]\n\n\\section{p5-exercise}\n\n\\begin{tcolorbox}\n\nThe parametric equations of a hypersurface in $V_n$ are\n\\begin{align*} \n\\ &x^1 = a \\cos(u^1)\\\\\n\\ &x^2 = a \\sin(u^1)\\cos(u^2)\\\\\n\\ &x^3 = a \\sin(u^1)\\sin(u^2)\\cos(u^3)\\\\\n\\vdots\\\\\n\\ &x^{N-1} = a \\sin(u^1)\\sin(u^2)\\sin(u^3)\\dots\\sin(u^{N-2})\\cos(u^{N-1})\\\\\n\\ &x^{N} = a \\sin(u^1)\\sin(u^2)\\sin(u^3)\\dots\\sin(u^{N-2})\\sin(u^{N-1})\\\\\n\\end{align*}\nwhere a is a constant. Find the single equation of the hyperspace in the form 1.103.\n\n\\end{tcolorbox}\n\nWe have:\n\\begin{align*}\n\\ (x^N)^2 + (x^{N-1})^2 &= a^2\\prod_{i=1}^{N-2}\\sin^2(u^i)(\\cos^2(u^{N-1})+\\sin^2(u^{N-1}))  \\\\\n\\ &= a^2\\prod_{i=1}^{N-2}\\sin^2(u^i)\\\\\n\\ &= a^2\\prod_{i=1}^{N-3}\\sin^2(u^i)\\sin^2(u^{N-2})\\\\\n\\ &= a^2\\prod_{i=1}^{N-3}\\sin^2(u^i)(1-\\cos^2(u^{N-2})\\\\\n\\ &= a^2\\prod_{i=1}^{N-3}\\sin^2(u^i) - a^2\\prod_{i=1}^{N-3}\\sin^2(u^i)\\cos^2(u^{N-2})\\\\\n\\ &= a^2\\prod_{i=1}^{N-3}\\sin^2(u^i) - (x^{N-2})^2\\\\\n\\end{align*}\ngiving\n$$(x^N)^2 + (x^{N-1})^2 + (x^{N-2})^2 = a^2\\prod_{i=1}^{N-3}\\sin^2(u^i)$$\nIn general, by recursion\n$$\\sum_{i=0}^k(x^{N-i})^2 = a^2\\prod_{i=1}^{N-k-1}\\sin^2(u^i)     \\quad (k \\leq N-2)$$\nbe k = N - 2 (N - k - 1 = 1) and in the left term put j = N - i (j goes from 2 to N), we get\n\\begin{align*}\n\\sum_{j=2}^N(x^{j})^2 &= a^2\\prod_{i=1}^{1}\\sin^2(u^i)\\\\\n\\ &= a^2(1-\\cos^2(u^1))\\\\\n\\ &= a^2 - (x^1)^2\\\\\n\\end{align*}\nand thus the equation of the hyperspace is given by\n\\begin{LARGE}\n\\textbf{\n$$\\sum_{j=1}^N(x^{j})^2 - a^2 = 0$$\n}\n\\end{LARGE}\n\\begin{tcolorbox}\n\nDetermine whether the points $(\\frac{1}{2}a,0,0,... 0)$, $(0,0,...,0, 2a)$ lie on the same or opposite sides of the hyperspace.\n\\end{tcolorbox}\nFor $(\\frac{1}{2}a,0,0,... 0)$ we have $\\sum_{j=1}^N(x^{j})^2 - a^2 = -\\frac{3a^2}{4} < 0$ and for \n$(0,0,...,0, 2a)$ \\\\we have $\\sum_{j=1}^N(x^{j})^2 - a^2 = \\frac{3a^2}{4} > 0$.\\\\\nSo the points lie on opposite sides of the hyperplane.\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p6-exercise}\n\n\\begin{tcolorbox}\n\nLet $U_2$ and $W_2$ be subspaces of $V_N$. Show that if N = 3  they will in general intersect in a curve; if N = 4 they will in general intersect in a finite number of points; and if $N > 4$ they will not in general intersect at all.\n\\end{tcolorbox}\n\nWe have (see 1.102 page 5):\n$\\quad x^r = f^r(u^1, u^2,..., u^M) \\quad (r = 1, 2, ...,N)$\n\nCase N=3: \\\\\n\nFor $U_2$ we have:\n$$x^r = \\phi^r(u^1, u^2) \\quad (r = 1, 2, 3)$$\n\nFor $W_2$ we have:\n$$x^r = \\psi^r(v^1, v^2) \\quad (r = 1, 2, 3)$$\n\nThe intersect of the two hyperplanes is given by the N equations:\n\n$$\\phi^r(u^1, u^2) = \\psi^r(v^1, v^2) \\quad (r = 1, 2, 3)$$\n\nSo we have 3 equations in 4 unknown $u^1,u^2, v^1, v^2$ and can choose (fix) one e.g. $u^1$ and solve the set of equations  for $u^2, v^1, v^2$ giving \n$$x^r = \\theta^r(u^1) \\quad (r = 1, 2, 3)$$\nThis is an equation of a curve in space (1 parameter equation)\\\\\nCase N=4: \\\\\nUsing the same reasoning as with N=3, we get 4 equations for 4 unknown $u^1,u^2, v^1, v^2$.\\\\\nProvided that the set of equation does not degenerate, these 4 equations will determine $u^1,u^2, v^1, v^2$ without any degree of freedom. So we get  points as solutions. This solution does not to be unique, e.g. if the $\\phi^r(u^1, u^2)$ are quadratic form, then the solutions \n$$(u^1,u^2, v^1, v^2)$$\n$$(-u^1,u^2, v^1, v^2)$$\n$$ (u^1,-u^2, v^1, v^2)$$\n$$ (-u^1,-u^2, v^1, v^2)$$\nare possible.\\\\\nCase N=5: \nThere are more equations than variables. If the equations are not linear dependent, no solutions will be found.\n$$\\blacklozenge$$\n\\pagebreak[4]\n\\section{p8-exercise}\n\n\\begin{tcolorbox}\nShow that $(a_{rst}+a_{str}+a_{srt})x^rx^sx^t = 3a_{rst}x^rx^sx^t$\n\\end{tcolorbox}\n%\\setcounter {equation} {1} %sets the counter to have the specified\n$(a_{rst}+a_{str}+a_{srt})x^rx^sx^t = a_{rst}x^rx^sx^t+a_{rts}x^rx^sx^t+a_{srt}x^rx^sx^t\\quad$\nso by just renaming the dummy indices e.g. for the second term  $r \\mapsto s\\quad$, $s \\mapsto t\\quad$ and $t \\mapsto r\\quad$ we get the desired result.\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p8-exercise}\n\n\\begin{tcolorbox}\nIf $\\phi = a_{rs}x^rx^s$, show that\n$$\\pdv{\\phi}{x^{r}} = (a_{rs}+a_{sr})x^s \\quad\\text{,}\\quad\\pdv{\\phi}{x^{r}}{x^{s}} = a_{rs}+a_{sr}$$\nSimplify these expressions in the case where $a^{rs} = a^{sr}$\n\\end{tcolorbox}\nWe have \n\\begin{align} \n\\pdv{\\phi}{x^{t}} &= \\pdv{a_{rs}}{x^{t}}x^{r}x^{s}+a_{rs}\\pdv{x^{r}}{x^{t}}x^{s}+a_{rs}x^{r}\\pdv{x^{s}}{x^{t}}\\\\\n&= \\pdv{a_{rs}}{x^{t}}x^{r}x^{s}+a_{rs}\\delta_t^rx^{s}+a_{rs}x^{r}\\delta^s_t\\\\\n&= \\pdv{a_{rs}}{x^{t}}x^{r}x^{s}+a_{ts}x^{s}+a_{rt}x^{r}\\\\\n&= \\pdv{a_{rs}}{x^{t}}x^{r}x^{s}+a_{ts}x^{s}+a_{st}x^{s}\\quad\\text{(rename dummy variable in third term)}\\\\\n&= \\pdv{a_{rs}}{x^{t}}x^{r}x^{s}+(a_{ts}+a_{st})x^{s}\n\\end{align}\nReplace $x^t$ by $x^r$, we get\n\\begin{align}\n\\pdv{\\phi}{x^{r}}  =\\pdv{a_{rs}}{x^{r}}x^{r}x^{s}+(a_{rs}+a_{sr})x^{s}\n\\end{align}\nSo the asked expression is only true if $a_{rs}$ is not a function of the $x^{s}$.\nAssuming that $a_{rs}$ is not a function of the $x^{s}$, take the partial derivative of (6) with respect to $x^{t}$, we get\n\\begin{align} \n\\pdv{\\phi}{x^{r}}{x^{t}} &= (a_{rs}+a_{sr})\\pdv{x^{s}}{x^{t}}\\\\\n&=(a_{rs}+a_{sr})\\delta^{s}_{t}\\\\\n&=(a_{rt}+a_{tr})\n\\end{align}\nReplace $x^t$ by $x^s$, and we get the proposed expression.\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p8-clarification on expression 1.210}\n\n\\begin{tcolorbox}\n$$\\pdv{x^{,q}}{x^{p}}{x^{s}}+\\pdv{x^{r}}{x^{,m}}{x^{,n}}\\pdv{x^{,m}}{x^{p}}\\pdv{x^{,n}}{x^{s}}\\pdv{x^{,q}}{x^{r}} = 0 $$\n\\end{tcolorbox}\nFrom 1.209:\n\\begin{gather} \n\\pdv{x^r}{x^{,m}}{x^{,n}}\\pdv{x^{,m}}{x^{p}}\\pdv{x^{,n}}{x^{s}}+\\pdv{x^r}{x^{,n}}\\pdv{x^{,n}}{x^p}{x^{s}} = 0\n\\end{gather}\n multiply (1)  with $\\quad\\pdv{x^{,q}}{x^{r}}$\n\\begin{gather} \n\\pdv{x^r}{x^{,m}}{x^{,n}}\\pdv{x^{,m}}{x^{p}}\\pdv{x^{,n}}{x^{s}}\\pdv{x^{,q}}{x^{r}}+\\pdv{x^r}{x^{,n}}\\pdv{x^{,n}}{x^p}{x^{s}}\\pdv{x^{,q}}{x^{r}} = 0\\\\\n\\Leftrightarrow\\pdv{x^r}{x^{,n}}\\pdv{x^{,n}}{x^p}{x^{s}}\\pdv{x^{,q}}{x^{r}}+ \\pdv{x^r}{x^{,m}}{x^{,n}}\\pdv{x^{,m}}{x^{p}}\\pdv{x^{,n}}{x^{s}}\\pdv{x^{,q}}{x^{r}}= 0\n\\end{gather}\n\\begin{gather} \n\\text{\\centering in the first term we get\\quad\\quad}\\quad \\pdv{x^{,q}}{x^{r}}\\pdv{x^r}{x^{,n}} = \\pdv{x^{,q}}{x^{,n}} = \\delta_n^q\n\\end{gather}\n(3) becomes\n\\begin{gather} \n\\pdv{x^{,n}}{x^p}{x^{s}}\\delta_n^q + \\pdv{x^r}{x^{,m}}{x^{,n}}\\pdv{x^{,m}}{x^{p}}\\pdv{x^{,n}}{x^{s}}\\pdv{x^{,q}}{x^{r}}=  0\\\\\n\\Leftrightarrow\\pdv{x^{,q}}{x^p}{x^{s}} + \\pdv{x^r}{x^{,m}}{x^{,n}}\\pdv{x^{,m}}{x^{p}}\\pdv{x^{,n}}{x^{s}}\\pdv{x^{,q}}{x^{r}}= 0\n\\end{gather} \n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\n\n\\section{p9-exercise}\n\n\\begin{tcolorbox}\nIf $A_s^r$ are the elements of a determinant A, and $B_s^r$ the elements of a determinant B, show that the element of the product determinant is $A_n^rB^n_s$. Hence show that the product of the two jacobians\n$$J =\\Bigg|\\pdv{x^{r}}{x^{,s}}\\Bigg|\\text{,}\\quad J^{'} = \\Bigg|\\pdv{x^{,r}}{x^{s}}\\Bigg|$$\nis unity.\n\\end{tcolorbox}\nRemark: Some nitpick about the formulation: $A_s^r$ are not the elements of a determinant A, but elements of the matrix A which gives $\\det{A}$ provided that A is square (which is not explicitly mentioned.). The same remark for B and $A_n^rB^n_s$.\\\\\nBe $A^i_k $ the elements of matrix A and $B^k_j $ the elements of matrix B and C = A.B the resulting matrix of the multiplication of A and B, then\n$$C^i_j  = A^i_kB^k_j $$\nare the elements of matrix C.\nNow, put $A^i_k =\\pdv{x^{i}}{x^{,k}} \\quad$ and $B^k_j =\\pdv{x^{,k}}{x^{j}} \\quad$ then,\n\\begin{align}\nC^{i}_{j}  &= A^{i}_{k}B^{k}_{j} \\\\\n&=\\pdv{x^{i}}{x^{,k}}\\pdv{x^{,k}}{x^{j}}\\\\\n&= \\delta^{i}_{k}\n\\end{align}\nSo $C = JJ^{,}\\quad$becomes the unity matrix. \n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p11-exercise}\n\n\\begin{tcolorbox}\nShow that a finite contravariant vector determines the ratios of the components of an infinitesimal displacement. (Consider the transformation of the equation $dx^r=\\theta T^r$, where $\\theta$ is an arbitrary factor which does not change under the transformation. Alternatively, show that the equations $T^{r} dx^{s}-T^{s} x^{r} = 0$ remain true when we transform the coordinates.)\n\n\\end{tcolorbox}\nBe $T^{q}$ a contravariant vector.\n\\begin{align}\nT^{,q}=T^{r} \\pdv{x^{,q}}{x^r}\\quad\\text{(by definition)}\n\\end{align}\nBe  $\\theta$ a small infinitesimal factor invariant for a coordinate transformation,  define \\\\\n\\begin{align}\n\\ dx^{r} = \\theta T^{r} \\\\\n\\end{align}\nthen\n\\begin{align}\n\\dv{x^r}{x^s} = \\frac{\\theta T^r}{\\theta T^s}\\\\\n\\Leftrightarrow T^s dx^r - T^r dx^s = 0\n\\end{align}\nAlternatively, multiply (5) with $\\partial_{x^r}{x^{,q}}$, then\n\\begin{align}\n\\pdv{x^{,q}}{x^r} dx^r T^s   -  \\pdv{x^{,q}}{x^r}dx^s T^r &= 0\\\\\n\\Leftrightarrow \\pdv{x^{,q}}{x^r} dx^r T^s   -  dx^s T^{,q} &= 0 \\quad \\text{(use (1) in the second term)}\\\\\n\\Leftrightarrow dx^{,q} T^s   -  dx^s T^{,q} &= 0 \\\\\n\\end{align}\nMultiply (8) with $\\partial_{x^s}{x^{,p}}$, then\n\\begin{align}\n\\ &dx^{,q} T^s \\partial_{x^s}{x^{,p}}  -  dx^s T^{,q}\\partial_{x^s}{x^{,p}} = 0 \\\\\n\\Leftrightarrow \\quad &T^{,p} dx^q   -   T^{,q} dx^{,p} = 0 \\quad \\text{(use (1) in the first term)}\n\\end{align}\nand thus \n$$\\dv{x^{,q}}{x^{,p}} = \\frac{T^{,q}}{T^{,p}}$$\n\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\n\\section{p12-exercise}\n\n\\begin{tcolorbox}\nWrite down the equation of transformation, analogous to 1.305, of a contravariant tensor of the third order. Solve the equation so as to express the unprimed components in terms of the primed components.\n\n\\end{tcolorbox}\nBe \n\\begin{align}\nT^{,uvw}=T^{rst} \\pdv{x^{,u}}{x^r}\\pdv{x^{,v}}{x^s}\\pdv{x^{,w}}{x^t}\\quad\\text{(by definition)}\n\\end{align}\na contravariant vector.\\\\\nMultiply (1) by $\\pdv{x^{n}}{x^{,u}}$\n\\begin{align}\n\\ T^{,uvw}\\pdv{x^{n}}{x^{,u}}&= T^{rst} \\pdv{x^{,u}}{x^r}\\pdv{x^{n}}{x^{,u}}\\pdv{x^{,v}}{x^s}\\pdv{x^{,w}}{x^t}\\\\\n\\Leftrightarrow  T^{,uvw}\\pdv{x^{n}}{x^{,u}}&= T^{rst} \\delta^{n}_{r}\\pdv{x^{,v}}{x^s}\\pdv{x^{,w}}{x^t}\\\\\n\\Leftrightarrow  T^{,uvw}\\pdv{x^{n}}{x^{,u}}&= T^{nst} \\pdv{x^{,v}}{x^s}\\pdv{x^{,w}}{x^t}\n\\end{align}\nMultiply (4) by $\\pdv{x^{m}}{x^{,v}}$\n\\begin{align}\n\\ T^{,uvw}\\pdv{x^{n}}{x^{,u}}\\pdv{x^{m}}{x^{,v}} &= T^{nst} \\pdv{x^{,v}}{x^s}\\pdv{x^{m}}{x^{,v}}\\pdv{x^{,w}}{x^t}\\\\\n\\Leftrightarrow  \\ T^{,uvw}\\pdv{x^{n}}{x^{,u}}\\pdv{x^{m}}{x^{,v}} &= T^{nst} \\delta_{s}^{m}\\pdv{x^{,w}}{x^t}\\\\\n\\Leftrightarrow  \\ T^{,uvw}\\pdv{x^{n}}{x^{,u}}\\pdv{x^{m}}{x^{,v}} &= T^{nmt} \\pdv{x^{,w}}{x^t}\n\\end{align}\nMultiply (7) by $\\pdv{x^{p}}{x^{,w}}$\n\\begin{align}\n\\ T^{,uvw}\\pdv{x^{n}}{x^{,u}}\\pdv{x^{m}}{x^{,v}}\\pdv{x^{p}}{x^{,w}} &= T^{nmt} \\pdv{x^{,w}}{x^t}\\pdv{x^{p}}{x^{,w}}\\\\\n\\Leftrightarrow \\ T^{,uvw}\\pdv{x^{n}}{x^{,u}}\\pdv{x^{m}}{x^{,v}}\\pdv{x^{p}}{x^{,w}} &= T^{nmt} \\delta^{p}_{t}\\\\\n\\Leftrightarrow  \\ T^{,uvw}\\pdv{x^{n}}{x^{,u}}\\pdv{x^{m}}{x^{,v}}\\pdv{x^{p}}{x^{,w}} &= T^{nmp} \n\\end{align}\nGiving\n$$T^{nmp} =  T^{,uvw}\\pdv{x^{n}}{x^{,u}}\\pdv{x^{m}}{x^{,v}}\\pdv{x^{p}}{x^{,w}} $$\n\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p14-exercise}\n\n\\begin{tcolorbox}\nFor a transformation from on set of rectangular Cartesian coordinates to another in Euclidean 3-space, show that the law of transformation of a contravariant vector is precisely the same as that of a covariant vector. Can this statements be extended to cover tensor of higher orders?\n\\end{tcolorbox}\nWe have to prove that, given that, $$T^{,i}= T^{j} \\pdv{x^{,i}}{x^j} \\quad T^{,}_{i}= T_{j} \\pdv{x^{j}}{x^{,i}}$$ that also\n\\begin{align}\n\\ T^{,i}= T^{j} \\pdv{x^{j}}{x^{,i}} \\quad T^{,}_{i}&= T_{j}\\pdv{x^{,i}}{x^j} \\\\\n\\Leftrightarrow \\pdv{x^{j}}{x^{,i}} &= \\pdv{x^{,i}}{x^j} \n\\end{align}\nBe\n\\begin{align}\n\\hat{e^{,i}} = g^i_k\\hat{e^{k}}\\quad\\text{and } \\hat{e^{i}} = h^i_k\\hat{e^{,k}}\n\\end{align}\nthe transformation rules from one set of (rectangular Cartesian) basis vectors to another set of  (rectangular Cartesian) basis vectors.\nThen,\n\\begin{align}\n\\langle \\hat{e^{,i}},\\hat{e^{,j}} \\rangle = \\langle g^i_k\\hat{e^{k}},g^j_k\\hat{e^{k}} \\rangle &\\text{ and } \\langle \\hat{e^{i}},\\hat{e^{j}} \\rangle = \\langle h^i_k\\hat{e^{,k}},h^j_k\\hat{e^{,k}} \\rangle\\\\\n\\Leftrightarrow \\delta^p_j = g^p_k g^j_k &\\text{ and } \\delta^p_j = h^p_k h^j_k \\\\\n\\end{align}\nBe $\\vec{v}$ a random vector in the Euclidean space,\n\\begin{align}\n\\vec{v} = x^j\\hat{e^{j}} = x^{,j}\\hat{e^{,j}}\n\\end{align}\nthen\n\\begin{align}\n\\text{(3) } \\Rightarrow x^j\\hat{e^{j}} = x^{j}h^j_k\\hat{e^{,k}}&\\text{ and }x^{,j}\\hat{e^{,j}} = x^{,j}g^j_k\\hat{e^{k}}\\\\\n\\Rightarrow x^{,j} = x^{m}h^m_j  &\\text{ and }x^m = x^{,j}g^j_m\\\\\n\\Rightarrow x^{,j} = x^{,i}g^i_m h^m_j&\\text{ and } x^m = x^{k}h^k_j g^j_m \\\\\n\\Rightarrow \\delta^p_j =g^p_k h^k_j &\\text{ and } \\delta^p_j =g^k_j h^p_k\\\\\n\\text{(5) } \\Rightarrow g^p_k g^j_k=g^p_k h^k_j &\\text{ and } h^p_k h^j_k=g^k_j h^p_k\\\\\n \\Rightarrow g^j_k =  h^k_j &\\text{ and }h^j_k =  g^k_j\n\\end{align}\nFrom (9)\n\\begin{align}\n\\ x^{j} = x^{,m} g^m_j &\\text{ and } x^{,k} = x^{n} h^n_k\\\\\n\\Rightarrow \\pdv{x^{,k}}{x^j} = \\pdv{x^{n}}{x^j} h^n_k  &\\text{ and } \\pdv{x^{j}}{x^{,k}} = \\pdv{x^{,m}}{x^{,k}}g^m_j\\\\\n\\Leftrightarrow \\pdv{x^{,k}}{x^j} = \\delta^n_j h^n_k  &\\text{ and } \\pdv{x^{j}}{x^{,k}} = \\delta^m_k g^m_j\\\\\n\\Leftrightarrow \\pdv{x^{,k}}{x^j} = h^j_k  &\\text{ and } \\pdv{x^{j}}{x^{,k}} = g^k_j\\\\\n\\text{(13) }\\Rightarrow \\pdv{x^{,k}}{x^j} &= \\pdv{x^{j}}{x^{,k}}\n\\end{align}\nSo (13) matches (2), proving the assertion.\\\\\\\\\nCan this statements be extended to cover tensor of higher orders?\nConsider\n$$T^{,i,j,\\dots ,n}= T^{r,s,\\dots w} \\pdv{x^{,i}}{x^{r}}\\pdv{x^{,j}}{x^{s}}\\dots \\pdv{x^{,n}}{x^{w}} \\text{ and } T^{r,s,\\dots w}= T^{,i,j,\\dots ,n} \\pdv{x^{r}}{x^{,i}}\\pdv{x^{s}}{x^{,j}}\\dots \\pdv{x^{w}}{x^{,n}}$$\nUsing the same reasoning as in (1) to (2) we need\n$$\\pdv{x^{,i}}{x^{r}}\\pdv{x^{,j}}{x^{s}}\\dots \\pdv{x^{,n}}{x^{w}} =\\pdv{x^{r}}{x^{,i}}\\pdv{x^{s}}{x^{,j}}\\dots \\pdv{x^{w}}{x^{,n}}$$\nAs the conclusion (18) is independent of the order of the tensor, it is obvious that the above equality yields. Hence, the answer is YES.\n\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p16-exercise}\n\n\\begin{tcolorbox}\nIn a space of 4 dimensions, the tensor $A_{rst}$ is skew-symmetric in the last pair of suffixes. Show that only 24 of the 64 components may be chosen arbitrarily. If the further condition\n$A_{rst} + A_{str}+A_{trs} =0$\nis imposed, show that that only 20 components may be chosen arbitrarily.\n\n\\end{tcolorbox}\nWe have, as A is skew-symmetric in the last pair of suffixes\n$$A_{rst} = -A_{rts}  \\Rightarrow s=t \\text{: } A_{rst} = 0 $$\nSo, for each r (4 possible choices as N = 4) we have 4x4/2 - 4 = 6 degrees of freedom. [we have the term 4x4/2  as the tensor is (skew-)symmetric, e.g. once we choose element $a_{12}$, then $a_{21}$ is also known. The term -4 takes into account the diagonal element which are 0 and thus cannot be chosen.]\\\\\nSo, we have 4x6 = 24 degrees of freedom.\\\\\nWhat about the supplementary constraint $A_{rst} + A_{str}+A_{trs} =0 $       :\\\\\nConsider the two possible excluding cases:\\\\\n\ni) $r=s\\neq t \\text{ (}\\Leftrightarrow r=t\\neq s \\text{)}$\\\\\nThis case gives - without the additional constraint (1) -  4x(4x3/2-4) = 8 degrees of freedom.\nDoes the constraint (1) reduces this degree of freedom?\\\\\nWe have, \n\\begin{align}\n\\ A_{rst} + A_{str}+A_{trs} =0\\\\\n\\Rightarrow \\underbrace{A_{rrt} + A_{rtr}}_\\text{= 0 (non-diagonal terms)} + \\underbrace{A_{trr}}_\\text{= 0 (diagonal terms)} =0\n\\end{align}\nSo, no additional constraints are added by (1) to the restriction i) and the DOF remains 8.\\\\\n\nii) $t \\neq r\\neq s\\neq t$\\\\\nThis case means that we have to choose a set of 3 elements out of 4 elements without repetition. This a \\textit{variation} of 3 elements out of 4.\n$$V^n_{k} = \\frac{n!}{(n-k)!} \\text{ giving } V^4_{3} = \\frac{4!}{(4-3)!} = 24 $$\nThe constraint (1) gives us 24 equations but as  $A_{rst} = -A_{rts}$ only 12 equations have to be considered. So, with the  additional constraints the DOF becomes 24-12 = 12.\\\\\nAs i) and ii) are independent and excluding events we can add the DOF of both events and we get 8+12 = 20 DOF.\n\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p16-exercise}\n\n\\begin{tcolorbox}\nIf $A^{rs}$ is skew-symmetric and $B_{rs}$ is symmetric, prove that $A^{rs}B_{rs} = 0$. Hence show that the quadratic form $a_{ij}x^ix^j$ is unchanged if $a_{ij}$ is replaced by its symmetric part.\n\\end{tcolorbox}\nWe can split the summation $A^{rs}B_{rs}$ in three subsummations:\n\\begin{align}\n\\ A^{rs}B_{rs}  = &A^{rs}B_{rs} \\vert_{r=s} \\\\\n\\ + &A^{rs}B_{rs}\\vert_{r>s} \\\\\n\\ + &A^{rs}B_{rs}\\vert_{r<s}\n\\end{align}\nWe have:\\\\\n(1) = 0 as $A^{kk} = 0$ (skew-symmetric)\\\\\n(2)+(3) = $A^{rs}B_{rs}\\vert_{r>s} \\ + A^{rs}B_{rs}\\vert_{r<s}$\\\\\nAs $A^{rs} = -A^{sr}$ and $B^{rs} = B^{sr}$ we can write (2)+(3) as :\n$$A^{rs}B_{rs}\\vert_{r>s} \\ + (-A^{sr})B_{sr}\\vert_{r>s} = 0$$\nSo, $A^{rs}B_{rs} = 0$\\\\\\\\\nConsider the quadratic form $\\phi = a_{ij}x^ix^j$\\\\\nBe $A_{ij} = (a_{ij})$ and $B_{ij} = (x^ix^j)$, then it is obvious that $B_{ij}$ is symmetric and that $C_{ij} = -A_{ij}$ is the form where $-a_{ij}$ is replaced by its symmetric part (skew-symmetric).\nHence $\\phi = a_{ij}x^ix^j =a_{ij}b^{ij}= 0$ and so is $\\phi = c_{ij}b^{ij}= 0$ \n\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p18-exercise}\n\n\\begin{tcolorbox}\nWhat are the values (in a space of N dimensions) of the folllowing contractions formed from the Kronecker delta?\n$$\\delta^{m}_{m},  \\delta^{m}_{n} \\delta^{n}_{m},  \\delta^{m}_{n} \\delta^{n}_{r} \\delta^{r}_{m}$$\n\\end{tcolorbox}\n\\begin{align}\n\\delta^{m}_{m} = N\\\\\n\\delta^{m}_{n} \\delta^{n}_{m} = \\delta^{m}_{m} = N\\\\\n\\delta^{m}_{n} \\delta^{n}_{r} \\delta^{r}_{m} = \\delta^{m}_{n} \\delta^{n}_{m} = \\delta^{m}_{m} = N\n\\end{align}\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p19-exercise}\n\\begin{tcolorbox}\nIf $X^{r}$, $Y^{r}$ are arbitrary contravariant vectors and $a_{rs}X^{r}Y^{s}$ is an invariant, then $a_{rs}$ are the components of a covariant tensor of the second order. \n\\end{tcolorbox}\nWe have to prove that\n\\begin{align}\n\\ a^{,}_{rs} = a_{ij}\\pdv{x^{i}}{x^{,r}}\\pdv{x^{j}}{x^{,s}} \\text{ or } a^{}_{ij} = a^{,}_{rs}\\pdv{x^{,r}}{x^{i}}\\pdv{x^{,s}}{x^{j}}\n\\end{align}\n$a_{rs}X^{r}Y^{s}$ is an invariant, means\n\\begin{align}\n\\ a^{,}_{rs}X^{,r}Y^{,s} = a_{rs}X^{r}Y^{s}\n\\end{align}\nAs $X^{r}$, $Y^{r}$ are arbitrary contravariant vectors, we have\n\\begin{align}\n\\ X^{,r} = X^{i}\\pdv{x^{,r}}{x^{i}} \\text{   and  } Y^{,s} = Y^{j}\\pdv{x^{,s}}{x^{j}}\n\\end{align}\n(3) in (2) gives\n\\begin{align}\n\\ a^{,}_{rs}X^{i}\\pdv{x^{,r}}{x^{i}}Y^{j}\\pdv{x^{,s}}{x^{j}} = a_{rs}X^{r}Y^{s}\\\\\n\\Leftrightarrow a^{,}_{rs}\\pdv{x^{,r}}{x^{i}}\\pdv{x^{,s}}{x^{j}}X^{i}Y^{j} = a_{ij}X^{i}Y^{j}\\\\\n\\Leftrightarrow (a^{,}_{rs}\\pdv{x^{,r}}{x^{i}}\\pdv{x^{,s}}{x^{j}} - a_{ij})X^{i}Y^{j} = 0\n\\end{align}\nAs $X^{r}$, $Y^{r}$ are arbitrary contravariant vectors, we conclude that \n\\begin{align}\n\\ a^{,}_{rs}\\pdv{x^{,r}}{x^{i}}\\pdv{x^{,s}}{x^{j}} - a_{ij} = 0\\\\\n\\Leftrightarrow a_{ij} =  a^{,}_{rs}\\pdv{x^{,r}}{x^{i}}\\pdv{x^{,s}} {x^{j}}\n\\end{align}\n(8) = (1): OK\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p19-exercise}\n\\begin{tcolorbox}\nIf $X_{rs}$ is an arbitrary covariant tensor of the second order, and $A^{mn}_{r }X_{mn}$ is a covariant vector, then $A^{mn}_{r }$ has the mixed tensor character indicated by the positions of its suffixes \n\\end{tcolorbox}\nWe have to prove that\n\\begin{align}\n\\ A^{,vw}_{r} = A^{mn}_k\\pdv{x^{k}}{x^{,r}}\\pdv{x^{,v}}{x^{m}}\\pdv{x^{,w}}{x^{n}} \n\\end{align}\nWe have\n\\begin{align}\n\\ P_{r} =A^{mn}_{r }X_{mn}\n\\end{align}\nis a covariant vector\n\\begin{align}\n\\Rightarrow P^{,}_{r} =A^{mn}_{k }X_{mn}\\pdv{x^{k}}{x^{,r}}\n\\end{align}\nbut $X_{mn}$ is a covariant tensor\n\\begin{align}\n\\Rightarrow X_{mn} = X^{,}_{ps}\\pdv{x^{,p}}{x^{m}}\\pdv{x^{,s}}{x^{n}}\n\\end{align}\nSo (4) in (3) gives\n\\begin{align}\n\\ P^{,}_{r} =A^{mn}_{k }X^{,}_{ps}\\pdv{x^{,p}}{x^{m}}\\pdv{x^{,s}}{x^{n}}\\pdv{x^{k}}{x^{,r}}\\\\\n\\Leftrightarrow P^{,}_{r} = \\underbrace{A^{mn}_{k }\\pdv{x^{,p}}{x^{m}}\\pdv{x^{,s}}{x^{n}}\\pdv{x^{k}}{x^{,r}}}_\\text{(*)}X^{,}_{ps}\n\\end{align}\nPutting (*) as $ A^{,ps}_{r }= A^{mn}_{k }\\pdv{x^{,p}}{x^{m}}\\pdv{x^{,s}}{x^{n}}\\pdv{x^{k}}{x^{,r}}$ we see that (6) has the form (2) and that $A^{,ps}_{r }$ obeys the rule of a mixed tensor (1).\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p21-exercise}\n\\begin{tcolorbox}\nIf $A_{rs}$ is a skew-symmetric covariant tensor, prove that $B_{rst}$ defined as \n$$B_{rst} = \\partial_{r}{A_{st}} + \\partial_{s}{A_{tr}} +\\partial_{t}{A_{rs}} $$ is a covariant tensor, and that it is skew-symmetric in all pairs of suffixes.\n\\end{tcolorbox}\n\nWe have $A_{rs}$ is a covariant tensor\n\\begin{align}\n\\ A_{ij} &= A_{\\alpha\\beta}\\pdv{x^{\\alpha}}{x^{i}}\\pdv{x^{\\beta}}{x^{j}}\\\\\n\\Rightarrow B_{rst} &= \\partial_{r}{(A_{\\alpha\\beta}\\pdv{x^{\\alpha}}{x^{s}}\\pdv{x^{\\beta}}{x^{t}})} + \\partial_{s}{(A_{\\alpha\\beta}\\pdv{x^{\\alpha}}{x^{t}}\\pdv{x^{\\beta}}{x^{r}})} +\\partial_{t}{(A_{\\alpha\\beta}\\pdv{x^{\\alpha}}{x^{r}}\\pdv{x^{\\beta}}{x^{s}})}\n\\end{align}\nNote that\n\\begin{align}\n\\partial_{k}{(A_{\\alpha\\beta}\\pdv{x^{\\alpha}}{x^{s}}\\pdv{x^{\\beta}}{x^{t}})} = \n\\partial_{k}{(A_{\\alpha\\beta})}\\pdv{x^{\\alpha}}{x^{s}}\\pdv{x^{\\beta}}{x^{t}}+\n\\ A_{\\alpha\\beta}\\partial_{k}{(\\pdv{x^{\\alpha}}{x^{s}})}\\pdv{x^{\\beta}}{x^{t}}+\n\\ A_{\\alpha\\beta}\\pdv{x^{\\alpha}}{x^{s}} \\partial_{k}{(\\pdv{x^{\\beta}}{x^{t}})}\\\\\n\\end{align}\nso, \n\\begin{align}\n\\begin{array}{r c l}\n\\ B_{rst} = \\partial_{r}{A_{\\alpha\\beta}}\\pdv{x^{\\alpha}}{x^{s}}\\pdv{x^{\\beta}}{x^{t}}+ \\underbrace{A_{\\alpha\\beta}\\partial_{r}{\\pdv{x^{\\alpha}}{x^{s}}}\\pdv{x^{\\beta}}{x^{t}}}_\\text{*} +\\underbrace{A_{\\alpha\\beta}\\pdv{x^{\\alpha}}{x^{s}}\\partial_{r}{\\pdv{x^{\\beta}}{x^{t}}}}_\\text{**}\\\\ +\n\\partial_{s}{A_{\\alpha\\beta}}\\pdv{x^{\\alpha}}{x^{t}}\\pdv{x^{\\beta}}{x^{r}}+\\underbrace{A_{\\alpha\\beta}\\partial_{s}{\\pdv{x^{\\alpha}}{x^{t}}}\\pdv{x^{\\beta}}{x^{r}}}_\\text{***}+\\underbrace{A_{\\alpha\\beta}\\pdv{x^{\\alpha}}{x^{t}}\\partial_{s}{\\pdv{x^{\\beta}}{x^{r}}}}_\\text{*}\\\\+\n\\partial_{t}{A_{\\alpha\\beta}}\\pdv{x^{\\alpha}}{x^{r}}\\pdv{x^{\\beta}}{x^{s}}+A_{\\alpha\\beta}\\underbrace{\\partial_{t}{\\pdv{x^{\\alpha}}{x^{r}}}\\pdv{x^{\\beta}}{x^{s}}}_\\text{**}+\\underbrace{A_{\\alpha\\beta}\\pdv{x^{\\alpha}}{x^{r}}\\partial_{t}{\\pdv{x^{\\beta}}{x^{s}}}}_\\text{***}\n\\end{array}\n\\end{align}\nIn (5) consider the two terms with (*) \n\\begin{align}\n\\ T &= A_{\\alpha\\beta}\\partial_{r}{\\pdv{x^{\\alpha}}{x^{s}}}\\pdv{x^{\\beta}}{x^{t}}+ A_{\\alpha\\beta}\\pdv{x^{\\alpha}}{x^{t}}\\partial_{s}{\\pdv{x^{\\beta}}{x^{r}}}\\\\\n& = A_{\\alpha\\beta}\\pdv{x^{\\alpha}}{x^{s}}{x^{r}}\\pdv{x^{\\beta}}{x^{t}}+ A_{\\alpha\\beta}\\pdv{x^{\\alpha}}{x^{t}}\\pdv{x^{\\beta}}{x^{r}}{x^{s}}\\\\\n& = A_{\\alpha\\beta}\\pdv{x^{\\alpha}}{x^{s}}{x^{r}}\\pdv{x^{\\beta}}{x^{t}}+ A_{\\beta\\alpha}\\pdv{x^{\\beta}}{x^{t}}\\pdv{x^{\\alpha}}{x^{r}}{x^{s}} \\text{ (by renaming dummy variables)}\n\\end{align}\nAs $A_{ij} = - A_{ji}$ (skew-symmetric tensor), we get $T=0$. The same yields for the (**) and (***) terms. So, $B_{rst}$ reduces to\n\\begin{align}\n\\ B_{rst} = \\partial_{r}{A_{\\alpha\\beta}}\\pdv{x^{\\alpha}}{x^{s}}\\pdv{x^{\\beta}}{x^{t}}+ \n\\partial_{s}{A_{\\alpha\\beta}}\\pdv{x^{\\alpha}}{x^{t}}\\pdv{x^{\\beta}}{x^{r}}+\n\\partial_{t}{A_{\\alpha\\beta}}\\pdv{x^{\\alpha}}{x^{r}}\\pdv{x^{\\beta}}{x^{s}}\\\\\n\\Leftrightarrow \\ B_{rst} = \\pdv{A_{\\alpha\\beta}}{x^{\\gamma}}\\pdv{x^{\\gamma}}{x^{r}}\\pdv{x^{\\alpha}}{x^{s}}\\pdv{x^{\\beta}}{x^{t}}+ \n\\pdv{A_{\\alpha\\beta}}{x^{\\gamma}}\\pdv{x^{\\gamma}}{x^{s}}\\pdv{x^{\\alpha}}{x^{t}}\\pdv{x^{\\beta}}{x^{r}}+\n\\pdv{A_{\\alpha\\beta}}{x^{\\gamma}}\\pdv{x^{\\gamma}}{x^{t}}\\pdv{x^{\\alpha}}{x^{r}}\\pdv{x^{\\beta}}{x^{s}}\n\\end{align}\nBy adequate renaming of the dummy variable in the 3 terms:\n$$  \\left[ {\\begin{array}{c}\n    1^{st} term \\\\\n    2^{nd} term  \\\\\n    3^{rd} term  \n  \\end{array} } \\right]\n\\longrightarrow\n  \\left[ {\\begin{array}{ccc}\n    \\gamma \\to \\alpha & \\alpha \\to \\beta & \\beta \\to \\gamma \\\\\n    \\beta \\to \\alpha & \\gamma \\to \\beta & \\alpha \\to \\gamma \\\\\n    \\alpha \\to \\alpha & \\beta \\to \\beta & \\gamma \\to \\gamma \n  \\end{array} } \\right]\n$$\nwe get\n\\begin{align}\n\\ B_{rst} = (\\pdv{A_{\\beta\\gamma}}{x^{\\alpha}}+\\pdv{A_{\\gamma\\alpha}}{x^{\\beta}}+\\pdv{A_{\\alpha\\beta}}{x^{\\gamma}})\\pdv{x^{\\alpha}}{x^{r}}\\pdv{x^{\\beta}}{x^{s}}\\pdv{x^{\\gamma}}{x^{t}}\\\\\n\\Leftrightarrow  B_{rst} = (\\underbrace{\\partial_{\\alpha}{A_{\\beta\\gamma}}+\\partial_{\\beta}{A_{\\gamma\\alpha}}+\\partial_{\\gamma}{A_{\\alpha\\beta}}}_\\text{(****)})\\pdv{x^{\\alpha}}{x^{r}}\\pdv{x^{\\beta}}{x^{s}}\\pdv{x^{\\gamma}}{x^{t}}\n\\end{align}\nThe expression (****) has exactly the required form $B_{rst} = \\partial_{r}{A_{st}} + \\partial_{s}{A_{tr}} +\\partial_{t}{A_{rs}} $ and is transformed (12) according the rules of a covariant tensor.\\\\\nLet's prove now that it is skew-symmetric in all pairs of suffixes.\nWe have to consider the following permutations\n$$  \\left[ {\\begin{array}{c}\n    rst \\\\\n    rts\\\\\n    srt  \\\\\n    str\\\\  \n    trs \\\\\n    tsr\n  \\end{array} } \\right]$$\n  \nE.g. $srt$\n\\begin{align}\n\\ B_{rts} &= \\partial_{r}{A_{ts}}+\\partial_{t}{A_{sr}}+\\partial_{s}{A_{rt}}\\\\\n&= -\\partial_{r}{A_{st}}-\\partial_{t}{A_{rs}}-\\partial_{s}{A_{tr}}\\\\\n&= - B_{rst}\n\\end{align}\nThe same calculations can be done for the other permutations.\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p23-exercise 1.}\n\\begin{tcolorbox}\nIn a $V_{4}$ there are two 2-spaces with equations\n$$x^r = f^r(u^1,u^2)\\text{, }x^r = g^r(u^3,u^4) $$\nProve that if these 2-spaces have a curve of intersection, then the determinal equation\n$$\\left|\\pdv{x^r}{u^s}\\right| = 0$$\nis satisfied along the curve.\n\\end{tcolorbox}\nHaving a curve means that one of the parameters $u^i$ can be freely chosen while the other 3 are determined by the chosen parameter.\\\\\nWe have,\n\\begin{align}\n\\left|\\pdv{x^r}{u^s}\\right| = \\left| {\\begin{array}{cccc}\n    \\pdv{x^1}{u^1} & \\pdv{x^1}{u^2} & \\pdv{x^1}{u^3} & \\pdv{x^1}{u^4}\\\\\n    \\vdots & \\vdots & \\vdots & \\vdots\\\\\n    \\pdv{x^4}{u^1} & \\pdv{x^4}{u^2} & \\pdv{x^4}{u^3} & \\pdv{x^4}{u^4}\\\\\n  \\end{array} } \\right|\n\\end{align}\nSuppose we choose $u^4$ as parameter.\nThis means $u^i = \\phi^i(u^4)$ for i=1,2,3 and thus we can write\n\\begin{align}\n\\pdv{x^i}{u^4} &= \\pdv{x^i}{u^j}\\dv{\\phi^j}{u^4}+ \\pdv{x^i}{u^4}\\quad\\text{ with j=1,2,3} \\quad\\text{  i = 1,2,3,4}\\\\\n&\\Rightarrow \\pdv{x^i}{u^j}\\dv{\\phi^j}{u^4} = 0\n\\end{align}\nThis means that in (1) the three first columns a not linearly independent and thus have   $\\left|\\pdv{x^r}{u^s}\\right| = 0$\n\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p23-exercise 2.}\n\\begin{tcolorbox}\nIn Euclidean space of three dimensions, write down the equations of transformation between rectangular Cartesian coordinates x, y, z and spherical polar coordinates $r$,$\\theta$,$\\phi$.\\\\\nFind the Jacobian of the transformation. Where is it zero or infinite?\n\\end{tcolorbox}\n\n\\begin{figure}[h]\n\\centering\n\\begin{minipage}[t]{.6\\textwidth}\n%\\centering\n\\vspace{0pt}\n\\input{D:/MathLatex/images/fig_p23_117_a.tex}\n\\end{minipage}\\hfill\n\\begin{minipage}[t]{0.3\\textwidth}\n%\\centering\n\\vspace{50pt}\n$\\left\\{ \\begin{array}{c}\n    x= r\\sin \\theta \\cos \\phi \\\\\n     y= r\\sin \\theta\\sin \\phi \\\\\n      z= r\\cos\\theta \n  \\end{array} \\right.$\n\\end{minipage}\n\\caption{Spherical coordinate system}\n\\label{fig:fig_p23_117_a}\n\\end{figure}\nPartial differentiating of (x,y,z) with respect to (r,$\\theta$,$\\phi$) gives the Jacobian\n\\begin{align}\n\\ J&=\n\\left| {\\begin{array}{ccc}\n    \\sin \\theta \\cos \\phi & r\\cos \\theta\\cos \\phi  & -r\\sin \\theta \\sin \\phi\\\\\n    \\sin \\theta \\sin \\phi & r\\cos \\theta\\sin \\phi  & r\\sin\\theta \\cos\\phi\\\\\n    \\cos\\theta  & -r\\sin \\theta &0\\\\\n  \\end{array} } \\right|\n  \\\\\n\\ &= r^2\\sin \\theta (\\sin^2 \\theta\\cos^2 \\phi + \\sin^2 \\theta \\sin^2 \\phi + \\cos^2\\theta \\cos^2\\phi + \\cos^2\\theta\\sin^2\\phi)\\\\\n\\  &= r^2\\sin \\theta \n\\end{align}\nJ=0: for $r=0$ or $\\theta = 0_{\\ r \\epsilon (-\\infty, +\\infty)}$ and $J\\rightarrow \\pm\\infty$ or $\\mp\\infty$ for $r\\rightarrow \\pm\\infty|_{\\theta\\neq 0}$. But what about the case $r\\rightarrow \\pm\\infty|_{\\theta\\rightarrow 0}$? This case is not determined as long as no path is chosen in the $(r,\\theta)$ configuration space.\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p23-exercise 3.}\n\\begin{tcolorbox}\nIf $X, Y,Z$ are the components of a contravariant vector for rectangular Cartesian coordinates in Euclidean 3-space, find it's components for spherical polar coordinates.\n\\end{tcolorbox}\n\nBe $x^{\\alpha}$ the components of a contravariant vector in spherical polar coordinates and $x^{i}$ it's components in rectangular Cartesian coordinates. As we have  \n\\begin{align}\n \\begin{array}{c}\n    \\ x^{\\rho} = \\sqrt{x^{j}x^{j}}\\\\\n    \\ x^{\\theta} = \\atan{\\frac{x^{2}}{x^{1}}}\\\\\n    \\ x^{\\phi} = \\asin{\\frac{x^{3}}{\\sqrt{{x^{j}x^{j}}}}}\\\\\n  \\end{array} \\quad \\text{ and } \\quad A^{\\alpha} = A^{i}\\pdv{x^{\\alpha}}{x^{i}}\n  \\end{align}\n\\begin{align}\n\\Rightarrow \\left[A^{\\alpha} \\right]=  \\left[A^{i}\\pdv{x^{\\alpha}}{x^{i}}\\right] = \\left[ {\\begin{array}{ccc}\n    \\ \\frac{x^1} { \\sqrt{x^{j}x^{j}}} & \\frac{x^2} { \\sqrt{x^{j}x^{j}}} & \\frac{x^3} { \\sqrt{x^{j}x^{j}}}\\\\\\\\\n    -\\frac{x^2} { (x^1)^2+(x^2)^2} & \\frac{x^1} { (x^1)^2+(x^2)^2}  & 0 \\\\\\\\\n    -\\frac{x^3x^1} { (x^{j}x^{j})\\sqrt{(x^1)^2+(x^2)^2}} & -\\frac{x^3x^2} { (x^{j}x^{j})\\sqrt{(x^1)^2+(x^2)^2}}  & \\frac{\\sqrt{(x^1)^2+(x^2)^2}} { (x^{j}x^{j})} \\\\\n  \\end{array} } \\right]\\left[ {\\begin{array}{c}\n    \\ A^{1}\\\\\\\\\n    \\ A^{2}\\\\\\\\\n    \\ A^{3}\\\\\\\\\n  \\end{array} } \\right]\n\\end{align}\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p23-exercise 4.}\n\\begin{tcolorbox}\nIn a space of three dimensions, how many different expressions are represented by the product $A^{m}_{np} B^{pq}_{rs}C^{s}_{tu}$? How many terms occur in each such expression, when written out explicitly?\n\\end{tcolorbox}\n\nAs we have $V_{3}$ and considering that in $A^{m}_{np} B^{pq}_{rs}C^{s}_{tu}$ the six indices m, n, q, r, t, u are not dummy indices, we get $3^{6}$ different expressions (first choose m: you have three choices, then n: also three choices giving 3x3 possibilities, etc for q, r, t, u).\\\\\nFor the second question, as in $A^{m}_{np} B^{pq}_{rs}$ there is only summation on over index (p) we get three terms for this part. As the summation with $A^{m}_{np} B^{pq}_{rs}$ and $C^{s}_{tu}$ occurs only on one index also (s) we get 3x3 terms in the expression.\n\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p23-exercise 5.}\n\\begin{tcolorbox}\nIf A  is an invariant in $V_{n}$, are the second derivatives $\\pdv{A}{x^{r}}{x^{s}}$ the components of a tensor?\n\\end{tcolorbox}\n\nAs A is invariant (note: different alphabets in the indices indicates different coordinate systems):\n\\begin{align}\n\\ A(x^{\\rho}) = A(x^{i})\\\\\n\\Rightarrow \\pdv{A(x^{\\rho})}{x^{i}} = \\pdv{A(x^{j})}{x^{i}}\n\\end{align}\nTo simplify the notation, we put $A(x^{\\rho}) = A^{,}$ and $A(x^{j}) = A^{,}$ then (2) can be written as\n\\begin{align}\n\\pdv{A^{,}}{x^{\\rho}}\\pdv{x^{\\rho}}{x^{i}} = \\pdv{A}{x^{i}}\n \\end{align}\n Conclusion: $\\pdv{A}{x^{i}}$ is a covariant tensor. \\\\\\\\Consider now $\\pdv{A}{x^{i}} = \\pdv{A^{,}}{x^{\\rho}}\\pdv{x^{\\rho}}{x^{i}}$. Then,\n\\begin{align}\n\\pdv{A}{x^{i}}{x^{j}} &= \\pdv{A^{,}}{x^{\\rho}}{x^{j}}\\pdv{x^{\\rho}}{x^{i}}+ \\pdv{A^{,}}{x^{\\rho}}\\pdv{x^{\\rho}}{x^{i}}{x^{j}}\\\\\n\\Leftrightarrow \\pdv{A}{x^{i}}{x^{j}} &= \\pdv{A^{,}}{x^{\\rho}}{x^{\\gamma}}\\pdv{x^{\\gamma}}{x^{j}}\\pdv{x^{\\rho}}{x^{i}}+ \\pdv{A^{,}}{x^{\\rho}}\\pdv{x^{\\rho}}{x^{i}}{x^{j}}\n\\end{align}\nThe first term on the right side, behaves as covariant tensor but the presence of the second term makes that generally, $\\pdv{A}{x^{i}}{x^{j}}$ has not a tensor character. This is only when $\\pdv{A^{,}}{x^{\\rho}}\\pdv{x^{\\rho}}{x^{i}}{x^{j}}=0$, which means that $x^{\\rho}, x^{i}$ are a linear map of each other.\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p23-exercise 6.}\n\\begin{tcolorbox}\nSuppose that in $V_2$ the components of a contravariant tensor field $T^{mn}$ in a coordinate system $x^r$ are \n$$T^{11}=1 \\quad T^{12}=0$$\n$$T^{21}=1 \\quad T^{22}=0$$\nFind the components $T^{,mn}$ in a coordinate system $x^{,r}$, where\n$$x^{,1} =(x^{1})^2\\quad x^{,2} = (x^{2})^2$$\nWrite down the values of these components in particular at the point $x^1 = 1, x^2 0 =$.\n\\end{tcolorbox}\nAs we have a contravariant tensor field :\n\\begin{align}\n\\ T^{,mn} =  T^{ij}\\pdv{x^{,m}}{x^{i}}\\pdv{x^{,n}}{x^{j}}\\\\\n \\begin{array}{ccc}\n   \\quad \\quad \\quad \\quad  x^{,1} =(x^{1})^2  \\Rightarrow & \\pdv{x^{,1}}{x^{1}} = 2x^{1} & \\pdv{x^{,1}}{x^{2}} = 0\\\\\n\\quad \\quad \\quad \\quad x^{,2} =(x^{2})^2  \\Rightarrow & \\pdv{x^{,2}}{x^{1}} = 0 & \\pdv{x^{,2}}{x^{2}} = 2x^{2}\\\\\n  \\end{array}\\\\\n  \\end{align}\n  \\begin{align}\n  &\\Rightarrow T^{,11} = 4(x^{1})^2 + 4(x^{2})^2 \\\\\n  &\\Rightarrow T^{,12} = T^{,21}=0 \\\\\n  &\\Rightarrow T^{,22} = 4(x^{1})^2 + 4(x^{2})^2\n  \\end{align}\\\\\\\\\n  The components in  at the point $x^1 = 1, x^2 = 0$ are\n  $$T^{,}(1,0) = \\left[{\\begin{array}{cc} 4 & 0 \\\\\n    0 & 4 \\\\ \n    \\end{array} } \\right]$$\n    \n    $$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p24-exercise 7.}\n\\begin{tcolorbox}\nGiven that if $T_{mnrs}$ is a covariant tensor, and \n$$ T_{mnrs}+T_{mnsr} = 0$$ in a coordinate system $x^{p}$, establish directly that $$ T^{,}_{mnrs}+T^{,}_{mnsr} = 0$$ in any other coordinate system $x{,q}$.\n\\end{tcolorbox}\nNote: in the following, different alphabets in the indices indicates different coordinate systems.\nAs we $T_{mnrs}$ is a covariant tensor :\n\\begin{align}\n\\ T_{\\alpha\\beta\\gamma\\delta} &=  T_{mnrs}\\pdv{x^{m}}{x^{\\alpha}}\\pdv{x^{n}}{x^{\\beta}}\\pdv{x^{r}}{x^{\\gamma}}\\pdv{x^{s}}{x^{\\delta}}\\\\\n\\Rightarrow T_{\\alpha\\beta\\gamma\\delta}+T_{\\alpha\\beta\\delta\\gamma} &= T_{mnrs}\\pdv{x^{m}}{x^{\\alpha}}\\pdv{x^{n}}{x^{\\beta}}\\pdv{x^{r}}{x^{\\gamma}}\\pdv{x^{s}}{x^{\\delta}}+ T_{mnrs}\\pdv{x^{m}}{x^{\\alpha}}\\pdv{x^{n}}{x^{\\beta}}\\pdv{x^{r}}{x^{\\delta}}\\pdv{x^{s}}{x^{\\gamma}}\n\\end{align}\nNow, swap the dummy indices r and s in the second term on the right and as $T_{mnrs} = - T_{mnsr}$:\n\\begin{align}\n\\ T_{\\alpha\\beta\\gamma\\delta}+T_{\\alpha\\beta\\delta\\gamma} &= T_{mnrs}\\pdv{x^{m}}{x^{\\alpha}}\\pdv{x^{n}}{x^{\\beta}}\\pdv{x^{r}}{x^{\\gamma}}\\pdv{x^{s}}{x^{\\delta}}+ T_{mnsr}\\pdv{x^{m}}{x^{\\alpha}}\\pdv{x^{n}}{x^{\\beta}}\\pdv{x^{s}}{x^{\\delta}}\\pdv{x^{r}}{x^{\\gamma}}\\\\\n&= (T_{mnrs}+ T_{mnsr})\\pdv{x^{m}}{x^{\\alpha}}\\pdv{x^{n}}{x^{\\beta}}\\pdv{x^{s}}{x^{\\delta}}\\pdv{x^{r}}{x^{\\gamma}}\\\\&=0\n\\end{align}\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p24-exercise 8.}\n\\begin{tcolorbox}\nProve that if $A_{r}$ is a covariant vector, then $\\pdv{A_{r}}{x^{s}} - \\pdv{A_{s}}{x^{r}}$ is a skew-symmetric covariant tensor of the second order (use the notation of 1.7).\n\\end{tcolorbox}\nBe $B_{rs} = \\pdv{A_{r}}{x^{s}} - \\pdv{A_{s}}{x^{r}}$.\\\\\ni) $B_{rs}$ is skew-symmetric:\nIt is obvious that:$$-B_{rs} = -\\pdv{A_{r}}{x^{s}} + \\pdv{A_{s}}{x^{r}} = \\pdv{A_{s}}{x^{r}}-\\pdv{A_{r}}{x^{s}}\\equiv B_{sr}$$\nii)  $B_{rs}$ is covariant:\\\\\n\\textit{Note: in the following, different alphabets in the indices indicates different coordinate systems.}\\\\\nLet \n\\begin{align}\n\\ C_{\\alpha\\beta} = (\\partial_sA_r - \\partial_rA_s)X^r_{\\alpha}X^s_{\\beta}. \n\\end{align}\nWe know that $A_i= A_{\\gamma}X^{\\gamma}_i$  as $A_i$ is covariant. Hence,\n\\begin{align}\n\\partial_jA_i &= \\partial_j A_{\\gamma} X^{\\gamma}_i + A_{\\gamma}\\partial_jX^{\\gamma}_i\\\\\n\\ &= \\partial_{\\alpha} A_{\\gamma} X^{\\alpha}_j X^{\\gamma}_i + A_{\\gamma}\\partial_jX^{\\gamma}_i\n\\end{align}\nUsing (3), we compute the first term in (1)\n\\begin{align}\n\\partial_sA_rX^r_{\\alpha}X^s_{\\beta}&=  \\partial_{\\rho} A_{\\gamma} X^{\\rho}_s X^{\\gamma}_rX^r_{\\alpha}X^s_{\\beta}+A_{\\gamma}\\partial_sX^{\\gamma}_rX^r_{\\alpha}X^s_{\\beta}\\\\\n\\ &=  \\partial_{\\rho} A_{\\gamma} X^{\\rho}_{\\beta} X^{\\gamma}_{\\alpha}+A_{\\gamma}\\partial_sX^{\\gamma}_rX^r_{\\alpha}X^s_{\\beta}\\\\\n\\ &=  \\partial_{\\rho} A_{\\gamma} \\delta^{\\rho}_{\\beta} \\delta^{\\gamma}_{\\alpha}+A_{\\gamma}\\partial_sX^{\\gamma}_rX^r_{\\alpha}X^s_{\\beta}\\\\\n\\ &=  \\partial_{\\beta} A_{\\alpha} +A_{\\gamma}\\partial_sX^{\\gamma}_rX^r_{\\alpha}X^s_{\\beta}\n\\end{align}\nIn the same way, we get for the second term in (1)\n\\begin{align}\n\\partial_rA_sX^s_{\\alpha}X^r_{\\beta} &=  \\partial_{\\alpha} A_{\\beta} + A_{\\gamma}\\partial_rX^{\\gamma}_sX^r_{\\alpha}X^s_{\\beta}\n\\end{align}\\\\\nAnd thus,\n\\begin{align}\n\\ C_{\\alpha\\beta} =(\\partial_sA_r - \\partial_rA_s)X^r_{\\alpha}X^s_{\\beta} &=\\partial_{\\beta} A_{\\alpha} +A_{\\gamma}\\partial_sX^{\\gamma}_rX^r_{\\alpha}X^s_{\\beta} - \\partial_{\\alpha} A_{\\beta} - A_{\\gamma}\\partial_rX^{\\gamma}_sX^r_{\\alpha}X^s_{\\beta}\\\\\n\\ \\Rightarrow \\partial_{\\beta} A_{\\alpha}  - \\partial_{\\alpha} A_{\\beta} &=  (\\partial_sA_r - \\partial_rA_s)X^r_{\\alpha}X^s_{\\beta}\n\\end{align}\nSo, i) and (10) proves that $\\pdv{A_{r}}{x^{s}} - \\pdv{A_{s}}{x^{r}}$ is skew-symmetric tensor of the second order.\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p24-exercise 9.}\n\\begin{tcolorbox}\nLet $x^r, \\overline{x}^r, y^r,\\overline{y}^r $ be four systems of coordinates. Examine the tensor character of $\\pdv{x^r}{y^s}$ with respect to the following transformations:\\\\\ni) A transformation $x^r = f^r(\\overline{x}^1,\\dots,\\overline{x}^N)$, with $y^r$ unchanged;\\\\\nii) A transformation $y^r = g^r(\\overline{y}^1,\\dots,\\overline{y}^N)$, with $x^r$ unchanged;\n\\end{tcolorbox}\n\\textit{Note: in the following, different alphabets in the indices indicates different coordinate systems.}\\\\\\\\\n%Be $A(r,s) = \\pdv{x^r}{y^s}$.\\\\\ni) Let's compute the expression $A(\\alpha, \\beta) = \\pdv{x^r}{y^s}\\pdv{x^{\\alpha}}{x^r}\\pdv{x^s}{x^{\\beta }}$. Obviously, the right side is an expression of a (possible) mixed tensor of the second order ($\\pdv{x^r}{y^s}$) under transformation from the (r) coordinate system to the ($\\alpha$) coordinate system. Then, \n\\begin{align}\n\\ A(\\alpha, \\beta) &= \\pdv{x^r}{y^s}\\pdv{x^{\\alpha}}{x^r}\\pdv{x^s}{x^{\\beta }}\\\\\n&= \\pdv{x^{\\alpha}}{y^s}\\pdv{x^s}{x^{\\beta }}\\\\\n&= \\pdv{x^{\\alpha}}{y^{\\rho}}\\pdv{y^{\\rho }}{y^s}\\pdv{x^s}{x^{\\beta }}\n\\end{align}\nIf we consider the $\\overline{y}^r$ coordinate system as the $y^{\\rho }$ coordinate system and as $\\overline{y}^r = y^r$ then $\\pdv{y^{\\rho }}{y^s} = \\delta^{\\rho}_s$ and we get from (3)\n\\begin{align}\n\\ A(\\alpha, \\beta) &= \\pdv{x^{\\alpha}}{y^{\\rho}}\\pdv{y^{\\rho }}{y^s}\\pdv{x^s}{x^{\\beta }}\\\\\n\\ &= \\pdv{x^{\\alpha}}{y^{\\rho}}\\delta^{\\rho}_{s}\\pdv{x^s}{x^{\\beta }}\\\\\n\\ &= \\pdv{x^{\\alpha}}{y^{\\rho}}\\pdv{x^{\\rho}}{x^{\\beta }}\\\\\n\\ &= \\pdv{x^{\\alpha}}{y^{\\rho}}\\delta^{\\rho}_{\\beta }\\\\\n\\ &= \\pdv{x^{\\alpha}}{y^{\\beta}}\\\\\n\\text{(1) and (8)   } \\Rightarrow \\pdv{x^{\\alpha}}{y^{\\beta}} &= \\pdv{x^r}{y^s}\\pdv{x^{\\alpha}}{x^r}\\pdv{x^s}{x^{\\beta }}\n\\end{align}\nSo $A(r,s) = \\pdv{x^r}{y^s}$ is a mixed tensor of type $A_s^r$\\\\\\\\\nii) Let's compute the expression $A(\\alpha, \\beta) = \\pdv{x^r}{y^s}\\pdv{y^{\\alpha}}{y^r}\\pdv{y^s}{y^{\\beta }}$. Obviously, the right side is an expression of a (possible) mixed tensor of the second order ($\\pdv{x^r}{y^s}$) under transformation from the (r) coordinate system to the ($\\alpha$) coordinate system. Then, \n\\begin{align}\n\\ A(\\alpha, \\beta) &= \\pdv{x^r}{y^s}\\pdv{y^{\\alpha}}{y^r}\\pdv{y^s}{y^{\\beta }}\\\\\n&= \\pdv{x^r}{y^{\\rho}}\\pdv{y^{\\rho}}{y^s}\\pdv{y^{\\alpha}}{y^r}\\pdv{y^s}{y^{\\beta }}\\\\\n&= \\pdv{x^r}{y^{\\rho}}\\pdv{y^{\\rho}}{y^{\\beta}}\\pdv{y^{\\alpha}}{y^r}\\\\\n&= \\pdv{x^r}{y^{\\rho}}\\delta^{\\rho}_{\\beta}\\pdv{y^{\\alpha}}{y^r}\\\\\n&= \\pdv{x^r}{y^{\\beta}}\\pdv{y^{\\alpha}}{y^r}\\\\\n&= \\pdv{x^r}{x^{\\sigma}}\\pdv{x^{\\sigma}}{y^{\\beta}}\\pdv{y^{\\alpha}}{y^r}\n\\end{align}\nIf we consider the $\\overline{x}^r$ coordinate system as the $x^{\\sigma }$ coordinate system and as $\\overline{x}^r = x^r$ then $\\pdv{x^{\\sigma }}{x^r} = \\delta^{\\sigma}_r$ and we get from (15)\n\\begin{align}\n\\ A(\\alpha, \\beta) &= \\pdv{x^r}{x^{\\sigma}}\\pdv{x^{\\sigma}}{y^{\\beta}}\\pdv{y^{\\alpha}}{y^r}\\\\\n\\ &= \\delta^r_{\\sigma}\\pdv{x^{\\sigma}}{y^{\\beta}}\\pdv{y^{\\alpha}}{y^r}\\\\\n\\ &= \\pdv{x^{\\sigma}}{y^{\\beta}}\\pdv{y^{\\alpha}}{y^{\\sigma}}\\\\\n\\ &= \\pdv{x^{\\sigma}}{y^{\\beta}}\\delta^{\\alpha}_{\\sigma}\\\\\n\\ &= \\pdv{x^{\\alpha}}{y^{\\beta}}\\\\\n\\text{(10) and (19)   } \\Rightarrow \\pdv{x^{\\alpha}}{y^{\\beta}} &= \\pdv{x^r}{y^s}\\pdv{y^{\\alpha}}{y^r}\\pdv{y^s}{y^{\\beta }}\n\\end{align}\nSo $A(r,s) = \\pdv{x^r}{y^s}$ is a mixed tensor of type $A_s^r$\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p24-exercise 10.}\n\\begin{tcolorbox}\nIf $x^r, y^r, z^r$ are three systems of coordinates, prove the follwoing rule for the multiplication of Jacobians.\n$$\\left|\\pdv{x^m}{y^n}\\right|\\left|\\pdv{y^r}{z^s}\\right| = \\left|\\pdv{x^t}{z^u}\\right|$$\n\\end{tcolorbox}\n As we have  \n\\begin{align}\n\\pdv{x^t}{z^u} &=\\pdv{x^t}{y^k} \\pdv{y^k}{z^u}\\\\\n \\left[ { \\begin{array}{ccc}\n   \\ \\pdv{x^1}{z^1} & \\dots & \\pdv{x^1}{z^N}\\\\\n   \\vdots & \\vdots & \\vdots\\\\\n    \\pdv{x^N}{z^1} & \\dots & \\pdv{x^N}{z^N}\\\\\n  \\end{array}} \\right] &= \\left[ { \\begin{array}{ccc}\n   \\ \\pdv{x^1}{y^k}\\pdv{y^k}{z^1} & \\dots & \\pdv{x^1}{y^k}\\pdv{y^k}{z^N}\\\\\n   \\vdots & \\vdots & \\vdots\\\\\n    \\pdv{x^N}{y^k}\\pdv{y^k}{z^1}& \\dots & \\pdv{x^N}{y^k}\\pdv{y^k}{z^N}\\\\\n  \\end{array}} \\right]\\\\\n  &= \\left[ { \\begin{array}{ccc}\n   \\ \\pdv{x^1}{y^1}& \\dots & \\pdv{x^1}{y^N}\\\\\n   \\vdots & \\vdots & \\vdots\\\\\n    \\pdv{x^N}{y^1}& \\dots & \\pdv{x^N}{y^k}\\\\\n  \\end{array}} \\right]\\left[ { \\begin{array}{ccc}\n   \\ \\pdv{y^1}{z^1} & \\dots & \\pdv{y^1}{z^N}\\\\\n   \\vdots & \\vdots & \\vdots\\\\\n    \\pdv{y^N}{z^1}& \\dots & \\pdv{y^N}{z^N}\\\\\n  \\end{array}} \\right]\\\\\n  \\ & \\Rightarrow \\left|\\pdv{x^m}{y^n}\\right|\\left|\\pdv{y^r}{z^s}\\right| = \\left|\\pdv{x^t}{z^u}\\right|\n  \\end{align}\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\n\\section{p24-exercise 11.}\n\\begin{tcolorbox}\nProve that with respect to transformations $$ x^{,r} = C_{rs}x^s$$ where the coefficients are constants satisfying $$C_{mr}C_{ms} = \\delta^r_s$$ contravariant and covariant vectors have the same formula of transformation $$ A^{,r} = C_{rs}A^{s} \\text{, } A_{,r} = C_{rs}A_{s} $$\n\\end{tcolorbox}\n i) $ A^{,r} = C_{rs}A^{s}$\\\\\n \n Be $ A^{,r} = A^{s}\\pdv{x^{,r}}{x^s}$ and as $x^{,r} = C_{rs}x^{s}$  we have $\\pdv{x^{,r}}{x^s} = C_{rs}$. Hence,$$ A^{,r} = C_{rs}A^{s}$$.\\\\\\\\\n i) $ A_{,r} = C_{rs}A_{s}$\\\\\n Be $ A_{,r} = A_{s}\\pdv{x^{s}}{x^{,r}}$ and as $x^{,r} = C_{rs}x^{s}$  we have\n\\begin{align}\n\\pdv{x^{,r}}{x^{,t}} &= C_{rs}\\pdv{x^{s}}{x^{,t}}\\\\\n\\Rightarrow \\delta^{r}_{t} &= C_{rs}\\pdv{x^{s}}{x^{,t}}\n  \\end{align}\n  Now, multiply (2) by $C_{rq}$. We get,\n  \\begin{align}\n \\delta^{r}_{t}C_{rq} &= C_{rq}C_{rs}\\pdv{x^{s}}{x^{,t}}\\\\\n \\ C_{tq} &= C_{rq}C_{rs}\\pdv{x^{s}}{x^{,t}}\\\\\n \\text{as }C_{mr}C_{ms} = \\delta^r_s \\Rightarrow \\quad \\quad  C_{tq} &= \\delta^q_s\\pdv{x^{s}}{x^{,t}}\\\\\n \\Rightarrow   C_{tq} &= \\pdv{x^{q}}{x^{,t}} \\text{  or  }  C_{rs} = \\pdv{x^{s}}{x^{,r}}\\\\\n \\text{  as  } A_{,r} = A_{s}\\pdv{x^{s}}{x^{,r}} \\Rightarrow A_{,r} &= C_{rs}\\pdv{x^{s}}{x^{,r}}\n  \\end{align}\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\n\\section{p25-exercise 12.}\n\\begin{tcolorbox}\nProve that $$\\pdv{ln\\left|\\pdv{x^m}{y^n}\\right|}{x^r} =\\pdv{y^m}{x^r}{x^n}\\pdv{x^n}{y^m}$$.\n\\end{tcolorbox}\n\\begin{lemma}\nBe $A$ a square matrix $N\\times N$; Be $f$ a $C^1$ function $f:\\mathbb{R}^{NxN} \\rightarrow \\mathbb{R}$. Define $A^{,}$ as $(A^,_{ij}) = \\dv{f}{A_{ij}}$. Then,$$(ln\\left|A\\right|)^, = (A^{-1})^T \\text{ wih }  f =\\left|A\\right|$$\nProof:\\\\\nBy definition of the determinant, we have\n\\begin{align}\n\\left|A\\right| = A_{iK}C_{K}^i \\quad \\text{ (no summation on K!)}\n\\end{align}\nwith $(C_{K}^i) =  (-1)^{i+K}M^{i}_K$ being the cofactor  of element $A_{iK}$ and $M^{i}_K$ the minor (N-1)x(N-1) matrix associated with the cofactor $A_{K^i}$. Be $C = (C_{ij})$ the NxN matrix formed with all possible cofactor elements  $C_{j}^i \\text{  }(i,j = 1 \\dots,N)$.\\\\\nWe have \n\\begin{align}\n\\ A^{-1} &= \\frac{C^T}{\\left|A\\right|}\\\\\n\\Rightarrow (A^{-1})^T &= \\frac{C}{\\left|A\\right|} \\\\\n\\text{differentiating (1) }\\Rightarrow \\pdv{\\left|A\\right|}{A_{mn}} &= \\pdv{A_{iK}}{A_{mn}}C^i_K +A_{iK} \\pdv{C^i_K}{A_{mn}}\\\\\n\\text{we have for i = m } & \\begin{array}{c}\n    \\pdv{A_{iK}}{A_{mn}} = 1\\quad K=n\\\\\n    \\pdv{A_{iK}}{A_{mn}} = 0\\quad K \\neq n\\\\\n  \\end{array}\n\\end{align}\nAlso, $\\forall K: \\pdv{C^i_K}{A_{in}} = 0 $ as by definition of the cofactor matrix, $A_{ij} $ is not contained in $C_{ij} $.\\\\\nHence, (4) becomes\n\\begin{align}\n\\pdv{\\left|A\\right|}{A_{ij}} &= C^i_j\\\\\n\\text{But,}\\quad \\pdv{ln\\left|A\\right|}{A_{ij}} &= \\frac{\\pdv{\\left|A\\right|}{A_{ij}}}{\\left|A\\right|}\\\\\n\\text{(6) and  (7) gives}\\quad \\pdv{ln\\left|A\\right|}{A_{ij}} &= \\frac{C^i_j}{\\left|A\\right|}\\\\\n\\text{(3) and  (8) gives}\\quad \\pdv{ln\\left|A\\right|}{A_{ij}} &= \\frac{(A^{-1}_{ij})^T \\left|A\\right|}{\\left|A\\right|} = (A^{-1}_{ij})^T \\\\\n\\Rightarrow (ln\\left|A\\right|)^, &= (A^{-1})^T\n\\end{align}\n\\end{lemma}$$\\diamond$$\n\nNow the main proof:\\\\\nLet, \n\\begin{align}\n\\ A \\equiv \\left[ a_{mn}\\right] &= \\left[ \\pdv{y^m}{x^n}\\right]\\\\\n\\Rightarrow \\pdv{ln\\left|A\\right|}{x^r} &= \\pdv{ln\\left|A\\right|}{a_{mn}}\\pdv{a_{mn}}{x^r}\\\\\n\\text{from (10) we get }\\quad \\pdv{ln\\left|A\\right|}{a_{mn}} &= (A^{-1})^T_{mn}\\\\\n\\text{But A is a Jacobian, so } (A^{-1})_{mn} &= \\pdv{x^m}{y^n}\\\\\n\\text{ and thus  }(A^{-1})^T_{mn} &=  \\pdv{x^n}{y^m}\\\\\n\\text{(13) can be written as }  \\pdv{ln\\left|A\\right|}{x^r} &=  \\pdv{x^n}{y^m}\\pdv{a_{mn}}{x^r}\\\\\n\\Rightarrow \\pdv{ln\\left|A\\right|}{x^r} &=  \\pdv{x^n}{y^m}\\pdv{y^m}{x^r}{x^n}\n\\end{align}\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p25-exercise 13.}\n\\begin{tcolorbox}\nConsider the quantities $\\dv{x^r}{t}$ for a particle moving in the plane. If $x^r$ are the rectangular Cartesian coordinates, are these quantities the components of a contravariant or covariant vector with respect to rotation of the axes? Are they components of a vector with respect to transformation to any curvilinear coordinates (e.g. polar coordinates)?\n\\end{tcolorbox}\nNote: we suppose that by a rotation of the axes, the problem means a fixed rotation and not a rotation varying in time.\\\\\\\\\n i) Be $v^{r} = \\dv{x^r}{t}$ and consider $v^{\\alpha}$  the same object but in another the coordinate system.\n A rotation of the axes implies the linear form\n \\begin{align}\n \\ &x^{\\alpha} = R^{\\alpha }_k x^k \\quad \\text{ with } R^{\\alpha }_k \\neq R^{\\alpha }_k (x^k)\\\\\n \\Rightarrow\\quad  & \\pdv{x^{\\alpha}}{x^r} = R^{\\alpha }_k \\delta^k_r \\\\\n \\Rightarrow\\quad  & R^{\\alpha }_r  = \\pdv{x^{\\alpha}}{x^r} \n \\end{align}\n Consider $v^{\\alpha} = \\dv{x^{\\alpha}}{t}$\n \\begin{align}\n v^{\\alpha} &= \\dv{x^{\\alpha}}{t}\\\\\n \\text{(1)   }\\Rightarrow\\quad v^{\\alpha} &= R^{\\alpha }_k \\dv{x^k}{t}\\\\\n \\Rightarrow\\quad v^{\\alpha} &= R^{\\alpha }_k v^k\\\\\n \\text{(3)   }\\Rightarrow\\quad v^{\\alpha} &= v^k\\pdv{x^{\\alpha}}{x^r} \n \\end{align}\n Conclusion: $v^k$ is a contravariant vector.\\\\\\\\\n ii) Are they components of a vector with respect to transformation to any curvilinear coordinates (e.g. polar coordinates)?\\\\\nWe know that \n\\begin{align}\n\\ dx^{\\alpha} = \\pdv{x^{\\alpha}}{x^r}dx^r\\\\\n\\Rightarrow \\quad \\dv{x^{\\alpha}}{t} = \\pdv{x^{\\alpha}}{x^r}\\dv{x^r}{t}\\\\\n\\Rightarrow \\quad v^{\\alpha} = v^r\\pdv{x^{\\alpha}}{x^r}\n\\end{align}\nSo $v^r$ is a contravariant vector in general. Note that this proof is more straightforward than the prove in i).\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p25-exercise 14.}\n\\begin{tcolorbox}\nConsider the question raised in No. 13 for the acceleration $\\dv[2]{x^r}{t}$.\n\\end{tcolorbox}\nFrom exercise 13. we know that \n\n \\begin{align}\n \\dv{x^{\\alpha}}{t} &= \\pdv{x^{\\alpha}}{x^r}\\dv{x^r}{t}\\\\ \n \\Rightarrow\\quad \\dv[2]{x^{\\alpha}}{t} &= \\dv[2]{x^r}{t}\\pdv{x^{\\alpha}}{x^r}+ \\dv{\\pdv{x^{\\alpha}}{x^r}}{t}\\dv{x^r}{t}\\\\ \n &= \\dv[2]{x^r}{t}\\pdv{x^{\\alpha}}{x^r}+ \\pdv{x^{\\alpha}}{x^r}{x^m}\\dv{x^m}{t}\\dv{x^r}{t} \n \\end{align}\n The second term on the right does not vanish in general, hence $\\dv[2]{x^r}{t}$ has not a tensor character.\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p25-exercise 15.}\n\\begin{tcolorbox}\nIt is well known that the equation of an ellipse may be written $$ ax^2+2hxy+by^2 =1$$\nWhat is the tensor character of $a,h, b$ with respect to transformation to any Cartesian coordinates (rectangular or oblique) in the plane?\n\\end{tcolorbox}\nConsider the transformation from a $(w,z)$ coordinate system to a $(x,y)$ coordinate system. For the considered type of transformation we have\n\\begin {align}\n\\begin{array}{c}\n\\ x = \\alpha w + \\beta z\\\\\n\\ y = \\gamma w + \\delta z\\\\\n  \\end{array}\\\\\n\\text{consider}\\quad \\begin{array}{c}\n\\ ax^2+2hxy+by^2 =1\\\\\n\\ pw^2+2qwz+rz^2 =1\n  \\end{array}\n\\end{align}\nthe two representations of the same ellipse in the respective coordinate systems. Plugging (1) in (2):\n\\begin {align}\n%\\text{(2)}\\quad \\Rightarrow\\quad ax^2+2hxy+by^2 = pw^2+2qwz+rz^2\\\\\n\\ a\\alpha^2 w^2 + a 2 \\alpha \\beta w z + \\alpha \\beta^2 z^2 +2h \\alpha \\gamma w^2 +\\beta \\delta z^2+2h(\\alpha \\delta + \\gamma \\beta) w z + b \\gamma^2 w^2 + 2 b \\gamma \\delta w z +\\delta^2 z^2 b = 1\\\\\n\\end{align}\nRearranging and equating the terms in $w^2, wz, z^2$ in (2) gives\n\\begin{align}\n\\ p &= a \\alpha^2 + 2 h \\alpha \\gamma + b \\gamma^2\\\\\n\\ q &=  a \\alpha \\beta + h(\\alpha \\delta + \\gamma \\beta) + \\gamma d\\\\\n\\ r &= a \\beta^2 + 2 h \\beta \\delta +b \\delta^2\n\\end{align}\nConsider the following objects\n\\begin {align}\n\\ (A_{ij}) = \\left[ { \\begin{array}{cc}\n  \\ a &  h\\\\\n  \\ h   &b\\\\\n  \\end{array}} \\right] \\\\\n  \\ (A_{ij})^{,} = \\left[ { \\begin{array}{cc}\n  \\ a^{,}_{11} &  a^{,}_{12}\\\\\n  \\ a^{,}_{21}  & a^{,}_{21}\\\\\n  \\end{array}} \\right] \\\\\n  \\text{ we calculate}\\quad A^{,}_{ij} = A_{km}\\pdv{x^k}{x^{,i}}\\pdv{x^m}{x^{,j}}\n\\end{align}\nwith $(x^{,1},x^{,2}) = (w, z)$ and $(x^{1},x^{2}) = (x, y)$. We have,\n\\begin{align}\n\\ \\pdv{x^1}{x^{,1}} &= \\alpha, \\pdv{x^1}{x^{,2}} = \\beta,\\pdv{x^2}{x^{,1}} = \\gamma,\\pdv{x^2}{x^{,2}} = \\delta\\\\\n\\text{ (10) and (11)}\\quad \\Rightarrow\\ &\\begin{array}{c}\n  \\ a^{,}_{11} = a \\alpha^2 + 2 h \\alpha \\gamma + b \\gamma^2 \\\\\n  \\ a^{,}_{22} = a \\beta^2 + 2 h \\delta \\beta + b \\delta^2 \\\\\n  \\ a^{,}_{12} = a^{,}_{21} =a \\alpha \\beta + h( \\alpha \\delta + \\gamma \\beta) + b \\gamma \\delta \\\\\n  \\end{array}\n\\end{align}\nCombining (5), (6), (7) and (12) we get $$ p = a^{,}_{11}, r = a^{,}_{22}, q =  a^{,}_{12} = a^{,}_{21}$$ and so (9) becomes $$  (A_{ij})^{,} = \\left[ { \\begin{array}{cc}\n  \\ p &  q\\\\\n  \\ q  & r\\\\\n  \\end{array}} \\right] \\\\$$\nConsidering (10) we see that $\\left[ { \\begin{array}{cc}\n  \\ a &  h\\\\\n  \\ h   &b\\\\\n  \\end{array}} \\right] $ transforms to $\\left[ { \\begin{array}{cc}\n  \\ p &  q\\\\\n  \\ q  & r\\\\\n  \\end{array}} \\right]$ according the rules of a covariant tensor of order two.\n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p25-exercise 16.}\n\\begin{tcolorbox}\nMatter is distributed in a plane and $A,B,H$ are the moments and product of inertia with respect to rectangular aces $0xy$ in a plane. Examine the tensor character of the set of quantities $A,B,H$ under rotation of the axes. What notation would you suggest for moments and product of inertia in order to exhibit the tensor character? What simple invariant can be formed from $A,B,H$ ?\n\\end{tcolorbox}\nConsider the transformation from a $(x^1,x^2)$ coordinate system to a $(y^1,y^2)$ coordinate system. For the considered type of transformation we have\n\\begin {align}\n\\begin{array}{c}\n\\ y^1 = \\alpha x^1 + \\beta x^2\\\\\n\\ y^2 = \\gamma x^1 + \\delta x^2\\\\\n  \\end{array}\\\\\n  \\text{Be }\\quad  \\begin{array}{c}\n  \\ A = \\sum_{\\rho} m_{\\rho} (x^{2,\\rho})^2\\\\\n  \\ B = \\sum_{\\rho} m_{\\rho} (x^{1,\\rho})^2\\\\\n  \\ H = \\sum_{\\rho} m_{\\rho} x^{1,\\rho} x^{2,\\rho}\\\\\n  \\end{array}\n    \\text{and}\\quad  \\begin{array}{c}\n  \\ A^, = \\sum_{\\rho} m_{\\rho} (y^{2,\\rho})^2\\\\\n  \\ B^, = \\sum_{\\rho} m_{\\rho} (y^{1,\\rho})^2\\\\\n  \\ H^, = \\sum_{\\rho} m_{\\rho} y^{1,\\rho} y^{2,\\rho}\\\\\n  \\end{array}\n\\end{align}\nthe moments and product of inertia, $\\rho$ being the index of summation over all the points with mass $m_{\\rho}$.\\\\\nFor the sake of notational simplicty we consider only one point of mass as the linearity of $A, B, H$ related to $\\rho$ ensures the validity of the nexts steps for all points in the plane.\\\\\nFrom (1) and (2) we have:\n\\begin {align}\n\\ \\frac{A^,}{m_{\\rho}}  &= \\gamma^2 (x^1)^2+2 \\gamma \\delta x^1 x^2 + \\delta ^2 (x^2)^2\\\\\n\\  \\frac{B^,}{m_{\\rho}}  &= \\alpha^2 (x^1)^2+2 \\alpha \\beta x^1 x^2 + \\beta ^2 (x^2)^2\\\\\n\\  \\frac{H^,}{m_{\\rho}}  &= \\alpha \\gamma (x^1)^2 + (\\gamma \\beta + \\alpha \\delta) x^1 x^2 + \\beta \\delta (x^2)^2\\\\\n\\text{Note that} \\quad &\\begin{array}{cc}\n  \\pdv{y^1}{x^1} = \\alpha & \\pdv{y^1}{x^2} = \\beta\\\\ \n\t\\pdv{y^2}{x^1} = \\gamma & \\pdv{y^2}{x^2} = \\delta\\\\ \n  \\end{array}\\\\\n  \\text{(6) in  (4):}\\quad &\\frac{B^,}{m_{\\rho}} =  (x^1)^2\\pdv{y^1}{x^1} \\pdv{y^1}{x^1}  + 2 (x^1)(x^2)\\pdv{y^1}{x^1}\\pdv{y^1}{x^2} + (x^2)^2\\pdv{y^1}{x^2}\\pdv{y^1}{x^2}\\\\\n  &=  (x^1)^2\\pdv{y^1}{x^1} \\pdv{y^1}{x^1}  +  (x^1)(x^2)\\pdv{y^1}{x^1}\\pdv{y^1}{x^2} + (x^2)(x^1)\\pdv{y^1}{x^1}\\pdv{y^1}{x^2} + (x^2)^2\\pdv{y^1}{x^2}\\pdv{y^1}{x^2}\n\\end{align}\nRepeating the same calculations for $\\frac{A^,}{m_{\\rho}}$ and $\\frac{H^,}{m_{\\rho}} $ gives:\n\\begin {align}\n\\begin{array}{c}\n\\frac{A^,}{m_{\\rho}} =  (x^1)^2\\pdv{y^2}{x^1} \\pdv{y^2}{x^1}  +  (x^1)(x^2)\\pdv{y^2}{x^1}\\pdv{y^2}{x^2} + (x^2)(x^1)\\pdv{y^2}{x^2}\\pdv{y^2}{x^1} + (x^2)^2\\pdv{y^2}{x^2}\\pdv{y^2}{x^2}\\\\\n\\frac{B^,}{m_{\\rho}} =  (x^1)^2\\pdv{y^1}{x^1} \\pdv{y^1}{x^1}  +  (x^1)(x^2)\\pdv{y^1}{x^1}\\pdv{y^1}{x^2} + (x^2)(x^1)\\pdv{y^1}{x^1}\\pdv{y^1}{x^2} + (x^2)^2\\pdv{y^1}{x^2}\\pdv{y^1}{x^2}\\\\\n\\frac{H^,}{m_{\\rho}} =  (x^1)^2\\pdv{y^1}{x^1} \\pdv{y^2}{x^1}  +  (x^1)(x^2)\\pdv{y^1}{x^2}\\pdv{y^2}{x^1} + (x^2)(x^1)\\pdv{y^1}{x^1}\\pdv{y^2}{x^2} + (x^2)^2\\pdv{y^1}{x^2}\\pdv{y^2}{x^2}\n  \\end{array}\n\\end{align}\nNow, define \n\\begin{align}\n(K_{ij}) = \\left[ { \\begin{array}{cc}\n  \\ (x^1)^2 &  (x^1)(x^2)\\\\\\\\\n  \\ (x^2)(x^1)  & (x^2)^2\\\\\n  \\end{array}} \\right] \\quad \\quad (K_{ij})^{,} = \\left[ { \\begin{array}{cc}\n  \\ (y^1)^2 &  (y^1)(y^2)\\\\\\\\\n  \\ (y^2)(y^1)  & (y^2)^2\\\\\n  \\end{array}} \\right]\n\\end{align}\n Then (9) can be written as\n \\begin {align}\n\\begin{array}{c}\n\\frac{A^,}{m_{\\rho}} = (y^1)^2 =  K^{11}\\pdv{y^2}{x^1} \\pdv{y^2}{x^1}  +  K^{12}\\pdv{y^2}{x^1}\\pdv{y^2}{x^2} + K^{21}\\pdv{y^2}{x^2}\\pdv{y^2}{x^1} + K^{22}\\pdv{y^2}{x^2}\\pdv{y^2}{x^2}\\\\\\\\\n\\frac{B^,}{m_{\\rho}} = (y^2)^2 =  K^{11}\\pdv{y^1}{x^1} \\pdv{y^1}{x^1}  +  K^{12}\\pdv{y^1}{x^1}\\pdv{y^1}{x^2} + K^{21}\\pdv{y^1}{x^1}\\pdv{y^1}{x^2} + K^{22}\\pdv{y^1}{x^2}\\pdv{y^1}{x^2}\\\\\\\\\n\\frac{H^,}{m_{\\rho}} = (y^1)(y^2)  = K^{11}\\pdv{y^1}{x^1} \\pdv{y^2}{x^1}  +  K^{12}\\pdv{y^1}{x^2}\\pdv{y^2}{x^1} + K^{21}\\pdv{y^1}{x^1}\\pdv{y^2}{x^2} + K^{22}\\pdv{y^1}{x^2}\\pdv{y^2}{x^2}\n  \\end{array}\n  \\end{align}\n  Hence,\n  \\begin{align}\n\\begin{array}{c}\n  \\ K^{,11}  =  K^{11}\\pdv{y^1}{x^1} \\pdv{y^1}{x^1}  +  K^{12}\\pdv{y^1}{x^1}\\pdv{y^1}{x^2} + K^{21}\\pdv{y^1}{x^1}\\pdv{y^1}{x^2} + K^{22}\\pdv{y^1}{x^2}\\pdv{y^1}{x^2}\\\\\\\\\n\\ K^{,22} =  K^{11}\\pdv{y^2}{x^1} \\pdv{y^2}{x^1}  +  K^{12}\\pdv{y^2}{x^1}\\pdv{y^2}{x^2} + K^{21}\\pdv{y^2}{x^2}\\pdv{y^2}{x^1} + K^{22}\\pdv{y^2}{x^2}\\pdv{y^2}{x^2}\\\\\\\\\n \\ K^{,12} = K^{,21} = K^{11}\\pdv{y^1}{x^1} \\pdv{y^2}{x^1}  +  K^{12}\\pdv{y^1}{x^2}\\pdv{y^2}{x^1} + K^{21}\\pdv{y^1}{x^1}\\pdv{y^2}{x^2} + K^{22}\\pdv{y^1}{x^2}\\pdv{y^2}{x^2}\n  \\end{array}\n\\end{align}\nSo the object $(K_{ij})\\equiv K^{ij}$ transforms according (12) like a contravariant second order tensor.\\\\\n\nNow, consider $|K^{ij}|$, obviously $|K^{ij}| = (x^1)^2(x^2)^2-(x^1)(x^2)(x^2)(x^1) =0$, but so is also $|K^{,ij}|$.\n$$\\Rightarrow\\quad |K^{ij}| \\text{ is an invariant under the considered transformation}$$. \n$$\\blacklozenge$$\n\\pagebreak[4]\n\n\\section{p25-exercise 17.}\n\\begin{tcolorbox}\n$S_{nmr}$ is a skew-symmetric tensor in the first two indices.\n $-f_{mnr} + f_{nmr} = S_{mnr}$.\n\\end{tcolorbox}\nFrom exercise 13. we know that \n\\begin{align}\n-f_{mnr} + f_{nmr} = S_{mnr}\n\\end{align}\nSwap the indices three times\n\\begin{align}\n\\text{i)}\\quad n \\leftrightarrow r: (1) &\\Rightarrow -f_{mrn} + f_{rmn } = S_{mrn}\\\\\n\\ &\\Leftrightarrow \\underbrace{f_{mnr}}_\\text{*} + \\underbrace{f_{rmn }}_\\text{**} = -S_{rmn}\\\\\n\\text{ii)}\\quad m \\leftrightarrow r: (1) &\\Rightarrow -f_{rnm} + f_{nrm } = S_{rnm}\\\\\n\\ &\\Leftrightarrow \\underbrace{f_{rmn}}_\\text{**} + \\underbrace{f_{nrm }}_\\text{***} = -S_{nrm}\\\\\n\\text{iii)}\\quad m \\leftrightarrow n: (1) &\\Rightarrow -f_{nmr} + f_{mnr } = S_{nmr}\\\\\n\\ &\\Leftrightarrow \\underbrace{f_{nrm}}_\\text{***} + \\underbrace{f_{mnr }}_\\text{*} = -S_{mnr}\\\\\n\\text{(3) - (5) + (7):} \\quad 2\\underbrace{f_{mnr}}_\\text{*} &= -S_{rmn}+S_{nrm}-S_{mnr}\\\\\n\\ \\Leftrightarrow f_{mnr} &= \\frac{-S_{rmn}+S_{nrm}-S_{mnr}}{2}\n\\end{align}\n$$\\blacklozenge$$\n\\pagebreak[4]", "meta": {"hexsha": "45048d491ec448f61fd56d4b34a9f99793b4a337", "size": 55470, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter1.tex", "max_stars_repo_name": "Niohori/Synge-Tensor-Calculus", "max_stars_repo_head_hexsha": "a11e45d9d8c4f78b9e9504391b532bb4f0d0587f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter1.tex", "max_issues_repo_name": "Niohori/Synge-Tensor-Calculus", "max_issues_repo_head_hexsha": "a11e45d9d8c4f78b9e9504391b532bb4f0d0587f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter1.tex", "max_forks_repo_name": "Niohori/Synge-Tensor-Calculus", "max_forks_repo_head_hexsha": "a11e45d9d8c4f78b9e9504391b532bb4f0d0587f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.8432630614, "max_line_length": 384, "alphanum_fraction": 0.5851992068, "num_tokens": 24899, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8670357546485407, "lm_q1q2_score": 0.7187195852304206}}
{"text": "\\chapter{Specific Groups}\r\n\\section {Classical Groups:}\r\n{\\bf Theorem 1:}\r\n$A_n$ is simple for $n>4$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Suppose $1 \\ne H \\lhd A_n$.\\\\\r\n\\\\\r\nClaim 1: If $(abc) \\in H$ for any $a,b,c, H=A_n$.\\\\\r\nWithout loss, $(abc)=(123)$.  Put $g= (12k), k>3$.  $(123)^g= (12k)$ and these $3$-cycles\r\ngenerate $A_n$.\\\\\r\nClaim 2: $H$ contains a $3$-cycle.\\\\\r\nLet $x \\in H$ be the element that moves the fewest points other than the identity.\r\n$x$ must move at least $3$ points or it would not be in $A_n$.  The cycle structure of\r\n$x$ must be one of the following:\r\n(1) $(12) (34)$, (2) $(12)(34) (56)(78)\\ldots $, \r\n(3) $(123) (456) \\ldots$,\r\n(4) $(12345...) (k, k+1, \\ldots)$,\r\n(5) $(123)$.\r\nNote that all cycles must have the same length otherwise by raising $x$ to the power of\r\nthe length of the shortest cycle yields an element moving fewer points.\r\nIn case 1, put $g= (125) \\in A_n$.  $x^gx= (125)$, so $H$ contains a $3$ cycle in \r\nthis case.\r\nIn case 2, put $g= (123) \\in A_n$.  $x^gx= (13)(24)$ which moves fewer points \r\nthan $x$ contrary to the selection of $x$, so this can't happen.\r\nIn case 3, put $g= (234) \\in A_n$.  $x^gx^{-1}= (12436)(5)$ which moves fewer elements than\r\n$x$ so this can't happen.\r\nIn case 4, put $g=(123)$; then $x^{-1}x^g$ fixes $3$ and all elements $\\ge k$ so it fixes more\r\nelements than $x$ which can't happen.  So only case 5 is possible.\r\n\\\\\r\n\\\\\r\nSince $H$ contains a $3$-cycle by claim 1, it contains all of $A_n$.\r\n\\end{quote}\r\n{\\bf Notation:}  $L_n(F)$ is the invertible linear transformations in a vector space of\r\ndimension $n$ over the field $F$.  $L_n(q)=L_n(F_{q})$.  $SL_n(F)= \\{M \\in L_n(F): det(M)=1 \\}$.\r\nA \\emph{transvection}, $\\tau$, is a matrix of the form\r\n$\\left(\r\n\\begin{array}{cc}\r\n1 &  0_{n-1} \\\\\r\nv_{n-1} &  I_{n-1} \\\\\r\n\\end{array}\r\n\\right)$.\r\nNote that\r\n$\\left[\r\n\\left(\r\n\\begin{array}{cc}\r\n1 &  -x \\\\\r\n0 &  1 \\\\\r\n\\end{array}\r\n\\right)\r\n\\left(\r\n\\begin{array}{cc}\r\na &  0 \\\\\r\n0 &  a^{-1} \\\\\r\n\\end{array}\r\n\\right)\r\n\\left(\r\n\\begin{array}{cc}\r\n1 &  x \\\\\r\n0 &  1 \\\\\r\n\\end{array}\r\n\\right)\r\n\\left(\r\n\\begin{array}{cc}\r\na^{-1} &  0 \\\\\r\n0 &  a \\\\\r\n\\end{array}\r\n\\right)\r\n= \\left(\r\n\\begin{array}{cc}\r\n1 &  x(a^{2}-1)\\\\\r\n0 &  1 \\\\\r\n\\end{array} \\right)\\right] $.  \r\nAlso note that $\\tau(x)-x$ is a hyperplane.\r\n\\\\\r\n\\\\\r\nThere's another way to define transvections.  Pick $1 \\ne \\phi \\in \\hat{V}$ and\r\n$v \\in V: \\phi(v) = 0$.  The set $H = \\{y: \\phi(y) = 0 \\}$ is a hyperplane.  A transvection can be defined by\r\n$\\tau_{\\phi,v}(x) = x + \\phi(x) v$.  Note that if $x \\in H, \\tau_{\\phi,v}(x) = x$, since $\\phi(v) = 0$, \r\n$\\forall x \\in V, \\tau_{\\phi,v}(x) - x = \\phi(x) v$ and $\\phi(phi(x)v))= \\phi(x)\\phi(v)= 0$, so $\\tau_{\\phi,v}(x) - x \\in H$.\r\n$\\tau_{\\phi,v}(\\tau_{\\phi,-v}(x)) = x$.  in fact, if $\\phi$ is given and $\\phi(v_1)=0=\\phi(v_2)$,\r\n$\\tau_{\\phi, v_1}(\\tau_{\\phi, v_2}(x) = \\tau_{\\phi, v_1 + v_2}(x)$.\r\nFinally, let $\\sigma \\in GL_n(F)$, then $\\sigma(\\tau_{\\phi, v}(\\sigma^{-1}(x))) = \\tau_{\\phi \\sigma^{-1}, \\sigma(v)}(x)$.\r\nThe hyperplane for $\\phi \\sigma^{-1}$ is $\\{y: \\phi \\sigma^{-1}(y)=0 \\} = \\{ \\sigma(x): \\phi(x)=0 \\} = \\sigma H$.\r\nPutting, $\\psi = \\phi \\sigma^{-1}, H'= \\sigma(H), v' = \\sigma(v)$, we get \r\n$\\sigma(\\tau_{\\phi, v}(\\sigma^{-1}(x)))=  \\tau_{\\psi, v'}(x)$.  Going the other way, given $H'$ and $v'$, we can find\r\n$\\sigma \\in GL_n(F): \\sigma(H)= H', \\sigma(v)= v'$ and thus a transvection is conjugate to any other transvection in $GL_n(F)$.\r\nIn fact, if $n \\geq 3$, all transvections are conjugate in $SL_n(F)$.\r\nAll transvections have the same determinant and, furthermore, since $\\tau_{\\sigma, v_1} \\tau_{\\sigma, v_2} = \\tau_{\\sigma, v_1 + v_2}$,\r\nthat common determinant is $1$. Commutators of transvections also have determinant $1$ so the group generated by\r\ntransvections in $GL_n(F)$ lies in $SL_n(F)$.  Using Theorem 3 below, we see that the transvections actually generate\r\nall of $SL_n(F)$, for $n \\geq 3$.  By theorem 4 below, for $n \\geq 3$, the commutator of two transvections is also a transvection\r\nand since all transvections are congugate, $SL_n(F)' = SL_n(F)$.\r\n\\\\\r\n\\\\\r\nReturning to the matrix form above,\r\nwe see that the stabilizer of $e_1$ consists of matricies of the form:\r\n$\r\n\\left(\r\n\\begin{array}{cc}\r\na_{11} &  0_{n-1} \\\\\r\n{\\vec a}_{n-1} &  I_{n-1} \\\\\r\n\\end{array}\r\n\\right)\r\n$.  We will use this stabilizer in conjunction with Iwasawa's theorem to show $PSL_n(F)$ is simple for $n \\geq 3$ or $|F|>3$.\r\n\\\\\r\n\\\\\r\nThe following theorem is a simplification of Iwasawa's Theorem that is used to show the\r\nsimplicity of the classical groups.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 2:}\r\n(Iwasawa) Suppose $G$ acts faithfully and primitively on a set $\\Omega$ and\r\n$A \\lhd G_a$ is abelian. Suppose further $ \\langle A^G \\rangle = G$ and $G=G'$.\r\nThen $G$ is simple.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSuppose $1 \\ne N \\lhd G$.  $N$ is not contained $G_a$ for some $a$.  Since $G_a$ is maximal,\r\n$G=N G_a$ so $g= nh, n \\in N, h \\in G_a$.  $g A g^{-1} = n A n^{-1}$, since\r\n$A \\lhd G_a$, so $g A g^{-1} \\subseteq NA$ so $G= \\langle A^G \\rangle = NA$.  \r\nBut $G/N = A/(A \\cap N)$ is abelian so\r\n$G' \\subseteq N$, however $G=G'$ so $N=G$.\r\n\\end{quote}\r\n{\\bf Theorem 3:}\r\n$SL_n(F)$ is generated by $T_{ij}(b)=I + b (\\delta_{ik} \\delta_{lj}), i \\ne j, b \\in F^*$ if $n>2$.\r\nNote: $SL_n(F)$ is also generated by transvections.  Note also that $T_{ij}(b)T_{ij}(-b) = I$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nNote that $det(T_{ij}(b))=1$.  For $A \\in SL_n(F)$,\r\n$\\exists P, Q \\subseteq \\langle T_{ij}(b) \\rangle: PAQ=diag( d_1, d_2 , \\ldots, d_n )$ and\r\n$d_1 d_2 \\ldots d_n =1$.  Also,\r\n$\\left(\r\n\\begin{array}{cc}\r\nd^{-1} &  0 \\\\\r\n0 &  d \\\\\r\n\\end{array}\r\n\\right) \r\n\\subseteq \\langle T_{ij}(b) \\rangle$.\r\n\\end{quote}\r\n{\\bf Theorem 4:}  If $n>2$ or $F$ has more than $3$ elements,\r\n$SL_n(F) = SL_n(F)'$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nSTS $T_{ij}(b) \\in SL_n(F)'$.  If $n>2$ then for $k \\ne i, j$:\r\n$T_{ij}(b)= T_{ik}(b) T_{kj}(1) T_{ik}(-b) T_{kj}(-1)=\r\nT_{ik}(b) T_{kj}(1) T_{ik}(b)^{-1} T_{kj}(1)^{-1}$.\r\nIf $|F|>2$, $\r\n\\left(\r\n\\begin{array}{cc}\r\nd &  0 \\\\\r\n0 &  d^{-1} \\\\\r\n\\end{array}\r\n\\right) \r\n\\left(\r\n\\begin{array}{cc}\r\n1 &  c \\\\\r\n0 &  1 \\\\\r\n\\end{array}\r\n\\right) \r\n\\left(\r\n\\begin{array}{cc}\r\nd^{-1} &  0 \\\\\r\n0 &  d \\\\\r\n\\end{array}\r\n\\right) \r\n\\left(\r\n\\begin{array}{cc}\r\n1 &  -c \\\\\r\n0 &  1 \\\\\r\n\\end{array}\r\n\\right) =\r\n\\left(\r\n\\begin{array}{cc}\r\n1 &  c(d^2-1) \\\\\r\n0 &  1 \\\\\r\n\\end{array}\r\n\\right)$.  \r\nChoose $d \\neq 0, d^2 \\neq 1$. Put $c= (d^2-1)^{-1} b$.\r\nThis shows $T_{12}(b) \\in SL_n(F)'$.\r\n\\end{quote}\r\n{\\bf Theorem 5:}  Let $C_n(F)= {\\mathbb Z}(SL_n(F))$, then $C_n(F)= \\{ \\alpha I_n : \\alpha^n=1 \\}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nNote that $GL_n(F)' \\subseteq SL_n(F)$ since \r\n$GL_n(F)/SL_n(F)$ is abelian.  If $X$ commutes with $SL_n(F)$ it must commute with\r\n$T_{ij}(1)$, hence  $C_n(F)= F^* I_n \\cap SL_n(F)$ with $d^n=1$.\r\n\\end{quote}\r\n{\\bf Observation:}  $GL_n(F)$ and hence $SL_n(F)$ acts on ${\\mathbb P}_{n-1}(F)$ whose elements\r\nare one dimensional subspaces of $A_n(F)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 6:}  $SL_n(F)$ is $2$-transitive on ${\\mathbb P}_{n-1}(F)$ if $n \\ge 2$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSuppose \r\n$Fx_1 \\ne F x_2$ and\r\n$Fy_1 \\ne F y_2$.  Choose a base $x_1, x_2, \\ldots , x_n$ and write\r\n$y_k= \\sum_j a_{kj}x_j , k= 1,2$.  Add $n-2$ rows to the matrix $(a_{ij})$ to obtain\r\na matrix with determinant $1$.  Let $T$ be the  linear transformation\r\nsending $x_k \\rightarrow y_k$.  If $n=2$ \r\nand $det(A)=a \\ne 0$, pick $T$ as \r\n$x_1 \\rightarrow y_1$ and $x_2 \\rightarrow a^{-1} y_2$.\r\n\\end{quote}\r\n{\\bf Theorem 7:}  $SL_n(F)_{e_1}$ contains an abelian normal subgroup $A_{e_1}$ whose\r\nconjugates generate $SL_n(F)$.\r\n\\begin{quote}\r\n\\emph{Proof:} The stabilizer of $e_1$ is matrix with $a_{11}, \\ldots, a_{n1}$ as the first\r\ncolumn with all entries of the first row (except possibly $a_{11}$ equal to $0$ and any\r\n$A_{n-1}$ in the lower right hand corner with $a_{11} det (A_{n-1}) = 1$.  Let $A_{e_1}$\r\ndenote the matrices with $a_{11}=1$ and $A_{n-1}= I_{n-1}$ then $A_{e_1}$ is a normal\r\nabelian subgroup and $T_{21}(b) \\in A_{e_1}$.  By conjugating this element, we can get\r\nany $T_{ik}(b)$, so $SL_n(F) \\subseteq \\langle A_{e_1}^g \\rangle $.\r\n\\end{quote}\r\n{\\bf Theorem 9:}\r\n$PSL_n(q)$ is simple for $n>2$ or $q>3$.\r\n\\begin{quote}\r\n\\emph {Proof:} Apply the above theorem on simplicity to $SL_n(q)$ with the identified\r\n$A_{e_1}$.\r\n\\end{quote}\r\n{\\bf Theorem 10:}\r\n$|PSL_n(q)|= {\\frac 1 {(q-1)(n,q-1)}} \r\n(q^{n} -1) (q^{n} -q) (q^{n} -q^{2}) ...  (q^{n} -q^{n-1})$,\r\nis simple if $n>2$ or $q>3$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $v_1, \\ldots, v_n$ be a base.  For $T \\in L_n(F_q)$, there are $q^n-1$ ways to choose $T(v_1)$,\r\n$q^n-q)$ ways to choose $T(v_2)$, \\ldots, $q^n-q^{n-1}$ ways to choose $T(v_n)$. So\r\n$|L_n(F_q)|= (q^{n} -1) (q^{n} -q) (q^{n} -q^{2}) ...  (q^{n} -q^{n-1})$.\r\n$|SL_n(F_q)|= {\\frac {|L_n(F_q)|}{(q-1)}}$.  There are $(n,q-1)$ solutions in $F_q$ of\r\n$d^n=1$ so $|PSL_n(F_q)|= {\\frac {|SL_n(F_q)|} {(n,q-1)}}$.\r\n\\end{quote}\r\n{\\bf Bilinear Forms:}  $B(x,y)$.  A quadratic form is $Q(x): Q(ax)= a^2Q(x)$ and if $char(F) \\ne 2$\r\nthe the quadratic form gives rise to the bilinear form ${\\frac 1 2} Q(x+y)-Q(x)-Q(y)$.\r\n$U_B^{\\perp_R} = \\{v \\in V: (v, u)=0, \\forall u \\in V \\}$.  Matrix for $B(x,y)$ over the\r\nbasis $e_i$ is $b_{ij}= B(e_i, e_j)$.  Bilinear form is \\emph {non-degenerate} if\r\n$ U_B^{\\perp_R} = U_B^{\\perp_L} = 0 $.  Bilinear form is \r\n\\emph{symmetric} if $B(x,y)= B(y,x)$, \\emph{hermitian} if $B(x,y)= {\\overline B(y,x)}$,\r\nand \\emph{alternating} if $B(x,y)= -B(y,x)$.  If $b_{ij}= (e_i, e_j)$, the \\emph{discrimminant}\r\nof the bilinear form is $det(b_{ij})$.\r\n$\\sigma \\in L_n(F)$ \r\nis an \\emph{isometry}\r\nwith respect to a bilinear form, $B$, \r\nif $B(x,y)=B(\\sigma x, \\sigma y)$.  \r\n$U$ is a \\emph{non-isotropic} subspace if $dim(U \\cap U^{\\perp})=0$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 11:} \r\nThe following three conditions on a bilinear form, $B$, are equivalent:\r\n(1) $V^{\\perp_R}= 0$,\r\n(2) $V^{\\perp_L}= 0$,\r\n(3) the matrix of $B$ relative to any basis is invertible.\r\n\\begin{quote}\r\n\\emph{Proof:} Straightforward.\r\n\\end{quote}\r\n{\\bf Theorem 12:} \r\nLet $B$ be a symmetric bilinear form on $V$ over $F$, $char(F) \\ne 2$, then there\r\nis a base $( u_1 , u_2 , \\ldots , u_r , z_1 , \\ldots ,  z_{n-r} )$  such that relative to\r\nthis base, $B$ has the form $diag( b_1 , b_2 , \\ldots , b_r, 0, 0, \\ldots ,0)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nThis uses the Lagrange reduction which works like this:\r\nIf $B=0$, we're done.  Choose $u_i: Q(u_i ) = b_i \\ne 0$.  In the inductive step,\r\nsuppose $V_k= (u_1 , u_2 , \\ldots , u_k )$ be a basis with $(u_i, u_j) = 0, i \\ne j$ and\r\n$(u_i , u_i )= b_i$.  Put $y= x - \\sum_{i=1}^k (x, u_i ) b_i^{-1} u_i$ then $y \\in V_k^{\\perp}$.\r\n\\end{quote}\r\n{\\bf Theorem 13:} If $B$ is a non-degenerate bilinear form over $V$ and $U \\subseteq V$ is a \r\nsubspace then $V= U \\oplus U^{\\perp}$.  \r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $( u_1 , \\ldots , u_r )$ be a basis for $U$.  Extend $U$ to a basis for $V$\r\nby adding $(u_{r+1} , \\ldots , u_n )$.\r\nIf $(u_i, u_j) = a \\ne 0, i \\le r, j>r$, replace\r\n$u_j$ with $u_j'= u_j - {\\frac {a} {(u_i, u_i)}} u_i$.  This process can continue until\r\nwe have a basis $(u_1 , \\ldots , u_r, u_{r+1}', \\ldots , u_n' )$ with the property that\r\n$(u_i, u_j')=0, i \\le r, j>r$.  $ \\langle u_{r+1}', \\ldots , u_n' \\rangle = U^{\\perp}$.\r\n\\end{quote}\r\n{\\bf Theorem 14:} \r\nAny non-degenerate symmetric bilinear form on $V$ over $F$, $char(F) \\ne 2$ is equivalent to\r\none with matrix $diag(1,1,\\ldots,1,d)$, $d= Disc(B)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nUse Lagrange diagonalization and take $b_1 = b_2 = \\ldots =b_{n-1}=1$, the last diagonal element\r\nmust preserve the discrimanent and so must be $d$.\r\n\\end{quote}\r\n{\\bf Theorem 15:} \r\n(1) The following are equivalent:\r\n(i) $V$ is a hyperbolic plane, \r\n(ii) $V$ has hyperbolic pair $(u,v)$ as a basis (i.e.- $(u,u)=0=(v,v), (u,v)=1$),\r\n(iii) $disc(B)= (-1) (F^*)^2$,\r\n(2) any two hyperbolic planes are isometric,\r\n(3) any hyperbolic plane contains two one dimensional totally isotropic subspaces,\r\n(4) the rotation group of a hyperbolic plane is isomorphic to $F^*$ and every improper\r\ntransformation on $V$ is a symmetry.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n\\\\\r\n(1) If $V$ is a hyperbolic plane, $\\exists 0 \\ne u \\in V: Q(u)=0$ and since\r\n$V^{\\perp}=0$ and $\\exists v \\in V: (u,v) \\ne 0$.  Since $(u,u)= 0$,\r\n$v$ is not a multiple of $u$.  Hence $(u, v)$ is a base.  Replacing $v$ by a multiple of\r\n$v$, we may assume $(u, v) = 1$.  Moreover, if $a \\in F$ then $Q(v+au) = Q(v) +a$ so if \r\nwe replace $v$ with $v-Q(v)u$, we have $Q(v)=0$ and $(u, v)= 1$ so $(i) \\rightarrow (ii)$. \r\nAssume $(ii)$.\r\nThe matrix that describes $B$,  is $-1$.    Hence the discriminant of $B$ is\r\n$(-1)(F^*)^2$.  We have a base $(u_1, u_2 )$ such that the matrix for $B$ with respect to\r\n$(u_1, u_2 )$ is $diag(b_1 , b_2 )$ where $b_1 b_2 = -c^2>0, c \\in F$.  Let\r\n$x= cu_1 + b_1 u_2$,\r\nthen $Q(x)= {\\frac 1 2} c^2 b_1 + {\\frac 1 2} b_1^2 b_2 = 0$. Hence $V$ is a hyperbolic\r\nplane and we proved $(iii) \\rightarrow (i)$.\r\n\\\\\r\n(2) Any two hyperbolic planes have bases $(x, y)$, $(x', y')$ which are hyperbolic pairs.\r\n$u \\mapsto u', v \\mapsto v'$ is an isometry.\r\n\\\\\r\n(3) Let $(u,v)$ be a base  which is a hyperbolic pair, then $Q(au+bv)=ab$.  So $au+bv$ is\r\nisotropic iff either $a=0, b \\ne 0$ or $a \\ne 0, b=0$  then $Fu$ and $Fv$ are the only\r\none dimensional totally isotropic subspaces of $V$.\r\n\\\\\r\n(4)  Let $\\eta$ be an orthogonal transformation of the hyperbolic plane $V$ and let\r\n$Fu$ and $Fv$ be the two one dimensional totally isotropic subspaces.\r\nThen either $\\eta(Fu)=Fu$ and $\\eta(Fv)=Fv$ or\r\n$\\eta(Fu)=Fv$ and $\\eta(Fv)=Fu$.\r\nIn the first case, $\\eta(u)= au, \\eta(v)= bv$ and $ab(u,v)= (\\eta(u). \\eta(v))= (u,v)$\r\ngives $ab= 1$ since $(u,v) \\ne 0$.  Hence \r\n$\\eta(u)= au$ and\r\n$\\eta(v)= a^{-1}v$ and $\\eta$ is a rotation.  In the second case,\r\n$\\eta(u)= av$ and\r\n$\\eta(v)= bu$ and again, $b= a^{-1}$ and $\\eta$ is improper.\r\nFor any $a \\ne 0$, the linear maps \r\n$u \\mapsto au, v \\mapsto a^{-1}v$ and\r\n$u \\mapsto av, v \\mapsto a^{-1}u$ are rotations or improper.  The map from\r\n$F^*$ into the rotations is an isomorphism of $F^* \\rightarrow O^+ (V,Q)$. \r\nFinally, if $\\eta$ is improper, $\\eta(u + av)= u + av$ and\r\n$\\eta(u - av)= -(u - av)$ hence $\\eta$ is the symmetry $S_{u-av}$.\r\n\\end{quote}\r\n{\\bf Theorem 16:} An alternate non-degenerate bilinear form is equivalent to one in which the matrix is\r\n$diag(H,H,..., H)$,\r\nwhere $H=\r\n\\left(\r\n\\begin{array}{cc}\r\n0 &  1 \\\\\r\n-1 &  0 \\\\\r\n\\end{array}\r\n\\right)$.  \r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nBy induction.  In inductive step, we have $u_i , v_i $ with the properties\r\n$(u_i, v_i)= 1 = -(v_i , u_i)$ and $(u_i , u_i ) = 0 = (v_i , v_i )$.  Put\r\n$V_k = \\langle u_1, v_1 , \\ldots , u_k , v_k \\rangle $.  $V_k \\cap V_k^{\\perp} = 0$.\r\nLet $y \\in V$ then $y= x - \\sum_{i=1}^k (x, v_i ) u_i + \\sum_{i=1}^k (x, u_i) v_i$ then\r\n$y \\in V_k^{\\perp}$ and we can show $V= V_k \\oplus V_k^{\\perp}$.\r\n\\end{quote}\r\n{\\bf Witt's Cancellation Theorem:}  Let $Q$ be a non-degenerate quadratic \r\nform and $char(F) \\ne 2$ and\r\nsuppose two subspaces, $U_1$ and $U_2$ are isometric, then \r\n$U_1^{\\perp}$ and\r\n$U_2^{\\perp}$ are isometric.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nBy induction on $dim(U_i)$.  If $U_i= F u_i$ and \r\n$Q(u_1) \\ne 0$, we may assume\r\n$Q(u_1) = Q(u_2) $.  $Q(u_1 \\pm u_2)= 2 Q(u_1) \\pm (u_1, u_2)$, so either\r\n$Q(u_1 + u_2) \\ne 0$ or \r\n$Q(u_1 - u_2) \\ne 0$.  Define $S_u: x \\mapsto x- {\\frac {(x,u)} {(u,u)}} u$.\r\nIn the first case, \r\n$S_{u_1 + u_2}(u_1 - u_2) = u_1 - u_2$ and\r\n$S_{u_1 + u_2}(u_1 + u_2) = -(u_1 + u_2)$, so $(u_1 - u_2) \\perp (u_1 + u_2)$ and a simple\r\ncalculation shows $S_{u_1 + u_2}(Fu_1)^{\\perp} = (Fu_2)^{\\perp}$ and $U_1^{\\perp}$ is\r\nisometric to $U_2^{\\perp}$.  Now suppose the result is true for $dim(U_i)=n-1$.\r\nChoose a non-isotropic $u_1 \\in U_1$ and write \r\n$U_1= F u_1 \\perp  W_1$ and\r\n$U_2= F u_2 \\perp  W_2$.  \r\nSo $V = F u_1 \\perp W_1 \\perp U_1^{\\perp} = F u_2 \\perp W_2 \\perp U_2^{\\perp}$.\r\nApply the one-dimensional case to show there is an isometry, $\\eta$, from\r\n$W_1 \\perp U_1^{\\perp}$ to $W_2 \\perp U_2^{\\perp}$.  The induction hypothesis applied\r\nto $W_2, \\eta(W_1)$ shows $U_2^{\\perp}$ is isometric to $\\eta(U_1^{\\perp})$ which\r\nis in turn isometric to $U_1^{\\perp}$.\r\n\\end{quote}\r\n{\\bf Theorem 17:}  Let $V$ be equipped with a non-degenerate form and $U$ be a subspace such that\r\n$rad(U)= U \\cap U^{\\perp} \\ne 0$.  Write $U= rad(U) \\oplus U'$ and let $z_1, \\ldots, z_r$\r\nbe a base for $rad(U)$.  U can be imbedded in a non degenerate subspace $U \\oplus W$ where\r\n$W$ has a base $w_1 , \\ldots, w_r$ such that $z_i, w_i$ is a hyperbolic pair, $H_i= Fz_i + F w_i$,\r\nand\r\n$U \\oplus W = U' \\perp H_1 \\perp \\ldots \\perp H_r$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $f$ be a linear function on $U$ with $f(z_1 ) =1, f(z_i ) = 0 , i \\ne 1$ and\r\n$f(u' )= 0, u' \\in U'$.  $\\exists w_1 \\in V:f(u)= (u, w_`), u \\in U$.  Thus\r\n$(z_1, w_1 )=1, (z_i , w_1 ) =0, i>1$ and $(u', w_1)=0, u' \\in U'$.  Replacing\r\n$w_1$ by $w_1 + a z_1$, we may assume $Q(w_1 ) = 0$ and $(z_1, w_1)$ is a hyperbolic pair.\r\n$V= (F z_1  + F w_1 ) \\oplus (F z_1  + F w_1 )^{\\perp}$ and\r\n$U_1= U' + \\sum_{j>1} F z_j \\subseteq V_1= (F z_1  + F w_1 )^{\\perp}$.  \r\n$rad(U_1)=  \\sum{j>1} F z_j$.  If $r>1$, we take $W= F w_1$ and we have\r\n$U \\perp W = U' \\perp H_1$, $H_1= F z_1 + F w_1$.  If $r>1$, we replace\r\n$U, V$ with $U_1, V_1$ and note that $rad( U_1 ) =r-1$ hence by induction we get\r\n$w_2 , \\ldots , w_n$ such that $U_1 + \\sum_j F w_j = U' \\perp H_2 \\perp \\ldots \\perp H_r$\r\nand $H_j= F z_j + F w_j$.  $W= \\sum_{i=1}^r F w_i$ satisfies the conclusion.\r\n\\end{quote}\r\n{\\bf Witt Extension Theorem}  Let $Q$ be a non-degenerate quadratic form and $char(F) \\ne 2$ and\r\nsuppose two subspaces, $U_1$ and $U_2$ are isometric, then the isometry can be extended to all\r\nof $V$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $\\eta$ be an isometry between $U_1$ and $U_2$.  If $U_1$ is non-degenerate, so is $U_2$\r\nand $\\eta$ can be extended to an orthogonal transformation.  If $rad(U) \\ne 0$, we\r\napply the previous result, $U_1 = rad(U_1 ) \\oplus U_1'$ and\r\n$U_1 + W_1 U_1' \\perp H_1 \\perp \\ldots \\perp H_r$ where $H_i= F z_i + F w_i$ is a hyperbolic pair.\r\nImbed $U_2= \\eta(U_1 )$ in $U_2 + W_2\r\n\\eta(U_1') \\perp H_1' \\perp \\ldots \\perp H_r'$ where $H_i'= F \\eta(z_i) + F w_i'$\r\nis a hyperbolic pair.\r\n$U_1 + W_1 \\rightarrow U_2 + W_2$ coincides with $\\eta$ on $U_1$ and sends $w_i \\mapsto w_i'$\r\nand is an isometry of\r\n$U_1 + W_1$ and $U_2 + W_2$.  Since \r\n$U_1 + W_1$ is non-degenerate, this can be extended to an orthogonal transformation and\r\nthus so can $\\eta$.\r\nIf $rad(U) = 0$, Witt's Cancellation Theorem proves it.\r\n\\end{quote}\r\n{\\bf Definition 1:} A vector $v$ is \\emph{isotropic} if $B(v,v)=0$.  The \\emph{Witt index}\r\nis the common dimension of maximal totally isotropic subspaces. $\\tau_{u,c} (x)= x+cB(x,u)u$\r\nare called \\emph{symplectic transvections}.  Note that by Witt's Theorem all such maximally\r\nisotropic subspaces are isometric and that quadratic forms are equivalent if their\r\nanisotropic subspaces are.\r\nA \\emph{symplectic base} is a base\r\n$u_1, \\ldots, u_r, v_1 , \\ldots , v_r, 2r=n$ such that $(u_i, u_j)=(v_i, v_j)=0$ and\r\n$(u_i, v_j)= \\delta_{ij}= - (v_j, u_i)$.  Note that \r\n$\\eta \\in Sp_n(F) \\rightarrow \\eta \\tau_{u,c} \\eta^{-1}= \\tau_{\\eta, c}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 19:}\r\nAny orthogonal transformation is a product of symmetries.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $\\eta$ be orthogonal and $U: Q(u) \\ne 0$.  As in the proof of Witt's Cancellation\r\nTheorem, there is a symmetry, $S_w(x)= x- 2 {\\frac {(x,w)}{(w,w)}}w$, \r\n$w= u + \\epsilon \\eta(u)$ such that $\\eta'(u) = - \\epsilon u$ for $\\eta'= S_w \\eta$ and\r\n$\\epsilon = \\pm 1$.  $\\eta'$ stabilizes $Fu^{\\perp}$ which is non degenerate and of dimension\r\n$n-1$.  By induction, \r\n$\\eta'_{|F u ^{\\perp}} = {\\overline S}_{w_1} {\\overline S}_{w_2} \\ldots {\\overline S}_{w_k}$\r\nwhere ${\\overline S}_{w_i}$ is determines by $w_i \\in F u^{\\perp}$.\r\n${\\overline S}_{w_i}= S_{w_i | F u^{\\perp}} $ and $u \\perp w_i$ so it fixes $u$.\r\nThen $\\eta''=\r\nS_{w_1} S_{w_2} \\ldots S_{w_k} \\eta$ is the identity on $F u^{\\perp}$ (reverse order for inverse).\r\nAlso, $\\eta''(u)= \\eta'(u)= \\pm u$.  If \r\n$\\eta''(u)= u$,\r\n$\\eta''=1$ and if\r\n$\\eta''(u)= -u$,\r\n$\\eta''= S_u$.  In either case, $\\eta'$ is a product of symmetries and hence so is\r\n$\\eta= S_u \\eta'$.\r\n\\end{quote}\r\n{\\bf Theorem 20:}\r\nIf $dim(V)=n$, any orthogonal transformation is a product of $ \\le n$ symmetries.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n\\\\\r\nCase 1: $V_1=Fix( \\eta)$ is not totally isotropic.\r\n\\\\\r\n$\\exists u: Q(u) \\ne 0$ and $\\eta$ stabilizes $F u^{\\perp}$, so by induction,\r\n$\\eta_{F u^{\\perp}})$ is a product of $n-1$ symmetries.\r\n\\\\\r\n\\\\\r\nCase 2: $\\exists u \\in V: Q(u) \\ne 0$ and $Q(u- \\eta(u)) \\ne 0$.\r\n\\\\\r\nAs in Witt, $\\exists S_w: \\eta= S_w \\eta'$ fixes $u$ and we're back in Case 1.\r\n\\\\\r\n\\\\\r\nCase 3:  $dim(V)=2$\r\n\\\\\r\nTrue by above if $V$ is anisotropic so $V$ is a hyperbolic plane, $u,v$ and\r\neither \r\n$\\eta(u)= au, \\eta(v)= a^{-1}v$ or\r\n$\\eta(u)= av, \\eta(v)= a^{-1}u$.  If $a=1$ the theorem holds trivially.\r\nIf $w= u+v$, $w- \\eta(w)= (1-a)u + (1-a^{-1}v$ satisfies $Q(w) \\ne 0, Q(w- \\eta(w)) \\ne 0$\r\nand the result holds as before.  If \r\n$\\eta(u)= av, \\eta(v)= a^{-1}u$, $w+av$ is fixed by $\\eta$ and $Q(v) \\ne 0$ and we're done by\r\ncase 1.\r\n\\\\\r\n\\\\\r\nCase 4:  Holds in all other cases, namely: $dim(V) \\ge 3$, $V_1=Fix( \\eta )$ is\r\ntotally isotropic and $Q(u- \\eta(u)) =0, \\forall u: Q(u) \\ne 0$.\r\n\\\\\r\nWe claim $Q(u- \\eta(u)) =0, \\forall u$.  STS this for the $w \\ne 0: Q(w)=0$.\r\nConsider $F w^{\\perp}$.  \r\n$dim(F w^{\\perp}) = n-1$, $n \\ge 3$, $n-1 > \\lfloor {\\frac n 2} \\rfloor$ so\r\n$F w^{\\perp}$ is not totally isotropic.  So $\\exists u \\ne 0: u \\perp w, Q(u) \\ne 0$.\r\nThen $(w \\pm u) \\perp w$, $Q(w \\pm u) = Q(u) \\ne 0$.  Put $\\zeta= 1- \\eta$.\r\n$Q(\\zeta(w))= Q(w - \\eta(w)) =0$ and $\\zeta(V)$ is totally isotropic.  Put\r\n$V_1= (\\zeta(V))^{\\perp}$ then $V_1^{\\perp} = \\zeta(V)$ and we have both\r\n$V_1 \\subseteq \\zeta(V)^{\\perp}$ and\r\n$V_1 \\subseteq V_1^{\\perp} = \\zeta(V)^{\\perp}$ and $\\zeta(V) \\subseteq V_1$.\r\nThus $V_1 = \\zeta(V)$.  If $x \\in V$, then $\\zeta^2(x) = 0$ and $\\eta$ is unipotent.\r\n$n= dim(V_1) + dim(V_1^{\\perp})= 2dim(V_1)$.  Now put $\\eta'= S_w \\eta$ for any symmetry,\r\n$S_w$.  $\\eta'$ is improper and is thus a product of $k \\le n$ symmetries; in fact,\r\n$k \\le n-1$ and thus $\\eta= S_w \\eta'$ is a product of at most $n$ symmetries.\r\n\\end{quote}\r\n{\\bf Theorem 21:}\r\n$Sp_n(F)= \\langle \\tau_{u,c} \\rangle $.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nA symplectic transformation takes a hyperbolic pair into a hyperbolic pair.\r\n\\\\\r\n\\emph{Claim:} If $\\zeta \\in Sp_n(F)$ takes the hyperbolic pair $(u,v) \\rightarrow (u', v')$ then\r\n$\\zeta \\in \\langle \\tau_{u,c} \\rangle $. (Proof: do this in two transvections.)\r\n\\\\\r\nNote: $\\tau_{u, c_1} \\tau_{u,c_2} = \\tau_{u, c_1 + c_2}$ and for\r\n$\\eta \\in Sp(F)$, $\\eta \\tau_{u,c} \\eta^{-1} = \\tau_{\\eta u,c}$.\r\nGiven claim, let $\\eta: (u,v) \\mapsto (u',v')$ and set\r\n$\\eta'= \\zeta^{-1} \\eta$ where $\\zeta \\in \\langle \\tau_{u,c}: (u,v) \\rightarrow (u', v') \\rangle$ and fixes\r\nthe rest of $V$.  Then $\\eta'= \\zeta^{-1} \\eta$ \r\nfixes $(u,v)$ and stabilizes $(Fu \\oplus Fv)^{\\perp}$\r\nand by induction, $\\eta' \\in \\langle \\tau_{u,c} \\rangle $.\r\n\\end{quote}\r\n{\\bf Theorem 22:}\r\n${\\mathbb Z}(Sp_n(F))= \\{ 1, -1 \\}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nIf \r\n$T \\in {\\mathbb Z}(Sp_n(F))$, $T$ commutes with all $\\tau_{z,c}$.  The fixed points of\r\n$\\tau_{u,c}, c \\ne 0$ is $Fu^{\\perp}$ and $T$ maps fixed points into fixed points so\r\n$T$ stabilizes $F u^{\\perp}$ but $Fu= rad(F u^{\\perp})$ so $T$ stabilizes $Fu$ and\r\n$T$ is a scalar matrix.\r\n\\end{quote}\r\n{\\bf Definition:} ${\\mathbb P}_{n}(F)= \\{ (x_1, \\ldots, x_{n+1}): x_i \\in F\\}$ where not all $x_i$ are $0$ and\r\nwith $(x_1, \\ldots, x_{n+1}) \\sim \\lambda (x_1, \\ldots, x_{n+1}), \\lambda \\in F, \\lambda \\neq 0$. This is called\r\nthe projective space of dimension $n$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 23:}\r\n$Sp_n(F)$ acts primitively on ${\\mathbb P}_{n-1}(F)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $S= Stab(Sp_n(F))$.  We can show $S= {\\mathbb P}_{n-1}(F)$. $|S|>1$.  Suppose $(Fx, Fy): (x, y) \\ne 0$.\r\nAssume $(x, y) =1$.  Let $Fz \\in {\\mathbb P}_{n-1}(F)$; if $(x,z) \\ne 0$ we may\r\nassume $(x,x)=1$.  By Witt,\r\n$\\exists \\eta \\in Sp_n(F): \\eta(x)= x, \\eta(y)=z$,\r\nthen $\\eta(S)= S$, since $Fx \\in S$, $Fz \\in S$ and since $F(y) \\in S$, $\\eta(y)= z$.\r\nNow suppose $(x, z) = 0$ and $Fz \\ne Fx$ then $\\exists Fw \\in S$.\r\nWe have $\\zeta \\in Sp_n(F): \\zeta(w)= w, \\zeta(x)=z$ then $\\zeta(S)=S$. \r\n$(x,w)=1=(x,z)$ since\r\n$Fw \\in S$, $Fz \\in S$ because $Fx \\in S$.\r\n\\\\\r\n\\\\\r\nThus $S= {\\mathbb P}_{n-1}(F)$ if $S$ contains $(Fx, Fy)$ be a pair of points in \r\n$S: (x,y) \\ne 0, \\exists u \\in V$,\r\n$(x,u) = 1, (y, u) = 0$.  Let $U= (Fx + Fu)^{\\perp}$ and let $G < Sp_n(F)$.\r\n$\\eta(t)=t$ if $t \\in Fx + Fu$.  These map the set of restrictions $\\eta_{|U}$\r\nin the symplectic group on $U$.  Let $z \\in U, z \\ne 0$.  Since $y \\in U$\r\n$\\exists \\eta \\in G: \\eta(y)=z$.  Now $\\eta(S)=S$ since $Fx \\in S$ and since\r\n$Fx, Fy \\in S$, we have $Fx \\in S$.  This shows that every $0 \\ne z \\in U$,\r\nis in $S$, since $U$ contains a hyperpolic pair, we've reduced to the argument in the first\r\nparagraph.\r\n\\end{quote}\r\n{\\bf Theorem 24:}\r\n$Sp_n(F) = Sp_n(F)'$ except for $n=2, |F|= 2,3$ or $n=4, |F|=2$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nIf $|F|>3$, given $\\tau_{z,c} \\ne 1$, pick $d \\ne 0$, $d^2 \\ne 1$,\r\n$b=(1-d^2)^{-1}c$ and $a= -d^2b$, then $a+b=c$ and \r\n$ \\tau_{z,c} = \\tau_{z,a} \\tau_{z,b}$.  Let $\\eta$ be a symplectic transformation then\r\n$\\eta \\tau_{z,b}^{-1} \\eta^{-1} =\r\n\\eta \\tau_{z,-b} \\eta^{-1}=\r\n\\tau_{\\eta(z),-b}= \\tau_{dz,-b}= \\tau_{z,-bd^2}= \\tau_{z,a}$ and hence\r\n$\\tau_{z,c}= \\eta \\tau_{z,b}^{-1} \\eta^{-1} \\tau_{z,b}$.\r\n\\end{quote}\r\n{\\bf Theorem 25:}\r\n$Sp_n(F)$ is simple except for $n=2, |F|= 2,3$ or $n=4, |F|=2$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nFollows from the two previous results and simplicity theorem.\r\n\\end{quote}\r\n{\\bf Theorem 26:} \r\n$|Sp_n(q)| = q^{n-1} (q^n-1) q^{n-3} (q^{n-2} -1) \\ldots q(q^2-1)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$|Sp_n(q)| = q^{n-1} (q^n-1) |Sp_{n-2}(q)|$ because there are \r\n$q^{n-1}(q^n-1)$ ways to map a hyperbolic pair with respect to a hyperbolic\r\npair and $|Sp_{n-2}(q)|$ ways to map the complementary space. (There are\r\n$q^n-1)$ ways to pick  the first vector.  The second vector has to be a\r\nsolution to $(x_1)^{(2)} \\cdot (y_1)^{(1)} + (y_1)^{(2)} \\cdot (x_1)^{(1)} + \\ldots +\r\n(x_k)^{(2)} \\cdot (y_k)^{(1)} + (y_k)^{(2)} \\cdot (x_k)^{(1)} = 1$.  There are\r\n$q^{n-1}$ such solutions.)\r\n\\end{quote}\r\n{\\bf Theorem 27:}\r\n$|PSp_{2l}(q)|= {\\frac 1 {(2,q-1)}} q^{l^2}(q^{2} -1) (q^{4} -1) ...  (q^{2l} -1)$,\r\nis simple unless $(2l,q)= (2,2), (2,3), (4,2)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$|PSp_{2l}(q)|= {\\frac {|Sp_{2l}(F)|} {|{\\mathbb Z}(Sp_{2l}(F))|} }$ and the center is has order\r\n$2$ or $1$ depending on whether $q-1$ is divisible by $2$.\r\n\\end{quote}\r\n{\\bf Theorem 28:}\r\nLet $F_1(x_1,y_1, \\ldots, x_r, y_r) =x_1^2 - y_1^2 + \\ldots + x_r^2 - y_r^2$, \r\n$F_2(x_1,y_1, \\ldots, x_r, y_r, x_{r+1}) =x_1^2 - y_1^2 + \\ldots + x_r^2 - y_r^2-x_{r+1}^2$, and\r\n$F_3(x_1,y_1, \\ldots, x_r, y_r, x_{r+1}) =x_1^2 - y_1^2 + \\ldots + x_r^2 - y_r^2- dx_{r+1}^2$.\r\nThe number of solutions of \r\n$F_1(x_1, y_1, \\ldots, x_r, y_r)=b$ over $F_{q}$ is\r\n$q^{2r-1}+q^r-q^{r-1}$ if $b=0$ and\r\n$q^{2r-1}-q^{r-1}$ if $b \\ne 0$.\r\nThe number of solutions of \r\n$F_2(x_1, y_1, \\ldots, x_r, y_r, x_{r+1})=b$ over $F_{q}$ is\r\n$q^{2r}$ if $b=0$, $q^{2r}-q^r$ if $-b \\ne 0$ is not a square and\r\n$q^{2r}+q^r$ if $-b \\ne 0$ is a square.\r\nThe number of solutions of \r\n$F_3(x_1, y_1, \\ldots, x_r, y_r, x_{r+1})=b$ over $F_{q}$ is\r\n$q^{2r-1}-q^{r} + q^{r-1}$ if $b = 0$ and\r\n$q^{2r-1}+q^{r-1}$ if $b \\ne 0$.\r\n\\begin{quote}\r\n\\emph{Proof:} For $r=1$, $x^2-y^2=b$, put $u=(x-1), v=(x+y)$.  So the number of solutions for \r\n$b=0$ is the number of $u,v: uv=0$; there are $2q-1$ of these.  For $b \\ne 0$, the\r\nnumber of solutions is $q-1$.  Now applying induction, let $b= a+c$, \r\n$a= \\sum_{i=1}^r x_i^2-y_i^2$ and $c= x_{r+1}^2-y_{r+1}^2$.\r\n$N_q(2(r+1),0) = (2q-1) N_q(2r,0) + (q-1) N_q(2r,c), c \\ne 0$.  The remainder of the proof is\r\nsimilar.\r\n\\end{quote}\r\n{\\bf Definition 2:} Let $Q$ be a quadratic form.\r\nThe \\emph{orthogonal} group on a vector\r\nspace, $V$, denoted $O(V,Q)$ is the\r\ngroup fixing lengths.\r\n$O(V,Q)^+$ is the subgroup of \\emph{rotations}. \r\n\\\\\r\n\\\\\r\n{\\bf Theorem 28a:} Any non-degenerate symmetric form over $F_q$ is equivalent to one of the following:\\\\\r\n(a) [even dimension] $diag(1, -1, 1, -1 , \\ldots , 1, -1)$, ($\\epsilon = 1$);\\\\\r\n(b) [even dimension] $diag(1,-1, \\ldots , 1, -d)$, ${\\frac {-d} {q}}) = -1$, ($\\epsilon = -1$); \\\\\r\n(c) [odd dimension] $diag(1, -1, 1, -1 , \\ldots , 1, -1, -d), ({\\frac {-d} {q}}) = -1$; \\\\\r\n(d) [odd dimension] $diag(1, -1, 1, -1 , \\ldots , 1, -1, -d), ({\\frac {-d} q}) = 1$.\r\n\\begin{quote}\r\n\\emph{Proof:} Lagrange reduction. Note that types (c) and (d) yield non-isometric spaces but isomorphic\r\ngroups.  (a) and (b) yield non-isomophic groups.\r\n\\end{quote}\r\n{\\bf Notation for orthogonal groups:}\r\nA vector, $x$, is called \\emph{isotropic} if $(x, x) = 0$.\r\nA space, $V$, is called \\emph{anisotropic} if $\\forall x \\in V, (x, x) \\ne 0$.\r\nA \\emph{symmetry} in $V$ is the linear map\r\n$S_u : x \\mapsto x - 2 {\\frac {(x,u)} {(u,u)}} u$.  Note that $\\eta S_u \\eta^{-1}= S_{\\eta(u)}$.\r\nNote that $S_u$ is the identity on $Fu^{\\perp}$ and the matrix for $S_u$ is\r\n$diag(-1, 1, \\ldots , 1)$ where $u$ is in the first position.\r\n\\\\\r\n\\\\\r\n{\\bf Dimension $2$:}\r\nLet $(u, v)$ be a hyperbolic pair.  $\\eta_a$, \r\n$\\eta_a(u)= au$ and\r\n$\\eta_a(v)= a^{-1}v$.  The map $a \\rightarrow \\eta_a$ is a map from\r\n$F^* \\rightarrow O^+(V,Q)$.  \\emph{Improper} transformation, \r\n$\\tau_b$,  $\\tau_b(u)= b v$ and $\\tau_b(v)= b^{-1}u$.\r\nWe have $\\tau_b \\eta_a \\tau_b^{-1}= \\eta_a^{-1}$.  $O(V,Q)$ is a semi-direct product\r\nof $F^*$ and $Z_2$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 28b:} If $B$ is a symmetric bilinear form and there is a $u \\in V, u \\neq 0$ such that\r\n$(u,u)=0$ then $(u,u) = b$ has a solution for any $b$ ($B$ is called universal in this case).\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSuppose $\\exists u: (u,u) = 0$.  Since the form is non-degenerate,\r\n$\\exists w: (u,w) = {\\frac 1 2}$.  Put $v=au+w$ and take $a = b -(w,w)$.  This gives\r\n$(v,v) = b$.  For the non-isotropic case, we may assume $B= diag(a,b)$ and\r\nwe want to solve $ax^2 + by^2 = c$.  We can divide and take $a=1$.\r\nIf $x^2 + b y^2 \\neq 0$, then $({\\frac {-b} {q}}) = -1$. So $x^2+by^2$ is\r\nthe norm in $K/F$. $u \\mapsto u^q$ is an automorphism.  $N_{K/F}(u)= u^{q+1}$.\r\nbut $K$ is cyclic with kernel of size $q+1$ and image of size $q-1$.  So the automorphism\r\nis surjective.\r\n\\end{quote}\r\n{\\bf Theorem 28c:}\r\nIf $V$, $dim(V)=2$, has a non-degenerate symmetric bilinear form \r\nthen $\\nu(Q) \\le \\lfloor {\\frac n 2} \\rfloor$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nObvious from the definition.\r\n\\end{quote}\r\n{\\bf Theorem 28d:}\r\n$|O_n(q)| = \\lambda_n |O_{n-2}(q)|$, $\\lambda_n$ is the number of hyperbolic pairs in $V$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nConsider a map, $g$, from a hyperbolic pair to a hyperbolic pair ($\\langle u_1, v_1 \\rangle \\mapsto \\langle u_2, v_2 \\rangle$),\r\nextended to all of $O_n(q)$.  If $h \\in O_n(q)$ is any map taking the first hyperbolic pair into the second, put\r\n$t= h^{-1}g$.  $t$ is the identity on $\\langle u_1, v_1 \\rangle$; in fact, $t = id_{\\langle u_1, v_1 \\rangle} \\perp t'$,\r\n$t' \\in \\langle u_1, v_1 \\rangle ^ {\\perp}$, $t' \\in O_{n-2}(q)$. $\\lambda_n$ is calculated from\r\nTheorem 28.\r\n$\\lambda_n = q^{n-2} (q^{n-1} - 1)$ if $n$ is odd and\r\n$\\lambda_n = q^{n-2} (q^{n/2} - \\epsilon) (q^{n/2-1} + \\epsilon) $, if $n$ is even.\r\n\\end{quote}\r\n{\\bf Definition:} If $Q(x) = 0$, $u, z \\in Fx^\\perp$, $dim(V) \\geq 3$, define $\\eta_{x,u}(z) = z + (z,u) x$.\r\nNote that $x \\in F u^\\perp$ means $\\eta_{x,u}(x) = x$, $\\eta_{x,u}^{-1} = \\eta_{x,-u}$ and\r\n$\\eta_{x, u_1 + u_2} = \\eta_{x,u_1} + \\eta_{x,u_2}$.  Note also that \r\n$Q(z + (z,u)x)= Q(z) + (z,(z,u)x) + (z,u)^2 Q(x) = Q(z)$.  In the next few theorems,\r\nwe pick $y$ such that $Q(y)=0$ and $(x, y) = 1$ so $V = Fx + Fy + U$, $U = (Fx + Fy)^\\perp$ and\r\n$Fx^\\perp = Fx + U$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 28e:} Let $V, x, u, z, \\eta_{x,u}$ be as in the above definition with $(\\cdot, \\cdot)$, non-degenetate.\r\nextends uniquely to an isometry $\\rho_{x, u} \\in O(V)$. $\\rho_{x, u}$ is called a Siegal transformation.\r\nFurther, \r\n$\\rho_{x, u_1 + u_2} = \\rho_{x,u_1} + \\rho_{x,u_2}$ and \r\n$\\eta \\in O(V, Q) \\rightarrow \\eta \\rho_{x,u} \\eta= \\rho_{\\eta(x),  \\eta(u)}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nDefine $\\rho_{x, u}(w) = \\eta_{x,u}(w)$ if $w \\in Fx^\\perp$ and $\\rho_{x, u}(y) = ax + by + v$, $v \\in U$.\r\nNote that if $\\rho_{x, u}$ is well defined, it's domain is $V$.\r\nIf $\\rho_{x, u}$ is an isometry, some selection of $a, b, v$ must give $Q(\\rho_{x, u}(y)) = Q(y) = 0$ and\r\n$(\\rho_{x, u}(y), \\rho_{x, u}(z)) = (y,z)$ if $z \\in Fx^\\perp$.  The conditions are $Q(\\rho_{x,u}(y) =0$\r\nand $(\\rho_{x,u}(y), \\rho_{x,u}(z)) = (y,z) = 1$, if $z \\in Fx^\\perp$.  These hold if the following holds:\r\n$ab + Q(v) = 0$, $b = 1$ and $(z,u) + (z, v) = 0$.  These hold if $b = 1$, $a = -Q(v)$ and $v = -u$.  So the\r\ndefinition of $\\rho_{x, u}$ becomes $\\rho_{x, u}(w) = \\eta_{x,u}(w)$ if $w \\in Fx^\\perp$ and\r\n$\\rho_{x, u}(y) = -Q(u)x + y - u$ and all conditions are satisfied.  The extension is unique because there is\r\na unique solution to the necessary conditions.\r\n\\end{quote}\r\n{\\bf Definition:} We define the\r\n``root'' transformations as the\r\ntransformations $\\tau_{u,v, \\lambda}: x \\mapsto x + \\lambda (x,u) v - \\lambda (x,v) u$ with\r\n$(u, v)$ satisfing $(u,u)= (v,v) = 0$, $(u,v)=1$.  Note that unless $char(F) =2$, an\r\northogonal space has no transvections. \r\nA \\emph{flat} is an isotropic subspace.  Define ${\\cal C}= \\{x: Q(x)=0 \\}$, a \r\n${\\mathbb P} {\\cal C}$ be the corresponding set in projective space.  \r\nLet $V, x, u, z, \\eta_{x,u}$ be as in the above definition and $dim(V) \\ge 3$.\r\nLet $x$ be an isotropic vector in $V$, $H_x=  \\langle \\rho_{x,u} \\rangle $, $U= Fy + F u^{\\perp}$,\r\n$y: (x,y)=1, Q(y)=0$.  \\emph{Define} $\\Omega= \\langle H_x \\rangle $, $x$ isotropic.\r\n\\\\\r\n\\\\\r\n{\\bf Lemma 1:}\r\nLet $V, x, u, z, \\eta_{x,u}$ be as in the above definition and $dim(V) \\ge 3$.\r\n$H_x$ is a normal abelian subgroup of $Stab_{O(V)}(x)$ and\r\n$u \\mapsto \\rho_{x,u}$ is an isomorphism of $U^+$ with $H_x$.  $\\eta H_x \\eta^{-1}= H_{\\eta(x)}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nIf $\\eta \\in O(V,Q)$, $\\eta H_x \\eta^{-1}=H_{\\eta x}$, $x$, isotropic. \r\n$\\Omega \\lhd Q(V,Q)$.  $\\Omega$ acts on a quadratic cone.  Let ${\\cal C} = \\{ x: Q(x)=0 \\}$ and\r\n$e_1 , e_2 , \\ldots , e_n$ a base for $V$ and $x= \\sum_i a_i e_i$.  \r\n$Q(x)=0 \\leftrightarrow \\sum_{i,j} b_{i,j} a_i a_j =0$, $b_{i,j}= (e_i, e_j)$.\r\n${\\cal C}$ is a cone, ${\\mathbb P}{\\cal C}$ is the cone in ${\\mathbb P}_{n-1}(F)$.\r\n\\end{quote}\r\n{\\bf Definition 4:}  $\\Omega= \\langle H_x \\rangle $, $x$ isotropic. Alternative definition:\r\n$\\Omega_n(q)= O_n(q)'$.\r\nNote: $\\Omega \\lhd O^+(V, Q) \\; char \\; O(V,Q)$.\r\n\\\\\r\n\\\\\r\n{\\bf Lemma 2:}\r\n$Z= {\\mathbb Z}(O(V,Q))= \\{ 1, -1 \\}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $\\gamma \\in Z$, $Fu= \\{x: S_u(x)= -x \\}$, $Fu= \\{x: S_u(x)= -x \\}$.\r\n$S_u(\\gamma(u)= \\gamma(S_u(u))= - \\gamma(u)$.\r\nIf $u_1 , \\ldots , u_n$ is an orthonormal basis for $V$. $\\gamma(u_i )= \\epsilon_i u_i$.\r\n$\\gamma(u_i + u_j )= \\pm (u_i + u_j)$.  $\\gamma(u_i + u_j + u_k ) = \\pm (u_i + u_j + u_k)$.\r\n\\end{quote}\r\n{\\bf Lemma 3:}\r\nIf $\\eta \\in O(V,Q)$ satisfies $\\eta(x) \\in F x$ then $\\eta= \\pm 1$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $(u,v)$ be a hyperbolic pair and $z \\in (Fu + Fv)^{\\perp}$, then $x=z-Q(z)u+v$\r\nis isotropic.  Thus, \r\n$\\eta(u)= c_u u$,\r\n$\\eta(v)= c_v v$ and\r\n$\\eta(x)= c_x x$.  Then \r\n$c_x(z-Q(z)u+v)= \\eta(x)= \\eta(z) - c_u Q(z) + c_v v$.\r\nSince $\\eta(z) \\in (Fu + Fv)^{\\perp}$, it follows that $\\eta(z) = c_x z$ and\r\n$c_x = c_u = c_v$.  Hence if $c = c_x$,\r\nwe have $\\eta=1$.  Since $\\eta$ is orthogonal, $c= \\pm 1$.\r\n\\end{quote}\r\n{\\bf Lemma 4:}\r\nLet $T_x= {\\cal C} \\cap F x^{\\perp}$, $PT_x= \\{Fy \\ne 0: y \\in T_x \\}$ then $H_x$ acts transitively\r\non the complement of $PT_x$ in ${\\mathbb P}{\\cal C}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nThis means $y, z$ are isotropic vectors not orthogonal to $x$.  There is a $\\rho_{x,u} \\in H_x$\r\nsuch that $\\rho_{x,u}(y) \\in Fz$.  We may assume $(y,x) = (z, x)$.   We have\r\n$V= Fy + F x^{\\perp} = Fx \\oplus Fy \\oplus U$ where $U= (Fx+Fy)^{\\perp}$.  $z= ay + bx +u, u \\in U$.\r\n$(Z,x)=1, a=1$ and since $Q(z)=0$, we have $b + Q(u)=0$ and so\r\n$z= y - Q(u) x +u$.  Then $\\rho_{x, -u}(y)=z$.\r\n\\end{quote}\r\n{\\bf Lemma 5:}\r\n$\\Omega$ is transitive on ${\\mathbb P}{\\cal C}$ and on the set of hyperbolic pairs of ${\\mathbb P}{\\cal C}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $Fx$ and $Fy$ be distinct points on ${\\mathbb P}{\\cal C}$.  $\\exists Fz \\in {\\mathbb P}{\\cal C}$ such that\r\n$(Fz, Fx)$ and $(Fx, Fz)$ are hyperbolic.\r\n$(Fx, Fy)$ is hyperbolic and $(x, y)$ is a hyperbolic pair.\r\nLet $u$ be a non-isotropic vector is $U= (Fx + Fy)^{\\perp}$.  Put $z= x- Q(u) y +u$ then\r\n$Q(z)= -Q(u) (x, y) + Q(u) = 0$ and $(z,x)= -Q(u) \\ne 0$ and $(z, y) = 1$.  So $Fz$\r\nsatisfies requirement.  Since $x, y$ are linearly independent, there is a linear function\r\nmapping $x, y \\mapsto 1$ so $\\exists z \\in V: (x,z) = 1 = (y,z)$.  Subtracting a\r\nmultiple of $X$ from $z$, we can get $Q(z) = 0$.\r\n$(Fz, Fx)$ and $(Fz, Fy)$ are hyperbolic so again we have $Fz$ satisfying the requirement.\r\nApply the previous lemma to get $\\eta \\in \\Omega: \\eta(Fx)= Fy$.   This gives the\r\ntransitivity of $\\Omega$ on ${\\mathbb P}{\\cal C}$.  Now let $(Fx, Fy)$ and $(Fx', Fy')$ be hyperbolic\r\nplanes.  $\\exists \\zeta \\in \\Omega:  \\zeta(Fx')= Fx'$ and $\\zeta(\\eta(Fy))= Fy'$.\r\nThen $\\zeta \\eta$ maps $(Fx, Fy)$ to $(Fx', Fy')$ proving the second statement.\r\n\\end{quote}\r\n{\\bf Lemma 6:}\r\n$\\Omega$ acts primitively on ${\\mathbb P}{\\cal C}$ except when $dim(V)=1, \\nu(Q)=2$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSuppose $\\nu(Q)=1$.  $(Fx, Fy)$ of ${\\mathbb P}{\\cal C}$ is hyperbolic so by lemma 5 it is $2$-transitive\r\non ${\\mathbb P}{\\cal C}$ then the action of $\\Omega$ is primitive.\r\nAssuming $\\nu \\ge 2$ omitting $dim(V) \\ne 4$ so $dim(V) \\ge 5$.  Let $S$ be one of the sets\r\nof a partition of ${\\mathbb P}{\\cal C}$ stabilized by $\\Omega$ and containing more than one point.\r\nPrimitivity follows if $S={\\mathbb P}{\\cal C}$.  Suppose $Fx, Fy \\in S, (x,y)=0$ then we can find isotropic\r\n$z$: $(x,z)= 1$, $(y, z)=0$.  $V= (Fx + Fz) \\oplus U$ where $U= (Fx +Fz)^{\\perp}$ is at\r\nleast three dimensional and non-degenerate,  Since $y \\in U, \\exists w \\in U: (y, w)$ is\r\na hyperbolic pair.  $dim(U) \\ge 3$ and $U$ contains isotropic vectors.  Applying Lemma 5,\r\nto $U$, $\\exists \\eta$ which is the product of $\\rho_{u,v}, u,v \\in U: \\eta(Fy)= Fw$.\r\nSince $x \\in (Fu + Fv)^{\\perp}$, this shows $\\eta(Fx)= Fx$.  Since $Fx \\in S$,\r\n$\\eta(S) = S$ and since $Fy, Fw \\in S$ and $(Fy, Fw)$ is  a hyperbolic pair.\r\nLet $Fz \\in {\\mathbb P}{\\cal C}: Fz \\ne Fx$.  $\\exists Fw: (Fx, Fy)$ and $(Fx, Fw)$, we get\r\n$\\eta \\in \\Omega: \\eta(Fx)= Fx, \\eta(Fy)= Fw, \\eta(S)= S$.\r\n$Fw, FZ \\in S$.  Since $Fz$ was arbitrary in $Fx^{\\perp} \\in {\\mathbb P}{\\cal C}$, we have $S= {\\mathbb P}{\\cal C}$.\r\n\\end{quote}\r\n{\\bf Lemma 7:}\r\n$ O(V,Q)' \\subseteq \\Omega $.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $(x, y)$ be a hyperbolic pair and $u$ is non-isotropic.  \r\n$\\exists \\rho \\in \\Omega: \\rho(u) \\in Fx + Fy, u_1 = x + Q(u)y$\r\nsatisfies $Q(u_1 ) = Q(u)$.  Hence $\\exists \\eta \\in O(V, Q): \\eta(u_1 ) =u$.  By lemma 5, \r\n$\\exists \\rho \\in \\Omega: \\rho(F(\\eta x))= Fx$ and $\\rho(F(\\eta y)) = Fx + Fy$.\r\nSince $u_1 \\in Fx + Fy$, $u= \\eta u_1 \\in \\eta(Fx) + \\eta(Fy)$ hence\r\n$\\rho(u) \\in \\rho(F(\\eta(x))) + \\rho(F(\\eta(y)))= Fx + Fy$.  If $S_u$ is a symmetry,\r\n$\\exists \\rho \\in \\Omega: \\rho S_u \\rho^{-1} = S_{u'}, u' \\in \\rho(u) \\in Fx+Fy$.\r\nLet $O_{x,y}= \\langle s_{u'}: u' \\in Fx + Fy \\rangle $.  Since there is a restriction of $S_{u'}$\r\nto $U= (Fx+Fy)^{\\perp}$ is the identity.  $\\eta' \\rightarrow  \\eta'_{|Fx+Fy}, \\eta' \\in O_{x,y}$\r\nis an isomorphism between $O_{x,y} \\rightarrow O(Fx+Fy, V)$ sending\r\n$O^+_{x,y} \\rightarrow O^+(Fx+Fy, Q)$.  Let be a rotation in $V$, \r\n$\\zeta = S_{u_1} \\ldots S_{u_{2k}}, u_i$ non-isotropic, \r\n$S_0, \\exists \\rho_i \\in \\Omega: u_i'= \\rho_i u_i \\in Fx + Fy$ then\r\n$\\zeta = (\\rho_1 S_{u_1} \\rho_1^{-1})  \\ldots (\\rho_{2k} S_{u_{2k}}\\rho_{2k}^{-1})$.\r\nSince $\\Omega \\lhd O(V,Q)$\r\n$\\zeta = \\rho S_{u_1'} \\ldots S_{u_{2k}'}$ and hence \r\n$O^+(V,Q)/ \\Omega \\cong O^+_{x,y}/(O^+_{x,y} \\cap \\Omega)$ and since\r\n$O^+_{x,y} \\cong O^+(Fx+Fy, Q)$ and $Fx + Fy$ is a hyperbolic time\r\n$O^+_{x,y}$ is abelian so $O^+_{x,y} / \\Omega$ is abelian and since\r\n$\\Omega \\supset (O^+(V,Q)')$ and we have $O(V,Q)' = O^+(V,Q)'$ and hence\r\n$\\Omega \\supset O(V,Q)'$.\r\n\\end{quote}\r\n{\\bf Dickson-Dieudonne Theorem:}\r\nLet $Q$ be a non-degenerate quadratic form of Witt index $\\nu$ in $V$,\r\n$dim(V) \\ge 3$ then $P \\Omega = O(V,Q)'/{\\mathbb Z}(O(V,Q)')$ is simple unless $n=4$ and\r\n$\\nu = 2$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$O(V,Q) \\subseteq \\Omega \\subseteq O(V,Q)$.  This also proves $\\Omega'= \\Omega$.\r\n$\\forall \\rho_{x,u} \\in \\Omega'$, $x$ isotropic, $u \\in F u^{\\perp}$.\r\nChoose $u \\in F x^{\\perp}$ and choose $y$ such that $(x, y)$ is a hyperbolic pair.\r\nLet $O_{x,y}$ be as in the lemma.  $O_{x,y}= O(Fx + Fy, Q)$ the \r\n$\\forall a \\in F^* , \\exists \\eta_a \\in O_{x,y}$.  Also, $\\exists \\tau \\in O_{x, y}: \r\n\\tau(x)=y, \\tau(y)=x$ and $\\tau \\eta_a^{-1} \\tau \\eta= \\eta_a^2$.\r\n\\end{quote}\r\n{\\bf Theorem 29:}\r\n$\\Omega(n,F)$ acts primitively on flat subspaces.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nThis is a restatement of Lemma 6.\r\n\\end{quote}\r\n{\\bf Notes on orthogonal groups:} Orthogonal groups over fields with odd characteristic do not have transvections and\r\n$SO_n(q) \\neq SO_n(q)'$, in general.  $SO_n(q)/\\Omega_n(q) =2$ if $q$ is not even and $n$ is odd. \r\n$-I \\in \\Omega_{2r}^{\\epsilon}(q)$ iff $q^r = \\epsilon \\jmod{4}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 30:} \r\n$|O_{2r}(q)|= 2 q^{r(r-1)} (q^r - 1) \\prod_{i=1}^{r-1} (q^{2i}-1)$.\\\\\r\n$|O_{2r}(q, d)|= q^{r(r-1)} (q^r + 1) \\prod_{i=1}^{r-1} (q^{2i}-1)$,\r\n$d$, non-square.\\\\\r\n$|O_{2r+1}(q)|= 2 q^{r^2} \\prod_{i=1}^{r} (q^{2i}-1)$.\\\\\r\n$|P\\Omega_{2r+1}(q)|= {\\frac 1 {(q-1,2)}}  q^{r^2} \\prod_{i=1}^{r} (q^{2i}-1)$.\\\\\r\n$|P\\Omega_{2r}^{\\epsilon}(q)|= {\\frac 1 {(4, q^r - \\epsilon)}} q^{r(r-1)} (q^r - \\epsilon) \\prod_{i=1}^{r-1} (q^{2i}-1)$.\\\\\r\n\\begin{quote}\r\n\\emph{Proof:}  By induction on $n$.  For $n=1$, $O_1(q)= \\{ 1, -1 \\}$.\r\nAssume $n \\ge 2$ and pick $x: Q(x)=1$.  $|G|= |x^G| |G_x|$ and $G_x \\cong O_{n-1}(q)$ on the\r\nspace $Fx^{\\perp}$.  Since $G$ is transitive on vectors of length $1$, $|x^G|$ will consist of\r\nall the vectors of length $1$.\r\nThus, for the case $n=2r$, \r\nfor example, $|x^G|= (q^{2r-1} -q^{r-1})$.  The\r\nresult follows mutatis mutandis in all cases.\r\nNote that \r\n$|O_n(q):SO_n(q)| = 2$,\r\n$|SO_n(q):PSO_n(q)| = 2$, if $n$ is even, $1$ otherwise.\r\n$|PSO_n(q):\\Omega_n(q)| = 2$.\r\n\\end{quote}\r\n{\\bf Theorem 31:}  If $dim(V) \\ge 3$ then $O^+(V,Q)= Q(V,Q)'$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nFollows from the fact that elements are products of $\\le n$ symmetries and the fact that\r\n$ \\langle S_u S_v)^2 \\rangle \\lhd O(V,Q)$.  \\emph{Note:} there is an \r\nisomophism $F^* \\rightarrow \\eta_a$.\r\n\\end{quote}\r\n{\\bf Theorem 32:} \r\n$|O^+_n(q)|= {\\frac {|O_n(q)|} {2}}$.  Since $\\Omega_n(q) \\cong O^+_n(q)/O_n(q)'$ and\r\n$-1 \\in \\Omega_n(q)= O_n(q)'$, for $n$, even but\r\n$-1 \\notin \\Omega_n(q)= O_n(q)'$, for $n$, odd, we also get the formulas for\r\n$P \\Omega_n(q)$ and $P \\Omega_n(q, d)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nFor $n=1$, groups consist of $\\pm 1$.  Proceed by induction on $n$.  Choose $x \\in V$ with\r\n$Q(x)=1$ and consider the orbit $Gx$, the set of vectors with $Q(y)=1$.\r\n$|G|= |x^G| |G_x|$. \r\nIf $G= O_n(q), n=2r$  $G_x$ is  isomorphic to thr orthogonal group in $Fx^{\\perp}$ relative to the restricted\r\n$Q$ and hence $O_{n-1}(q)$.  The number of solutions to $Q(y)=1$ is $q^{2r-1}-q^{r-1}$.  We may assume the formula\r\nfor $n-1=2r-1$.  For $O_n(q,d)$ do the same with $q^{2r-1}+q^{r-1}$.  The case $n=2r+1$ uses $O_{n-1}(q)$, $n-1=2r$.\r\n\\end{quote}\r\n{\\bf Notation:}\r\n${P\\Omega^{\\epsilon}}_{2l}(q)$ is used with $\\epsilon= \\pm 1$ to distinguish between the \r\ntwo cases in even order.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 33:}\r\n$P\\Omega_n(q)$ is simple if $n>2$, $n$, odd. \r\n${P\\Omega^{\\epsilon}}_{2l}(q)$ is simple if $l>2$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nApply Iwasawa's theorem given that if\r\n$G= P\\Omega_n(q)$, $G'=G$,\r\n$G$ acts primitively on flat spaces and $H \\lhd G_u$ \r\n$ \\langle H^G \\rangle = G$.\r\n\\end{quote}\r\n{\\bf Theorem 34:}\r\nFor $l \\ge 2$, $q$, odd,\r\n$P\\Omega_{2l+1}(q)$ is not isomorphic to $PSp_{2l}(q)$ despite having the same order.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$PSp_{2m}(q)$ has $\\lfloor {\\frac m 2} \\rfloor + 1$ conjugacy classes of elements of\r\norder $2$.\r\n$P \\Omega_{2l+1}(q)$ has $m$ conjugacy classes of elements of order $2$.\r\nIf $t \\in Sp_{2m}(q)$ with $t^2=1$\r\nor $t \\in \\Omega_{2m}(q)$ with $t^2=1$ then $V= V^+ \\oplus V^-$ where $vt= \\lambda v$\r\nfor $v \\in V^{\\lambda}$ and $V^+$ and $V^-$ are orthogonal.  There are $m$ possibilities\r\nfor the subspaces for these subspaces up to isometry; in the symplectic space, it interchanges\r\n$t$ and $-t$ in the symplectic case there is another with $t^2= -1$.\r\n\\end{quote}\r\n{\\bf Definition 5:} The transformation \r\n$\\tau_{u,c}: x \\mapsto x + c(x, u)u$, $u$, isotropic, ${\\overline c} = - c$, is a \r\n\\emph{unitary transvection}.  For the unitary form, let $\\sigma \\in F(q^2)/F(q)$ such\r\nthat $\\sigma^2=1$ ($\\sigma$ is like the complex conjugate operation over ${\\mathbb C})$.\r\n$ \\langle x, y \\rangle $ is a \\emph{hyperbolic plane} if \r\n$(x, y)= 1, (x,x)=(y,y)=0$. $(Fx, Fy)$ is a\r\n\\emph{hyperbolic pair} if $(x,y) \\ne 0$.  For a hyperbolic pair, define $\\eta_a$ by\r\n$\\eta_a(x)= ax, \\eta_a(v)= a^{-1}v$.  $K_0= \\{ a \\in K: {\\overline a} = a \\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Summary Theorem:} (a) All unitary transvections are of the form given above.  (b) If $V$ is a unitary\r\nspace with $dim(V) \\geq 2$ then $V$ is isotropic and $V$ is a direct sum of hyperbolic planes.\r\n(c) $U_n(q)$ is transitive on ${\\mathbb P}{\\cal C}_n(q^2)$.  (d) The unitary transvections\r\ngenerate $SU_n(q)$. (e) $SU_n(q)$ acts primitively on ${\\mathbb P}{\\cal C}_n(q^2)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nThis is similar to the proofs for the orthogonal case.\r\n\\end{quote}\r\n{\\bf Theorem 35:}\r\n$V = H_1 \\perp H_2 \\perp \\ldots \\perp H_r \\perp W$; the $H_i$ are hyperplanes and $W$ is\r\nanisotropic.\r\n$SU_n(F)$ is generated by unitary transvections and acts primitively on isotropic lines.\r\nFurther, let $A= \\langle \\tau_{\\lambda,u} \\rangle $ for fixed $u$.  \r\n$A \\lhd SU_n(q)_u$ and $A' = 1$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nThis is a straightforward computation.\r\n\\end{quote}\r\n{\\bf Theorem 36:}\r\n$SU_n(F)'=SU_n(F)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nEvery unitary transvection is a commutator, as in the linear group.  These generate\r\n$SU_n(q)$.\r\n\\end{quote}\r\n{\\bf Theorem 37:} \r\n$|PSU_n(q^2)|= (n, q+1)^{-1} q^{\\frac {n(n-1)} {2}} \\prod_{i=1}^n (q^{2i}-(-1)^i)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $y_n$ be the number of vectors of norm $1$ and $z_n$ be the number of vectors of norm $0$ in an $n$\r\ndimensional unitary space.\r\n$q^{2n}= 1+ z_n + (q-1) y_n$, $z_0 = z_1 =0$,\r\n$z_{n+1}= z_n + (q^2-1) y_n$, so \r\n$z_n= (q^n - (-1)^n)(q^{n-1} + (-1)^n)$\r\n$y_n= q^{n-1}(q^n - (-1)^n)$.\\\\\r\n$|GU_n(q^2)|= \\prod_{i=1}^n q^{i-1} (q^i - (-1)^i)= q^{\\frac {n(n-1)} 2} \\prod_{i=1}^n (q^i - (-1)^i)$. \\\\\r\n$|GU_n(q^2):SU_n(q^2)|= q+1$,\r\n$|SU_n(q^2):PSU_n(q^2)|= (n,q+1)$.\r\n\\\\\r\n\\\\\r\n{\\bf Another proof:} Let $i_n= |{\\mathbb P}{\\cal C}_n(q^2) \\cup \\{0\\}|$ and $h_n$ be the number of hyperbolic planes in $V$.\r\n$i_n= q^{2n} + (-1)^n(q^n-q^{n-1})$. $h_n = q^{2n-3} i_n$.  ${\\mathbb P}{\\cal C}_n(q^2)$ is the orbit of $U_n(q)$ on\r\nan isotropic vector, $u$, and $|{\\mathbb P}{\\cal C}_n(q^2)|= q+1$.  The stabiliser of $u$ has order $q(q^2-1)$.\r\n\\end{quote}\r\n{\\bf Theorem 38:}\r\n$|PSU_n(q^2)|= {\\frac 1 {(n,q+1)}} q^{\\frac {n(n-1)} 2} (q^{2} -1) (q^{3} +1) \r\n(q^4 -1)...  (q^{n} - (-1)^n)$,\r\nis simple unless $(2l,q)= (2,4), (2,9), (3,4)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nApply Iwasawa's theorem given that if $G= PSU_n(q)$, $G'=G$,\r\n$G$ acts primitively on isotropic lines and $H \\lhd G_u$, where $H$ is the unitary\r\ntransvections fixing $u$ and $ \\langle H^G \\rangle = G$.\r\n\\end{quote}\r\n{\\bf Theorem 39:} Let $V= A_n(F)$.  $GL(V)/SL(V) \\cong K^*$.  \r\nIf $t \\in Inv(SL(V)), v + v^t \\in C_V(t)$.\r\nAll $p$-elements of $GL_2(V)$ are in $SL_2(V)$.  There are $q+1$ sylow $p$-subgroups in\r\n$GL_2(q), q= p^k$.  If $P_1 \\ne P_2$ are two Sylow $2$ subgroups in $GL_2(V)$ then\r\n$SL_2(V)=\r\n\\langle\r\nP_1, P_2\r\n\\rangle\r\n$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nThese all follow easily from the definitions.\r\n\\end{quote}\r\n{\\bf Theorem 40:} If $r \\ne p$ are two primes, $R \\in S_r(SL_2(V))$, then, if $r \\ne 2$,\r\n$R$ is cyclic; if $r=2$, $R$ is quaternion.\r\n\\begin{quote}\r\n\\emph{Proof:}  Stellmacher 8.6.9.\r\n\\end{quote}\r\n{\\bf Theorem 41:} If $p \\ne 2$, $a \\in p(SL(V))$ and $R$ is a $ \\langle a \\rangle $-invariant \r\n$p'$-subgroup of\r\n$SL(V)$, such that $1 \\ne [R,a]$, then $p=3$ and $R$ is quaternion of order $8$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$R= [R, a] C_R(a)$ and $[R, a, a] = [R, a]$.  $C_R(a) = \\langle z \\rangle$ where\r\n$z$ is the unique involution.\\\\\r\n\\emph{Claim:} $[R, a]$ is quaternion implies \r\n$\\langle z \\rangle = {\\mathbb Z}([R,a])$.\r\n\\\\\r\n\\emph{Proof of claim:} By induction on $|R|$.  If $R = [R,a]$, otherwise we can apply\r\ninduction.  So $a$ is a $p$ element and $R$ is an $r$-group, $r \\ne p$.  $a$ acts\r\non the cyclic group $R$ so $p \\mid (r-1)$ and thus $r \\ne 2$ and $r \\mid (q+1)$ or $r \\mid (q-1)$.\r\nIf $q=p$ these are inconsistant.  If $r \\mid (q-1)$, the with $V= Ku + Kw$, $Ku$ and\r\n$Kw$ are the only $a$- invariant subspaces of $V$ and $a$ acts either trivially or transitively,\r\nwhich is a contradiction.  If $r \\mid (q+1)$, we can extend the underlying field and obtain\r\n$R \\langle a \\rangle$ is isomorphic to the extended linear group.  This returns us to the prior\r\ncontradiction and the claim holds.\r\n\\\\\r\nGiven claim, \r\n$\\langle z \\rangle = {\\mathbb Z}([R,a])$ and thus $R= [R, a]$.  Hence $R= Q_{2^n}$\r\nFor $n \\ge 4$, $R$ has a cyclic characteristic\r\ngroup of index $2$ and $a$ acts trivially on it and the quotient and thus $R=Q_8$.\r\n\\end{quote}\r\n{\\bf Notes:} $|A_8|=|PSL_3(4)|$ but the two groups are not isomorphic.  Similarly, the infinite\r\nfamilies $P \\Omega_{2l+1}(q)$ and $PSp_{2l}(q^2)$ have the same orders but are not isomorphic.\r\nHere are some ``accidental'' isomorphisms:\r\n$Sp_2(q) \\cong SL_2(q)$,\r\n$P{\\Omega_6}^+(q) \\cong PSL_4(q)$,\r\n$P{\\Omega_6}^-(q) \\cong PSU_4(q)$,\r\n$P{\\Omega_5}^-(q) \\cong PSp_4(q)$,\r\n$PSL_4(q) \\cong A_8$,\r\n$L_2(2) \\cong S_3$,\r\n$L_2(3) \\cong A_4$,\r\n$L_2(4) \\cong L_2(5)$,\r\n$PSL_2(7) \\cong PSL_3(2)$.\r\n\\section{Groups of Lie Type}\r\n{\\bf Setting:}\r\nA \\emph{complex Lie algebra} is a non-commutative algebra over ${\\mathbb C}$ satisfying\r\n$x \\cdot (y+z)= x \\cdot y + x \\cdot z$,\r\n$(y+z) \\cdot x =  y \\cdot x + z \\cdot x$, $(x \\cdot y) \\cdot z = x \\cdot (y \\cdot z)$,\r\n$(\\lambda x) \\cdot y = \\lambda (x \\cdot y)$ and\r\n$ (x \\cdot y) \\cdot z + (z \\cdot x) \\cdot y + (y \\cdot z) \\cdot x = 0$.\r\nThe simple Lie algebras (ones with no proper ideals) are:\r\n$A_n, n \\ge 1$ [corresponding to $PSL_{n+1}(q)$],\r\n$B_n, n \\ge 2$ [corresponding to $O_{2n+1}(q)$],\r\n$C_n, n \\ge 3$ [corresponding to $Sp_{2n}(q)$],\r\n$D_n, n \\ge 4$ [corresponding to $O^+_{2n}(q)$],\r\n$G_2$,\r\n$F_4$,\r\n$E_6$,\r\n$E_7$, and\r\n$E_8$.  The twisted groups which are groups arising from automorphisms of the Dynkin\r\ndiagram for the Lie algebra are:\r\n$^2A_n, n > 1$ [corresponding to $U_{n+1}(q)$],\r\n$^2D_n, n > 2$ [corresponding to $O^-_{2n}(q)$],\r\n$^3D_4$, and $^2E_6$.  Finally, the exceptional families associated with\r\n$B_2$, $G_2$ and $F_4$ give rise to (resp), \r\nthe Suzuki groups ($q=2^n, n > 1$),\r\nthe Ree groups of odd type ($q=3^n, n > 1$), and\r\nthe Ree groups of eventype ($q=2^n, n > 1$).\r\n\r\n\\section{Finite Simple Groups}\r\n${\\mathbb Z}_p$, Schur Multiplier: 1.\r\n\\\\\r\n$\\Sigma_n'$ simple if $n>4$,\r\nSchur Multiplier: 6 if $n= 6,7$, 2 if $n=5, n>7$.\r\n\\\\\r\n$A_n (q) = PSL_{n+1}(q)$ simple if $ n \\geq 1$, \r\nSchur Multiplier: $(n+1,q-1)$ except \r\n$A_1(4) [2]$,\r\n$A_1(9) [6]$,\r\n$A_2(4) [48]$,\r\n$A_3(2) [2]$.\r\n\\\\\r\n$B_n (q)= P\\Omega_{2n+1}(q)$\r\nsimple if $ n \\geq 1$ , Schur Multiplier: $(2,q-1)$ except\r\n$B_2(2)$,\r\n$B_3(2) [2]$,\r\n$B_2(2) [6]$;\r\n\\\\\r\n$C_n (q)= PSp_{2n} (q)$ simple if $n > 2$ , Schur Multiplier: \r\n$(2,q-1)$ except $C_3(2) [2]$.\r\n\\\\\r\n$D_n (q)= P\\Omega_{2n}^{+}(q)$ simple if $n \\geq 4$, \r\nSchur Multiplier: $(2,q-1)$ except $D_4(2) [4]$.\r\n\\\\\r\n$E_6 (q)$ of order \r\n${\\frac 1 {(3,q-1)}} q^{36} (q^{12}-1)(q^{9}-1) (q^{8}-1) (q^{6}-1) (q^{5}-1) (q^{2}-1)$, \r\nSchur Multiplier: $(3,q-1)$.\r\n\\\\\r\n$E_7 (q)$ \r\nof order \r\n${\\frac 1 {(3,q-1)}} q^{63} (q^{18}-1) (q^{14}-1) (q^{12}-1) \r\n(q^{10}-1) (q^{8}-1) (q^{6}-1) (q^{2}-1)$, \r\nSchur Multiplier: $(2,q-1)$.\r\n\\\\\r\n$E_8 (q)$ \r\nof order \r\n$q^{120} (q^{30}-1) (q^{24}-1) (q^{20}-1) \r\n(q^{18}-1) (q^{14}-1) (q^{12}-1) (q^{8}-1) (q^{2}-1)$, \r\nSchur Multiplier: $1$.\r\n\\\\\r\n$F_4 (q)$ of order $q^{24} (q^{12}-1) (q^{8}-1) (q^{6}-1) (q^{2}-1)$, \r\nSchur Multiplier: $1$ except $F_4(2)[4]$.\r\n\\\\\r\n$G_2 (q)$ simple except $G_2(2)$\r\nof order \r\n$q^{6} (q^{6}-1)(q^{2}-1)$, \r\nSchur Multiplier: $1$ except $G_2(3) [3]$, $G_2(4) [2]$.\r\n\\\\\r\n$^2A_n (q^2) = PSU_{n+1}(q)$ simple if $ n \\geq 2$, Schur Multiplier: \r\n$(n+1, q+1)$ except\r\n$^2A_3(2^2) [2]$,\r\n$^2A_3(3^2) [36]$,\r\n$^2A_5(2^2) [12]$ .\r\n\\\\\r\n$^2D_n (q)= P\\Omega_{2n}^{-}(q)$\r\nsimple if $ n \\geq 4$, Schur Multiplier: $(4, q^n+1)$.\r\n\\\\\r\n$^3D_4 (q^3)$ \r\nof order \r\n$q^{12} (q^{8}+q^4+1) (q^{6}-1) (q^{2}-1)$, \r\nSchur Multiplier: $1$ .\r\n\\\\\r\n$^2E_6 (q)$ \r\nof order \r\n$q^{36} (q^{12}-1) (q^{9}+1) (q^{8}-1) (q^{6}-1) (q^{2}-1)$, \r\nSchur Multiplier: $(3,q+1)$ except\r\n$^2E_6(2^2) [12]$.\r\n\\\\\r\n$^2B_2 (2^{2m+1})= Sz(2^{2m+1})$\r\nsimple if $ m > 1$ \r\nof order \r\n$q^{2} (q^{2}+1) (q-1)$, \r\nSchur Multiplier: $1, n>2$.\r\n\\\\\r\n$^2F_4 (2^{2m+1})$ (Ree) simple if $ m >1$\r\nof order \r\n$q^{12} (q^{6}+1) (q^{4}-1) (q^{3}+1) (q-1)$, \r\nSchur Multiplier: $1, m>1$.\r\n\\\\\r\n$^2G_2 (3^{2m+1})$ (Ree) simple if $ m > 1$\r\nof order \r\n$q^{3} (q^{3}+1) (q-1)$, \r\nSchur Multiplier: $1, m>1$.\r\n\\section {Sporadic Groups}\r\n$M_{11}$ ($2^4 \\cdot 3^2 \\cdot 5 \\cdot 11$), Schur: 1.\r\n\\\\\r\n$M_{12}$ ($2^6 \\cdot 3^3 \\cdot 7 \\cdot 11$), Schur: 2.\r\n\\\\\r\n$M_{22}$ ($2^{7} \\cdot 3^2 \\cdot 5 \\cdot 7 \\cdot 11$), Schur: 6.\r\n\\\\\r\n$M_{23}$ ($2^{7} \\cdot 3^2 \\cdot 5 \\cdot 7 \\cdot 11 \\cdot 23$), Schur: 1.\r\n\\\\\r\n$M_{24}$ ($2^{10} \\cdot 3^3 \\cdot 5 \\cdot 7 \\cdot 11 \\cdot 23$), Schur: 1.\r\n\\\\\r\n$J_1$ ($2^{3} \\cdot 3 \\cdot 5 \\cdot 7 \\cdot 11 \\cdot 19$), Schur: 1.\r\n\\\\\r\n$J_2 = HJ$ ($2^{7} \\cdot 3^3 \\cdot 5^2 \\cdot 7$), Schur: 2.\r\n\\\\\r\n$J_3 = HJM$ ($2^{7} \\cdot 3^5 \\cdot 5 \\cdot 17 \\cdot 19$), Schur: 3.\r\n\\\\\r\n$J_4$ ($2^{21} \\cdot 3^3 \\cdot 5 \\cdot 7 \\cdot 11^3 \\cdot 23 \\cdot 29 \\cdot 31 \\cdot 37 \\cdot 43$), Schur: 1.\r\n\\\\\r\n$Co_1$ ($2^{21} \\cdot 3^9 \\cdot 5^4 \\cdot 7^2 \\cdot 11 \\cdot 13 \\cdot 23$), Schur: 2.\r\n\\\\\r\n$Co_2$ ($2^{18} \\cdot 3^6 \\cdot 5^3 \\cdot 7 \\cdot 11 \\cdot 23$), Schur: 1.\r\n\\\\\r\n$Co_3$ ($2^{10} \\cdot 3^7 \\cdot 5^3 \\cdot 7 \\cdot 11 \\cdot 23$), Schur: 1.\r\n\\\\\r\n$HS$ ($2^{9} \\cdot 3^2 \\cdot 5^3 \\cdot 7 \\cdot 11$), Schur: 2.\r\n\\\\\r\n$Mc$ ($2^{7} \\cdot 3^6 \\cdot 5^3 \\cdot 7 \\cdot 11$), Schur: 3.\r\n\\\\\r\n$Sz$ ($2^{13} \\cdot 3^7 \\cdot 5^2 \\cdot 7 \\cdot 11 \\cdot 13$), Schur: 1.\r\n\\\\\r\n$Ly$ ($2^{8} \\cdot 3^7 \\cdot 5^6 \\cdot 7 \\cdot 11 \\cdot 31 \\cdot 37 \\cdot 67$), Schur: 1.\r\n\\\\\r\n$He$ ($2^{10} \\cdot 3^3 \\cdot 5^2 \\cdot 7^3 \\cdot 17$), Schur: 1.\r\n\\\\\r\n$Ru$ ($2^{14} \\cdot 3^3 \\cdot 5^3 \\cdot 7 \\cdot 13 \\cdot 29$), Schur: 1.\r\n\\\\\r\n$O'N-S$ ($2^9 \\cdot 3^4 \\cdot 5 \\cdot 7^3 \\cdot 11 \\cdot 19 \\cdot 31$), Schur: 3.\r\n\\\\\r\n$F_{22}$ ($2^{17} \\cdot 3^9 \\cdot 5^2 \\cdot 7 \\cdot 11 \\cdot 13$), Schur: 6.\r\n\\\\\r\n$F_{23}$ ($2^{18} \\cdot 3^{13} \\cdot 5^2 \\cdot 7 \\cdot 11 \\cdot 13 \\cdot 17 \\cdot 23$), Schur: 1.\r\n\\\\\r\n$F_{24}$ ($2^{21} \\cdot 3^{16} \\cdot 5^2 \\cdot 7^3 \\cdot 11 \\cdot 13 \\cdot 17 \\cdot 23 \\cdot 29$), Schur: 3.\r\n\\\\\r\n$F_3$ (Thompson) ($2^{15} \\cdot 3^{10} \\cdot 5^3 \\cdot 7^2 \\cdot 13 \\cdot 19 \\cdot 31$), Schur: 2.\r\n\\\\\r\n$F_5$ (Harada) ($2^{14} \\cdot 3^{6} \\cdot 5^6 \\cdot 7 \\cdot 11 \\cdot 19$), Schur: 1.\r\n\\\\\r\n$F_2$ (Baby Monster) ($2^{41} \\cdot 3^{13} \\cdot 5^6 \\cdot 7^2 \\cdot 11 \\cdot 13 \r\n\\cdot 17 \\cdot 19 \\cdot 23 \\cdot 31 \\cdot 47$), Schur: 2.\r\n\\\\\r\n$F_1$ (Monster) ($2^{46} \\cdot 3^{20} \\cdot 5^9 \\cdot 7^6 \r\n\\cdot 11^2 \\cdot 13^3 \\cdot 17 \\cdot 19 \\cdot 23 \\cdot 29 \\cdot 31 \\cdot 41 \\cdot 47 \\cdot \r\n59 \\cdot 71$), Schur: 1.\r\n\\section{Coxeter groups}\r\n{\\bf Definition 6:}  If $G$ is a finite subgroup of $O(V)$, a subset $F \\subset V$ \r\nis a \\emph{fundamental region} if (1) $F$ is open, (2) $F \\cap T_g(F) = \\emptyset$\r\nif $g \\ne 1$ and (3) $V= \\bigcup_{g \\in G} T_g(F)^c$ where $X^c$ is the closure of\r\n$X$ in $V$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 42:}  If $dim(V)=2$ and $G \\subseteq O(V), |G|< \\infty$,\r\n$G$ is cyclic or dihedral.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $H$ be the subgroup of rotations.  It has index $1$ or $2$.  Elements of $H$ are parameterized\r\nby $\\theta$.  Pick the minimum $\\theta$ that generates the (cyclic) group $H$.\r\n\\end{quote}\r\n{\\bf Theorem 43:}  If $dim(V)=3$ and $T_g$ is a rotation about an fixed axis, ${\\vec v}$, then\r\n$T_g$ is a rotation about ${\\vec v}$ in ${\\vec v}^{\\perp}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSince $T$ is a rotation, it preserves length and the determinant is thus $1$.  \r\nSince the dimension is $3$, the characteristic equation has at least one real root and\r\nhence at least one real eigenvalue which, by the foregoing, must be $1$.  This proves the result.\r\n\\end{quote}\r\n{\\bf Definition 7:}  If $dim(V)=3$ and $G$ is a finite subgroup of $O(V)$ the poles of $G$ are\r\nthe fixed points of the rotations in $G$. \r\n${\\cal C}_3^n$ is the cyclic group of order $n$,\r\n${\\cal H}_3^n$ is the dihedral group of order $2n$,\r\n${\\cal T}_3$ is the symmetry group of the tetrahedron,\r\n${\\cal W}_3$ is the symmetry group of the dodecahedron, and\r\n${\\cal I}_3$ is the symmetry group of the ichosahedron.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 44:}  \r\nIf $dim(V)=3$ and $G \\subseteq O(V), |G|< \\infty$ then \r\n$G$ is a permutation group on the poles of $G$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $\\gamma$ be the poles.  If $x \\in \\gamma$ fixed by $T$, $Rx= RTR^{-1} Rx$ and \r\n$Rx$ is a pole of $RTR^{-1}$.\r\n\\end{quote}\r\n{\\bf Theorem 45:}\r\nIf $dim(V)=3$ and $G \\subseteq O(V), |G|< \\infty$ then \r\n$G$ is one of the groups in the prior definition.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $G$ be a finite rotation group, $|G|=n$ and $\\gamma = \\{ x_1 , x_2 , \\ldots , x_k \\}$ be the\r\npoles.\r\nPut ${\\cal U}= \\{ (T,x), T \\in G, T \\ne 1, x \\in \\gamma \\}$.\r\n$|{\\cal U}|= 2(n-1)= \\sum_{i=1}^k |x_i^G| (|G_{x_i}| -1)$.  Then\r\n$2- {\\frac 2 n} = \\sum_{i=1}^k (1- {\\frac 1 {|x_i^G|}})$ and\r\n$ 1 \\le 2-2/n<2$, so $k=2$ or $k=3$.  Putting $n_i= |x_i^G|$,\r\nwhen $k=2$, $1= {\\frac {n} {n_1}} + {\\frac n {n_2}}$ so $n_1 = n_2 =n$.\r\nFor $k=3$, $n_1=2$ and $n_2= 2,3$, then\r\n$n_3= 3, n=12$, $n_3= 4, n=24$ or $n_3=5, n=60$.  $n_5<6$.\r\n\\end{quote}\r\n{\\bf Theorem 46:} If $dim(V) \\ge 1$, then $V$ is not the union of a finite number of\r\nproper subspaces.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nBy induction on $n= dim(V)$.  True for $n=1$.  Suppose\r\n$V= V_1 \\cup \\ldots \\cup V_m$ and let $W$ be a subspace of dimension  $n-1$ then\r\n$W= W \\cap V= (W \\cap V_1) \\cup \\ldots \\cup (W \\cap V_m)$.  By induction, $W= V_i$\r\nfor some $i$ and in fact, every subspace of dimension $n-1$ must be one of the $V_i$\r\nbut there are infinitely many subspaces of dimension $n-1$ and this is a contradiction.\r\n\\end{quote}\r\n{\\bf Definition 8:}  Let \r\n${\\cal P}_i$ be the perpendicular bisector of the line segment ${\\vec x}_0, {\\vec x}_i$.  In this case,\r\n${\\cal P}_i = \\{x: d(x, x_0) = d(x, x_i) \\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 47:}\r\nLet ${\\vec x}_i= T_{g_i} ({\\vec x}_0)$, $i= 0,1, \\ldots, |G|-1$.\r\n${\\cal P}_i = \\{ {\\vec x} \\in V: d({\\vec x}, {\\vec x}_0)= d({\\vec x}, {\\vec x}_i) \\}$ and\r\n${\\cal L}_i= \\{ {\\vec x} \\in V: d({\\vec x}, {\\vec x}_0) < d({\\vec x}, {\\vec x}_i) \\}$.\r\n$F= \\bigcap_{i=0}^{|G|-1} {\\cal L}_i$ is a fundamental region for $G$ in $V$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Since each ${\\cal L}_i$ is open, so is $F$.\r\n$T_i(F)= \\{T_ix: d(T_ix,T_ix_0) < d(T_ix, T_iT_jx_0) \\}= \\{y: d(y, x_i) < d(y, T_k x_0) \\}$ but\r\n$\\bigcup_j \\{T_iT_j \\}= G \\setminus  \\{T_i \\}$.  So\r\n$T(F)= \\{x: d(x,x_i) < d(x, x_j), i \\ne j \\}$.  If $x \\in F \\cap T_iF$ then\r\n$d(x,x_i)<d(x,x_0)$ and\r\n$d(x,x_i)>d(x,x_0)$ so $F \\cap T_i F= \\emptyset$.  If $x \\in V$ choose $i$ such that\r\n$d(x, x_i)$ is minimal and so $d(x, x_i) \\le d(x, x_j), \\forall j$ and so\r\n$x \\in T_i(F)^c$ and the union of all these is $V$.\r\n\\end{quote}\r\n{\\bf Definition 9:}  If $G$ is a finite subgroup of $O(V)$, and\r\n$r$ is a unit vector then $s_{r}(x)= x- 2(x,r)r$ is called a \\emph{reflection}\r\nthrough $r^{\\perp}$.  $s_r \\in O(V)$ and the $\\pm r$ are called \\emph{roots}\r\nof $G$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 48:}\r\nIf $r$ is a root of $G$ then $x=T_g(r)$ is also a root and $s_x= T_g s_r T_g^{-1}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n${\\cal P}= r^{\\perp}$ and\r\n${\\cal P}'= T( {\\cal P}) = T(r)^{\\perp}= x^{\\perp}$.  If $y= T(z) \\in {\\cal P}', z \\in {\\cal P}$.\r\n$s_x(y) = Ts_rT^{-1}(y)= y$.\r\n\\end{quote}\r\n{\\bf Definition 10:}  $V_T= \\{ x \\in V: T(x)=x \\}$.  $V_0 = V_0(G)= \\bigcap_{g \\in G} V_{T_g}$.\r\nA group $G \\le O(V)$ is \\emph{effective} if $V_0(G)=0$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 49:}\r\nSuppose $G$ is generated by the reflections $s_r, r \\in \\{r_1, \\ldots, r_k \\}$.\r\nThen $G$ is effective iff $\\{r_1, \\ldots, r_k \\}$ is a basis.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSet $W= \\bigcap r_i^{\\perp}, 1 \\le i \\le k$.  Note that each $T \\in G$, $T$ is a product of\r\nthe generating reflections.  $T_{|W} = 1$ so $W \\subseteq V_0(G)$ but \r\n$x \\in V_0(G)$, each generating reflection fixes $x$ so $x \\in r_i^{\\perp}$ for each $i$.\r\nThis $ x \\in W$ and $W= V_0(G)$ and $W^{\\perp}= V$ but\r\n$W^{\\perp}= (\\bigcap_{i=1}^k r_i^{\\perp})^{\\perp} = \\sum_{i=1}^k r_i^{ \\perp \\perp}$\r\nand so the $r_i$ span $W^{\\perp}$ and the result holds.\r\n\\end{quote}\r\n{\\bf Definition 11:} \r\nSuppose $G$ is generated by the reflections $s_r, r \\in R= \\{r_1, \\ldots, r_k \\}$.\r\n$\\Delta= \\{ T_g(r_j), g \\in G, 1 \\le j \\le k \\}$ is called a \\emph{root system}.\r\n$\\Delta_t^+= \\{ r \\in \\Delta: (t,r) > 0 \\}$ and\r\n$\\Delta_t^-= \\{ r \\in \\Delta: (t,r) < 0 \\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 50:}\r\nSuppose $G$ is generated by the reflections $s_r, r \\in R= \\{r_1, \\ldots, r_k \\}$\r\nand $G$ is effective.  If a root system $\\Delta$ for $G$ is finite, so is $G$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nIf $T \\in G$, $T(\\Delta)= \\Delta$ and $G$ is a permutation group on $\\Delta$.\r\nSince $\\Delta$ is effective, it contains a basis so if $T_{| \\Delta} =1  \\rightarrow\r\nT= 1$ and $G$ is faithful on $\\Delta$ so $G$ is finite.\r\n\\end{quote}\r\n{\\bf Definition 12:} \r\nA finite effective group $G \\le O(V)$ generated by a finite set of reflections\r\n$s_r, r \\in R= \\{r_1, \\ldots, r_k \\}$ with root system $\\Delta$ is called a \r\n\\emph{Coxeter group} with root system $\\Delta$.\r\nA $t$\\emph{-base} for $\\Delta$ is a subset $\\Pi \\subseteq \\Delta_t^+$ minimal with respect\r\nto the property that every $r \\in \\Delta_t^+$ is a linear combination of elements of\r\n$\\Pi$ with non-negative coefficients.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 51:}\r\nIf $r_i, r_j \\in \\Pi, i \\ne j$ and $\\lambda_i, \\lambda_j >0$ then\r\n$x= \\lambda_i r_i - \\lambda_j r_j$ is neither $t$-positive nor $t$-negative.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nIf $x$ were positive, $x= \\lambda_i r_i = \\lambda_j r_j = \\sum_{k=1}^m u_k r_k$\r\nwith all $u_k \\ge 0$.  If $\\lambda_i \\le u_i$ then\r\n$0= (u_i - \\lambda_i) r_i + (u_j + \\lambda_j) r_j +\r\n\\sum u_k r_k, k \\ne i,j \\ge \\lambda_j(t, r_j) >0$, a contradiction.\r\nIf $\\lambda_i > u_i$ then\r\n$(\\lambda_i - u_i) r_i = (u_j + \\lambda_j) r_j + \\sum u_k r_k: k \\ne i, j$.\r\nSo we can express $r_i$ as a non-negative linear combination of elements of\r\n$\\Pi \\setminus \\{ r_i \\}$ contradicting the minimality of $\\Pi$.  Thus $x$\r\nis not positive which is impossible by the above argument with $i$ and $j$ interchanged.\r\n\\end{quote}\r\n{\\bf Theorem 52:}\r\nIf $r_i, r_j \\in \\Pi, i \\ne j$ and $s_i$ the reflection along $r_i$, then $s_i(r_j) \\in \\Delta^+$\r\nand $(r_i, r_j) \\le 0$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSince $s_i(r_j) \\in \\Delta$, \r\n$s_i(r_j)$ is either positive or negative, but $s_i(r_j)= r_j - 2(r_i, r_j) r_i$ with\r\none coefficient positive.  By previous result, both must be non-negative, so $(r_i , r_j) \\le 0$\r\nand $s_i(r_j)$ is positive.\r\n\\end{quote}\r\n{\\bf Theorem 53:}\r\nIf $\\Pi$ is a $t$-base for $\\Delta$ then $\\Pi$ is a basis for $V$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSince $G$ is effective, $\\Delta$ spans $V$.  Since every $r \\in \\Delta$\r\nis a linear combination of roots in $\\Pi$, $V$ is spanned by $\\Pi$.  The\r\nelements of $\\Pi$ are linear independent so $\\Pi$ is a basis.\r\n\\end{quote}\r\n{\\bf Theorem 54:}\r\nThere is only one $t$-base for $\\Delta$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSuppose $\\Pi_1$ and $\\Pi_2$ are two different $t$-bases.  Since each root in $\\Pi_1$\r\nis a non-negative linear combination of roots in $\\Pi_2$, the roots are related\r\nby a matrix $A$ and $B= A^{-1}$.  \r\nLet $a_1 , \\ldots , a_n$ be the rows of $A$\r\nand $b_1 , \\ldots , b_n$ be the rows of $B$.  $AB=I$ and $a_1^{\\perp} b_i, i \\ne 1$.\r\nThere is at most on $j$ for which the $j$th entry in all the\r\n$b_1 , \\ldots , b_n$ is zero otherwise the $b_i$ would be linearly dependent.  A similar argument\r\napplies to the columns and so there is exactly one non-zero entry in each row and column and\r\nit must be $1$ and so $A$ is a permutation matrix and $\\Pi_1= \\Pi_2$.\r\n\\end{quote}\r\n{\\bf Theorem 55:}\r\nSuppose $s_r, r \\in \\Pi$.  If $r_i \\in \\Delta^+, r_i \\ne r$ then $s_i (r) \\in \\Delta^+$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nIf $r \\in \\Pi$, $s_i(r) \\in \\Delta^+$.  If $r \\notin \\Pi$, \r\n$r= \\sum_{i=1}^n \\lambda_j r_j$ and at least one of the $\\lambda_j >0$ so\r\n$r_i \\ne r_1$, $\\lambda_1>0$ and\r\n$s_i(r) = \\sum_{j=1}^n \\lambda_j s_i(r_j)$.  Since $s_i(r) \\in \\Delta$,\r\nit is either positive or negative and since $\\lambda_1>0$, $s_i(r) \\in \\Delta^+$.\r\n\\end{quote}\r\n{\\bf Definition 13:} \r\nThe reflections $s_r , r \\in \\Pi$ are called \\emph{fundamental reflections}.\r\n$H_G= \\langle s_i \\rangle$, where the $s_i$ are the fundamental reflections.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 56:}\r\nIf $x \\in V, \\exists T \\in H_G: (T(x), r_i) \\ge 0, \\forall r_i \\in \\Pi$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSet $x_0= {\\frac 1 2} \\sum_{r \\in \\Delta^+} r$.  Since $H_G$ is finite,\r\n$\\exists T \\in H_G$ for which $Tx,x_0)$ is maximal and $s_i(x_0)= x_0 - r_i$.\r\nBy maximality, $(Tx,x_0) \\ge ( s_i(T(x)) , x_0) = (Tx, x_0) - (Tx, r_i)$ so\r\n$(Tx, r_i) > 0$.\r\n\\end{quote}\r\n{\\bf Theorem 57:}\r\nIf $r \\in \\Delta^+$ then $\\exists T \\in G: T(r) \\in \\Pi$ for some $T \\in H_G$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nIf $r \\in \\Pi$, set $g=1$.\r\nIf $r \\notin \\Pi$, by previous result, $\\exists i: (r, r_i) >0$ otherwise\r\n$\\Pi \\cup \\{r \\}$ would be linearly independent.  Set\r\n$a_1= s_1(r)= r-2(r,r_1) r_1$ then $a_1 \\in \\Delta^+$ by the previous result and\r\n$(a_1, t)= (r, t)- 2 (r, r_1) (r_1, t)< (r,t)$.\r\nIf $a_1 \\in \\Pi$, put $T= s_1 \\in H_G$.\r\nIf $a_1 \\notin \\Pi$ reapply procedure to get $a_2= s_2(a_1)$ with $(a_2, t) < (a_1, t)$.\r\nEventually, this process terminates with\r\nIf $a_k \\in \\Pi$, $a_k= s_k s_{k-1} \\ldots s_1(r)$.  Now put\r\n$T= s_k s_{k-1} \\ldots s_1$ and we're done.\r\n\\end{quote}\r\n{\\bf Theorem 58:}\r\n$H_G=G$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSince $G= \\langle s_r: r \\in \\Delta \\rangle$.  STS $r \\in \\Delta^+$ then $s_r \\in H_G$.\r\nSuppose $r \\in \\Delta^+$ so there is a $T \\in G$ such that $T(r) \\in \\Pi$ say $T(r)= r_i$\r\nand then $s_r= T^{-1} s_i T \\in H_G$.\r\n\\end{quote}\r\n{\\bf Theorem 59:}\r\nIf $T_g(\\Pi)= \\Pi$ then $g=1$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nSuppose $T \\ne 1$, by previous result, \r\n$T= s_1 s_2 \\ldots s_k$.  Assume $k$ is minimal, we have $k>0$.\r\nSince $T(\\Pi)= \\Pi$,\r\n$T(r_k)= s_1 s_2 \\ldots s_k(r_k)$\r\nso\r\n$s_1 s_2 \\ldots s_{k-1} \\in \\Delta^-$.  Put\r\n$a_0= s_1 s_2 \\ldots s_{k-1}(r_k)$,\r\n$a_1= s_1(a_0)$, \\ldots,\r\n$a_{k-1}= s_{k-1} (a_{k-2})= r_k$.  \r\nNow $a_0 \\in \\Delta^-$ but\r\n$a_{k-1} \\in \\Delta^+$.\r\nSuppose\r\n$a_0, a_1, \\ldots, a_{j-1} \\in \\Delta^-$ but\r\n$a_{j} \\in \\Delta^+$ then \r\n$s_j(a_j)= a_{j-1} \\in \\Delta^-$ so by an earlier result $a_j=r_j$ and so\r\n$r_j= s_{j+1} \\ldots s_{k-1}(r_k)$.  But then\r\n$s_j= s_{j+1} \\ldots s_{k-1} s_k (s_{j+1} \\ldots s_{k-1})^{-1}$ so \r\n$T = s_1 s_2 \\ldots s_k = s_1 s_2 \\ldots s_{j-1} s_{j+1} \\ldots s_k $ contradicting minimality.\r\n\\end{quote}\r\n{\\bf Theorem 60:}\r\n$T_g(\\Delta_t^+)= \\Delta_{T_g(t)}^+$ and $T(\\Pi_t)= \\Pi_{T(t)}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nEvery root in $T(\\Delta_t^+)$ is a non-negative linear combination of roots in\r\n$T(\\Pi_t)$.  $T(\\Delta_t^+) = T(\\{r \\in \\Delta: (t,r)>0 \\})\r\n= \\{s \\in \\Delta: (Tt,r)>0 \\} = \\Delta_{T(t)}^+$.\r\n\\end{quote}\r\n{\\bf Theorem 61:}\r\nIf $T_g(\\Delta^+)= \\Delta^+$ then $g=1$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$\\Delta_t^+ = T(\\Delta_t^+)= \\Delta_{\\Pi(t)}^+$ so\r\n$\\Pi_t = \\Pi_{T(t)}$ but then\r\n$T( \\Pi_t) = \\Pi_t$ and $t=1$.\r\n\\end{quote}\r\n{\\bf Definition 14:}\r\n$F_t= \\{ x \\in V: (x,r_i) > 0, \\forall r_i \\in \\Pi \\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 62:}\r\n$F= F_t$ is a fundamental region for the Coxeter group $G$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$F$ is open.  Suppose $T \\in G$ and $x \\in F \\cap T(F)$ and set $R= T^{-1}$ then\r\n$R(x) \\in F$ and $(x, r_i)>0, \\forall i$ so $(x, r_i)>0, r \\in \\Delta_t^+$.\r\nThus $\\Delta_x= \\Delta_t$ and $\\Pi_t= \\Pi_x$ also $\\Pi_{R(x)}= \\Pi_t$.\r\nBy a previous result,\r\n$\\Pi_t= \\Pi_{Rx}=R(\\Pi_x )= R(\\Pi_t )$ and $R=T=1$.  Finally, if $y \\in V$ then by\r\na previous result, $\\exists T: (Ty, r_i) \\ge 0, \\forall r_i \\in \\Pi$ and so\r\n$T(y) \\in F^c$.  Thus $y \\in T^{-1}(F^c)= T^{-1}(F)^c$ so\r\n$V= \\bigcup \\{ (RF)^c: R \\in G \\}$ and we're done.\r\n\\end{quote}\r\n{\\bf Theorem 63:}\r\nEvery reflection is conjugate to a fundamental reflection.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nSuppose $s_r \\in G$ and put ${\\cap P}= r^{\\perp}$.  If $F$ is the fundamental region\r\naboive, so is $T(F), T \\in G$.  If \r\n${\\cal P} \\cap T(F) \\ne \\emptyset$ for some $T$,\r\nchoose $x \\in {\\cal P} \\cap T(F)$ and there is a ball, $B$, of radius $\\epsilon$ lying entirely in\r\n$T(F)$.  Since $s_r(x)=x$, $s_r(B)=B$ but $B \\nsubseteq {\\cal P}$ so we can pick\r\n$y \\in B \\setminus {\\cal P}$.  $s_r(y) \\in B \\subseteq T(F)$ but $s_r(y) \\ne y$ contradicting\r\nthe fact that $T(F)$ is a fundamental region.\r\n${\\cap P} \\subseteq V \\setminus (\\bigcup_{T \\in G} T(F)) = \\bigcup {\\cal P}_i$ so\r\n${\\cal P}= \\bigcup_{T \\in G} {\\cal P} \\cap T({\\cal P}_i)$ or ${\\cal P} \\subseteq T({\\cal P}_i)$\r\nfor some $T$ and some $i$.  Since both ${\\cal P}$ and $T({\\cal P}_i)$ are both hyperplanes,\r\n${\\cal P}= T({\\cal P}_i)$ and $r= T(r_i)$ or $r= - T(r_i )= T(s_i(r_i))$.  In either case,\r\n$r \\in \\Delta$ and $s_r= TS_i T^{-1}$ and we're done.\r\n\\end{quote}\r\n{\\bf Theorem 64:}\r\nIf $r_i, r_j \\in \\Pi$ is a $t$-base\r\n then $\\exists p_{ij} \\in {\\mathbb Z}, p_{ij} \\ge 1$ such that\r\n${\\frac {(r_i, r_j)} {||r_i|| \\cdot ||r_j||}}= -cos({\\frac {\\pi} {p_{ij}}})$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIf $i=j$ put $p_{ij}=1$.  If $i \\ne j$, put $W= {\\mathbb R} r_i + {\\mathbb R} r_j$ and\r\n$H= \\langle s_i, s_j \\rangle$.  Note that \r\n$(s_i)_{|W^{\\perp}}= 1= (s_j)_{|W^{\\perp}}$ and $H= \r\nH_2^m \\times 1$ where\r\n$H_2^m$ is the dihedral group.\r\n$t= t_1 + t_2, t_1 \\in W, t_2 \\in W^{\\perp}$ and $r_i, r_j$ is a $t_1$-base for\r\n$H_2^m$ in $W$.  If not, $\\exists r$, a root of\r\n$H_2^m$ such that $r, r_j$ is a $t_1'$-base for some $t_1' \\in W$ and\r\nall of $r, r_i, r_j$ are $t_1'$-positive.  If $r$ is a root of $G$,\r\n$r= \\lambda_i r_i - \\lambda_j r_j$ but this contradicts an earlier proposition.\r\nSo $r_i, r_j$ is a $t_1$-base.\r\n$(r_i, r_j)= cos(\\theta)= cos (\\pi - \\varphi) = - cos(\\varphi)= - cos({\\frac {\\pi} {p_{ij}}})$.\r\n\\end{quote}\r\n{\\bf Notation:} $M= (m_{ij}), 1 \\le i,j \\le n, m_{ii}=1$, \r\n$m_{ij} \\in {\\mathbb Z}, m_{ij} \\ge 2$.  Associate to each\r\nsuch matrix a graph with nodes $i, 1 \\le i \\le n$, $(i,j)$ is an edge if $m_{ij}>0$ if\r\n$m_{ij}>2$, label it with $m_{ij}-2$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition 15:} If $\\Delta= \\{ r_1 , \\ldots , r_n \\}, ||r_i||=1$ \r\nis a root system with unit vectors\r\n$r_i$ defining a reflection along its associated hyperplane by \r\n$s_r (x) = x-2(r,x)r$ and\r\n$\\alpha_{ij}= -cos({\\frac {\\pi} {p_{ij}}})= (r_i , r_j)$, associate a marked\r\ngraph with edges labeled by $p_{ij}$ (unmarked edged have $p_{ij}=3$) and associated\r\nquadratic form $Q({\\vec x})= \\sum \\alpha_{ij} x_i x_j$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 65:} The Coxeter group is generated\r\nby the involutions $s_r$ and $s_{r_i} s_{r_j}$ has order $p_{ij}$.  \r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$s_i s_j$ is a rotation through an angle of ${\\frac {\\pi} {p_{ij}}}$.\r\n\\end{quote}\r\n{\\bf Theorem 66:}\r\nIf $G_1$ and $G_2$ are Coxeter groups with the same graph they are related by a similarity\r\n$T \\in O(V)$ and $T G_1 T^{-1}= G_2$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $\\Pi_1$ and $\\Pi_2$ be two bases of unit vectors for the root systems of $G_1$ and\r\n$G_2$ respectively.  Since they have the same graphs, after reordering,\r\n$\\Pi_1= \\{ r_1 , \\ldots , r_n \\}$ and\r\n$\\Pi_2= \\{ r_1' , \\ldots , r_n' \\}$ with $(r_i, r_j)= (r_i', r_j')$.  Define $T: r_i \\mapsto r_i'$\r\nand extend by linearity.  $s_i' = T s_i T^{-1}$ and the result follows.\r\n\\end{quote}\r\n{\\bf Theorem 67:}\r\nThe Coxeter graph of a Coxeter group is positive definite.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIf the roots are unit vectors,\r\nthen the matrix, $A$, defining the quadratic form is $(a_{ij})$ with\r\n$a_{ij}= (r_i, r_j)$.  If $0 \\ne x= (x_1, \\ldots, x_n) \\in {\\mathbb R}^n$, then\r\n$\\sum_{i=1}^n x_i r_i \\ne 0$ since the elements of $\\Pi$ are linearly independent\r\nand $Q(x)= \\sum_{i,j} (r_i, r_j) x_i x_j = || \\sum_i x_i r_i ||^2>0$.  So\r\n$Q$ is positive definite.\r\n\\end{quote}\r\n{\\bf Definition 16:}\r\nA Coxeter group, $G$, with root system $\\Delta$, is \\emph{reducible} iff\r\n$\\Pi= \\Pi_1 \\cup \\Pi_2$, $\\Pi_1 \\perp \\Pi_2$ and $\\Pi_1 \\ne \\emptyset \\ne \\Pi_2$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 69:}\r\nThe Coxeter graph of a Coxeter group is connected iff $G$ is irreducible.\r\n\\begin{quote}\r\n\\emph{Proof:}  Clear from definitions.\r\n\\end{quote}\r\n{\\bf Theorem 70:}  A subgraph, $H$, of a positive definite marked graph, $G$, is also positive\r\ndefinite.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nOrder the nodes of $G$, \r\n$a_1, a_2 , \\ldots, a_n$ such that\r\n$a_1, a_2 , \\ldots, a_k$ are the nodes of $H$ and let the respective quadratic\r\nforms be denoted $Q_G$ and $Q_H$.  If $Q_H$ is not positive define,\r\n$\\exists x \\ne 0, x= \\sum_{i=1}^k x_k e_k \\in {\\mathbb R}^k$ such that $Q_H(x) \\le 0$.\r\ndenoting as $y$, the extention of\r\n$x$ to ${\\mathbb R}^n$, $0 \\ge Q_H(x) \\ge Q_G(y) > 0$ which is a contradiction.\r\n\\end{quote}\r\n{\\bf Definition 17:}\r\n$G$ satisfies the \\emph{crystallographic condition} if it fixes a lattice.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 71:}\r\nIf $G$ satisfies the crystallographic condition, $p_{ij}= 1,2,3,4,6$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$s_i s_j=\r\n\\left(\r\n\\begin{array}{cc}\r\nA &  0_{n-2} \\\\\r\n0  &  I_{n-2} \\\\\r\n\\end{array}\r\n\\right)$ where\r\n$A=\r\n\\left(\r\n\\begin{array}{cc}\r\ncos({\\frac {2 \\pi} {m}}) & -sin({\\frac {2 \\pi} {m}}) \\\\\r\nsin({\\frac {2 \\pi} {m}}) & cos({\\frac {2 \\pi} {m}}) \\\\\r\n\\end{array}\r\n\\right)$.  $Tr(A)= 2 cos({\\frac {2 \\pi} {m}}) + (n-2) \\in {\\mathbb Z}$ so\r\n$Tr(A)= 2 cos({\\frac {2 \\pi} {m}}) \\in {\\mathbb Z}$ and $m= 1, 2, 3, 4, 6$.\r\n\\end{quote}\r\n\\begin{figure}\r\n\\center\r\n\\includegraphics[natwidth=642, natheight=610, width=80mm]{dynkin.pdf}\r\n\\end{figure}\r\n{\\bf Theorem 72:}\r\nIf $G$ is a connected positive definite Coxeter graph then $G$ is one of\r\n$A_n$,\r\n$B_n$,\r\n$D_n$,\r\n$H_2^n$,\r\n$G_2$,\r\n$I_3$,\r\n$I_4$,\r\n$F_4$,\r\n$E_6$,\r\n$E_7$, or\r\n$E_8$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nThe graph for $G$ can contain no cycles or the form would not be positive definite.\r\nIf $H_2^n$ is a subgraph of $G$, for any $n \\ge 7$ then $G= H_2^n$ otherwise\r\n$U_3$  would be in the graph.  Similarly, $G= G_2$ if it occurs.\r\nWe can assume any branch is labeled $3$, $4$ or $5$.  Suppose that $B_2$\r\nis a subgraph of $G$; it cannot occur more than twice otherwise some $S_n$\r\nwould be a subgraph.  $G$ cannot have a branch point otherwise $T_n$ would be\r\na subgraph.  If $H_2^5$ is a subgraph then $G= H_2^5$, $G= I_3$ or\r\n$G= I_4$.  There are no other possibilities otherwise $G$ would have $Z_4$\r\nor $Y_5$ as a subgraph.  If $B_2$ is a subgraph but $H_2^5$ is not, then\r\n$G$ may be $B_n$ for some $n \\ge 2$ or $F_4$.  There are no other possibilities\r\notherwise $V_5$ would be a subgraph of $G$.  In the case that all branches are unmarked\r\nthen $G$ can have at most one bransh point and only $3$ branches can emanate from any branch point\r\notherwise $Q_n$ would occur in $G$.  If there is no branch point $G= A_n$.  If $G$\r\nhas one branch point, $G= D_n$ for some $n$ or $G= E_6, E_7, E_8$ or $R_7, R_8, R_9$ would\r\noccur in $G$.\r\n\\end{quote}\r\n{\\bf Theorem 73:}\r\nIf $G$ has Coxeter graph\r\n$A_n$, $B_n$, $D_n$, $H_2^n$,\r\n$G_2$, $I_3$, $I_4$, $F_4$,\r\n$E_6$, $E_7$, or\r\n$E_8$ then $G$ satisfies the crytallographic condition.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n${\\cal L} = \\sum_{i-1}^n k_i r_i$.  If $p_{ij}= 3$, $||r_i||= ||r_j||$ and\r\n$(r_i , r_j ) = - {\\frac 1 2} ||r_i|| \\cdot ||r_j||$ and $s_i(r_j)= r_i + r_j \\in {\\cal L}$.\r\nIf $p_{ij}= 4$, $s_i(r_j)= r_j + r_i$ or $s_i(r_j)= r_j + 2r_i$.\r\nIf $p_{ij}= 6$, $s_i(r_j)= r_j + r_i$ or $s_i(r_j)= r_j + 3r_i$.\r\nIf $p_{ij}= 1$, $s_i(r_j)= - r_j$.\r\nIf $p_{ij}= 2$, $s_i(r_j)= r_j$.\r\n\\end{quote}\r\n\\begin{center}\r\n\\begin{tabular} {|r|r|}\r\n\\hline\r\n{\\bf Graph} & {\\bf Base} \\\\\r\n\\hline\r\n$A_n$ & $r_i= e_{i+1}-e_i$, $1 \\le i \\le n$ \\\\\r\n\\hline\r\n$B_n$ & $r_1= e_1$, $r_i= e_{i}-e_{i-1}$, $2 \\le i \\le n$ \\\\\r\n\\hline\r\n$D_n$ & $r_1= e_1 + e_2$, $r_i= e_{i+1}-e_i$, $2 \\le i \\le n$ \\\\\r\n\\hline\r\n$H_2^n$ & $r_i= e_{i+1}-e_i$, $2 \\le i \\le n$ \\\\\r\n\\hline\r\n$G_2$ & $r_i= e_2-e_1$, $r_2 = e_1 -2e_2+e_3$ \\\\\r\n\\hline\r\n$I_3$ & \r\n$r_1= \\beta(2 \\alpha + 1, 1, -2 \\alpha)$,\r\n$r_2= \\beta(-2 \\alpha - 1, 1, 2 \\alpha)$,\r\n$r_3= \\beta(2 \\alpha, -2 \\alpha -1 , 1)$\\\\\r\n\\hline\r\n$I_4$ & $r_1= \\beta(2 \\alpha + 1, 1, -2 \\alpha, 0)$, $r_2= \\beta(-2 \\alpha - 1, 1, 2 \\alpha, 0)$,\\\\\r\n & $r_3= \\beta(2 \\alpha, -2 \\alpha -1 , 1, 0)$, $r_4= \\beta(2 \\alpha, 0, -2 \\alpha -1 , 1)$ \\\\\r\n\\hline\r\n$F_4$ & \r\n$r_1= 1{\\frac 1 2} (\\sum_{i=1}^4 e_i$, $r_2= e_1$, $r_3= e_2 - e_1$, $r_4= e_3- e_2$ \\\\\r\n\\hline\r\n$E_6$ & $r_1= 1{\\frac 1 2} (\\sum_{i=1}^3 e_i - \\sum_{i=4}^8 e_i)$, $r_i= e_i-e_{i-1}$, \r\n$2 \\le i \\le 6$ \\\\\r\n\\hline\r\n$E_7$ & $r_1= 1{\\frac 1 2} (\\sum_{i=1}^3 e_i - \\sum_{i=4}^8 e_i)$, $r_i= e_i-e_{i-1}$, \r\n$2 \\le i \\le 7$ \\\\\r\n\\hline\r\n$E_8$ & $r_1= 1{\\frac 1 2} (\\sum_{i=1}^3 e_i - \\sum_{i=4}^8 e_i)$, $r_i= e_i-e_{i-1}$, \r\n$2 \\le i \\le 8$ \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\begin{center}\r\n\\begin{tabular} {|r|r|r|}\r\n\\hline\r\n{\\bf Base} & $|\\Delta|$ & {\\bf Root System} \\\\\r\n\\hline\r\n$A_n$ & $n^2+n$ & $\\pm (e_i - e_j)$ \\\\\r\n\\hline\r\n$B_n$ & $2n^2$ &\r\n$\\pm e_i$, $\\pm e_i \\pm e_j$ \\\\\r\n\\hline\r\n$D_n$ & $2n(n-1)$ &\r\n$\\pm e_i \\pm e_j$ \\\\\r\n\\hline\r\n$H_2^n$ & $2n$ &\r\n$(cos({\\frac {j \\pi} {n}}), sin({\\frac {j \\pi} {n}})) $, $0 \\le j <2n$\\\\\r\n\\hline\r\n$G_2$ & $12$ & $\\pm(e_i - e_j)$, $1 \\le i \\le 3$, $ \\pm (1, -2, 1)$, $(-2, 1,1)$, $\\pm(1,1, -2)$ \\\\\r\n\\hline\r\n$I_3$ & $30$ &\r\n$ \\pm e_i$, $1 \\le i \\le 3$, $\\beta ( \\pm (2 \\alpha +1), \\pm 1, \\pm 2 \\alpha)$,\\\\\r\n& &  and all even permutation of coordinates\\\\\r\n\\hline\r\n$I_4$ &  $120$ & $ \\pm e_i$, $1 \\le i \\le 4$, $\\beta ( \\pm 2 \\alpha , 0,  \\pm (2 \\alpha +1) )$, \\\\\r\n& &  and all even permutation of coordinates\\\\\r\n\\hline\r\n$F_4$ &  $48$ &\r\n$ \\pm e_i$, $\\pm e_i \\pm e_j$, $1 \\le i \\le 4$ \\\\\r\n\\hline\r\n$E_8$ & $240$ &\r\n$ \\pm e_i \\pm e_j $, $1 \\le j < i \\le 8$, $\\sum_{i=1}^8 \\epsilon_i e_i$, $\\epsilon_i = \\pm 1$,\r\n$\\prod_{i=1}^8 \\epsilon_i = -1$ \\\\\r\n\\hline\r\n$E_7$ & $126$ & roots of $E_8$ orthogonal to $u= (1,1,1,1,1,1,1,-1)$ \\\\\r\n\\hline\r\n$E_6$ & $72$ & roots of $E_8$ orthogonal to $r_8= e_8 - e_7$ \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\begin{center}\r\n\\begin{tabular} {|r|r|}\r\n\\hline\r\n{\\bf Graph} & $|G|$ \\\\\r\n\\hline\r\n$A_n$ &  $(n+1)!$ \\\\\r\n\\hline\r\n$B_n$ &  $2^n n!$ \\\\\r\n\\hline\r\n$D_n$ &  $2^{n-1} n!$ \\\\\r\n\\hline\r\n$H_2^n$ & $2n$ \\\\\r\n\\hline\r\n$G_2$ &  $12$ \\\\\r\n\\hline\r\n$F_4$ &  $2^{7} \\cdot 3^{2}$ \\\\\r\n\\hline\r\n$I_3$ &  $2^{3} \\cdot 3 \\cdot 5$ \\\\\r\n\\hline\r\n$I_4$ &  $2^{6} \\cdot 3^{2} \\cdot 5^2$ \\\\\r\n\\hline\r\n$E_6$ &  $2^{7} \\cdot 3^{4} \\cdot 5$ \\\\\r\n\\hline\r\n$E_7$ &  $2^{10} \\cdot 3^{4} \\cdot 5 \\cdot 7$ \\\\\r\n\\hline\r\n$E_8$ &  $2^{14} \\cdot 3^{5} \\cdot 5^2 \\cdot 7$ \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\section{Mathieu Groups}\r\n{\\bf Construction:}\r\n$M_{11}$: $\\pi_1= (123)(456)(789), \\pi_2= (147)(258)(369)$,\r\n$ \\langle \\pi_1, \\pi_2 \\rangle = {\\mathbb Z}_3 \\times {\\mathbb Z}_3$, \r\n$\\rho_1= (2437)(5698), \\rho_2= (2539)(4876)$, $ \\langle \\rho_1 , \\rho_2 \\rangle = Q \\cong Q_8$.  Set\r\n$M_9= \\langle \\pi_1 , \\pi_2 , \\rho_1 , \\rho_2 \\rangle $, $|M_9|=72$.  \r\nNow set $\\sigma= (1, 10)(4,5)(6,8)(7,9)$, $\\mu= (4,7)(5,8) (6,9) (10,11)$,\r\n$\\theta= (4,9) (5,7) (6,8)(11,12)$.  \r\n$M_{10}= M_9 \\cup M_9 \\sigma M_9$,  $(M_{10})_x= M_{9}$,\r\n$M_{11}= M_{10} \\cup M_{10} \\mu M_{10}$,  $(M_{11})_x= M_{10}$,\r\n$M_{12}= M_{11} \\cup M_{11} \\theta M_{11}$,  $(M_{12})_x= M_{11}$.  $|M_{11}|=7920$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 74:}\r\n$|M_{24}|= 24 \\cdot 23 \\cdot 22 \\cdot 21 \\cdot 20 \\cdot 48 $.  $M_{11}$ is simple.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $N$ be a non-trivial normal subgroup, it is regular and all Sylow 11 subgroups\r\nare contained in it (there are 144 by Sylow) and $|G:N|= 5$.  All Sylow 3 subgroups\r\nof $M_{11}$ are in $N$ and $\\psi= \\pi_1 \\sigma \\pi_2^2 \\sigma^{-1}$ has order 5 which is a\r\ncontradiction.  Note that the symmetries of $S(4,5,11)$ also generate it and\r\nthat $(M_{11})_a= PSL_2(9)$ and $(M_{22})_a = PSL_3(4)$.\r\n\\end{quote}\r\n\\section{Conway's Groups}\r\n{\\bf Notation:}  Let $R(C)$ be the row space of $C$ over $GF(2)$.  Define the $\\Gamma$ to\r\nbe the collection of $(v_1, v_2, \\ldots , v_{24})=v \\in {\\mathbb Z}^{24}$ such that\r\n(1) $\\sum_{i=1}^{24} v_i = 4m$, (2) $v_i = m \\jmod{4}$, \r\nif $c_i = 0$, (3) $v_i=m+2 \\jmod{4}$ if $c_i = 1$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition 18:}\r\n$L_8 \\rightarrow \\Lambda_8$:  $v \\in \\Gamma_8$ iff\r\n$v \\in L_8$ and $\\sum_{i=1}^{8} v_i = 4m$.  Contact number: $112+128=240$, radius: ${\\sqrt 2}$.\r\n\\emph{Alternate definition} of $\\Lambda_8$: $8$-tuples whose spheres are congruent $\\jmod{2}$ to\r\nrows of $A_8$ or ${\\overline {A_8}}$.\r\nDensity is ${\\frac {\\pi^4}{4!2^4}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Golay:}\r\n$L_8$:  $v \\in L_8$ iff $v \\in {\\mathbb Z}^8$ and $v_i = a_i \\jmod{2}$ or\r\n$v_i = {\\overline a_i} \\jmod{2}$.  Generator matrix:\r\n$$\\left(\r\n\\begin{array}{cccccccc}\r\n1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\\\\r\n2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n0 & 2 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n\\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots \\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 2 & 0 \\\\\r\n\\end{array}\r\n\\right).$$\r\n{\\bf Definition 19:}\r\nLet $R(C)$ be the row space of ${\\cal G}_{24}$ over $GF(2)$.  \r\nDefine the \\emph{Leech Lattice}, $\\Lambda_{24}$,\r\nas the vectors that satisfy the following conditions:\r\nExpress coordinates in $E_{24}$ in binary and retain the ones that satisfy\r\nthe following conditions (a) the $24$ $1$'s bits are either all $0$ or all $1$, (b)\r\nthe $2$'s bits form a row in $R(C)$, (c) $4$'s bits rows have even parity for points\r\nwith $1$'s bits that are all $0$ and odd otherwise. This is equivalent to the following:\r\nSuppose ${\\vec c} \\in R(C)$ and for $m \\in {\\mathbb Z}$, define\r\n${\\vec c}(m)= \\{  \r\nv \\in {\\mathbb Z}^{24}:  \\sum_i v_i = 4m, \r\nc_i = 0 \\rightarrow v_i = m \\jmod{4},\r\nc_i = 1 \\rightarrow v_i = m+2 \\jmod{4}\r\n\\}$,\r\n$\\Lambda = \\Lambda_{24}= \\cup_m {\\vec c}(m)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 75:}   In $\\Lambda$, lattice points are seperated by a minimum\r\ndistance of $4 {\\sqrt 2}$.  Lattice points a minumum distance from the origin\r\nhave shapes: $(0^{16}, (\\pm 2)^8)$, $(0^{22}, (\\pm 4)^2)$, $((\\pm 1)^{23}, (\\pm 3))$.  \r\nHence the contact number is $98256$ (lattice point with even parity) + $98304$ \r\n(lattice point with odd parity) $= 196,560$;  \r\nthe density is $.001929$.  Each pair of adjacent lattice points is adjacent to $4600$\r\nothers. \\emph{Example:} $(4,4, 0, \\ldots, 0)$\r\nis adjacent to $(4,0, \\ldots , 0)$ - there are $88$ of these,\r\n$(2,2, \\ldots , 0)$ - there are $77 \\times 2^7$ of these and\r\n$(1,3, \\ldots , 0)$ - there are $2048$ of these.\r\nFor the first Leech packing,\r\nthe density is ${\\frac {2^{24}} { 2 \\times 2^{12}}}= 2^{-11}$, \r\nfirst factor of $2$ in \r\ndenominator is from condition that the sum of the\r\ncoordinates $= 0 \\jmod{4}$ and so the packing density is $.0009647$.  The\r\nLeech lattice doubles this which is about $.8$ of the Rogers bound.\r\n\\\\\r\n\\\\\r\nNoting that there must be an even number of $-2$'s,\r\nfor the Leech packing, lattice points with even coordinates are:\r\n\\begin{center}\r\n\\begin{tabular} {|r|r|}\r\n\\hline\r\n{\\bf Shape} & {\\bf Number} \\\\\r\n\\hline\r\n$0^{16}, (-2)^8$ & $759$ \\\\\r\n$0^{16}, (-2)^6, 2^2$ & $759 \\cdot {8 \\choose 2}=21252$ \\\\\r\n$0^{16}, (-2)^4, 2^4$ & $759 \\cdot {8 \\choose 4}=53130$ \\\\\r\n$0^{16}, (-2)^2, 2^6$ & $759 \\cdot {8 \\choose 2}=21252$ \\\\\r\n$0^{16}, 2^8$ & $759$ \\\\\r\n$0^{22}, (-2)^2$ & ${24 \\choose 2}=276$ \\\\\r\n$0^{22}, -2, 2$ & $ 24 \\cdot 23 =552$ \\\\\r\n$0^{22}, 2^2$ & ${24 \\choose 2}=276$ \\\\\r\n\\hline\r\n{\\bf Total} & $98256$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nThe lattice points with odd coordinates are:\r\n\\begin{center}\r\n\\begin{tabular} {|r|r|}\r\n\\hline\r\n{\\bf Shape} & {\\bf Number} \\\\\r\n\\hline\r\n$(-1)^{23}, 3$ & $24$ \\\\\r\n$(-1)^{16}, (1)^{7}, -3$ & $759 \\cdot 8= 6,072$ \\\\\r\n$(-1)^{15}, (1)^{8}, 3$ & $759 \\cdot 16= 12,144$ \\\\\r\n$(-1)^{12}, (1)^{11}, -3$ & $2576 \\cdot 12= 30,912$ \\\\\r\n$(-1)^{11}, (1)^{12}, 3$ & $2576 \\cdot 12= 30,912$ \\\\\r\n$(-1)^{8}, (1)^{15}, -3$ & $759 \\cdot 16= 12,144$ \\\\\r\n$(-1)^{7}, (1)^{16}, 3$ & $759 \\cdot 8= 6,072$ \\\\\r\n$(1)^{23}, -3$ & $24$ \\\\\r\n\\hline\r\n{\\bf Total} & $98304$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nThere are \r\n$4600$ vertices adjacent to $2$ adjacent simplex,\r\n$891$ vertices adjacent to $3$ adjacent simplex,\r\n$336$ vertices adjacent to $4$ adjacent simplex and\r\n$170$ vertices adjacent to $5$ adjacent simplex.  \r\nThis gives a dihedral like estimate on the size of the symmetry group.\r\n\\\\\r\n\\\\\r\n{\\bf Definition of\r\nConway's group:} ${\\bf .O}$ is the set of rotations in ${\\mathbb R}^{24}$ fixing $O$ \r\npointwise and $\\Lambda$ setwise.\r\n\\\\\r\n\\\\\r\n{\\bf Notation:}\r\n$v_S= \\sum_{i \\in S} v_i$. \r\n$Q= \\{ x^2: x \\in F_{23} \\}, N= \\Omega \\setminus Q$.\r\n$A+B= A \\setminus B \\cup B \\setminus A$.  $N_i= \\{ n-i, n \\in N \\}$.  Golay code,\r\n${\\cal C}$, is\r\ngenerated by $N_i, N_{\\Omega}$.  $N_A = \\sum_{a \\in A} N_a$.  $C \\in {\\cal C}$ iff $N_C=0$.\r\n$\\Omega= PL(23)$, $\\alpha: x \\mapsto x+1$, $\\beta: x \\mapsto 2x$,\r\n$\\gamma: x \\mapsto {\\frac {-1} x}$, \r\n$\\delta: x \\mapsto 9 x^3, x \\notin Q$ and\r\n$\\delta: x \\mapsto {\\frac {x^3} 9}, x \\in Q$.  \r\n$L_2(23)= PSL_2(23)= \\langle \\alpha, \\gamma \\rangle$,\r\n$M_{24}= \\langle \\alpha, \\gamma, \\delta \\rangle$.  If $\\pi \\in S_{\\Omega}$, define\r\n$(v_i)^{\\pi} = v_{\\pi(i)}$.  \r\n$\\epsilon_S(v_i) = -v_i, i \\in S$ and\r\n$\\epsilon_S(v_i) = v_i, i \\notin S$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 76:}\r\nThe set $G \\Lambda = \\{ 2 v_K, K \\in R(C) \\} \\cup\r\n\\{ v_{\\Omega} - 4 v_{\\infty} \\}$ generates $\\Lambda$.  If $v, w \\in G \\Lambda$, then\r\n$v \\cdot v= 16n$ and $v \\cdot w = 0 \\jmod{8}$.  \r\n$\\Lambda_n= \\{ x  \\in \\Lambda, x \\cdot x = 16n \\}$.  $\\Lambda_1 = \\emptyset$,\r\n$\\Lambda_2$ consists of \r\n$\\Lambda_2^2$ of shape $(0^{16}, (\\pm 2)^8)$ - there are $97152$ of these,\r\n$\\Lambda_2^3$ of shape $((\\pm 1)^{23}, (\\pm 3)^1)$ - there are $98,304$ of these,\r\n$\\Lambda_2^4$ of shape $(0^{22}, (\\pm 4)^2)$ - there are $1104$ of these.\r\nIn tabular form:\r\n\\begin{center}\r\n\\begin{tabular} {|r|r|r|}\r\n\\hline\r\n{\\bf Name} & {\\bf Shape} & {\\bf Number} \\\\\r\n\\hline\r\n$\\Lambda_2^2$ & $0^{16}, \\pm 2^8$ & $759 \\cdot 2^7$\\\\\r\n\\hline\r\n$\\Lambda_2^3$ & $\\pm 1^{22}, \\pm 3$ & $24 \\cdot 2^{12}$\\\\\r\n\\hline\r\n$\\Lambda_2^4$ & $0^{22}, \\pm 4^4$ & ${24 \\choose 2} \\cdot 2^2$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n{\\bf Notation:}\r\nIf $S \\in R(C)$, $\\epsilon_S \\in .O$.\r\n$E= \\langle \\epsilon_S \\rangle_{S \\in R(C)}$, $M= M_{24}$.  $N= EM$.\r\n$T_0= \\{0, 3, 15, \\infty \\}$,\r\n$T_1= \\{ 1,12,21,22 \\}$,\r\n$T_2= \\{ 2,7,11,13 \\}$,\r\n$T_3= \\{ 4,10,16,17 \\}$,\r\n$T_4= \\{ 5,6,9,19 \\}$,\r\n$T_5= \\{ 8, 14,18,20 \\}$,\r\n$B= \\{ T_0, T_1, T_2, T_3, T_4, T_5 \\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 77:}\r\n$\\lambda \\in .O$ and $\\lambda$ fixes $v_i$ (some $i$) iff $\\lambda \\in N$.\r\n\\begin{quote}\r\n\\emph{Proof of $\\rightarrow$:}\r\nSuppose $\\lambda \\in .O$ and $\\lambda(v_i)= v_i$.  If $\\lambda(v_j)= w_j, i \\ne j$ then\r\n$(v_i, w_j)= 0$.  Since $4 v_i + 4 v_j \\in \\Lambda_2$,\r\n$4 v_i + 4 w_j \\in \\Lambda_2$.  Examining the elements of $\\Lambda_2$, we see\r\n$w_j= \\pm v_k$ for some $k \\in \\Omega$ since $8w_j \\in \\Lambda$ and $4w_j \\notin \\Lambda$.\r\nDistinct values of $j$ yield distinct values of $k$.  Thus $\\lambda= \\pi \\epsilon_S$,\r\n$S \\subseteq \\Omega, \\pi \\in S_{24}$.  The non-zero coordinates of\r\n$\\lambda( 2 v_K ), K $ an octet are in the coordinate postions $\\pi(K)$, so\r\n$\\pi(K)$ is an octet and  $\\pi \\in M_{24}=M$.  $\\lambda( v_{\\Omega} - 4 v_{\\infty})$ is\r\na lattice point of the same shape and the coordinates are $=1 \\jmod{4}$.\r\n$\\epsilon_S: v_i \\mapsto -v_i, i \\in S$ so the coordinates of\r\n$\\lambda( v_{\\Omega} - 4 v_{\\infty})$ which are $= 3 \\jmod{4}$ are in the places\r\n$\\pi(S)$ and so $S \\in R(C)$.  So $\\lambda = \\pi \\epsilon_S \\in N$.\r\n\\end{quote}\r\n{\\bf Theorem 78:}\r\nIf $\\lambda(\\Lambda_2^4)= \\Lambda_2^4$ then\r\n$\\lambda \\in N$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe use the following lemma:\r\n\\\\\r\n\\emph{Lemma:} If $\\lambda \\in .O$ and $|\\lambda|= p$, a prime then $p \\le 23$ further,\r\nno element of $.O$ has order $13 \\cdot 23$.\r\n\\\\\r\n\\\\\r\nLet $H$ be the symmetries fixing $\\Lambda_2^4$ as a whole and $x= 4v_i +4v_j$\r\nand $N_x$ is the subgroup fixing $x$.  $N$ only changes signs and permutes\r\ncoordinates so $N: \\Lambda_2^4 \\rightarrow \\Lambda_2^4$ and fixes\r\n$\\Lambda_2^4(x)$ as a whole.  There are $2^2 {22 \\choose 2}= 924$ vectors\r\nof the form $\\pm 4 v_h \\pm 4 v_k$ are perpendicular to \r\n$\\pm(4 v_i - 4 v_j)$ with\r\n$h, i, j,k$ distinct and so are\r\n$\\pm(4 v_i - 4 v_j)$.  These $926$ vectors form\r\n$\\Lambda_2^4(x)$.  $N_x$ is $2$-transitive so $\\exists \\sigma: \r\n(4 v_i - 4 v_j) \\mapsto \\pm (4 v_i - 4 v_j) $ and no other elements are in this orbit.\r\nThus $\\{ (4 v_i - 4 v_j), -(4 v_i - 4 v_j) \\} $ form a single orbit.\r\n$N_x \\subseteq H_x$ and the orbits of $H_x$ are a union of $N_x$ orbits.  As a result,\r\nit is either all $926$ orbits or the $N_x$ orbits.  In the latter case,\r\n$|H_x: H_{x,y}| = 926= 2 \\cdot 463$ which contradicts the lemma.\r\nSo we know $H_x$ has $2$ orbits on $\\Lambda_2^4(x)$ and maps \r\n$(4 v_i - 4 v_j)$ to itself or it's negative.  In the first case, $\\lambda(v_i)= v_i$ and\r\n$\\lambda \\in N$ by the\r\nprevious theorem.  In the second case, $\\lambda( v_i)= v_j$ and hence\r\n$ (4 v_i + 4 v_h)  \\mapsto (\\pm 4 v_j \\pm 4 v_k) , h \\ne j $ and again $\\lambda \\in N$.  Thus\r\n$H_x \\subseteq N$ and $H_x \\subseteq N_x$ and therefore $H \\subseteq N$.\r\n\\end{quote}\r\n{\\bf Theorem 79:}\r\nThere is a subgroup isomorphic to $L_2(23)$ which is\r\ntransitive on octads. \r\n\\begin{quote}\r\n\\emph{Proof:} \r\nThere is a copy of $L_2(23)$ in $M_{24}$.\r\n\\end{quote}\r\n{\\bf Definition 20:} $\\epsilon(v_i) = \r\nv_i \\textnormal{ if } i \\notin Q \\textnormal{ and } -v_i \\textnormal{ if } i \\in Q $.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 80:} $N= \\langle \\alpha, \\beta, \\gamma, \\delta, \\epsilon \\rangle$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nApplying permutations from the right, note $\\epsilon_K= \r\n\\epsilon \\alpha  \\delta \\alpha  \\epsilon \\alpha^{-1} \\delta^{-1} \\alpha^{-1}$, \r\n$K= \\{ 0,1,4,5,11,12,14,22 \\}$.  If $L$ is another $8$-set and $\\theta: K \\rightarrow L$ then\r\n$\\epsilon_L = \\theta^{-1} \\epsilon_K \\theta$.\r\n\\end{quote}\r\n{\\bf Theorem 81:}\r\n$N$ is a proper subgroup of $.O$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nLet $T=T_0$ be any $4$-set of $\\Omega$.  $T$ lies in $5$, $8$ sets\r\n$ T+T_1, T+T_2, \\ldots, T+T_5$, where $T_i$ is the complement of\r\n$T$ in the $i$-th $8$-set.  $\\Omega$ is the disjoint union of\r\n$6$, $4$-sets.  $B= \\{ T_0 , T_1 , \\ldots , T_5 \\}$.\r\n$\\eta= \\eta_B: v_i \\mapsto v_i- {\\frac 1 2} v_{T_j}$ and\r\n$\\zeta_T= \\eta \\epsilon_T$.  $\\zeta_T^2=1$.  $\\zeta_T \\in .O$ and\r\n$\\zeta_T \\notin N$.\r\n\\end{quote}\r\n{\\bf Theorem 82:}\r\n$H_x$ is transitive on $\\Lambda_2(x)$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nLet $x= v_{\\Omega}- v_{\\infty}$.  The order of each orbit of $H_x$ on $\\Lambda_2(x)$\r\nhas order divisible by $23$.\r\n\\end{quote}\r\n{\\bf Theorem 83:}\r\nIf $H>N$, $H$ is transitive on $\\Lambda_2$ and $H=.O$.  $|.O|=\r\n2^{22} \\cdot 3^{9} \\cdot 5^4 \\cdot 7^2 \\cdot 11 \\cdot 13 \\cdot 23= 8,315,553,613,086,720,000$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n(1) $\\Lambda_2^2$, $\\Lambda_2^3$, $\\Lambda_2^4$ are all $N$-orbits.  \r\nA counting argument shows that the union of two\r\nof them can't be an $H$ orbit (otherwise, $p \\mid |.O|$ for $p>23$).  Now define\r\n$\\Lambda_2 (x)= \\{ y: y \\in \\Lambda_2, y \\perp x \\}$.\r\nRecall $H_x$ is transitive on $\\Lambda_2(x)$.\r\nSince $M_{24}$ is $5-$transitive $|H_x : H_{x,y}|= 926$ and\r\n$|.O|= |H| = 196560 \\cdot |H_x|$; further,  $H_x$ is transitive on \r\n$\\Lambda_2 (x)= \\{ y: y \\perp x \\}$.  An orbit of $H_x$ has $93150$ elements so\r\n$|H_x|= (93150) |H_{x,y}|$ and $H_{x,y} = E_{10} M_{22}$.  This gives the order of\r\n$H$ and shows $H=.O$.\r\n\\end{quote}\r\n{\\bf Definition 21:}\r\nFor $x \\in \\Lambda_2$, define $\\{ x , -x \\}$ is called a diameter.\r\n${\\overline {\\Lambda_2}}$ is the set of $98280$ diameters.\r\n$.1= .O_d, d= \\{x, -x \\}, x \\in \\Lambda_2$ \r\n\\\\\r\n\\\\\r\n{\\bf Theorem 84:} $N$ is maximal in $.O$.  $.O= \\langle N, \\zeta \\rangle$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nBy the theorem, if $H>N$, $H=.O$.  The second statement follows from $\\zeta \\notin N$ and $\\zeta \\in .O$.\r\n\\end{quote}\r\n{\\bf Theorem 85:} \r\n$.O$ is transitive on ordered pairs of points of vectors of $\\Lambda_2$ with a\r\ngiven scalar product.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$\\Lambda_2= \\{ v \\in \\Lambda: v \\cdot v= 16 \\cdot 2 \\}$.  By looking at products of\r\nvectors of standard type, the possible products are\r\n$0, \\pm 8, \\pm 16, \\pm 32$.  Put $\\Lambda_2(x,m)= \\{y: (x,y)= m \\}$.\r\nWe find orbits of $N_x$ on $\\Lambda_2(x,16)$ and show \r\n$\\Lambda_2(x,16)$ is a single orbit of $.O_x$.\r\n\\end{quote}\r\n{\\bf Observation:}\r\nLet $\\varphi$ be an octad, say $\\{ 0,1,2,3,4,7,10,12 \\}$,\r\nand $i \\notin \\varphi$; suppose $K$ is the subgroup fixing $\\varphi$,\r\nsetwise and $H= K_i$.  The subset fixed is of codimension $8$ so it has dimension $4$.  $K$\r\nacts naturally on this $4$-dimensional subspace.  $K \\approx 2^4 L_4(2)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 86:} \r\n$.1 \\cong .O/{\\mathbb Z}(.O)$ and\r\n$|{\\mathbb Z}(.O)|= 2$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nSuppose $\\lambda \\notin \\{\\pm1\\} \\in {\\mathbb Z}(.O)$.\r\n$\\theta_i= \\alpha^{23-i} \\gamma \\alpha  \\gamma \\alpha^i $ fixes $i$ and moves all other\r\npoints of $\\Omega$.  \r\n(1) $\\lambda$ cannot send $v_j \\mapsto \\pm v_j, \\forall j$ since\r\n$(v_j)\\lambda \\alpha = - v_{j+1}$ and\r\n$(v_j)\\alpha \\lambda= v_{j+1}$.  \r\n(2) $\\lambda$ cannot map $v_i \\mapsto \\pm v_j, i \\ne j$, \r\n$(v_i) \\lambda \\theta_i= \\pm (v_j) \\theta_i= \\pm v_k \\ne \\pm  v_j$, but\r\n$(v_i) \\theta_i \\lambda= \\pm (v_j)$.\r\n(3) Remaining case, namely, $\\lambda: v_i \\mapsto w \\ne \\pm v_j, j \\in \\Omega$ is impossible too.\r\nIf $(v_j)\\lambda = w \\ne \\pm v_k$, any $k$.  $(8v_i)\\lambda \\in \\Lambda_4$ and has one of the following\r\nform $(0^{23},\\pm 8^{1})$, $(\\pm 0^{20},\\pm 4^{4})$, $(\\pm 0^{16},\\pm 2^{7}, \\pm 6^{1})$,\r\n$(\\pm 0^{14},\\pm 2^{8}, \\pm 4^{2})$, $(\\pm 0^{11},\\pm 2^{12}, \\pm 4^{1})$, $(\\pm 0^{8},\\pm 2^{16})$,\r\n$(\\pm 1^{21},\\pm 3^{2}, \\pm 5^{1})$, $(\\pm 1^{19},\\pm 3^{5})$.  The only one fixed by $\\theta_i$ is\r\n$8v_i$.  Thus\r\n$(v_i) \\lambda \\theta_i = (w)\\theta_i \\ne w$ but\r\n$(v_i) \\theta_i \\lambda= w$ and the theorem holds.\r\n\\end{quote}\r\n{\\bf Theorem 87:}\r\n$.1$ acts primitively on ${\\overline {\\Lambda_2}}$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nEach element of $.1$ permutes $98280$ diameters.  Since $.O$ is transitive on\r\n$\\Lambda_2$, $.1$ is transitive for diameters.  Suppose\r\n$.1$ is imprimitive.  $|S_1| \\mid 98280$.  Let ${\\overline x} \\in S_1$.\r\nSince $|S_1| \\ge 1, \\exists y \\in S_1$ whose orbit under $.1_{\\overline x}$\r\nhas order $4600, 47104, 46575$.  Since $.1$ fixes ${\\overline x}$,\r\n$.1: S_1 \\rightarrow S_1$ and $|S_1| \\ge 4601$.  None divide\r\n$98280$ so $\\exists {\\overline z} \\ne {\\overline x}$ outside $S_1$.\r\nBut then $S_1$ which has at least $1+4600+46575=51176$ and thus must be all of\r\n${\\overline {\\Lambda_2}}$.  This contradicts the assumed imprimitivity of $.1$.\r\n\\end{quote}\r\n{\\bf Theorem 88:}\r\n$.1= .O/{\\mathbb Z}(.O)$ is simple.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nSuppose ${\\mathbb Z}(H) \\subsetneq H \\subsetneq .O$.  \r\n(1) $H$ is transitive on ${\\overline {\\Lambda_2}}$.\r\nIf not $\\exists {\\overline x}= \\{x, -x\\}$\r\nand $y \\in \\Lambda_2: \\eta(x)= y, \\eta \\in H$.  $.O$ is transitive on\r\n${\\overline {\\Lambda}}_2$.  Orbits of $H$ in ${\\overline {\\Lambda}}_2$ are of\r\nequal size.\r\n(2) $N$ is not normal in $.0$.  This is proved by looking at $B$, the $4$-subsets defined above.\r\n(3) $H=N$.  $|H:H_x|= 13 \\cdot 7560$.  Let $P \\in S_{13}$.  Since $H$ is normal, all the sylow $13$\r\nsubgroups of $.O$ are in $H$ so\r\n$|>O:N_{.O}(P)= |ccl_{.O}(P)|=\r\n|ccl_{H}(P)|= |H:N_H(P)|$ and $|.O:H|= |N_{.O}(P):N_H(P)|$ with $N_H(P)= N_{,O}(P) \\cap H$.\r\nThus $|.O|= |N_{.O}(P)H|= {\\frac\r\n{|N_{.O}(P)| \\cdot |H|}\r\n{|N_{.O}(P) \\cap H|}}$ and\r\n$23 \\mid |N_{.O}(P)|$ or $23 \\mid |H|$.  In the former case, put\r\n$K= \\langle \\lambda \\rangle$,\r\n$P= \\langle \\mu \\rangle$, $|\\lambda|= 13$, but then $|PK|=13 \\cdot 23$ which contradicts an\r\nearlier lemma.  In the latter case,  $23 \\mid |H|$ so $H \\cap N = N$ but $N$ is maximal so\r\n$H=N$.\r\nNow we have $H \\lhd .O$ and $H=N$ but $N$ is not normal and this establishes the result.\r\n$\\zeta \\in .1: x \\mapsto z$,\r\n$\\lambda \\in H: x \\mapsto w$.\r\n$\\zeta(w)= \\zeta(\\lambda(x))= \\zeta \\lambda \\zeta^{-1}(z)$ is in orbit of $z$\r\nsinze $\\zeta \\lambda \\zeta^{-1} \\in H$.  $.1$ preserves orbits in\r\n$\\Lambda_2$ and the orbits are sets of imprimitivity for $.1$ on\r\n${\\overline {\\Lambda}}_2$ which contradicts the previous result.\r\nFor $x \\in {\\overline {\\Lambda}}_2$, \r\n$|H:H_x|=|{\\overline {\\Lambda}}_2| = 98280= 13 \\cdot 7560$.\r\nLet $P \\in S_{13}(H)$ all such are $H$ conjugate and\r\n$|.O:N_{.O}(P)|= |H:N_H(P)|$.\r\n\\end{quote}\r\n{\\bf Conway's other simple groups:} \r\n$.2= \\{ x \\in .O$, $x$ stabilizes\r\n$2$ points $v,w \\in \\Lambda_2: |v-w|= 4 {\\sqrt 2} \\}$.\r\n$.3= \\{ x \\in .O$, where $x$ stabilizes\r\n$2$ points $v,w \\in \\Lambda_2: |v-w|= 4 {\\sqrt 3} \\}$.\r\n", "meta": {"hexsha": "c7da3625a43987d3b2ebe3db1a0a74df085594c8", "size": 98410, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "groups/gtSpecific.tex", "max_stars_repo_name": "jlmucb/class_notes", "max_stars_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "groups/gtSpecific.tex", "max_issues_repo_name": "jlmucb/class_notes", "max_issues_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "groups/gtSpecific.tex", "max_forks_repo_name": "jlmucb/class_notes", "max_forks_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.3084714549, "max_line_length": 136, "alphanum_fraction": 0.5771771161, "num_tokens": 42266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733979704703, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7186872881339216}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{3n-1}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution 1}\r\n\r\n$\\displaystyle \\sum_{n=1}^\\infty \\frac1{n}$ is a $p$-series which diverges by the $p$-series test. If we use $a_n = \\frac{1}{3n-1}$ and $b_n = \\frac1{n}$, then\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} \\frac{a_n}{b_n}\r\n&= \\lim_{n \\to \\infty} \\frac{1}{3n-1} \\cdot \\frac{n}{1}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{n}{3n-1} \\\\\r\n&= \\lim_{n \\to \\infty} \\frac13 \\text{ using L'hopital}\\\\\r\n&= \\frac13\r\n\\end{align*}\r\nSo by the Limit Comparison Test, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{3n-1}$ diverges.\r\n\r\n\\subsection*{Solution 2}\r\n\r\nThe Direct Comparison Test will also work, but will involve finding first finding a fixed value of $K > 0$ such that\r\n\\[ K \\cdot \\frac{1}{3n-1} \\geq \\frac1n.\\]\r\nMultiply both sides by $n(3n-1)$.\r\n\\[ Kn \\geq 3n-1\\]\r\nThis inequality will be true for all $n$ if we choose $K=3$.\r\nSo we are done with the scratch work and instead begin our work:\r\n\r\nNote that\r\n\\[ 3n \\geq 3n-1\\]\r\nDividing both sides by $3n(3n-1)$, we get\r\n\\[ \\frac{1}{3n-1} \\geq \\frac1{3n}\\]\r\nThe series $\\displaystyle \\sum_{n=1}^\\infty \\frac1{3n} = \\frac13\\sum_{n=1}^\\infty \\frac1{n}$ is a $p$-series which diverges by the $p$-series test. So the series $\\displaystyle \\sum_{n=1}^\\infty \\frac1{3n-1}$ diverges by the Direct Comparison Test.\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\left|\\frac{a_{n+1}}{a_n}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\right|\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} a_n\r\n&= \\lim_{n \\to \\infty} \\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "555e72ba63c647607b2b6219a8f3359ad6dae4cf", "size": 2285, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/i1.tex", "max_stars_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_stars_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "key/series/i1.tex", "max_issues_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_issues_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "key/series/i1.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 34.1044776119, "max_line_length": 249, "alphanum_fraction": 0.6380743982, "num_tokens": 856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339716830606, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7186872828123195}}
{"text": "\\section{The Erone's model}\nAs discussed in the previous chapters, once some points of interest are determined in the wheel profile, it is simple to estimate its measures: in fact, they are simple distances between the keypoints, along a specific axis. However, the estimation of the wheel diameter is not so trivial. As shown in Section \\ref{sec:sys-cmp}, there are many models used to estimate the diameter, and all of them require at least three point to reach this goal. Furthermore, many of them can be improved by using more points along the profile. In systems like the one we are considering, we need more laser-camera pair to increase the number of the profiles acquired at the same time, thus the number of detectable rolling points is increased. Another solution could be to project a single laser beam perpendicularly to the wheel rolling section, so with a single stripe we are able to collect more than three points. \\\\\nThe second problem is the choice of the fitting algorithm, in order to correctly identify the shape of the rolling section. As we already said, rail wheels are conical-shaped, thus it is extremely important to identify the correct plane in which the rolling section lies. Also in this case, there are a lot of algorithm that solve this problem, and our choice has been the Erone's formula. \\\\\n\nThe Erone's formula is a general mathematical model that allows to estimate the area of a triangle, when the lengths of its sides are known. Let $a$, $b$ and $c$ are these length, the equation for the area is given by:\n  \\begin{equation}\n    A = \\frac{\\sqrt{( a + b + c )( - a + b + c )( a - b + c )( a + b - c )}}{4}\n    \\label{eq:area}\n  \\end{equation}\nIt is simple to see that the detected rolling points along the profile could be seen as the vertexes of a triangle inscribed in a circumference, thus $a$, $b$ and $c$ can be estimated as the reciprocal distance between these points. % An example of this approximation is shown in Figure \\ref{fig:triang-inscritto}. \n%  \\begin{figure}[b!]\n%    \\centering\n%    \\includegraphics[width=0.4\\textwidth]{./images/wpms/triang-insc.png}\n%    \\caption{Representation of the triangle obtained from the rolling points detected from the wheel profiles}\n%    \\label{fig:triang-inscritto}\n%  \\end{figure}\nHence, we can define the diameter $D$ of the circle circumscribed to the triangle as follows:\n  \\begin{equation*}\n    D = \\frac{a\\cdot b\\cdot c}{2A}\n  \\end{equation*}\nand replacing $A$ with Equation \\ref{eq:area}, we can conclude that:\n  \\begin{equation}\n    D = \\frac{2\\cdot a\\cdot b\\cdot c}{\\sqrt{( a + b + c )( - a + b + c )( a - b + c )( a + b - c )}}\n    \\label{eq:diam:erone}\n  \\end{equation}\n~\\\\\n\nAs we have done for the model proposed in Chapter \\ref{ch::model}, we are interested in determining the error made while we are evaluating this property of the wheel, and if possible, to develop a model that allows to determine the better configuration during the design of the system. Thus, we used the same approach as before, and the equation for the propagation error is:\n  \\begin{equation}\n    \\sigma_D = \\sqrt{\n      \\left( \\frac{\\partial D}{\\partial a} \\sigma_a \\right)^2 + \n      \\left( \\frac{\\partial D}{\\partial b} \\sigma_b \\right)^2 + \n      \\left( \\frac{\\partial D}{\\partial c} \\sigma_c \\right)^2\n    }\n    \\label{eq:diam-prop-1}\n  \\end{equation}\nHowever, we had some problems to evaluate the errors $\\sigma_a$, $\\sigma_b$ and $\\sigma_c$. Each point used as vertex for the triangle, was obtained from a different laser-camera pair. Accordingly with what we have done in Chapter \\ref{ch::model}, each of these pairs could be set in a different way, depending by the requirements, hence the weight of the noise in the final spot detection, can be different pair by pair.\n\nTo solve this problem we thought to project all the points in a common reference system, like the one shown in Figure \\ref{fig:common-rs}.\n  \\begin{figure}[t!]\n    \\centering\n    \\includegraphics[width=\\textwidth]{./images/wpms/diam_rs.png}\n    \\caption{Example of the common reference system used for all the detected rolling points}\n    \\label{fig:common-rs}\n  \\end{figure}\nIn this way, each vertex can be defined by a vector, starting from the laser projector to the point itself. We called this vector $y_i$. Using simple trigonometric relationships, we can decompose each vector in the its components $w_i$ and $z_i$ as follows:\n  \\begin{equation}\n    \\begin{matrix}\n      w_i = y_i \\cdot \\sin \\theta_i \\\\ \\\\\n      z_i = y_i \\cdot \\cos \\theta_i + H_i \\\\\n    \\end{matrix}\n    \\label{eq:components}\n  \\end{equation}\nwhere $\\theta_i$ is the triangulation angle and $H_i$ is the offset of the laser projector with respect to the origin of the coordinate system. At this point, it is simple to compute the edges length as:\n  \\begin{equation}\n    \\left\\{\n    \\begin{matrix} \n      & a = \\sqrt{(w_1 - w_2)^2 + (z_1 - z_2)^2} \\\\ \\\\\n      & b = \\sqrt{(w_2 - w_3)^2 + (z_2 - z_3)^2} \\\\ \\\\\n      & c = \\sqrt{(w_3 - w_1)^2 + (z_3 - z_1)^2}\n    \\end{matrix}\n    \\right.\n    \\label{eq:edges-len}\n  \\end{equation} \\\\\nHence, replacing in Equation \\ref{eq:diam-prop-1} the results obtained in Equations \\ref{eq:edges-len} and \\ref{eq:components}, we can conclude that the error is propagated accordingly with:\n  \\begin{equation}\n    \\sigma_D = \\sqrt{\n      \\sum_{i = 1}^3 \\left( \\frac{\\partial D}{\\partial y_i} \\sigma_{y_i} \\right)^2 + \n      \\sum_{i = 1}^3 \\left( \\frac{\\partial D}{\\partial H_i} \\sigma_{H_i} \\right)^2 + \n      \\sum_{i = 1}^3 \\left( \\frac{\\partial D}{\\partial \\theta_i} \\sigma_{\\theta_i} \\right)^2\n    }\n    \\label{eq:diam-prop-2}\n  \\end{equation} \\\\\n \nThe last step, is linking the Equation \\ref{eq:diam-prop-2} with the output of the Equations \\ref{eq:radial-compensations}. In real conditions, the transformations between the laser-camera pairs and the common coordinate reference system are allowed by a second calibration process. As discussed in Section \\ref{sec:teo-calibration}, the camera calibration can determine the intrinsic and extrinsic parameters of a single camera. However, this process can be modified in order to align two or more cameras at the same reference system, as in this case. \\\\\nIdeally, the two reference systems are related to each other through a rototranslation, i.e. a linear transformation. This means that the vector $y_i$ remains the same, except for the values of its coordinates. Thus, we can determine the norm of $y_i$ as:\n  \\begin{equation*}\n    |y_i| = \\sqrt{x_w^2 + y_w^2 + z_w^2}\n  \\end{equation*}\nwhere $\\left( x_w, y_w, z_w \\right)$ are the coordinates evaluated with Equations \\ref{eq:radial-compensations}, and $z_w = 0$ accordingly with the fact that the laser plane is arbitrarily put at $0$. Now, it is simple to determine $\\sigma_{y_i}$ as:\n  \\begin{equation*}\n    \\sigma_{y_i} = \\sqrt{\n      \\left( \\frac{\\partial y_i}{\\partial x_w} \\sigma_{x_w} \\right)^2 + \n      \\left( \\frac{\\partial y_i}{\\partial y_w} \\sigma_{y_w} \\right)^2\n    }\n    % = \\frac{x}{\\sqrt{x_w^2 + y_w^2}}\n  \\end{equation*}\nwhere $\\sigma_{x_w}$ and $\\sigma_{y_w}$ are the value computed with Equations \\ref{eq:err-radial-comp-xw} and \\ref{eq:err-radial-comp-yw}, respectively. \\\\\n\nConcerning the estimation of $\\sigma_{H_i}$ and $\\sigma_{\\theta_i}$, the things are simpler. The errors of $H_i$ are a constructive parameters, i.e. we can set them reasonably, with respect to the requirements of product construction. Vice-versa, $\\theta_i$ are the same triangulation angles used in Chapter \\ref{ch::model}, thus $\\sigma_{\\theta_i}$ can be computed accordingly with Equation \\ref{eq:det_a}.\n", "meta": {"hexsha": "adc07c62e8053cde07cd4bc333100932121e0a83", "size": 7577, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/thesis/src/chapters/ch6-Diameter/model.tex", "max_stars_repo_name": "extoxesses/LaserMat", "max_stars_repo_head_hexsha": "4e893cd56ecea8497918ecafb642b2fbf9a085a2", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-05-12T08:53:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T06:36:55.000Z", "max_issues_repo_path": "report/thesis/src/chapters/ch6-Diameter/model.tex", "max_issues_repo_name": "extoxesses/LaserMat", "max_issues_repo_head_hexsha": "4e893cd56ecea8497918ecafb642b2fbf9a085a2", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/thesis/src/chapters/ch6-Diameter/model.tex", "max_forks_repo_name": "extoxesses/LaserMat", "max_forks_repo_head_hexsha": "4e893cd56ecea8497918ecafb642b2fbf9a085a2", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 83.2637362637, "max_line_length": 905, "alphanum_fraction": 0.7163785139, "num_tokens": 2105, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.8031737987125613, "lm_q1q2_score": 0.7186714432705257}}
{"text": "\\section{Free precession\\label{correctBrettAppendix}}\n\nThis argument is modelled after~\\cite{Ruf:02}. The moment of inertia $\\ve{L}$ of a rigid\nbody is defined as\n\\begin{equation}\n\\label{correctBrett1}\n\\ve{L} = \\m{I}\\ve{\\omega}\n\\end{equation}\nwhere $\\m{I}$ is the inertia tensor and $\\ve{\\omega}$ is the angular velocity vector.\nTorque is the rate of change of angular momentum over time:\n\\begin{equation}\n\\label{correctBrett2}\n\\ve{\\tau} = \\dot{\\ve{L}} = \\dot{\\m{I}}\\ve{\\omega} + \\m{I}\\dot{\\ve{\\omega}}\n\\end{equation}\n\nWe can further evaluate $\\dot{\\m{I}}$ by writing \\m{I} as a product with some rotation matrix\n$\\m{R}$ and its transpose:\n\\begin{equation}\n\\label{correctBrett3}\n\\m{I} = \\m{R}\\m{I}_\\mathrm{body}\\m{R}^T\n\\end{equation}\n\nIt can be shown that such a decomposition of the inertia tensor always exists, and that\n$\\m{I}_\\mathrm{body}$ is a diagonal, time-invariant matrix containing the moments\nof inertia about the body's principal axes~\\cite{Feynman:63}. Hence we obtain\n\\begin{equation}\n\\label{correctBrett4}\n\\dot{\\m{I}} = \\dot{\\m{R}}\\m{I}_\\mathrm{body}\\m{R}^T +\n    \\m{R}\\m{I}_\\mathrm{body}\\frac{\\diff}{\\diff t}\\m{R}^T\n\\end{equation}\n\nWitkin~\\cite{BaraffWitkin:97} derives that $\\dot{\\m{R}} = \\dual{\\ve{\\omega}}\\,\\m{R}$\nfor a rotation matrix $\\m{R}$ and an angular velocity vector $\\ve{\\omega}$.\nUsing this identity and taking the differential operator onto the inside of the\ntranspose at the end of equation~\\ref{correctBrett4},\n\\begin{eqnarray}\n\\dot{\\m{I}} &=& \\dual{\\ve{\\omega}}\\,\\m{R}\\m{I}_\\mathrm{body}\\m{R}^T +\n    \\m{R}\\m{I}_\\mathrm{body}(\\dual{\\ve{\\omega}}\\,\\m{R})^T \\nonumber\\\\\n&=& \\dual{\\ve{\\omega}}\\,\\m{R}\\m{I}_\\mathrm{body}\\m{R}^T -\n    \\m{R}\\m{I}_\\mathrm{body}\\m{R}^T\\dual{\\ve{\\omega}} \\nonumber\\\\\n&=& \\dual{\\ve{\\omega}}\\,\\m{I} - \\m{I}\\dual{\\ve{\\omega}} \\label{correctBrett5}\n\\end{eqnarray}\n\nSubstituting equation~\\ref{correctBrett5} back into~\\ref{correctBrett2}:\n\\begin{eqnarray}\n\\ve{\\tau} & = & \\m{I}\\dot{\\ve{\\omega}} + \\dual{\\ve{\\omega}}\\,\\m{I}\\ve{\\omega} -\n    \\m{I}\\dual{\\ve{\\omega}}\\,\\ve{\\omega} \\nonumber \\\\\n& = & \\m{I}\\dot{\\ve{\\omega}} + \\dual{\\ve{\\omega}}\\,\\m{I}\\ve{\\omega} \\label{correctBrett6}\n\\end{eqnarray}\n\nEquation~\\ref{correctBrett6} corrects the similar expression in~\\cite{Saunders:PhD},\npage~34. This means that the angular acceleration of a rigid body is given by\n\\begin{equation}\n\\label{correctBrett7}\n\\dot{\\ve{\\omega}} = \\m{I}^{-1} (\\ve{\\tau} - \\dual{\\ve{\\omega}}\\,\\m{I}\\ve{\\omega}).\n\\end{equation}\nwhere \\ve{\\tau} is the sum of all torque vectors acting on the body. This means that even if\nthere are no torques, its angular velocity may change if \\m{I} is not diagonal (i.e.\\ if\nthe body is somehow asymmetric). This effect is called \\emph{free precession}.\n\nIn a simulation, we usually integrate over torques to find angular momentum, and then calculate\nthe angular velocity from the momentum in each time step using the current moment of inertia. In\nthis case, the angular acceleration in equation~\\ref{correctBrett7} is not needed. It is required\nonly for purposes of computing constraint forces and torques.\n", "meta": {"hexsha": "8a432766059b583ec94a3e51903755b31d54b4b1", "size": 3064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/rigidBody.tex", "max_stars_repo_name": "ept/maniation", "max_stars_repo_head_hexsha": "546b78cec5cf3a83986a94086b97f4236b76df2a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-05-09T00:54:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:40:52.000Z", "max_issues_repo_path": "report/rigidBody.tex", "max_issues_repo_name": "ept/maniation", "max_issues_repo_head_hexsha": "546b78cec5cf3a83986a94086b97f4236b76df2a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/rigidBody.tex", "max_forks_repo_name": "ept/maniation", "max_forks_repo_head_hexsha": "546b78cec5cf3a83986a94086b97f4236b76df2a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-04-17T14:39:12.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-08T05:38:45.000Z", "avg_line_length": 47.1384615385, "max_line_length": 97, "alphanum_fraction": 0.6932114883, "num_tokens": 1075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055545, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7186568119842836}}
{"text": "\\subsection{Eigenvalues \\& Eigenvectors}\r\n\\begin{definition}\r\n\tLet $A$ be an $n \\times n$ matrix. A scalar $\\lambda$ and a vector $\\vec{v}$ are an eigenvalue and eigenvector of $A$ if\r\n\t\\begin{equation*}\r\n\t\tA\\vec{v} = \\lambda\\vec{v}\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\\noindent\r\nWe call $p(\\lambda) = \\det{(A - \\lambda I)}$ the characteristic polynomial of $A$. The eigenvalues for $A$ are the solutions to the equation\r\n\\begin{equation*}\r\n\tp(\\lambda) = \\det{(A - \\lambda I)} = 0\r\n\\end{equation*}\r\nOnce we have an eigenvalue, we can find the basis vectors for the corresponding eigenspace by solving the equation\r\n\\begin{equation*}\r\n\t\\left( A - \\lambda I \\right)\\vec{v} = \\vec{0}\r\n\\end{equation*}\r\nThe basis vectors of the eigenspace for $A$ are the union of the basis vectors of each eigenspace corresponding to each eigenvalue.\r\n\r\n\\ifodd\\includeBackgroundReviewExamples\\input{./backgroundReview/matrices/eigenvaluesEigenvectors_example.tex}\\fi", "meta": {"hexsha": "7dd7e632d91bcec052e3e70656fa723a5598d9f9", "size": 947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/backgroundReview/matrices/eigenvaluesEigenvectors.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/backgroundReview/matrices/eigenvaluesEigenvectors.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/backgroundReview/matrices/eigenvaluesEigenvectors.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.8421052632, "max_line_length": 141, "alphanum_fraction": 0.7233368532, "num_tokens": 286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.718656800403585}}
{"text": "\\section{The intuition behind SVD}\n\nIn this section we will provide several informal ways of looking at\nthe SVD factorization, aiming to ignite the formal discussion of next\nsection (where we prove the SVD theorem). \\\\\n\n\\input{svd-intuit-fcomp.tex}\n\\input{svd-intuit-cbasis.tex}\n\\input{svd-intuit-geoin.tex}\n\nAlthough the geometrical interpretation works great for a simple\nexample in \\R{2}, there are a couple of missing details in the action of\nmatrix $\\Sigma$ which are worth mentioning. The first, is that the\ndimensions of $\\Sigma$ are those of the original matrix ($n \\times\nm$); therefore, its action is not only expanding or contracting, but\nalso a migration of space (from \\R{n} to \\R{m}). If there are more\nrows than columns ($m > n$), the transformation $\\Sigma$ will produce\na bigger vector than its input (the diagonal entries beyond position\n$n$ will be zeroes, which in turn will fill the new vector entries\nwith zeroes as well; up to $m$ entries). If on the contrary we have\nmore columns than rows ($m < n$), then the effect will be a truncation\nof the input vector (resulting vector has as many entries as rows in\n$\\Sigma$). In our example, this change of space was not perceived, as $n\n= m$. \\\\\n\nThe second omitted detail about the action of $\\Sigma$ in \n\\cref{fig:svd-geo-diag}, is even more subtle: along with the migration\nof space \\R{n} to space \\R{m}, we are also changing the basis; from\n$\\{\\vec{v_1},\\vec{v_2},\\dots,\\vec{v_n}\\}$ to\n$\\{\\vec{u_1},\\vec{u_2},\\dots,\\vec{u_m}\\}$. This additional effect may\nnot be evident at all, but is thanks to an additional property that\nis required on the two basis for the SVD factorization to hold:\n\n\\[\nA\\vec{v_i} = \\sigma_i\\vec{u_i}, \\ds{}\\forall i=1 \\dots r, \\ds{}\\text{where\n} r = rank(A).\n\\]\n\\hfill\n\nThe above property tells us that the vectors from the two basis were\npicked in a very special way: each vector \\vec{u_i} is parallel to the\nimage under $A$ of its associated \\vec{v_i}; in other words, the\ntransformation $A$ maps the \\R{n} basis\n$\\{\\vec{v_1},\\dots\\,\\vec{v_n}\\}$, into vectors which are parallel to\nthe \\R{m} basis $\\{\\vec{u_1},\\dots\\,\\vec{u_m}\\}$. Given that both basis\nare orthonormal, a consequence from this observation is that the\northogonality of the basis $\\{\\vec{v_1},\\dots\\,\\vec{v_n}\\}$ is preserved\nunder $A$ (\\cite{kalman96}). This is not a trivial property, and not\nevery basis has it (given $A$ is assumed to be given). This is\nactually the key problem of the SVD factorization, and the proofs\nprovided in the next section, focus around the problem of finding such\nspecial basis.  \n\n", "meta": {"hexsha": "dd8edc3874baa4b4b163af86f13f37b359309f88", "size": 2575, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-intuit.tex", "max_stars_repo_name": "rzavalet/svd-lsi-project-master", "max_stars_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "svd-intuit.tex", "max_issues_repo_name": "rzavalet/svd-lsi-project-master", "max_issues_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "svd-intuit.tex", "max_forks_repo_name": "rzavalet/svd-lsi-project-master", "max_forks_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.6851851852, "max_line_length": 74, "alphanum_fraction": 0.734368932, "num_tokens": 739, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.8740772318846386, "lm_q1q2_score": 0.7186567916756851}}
{"text": "\\subsection{Ring ideals}\\label{subsec:ring_ideals}\n\n\\begin{definition}\\label{def:semiring_ideal}\n  Let \\( R \\) be a semiring and \\( I \\) be a subset of \\( R \\). We say that \\( I \\) is an \\term{ideal} (left, right or two-sided) if \\( (I, +) \\) is a subgroup of \\( (R, +) \\) and \\( (I, \\cdot) \\) is a \\hyperref[def:magma_ideal]{magma ideal} of \\( (R, \\cdot) \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:semiring_ideal_is_nonunital_subsemiring}\n  Two-sided semiring ideals are subsemirings. In the special case where the semiring is unital, an ideal is a unital subsemiring if and only if it is not a proper ideal.\n\\end{proposition}\n\\begin{proof}\n  Follows from \\fullref{thm:magma_ideal_is_submagma} and \\fullref{thm:unital_magma_ideal_is_submagma_iff_contains_identity}.\n\\end{proof}\n\n\\begin{definition}\\label{thm:semiring_ideal_iff_kernel}\n  A subset of a ring is a two-sided \\hyperref[def:semiring_ideal]{ideal} if and only if it is the \\hyperref[def:semiring_kernel]{kernel} of some ring homomorphism.\n\\end{definition}\n\\begin{proof}\n  \\SufficiencySubProof Let \\( I \\) be a two-sided ideal. Since it is an abelian group, \\( I \\) is a normal subgroup and thus we can form the quotient \\hyperref[def:normal_subgroup]{group} \\( R / I \\) with the canonical projection\n  \\begin{balign*}\n     & \\pi: R \\to R / I       \\\\\n     & \\pi(x) \\coloneqq x + I\n  \\end{balign*}\n\n  Multiplication in \\( R \\) induces multiplication in \\( R / I \\) by\n  \\begin{equation*}\n    (x + I) \\cdot (y + I) \\coloneqq (xy + I).\n  \\end{equation*}\n\n  It is well-defined since if \\( x + I = x' + I \\) and \\( y + I = y' + I \\), then\n  \\begin{balign*}\n    (x + I) (y + I)\n     & =\n    xy + (Iy + xI + II)\n    =    \\\\ &=\n    xy + I\n    =    \\\\ &=\n    x'y' + I\n    =    \\\\ &=\n    x'y' + (Iy' + x'I + II)\n    =    \\\\ &=\n    (x' + I) (y' + I).\n  \\end{balign*}\n\n  Thus, the ring structure on \\( R \\) induces a ring structure on \\( R / I \\).\n\n  The canonical projection \\( \\pi \\) is an additive group homomorphism. Since we just showed that \\( \\pi(xy) = \\pi(x) \\pi(y) \\), it follows that it is also a ring homomorphism.\n\n  It only remains to show that \\( \\ker(\\pi) = I \\). Since \\( I \\) is closed under addition, naturally \\( I \\subseteq \\ker(\\pi) \\). Conversely, if \\( x \\in \\ker(\\pi) \\), then \\( \\pi(x) = \\pi(0) = I \\), i.e. \\( x \\in I \\). Hence, \\( \\ker(\\pi) = I \\).\n\n  \\NecessitySubProof Let \\( f: R \\to T \\) is a ring homomorphism. We must show that \\( \\ker(f) \\) is an ideal. If \\( x \\in R \\) and \\( y \\in \\ker(f) \\), then\n  \\begin{equation*}\n    f(xy) = f(x) f(y) = f(x) 0 = 0.\n  \\end{equation*}\n\n  Thus, \\( xy \\in \\ker(f) \\). Similarly, we can show that \\( yx \\in \\ker(f) \\). Thus, \\( R \\ker(f) = \\ker(f) R = \\ker(f) \\) and \\( \\ker(f) \\) is a two-sided ideal.\n\\end{proof}\n\n\\begin{definition}\\label{def:generated_ring_ideal}\n  Let \\( R \\) be a commutative ring, so that left and right ideals coincide. Let \\( S \\subseteq R \\) be any nonempty subset of \\( R \\). We define the ideal generated by \\( S \\) equivalently as either\n  \\begin{thmenum}\n    \\thmitem{def:generated_ring_ideal/minimal} the smallest ideal of \\( R \\) that contains \\( S \\).\n    \\thmitem{def:generated_ring_ideal/direct} the ideal\n    \\begin{equation*}\n      \\braket S \\coloneqq \\left\\{ \\sum_{k=1}^n r_k s_k \\mid r_1, \\ldots, r_n \\in R, s_1, \\ldots, s_n \\in S, n \\in \\BbbZ_{>0} \\right\\}\n    \\end{equation*}\n    of finite linear combinations.\n\n    \\thmitem{def:generated_ring_ideal/polynomials} the ideal\n    \\begin{equation*}\n      \\braket S \\coloneqq \\left\\{ p(s_1, s_2, \\ldots, s_n) \\mid s_1, \\ldots, s_n \\in S, p \\in R[X_1, \\ldots, X_n], n \\in \\BbbZ_{>0} \\right\\}\n    \\end{equation*}\n  \\end{thmenum}\n\n  If \\( S \\) is finite, then \\( \\braket S \\) is called \\term{finitely generated}. If \\( S = \\{ s_1, \\ldots, s_n \\} \\), then\n  \\begin{equation*}\n    \\braket S = s_1 R + s_2 R + \\cdots s_n R.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}\\label{def:principal_ideal}\n  If an ideal \\( I \\) is \\hyperref[def:generated_ring_ideal]{generated} by a single element, it is called a \\term{principal ideal}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:product_of_principal_ideals}\n  In a commutative unital ring \\( R \\) the product of the principal ideals \\( \\braket{x} \\) and \\( \\braket{y} \\) is \\( \\braket{xy} \\).\n\\end{proposition}\n", "meta": {"hexsha": "c596cb3841387728824ce017c9152f370d4e6808", "size": 4277, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/ring_ideals.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/ring_ideals.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/ring_ideals.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.1609195402, "max_line_length": 262, "alphanum_fraction": 0.6270750526, "num_tokens": 1519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673223709251, "lm_q2_score": 0.8840392741081575, "lm_q1q2_score": 0.7186066376150343}}
{"text": "\\section*{Exercises}\n\n\\begin{ex} The following is a Markov (migration) matrix for three locations\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n\\vspace{0.05in}\\frac{7}{10} & \\vspace{0.05in}\\frac{1}{9} & \\vspace{0.05in}\\frac{1}{5} \\\\\n\\vspace{0.05in}\\frac{1}{10} & \\vspace{0.05in}\\frac{7}{9} & \\vspace{0.05in}\\frac{2}{5} \\\\\n\\vspace{0.05in}\\frac{1}{5} & \\vspace{0.05in}\\frac{1}{9} & \\vspace{0.05in}\\frac{2}{5}\n\\end{mymatrix}\n\\end{equation*}\n\\begin{enumerate}\n\\item\nInitially, there are $90$ people in location $1$, $81$ in location $2$, and $85$ in location $3$. How many are in each location after one time period?\n\\item\nThe total number of individuals in the migration process is $256$. After a long time, how many are in each location?\n\\end{enumerate}\n\\begin{sol}\n\\begin{enumerate}\n\\item  Multiply the given matrix by the initial state vector given by\n$\\begin{mymatrix}{r}\n90 \\\\\n81 \\\\\n85\n\\end{mymatrix}$. After one time period there are $89$ people in location $1$, $106$ in location $2$, and $61$ in location $3$.\n\\item  Solve the system given by $(I - A) X_s = 0$ where $A$ is the migration matrix and $X_s = \\begin{mymatrix}{c}\nx_{1s} \\\\\nx_{2s} \\\\\nx_{3s}\n\\end{mymatrix}$ is the steady state vector. The solution to this system is given by\n\\begin{eqnarray*}\nx_{1s} &=& \\frac{8}{5} x_{3s} \\\\\nx_{2s} &=& \\frac{63}{25} x_{3s}\n\\end{eqnarray*}\nLetting $x_{3s} = t$ and using the fact that there are a total of $256$ individuals, we must solve\n\\[\n\\frac{8}{5} t + \\frac{63}{25} t + t = 256\n\\]\nWe find that $t=50$. Therefore after a long time, there are $80$ people in location $1$, $126$ in location $2$, and $50$ in location $3$.\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} The following is a Markov (migration) matrix for three locations\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n\\vspace{0.05in}\\frac{1}{5} & \\vspace{0.05in}\\frac{1}{5} & \\vspace{0.05in}\\frac{2}{5} \\\\\n\\vspace{0.05in}\\frac{2}{5} & \\vspace{0.05in}\\frac{2}{5} & \\vspace{0.05in}\\frac{1}{5} \\\\\n\\vspace{0.05in}\\frac{2}{5} & \\vspace{0.05in}\\frac{2}{5} & \\vspace{0.05in}\\frac{2}{5}\n\\end{mymatrix}\n\\end{equation*}\n\\begin{enumerate}\n\\item Initially, there are $130$ individuals in location $1$, $300$ in location $2$, and $70$ in location $3$. How many are in each location after two time periods?\n\n\\item\nThe total number of individuals in the migration process is $500$. After a\nlong time, how many are in each location?\n\\end{enumerate}\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} The following is a Markov (migration) matrix for three locations\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n\\vspace{0.05in}\\frac{3}{10} & \\vspace{0.05in}\\frac{3}{8} & \\vspace{0.05in}\\frac{1}{3} \\\\\n\\vspace{0.05in}\\frac{1}{10} & \\vspace{0.05in}\\frac{3}{8} & \\vspace{0.05in}\\frac{1}{3} \\\\\n\\vspace{0.05in}\\frac{3}{5} & \\vspace{0.05in}\\frac{1}{4} & \\vspace{0.05in}\\frac{1}{3}\n\\end{mymatrix}\n\\end{equation*}\nThe total number of individuals in the migration process is $480$. After a\nlong time, how many are in each location?\n\\begin{sol}\nWe solve $(I-A)X_s = 0$ to find the steady state vector $X_s = \\begin{mymatrix}{c}\nx_{1s} \\\\\nx_{2s} \\\\\nx_{3s}\n\\end{mymatrix}$.\nThe solution to the system is given by\n\\begin{eqnarray*}\nx_{1s} &=& \\frac{5}{6} x_{3s} \\\\\nx_{2s} &=& \\frac{2}{3} x_{3s}\n\\end{eqnarray*}\nLetting $x_{3s} = t$ and using the fact that there are a total of $480$ individuals, we must solve\n\\[\n\\frac{5}{6} t + \\frac{2}{3} t + t = 480\n\\]\nWe find that $t=192$. Therefore after a long time, there are $160$ people in location $1$, $128$ in location $2$, and $192$ in location $3$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} The following is a Markov (migration) matrix for three locations\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n\\vspace{0.05in}\\frac{3}{10} & \\vspace{0.05in}\\frac{1}{3} & \\vspace{0.05in}\\frac{1}{5} \\\\\n\\vspace{0.05in}\\frac{3}{10} & \\vspace{0.05in}\\frac{1}{3} & \\vspace{0.05in}\\frac{7}{10} \\\\\n\\vspace{0.05in}\\frac{2}{5} & \\vspace{0.05in}\\frac{1}{3} & \\vspace{0.05in}\\frac{1}{10}\n\\end{mymatrix}\n\\end{equation*}\nThe total number of individuals in the migration process is $1155$. After a\nlong time, how many are in each location?\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} The following is a Markov (migration) matrix for three locations\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n\\vspace{0.05in}\\frac{2}{5} & \\vspace{0.05in}\\frac{1}{10} & \\vspace{0.05in}\\frac{1}{8} \\\\\n\\vspace{0.05in}\\frac{3}{10} & \\vspace{0.05in}\\frac{2}{5} & \\vspace{0.05in}\\frac{5}{8} \\\\\n\\vspace{0.05in}\\frac{3}{10} & \\vspace{0.05in}\\frac{1}{2} & \\vspace{0.05in}\\frac{1}{4}\n\\end{mymatrix}\n\\end{equation*}\nThe total number of individuals in the migration process is $704$. After a\nlong time, how many are in each location?\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} A person sets off on a random walk with three possible locations. The Markov matrix of probabilities $A = [a_{ij}]$ is given by\n\\[\n\\begin{mymatrix}{rrr}\n0.1 & 0.3 & 0.7 \\\\\n0.1 & 0.3 & 0.2 \\\\\n0.8 & 0.4 & 0.1\n\\end{mymatrix}\n\\]\nIf the walker starts in location $2$, what is the probability of ending back in location $2$ at time $n = 3$?\n\\begin{sol}\n\\[\nX_{3} = \\begin{mymatrix}{r}\n0.38 \\\\\n0.18 \\\\\n0.44\n\\end{mymatrix}\n\\]\nTherefore the probability of ending up back in location $2$ is $0.18$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} A person sets off on a random walk with three possible locations. The Markov matrix of probabilities $A = [a_{ij}]$ is given by\n\\[\n\\begin{mymatrix}{rrr}\n0.5 & 0.1 & 0.6 \\\\\n0.2 & 0.9 & 0.2 \\\\\n0.3 & 0 & 0.2\n\\end{mymatrix}\n\\]\n\nIt is unknown where the walker starts, but the probability of starting in each location is given by\n\\[\nX_{0}\n= \\begin{mymatrix}{r}\n0.2 \\\\\n0.25 \\\\\n0.55\n\\end{mymatrix}\n\\]\nWhat is the probability of the walker being in location $1$ at time $n = 2$?\n\\begin{sol}\n\\[\nX_{2} = \\begin{mymatrix}{r}\n0.367 \\\\\n0.4625 \\\\\n0.1705\n\\end{mymatrix}\n\\]\nTherefore the probability of ending up in location $1$ is $0.367$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} You own a trailer rental company in a large city and you have four\nlocations, one in the South East, one in the North East, one in the North\nWest, and one in the South West. Denote these locations by SE,NE,NW, and SW\nrespectively. Suppose that the following table is observed to take place.\n\\begin{equation*}\n\\begin{tabular}{lllll}\n& SE & NE & NW & SW \\\\[0.5em]\nSE & $\\frac{1}{3}$ & $\\frac{1}{10}$ & $\\frac{1}{10}$ & $\\frac{1}{5}$ \\\\[0.5em]\nNE & $\\frac{1}{3}$ & $\\frac{7}{10}$ & $\\frac{1}{5}$ & $\\frac{1}{10}$ \\\\[0.5em]\nNW & $\\frac{2}{9}$ & $\\frac{1}{10}$ & $\\frac{3}{5}$ & $\\frac{1}{5}$ \\\\[0.5em]\nSW & $\\frac{1}{9}$ & $\\frac{1}{10}$ & $\\frac{1}{10}$ & $\\frac{1}{2}$ \\\\\n\\end{tabular}\n\\end{equation*}\nIn this table, the probability that a trailer starting at $NE$ ends in $NW$\nis $1/10$, the probability that a trailer starting at $SW$ ends in $NW$ is\n$1/5$, and so forth. Approximately how many will you have in each location\nafter a long time if the total number of trailers is $413$?\n\\begin{sol}\nThe migration matrix is\n\\[\nA =\n\\begin{mymatrix}{rrrr}\n\\vspace{0.05in}\\frac{1}{3} & \\vspace{0.05in}\\frac{1}{10} & \\vspace{0.05in}\\frac{1}{10} &\\vspace{0.05in}\\frac{1}{5} \\\\\n\\vspace{0.05in}\\frac{1}{3} & \\vspace{0.05in}\\frac{7}{10} & \\vspace{0.05in}\\frac{1}{5} &\\vspace{0.05in}\\frac{1}{10} \\\\\n\\vspace{0.05in}\\frac{2}{9} & \\vspace{0.05in}\\frac{1}{10} & \\vspace{0.05in}\\frac{3}{5} &\\vspace{0.05in}\\frac{1}{5} \\\\\n\\vspace{0.05in}\\frac{1}{9} & \\vspace{0.05in}\\frac{1}{10} & \\vspace{0.05in}\\frac{1}{10} &\\vspace{0.05in}\\frac{1}{2}\n\\end{mymatrix}\n\\]\nTo find the number of trailers in each location after a long time we solve system $(I - A)X_s = 0$ for the steady state vector $X_s = \\begin{mymatrix}{c}\nx_{1s} \\\\\nx_{2s} \\\\\nx_{3s} \\\\\nx_{4s}\n\\end{mymatrix}$.\nThe solution to the system is\n\\begin{eqnarray*}\nx_{1s} &=& \\frac{9}{10} x_{4s} \\\\\nx_{2s} &=& \\frac{12}{5} x_{4s} \\\\\nx_{3s} &=& \\frac{8}{5} x_{4s}\n\\end{eqnarray*}\nLetting $x_{4s} = t$ and using the fact that there are a total of $413$ trailers we must solve\n\\[\n\\frac{9}{10} t + \\frac{12}{5} t + \\frac{8}{5}t  + t = 413\n\\]\nWe find that $t=70$. Therefore after a long time, there are $63$ trailers in the SE, $168$ in the NE, $112$ in the NW and $70$ in the SW.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} You own a trailer rental company in a large city and you have four\nlocations, one in the South East, one in the North East, one in the North\nWest, and one in the South West. Denote these locations by SE,NE,NW, and SW\nrespectively. Suppose that the following table is observed to take place.\n\\begin{equation*}\n\\begin{tabular}{lllll}\n& SE & NE & NW & SW \\\\[0.5em]\nSE & $\\frac{1}{7}$ & $\\frac{1}{4}$ & $\\frac{1}{10}$ & $\\frac{1}{5}$ \\\\[0.5em]\nNE & $\\frac{2}{7}$ & $\\frac{1}{4}$ & $\\frac{1}{5}$ & $\\frac{1}{10}$ \\\\[0.5em]\nNW & $\\frac{1}{7}$ & $\\frac{1}{4}$ & $\\frac{3}{5}$ & $\\frac{1}{5}$ \\\\[0.5em]\nSW & $\\frac{3}{7}$ & $\\frac{1}{4}$ & $\\frac{1}{10}$ & $\\frac{1}{2}$ \\\\\n\\end{tabular}\n\\end{equation*}\nIn this table, the probability that a trailer starting at $NE$ ends in $NW$\nis $1/10$, the probability that a trailer starting at $SW$ ends in $NW$ is\n$1/5$, and so forth. Approximately how many will you have in each location\nafter a long time if the total number of trailers is $1469$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} The following table describes the transition probabilities between the\nstates rainy, partly cloudy and sunny. The symbol p.c. indicates partly\ncloudy. Thus if it starts off p.c. it ends up sunny the next day with\nprobability $\\frac{1}{5}$. If it starts off sunny, it ends up sunny the next\nday with probability $\\frac{2}{5}$ and so forth.\n\\begin{equation*}\n\\begin{array}{cccc}\n& \\text{rains} & \\text{sunny} & \\text{p.c.} \\\\\n\\text{rains} & \\vspace{0.05in}\\frac{1}{5} & \\vspace{0.05in}\\frac{1}{5} & \\vspace{0.05in}\\frac{1}{3} \\\\\n\\text{sunny} & \\vspace{0.05in}\\frac{1}{5} & \\vspace{0.05in}\\frac{2}{5} & \\vspace{0.05in}\\frac{1}{3} \\\\\n\\text{p.c.} & \\vspace{0.05in}\\frac{3}{5} & \\vspace{0.05in}\\frac{2}{5} & \\vspace{0.05in}\\frac{1}{3}\n\\end{array}\n\\end{equation*}\nGiven this information, what are the probabilities that a given day is\nrainy, sunny, or partly cloudy? \\vspace{1mm}\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} The following table describes the transition probabilities between the\nstates rainy, partly cloudy and sunny. The symbol p.c. indicates partly\ncloudy. Thus if it starts off p.c. it ends up sunny the next day with\nprobability $\\frac{1}{10}$. If it starts off sunny, it ends up sunny the\nnext day with probability $\\frac{2}{5}$ and so forth.\n\\begin{equation*}\n\\begin{array}{cccc}\n& \\text{rains} & \\text{sunny} & \\text{p.c.} \\\\\n\\text{rains} & \\vspace{0.05in}\\frac{1}{5} & \\vspace{0.05in}\\frac{1}{5} & \\vspace{0.05in}\\frac{1}{3} \\\\\n\\text{sunny} & \\vspace{0.05in}\\frac{1}{10} & \\vspace{0.05in}\\frac{2}{5} & \\vspace{0.05in}\\frac{4}{9} \\\\\n\\text{p.c.} & \\vspace{0.05in}\\frac{7}{10} & \\vspace{0.05in}\\frac{2}{5} & \\vspace{0.05in}\\frac{2}{9}\n\\end{array}\n\\end{equation*}\nGiven this information, what are the probabilities that a given day is\nrainy, sunny, or partly cloudy?\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} You own a trailer rental company in a large city and you have four\nlocations, one in the South East, one in the North East, one in the North\nWest, and one in the South West. Denote these locations by SE,NE,NW, and SW\nrespectively. Suppose that the following table is observed to take place.\n\\begin{equation*}\n\\begin{tabular}{lllll}\n& SE & NE & NW & SW \\\\[0.5em]\nSE & $\\frac{5}{11}$ & $\\frac{1}{10}$ & $\\frac{1}{10}$ & $\\frac{1}{5}$ \\\\[0.5em]\nNE & $\\frac{1}{11}$ & $\\frac{7}{10}$ & $\\frac{1}{5}$ & $\\frac{1}{10}$ \\\\[0.5em]\nNW & $\\frac{2}{11}$ & $\\frac{1}{10}$ & $\\frac{3}{5}$ & $\\frac{1}{5}$ \\\\[0.5em]\nSW & $\\frac{3}{11}$ & $\\frac{1}{10}$ & $\\frac{1}{10}$ & $\\frac{1}{2}$ \\\\\n\\end{tabular}\n\\end{equation*}\nIn this table, the probability that a trailer starting at $NE$ ends in $NW$\nis $1/10$, the probability that a trailer starting at $SW$ ends in $NW$ is\n$1/5$, and so forth. Approximately how many will you have in each location\nafter a long time if the total number of trailers is $407$?\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} The University of Poohbah offers three degree programs, scouting\neducation (SE), dance appreciation (DA), and engineering (E). It has been\ndetermined that the probabilities of transferring from one program to\nanother are as in the following table.\n\\begin{equation*}\n\\begin{tabular}{l|l|l|l|}\n\\cline{2-4}\n& SE & DA & E \\\\ \\hline\n\\multicolumn{1}{|l|}{SE} & 0.8 & 0.1 & 0.3 \\\\ \\hline\n\\multicolumn{1}{|l|}{DA} & 0.1 & 0.7 & 0.5 \\\\ \\hline\n\\multicolumn{1}{|l|}{E} & 0.1 & 0.2 & 0.2 \\\\ \\hline\n\\end{tabular}\n\\end{equation*}\nwhere the number indicates the probability of transferring from the top\nprogram to the program on the left. Thus the probability of going from DA to\nE is $0.2$. Find the probability that a student is enrolled in the various\nprograms.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} In the city of Nabal, there are three political persuasions,\nrepublicans (R), democrats (D), and neither one (N). The following table\nshows the transition probabilities between the political parties, the top\nrow being the initial political party and the side row being the political\naffiliation the following year.%\n\\begin{equation*}\n\\begin{array}{cccc}\n& \\text{R} & \\text{D} & \\text{N} \\\\\n\\text{R} & \\vspace{0.05in}\\frac{1}{5} & \\vspace{0.05in}\\frac{1}{6} & \\vspace{0.05in}\\frac{2}{7} \\\\\n\\text{D} & \\vspace{0.05in}\\frac{1}{5} & \\vspace{0.05in}\\frac{1}{3} & \\vspace{0.05in}\\frac{4}{7} \\\\\n\\text{N} & \\vspace{0.05in}\\frac{3}{5} & \\vspace{0.05in}\\frac{1}{2} & \\vspace{0.05in}\\frac{1}{7}\n\\end{array}\n\\end{equation*}\nFind the probabilities that a person will be identified with the various\npolitical persuasions. Which party will end up being most important?\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} The following table describes the transition probabilities between the\nstates rainy, partly cloudy and sunny. The symbol p.c. indicates partly\ncloudy. Thus if it starts off p.c. it ends up sunny the next day with\nprobability $\\frac{1}{5}$. If it starts off sunny, it ends up sunny the next\nday with probability $\\frac{2}{7}$ and so forth.\n\\begin{equation*}\n\\begin{array}{cccc}\n& \\text{rains} & \\text{sunny} & \\text{p.c.} \\\\\n\\text{rains} & \\vspace{0.05in}\\frac{1}{5} & \\vspace{0.05in}\\frac{2}{7} & \\vspace{0.05in}\\frac{5}{9} \\\\\n\\text{sunny} & \\vspace{0.05in}\\frac{1}{5} & \\vspace{0.05in}\\frac{2}{7} & \\vspace{0.05in}\\frac{1}{3} \\\\\n\\text{p.c.} & \\vspace{0.05in}\\frac{3}{5} & \\vspace{0.05in}\\frac{3}{7} & \\vspace{0.05in}\\frac{1}{9}\n\\end{array}\n\\end{equation*}\nGiven this information, what are the probabilities that a given day is\nrainy, sunny, or partly cloudy?\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "433c1c2d3464dc813c61d5af01f9097304b990cd", "size": 14553, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/exercises/SpectralTheory-Applications-Markov.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/exercises/SpectralTheory-Applications-Markov.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/exercises/SpectralTheory-Applications-Markov.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 40.6508379888, "max_line_length": 164, "alphanum_fraction": 0.6615818044, "num_tokens": 5518, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199673867852, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7184836966955421}}
{"text": "\\section{Fold}\n\nIn the general case, functions of two parameters are \\textbf{not associative}, so the order in which one carries out the \\textbf{combination of the elements matters}. On lists, there are two obvious ways to carry this out: either by recursively combining the first element with the results of combining the rest (called a right fold) or by recursively combining the results of combining all but the last element with the last one, (called a left fold). \n\n\\begin{lstlisting}[language=Haskell]\n-- f :: a -> a -> a -> a\n-- [a1, a2, a3, a4]\n-- Right fold: f a1 (f a2 (f a3 a4))\n-- Left fold: f (f (f a1 a2) a3) a4\n\\end{lstlisting}\n\nAlso, in practice, it is convenient and natural to have an initial value which in the case of a right fold, is used when one reaches the end of the list, and in the case of a left fold, is what is initially combined with the first element of the list.\n\n\\subsection{What fold does to lists}\nOne can view a fold on lists as replacing the nil at the end of the list with a specific value, and replacing each cons with a specific function. These replacements can be viewed as a diagram: \n\n\\begin{center}\n  \\textbf{Foldr} \\\\\n  \\includegraphics[width=0.6\\textwidth]{figures/foldr-overview.png}\n\\end{center}\n\n\\begin{center}\n  \\textbf{Foldl} \\\\\n  \\includegraphics[width=0.7\\textwidth]{figures/foldl.png}\n\\end{center}\n\nThey also highlight the fact that foldr (:) [] is the identity function on lists (a shallow copy in Lisp parlance), as replacing cons with cons and nil with nil will not change the result. The left fold diagram suggests an easy way to reverse a list, foldl (flip (:)) []\n\n\\clearpage\n\\subsection{Linear Foldr}\n\\begin{lstlisting}[language=Haskell]\n-- if the list is empty, the result is the initial value z; else\n-- apply f to the first element and the result of folding the rest\n\nfoldr' :: (a -> b -> b) -> b -> [a] -> b\nfoldr' f z []     = z \nfoldr' f z (x:xs) = f x (foldr' f z xs) \n\n-- foldr' f id [a1, a2, a3, a4]\n-- f a1 (foldr' f id [a2, a3, a4])\n-- f a1 (f a2 (foldr' f id [a3, a4]))\n-- f a1 (f a2 (f a3 (foldr' f id [a4])))\n-- f a1 (f a2 (f a3 (f a4 (foldr' f id [])))\n-- f a1 (f a2 (f a3 (f a4 id))\n\\end{lstlisting}\n\n\\subsection{Linear Foldl}\n\nAgain, the first argument to foldl should be a function that is all about taking a default value, the first element of the list, and then returning a new default for the process to continue with a shortened list.\n\n\\begin{lstlisting}[language=Haskell]\n-- if the list is empty, the result is the initial value; else\n-- we recurse immediately, making the new initial value the result\n-- of combining the old initial value with the first element.\n\nfoldl' :: (b -> a -> b) -> b -> [a] -> b\nfoldl' f z []     = z                  \nfoldl' f z (x:xs) = foldl' f (f z x) xs\n\n-- foldl' f id [a1, a2, a3, a4]\n-- foldl' f (f id a1) [a2, a3, a4]\n-- foldl' f (f (f id a1) a2) [a3, a4]\n-- foldl' f (f (f (f id a1) a2) a3) [a4]\n-- foldl' f (f (f (f (f id a1) a2) a3) a4) []\n-- foldl' f (f (f (f (f id a1) a2) a3) a4)\n-- f (f (f (f (f id a1) a2) a3) a4)\n\\end{lstlisting}\n\n\\subsection{Difference between reduction and fold}\nFold takes an explicit initial value for the accumulator while reduce uses the first element of the input list as the initial accumulator value.\n\n\\subsection{Tree-like folds}\n\\begin{lstlisting}[language=Haskell]\nfoldt            :: (a -> a -> a) -> a -> [a] -> a\nfoldt f z []     = z\nfoldt f z [x]    = x                             -- aka foldt' of data-ordlist\nfoldt f z xs     = foldt f z (pairs f xs)\n \nfoldi            :: (a -> a -> a) -> a -> [a] -> a\nfoldi f z []     = z\nfoldi f z (x:xs) = f x (foldi f z (pairs f xs))  -- aka foldt of data-ordlist\n \npairs            :: (a -> a -> a) -> [a] -> [a]\npairs f (x:y:t)  = f x y : pairs f t\npairs f t        = t\n\\end{lstlisting}\n\n\\clearpage", "meta": {"hexsha": "ddd05995995be26332af828136d0422d36aa7930", "size": 3805, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TSM_AdvPrPa/Fold/01_Fold.tex", "max_stars_repo_name": "nortismo/mse-documentations", "max_stars_repo_head_hexsha": "cc67637785237d630f077a863edcd5f49aa52b59", "max_stars_repo_licenses": ["Beerware"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "TSM_AdvPrPa/Fold/01_Fold.tex", "max_issues_repo_name": "nortismo/mse-documentations", "max_issues_repo_head_hexsha": "cc67637785237d630f077a863edcd5f49aa52b59", "max_issues_repo_licenses": ["Beerware"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TSM_AdvPrPa/Fold/01_Fold.tex", "max_forks_repo_name": "nortismo/mse-documentations", "max_forks_repo_head_hexsha": "cc67637785237d630f077a863edcd5f49aa52b59", "max_forks_repo_licenses": ["Beerware"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-15T07:10:24.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-15T07:10:24.000Z", "avg_line_length": 43.2386363636, "max_line_length": 453, "alphanum_fraction": 0.653088042, "num_tokens": 1221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199673867852, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7184836875589281}}
{"text": "\\section{Fixed Point [25 pts]}\n\nIn this exercise we will use  \\href{https://en.wikipedia.org/wiki/Cauchy_sequence}{Cauchy sequences}  to prove that value iteration will converge to a unique fixed point (in this case, a value function $V$) regardless of the starting point. An element $V$ is a fixed point for an operator $B$ (in this case the Bellman operator) if performance of $B$ on $V$ returns $V$, i.e., $BV = V$. Recall that the Bellman backup operator $B$ is defined as (in lecture 2):\n\\begin{equation}\n    V_{k+1} \\overset{def}{=} BV_{k} = \\max_a[ R(s, a) + \\gamma\\sum_{s' \\in S}p(s'|s,a)V^\\pi_{k}(s')].\n\\end{equation}\n\nAdditionally, in lecture 2, we proved that this Bellman backup is a contraction for $\\gamma < 1$ on the infinity norm\n\\begin{equation}\n    \\|BV' - BV''\\|_\\infty\\leq \\gamma \\|V' - V''\\|_\\infty\n\\end{equation}\nfor any two value functions $V'$ and $V''$, meaning if we apply it to two different value functions, the distance between value functions (in the $\\infty$ norm) shrinks after application of the operator to each element.\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item (5pts) Prove by induction that $\\|V_{n+1} - V_{n}\\|_\\infty \\leq \\gamma^n \\|V_1 - V_0\\|_\\infty$\n\n\\textbf{Answer:}\n\\begin{equation}\n\\begin{aligned}\n& n = 1: \\\\\n& \\|V_2 - V_1\\|_\\infty = \\|BV_1 - BV_0\\|_\\infty\\leq \\gamma^1\n\\|V_1 - V_0\\|_\\infty \\\\\n& n = 2: \\\\\n& \\|V_3 - V_2\\|_\\infty = \\|BV_2 - BV_1\\|_\\infty\\leq \\gamma^1 \\|V_2 - V_1\\|_\\infty \\leq \\gamma^1 \\|V_1 - V_0\\|_\\infty \\\\\n& n = k, \\text{assume:} \\\\\n& \\|V_{k+1} - V_k\\|_\\infty \\leq \\gamma^1 \\|V_1 - V_0\\|_\\infty \\\\\n& \\|V_{k+2} - V_{k+1}\\|_\\infty = \\|BV_{k+1} - BV_k\\|_\\infty \\\\\n& \\leq \\gamma^1\\|V_{k+1} - V_k\\|_\\infty \\leq \\gamma^1 \\gamma^k \\|V_1 - V_0\\|_\\infty = \\gamma^{k+1} \\|V_1 - V_0\\|_\\infty \\\\\n& 0 < \\gamma < 1, \\text{by induction: } \\|V_{n+1} - V_{n}\\|_\\infty \\leq \\gamma \\|V' - V''\\|_\\infty\n\\end{aligned}\n\\end{equation}\n\n\n\\item (10pts) Prove that for any $c>0$, $\\|V_{n+c} - V_n\\|_\\infty \\leq \\frac{\\gamma^n}{1-\\gamma}\\|V_1 - V_0\\|_\\infty$\n\\end{enumerate}\n\n\\textbf{Answer:}\n\\begin{equation}\n\\begin{aligned}\n\\text{consider } c > 1: &\\\\\n\\|V_{n+c} - V_n\\|_\\infty & = \\|V_{n+c} - V_{n+1} + V_{n+1} - V_n\\|_\\infty \\leq  \\|V_{n+c} - V_{n+1}\\|_\\infty + \\|V_{n+1} - V_n\\|_\\infty \\\\\n\\|V_{n+c} - V_n\\|_\\infty  & \\leq \\sum_{k=n}^{n+c}  \\|V_{k+1} - V_k\\|_\\infty \\\\\n                          & = \\sum_{k=n}^{n+c} \\gamma^k \\|V_{1} - V_0\\|_\\infty \\\\\n                          & = \\frac{\\gamma^n - \\gamma^{n+c}}{1-\\gamma}\\|V_{1} - V_0\\|_\\infty \\\\\n                          & \\leq \\frac{\\gamma^n}{1-\\gamma}\\|V_{1} - V_0\\|_\\infty\n\\end{aligned}\n\\end{equation}\n\nA \\emph{Cauchy sequence} is a sequence whose elements become arbitrarily close to each other as the sequence progresses. Formally a sequence $\\{a_n\\}$ in metric space $X$ with distance metric $d$ is a Cauchy sequence if given an $\\epsilon > 0$ there exists k such that if m, n > k then $d(a_m, a_n) < \\epsilon$. Real Cauchy sequences are convergent.\n\\begin{enumerate}[label=(\\alph*)]\n\\setcounter{enumi}{2}\n\\item (2pts) Using this information about Cauchy sequences, argue that the sequence $V_0, V_1, ...$ is a Cauchy sequence and is therefore convergent and must converge to some element $V$ and this V is a fixed point\n\n\\textbf{Answer:}\n\\begin{equation}\n\\text{let } k < n, m = n + c, \\epsilon = \\frac{\\gamma^k}{1-\\gamma}\\|V_{1} - V_0\\|_\\infty:\n\\end{equation}\n\\begin{equation}\n\\begin{aligned}\n\\|V_{m} - V_n\\|_\\infty  & \\leq \\frac{\\gamma^n}{1-\\gamma}\\|V_{1} - V_0\\|_\\infty \\\\\n                          & < \\frac{\\gamma^k}{1-\\gamma}\\|V_{1} - V_0\\|_\\infty \\\\\n                          & = \\epsilon\n\\end{aligned}\n\\end{equation}\n\n\\item (8pts) Show that this fixed point is unique.\n\n\\end{enumerate}\n\nAssume there are two fixed points $V$ and $V'$\n\nAt those points, because of convergence: $BV = V$\n\n$\\|V - V'\\|_\\infty = \\|BV - BV'\\|_\\infty \\leq \\gamma \\|V - V'\\|_\\infty$\n\nBecause $ 0 < \\gamma < 1$, so $\\|V - V'\\| = 0$\n\nContraditon, there is only one fix point.\n", "meta": {"hexsha": "c715ccf4efa59c4c09f8e5b4c0e93131e020a997", "size": 3956, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment1_written/tex/Q_fixedpoint.tex", "max_stars_repo_name": "ksang/cs234-assignments", "max_stars_repo_head_hexsha": "dc9a2238c7e28db7ae5eaebde6d776a2e5a59ebc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-12-25T12:29:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T12:53:13.000Z", "max_issues_repo_path": "assignment1_written/tex/Q_fixedpoint.tex", "max_issues_repo_name": "ksang/cs234-assignments", "max_issues_repo_head_hexsha": "dc9a2238c7e28db7ae5eaebde6d776a2e5a59ebc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-11-13T17:43:49.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T02:04:12.000Z", "max_forks_repo_path": "assignment1_written/tex/Q_fixedpoint.tex", "max_forks_repo_name": "ksang/cs234-assignments", "max_forks_repo_head_hexsha": "dc9a2238c7e28db7ae5eaebde6d776a2e5a59ebc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-02T01:34:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-02T01:34:47.000Z", "avg_line_length": 50.0759493671, "max_line_length": 460, "alphanum_fraction": 0.6134984833, "num_tokens": 1531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.8918110504699677, "lm_q1q2_score": 0.7184716970714484}}
{"text": "\\documentclass[en,12pt]{elegantpaper}\n\n\\begin{document}\n    \\section*{4}\n    \\noindent For Gamma distribution, \n    \\[\n        f(\\mathbf{x}|\\alpha_0, \\lambda)=\\frac{\\prod{x_i}^{\\alpha_0-1}}{\\Gamma^n(\\alpha_0)}\\exp\\left(-\\lambda\\sum^n x_i+n\\alpha_0\\log(\\lambda)\\right). \n    \\]\n    So, $T(X)=\\bar{X}$ is a sufficient and complete statistics for $\\lambda$. Next, we need to prove that $X_1/\\bar{X}$ is an ancillary statistics. \n\n    Let $Z\\sim\\Gamma(\\alpha_0, 1)$, then \n    \\[\n        X\\sim\\lambda^{\\alpha_0}e^{-\\lambda}Z, \\quad \\bar{X}\\sim \\lambda^{\\alpha_0}e^{-\\lambda}\\bar{Z}. \n    \\]\n    So, \n    \\[\n        \\frac{X_1}{\\bar{X}}\\sim\\frac{\\lambda^{\\alpha_0}e^{-\\lambda}Z_1}{\\lambda^{\\alpha_0}e^{-\\lambda}\\bar{Z}}=\\frac{Z_1}{\\bar{Z}}. \n    \\]\n    This ratio is independent on $\\lambda$, i.e., it is an ancillary statistics. So, from \\emph{Basu theorem}, $X_1/\\bar{X}$ is independent with $\\bar{X}$. \n\\end{document}", "meta": {"hexsha": "363cbdc415c6c44f40c998c619d5a9a130f84195", "size": 914, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Statistics/midterm1/4.tex", "max_stars_repo_name": "Addasecond86/MS-Stat-Tulane", "max_stars_repo_head_hexsha": "3af55f890c0dedfed7a4614665730002b4c3a370", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Mathematical Statistics/midterm1/4.tex", "max_issues_repo_name": "Addasecond86/MS-Stat-Tulane", "max_issues_repo_head_hexsha": "3af55f890c0dedfed7a4614665730002b4c3a370", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mathematical Statistics/midterm1/4.tex", "max_forks_repo_name": "Addasecond86/MS-Stat-Tulane", "max_forks_repo_head_hexsha": "3af55f890c0dedfed7a4614665730002b4c3a370", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.7, "max_line_length": 156, "alphanum_fraction": 0.6083150985, "num_tokens": 347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7184716872460178}}
{"text": "%intro\n\n\\section{Prerequisits}\n\nFollowing the standard notation from Bourbaki, we will denote for a given set $X$ the power set $\\calp(X) = 2^X = \\{A : A \\subset X\\}$.\n\\begin{defi}\nA universe $\\calu$ is a set satisfying the following properties:\n\\begin{enumerate}\n\\item $\\emptyset \\in \\calu$,\n\\item $U \\in \\calu$ implies $U \\subset \\calu$,\n\\item $U \\in \\calu$ implies $\\{U\\} \\in \\calu$,\n\\item $U \\in \\calu$ implies $\\calp(U) \\in \\calu$,\n\\item if $I \\in \\calu$ and $U_i \\in \\calu$ for $i \\in I$ then\n$$\\bigcup_{i \\in I} U_i \\in \\calu,$$\n\\item $\\nz \\in \\calu$.\n\\end{enumerate}\nWe call a set $U$ a $\\calu$-set if $U \\in \\calu$. We call a set $U$ $\\calu$-small if it is isomorphic to a set in $\\calu$.\n\\end{defi}\nFollowing Grothendieck we shall add to the axiom system of Zermelo-Fraenkel the axiom demanding for any set $X$ there is a universe $\\calu$ containing $X$.\n\\begin{defi}\nAn order on a set $I$ is a relation $\\leq$ which is reflexive, antisymmetric and transitive. We call an order directed or filtrant if $I$ is non empty and if for any pair $i, j \\in I$ there is $k \\in I$ such that $i \\leq k$ and $j \\leq k$. We call an order total if for all $i, j \\in I$ we have either $i \\leq j$ or $j \\leq i$ (or both). An ordered set $I$ is inductively ordered if any totally ordered subset $I' \\subset I$ has an upper bound. \n\\end{defi}\nWe remark that following the axiom of choice any inductively ordered set as an maximal element (Zorn's lemma).\n\n\\subsection{Categories and functors}\n\\begin{defi}\nA category $\\calc$ consists of the following data:\n\\begin{enumerate}\n\\item the class of objects $\\objc$,\n\\item the class of morphisms $\\morc$ which consists for all $X, Y \\in \\mrm{Ob}(\\calc)$ of the classes of morphisms $\\homc{X,Y}$ and \n\\item the composition law of morphisms: for any triple $X, Y, Z$ of objects in $\\calc$ and morphisms $f \\in \\homc{X,Y}$ and $g \\in \\homc{Y,Z}$ we get a morphism $h = g \\circ f \\in \\homc{X,Z}$.\n\\end{enumerate}\nFor each object $X \\in \\objc$ there is a morphism $e \\in \\homc{X,X}$ such that $f \\circ e = f$ and $e \\circ g = g$ for all $f \\in \\homc{X,Y}$ and $g \\in \\homc{Y,X}$.\n\\end{defi}\nWe remark that the composition is associative and the latter morphism is simply the identity map. We call a category $\\calc$ $\\calu$-category if for all $X, Y \\in \\objc$ the class $\\homc{X,Y}$ is $\\calu$-small. A $\\calu$-small category is a $\\calu$-category $\\calc$ such that $\\objc$ is $\\calu$-small.\n\\begin{defi}\nGiven a category $\\calc$ we define the opposite category $\\calc^{\\mrm{op}}$ to be:\n$\\obj{\\calc^{\\mrm{op}}} = \\objc$ and $\\homo{\\calc^{\\mrm{op}}}{X,Y} = \\homc{Y,X}$ for all $X, Y \\in \\objc$.\nThe composition is simply inverted: for $f \\in \\homo{\\calc^{\\mrm{op}}}{X,Y}$ and $g \\in \\homo{\\calc^{\\mrm{op}}}{Y,Z}$ we get:\n$$g \\circ^{\\mrm{op}} f = f \\circ g.$$\n\\end{defi}\nA morphism $f : X \\longrightarrow Y$ in $\\calc$ is called an isomorphism if there exists a morphism $g : Y \\longrightarrow X$ in $\\calc$ such that\n$$ f \\circ g = id_Y  \\ \\mrm{and}\\ g \\circ f = id_X.$$\nAn endomorphism is a morphism with target object $Y = X$ - an automorphism is and endomorphism and isomorphism. Two morphism $f, g$ are parallel if they have the same source and targets:\n$$f, g : X\\  \\substack{\\longrightarrow\\\\\\longrightarrow}\\ Y.$$\nA morphism $f : X \\longrightarrow Y$ is a monomorphism if for any parallel morphisms $g_1 , g_2 : Z\\  \\substack{\\longrightarrow\\\\\\longrightarrow}\\ X$ we have\n$$g_1 \\circ f = g_2 \\circ f\\ \\Rightarrow\\ g_1 = g_2.$$\nA morphism $f : X \\longrightarrow Y$ is an epimorphism if $f^{\\mrm{op}}$ is a monomorphism.\nWe call a category $\\calc'$ a subcategory of $\\calc$ if $\\obj{\\calc'} \\subset \\objc$ and $\\homo{\\calc'}{X,Y} \\subset \\homc{X,Y}$ for all $X, Y \\in \\obj{\\calc'}$. We call a subcategory $\\calc'$ of $\\calc$ full if $\\homo{\\calc'}{X,Y} = \\homc{X,Y}$. A full subcategory $\\calc'$ of $\\calc$ is saturated if $X \\in \\calc$ belongs to $\\calc'$ whenever $X$ is isomorphic to an object in $\\calc'$. A category is discrete if all morphism are identity morphisms. A category $\\calc$ is non empty if $\\objc$ is non empty. A category is a groupoid if all morphisms are isomorphisms. A category $\\calc$ is finite if $\\morc$ is finite as a set. A category is connected if its non empty and for any pair objects $X, Y \\in \\calc$ there is a finite sequence of objects $X = X_0, \\ldots, X_i = Y$ such that at least one of the sets $\\homc{X_j,X_{j+1}}$ or $\\homc{X_{j+1},X_j}$ is non empty for all $0 \\leq j \\leq i - 1$.\\\\\n\\indent A diagram in a category $\\calc$ is a family of symbols representing objects in $\\calc$ and arrows betweens these representing morphisms of these objects. The definition of a commutative diagrams follows in an obvious fashion.\n\\bsp \n\\begin{enumerate}\n\\item $\\mrm{Set}$ is the category of $\\calu$-sets and maps, $\\mrm{Set}^f$ the full subcategory of finite $\\calu$-sets.\n\\item The category $\\mrm{Rel}$ of binary relations is defined to be:\n$\\obj{\\mrm{Rel}} = \\obj{\\mrm{Set}}$ and $\\homo{\\mrm{Rel}}{X,Y} = \\power{X \\times Y}$, the set of subsets of $X \\times Y$. The composition law is defined as follows: if $f : X \\longrightarrow Y$ and $g : Y \\longrightarrow Z$ then $g \\circ f$ is\n$$\\{(x,z) \\in X \\times Z : \\exists y \\in Y,\\ (x,y) \\in f \\wedge (y,z) \\in g\\}.$$\nThe identity morphism is the diagonal map $\\Delta : X \\longrightarrow X \\times X$.\n\\item  Let $R$ be a unital ring (not necessarily commutative, $R \\in \\calu$). The category of $R$ left modules belonging to $\\calu$  is denoted $\\mrm{Mod}(R)$. The category of $R$ right modules is simply the $R^{\\mrm{op}}$ left modules where $R^{\\mrm{op}}$ is the opposite ring (with multiplication flipped). Its class of morphisms is\n$$\\homo{\\mrm{Mod}(R)}{\\;\\cdot,\\;\\cdot} = \\homo{R}{\\;\\cdot,\\;\\cdot}.$$\nWe denote with $\\mrm{End}_R(M)$ the ring of $R$ endomorphisms on $M$ and $\\mrm{Aut}_R(M)$ the group of automorphisms on $M$. We denote by $\\mrm{Mod}^{\\mrm{f}}$ the category of finitely generated modules over $R$ (recall: finitely generated iff there is a surjective $R$ linear map $u : R^\\oplus \\longrightarrow M$ for some $n \\geq 1$). They are also called modules of finite type.\\\\\n\\indent We denote by $\\mrm{Mod}^{\\mrm{fp}}$ the category of finitely presented $R$ modules. Recall a module is finitely presented if it is of finite type and $\\ker u$, as defined above, is also of finite type.\n\\item Let $(I,\\leq)$ be an ordered set. We associate to it a category $\\call{I}$ as follows:\n$$\\begin{array}{rcl}\n\\obj{\\call{I}} &=& I\\\\\n&&\\\\\n\\homo{\\call{I}}{i,j} &=& \\begin{cases}\n\\ast,& i \\leq j\\\\\n\\emptyset, & \\mrm{else}\\\\\n\\end{cases}\\\\\n\\end{array}$$\nwhere $\\ast$ stands for some pointed space. Thus, the set of morphisms is either single-pointed or empty.\n\\item We call a category of boolean type or a boolean category if there three maps\n$$\\begin{array}{rrcl}\na : & B \\times B & \\longrightarrow& B\\\\\n&&&\\\\\no : & B \\times B & \\longrightarrow& B\\\\\n&&&\\\\\nn : & B &\\longrightarrow& B\\\\\n\\end{array}$$\nsuch that the following diagrams commute:\n$$\\begin{array}{cc}\n\\xymatrix{\nB \\ar[rd]_{id_B}\\ar[r]^n&B\\ar[d]^n\\\\\n&B\\\\\n} &\n\\xymatrix{\nB \\ar[d]_n & B \\times B \\ar[l]_a \\ar[r]^o \\ar[d]_{n \\times n} & B\\ar[d]^n\\\\\nB & B \\times B \\ar[l]^o \\ar[r]_a &B\\\\\n}\\\\\n\\end{array}$$\nIts morphisms are simply the maps preserving the each of the three maps.\n\\end{enumerate}\n\\subsubsection{Topological spaces as category}\n\n\\subsection{Functors}\n\n\\subsection{Yoneda functors and Yoneda lemma}\nGiven a universe $\\calu$ and a $\\calu$-category $\\calc_\\calu$ we define two functors:\n$$\\begin{array}{rrcl}\n\\hat{h} : &\\calc_\\calu &\\longrightarrow& \\hat{\\calc}_\\calu\\\\\n&&&\\\\\n&C& \\longmapsto& \\homo{\\calc_{\\calu}}{\\;\\cdot\\;,C}\\\\\n&&&\\\\\n\\hat{k} :&\\calc &\\longrightarrow& \\check{\\calc}_\\calu\\\\\n&&&\\\\\n&C&\\longmapsto&\\homo{\\calc_{\\calu}}{C,\\;\\cdot\\;}\\\\\n\\end{array}$$\n\n\n\n\\subsection{Group objects}\nGiven a category $\\calc$ with initial object $\\ast$ and finite products we call an object $G \\in \\calc$ a group object (in $\\calc$) %there are morphisms $e \\in \\homo{\\calc}{\\ast,G}$, $m \\in \\homo{\\calc}{G \\times G, G}$ and $S : G \\longrightarrow G$ if and only if $\\mrm{im} m \\supset G$ and the following diagrams commute:\nif there is a functor $\\overline{G} : \\calc^{\\mrm{op}} \\longrightarrow \\mrm{Grp}$ such that $G$ represents the composition functor $\\mrm{For} \\circ \\overline{G}$ given in the following diagram:\n$$\\xymatrix{ \\calc^{\\mrm{op}} \\ar[r]^{\\overline{G}} \\ar[rd]_{\\mrm{For}\\;\\circ\\;\\overline{G}}& \\mrm{Grp}\\ar[d]^{\\mrm{For}}\\\\\n&\\mrm{Set}.\\\\\n}$$\nHere, $\\mrm{For}$ is simply the forgetful functor:\n$$\\mrm{Grp} \\longrightarrow \\mrm{Set}.$$\nFurthermore, representation means that $\\overline{G} \\simeq h_{\\calc}(G) = \\homo{\\calc}{\\;\\cdot\\;,G}$. Therefore, we may identify $G$ and $\\overline{G}$ ($G$ thought of as a functor). Furthermore, there is a functorial isomorphism:\n$$G(X) \\times G(X) \\simeq (G \\times G)(X)$$\nmaking $m : G \\times G \\longrightarrow G$ a morphism in $\\hat{\\calc}$.\nwe get functors% $m : \\hat{\\calc} \\times \\hat{\\calc} \\longrightarrow \\hat{\\calc}$, $e : \\hat{h}\n\\begin{description}\n\\item[Unity:]\n$$\\xymatrix{\n\\ast \\times G \\ar[rd]_\\simeq \\ar[r]^{e \\times id_G}& G\\times G \\ar[d]^m&G\\times \\ast\\ar[l]_{id_G \\times e}\\ar[ld]^\\simeq\\\\\n&G&\\\\\n}$$\n\\item[Associativity]\n$$\\xymatrix{\nG \\times G \\times G \\ar[rr]^{m \\times id_G}\\ar[d]_{id_G\\times m} && G\\times G \\ar[d]^m\\\\\nG \\times G \\ar[rr]_m &&G\\\\\n}$$\n\\end{description}\n\\subsubsection{Functors and schemes}\nTwo prominent examples of functors are the following:\n\\paragraph{Additive group scheme}\n\n\\paragraph{Multiplicative group scheme}\nGiven a commutative ring $R$ with unit, we define the following functor:\n$$\\mathbb{G}_m : \\mrm{CURng} \\longrightarrow \\mrm{Grp},\\ R \\longmapsto \\mrm{Gl}_1(R).$$\nIn this case the base scheme is simply the spectrum of $R$ and its affine scheme is:\n$$\\mrm{Spec} \\left(R\\left[x,x^{-1}\\right]\\right)$$\nas follows: the ring of Laurent polynomials $R[x,x^{-1}]$ over $R$ has the comultiplication\n$$\\Delta : R[x,x^{-1}] \\longrightarrow R[x,x^{-1}]^{\\otimes 2},\\ x \\longmapsto x \\otimes x,$$\nand counit\n$$\\varepsilon : R[x,x^{-1}] \\longrightarrow R,\\ x \\longmapsto 1.$$\nNow, we take the dualisation via the spectrum functor as follows:\n\\begin{enumerate}\n\\item we pick a minimial prime ideal $\\mathfrak{p}$ over zero in $R$ and form a singleton $(\\{\\mathfrak{p}\\},\\mathfrak{p})$ and the map:\n$$\\mrm{Spec}(\\varepsilon) : \\{\\mathfrak{p}\\} \\longrightarrow \\mrm{Spec} R[x,x^ {-1}],\\ \\mathfrak{p} \\longmapsto \\left<x - 1\\right>$$\nNote that if $R$ is some integral domain this chosen prime ideal is naturally the zero ideal. This map becomes our inclusion $e : \\ast \\longrightarrow R^\\times$ of the trivial subgroup.\n\\item Next, we note that the tensor product $R[x,x^{-1}] \\otimes R[x,x^{-1}]$ is isomorphic to $R[x,x^{-1},y,y^{-1}] = S^{-1}_{x,y} R[x,y]$ and we therefore only need to discuss the prime ideals in the latter ring (actually only those in $R[x,x^{-1}]$ as only those will be in the preimage of $\\Delta$):\n$$\\bao{rrcl}\n\\mrm{Spec}(\\Delta) : &\\mrm{Spec} (R[x,x^{-1}] \\otimes R[x,x^{-1}]) &\\longrightarrow &\\mrm{Spec}(R[x,x^ {-1}])\\\\\n& \\left<a x - 1\\right> \\otimes \\left<b x - 1\\right> &\\longmapsto & \\left<a b x - 1\\right>\\\\\n\\ea$$\n\\end{enumerate}\n", "meta": {"hexsha": "163e1ae0f94ad27afec038c02d9c88ce5dc6f85a", "size": 11127, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "category_theory/intro.tex", "max_stars_repo_name": "gmuel/texlib", "max_stars_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "category_theory/intro.tex", "max_issues_repo_name": "gmuel/texlib", "max_issues_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "category_theory/intro.tex", "max_forks_repo_name": "gmuel/texlib", "max_forks_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.9811320755, "max_line_length": 902, "alphanum_fraction": 0.6699919116, "num_tokens": 3864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.7184716839868961}}
{"text": "\\chapter{Unit 6}\n\\section{Integration by Parts}\nTo integrate using parts, pick a $u$ and a $dv$ from the origianl integral. The\n$dv$ ideally should be something that is easy to integrate, while the $u$ should\nbe easy to differentiate.\n\nOnce selected, simply apply the formula to yield your answer. You may have to do\nparts more than once, or have the recursive case where the original integral\ncomes up again, and you have to move it to one side.\n\n\\begin{equation}\n  \\int u dv = uv - \\int v du\n\\end{equation}\n\n\\section{Powers of Trigonometric Expressions}\n\\subsection{$\\int \\cos^n\\theta\\sin^m\\theta d\\theta$}\n\\begin{description}\n  \\item[$n$ or $m$ odd] convert all but one of that function to the other using\n    a trigonometric identity. The remaining power is the $d\\theta$.\n  \\item[$n$, $m$ both even] use a power reducing formula.\n\\end{description}\n\n\\subsection{$\\int \\sec^n\\theta\\tan^m\\theta d\\theta$}\n\\begin{description}\n  \\item[$n$ is even] convert all but one $\\sec^2\\theta$ to $\\tan$s using a\n    trigonometric identity. The remaining $\\sec^2\\theta$ will be your $d\\theta$.\n  \\item[$n$ is odd] convert all but one to $\\sec\\theta$, saving a\n    $\\sec\\theta\\tan\\theta$.\n  \\item[$n=0$, $m$ is anything] convert one $\\tan^2\\theta$ to $\\sec^2\\theta-1$\n\\end{description}\n\n\\subsection{Base-case}\nIf the trigonometric power expression you have is none of the above, you have to\nconvert everything to $\\sin$s and $\\cos$s and simplify from there.\n\n\\section{Triginometric Substitution}\nYou can substitute three cases of integrals into a triangle and then simplify\nin terms of $\\theta$. Integrate with respect to $d\\theta$ and then convert your\nanswer back in terms of $x$, $y$, or $z$ using the original triangle.\n\n\\begin{align}\n  \\sqrt{a^2-u^2} &\\to \\sin\\theta = \\frac{u}{a} \\\\\n  \\sqrt{a^2+u^2} &\\to \\tan\\theta = \\frac{u}{a} \\\\\n  \\sqrt{u^2-a^2} &\\to \\sec\\theta = \\frac{u}{a}\n\\end{align}\n\n\\section{Partial Fractions}\nIf you have a integral where the denominator is factorable (or can be split to\nbecome factorable) then you can use partial fractions.\n\n\\begin{equation}\n  \\int \\frac{p(x)}{q(x)} dx = \\int {\\frac{A}{x}+\\frac{B}{(x+1)}+\\ldots\\; } dx\n\\end{equation}\n\nThere are a few rules when dealing with expanding the denominator to use partial\nfractions.\n\\begin{itemize}\n  \\item If you have a factor in the form $(px^2+q)$, the numerator is in the\n    form $(Ax+B)$.\n  \\item If you have a factor in the form $(px+q)$ then then numerator is in the\n    form of $A$.\n\\end{itemize}\n\nTo solve...\n\\begin{enumerate}\n  \\item Make the denominator factor-able.\n  \\item Break apart the partial fraction.\n  \\item Create the basic equation.\n  \\item Isolate terms by power.\n  \\item Solve the system.\n  \\item Integrate each part.\n\\end{enumerate}\n", "meta": {"hexsha": "9801f66cbdb180944481e3138daf0dcc9e87b8ce", "size": 2729, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016/bc_calculus/units/unit_6.tex", "max_stars_repo_name": "ttaylorr/midterms", "max_stars_repo_head_hexsha": "fdde0fd1a66eb5242d0dfa04a5201c3ab6d6b7eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-01-06T06:55:26.000Z", "max_stars_repo_stars_event_max_datetime": "2015-01-06T06:55:26.000Z", "max_issues_repo_path": "2016/bc_calculus/units/unit_6.tex", "max_issues_repo_name": "ttaylorr/midterms", "max_issues_repo_head_hexsha": "fdde0fd1a66eb5242d0dfa04a5201c3ab6d6b7eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2016/bc_calculus/units/unit_6.tex", "max_forks_repo_name": "ttaylorr/midterms", "max_forks_repo_head_hexsha": "fdde0fd1a66eb5242d0dfa04a5201c3ab6d6b7eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.3835616438, "max_line_length": 80, "alphanum_fraction": 0.7097838036, "num_tokens": 829, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.924141826246517, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.7183353132471432}}
{"text": "\\subsection{ResNet and pre-act ResNet structure}\nBased on the notation for standard DNN structure, we now present\nthe definition for ResNet type models in DNNs.\n\n\\paragraph{ResNet}\nThe ResNet can be written as\n\\begin{equation}\\label{ori-ResNet-dnn}\n\\begin{cases}\nx^0 &= x, \\\\\nx^{\\ell} &= \\sigma \\left( P^\\ell x^{\\ell-1} + \\mathcal{F}^{\\ell} (x^{\\ell-1}) \\right), \\quad \\ell = 1:L ,\\\\\n{\\text{ResNet}}_{L}(x) &=   W^L x^{L}  + b^L.\n\\end{cases}\n\\end{equation}\nHere\n\\begin{equation}\\label{eq:F-ResNet}\n\\mathcal{F}^{\\ell}  \\in  \\dnn(n_\\ell, m_\\ell),\n\\end{equation}\nor more precisely, \n\\begin{equation}\\label{key}\n\\mathcal{F}^{\\ell}(x) = \\xi^{\\ell} \\circ \\sigma \\circ \\eta^{\\ell} (x),\n\\end{equation}\nwhere\n\\begin{equation}\\label{key}\n\\eta^\\ell: \\mathbb{R}^{{\\rm dim}_x} \\mapsto \\mathbb{R}^{n_\\ell}, \\quad \\text{and} \\quad \\xi^{\\ell}:  \\mathbb{R}^{n_\\ell} \\mapsto \\mathbb{R}^{m_\\ell}.\n\\end{equation}\nThis kind of ResNet is consist with original ResNet CNN~\\cite{he2016deep}, which is associated with a skip connection distant 2. \nHere $P^i$ is use to fit the dimension as\n\\begin{equation}\\label{eq:P^i}\nP^\\ell: \\mathbb{R}^{{\\rm dim}_{x^{\\ell-1}}} \\mapsto \\mathbb{R}^{m_\\ell}.\n\\end{equation}\nIn most cases, if ${\\rm dim}_{x^{\\ell-1}} = m_\\ell$, then take $P^\\ell = {\\rm id}$.\n\n\\paragraph{pre-act ResNet} \nThe pre-act ResNet~\\cite{he2016identity} can be written as:\n\\begin{equation}\\label{ori-iResNet-dnn}\n\\begin{cases}\nx^0 &= x, \\\\\nx^{\\ell} &=  P^\\ell x^{\\ell-1} + \\mathcal{F}^{\\ell} \\left( \\sigma (x^{\\ell-1}) \\right), \\quad \\ell = 1:L ,\\\\\n{\\text{pre-act ResNet}}_{L}(x) &=  W^L x^{L} + b^L.\n\\end{cases}\n\\end{equation}\nHere $\\mathcal{F}^{\\ell}$ and $P^\\ell$ share the same setup as in ResNet.\n\n\n\\subsection{A more general ResNet DNN}\nIn some literature, the next ResNet type DNN is more popular.\n\\begin{equation}\\label{general-ResNet-dnn}\n\\begin{cases}\nx^0 &= x, \\\\\nx^{\\ell} &=  P^\\ell x^{\\ell-1} + \\mathcal{F}^{\\ell} \\left( x^{\\ell-1} \\right), \\quad \\ell = 1:L ,\\\\\n{\\text{gResNet}}_{L}(x) &=  W^L x^{L} + b^L.\n\\end{cases}\n\\end{equation}\nHere $\\mathcal{F}^{\\ell}$ may have a more general version compared with classical ResNet.\nFor example, \n\\begin{equation}\\label{key}\n\\mathcal{F}^{\\ell} = \\sigma \\circ \\theta^\\ell, \\quad \\text{and} \\quad P^\\ell = {\\rm id},\n\\end{equation}\nor\n\\begin{equation}\\label{key}\n\\mathcal{F}^{\\ell} \\in \\dnn(n^\\ell_1, n^\\ell_2, \\cdots, n^\\ell_{L_\\ell}).\n\\end{equation}\n\n\n\\subsection{DNN type DenseNet}\nIn fact, DenseNet might be simple for definition in DNN case. \n\nHere use $\\sigma \\circ \\theta$ type as example.\n\\begin{equation}\\label{ori-DenseNet-dnn}\n\\begin{cases}\nx^0 &= x, \\\\\nx^{\\ell} &=   \\sigma \\circ \\theta^{\\ell}([x^{\\ell-1}, x^{\\ell-2}, \\cdots, x^0]) , \\quad \\ell = 1:L ,\\\\\n{\\text{DenseNet}}_{L}(x) &=  W^L x^{L} + b^L.\n\\end{cases}\n\\end{equation}\n\nHere $[x^{\\ell-1}, x^{\\ell-2}, \\cdots, x^0]$ means a long vector by collecting all \noutputs from $x^0$ to $x^{\\ell-1}$.\n\n%, thus to say\n%$$\n%{\\rm dim}([f^{i-1}, f^{i-2}, \\cdots, f^0]) = \\sum_{i=0}^{i-1} n_i.\n%$$\n\n\n\\endinput\n%\\subsection{DNN type MgNet}\n%Similar with ResNet, we can rewrite MgNet.\n%\n%Here use $\\theta \\circ \\sigma$ type as example.\n%\\begin{equation}\\label{ori-MgNetNet-dnn}\n%\\begin{cases}\n%u^0 &= 0, \\quad f^0 = \\theta^0(x) \\\\\n%u^{\\ell} &=  P^\\ell u^{\\ell-1} + \\mathcal{F}^{i} (f^{i-1} - ) , \\quad i = 1:J ,\\\\\n%{\\rm MgNet}_{L} &= u^{L}.\n%\\end{cases}\n%\\end{equation}\n%Here\n%\\begin{equation}\\label{eq:F-MgNet}\n%\\mathcal{F}^{i} (f^{i-1}) = \\xi^{i} \\left( f^{i-1} +  \\sigma \\circ \\eta^{i} \\circ \\sigma(f^{i-1}) \\right).\n%\\end{equation}\n\n%\\newpage\n%\\input{juncai_dnn}", "meta": {"hexsha": "84b6f7f92b940798f990f14d8bac3c0f9d51af4c", "size": 3555, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/DNNResNet.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/DNNResNet.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/DNNResNet.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.1826923077, "max_line_length": 149, "alphanum_fraction": 0.6250351617, "num_tokens": 1461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7183353068555887}}
{"text": "\\subsection{Hyperboloids}\r\n\\noindent\r\nA hyperboloid looks like a hyperbola that has been rotated and extruded about its center. It is also radially symmetric with circular level curves. Paraboloids have the form \r\n\\begin{equation*}\r\n\td = \\pm \\frac{x^2}{a^2} \\pm \\frac{y^2}{b^2} \\pm \\frac{z^2}{c^2},\r\n\\end{equation*}\r\nwhere one sign is different from the others. Depending on the signs and the value of $d$, one can get a hyperboloid of one sheet, two sheets, or a cone.\r\n\r\n\\input{./differentialMultivariableCalculus/hyperboloidOneSheet}\r\n\\input{./differentialMultivariableCalculus/hyperboloidTwoSheet}\r\n\\input{./differentialMultivariableCalculus/cone}", "meta": {"hexsha": "b2915cb2fcc4aa9ff8ab3dd1bac52d2cf48335da", "size": 651, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/hyperboloids.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/hyperboloids.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/hyperboloids.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 59.1818181818, "max_line_length": 175, "alphanum_fraction": 0.7695852535, "num_tokens": 192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7182900040077157}}
{"text": "\\chapter{Unit 2}\n\\section{Continuity, Intermediate Value Theroem}\n\\subsection{Continuity}\nLet $f(x)$ be a function defined at $x=a$. $f$ is said to be continuous at $x=a$\nif:\n\\begin{equation}\n  \\lim_{x\\to{a^+}} f(x) = \\lim_{x\\to{a^-}} f(x) = f(a)\n\\end{equation}\n\n\\subsection{Intermediate Value Theorem}\nLet $f(x)$ be defined over $x\\in[a,b]$. Suppose that $f(a)$ and $f(b)$ both\nexist. The intermediate value theorem states that there exists a $c\\in[a,b]$\nsuch that $f(a)<f(c)=V<f(b)$.\n\n\\section{$\\delta$-$\\epsilon$ proofs}\nPreforming a $\\delta$-$\\epsilon$ proof means proving the existence of a limit\nusing the $\\delta$-$\\epsilon$ definition of a limit. That definition follows\nbelow:\n\nSuppose:\n$$\\lim_{x\\to{c}} f(x) = L$$\n\nIt can be said, therefore:\n\\begin{equation}\n  |x-c|<\\delta \\Rightarrow |f(x)-L|<\\epsilon\n\\end{equation}\n\nTo prove the existence of a limit using the $\\delta$-$\\epsilon$ definition of\nthe limit, follow the process below:\n\\begin{enumerate}\n  \\item Write $|x-c|<\\delta$ filling in known values of $c$.\n  \\item Write $|f(x|-L|<\\epsilon$ filling in the values of $f(x)$ in terms of\n    $x$ and $L$.\n  \\item Manipulate one inequality to look like the other, and set them equal.\n  \\item Determine the relationship between $\\delta$ and $\\epsilon$.\n  \\item Reverse to prove.\n\\end{enumerate}\n\n\\section{Indeterminate Forms \\& L'Hopital's rule}\n\\subsection{Indeterminate Forms}\nWhen evaluating a limit, it may become impossible to continue evaluation if the\ninner-function of the limit is not defined.\n\nFor limits of the form:\n$$\\lim_{x\\to{c}}\\frac{p(x)}{q(x)}=L$$\n\nIf $\\frac{p(x)}{q(x)}$ is one of the following forms: $\\frac{0}{0}$ or\n$\\frac{\\pm\\infty}{\\pm\\infty}$, then L'Hopital's rule may be applied.\n\nL'Hopital's rule states the following for limits with indeterminate forms:\n\n\\begin{equation}\n  \\lim_{x\\to{c}} \\frac{p(x)}{q(x)} = \\lim_{x\\to{c}} \\frac{p'(x)}{q'(x)}\n\\end{equation}\n\n...and so-on and so-forth until the limit exists (so long as $\\frac{p(x)}{q(x)}$\nis an indeterminate form).\n\n\\section{Limits and Continuity}\n\\section{Derivatives}\nThe derivative of a function is another function which is valued as the set of\ninstantenous rates of changes of its \"parent\" function. A definition follows:\n\n\\subsection{Limit Definition}\n\\begin{equation}\n  f'(x)=\\lim_{h\\to{0}} \\frac{f(x+h)-f(x)}{h}\n\\end{equation}\n\n\\subsection{Alternate Form}\nThe alternate form of the derivate follows:\n\\begin{equation}\n  f'(c)=\\lim_{x\\to{c}} \\frac{f(x)-f(c)}{x-c}\n\\end{equation}\n\n\\subsection{Implicit Differentation}\nDifferentiate an equation with respect to one variable, and other differentials\nremain. You can move all differentials of a single kind over to one side to\nsolve. An example follows below:\n\n\\begin{align*}\n  x^2+y^2 &= \\sin(xy)-y^2 \\\\\n  \\frac{d}{dx}[x^2+y^2] &= \\frac{d}{dt}[\\sin(xy)-y^2] \\\\\n  2x+2y\\frac{dy}{dt} &= cos(xy)\\left(y+x\\frac{dy}{dt}\\right)-2y\\frac{dy}{dt}\n\\end{align*}\n\n\\subsection{Average Rate of Change}\nThe average rate of change gives the average rate of change of $f(x)$ on the\ninterval $[a,b]$.\n\\begin{equation}\n  \\frac{f(b)-f(a)}{b-a}\n\\end{equation}\n\n\\subsection{Instantenous Rate of Change}\nThe instantenous rate of change gives the rate of change at a particular point.\n\\begin{equation}\n  f'(c)\n\\end{equation}\n\n\\subsection{Arctrig Proofs}\nSuppose $y=\\arctan(x)$, therefore $y'=\\frac{dx}{1+x^2}$. Prove.\n\n\\begin{equation}\n\\begin{aligned}\n  \\tan(y) &= x \\\\\n  \\sec^2(y)\\frac{dy}{dx} &= 1 \\\\\n  \\frac{1}{\\sec^2(y)} &= \\frac{dy}{dx} \\\\\n  \\frac{1}{1+\\tan^2(y)} &= \\\\\n  \\frac{1}{1+x^2} &=\n\\end{aligned}\n\\end{equation}\n\n\\subsection{Differentiability}\nSuppose $f(x)$ is a function such that $\\{c\\} \\in D_{f(x)}$. While\ndifferentiability at $x=c$ is an implication of continuity at $x=c$, the\nconverse is not necessairly true. Continuity implies differentiability in the\nfollowing scenarios:\n\\begin{itemize}\n  \\item $f(x)$ has normal behavior around $x=c$.\n\\end{itemize}\n\n...but does not imply differentiability in the following scenarios:\n\\begin{itemize}\n  \\item $f(x)$ has a cusp at $x=c$.\n  \\item $f(x)$ has a vertical \"jump\" at $x=c$.\n\\end{itemize}\n\nTo prove differentiability of $f$ at a point $x=c$, the following steps must be\ntaken:\n\\begin{enumerate}\n  \\item $\\lim_{x\\to{c}} \\frac{f(x)-f(c)}{x-c}$ must exist and \"agree\" from both\n    sides.\n\\end{enumerate}\n\n\\subsection{Inverse Functions}\nThe derivative of an inverse function is defined:\n\\begin{equation}\n  \\frac{d}{dx}\\left[f^{-1}(x)\\right]=\\frac{1}{f'(f^{-1}(x))}\n\\end{equation}\n\n\\section{Logarithmic and Exponential Functions}\nIf it is impossible to differentiate or take the limit of a function w.r.t. $x$,\nit is sometimes useful to take the natural log of both sides such that\nL'Hopital's rule may be applied. An example is shown below:\n\\begin{equation}\n  \\begin{aligned}\n    L &= \\lim_{x\\to\\infty} \\left(1+\\frac{1}{x}\\right)^x \\\\\n    \\ln{L} &= \\ln{\\lim_{x\\to\\infty} \\left(1+\\frac{1}{x}\\right)^x} \\\\\n           &= \\lim_{x\\to\\infty} \\ln\\left(\\left(1+\\frac{1}{x}\\right)^x\\right) \\\\\n           &= \\lim_{x\\to\\infty} x\\ln\\left(1+\\frac{1}{x}\\right) \\\\\n           &= \\lim_{x\\to\\infty} \\frac{\\ln\\left(1+\\frac{1}{x}\\right)}{x^{-1}} \\\\\n           &= \\lim_{x\\to\\infty} \\frac{0}{0} \\\\\n           &= \\lim_{x\\to\\infty} \\frac{\\frac{1}{1+\\frac{1}{x}}x^{-2}}{-x^{-2}} \\\\\n           &= \\lim_{x\\to\\infty} \\frac{1}{1+\\frac{1}{x}} \\\\\n           &= 1 \\\\\n    L &= e.\n  \\end{aligned}\n\\end{equation}\n\n\\section{Derivates w.r.t Other Functions}\nAs we have seen so far, functions can be differentiated with respect to a\nvariable of that function (ex.: $f(x)$ and $\\frac{d}{dx}(f(x))$).\n\nHowever, it is possible to differentiate a function with respect to another\nfunction. To differentiate a function $f(x)$ with respect to another function\n$g(x)$, the following equation is used:\n\\begin{equation}\n  \\frac{d[f(x)]}{d[g(x)]}=\\frac{d[f(x)]/dt}{d[g(x)]/dt}\n\\end{equation}\n", "meta": {"hexsha": "3fac33ae478a84a3a42ff0d20e3e8026fe149271", "size": 5833, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016/bc_calculus/units/unit_2.tex", "max_stars_repo_name": "ttaylorr/midterms", "max_stars_repo_head_hexsha": "fdde0fd1a66eb5242d0dfa04a5201c3ab6d6b7eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-01-06T06:55:26.000Z", "max_stars_repo_stars_event_max_datetime": "2015-01-06T06:55:26.000Z", "max_issues_repo_path": "2016/bc_calculus/units/unit_2.tex", "max_issues_repo_name": "ttaylorr/midterms", "max_issues_repo_head_hexsha": "fdde0fd1a66eb5242d0dfa04a5201c3ab6d6b7eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2016/bc_calculus/units/unit_2.tex", "max_forks_repo_name": "ttaylorr/midterms", "max_forks_repo_head_hexsha": "fdde0fd1a66eb5242d0dfa04a5201c3ab6d6b7eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.5147928994, "max_line_length": 80, "alphanum_fraction": 0.6691239499, "num_tokens": 1942, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317473, "lm_q2_score": 0.8688267864276108, "lm_q1q2_score": 0.7182693439253802}}
{"text": "\\documentclass{article}\n    % General document formatting\n    \\usepackage[margin=0.7in]{geometry}\n    \\usepackage[parfill]{parskip}\n    \\usepackage[utf8]{inputenc}\n    \\usepackage{mathrsfs}\n    \\usepackage{amsmath}\n    \\usepackage{amssymb}\n    \\usepackage{tikz}\n    \\usepackage{fancyhdr}\n    \\usepackage{multicol}\n\n    \\usetikzlibrary{positioning}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\\rhead{Edgar Jacob Rivera Rios - A01184125}\n\n\\renewcommand{\\labelenumi}{\\alph{enumi})}\n\n\\begin{document}\n\\section*{5.1.1}\nThe Employment and Training Administration reported that the U.S. mean unemployment insurance benefit was \\$238 per week (The World Almanac, 2003). A researcher in the state of Virginia anticipated that sample data would show evidence that the mean weekly unemployment insurance benefit in Virginia was below the national average.\n\n\\begin{enumerate}\n  \\item Develop appropriate hypotheses such that rejection of H0 will support the researcher’s contention.\n  \\begin{align*}\n    H_{0} &= \\mu \\geq \\mu_{l}\\\\\n    H_{\\alpha} &= \\mu < \\mu_{l}\\\\\n  \\end{align*}\n\n  \\item For a sample of 100 individuals, the sample mean weekly unemployment insurance benefit was \\$231 with a sample standard deviation of \\$80. What is the $p$-value?\n  \\begin{align*}\n    s &= 80\\\\\n    \\mu &= 238\\\\\n    \\bar{x} &= 231\\\\\n    n &= 100\\\\\n    s_{\\bar{x}} &= \\frac{s}{\\sqrt{n}}\\\\\n    s_{\\bar{x}} &= \\frac{80}{\\sqrt{100}}\\\\\n    s_{\\bar{x}} &= 8\\\\\n    t &= \\frac{\\bar{x} - \\mu}{s_{\\bar{x}}}\\\\\n    t &= \\frac{231 - 238}{8}\\\\\n    t &= -0.875\\\\\n    p-value &= 0.19184589\n  \\end{align*}\n\n  \\item At $\\alpha = .05$, what is your conclusion?\n\n  As the $p-value$ is greater than 0.05, we cannot reject $H_{0}$\n\n  \\item Repeat the preceding hypothesis test using the critical value approach.\n\n  \\begin{align*}\n    t &= -0.875\\\\\n    \\text{critical value} (t_{0}) &= -1.66039115\n  \\end{align*}\n  As $t < t_{0}$ does not hold, we cannot reject $h_{0}$\n\n\\end{enumerate}\n\\pagebreak\n\n\\section*{5.1.2}\nA shareholders’ group, in lodging a protest, claimed that the mean tenure for a chief executive office (CEO) was at least nine years. A survey of companies reported in The Wall Street Journal found a sample mean tenure of$\\bar{X} = 7.27$ years for CEOs with a standard deviation of $s = 6.38$ years (The Wall Street Journal, January 2, 2007).\n\\begin{enumerate}\n  \\item Formulate hypotheses that can be used to challenge the validity of the claim made by the shareholders’ group.\n  \\begin{align*}\n    H_{0} &= \\mu \\geq 9\\\\\n    H_{\\alpha} &= \\mu < 9 \\\\\n  \\end{align*}\n\n  \\item Assume 85 companies were included in the sample. What is the $p$-value for your hypothesis test?\n  \\begin{align*}\n    s &= 6.38\\\\\n    \\mu_{0} &= 9\\\\\n    \\bar{x} &= 7.27\\\\\n    n &= 85\\\\\n    s_{\\bar{x}} &= \\frac{s}{\\sqrt{n}}\\\\\n    s_{\\bar{x}} &= \\frac{6.38}{\\sqrt{85}}\\\\\n    s_{\\bar{x}} &= 0.692008160441513\\\\\n    t &= \\frac{\\bar{x} - \\mu_{0}}{s_{\\bar{x}}}\\\\\n    t &= \\frac{7.27 - 9}{0.692008160441513}\\\\\n    t &= -2.49997051898381\\\\\n    p-value &= 0.007182545042323\n  \\end{align*}\n\n  \\item At $\\alpha = .01$, what is your conclusion?\n\n  As the $p-value$ is less than 0.01, we can reject $H_{0}$, which means that the CEO's mean tenure is less than 9 years\n\n\\end{enumerate}\n\\pagebreak\n\n\\section*{5.1.3}\nThe Coca-Cola Company reported that the mean per capita annual sales of its beverages in the United States was 423 eight-ounce servings (Coca-Cola Company website, February 3, 2009). Suppose you are curious whether the consumption of Coca-Cola beverages is higher in Atlanta, Georgia, the location of Coca-Cola’s corporate headquarters.\n\nA sample of 36 individuals from the Atlanta area showed a sample mean annual consumption of 460.4 eight-ounce servings with a standard deviation of $s = 101.9$ ounces.\n\nUsing $\\alpha = .05$, do the sample results support the conclusion that mean annual consumption of Coca-Cola beverage products is higher in Atlanta?\n\n\\begin{align*}\n  H_{0} &= \\mu \\leq 423\\\\\n  H_{\\alpha} &= \\mu > 423 \\\\\n  s &= 101.9\\\\\n  \\mu_{0} &= 423\\\\\n  \\bar{x} &= 460.4\\\\\n  n &= 36\\\\\n  s_{\\bar{x}} &= \\frac{s}{\\sqrt{n}}\\\\\n  s_{\\bar{x}} &= \\frac{101.9}{\\sqrt{36}}\\\\\n  s_{\\bar{x}} &= 16.9833333333333\\\\\n  t &= \\frac{\\bar{x} - \\mu_{0}}{s_{\\bar{x}}}\\\\\n  t &= \\frac{460.4 - 423}{16.9833333333333}\\\\\n  t &= 2.20215897939156\\\\\n  p-value &= 0.01716737427853\n\\end{align*}\n\nAs the $p-value$ is less than 0.05, we can reject $H_{0}$, which means that the Coke consumption it's higher in Atlanta than in the rest of the USA\n\n\\end{document}", "meta": {"hexsha": "773bf1b4987e62bc00d5c5a77c09af073687b166", "size": 4468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/Homework5_1.tex", "max_stars_repo_name": "edjacob25/Applied-Maths", "max_stars_repo_head_hexsha": "0a0f8e5b88083a1b0ec85069efbf266b6a12c741", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Homework/Homework5_1.tex", "max_issues_repo_name": "edjacob25/Applied-Maths", "max_issues_repo_head_hexsha": "0a0f8e5b88083a1b0ec85069efbf266b6a12c741", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework/Homework5_1.tex", "max_forks_repo_name": "edjacob25/Applied-Maths", "max_forks_repo_head_hexsha": "0a0f8e5b88083a1b0ec85069efbf266b6a12c741", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.8644067797, "max_line_length": 342, "alphanum_fraction": 0.6602506714, "num_tokens": 1458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.835483553488848, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.7182349250815757}}
{"text": "\\section*{Exercises}\n\n\\begin{ex} Give the complete solution to $x^{4}+16=0$.\n\\begin{sol}\n Solution is:\n\\[\n(1-i) \\sqrt{2},-(1+i) \\sqrt{2},-(1-i)\n\\sqrt{2},(1+i) \\sqrt{2}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} \\label{cube-roots} Find the complex cube roots of $8$.\n\\begin{sol}\nThe cube roots are the solutions to $%\nz^{3}+8=0$, Solution is: $i\\sqrt{3} +1,1-i\\sqrt{3},-2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} \\label{cube-roots2} Find the four fourth roots of $16$.\n\\begin{sol}\nThe fourth roots are\nthe solutions to $z^{4}+16=0$, Solution is:\n\\[\n(1-i) \\sqrt{2},-(1+i) \\sqrt{2},-(1-i)\n\\sqrt{2},(1+i)\\sqrt{2}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} \\label{exer-complex1}De Moivre's theorem says $\\mat{r(\\cos\nt+i\\sin t)} ^{n}=r^{n}(\\cos nt+i\\sin nt) $ for $n$\na positive integer. Does this formula continue to hold for all integers $n$,\neven negative integers? Explain.\n\\begin{sol}\nYes, it holds for all integers. First of\nall, it clearly holds if $n=0$. Suppose now that $n$ is a negative integer.\nThen $-n>0$ and so\n\\[\n\\mat{r(\\cos t+i\\sin t)} ^{n}=\\frac{1}{\\mat{r(\n\\cos t+i\\sin t)} ^{-n}}=\\frac{1}{r^{-n}(\\cos (\n-nt) +i\\sin (-nt)) }\n\\]\n\\begin{eqnarray*}\n&=&\\frac{r^{n}}{(\\cos (nt) -i\\sin (nt))\n}=\\frac{r^{n}(\\cos (nt) +i\\sin (nt)) }{\n(\\cos (nt) -i\\sin (nt)) (\\cos\n(nt) +i\\sin (nt)) } \\\\\n&=&r^{n}(\\cos (nt) +i\\sin (nt))\n\\end{eqnarray*}\nbecause $(\\cos (nt) -i\\sin (nt)) (\n\\cos (nt) +i\\sin (nt)) =1$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Factor $x^{3}+8$ as a product of linear factors. \\textbf{Hint:} Use the result of {\\eqref{cube-roots}}.\n\\begin{sol}\nSolution\nis: $i\\sqrt{3}+1,1-i\\sqrt{3},-2$ and so this polynomial equals\n\\[\n(x+2) (x-(i\\sqrt{3}+1)) (x-(\n1-i\\sqrt{3}))\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Write $x^{3}+27$ in the form $(x+3) (\nx^{2}+ax+b) $ where $x^{2}+ax+b$ cannot be factored any more using\nonly real numbers.\n\\begin{sol}\n$x^{3}+27= (x+3) (\nx^{2}-3x+9) $\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Completely factor $x^{4}+16$ as a product of linear factors. \\textbf{Hint:} Use the result of {\\eqref{cube-roots2}}.\n\\begin{sol}\nSolution is:\n\\[\n(1-i) \\sqrt{2},-(1+i) \\sqrt{2},-(1-i)\n\\sqrt{2},(1+i) \\sqrt{2}.\n\\]\nThese are just the fourth roots of $-16$. Then to factor, you get\n\\begin{eqnarray*}\n&&(x-((1-i) \\sqrt{2})) (x-(\n-(1+i) \\sqrt{2})) \\cdot \\\\\n&&(x-(-(1-i) \\sqrt{2})) (x-(\n(1+i) \\allowbreak \\sqrt{2}))\n\\end{eqnarray*}\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Factor $x^{4}+16$ as the product of two quadratic polynomials each of\nwhich cannot be factored further without using complex numbers.\n\\begin{sol}\n$x^{4}+16=(x^{2}-2\\sqrt{2}x+4) (x^{2}+2\\sqrt{2}x+4) .\n$ You can use the information in the preceding problem. Note that $(\nx-z) (x-\\conjugate{z}) $ has real coefficients.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} If $n$ is an integer, is it always true that $(\\cos \\theta\n-i\\sin \\theta) ^{n}=\\cos (n\\theta) -i\\sin (n\\theta\n)$? Explain.\n\\begin{sol}\nYes, this is true.\n\\begin{eqnarray*}\n(\\cos \\theta -i\\sin \\theta) ^{n} &=&(\\cos (-\\theta\n) +i\\sin (-\\theta)) ^{n} \\\\\n&=&\\cos (-n\\theta) +i\\sin (-n\\theta) \\\\\n&=&\\cos (n\\theta) -i\\sin (n\\theta)\n\\end{eqnarray*}\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose $p(x) =a_{n}x^{n}+a_{n-1}x^{n-1}+\\ldots+a_{1}x+a_{0}$ \\ is a polynomial and it has $n$ zeros,\n\\begin{equation*}\nz_{1},z_{2},\\ldots,z_{n}\n\\end{equation*}\nlisted according to multiplicity. ($z$ is a root of multiplicity $m$ if the\npolynomial $f(x) =(x-z) ^{m}$ divides $p(\nx) $ but $(x-z) f(x) $ does not.) Show that\n\\begin{equation*}\np(x) =a_{n}(x-z_{1}) (x-z_{2}) \\cdots\n(x-z_{n})\n\\end{equation*}\n\\begin{sol}\n$p(x) =(x-z_{1}) q(x) +r(x) $\nwhere $r(x) $ is a non-zero constant or equal to $0$. However, $r(z_{1}) =0$ and so $r(x) =0$. Now do to $q(\nx) $ what was done to $p(x) $ and continue until the\ndegree of the resulting $q(x) $ equals $0$. Then you have the\nabove factorization.\n\\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "ac4cd797e6e56d9c6b99ce56e6d956c9b6f5c2b7", "size": 3762, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/exercises/ComplexNumbers-Roots.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/exercises/ComplexNumbers-Roots.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/exercises/ComplexNumbers-Roots.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 27.6617647059, "max_line_length": 127, "alphanum_fraction": 0.6031366295, "num_tokens": 1581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7182349230112592}}
{"text": "\\subsection{Cell complexes}\n\\begin{defn}\nA CW complex is a Hausdorff space $X$ constructed as follows:\\end{defn}\n\\begin{enumerate}\n\\item Start with $X^{0}=\\{\\text{discrete set of points}\\}$.\n\\item Form a graph $X^{n}$ from $X^{n-1}$ by attacheding n-cells via maps\n$\\phi_{\\alpha}:S^{n-1}\\to X^{n-1}$. So $X^{n}=(X^{n-1}\\sqcup B_{\\alpha}^{n})/(x\\sim\\phi_{\\alpha}(x)\\forall x\\in\\partial B_{\\alpha}^{n})$\\\\\n\\\\\n$X^{n}$ has the quotient topology defined by $q:X^{n-1}\\sqcup B_{\\alpha}^{n}\\to X^{n}$,\ni.e. $U\\subset X^{n}$ open iff $q^{-1}(U)$ open in $X^{n-1}\\sqcup B_{\\alpha}^{n}$.\\\\\n\\\\\n$X^{n}=\\text{\"n-skeleton\"}=X^{n-1}\\sqcup e_{\\alpha}^{n}$ where $e_{\\alpha}^{n}$\nis an open $n$-ball, i.e. the image of $\\text{int}B_{\\alpha}^{n}$\nunder $q$.\n\\item $X=X^{n}$ for finite integer $n$ or $X=\\bigcup_{n=0}^{\\infty}X^{n}$\nand $X$ has the ``weak topology''.\n\\end{enumerate}\nNote: If $X$ is finite, we can define the Euler characteristic $\\chi(X)=\\sum_{i}(-1)^{i}(\\text{\\# of \\ensuremath{i}-cells in \\ensuremath{X})}$.\nThe dimension of $X$ is the maximum dimension of the cells.\n\nNotes about CW complexs:\n\\begin{itemize}\n\\item $\\chi(S^{2})=2$, $\\chi(M_{g})=2-2g$, $\\chi(N_{h})=2-h$.\n\\item $S^{n}=e^{-0}\\cup e^{n}$\n\\item $\\mathbb{R}P^{n}=\\mathbb{R}P^{n-1}\\cup(\\text{open n-cell})=e^{0}\\cup e^{1}\\cup\\cdots\\cup e^{n}$.\n\\item $\\chi(\\mathbb{R}P^{n})=1-1+1\\dots=\\begin{cases}\n1 & n\\,\\text{even}\\\\\n0 & n\\,\\text{odd}\n\\end{cases}$\n\\item $\\mathbb{C}P^{n}=\\mathbb{C}P^{n-1}\\cup(\\text{copy of \\ensuremath{\\mathbb{C}^{n})=}}e^{0}\\cup e^{2}\\cup\\cdots\\cup e^{2n}.$\n\\item Products of finite CW complexes are CW complexes.\\\\\n\\\\\nSuppose $X=\\bigcup_{\\alpha}e_{\\alpha},$ $Y=\\bigcup_{\\beta}e_{\\beta}$,\nthen $X\\times Y=\\bigcup_{\\alpha,\\beta}(e_{\\alpha}\\times e_{\\beta})$\nhas dimension $\\dim(e_{\\alpha})+\\dim(e_{\\beta})$. It's an exercise\nto show $\\chi(X\\times Y)=\\chi(X)\\cdot\\chi(Y)$.\\\\\n\\\\\nExample: $S^{2}\\times S^{2}=(e^{0}\\cup e^{2})\\times(e^{0}\\cup e^{2})=e^{0}\\times e^{0}\\cup e^{0}\\times e^{2}\\cup e^{2}\\times e^{0}\\cup e^{2}\\times e^{2}$.\n\\end{itemize}\n", "meta": {"hexsha": "527c3575869647468a9c922d9fb543fc4159c665", "size": 2028, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cw_complexes.tex", "max_stars_repo_name": "silky/alg-top-notes", "max_stars_repo_head_hexsha": "2e47a522a31a93487df6ab523ed555aaa2ca017c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-11-17T08:28:55.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-17T08:28:55.000Z", "max_issues_repo_path": "cw_complexes.tex", "max_issues_repo_name": "silky/alg-top-notes", "max_issues_repo_head_hexsha": "2e47a522a31a93487df6ab523ed555aaa2ca017c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cw_complexes.tex", "max_forks_repo_name": "silky/alg-top-notes", "max_forks_repo_head_hexsha": "2e47a522a31a93487df6ab523ed555aaa2ca017c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.7, "max_line_length": 154, "alphanum_fraction": 0.6065088757, "num_tokens": 862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7182349222856748}}
{"text": "\\subsection{Surface Integrals}\r\n\\begin{definition}\r\n    Consider a map $f:\\mathbb R^3\\to\\mathbb R$, then we can define a surface by $\\{\\underline{x}:f(\\underline{x})=0\\}$.\r\n\\end{definition}\r\nIn this case, the normal to the surface at $\\underline{x}$ is $\\nabla f(\\underline{x})$.\r\n\\begin{definition}\r\n    A surface thus defined is called regular if $\\nabla f\\neq \\underline{0}$ everywhere on the surface.\r\n\\end{definition}\r\n\\begin{example}\r\n    Consider $f(x,y,z)=x^2+y^2+z^2-1$, then it defines the unit sphere $S^2$.\r\n    Note that $\\nabla f=(2x,2y,2z)^\\top$ which is certainly normal to $S^2$.\r\n    It is also regular.\\\\\r\n    In spherical polars, it is in the form $f(r,\\theta,\\phi)=r^2-1$, so $\\nabla f=2r\\underline{e_r}=2\\underline{x}$.\r\n\\end{example}\r\nSome surfaces have a boundary, for example a hemisphere.\r\nIn this case we write $\\partial S$ to be the boundary of $S$.\r\nIn particular the boundary of a hemisphere defined by $x^2+y^2+z^2-1=0$ and $z=0$ is the unit circle in the $x-y$ plane.\r\nIf a surface does not have a boundary, we say the boundary is empty.\r\nIn this case, we call such a surface closed.\\\\\r\nOften easiest is to give a local coordinate $u,v$, so $S=\\{\\underline{x}=\\underline{x}(u,v)\\}$.\r\nIn this case, we define a normal as\r\n$$\\frac{\\partial\\underline{x}}{\\partial u}\\times\\frac{\\partial\\underline{x}}{\\partial v}\\left/\\middle\\|\\frac{\\partial\\underline{x}}{\\partial u}\\times\\frac{\\partial\\underline{x}}{\\partial v}\\right\\|$$\r\nassuming it is well-defined.\r\nFor regular surfaces, this is always well-defined.\r\nIt can define the normal consistenly (in terms of sign) or smoothly if the surface is orientable (which we may not define rigourously, sadly).\r\nIf the surface is indeed orientable, we use the convention for the orientation of the boundary curve that when we moving along the boundaries, normal vectors are on our left.\r\n\\begin{example}\r\n    Consider the hemisphere again using spherical polars $S=\\{(\\cos\\phi\\sin\\theta,\\sin\\phi\\sin\\theta,\\cos\\theta):\\theta\\in[0,\\pi/2],\\phi\\in[0,2\\pi]\\}$\r\n    By calculation we get exactly the vector $\\underline{e_r}$ as the normal.\r\n\\end{example}\r\nTo calculate the area of a surface, we want to partition the surface by a rectangularization of the $u-v$ plane.\r\nSo the area of the piece that might look like a parallelogram when we zoom in have an approximated area of $\\delta u\\delta v\\|(\\partial \\underline{x}/\\partial u)\\times(\\partial \\underline{x}/\\partial v)\\|$, so the area is (from intuition):\r\n\\begin{definition}\r\n    The area of the surface $S$ is\r\n    $$\\int_S\\mathrm dS=\\int_S|\\mathrm d\\underline{S}|=\\int_S\\left\\|\\frac{\\partial\\underline{x}}{\\partial u}\\times\\frac{\\partial\\underline{x}}{\\partial v}\\right\\|\\,\\mathrm du\\,\\mathrm dv$$\r\n\\end{definition}\r\nWhere we write $\\mathrm d\\underline{S}=\\underline{n}\\,\\mathrm dS$.\r\n\\begin{example}\r\n    We (yet again) look at the hemisphere paramterized by $S=\\{(R\\cos\\phi\\sin\\theta,R\\sin\\phi\\sin\\theta,R\\cos\\theta):\\theta\\in[0,\\pi/2],\\phi\\in[0,2\\pi]\\}$, so\r\n    $$\\int_S\\mathrm dS=\\int_S|\\mathrm d\\underline{S}|=\\int_SR^2\\sin\\theta\\,\\mathrm d\\theta\\,\\mathrm d\\phi=2\\pi R^2$$\r\n\\end{example}\r\nWe want to use similar method to define the flux integral, which is like the amount of fluid passing though the surface $S$ in unit time.\r\n\\begin{definition}\r\n    We define the integral of $f:\\mathbb R^3\\to\\mathbb R$ to be\r\n    $$\\int_Sf\\,\\mathrm dS=\\iint_Sf(\\underline{x}(u,v))\\left\\|\\frac{\\partial\\underline{x}}{\\partial u}\\times\\frac{\\partial\\underline{x}}{\\partial v}\\right\\|\\,\\mathrm du\\,\\mathrm dv$$\r\n\\end{definition}\r\nSuppose $S:\\underline{x}=\\underline{x}(u,v),S':\\underline{\\tilde{x}}=\\underline{\\tilde{x}}(\\tilde{u},\\tilde{v})$ are two different parameterizations of the same surface $S$, then we have $\\underline{x}(u,v)=\\underline{\\tilde{x}}(\\tilde{u}(u,v),\\tilde{v}(u,v))$, where we assume that $\\tilde{u},\\tilde{u}$ are smooth bijections with smooth inverse.\r\nSo we have, by calculus,\r\n$$\\frac{\\partial\\underline{x}}{\\partial u}\\times\\frac{\\partial\\underline{x}}{\\partial v}=\\frac{\\partial\\underline{\\tilde{x}}}{\\partial\\tilde{u}}\\times\\frac{\\partial\\underline{\\tilde{x}}}{\\partial\\tilde{v}}\\frac{\\partial (\\tilde{u},\\tilde{v})}{\\partial (u,v)}$$\r\nSo\r\n\\begin{align*}\r\n    \\int_S f\\,\\mathrm dS&=\\iint_Sf(\\underline{x}(u,v))\\left\\|\\frac{\\partial\\underline{x}}{\\partial u}\\times\\frac{\\partial\\underline{x}}{\\partial v}\\right\\|\\,\\mathrm du\\,\\mathrm dv\\\\\r\n    &=\\iint_{S}f(\\underline{\\tilde{x}}(\\tilde{u}(u,v),\\tilde{v}(u,v)))\\left\\|\\frac{\\partial\\underline{\\tilde{x}}}{\\partial\\tilde{u}}\\times\\frac{\\partial\\underline{\\tilde{x}}}{\\partial\\tilde{v}}\\frac{\\partial (\\tilde{u},\\tilde{v})}{\\partial (u,v)}\\right\\|\\,\\mathrm du\\,\\mathrm dv\\\\\r\n    &=\\iint_{S}f(\\underline{\\tilde{x}}(\\tilde{u}(u,v),\\tilde{v}(u,v)))\\left\\|\\frac{\\partial\\underline{\\tilde{x}}}{\\partial\\tilde{u}}\\times\\frac{\\partial\\underline{\\tilde{x}}}{\\partial\\tilde{v}}\\right\\|\\left|\\frac{\\partial (\\tilde{u},\\tilde{v})}{\\partial (u,v)}\\right|\\,\\mathrm du\\,\\mathrm dv\\\\\r\n    &=\\iint_{S'}f(\\underline{\\tilde{x}}(\\tilde{u},\\tilde{v}))\\left\\|\\frac{\\partial\\underline{\\tilde{x}}}{\\partial \\tilde{u}}\\times\\frac{\\partial\\underline{\\tilde{x}}}{\\partial\\tilde{v}}\\right\\|\\,\\mathrm d\\tilde{u}\\,\\mathrm d\\tilde{v}\\\\\r\n    &=\\int_{S'} f\\,\\mathrm dS'\r\n\\end{align*}\r\nJust as the Fundamental Theorem of Calculus told us that the integration over a derivative depends only on its endpoints, the integral over a surface of some sort of derivative will only depend on the boundary of the surface.\r\n\\footnote{In fact, this is true in manifolds of even higher dimensions, which is known as Stokes' Theorem.}\r\nThen, for a vector field $\\underline{F}$, we define the flux integral of it over the surface $S$ by\r\n$$\\int_S\\underline{F}\\cdot\\mathrm d\\underline{S}=\\int_S\\underline{F}\\cdot\\underline{n}\\,\\mathrm dS$$", "meta": {"hexsha": "a995a3b0b3ef1010d9f93f89af43ce915837cbfb", "size": 5777, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/surf.tex", "max_stars_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_stars_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3/surf.tex", "max_issues_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_issues_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3/surf.tex", "max_forks_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_forks_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 94.7049180328, "max_line_length": 348, "alphanum_fraction": 0.6951705037, "num_tokens": 1866, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034369, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.7182349094936783}}
{"text": "\\input{Lecture-header}\n\\begin{document}\n\\providecommand{\\currentLecture}{8}\n\n\\lect{\\semester}{Angles}{1}{% begin lecture\n%DesiredLectureName: Angles\n\\section{Angles}\n\\subsection{The Unit circle}\n\\input{../../modules/trigonometry/unit-circle-def}\n\\subsection{Three Meanings of Angle}\n\\input{../../modules/trigonometry/angle-three-meanings}\n\\input{../../modules/trigonometry/angle-geometric-definition}\n\\input{../../modules/trigonometry/angle-measure-of-geometric-angle-definition}\n\\input{../../modules/trigonometry/circle-arclength-from-general-definition-note}\n\\input{../../modules/trigonometry/circle-arclength}\n\\input{../../modules/trigonometry/circle-arclength-ex1}\n\\subsection{Two Meanings of Rotation}\n\\input{../../modules/trigonometry/rotation-two-meanings}\n\\input{../../modules/trigonometry/continuous-rotation-definition}\n\\input{../../modules/trigonometry/angle-measure-of-continuous-rotation}\n\\input{../../modules/trigonometry/angle-equivalence}\n\\subsection{Angles and the Coordinate System}\n\\input{../../modules/trigonometry/angle-coordinate-system}\n\\subsection{Radians and Degrees}\n\\input{../../modules/trigonometry/angles-measurement-units}\n\\input{../../modules/trigonometry/convert-radians-degrees-ex1}\n\\input{../../modules/trigonometry/circle-arclength-ex2}\n\\input{../../modules/trigonometry/frequently-encountered-angles}\n\\input{../../freecalc/modules/trigonometry/coterminal-angles}\n\\input{../../modules/trigonometry/coterminal-angles-example-1}\n\\input{../../modules/trigonometry/complementary-angles}\n\\input{../../modules/trigonometry/supplementary-angles}\n\\subsection{Area cut off by an angle}\n\\input{../../modules/trigonometry/area-sector}\n}\n\n\\lect{\\semester}{Lecture 2}{2}{% begin lecture\n%DesiredLectureName: Trigonometry_Definitions\n\\section{Trigonometry}\n\\subsection{Definition of the Trigonometric Functions}\n\\input{../../freecalc/modules/trigonometry/trig-functions-definition}\n\\input{../../freecalc/modules/trigonometry/similar-triangles-def}\n\\input{../../freecalc/modules/trigonometry/similar-triangles-same-side-ratios}\n\\input{../../freecalc/modules/trigonometry/trig-functions-and-right-angle-triangles}\n\\subsection{Basic Computations with Trigonometric Functions}\n\\input{../../freecalc/modules/trigonometry/trig-functions-example3}\n\\input{../../freecalc/modules/trigonometry/trig-functions-example2}\n\\input{../../freecalc/modules/trigonometry/triangle-angles-sum-to-180-degrees}\n\\input{../../freecalc/modules/trigonometry/trig-functions-of-45-degrees}\n\\input{../../freecalc/modules/trigonometry/trig-functions-of-30-60-degrees}\n\\subsection{Reference Angles}\n\\input{../../freecalc/modules/trigonometry/reference-angles}\n\\input{../../freecalc/modules/trigonometry/trig-example}\n\\input{../../freecalc/modules/trigonometry/frequently-encountered-sines-cosines}\n\\subsection{Geometric Interpretation of the Trigonometric Functions}\n\\input{../../freecalc/modules/trigonometry/trig-functions-unit-circle}\n\\subsection{Periodicity and Symmetries of the Trig Functions}\n\\input{../../freecalc/modules/trigonometry/trig-functions-even-odd}\n\\input{../../freecalc/modules/trigonometry/trig-functions-periodicity}\n\\input{../../freecalc/modules/trigonometry/trig-identity-definition}\n\\input{../../freecalc/modules/trigonometry/trig-identities-pythagorean}\n%\\input{../../modules/trigonometry/trig-identities-angle-sum-summary}\n}\n\n\\lect{\\semester}{Lecture 3}{3}{% begin lecture\n%DesiredLectureName: Trigonometry_Cofunction_Identities_Angle_Sum_Formulas\n\\section{Cofunction identities}\n\\input{../../modules/trigonometry/cofunction-identities-part1}\n\\input{../../modules/trigonometry/cofunction-identities-part2}\n\\input{../../modules/trigonometry/cofunction-identities-memorization-aid}\n\\section{Trigonometric Functions of Sums of Angles}\n\\input{../../modules/trigonometry/similar-triangles-def}\n\\input{../../modules/trigonometry/similar-triangles-same-side-ratios}\n\\input{../../modules/trigonometry/trig-angle-sum-formulas-geometric-proof}\n\\input{../../modules/trigonometry/trig-angle-sum-formulas-geometric-proof-part2}\n\\input{../../modules/trigonometry/trig-angle-sum-formulas-geometric-proof-part3}\n\\input{../../modules/trigonometry/trig-angle-sum-formulas-to-find-sin-cos-ex1}\n\\input{../../modules/trigonometry/trig-angle-sum-formulas-sums-pi-over-2-ex1}\n\\input{../../modules/trigonometry/trig-angle-sum-formulas-sums-pi-over-2-ex2}\n\\input{../../modules/trigonometry/trig-angle-sum-formulas-tan-is-pi-periodic}\n\\input{../../modules/trigonometry/trig-angle-sum-formulas-to-prove-pythagorean-identity}\n\\input{../../modules/trigonometry/tan-angle-sum-formula}\n\\section{Double Angle Formulas}\n\\input{../../modules/trigonometry/double-angle-formulas}\n\\input{../../modules/trigonometry/double-angle-formulas-proof}\n\\input{../../modules/trigonometry/half-angle-formula-ex1}\n\\input{../../modules/trigonometry/power-reducing-formulas}\n\\input{../../modules/trigonometry/power-reducing-formulas-ex1}\n}\n\n\\lect{\\semester}{Lecture 4}{4}{% begin lecture\n%DesiredLectureName: Complex-numbers-basics\n\\section{Complex Numbers}\n\\input{../../modules/complex-numbers/complex-numbers-definition}\n\\input{../../modules/complex-numbers/complex-numbers-addition-multiplication-example-1}\n\\input{../../modules/complex-numbers/complex-numbers-multiplication-example-2}\n\\input{../../modules/complex-numbers/overview-of-numbers}\n}\n\n\\lect{\\semester}{Lecture 5}{5}{% begin lecture\n%DesiredLectureName: Trigonometric_Identities\n\\section{Trigonometric Identities}\n\\subsection{Trigonometric Identities and Complex Numbers}\n\\input{../../modules/trigonometry/trig-Euler-formula}\n\\input{../../modules/trigonometry/trig-using-euler-formula}\n\\subsection{Trigonometric Identities without Complex Numbers}\n\\input{../../modules/trigonometry/trig-identity-definition}\n\\input{../../modules/trigonometry/trig-identity-proving}\n\\input{../../modules/trigonometry/trig-identity-types}\n\\subsection{Trig Identities Using $\\sin^2\\theta+\\cos^2\\theta=1$}\n\\input{../../modules/trigonometry/trig-identities-pythagorean-ex1}\n\\input{../../modules/trigonometry/trig-identities-pythagorean-ex2}\n\\input{../../modules/trigonometry/trig-identities-pythagorean-ex3}\n\\input{../../modules/trigonometry/trig-identities-pythagorean-ex4}\n\\subsection{Trig Identities Using the Angle Sum Formulas}\n\\input{../../modules/trigonometry/trig-identities-example-1}\n\\input{../../modules/trigonometry/trig-identities-example-3}\n\\input{../../modules/trigonometry/trig-identities-example-3-with-Eulers-Formula}\n\\input{../../modules/trigonometry/trig-identities-example-2}\n\\input{../../modules/trigonometry/trig-identities-strategy-note}\n\\subsection{Trig Identities Exercises}\n\\input{../../modules/trigonometry/trig-identities-exercises-1}\n}\n\n\\lect{\\semester}{Lecture 6}{6}{% begin lecture\n%DesiredLectureName: Inverse_Functions\n\\section{Inverse Functions}\n\\subsection{One-to-one Functions}\n\\input{../../modules/inverse-functions/one-to-one-def}\n\\input{../../modules/inverse-functions/horizontal-line-test}\n\\subsection{The Definition of the Inverse of $f$}\n\\input{../../modules/inverse-functions/inverse-function-def}\n\\input{../../modules/inverse-functions/inverse-notation-warning}\n\\input{../../modules/inverse-functions/inverse-function-equations}\n\\input{../../modules/inverse-functions/inverse-function-solve-for-version2}\n\\input{../../modules/inverse-functions/guess-and-check}\n\\input{../../modules/inverse-functions/inverse-function-graph}\n\\input{../../modules/inverse-functions/inverse-function-ex5}\n\\input{../../modules/inverse-functions/inverse-function-solve-for-ex1-freeCalc}\n\\input{../../modules/inverse-functions/inverse-function-solve-for-ex3-freeCalc}\n}\n\n\\lect{\\semester}{Lecture 7}{7}{% begin lecture\n%DesiredLectureName: Trigonometric_Function_Graphs_Inverse_Trig\n\\section{Graphs of the Trigonometric Functions}\n\\subsection{Graphs of $\\sin $ and $\\cos$}\n\\input{../../freecalc/modules/trigonometry/graph-sin-extended}\n\\input{../../freecalc/modules/trigonometry/graph-cos-extended}\n\\input{../../freecalc/modules/trigonometry/graphs-sin-and-cos}\n\\subsection{Graph of $a\\sin(bx-c)$}\n\\input{../../freecalc/modules/trigonometry/graphs-asinbx-plus-c}\n\\subsection{Graphs of $\\tan, \\cot, \\sec, \\csc $}\n\\input{../../freecalc/modules/trigonometry/graph-tan-extended}\n\\input{../../freecalc/modules/trigonometry/graphs-tan-and-cot}\n\\input{../../freecalc/modules/trigonometry/graphs-sec-and-csc}\n\\section{Inverse Trigonometric Functions}\n\\input{../../freecalc/modules/inverse-trig/arcsin-def}\n\\input{../../freecalc/modules/inverse-trig/arcsin-frequently-encountered-example-1}\n\\input{../../freecalc/modules/inverse-trig/tan-arcsin-example-1}\n\\input{../../freecalc/modules/inverse-trig/arcsin-sin-ex1}\n\\input{../../freecalc/modules/inverse-trig/arcsin-sin-ex2}\n\\input{../../freecalc/modules/inverse-trig/arcsin-properties}\n\\input{../../freecalc/modules/inverse-trig/arccos-def}\n\\input{../../freecalc/modules/inverse-trig/arccos-properties}\n\\input{../../freecalc/modules/inverse-trig/arccos-cos-example-1}\n%\\section{Some applied trigonometric problems}\n\\input{../../freecalc/modules/trigonometry/text-problem-visibility-horizon-earth-1}\n%\\input{../../freecalc/modules/trigonometry/text-problem-visibility-mountain-earth-1}\n\\subsection{Trigonometric Functions with Inverse Trig Arguments}\n\\input{../../freecalc/modules/inverse-trig/trig-applied-to-inverse-trig-ex1}\n\\input{../../freecalc/modules/inverse-trig/trig-applied-to-inverse-trig-ex2}\n\\input{../../freecalc/modules/inverse-trig/arctan-def}\n\\input{../../freecalc/modules/inverse-trig/arctan-ex3}\n\\input{../../freecalc/modules/inverse-trig/arcsec-intro}\n\\input{../../freecalc/modules/inverse-trig/arcsec-def}\n}\n\n\\lect{\\semester}{Lecture 8}{8}{% begin lecture\n%DesiredLectureName: Trig_Equations_Inequalities\n\\section{Trigonometric equations and inequalities}\n\\input{../../freecalc/modules/trigonometry/trig-equations-intro}\n\\subsection{The Equations $\\sin x = A$, $\\cos x = B$}\n\\input{../../freecalc/modules/trigonometry/trig-equations-sin-x-equals-const-algebraic-1}\n\\input{../../freecalc/modules/trigonometry/trig-equations-cos-x-equals-const-algebraic-1}\n\\input{../../freecalc/modules/trigonometry/trig-equations-sin-x-equals-const-general-1}\n\\subsection{Equations that reduce to $\\sin x = A$, $\\cos x = B$}\n\\input{../../freecalc/modules/trigonometry/trig-equations-example}\n\\input{../../freecalc/modules/trigonometry/trig-equations-example-2}\n\\input{../../freecalc/modules/trigonometry/trig-equations-strategy}\n\\section{Product-to-Sum Formulas}\n\\input{../../freecalc/modules/trigonometry/product-to-sum-formulas}\n\\input{../../freecalc/modules/trigonometry/sum-to-product-formulas}\n\\input{../../freecalc/modules/trigonometry/sum-to-product-formulas-ex1}\n\\section{Trigonometric inequalities}\n\\input{../../freecalc/modules/trigonometry/sin-geq-leq-constants-example-1}\n\\input{../../freecalc/modules/inequalities-polynomial/trig-inequality-reduced-to-quadratic-1}\n}\n\n\\lect{\\semester}{Lecture 9}{9}{% begin lecture\n%DesiredLectureName: Law_of_Sines_Law_of_Cosines_Trig_Applications\n\\section{Law of sines}\n\\input{../../modules/trigonometry/area-of-triangle-from-base-and-height}\n\\input{../../modules/trigonometry/area-of-triangle-from-two-sides-and-angle}\n\\input{../../modules/trigonometry/law-of-sines}\n\\input{../../modules/trigonometry/law-of-sines-example-1}\n\\section{Law of cosines}\n\\input{../../modules/trigonometry/law-of-cosines}\n\\input{../../modules/trigonometry/law-of-cosines-solve-triangle-example-1}\n}\n\n\\lect{\\semester}{Lecture 10}{10}{\n%DesiredLectureName: Exponents\n\\section{Exponents}\n\\input{../../modules/exponential-functions/exponential-properties}\n\\subsection{Two ways to define exponents}\n\\input{../../modules/exponential-functions/exponential-function-def-various-approaches}\n\\input{../../modules/exponential-functions/exponential-function-def}\n\\subsection{Basic properties}\n\\input{../../modules/exponential-functions/exponential-function-graphs}\n\\input{../../modules/exponential-functions/exponential-versus-polynomial}\n\\input{../../modules/exponential-functions/exponential-function-ex-sketch}\n\\input{../../modules/exponential-functions/exponential-one-to-one-over-reals}\n\\subsection{The Natural Exponential Function}\n\\input{../../modules/exponential-functions/natural-exponential-intro}\n\\input{../../modules/logarithms/e-limit-no-lim-notation}\n\\input{../../modules/exponential-functions/compound-interest}\n\\input{../../modules/logarithms/e-limit-compound-interest-example-1}\n\\input{../../modules/logarithms/e-limit-compound-interest-example-2}\n\\input{../../modules/logarithms/e-limit-compound-interest-rule-of-72}\n}\n\n\\lect{\\semester}{Lecture 11}{11}{% begin lecture\n%DesiredLectureName: Logarithm_Basics\n\\section{Logarithmic Functions}\n\\subsection{Logarithm basics}\n\\input{../../modules/logarithms/logarithm-def}\n\\input{../../modules/logarithms/logarithm-def-ex1}\n\\input{../../modules/logarithms/log-and-exp}\n\\input{../../modules/logarithms/logarithm-graphs}\n\\subsection{Natural Logarithms}\n\\input{../../modules/logarithms/natural-logarithm-def}\n\\input{../../modules/logarithms/log-notation-note}\n\\input{../../modules/logarithms/log-notation-summary}\n\\subsection{Shifting graphs of logarithmic functions}\n\\input{../../modules/logarithms/natural-logarithm-def-ex8}\n\\section{Basic Operations with Logarithms}\n\\input{../../modules/logarithms/logarithm-properties}\n\\input{../../modules/logarithms/logarithm-properties-compute-arbitrary-base-via-ln-example-1}\n\\input{../../modules/logarithms/logarithm-properties-ex2}\n\\input{../../modules/logarithms/logarithm-properties-ex4}\n\\input{../../modules/logarithms/logarithm-properties-ex6}\n\\input{../../modules/logarithms/logarithm-properties-ex7}\n\\input{../../modules/logarithms/logarithm-properties-extra}\n\\input{../../modules/logarithms/logarithm-properties-ex5}\n\\input{../../modules/logarithms/logarithm-evaluate-log-linear-combination-multiple-techniques-1}\n\\input{../../modules/logarithms/logarithm-properties-proofs}\n}\n\n\\lect{\\semester}{Lecture 12}{12}{% begin lecture\n%DesiredLectureName: Equations_involving_logarithms_and_exponents\n\\section{Equations involving logarithms}\n\\input{../../modules/logarithms/logarithms-equations-ex1}\n\\input{../../modules/logarithms/logarithms-equations-ex2}\n\\section{Equations involving exponents}\n\\input{../../modules/exponential-functions/exponential-equation1}\n\\input{../../modules/logarithms/exponential-equation-basic-arbitrary-base-1.tex}\n\\input{../../modules/logarithms/exponential-equation-basic-two-exponents-1}\n\\input{../../modules/logarithms/exponential-equation-basic-two-different-exponents-1}\n\\input{../../modules/logarithms/natural-logarithm-def-ex5}\n\\input{../../modules/exponential-functions/exponential-word-problem1}\n\\input{../../modules/exponential-functions/exponential-equation2}\n\\input{../../modules/logarithms/exponential-equation-quadratic-natural-base-1}\n\\input{../../modules/logarithms/exponential-equation-quadratic-arbitrary-base-1}\n\\input{../../modules/logarithms/exponential-equation-quadratic-arbitrary-base-2}\n\\section{Inverse function problems and exponents}\n\\input{../../modules/inverse-functions/inverse-function-solve-for-ex2-freeCalc}\n\\section{Basic exponential inequalities}\n\\input{../../modules/logarithms/exponential-inequality-basic-1}\n}\n\n\\lect{\\semester}{Lecture 13}{13}{% begin lecture\n%DesiredLectureName: Exponential_and_Logarithmic_models\n\\section{Models Involving Logarithms and Exponents}\n\\input{../../modules/logarithms/models-involving-logarithms-and-exponents}\n\\input{../../modules/exponential-growth-and-decay/exponential-growth-decay-model}\n\\input{../../modules/exponential-growth-and-decay/exponential-growth-model-ex1}\n\\input{../../modules/exponential-growth-and-decay/exponential-decay-model-ex1}\n\\input{../../modules/exponential-growth-and-decay/logistic-growth-model}\n\\input{../../modules/exponential-growth-and-decay/logistic-growth-model-ex1}\n\\input{../../modules/logarithms/logarithmic-models}\n\\input{../../modules/logarithms/logarithmic-models-ex1}\n}\n\n\\lect{\\semester}{Lecture 14}{14}{\n%DesiredLectureName: Factoring_polynomials_and_polynomial_inequalities\n\\section{Factoring quadratics}\n\\input{../../modules/polynomial-factorization/factorization-meaning-1}\n\\input{../../modules/quadratic-functions/factoring-quadratics-theory-1}\n\\input{../../modules/quadratic-functions/factoring-quadratics-example-Vieta-guessing-or-formula-1}\n\\input{../../modules/quadratic-functions/vietas-formulas}\n\\input{../../modules/quadratic-functions/factoring-quadratics-example-example-Vieta-guessing-1}\n\\input{../../modules/quadratic-functions/factoring-quadratics-example-by-formula-1}\n\\input{../../modules/quadratic-functions/factoring-quadratics-example-by-formula-no-real-roots-1}\n\\section{Factorization overview}\n\\input{../../modules/polynomial-factorization/factorization-examples-no-theory-1}\n\\input{../../modules/polynomial-factorization/fundamental-theorem-of-algebra-statement}\n\\input{../../modules/polynomial-factorization/factorization-examples-1}\n\\input{../../modules/polynomial-factorization/factorization-algebraic-overview-1}\n\\input{../../modules/polynomial-factorization/factorization-over-basic-three-fields-explanation}\n\\input{../../modules/polynomial-factorization/factorization-over-rationals}\n%DesiredLectureName: Factoring_cubics_with_rational_root\n\\section{Polynomial division}\n\\input{../../modules/polynomial-factorization/polynomial-division-example-1}\n\\input{../../modules/polynomial-factorization/polynomial-division-use-to-factor-1}\n\\section{Factoring cubics with rational root}\n\\input{../../modules/polynomial-factorization/solve-cubic-rational-roots-using-graph-1}\n\\input{../../modules/polynomial-factorization/solve-cubic-one-rational-two-real-roots-from-graph-1}\n\\input{../../modules/polynomial-factorization/solve-cubic-one-rational-two-complex-roots-from-graph-1}\n\\section{Polynomial inequalities}\n%DesiredLectureName: Polynomial_inequalities\n\\input{../../freecalc/modules/inequalities-polynomial/inequality-quadratic-1}\n\\input{../../freecalc/inequalities-polynomial/inequality-cubic-three-rational-roots-1}\n}\n\n\\lect{\\semester}{Lecture 98}{98}{\n%DesiredLectureName: Graphing-Equations-Circle-Equation\n\\section{Graph of an equation}\n\\input{../../modules/equation-graph/equation-graph-def}\n\\input{../../modules/equation-graph/equation-check-solution-1}\n\\input{../../modules/equation-graph/equation-check-solution-2}\n\\input{../../modules/equation-graph/graph-equation-when-one-variable-is-function-of-the-other}\n\\youWillNotBeTested\n\\input{../../modules/equation-graph/graph-equation-implicit-computer-algorithm}\n\\input{../../modules/equation-graph/graph-intercepts}\n\\input{../../modules/equation-graph/find-graph-intercepts-example-1}\n\\input{../../modules/equation-graph/find-graph-intercepts-example-2}\n\\input{../../modules/equation-graph/graph-symmetries}\n\\input{../../modules/equation-graph/circle-equation}\n\\input{../../modules/quadratic-functions/completing-the-square}\n\\input{../../modules/quadratic-functions/completing-the-square-example-1}\n\\input{../../modules/equation-graph/find-center-radius-from-circle-equation-1}\n\\input{../../modules/equation-graph/find-circle-equation-from-radius-and-point-1}\n}% end lecture\n\n\\lect{\\semester}{Lecture 99}{99}{\n%DesiredLectureName: Quadratic_Functions\n\\section{Quadratic Functions}\n\\subsection{Standard Form}\n\\input{../../freecalc/modules/quadratic-functions/definition-quadratic-function}\n\\input{../../freecalc/modules/quadratic-functions/completing-the-square-example-1}\n\\input{../../freecalc/modules/quadratic-functions/completing-the-square}\n\\input{../../freecalc/modules/quadratic-functions/discriminant-and-standard-form-quadratic}\n\\subsection{Geometric Features}\n\\input{../../freecalc/modules/quadratic-functions/quadratic-function-geometric-features}\n\\input{../../freecalc/modules/quadratic-functions/write-equation-parabola-given-vertex-and-point-example-1}\n\\subsection{Quadratic Equations}\n\\input{../../freecalc/modules/quadratic-functions/quadratic-equation-solution}\n\\input{../../freecalc/modules/quadratic-functions/quadratic-equation-solution-example-1}\n\\input{../../freecalc/modules/quadratic-functions/quadratic-equation-solution-example-2}\n\\input{../../freecalc/modules/quadratic-functions/quadratic-equation-solution-example-3}\n\\subsection{Vieta's Formulas}\n\\input{../../freecalc/modules/quadratic-functions/dicriminant-from-roots-formula}\n\\input{../../freecalc/modules/quadratic-functions/vietas-formulas}\n\\subsection{Factoring quadratics}\n\\input{../../freecalc/modules/quadratic-functions/factoring-quadratics-theory-1}\n\\input{../../freecalc/modules/quadratic-functions/factoring-quadratics-example-Vieta-guessing-or-formula-1}\n\\input{../../freecalc/modules/quadratic-functions/vietas-formulas}\n\\input{../../freecalc/modules/quadratic-functions/factoring-quadratics-example-example-Vieta-guessing-1}\n\\input{../../freecalc/modules/quadratic-functions/factoring-quadratics-example-by-formula-1}\n\\input{../../freecalc/modules/quadratic-functions/factoring-quadratics-example-by-formula-no-real-roots-1}\n\\subsection{Plotting Quadratics}\n\\input{../../freecalc/modules/quadratic-functions/plot-roughly-by-hand-parabola-recipe}\n\\input{../../freecalc/modules/quadratic-functions/plot-roughly-by-hand-parabola-example-1}\n\\input{../../freecalc/modules/quadratic-functions/quadratic-find-parameters-to-ensure-quadratic-positive-1}\n\\subsection{Maxima and Minima}\n\\input{../../freecalc/modules/quadratic-functions/quadratic-function-minimum-example-1}\n\\input{../../freecalc/modules/quadratic-functions/quadratic-function-maximum-or-minimum}\n\\input{../../freecalc/modules/quadratic-functions/quadratic-max-min-word-problem-1}\n}\n\n\\lect{\\semester}{Lecture 100}{100}{\n%DesiredLectureName: Cartesian_Coordinates_Vector_Addition_Scalar_Product\n\\section{Cartesian coordinate system}\n\\input{../../modules/coordinate-systems/cartesian-coordinates-2d-part1}\n\\input{../../modules/coordinate-systems/cartesian-coordinates-2d-part2}\n\\input{../../modules/coordinate-systems/cartesian-coordinates-2d-part3}\n\\input{../../modules/coordinate-systems/cartesian-coordinates-2d-plot-points-example}\n\n\\subsection{The Pythagorean Theorem, Euclidean Distance}\n\\input{../../modules/coordinate-systems/pythagorean-theorem}\n\\input{../../modules/coordinate-systems/distance-in-cartesian-coordinates-2d}\n\\input{../../modules/coordinate-systems/distance-2d-example-1}\n\\input{../../modules/coordinate-systems/distance-2d-check-if-triangle-right-angled-1}\n\\subsection{Vectors}\n\\input{../../modules/vectors/vector-addition-and-scalar-mult-from-cartesian-system-2d-part1}\n\\input{../../modules/vectors/vector-addition-and-scalar-mult-from-cartesian-system-2d-part2}\n\\input{../../modules/vectors/vector-addition-and-scalar-mult-from-cartesian-system-2d-part3}\n\\input{../../modules/vectors/vector-addition-and-scalar-mult-from-cartesian-system-2d-part4-translation-definition}\n\\input{../../modules/vectors/vectors-translation-of-point-2d-example-1}\n\\subsection{Segments, Midpoints}\n\\input{../../modules/coordinate-systems/segment-between-two-points}\n\\input{../../modules/coordinate-systems/midpoint-definition-verification-2d}\n\\input{../../modules/coordinate-systems/find-midpoint-1}\n}% end lecture\n\n\\lect{\\semester}{Lecture 101}{101}{\n%DesiredLectureName: Lines\n\\section{Lines}\n\\input{../../modules/coordinate-systems/r-two-r-n}\n\\input{../../modules/lines-2d/line-definition}\n\\input{../../modules/lines-2d/line-from-two-points}\n\\input{../../modules/lines-2d/line-from-two-points-formulas-and-slope-form}\n\\subsection{Slope-intercept Form}\n\\input{../../modules/lines-2d/line-slope-intercept-form}\n\\input{../../modules/lines-2d/line-slope-intercept-form-explanation}\n\\input{../../modules/lines-2d/compare-linear-functions-via-slope}\n\n\\input{../../modules/lines-2d/vertical-line-and-slope}\n\\input{../../modules/lines-2d/line-plot-from-equation-example-1}\n\n\\input{../../modules/lines-2d/line-from-two-points-example-1}\n\\input{../../modules/lines-2d/line-from-point-and-slope-example-1}\n\n\\subsection{Line intersection}\n\\input{../../modules/lines-2d/line-intersection}\n\\input{../../modules/lines-2d/line-intersection-example-1}\n\\input{../../modules/lines-2d/parallel-lines-equal-slopes}\n}% end lecture\n\n\\lect{\\semester}{Lecture 102}{102}{\n%DesiredLectureName: Functions\n\\section{The Definition of a Function}\n\\input{../../modules/functions-basics/function-def-uses-arrows}\n\\input{../../modules/functions-basics/function-def}\n\\input{../../modules/functions-basics/function-def-note-on-f-of-x-notation}\n\\input{../../modules/functions-basics/function-formulas-and-bound-variables}\n\\input{../../modules/functions-basics/function-formula-understanding-example-1}\n\\subsection{Function Domains}\n\\input{../../modules/functions-basics/domains}\n\\input{../../modules/functions-basics/domains-example-1}\n\n\\subsection{The Vertical Line Test}\n\\input{../../modules/precalculus/vertical-line-test}\n\\subsection{Piecewise Defined Functions}\n\\input{../../modules/precalculus/function-piecewise}\n\\input{../../modules/precalculus/absolute-value}\n\\input{../../modules/precalculus/piecewise-formula}\n\\input{../../modules/precalculus/piecewise-ex1}\n\\input{../../modules/precalculus/piecewise-ex2}\n\\subsection{Zeros of a function}\n\\input{../../modules/functions-basics/zeroes-of-a-function}\n\\input{../../modules/functions-basics/zeroes-of-function-from-formula-1}\n\\input{../../modules/functions-basics/f-of-x-equals-g-of-x-algebra-example-1}\n\\input{../../modules/functions-basics/finding-when-f-of-x-equals-g-of-x}\n\\subsection{Symmetry}\n\\input{../../modules/precalculus/even-and-odd}\n\\subsection{Increasing and Decreasing Functions}\n\\input{../../modules/precalculus/increasing-decreasing}\n\n}% end lecture\n\n\\lect{\\semester}{Lecture 103}{103}{\n%DesiredLectureName: Functions\n\\section{A Catalog of Essential Functions}\n\\subsection{Linear Functions}\n\\input{../../modules/lines-2d/linear-functions}\n\\input{../../modules/lines-2d/linear-functions-examples-1}\n\\subsection{Polynomials}\n\\input{../../modules/precalculus/polynomials}\n\\subsection{Power Functions}\n\\input{../../modules/precalculus/power-functions-def}\n\\input{../../modules/precalculus/root-functions}\n\\input{../../modules/precalculus/reciprocal-function}\n\\subsection{Rational Functions}\n\\input{../../modules/precalculus/rational-functions}\n\\subsection{Algebraic Functions}\n\\input{../../modules/precalculus/algebraic-functions}\n\\subsection{Transcendental Functions}\n\\input{../../modules/precalculus/transcendental-functions-version2}\n\\subsection{Miscellaneous}\n\\input{../../modules/continuity/greatest-integer-function}\n\\section{New Functions from Old Functions}\n\\input{../../modules/precalculus/combinations-functions}\n\\input{../../modules/precalculus/composition-functions}\n\\input{../../modules/precalculus/composition-example}\n\\input{../../modules/precalculus/composition-example-2}\n}\n\n\\lect{\\semester}{Lecture 104}{104}{\n\\section{Composing Functions with Linear Transformations}\n\\input{../../modules/function-graph-linear-transformations/transformations-shifts}\n\\input{../../modules/function-graph-linear-transformations/transformations-shifts-example}\n\\input{../../modules/function-graph-linear-transformations/transformations-magnifications}\n\\input{../../modules/function-graph-linear-transformations/transformations-horizontal-stretches}\n\\section{Graphing Absolute Value of a Function}\n\\input{../../modules/function-graph-linear-transformations/transformations-absolute-value}\n}\n\\end{document}\n", "meta": {"hexsha": "f1f176c4167d565c33d663d9ad1a7eca69d710f4", "size": 27308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX-materials/Curriculum-200-Precalculus/Lecture.tex", "max_stars_repo_name": "tmilev/courses_calculator", "max_stars_repo_head_hexsha": "dd67435dd7a25c59afcefb9ef3b1f004246eca81", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "LaTeX-materials/Curriculum-200-Precalculus/Lecture.tex", "max_issues_repo_name": "tmilev/courses_calculator", "max_issues_repo_head_hexsha": "dd67435dd7a25c59afcefb9ef3b1f004246eca81", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LaTeX-materials/Curriculum-200-Precalculus/Lecture.tex", "max_forks_repo_name": "tmilev/courses_calculator", "max_forks_repo_head_hexsha": "dd67435dd7a25c59afcefb9ef3b1f004246eca81", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.7254509018, "max_line_length": 115, "alphanum_fraction": 0.7762926615, "num_tokens": 7083, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7182348997055884}}
{"text": "% jam 2004-09-10\n\n\\section{Vector spaces}\n\\label{sec:vector-spaces}\n\nMy approach to vector spaces is largely based on\nthe texts I used as a college freshman for linear algebra and\nmultivariate calculus: Halmos \\cite{halmos1958finite}\nand Spivak \\cite{spivak-1965}.\n\nSome useful definitions/identities:\n\nLet $\\Vspace$ be an $n$-dimensional real inner product space.\nLet $\\v, \\w \\in \\Vspace$.\n\n\\begin{itemize}\n\\item The inner (dot) product on $\\Reals^n$:\n\\begin{equation}\n\\v \\bullet \\w \\; \\equiv \\; \\sum_{i=0}^{n-1} v_i w_i\n\\end{equation}\n\n\\item The euclidean ($l_2$) norm:\n\\begin{equation}\n\\| \\v \\|^2 \\; \\equiv \\; \\v \\bullet \\v\n\\end{equation}\n\n\\item $\\theta(\\v,\\w)$ is the angle between $\\v$ and $\\w$\nand is defined by:\n\\begin{eqnarray}\n\\v \\bullet \\w \\; = \\; \\| \\v \\| \\| \\w \\| \\cos(\\theta(\\v,\\w))\n\\\\\n\\theta(\\v,\\w)\n\\; \\equiv \\;\n\\cos^{-1} \\left(\\frac{ \\v \\bullet \\w }{\\| \\v \\| \\| \\w \\| } \\right)\n\\nonumber\n\\end{eqnarray}\n\n\\item The tensor (outer) product:\n\nLet $\\v, \\u \\in \\Vspace, \\w \\in \\Wspace.$\n$\\w \\otimes \\v$ is a rank 1 linear map\nfrom $\\Vspace$ to $\\Wspace$, defined by:\n\\begin{equation}\n(\\w \\otimes \\v)(\\u) \\; \\equiv \\; \\w (\\v \\bullet \\u)\n\\end{equation}\n\nNote: this is an abuse of the usual definition of tensor product $\\otimes$.\nThis operation, which takes a pair of vectors and returns a linear map,\nis more conventionally referred to as the 'outer product',\nand written $\\w \\v^{\\dagger}$.\nHowever, because I am working in spaces other than $\\Reals^n$\n(eg. $\\Lspace(\\Vspace,\\Wspace)$, the space of linear maps\nbetween 2 vector spaces),\nI want to avoid notations that suggest thinking in terms\nof 'row' and 'column' vectors.\n\nThe following is a useful identity.\nIf $\\t \\in \\Tspace$, $\\u, \\v \\in \\Vspace$, and $\\w \\in \\Wspace.$\nthen\n\\begin{equation}\n\\label{eq:tensor-dot}\n(\\t \\otimes \\u) (\\v \\otimes \\w)(\\u) = (\\u \\bullet \\v) (\\t \\otimes \\w)\n\\end{equation}\n\n\n\\item Elementary orthogonal projection:\n\\begin{equation}\n\\Projection_{\\w} \\v\n\\; \\equiv \\;\n\\left( \\frac{ \\w }{ \\| \\w \\| } \\otimes \\frac{ \\w }{ \\| \\w \\| } \\right) \\v\n\\; = \\;\n\\left( \\frac{\\w }{\\|\\w\\|} \\bullet \\v \\right) \\frac{\\w}{\\|\\w\\|}\n\\end{equation}\n\n\\item Orthogonal complement:\n\\begin{equation}\n\\perp_{\\w} \\v\n\\; \\equiv \\;\n\\v \\perp \\w\n\\; \\equiv \\;\n\\v \\; - \\; \\Projection_{\\w} \\v\n\\; = \\;\n\\v \\; - \\; \\left( \\frac{\\w}{\\|\\w\\|} \\bullet \\v \\right) \\frac{\\w}{\\|\\w\\|}\n\\end{equation}\n\n\\end{itemize}\n\n", "meta": {"hexsha": "0bbf83158a6bfa60c5f8d3e69f9febb90cb35fcd", "size": 2358, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fosm/vectors.tex", "max_stars_repo_name": "palisades-lakes/les-elemens", "max_stars_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/old/fosm/vectors.tex", "max_issues_repo_name": "palisades-lakes/les-elemens", "max_issues_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/old/fosm/vectors.tex", "max_forks_repo_name": "palisades-lakes/les-elemens", "max_forks_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.7954545455, "max_line_length": 75, "alphanum_fraction": 0.631043257, "num_tokens": 865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.7182094192404406}}
{"text": "\\subsection{Trigonometric Functions}\nThere are six basic trigonometric functions:\n\\begin{multicols}{2}\n\\begin{itemize}\n\t\\item Sine (abbreviated by $\\sin$)\n\t\\item Cosine (abbreviated by $\\cos$)\n\t\\item Tangent (abbreviated by $\\tan$)\n\t\\item Cosecant (abbreviated by $\\csc$)\n\t\\item Secant (abbreviated by $\\sec$)\n\t\\item Cotangent (abbreviated by $\\cot$)\n\\end{itemize}\n\\end{multicols}\n\nWe first describe trigonometric functions in terms of ratios of two sides of a \\ifont{right angle triangle} containing the angle $\\theta$. \n\n$$\\includegraphics[width=2.5in]{images/trig2}$$\n\nWith reference to the above triangle, for an acute angle $\\theta$ (that is, $0\\leq\\theta<\\pi/2$), the six trigonometric functions can be described as follows:\n$$\\begin{array}{ccc}\n\\ds\\sin\\theta=\\frac{\\rm opp}{\\rm hyp}&\\qquad&\\ds\\csc\\theta=\\frac{\\rm hyp}{\\rm opp}\\\\\n\\\\\n\\ds\\cos\\theta=\\frac{\\rm adj}{\\rm hyp}&\\qquad&\\ds\\sec\\theta=\\frac{\\rm hyp}{\\rm adj}\\\\\n\\\\\n\\ds\\tan\\theta=\\frac{\\rm opp}{\\rm adj}&\\qquad&\\ds\\cot\\theta=\\frac{\\rm adj}{\\rm opp}\\\\\n\\end{array}$$\n\n\\begin{formulabox}[Mnemonic]\nThe mnemonic \\ifont{SOH CAH TOA} is useful in remembering how trigonometric functions of acute angles relate to the sides of a right triangle.\n\\end{formulabox}\n\nThis description does not apply to \\ifont{obtuse} or \\ifont{negative angles}.\nTo define the six basic trigonometric functions we first define sine and cosine as the lengths of various line segments from a unit circle, and then we define the remaining four basic trigonometric functions in terms of sine and cosine.\n\nTake a line originating at the origin (making an angle of $\\theta$ with the positive half of the $x$-axis) and suppose this line intersects the unit circle at the point $(x,y)$.\nThe $x$- and $y$-coordinates of this point of intersection are equal to $\\cos\\theta$ and $\\sin\\theta$, respectively.\n$$\\includegraphics[width=2.3in]{images/trig3}$$\nFor angles greater than $2\\pi$ or less than $-2\\pi$, simply continue to rotate around the circle.\nIn this way, sine and cosine become periodic functions with period $2\\pi$:\n$$\\sin\\theta = \\sin\\left(\\theta + 2\\pi k \\right)\\qquad\\qquad \\cos\\theta = \\cos\\left(\\theta + 2\\pi k \\right)$$\nfor any angle $\\theta$ and any integer $k$.\n\nAbove, only sine and cosine were defined directly by the circle.\nWe now define the remaining four basic trigonometric functions in terms of the functions $\\sin\\theta$ and $\\cos\\theta$:\n$$\\tan\\theta = \\frac{\\sin\\theta}{\\cos\\theta} \\qquad \\sec\\theta = \\frac{1}{\\cos\\theta} \\qquad \\csc\\theta = \\frac{1}{\\sin\\theta} \\qquad \\cot\\theta = \\frac{\\cos\\theta}{\\sin\\theta}$$", "meta": {"hexsha": "d0d5c847720a0510dd868d7e70556d8e64e7fec3", "size": 2568, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1-review/1-3-2-trig-functions.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1-review/1-3-2-trig-functions.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1-review/1-3-2-trig-functions.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.3636363636, "max_line_length": 236, "alphanum_fraction": 0.7297507788, "num_tokens": 785, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646392, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7182094115176832}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath, amsthm, amssymb}\n\\usepackage{fullpage}\n\n\\newcommand{\\N}{\\mathcal{N}}\n\\renewcommand{\\v}[1]{\\mathbf{#1}}\n\\begin{document}\n\nWe have an observed signal $O(t)$. We have an arrival at time $t_0$, with a latent shape $S(t)$, repeatable wiggle $R(t)$, and nonrepeatable wiggle $W(t)$. These combine to form a latent signal $L(t) = S(t) \\cdot (R(t) + W(t))$.\n\nWe assume the observed signal is modeled as $O(t) = L(t) + N(t)$ where $N(t)$ is an $AR(p_N)$ noise process with mean $0$, parameters $\\phi^N$, and step variance $\\sigma^2_N$. Here we are ignoring, for simplicity of exposition, the contribution to $O(t)$ of any other simultaneous arrivals, along with any nonzero noise mean, since WLOG these can be subtracted out beforehand. We also assume that $W(t)$ is an $AR(p_W)$ noise process with mean $1$, parameters $\\phi_W$ and step variance $\\sigma^2_W$.\n\nWe consider here the problem of Gibbs sampling a new entry at time $k$ of the latent nonrepeatable wiggle $W(k)$. That is, we want to find the distribution\n\\[p(W(k) | W(\\not k), O, S, R).\\]\n\nIt's most enlightening to consider the problem in terms of the autoregressive processes $W$ and $N$. We can solve for $N$ as $N = O - L = O - S \\cdot (R + W)$. Note that, with $O$, $S$, $R$ observed, $N$ has a deterministic dependence on $W$: given any latent wiggle hypothesis, we can compute the station noise that would be required to explain the remainder of the observed signal. We deal with this deterministic dependence by 'integrating out' $N$, i.e. just modeling $O$ as a noisy function of $L$ with no explicit representation of $N$ in the model. This means that, when resampling $W(k)$, we do not have access to $N(k)$, since $N(k)$ can only be computed from the current value of $W(k)$.\n\nThe Markov blanket of $W(k)$ includes the $p_W$ entries of $W$ preceding $W(k)$ as well as the $p_W$ entries following it. Since $N(k)$ is a deterministic function of $W(K)$, it also includes the $p_N$ entries of $N$ preceding $N(k)$ and the $p_N$ entries following. We can write the joint distribution on all of these quantities as\n\\[p(W,O) = p_{AR}(W(k-p_W), \\cdots, W(k+p_W) \\cdot p_{AR}(N(k-p_N), \\cdots, N(k+p_N))\\]\nwhere $p_{AR}$ denotes probability under the relevant AR model and we take $N = O - SR - SW$.\n\nSince $N$ depends linearly on $W$, this is a linear Gaussian system. We can determine the posterior on $W(k)$ by the messages that are passed from the variables in its Markov blanket. We can divide these messages into $W$-messages and $N$-messages. The $W$ messages together will yield exactly the AR smoothing distribution on $W(k)$ given the other entries of $W$. Similarly, the $N$ messages together will yield the AR smoothing distribution on $N(k)$, which is just a linear function of $W(k)$, so we can transform that distribution into a message to $W(k)$ which we will combine with the smoothing distribution already received.\n\n\n\\section{Fully Observed Smoothing Distributions}\n\nHere we consider the smoothing distribution of an AR process $W$ with mean 0, parameters $\\phi$ and step variance $\\sigma^2$. We assume that all entries other than $W(k)$ are observed.\n\nNotation: we define an AR process by $W(k) = \\phi^T W(k-p : k-1) + \\N(0,\\sigma^2) = \\sum_{i=1}^{p} \\phi_i W(k-i)$. So increasing indices to $\\phi$ denote coefficients that are 'further back' in time.\n\nThe joint distribution on the Markov blanket is given by\n\\begin{align*}\np(W(k-p_W : k+p_W)) &= \\N(W(k); \\phi^T W(k-p : k-1); \\sigma^2 ) \\prod_{j=1}^p \\N(W(k+j); \\phi^T W(k-p+j : k+j-1); \\sigma^2 )\n\\end{align*}\nIf we adopt the shorthand $\\Pi(k') = W(k'-p : k'-1)$, i.e. we let $\\Pi(k')$ denote the vector of values that directly influence $W(k')$, we can rewrite this as\n\\begin{align*}\np(W(k-p_W : k+p_W)) &= \\N(W(k); \\phi^T \\Pi(k); \\sigma^2 ) \\prod_{j=1}^p \\N(W(k+j); \\phi^T \\Pi(k+j); \\sigma^2 )\\\\\n&\\propto \\exp\\left(\\left( \\left( W(k) - \\phi^T \\Pi(k) \\right)^2  + \\sum_{j=1}^p \\left( W(k+j) - \\phi^T \\Pi(k+j)\\right)^2 \\right) / \\sigma^2 \\right)\\\\\n\\end{align*}\nNote that each term inside the exponential includes $W(k)$ somewhere: the first term explicitly, and all subsequent terms as a component of the $\\Pi(k')$ vector. We can thus imagine rewriting each of these terms as $(\\phi^*_j W(k) - z_j)$ for some $z_j$, where $\\phi^*_j$ is the coefficient on the $W(k)$ term that we've pulled out, and $z_j$ is just ``whatever's left'' after pulling out that term. Formally, this gives\n\\begin{align*}\nz_0 &= \\phi^T \\Pi(k)\\\\\nz_j &= W(k+j) - \\sum_{i=1, i \\ne j}^p \\phi_i W(k+j-i)\n\\end{align*}\n\n\\begin{align*}\n\\phi^*_0 &= 1\\\\\n\\phi^*_j &= -\\phi_j\n\\end{align*}\n\nUnder this notation we can write\n\n\\begin{align*}\np(W(k-p_W : k+p_W)) & \\propto \\exp\\left( \\sum_{j=0}^p \\left(\\phi^*_j W(k) - z_j \\right)^2  / \\sigma^2 \\right)\\\\\n&= \\exp\\left( \\| W(k) \\v{\\phi^*} - \\v{z} \\|^2 / \\sigma^2 \\right)\\\\\n\\end{align*}\nWe can view this as a Gaussian distribution on $W(k) \\v{\\phi^*}$ with mean $\\v{z}$ and covariance $\\sigma^2 \\mathcal{I}$. By the standard formula for linear transformations of a Gaussian, we can transform by $\\v{\\phi^*}^T / \\|\\v{\\phi^*}\\|^2$ to yield a Gaussian $\\N\\left(W(k); \\mu, \\sigma^2 / \\|\\v{\\phi^*}\\|^2\\right)$  where $\\mu = \\v{\\phi^*}^T\\v{z} /  \\|\\v{\\phi^*}\\|^2$. This gives the smoothing distribution on $W(k)$.\n\nWe can calculate this efficiently by first computing the filtered means $f_t = \\sum_{i=1}^p \\phi_i W(t-i)$, then computing each $z$ value as $z_j = W(k+j) - (f_{k+j} - \\phi_{j} f_k)$, i.e. we remove the $k$ term from the filtered prediction at each timestep.\n\n\\section{Partly Observed Smoothing Distributions}\n\nWe now consider the case where some of the $W(t)$'s are unknown.\n\n\\subsection{Filtering}\n\nWe begin by considering just the filtering distribution. In particular, suppose some $W(\\ell)$ is unobserved, where $k-p < \\ell < k$ and we let $L = k-\\ell$ denote the coefficient $\\phi_L$ by which $W(\\ell)$ predicts $W(k)$. Now we have unknowns $W(k)$ and $W(\\ell)$. We solve for the marginal on $W(k)$:\n\\begin{align*}\np(W(k) | W(\\ell-p), &\\ldots, W(\\ell-1), W(\\ell+1), \\ldots, W(k-1)) \\\\\n&= \\int p\\left(W(k), W(\\ell) | W(\\ell-p), \\ldots, W(\\ell-1), W(\\ell+1), \\ldots, W(k-1)\\right) d W(\\ell)\\\\\n&= \\int \\N\\left(W(k); \\phi_{\\neg L}^T \\Pi_{\\neg \\ell}(k)  + \\phi_L W(\\ell), \\sigma^2 \\right) \\N\\left(W(\\ell); \\phi^T \\Pi(\\ell), \\sigma^2\\right) dW(\\ell)\n\\end{align*}\nwhere $\\phi_{\\neg L}$ and $\\Pi_{\\neg \\ell}$ have the obvious interpretations as vectors excluding the element corresponding to $W(\\ell)$. By the ``marginalization'' section of my notes on multivariate Gaussians, we find\n\\[p(W(k)) \\sim \\N\\left(\\phi_{\\neg L}^T \\Pi_{\\neg \\ell}(k)  + \\phi_L \\phi^T \\Pi(\\ell), \\sigma^2 + \\sigma^2\\phi_L^2  \\right).\\]\nThis is essentially the usual filtering distribution on $W(k)$, but with $W(\\ell)$ replaced by its filtered prediction $\\phi^T \\Pi(\\ell)$, and the variance increased slightly to compensate.\n\nIt is easy to see that if we had {\\em multiple} missing values in the dependence set for $W(k)$, we could apply this formula recursively: first calculate the filtering distribution for the second missing value given the first, then for the third given the second and first, and so on: in each case we substitute the filtered mean for each missing variable in the mean calculation, and add the filtered variance of each missing variable, weighted by its squared coefficient, to the variance.\n\n{\\bf But wait!} This is wrong because if we depend on multiple missing values, they will in general also depend on each other. A good way to think of this is that each filtered timestep $W(k)$ is a Gaussian random variable formed by the linear combination $\\phi^T \\Pi(k) + \\N(0, \\sigma^2)$, where each of its dependencies in $\\Pi(k)$ is {\\em also} such a Gaussian variable. As a sum of correlated variables, $\\phi^T \\Pi(k)$ has variance\n\\begin{align*}\nVar\\left(\\sum_i^p \\phi_i W(k-i) \\right) &= \\sum_{i,j} \\phi_i \\phi_j Cov(W(k-i), W(k-j))  \\\\\n&= \\sum_i \\phi_i^2 Var(W(k-i)) + \\sum_{i \\ne j} \\phi_i \\phi_j Cov(W(k-i), W(k-j)) \\\\\n&= \\sum_i \\phi_i^2 Var(W(k-i)) + 2\\sum_{i > j} \\phi_i \\phi_j Cov(W(k-i), W(k-j))\n\\end{align*}\n\nNow how do we find these covariances? In general if we have $Z = X+Y$ where $X$ and $Y$ are uncorrelated Gaussian rvs, then $var(Z) = var(X) + var(Y)$ and $cov(Z, X) = E[X(X+Y)] = E[X^2 + XY] = E[X^2] = Var(X)$.\nWhat if $X$ and $Y$ are correlated with some covariance $\\xi$? Then $cov(Z, X) = Var(X) + \\xi$.\n\nIn the autoregressive case, say we know the variance and covariances up to $W(k)$. Now we want $W(k+1)$.\n\n\nAssume WLOG that $i > j$, then we have\n\\begin{align*}\nCov(W(k-i), W(k-j)) &= E\\left[ W(k-i) W(k-j) \\right]\\\\\n&= E\\left[\\left(\\sum_{i'}\\phi_{i'} W(k-i-i')\\right) \\left(\\sum_{j'} \\phi_{j'}W(k-j-j')\\right)  \\right]\\\\\n&= E\\left[\\sum_{i',j'}\\phi_{i'} \\phi_{j'} W(k-i-i') W(k-j-j')  \\right]\n\\end{align*}\n\n\n\\subsection{Smoothing}\n\nWe now return to the smoothing calculation as described above. Recall that we factored the joint distribution on $W(k), \\ldots, W(k+p)$, conditioned on $W(k-p), \\ldots, W(k-1)$, into the product of filtering distributions for each of $W(k), \\ldots, W(k+p)$. Thus a missing observation will have two effects: first, we will not have a factor for the filtering distribution of that variable, and second, that variable will be missing from the filtering condition for all other relevant variables.\n\nI don't want to figure out the notation to write this all out, but the implementation is: we compute the filtering distribution as described above, then also just ignore any component of $z$ corresponding to a missing observation. A slight change is that we now have different filtering variances for different variables. Let $\\sigma^2_j$ denote the filtering variance for $W(k+j)$, so that $\\v{\\sigma^2}$ is a $p+1$-dimensional vector. Then\n\\begin{align*}\np(W(k-p_W : k+p_W)) & \\propto \\exp\\left( \\sum_{j=0}^p \\left(\\phi^*_j W(k) - z_j \\right)^2  / \\sigma_j^2 \\right)\\\\\n&= \\exp\\left( ( W(k) \\v{\\phi^*} - \\v{z})^T \\text{diag}(\\sigma^2)^{-1}  ( W(k) \\v{\\phi^*} - \\v{z}) \\right)\n\\end{align*}\nand applying the linear transformation $\\v{\\phi^*}^T / \\|\\v{\\phi^*}\\|^2$ now yields the Gaussian $\\N\\left(W(k); \\mu,   \\xi   \\right)$  where $\\mu = \\v{\\phi^*}^T\\v{z} /  \\|\\v{\\phi^*}\\|^2$ and $\\xi = \\v{\\phi^*}^T  \\text{diag}(\\sigma^2) \\v{\\phi^*} / \\| \\v{\\phi^*}\\|^4$.\n\n\\end{document}\n", "meta": {"hexsha": "2d7a3e82ec977f55864223555d61d4c9a15227a2", "size": 10318, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/wiggle_ar.tex", "max_stars_repo_name": "davmre/sigvisa", "max_stars_repo_head_hexsha": "91a1f163b8f3a258dfb78d88a07f2a11da41bd04", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/wiggle_ar.tex", "max_issues_repo_name": "davmre/sigvisa", "max_issues_repo_head_hexsha": "91a1f163b8f3a258dfb78d88a07f2a11da41bd04", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/wiggle_ar.tex", "max_forks_repo_name": "davmre/sigvisa", "max_forks_repo_head_hexsha": "91a1f163b8f3a258dfb78d88a07f2a11da41bd04", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 91.3097345133, "max_line_length": 697, "alphanum_fraction": 0.6717387091, "num_tokens": 3361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896671963206, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7182094077495716}}
{"text": "\\subsection{Quadratic forms}\n\nOne of the applications of orthogonal diagonalization is that of quadratic forms and graphs of level curves of a quadratic form. This section has to do with rotation of axes\nso that with respect to the new axes, the graph of the level curve of a\nquadratic form is oriented parallel to the coordinate axes. This makes it\nmuch easier to understand. For example, we all know that $x_1^2 + x_2^2=1$ represents the equation in two variables whose graph in $\\R^2$ is a circle of radius $1$. But how do we know what the graph of the equation $5x_1^2 + 4x_1x_2 + 3x_2^2=1$ represents?\n\\index{principal axis!quadratic forms}\n\nWe first formally define what is meant by a quadratic form. In this section we will work with only \\textit{real} quadratic forms, which means that the coefficients will all be real numbers.\n\n\\begin{definition}{Quadratic form}{quadratic-form}\nA \\textbf{quadratic form}\\index{quadratic form} is a polynomial of degree two in $n$ variables $x_1, x_2,\\ldots, x_n$, written as a linear combination of $x_i^{2}$ terms and $x_ix_j$ terms.\n\\end{definition}\n\nConsider the quadratic form $q = a_{11}x_1^2 + a_{22}x_2^2 + \\ldots + a_{nn}x_n^2 + a_{12}x_1x_2 + \\ldots$. We can write $\\vect{x} = \\begin{mymatrix}{r}\nx_1 \\\\\nx_2 \\\\\n\\vdots \\\\\nx_n\n\\end{mymatrix}$ as the vector whose entries are the variables contained in the quadratic form.\n\nSimilarly, let $A = \\begin{mymatrix}{rrrr}\na_{11} & a_{12} & \\cdots & a_{1n} \\\\\na_{21} & a_{22} & \\cdots & a_{2n} \\\\\n\\vdots & \\vdots & & \\vdots \\\\\na_{n1} & a_{n2} & \\cdots & a_{nn}\n\\end{mymatrix}$ be the matrix whose entries are the coefficients of $x_i^2$ and $x_ix_j$ from $q$. Note that the matrix $A$ is not unique, and we will consider this further in the example below. Using this matrix $A$,  the quadratic form can be written as $q = \\vect{x}^T A \\vect{x}$.\n\n\\begin{eqnarray*}\nq &=& \\vect{x}^T A \\vect{x} \\\\\n&=& \\begin{mymatrix}{rrrr}\nx_1 & x_2 & \\cdots & x_n\n\\end{mymatrix}\n \\begin{mymatrix}{rrrr}\na_{11} & a_{12} & \\cdots & a_{1n} \\\\\na_{21} & a_{22} & \\cdots & a_{2n} \\\\\n\\vdots & \\vdots & & \\vdots \\\\\na_{n1} & a_{n2} & \\cdots & a_{nn}\n\\end{mymatrix}\n\\begin{mymatrix}{r}\nx_1 \\\\\nx_2 \\\\\n\\vdots \\\\\nx_n\n\\end{mymatrix} \\\\\n&=&\n\\begin{mymatrix}{rrrr}\nx_1 & x_2 & \\cdots & x_n\n\\end{mymatrix}\n\\begin{mymatrix}{c}\na_{11}x_1 + a_{21}x_2 + \\ldots + a_{n1}x_n \\\\\na_{12}x_1 + a_{22}x_2 + \\ldots + a_{n2}x_n \\\\\n\\vdots \\\\\na_{1n}x_1 + a_{2n}x_2 + \\ldots + a_{nn}x_n\n\\end{mymatrix} \\\\\n&=& a_{11}x_1^2 + a_{22}x_2^2 + \\ldots + a_{nn}x_n^2 + a_{12}x_1x_2 + \\ldots\n\\end{eqnarray*}\n\nLet's explore how to find this matrix $A$. Consider the following example.\n\n\\begin{example}{Matrix of a quadratic form}{matrix-quadratic-form}\nLet a quadratic form $q$ be given by\n\\[\nq = 6x_1^2 + 4x_1x_2 + 3x_2^2\n\\]\nWrite $q$ in the form $\\vect{x}^TA\\vect{x}$.\n\\end{example}\n\n\\begin{solution}\nFirst, let $\\vect{x} = \\begin{mymatrix}{r}\nx_1 \\\\\nx_2\n\\end{mymatrix}$ and $A = \\begin{mymatrix}{rr}\na_{11} & a_{12} \\\\\na_{21} & a_{22}\n\\end{mymatrix}$.\n\nThen, writing $q = \\vect{x}^TA\\vect{x}$ gives\n\\begin{eqnarray*}\nq &=& \\begin{mymatrix}{rr}\nx_1 & x_2\n\\end{mymatrix}\n\\begin{mymatrix}{rr}\na_{11} & a_{12} \\\\\na_{21} & a_{22}\n\\end{mymatrix}\n\\begin{mymatrix}{r}\nx_1 \\\\\nx_2\n\\end{mymatrix} \\\\\n&=& a_{11}x_1^2 + a_{21}x_1x_2 + a_{12}x_1x_2 + a_{22}x_2^2\n\\end{eqnarray*}\n\nNotice that we have an $x_1x_2$ term as well as an $x_2x_1$ term. Since multiplication is commutative, these terms can be combined. This means that $q$ can be written\n\\[\nq =  a_{11}x_1^2 + (a_{21}+ a_{12}) x_1x_2 + a_{22}x_2^2\n\\]\n\nEquating this to $q$ as given in the example, we have\n\\[\n a_{11}x_1^2 + (a_{21}+ a_{12}) x_1x_2 + a_{22}x_2^2 =  6x_1^2 + 4x_1x_2 + 3x_2^2\n\\]\n\nTherefore,\n\\begin{eqnarray*}\na_{11} &=& 6 \\\\\na_{22} &=& 3 \\\\\na_{21}+a_{12} &=& 4\n\\end{eqnarray*}\n\nThis demonstrates that the matrix $A$ is not unique, as there are several correct solutions to $a_{21}+a_{12} = 4$. However, we will \\textit{always} choose the coefficients such that $a_{21} = a_{12} = \\frac{1}{2} (a_{21}+a_{12})$. This results in $a_{21} = a_{12} = 2$. This choice is key, as it will ensure that $A$ turns out to be a symmetric matrix.\n\nHence,\n\\[\nA =\n\\begin{mymatrix}{rr}\na_{11} & a_{12} \\\\\na_{21} & a_{22}\n\\end{mymatrix}\n=\n\\begin{mymatrix}{rr}\n6 & 2 \\\\\n2 & 3\n\\end{mymatrix}\n\\]\n\nYou can verify that $q = \\vect{x}^T A \\vect{x}$ holds for this choice of $A$.\n\\end{solution}\n\nThe above procedure for choosing $A$ to be symmetric applies for any quadratic form $q$. We will \\textit{always} choose coefficients such that $a_{ij}=a_{ji}$.\n\nWe now turn our attention to the focus of this section. Our goal is to start with a quadratic form $q$ as given above and find a way to rewrite it to eliminate the $x_ix_j$ terms. This is done through a change of variables. In other words, we wish to find $y_i$ such that\n\\[\nq = d_{11}y_1^2 + d_{22}y_2^2 + \\ldots + d_{nn}y_n^2\n\\]\n Letting $\\vect{y} = \\begin{mymatrix}{r}\ny_1 \\\\\ny_2 \\\\\n\\vdots \\\\\ny_n\n\\end{mymatrix}$ and $D = \\mat{d_{ij} }$, we can write $q = \\vect{y}^T D \\vect{y}$ where $D$ is the matrix of coefficients from $q$. There is something special about this matrix $D$ that is crucial. Since no $y_iy_j$ terms exist in $q$, it follows that $d_{ij} = 0$ for all $i \\neq j$. Therefore, $D$ is a diagonal matrix. Through this change of variables, we find the \\textbf{principal axes}\\index{principal axes} $y_1, y_2,\\ldots, y_n$ of the quadratic form.\n\nThis discussion sets the stage for the following essential theorem.\n\n\\begin{theorem}{Diagonalizing a quadratic form}{diagonalize-quadratic-form}\nLet $q$ be a quadratic form in the variables $x_1,\\ldots, x_n$. It follows that $q$ can be written in the form $q = \\vect{x}^T A \\vect{x}$ where\n\\[\n\\vect{x} = \\begin{mymatrix}{r}\nx_1 \\\\\nx_2 \\\\\n\\vdots \\\\\nx_n\n\\end{mymatrix}\n\\]\nand $A = \\mat{a_{ij} }$ is the symmetric matrix of coefficients of $q$.\n\nNew variables $y_1, y_2,\\ldots, y_n$ can be found such that $q = \\vect{y}^T D \\vect{y}$ where\n\\[\n\\vect{y} = \\begin{mymatrix}{r}\ny_1 \\\\\ny_2 \\\\\n\\vdots \\\\\ny_n\n\\end{mymatrix} \\] and $D=\\mat{d_{ij} }$ is a diagonal matrix. The matrix $D$ contains the eigenvalues of $A$ and is found by orthogonally diagonalizing $A$.\n\\end{theorem}\n\nWhile not a formal proof, the following discussion should convince you that the above theorem holds. Let $q$ be a quadratic form in the variables $x_1,\\ldots, x_n$. Then, $q$ can be written in the form $q = \\vect{x}^T A \\vect{x}$ for a symmetric matrix $A$.\nBy Theorem~\\ref{thm:orthogonal-diagonalization} we can orthogonally diagonalize the matrix $A$ such that $U^TAU = D$ for an orthogonal matrix $U$ and diagonal matrix $D$.\n\nThen, the vector $\\vect{y} = \\begin{mymatrix}{r}\ny_1 \\\\\ny_2 \\\\\n\\vdots \\\\\ny_n\n\\end{mymatrix}\n$ is found by $\\vect{y} = U^T \\vect{x}$. To see that this works, rewrite $\\vect{y} = U^T \\vect{x}$ as $\\vect{x} = U\\vect{y}$. Letting $q = \\vect{x}^TA\\vect{x}$, proceed as follows:\n\\begin{eqnarray*}\nq &=& \\vect{x}^T A \\vect{x}\\\\\n&=& (U\\vect{y})^T A (U\\vect{y})\\\\\n&=& \\vect{y}^T (U^TAU) \\vect{y} \\\\\n&=& \\vect{y}^T D \\vect{y}\n\\end{eqnarray*}\n\nThe following procedure details the steps for the change of variables given in the above theorem.\n\n\\begin{procedure}{Diagonalizing a quadratic form}{diagonalize-quadratic-form}\nLet $q$ be a quadratic form in the variables $x_1,\\ldots, x_n$ given by\n\\[\nq = a_{11}x_1^2 + a_{22}x_2^2 + \\ldots + a_{nn}x_n^2 + a_{12}x_1x_2+\\ldots\n\\]\nThen, $q$ can be written as $q = d_{11}y_1^2 + \\ldots + d_{nn}y_n^2$ as follows:\n\n\\begin{enumerate}\n\\item\nWrite $q = \\vect{x}^T A \\vect{x}$ for a symmetric matrix $A$.\n\n\\item\nOrthogonally diagonalize $A$ to be written as $U^TAU=D$ for an orthogonal matrix $U$ and diagonal matrix $D$.\n\n\\item\nWrite $\\vect{y} = \\begin{mymatrix}{c}\ny_1 \\\\\ny_2 \\\\\n\\vdots \\\\\ny_n\n\\end{mymatrix}$. Then, $\\vect{x} = U \\vect{y}$.\n\n\\item\nThe quadratic form $q$ will now be given by\n\\[\nq = d_{11}y_1^2 + \\ldots + d_{nn}y_n^2 = \\vect{y}^T D \\vect{y}\n\\]\nwhere $D = \\mat{d_{ij} }$ is the diagonal matrix found by orthogonally diagonalizing $A$.\n\\end{enumerate}\n\\end{procedure}\n\nConsider the following example.\n\n\\begin{example}{Choosing new axes to simplify a quadratic form}{new-axes1}\nConsider the following level curve\n\\[\n6x_1^2 + 4x_1x_2 + 3x_2^2 = 7\n\\]\nshown in the following graph.\n\\begin{center}\n\\begin{tikzpicture}[scale=0.5]\n\\draw[-, thick](-2,0)--(2,0);\n\\node[above right] at (2,0){$x_1$};\n\\draw[-, thick](0,-2)--(0,2);\n\\node[above right] at (0,2){$x_2$};\n\\draw[blue, ultra thick, domain=-1.78376:1.78376] plot(\\x, {0.2*(-2*\\x-sqrt(35-11*\\x*\\x))});\n\\draw[blue, ultra thick, domain=-1.78376:1.78376] plot(\\x, {0.2*(sqrt(35-11*\\x*\\x)-2*\\x)});\n\\end{tikzpicture}\n\\end{center}\n\nUse a change of variables to choose new axes such that the ellipse is oriented parallel to the new coordinate axes. In other words, use a change of variables to rewrite $q$ to eliminate the $x_1x_2$ term.\n\\end{example}\n\n\\begin{solution}\nNotice that the level curve is given by $q = 7$ for $q = 6x_1^2 + 4x_1x_2 + 3x_2^2$. This is the same quadratic form that we examined earlier in Example~\\ref{exa:matrix-quadratic-form}. Therefore we know that we can write $q = \\vect{x}^T A \\vect{x}$ for the matrix\n\\[\nA = \\begin{mymatrix}{rr}\n6 & 2 \\\\\n2 & 3\n\\end{mymatrix}\n\\]\n\nNow we want to orthogonally diagonalize $A$ to write $U^TAU=D$ for an orthogonal matrix $U$ and diagonal matrix $D$. The details are left to the reader, and you can verify that the resulting matrices are\n\\begin{eqnarray*}\nU &=&\n\\begin{mymatrix}{rr}\n\\vspace{0.05in}\\frac{2}{\\sqrt{5}} & -\\vspace{0.05in}\\frac{1}{\\sqrt{5}} \\\\\n\\vspace{0.05in}\\frac{1}{\\sqrt{5}} & \\vspace{0.05in}\\frac{2}{\\sqrt{5}}\n\\end{mymatrix} \\\\\nD &=&\n\\begin{mymatrix}{rr}\n 7 & 0 \\\\\n0 & 2\n\\end{mymatrix}\n\\end{eqnarray*}\n\nNext we write $ \\vect{y} = \\begin{mymatrix}{c}\ny_1 \\\\\ny_2\n\\end{mymatrix}$. It follows that $\\vect{x} = U \\vect{y}$.\n\nWe can now express the quadratic form $q$ in terms of $y$, using the entries from $D$ as coefficients as follows:\n\\begin{eqnarray*}\nq &=& d_{11}y_1^2 + d_{22}y_2^2 \\\\\n&=& 7y_1^2 + 2y_2^2\n\\end{eqnarray*}\n\nHence the level curve can be written $7y_1^2 + 2y_2^2 =7$.\nThe graph of this equation is given by:\n\n\\begin{center}\n\\begin{tikzpicture}\n\\draw[-, thick](-2,0)--(2,0);\n\\node[above right] at (2,0){$y_1$};\n\\draw[-, thick](0,-2.5)--(0,2.5);\n\\node[above right] at (0,2.5){$y_2$};\n\\draw[ultra thick, blue] (0,0) ellipse (1cm and 2cm);\n\\end{tikzpicture}\n\\end{center}\n\nThe change of variables results in new axes such that with respect to the new axes, the ellipse is oriented parallel to the coordinate axes. These are called the \\textbf{principal axes} of the quadratic form.\n\\end{solution}\n\nThe following is another example of diagonalizing a quadratic form.\n\n\\begin{example}{Choosing new axes to simplify a quadratic form}{new-axes2}\nConsider the level curve\n\\begin{equation*}\n5x_1^{2}-6x_1x_2+5x_2^{2}=8\n\\end{equation*}\nshown in the following graph.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=0.5]\n\\draw[-, thick](-2,0)--(2,0);\n\\node[above right] at (2,0){$x_1$};\n\\draw[-, thick](0,-2)--(0,2);\n\\node[above right] at (0,2){$x_2$};\n\\draw[blue, ultra thick, domain=-1.58113:1.58113] plot(\\x, {0.2*(3*\\x-2*sqrt(2)*sqrt(5-2*\\x*\\x))});\n\\draw[blue, ultra thick, domain=-1.58113:1.58113] plot(\\x, {0.2*(2*sqrt(2)*sqrt(5-2*\\x*\\x)+3*\\x)});\n\\end{tikzpicture}\n\\end{center}\n\nUse a change of variables to choose new axes such that the ellipse is oriented parallel to the new coordinate axes. In other words, use a change of variables to rewrite $q$ to eliminate the $x_1x_2$ term.\n\\end{example}\n\n\\begin{solution}\nFirst, express the level curve as $\\vect{x}^TA\\vect{x}$ where $\\vect{x} = \\begin{mymatrix}{r}\nx_1 \\\\\nx_2\n\\end{mymatrix}$ and $A$ is symmetric. Let $A = \\begin{mymatrix}{rr}\na_{11} & a_{12} \\\\\na_{21} & a_{22}\n\\end{mymatrix}$. Then $q = \\vect{x}^T A \\vect{x}$ is given by\n\\begin{eqnarray*}\nq &=&  \\begin{mymatrix}{cc}\nx_1 & x_2\n\\end{mymatrix}\n\\begin{mymatrix}{rr}\na_{11} & a_{12} \\\\\na_{21} & a_{22}\n\\end{mymatrix}\n\\begin{mymatrix}{r}\nx_1 \\\\\nx_2\n\\end{mymatrix}\\\\\n&=& a_{11}x_1^2 + (a_{12} + a_{21})x_1x_2 + a_{22}x_2^2\n\\end{eqnarray*}\n\nEquating this to the given description for $q$, we have\n\\[\n5x_1^2 -6x_1x_2 + 5x_2^2 =  a_{11}x_1^2 + (a_{12} + a_{21})x_1x_2 + a_{22}x_2^2\n\\]\nThis implies that $a_{11} = 5, a_{22} = 5$ and in order for $A$ to be symmetric, $a_{12} = a_{22} = \\frac{1}{2} (a_{12}+a_{21}) = -3$. The result is $A = \\begin{mymatrix}{rr}\n5 & -3 \\\\\n-3 & 5\n\\end{mymatrix}$. We can write $q = \\vect{x}^TA\\vect{x}$ as\n\\begin{equation*}\n\\begin{mymatrix}{cc}\nx_1 & x_2\n\\end{mymatrix} \\begin{mymatrix}{rr}\n5 & -3 \\\\\n-3 & 5\n\\end{mymatrix} \\begin{mymatrix}{c}\nx_1 \\\\\nx_2\n\\end{mymatrix} =8\n\\end{equation*}\n\nNext, orthogonally diagonalize the matrix $A$ to write $U^TAU = D$. The details are left to the reader and the necessary matrices are given by\n\\begin{eqnarray*}\nU &=& \\begin{mymatrix}{rr}\n\\vspace{0.05in}\\frac{1}{2}\\sqrt{2} & \\vspace{0.05in}\\frac{1}{2}\\sqrt{2} \\\\\n\\vspace{0.05in}\\frac{1}{2}\\sqrt{2} & -\\vspace{0.05in}\\frac{1}{2}\\sqrt{2}\n\\end{mymatrix} \\\\\nD &=&\n\\begin{mymatrix}{rr}\n2 & 0 \\\\\n0 & 8\n\\end{mymatrix}\n\\end{eqnarray*}\n\nWrite $\\vect{y} = \\begin{mymatrix}{r}\ny_1 \\\\\ny_2\n\\end{mymatrix}$, such that $\\vect{x} = U \\vect{y}$. Then it follows that $q$ is given by\n\\begin{eqnarray*}\nq &=& d_{11}y_1^2 + d_{22}y_2^2 \\\\\n&=& 2y_1^{2}+8y_2^{2}\n\\end{eqnarray*}\nTherefore the level curve can be written as $2y_1^{2}+8y_2^{2}=8$.\n\nThis is an ellipse which is parallel to the coordinate axes. Its graph is of\nthe form\n\n\\begin{center}\n\\begin{tikzpicture}\n\\draw[-, thick](-2.5,0)--(2.5,0);\n\\node[above right] at (2.5,0){$y_1$};\n\\draw[-, thick](0,-2)--(0,2);\n\\node[above right] at (0,2){$y_2$};\n\\draw[ultra thick, blue] (0,0) ellipse (2cm and 1cm);\n\\end{tikzpicture}\n\\end{center}\n\n\\noindent Thus this change of variables chooses new axes  such that with respect to these new axes, the\nellipse is oriented parallel to the coordinate axes.\n\\end{solution}\n", "meta": {"hexsha": "5396c14948bec1880c994317cae93938a6342184", "size": 13821, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryOrthogonalityQuadraticForms.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/spectraltheoryOrthogonalityQuadraticForms.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/spectraltheoryOrthogonalityQuadraticForms.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 35.078680203, "max_line_length": 459, "alphanum_fraction": 0.6699225816, "num_tokens": 5389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.8887587942290706, "lm_q1q2_score": 0.718176850589203}}
{"text": "\\chapter{Physically-based animation} \\label{chapter:pba}\n\\section{Particles} \\label{sec:particles}\n\\subsection{Basic equation}\nA particle is a moving point with a mass. Generally the mass is a constant over time while its position and velocity can vary. We therefore consider the mass $ m $ (in $ kg $) as an attribute while its position $ x $ (in $ m $) and its velocity $ v $ (in $m.s^{-1}$) are its state variables. \nParticles obey Newton's law: \n\\begin{equation} \\label{eq:newton}\nma = \\Sigma f\n\\end{equation} \nwhere $a$ is the particle's acceleration (in $m.s^{-2}$). This defines the Ordinary Differential Equation (ODE) $a(t) = f(x,v,t)$. Physically-based animation requires us to repeatedly solve it over the interval $[t,t+dt]$ and redisplay.\n\nFrom equation \\ref{eq:newton} we can deduce $a=1/m\\;\\Sigma f$ and integrate time over a time step dt, and so on. The simplest integration method is Euler's explicit scheme:\n\\begin{eqnarray}\nv(t+dt) &=& v(t)+a(t)dt \\nonumber \\\\\nx(t+dt) &=& x(t)+v(t)dt \\label{eq:expliciteuler}\n\\end{eqnarray}\n\nParticles can live in any k-dimensional space $\\Re^k$, where state variables and forces are k-dimensional vectors of scalar values. The dynamics equation \\ref{eq:newton} applies to each scalar value.\nWhen considering $n$ particles the equations can be conveniently written in matrix form:\n\\begin{eqnarray*}\n\\ma M \\ve a &=& \\ve f\\\\\n\\ve a &=& \\ma M^{-1} \\ve f\n\\end{eqnarray*}\nwhere \\ma M is a diagonal matrix of dimension $kn\\times kn$ , \\ve a and \\ve f are vectors of dimension $kn$ gathering all the scalar components associated with each particle.\n\nNumerical integration can generate instabilities leading to the divergence of the simulated system. To avoid this, one solution is to decrease the time step. The other solution is to use an implicit integration scheme, which takes into account the variation of the forces during the time step. The simplest one is the implicit Euler's method which applies a step based on the forces at the end of the time step instead of the beginning. Equation \\ref{eq:expliciteuler} becomes:\n\\begin{eqnarray}\nv(t+dt) &=& v(t)+a(t+dt)dt \\nonumber\\\\\nx(t+dt) &=& x(t)+v(t+dt)dt \\label{eq:impliciteuler}\n\\end{eqnarray}\nSince $a(t+dt)$ is unknown we have to solve an equation.\nIf we write $v(t+dt) = v(t)+\\Delta v$ the matrix form equation to solve is:\n\\begin{equation}\n\\label{eq:matimplicit}\n\\left( \\ma M + dt \\ma D + dt^2 \\ma K \\right) \\ve{\\Delta v} = dt \\left( \\ve f(t) + \\ma D \\ve{v}(t) \\right) \n\\end{equation}\nwhere the damping matrix $\\ma D = \\delta \\ve f/\\delta \\ve v$ encodes the variation of force given a variation of velocity, and the stiffness matrix $\\ma K = \\delta \\ve f/\\delta \\ve p$ encodes the variation of force given a variation of position.\n\n\\subsection{Forces}\nThe forces are responsible for the accelerations of the bodies. Their physical unit is the Newton ($N=kg.m.s^{-2}$).\nHere we briefly review the most commonly used forces.\n\n\\subsubsection{Weight}\nA uniform gravitational field $g$ (in $m.s^{-2}$) applies a force \n\\begin{equation} \\label{eq:gravity}\nf = mg\n\\end{equation} \nto each particle where $m$ is the mass of the particle.\n\n\\subsubsection{Linear damping}\nDamping transforms kinetic energy to heat by applying a force opposed to the velocity. It tends to slow down the objects. Linear damping is proportional to the velocity, thus \n\\begin{equation}\\label{eq:lineardamping}\nf=-\\nu v\n\\end{equation}\nwhere $v$ is the velocity of the particle and $\\nu$ a positive scalar (in $kg.s^{-1}$).\n\n\\subsubsection{Air damping}\nAir damping is proportional to the square of the velocity of the body with respect to the air:\n\\begin{equation}\nf = -\\rho S_u C_u v^2 u \n\\end{equation}\nwhere $\\rho$ is the volumic mass the air ($kg.m^{-3}$), $v$ the velocity of the object, $u$ a no-dimensional unit vector in the direction of the velocity, $S$ the area ($m^2$) of the object projected along $u$, and $C_u$ a no-dimensional coefficient associated with the shape of the object and the direction $u$.\n\n\\subsubsection{Linear springs}\nA springs applies an elastic force between two points. It is modeled using its rest length $l_0$ (in $m$) and its stiffness $k$ (in $N.m^{-1}$). \nLet $i$ and $j$ be the indices of points linked by a given spring. \nThe force applied by a linear spring to point $i$ is given by:\n\\begin{equation}\n\\label{eq:spring}\nf_i = k( l-l_0 ) u\n\\end{equation}\nwhere $l=\\|x_j - x_i\\|$ is the distance between the points and $u$ a unit vector pointing from point $i$ to point $j$. The force $f_j$ applied to point $j$ is the opposite: $f_j = -f_i$. Nonlinear springs can be used to model more complex behaviors.\n\n\\subsubsection{Linear damped springs}\nDamping forces are commonly associated with springs in order to dissipate energy. They are opposed to the relative velocity of the points. They are typically modeled using a coefficient $\\nu$ (in $kg.s^{-1}$).\nThe force applied by a linear damped spring to point $i$ is given by:\n\\begin{equation}\n\\label{eq:dampedspring}\nf_i = \\left( k( l-l_0 ) + \\nu v_{ij} \\right) u\n\\end{equation}\nwhere $v_{ij} = (v_j-v_i).u$ is the relative velocity of the particles along direction $u$.\n\n\\subsubsection{Finite elements}\nFinite elements is a powerful paradigm for modeling continuous material. At our level, we can see them as springs acting on more than two points simultaneously. For example, a tetrahedral finite element acts on the four vertices of a tetrahedron and allows a more effective control of stiffness and volume than using springs.\n\n\n%===========================================================================================\n\n\\section{Solids}\nA solid is a moving reference frame with a mass matrix. In two dimensions it has three degrees of freedom (DOFs), two translations and one rotation, while in three dimensions it has six DOFs, three translations and three independent rotation values. The remainder of this document focuses on three dimensions.\n\n\\subsection{Orientation}\nThere are different ways of modeling orientation ot one frame with respect to another in three dimensions, each of them with advantages and drawbacks:\n\\begin{itemize}\n\\item matrices directly define the axes of the solid with respect to a reference frame. They allow fast projections from one frame to another but they contain nine dependent entries and they can not be set up intuitively;\n\\item Euler angles are compact (three parameters) and intuitive but they have singularities and they can not be easily combined;\n \\item (axis, angle) pairs are more intuitive and more compact (four parameters) than matrices but they do not allow projections and combinations;\n\\item quaternions are compact (four parameters) and allow easy projections and combinations, but they are not easy to set up intuitively.\n\\end{itemize}\n\n\\subsubsection{Orientation matrices}\nOrientations matrices are $3\\times 3$ matrices, each column gathering the coordinates of one axis of the rotated frame with respect to the reference frame. Each column is thus a unit vector orthogonal to the others. This creates six relations among the nine parameters, leaving three independent DOFs.\n\n\\subsubsection{Euler angles}\nEuler angles model a sequence of three rotations along three pairwise-independent directions. For example, the following matrix product represents a rotation $\\alpha$ along axis $x$ followed by a rotation $\\beta$ along rotated axis $y$ followed by a rotation $\\gamma$ along the twice rotated axis $z$.\n%\\begin{equation}\\label{eq:angles euler}\n$$\n\\left(\\begin{array}{ccc}\n1 & 0 & 0 \\\\\n0 & \\cos\\alpha & -\\sin\\alpha \\\\\n0 & \\sin\\alpha &  \\cos\\alpha\n\\end{array}\\right)\n\\left(\\begin{array}{ccc}\n\\sin\\beta & 0 &  \\cos\\beta\\\\\n0 & 1 & 0 \\\\\n\\cos\\beta & 0 & -\\sin\\beta\n\\end{array}\\right)\n\\left(\\begin{array}{ccc}\n\\cos\\gamma & -\\sin\\gamma & 0\\\\\n\\sin\\gamma & \\cos\\gamma & 0\\\\\n0 & 0 & 1\\\\\n\\end{array}\\right)\n$$\n%\\end{equation}\nAlternatively, this can be seen as a rotation  $\\gamma$ along axis $z$ followed by a rotation $\\beta$ along the fixed axis $y$ followed by a rotation $\\alpha$ along the fixed axis $x$. An example of singularity is the fact that in this system, rotation $(\\pi,\\pi,0)$ is equivalent with rotation $(0,0,\\pi)$. Another example is the fact that rotation $(\\alpha,\\pi /2, \\gamma)$ is equivalent with rotation $(0,\\pi /2, \\alpha+\\gamma)$ for any $\\alpha$ and $\\gamma$ (this loss of one DOF is called \\emph{gimbal lock}).\n\n\\subsubsection{Axis, angle}\nThe rotation $\\theta$ along an axis defined by a unit vector $n$ has the following matrix:\n$$\n\\rot{\\theta}{u} = \\mat{I} + \\sin\\theta\\oppvec{n} + (1-\\cos\\theta)\\oppvec{n}^2\n$$\nwhere matrix $\\oppvec{n}$  is the vector product matrix operator: \n%\\begin{equation}\\label{eq:oppvec}\n$$\n\\oppvec{n} = \\left(\\begin{array}{ccc}\n0 & -n_z & n_y \\\\\nn_z & 0 & -n_x \\\\\n-n_y & n_x & 0\n\\end{array}\\right)\n$$\n%\\end{equation}\nIt is possible to convert a matrix back to (axis, angle) by noticing that  $\\trace{\\mat R}=1+2\\cos\\theta$ et que $\\mat R -\\transp{\\mat R} = 2\\sin\\theta\\oppvec{n}$\n\n\\subsubsection{Quaternions}\nQuaternions are an extension of complex numbers: $ \\bm q = w + x\\bm i + y \\bm j + z \\bm k = (w,\\vect v)$.\\\\\nw is the real part, \\vect v the imagianry part.\nProperties of \\bm i, \\bm j, \\bm k:\n$$\n\\begin{array}{l}\n  \\bm i^2 = \\bm j^2 = \\bm k^2 = -1\\\\\n  \\bm{ij}=\\bm k,\\;\\bm{ji} = -\\bm k\\\\\n  \\bm{jk}=\\bm i,\\;\\bm{kj} = -\\bm i\\\\\n  \\bm{ki}=\\bm j,\\;\\bm{ik} = -\\bm j\\\\\n\\end{array}\n$$\nA 3d vector is a pure imaginary quaternion:\n$$\n\\bm p = (0,x,y,z)\n$$\nProduct of quaternions (not commutative):\n$$\n\\bm{q_1q_2} = (w_1w_2 - \\bm v_1.\\bm v_2, \\; w_1\\bm v_2 + w_2\\bm v_1 + \\bm v_1 \\wedge \\bm v_2)\n$$\nConjugate quaternion:\n$$\n\\begin{array}{l}\n  \\bm{\\bar q} = w - x\\bm i - y \\bm j - z \\bm k\\\\\n  \\bm{q\\bar q} = w^2 + x^2 + y^2 + z^2\n\\end{array}\n$$\nUnit quaternions used to model rotations:\n$$\n\\bm{q\\bar q} = 1\n$$\nRotation $(\\theta, \\bm u)$: {\\em ($\\bm u^2=1$)}\n$$\n\\bm q_{(\\theta,u)} = ( \\cos{\\frac{\\theta}{2}}, u_x\\sin{\\frac{\\theta}{2}}, u_y\\sin{\\frac{\\theta}{2}}, u_z\\sin{\\frac{\\theta}{2}})\n$$\nRotation of a vector \\bm p:$\\;\\;\\;\\bm{ qp\\bar{q} }$\\\\\nRotation matrix associated with a unit quaternion:\n$$\n\\left( \\begin{array}{ccc}\n  1 - 2y^2 - 2z^2 & 2xy - 2wz & 2xz + 2wy \\\\\n  2xy + 2wz & 1-2x^2-2z^2 & 2yz - 2wx \\\\\n  2xz - 2wy & 2yz + 2wx & 1 - 2x^2 - 2y^2\n\\end{array} \\right)\n$$\nCombination of rotations: $\\rot{\\alpha}{u}\\rot{\\beta}{v} \\longrightarrow q_{(\\alpha,u)}q_{(\\beta,v)}$\\\\\nInverse rotation: $\\inv{ q_{(\\theta,u)}} = q_{(-\\theta,u)} = q_{(\\theta,-u)} = (-w,\\vect v) = (w,\\vect -v)$ \\\\\nConversion $(w, \\vect v) \\longrightarrow ( \\theta, \\vect u)$ :\n\\begin{eqnarray*}\n\\cos(\\theta/2) &=& w\\\\\n\\sin(\\theta/2) &=& \\|\\vect v\\|\\\\\n\\vect u &=& \\vect v/\\|\\vect v\\|\n\\end{eqnarray*}\n\nThe time derivative of the unit quaternion $q$ defining the orientation of a solid with angular velocity $\\omega$ (vector of $\\RRR$, see section \\ref{sec:omega}) is: $\\dot q = \\frac{1}{2}\\omega q$.\n\n\n\\subsection{Kinematics}\n\\todo{choose omega or Omega. Simplify notations where possible.}\n\\todo{choose n or u.}\n\\subsubsection{Derivative in \\Rep{0} of a vector fixed in \\Rep{1}. Angular velocity.} \\label{sec:omega}\nConsider vector \\fixedans{\\vect u}{1}, fixed in frame \\rep{1}. Frame \\rep{1} rotates with respect to frame \\rep{0}. Consider the projection \\vecin{\\fixedans{\\vect u}{1}}{0} of this vector to \\rep{0}, which we sometimes call \\vect u for clarity, and its derivative in \\rep{0} which we write $\\derivedans{\\fixedans{\\bm u}{1}}{0}$.\n\n\nLet \\mat{R(dt)} be the rotation of \\rep{1} between time $t$ and $t+dt$. We write:\n\\begin{eqnarray}\n \\vect u(t+dt) &=& \\mat{R(dt)} \\vect u(t)\\\\\n \\vect u(t+dt) - \\vect u(t)&=& (\\mat{R(dt)}-\\ident{}) \\vect u(t) \\label{eq ri}\n\\end{eqnarray}\nLet $\\dot{\\theta}$ be the angular velocity along the rotation axis, which we set to \\vect z for clarity. The first-order Taylor series is: \n$$\n \\mat{R(dt)}-\\ident{} = \n \\left(\\begin{array}{ccc}\n  cos(\\dot{\\theta}dt)-1 & -sin(\\dot{\\theta}dt) & 0\\\\   \n   sin(\\dot{\\theta}dt)& cos(\\dot{\\theta}dt)-1& 0\\\\ \n  0 & 0 & 0 \n \\end{array}\\right)\n \\longrightarrow\n \\left(\\begin{array}{ccc}\n  0 & -\\dot{\\theta}dt & 0\\\\\n  \\dot{\\theta}dt & 0 & 0\\\\\n  0 & 0 & 0\n \\end{array}\\right) \n =\n \\dot{\\theta}dt \\oppvec{z}\n$$\nwhich can be easily extended to any rotation axis. Let $\\vecrot{1}{0}=\\dot{\\theta}\\vect n$. Dividing expression \\ref{eq ri} by $dt$ and decreasing $dt$ to $0$ gives $\\dot{\\mat R} = \\oppvec{ \\vecrot{1}{0} }$.\n\nWe can write the time derivative in \\rep{0}: $\\derivedans{\\fixedans{\\bm u}{1}}{0}  = \\vecrot{1}{0} \\wedge  \\fixedans{\\vect u}{1}$, or more simply:\n\n\\begin{equation}\\label{vrot}\n\\begin{array}{rcl}\n \\dot{\\vect u} &=& \\dot{\\mat R} \\vect u \\\\\n               &=& \\oppvec{ \\vecrot{1}{0} } \\vect u \\\\\n               &=& \\vecrot{1}{0} \\wedge \\vect u\n\\end{array}\n\\end{equation}\n \n\n\\subsection{Velocity in \\Rep{0} of a point fixed in \\Rep{1}. Velocity field.}\nWe consider the velocity $\\vfdans{A}{1}{0}$ in \\rep{0} of a point $A$ fixed in \\rep{1} while \\rep{1} moves with respect to \\rep{0}. Let $O_0$ be the origin of \\rep{0} and $O_1$ the origin of \\rep{1}. The following relation holds:\n$$ \\vfdans{A}{1}{0} = \\vfdans{O_1}{1}{0} + \\vecrot{1}{0} \\wedge \\vecf{O_1A} \\label{eq vit} \\label{eq vit solide}\n$$\n\n\\subsection{Acceleration in \\Rep{0} of  point fixed in \\Rep{1}. Acceleration field. }\nBy deriving equation \\ref{eq vit}, and based on the fact that $\\vecf{O_1A}$ is fixed in \\rep{1}, we get the acceleration of A, fixed in \\rep{1}, with respect to \\rep{0}:\n\\begin{equation}\\label{eq acc}\n \\afdans{A}{1}{0} = \\afdans{O_1}{1}{0} + \\accrot{1}{0}\\wedge \\vecf{O_1A} + \\vecrot{1}{0} \\wedge \\left( \\vecrot{1}{0} \\wedge \\vecf{O_1A} \\right)\n\\end{equation}\n\n\\subsection{Derivative in \\rep{0} of a vector defined in \\rep{1}}\nLet $(\\vect e_1, \\vect e_e, \\vect e_3)$ be a base of \\rep{1}. We have:\n\\begin{eqnarray*}\n \\vecin{u}{1} &=& \\sum_i x_i \\vect e_i\\\\\n \\dot{\\vect u} &=& \\sum_i \\dot x_i \\vect e_i + \\sum_i x_i \\dot{\\vect e}_i\n\\end{eqnarray*}\nand thus:\n\\begin{equation}\\label{eq vec mob}\n \\derivedans{u}{0} = \\derivedans{u}{1} + \\vecrot{1}{0} \\wedge \\vect u\n\\end{equation}\n\n\n\\subsection{Velocity in \\rep{0} of a point moving in \\rep{1}.}\nLet \\vmdans{A}{1} be the velocity of point $A$ with respect to \\rep{1}. We have:\n\\begin{equation}\\label{eq vit mob}\n\\vmdans{A}{0} = \\vmdans{A}{1} + \\vfdans{O_1}{1}{0} + \\vecrot{1}{0} \\wedge \\vecf{O_1A}\n\\end{equation}\nNote that $O_1$ being the origin of frame \\rep{1}, we have $\\vmdans{O_1}{0} = \\vfdans{O_1}{1}{0}$.\n\n\\subsection{Acceleration in \\rep{0} of a point moving in \\rep{1}. Coriolis acceleration.}\nEBy deriving equation \\ref{eq vit mob} nous we get:\n$$\n \\amdans{A}{0} = \\underbrace{\\amdans{A}{1} + \\vecrot{1}{0}\\wedge \\vmdans{A}{1}}_{\\overset{\\circ}{\\vmdans{A}{1}}} + \\amdans{O_1}{0} + \\underbrace{\\accrot{1}{0}\\wedge \\vect{O_1}{A} + \\vecrot{1}{0}\\wedge \\vmdans{A}{1} + \\vecrot{1}{0} \\wedge (\\vecrot{1}{0}\\wedge \\vecf{O_1A})}_{\\overset{\\circ}{\\vecrot{1}{0} \\wedge \\vecf{O_1A}}}\n$$\nor:\n\\begin{equation}\\label{eq acc mob}\n \\amdans{A}{0} = \\amdans{A}{1} +  \\amdans{O_1}{0} + \\vecrot{1}{0} \\wedge (\\vecrot{1}{0}\\wedge \\vecf{O_1A}) + 2\\vecrot{1}{0}\\wedge \\vmdans{A}{1}\n\\end{equation}\nwith:\n\\begin{itemize}\n\\item $\\amdans{A}{1} = \\sum_i \\ddot x_i \\vect e_i$ relative acceleration\n\\item $\\amdans{O_1}{0}$ frame acceleration (?)\n\\item $\\vecrot{1}{0} \\wedge (\\vecrot{1}{0}\\wedge \\vecf{O_1A})$ centripetal acceleration\n\\item $2\\vecrot{1}{0}\\wedge \\vmdans{A}{1}$ Coriolis acceleration\n\\end{itemize}\n\n\n\\subsection{Dynamics}\nSolids accelerate linearly due to forces, and accelerate angularly due to torques. A given torque has the same value everywhere in the solid. However, a given force generates different torques at different points. The torque $\\tau$ applied at point $c$ generated by a force $f$ applied at point $b$ is: $\\tau=cb\\wedge f$.\n\nThe acceleration $\\ddot c$ of the mass center of a solid and its angular acceleration $\\dot \\omega$ with respect to the world are given by the relations:\n\n    \\begin{eqnarray*}\n        m \\bf{ \\ddot c } = \\sum\\bf{f_{ext}} \\\\%\\label{eq:PFD1}\\\\\n        \\bf{ I_M \\dot \\omega } + \\bm{ \\omega \\times I_M \\omega} = \\sum\\bf{\\tau_{ext}} %\\label{eq:PFD2}\n    \\end{eqnarray*}\nwhere $m$ is the mass of the solid, $\\sum {\\bf f_{ext}}$ is the sum of the forces applied to the solid, ${\\bf I_M}$ is the inertia matrix et $\\sum {\\bf \\tau_{ext}}$ the sum of the torques applied to the solid and expressed at its mass center. The inertia matrix is given by:\n$${\\bf I_M} = \\int_x \\int_y \\int_z \\rho (x,y,z)\\begin{bmatrix}  y^2+z^2 & -xy & -xz \\\\ -xy & x^2+z^2 & -yz \\\\ -xz & -yz & x^2+y^2 \\end{bmatrix} dx dy dz$$\nwhere $\\rho(x,y,z)$ is the volumic mass of the naterial (in $kg.m^{-3}$).\n\n\n", "meta": {"hexsha": "00930c8b52e37aeddd42fcbb5b260dfb80dce92a", "size": 16576, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/introduction-old/physicallyBasedAnimation.tex", "max_stars_repo_name": "sofa-framework/issofa", "max_stars_repo_head_hexsha": "94855f488465bc3ed41223cbde987581dfca5389", "max_stars_repo_licenses": ["OML"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/introduction-old/physicallyBasedAnimation.tex", "max_issues_repo_name": "sofa-framework/issofa", "max_issues_repo_head_hexsha": "94855f488465bc3ed41223cbde987581dfca5389", "max_issues_repo_licenses": ["OML"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/introduction-old/physicallyBasedAnimation.tex", "max_forks_repo_name": "sofa-framework/issofa", "max_forks_repo_head_hexsha": "94855f488465bc3ed41223cbde987581dfca5389", "max_forks_repo_licenses": ["OML"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.7062706271, "max_line_length": 514, "alphanum_fraction": 0.6834580116, "num_tokens": 5456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318195, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7181768489207645}}
{"text": "%!TEX root = ../TTT4150-Summary.tex\n\\section{Kalman filtering}\n\nA \\emph{Kalman filter} recursively estimates the state of a process, such that it minimizes the mean squared error. Or, maximize separation of signal and noise.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Process model}\n\nThe \\emph{discretized} process is\n\\begin{equation}\n\\begin{split}\n\tx_k &= \\Phi x_{x-1} + w_{k-1} \\\\\n\tz_k &= H x_k + v_k\n\\end{split}\n\\end{equation}\nwhere\n\\begin{itemize}\n\t\\item $\\Phi$ is the (state) \\emph{transition matrix},\n\t\\item $H$ is the \\emph{design matrix},\n\t\\item $w_k$ is random white process noise $p(w) \\sim N(0,Q)$, and\n\t\\item $v_k$ is random white measurement noise $p(v) \\sim N(0,R)$.\n\\end{itemize}\n\nThe transition matrix is calculated from the continuous-time representation\n\\begin{equation}\n\t\\dot{x} = F x + G u\n\\end{equation}\nas\n\\begin{equation}\n\t\\Phi = \\euler^{F \\Delta t} = I + F \\Delta t + \\frac{(F \\Delta t)^2}{2!} + \\dots\n\\end{equation}\nor, for time-variant $F$\n\\begin{equation}\n\t\\Phi_k = \\laplace{(sI - F)^{-1}}_{t = \\Delta t}.\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Method}\n\nThe goal is to compute an \\emph{a posteriori} estimate\\footnote{\\emph{After} measuring.} $\\hat{x}_k$ based on an \\emph{a priori} estimate\\footnote{\\emph{Before} measuring.} $\\hat{x}_k^-$, a measurement $z_k$, and a measurement prediction $H \\hat{x}_k^-$. This is how we do it:\n\\begin{equation}\n\t\\hat{x}_k = \\hat{x}_k^- + K_k(z_k - H \\hat{x}_k^-)\n\\end{equation}\n\nThe gain matrix $K$ is chosen to minimize the a posteriori error covariance $P_k = E \\left[ e_k e_k\\T \\right]$, where $e_k \\equiv x_k - \\hat{x}_k$. Some math leads to\n\\begin{equation}\n\tK_k = P_k^- H\\T \\left( H P_k^- H\\T + R \\right)^{-1}.\n\\end{equation}\nWe have $\\lim_{R \\rightarrow 0} K_k = H^{-1}$, which gives $\\hat{x}_k = H^{-1} z_k$. Makes sense, because zero measurement error covariance $R$ should let us trust the measurement fully. We also have $\\lim_{P_k^- \\rightarrow 0} K_k = 0$, giving $\\hat{x}_k = \\hat{x}_k^-$. Also makes sense, because zero a priori estimate error covariance $P_k^-$ should make us not trust the measurement at all.\n\nThese equations are split into the time update equations\n\\begin{equation}\n\\begin{split}\n\t\\hat{x}_k^- &= \\Phi_{k-1} \\hat{x}_{k-1} \\\\\n\tP_k^-       &= \\Phi_{k-1} \\hat{P}_{k-1} \\Phi_{k-1}\\T + Q\n\\end{split}\n\\end{equation}\nand the measurement update equations\n\\begin{equation}\n\\begin{split}\n\tK_k       &= P_k^- H\\T \\left( H P_k^- H\\T + R \\right)^{-1} \\\\\n\t\\hat{x}_k &= \\hat{x}_k^- + K_k(z_k - H \\hat{x}_k^-) \\\\\n\t\\hat{P}_k       &= \\left( I - K_k H \\right) P_k^-.\n\\end{split}\n\\end{equation}\n\nOften, $Q$ and $R$ are simply considered tuning parameters. Large $R$ means we expect a large measurement error variance, and the filter converges slowly because it cannot trust the measurements. A small $R$ does the opposite: Converges fast, but possibly so fast that the estimate follows the measurement noise.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{IMU + GNSS integration}\n\nGNSS has good long time accuracy, and gives measurements without drift. INS has good short time accuracy, but drifts a lot. Combining both in a \\emph{complementary filter} gives ``the best of both worlds''.\n", "meta": {"hexsha": "dd19f3b630a7e4d63abfd3db36b7f5f44c690e48", "size": 3276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTT4150 Navigation systems/tex/sec-kalman.tex", "max_stars_repo_name": "jakoblover/ntnu-course-summaries", "max_stars_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-11T02:42:40.000Z", "max_issues_repo_path": "TTT4150 Navigation systems/tex/sec-kalman.tex", "max_issues_repo_name": "jakoblover/ntnu-course-summaries", "max_issues_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TTT4150 Navigation systems/tex/sec-kalman.tex", "max_forks_repo_name": "jakoblover/ntnu-course-summaries", "max_forks_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.8767123288, "max_line_length": 394, "alphanum_fraction": 0.648046398, "num_tokens": 1035, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.7181768438319666}}
{"text": "\\section{Cartesian Tensors}\r\nIn this section, we are only interested in the Cartesian coordinates in a right-handed basis.\r\n\\subsection{A Closer Look at Vectors}\r\nGiven the basis, we can write $\\underline{x}\\in\\mathbb R^3$ in the form $x_i\\underline{e_i}$ where the summation convention is used.\r\nWe should not identify the vector $\\underline{x}$ with component $x_i$ since we may want to choose another basis for certain purposes.\r\nBut if we have $\\underline{x}=x_i\\underline{e_i}=x_i'\\underline{e_i'}$ for right-handed bases $\\underline{e_i},\\underline{e_i'}$, then\r\n$$x_i'=x_j'\\delta_{ij}=x_j'\\underline{e_j'}\\cdot\\underline{e_i'}=\\underline{e_i'}\\cdot(x_j'\\underline{e_j'})=\\underline{e_i'}\\cdot(x_j\\underline{e_j})=x_j\\underline{e_i'}\\cdot\\underline{e_j}=R_{ij}x_j,R_{ij}=\\underline{e_i'}\\cdot\\underline{e_j}$$\r\nPlaying the same game yields $x_i=\\underline{e_i}\\cdot\\underline{e_j'}x_j'=R_{ji}x_j'$.\r\nCombining them gives $x_i=R_{ji}R_{jk}x_k$, so $0=(R_{ji}R_{jk}-\\delta_{ik})x_k$, which has to hold for any choice of $x_k$, therefore $R_{ji}R_{jk}=\\delta_{ik}$.\r\nIf we set $R$ to be the matrix with entries $R_{ij}$, then what we obtained above means $R^\\top R=I$.\r\nSo $R\\in\\operatorname{O}(3)$.\r\nNow $x_i\\underline{e_i}=x_i'\\underline{e_i'}=R_{ij}x_j\\underline{e_i'}=R_{ji}x_i\\underline{e_j'}$, so $\\underline{e_i}=R_{ji}\\underline{e_j'}$, so $R$ has to be in $\\operatorname{SO}(3)$ since both bases are right-handed.\r\nIn summary, changing from $\\{\\underline{e_i}\\}$ to $\\{\\underline{e_i'}\\}$ induces the change in components by multiplication of a matrix in $\\operatorname{SO}(3)$, i.e. $x_i'=R_{ij}x_j$.\r\nWe call such objects rank-$1$ tensors of vectors.\r\n\\subsection{A Closer Look at Scalars}\r\nConsider $\\sigma=\\underline{a}\\cdot\\underline{b}$.\r\nUsing $\\underline{e_i}$ with $\\underline{a}=a_i\\underline{e_i},\\underline{b}=b_i\\underline{e_i}$, then $\\sigma=a_ib_j\\underline{e_i}\\cdot\\underline{e_j}=a_ib_j\\delta{ij}=a_ib_i$.\r\nIf we used another set of basis vectors $\\underline{a}=a_i'\\underline{e_i'},\\underline{b}=b_i'\\underline{e_i'}$, then $\\sigma'=a_i'b_i'$ has\r\n$$\\sigma'=a_i'b_i'=R_{ij}a_jR_{ik}b_k=R_{ij}R_{ik}a_jb_k=\\delta_{jk}a_jb_k=a_jb_j=\\sigma$$\r\nas one may have expected.\r\nCall such transformation of scalars rank-$0$ tensors.\r\n\\subsection{A Closer Look at Linear Maps}\r\nConsider linear map $T:\\mathbb R^3\\to\\mathbb R^3$ with $\\underline{x}\\mapsto\\underline{y}=T(\\underline{x})=\\underline{x}-(\\underline{x}\\cdot\\underline{n})\\underline{n}$ which is jus the projection of $\\underline{x}$ down the plane with normal $\\underline{n}$.\r\nIf we use basis $\\{\\underline{e_i}\\}$, then\r\n$$y_i\\underline{e_i}=T(x_j\\underline{e_j})=x_jT(\\underline{e_j})=x_j(\\underline{e_j}-n_in_j\\underline{e_i})=x_j(\\delta_{ij}-n_in_j)\\underline{e_i}$$\r\nSo $y_i=T_{ij}x_j$ where $T_{ij}=\\delta_{ij}-n_in_j$.\r\nIf we used another basis $\\underline{e_i'}$, we would have got $y_i'=T_{ij}'x_j'$ where $T_{ij}'=\\delta_{ij}-n_i'n_j'$.\r\nNote that using $n_i'=R_{ip}n_p$, etc., we have\r\n$$T_{ij}'=\\delta{ij}-R_{ip}R_{jq}n_pn_q=R_{ip}R_{jq}(\\delta_{pq}-n_pn_q)=R_{ip}T_{pq}R_{jq}$$\r\nSo changing from one set of right handed orthonormal basis to another induces change in components of linear map $T$ (as a matrix) by $T_{ij}'=R_{ip}R_{jq}T_{pq}$, or $T'=RTR^\\top$.\r\nWe call objects changing like that to be rank-$2$ tensors.\r\n\\subsection{Cartesian Tensors of General Rank}\r\n\\begin{definition}\r\n    An object with components $T_{i_1\\cdots i_n}$ is called a tensor of rank $n$ if its component transform according to $T_{i_1\\cdots i_n}'=R_{i_1j_1}\\cdots R_{i_nj_n}T_{j_1\\cdots j_n}$ when we change from one right-handed Cartesian basis $\\{\\underline{e_i}\\}$ to $\\{\\underline{e_i'}\\}$ where $\\det R=1$ and $R_{i_pi_r}R_{i_qi_r}=\\delta_{i_pi_q}$ for $p,q,r$ distinct.\r\n\\end{definition}\r\nNote that $R_{ij}$'s are rotation matrices.\r\n\\begin{example}\r\n    1. If $u_{i_1},v_{i_2},\\ldots,w_{i_n}$ are components of set of $n$ vectors, then $T_{i_1\\cdots i_k}=u_{i_1}v_{i_2}\\cdots w_{i_n}$ is a tensor of rank $n$.\r\n    Suppose we change from $\\{\\underline{e_i}\\}$ to $\\{\\underline{e_i'}\\}$, then\r\n    $$T_{i_1\\cdots i_n}'=u_{i_1}'v_{i_2}'\\cdots w_{i_n}'=R_{i_1j_1}u_{j_1}R_{i_2j_2}u_{j_2}\\cdots R_{i_nj_n}u_{j_n}=R_{i_1j_1}\\cdots R_{i_nj_n}T_{j_1\\cdots j_n}$$\r\n    2. The Kronecker delta $\\delta_{ij}$ is a tensor of rank $2$ as it is independent of choice of basis.\r\n    Indeed, we want $R_{ip}R_{jq}\\delta_{pq}=R_{ip}R_{jp}=\\delta_{ij}=\\delta_{ij}'$.\\\\\r\n    3. The Levi-Civita epsilon again is independent of choice of basis, so $\\epsilon_{ijk}'=\\epsilon_{ijk}$.\r\n    We have\r\n    $$R_{ip}R_{jq}R_{kr}\\epsilon_{pqr}=\\det(R)\\epsilon_{ijk}=\\epsilon_{ijk}=\\epsilon_{ijk}'$$\r\n    So it is a tensor of rank $3$.\\\\\r\n    4. Experimental evidence suggests a linear relationship between code $j$ produced in some medium that is exposed to electric field $\\underline{E}$.\r\n    So a given Cartesian basis $\\{\\underline{e_i}\\}$, we must have numbers $\\sigma_{ij}$ such that $J_i=\\sigma_{ij}E_j$, so if we change basis from $\\{\\underline{e_i}\\}$ to $\\{\\underline{e_i'}\\}$, then $\\sigma_{ij}'E_j'=J_i'=R_{ip}J_p=R_{ip}\\sigma_{pq}E_q=R_{ip}R_{jq}\\sigma_{pq}E_j'$, so $\\sigma_{ij}'=R_{ip}R_{jq}\\sigma_{pq}$.\r\n    So $\\sigma$ is a tensor of rank $2$.\r\n    This is an example of something called the quotient theorem, which will be proved at the end of the course.\r\n\\end{example}\r\n\\begin{example}[Non-example]\r\n    Not every array of numbers is a tensor.\r\n    For example, in some given basis $\\{\\underline{e_i}\\}$ we define an array\r\n    $$(a_{ij})=\\begin{pmatrix}\r\n        1&2&3\\\\\r\n        4&5&6\\\\\r\n        7&8&\\pi\r\n    \\end{pmatrix}$$\r\n    and $a_{ij}=0$ in any other choice of basis, then $a_{ij}$ is not the component of a second rank tensor.\r\n\\end{example}\r\n\\begin{definition}\r\n    If $a,b$ are rank-$n$ tensors with components $a_{i_1\\cdots i_n},b_{i_1\\cdots i_n}$, then the object $a+b$ by $(a+b)_{i_1\\cdots i_n}=a_{i_1\\cdots i_n}+b_{i_1\\cdots i_n}$ is also a tensor of rank $n$.\r\n    If $\\alpha$ is a scalar, then we can define the tensor $\\alpha a$ by $(\\alpha a)_{i_1\\cdots i_n}=\\alpha a_{i_1\\cdots i_n}$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    If $U$ is a tensor of rank $n$ and $V$ a tensor of rank $m$, then their tensor product $U\\otimes V$ is a tensor of rank $m+n$ defined by\r\n    $$(U\\otimes V)_{i_1\\cdots i_nj_1\\cdots j_m}=U_{i_1\\cdots i_n}V_{j_1\\cdots j_m}$$\r\n\\end{definition}\r\n\\begin{definition}\r\n    Suppose $n\\ge 2$ and $T$ is a tensor of rank $n$, we can define a new tensor of rank $n-2$ by contraction on two indices (i.e. summing over two chosen indices).\r\n\\end{definition}\r\nIt is easy to check that these are indeed all tensors.\r\nWe say $T_{i_1\\cdots i_n}$ is symmetric in $i_1,i_2$ if $T_{i_1i_2\\cdots i_n}=T_{i_2i_1\\cdots i_n}$.\r\nThis is obviously well-behaved.\r\nNote that we can generalize it to symmetries in any pair of indices.\r\nWe say it is antisymmetric in $i_1,i_2$ if $T_{i_1i_2\\cdots i_n}=-T_{i_2i_1\\cdots i_n}$.\r\nWe say it is totally symmetric if it is symmetric in each pair of indices, and totally antisymmetric if it is antisymmetric in any two indices.\r\n\\begin{example}\r\n    Both $\\delta_{ij}$ and $a_ia_ja_k$ are totally symmetric tensors.\r\n    Also $\\epsilon_{ijk}$ is totally antisymmetric.\r\n    In fact, one can see immediately that the Levi-Civita $\\epsilon$ is the only antisymmetric tensor of rank $3$ up to proportionality.\r\n\\end{example}\r\nAlso, there are no nonzero totally antisymmetric tensor of rank $n\\ge 4$ in $\\mathbb R^3$.\r\n\\subsection{Tensor Calculus}\r\nWe say $T_{i_1\\cdots i_n}(\\underline{x})$ is a tensor field of rank $n$ if for each $\\underline{x_0}\\in\\mathbb R^3$, $T_{i_1\\cdots i_n}(\\underline{x_0})$ is a tensor of rank $n$.\r\nNote that $x_i'=R_{ij}x_j$ when we transform to one orthonormal right-handed basis to the other.\r\nAlso $x_j=R_{kj}x_k'$.\r\nBy the chain rule, $\\partial/\\partial x_i'=(\\partial x_j/\\partial x_i')(\\partial/\\partial x_j)=R_{ij}\\partial/\\partial x_j$.\r\n\\begin{proposition}\r\n    Suppose $T_{i_1\\cdots i_n}(\\underline{x})$ is a tensor field of rank $n$, then\r\n    $$A_{j_1\\cdots j_mi_1\\cdots i_n}(\\underline{x})=\\frac{\\partial}{\\partial x_{j_1}}\\cdots\\frac{\\partial}{\\partial x_{j_m}}T_{i_1\\cdots i_n}(\\underline{x})$$\r\n    is a tensor field of rank $m+n$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    From definition and chain rule.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. If $\\phi$ is a scalar field, then components of $\\nabla\\phi$ changes according to $[\\nabla\\phi]_i'=\\partial\\phi/\\partial x_i'=R_{ij}\\partial\\phi/\\partial x_j=R_{ij}[\\nabla\\phi]_j$, so $\\nabla\\phi$ is a rank $1$ tensor field (or vector field).\\\\\r\n    2. If $\\underline{v}$ is a vector field, then using the same trick we can see that $\\nabla\\cdot\\underline{v}$ is a rank $0$ tensor (or scalar field).\\\\\r\n    3. If $\\underline{v}$ is a vector field, so is $\\nabla\\times\\underline{v}$.\r\n\\end{example}\r\n\\begin{example}\r\n    Recall the divergence theorem for vector fields:\r\n    $$\\int_V\\nabla\\cdot\\underline{F}\\,\\mathrm dV=\\int_{\\partial V}\\underline{F}\\cdot\\mathrm dS$$\r\n    Equivalently (or not),\r\n    $$\\int_V\\frac{\\partial F_i}{\\partial x_i}\\,\\mathrm dV=\\int_{\\partial V}v_in_i\\,\\mathrm dS$$\r\n    Turns out we can do this on tensor fields as well, where we have\r\n    $$\\int_V\\frac{\\partial}{\\partial x_{i_k}}T_{i_1\\cdots i_n}\\,\\mathrm dV=\\int_{\\partial V}T_{i_1\\cdots i_n}n_{i_k}\\,\\mathrm dS$$\r\n    which follows from the case for vector fields on the field\r\n    $$v_{i_k}=a_{i_1}b_{i_2}\\cdots c_{i_n}T_{i_1\\cdots i_k\\cdots i_n}$$\r\n\\end{example}\r\n\\subsection{Tensors of Rank 2}\r\nAn arbitrary rank-$2$ tensor $T_{ij}$ can be written as\r\n$$T_{ij}=\\frac{1}{2}(T_{ij}+T_{ji})+\\frac{1}{2}(T_{ij}-T_{ji})=S_{ij}+A_{ij}$$\r\nSo $S_{ij}$ is symmetric and $A_{ij}$ is antisymmetric.\r\nNote that $S_{ij}$ only has $6$ independent components, and $A_{ij}$ has $3$ independent components.\r\nThis is all consistent since a rank $3$ tensor has $9=6+3$ independent components.\r\n\\begin{proposition}\r\n    A rank $2$ tensor can be written as $T_{ij}=S_{ij}+\\epsilon_{ijk}\\omega_k$ where $S_{ij}$ is symmetric and $\\omega_k=\\epsilon_{kpq}T_{pq}/2$.\r\n    Also, this decomposition is unique.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Just expand by taking $S_{ij}=(T_{ij}+T_{ji})/2$ for existence.\r\n    As for uniqueness, suppose $S_{ij}+\\epsilon_{ijk}\\omega_k=\\tilde{S}_{ij}+\\epsilon_{ijk}\\tilde\\omega_k$.\r\n    But we can take the symmetric part of each sides to get $S_{ij}=\\tilde{S}_{ij}$, hence $\\omega_k=\\tilde\\omega_k$.\r\n\\end{proof}\r\n\\begin{example}\r\n    Suppose each point $\\underline{x}$ in an elastic body undergoes small displacement $\\underline{u}(\\underline{x})$, then consider two points, initially seperated by $\\delta\\underline{x}$, then after the displacement they are seperated by\r\n    $$\\underline{u}(\\underline{x}+\\delta\\underline{x})+\\underline{x}+\\delta\\underline{x}-\\underline{u}(\\underline{x})-\\underline{x}=\\delta\\underline{x}+(\\underline{u}(\\underline{x}+\\delta\\underline{x})-\\underline{u}(\\underline{x}))$$\r\n    So the change in seperation would be $\\underline{\\underline{x}+\\delta\\underline{x}}-\\underline{u}(\\underline{x})$.\r\n    Now using Cartesian and suffix notation, we have $u_i(\\underline{x}+\\delta\\underline{x})-u_i(\\underline{x})=\\delta x_j\\partial u_i/\\partial x_j+o(|\\delta\\underline{x}|)$\r\n    We write $\\partial u_i/\\partial x_j=e_{ij}+\\epsilon_{ijk}\\omega_k$ where\r\n    $$e_{ij}=\\frac{1}{2}\\left(\\frac{\\partial u_i}{\\partial x_j}+\\frac{\\partial u_j}{\\partial x_i}\\right),\\omega_k=\\frac{1}{2}\\epsilon_{kpq}\\partial u_p/\\partial x_q=-\\frac{1}{2}[\\nabla\\times\\underline{u}]_k$$\r\n    $e_{ij}$ here is called the linear strain tensor.\r\n    So we have\r\n    $$\\underline{u}(\\underline{x}+\\delta\\underline{x})-\\underline{u}(\\underline{x})=e_{ij}\\delta x_j+[\\delta\\underline{x}\\times\\underline{\\omega}]_i+o(|\\delta\\underline{x}|)$$\r\n    So $e_{ij}$ tells you how the material strains,\r\n\\end{example}\r\nSuppose a body occupies a volume $V$ has density $\\rho(\\underline{x})$ and suppose each point is rotating with angular velocity $\\underline{\\omega}$ through the origin, then the velocity of the point $\\underline{x}$ is $\\underline{\\omega}\\times\\underline{x}$.\r\nThen the total angular momentum is\r\n$$\\underline{L}=\\int_V\\rho(\\underline{x})(\\underline{x}\\times\\underline{v})\\,\\mathrm dV=\\int_V\\rho(\\underline{x})(\\underline{x}\\times(\\underline{\\omega}\\times\\underline{x}))\\,\\mathrm dV$$\r\nUsing a right-handed basis $\\{\\underline{e_i}\\}$ of $\\mathbb R^3$, we have\r\n$$L_i=\\int_{\\mathcal V}\\rho(\\underline{x})(x_kx_k\\omega_i-x_ix_j\\omega_j)\\,\\mathrm dV=I_{ij}\\omega_j,I_{ij}=\\int_{\\mathcal V}\\rho(\\underline{x})(x_kx_k\\delta_{ij}-x_ix_j)\\,\\mathrm dV$$\r\nwhere $\\mathcal V=\\{(x_1,x_2,x_3):\\underline{x}=x_i\\underline{e_i}\\in V\\}$.\r\nIf we change our basis to another $\\{\\underline{e_i'}\\}$, then we have (with $x_i'=R_{ij}x_j$)\r\n\\begin{align*}\r\n    I_{ij}'&=\\int_{\\mathcal V'}\\rho(\\underline{x})(x_k'x_k'\\delta_{ij}-x_i'x_j')\\,\\mathrm dV\\\\\r\n    &=R_{ip}R_{jq}\\int_{\\mathcal V}\\rho(\\underline{x})(x_kx_k\\delta_{pq}-x_px_q)|J|\\,\\mathrm dV\\\\\r\n    &=R_{ip}R_{jq}I_{pq}\r\n\\end{align*}\r\nSo $I_{ij}$ is really a tensor.\r\nWe call it the inertial tensor.\r\n\\begin{example}\r\n    Consider an ellipsoid\r\n    $$\\frac{x_1^2}{a^2}+\\frac{x_2^2}{b^2}+\\frac{x_3^2}{c^2}=1$$\r\n    with $\\rho(\\underline{x})\\equiv\\rho_0$.\r\n    By symmetry, if $i\\neq j$, then $I_{ij}=0$.\r\n    Now\r\n    $$I_{11}=\\rho_0\\int_Vx_2^2x_3^2\\,\\mathrm dV$$\r\n    By using scaled spherical polars $x_1=ar\\cos\\phi\\sin\\theta,x_2=br\\sin\\phi\\sin\\theta,x_3=cr\\cos\\theta$, so $\\mathrm dV=abcr^2\\sin\\theta\\,\\mathrm dr\\,\\mathrm d\\theta\\,\\mathrm d\\phi$, we have\r\n    $$I_{11}=\\int_0^{2\\pi}\\int_0^\\pi\\int_0^1 r^2(b^2\\sin^2\\phi\\sin^2\\theta+c^2\\cos^2\\theta)abcr^2\\sin\\theta\\,\\mathrm dr\\,\\mathrm d\\theta\\,\\mathrm d\\phi=\\frac{M}{5}(b^2+c^2)$$\r\n    So\r\n    $$(I_{ij})=\\frac{M}{5}\\begin{pmatrix}\r\n        b^2+c^2&0&0\\\\\r\n        0&a^2+c^2&0\\\\\r\n        0&0&a^2+b^2\r\n    \\end{pmatrix}$$\r\n    If in particular $a=b=c$, then $I_{ij}\\propto\\delta_{ij}$.\r\n\\end{example}\r\n\\begin{proposition}\r\n    If $T_{ij}$ is real and symmetric, then there exists choice of basis in which $T_{ij}=0$ whenever $i\\neq j$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    In Vectors \\& Matrices.\r\n\\end{proof}\r\n\\subsection{Isotropic Tensors}\r\n\\begin{definition}\r\n    Say $T_{i_1\\cdots i_n}$ is isotropic if $T_{i_1\\cdots i_n}'=T_{i_1\\cdots i_n}$ when transforming from a basis to the other.\r\n    That is, for any rotational $R$, we have\r\n    $$T_{i_1\\cdots i_n}=R_{i_1j_1}\\cdots R_{i_nj_n}T_{j_1\\cdots j_n}$$\r\n\\end{definition}\r\n\\begin{example}\r\n    1. Scalars are isotropic.\\\\\r\n    2. $\\delta_{ij}$ is isotropic.\\\\\r\n    3. $\\epsilon_{ijk}$ is also isotropic.\r\n\\end{example}\r\nIt turns out that we can classify all isotropic tensors in $\\mathbb R^3$, and we can generalise this to $\\mathbb R^n$.\r\nWe state this in the proposition below, which we shall provide a partial proof.\r\n\\begin{proposition}\r\n    In $\\mathbb R^3$:\\\\\r\n    1. All scalars are isotropic.\\\\\r\n    2. There are no nonzero isotropic rank-$1$ tensors (vectors).\\\\\r\n    3. Most general isotropic tensor of rank $2$ is $\\alpha\\delta_{ij}$ where $\\alpha$ is a scalar.\\\\\r\n    4. Most general isotropic tensor of rank $3$ is $\\beta\\epsilon_{ijk}$ where $\\beta$ is a scalar.\\\\\r\n    5. Most general isotropic tensor of rank $4$ is $\\alpha\\delta_{ij}\\delta_{kl}+\\beta\\delta_{il}\\delta_{jk}+\\gamma\\delta_{ik}\\delta_{jl}$ where $\\alpha,\\beta,\\gamma$ are scalars.\\\\\r\n    6. Tensors of higher rank is a linear combination of $\\epsilon$'s and $\\delta$'s, e.g. $\\delta_{ij}\\epsilon_{pqr}$ is an isotropic rank $5$ tensor.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    1 is obvious.\\\\\r\n    For 2, assume $v_i$ is an isotropic tensor of rank $1$, then $v_i=R_{ij}v_j$ for all choice of rotation $R$.\r\n    If we choose\r\n    $$(R_{ij})=\\begin{pmatrix}\r\n        -1&0&0\\\\\r\n        0&-1&0\\\\\r\n        0&0&1\r\n    \\end{pmatrix}$$\r\n    then we immediately get $v_1=v_2=0$.\r\n    Similarly $v_3=0$, so $v=0$.\\\\\r\n    For 3, suppose $T_{ij}$ is isotropic, then $T_{ij}=R_{ip}R_{jq}T_{pq}$ for any rotation $R$.\r\n    Choose\r\n    $$(R_{ij})=\\begin{pmatrix}\r\n        0&1&0\\\\\r\n        -1&0&0\\\\\r\n        0&0&1\r\n    \\end{pmatrix}$$\r\n    Then\r\n    $$T_{23}=R_{2p}R_{3q}T_{pq}=R_{21}R_{33}T_{13}=-T_{13},T_{13}=R_{1p}R_{3q}T_{pq}=R_{12}R_{33}T_{23}=T_{23}$$\r\n    so we conclude $T_{13}=T_{23}=0$.\r\n    Now $T_{11}=R_{1p}R_{1q}T_{pq}=T_{22}$, so $T_{11}=T_{22}$.\r\n    Consider another rotation matrix\r\n    $$(R_{ij})=\\begin{pmatrix}\r\n        1&0&0\\\\\r\n        0&0&1\\\\\r\n        0&-1&0\r\n    \\end{pmatrix}$$\r\n    then\r\n    $$T_{31}=R_{3p}R_{1q}T_{pq}=R_{32}R_{11}R_{21}=-R_{21},T_{21}=R_{2p}R_{1q}T_{pq}=R_{23}R_{11}T_{31}=T_{31}$$\r\n    So $T_{31}=T_{21}=0$.\r\n    Lastly\r\n    $$T_{32}=R_{3p}R_{2q}T_{pq}=R_{32}R_{23}T_{23}=0,T_{12}=R_{1p}R_{2q}T_{pq}=R_{11}R_{23}T_{13}=0$$\r\n    So in conclusion $T_{ij}=0$ whenever $i\\neq j$\r\n    Also $T_{33}=R_{3p}R_{3q}T_{pq}=R_{32}R_{32}T_{22}=T_{22}$, so $T_{11}=T_{22}=T_{33}$.\r\n    Hence $T_{ij}=T_{11}\\delta_{ij}$.\r\n    Take $\\alpha=T_{11}$ completes the proof.\\\\\r\n    4,5,6 can be proved by similar idea.\r\n\\end{proof}\r\nConsider tensors of the form\r\n$$T_{i_1\\cdots i_n}=\\int_{V_R}f(r)x_{i_1}\\cdots x_{i_n}\\,\\mathrm dV$$\r\nwhere $r^2=x_px_p$ and $V_R$ is a ball of radius $R$ centered at $0$.\r\nThen when we go to another frame of reference by $R$,\r\n$$T_{i_1\\cdots i_n}'=R_{i_1j_1}\\cdots R_{i_nj_n}T_{j_1\\cdots j_n}=R_{i_1j_1}\\cdots R_{i_nj_n}\\int_{V_R}f(r')x_{j_1}\\cdots x_{j_n}\\,\\mathrm dV$$\r\nwhere $r'^2=r^2$ since $R$ is a rotation.\r\nSet $y_{i_k}=R_{i_kj_k}x_{j_k}$ and do a change of variable in this way, we get\r\n$$T_{i_1\\cdots i_n}'=\\int_{V_R}f(r')y_{i_1}\\cdots y_{i_n}\\,\\mathrm dV=T_{i_1\\cdots i_n}$$\r\nSince $V_R$ is indeendent of rotation.\r\nSo $T$ is indeed isotropic.\r\nTaking $R\\to\\infty$ allows us to view it as an integration over $\\mathbb R^3$.\r\n\\begin{example}\r\n    Consider\r\n    $$T_{ij}=\\int_{\\mathbb R^3}e^{-r^5}x_ix_j\\,\\mathrm dV=T_{11}\\delta_{ij}$$\r\n    by our classification theorem.\r\n    Also $T_{ii}=4\\pi/5$, so $T_{ij}=4\\pi\\delta_{ij}/15$.\r\n\\end{example}\r\n\\begin{example}\r\n    The inertial tensor of a ball with radius $R>0$ and constant density $\\rho_0$, so\r\n    $$I_{ij}=\\rho_0\\int_{V_R}x_kx_k\\delta_{ij}-x_kx_j\\,\\mathrm dV$$\r\n    The right hand side is the sum of two isotropic tensor of rank $2$, so $I_{ij}=\\alpha\\delta_{ij}$.\r\n    Contract on $i,j$ gives $\\alpha=2MR^2/5$ where $M=\\rho_0 4\\pi R^3/3$.\r\n\\end{example}\r\n\\subsection{Multilinear Maps and Quotient Theorem}\r\nGiven some right-handed orthonormal basis, let $T_{ij}$ denote the components of rank $2$ tensor.\r\nDefine a bilinear map $t:\\mathbb R^3\\times\\mathbb R^3\\to\\mathbb R$ by $t(\\underline{a},\\underline{b})=T_{ij}a_ib_j$, which one can note is independent of the basis we chose hence the map is well-defined.\r\nConversely, for a bilinear $t:\\mathbb R^3\\times\\mathbb R^3\\to\\mathbb R$, and we choose a certain basis $\\{\\underline{e_i}\\}$, then we can write $t(\\underline{a},\\underline{b})=a_ib_jt(\\underline{e_i},\\underline{e_j})$, so $T_{ij}=t(\\underline{e_i},\\underline{e_j})$ is a rank-$2$ tensor since  $t$ is bilinear.\r\nThis gives a one-to-one correspondence between bilinear maps and rank-$2$ tensors.\r\nIn particular, if a (bilinear) map $(\\underline{a},\\underline{b})\\mapsto T_{ij}a_ib_j$ is well-defined, then $T_{ij}$ is naturally a tensor.\\\\\r\nIn general, we can correspondingly identify a rank-$n$ tensor in $\\mathbb R^3$ by multilinear maps $(\\mathbb R^3)^n\\to\\mathbb R$.\r\n\\begin{proposition}[Quotient Theorem]\r\n    Given basis $\\{\\underline{e_i}\\}$, let $T_{i_1\\cdots i_nj_1\\cdots j_m}$ be array of numbers such that $v_{i_1\\cdots i_n}=T_{i_1\\cdots i_nj_1\\cdots j_m}u_{j_1\\cdots j_m}$ is a tensor for any tensor $u$, then $T$ is a tensor.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Take $u_{j_1\\cdots j_m}=c^1_{j_1}\\cdots c^m_{j_m}$, where $\\underline{c^k}$ are vectors.\r\n    So\r\n    $$v_{i_1\\cdots i_n}=T_{i_1\\cdots i_nj_1\\cdots j_m}c^1_{j_1}\\cdots c^m_{j_m}$$\r\n    is a tensor by hypothesis.\r\n    Let $\\underline{a^1},\\ldots,\\underline{a^n}$ be vectors, then we can contract $v$ by $v_{i_1\\cdots i_n}a_{i_1}^1\\cdots a_{i_n}^n$, which is a scalar that is independent of basis, so the map\r\n    $$(\\underline{a^1},\\ldots,\\underline{a^n},\\underline{c^1},\\ldots,\\underline{c^n})\\mapsto T_{i_1\\cdots i_nj_1\\cdots j_m}a_{i_1}^1\\cdots a_{i_n}^nc_{j_1}^1\\cdots c_{j_m}^m$$\r\n    is independent of choice of coordinates, so $T$ is a tensor.\r\n\\end{proof}\r\n\\begin{example}\r\n    Recall linear strain tensor $e_{ij}=(\\partial u_i/\\partial x_j+\\partial u_j/\\partial x_i)/2$ where $\\underline{u}(\\underline{x})$ is the displacement of the particle at $\\underline{x}$ of a body undergoing deformation.\r\n    Experimental evidence suggests a linear relationship between stresses (internal forces) and strain.\r\n    We measure stress using stress tensor $\\sigma_{ij}$.\r\n    There are $3^4=81$ numbers $c_{ijkl}$ such that $\\sigma_{ij}=c_{ijkl}e_{kl}$.\r\n    This is just a generalization of Hookes' Law to higher dimensions.\r\n    Now if we know that $c_{ijkl}=c_{ijlk}$ we know that $c_{ijkl}$ is a tensor from the quotient theorem.\r\n    In this case we call this array $c_{ijkl}$ is the stiffness tensor.\r\n    For isotropic material, we know that $c_{ijkl}=\\alpha\\delta_{ij}\\delta_{kl}+\\beta\\delta_{ik}\\delta_{jl}+\\gamma\\delta_{il}\\delta_{jk}$, so $\\sigma_{ij}=\\alpha e_{kk}\\delta_{ij}+\\beta e_{ij}+\\gamma e_{ji}=\\alpha e_{kk}\\delta_{ij}+2\\mu e_{ij}$ where $\\mu=\\beta+\\gamma$.\r\n    We can invert for $e_{ij}$ by contract on indices $i,j$, so $\\sigma_{kk}=(3\\alpha+2\\mu)e_{kk}$, so $e_{kk}=\\sigma_{kk}/(3\\alpha+2\\mu)$.\r\n    So $2\\mu e_{ij}=\\sigma_{ij}-\\alpha\\sigma_{kk}\\delta_{ij}/(3\\alpha+2\\mu)$.\r\n\\end{example}", "meta": {"hexsha": "0d43b4e840a0badb17e88e96a8831e618674d4a9", "size": 21556, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8/tensor.tex", "max_stars_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_stars_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "8/tensor.tex", "max_issues_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_issues_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "8/tensor.tex", "max_forks_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_forks_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 74.0756013746, "max_line_length": 370, "alphanum_fraction": 0.6738263129, "num_tokens": 7835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7181768424318292}}
{"text": "\\documentclass[12pt,fleqn]{article}\n\\usepackage{mathtools}\n\\usepackage{amsmath}\n\n\n\\begin{document}\n% \\setlength{\\mathindent}{0pt}\n\\section{Distributions}\n\\subsection{how to tell between the distributions?}\n\ngenerallly counting processes are discrete (how many coin flips)\n\namount of time, speed, height, continuous/interval processes are continuous. measured using an interval (you dont go from 500kph to 501 kph without passing through 500.5 kph)\n\n\n\n\\subsection{Geometric}\nDiscrete\n\n\"how many flips until first success\"\n\n$E[k, p] = \\dfrac{1-p}{p}$ or $\\dfrac{1}{p}$\n\n$\\sigma = \\dfrac{1-p}{p^2}$\n\n\\subsubsection{PMF}\n$Geo(k, p) = (1-p)^{k-1}p$\n\n\\subsection{Bernoulli}\n\\subsection{Binomial}\nDiscrete\n\n\\begin{align*}\n\tE[x] = np\\\\\n\tVar(x) = np(1-p)\n\\end{align*}\n\n\\subsubsection{PMF}\n$bin(x=k,n,p) = {N\\choose k} p^k(1-p)^n-k$\n\nassumes resilts are independent and identically distributed\n\n\n\\subsection{Negative Binomial}\n\\subsection{Poisson}\nDiscrete\n\nmean arrival rate ($\\mu$) is usually given\n\n$\\sigma = \\sqrt{\\mu}$\n\n\\subsubsection{PDF}\n$p_x(k;\\mu) = p(X=k; \\mu) = \\dfrac{e^{-\\mu}\\mu^k}{k!}$, for $k = 0,1,2...$\n\\subsection{Uniform}\n\n\\begin{align*}\n\tf(x) &= \\dfrac{1}{(b-a)}, \\text{for $a \\le x \\le b$}\\\\\n\tf(x) &= 0, \\text{for any single $x$}\\\\\n\tE[x] &= \\dfrac{(b-a)}{2}\\\\\n\tVar(x) &=\\dfrac{(b-a)^2}{12}\n\\end{align*}\n\n\\subsection{Normal}\n\nmedian is $\\mu$\n\n\\begin{align*}\n\t\\mu_{discrete} &= \\sum_{x \\in D} x p(x)\\\\\n\tE[x]_{discrete} &= \\sum_{x \\in D} h(x) p(x)\\\\\n\t\\mu_{continuous} &= \\int_{-\\infty}^{\\infty} x f(x) dx\\\\\n\tE[x]_{continuous} &= \\int_{-\\infty}^{\\infty} h(x) f(x) dx\n\\end{align*}\n\n\\subsubsection{PDF}\n$f(x) = \\dfrac{1}{\\sigma\\sqrt{2\\pi}}e^{(\\dfrac{-(x-\\mu)^2}{2\\sigma^2})}$\n\\subsubsection{CDF}\n$F(x) = $\n\n\\subsubsection{Standardizing}\na random variable following the standard normal distribution $\\Phi$ has $\\mu = 0$ and $\\sigma = 1$ and is often represented by the letter $Z$.\n\nThis can be converted to/from a non-standard normal using these formulas:\n\n$Z = \\dfrac{X-\\mu}{\\sigma}$\n\n\n$X = (Z \\sigma) + \\mu$\n\n\n\\subsection{Exponential}\n\n\n$\nf(x)=\\begin{cases}\n\\lambda e^{-\\lambda x}, & \\text{for $x\\ge0$}.\\\\\n0, & \\text{for $x<0$}.\n\\end{cases}\n$\n\n$ F(x)=1-e^{-\\lambda x} $\n\n\n\\subsection{Weibull}\n\n$\\alpha$ - shape\n$\\beta$ - scale\n\n$E[X] = \\beta\\Gamma(1+\\dfrac{1}{\\alpha})$\n$Var(X) = \\beta^2[\\Gamma(1+\\dfrac{2}{\\alpha})-[\\Gamma(1+\\dfrac{1}{\\alpha})]^2]$\n\n\\subsubsection{PDF}\n\n$\nf(x)=\\begin{cases}\n\\dfrac{\\alpha}{\\beta^\\alpha}x^{\\alpha-1}e^{-(x/\\beta)^\\alpha}, & \\text{for $x\\ge0$}.\\\\\n0, & \\text{for $x<0$}.\n\\end{cases}\n$\n\n\\subsubsection{CDF}\n\n$\nf(x)=\\begin{cases}\n1-e^{-(x-\\beta)^\\alpha}, & \\text{for $x\\ge0$}.\\\\\n0, & \\text{for $x<0$}.\n\\end{cases}\n$\n\n\n\\subsection{Gamma}\n\n$\\Gamma(n)$ known as \"standard gamma\"\n\n\nfor any $\\alpha > 1$:\n\\begin{itemize}\n\t\\item ? (missed this in notes)\n\t\\item for any positive integer n $\\Gamma(n) = (n-1)!$\n\t\\item $\\Gamma(1/2) = \\sqrt{\\pi}$\n\\end{itemize}\n\n\n\\subsubsection{PDF}\n\nnonstandard gamma\n$f(x;\\alpha, \\beta) = \\dfrac{x^{\\alpha-1}e^{\\dfrac{-x}{\\beta}}}{\\beta^\\alpha \\int_0^\\infty x^{\\alpha-1}e^{-x}dx}$\n\n\nstandard gamma ($\\beta=1$)\n$\\Gamma(x; \\alpha) = \\int_0^\\infty x^{\\alpha-1}e^{-x}dx$\n\n\\subsection{Sample Means}\n\n$\\sigma$ - Population standard deviation\n\n$\\mu$ - Population mean\n\n$\\overline{X}$ - Sample mean\n\n$T_0$ - Sample total\n\n\\begin{align*}\nT_0 &= n\\mu\\\\\nVar(T_0) &= \\sqrt{n\\sigma}\n\\end{align*}\n\n\\end{document}", "meta": {"hexsha": "61a757fbf52b917a6ae712c925f11a2da2315e14", "size": 3359, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "distributions.tex", "max_stars_repo_name": "ace4971/math-251-formulasheet", "max_stars_repo_head_hexsha": "ef100d52dd35e67f07cc9abde24422bf8dffaeb0", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "distributions.tex", "max_issues_repo_name": "ace4971/math-251-formulasheet", "max_issues_repo_head_hexsha": "ef100d52dd35e67f07cc9abde24422bf8dffaeb0", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "distributions.tex", "max_forks_repo_name": "ace4971/math-251-formulasheet", "max_forks_repo_head_hexsha": "ef100d52dd35e67f07cc9abde24422bf8dffaeb0", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.1137724551, "max_line_length": 174, "alphanum_fraction": 0.6302470974, "num_tokens": 1282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672089305841, "lm_q2_score": 0.8887587831798665, "lm_q1q2_score": 0.7181768293366969}}
{"text": "\n\\subsection{The bit}\n\nA single bit can store a binary piece of information. We can use it to distinguish between two states.\n\nThese two states could be represented by True \\(T\\) and False \\(F\\), but by convention we use \\(1\\) and \\(0\\).\n\nWe can combine bits to store more complex pieces of information. If we have \\(n\\) bits, we can distinguish between \\(2^n\\) states.\n\nEight bits together constitute a byte. This can represent one of \\(2^8=256\\) states.\n\n", "meta": {"hexsha": "c889436f8d1c0d5097add8981e1a886337ba2857", "size": 457, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/logic/01-01-inputs.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/computer/logic/01-01-inputs.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/computer/logic/01-01-inputs.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.0833333333, "max_line_length": 130, "alphanum_fraction": 0.7264770241, "num_tokens": 109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7180519195939227}}
{"text": "\n\\Lecture{Jayalal Sarma}{Nov 23, 2020}{34}{Extremal Set Theory}{Mohit Singla}{$\\alpha$}{JS}\n\\section{Recall Sperner Theorem}\n\\begin{theorem}\nLet $F$ be the family of subsets of $[n]$ $|$ $\\forall$ $A,B \\in F$, $A \\nsubseteq B$.\n$$|F| \\le {n\\choose{n/2}}$$\nThe size is the width of subset boolean poset.\n\\begin{proof}\n\\textbf{Tightness:-} The bound is tight as we have example $F=\\{A\\subseteq [n] \\mid \\left |A\\right |=n/2\\}$\\\\\\\\\n A permutation $\\pi \\in S_n$ is said to meet $A \\subseteq \\{1,2,\\ldots,n\\}$ if $A$ forms prefix of $\\pi$. Let's say $|A| = k$ then $\\pi$ said to meet $A$ if $A = \\{\\pi(1),\\pi(2),\\ldots,\\pi(k)\\}$.\\\\\\\\\nConsider each subset in $F$ and consider permutations meeting them, As we are taking subsets from $F$, they are incomparable. Hence a single permutation can not meet both $A$ and $B$. So,\n$$\\sum_{A\\in F} \\bigg|\\{\\pi | \\pi ~meets~ A\\}\\bigg| \\leq n!$$\\\\\nNow number of permutations that can meet set $A$ of size $k$ is $k! \\times (n-k)!$.So,\n$$\\sum_{A\\in F} |A|! \\times (n-|A|)! ~~~\\leq~~~ n!$$\n$$\\boxed{\\sum_{A\\in F} \\frac{1}{{n \\choose {|A|}}} ~~~ \\leq ~~~ 1}$$\\\\\nThe above inequality is known as \\textbf{LYM Inequality -  Lubell–Yamamoto–Meshalkin Inequality,}\\\\\\\\\nWe can substitute $n \\choose \\frac{n}{2}$ in place of $|A|$ and the inequality still holds.\n$$\\sum_{A\\in F} \\frac{1}{{n \\choose \\frac{n}{2}}} ~~~ \\leq ~~~ 1$$\n$$\\sum_{A\\in F} 1  ~~~ \\leq ~~~ {n \\choose \\frac{n}{2}}$$\n$$|F| ~~~\\leq~~~ {n \\choose \\frac{n}{2}}$$\\\\\n\\end{proof}\n\\end{theorem}\n\\section{Disussing family of subsets with certain intersection properties}\nThe \\textbf{Sperner theorem} we did is sample of family of subsets with intersection properties : for any pair $A,B \\subseteq F ~|~ A\\cap B \\neq A$\\\\\\\\\n\\textbf{Question:-} Consider  family of subsets of $[n]$ such that for any pair $A,B \\subseteq [n]$, $A \\cap B \\neq \\phi$. How large can $F$ be?\\\\\\\\\n\\textbf{Building up:-} The size can be as large a $2^n$ but will not be equal to $2^n$ as if we take all singleton sets, their pairwise intersection is empty.\\\\ The size can be $2^{n-1}$, $F = \\{ B \\cup \\{n\\}~ | ~B\\subseteq[n-1] \\}$. Example for $n=3$ : $F=\\{\\{3\\},\\{1,3\\},\\{2,3\\},\\{1,2,3\\}\\}$. Can it be larger than $2^{n-1}$ ?\n\\begin{theorem} The size of intersection family is atmost $2^{n-1}$. And this bound is tight as we already have an example for any $n$.\n\\begin{proof}\nBy the property of family of subsets, its clear that if any subset $A \\in F \\implies {A}^\\complement \\notin F$. If both $A$ and $A^\\complement$ are present then their intersection is empty. So for every subset in $F$ there is subset not present in $F$. Hence $|F| \\le 2^{n-1}$.\n\\end{proof}\n\\end{theorem}\n\\textbf{Special cases of above family:-}\n\\begin{enumerate}\n\\item The intersection size is always $\\lambda$ i.e. $A,B \\subseteq F ~ \\mid ~ |A \\cap B|=\\lambda$. Claim : $|F|\\le n$.\n\\item The family is $k$-uniform.\n\\end{enumerate}\nWe will answer above two cases using \\textbf{Linear Algebra} techniques. Before proving above claims lets take a look at some other problem that uses similar proof techniques.\n\n\\subsection{Odd Town Problem}\n\\begin{itemize}\n    \\item $n$ people in an odd town form $m$ clubs $C_1, C_2, \\hdots, C_m$.\n    \\item Each club has an odd number of members.\n    \\item Each pair of clubs have an even number of common members.\n    \\item No two clubs have same set of members.\n\\end{itemize}\n\\begin{theorem}In Odd Town problem $m \\le n$.\n\\begin{proof}\nAssociate a $n$-sized 0-1 vector $v_i$ to each club $C_i$, such that $v_i[j]=1$ if $j$ is member of club $C_i$ else 0. It is now sufficient to prove that we cannot have more than $n$ different vectors. Theses vectors are defined over field $\\mathbb{F}_2^n$. The field $\\mathbb{F}_2^n$ can be considered as structure where both addition and multiplication is modulo 2 and every element is either 0 or 1.\\\\\\\\\nIf we can show that the set of vectors $v_1, v_2, \\hdots, v_m$ are linearly independent over $\\mathbb{F}_2^n$, then it's implied that $m \\le n$ as number of independent vectors are always less than or equal to dimension.\\\\\\\\\nConsider the inner product $\\langle v_i,v_j\\rangle$. In $\\mathbb{F}_2^n$, $\\langle a,b\\rangle = (\\sum_{1}^{n} a_ib_i)\\%2$.\\\\\n\n~\\textbf{Case 1:} $i\\neq j$, $\\langle v_i,v_j\\rangle = \\sum_{k=1}^{n} v_i[k]v_j[k] = | C_i \\cap C_j |\\%2 = 0$. As the size of intersection is always $even$.\\\\\n\n~\\textbf{Case 2:} $i= j$, $\\langle v_i,v_j\\rangle = \\sum_{k=1}^{n} v_i[k]v_i[k] = (\\sum_{k=1}^{n} v_i[k])\\%2= 1$. As the size of each club is $odd$.\\\\\\\\\nSuppose the set of vectors $v_1, v_2, \\hdots, v_m$ are not linearly independent. Then these exist non-trivial solution to the equation: $\\sum \\lambda_i v_i=0$. If we can show that only solution to above equation is when all $\\lambda_i$ is \\textbf{0}, then we are done with proof.\\\\\\\\\nTake inner product of $\\sum \\lambda_i v_i$ with $v_j$ for every $j$. As $\\sum \\lambda_i v_i$ is \\textbf{0} vector.\n$$ \\left \\langle \\sum \\lambda_i v_i,v_j\\right\\rangle = 0$$\n$$  \\sum \\left \\langle \\lambda_i v_i,v_j\\right\\rangle = 0$$\n$$  \\sum \\lambda_i \\left \\langle  v_i,v_j\\right\\rangle = 0$$\\\\\nAs we saw earlier, when $i\\neq j$ $\\langle v_i,v_j\\rangle=0$. And when $i= j$, $\\langle v_i,v_j\\rangle=1$. So the above equation can be written as:\n$$  \\lambda_j \\left \\langle  v_j,v_j\\right\\rangle = 0$$\nFor above equation to satisfy $\\lambda_j=0$, this can be shown for all $\\lambda$s. Hence proved $m\\le n$.\n\\end{proof}\n\\end{theorem}\nIn next lecture we will analyse the special cases of intersection family.\n\n\n\\Lecture{Jayalal Sarma}{Nov 25, 2020}{35}{More on Linear Algebra Techniques}{Mohit Singla}{$\\alpha$}{JS}\n\\section{Recall some intersection families}\nThe family $F$ such that for any two subsets $A,B\\subseteq F ~|~ A\\cap B \\neq \\phi$, then $|F| \\le 2^{n-1}$. Then we questioned two special cases of this intersection family.\n\\begin{enumerate}\n    \\item The intersection size is always $\\lambda$ i.e. $A,B \\subseteq F ~ \\mid ~ |A \\cap B|=\\lambda$. Claim : $\\boxed{|F|\\le n}$. This inequality is knows as \\textbf{Fisher's Inequality}.\n    \\item The family is $k$-uniform $\\lambda$ i.e. $A \\subseteq F ~ \\mid ~ |A|=k$. Claim : $\\boxed{|F|\\le {{n-1}\\choose{k-1}}}$. This is knows as \\textbf{Edr{\\\"o}s Ko-Rado Theorem}.\n\\end{enumerate}\nWe saw \\textbf{Odd-Town Theorem} which states that if:\n\\begin{itemize}\n    \\item $n$ people in an odd town form $m$ clubs $C_1, C_2, \\hdots, C_m$.\n    \\item Each club has an odd number of members.\n    \\item Each pair of clubs have an even number of common members.\n    \\item No two clubs have same set of members.\n\\end{itemize}\nThen $m\\le n$. We proved this inequality using \\textbf{Linear Algebra}. We associated one vector with each club and showed that all the vectors are linearly independent. As the dimension is $n$, there can not be more that $n$ linearly independent vectors.\n\n\\section{Fisher's Inequality (1940s)}\nWe will look at proof by \\textbf{Babai Frankl} in 1992.\n\\begin{theorem}\nThe family $F$ such that intersection size is always $\\lambda$ i.e. $A,B \\subseteq F ~ \\mid ~ |A \\cap B|=k $. then $|F|\\le n$.\n\\begin{proof}Associate a $n$-sized 0-1 vector $v_i$ to each club $C_i$, such that $v_i[j]=1$ if $j$ is member of club $C_i$ else 0. Each $v_i\\in \\mathbb{R}^n$.\\\\\\\\\nConsider the inner product $\\langle v_i,v_j\\rangle$. In $\\mathbb{R}^n$, $\\langle a,b\\rangle = (\\sum_{1}^{n} a_ib_i)$.\\\\\n\n~\\textbf{Case 1:} $i\\neq j$, $\\langle v_i,v_j\\rangle = \\sum_{k=1}^{n} v_i[k]v_j[k] = | C_i \\cap C_j | = k$. As the size of intersection is always k.\\\\\n\n~\\textbf{Case 2:} $i= j$, $\\langle v_i,v_j\\rangle = \\sum_{k=1}^{n} v_i[k]v_i[k] = \\sum_{k=1}^{n} v_i[k]= |C_i|$.\\\\\\\\\nWe will show the vectors are linearly independent. Suppose the set of vectors $v_1, v_2, \\hdots, v_m$ are not linearly independent. Then these exist non-trivial solution to the equation: $\\sum \\lambda_i v_i=\\textbf{0}$. We can write\\\\\n$$ \\left \\langle \\sum_1^m \\lambda_i v_i,\\sum_1^m \\lambda_i v_i \\right\\rangle = 0$$\n$$\\implies ~~ \\sum_1^m \\lambda_i^2 \\left \\langle   v_i, v_i \\right\\rangle + \\sum_{1\\le i \\neq j\\le m} \\lambda_i \\lambda_j \\left \\langle   v_i, v_j \\right\\rangle = 0$$\n$$\\implies ~~ \\sum_1^m \\lambda_i^2 |C_i| + \\sum_{1\\le i \\neq j\\le m} \\lambda_i \\lambda_j k = 0$$\n$$\\implies ~~ \\sum_1^m \\lambda_i^2 (|C_i|-k) +\\sum_1^m \\lambda_i^2k + \\sum_{1\\le i \\neq j\\le m} \\lambda_i \\lambda_j k = 0$$\n$$\\implies ~~ \\sum_1^m \\lambda_i^2 (|C_i|-k) +(\\sum_1^m \\lambda_i)^2k = 0$$\\\\\\\\\n\nSuppose there exist a $C_i$ such that $|C_i|=k$, then no other club size can be $k$. If there are two clubs with size $k$ and their intersection is also of size $k$, then both the clubs have to be equal. so at-most one club can have size $k$. Now as the intersection size is always $k$, for all $j$, $C_i \\subseteq C_j$ must hold as the size of $C_i$ is $k$ and $|C_i \\cap C_j |=k$. Note for all $C_i$, $|C_i|\\ge k$ as the intersection size with any other club is of size $k$.\\\\\\\\\nSo in the expression $\\sum_1^m \\lambda_i^2 (|C_i|-k) +(\\sum_1^m \\lambda_i)^2k$, both the parts in summation are non-negative. For right part to be zero, $\\sum_1^m \\lambda_i =0$. Not all $\\lambda$s are zero but their summation is, so there are atleast 2 $\\lambda$s which are non-zero.\\\\\\\\\nNow lets focus on left part. Each term $\\lambda_i^2 (|C_i|-k)$ is non-negative.  There are atleast 2 $\\lambda$s which are non-zero but atmost one $(|C_i|-k)$ can be zero. So the summation is always positive. So if there are non-zero $\\lambda$s then summation cannot be equated to zero. This leads to contradiction in assumption that there exists non-zero $\\lambda$s which satisfy above equation.\\\\\\\\\nHence proved that vectors $v_1, v_2, \\hdots, v_m$ are linearly independent. So $m\\le n$.\n\\end{proof}\n\\end{theorem}\n\n\\section{Application of Fisher Inequality and Odd Town Theorem}\n\\subsection{Ramsey Number}\n\\textbf{Definition:}$R(s,t)$ is minimum number ($n$) of vertices required in complete graph such that 2-edge coloring (red and blue colors) of this $K_n$ produces either red $K_s$ or blue $K_t$.\\\\\\\\\nEarlier we have proved $R(t,t)>2^t$ i.e. there exist a 2-edge coloring of $K_{2^t}$ such that there is no red $K_t$ or blue $K_t$. We proved this using probabilistic method. We chose color of each edge uniformly at random and observed that the probability of graph having either red $K_t$ or blue $K_t$ is strictly less than 1. So there exist a graph with neither has red $K_t$ nor blue $K_t$, we did not explicitly drew thew the graph. This proof was \\textbf{non-constructive}.\\\\\\\\\nIf we want a constructive example for lower-bound, we have much weaker lower bound.\n\\subsection{Constructive lower bound for diagonal Ramsey number}\n\\begin{claim}\n$R(t+1,t+1)> {t\\choose 3}$\\\\\\\\\nWe will be able to show a construction to prove this claim.\n\\begin{proof}\nWe need to show there exist a 2-edge coloring of $K_{t\\choose 3}$ such that there is no red $K_{t+1}$ or blue $K_{t+1}$.\\\\\\\\\n$n={t\\choose 3}$. Interpret each vertex as 3-sized subset of set $\\{1, 2, \\hdots, t\\}$. Let $A,B \\in V$, then $A,B \\subseteq [t]$ and $|A|=|B|=3$. Color edge $AB$ red if $|A\\cap B| =0$ or $2$. As size of each subset is 3 and all are pairwise distinct, the intersection size can only be 0, 1 or 2. Color edge $AB$ blue if $|A\\cap B| =1$.\\\\\\\\\nLets look for blue $K_{t+1}$. Consider $F$ as family consisting 3-sized subsets of $[t]$ such that intersection size is 1. These subsets in $F$ will represent the vertices corresponding to blue edges as described earlier. By Fishers theorem we know $|F|\\le t$. There are atmost $t$ vertices available so there cannot be $K_{t+1}$.\\\\\\\\\nLets look for red $K_{t+1}$. Consider $F$ as family consisting 3-sized subsets of $[t]$ such that intersection size is even. These subsets in $F$ will represent the vertices corresponding to red edges as described earlier. Now we have all subsets of odd size and intersection size even. All conditions required in Odd Town theorem are satisfied, so by the theorem $|F|\\le t$. There are atmost $t$ vertices available so there cannot be $K_{t+1}$.\\\\\\\\\nHence proved.\n\\end{proof}\n\\end{claim}\n\n\\section{Edr{\\\"o}s Ko-Rado Theorem (Discovered-1938, Presented-1962)}\n\\begin{lemma} Let $C$ be a cycle of length $n$ ($n$ edges and $n$ vertices). Let $H$ be family of paths in $C$ of fixed length $k$ where $k\\le \\frac{n}{2}$. Assume any paths in $H$ have an common edge. Then $|H|\\le k$.\n\\begin{proof}Pick a path $p = (v_1, v_2, \\hdots v_{k+1})$. All other paths have to intersect with this path. A path here is contiguous set of edges in cycle. Lets analyse how other paths look like. No other path can start from $v_1$, as it will end up being the same path $p$. No path can start at $v_{k+1}$, as $k\\le \\frac{n}{2}$ and path starting at $v_{k+1}$ will not have any edge common with $p$. Similarly no path can end at $v_1$ and $v_{k+1}$. So paths can start or end at $v_2, v_3 \\hdots v_{k}$. Note if there is a path that starts at $v_j$, we cannot include path ending at $v_j$ as these two paths will not have any common edge. So there can at-most be $k-1$ other paths. Hence $|H|\\le k$.\n\\end{proof}\n\\end{lemma}\n\n\\begin{theorem}[{\\bf Erd{\\\"o}s-Ko-Rado Theorem}]\n$F$ is $k$-uniform where $k\\le \\frac{n}{2}$, family of subsets of $[n]$ such that for every $A,B \\subseteq F$, $A\\cap B \\neq \\phi$. Note if $k> \\frac{n}{2}$, then every pair of subsets trivially has non-empty intersection. Then $|F|\\le {{n-1}\\choose{k-1}}$\n\n\\begin{proof}\nBefore we prove the theorem, to get a feel, we construct an example first. And this example also will prove that the above theorem is tight.\n\n\\paragraph{Tightness:} \nConsider the family.\n$$F_k=\\{\\{n\\}\\cup B ~|~ B\\subseteq [n-1] ,|B|=k-1\\}$$\n\nSince $n$ is there in every set in the family, the family is an intersecting family. All sets have size $k$ and hence it is $k$-uniform. By definition, $|F_k|={{n-1}\\choose{k-1}}$. Thus the claim is tight as we have an example for any $k$. It turns out that these are the only tight examples when $k < \\frac{n}{2}$.\n\nWhen $n$ is even and $k=n/2$, there is one more tight example. We can take $F_k$ such that for every $\\frac{n}{2}$-sized subset of $[n]$, we take either that subset or its complement in $F$. \n$$|F_k|={{{n}\\choose{n/2}}* \\frac{1}{2}}=\\frac{n}{n/2}* {{n-1}\\choose n/2-1}* \\frac{1}{2} = {{n-1}\\choose{n/2-1}}$$\n\n\\paragraph{Proof of the {\\bf Erd{\\\"o}s-Ko-Rado Theorem}:} We will discuss the proof by \\textbf{Katona (1972)} using cycle permutation argument. \n\nAssume someone invited all of the $n$ people from the town to a party. These $n$ people are members of clubs $C_1, C_2, \\hdots, C_m$ where each club is of size $k$ and every pair of intersection is non-empty. The party has round table with $n$ labelled chairs. Host wants to seat the club members contiguously. But of course he may not be able to since there may be contradictory requirements across clubs since members can be common. \n\nHowever, in an attempt to maximise the seating satisfaction of the club members, he decided to try all $n!$ permutations. Lets define a Matrix $H$ with $n!$ rows indexing the permutation number which represents seating arrangement. The columns are indexed by club $C_1, C_2, \\hdots, C_m$, so total $m$ columns. The entries of the matrix defined as follows. For $\\sigma \\in S_n, j \\in [m]$:\n\n$$H(\\sigma,j) = \n\\begin{cases}\n1 & \\textrm{~if $\\sigma$ seats members of club $C_j$ contiguously} \\\\\n0 & \\textrm{otherwise} \\\\\n\\end{cases}\n$$\n\nLet $c$ be the number of ones in matrix $H$. we will count $c$ in two different ways.\n\n\\begin{description}\n\\item{\\textbf{Count 1 - Row-wise first:}} For a given permutation, each club seated contiguously is a path in the cycle. The guests correspond to edges. As the family of clubs is an intersecting family, by above lemma we know that in each row there can be atmost $k$ ones. so $c \\le k*n!$\n\\item{\\textbf{Count 2 : Column-wise first:}} As we are considering all the permutations possible, the number of times each club appears contiguously will be the same. In fact a club will appear contiguously in $nk!(n-k)!$ permutations. First choose the starting index from n positions, then permute the members inside group, and then permute the members outside group. There are $m$ columns, so $c=mnk!(n-k)!$.\n\\end{description}\nUsing the above two counts, \n\\begin{eqnarray*}\nm~n~k!~(n-k)! & \\le & k~n! \\\\ \nm & \\le & \\frac{kn!}{nk!(n-k)!} \\le \\frac{(n-1)!}{(k-1)!(n-k)!} \\le {n-1 \\choose k-1}\n\\end{eqnarray*}\n\n\n\\end{proof}\n\\end{theorem}\n\n\\Lecture{Jayalal Sarma}{Nov 27, 2020}{37}{Generalization of linear algebraic method }{Banavath Tarun}{$\\alpha$}{JS}\n\n\\section {Running problems}\n\n\\begin{enumerate}\n    \\item \\underline{\\textbf{Intersecting family}} : Let $\\mathcal{F}$ be family of subsets of $\\{1,2,3,...,n\\}$ and is called Intersecting family, if every two subsets in these family intersect (i.e. $\\forall A, B \\in \\mathcal{F}$, ~~$A \\cap B \\ne \\phi$), and we have seen that $|\\mathcal{F}|\\le 2^{n-1}$.\n\n    \\item \\underline{\\textbf{Intersecting family with fixed size $\\lambda$ (Fisher's Inequality)}} : Similarly, when $\\mathcal{F}$ is a family of subsets of $\\{1,2,3,....,n\\}$ such that $\\forall A, B \\in \\mathcal{F}$, $~~~|A\\cap B| = \\lambda$, then size of family is not too large and is given as $|\\mathcal{F}|\\le n$\n    \\subitem \\textbf{techniques used in Fisher's inequality :} Odd town problem, linear algebra method. \n\\end{enumerate}\n\nIn this lecture, we discuss the theorems involving polynomial methods (or) function space methods.\n\\\\\n\n\\underline{proof techniques for polynomial method (or) function space methods includes 3 steps:}\n\n\\begin{enumerate}\n     \\item Associate a polynomial in $n$-variables with each element \n     \\item prove that polynomials are linearly independent\n     \\item Bound the dimensions of space of polynomials\n\\end{enumerate}\n\n\n\n\n\\section{Independence criterion Tool and Two-distance set}\n\n\\begin{lemma}\n(\\textbf{Independence criterion Tool}) $\\forall ~1 \\le i \\le m$, let $f_i : \\Omega \\longrightarrow \\mathbb{F}$ be a function, $v_i \\in \\Omega$ such that it satisfies the following two conditions : \n\\begin{enumerate}\n    \\item $f_i(v_i) \\ne 0, ~\\forall ~i$\n    \\item $f_i(v_j) = 0, ~\\forall ~1 \\le i<j \\le m $\n\\end{enumerate}\nthen $\\{f_1, f_2, f_3,....,f_m\\}$ are linearly independent in $\\mathbb{F}^{\\Omega}$. (Here each function $f_i$ is a element in $\\mathbb{F}^{\\Omega}$ i.e. a vector)\n\\begin{proof}\nSuppose $\\exists \\lambda_1, \\lambda_2, \\lambda_3,...,\\lambda_m \\in \\mathbb{F}$ such that $F = \\sum_{i =1}^{m} \\lambda_i f_i = 0$ and suppose there are dependent, where not all $\\lambda_i = 0$, then there is a contradiction. \nLet $j$ be the largest index (rightmost) such that $\\lambda_j \\ne 0.$ Substitute $v_j$ to the above function $F$.\nWe then have $F(v_j) = \\sum_{i=1}^{m} \\lambda_i f_i(v_j) = \\lambda_j f_j(v_j)$ (because $\\forall i > j $ $\\lambda_i = 0$ by choice of $j$ and $\\forall i< j$ the term $f_i(v_j) = 0$ by second condition) then $\\lambda_j f_j(v_j) = 0$. Since $f_j(v_j) \\ne 0$, $\\lambda_j$ should be zero, but $\\lambda_j \\ne 0$ from above assumption. Thus it contradicts the fact that $\\exists~ \\lambda_1, \\lambda_2, \\lambda_3,...,\\lambda_m \\in \\mathbb{F}$ that are dependent. \n\\end{proof}\n\\end{lemma}\n\n\\begin{claim}\nLet $a_1,a_2,....,a_m$ be $m$ points in $\\mathbb{R}^{n}$, such that all pair-wise distances are unique, them relation between $m$ and $n$ is given as : $m \\le n+1$ \n\\end{claim}\nWhat if we relax the condition in above claim and require that there are two possible distances c, d, so that any pairwise distance is either c or d? Such a set is called a two-distance set.\n\\\\\nBelow theorem is an example of demonstration of a polynomial method (or) function space method.\n\\\\\n\\begin{theorem}(\\textbf{Two-distance set}) Consider a two-distance set, a set $S = \\{a_1,a_2,a_3,...,a_m\\}$ is said to two-distance set, if $\\exists$ $d_1, d_2$ (two fixed distances) such that $\\forall a_i, a_j \\in S$, satisfy the relation $dist(a_i, a_j) = d_1$ or $dist(a_i, a_j) = d_2$ (where $dist(a_i, a_j)$ is the distance between the two points $a_i,a_j$ in $\\mathbb{R}^{n}$).\nThen the relation between $m$ (size of two-distance set) and $n$ (dimension of elements in two-distance set) is given as : $m \\le {n \\choose 2} + 3n +2$.\n\\end{theorem}\n\\begin{proof}\nWe Solve it using polynomial method (or) function space methods that follows the three steps as already mentioned.\n\\\\\n\n\\underline{\\textbf{step1 (Associate a polynomial)}} : \nAssociate a polynomial $P_i(x_1,x_2,x_3,....,x_n)$ for each element $a_i$ in $S=\\{a_1,a_2,a_3,....,a_m\\}$ with some properties, so that we can prove independence in these polynomials. As seen in above lemma the functions $f_i$'s are polynomial $P_i$'s here and $\\Omega = \\mathbb{R}^{n}$ in this case (since $\\forall i,~a_i \\in \\mathbb{R}^{n}$). Let $x=(x_1,x_2,x_3,...,x_n)$ be a $n$-vector then polynomial : \n$\\forall ~1 \\le i \\le m ~P_i(x) = \\big({||x-a_i||}^2-{d_1}^2\\big)\\big({||x-a_i||}^2-{d_2}^2\\big)$.\n\\\\\n\n\\underline{\\textbf{step2 (prove that polynomials are linearly independent)}} : \nThe above polynomials defined satisfies the two conditions of independent criterion tool. i.e.\n\\begin{enumerate}\n    \\item $P_i(a_i) \\ne 0,~ \\forall i$. $P_i$ satisfy the first condition because $P_i(a_i)= \\big({||a_i-a_i||}^2-{d_1}^2\\big)\\big({||a_i-a_i||}^2-{d_2}^2\\big) = {{d_1}^2}{{d_2}^2} \\ne 0$ (since $d_1,d_2 \\ne 0$), So  $P_i(a_i) \\ne 0,~ \\forall i$\n    \\item $P_i(a_j) = 0, \\forall 1 \\le i <j \\le m$. $P_i$ also satisfy the second condition because $P_i(a_j) = \\big({||a_j-a_i||}^2-{d_1}^2\\big)\\big({||a_j-a_i||}^2-{d_2}^2\\big)$ and also ${||a_j - a_i||}^2 = {{d_1}^2}$ (or) ${||a_j - a_i||}^2 = {{d_2}^2}$ from definition of two-distance set. So $P_i(a_j) = \\big({||a_j-a_i||}^2-{d_1}^2\\big)\\big({||a_j-a_i||}^2-{d_2}^2\\big) = 0, \\forall 1 \\le i <j \\le m$\n\\end{enumerate}\n\n\n\\underline{\\textbf{step3 (Bound the dimension of space of polynomials)}} :  \nThe polynomial that we have constructed has a property that we wanted and all these polynomials are now independent by independent criteria. Also after expanding the polynomial $P_i(x=(x_1,x_2,...x_n)) = \\big({||x-a_i||}^2-{d_1}^2\\big)\\big({||x-a_i||}^2-{d_2}^2\\big)$, we can see that the polynomial have only following type of terms:\n$$(\\sum_{i=1}^{n}{x_i}^{2})^2, {\\sum_{i}{x_i}^{2}} x_j, {\\sum_{1 \\le i\\le j \\le n}x_ix_j}, \\sum_{i=1}^{n}x_i ,1$$.\ni.e. \n\\begin{itemize}\n    \\item Number of terms of form $(\\sum_{i=1}^{n}{x_i}^{2})^2$ are $1$. \n    \\item Number of terms of form ${\\sum_{i}{x_i}^{2}} x_j$ are $n$. \n    \\item Number of terms of form ${\\sum_{1 \\le i\\le j \\le n}x_ix_j}$ are ${n \\choose 2} + n$. \n    \\item Number of terms of form $\\sum_{i=1}^{n}x_i$ are $n$. \n    \\item Number of constant terms are $1$. \n\\end{itemize}\nSo in total we have $1+n+{n \\choose 2} + n + n +1  = {n \\choose 2} + 3n + 2$ number of terms i.e. any polynomial in our family can be expressed as a linear combination in ${n \\choose 2} + 3n + 2$ number of terms, which means that dimensions of set of polynomials that we are looking cannot be greater than ${n \\choose 2} + 3n + 2$ because these are the simplified polynomials using which we can express all the polynomials in our family. So, the dimension of underline space is bounded by ${n \\choose 2} + 3n + 2$ and hence \n$$m \\le {n \\choose 2} + 3n + 2$$ because there cannot be more than ${n \\choose 2} + 3n + 2$ number of independent polynomials (or) vectors.\n\\end{proof}\n\n\\section{Frankl-Wilson Theorem}\n\\begin{theorem}\nLet $\\mathcal{F}$ be family of subsets of $[n]$ and let $L$ be subset of $[n]$ ($L \\subseteq \\{1,2,3,...,n\\}$) such that $\\forall A,B \\in \\mathcal{F}$,  $~~|A\\cap B| \\in L$, then $|\\mathcal{F}| \\le \\sum_{i=1}^{|L|} {n \\choose i}$. This theorem is also known as \\textbf{Frankl-Wilson Theorem}, which is a Generalization of \\textbf{Fisher's theorem}.\n\\end{theorem}\n\n\\begin{proof}\nLet $\\mathcal{F} = \\{A_1,A_2,....,A_m\\}$ be family of subsets of $[n]$, $L={l_1,l_2,....,l_s}$ be a subset of $[n]$ such that $\\forall i,j ~(1 \\le i,j \\le n)$ $\\exists~ k~(1 \\le k \\le s)$ such that $|A_i\\cap A_j| = l_k$. Let $v_i$ be the characteristic vector of $A_i$, $v_i \\in \\Omega = \\mathbb{R}^n$ \\big(where $<v_i,v_i> = |A_i|$ and $<v_i,v_j> = |A_i\\cap A_j|\\big)$ and we can assume that $A_1$ to $A_m$ is ordered such that sizes are non-decreasing order (or) rename them accordingly. We then have\n$$|A_1| \\le |A_2|  \\le |A_3|..... \\le |A_m|.$$ \nNow We Solve the proof using polynomial method (or) function space methods that follows the three steps as already mentioned.\n\\\\\n\n\\underline{\\textbf{step1 (Associate a polynomial)}} : \nAssociate a polynomial $P_i(x_1,x_2,....,x_n)$ for each element $A_i$. So the polynomial that we are going to define is as follows:\n$$P_i\\big(x = (x_1,x_2,....,x_n)\\big) = \\prod_{k ~: ~l_k < |A_i|}\\big(<v_i,x>-l_k\\big)$$\nwhere $x=(x_1,x_2,....,x_n)$ is a $n$-vector.\n\\\\\n\n\n\\underline{\\textbf{step2 (prove that polynomials are linearly independent}} : The above polynomials defined satisfies the two conditions of independent criterion tool.\n\\begin{enumerate}\n    \\item \n    when $x=v_i$, we have:\n$$P_i(v_i) = \\prod_{k ~: ~l_k < |A_i|}\\big(<v_i,v_i>-l_k\\big) = \\prod_{k:l_k < |A_i|}\\bigg(|A_i|-l_k\\bigg) \\ne 0$$\nso, $P_i(v_i) \\ne 0,~ \\forall i$\n    \\item\n    when $x=v_j$ and $i < j$, we have:\n$$P_i(v_j) = \\prod_{k ~: ~l_k < |A_i|}\\big(<v_i,v_j>-l_k\\big) = \\prod_{k:l_k < |A_i|}\\big(|A_i\\cap A_j|-l_k\\big)=0$$\nSince $|A_i \\cap A_j| $ must be one of the $l_p \\in L$ and this $p$ must satisfy $l_p < |A_i|$, because the intersection size $|A_i \\cap A_j|$ cannot be more than $A_i$.\nSo, $P_i(v_j) = 0, \\forall 1 \\le i <j \\le m$\nNow we have this polynomial $P_i\\big(x = (x_1,x_2,....,x_n)\\big) = \\prod_{k ~: ~l_k < |A_i|}\\big(<v_i,x>-l_k\\big)$ that satisfies the two conditions of Independent criteria and hence $P_1,P_2,....,P_n$ are linearly independent as polynomials (or) as coefficients of vectors.\n\\end{enumerate}\n\n\\underline{\\textbf{step3 (Bound the dimension of space of polynomials)}} : \nEstimating the underlying dimensions (here, space of polynomials):\nWe need to compute the dimension of space containing all these polynomials. Since we are using only 0/1 vectors here we can reduce the dimension by replacing the higher powers ${x_i}^k$ with $x_i$, this process does not change the linear dependence property and we still get same conditions. Now each term monomial looks like $x_1x_2x_3....$. Polynomials with these properties (i.e. each monomial with every individual variable degree to be at most one) are called as multilinear polynomials. So the polynomials under consideration lives in the space of multilinear polynomials of degree at most $s$.\n\\\\\nLet us look at the example on multilinear polynomials when $n=3$ and degree=2, the only terms correspond to these multilinear polynomials looks like:\n$$x_1 x_2, ~x_2 x_3, ~x_1 x_3, ~x_1, ~x_2, ~x_3, ~1$$ there are 7 terms and an example of these multilinear polynomial with real coefficients looks like:\n$5x_1 x_2 + 6x_1 x_3 + 5x_2 x_3 + 3x_1 + 2x_2 + x_3 + 6$\nand dimension of this multilinear polynomial example is $7$. The number of monomials we can have with that much degree is the bound for dimension. So in general when degree=$k$ and number of variables is $n$, then number of monomials in this multilinear polynomial is $n \\choose k$ (i.e. select $k$ elements from $\\{1,2,3,....,n\\}$ and associate a monomial with corresponding variables). But now we have that degree is at most $s$, so we need to sum the result $n \\choose k$ overall values of $k$ (i.e. $1 \\le k \\le s$). So,\n$$Dimension ~of ~space = \\# ~of~ subsets~ of ~\\{1,2,3,...,n\\} ~of~ size ~\\le s = \\sum_{k=1}^{s}{n\\choose k}$$\nand hence\n$$m \\le Dimension \\le \\sum_{k=1}^{|L|}{n \\choose k}$$\n\\end{proof}\n\n\n\\begin{theorem}\nLet $\\mathcal{F}$ be family of subsets of $[n]$, $p$ be a prime and $L$ be subset of $\\{0,1,2,3,...,p-1\\}$, ($L \\in \\{0,1,2,3,...,p-1\\}$) such that $\\forall A, B \\in F$, $~~|A \\cap B| \\in L (mod~p)$ and $|A| \\notin L (mod~p)$, then $|\\mathcal{F}| \\le \\sum_{i=1}^{|L|} {n \\choose i}$. This theorem is proved by \\textbf{Ray-choudhuri Wilson}, which is a Generalization of \\textbf{odd-town problem}. \n\\end{theorem}\n\n\\begin{theorem}\nLet $\\mathcal{F}$ be a k-Uniform family of subsets of $[n]$ and let $L$ be subset of $[n]$,  ($L \\subseteq \\{1,2,3,...,n\\}$) such that $\\mathcal{F}$ is $L-$intersecting (i.e. $\\forall A, B \\in F$, $~~|A \\cap B| \\in L$), then the size of $\\mathcal{F}$ is given as : $|\\mathcal{F}|\\le {n \\choose |L|}$. This theorem is proved by \\textbf{Ray-choudhuri Wilson}  \n\\end{theorem}\n\nThe above two theorems are also applications of polynomial method and process involved in proving them is similar to that we have done before.\n", "meta": {"hexsha": "154e8525cb458f9f2155a83be6dca16272297503", "size": 28526, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week12.tex", "max_stars_repo_name": "jayalalsarma/theory-toolkit", "max_stars_repo_head_hexsha": "41d72c3bbe6bfdb0720801d220e210b9c77a1300", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week12.tex", "max_issues_repo_name": "jayalalsarma/theory-toolkit", "max_issues_repo_head_hexsha": "41d72c3bbe6bfdb0720801d220e210b9c77a1300", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-10-08T07:34:26.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-30T06:06:12.000Z", "max_forks_repo_path": "week12.tex", "max_forks_repo_name": "jayalalsarma/theory-toolkit", "max_forks_repo_head_hexsha": "41d72c3bbe6bfdb0720801d220e210b9c77a1300", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2020-09-25T01:35:07.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-28T11:22:06.000Z", "avg_line_length": 90.847133758, "max_line_length": 701, "alphanum_fraction": 0.6812031129, "num_tokens": 9641, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.8757869835428966, "lm_q1q2_score": 0.718051903778212}}
{"text": "%%%\r\n\\chapter{Mathematics}\r\n\r\nOne of the greatest motivating forces for Donald Knuth when he began developing the original TeX system was to create something that allowed simple construction of mathematical formulae\\index{formulae}, while looking professional when printed. The fact that he succeeded was most probably why TeX (and later on, LaTeX) became so popular within the scientific community. Typesetting mathematics is one of LaTeX's greatest strengths. It is also a large topic due to the existence of so much mathematical notation.\r\n\r\nIf your document requires only a few simple mathematical formulas, plain LaTeX has most of the tools that you will need. If you are writing a scientific document that contains numerous complicated formulas, the amsmath package\\index{package} introduces several new commands that are more powerful and flexible than the ones provided by basic LaTeX. The mathtools package fixes some amsmath quirks and adds some useful settings, symbols, and environments to amsmath.\r\n\r\n$$M = \\begin{bmatrix}\r\n\\frac{5}{6} & \\frac{1}{6} & 0           \\\\[0.3em]\r\n\\frac{5}{6} & 0           & \\frac{1}{6} \\\\[0.3em]\r\n0           & \\frac{5}{6} & \\frac{1}{6}\r\n\\end{bmatrix}$$\r\n\r\n\\begin{equation}\r\nx = a_0 + \\cfrac{1}{a_1 \r\n\t+ \\cfrac{1}{a_2 \r\n\t\t+ \\cfrac{1}{a_3 + \\cfrac{1}{a_4} } } }\r\n\\end{equation}\r\n\r\n\r\n\r\n", "meta": {"hexsha": "6d6e9180da8511c7a1db5e1c7aaea3cfd2ec95fd", "size": 1326, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "04-Book/chapters/ch3.tex", "max_stars_repo_name": "datasticslab/ISCB1002", "max_stars_repo_head_hexsha": "d803fd0d70aabc51a92030f029d67286ce1b33d1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-28T15:36:29.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-28T15:36:29.000Z", "max_issues_repo_path": "04-Book/chapters/ch3.tex", "max_issues_repo_name": "datasticslab/ISCB1002", "max_issues_repo_head_hexsha": "d803fd0d70aabc51a92030f029d67286ce1b33d1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "04-Book/chapters/ch3.tex", "max_forks_repo_name": "datasticslab/ISCB1002", "max_forks_repo_head_hexsha": "d803fd0d70aabc51a92030f029d67286ce1b33d1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.2727272727, "max_line_length": 512, "alphanum_fraction": 0.7247360483, "num_tokens": 348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7179469062158648}}
{"text": "\\appendix\n\\chapter{Appendix}\n\n\\section{Sum of reciprocal vertices depending only on $v_1$}\n\\label{appx:sum_reciprocal_vertices}\nOne condition deduced from theorem~\\ref{theo:1} is the product condition~\\ref{eq:condition_max}, which specifies the validity of the cycle-alpha's upper limit. This condition requires the sum $\\frac{1}{kv_1}+\\frac{1}{kv_2}+\\frac{1}{kv_3}+\\ldots$ to be limited. In order to formulate this sum independently from the successive vertices $v_2,v_3,\\ldots$, we substitute these as follows:\n\\begin{flalign}\nv_1&=v_1\\notag\\\\\nv_2&=\\frac{kv_1+1}{2^{\\alpha_1}}\\notag\\\\\nv_3&=\\frac{k^2v_1+k+2^{\\alpha_1}}{2^{\\alpha_1+\\alpha_2}}\\notag\\\\\nv_4&=\\frac{k^3v_1+k^2+k\\cdot2^{\\alpha_1}+2^{\\alpha_1+\\alpha_2}}{2^{\\alpha_1+\\alpha_2+\\alpha_3}}\\label{eq:sum_v_4}\\\\\n\\vdots\\notag\\\\\nv_{n+1}&=\\frac{k^nv_1+\\sum_{j=1}^{n}k^{j-1}2^{\\alpha_1+\\ldots+\\alpha_n-\\sum_{l>n-j}\\alpha_l}}{2^{\\alpha_1+\\ldots+\\alpha_n}}\\label{eq:sum_v_n_plus_1}\n\\end{flalign}\n\n\\par\\medskip\nThe sum of the reciprocal vertices can be expressed as a term that depends from $v_1$ and from the number of contracted edges, id est the number of dvisions by two, between two successive vertices $\\alpha_1,\\alpha_2,\\alpha_3,\\ldots$: \n\\begin{equation*}\n\\sum_{i=1}^{n+1}\\frac{1}{kv_i}=\\frac{1}{k}\\left(\\frac{1}{v_1}+\\sum_{i=1}^{n}\\frac{1}{v_{i+1}}\\right)=\\frac{1}{k}\\left(\\frac{1}{v_1}+\\sum_{i=1}^{n}\\frac{2^{\\alpha_1+\\ldots+\\alpha_i}}{k^iv_1+\\sum_{j=1}^{i}k^{j-1}2^{\\alpha_1+\\ldots+\\alpha_n-\\sum_{l>i-j}\\alpha_l}}\\right)\n\\end{equation*}\n\n\\section{The product formula depending only on $v_1$}\n\\label{appx:product_formula_depending_v1}\nIn a similar way to deduce the sum of reciprocal vertices depending only on $v_1$ as performed in \\ref{appx:sum_reciprocal_vertices}, we evolve the product formula depending only on $v_1$:\n\\begin{flalign}\n\\prod_{i=1}^{n+1}\\left(1+\\frac{1}{kv_i}\\right)&=1+\\frac{2^{\\alpha_1+\\ldots+\\alpha_n}+k\\cdot2^{\\alpha_1+\\ldots+\\alpha_{n-1}}+\\ldots+k^{n-1}\\cdot2^{\\alpha_1}+k^n}{k^{n+1}v_1}\\label{eq:prod_sum_v_n_plus_1}\\\\\n&=1+\\frac{2^{\\alpha_1+\\ldots+\\alpha_n}+k\\cdot\\sum_{j=1}^{i}k^{j-1}2^{\\alpha_1+\\ldots+\\alpha_n-\\sum_{l>i-j}\\alpha_l}}{k^{n+1}v_1}\\label{eq:prod_sum_v_n_plus_1_inserted}\\\\\n&=1+\\frac{2^{\\alpha_1+\\ldots+\\alpha_n}+k\\cdot\\left(v_{n+1}\\cdot2^{\\alpha_1+\\ldots+\\alpha_n}-k^nv_1\\right)}{k^{n+1}v_1}\\notag\\\\\n&=\\frac{2^{\\alpha_1+\\ldots+\\alpha_n}\\left(1+kv_{n+1}\\right)}{k^{n+1}v_1}\\label{eq:prod_sum_v_n_plus_1_simplified}\n\\end{flalign}\nWe inserted the sum used in equation~\\ref{eq:sum_v_n_plus_1} into the above-given equation~\\ref{eq:prod_sum_v_n_plus_1} and then obtained equation~\\ref{eq:prod_sum_v_n_plus_1_inserted}. Let us divide this product by the last factor and consider the product in the condition for cycle-alpha's upper limit, which iterates to $n$ instead of $n+1$:\n\n\\begin{equation}\n\\label{eq:prod_sum_v_n_simplified}\n\\prod_{i=1}^{n}\\left(1+\\frac{1}{kv_i}\\right)=\\frac{\\prod_{i=1}^{n+1}\\left(1+\\frac{1}{kv_i}\\right)}{\\frac{kv_{n+1}+1}{kv_{n+1}}}=\\frac{2^{\\alpha_1+\\ldots+\\alpha_n}\\cancel{\\left(1+kv_{n+1}\\right)}kv_{n+1}}{k^{n+1}v_1\\cancel{\\left(kv_{n+1}+1\\right)}}=\\frac{2^{\\alpha_1+\\ldots+\\alpha_n}v_{n+1}}{k^nv_1}\n\\end{equation}\n\nThe above-shown equation~\\ref{eq:prod_sum_v_n_simplified} for the product in the condition for cycle-alpha's upper limit becomes simplified, when we replaced the numerator by equation~\\ref{eq:prod_sum_v_n_plus_1_simplified}.\n\n\\section{Simplying the product for $k=3$}\n\\label{appx:product_simplification_k3}\nBelow we will show the simplification of the product in the condition for alpha's upper limit, which has been performed by equation~\\ref{eq:product_simplification_k3}:\n\\[\n\\prod_{i=1}^{n}\\frac{3^i(v_1+1)-2^i}{3^i(v_1+1)-3*2^{i-1}}\n=\\frac{1}{v_1}-\\frac{1}{v_1}\\left(\\frac{2}{3}\\right)^n+1\n\\]\n\nIn fact, this product is a telescoping product. We factor out $\\frac{1}{3^n}$, then shift the index in the product of the denominator by one to start with $i=0$, and use the product's telescopic property to cancel equal factors in numerator and denominator:\n\\begin{flalign*}\n\t&\\prod_{i=1}^{n}\\frac{3^i(v_1+1)-2^i}{3^i(v_1+1)-3*2^{i-1}}\n\t=\\frac{1}{3^n}\\prod_{i=1}^{n}\\frac{3^i(v_1+1)-2^i}{3^{i-1}(v_1+1)-2^{i-1}}\n\t=\\frac{1}{3^n}\\frac{\\prod_{i=1}^{n}\\left(3^i(v_1+1)-2^i\\right)}{\\prod_{i=1}^{n}\\left(3^{i-1}(v_1+1)-2^{i-1}\\right)}\\\\\n\t=&\\frac{1}{3^n}\\frac{\\prod_{i=1}^{n}\\left(3^i(v_1+1)-2^i\\right)}{\\prod_{i=0}^{n-1}\\left(3^i(v_1+1)-2^i\\right)}\n\t=\\frac{1}{3^n}\\frac{3^n(v_1+1)-2^n}{(v_1+1)-1}\n\t=\\frac{3^nv_1+3^n-2^n}{3^nv_1}\n\t=\\frac{1}{v_1}-\\frac{1}{v_1}\\left(\\frac{2}{3}\\right)^n+1\n\\end{flalign*}\n\n\\section{Proving the product simplification for $k=3$ inductively}\n\\label{appx:proof_product_simplification_k3}\nUsing induction, we prove the simplification below that has been made by equation~\\ref{eq:product_simplification_k3}:\n\\[\n\\prod_{i=1}^{n}\\frac{3^i(v_1+1)-2^i}{3^i(v_1+1)-3*2^{i-1}}\n=\\frac{1}{v_1}-\\frac{1}{v_1}\\left(\\frac{2}{3}\\right)^n+1\n\\]\n\nThe base case $n=1$ is readily comprehensible and obviously correct:\n\\[\n\\prod_{i=1}^{1}\\frac{3^i(v_1+1)-2^i}{3^i(v_1+1)-3*2^{i-1}}\n=\\frac{3(v_1+1)-2}{3(v_1+1)-3}\n=\\frac{1}{3v_1}+1\n=\\frac{1}{v_1}-\\frac{1}{v_1}\\left(\\frac{2}{3}\\right)+1\n\\]\n\nThe induction step is explained below, and here we arrive at a true statement too:\n\\begin{flalign*}\n\t\\prod_{i=1}^{n+1}\\frac{3^i(v_1+1)-2^i}{3^i(v_1+1)-3*2^{i-1}}&=\\frac{3^{n+1}(v_1+1)-2^{n+1}}{3^{n+1}(v_1+1)-3*2^n}\\prod_{i=1}^{n}\\frac{3^i(v_1+1)-2^i}{3^i(v_1+1)-3*2^{i-1}}\\\\\n\t&=\\frac{3^{n+1}(v_1+1)-2^{n+1}}{3^{n+1}(v_1+1)-3*2^n}\\left(\\frac{1}{v_1}-\\frac{1}{v_1}\\left(\\frac{2}{3}\\right)^n+1\\right)\\\\\n\t&=\\frac{3^{n+1}(v_1+1)-2^{n+1}}{3^{n+1}(v_1+1)-3*2^n}\\cdot\\frac{3^n-2^n+3^nv_1}{3^nv_1}\\\\\n\t&=\\frac{3^{n+1}(v_1+1)-2^{n+1}}{\\cancel{3^{n+1}(v_1+1)-3*2^n}}\\cdot\\frac{\\cancel{3*(3^n-2^n+3^nv_1)}}{3*3^nv_1}\\\\\n\t&=\\frac{1}{v_1}-\\frac{1}{v_1}\\left(\\frac{2}{3}\\right)^{n+1}+1\n\\end{flalign*}\n\n\\section{The condition for an Engel expansion's limited growth}\n\\label{appx:condition_limited_growth}\nThe steps for transforming the inequality~\\ref{eq:condition_limited_growth} as the condition for limiting an Engel expansion's growth (see section~~\\ref{sec:condition_limited_growth}) are given below:\n\n\\begin{flalign*}\n0&<1+v_1-\\frac{3^nv_1}{2^{m+n}}-\\frac{3^{n-1}}{2^{m+n}}-\\frac{3^{n-1}2^{m+1}}{2^{m+n}}\\\\\n0&<1+v_1-\\frac{3^{n-1}}{2^{m+n}}\\left(3v_1+1\\right)-\\frac{3^{n-1}}{2^{n-1}}\\\\\n0&<2^{n-1}+2^{n-1}v_1-\\frac{3^{n-1}}{2^{m+1}}\\left(3v_1+1\\right)-3^{n-1}\\\\\n0&<3\\cdot2^{n-1}+3\\cdot2^{n-1}v_1-3\\cdot\\frac{3^{n-1}}{2^{m+1}}\\left(3v_1+1\\right)-3^n-2\\cdot2^{n-1}+2\\cdot2^{n-1}\\\\\n0&<2^{n-1}\\left(3v_1+1\\right)-3\\cdot\\frac{3^{n-1}}{2^{m+1}}\\left(3v_1+1\\right)-3^n+2^n\\\\\n0&<\\left(3v_1+1\\right)\\left(2^{n-1}-3\\cdot\\frac{3^{n-1}}{2^{m+1}}\\right)-3^n+2^n\\\\\n3^n-2^n&<\\left(3v_1+1\\right)\\left(2^{n-1}-3\\cdot\\frac{3^{n-1}}{2^{m+1}}\\right)\n\\end{flalign*}\n\nNow we reshape the inequality further so that we isolate $v_1$ to the right side of this inequality:\n{\\setlength{\\jot}{1.2em}\n\\begin{flalign*}\n\\frac{3^n-2^n}{2^{n-1}-3\\cdot\\frac{3^{n-1}}{2^{m+1}}}-1&<3v_1\\\\\n\\frac{3^n2^{m+1}-2^n2^{m+1}}{2^{m+1}2^{n-1}-3^n}-1&<3v_1\\\\\n\\frac{3^n2^{m+1}-2\\cdot3^n-2^n2^{m+1}+2\\cdot3^n}{2^{m+n}-3^n}-1&<3v_1\\\\\n\\frac{3\\cdot3^{n-1}2^{m+1}-2\\cdot3\\cdot3^{n-1}-2\\cdot2^{n-1}2^{m+1}+2\\cdot3^n}{3\\cdot\\left(2^{m+n}-3^n\\right)}-\\frac{1}{3}&<v_1\\\\\n\\frac{\\cancel3\\cdot3^{n-1}2^{m+1}-2\\cdot\\cancel3\\cdot3^{n-1}}{\\cancel3\\cdot\\left(2^{m+n}-3^n\\right)}-\\frac{2\\cdot\\cancel{\\left(2^{m+n}-3^n\\right)}}{3\\cdot\\cancel{\\left(2^{m+n}-3^n\\right)}}-\\frac{1}{3}&<v_1\\\\\n\\frac{3^{n-1}2^{m+1}-2\\cdot3^{n-1}}{2^{m+n}-3^n}-1&<v_1\n\\end{flalign*}}\n\n%\\section{An alternative proof for alpha's upper limit for $H_{C,1}$}\n%\\label{appx:proof_k1}\n%We demonstrate that condition~\\ref{eq:condition_max} is true for $k=1$. What makes this case so special and therefore so manageable is that the equation in theorem~\\ref{theo:2} constantly yields $2^1$, whatever value we use for $n$. By setting $k=1$, the condition becomes reduced to:\n%\\begin{equation}\n%\\label{eq:condition_k1}\n%\\prod_{i=1}^{n}\\frac{v_i+1}{v_i}<2^2\n%\\end{equation}\n%One can see instantly that the condition~\\ref{eq:condition_k1} above is met for $n=v_1=1$. This trivial cycle only includes the sole vertex $v_1=1$. The fact which causes a worst case sequence $v_n,v_{n-1},\\ldots,v_2,v_1$ describing a path from $v_n$ to $v_1$ is precisely that between two successive nodes a division by two was only made once:\n%\\begin{equation}\n%\\label{eq:worst_case_1}\n%\\arraycolsep=1.4pt\n%\\begin{array}{llll}\n%v_n&=2^{n-1}&\\cdot\\ (v_1-1)+1&\\\\\n%v_{n-1}&=2^{n-2}&\\cdot\\ (v_1-1)+1&\\\\\n%\\vdots\\\\\n%v_2&=2^1&\\cdot\\ (v_1-1)+1&=2v_1-1\\\\\n%v_1&=2^0&\\cdot\\ (v_1-1)+1&=v_1\n%\\end{array}\n%\\end{equation}\n%One example for such a sequence is $v_4=17,v_3=9,v_2=5,v_1=3$. It shall be mentioned that the sequence $v_1,2\\cdot v_1-1,4\\cdot v_1-3,\\ldots$ is an increasing one for any $v_1>1$, which means $v_1<v_2<\\ldots<v_{n-1}<v_n$. Why might such a sequence be referred to as worst case? Ultimately, it is because one needs to show that the product stays below the upper limit $2^2=4$. The smaller the values (labels) of the vertices, the larger the product. If we allowed additional divisions by $2$, the sequence would increase more steeply, the vertices' values would be larger and the product would consequently be smaller.\n\n%Setting the worst case sequence $v_n=2^{n-1}(v_1-1)+1$ into the product \\ref{eq:condition_k1} leads to the following product:\n%\\begin{equation}\n%\\label{eq:condition_k1_v1}\n%\\prod_{i=1}^{n}\\frac{2^{i-1}(v_1-1)+2}{2^{i-1}(v_1-1)+1}\n%\\end{equation}\n%As previously mentioned, we have to consider the worst case scenario, which results in the maximum product. We provoke the worst case if a vertex's value is as small as possible, which we achieve with the sequence $1,3,5,9,17,\\ldots$ that is composed from two partial sequences, namely the one-element sequence $v_1=1$ and the sequence defined by \\ref{eq:worst_case_1} starting with $v_1=3$. As product we then receive the composed product given below which must remain below the limit 4:\n%\\[\n%\\prod_{i=1}^{1}\\frac{v_i+1}{v_i}\\prod_{i=1}^{n}\\frac{2^{i-1}(v_1-1)+2}{2^%{i-1}(v_1-1)+1}=2\\prod_{i=1}^{n}\\frac{2^i+2}{2^i+1}<4\n%\\]\n%The first sub-product refers to \\ref{eq:condition_k1} and comprises only a single iteration. We insert the value $v_1=1$ yielding a final result of $2$. The second sub-product is sourced from \\ref{eq:condition_k1_v1} and has been simplified by setting $v_1=3$. We further facilitate this second sub-product as shown below:\n%\\begin{equation*}\n%\t\\prod_{i=1}^{n}\\frac{2^i+2}{2^i+1}=2^n\\prod_{i=1}^{n}\\frac{2^{i-1}+1}{2^i+1}=2^n\\frac{(2^0+1)\\cancel{(2^1+1)}\\cancel{(2^2+1)}\\cdots\\cancel{(2^{n-1}+1)}}{\\cancel{(2^1+1)}\\cancel{(2^2+1)}\\cdots\\cancel{(2^{n-1}+1)}(2^n+1)}=\\frac{2^{n+1}}{2^n+1}\n%\\end{equation*}\n\n%The upper limit of this second sub-product is $2$ and consequently the entire product composed by both sub-products therefore converges from below towards $4$, which leads to our condition~\\ref{eq:condition_k1} being fulfilled even in the worst case:\n%\\[\n%\\prod_{i=1}^{\\infty}\\frac{2^i+2}{2^i+1}=\\lim_{n\\to\\infty}\\frac{2^{n+1}}{2^n+1}=2\n%\\]\n\n\\section{Further worst-case studies}\n\\label{sec:worstcase_k3}\nRegarding worst case scenarios, a distinction must be made between two basic cases:\n\\begin{itemize}\n\t\\item The vertex $v_{n+1}$ becomes a maximum. This kind of worst case we have dealt with in chapter~\\ref{ch:maximizing_target_node} and we used for proving cycle-alpha's upper limit in $H_{C,1}$ with section~\\ref{sec:alphas_upper_limit_k_1}.\n\t\\item The product in condition~\\ref{eq:condition_max} and consequently the sum of reciprocal vertices, formulated in \\ref{appx:sum_reciprocal_vertices}, becomes a maximum.\n\\end{itemize}\nTrying to find a worst case that maximizes the product in condition~\\ref{eq:condition_max} means to search for a sequence of odd numbers that rises as high as possible. One could try the ascending sequence of odd integers $v_i=2i-1$ (beginning at $v_1=1$), but will find that for this case the product will not converge against a limit value. This sequence (beginning at $v_1=1$) allow us to transform the product contained in condition~\\ref{eq:condition_max} into a limit analyzable function using the Pochhammer’s symbol (sometimes referred to as the \\textit{rising factorial} or \\textit{shifted factorial}), which is denoted by $(x)_n$ and defined as follows \\cite{Ref_Zwillinger_Kokoska}, \\cite[p.~679]{Ref_Brychkov} and \\cite[p.~1005]{Ref_Trott}:\n\\[\n(x)_n=x(x+1)(x+2)\\cdots(x+n-1)=\\prod_{i=0}^{n-1}(x+i)=\\prod_{i=1}^{n}(x+i-1)=\\frac{\\Gamma(x+n)}{\\Gamma(x)}\n\\]\n\nSetting $v_i=2i-1$ into the product expressed by condition~\\ref{eq:condition_max} and setting $x=\\frac{k+1}{2k}$ into Pochhammer’s symbol $(x)_n$ interestingly makes it possible for us to perform the following transformation:\n\\begin{equation}\n\\label{eq:pochhammer}\n\\prod_{i=1}^{n}\\left(1+\\frac{1}{kv_i}\\right)\n=\\frac{\\prod_{i=1}^{n}(kv_i+1)}{\\prod_{i=1}^{n}kv_i}\n=\\frac{\\prod_{i=1}^{n}\\left(k(2i-1)+1\\right)}{k^n\\prod_{i=1}^{n}(2i-1)}\n=\\frac{2^{2n}n!}{(2n)!}\\cdot\\frac{\\Gamma\\left(\\frac{k+1+2kn}{2k}\\right)}{\\Gamma\\left(\\frac{k+1}{2k}\\right)}\n\\end{equation}\n\n\\begin{example}\n\tOne simple example that is easy to recalculate may be provided by choosing $k=3$ and $n=4$:\n\t\\[\n\t\\left(1+\\frac{1}{3*1}\\right)\\left(1+\\frac{1}{3*3}\\right)\\left(1+\\frac{1}{3*5}\\right)\\left(1+\\frac{1}{3*7}\\right)=1,6555=\\frac{2^8*4!}{8!}\\cdot\\frac{\\Gamma(\\frac{14}{3})}{\\Gamma(\\frac{4}{6})}\n\t\\]\n\\end{example}\n\nThe product in the numerator in equation~\\ref{eq:pochhammer} will be transformed into a form that allows us to use the Pochhammer’s symbol:\n\\[\\prod_{i=1}^{n}\\left((2i-1)k+1\\right)=2^nk^n\\prod_{i=1}^{n}\\frac{(2i-1)k+1}{2k}=2^nk^n\\prod_{i=1}^{n}\\frac{k+1+2ki-2k}{2k}=2^nk^n\\prod_{i=1}^{n}\\left(\\frac{k+1}{2k}+i-1\\right)\\]\n\nThis product can be written now as $2^nk^n(x)_n$, whwereby $x=\\frac{k+1}{2k}$:\n\\[\\prod_{i=1}^{n}\\left((2i-1)k+1\\right)=2^nk^n\\frac{\\Gamma\\left(\\frac{k+1+2kn}{2k}\\right)}{\\Gamma\\left(\\frac{k+1}{2k}\\right)}\\]\n\nWe recall the basic fact that the product of even integers is given by $\\prod_{i=1}^{n}2i=2^n\\cdot n!$ and the product of odd integers is $\\prod_{i=1}^{n}\\left(2i-1\\right)=1\\cdot3\\cdot5\\cdot7\\ldots=\\frac{(2n)!}{2^n\\cdot n!}$. Thus we can transform the product in the denominator in equation~\\ref{eq:pochhammer} as follows:\n\\[\\prod_{i=1}^{n}kv_i=k^n\\prod_{i=1}^{n}v_i=k^n\\prod_{i=1}^{n}(2i-1)=k^n\\frac{(2n)!}{2^nn!}\\]\n\n\\par\\medskip\nThis product is divergent, it does not converge to a limiting value. Thankfully, the ascending sequence of natural odd numbers overshoots the worst-case scenario. According to this scenario we would not have contracted a single edge between two successive nodes.\n", "meta": {"hexsha": "08c4d60f841a7103f7d7f166f37c8c823e984beb", "size": 14602, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01 Graph Theory/TeX/v4.1/chapter/07_appendix.tex", "max_stars_repo_name": "Sultanow/collatz", "max_stars_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-01T15:12:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T15:54:55.000Z", "max_issues_repo_path": "01 Graph Theory/TeX/v4.1/chapter/07_appendix.tex", "max_issues_repo_name": "Sultanow/collatz", "max_issues_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01 Graph Theory/TeX/v4.1/chapter/07_appendix.tex", "max_forks_repo_name": "Sultanow/collatz", "max_forks_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-06T20:44:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-06T20:44:07.000Z", "avg_line_length": 77.670212766, "max_line_length": 751, "alphanum_fraction": 0.6890152034, "num_tokens": 6007, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7179409850693205}}
{"text": "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Copyright (c) 2003-2018 by The University of Queensland\n% http://www.uq.edu.au\n%\n% Primary Business: Queensland, Australia\n% Licensed under the Apache License, version 2.0\n% http://www.apache.org/licenses/LICENSE-2.0\n%\n% Development until 2012 by Earth Systems Science Computational Center (ESSCC)\n% Development 2012-2013 by School of Earth Sciences\n% Development from 2014 by Centre for Geoscience Computing (GeoComp)\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\chapter{Einstein Notation}\n\\label{EINSTEIN NOTATION}\n\nCompact notation is used in equations such continuum mechanics and linear\nalgebra; it is known as Einstein notation or the Einstein summation convention.\nIt makes the conventional notation of equations involving tensors more compact\nby shortening and simplifying them.\n\nThere are two rules which make up the convention.\nFirstly, the rank of a tensor is represented by an index.\nFor example, $a$ is a scalar, $b_{i}$ represents a vector, and $c_{ij}$\nrepresents a matrix.\nSecondly, if an expression contains repeated subscripted variables, they are\nassumed to be summed over all possible values, from $0$ to $n$.\nFor example, the expression\n\\begin{equation}\ny = a_{0}b_{0} + a_{1}b_{1} + \\ldots + a_{n}b_{n}\n\\label{NOTATION1}\n\\end{equation}\ncan be represented as\n\\begin{equation}\ny = \\sum_{i=0}^n  a_{i}b_{i}\n\\label{NOTATION2}\n\\end{equation}\nthen in Einstein notation:\n\\begin{equation}\ny = a_{i}b_{i}\n\\label{NOTATION3}\n\\end{equation}\n%\nAnother example:\n\\begin{equation}\n\\nabla p = \\frac{\\partial p}{\\partial x_{0}}\\textbf{i} + \\frac{\\partial p}{\\partial x_{1}}\\textbf{j} + \\frac{\\partial p}{\\partial x_{2}}\\textbf{k}\n\\label{NOTATION4}\n\\end{equation}\ncan be expressed in Einstein notation as\n\\begin{equation}\n\\nabla p = p,_{i}\n\\label{NOTATION5}\n\\end{equation}\nwhere the comma ',' in the subscript indicates the partial derivative.\n\n\\noindent For a tensor:\n\\begin{equation}\n\\sigma _{ij}= \n\\left[ \\begin{array}{ccc}\n\\sigma_{00} & \\sigma_{01} & \\sigma_{02} \\\\\n\\sigma_{10} & \\sigma_{11} & \\sigma_{12} \\\\\n\\sigma_{20} & \\sigma_{21} & \\sigma_{22} \\\\\n\\end{array} \\right]\n\\label{NOTATION6}\n\\end{equation}\n\nThe $\\delta_{ij}$ is the Kronecker $\\delta$-symbol, which is a matrix with ones\nin its diagonal entries ($i = j$) and zeros in the remaining entries\n($i \\neq j$).\n\n\\begin{equation}\n\\delta _{ij} = \n\\left \\{ \\begin{array}{cc}\n1, & \\mbox{if $i = j$} \\\\\n0, & \\mbox{if $i \\neq j$} \\\\\n\\end{array}\n\\right.\n\\label{KRONECKER}\n\\end{equation}\n\n", "meta": {"hexsha": "89d8964e2f88e86da2301d804ff5b557822edada", "size": 2566, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/user/notation.tex", "max_stars_repo_name": "markendr/esys-escript.github.io", "max_stars_repo_head_hexsha": "0023eab09cd71f830ab098cb3a468e6139191e8d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/user/notation.tex", "max_issues_repo_name": "markendr/esys-escript.github.io", "max_issues_repo_head_hexsha": "0023eab09cd71f830ab098cb3a468e6139191e8d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-01-14T03:07:43.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-14T03:07:43.000Z", "max_forks_repo_path": "doc/user/notation.tex", "max_forks_repo_name": "markendr/esys-escript.github.io", "max_forks_repo_head_hexsha": "0023eab09cd71f830ab098cb3a468e6139191e8d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.9156626506, "max_line_length": 146, "alphanum_fraction": 0.6773187841, "num_tokens": 772, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7179409672660108}}
{"text": "\\chapter{Representations of algebras}\nIn the 19th century, the word ``group'' hadn't been invented yet;\nall work was done with subsets of $\\GL(n)$ or $S_n$.\nOnly much later was the abstract definition of a group was given,\nan abstract set $G$ which was an object in its own right.\n\nWhile this abstraction is good for some reasons,\nit is often also useful to work with concrete representations.\nThis is the subject of representation theory.\nLinear algebra is easier than abstract algebra,\nso if we can take a group $G$ and represent it concretely\nas a set of matrices in $\\opname{GL}(n)$,\nthis makes them easier to study.\nThis is the \\emph{representation theory of groups}:\nhow can we take a group and represent its elements as matrices?\n\n\\section{Algebras}\n\\prototype{$k[x_1, \\dots, x_n]$ and $k[G]$.}\nRather than working directly with groups from the beginning,\nit will be more convenient to deal with so-called $k$-algebras.\nThis setting is more natural and general than that of groups,\nso once we develop the theory of algebras well enough,\nit will be fairly painless to specialize to the case of groups.\n\nColloquially,\n\\begin{moral}\n\tAn associative $k$-algebra is\n\ta possibly noncommutative ring with a copy of $k$ inside it.\n\tIt is thus a $k$-vector space.\n\\end{moral}\n% In particular this makes such an algebra into a $k$-vector space.\nI'll present examples before the definition:\n\\begin{example}\n\t[Examples of $k$-Algebras]\n\tLet $k$ be any field. The following are examples of $k$-algebras:\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The field $k$ itself.\n\t\t\\ii The polynomial ring $k[x_1, \\dots, x_n]$.\n\t\t\\ii The set of $n \\times n$ matrices with entries in $k$,\n\t\twhich we denote by $\\Mat_n(k)$.\n\t\tNote the multiplication here is not commutative.\n\t\t\\ii The set $\\Mat(V)$ of linear operators $T : V \\to V$,\n\t\twith multiplication given by the composition of operators.\n\t\t(Here $V$ is some vector space over $k$.)\n\t\tThis is really the same as the previous example.\n\t\\end{enumerate}\n\\end{example}\n\\begin{definition}\n\tLet $k$ be a field.\n\tA \\vocab{$k$-algebra} $A$ is a \\emph{possibly noncommutative} ring,\n\tequipped with an injective ring homomorphism $k \\injto A$\n\t(whose image is the ``copy of $k$'').\n\tIn particular, $1_k \\mapsto 1_A$.\n\n\tThus we can consider $k$ as a subset of $A$, and\n\twe then additionally require $\\lambda \\cdot a = a \\cdot \\lambda$\n\tfor each $\\lambda \\in k$ and $a \\in A$.\n\n\tIf the multiplication operation is also commutative,\n\tthen we say $A$ is a \\vocab{commutative algebra}.\n\\end{definition}\n\\begin{definition}\n\tEquivalently, a \\vocab{$k$-algebra} $A$ is a\n\t$k$-\\emph{vector space} which also has an associative,\n\tbilinear multiplication operation (with an identity $1_A$).\n\tThe ``copy of $k$'' is obtained by considering elements\n\t$\\lambda 1_A$ for each $\\lambda \\in k$\n\t(i.e.\\ scaling the identity by the elements of $k$,\n\ttaking advantage of the vector space structure).\n\\end{definition}\n\n\\begin{abuse}\n\tSome other authors don't require $A$ to be associative or to have\n\tan identity, so to them what we have just defined is an\n\t``associative algebra with $1$''.\n\tHowever, this is needlessly wordy for our purposes.\n\\end{abuse}\n\n\\begin{example}\n\t[Group algebra]\n\tThe \\vocab{group algebra} $k[G]$ is the $k$-vector space\n\twhose \\emph{basis elements} are the elements of a group $G$,\n\tand where the product of two basis elements is the group multiplication.\n\tFor example, suppose $G = \\Zc 2 = \\{1_G, x\\}$.\n\tThen\n\t\\[ k[G] = \\left\\{ a1_G + bx \\mid a,b \\in k \\right\\} \\]\n\twith multiplication given by\n\t\\[ (a1_G + bx)(c1_G+dx) = (ac+bd)1_G + (bc+ad)x. \\]\n\\end{example}\n\\begin{ques}\n\tWhen is $k[G]$ commutative?\n\\end{ques}\nThe example $k[G]$ is very important,\nbecause (as we will soon see) a representation of the algebra $k[G]$\namounts to a representation of the group $G$ itself.\n\nIt is worth mentioning at this point that:\n\\begin{definition}\n\tA \\vocab{homomorphism} of $k$-algebras $A$, $B$ is a\n\tlinear map $T : A \\to B$ which respects multiplication\n\t(i.e.\\ $T(xy) = T(x)T(y)$) and which sends $1_A$ to $1_B$.\n\tIn other words, $T$ is both a homomorphism as a ring and as a vector space.\n\\end{definition}\n\\begin{definition}\n\tGiven $k$-algebras $A$ and $B$, the \\vocab{direct sum} $A \\oplus B$\n\tis defined as pairs $a + b$, where addition is done in the obvious way,\n\tbut we declare $ab = 0$ for any $a \\in A$ and $b \\in B$.\n\\end{definition}\n\\begin{ques}\n\tShow that $1_A + 1_B$ is the multiplicative identity of $A \\oplus B$.\n\\end{ques}\n\n\\section{Representations}\n\\prototype{$k[S_3]$ acting on $k^{\\oplus 3}$ is my favorite.}\n\n\\begin{definition}\n\tA \\vocab{representation} of a $k$-algebra $A$\n\t(also a \\vocab{left $A$-module}) is:\n\t\\begin{enumerate}[(i)]\n\t\t\\ii A $k$-vector space $V$, and\n\t\t\\ii An \\emph{action} $\\cdot$ of $A$ on $V$: thus, for every $a \\in A$\n\t\twe can take $v \\in V$ and act on it to get $a \\cdot v$.\n\t\tThis satisfies the usual axioms:\n\t\t\\begin{itemize}\n\t\t\t\\ii $(a+b) \\cdot v = a \\cdot v + b \\cdot v$,\n\t\t\t$a \\cdot (v+w) = a \\cdot v + a \\cdot w$,\n\t\t\tand $(ab) \\cdot v = a \\cdot (b \\cdot v)$.\n\t\t\t\\ii $\\lambda \\cdot v = \\lambda v$ for $\\lambda \\in k$.\n\t\t\tIn particular, $1_A \\cdot v = v$.\n\t\t\\end{itemize}\n\t\\end{enumerate}\n\\end{definition}\n\n\\begin{definition}\n\tThe action of $A$ can be more succinctly described as saying\n\tthat there is a \\emph{$k$-algebra homomorphism} $\\rho : A \\to \\Mat(V)$.\n\t(So $a \\cdot v = \\rho(a)(v)$.)\n\tThus we can also define a \\vocab{representation} of $A$ as a pair\n\t\\[ \\left( V, \\rho : A \\to \\Mat(V) \\right). \\]\n\\end{definition}\nThis is completely analogous to how a group action $G$ on a set $X$\nwith $n$ elements just amounts to a group homomorphism $G \\to S_n$.\nFrom this perspective, what we are really trying to do is:\n\\begin{moral}\n\tIf $A$ is an algebra,\n\twe are trying to \\emph{represent}\n\tthe elements of $A$ as matrices.\n\\end{moral}\n\n\\begin{abuse}\n\tWhile a representation is a pair $(V, \\rho)$\n\tof \\emph{both} the vector space $V$ and the action $\\rho$,\n\twe frequently will just abbreviate it to ``$V$''.\n\tThis is probably one of the worst abuses I will commit,\n\tbut everyone else does it and I fear the mob.\n\\end{abuse}\n\\begin{abuse}\n\tRather than $\\rho(a)(v)$ we will just write $\\rho(a)v$.\n\\end{abuse}\n\n\\begin{example}\n\t[Representations of $\\Mat(V)$]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Let $A = \\Mat_2(\\RR)$.\n\t\tThen there is a representation $(\\RR^{\\oplus 2}, \\rho)$\n\t\twhere a matrix $a \\in A$ just acts by $a \\cdot v = \\rho(a)(v) = a(v)$.\n\n\t\t\\ii More generally, given a vector space $V$ over any field $k$,\n\t\tthere is an obvious representation of $A = \\Mat(V)$\n\t\tby $a \\cdot v = \\rho(a)(v) = a(v)$ (since $a \\in \\Mat(V)$).\n\n\t\tFrom the matrix perspective: if $A = \\Mat(V)$,\n\t\tthen we can just represent $A$ as matrices over $V$.\n\n\t\t\\ii There are other representations of $A = \\Mat_2(\\RR)$.\n\t\tA silly example is the representation $(\\RR^{\\oplus 4}, \\rho)$ given by\n\t\t\\[\n\t\t\t\\rho : \n\t\t\t\\begin{bmatrix} a & b \\\\ c & d \\end{bmatrix} \n\t\t\t\\mapsto\n\t\t\t\\begin{bmatrix} a & b & 0 & 0 \\\\ c & d & 0 & 0 \\\\\n\t\t\t\t0 & 0 & a & b \\\\ 0 & 0 & c & d \\end{bmatrix} .\n\t\t\\]\n\t\tMore abstractly, viewing $\\RR^{\\oplus 4}$ as\n\t\t$(\\RR^{\\oplus 2}) \\oplus (\\RR^{\\oplus 2})$,\n\t\tthis is $a \\cdot (v_1,v_2) = (a \\cdot v_1, a \\cdot v_2)$.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{example}\n\t[Representations of polynomial algebras]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Let $A = k$.\n\t\tThen a representation of $k$ is just any $k$-vector space $V$.\n\n\t\t\\ii If $A = k[x]$,\n\t\tthen a representation $(V, \\rho)$ of $A$\n\t\tamounts to a vector space $V$ plus the choice of\n\t\ta linear operator $T \\in \\Mat(V)$ (by $T = \\rho(x)$).\n\n\t\t\\ii If $A = k[x] / (x^2)$\n\t\tthen a representation $(V, \\rho)$ of $A$\n\t\tamounts to a vector space $V$ plus the choice of\n\t\ta linear operator $T \\in \\Mat(V)$ satisfying $T^2 = 0$.\n\n\t\t\\ii We can create arbitrary ``functional equations'' with this pattern.\n\t\tFor example, if $A = k[x,y] / (x^2 - x+y, y^4)$\n\t\tthen representing $A$ by $V$ amounts to finding operators\n\t\t$S, T \\in \\Mat(V)$ satisfying $S^2 = S-T$ and $T^4 = 0$.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{example}\n\t[Representations of groups]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Let $A = \\RR[S_3]$.\n\t\tThen let \n\t\t\\[ V = \\RR^{\\oplus 3} = \\{ (x,y,z) \\mid x,y,z \\in \\RR \\}. \\]\n\t\tWe can let $A$ act on $V$ as follows:\n\t\tgiven a permutation $\\pi \\in S_3$, we permute the corresponding\n\t\tcoordinates in $V$.\n\t\tSo for example, if \n\t\t\\[ \\text{If } \\pi = (1 \\; 2)\n\t\t\\text{ then } \\pi \\cdot (x,y,z) = (y,x,z). \\]\n\t\tThis extends linearly to let $A$ act on $V$,\n\t\tby permuting the coordinates.\n\n\t\tFrom the matrix perspective, what we are doing\n\t\tis representing the permutations in $S_3$\n\t\tas permutation matrices on $k^{\\oplus 3}$, like\n\t\t\\[ (1 \\; 2)\n\t\t\\mapsto \\begin{bmatrix} 0&1&0 \\\\ 1&0&0 \\\\ 0&0&1 \\end{bmatrix}. \\]\n\t\t\n\t\t\\ii More generally, let $A = k[G]$.\n\t\tThen a representation $(V, \\rho)$ of $A$\n\t\tamounts to a group homomorphism $\\psi : G \\to \\GL(V)$.\n\t\t(In particular, $\\rho(1_G) = \\id_V$.)\n\t\tWe call this a \\vocab{group representation} of $G$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{example}[Regular representation]\n\tAny $k$-algebra $A$ is a representation $(A, \\rho)$ over itself,\n\twith $a \\cdot b = \\rho(a)(b) = ab$ (i.e.\\ multiplication given by $A$).\n\tThis is called the \\vocab{regular representation}, denoted $\\Reg(A)$.\n\\end{example}\n\n\\section{Direct sums}\n\\prototype{The example with $\\RR[S_3]$ seems best.}\n\\begin{definition}\n\tLet $A$ be $k$-algebra and let $V = (V, \\rho_V)$ and $W = (W, \\rho_W)$\n\tbe two representations of $A$.\n\tThen $V \\oplus W$ is a representation, with action $\\rho$ given by\n\t\\[ a \\cdot (v,w) = (a \\cdot v, a \\cdot w). \\]\n\tThis representation is called the \\vocab{direct sum} of $V$ and $W$.\n\\end{definition}\n\\begin{example}\n\tEarlier we let $\\Mat_2(\\RR)$ act on $\\RR^{\\oplus 4}$ by\n\t\\[\n\t\t\\rho : \n\t\t\\begin{bmatrix} a & b \\\\ c & d \\end{bmatrix} \n\t\t\\mapsto\n\t\t\\begin{bmatrix} a & b & 0 & 0 \\\\ c & d & 0 & 0 \\\\\n\t\t\t0 & 0 & a & b \\\\ 0 & 0 & c & d \\end{bmatrix} .\n\t\\]\n\tSo this is just a direct sum of two two-dimensional representations.\n\\end{example}\nMore generally, given representations $(V, \\rho_V)$ and $(W, \\rho_W)$\nthe representation $\\rho$ of $V \\oplus W$ looks like\n\\[ \\rho(a) =\n\t\\begin{bmatrix}\n\t\t\\rho_V(a) & 0 \\\\ 0 & \\rho_W(a)\n\t\\end{bmatrix}.\n\\]\n\\begin{example}[Representation of $S_n$ decomposes]\n\tLet $A = \\RR[S_3]$ again,\n\tacting via permutation of coordinates on\n\t\\[ V = \\RR^{\\oplus 3} = \\{ (x,y,z) \\mid x,y,z \\in \\RR \\}. \\]\n\tConsider the two subspaces\n\t\\begin{align*}\n\t\tW_1 &= \\left\\{ (t,t,t) \\mid t \\in \\RR \\right\\} \\\\\n\t\tW_2 &= \\left\\{ (x,y,z) \\mid x+y+z = 0 \\right\\}.\n\t\\end{align*}\n\tNote $V = W_1 \\oplus W_2$ as vector spaces.\n\tBut each of $W_1$ and $W_2$ is a subrepresentation\n\t(since the action of $A$ keeps each $W_i$ in place),\n\tso $V = W_1 \\oplus W_2$ as representations too.\n\\end{example}\n\nDirect sums also come up when we play with algebras.\n\\begin{proposition}[Representations of $A \\oplus B$ are $V_A \\oplus V_B$]\n\t\\label{prop:rep_direct_sum}\n\tLet $A$ and $B$ be $k$-algebras.\n\tThen every representation of $A \\oplus B$ is of the form \n\t\\[ V_A \\oplus V_B \\]\n\twhere $V_A$ and $V_B$ are representations of $A$ and $B$, respectively.\n\\end{proposition}\n\\begin{proof}[Sketch of Proof]\n\tLet $(V, \\rho)$ be a representation of $A \\oplus B$.\n\tFor any $v \\in V$, $\\rho(1_A+1_B)v = \\rho(1_A)v + \\rho(1_B)v$.\n\tOne can then set $V_A = \\{ \\rho(1_A)v \\mid v \\in V \\}$\n\tand $V_B = \\{ \\rho(1_B)v \\mid v \\in V \\}$.\n\tThese are disjoint, since if $\\rho(1_A) v = \\rho(1_B) v'$,\n\twe have $\\rho(1_A)v = \\rho(1_A1_A)v = \\rho(1_A1_B) v' = 0_V$,\n\tand similarly for the other side.\n\\end{proof}\n\n\\section{Irreducible and indecomposable representations}\n\\prototype{$k[S_3]$ decomposes as the sum of two spaces.}\n\nOne of the goals of representation theory will be to classify\nall possible representations of an algebra $A$.\nIf we want to have a hope of doing this,\nthen we want to discard ``silly'' representations such as\n\\[\n\t\\rho : \n\t\\begin{bmatrix} a & b \\\\ c & d \\end{bmatrix} \n\t\\mapsto\n\t\\begin{bmatrix} a & b & 0 & 0 \\\\ c & d & 0 & 0 \\\\\n\t\t0 & 0 & a & b \\\\ 0 & 0 & c & d \\end{bmatrix}\n\\]\nand focus our attention instead on ``irreducible'' representations.\nThis motivates:\n\\begin{definition}\n\tLet $V$ be a representation of $A$.\n\tA \\vocab{subrepresentation} $W \\subseteq V$ is a subspace $W$\n\twith the property that for any $a \\in A$ and $w \\in W$,\n\t$a \\cdot w \\in W$.\n\tIn other words, this subspace is invariant under actions by $A$.\n\\end{definition}\nThus for example if $V = W_1 \\oplus W_2$ for representations $W_1$, $W_2$\nthen $W_1$ and $W_2$ are subrepresentations of $V$.\n\n\\begin{definition}\n\tIf $V$ has no proper nonzero subrepresentations then it is \\vocab{irreducible}.\n\tIf there is no pair of proper subrepresentations $W_1$, $W_2$ such that $V = W_1 \\oplus W_2$,\n\tthen we say $V$ is \\vocab{indecomposable}.\n\\end{definition}\n\\begin{definition}\n\tFor brevity, an \\vocab{irrep} of an algebra/group is a\n\t\\emph{finite-dimensional} irreducible representation.\n\\end{definition}\n\n\\begin{example}[Representation of $S_n$ decomposes]\n\tLet $A = \\RR[S_3]$ again, acting via permutation of coordinates on\n\t\\[ V = \\RR^{\\oplus 3} = \\{ (x,y,z) \\mid x,y,z \\in \\RR \\}. \\]\n\tConsider again the two subspaces\n\t\\begin{align*}\n\t\tW_1 &= \\left\\{ (t,t,t) \\mid t \\in \\RR \\right\\} \\\\\n\t\tW_2 &= \\left\\{ (x,y,z) \\mid x+y+z = 0 \\right\\}.\n\t\\end{align*}\n\tAs we've seen, $V = W_1 \\oplus W_2$, and thus $V$ is not irreducible.\n\tBut one can show that $W_1$ and $W_2$ are irreducible \n\t(and hence indecomposable) as follows.\n\t\\begin{itemize}\n\t\t\\ii For $W_1$ it's obvious, since $W_1$ is one-dimensional.\n\t\t\\ii For $W_2$, consider any vector $w = (a,b,c)$\n\t\twith $a+b+c=0$ and not all zero.  Then WLOG we can assume $a \\neq b$ \n\t\t(since not all three coordinates are equal).\n\t\tIn that case, $(1 \\; 2)$ sends $w$ to $w' = (b,a,c)$.\n\t\tThen $w$ and $w'$ span $W_2$.\n\t\\end{itemize}\n\tThus $V$ breaks down completely into irreps.\n\\end{example}\n\nUnfortunately, if $W$ is a subrepresentation of $V$,\nthen it is not necessarily the case that we can find a\nsupplementary vector space $W'$ such that $V = W \\oplus W'$.\nPut another way, if $V$ is reducible, we know that it has a subrepresentation,\nbut a decomposition requires \\emph{two} subrepresentations.\nHere is a standard counterexample:\n\\begin{exercise}\n\t\\label{exer:irred_not_indecomp}\n\tLet $A = \\RR[x]$, and $V = \\RR^{\\oplus 2}$ be the representation with action\n\t\\[ \\rho(x) = \\begin{bmatrix} 1 & 1 \\\\ 0 & 1 \\end{bmatrix}. \\]\n\tShow that the only subrepresentation is $W = \\{ (t,0) \\mid t \\in \\RR \\}$.\n\tSo $V$ is not irreducible, but it is indecomposable.\n\\end{exercise}\n\nHere is a slightly more optimistic example,\nand the ``prototypical example'' that you should keep in mind.\n\n\\begin{exercise}\n\tLet $A = \\Mat_d(k)$ and consider the obvious representation $k^{\\oplus d}$\n\tof $A$ that we described earlier. Show that it is irreducible.\n\t(This is obvious if you understand the definitions well enough.)\n\\end{exercise}\n\n\\section{Morphisms of representations}\nWe now proceed to define the morphisms between representations.\n\n\\begin{definition}\n\tLet $(V, \\rho_V)$ and $(W, \\rho_W)$ be representations of $A$.\n\tAn \\vocab{intertwining operator}, or \\vocab{morphism}, is a\n\tlinear map $T : V \\to W$ such that\n\t\\[ T(a \\cdot v) = a \\cdot T(v) \\]\n\tfor any $a \\in A$, $v \\in V$.\n\t(Note that the first $\\cdot$ is the action of $\\rho_V$\n\tand the second $\\cdot$ is the action of $\\rho_W$.)\n\tThis is exactly what you expect if you think that $V$ and $W$\n\tare ``left $A$-modules''.\n\tIf $T$ is invertible, then it is an \\vocab{isomorphism} of representations\n\tand we say $V \\cong W$.\n\\end{definition}\n\\begin{remark}\n\t[For commutative diagram lovers]\n\tThe condition $T(a \\cdot v) = a \\cdot T(v)$ can be read as saying that\n\t\\begin{diagram}\n\t\tV & \\rTo^{\\rho_1(a)} & V \\\\\n\t\t\\dTo^T & & \\dTo_T \\\\\n\t\tW & \\rTo_{\\rho_2(a)} & W\n\t\\end{diagram}\n\tcommutes for any $a \\in A$.\n\\end{remark}\n\n\\begin{remark}\n\t[For category lovers]\n\tA representation is just a ``bilinear'' functor from an\n\tabelian one-object category $\\{\\ast\\}$ (so $\\Hom(\\ast, \\ast) \\cong A$)\n\tto the abelian category $\\catname{Vect}_k$.\n\tThen an intertwining operator is just a \\emph{natural transformation}.\n\\end{remark}\n\nHere are some examples of intertwining operators.\n\\begin{example}[Intertwining operators]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii For any $\\lambda \\in k$, the scalar map $T(v) = \\lambda v$\n\t\tis intertwining.\n\t\t\\ii If $W \\subseteq V$ is a subrepresentation,\n\t\tthen the inclusion $W \\injto V$ is an intertwining operator.\n\t\t\\ii The projection map $V_1 \\oplus V_2 \\surjto V_1$\n\t\tis an intertwining operator.\n\t\t\\ii Let $V  = \\RR^{\\oplus 2}$ \n\t\tand represent $A = k[x]$ by $(V, \\rho)$ where\n\t\t\\[ \\rho(x) = \\begin{bmatrix} 0 & 1 \\\\ -1 & 0 \\end{bmatrix}. \\]\n\t\tThus $\\rho(x)$ is rotation by $90\\dg$ around the origin.\n\t\tLet $T$ be rotation by $30\\dg$.\n\t\tThen $T : V \\to V$ is intertwining (the rotations commute).\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{exercise}[Kernel and image are subrepresentations]\n\tLet $T : V \\to W$ be an intertwining operator.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Show that $\\ker T \\subseteq V$ is a subrepresentation of $V$.\n\t\t\\ii Show that $\\img T \\subseteq W$ is a subrepresentation of $W$.\n\t\\end{enumerate}\n\\end{exercise}\n\nThe previous lemma gives us the famous Schur's lemma.\n\\begin{theorem}\n\t[Schur's lemma]\n\tLet $V$ and $W$ be representations of a $k$-algebra $A$.\n\tLet $T : V \\to W$ be a \\emph{nonzero} intertwining operator.\n\tThen\n\t\\begin{enumerate}[(a)]\n\t\t\\ii If $V$ is irreducible, then $T$ is injective.\n\t\t\\ii If $W$ is irreducible, then $T$ is surjective.\n\t\\end{enumerate}\n\tIn particular if both $V$ and $W$ are irreducible then $T$\n\tis an isomorphism.\n\\end{theorem}\nAn important special case is if $k$ is algebraically closed:\nthen the only intertwining operators $T \\colon V \\to V$\nare multiplication by a constant.\n\\begin{theorem}\n\t[Schur's lemma for algebraically closed fields]\n\tLet $k$ be an algebraically closed field.\n\tLet $V$ be an irrep of a $k$-algebra $A$.\n\tThen any intertwining operator $T \\colon V \\to V$ is multiplication by a scalar.\n\t\\label{thm:schur_algclosed}\n\\end{theorem}\n\\begin{exercise}\n\tUse the fact that $T$ has an eigenvalue $\\lambda$ to\n\tdeduce this from Schur's lemma.\n\t(Consider $T - \\lambda \\cdot \\id_V$, and use Schur to deduce it's zero.)\n\\end{exercise}\nWe have already seen the counterexample of rotation by $90\\dg$ for $k = \\RR$;\nthis was the same counterexample we gave to the assertion that all linear maps\nhave eigenvalues.\n\n\\section{The representations of $\\Mat_d(k)$}\nTo give an example of the kind of progress already possible, we prove:\n\\begin{theorem}\n\t[Representations of $\\Mat_d(k)$]\n\t\\label{thm:rep_1mat}\n\tLet $k$ be any field, $d$ be a positive integer and\n\tlet $W = k^{\\oplus d}$ be the obvious representation of $A = \\Mat_d(k)$.\n\tThen the only finite-dimensional representations\n\tof $\\Mat_d(k)$ are $W^{\\oplus n}$\n\tfor some positive integer $n$ (up to isomorphism).\n\tIn particular, it is irreducible if and only if $n=1$.\n\\end{theorem}\nFor concreteness, I'll just sketch the case $d=2$,\nsince the same proof applies verbatim to other situations.\nThis shows that the examples of representations of $\\Mat_2(\\RR)$\nwe gave earlier are the only ones.\n\nAs we've said this is essentially a functional equation.\nThe algebra $A = \\Mat_2(k)$ has basis given by four matrices\n\\[\n\tE_1 = \\begin{bmatrix} 1 & 0 \\\\ 0 & 0 \\end{bmatrix},\n\t\\qquad\n\tE_2 = \\begin{bmatrix} 0 & 0 \\\\ 0 & 1 \\end{bmatrix},\n\t\\qquad\n\tE_3 = \\begin{bmatrix} 0 & 1 \\\\ 0 & 0 \\end{bmatrix},\n\t\\qquad\n\tE_4 = \\begin{bmatrix} 0 & 0 \\\\ 1 & 0 \\end{bmatrix}\n\\]\nsatisfying relations like $E_1 + E_2 = \\id_A$, $E_i^2 = E_i$, $E_1E_2 = 0$, etc.\nSo let $V$ be a representation of $A$, and let $M_i = \\rho(E_i)$ for each $i$;\nwe want to classify the possible matrices $M_i$ on $V$\nsatisfying the same functional equations.\nThis is because, for example,\n\\[ \\id_V = \\rho(\\id_A) = \\rho(E_1+E_2) = M_1 + M_2. \\]\nBy the same token $M_1M_3 = M_3$.\nProceeding in a similar way, we can obtain the following multiplication table:\n\\[\n\t\\begin{array}{r|llll}\n\t\t\\times & M_1 & M_2 & M_3 & M_4 \\\\ \\hline\n\t\tM_1 & M_1 & 0 & M_3 & 0 \\\\\n\t\tM_2 & 0 & M_2 & 0 & M_4 \\\\\n\t\tM_3 & 0 & M_3 & 0 & M_1 \\\\\n\t\tM_4 & M_4 & 0 & M_2 & 0\n\t\\end{array}\n\t\\qquad \\text{and} \\qquad\n\tM_1 + M_2 = \\id_V\n\\]\nNote that each $M_i$ is a linear operator $V \\to V$;\nfor all we know, it could have hundreds of entries.\nNonetheless, given the multiplication table of the basis $E_i$\nwe get the corresponding table for the $M_i$.\n\nSo, in short, the problem is as follows:\n\\begin{moral}\n\tFind all vector spaces $V$ and quadruples of matrices $M_i$\n\tsatisfying the multiplication table above.\n\\end{moral}\n\nLet $W_1 = M_1\\im(V)$ and $W_2 = M_2\\im(V)$ be the images of $M_1$ and $M_2$.\n\\begin{claim}\n\t$V = W_1 \\oplus W_2$.\n\\end{claim}\n\\begin{proof}\n\tFirst, note that for any $v \\in V$ we have\n\t\\[ v = \\rho(\\id)(v) = (M_1+M_2)v = M_1v + M_2v. \\]\n\tMoreover, we have that $W_1 \\cap W_2 = \\{0\\}$, because if\n\t$M_1v_1 = M_2v_2$ then $M_1v_1 = M_1(M_1v_1) = M_1(M_2v_2) = 0$.\n\\end{proof}\n\\begin{claim}\n\t$W_1 \\cong W_2$.\n\\end{claim}\n\\begin{proof}\n\tCheck that the maps \n\t\\[ W_1 \\taking{\\times M_4} W_2\n\t\t\\quad\\text{and}\\quad\n\t\tW_2 \\taking{\\times M_3} W_1 \\]\n\tare well-defined and mutually inverse.\n\\end{proof}\nNow, let $e_1, \\dots, e_n$ be basis elements of $W_1$;\nthus $M_4e_1$, \\dots, $M_4e_n$ are basis elements of $W_2$.\nHowever, each $\\{e_j, M_4e_j\\}$ forms a basis of a subrepresentation\nisomorphic to $W = k^{\\oplus 2}$ (what's the isomorphism?).\n\nThis finally implies that all representations of $A$\nare of the form $W^{\\oplus n}$.\nIn particular, $W$ is irreducible because there are no representations\nof smaller dimension at all!\n\n\\section\\problemhead\n\\begin{dproblem}\n\t\\label{prob:one_dim}\n\tSuppose we have \\emph{one-dimensional} representations\n\t$V_1 = (V_1, \\rho_1)$ and $V_2 = (V_2, \\rho_2)$ of $A$.\n\tShow that $V_1 \\cong V_2$ if and only if\n\t$\\rho_1(a)$ and $\\rho_2(a)$ are multiplication\n\tby the same constant for every $a \\in A$.\n\\end{dproblem}\n\n\\begin{dproblem}\n\t[Schur's lemma for commutative algebras]\n\tLet $A$ be a \\emph{commutative} algebra\n\tover an algebraically closed field $k$.\n\tProve that any irrep of $A$ is one-dimensional.\n\t\\begin{hint}\n\t\tFor any $a \\in A$, the map $v \\mapsto a \\cdot v$ is intertwining.\n\t\\end{hint}\n\\end{dproblem}\n\n\\begin{sproblem}\n\t\\label{prob:reg_mat}\n\tLet $(V, \\rho)$ be a representation of $A$.\n\tThen $\\Mat(V)$ is a representation of $A$\n\twith action given by \n\t\\[ a \\cdot T = \\rho(a) \\circ T \\]\n\tfor $T \\in \\Mat(V)$.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Show that $\\rho : \\Reg(A) \\to \\Mat(V)$ is an intertwining operator.\n\t\t\\ii If $V$ is $d$-dimensional, show that $\\Mat(V) \\cong V^{\\oplus d}$\n\t\tas representations of $A$.\n\t\\end{enumerate}\n\t\\begin{hint}\n\t\tFor part (b), pick a basis and do $T \\mapsto (T(e_1), \\dots, T(e_n))$.\n\t\\end{hint}\n\\end{sproblem}\n\n\\begin{sproblem}\n\t\\label{prob:regA_intertwine}\n\tFix an algebra $A$.\n\tFind all intertwining operators \n\t\\[ T : \\Reg(A) \\to \\Reg(A). \\]\n\t\\begin{hint}\n\t\tRight multiplication.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tThe operators are those of the form $T(a) = ab$\n\t\tfor some fixed $b \\in A$.\n\t\tOne can check these work, since for $c \\in A$\n\t\twe have $T(c \\cdot a) = cab = c \\cdot T(a)$.\n\t\tTo see they are the only ones, note that\n\t\t$T(a) = T(a \\cdot 1_A) = a \\cdot T(1_A)$ for any $a \\in A$.\n\t\\end{sol}\n\\end{sproblem}\n\n\\begin{problem}\n\t\\gim\n\tLet $(V, \\rho)$ be an \\emph{indecomposable}\n\t(not irreducible) representation of an algebra $A$.\n\tProve that any intertwining operator $T : V \\to V$\n\tis either nilpotent or an isomorphism.\n\n\t(Note that \\Cref{thm:schur_algclosed} doesn't apply,\n\tsince the field $k$ may not be algebraically closed.)\n\t\\begin{hint}\n\t\tApply \\Cref{prob:endomorphism_eventual_lemma}.\n\t\\end{hint}\n\\end{problem}\n", "meta": {"hexsha": "d1ae0e63543aeb6da093f2bd1252fe2ddd66644a", "size": 23689, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/rep-theory/rep-alg.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/rep-theory/rep-alg.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/rep-theory/rep-alg.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.9563182527, "max_line_length": 94, "alphanum_fraction": 0.6695090548, "num_tokens": 8260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.8856314647623016, "lm_q1q2_score": 0.7177856311529976}}
{"text": "\\documentclass{tufte-handout}\n\n\\usepackage{xcolor}\n\\usepackage{graphicx}\n\n% set hyperlink attributes\n\\hypersetup{colorlinks}\n\n\\usepackage{amsmath}\n\n% set image attributes:\n\\usepackage{graphicx}\n\\graphicspath{ {images/} }\n\n% create environment for bottom paragraph:\n\\newenvironment{bottompar}{\\par\\vspace*{\\fill}}{\\clearpage}\n\n% ============================================================\n\n% define the title\n\\title{SOC 4930/5050: Week 05 Equations Quick \\\\Reference}\n\\author{Christopher Prener, Ph.D.}\n\\date{September 25\\textsuperscript{th}, 2017}\n% ============================================================\n\\begin{document}\n% ============================================================\n\\maketitle % generates the title\n% ============================================================\n\n\\vspace{5mm}\n\\section{Binomial Distribution}\nFor the binomial distribution, let: \\\\\n\\noindent $n =$ number of independent trials \\\\\n\\noindent $p =$ probability of success in each trial\n\n\\paragraph{Mean}\\mbox{}\\\\\n\\begin{equation}\n\\scalebox{2} {$ \\mu = np $}\n\\end{equation}\n\n\\paragraph{Standard Deviation}\\mbox{}\\\\\n\\begin{equation}\n\\scalebox{2} {$ \\sigma =\\sqrt { np\\left( 1-p \\right)  } $}\n\\end{equation}\n\n\\vspace{5mm}\n\\section{Poisson Distribution}\nFor the Poisson distribution, let: \\\\\n\\noindent $n =$ count of independent events \\\\\n\\noindent $p =$ probability of success in each event \\\\\n\\begin{equation}\n\\scalebox{2} {$ \\lambda = np $}\n\\end{equation}\n\n\\vspace{5mm}\n\\section{Standard Normal Distribution}\n\\paragraph{Standardized Scores: Population}\\mbox{}\\\\\n\\begin{equation}\n\\scalebox{2} {$ z = \\frac{x-\\mu}{\\sigma} $}\n\\end{equation}\n\n\\paragraph{Standardized Scores: Sample}\\mbox{}\\\\\n\\begin{equation}\n\\scalebox{2} {$ z = \\frac{x-\\bar{x}}{s} $}\n\\end{equation}\n\n\\vspace{5mm}\n\\section{Skew}\\marginnote{Note that $sk$ is an abbreviation that I use in my classes to differentiate skew from standard deviation. There is no single accepted abbreviation for skew. Similarly, there are a number of equations in use to calculate skew; this is one that I teach because it simplifies some of the required calculations.}\n\\begin{equation}\n\\scalebox{2} {$ sk = \\sqrt{n}\\frac { \\sum _{ i=1 }^{ n }{ \\left( {x}_{i}-\\bar{x} \\right)^3 }  }{ \\left( \\sum _{ i=1 }^{ n }{ \\left( { x }_{ i }-\\bar{x} \\right)^2 }  \\right)^\\frac{3}{2}  } $}\n\\end{equation}\n\n\\vspace{5mm}\n\\section{Kurtosis}\\marginnote{Note that there are a number of accepted abbreviations for kurtosis including $k$. There are also a number of equations in use to calculate kurtosis. As with skew, this is one that I teach because it simplifies some of the required calculations.}\n\\begin{equation}\n\\scalebox{2} {$ k = n\\frac { \\sum _{ i=1 }^{ n }{ \\left( {x}_{i}-\\bar{x} \\right)^4 }  }{ \\left( \\sum _{ i=1 }^{ n }{ \\left( { x }_{ i }-\\bar{x} \\right)^2 }  \\right)^2  } $}\n\\end{equation}\n% ============================================================\n\\end{document}", "meta": {"hexsha": "51da0babbbaa42f8262cc83a8fe0ea0fee81201e", "size": 2895, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week-05-equations.tex", "max_stars_repo_name": "slu-soc5050/Equations", "max_stars_repo_head_hexsha": "6398ba3a3d351d95a37d3245fcc6eabb91fdd032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week-05-equations.tex", "max_issues_repo_name": "slu-soc5050/Equations", "max_issues_repo_head_hexsha": "6398ba3a3d351d95a37d3245fcc6eabb91fdd032", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week-05-equations.tex", "max_forks_repo_name": "slu-soc5050/Equations", "max_forks_repo_head_hexsha": "6398ba3a3d351d95a37d3245fcc6eabb91fdd032", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6455696203, "max_line_length": 334, "alphanum_fraction": 0.6227979275, "num_tokens": 843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436728, "lm_q2_score": 0.8104788995148792, "lm_q1q2_score": 0.7177856124897657}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage[headings]{fullpage}\n\\usepackage[utopia]{mathdesign}\n\n\\pagestyle{myheadings}\n\\markboth{}{Conditioning}\n\n\\input{../../fncextra}\n\n\\begin{document}\n\n\\begin{center}\n  \\bf Rooting for accuracy\n\\end{center}\n\nSuppose we have a quadratic polynomial $p(x;s) = a(s)x^2+b(s)x+c(s)$ whose coefficients depend on a parameter $s$. In this lab, we define\n\\begin{equation}\n  \\label{eq:poly}\n  p(x;s) = 9x^2 - (6+s)x + 1.\n\\end{equation}\nFor each value of $s$ there are two roots $t_1(s)$ and $t_2(s)$. Since $a$, $b$, and $c$ vary continuously as a function of $s$, $t_1(s)$ and $t_2(s)$ are also continuous.\n\nThe effect of roundoff in floating point calculations is to perturb the coefficients of $p$ by a relative amount $\\macheps$. As a result, the roots may change by a relative amount $\\kappa \\macheps$, where $\\kappa$ is the condition number of the roots. In the text it's shown in a special case that for the root $t_k$, the condition number is given by\n\\begin{equation}\n  \\label{eq:kappa}\n  \\kappa = |t_k|/|t_1-t_2|.\n\\end{equation}\nIf $t_1\\approx t_2$, the errors in the computed roots are potentially large (compared to machine precision). In our case $p(x;0)=(3x-1)^2$, which makes $\\kappa$ formally infinite, so $s=0$ is critical to the conditioning of the roots.\n\n\n%Even when a computed $\\tilde{t}_k$ is not close to $t_k$, however, it may still be the case that the \\textbf{residual} $p(\\tilde{t}_k;s)$ is close to zero. In practical computations we usually don't know the error, but we can always compute the residual.\n\n\\subsection*{Goals}\n\nYou will examine the sensitivity of the roots of a quadratic polynomial whose roots come together, coalesce, and separate again.\n\n\\subsection*{Preparation}\n\nRead section~1.2 and the online help for the \\texttt{roots} and \\texttt{polyval} commands.\n\nIn MATLAB, perform the following.\n\\begin{verbatim}\nt1 = @(s) (6+s+sqrt((6+s).^2-36))/18;\nt2 = @(s) (6+s-sqrt((6+s).^2-36))/18;\ns = linspace(-1,1,800)';\nplot(t1(s),'r.')\nhold on\nplot(t2(s),'b.')\nxlabel('real part'),  ylabel('imaginary part')\ntitle('Roots for -1 < s < 1') \n\\end{verbatim}\nUse the resulting picture to describe in words what happens to the roots as the parameter $s$ passes from negative to positive values. \n\n\n\\subsection*{Procedure}\n\nDownload the template script and complete it in sections as guided below.\n\n\\begin{enumerate}\n\\item Define the functions \\texttt{t1} and \\texttt{t2} as in the Preparation section above.\n\n\\item Let $s=-0.1$. Use \\texttt{roots} to compute the two roots of $p(x;s)$ as a vector \\texttt{r}. One complication is that we don't know whether \\texttt{r(1)} is meant to be $t_1$ or $t_2$. So we compute its error by means of\n\\begin{verbatim}\nerr1 = min( abs(r(1)-t1(s)), abs(r(1)-t2(s)) )\n\\end{verbatim}\n  Find this value. Then find $\\kappa$ from~\\eqref{eq:kappa} with $k=1$.\n\n\\item Define the vector\n\\begin{verbatim}\ns = linspace(-1,1,800)';\n\\end{verbatim}\n  In a loop over the entries of the vector \\texttt{s}, find the error and $\\kappa$, storing the results in vectors. The template has code for plotting the results. \n\n\\item Nothing in the previous step indicates much reason for concern. However, the results are strikingly different if we approach very close to $s=0$. Define \n\\begin{verbatim}\ns = logspace(-15,-1,100)';\n\\end{verbatim}\nThen repeat the loop from step~3. \n\\end{enumerate}\n\n\\subsection*{Going further}\n\nWe always compute with a fixed value of $\\varepsilon_{\\text{mach}}$, but we can simulate the effect of varying it by manually perturbing data. For example, a relative perturbation of size $\\delta$ to each entry of vector $y$ is made by\n\\begin{verbatim}\nr = 2*rand(size(y))-1;    % random in [-1,1]\nyy = y .* (1+delta*r);\n\\end{verbatim}\nFor each $\\delta=10^{-6},10^{-8},10^{-10},10^{-12},10^{-14}$, make 500 random perturbations to the coefficient vector of $p(x;0)$, each time using \\texttt{roots} to find the resulting roots and plotting them in the complex plane. (You should end up five plots, each with 1000 points.) \n\n\n\\end{document}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: t\n%%% End:\n", "meta": {"hexsha": "3ae8681fe46cdf5ef74561a87edd24b78be333e4", "size": 4096, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter01/Conditioning/Conditioning.tex", "max_stars_repo_name": "snowdj/fnc-extras", "max_stars_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 109, "max_stars_repo_stars_event_min_datetime": "2018-04-21T09:02:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T19:03:54.000Z", "max_issues_repo_path": "labs/chapter01/Conditioning/Conditioning.tex", "max_issues_repo_name": "snowdj/fnc-extras", "max_issues_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-12-04T22:17:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T21:04:47.000Z", "max_forks_repo_path": "labs/chapter01/Conditioning/Conditioning.tex", "max_forks_repo_name": "snowdj/fnc-extras", "max_forks_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 49, "max_forks_repo_forks_event_min_datetime": "2017-04-02T17:21:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T17:19:57.000Z", "avg_line_length": 41.7959183673, "max_line_length": 350, "alphanum_fraction": 0.7126464844, "num_tokens": 1223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8991213853793452, "lm_q1q2_score": 0.7176668013927237}}
{"text": "\\section{Application: Balancing chemical reactions}\n\nThe tools of linear algebra can also be used in the subject area of\nChemistry, specifically for balancing chemical reactions.  Consider\nthe chemical reaction%\n\\index{chemical reactions!balancing}\n\\begin{equation*}\n  SnO_2+H_2\\rightarrow Sn+H_2O.\n\\end{equation*}\nHere the elements involved are tin ($Sn$), oxygen ($O$), and hydrogen\n($H$). A chemical reaction occurs that transforms a combination of tin\ndioxide ($SnO_2$) and hydrogen ($H_2$) into a combination of tin\n($Sn$) and water ($H_2O$). When considering chemical reactions, we\nwant to investigate how much of each substance we began with and how\nmuch of each substance is involved in the result.\n\nAn important theory we will use here is the mass balance theory. It\ntells us that we cannot create or delete elements within a chemical\nreaction. For example, in the above expression, we must have the same\nnumber of atoms of oxygen, tin, and hydrogen on both sides of the\nreaction. Notice that this is not currently the case.  For example,\nthere are two oxygen atoms on the left and only one on the right. In\norder to fix this, we want to find numbers $x,y,z,w$ such that\n\\begin{equation*}\n  x\\;SnO_2+y\\;H_2\\rightarrow z\\;Sn+w\\;H_2O,\n\\end{equation*}\nwhere both sides of the reaction have the same number of atoms of the\nvarious elements.\n\nThis is a familiar problem. We can solve it by setting up a system of\nequations in the variables $x,y,z,w$. Thus we need\n\\begin{equation*}\n  \\begin{array}{cl}\n    Sn: & x=z \\\\\n    O: & 2x=w \\\\\n    H: & 2y=2w.\n  \\end{array}\n\\end{equation*}\nWe can rewrite these equations as\n\\begin{equation*}\n  \\begin{array}{cl}\n    Sn: & x - z = 0 \\\\\n    O: & 2x - w = 0 \\\\\n    H: & 2y - 2w = 0.\n  \\end{array}\n\\end{equation*}\nThe augmented matrix for this system of equations is given by\n\\begin{equation*}\n  \\begin{mymatrix}{rrrr|r}\n    1 & 0 & -1 & 0 & 0 \\\\\n    2 & 0 & 0 & -1 & 0 \\\\\n    0 & 2 & 0 & -2 & 0\n  \\end{mymatrix}.\n\\end{equation*}\nThe {\\rref} of this matrix is\n\\begin{equation*}\n  \\def\\arraystretch{1.2}\n  \\begin{mymatrix}{rrrr|r}\n    1 & 0 & 0 & -\\frac{1}{2} & 0 \\\\\n    0 & 1 & 0 & -1 & 0 \\\\\n    0 & 0 & 1 & -\\frac{1}{2} & 0\n  \\end{mymatrix},\n\\end{equation*}\nand the solution is given in parametric form as\n\\begin{equation*}\n  \\begin{array}{r@{~}c@{~}ll}\n    x &=& \\frac{1}{2} t \\\\\n    y &=& t \\\\\n    z &=& \\frac{1}{2}t \\\\\n    w &=& t.\n  \\end{array}\n\\end{equation*}\nFor example, let $t=2$ and this would yield $x=1$, $y=2$, $z=1$, and\n$w=2$. We can put these values back into the expression for the\nreaction which yields\n\\begin{equation*}\n  SnO_2+2H_2\\rightarrow Sn+2H_2O.\n\\end{equation*}\nObserve that each side of the expression contains the same number of\natoms of each element. This means that the chemical reaction is\nbalanced. Of course, because it is a homogeneous system of equations,\nany multiple of a solution is also a solution. For example,\n\\begin{equation*}\n  2SnO_2+4H_2\\rightarrow 2Sn+4H_2O\n\\end{equation*}\nis also correct. It just means that we have just doubled the amount of\nevery substance involved. In chemistry, the numbers you are finding\nwould typically be the number of mols of the molecules on each\nside. Thus one mol of $SnO_2$ added two mols of $H_2$ yields one mol\nof $Sn$ and two mols of $H_2O$.\n\nHere is another example.\n\n\\begin{example}{Balancing a chemical reaction}{balancing-chem}\n  Potassium is denoted by $K$, oxygen by $O$, phosphorus by $P$ and\n  hydrogen by $H$.  Consider the reaction given by\n  \\begin{equation*}\n    KOH+H_3PO_4\\rightarrow K_3PO_4+H_2O.\n  \\end{equation*}\n  Balance this chemical reaction.\n\\end{example}\n\n\\begin{solution}\n  We will use the same procedure as above to solve this problem. We\n  need to find values for $x,y,z,w$ such that\n  \\begin{equation*}\n    x\\;KOH+y\\;H_3PO_4\\rightarrow z\\;K_3PO_4+w\\;H_2O.\n  \\end{equation*}\n  preserves the total number of atoms of each element.  Finding these\n  values can be done by finding the solution to the following system\n  of equations.\n  \\begin{equation*}\n    \\begin{array}{cl}\n      K: & x=3z \\\\\n      O: & x+4y=4z+w \\\\\n      H: & x+3y=2w \\\\\n      P: & y=z.\n    \\end{array}\n  \\end{equation*}\n  The augmented matrix for this system is\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrr|r}\n      1 & 0 & -3 & 0 & 0 \\\\\n      1 & 4 & -4 & -1 & 0 \\\\\n      1 & 3 & 0 & -2 & 0 \\\\\n      0 & 1 & -1 & 0 & 0\n    \\end{mymatrix},\n  \\end{equation*}\n  and the {\\rref} is\n  \\begin{equation*}\n    \\def\\arraystretch{1.2}\n    \\begin{mymatrix}{rrrr|r}\n      1 & 0 & 0 & -1 & 0 \\\\\n      0 & 1 & 0 & -\\frac{1}{3} & 0 \\\\\n      0 & 0 & 1 & -\\frac{1}{3} & 0 \\\\\n      0 & 0 & 0 & 0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n\n  The general solution is given in terms of the parameter $t$ as\n  \\begin{equation*}\n    \\begin{array}{c}\n      x = t \\\\\n      y = \\frac{1}{3}t \\\\\n      z = \\frac{1}{3}t \\\\\n      w = t\n    \\end{array}\n  \\end{equation*}\n  Choose a value for $t$, say $3$. This yields $x=3$, $y=1$, $z=1$,\n  and $w=3$. It follows that the balanced reaction is given by\n  \\begin{equation*}\n    3KOH+H_3PO_4\\rightarrow K_3PO_4+3H_2O\n  \\end{equation*}\n  Note that this results in the same number of atoms of each element\n  on both sides.\n\\end{solution}\n\n", "meta": {"hexsha": "89ec883f310eab493be9bed7ac69375e4962c151", "size": 5172, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/SystemsofEquations-Application-BalancingChemical.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/SystemsofEquations-Application-BalancingChemical.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/SystemsofEquations-Application-BalancingChemical.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 32.7341772152, "max_line_length": 70, "alphanum_fraction": 0.657579273, "num_tokens": 1808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8991213678089741, "lm_q1q2_score": 0.7176667873682858}}
{"text": "Deep Neural Networks (DNNs) consists of connected layers of different types. These types of layers will be discussed in this section\n\n\\subsection{Fully Connected layer}\n\nA Fully Connected (FC) layer is a layer where every neuron from the previous layer is connected to every neuron in the next layer (See Figure 1). It is the basic layer in most of Deep Learning Systems, however due to the number of operations it has a big complexity (matrix multiplication is around $O(n^3)$  in big O notation). The face images used in this study were images of size $224 \\times 224$ with 3 RGB channels. If in the first hidden layer we would have 1000 nodes it would be $224 \\times 224 \\times 1000 = 50176000$ parameters to optimize (it is only the first layer). For this reason, we must somehow reduce the number of parameters, for example by using convolution layers. \n\n\\subsection{Convolution layer}\n\nConvolution Layer is an idea based on edge detection. Edge detection was one of early techniques used to solve computer vision problems, as the name suggest it allows us to detect edges in a given image (See Figure 3). The Edge detection  algorithm  is  performed using a matrix called a mask and an operation called convolution. It takes matrix of size m (size of a mask) from input image, multiply it element-wise by values in mask, sums all values and as a result returns edges detected in input image (See Figure 2). The general expression of a convolution is: \n\\begin{equation}\ng(x, y)=(\\omega * f)(x, y)=\\sum_{s=-a}^{a} \\sum_{t=-b}^{b} \\omega(s, t) f(x-s, y-t)\n\\end{equation}\n\nWhere $g(x,y)$ is the filtered image, $f(x,y)$ is the original image, $\\omega$ is the filter kernel. Every element of the filter kernel is considered by $-a \\leqslant s \\leqslant a$ and $-b \\leqslant t \\leqslant b$ \\footnote{Equation from Wikipedia \\url{https://en.wikipedia.org/wiki/Kernel_(image_processing)}}\n\\newline\n\nUsing hand-engineered filters values we can detect horizontal or vertical edges (See Figure 4) but what if we want to detect some more sophisticated features like cat edges (See Figure 5)? This is where deep learning comes in: Instead of using hand-engineered filter values we can use a Gradient Descent Algorithm to find the right values for mask matrix.\n\n\nWhat is interesting at this point is the fact that regardless of the image size, we have same number of parameters to train. No matter if our image is $20 \\times 20$ pixels or $1000 \\times 1000$ we need to train the same number of parameters - the number of values in filter mask. It is one of main reasons why CNNs are so popular in real life computer vision problems.\n\nThe role of convolution layer is to extract crucial information (edges) from image by using custom filter masks. The side benefit of detecting edges can be reduction of image size (it is not always the case, it depends on used padding see Sec. 3.5 Padding). Outcome of Convolution Layer (the one consisting crucial information about edges) can be then propagated to Fully Connected Layers to perform classification.\n\n\n   \\begin{figure}[!ht]\n  \\centering\n  \\framebox{\\parbox{5.5in}{$\n    \\begin{bmatrix}\n        0 & 0 & 0 & 10 & 10 & 10\\\\\n        0 & 0 & 0 & 10 & 10 & 10\\\\\n        0 & 0 & 0 & 10 & 10 & 10\\\\\n        0 & 0 & 0 & 10 & 10 & 10\\\\\n        0 & 0 & 0 & 10 & 10 & 10\\\\\n        0 & 0 & 0 & 10 & 10 & 10\\\\\n    \\end{bmatrix}_{img} * \\begin{bmatrix}\n        -1 & 0 & 1\\\\\n        -1 & 0 & 1\\\\\n        -1 & 0 & 1\\\\\n    \\end{bmatrix}_{mask} =\n    \\begin{bmatrix}\n        0 & 30 & 30 & 0\\\\\n        0 & 30 & 30 & 0\\\\\n        0 & 30 & 30 & 0\\\\\n    \\end{bmatrix}_{detected \\: edge}\n    $\n    }}\n  %\\includegraphics[scale=1.0]{figurefile}\n  \\caption{Example convolution operation}\n  \\label{figurelabel}\n\\end{figure}    \n\n\n\n\\begin{figure}[!ht]\n  \\centering\n  \\includegraphics[scale=0.35]{Images/bikes-gray-sobel.jpg}\n  \\caption{Detected edges after applying Sobel filter\\protect\\footnotemark}\n  \\label{figurelabel}\n\\end{figure}\n\n\\footnotetext{Cat edges from \\url{http://mcogswell.io/blog/why_cat_2/}}\n\n\n\\begin{figure}[!ht]\n  \\centering{\n  \\framebox{\\parbox{4in}{\n  $\\begin{bmatrix}\n-1 & 0 & 1\\\\\n-2 & 0 & 2\\\\\n-1 & 0 & 1\\\\\n\\end{bmatrix}_{0} $       $\\begin{bmatrix} \n0 & 1 & 2\\\\\n-1 & 0 & 1\\\\\n-2 & -1 & 0\\\\\n\\end{bmatrix}_{45} $  $\\begin{bmatrix}\n1 & 2 & 1\\\\\n0 & 0 & 0\\\\\n-1 & -2 & 1\\\\\n\\end{bmatrix}_{90} $ \n}}}\n  \n  \\caption{Example edge detection Sobel filter for angles: \\ang{0}, \\ang{45} and \\ang{90}}\n  \\label{figurelabel}\n\\end{figure}  \n\n\n\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.5\\textwidth]{Images/cat-features.png}\n\\caption{Cat edges recognized by individual CNN layers\\protect\\footnotemark}\n\\end{figure}\n\n\n\\footnotetext{Example detected egdes image from \\url{https://en.wikipedia.org/wiki/Sobel_operator}}\n\n\n\\subsection{Convolution operation on volume}\n\nBlack and white images contain only single color channel, but in color images there are more. E.g. color RGB Image contains 3 channels (Red, Green, Blue). In that case each filter need to have 3 \"sub filters\", one for each channel. We apply convolution operation to each channel and then sum up the result (See Figure 6).  \n\\newline\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{Images/convolution-operation-on-volume.png}\n\\caption{Convolution on volume example [11]}\n\\end{figure}\n\n\\subsection{Multiple filters}\n\nTo detect multiple types of features in previous layer we should use multiple filters. E.g. one filter will detect vertical edges and one will detect horizontal (See Figure 7).\n\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{Images/convolution-with-multiple-filters.png}\n\\caption{Convolution with multiple filters example[11]}\n\\end{figure}\n\n\n\\subsection{Padding}\n\nTo avoid underrepresentation of edge pixels it is worth to add one layer of extra pixels around original image (See Figure 8).\n\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.5\\textwidth]{Images/padding.png}\n\\caption{Example of 1 pixel padding [11]}\n\\end{figure}\n\n\\subsection{Stride}\n\nStride determines the number of cells that the filter moves in the input to calculate cell in output (See Figure 9).\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.5\\textwidth]{Images/stride.png}\n\\caption{Example output for stride equal 2[11]}\n\\end{figure}\n\n\\subsection{Pooling layer}\n\nAnother type of layer used in CNNs is Pooling Layer. There are two types of Pooling Layers: Avg. Pooling and Max Pooling.  Pooling layers significantly reduce size of an image. The intuition behind pooling is \\textit{take most important information} for Max Pooling and \\textit{take average of all information} for Avg Pooling. (See Figure 10).\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.5\\textwidth]{Images/pooling-layer.png}\n\\caption{Outputs after pooling operations [11]}\n\\end{figure}\n\n\n", "meta": {"hexsha": "9c61c5f6c3e1c577d06f2a6b2a318eaab0b6dd8e", "size": 6795, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "deep-neural-network-architecture.tex", "max_stars_repo_name": "tugot17/ML-In-Cybersecurity-Paper-", "max_stars_repo_head_hexsha": "9102121ee32410fdefb415e601e9ab8c027b149a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-31T17:04:19.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-31T17:04:19.000Z", "max_issues_repo_path": "deep-neural-network-architecture.tex", "max_issues_repo_name": "tugot17/ML-In-Cybersecurity-Paper-", "max_issues_repo_head_hexsha": "9102121ee32410fdefb415e601e9ab8c027b149a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "deep-neural-network-architecture.tex", "max_forks_repo_name": "tugot17/ML-In-Cybersecurity-Paper-", "max_forks_repo_head_hexsha": "9102121ee32410fdefb415e601e9ab8c027b149a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.1233766234, "max_line_length": 688, "alphanum_fraction": 0.7253863135, "num_tokens": 1918, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.7956581000631541, "lm_q1q2_score": 0.7176204981879641}}
{"text": "\\section{Reasoning}\n\n\\subsection{Beweismethoden}\n\\begin{tabular}{ll}\n    Direkter Beweis & $ p \\rightarrow q $ \\\\\n    Beweis durch Kontraposition & $ \\neg q \\rightarrow \\neg p $ \\\\\n    Beweis durch Widerspruch & $ \\neg p \\rightarrow q $ \\\\\n\\end{tabular}\n\n\\subsection{Induktionsbeweis}\n\\begin{tabular}{ll}\n    Induktionshypothese & $P(k)$ \\\\\n    Induktionsverankerung & $P(1)$ \\\\\n    Induktionsschritt & $P(k) \\to P(k+1)$ \\\\\n\\end{tabular} \\\\\n\n$[P(1) \\land \\forall k (P(k) \\to P(k+1))] \\to \\forall n P(n)$\n\n\\subsection{Schlussregeln / Inferenzregeln}\n\\begin{tabular}{ll}\n    Modus ponens & $((p \\to q) \\land p) \\to q$ \\\\\n    Modus tollens & $((\\neg q \\land (p \\to q))) \\to \\neg p$ \\\\\n    Hypothetischer & \\multirow{2}{*}{$((p \\to q) \\land (q \\to r)) \\to (p \\to r)$} \\\\ \n    Syllogismus & \\\\\n    Disjunktiver & \\multirow{2}{*}{$((p \\lor q) \\land \\neg p) \\to q$} \\\\\n    Syllogismus & \\\\\n    Addition & $p \\to (p \\lor q)$ \\\\\n    Simplifikation & $(p \\land q) \\to p$ \\\\\n    Konjunktion & $((p) \\land (q)) \\to p \\land q$ \\\\\n    Resolution & $((p \\land q) \\land (\\neg p \\lor r)) \\to (q \\lor r)$ \\\\\n\\end{tabular} \\\\\n\n", "meta": {"hexsha": "845f81ebf32f795991acdd481238d8209dd68d73", "size": 1108, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lessons/04-Reasoning.tex", "max_stars_repo_name": "florianbaer/dmath", "max_stars_repo_head_hexsha": "395f5f53623f577807ab538e64a36ccafa2fbe47", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-12-02T14:07:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-19T13:34:41.000Z", "max_issues_repo_path": "lessons/04-Reasoning.tex", "max_issues_repo_name": "florianbaer/dmath", "max_issues_repo_head_hexsha": "395f5f53623f577807ab538e64a36ccafa2fbe47", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-01-10T07:34:30.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-10T19:06:27.000Z", "max_forks_repo_path": "lessons/04-Reasoning.tex", "max_forks_repo_name": "florianbaer/dmath", "max_forks_repo_head_hexsha": "395f5f53623f577807ab538e64a36ccafa2fbe47", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-11-24T18:47:13.000Z", "max_forks_repo_forks_event_max_datetime": "2017-11-24T18:47:13.000Z", "avg_line_length": 33.5757575758, "max_line_length": 85, "alphanum_fraction": 0.5703971119, "num_tokens": 433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7176204963528855}}
{"text": "%\n% 491\n%\n\\chapter{The Jacobian Elliptic Functions}\n\n\\Section{22}{1}{Elliptic functions with two simple poles.}\n\nIn the course of pr6ving general theorems concerning elliptic\nfunctions at the beginning of Chapter xx, it was shewn that two\nclasses of elliptic functions were simpler than any others so far as\ntheir singularities were concerned, namely the elliptic functions of\norder 2. The first class consists of those with a single double pole\n(with zero residue) in each cell, the second consists of those with\ntwo simple poles in each cell, the sum of the residues at these poles\nbeing zero.\n\nAn example of the first class, namely z), was discussed at length in\nChapter xx; in the present chapter we shall discuss various examples\nof the second class, known as Jacobian elliptic functions*.\n\nIt will be seen \\hardsubsubsectionref{22}{1}{2}{2}, note) that, in certain circumstances, the\nJacobian functions degenerate into the ordinary circular functions;\naccordingly, a notation (invented by Jacobi and modified by Gudermann\nand Glaisher) will be employed which emphasizes an analogy between the\nJacobian functions and the circular functions.\n\nFrom the theoretical aspect, it is most simple to regard the Jacobian\nfunctions as quotients of Theta-functions \\hardsubsectionref{21}{6}{1}). But as many of\ntheir fundamental properties can be obtained by quite elementary\nmethods, without appealing to the theory of Theta-functions, we shall\ndiscuss the functions without making use of Chapter xxi except when it\nis desirable to do so for the sake of brevity or simplicity.\n\n\\Subsection{22}{1}{1}{The Jacobian elliptic functions, TODO, TODO, TODO.}\nIt was shewn in\n§ 21 \"61 that if\n\ny '\\$,,% ul%'y the Theta-functions being formed with parameter t, then\n\nwhere k = o (0 ! t)/ 3 (0 | r). Conversely, if the constant h (called\nthe modulus-f) be given, then, unless k- 1 or /c- O, a value of r can\nbe found\n\n* These functions were introduced by Jacobi, but many of their\nproperties were obtained independently by Abel, who used a different\nnotation. See the note on p. 512.\n\nt If 0</c<l, and is the acute angle such that sin d = k, 6 is called\nthe modular angle.\n\n%\n% 492\n%\n\n(§§ 21-7-21-712) for which V (0 t) V (0 t) = A--, so that the sokition\nof the differential equation\n\n;|y=(i-yn(i-%')\n\nsubject to the condition ( -y ) = 1 is\n\nthe Theta-functions being formed with the parameter t which has been\ndetermined.\n\nThe differential equation may be written\n\nto=i\\ l-t-)- - l-k-H')- -dt, Jo\n\nand, by the methods of \\hardsubsectionref{21}{7}{3}, it may be shewn that, if y and a are\ncon- nected by this integral formula, y may be expressed in terms of u\nas the quotient of two Theta-functions, in the form already given.\n\nThus, if\n\nJo y may be regarded as the function of u defined by the quotient of\nthe Theta- functions, so that y is an analytic function of u except at\nits singularities, which are all simple poles; to denote this\nfunctional dependence, we write\n\ny = sn(? k), or simply y= sn u, when it is unnecessary to emphasize\nthe modulus*. The function sn u is known as a Jacobian elliptic\nfunction of ii, and\n\n °\"=a;§:w5?) -\n\n[Unless the theory of the Theta-functions is assumed, it is\nexceedingly difficult to shew that the integral formula defines y as a\nfunction of u which is analytic except at simple poles. Cf. Hancock,\nElliptic Functions, i. (New York, 1910).]\n\n ow write cnOa-) =;(;y (B),\n\n''\"(\" > = a, aTWV) * >-\n\nThen, from the relation of \\hardsectionref{21}{6}, we have\n\n - sn i( = en M dn (/ (I),\n\ndu\n\n* The modulus will alwaj's be iuserted when it is not k.\n\n%\n% 493\n%\n\nand from the relations of § 21 '2, we have\n\nsn- u + cn u = 1 (II),\n\nk' sn- u + dn- u = l (Ill),\n\nand, obviously, en -= dn = 1 (I )-\n\n\"We shall now discuss the properties of the functions sn u, en u, dn u\nas defined bj' the equations (A), (B), (C) by using the four relations\n(I), (II), (III), (IV); these four relations are sufficient to make\nsn u, on u, dn u determinate functions of u. It will be assumed, when\nnecessary, that sn u, en m, dn u are one-valued functions of ti,\nanalytic except at their poles; it will also be assumed that they are\none-valued analytic functions of k' when cuts are made in the plane of\nthe complex variable k from 1 to -f oo and from to - xi .\n\n\\Subsection{22}{1}{2}{Simple properties of TODO, TODO, TODO.}\n\nFrom the integral u= j (1 - t-) (1 - k'-t-) 2 df it is evident, on\nwriting\n\nJo\n\n- t for t, that, if the sign of y be changed, the sign of u is also\nchanged.\n\nHence sn u is an odd function of u.\n\nSince sn (- ii) = - sn u, it follows from (II) that en (- u) = + en u;\non account of the one-valuedness of en u, by the theory of analytic\ncontinuation it follows that either the upper sign, or else the lower\nsign, must always be taken. In the special case u = 0, the upper sign\nhas to be taken, and so it has to be taken always; hence cn -u) = cnu,\nand cnu is cm even function of u. In like manner, dn u is an even\nfunction of u.\n\nThese results are also obvious from the definitions (A), (B) and (C)\nof §2211.\n\nNext, let us differentiate the equation sn- u + en- u = l; on using\nequation (I), we get\n\nd en a T\n\n- z - = - sn u dn u; du\n\nin like manner, from equations (III) and (I) we have\n\nd dn u, - -, - = - A;- sn u en u. du\n\n\\Subsubsection{22}{1}{2}{1}{Tlie complementary TODO modulus.}\n\nIf k- + k'- = 1 and ' -f 1 as k 0, k' is known as the complementary\nmodulus. On account of the cut in the --plane from 1 to -f x, k' is a\none- valued function of k.\n\n[With the aid of the Theta-functions, we can make k' one-valued, by\ndefining it to be\n\nExample. Shew that, if\n\nJ V then ?/ = en u, k).\n\n%\n% 494\n%\n\nAlso, shew that, if = [ \\ l - -') - J ( 2 \\ /.'2) - I dt\n\nthen 3/ = dn (, /().\n\n[These results are sometimes written in the form\n\nJ en ti J An It\n\n22122. Glaiskers notation* for quotients.\n\nA short and convenient notation has been invented by Glaisher to\nexpress\n\nreciprocals and quotients of the Jacobian elliptic functions; the\nreciprocals\n\nare denoted by reversing the order of the letters which express the\nfunction,\n\nthus\n\nns u = 1/sn u, nc u = l /en u, nd = 1 /dn u;\n\nwhile quotients are denoted by writing in order the first letters of\nthe\n\nnumerator and denominator functions, thus\n\nsc u = sn u/cn u, sd u - sn ? /dn u, cd u = en w/dn w, cs w = en w/sn\nw, ds u = dn ujsn u, dc u = dn u/cn u.\n\n[Note. Jacobi's notation for the functions sn rt, en u, dn u was sinam\nu, cosam m, Aamw, the abbreviations now in use being due to\nGudermannt, who also wrote tuu, as an abbreviation for tanam u, in\nplace of what is now written sc u.\n\nThe reason for Jacobi's notation was that he regarded the inverse of\nthe integral\n\nu= |*(l-Fsin2 )- rf\n\nas fundamental, and wrote J ( = am w; he also wrote A = (l-/?-- sin c\n)- for -j- .] Example. Obtain the following results :\n\nJ ./ cs u\n\n= r' '\\ i-k'-'fi)- ii+kH )-- dt= r f'-f )- t''+k r dt\n\nJo 7 ds H\n\n= /' t )- l-kH )- dt =[' t''-l)- t -k )- dt\n\nJ cd i( J dc u\n\n= / t- -l)- t -k )~ dt = [\"'\" t''- ) - - FH'-+k- )~ -dt\n\nr Ud M 1 1\n\n= 1 fi-i)-i i-r-f )- dt.\n\n\\Section{22}{2}{The addition-theorem for the function TODO.}\n\nWe shall now shew how to express sn (u + v) in terms of the Jacobian\nelliptic functions of u and v; the result will be the\naddition-theorem for the function sn u; it will be an\naddition-theorem in the strict sense, as it can be written in the form\nof an algebraic relation connecting sn u, sn v, sn u + v).\n\n* Messenger of Mathematics, xi. (1882), p. 86. t Journal fiir Math,\nxviii. (1838), pp. 12, 20. J Fundamenta Nova, p. 30. As k-*-Q, am )(-\n-(/.\n\n%\n% 495\n%\n\n[There are numerous methods of establishing the result; the one given\nis essentially due to Euler*, who was the first to obtain (in 1756,\n1757) the integral of\n\nin the form of an algebraic relation between x and, when X denotes a\nquartic function of X and Y is the same quartic function of y.\n\nThree t other methods are given as examples, at the end of this\nsection.]\n\nSuppose that xi and v vary while u- v remains constant and equal to a,\nsay, so that\n\ndv \\ die\n\nNow introduce, as new variables, Sj and Sg defined by the equations\n\nSi - sn %i, Sn = sn v,\n\nso thatj .V = (1 - s ) (1 -]es \\\n\nand 4- = (1 - s.f) (1 - I:? si), since xr = .\n\nDifferentiating with regard to u and dividing by 2si and 24\nrespectively, we find that, for general values § of u and v,\n\nSi = - ( 1 + A;-) Si + IhH, if. = - (1 + A; 52 + Ih s-f.\n\nHence, by some easy algebra,\n\nS\\ Sn - S Sx Zk S1S2 \\ Si - 2 )\n\nSi's.:r-S./S,' ~ si-Sx ) l-k'Sx si) '\n\nand so\n\n(s,s, - s,s,)-' ~ (s,s, - s,s;) = (1 - k's.W)-' (1 - k's,%');\n\non integrating this equation we have\n\nS1S2 s Si\n\n1 - k 81 82'\n\nwhere C is the constant of integration.\n\nReplacing the expressions on the left by their values in terms of u\nand v we get \\\n\nen ?i dn M sn y + en w dn w sn u 1 -k sn u sn v\n\n* Acta Petropolitana, vi. (1761), pp. 35-57. Euler had obtaiued some\nspecial cases of this result a few years earlier.\n\nt Another method is given by Legendre, Fonctions Elliptiques, i.\n(Paris, 1825), p. 20, and an interesting geometrical proof was given\nbj- Jacobi, Journal fur Math. iii. (1828), p. 376. X For brevity, we\nshall denote differential coefficients with regard to u by dots, thus\n\ndv .. d v du dii\n\n8 I.e. those values for which en u dn u and cnv nv do not vanish.\n\n%\n% 496\n%\n\nThat is to say, we have two integrals of the equation du + dv = 0,\nnamely ) u + v= a and (ii)\n\nsn u en V dn V + sn ?; en M dn u\n\n1 - k sn\" u sn v\n\n= G,\n\neach integral involving an arbitrary constant. By the general theory\nof differential equations of the first order, these integrals cannot\nbe functionally independent, and so\n\nsn u en v dn v + sn v en u dn u 1 - A;- sn ii sn\"-* v\n\nis expressible as a function oi u + v; call this function f(u + v).\n\nOn putting i; = 0, we see that /(u)=snw; and so the function / is the\nsn function.\n\nWe have thus demonstrated the result that\n\nsn tt en V dn V 4- sn v en u dn u\n\nsn u + v) = j- -,\n\n1 - '- sn- u sn- V\n\nwhich is the addition-theorem.\n\nUsing an obvious notation*, wc may write\n\n. s.cdo + SoCidi\n\nExample 1. Obtain the addition-theorem for sin ic by using the results\n\nExample 2. Prove from first principles that\n\n3 d\\ SiC2d2 + s.2Cidi\\\n\n\\ cv cuj\n\nycv cuJ 1 - k'-s -s-r\n\nand deduce the addition-theorem for sn u.\n\n(Abel, Journal fUr Math. n. (1827), p. 105.) Example 3. Shew that\n\ns -8 \\ S iCid + s Cidi SidiC +SjdiCi s c d - s Cidi CiC2 + Sidj Sod2\ndid2+khiS2CiC2'\n\n(Cayley, Elliptic Functions (1876), p. 63.)\n\nExample 4. Oljtain the addition-theorem for sn u from the results\n\n i(y-H ) 4(y- ) 253=-9,(y)54(y) 2( ) 3( )+- 2(y) 3(3/)5i( )54(4 4 y+z)\nSi(2/-2) V= V (y) i' (z) - 1- ii/) l' (z),\n\ngiven in Chapter xxi, Miscellaneous Examples 1 and 3 (pp. 487, 488).\n\\addexamplecitation{Jacobi.}\n\nExample 5. Assuming that the coordinates of any point on the curve\n\n?/- = (l-;f2)(l-y5;2a;2)\n\ncan be expressed in the form (sn u, en u dn u), obtain the\naddition-theorem for sn u by Abel's method \\hardsubsubsectionref{20}{3}{1}{2}).\n\n* This uotation is due to Glaisher, Messenger, x. (1881), pj). 9'2,\n124.\n\nI\n\n%\n% 497\n%\n\n[Consider the intersections of the given curve with the variable curve\ny = I + mx + n.v'; one is (0, 1); let the others have parameters u,\nUz, M3, of which u . xii may be chosen arbitrarily Vjy suitable choice\nof m and n. Shew that U1 + U2 + U3 is constant, by the method of §\n20-312, and deduce that this constant is zero by taking\n\n i = 0, = -|(1+F).\n\nObserve also that, by reason of the relations\n\nwe have\n\n 3(1 -k' Xi x. ) = X3- +,2\\ 2 ) mx x x - mxix.,- nxxX2 ( 1 + 2+ 3)\n\n= xi+x-2- -x - nxi x-2 X3) - Xi + X2) - 2mxi Xo - nx Xo xi + 2)\n\n\\Subsection{22}{2}{1}{The addition-theorems for en u and dn u.}\nWe shall now establish\nthe results\n\nen M en w - sn w sn V dn w dn w\n\nen (z< + v) = = Y, - 2 2 .\n\n- ., dn dn V - k- sn w sn v en u en v dn (u + v) = rw- - .;\n\nthe most simple method of obtaining them is from the formula for sn (u\n+ v).\n\nUsing the notation introdueed at the end of \\hardsectionref{22}{2}, we have (1 - k's\n's.-y en- (u + v) = (l - k s s Y 1 - sn- (u + v)]\n\n= (1 - k' S ' S y - (SjCaC o + SoCidiY\n\n= 1 - 'Ik'-si's + k*s,*s.2' - sf (1 - si) (1 - k si)\n\n- si (1 - si) (1 - k-si) - 2sxS.2CiC.2did2 = (1 - si) (1 - si) + sisi\n(1 - k'si) (1 - k'si)\n\n- 2siS2CiC.,dxd.2 = (ciCo - SySod d y\n\nand so en (u + v) = + - - r ~ -\n\n 1 - k-sisi\n\nBut both of these expressions are one- valued funetions of u, analytic\nexeept at isolated poles and zeros, and it is ineonsistent with the\ntheory of analytic continuation that their ratio should be + 1 for\nsome values of u, and - 1 for other values, so the ambiguous sign is\nreally definite; putting li = 0, we see that the plus sign has to be\ntaken. The first formula is consequently proved.\n\nThe formula for dn u + v) follows in like manner from the identity (1\n- k' sisiy - k (s CoJz + s.Cxdn y\n\n= (1 - k'-si) (1 - fi'si) + k*sisi (1 - si) (1 - si) -\n2k's,SoC,C2d,d2,\n\nthe proof of which is left to the reader.\n\nw. ii. A. 32\n\n%\n% 498\n%\n\nExample 1. Shew that\n\ndu u + v) dn u-v) = -j j i '\n\n\\addexamplecitation{Jacobi.} [A set of 33 formulae of this nature connecting functions of\nu + v and of - v is given in the Fundamenta Nova, pp. 32-34.]\n\nExample 2. Shew that\n\n8 cnu + cnv \\ 9 cnw+cnv\n\ncu sn M dn V + sn V dn ?< ov sn i dn v + sn i; dn u '\n\nso that (en r(+cn v)/(snMdn?' + sn vdnii) is a function of i + v only;\nand deduce that it is\n\nequal to 1 +cn u + v) lsvi u + v).\n\nObtain a corresponding result for the function ( iC9 +\nS2Ci)/(c?j+(a?2).\n\n(Cayley, Messenger, xiv. (1885), pp. 56-61.) Example 3. Shew that\n\n1 - Fsn2 u + v) sn2 u-v) = Fsn* u) l- F sn* v) (1 - Fsn2 ?< sn2 y) -2,\n'- + >fc2cn2(?< + v) (in u~v) = k\" + k-cn*u) (/ '2+Fcn' r) (1\n-Fsn2%sn2w)-2.\n\n\\addexamplecitation{Jacobi and Glaisher.}\n\nExample 4. Obtain the addition-theorems for cn(-w + r), dn(w-|-'i?) by\nthe method of \\hardsectionref{22}{2} example 4.\n\nExample 5. Using Glaisher's abridged notation Messenger, x. (1881), p.\n105), namely\n\ns, c, d=s\\ \\ u, en u, dn u, and >S', C, Z) = sn 2i, en 2i(, dn 2,\nprove that\n\n2gCt l-2g2 .2g4 1 - 2/t2s2 + y[;y\n\nl->;254' - l\\ y[,.254 ' - 1 L y[ s4- '\n\n(i+ )4\\ (i\\ i\n\n(l + -?:,S') + (l-Z-,S') ' Example 6. With the notation of example 5,\nshew that\n\n1-C D D-BC-k- D-G\n\n   =\n\nl+Z>~F(l + (7) k D-G) k' '+D-BC \\ D + C \\ D + k- C-k ' \\ /;'2(i-Z)) \\\n/j:'2(i + (7) ~l-|-i>~ k: l + G)' ~ k- D -C)~ k\"- + D- PC\n\nk' +D + k' G \\ D+C \\ k' C) k' \\ + D ) \\ + D \"l + C\" D~C ~k' + D-k- G'\n\n\\addexamplecitation{Glaisher.}\n\n\\Section{22}{3}{The constant K.}\nWe have seen that, if\n\nu=\\ \\ l- )- ~ l-kH'')- ~dt,\n\nJ then y = sn u, k).\n\nIf we take the upper limit to be unity (the path of integration being\na straight line), it is customary to denote the value of the integral\nby the symbol K, so that sn K, k)= 1.\n\n[It will be seen in \\hardsubsubsectionref{22}{3}{0}{2} that this detinition of A' is equivalent\nto the definition as TT a in \\hardsubsectionref{21}{6}{1}.]\n\n%\n% 499\n%\n\nIt is obvious that en = and dn K= ± k' : to fix the ambiguity in sign,\nsuppose < A' < 1, and trace the change in (1 - k'H-) as t increases\nfrom to 1; since this expression is initially unity and as neither of\nits branch points (at t = ± k~ ) is encountered, the final value of\nthe expression is positive, and so it is + A '; and therefore, since\ndn is a continuous function of k, its value is always + k'.\n\nThe elliptic functions of K are thus given by the formulae sniT-l, cn\n= 0, dn K = k'.\n\n\\Subsubsection{22}{3}{0}{1}{The expression of K in terms of k.}\n\nIn the integral defining K, write t = sin <, and we have at once\n\nK \\ (l-A-2sin-(/))- cZ(/>.\n\nJ\n\nWhen \\ k\\ < \\, the integi-and may be expanded in a series of powers of\nk, the series converging uniformly with regard to (by \\hardsubsectionref{3}{3}{4}, since\nsin-\" ( 1 ); integrating term-by-term \\hardsectionref{4}{7}), we at once get\n\nK=\\ \\ F \\, \\; 1; k =\\ \\ Fl\\, 1;\n\nwhere c = k\" . By the theory of analytic continuation, this result\nholds for all values of c when a cut is made from 1 to -l- oo in the\nc-plane, since both the integrand and the hypergeometric function are\none-valued and analytic in the cut plane. Example. Shew that\n\n(Legendre, Fonctions Elliptiques, i. (1825), p. 62.)\n\n\\Subsubsection{22}{3}{0}{2}{The equivalence of the definitions of K-}\n\nTaking = 3- in \\hardsubsectionref{21}{6}{1}, we see at once that \\&n hTrd ) = \\ and so\ncn(|7r53-) = 0. Consequently, 1 - sn m has a double zero at \\ 7r i .\nTherefore, since the number of poles of sn w in the cell with corners\n0, nS, n t- ) B, tt (r - 1) .93'- is two, it follows from \\hardsubsectionref{20}{1}{3}\nthat the only zeros of 1 - sum are at the points = Jn-\n(4?n-l-l-|-2?ir) 3, where m and n are integers. Therefore, with the\ndefinition of \\hardsectionref{22}{3},\n\nA'=|7r(4m-l-l+2 r)532.\n\nNow take t to be a pure imaginary, so that < /( < 1, and K is real;\nand we have ?i = 0, so that\n\n\\ TT Am + l)B = j ''(l->t2sin2 0)~2(/,\n\nwhere m is a positive integer or zero; it is obviously not a negative\ninteger.\n\nIf m is a positive integer, since / (1 - k' sin 4>)~ i * continuous\nfunction of a and\n\nJ so passes through all values between and K as a increases from to\ntt, we can find a value of a less than tt, such that\n\nA7(4?ra -I- 1 ) = hrrS = f \" ( 1 - P sin2 cj))- dc;\n\nand so sn ( TrSs ) = sin a < 1,\n\nwhich is untrue, since sn (-177 32) = 1.\n\n32-2\n\n%\n% 500\n%\n\nTherefore m must he zero, that is to say we have\n\nBut both K and n - are analytic functions of / when tlie o-plane is\ncut from 1 to + 00, and so, by the theory of analytic continuation,\nthis result, proved when 0< -<l, persists throughout the cut plane.\n\nThe equivalence of the definitions of K has therefore been\nestablished. Example 1. By considering the integral\n\nJ shew that sn 2K= 0.\n\nExample 2. Prove that\n\nsn A'=(l +/;')\" S cnhK=M \\ + k')', dn|A' = /CA\n\n[Notice that when u = \\ K, cn2M = 0. The simplest way of determining\nthe signs to be attached to the various radicals is to make --a-O,\nX'-a-l, and then sn ?<, en w, dn u degenerate into sin u, cos u, 1.]\n\nExample 3. Prove, by means of the theory of Theta-functions, that\n\ncs iA'=dn \\ K=k' .\n\n\\Subsection{22}{3}{1}{The periodic proper ties (associated with K) of the Jacobian elliptic functions.}\n\nThe intimate connexion of K with periodic properties of the functions\nsnu, en 11, dnu, which may be anticipated from the periodic properties\nof\n\nTheta-functions associated with - tt, will now be demonstrated\ndirectly from\n\nthe addition-theorem.\n\nBy \\hardsectionref{22}{2}, Ave have\n\n, snucnK dnK + iiKcn.udnu,\n\nsn(u + K)-; - y ., -, --77 = cd u.\n\n  \\ - k' sn- a sn K\n\nIn like manner, from \\hardsectionref{22}{2}],\n\nen (it + K) = - ' sd u, dn (a + ii ) = ' nd u.\n\nTT /, Tj x cn((t + / ) 'sdw\n\nHence sn ( (i 4- 2it ) =, - 7; = - .-> - ~ = - sn u,\n\n  dn(u-l-ir) A;ndM\n\nand, similarly, en u -f IK) = - en u, dn it + 'IK) = dn u.\n\nFinally, sn u -h K) = - sn u -f 2K) = sn u, en (?( -I- 4 A\") = en u.\n\nThus 4iK is a period of each of the functions sn u, en ( while dn u\nhas the smaller period 2K.\n\nExample 1. Obtain the results\n\nsn ( u + A') = cd u, en (m + K) = - k' sd u, dn ( u + K) = k' nd m,\ndirectly from the definitions of sn ?t, en ?<, dn u as quotients of\nTheta-functions. Example 2. Shew that cs u cs ( K - u) = k'.\n\n%\n% 501\n%\n\n\\Subsection{22}{3}{2}{The constant K'.}\nWe shall denote the integi'al\n\nJo\n\nby the symbol K', so that K' is the same function of k'- (= c) as K is\nof k (= c); and so\n\nK'= rrFi -, \\; 1; k\",\n\nwhen the c'-plane is cut from 1 to + oo, i.e. when the c-plane is cut\nfrom\n\nto - X .\n\nTo shew that this definition of K' is equivalent to the definition of\n§ 21 \"61, we observe that if T7-'= - 1, is the one-valued function of\nP, in the cut plane, defined by the equations\n\nK= M - (0 1 r), F = 5, (0 ! r) 3* (0 I r),\n\nwhile, with the definition of \\hardsubsectionref{21}{5}{1},\n\n ' = 1 32(010,; :'2 = 52*(01r') 3'*(0|r'),\n\nso that K' must be the same function of kf as K is of k\"; and this is\nconsistent with the integral definition of K' as\n\nJo It will now be shewn that, if the c-plane be cut from to - 00 and\nfrom\n\n1 to + X, then, in the cut plane, K' may be defined by the equation\n\nK' =r\\ s'-l)-- l- k's') - ds.\n\nJ 1\n\nFirst suppose that 0< '<1, so that < ' < 1, and then the integrals\nconcerned are real. In the integral\n\nf\\ l -t )-iO--k'H')- dt .'0\n\nmake the substitution\n\ns = l-k'H-)-',\n\nwhich gives\n\n(s' - 1)4 = k't (1 - I -f) -i, (1 - k's'-)i = k' (1 - i?f (1 - k'H-) '\n*, ds \\ k'H dt Xl-k'H-'f\n\nit being understood that the positive value of each radical is to be\ntaken. On substitution, we at once get the result stated, namely that\n\nK' = I ' (6- - 1) - i (1 - k's') - i ds,\n\nprovided that < k <\\; the result has next to be extended to complex\nvalues of .\n\n%\n% 502\n%\n\nConsider T' ' l-t )~ l -kH\"-) \" dt.\n\nthe path of integration passing above the point 1, and not crossing\nthe imaginary axis*. The path may be taken to be the straight lines\njoining to 1 - 8 and 1 + 8 to k~ together with a semicircle of (small)\nradius S above the real axis. If (l-t-y and ( k' t-)\n\nreduce to + 1 at = the value of the former at 1 + S is e\" \"\" S (2 + 8)\n= - i (t - Vf, where each radical is positive; while the value of the\nlatter at <=1 is +/' when k is real, and hence by the theory of\nanalytic continuation it is always +/;'.\n\nMake 8-*-0, and the integral round the semicircle tends to zero like\n8-; and so\n\nNow f-)- - k'H y -clt=\\ (F-?('-i)\"2(i\\,,2)-2o;?(,\n\nwhich t is analytic throughout the cut plane, while K is analytic\nthroughout the cut plane.\n\nHence \\ \\ ' i: -\\ y hH y dt\n\nis analytic thi'oughout the cut plane, and as it is equal to the\nanalytic function K' when < X-'< 1, the equality persists throughout\nthe cut plane; that is to say\n\n/ l/A; 1 1\n\nwhen the c-plane is cut from to - qo and from 1 to + oo,\n\nSince\n\nK + iK'=\\ l-t-)-- il-hH')- ~dt,\n\nJo\n\nwe have sn (K + iK') = i/k, dn (K + iK') =;\n\nwhile the value of en (K + iK') is the value of (1 - P) when t has\nfollowed the prescribed path to the point 1/A-, and so its value is\n-ik'/k, not +ik'lk.\n\nExample 1. Shew that\n\nI f \\ t l-t) l-Pt) ~- dt = l r t t-' ) kH- ) ~ dt=K,\n\n- / -t l-t) kH) - dt = ( - 1) (1 - FOl- ~ 'dt = A\".\n\nExample 2. Shew that K' satisfies the same linear differential\nequation as K \\hardsubsubsectionref{22}{3}{0}{1} example).\n\n\\Subsection{22}{3}{3}{The periodic propertiesX associated with K + iK') of the Jacohian elliptic functions.}\n\nIf we make use of the three equations\n\nsn K + iK') = k-\\ en (K + iK') = - ik'jk, dn K + iK') = 0,\n\n* II (A:) > because | arg c I < tt.\n\nt The path of integration passes above the point u = k.\n\nJ The double periodicity of snw may be inferred from dynamical\nconsiderations. See Whittaker, Analytical Dynamics (1917), § 44.\n\n%\n% 503\n%\n\nwe get at once, from the addition-theorems for sn u, en u, dn u, the\nfollowing results :\n\n, ., sn u en K + iK') dn (K + iK') + sn (Z H- iK') cnudnw\n\nsn ( 4- ii + *A ) = z Tz - 2/ ir, ir'\\ '\n\n  1 - k sn u sn K +%K )\n\n= k~ do (t, and similarly en ' u + K + iK') = - ik'k~ nc u,\n\ndn (zt + if + iK') = ik' sc w. By repeated applications of these\nformulae we have\n\nf sn (u + 2K+ 2iK') = - sn u, ( sn (a + 4>K + UK') = sn u, cn(u+2K-\n2iK') en t<, -. en (u + 4 \" + 4tX') =cn m, [dn (m + 2Z + 2iK') = - dn\nw, [dn u 4<K + UK') = dn u. Hence the functions sn u and dn u have\nperiod 4iK + UK', ivhile en u has the smaller period 2K + 2iK'.\n\n\\Subsection{22}{3}{4}{The periodic proper-ties (associated with iK') of the Jacobian elliptic functions.}\n\nBy the addition-theorem we have\n\nsn (u + iK') = Sn(u-K + K+ iK') = k-' dc (u - K) = k~ ns u. Similarly\nwe find the equations\n\nen (u + iK') - - ik~ ds u, dn u + iK') = - ics u. By repeated\napplications of these formulae we have\n\n' Bn u- 2iK') = sn u, ( sn (ii + UK') = sn u, - en (u + 2iK') = - en\nu, - en u + UK) = en u,,dn (u + 2iK') = - dn u, [dn u + UK') = dn u.\nHence the functions en u and dn u have period UK', luhile sn u has the\nsmaller period 2iK' .\n\nExample. Obtain the formulae\n\nsn iu + 2mK+ 2mK') = ( - )'\" sn ti, en (u + 27nK+ 2niK') = ( - )™ + \"\nen i, dn ( + 2mK+2niK') = ( - )\" dn u.\n\n\\Subsubsection{22}{3}{4}{1}{The behaviour of the Jacobian elliptic functions near the origin and near iK'.}\n\nWe have\n\nd d\n\n- sn u = en M dn u, -i- sn u = 4 gn u en u dn m - en m dn u (dn u + k\n- cn u). du du\n\n%\n% 504\n%\n\nHence, by Maclaurin's theorem, we have, for small values of | w|, sn u\n=u-~(l + k-) u' + (u'), on using the fact that sn u is an odd\nfunction.\n\nIn like manner\n\ndn u = l-l khr + (u'). It follows that\n\nsn (u + iK') = k~ ns u\n\nku [ b )\n\n1 1 + '-, 3,\n\n=,- + -7rr- u+0(u'); ku bk\n\n- i 2k- - 1 and similarly en (u + iK') = tt; +, iu + (u'),\n\ndn (u + iK') = - - + / ' ill + (u').\n\nu b\n\nIt follows that at the point iK' the functions sn r, cnv, dnv have\nsimple poles with residues k~, - ik~, - i ixspectively.\n\nExample. Obtain the residues of snw, cnw, dnw at iK' by the theory of\nTheta- fiinctions.\n\n2235. General description of the functiotis sn u, en u, dn u.\n\nThe foregoing investigations of the functions sn u, en u and dn u may\nbe summarised in the following terms :\n\n(I) The function sn m is a doubly-periodic function of u with period:?\nK, 2iK'. It is analytic except at the points congruent to iK' or to 2K\n+ iK' (mod. 4jfir, 2iK'); these points are simple poles, the residues\nat the first set all being k~ and the residues at the second set all\nbeing - k~; and the function has a simple zero at all points\ncongruent to (mod. 2K, 2iK').\n\nIt may be observed that sn u is the only function of u satisfying this\ndescription; for if (m) were another such function, sn m - (m) would\nhave no singularities and would be a doubly-periodic function; hence\n\\hardsubsectionref{20}{1}{2}) it would be a constant, and this constant vanishes, as may\nbe seen by putting u = 0; so that (tt) = sn u.\n\nWhen 0< A; < 1, it is obvious that K and K' are real, and sn u is real\nfor real values of u and is a pure imaginary when a is a pure\nimaginary.\n\n(II) The function cm* is a doubly-periodic function of u with periods\nK and 2K -+ 2iK'. It is analytic except at points congruent to iK' or\nto 2ir-f- iK' (mod. 4/1\", 2K - 2iK'); these points are simple poles,\nthe residues\n\n%\n% 505\n%\n\nat the first set being - ik~\\ and the residues at the second set being\nik~; and the function has a simple zero at all points congruent to K\n(mod. 2K, 2iK'). (Ill) The function dn u is a doubly-periodic function\nof u with periods 2,K and 4iiK'. It is analytic except at points\ncongruent to iK' or to ZiK' (mod. ''2K, 4tiK'); these points are\nsimple poles, the residues at the first set being - i, and the\nresidues at the second set being i; and the function has a simple\nzero at all points congruent to K + iK' (mod. 2K, 2iK').\n\n[To see that the fvinctions have no zeros or poles other than those\njust specified, recourse must be had to their definitions in terms of\nTheta-functions.]\n\n\\Subsubsection{22}{3}{5}{1}{The connexion between Weierstrassian and Jacobian elliptic functions.}\nIf ej, 62) 3 be any three distinct numbers whose sum is\nzero, and if we write\n\n61-63\n\n  = 3 +\n\nsn2 (Xm, k) '\n\nwe have (;7 ) (' 'i ~\" z)' \" \"' ** '\n\n= 4 (ei ~e'i)-\\ \\ ns Xzi (ns Xw - 1) (ns Xw- ) = 4X2 (ci - 63) ~ V / -\n3) ( / - ei) y - F e - 63) - 63 . Hence, if X2 = 6i - 63 and >?'2 =\n(e-. - 63)/(6i - 63), then y satisfies the equation*\n\nand so e3 + (ei-63) ns Jm (61-63)2, A/ zyr = § (' +; Qi, 9z\\\n\nwhere a is a constant. Making u - 0, we see that a is a period, and so\n\n  (u; g2, 93) = 63 + ei - 63) ns2 u (ci - 63)% the Jacobian elhptic\nfunction having its modulus given by the eqviation\n\n1-63\n\n61-63\n\\Section{22}{4}{Jacobi's imaginary transformation TODO.}\n\nThe result of | 21-51, which gave a transformation from\nTheta-functions with parameter t to Theta-functions with parameter t'\n= - l/r, naturally produces a transformation of Jacobian elliptic\nfunctions; this transformation is expressed by the equations\n\nsn (iu, k) = i sc (u, k'), en iu, k) nc (u, k'), dn in, k) = dc (a,\n¥). Suppose, for simplicity, that < c < 1 and y >; let\n\n' 'l-t')' l- kH-) ' dt = iu,\n\nf\n\nJo\n\nso that iy = sn (iu, k);\n\ntake the path of integration to be a straight line, and we have en\n(iu, k) = (1 + y' ), dn iu, A;) = (1 -1- k-y-) .\n\n* The values of 2 '' 93, usual, - J2e2 3 and eie e-s.\n\nf Fundamenta Nova, pp. 34, 35. Abel Journal fUr Math. 11. (1827), p.\n104) derives the double periodicity of elliptic functions from this\nresult. Cf. a letter of Jan. 12, 1828, from Jacobi to Legendre\n[Jacobi, Ges. Werke, i. (1881), p. 402].\n\n%\n% 506\n%\n\nNow put V = 77/(1 - ?;-)-, where < 77 < 1, so that the range of values\nof t is from to 177/(1-77-)-, and hence, if t = iUl \\ - t ), the\nrange of values of t is from to 77.\n\nThen dt = i t )- -idU, (1 - r-) = (1 -,-)-*,\n\n1 - kH' = (1 - kH ) ~ - l- /r) - i\n\nand we have in=\\ (1 - fj-) \" (1 - h'-ti-) ' idti,\n\nJo\n\nso that 77 = sn (u, k')\n\nand therefore tj = sc u, k').\n\nWe have thus obtained the result that sn hi, k) = i sc u, k').\n\nAlso en in, k) = (1 -f- y'-)- -- (1 - 77-) ~ = nc u, k'),\n\nand dn iu, k) = l- ¥if) = ( 1 - k'-'n'') ( 1 - 77-) ~ * = dc a, k').\n\nNow sn iu, k) and isc (w, k') are one-valued functions of u and A; (in\nthe cut c-plane) with isolated poles. Hence by the theory of analytic\ncontinuation the results proved for real values of u and k hold for\ngeneral complex values of u and k.\n\n\\Subsection{22}{4}{1}{Proof of Jacohi's imagimiry transformation by the aid of Theta-functions.}\n\nThe results just obtained may be proved very simply by the aid of\nTheta-functions. Thus, from \\hardsubsectionref{21}{6}{1},\n\nsndu M\\ 3(0|T),(i iT) '' '''' -% Oit)% J t)'\n\nwhere = m/ 3- (0 | t),\n\nand so, by \\hardsubsectionref{21}{5}{1}, sn tu, k) = |4 |4> . \"f '\"'\n\n= - isc (v, k'),\n\nwhere v = izr\" (0 j t) = izr' . (- ir) 3- (0 j t) = - w,\n\nso that, finally, sn iu, k) = i sc u, k').\n\nExample 1. Prove that en iu, l-) = nc(u, k', dn (in, i-) = do ri, k')\nby the aid of Theta- functions.\n\nExample . Shew that\n\nsn hiK', k) = iiic K', k') = ik~-,\n\nen i iK', k) = l+k) k-, dn iiK', k) = l+k)K\n\n[There is great difficulty in determining the signs of sn iK', ci\\ j\niE', dnit'A'', if any method other than Jaeobi's transformation is\nused.]\n\n%\n% 507\n%\n\nExample 3. Shew that\n\nExample 4. If < Z- < 1 and if be the modular angle, shew that\n\nsn \\ K + ?:/ :') = e'' *' \" *' V(cosec ), en h K + iK') = e \" i' '\n/(cot 6),\n\n\\addexamplecitation{Glaisher.} 22\"42. Landens transformation* . We shall now obtain the\nformula\n\nf ' (1 - l- sin- d,) ~ dd, = l- k') f (1 - -' sin- 6) \" *c, Jo Jo\n\nwhere sin j = (1 + k') sin ( cos < (1 - kr sin- ) ~\n\nand k, = l-k')l l + k').\n\nThis formula, of which Landen was the discoverer, may be expressed by-\nmeans of Jacobian elliptic functions in the form\n\nsn (1 + k') u, k \\ = \\ ->r k') sn u, k) cd u, k), on writing (f) = am\nu, (f) - am u .\n\nTo obtain this result, we make use of the equations of | 21-52, namely\n% z\\ r), z\\ r ) % z\\ t); z\\ t ) 3 (0 | t) 4 (0 I t) 4(2 12t) -\n(22I2t) 4(0|2t)\n\nWritef Ti = 2t, and let k-, A, A' be the modulus and quarter-periods\nformed with parameter Tj; then the equation\n\n% z\\ r)X z\\ r) \\ ' 'lz\\ n;) % z\\ r), z\\ r),(20iTO\n\nmay obviously be written\n\nk sn 2Kz/7r, k) cd (2 A /tt, k) = k, sn (4 A tt, k,) (A).\n\nTo determine k in terms of k, put z = jTt, and we immediately get\n\n  /(l + k') = k, which gives, on squaring, k = (1 - '')/(l + k'), as\nstated above.\n\nTo determine A, divide equation (A) by z, and then make - >0; and we\nget\n\n2Kk = 4 'l* A,\n\nso that A=~ [+k')K.\n\n* Phil. Trans, of the Royal Sac. lxv. (1775), p. 285.\n\nt It will be supposed that \\ R(t)\\ < :, to avoid difficulties of sign\nwhich arise if R (tj) does not lie between ±1. This condition is\nsatisfied when 0<k<l, for r is then a pure imaginary.\n\n%\n% 508\n%\n\nHence, writing ii in place of Kzjir, we at once get from (A) (1 + A;')\nsn u, k) cd u, k) = sn (1 + k') u, ki], since 4<Az/7r = 2Au/K =(1 +\nk')ii;\n\nso that Landen's result has been completely proved.\n\nExample 1. Shew that JA = 2K'jK, and thence that A' = (l +1-') K'.\nExample 2. Shew that\n\nen (!+/')\", /i = l -(!+>(') sn2(, H') nd n, k), dn (l+ ')w, i] = W\n+ (l - k') cn (u, X-) nd(M, k). Example 3. Shew that\n\ndn u, k) = l-k')cn l+k')u, ki] + I + i-') dn I + k') u, l\\ \\ },\n\nwhere X-=2 -ii/(l+ 'i).\n\n\\Subsubsection{22}{4}{2}{1}{Transformations of elliptic functions.}\n\nThe formula of Landen is a particular case of what is known as a\ntransformation of elliptic functions; a transformation consists in\nthe expression of elliptic functions with parameter t in terms of\nthose with parameter a + bT)j c + dT, where a, b, c, d are integers.\n\"We have had another transformation in which = - 1, 6 = 0, c = 0,\nc?=l, namely Jacobi's imaginary transformation. For the general theory\nof transformations, which is out- side the range of this book, the\nreader is referred to Jacobi, Fundamenta JYova, to Klein, Vorlesungen\niiher die Theorie der elliptischen Modulfunktionen (edited by Fricke),\nand to Cayley, Elliptic Functions (London, 1895).\n\nExample. By considering the transformation ro = r+l, shew, by the\nmethod of \\hardsubsectionref{22}{4}{2}, that\n\nsn k'u, k2)=k' sd u, k),\n\nwhere -0= ± ik/k', and the upper or lower sign is taken according as R\nt)<0 or R (r) >; and obtain formulae for en k'u, 2) and dn k' l, k' .\n\n\\Section{22}{5}{Infinite products for the Jacohian elliptic functions*.TODO}\n\nThe products for the Theta-functions, obtained in \\hardsectionref{21}{3}, at once\nyield products for the Jacobian elliptic functions; writing a =\nKxJtt, we obviously have, from \\hardsubsectionref{22}{1}{1}, formulae (A), (B) and (C),\n\n  i, - It  ( 1 - 2m cos 2a; + o \" ]\n\n   =i 1 1 - 25-'*-! cos 1x + (7 \"-- J\n\ng i;47 -4 n 1 1 + 29 \" COS 2 + \" [\n\nen II = 2q*k -k - cos x H \\ ?r- r~~, t;;- i .\n\n,j i (1 - 2 2\"-> cos 2x + 5'*\"-2)\n\n- lA u (l + 2g - cos2a; + g -'\n\n''1 [1 - 2cf' ''' COS 2x + q\n\nFrom these results the products for the nine reciprocals and quotients\ncan\n\nbe written down.\n\nThere are twenty-four other formulae which may be obtained in the\nfollowing manner :\n\nFrom the duplication-formulae \\hardsubsectionref{22}{2}{1} example 5) we have\n\n1-cntt 1,1 l-HduM,1 1 dn?i-|-cnM 1,1\n\n= sn - udc - u, =as -u uc -,  = en ? as - u.\n\nHuu 2 2 sn 2 2 sn m 2 2\n\n* Fundamenta Nova, pp. 84-115.\n\n%\n% 509\n%\n\nTake the first of these, and use the products for sn u, en |i(, dn u;\nwe get\n\n7+q j '\n\nl - cnu l-cos. ' ° fl -2 ( -o)\" cos j;-\n\nsnu ~ sin =i (1 + 2 (-g )\"cosa;+g'2 on combining the various products.\n\nWrite u + K for u, x+h-rr for x, and ve have\n\ndnw + snw l + sin.-?; * fl + 2 (-g)\" sin.- g + g \" ! cnu \" cos j; =i\n[1 - 2 ( - g)\" sin a; + ( - j '\n\nWriting u + iK' for in these formulae we have\n\n. - ri + 2  ( - ) o\" - sin .v - <f'' \" ] k sn if + dn ?< = I n - =\nrr-. - r; - -. - - t,\n\nand the expression for cd ?i + ik' nd u is obtained by writing cos x\nfor sin .t? in this product.\n\nFrom the identities I - cmi) (I + cmi) = an ti, (ksmi + idnu)\nl-sm(-idmi) l, etc., we at once get four other formuhxe, making eight\nin all; the other sixteen follow in the same way from the expressions\nfor ds-|Mnc M and cn tids ic. The reader may obtain these as an\nexample, noting specially the following :\n\nExample 1. Shew that\n\n  >-i ((i-ij '-'Xi+t '\"\"')!\n\nExample 2. Deduce fron\\ example 1 and from § 22 '41 example 4, that,\nif 6 be the modular angle, then\n\n\" tl+(-)\" . +*/'\n\nand thence, by taking logarithms, obtain Jacobi's result\n$$\nTODO\n$$\n' quae inter formulas elegantissimas censeri debet.' Fund. Nova, p.\n108.) Example 3. By expanding each term in the equation log sn M = log\n(2 J') - i log /t + log sin x + 2 log ( 1 - j \" e * )\n\n+ log (1 - j2ne-2ia;)\\ log(l-j2n-l e' ) -\\ og (1 - J n-l g -2ia:-)j\n\nin powers of e ', and rearranging the resulting double series, shew\nthat\n\n, K 1, 7 1  ** 2o'\" cos 2mA'\n\nlogsnw=log(2g')-|log/ - + logsm.r+ 2;,,,\n\nwhen l/(2)l<-|7r/(r).\n\nObtain similar series for log en u, log dn i.\n\n(Jacobi, Fundamenta Nova, j). 99.)\n\nExample 4. Deduce from example 3 that\n\n K\n\nlog sn udu= - irK' - \\ K log k.\n\n(Glaisher, Proc. Royal Soc. xxix.)\n\n/:\n\n%\n% 510\n%\n\n\\Section{22}{6}{Fourier series for the Jacobian elliptic functions*.TODO}\n\nIf u = Rxjir, sn u is an odd periodic function of x (with period 27r),\nwhich obviously satisfies Dirichlet's conditions \\hardsectionref{9}{2}) for real\nvalues of x; and therefore \\hardsubsectionref{9}{2}{2}) we may expand sn w as a Fourier\nsine-series in sines of multiples of x, thus\n\nsn a - hn sin nx,\n\nn = \\\n\nthe expansion being valid for all real values of x. It is easily seen\nthat the coefficients 6 are given by the formula\n\nTTibn - I sn u . exp nix) dx.\n\nJ -77\n\nTo evaluate this integi'al, consider I snu. exp nix) dx taken round\nthe parallelogram whose corners are - tt, tt, ttt, - 27r + ttt.\n\nTttt\n\nFrom the periodic properties of sn w and exp nix), we see that 1\ncancels\n\nr -It ' IT\n\n1; and so, since -tt + ttt and ttt are the only poles of the\nintegrand\n\n qua function of x) inside the contour, with residuesf\n\n- ~ ( 2 tt/K ] exp ( - niir + - niriT j\n\nand k- Q Tr/iTJ exp Q nirir)\n\nrespectively, we have\n\n\\ \\ - [ sn li . exp nix)dx = - g-\" 1 - (-)\" .\n\n(J -TT J -2;7 + 7rTj -\"- \"\n\nWriting a; - tt + ttt for x in the second integral, we get\n\n[1 + (-)\"?\" j sn I* . exp (mic) rfa; = -| 3 \" 1 - (-)~ .\n\nHence, when /i is even, hn =; but when n is odd Consequently\n\nsn ti =\n\n27r J5'- sin a; g sin Sx q sin oa; ]\n\nwhen X is real; but the right-hand side of this equation is analytic\nwhen q \" exTp nix) and q exp -nix) both tend to zero as w- >x, and the\nleft- hand side is analytic except at the poles of sn u.\n\n* These results are substantially due to Jacobi, Fundamenta Nova, p.\n101. t The factor irlK has to be inserted because we are dealing with\nsn (2KxJTr).\n\n%\n% 511\n%\n\nHence both sides are analytic in the strip (in the plane of the\ncomplex variable x) which is defined by the inequality [ I(oc) : < irl\nr).\n\nAnd so, by the theory of analj tic continuation, we have the result sn\n\n\\ 27r I g\" sin(2;? + ) x (where u = KxJtt), valid throughout the strip\n[ / (a;) | < - tt/ (r)\n\nExample 1. Shew that, if ?i = 2A'.iY7r, then\n\nCU M =\n\n27r 5 cos(2?;.+ l) A- \\ tt Stt °° §'\" cos 2??.r\n\nA n=o l + ? -i ' '''''*\"2Z + T !i l+j- '\n\nI \" J . 7., 29\" sin 2?i ./o,1=1 %(l+j2 )\n\nthese results being valid when | /( ) | <c\\ tt I r).\n\nExample 2. By writing x-k-\\ iT for x in results ah'eady obtained, shew\nthat, if u= Kxl-K and \\ I x)\\ < \\ ivI t\\\n\nthen cd - 1 (-rg--+ cos(2 + l ) sd..-- 1 (- ?\"+ sin (2n + l).: then\ncdw-, 2 l\\ j2 + i ' '\" '-A'M'io T+ i '\n\n, TT 27r \"\" ( - )\" o\" COS 2 a;\n\nnd =-.>,, + -FT, 2 - - - 5 .\n\n2AX-' Kk' =i l+j2n\n\n\\Subsection{22}{6}{1}{Fourier series for reciprocals of Jacobian elliptic functions.}\n\nIn the result of \\hardsectionref{22}{6}, write u + iK' for u and consequentl a; + ttt\nfor a;;\n\nthen we see that, ifO>/(a7)> - tt/ (t),\n\nand so (§ 22-:34)\n\nns li = (- iirjK) S \" + * [5\" + ie(2 +i) \\ - - ie-(2n+i) ix|/( i \\ 2\n+i\n\nw =\n\nX\n\n= (- iV/iT) S [2t5-\"+i sin (2n + 1) a; + (1 - q--' - ) e-(- +i '\na'J/(i \\ 2n+i =o\n\n  27r - r+' sin (27 + 1) a : \\ iV,,, .\n\nThat is to say\n\nTT 27r o-'*+i sin (2/i 4- 1) a; ns =j eosee + yJ\\ L\\ \\ .\n\nBut, apart from isolated poles at the points x = wrr, each side of\nthis equation is an analytic function of x \\ r\\ the strip in which\n\nIT I (r) >I x)>-'TrI (r) : - a strip double the width of that in which\nthe equation has been proved to be true; and so, by the theory of\nanalytic continuation, this expansion for ns u is valid throughout the\nwider strip, except at the points x = iiir.\n\n%\n% 512\n%\n\nExample. Obtain the following expansions, valid throughout the strip '\nI x)\\ < itI t) except at the poles of the first term on the right-hand\nsides of the respective expansions :\n\nTT 27r == a2n + isin(2?i + l) ds u = cosec..- 2 i: .T- >\n\nTT, 27r \" o- \" sin 2nx\n\n-' cot y;r 2\n\n2K K =i 1+?= \" '\n\nTT 27r \" (-) g2n + lcos(2?l + l).r\n\n . secA- + 2 l-g- -i '\n\nnc = 2ZX,sec.r -, 2 -,,,\n\nTT, 27r \" ( - )\" o \" sin 2?U7\n\n2 A A: Kk =i l+y n\n\n\\Section{22}{7}{Elliptic integrals.}\n\nAn integi-al of the form IR(w, x)dx, where R denotes a rational\nfunction\n\nof w and x, and w is a QUARTIG, or CUBIC function of x (without\nrepeated factors), is called an elliptic integral*.\n\n[Note. Elliptic integrals are of considerable historical importance,\nowing to the fact that a very large number of important properties of\nsuch integrals were discovered by Euler and Legendre before it was\nrealised that the inverses of certain standard types of such\nintegrals, rather than the integrals themselves, should be regarded as\nfundamental functions of analjsis.\n\nThe first mathematician to deal with elliptic functions as opposed to\nelliptic integrals was Gauss (§ 22 \"S), but the first results\npublished were by Abelt and Jacobil.\n\nThe results obtained by Abel were brought to the notice of Legendre by\nJacobi immediately after the publication by Legendre of the Traite des\nfonciions elliptiques. In the supplement (tome in. (1828), p. 1),\nLegendre comments on their discoveries in the following terms : \"A\npeine mon ouvrage avait-il vu le jour, a peine son titre pouvait-il\n§tre connu des .savans etrangers, que j'appris, avec autant\nd'etonnement que de satisfaction, que deux jeunes geometres, IM.\nJacobi (C.-G.-J.) de Koeuigsberg et Abel de Christiania, avaient\nreussi, par leurs travaux particuliers, a perfectionner\nconsiderablement la theorie des fonctions elliptiques dans ses points\nles plus eleves.\"\n\nAn interesting correspondence between Legendre and Jacobi was printed\nin Journal fur Math. Lxxx. (1875), pp. 20.5-279; in one of the letters\nLegendre refers to the claim of Gauss to have made in 1809 many of the\ndiscoveries published by Jacobi and Abel. The validity of this claim\nwas established by Schering (see Gauss, Werke, in. (1876), pp. 493,\n494), though the researches of Gauss ( Werke, in. pp. 404-460)\nremained unpubli-shed until after his death.]\n\nWe shall now give a brief outline of the important theorem that every\nelliptic integral can be evaluated by the aid of Theta-functions,\ncombined\n\n* Strictly speaking, it is only called an elliptic integral when it\ncannot be integrated by means of the elementary functions, and\nconsequently involves one of the three kinds of elliptic integrals\nintroduced in § 22 \"72.\n\nt Journal fur Math. ii. (1827), pp. 101-196.\n\ni Jacobi announced his discovery in two letters (dated June 13, 1827\nand August 2, 1827) to Schumacher, who published extracts from them in\nAstr. Nach. vi. (No. 123) in September 1827 - the month in which\nAbel's memoir appeared. .\n\n%\n% 513\n%\n\nwith the elementary functions of analysis; it has already been seen\n\\hardsectionref{20}{6}) that this process can be carried out in the special case of\njiv~ dx, since\n\nthe Weierstrassian elliptic functions can easily be expressed in terms\nof Theta-functions and their derivates \\hardsubsectionref{21}{7}{3}).\n\n[The most important case practically is that in which R is a real\nfunction of x and w, which are themselves real on the path of\nintegration; it will be shewn how, in such circumstances, the\nintegral may be expressed in a real form.]\n\nSince R (lu, x) is a rational function of w and x we may write\n\nR (w, x) = P (w, x)IQ w, x),\n\nwhere P and Q denote polynomials in w and x; then we have\n\nR(w x)= ' ~ ' ~ wQ (w, x) Q (- w, x) '\n\nNow Q (w, x) Q (- w, x) is a rational function of w- and x, since it\nis unaffected by changing the sign of lu; it is therefore expressible\nas a rational function of x.\n\nIf now we multiply out wP w, x) Q (- w;, x) and substitute for w- in\nterms of X wherever it occurs in the expression, we ultimately reduce\nit to a poly- nomial in X and w, the polynomial being linear in iv. We\nthus have an identity of the form\n\nR (w, x) = Ri (x) + tvRz x)]lw,\n\nby reason of the expression for w- as a quartic in x; where jRj and\nR2 denote\n\nrational functions of x.\n\nNow \\ Ro x) dx can be evaluated by means of elementary functions\nonly*;\n\nso the problem is reduced to that of evaluating jw~ Ri (x) dx. To\ncarry out\n\nthis process it is necessary to obtain a canonical expression for w'-,\nwhich we now proceed to do.\n\n\\Subsection{22}{7}{1}{The expression of a quartic as the product of sums of squares.}\n\nIt will now be shewn that any quartic (or cubicf) in x (with no\nrepeated factors) can be expressed in the form\n\n A,(x- a) + BJx- Y] A, (x - af + B, (x - f],\n\nwhere, if the coefficients in the quartic are real, A, B, A.., B,\na, /3 are all real.\n\n* The integratiou of rational functions of one variable is discussed\nin text-books on Integral Calculus.\n\nt In the following analysis, a cubic may be regarded as a quartic in\nwhich the eoefiScient of X* vanishes.\n\nW. M. A. 33\n\n%\n% 514\n%\n\nTo obtain this result, we observe that any quartic can be expressed yi\nthe form S S.. where Si, S2 are quadratic in x, say*\n\n<S'i = a x + 2biX + Ci, S.2 = aox- + 2h..x + c.,.\n\nNow, X being a constant, 1 - \\ S. will be a perfect square in x if\n\n(tti - Xftj) (ci - Xco) - (61 - \\ h - = 0.\n\nLet the roots of this equation be X, X ', then, by hypothesis,\nnumbers a, yQ exist such that\n\nSi - \\ 1S.2 = (o-i - Xitto) (x - a)-. Si - X S.. (a I - Xstu) x - f;\n\non solving these as equations in j, S.,, we obviously get results of\nthe form\n\nSi = Ai x- a)- + Bi x- /3)-, S. s A (x - a)- + Bo x - /S)\n\nand the required reduction of the quartic has been effected.\n\n[Note. If the quartic is real and has two or four complex factors, let\nSi have com- plex factors; then Xi and Xi are real and distinct since\n\n( ! - Xa2) (c'l - XC2)- (61- X62)\n\nis positive when X = and negative! when X = ai/ 2.\n\nWhen Si and S-i have real factors, say x - i) -v - i), - 2) - 2), the\ncondition that Xi and X2 should be real is easily found to be\n\n( 1 - 2) (6' - 2) ( 1 - 2') ( 1' - f/) > 0,\n\na condition which is satisfied when the zeros of Si and those of \\& do\nnot interlace; this was, of course, the reason for choosing the\nfactors S\"! and So of the quartic in such a way that their zeros do\nnot interlace.]\n\n\\Subsection{22}{7}{2}{The three kinds of elliptic integrals.}\n\nLet a, /3 be determined by the rule just obtained in \\hardsubsectionref{22}{7}{1}, and, in\nthe integral w~ Ri x) dx, take a new variable t defined by the\nequation;!:\n\nt=(x-a)l x- );\n\n,, dx (a-B)~ dt we then have - = + .\n\n    Aif' + Bi)(Ad' + B.2)\\ i\n\n* If the coefficients in the quartic are real, the factorisation can\nbe carried out so that the coefficients in .Sj and So are real. In the\nspecial case of the quartic having four real linear factors, these\nfactors should be associated in pairs (to give Sj and S2) in such a\nwaj* that the roots of one pair do not interlace the roots of the\nother pair; tlie reason for this will be seen in the note at the end\nof the section.\n\nt Unless ttj; 02 = 1 : \\&2i i\" which case\n\nSi ai x-a) + Bi, S., = ao x - a) + Bo.\n\nt It is rather remarkable that Jacobi did not realise the existence of\nthis homographic substitution; in his reduction he employed a\nquadratic substitution, equivalent to the result of applying a Landen\ntransformation to the elliptic functions which we shall introduce.\n\n%\n% 515\n%\n\nIf we write R x) in the form ± (a - /3) R (t), where R is rational, we\nget\n\nfRi (x) dx \\ r R., (t) dt\n\n-' ~f (A,t' + B,)(A,t'+B,)]i' Now R, (t) + R, (- t) ~ 2R, tr), R, t) -\nR, (- t) = 2tR, t% where R and R are rational functions of t-, and so\n\nRo (t) = R, (f ) + tR, (t ).\n\nBut l (A,t;' + B,)(A.J' + Bo) tR, t\")dt\n\ncan be evaluated in terms of elementary functions by taking t\" as a\nnew variable*; so that, if we put Ri t') into partial fractions, the\nproblem of\n\nintegrating I R (tv, x) dx has been reduced to the integration of\nintegrals of the following types :\n\n f A,P + B,) A,t' + B,)] - dt,\n\n[(1 + m y A,t' + B,) A,t' + B,)] - dt;\n\nin the former of these m is an integer, in the latter m is a positive\ninteger andi\\ \\ 0.\n\nBy differentiating expressions of the form\n\nt? -' [ A,t + B,) A.J- + i?,)]*, t (1 + m y- [ A,i:' + B,) A,t' +\n5,);i,\n\nit is easy to obtain reduction formulae by means of which the above\nintegrals can be expressed in terms of one of the three canonical\nforms :\n\n(i) [ A,t + B,) A,P + B.;)]-idt, (ii) 1 [(.4, + B,) A,t- + B,)] -Ut,\n\n(iii) [(1 + m )-' (A,t' + B,) A,r- + 5,) -idt.\n\nThese integrals were called by Legendref elliptic integrals of the\nfirst, second and thii'd kinds, respectively.\n\nThe elliptic integral of the first kind presents no difficulty, as it\ncan be integrated at once by a substitution based on the integral\nformulae of §§22121, 22-122; thus, if A B A., B., are all positive and\nA B,>A,B., we write\n\nA, t = Bi cs (u, k). [k'-' = (A,B,)/(A,B,).]\n\n* See, e.g., Hardy, Integration of Functions of a single Variable\n(Camb. Math. Tracts, No. 2). t Exercices de Calcul Integral, i.\n(Paris, 1811), p. 19.\n\n. 33-2\n\n%\n% 516\n%\n\nExample 1. Verify that, in the case of real integi'als, the following\nscheme gives all possible essentially diflerent arrangements of sign,\nand determine the appropriate substitutions necessary to evaluate the\ncorresponding integrals.\n\n 1\n\n+\n\n+\n\n-\n\n+\n\n+\n\n-\n\nA\n\n+\n\n-\n\n+\n\n-\n\n-\n\n+\n\nA,\n\n+\n\n+\n\n+\n\n+\n\n-\n\n-\n\n1\n\n+\n\n+\n\n+\n\n-\n\n+\n\n+ :\n\n1- cd u\n\nExample 2. Shew that\n\nI sn \\ i du = -rr log r-,,,\n\nI dmidu = a.m u,\n\nI en u du = k~ arc tan k sd u),\n\n1, dn?i + X-'\n\n/\n\n,, 1, 1 - en ?\n\nas udu = - log -,\n\n2 °l+cnM'\n\nI sc udu=z, log '-. J-,,\n\nI A 7 1 1 1 + sn ?i\n\nI dc 2( du - ~ log,,\n\n] 2 ° 1 - sn M '\n\nand obtain six similar formulae by writing u- K for u.\n\n\\addexamplecitation{Glaisher.}\n\nExample 3. Prove, by differentiation, the equivalence of the following\ntwelve expressions :\n\nn - Ifi \\ \\&vr n du, J dn- M du,\n\n// tf + dn u%cu - l<!''-\\ vi.o''udu, dn tt sc - 2 J gc2 j (j 2(\n\nM + P sn M cd - F Jcd u du,\n\nk\"- It - dn ?; cs M - Jds- u du,\n\nExample 4. Shew that\n\n'!\" = n (n - 1) sn --' u - n- (\\ + k-) sn\" u + n (n + 1) F- sn + 2 du-\n\nand obtain eleven similar formulae for the second differential\ncoefficients of en\" ?i,\n\ndn\" ? ... nd\"M. What is the connexion between these formulae and the\nreduction\n\nformula for \\ t'' Ait' - Bi) A2fi + Bo)]~ dt]\n\n\\addexamplecitation{Jacobi; and Glaisher, Messenger, xi.}\n\nExample 5. By means of § 206 shew that, if a and;3 are positive.\n\nk'- u + k- I en- u du,\n\nu - dmi cs u - j ns- u du,\n\nk sn % cd it + kf Jnd xi dti,\n\nk\" u + k SQU cdu + P k\" j sd - z< du,\n\n- dn u cs ? - J cs'' u du,\n\nu + dn w sc M - I\" dc u du.\n\ni:\n\n i\n\n-a ./ <>,\n\nwhere e is the real root of the cubic and\n\n92 = .2 a - 'f-a' ', 93= - a'- ') a - 2)2 -36a2/32 /216; and prove\nthat, if 2 = 0, then a and are given by the equations\n\na- - - = - 3 (2 3)4, d' + /a2 = 2 /3 . I 2g3 |* .\n\n%\n% 517\n%\n\nExample 6. Deduce from example 5, combined with the integral formula\nfor en m, that, if g-i is positive,\n\nwhere a2 = (V3-f) (2 3)*, /32 = (v/3 + f) (2 3)*, and the modulus is\na(aH )\" -\n\n\\Subsection{22}{7}{3}{The elliptic integral of the second kind. The function* E(u).}\nTo reduce an integral of the type\n\njf' (A,t' + B,) (A,t + B,)l - idt,\n\nwe employ the same elliptic function substitution as in the case of\nthat elliptic integral of the first kind which has the same expression\nunder the radical. We are thus led to one of the twelve integrals\n\njsn udu, icn udu, ... jnd' udu.\n\nBy \\hardsubsectionref{22}{7}{2} example 3, these are all expressible in terms of u,\nelliptic functions of u and Jdn-udu; it is convenient to regard\n\nfu\n\nE(ii) = dn- udu\n\nJo\n\nas the fundamental elliptic integral of the second kind, in terms of\nwhich all others can be expressed; when the modulus has to be\nemphasized, we write E u, k) in place oi E u).\n\nWe observe that\n\ndE(it)\n\ndu\n\n= dn-u, E 0) = 0.\n\nFurther, since dn u is an even function with double poles at the\npoints 2mK + (2n + l)iK, the residue at each pole being zero, it is\neasy to see that E(u) is an odd one-valuedf function of u with simple\npoles at the poles of dn u.\n\nIt will now be shewn that E () may be expressed in terms of Theta-\nfunctions; the most convenient type to employ is the function (u).\n\n °'''''' '' m %U\\ '\n\nit is a doubly-periodic function of u with double poles at the zeros\nof © (u), i.e. at the poles of dn u, and so, if A be a suitably chosen\nconstant,\n\ndn-u - A - -,; ' du (©(z<.)\n\n* This notation was introduced by Jacobi, Journal fiir Math. iv.\n(1829), p. 373 [Ges. Werke, I. (1881), p. 299J. In the Fundamenta\nNova, he wrote E (am u) where we write E (u).\n\n+ Since the residues of dn m are zero, the integral defining E u) is\nindependent of the path chosen \\hardsectionref{6}{1}).\n\n%\n% 518\n%\n\nis a doubly-periodic function of u, with periods 2K, 2 K', with only a\nsingle\n\nsimple pole in any cell. It is therefore a constant; this constant is\nusually\n\nwritten in the form JE/K. To determine the constant A, we observe that\n\nthe principal part of dn- u at iK' is - (u - iK')~, by \\hardsubsubsectionref{22}{3}{4}{1}; and\nthe\n\nresidue of \\&' (u)IS (u) at this pole is unity, so the principal part\nof\n\nd 10'(u)) . \\ .,\n\n-y- <,, ' y IS - n - iK ) -. Hence yi = 1, so\n\ndu [yd u))\n\nIntegrating and observing that H' (0) = 0, we get E (w) = ©' (;f )/0\n(w) + tiEjK. Since ©' K) = 0, we have E (K) = E; hence\n\nE=( dn- ucZw=r (l-k'sm\"-0dcf> = l7rF(-l, ~; 1; kA .\n\nIt is usual (cf.\\hardsectionref{22}{3}) to call K and E the complete elliptic\nintegrals of the first and second kinds. Tables of them qua functions\nof the modular angle are given by Legendre, Fonctions Elliptiques, ii.\n\nExample 1. Shew that E u + 2nK)= E ti) + 2nE, where n is any integer.\n\nExample 2. By expressing e u) in terms of the function 9 ( irulK), and\nexpanding about the point u = iK', shew that\n\n = (2-P-V7W5i') ir.\n\n\\Subsubsection{22}{7}{3}{1}{The Zeta-f unction Z (w).}\n\nThe function E (u) is not periodic in either 2K or in 2iK', but,\nassociated with these periods, it has additive constants 2E, 2iK'E -\n7ri]/K; it is convenient to have a function of the same general type\nas E u) which is singly-periodic, and such a function is\n\nZ (u) = ©' (m)/© (u); from this definition, we have*\n\nZ (u) = E (ti) - uE/K, © (m) = © (0) exp I j\" Z t) dt\\ .\n\n\\Subsubsection{22}{7}{3}{2}{The addition-formulae for E u) and Z u).}\n\nConsider the expression\n\ne'(u + v) ©'(m) W(v),,,\n\n-- ' / - T TT x - /-v / + f ' sn u sn V sn u + v)\n\n@(u + v) ©(m) S v)\n\n* The integral in the expression for (u) is not one-valued as Z (f)\nhas residue 1 at its poles; bat the difference of the integrals taken\nalong any two paths with the same end points is 2/i7r/ where n is the\nnumber of poles enclosed, and the exponential of the integral is\ntherefore one- valued, as it should be, since 0(m) is one-valued.\n\n%\n% 519\n%\n\nqua function of m. It is doubly-periodic* (periods 2if and 2iK') with\nsimple poles congruent to iK' and to iK' - v; the residue of the\nfirst two terms at iK' is - 1, and the residue of sn u sn v sn (u + v)\nis k~ sn v sn (iK' + v) = k~ .\n\nHence the function is doubly-periodic and has no poles at points\ncongruent to iK' or (similarly) at points congruent to iK' - v. By\nLiouville's theorem, it is therefore a constant, and, putting u = 0,\nwe see that the constant is zero.\n\nHence we have the addition-formulae\n\nZ (w) -f- Z (v) - Z(u+v) = k sn M sn V sn (?< + v),\n\nE(u) + E (v) - Eiu 4- v) = k sn u sn v sn u + v).\n\n[Note. Since Z u) and E (u) are not doubly- periodic, it is possible\nto prove that no algebraic relation can exist connecting them with sn\nu, en u and dn u, so these are not addition-theoreras in the strict\nsense t.]\n\n\\Subsubsection{22}{7}{3}{3}{Jacobi's imaginary transformation\\ of7i u).}\n\nFrom \\hardsubsectionref{21}{5}{1} it is fairly evident that there must be a transformation\nof Jacobi's type for the function Z ii). To obtain it, we translate\nthe formula\n\n 2 ix i t) = (- ir) exp (- iTX /ir) . 4 (ixr \\ r) into Jacobi's\nearlier notation, when it becomes\n\nH (iu + K, k) = (- ir)i exp (\\ (, k'),\n\nand hence\n\n/ Tru-\" \\ 4 (0 I t) © (u, k')\n\nen (in, k) = (- V)* exp ( j\n\nTaking the logarithmic ditferential of each side, we get, on making\nuse of \\hardsectionref{22}{4},\n\nZ iu, k) = i dn (u, k') sc u, k') - iTj u, k') - 7riu/(2KK').\n\n22 734. Jacobi's imaginary transformation of E(u).\n\nIt is convenient to obtain the transformation of E (u) directly from\nthe integral definition; we have\n\nE (in, k) = I \"dn- t, k) dt=\\ dn- (it', k) idt'\n\nJo Jo\n\n= i dc- (t', k') dt', ]\n\non writing t - it' and making use of § 22 \"4.\n\n* 2iK' is a j eriod since the additive constants for the first two\nterms cancel.\n\nt A theorem due to Weierstrass states that an analytic function,/ (2),\npossessing an addition- theorem in the strict sense must be either\n\n(i) an algebraic function of z, or (ii) an algebraic function of exp\n(Trizjw),\n\nor (iiij an algebraic function of (2 | wi, W2) J\n\nwhere w, wj, W2 are suitably chosen constants. See Forsyth, Theory of\nFunctions (1918), Ch. xiii.\n\nJ Fundamenta Nova, p. 161.\n\n%\n% 520\n%\n\nHence, from \\hardsubsectionref{22}{7}{2} example 3, we have\n\nE hi, k) = i \\ u + dn u, k') sc (, k') - \\ dn= t', k') dt' [,\n\nand so E iu, k) = iu + i dn u, k') sc u, k') - iE u, k').\n\nThis is the transformation stated.\n\nIt is convenient to write E' to denote the same function of k' as E is\nof k, i.e. E' = E(K', k'X so that\n\nE 2 K',k) = 2i(K' -E').\n\n\\Subsubsection{22}{7}{3}{5}{Legendre's relation*.}\n\nFrom the transformations of E u) and Z u) just obtained, it is\npossible to derive a remarkable relation connecting the two kinds of\ncomplete elliptic integrals, namely\n\nEK' + E'K-EK' = \\ ir.\n\nFor we have, by the transformations of §§ 22\"733, 22*734,\n\nE iu, k) - Z iu, k) = iu - i [E u, k') - Z u, k')\\ + '7riu/ 2KK'),\n\nand on making use of the connexion between the functions E u, k) and Z\nu, k), this gives\n\niuE/K = iu - i [uE'jK'] + 'Triu/ 2KK'). Since we may take m =| 0, the\nresult stated follows at once ft-om this equation; it is the analogue\nof the relation rj coo - Vzf i = 9 tJ\"* which arose in the\nWeierstrassian theory (§ 2041 1). Example 1. Shew that\n\nE u + K)-F ii) = E-k-mucdu. Example 2. Shew that\n\nE(2u + 2iK') E (2u) + 2i K' - E'). Example 3. Deduce from example 2\nthat\n\nE ti + iK') = E 2u + 2iK') + W sn ( u + iK') sn (2m + 2iK') = E (u)\n-fen M ds M + i (A\" - £\"). Example 4. Shew that\n\nE u + K+ iK') = E (u) - sn u dc u + E+i E' - E'). Example 5. Obtain\nthe expansions, vaHd when | I x) l< 7r/(T),\n\n/7 r'NO o tt;,'T-, o ' iw\" COS 2ii.r . -, °° Q' s\\ Vi2nx n=i q \" n=\\\n1-?''\"\n\n\\addexamplecitation{Jacobi.}\n\n* Exercices de Calcul Integral, i. (1811), p. 01. For a geometrical\nproof see Glaisher, Messenger, iv. (1874), pp. 95-96,\n\n%\n% 521\n%\n\n\\Subsubsection{22}{7}{3}{6}{Properties of the complete elliptic integrals, regarded as functions of the modulus.}\n\nIf, in the formulae B=\\ (1 - k sin (f)y d<f>, we differentiate under\nthe\n\nJo\n\nL \\hardsectionref{4}{2}), we have\n\nfh . . \\ i E-\n\n= - I k sm- (f) (1 - k\" sm (f)) -d(J3 = - j-\n\nJ K\n\nDrmula for K in the same manner, we ha'\n\n= ' sin- < ( 1 -  ' sm\" (j>) d(f) = k \\ sd u di\n\nJ a Jo\n\nsign of integration \\hardsectionref{4}{2} ), we have\n\ndE fh, . . . .., . ..\\ ! .. E-K\n\ndk\n\nTreating the formula for K in the same manner, we have\n\ndJ dk\n\nK\n\njLj/ dn'u*,.-\n\nk!''-u\n\nby \\hardsubsectionref{22}{7}{2} example 3; so that\n\ndk kk'- k If we write k- = c, k'-= c', these results assume the forms\ndE E-K dK E-Kc' dc c dc cc\n\nExample 1. Shew that\n\n dE K'~E' 2 = cK'-E'\n\ndc c' ' dc cc'\n\nExample 2. Shew, by difterentiation with regard to c, that EK' + E'K -\nKK' is constant.\n\nExample 3. Shew that K and K' are solutions of\n\nd dk\n\nand that E and E' - K' are sohitions of\n\n|m' | |= ..,\n\n '\" ~M- \\ \\ 'M ' ~ ' (Legendre. )\n\n\\Subsubsection{22}{7}{3}{7}{The values of the complete elliptic integrals for small values of k. }\nFrom the integral definitions of E and K it is easy to see, by\nexpanding in powers of k, that\n\nlim K = lim E l-TT, lim (K - E)lk' = tt.\n\nIn like manner, lim E' = I cos (f)d(j) = 1.\n\nk- -o J\n\nIt is not possible to determine lim/i' in the same way because\n\nfc O\n\n(1 - '-sin ( )\" 2 is discontinuous at </> = 0, k =; but it follows\nfrom example 21 of Chapter xiv (p. 299) that, when | argA- 1 < tt,\n\nlim i '-log(4/ )l=0.\n\n%\n% 522\n%\n\nThis result is also deducible from the formulae 2iK' = -!TT i, k .\njBi, by making q-*-0; or it may be proved for real values of k by the\nfollowing elementary method :\n\nBy \\hardsubsectionref{22}{3}{2}. A\" = / f- - k-) ' l-t')' dt; now, when / < < Jk, l-t-)\nlies between\n\n1 and 1-/-; and, when s,'k<t<\\ \\ fi-k )/t lies between 1 and 1 ~k.\nTherefore A'' lies between\n\nJk i /A-\n\nand (i-/.)-*]/\" ( 2\\ .2)-ij;+ / t-- l-f- )-hdt\\;\n\nand therefore\n\nA =(1 - 6k) ijlog log 1-- /(i l.\n\n= (1 - Ok) - h [2 log 1 + v'(l - k) - log /], where 0 1.\n\nXow lira [2 (1 - Ok) ' i log 1 + v/(l - k) - log 4] = 0,\n\n\\ \\ m I - I - 6k) - log k = 0,\n\nand therefore lim A' - log (4/),-) = 0,\n\nwhich is the required result.\n\nExample. Deduce Legendre's relation from \\hardsubsubsectionref{22}{7}{3}{6} example 2, by making\nk- 0.\n\n\\Subsection{22}{7}{4}{The elliptic integral of the third kind*.}\nTo evaluate an\nintegral of the type\n\nf(l + Nt')-' A,P + B,) A,t'+B. ] - dt\n\n/<\n\nin terms of known functions, we make the substitution made in the\ncorre- sponding integrals of the first and second kinds (§§ 22*72,\n22\"73). The integral is thereby reduced to\n\nI -- du = ait + (p - av) - du,\n\nwhere or, yS, v are constants; if i = 0, - 1, x or - the integral\ncan be expressed in terais of integrals of the first and second kinds\n; for other values of V we determine the parameter a by the equation v\n= - k sn- a, and then it is evidentl ' permissible to take as the\nfundamental integral of the third kind\n\n, [ k-snacn a dn a sn' u,\n\nn (u, a) = - j~. - du.\n\n  Jo 1 - k sn a sn u\n\nTo express this in terms of Theta-functions, we observe that the inte-\ngrand may be written in the form\n\nI k- sn u sn a sn (u + a) -1- sn (u - ) = ( (\" - ) - (\" + a) + 2Z (a)\n,\n\n* Legendre, Exercices de Calcul Integral, i. (1811), p. 17; Fonctions\nEUiptiques, i. (1825), pp. 14-18, 74, 75; Jacobi, Fundamenta Nova\n(1829), pp. 137-172; we employ Jacobi's notation, not Legendre's.\n\n%\n% 523\n%\n\nby the addition-theorem for the Zeta-fimction; making use of the\nformula Z (i() = B'(m)/ (u), we at once get\n\na result which shews that U(u, a) is a many- valued function of u with\nlogarithmic singularities at the zeros of @ (u ± a).\n\nExample 1. Obtain the addition-formula*\n\ne (u+v + a) e ( tt-g) e (v -a)\n\nn u, a)+n v, a)-niu+v, ) = iloge( +.,-a)e( -ha)e( + )\n\nj 1 - Psnasn - sn-?;sn (tc + v - a) ~2 °\"l + Psn asnwsnvsn (w + v +\na)'\n\n\\addexamplecitation{Legendre.}\n\n(Take a- : y : s : tf = m : w : ± a : i( -h r ± a in Jacobi's\nfundamental formula\n\n[4] + [l] = [4]'-r[l]'.)\n\n-Example 2. Shew that\n\nn u, a) - n (a, m) = uZ (a) - aZ (tt).\n\n\\addexamplecitation{Legendre and Jacobi.}\n\n[This is known as the formula for interchange of argument and\nparameter.]\n\nExample 3. Shew that\n\nl-PsnaHnbsnuHn a + b-u) n (iL a) + n hi, h) - n (u, a + b) = i log \\,\n- j r -. -, i,,,\\\n\n+ uk sn a sn 6 sn (a 4- 6).\n\n\\addexamplecitation{Jacobi.} [This is known as the formula for addition of parameters.]\n\nExample 4. Shew that\n\nIT iio, ia + /i, k) = Il u,a + K\\ k'). \\addexamplecitation{Jacobi.}\n\nExample 5. Shew that\n\nn (m + v, a-irb) + n (u-v, a-b)-2n u, a)-2U v, b)\n\n,,,, l-Fsn2(2<-a)sn2(i;-6) = - F sn a sn 6 . (u + v) sn (a -f b) -\n(w - y) sn ( - 6) -H i log i + 2 . 2 (;,,) s ( + 6) '\n\nand obtain special forms of this result by putting v or h equal to\nzero. \\addexamplecitation{Jacobi.}\n\n22 741. A dynamical application of the elliptic integral of the third\nkind. It is evident from the expression for n (m, a) in terms of\nTheta- functions that if u, a, k are real, the average rate of\nincrease of n (m, a) as u increases is Z (a), since 9 ii±a) is\nperiodic with resjject to the real period 2K.\n\nThis result determines the mean precession about the invariable line\nin the motion of a rigid body relative to its centre of gravity under\nforces whose resultant passes through its centre of gravity. It is\nevident that, for purposes of computation, a result of this nature is\npreferable to the corresponding result in terms of Sigma-functions and\nWeierstrassian Zeta-functions, for the reasons that the\nTheta-functious have a specially simple behaviour with respect to\ntheir real period - the period which is of importance in Applied\nMathe- matics - and that the -series are much better adapted for\ncomputation than the product by which the Sigma-function is most\nsimply defined.\n\n* No fewer than 96 forms have been obtained for the expression on the\nright. See Glaisher, Messenger, x. (1881), p. 124.\n\n%\n% 524\n%\n\n\\Section{22}{8}{The lemniscate functions.}\n\nThe integral (1 - ) dt occurs in the problem of rectifying the arc of\n\nJo\n\nthe lemniscate*; if the integral be denoted by, we shall express the\nrelation between and x by writingi* x - sin lemn < .\n\nIn like manner, if\n\nJ X - .'\n\nwe write\n\nx = cos lemn j, and we have the relation\n\nsin lemn < = cos lemn ( tn- - ( j .\n\nThese lemniscate functions, which were the first functions:]: defined\nby the inversion of an integral, can easily be expressed in terms of\nelliptic functions with modulus l/VS; for, from the formula \\hardsubsubsectionref{22}{1}{2}{2}\nexample)\n\nr sd u u=\\ [ l-k' f) l+l: f)]-Uy,\n\n.\n\nit is easy to see (on writing y = t \\/2) that\n\nsin lemn = 2 \" sd (< \\/2, l/V ); similarly, cos lemn = en (</> V2, 1/\n2).\n\nFurther, is the smallest positive value of for which\n\ncn(< V2, 1/V2) = 0, so that OT=V2 o,\n\nthe suffix attached to the complete elliptic integral denoting that it\nis formed with the particular modulus l/\\/2.\n\nThis result renders it possible to express Kq in terms of\nGamma-functions,\n\nthus\n\nK,= 2 [ P)- -dt='2---\\ \\ u - l-u)- -di Jo Jo\n\na result first obtained by Legendre§.\n\nSince k = // when k = l/\\/2, it follows that 7 = 7iV. and so o = e \".\n\n* The equation of the lemniscate being r- = a' cos 26, it is easj' to\nderive the equation\n\n %)' = ar~* '' '\" ' ' ' \" \" tj= 1 + (1-)'\n\nt Gauss wrote si and cl for siu lemn and cos lemn, Werke, iii. (1876),\np. 493.\n\nt Gauss, Werke, iii. (187(5), p. 40i. The idea of investigating the\nfunctions occurred to Gauss on January 8, 1797.\n\n§ Exercices de Calcul Integral, i. (Paris, 1811), p. 209. The value of\nKq is 1-85407468... while 07 = 2-62205756....\n\n%\n% 525\n%\n\nExample . Express A'o in terms of Gamma-fuuctions by usiug Kummer's\nformula (see Chapter xiv, example 12, p. 298).\n\nExample 2. By writing t = \\ -m ) j the formula\n\nshew that 2 o = / ( 1 - ?**) ' du+T u l- ic*) ~ i du,\n\nand deduce that 2 o - J o = Stt r ( j) ~ 2,\n\nExample 3. Deduce Legendre's relation \\hardsubsubsectionref{22}{7}{3}{5}) from example 2\ncombined with \\hardsubsubsectionref{22}{7}{3}{6} example 2.\n\nExample 4. Shew that\n\n.,, 1 - cos lemn (b\n\nsm Iemn2d) = - --t- .\n\nH-coslemn''9\n\n\\Subsection{22}{8}{1}{The values of K and K' for special values of k.}\n\nIt has been seen that, when k=ljJ2, K can be evaluated in terms of\nGamma-functions, and K=E'; this is a special case of a general\ntheorem* that, whenever\n\nE' \\ a + hjn E c + djn'' where, b, c, d, n are integers, k is a root\nof an algebraic equation with integral coefficients.\n\nThis theorem is based on the theory of the transformation of elliptic\nfunctions and is beyond the scope of this book; but there are three\ndistinct cases in which k, 7i, E' all have fairly simj le values,\nnamely\n\n(I) >(- = V2-l, E' = EJ2,\n\n(II) k = Hm 7r, E' = E %\n\n(III) k=tsin 7r, E' 2E. Of these we shall give a brief investigation\nt.\n\n(I) The quarter-periods with the modulus /2 - 1.\n\nLanden's transformation gives a relation between elliptic functions\nwith any modulus k and those with modulus ki = l - k')/ l+k'); and the\nquarter-periods A, A' associated with the modulus k satisfy the\nrelation A'/a = 2E'/E.\n\nIf we choose k so that ky = k', then A = /i'' and k = k so that i. ' =\nE; and the relation A7A=2A'7A'gives A'2=2a2.\n\nTherefore the quarter-periods A, A' associated with the modulus k-\ngiven by the equation i = (l - i)/(l-|-X-i) are such that A'=±Av/2;\ni.e. \\ i ki = l2-\\, then A' = Av/2 (since A, A' obviously are both\npositive).\n\n(II) The quarter-periods associated ivith the modidus sin y tt.\n\nThe case of k = s,\\ n -rrr was discussed by Legendre|; he obtained the\nremarkable result that, with this value of k,\n\nE' = Ey/3.\n\n* Abel, Journal fiir Math. in. p. 184 [Oeuvres, i. (1881), p. 377].\n\nt For some similar formulae of a less simple nature, see Kronecker,\nBerliner Sitzungsherichte, 1857, 1862.\n\nX Exercices de Calcul Integral, i. (1811), pp. 59, 210; Fonctions\nElliptiques, i. (1825), pp. 59, 60.\n\n%\n% 526\n%\n\nThis result follows from the relation between detinite integi-als\n\nTo obtain this relation, consider l l-z )~ dz taken round the contour\nformed by the part of the real axis (indented at s=l by an arc of\nradius R' ) joining the points and B the line joining e*\"' to and the\narc of radius B joining the points R and Re \"\"; as R a:, the\nintegral round the arc tends to zero, as does the integral round the\nindentation, and so, by Cauchy's theorem,\n\non writing .v and e*'\"* respectively for z on the two straight lines.\nWriting [\\ l-x )- -dx = Ii, j\\ x- -l)- dx = L, j\\ l+.f )-- ds=j\\ l-x\n)- dx I\n\nwe have /j + iV. = 4 (1 + is/S) h;\n\nso, equating real and imaginary parts,\n\nA = 5- 3 5 - 2 = 5- 3X 3,\n\nand therefore h-V I - Lis'' = \\ h + h-¥i=\n\nwhich is the relation stated*. Now, by \\hardsubsectionref{22}{7}{2} example 6,\n\n/2 = 4(a2 + 2)-*£', / + /3 = 4(a2 + /32)-4 ',\n\nwhere the modulus is a d' + ) ~ and\n\na2=2v3-3, /32 = 2V3 + 3, so that, > :2 = i(2-V3) = sin2Js7r.\n\nWe therefore have\n\n3-i. 2/1 = 3-2. 2 ' = /2 = 3 /i\n\n= 3- |V\"s(i- )-ic =i,r r(J)/r(|),\n\nwhen the modulus k is sin jV -\n\n(III) The quarter-periods iiith the modtdus tan -i-Tr.\n\nIf, in Landen's transformation \\hardsubsectionref{22}{4}{2}), we take l::=i; '2, we have\nA'/A=2K'/K=2;\n\nnow this value of k gives\n\n7 V -1 . \"1\n\nand the corresponding quarter-periods \\, A' are |(1 + 2 ) A'o and (1 +\n2 ) Kq.\n\nExample 1. Discuss the quarter-i)eriods when k has the values\n(2;,y2-2), sin f 7r, and 2 ( 2-1).\n\n* Another method of obtaining the relation is to express Ij, I, h in\nterms of Gamma- functions by writing t, t~, ( -' - 1)* respectively\nfor x in the integrals by which Ii, I2, I3 are defined.\n\n%\n% 527\n%\n\nExample 2. Shew that\n\n?l = )i = l\n\n\\addexamplecitation{Glaisher, Messenger, v.}\nExample 3. Express the coordinates of any\npoint on the curve y =ofi- 1 in the form\n\n1 3\n\n3 (1- en u) \\ 2.3 snMdnM\n\n ~ l+cn?< ' ' ~ (l + cnM)2 '\n\nwhere the moduhis of the eUiptic functions is sin jV\"\", and shew that\n-=- = ~ iy.\n\nBy considering / y~ dx = 3~* I die, evahiate K in terms of\nGamma-functions when\n\nExample 4. Shew that, when y' =x -l,\n\nr y-Hx-lYdx=[- y- l-x-' fl +' T x~ y- -x-h/- )dx;\n\n7 1 L ' Ji ' y 1\n\nand thence, by using example 3 and expressing the last integral in\nterms of Gamma- functions by the substitution x = t~, obtain the\nformula of Legendre Calcul Integral, p. 60) connecting the first and\nsecond complete elliptic integrals with modulus sin jJjtt:\n\nExample 5. By expressing the coordinates of any point on the curve Y'\n= X in the form\n\n \\ 32(l-cnv) \\ 2. 3*sn vdn??\n\n1+cni? ' (1-l-cn ') '\n\nin which the modulus of the elliptic functions is sin y tt, and\nevaluating\n\n />/\n\nY- XfdX\n\nin terms of Gamma-functions, obtain Legendre's result that*, when k sm\nw,\n\n\\Subsection{22}{8}{2}{A geometrical illustration of tlie functions sn u, en ii, dn u.}\n\nA geometrical representation of Jacobian elliptic functions with\nk=ljJ2 is afforded by the arc of the lemniscate, as has been seen in §\n22\"8; to represent the Jacobian functions with any modulus k 0 <k < )\n, we may make use of a curve described on a sphere, known as Seifferfs\nspherical spiral .\n\nTake a sphere of radius unity with centre at the origin, and let the\ncylindrical polar coordinates of any point on it l e (p,, z), so that\nthe arc of a curve traced on the sphere is given by the formula \\\n\n dsr =pHdcf>y+ i-p )- dpy.\n\n* It is interesting to observe that, when Legendre had proved by\ndifferentiation that EK' + E'K- KK' is constant, he used the results\nof examples 4 and 5 to determine the constant, before using the\nmethods of \\hardsectionref{22}{8} example 3 and of \\hardsubsubsectionref{22}{7}{3}{7}.\n\nt Seiffert, Ueher eine neue geometrische Eiiifilhrung in die Theorie\nder elliptisclien Funktiunen (Charlottenburg, 1896).\n\nX This is an obvious transformation of the formula ds)\"= dp)' + p'\n(d(p)~ + dz) when p and z are connected by the relation p' + z'- - l.\n\n%\n% 528\n%\n\nSeiffert's spiral is defined by the equation\n\n(f) = ks,\n\nwhere s is the arc measured from the pole of the sphere (i.e. the\npoint where the axis of s meets the sphere) and k is a positive\nconstant, less than unity*.\n\nFor this curve we have\n\nand so, since s and p vanish together,\n\np = sn (s, k).\n\nThe cylindrical polar coordinates of any point on the curve expressed\nin terms of the arc measured from the pole are therefore\n\n p, cf), z) = (sn s, /ts, en s);\n\nand dn s is easily seen to be the cosine of the angle at which the\ncurve cuts the meridian. Hence it may be seen that, if K be the arc of\nthe curve from the pole to the equator, then sn s and cu s have period\nAK, while dn 6* has period 2K.\n\nREFERENCES.\n\nA. M. Legendre, Traite des Fonctions Elliptiques (Paris, 1825-1828).\n\nC. G. J. Jacobi, F\\ hiidamenta Nova Theoriae Functionv.m Ellipticanim\n(Konigsberg, 1829).\n\nJ. Tannery et J. Molk, Fonctions Elliptiques (Paris, 1893-1902).\n\nA. Cayley, Elliptic Functions (London, 1895).\n\nP. F. Verhulst, Traite eUmentaire des fonctions elliptiques (Brussels,\n1841).\n\nA. Enneper, Elliptische Funktionen, Zweite Auflage von F. Miiller\n(Halle, 1890).\n\nMiscellaneous Examples.\n\n1. Shew that one of the values of\n\n11 1 1\n\ndnM + cnwV- /dn w-cn wV'j U l-sn% / l + sni* \\ \\ '\\\n\nl+cn?t / \\ - cnn J ) \\ \\ dinu - k'su.u) \\ 6.nu + k' snu) J\n\nis 2 (1 +k'). \\addexamplecitation{Math. Trip. 1904.}\n\n2. li x + iy = sn\" ( u + iv) and x - iy - sn (% - iv), shew that\n\n ( -l)2+2/- - = ( -+y ) dn22( + cn2w.\n\n\\addexamplecitation{Math. Trip. 1911.}\n\n3. Shew that\n\n l±cn( + .) l±cn( -i;) = /'-'?/= . 1 - '= sn w sn- V\n\n4. Shew that\n\n, cn u + cn V\n\n1 +cn (w + v) en u-v) = - - -p, - 5- .\n\n  1 - A: sn-M sn V\n\n\\addexamplecitation{Jacobi.} * If fc>l, the curve is imaginary.\n\n%\n% 529\n%\n\np \\ + cn(ti + v)cn(u-v) r . c o, i\n\n5. Express - \\ (-; - 7 ( as a function or sn-'w + sn v.\n\n   + an u + v)axi(u - v)\n\n6. Shew that\n\n7. Shew that\n\nsn u - v) dn u + v) =\n\n\\addexamplecitation{Math. Trip. 1909.}\nsn M dn -M en V - sn v dn i? en u\n\n1 - 2 sn\" u su\" r\n\n\\addexamplecitation{Jacobi.}\n\n    + k')s,r).us,n u- E)) l~ k') sn m sn u + K)] = su ( . + ) - sn uf.\n\n\\addexamplecitation{Math. Trip. 1914.}\n\n8. Shew that\n\n9. Shew that\n\nsn (i< + |iA''') =\n\n(1 -/(:')\n\n\\ 1 (1 + ) sn M + en w dni< 1 + sn M\n\n.,,,,,, 2sn?icnMdnv\n\nsm am i,, + v) + - m u-v) j-j,~,\n\n,, ., ., cn V - sn V dn m\n\ncos am u + v)- m ( - )H 2 3 2,,s 2\n\n\\addexamplecitation{Jacobi.}\n\n10. Shew that and hence express\n\ndn u+v) dn u - v) =\n\nds2?ids- v + F '2\n\nns ?i ns V - -2 '\n\n(u + v) - €2 iP u - vj - e-\n\nas a rational function of ip u) and v). \\addexamplecitation{Trinity, 1903.}\n\n11. From the formulae for cn(2 - ) and diW 2K-u) combined with the\nformulae for 1 +cn 2u and l + dnSw, shew that\n\n(l-cn|ir)(H-dn§ ) = l. \\addexamplecitation{Trinity, 1906.}\n\n12. With notation similar to that of \\hardsectionref{22}{2}, shew that\n\nCi d-i - c<idx en ( i + u-i) - dn ( Mj + 2) Sj-sa sn( i4- 2)\n\nand deduce that, if Mi + (/o f-% + '4 = 2A', then\n\n(Ci 0?9 - C2 0?i) (C3 c/4 - C4 ( 3) = 2 (sj \\ s.,) (S3 - S4).\n\n\\addexamplecitation{Trinity, 1906.}\n\n13. Shew that, if u + i + ?r = 0, then\n\n1 - dn XL - dn v - dn-  + 2 dn m dn v dn u'=k* sn ?< sn v sn m;.\n\n\\addexamplecitation{Math. Trip. 1907.}\n\n14. By Liouville's theorem or otherwise, shew that\n\ndn?< dn u + w)-dn <;dn v + w) = k sn yen u sn (v + w) en (u + w)\n\n- snMcn vsn u + xo) en (y +;) .\n\n\\addexamplecitation{Math. Trip. 1910.}\n\n15. Shew that\n\n2 en Uo en u sn (?<2 - %) dn Mj + sn ( 2 - M3) sn (W3 - ?<i) sn (i<i -\nMo) dn ?ii dn Mo dn % = 0, the summation applying to the suffices 1,\n2, 3. \\addexamplecitation{Math. Trip. 1894.}\n\nW. M. A. 34\n\n%\n% 530\n%\n\n16. Obtain the formulae\n\nsn 3 = AID, cii 3?< = BjD, dn 'Mi = CLD, where = 3s - 4 ( 1 + /f- ) s\n+ Qk' s - k* s%\n\nB = c l-4:S + 6k s*-4kU' + k s,\n\nC=d l-4k s + 6/5-2 4 \\ 4X.2 c + ia gsx\n\nD = l- 6 -2 S-* + 4:k- ( 1 + /?;2) §0 - Zk s% and s = sn, c' = cni(,\nc/=dn;<.\n\n17. Shew that\n\n1 - dn 3u \\ / 1 - dn ?t\\ /I + a dn u + 02 dn u + c'3 dn ?< + a dn 1 +\ndn 'iu \\ l + dn tcj \\ l - aj dn ?< + 2 dn 14 - ag dn % + a dn* uj\nwhere Ui, ao, 3, a are constants to be determined. \\addexamplecitation{Trinity, 1912.}\n\n18. If\n\nshew that\n\n  . ., 1 + dn 3i( W + dn ?<\n\nP u) + F tt+2iK')\n\nsn 2u en u en 2m sn u '\n\nF u)-F u + 2iK')\n\nDetermine the poles and zeros of P (u) and the fii'st term in the\nexpansion of the function about each pole and zero.\n\n\\addexamplecitation{Math. Trip. 1908.}\n\n19. Shew that\n\nsn ui + U-2 + U3) = A/D, en ui + U2 + ii ) = BjD, dn ui + M2 + %) =\nC'/i), where\n\nA=SiSoSi - 1 --?-2 + 2F2V-('<'-' + -'') 252 532+ 2ytisi2s22 532)\n\n+ 2 s c.c dod i l + 2k' s.isi-B s. si)],\n\nB =CiC2Cs 1 - k 2s.2 S3 +2k*S S2 S-/\n\n+ 2 CiS2.?3O?20?3(- 1 +2Ps2 S32 + 2Fsi2-F25225g2))\n\nC = d,d2d3 l-P2s./ss' + 2F-s, s.2H:i\n\n+ F2 diS SsCoC-i ( - 1 +2/ -2s22s32 + 2Si2-F2S22532), D=l - 2P2S2'-\nS32 + 4 (F + F) Si2 2 3- \" 2k*Si S2-S3~2Si- + B2s.*S3*,\n\nand the summations refer to the suffices 1, 2, 3. (Glaisher,\nMessenger, xi.)\n\n20. Shew that\n\nsn (ui + W2 + '-s) = - '/D', en ui + U2 + its) = '/- 'j dn (u + U2 +\nu. ) = G'jD', where J' = 2siC2C3C 2 3--5iS2S3(l+ - 2si2+/\n;4si2s22s32),\n\n5' = Ci C2C3 (1 - * Si2s22 32) - di d d 'Ss s Ci di,\n\nC\" = 0?i C?2 0?3 ( 1 - F Si2 §22 S32) - F Cj C2 C3 2 2 S3 <?! C l,\n\nZ)' = l - F 25-22 S32 + (F + *) Si2s22s32-FsjS2S32SiC2C3C 2' 3-\n\n((/'ayley, Journal fur Matli. XLi.)\n\n21. By applying Abel's method \\hardsectionref{20}{3} 12) to the intersections of the\ntwisted curve;j72\\ |.y2\\ i 22 + F\\ .2\\ .i itii the variable plane Ix\n+ my + nz-l, shew that, if\n\n'Mi + M2 + % + 4 = 0j\n\nthen Si Ci d 1 =0.\n\n52 C2 2 1\n\n53 C3 0?3 1\n\n54 C4 0 4 1\n\nOVjtain this result also from the equation\n\n( 2 - i) ( 3 4 - 40 3) + ( 4 - s which may be proved by the method of\nexample 12.\n\n cid2~C2di) = 0,\n\n\\addexamplecitation{Cay ley, Messenger, xiv.}\n\n%\n% 531\n%\n\n22. Shew that\n\nby expressing each side in terms of Si, §2, s, s; and deduce from\nexample 21 that, if\n\nTODO\n\n\\addexamplecitation{Forsyth, Messenger, xiv.}\n\n23. Deduce from Jacobi's fundamental Theta-function formulae that, if\n\nUi + U.2 + M3 + M4 = 0,\n\nthen k'- - k k\"'si So S3 S4 4- k Ci c, c c - di d.2 d d = 0.\n\n\\addexamplecitation{Gudermann, Journal fur Math, xviii.}\n\n24. Deduce from Jacobi's fundamental Theta-function formulae that, if\n\nUl + U.2 + lt3 + Ui = 0,\n\nthen F (si S2 C3 C4 - Ci 6'2 S3 S4) - c ia?2 + < 3 0 4= 0,\n\nk' S1S2- 838 ) +did2C3Ci - CiC2d3di = 0,\n\n.SiS2C 3( 4 - did2S Si + C3C4 - Ci C2 = 0.\n\n(H. J. S. Smith, Proc. London Math. Soc. (1), x.)\n\n25. If Ui + Uo + n3-)rUi = 0, shew that the cross-ratio of sn Ui, sn\nUo, sn M3, sn ?<4 is equal to the cross-ratio of sn (u + K)., sn\nu-i+K), sn 11,3 + K\\ sn Ui + K).\n\n\\addexamplecitation{Math. Trip. 1905.}\n\n26. Shew that\n\niin ii,+v) sn (ji-f-y) sn (w- <;) fiTi? u-v), Sk\"' SiS2 CiC did\n\ncn2 (w -I- v) en (m -f v) en ( - v) en- (w - v) (, - 'Si S2 J\n\ndn' ( -|-i ) dn (m -t- 2 ) dn (?( - y) dn u - v)\n\n\\addexamplecitation{Math. Trip. 1913.}\n\n27. Find all systems of values of u and f for which iivi u + iv) is\nreal when u and y are real and 0<k-<. \\addexamplecitation{Math. Trip. 1901.}\n\n28. If k' = J a ~ - a)'-, where < a < 1, shew that\n\n' 1 r- 4a3\n\n \"(l-f-a2)(l + 2a-a- )'\n\nand that sn'- fiT is obtained by writing -a~ for a in this expression.\n\n\\addexamplecitation{Math. Trip. 1902.}\n\n29. If the values of en z, which are such that en 3z = a, are Cj, C2,\n... Cg, shew that\n\n9 9\n\n3k* n Cr + k'* 2 c,. = 0.\n\n\\addexamplecitation{Math. Trip. 1899.}\n\ny,. g-l-sn (M-l-y) \\ 6-|-cn( f-f y) \\ c + dn u + v)\n\na + su u - v) b + cn u - v) c + dii it - v)'\n\nand if none of snv, cnu, dnu, 1 - -' sn wsn y vanishes, shew that ti\nis given by the equation\n\nX-2 (t' d' + b''- c ) sn- u = k'-+k' b'' - c\\\n\n\\addexamplecitation{King's, 1900.}\n\n34- :i\n\n%\n% 532\n%\n\n31. Shew that\n\n\\addexamplecitation{Math. Trip. 1912.}\n\n32. Shew that\n\nl-sn(2 .r/7r)\n\n\"Jl-2j2n-lgin-j; + j4n-2\n\n dn 2KxlTr) - /;' sn (2A'j\n\n\\addexamplecitation{Math. Trip. 1904.}\n\n33. Shew that if k be so small that k may be neglected, then\n\nsn M = sin u - k-cosic. (t< - sin iccos u), for small values of ? .\n\\addexamplecitation{Trinity, 1904.}\n\n34. Shew that, if | / x) \\ < nl (r), then\n\n4j\" sin nx\n\nlog en (2 A'.r/Tr) = log cos .r - 2 -\n\n =iw l + (-?)\"\n\n\\addexamplecitation{Math. Trip. 1907.} [Integrate the Fourier series for sn (2A'' /7r)dc\n(2A'r/7r).]\n\n35. Shew that\n\ncn 71 dn'= m\n\n\\addexamplecitation{Math. Trip. 1906.} [Express the integrand in terms of functions of\n2u.]\n\n36. Shew that\n\n/cnvdu \\ . 5i (|a' + -| - i7r) i(| .r + 5y-|7r - -iTrr) i iZ + hirr)\nsnv-snT<~ Ml- - y) h il/ - i r) '* Ij y+i\" ) '\n\nwhere 2Kx = Tru, 2Ky=irv. \\addexamplecitation{Math. Trip. 1912.}\n\n37. Shew that\n\n  jo l+cuu)dn u\n\n\\addexamplecitation{Math. Trip. 1903.}\n\n,,' +,, l+X-snasn/3\n\nk I sn ?(a; = io2;\n\n38. Shew that\n\n/ I v'r -i/ /-/)/ - Irvnr\n\n1 - /;sn asn j3'\n\n\\addexamplecitation{St John's, 1914.}\n\n39. By integrating je ' dmicsudz round a rectangle whose corners are\n±i7r, ± ir + cci (where 2Kz = itii) and then integrating by parts,\nshew that, if </:- < 1, then\n\n\\ cos (iru/K) logsn t(,dii = K timh. ( irir). Jo'\n\n\\addexamplecitation{Math. Trip. 1902.}\n\n40. Shew that K and K' satisfy the equation\n\nc(l- ) + (l-2c) -i = 0,\n\nwhere c = 2. j j-kJ deduce that they satisfy Legendre's equation for\nfunctions of degree - with argument 1 - 2k' .\n\n%\n% 533\n%\n\n41. Express the coordinates of any point on the curve x +y =l in the\nform 2.3 snMdnM-(l-cn u) \\ 2 cos 3 tt (1 - on w) 1 + tan jLtt en u)\n\n2.3isn%dntt + (l-cn w)2 2. 3 snwdn m + (1 -cnw)'\n\nthe modulus of the elliptic functions being sin yV 't; and shew that\n\nJ X Jo\n\nShew further that the sum of the parameters of three coUinear points\non the cubic is a period.\n\n[See Richelot, Journal fiir Math. ix. (1832), pp. 407-408 and Cayley,\nProc. Camb. Phil. Soc. IV. (1883), pp. 106-109. A uniformising\nvariable for the general cubic in the canonical form X + F + Z +\n6rnXYZ=0 has been obtained by Bobek, Einleitung in die Theorie dex\nelliptischen Funktionen (Leipzig, 1884), p. 251. Dixon Quarterly\nJournal, xxiv. (1890), pp. 167-233) has developed the theory of\nelliptic functions by taking the equivalent curve a +y' - cuicy=\\ as\nfundamental, instead of the curve\n\ny2=(l-. 2)(1\\ .2 .2).]\n\n42. Express I 2x-x-) (4 -2 + 9) ~ \" dx in terms of a complete elliptic\nintegral of the first kind with a real modulus. \\addexamplecitation{Math. Trip. 1911.}\n\n43. If u=l t + ) t: + t + ) ]- dt,\n\nexpress x in terms of Jacobian elliptic functions of u with a real\nmodulus.\n\n\\addexamplecitation{Math. Trip. 1899.}\n\n44. If i= P (1+ 2 \\ 2 4)- i;\n\nexpress x in terms of by means of either Jacobian or Weierstrassian\nelliptic functions.\n\n\\addexamplecitation{Math. Trip. 1914.}\n\n45. Shew that\n\n2' 7r\n\n\\addexamplecitation{Trinity, 1881.}\n\n46. When a>x> >y, reduce the integrals\n\n\\ \\ a-t) t- ) t-y)]- dt, j-\" (a-t) t- )(t-y) -idt\n\nby the substitutions\n\nx-y = a- y) dn w, x - y = (p-y) nd- ??\n\nrespectively, where k' = a - )/ a - y).\n\nDeduce that, ii u + v = K, then\n\n1-sn u - sn v + k'sn uiin v = 0.\n\nBy the substitution y = a - t) t - j3)l t - y) applied to the above\nintegral taken between the limits j3 and a, obtain the Gaussian form\nof Landen's transformation,\n\nI a cos d + bi' Hm-d)~ de= I a- eos 6 + b' sin (9) ~ a dd,\n\nwhere ai, bi are the arithmetic and geometric means between a and b.\n\n(Gauss, Werke, ill. p. 352; Math. Trip. 1895.)\n\n%\n% 534\n%\n\n47. Shew that\n\nsc ?f = - k' - 1 C u - A') - C (u - K - 2iK') - C 2iK% where the\nZeta-functions are formed with periods 2a)i, 2co2 = 2K, AiE'.\n\n\\addexamplecitation{Math. Trip. 1903.}\n\n48. Shew that E - k\" K sati.sfies the equation\n\nwhere c=lfi, and obtain the primitive of this equation.\n\\addexamplecitation{Math. Trip. 1911.}\n\n49. Shew that ni k K' dk= n- ) ( /('' - E' dk,\n\n(71 + 2) j t'E'dk= n + l) I k' K'dk. \\addexamplecitation{Trinity, 1906.}\n\n50. If u W\"\" t t) ct) ~ dt,\n\n  J\n\nshew that o(c-l) +(2c-l) + 4. = | 3\n\n51. SHew that the primitive of\n\ndu u k \\\n\ndk' J' T '\n\nA E-K) + A'E'\n\n\\addexamplecitation{Trinity, 1896.}\n\n'\"\"'AE+A'iE'-K'y\n\nwhere J, A' are constants. \\addexamplecitation{Math. Trip. 1906.}\n\n52. Deduce from the addition-formula for E u) that, if\n\nUi + U2 + U + Ui = 0,\n\nthen (sn ?<! sn l<l - sn u sn Ui) sn (uy + %i\n\nis unaltered by any permutation of suffices. \\addexamplecitation{Math. Trip. 1910.}\n\n53. Shew that\n\n\\addexamplecitation{Math. Trip. 1913.}\n\n54. Shew that\n\nU- i' u cd udu = 2K (2 + P) A'- 2 (1 -l-F) E). [Write = A''+r.] '\n\\addexamplecitation{Math. Trip. 1904.}\n\n55. By considering the curves ?/2 = (i \\ .) (1 \\ .2,) y = l- mx +\nn.v', shew that, if u 1 + Uo + Us + Ui = 0, then\n\nE %lx)+E U2) + E ll3) + E Ui) = k\\ 2 .V + 2CiC2C3C4-2SiS2S3S4-2r.\n\n\\addexamplecitation{Math. Trip. 1908.}\n\n56. By the method of example 21, obtain the following seven\nexpressions for\n\nE ui) + E u2) + E(u3) + E tii) when Ui + U2 + U3 + Ui = 0:\n\nl + k s s Si r=i ' ' \" k'-' + d d dsdi r=i '' '' ' k cc c c, - X-'2\n,=1 ' ' '' ' k SiS2S3Sidid 2d3di * c Ks d ) - k CiC2 C3Cidi d2d3di * g\nu d)\n\nPkf SiS2S3Si-did2d3di r=l d d2d3di-lrk' CiC2C3Ci r=l\n\nk'SiS2S3Si + CiC2C3Ci *\n\nClC2C3C4 + A:2siS253S4,.=i\n\n4\n\n- 2;(gj52S3S4)-l + (CiC2C3C4)-l + X' (a?lC/2C 3<: 4)~' ~ 2 ll s,Crdr).\n\nr=l\n\n\\addexamplecitation{Forsyth, Messenger, xv.}\n\n%\n% 535\n%\n\n57. Shew that\n\nwhen I I x) | <7r/(r); and, by differentiation, deduce that\n\n6 f y ns* [- \") = 6 cosec* x + i (1 + F) ( y - 1 cosec x\n\nTT \\ TT /\n\n -, * f 79S /2/r\\ 2 \"] o2 COS 2 A'\n\nShew also that, when | /( ) | < |7r/(r),\n\nn.M + 2\n\n2Kx\\ \\ - fl-hf-2 \\ 2n + lf fjn yi 27rg\"- - sin (2ot + 1) j -,!o 1 2P\n' 2F - \\ 2k) j (1 - ? - 1)\n\n\\addexamplecitation{Jacobi.}\n\n58. Shew that, if a be the semi-major axis of an ellipse whose\neccentricity is sin j-Vtt, the perimeter of the ellipse is\n\n\\addexamplecitation{Ramanujan, Quarterly Journal, XLV.}\n\n59. Deduce from examjjle 19 of Chapter xxi that\n\nTO o -k\" + dn udn3u,,\\ k' + k cn u en Su\n\nF cn3 2u = - - T-, - 5 r-, dn 2u = r- 71 - 5 i~\n\nl+k sn usn3u l + Fsn wsnSM\n\n\\addexamplecitation{Trinity, 1882.}\n\n60. From the formula sd i.u, k) = i sd (n, k') deduce that\n\nrq '+i . f n + i)7ru\\ \\ 1 - (-)'*?i' \"';. f 7i + i)nu\n\nK'\n\n1 1 ( rv i.br ' i V- i - g \"\"'\n\nwhere q = exp ( - ttK'/K), q = exp ( - irKjK'),\n\nand u lies inside the parallelogram whose vertices are\n\n±iK±K'. By integrating from u to K\\ from to u and again from ti to K',\nprove that\n\n[A formula which may be derived from this by writing 2i = \\$ + iri,\nwhere | and rj are real, and equating imaginary parts on either side\nof the equation was obtained by Thomson and Tait, Natural Philosopki\nii. (1883), p. 249, but they failed to observe that their formula was\nnothing but a consequence of Jacobi's imaginary transformation. The\nformula was suggested to Thomson and Tait by the solution of a problem\nin the theory of Elasticity.]\n", "meta": {"hexsha": "c51179e69f968c81140093713597dc53914a26b3", "size": 86413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch22.tex", "max_stars_repo_name": "CdLbB/Whittaker-and-Watson", "max_stars_repo_head_hexsha": "5fefdd2c36b4e48cc078a88afc77df289e680a73", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/tex/wandw-ch22.tex", "max_issues_repo_name": "CdLbB/Whittaker-and-Watson", "max_issues_repo_head_hexsha": "5fefdd2c36b4e48cc078a88afc77df289e680a73", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tex/wandw-ch22.tex", "max_forks_repo_name": "CdLbB/Whittaker-and-Watson", "max_forks_repo_head_hexsha": "5fefdd2c36b4e48cc078a88afc77df289e680a73", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.5722632226, "max_line_length": 113, "alphanum_fraction": 0.6451228403, "num_tokens": 30952, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8311430562234877, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.7176019472743953}}
{"text": "\\chapter{Binary Collatz Tree}\n\\label{ch:binary_tree}\n\n\\section{Some essentials on binary trees}\nA binary tree is a rooted tree, where each node has at most two immediate successors. Those nodes, from which no edge goes out downward, are called leaves, the others are called internal nodes. In a full binary tree, all internal nodes have exactly two children \\cite[p.~102]{Ref_Higham_2015}. Full binary trees have an odd number $2n+1$ of nodes. Of these $n+1$ are leaves and $n$ are inner nodes \\cite[p.~134]{Ref_Kersting_Wakolbinger_2008}. Each node in a binary tree has a left subtree and a right subtree, which is why a binary tree is inherently recursive, since the left and right subtrees of the root are themselves binary trees \\cite[p.~246-247]{Ref_Mazur_2010}. As it often pops up in combinatorial problems, the famous $n$-th Catalan number, named after the Belgian mathematician Eugène Catalan, comes in connection with binary trees into play. For $n\\ge1$ it specifies the number of binary trees on $n$ vertices \\cite[p.~247]{Ref_Mazur_2010}:\n\\[\nB_n=\\sum_{i=0}^{n-1}B_iB_{n-1-i}=\\sum_{i=1}^{n}B_{i-1}B_{n-i}=\\frac{1}{n+1}\\binom{2n}{n}\n\\]\n\nThere is an interesting property that trees exhibit regarding abstract algebra. Let's have a look at the algebraic structure of magmas. Consider an element $x$ of a magma $(M,*)$ which is an iterated product of other elements in $M$. Such an element can be described by a planar (no edges cross each other) rooted binary tree whose $n$ leaves are labelled by these other elements $x_1,\\ldots,x_n\\in M$ \\cite[p.~96]{Ref_Kalka_2016}.\n\nBinary trees make well-suited data structures for storing information. With about $2^m$ data points (nodes), a search of a binary tree takes only about $m$ steps, compared to about $2^{m-1}$ steps which are required to search a simple list \\cite[p.~84]{Ref_Benjamin_2009}.\n\n\\section{Transforming the Collatz tree into a binary tree}\nJan Kleinnijenhuis and Alissa M. Kleinnijenhuis \\cite{Ref_Kleinnijenhuis_2020a} introduced a binary tree $T_{\\ge0}$ by transforming the original Collatz tree $H_U$ into the Syracuse tree $H_{C,3}$, which in turn is transformed into the binary tree $T_{\\ge0}$ as described next. The edges are changed according to the following procedure: whenever a parent node $w$ has edges to its child nodes $v_0,v_1,\\ldots,v_n$, on the tree $H_{C,3}$, we draw an edge from $w$ to $v_0$, and edges from $v_i$ to $v_{i+1}$ for each $i=1,\\ldots,n-1$, in the binary new tree. Note that the nodes $v_1,v_2,\\ldots,v_n$ are sorted in increasing order of label $v_0<v_1<\\ldots<v_n$, which is already given by \\ref{eq:n_fold_right_sibling_k}. Figure~\\ref{fig:bt3} and \\ref{fig:bt3_rot} display that tree -- once in our standard layout and once reversed (from bottom to top).\n\n\\begin{figure}[H]\n\t\\includegraphics[width=1.00\\textwidth]{figures/bt_3_t0.png}\n\t\\caption{The Collatz Tree transformed to the binary tree $T_{\\ge0}$}\n\t\\label{fig:bt3}\n\\end{figure}\n\n\\vspace{-2em}\n\\begin{figure}[H]\n\t\\includegraphics[width=1.00\\textwidth]{figures/bt_3_t0_rot.png}\n\t\\caption{The binary tree $T_{\\ge0}$ with \\textit{bottom-to-top} layout orientation}\n\t\\label{fig:bt3_rot}\n\\end{figure}\n\n\\begin{remark}\n\tTo clarify the terminology, it should be mentioned that Jan and Alissa M. Kleinnijenhuis in their manuscripts \\cite{Ref_Kleinnijenhuis_2020a}, \\cite{Ref_Kleinnijenhuis_2020b} denote the original Collatz tree $T_C$ while we call it $H_U$. They denote the Syracuse Tree $T_T$ which in our nomenclature is referred to as $H_{C,3}$.\n\\end{remark}\n\nNodes that are highlighted orange in figures~\\ref{fig:bt3},~\\ref{fig:bt3_rot} are called \\textit{prunable} and they are exactly those nodes resulting as output of the \\textit{Rightward} function. For navigating within this binary tree, Jan Kleinnijenhuis and Alissa M. Kleinnijenhuis \\cite{Ref_Kleinnijenhuis_2020a} defined an \\textit{Upward} function $U(n)$ and a \\textit{Rightward} function $R(n)$ as follows:\n\n\\begin{equation}\n\\label{eq:bintree_3_rightward_upward}\n\\setlength{\\arraycolsep}{1.6em}\n\\begin{array}{cc}\nU(n)=\\begin{cases}\n        4n+1\t&\tn\\equiv 1\\pmod 6\\\\\n        16n+5\t&\tn\\equiv 5\\pmod 6\n    \\end{cases} &\nR(n)=\\begin{cases}\n    \\nicefrac{(2^2n-1)}{3}\t&\tn\\equiv 1\\pmod{18}\\\\\n    \\nicefrac{(2^3n-1)}{3}\t&\tn\\equiv 5\\pmod{18}\\\\\n    \\nicefrac{(2^4n-1)}{3}\t&\tn\\equiv 7\\pmod{18}\\\\\n    \\nicefrac{(2^1n-1)}{3}\t&\tn\\equiv 11\\pmod{18}\\\\\n    \\nicefrac{(2^2n-1)}{3}\t&\tn\\equiv 13\\pmod{18}\\\\\n    \\nicefrac{(2^1n-1)}{3}\t&\tn\\equiv 17\\pmod{18}\n\\end{cases}\n\\end{array}\n\\end{equation}\n\nThe domain and codomain of both functions consist of the two residue classes $[1]_6,[5]_6$, which form the multiplicative (cyclic) group $\\mathbb{Z}^\\ast_6=\\{1,5\\}=<5>$. Consequently, the domain and codomain exclude all integers divisible by $2$ and $3$, which is due to the fact that this binary tree (just like our tree $H_{C,3}$) does not contain even numbers and additionally all leaves -- namely those nodes labeled with an integer divisible by three -- were deleted. The function $U(n)$ is very similar to the function~\\ref{eq:next_sibling_k3} and to the more general function~\\ref{eq:n_fold_right_sibling_k} (when setting $n=1,k=3$) which both calculate the right-sibling of a given vertex. This is clear, since siblings (parallel) in $H_{C,3}$ are successors (serial) in the binary tree $T_{\\ge0}$. In the end, for a node $v_0$ having a leaf as right-sibling in $H_{C,3}$, the function $U(v_0)$ is defined as $v_1=4v_0+1$ executed twice $v_1=4(4v_0+1)+1=16v_0+5$, because we must skip this leaf. Recall that all leafs in $H_{C,3}$ are excluded from the binary tree without exception. For any $n\\in[5]_6$ it applies that $U(n)\\equiv16n+5\\equiv\\boldsymbol{1}\\bmod(6)$ since $6\\mid16n+5-\\boldsymbol{1}$ resulting in $6\\mid16(5+k\\cdot6)+5-\\boldsymbol{1}$, see \\ref{eq:congruence}, and analogously for any $n\\in[1]_6$ it applies that $U(n)\\equiv4n+1\\equiv\\boldsymbol{5}\\bmod(6)$ since $6\\mid4n+1-\\boldsymbol{5}$ resulting in $6\\mid4(1+k\\cdot6)+1-\\boldsymbol{5}$. Therefore executing the Upward function twice in a row leads unconditionally to $U^2(n)=16(4n+1)+5=4(16n+5)+1=64n+21$.\n\n\\begin{remark}\n\tWhile we displayed trees from top to down, it is sometimes usual to draw trees in a bottom-to-top fashion as Kleinnijenhuis \\cite{Ref_Kleinnijenhuis_2020b} do. The Rightward function corresponds to what we call left-child and the Upward function relates to the right-child which is commonly used in the context of binary trees \\cite[p. 246]{Ref_Mazur_2010}.\n\\end{remark}\n\nJan and Alissa M. Kleinnijenhuis \\cite{Ref_Kleinnijenhuis_2020a} defined the set $N(T_C)=N(H_U)$ that contains the labels of all nodes, to which a path from the root in $H_U$ exists, in other words, this set contains all integers $n$ for which the orbit of $n$ under the (uncompressed) Collatz function~\\ref{eq:func_collatz} converges to $1$. Furthermore they introduced $S_{\\ge0}$ as the node set containing integers that are neither divisible by $2$ nor by $3$. The set $S_{-1}$ comprises on the contrary all numbers, which are divisible by $2$ or $3$. In order to comprehend the structure of these sets $S$, let us take a look at the following list showing which tree includes which node set, see also the ancillary files of \\cite{Ref_Kleinnijenhuis_2020a}, \\cite{Ref_Kleinnijenhuis_2020b}:\n\n\\[\\arraycolsep=0.6em\\def\\arraystretch{1.4}\n\\begin{array}{llll}\n\\text{Original Collatz tree} & N(T_C)=N(H_U)&=&\\mathbb{N^+} \\hspace{0.6em}\\text{if the Collatz conjecture holds}\\\\\n\\text{Syracuse tree} & N(T_T)=N(H_{C,3})&=&N(T_C)\\setminus2\\mathbb{N}\\\\\n\\text{Binary tree}\\hspace{0.6em}T_{\\ge0}& N(T_{\\ge0})=S_{\\ge0}&=&N(T_C)\\setminus S_{-1}\\hspace{2.1em}=S_{0}\\cup S_{1}\\cup S_{2}\\ldots\\\\\n\\text{Binary tree}\\hspace{0.6em}T_{\\ge1}& N(T_{\\ge1})=S_{\\ge1}&=&N(T_C)\\setminus \\bigcup_{i=-1}^{0}S_i=S_{1}\\cup S_{2}\\cup S_{3}\\ldots\\\\\n\\text{Binary tree}\\hspace{0.6em}T_{\\ge j} & N(T_{\\ge j})=S_{\\ge j}&=&N(T_C)\\setminus \\bigcup_{i=-1}^{j-1}S_i=\\bigcup_{i=j}^{\\infty}S_i\n\\end{array}\n\\]\n\n\\par\\medskip\nLet us describe these sets using multiplicative groups. The set $S_{\\ge0}=\\mathbb{Z}^\\ast_6$ can be understood as the multiplicative group modulo $6$ and the set $S_{-1}=\\mathbb{Z}/6\\mathbb{Z}\\setminus\\mathbb{Z}^\\ast_6=\\{0,2,3,4\\}$ as the set of all non-invertible elements (non-units) of $\\mathbb{Z}/6\\mathbb{Z}$.\n\nThe set $S_0$ consists of all nodes resulting as output of $R(n)$ within the binary tree $T_{\\ge0}$. These are the orange highlighted nodes displayed by figures~\\ref{fig:bt3},~\\ref{fig:bt3_rot}. In other words, $S_0$ is the codomain of the function $R(n)$ operating on nodes within $T_{\\ge0}$. The binary tree $T_{\\ge0}$ can be transformed to a (pruned) binary tree $T_{\\ge1}$. For this, the prunable nodes will be deleted and their neighbors reconnected. The upward neighbor of a pruned node will then be identified as pruning candidate for a later transformation of the resulting tree $T_{\\ge1}$ to a more pruned tree $T_{\\ge2}$.\n\nThe set $S_1$ contains all nodes that are (as per the description above) identified as pruning candidates for the next transformation of $T_{\\ge1}$ to $T_{\\ge2}$. After having transformed $T_{\\ge1}$ to $T_{\\ge2}$, the more pruned binary tree $T_{\\ge2}$ contains nodes that are identified as pruning candidates for another upcoming transformation of $T_{\\ge2}$ to $T_{\\ge3}$ -- these nodes are elements of the set $S_2$. This pruning algorithm is repeatedly applied in the same pattern. And in this way we obtain the sets $S_1,S_2,S_3,\\ldots$ and so forth. Generally, we can write these sets in the form $S_j=\\{n\\in N(T_{j-1})\\mid U^{-j}(n)\\in S_0\\}$. Kleinnijenhuis found out that the codomain $\\mathbb{N}^U$ of the Upward function contains $5$ residue classes modulo $96$, namely $\\{5, 29, 53, 77, 85\\}=\\mathbb{N}^U$ and the codomain $\\mathbb{N}^R$ of the Rightward function comprises $27$ residue classes modulo $96$, namely $\\{1, 7, 11, 13, 17, 19, 23, 25, 31, 35, 37, 41, 43, 47, 49, 55, 59, 61, 65, 67, 71, 73, 79, 83, 89, 91, 95\\}=\\mathbb{N}^R$. The union of both sets $\\mathbb{N}^U\\cup\\mathbb{N}^R$ forms the non-cyclic multiplicative group $\\mathbb{Z}^\\ast_{96}$, whose generating set is $\\{5, 17, 31\\}$ (see \\cite{Ref_Lang_2017}, \\cite{Ref_OESIS_A033949}). All elements of the Upward function's codomain have the same remainder $5$ when divided by $8$.\n\nFor each subset $X$ of a group $G$, the intersection over all subgroups (of $G$) that contain this subset $X$ is \\cite[p.~34]{Ref_Karpfinger_Meyberg_2017}:\n\\[\n\\left<X\\right>=\\bigcap_{X\\subseteq U\\le G}U\n\\]\n\nFirstly it applies $\\left<X\\right>\\le G$ meaning that this intersection is again a subgroup of $G$. It is generated by the \\textit{generating set} $X$ and it is the smallest subgroup of $G$ containing every element of $X$ \\cite[p.~35]{Ref_Karpfinger_Meyberg_2017}. Secondly, $\\left<X\\right>\\subseteq U$ for each subgroup $U$ (of $G$) containing $X$.  Thirdly, when there is only a single element $x$ in $X$, then $\\left<X\\right>$ is usually written as $\\left<x\\right>$ and in this case, $\\left<x\\right>$ is the cyclic subgroup of $G$ -- such situations we have already seen in section~\\ref{sec:left_child_right_sibling_3}. Let us refer back to $\\mathbb{Z}^\\ast_{96}$. In this example, $\\left<\\{5,17,31\\}\\right>$ is the subgroup generated by $\\{5,17,31\\}$ and therefore every element of $\\mathbb{Z}^\\ast_{96}$ is of the form $5^l17^m31^n$ where $l\\in\\{0,1,\\ldots,7\\}$ because the element $5$ has order $8$, and similarly $m,n\\in\\{0,1\\}$ since both elements $17$ and $31$ have order $2$. Non-cyclic groups can be cyclic decomposed, which is detailed by Gallian and Rusin \\cite{Ref_Gallian_Rusin_1980} and Cheng \\cite{Ref_Cheng_1989} using the concept of the external direct product \\cite[p.~79]{Ref_Karpfinger_Meyberg_2017}, \\cite[p.~156]{Ref_Gallian} and the internal direct product \\cite[p.~80]{Ref_Karpfinger_Meyberg_2017}, \\cite[p.~183]{Ref_Gallian}. A comprehensive table of cyclic decompositions of multiplicative non-cyclic groups of integers modulo $n$ up to $n=130$ is provided by Wolfdieter Lang \\cite{Ref_Lang_2017}.\n\n% http://mathonline.wikidot.com/the-internal-direct-product-of-two-groups\n\nLet us take a closer look at the (cyclic) multiplicative group $\\mathbb{Z}^\\ast_{18}=\\{1,5,7,11,13,17\\}=\\left<5\\right>$ which has an order $ord(\\mathbb{Z}^\\ast_{18})=6$. Having the generator $5$ coprime to the modulus $18$, we obtain the congruence $5^{\\phi(18)}\\equiv1\\pmod{18}$ in accordance with Euler's theorem \\ref{eq:eulers_theorem}. This allows us to infer from $5^6\\equiv5^{6(n+1)}\\equiv5^j5^{6n+6-j}\\equiv1\\pmod{18}$ the congruences given by \\ref{eq:homomorphism_congruences} (on the left).\n\nIf a natural number divides another, $m\\mid n$, as in our case $3\\mid18$, then for two integers $a,b$ the following implication holds, see \\cite[p.~21]{Ref_Mueller-Stach_2011}:\n\n\\begin{equation}\n\t\\label{eq:reduce_modulus}\n\ta\\equiv b\\pmod n\\rightarrow a\\equiv b\\pmod m\n\\end{equation}\n\nThis means in our case $w\\cdot5^{6n+6}\\equiv 1\\pmod{18}\\rightarrow w\\cdot5^{6n+6}\\equiv 1\\pmod 3$. Based on equation~\\ref{eq:congruence_reduction} we can state that $a\\equiv b\\pmod m$ implies $(a+m)\\equiv b\\pmod m$. Let us set $a=w\\cdot2^{2n+2}$ and $b=1$ and $m=3$, then we obtain $(w\\cdot2^{2n+2}+3)\\equiv1\\pmod3$ and using a factor $i\\in\\mathbb{N}$ we obtain the more general congruence $(w\\cdot2^{2n+2}+3i)\\equiv1\\pmod3$. As a consequence the congruences in \\ref{eq:homomorphism_congruences} are true, while $w\\cdot5^{6n+6}=w\\cdot2^{2n+2}+3\\cdot i$ or rather while $3\\mid(5^{6n+6}-2^{2n+2})$. These conditions continue $3\\mid(5^{6n+5}-2^{2n+3})$ and $3\\mid(5^{6n+4}-2^{2n+4})$ and so forth.\n\n\\begin{equation}\n\\label{eq:homomorphism_congruences}\n\\begin{array}{llllll}\n\tj=0, & w\\in [1]_{18} & \\hspace{1em} w\\cdot5^{6n+6}&\\equiv1\\pmod{18}&\\hspace{4em}w\\cdot2^{2n+2} &\\equiv1\\pmod{3}\\\\\n\tj=1, & w\\in [5]_{18} & \\hspace{1em} w\\cdot5^{6n+5}&\\equiv1\\pmod{18}&\\hspace{4em}w\\cdot2^{2n+3} &\\equiv1\\pmod{3}\\\\\n\tj=2, & w\\in [7]_{18} & \\hspace{1em} w\\cdot5^{6n+4}&\\equiv1\\pmod{18}&\\hspace{4em}w\\cdot2^{2n+4} &\\equiv1\\pmod{3}\\\\\n\tj=3, & w\\in [17]_{18} & \\hspace{1em} w\\cdot5^{6n+3}&\\equiv1\\pmod{18}&\\hspace{4em}w\\cdot2^{2n+1} &\\equiv1\\pmod{3}\\\\\n\tj=4, & w\\in [13]_{18} & \\hspace{1em} w\\cdot5^{6n+2}&\\equiv1\\pmod{18}&\\hspace{4em}w\\cdot2^{2n+2} &\\equiv1\\pmod{3}\\\\\n\tj=5, & w\\in [11]_{18} & \\hspace{1em} w\\cdot5^{6n+1}&\\equiv1\\pmod{18}&\\hspace{4em}w\\cdot2^{2n+1} &\\equiv1\\pmod{3}\n\\end{array}\n\\end{equation}\n\nMoreover, the map $f:\\mathbb{Z}^\\ast_n\\rightarrow \\mathbb{Z}^\\ast_m$ with $f(r\\bmod n)=r\\bmod m$ is a homomorphism as long as $\\gcd(r\\bmod n,n)=1$ leads to $\\gcd(r\\bmod m,m)=1$. By Euclid, we know that in the case $r$ is coprime to $n$ then it is also coprime to every factor $m$ of $n$. That is why a homomorphism exist to the congruences shown in \\ref{eq:homomorphism_congruences} (on the right).\n\nFigure~\\ref{fig:tree_transformations} shows the complete chain of tree transformations, beginning from the original Collatz tree, over the Syracuse tree to the binary tree and pruned ones.\n\n% trim=left bottom right top\n\\begin{figure}[H]\n\t\\includegraphics[trim=1.1cm 10cm 2.6cm 0.2cm, \n\twidth=1.00\\textwidth,page=1]{figures/tree_transformations.pdf}\n\t\\caption{Transformation chain, beginning from the original Collatz tree up to pruned binary trees}\n\t\\label{fig:tree_transformations}\n\\end{figure}", "meta": {"hexsha": "2439491751619529b81824260bdddfd9ed572e08", "size": 15252, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01 Graph Theory/TeX/v5.0/chapter/03_binary_tree.tex", "max_stars_repo_name": "Sultanow/collatz", "max_stars_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-01T15:12:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T15:54:55.000Z", "max_issues_repo_path": "01 Graph Theory/TeX/v5.0/chapter/03_binary_tree.tex", "max_issues_repo_name": "Sultanow/collatz", "max_issues_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01 Graph Theory/TeX/v5.0/chapter/03_binary_tree.tex", "max_forks_repo_name": "Sultanow/collatz", "max_forks_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-06T20:44:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-06T20:44:07.000Z", "avg_line_length": 125.0163934426, "max_line_length": 1584, "alphanum_fraction": 0.7256753213, "num_tokens": 5343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7176019440894417}}
{"text": "\\subsection{Bilinear forms}\\label{subsec:bilinear_forms}\n\n\\begin{definition}\\label{def:bilinear_form}\\mcite[249]{Knapp2016BasicAlgebra}\n  Let \\( M \\) and \\( N \\) be left \\( R \\)-modules and \\( L: M \\times N \\to R \\) be a \\hyperref[def:multilinear_function]{multilinear function}. We say that \\( L \\) is a \\term{bilinear form}.\n\n  If \\( M = N \\), we have the following additional types of bilinear forms:\n  \\begin{thmenum}\n    \\thmitem{def:bilinear_form/symmetric} If \\( L \\) is a \\hyperref[def:multi_valued_function/symmetric]{symmetric function}, we say that is is a \\term{symmetric bilinear form}\n\n    \\thmitem{def:bilinear_form/skew_symmetric} If for all \\( x, y \\in M \\) instead of \\( L(x, y) = L(y, x) \\) we have \\( L(x, y) = -L(y, x) \\), we say that \\( L \\) is \\term{skew-symmetric}.\n\n    \\thmitem{def:bilinear_form/alternating} If for all \\( x \\in M \\) we have \\( L(x, x) = 0 \\), we say that \\( L \\) is \\term{alternating}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:skew_symmetric_iff_alternating}\n  Let \\( 1 + 1 = 2 \\) be a unit in the ring \\( R \\). Let \\( M \\) be a left module over \\( R \\). Then the bilinear form \\( L: M \\times M \\to R \\) is \\hyperref[def:bilinear_form/alternating]{alternating} if and only if it is \\hyperref[def:bilinear_form/skew_symmetric]{skew-symmetric}.\n\n  Alternating implies skew-symmetric even if \\( 2 \\) is not invertible.\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Let \\( L \\) be alternating. Then\n  \\begin{balign*}\n    L(x + y, x + y) & = L(x, x) + L(x, y) + L(y, x) + L(y, y) \\\\\n    0               & = L(x, y) + L(y, x)                     \\\\\n    L(x, y) = -L(y, x).\n  \\end{balign*}\n\n  \\NecessitySubProof Let \\( L \\) be skew-symmetric. Then\n  \\begin{equation*}\n    L(x, x) = -L(x, x),\n  \\end{equation*}\n  which implies that \\( 2L(x, y) = 0 \\). Hence, \\( L \\) is alternating if we are able to divide by \\( 2 \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:bilinear_form_radicals}\\mcite[250]{Knapp2016BasicAlgebra}\n  Let \\( L: M \\times N \\to R \\) be a bilinear form. We define its \\term{left radical}\n  \\begin{equation*}\n    \\{ x \\in M \\colon \\forall y \\in N, \\inprod x y = 0 \\}\n  \\end{equation*}\n  and \\term{right radical}\n  \\begin{equation*}\n    \\{ y \\in N \\colon \\forall x \\in M, \\inprod x y = 0 \\}.\n  \\end{equation*}\n\n  Note that if \\( L \\) is symmetric or skew-symmetric (which also implies \\( M = N \\)), the two are identical and we speak simply of the \\term{radical} \\( \\sqrt L \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:nondegenerate_bilinear_form}\\mcite[249]{Knapp2016BasicAlgebra}\n  We say that a bilinear form \\( L: M \\times N \\to R \\) is \\term{nondegenerate} if both its left and right \\hyperref[def:bilinear_form_radicals]{radicals} are nontrivial.\n\\end{definition}\n\n\\begin{theorem}\\label{thm:bilinear_form_matrix_presentation}\n  Fix a commutative unital ring \\( R \\) and a bilinear form \\( L: R^n \\times R^m \\to R \\). Then there exists a matrix \\( A \\in R^{n \\times m} \\) such that\n  \\begin{equation*}\n    L(x, y) \\coloneqq x^T A y.\n  \\end{equation*}\n\n  This matrix is called the generalized \\term{Gram matrix}.\n\n  In particular, if \\( L \\) is \\hyperref[def:multi_valued_function/symmetric]{symmetric}, so it \\( A \\).\n\\end{theorem}\n\\begin{proof}\n  Denote by \\( e_1, \\ldots, e_n \\) the basis of \\( R^n \\) and by \\( f_1, \\ldots, f_m \\) the basis of \\( R^m \\).\n\n  Define the matrix \\( A = \\{ a_{i,j} \\}_{i,j=1}^{n,m} \\) by\n  \\begin{equation*}\n    a_{i,j} \\coloneqq L(e_i, f_j).\n  \\end{equation*}\n\n  Note that if \\( n = m \\) and if \\( L \\) is symmetric, then the matrix \\( A \\) is obviously symmetric too.\n\n  For any fixed basis vector \\( e_i, i = 1, \\ldots, n \\) of \\( R^n \\), we have\n  \\begin{equation*}\n    L(e_i, y)\n    =\n    \\sum_{j=1}^m y_i L(e_i, f_j)\n    =\n    y_i a_{(i,-)},\n  \\end{equation*}\n  where \\( a_{(i,-)} \\) is the \\( i \\)-th row of \\( A \\).\n\n  Thus, for an arbitrary \\( x \\in R^n \\)\n  \\begin{equation*}\n    L(x, y)\n    =\n    \\sum_{i=1}^n x_i L(e_i, y)\n    =\n    \\sum_{i=1}^n x_i (a_{(i,-)} y)\n    =\n    \\left( \\sum_{i=1}^n x_i a_{(i,-)} \\right) y\n    =\n    x^T A y.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{corollary}\\label{thm:bilinear_forms_isomorphic_to_matrices}\n  Fix a commutative unital ring \\( R \\). The vector space of bilinear forms of type \\( R^n \\times R^m \\to R \\) is isomorphic to the matrix space \\( A \\in R^{n \\times m} \\).\n\\end{corollary}\n\n\\begin{definition}\\label{def:sesquilinear_form}\\mcite[258]{Knapp2016BasicAlgebra}\n  Let \\( V \\) be a complex vector space and let \\( \\overline V \\) be its conjugate \\hyperref[def:complex_conjucate_vector_space]{transpose}. We call the bilinear form \\( L: V \\times \\overline V \\to \\BbbC \\) a \\term{sesquilinear form} (we say that \\( L \\) is \\enquote{semilinear} in its second argument and \\enquote{sesqui} means \\enquote{one and a half} is Latin).\n\n  Similar to \\fullref{def:bilinear_form}, we have\n  \\begin{thmenum}\n    \\thmitem{def:sesquilinear_form/hermitian} If for all \\( x, y \\in V \\) we have \\( L(x, y) = \\overline{L(y, x)} \\), we say that \\( L \\) is \\term{Hermitian}.\n\n    \\thmitem{def:sesquilinear_form/skew_hermitian} If for all \\( x, y \\in V \\) we have \\( L(x, y) = -\\overline{L(y, x)} \\), we say that \\( L \\) is \\term{skew-Hermitian}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:quadratic_form}\n  If \\( L: M \\times M \\to R \\) be a bilinear \\hyperref[def:bilinear_form]{form}, we call the function\n  \\begin{equation*}\n    Q(x) \\coloneqq L(x, x)\n  \\end{equation*}\n  a \\term{quadratic form} over \\( M \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:quadratic_form_definiteness}\n  \\todo{Define definiteness of quadratic forms}\n\\end{definition}\n\n\\begin{definition}\\label{def:homogenous_function}\n  Let \\( M \\) and \\( N \\) be left \\( R \\)-modules. We say that the function \\( f: M \\to N \\) is homogeneous with degree \\( n \\) if for all \\( t \\in R \\) and \\( x \\in M \\) we have\n  \\begin{equation*}\n    f(t x) = t^n f(x).\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:bilinear_forms_vs_to_quadratic_forms}\n  A \\term{quadratic form} \\( Q: M \\to R \\) is a \\hyperref[def:homogenous_function]{homogeneous function} of degree \\( 2 \\). In particular, \\( Q(x) = Q(-x) \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( L: M \\times M \\to R \\) be the corresponding bilinear form. Then, by \\fullref{def:semimodule/homomorphism/homogeneity},\n  \\begin{equation*}\n    Q(tx) = L(tx, tx) = t^2 L(x, x) = t^2 Q(x).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:polarization_identity}\\mcite{nLab:polarization_identity}\n  Let \\( L: M \\times M \\to R \\) be a bilinear \\hyperref[def:bilinear_form]{form} and \\( Q: M \\to R \\) be its associated quadratic \\hyperref[def:quadratic_form]{form}. Then the \\term{polarization identity} holds:\n  \\begin{equation}\\label{thm:polarization_identity/polarization_identity}\n    2 L(x, y) + 2 L(y, x) = Q(x + y) - Q(x - y)\n  \\end{equation}\n\n  The similar looking, but slightly less useful parallelogram law also holds:\n  \\begin{equation}\\label{thm:polarization_identity/parallelogram_law}\n    2 Q(x) + 2 Q(y) = Q(x + y) + Q(x - y)\n  \\end{equation}\n\n  If \\( 2 = 1 + 1 \\) is a unit in \\( R \\), we can \\enquote{recover} from \\( Q \\) the bilinear form:\n  \\begin{equation}\\label{thm:polarization_identity/symmetrization_definition}\n    \\hat L(x, y) \\coloneqq \\frac 1 2 \\left[ Q(x + y) - Q(x) - Q(y) \\right]\n  \\end{equation}\n\n  The function \\( \\hat L \\) is \\hyperref[def:multi_valued_function/symmetric]{symmetric} and is called the \\term{symmetrization} of \\( L \\). If \\( L \\) itself is symmetric, \\( L = \\hat L \\).\n\\end{proposition}\n\\begin{proof}\n  Identities \\fullref{thm:polarization_identity/polarization_identity,thm:polarization_identity/parallelogram_law,thm:polarization_identity/symmetrization_definition} all follow from the bilinearity of \\( L \\), that is,\n  \\begin{equation*}\n    Q(x \\pm y)\n    =\n    L(x, x) \\pm L(x, y) \\pm L(y, x) + L(y, y)\n    =\n    [Q(x) + Q(y)] \\pm [L(x, y) + L(y, x)].\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:orthogonality}\n  Let \\( U \\) and \\( V \\) be vector spaces over \\( \\BbbK \\) and let \\( L: U \\times V \\to \\BbbK \\) be a nondegenerate bilinear form. We say that the vectors \\( x \\in U \\) and \\( y \\in V \\) are \\term{orthogonal} with respect to \\( L \\) if\n  \\begin{equation*}\n    L(x, y) = 0.\n  \\end{equation*}\n\n  For every subspace \\( U \\subseteq V \\) we define its \\term{orthogonal complement} with respect to \\( L \\) as\n  \\begin{equation*}\n    U^\\perp \\coloneqq \\set{ x \\in U \\colon L(x, y) = 0 \\T{for all} y \\in V }\n  \\end{equation*}\n  and analogously for submodules of \\( V \\).\n\n  Let \\( \\mscrK \\) be an index set and \\( \\seq{ x_k }_{k \\in \\mscrK} \\subseteq U \\), \\( \\seq{ y_k }_{k \\in \\mscrK} \\subseteq V \\) be two families of vectors indexed by \\( \\mscrK \\). We say that these families form a \\term{biorthogonal system} with respect to \\( L \\) if\n  \\begin{equation*}\n    L(x_k, y_m) = 0 \\text{ follows from } k \\neq m\n  \\end{equation*}\n\n  If \\( U = V \\), we usually consider \\term{orthogonal systems} \\( \\seq{ x_k }_{k \\in \\mscrK} \\subseteq V \\) where\n  \\begin{equation*}\n    L(x_k, x_m) = 0 \\iff k \\neq m\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}\\label{def:inner_product_space}\n  An \\term{inner product space} is a vector space \\( V \\) over \\( F \\) equipped with a positive \\hyperref[def:quadratic_form_definiteness]{definite} \\hyperref[def:bilinear_form/symmetric]{symmetric} bilinear form \\( \\inprod \\cdot \\cdot: V \\times V \\to F \\).\n\n  In the special case where \\( F = \\BbbC \\), by convention we require \\( V \\) to instead be equipped with a positive definite \\hyperref[def:sesquilinear_form/hermitian]{Hermitian} sesquilinear form instead.\n\\end{definition}\n\n\\begin{definition}\\label{def:symplectic_vector_space}\n  A \\term{symplectic vector space} is a vector space \\( V \\) over \\( F \\) equipped with a \\hyperref[def:bilinear_form/symmetric]{nondegenerate}  \\hyperref[def:bilinear_form/alternating]{alternating} bilinear form \\( \\inprod \\cdot \\cdot: V \\times V \\to F \\).\n\\end{definition}\n\n\\begin{lemma}\\label{thm:inner_product_quadratic_form_is_positive_definite}\n  Let \\( V \\) be a real or complex \\hyperref[def:inner_product_space]{inner product space} with product \\( \\inprod \\cdot \\cdot \\). The function \\( Q(x) \\coloneqq \\inprod x x \\) (which is not a quadratic form in the complex case) is positive definite.\n\\end{lemma}\n\\begin{proof}\n  The real case is trivial. Assume that \\( V \\) is a complex vector space and that \\( \\inprod \\cdot \\cdot \\) is Hermitian. This implies that \\( \\inprod x x = \\overline{\\inprod x x} \\), thus \\( \\inprod x x \\in \\BbbR \\). Furthermore, since the inner product is positive definite, we have \\( Q(x) = \\inprod x x \\geq 0 \\). Thus, \\( Q \\) is nonnegative real valued.\n\n  Since \\( \\inprod \\cdot \\cdot \\) is positive definite, so is \\( Q \\).\n\\end{proof}\n\n\\begin{theorem}[Cauchy-Bunyakovsky-Schwarz inequality]\\label{thm:cauchy_bunyakovsky_schwarz_inequality}\n  Let \\( V \\) be a real or complex \\hyperref[def:inner_product_space]{inner product space} with product \\( \\inprod \\cdot \\cdot \\). For every \\( x, y \\in V \\) it holds that\n  \\begin{equation}\\label{thm:cauchy_bunyakovsky_schwarz_inequality/inequality}\n    {\\abs{\\inprod x y}}^2 \\leq \\inprod x x \\inprod y y.\n  \\end{equation}\n\n  Furthermore, equality is achieved if and only if \\( x \\) and \\( y \\) are linearly dependent.\n\\end{theorem}\n\\begin{proof}\n  Note that we use this theorem to prove that the induced norm is a norm, so we cannot use the norm here. Associate with \\( \\inprod \\cdot \\cdot \\) the function \\( Q(x) \\coloneqq \\inprod x x \\). By \\fullref{thm:inner_product_quadratic_form_is_positive_definite}, \\( Q \\) is positive definite.\n\n  Fix \\( x, y \\in V \\) and \\( t \\in \\BbbC \\). If either vector is zero the statement is trivially true, so let both be nonzero. We have\n  \\begin{balign*}\n    Q(x + ty)\n     & =\n    \\inprod {x + ty} {x + ty}\n    =    \\\\ &=\n    Q(x) + \\overline t \\inprod x y + t \\inprod y x + \\abs{t}^2 Q(y)\n    =    \\\\ &=\n    Q(x) + 2\\real t \\overline{\\inprod x y} + \\abs{t}^2 Q(y)\n  \\end{balign*}\n\n  Take \\( t \\coloneqq - \\frac {\\inprod x y} {Q(y)} \\), so that\n  \\begin{equation*}\n    Q(x + ty)\n    =\n    Q(x) - 2 \\frac {\\abs{\\inprod x y}^2} {Q(y)} + \\frac {\\abs{\\inprod x y}^2} {Q(y)}\n    =\n    Q(x) - \\frac {\\abs{\\inprod x y}^2} {Q(y)}\n  \\end{equation*}\n\n  Since \\( Q(x + ty) \\geq 0 \\), it follows that\n  \\begin{balign*}\n    Q(x) - \\frac {\\abs{\\inprod x y}^2} {Q(y)} & \\geq 0                  \\\\\n    Q(x) Q(y)                               & \\geq \\abs{\\inprod x y}^2.\n  \\end{balign*}\n\n  If \\( x \\) and \\( y \\) are linearly dependent, equality obviously holds. Conversely, suppose that equality holds. This implies that\n  \\begin{equation*}\n    Q(x + ty) = 0,\n  \\end{equation*}\n  which by the positive definiteness of \\( Q \\) means that \\( x = -ty \\). Thus, \\( x \\) and \\( y \\) are linearly dependent.\n\\end{proof}\n\n\\begin{definition}\\label{def:bilinear_form_induced_norm}\n  Let \\( V \\) be a real or complex \\hyperref[def:inner_product_space]{inner product space} with product \\( \\inprod \\cdot \\cdot \\). We define its induced \\hyperref[def:norm]{norm} as\n  \\begin{balign*}\n     & \\norm \\cdot : V \\to \\BbbR_{\\geq 0}    \\\\\n     & \\norm x \\coloneqq \\sqrt{\\inprod x x}.\n  \\end{balign*}\n\n  If \\( V \\) is a real inner product space, the induced norm is a square root of the induced quadratic \\hyperref[def:quadratic_form]{form} of \\( \\inprod \\cdot \\cdot \\).\n\\end{definition}\n\\begin{proof}\n  We will only prove the complex case because the real case is identical, but slightly simpler.\n\n  Note that \\( \\norm \\cdot \\) is well-defined (that is, positive definite) by \\fullref{thm:inner_product_quadratic_form_is_positive_definite}.\n\n  Now we will show that it is a norm.\n  \\SubProofOf{def:norm/N1} Follows from the positive definiteness of \\( \\inprod \\cdot \\cdot \\)\n\n  \\SubProofOf{def:norm/N2} For \\( t \\in \\BbbC \\) and \\( x \\in V \\) we have\n  \\begin{equation*}\n    \\norm{tx} = \\sqrt{\\inprod{tx} {tx}} = \\abs{t} \\sqrt{\\inprod x x} = \\abs t \\norm x.\n  \\end{equation*}\n\n  \\SubProofOf{def:norm/N3} For \\( x, y \\in V \\) we have\n  \\begin{balign*}\n    \\norm{x + y}^2\n     & =\n    \\inprod{x + y} {x + y}\n    =                                                            \\\\ &=\n    \\inprod x x + \\inprod x y + \\inprod y x + \\inprod y y\n    =                                                            \\\\ &=\n    \\norm{x}^2 + 2 \\real \\inprod x y + \\norm{y}^2\n    \\leq                                                         \\\\ &\\leq\n    \\norm{x}^2 + 2 \\abs{\\real \\inprod x y} + \\norm{y}^2\n    \\reloset {\\ref{thm:cauchy_bunyakovsky_schwarz_inequality}} = \\\\ &=\n    \\norm{x}^2 + 2 \\norm x \\norm y + \\norm{y}^2\n    =\n    (\\norm{x} + \\norm{y})^2\n  \\end{balign*}\n\n  Therefore,\n  \\begin{equation*}\n    \\norm{x + y} \\leq \\norm x + \\norm y.\n  \\end{equation*}\n\\end{proof}\n", "meta": {"hexsha": "0acc866deba5b504a585a5ea01acb0f5be018b13", "size": 14765, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/bilinear_forms.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/bilinear_forms.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/bilinear_forms.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.2166666667, "max_line_length": 364, "alphanum_fraction": 0.6350829665, "num_tokens": 5110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737807, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.7176019414313256}}
{"text": "\\section{Correctness of the Bayes Filter Algorithm}\\label{sec:ap:bayes-filter}\nThe current posterior distribution is calculated as it is shown in equation \\ref{eq:ch-2:bel-derivation}.\n\n\\begin{equation}\\label{eq:ch-2:bel-derivation}\np(x_t| z_{1:t}, u_{1:t}) = \\frac{p(z_t | x_t, z_{1:t-1}, u_{1:t}) \\: p(x_t | z_{1:t-1}, u_{1:t})}{p(z_t | z_{1:t-1}, u_{1:t})}\n\\end{equation}\n\nWhere,\n\n\\begin{itemize}\n\\item $p(x_t | z_{1:t-1}, u_{1:t})$ is the prior distribution. That is the information of state $x_t$ before seen the observation at time $t$.\n\\item $p(z_t | x_t, z_{1:t-1}, u_{1:t})$ is the likelihood model for the measurements. A causal, but noisy relationship\\cite{Sarkka:bayesian-filters}. \n\\item $p(z_t | z_{1:t-1}, u_{1:t})$ is the normalization constant defined as $\\eta$\n\\end{itemize}\n\nThus equation \\ref{eq:ch-2:bel-derivation} can be summarized as follows:\n\n\\begin{equation} \\label{eq:ch-2:bel-derivation-2}\np(x_t| z_{1:t}, u_{1:t}) = \\eta \\: p(z_t | x_t, z_{1:t-1}, u_{1:t}) \\: p(x_t | z_{1:t-1}, u_{1:t}) \n\\end{equation}\n\nThe prediction of observation $z_t$ based on the state $x_t$, the previous observation $z_{1:t-1}$ and the control action $u_{1:t}$ has a conditional independence regarding the previous observation and the control action because they do not aport any information while predicting $z_t$. Thus the likelihood model for the measurements can be simplified as follows:\n\n\\begin{equation}\np(z_t | x_t, z_{1:t-1}, u_{1:t}) = p(z_t | x_t)\n\\end{equation}\n\nTherefore equation \\ref{eq:ch-2:bel-derivation-2} reduces to:\n\n\\begin{equation} \\label{eq:ch-2:bel-derivation-3}\np(x_t| z_{1:t}, u_{1:t}) = \\eta \\: p(z_t | x_t) \\: p(x_t | z_{1:t-1}, u_{1:t})\n\\end{equation}\n\nIn equation \\ref{eq:ch-2:expand-prior-here} the prior distribution is expanded.\n\n\\begin{equation}\\label{eq:ch-2:expand-prior-here}\np(x_t | z_{1:t-1}, u_{1:t}) = \\int p(x_t | x_{t-1}, u_t) \\: p(x_{t-1} | z_{1:t-1}, u_{1:t-1}) dx_{t-1}\\\\\n= \\overline{bel}(x_t)\n\\end{equation}\n\nReplacing equation \\ref{eq:ch-2:expand-prior-here} in \\ref{eq:ch-2:bel-derivation-3}, equation \\ref{eq:ch-2:bel-derivation-4} is obtained which is calculated by the algorithm in list \\ref{ch-2:algo:bayes-filter}, third line.\n\n\\begin{equation}\\label{eq:ch-2:bel-derivation-4}\np(x_t| z_{1:t}, u_{1:t}) = \\eta \\: p(z_t | x_t) \\: \\overline{bel}(x_t)\n\\end{equation}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "7a23ce3754757a46f78ae8fe38fd6b2a70c6cf1b", "size": 2342, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/thesis-doc/chapters/appendix.tex", "max_stars_repo_name": "qiuwenhui/webots-thesis", "max_stars_repo_head_hexsha": "9f49928aae755fb89d5fc884927de6593d5e122c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-17T22:19:35.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-17T22:19:35.000Z", "max_issues_repo_path": "documents/thesis-doc/chapters/appendix.tex", "max_issues_repo_name": "qiuwenhui/webots-thesis", "max_issues_repo_head_hexsha": "9f49928aae755fb89d5fc884927de6593d5e122c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-11-13T18:48:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-25T16:05:09.000Z", "max_forks_repo_path": "documents/thesis-doc/chapters/appendix.tex", "max_forks_repo_name": "qiuwenhui/webots-thesis", "max_forks_repo_head_hexsha": "9f49928aae755fb89d5fc884927de6593d5e122c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-25T21:07:09.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-25T21:07:09.000Z", "avg_line_length": 36.0307692308, "max_line_length": 363, "alphanum_fraction": 0.6797608881, "num_tokens": 864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737807, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.7176019269864886}}
{"text": "\\subsubsection{The factorization properties}\n\nLet us resume the discussion from last section, where we claim that\nall we needed  was that the vectors of\nthe two bases had the property of $A\\vec{v_i} =\n\\sigma_i\\vec{u_i}$. Let us prove such claim, and show that if that\ncondition is met, then SVD factorization can be achieved. \\\\\n\n\\begin{theorem}[SVD Part 1: the factorization]\n\\label{thm:SVD1}\nLet $A$ be a real matrix of $n \\times m$,\\text{if } $\\exists$\northonormal basis $\\{\\vec{v_1},\\vec{v_2},\\dots,\\vec{v_n}\\}$ for \\R{n},\nand another orthonormal $\\{\\vec{u_1},\\vec{u_2},\\dots,\\vec{u_m}\\}$ for\n\\R{m} which hold the following property:\n\n\\[\nA\\vec{v_i} = \\sigma_i\\vec{u_i}, \\ds{}\\forall i=1 \\dots r, \\ds{}\\text{where\n} r = rank(A).\n\\]\n\\\\\nThen we can factorize matrix $A$ as $U \\Sigma \\trans{V}$. \\\\\n\nwhere \n\n\\begin{itemize}\n\\item $V$ is the orthogonal matrix formed by arranging vectors\n\\vec{v}\\apos{s}\n\\item matrix $U$ is defined similarly for vectors\n\\vec{u}\\apos{s}\n\\item The only non zero entries of diagonal matrix $\\Sigma$, are \nthose $\\Sigma_{ii} = \\sigma_i > 0$ for $1 <= i <= r$.\n\\end{itemize}\n\\end{theorem}\n\\hfill\n\n\\begin{proof}\nThis \\cref{thm:SVD1} is mentioned in \\cite{kalman96}, though not\nexplicitly proved. Let us do it here, following the advice from\n\\cite{strang88}, that the trick is to think about a matrix\nmultiplication $A B$, as the result of matrix-vector products ($A\n\\vec{b_i}$), where the vectors are the columns of $B$. In our particular\ncase, the matrix-vector products we have are $A\\vec{v_i}$; if we\narrange them as columns of a new matrix it would be equal to $A\nV$. That is: \n\n\\[\n\\begin{bmatrix}\n  A\\vec{v_1} \\mid A\\vec{v_2} \\mid \\cdots \\mid A\\vec{v_n} \n\\end{bmatrix} = \nA \n\\begin{bmatrix}\n  \\vec{v_1} \\mid \\vec{v_2} \\mid \\cdots \\mid \\vec{v_n} \n\\end{bmatrix} =\nAV\n\\]\n\\hfill\n\nSince we do not have product $AV$ in our target result, let us use the\nfact that $V$ is orthogonal; which in particular implies that \\inv{V}\n= \\trans{V}. That allows to focus on an target result, which involves\n$AV$: \n\n\\[\nA   = U \\Sigma \\trans{V} \\ds{\\iff}\nA V = U \\Sigma V \\trans{V} \\ds{\\iff}\nA V = U \\Sigma\n\\]\n\\hfill\n\nSo we can focus in proving that $A V = U \\Sigma$. Let us work\nthe left side first, which per our previous observation that\n$A\\vec{v_i}$ are the columns of matrix product $AV$, and per hypothesis\nthat $A\\vec{v_i} = \\sigma_i\\vec{u_i}$ can be rewritten as follows:\n\n\\begin{align*}\n  & A V &= \\\\\n  & A \\begin{bmatrix}\n    \\vec{v_1} \\mid \\vec{v_2} \\mid \\cdots \\mid \\vec{v_n} \n  \\end{bmatrix} &= \\\\\n  & \\begin{bmatrix}\n      A\\vec{v_1} \\mid A\\vec{v_2} \\mid \\cdots \\mid A\\vec{v_n} \n    \\end{bmatrix} &= \\\\\n  & \\begin{bmatrix} \n      \\sigma_1\\vec{u_1} \\mid \\sigma_2\\vec{u_2} \\mid \\dots \\mid \\sigma_r\\vec{u_r} \n      \\mid A\\vec{v_{r+1}} \\mid A\\vec{v_{r+2}} \\mid \\dots \\mid A\\vec{v_{n}} \n    \\end{bmatrix}\n\\end{align*}\n\\hfill\n\nLet us now develop the left side $U \\Sigma$ by thinking again in the\nresult, as formed by columns of the form $U \\vec{\\Sigma_i}$ (where\n  \\vec{\\Sigma_i} is the $i$th column of diagonal matrix $\\Sigma$): \n\n\\begin{align*}\n  & U \\Sigma &= \\\\\n  & \\begin{bmatrix}\n      U\\vec{\\Sigma_1} \\mid U\\vec{\\Sigma_2} \\mid \\cdots \\mid U\\vec{\\Sigma_n} \n    \\end{bmatrix} &= \\\\\n  & \\begin{bmatrix}\n      U\\vec{\\Sigma_1} \\mid U\\vec{\\Sigma_2} \\mid \\cdots \\mid U\\vec{\\Sigma_r} \\mid\n      U\\vec{\\Sigma_{r+1}} \\mid U\\vec{\\Sigma_{r+2}} \\mid \\cdots \\mid U\\vec{\\Sigma_{n}} \n    \\end{bmatrix} &= \\\\[1ex]\n  & \\begin{bmatrix}\n      U\\vec{\\Sigma_1} \\mid U\\vec{\\Sigma_2} \\mid \\cdots \\mid U\\vec{\\Sigma_r} \\mid\n      \\smash{\\underbrace{U\\vec{0} \\mid U\\vec{0} \\mid \\cdots\n          \\mid U\\vec{0}}_{n - r}}\n    \\end{bmatrix} &= \\\\[2.5ex]\n  & \\begin{bmatrix}\n      U\\vec{\\Sigma_1} \\mid U\\vec{\\Sigma_2} \\mid \\cdots \\mid U\\vec{\\Sigma_r} \\mid\n      \\smash{\\underbrace{\\vec{0} \\mid \\vec{0} \\mid \\cdots \\mid \\vec{0}}_{n-r}} \n    \\end{bmatrix} &= \\\\[0.5ex]\n\\end{align*}\n\nThe last $n - r$ zero vectors were a consequence of the definition of\n$\\Sigma$, which only has non-zeroes on diagonal up to position\n$r$. And the columns $U\\vec{\\Sigma_i}$ can be simplified further, as\neach column vector \\vec{\\Sigma_i} has the only non-zero entry\n$\\sigma_i$ precisely at position $i$. Hence, only column $i$ of $U$\nsurvives after multiplying it by \\vec{\\Sigma_i}, and the final effect\nis just the multiplication by scalar $\\sigma_i$:\n\n\\[\n U \\Sigma = \n\\begin{bmatrix}\n   U\\vec{\\Sigma_1} \\mid U\\vec{\\Sigma_2} \\mid \\cdots \\mid U\\vec{\\Sigma_r} \\mid\n   \\smash{\\underbrace{\\vec{0} \\mid \\vec{0} \\mid \\cdots \\mid \\vec{0}}_{n-r}}\n\\end{bmatrix} = \n\\begin{bmatrix}\n   \\sigma_1\\vec{u_1} \\mid \\sigma_2\\vec{u_2} \\mid \\cdots \\mid \\sigma_1\\vec{u_r} \\mid\n   \\smash{\\underbrace{\\vec{0} \\mid \\vec{0} \\mid \\cdots \\mid \\vec{0}}_{n-r}}\n\\end{bmatrix}\n\\]\n\\hfill\n\nIf we put together the developments for each side, we are almost done:\n\n\\begin{align*}\n  & A V &= \\\\[1.5ex]\n  & \\begin{bmatrix}\n    \\sigma_1\\vec{u_1} \\mid \\sigma_2\\vec{u_2} \\mid \\cdots \\mid \\sigma_r\\vec{u_r} \\mid\n    \\smash{\\underbrace{A\\vec{v_{r+1}} \\mid A\\vec{v_{r+2}} \\mid \\cdots \\mid A\\vec{v_{n}}}_{n-r}}\n  \\end{bmatrix}  &= \\\\[3.5ex]\n  & \\begin{bmatrix}\n    \\sigma_1\\vec{u_1} \\mid \\sigma_2\\vec{u_2} \\mid \\cdots \\mid \\sigma_1\\vec{u_r} \\mid\n    \\smash{\\underbrace{\\vec{0} \\mid \\vec{0} \\mid \\cdots \\mid \\vec{0}}_{n-r}}\n  \\end{bmatrix} &= \\\\[1.5ex]\n  & U \\Sigma\n\\end{align*}\n\\hfill\n\n\\end{proof}\n\nIt can be observed that the proof is not complete, though we are\nalmost done; in order to achieve an equality between $AV$ and\n$U\\Sigma$, the only missing part is that the last $n-r$ items on each\nside are the same. This can be restated in an additional theorem: \\\\\n\n\\begin{restatable}[SVD Part2: basis of null space]{theorem}{svdtwo}\n\\label{thm:SVD2}\nAssuming same definitions as \\cref{thm:SVD1}, it must be the case that:\n\n\\[\nA\\vec{v_i} = \\vec{0}, \\textds{for} (r+1) \\le i \\le n\n\\]\n\nwhich is equivalent to say that those vectors \\vec{v_i}, belong to the\nnull space of $A$ (they actually form a basis of it).\n\\end{restatable}\n\nWe do not have yet the required machinery to proof \n\\cref{thm:SVD2}, but we will do it on the next section, when we\nintroduce the subspaces associated with each matrix $A$. \\\\\n", "meta": {"hexsha": "5ddde182a1c432266fea3fadafc030892037af77", "size": 6131, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-proof-spec-fact.tex", "max_stars_repo_name": "rzavalet/svd-lsi-project-master", "max_stars_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "svd-proof-spec-fact.tex", "max_issues_repo_name": "rzavalet/svd-lsi-project-master", "max_issues_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "svd-proof-spec-fact.tex", "max_forks_repo_name": "rzavalet/svd-lsi-project-master", "max_forks_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.4393063584, "max_line_length": 95, "alphanum_fraction": 0.6602511825, "num_tokens": 2274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.7176019226041861}}
{"text": "\\subsection{Examples}\r\n\r\n\\begin{frame}{Universal Hashing}{Examples}\r\n  \\textbf{Negative example:}\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      The set of all {\\color{MainA}$h$} for which\r\n      {\\color{MainA}$h_a(x) = (a \\cdot x) \\mod m$, for a $a \\in \\mathbb{U}$}\r\n    \\item<3->\r\n      It is not {\\color{MainA}$c$}-universal. \\onslide<3-| handout: 0>{Why?}\r\n    \\item<4->\r\n      If universal:\r\n      {\\color{MainA}\r\n      \\begin{displaymath}\r\n        \\forall x, y \\hspace{1em} x \\neq y\\!: \\; \\frac{\r\n          \\vert \\{h \\in \\mathbb{H}: h(x) = h(y)\\} \\vert\r\n        }{\r\n          \\vert \\mathbb{H} \\vert\r\n        } \\leq c \\cdot \\frac{1}{m}\r\n       \\end{displaymath}}\r\n    \\vspace{-1em}\r\n    \\item<5->\r\n      Which {\\color{MainA}$x, y$} lead to a relative collision count bigger than {\\color{MainA}$\\frac{c}{m}$}?\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Examples}\r\n  \\textbf{Positive example:}\r\n  \\begin{itemize}\r\n    \\item<1->\r\n      Let {\\color{MainA}$p$} be a big prime number, {\\color{MainA}$p > m$}\r\n      and {\\color{MainA}$p \\geq \\vert \\mathbb{U} \\vert$}\r\n    \\item<2->\r\n      Let {\\color{MainA}$\\mathbb{H}$} be the set of all {\\color{MainA}$h$}\r\n      for which:\r\n      {\\color{MainA}\r\n      \\begin{align*}\r\n        h_{a, b}(x) = ((a \\cdot x + b) \\mod p) \\mod m,\\\\\r\n        \\hspace*{1.5em} \\text{{\\color{black}where }}\r\n        1 \\leq a < p, \\; 0 \\leq b < p\r\n      \\end{align*}}\r\n    \\item<3->\r\n      This is {\\color{MainA}$\\approx1$-universal},\r\n      see {\\color{teal}Exercise 4.11} in Mehlhorn/Sanders\r\n    \\item<4->\r\n      E.g.: {\\color{MainA}$U=\\{0,...,99\\},$ \\hspace{0.5em} $p=101,$\r\n        \\hspace{0.5em} $a=47,$ $b=5$}\r\n   \\item<5->\r\n     Then {\\color{MainA}$h(x) = ((47 \\cdot x + 5) \\mod 101) \\mod m$}\r\n   \\item<6->\r\n     Easy to implement but hard to proof\r\n   \\item<7->\r\n     Exercise: show empirically that it is {\\color{MainA}$2$}-universal\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Examples}\r\n  \\textbf{Positive example:}\r\n  \\begin{itemize}\r\n    \\item<1->\r\n      The set of hash functions is {\\color{MainA}$c$}-universal:\r\n      {\\color{MainA}\r\n      \\[h_{a}(x) = a \\bullet x \\mod m, \\hspace*{1.5em} a \\in \\mathbb{U}\\]}\r\n    \\item<2->\r\n      \\textbf{We define:}\r\n      {\\color{MainA}\r\n      \\begin{align*}\r\n        a &= \\sum_{0, \\ldots, k-1} a_i \\cdot m^i,\r\n        \\hspace*{1.5em} k = \\mathrm{ceil}(\\log_m \\vert \\mathbb{U} \\vert)\\\\\r\n        x &= \\sum_{0, \\ldots, k-1} x_i \\cdot m^i\r\n      \\end{align*}}\r\n    \\item<3->\r\n      \\textbf{Intuitive}: scalar product with base {\\color{MainA}$m$}\r\n      {\\color{MainA}\r\n      \\begin{align*}\r\n        a \\bullet x &= \\sum_{0, \\ldots, k-1} a_i \\cdot x_i\r\n      \\end{align*}}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Examples}\r\n  \\begin{example}[$\\mathbb{U} = \\{0, \\dots, 999\\}, \\; m = 10, \\; a = 348$]% \r\n    With $a=348$: $a_2 = 3, \\; a_1 = 4, \\; a_0 = 8$\r\n    \\begin{align*}\r\n      h_{348}(x) &= (a_2 \\cdot x_2 + a_1 \\cdot x_1 + a_0 \\cdot x_0) \\mod m\\\\\r\n      {} &= (3 \\, x_2 + 4 \\, x_1 + 8 \\, x_0) \\mod 10\r\n    \\end{align*}\r\n    With $x = 127$: $x_2 = 1, \\; x_1 = 2, \\; x_0 = 7$\r\n    \\begin{align*}\r\n      h_{348}(127) &= (3 \\cdot x_2 + 4 \\cdot x_1 + 8 \\cdot x_0) \\mod 10\\\\\r\n      {} &= (3 \\cdot 1 + 4 \\cdot 2 + 8 \\cdot 7) \\mod 10\\\\\r\n      {} &= 7\r\n    \\end{align*}\r\n  \\end{example}\r\n\\end{frame}\r\n", "meta": {"hexsha": "b81ab02ead3c988f409d71c36089ee8b0dae9c9d", "size": 3584, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-5/Chapter/eng/060_UniversalHashing_Examples.tex", "max_stars_repo_name": "TobiOnline/AlgoDat", "max_stars_repo_head_hexsha": "565a9f03a9ed7ef354cb4f143959df77df89b726", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2016-12-16T17:42:34.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-26T11:07:16.000Z", "max_issues_repo_path": "Lecture-5/Chapter/eng/060_UniversalHashing_Examples.tex", "max_issues_repo_name": "TobiOnline/AlgoDat", "max_issues_repo_head_hexsha": "565a9f03a9ed7ef354cb4f143959df77df89b726", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2016-10-08T09:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-20T15:40:10.000Z", "max_forks_repo_path": "Lecture-5/Chapter/eng/060_UniversalHashing_Examples.tex", "max_forks_repo_name": "TobiOnline/AlgoDat", "max_forks_repo_head_hexsha": "565a9f03a9ed7ef354cb4f143959df77df89b726", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2016-10-07T11:55:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-05T08:36:38.000Z", "avg_line_length": 35.137254902, "max_line_length": 111, "alphanum_fraction": 0.4782366071, "num_tokens": 1346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.717601922522767}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\subsection{Worksheet - Energy and the Hamiltonian}\n\\begin{p}\nShow that if a coordinate transformation is \"natural\" (no explicit time-dependence, $\\v{r} = \\v{r}(q_1, \\cdots, q_n)$) that the kinetic energy is a homogenous quadratic function of the velocities (a function is homogenous of degree $k$ if $f(\\alpha x) = \\alpha^kf(x)$. Find this quadratic function.\n\\end{p}\n\\begin{s}\nNote that any function that is a power law will satisfy this property; it turns out that kinetic energy has this property (as we know). To solve the problem, we consider $\\dot{\\v{r}}_j$:\n\\[\\dot{\\v{r}}_j = \\sum_{i=1}^n\\dpd{\\v{r}_j}{q_i}\\dot{q}_i\\]\nTo calculate $\\dot{\\v{r}}_j^2$, we multiply the two sums:\n\\[\\dot{\\v{r}}_j^2 = \\left(\\sum_i\\dpd{\\v{r}_j}{q_i}\\dot{q}_i\\right)\\left(\\sum_k\\dpd{\\v{r}_j}{q_k}\\dot{q}_k\\right)\\]\nThis gives us:\n\\[T = \\frac{1}{2}\\sum_jm_j\\dot{\\v{r}}_j^2 = \\frac{1}{2}\\sum_{i,k}\\dot{q}_i\\dot{q}_j\\left(\\sum_j m_j\\dpd{\\v{r}_j}{q_i}\\dpd{\\v{r}_j}{q_k}\\right)\\]\nThis term on the right is a matrix which we can call $A_{ik}$. Once we sum over these components, we get the total energy. Now we can see that this is homogenous, quadratic in $\\dot{\\v{r}}_j$.\n\\end{s}\n\n\\begin{p}\nShow then that the conjugate momenta have the form $p_i = \\sum_j A_{ij}\\dot{q}_j$, and thus that the hamiltonian $\\HH = E$, the total energy. Thus, under the above conditions, symmetry under time translation is equivalent to conservation of energy.\n\\end{p}\n\\begin{s}\nUsing the result from above:\n\\[p_i = \\dpd{\\LL}{\\dot{q}_i} = \\dpd{T}{\\dot{q}_i}  = \\sum_j A_{ij}\\dot{q}_j\\]\nTherefore:\n\\[\\sum_i p_i\\dot{q}_i = \\sum_i\\left(\\sum_j A_{ij} \\dot{q}_j\\right)\\dot{q}_i = \\sum_{i,j}A_{ij} \\dot{q}_i\\dot{q}_j = 2T\\]\nHence (using the defintion of $\\HH$ from lecture):\n\\[\\HH = 2T - \\LL = 2T - (T - U) = T + U = E\\]\nWhich is just the total energy.\n\\end{s}\n\n\\begin{p}\nShow that the same derivation follows directly by using the property that the kinetic energy is a homogenous function of degree 2 in the generalized velocities (use Euler’s homogeneity theorem: $f$ is positively homogenous of degree $k$ if and only if $\\v{x}\\cdot\\grad{f(\\v{x}} = kf(\\v{x})$.\n\\end{p}\n\\begin{s}\nWe have (letting $\\v{x} = \\dot{\\v{q}}$:\n\\[\\dot{\\v{q}} \\cdot \\dpd{T}{\\dot{\\v{q}}} = \\sum_i p_i \\dot{q}_i = 2T\\]\nWhere the last line follows from the homogeneity theorem.\n\\end{s}\n\\end{document}", "meta": {"hexsha": "dbd8543bfa53a9c1d3c01e85fa0551b3fb8a80da", "size": 2390, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-7/Worksheet-7.tex", "max_stars_repo_name": "RioWeil/PHYS306-notes", "max_stars_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture-7/Worksheet-7.tex", "max_issues_repo_name": "RioWeil/PHYS306-notes", "max_issues_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture-7/Worksheet-7.tex", "max_forks_repo_name": "RioWeil/PHYS306-notes", "max_forks_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.2820512821, "max_line_length": 298, "alphanum_fraction": 0.6815899582, "num_tokens": 863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.7176019211434186}}
{"text": "\\documentclass[12pt, a4paper, twoside,draft]{article}\n\\usepackage{amsmath}\n\\usepackage{framed}\n\n\\newcommand{\\norm}[1]{\\left\\lVert#1\\right\\rVert}\n\n\\title{CASSANDRA (draft)\\\\ A framework for tensorial prediction \\\\ v0.1}\n\n\n\\date{\\today}\n% \\date{\\today} date coulde be today\n% \\date{25.12.00} or be a certain date\n% \\date{ } or there is no date\n\\begin{document}\n\\maketitle\n\n\\section{Abstract}\nWe present a method for tensorial prediction using a convolutional blind decomposition approach (filters convolved with activations) where the activation variables are shared between the input and the output.\n\n\\section{A framework for tensor evolution prediction using a tensor-based spectral convolutional method}\n\n\\subsection{Analysis Formulation - Multiple Tensors + Spectral Data fit}\nLet $\\mathbf{X} = [\\mathbf{X}_1, \\hdots, \\mathbf{X}_D ]$ be a collection of $D$ tensors.\n\\begin{framed}\n\\textbf{Analysis formulation:} Identification of a common compositional structure (filters) among the $D$ tensors such that the $D$ tensors can be reconstructed, within a margin of error, by a finite sum of tensorial convolutions of the compositional structures (filters) and an activations of the compositional structures (activations).\n\\end{framed}\nThis can be achieved through the following optimization problem:\n\\begin{align}\nf, \\left[ \\begin{matrix}h_1 \\\\ \\vdots \\\\ h_D \\end{matrix} \\right] = \\arg \\min_{f,h} \\left\\Vert \\left[ \\begin{matrix}\\mathbf{X}_1 \\\\ \\vdots \\\\ \\mathbf{X}_D \\end{matrix} \\right] - \\sum_k f_k \\ast  \\left[ \\begin{matrix}h_{1,k} \\\\ \\vdots \\\\ h_{D,k} \\end{matrix} \\right] \\right\\Vert,\n\\end{align}\nwhere $f_j$ denotes the $j$th compositional structure (filter) and $h_{i,j}$ denotes the activation of the $j$th compositional structure on the $i$th tensor ($X_i$).\nThis problem is biconvex and, generally, ill-defined, as the solution might not be unique (multiple combinations of filters and activations can reconstruct the collection of tensors).\nTo address the biconvexity of the problem, we find an approximate solution through an alternating optimization of the filters and their activations, in convex subproblems (addressed further ahead).\nTo address the fact that this optimization problem can be ill-defined, we can introduce priors on the activations (\\emph{e.g.} sparse activations, activations smooth or piecewise smooth activations in specific dimensions, ...) or in the filters (\\emph{e.g.} filters with fixed components in a number of dimensions, smooth or piecewise smooth activations in specific dimensions, ...).\nOur problem becomes then:\n\\begin{align}\nf, \\left[ \\begin{matrix}h_1 \\\\ \\vdots \\\\ h_D \\end{matrix} \\right] = \\arg \\min_{f,h} \\underbrace{\\left\\Vert \\left[ \\begin{matrix}\\mathbf{X}_1 \\\\ \\vdots \\\\ \\mathbf{X}_D \\end{matrix} \\right] - \\sum_k f_k \\ast  \\left[ \\begin{matrix}h_{1,k} \\\\ \\vdots \\\\ h_{D,k} \\end{matrix} \\right] \\right\\Vert }_{\\textrm{data fit}} + \\underbrace{\\mathcal{P}_h(h) + \\mathcal{P}_f(f) }_\\textrm{prior information},\n\\end{align}\nwhere $\\mathcal{P}_h(h)$ denotes a prior on the activations and $\\mathcal{P}_f(f)$ denotes a prior on the filters.\n\nThe solution of the data fit component of the optimization problem is computationally challenging as the data and the filters increase in number of dimensions and size.\nWe note however, that we can efficiently solve the data fit problem in the spectral domain as\n\\begin{align}\n  \\arg \\min_{f,h} & \\left\\Vert \\left[ \\begin{matrix}\\mathbf{X}_1 \\\\ \\vdots \\\\ \\mathbf{X}_D \\end{matrix} \\right] - \\sum_k f_k \\ast  \\left[ \\begin{matrix}h_{1,k} \\\\ \\vdots \\\\ h_{D,k} \\end{matrix} \\right] \\right\\Vert  &=   \\nonumber \\\\\n  \\arg \\min_{f,h} & \\left\\Vert \\mathcal{F}\\left(\\left[ \\begin{matrix}\\mathbf{X}_1 \\\\ \\vdots \\\\ \\mathbf{X}_D \\end{matrix} \\right] - \\sum_k f_k \\ast  \\left[ \\begin{matrix}h_{1,k} \\\\ \\vdots \\\\ h_{D,k} \\end{matrix} \\right] \\right) \\right\\Vert & = \\nonumber \\\\\n  \\arg \\min_{f,h} & \\left\\Vert \\mathcal{F}\\left(\\left[ \\begin{matrix}\\mathbf{X}_1 \\\\ \\vdots \\\\ \\mathbf{X}_D \\end{matrix} \\right] \\right) - \\mathcal{F}\\left(\\sum_k f_k \\ast  \\left[ \\begin{matrix}h_{1,k} \\\\ \\vdots \\\\ h_{D,k} \\end{matrix} \\right] \\right) \\right\\Vert & = \\nonumber \\\\\n  \\arg \\min_{f,h} & \\left\\Vert \\mathcal{F}\\left(\\left[ \\begin{matrix}\\mathbf{X}_1 \\\\ \\vdots \\\\ \\mathbf{X}_D \\end{matrix} \\right] \\right) - \\sum_k \\mathcal{F}(f_k)   \\mathcal{F}\\left(\\left[ \\begin{matrix}h_{1,k} \\\\ \\vdots \\\\ h_{D,k} \\end{matrix} \\right] \\right) \\right\\Vert &\n\\end{align}\nwhere $\\mathcal{F}$ denotes the Fourier transform.\n\n\\subsection{Prediction Formulation}\nLet $\\mathbf{X} = [\\mathbf{X}_1, \\hdots, \\mathbf{X}_D ]$ be a collection of $D$ tensors representing $D$ different social signals, and\n$\\mathbf{Y} = [\\mathbf{Y}_1, \\hdots, \\mathbf{Y}_M]$ a collection of $M$ tensors representing $M$ target social signals (social signals we want to predict).\nOur goal is the estimation of $\\mathbf{Y}$ from the knowledge of the \\emph{directed} patterns of interaction $\\mathbf{X} \\rightarrow \\mathbf{Y}$.\n\nThe  estimation of the directed patterns of interaction allows not only to understand patterns of interaction from a causality point of view (not approached in this document) but also to estimate $\\mathbf{Y}$ given $\\mathbf{X}$.\nThis is of utmost importance in the prediction of time-series and tensor evolution.\n\nWe approach the problem from the same approach as the analysis part.\n\\begin{align}\nf_1,h_1 = \\arg\\min_{f,h} \\| \\mathbf{X} - \\sum_{k=1}^{k_1} f_k \\ast h_k \\| + \\mathcal{P}_h(h) + \\mathcal{P}_f(f),\n\\end{align}\nwhere $\\mathcal{P}_h$ and  $\\mathcal{P}_f$ denote priors on the activations and filters, respectively.\nThis problem can be solved in the spectral domain as follows,\n\\begin{align}\nf_1,h_1 = \\arg\\min_{f,h} \\| \\mathbf{X} -  \\sum_{k=1}^{k_1}  \\mathcal{F}(f_k)  \\mathcal{F}(  h_k) \\| + \\mathcal{P}_h(h) + \\mathcal{P}_f (f),\n\\end{align}\nwhere $\\mathcal{F}(.)$ denotes the Fourier transform operator.\nAssuming convexity of the priors on the activations and filters, this is a biconvex problem, which can be solved approximately as,\n\\begin{align}\n  f^{t+1} = \\arg\\min_{f} \\|  \\mathcal{F}(\\mathbf{X}) - \\sum_{k=1}^{k_1}  \\mathcal{F}(f_k)  \\mathcal{F}(  h^{t}_k) \\| + \\mathcal{P}_f (f), \\\\\n h^{t+1} = \\arg\\min_{h} \\|  \\mathcal{F}(\\mathbf{X}) - \\sum_{k=1}^{k_1}  \\mathcal{F}(f^{t+1}_k) \\mathcal{F}(  h_k) \\| +  \\mathcal{P}_h (h).\n\\end{align}\nThis corresponds to finding simultaneously the filters and the activations for $\\mathbf{X}$.\n\nWe then find the filters $g$ such that,\n\\begin{align}\ng = \\arg\\min_{g} \\|  \\mathcal{F}(\\mathbf{Y}) - \\sum_{k=1}^{k_1}  \\mathcal{F}(g_k) \\mathcal{F}(  h_k) \\| + \\mathcal{P}_h(h) + \\mathcal{P}_g(g).\n\\end{align}\nThis means that we find filters $g$ such that we can reconstruct $\\mathbf{Y}$ from the filters $g$ and the activations derived from $\\mathbf{X}$.\n\nThe pair of filters $f$ and $g$ provide a path between the known and accessible $\\mathbf{X}$ and the unknown and $\\mathbf{Y}$,\n\\begin{align}\n  \\textrm{train} & \\nonumber\\\\\n&  (\\mathbf{X}_\\textrm{train}) \\rightarrow (\\underline{f},h) \\\\\n  & (\\mathbf{Y}_\\textrm{train}, h) \\rightarrow(\\underline{g}) \\\\\n  \\nonumber \\\\\n  \\textrm{predict} & \\nonumber \\\\\n  & (\\mathbf{X}_\\textrm{test}, \\underline{f}) \\rightarrow (h_\\textrm{test})\\\\\n&  (h_\\textrm{test}, \\underline{g}) \\rightarrow (\\mathbf{Y}_\\textrm{predicted})\n\\end{align}\n\n\\end{document}\n", "meta": {"hexsha": "614ca1c5a4654b1edf10f9f3f3d30b8cb07cf272", "size": 7295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "white paper/white_paper.tex", "max_stars_repo_name": "fcondessa/kassandra", "max_stars_repo_head_hexsha": "c8d9213ace30f1749af15191a64a9ea960e231d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "white paper/white_paper.tex", "max_issues_repo_name": "fcondessa/kassandra", "max_issues_repo_head_hexsha": "c8d9213ace30f1749af15191a64a9ea960e231d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "white paper/white_paper.tex", "max_forks_repo_name": "fcondessa/kassandra", "max_forks_repo_head_hexsha": "c8d9213ace30f1749af15191a64a9ea960e231d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 77.6063829787, "max_line_length": 391, "alphanum_fraction": 0.7065113091, "num_tokens": 2379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159727, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.717518016785261}}
{"text": "\\section{Distance}\n\\label{sec:Distance}\nIn order to measure the similarity of different samples, the Dynamic Time Warping (DTW) algorithm was used. DTW compares sequences of feature vectors to one another, even if the sequences are of different lengths. This is important, since the samples in our sample base have different lengths. DTW stretches and compresses sample feature vector sequences for maximum similarity. It can thus find similarities in samples that are time-stretched versions of one another or that contain each other.\\\\\nDTW first compares every feature vector of one sample to every feature vector of another sample by calculating the Euclidean distance between each feature vector. This creates a cost matrix $C$ of distances between every block $f_n$ of the first sample to every block $f'_m$ of the second sample. This matrix is of dimension $N \\times M$, where $N$ and $M$ are the lengths of the feature sequences of both samples, respectively.\\\\\n\\[\n    C_{n,m} = ||f_n - f'_m||\n\\]\nThen, DTW searches for the cheapest path through $C$. In order to not having to search every possible path through this matrix, DTW only calculates the cheapest path $P_{n,m}$ from $C_{0,0}$ to $C_{n,m}$ for every positive time step from $P_{n-1,m}, P_{n,m-1}, P_{n-1,m-1}$ to $P_{n,m}$. This can be done recursively for all $n,m$ by starting from low $n,m$ and working line- or column-wise towards high $n,m$.\\\\\n\\[\n    P_{n,m} = \\min \\left(\n    \\begin{array}{rll}\n      P_{n-1,m}   &+ &C_{n,m} \\cdot c_\\text{horz}\\\\\n      P_{n,m-1}   &+ &C_{n,m} \\cdot c_\\text{vert}\\\\\n      P_{n-1,m-1} &+ &C_{n,m} \\cdot c_\\text{diag}\n    \\end{array}\n    \\right)\n\\]\nwhere $c_\\text{horz} = \\frac{1}{N}$, $c_\\text{vert} = \\frac{1}{M}$, and $c_\\text{diag} = ||\\frac{1}{N},\\frac{1}{M}||$ are the stepping distances through the matrix.\\\\\nThe final distance between the samples is then calculated by adding all the steps $C_{n,m} \\cdot c_\\text{x}$ on the cheapest paths from $C_{0,0}$ to $C_{N,M}$. This sum is equivalent to $P_{N,M}$. The stepping distances ensure that sample comparisions for long samples are not automatically bigger than sample comparisons of short samples.\\\\\nThis algorithm was implemented in Python, but it was too slow for practical comparisons of big sample sets. Thus, we further implemented it in C and called that version from Python, which provided two orders of magnitude of speedup. Still, calculating all the distances between all the samples in the sample database takes about two hours on a modern computer\\footnote{Since the multiprocessing module in Python seems to have problems with Windowss, calculation times are four times longer there}. This distance matrix was saved as Pandas DataFrame to a HD5 database of 60~Mb.", "meta": {"hexsha": "9188c63848967ff9a6d16c38071ba9cc2a3510d5", "size": 2739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/Distance.tex", "max_stars_repo_name": "bastibe/MusicTagger", "max_stars_repo_head_hexsha": "ed4d6a642f6d624325b3d4fb4bdc022671e24777", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-02T19:16:29.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-02T19:16:29.000Z", "max_issues_repo_path": "Report/Distance.tex", "max_issues_repo_name": "bastibe/MusicTagger", "max_issues_repo_head_hexsha": "ed4d6a642f6d624325b3d4fb4bdc022671e24777", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/Distance.tex", "max_forks_repo_name": "bastibe/MusicTagger", "max_forks_repo_head_hexsha": "ed4d6a642f6d624325b3d4fb4bdc022671e24777", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 136.95, "max_line_length": 576, "alphanum_fraction": 0.7374954363, "num_tokens": 730, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.71751800111887}}
{"text": "% \\section*{Parametric Bootstrap for the 100-year Atlantic wave}\n\n\\subsection*{a)}\nWe will here find the inverse of the atlantic wave distribution, approximated as a \\textit{Gumpel Distribution}. To begin finding an inverse we insert a new variable for the function and solve for x. This is done below\n\n\\[ F(x;\\mu,\\beta))=\\exp\\left(-\\exp\\left(-\\frac{x-\\mu}{\\beta}\\right)\\right), x \\in \\mathbb{R} \\]\nHere we insert $u$ for the function\n\\begin{align*}\n&u = \\exp \\left \\{ -\\exp\\left(-\\frac{x-\\mu}{\\beta}\\right)\\right\\} \\Rightarrow \\ln(u)=-\\exp\\left(-\\frac{x-\\mu}{\\beta}\\right) \\Rightarrow \\\\\n& \\ln\\left\\{\\ln\\left(\\frac{1}{u}\\right)\\right\\}=-\\frac{x-\\mu}{\\beta} \\Rightarrow \\mu-\\beta \\ln \\left \\{\\ln\\left ( \\frac{1}{u}\\right ) \\right \\}=x.\n\\end{align*}\n", "meta": {"hexsha": "7d32cd96cb9132eb9159aaabf3260e4405027bd6", "size": 749, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lab2/Report/task2a.tex", "max_stars_repo_name": "eleijonmarck/computer-intensive", "max_stars_repo_head_hexsha": "eec876e31e21ee104343c985d757b6eecc06b7d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lab2/Report/task2a.tex", "max_issues_repo_name": "eleijonmarck/computer-intensive", "max_issues_repo_head_hexsha": "eec876e31e21ee104343c985d757b6eecc06b7d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab2/Report/task2a.tex", "max_forks_repo_name": "eleijonmarck/computer-intensive", "max_forks_repo_head_hexsha": "eec876e31e21ee104343c985d757b6eecc06b7d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.4166666667, "max_line_length": 218, "alphanum_fraction": 0.6702269693, "num_tokens": 253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.926303732328411, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.7174994893917747}}
{"text": "\\section{ODE Model}\r\nTo begin with a simplistic Ordinary Differential Equation (ODE) model was used. This would help us with forming expectations of the system and parameterization for the upcoming Agent Based Model (ABM). The ODE model is less computationally costly at the tradeoff of not being able to capture complex behaviour when compared to ABM.\r\n\r\nThe model we developed is based on a simple Logistic Model \\cite{Logistic} but with an addition environmental dependence on carrying capacity. The ``environment\" consists of the resources, oxygen and testosterone which have their own equations for production and consumption. Although a real cell would depend on a lot more resources, for simplicity they're all assumed to be in excess. The equations are given below:\r\n\\begin{equation}\r\n  \\frac{dy_i}{dt} = r_i y_i (1 - \\frac{y_i}{K_{min} + \\rho_i f_i(O_2) f_i(test)} )- \\delta_i y_i\r\n  \\label{celleq}\r\n\\end{equation}\r\n\\begin{equation}\r\n  \\frac{dO_2}{dt} = p_{O_2} - \\sum_i \\mu_{O_2,i} y_i - \\lambda_{O_2} O_2\r\n  \\label{o2eq}\r\n\\end{equation}\r\n\\begin{equation}\r\n  \\frac{dtest}{dt} = p_{test} y_{T^p} - \\sum_i \\mu_{test,i} y_i - \\lambda_{test} test\r\n  \\label{testeq}\r\n\\end{equation}\r\n\\begin{equation}\r\n  f_i(res) = \\begin{cases}\r\n    1 &\\text{if } ul_{res,i} \\leq res\\\\\r\n    \\frac{res-ll_{res,i}}{ul_{res,i}-ll_{res,i}} &\\text{if } ll_{res,i} < res < ul_{res,i}\\\\\r\n    0 &\\text{if } res \\leq ll_{res,i}\\\\\r\n  \\end{cases}\r\n  \\label{freseq}\r\n\\end{equation}\r\n\r\nWhere,\r\n\\begin{itemize}\r\n  \\item $i \\in \\{T^+,T^p,T-\\}$ and $res \\in \\{O_2,test\\}$\r\n  \\item $y_i$ is the no. of cells of cell type $i$\r\n  \\item $r_i$ is the population growth rate of cell type $i$\r\n  \\item $\\delta_i$ is the population death rate of cell type $i$\r\n  \\item $K_{min}$ is the carrying capacity in the absence of resources.\r\n  \\item $\\rho_i$ is the carrying capacity coming up through the environment/resources\r\n  \\item $f_{i,res}$ is the functional dependence of cell type $i$ on resource $res$, normalised to 1. Note that $f_{T^-,test}=1$\r\n  \\item $p_{res}$ is the production rate of resource, either as bulk or by cells\r\n  \\item $\\mu_{res,i}$ is the uptake of resource $res$ by cell type $i$. Note that $\\mu_{test,T^-} = 0$\r\n  \\item $\\lambda_{res}$ is the decay rate of resource $res$\r\n  \\item $ll_{res,i}$ is the lower limit/threshold level of resource $res$ for carrying capacity of cell type $i$.\r\n  \\item $ul_{res,i}$ is the upper limit/saturation level of resource $res$ for carrying capacity of cell type $i$.\r\n\\end{itemize}\r\n\r\n\\subsection{Parameters}\r\n\\subsubsection{Resource Normalization}\r\nFor ease of use we took the typical tissue levels (TTL) of a resource and normalised the resource values with it. The corresponding parameters for the resource would also be normalised by the TTL. These values were taken from \\cite{Steward} for oxygen and \\cite{Titus} for testosterone.\r\n\\begin{table}[h]\r\n\\centering\r\n\\begin{tabular}{|l|l|}\r\n  \\hline\r\n  Resource & Value             \\\\\r\n  \\hline\r\n  $O_2$    & 2.5 mmHg          \\\\\r\n  $test$   & 3.74 pmol/g tissue\\\\\r\n  \\hline\r\n\\end{tabular}\r\n\\end{table}\r\n\\subsubsection{Tissue Volume}\r\nSome of the parameters differed from the other in terms of volume/mass of tumour. According to \\cite{Stamey}, the volume of prostate cancer tumour vaired between 0.4 to 12 ml. A tumour volume of 1 ml was assumed for the model, which, translates to 1.03 g.\r\n\\subsubsection{Growth Parameters}\r\nThe following values were taken from \\cite{ATCC-lncap,ATCC-22rv1} for doubling time ($\\tau_d$) and \\cite{Jain} for death rate. Considering the exponential phase of Equation \\ref{celleq} with low cell numbers and excess resources,\r\n\\begin{equation}\r\nr_i = \\frac{ln(2)}{\\tau_d} + \\delta_i\r\n\\end{equation}\r\n\\begin{table}[h]\r\n\\centering\r\n\\begin{tabular}{|l|l|l|l|l|}\r\n  \\hline\r\n  Cell Type & Cell Line & $\\tau_d$ (hr) & $\\delta_i$ (min$^{-1}$) & $r_i$ (min$^{-1}$)    \\\\\r\n  \\hline\r\n  $T^+$     & LNCap     & 34            & $2.5 \\times 10^{-3}$    & $2.84 \\times 10^{-3}$ \\\\\r\n  $T^p$     & 22Rv1     & 40            & $2.5 \\times 10^{-3}$    & $2.79 \\times 10^{-3}$ \\\\\r\n  $T^-$     & PC3       & 25            & $1.6 \\times 10^{-4}$    & $6.23 \\times 10^{-4}$ \\\\\r\n  \\hline\r\n\\end{tabular}\r\n\\end{table}\r\n\\subsubsection{Carrying Capacity}\r\nDue to constitutive dependence on the resources and to avoid divided by zero, $K_{min}$ is set to 1. \\\\\r\nAssuming the equilibrium values of the cells ($y^*$) to be 10000 in the excess of resources, the values of $\\rho$ were obtained on setting Equation \\ref{celleq} to 0,\r\n\\begin{equation}\r\n\\rho_i=\\frac{r_i}{r_i-\\delta_i} y^*\r\n\\end{equation}\r\n\\begin{table}[h]\r\n\\centering\r\n\\begin{tabular}{|l|l|}\r\n  \\hline\r\n  Cell Type & $\\rho$             \\\\\r\n  \\hline\r\n  $T^+$     & $8.35 \\times 10^4$ \\\\\r\n  $T^p$     & $9.62 \\times 10^4$ \\\\\r\n  $T^-$     & $1.34 \\times 10^4$ \\\\\r\n  \\hline\r\n\\end{tabular}\r\n\\end{table}\r\n\\subsubsection{Oxygen uptake and production}\r\nThe following values were taken from \\cite{HailJr}.\r\n\\begin{table}[h]\r\n\\centering\r\n\\begin{tabular}{|l|l|l|}\r\n  \\hline\r\n  Cell Type & Raw value (nmol/min/$10^6$ cells) & Normalised (min$^{-1}$cell$^{-1}$) \\\\\r\n  \\hline\r\n  $T^+$     & 5.5                               & $1.63 \\times 10^{-6}$              \\\\\r\n  $T^p$     & 5.5                               & $1.63 \\times 10^{-6}$              \\\\\r\n  $T^-$     & 3.5                               & $1.04 \\times 10^{-6}$              \\\\\r\n  \\hline\r\n\\end{tabular}\r\n\\end{table}\r\n\\\\Using the uptake values for $T^-$ and assuming the equilibrium value for $O_2$ to be TTL (normalised to 1) in Equation \\ref{o2eq} set to 0,\r\n\\begin{equation}\r\n  p_{O_2} = \\lambda_{O_2} O_2^* + y_i^* \\mu_i\r\n\\end{equation}\r\n\\subsubsection{Testosterone uptake and production}\r\nAssuming the equilibrium value for $test$ to be TTL (normalised to 1) in Equation \\ref{testeq} set to 0, the following constraint is obtained.\r\n\\begin{equation}\r\n  p_{test} - \\mu_{test,T^p} = \\frac{test^* \\lambda_{test}}{y_{T^p}^*} = 4 \\times 10^{-4}\r\n\\end{equation}\r\n\\\\$\\mu_{test,T^+}$ has no constraint and has to be explored.\r\n\\subsubsection{Limits}\r\nSince the resources are normalised to 1, the limits would $\\in [0,1]$. This needs to be explored.\r\n", "meta": {"hexsha": "02100af8e13074cd1bdb7d2d88c4fa8ecef090f6", "size": 6138, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writing/midyear-report/ode.tex", "max_stars_repo_name": "Harshavardhan-BV/Cancer-compe-strat", "max_stars_repo_head_hexsha": "e4decacd5779e85a68c81d0ce3bedf42dea2964f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-18T15:54:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-18T15:54:26.000Z", "max_issues_repo_path": "writing/midyear-report/ode.tex", "max_issues_repo_name": "Harshavardhan-BV/Cancer-compe-strat", "max_issues_repo_head_hexsha": "e4decacd5779e85a68c81d0ce3bedf42dea2964f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "writing/midyear-report/ode.tex", "max_forks_repo_name": "Harshavardhan-BV/Cancer-compe-strat", "max_forks_repo_head_hexsha": "e4decacd5779e85a68c81d0ce3bedf42dea2964f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.5798319328, "max_line_length": 418, "alphanum_fraction": 0.6446725318, "num_tokens": 2010, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552538, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.7174782239710202}}
{"text": "\\section{Syntax to define a mathematical function\\label{parser}}\nIn a mathematical function,\nused for example in field definition, it's possible to use the predifined function (an object parser is used to\nevaluate the functions) :\n\nABS\\ \\ \\ \\ : absolute value function\n\nCOS \\ \\ \\ \\ : cosine function\n\nSIN\\ \\ \\ \\ : sine function\n\nTAN\\ \\ \\ \\ : tangent function\n\nATAN\\ \\ : arctangent function\n\nEXP\\ \\ \\ \\ : exponential function\n\nLN\\ \\ \\ \\ : natural logarithm function\n\nSQRT \\ \\ : square root function\n\nINT\\ \\ \\ \\ : integer function\n\nERF\\ \\ \\ \\ : error function\n\nRND(x)\\ \\ : random function (values between 0 and x)\n\nCOSH\\ \\ \\ \\ : hyperbolic cosine function\n\nSINH\\ \\ \\ \\ : hyperbolic sine function\n\nTANH\\ \\ \\ \\ : hyperbolic tangent function\n\nACOS\\ \\ \\ \\ : inverse cosine function\n\nASIN\\ \\ \\ \\ : inverse sine function\n\nATANH\\ \\ : inverse hyperbolic tangent function\n\nNOT(x)\\ \\ : NOT x (returns 1 if x is false, 0 otherwise) \n\nSGN(x)\\ \\ : SGN x (returns 1 if x is positive, -1 if negative, 0 if zero) \n\nx\\_AND\\_y \\ \\ : boolean logical operation AND (returns 1 if both x and y are true, else 0)\n\nx\\_OR\\_y\\ \\ : boolean logical operation OR (returns 1 if x or y is true, else 0)\n\nx\\_GT\\_y\\ \\ : greater than (returns 1 if x{\\textgreater}y, else 0)\n\nx\\_GE\\_y\\ \\ : greater than or equal to (returns 1 if x{\\textgreater}=y, else 0)\n\nx\\_LT\\_y\\ \\ : less than (returns 1 if x{\\textless}y, else 0)\n\nx\\_LE\\_y\\ \\ : less than or equal to (returns 1 if x{\\textless}=y, else 0)\n\nx\\_MIN\\_y \\ \\ \\ \\ \\ : returns the smallest of x and y\n\nx\\_MAX\\_y \\ \\ \\ \\ : returns the largest of x and y\n\nx\\_MOD\\_y \\ \\ \\ \\ : modular division of x per y\n\nx\\_EQ\\_y \\ \\ \\ \\ \\ \\ \\ \\ : equal to (returns 1 if x==y, else 0)\n\nx\\_NEQ\\_y \\ \\ \\ \\ \\ : not equal to (returns 1 if x!=y, else 0) \n\n\n\\bigskip\n\nYou can also use the following operations:\n\n+\\ \\ : addition\n\n{}- \\ \\ : subtraction\n\n/ \\ \\ : division\n\n*\\ \\ : multiplication\n\n\\%\\ \\ : modulo\n\n\\$\\ \\ : max\n\n\\^{} \\ \\ : power\n\n{\\textless}\\ \\ : less than\n\n{\\textgreater}\\ \\ : greater than\n\n[\\ \\ : less than or equal to\n\n]\\ \\ : greater than or equal to\n\n\n\\bigskip\n\nYou can also use the following constants:\n\nPi \\ \\ : pi value (3,1415{\\dots})\n\n\n\\bigskip\n\nThe variables which can be used are:\n\nx,y,z \\ \\ : coordinates \n\nt \\ \\ : time\n\n\n\\bigskip\n\n{\\bfseries\nExamples:}\n\nChamp\\_front\\_fonc\\_txyz\\index{Champ\\_front\\_fonc\\_txyz} \\ 2 \\ cos(y+x\\^{}2) \\ t+ln(y)\n\nChamp\\_fonc\\_xyz\\index{xyz} dom 2 tanh(4*y)*(0.95+0.1*rnd(1)) 0.\n\n\n\\bigskip\n\n{\\bfseries\nPossible errors:}\n\nError 1:\n\nChamp\\_fonc\\_txyz 1 \\ cos(10*t)*(1{\\textless}x{\\textless}2)*(1{\\textless}y{\\textless}2)\n\nPrevious line is wrong. It should be written as:\n\nChamp\\_fonc\\_txyz 1 \\ cos(10*t)*(1{\\textless}x)*(x{\\textless}2)*(1{\\textless}y)*(y{\\textless}2)\n\n\\bigskip\nError 2:\n\nChamp\\_front\\_fonc\\_xyz 1 \\ 20*(x{\\textless}-2)+10*(y]-5)+3*(z{\\textgreater}0)\n\nPrevious line is wrong because negative values are not written between parentheses. It should be written as:\n\nChamp\\_front\\_fonc\\_xyz 1 \\ 20*(x{\\textless}(-2))+10*(y](-5))+3*(z{\\textgreater}0)\n", "meta": {"hexsha": "6c470a135c4fd3993eb000e7002eaefb324f9a30", "size": 2996, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Outils/TRIOXDATA/XTriou/doc_ressources/parser.tex", "max_stars_repo_name": "cea-trust-platform/trust-code", "max_stars_repo_head_hexsha": "c4f42d8f8602a8cc5e0ead0e29dbf0be8ac52f72", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-06-30T18:50:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T09:03:16.000Z", "max_issues_repo_path": "Outils/TRIOXDATA/XTriou/doc_ressources/parser.tex", "max_issues_repo_name": "pledac/trust-code", "max_issues_repo_head_hexsha": "46ab5c5da3f674185f53423090f526a38ecdbad1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Outils/TRIOXDATA/XTriou/doc_ressources/parser.tex", "max_forks_repo_name": "pledac/trust-code", "max_forks_repo_head_hexsha": "46ab5c5da3f674185f53423090f526a38ecdbad1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-10-04T09:19:39.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T14:21:04.000Z", "avg_line_length": 21.2482269504, "max_line_length": 111, "alphanum_fraction": 0.6488651535, "num_tokens": 1012, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039739, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7174782095103923}}
{"text": "\n\\subsection{Random forests}\n\nThese use bagging techniques with random trees.\n\nAt each node, rather than sample the whole data we sample a random selection.\n\nGet \\(d\\) dimensions, and sample \\(m\\) of them at each node.\n\nChoose \\(m\\le \\sqrt d\\)\n\n\n", "meta": {"hexsha": "ddd9aac2096a9695b02f7aedb3a932c2d3b038ea", "size": 246, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/treesEnsemble/01-05-randomForests.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/treesEnsemble/01-05-randomForests.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/treesEnsemble/01-05-randomForests.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.9230769231, "max_line_length": 77, "alphanum_fraction": 0.7276422764, "num_tokens": 59, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.7174026295254025}}
{"text": "%!TEX root = paper.tex\r\n\\subsection{Depth-averaged \\nheswe}\r\nThe linearized system of equations \\eqref{eq:nh_conti}--\\eqref{eq:nh_closure} reduces to \r\n\\begin{align*}\r\n 0 &= \\partial_t\\xi+\\partial_x(du), \\\\\r\n \\partial_tu + g\\partial_x\\xi &= \\frac{1}{2\\fnh}d^2\\partial_{txx} u,\r\n%  \\label{eq:nh_1D_Bouss_Disp}\r\n\\end{align*}\r\nwhere the scalar $\\fnh$ determines the vertical pressure profile. The resulting dispersion relation is\r\n\\begin{equation}\r\n \\omega^2_{\\text{nh,}\\fnh}=\\frac{\\csw^2\\kappa^2}{1+\\frac{(\\kappa d)^2}{2\\fnh}},\r\n \\label{eq:disp_nh_fnh}\r\n\\end{equation}\r\nwhere $\\csw=\\sqrt{gd}$ is the linear shallow water gravity wave speed.\r\nThe dispersion relation resulting from the quadratic vertical pressure profile ($\\fnh=\\frac{3}{2}$) is the same as for the Serre equations, so\r\n\\begin{equation}\r\n \\omega^2_{\\text{nh,quad}}=\\frac{\\csw\\kappa^2}{1+\\frac{(\\kappa d)^2}{3}}=\\csw^2\\kappa^2\\left(1-\\frac{1}{3}(kd)^2+\\frac{1}{9}(kd)^4+\\mathcal{O}(kd)^6 \\right),\r\n \\label{eq:disp_nh_quadr}\r\n\\end{equation}\r\nwhereas the linear vertical pressure profile ($\\fnh=2$) leads to the dispersion relation\r\n\\begin{equation}\r\n \\omega^2_{\\text{nh,lin}}=\\frac{\\csw^2\\kappa^2}{1+\\frac{(\\kappa d)^2}{4}}=\\csw^2\\kappa^2\\left(1-\\frac{1}{4}(kd)^2+\\frac{1}{16}(kd)^4+\\mathcal{O}(kd)^6 \\right) \\label{eq:disp_nh_lin}\r\n\\end{equation}\r\n% The same result is given in \\cite{Cui.2014} for the linear vertical profile.\r\nFor comparison, the dispersion relation from the full linear inviscid equations\r\nis (see, for instance, \\cite{Whitham.1974})\r\n\\begin{equation}\r\n \\omega^2_{\\text{full}}=g\\kappa\\tanh\\left(\\kappa d  \\right)=\\csw^2\\kappa^2\\left(1-\\frac{1}{3}(kd)^2+\\frac{2}{15}(kd)^4+\\mathcal{O}(kd)^6 \\right) .\r\n \\label{eq:disp_full}\r\n\\end{equation}\r\nTherefore, the quadratic vertical profile of the \\nhp\\ is exact in comparison with the dispersion relation from the full linear inviscid equations up to the first order, whereas the linear profile leads to a match only in the zeroth order.", "meta": {"hexsha": "808d9dc8d3df55466b0a95a87986b35e91e19035", "size": 1961, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/papers/theoretical_1d/D_nonhydrostatic.tex", "max_stars_repo_name": "mandli/coastal", "max_stars_repo_head_hexsha": "8c80a4c740f92ea83b54c8a5432d11058c0d3476", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/papers/theoretical_1d/D_nonhydrostatic.tex", "max_issues_repo_name": "mandli/coastal", "max_issues_repo_head_hexsha": "8c80a4c740f92ea83b54c8a5432d11058c0d3476", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/papers/theoretical_1d/D_nonhydrostatic.tex", "max_forks_repo_name": "mandli/coastal", "max_forks_repo_head_hexsha": "8c80a4c740f92ea83b54c8a5432d11058c0d3476", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.2580645161, "max_line_length": 239, "alphanum_fraction": 0.7072921979, "num_tokens": 690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736692, "lm_q2_score": 0.8175744739711884, "lm_q1q2_score": 0.7174026177082368}}
{"text": "\n\\subsection{Upper Confidence bound 1 applied to Trees (UCT)}\n\n\\subsubsection{Introduction}\n\nWay to choose paths\n\n\\(\\dfrac{w}{n}+c\\sqrt {\\dfrac{\\ln N}{n}}\\)\n\n\\(w\\) is number of wins from node chosen\n\n\\(n\\) is number of simulations from node chosen\n\n\\(N\\) is number of simulations that have happened this many layers in\n\n", "meta": {"hexsha": "4acaac063293963b0f27bf549a9f30ab5c2de3ca", "size": 320, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/gameTheoryDeep/03-02-UCT.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/ai/gameTheoryDeep/03-02-UCT.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/ai/gameTheoryDeep/03-02-UCT.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.0, "max_line_length": 69, "alphanum_fraction": 0.715625, "num_tokens": 87, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404077216356, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.717382535328843}}
{"text": "% Optimal truncation\n\\section{Optimal Truncation}\n\\label{sec:truncation}\n\nIn any decomposition-based approximation the question emerges of how many terms to keep. The optimal value depends both on the true rank of the underlying signal but also the signal to noise ratio: truncating the decomposition of a rank $r$ data matrix at $r$ does not necessarily give the result that minimizes error. Almost always, the suggestion is to use a heuristic method, but it turns out that one can do better. The discussion below uses the context of singular value decomposition, but the problem of optimal truncation is more general and is an example tuning the hyperparameter that determines the capacity of an estimator to mold itself to a dataset.\n\n\n\\subsection{Scree Plots, Heuristic Methods}\n\\label{sec:scree}\nThe canonical heuristic approaches focus on \\textit{scree plots}, which simply show the singular values in decreasing order, or cumulative plots, which show the fraction of the total sum of singular values that the first $n$ singular values add up to. In case of PCA, the cumulative plot is directly interpretable as the fraction of the explained variance by the first $n$ principal components, where the total variance is given by $\\sigma_2 = \\sum_i \\sigma_i^2$. \\\\\n\nA scree plot is sometimes referred to as an \\textit{elbow plot}, and a common approach is to truncate at the elbow, which is known as \\textit{elbow truncation}. Scree refers to the rock fragments that gather at the foot of a steep hill due to erosion, but I wouldn't really know, because I haven't gone outside in a while. \n\nAnother common way to go about this would be to, for example, keep only the singular components that account to 90\\% of the decomposition.\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=\\textwidth]{svd_scree.png}\n    \\caption{Left: Original image of Princess Yvonne und Prince Alexander zu Sayn-Wittgenstein, photographed by their mother, Princess Marianne, in 1955 (1280 by 1277 pixels). Middle: Scree plot, which shows that the first few components are dominant in the image. Right: Cumulative plot that shows that the first singular component accounts for more than 20\\% of the decomposition.}\n    \\label{fig:svd_scree}\n\\end{figure}\n\n\nEither method is not limited to SVD or PCA, but also show up whenever, for example, someone wants to decide on the number of clusters in cluster analysis, the number of regressors in mutlivariate regression (only sometimes), or independent component analysis (ICA).\n\n\n\\subsection{Gavish \\& Donoho's Optimal Threshold for SVD}\n\nI came across this through \\citeasnoun{gavish2013optimal} and Steve Brunton's youtube channel \\cite{stevebrunton}. The idea is the following. Assume that some data matrix $\\mathbf{X}\\in\\mathbb{R}^{N \\times p}$ consists of a signal $\\mathbf{X}_{r}$ with a rank $r$ substructure, and normally distributed noise with mean zero $\\mathbf{X}_{\\epsilon}\\sim \\mathscr{N}(0,\\sigma_{\\epsilon}^2)$. The method assumes that the rank of the signal $r$ is small compared to the rank of $\\mathbf{X}$. \n\n\\begin{equation}\n\\mathbf{X} = \\mathbf{X}_r + \\mathbf{X}_{\\epsilon}\n\\end{equation}\n\nThe distribution of singular values of a matrix $\\mathbf{X}_{\\epsilon}\\sim \\mathscr{N}(0,\\sigma_{\\epsilon}^2)$ is known up to the variance. \\possessivecite{gavish2013optimal} method is to truncate the decomposition of $\\mathbf{X}$ at the singular value that fall below the largest singular value of $\\mathbf{X}_{\\epsilon}$. It turns out that, with respect to average mean square error, this truncation is asymptotically always better than any other truncation and even always better than the true thresholding at rank $r$ when the rank of the underlying signal happens to be known. When the variance of the noise $\\sigma^2_{\\epsilon}$ is not known, then \\citeasnoun{gavish2013optimal} instead use the median singular value of $\\mathbf{X}$. \n\nLet $y_{\\mathrm{med}} = \\mathrm{med}\\{\\sigma_i: 1\\leq0\\leq n\\}$ be the median singular value. Then the optimal hard threshold for a matrix $\\mathbf{X}\\in\\mathbb{R}^{m \\times n}$ is given by:\n\n\\begin{equation}\n\\tau = \\omega(\\beta) y_{\\mathrm{med}}\n\\end{equation}\n\nWhere $\\beta= \\frac{m}{n}$ is the aspect ratio of the matrix $\\mathbf{X}$ so that $0\\leq \\beta \\leq 1$,  and $\\omega(\\beta)$ is a constant that needs to be calculated numerically:\n\n\\begin{equation}\n\\omega(\\beta) = \\frac{\\lambda_{*}(\\beta)}{\\sqrt{\\mu_{\\beta}}}\n\\end{equation}\n\nWhere $\\lambda_{*}(\\beta)$:\n\n\\begin{equation}\n\\lambda_{*}(\\beta) = \\sqrt{2(\\beta+1) + \\frac{8\\beta}{(\\beta+1)+\\sqrt{\\beta^2 + 14\\beta+1}}} \n\\end{equation}\n\nAnd $\\mu_{\\beta}$ is unfortunately the median of the Mar\\v{c}enko-Pastur distribution, which is the unique solution to:\n\n\\begin{equation}\n\\int_{\\beta_{-}^x}\\frac{\\sqrt{(\\beta_{+}-t)(t-\\beta_{-})}}{2\\pi t} \\mathrm{d}t = \\frac{1}{2}\n\\end{equation}\n\nWith $\\beta_{\\pm} = (1\\pm\\beta)^2$. Cautiously, \\citeasnoun{gavish2013optimal} provide the approximation:\n\n\\begin{equation}\n\\omega(\\beta) \\approx 0.56\\beta^3 - 0.95\\beta^2 + 1.82\\beta + 1.43\n\\end{equation}\n\nWhich has error bounded by $\\leq0.02$ on the interval $0.001\\leq\\beta \\leq 1$.\n\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=\\textwidth]{truncated_svd.png}\n    \\caption{Left: Princess and Prince zu Sayn-Wittgenstein with different amounts of Gaussian noise added. Center: The same image estimated using TSVD with Gavish \\& Donoho's approximate rank threshold. Right: Singular value spectrum of original, noise and truncated images. TSVD reduces the average mean square error (AMSE) with respect to the original image by over 50\\%. Visually, the difference is not too perceptible.}\n    \\label{fig:truncated_svd}\n\\end{figure}\n\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=\\textwidth]{truncated_svd2.png}\n    \\caption{Average means square error relative to the original image for the photo with added noise (blue) and after TSVD denoising (organge). The percentage of components retained via Gavish \\& Donoho's approximate rank threshold shown in green. $\\sigma_{\\epsilon}$ is the standard deviation of the added (Gaussian) noise and $\\sigma_0$ is the standard deviation of the pixel values of the original image. When $\\sigma_{\\epsilon}$ is small, G \\& D automatically truncates the TSVD at about 40\\% of the singular values, which is why, at first, the \"denoised\" image has greater error than the noisy issues.}\n    \\label{fig:truncated_svd}\t\n\\end{figure}", "meta": {"hexsha": "eb1351269bec9ef209987dce0702385180441b44", "size": 6400, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/unsup_truncation.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/unsup_truncation.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/unsup_truncation.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 77.1084337349, "max_line_length": 740, "alphanum_fraction": 0.756875, "num_tokens": 1750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7173319204931934}}
{"text": "\\section{Extrema of a Function}\\label{sec:ExtremaSection}\nIn calculus, there is much emphasis placed on analyzing the behaviour\nof a function $f$ on an interval $I$. Does $f$ have a maximum value on $I$?\nDoes it have a minimum value? How does the interval $I$ impact our discussion\nof extrema?\n\n% % % % % % % % % % % %\n% Subsections to include\n\n\\input{5-applications-of-derivatives/5-2-1-local-extrema}\n\\input{5-applications-of-derivatives/5-2-2-absolute-extrema}\n\n% Exercises are at the end of each subsection above\n\n", "meta": {"hexsha": "c385fbbbf17942b54f105ea38517fd28f7a90fe7", "size": 518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-2-0-extrema.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5-applications-of-derivatives/5-2-0-extrema.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5-applications-of-derivatives/5-2-0-extrema.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.5333333333, "max_line_length": 77, "alphanum_fraction": 0.7355212355, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8479677545357568, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7173319139712063}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Conditional probability}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Exploring probabilities with a contingency table}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Relapse}\n\nResearchers randomly assigned 72 chronic users of cocaine into three groups: desipramine (antidepressant), lithium (standard treatment for cocaine) and placebo. Results of the study are summarized below.\n\n{\\small\n\\begin{center}\n\\begin{tabular}{l | c c | c}\n\t\t\t& \t\t& no \t\t&  \\\\\n\t\t\t& relapse\t& relapse\t& total \\\\\n\\hline\ndesipramine\t& 10\t\t& 14\t\t& 24 \\\\\nlithium\t\t& 18\t\t& 6\t\t& 24 \\\\\nplacebo\t\t& 20\t\t& 4\t\t& 24 \\\\\n\\hline\ntotal\t\t\t& 48\t\t& 24\t\t& 72\n\\end{tabular}\n\\end{center}\n}\n\n\\ct{\\webURL{http://www.oswego.edu/~srp/stats/2_way_tbl_1.htm}}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\n\\dq{What is the probability that a patient did not relapse?}\n\n\n{\\small\n\\begin{center}\n\\begin{tabular}{l | c c | c}\n\t\t\t& \t\t& no \t\t&  \\\\\n\t\t\t& relapse\t& relapse\t& total \\\\\n\\hline\ndesipramine\t& 10\t\t& 14\t\t& 24 \\\\\nlithium\t\t& 18\t\t& 6\t\t& 24 \\\\\nplacebo\t\t& 20\t\t& 4\t\t& 24 \\\\\n\\hline\ntotal\t\t\t& 48\t\t& 24\t\t& 72\n\\end{tabular}\n\\end{center}\n}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Marginal and joint probabilities}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Marginal probability}\n\n\\dq{What is the probability that a patient relapsed?}\n\n{\\small\n\\begin{center}\n\\begin{tabular}{l | c c | c}\n\t\t\t& \t\t& no \t\t&  \\\\\n\t\t\t& relapse\t& relapse\t& total \\\\\n\\hline\ndesipramine\t& 10\t\t& 14\t\t& 24 \\\\\nlithium\t\t& 18\t\t& 6\t\t& 24 \\\\\nplacebo\t\t& 20\t\t& 4\t\t& 24 \\\\\n\\hline\ntotal\t\t\t& \\only<1>{48}\\only<2->{\\red{48}}\t\t& 24\t\t&  \\only<1>{72}\\only<2->{\\red{72}}\n\\end{tabular}\n\\end{center}\n}\n\n\\onslide<2->{P(relapsed) = $\\frac{48}{72} \\approx 0.67$} \\\\\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Joint probability}\n\n\\dq{What is the probability that a patient received the antidepressant (desipramine) \\underline{and} relapsed?}\n\n{\\small\n\\begin{center}\n\\begin{tabular}{l | c c | c}\n\t\t\t& \t\t& no \t\t&  \\\\\n\t\t\t& relapse\t& relapse\t& total \\\\\n\\hline\ndesipramine\t& \\only<1>{10} \\only<2->{\\red{10}}\t\t& 14\t\t& 24 \\\\\nlithium\t\t& 18\t\t& 6\t\t& 24 \\\\\nplacebo\t\t& 20\t\t& 4\t\t& 24 \\\\\n\\hline\ntotal\t\t\t& 48\t& 24\t\t&  \\only<1>{72} \\only<2->{\\red{72}}\n\\end{tabular}\n\\end{center}\n}\n\n\\onslide<2->{P(relapsed and desipramine) = $\\frac{10}{72} \\approx 0.14$} \\\\\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Defining conditional probability}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Conditional probability}\n\n\\formula{Conditional probability}{\nThe conditional probability of the outcome of interest $A$ given condition $B$ is calculated as\n\\[ P(A|B) = \\frac{P(A~and~B)}{P(B)} \\]\n}\n\n\\pause\n\n\\twocol{0.5}{0.5}\n{\n{\\small\n\\begin{center}\n\\begin{tabular}{l | c c | c}\n\t\t\t& \t\t& no \t\t&  \\\\\n\t\t\t& relapse\t& relapse\t& total \\\\\n\\hline\ndesipramine\t& 10\t\t& 14\t\t& 24 \\\\\nlithium\t\t& 18\t\t& 6\t\t& 24 \\\\\nplacebo\t\t& 20\t\t& 4\t\t& 24  \\\\\n\\hline\ntotal\t\t\t& 48\t\t& 24\t\t&  72\n\\end{tabular}\n\\end{center}\n}\n}\n{\n\\begin{eqnarray*}\n&&P(relapse |  desipramine) \\\\\n&&= \\frac{P(relapse ~ and ~ desipramine)}{P(desipramine)} \\\\\n\\pause\n&&= \\frac{10 / 72}{24 / 72} \\\\\n\\pause\n&&= \\frac{10}{24} \\\\\n\\pause\n&&= 0.42\n\\end{eqnarray*}\n}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Conditional probability (cont.)}\n\n\\dq{If we know that a patient received the antidepressant (desipramine), what is the probability that they relapsed?}\n\n{\\small\n\\begin{center}\n\\begin{tabular}{l | c c | c}\n\t\t\t& \t\t& no \t\t&  \\\\\n\t\t\t& relapse\t& relapse\t& total \\\\\n\\hline\n\\rowcolor[gray]{.7}\ndesipramine\t& \\only<1>{10} \\only<2->{\\red{10}}\t\t\t& 14\t\t& \\only<1>{24} \\only<2->{\\red{24}} \\\\\nlithium\t\t& 18\t\t& 6\t\t& 24 \\\\\nplacebo\t\t& 20 \t\t& 4\t\t& 24  \\\\\n\\hline\ntotal\t\t\t& 48\t& 24\t\t&  72\n\\end{tabular}\n\\end{center}\n}\n\n\\onslide<2->{P(relapse $|$  desipramine) = $\\frac{10}{24} \\approx 0.42$} \\\\\n\n\\onslide<3->{\n$\\:$ \\\\\nP(relapse $|$  lithium) = $\\frac{18}{24} \\approx 0.75$ \\\\\nP(relapse $|$  placebo) = $\\frac{20}{24} \\approx 0.83$ \\\\\n}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Conditional probability (cont.)}\n\n\\dq{If we know that a patient relapsed, what is the probability that they received the antidepressant (desipramine)?}\n\n{\\small\n\\begin{center}\n\\begin{tabular}{l | >{\\columncolor[gray]{0.7}[0pt]}c c | c}\n\t\t\t& \t\t& no \t\t&  \\\\\n\t\t\t& relapse\t& relapse\t& total \\\\\n\\hline\ndesipramine\t& \\only<1>{10} \\only<2->{\\red{10}}\t\t\t& 14\t\t& 24 \\\\\nlithium\t\t& 18\t\t& 6\t\t& 24 \\\\\nplacebo\t\t& 20\t\t& 4\t\t& 24  \\\\\n\\hline\ntotal\t\t\t& \\only<1>{48} \\only<2->{\\red{48}}\t& 24\t\t&  72\n\\end{tabular}\n\\end{center}\n}\n\n\\onslide<2->{P(desipramine $|$  relapse) = $\\frac{10}{48} \\approx 0.21$} \\\\\n\n\\onslide<3->{\n$\\:$ \\\\\nP(lithium $|$  relapse) = $\\frac{18}{48} \\approx 0.375$ \\\\\nP(placebo $|$  relapse) = $\\frac{20}{48} \\approx 0.42$ \\\\\n}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{General multiplication rule}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{General multiplication rule}\n\n\\begin{itemize}\n\n\\item Earlier we saw that if two events are independent, their joint probability is simply the product of their probabilities. If the events are not believed to be independent, the joint probability is calculated slightly differently.\n\n\\pause\n\n\\item If $A$ and $B$ represent two outcomes or events, then\n\\formula{\\[ P(A~and~B) = P(A|B) \\times P(B) \\]}\nNote that this formula is simply the conditional probability formula, rearranged.\n\\pause\n\n\\item It is useful to think of $A$ as the outcome of interest and $B$ as the condition.\n\n\\end{itemize}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Independence considerations in conditional probability}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Independence and conditional probabilities}\n\nConsider the following (hypothetical) distribution of gender and major of students in an introductory statistics class:\n\n{\\small\n\\begin{center}\n\\begin{tabular}{l | c c | c}\n\t\t\t& social\t& non-social \t\t&  \\\\\n\t\t\t& science\t& science\t& total \\\\\n\\hline\nfemale\t\t& 30\t\t& 20\t\t& 50 \\\\\nmale\t\t\t& 30\t\t& 20\t\t& 50 \\\\\n\\hline\ntotal\t\t\t& 60\t\t& 40\t\t& 100\n\\end{tabular}\n\\end{center}\n}\n\n\\pause\n\n\\begin{itemize}\n\n\\item The probability that a randomly selected student is a social science major is \\pause $\\frac{60}{100} = 0.6$. \n\n\\pause\n\n\\item The probability that a randomly selected student is a social science major given that they are female is \\pause $\\frac{30}{50} = 0.6$. \n\n\\pause\n\n\\item Since $P(SS | M)$ also equals 0.6, major of students in this class does not depend on their gender: P(SS $|$ F) = P(SS).\n\n\\end{itemize}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Independence and conditional probabilities (cont.)}\n\nGenerically, if $P(A|B) = P(A)$ then the events $A$ and $B$ are said to be independent.\n\n\\pause\n\n\\begin{itemize}\n\n\\item Conceptually: Giving $B$ doesn't tell us anything about $A$.\n\n\\pause\n\n\\item Mathematically: We know that if events $A$ and $B$ are independent, $P(A~and~B) = P(A) \\times P(B)$. Then,\n\\[ P(A|B) = \\frac{P(A~and~B)}{P(B)} = \\frac{P(A) \\times P(B)}{P(B)} = P(A) \\]\n\n\\end{itemize}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Tree diagrams}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Breast cancer screening}\n\n\\begin{itemize}\n\n\\item American Cancer Society estimates that about 1.7\\% of women have breast cancer. \\\\\n{\\small\\webURL{http://www.cancer.org/cancer/cancerbasics/cancer-prevalence}}\n\n\\item Susan G. Komen For The Cure Foundation states that mammography correctly identifies about 78\\% of women who truly have breast cancer. \\\\\n{\\small\\webURL{http://ww5.komen.org/BreastCancer/AccuracyofMammograms.html}}\n\n\\item An article published in 2003 suggests that up to 10\\% of all mammograms result in false positives for patients who do not have cancer. \\\\{\\small \\webURL{http://www.ncbi.nlm.nih.gov/pmc/articles/PMC1360940}}\n\n\\end{itemize}\n\n\\vfill\n\n\\Note{These percentages are approximate, and very difficult to estimate.}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Inverting probabilities}\n\n\\dq{When a patient goes through breast cancer screening there are two competing claims: patient had cancer and patient doesn't have cancer. If a mammogram yields a positive result, what is the probability that patient actually has cancer?}\n\n\\pause\n\n\\twocol{0.7}{0.3}{\n\\includegraphics[width=\\textwidth]{3-2_conditional_probability/figures/cancer_tree/cancer_tree_first} \n}\n{\n\\pause\n{\\footnotesize\n\\begin{eqnarray*}\n&&P(C | +) \\\\\n\\pause\n&&= \\frac{P(C~and~+)}{P(+)} \\\\\n\\pause\n&&= \\frac{0.0133}{0.0133 + 0.0983} \\\\\n\\pause\n&&= 0.12\n\\end{eqnarray*}\n}\n}\n\n\\pause\n\n\\Note{Tree diagrams are useful for inverting probabilities: we are given $P(+|C)$ and asked for $P(C|+)$.}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Practice}\n\n\\pq{Suppose a woman who gets tested once and obtains a positive result wants to get tested again. In the second test, what should we assume to be the probability of this specific woman having cancer?}\n\n\\begin{enumerate}[(a)]\n\\item 0.017\n\\solnMult{0.12}\n\\item 0.0133\n\\item 0.88\n\\end{enumerate}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Practice}\n\n\\pq{What is the probability that this woman has cancer if this second mammogram also yielded a positive result?}\n\n\\twocol{0.2}{0.7}\n{\n\\begin{enumerate}[(a)]\n\\item 0.0936\n\\item 0.088\n\\item 0.48\n\\solnMult{0.52}\n\\end{enumerate}\n}\n{\n\\solnGr{\\only<2->{\n\\includegraphics[width=\\textwidth]{3-2_conditional_probability/figures/cancer_tree/cancer_tree_second} \n}}\n}\n\n\\soln{\\only<3->{\n{\\small \\[P(C | +) = \\frac{P(C~and~+)}{P(+)} = \\frac{0.0936}{0.0936+0.088} = 0.52\\]}\n}}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Bayes' Theorem}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Bayes' Theorem}\n\n\\begin{itemize}\n\n\\item The conditional probability formula we have seen so far is a special case of the Bayes' Theorem, which is applicable even when events have more than just two outcomes.\n\n\\pause \n\n\\item \\hl{Bayes' Theorem:}\n\\formula{\n\\[ P(outcome~A_1~of~variable~1~|~outcome~B~of~variable~2) \\]\n\\[ = \\frac{P(B|A_1)P(A_1)}{P(B|A_1)P(A_1) + P(B|A_2)P(A_2) + \\cdots + P(B|A_k)P(A_k)} \\]\n}\nwhere $A_2$, $\\cdots$, $A_k$ represent all other possible outcomes of variable 1.\n\n\\end{itemize}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Application activity: Inverting probabilities}\n\n\\app{{\\footnotesize A common epidemiological model for the spread of diseases is the SIR model, where the population is partitioned into three groups: Susceptible, Infected, and Recovered. This is a reasonable model for diseases like chickenpox where a single infection usually provides immunity to subsequent infections. Sometimes these diseases can also be difficult to detect. \\vspace{2mm} \\\\\nImagine a population in the midst of an epidemic where 60\\% of the population is considered susceptible, 10\\% is infected, and 30\\% is recovered. The only test for the disease is accurate 95\\% of the time for susceptible individuals, 99\\% for infected individuals, but 65\\% for recovered individuals. (Note: In this case accurate means returning a negative result for susceptible and recovered individuals and a positive result for infected individuals). \\vspace{2mm} \\\\\nDraw a probability tree to reflect the information given above. If the individual has tested positive, what is the probability that they are actually infected?\n}}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{frame}\n\\frametitle{Application activity: Inverting probabilities (cont.)}\n\n\\vspace{-0.5cm}\n\n\\includegraphics[width=\\textwidth]{3-2_conditional_probability/figures/sir_tree/sir_tree} \n\n\\pause\n\n\\[ P(inf | +) = \\frac{P(inf~and~+)}{P(+)} = \\frac{0.099}{0.03 + 0.099 + 0.105} \\approx 0.423 \\]\n\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n%\\end{frame}", "meta": {"hexsha": "459d79095dbd33e22e67dd5a48b5a0d6d9378932", "size": 11986, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/3-2_conditional_probability/3-2_conditional_probability.tex", "max_stars_repo_name": "sumitrmishra/data504", "max_stars_repo_head_hexsha": "e0cb3259f6dd362c9591375390c9d6e5d59689b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slides/3-2_conditional_probability/3-2_conditional_probability.tex", "max_issues_repo_name": "sumitrmishra/data504", "max_issues_repo_head_hexsha": "e0cb3259f6dd362c9591375390c9d6e5d59689b7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slides/3-2_conditional_probability/3-2_conditional_probability.tex", "max_forks_repo_name": "sumitrmishra/data504", "max_forks_repo_head_hexsha": "e0cb3259f6dd362c9591375390c9d6e5d59689b7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-20T07:26:35.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-20T07:26:35.000Z", "avg_line_length": 25.0229645094, "max_line_length": 470, "alphanum_fraction": 0.6233939596, "num_tokens": 3903, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198946, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7173319122378777}}
{"text": "\\section{Experiments}\nIn this section, we briefly present our experiments on some of the \nalgorithms presented at the previous sections. Two sets of experiments are presented.\n\nThe first tests are on powers\nof random gaussian matrices of different sizes. The goal of this set of numerics\nis to check the performance of the algorithms and make sure they are working\nas expected. We also analyze the sharpness of the bounds dictated by the theory.\nIn particular, the bound on the expectation of the error given\nby \\ref{thm:avg-frob-error-gauss} and\nthe error estimation procedure which was motivated by \nLemma \\ref{thm:aposteriori}.\nWe have used an \\textit{oversampling parameter} $p=5$ for all of the experiments.\n\nThe second set of experiments analyses the performance of the\n\\textit{Randomized Power Method} \\ref{alg:randomized-power-iteration} on MNIST\nand on a matrix appearing in image processing.\n\n\\subsection{Details of the implementation}\nThe experiments have been implemented in \\verb|Matlab|. The reproducible\nsource code can be found at the following \n\\href{https://github.com/alexnowakvila/ProbAlgosProj}{Github repository}\ntogether with the \\LaTeX~  of the report. Please read \\verb|README| documentation\nto run the code on the \\verb|Matlab| interactive command line.\n\\subsection{Gaussian Matrices} \\label{sec:gaussian-matrices}\nIn this set of experiments, we test and analyze the performance of the \nAlgorithms \\ref{alg:randomized-range-finder}, \n\\ref{alg:adaptive-randomized-range-finder},\n\\ref{alg:randomized-power-iteration}\nand \\ref{alg:fast-randomized-range-finder}.\n\nThe experiments are performed on powers of gaussian random\nmatrices of the form:\n\n\\begin{equation}\\label{eq:gaussian-matrices}\n\\mtx{A} = \\frac{1}{\\sqrt{m}+\\sqrt{n}}\\mtx{G}, \\hspace{0.5cm}\n G_{ij}\\sim N(0,1)\n\\end{equation}\nThe normalization in \\ref{eq:gaussian-matrices} is to make sure that the norm\nof $\\mtx{A}$ is around 1 with high probability\n\\footnote{This is a direct consequence of Sudakov-Fernique's inequality that\ncompares the supremum of two gaussian processes when one is dominated\nby the other. More precisely, you have the bound on the expectation\nof the norm $\\Expect\\|\\mtx{G}\\|\\leq\\sqrt{m}+\\sqrt{n}$\nand also an accompanying tail bound \n$\\Prob{\\|\\mtx{G}\\| \\geq \\sqrt{m} + \\sqrt{n} + t}\\leq 2\\exp(-ct^2)$.\nUsing Gordon's inequality (generalization of Sudakov Fernique's), you can\nalso prove lower bounds on the smallest singular value\n$\\Expect\\|\\mtx{G}^\\dagger\\|\\geq \\sqrt{m} - \\sqrt{n}$ and\n$\\Prob{\\|\\mtx{G}\\|\\leq \\sqrt{m}-\\sqrt{n}-t}\\leq 2\\exp(-ct^2)$.\nThese results on concentration of measure have been studied at the Theory\nReading Group following the book on High Dimensional Probability\nfrom R.Vershynin which I highly recommend \n\\cite{vershynin2016high}.}.\nAs seen from Equation \\ref{eq:sing-values-power}, the singular values decay faster \nfor higher powers of the matrix.\n\\subsubsection{Experiments on Randomized Range Finder \n\\ref{alg:randomized-range-finder}} See Figure \\ref{fig:exp1-1}.\n\\begin{figure}[H]\\label{fig:exp1-1}\n\\begin{center}\n\\includegraphics[width=\\textwidth, trim=0cm 8cm 0cm 9cm, clip=true]{figures/1-4.pdf}\n\\end{center}\n\\caption{Comparison between theoretical mean bound \\ref{thm:avg-frob-error-gauss}\nand numerical error \\ref{eq:range-error} produced by Algorithm \\ref{alg:randomized-range-finder}\n for $(\\mtx{A}\\mtx{A}^\\adj)^r\\mtx{A}$ with $r=0,1,2$. }\n\\end{figure}\n\n\\subsubsection{Experiments on Randomized Power Iteration \n\\ref{alg:randomized-power-iteration}} See Figure \\ref{fig:exp1-2}.\n\\begin{figure}[H] \\label{fig:exp1-2}\n\\begin{center}\n\\includegraphics[width=\\textwidth, trim=0cm 8cm 0cm 9cm, clip=true]{figures/1-5.pdf}\n\\end{center}\n\\caption{Comparison between theoretical mean bound from Corollary\n\\ref{cor:power-method-spec-gauss} and numerical\nerror \\ref{eq:range-error} produced by Algorithm \\ref{alg:adaptive-randomized-range-finder}\nfor $\\mtx{A}$ and $q=1,2,3$}\n\\end{figure}\n\n\\subsubsection{Experiments on Adaptive Randomized Range Finder\n\\ref{alg:adaptive-randomized-range-finder}}\nIn this experiment, Algorithm \\ref{alg:adaptive-randomized-range-finder} is applied\nto $(\\mtx{A}\\mtx{A}^\\adj)^2\\mtx{A}$ with pre-specified tolerances ranging\nfrom 0 to 1. We have fitted a line to the numerical\nerror produced vs the tolerance (the dependence was close to linear). The slope of the\nresulting line\nis $\\textbf{0.045}$, i.e, for the matrices used in the experiment, the \nbound \\ref{eq:errorest} has a numerical suboptimality of 0.045.\n\\subsubsection{Experiments on Fast Randomized Range Finder\n\\ref{alg:fast-randomized-range-finder}}\nAlgorithm \\ref{alg:fast-randomized-range-finder} has been applied to several\npowers of $\\mtx{A}$ (using SRFT test matrices) and the error curve for \ndifferent target ranks is essentially the same as the one found using\nAlgorithm \\ref{alg:randomized-range-finder}.\n\n\\subsection{Real Datasets}\n\\subsubsection{MNIST}\nIn this experiment, we used 10,000 examples from\nthe MNIST dataset \\cite{lecun1998mnist} of 28x28\nblack and white images of handwritten digits.\n\nThe goal is to compare Algorithm \\ref{alg:randomized-range-finder} with the\npower version \\ref{alg:randomized-power-iteration} on the matrix\n$\\mtx{M}\\in\\Rspace{10000\\times 784}$ where each row is a flattened image.\nThe singular values of $\\mtx{M}$ decay fast, hence, the power scheme does not\nsignificantly improve the randomized scheme for $q>1$.\nSee Figure \\ref{fig:exp2}.\n\n\\subsubsection{A Large, Sparse, Noisy Matrix Arising in Image Processing}\nOne way to tackle standard tasks in image processing is to use the information\nabout the local geometry of the image through the \\textit{graph Laplacian}.\nThe dominant eigenvectors of this operator provide coordinates that help to smooth\nout noisy image patches \\cite{szlam2008regularization}.\n\nFirst, define $\\widetilde{\\mtx{W}}$ as\n\\begin{equation}\\label{eq:similarities}\n\\widetilde{w}_{ij}=\\exp\\{-\\|\\mtx{x}^{(i)} - \\mtx{x}^{(j)}\\|^2/\\sigma^2\\}\n\\end{equation}\nwhere $\\mtx{x}^{(i)}$ is a vector gathering the intensities of a neighborhood\nof a certain size of the pixel $i$. Here, $\\sigma$ controls the level of\nsensitivity. We then define the sparse matrix $\\mtx{W}$ constructed by\nzeroing out all the entries in $\\widetilde{\\mtx{W}}$ except the 7 largest\nones in each row. \nFinally, the laplacian operator is defined as\n\\begin{equation}\\label{eq:graph-laplacian}\n\\mtx{L}=\\mtx{I}-\\mtx{D}^{-1/2}\\mtx{W}\\mtx{D}^{-1/2}\n\\end{equation}\nwhere $\\mtx{D}$ is the diagonal matrix with entries $d_{ii}=\\sum_{j}w_{ij}$.\n\nIn order to find the low-frequency eigenvectors of $\\mtx{L}$,\nwe must find the eigenvectors with dominant eigenvalues of\n\n\\begin{equation}\\label{eq:adj}\n\\mtx{A}=\\mtx{D}^{-1/2}\\mtx{W}\\mtx{D}^{-1/2}\n\\end{equation}\n\nIn our experiment, we have taken a patch of size 57x57 from the classical\n$\\verb|Lenna.png|$ photo. The matrix $\\widetilde{\\mtx{W}}$ is constructed \nwith patches of size 5x5 centered at the corresponding pixel with\nzero-padding at the boundary. The resulting\nmatrix $\\mtx{A}$ has size 3249x3249 and has low decaying eigenvalues. Hence,\nas can be seen in Figure \\ref{fig:exp2}, the power scheme from\nAlgorithm \\ref{alg:randomized-power-iteration} is very advantageous.\n\n\\begin{figure}[H] \\label{fig:exp2}\n\\begin{center}\n\\includegraphics[width=\\textwidth, trim=0cm 8cm 0cm 7cm, clip=true]{figures/2-2.pdf}\n\\end{center}\n\\caption{Approximation error \\ref{eq:range-error} for the\npower scheme \\ref{alg:randomized-power-iteration} for MNIST \n(Left) and $\\mtx{A}$ \\ref{eq:adj} (Right) for $k$ ranging from $1$ to $100$.}\n\\end{figure}", "meta": {"hexsha": "f5adf9807f4d7757e502b02a010af1fed658b644", "size": 7537, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/experiments.tex", "max_stars_repo_name": "alexnowakvila/ProbAlgosProj", "max_stars_repo_head_hexsha": "819251313cb2b9ca4748892ee62f40c602453ddc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-06-10T11:13:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-05T07:55:46.000Z", "max_issues_repo_path": "report/sections/experiments.tex", "max_issues_repo_name": "alexnowakvila/ProbAlgosProj", "max_issues_repo_head_hexsha": "819251313cb2b9ca4748892ee62f40c602453ddc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/sections/experiments.tex", "max_forks_repo_name": "alexnowakvila/ProbAlgosProj", "max_forks_repo_head_hexsha": "819251313cb2b9ca4748892ee62f40c602453ddc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-05T07:55:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-05T07:55:49.000Z", "avg_line_length": 49.5855263158, "max_line_length": 96, "alphanum_fraction": 0.7638317633, "num_tokens": 2199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245618, "lm_q2_score": 0.8479677526147222, "lm_q1q2_score": 0.717331904112455}}
{"text": "\n\\subsection{The Link test}\n\n\\subsubsection{Introduction}\n\nAlternative to RESET\n\nWe have \\(\\hat y\\).\n\nWe regress \\(y=\\alpha + \\beta \\hat y + \\gamma \\hat y^2\\).\n\nWe test that \\(\\gamma =0\\).\n\nIf it is not, then this suggests the model is misspecified.\n\n", "meta": {"hexsha": "8ed78582d228105e442fb047706422b7bcbacb72", "size": 251, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/linearML/04-02-link.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/linearML/04-02-link.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/linearML/04-02-link.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.6875, "max_line_length": 59, "alphanum_fraction": 0.6772908367, "num_tokens": 72, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7172967840172331}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\title{GAVisTool\\\\User Manual\\\\Version 0.1}\n\\author{Spencer T. Parkin}\n\n\\newcommand{\\G}{\\mathbb{G}}\n\\newcommand{\\V}{\\mathbb{V}}\n\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\B}{\\mathbb{B}}\n\\newcommand{\\nvao}{o}\n\\newcommand{\\nvai}{\\infty}\n\n\\begin{document}\n\\maketitle\n\nThis is the manual for the GAVisTool program.  It is the quickest way to learn\nhow to use this software, provided the reader is already familiar with geometric\nalgebra and the conformal model.  For more information on these topics, see\n\"Geometric Algebra for Computer Science\" by Dr. Leo Dorst, et. al.  Another good\nsource of information on these topics can be found in Dr. Christian Perwass's \"Geometric\nAlgebra with Applications in Engineering.\"\n\n\\section{The Console Window}\n\nWhen the GAVisTool program comes up, you are presented with two windows: the console\nwindow and the canvas window.  Ignoring the canvas window for the moment, the console\nwindow is where you will interact with the GA environment by inputting expressions in the\ntext box at the bottom, then seeing the evaluation of these expressions as output in the\nmain part of the window.\n\n\\subsection{The GAVisTool Language}\n\nA design goal of the GAVisTool software was that of not requiring the user to learn a language\nunique to the software.  On the contrary, the tool better serves its user as a means to learning\nthe language of geometric algebra and mathematics in general.  With that in mind, the language\nrecognized by GAVisTool deviates from the language of mathematics only where unique features\nof the GAVisTool software are concerned.  In fact, if you're familiar with basic mathematics, then\nyou already know the entire syntax of the GAVisTool language.  Specificly,\nits syntax consists of left and right unary operators, infix binary operator notation,\nand function call syntax.  That's it.  It's not any more or less complicated than that.  All that\nremains then for the user to learn is what unary and binary operators are supported,\nwhat functions are available, and what types of numbers are the subject of all these things.\n\n\\subsubsection{Numbers}\n\nThe concept of number is abstracted in the software to mean whatever is applicable\nto current environment.  As of this writing, the only environment presented to the\nuser is the GA environment, and so the numbers in this context are simply the elements\nof any geometric algebra defined over the field of real numbers.  The specific GA being\nused depends on what basis vectors the user chooses to mix into his or her\nexpressions.  The following table lists the currently recognized constants in the\nGA environment.\n\\begin{equation*}\n\\begin{array}{ccl}\n\\mbox{Console} & \\mbox{Math Symbol} & \\mbox{Description} \\\\\n\\hline\n\\mbox{no} & \\nvao & \\mbox{Null vector at origin} \\\\\n\\mbox{ni} & \\nvai & \\mbox{Null vector at infinity} \\\\\n\\mbox{e0} & e_0 & \\mbox{Unit X-axis Euclidean vector} \\\\\n\\mbox{e1} & e_1 & \\mbox{Unit Y-axis Euclidean vector} \\\\\n\\mbox{e2} & e_2 & \\mbox{Unit Z-axis Euclidean vector} \\\\\n\\mbox{I} & e_0\\wedge e_1\\wedge e_2\\wedge \\nvao\\wedge \\nvai & \\mbox{Unit psuedo-scalar of 3D CGA} \\\\\n\\mbox{i} & e_0\\wedge e_1\\wedge e_2 & \\mbox{Unit psuedo-scalar of 3D EGA} \\\\\n\\mbox{E0} & e_1\\wedge e_2 & \\mbox{Unit YZ-plane Euclidean 2-blade} \\\\\n\\mbox{E1} & e_2\\wedge e_0 & \\mbox{Unit XZ-plane Euclidean 2-blade} \\\\\n\\mbox{E2} & e_0\\wedge e_1 & \\mbox{Unit XY-plane Euclidean 2-blade}\n\\end{array}\n\\end{equation*}\nThe vectors $e_0$, $e_1$ and $e_2$ form a right-handed orthonormal basis for 3-dimensional\nEuclidean space.\n\nYou may enter any one of the above variable names into the console to see it recognized\nby the GA environment.  The first five symbols given in the table form the basis for the\ngeometric algebra used by the conformal model of 3-dimensional space.  The remaining\nfive variables are provided for convenience.\n\nAlso recognized by the GA environment are scalar literal values.  These are bits of\ntext such as \"3.14159\" and \"0.12345\" and so on.\n\n\\subsubsection{Unary and Binary Operators}\n\nMany unary and binary operators are recognized by the GA enviornment, but the first\nof note are simply those that will allow us to generate linear combinations of the basis\nvectors given in the previous section.  This is done just as you would expect.\nFor example, try inputting the following expressions.\n...\n\n\\subsubsection{Functions}\n\n\\subsubsection{Variables}\n\nWhen the GA environment encounters a named number that it doesn't recognize\nas a built-in constant, it treats it as a variable, and remembers variable values.\nTo store a value (a number) in a variable, use the assignment operator.\n\n\\section{The Canvas Window}\n\nThe console window by itself is useful for making calculations in geometric algebra, but the main\npurpose of GAVisTool is to provide a way to visualize the results of your mathematical expressions.\nThis is where the canvas window comes in.\n\n\\subsection{Bind Targets}\n\nBind targets are things that appear in the canvas window and that are bound to a variable\nin the GA environment.  The type of bind target and how its bound to the variable determine\nhow that bind target will interpret the value of the variable to which it is bound.  For example,\nif we have a variable named $\\mbox{sph}$ that we would like to visualize as a conformal\nsphere, then we can input the expression $\\mbox{bind\\_sphere(sph)}$ to create and bind to it\na bind target in the canvas window that is designed to interpret $\\mbox{sph}$ as a conformal sphere.\nOnce bound, any changes we make to the value of the variable $\\mbox{sph}$ will be reflected\nas changes to the way the sphere is manifested in the canvas window by the bind target.\nConversly, any changes we make to the bind target (a sphere in this case) will be reflected\nas changes to the value of the variable $\\mbox{sph}$ in the console window.  (We'll go over\ncanvas interaction in the next section.)\n\nAnother type of bind target is a user interface.  As a single element of GA may be characterized\nby a number of properties, these properties may be manifested through a simple user interface.\nThese interfaces appear as floatling control panels that can be docked about the canvas window.\nAs of this writing, the only currently available bind target interface is a scalar interface which can\nbe bound to a scalar (real number) variable in the console window.\n\nThe following table lists the currently available bind target functions.\n\\begin{equation*}\n\\begin{array}{ll}\n\\mbox{Function} & \\mbox{Description} \\\\\n\\hline\n\\mbox{bind\\_point} & \\mbox{Bind a variable to a conformal point} \\\\\n\\mbox{bind\\_sphere} & \\mbox{Bind a variable to a conformal sphere} \\\\\n\\mbox{bind\\_circle} & \\mbox{Bind a variable to a conformal circle} \\\\\n\\mbox{bind\\_pointpair} & \\mbox{Bind a variable to a conformal point-pair} \\\\\n\\mbox{bind\\_line} & \\mbox{Bind a variable to a conformal line} \\\\\n\\mbox{bind\\_plane} & \\mbox{Bind a variable to a conformal plane} \\\\\n\\mbox{bind\\_flatpoint} & \\mbox{Bind a variable to a conformal flat-point} \\\\\n\\mbox{bind\\_scalar\\_iface} & \\mbox{Bind a variable to a scalar interface} \\\\\n\\end{array}\n\\end{equation*}\nLeft out of the table for ease of reading were functions such as $\\mbox{bind\\_dual\\_point}$\nand $\\mbox{bind\\_dual\\_sphere}$.  These interpret elements of GA as dual points and dual\nspheres, respectively.  A dual version of all bind target functions for conformal geometries\nis provided.\n\nAlso left out of the table was a function named $\\mbox{bind\\_inferred\\_geo}$.\nA bind target for a specific conformal geometry assumes a certain form for\nelements of GA it is given to interpret.  The inferred geometry bind target, however,\nanalyzes a given element first to determine what type of conformal geometry it\nmay represent, then interprets it as that geometry.  As of this writing, this\nfeature has not yet been implemented.\n\n\\subsection{Canvas Interaction}\n\nJust as with the console window, the canvas window too provides both output and input.\nSpecifically, through the canvas window the user can interact with the set of\ncurrently created bind targets.  Continuing with the conformal sphere example in the\nprevious section, right-clicking on this sphere in the canvas window will select it.  You can\nthen move the sphere in a plane orthogonal to the viewing direction by holding the\nCTRL key and left mouse button down while dragging the mouse in the canvas window.\nHolding the CTRL and SHIFT keys down while moving the mouse wheel will rotate\nthe selected bind target on an axis horizontal and perpendicular to the viewing direction,\nand going through the center of the bind target's geometry.\n(Notice that conformal spheres don't rotate, because they are invariant under rotations\nabout their center.)  Without the SHIFT key down, that same action will scale the\nbind target's geometry up and down.\n\nRight-clicking on no bind target's geometry unselects the currently selected bind target, if any.\n\n\\subsection{Canvas Camera Control}\n\nSince geometry movement control is based on the camera orientation, we must have a way\nof moving the camera around.  We would also like to be able to look at the scene from\ndifferent perpsectives.\n\nHolding the left mouse button down while dragging the mouse in the canvas window allows\nyou to rotate the viewing location about the focal point.  Doing so while the ALT key is down allows you to pan\nthe camera in a plane orthogonal to the viewing direction, which also changes the focal point.  The focal\npoint is an invisible point in space in front of the camera.\nIf a bind target is selected, then hitting the SPACE bar will set the focal point of the camera to the\ncenter of the bind target's geometry.  Subsequent rotations of the camera about the\nfocal point allow you to then view the bind target's geometry from different angles.\n\n\\section{Constraints}\n\nThe GAVisTool software maintains a set of constraints between the current\nset of bind targets.  Like bind targets, until you actually create a constraint,\nthere are none maintained by the system.  A constraint names one or more\nbind targets as its set of inputs and one or more bind targets as its set of outputs.\nWhen a constraint executes, it pulls values from the variables bound to its\ninput bind targets, performs some sort of calculation and/or algorithm on this data,\nand then pushes result values to the variables bound to its output bind targets.\nA constraint is schedualed to execute when it is detected that one or more of\nits inputs has changed.\n\nOne can imagine that with multiple constraints maintained by the system, these\nform a dependency graph as one constraint's set of inputs may overlap with\nanother contraint's set of outputs.  Indeed, when a contraint executes, it may\ncause other constraints to execute as well.  There is no need to worry about\ncreating circular dependencies.  When a single bind target is changed, an entire\nchain of constraints is schedualed for execution before actually being executed.\nIf a constraint can't be schedualed for execution, (due to a circular dependency), it is simply not\nexecuted.  This schedualling failure is not necessarily a design flaw on the part\nof the author of the constraint system.  When rigging together a bunch of bind\ntargets with constraints, it is not uncommon to constrain two bind targets to\none another using two mutually dependent constraints.\n\nAs of this writing, there is currently only one type of constraint that can be\ncreated, but it is a powerful one.  It is called a formulated constraint.\n\n\\section{Scripts}\n\n\\end{document}", "meta": {"hexsha": "367ae29f8599e5840e9c758b1694c5dea307b236", "size": 11561, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Docs/GAVisToolManual/GAVisToolManual.tex", "max_stars_repo_name": "spencerparkin/GAVisTool", "max_stars_repo_head_hexsha": "fb61a1789d58aedce4dbb5a53b181fbc06172a2a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Docs/GAVisToolManual/GAVisToolManual.tex", "max_issues_repo_name": "spencerparkin/GAVisTool", "max_issues_repo_head_hexsha": "fb61a1789d58aedce4dbb5a53b181fbc06172a2a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Docs/GAVisToolManual/GAVisToolManual.tex", "max_forks_repo_name": "spencerparkin/GAVisTool", "max_forks_repo_head_hexsha": "fb61a1789d58aedce4dbb5a53b181fbc06172a2a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.5330188679, "max_line_length": 111, "alphanum_fraction": 0.7835827351, "num_tokens": 2819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7172967785298736}}
{"text": "\\section{Orthogonality}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine whether two vectors in an inner product space are\n    orthogonal.\n  \\item Find the orthogonal complement of a set of vectors.\n  \\item Determine whether a set of vectors is orthogonal and/or orthonormal.\n  \\item Check whether a basis is orthogonal and/or orthonormal.\n  \\item Calculate the Fourier coefficients of a vector with respect to\n    an orthogonal basis.\n  \\end{enumerate}\n\\end{outcome}\n\n\\begin{definition}{Orthogonality}{inner-product-orthogonality}\n  Let $\\vect{u}$ and $\\vect{v}$ be vectors in an inner product space.\n  We say that $\\vect{u}$ and $\\vect{v}$ are \\textbf{orthogonal}%\n  \\index{vector!orthogonal}%\n  \\index{orthogonal vectors} if\n  \\begin{equation*}\n    \\iprod{\\vect{u}, \\vect{v}} = 0.\n  \\end{equation*}\n  We also write $\\vect{u}\\orth\\vect{v}$ to indicate that $\\vect{u}$\n  and $\\vect{v}$ are orthogonal.\n\\end{definition}\n\nWe note that the zero vector $\\vect{0}$ is orthogonal to all vectors,\nbecause $\\iprod{\\vect{u},\\vect{0}} = 0$ follows from the linearity of\nthe inner product. We also note that $\\vect{u}\\orth\\vect{v}$ if and\nonly if $\\vect{v}\\orth\\vect{u}$; this follows from the symmetry of the\ninner product.\n\n\\begin{definition}{Orthogonal complement}{inner-product-orthogonal-complement}\n  Let $S$ be a subset of an inner product space $V$. The\n  \\textbf{orthogonal complement}%\n  \\index{orthogonal complement} of $S$ is the set\n  \\begin{equation*}\n    S^{\\orth} = \\set{\\vect{v}\\in V \\mid\n      \\mbox{\n        $\\iprod{\\vect{v},\\vect{w}} = 0$ for all $\\vect{w}\\in S$\n      }}.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}{Orthogonal complement}{inner-product-orthogonal-complement}\n  If $S$ is any subset of an inner product space $V$, then $S^{\\orth}$\n  is a subspace.\n\\end{proposition}\n\n\\begin{proof}\n  We clearly have $\\vect{0}\\in S^{\\orth}$, because $\\vect{0}$ is\n  orthogonal to all vectors. To show that $S^{\\orth}$ is closed under\n  addition, assume $\\vect{v}, \\vect{v}'\\in S^{\\orth}$. We have to show\n  $\\vect{v}+\\vect{v}'\\in S^{\\orth}$. So take an arbitrary $\\vect{w}\\in\n  S$. Then we have\n  \\begin{equation*}\n    \\iprod{\\vect{v}+\\vect{v}',\\vect{w}}\n    = \\iprod{\\vect{v},\\vect{w}} + \\iprod{\\vect{v}',\\vect{w}}\n    = 0 + 0 = 0.\n  \\end{equation*}\n  Therefore, $\\vect{v}+\\vect{v}'\\in S^{\\orth}$. Finally, to show that\n  $S^{\\orth}$ is closed under scalar multiplication, assume\n  $\\vect{v}\\in S^{\\orth}$ and $k\\in\\R$. We have to show\n  $k\\vect{v}\\in S^{\\orth}$. So take an arbitrary\n  $\\vect{w}\\in S$. Then we have\n  \\begin{equation*}\n    \\iprod{k\\vect{v},\\vect{w}}\n    = k\\iprod{\\vect{v},\\vect{w}}\n    = k0 = 0.\n  \\end{equation*}\n  Therefore, $k\\vect{v}\\in S^{\\orth}$. It follows that $S^{\\orth}$ is\n  a subspace of $V$.\n\\end{proof}\n\nHere is an illustration of a subspace $S$ of $\\R^3$ and its orthogonal\ncomplement $S^{\\orth}$:\n\n\\begin{center}\n  \\begin{tikzpicture}[x={(1cm,0cm)},y={(1cm,0.5cm)},z={(0cm,1cm)},rotate=0]\n    \\draw[thick,blue!80!black](-2,0,0) -- (2,0,0);\n    \\filldraw[draw=red!80,fill=red!10](0,-1,-1.5) -- (0,-1,1.5) --\n    (0,1,1.5) -- (0,1,-1.5) -- cycle;\n    \\path[red!80] (0,0,0.5) node[above] {$S$};\n    \\draw[thick,blue!80!black](0,0,0) -- node[above, pos=0.7] {$S^{\\orth}$} (2,0,0);\n  \\end{tikzpicture}\n\\end{center}\n\n\\begin{example}{Orthogonal complement}{inner-product-orthogonal-complement}\n  Consider the inner product space $\\Poly_3$ of polynomials of degree\n  at most $3$, with the inner product defined by\n  \\begin{equation*}\n    \\iprod{f,g} = \\int_{-1}^{1} f(x)g(x)\\,dx.\n  \\end{equation*}\n  Find the orthogonal complement of $\\set{x^2}$.\n\\end{example}\n\n\\begin{solution}\n  We have to compute the set of all polynomials of the form\n  $p(x)=ax^3+bx^2+cx+d$ that are orthogonal to $x^2$. So let us\n  compute the inner product:\n  \\begin{eqnarray*}\n    \\iprod{p(x), x^2}\n    &=& \\int_{-1}^{1} (ax^3+bx^2+cx+d)x^2\\,dx \\\\\n    &=& \\int_{-1}^{1} ax^5+bx^4+cx^3+dx^2\\,dx \\\\\n    &=& 0a  + \\frac{2}{5}b + 0c + \\frac{2}{3}d.\n  \\end{eqnarray*}\n  Setting this equal to $0$, we see that $\\iprod{p(x), x^2}=0$ if and\n  only if $\\frac{2}{5}b + \\frac{2}{3}d = 0$, or equivalently,\n  $3b+5d=0$. The basic solutions are\n  \\begin{equation*}\n    \\begin{mymatrix}{c} a \\\\ b \\\\ c \\\\ d \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{mymatrix},\\quad\n    \\begin{mymatrix}{c} a \\\\ b \\\\ c \\\\ d \\end{mymatrix}\n    = \\begin{mymatrix}{c} 0 \\\\ 5 \\\\ 0 \\\\ -3 \\end{mymatrix},\\quad\n    \\begin{mymatrix}{c} a \\\\ b \\\\ c \\\\ d \\end{mymatrix}\n    = \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{mymatrix},\n  \\end{equation*}\n  giving the following basis for the space of polynomials orthogonal\n  to $x^2$:\n  \\begin{equation*}\n    \\set{x^3,\\quad 5x^2-3, \\quad x}.\n  \\end{equation*}\n\\end{solution}\n\nWe now consider orthogonal sets and bases.\n\n\\begin{definition}{Orthogonal and orthonormal sets of vectors}{orthogonal-set}\n  A set of vectors $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ in an inner\n  product space is called an \\textbf{orthogonal set}%\n  \\index{orthogonal set} if the vectors are non-zero and pairwise\n  orthogonal, i.e., for all $i$, $\\vect{u}_i\\neq\\vect{0}$ and for all\n  $i\\neq j$, $\\vect{u}_i\\orth\\vect{u}_j$.\n  \\smallskip\\smallskip\n\n  Moreover, the set of vectors $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is\n  called \\textbf{orthonormal}%\n  \\index{orthonormal set} if it is orthogonal and each vector is\n  normalized, i.e., $\\norm{\\vect{u}_i}=1$.\n\\end{definition}\n\nThe interest of orthogonal and orthonormal sets of vectors lies, among\nother things, in the fact that they are automatically linearly\nindependent.\n\n\\begin{proposition}{Orthogonal set is linearly independent}{orthogonal-linear-independence}\n  If $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is an orthogonal set of\n  vectors, then $\\vect{u}_1,\\ldots,\\vect{u}_k$ are linearly\n  independent.\n\\end{proposition}\n\n\\begin{proof}\n  Assume $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is an orthogonal set. To\n  show that $\\vect{u}_1,\\ldots,\\vect{u}_k$ are linearly\n  independent, assume\n  \\begin{equation*}\n    a_1\\vect{u}_1 + \\ldots + a_k\\vect{u}_k = \\vect{0}.\n  \\end{equation*}\n  We must show that $a_1,\\ldots,a_k = 0$. So pick some\n  $i\\in\\set{1,\\ldots,k}$. We compute\n  \\begin{eqnarray*}\n    \\iprod{a_1\\vect{u}_1 + \\ldots + a_k\\vect{u}_k, \\vect{u}_i}\n    &=& a_1\\iprod{\\vect{u}_1,\\vect{u}_i}\n        + \\ldots\n        + a_i\\iprod{\\vect{u}_i,\\vect{u}_i}\n        + \\ldots\n        + a_k\\iprod{\\vect{u}_k,\\vect{u}_i} \\\\\n    &=& 0\n        + \\ldots\n        + a_i\\iprod{\\vect{u}_i,\\vect{u}_i}\n        + \\ldots\n        + 0 \\\\\n    &=& a_i \\iprod{\\vect{u}_i,\\vect{u}_i}.\n  \\end{eqnarray*}\n  On the other hand,\n  \\begin{equation*}\n    \\iprod{a_1\\vect{u}_1 + \\ldots + a_k\\vect{u}_k, \\vect{u}_i}\n    = \\iprod{\\vect{0}, \\vect{u}_i} = 0.\n  \\end{equation*}\n  It follows that $a_i \\iprod{\\vect{u}_i,\\vect{u}_i} = 0$. Since\n  $\\iprod{\\vect{u}_i,\\vect{u}_i}\\neq 0$, it follows that\n  $a_i=0$. Since the choice of $i$ was arbitrary, it follows that\n  $a_1,\\ldots,a_k = 0$, and $\\vect{u}_1,\\ldots,\\vect{u}_k$ are\n  linearly independent.\n\\end{proof}\n\n\\begin{example}{An orthogonal set of functions}{orthogonal-set-sin-cos}\n  Consider the inner product space $C[0,2\\pi]$. The following\n  functions form an (infinite) orthogonal set:\n  \\begin{eqnarray*}\n    g_0(x) &=& 1 \\\\\n    f_1(x) &=& \\sin x \\\\\n    g_1(x) &=& \\cos x \\\\\n    f_2(x) &=& \\sin 2x \\\\\n    g_2(x) &=& \\cos 2x \\\\\n    &\\vdots& \\\\\n    f_k(x) &=& \\sin kx \\\\\n    g_k(x) &=& \\cos kx \\\\\n    &\\vdots&\n  \\end{eqnarray*}\n\\end{example}\n\n\\begin{proof}\n  We have to check that any two functions are orthogonal to each\n  other. This is true because of trigonometric identities. We have the\n  following trigonometric formulas:\n  \\begin{eqnarray*}\n    \\sin\\alpha\\sin\\beta &=& \\frac{1}{2}(\\cos(\\alpha-\\beta) - \\cos(\\alpha+\\beta)), \\\\\n    \\cos\\alpha\\cos\\beta &=& \\frac{1}{2}(\\cos(\\alpha-\\beta) + \\cos(\\alpha+\\beta)), \\\\\n    \\sin\\alpha\\cos\\beta &=& \\frac{1}{2}(\\sin(\\alpha-\\beta) + \\sin(\\alpha+\\beta)).\n  \\end{eqnarray*}\n  Using these, we can compute the relevant inner products. Assume $i\\neq j$. Then\n  \\begin{eqnarray*}\n    \\iprod{g_i,g_j}\n    &=& \\int_{0}^{2\\pi} \\cos(ix)\\cos(jx)\\,dx \\\\\n    &=& \\frac{1}{2}\\int_{0}^{2\\pi} \\cos((i-j)x) + \\cos((i+j)x)\\,dx \\\\\n    &=& \\frac{1}{2}\\bigbracket{\\frac{1}{(i-j)} \\sin((i-j)x) + \\frac{1}{(i+j)}\n      \\sin((i+j)x)}_0^{2\\pi} \\\\\n    &=& 0,\n  \\end{eqnarray*}\n  and therefore $g_i\\orth g_j$. The proofs of $f_i\\orth f_j$ and\n  $f_i\\orth g_j$ are similar.\n\\end{proof}\n\n\\begin{definition}{Orthogonal and orthonormal bases}{orthogonal-basis}\n  Let $V$ be an inner product space, and let $W$ be a subspace of\n  $V$. We say that $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is an\n  \\textbf{orthogonal basis}%\n  \\index{orthogonal basis}%\n  \\index{basis!orthogonal} for $W$ if it is an orthogonal set and\n  spans $W$.\n  \\smallskip\\smallskip\n\n  If, moreover, each $\\vect{u}_i$ is normalized, we say that\n  $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is an \\textbf{orthonormal\n    basis}%\n  \\index{orthonormal basis}%\n  \\index{basis!orthonormal} for $W$.\n\\end{definition}\n\nWe note that, by\nProposition~\\ref{prop:orthogonal-linear-independence}, every\northogonal (or orthonormal) basis is automatically linearly\nindependent, and therefore an actual basis of $W$.\n\n\\begin{example}{Orthogonal, orthonormal, and non-orthogonal bases}{orthogonal-basis}\n  Consider $\\R^2$ as an inner product space with the usual dot product.\n  \\begin{itemize}\n  \\item $\\set{\\begin{mymatrix}{r} 1 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 1 \\end{mymatrix}}$ is an orthonormal\n    basis of $\\R^2$.\n  \\item\n    $\\set{\\frac{1}{\\sqrt{2}}\\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix},\n      \\frac{1}{\\sqrt{2}}\\begin{mymatrix}{r} 1 \\\\ -1 \\end{mymatrix}}$\n    is an orthonormal basis of $\\R^2$.\n  \\item $\\set{\\begin{mymatrix}{r} 2 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 3 \\end{mymatrix}}$ is an orthogonal\n    basis of $\\R^2$, but not orthonormal.\n  \\item $\\set{\\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 1 \\\\ -1 \\end{mymatrix}}$ is an orthogonal\n    basis of $\\R^2$, but not orthonormal.\n  \\item $\\set{\\begin{mymatrix}{r} 1 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix}}$ is a basis of\n    $\\R^2$, but neither orthogonal nor orthonormal.\n  \\end{itemize}\n\\end{example}\n\nSo why are we interested in orthogonal and orthonormal bases? The main\nreason is that finding coordinates is {\\em much easier} when the bases\nare orthogonal (and even better when they are orthonormal). We have\nthe following property:\n\n\\begin{proposition}{Fourier coefficients}{fourier-coefficients}\n  Let $B=\\set{\\vect{u}_1,\\ldots,\\vect{u}_n}$ be an orthogonal basis of\n  some space $W$, and suppose $\\vect{v}\\in W$. Then\n  \\begin{equation*}\n    \\vect{v} = a_1\\vect{u}_1 + \\ldots + a_n\\vect{u}_n,\n  \\end{equation*}\n  where\n  \\begin{equation*}\n    a_i = \\frac{\\iprod{\\vect{u}_i,\\vect{v}}}{\\iprod{\\vect{u}_i,\\vect{u}_i}}.\n  \\end{equation*}\n  In this situation, the coordinates $a_1,\\ldots,a_n$ are also called\n  the \\textbf{Fourier coefficients}%\n  \\index{Fourier coefficients} of $\\vect{v}$ (with respect to the\n  orthogonal basis $B$).\n  \\smallskip\\smallskip\n\n  In case $B$ is an orthonormal basis, the formula is even simpler. In\n  that case:\n    \\begin{equation*}\n    a_i = \\iprod{\\vect{u}_i,\\vect{v}}.\n  \\end{equation*}\n\\end{proposition}\n\n\\begin{proof}\n  Since $B$ is a basis of $W$, we know that there exist coefficients\n  $a_1,\\ldots,a_n$ such that\n  $\\vect{v} = a_1\\vect{u}_1 + \\ldots + a_n\\vect{u}_n$. It remains to\n  verify that the coefficients satisfy the required formula. This is a\n  simple calculation. We have\n  \\begin{eqnarray*}\n    \\iprod{\\vect{u}_i,\\vect{v}}\n    &=& \\iprod{\\vect{u}_i, a_1\\vect{u}_1 + \\ldots + a_n\\vect{u}_n} \\\\\n    &=& a_1\\iprod{\\vect{u}_i,\\vect{u}_1}\n        + \\ldots\n        + a_i\\iprod{\\vect{u}_i,\\vect{u}_i}\n        + \\ldots\n        + a_n\\iprod{\\vect{u}_i,\\vect{u}_n} \\\\\n    &=& 0\n        + \\ldots\n        + a_i\\iprod{\\vect{u}_i,\\vect{u}_i}\n        + \\ldots\n        + 0 \\\\\n    &=& a_i \\iprod{\\vect{u}_i,\\vect{u}_i}.\n  \\end{eqnarray*}\n  Since $\\vect{u}_i\\neq \\vect{0}$, we have\n  $\\iprod{\\vect{u}_i,\\vect{u}_i}\\neq 0$ by the positive definite\n  property. We can therefore divide both sides of the equation by\n  $\\iprod{\\vect{u}_i,\\vect{u}_i}$ to obtain\n  \\begin{equation*}\n    a_i = \\frac{\\iprod{\\vect{u}_i,\\vect{v}}}{\\iprod{\\vect{u}_i,\\vect{u}_i}},\n  \\end{equation*}\n  as desired. Finally, if the basis is orthonormal, then\n  $\\iprod{\\vect{u}_i,\\vect{u}_i}=1$, and the denominator disappears,\n  so that $a_i = \\iprod{\\vect{u}_i,\\vect{v}}$.\n\\end{proof}\n\n\\begin{example}{Fourier coefficients}{fourier-coefficients}\n  Suppose $B=\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3}$ is an orthogonal\n  basis for an inner product space $V$, such that\n  $\\norm{\\vect{u}_1}=1$, $\\norm{\\vect{u}_2}=\\sqrt{2}$, and\n  $\\norm{\\vect{u}_3}=2$.  Moreover, suppose that $\\vect{v}\\in V$ is a\n  vector such that $\\iprod{\\vect{v},\\vect{u}_1} = 3$,\n  $\\iprod{\\vect{v},\\vect{u}_2} = -1$, and\n  $\\iprod{\\vect{v},\\vect{u}_3} = 2$.  Find the coordinates of\n  $\\vect{v}$ with respect to $B$.\n\\end{example}\n\n\\begin{solution}\n  We have to find $a_1,a_2,a_3$ such that\n  \\begin{equation*}\n    \\vect{v} = a_1\\vect{u}_1 + a_2\\vect{u}_2 + a_3\\vect{u}_3.\n  \\end{equation*}\n  We have sufficient information to compute $a_1,a_2,a_3$. Namely,\n  \\begin{eqnarray*}\n    a_1\n    &=& \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\n        ~=~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\norm{\\vect{u}_1}^2}\n        ~=~ \\frac{3}{1} ~=~ 3, \\\\\n    a_2\n    &=& \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\n        ~=~ \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\norm{\\vect{u}_2}^2}\n        ~=~ \\frac{-1}{2} ~=~ -0.5, \\\\\n    a_3\n    &=& \\frac{\\iprod{\\vect{u}_3,\\vect{v}}}{\\iprod{\\vect{u}_3,\\vect{u}_3}}\n        ~=~ \\frac{\\iprod{\\vect{u}_3,\\vect{v}}}{\\norm{\\vect{u}_3}^2}\n        ~=~ \\frac{2}{4} ~=~ 0.5.\n  \\end{eqnarray*}\n\\end{solution}\n\nProposition~\\ref{prop:fourier-coefficients} shows that if\n$\\set{\\vect{u}_1,\\ldots,\\vect{u}_n}$ is an orthogonal basis, then we\ncan solve $\\vect{v} = a_1\\vect{u}_1 + \\ldots + a_n\\vect{u}_n$ without\nhaving to solve a system of equations. While this is a useful thing to\nbe able to do, perhaps it is merely a convenience (solving a system of\nequations would also be fine). However, there is another very useful\nproperty of Fourier coefficients. The coefficient $a_i$ only depends\non the basis vector $\\vect{u}_i$, and not on any of the other basis\nvectors. This is useful in situations where only {\\em part} of an\northogonal basis is known. We can calculate the corresponding\ncoefficients without having to know the rest of the basis.\n\n\\begin{example}{Finding partial coordinates}{partial-coordinates}\n  Suppose $B=\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3,\\vect{u}_4}$ is an\n  orthogonal basis of $\\R^4$. We have been told that\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ -1 \\\\ 0 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 2 \\\\ 3 \\end{mymatrix},\n  \\end{equation*}\n  but it is not known what $\\vect{u}_3$ and $\\vect{u}_4$ are. Find the\n  first two coordinates of the vector\n  \\begin{equation*}\n    \\vect{v} = \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 2 \\\\ 0 \\end{mymatrix}\n  \\end{equation*}\n  with respect to the basis $B$.\n\\end{example}\n\n\\begin{solution}\n  We have $\\vect{v} = a_1\\vect{u}_1 + a_2\\vect{u}_2 + a_3\\vect{u}_3 +\n  a_4\\vect{u}_4$, where\n  \\begin{equation*}\n    a_1\n    = \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\n    = \\frac{-1}{6}\n    \\quad\\mbox{and}\\quad\n    a_2\n    = \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\n    = \\frac{4}{14}.\n  \\end{equation*}\n  So the first two coordinates are $-\\frac{1}{6}$ and $\\frac{2}{7}$.\n\\end{solution}\n\nA word of warning is in order: Fourier coefficients do not work when\nthe basis is not orthogonal. Consider the following picture, where\n$\\vect{u}_1$ and $\\vect{u}_2$ are not orthogonal.\n\\begin{equation*}\n  \\begin{tikzpicture}[scale=2]\n    \\draw (-2,0) -- (3,0);\n    \\draw (-0.2,-0.4) -- (1.1,2.2);\n    \\draw[thick,red,fill=yellow!20] (0,0) -- (2,0) -- (2.5,1) -- (0.5,1) -- cycle;\n    \\draw[dashed,green!70!black] (2.5,1) -- (2.5,0) node[below]{$a_1$};\n    \\draw[dashed,green!70!black] (2.5,1) -- (0.9,1.8) node[left,yshift=3]{$a_2$};\n    \\draw[thick,blue,->] (0,0) -- node[below]{$\\vect{u}_1$} (1,0);\n    \\draw[thick,blue,->] (0,0) -- node[left, pos=0.55]{$\\vect{u}_2$} (0.5,1);\n    \\draw[thick,blue,->] (0,0) -- node[above]{$\\vect{v}$} (2.5,1);\n  \\end{tikzpicture}\n\\end{equation*}\nThe {\\em coordinates} of $\\vect{v}$ with respect to\n$\\vect{u}_1,\\vect{u}_2$ are $(2,1)$, because\n$\\vect{v}=2\\vect{u}_1+1\\vect{u}_2$, as indicated by the shaded\nparallelogram. On the other hand, the formula for the {\\em Fourier\n  coefficients} is concerned with the orthogonal projections of\n$\\vect{v}$ onto $\\vect{u}_1$ and $\\vect{u}_2$, as indicated by the\ndashed lines. It yields the coefficients\n\\begin{eqnarray*}\n  a_1 &=& \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}} ~\\approx~ 2.5, \\\\\n  a_2 &=& \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\iprod{\\vect{u}_2,\\vect{u}_2}} ~\\approx~ 1.8.\n\\end{eqnarray*}\nThese are not the same as the coordinates of $\\vect{v}$, because the\ndashed lines are orthogonal to $\\vect{u}_1$ and $\\vect{u}_2$, instead\nof parallel to them. In summary, the Fourier coefficients of a vector\nare equal to its coordinates {\\em only if the basis is orthogonal}.\n\nWhen $\\vect{u}_1,\\ldots,\\vect{u}_k$ are orthogonal, we have a\nconvenient formula for the norm of\n$a_1\\vect{u}_1+\\ldots+a_k\\vect{u}_k$:\n\n\\begin{proposition}{Norm of orthogonal linear combination}{norm-orthogonal}\n  Let $V$ be an inner product space, and suppose that\n  $\\vect{u}_1,\\ldots,\\vect{u}_k$ are orthogonal. Then\n  \\begin{equation*}\n    \\norm{a_1\\vect{u}_1+\\ldots+a_k\\vect{u}_k}^2\n    = a_1^2\\norm{\\vect{u}_1}^2 + \\ldots + a_k^2\\norm{\\vect{u}_k}^2.\n  \\end{equation*}\n\\end{proposition}\n\n\\begin{proof}\n  We have\n  \\begin{eqnarray*}\n    \\norm{a_1\\vect{u}_1+\\ldots+a_k\\vect{u}_k}^2\n    &=&\n    \\iprod{a_1\\vect{u}_1+\\ldots+a_k\\vect{u}_k,a_1\\vect{u}_1+\\ldots+a_k\\vect{u}_k} \\\\\n    &=& \\begin{array}[t]{@{}c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n          &   a_1^2\\iprod{\\vect{u}_1,\\vect{u}_1}\n          &+& a_1a_2\\iprod{\\vect{u}_1,\\vect{u}_2}\n          &+& \\ldots\n          &+& a_1a_n\\iprod{\\vect{u}_1,\\vect{u}_n} \\\\\n          +&  a_2a_1\\iprod{\\vect{u}_2,\\vect{u}_1}\n          &+& a_2^2\\iprod{\\vect{u}_2,\\vect{u}_2}\n          &+& \\ldots\n          &+& a_2a_n\\iprod{\\vect{u}_2,\\vect{u}_n} \\\\\n          +&  \\vdots\n          && \\vdots\n          &&\n          && \\vdots \\\\\n          +&  a_na_1\\iprod{\\vect{u}_n,\\vect{u}_1}\n          &+& a_na_2\\iprod{\\vect{u}_n,\\vect{u}_2}\n          &+& \\ldots\n          &+& a_n^2\\iprod{\\vect{u}_n,\\vect{u}_n}\n        \\end{array} \\\\\n    &=& a_1^2\\norm{\\vect{u}_1}^2 + \\ldots + a_k^2\\norm{\\vect{u}_k}^2.\n  \\end{eqnarray*}\n  Here we have used the fact that $\\iprod{\\vect{u}_i,\\vect{u}_j}=0$\n  when $i\\neq j$. \n\\end{proof}\n\nWe conclude this section by making a connection between arbitrary\ninner products and dot products.  Once an orthonormal basis has been\nchosen on an inner product space, computing inner products is\nessentially the same as computing dot products. The following\nproposition makes this more precise.\n\n\\begin{proposition}{Inner product and dot product}{inner-product-dot-product}\n  Let $V$ be an inner product space, and suppose that\n  $B=\\set{\\vect{u}_1,\\ldots\\vect{u}_n}$ is an orthonormal basis. Then\n  for any pair of vectors $\\vect{v},\\vect{w}\\in V$, their inner\n  product is equal to the dot product of their coordinate vectors with\n  respect to the basis $B$, i.e.\n  \\begin{equation*}\n    \\iprod{\\vect{v},\\vect{w}}\n    = \\coord{\\vect{v}}_B \\dotprod \\coord{\\vect{w}}_B.\n  \\end{equation*}\n\\end{proposition}\n\n\\begin{proof}\n  By definition of coordinate vectors, we have\n  \\begin{equation*}\n    \\coord{\\vect{v}}_B\n    = \\begin{mymatrix}{c} a_1 \\\\ \\vdots \\\\ a_n \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\coord{\\vect{w}}_B\n    = \\begin{mymatrix}{c} b_1 \\\\ \\vdots \\\\ b_n \\end{mymatrix},\n  \\end{equation*}\n  where $\\vect{v} = a_1\\vect{u}_1 + \\ldots + a_n\\vect{u}_n$\n  and $\\vect{w} = b_1\\vect{u}_1 + \\ldots + b_n\\vect{u}_n$.\n  We calculate\n  \\begin{eqnarray*}\n    \\iprod{\\vect{v},\\vect{w}}\n    &=& \\iprod{a_1\\vect{u}_1 + \\ldots + a_n\\vect{u}_n, b_1\\vect{u}_1 +\n        \\ldots + b_n\\vect{u}_n} \\\\\n    &=& \\begin{array}[t]{@{}c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n          &   a_1b_1\\iprod{\\vect{u}_1,\\vect{u}_1}\n          &+& a_1b_2\\iprod{\\vect{u}_1,\\vect{u}_2}\n          &+& \\ldots\n          &+& a_1b_n\\iprod{\\vect{u}_1,\\vect{u}_n} \\\\\n          +&  a_2b_1\\iprod{\\vect{u}_2,\\vect{u}_1}\n          &+& a_2b_2\\iprod{\\vect{u}_2,\\vect{u}_2}\n          &+& \\ldots\n          &+& a_2b_n\\iprod{\\vect{u}_2,\\vect{u}_n} \\\\\n          +&  \\vdots\n          && \\vdots\n          &&\n          && \\vdots \\\\\n          +&  a_nb_1\\iprod{\\vect{u}_n,\\vect{u}_1}\n          &+& a_nb_2\\iprod{\\vect{u}_n,\\vect{u}_2}\n          &+& \\ldots\n          &+& a_nb_n\\iprod{\\vect{u}_n,\\vect{u}_n}\n        \\end{array} \\\\\n    &=& a_1b_1 + a_2b_2 + \\ldots + a_nb_n \\\\\n    &=& \\coord{\\vect{v}}_B \\dotprod \\coord{\\vect{w}}_B.\n  \\end{eqnarray*}\n  Here we have used the fact that $\\iprod{\\vect{u}_i,\\vect{u}_j}=1$\n  when $i=j$ and $\\iprod{\\vect{u}_i,\\vect{u}_j}=0$ otherwise, which\n  holds because $B$ is orthonormal.\n\\end{proof}\n", "meta": {"hexsha": "3e8d722868568e19d7cfebda8bd7c7122e7b3b3b", "size": 21323, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/InnerProductSpaces-Orthogonality.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/InnerProductSpaces-Orthogonality.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/InnerProductSpaces-Orthogonality.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 39.7076350093, "max_line_length": 93, "alphanum_fraction": 0.6233175444, "num_tokens": 8299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.8824278741843884, "lm_q1q2_score": 0.7172967712726636}}
{"text": "\\input{../header_function}\r\n\r\n%---------- start document ---------- %\r\n \\section{multiplicative -- multiplicative number theoretic functions}\\linkedzero{multiplicative}\r\n%\r\nAll functions of this module accept only positive integers,\r\nunless otherwise noted.\r\n%\r\n  \\subsection{euler -- the Euler totient function}\\linkedone{multiplicative}{euler}\r\n   \\func{euler}\r\n   {%\r\n     \\hiki{n}{integer}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the number of numbers relatively prime to \\param{n}\r\n   and smaller than \\param{n}.  In the literature, the function is\r\n   referred often as \\(\\varphi\\).\r\n\r\n  \\subsection{moebius -- the M\\\"obius function}\\linkedone{multiplicative}{moebius}\r\n   \\func{moebius}\r\n   {%\r\n     \\hiki{n}{integer}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return:\r\n   \\begin{description}\r\n   \\item[-1] if n has odd distinct prime factors,\r\n   \\item[1] if n has even distinct prime factors, or\r\n   \\item[0] if n has a squared prime factor.\r\n   \\end{description}\r\n   In the literature, the function is referred often as \\(\\mu\\).\r\n\r\n  \\subsection{sigma -- sum of divisor powers)}\\linkedone{multiplicative}{sigma}\r\n   \\func{sigma}\r\n   {%\r\n     \\hiki{m}{integer},\\ %\r\n     \\hiki{n}{integer}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   Return the sum of \\param{m}-th powers of the factors of \\param{n}.\r\n   The argument \\param{m} can be zero, then return the number of factors.\r\n   In the literature, the function is referred often as \\(\\sigma\\).\r\n%\r\n\\begin{ex}\r\n>>> multiplicative.euler(1)\r\n1\r\n>>> multiplicative.euler(2)\r\n1\r\n>>> multiplicative.euler(4)\r\n2\r\n>>> multiplicative.euler(5)\r\n4\r\n>>> multiplicative.moebius(1)\r\n1\r\n>>> multiplicative.moebius(2)\r\n-1\r\n>>> multiplicative.moebius(4)\r\n0\r\n>>> multiplicative.moebius(6)\r\n1\r\n>>> multiplicative.sigma(0, 1)\r\n1\r\n>>> multiplicative.sigma(1, 1)\r\n1\r\n>>> multiplicative.sigma(0, 2)\r\n2\r\n>>> multiplicative.sigma(1, 3)\r\n4\r\n>>> multiplicative.sigma(1, 4)\r\n7\r\n>>> multiplicative.sigma(1, 6)\r\n12L\r\n>>> multiplicative.sigma(2, 7)\r\n50\r\n\\end{ex}%Don't indent!(indent causes an error.)\r\n\\C\r\n\r\n%---------- end document ---------- %\r\n\r\n\\input{../footer}\r\n", "meta": {"hexsha": "1b80d0ecfc3d27b3c0b9f99eab5cd900d1da335c", "size": 2247, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/en/multiplicative.tex", "max_stars_repo_name": "turkeydonkey/nzmath3", "max_stars_repo_head_hexsha": "a48ae9efcf0d9ad1485c2e9863c948a7f1b20311", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-26T19:22:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T19:22:17.000Z", "max_issues_repo_path": "manual/en/multiplicative.tex", "max_issues_repo_name": "turkeydonkey/nzmath3", "max_issues_repo_head_hexsha": "a48ae9efcf0d9ad1485c2e9863c948a7f1b20311", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "manual/en/multiplicative.tex", "max_forks_repo_name": "turkeydonkey/nzmath3", "max_forks_repo_head_hexsha": "a48ae9efcf0d9ad1485c2e9863c948a7f1b20311", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.9666666667, "max_line_length": 98, "alphanum_fraction": 0.6350689809, "num_tokens": 640, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.8438951045175642, "lm_q1q2_score": 0.7172865173256029}}
{"text": "% Author: Jonathan Siegel\n% This chapter aims to provide an introduction to the online learning framework.\n% We consider only the convex problems and first-order (i.e. gradient-based) methods.\n\n\\section{Online Optimization}\nIn this chapter we introduce the concept of online learning.\n\nIn the online setting, we observe a sequence of objective functions $f_i$. We generate iterates $x_i$ based on the\nobserved functions $f_i$ with the goal of minimizing the regret $R(x,z^*)$ where\n\\begin{equation}\n R(x_1,...,x_n,z) = \\displaystyle\\sum_{i = 1}^n (f_i(x_i) - f_i(z))\n\\end{equation}\nand $z^*\\in\\arg\\min_{z} \\displaystyle\\sum_{i = 1}^n f_i(z)$. Notice the point $z$ is fixed in hindsight while the $x_i$ vary.\n\nWe begin by deriving regret bounds for the dual averaging method in the convex, Lipschitz case. The dual averaging method\nis given by\n\\begin{equation} \\label{online_DA}\n x_{n + 1} = \\arg\\min_x \\left(\\displaystyle\\sum_{i = 1}^n \\langle sg_i, x\\rangle + \\frac{\\alpha_{n+1}}{2}\\|x - x_1\\|_2^2\\right)\n\\end{equation}\nwhere $g_i\\in \\partial f_i(x_i)$. Note that if $\\alpha_i = 1$, then we simply have subgradient descent with\nstepsize $s$. We have the following theorem.\n\\begin{theorem}\n Assume that each $f_i$ is convex and Lipschitz with constant $M$. Let $x_i$ be given by iteration (\\ref{online_DA})\n with $\\alpha_i \\leq \\alpha_{i+1}$.\n Then for any $z$, we have\n \\begin{equation}\n  R(x_1,...,x_n,z) \\leq \\frac{\\alpha_n}{2s} \\|z - x_1\\|_2^2 + \\frac{sM^2}{2}\\displaystyle\\sum_{i = 1}^n \\frac{1}{\\alpha_i}\n \\end{equation}\n \\end{theorem}\n \\begin{proof}\n  We note that by convexity, we have\n  \\begin{equation}\\label{convexity_bound}\n   R(x_1,...,x_n,z) = \\displaystyle\\sum_{i = 1}^n (f_i(x_i) - f_i(z)) \\leq \\displaystyle\\sum_{i = 1}^n\\langle g_i, x_i - z\\rangle\n   = \\frac{1}{s}\\displaystyle\\sum_{i = 1}^n\\langle sg_i, x_i - z\\rangle\n  \\end{equation}\n  We proceed by rewriting the sum as follows\n  \\begin{equation}\\label{sum_rewriting}\n   \\displaystyle\\sum_{i = 1}^n\\langle sg_i, x_i - z\\rangle = \\displaystyle\\sum_{i = 1}^n\\langle sg_i, x_n - z\\rangle + \n   \\displaystyle\\sum_{i = 1}^{n-1} \\displaystyle\\sum_{j = 1}^i \\langle sg_j, x_i - x_{i+1}\\rangle\n  \\end{equation}\n  We now bound the quantity\n  \\begin{equation}\n   \\displaystyle\\sum_{j = 1}^i \\langle sg_j, x_i - y\\rangle\n  \\end{equation}\n  for arbitrary $y$ as follows. We note that by (\\ref{online_DA}), we have\n  \\begin{equation}\n   x_i = \\arg\\min_x \\displaystyle\\sum_{j = 1}^{i-1} \\langle sg_j, x\\rangle + \\frac{\\alpha_i}{2}\\|x - x_1\\|_2^2 = \\arg\\min_x f_i(x)\n  \\end{equation}\n  This means that $0\\in \\partial f_i(x_i)$ and so $sg_i\\in \\partial f_i^\\prime(x_i)$ where \n  $f_i^\\prime(x) = f_i(x) + \\langle sg_i, x\\rangle$. Note additionally that $f_i$ and thus $f_i^\\prime$ are strongly\n  convex with convexity parameter $\\alpha_i$. This implies that for any $y$,\n  \\begin{equation}\n   f_i^\\prime(x_i) - f_i^\\prime(y) \\leq \\frac{1}{2\\alpha_i}\\|sg_i\\|_2^2 \\leq \\frac{s^2M^2}{2\\alpha_i}\n  \\end{equation}\n  since $\\|g_i\\|_2\\leq M$ by the Lipschitz assumption on $f_i$. Plugging in $y = x_{i+1}$ and $y = z$, and\n  expanding $f_i^\\prime$, we see that\n  \\begin{equation}\n   (\\ref{sum_rewriting})\\leq \\frac{\\alpha_n}{2} \\|z - x_1\\|_2^2 \n   + \\frac{1}{2}\\displaystyle\\sum_{i = 2}^n (\\alpha_{i-1} - \\alpha_i)\\|x_i - x_1\\|_2^2 + \\frac{s^2M^2}{2}\\displaystyle\\sum_{i = 1}^n \\frac{1}{\\alpha_i}\n  \\end{equation}\n  Now the assumption that $\\alpha_{i-1} - \\alpha_i\\leq 0$ implies that\n  \\begin{equation}\n   (\\ref{sum_rewriting})\\leq \\frac{\\alpha_n}{2} \\|z - x_1\\|_2^2 + \\frac{s^2M^2}{2}\\displaystyle\\sum_{i = 1}^n \\frac{1}{\\alpha_i}\n  \\end{equation}\n  Plugging this into equation (\\ref{convexity_bound}), we get\n  \\begin{equation}\n   R(x_1,...,x_n,z) \\leq \\frac{\\alpha_n}{2s} \\|z - x_1\\|_2^2 + \\frac{sM^2}{2}\\displaystyle\\sum_{i = 1}^n \\frac{1}{\\alpha_i}\n  \\end{equation}\n\n\n \\end{proof}\n\n Note that setting $\\alpha_i = 1$ and $s_i = \\frac{1}{\\sqrt{n}}$ produces a regret which is $O(\\sqrt{n})$. It can be\n shown that this is optimal for convex Lipschitz functions in the black-box setting.\n\\section{Cycle SGD}\nWe now use the results on online optimization to derive convergence results for the cycle SGD algorithm.\nTo this end, we let $f_1,...,f_n$, be a collection of convex, Lipschitz functions and suppose we want\nto minimize\n\\begin{equation}\n f(x) = \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n f_i(x)\n\\end{equation}\nThe cycle SGD for $k$ epochs is the same as running the online algorithm (\\ref{online_DA}) with $\\alpha_i = 1$ on the sequence of\nfunctions $f_1,...,f_{nk}$ where $f_i = f_{i\\mod n}$, i.e. we repeat the same sequence over and over again. \nGiven any such order, we obtain the regret bound from the previous section\n\\begin{equation}\n \\displaystyle\\sum_{i = 1}^{nk} (f_i(x_i) - f_i(x^*)) \\leq \\frac{1}{2s} \\|x^* - x_1\\|_2^2 + \\frac{knsM^2}{2}\n\\end{equation}\n\nNow let $\\bar{x} = \\frac{1}{nk}\\displaystyle\\sum_{i = 1}^{nk} x_i$ be the average of the iterates $x_i$ and note that\n\\begin{equation}\n f(\\bar{x}) - f(x^*) = \\frac{1}{n}\\displaystyle\\sum_{i = 1}^{n} (f_i(\\bar{x}) - f_i(x^*)) \n \\leq \\frac{1}{kn^2}\\displaystyle\\sum_{i = 1}^{n} \\displaystyle\\sum_{j = 1}^{nk} (f_i(x_j) - f_i(x^*))\n\\end{equation}\nRewriting this, we get\n\\begin{equation}\n f(\\bar{x}) - f(x^*) \\leq \\frac{1}{kn^2}\\displaystyle\\sum_{i = 1}^{n} \\displaystyle\\sum_{j = 1}^{nk} (f_i(x_{k(i,j)}) - f_i(x^*)) + (f_i(x_j) - f_i(x_{k(i,j}))\n\\end{equation}\nwhere $k(i,j)$ is the index in the same block as $j$ which is congruent to $i$ mod $n$.\n\nThe regret bound implies that\n\\begin{align}\n \\frac{1}{kn^2}\\displaystyle\\sum_{i = 1}^{n} \\displaystyle\\sum_{j = 1}^{nk} (f_i(x_{k(i,j)}) - f_i(x^*)) \n &= \\frac{1}{nk}\\displaystyle\\sum_{i = 1}^{nk} (f_i(x_i) - f_i(x^*)) \\\\\n &\\leq \\frac{1}{2nks} \\|x^* - x_1\\|_2^2 + \\frac{sM^2}{2}\n\\end{align}\n\nIt remains to bound \n$$\\frac{1}{kn^2}\\displaystyle\\sum_{i = 1}^{n} \\displaystyle\\sum_{j = 1}^{nk} (f_i(x_j) - f_i(x_{k(i,j}))\n$$\n\nNote that for each $i$, $f_i$ is $M$-Lipschitz and since $x_{i+1} = x_{i} + sg_i$, we have $|x_j - x_{k(i,j)}|\\leq sM|j - k(i,j)|$.\nThis means that\n\\begin{equation}\n \\frac{1}{kn^2}\\displaystyle\\sum_{i = 1}^{n} \\displaystyle\\sum_{j = 1}^{nk} (f_i(x_j) - f_i(x_{k(i,j})) \\leq \\frac{sM^2}{kn^2}\\displaystyle\\sum_{i = 1}^{n} \\displaystyle\\sum_{j = 1}^{nk} |j - k(i,j)|\n\\end{equation}\nIt is a simple matter to check that for each $j$, we have\n\\begin{equation}\n \\displaystyle\\sum_{i = 1}^{n}|j - k(i,j)| \\leq \\frac{n(n-1)}{2}\n\\end{equation}\nwhich means that\n\\begin{equation}\n \\frac{1}{kn^2}\\displaystyle\\sum_{i = 1}^{n} \\displaystyle\\sum_{j = 1}^{nk} (f_i(x_j) - f_i(x_{k(i,j})) \\leq \\frac{sM^2(n-1)}{2}\n\\end{equation}\nPutting all of this together, this means that\n\\begin{equation}\n f(\\bar{x}) - f(x^*) \\leq \\frac{1}{2}\\left(\\frac{1}{nks} \\|x^* - x_1\\|_2^2 + sM^2n\\right)\n\\end{equation}\nIf we let $R = \\|x^* - x_1\\|_2$, then setting $s = \\frac{R}{Mn\\sqrt{k}}$ gives a bound\n\\begin{equation}\n f(\\bar{x}) - f(x^*) \\leq \\frac{1}{2\\sqrt{k}}\\left(R^2 + M^2\\right)\n\\end{equation}\n\n\\section{Shuffle SGD}\nFinally, we conside the shuffle SGD algorithm. Let $f_1,...,f_n$, be a collection of convex, Lipschitz functions and suppose we want\nto minimize\n\\begin{equation}\n f(x) = \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n f_i(x)\n\\end{equation}\nThe shuffle SGD algorithm chooses the order $f_1,...,f_n$ randomly in each epoch. The convergence rate of cycle SGD \napplies for the shuffle SGD as well. However, it should be possible to obtain an improved convergence\nrate if the order is randomly shuffled each time. However, I believe the convergence rate of the shuffle SGD\nalgorithm is still an open problem, all of the literature I'm aware of make additional assumptions beyond\nthe Lipschitz and convex assumptions. See \\cite{shamir2016without} for instance.\n\n\\iffalse\n\\section{Introduction}\n\\subsection{Basic Concepts}\n\\subsection{Example: Learning from Expert Advice}\n\\section{Gradient Descent}\n\\subsection{Convex Case}\n\\subsection{Strongly Convex Case}\n\\section{Mirror Descent}\n\\subsection{Example: Learning from Expert Advice as Mirror Descent}\n\\fi", "meta": {"hexsha": "96c9be8cc84856cd3aa94745746673fac8ae41b5", "size": 8020, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/OnlineLearning.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/OnlineLearning.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/OnlineLearning.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.0779220779, "max_line_length": 199, "alphanum_fraction": 0.6739401496, "num_tokens": 3013, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7172865091129306}}
{"text": "\\section{Inner Products and Norms}\n\n\\subsection{Inner Products}\n\n\tDot products are a form of inner product.\n\n\tLet's apply the dot product to the vectors $<v_1,v_2,\\ldots,v_n>\\cdot<w_1,w_2,\\ldots,w_3>$ to show that the dot product is an inner product.\n\n\t\\begin{equation}\n\t\t=v_1w_1+v_2w_2+\\ldots+v_nw_n\n\t\\end{equation}\n\n\tTherefore, $v\\times v$ goes to $\\R$. So we know that \n\n\t\\begin{equation}\n\t\t\\vec{v}\\cdot\\vec{v}=v_1^2+v_2^2+\\ldots+v_n^2\n\t\\end{equation}\n\n\tIn general, we can assume that $ | | \\vec{v} | | = \\sqrt{\\vec{v}\\vec{v}}$. We should also keep in mind that $\\vec{v}\\cdot\\vec{w}= | | \\vec{v} | | | | \\vec{w} | | \\cos\\theta$ \n\n\t\\begin{definition}\n\t\tAAn inner product of $V$ is a function $<,>:v\\times v\\to\\R$ such that\n\n\t\t\\begin{itemize}\n\t\t\t\\item\\begin{align}\n\t\t\t\t\t<c\\vec{u}+d\\vec{v},w> &= c<\\vec{u},\\vec{v}>+d<\\vec{v},\\vec{u}>\\\\\n\t\t\t\t<\\vec{u},c\\vec{v}+d\\vec{w}&=c<\\vec{u},\\vec{v}>+d<\\vec{u},\\vec{w}>\n\t\t\t\\end{align}\n\t\t\t\\item $<\\vec{v},\\vec{w}> = <\\vec{w}, \\vec{v}>$\n\t\t\t\\item $<\\vec{v},\\vec{v}>\\ge_0$ while $<0,0> = \\vec{0}$.\t\n\t\t\\end{itemize}\n\t\\end{definition}\n\n\tA vector space with an inner product is an inner product space.\n\n\t\\begin{definition}\n\t\tIIf $V$ is an inner product space, then it's magnitude is \n\t\t\n\t\t\\begin{equation}\n\t\t\t| | \\vec{v} | | = \\sqrt{<\\vec{v},\\vec{v}>} \n\t\t\\end{equation}\n\t\\end{definition}\n\n\tLet's take a look at a weighted inner product on $\\R^3$. We are going to let $r_1,r_2,r_3>0$. We can define $<\\vec{v},\\vec{w}>$ as $r_1v_1w_1+r_2v_2w_2+r_3v_3w_3$\n\n\t\\begin{problem}\n\t\tLet's define $[a,b]\\le\\R$. Consider $\\mathbb{C}^0[a,b]$. This is a vector space. Define \n\t\t\\begin{equation}\n\t\t\t<f(x),g(x)> = \\int_a^bf(x)g(x)dx\n\t\t\\end{equation}\n\n\t\tThis is an inner product, so we also know that\n\n\t\t\\begin{equation}\n\t\t\t| | f | | = \\sqrt{\\int_a^b\\left(f(x)\\right)^2dx}\n\t\t\\end{equation}\n\n\t\tThis equation is the $L^2$ norm.\n\t\\end{problem}\n\n\\subsection{Inequalities}\n\n\tRecall that $\\vec{v}\\cdot\\vec{w} = | | \\vec{v} | | | | \\vec{w} | |\\cos\\theta$, where $\\theta$ is the angle between $\\vec{v}$ and $\\vec{w}$. Now $-1\\le\\cos\\theta\\le_1$, so we know that \n\t\n\t\\begin{equation}\n\t\t| | \\vec{v}\\cdot\\vec{w} | | \\le | | \\vec{v} | | | | \\vec{w} | |\n\t\\end{equation}\n\n\tThis is the Cauchy-Shuartz inequality.\n\n\t\\begin{theorem}\n\t\tFFor any inner product space\n\n\t\t\\begin{equation}\n\t\t\t||<\\vec{v},\\vec{w}>||\\le | | \\vec{v}  | | | | \\vec{w} | |\n\t\t\\end{equation}\n\t\\end{theorem}\n\n\t\\begin{definition}\n\t\tIIf $\\vec{v},\\vec{w}\\in V$, we say $\\vec{v}$ and $\\vec{w}$ are orthogonal if $<\\vec{v},\\vec{w}> = 0$\n\t\\end{definition}\n\n\t\\begin{problem}\n\t\tLet's look at an example of checking orthogonality of two equations $x,x^2-y\\in\\mathbb{C}^0[0,1]$. In order to do this we need to find the $L^2$ norm of the equations.\n\t\t\\begin{align*}\n\t\t\t\\left<x,x^2-\\frac{1}{2}\\right> &= \\int_0^1x\\left(x^2-\\frac{1}{2}\\right)dx\\\\\n\t\t\t\t\t    &=\\int_0^1\\left(x^3-\\frac{1}{2}x\\right)dx\\\\\n\t\t\t\t\t    &=\\left.\\frac{1}{4}x^4-\\frac{1}{4}x^2\\right|_0^1=0\n\t\t.\\end{align*}\t\n\t\tBecause the result of the inner product was zero, we know that $x,x^2-\\frac{1}{2}$ are orthogonal in the $L^2$ norm.\n\t\\end{problem}\n\n\t\\begin{theorem}\n\t\tTThe triangle inequality states that if $V$ is an inner product space,\n\n\t\t\\begin{equation}\n\t\t\t| | <\\vec{v},\\vec{w}> | | = | | \\vec{v} | | + | | \\vec{w} | |\n\t\t\\end{equation}\n\t\\end{theorem}\n\n\tBecause we know that if we take the dot product of the same vector itself, $<a,b,c>\\cdot<a,b,c>$, we get all of the items squared $<a^2,b^2,c^2>$, and because we know that $| | \\vec{v} | | = \\sqrt{<\\vec{v},\\vec{v}>}$, we get an idea of size. So we can define the unit ball to be \n\t\\begin{equation}\n\t\t\\{\\vec{v}\\in V\\Big| | | \\vec{v} | | = 1\\}\t\t\n\t\\end{equation}\n\n\\subsection{Norms}\n\n\tEquation (3.5) gives us the \"size\" of $\\vec{V}$.\n\n\t\\begin{definition}\n\t\tAA norm on $V$ is a function $ | | \\cdot | |:V\\to\\R$ such that \n\t\t\\begin{itemize}\n\t\t\t\\item $| | \\vec{v} | | = 0$ if and only if $\\vec{v}=0$\n\t\t\t\\item $| | c\\vec{v} | | = |c|\\cdot| | \\vec{v} | |$\n\t\t\t\\item $| | \\vec{v}+\\vec{w} | | \\le | | \\vec{v} | | + | | \\vec{w} | |$\n\t\t\\end{itemize}\n\n\t\tIf $||<\\vec{v},\\vec{w}>||\\le | | \\vec{v}  | | | | \\vec{w} | |$, then that is a norm. There are other norms to learn about. \n\t\t\t\n\t\\end{definition}\n\n\t\\begin{problem}\n\t\tConsider $V=\\R^n$. We know that the magnitude of $\\vec{V}_p$ is \n\t\t\\begin{equation}\n\t\t\t\\sqrt[p]{|\\vec{v_1}|^p+|\\vec{v_2}|^p+|\\vec{v_3}|^p}.\n\t\t\\end{equation}\n\t\tSo if $v=\\R^2$, $p=2$ we have \n\t\t\\begin{equation}\n\t\t\t| |<x,y>| | _2=\\sqrt{x^2+y^2}. \n\t\t\\end{equation}\n\t\tBut if we were to have $p=3$, we would have \n\t\t\\begin{equation}\n\t\t\t| | <x,y> | |_3=\\sqrt[3]{x^3+y^3}\n\t\t\\end{equation}\n\t\t\n\t\tIn $| | \\cdot | |_3$, the size is $\\sqrt[3]{3^3+4^3} \\approx_4.5$\n\t\\end{problem}\n\n\tIn the 4 term, $| | \\cdot | |_4$, the unit circle is the $(x,y)$'s such that $\\sqrt[4]{x^4\\cdot Y_4} =1$\n\n\t\\begin{equation}\n\t\t\\boxed{x^4+y^4=1}\n\t\\end{equation}\n\n\tAnother norm on $R^n$ is the super-norm. This is where\n\n\t\\begin{equation}\n\t\t| |<x_1,x_2,\\ldots,x_n>| |_\\infty = max\\{|x_1|,|x_2|,\\ldots,|x_n|\\}\t\n\t\\end{equation}\n\n\tHere's a quick example: The super-norm for $<3,4>$ is \n\n\t\\begin{equation}\n\t\t| | <3,4> | |_\\infty=4\n\t\\end{equation}\n\n\tbecause the maximum value in the set is $4$.\n\n\tSomething to keep in mind is $| | <x,y> | |=|x|+|y|$.\n\n\t\\begin{theorem}\n\t\tLLet $| | \\cdot | |_A$ and $| | \\cdot | |_B$ be two norms on $\\R^n$. Then there exists positive numbers $0<c<k$ such that \n\t\t\\begin{equation}\n\t\t\tc\\cdot| | \\vec{v} | |_A<| | \\vec{v} | |_B<k \\cdot | | \\vec{v} | |_A\n\t\t\\end{equation}\n\t\\end{theorem}\n\t\tLet's consider $V\\in\\R^2$. Let's take a look at $| | \\cdot | |_2$ and $| | \\cdot | | _\\infty$. Where $\\vec{V}= <v_1,v_2>$.\n\n\t\\begin{equation}\n\t\t\\frac{1}{\\sqrt{2} }\\cdot | | \\vec{v} | |_2\\le | | \\vec{v} | | _\\infty < 1\\cdot | | \\vec{v} | |_2\n\t\\end{equation}\n\n\tWe can also define norms on matrices.\n\n\t\\begin{theorem}\n\t\tIIf $| | \\cdot | |$ is a norm on $\\R^2$ and $A$ is an $m\\times n$ matrix, then\n\n\t\t\\begin{equation}\n\t\t\t| | A | | = max\\{| | A\\cdot\\vec{u}| | \\Big| | |\\vec{u} | | = 1\n\t\t\\end{equation}\n\t\\end{theorem}\n\n\tThese matrix norms satisfy the following:\n\n\t\\begin{enumerate}\n\t\t\\item $| | A\\cdot\\vec{v} | | \\le | | A | | \\cdot | | \\vec{v} | |$\n\t\t\\item $ | | A\\cdot B | | \\le | | A | | \\cdot | | B | |$\n\t\t\\item $| | A^k| | \\le | | A | | ^k$\n\t\\end{enumerate}\n\n\tLet's take a quick look at $| | A | |_\\infty$\n\n\t\\begin{definition}\n\t\tTThe $i^{th}$ absolute row sum of $A$ is the sum of the absolute values of the entries in the $i^{th}$ row.\n\t\\end{definition}\n\n\t\\begin{theorem}\n\t\ty$| | A | |_\\infty$ the maximum absolute row sum.\n\t\\end{theorem}\n\n\tHere's an example of using the $| | A | |_\\infty$ value. Let $A=\\SmallMatrix{-3&2\\\\5&4}$. We can determine that the maximum absolute row sum of $A$ is 8. This is because we can do \n\n\t\\begin{align}\n\t\t|-3|+|2|&=5\\\\\n\t\t|5|+|3|&=\\boxed{8}\n\t\\end{align}\n\\subsection{Positive Definite Matrices}\n\n\tConsider the following two equations:\n\n\t\\begin{align}\n\t\t\\vec{x}=x_1\\vec{e_1}+x_2\\vec{e_2}+\\ldots+x_n\\vec{e_n}\\\\\n\t\t\\vec{y}=y_1\\vec{e_1}+y_2\\vec{e_2}+\\ldots+v_n\\vec{e_n}\n\t\\end{align}\n\n\tWe can analyze this as \n\n\t\\begin{equation}\n\t\t<\\vec{x},\\vec{y}> = [x_1,x_2,\\ldots,x_n]\\cdot \\begin{bmatrix} k_{11}&\\ldots&k_{1n}\\\\ \\vdots&\\ddots&\\vdots\\\\ k_{n_1}&\\ldots&k_{nn} \\end{bmatrix} \\begin{bmatrix} y_1\\\\y_2\\\\ \\vdots y_n \\end{bmatrix} \n\t\\end{equation}\n\n\t\\begin{align}\n\t\tk_{ij}&= <e_i,e_j>\\\\\n\t\t&=\\vec{x}^Tk\\vec{y}\\\\\n\t\tk&=k^T\n\t\\end{align}\n\n\tThis means that $k$ is symmetrical across the diagonal.\n\n\t\\begin{equation}\n\t\t\\begin{bmatrix} k_{11}&k_{12}&k_{13}\\\\ k_{12}&k_{22}&k_{23}\\\\ k_{13}&k_{23}&k_{33} \\end{bmatrix} \n\t\\end{equation}\n\n\t\\begin{definition}\n\t\tAA $n\\times n$ matrix $A$ is a symmetrical positive definite matrix if $A=A^{T}$ and $x^{t}k<x>0$.\n\t\\end{definition}\n\n\t\\begin{theorem}\n\t\tEEvery inner product on $\\R^{n}$ is given by $<x,y> = \\vec{x}^{T}k\\vec{y}$ where $k$ is a symmetrical positive definite matrix. So $<\\vec{x},\\vec{y}>$ is a dot product or a weighted product.\n\t\t\\begin{align}\n\t\t\t<\\vec{x},\\vec{y}> &= \\vec{x}^{T}k\\vec{y}\\\\\n\t\t\tk^{T}&=k\\\\\n\t\t\t\\vec{v}^{T}k\\cdot\\vec{v} &>0\\\\\n\t\t\t\\vec{v}\\neq_0\n\t\t\\end{align}\n\t\\end{theorem}\n\n\tLet's take a look at an example for this:\n\n\t\\begin{problem}\n\t\tLet $k=\\left[\\begin{smallmatrix}2&0\\\\0&3\\end{smallmatrix}\\right]$. First we need to check to see if $k^T=k$. By just looking at $k$, we can see that $k^{T}=k$. Next we need to do the following calculation to see if $\\left[\\begin{smallmatrix}x\\\\y\\end{smallmatrix}\\right]$ is the weighted inner product of the matrix $k$.\n\n\t\t\\begin{align}\n\t\t\t\\begin{bmatrix} x&y \\end{bmatrix} \\begin{bmatrix} 2&0\\\\0&3 \\end{bmatrix} \\begin{bmatrix} x\\\\y \\end{bmatrix} &= \\begin{bmatrix} x&y \\end{bmatrix} \\begin{bmatrix} 2x\\\\3x \\end{bmatrix} \\\\\n\t\t\t\t\t =2x^2+2y^2&>0\\\\\n\t\t\t\\begin{bmatrix} x\\\\y \\end{bmatrix} &\\neq\\begin{bmatrix} 0\\\\0 \\end{bmatrix} \n\t\t\\end{align}\n\t\tTherefore we know that \n\t\\end{problem}\n\n\t\\begin{problem}\n\t\tLet's consider the following problem\n\n\t\t\\begin{equation}\n\t\t\t\\begin{bmatrix} x&y \\end{bmatrix} \\begin{bmatrix} 4&-2\\\\-2&3 \\end{bmatrix} \\begin{bmatrix} x\\\\y \\end{bmatrix} \n\t\t\\end{equation}\n\n\t\tIf we let $A$ be the numerical matrix, we can see that $A^{T}=A$. Let's simplify the equation from before\n\n\t\t\\begin{align}\n\t\t\t\\begin{bmatrix} x&y \\end{bmatrix} \\begin{bmatrix} 4x-2y\\\\-2x+3y \\end{bmatrix}&=4x^2-2xy-2xy+3x^2\\\\\n\t\t\t\t\t &=4x^2-4xy+3y^2\\\\\n\t\t\t(2x-y)^2+2y^2&>0\\begin{bmatrix} x\\\\y \\end{bmatrix} \\neq\\begin{bmatrix} 0\\\\0 \\end{bmatrix} \n\t\t\\end{align}\n\t\tNow we can see that this is a positive definite matrix.\n\t\\end{problem}\n\tIf we are given a symmetric matrix, $k$, the polynomial $x^{T}kx$ is a quadratic form of $k$.\n\n\t\\begin{problem}\n\t\tLet's consider $k=\\begin{bmatrix} 1&-3\\\\-3&2 \\end{bmatrix}$. Let's find the quadratic form of $k$. First we need to write $k$ like so:\n\n\t\t\\begin{align}\n\t\t\t\\begin{bmatrix} x&y \\end{bmatrix} \\begin{bmatrix} 1&-3\\\\-3&2 \\end{bmatrix} \\begin{bmatrix} x\\\\y \\end{bmatrix} &=\\begin{bmatrix} x&y \\end{bmatrix} \\begin{bmatrix} x-3y\\\\-3x+2y \\end{bmatrix} \\\\\n\t\t\t\t\t &=x^3-3xy-3xy+2y^2\\\\\n\t\t\t\t\t &=x^3-6xy+2y^2\\\\\n\t\t\\end{align}\n\t\t Therefore we know that the quadratic form of $k$ is $x^3-6xy-2y^2$.\n\t\\end{problem}\n\n  For a positive definite matrix, $k=k^{T}$ and $x^{T}kx>0$ for all $\\vec{x}\\neq 0$\n\n  \\begin{theorem}\n    EEvery inner product in $\\R^n$ is given by \n    \\begin{equation}\n      <x,y> = x^{T}ky \\text{ for }xy\\in\\R^n\n    \\end{equation}\n\n    Let $v$ be an inner product space and $\\vec{v_1},\\ldots,\\vec{v_2}$. The gram matrix of $v$ is \n    \\begin{equation}\n      K=\n      \\begin{bmatrix} \n        <v_1,v_2>&<v_1,v_2>&\\ldots&<v_1,v_n>\\\\\n        <v_2,v_1>&<v_2,v_2>&\\ldots&<v_2,v_n>\\\\\n        \\vdots&\\vdots&\\ddots&\\vdots\\\\\n        <v_n,v_1>&<v_n,v_2>&\\ldots&<v_n,v_n>\n      \\end{bmatrix} \n    \\end{equation}\n  \\end{theorem}\n\n  \\begin{definition}\n    AA is a matrix that is $n\\times n$. A is a positive semidefinite matrix if $A^{T}=A$ and $\\vec{x}^{T}A\\vec{x}\\ge 0$\n  \\end{definition}\n\n  \\begin{theorem}\n    AAll gram matrices are positive semi-definite. They are positive definite if and only if $\\vec{v_1},\\ldots,\\vec{v_n}$ are linearly independent.\n  \\end{theorem}\n\n  Suppose we are in $R^{m}$ and the inner produt is the dot product. Let $\\vec{v_1},\\ldots \\vec{v_n}\\in\\R^{m}$\\newline\n  Let $A=[v_1,v_2,v_3,\\ldots,v_n]$. Then $K=A^{T}$. Let A be a gram matrix generated by $v_1,\\ldots,v_n$ with the dot product.\n\n  \\begin{align}\n    K=A^{T}A&=\\begin{bmatrix} \\vec{v_1}\\\\\\vec{v_2}\\\\ \\vdots\\\\\\vec{v_n} \\end{bmatrix}\n    \\begin{bmatrix} \\vec{v_1}&\\vec{v_2}&\\ldots&\\vec{v_n} \\end{bmatrix} \\\\\n                             &=\n    \\begin{bmatrix} \n      <v_1,v_1>&<v_1,v_2>&\\ldots&<v_1,v_n>\\\\\n      <v_2,v_1>&<v_2,v_2>&\\ldots&<v_2,v_n>\\\\\n      \\vdots&\\vdots&\\ddots&\\vdots\\\\\n      <v_n,v_1>&<v_n,v_2>&\\ldots&<v_n,v_n>\n    \\end{bmatrix} \n  \\end{align}\n\n  \\begin{prop}\n    GGiven an $m\\times n$ matrix $A$. The following are true\n    \\begin{enumerate}\n      \\item The $m\\times n$ matrix $k=A^{T}A$ is positive definite.\n      \\item $A$ has linearly independent columns.\n      \\item $rank (A)=n$\n      \\item $Ker(A)=\\{0\\}$\n    \\end{enumerate}\n  \\end{prop}\n\n  \\begin{theorem}\n    EEvery inner product on $\\R^{n}$ is given by \n    \\begin{equation}\n      <\\vec{x},\\vec{y}> = \\vec{x}^{T}\\cdot c\\vec{y}\n    \\end{equation}\n    where $C$ is a symetric, positive definite $n\\times n$ matrix.\n  \\end{theorem}\n\n  Let $\\vec{v_1},\\ldots,\\vec{v_n}\\in\\R^{n}$. Let $A=[\\vec{v_1}\\vdots \\vec{v_2} \\vdots \\ldots \\vdots \\vec{v_n}]$. Then $K=A^{T}CA$ is the gram matrix with respect to the inner product $\\vec{v}^{T}C\\vec{w}$.\n\n  \\begin{theorem}\n    SSuppose $A$ is an $m\\times n$ matrix with linearly independent collumns. Suppose $C$ is any positive definite $m\\times m$ matrix. Then $\\vec{v}^{T}C\\vec{w}$\n  \\end{theorem}\n\n  \\begin{definition}\n    TThe hilbert matrix $H=(h_{ij})$ where $h_{ij}=\\frac{1}{i+j-1}$\n  \\end{definition}\n\n  The $3\\times 3$ hilbert matrix:\n\n  \\begin{equation}\n    \\begin{bmatrix} \n      \\frac{1}{1}&\\frac{1}{2}&\\frac{1}{3}\\\\\n      \\frac{1}{2}&\\frac{1}{3}&\\frac{1}{4}\\\\\n      \\frac{1}{3}&\\frac{1}{4}&\\frac{1}{5}\n    \\end{bmatrix} \n  \\end{equation}\n\n  \\begin{problem}\n    Make a gram matrix, not in $\\R^{m}$. Let $V=\\mathbb{C}^{0}[0,1]$. Use the $L^{2}$ inner product.\n\n    \\begin{equation}\n      <f,g> = \\int_0^{1}f(x)g(x)dx\n    .\\end{equation}\n\n    $1,x,x^2$ are linearly independent.\n\n    \\begin{align}\n      <v_i,v_k> &= \\int_0^{1}x^{i-1}x^{j-1}dx \\\\\n                &=\\int_0^{1}x^{i+j-2}dx\\\\\n                &=\\frac{1}{i+j-1}x^{i+j-1}\\\\\n                &=\\frac{1}{i+j-1}\\\\\n                \\to \\begin{bmatrix} \n                  \\frac{1}{1}&\\frac{1}{2}&\\frac{1}{3}\\\\\n                  \\frac{1}{2}&\\frac{1}{3}&\\frac{1}{4}\\\\\n                  \\frac{1}{3}&\\frac{1}{4}&\\frac{1}{5}\n                \\end{bmatrix} \n    .\\end{align}\n  \\end{problem}\n\t\\newpage\n", "meta": {"hexsha": "2e7d1655b83776ae04b9d653be7a70293411c83c", "size": 13664, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math363/chapters/3.tex", "max_stars_repo_name": "CameronSWilliamson/GU-MATH", "max_stars_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-18T00:49:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T00:49:14.000Z", "max_issues_repo_path": "math363/chapters/3.tex", "max_issues_repo_name": "therealkeyisme/Math-Notes", "max_issues_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math363/chapters/3.tex", "max_forks_repo_name": "therealkeyisme/Math-Notes", "max_forks_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.7684478372, "max_line_length": 321, "alphanum_fraction": 0.5911885246, "num_tokens": 5761, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7172865060356807}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 5}\n\nIn Figure 3 of Lecture Note 4, where do the costs in the right-hand column come from? Show that they make sense.\nIn particular, show why some of the costs are exact, and are upper bounds (with $\\leq$ signs).\n\n\\subsection*{Solution}\n\nThe costs indicated at each level of the recursion tree are actually run time costs of calling the \\textsc{Partition} method on subarrays.\nAs the \\textsc{Partition} algorithm has a runtime of $\\mathcal{O}(n)$ for an array of length $n$, it is not surprising that no matter how many times with divide the array to subarrays of length larger than 1, the runtime cost at each level would still remain the same.\n\nIn case at each call of \\textsc{Partition} the array is divided into two subarrays of equal length, we can expect that all levels would have a similar constant value.\nHowever, if \\textsc{Partition} doesn't give the pivot value at middle of the array, at some level length of the subarrays that are the smaller parts given by \\textsc{Partition} would reach 1 and \\textsc{Partition} would have no effect, thus no cost.\nThis makes the runtime cost of higher levels in the recursion tree in Figure 3 less than the constant value given in earlier levels.\n", "meta": {"hexsha": "f3a9ce3bbf4ac34d7a5ea75b3edd9d74a3c347d7", "size": 1570, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q05.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q05.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q05.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 74.7619047619, "max_line_length": 268, "alphanum_fraction": 0.7133757962, "num_tokens": 357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303285397348, "lm_q2_score": 0.9073122169746364, "lm_q1q2_score": 0.7172578249730744}}
{"text": "%!TEX root = /Users/stevenmartell/Documents/iSCAM-project/docs/iSCAM-guide/userGuide/usrGuide.tex\n\\section{Statistical functions \\& probability distributions}\n\\begin{multicols}{2}\nMany of the statistical functions commonly used in R have been written as negative log likelihoods and are in the \\texttt{stats.cxx} library.  In this appendix is the documentation for the available functions in the stats.cxx library.  For the most part I have implemented the function based on the description from the R language, so it is possible to use \\texttt{?function} name in R to learn more about the funciton.  Here I provide the formula, the actual code used to implement the function and a description of the variables. Note that some of the functions have been overloaded several times to deal with variables, vectors or a matrix.\n\\end{multicols}\n\n\\paragraph{dbeta} The beta distribution.\n\\[\n\tp(x|a,b) = - \\ln(\\Gamma(a+b))+(\\ln(\\Gamma(a))+\\ln(\\Gamma(b)))-(a-1)\\ln(x)-(b-1)*\\ln(1-x)\n\\]\nthe mean is given by $a/(a+b)$ and the variance is $\\dfrac{ab}{(a+b)^2(a+b+a)}$\n\\begin{verbatim}\n//beta distribution\ndvariable dbeta(const dvariable& x, const double a, const double b)\n{\n\treturn - gammln(a+b)+(gammln(a)+gammln(b))-(a-1.)*log(x)-(b-1.)*log(1.-x);\n}\n\\end{verbatim}\n\n\\paragraph{dgamma} The gamma distribution.\n\\[\n p(x|a,b) = -a \\ln(b)+\\ln(\\Gamma(a))-(a-1)\\ln(x)+bx\n\\]\nwhere the mean and variance are given by $E(x) = a/b$ and $V(x) = a/b^2$.   Note that you can also compute $a$ and $b$ from $E(x)$ and $V(x)$ using the following relationships:\n\\[\n a=\\frac{E(x)^2}{V(x)}, \\quad b=\\frac{E(x)}{V(x)}\n\\]\n\\noindent The following code is implemented in \\texttt{stats.cxx} library:\n\\begin{verbatim}\n//gamma\ndvariable dgamma(const dvariable &x, const double a, const double b)\n{\n\treturn -a*log(b)+gammln(a)-(a-1.)*log(x)+b*x;\n}\n\\end{verbatim}\n\n\n\\paragraph{dnorm} The normal distribution\n\\[\n\tp(x|\\mu,\\sigma) = 0.5\\ln(2\\pi)+\\ln(\\sigma)+0.5\\frac{(x-\\mu)^2}{\\sigma^2}\n\\]\nwhere the mean is $\\mu$ and the variance is $\\sigma^2$.\n\\begin{verbatim}\n//normal distribution\ndvariable dnorm(const dvariable& x, const double& mu, const double& std)\n{\n\tdouble pi=3.141593;\n\treturn 0.5*log(2.*pi)+log(std)+0.5*square(x-mu)/(std*std);\n}\n\\end{verbatim}\n\n\\paragraph{dlnorm} The log normal distribution\n\\[\n\tp(x|\\mu,\\sigma) = 0.5\\ln(2\\pi)+\\ln(\\sigma)+\\ln(x)+0.5\\frac{(\\ln(x)-\\mu)^2}{\\sigma^2}\n\\]\nwhere the log mean is $\\mu$ and the log variance is $\\sigma^2$.\n\\begin{verbatim}\n//log normal distribution\ndvariable dlnorm(const dvariable& x, const double& mu, const double& std)\n{\n\tdouble pi=3.141593;\n\treturn 0.5*log(2.*pi)+log(std)+log(x)+square(log(x)-mu)/(2.*std*std);\n}\n\\end{verbatim}\n\n\n\\section{Scripts}\n\\subsection{Bash script for creating the iscamArchive.zip \\& .tar.gz files}\nThe following is a bash script that is used for archiving the source code files for \\iscam\\ and the scripts for the R code that is hosted on the Goole site.\n\n%\\begin{verbatim}\n\\begin{lstlisting}\n#\n#  bash script for creating the iscam archive\n#\nclear\necho \"Archiving iscam files\"\n\n# script for creating the Tape Archive file\ntar -czvf iscamArchive.$(date +%Y.%m.%d).tgz.gz Examples baranov.cxx\\\n iscam.tpl iscam.dat iscam.r\\\n stats.cxx iSCAMwin.txt Riscam_1.0.tar.gz\n\n# script for creating a windoz zip file\nzip -r iscamArchive.$(date +%Y.%m.%d).zip Examples baranov.cxx\\\n iscam.tpl iscam.dat iscam.r\\\n stats.cxx iSCAMwin.txt Riscam_1.0.tar.gz\n\nexit 0\n\\end{lstlisting}\n%\\end{verbatim}\n\n\\section{R-code for figures and Tables}\n%\\begin{multicols}{2}\n\n%\t\t\\tiny\n%\t\\begin{alltt}\n%\t  \\input{../iscam.R}\\label{HakeDataFile}\n%\t\\end{alltt}\n%\t\\normalsize\n%\\lstset{language=R}\n\nHere is the R-script that is used for reading in report files from ADMB.  Currently this is also compiled as an R-package.\n\\begin{scriptsize}\n\\lstinputlisting[language=R]{../../../src/r-code/read.admb.R}\n\\end{scriptsize}\n%\\end{multicols}\n", "meta": {"hexsha": "d9efd81968855e7a79bad5b72e82ccb496f167ca", "size": 3853, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/iSCAM-guide/userGuide/Stats.tex", "max_stars_repo_name": "krHolt/iSCAM", "max_stars_repo_head_hexsha": "b6e1f1b5c3f81e1860a983cbafd18221d365fdb6", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/iSCAM-guide/userGuide/Stats.tex", "max_issues_repo_name": "krHolt/iSCAM", "max_issues_repo_head_hexsha": "b6e1f1b5c3f81e1860a983cbafd18221d365fdb6", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/iSCAM-guide/userGuide/Stats.tex", "max_forks_repo_name": "krHolt/iSCAM", "max_forks_repo_head_hexsha": "b6e1f1b5c3f81e1860a983cbafd18221d365fdb6", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.6759259259, "max_line_length": 643, "alphanum_fraction": 0.7082792629, "num_tokens": 1227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7172496929955144}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 3.2 Gaussian (Normal) Random Numbers and Vectors\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nGenerate pseudorandom numbers or vectors from the Gaussian (normal)\ndistribution.\n\n\\subsection{Usage}\n\n\\subsubsection{Generating Gaussian (normal) pseudorandom numbers}\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[REAL]  \\ {\\bf SRANG, X}\n\\end{description}\n$$\n\\fbox{{\\bf X = SRANG()}}\n$$\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[SRANG]  \\ [out] The function returns a pseudorandom number from the\nGaussian (normal) distribution with mean zero and unit standard deviation.\n\\end{description}\n\n\\subsubsection{Generating Gaussian (normal) pseudorandom vectors}\n\nGiven an N-vector, ${\\bf \\mu }$, and a symmetric positive-definite N$\\times $%\nN matrix, $A$, the objective is to compute pseudorandom N-vectors, ${\\bf x}$%\n, from the N-dimensional Gaussian (normal) distribution having mean vector, $%\n{\\bf \\mu }$, and covariance matrix, $A$.\n\nOn the first call to SRANGV with a new covariance matrix, $A$, the user must\nset HAVEC = .false. to indicate that the Cholesky factor of $A$ has not yet\nbeen computed. SRANGV will replace $A$ in storage by its Cholesky factor, $C$%\n, and set HAVEC = .true. to indicate that the array A() now contains $C$\nrather than $A$.\n\nOn each call to SRANGV an N-vector, ${\\bf x}$, is returned as a pseudorandom\nsample from the specified distribution.\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf NDIM, N, IERR}\n\n\\item[REAL]  \\ {\\bf A}(NDIM$\\geq $N, $\\geq $N){\\bf , U}($\\geq $N){\\bf , X}($%\n\\geq $N)\n\n\\item[LOGICAL]  \\ {\\bf HAVEC}\n\\end{description}\n\nAssign values to A(,), NDIM, N, U(), and HAVEC.\n\n\\begin{center}\n\\fbox{\\begin{tabular}{@{\\bf }c}\nCALL SRANGV(A, NDIM, N, U,\\\\\nX, HAVEC, IERR)\\\\\n\\end{tabular}}\n\\end{center}\n\nComputed values will be returned in X() and IERR, and the contents of A(,)\nand HAVEC may be changed.\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[A(,)]  \\ [inout] When HAVEC is .false., A(,) contains a user-supplied N%\n$\\times $N symmetric positive-definite covariance matrix, $A$. Only the\ndiagonal and subdiagonal elements of $A$ need be given. This subroutine will\nnot access the super-diagonal locations in the array, A(,). This subroutine\nwill replace $A$ by its lower-triangular Cholesky factor, $C$, and set HAVEC\n= .true.\n\nWhen HAVEC is .true., A(,) is assumed to contain the Cholesky factor, $C$.\n\n\\item[NDIM]  \\ [in] First dimension of the array A(,). Require NDIM $\\geq $\nN.\n\n\\item[N]  \\ [in] Order of the covariance matrix $A$ and dimension of the\nvectors U and X.  Require N $\\geq $ 1.\n\n\\item[U()]  \\ [in] Contains the N-dimensional mean vector, ${\\bf \\mu }.$\n\n\\item[X()]  \\ [out] On return will contain the N-dimensional generated\nrandom vector.\n\n\\item[HAVEC]  \\ [inout] See description above for A(,).\n\n\\item[IERR]  \\ [out] IERR will only be referenced when the subroutine is\nentered with HAVEC = .false. If the Cholesky factorization is successful,\nthe subroutine will set HAVEC = .true. and IERR = 0. Otherwise, it will\nleave HAVEC = .false. and set IERR to the index of the row of $A$ in which\nfailure was noted. In this latter case the results returned in A(,) and X()\nwill not be useful.\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nFor double-precision usage, change the REAL statements to DOUBLE PRECISION\nand change the initial ``S\" of the function and subroutine names to ``D.\"\nNote particularly that if the function name, DRANG, is used it must be typed\nDOUBLE PRECISION either explicitly or via an IMPLICIT statement.\n\n\\subsection{Examples and Remarks}\n\nThe program DRSRANG demonstrates the use of SRANG to compute Gaussian random\nnumbers and uses SSTAT1 and SSTAT2 to compute and print statistics and a\nhistogram based on a sample of~10000 numbers delivered by SRANG.\n\nTo compute Gaussian random numbers with mean XMEAN and standard deviation\nSTDDEV, one can use the statement\n$$\n\\text{X = XMEAN + STDDEV }*\\text{ SRANG()}\n$$\nThe program DRSRANGV demonstrates the use of SRANGV to compute pseudorandom\nvectors from a 3-dimensional Gaussian distribution with mean vector and\ncovariance matrix specified as%\n$$\n{\\bf \\mu } =\\left[\n\\begin{array}{c}\n1 \\\\\n2 \\\\\n3\n\\end{array}\n\\right] \\quad \\text{and}\\quad A=\\left[\n\\begin{array}{rrr}\n0.05 & 0.02 & 0.01 \\\\\n0.02 & 0.07 & -0.03 \\\\\n0.01 & -0.03 & 0.06\n\\end{array}\n\\right] .\n$$\nTo fetch or set the seed used in the underlying pseudorandom integer\nsequence use the subroutines described in Chapter~3.1.\n\n\\subsection{Functional Description}\n\n\\subparagraph{Method}\n\nThe algorithm for generation of Gaussian random numbers is based on\n\\cite{Bell:1968:A334}--\\nocite{Box:1958:NOG}\\cite{vonNeumann:1959:VTU}.\nThis method draws pairs of uniform random numbers $x$ from\n[0,~1] and $y$ from [$-$1,~1] until a pair is obtained that\nsatisfies $x^2 + y^2 \\leq 1$.\nThe probability of satisfying this constraint is $\\pi /4 \\approx 0.785$. It\nthen draws another uniform random number $u$ from [0,~1] and computes\n\\begin{eqnarray*}\ns & = & x^2 + y^2\\\\\nt & = & \\sqrt{-2\\ \\log u} \\,/s\\\\\ng_1 & = & t(x^2 - y^2)\\\\\ng_2 & = & 2xyt\n\\end{eqnarray*}\nThe numbers $g_1$ and $g_2$ are independent samples from the Gaussian\ndistribution with mean zero and unit standard deviation. The number $g_1$ is\nreturned when it is computed and $g_2$ is saved and returned the next time a\nGaussian random number is requested. The saved value will be discarded if\nthe underlying uniform sequence is reinitialized by a call to RAN1 or RANPUT\nof Chapter~3.1.\n\nThis method is a mathematically exact transformation from the uniform\ndistribution to the Gaussian distribution so the statistical quality of the\ndelivered numbers depends entirely on the quality of the uniform\npseudorandom numbers used. The uniform numbers are obtained by calling\nSRANUA or DRANUA, using the array in common block /RANCMS/ or /RANCMD/ as a\nbuffer as described in Chapter~3.1.\n\nFor the generation of Gaussian random vectors we are given a mean vector $%\n{\\bf \\mu }$ and a symmetric positive-definite covariance matrix $A$. The\nCholesky method is used to factor the given covariance matrix $A$ as $A =\nCC^t$ where $C$ is a lower triangular matrix. Then for each vector to be\ndelivered the method first constructs a vector ${\\bf g}$ whose components\nare independent samples from the Gaussian distribution with mean zero and\nunit standard deviation. It then computes\n$$\n{\\bf x} = {\\bf \\mu }+C{\\bf g}\n$$\nwhich is a sample from the N-dimensional Gaussian distribution with mean $%\n{\\bf \\mu }$ and covariance matrix $A$.\n\nValues returned as double-precision random numbers will have random bits\nthroughout the word, however the quality of randomness should not be\nexpected to be as good in a low-order segment of the word as in a high-order\npart.\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nWhile computing the Cholesky factorization of $A$, subroutine SRANGV or\nDRANGV may determine that the matrix is not positive-definite. In that case\nit will return with IERR set to the index of the row of the matrix at which\nthe problem was detected. In this non-positive-definite case the contents of\nthe array A(,) will have been altered, HAVEC will still have the value\n.false., and X() will not contain useful results.\n\nWhen the Cholesky factorization is successful, IERR will be set to zero.\n\nThe conditions that N $\\geq $ 1, and NDIM $\\geq $ N are required but\nnot checked.\n\n\\subsection{Supporting Information}\n\nThe source language is ANSI Fortran~77.\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt} \\\\\nDRANG & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDRANG, ERFIN, ERMSG, RANPK1, RANPK2\\rule[-5pt]{0pt}{8pt}}\\\\\nDRANGV & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDRANG, DRANGV, ERFIN, ERMSG, RANPK1, RANPK2\\rule[-5pt]{0pt}{8pt}}\\\\\nSRANG & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, RANPK1, RANPK2, SRANG\\rule[-5pt]{0pt}{8pt}}\\\\\nSRANGV & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, RANPK1, RANPK2, SRANG, SRANGV}\\\\\\end{tabular}\n\nBased on subprograms written for JPL by Carl Pitts, Heliodyne Corp., April,\n1969. Adapted to Fortran~77 for the JPL MATH77 library by C. L. Lawson and\nS. Y. Chiu, JPL, April~1987. November~1991: Lawson reorganized and renamed\ncommon blocks. Improved coordination between Gaussian and uniform sequences\non reinitializations.\n\n\n\\begcodenp\n\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSRANG}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{srang}}\n\\newpage\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSRANG}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{srang}}\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\\newpage\n\n\\centerline{\\bf \\large DRSRANGV}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{srangv}}\n\\newpage\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSRANGV}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{srangv}}\n\\end{document}\n", "meta": {"hexsha": "c5363c94bf50e7611d91c168e6a86fe8d9798be3", "size": 9305, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch03-02.tex", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "doc/doctex/ch03-02.tex", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "doc/doctex/ch03-02.tex", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 36.34765625, "max_line_length": 98, "alphanum_fraction": 0.7429339065, "num_tokens": 2775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388040954684, "lm_q2_score": 0.8652240912652671, "lm_q1q2_score": 0.7172178234880189}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{numprint}\n\n\\author{Daniel Fernandes Martins (danielfmt)}\n\\title{Question \\#4 Solution}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Partial Derivative of $E(u,v)$}\n\nIn this exercise, we are asked to compute the partial derivative\n$\\frac{\\partial E}{\\partial u}$ of an error function that defines a\nhypothetical error surface.\n\n\\begin{equation*}\n\\frac{\\partial}{\\partial u} E(u,v) = (ue^v -2ve^{-u})^2\n\\end{equation*}\n\nLet's define the partial derivative of each term, step-by-step. First, we apply\nthe \\textit{power rule}, which says $\\frac{\\partial}{\\partial x} x^n = n \\cdot x^{n-1}$:\n\n\\begin{equation*}\n\\frac{\\partial}{\\partial u} E(u,v) = 2(ue^v -2ve^{-u})^1 \\\\ \n\\frac{\\partial}{\\partial u} (ue^v -2ve^{-u})\n\\end{equation*}\n\nNotice that we also applied the \\textit{chain rule} to the squared term since\nit contain terms of $u$.\n\nNow, the term $ue^v$, which is $u$ multiplied by a constant, is really simple\nto differentiate:\n\n\\begin{equation*}\n\\frac{\\partial}{\\partial u} (ue^v) = 1 \\cdot e^v = e^v\n\\end{equation*}\n\nFinally, to differentiate a term that looks like $e^u$ we just need to multiply\nit by the derivative of $u$, which is 1 or -1 depending on the sign:\n\n\\begin{equation*}\n\\frac{\\partial}{\\partial u} (-2ve^{-u}) = -2ve^{-u} \\cdot -1 = 2ve^{-u}\n\\end{equation*}\n\nPutting everything together, we have the solution:\n\n\\begin{equation*}\n\\frac{\\partial}{\\partial u} E(u, v) = \\\\\n2(ue^v -2ve^{-u})(e^v + 2ve^{-u})\n\\end{equation*}\n\n\\end{document}\n", "meta": {"hexsha": "06645a6fed9b74d4f9d32f589fb40b6d86c9b42c", "size": 1507, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework_5/Octave/by_danielfmt/week-05/math/q04.tex", "max_stars_repo_name": "freeernest/edX-Learning-From-Data-Solutions", "max_stars_repo_head_hexsha": "5cbcf0885b5fdb00c3658d230fc7bb7e20b5cf44", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 98, "max_stars_repo_stars_event_min_datetime": "2015-04-27T06:55:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:09:19.000Z", "max_issues_repo_path": "Homework_5/Octave/by_danielfmt/week-05/math/q04.tex", "max_issues_repo_name": "freeernest/edX-Learning-From-Data-Solutions", "max_issues_repo_head_hexsha": "5cbcf0885b5fdb00c3658d230fc7bb7e20b5cf44", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-05-14T19:33:33.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-12T13:07:41.000Z", "max_forks_repo_path": "Homework_5/Octave/by_danielfmt/week-05/math/q04.tex", "max_forks_repo_name": "freeernest/edX-Learning-From-Data-Solutions", "max_forks_repo_head_hexsha": "5cbcf0885b5fdb00c3658d230fc7bb7e20b5cf44", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 56, "max_forks_repo_forks_event_min_datetime": "2015-01-10T08:18:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-28T08:46:22.000Z", "avg_line_length": 26.9107142857, "max_line_length": 88, "alphanum_fraction": 0.6854678169, "num_tokens": 504, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.8289388146603364, "lm_q1q2_score": 0.7172178196653861}}
{"text": "\\section{Adaptive AR Model Based Time-Frequency Estimation}\n\\subsection{AR modelling of FM signal}\n\\begin{figure}[htb]\n\t\\centering\n    \\includegraphics[width=0.36\\textwidth]{fig/32/32a1.eps}\n    \\caption{Time-variant frequency of FM signal}\n    \\label{fig:3_2_a1}\n\\end{figure}\n\\noindent\nA FM signal with time-variant frequency as shown in Fig.\\ref{fig:3_2_a1} is modulated with adding white noise in distribution of $\\mathcal N\\in$ (0, 0.05). The frequency is composed of three segments with constant, linear and quadratic parts, resulting in the non-stationary FM signal.\n\\begin{figure}[htb]\n     \\centering\n     \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/32/32a2.eps}\n     \\end{subfigure}\n    \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/32/32a3.eps}\n     \\end{subfigure}\n    \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/32/32a4.eps}\n     \\end{subfigure}\n    \\caption{Whole FM AR estimation with order=1, 10 and 15}\n    \\label{fig:3_2_a2}\n\\end{figure}\\\\\nWhen using the MATLAB function \\texttt{aryule} to estimate the coefficient for entire signal, Fig.\\ref{fig:3_2_a2} depicts the performance of estimations with different orders. For AR(1) modelling, the estimated peak of frequency is inaccurate since the function is incapable to estimate non-stationary signal. With increasing the order of estimated model, only the constant frequency at $100Hz$ is successfully estimated. However, other segments frequencies are still not captured accurately. Thus, the previous method in Part 2.2 is not applicable for FM signal.\n\\begin{figure}[htb]\n     \\centering\n     \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.32\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/32/32a5.eps}\n     \\end{subfigure}\n    \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.32\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/32/32a6.eps}\n     \\end{subfigure}\n    \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.32\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/32/32a7.eps}\n     \\end{subfigure}\n     \\\\\n     \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.32\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/32/32a8.eps}\n     \\end{subfigure}\n    \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.32\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/32/32a9.eps}\n     \\end{subfigure}\n    \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.32\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/32/32a10.eps}\n     \\end{subfigure}\n        \\caption{Block-based AR estimation with order=1 and 15}\n        \\label{fig:3_2_a3}\n\\end{figure}\\\\\nIn addition, the frequency is time-varying function with constant, linear and quadratic segments. Thus, the block-based estimation is implemented with segments length $N=500$ samples. Fig.\\ref{fig:3_2_a3} illustrates the performance of estimated AR model with order 1 and 15. The constant frequency part can be successfully estimated with $p=1$ presented in a peak value at $100Hz$. However, the linear and quadratic segments perform inferior with inaccurate frequencies. By increasing the capacity of estimated model, the frequency range of segment can be approximately estimated with acceptable uncertainty, as shown in second row of Fig.\\ref{fig:3_2_a3}. Nevertheless, the linear and quadratic relationship can not be observed based on the estimation since they are not satisfied with stationary.\n\\subsection{CLMS based estimated AR coefficient}\nIn this section, the CLMS algorithm is applied to estimate non-stationary signal. Fig.\\ref{fig:3_2_b} shows the performance of estimating AR(1) coefficients with varying step-size $\\mu$. It is obviously that the CLMS can adaptively capture the time-variant frequencies. However, the different step-size $\\mu$ also affects the performance of the CLMS estimation. With small step-size, the learning curve can not converge, leading to inadequate estimation. The performance at $\\mu=0.01$ is improved in spite of lacking beginning parts of the constant frequency. Setting $\\mu=0.05$ introduces an optimal estimation, while larger step causes oscillation in convergence. As a consequence, there are large variance and distortions of spectrum.\n\\begin{figure}[htb]\n     \\centering\n     \\hspace{0.4cm}\n     \\begin{subfigure}[b]{0.35\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/32/32b1.eps}\n     \\end{subfigure}\n    \\hspace{0.4cm}\n     \\begin{subfigure}[b]{0.35\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/32/32b2.eps}\n     \\end{subfigure}\n    \\\\\n    \\hspace{0.4cm}\n     \\begin{subfigure}[b]{0.35\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/32/32b3.eps}\n     \\end{subfigure}\n     \\hspace{0.4cm}\n     \\begin{subfigure}[b]{0.35\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/32/32b4.eps}\n     \\end{subfigure}\n        \\caption{CLMS-based AR estimation with different step $\\mu$}\n        \\label{fig:3_2_b}\n\\end{figure}\n", "meta": {"hexsha": "d5b2d8b64d81f82a8d7f2bba48e748a54e040dca", "size": 5295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/sections/Part3/32.tex", "max_stars_repo_name": "zdhank/Adaptive-Signal-Processing", "max_stars_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-05T10:27:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-19T08:55:10.000Z", "max_issues_repo_path": "Report/sections/Part3/32.tex", "max_issues_repo_name": "zdhank/Adaptive-Signal-Processing", "max_issues_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/sections/Part3/32.tex", "max_forks_repo_name": "zdhank/Adaptive-Signal-Processing", "max_forks_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.587628866, "max_line_length": 799, "alphanum_fraction": 0.7084041549, "num_tokens": 1502, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.7172178157319765}}
{"text": "\n\\section{Neighbourhoods}\n\n\\subsection{Neighbourhood topology}\n\nWe have a set \\(X\\).\n\nFor each element \\(x\\in X\\), there is a non-empty set of neighbourhoods \\(N\\in \\mathbf N(x)\\) where \\(x\\in N\\subseteq X\\) such that:\n\n\\begin{itemize}\n\\item If \\(N\\) is a subset of \\(M\\), \\(M\\) is a neighbourhood.\n\\item The intersection of two neighbourhoods of \\(x\\) is a neighbourhood of \\(x\\).\n\\item \\(N\\) is a neighbourhood for each point in some \\(M\\subseteq N\\)\n\\end{itemize}\n\n\n\n", "meta": {"hexsha": "e807f46632dc8d7545c2b3d5056655425d231ac7", "size": 470, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/topologyFinite/01-02-neighbourhood.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/topologyFinite/01-02-neighbourhood.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/topologyFinite/01-02-neighbourhood.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.1111111111, "max_line_length": 132, "alphanum_fraction": 0.6808510638, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.7171314097877}}
{"text": "\\chapter{AutoDiff}\r\n\\section{Introduction}\r\nSuppose $\\mathcal F:\\mathbb U \\mapsto \\mathbb V$, (usually $\\mathbb U = \\mathbb R^n$ and $\\mathbb V\\in\\mathbb R^m$) and the tangent space of a point $u\\in\\mathbb U$ with $v=\\mathcal F(u) \\in \\mathbb V$ is $T_u\\mathbb U$ and $T_v\\mathbb V$. The dual of  $T_u\\mathbb U$ and $T_v\\mathbb V$ is  $(T_u\\mathbb U)'$ and $(T_v\\mathbb V)'$. Then for any $u\\in\\mathbb U$, $\\mathcal{F}'(u)=\\nabla \\mathcal{F}(u)$ is the linear operator from $T_u\\mathbb U$ to $T_v\\mathbb V$ and $(\\nabla \\mathcal{F}(u))^T$ is the linear from $(T_v\\mathbb V)'$ to $(T_u\\mathbb U)'$.\r\n\r\n For any $u_0\\in \\mathbb U$, $v_0=\\mathcal{F}(u_0)\\in\\mathbb V$, and assume the coat of time to calculate each entry of $\\mathcal F$ or $\\mathcal{F}'$ can be bounded by a constant, and let $F_{time}$ is the cost of calculating $\\mathcal F$.\r\n\\begin{itemize}\r\n\t\\item  Suppose $u$ is depend on a variable $s$. If we have already known $x^1=\\dfrac{\\partial u}{\\partial s}(u_0)\\in T_{u_0}\\mathbb U$, the forward autodiff algorithm is to calculate\r\n\t\\begin{equation}\r\n\t\\dfrac{\\partial v}{\\partial s}(u_0)=\t\\dfrac{\\partial \\mathcal F}{\\partial s}(u_0)=\\nabla \\mathcal F(u_0) \\dfrac{\\partial u}{\\partial s}(u_0)=\\nabla \\mathcal F(u_0) x^1\r\n\t\\end{equation}\r\n\tand the cost of time is $O(F_{time})$\r\n \t\\item  Suppose $t$ is a variable depend on $v$. If we have already known $y_1=(\\dfrac{\\partial t}{\\partial v}(v_0))^T\\in (T_{v_0}\\mathbf V)'$ the backward autodiff algorithm is to calculate\r\n \t\\begin{equation}\r\n \t(\\dfrac{\\partial t}{\\partial u}(u_0))^T=(\\dfrac{\\partial v}{\\partial u}(u_0))^T(\\dfrac{\\partial t}{\\partial v}(v_0))^T=(\\nabla \\mathcal{F}(u_0))^T y_1\r\n \t\\end{equation}\r\n \tand the cost of time is $O(F_{time})$\r\n\\end{itemize}\r\n\r\nIf we want to calculate $\\nabla F$ by autodiff, we can set $x^1=e^1,...,e^n$ or set $y_1=e_1,...,e_m$, where $e^i$ is the $i$th column of $I_n$ and $e_i$ is the $i$th column of $I_m$. This means the cost of forward algorithm is $O(nF_{time})$ and the cost of backward algorithm is $O(mF_{time})$.\r\n\r\nNow we have a series of $\\mathcal F_j:\\mathbb R^{n_j-1}\\mapsto\\mathbb R^{n_j}$, and $t=\\mathcal{F}_J\\circ\\cdots\\circ \\mathcal{F}_1(s)$, if we use forward algorithm for all functional composition, the cost is $O(n_0(n_1+\\cdots+n_J)F_{time})$, if we use backward  algorithm for all functional composition, the cost is $O(n_J(n_{J-1}+\\cdots+n_0)F_{time})$. For deep learning problem, the $n_0$ is very large but $n_0=1$, so backward algorithm is much better.", "meta": {"hexsha": "959c28f2eb62cd432059d550c59bc5a407df7fd8", "size": 2489, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/AutoDiff.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/AutoDiff.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/AutoDiff.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 118.5238095238, "max_line_length": 554, "alphanum_fraction": 0.6777822419, "num_tokens": 938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7169441087352355}}
{"text": "\\section{Markov decision processes}\n\n\\subsection{Introduction}\n\nAn MDP is defined by:\n\\begin{itemize}\n    \\item A set of states $s \\in S$\n    \\item A set of actions $a \\in A$\n    \\item A transition function $T(s, a, a')$ - the model - that represents the probability that $a$ leads to $s'$ fro $s$\n    \\item A reward function $R(s, a, s')$\n    \\item (Optional) A terminal state\n\\end{itemize}\n\nThe action outcome depends only on the current state, but not on the history of actions\n\n\\subsection{Policies}\n\nA policy is a function that $P: S \\mapsto A$, that gives an action for each state. An optimal policy $p^*$ maximizes the expected utility if followed.\n\n\\subsection{Discounting rewards}\n\nSolution to avoid infinite rewards:\n\\begin{itemize}\n    \\item Finite horizon: (similar to depth-limited search)\n    \\begin{itemize}\n        \\item Terminate episodes after a fixed T steps (e.g. life)\n        \\item Gives non-stationary policies ($p$ depends on time left)\n    \\end{itemize}\n    \\item Discounting: smaller $\\gamma$ means smaller “horizon” – shorter term focus\n    \\begin{math}\n    U(\\overline{r}) = \\sum_{t=0}^{\\infty}{\\gamma^t r_t} \\leq \\frac{R_{max}}{1-\\gamma}\n    \\end{math}\n    \\item Absorbing state: guarantee that for every policy, a terminal state will eventually be reached\n\\end{itemize}\n\n\\subsection{Solving MDPs}\n\nGiven:\n\\begin{itemize}\n    \\item $V^*(s)$  the expected utility starting in $s$ and acting optimally\n    \\item $Q^*(s, a)$ - q-state - the expected utility starting out having taken action $a$ from state $s$ and thereafter acting optimally\n    \\item $\\pi^*(s)$ the optimal action from state $s$\n    \\item $V_k(s)$ the expected utility starting in $s$ and acting optimally if the game ends in $k$ more time steps\n\\end{itemize}\n\n\\subsubsection{Value iteration}\n\nGiven the Bellman equation:\n\\begin{equation}\n    V^*(s) = \\underset{a}{max}(R(s,a, s') + \\gamma V_k(s'))\n\\end{equation}\n\n\n\\paragraph{Algorithm} Repeat until convergence:\n\\begin{itemize}\n    \\item Start with $V_0(s) = 0$: no time steps left means an expected reward sum of zero\n    \\item Given vector of $V_k(s)$ values, do one ply of expectimax from each state:\n    \\begin{math}\n    V_{k+1}(s) = \\underset{a}{max}{R(s,a, s') + \\gamma V_K(s')}\n    \\end{math}\n\\end{itemize}\n\n\\paragraph{Properties}\n\\begin{itemize}\n    \\item Complexity of each iteration: $O(S^2A)$\n    \\item Theorem: will converge to unique optimal values\n    \\item Basic idea: approximations get refined towards optimal values\n    \\item Policy may converge long before values do\n\\end{itemize}\n\n\\subsection{Policy extraction}\n\n\\begin{equation}\n    \\pi^*(s) = \\underset{a}{arg max}\\sum_{s'}{T(s,a,a')[R(s,a, s') + \\gamma V_k(s')]}\n\\end{equation}\n\n\\subsection{Policy iteration}\n\n\\paragraph{Algorithm} Repeat steps until policy converges:\n\\begin{itemize}\n    \\item Policy evaluation: calculate utilities for some fixed policy (not optimal utilities!) until convergence\n    \\begin{math}\n    V^{\\pi_i}_{k+1}(s) \\leftarrow \\sum_{s'}{T(s,a,a')[R(s,\\pi_i(s)=a, s') + \\gamma V^{\\pi_i}_K(s')]}\n    \\end{math}\n    If the state space is finite, the utilities can also be computed by solving a set of linear equations.\n    \\item Policy improvement: update policy using one-step look-ahead with resulting converged (but not optimal!) utilities as future values\n    \\begin{math}\n    \\pi^*_{i+1}(s) = \\underset{a}{argmax}\\sum_{s'}{T(s,a,a')[R(s,a, s') + \\gamma V_k^{\\pi_i}(s')]}\n    \\end{math}\n\\end{itemize}", "meta": {"hexsha": "a0f263934b255c75b90a3f5cb7e7e7d0253b11e7", "size": 3443, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/mdp.tex", "max_stars_repo_name": "Calcifer777/columbia-ai", "max_stars_repo_head_hexsha": "aaa7173bca6f2bc9edfe6fe55b5a1a37ab310066", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/mdp.tex", "max_issues_repo_name": "Calcifer777/columbia-ai", "max_issues_repo_head_hexsha": "aaa7173bca6f2bc9edfe6fe55b5a1a37ab310066", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/mdp.tex", "max_forks_repo_name": "Calcifer777/columbia-ai", "max_forks_repo_head_hexsha": "aaa7173bca6f2bc9edfe6fe55b5a1a37ab310066", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2555555556, "max_line_length": 150, "alphanum_fraction": 0.688062736, "num_tokens": 1019, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7169209500474215}}
{"text": "\\chapter{Group Theory}\n\nA group is a set of elements that can move between themselves. That movement is denoted by the multiplication of elements. We call the entire group itself $G$, which contains $g_1, g_2, ... g_N$ elements ($N$ is the order of $G$). The group is defined in the following way\n\\begin{enumerate}\n\t\\item $g_1g_2~\\exists ~G$ for all $g_1, g_2~\\exists~ G$. Which says when we multiply two elements, we get another element that is still within the group back\n\t\\item $(g_1g_2)g_3 = g_1(g_2g_3)$ for $g_1, g_2, g_3~\\exists~ G$. Which says when given a specific order to multiply the elements, the sequencing of multiplication doesn't matter\n\t\\item There is an identity element $e$ which gives $eg = ge = g$ for all $g\\exists G$. This says there is one element that does not change any of the other elements.\n\t\\item For every element $g$, there is an inverse $g^{-1}$ such that $gg^{-1} = e$. Which allows us, from any element, to return to the identity\n\\end{enumerate}\nThe order of any of these elements $g$ are given by the smallest integer $k$ such that $g^k = e$.\nAn isomorphism between two groups technically is a bijective map that preserves the group operations. This means that any of the operations from one group can be mapped exactly on to those of another.\n\n\\subsection{Quaternion Group}\nThe Quaternion Group $Q_8$ is defined such that\n\\begin{align}\n\ti^2 = j^2 = k^2 = ijk = -1\n\\end{align}\n\n%\n%TODO:\n%\\begin{itemize}\n%\t\\item SO(3) can have matrices that represent it of arbitrary size?\n%\t\\item Put example of what a matrix tensor product looks like (from comp notes)\n%\t\\item Irreducible representation\n%\\end{itemize}\n%\n%\n\\subsection{Lie Groups}\nOf particular importance in physics are \\textbf{Lie groups}, groups in which you can change infinitesimally between their elements. This allows you to Taylor expand ... TODO\n\n\\subsection{SO(3)}\nConsider the addition of angular momentum of two spin $1/2$ particles, $a$ and $b$ the Hilbert space in which they live both have dimension\n\\begin{align}\nd_i = (2j_i + 1)\n\\end{align}\nwhere $i ~\\exists~(a,b)$. So $d_i = 2$ in the case of spin 1/2 particles ($\\uparrow$ and $\\downarrow$). The dimension of their combination is the product of both dimensions\n\\begin{align}\nd_{ab} = (2j_a+1)(2j_b+1)\n\\end{align}\ngiving us 4. Considering each particle individually, we have a set of operators that \"represent\" the legal group operations that are allowed to make on the ket that would match with another potential bra. Following the same notation we look for the tensor product of the two representations\n\\begin{align}\nD^{(j_a)}\\otimes D^{(j_b)}\n\\end{align}\n\nIt can be shown \\cite{sakurai} that when you combine any two particles with angular momentum $j, j'$ you can describe any transformation on the system as a whole in terms of a sum of irreducible representations.\n\n\\begin{align}\nD^{(j)}\\otimes D^{(j')} = \\bigoplus^{j+j'}_{l=|j-j'|} D^{(l)}\n\\end{align}\n\nGroups themselves are abstract entities defined by just the rules to get between elements. In physics, we use a \\textbf{representation} of a group, which is the group put into matrix form such that it obeys the same rules as its definition.\n\\begin{gather}\n\\begin{align}\n\\textrm{Group} && \\textrm{Representation}\\\\\ng_1g_2 = g_3 && D(g_1)D(g_2) = D(g_3)\n\\end{align}\n\\end{gather}\nWhere $D(g_1)$ is a matrix representation of the group element $g_1$ etc. \n", "meta": {"hexsha": "eb1bbb8971ec81500e8b9a43d011a1a1947cf89e", "size": 3370, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mathematics/groupTheory.tex", "max_stars_repo_name": "williamnash/notes", "max_stars_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mathematics/groupTheory.tex", "max_issues_repo_name": "williamnash/notes", "max_issues_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-08-23T23:01:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-16T23:17:43.000Z", "max_forks_repo_path": "mathematics/groupTheory.tex", "max_forks_repo_name": "williamnash/notes", "max_forks_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.1186440678, "max_line_length": 290, "alphanum_fraction": 0.740652819, "num_tokens": 960, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995028, "lm_q2_score": 0.8080672135527631, "lm_q1q2_score": 0.7169209463061702}}
{"text": "\\section{Higher Order Linear ODEs}\r\n\\subsection{Second Order Linear ODEs with Constant Coefficients}\r\n\\begin{definition}\r\n    A second order linear ODE with constant coefficient is an ODE of the form\r\n    $$a\\frac{\\mathrm d^2y}{\\mathrm dx^2}+b\\frac{\\mathrm dy}{\\mathrm dx}+cy=f(x)$$\r\n    where $a,b,c$ are constants with $a\\neq 0$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A linear differential operator $\\mathscr{D}$ is a linear combination of (different orders of) differentiation operators.\r\n\\end{definition}\r\nWe know that the (arbitrary order) differentiation operator is linear, hence any linear differential operator is linear, which gives rise to the principle of superposition.\r\n\\begin{proposition}\r\n    If $y_\\alpha, y_\\beta$ are solutions to $ay^{\\prime\\prime}+by^\\prime+cy=f$, then $y_{\\alpha}-y_\\beta$ is a solution to $ay^{\\prime\\prime}+by^\\prime+cy=0$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Consider the linear operator\r\n    $$\\mathscr{D}=a\\frac{\\mathrm d^2}{\\mathrm dx^2}+b\\frac{\\mathrm d}{\\mathrm dx}+c$$\r\n    then $\\mathscr{D}(y_\\alpha-y_\\beta)=\\mathscr{D}(y_\\alpha)-\\mathscr{D}(y_\\beta)=f(x)-f(x)=0$.\r\n\\end{proof}\r\nWe can extend the above proposition to any order of linear ODEs with constant coefficient in the obvious way.\\\\\r\nSo we can solve these solutions in the following steps, assuming $\\mathscr{D}$ is defined as in the above proof:\\\\\r\nFirst, we find complementary (linearly independent, defined below) solutions $y_1,y_2$ to $\\mathscr{D}(y)=0$.\\\\\r\nThen we find a particular solution $y_p$ to $\\mathscr{D}(y)=f(x)$.\\\\\r\nThe general form of the solutions to $\\mathscr{D}(y)=f(x)$ is $y_p+Ay_1+By_2$ where $A,B$ are constants.\r\n\\begin{definition}\r\n    A set of functions $(f_i)_{i\\in I}$ are linearly dependent if $\\sum_ic_if_i(x)=0$ for some constants $c_i$ that are not all zero.\r\n    The sum here is taken over some finite set of indices.\\\\\r\n    Otherwise, they are linearly independent.\r\n\\end{definition}\r\nEquivalently, if a function in the set of functions can be written as a linear combination of others, then the set is linearly dependent.\\\\\r\nConsider a second-order linear differential operator.\r\nWe know that the a first order one has eigenfunction to be the exponential function.\r\nNote that it is also the eigenfunction of a second-order one.\r\nIn fact, the exponential is the eigenfunction of any linear differential operator.\r\nConsider the homogeneous equation $\\mathscr{D}y=0$ where\r\n$$\\mathscr{D}=a\\frac{\\mathrm d^2}{\\mathrm dx^2}+b\\frac{\\mathrm d}{\\mathrm dx}+c$$\r\nPlug in $y=e^{\\lambda x}$ we have $a\\lambda^2+b\\lambda+c=0$ which we call \\textit{characteristic equation} or \\textit{auxiliary equation}.\r\nFrom FTA, we have at least $1$ (complex) solutions.\r\nLet $\\lambda_1,\\lambda_2$ be two solutions, then\\\\\r\nCase 1: $\\lambda_1\\neq\\lambda_2$.\\\\\r\nThen $y_1=Ae^{\\lambda_1x}$, $y_2=Be^{\\lambda_2x}$ are both solutions for each $A,B$ constants.\r\nIt is easy to see that these two are linearly independent for $AB\\neq 0$.\r\nWe can show that they form a basis for solution space,\r\n\\footnote{This will be discussed later.}\r\nand any other solutions must be of the form $Ae^{\\lambda_1x}+Be^{\\lambda_2x}$ for $A,B$ constants.\\\\\r\nCase 2: $\\lambda_1=\\lambda_2$.\\\\\r\nIn this case, $y_1,y_2$ cannot span the solution space, but there is some workaround.\r\n\\begin{example}\r\n    $y^{\\prime\\prime}-4y^\\prime+4y=0$, then $(y^\\prime-2y)^\\prime-2(y^\\prime-2y)=0$ can give the solution.\\\\\r\n    Or we can consider the slightly modifies equation $y^{\\prime\\prime}-4y^\\prime+(4-\\epsilon^2)y=0$ for some small enough $\\epsilon$.\r\n    This modified equation has the general solution $y_\\epsilon=Ae^{\\lambda_1x}+Be^{\\lambda_2x}$ where $\\lambda_{1,2}=2\\pm\\epsilon$, so\r\n    $$y_\\epsilon=e^{2x}(Ae^{\\epsilon x}+Be^{-\\epsilon x})=e^{2x}((A+B)+\\epsilon x(A-B)+O(\\epsilon^2))\\to Cxe^{2x}+De^{2x}$$\r\n    for some constants $C,D$ by clever (or not) choices of $A,B$.\r\n    This gives a pair of linearly independent solutions.\r\n\\end{example}\r\n\\subsection{Second Order Linear ODEs with Non-constant Coefficients}\r\nAgain we are interested in the homogeneous ones due to the superposition principle.\r\nConsider the equations in the form\r\n$$y^{\\prime\\prime}+p(x)y^\\prime+q(x)y=0$$\r\nWe shall use the method of reduction of order.\r\nGiven one solution $y_1$ to the equation, we shall find a second solution by looking for solutions of the form $y_2=vy_1$.\\\\\r\nFirst, note that $y_2^\\prime=v^\\prime y_1+vy_1^\\prime,y_2^{\\prime\\prime}=v^{\\prime\\prime}y_1+2v^\\prime y_1^\\prime +vy^{\\prime\\prime}$, so plugging it in we have\r\n$$v^\\prime(2y_1^\\prime+py_1)+v^{\\prime\\prime}y_1=0$$\r\nSo it is a seperable first order equation in $v^\\prime$ which we know how to solve, plugging it back gives the solution.\r\n\\subsection{Phase Space}\r\nConsider the ODE $p_i(x)y^{(i)}=f(x)$ where the summation convention is used and $i$ is summed over $0,1,\\ldots,n$.\r\nSo we can write $y^{(n)}$ as a combination of $y^{(i)}$ for $i\\in\\{0,1,2,\\ldots,n-1\\}$ and $f$ and $p_i$'s.\r\n\\begin{example}\r\n    The damped oscillator has the DE\r\n    $$m\\ddot{y}=-ky-L\\dot{y}$$\r\n    The state of the system can be described by an $n$-dimensional solution vector\r\n    $$\\underline{y}=\r\n    \\begin{pmatrix}\r\n        y\\\\\r\n        y^\\prime\\\\\r\n        \\vdots\\\\\r\n        y^{(n-1)}\r\n    \\end{pmatrix}$$\r\n    Going back to an undampted oscillator $y^{\\prime\\prime}+4y=0$ which has the general solution spanned by $y_1(x)=\\cos{2x}, y_2(x)=\\sin{2x}$, so the solution vectors are\r\n    $$\\underline{y_1}=\r\n    \\begin{pmatrix}\r\n        \\cos{2x}\\\\\r\n        -2\\sin{2x}\r\n    \\end{pmatrix},\r\n    \\underline{y_2}=\r\n    \\begin{pmatrix}\r\n        \\sin{2x}\\\\\r\n        2\\cos{2x}\r\n    \\end{pmatrix}$$\r\n    Thus we can do 2D phase portrait of the solutions to observe the two vectors, where we can find that the trajectories coincide.\r\n    Since $y_1,y_2$ are linearly independent, any point in phase space can be obtained from a linear combination of them.\r\n    In general, $y_1,y_2,\\ldots, y_n$ are linearly independent if their solution vectors are linearly independent in the phase space.\r\n\\end{example}\r\n$n$ linearly independent solution vectors form a basis for the phase space of an $n^{th}$ order ODE.\r\nConsider the initial conditions for a second order homogeneous ODE $y(0)=a,y^\\prime(0)=b$.\r\nIf the general solution is formed by the linear combination of linearly independent functions $y_1,y_2$, then in order to find a solution that complies with the initial condition, we will be solving the linear system in $A,B$.\r\n$$\r\n\\begin{cases}\r\n    Ay_1(0)+By_2(0)=a\\\\\r\n    Ay_1^\\prime(0)+By_2^\\prime(0)=b\\\\\r\n\\end{cases}\r\n$$\r\nSo we obtain unique solutions if and only if\r\n$$y_1(0)y_2^\\prime(0)\\neq y_2(0)y_1^\\prime(0)$$\r\nwhich is true if $\\underline{y_1}(0),\\underline{y_2}(0)$ are linearly independent.\r\n\\begin{definition}\r\n    The Wronskian $W(x)$ is defined as\r\n    $$W(x)=\r\n    \\begin{vmatrix}\r\n        y_1&y_2&\\dots&y_n\\\\\r\n        y_1^\\prime&y_2^\\prime&\\dots&y_n^\\prime\\\\\r\n        \\vdots&\\vdots&\\ddots&\\vdots\\\\\r\n        y_1^{(n-1)}&y_2^{(n-1)}&\\dots&y_n^{(n-1)}\r\n    \\end{vmatrix}\r\n    $$\r\n\\end{definition}\r\nSo the solutions are linearly independent if $W(x)\\neq 0$.\r\nBut does $W(x)=0$ necessarily imply linear dependence?\r\n\\begin{theorem}[Abel's Theorem]\r\n    Consider a second order linear ODE $y^{\\prime\\prime}+py^\\prime+qy=0$.\r\n    If $p(x),q(x)$ are continuous on an interval $I$, then either $\\forall x\\in I, W(x)\\neq 0$ or $\\forall x\\in I, W(x)=0$\r\n\\end{theorem}\r\n\\begin{proof}[Sketch of proof]\r\n    Let $y_1,y_2$ be solutions to the ODE, and $\\mathscr D$ be the differential operator in the left hand side of the equation, so\r\n    $$y_2\\mathscr{D}(y_1)=y_1\\mathscr{D}(y_2)=0\\implies y_2y_1^{\\prime\\prime}-y_1y_2^{\\prime\\prime}+(y_2y_1^\\prime-y_1y_2^\\prime)p\\implies W^\\prime+pW=0$$\r\n    So we could integrate it back from $x_0$ to $x$ to get\r\n    $$W(x)=W(x_0)\\exp\\left(-\\int_{x_0}^xp(u)\\,\\mathrm du\\right)$$\r\n    which is called the Abel identity.\r\n    Since $p$ is continuous on a closed interval, it is bounded and integrable, therefore the exponential function part is always defined and nonzero, so $W(x_0)=0$ if and only if $W(0)=0$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $p(x)=0$, then the Wronskian is constant.\r\n\\end{corollary}\r\nOne can generalize the theorem above to $n^{th}$ order linear ODEs.\r\nIndeed, for $\\underline{y}^\\prime+A(x)\\underline{y}=\\underline{0}$, we have $W^\\prime+\\operatorname{tr}(A(x))W=0$.\\\\\r\nOne practical application of Abel's identity can be used to find a second solution $y_2$ given one solution $y_1$.\r\nThis can be done by observing that\r\n$$y_1y_2^\\prime-y_2y_1^\\prime=W(x)=W(x_0)\\exp\\left(-\\int_{x_0}^xp(u)\\,\\mathrm du\\right)$$\r\nis both linear and of first order in $y_2$.\\\\\r\nWe cannot, of course, (analytically) solve all ODEs, but for some special types of them, it is sometimes possible.\r\n\\subsection{Special Types of ODEs}\r\n\\begin{definition}\r\n    An ODE is called equidimensional if the differential operator is unaffected by a multiplicative rescaling.\r\n    So $\\mathscr{D}_x=\\mathscr{D}_{\\tilde{x}=\\alpha x}$ where $\\alpha$ is a constant.\r\n    So the general form of a second order linear equidimensional is the following:\r\n    $$ax^2\\frac{\\mathrm d^2y}{\\mathrm dx^2}+bx\\frac{\\mathrm dy}{\\mathrm dx}+cy=f(x)$$\r\n\\end{definition}\r\nThere are two methods to find $y_c$.\\\\\r\nMethod 1: Note that $y=x^k$ is an eigenfunction of the eigenvector of $x(\\mathrm d/\\mathrm dx)$.\r\nTo solve the homogeneous equation, we can plug the eigenfunction in and find out that $k$ satisfies\r\n$$ak(k-1)+bk+c=0$$\r\nIf there are two roots $k_1,k_2$, then the general solution is $y_c=Ax^{k_1}+Bx^{k_2}$ where $A,B$ are constants.\r\nOtherwise, we have at least one $y_c$, so we could use the method in previous sections to find the other.\\\\\r\nMethod 2: Use the substitution $z=\\ln x$, so we will have\r\n$$a\\frac{\\mathrm d^2y}{\\mathrm dz^2}+(b-a)\\frac{\\mathrm dy}{\\mathrm dz}+cy=0$$\r\nwhich we know how to solve.\\\\\r\nFor the forced type of ODE, due to the superposition principle, we just (and will) need a particular solution $y_p$.\r\nThere are two methods to do it.\\\\\r\nMethod 1: Guesswork.\r\n\\begin{center}\r\n    \\begin{tabular}{c|c}\r\n        Form of $f(x)$&Educated guess\\\\\r\n        \\hline\r\n        $e^{kx}$&$Ae^{kx}$\\\\\r\n        $\\sin(kx),\\cos(kx)$&$A\\sin{kx}+B\\cos{kx}$\\\\\r\n        Polynomial&Polynomials\r\n    \\end{tabular}\r\n\\end{center}\r\nWe could plug the educated guesses in and solve for the coefficients.\\\\\r\nMethod 2: Method of parameters.\r\nGiven complementary functions $y_1,y_2$ and solution vectors $\\underline{y_1},\\underline{y_2}$.\r\nSuppose that the solution vector $\\underline{y_p}$ for $y_p$ satisfies\r\n$$\\underline{y_p}=u(x)\\underline{y_1}+v(x)\\underline{y_2}$$\r\nSo what we now try to do is to define two equations for $u^\\prime,v^\\prime$\r\n$$\r\n\\begin{cases}\r\n    y_p=uy_1+vy_2\\\\\r\n    y_p^\\prime=uy_1^\\prime+vy_2^\\prime\r\n\\end{cases}\r\n$$\r\nSo by differentiating the first equation and comparing it with the other, we have $u^\\prime y_1+v^\\prime y_2=0$.\r\nNow differentiate the second equation and plug back to the differential equation, we know that $u^\\prime y_1^\\prime+ v^\\prime y_2^\\prime =f(x)$.\r\nSince the Wronskian is not zero due to definitions of $y_1,y_2$, we know that we can solve for $u^\\prime,v^\\prime$ and a unique solution is guaranteed.\r\nIndeed, $u^\\prime=-fy_2/W,v^\\prime=fy_1/W$.\r\nSo\r\n$$y_p=y_2\\int_{x_0}^x\\frac{y_1(t)f(t)}{W(t)}\\,\\mathrm dt-y_1\\int_{x_0}^x\\frac{y_2(t)f(t)}{W(t)}\\,\\mathrm dt$$\r\n\\begin{definition}\r\n    A forced oscillating ODE is a linear second order ODE forced by oscillating force.\r\n\\end{definition}\r\nThis arises as many physical systems have a restoring force and damping (e.g. friction).\r\n\\begin{example}\r\n    A wheel of mass $M$ is connected to a spring and a damper from above and a force $F(t)$ is applied from below, so $M\\ddot{y}=F(t)-ky-L\\dot{y}$, written in stardard form,\r\n    $$\\ddot{y}+\\frac{L}{M}\\dot{y}+\\frac{k}{M}y=\\frac{F(t)}{M}$$\r\n    we redefine time $\\tau=\\sqrt{k/M}t$ and get\r\n    $$y^{\\prime\\prime}+2Ky^\\prime+y=f(\\tau), K=\\frac{L}{2\\sqrt{kM}}$$\r\n\\end{example}\r\nWe can evaluate the unforced (free, homogeneous) solution where $f\\equiv 0$, which we know how to solve in the general form $Ay_1+By_2$ where $A,B$ are constants.\\\\\r\nCase 1: $K<1$, so we have complex roots of auxiliary equation, so we say the system is underdamped, so\r\n$$y=e^{-K\\tau}[A\\sin(\\sqrt{1-K^2}\\tau)+B\\cos(\\sqrt{1-K^2}\\tau)]$$\r\nCase 2: $K=1$, which system we call it is a critically damped.\r\n$$y=(A+B\\tau)e^{-K\\tau}$$\r\nCase 3: $K>1$, where the system is overdamped.\r\n$$y=Ae^{\\lambda_1\\tau}+Be^{\\lambda_2\\tau},\\lambda_{1,2}=-K\\pm\\sqrt{K^2-1}$$\r\nSo the unforced response always decays exponentially as time goes to infinity.\\\\\r\nAs for forced response, if we have\r\n$$\\ddot{y}+\\mu\\dot{y}+\\omega_0^2y=\\sin{\\omega t}$$\r\nwhich by guessing we have the particular solution\r\n$$y_p=\\frac{\\omega_0^2-\\omega^2}{\\omega_0^2-\\omega^2+\\mu^2\\omega^2}\\sin{\\omega t}+\\frac{-\\mu\\omega}{\\omega_0^2-\\omega^2+\\mu^2\\omega^2}\\cos{\\omega t}$$\r\nFor $\\mu\\neq 0$, we have finite complitude oscillations matching the forcing frequency.\r\nEven when $\\omega=\\omega_0$, then taking the limit to get $-(\\cos\\omega t)/(\\mu\\omega)$, in which case we still have finite amplitude oscillations.\\\\\r\nSo in general, in a damped system, the unforced part gives the short time response whilst the particular solution gives the long time behaviour.\\\\\r\nBut if $\\mu=0,\\omega_0=\\omega$, we call this is a resonance.\r\nThe forcing then matches the unforced responce, where the equation turns to\r\n$$\\ddot{y}+\\omega_0 y=\\sin\\omega_0 t$$\r\nWe shall use detuning to solve the equation.\r\nConsider the equation\r\n$$\\ddot{y}+\\omega_0 y=\\sin\\omega t$$\r\nSo by guessing, we have $y_p=\\sin\\omega t/(\\omega_0^2-\\omega_2)$.\r\nDue to linearity, $y_p+Ay_c$ works for any constant $A$, so\r\n$$y_p=\\frac{\\sin\\omega t-\\sin\\omega_0t}{\\omega_0^2-\\omega^2}=\\frac{2}{\\omega_0^2-\\omega^2}\\cos\\left(\\frac{\\omega_0+\\omega}{2}t\\right)\\sin\\left(\\frac{\\omega-\\omega_0}{2}t\\right)$$\r\nalso solves the equation.\r\nBy letting $\\omega_0\\to\\omega$, we have\r\n$$y_p=-\\frac{t\\cos\\omega_0t}{2\\omega_0}$$\r\nwhich indeed solves the problem.\r\n\\subsection{Dirac Delta (sorry; not sorry)}\r\n\\begin{definition}\r\n    An impulse forcing is a type of forcing by a sudden change.\r\n\\end{definition}\r\n\\begin{example}\r\n    A mountainbike riding from the road onto a side block.\r\n    When they hits, then there is a sudden increase in altitude, which might be followed by some oscillation.\r\n    When the time for this goes to zero, then it is considered as an (infinite) impulse.\r\n    So the forced, damped oscillator has the equation\r\n    $$M\\ddot{y}=F(t)-ky-L\\dot{y}$$\r\n    Now if we add the impulse, and we integrate both sides and let the time elapsed during the hitting to the road block tend to $0$, we will want to define the impulse by\r\n    $$I=\\lim_{\\epsilon\\to 0}\\int_{T-\\epsilon}^{T+\\epsilon}F(t)\\,\\mathrm dt=\\lim_{\\epsilon\\to 0}M[\\dot{y}]^{T+\\epsilon}_{T-\\epsilon}$$\r\n\\end{example}\r\nWe then introduce the Dirac delta function.\r\n\\footnote{And this is the end of the world.}\r\n\\begin{definition}\r\n    Fix a family of functions $D(t;\\epsilon)$ indexed by $\\epsilon$ with the properties:\\\\\r\n    1. For any $t\\neq 0$, we have $\\lim_{\\epsilon\\to0}D(t;\\epsilon)=0$ for $t\\neq 0$.\\\\\r\n    2.\r\n    $$\\int_{\\mathbb R}D(t;\\epsilon)\\,\\mathrm dt=1$$\r\n    We ``define'' the Dirac delta function by $\\delta(t)=\\lim_{\\epsilon\\to 0}D(t;\\epsilon)$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    1. $\\forall t\\neq 0,\\delta(t)=0$.\\\\\r\n    2. For any $a<0<b$,\r\n    $$\\int_a^b\\delta(t)\\,\\mathrm dt=1$$\r\n    3. We have the sampling property.\r\n    For all functions $g(x)$ which are continuous at $x=0$, then\r\n    $$\\int_{\\mathbb{R}}g(x)\\delta(x)\\,\\mathrm dx=g(0)$$\r\n    In general\r\n    $$\\int_a^bg(x)\\delta(x-x_0)\\,\\mathrm dx=\r\n    \\begin{cases}\r\n        g(x_0)\\text{, if $x_0\\in[a,b]$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Ahem.\r\n\\end{proof}\r\n\\begin{definition}\r\n    The Heaviside step function $H(x)$ is defined by\r\n    $$H(x)=\\int_{-\\infty}^x\\delta(x)\\,\\mathrm dx=\r\n    \\begin{cases}\r\n        1\\text{, if $x>0$}\\\\\r\n        0\\text{, if $x<0$}\r\n    \\end{cases}$$\r\n    And $H(0)$ is not defined.\\\\\r\n    It is decreed that $H^\\prime(x)=\\delta(x)$ ``by FTC''.\r\n    \\footnote{I know, I know, stay calm, it is an applied course.}\r\n\\end{definition}\r\n\\begin{definition}\r\n    The ramp function $r(x)$ is defined by\r\n    $$r(x)=\\int_{-\\infty}^xH(x)\\,\\mathrm dx=\r\n    \\begin{cases}\r\n        x\\text{, when $x\\ge 0$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    By FTC, $r^\\prime=H$.\r\n    \\footnote{Lol I guess?}\r\n\\end{definition}\r\nConsider\r\n$$y^{\\prime\\prime}+py^\\prime+qy=\\delta(x)$$\r\nSince $\\delta(x)=0$ for all $x\\neq 0$, so $y^{\\prime\\prime}+py^\\prime+qy=0$ for $x<0$ and $x>0$.\r\nThe highest order derivative inherits the discontinuity from the forcing.\r\nBut we would want $y$ to be continuous at $x=0$, so $\\lim_{\\epsilon\\to 0}[y]^{\\epsilon}_{-\\epsilon}=0$.\r\nAnd $y^\\prime$ would have a jump near $0$, so\r\n$$\\lim_{\\epsilon\\to 0}[y^\\prime]^\\epsilon_{-\\epsilon}=\\lim_{\\epsilon\\to 0}\\int_{-\\epsilon}^\\epsilon y^{\\prime\\prime}+py^\\prime+qy\\,\\mathrm dx=1$$\r\nWe first solve the equations for $x<0$ and $x>0$, so we will have $4$ undetermined constants. and $2$ initial conditions, so we need $2$ more equations, which we can find from the two jump conditions as stated above.\r\n\\begin{example}\r\n    Consider $y^{\\prime\\prime}-y=3\\delta(x-\\pi/2)$\r\n    with $y=0$ at $x=0,\\pi$.\r\n    Note that $y^{\\prime\\prime}-y=0\\implies y=A\\sinh x+B\\cosh x$\r\n    Our initial conditions then implies\r\n    $$y=\r\n    \\begin{cases}\r\n        A\\sinh x\\text{, when $x<\\pi/2$.}\\\\\r\n        C\\sinh (\\pi-x)\\text{, when $x>\\pi/2$.}\r\n    \\end{cases}$$\r\n    For constants $A,C$.\r\n    So we put in the jump condition to have\r\n    $3=\\int_{\\pi/2-\\epsilon}^{\\pi/2+\\epsilon}y^{\\prime\\prime}-y\\,\\mathrm dx=[y^\\prime]^{(\\pi/2)^+}_{(\\pi/2)^-}$\r\n    Putting in the definitions to have\r\n    $$-A\\cosh(\\pi/2)-c\\cosh(\\pi/2)=3$$\r\n    Since we also have $0=[y]^{(\\pi/2)^+}_{(\\pi/2)^-}$, we can solve to get $A=C$, therefore\r\n    $$A=C=\\frac{-3}{2\\cosh(\\pi/2)}$$\r\n    Thus\r\n    $$y=\r\n    \\begin{cases}\r\n        \\frac{-3\\sinh x}{2\\cosh(\\pi/2)}\\text{, when $x\\le\\pi/2$.}\\\\\r\n        \\frac{-3\\sinh (\\pi-x)}{2\\cosh(\\pi/2)}\\text{, when $x>\\pi/2$.}\r\n    \\end{cases}$$\r\n\\end{example}\r\nWe can also have the forcing by Heaviside function.\r\nConsider\r\n$$y^{\\prime\\prime}+py^\\prime+qy=H(x-x_0)$$\r\nFor $p,q$ continuous.\r\n$y(x)$ satisfies $y^{\\prime\\prime}+py^\\prime+qy=0$ for $x<x_0$ and $y^{\\prime\\prime}+py^\\prime+qy=1$ for $x>x_0$\r\nWe can evaluate the equation on either sides of $x_0$, thus\r\n$$[y^{\\prime\\prime}]^{x_0^+}_{x_0^-}+p[y^{\\prime}]^{x_0^+}_{x_0^-}+q[y]^{x_0^+}_{x_0^-}=1$$\r\nIf $y^{\\prime\\prime}$ behaves like the Heaviside function (then $y^\\prime$ bahaves like the ramp function), then $y^\\prime,y$ are continuous, thus $[y^{\\prime}]^{x_0^+}_{x_0^-}=[y]^{x_0^+}_{x_0^-}=0$ and $[y^{\\prime\\prime}]^{x_0^+}_{x_0^-}=1$, which is our jump conditions, which would be enough to find out the constants with the initial conditions.\r\n\\subsection{Higher-Order Discrete/Difference Equations}\r\n\\begin{definition}\r\n    The general form of an $m^{th}$ order linear discrete equation with constant coefficient is\r\n    $$a_my_{n+m}+a_{m-1}y_{n+m-1}+\\cdots+a_0y_n=f(n)$$\r\n\\end{definition}\r\nTurns out that they are closely related to higher order DEs, and we can solve them using the same principles.\r\n\\begin{definition}\r\n    A difference operator $\\mathcal D$ is such that $\\mathcal D (y_n)=y_{n+1}$.\r\n    It has eigenfunctions in the form $y_n=k^n$ for constant $k$ as $D(k^n)=k(k^n)=ky_n$.\r\n\\end{definition}\r\nNote that our difference equation is linear in $y$, thus we can dissolve $y$ into sum of particular and complementary solutions $y_n=y_n^{(c)}+y_n^{(p)}$.\r\n\\begin{example}\r\n    We want to solve $a_2y_{n+2}+a_1y_{n+1}+a_0y_n=f_n$.\r\n    Consider the homogeneous equation with $f=0$, then we can put in $y_n=k^n$ to get $a_2k^2+a_1k+a_0=0$, so its solutions $k_{1,2}$ gives the general form of the complementary solution\r\n    $$\r\n    y_n^{(c)}=\r\n    \\begin{cases}\r\n        Ak_1^n+Bk_2^n\\text{, if $k_1\\neq k_2$}\\\\\r\n        Ak_1^n+Bnk_1^n\\text{, if $k_1=k_2$}\r\n    \\end{cases}\r\n    $$\r\n    Note that these are all the complementary solutions since it has $2$ degrees of freedom and the sequence would be completely determined by its value at the first two initial values.\\\\\r\n    We can use guessing works for particular solution\r\n    \\begin{center}\r\n        \\begin{tabular}{c|c}\r\n            Form of $f_n$&Form of $y_n^{(p)}$\\\\\r\n            \\hline\r\n            $k^n,k\\neq k_{1,2}$&$Ak^n$\\\\\r\n            $k_{1,2}^n$&$Ank_1^n+Bnk_2^n$\\\\\r\n            Polynomial&Polynomials\r\n        \\end{tabular}\r\n    \\end{center}\r\n\\end{example}\r\nThe Fibonacci numbers are defined as $y_0=y_1=1,y_{n+1}=y_n+y_{n-1}$ for $n\\ge 1$.\r\nNote that it has the auxiliary equation $k^2-k-1=0$, which has roots $k_{1,2}=(1\\pm\\sqrt{5})/2$\r\nSo by plugging in our initial conditions, we obtain\r\n$$y_n=\\frac{1}{\\sqrt{5}}(\\phi^{n+1}-(-\\phi^{-1})^{n+1})$$\r\nwhere $\\phi=(\\sqrt{5}+1)/2$ is the golden ratio.\r\nIn particular, $y_{n+1}/y_n\\to\\phi$ as $n\\to\\infty$.\r\n\\subsection{Series Solutions}\r\nOften, there are no analytic solutions to some particular ODE or it is very hard to obtain one.\r\nIn this case, we can try to solve the equation in the form of an infinite power series.\r\nWe can use the method of Frobenius.\r\nConsider the ODE $py^{\\prime\\prime}+qy^\\prime+ry=0$.\r\nWe will seek a series expansion at $x=x_0$ of a (local) solution around some point.\r\nThere are many choice of $x_0$.\r\nIf the series expansions of $q/p$ and $r/p$ converge locally at $x_0$, we say $x_0$ is an ordinary point.\r\nOtherwise, we say it is a singular point.\r\nThere are two types of singular point:\r\nIf $x_0$ is a singular point but the equation can be written in the following way:\r\n$$P(x-x_0)^2y^{\\prime\\prime}+Q(x-x_0)y^\\prime+Ry=0$$\r\nand $Q/P,R/P$ are analytic, then we say $x_0$ is a regular singular point.\r\nNote that $Q/P=(x-x_0)q/p,R/P=(x-x_0)^2r/p$.\r\nOtherwise it is called an irregular singular point.\r\n\\begin{example}\r\n    1. We want to solve\r\n    $$(1-x^2)y^{\\prime\\prime}-2xy^\\prime+2y=0$$\r\n    then $q/p=-2x/(1-x^2),r/p=2/(1-x^2)$, so $x=\\pm 1$ are singularities.\r\n    But $Q/P=(x-x_0)q/p=-2x/(1+x)$, so $x=1$ is regular.\r\n    Similarly $x=-1$ is regular as well.\\\\\r\n    2. Consider\r\n    $$y^{\\prime\\prime}\\sin x+y^\\prime\\cos x+2y=0$$\r\n    Then the singularities are $n\\pi,n\\in\\mathbb Z$, but since $(x-n\\pi)/(\\sin x)$ as $x\\to n\\pi$ tends to a limit, every of them is regular.\\\\\r\n    3. We look into\r\n    $$(1+\\sqrt{x})y^{\\prime\\prime}-2xy^\\prime+2y=0$$\r\n    So $q/p=-2x/(1+\\sqrt{x})$, one can find that the Taylor series at $0$ is undefined.\r\n    Indeed, $0$ is an irregular singular point here.\r\n\\end{example}\r\n\\begin{theorem}[Fuch's Theorem]\r\n    1. If $x=x_0$ is an ordinary point, then there are two linearly independent power series solutions of the form\r\n    $$y=\\sum_{n=0}^\\infty a_n(x-x_0)^{n}$$\r\n    locally near $x_0$.\\\\\r\n    2. If $x=x_0$ is a regular singular point, then there is at least $1$ solution of the form\r\n    $$y=\\sum_{n=0}^\\infty a_n(x-x_0)^{n+\\sigma}$$\r\n    where $\\sigma$ is real and $a_0\\neq 0$.\r\n\\end{theorem}\r\n\\begin{example}\r\n    1. The equation $(1-x^2)y^{\\prime\\prime}-2xy^\\prime+2y=0$ has singular points $\\pm 1$ and they are both regular.\r\n    We first find series solution about an ordinary point, say $x=0$.\r\n    We try\r\n    $$y=\\sum_{n=0}^\\infty a_n(x-0)^{n}$$\r\n    So by plugging in,\r\n    $$(1-x^2)\\sum_{n=2}^\\infty n(n-1)a_nx^{n-2}-2x\\sum_{n=1}^\\infty na_nx^{n-1}+2\\sum_{n=0}^\\infty a_nx^{n}=0$$\r\n    From which we have $a_nn(n-1)-a_{n-2}(n-2)(n-3)-2a_{n-2}(n-2)+2a_{n-2}=0$ for $n\\ge 2$.\r\n    Just simplify to get $n(n-1)a_n=(n^2-3n)a_{n-2}$, so\r\n    $$a_n=\\frac{n-3}{n-1}a_{n-2}$$\r\n    Consequently, $a_0,a_1$, which can be arbitrary constants, could be our initial condition.\r\n    Note that $a_3=0$, hence $a_k=0$ for any odd $k\\ge 3$.\r\n    for even values of $n$, we have\r\n    $$a_n=\\frac{n-3}{n-1}a_{n-2}=\\frac{n-3}{n-1}\\frac{n-5}{n-3}a_{n-4}=\\frac{n-5}{n-1}a_{n-4}=\\cdots=\\frac{n-2k-1}{n-1}a_{n-2k}$$\r\n    Thus $a_{2k}=a_0/(1-n)$, so\r\n    $$y=a_1x+a_0\\left(1-x^2-\\frac{x^4}{3}-\\frac{x^6}{5}-\\cdots\\right)=a_1x+a_0\\left( 1-\\frac{x}{2}\\ln\\frac{1+x}{1-x} \\right)$$\r\n    2. Consider $4xy^{\\prime\\prime}+2(1-x^2)y^\\prime-xy=0$, which has a regular singular point at $x=0$.\r\n    We now try to expand the solution near it.\r\n    We try $y=\\sum_{n=0}^\\infty a_nx^{n+\\sigma}$ for $a_0\\neq 0$ by Fuch's Theorem.\r\n    So we can plug it in our equation to try and get a recurrence for the coefficients.\r\n    Note first that, by multiplying $x$ to both sides\r\n    $$\\sum_{n=0}^\\infty a_nx^{n+\\sigma}(4(n+\\sigma)(n+\\sigma-1)+2(1-x^2)(n+\\sigma)-x^2)=0$$\r\n    Thus by comparing coefficients,\r\n    $$2(n+\\sigma)(2n+2\\sigma-1)a_n=(2n+2\\sigma-3)a_{n-2}$$\r\n    which is our equivalence relation.\\\\\r\n    To find $\\sigma$, we will equate coefficient of lowest power of $x$.\r\n    Set $n=0$, then we can equate the coefficient of $x^\\sigma$, so $a_0(4\\sigma(\\sigma-1))+a_02\\sigma=0\\implies 2\\sigma(2\\sigma-1)a_0=0$.\r\n    This is called the indicial equation.\r\n    So we get $\\sigma=0$ or $\\sigma=1/2$.\\\\\r\n    For $\\sigma=0$, we again set $n=0$ to find that $a_0$ is arbitrary.\r\n    Then consider $n=1$, we have $2a_1=0\\implies a_1=0$.\r\n    Our equivalence relation reduced to $2n(2n-1)a_n=(2n-3)a_{n-2}$, which means that $a_k=0$ for any odd $k$.\r\n    For even $n=2k$, we can calculate a few values to get\r\n    $$y=a_0\\left(1+\\frac{x^2}{4\\cdot 3}+\\frac{5x^4}{8\\cdot 7\\cdot 4\\cdot 3}+\\cdots\\right)$$\r\n    For $\\sigma=1/2$, our recurrence relation reduced to $(2n+1)(2n)b_n=(2n-2)b_{n-2}$ for $n\\ge 2$ where $b_n=a_n$ to avoid ambiguity.\r\n    We can equate the coefficient in the lowest power to get $b_0$ being arbitrary, and by considering $n=1$ we have $b_1=0$, so $b_k=0$ for any odd $k$ as well.\r\n    We can calculate $b_n$ for $n$ even and get\r\n    $$y=b_0x^{1/2}\\left( 1+\\frac{x^2}{2\\cdot 5}+\\frac{5x^4}{2\\cdot 5\\cdot 4\\cdot 9}+\\cdots \\right)$$\r\n\\end{example}\r\nThere are some special cases of the indicial equation.\r\nLet $x_0$ be a regular singular point, and suppose $\\operatorname{Re}(\\sigma_1)\\le\\operatorname{Re}(\\sigma_2)$ where $\\sigma_{1,2}$ are the roots of the indicial equation.\\\\\r\nCase 1: $\\sigma_2-\\sigma_1$ is a non-integer, then the two solutions are linearly independent.\\\\\r\nCase 2: It is a nonzero integer.\r\nIn this case, it is possible, but no guarantee, that the solutions $y_1,y_2$ are linearly dependent, so we might need an extra term in the form $cy_1\\ln(x-x_0)$ in $y_2$, where $c$ is a constant.\\\\\r\nCase 3: It is $0$.\r\nHence $c\\neq 0$, so we can set $c=1$, so we may add $y_1\\ln(x-x_0)$ to $y_2$ in order to yield two linearly independent solutions.", "meta": {"hexsha": "c12e03855e51ec0b7810cf2d3a4496b1de688cf9", "size": 26722, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/higher.tex", "max_stars_repo_name": "david-bai-notes/IA-Differential-Equations", "max_stars_repo_head_hexsha": "eba1ffe070fce235ce1c9611b23339c35c6d6931", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/higher.tex", "max_issues_repo_name": "david-bai-notes/IA-Differential-Equations", "max_issues_repo_head_hexsha": "eba1ffe070fce235ce1c9611b23339c35c6d6931", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/higher.tex", "max_forks_repo_name": "david-bai-notes/IA-Differential-Equations", "max_forks_repo_head_hexsha": "eba1ffe070fce235ce1c9611b23339c35c6d6931", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.9147982063, "max_line_length": 351, "alphanum_fraction": 0.6624504154, "num_tokens": 9268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439707, "lm_q2_score": 0.8376199653600371, "lm_q1q2_score": 0.7168780111557507}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Trigonometric Integral}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nVarious exercises relating to the integration of trigonometric functions.\n\\end{abstract}\n\\maketitle\n\n\nCompute the indefinite integrals below. Since there are many possible answers (which differ by constant values), use the given instructions if needed to choose which possible answer to use.\n\n\\begin{exercise}%[APEX0603TRIG05]\n\\[  \\int \\sin x\\cos^4x\\ dx = \\answer{-\\frac{1}{5} \\cos ^5(x)}+C\\]\n(Your answer should not include any constant term.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0603TRIG08]\n\\[ \\int \\sin^3 x\\cos^3 x\\ dx = \\answer{\\frac{1}{6}\\cos^6x-\\frac{1}{4}\\cos^4x}+C\\]\n(Your answer should not include any constant terms.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0603TRIG19]\n\\[ \\int \\tan^4x\\sec^2x\\ dx = \\answer{\\frac{\\tan ^5(x)}{5}}+ C\\]\n(Add a constant to your answer if needed so that it equals $0$ at $x = 0$.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0603TRIG23]\n\\[ \\int \\tan^3x\\sec^3x\\ dx = \\answer{\\frac{\\sec ^5(x)}{5}-\\frac{\\sec ^3(x)}{3}}+ C\\]\n(Add a constant to your answer if needed so that it equals $-2/15$ at $x = 0$.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0603TRIG10]\n\\[ \\int \\sin^2 x\\cos^7 x\\ dx = \\answer{-\\frac{1}{9} \\sin ^{9}(x)+\\frac{3 \\sin^7(x)}{7}-\\frac{3\\sin ^5(x)}{5}+\\frac{\\sin ^3(x)}{3}}+ C\\]\n(Your answer should not include any constant terms.)\n\\begin{hint}\n\\[ (1-u^2)^3 = 1 - 3 u^2 + 3 u^4 - u^6. \\]\n\\end{hint}\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0603TRIG13]\n\\[ \\int \\sin(5x)\\cos(3x)\\ dx = \\answer{\\frac{1}{2}\\left(-\\frac{1}{8}\\cos(8x)-\\frac{1}{2}\\cos(2x)\\right)}+ C\\]\n\\begin{hint}\nYou can either use an integration by parts technique or you can use a trigonometric identity to simplfy the expression $\\cos Ax \\sin Bx$ (for constants $A$ and $B$) as a sum of simpler things.\n\\end{hint}\n(Your answer should not include any constant terms.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0603TRIG11]\n\\[ \\int \\sin^2 x\\cos^2 x\\ dx = \\answer{\\frac{x}{8}-\\frac{1}{32} \\sin (4 x)}+ C \\]\n(Your answer should not include any constant terms and should equal $0$ at $x = 0$.)\n\\begin{hint}\nUse power reduction formulas.\n\\end{hint}\n%\n%\n\\end{exercise}\n\n\\begin{exercise}\nTo fully evaluate the integral from Example \\ref{trig:reduce_example}, it helps to identify the pattern.  Suppose that the power $7$ is replaced by an unknown positive constant $n > 2$. Carry out the calculation again with the unspecified exponent:\n\\[ \\begin{aligned}\n\\int & \\sec^{n} x \\, dx  = \\int \\sec^{\\answer{n-2}} x  \\sec^2 x \\, dx \\\\\n& = \\sec^{\\answer{n-2}} x \\tan x - \\int \\answer{(n-2)} (\\sec x)^{\\answer{n-3}} (\\sec x \\tan x) \\tan x dx \\\\\n& = \\sec^{\\answer{n-2}} x \\tan x - \\answer{(n-2)}  \\int \\sec^{n} x \\, dx + \\answer{n-2} \\int \\sec^{\\answer{n-2}} x \\, dx.\n\\end{aligned} \\]\nWe conclude\n\\[ \\int \\sec^n x \\, dx = \\answer{\\frac{1}{n-1}} \\sec^{n-2} x \\tan x + \\answer{\\frac{n-2}{n-1}} \\int \\sec^{n-2} x \\, dx. \\]\nUsing this formula several times in a row gives the result\n\\[ \\begin{aligned}\n\\int &  \\sec^7 x \\, dx \\\\\n = & \\frac{\\sec^5 x \\tan x}{6} + \\frac{5}{6} \\int \\sec^5 x \\, dx \\\\\n = & \\frac{\\sec^5 x \\tan x}{6} + \\frac{5}{6}  \\left[ \\frac{\\sec^3 x \\tan x}{4} + \\frac{3}{4} \\int \\sec^3 x \\, dx \\right] \\\\\n = & \\frac{\\sec^5 x \\tan x}{6} +  \\frac{5 \\sec^3 x \\tan x}{4 \\cdot 6} + \\frac{5}{6} \\cdot \\frac{3}{4} \\left[ \\frac{\\sec x \\tan x}{2} + \\frac{1}{2} \\int \\sec x \\, dx \\right] \\\\\n = & \\frac{\\sec^5 x \\tan x}{6} + \\frac{5 \\sec^3 x \\tan x}{24} + \\frac{5 \\sec x \\tan x}{16} + \\frac{5}{16} \\ln |\\sec x + \\tan x| + C.\n\\end{aligned} \\]\n\\end{exercise}\n\n\n\\section*{Sample Quiz Questions}\n\n\\begin{question}%%%%%[TrigInt001]\n\nCompute the value of the integral\n\\[\\int_{0}^{\\frac{\\pi}{4}} \\sin^{3} 2x ~dx.\\]\n(Hints won't be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\frac{1}{5}\\)}\n\\choice[correct]{\\(\\displaystyle \\frac{1}{3}\\)}\n\\choice{\\(\\displaystyle \\frac{1}{2}\\)}\n\\choice{\\(\\displaystyle 1\\)}\n\\choice{\\(\\displaystyle 2\\)}\n\\choice{\\(\\displaystyle 3\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nTo simplify the calculation, begin with a substitution which replaces \\(x\\) with \\(x/2\\). The question reduces to computing\n\\[\\frac{1}{2}\\int_{0}^{\\frac{\\pi}{2}} \\sin^{3} x ~dx.\\]\nThis integral is compatible with the substitution \\(u = \\cos x\\). \\begin{hint} By the substitution formula, this means \\(dx = - du / \\sin x\\), and one must also replace \\(\\sin^2 x\\) by \\(1 - u^2\\). Furthermore, by virtue of the special angle formulas \\(\\cos 0 = 1\\) and \\(\\cos \\frac{\\pi}{2} = 0\\), the problem is reduced to computing the integral\n\\[-\\frac{1}{2}\\int_{1}^{0} (1 - u^2) ~du.\\]\n\\begin{hint}\nCarrying out this calculation in the usual way gives a final answer of \\(\\frac{1}{3}\\).\n\\end{hint}\n\\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[TrigInt010]\n\nCompute the value of the integral\n\\[\\int_{\\frac{\\pi}{6}}^{\\frac{\\pi}{2}} \\tan^{-6} x  \\sec^{5} x ~dx.\\]\n(Hints won't be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\frac{17}{5}\\)}\n\\choice{\\(\\displaystyle \\frac{19}{5}\\)}\n\\choice{\\(\\displaystyle \\frac{23}{5}\\)}\n\\choice{\\(\\displaystyle \\frac{29}{5}\\)}\n\\choice[correct]{\\(\\displaystyle \\frac{31}{5}\\)}\n\\choice{\\(\\displaystyle \\frac{37}{5}\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nSince the power of secant is odd and the power of tangent is even, try rewriting the integral in terms of sine and cosine. This gives \n\\[\\int_{\\frac{\\pi}{6}}^{\\frac{\\pi}{2}} \\sin^{-6} x  \\cos x ~dx.\\]\nThis integral is compatible with the substitution \\(u = \\sin x\\). \\begin{hint} By the substitution formula, this means \\(dx = du / \\cos x\\). Furthermore, by virtue of the special angle formulas \\(\\sin \\frac{\\pi}{6} = \\frac{1}{2}\\) and \\(\\sin \\frac{\\pi}{2} = 1\\), the problem is reduced to computing the integral\n\\[\\int_{\\frac{1}{2}}^{1} u^{-6} ~du.\\] \\begin{hint}\nCarrying out this calculation in the usual way gives a final answer of \\(\\frac{31}{5}\\). \\end{hint} \\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[TrigInt020]\n\nCompute the value of the integral\n\\[\\int_{\\frac{\\pi}{6}}^{\\frac{\\pi}{2}} \\sin^{-2} x  \\cos^{3} x ~dx.\\]\n(Hints won't be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\frac{1}{5}\\)}\n\\choice{\\(\\displaystyle \\frac{1}{3}\\)}\n\\choice[correct]{\\(\\displaystyle \\frac{1}{2}\\)}\n\\choice{\\(\\displaystyle 1\\)}\n\\choice{\\(\\displaystyle 2\\)}\n\\choice{\\(\\displaystyle 3\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nThis integral is compatible with the substitution \\(u = \\sin x\\). By the substitution formula, this means \\(dx = du / \\cos x\\), and one must also replace \\(\\cos^2 x\\) by \\(1-u^2\\). Furthermore, by virtue of the special angle formulas \\(\\sin \\frac{\\pi}{6} = \\frac{1}{2}\\) and \\(\\sin \\frac{\\pi}{2} = 1\\), the problem is reduced to computing the integral \\begin{hint}\n\\[\\int_{\\frac{1}{2}}^{1} u^{-2}(1-u^2) ~du.\\] \\begin{hint}\nCarrying out this calculation in the usual way gives a final answer of \\(\\frac{1}{2}\\). \\end{hint} \\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%%%%%[2015C.10]\n\nCompute the integral below.\n\\[ \\int_0^{\\frac{\\pi}{8}} \\tan^4 2x \\sec^4 2x ~ dx \\]\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\frac{4}{9}\\)}\n\\choice{\\(\\displaystyle \\frac{7}{24}\\)}\n\\choice{\\(\\displaystyle \\frac{5}{14}\\)}\n\\choice{\\(\\displaystyle \\frac{9}{28}\\)}\n\\choice[correct]{\\(\\displaystyle \\frac{6}{35}\\)}\n\\choice{\\(\\displaystyle \\frac{1}{7}\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "d57c5e0889f1e6e65b69db0e9add8900083460d4", "size": 7559, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "techniques/10trigonometricpractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "techniques/10trigonometricpractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "techniques/10trigonometricpractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.0815217391, "max_line_length": 364, "alphanum_fraction": 0.6455880407, "num_tokens": 2678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439707, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7168780076865613}}
{"text": "\\hypertarget{group__numpp__differentiation__forward__automatic}{}\\section{Forward Automatic Differentiation}\n\\label{group__numpp__differentiation__forward__automatic}\\index{Forward Automatic Differentiation@{Forward Automatic Differentiation}}\n\n\nFirst order automatic differentiation in forward mode.  \n\n\n\\subsection*{Classes}\n\\begin{DoxyCompactItemize}\n\\item \nclass \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward$<$ T $>$}\n\\end{DoxyCompactItemize}\n\\begin{DoxyCompactItemize}\n\\item \n{\\footnotesize template$<$typename T $>$ }\\\\constexpr auto \\hyperlink{group__numpp__differentiation__forward__automatic_ga2faff4e6f917370493a6c12f947e2573}{std\\+::relu} (const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&x)\n\\item \n{\\footnotesize template$<$typename T $>$ }\\\\C\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto \\hyperlink{group__numpp__differentiation__forward__automatic_gab45ba058e4fd16d0f9f4c26426e385f9}{std\\+::exp} (const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&x)\n\\item \n{\\footnotesize template$<$typename T $>$ }\\\\C\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto \\hyperlink{group__numpp__differentiation__forward__automatic_ga0f6011595edffe756a984de60358fe5f}{std\\+::log} (const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&x)\n\\item \n{\\footnotesize template$<$typename T $>$ }\\\\C\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto \\hyperlink{group__numpp__differentiation__forward__automatic_ga6f6f07250087b18ada9ea1f84418f24f}{std\\+::sin} (const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&x)\n\\item \n{\\footnotesize template$<$typename T $>$ }\\\\C\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto \\hyperlink{group__numpp__differentiation__forward__automatic_gaa5a06320f93037d94fda441546d7d690}{std\\+::cos} (const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&x)\n\\item \n{\\footnotesize template$<$typename T $>$ }\\\\C\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto \\hyperlink{group__numpp__differentiation__forward__automatic_ga9547d13665c214d44b017b140ccc1a3e}{std\\+::atan} (const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&x)\n\\item \n{\\footnotesize template$<$typename T $>$ }\\\\C\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto \\hyperlink{group__numpp__differentiation__forward__automatic_ga9c142d0a384bfa6e79bf6f614c98fe1d}{std\\+::sqrt} (const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&x)\n\\item \n{\\footnotesize template$<$typename T $>$ }\\\\C\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto \\hyperlink{group__numpp__differentiation__forward__automatic_ga2db415f6b1d59e1f1679ff7bbf4c426b}{std\\+::asin} (const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&x)\n\\end{DoxyCompactItemize}\n\n\n\\subsection{Detailed Description}\nFirst order automatic differentiation in forward mode. \n\n\n\\begin{DoxyCode}\n\\textcolor{preprocessor}{#include\"numpp/differentiation/automatic/forward.h\"}\n\\end{DoxyCode}\n\n\nYou can use it almost in the same way as built-\\/in arithmetic types, e.\\+g. addition, multiplication and other similiar operations are provided.\n\nIt is advised to use auto whenever possible to ease the need of explicit namespace/class names providing.\n\nYou can use partial differentiation, but you have to specify the activity parameter in the constructor (equal to 0 for inactive node), example shown below.\n\n/warning\\+If you need derivatives of higher order it is advised to use symbolic differentiation module for it\\textquotesingle{}s simplifying ability.\n\n{\\bfseries Example\\+: Calculating $ \\frac{\\partial z}{\\partial x} \\cos(x+y)*\\sin(y) + 3 $\\+:} \n\\begin{DoxyCode}\n\\textcolor{comment}{//Active variable x with initial value of 6}\n\\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp::differentiation::automatic::forward} \n      \\hyperlink{group__numpp__differentiation__symbolic_gac865497d2896f51d0cab2e9c64799a15}{x}\\{6\\};\n\\textcolor{comment}{//Inactive variable y with initial value of 4;}\n\\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp::differentiation::automatic::forward} y\\{4\\};\n\\textcolor{comment}{//Calculate value and partial derivative into two seperate variables}\n\\textcolor{keyword}{auto} z = \\hyperlink{group__numpp__differentiation__forward__automatic_gaa5a06320f93037d94fda441546d7d690}{std::cos}(\\hyperlink{group__numpp__differentiation__symbolic_gac865497d2896f51d0cab2e9c64799a15}{x}+y)*\\hyperlink{group__numpp__differentiation__forward__automatic_ga6f6f07250087b18ada9ea1f84418f24f}{std::sin}(y) + 3\nstd::cout << \\textcolor{stringliteral}{\"Function value: \"} << z.value << std::endl;\nstd::cout << \\textcolor{stringliteral}{\"Function derivative wrt x: \"} << z.derivative<< std::endl;\n\\end{DoxyCode}\n\n\n\\begin{DoxySeeAlso}{See also}\nnumpp\\+\\_\\+symbolic\\+\\_\\+differentiation \\char`\\\"{}\\+Symbolic Differentiation\\char`\\\"{} \n\\end{DoxySeeAlso}\n\n\n\\subsection{Function Documentation}\n\\mbox{\\Hypertarget{group__numpp__differentiation__forward__automatic_ga2db415f6b1d59e1f1679ff7bbf4c426b}\\label{group__numpp__differentiation__forward__automatic_ga2db415f6b1d59e1f1679ff7bbf4c426b}} \n\\index{Forward Automatic Differentiation@{Forward Automatic Differentiation}!asin@{asin}}\n\\index{asin@{asin}!Forward Automatic Differentiation@{Forward Automatic Differentiation}}\n\\subsubsection{\\texorpdfstring{asin()}{asin()}}\n{\\footnotesize\\ttfamily template$<$typename T $>$ \\\\\nC\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto std\\+::asin (\\begin{DoxyParamCaption}\\item[{const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&}]{x }\\end{DoxyParamCaption})}\n\nCalculates $\\arcsin(x)$ of a given variable \n\\begin{DoxyParams}{Parameters}\n{\\em x} & forward node being the asin argument \\\\\n\\hline\n\\end{DoxyParams}\n\\begin{DoxyReturn}{Returns}\nNode passed through asin function\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__forward__automatic_ga9547d13665c214d44b017b140ccc1a3e}\\label{group__numpp__differentiation__forward__automatic_ga9547d13665c214d44b017b140ccc1a3e}} \n\\index{Forward Automatic Differentiation@{Forward Automatic Differentiation}!atan@{atan}}\n\\index{atan@{atan}!Forward Automatic Differentiation@{Forward Automatic Differentiation}}\n\\subsubsection{\\texorpdfstring{atan()}{atan()}}\n{\\footnotesize\\ttfamily template$<$typename T $>$ \\\\\nC\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto std\\+::atan (\\begin{DoxyParamCaption}\\item[{const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&}]{x }\\end{DoxyParamCaption})}\n\nCalculates $\\arctan(x)$ of a given variable \n\\begin{DoxyParams}{Parameters}\n{\\em x} & forward node being the arctan argument \\\\\n\\hline\n\\end{DoxyParams}\n\\begin{DoxyReturn}{Returns}\nNode passed through arctan function\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__forward__automatic_gaa5a06320f93037d94fda441546d7d690}\\label{group__numpp__differentiation__forward__automatic_gaa5a06320f93037d94fda441546d7d690}} \n\\index{Forward Automatic Differentiation@{Forward Automatic Differentiation}!cos@{cos}}\n\\index{cos@{cos}!Forward Automatic Differentiation@{Forward Automatic Differentiation}}\n\\subsubsection{\\texorpdfstring{cos()}{cos()}}\n{\\footnotesize\\ttfamily template$<$typename T $>$ \\\\\nC\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto std\\+::cos (\\begin{DoxyParamCaption}\\item[{const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&}]{x }\\end{DoxyParamCaption})}\n\nCalculates $\\cos(x)$ of a given variable \n\\begin{DoxyParams}{Parameters}\n{\\em x} & forward node being the cos argument \\\\\n\\hline\n\\end{DoxyParams}\n\\begin{DoxyReturn}{Returns}\nNode passed through cos function\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__forward__automatic_gab45ba058e4fd16d0f9f4c26426e385f9}\\label{group__numpp__differentiation__forward__automatic_gab45ba058e4fd16d0f9f4c26426e385f9}} \n\\index{Forward Automatic Differentiation@{Forward Automatic Differentiation}!exp@{exp}}\n\\index{exp@{exp}!Forward Automatic Differentiation@{Forward Automatic Differentiation}}\n\\subsubsection{\\texorpdfstring{exp()}{exp()}}\n{\\footnotesize\\ttfamily template$<$typename T $>$ \\\\\nC\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto std\\+::exp (\\begin{DoxyParamCaption}\\item[{const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&}]{x }\\end{DoxyParamCaption})}\n\nCalculates $e^x$ of a given variable \n\\begin{DoxyParams}{Parameters}\n{\\em x} & forward node being the exponent \\\\\n\\hline\n\\end{DoxyParams}\n\\begin{DoxyReturn}{Returns}\nNode passed through exponential function\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__forward__automatic_ga0f6011595edffe756a984de60358fe5f}\\label{group__numpp__differentiation__forward__automatic_ga0f6011595edffe756a984de60358fe5f}} \n\\index{Forward Automatic Differentiation@{Forward Automatic Differentiation}!log@{log}}\n\\index{log@{log}!Forward Automatic Differentiation@{Forward Automatic Differentiation}}\n\\subsubsection{\\texorpdfstring{log()}{log()}}\n{\\footnotesize\\ttfamily template$<$typename T $>$ \\\\\nC\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto std\\+::log (\\begin{DoxyParamCaption}\\item[{const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&}]{x }\\end{DoxyParamCaption})}\n\nCalculates $\\ln(x)$ of a given variable \n\\begin{DoxyParams}{Parameters}\n{\\em x} & forward node being the logarithm argument \\\\\n\\hline\n\\end{DoxyParams}\n\\begin{DoxyReturn}{Returns}\nNode passed through logarithm function\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__forward__automatic_ga2faff4e6f917370493a6c12f947e2573}\\label{group__numpp__differentiation__forward__automatic_ga2faff4e6f917370493a6c12f947e2573}} \n\\index{Forward Automatic Differentiation@{Forward Automatic Differentiation}!relu@{relu}}\n\\index{relu@{relu}!Forward Automatic Differentiation@{Forward Automatic Differentiation}}\n\\subsubsection{\\texorpdfstring{relu()}{relu()}}\n{\\footnotesize\\ttfamily template$<$typename T $>$ \\\\\nconstexpr auto std\\+::relu (\\begin{DoxyParamCaption}\\item[{const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&}]{x }\\end{DoxyParamCaption})}\n\nCalculates rectified linear unit $\\max(0,x)$ of a forward variable \n\\begin{DoxyParams}{Parameters}\n{\\em x} & forward node being passed to Re\\+LU \\\\\n\\hline\n\\end{DoxyParams}\n\\begin{DoxyReturn}{Returns}\nNode passed through Re\\+LU\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__forward__automatic_ga6f6f07250087b18ada9ea1f84418f24f}\\label{group__numpp__differentiation__forward__automatic_ga6f6f07250087b18ada9ea1f84418f24f}} \n\\index{Forward Automatic Differentiation@{Forward Automatic Differentiation}!sin@{sin}}\n\\index{sin@{sin}!Forward Automatic Differentiation@{Forward Automatic Differentiation}}\n\\subsubsection{\\texorpdfstring{sin()}{sin()}}\n{\\footnotesize\\ttfamily template$<$typename T $>$ \\\\\nC\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto std\\+::sin (\\begin{DoxyParamCaption}\\item[{const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&}]{x }\\end{DoxyParamCaption})}\n\nCalculates $\\sin(x)$ of a given variable \n\\begin{DoxyParams}{Parameters}\n{\\em x} & forward node being the sin argument \\\\\n\\hline\n\\end{DoxyParams}\n\\begin{DoxyReturn}{Returns}\nNode passed through sin function\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__forward__automatic_ga9c142d0a384bfa6e79bf6f614c98fe1d}\\label{group__numpp__differentiation__forward__automatic_ga9c142d0a384bfa6e79bf6f614c98fe1d}} \n\\index{Forward Automatic Differentiation@{Forward Automatic Differentiation}!sqrt@{sqrt}}\n\\index{sqrt@{sqrt}!Forward Automatic Differentiation@{Forward Automatic Differentiation}}\n\\subsubsection{\\texorpdfstring{sqrt()}{sqrt()}}\n{\\footnotesize\\ttfamily template$<$typename T $>$ \\\\\nC\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto std\\+::sqrt (\\begin{DoxyParamCaption}\\item[{const \\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward}$<$ T $>$ \\&}]{x }\\end{DoxyParamCaption})}\n\nCalculates $\\sqrt(x)$ of a given variable \n\\begin{DoxyParams}{Parameters}\n{\\em x} & forward node being the sqrt argument \\\\\n\\hline\n\\end{DoxyParams}\n\\begin{DoxyReturn}{Returns}\nNode passed through sqrt function\n\\end{DoxyReturn}\n", "meta": {"hexsha": "2a37ea21602c4d64e8ec3081f1c4e3944e938065", "size": 12862, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/group__numpp__differentiation__forward__automatic.tex", "max_stars_repo_name": "szymonmaszke/numpp", "max_stars_repo_head_hexsha": "9149c9d81f70a6ce833fdd1d2f0f2b584e2ac4d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2018-06-06T01:51:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-02T15:17:00.000Z", "max_issues_repo_path": "docs/group__numpp__differentiation__forward__automatic.tex", "max_issues_repo_name": "vyzyv/numpp", "max_issues_repo_head_hexsha": "9149c9d81f70a6ce833fdd1d2f0f2b584e2ac4d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-11-28T12:15:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-16T00:03:38.000Z", "max_forks_repo_path": "docs/group__numpp__differentiation__forward__automatic.tex", "max_forks_repo_name": "szymonmaszke/numpp", "max_forks_repo_head_hexsha": "9149c9d81f70a6ce833fdd1d2f0f2b584e2ac4d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-08-06T13:58:27.000Z", "max_forks_repo_forks_event_max_datetime": "2018-04-06T06:45:22.000Z", "avg_line_length": 67.6947368421, "max_line_length": 343, "alphanum_fraction": 0.7928004976, "num_tokens": 4286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619947119304, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7168779878451813}}
{"text": "\\documentclass{book}\n\\usepackage{lmodern}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsfonts}\n\\usepackage{xcolor}\n\\usepackage{mdframed}\n\\usepackage[top=3cm, bottom=3cm, inner=4cm, outer=3cm]{geometry}\n\\usepackage{hhline}\n\\usepackage{graphicx}\n\n\\DeclareMathOperator{\\lcm}{lcm}\n\\DeclareMathOperator{\\bigo}{\\mathcal{O}}\n\\renewcommand{\\mod}{\\textrm{mod }}\n\n\\newenvironment{task}\n  {\\begin{mdframed}[backgroundcolor=lightgray]}\n  {\\end{mdframed}}\n  \n\\begin{document}\n\n\\chapter{Solutions}\n\n\\section{Multiples of 3 and 5}\n\n\\begin{task}\nIf we list all the natural numbers below $10$ that are multiples of $3$ and $5$, we get $3$, $5$, $6$, and $9$. The sum of these multiples is $23$.\\\\\n\\\\\nFind the sum of all the multiples of $3$ and $5$ below $1000$.\n\\end{task}\n\nThe first problem is pretty much straightforward. It asks us to find the sum of all multiples of $3$\nand $5$, but any multiple must not exceed $1000 - 1 = 999$. But wait, is this task really that simple?\nThe only trick is that when we calculate the multiples, some of the multiples of $3$ and $5$ are the\nsame, e.g. $15$, $30$, ... That means, that if we do not implement this task in smart way, some of the\nmultiples might get counted twice. Those numbers are exactly the multiples of the least common\nmultiple of $3$ and $5$, which is $15$. We denote that as $\\lcm(3, 5) = 15$.\\\\\n\nLet us take a look at naive solution:\n\n\\begin{verbatim}\n#include<stdio.h>\n\nint main()\n{\n    int sum = 0;\n    for (int i = 1; i <= 333; i++)   // we iterate from 1 to (int)999/3 = 333\n        sum += 3 * i;\n    for (int i = 1; i <= 199; i++)   // we iterate from 1 to (int)999/5 = 199\n        sum += 5 * i;\n    for (int i = 1; i <= 66; i++)    // we iterate from 1 to (int)999/15 = 66\n        sum -= 15 * i;               // we must subtract the twice counted numbers\n    printf(\"%d\\n\", sum);\n\n    return 0;\n}\n\\end{verbatim}\n\nNote that if you implement this program, it will print the value instantly, therefore you might pose the question, why is this a naive solution?\nThe reasons are two. Firstly, we use three for loops. That results in asymptotic complexity of $\\bigo(m/x + m/y + m/ \\lcm(x, y))$, where $x$ and $y$ are the numbers whose multipliers we want to sum and $m$ is the upper bound for all multiples. Now consider we are given extremely large numbers. Although the program runs in linear time, it will take more and more time to get through those three loops. We can clearly see, that we could get rid of three loops and make only one loop, as in next implementation. Wait until you see the real reason why this implementation is not as beautiful as it could be (not to mention it is tiresomly slow - oh, wait, linear is slow, can you do it faster, let’s say logarithmic? Hell no, CONSTANT!).\n\n\\begin{verbatim}\n#include<stdio.h>\n\nint main()\n{\n    int sum = 0;\n    for (int i = 3; i < 1000; i++)\n    {\n        if (i % 3 == 0 || i % 5 == 0)\n            sum += i;\n    }\n    printf(\"%d\\n\", sum);\n    \n    return 0;\n}\n\\end{verbatim}\n\nNote that this implementation does not require any subtraction of multiples of $15$, because we check every integer between $3$ and $999$ inclusively only once. We also expect this program to run slower then the three for one, because in this case we have to loop through $m - 2 = 998$ numbers and each time check whether that number is a multiple of $3$ or $5$, whereas in three for loop we only loop through $\\lfloor(m - 1)/x\\rfloor + \\lfloor(m - 1)/y\\rfloor + \\lfloor(m - 1)/ \\lcm(x, y)\\rfloor = 333 + 199 + 66 = 598$ numbers and we do not need to do any checks.\n\nThe second reason, and here starts the real solution to the problem, is that what we are doing is actually computing a sum of three \\textit{arithmetic series}. An arithmetic series is a sum of numbers that are computed using relation \\[a_1;~~~a_i = a_1 + d(i-1),\\] where $d$ denotes a difference or \\textit{distance} between two numbers in series. In our case we have three arithmetic series, first given by \\[a_1 = 3;~~a_i = 3 + 3(i-1) = 3i,\\] the second by \\[b_1 = 5;~~b_i = 5 + 5(i-1) = 5i\\] and the third by \\[c_1 = 15;~~c_i = 15 + 15(i-1) = 15i.\\] We are actually subtracting the sum of $\\{c_i\\}_{i = 1}^{66}$ series.\nNow, beautiful mathematics gives us a formula for computing sum of arithmetic series. The formula is \\[\\sum_{i=1}^n a_i = \\frac{n}{2}(a_1 + a_n).\\] Since in our case $a_n = 3n$, $b_n = 5n$, and $c_n = 15n$, the above equation simplifies into \\[\\sum_{i=1}^n a_i = a_1 \\cdot \\frac{n(n+1)}{2}.\\] You can simply make your own calculations to see that formula is indeed correct. Let us now implement the program WITHOUT any \\texttt{for} loops at all! We use a formula derived above and get \\[\\textrm{sum} = \\sum_{i=1}^{333} 3i + \\sum_{i=1}^{199} 5i - \\sum_{i=1}^{66} 15i = 3\\cdot\\frac{333\\cdot334}{2} + 5\\cdot\\frac{199\\cdot200}{2} - 15\\cdot\\frac{66\\cdot67}{2}.\\]\n\n\\begin{verbatim}\n#include<stdio.h>\n#include \"campovski.h\"               // needed for LCM\n\nint main()\n{\n    int x, y, m;                     // we let user input starting numbers\n    scanf(\"%d %d %d, &x, &y, &m);    // (in our case \"3 5 1000\")\n    m--;                             // number below m, m not included (1000-1)\n    \n    int z = lcm(x, y);\n    int n1 = (int) m / x;            // calculate range of sum for x (3)\n    int n2 = (int) m / y;            // calculate range of sum for y (5)\n    int n3 = (int) m / z;            // calculate range of sum for LCM(x,y) (15)\n    \n    int sum = x * n1 * (n1 + 1) / 2;\n    sum += y * n2 * (n2 + 1) / 2;\n    sum -= z * n3 * (n3 + 1) / 2;\n    \n    printf(\"%d\\n\", sum);\n    \n    return 0; \n}\n\\end{verbatim}\n\nYou might say taht you could do that faster with your own calculator. Well, the beauty of coding is finding mathematical background of given problem and optimizing the solution.\\\\\n\nI tested all three of the above programs with number $x = 3$, $y = 5$, and $m \\in \\{10^3, 10^6, 10^9, 10^{12}\\}$. The results are astounding (see table below). I also had to change \\texttt{int}s to \\texttt{long long}s.\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{||l||c|c|c|c||}\n\\hhline{|t:=====:t|}\n\\textit{Algorithm} & $t(m = 10^3)$ & $t(m = 10^6)$ & $t(m=10^9)$ & $t(m=10^{12})$\\\\\n\\hhline{||=||=|=|=|=||}\nThree \\texttt{for} loops & $0.000002$ & $0.001528$ & $1.384336$ & $1321.064965$\\\\\n\\hhline{||-||-|-|-|-||}\nOne \\texttt{for} loop & $0.000004$ & $0.003579$ & $3.020462$ & \\\\\n\\hhline{||-||-|-|-|-||}\nFormula & $< 0.000001$ & $< 0.000001$ & $< 0.000001$ & $< 0.000001$\\\\\n\\hhline{|b:=====:b|}\n\\end{tabular}\n\\caption{Table shows running time (in seconds) of given algorithms in relation to $m$. Time was measured with help of \\texttt{time.h}.}\n\\end{table}\n\nNote, hot lovely are the running times of first two algorithms increasing with $m$. Thousand times greater problem, thousand times more time needed. The third algorithm obviously runs in constant time.\n\n\\pagebreak\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Even Fibonacci numbers}\n\n\\begin{task}\nEach new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with $1$ and $2$, the first $10$ terms will be: \\[1,2,3,5,8,13,21,34,55,89,\\dotsc\\]\n\nBy considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.\n\\end{task}\n\nLet us start with example from the task. The first ten terms of Fibonacci sequence, as the task states it, are $1$, $2$, $3$, $5$, $8$, $13$, $21$, $34$, $55$, and $89$. Even-valued terms, that do not exceed $34$ are $2$, $8$, and $34$. Therefore, the sum of the even-valued terms that do not exceed $34$ is $2+8+34 = 44$.\\\\\n\nBefore we get into programming, let us first discuss how terms of Fibonacci sequence are calculated. The first two terms, according to task, are $F_1 = 1$ and $F_2 = 2$. (Mind, that some sources state Fibonacci sequence as $1$, $1$, $2$, $3$, $5$, $8$, $13$,... or even $0$, $1$, $1$, $2$, $3$, $5$, $8$, $13$,...) The next term is acquired by adding previous two together. We end up with formula \\[F_n = F_{n-1} + F_{n-2};~n \\geq 3.\\] This is recursive formula with starting values of $F_1 = 1$ and $F_2 = 2$. At this point you might think that we are going to recursion in order to calculate terms of Fibonacci sequence, but we are not. The reason is, that if we want to compute $n$-th term of Fibonacci sequence, we can use recursion. In our case, we do not know what term is the first that exceeds $4000000$, therefore we cannot use recursion. Besides, naive recursion (if we could use it) would calculate the same terms over and over again - see figure below. We could use a concept called \\textit{memoization} and get rid of this problem, but as I said, we cannot use this technique in this situation.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=1]{images/002-tree.pdf}\n\\caption{Recursion tree for Fibonacci sequence. Note, how terms keep repeating.}\n\\end{figure}\n\nSince we cannot use recursion from $n$ to $1$, we are going to go from $1$ to $n$, summing the previous two terms together to obtain the next one. We are going to check whether that term is even and if it is, we are going to add it to sum.\n\n\\begin{verbatim}\n#include<stdio.h>\n\nint main()\n{\n    int x = 1;             // x represents F(n-2)\n    int y = 2;             // y represents F(n-1)\n    int tmp;               // tmp represents F(n)\n    int sum = 0;\n    while (x <= 4000000)\n    {\n        if (!(x % 2))      // check if x is even\n            sum += x;\n        tmp = x + y;       // F(n) = F(n-1) + F(n-2)\n        x = y;             // F(n-1) becomes F(n-2) for next iteration\n        y = tmp;           // F(n) becomes F(n-1) for next iteration\n    }\n    printf(\"%d\\n\", sum);\n    \n    return 0;\n}\n\\end{verbatim}\n\nThere are probably few things I should explain. First is the condition in \\texttt{if} clause. In C, as well as in some other languages, number $0$ of type \\texttt{int}, beside of being a regular number, stands for $\\textit{false}$ (mind, that C does NOT have boolean variables). Thus, we do not need to make comparison of \\texttt{0 == 0}, but we can simply write \\texttt{!0}, which evaluates to \\texttt{1}.\nNext thing is the way we compute terms for next iteration. First, we sum current terms and save the result in temporary variable \\texttt{tmp}. Then we rewrite \\texttt{x} and \\texttt{y} with \\texttt{y} and \\texttt{tmp} respectively, thus shifting the sequence to the left. The asymptotic complexity of this algorithm is $\\bigo(n)$, where $n$ is the number which terms must not exceed - in our case $n = 4000000$.\\\\\n\nRemember, that I said that some sources state Fibonacci sequence as $1$, $1$, $2$, $3$, $5$, $8$, $13$, $21$, $44$,... Observing this sequence for long enough we can see, that even-valued terms are $F_{3i}$ for all $i \\in \\mathbb{N}$. Proving this is simple. The sum of two odd numbers is even and the sum of even and odd number is odd. Looking at the sequence we can see that this proves the statement by law of induction. Therefore, we can be sure that if we add every third term of Fibonacci sequence to our final sum, we will obtain the correct result. The following algorithm does exactly that. Each iteration we compute the next three terms of Fibonacci sequence and always add the third to final sum.\n\n\\begin{verbatim}\n#include<stdio.h>\n\nint main()\n{\n    int x = 1;             // x represents F(n-2) - always odd\n    int y = 1;             // y represents F(n-1) - always odd\n    int z = 2;             // z represents F(n) - the even term\n    int sum = 0;\n    \n    while (z <= 4000000)\n    {\n        sum += z;          // always add z since it is always even\n        x = y + z;         // F(n+1) = F(n-1) + F(n) (x becomes F(n-2))\n        y = z + x;         // F(n+2) = F(n) + F(n+1) (y becomes F(n-1))\n        z = x + y;         // F(n+3) = F(n+2) + F(n+2) (z becomes F(n))\n    }\n    \n    printf(\"%d\\n\", sum);\n    \n    return 0;\n}\n\\end{verbatim}\n\nThis algorithm still runs in $\\bigo(n)$ but we are advancing three times faster than in previous algorithm, because we calculate three terms in each iteration of \\texttt{while} loop and omitting the \\texttt{if} clause, thus expecting this algorithm to run approximately three times faster does not sound stupid. The only problem is that we are also doing more summations, which will result in algorithm not being three times as fast as the previous one, but it should still be faster.\\\\\n\nNow it is time for some maths. We already figured out that even-valued terms are $F_{3i}$. If we manage to rewrite the recusrion formula $F_n = F_{n-1} + F_{n-2}$ into $F_n = \\alpha f_{n-3} + \\beta F_{n-6}$, we will obtain a formula that uses only every third Fibonacci number and we will not have to bother with odd-valued terms. Let us try to do that.\n\\begin{align*}\nF_n &= F_{n-1} + F_{n-2}\\\\\n&= (F_{n-2} + F_{n-3}) + (F_{n-3} + F_{n-4})\\\\\n&= \\big((F_{n-3} + F_{n-4}) + F_{n-3}\\big) + \\big(F_{n-3} + (F_{n-5} + F_{n-6})\\big)\\\\\n&= 3F_{n-3} + (F_{n-4} + F_{n-5}) + F_{n-6}\\\\\n&= 4F_{n-3} + F_{n-6}\n\\end{align*}\nEasy peasy lemon squizy! Based on formula derived, we can implement next program.\n\n\\begin{verbatim}\n#include<stdio.h>\n\nint main()\n{\n    int x = 2;             // x represents F(n-6)\n    int y = 8;             // y represents F(n-3)\n    int tmp;               // tmp represents F(n)\n    int sum = 0;\n    \n    while (x <= 4000000)\n    {\n        sum += x;\n        tmp = 4 * y + x;   // F(n) = 4 * F(n-3) + F(n-6)\n        x = y;             // F(n-3) becomes F(n-6) for next iteration\n        y = tmp;           // F(n) becomes F(n-3) for next iteration\n    }\n    \n    printf(\"%d\\n\", sum);\n    \n    return 0;\n}\n\\end{verbatim}\n\nCan you guess, how much faster, if faster, will this algorithm run compared to the second one? It still runs in $\\bigo(n)$, we still advance by three terms each iteration... But hey, did you forget about the number of operations again?! I hope not. This time, we do one multiplication more than in second algorithm, but two summations less. Therefore, we expect this program to run faster than the second one, and therefore also faster than the first one. Actually, if we compare the first program to the last one, we can see, that the difference is one \\texttt{if} clause more in the first one and one small multiplication more in the third one. We might actually hope that the last algorithm will run three times as fast as the first one.\\\\\n\nI ran all three programs and measured the time with \\texttt{time.h} but the precision of timing was too low to see much difference. The first program finished in average time of $0.000002$ seconds, and the other two finished in under $0.000001$ seconds. with $n = 9\\,000\\,000\\,000\\,000\\,000\\,000 \\approx \\texttt{LLONG\\_MAX}$ ($9$ quintillion). I decided to make each algorithm run more times. The following table shows the results.\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{||l||c|c|c||}\n\\hhline{|t:====:t|}\n\\textit{Algorithm} & $t(r = 10^3)$ & $t(r = 10^6)$ & $t(r = 10^9)$\\\\ \\hhline{||=||=|=|=||}\n\\texttt{for} and \\texttt{if} & $0.001498$ & $0.335005$ & $330.163120$\\\\ \\hhline{||-||-|-|-||}\nNaive three step & $0.000784$ & $0.183093$ & $181.040890$\\\\ \\hhline{||-||-|-|-||}\nThree step formula & $0.000215$ & $0.102709$ & $97.865098$\\\\ \\hhline{|b:====:b|}\n\\end{tabular}\n\\caption{Table shows the running time (in seconds) of given algorithms in relation to $r$, where $r$ is the number of repetitions the core of program (the algorithm) ran. Time was measured with help of \\texttt{time.h}.}\n\\end{table}\n\nThe results are just like we expected them to be. The \\textit{three step formula} (last algorithm) is three times as fast as the \\textit{\\texttt{for} and \\texttt{if}} (first algorithm). The \\textit{naive three step} (second algorithm) is somewhere in the middle.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Largest prime factor}\n\n\\begin{task}\nThe prime factors of $13195$ are $5$, $7$, $13$, and $29$.\\\\\n\\\\\nWhat is the largest prime factor of the number $600851475143$?\n\\end{task}\n\nThere is a pretty straightforward solution to this problem that seemingly runs in $\\bigo(n)$. What we can do is to loop through every number below $600851475143$ and check whether it is a prime and whether it divides $600851475143$. The most easily grasped solution with high running time. But why did I say it \\textit{seemingly} runs in $\\bigo(n)$. The answer is simple. We have to loop through $n$ numbers, for each check, whether it is a prime or not, that adds another $n$ in game. The total running time is then $\\bigo(n^2)$. With $n = 600851475143$, my head starts burning. I just hope my computer will not. Let us implement this monstrous piece. I advise you not to try this at home. (Not sure should I do a backup first or not...)\n\n\\begin{verbatim}\n#include<stdio.h>\n#include<stdlib.h>\n#define N 600851475143\n\nint is_prime(long n);\n\nint main()\n{\n    long largest = 1;\n    for (long i = 2; i <= N; i++)\n    {\n        if (N % i == 0 && is_prime(i))\n            largest = i;\n    }\n\n    printf(\"%li\\n\", largest);\n\n    return 0;\n}\n\nint is_prime(long n)\n{\n    for (int i = 2; i < n; i++)\n    {\n        if (n % i == 0)\n            return 0;\n    }\n    return 1;\n}\n\\end{verbatim}\n\nMind two things: Although this is a not do at home algorithm, this might come in handy sometime in the future. Mind how we wrote \\texttt{N \\% i == 0} before \\texttt{is\\_prime(i)} in \\texttt{if} clause of function \\texttt{main}. Since we wrote it this way, the computer will first check whether \\texttt{i} divides \\texttt{N}. If not, it will not bother executing \\texttt{is\\_prime(i)}, since the \\texttt{AND} clause will evaluate to \\texttt{0} no matter the second argument. By doing that, we make sure, that we do not check every number for primality and therefore the running time of algorithm is reduced substantially. What we could also do is return $n$ when the for loop comes to it and \\texttt{largest == 1}, since we did not find any other divisor of $n$, meaning $n$ is prime and we do not need to check its primality.\n\nThe second thing you should mind is that we do not need to check whether the new prime divisor is greater than the largest. You might have seen it by yourself why is so, but if not, here is the deal. The \\texttt{i}, which is a possible prime divisor, increases and never decreases. Therefore, it always holds \\texttt{i > largest}.\\\\\n\nThere are few things we could do better in implementation above and we would not even need to think hard. The first that comes to my mind is, that when we check for primality, we do not need to loop from $2$ to $n$. We only need to loop to $\\sqrt{n}$. The reason is that if a number has a higher divisor then its square root, the result of division is smaller than number's square root and it is also a divisor. Therefore we can only check in range from $2$ to $\\sqrt{n}$.\\\\\n\nIt is time for some maths. You have learned about \\textit{sieve of Eratosthenes} in primary school for sure. The idea behind the sieve is to generate an array of numbers between $2$ and $n$. Then we start and cross out all multiples of $2$, except $2$, which is prime. After that, we cross out all multiples of next number that is not crossed, that is $3$. We continue by crossing the multiples of all numbers that are not crossed. By doing so, we end up with table of prime numbers. The array \\texttt{eratosthenes} returns is the array of $0$s and $1$s. A $0$ on $i$-th place in array denotes $i$ is prime. For full implementation of Eratosthenes' sieve see appendix. The only problem is, that we cannot use it here, because we cannot store $600851475143$ bytes anywhere. We will have to dig further, but here is the implementation using sieve of Eratosthenes. It works for small numbers and it works fast.\n\n\\begin{verbatim}\n#include<stdio.h>\n#include \"campovski.h\"                  // needed for ERATOSTHENES\n#define N 100003                        // some small number\n\nint main()\n{\n    char* sieve = eratosthenes(N);      // get prime array\n    int largest = 1;\n\n    for (int i = 2; i <= N; i++)\n    {\n        if (!sieve[i] && N % i == 0)    // if i is prime, sieve[i] = 0\n            largest = i;\n    }\n\n    printf(\"%d\\n\", largest);\n\n    return 0;\n}\n\n\\end{verbatim}\n\nThe idea for next algorithm comes directly from Eratosthenes but instead of creating a sieve, we completely divide out each of the divisor of $n$. By doing that we make sure that the next divisor will certainly be prime and therefore we do not need to check for divisor whether it is prime or not. By doing so we spare a lot of time, because every time we find a divisor $a$, we divide $n$ by $a$ as many times as we can, meaning we end up with smaller and smaller $n$, thus the calculation become faster and faster. Next implementation shows how that is done.\n\n\\begin{verbatim}\n#include<stdio.h>\n#include<stdlib.h>\n\nint main()\n{\n    long long n = 600851475143;\n    long long factor = 2;\n    long long largest;\n\n    while (n > 1)\n    {\n        if (!(n % factor))\n        {\n            largest = factor;\n            do {\n                n /= factor;\n            } while (!(n % factor));\n        }\n\n        factor++;\n    }\n\n    printf(\"%lli\\n\", largest);\n\n    return 0;\n}\n\\end{verbatim}\n\nThis algorithm can be improved in two ways. It is obvious that $2$ is the only even-valued prime number. Therefore we can treat it on its own. By doing so, we can increase \\texttt{factor} by 2 on each iteration and only traverse over odd numbers. The second improvement comes with realisation that every number can have at most one prime factor greater than $\\sqrt{n}$. That leaves us with two options, either we found a factor lower then $\\sqrt{n}$, divided it out and continued with next iteration, or we came to $\\sqrt{n}$ and did not find a factor. In second option, we can stop checking since if there is no prime smaller then $n$ that would divide $n$, then the only numbers that divide $n$ are $1$ and $n$. That means $n$ is a prime and we return it. The next implementation does exactly that.\n\n\\begin{verbatim}\n#include<stdio.h>\n#include<math.h>\n\nint main()\n{\n    long long n = 600851475143;\n    long long largest = 1;\n\n    if (!(n % 2))\n    {\n        largest = 2;\n        do {\n            n /= 2;\n        } while (!(n % 2));\n    }\n\n    long long factor = 3;\n    long long max_factor = (long long) sqrt(n);\n\n    while (n > 1 && factor <= max_factor)\n    {\n        if (!(n % factor))\n        {\n            largest = factor;\n            do {\n                n /= factor;\n            } while (!(n % factor));\n            max_factor = (long long) sqrt(n);\n        }\n\n        factor += 2;\n    }\n\n    if (n == 1)\n        printf(\"%lli\\n\", largest);\n    else printf(\"%lli\\n\", n);\n\n    return 0;\n}\n\\end{verbatim}\n\nI measured the running time of algorithms and the results were quite shocking. The first algorithm needed..., while the second and third one were surprisingly fast. The next table shows running times of algorithms with respect to $n$. Each program was run 1000 times to ensure smaller relative error, except for \\textit{one step \\texttt{factor}} on $n = 100123456789$.\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{||l||c|c|c|c|c||}\n\\hhline{|t:======:t|}\n\\textit{Algorithm} & $t(n = 10^3)$ & $t(n = 10^6)$ & $t(n = 10^5 + 3)$ & $t(n = n_1)$ & $t(n= n_2)$\\\\ \\hhline{||=||=|=|=|=|=||}\nMonster & $0.012390$ & $8.448938$ & $1.754996$ &  &\\\\ \\hhline{||-||-|-|-|-|-||}\nSieve & $0.009984$ & $3.659880$ & $0.454618$ & $-$ & $-$ \\\\ \\hhline{||-||-|-|-|-|-||}\nOne step \\texttt{factor} & $0.000478$ & $0.000634$ & $0.214148$ & $0.130969$ & $\\sim116$ days\\\\ \\hhline{||-||-|-|-|-|-||}\nTwo step + \\texttt{sqrt} & $0.006801$ & $0.007498$ & $0.001555$ & $0.023457$ & $1.362939$ \\\\ \\hhline{|b:======:b|}\n\\end{tabular}\n\\caption{Table shows the running time (in seconds) of given algorithms with respect to $n$, where $n$ is the number whose greatest prime factor we are trying to calculate. $n_1 = 600851475143$ and $n_2 = 100123456789$ ($n_2$ is prime). Time was measured with help of \\texttt{time.h}.}\n\\end{table}\n\nAs you can see, running times are quite strange. For small numbers that are not prime the \\texttt{one step \\texttt{factor}} is faster than \\texttt{two step + \\texttt{sqrt}}, because square root takes too much time to evaluate. On the other hand, if $n$ happens to be prime, the \\texttt{one step \\texttt{factor}} takes a lot of time, because it has to search through all numbers below $n$ before realizing it could actually return an answer. Therefore, one can clearly see that \\textit{two step + \\texttt{sqrt}} is a way to go. The \\textit{sieve} is quite fast, but not appropriate for this problem, since has such a specific implementation that it simply cannot compete. We included it just for broadening mind. Mind also, that we computed sieve only once and ran the rest of the program 1000 times. Places with $-$ denote we could not allocate such a huge sieve and empty space means we did not run the program because it would take too long to execute.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Largest palindrome product}\n\n\\begin{task}\nA palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is $9009 = 91 \\cdot 99$.\\\\\n\\\\\nFind the largest palindrome made from the product of two 3-digit numbers.\n\\end{task}\n\nThis task might look a bit awkward at first. The first problem we encounter is how to smartly generate possible products and the second is how to check if the number is palindrome.\n\nWe tackle the first problem in this way. For generating products we use two \\texttt{for} loops to generate each number in product and then multiply them together. Since we are not stupid, we know that the product $x \\cdot y$ is the same as $y \\cdot x$. That means, that not both numbers $x$ and $y$ must start their loop at $100$. Instead, the inner loop can start where $x$ has left.\n\nThe second problem is a bit trickier. If we were to check if string is palindrome, we could simply iterate over it and check whether the $i$-th character from start is the same as $i$-th character from the end. In case of numbers, we cannot directly iterate over them, but have to first convert them into \\texttt{char} arrays. We use function \\texttt{int\\_to\\_arr}, which is defined in \\texttt{campovski.h}. Now we can do what we would have done with strings. The other way is to use an algorithm for reversing the number and then checking if original number is the same as reversed, but we are not going to do that. Some other time maybe. If you are eager to learn, you can google how to reverse a number in C and you will get plenty of hits.\\\\\n\nNow we are good to go implement the program.\n\n\\begin{verbatim}\n#include<stdio.h>\n#include<math.h>\n#include<stdlib.h>\n#include \"campovski.h\"          // needed for INT_TO_ARR\n\nchar is_palindrome(int n);\n\nint main()\n{\n    int largest = 10000;        // 10000 = 100 * 100\n\n    for (int x = 100; x <= 999; x++)\n    {\n        for (int y = x; y <= 999; y++)  // evade double checking\n        {\n            if (is_palindrome(x*y) && x * y >= largest)\n                largest = x * y;\n        }\n    }\n\n    printf(\"%d\\n\", largest);\n\n    return 0;\n}\n\nchar is_palindrome(int n)\n{\n    char* n_arr = int_to_arr(n);\n    int l = floor(log10(abs(n))) + 1;\n    for (int i = 0; i < (int) l/2; i++)\n    {\n        if (n_arr[i] != n_arr[l-i-1])\n            return 0;\n    }\n\n    return 1;\n}\n\\end{verbatim}\n\nAlthough this program seems alright, there are still some improvements to make. First, let us assume that the largest palindrome product will be a product of two large 3-digit numbers. Therefore, we can start with $x = 999$, decrement $x$ on each iteration and break the inner \\texttt{for} loop when $y$ is so small that $x * y \\leq \\textrm{largest}$. By doing that we hope to spend less time for finding the largest palindrome product.\n\nThe next improvemt is not always possible, therefore we will still consider the above program as BEST! This improvement comes after doing some maths. We realize that $111111 = 143\\cdot 777$ is palindromic and $999 \\cdot 999 < 1000000$. That means that the largest palindrome that is a product of two 3-digit numbers has 6 digits. Let $p$ be a palindromic number with 6 digits. Then we can write\n\\begin{align*}\np &= 100000a + 10000b + 1000c + 100c + 10b+ a\\\\\n&= 100001a + 10010b + 1100c\\\\\n&= 11(9091a + 910b + 100c)\n\\end{align*}\n\nWe figured out, that $11$ must divide the 6-digit palindrome. Since $11$ is a prime, a theorem from number theory and abstract algebra tells us, that at least one of $x$ and $y$ must be divisible by $11$. Therefore, if $x$ is not divisible by $11$, $y$ has to be. Using the information derived and described above, we can implement next program.\n\n\\begin{verbatim}\n#include<stdio.h>\n#include<stdlib.h>\n#include<math.h>\n#include \"campovski.h\"         // needed for INT_TO_ARR\n\nchar is_palindrome(int n);\n\nint main()\n{\n    int largest = 111111;       // 111111 = 143 * 777\n    int y, dy;\n\n    for (int x = 999; x >= 100; x--)\n    {\n        if (x % 11 == 0)       // 11 divides x, doesn't need to divide y\n        {\n            y = 999;           // we must check all y's\n            dy = 1;            // and decrement by 1\n        }\n        else                   // 11 must divide y\n        {\n            y = 990;           // largest 3 digit number that y % 11 = 0\n            dy = 11;           // decrement by 11\n        }\n\n        for (; y >= x; y -= dy)\n        {\n            if (x * y <= largest)    // don't even need to check if\n                break;               // the product is palindrome\n            if (is_palindrome(x*y))\n                largest = x * y;\n           // y -= dy;\n        }\n    }\n\n    printf(\"%d\\n\", largest);\n\n    return 0;\n}\n\nchar is_palindrome(int n)\n{\n    char* n_arr = int_to_arr(n);\n    int l = floor(log10(abs(n))) + 1;\n    for (int i = 0; i < (int) l/2; i++)\n    {\n        if (n_arr[i] != n_arr[l-i-1])\n            return 0;\n    }\n\n    return 1;\n}\n\\end{verbatim}\n\nI tested the program above for finding the largest palindrome product of two $n$-digit numbers, where $n \\in \\{3,4,5\\}$. The table above shows running times.\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{||l||c|c||}\t\n\\hhline{|t:===:t|}\n\\textit{Algorithm} & $t(n=3)$ & $t(n=4)$\\\\ \\hhline{||=||=|=||}\nSimple & $0.140$ & $5.852$ \\\\ \\hhline{||-||-|-||}\nAdvanced & $0.086 / 1000$ & \\\\ \\hhline{|b:===:b|}\n\\end{tabular}\n\\caption{Running time (in seconds) of two implementations for finding largest palindromic product of two $n$-digit numbers. The time was measured by \\texttt{time} command in bash shell.}\n\\end{table}\n\nAs we assumed the second algorithm was much faster, but it could not be used in case of $n = 4$, since the product of two 4-digit numbers can either be a 7-digit or 8-digit number. We could of course break that down too and maybe find something interesting but we are not going to. You can do that for your homework.\\\\\n\nFrom now on, we will be measuring running time with Unix \\texttt{time} command rather than with \\texttt{time.h}.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Smallest multiple}\n\n\\begin{task}\n$2520$ is the smallest number that can be divided by each of the numbers from $1$ to $10$ without any remainder.\\\\\n\\\\\nWhat is the smallest positive number that is evenly divisible by all of the numbers from $1$ to $20$?\n\\end{task}\n\nThis is the first task that actually requires us to know some maths. There is no naive implementation that would just pop up from nowhere. What this task actually requires is to solve the next system of linear congruences:\n\\begin{align*}\nn &\\equiv 0~(\\mod 1)\\\\\nn &\\equiv 0~(\\mod 2)\\\\\nn &\\equiv 0~(\\mod 3)\\\\\n&~~\\vdots\\\\\nn &\\equiv 0~(\\mod 20)\n\\end{align*}\n\nThe only thing we are lucky here is, that $n$ has to be congruent to $0$ by all moduli. The reason for that is, that if $x$ was to be congruent to some other numbers, we would have to use \\textit{Chinese remainder theorem}. And since Chinese remainder theorem only works when moduli are pairwise coprime, meaning that $\\gcd$ of each pair of moduli is $1$, we would have to disassemble the pairs of congruences where $\\gcd$ of moduli would not be $1$ into more congruences whose moduli would be pairwise coprime. The reason why we do not need to use Chinese remainder theorem is fairly obvious. Since $n$ has to be congruent to $0$, that means that $n$ has to be a multiple of moduli. Because we are looking for the smallest number that satisfies these criteria, we are actually looking for least common multiple of moduli. Once we know that, the implementation is really easy, just like \"Hello world!\".\\\\\n\nLet me just mention few things on how to implement the algorithm. First, since $1$ divides every number, we can omit the first congruence. Second, the following is true and can be easily proved: \\[\\lcm(x,y,z) = \\lcm(\\lcm(x,y), z) = \\lcm(x, \\lcm(y,z)).\\] We can use that to compute $\\lcm$ on-the-fly, meaning we can compute the $\\lcm$ of previous $\\lcm$ and next modulo and the result will be the $\\lcm$ of all moduli.\n\n\\begin{verbatim}\n#include<stdio.h>\n#include \"campovski.h\"                // used for LCM\n\nint main()\n{\n    int r = 20;                       // the highest modulo is 20\n    long long n = 2;                  // 1 divides everything\n\n    for (int i = 3; i < r; i++)\n        n = lcm(n, i);                // compute lcm of moduli\n\n    printf(\"%lli\\n\", n);\n\n    return 0;\n}\n\\end{verbatim}\n\nThis algorithm is faster than light. I ran it with different $r$s and the following table shows the results.\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{||l||c|c|c||}\n\\hhline{|t:====:t|}\n\\textit{Algorithm} & $t(r = 20)$ & $t(r = 30)$ & $t(r = 40)$ \\\\ \\hhline{||=||=|=|=||}\n\\texttt{lcm} & $0.676 \\times 10^{-6}$ & $1.112 \\times 10^{-6}$ & $1.508 \\times 10^{-6}$ \\\\ \\hhline{|b:====:b|}\n\\end{tabular}\n\\caption{Running time (in seconds) of the algorithm, measured by Unix \\texttt{time} bash command.}\n\\end{table}\n\nThe limit on $r$ is $r = 43$. With $r >= 44$ we cannot store $n$ in \\texttt{unsigned long long}. Note, that \\textit{Project Euler Problem 5 overview} contains different algorithm, but that algorithm is highly impractical. The reason is, that the algorithm assumes it is given an array of prime numbers, which takes time to calculate. Furthermore, we cannot use our \\texttt{eratosthenes} from \\texttt{campovski.h} because that array contains a lot of zeros and uses a lot of important memory. We would need to implement another function that can compute large primes in a moment and return the array prime numbers. We might do that in the future, if we come across some high primality problem.\n\nThe algorithm provided by Project Euler is suitable for extremely large numbers, which you would need to store in \\texttt{char} array but we are not going to go into that at this moment. If you want you can check the algorithm after you have succesfully solved the problem and checked the solution.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Sum square difference}\n\n\\begin{task}\nThe sum of the squares of the first ten natural numbers is \\[1^2 + 2^2 + \\dotsm + 10^2 = 385.\\] The square of the sum of the first ten natural numbers is \\[(1+2+ \\dotsm + 10) ^2 + 55^2 = 3025.\\] Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is $3025 - 385 = 2640$.\\\\\n\\\\\nFind the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.\n\\end{task}\n\nThis task is really simple. Even a child in primary school can solve it. All you have to do is loop from numbers between $1$ and $100$, calculate their squares and add that number to final sum At the same time we add each number to \\texttt{tmp} which is a normal sum of integers between $1$ and $100$. At the end we subtract the normal sum squared from the sum of squares and print a number that is greater than $0$. BAM, problem 6 done!\n\n\\begin{verbatim}\n#include<stdio.h>\n\nint main()\n{\n    int sum = 0;                            // sum of squares\n    int tmp = 0;                            // sum of natural\n    for (int i = 1; i <= 100; i++)\n    {\n        sum += i * i;\n        tmp += i;\n    }\n    sum -= tmp * tmp;                       // calculate difference\n\n    printf(\"%d\\n\", sum >= 0 ? sum : -sum);  // print nonnegative sum\n\n    return 0;\n}\n\\end{verbatim}\n\nBut wait, there must be something behind this problem. It cannot be that easy and the straightforward solution shall not return the answer instantly... Actually there is a better solution. The implementation above runs in $\\bigo(n)$. But since this is a simple mathematical problem, there exists a solution that runs in $\\bigo(1)$. Let me walk you to better solution.\\\\\n\nIn \\textit{problem 1} we already discussed the concept of \\textit{arithmetic series}. The sum of natural numbers between $1$ and $n$ is nothing else but an arithmetic series with $a_1 = 1$ and $d = 1$. So we derive the next formula: \\[\\sum_{i=1}^n i = \\frac{n(n+1)}{2}.\\] For the sum of squares, there also exists a formula, which we are not going to derive here but the derivation can easily be found online. The formula is \\[\\sum_{i=1}^n i^2 = \\frac{n(n+1)(2n+1)}{6}.\\] Once known it can be quite easily proved by the law of induction. Knowing this two formulas, we get a solution that runs in $\\bigo(1)$.\n\n\\begin{verbatim}\n#include<stdio.h>\n\nint main()\n{\n    int n = 100;\n    int sum_squares = n * (n+1) * (2*n+1) / 6;  // sum of squares\n    int sum = n * (n+1) / 2;                    // sum of natural\n    int diff = sum_squares - sum * sum;         // difference\n\n    printf(\"%d\\n\", diff >= 0 ? diff : -diff);   // print nonnegative diff\n\n    return 0;\n}\n\\end{verbatim}\n\nMind, that we did not need the extra variable \\texttt{diff}. We only did that to make the code more readable. Another thing we could do in some other situation is, that we could divide by 6 in \\texttt{sum\\_squares} at some other position and by that evade the number from growing over the result of that whole line operation, thus being able to calculate higher sums since we would not overflow. But in this case we cannot do that, since we do not know whether any of numbers $n$, $n+1$, and $2n+1$ is divisible by $6$. I am just saying this so you know that the order of operation matters and can sometimes get really useful. For example, if we knew that $n$ is even, we could write \\texttt{int sum = n / 2 * (n+1);} and may be able to calculate sum for higher $n$, because we would first halve the $n$ and then multiply it by $n+1$. Similarly, if $n$ was even, we could write \\texttt{int sum = (n+1) / 2 * n;}.\n\nI ran the above programs and measured running time with Unix \\texttt{time}. The results are in the following table.\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{||l||c|c|c||}\n\\hhline{|t:====:t|}\n\\textit{Algorithm} & $t(n=10^2)$ & $t(n = 10^3)$ & $t(n=10^4)$\\\\ \\hhline{||-||---||}\nBrute force & $0.384 \\times 10^{-6}$ & $2.964 \\times 10^{-6}$ & $29.340 \\times 10^{-6}$\\\\ \\hhline{||-||---||}\nFormulas & $0.016 \\times 10^{-6}$ & $0.012 \\times 10^{-6}$ & $0.024 \\times 10^{-6}$ \\\\ \\hhline{|b:====:b|}\n\\end{tabular}\n\\caption{Running time (in seconds) of programs. They were run $10^6$-times, that is why the time is then divided by $10^6$. $n$ is the upper range of the sum we are calculating (from $1$ to $n$).}\n\\end{table}\n\nOne can clearly see, that first program is nicely linear in $n$. The second runs in constant time... Actually it runs in some respect to the length of $n$, since the longer the number, the more time it needs to multiply. But that is still $\\bigo(1)$ with respect to $n$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{10001st prime}\n\n\\begin{task}\nBy listing the first six prime numbers: $2$, $3$, $5$, $7$, $11$, and $13$, we can see that the 6th prime is $13$.\\\\\n\\\\\nWhat is the 10001st prime number?\n\\end{task}\n\nWe have already discussed a great deal about prime numbers in \\textit{problem 3}. Therefore, we are not going to go in any details here. We are going to use \\texttt{eratosthenes} from \\texttt{campovski.h} which starts with array of $0$ and then places $1$ on $i$-th place if $i$ is NOT a prime number.\n\nAfter acquiring the eratosthenes sieve, we loop through it and every time we find $0$ we add $1$ to count of prime numbers. When count reaches $10001$, we stop and print the index. If the returned index is \\texttt{i = len(sieve) - 1}, the sieve made is not big enough, because we now that \\texttt{(len(sieve) - 1} is not a prime number, since it is even.\n\n\\begin{verbatim}\n#include<stdio.h>\n#include \"campovski.h\"\n\nint main()\n{\n    char* sieve = eratosthenes(1000001);  // generate huge sieve\n    int count = 0;                        // count of primes\n\n    int i;                                // we will need i outside the loop\n    for (i = 2; i < 1000001; i++)\n    {\n        if (!sieve[i])                    // if sieve[i] = 0 then i is prime\n            count++;                      // we found another prime\n        if (count == 10001)               // we found 10001st prime\n            break;\n    }\n\n    printf(\"%d\\n\", i);\n\n    return 0;\n}\n\\end{verbatim}\n\nLet us take a look at the running times of above implementation with different $n$s, where $n$ means that we want to find $n$-th prime.\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{||l||c|c|c|c||}\n\\hhline{|t:=====:t|}\n\\textit{Algorithm} & $t(n=10001)$ & $t(n = 10^5)$ & $t(n=10^6)$ & $t(n=10^7)$\\\\ \\hhline{||-||----||}\nSieve walk & $0.048$ & $0.236$ & $2.700$ & $29.080$ \\\\ \\hhline{|b:=====:b|}\n\\end{tabular}\n\\caption{Running time (in seconds) of programs. We used a sieve of size $10^6 + 1$ for $n=10001$, $10^7 + 1$ for $n = 10^5$, $10^8 + 1$ for $n = 10^6$. and $10^9 + 1$ for $n = 10^7$.}\n\\end{table}\n\nThe algorithm is lovely linear. We increase $n$ ten times, the running time increases ten times.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\setcounter{section}{24}\n\\section{1000-digit Fibonacci number}\n\n\\begin{task}\nThe Fibonacci sequence is defined by the recurrence relation:\n\\[F_n = F_{n-1} + F_{n-2},\\textrm{ where $F_1 = 1$ and $F_2 = 1$}.\\]\nHence the first $12$ terms will be:\n\\begin{align*}\nF_1 &= 1\\\\\nF_2 &= 1\\\\\nF_3 &= 2\\\\\nF_4 &= 3\\\\\nF_5 &= 5\\\\\nF_6 &= 6\\\\\nF_7 &= 13\\\\\nF_8 &= 21\\\\\nF_9 &= 34\\\\\nF_{10} &= 55\\\\\nF_{11} &= 89\\\\\nF_{12} &= 144\n\\end{align*}\nThe $12$th term, $F_{12}$, is the first term to contain three digits.\\\\\n\\\\\nWhat is the index of the first term in the Fibonacci sequence to contain $1000$ digits?\n\\end{task}\n\nThis is one of the problems that we are particularly not lucky to be programming in C. We cannot store the $1000$ digit number in any of number types. We will have to use array of \\texttt{int}s (we could use \\texttt{char}s, but it is really not necessary, since we do not need to spare with memory). The only possible solution to this problem is brute force, since there are no known rules for how Fibonacci numbers' lengths increase. In languages like Python we could write the solution to this problem very easily because we do not need to worry about storing such huge numbers. The solution in Python is this:\n\n\\begin{verbatim}\nx = 1\ny = 1\ncount = 2\nwhile len(str(y)) != 1000:\n    x, y = y, x + y\n    count += 1\nprint count\n\\end{verbatim}\n\nSimple as f***. Now, the solution in C is not much harder, we just have to be careful with arrays. Since we will not care about memory, we can allocate three $1000$ \\texttt{int}s long arrays, one for $F_{n-1}$, one for $F_n$, and one for $F_{n+1}$. Then we loop over all the digits in $F_{n-1}$ and $F_n$ and calculate each digit of $F_{n+1}$ by piece. The only problem is, that we must take care of the situation where \\texttt{F(n-1)[i] + F(n)[i] >= 10}. In this case, we have to remember to increment the next digit. Fairly simple, but quite painful. The next implementation does exactly that.\n\n\\begin{verbatim}\n#include<stdio.h>\n#include<stdlib.h>\n\nint main()\n{\n    int* x = (int*) malloc(1000*sizeof(int));\n    int* y = (int*) malloc(1000*sizeof(int));\n    int* tmp = (int*) malloc(1000*sizeof(int));\n    int inc = 0;                                  // increment on next step\n\n    x[0] = 1;                                     // F(1) = 1\n    y[0] = 1;                                     // F(2) = 1\n    int count = 2;                                // we already know 2 numbers\n\n    while (!y[999])                               // loop while 1000th digit is 0\n    {\n        for (int i = 0; i < 1000; i++)\n        {\n            int s = x[i] + y[i] + inc;            // sum of i-th digit + increment\n            tmp[i] = s % 10;                      // digit of F(n+1)\n            x[i] = y[i];                          // F(n) becomes F(n-1)\n            y[i] = tmp[i];                        // F(n+1) becomes F(n)\n            inc = (s >= 10) ? 1 : 0;              // if s>=10, we must inc on next iter\n        }\n        count++;\n    }\n\n    printf(\"%d\\n\", count);\n\n    return 0;\n}\n\\end{verbatim}\n\nNow if we would want to spare with memory, we would have two options. The first thing we could do is change all \\texttt{int} values to \\texttt{short}s. That would spare a lot of the memory we used for variables. But furthermore, since we know that we will only be using really small numbers at a time (less then $9+9+1 = 19$), we could allocate a \\texttt{char} array and spare even more. Many people think that \\texttt{char} stands for \\textit{character}. Well, it actually does, but the \\texttt{char} type can normally store integral values, just as long as they do not exceed $2^8$. Instead of $4$ bytes (can store up to $2^{32}$) for an \\texttt{int}, we could only use $1$ byte (can store up to $2^8$) for a \\texttt{char}. The implementation is the same.\n\n\\begin{verbatim}\n#include<stdio.h>\n#include<stdlib.h>\n\nint main()\n{\n    char* x = (char*) malloc(1000*sizeof(char));\n    char* y = (char*) malloc(1000*sizeof(char));\n    char* tmp = (char*) malloc(1000*sizeof(char));\n    char inc = 0;\n\n    x[0] = 1;\n    y[0] = 1;\n    int count = 2;\n\n    while (!y[999])\n    {\n        for (int i = 0; i < 1000; i++)\n        {\n            char s = x[i] + y[i] + inc;\n            tmp[i] = s % 10;\n            x[i] = y[i];\n            y[i] = tmp[i];\n            inc = s >= 10 ? 1 : 0;\n        }\n        count++;\n    }\n\n    printf(\"%d\\n\", count);\n\n    return 0;\n}\n\\end{verbatim}\n\nLet me take another note on \\texttt{char}s. One \\texttt{char} is 1 byte, 1 byte is 8 bits and 1 bit can store two values, \\texttt{0} and \\texttt{1}. Since we can store 8 bits in a byte, that means, we can store $2^8$ values in 1 byte. Therefore, if we only have less than $2^8 = 256$ different signs to store, we can use a \\texttt{char}. We use so called ASCII table, which is nothing else but a bijection between symbols like characters, numbers, punctuation, etc. and numbers between $0$ and $255$. For example, a character \\texttt{\"A\"} has an ASCII value of \\texttt{65}. Therefore, if we write something like \\texttt{char c = \"A\";}, what actually gets stored in \\texttt{c} is the number \\texttt{65}, which represents \\texttt{\"A\"}. That means, that if we store \\texttt{42} in \\texttt{char}, the computer might understand that as a character with ASCII value of 42, that is \\texttt{*}, but it can serve as a pure number for our needs, see what I mean? For full ASCII table go ahead and google it, there is really no point in creating one here.\n\nAlso, we will not be making any time comparison here, since we only have one algorithm, the running time of which is clearly $\\bigo(n)$, where $n$ is the length of Fibonacci number, in our case $n = 1000$.\\\\\n\nI measured the running times of above programs with Unix \\texttt{time} bash command. The following table contains results.\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{||l||c|c|c||}\n\\hhline{|t:====:t|}\n\\textit{Algorithm} & $t(n=10^3)$ & $t(n=10^4)$ & $t(n=10^5)$\\\\ \\hhline{||=||=|=|=||}\n\\texttt{int*} & $0.076$ & $4.004$ & $398.320$ \\\\ \\hhline{||-||-|-|-||}\n\\texttt{char*} & $0.040$ & $4.064$ & $402.524$ \\\\ \\hhline{|b:====:b|}\n\\end{tabular}\n\\caption{Running times of the implementations with respect to $n$, where $n$ is the desired length of Fibonacci number.} \n\\end{table}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "ec9153af7df302df6ac20ac77c4f01566f214885", "size": 48783, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "book/book.tex", "max_stars_repo_name": "campovski/euler", "max_stars_repo_head_hexsha": "bb2c8eb1937772563ea6e1fd0b33991c55d5a747", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "book/book.tex", "max_issues_repo_name": "campovski/euler", "max_issues_repo_head_hexsha": "bb2c8eb1937772563ea6e1fd0b33991c55d5a747", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "book/book.tex", "max_forks_repo_name": "campovski/euler", "max_forks_repo_head_hexsha": "bb2c8eb1937772563ea6e1fd0b33991c55d5a747", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.1984732824, "max_line_length": 1107, "alphanum_fraction": 0.6391980813, "num_tokens": 14129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8670357598021707, "lm_q1q2_score": 0.7167886811059279}}
{"text": "\\section{Homology of CW-complexes}\n\\begin{lemma}\nThere are isomorphisms:\n\\begin{equation*}\n H_q(X_n,X_{n-1})\\xrightarrow{\\cong} H_q(X_n/X_{n-1},\\ast)= H_q\\left(\\bigvee_{\\alpha\\in A_n}S^n_\\alpha,\\ast\\right)=\\begin{cases}0 & q\\neq n \\\\ \\Z[A_n] & q=n\\end{cases}\n\\end{equation*}\n\\end{lemma}\nLet's talk about ``characteristic maps''. This is a map $\\left(\\coprod D^n_\\alpha,\\coprod S^{n-1}_\\alpha\\right)\\to (X_n,X_{n-1})$. This is like a ``relative homeomorphism'' (I was drinking water, so this isn't exactly accurate). We have a map $ H_q(X_n,X_{n-1})\\to H_q(X_n/X_{n-1},\\ast)$, to get a commutative diagram:\n\\begin{equation*}\n\\xymatrix{ H_q\\left(\\coprod D^n_\\alpha,\\coprod S^{n-1}_\\alpha\\right)\\ar[r]\\ar[d] & H_q\\left(\\bigvee S^n_\\alpha,\\ast\\right)\\ar[d]\\\\\n H_q(X_n,X_{n-1})\\ar[r] & H_q(X_n/X_{n-1},\\ast)}\n\\end{equation*}\nThe right arrow is an isomorphism. The top arrow is an isomorphism. The lemma says that the bottom map is an isomorphism, so that $ H_q\\left(\\coprod D^n_\\alpha,\\coprod S^{n-1}_\\alpha\\right)\\to H_q(X_n,X_{n-1})$ is an isomorphism. This is called the ``cellular $n$-chains'' on $X$.\n\nNow, fix $q$. For $q=0$, there is:\n\\begin{equation*}\n\\xymatrix{ H_1(X_1,X_0)\\ar[d] & H_0(X_1,X_0)=0 & H_0(X_2,X_1)=0\\\\\n H_0(X_0)\\ar[r]\\ar[drrr] & H_0(X_1)\\ar[r]\\ar[drr]\\ar[u] & H_0(X_2)\\ar[u]\\ar[r]\\ar[dr] & \\cdots\\ar[d]\\\\\n & H_1(X_2,X_1)=0\\ar[u] & & H_0(X)}\n\\end{equation*}\nWe know that $ H_0(X_1,X_0)=0$, but $ H_1(X_1,X_0)$ is not necessarily $0$. This means that $ H_0(X_0)\\to H_0(X_1)$ is surjective, and $ H_0(X_1)\\cong H_0(X_2)$, and so on for higher dimensions. This makes sense because adding higher dimensional cells does not change path components.\n\nLet's try this for $q>0$. Then you have:\n\\begin{equation*}\n\\xymatrix{ & H_{q+1}(X_q,X_{q+1})=0\\ar[d]& H_{q+1}(X_{q+1},X_q)\\ar[d]\\\\\n\\ar[r]\\cdots & H_q(X_{q-1})\\ar[r]\\ar[dr] & H_q(X_q)\\ar[r]\\ar[d] & H_q(X_{q+1})\\ar[r]\\ar[d] & H_q(X_{q+2})\\ar[d]\\ar[r] & \\cdots\\\\\n& & H_q(X_{q},X_{q-1}) & H_q(X_{q+1},X_q)=0 & H_q(X)}\n\\end{equation*}\nSo the first maps ($ H_q(X_0)\\to H_q(X_1)\\to\\cdots$) are isomorphisms, the map $ H_q(X_{q+1})\\to H_q(X_q)$ is an injection, and the map $ H_q(X_q)\\to H_q(X_{q+1})$ is surjective. But also, $ H_q(X_{q+1})\\cong H_q(X_{q+2})\\cong \\cdots$. But also, $ H_q(X_0)\\cong 0$, and we have:\n\\begin{corollary}\n$ H_q(X)=0$ for $q>\\dim X=n$.\n\\end{corollary}\n\\begin{lemma}\n$ H_q(X_n)\\cong H_q(X)$ for $n>0$.\n\\end{lemma}\nI want you to have the following picture in mind. We have a diagram coming from the lexseq in the homology of a pair:\n\\begin{equation*}\n\\xymatrix{C_{n+1}(X)= H_{n+1}(X_{n+1},X_n)\\ar[d]^\\partial\\ar[dr]^d & & 0= H_{n-1}(X_{n-2})\\ar[d]\\\\\n H_n(X_n)\\ar[r]^j\\ar[d] & C_n(X)= H_n(X_n,X_{n-1})\\ar[r]^\\partial\\ar[dr]^d & H_{n-1}(X_{n-1})\\ar[d]^j\\\\\n H_n(X_{n+1})\\ar[d] & & C_{n-1}(X)= H_{n-1}(X_{n-1},X_{n-2})\\\\\n0 = H_n(X_{n+1},X_n)}\n\\end{equation*}\nNow, $\\partial\\circ j=0$. So the composite of the diagonals is zero, i.e., $d^2=0$, and we have a chain complex! More precisely, we get a chain complex, denoted $C_\\ast(X)$. This is the ``cellular chain complex'' of $X$. We should compute the homology of this chain complex. Well, $ H_n(C_\\ast(X))=\\ker d/\\img d$. Now, $\\ker d=\\ker (j\\circ\\partial)$. But $j$ is injective, so $\\ker d=\\ker\\partial$. Also, $\\img d=\\img(j\\circ\\partial)=j(\\img\\partial)$ because $j$ is injective.\n\nThe kernel of $\\partial$ is the image of $j$ by exactness, but $j$ is a monomorphism, so $\\ker\\partial\\cong H_n(X)$. Now, $ H_n(C_\\ast(X))\\cong\\frac{ H_n(X)}{\\img(\\partial)}$. This is equal to $ H_n(X_{n+1})$, again by exactness. But out lemma shows that $ H_n(X_{n+1})= H_n(X)$. In other words, we've proved:\n\\begin{theorem}\nIf $X$ is a CW-complex, then $ H_\\ast(C_\\ast(X))\\cong H_\\ast(X)$. I didn't use specific attaching maps at all, so this is natural in ``skeletal'' maps of CW-complexes.\n\\end{theorem}\nWhat is the differential? You have a relative cycle in dimension $(n+1)$, you're taking its boundary, and then working relative the $(n-1)$-skeleton. You'll see this better in the example we're going to do now, namely projective space.\n\\begin{example}\nWe'll try $ H_\\ast(\\mathbf{RP}^n)$. We have: $\\mathrm{sk}_k(\\RP^n)=\\RP^k$, which are just $1$-dimensional subspaces of $\\mathbf{R}^{k+1}$. Think of the inclusion $\\mathbf{R}^{k+1}\\to\\mathbf{R}^{n+1}$ as the inclusion of the first $(k+1)$ basis vectors. This is a CW-complex because the map $S^{k-1}\\to \\mathbf{RP}^{k-1}$ is a double cover, and you have a pushout:\n\\begin{equation*}\n\\xymatrix{S^{k-1}\\ar[r]\\ar@{^(->}[d] & \\mathbf{RP}^{k-1}\\ar@{^(->}[d]\\\\\nD^k\\ar[r] & \\mathbf{RP}^k}\n\\end{equation*}\nThe attaching maps are the double cover maps.\n\\end{example}\nThe notation is as follows. $\\mathbf{RP}^n=\\mathbf{RP}^{n-1}\\cup_f D^n=\\mathbf{RP}^{n-1}\\cup_f e^n$. The $e^n$ is the notation for an $n$-cell. In particular, $\\mathbf{RP}^n=e_0\\cup_f e_1\\cup_f\\cdots\\cup_f e_n$. You have:\n\\begin{equation*}\n\\xymatrix{0 & C_0(\\mathbf{RP}^n)\\ar[d]\\ar[l] & C_1(\\mathbf{RP}^n)\\ar[d]\\ar[l] & \\cdots\\ar[l]\\ar[d] & C_n(\\mathbf{RP}^n)\\ar[d]\\ar[l] & 0\\\\\n& \\Z\\langle e^0\\rangle & \\Z\\langle e^1\\rangle\\ar[l]^{d=0} & \\cdots\\ar[l] & \\Z\\langle e^n\\rangle\\ar[l]}\n\\end{equation*}\nThe first differential is zero because we know what $ H_0(\\mathbf{RP}^n)$ is (it's $\\Z$!). I have $S^{n-1}\\xrightarrow{f}\\mathbf{RP}^{n-1}\\to \\mathbf{RP}^{n-1}/\\mathbf{RP}^{n-2}=S^{n-1}$. Also recall the commutative diagram from before.\n\\begin{equation*}\n\\xymatrix{ H_n(D^n,S^{n-1})\\ar[r]^\\partial \\ar[d]^\\cong & H_{n-1}(S^{n-1})\\ar[r]\\ar[d]^\\cong & H_{n-1}(S^{n-1},\\ast)\\ar[d]^\\cong\\\\\nC_n= H_n(\\mathbf{RP}^n,\\mathbf{RP}^{n-1})\\ar[r]^\\partial & H_{n-1}(\\mathbf{RP}^{n-1}) \\ar[r] & H_{n-1}(\\mathbf{RP}^{n-1},\\mathbf{RP}^{n-2})=C_{n-1}\n}\n\\end{equation*}\nThe first map on the top is an isomorphism. The bottom composite is our differential. So the map $ H_{n-1}(S^{n-1})\\to H_{n-1}(S^{n-1},\\ast)$. Therefore, $S^{n-1}\\xrightarrow{\\text{double cover}}\\mathbf{RP}^{n-1}\\xrightarrow{\\text{pinching}} S^{n-1}$.\n\\begin{equation*}\n\\xymatrix{S^{n-1}\\ar[r]^{\\text{double cover}}\\ar[dr] & \\mathbf{RP}^{n-1}\\ar[r]^{\\text{pinching}} & S^{n-1}\\\\\n & S^{n-1}/S^{n-2}=S^{n-1}\\vee S^{n-1}\\ar[ur]}\n\\end{equation*}\nOne of the maps $S^{n-1}\\to S^{n-1}$ from the wedge is the identity, and the other map is the antipodal map, as can be seen by looking at a picture. If $\\alpha$ is the antipodal map, then $S^{n-1}\\vee S^{n-1}\\to S^{n-1}$ is $[1,\\alpha]$. If $\\sigma$ is a generator of $ H_{n-1}(S^{n-1})$, we have $\\sigma\\mapsto (\\sigma,\\sigma)\\mapsto \\sigma+\\alpha_\\ast\\sigma$. What is the degree of $\\alpha_\\ast: H_{n-1}(S^{n-1})\\to H_{n-1}(S^{n-1})$, so $\\deg\\alpha=(-1)^n$. Thus the composite, and hence the attaching map, is $(1+(-1)^n)\\sigma$. This means the cellular chain complex is:\n\\begin{equation*}\n\\xymatrix{0 & \\Z\\ar[l]^0 & \\Z\\ar[l]^2 & \\cdots\\ar[l]^0 & \\Z\\ar[l]^{2\\text{ or }0} & 0\\ar[l] & 0\\ar[l] & \\cdots\\ar[l]}\n\\end{equation*}\nWe'll continue next time\\footnote{Why don't we work in $\\Z/2\\Z$ coefficients? This is so much easier then. :P}.\n", "meta": {"hexsha": "891effe499fee6dd685bc20e5cf4cd607a711353", "size": 6961, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-16-homology-cw-complexes.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "old-905/lec-16-homology-cw-complexes.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "old-905/lec-16-homology-cw-complexes.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 88.1139240506, "max_line_length": 574, "alphanum_fraction": 0.6434420342, "num_tokens": 2905, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8670357563664175, "lm_q1q2_score": 0.7167886782655501}}
{"text": "\n\\subsection{Momentum}\n\nWe define the momentum as:\n\n\\(p_j = \\dfrac{\\delta L}{\\delta \\dot q_j}\\)\n\n\\(p_j = \\dfrac{\\delta }{\\delta \\dot q_j}\\sqrt {(\\mathbf {\\dot q})^T\\mathbf M\\mathbf {\\dot q}}\\)\n\n", "meta": {"hexsha": "36bd188ca12f5cb91969ce61f95b2280dbfb8522", "size": 194, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/physics/worldlines/06-06-momentum.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/physics/worldlines/06-06-momentum.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/physics/worldlines/06-06-momentum.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.4, "max_line_length": 95, "alphanum_fraction": 0.618556701, "num_tokens": 73, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9683812363814259, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.7167709749496749}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Find the least squares approximation for the system of equations\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}r@{~}c@{~}r@{~}c@{~}r}\n       x &+& 2y &+& 2z &=&   5, \\\\\n       x &+&  y &-&  z &=&  11, \\\\\n       x &+& 2y &-&  z &=& -18, \\\\\n      2x &-&  y &+& 2z &=&  0. \\\\\n    \\end{array}\n  \\end{equation*}\n  \\begin{sol}\n    $(x,y,z) = (-1,-1,2)$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the least squares approximation for the system of equations\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      -1 & 2 & 1 \\\\\n      -1 & 0 & -1 \\\\\n      2 & 0 & 2 \\\\\n      0 & 0 & 2 \\\\\n      1 & 2 & 2 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    =\n    \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 3 \\\\ -2 \\\\ 4 \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    $(x,y,z) = (2,2,-1)$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the points $(x_1,y_1) = (-1,0)$, $(x_2,y_2) = (0,3)$,\n  $(x_3,y_3) = (1,3)$, $(x_4,y_4) = (2,5)$, $(x_5,y_5) = (3,9)$.  Find\n  the least squares line for these points.\n  \\begin{sol}\n    $y = 2+2x$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the points $(x_1,y_1) = (-1,4)$, $(x_2,y_2) = (0,-2)$,\n  $(x_3,y_3) = (1,4)$, $(x_4,y_4) = (2,2)$.  Find the least squares\n  parabola for these points.\n  \\begin{sol}\n    $y = 1-x+x^2$.\n  \\end{sol}\n\\end{ex}\n", "meta": {"hexsha": "b02501909048af805e3a3b16e348eabc914d64b8", "size": 1318, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/InnerProductSpaces-Application-LeastSquares.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/InnerProductSpaces-Application-LeastSquares.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/InnerProductSpaces-Application-LeastSquares.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 24.4074074074, "max_line_length": 70, "alphanum_fraction": 0.4787556904, "num_tokens": 621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.7167090143104922}}
{"text": "\\chapter{Complexity Classes}\n\nA complexity class is a set of related problems.  Before we talk about\nspecific classes, it is important to understand the difference between\na decision problem and an optimization problem.\n\n\\section{Optimization Problems}\n\nAn optimization problem is a problem of the form ``find the optimal\nsolution for problem p.''  Each such problem may have a different\ndefintion of optimal, and there may be many optimal solutions.\n\n\\section{Decision Problems}\n\nA decision problem is much more limited in scope.  These are problems\nwith strictly yes/no answers, often of the form ``is there a solution of\nsize (at least or at most) k to problem p?''.\n\nNotice that optimization problems have related decision problems.  For\nany optimization problem we can ask the decision problem ``is x the\noptimal solution to problem p?''.\n\n\\section{P}\n\nThe complexity class $P$ is the set of all decision problems which are\nsolvable in polynomial time.  That is to say, all problems for which\nthere exists an algorithm to solve the problem bounded above by\n$O(n^d)$ where $d \\in \\mathbb{Z}$.\n\n\\section{NP}\n\nThe complexity class $NP$ is the set of all decision problems for\nwhich a certificate (possible solution) may be verified in polynomial\ntime.  \n\n\\section{$P \\subseteq NP$}\n\nIt should be obvious that any problem in $P$ is also in $NP$, since if\nwe can find the answer in polynomial time without the certificate, we\nmust certainly be able to do so with the certificate.\n\n\\section{P = NP?}\n\nIt is not obvious if there are problems in $NP$ but not in $P$ or if\nall problems in $NP$ are also in $P$.  In fact,\n\\href{http://www.claymath.org/}{the Clay Mathematics Institute} has\n\\href{http://www.claymath.org/millennium/P_vs_NP/}{listed this as one\n  of the Millenium Prizes} for which the award for solving is 1\nmillion USD.\n", "meta": {"hexsha": "6adeba94609b0e14b51d88ef8b5116edc93509c2", "size": 1832, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "complexity_classes.tex", "max_stars_repo_name": "SteamedPears/AllTheAlgorithms", "max_stars_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-10-12T19:16:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-01T03:13:05.000Z", "max_issues_repo_path": "complexity_classes.tex", "max_issues_repo_name": "SteamedPears/AllTheAlgorithms", "max_issues_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "complexity_classes.tex", "max_forks_repo_name": "SteamedPears/AllTheAlgorithms", "max_forks_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.64, "max_line_length": 72, "alphanum_fraction": 0.7658296943, "num_tokens": 449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7167090045930851}}
{"text": "\n\\section{Inverting \\partialsum and \\adjacentdifference}\n\\Label{sec:partialsuminv}\n\\Label{sec:adjacentdifferenceinv}\n\n\nIn this section we show that under appropriate preconditions\nthe algorithms \\partialsum and\\\\\n\\adjacentdifference are inverse to each other.\n\n\\subsection{Inverting \\partialsum}\n\nLet \\inl{a[0..n-1]} and \\inl{b[0..n-1]} be the respective input and output \nof \\partialsum.\nWe have in other words\n\\begin{align*}\n   \\mathtt{b}[0] &= \\mathtt{a}[0] \\\\\n   \\mathtt{b}[1] &= \\mathtt{a}[0] + \\mathtt{a}[1] \\\\\n                 &\\vdotswithin{=} \\\\\n   \\mathtt{b}[n-1]  &= \\mathtt{a}[0] + \\mathtt{a}[1] + \\ldots + \\mathtt{a}[n-1] \\\\\n\\end{align*}\n\nIf we apply now the algorithm \\adjacentdifference to \\inl{b[0..n-1]}, then\nwe find for its output \\inl{a'[0..n-1]}\n\\begin{alignat*}{3}\n   \\mathtt{a'}[0] &= \\mathtt{b}[0]                        &\\quad &=\\quad \\mathtt{a}[0] \\\\\n   \\mathtt{a'}[1] &= \\mathtt{b}[1] - \\mathtt{b}[0]        &\\quad &=\\quad \\mathtt{a}[1] \\\\\n                 &\\vdotswithin{=}  \\\\\n   \\mathtt{a'}[n-1] &= \\mathtt{b}[n-1] - \\mathtt{b}[n-2]  &\\quad &=\\quad \\mathtt{a}[n-1]\n\\end{alignat*}\n\n\nBefore we start show the \\acsl lemmas of our claim, we present\nthe predicate \\logicref{DefaultBounds} in order to express that the values\nin the input (and output!) array~\\inl{a[0..n-1]} do not overflow.\n\n\\input{Listings/DefaultBounds.acsl.tex}\n\nLemma \\PartialSumInverse from the following listing\nexpresses as \\acsl lemmas\nthat the algorithms \\partialsum and \\adjacentdifference are inverse to each other.\n\n\\input{Listings/NumericInverse.acsl.tex}\n\n%\\clearpage\n\nThe following listing now shows \\isoc function \\partialsuminv\n(both the contract and the implementation).\nThis function calls first \\partialsum and then \\adjacentdifference.\n\n\\input{Listings/partial_sum_inv.c.tex}\n\nThe contract of \\partialsuminv formulates preconditions that shall guarantee\nthat during the computation neither arithmetic overflows (property~\\inl{bounds})\nnor unintended aliasing of arrays (property~\\inl{sep}) occur.\nUnder these precondition, \\framac shall verify\nthat the final call to \\specref{adjacentdifference} just restores the original contents\nof~\\inl{a[0..n-1]} that we supplied for the initial call to \\specref{partialsum}.\n\n\\clearpage\n\n\\subsection{Inverting \\adjacentdifference}\n\nAfter executing the function \\specref{adjacentdifference} on\nthe input array \\inl{a[0..n-1]} the output array \\inl{b[0..n-1]}\nholds the following values\n\\begin{align*}\n   \\mathtt{b}[0] &= \\mathtt{a}[0] \\\\\n   \\mathtt{b}[1] &= \\mathtt{a}[1] - \\mathtt{a}[0] \\\\\n                 &\\vdotswithin{=} \\\\\n   \\mathtt{b}[n-1] &= \\mathtt{a}[n-1] - \\mathtt{a}[n-2] \\\\\n\\end{align*}\n\nIf we call now \\partialsum with the array \\inl{b[0..n-1]}\nas input, then we obtain for its output \\inl{a'[0..n-1]}\n\\begin{alignat*}{3}\n   \\mathtt{a'}[0] &= \\mathtt{b}[0]\n                  &\\quad &=\\quad \\mathtt{a}[0] \\\\\n   \\mathtt{a'}[1] &= \\mathtt{b}[0] + \\mathtt{b}[1]\n                  &\\quad &=\\quad \\mathtt{a}[1] \\\\\n                  &\\vdotswithin{=} \\\\\n   \\mathtt{a'}[n-1]  &=\\ \\mathtt{b}[0] + \\mathtt{b}[1] + \\ldots + \\mathtt{b}[n-1]\n                     &\\quad &=\\quad \\mathtt{a}[n-1] \n\\end{alignat*}\n%\nwhich means that applying \\specref{partialsum} on the output of\n\\adjacentdifference produces the original input.\nLemma \\logicref{AdjacentDifferenceInverse} expresses this property as a lemma.\n\nThe function \\implref{adjacentdifferenceinv} first calls \\adjacentdifference and then\\\\\n\\partialsum.\nThe contract of this function formulates preconditions that shall guarantee\nthat during the computation neither arithmetic overflows (property~\\inl{bound})\nnor unintended aliasing of arrays (property~\\inl{sep}) occur.\nIn order to improve the automatic verification of \n\\adjacentdifferenceinv we also use lemma \\logicref{UnchangedTransitive}.\nLemma \\logicref{AdjacentDifferenceInverseBounds} simplifies\nthe verification of the precondition \\inl{bounds} of \\partialsum.\n\n\\input{Listings/adjacent_difference_inv.c.tex}\n\n", "meta": {"hexsha": "e8a6e78ab870b4c7376819dbb6f6fb99e33b92c0", "size": 3972, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/numeric/numeric_inverse.tex", "max_stars_repo_name": "fraunhoferfokus/acsl-by-example", "max_stars_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2017-06-14T04:17:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T06:07:36.000Z", "max_issues_repo_path": "Informal/numeric/numeric_inverse.tex", "max_issues_repo_name": "fraunhoferfokus/acsl-by-example", "max_issues_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-10-18T13:30:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T07:10:16.000Z", "max_forks_repo_path": "Informal/numeric/numeric_inverse.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 38.9411764706, "max_line_length": 89, "alphanum_fraction": 0.6873111782, "num_tokens": 1275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8791467595934565, "lm_q1q2_score": 0.7167090013291177}}
{"text": "\\lesson{3}{Nov 29 2021 Mon (21:06:20)}{Polynomial Transformations}{Unit 3}\n\n\\begin{definition}[Polynomial Function]\n    A \\bf{Polynomial Function} is a function composed of $1$ or more terms, at least $1$ of which contains a variable. A polynomial function whose degree is $3$ is called a \\bf{Cubic Function}. A \\bf{Polynomial Function} whose degree is $4$ is called a \\bf{Quartic Function}.\n    \n    Simple polynomial functions may be graphed by hand by substituting x-coordinates and solving for the corresponding y-coordinates.\n    \n    The real number solutions of a polynomial equation can be found by identifying the x-intercepts from the graph of the function. Graph the function, and find the point(s) of intersection between the graph and the x-axis.\n\\end{definition}\n\n\\subsubsection*{Odd vs Even vs Neither Polynomial Functions}\n\n\\begin{center}\n\t\\begin{table}[h]\n\t\t\\begin{tabular}{ |r|c|l| } \n\t\t\t\\hline\n\t\t\tResult & Function Type & Symmetry \\\\\n\t\t\t\\hline\n\t\t\t\\multirow{3}{4em}{} $f(-x) = f(x)$\t                & Even function\t       &  y-axis    \\\\\n                                $f(-x) = -f(x)$                 & Odd function         &  Origin    \\\\\n                                $f(-x) \\neq f(x)$ or $f(-x)$    & Neither even and odd &            \\\\\n\t\t\t\t\t\t\t\t\\hline\n\t\t\\end{tabular}\n\n\t\t\\caption{Odd vs Even vs Neither Polynomial Functions}\n\t\t\\label{table:odd-vs-even-vs-neither-polynomial-functions}\n\t\\end{table}\n\\end{center}\n\n\\newpage\n", "meta": {"hexsha": "94ddb79f95204ad0f18ed9bc5f0412d0aa4b75df", "size": 1446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-3/lesson-3.tex", "max_stars_repo_name": "SingularisArt/notes", "max_stars_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-08-31T12:45:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T07:29:05.000Z", "max_issues_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-3/lesson-3.tex", "max_issues_repo_name": "SingularisArt/notes", "max_issues_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-3/lesson-3.tex", "max_forks_repo_name": "SingularisArt/notes", "max_forks_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.6451612903, "max_line_length": 275, "alphanum_fraction": 0.6410788382, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034369, "lm_q2_score": 0.8577681122619883, "lm_q1q2_score": 0.716651136447184}}
{"text": "\\documentclass[11pt,twoside]{article}\n\n\\usepackage[headings]{fullpage}\n\\usepackage[utopia]{mathdesign}\n\n\\pagestyle{myheadings}\n\\markboth{Eigenworms}{Eigenworms}\n\n\\input{../../fncextra}\n\n\\begin{document}\n\n\\begin{center}\n  \\bf Early bird gets the eigenworm\n\\end{center}\n\nThe idea and data for this lab come from Stephens \\textit{et al.}, ``Dimensionality and Dynamics in the Behavior of \\textit{C.\\ elegans},'' \\textit{PLoS Comput Biol}, 2008. In this work the authors captured video of worms moving as they were subjected to stimuli (from ``standard'' to ``painful''). Using image processing, they found 100 points representing a path along the back of single worm within each frame of the video and computed a representation independent of rotation and translation using the tangents to the path. The result is a $100\\times n$ matrix of tangent angles for $n$ frames of video. They used $n=56200$.\n\nThe authors then noted that dimension reduction by the SVD is extraordinarily successful for this data set; they showed that the data are well characterized by a small number of ``eigenworms''.\\footnote{One often sees the ``eigen-'' prefix used in this context, but the SVD is a more fundamental description of the mathematics.} This makes some sense, as the motions are constrained a great deal by anatomy and kinematics. \n\nSuppose $\\m{T}$ is the matrix of angles; i.e., column $\\bft_j$ is the vector of angles in the $j$th video frame. Suppose we have the full SVD $\\m{T}=\\m{U} \\mS \\mV^T$. This would make $\\mV$ an $n\\times n$ matrix, which would not fit in memory, so we have to use a thin SVD. In the text we only did this for an $m\\times n$ matrix with $m>n$, which is not the case for $\\m{T}$. However, $\\m{T}^T=\\m{V} \\mS^T \\mU$ does have a thin form in which $\\m{T}^T=\\widehat{\\mV} \\widehat{\\mS}^T \\mU$, where $\\widehat{\\mV}$ is only $n\\times 100$ and $\\widehat{\\mS}$ is $100\\times 100$. Finally, this gives us\n\\begin{equation}\n  \\label{eq:reducesvd}\n  \\m{T}=\\mU \\widehat{\\mS} \\widehat{\\mV}^T,\n\\end{equation}\nthe thin SVD we need. \n\nObserve that\n\\begin{equation}\n  \\m{T} = \\sum_{k=1}^{100} \\sigma_k \\bfu_k \\bfv_k^T.\n\\end{equation}\nBecause the singular values are always in decreasing order, we may approximate the original matrix by\n\\begin{equation}\n  \\m{T}_r = \\sum_{k=1}^{r} \\sigma_k \\bfu_k \\bfv_k^T,\n\\end{equation}\nfor some rank $r\\ll 100$.  The range of this matrix is spanned by $\\bfu_1,\\ldots,\\bfu_r$, which are the eigenworms. A good way to express the proportion of $\\m{T}$ that is captured by $\\m{T}_r$ is the ratio\n\\begin{equation}\n  \\tau_r = \\frac{\\|\\mathbf{s}_r\\|^2_2}{\\|\\mathbf{s}_{100}\\|^2_2},\n\\end{equation}\nwhere $\\mathbf{s}_k$ is the vector $\\bigl[ \\sigma_1,\\ldots,\\sigma_k \\bigr]$.\n\nOne use of the eigenworms is to create a compact representation of the data. A column $\\bft_j$ of the original data can be expressed in terms of its closest approximation as a linear combination of the eigenworms:\n\\[\n  \\bft_j \\approx c_1 \\bfu_1  + \\cdots + c_r \\bfu_r = \\mU_r \\bfc,\n\\]\nwhere $\\mU_r$ is $100\\times r$. This is a least squares problem, but by orthogonality its solution is $\\bfc=\\mU_r^T\\bft_j$. The $r$ values in this vector give the components of $\\bft_j$ in the principal eigenworm directions and could be used as a low-dimensional representation for further analysis.  \n\n\\subsection*{Goals}\n\nGiven the data matrix, you will perform the SVD analysis, find a reasonable value for the cutoff rank $r$ using the coefficients $\\tau_k$, and extract the eigenworms. \n\n\\subsection*{Preparation}\n\nRead section 7.5. Read the online help for \\texttt{svd}; it uses the term ``economy size'' for the thin SVD. \n\n\\subsection*{Procedure}\n\n\\begin{enumerate}\n\\item Load the \\texttt{shapes.mat} file from the assignment site. It has the matrix \\texttt{T}. \n\n\\item On one graph, plot the first three columns of $\\m{T}$. (These are tangent angles of the worm's body as a function of arc length.) \n\n\\item Using \\texttt{svd}, compute the three matrices in the thin SVD~\\eqref{eq:reducesvd}.\n\n\\item Let \\texttt{s} be the vector of singular values. Using it, plot $1-\\tau_r$ versus $r$ on a semi-log scale, for $r=1,\\dots,100$. From this plot it should be clear that $r=4$ is a compelling choice. Compute and print out the value of $\\tau_4$.\n  \n\\item In a 2-by-2 subplot grid, plot the first 4 eigenworms.\n\n\\item For the first three columns of $\\mT$, plot the best approximation of each column by the leading 4 eigenworms. (The results will be much smoother curves than in step~1.) \n\\end{enumerate}\n\n\\subsection*{Extra}\nThe data has been presented as $\\theta(s)$, i.e.\\ tangent angle as a function of arclength. The tangent and normal vectors to the curve are given by\n\\begin{equation}\n  \\begin{split}\n    \\bft'(s) &= \\frac{d\\theta}{ds} \\mathbf{n}(s),\\\\\n    \\mathbf{n}'(s) &= -\\frac{d\\theta}{ds} \\mathbf{t}(s), \\\\\n    \\bft(0) &= \\bigl[1,0\\bigr], \\quad \\mathbf{n}(0) = \\bigl[ 0,1 \\bigr].\n  \\end{split}\n\\end{equation}\nThe position vector $\\bfr(s)=\\bigl[x(s),y(s)\\bigr]$ is then given by $\\bfr'(s)=\\bft(s)$, $\\bfr(0)=\\bigl[ 0,0 \\bigr]$. For each of the four eigenworms plotted in step~5, solve these equations and plot $\\bfr(s)$. (Hint: You may either discretize the ODEs using Euler's method and then plug in the computed $\\theta$, or you may interpolate the computed $\\theta$ and plug that into an IVP solver. High accuracy is not a concern here.)\n\n\n\\end{document}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: t\n%%% End: \n", "meta": {"hexsha": "88bc25eb306cf7ce62326163fb27cfc54e1ae5d4", "size": 5431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter07/WormMotion/WormMotion.tex", "max_stars_repo_name": "snowdj/fnc-extras", "max_stars_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 109, "max_stars_repo_stars_event_min_datetime": "2018-04-21T09:02:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T19:03:54.000Z", "max_issues_repo_path": "labs/chapter07/WormMotion/WormMotion.tex", "max_issues_repo_name": "snowdj/fnc-extras", "max_issues_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-12-04T22:17:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T21:04:47.000Z", "max_forks_repo_path": "labs/chapter07/WormMotion/WormMotion.tex", "max_forks_repo_name": "snowdj/fnc-extras", "max_forks_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 49, "max_forks_repo_forks_event_min_datetime": "2017-04-02T17:21:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T17:19:57.000Z", "avg_line_length": 60.3444444444, "max_line_length": 628, "alphanum_fraction": 0.7180997975, "num_tokens": 1672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7166511279008569}}
{"text": "\\section{Logical Formulas}\n\n\\frame{\\tableofcontents[currentsection,hideallsubsections, firstsection=2, sections={2-4}]}\n\n% - Logical formulas\n%    - Logical formulas can be expressed as truth tables.\n\n\\subsection{Predicate Cauculus and Truth Tables}\n\\begin{frame}\n  \\frametitle{Why Mathematical Language?}\n  Human language can be imprecise, so we have mathematical language that can be more specific:\\bigskip\n\n  \\begin{center}\n    \"Go to the supermarket to buy 1 milk pack. If they have eggs, buy 12.\"\n  \\end{center}\n  \\bigskip\n\n  Which of the following is correct?\n  \\begin{itemize}\n    \\item If the supermarket has eggs, buy 1 milk pack and 12 eggs.\n    \\item If the supermarket has eggs, buy 12 milk packs.\n  \\end{itemize}\n  \\bigskip\n\n  To avoid this imprecision, we prefer to use mathematical language when talking about logical relationships and proofs.\n\\end{frame}\n\n% Truth table.\n\n\\begin{frame}{Predicate Calculus and Logical Operators}\n  The mathematical language that we use in this lecture is called \\emph{Predicate Calculus}. Predicate calculus connects {\\bf Predicates} and {\\bf Propositions} using logical operators.\\bigskip\n\n  Many of the logical operators you already know from boolean logic:\n  \\begin{itemize}\n    \\item {\\bf AND}, {\\bf OR}, {\\bf XOR}, {\\bf NOT}, etc...\n  \\end{itemize}\\bigskip\n\n  There are a few more unusual logical operators too:\n  \\begin{itemize}\n    \\item {\\bf IMPLIES}, {\\bf IFF}, {\\bf FOR ALL}, {\\bf EXISTS}\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Predicate Calculus and Truth Tables}\n  To evaluate a formula in predicate calculus, we can use \\structure{Truth Tables}, which describe every possible truth value to each proposition.\\bigskip\n\n  {\\bf Example:} P AND Q IMPLIES R\\bigskip\n\n  \\begin{tabular}{|lll|l|l|}\n    P & Q & R & P AND Q & P AND Q IMPLIES R\\\\\n    \\hline\n    {\\bf TRUE} & {\\bf TRUE} & {\\bf TRUE} & {\\bf TRUE} & {\\bf TRUE} \\\\\n    {\\bf TRUE} & {\\bf TRUE} & FALSE & {\\bf TRUE} & FALSE \\\\\n    {\\bf TRUE} & FALSE & {\\bf TRUE} & FALSE & {\\bf TRUE} \\\\\n    {\\bf TRUE} & FALSE & FALSE & FALSE & {\\bf TRUE} \\\\\n    FALSE & {\\bf TRUE} & {\\bf TRUE} & FALSE & {\\bf TRUE} \\\\\n    FALSE & {\\bf TRUE} & FALSE & FALSE & {\\bf TRUE} \\\\\n    FALSE & FALSE & {\\bf TRUE} & FALSE & {\\bf TRUE} \\\\\n    FALSE & FALSE & FALSE & FALSE & {\\bf TRUE} \\\\\n  \\end{tabular}\n\\end{frame}\n\n\n\\subsection{Validity and Satisfiability}\n% - In mathematics and proofs: Every/Exists and their relationship\n%    with validity and satisfiability. (Not only boolean)\n\n\\begin{frame}{Logic Operators: \"For All\" and \"Exists\"}\n  Two of the operators we mentioned are special, and deserve some special attention:\n\n  \\begin{block}{Operator: For all}\n    For a predicate $P(x)$, FOR ALL $P(x)$ is True if $P(x)$ is true for {\\bf every} value of x. It is equivalent to a chain of \"AND\"s:\n\n    \\[\n      F(P(x)): \\forall x_i \\in X, P(x_0) \\land P(x_1) \\land \\ldots \\land P(x_n)\n    \\]\n\n  \\end{block}\n\n  \\begin{block}{Operator: Exists}\n    For a predicate $P(x)$, EXISTS $P(x)$ is True if $P(x)$ is true for {\\bf any} value of x. It is equivalent to a chain of \"OR\"s:\n\n    \\[\n      E(P(x)): \\exists x_i \\in X, P(x_0) \\lor P(x_1) \\lor \\ldots \\lor P(x_n)\n    \\]\n  \\end{block}\n\\end{frame}\n\n% - Validity: Always True\n% - Satisfiability: True for some values\n%    - Can test both with truth tables\n\n\\begin{frame}{Validity and Satisfiability}\n  The logical operators \"exists\" and \"for all\" are closed linked to the concepts of \"Validity\" and \"Satisfiability\":\\bigskip\n\n  \\begin{itemize}\n    \\item {\\bf A logical formula is \\structure{Valid} if}: The formula evaluates for true for every possible assignment of every variable.\\medskip\n\n    For example: $P \\lor \\text{ NOT } P \\implies Q$ is valid.\\bigskip\n\n    \\item {\\bf A logical formula is \\structure{Satisfiable} if}: The formula evaluates for true for at least one possible assignment of variables.\\medskip\n\n    For example: $P \\lor (Q \\land R)$ is satisfiable\n  \\end{itemize}\\bigskip\n\\end{frame}\n\n\\begin{frame}{Validity and Satisfiability}{Proofs and Validity}\n  There are many important implications and uses for the concepts of validity and satisfiability. For example, we can use these concepts when designing proofs.\\bigskip\n\n  If we define a proposition that we want to prove as a logical formula, we can say that the proposition is true if the logical formula is \\structure{Valid}.\\bigskip\n\n  On the other hand, we can define a \\structure{proof by contradiction} by showing that a logical formula that indicates the negative of the proposition is \\structure{satisfiable}.\n\\end{frame}\n\n% - Equivalence: A and B have exactly the same truth table (IFF)\n%    - Rewriting code\n\n\\begin{frame}{Equivalence}{Comparison of Two Formulas}\n  Another related concept is \\structure{Equivalence}. We say that two logical formulas are equivalent, if their result is identical for every variable assignment.\\vfill\n\n  For example: $\\text{NOT }(P \\lor Q)$ is equivalent to $\\text{NOT } P \\land \\text{ NOT } Q$\\\\\n  \\hfill (DeMorgan's Law)\\vfill\n\n  The equivalence of two formulas is useful when rewriting code, and showing that two different pieces of code have the same result.\n\\end{frame}\n\n\\begin{frame}{Validity, Satisfiability, Equivalence and Truth tables}\n  We can show the Validity, Satisfiability, or Equivalence of logical formulas using Truth tables:\\bigskip\n\n  \\begin{itemize}\n    \\item {\\bf A formula is valid}: If all lines in the truth table evaluate to TRUE.\n    \\item {\\bf A formula is satisfiable}: If at least one line in the truth table evaluates to TRUE.\n    \\item {\\bf Two formulas are equivalent}: If all lines in the truth table of the two formulas evaluate to the same value.\n  \\end{itemize}\\bigskip\n\n  However, remember that the size of a truth table is $2^n$, where $n$ is the number of variables in a formula, so this approach might not be feasible for complex formulas.\n\\end{frame}\n\n\n\\subsection{The Satisfiability Problem (SAT problem)}\n\n\\begin{frame}{The Satisfiability Problem}\n\n  Consider the problem of simplifying a computer program: Given a program defined as a logical formula $A$, we want to find a smaller formula $B$ that has the same functionality.\\vfill\n\n  We can test if a certain $B$ is equivalent to $A$ by testing if the expression $A \\iff B$ is {\\bf valid}. Alternatively, We can test that $B$ is {\\bf not} equivalent to $A$ by testing if $\\text{NOT }(A \\iff B)$ is {\\bf satisfiable}. If we can find only one variable assignment where $A$ and $B$ are not equal, then we can discard the program candidate $B$.\\vfill\n\n  This kind of analysis is useful for making programs run faster, or for creating simpler and cheaper hardware.\n\\end{frame}\n\n\\begin{frame}{The Satisfiability Problem}{Proving equivalences}\n  The basic algorithm for proving equivalence in a SAT problem is to test each combination of variables (each line in the truth table). As we discussed before, the number of lines is $2^n$, so this can take a very long time.\\vfill\n\n  Interestingly, if we KNOW one set of variables that satisfy the formula, it is very quick to test it. Just evaluate the formula.\\vfill\n\n  This characteristic of SAT: \"Very slow to find the answer, very fast to check the answer\", is one of the key characteristics of NP-hardness. If you can find a quick solution to the SAT problem, you would become a very famous computer scientist!\n\\end{frame}\n", "meta": {"hexsha": "fd3b4a7d6539e0b7e360ed9d060f6263c1fd51ac", "size": 7311, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week01/04_LogicalFormulas.tex", "max_stars_repo_name": "caranha/MathCS", "max_stars_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-09-13T18:59:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T02:14:56.000Z", "max_issues_repo_path": "week01/04_LogicalFormulas.tex", "max_issues_repo_name": "caranha/MathCS", "max_issues_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week01/04_LogicalFormulas.tex", "max_forks_repo_name": "caranha/MathCS", "max_forks_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.2721518987, "max_line_length": 364, "alphanum_fraction": 0.7160443168, "num_tokens": 1936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867825403177, "lm_q2_score": 0.897695295528596, "lm_q1q2_score": 0.7165285196395497}}
{"text": "\\chapter{Fixed Point Theorem}\nProbbaly one of the most surprinsg phenomenon in the world of esoteric \nprogramming is existence of quines, the programs that print themself.\\marginurl{%\nProbably the most impresive example of a quine is Quine Relay, a Ruby program\n  that generates Rust program that generates Scala program that generates\n  \\dots (through 128 languages in total)\\dots REXX program that generates the\n  original Ruby code again.\n}{github.com/mame/quine-relay}\nThis chapter proves existence of such programs in almost all programming\nlanguages.\n\n\\begin{theorem}[Kleene's Fixed Point Theorem]\n\\label{theorem:kleene}\n  Let $h : \\N \\to \\N$ be a total computbale function, and let $U : \\N^2 \\to \\N$\n  be a G\\\"odel universal function. Then there is $n \\in \\N$ such that $U_n$ is\n  equal to $U_{h(n)}$.\n\\end{theorem}\n\\begin{proof}\n  Let $f : \\N \\to \\N$ be a computable function such that no computable function\n  $g : \\N \\to \\N$ can differ from $f$ everywhere, such a function exists by\n  \\Cref{theorem:intersecting-function}. Note that there is a total computable\n  function $g : \\N \\to \\N$ such that $U_{f(n)} = U_{g(n)}$ provided that $f(n)$\n  is defined. Indeed, let us consider $V(x, y) = U(f(x), y)$; since $U$ is a\n  G\\\"odel universal function, there is a total function $g(n)$ such that\n  $V(x, y) = U(g(x), y)$.\n\n  Assume for the sake of contradiction that $U_n \\neq U_{h(n)}$ for all $n \\in\n  \\N$. Let $t : \\N \\to \\N$ be a total computable function such that $t(n) =\n  h(g(n))$. It is clear that if $f$ is different from $t$ evrywhere, which\n  contradictis to the definition of $f$.\n\\end{proof}\n\n\\begin{corollary}\n  Let $U : \\N^2 \\to \\N$ be a G\\\"odel universal function. Then there is $n \\in\n  \\N$ such that $U(n, x) = n$ for all $x \\in \\N$.\n\\end{corollary}\n\\begin{proof}\n  Let $q : \\N \\to \\N$ be a computable total function such that $U(q(n), x) = n$\n  for all $x \\in \\N$ (such a function exists since $U$ is a G\\\"odel universal\n  function). Note that there is $n$ such that $U_n$ is equal to $U_{q(n)}$ which\n  implies that $U(n, x) = U(q(n), x) = n$ for all $x \\in \\N$.\n\\end{proof}\n\n\\begin{exercise}\n  Prove that there is a program on the programing of your choice that prints its\n  text backwards.\n\\end{exercise}\n\nPotentially, the function $h$ in Kleene's fixed point theorem\n(\\Cref{theorem:kleene}) may depend on a parameter; however, even in this case\nthere is a fixed point theorem.\n\\begin{theorem}\n\\label{theorem:kleene-parameter}\n  Let $h : \\N^2 \\to \\N$ be a total computbale function, and let $U : \\N^2 \\to \\N$\n  be a G\\\"odel universal function. Then there is total computable function $m\n  \\in \\N$ such that $U(h(p, m(p)), x) = U(m(p), x)$ for all $p, x \\in \\N$\n\\end{theorem}\n\n\\begin{chapterendexercises}\n  \\exercise Show that there are different $p, q \\in \\N$ such that $U(p, x) = q$\n    and $U(q, x) = p$ for all $x \\in \\N$.\n  \\exercise Let $h : \\N \\to \\N$ be a total computbale function, and let \n    $U : \\N^2 \\to \\N$ be a G\\\"odel universal function. Show that\n    there are infinetely many $n \\in \\N$ such that $U_n = U_{h(n)}$.\n  \\exercise Prove \\Cref{theorem:kleene-parameter}.\n\n\\end{chapterendexercises}\n", "meta": {"hexsha": "23331236317a4c1ab326b8d38eaf04cb0abd9ca0", "size": 3139, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_9/chapter_38_fixed_point.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_9/chapter_38_fixed_point.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_9/chapter_38_fixed_point.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 46.1617647059, "max_line_length": 81, "alphanum_fraction": 0.6801529149, "num_tokens": 1030, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7165138144823826}}
{"text": "\\section{Integral Domains, Maximal and Prime Ideals}\r\n\\subsection{Integral Domains}\r\n\\begin{definition}\r\n    An integral domain is a ring $R$ with $0\\neq 1$ and $ab=0$ implies $a=0$ or $b=0$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    In a ring $R$, an element $a\\neq 0$ is called a zero divisor if $\\exists b\\in R,b\\neq 0,ab=0$.\r\n\\end{definition}\r\nSo an integral domain is a ring without zero divisors.\r\n\\begin{example}\r\n    1. All fields are integral domains.\\\\\r\n    2. Any subring of an integral domain is an integral domain.\r\n    Hence $\\mathbb Z[i]\\le\\mathbb C$ is an integral domain.\\\\\r\n    3. (non-example) $\\mathbb Z\\times\\mathbb Z$ is not an integral domain since $(1,0)(0,1)=(0,0)$.\r\n\\end{example}\r\n\\begin{lemma}\r\n    If $R$ is an integral domain, so is $R[X]$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Let $f,g\\in R[X]$ be nonzero polynomials.\r\n    Suffice to show that $\\deg(fg)=\\deg(f)+\\deg(g)$.\r\n    Indeed, if\r\n    $$f(X)=\\sum_{k=0}^na_kX^k,g(X)=\\sum_{k=0}^mb_kX^k,a_n,b_m\\neq 0$$\r\n    Then $f(X)g(X)=a_nb_mX^{n+m}+\\cdots$, but since $R$ is an integral domain, $a_nb_m\\neq 0$, therefore $\\deg(fg)=n+m=\\deg(f)+\\deg(g)$.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Let $R$ be an integral domain and $0\\neq f\\in R[X]$.\r\n    Then the number of roots of $f$ in $R$ is at most $n$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Exercise.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    Any finite subgroup of the multiplicative group of a field is cyclic.\r\n\\end{theorem}\r\n\\begin{example}\r\n    $(\\mathbb Z/p\\mathbb Z)^\\times$ is cyclic.\\\\\r\n    Also, $U_m=\\{x^m=1:x\\in\\mathbb C\\}$ is cyclic.\r\n\\end{example}\r\n\\begin{proof}\r\n    Let $F$ be a field and $A$ a finite subgroup of $F^\\times$.\r\n    So $A$ is a finite abelian group, and if it is not cyclic, then by Theorem \\ref{fin_abe_struct}, it contains a subgroup isomorphic to $C_m\\times C_m$ for some $m\\ge 2$, but then $f(X)=X^m-1$ has at least $m^2$ roots, contradicting the preceding lemma.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Any finite integral domain is a field.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Consider a finite integral domain $R$ and $0\\neq a\\in\\mathbb R$.\r\n    The map $\\phi:R\\to R$ by $r\\mapsto ra$.\r\n    This map is injective since $R$ is an integral domain, but then it is automatically surjective since $R$ is finite.\r\n    So there is some $r$ such that $ra=1$.\r\n\\end{proof}\r\nCombining these two gives that every finite integral domain has cyclic multiplicative group.\r\n\\begin{theorem}\r\n    Let $R$ be an integral domain, then there is a field $F$ with the following properties:\\\\\r\n    1. $R\\le F$.\\\\\r\n    2. Every element of $F$ can be written as $ab^{-1}$ where $a,b\\in R$.\r\n\\end{theorem}\r\nConsequently, such an $F$ is the unique minimal field containing $R$.\r\n$F$ is called the field of fractions.\r\n\\begin{example}\r\n    The field of fractions of $\\mathbb Z$ is $\\mathbb Q$.\r\n\\end{example}\r\n\\begin{proof}\r\n    Consider the set $F=(R\\times R\\setminus\\{0\\})/\\sim$ where\r\n    $$(a,b)\\sim (c,d)\\iff ad=bc$$\r\n    We write the equivalence class containing $(a,b)$ as $a/b$.\r\n    One can show that this is an equivalence relation since $R$ is an integral domain and that the following operations are well-defined:\r\n    $$(a/b)+(c/d)=(ad+bc)/(bd),(a/b)(c/d)=(ac)/(bd)$$\r\n    $F$ is obviously a field under these two operations.\r\n    Also we can embed $R$ into $F$ by $r\\mapsto r/1$ and we have $a/b=(a/1)(1/b)=(a/1)(b/1)^{-1}=ab^{-1}$, so this is the field we want.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. The field of fraction of the Gaussian integers $\\mathbb Z[i]$ is the set $\\{ab^{-1}:a,b\\in\\mathbb Z[i]\\le\\mathbb C\\}$.\r\n    In fact, $F$ is exactly numbers in the form $p+iq,p,q\\in\\mathbb Q$.\\\\\r\n    2. The field of fraction of the polynomial ring $R[X]$ over a ring $R$ is called the field of fractions $R(X)$ of $R$.\r\n\\end{example}\r\n\\subsection{Prime and Maximal Ideals}\r\n\\begin{lemma}\r\n    A ring $R$ is a field iff its only ideas are $\\{0\\},R$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $S$ be a collection of subsets of a set $X$.\r\n    $A\\in S$ is maximal if there does not exists $B\\in S$ such that $A\\subsetneq B$.\\\\\r\n    An ideal $I\\unlhd R$ is maximal if it is maximal in the set of all proper ideas $\\mathcal I_R=\\{J\\unlhd R:\\{0\\}\\subsetneq J\\subsetneq R\\}$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    Let $I\\unlhd R$, then $R/I$ is a field iff $I$ is maximal.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    $R/I$ is a field iff $I/I,R/I$ are the only ideals of $R/I$, which happens iff $I$ and $R$ are the only ideals of $R$ containing $I$ iff $I$ is maximal.\r\n\\end{proof}\r\n\\begin{definition}\r\n    An ideal $I\\unlhd R$ is prime if $I\\neq R$ and $ab\\in I$ implies that at least one of $a,b$ is in $I$.\r\n\\end{definition}\r\n\\begin{example}\r\n    The prime ideals of $\\mathbb Z$ are $p\\mathbb Z$ with $p$ prime or $0$.\r\n    Incidentally (or not), $p\\mathbb Z$ are also all maximal ideals of $\\mathbb Z$.\r\n\\end{example}\r\n\\begin{proposition}\r\n    Let $I\\unlhd R$, then $I$ is prime iff $R/I$ is an integral domain.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    $I$ is prime iff $ab\\in I\\implies a\\in I\\lor b\\in I$ iff $ab+I=I\\implies a+I=I\\lor b+I=I$ iff $I$ is an integral domain.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Combining the results reveals that every maximal ideal is prime.\r\n\\end{remark}\r\n\\begin{remark}\r\n    If $\\operatorname{char}(R)=n\\ge 2$, then $\\mathbb Z/n\\mathbb Z\\le R$, hence $n$ is prime.\r\n    In particular, the characteristic of a field $F$ is either $0$ or a prime number.\r\n    When the field has characteristic $0$, then $\\mathbb Z\\le F$, hence $\\mathbb Q\\le F$ since $F$ is a field.\r\n\\end{remark}", "meta": {"hexsha": "e0f02d3a683074b5989324720d0d8612ed900d06", "size": 5582, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "9/intdom.tex", "max_stars_repo_name": "david-bai-notes/IB-Groups-Rings-and-Modules", "max_stars_repo_head_hexsha": "f4d4cc7141d30f03f775a67afc5a724db6a35da6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "9/intdom.tex", "max_issues_repo_name": "david-bai-notes/IB-Groups-Rings-and-Modules", "max_issues_repo_head_hexsha": "f4d4cc7141d30f03f775a67afc5a724db6a35da6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "9/intdom.tex", "max_forks_repo_name": "david-bai-notes/IB-Groups-Rings-and-Modules", "max_forks_repo_head_hexsha": "f4d4cc7141d30f03f775a67afc5a724db6a35da6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.1206896552, "max_line_length": 256, "alphanum_fraction": 0.6512002866, "num_tokens": 1872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8840392817460333, "lm_q1q2_score": 0.7164951922912208}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{mathtools}\n\n\\title{Bayes's theorem and logistic regression}\n\\author{Allen B. Downey}\n\n\\newcommand{\\logit}{\\mathrm{logit}}\n\\renewcommand{\\P}{\\mathrm{P}}\n\\renewcommand{\\O}{\\mathrm{O}}\n\\newcommand{\\LR}{\\mathrm{LR}}\n\\newcommand{\\LO}{\\mathrm{LO}}\n\\newcommand{\\LLR}{\\mathrm{LLR}}\n\\newcommand{\\OR}{\\mathrm{OR}}\n\\newcommand{\\LOR}{\\mathrm{LOR}}\n\\newcommand{\\IF}{\\mathrm{if}}\n\\newcommand{\\notH}{\\neg H}\n\n\\setlength{\\headsep}{3ex}\n\\setlength{\\parindent}{0.0in}\n\\setlength{\\parskip}{1.7ex plus 0.5ex minus 0.5ex}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\nMy two favorite topics in probability and statistics are\nBayes's theorem and logistic regression.  Because there are\nsimilarities between them, I have always assumed that there is\na connection.  In this note, I demonstrate the\nconnection mathematically, and (I hope) shed light on the\nmotivation for logistic regression and the interpretation of\nthe results.\n\\end{abstract}\n\n\n\\section{Bayes's theorem}\n\nI'll start by reviewing Bayes's theorem, using an example that came up\nwhen I was in grad school.  I signed up for a class on Theory of\nComputation.  On the first day of class, I was the first to arrive.  A\nfew minutes later, another student arrived.  Because I was expecting\nmost students in an advanced computer science class to be male, I was\nmildly surprised that the other student was female.  Another female\nstudent arrived a few minutes later, which was sufficiently\nsurprising that I started to think I was in the wrong room.  When\nanother female student arrived, I was confident I was in the wrong\nplace (and it turned out I was).\n\nAs each student arrived, I used the observed data to update my\nbelief that I was in the right place.  We can use Bayes's theorem to\nquantify the calculation I was doing intuitively.\n\nI'll us $H$ to represent the hypothesis that I was in the right\nroom, and $F$ to represent the observation that the first other\nstudent was female.  Bayes's theorem provides an algorithm for\nupdating the probability of $H$:\n\n\\[ \\P(H|F) = \\P(H)~\\frac{\\P(F|H)}{P(F)}\\]\n\nWhere\n\n\\begin{itemize}\n\n\\item $\\P(H)$ is the prior probability of $H$ before the other\nstudent arrived.\n\n\\item $\\P(H|F)$ is the posterior probability of $H$, updated based\non the observation $F$.\n\n\\item $\\P(F|H)$ is the likelihood of the data, $F$, assuming that\nthe hypothesis is true.\n\n\\item $P(F)$ is the likelihood of the data, independent of $H$.\n \n\\end{itemize}\n\nBefore I saw the other students, I was confident I was in the right\nroom, so I might assign $\\P(H)$ something like 90\\%.\n\nWhen I was in grad school most advanced computer science classes were\n90\\% male, so if I was in the right room, the likelihood of the\nfirst female student was only 10\\%.  And the likelihood of three\nfemale students was only 0.1\\%.\n\nIf we don't assume I was in the right room, then the likelihood of\nthe first female student was more like 50\\%, so the likelihood\nof all three was 12.5\\%.\n\nPlugging those numbers into Bayes's theorem yields $\\P(H|F) = 0.64$\nafter one female student, $\\P(H|FF) = 0.26$ after the second,\nand $\\P(H|FFF) = 0.07$ after the third.\n\n\n\\section{Logistic regression}\n\nLogistic regression is based on the following functional form:\n\n\\[ \\logit(p) = \\beta_0 + \\beta_1 x_1 + ... + \\beta_n x_n \\]\n\nwhere the dependent variable, $p$, is a probability,\nthe $x$s are explanatory variables, and the $\\beta$s are\ncoefficients we want to estimate.  The $\\logit$ function is the\nlog-odds, or\n\n\\[ \\logit(p) = \\ln \\left( \\frac{p}{1-p} \\right) \\]\n\nWhen you present logistic regression like this, it raises\nthree questions:\n\n\\begin{itemize}\n\n\\item Why is $\\logit(p)$ the right choice for the dependent\nvariable?\n\n\\item Why should we expect the relationship between $\\logit(p)$\nand the explanatory variables to be linear?\n\n\\item How should we interpret the estimated parameters?\n\n\\end{itemize}\n\nThe answer to all of these questions turns out to be Bayes's\ntheorem.  To demonstrate that, I'll use a simple example where\nthere is only one explanatory variable.  But the derivation\ngeneralizes to multiple regression.\n\nOn notation: I'll use $\\P(H)$ for the probability\nthat some hypothesis, $H$, is true.  $\\O(H)$ is the odds of the same\nhypothesis, defined as\n\n\\[ \\O(H) = \\frac{\\P(H)}{1 - \\P(H)} \\]\n\nI'll use $\\LO(H)$ to represent the log-odds of $H$:\n\n\\[ \\LO(H) = \\ln \\O(H) \\]\n\nI'll also use $\\LR$ for a likelihood ratio, and $\\OR$ for an odds\nratio.  Finally, I'll use $\\LLR$ for a log-likelihood ratio, and\n$\\LOR$ for a log-odds ratio.\n\n\n\n\n\n\\section{Making the connection}\n\nTo demonstrate the connection between Bayes's theorem and\nlogistic regression, I'll start with the odds form\nof Bayes's theorem.  Continuing the previous example,\nI could write\n\n\\begin{equation} \\label{A}\n\\O(H|F) = \\O(H)~\\LR(F|H)\n\\end{equation}\n\nwhere\n\n\\begin{itemize}\n\n\\item $\\O(H)$ is the prior odds that I was in the right room,\n\n\\item $\\O(H|F)$ is the posterior odds after seeing one female student,\n\n\\item $\\LR(F|H)$ is the likelihood ratio of the data, given\nthe hypothesis.\n\n\\end{itemize}\n\nThe likelihood ratio of the data is:\n\n\\[ \\LR(F|H) = \\frac{\\P(F|H)}{\\P(F|\\notH)} \\]\n\nwhere $\\notH$ means $H$ is false.\n\nNoticing that logistic regression is expressed in terms of\nlog-odds, my next move is to write the log-odds form of\nBayes's theorem by taking the log of Eqn~\\ref{A}:\n\n\\begin{equation} \\label{B}\n\\LO(H|F) = \\LO(H) + \\LLR(F|H)\n\\end{equation}\n\nIf the first student to arrive had been male, we would write\n\n\\begin{equation} \\label{C} \\nonumber\n\\LO(H|M) = \\LO(H) + \\LLR(M|H)\n\\end{equation}\n\nOr more generally if we use $X$ as a variable to represent\nthe sex of the observed student, we would write\n\n\\begin{equation} \\label{D}\n\\LO(H|X) = \\LO(H) + \\LLR(X|H)\n\\end{equation}\n\nI'll assign $X=0$ if the observed student is female and\n$X=1$ if male.  Then I can write:\n\n\\begin{equation} \\label{E} \\nonumber\n\\LLR(X|H) = \\left\\{\n  \\begin{array}{lr}\n    \\LLR(F|H) & \\IF ~X = 0\\\\\n    \\LLR(M|H) & \\IF ~X = 1\n  \\end{array}\n\\right.\n\\end{equation}\n\nOr we can collapse these two expressions into one by using\n$X$ as a multiplier:\n\n\\begin{equation} \\label{F}\n\\LLR(X|H) = \\LLR(F|H) + X [\\LLR(M|H) - \\LLR(F|H)]\n\\end{equation}\n\n\n\\section{Odds ratios}\n\nThe next move is to recognize that \nthe part of Eqn~\\ref{F} in brackets is the log-odds ratio\nof $H$.  To see that, we need to look more closely at odds ratios.\n\nOdds ratios are often used in medicine to describe the association\nbetween a disease and a risk factor.  In the example scenario, we\ncan use an odds ratio to express the odds of the hypothesis\n$H$ if we observe a male student, relative to the odds if we\nobserve a female student:\n\n\\[ \\OR_X(H) = \\frac{\\O(H|M)}{\\O(H|F)} \\]\n\nI'm using the notation $\\OR_X$ to represent the odds ratio\nassociated with the variable $X$.\n\nApplying Bayes's theorem to\nthe top and bottom of the previous expression yields\n\n\\[ \\OR_X(H) = \\frac{\\O(H)~\\LR(M|H)}{\\O(H)~\\LR(F|H)} = \n\\frac{\\LR(M|H)}{\\LR(F|H)}\\]\n\nTaking the log of both sides yields\n\n\\begin{equation} \\label{G}\n\\LOR_X(H) = \\LLR(M|H) - \\LLR(F|H)\n\\end{equation}\n\nThis result should look familiar, since it appears in\nEqn~\\ref{F}.\n\n\n\\section{Conclusion}\n\nNow we have all the pieces we need; we just have to assemble them.\nCombining Eqns~\\ref{F} and \\ref{G} yields  \n\n\\begin{equation} \\label{H}\n\\LLR(H|X) = \\LLR(F) + X~\\LOR(X|H)\n\\end{equation}\n\nCombining Eqns~\\ref{D} and \\ref{H} yields\n\n\\begin{equation} \\label{I}\n\\LO(H|X) = \\LO(H) + \\LLR(F|H) + X~\\LOR(X|H)\n\\end{equation}\n\nFinally, combining Eqns~\\ref{B} and \\ref{I} yields\n\n\\[ \\LO(H|X) = \\LO(H|F) + X~\\LOR(X|H) \\]\n\nWe can think of this equation as the log-odds form of Bayes's theorem,\nwith the update term expressed as a log-odds ratio.  Let's compare\nthat to the functional form of logistic regression:\n\n\\[ \\logit(p) = \\beta_0 + X \\beta_1 \\]\n\nThe correspondence between these equations suggests the following\ninterpretation:\n\n\\begin{itemize}\n\n\\item The predicted value, $\\logit(p)$, is the posterior log\nodds of the hypothesis, given the observed data.\n\n\\item The intercept, $\\beta_0$, is the log-odds of the\nhypothesis if $X=0$.\n\n\\item The coefficient of $X$, $\\beta_1$, is a log-odds ratio\nthat represents odds of $H$ when $X=1$, relative to\nwhen $X=0$.\n\n\\end{itemize}\n\nThis relationship between logistic regression and Bayes's theorem\ntells us how to interpret the estimated coefficients.  It also\nanswers the question I posed at the beginning of this note:\nthe functional form of logistic regression makes sense because\nit corresponds to the way Bayes's theorem uses data to update\nprobabilities.\n\n\\end{document}\n", "meta": {"hexsha": "0a5fb19d690f3b1b74564d47e47f6325aadce233", "size": 8566, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "DSC 530 - Data Exploration and Analysis/ThinkStats2/book/note.tex", "max_stars_repo_name": "Hakuna-Patata/BU_MSDS_PTW", "max_stars_repo_head_hexsha": "4759cb2db3e63ae5722bd42771e4d228dfbc733d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DSC 530 - Data Exploration and Analysis/ThinkStats2/book/note.tex", "max_issues_repo_name": "Hakuna-Patata/BU_MSDS_PTW", "max_issues_repo_head_hexsha": "4759cb2db3e63ae5722bd42771e4d228dfbc733d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DSC 530 - Data Exploration and Analysis/ThinkStats2/book/note.tex", "max_forks_repo_name": "Hakuna-Patata/BU_MSDS_PTW", "max_forks_repo_head_hexsha": "4759cb2db3e63ae5722bd42771e4d228dfbc733d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.4584717608, "max_line_length": 70, "alphanum_fraction": 0.7153864114, "num_tokens": 2600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254319, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7164951823866811}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Moments}\\label{sec:moments}\n\n%-----------------------------\n\\subsection{Expectation of transformed variables}\\label{sec:expe_transformed}\n\nLet $X$ be a random variable and let $g:\\R\\to\\R$ be a transformation. \n\n\\ben\n\\it If $g$ is a \\emph{non-negative} function, the expected value of $g(X)$ is\n\\[\n\\expe\\big[g(X)\\big] = \\begin{cases}\n\t\\displaystyle\\sum_{i=1}^{\\infty} g(x_i)f(x_i)\t\t& \\text{if $g(X)$ is discrete, and} \\\\[3ex]\n\t\\displaystyle\\int_{-\\infty}^{\\infty} g(x)f(x)\\,dx\t& \\text{if $g(X)$ is continuous.} \n\\end{cases}\n\\]\n\n\\it If $g$ is a \\emph{signed function}, the expected value of $g(X)$ is\n\\[\n\\expe\\big[g(X)\\big] = \\expe\\big[g^{+}(X)\\big] - \\expe\\big[g^{-}(X)\\big],\n\\]\nprovided $\\expe\\big[g^{+}(X)\\big]$ and $\\expe\\big[g^{-}(X)\\big]$ are not both infinite, where $g^{+}$ and $g^{-}$ are respectively the positive and negative parts of $g$, \n\\[\ng^{+}(x)\t= \\begin{cases}  g(x) & \\text{ if } g(x)\\geq 0, \\\\ 0 & \\text{otherwise,}\\end{cases}\n\\qquad\\text{and}\\qquad\ng^{-}(x)\t= \\begin{cases} -g(x) & \\text{ if } g(x)<0, \\\\ 0 & \\text{otherwise.}\\end{cases}\n\\]\n\\een\n\n\\begin{example}\nFor $X\\sim\\text{Uniform}[-1,1]$ find $\\expe(1/X^2)$ and $\\expe(1/X)$.\n\\begin{solution}\nThe PDF of $X$ is $f(x)=1/2$ for $x\\in[-1,1]$ and zero otherwise.\n\\ben\n\\it Let $g(x) = 1/x^2$. This is a non-negative function, so\n\\begin{align*}\n\\expe\\left(\\frac{1}{X^2}\\right) \n\t= \\int_{-\\infty}^{\\infty} g(x)f(x)\\,dx \n\t= \\frac{1}{2}\\int_{-1}^{1} \\frac{1}{x^2}\\,dx\n\t= \\int_{0}^{1}\\frac{1}{x^2}\\,dx\n\t= \\infty,\n\\end{align*}\n%so $\\expe(1/X^2)$ is infinite.\n\n\\it Let $g(x) = 1/x$. This is a signed function, so we must consider its positive and negative parts separately:\n\\[\ng^{+}(x)\t= \\begin{cases}  1/x & \\text{ if}\\quad x\\geq 0, \\\\ 0 & \\text{ if}\\quad x < 0,\\end{cases}\n\\qquad\\text{and}\\qquad\ng^{-}(x)\t= \\begin{cases}  0 & \\text{ if}\\quad x\\geq 0, \\\\ -1/x & \\text{ if}\\quad x < 0.\\end{cases}\n\\]\nThus\n\\begin{align*}\n\\expe\\left(\\frac{1}{X}\\right)\n\t& = \\int_{0}^{\\infty} g^{+}(x)f(x)\\,dx - \\int_{0}^{\\infty} g^{-}(x) f(x)\\,dx \\\\\n\t& = \\frac{1}{2}\\int_0^1 \\frac{1}{x}\\,dx - \\frac{1}{2}\\int_{-1}^0 \\frac{-1}{x}\\,dx \\\\\n\t& = \\frac{1}{2}\\int_0^1 \\frac{1}{x}\\,dx - \\frac{1}{2}\\int_{0}^{1} \\frac{1}{x}\\,dx \\\\\n\t& = \\infty - \\infty,\n\\end{align*}\nso $\\expe(1/X)$ is undefined.\n\\een\n\\end{solution}\n\\end{example}\n\n%-----------------------------\n\\subsection{Moments}\n\nWe now consider transformations of the form $g(x)=x^k$ for various values of $k\\in\\Z$.\n% definition: raw moments\n\\begin{definition}\nThe expectation $\\expe(X^{k})$ is called the \\emph{$k$th moment about the origin} of $X$.\n\\end{definition}\n\n%In particular,\n\\bit\n\\it $\\expe(X^0) = 1$,\n\\it $\\expe(X)$ is the \\emph{mean} of $X$, often denoted by $\\mu$,\n\\it $\\expe(X^2)$ is the \\emph{mean-square} of $X$.\n\\eit\n\n% definition: central moments\n\\begin{definition}\nThe expectation $\\expe\\big[(X-\\mu)^{k}\\big]$ is called the \\emph{$k$th moment about the mean} of $X$.\n\\end{definition}\n\n%In particular,\n\\bit\n\\it $\\expe\\big[(X-\\mu)^{0}\\big] = 1$,\n\\it $\\expe\\big[(X-\\mu)\\big] = 0$,\n\\it $\\expe\\big[(X-\\mu)^2\\big]$ is the \\emph{variance} of $X$, often denoted by $\\sigma^2$.\n\\it $\\expe\\big[(X-\\mu)^2\\big]^{1/2}$ is the \\emph{standard deviation} of $X$, often denoted by $\\sigma$.\n%\\it $\\sqrt{\\mu_2}$ is the \\emph{standard deviation} of $X$, denoted by $\\sigma$.\n\\eit\n\n\n%-----------------------------\n\\subsection{Location, scale and shape} \n\nWhen trying to describe a distribution, it is natural to look for its \\emph{location}, \\emph{scale} (size) and \\emph{shape}.\n\n%% mean and variance\n%For any random variable $X:\\Omega\\to\\R$,\n%\\ben\n%\\it the first moment of $X$ about the origin ($\\mu$)  describes its location, \n%\\it the second moment of $X$ about the mean ($\\sigma^2$) describes its scale, and\n%\\it the higher moments of $X$ describe the shape of its distribution.\n%\\een\n\n\\paragraph{Location}\nTo locate $X$, we look for a point $c\\in\\R$ such that the expected squared deviation $\\expe\\big[(X-c)^2\\big]$ around this point is minimum. By the linearity of expectation,\n\\[\n\\expe\\big[(X-c)^2\\big] = \\expe(X^2 - 2cX + c^2) = \\expe(X^2) - 2c\\expe(X) + c^2\n\\]\nTo find the value of $c$ that minimises the expected squared deviation, we differentiate the right-hand side with respect to $c$ and set the resulting expression to zero. This yields $c=\\expe(X)$, so the location of $X$ is described by its \\emph{expectation} (or first moment about the origin), $\\mu$. \n\n\\paragraph{Scale}\nThe size of a distribution should not depend on its location, so we consider the \\emph{centred} variable \n\\[\nY=X-\\expe(X),\n\\]\nwhich has the property $\\expe(Y)=0$. The expected squared deviation of $X$ around its mean $\\expe(X)$ is its \\emph{variance} (or second moment about the mean), so the size of $X$ is described by its \\emph{standard deviation}, $\\sigma$.\n\n\\paragraph{Shape}\nThe shape of a distribution should not depend on its location nor its scale. Thus we consider the higher moments of the so-called \\emph{standardised} variable,\n\\[\nZ = \\frac{X-\\mu}{\\sigma},\n\\]\nwhich has the properties $\\expe(Z)=0$ and $\\var(Z)=1$.\n\n% definition\n\\begin{definition}\nThe \\emph{skewness} of a random variable $X$ is defined to be\n\\[\n\\gamma_1 = \\expe\\left[\\left(\\frac{X-\\mu}{\\sigma}\\right)^3\\right] %= \\frac{\\mu_{3}}{\\sigma^3}\n\\]\n%where $\\mu_3$ is the third central moment of $X$, and $\\sigma$ is its standard deviation. \n\\end{definition}\n\nSkewness is a measure of \\emph{asymmetry}:\n\\bit\n\\it Negative skew ($\\gamma_1 < 0$): long tail on the left, mass concentrated on the right.\n\\it Positive skew ($\\gamma_1 > 0$): long tail on the right, mass concentrated on the left.\n\\eit\n\n% example: skewness of binomial\n\\begin{example}\\label{ex:skewness_binomial}\nIf $X\\sim\\text{Binomial}(n,p)$, some tedious algebra shows that the skewness of $X$ is \n\\[\n\\gamma_1 = \\frac{1-2p}{\\sqrt{np(1-p)}} = \\begin{cases}\n\t< 0 \t& \\text{if } p > \\frac{1}{2} \\\\\n\t= 0 \t& \\text{if } p = \\frac{1}{2} \\\\\n\t> 0 \t& \\text{if } p < \\frac{1}{2} \\\\\n\\end{cases}\t\n\\]\n\\end{example}\n\n% definition: kurtosis\n\\begin{definition}\nThe \\emph{excess kurtosis} of a random variable $X$ is defined to be\n\\[\n\\gamma_2 = \\expe\\left[\\left(\\frac{X-\\mu}{\\sigma}\\right)^4\\right] -3.%= \\frac{\\mu_{4}}{\\sigma^4},\n\\]\n%and the \\emph{excess kurtosis} is $\\gamma_2 = \\beta_2 - 3$.\n\\end{definition}\n\nKurtosis is a measure of \\emph{peakiness}. The normal distribution has $\\gamma_2=0$, so excess kurtosis provides a measure of peakiness relative to that of the normal distribution.\n\\bit\n\\it Negative excess kurtosis ($\\gamma_2 < 0$): tall and peaky with heavy tails (\\emph{leptokurtic}),\n\\it Positive excess kurtosis ($\\gamma_2 > 0$): low and wide with light tails (\\emph{platykurtic}).\n\\eit\n\n\\begin{example}\\label{ex:kurtosis_binomial}\nIf $X\\sim\\text{Binomial}(n,p)$ some more tedious algebra shows that the excess kurtosis of $X$ is\n\\[\n\\gamma_2 = \\frac{1-6p(1-p)}{np(1-p)} = \\begin{cases}\n\t< 0 \t\t\t\t& \\text{if } \\left|p -\\frac{1}{2}\\right| < \\frac{1}{2\\sqrt{3}} \\\\\n\t> 0 \t\t\t\t& \\text{if } \\left|p -\\frac{1}{2}\\right| > \\frac{1}{2\\sqrt{3}} \\\\\n\\end{cases}\n\\]\n\\end{example}\n\n% exercises: moments\n\\begin{exercise}\n\\begin{questions}\n\n\\question\nLet $X$ be a continuous random variable with uniform density on the interval $[-1,1]$,\n\\[\nf(x) = \\begin{cases}\n\t\\frac{1}{2}\t& \\text{ if } x\\in[-1,+1] \\\\\n\t0\t\t\t& \\text{ otherwise.}\n\\end{cases}\n\\]\nCompute the moments $\\expe(X)$, $\\expe(X^2)$, $\\expe(X^3)$, $\\expe(1/X)$ and $\\expe(1/X^2)$.\n\\begin{answer}\nSince $xf(x)$, $x^2f(x)$ and $x^3f(x)$ are continuous and bounded over $\\supp(f)=[-1,1]$, the first three expectations can be computed using definite integrals. This is not the case for$\\expe(1/X)$ and $\\expe(1/X^2)$.\n\n\\ben\n\\it % << (i)\n$\\displaystyle\\expe(X) = \\frac{1}{2}\\int_{-1}^1 x\\,dx = 0.$\n%Let $g(x) = x$. This is a signed function, so\n%\\begin{align*}\n%\\expe(X) \n%\t& = \\int_{-\\infty}^{\\infty} g^{+}(x)f(x)\\,dx - \\int_{-\\infty}^{\\infty} g^{-}(x) f(x)\\,dx \\\\\n%\t& = \\frac{1}{2}\\int_0^1 x\\,dx - \\frac{1}{2}\\int_{-1}^0 (-x)\\,dx \\\\\n%\t& = \\frac{1}{2}\\left[\\frac{x^2}{2}\\right]_0^1 - \\frac{1}{2}\\left[\\frac{-x^2}{2}\\right]_{-1}^0\n%\t= \\left(\\frac{1}{4}-0\\right) - \\left(0 + \\frac{1}{4}\\right)\n%\t= 0.\n%\\end{align*}\n%\n\\it % << (ii)\n$\\displaystyle\\expe(X^2) = \\frac{1}{2}\\int_{-1}^1 x^2\\,dx = \\frac{1}{3}.$\n%Let $g(x) = x^2$. This is a non-negative function, so\n%\\begin{align*}\n%\\expe(X^2) \n%\t& = \\int_{-\\infty}^{\\infty} g(x)f(x)\\,dx \\\\\n%\t& = \\frac{1}{2}\\int_{-1}^{1} x^2\\,dx\n%\t= \\int_{0}^{1} x^2\\,dx\n%\t= \\left[\\frac{x^3}{3}\\right]_0^1\n%\t= \\frac{1}{3}.\n%\\end{align*}\n%\n\\it % << (iii)\n$\\displaystyle\\expe(X^3) = \\frac{1}{2}\\int_{-1}^1 x^3\\,dx = 0.$\n%Let $g(x) = x^3$. This is a signed function, so\n%\\begin{align*}\n%\\expe(X^3) \n%\t& = \\int_{-\\infty}^{\\infty} g^{+}(x)f(x)\\,dx - \\int_{-\\infty}^{\\infty} g^{-}(x) f(x)\\,dx \\\\\n%\t& = \\frac{1}{2}\\int_0^1 x^3\\,dx - \\frac{1}{2}\\int_{-1}^0 (-x^3)\\,dx \\\\\n%\t& = \\frac{1}{2}\\left[\\frac{x^4}{4}\\right]_0^1 - \\frac{1}{2}\\left[\\frac{-x^4}{4}\\right]_{-1}^0 \n%\t= \\left(\\frac{1}{8}-0\\right) - \\left(0 + \\frac{1}{8}\\right) \n%\t= 0.\n%\\end{align*}\n\n\\it % << (iv)\nLet $g(x) = 1/x$. This is a signed function, so\n\\begin{align*}\n\\expe\\left(\\frac{1}{X}\\right)\n\t& = \\int_{-\\infty}^{\\infty} g^{+}(x)f(x)\\,dx - \\int_{-\\infty}^{\\infty} g^{-}(x) f(x)\\,dx \\\\\n\t& = \\frac{1}{2}\\int_0^1 \\frac{1}{x}\\,dx - \\frac{1}{2}\\int_{-1}^0 \\frac{-1}{x}\\,dx \\\\\n\t& = \\frac{1}{2}\\int_0^1 \\frac{1}{x}\\,dx - \\frac{1}{2}\\int_{0}^{1} \\frac{1}{x}\\,dx \n\t= \\infty - \\infty\n\\end{align*}\nso $\\expe(1/X)$ is undefined.\n\n\\it % << (v)\nLet $g(x) = 1/x^2$. This is a non-negative function, so\n\\begin{align*}\n\\expe\\left(\\frac{1}{X^2}\\right)\n\t& = \\int_{-\\infty}^{\\infty} g(x)f(x)\\,dx \\\\\n\t& = \\frac{1}{2}\\int_{-1}^{1} \\frac{1}{x^2}\\,dx\n\t= \\int_{0}^{1}\\frac{1}{x^2}\\,dx\n\t= \\infty\n\\end{align*}\nso $\\expe(1/X^2)$ is infinite.\n\\een\n\\end{answer} \n\n\\question\nLet $X$ be a continuous random variable with the following PDF:\n\\[\nf(x) = \\begin{cases}\n\t1-|x|\t& \\text{ if } x\\in[-1,1] \\\\\n\t0\t\t& \\text{ otherwise.}\n\\end{cases}\n\\]\nFor what values of $k\\in\\Z$ do the moments $\\expe(X^{k})$ exist?  \n\\begin{answer}\nFor $k>0$,\n\\[\n\\expe(X^{k}) = \\int_{-1}^{0}x^{k}(1+x)\\,dx + \\int_{0}^{1}x^{k}(1-x)\\,dx < \\infty\n\\]\nLet $k < 0$. If $k$ is even then $X^k$ is non-negative, so\n\\begin{align*}\n\\expe(X^k)\n\t& = \\expe\\big((X^{+})^{k}\\big) = +\\infty\\\\\n\\intertext{If $k$ is odd,}\n\\expe(X^k)\n\t& = \\expe\\big((X^{+})^{k}\\big) - \\expe\\big((X^{-})^{k}\\big) \n\t\t= \\infty - \\infty \n\\end{align*}\nso in this case the moment $\\expe(X^k)$ does not exist.\n\\end{answer} \n\n\\question\nLet $X$ be a discrete random variable with the following PMF:\n\\[\n\\prob(X=x) = \\frac{45}{\\pi^4x^4} \\qquad\\text{for $x=\\pm 1,\\pm 2,\\pm 3\\ldots$ (and zero otherwise).}\n\\]\n\\begin{parts}\n\\part For what values of $k\\in\\Z$ do the moments $\\expe(X^{k})$ exist?  \n\\begin{answer}\nLet $c = 45/\\pi^4$.\n\\bit\n\\it If $k\\leq 2$ then $\\expe(X^k)$ exists and is finite because \n\\[\n\\expe(X^k) \n\t= c\\sum_{x\\neq 0}\\frac{x^k}{x^4} \n\t= 2c\\sum_{x=1}^{\\infty}\\frac{1}{x^{4-k}}\n\t< \\infty.\n\\]\n\\it If $k>2$ and $k$ is even, $\\expe(X^k)$ is infinite because\n\\[\n\\expe(X^k) \n\t= c\\sum_{x\\neq 0}\\frac{x^k}{x^4} \n\t= c\\sum_{x=1}^{\\infty}\\frac{1}{x^{4-k}} \n\t= \\infty.\n\\]\nIf $k>2$ and $k$ is odd, $\\expe(X^k)$ does not exist because\n\\[\n\\expe(X^k) \n\t= c\\sum_{x\\neq 0}\\frac{x^k}{x^4} \n\t= c\\sum_{x=1}^{\\infty}\\frac{1}{x^{4-k}} - c\\sum_{x=1}^{\\infty}\\frac{1}{x^{4-k}} \n\t= \\infty - \\infty.\n\\]\n\\eit\n\\end{answer}\n\\part Compute the variance of $X$ and its first negative moment $\\expe(X^{-1})$.\n\\begin{answer}\nThe first two moments of $X$ are\t\n\\begin{align*}\n\\expe(X) \n\t& = c\\sum_{x\\neq 0}\\frac{1}{x^3} \n\t  = c\\sum_{x=1}^{\\infty}\\frac{1}{x^3} - c\\sum_{x=1}^{\\infty}\\frac{1}{x^3} = 0 \\\\\n\\expe(X^2)\n\t& = c\\sum_{x\\neq 0}\\frac{1}{x^2} \n\t  = 2c\\sum_{x=1}^{\\infty}\\frac{1}{x^2}\n\t  = 2\\left(\\frac{45}{\\pi^4}\\right)\\left(\\frac{\\pi^2}{6}\\right) = \\frac{15}{\\pi^2},\n\\end{align*}\nso $\\var(X)=15/\\pi^2$. Similarly,\n\\begin{align*}\n\\expe\\left(\\frac{1}{X}\\right) \n\t& = c\\sum_{x\\neq 0}^{\\infty}\\frac{1}{x^5} \\\\\n\t& = c\\sum_{n=1}^{\\infty}\\frac{1}{n^5} - c\\sum_{x=1}^{\\infty}\\frac{1}{x^5} \\\\\n\t& = 0.\n\\end{align*}\nIn fact, all negative odd-integer moments are zero.\n\\end{answer}\n\\end{parts}\n\n\\end{questions}\n\\end{exercise}\n\n", "meta": {"hexsha": "5e552096df87b964daa977dacd37615c5960c7a0", "size": 12111, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/04D_moments.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/04D_moments.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/04D_moments.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 35.1043478261, "max_line_length": 302, "alphanum_fraction": 0.598299067, "num_tokens": 5043, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788903594354, "lm_q2_score": 0.8840392863287585, "lm_q1q2_score": 0.7164951798178794}}
{"text": "\\subsection{Analytic Maps}\r\n\\begin{definition}\r\n    Let $R$ and $S$ be Riemann surfaces.\r\n    A continuous map $f:R\\to S$ is analytic or holomorphic if for any chart $(\\phi,U)$ on $R$ and $(\\psi,V)$ on $S$, the map $\\psi\\circ f\\circ \\phi^{-1}$ is analytic on $\\phi(U\\cap f^{-1}(V))$.\r\n\\end{definition}\r\n\\begin{lemma}\\label{analytic_local}\r\n    A continuous map $f:R\\to S$ of Riemann surfaces is analytic iff for each $p\\in R$, there is a chart $\\phi_p,U_p$ on $R$ with $p\\in U_p$ and a chart $(\\psi_p,V_p)$ on $V$ with $f(p)\\in V_p$ such that $\\psi_p\\circ f\\circ \\phi_p^{-1}$ is analytic on $\\phi_p(U_p\\cap f^{-1}(V_p))$\r\n\\end{lemma}\r\nThe key point of the proof is basically that the function we want to be analytic can be written as a composition of local analytic functions composed with transition maps.\r\n\\begin{proof}\r\n    The ``only if'' direction is immediate.\r\n    For the ``if'' direction, given charts $(\\phi,U)$ on $R$ and $(\\psi,V)$ on $S$, it suffices to show that $\\psi\\circ f\\circ\\phi^{-1}$ is analytic at $\\phi(p)$ for any $p\\in U\\cap f^{-1}(V)$.\r\n    We know from hypothesis that there is some charts $(\\phi_p,U_p)$ on $R$ and $(\\psi_p,V_p)$ on $S$ with $p\\in U_p,f(p)\\in V_p$ and $\\psi_p\\circ f\\circ\\phi_p^{-1}$ is analytic on $\\phi_p(U\\cap f^{-1}(V))$, hence in particular at $\\phi_p(p)$.\r\n    Hence\r\n    $$\\psi\\circ f\\circ\\phi^{-1}=(\\psi\\circ\\psi_p^{-1})\\circ(\\psi_p\\circ f\\circ\\phi_p^{-1})\\circ (\\phi_p\\circ\\phi^{-1})$$\r\n    is analytic at $\\phi(p)$.\r\n\\end{proof}\r\n\\begin{lemma}\\label{analytic_compose}\r\n    If $f:R\\to S$ and $g:S\\to T$ are analytic, so is $g\\circ f:R\\to T$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Simple corollary of Lemma \\ref{analytic_local}.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A conformal equivalence or biholomorphism is an analytic bijection of Riemann surfaces with analytic inverse.\r\n\\end{definition}\r\nIt is an equivalence relation by Lemma \\ref{analytic_compose}.\r\n\\begin{example}\r\n    The map $f:\\mathbb C\\to\\bar{\\mathbb C}$ with $z\\mapsto \\bar{z}$ is a conformal equivalence.\r\n\\end{example}", "meta": {"hexsha": "4854dddceaa37febbb40837faf5802f17806e29f", "size": 2035, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/map.tex", "max_stars_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_stars_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3/map.tex", "max_issues_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_issues_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3/map.tex", "max_forks_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_forks_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.8333333333, "max_line_length": 281, "alphanum_fraction": 0.6638820639, "num_tokens": 673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.8840392756357326, "lm_q1q2_score": 0.7164951792451794}}
{"text": "\n\\subsection{Probability of null}\n\n\\(P(\\Omega )=1\\)\n\n\\(P(\\Omega \\lor \\varnothing )=1\\)\n\n\\(P(\\Omega )+P(\\varnothing )=1\\)\n\n\\(P(\\varnothing )=0\\)\n\n\\subsection{Monotonicity}\n\nConsider \\(E_i\\subseteq E_j\\):\n\n\\(E_j=E_i\\lor E_k\\)\n\n\\(P(E_j)=P(E_i\\lor E_k)\\)\n\nDisjoint so:\n\n\\(P(E_j)=P(E_i)+P(E_k)\\)\n\nWe know that \\(P(E_k)\\ge 0\\) from axiom \\(1\\) so:\n\n\\(P(E_j)\\ge P(E_i)\\)\n\n\\subsection{Bounds of probabilities}\n\nAs all events are subsets of the sample space:\n\n\\(P(\\Omega )\\ge P(E)\\)\n\n\\(1\\ge P(E)\\)\n\nFrom axiom \\(1\\) then know:\n\n\\(\\forall E\\in F [0\\le P(E)\\le 1]\\)\n\n\\subsection{Union and intersection for null and universal}\n\n\\(P(E\\land \\varnothing )=P(\\varnothing )=0\\)\n\n\\(P(E\\lor \\Omega )=P(\\Omega )=1\\)\n\n\\(P(E\\lor \\varnothing)=P(E)\\)\n\n\\(P(E\\land \\Omega )=P(E)\\)\n\n\\subsection{Separation rule}\n\nFirstly:\n\n\\(P(E_i)=P(E_i\\land \\Omega)\\)\n\n\\(P(E_i)=P(E_i\\land (E_j\\lor E_j^C))\\)\n\n\\(P(E_i)=P((E_i\\land E_j)\\lor (E_i\\land E_j^C))\\)\n\nAs the latter are disjoint:\n\n\\(P(E_i)=P((E_i\\land E_j)+(E_i\\land E_j^C))\\)\n\n\\subsection{Addition rule}\n\nWe know that:\n\n\\(P(E_i\\lor E_j)=P((E_i\\lor E_j)\\land (E_j\\lor E_j^C))\\)\n\nBy the distributive law of sets:\n\n\\(P(E_i\\lor E_j)=P((E_i\\land E_j^C)\\lor E_j)\\)\n\n\\(P(E_i\\lor E_j)=P((E_i\\land E_j^C)\\lor (E_j\\land (E_i\\lor E_i^C))\\)\n\nBy the distributive law of sets:\n\n\\(P(E_i\\lor E_j)=P((E_i\\land E_j^C)\\lor (E_j\\land E_i)\\lor (E_j\\land E_i^C))\\)\n\nAs these are disjoint:\n\n\\(P(E_i\\lor E_j)=P(E_i\\land E_j^C)+ P(E_j\\land E_i)+P(E_j\\land E_i^C)\\)\n\nFrom the separation rule:\n\n\\(P(E_i\\lor E_j)=P(E_i)-P(E_i\\land E_j)+ P(E_j\\land E_i)+P(E_j)-P(E_j\\land E_i)\\)\n\n\\(P(E_i\\lor E_j)=P(E_i)+P(E_j)-P(E_i\\land E_j)\\)\n\n\\subsection{Probability of complements}\n\nFrom the addition rule:\n\n\\(P(E_i\\lor E_j)=P(E_i)+P(E_j)-P(E_i\\land E_j)\\)\n\nConsider \\(E\\) and \\(E^C\\):\n\n\\(P(E\\lor E^C)=P(E)+P(E^C)-P(E\\land E^C)\\)\n\nWe know that \\(E\\) and \\(E^C\\) are disjoint, that is:\n\n\\(E\\land E^C=\\varnothing\\)\n\nSimilarly by construction:\n\n\\(E\\lor E^C=\\Omega \\)\n\nSo:\n\n\\(P(\\Omega )=P(E)+P(E^C)-P(\\varnothing)\\)\n\n\\(1=P(E)+P(E^C)\\)\n\n", "meta": {"hexsha": "b4a011ad6433d2cdc331f52d0e700b7511a2abe6", "size": 2008, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityAxioms/03-01-basicResults.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/probabilityAxioms/03-01-basicResults.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/probabilityAxioms/03-01-basicResults.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.6140350877, "max_line_length": 81, "alphanum_fraction": 0.6155378486, "num_tokens": 820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894717137996, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7164507714331017}}
{"text": "\n\\subsection{Priors of trees}\n\n\\subsubsection{Priors for simple trees}\n\nWe can define a tree as a set of nodes: \\(T\\).\n\nFor each node we define a splitting variable \\(k\\) and a splitting threshold \\(r\\).\n\nOur prior is \\(P(T, k, r)\\).\n\nWe split this up to:\n\n\\(P(T, k, r)=P(T)P(k, r|T)\\)\n\n\\(P(T, k, r)=P(T)P(k|T)P(r|T, k)\\)\n\nSo we want to estimate:\n\n\\begin{itemize}\n\\item \\(P(T)\\) - The number of nodes.\n\\item \\(P(k|T)\\) - Which variables we split by, given the tree size.\n\\item \\(P(r|T, k)\\) - The cutoff, given the tree size and the variables we are splitting by.\n\\end{itemize}\n\n\\subsubsection{Priors for mixed trees}\n\nIf at the leaf we have a parametric model, our prior is instead:\n\n\\(P(T, k, r, \\theta )=P(T)P(k|T)P(r|T, k)P(\\theta | T, k, r)\\)\n\nWe then need to additionally estimate \\(P(\\theta | T, k, r)\\).\n\n", "meta": {"hexsha": "5cec1dcf3e7eec370a61b60f7cbce77625e327a0", "size": 813, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/treesBayesian/01-01-priors.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/treesBayesian/01-01-priors.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/treesBayesian/01-01-priors.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.9117647059, "max_line_length": 92, "alphanum_fraction": 0.6408364084, "num_tokens": 275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802373309982, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7164080641418856}}
{"text": "\\section{Adaptive Step Sizes}\n\n\\begin{enumerate}[label=\\alph*), leftmargin=*]\n\n%% a)\n\\item\n%\n\nLet a Moving Average process $x(n)$ of order $q=1$, MA(1), such that:\n\n\\begin{equation}\n    x(n) = 0.9 \\eta(n - 1) + \\eta(n), \\quad \\eta \\sim \\mathcal{N}(0, 0.5)\n\\end{equation}\n\nWhen LMS is used with a constant step-size $\\mu$, a trade-off between convergence speed, smoothness and oscillations magnitude at steady-state is inevitable.\nGradient Adaptive Step-Size (GASS) algorithms attempt to combine the positive aspects of both\nlarge and small values of $\\mu$ by adapting its magnitude according to the gradient $\\nabla_{\\mu} \\mathcal{J}$, where $\\mathcal{J}$ the objective function\nminimised by the adaptive filter.\n\nDifferent GASS algorithms, namely Benvenist, Ang \\& Farhan and Matthews \\& Xi, are implemented and their performance is compared to simple constant step-size LMS algorithm.\nWeight error and squared prediction error curves are provided at figure \\ref{fig:3_2_a}.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-step-sizes/assets/a/weight_error_curves}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-step-sizes/assets/a/squared_prediction_error}\n    \\end{subfigure}\n    \\caption{GASS LMS: weight error and squared prediction error curves.}\n    \\label{fig:3_2_a}\n\\end{figure}\n\nAll GASS algorithms converge to the true process parameters faster than simple LMS (within less than 50 steps), while unsurprisingly,\nthe most computationally intensive algorithm, Benvenist ($\\mathcal{O}(M^{2})$), adapts first of all and scores the smallest squared prediction error.\nMoreover, their steady-state error is much smaller (below $-300dB$) than the fixed step-size LMS algorithm (at $-200dB,\\ -120dB,\\ -30dB$ for $\\mu = 0.1,\\ 0.05,\\ 0.01$, respectively),\nimproving the EMSE from the previous part.\n\n%% b)\n\\item\n%\n\nStarting from the update equation based on the \\textit{a posteriori error} $e_{p}(n) = d(n) - \\mathbf{x}(n)^{T} \\vw(n + 1)$:\n\n\\begin{equation}\n    \\vw(n + 1) = \\vw(n) + \\mu e_{p}(n) \\mathbf{x}(n)\n\\label{eq:nlms_a_error}\n\\end{equation}\n\nMultiply both sides with $-\\mathbf{x}(n)^{T}$ and add $d(n)$ to construct $e_{p}(n)$ on the LHS:\n\n\\begin{equation}\n    d(n) - \\mathbf{x}(n)^{T} \\vw(n + 1) = d(n) - \\mathbf{x}(n)^{T} \\vw(n) - \\mathbf{x}(n)^{T} \\mu e_{p}(n) \\mathbf{x}(n)\n\\end{equation}\n\nNote that the LHS term is the a posteriori error, $e_{p}(n)$, while the first RHS term the a priori error, $e(n)$:\n\n\\begin{align}\n    e_{p}(n)    &= e(n) - \\mu e_{p}(n) \\| \\mathbf{x}(n) \\|^{2} \\\\\n    e_{p}(n)    &= e(n) \\frac{1}{1 + \\mu \\| \\mathbf{x}(n) \\|^{2}}\n                % &= e(n) \\bigg[ \\frac{1 + \\mu \\| \\mathbf{x}(n) \\|^{2} - \\mu \\| \\mathbf{x}(n) \\|^{2} }{1 + \\mu \\| \\mathbf{x}(n) \\|^{2}} \\bigg] \\\\\n                % &= e(n) \\bigg[ 1 - \\mu \\frac{\\| \\mathbf{x}(n) \\|^{2}}{1 + \\mu \\| \\mathbf{x}(n) \\|^{2}} \\bigg]\n\\label{eq:aa_errors}\n\\end{align}\n\nSubstituting (\\ref{eq:aa_errors}) in update equation (\\ref{eq:nlms_a_error}):\n\n\\begin{align}\n    \\vw(n + 1)  &= \\vw(n) + \\mu \\frac{1}{1 + \\mu \\| \\mathbf{x}(n) \\|^{2}} e(n) \\mathbf{x}(n) \\\\\n    \\vw(n + 1)  &= \\vw(n) + \\frac{1}{\\frac{1}{\\mu} + \\| \\mathbf{x}(n) \\|^{2}} e(n) \\mathbf{x}(n) \\\\\n    \\vw(n + 1)  &= \\vw(n) + \\frac{\\beta}{\\epsilon + \\| \\mathbf{x}(n) \\|^{2}} e(n) \\mathbf{x}(n) \\label{eq:nlms}\n\\end{align}\n\nwhere for $\\beta = 1$ and $\\epsilon = \\frac{1}{\\mu}$ we showed that the NLMS update (\\ref{eq:nlms}) is equivalent to the update equation based on the \\textit{a posteriori error},\ngiven by (\\ref{eq:nlms_a_error}).\n\n%% c)\n\\item\n%\n\nThe implementation of Generalized Nnormalized Gradient Descent (GNGD) algorithm is compared with the the Benvenist GASS algorithm, and the weight error and squared prediction error curves\nare provided at figure \\ref{fig:3_2_c}. We notice that the GNGD algorithm converges to the true process parameters within 30 timesteps,\nfaster than the Benvenist GASS algorithm which reaches a steady-state in 50 timesteps. This is also reflected in the squared prediction error curves,\nwhere the GNGD error is always smaller than the Benvenist GASS prediction error.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-step-sizes/assets/c/weight_error_curves}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/adaptive-step-sizes/assets/c/squared_prediction_error}\n    \\end{subfigure}\n    \\caption{GNGD vs Benvenist GASS: weight error and squared prediction error curves.}\n    \\label{fig:3_2_c}\n\\end{figure}\n\nIn the previous part we empirically showed the superiority of the Benvenist GASS algorithm over the other GASS algorithms and the standard LMS, in terms of performance (speed \\& prediction error).\nNonetheless, this improved performance comes with an increased computational complexity load.\n\nLet $M$ the model order (number of lags in MA or AR model process), then the input vector $\\mathbf{x}(n) \\in \\sR^{M}$.\n\nEach update of the Benvenist GASS algorithm involves the calculation of \n\\begin{itemize}\n    \\item the outer product $\\mathbf{x}(n-1) \\mathbf{x}(n-1)^{T}$\n    \\item the matrix product $\\big[I - \\mu(n-1) \\mathbf{x}(n-1) \\mathbf{x}(n-1)^{T} \\big] \\boldsymbol{\\psi}(n - 1)$\n\\end{itemize}\n\nwhich both have quadratic complexity in $M$. Hence Benvenist GASS algorithm is $\\mathbf{\\mathcal{O}(M^{2})}$.\n\nEach update of the GNGD algorithm involves only inner product calculations, additions of $M$-dimensional vectors and scalar operations, all bounded by linear complexity in $M$.\nTherefore, GNGD algorithm is $\\mathbf{\\mathcal{O}(M)}$.\n\nSurprisingly, the GNGD algorithm does not only perform better (convergence speed and prediction error) than the Benvenist GASS algorithm, but it is also computationally less expensive.\n\n%\n\\end{enumerate}", "meta": {"hexsha": "ad32dd21f723d198150ab5178f721940ca33c338", "size": 6112, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/adaptive-signal-processing/adaptive-step-sizes/index.tex", "max_stars_repo_name": "filangel/ASPMI", "max_stars_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-02-20T14:43:34.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-13T21:13:02.000Z", "max_issues_repo_path": "tex/report/adaptive-signal-processing/adaptive-step-sizes/index.tex", "max_issues_repo_name": "AmjadHisham/ASPMI", "max_issues_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/report/adaptive-signal-processing/adaptive-step-sizes/index.tex", "max_forks_repo_name": "AmjadHisham/ASPMI", "max_forks_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-07-17T08:32:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-12T18:26:18.000Z", "avg_line_length": 49.2903225806, "max_line_length": 196, "alphanum_fraction": 0.6870091623, "num_tokens": 1908, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.903294209307224, "lm_q1q2_score": 0.7164080130717062}}
{"text": "%!TEX root = TTK4215-Summary.tex\n\\section{Extremum seeking}\nThe basic idea: Want to find the optimal plant input $\\theta^*$ that maximises the output $y$. Add a slow periodic perturbation to our estimate $\\hat{\\theta}$. If increasing $\\theta$ increases $y$, then $y$ will oscillate in phase with $\\theta$. In the opposite case, $y$ with be out of phase with $\\theta$. The DC component of $y$ is removed with a high-pass filter, and the result multiplied with the perturbation signal. The product will have a positive DC component if $y$ and $\\theta$ are in phase, and negative DC if they are out of phase. This DC component is extracted with a low-pass filter, and is then a value indicating how far off $\\theta$ is, and in what direction. This is integrated and multiplied with a gain $k$ to form the estimate $\\hat{\\theta}$. Pretty clever.\n\n\\begin{figure}[htbp]\n\\begin{center}\n\t\\includegraphics[width = \\textwidth]{extremum-seeking}\n\t\\caption{Block diagram for extremum seeking}\n\t\\label{fig:MRAC}\n\\end{center}\n\\end{figure}", "meta": {"hexsha": "dd5e08e0575cc617dd66514ead3c968d681a408c", "size": 1024, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK4215 System identification and adaptive control/sec-extremum.tex", "max_stars_repo_name": "jakoblover/ntnu-course-summaries", "max_stars_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-11T02:42:40.000Z", "max_issues_repo_path": "TTK4215 System identification and adaptive control/sec-extremum.tex", "max_issues_repo_name": "jakoblover/ntnu-course-summaries", "max_issues_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TTK4215 System identification and adaptive control/sec-extremum.tex", "max_forks_repo_name": "jakoblover/ntnu-course-summaries", "max_forks_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 93.0909090909, "max_line_length": 781, "alphanum_fraction": 0.75, "num_tokens": 266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7164080112948361}}
{"text": "One key issue posed from the consensus mechanism described in \\cite{TWP} is the propagation and distribution of information across producers and eventually across the entire network. This is particularly an issue for the distribution of the list of producers   that a specific producer considers to have created the correct ledger state update. With larger producer pool which are necessary for security consideration, large lists of information are impractical for distribution. When it it is considered the every PID is 32Bytes long, for a group of 1000 producers lists would reach 32KBytes if the raw lists of producers are distributed. While compression can be used, what is gained in size of the elements is lost in time for compression and decompression of the lists. This is especially true when it is considered that every producer could potentially have to decompress 999 lists from a pool of 1000 producers. Furthermore using a User Datagram Protocol (UDP) as used in Catalyst, the potential for lost information on elements of that size is high. Therefore a more compact and efficient method is required. Bloom filters \\\\\n\nBloom filters are data structures that allow proof of membership of a set. They work is such a way that they can never provide a false negative i.e. showing that an element is in fact in the bloom filter as false. They can however show false positives meaning that an element that is not in the bloom filter can in fact come back true. Bloom filters are simple byte arrays of a specified length. Upon initialisation all bits within the byte array are set to 0. For each element to be added to the bloom filter it is hashed a defined number of times and the corresponding bit for the hash is flipped to a 1. For example for a small bit array \\verb'0bx0000' and element \\verb'Hello' is hashed to give the digest \\verb'04' then the $4^{th}$ bit would be flipped so the bloom filter would become \\verb'0bx1000'. This works on a modulo point, so if the digest was \\verb'05' then the first bit would be flipped giving the bloom filter \\verb'0bx0001'. For each element added to the bloom filter multiple hashes are created and added to the bloom filter, for example if 3 hashing functions are used 3 bits in total will be flipped in the bloom filter and these 3 flipped bits will represent the element. \\\\\n\nBloom filters are made up of four key variables, these are:\n\n\\begin{itemize} \n\\item $m$ - The size of the bloom filter in bits.  \n\\item $n$ - The number of elements to be added to the bloom filter. \n\\item $k$ - The number of hashing functions that are performed on each element added to the bloom filter. \n\\item $p$ - Probability of a false positive occurring for an element within the bloom filter. \n\\end{itemize} \n\nThe size of a bloom filter can be defined by: \n\n\\begin{center} \n$m = -(n \\times log(p)) \\div (log(2)^2)$\n\\end{center} \n\nThe optimum hash count of a bloom filter can be defined by:\n\n\\begin{center} \n$k = (m \\div n) \\times log(2)$\n\\end{center} \n\nThe false positive rate for a bloom filter is: \n\n\\begin{center} \n$p = (1 - e^{-kn \\div m})^k$\n\\end{center} \n\nThe number of elements added to the bloom filter is uniform across all producers as this must be set to the total number of producers for one cycle. Each of these variables can be changed in order to form a bloom filter for whatever accuracy, size or amount of producers it is required.\\\\\n\nThe reason for choosing a bloom filter over directly transferring the lists is for size considerations. Distributing a list containing 100 or a 1000 elements will be extremely cumbersome due to the size. While a bloom filter for 1000 elements would be approximately 1.4kBytes in size. Furthermore, due to the goal of the list creation is to efficiently deduce the members of the worker pool that created the correct delta and that bloom filters are an efficient method for membership validation the use of bloom filters lends itself to the Catalyst consensus algorithm. \n\n\\subsection{Statistics}\n\nUsing the script in \\cite{python} we can determine the probability of failure for any one particular node. Probability of failure is defined as the probability of any one node failing to hold a complete bloom filter of all producers who successfully produced the correct ledger state update. The process for a producer is such that, they produce a bloom filter of all producer they retrieved correct proposed ledger state updates at the beginning of the campaigning phase. This bloom filter is then passed of to  all other producers. However, due to natural inefficiencies it is unlikely all producers will receive all of the proposed updates therefore, the correct list must be constructed from all the received bloom filters. It is this created list for each producer that we will test. We analyse two variables, firstly is the message propagation ratio, this is the percentage of messages that we assume each producer recieves from the rest of the network, i.e. at a message propagation ratio of 0.75, for a producer pool of 100, each producer would receive randomly 75 other producers bloom filters. The second variable we will be testing is the size of the producer pool. ", "meta": {"hexsha": "db29d7a67b4018416d82426625415f63ccc1f171", "size": 5167, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex-files/consensus/bloom-filter.tex", "max_stars_repo_name": "catalyst-network/whitepaper", "max_stars_repo_head_hexsha": "06737c3da6476a5e14aecaed400dd24f04833ef6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-12T12:08:29.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-12T12:08:29.000Z", "max_issues_repo_path": "tex-files/consensus/bloom-filter.tex", "max_issues_repo_name": "catalyst-network/whitepaper", "max_issues_repo_head_hexsha": "06737c3da6476a5e14aecaed400dd24f04833ef6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 20, "max_issues_repo_issues_event_min_datetime": "2020-01-27T09:08:07.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-04T09:04:47.000Z", "max_forks_repo_path": "tex-files/consensus/bloom-filter.tex", "max_forks_repo_name": "catalyst-network/whitepaper", "max_forks_repo_head_hexsha": "06737c3da6476a5e14aecaed400dd24f04833ef6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-02-25T12:39:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-10T18:55:57.000Z", "avg_line_length": 135.9736842105, "max_line_length": 1198, "alphanum_fraction": 0.7900135475, "num_tokens": 1120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938414, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.7164080070214488}}
{"text": "\\lab{Algorithms}{Temporal Complexity and Sparse Matrices}{Complexity and Sparse Matrices}\n\n\\objective{Introduce the concept of temporal complexity and explore SciPy's special methods for working with sparse matrices.}\n\n\\section*{Temporal Complexity}\nOne of the most important questions in scientific computing is ``How long will this operation take?\"\nThe concept of temporal complexity attempts to answer this question by determining how much time a function needs to operate on a given size of input. \nFor example, suppose a particular algorithm operating on a matrix of size $n$ (that is, an $n \\times n$ matrix) requires the following number of calculations:\n\n\\begin{equation*}\nf(n) = \\frac{3n^3}{2} + 75n^2 + 250n + 30\n\\end{equation*}\n\nAs the input gets larger, the growth of $f(n)$ is dominated by the $n^3$ term.\nFor this reason we say that $f(n) \\in O(n^3)$, or more commonly, that $f(n)$ is $O(n^3)$ (spoken ``Big O of n cubed'' or ``order of n cubed\").\nThis notation is borrowed from analysis and captures the most important behavior of our temporal complexity. It describes the expected growth rate of the execution time of our algorithm. We also refer to this as \\emph{asymptotic notation}.\nWe will discuss this concept later, but this is a simple introduction to the notion of complexity and Big O.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{complexitycurves.pdf}\n\\caption{Some common asymptotic curves.}\n\\end{figure}\n\n\\begin{definition}[Temporal Complexity]\nLet $n$ represent the problem size.  Let $f(n)$ and $g(n)$ be functions mapping natural numbers to positive real numbers. We say that $f \\in O(g(n))$ if there exists a real number $c > 0$ and a natural number $n_0$ such that for all natural numbers $n > n_0$, $f(n) \\leq cg(n)$.\nWhen this is satisfied, we say that $g(n)$ is an asymptotic upper bound for $f(n)$. \nThe notation $f = O(g(n))$ is also common.\n\\end{definition}\n\nWhat does this have to do with computer programs?\nEvery algorithm executed on a computer corresponds to a function\nthat returns the number of steps taken (and therefore the time)\ngiven an input of size $n$.  Certain problems can be solved with fewer steps,while others require many more.  \n\nFor example, given two matrices of size $n$, matrix addition is $O(n^2)$. This is because it takes approximately $n^2$ steps to add $n^2$ elements for our $n \\times n$ arrays. \nComparatively, calculating the inverse of a matrix using Gaussian\nrow reduction is $O(n^3)$. (There are in fact more efficient\nalgorithms for matrix inversion.)\n\nHow do we determine the temporal complexity of a piece of code?\nCalculating the exact temporal complexity of a formula is fairly difficult.\nHowever, to asymptotically analyze a function is fairly straightforward.\n\n\\begin{lstlisting}\ns = 0\nfor i in xrange(100):\n    s = s + i\n\\end{lstlisting}\n\nThe code above is $O(n)$ because it takes approximately $n$ steps to complete. For-loops are a good indicator of the complexity.  A double for-loop strongly suggests $O(n^2)$ or worse.  Asymptotic analysis reveals that\nif we have an array of size $n \\times n$ and it takes $x$ seconds to execute an $O(n^2)$ algorithm,\nthen by increasing the size of the array to $2n \\times 2n$, we should expect the same algorithm\nto terminate in about $(2)^2 x = 4x$ seconds.  Sometimes, when you don't have code to look at,\nyou can approximate the asymptotic growth of a function by timing it on various sized inputs.\n\n\\begin{problem}\nTime the runtime of the following code for \\li{n = 1000, 2000, 4000, 8000}.\n\n\\lstinputlisting[style=fromfile]{test.py}\n\nNow write a function that takes no arguments and does the following: \n\\begin{enumerate}\n\\item Plots the four runtimes (use \\li{[1000, 2000, 4000, 8000]} or an equivalent array object as your domain).\nThe plot should look like Figure \\ref{prob1} if using the \\li{plt.scatter} command. \n\\item Returns the average ratio between successive runtimes (one such ratio would be the runtime for $n = 2000$ divided by the runtime for $n = 1000$).\n\\end{enumerate}\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{prob1.pdf}\n\\caption{The plot of problem 1}\n\\label{prob1}\n\\end{figure}\n\nWe can also classify an algorithm by the amount of memory it needs to execute.  We will use the term \\emph{spatial complexity} to measure the amount of memory an algorithm uses.  The definition of spatial complexity is the same as the definition of temporal complexity, with the obvious difference that $n$ refers to space rather than time.\nIn practice, spatial and temporal complexity are not completely independent of each other. The amount of memory required by an algorithm can affect its speed in several ways. The most important consideration is when the memory usage exceeds the amount of available RAM. When this occurs, the machine must use the hard disk or some other slower storage method. Doing so makes the read and write operations become substantially slower.\n\n\\section*{Sparse Matrices}\nA sparse matrix is a matrix that has relatively few nonzero elements. \nSciPy has several different ways to store sparse matrices. Each way has its own benefits and the reader is encouraged to do additional research. It is important to note that SciPy's \\li{sparse} methods refer to the way a matrix is stored and not the actual sparsity of the matrix in question; we can store a dense matrix using SciPy's \\li{sparse} methods, but we will not see efficiency gains as we do when we use these methods on matrices that are actually sparse.\n\n\\begin{table}\n\\centering\n\\begin{tabular}{|l|l|}\n\\hline\nFunction & Description \\\\\n\\hline\n\\li{sparse.bsr_matrix()} & Compressed Block Sparse Row\\\\\n\\li{sparse.coo_matrix()} & Coordinate\\\\\n\\li{sparse.csc_matrix()} & Compressed Sparse Column\\\\\n\\li{sparse.csr_matrix()} & Compress Sparse Row\\\\\n\\li{sparse.dia_matrix()} & Sparse Diagonal\\\\\n\\li{sparse.dok_matrix()} & Dictionary of Keys\\\\\n\\li{sparse.lil_matrix()} & Linked List\\\\\n\\hline\n\\end{tabular}\n\\caption{Sparse matrix representations in SciPy}\n\\label{smr}\n\\end{table}\n\nThe following showcases some of SciPy's sparse matrix representation functions listed in Table \\ref{smr}\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import sparse\n\n>>> A = np.diagflat([2, 3, 4])\n>>> A\narray([[2, 0, 0],\n       [0, 3, 0],\n       [0, 0, 4]])\n\n>>> B = sparse.csc_matrix(A)\n>>> B\n<3x3 sparse matrix of type '<type 'numpy.int64'>'\n\twith 3 stored elements in Compressed Sparse Column format>\n\n# Convert B to a storage in a full matrix format\n>>> C = B.todense()\n>>> C\nmatrix([[2, 0, 0],\n        [0, 3, 0],\n        [0, 0, 4]])\n\n\\end{lstlisting}\n\nNotice that the matrix $A$ has only three non-zero entries so we consider it to be a sparse matrix.\nIn memory, an array stores a piece of data (be it an integer, float, or complex number) in each entry. This means that a $3 \\times 3$ matrix requires a total 9 blocks of memory.\nHowever, if we leverage the sparsity of $A$ we realize that we really only need to store 3 numbers.\nThe \\li{sparse} methods do exactly this: they store only the non-zero entries and their locations in the matrix. \nAn entire array is no longer being stored, decreasing complexity.  \n\nSciPy has many methods for performing operations on sparse matrices. For example, to convert back to a dense matrix we use the \\li{todense()} method (of the sparse matrix). We can also convert between the different types of sparse matrices.\n\nNote that if you want to make a sparse diagonal matrix, the best way to do so isn't by creating a diagonal matrix using \\li{diagflat()} and then making it sparse by using \\li{sparse}. Instead it is much better to use the \\li{sparse.spdiags()} method like so:\n\n\\begin{lstlisting}\n# sparse.spdiags(data, diags, m, n)\nsparse.spdiags([2, 3, 4], 0, 3, 3) \n\\end{lstlisting}\n\nNote that \\li{diags=0} sets our data along the main diagonal for an $m \\times n$ matrix. If \\li{diags} $> 0$ then our data is set along the indicated upper diagonal. Similarly, if \\li{diags} $< 0$ then our data is set along the indicated lower diagonal. \n\nOften, when we are using sparse matrices it is because we are dealing with matrices that are otherwise too large to be handled efficiently when represented in full form.\n\n%insert problem here that lets them play around with large sparse matrices in diff forms\n\n\\section*{Banded Matrices}\nA banded matrix is one whose only non-zero entries are diagonal\nstrips.  For example, the matrix\n\\begin{equation*}\nA = \\begin{pmatrix}\n1 & 2 & 0 & 0 \\\\\n3 & 4 & 5 & 0 \\\\\n0 & 6 & 7 & 8 \\\\\n0 & 0 & 9 & 10\n\\end{pmatrix}\n\\end{equation*}\nis banded because the only non-zero entries are located in three nonzero diagonals.  This particular type of banded matrix is called a tri-diagonal matrix.\n\nBanded matrices are easily created using the \\li{diagflat()} method.\nFor example, the matrix $A$ from above can be created by doing:\n\n\\begin{lstlisting}\n# np.diagflat(data, k=0)\n>>>np.diagflat([3, 6, 9], -1) + np.diagflat([1, 4, 7, 10], 0) + np.diagflat([2, 5, 8], 1) \narray([[ 1,  2,  0,  0],\n       [ 3,  4,  5,  0],\n       [ 0,  6,  7,  8],\n       [ 0,  0,  9, 10]])\n\n\\end{lstlisting}\nNote that \\li{data} must be a flattened array and the keyword argument \\li{k} is an integer that determines which diagonal is set with the given data. \n\nHowever, creating this tri-diagonal required using \\li{np.diagflat} three times. Often, a better way to create a tri-diagonal is it use the \\li{sparse.spdiags()} method. %Note that\nThis is because many banded matrices are sparse.\n\nFor example, we can create the same matrix from above using the command:\n\\begin{lstlisting}\n>>> Z = np.array([[3,6,9,0],[1,4,7,10],[0,2,5,8]])\n>>> sparse.spdiags(Z, [-1, 0, 1], 4, 4)\n<4x4 sparse matrix of type '<type 'numpy.int64'>'\n\twith 10 stored elements (3 diagonals) in DIAgonal format>\n\n\\end{lstlisting}\n\nNote that the diagonals are all the same length, unlike when we used the \\li{np.diagflat} to construct this matrix. For more information, check the documentation by typing \\li{sparse.spdiags?}.\n\n\\begin{problem}\nWrite a function that takes an integer argument \\li{n} and returns a full $n\\times n$\ntri-diagonal array with $2$'s along the diagonal and $-1$'s along\nthe two sub-diagonals above and below the diagonal.\n\n\\emph{Helpful Hint}: Use the \\li{np.diagflat()} command.\n\\label{full_tridiag}\n\\end{problem}\n\nWe will now create a tri-diagonal array with uniformly distributed random entries. This example also demonstrates the efficiency of using sparse arrays.\n\n\\begin{lstlisting}\n>>>B = np.random.rand(3, 10000)\n\n>>> A = sparse.spdiags(B, range(-1, 2), 10000, 10000)\n\n# Only do this if you have several gigabytes of memory\n>>> denseA = A.todense() \n\n>>> A.data.nbytes # About .24MB of memory.\n240000\n\n>>> denseA.nbytes # About 762.9MB of memory.\n800000000\n\n\\end{lstlisting}\n\nEven when a complete matrix is too large to represent in memory,\nwe can still visualize it using the \\li{plt.spy()} command from Matplotlib,\nwhich essentially shows the location of non-zero entries in a matrix.\nThe output of \\li{plt.spy(A)} in this case is shown in Figure \\ref{fig:mpl_spy}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{spy.png}\n\\caption{The output of the \\li{spy()} command}\n\\label{fig:mpl_spy}\n\\end{figure}\n\n\\begin{problem}\nWrite a function that accepts an integer argument \\li{n} and returns the same array as Problem \\ref{full_tridiag}, but as a sparse array.\nYou must build this as a sparse matrix from the beginning.\n\n\\emph{Helpful Hint}: Use the \\li{sparse.spdiags()} method. \\li{format} should be set to \\li{'csr'}.\n\\label{prob:sparse_tridiag}\n\\end{problem}\n\n\\section*{Using Sparse Matrices}\nConsider the linear system $A x = b$, where $A$ is a $100000\\times 100000$ tri-diagonal matrix.\nStoring a full matrix of that size would normally require 10 billion double-precision floating-point numbers.  Since it takes 8 bytes to store a double, it would take roughly 80GB to store the full matrix.  For most desktop computers, that fact alone makes the system numerically prohibitive to solve.\nThe temporal complexity of this problem is even more problematic. Methods for directly solving an arbitrary linear system are usually $O(n^3)$. As a result, even if the computer could store an 80GB matrix in RAM, it would still take several weeks to solve the system. However, since we don't typically have computers with that much available RAM, most of the\nmatrix would have to be stored on the hard drive, so the computation would probably take between $6$ months to a year.\n\nThe point is, even as computers increase in processing speed and memory, we can still easily construct problems that they will struggle to solve in a reasonable amount of time. However, if we take advantage of the sparse structure of the tri-diagonal matrix, we can solve the linear system, even with a modest modern computer.  This is because all of those zeros don't need to be stored and we don't need to do as many operations to row reduce the tri-diagonal system. Note that you should never solve a sparse system by inverting the matrix, since the inverse of a sparse matrix will most likely be not sparse and therefore computationally unwieldy.\n\nLet's first compute the spatial complexity of the above system when considered as a sparse matrix.  There are three diagonals that have roughly $100000$ non-zero entries.  That's $300000$\ndouble-precision floating point numbers, which is about 2.4 MB (Less storage than your favorite song).  As a result, it will easily fit into the computer's RAM.  Furthermore, the temporal complexity for solving a tri-diagonal matrix is $O(n)$. Let's see how long it takes to solve the system for random data:\n\n\\begin{lstlisting}\n# Note that we need to import sparse.linalg as its own module instead of simply using the command sparse.linalg.spdiags\nfrom scipy.sparse import linalg as sl\nD = np.random.rand(3, 100000)\nb = np.random.rand(1, 100000)\nA = sparse.spdiags(D,[-1,0,1],100000,100000, format='csr')\ndef solSys():\n    return sl.spsolve(A, b)\n\n%timeit solSys()\n\n\\end{lstlisting}\n\n\n\\begin{problem}\nWrite a function that accepts an integer argument \\li{n} as well as a keyword argument \\li{sparse} whose value is either \\li{True} or \\li{False} (default to \\li{False}). Then do the following:\n\\begin{enumerate}\n\\item Inside of the function, use your previous solutions to generate an $n \\times n$ tri-diagonal array $A$ -- either sparse or full depending on the value of the \\li{sparse} argument.\n\\item Generate an $n \\times 1$ random array $b$\n\\item Solve the system $Ax = b$, using either \\li{scipy.sparse.linalg.spsolve} or \\li{scipy.linalg.solve}\n(again depending on the value of \\li{sparse}) and return the solution.\n\\item Time the function for \\li{n = 2000} using both the sparse and the full option.\n\\end{enumerate}\n\\end{problem}\n\n\\begin{problem}\nWrite a function that accepts an integer argument \\li{n} and returns $\\lambda n^2$, where\n$\\lambda$ is the smallest eigenvalue of the same $n \\times n$ sparse tri-diagonal array as described above.\n\nTo calculate $\\lambda$, use \\li{scipy.sparse.linalg.eigs}. You will need to set the \\li{which = 'SM'}\noptional argument. If \\li{A} is your tri-diagonal sparse matrix, you will need to use\n\\li{A.asfptype()} as the argument for the \\li{eigs} function (so that the matrix has the right data type).\nCheck the documentation of the \\li{eigs} function to see what it returns, so that you will know how to\nget the smallest eigenvalue.\n\nWhat value does $\\lambda n^2$ approach as $n \\rightarrow \\infty$?\n\n\\li{Helpful Hint}: It's the square of an important number.\nThis is related to operator theory: the second derivative operator has this eigenvalue in certain cases.\n\\end{problem}\n\n\\section*{Other Sparse Commands}\nOne important method of sparse matrix objects is the \\li{nonzero()} method, which is related to the number of nonzero entries in the matrix. This number is important because it is an indicator of the amount of time and space that is required to operate on the sparse matrix.\nYou should be aware that there is some overhead to using and storing the sparse matrix data structure. Sparsely represented matrices are very beneficial when the number of nonzero entries is relatively small compared to the total number of entries.\nWhen the matrix has many nonzero entries, a sparse representation becomes disadvantageous.\nTo see this, observe: \n\n\\begin{lstlisting}\n>>> A = np.random.rand(600, 600)\n\n>>> B = sparse.csc_matrix(A)\n\n>>> def square(A):\n>>>     return np.power(A, 2)\n\n>>> %timeit square(A)\n100 loops, best of 3: 9.53 ms per loop\n\n>>> %timeit square(B)\n1 loops, best of 3: 941 ms per loop\n\\end{lstlisting}\n\nNotice that it takes much longer to square the sparse matrix.\nThis is because the sparse matrix data structure is optimized for matrices that are actually sparse. The array $A$ is entirely nonzero. Thus, you incur the overhead of the sparse array representation without any benefits since there are no entries you are not required to store or compute.\n\nTo summarize, only use a sparse matrix when your matrix is in fact sparse. Using sparse matrices for mostly nonzero arrays will negatively impact performance and memory requirements.\n\nJust as with dense arrays, we can pre-allocate sparse matrices.\nSometimes it is necessary to create sparse matrices that do not have a nice banded pattern. We initialize a sparse matrix just like any other array. The most efficient sparse matrix for pre-allocation is \\li{LIL}. Once you are done constructing the sparse matrix and wish to perform calculations, you should convert to a more efficient sparse matrix (CSR or CSC).\n\n\n\\begin{lstlisting}\n>>> Z = sparse.lil_matrix((400, 300))\n\n>>> Z[1,34] = 23\n\n>>> Z[23,32] = 56\n\n>>> Z[2,:] = 13.2\n\n>>> Z\n<400x300 sparse matrix of type '<type 'numpy.float64'>'\n\twith 302 stored elements in LInked List format>\n\n\\end{lstlisting}\n\nWhen the matrix \\li{Z} from above is initialized, all entries of the $400 \\times 300$ \\li{LIL} sparse matrix are assumed to be zero. \nWe can then work with the sparse matrix as though it were a dense array.\nNote that only 302 elements are being stored for a matrix with 120000 possible entries. \n\n\\begin{problem}\nCreate a $500\\times 500$ matrix and vector of length 500, both full of random values. Use the \\li{A.dot(b)} command to multiply your matrix and your vector, and time how long it takes to do so. Then convert your matrix to sparse format and again time how long it takes to multiply it by your vector using \\li{A.dot(b)}.\n\\end{problem}\n \n", "meta": {"hexsha": "7dc0275d1f942c49528560bf493e9f28ff5257f5", "size": 18453, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/Matrices_Complexity/Matrices_Complexity.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/Matrices_Complexity/Matrices_Complexity.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/Matrices_Complexity/Matrices_Complexity.tex", "max_forks_repo_name": "lcbendall/numerical_computing", "max_forks_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.7988338192, "max_line_length": 650, "alphanum_fraction": 0.7502845066, "num_tokens": 4804, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7163789514923096}}
{"text": "\\section{Poisson Processes}\n\\label{sec:Poisson-Processes}\n\nThe Poisson process is the most widely used model for arrivals into a system because it is often a realistic representation of natural models and, since it exposes the Markovian property, it is analytically tractable.\nIt greatly models natural process where we observe aggregation of large number of independent entities \\footnote{This is true thanks to the Limiting Theorem \\cite{ross2014introduction}}.\n\nThe Poisson distribution is a discrete probability distribution that expresses the probability of a given number of events occurring in a fixed interval of time and/or space if these events occur with a known average rate and independently of the time since the last event. If inter-arrival times are Exponentially distributed, then the number of arrivals within a given time is Poisson distributed.\n\n\\begin{definition}[Poisson Distribution]\n\\label{def:Poisson-Distribution}\n\tA random variable $N(t)$ is Poisson distributed with rate\\footnote{if $N(t) \\sim Poisson(\\lambda)$, $\\lambda$ is called \\textit{rate} because $\\expected{N(t)}=\\lambda t$.} $\\lambda$ ($N(t) \\sim Poisson(\\lambda)$) if $N(t)$ has the following probability mass function:\n\t\n\t\\begin{equation}\n\t\\label{eqn:Poisson-PMF}\n\tf(k,t) = \\frac{(\\lambda t)^{k} e^{-\\lambda t}}{k!}\n\t\\end{equation}\n\\end{definition}\n\nThe p.d.f of $X \\sim Poisson(\\lambda)$ is shown in \\Cref{fig:poisson-pdf}.\n\n\\begin{figure}[tp]\n\\label{fig:Poisson-PMF}\t\n\t\\centering\n\t\\includegraphics{fig/poisson-pdf}\n\t\\caption{Poisson p.m.f.}\n\\end{figure}\n\nFrom the \\Cref{def:Poisson-Distribution} follows that the cumulative distribution function of $N(t) \\sim Poisson(\\lambda)$ is \n\n\\begin{equation}\n\\label{eqn:Poisson-CDF}\nF(k,t) = \\sum_{x=0}^{t} f(k,x)\n\\end{equation}\n\nThe Poisson distribution has mean\n\n\\begin{equation}\n\\label{eqn:Poisson-Mean}\n\\expected{N(t)} = \\lambda t\n\\end{equation}\n\nand variance\n\n\\begin{equation}\n\\label{eqn:Poisson-Variance}\n\\variance{N(t)} = \\lambda t\n\\end{equation}\n\n\\begin{definition}[Poisson Process]\n\\label{def:poisson-process-statistical}\n\tA Poisson process with rate $\\lambda$ is a sequence of events such that\n\t(i) $N(0)=0$,\n\t(ii) it has independent increments,\n\t(iii) $\\probability{N(s+t)-N(s) = n} \\sim Poisson(\\lambda t)$\n\\end{definition}\n\nNotice that point (iii) in \\Cref{def:poisson-process-statistical} implies stationary increments. \nFurthermore, the assumption of independent and stationary increments implies that, at any point in time, the process statistically restarts itself; that is, the process from any point onward is independent of all previously occurred (independent increments) and has the same distribution of the original process (stationary increments).\n\n\\begin{definition}[Poisson Process]\n\\label{def:poisson-process-practical}\n\tA Poisson process with rate $\\lambda$ is a sequence of events such that\n\t(i) the interarrival times are Exponential r.v. with rate $\\lambda$, and \n\t(ii) $N(0)=0$.\n\\end{definition}\n\nA Poisson process has stationary and independent increments.\n\nHere are some useful properties of the Poisson distribution.\n\n\\begin{theorem}[Poisson Merging]\n\\label{thm:Poisson-Merging}\t\n\tGiven two independent Poisson process with rate $\\lambda_{1}$ and $\\lambda_{2}$, the merged process is a Poisson process with rate $(\\lambda_{1} + \\lambda_{2})$.\n\\end{theorem}\n\n\\begin{theorem}[Poisson Splitting]\n\\label{thm:Poisson-Splitting}\t\n\tGiven a Poisson process with rate $\\lambda$, whose events are partitioned in class-A with probability $p$ and class-B with probability $(1-p)$, the class-A process is a Poisson process with rate $p \\lambda$ and the class-B process is a Poisson process with rate $(1-p) \\lambda$, and these processes are independent.\n\\end{theorem}\n\n\\begin{theorem}[Poisson Uniformity - Single Event]\n\\label{thm:Poisson-Uniformity-Single-Event}\t\n\tGiven that one event of a Poisson process has occurred by time $t$, that event is equally likely to have occurred anywhere in $[0,t]$. \n\\end{theorem}\n\n\\begin{theorem}[Poisson Uniformity - Multiple Events]\n\\label{thm:Poisson-Uniformity-Multiple-Events}\t\n\tIf $k$ events of a Poisson process occur by time $t$, then the $k$ events are distributed independently and uniformly in $[0,t]$. \n\\end{theorem}", "meta": {"hexsha": "b3c00694e9d41fdb4156d1aaf0588753d9583549", "size": 4219, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/poisson-processes.tex", "max_stars_repo_name": "gmarciani/research", "max_stars_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-07-27T13:31:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-20T12:54:12.000Z", "max_issues_repo_path": "performance-modeling/sec/poisson-processes.tex", "max_issues_repo_name": "gmarciani/research", "max_issues_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "performance-modeling/sec/poisson-processes.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 47.404494382, "max_line_length": 399, "alphanum_fraction": 0.7601327329, "num_tokens": 1150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145053, "lm_q2_score": 0.8333246035907933, "lm_q1q2_score": 0.7163789511189061}}
{"text": "\\chapter{Classification}\nIn classification task, we find a model for class attribute as a function of the values of other attributes. The goal is to assign previously unseen records a class as accurately as possible.\n\n\\section{Decision Tree based}\n\n\\subsection{Hunt's Algorithm}\n\nHunt's algorithm grows a decision tree in a recursive fashion by partitioning the training records into successively purer subsets. Let $D_t$ be the set of training records that reach a node $t$:\n\n\\begin{itemize}\n\\item If $D_t$ contains records that belong the same class $y_t$, then $t$ is a leaf node labeled as $y_t$\n\\item If $D_t$ is an empty set, then t is a leaf node labeled by the default class\n\\item If $D_t$ contains records that belong to more than one class, use an attribute test to split the data into smaller subsets.\n\\end{itemize}\n\n\\subsection{Measure of Node Impurity}\n\n\\underline{Gini Index}\n\n$$GINI(t) = 1 - \\sum_{j} P(j\\mid t)^{2}$$\n\n$$GINI_{split}=\\sum_{i=1}^{k} \\frac{n_i}{n} GINI(i)$$\n\\noindent\n\\underline{Entrophy} \n\n$$Entrophy(t)=-\\sum P(j \\mid t) log_2 P(j \\mid t)$$ \n\n$$GAIN_{split}=Entrophy(p)-\\sum_{i=1}^{k} \\frac{n_i}{n}Entrophy(i)$$\n\\noindent\nDisadvantage: Tends to prefer splits that result in large number of partitions, each being small but pure. \\\\\n\\par \\noindent\nIntroduce Gain Ratio: \n\n$$GainRATIO_{split}=\\frac{GAIN_{split}}{SplitINFO}$$\n\n$$SplitINFO=-\\sum_{i=1}^{k} \\frac{n_i}{n}log_2 \\frac{n_i}{n}$$ \\\\\n\\underline{Misclassification Error}\n\n$$Error(t)=1-max_i P(i \\mid t)$$ \n\\par \\noindent\n{\\it Hint: To compute maximum value for Gini Index, Entrophy, or Misclassification Error, subtitute $P(j\\mid t)$ with $1/ n_c$. Minimum values are always 0. }\n\n\\section{Rule-based}\nClassify records by using a collection of \"if… then…\" rules. \\\\\n\n\\subsection{Rule Coverage and Accuracy}\nGiven a rule $r$ in a dataset $D$:\n$$r: A \\rightarrow y$$\n\n$$coverage=\\frac{\\mid A \\mid}{\\mid D \\mid}$$\n$$accuracy=\\frac{\\mid A \\cap y \\mid}{\\mid A \\mid}$$\n\n\\subsection{Characteristics of Rule-Based Classifier}\n\n\\begin{description}\n  \\item[Mutually exclusive] Every record is covered by at most one rule. No two rules are trigger by the same record.\n  \\item[Exhaustive] Each record is covered by at least one rule\n\\end{description}\n\n\\section{Model Evaluation}\n\nFocus on predictive capability of a model\n\n\\subsection{Metrics for Performance Evaluation}\n\nConfusion Matrix:\n\\begin{center}\n\\begin{tabular}{ | p{4cm} | p{4cm} | p{4cm} | } \n    \\hline\n    Count & Predicted Class=YES & Predicted Class=NO \\\\\n    \\hline\n    Actual Class = YES & a(TP) & b(FN) \\\\\n    \\hline\n    Actual Class = NO & c(FP) & d (TN) \\\\\n    \\hline\n\\end{tabular}\n\\end{center}\n\n$$Accuracy=\\frac{a + d}{a + b + c + d}$$\n\n$$Weighted\\ Accuracy=\\frac{w_1a + w_4d}{w_1a + w_2b + w_3c + w_4d}$$\n\n$$Precision,p=\\frac{a}{a + c}$$\n\n$$Recall,r=\\frac{a}{a+b}$$\n\n$$F-measure,f=\\frac{2a}{2a + b + c}$$\n\n\\subsection{Methods for Performance Evaluation}\n\\begin{description}\n\\item[Holdout] reserve 2/3 for training and 1/3 for testing\n\\item[Random subsampling] repeated holdout\n\\item[Cross validation] partition data into k disjoint subsets\n\\item[Stratified sampling] oversampling vs undersampling\n\\item[Bootstrap] sampling with replacement\n\\end{description}\n\n\\subsection{Methods for Model Comparison}\nROC curve is a graph of TP rate againts FP rate\n$$TP\\ rate, TPR = \\frac{a}{a+b}$$\n$$FP\\ rate, FPR = \\frac{c}{c + d}$$\n\n\n", "meta": {"hexsha": "fe696296c09c6791ed5a3d70d791a6664ee489b2", "size": 3369, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter4.tex", "max_stars_repo_name": "Andyccs/data-mining-summary", "max_stars_repo_head_hexsha": "27ffac528e9e225c8a15ff44fbf2ed3e1c6b9f7a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter4.tex", "max_issues_repo_name": "Andyccs/data-mining-summary", "max_issues_repo_head_hexsha": "27ffac528e9e225c8a15ff44fbf2ed3e1c6b9f7a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter4.tex", "max_forks_repo_name": "Andyccs/data-mining-summary", "max_forks_repo_head_hexsha": "27ffac528e9e225c8a15ff44fbf2ed3e1c6b9f7a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3942307692, "max_line_length": 195, "alphanum_fraction": 0.7082220243, "num_tokens": 1052, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7163789505565719}}
{"text": "\\lab{Applications}{Regression}{Regression}\n\\label{Stats3?}\n\n\\objective{This section will introduce the very basics of Linear Regression (both simple and multiple) and Logistic Regression.}\nDependencies: Least squares\n\n\\section*{Introduction to Linear Regression}\n\nOne of the first skills in taught in basic algebra is to effectively plot the line $y=mx+b$.  But what if we want to find the line that best fits points?\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=3in]{slr.pdf}\n\\end{figure}\n\nHere, we can use ordinary least squares. If the line is $y=mx+b$, then let $$y_i = mx_i + b +\\epsilon_i$$ describe point $i$, $i \\in \\{1,...,n\\}$, where $\\epsilon_i$ is vertical distance from the point to the line, and is often called the residual or the error. These equations for all $n$ points can be described in vector notation. Let the different coordinates of the points be represented by a column vector $\\underline{x}$ and a column vector $\\underline{y}$, each of length n. Note that all vectors in this section will be assumed to be column vectors unless otherwise noted. Then $$\\underline{y}=m\\underline{x}+b\\underline{1}+\\underline{\\epsilon} = (\\underline{1}, \\underline{x}) \\begin{pmatrix} b \\\\ m \\end{pmatrix} + \\underline{\\epsilon}.$$ \n\nIn statistical science, the intercept and slope ($b$ and $m$) are called coefficients and denoted as $\\beta_0$ and $\\beta_1$ respectively, where $\\begin{pmatrix} \\beta_0 \\\\ \\beta_1 \\end{pmatrix} = \\underline{\\beta}$. Also, we will denote $(\\underline{1}, \\underline{x})$ as $X$. Thusly, our equation now reads as $$\\underline{y}=X\\underline{\\beta}+\\underline{\\epsilon}.$$ This notation is excessive for simply fitting a linear line, but what if the model we really want is $y=ax^3 + bx^2 + cx+d$? Then simply, $X=(\\underline{1},\\underline{x},\\underline{x^2},\\underline{x^3})$ and $\\underline{\\beta} = (\\beta_0, \\beta_1, \\beta_2, \\beta_3)^T$.\n\nBack to least squares: we like this notation because the least squares estimator for $\\underline{\\beta}$ is $$\\hat{\\beta} = (X^T X)^{-1} X^T \\underline{y}.$$ This works because for a linear regression model we assume $\\underline{y} \\sim N(X\\underline{\\beta}, \\sigma^2 I)$, where $\\underline{\\epsilon} \\sim N(\\underline{0}, \\sigma^2 I)$.\n\n\\subsection*{Example}\n\nNow, let us model the housing market in California. In the figure we see the median house prices for California across the years. \n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=3in]{california.pdf}\n\\includegraphics[width=3in]{cali-linear.pdf}\n\\includegraphics[width=3in]{cali-quadratic.pdf}\n\\end{figure}\n\n\n\\begin{problem}\nLoad the data in housingprices.npy. Note that the years column is years since 2000 (to avoid numerical issues of raising 4 digit numbers to large powers...). Fit a cubic regression [$X=(\\underline{1},\\underline{x},\\underline{x^2},\\underline{x^3})$] to the data. Why is this not a great fit? Next fit a quartic regression [$X=(\\underline{1},\\underline{x},\\underline{x^2},\\underline{x^3},\\underline{x^4})$] to the data. Is this model a good fit?\n\\end{problem}\n\n\n\\section*{Logistic Regression}\n%Thanks to Wiki, and http://www.statsci.org/data/general/challenger.html \n%http://science.ksc.nasa.gov/shuttle/missions/51-l/docs/rogers-commission/Chapter-4.txt\n%Data source: Chatterjee et al (1995). A casebook for a first course in statistics and data analysis. Wiley.\nOn January 28, 1986, less than two minutes into the Challenger space shuttle's 10th mission, there was a large explosion that originated from the spacecraft. As a result all seven crew members were killed and the shuttle was destroyed. The investigation that followed concluded that the malfunction was caused by damage to O-rings that are used as seals for parts of the rocket engines. There were 24 space shuttle missions before this disaster, and each had 6 primary O-rings. Some of these previous missions noted O-ring damage, but none, obviously, caused this much damage. So what happened? On  the day of the launch, it was $31^{\\circ}  \\mathbb{F}$, in Florida...\n\nIn the dataset \"challenger.npy\" you'll find data for 23 missions, where the first column is the ambient temperature in Fahrenheit, and the second column is an indicator of the presence of O-ring damage. One of the previous 24 engines was lost at sea, hence 23 data points.  Plotting the points and fitting a cubic curve with linear regression as we discussed above results in the fit shown in Plot----. \n\n\\begin{figure}[h]\n\\label{badfit}\n\\centering\n\\includegraphics[width=3in]{cubicthrulogitpoints.pdf}\n\\end{figure}\n\nClearly, there is a relationship between ambient temperature and O-ring damage. It is also clear that a cubic curve from linear regression is not the ideal model. First and foremost, our response variable (the y axis) is only 0 or 1, based on the presence of damage. ``2\" doesn't mean anything, so we shouldn't allow that to occur. In standard linear regression, we assume the $y$ variable follows a normal distribution, as stated previously. However, here we see that our $y$ variable, the presence of O-ring damage, follows a Bernoulli distribution (a Binomial distribution with $n=1$). This is also stated $$y_i \\sim Bern(p_i),$$ where $p_i$ is the probability that $y_i=1$, the probability of damage to the O-rings. We see in plot ---- that it appears that $p_i$ is affected by temperature, or in other words, is some function of $x_i$, the ambient temperature.  Thusly, we want to estimate $p_i$ using a linear model, $\\underline{x}^T_i \\underline{\\beta} = \\beta_0 + \\beta_1x_i$. However, this produces values in $\\mathbb{R}$, not just in $(0,1)$. Instead, we model the logit function of the probabilities: \n$$logit(p_i) = log \\left(\\frac{p_i}{1 - p_i}\\right) = \\beta_0 + \\beta_1x_i,$$ where $logit(p) = log(\\frac{p}{1-p}) \\in \\mathbb{R},$ for $p \\in (0,1)$. Furthermore, $$p_i = \\frac{e^{\\underline{x}^T_i\\underline{\\beta}}}{1+e^{\\underline{x}^T_i\\underline{\\beta}}}.$$\n\n%This model is shown in Figure ? with arbitrary values for x and y, and $\\underline{\\beta} = \\begin{bmatrix} 0 \\\\1 \\end{matrix}$, such that $p=\\frac{e^x}{1+e^x}$. Note the curve shows the estimated probabilities, but the points have only $y=1$ or $0$.\n\nThe values of $\\beta_0$ and $\\beta_1$ would be chosen to minimize $||\\underline{y} - \\underline{p}||$, for a chosen norm. This can't be solved with the same least squares approach used in linear regression, but instead we look to optimization. This will be introduced later, so for now we'll use a Logistic Regression package in python. \nNumPy has a function sklearn.linear\\_model.LogisticRegression that should help.\n\\begin{verbatim}\nfrom sklearn import linear_model \nmodel = linear_model.LogisticRegression(C=1000000)\nmodel.fit(X,Y)\n\\end{verbatim}\n\nNote that X must be a 2-d array or matrix, and by default it automatically includes an intercept. So the vector of temperatures needs to be relabeled/reshaped into a 2-d matrix:\n\n\\begin{verbatim}\nX=vector_of_temperatures.reshape([23,1])\n\\end{verbatim}\n\nOnce the model has been fit, the slope and intercept of the linear model can be obtained with\n\\begin{verbatim}\nmodel.intercept_\nmodel.coef_\n\\end{verbatim} \nand then used to obtain different probabilities of damage given an ambient temperature.\nOr the model has a function that will predict the value for you. If temp is an array of temperatures you want to know the percentage of O-ring failure then\n\\begin{verbatim}\nmodel.predict_proba(np.vstack(temp))[:,1]\n\\end{verbatim} \nwill return an array of probabilities of damage for the given ambient temperatures. The graph of O-ring failure given ambient temperature using a logistic model is shown below in a figure. Does it fit better than the cubic polynomial regression?  \n\n\\begin{figure}[h]\n\\label{logisticmodel}\n\\centering\n\\includegraphics[width=3in]{logreg.pdf}\n\\end{figure}\n\n\n\\begin{problem}\nRun the logistic regression model to predict probability of damage based on ambient temperature, and plot the different probabilities of damage from $30^{\\circ} $F to $100^{\\circ} $F. \n\\end{problem}\n\n\\begin{problem}\nGiven that it was $31^{\\circ}$ F at the time of launch, what was the probability of O-ring damage on January 28, 1986?\n\\end{problem}\n", "meta": {"hexsha": "1998bddc990c02edea55ecf2970ef2b3a7298428", "size": 8162, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/Regressions/Regressions.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/Regressions/Regressions.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/Regressions/Regressions.tex", "max_forks_repo_name": "lcbendall/numerical_computing", "max_forks_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 83.2857142857, "max_line_length": 1112, "alphanum_fraction": 0.7499387405, "num_tokens": 2174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637541053281, "lm_q2_score": 0.8333245932423309, "lm_q1q2_score": 0.7163789482149977}}
{"text": "\\chapter{Hydrogen atom }\n\\section{Central potential}\nWe are going to study the structure of the schrodinger equation for the particle of mass M moving in a spherically symmetric potential\\\\\n $V(\\vec{r})=V(r)$,\\\\\nwhich is also known as the central potential.\\\\\nThe time-independent Schrödinger equation for this particle, of momentum $-i \\hbar \\vec{\\nabla}$ and position vector $r$, is\n$$\n\\left[-\\frac{\\hbar^{2}}{2 M} \\nabla^{2}+V(r)\\right] \\psi(\\vec{r})=E \\psi(\\vec{r}) .\n$$\nSince the Hamiltonian is spherically symmetric, we are going to use the spherical coordinates $(r, \\theta, \\varphi)$ which are related to their Cartesian counterparts by\n$$\nx=r \\sin \\theta \\cos \\varphi, \\quad y=r \\sin \\theta \\sin \\varphi, \\quad z=r \\cos \\theta .\n$$\nThe Laplacian $\\nabla^{2}$ separates into a radial part $\\nabla_{r}^{2}$ and an angular part $\\nabla_{\\Omega}^{2}$ as follows:\n$$\n\\nabla^{2}=\\nabla_{r}^{2}-\\frac{1}{\\hbar^{2} r^{2}}$$\n $$\\nabla_{\\Omega}^{2}=\\frac{1}{r^{2}} \\frac{\\partial}{\\partial r}\\left(r^{2} \\frac{\\partial}{\\partial r}\\right)-\\frac{1}{\\hbar^{2} r^{2}}$$ $$\\hat{\\vec{L}}^{2}=\\frac{1}{r} \\frac{\\partial^{2}}{\\partial r^{2}} r-\\frac{1}{\\hbar^{2} r^{2}} \\hat{\\vec{L}}^{2}\n$$\nwhere $\\hat{L}$ is the orbital angular momentum with\n$$\n\\hat{\\hat{L}}^{2}=-\\hbar^{2}\\left[\\frac{1}{\\sin \\theta} \\frac{\\partial}{\\partial \\theta}\\left(\\sin \\theta \\frac{\\partial}{\\partial \\theta}\\right)+\\frac{1}{\\sin ^{2} \\theta} \\frac{\\partial^{2}}{\\partial \\varphi^{2}}\\right] .\n$$\nIn spherical coordinates the Schrödinger equation therefore takes the form\n$$\n\\left[-\\frac{\\hbar^{2}}{2 M} \\frac{1}{r} \\frac{\\partial^{2}}{\\partial r^{2}} r+\\frac{1}{2 M r^{2}} \\hat{\\vec{L}}^{2}+V(r)\\right] \\psi(\\vec{r})=E \\psi(\\vec{r}) .\n$$\nThe first term of this equation can be viewed as the radial kinetic energy\n$$\n-\\frac{\\hbar^{2}}{2 M} \\frac{1}{r} \\frac{\\partial^{2}}{\\partial r^{2}} r=\\frac{\\hat{P}_{r}^{2}}{2 M},\n$$\nNow $\\hat{\\hat{L}}^{2}$ does not depends on r, it commute with both $\\vec{V}(r)$ and the radial KE.Hence it also commute with the Hamiltonian H . In addition since $L_z$ commute with $\\hat{\\hat{L}}^{2}$, the three operators H,$\\hat{\\hat{L}}^{2}$, and $L_z$ mutually commute:\n$$\n\\left[\\hat{H}, \\hat{\\vec{L}}^{2}\\right]=\\left[\\hat{H}, \\hat{L}_{z}\\right]=0 .\n$$\nThus $\\hat{H}, \\hat{\\vec{L}}^{2}$, and $\\hat{L}_{z}$ have common eigenfunctions. We know that the simultaneous eigenfunctions of $\\hat{\\vec{L}}^{2}$ and $\\hat{L}_{z}$ are given by the spherical harmonics $Y_{I m}(\\theta, \\varphi)$ :\n$$\n\\begin{aligned}\n&\\hat{\\vec{L}}^{2} Y_{l m}(\\theta, \\varphi)=l(l+1) \\hbar^{2} Y_{l m}(\\theta, \\varphi), \\\\\n&\\hat{L}_{z} Y_{l m}(\\theta, \\varphi)=m \\hbar Y_{l m}(\\theta, \\varphi) .\n\\end{aligned}\n$$\nSince the Hamiltonian is a sum of a radial part and an angular part, we can look for solutions that are products of a radial part and an angular part, where the angular part is simply the spherical harmonic $Y_{l m}(\\theta, \\varphi)$ :\n$$\n\\psi(\\vec{r})=\\langle\\vec{r} \\mid n l m\\rangle=\\psi_{n l m}(r, \\theta, \\varphi)=R_{n l}(r) Y_{I m}(\\theta, \\varphi) .\n$$\nNote that the orbital angular momentum of a system moving in a central potential is conserved,it commutes with the Hamiltonian.\n\nThe radial wave function $R_{n l}(r)$ has yet to be found. The quantum number $n$ is introduced to identify the eigenvalues of $\\hat{H}$ :\n$$\n\\hat{H}|n l m\\rangle=E_{n}|n l m\\rangle\n$$\nSubstituting $\\psi_{n l m}(r, \\theta, \\varphi)$ into schrodinger equation and using the fact that $\\psi_{n l m}(r, \\theta, \\varphi)$ is an eigenfunction of $\\hat{\\vec{L}}^{2}$ with eigenvalue $l(l+1) \\hbar^{2}$, then dividing through by $R_{n l}(r) Y_{l m}(\\theta, \\varphi)$ and multiplying by $2 M r^{2}$, we end up with an equation where the radial and angular degrees of freedom are separated:\n$$\n\\left[-\\hbar^{2} \\frac{r}{R_{n l}} \\frac{\\partial^{2}}{\\partial r^{2}}\\left(r R_{n l}\\right)+2 M r^{2}(V(r)-E)\\right]+\\left[\\frac{\\hat{\\vec{L}}^{2} Y_{l m}(\\theta, \\varphi)}{Y_{l m}(\\theta, \\varphi)}\\right]=0 \n$$\nThe terms inside the first square bracket are independent of $\\theta$ and $\\varphi$ and those of the second are independent of $r$. They must then be separately equal to constants and their sum equal to zero. The second square bracket is the the eigenvalue equation of $\\hat{\\vec{L}}^{2}$; hence it is equal to $l(l+1) \\hbar^{2} .$ As for the first bracket, it must be equal to $-l(l+1) \\hbar^{2}$; this leads to an equation known as the radial equation for a central potential:\n$$\n-\\frac{\\hbar^{2}}{2 M} \\frac{d^{2}}{d r^{2}}\\left(r R_{n l}(r)\\right)+\\left[V(r)+\\frac{l(l+1) \\hbar^{2}}{2 M r^{2}}\\right]\\left(r R_{n l}(r)\\right)=E_{n}\\left(r R_{n l}(r)\\right) .\n$$\nNote that the above equation, which gives the energy levels of the system, does not depend on the azimuthal quantum number $m$. Thus, the energy $E_{n}$ is $(2 l+1)$-fold degenerate.\n\\section{Hydrogen atom }\nSchrödinger's equation for the electron in three dimensions, which is what we must use for the hydrogen atom, is\n$$\n\\frac{\\partial^{2} \\psi}{\\partial x^{2}}+\\frac{\\partial^{2} \\psi}{\\partial y^{2}}+\\frac{\\partial^{2} \\psi}{\\partial z^{2}}+\\frac{2 m}{\\hbar^{2}}(E-U) \\psi=0\n$$\nThe potential energy $U$ here is the electric potential energy\nElectric potential\n$$\nU=-\\frac{e^{2}}{4 \\pi \\epsilon_{0} r}\n$$\nof a charge $-e$ when it is the distance $r$ from another charge $+e$.\\\\\nIn spherical polar coordinates Schrödinger's equation is written\n$$\n\\begin{aligned}\n\\frac{1}{r^{2}} \\frac{\\partial}{\\partial r}\\left(r^{2} \\frac{\\partial \\psi}{\\partial r}\\right)+\\frac{1}{r^{2} \\sin \\theta} \\frac{\\partial}{\\partial \\theta}\\left(\\sin \\theta \\frac{\\partial \\psi}{\\partial \\theta}\\right) &+\\frac{1}{r^{2} \\sin ^{2} \\theta} \\frac{\\partial^{2} \\psi}{\\partial \\phi^{2}}+\\frac{2 m}{\\hbar^{2}}(E-U) \\psi=0\n\\end{aligned}\n$$\nSubstituting  for the potential energy $U$ and multiplying the entire equation by $r^{2} \\sin ^{2} \\theta$, we obtain\n$$\n\\begin{aligned}\n\\text { Hydrogen atom } \\quad \\sin ^{2} \\theta \\frac{\\partial}{\\partial r}\\left(r^{2} \\frac{\\partial \\psi}{\\partial r}\\right) &+\\sin \\theta \\frac{\\partial}{\\partial \\theta}\\left(\\sin \\theta \\frac{\\partial \\psi}{\\partial \\theta}\\right) \\\\\n&+\\frac{\\partial^{2} \\psi}{\\partial \\phi^{2}}+\\frac{2 m r^{2} \\sin ^{2} \\theta}{\\hbar^{2}}\\left(\\frac{e^{2}}{4 \\pi \\epsilon_{0} r}+E\\right) \\psi=0\n\\end{aligned}\n$$\nEquation is the partial differential equation for the wave function $\\psi$ of the electron in a hydrogen atom. Together with the various conditions $\\psi$ must obey, namely that $\\psi$ be normalizable and that $\\psi$ and its derivatives be continuous and single-valued at each point $r, \\theta, \\phi$, this equation completely specifies the behavior of the electron.\n\\subsection{Seperation of variables}\nThe advantage of writing Schrödinger's equation in spherical polar coordinates for the problem of the hydrogen atom is that in this form it may be separated into three independent equations, each involving only a single coordinate. Such a separation is possible here because the wave function $\\psi(r, \\theta, \\phi)$ has the form of a product of three different functions: $R(r)$, which depends on $r$ alone; $\\Theta(\\theta)$ which depends on $\\theta$ alone; and $\\Phi(\\phi)$, which depends on $\\phi$ alone. Of course, we do not really know that this separation is possible yet, but we can proceed by assuming that\\\\\n$$\\psi(r, \\theta, \\phi)=R(r) \\Theta(\\theta) \\Phi(\\phi)$$\nwhich we may write more simply as\n$$\n\\psi=R \\Theta \\Phi\n$$\nwe see that\n$$\n\\begin{aligned}\n\\frac{\\partial \\psi}{\\partial r} &=\\Theta \\Phi \\frac{\\partial R}{\\partial r}=\\Theta \\Phi \\frac{d R}{d r} \\\\\n\\frac{\\partial \\psi}{\\partial \\theta} &=R \\Phi \\frac{\\partial \\Theta}{\\partial \\theta}=R \\Phi \\frac{d \\Theta}{d \\theta} \\\\\n\\frac{\\partial^{2} \\psi}{\\partial \\phi^{2}} &=R \\Theta \\frac{\\partial^{2} \\Phi}{\\partial \\phi^{2}}=R \\Theta \\frac{d^{2} \\Phi}{d \\phi^{2}}\n\\end{aligned}\n$$\nWhen we substitute $R \\Theta \\Phi$ for $\\psi$ in Schrödinger's equation for the hydrogen atom and divide the entire equation by $R \\Theta \\Phi$, we find that\n$$\n\\begin{aligned}\n\\frac{\\sin ^{2} \\theta}{R} \\frac{d}{d r}\\left(r^{2} \\frac{d R}{d r}\\right)+\\frac{\\sin \\theta}{\\Theta} \\frac{d}{d \\theta}\\left(\\sin \\theta \\frac{d \\Theta}{d \\theta}\\right) &+\\frac{1}{\\Phi} \\frac{d^{2} \\Phi}{d \\phi^{2}} \\\\\n&+\\frac{2 m r^{2} \\sin ^{2} \\theta}{\\hbar^{2}}\\left(\\frac{e^{2}}{4 \\pi \\epsilon_{0} r}+E\\right)=0\n\\end{aligned}\n$$\nThe third term  is a function of azimuth angle $\\phi$ only, whereas the other terms are functions of $r$ and $\\theta$ only.\nLet us rearrange the equation to read\n$$\n\\begin{aligned}\n\\frac{\\sin ^{2} \\theta}{R} \\frac{d}{d r}\\left(r^{2} \\frac{d R}{d r}\\right)+\\frac{\\sin \\theta}{\\Theta} \\frac{d}{d \\theta} &\\left(\\sin \\theta \\frac{d \\Theta}{d \\theta}\\right) \\\\\n&+\\frac{2 m r^{2} \\sin ^{2} \\theta}{\\hbar^{2}}\\left(\\frac{e^{2}}{4 \\pi \\epsilon_{0} r}+E\\right)=-\\frac{1}{\\Phi} \\frac{d^{2} \\Phi}{d \\phi^{2}}\n\\end{aligned}\n$$\nThis equation can be correct only if both sides of it are equal to the same constant, since they are functions of different variables. As we shall see, it is convenient to call this constant $m_{l}^{2}$. The differential equation for the function $\\phi$ is the refore\n$$\n-\\frac{1}{\\Phi} \\frac{d^{2} \\Phi}{d \\phi^{2}}=m_{l}^{2}\n$$\nNext we substitute $m_{l}^{2}$ for the right-hand side the last equation and divide the entire equation by $\\sin ^{2} \\theta$, and rearrange the various terms, which yields\n$$\n\\frac{1}{R} \\frac{d}{d r}\\left(r^{2} \\frac{d R}{d r}\\right)+\\frac{2 m r^{2}}{\\hbar^{2}}\\left(\\frac{e^{2}}{4 \\pi \\epsilon_{0} r}+E\\right)=\\frac{m_{l}^{2}}{\\sin ^{2} \\theta}-\\frac{1}{\\Theta \\sin \\theta} \\frac{d}{d \\theta}\\left(\\sin \\theta \\frac{d \\Theta}{d \\theta}\\right)\n$$\nAgain we have an equation in which different variables appear on each side, requiring that both sides be equal to the same constant. This constant is called $l(l+1)$, once more for reasons that will be apparent later. The equations for the functions $\\Theta$ and $R$ are therefore\\\\\n$$\\begin{gathered}\n\\frac{m_{l}^{2}}{\\sin ^{2} \\theta}-\\frac{1}{\\Theta \\sin \\theta} \\frac{d}{d \\theta}\\left(\\sin \\theta \\frac{d \\Theta}{d \\theta}\\right)=l(l+1) \\\\\n\\frac{1}{R} \\frac{d}{d r}\\left(r^{2} \\frac{d R}{d r}\\right)+\\frac{2 m r^{2}}{\\hbar^{2}}\\left(\\frac{e^{2}}{4 \\pi \\epsilon_{0} r}+E\\right)=l(l+1)\n\\end{gathered}$$\nEquation for $\\Phi$ $$\\frac{d^{2} \\Phi}{d \\phi^{2}}+m_{l}^{2} \\Phi=0$$\nEquation\nfor $\\boldsymbol{\\theta}$\n$$\\frac{1}{\\sin \\theta} \\frac{d}{d \\theta}\\left(\\sin \\theta \\frac{d \\Theta}{d \\theta}\\right)+\\left[l(l+1)-\\frac{m_{l}^{2}}{\\sin ^{2} \\theta}\\right] \\Theta=0$$\nEquation\nfor $R$\n$$\\frac{1}{r^{2}} \\frac{d}{d r}\\left(r^{2} \\frac{d R}{d r}\\right)+\\left[\\frac{2 m}{\\hbar^{2}}\\left(\\frac{e^{2}}{4 \\pi \\epsilon_{0} r}+E\\right)-\\frac{l(l+1)}{r^{2}}\\right] R=0$$\n\\subsection{Quantum numbers}\n\\textbf{magnetic quantum number}\n$$\\Phi(\\phi)=A e^{i m_{l} \\phi}$$\nAs we know, one of the conditions that a wave function-and hence $\\Phi$, which is a component of the complete wave function $\\psi$-must obey is that it have a single value at a given point in space.We konw that $\\phi$ and $\\phi+2 \\pi$ both identify the same meridian plane. Hence it must be true that $\\Phi(\\phi)=$ $\\Phi(\\phi+2 \\pi)$, or\n$$A e^{i m_{l} \\phi}=A e^{i m_{l}(\\phi+2 \\pi)}$$\nwhich can happen only when $m_{l}$ is 0 or a positive or negative integer $(\\pm 1$, $\\pm 2, \\pm 3$....). The constant $m_{l}$ is known as the magnetic quantum number of the hydrogen atom.\\\\\nThe differential equation for $\\Theta(\\theta)$, has a solution provided that the constant $l$ is an integer equal to or greater than $\\left|m_{l}\\right|$, the absolute value of $m_{l}$. This requirement can be expressed as a condition on $m_{l}$ in the form\n$$\nm_{l}=0, \\pm 1, \\pm 2, \\ldots, \\pm l\n$$\nThe constant $l$ is known as the \\textbf{orbital quantum number}\\\\\nAn atomic electron that possesses angular momentum interacts with an external magnetic field $\\mathbf{B}$. The magnetic quantum number $m_{l}$ specifies the direction of $\\mathbf{L}$ by determining the component of $\\mathbf{L}$ in the field direction. This phenomenon is often referred to as space quantization.\n\nIf we let the magnetic-field direction be parallel to the $z$ axis, the component of $\\mathbf{L}$ in this direction is\nSpace quantization $$L_{z}=m_{l} \\hbar \\quad m_{l}=0, \\pm 1, \\pm 2, \\ldots, \\pm l$$\nThe possible values of $m_{l}$ for a given value of $l$ range from $+l$ through 0 to $-l$, so that the number of possible orientations of the angular-momentum vector $\\mathbf{L}$ in a magnetic field is $2 l+1$. When $l=0, L_{z}$ can have only the single value of 0 ; when $l=1, L_{z}$ may be $\\hbar, 0$, or $-\\hbar$; when $l=2, L_{z}$ may be $2 \\hbar, \\hbar, 0,-\\hbar$, or $-2 \\hbar ;$ and so on.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=6cm,width=8cm]{jamshi 6-crop}\n\t\\caption{Space quantization of orbital angular momentum with (l=2)}\n\t\\label{}\n\\end{figure}\n\\subsubsection{Orbital quantum mumber}\nElectron angular momenta \n$$\nL=\\sqrt{l(l+1)} \\hbar\n$$\nmomentum\nWith the orbital quantum number $l$ restricted to the values\n$$\nl=0,1,2, \\ldots,(n-1)\n$$\nThe electron can have only the angular momenta $L$ specified by $\nL=\\sqrt{l(l+1)} \\hbar\n$, Like total energy E, angular momentum is both conserved and quantized. The quantity\n$$\n\\hbar=\\frac{h}{2 \\pi}=1.054 \\times 10^{-34} \\mathrm{~J} \\cdot \\mathrm{s}\n$$\nis thus the natural unit of angular momentum.\\\\\n\\textbf { Designation of Angular-Momentum States }\\\\\nIt is customary to specify electron angular-momentum states by a letter, with $s$ corresponding to $l=0, p$ to $l=1$, and so on, according to the following scheme:\\\\\n$\\begin{array}{rlllllll}\n\tl=0 & 1 & 2 & 3 & 4 & 5 & 6 & \\ldots \\\\\n\ts & p & d & f & g & h & i & \\ldots\n\\end{array}$\\\\\n$\\begin{aligned}\n\t&\\text { Table of Atomic Electron States }\\\\\n\t&\\begin{array}{lcccccc}\n\t\t\\hline & I=0 & I=1 & I=2 & I=3 & I=4 & I=5 \\\\\n\t\t\\hline n=1 & 1 s & & & & & \\\\\n\t\tn=2 & 2 s & 2 p & & & & \\\\\n\t\tn=3 & 3 s & 3 p & 3 d & & & \\\\\n\t\tn=4 & 4 s & 4 p & 4 d & 4 f & & \\\\\n\t\tn=5 & 5 s & 5 p & 5 d & 5 f & 5 g & \\\\\n\t\tn=6 & 6 s & 6 p & 6 d & 6 f & 6 g & 6 h \\\\\n\t\t\\hline\n\t\\end{array}\n\\end{aligned}$\\\\\n\\textbf{Principal quantum number}\\\\\n For the radial part $R(r)$ of the hydrogenatom wave function $\\psi$ also requires that a certain condition be fulfilled. This condition is that $E$ be positive or have one of the negative values $E_{n}$ (signifying that the electron is bound to the atom) specified by\n$$\nE_{n}=-\\frac{m e^{4}}{32 \\pi^{2} \\epsilon_{0}^{2} \\hbar^{2}}\\left(\\frac{1}{n^{2}}\\right)=\\frac{E_{1}}{n^{2}} \\quad n=1,2,3, \\ldots\n$$\nAnother condition that must be obeyed in order to solve radial equation is that $n$, known as the principal quantum number, must be equal to or greater than $l+1$. This requirement may be expressed as a condition on $l$ in the form\n$$\nl=0,1,2, \\ldots,(n-1)\n$$\nHence we may tabulate the three quantum numbers $n, l$, and $m$ together with their permissible values as follows:\\\\\n$$\\begin{array}{lc}\n\t\\text { Principal quantum number } & n=1,2,3, \\ldots \\\\\n\t\\text { Orbital quantum number } & l=0,1,2, \\ldots,(n-1) \\\\\n\t\\text { Magnetic quantum number } & m_{l}=0, \\pm 1, \\pm 2, \\ldots, \\pm l\n\\end{array}$$\nTo exhibit the dependence of $R, \\Theta$, and $\\Phi$ upon the quantum numbers $n, l, m$, we may write for the electron wave functions of the hydrogen atom\n$$\n\\psi=R_{n l} \\Theta_{l m_{l}} \\Phi_{m_{l}}\n$$\n\\subsection{Normalized wavefunction of the Hydrogen atom for n=1,2,3.}\n$\\begin{array}{ccccccc}\n\t\\hline n & l & m_{l} & \\Phi(\\phi) & \\theta(\\theta) & R(r) & \\psi(r, \\theta, \\phi) \\\\\n\t\\hline 1 & 0 & 0 & \\frac{1}{\\sqrt{2 \\pi}} & \\frac{1}{\\sqrt{2}} & \\frac{2}{a_{0}^{3 / 2}} e^{-r / a_{0}} & \\frac{1}{\\sqrt{\\pi} a_{0}^{3 / 2}} e^{-r / a_{0}} \\\\\n\t2 & 0 & 0 & \\frac{1}{\\sqrt{2 \\pi}} & \\frac{1}{\\sqrt{2}} & \\frac{1}{2 \\sqrt{2} a_{0}^{3 / 2}}\\left(2-\\frac{r}{a_{0}}\\right) e^{-r / 2 a_{0}} & \\frac{1}{4 \\sqrt{2 \\pi} a_{0}^{3 / 2}}\\left(2-\\frac{r}{a_{0}}\\right) e^{-r / 2 a_{0}} \\\\\n\t2 & 1 & 0 & \\frac{1}{\\sqrt{2 \\pi}} & \\frac{\\sqrt{6}}{2} \\cos \\theta & \\frac{1}{2 \\sqrt{6} a_{0}^{3 / 2}} \\frac{r}{a_{0}} e^{-r / 2 a_{0}} & \\frac{1}{4 \\sqrt{2 \\pi} a_{0}^{3 / 2}} \\frac{r}{a_{0}} e^{-r / 2 a_{0}} \\cos \\theta \\\\\n\t2 & 1 & \\pm 1 & \\frac{1}{\\sqrt{2 \\pi}} e^{\\pm i \\phi} & \\frac{\\sqrt{3}}{2} \\sin \\theta & \\frac{1}{2 \\sqrt{6} a_{0}^{3 / 2}} \\frac{r}{a_{0}} e^{-r / 2 a_{0}} & \\frac{1}{8 \\sqrt{\\pi} a_{0}^{3 / 2}} \\frac{r}{a_{0}} e^{-r / 2 a_{0}} \\sin \\theta e^{\\pm i \\phi}\\\\\n\t3&0&0&\\frac{1}{\\sqrt{2 \\pi}}& \\frac{1}{\\sqrt{2}}&\\frac{2}{81 \\sqrt{3} a_{0}^{3 / 2}}\\left(27-18 \\frac{r}{a_{0}}+2 \\frac{r^{2}}{a_{0}^{2}}\\right) e^{-r / 3 a_{0}} &\\frac{1}{81 \\sqrt{3 \\pi} a_{0}^{3 / 2}}\\left(27-18 \\frac{r}{a_{0}}+2 \\frac{r^{2}}{a_{0}^{2}}\\right) e^{-r / 3 a_{0}}\\\\\n\t3& 1&  0 &\\frac{1}{\\sqrt{2 \\pi}} & \\frac{\\sqrt{6}}{2} \\cos \\theta & \\frac{4}{81 \\sqrt{6} a_{0}^{3 / 2}}\\left(6-\\frac{r}{a_{0}}\\right) \\frac{r}{a_{0}} e^{-r / 3 a_{0}} &\\frac{\\sqrt{2}}{81 \\sqrt{\\pi} a_{0}^{3 / 2}}\\left(6-\\frac{r}{a_{0}}\\right) \\frac{r}{a_{0}} e^{-r / 3 a_{0}} \\cos \\theta\\\\\n\t3 &1 & \\pm 1 & \\frac{1}{\\sqrt{2 \\pi}} e^{\\pm i \\phi} &\\frac{\\sqrt{3}}{2} \\sin \\theta & \\frac{4}{81 \\sqrt{6} a_{0}^{3 / 2}}\\left(6-\\frac{r}{a_{0}}\\right) \\frac{r}{a_{0}} e^{-r / 3 a_{0}} & \\frac{1}{81 \\sqrt{\\pi} a_{0}^{3 / 2}}\\left(6-\\frac{r}{a_{0}}\\right) \\frac{r}{a_{0}} e^{-r / 3 a_{0}} \\sin \\theta e^{\\pm i \\phi}\\\\\n\t3&2&0 & \\frac{1}{\\sqrt{2 \\pi}} & \\frac{\\sqrt{10}}{4}\\left(3 \\cos ^{2} \\theta-1\\right) & \\frac{4}{81 \\sqrt{30} a_{0}^{3 / 2}} \\frac{r^{2}}{a_{0}^{2}} e^{-r / 3 a_{0}} & \\frac{1}{81 \\sqrt{6 \\pi} a_{0}^{3 / 2}} \\frac{r^{2}}{a_{0}^{2}} e^{-r / 3 a_{0}}\\left(3 \\cos ^{2} \\theta-1\\right)\\\\\n\t3 & 2 & \\pm 1 & \\frac{1}{\\sqrt{2 \\pi}} e^{\\pm i \\phi} & \\frac{\\sqrt{15}}{2} \\sin \\theta \\cos \\theta & \\frac{4}{81 \\sqrt{30} a_{0}^{3 / 2}} \\frac{r^{2}}{a_{0}^{2}} e^{-r / 3 a_{0}} & \\frac{1}{81 \\sqrt{\\pi} a_{0}^{3 / 2}} \\frac{r^{2}}{a_{0}^{2}} e^{-r / 3 a_{o}} \\sin \\theta \\cos \\theta e^{\\pm i \\phi}\\\\\n\t3 & 2 &\\pm 2 & \\frac{1}{\\sqrt{2 \\pi}} e^{\\pm 2 i \\phi} & \\frac{\\sqrt{15}}{4} \\sin ^{2} \\theta&\\frac{4}{81 \\sqrt{30} a_{0}^{3 / 2}} \\frac{r^{2}}{a_{0}^{2}} e^{-r / 3 a_{0}} & \\frac{1}{162 \\sqrt{\\pi} a_{0}^{3 / 2}} \\frac{r^{2}}{a_{0}^{2}} e^{-r / 3 a_{0}} \\sin ^{2} \\theta e^{\\pm 2 i \\phi}\n\\end{array}$\n\\subsection{Electron probability density}\nThe probability density $|\\psi|^{2}$ that corresponds to the electron wave function $\\psi=R \\Theta \\Phi$ in the hydrogen atom is\n|$$\\psi|^{2}=|\\mathrm{R}|^{2}|\\Theta|^{2}|\\Phi|^{2}$$\nwe see that the azimuthal wave function is given by\n$$\n\\Phi(\\phi)=A e^{i m_{\\ell} \\phi}\n$$\nThe azimuthal probability density $|\\Phi|^{2}$ is therefore\n$$\n|\\Phi|^{2}=\\Phi^{*} \\Phi=A^{2} e^{-i m_{1} \\phi} e^{i m_{1} \\phi}=A^{2} e^{0}=A^{2}\n$$\nThe likelihood of finding the electron at a particular azimuth angle $\\phi$ is a constant that does not depend upon $\\phi$ at all. The electron's probability density is symmetrical about the $z$ axis regardless of the quantum state it is in, and the electron has the same chance of being found at one angle $\\phi$ as at another.\\\\\n\\par The probability density of the electron at the point $r, \\theta, \\phi$ is proportional to $|\\psi|^{2}$, but the actual probability of finding it in the infinitesimal volume element $d V$ there is $|\\psi|^{2} d V$. In spherical polar coordinates  $\\begin{aligned} d V &=(d r)(r d \\theta)(r \\sin \\theta d \\phi) \\\\ &=r^{2} \\sin \\theta d r d \\theta d \\phi \\end{aligned}$\\\\\nAs $\\Theta$ and $\\Phi$ are normalized functions, the actual probability $P(r) d r$ of finding the electron in a hydrogen atom somewhere in the spherical shell between $r$ and $r+d r$ from the nucleus is\n$$\n\\begin{aligned}\nP(r) d r &=r^{2}|R|^{2} d r \\int_{0}^{\\pi}|\\Theta|^{2} \\sin \\theta d \\theta \\int_{0}^{2 \\pi}|\\Phi|^{2} d \\phi \\\\\n&=r^{2}|R|^{2} d r\n\\end{aligned}\n$$\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=8cm,width=11cm]{diagram-20220115(7)}\n\t\\caption{The probability of finding the electron in a hydrogen atom at a distance between $r$ and $r+d r$ from the nucleus for the quantum states.}\n\\end{figure}\n\\subsection{ Degeneracy of Hydrogen atom}\nIf spin of the electron is not included then degeneracy of atom is $\\sum_{i=0}^{n-1}(2 l+1)=n^{2}$\\\\\nIf spin of the electron is included then degeneracy of atom is $2 \\sum_{l=0}^{n-1}(2 l+1)=2 n^{2}$\n\n\\begin{exercise}\n\t$\\text { Verify that the average value of } 1 / r \\text { for a } 1 \\text { s electron in the hydrogen atom is } 1 / a_{0} \\text {. }$\n\\end{exercise}\n\\begin{answer}\nThe wave function of a ls electron is,\n$$\n\\psi=\\frac{e^{-r / a_{0}}}{\\sqrt{\\pi} a_{0}^{3 / 2}}\n$$\nSince $d V=r^{2} \\sin \\theta d r d \\theta d \\phi$ we have for the expectation value of $1 / r$\n$$\n\\begin{aligned}\n\\left\\langle\\frac{1}{r}\\right\\rangle &=\\int_{0}^{\\infty}\\left(\\frac{1}{r}\\right)|\\psi|^{2} d V \\\\\n&=\\frac{1}{\\pi a_{0}^{3}} \\int_{0}^{\\infty} r e^{-2 r / a_{0}} d r \\int_{0}^{\\pi} \\sin \\theta d \\theta \\int_{0}^{2 \\pi} d \\phi\n\\end{aligned}\n$$\nThe integrals have the respective values\n$$\n\\begin{gathered}\n\\int_{0}^{\\infty} r e^{-2 r / a_{0}} d r=\\left[\\frac{a_{0}^{2}}{4} e^{-2 r / a_{0}}-\\frac{r}{2} e^{-2 r / a_{0}}\\right]_{0}^{\\infty}=\\frac{a_{0}^{2}}{4} \\\\\n\\int_{0}^{\\pi} \\sin \\theta d \\theta=[-\\cos \\theta]_{0}^{\\pi}=2 \\\\\n\\int_{0}^{2 \\pi} d \\phi=[\\phi]_{0}^{2 \\pi}=2 \\pi \\\\\n\\left\\langle\\frac{1}{r}\\right\\rangle=\\left(\\frac{1}{\\pi a_{0}^{3}}\\right)\\left(\\frac{a_{0}^{2}}{4}\\right)(2)(2 \\pi)=\\frac{1}{a_{0}}\n\\end{gathered}\n$$\t\n\\end{answer}\n\\begin{exercise}\n Show that the most probable distance by the electron from the nucleus in the ground state of hydrogen atom is equal to the Bohr's radius.\n\\end{exercise}\n\\begin{answer}\nFor the ground state of hydrogen atom, $n=1, \\ell=0$ and $m=0$. Hence the ground state wave function is,\n$$\n\\psi_{1,0,0}=\\left(\\frac{1}{\\pi a_{0}^{3}}\\right)^{1 / 2} e^{-r / a_{0}}\n$$\nSince, the wave function is independent of $\\theta$ and $\\phi$, therefore,\\\\\nRadial probability density $=P(r)=\\left|\\psi_{100}\\right|^{2} 4 \\pi r^{2}=\\frac{4}{a_{0}^{3}} e^{-2 r / a_{0}} r^{2}$\nFor most probable distance, $P(r)$ is to be the maximum\n$$\n\\frac{d P}{d r}=\\frac{4}{a_{0}^{3}}\\left[r^{2}\\left(-\\frac{2}{a_{0}}\\right) e^{-2 r / a_{0}}+2 r e^{-2 r / a_{0}}\\right]=0 \\Rightarrow r=a_{0}\n$$\nThus the most probable distance of the electron from the nucleus of hydrogen atom in the ground state is equal tothe Bohr radius $\\left(a_{0}\\right)$.\t\n\\end{answer}\n\\begin{exercise}\n If the ground state wave function for the hydrogen atom is\n\t$$\n\t\\psi=\\frac{1}{\\sqrt{\\pi}} \\frac{1}{a_{0}^{3 / 2}} e^{-r / a_{0}}\n\t$$\n\tshow that average distance of the electron from the nucleus is $1.5 \\mathrm{a}_{0}$.\n\\end{exercise}\n\\begin{answer}\n\tWe have the average distance of the electron from the hydrogen nucleus in the ground state is,\n\t$$\n\t\\begin{aligned}\n\t\\langle r\\rangle &=\\int_{0}^{\\infty} \\psi^{*} \\hat{r} \\psi d r=\\int_{0}^{\\infty} \\frac{1}{\\sqrt{\\pi}} \\frac{1}{a_{0}^{3 / 2}} e^{-r / a_{0}} r \\frac{1}{\\sqrt{\\pi}} \\frac{1}{a_{0}^{3 / 2}} e^{-r / a_{0}} d \\tau \\\\\n\t&=\\frac{1}{\\pi a_{0}^{3}} \\int_{0}^{\\infty} r e^{-2 r / a_{0}} r^{2} \\sin \\theta d r d \\theta d \\phi\n\t\\end{aligned}\n\t$$\n\tUsing the standard integral $\\int_{0}^{\\infty} e^{-a x} x^{n} d x=\\frac{n !}{a^{n+1}}$, we get\n\t$$\n\t\\langle r\\rangle=\\frac{1}{\\pi a_{0}^{3}} \\int_{0}^{\\infty} r^{3} e^{-2 r / a_{0}} d r \\int_{0}^{\\pi} \\sin \\theta d \\theta \\int_{0}^{2 \\pi} d \\phi=\\frac{1}{\\pi a_{0}^{3}} \\times \\frac{3 !}{\\left(2 / a_{0}\\right)^{4}} \\times 2 \\times 2 \\pi\n\t$$\n\tTherefore, $\\langle r\\rangle=\\frac{3}{2} a_{0}=1.5 a_{0}$\n\\end{answer}\n\\begin{exercise}\n\t What is the expectation value of the knetice nergy $\\left(E^{2}\\right)$ of the electron in the 1s state of the hydrogen atom?\n\\end{exercise}\n\\begin{answer}\n\tThe expectation value of the kinetic energy is,\n\t$$\n\t\\left\\langle E_{k}\\right\\rangle=\\int_{\\tau} \\psi_{1,0,0}^{*} \\hat{E}_{k} \\psi_{1,0,0} d \\tau=\\int_{0}^{\\infty} \\int_{0}^{\\pi} \\int_{0}^{2 \\pi} \\psi_{1,0,0} \\hat{E}_{k} \\psi_{1,0,0} r^{2} \\sin \\theta d r d \\theta d \\phi\n\t$$\n\tBut, $\\quad \\vec{E}_{k}=-\\frac{\\hbar^{2}}{2 m} \\nabla^{2}=-\\frac{\\hbar^{2}}{2 m}\\left[\\frac{1}{r^{2}} \\frac{\\partial}{\\partial r} r^{2} \\frac{\\partial}{\\partial r}+\\frac{1}{r^{2} \\sin \\theta} \\frac{\\partial}{\\partial \\theta} \\sin \\theta \\frac{\\partial}{\\partial \\theta}+\\frac{1}{r^{2} \\sin ^{2} \\theta} \\frac{\\partial^{2}}{\\partial \\phi^{2}}\\right]$\\\\\n\tSince $\\psi_{1,0,0}$ depends on $r$ only, the terms in $\\frac{\\partial}{\\partial \\theta}$ and $\\frac{\\partial}{\\partial \\phi}$ are zero.\\\\\n\t$$\\left\\langle E_{k}\\right\\rangle=-\\frac{\\hbar^{2}}{2 m} \\cdot 4 \\pi\\left(\\frac{1}{\\sqrt{\\pi} a_{0}^{3}}\\right)^{2} \\int_{0}^{\\infty} e^{-r / a_{0}} \\times\\left\\{\\left(\\frac{\\partial^{2}}{\\partial r^{2}}+\\frac{2}{r} \\frac{\\partial}{\\partial r}\\right) e^{-r / a_{0}}\\right\\} r^{2} d r$$\n\t$$\\begin{aligned}\n\t\t&=-\\frac{\\hbar^{2}}{2 m} \\frac{4}{a_{0}^{3}} \\int_{0}^{\\infty}\\left(\\frac{1}{a_{0}^{2}}-\\frac{2}{r a_{0}}\\right) e^{-2 r / a_{0}} r^{2} d r \\\\\n\t\t&=-\\frac{2 \\hbar^{2}}{m a_{0}^{3}}\\left[\\frac{1}{a_{0}^{2}} \\int_{0}^{\\infty} r^{2} e^{-2 r / a_{0}} d r-\\frac{2}{a_{0}} \\int_{0}^{\\infty} r e^{-2 r / a_{0}} d r\\right] \\\\\n\t\t&=-\\frac{2 \\hbar^{2}}{m a_{0}^{3}}\\left[\\frac{1}{a_{0}^{2}} \\frac{2}{\\left(2 / a_{0}\\right)^{3}}-\\frac{2}{a_{0}} \\frac{1}{\\left(2 / a_{0}\\right)^{2}}\\right]=\\frac{2 \\hbar^{2}}{m a_{0}^{3}} \\cdot \\frac{a_{0}}{4}\n\t\\end{aligned}$$\n\t$\\text { Therefore, }\\left\\langle E_{k}\\right\\rangle=\\frac{\\hbar^{2}}{2 m a_{0}^{3}}=\\frac{\\hbar^{2}}{2 m}\\left(\\frac{m e^{2}}{\\hbar^{2}}\\right)=\\frac{m e^{4}}{2 \\hbar^{2}}$\n\\end{answer}\n\\begin{exercise}\n Estimate the uncertainity in the radial position of the electron in the ground state of hydrogen atom.\n\\end{exercise}\n\\begin{answer}\nFor ground state\\\\\n$$\\langle r \\rangle =\\frac{4}{a_0^3}\t\\int_{0}^{\\infty} r^3 e^{\\frac{-2r}{a_0}}dr=\\frac{3a_0}{2}$$\n$$\\langle r^2 \\rangle =\\frac{4}{a_0^3}\t\\int_{0}^{\\infty} r^4 e^{\\frac{-2r}{a_0}}dr=3a_0^2$$\nuncertainity in the radial position of the particle will be \\\\\n$$\\Delta r=\\sqrt{\\langle r^2 \\rangle-\\langle r \\rangle^2}=\\frac{\\sqrt{3}}{2}a_0$$\n\\end{answer}\n\\begin{exercise}\n\tFind the positions of maxima of the radial probability curves for 1s,2s,2p and 3d orbitals of the hydrogen like atom \n\\end{exercise}\n\\begin{answer}\n\tThe radial probability density \\\\\n\t$$P_{nl}=r^2|R_{nl}|^2$$\n\t$$R_{10}=Constant \\times e^{-Zr/a_0}$$\n\t$$R_{21}=Constant \\times e^{-Zr/2a_0}$$\n\t$$R_{32}=Constant \\times e^{-Zr/3a_0}$$\n\t$P_{nl}$ will be maximum when $\\frac{dP_{nl}}{dr}=0$ hence \\\\\n\t$$\\frac{dP_{10}}{dr}=0 \\implies C(2r-\\frac{2Zr^2}{a_0})e^{\\frac{-2Zr}{a_0}}=0$$\n\t$$\\implies r=\\frac{a_0}{Z}$$\n\t$$\\frac{dP{21}}{dr}=0\\implies C(4r^3-\\frac{Zr^4}{a_0})e^{\\frac{-Zr}{a_0}}=0$$\n\t$$\\implies r=\\frac{4a_0}{Z}$$\n\tSimilarly $\\frac{dP_{32}}{dr}=0\\implies r=\\frac{9a_0}{2}$\\\\\n\tIn general $r_{max}=\\frac{n^2a_0}{2}$\n\\end{answer}\n\\begin{exercise}\n\t At time $t=0$, the wave function for the hydrogen atom is\n\t$$\n\t\\psi(r, 0)=\\frac{1}{\\sqrt{10}}\\left(2 \\psi_{100}+\\psi_{210}+\\sqrt{2} \\psi_{211}+\\sqrt{3} \\psi_{21,-1}\\right)\n\t$$\n\twhere the subscripts are values of the quantum numbers $n, l, m$. (i) What is the expectation value for the energy of the system? (ii) What is the probability of finding the system with $l=1, m=1$ ? .\n\\end{exercise}\n\\begin{answer}\n\tExpectation value $=\\langle E \\rangle =\\langle \\psi |H|\\psi\\rangle$\\\\\n$$=\\frac{1}{10}\\left\\langle \\left(2 \\psi_{100}+\\psi_{210}+\\sqrt{2} \\psi_{211}+\\sqrt{3} \\psi_{21,-1}\\right)|H|\\left(2 \\psi_{100}+\\psi_{210}+\\sqrt{2} \\psi_{211}+\\sqrt{3} \\psi_{21,-1}\\right)\\right\\rangle $$\n$$=\\frac{1}{10}\\left\\langle \\left(2 \\psi_{100}+\\psi_{210}+\\sqrt{2} \\psi_{211}+\\sqrt{3} \\psi_{21,-1}\\right)|\\left(2E_1 \\psi_{100}+E_2\\psi_{210}+\\sqrt{2} E_2\\psi_{211}+\\sqrt{3}E_2 \\psi_{21,-1}\\right)\\right\\rangle $$\n$$=\\frac{1}{10}\\left( 4E_1+E_2+2E_2+3E_2\\right) =\\frac{1}{10}\\left[ 4E_1+6E_2\\right] $$\n$$E_1=-13.6eV \\quad E_2=-3.4eV$$\n$$\\langle E \\rangle=-74.8eV$$\n\\end{answer}\n\n\n\n\\newpage\n\\begin{abox}\n\tPractice set 1\n\t\\end{abox}\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\t\\item The energy levels of the non-relativistic electron in a hydrogen atom (i.e. in a Coulomb potential $V(r) \\propto-1 / r$ ) are given by $E_{n l m} \\propto-1 / n^{2}$, where $n$ is the principal quantum number, and the corresponding wave functions are given by $\\psi_{n l m}$, where $l$ is the orbital angular momentum quantum number and $m$ is the magnetic quantum number. The spin of the electron is not considered. Which of the following is a correct statement?\n\t\t\\exyear{NET JUNE 2011}\n\t\\end{minipage}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] There are exactly $(2 l+1)$ different wave functions $\\psi_{n l m}$, for each $E_{n l m}$.\n\t\t\\task[\\textbf{B.}]There are $l(l+1)$ different wave functions $\\psi_{n l m}$, for each $E_{n l m}$.\n\t\t\\task[\\textbf{C.}] $E_{n l m}$ does not depend on $l$ and $m$ for the Coulomb potential.\n\t\t\\task[\\textbf{D.}]There is a unique wave function $\\psi_{n l m}$ for each $E_{n l m}$.\n\t\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Let $\\psi_{n l m_{l}}$ denote the eigenfunctions of a Hamiltonian for a spherically symmetric potential $V(r)$. The wavefunction $\\psi=\\frac{1}{4}\\left[\\psi_{210}+\\sqrt{5} \\psi_{21-1}+\\sqrt{10} \\psi_{211}\\right]$ is an eigenfunction only of\n\t\\exyear{NET JUNE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $H, L^{2}$ and $L_{2}$\n\t\\task[\\textbf{B.}]$H$ and $L_{z}$\n\t\\task[\\textbf{C.}]$H$ and $L^{2}$\n\t\\task[\\textbf{D.}]$L^{2}$ and $L_{z}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The wave function of a state of the Hydrogen atom is given by,\n\t$$\n\t\\psi=\\psi_{200}+2 \\psi_{211}+3 \\psi_{210}+\\sqrt{2} \\psi_{21-1}\n\t$$\n\twhere $\\psi_{n l m}$ is the normalized eigen function of the state with quantum numbers $n, l, m$ in the usual notation. The expectation value of $L_{z}$ in the state $\\psi$ is\n\t\\exyear{NET DEC 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{15 \\hbar}{6}$\n\t\\task[\\textbf{B.}]$\\frac{11 \\hbar}{6}$\n\t\\task[\\textbf{C.}]$\\frac{3 \\hbar}{8}$\n\t\\task[\\textbf{D.}]$\\frac{\\hbar}{8}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Let $\\psi_{n l m}$ denote the eigenfunctions of a Hamiltonian for a spherically symmetric potential $V(r)$. The expectation value of $L_{z}$ in the state\n\t$$\\psi=\\frac{1}{6}\\left[\\psi_{200}+\\sqrt{5} \\psi_{210}+\\sqrt{10} \\psi_{21-1}+\\sqrt{20} \\psi_{211}\\right] \\text { is }$$\n\t\\exyear{NET DEC 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-\\frac{5}{18} \\hbar$\n\t\\task[\\textbf{B.}]$\\frac{5}{6} \\hbar$\n\t\\task[\\textbf{C.}]$\\hbar$\n\t\\task[\\textbf{D.}] $\\frac{5}{18} \\hbar$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item An electron is in the ground state of a hydrogen atom. The probability that it is within the Bohr radius is approximately equal to\n\t\\exyear{NET JUNE 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $0.60$\n\t\\task[\\textbf{B.}] $0.90$\n\t\\task[\\textbf{C.}]$0.16$\n\t\\task[\\textbf{D.}]$0.32$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Let $\\psi_{\\text {nlm }}$ denote the eigenstates of a hydrogen atom in the usual notation. The state\n\t$$\n\t\\frac{1}{5}\\left[2 \\psi_{200}-3 \\psi_{211}+\\sqrt{7} \\psi_{210}-\\sqrt{5} \\psi_{21-1}\\right]\n\t$$\n\tis an eigenstate of\n\t\\exyear{NET DEC 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $L^{2}$, but not of the Hamiltonian or $L_{z}$\n\t\\task[\\textbf{B.}]the Hamiltonian, but not of $L^{2}$ or $L_{z}$\n\t\\task[\\textbf{C.}]the Hamiltonian, $L^{2}$ and $L_{z}$\n\t\\task[\\textbf{D.}]$L^{2}$ and $L_{z}$, but not of the Hamiltonian\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item If the position of the electron in the ground state of a Hydrogen atom is measured, the probability that it will be found at a distance $r \\geq a_{0}$ ( $a_{0}$ being Bohr radius) is nearest to\n\t\\exyear{NET DEC 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $0.91$ \n\t\\task[\\textbf{B.}] $0.66$\n\t\\task[\\textbf{C.}] $0.32$\n\t\\task[\\textbf{D.}]$0.13$\n\\end{tasks}\n\\end{enumerate}\n\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{c}&2&\\textbf{c}\\\\\\hline\n\t\t3&\\textbf{d}&4&\\textbf{d}\\\\\\hline\n\t\t5&\\textbf{d}&6&\\textbf{b}\\\\\\hline\n\t\t7&\\textbf{b}&&\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\newpage\n\\begin{abox}\n\tPractice set 2\n\t\\end{abox}\n\\begin{enumerate}\n\\begin{minipage}{\\textwidth}\n\t\\item The normalized ground state wavefunciton of a hydrogen atom is given by $\\psi(r)=\\frac{1}{\\sqrt{4 \\pi}} \\frac{2}{a^{3 / 2}} e^{-r / a}$, where $a$ is the Bohr radius and $r$ is the distance of the electron from the nucleus, located at the origin. The expectation value $\\left\\langle\\frac{1}{r^{2}}\\right\\rangle$ is\n\t\\exyear{GATE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{8 \\pi}{a^{2}}$\n\t\\task[\\textbf{B.}]$\\frac{4 \\pi}{a^{2}}$\n\t\\task[\\textbf{C.}]$\\frac{4}{a^{2}}$\n\t\\task[\\textbf{D.}]$\\frac{2}{a^{2}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The ground state wavefunction for the hydrogen atom is given by $\\psi_{100}=\\frac{1}{\\sqrt{4 \\pi}}\\left(\\frac{1}{a_{0}}\\right)^{3 / 2} e^{-r / a_{0}}$, where $a_{0}$ is the Bohr radius. The plot of the radial probability density, $P(r)$ for the hydrogen atom in the ground state is\n\t\\exyear{GATE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210824(2)-crop}\n\t\t\n\t\\end{figure}\n\t\\task[\\textbf{B.}]\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210824(3)-crop}\n\t\t\n\t\\end{figure}\n\t\\task[\\textbf{C.}]\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210824(4)-crop}\n\t\t\n\t\\end{figure}\n\t\\task[\\textbf{D.}]\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210824(5)-crop}\n\t\\end{figure}\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item An electron in the ground state of the hydrogen atom has the wave function $\\psi(\\vec{r})=\\frac{1}{\\sqrt{\\pi a_{0}^{3}}} e^{-\\left(\\frac{r}{a_{0}}\\right)}$, where $a_{0}$ is constant. The expectation value of the operator $\\hat{Q}=z^{2}-r^{2}$, where $z=r \\cos \\theta$ is\n\t(Hint: $\\left.\\int_{0}^{\\infty} e^{-a r} r^{n} d r=\\frac{\\sqrt{n}}{a^{n+1}}=\\frac{(n-1) !}{a^{n+1}}\\right)$\n\t\\exyear{GATE 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{-a_{0}^{2}}{2}$\n\t\\task[\\textbf{B.}]$-a_{0}^{2}$\n\t\\task[\\textbf{C.}]$\\frac{-3 a_{0}^{2}}{2}$\n\t\\task[\\textbf{D.}]$-2 a_{0}^{2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A hydrogen atom is in the state\n\t$$\n\t\\psi=\\sqrt{\\frac{8}{21}} \\psi_{200}-\\sqrt{\\frac{3}{7}} \\psi_{310}+\\sqrt{\\frac{4}{21}} \\psi_{321},\n\t$$\n\twhere $n, l, m$ in $\\psi_{n l m}$ denote the principal, orbital and magnetic quantum numbers, respectively. If $\\vec{L}$ is the angular momentum operator, then the average value of $L^{2}$ is $\\cdots \\quad \\hbar^{2}$\n\t\\exyear{GATE 2014}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item An electric field $\\vec{E}=E_{0} \\hat{z}$ is applied to a Hydrogen atom in $n=2$ excited state. Ignoring spin the $n=2$ state is fourfold degenerate, which in the $|l, m\\rangle$ basis are given by $|0,0\\rangle,|1,1\\rangle,|1,0\\rangle$ and $|1,-1\\rangle$. If $H^{\\prime}$ is the interaction Hamiltonian corresponding to the applied electric field, which of the following matrix elements is nonzero?\n\t\\exyear{GATE 2019}\n\\end{minipage}\n\\end{enumerate}\n\n\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{d}&2&\\textbf{d}\\\\\\hline\n\t\t3&\\textbf{d}&4&\\textbf{2}\\\\\\hline\n\t\t5&\\textbf{c}&&\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\n\n\\newpage\n\\begin{abox}\n\tPractice set 3\n\t\\end{abox}\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\\item $\\text { Verify that the average value of } 1 / r \\text { for a } 1 \\text { s electron in the hydrogen atom is } 1 / a_{0} \\text {. }$\n\\end{minipage}\n\t\\begin{answer}\n\t\tThe wave function of a ls electron is,\n\t\t$$\n\t\t\\psi=\\frac{e^{-r / a_{0}}}{\\sqrt{\\pi} a_{0}^{3 / 2}}\n\t\t$$\n\t\tSince $d V=r^{2} \\sin \\theta d r d \\theta d \\phi$ we have for the expectation value of $1 / r$\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\\left\\langle\\frac{1}{r}\\right\\rangle &=\\int_{0}^{\\infty}\\left(\\frac{1}{r}\\right)|\\psi|^{2} d V \\\\\n\t\t&=\\frac{1}{\\pi a_{0}^{3}} \\int_{0}^{\\infty} r e^{-2 r / a_{0}} d r \\int_{0}^{\\pi} \\sin \\theta d \\theta \\int_{0}^{2 \\pi} d \\phi\n\t\t\\end{aligned}\n\t\t$$\n\t\tThe integrals have the respective values\n\t\t$$\n\t\t\\begin{gathered}\n\t\t\\int_{0}^{\\infty} r e^{-2 r / a_{0}} d r=\\left[\\frac{a_{0}^{2}}{4} e^{-2 r / a_{0}}-\\frac{r}{2} e^{-2 r / a_{0}}\\right]_{0}^{\\infty}=\\frac{a_{0}^{2}}{4} \\\\\n\t\t\\int_{0}^{\\pi} \\sin \\theta d \\theta=[-\\cos \\theta]_{0}^{\\pi}=2 \\\\\n\t\t\\int_{0}^{2 \\pi} d \\phi=[\\phi]_{0}^{2 \\pi}=2 \\pi \\\\\n\t\t\\left\\langle\\frac{1}{r}\\right\\rangle=\\left(\\frac{1}{\\pi a_{0}^{3}}\\right)\\left(\\frac{a_{0}^{2}}{4}\\right)(2)(2 \\pi)=\\frac{1}{a_{0}}\n\t\t\\end{gathered}\n\t\t$$\t\n\t\\end{answer}\n\t\t\\begin{minipage}{\\textwidth}\n\t\t\\item \tShow that the most probable distance by the electron from the nucleus in the ground state of hydrogen atom is equal to the Bohr's radius.\n\t\\end{minipage}\n\t\\begin{answer}\n\t\tFor the ground state of hydrogen atom, $n=1, \\ell=0$ and $m=0$. Hence the ground state wave function is,\n\t\t$$\n\t\t\\psi_{1,0,0}=\\left(\\frac{1}{\\pi a_{0}^{3}}\\right)^{1 / 2} e^{-r / a_{0}}\n\t\t$$\n\t\tSince, the wave function is independent of $\\theta$ and $\\phi$, therefore,\\\\\n\t\tRadial probability density $=P(r)=\\left|\\psi_{100}\\right|^{2} 4 \\pi r^{2}=\\frac{4}{a_{0}^{3}} e^{-2 r / a_{0}} r^{2}$\n\t\tFor most probable distance, $P(r)$ is to be the maximum\n\t\t$$\n\t\t\\frac{d P}{d r}=\\frac{4}{a_{0}^{3}}\\left[r^{2}\\left(-\\frac{2}{a_{0}}\\right) e^{-2 r / a_{0}}+2 r e^{-2 r / a_{0}}\\right]=0 \\Rightarrow r=a_{0}\n\t\t$$\n\t\tThus the most probable distance of the electron from the nucleus of hydrogen atom in the ground state is equal tothe Bohr radius $\\left(a_{0}\\right)$.\t\n\t\\end{answer}\n\t\t\\begin{minipage}{\\textwidth}\n\t\t\\item If the ground state wave function for the hydrogen atom is\n\t\t$$\n\t\t\\psi=\\frac{1}{\\sqrt{\\pi}} \\frac{1}{a_{0}^{3 / 2}} e^{-r / a_{0}}\n\t\t$$\n\t\tshow that average distance of the electron from the nucleus is $1.5 \\mathrm{a}_{0}$.\n\t\\end{minipage}\n\t\\begin{answer}\n\t\tWe have the average distance of the electron from the hydrogen nucleus in the ground state is,\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\\langle r\\rangle &=\\int_{0}^{\\infty} \\psi^{*} \\hat{r} \\psi d r=\\int_{0}^{\\infty} \\frac{1}{\\sqrt{\\pi}} \\frac{1}{a_{0}^{3 / 2}} e^{-r / a_{0}} r \\frac{1}{\\sqrt{\\pi}} \\frac{1}{a_{0}^{3 / 2}} e^{-r / a_{0}} d \\tau \\\\\n\t\t&=\\frac{1}{\\pi a_{0}^{3}} \\int_{0}^{\\infty} r e^{-2 r / a_{0}} r^{2} \\sin \\theta d r d \\theta d \\phi\n\t\t\\end{aligned}\n\t\t$$\n\t\tUsing the standard integral $\\int_{0}^{\\infty} e^{-a x} x^{n} d x=\\frac{n !}{a^{n+1}}$, we get\n\t\t$$\n\t\t\\langle r\\rangle=\\frac{1}{\\pi a_{0}^{3}} \\int_{0}^{\\infty} r^{3} e^{-2 r / a_{0}} d r \\int_{0}^{\\pi} \\sin \\theta d \\theta \\int_{0}^{2 \\pi} d \\phi=\\frac{1}{\\pi a_{0}^{3}} \\times \\frac{3 !}{\\left(2 / a_{0}\\right)^{4}} \\times 2 \\times 2 \\pi\n\t\t$$\n\t\tTherefore, $\\langle r\\rangle=\\frac{3}{2} a_{0}=1.5 a_{0}$\n\t\\end{answer}\n\t\t\\begin{minipage}{\\textwidth}\n\t\t\\item What is the expectation value of the knetice nergy $\\left(E^{2}\\right)$ of the electron in the 1s state of the hydrogen atom?\n\t\\end{minipage}\n\t\\begin{answer}\n\t\tThe expectation value of the kinetic energy is,\n\t\t$$\n\t\t\\left\\langle E_{k}\\right\\rangle=\\int_{\\tau} \\psi_{1,0,0}^{*} \\hat{E}_{k} \\psi_{1,0,0} d \\tau=\\int_{0}^{\\infty} \\int_{0}^{\\pi} \\int_{0}^{2 \\pi} \\psi_{1,0,0} \\hat{E}_{k} \\psi_{1,0,0} r^{2} \\sin \\theta d r d \\theta d \\phi\n\t\t$$\n\t\tBut, $\\quad \\vec{E}_{k}=-\\frac{\\hbar^{2}}{2 m} \\nabla^{2}=-\\frac{\\hbar^{2}}{2 m}\\left[\\frac{1}{r^{2}} \\frac{\\partial}{\\partial r} r^{2} \\frac{\\partial}{\\partial r}+\\frac{1}{r^{2} \\sin \\theta} \\frac{\\partial}{\\partial \\theta} \\sin \\theta \\frac{\\partial}{\\partial \\theta}+\\frac{1}{r^{2} \\sin ^{2} \\theta} \\frac{\\partial^{2}}{\\partial \\phi^{2}}\\right]$\\\\\n\t\tSince $\\psi_{1,0,0}$ depends on $r$ only, the terms in $\\frac{\\partial}{\\partial \\theta}$ and $\\frac{\\partial}{\\partial \\phi}$ are zero.\\\\\n\t\t$$\\left\\langle E_{k}\\right\\rangle=-\\frac{\\hbar^{2}}{2 m} \\cdot 4 \\pi\\left(\\frac{1}{\\sqrt{\\pi} a_{0}^{3}}\\right)^{2} \\int_{0}^{\\infty} e^{-r / a_{0}} \\times\\left\\{\\left(\\frac{\\partial^{2}}{\\partial r^{2}}+\\frac{2}{r} \\frac{\\partial}{\\partial r}\\right) e^{-r / a_{0}}\\right\\} r^{2} d r$$\n\t\t$$\\begin{aligned}\n\t\t&=-\\frac{\\hbar^{2}}{2 m} \\frac{4}{a_{0}^{3}} \\int_{0}^{\\infty}\\left(\\frac{1}{a_{0}^{2}}-\\frac{2}{r a_{0}}\\right) e^{-2 r / a_{0}} r^{2} d r \\\\\n\t\t&=-\\frac{2 \\hbar^{2}}{m a_{0}^{3}}\\left[\\frac{1}{a_{0}^{2}} \\int_{0}^{\\infty} r^{2} e^{-2 r / a_{0}} d r-\\frac{2}{a_{0}} \\int_{0}^{\\infty} r e^{-2 r / a_{0}} d r\\right] \\\\\n\t\t&=-\\frac{2 \\hbar^{2}}{m a_{0}^{3}}\\left[\\frac{1}{a_{0}^{2}} \\frac{2}{\\left(2 / a_{0}\\right)^{3}}-\\frac{2}{a_{0}} \\frac{1}{\\left(2 / a_{0}\\right)^{2}}\\right]=\\frac{2 \\hbar^{2}}{m a_{0}^{3}} \\cdot \\frac{a_{0}}{4}\n\t\t\\end{aligned}$$\n\t\t$\\text { Therefore, }\\left\\langle E_{k}\\right\\rangle=\\frac{\\hbar^{2}}{2 m a_{0}^{3}}=\\frac{\\hbar^{2}}{2 m}\\left(\\frac{m e^{2}}{\\hbar^{2}}\\right)=\\frac{m e^{4}}{2 \\hbar^{2}}$\n\t\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item Estimate the uncertainity in the radial position of the electron in the ground state of hydrogen atom.\n\\end{minipage}\n\t\\begin{answer}\n\t\tFor ground state\\\\\n\t\t$$\\langle r \\rangle =\\frac{4}{a_0^3}\t\\int_{0}^{\\infty} r^3 e^{\\frac{-2r}{a_0}}dr=\\frac{3a_0}{2}$$\n\t\t$$\\langle r^2 \\rangle =\\frac{4}{a_0^3}\t\\int_{0}^{\\infty} r^4 e^{\\frac{-2r}{a_0}}dr=3a_0^2$$\n\t\tuncertainity in the radial position of the particle will be \\\\\n\t\t$$\\Delta r=\\sqrt{\\langle r^2 \\rangle-\\langle r \\rangle^2}=\\frac{\\sqrt{3}}{2}a_0$$\n\t\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item \tFind the positions of maxima of the radial probability curves for 1s,2s,2p and 3d orbitals of the hydrogen like atom \n\\end{minipage}\n\t\\begin{answer}\n\t\tThe radial probability density \\\\\n\t\t$$P_{nl}=r^2|R_{nl}|^2$$\n\t\t$$R_{10}=Constant \\times e^{-Zr/a_0}$$\n\t\t$$R_{21}=Constant \\times e^{-Zr/2a_0}$$\n\t\t$$R_{32}=Constant \\times e^{-Zr/3a_0}$$\n\t\t$P_{nl}$ will be maximum when $\\frac{dP_{nl}}{dr}=0$ hence \\\\\n\t\t$$\\frac{dP_{10}}{dr}=0 \\implies C(2r-\\frac{2Zr^2}{a_0})e^{\\frac{-2Zr}{a_0}}=0$$\n\t\t$$\\implies r=\\frac{a_0}{Z}$$\n\t\t$$\\frac{dP{21}}{dr}=0\\implies C(4r^3-\\frac{Zr^4}{a_0})e^{\\frac{-Zr}{a_0}}=0$$\n\t\t$$\\implies r=\\frac{4a_0}{Z}$$\n\t\tSimilarly $\\frac{dP_{32}}{dr}=0\\implies r=\\frac{9a_0}{2}$\\\\\n\t\tIn general $r_{max}=\\frac{n^2a_0}{2}$\n\t\\end{answer}\n\t\t\\begin{minipage}{\\textwidth}\n\t\t\\item \tAt time $t=0$, the wave function for the hydrogen atom is\n\t\t$$\n\t\t\\psi(r, 0)=\\frac{1}{\\sqrt{10}}\\left(2 \\psi_{100}+\\psi_{210}+\\sqrt{2} \\psi_{211}+\\sqrt{3} \\psi_{21,-1}\\right)\n\t\t$$\n\t\twhere the subscripts are values of the quantum numbers $n, l, m$. (i) What is the expectation value for the energy of the system? (ii) What is the probability of finding the system with $l=1, m=1$ ? .\n\t\\end{minipage}\n\t\\begin{answer}\n\t\tExpectation value $=\\langle E \\rangle =\\langle \\psi |H|\\psi\\rangle$\\\\\n\t\t$$=\\frac{1}{10}\\left\\langle \\left(2 \\psi_{100}+\\psi_{210}+\\sqrt{2} \\psi_{211}+\\sqrt{3} \\psi_{21,-1}\\right)|H|\\left(2 \\psi_{100}+\\psi_{210}+\\sqrt{2} \\psi_{211}+\\sqrt{3} \\psi_{21,-1}\\right)\\right\\rangle $$\n\t\t$$=\\frac{1}{10}\\left\\langle \\left(2 \\psi_{100}+\\psi_{210}+\\sqrt{2} \\psi_{211}+\\sqrt{3} \\psi_{21,-1}\\right)|\\left(2E_1 \\psi_{100}+E_2\\psi_{210}+\\sqrt{2} E_2\\psi_{211}+\\sqrt{3}E_2 \\psi_{21,-1}\\right)\\right\\rangle $$\n\t\t$$=\\frac{1}{10}\\left( 4E_1+E_2+2E_2+3E_2\\right) =\\frac{1}{10}\\left[ 4E_1+6E_2\\right] $$\n\t\t$$E_1=-13.6eV \\quad E_2=-3.4eV$$\n\t\t$$\\langle E \\rangle=-74.8eV$$\n\t\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item Let $\\psi_{n l m}$ denote the eigenfunctions of a Hamiltonian for a spherically symmetric potential $V(r)$\n\t$$\n\t\\psi_{n, l, m}=\\frac{1}{6}\\left[\\psi_{200}+\\sqrt{5} \\psi_{210}+\\sqrt{10} \\psi_{21-1}+\\sqrt{20} \\psi_{211}\\right]\n\t$$\n\tThen find\n\t(a) the expectation value of $L_{z}$\\\\\n\t(b) the expectation value of $L^{2}$ in the state\\\\\n\t(c) the expectation value of $L_{y}$\n\\end{minipage}\n\\begin{answer}\n\t$\\psi_{n m m}=\\frac{1}{6}\\left[\\psi_{200}+\\sqrt{5} \\psi_{210}+\\sqrt{10} \\psi_{21-1}+\\sqrt{20} \\psi_{211}\\right]$\\\\\n (a)\\begin{align*}\n\t\t\\left\\langle L_{z}\\right\\rangle &=\\frac{1}{36} 0 \\hbar+\\frac{5}{36} \\times 0 \\hbar+\\frac{10}{36} \\times(-1 \\hbar)+\\frac{20}{36}(1 \\hbar) \\\\\n\t\t&=\\frac{10}{36} \\hbar=\\frac{5}{18} \\hbar\n\t\\end{align*}\n\t(b) $\\left\\langle L^{2}\\right\\rangle=\\frac{1}{36} \\times 0 \\hbar^{2}+\\frac{5}{36} \\times\\left(2 \\hbar^{2}\\right)+\\frac{10}{36} \\times\\left(2 \\hbar^{2}\\right)+\\frac{20}{36}\\left(2 \\hbar^{2}\\right)$\n\t$$\n\t=\\frac{35}{36}\\left(2 \\hbar^{2}\\right)=\\frac{35}{18} \\hbar^{2}\n\t$$\n\t(c) $L_{y}=\\frac{L_{+}-L_{-}}{2 i}$\n\t\\begin{align*}\n\t&\\therefore\\left\\langle L_{y}\\right\\rangle=\\frac{1}{2 i}\\left\\{\\left\\langle L_{+}\\right\\rangle-\\left\\langle L_{-}\\right\\rangle\\right\\} \\\\\n\t&L_{+}|\\psi\\rangle=\\frac{\\sqrt{5}}{6} \\times \\sqrt{2} \\hbar \\psi_{211}+\\frac{\\sqrt{10}}{6} \\times \\sqrt{2} \\hbar \\psi_{210} \\\\\n\t&\\left\\langle\\psi\\left|L_{+}\\right| \\psi\\right\\rangle=\\frac{\\sqrt{20} \\times \\sqrt{5} \\times \\sqrt{2} \\hbar}{36}+\\frac{\\sqrt{10} \\times \\sqrt{5} \\times \\sqrt{2} \\hbar}{36} \\\\\n\t&L_{-}|\\psi\\rangle=\\frac{\\sqrt{5}}{6} \\times \\sqrt{2} \\hbar \\psi_{21-1}+\\frac{\\sqrt{20}}{6} \\times \\sqrt{2} \\hbar \\psi_{210} \\\\\n\t&\\left\\langle\\psi\\left|L_{-}\\right| \\psi\\right\\rangle=\\frac{\\sqrt{10} \\times \\sqrt{5} \\times \\sqrt{2} \\hbar}{36}+\\frac{\\sqrt{20} \\times \\sqrt{5} \\times \\sqrt{2} \\hbar}{36} \\quad \\therefore\\left\\langle L_{y}\\right\\rangle=0\n\t\\end{align*}\n\\end{answer}\n\\end{enumerate}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "a3fb0338b77d116dc7a58548e30da056b0b7f3ce", "size": 45599, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "QM -CSIR/chapter/hydrogen atom.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "QM -CSIR/chapter/hydrogen atom.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "QM -CSIR/chapter/hydrogen atom.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.6845549738, "max_line_length": 616, "alphanum_fraction": 0.6270093642, "num_tokens": 18446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.7163694091482274}}
{"text": "\\chapter{Approximation methods}\nPerturbation theory is based on the assumption that the problem we wish to solve is, in some sense, only slightly different from a problem that can be solved exactly. In the case where the deviation between the two problems is small, perturbation theory is suitable for calculating the contribution associated with this deviation; this contribution is then added as a correction to the energy and the wave function of the exactly solvable Hamiltonian. So perturbation theory builds on the known exact solutions to obtain approximate solutions.\\\\\nWhat about those systems whose Hamiltonians cannot be reduced to an exactly solvable part plus a small correction. For these, we may consider the variational method or the WKB approximation. The variational method is particularly useful in estimating the energy eigenvalues of the ground state and the first few excited states of a system for which one has only a qualitative idea about the form of the wave function.\\\\\nThe WKB method is useful for finding the energy eigenvalues and wave functions of systems for which the classical limit is valid. \n\\section{Time independent perturbation theory}\nThis method is most suitable when $\\hat{H}$ is very close to a Hamiltonian $H_{0}$ that can be solved exactly. In this case, $\\hat{H}$ can be split into two time-independent parts\n$$\n\\hat{H}=\\hat{H}_{0}+\\hat{H}_{p},\n$$\nwhere $\\hat{H}_{p}$ is very small compared to $\\hat{H}_{0}\\left(\\hat{H}_{0}\\right.$ is known as the Hamiltonian of the unperturbed system). As a result, $\\hat{H}_{p}$ is called the perturbation, for its effects on the energy spectrum and eigenfunctions will be small; such perturbation is encountered, for instance, in systems subject to weak electric or magnetic fields. We can make this idea more explicit by writing $\\hat{H}_{p}$ in terms of a dimensionless real parameter $\\lambda$ which is very small compared to 1 :\n$$\n\\hat{H}_{p}=\\lambda \\hat{W} \\quad(\\lambda \\ll 1) .\n$$\nThus the eigenvalue problem becomes\n$$\n\\left(\\hat{H}_{0}+\\lambda \\hat{W}\\right)\\left|\\psi_{n}\\right\\rangle=E_{n}\\left|\\psi_{n}\\right\\rangle .\n$$\nIn what follows we are going to consider two separate cases depending on whether the exact solutions of $\\hat{H}_{0}$ are nondegenerate or degenerate. Each of these two cases requires its own approximation scheme.\n\\subsection{Nondegenerate Perturbation theory}\nIn this section we limit our study to the case where $\\hat{H}_{0}$ has no degenerate eigenvalues; that is, for every energy $E_{n}^{(0)}$ there corresponds only one eigenstate $\\left|\\phi_{n}\\right\\rangle:$\n$$\n\\hat{H}_{0}\\left|\\phi_{n}\\right\\rangle=E_{n}^{(0)}\\left|\\phi_{n}\\right\\rangle,\n$$\nwhere the exact eigenvalues $E_{n}^{(0)}$ and exact eigenfunctions $\\left|\\phi_{n}\\right\\rangle$ are known.\\\\\n\nThe main idea of perturbation theory consists in assuming that the perturbed eigenvalues and eigenstates can both be expanded in power series in the parameter $\\lambda$ :\n$$\n\\begin{aligned}\nE_{n} &=E_{n}^{(0)}+\\lambda E_{n}^{(1)}+\\lambda^{2} E_{n}^{(2)}+\\cdots \\\\\n\\left|\\psi_{n}\\right\\rangle &=\\left|\\phi_{n}\\right\\rangle+\\lambda\\left|\\psi_{n}^{(1)}\\right\\rangle+\\lambda^{2}\\left|\\psi_{n}^{(2)}\\right\\rangle+\\cdots\n\\end{aligned}\n$$\n\nThe job of perturbation theory reduces then to the calculation of $E_{n}^{(1)}, E_{n}^{(2)}, \\ldots$ and $\\left|\\psi_{n}^{(1)}\\right\\rangle$, $\\left|\\psi_{n}^{(2)}\\right\\rangle, \\ldots .$ In this section we shall be concerned only with the determination of $E_{n}^{(1)}, E_{n}^{(2)}$, and $\\left|\\psi_{n}^{(1)}\\right\\rangle .$ Assuming that the unperturbed states $\\left|\\phi_{n}\\right\\rangle$ are nondegenerate, and substituting the power series expansion of $E_{n}$ and $\\left|\\psi_{n}\\right\\rangle $ in $\n\\left(\\hat{H}_{0}+\\lambda \\hat{W}\\right)\\left|\\psi_{n}\\right\\rangle=E_{n}\\left|\\psi_{n}\\right\\rangle .\n$ we obtain\n$$\n\\begin{aligned}\n&\\left(\\hat{H}_{0}+\\lambda \\hat{W}\\right)\\left(\\left|\\phi_{n}\\right\\rangle+\\lambda\\left|\\psi_{n}^{(1)}\\right\\rangle+\\lambda^{2}\\left|\\psi_{n}^{(2)}\\right\\rangle+\\cdots\\right) \\\\\n&\\quad=\\left(E_{n}^{(0)}+\\lambda E_{n}^{(1)}+\\lambda^{2} E_{n}^{(2)}+\\cdots\\right)\\left(\\left|\\phi_{n}\\right\\rangle+\\lambda\\left|\\psi_{n}^{(1)}\\right\\rangle+\\lambda^{2}\\left|\\psi_{n}^{(2)}\\right\\rangle+\\cdots\\right)\n\\end{aligned}\n$$\nThe coefficients of successive powers of $\\lambda$ on both sides of this equation must be equal. Equating the coefficients of the first three powers of $\\lambda$, we obtain these results:\\\\\n- Zero order in $\\lambda$ :\n$$\n\\hat{H}_{0}\\left|\\phi_{n}\\right\\rangle=E_{n}^{(0)}\\left|\\phi_{n}\\right\\rangle\n$$\n- First order in $\\lambda:$\n$$\n\\hat{H}_{0}\\left|\\psi_{n}^{(1)}\\right\\rangle+\\hat{W}\\left|\\phi_{n}\\right\\rangle=E_{n}^{(0)}\\left|\\psi_{n}^{(1)}\\right\\rangle+E_{n}^{(1)}\\left|\\phi_{n}\\right\\rangle\n$$\n- Second order in $\\lambda$ :\n$$\n\\hat{H}_{0}\\left|\\psi_{n}^{(2)}\\right\\rangle+\\hat{W}\\left|\\psi_{n}^{(1)}\\right\\rangle=E_{n}^{(0)}\\left|\\psi_{n}^{(2)}\\right\\rangle+E_{n}^{(1)}\\left|\\psi_{n}^{(1)}\\right\\rangle+E_{n}^{(2)}\\left|\\phi_{n}\\right\\rangle\n$$\nWe now proceed to determine the eigenvalues $E_{n}^{(1)}, E_{n}^{(2)}$ and the eigenvector $\\left|\\psi_{n}^{(1)}\\right\\rangle$  For this, we need to specify how the states $\\left|\\phi_{n}\\right\\rangle$ and $\\left|\\psi_{n}\\right\\rangle$ overlap. Since $\\left|\\psi_{n}\\right\\rangle$ is considered not to be very different from $\\left|\\phi_{n}\\right\\rangle$, we have $\\left\\langle\\phi_{n} \\mid \\psi_{n}\\right\\rangle \\simeq 1 .$ We can, however. normalize $\\left|\\psi_{n}\\right\\rangle$ so that its overlap with $\\left|\\phi_{n}\\right\\rangle$ is exactly equal to one:\\\\\n$$\\left\\langle\\phi_{n} \\mid \\psi_{n}\\right\\rangle=1 .$$\\\\\nSubstituting power series expansion of $\\left|\\psi_{n}\\right\\rangle $ ine above equation we get\\\\\n$$\n\\lambda\\left\\langle\\phi_{n} \\mid \\psi_{n}^{(1)}\\right\\rangle+\\lambda^{2}\\left\\langle\\phi_{n} \\mid \\psi_{n}^{(2)}\\right\\rangle+\\cdots=0\n$$\nhence the coefficients of the various powers of $\\lambda$ must vanish separately:\n$$\n\\left\\langle\\phi_{n} \\mid \\psi_{n}^{(1)}\\right\\rangle=\\left\\langle\\phi_{n} \\mid \\psi_{n}^{(2)}\\right\\rangle=\\cdots=0 .\n$$\n\\subsubsection{First order correction}\n$$E_{n}^{(1)}=\\left\\langle\\phi_{n}|\\hat{W}| \\phi_{n}\\right\\rangle$$\nEnergy of first order pertubration\n$$E_{n}=E_{n}^{(0)}+\\left\\langle\\phi_{n}\\left|\\hat{H}_{p}\\right| \\phi_{n}\\right\\rangle$$\nFirst order correction of eigen vector\\\\\n$$\\left|\\psi_{n}^{(1)}\\right\\rangle=\\sum_{m \\neq n} \\frac{\\left\\langle\\phi_{m}|\\hat{W}| \\phi_{n}\\right\\rangle}{E_{n}^{(0)}-E_{m}^{(0)}}\\left|\\phi_{m}\\right\\rangle$$\nThe eigenfunction $\\left|\\psi_{n}\\right\\rangle$ of $\\hat{H}$ to first order in $\\lambda \\hat{W}$ can then be obtained as\n$$\n\\left|\\psi_{n}\\right\\rangle=\\left|\\phi_{n}\\right\\rangle+\\sum_{m \\neq n} \\frac{\\left\\langle\\phi_{m}\\left|\\hat{H}_{p}\\right| \\phi_{n}\\right\\rangle}{E_{n}^{(0)}-E_{m}^{(0)}}\\left|\\phi_{m}\\right\\rangle\n$$\n\\subsubsection{second order correction}\n$$E_{n}^{(2)}=\\left\\langle\\phi_{n}|\\hat{W}| \\psi_{n}^{(1)}\\right\\rangle$$\nwhich can be written as \\\\\n$$E_{n}^{(2)}=\\sum_{m \\neq n} \\frac{\\left|\\left\\langle\\phi_{m}|\\hat{W}| \\phi_{n}\\right\\rangle\\right|^{2}}{E_{n}^{(0)}-E_{m}^{(0)}}$$\\\\\n$\\text { The eigenenergy to second order in } \\hat{H}_{p}$ is obtained as \n$$E_{n}=E_{n}^{(0)}+\\left\\langle\\phi_{n}\\left|\\hat{H}_{p}\\right| \\phi_{n}\\right\\rangle+\\sum_{m \\neq n} \\frac{\\left|\\left\\langle\\phi_{m}\\left|\\hat{H}_{p}\\right| \\phi_{n}\\right\\rangle\\right|^{2}}{E_{n}^{(0)}-E_{m}^{(0)}}+\\cdots .$$\n\\subsubsection{Application}\n\\subsubsection{Stark effect(n=1-non degenerate case)}\n\n The effect that an external electric field has on the energy levels of an atom is called the Stark effect. In the absence of an electric field, the (unperturbed) Hamiltonian of the hydrogen atom (in CGS units) is:\n$$\n\\hat{H}_{0}=\\frac{\\hat{\\vec{p}}^{2}}{2 \\mu}-\\frac{e^{2}}{r} .\n$$\nThe eigenfunctions of this Hamiltonian, $\\psi_{n l m}(\\vec{r})$, are given by\n$$\n\\langle r \\theta \\varphi \\mid n l m\\rangle=\\psi_{n l m}(r, \\theta, \\varphi)=R_{n l}(r) Y_{l m}(\\theta, \\varphi) .\n$$\nWhen the electric field is turned on, the interaction between the atom and the field generates a term $\\hat{H}_{p}=e \\overrightarrow{\\mathcal{E}} \\cdot \\vec{r}=e \\mathcal{E} \\hat{Z}$ that needs to be added to $\\hat{H}_{0}$.\n\nSince the excited states of the hydrogen atom are degenerate while the ground state is not, nondegenerate perturbation theory applies only to the ground state, $\\psi_{100}(\\vec{r})$. Ignoring the spin degrees of freedom, the energy of this system to second-order perturbation is given as follows\n$$\nE_{100}=E_{100}^{(0)}+e \\mathcal{E}\\langle 100|\\hat{Z}| 100\\rangle+e^{2} \\mathcal{E}^{2} \\sum_{n l m \\neq 100} \\frac{|\\langle n l m|\\hat{Z}| 100\\rangle|^{2}}{E_{100}^{(0)}-E_{n l m}^{(0)}}\n$$\nThe term\n$$\n\\langle 100|\\hat{Z}| 100\\rangle=\\int\\left|\\psi_{100}(\\vec{r})\\right|^{2} z d^{3} r\n$$\nis zero, since $\\hat{Z}$ is odd under parity and $\\psi_{100}(\\vec{r})$ has a definite parity. This means that there can be no correction term to the energy which is proportional to the electric field and hence there is no linear Stark effect. The underlying physics behind this is that when the hydrogen atom is in its ground state, it has no permanent electric dipole moment. We are left then with only a quadratic dependence of the energy  on the electric field. This is called the quadratic Stark effect. This correction, which is known as the energy shift $\\Delta E$, is given by\n$$\n\\Delta E=e^{2} \\mathcal{E}^{2} \\sum_{n l m \\neq 100} \\frac{|\\langle n l m|\\hat{Z}| 100\\rangle|^{2}}{E_{100}^{(0)}-E_{n l m}^{(0)}}\n$$\n\\subsection{Degenerate perturbation theory}\n We now apply perturbation theory to determine the energy spectrum and the states of a system whose unperturbed Hamiltonian $\\hat{H}_{0}$ is degenerate:\n$$\n\\hat{H}\\left|\\psi_{n}\\right\\rangle=\\left(\\hat{H}_{0}+\\hat{H}_{p}\\right)\\left|\\psi_{n}\\right\\rangle=E_{n}\\left|\\psi_{n}\\right\\rangle .\n$$\nIf, for instance, the level of energy $E_{n}^{(0)}$ is $f$-fold degenerate (i.e., there exists a set of $f$ different eigenstates $\\left|\\phi_{n_{\\alpha}}\\right\\rangle$, where $\\alpha=1,2, \\ldots, f$, that correspond to the same eigenenergy $\\left.E_{n}^{(0)}\\right)$, we have\n$$\n\\hat{H}_{0}\\left|\\phi_{n_{\\alpha}}\\right\\rangle=E_{n}^{(0)}\\left|\\phi_{n_{\\alpha}}\\right\\rangle \\quad(\\alpha=1,2, \\ldots, f),\n$$\nwhere $\\alpha$ stands for one or more quantum numbers; the energy eigenvalues $E_{n}^{(0)}$ are independent of $\\alpha$.\n\nIn the zeroth-order approximation we can write the eigenfunction $\\left|\\psi_{n}\\right\\rangle$ as a linear combination in terms of $\\left|\\phi_{n_{a}}\\right\\rangle$ :\n$$\n\\left|\\psi_{n}\\right\\rangle=\\sum_{\\alpha=1}^{f} a_{\\alpha}\\left|\\phi_{n_{\\alpha}}\\right\\rangle .\n$$\nConsidering the states $\\left|\\phi_{n_{a}}\\right\\rangle$ to be orthonormal with respect to the label $\\alpha$ (i.e., $\\left\\langle\\phi_{n_{a}} \\mid \\phi_{n_{\\beta}}\\right\\rangle=$ $\\left.\\delta_{a, \\beta}\\right)$ and $\\left|\\psi_{n}\\right\\rangle$ to be normalized, $\\left\\langle\\psi_{n} \\mid \\psi_{n}\\right\\rangle=1$, we can ascertain that the coefficients $a_{\\alpha}$ obey the relation\n$$\n\\left\\langle\\psi_{n} \\mid \\psi_{n}\\right\\rangle=\\sum_{\\alpha, \\beta} a_{\\alpha}^{*} a_{\\beta} \\delta_{\\alpha, \\beta}=\\sum_{\\alpha=1}^{f}\\left|a_{\\alpha}\\right|^{2}=1 .\n$$\nIn what follows we are going to show how to determine these coefficients and the first-order corrections to the energy. For this, let us substitute $\n\\left|\\psi_{n}\\right\\rangle=\\sum_{\\alpha=1}^{f} a_{\\alpha}\\left|\\phi_{n_{\\alpha}}\\right\\rangle .\n$ and $\n\\hat{H}_{0}\\left|\\phi_{n_{\\alpha}}\\right\\rangle=E_{n}^{(0)}\\left|\\phi_{n_{\\alpha}}\\right\\rangle \\quad(\\alpha=1,2, \\ldots, f),\n$ into eigen value equation(perturbed) we will get\n$$\n\\sum_{a}\\left[E_{n}^{(0)}\\left|\\phi_{n_{u}}\\right\\rangle+\\hat{H}_{p}\\left|\\phi_{n_{u}}\\right\\rangle\\right] a_{\\alpha}=E_{n} \\sum_{\\alpha} a_{a}\\left|\\phi_{n_{a}}\\right\\rangle\n$$\nThe multiplication of both sides of this equation by $\\left\\langle\\phi_{n_{\\beta}}\\right|$ leads to\n$$\n\\sum_{u} a_{u}\\left[E_{n}^{(0)} \\delta_{u, \\beta}+\\left\\langle\\phi_{n_{j}}\\left|\\hat{H}_{p}\\right| \\phi_{n_{a}}\\right\\rangle\\right]=E_{n} \\sum_{\\alpha} a_{a} \\delta_{\\alpha, \\beta}\n$$\nor 10\n$$\na_{\\beta} E_{n}=a_{\\beta} E_{n}^{(0)}+\\sum_{\\alpha=1}^{f} a_{u}\\left\\langle\\phi_{n_{n}}\\left|\\hat{H}_{p}\\right| \\phi_{n_{a}}\\right\\rangle,\n$$\nwhere we have used $\\left\\langle\\phi_{n \\beta} \\mid \\phi_{n_{a}}\\right\\rangle=\\delta_{\\beta, a}$. We can rewrite the above equation as \n$$\n\\sum_{a=1}^{f}\\left(\\hat{H}_{p_{\\beta a}}-E_{n}^{(1)} \\delta_{\\alpha, \\beta}\\right) a_{\\alpha}=0 \\quad(\\beta=1,2, \\ldots, f),\n$$\nwith $\\hat{H}_{p_{\\beta a}}=\\left\\langle\\phi_{n_{\\beta}}\\left|\\hat{H}_{p}\\right| \\phi_{n_{u}}\\right\\rangle$ and $E_{n}^{(1)}=E_{n}-E_{n}^{(0)}$. This is a system of $f$ homogeneous linear equations for the coefficients $a_{\\alpha}$. These coefficients are nonvanishing only when the determinant $\\left|\\hat{H}_{p_{a \\beta}}-E_{n}^{(1)} \\delta_{\\alpha, \\beta}\\right|$ is zero:\n$$\\left|\\begin{array}{ccccc}\n\t\\hat{H}_{p_{11}}-E_{n}^{(1)} & \\hat{H}_{p_{12}} & \\hat{H}_{p_{13}} & \\cdots & \\hat{H}_{p_{1 /}} \\\\\n\t\\hat{H}_{p_{21}} & \\hat{H}_{p_{22}}-E_{n}^{(1)} & \\hat{H}_{p_{23}} & \\cdots & \\hat{H}_{p_{2} f} \\\\\n\t\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\\hat{H}_{p_{f 1}} & \\hat{H}_{p_{f 2}} & \\hat{H}_{p_{f 3}} & \\cdots & \\hat{H}_{p_{f f}}-E_{n}^{(1)}\n\\end{array}\\right|=0$$\n In summary, to determine the eigenvalues to first-order and the eigenstates to zeroth order for an $f$-fold degenerate level from perturbation theory, we proceed as follows:\n \\begin{itemize}\n \t\\item First, for each $f$-fold degenerate level, determine the $f \\times f$ matrix of the perturbation $\\hat{H}_{p}$ :\n \t$$H_{p}=\\left(\\begin{array}{cccc}\n \t\t\\hat{H}_{p_{11}} & \\hat{H}_{p_{12}} & \\cdots & \\hat{H}_{p_{1 f}} \\\\\n \t\t\\hat{H}_{p_{21}} & \\hat{H}_{p_{22}} & \\cdots & \\hat{H}_{p_{2 f}} \\\\\n \t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n \t\t\\hat{H}_{p_{f 1}} & \\hat{H}_{p_{f 2}} & \\cdots & \\hat{H}_{p_{f \\prime}}\n \t\\end{array}\\right)$$\n \t\\item Second, diagonalize this matrix and find the $f$ eigenvalues $E_{n_{a}}^{(1)}(\\alpha=1,2, \\ldots, f)$ and their corresponding eigenvectors\\\\\n \t$$a_{\\alpha}=\\left(\\begin{array}{c}\n \t\ta_{\\alpha_{1}} \\\\\n \t\ta_{\\alpha_{2}} \\\\\n \t\t\\vdots \\\\\n \t\ta_{a_{f}}\n \t\\end{array}\\right) \\quad(\\alpha=1,2, \\ldots, f)$$\n \t\\item Finally, the energy eigenvalues are given to first order by\n \t$$\n \tE_{n_{a}}=E_{n}^{(0)}+E_{n_{a}}^{(1)} \\quad(\\alpha=1,2, \\ldots, f)\n \t$$\n \tand the corresponding eigenvectors are given to zero order by\n \t$$\n \t\\left|\\psi_{n_{a}}\\right\\rangle=\\sum_{\\beta=1}^{f} a_{\\alpha \\beta}\\left|\\phi_{n_{\\beta}}\\right\\rangle\n \t$$\n \\end{itemize}\n\n\\subsubsection{Application}\n\\textbf{Stark effect n=2 degenerate states}\\\\\nIn the absence of any external electric field, the first excited state (i.e., $n=2$ ) is fourfold degenerate: the states $|n l m\\rangle=|200\\rangle,|210\\rangle,|211\\rangle$, and $|21-1\\rangle$ have the same energy $E_{2}=-R_{y} / 4$, where $R_{y}=\\mu e^{4} /\\left(2 \\hbar^{2}\\right)=13.6 \\mathrm{eV}$ is the Rydberg constant.\n\nWhen the external electric field is turned on, some energy levels will split. The energy due to the interaction between the dipole moment of the electron $(\\vec{d}=-e \\vec{r})$ and the external electric field $(\\overrightarrow{\\mathcal{E}}=\\overrightarrow{\\mathcal{E}} \\vec{k})$ is given by\n$$\n\\hat{H}_{p}=-\\vec{d} \\cdot \\overrightarrow{\\mathcal{E}}=e \\vec{r} \\cdot \\overrightarrow{\\mathcal{E}}=e \\mathcal{E} \\hat{Z}\n$$\nTo calculate the eigenenergies, we need to determine and then diagonalize the $4 \\times 4$ matrix elements of $\\hat{H}_{p}:\\left\\langle 2 l^{\\prime} m^{\\prime}\\left|\\hat{H}_{p}\\right| 2 l m\\right\\rangle=e \\mathcal{E}\\left\\langle 2 l^{\\prime} m^{\\prime}|\\hat{Z}| 2 l m\\right\\rangle .$ The matrix elements $\\left\\langle 2 l^{\\prime} m^{\\prime}|\\hat{Z}|\\right.$ $2 l m)$ can be calculated more simply by using the relevant selection rules and symmetries. First, since $\\hat{Z}$ does not depend on the azimuthal angle $\\varphi, z=r \\cos \\theta$, the elements $\\left\\langle 2 l^{\\prime} m^{\\prime}|\\hat{Z}| 2 l m\\right\\rangle$ are nonzero only if $m^{\\prime}=m$. Second, as $Z$ is odd, the states $\\left|2 l^{\\prime} m^{\\prime}\\right\\rangle$ and $|2 l m\\rangle$ must have opposite parities so that $\\left\\langle 2 l^{\\prime} m^{\\prime}|\\hat{Z}| 2 l m\\right\\rangle$ does not vanish. Therefore, the only nonvanishing matrix elements are those that couple the $2 \\mathrm{~s}$ and $2 \\mathrm{p}$ states (with $m=0$ ); that is, between | 200) and $|210\\rangle$. In this case we have\\\\\n$$\\begin{aligned}\n\t\\langle 200|\\hat{Z}| 210\\rangle &=\\int_{0}^{\\infty} R_{20}^{*}(r) R_{21}(r) r^{2} d r \\int Y_{00}^{*}(\\Omega) z Y_{10}(\\Omega) d \\Omega \\\\\n\t&=\\sqrt{\\frac{4 \\pi}{3}} \\int_{0}^{\\infty} R_{20}(r) R_{21}(r) r^{3} d r \\int Y_{00}^{*}(\\Omega) Y_{10}^{2}(\\Omega) d \\Omega \\\\\n\t&=-3 a_{0},\n\\end{aligned}$$\nsince $z=r \\cos \\theta=\\sqrt{4 \\pi / 3} r Y_{10}(\\Omega),\\langle\\vec{r} \\mid 200\\rangle=R_{20}(r) Y_{00}(\\Omega),\\langle\\vec{r} \\mid 210\\rangle=R_{21}(r) Y_{10}(\\Omega)$, and $d \\Omega=\\sin \\theta d \\theta d \\varphi ; a_{0}=\\hbar^{2} /\\left(\\mu e^{2}\\right)$ is the Bohr radius. Using the notations $|1\\rangle=|200\\rangle$, $|2\\rangle=|21|\\rangle,|3\\rangle=|210\\rangle$, and $|4\\rangle=|21-1\\rangle$, we can write the matrix of $H_{p}$ as\n$$\nH_{p}=\\left(\\begin{array}{ccccc}\n\\left\\langle 1\\left|\\hat{H}_{p}\\right| 1\\right\\rangle & \\left\\langle 1\\left|\\hat{H}_{p}\\right| 2\\right\\rangle & \\left\\langle 1\\left|\\hat{H}_{p}\\right| 3\\right\\rangle & \\left\\langle 1\\left|\\hat{H}_{p}\\right| 4\\right\\rangle \\\\\n\\left\\langle 2\\left|\\hat{H}_{p}\\right| 1\\right\\rangle & \\left\\langle 2\\left|\\hat{H}_{p}\\right| 2\\right\\rangle & \\left\\langle 2\\left|\\hat{H}_{p}\\right| 3\\right\\rangle & \\left\\langle 2\\left|\\hat{H}_{p}\\right| 4\\right\\rangle \\\\\n\\left\\langle 3\\left|\\hat{H}_{p}\\right| 1\\right\\rangle & \\left\\langle 3\\left|\\hat{H}_{p}\\right| 2\\right\\rangle & \\left\\langle 3\\left|\\hat{H}_{p}\\right| 3\\right\\rangle & \\left\\langle 3\\left|\\hat{H}_{p}\\right| 4\\right\\rangle \\\\\n\\left\\langle 4\\left|\\hat{H}_{p}\\right| 1\\right\\rangle & \\left\\langle 4\\left|\\hat{H}_{p}\\right| 2\\right\\rangle & \\left\\langle 4\\left|\\hat{H}_{p}\\right| 3\\right\\rangle & \\left\\langle 4\\left|\\hat{H}_{p}\\right| 4\\right\\rangle\n\\end{array}\\right)\n$$\n$$H_{p}=-3 e \\mathcal{E} a_{0}\\left(\\begin{array}{cccc}\n\t0 & 0 & 1 & 0 \\\\\n\t0 & 0 & 0 & 0 \\\\\n\t1 & 0 & 0 & 0 \\\\\n\t0 & 0 & 0 & 0\n\\end{array}\\right)$$\n\nThe diagonalization of this matrix leads to the following eigenvalues:\n$$\nE_{2}^{(1)},=-3 e \\mathcal{E} a_{0}, \\quad E_{2}^{(1)}{ }_{2}=E_{2}^{(1)}{ }_{3}=0, \\quad E_{2{ }^{(1)}}{ }_{4}=3 e \\mathcal{E} a_{0} .\n$$\nThus, the energy levels of the $n=2$ states are given to first order by\n$$\nE_{2_{1}}=-\\frac{R_{y}}{4}-3 e \\mathcal{E} a_{0}, \\quad E_{2_{2}}=E_{2_{3}}=-\\frac{R_{y}}{4}, \\quad E_{2_{4}}=-\\frac{R_{y}}{4}+3 e \\mathcal{E} a_{0} .\n$$\nThe corresponding eigenvectors to zeroth order are\n$$\n\\begin{aligned}\n&\\left|\\psi_{2}\\right\\rangle_{1}=\\frac{1}{\\sqrt{2}}(|200\\rangle+|210\\rangle), \\quad\\left|\\psi_{2}\\right\\rangle_{2}=|211\\rangle, \\\\\n&\\left|\\psi_{2}\\right\\rangle_{3}=|21-1\\rangle, \\quad\\left|\\psi_{2}\\right\\rangle_{4}=\\frac{1}{\\sqrt{2}}(|200\\rangle-|210\\rangle) .\n\\end{aligned}\n$$\nThis perturbation has only partially removed the degeneracy of the $n=2$ level; the states $|211\\rangle$ and $|21-1\\rangle$ still have the same energy $E_{3}=E_{4}=-R_{y} / 4$.\n\n\\subsection{spin orbit coupling}\nOne of the most useful applications of perturbation theory is to calculate the energy corrections for the hydrogen atom, notably the corrections due to the fine structure. The fine structure is in turn due to two effects: spin-orbit coupling and the relativistic correction. Let us look at these corrections separately.\\\\\n\\par The spin-orbit coupling in hydrogen arises from the interaction between the electron's spin magnetic moment, $\\vec{\\mu}_{S}=-e \\vec{S} /\\left(m_{e} c\\right)$, and the proton's orbital magnetic field $\\vec{B}$.\n\nThe origin of the magnetic field experienced by the electron moving at $\\vec{v}$ in a circular orbit around the proton can be explained classically as follows. The electron, within its rest frame. sees the proton moving at $-\\vec{v}$ in a circular orbit around it . From classical electrodynamics, the magnetic field experienced by the electron is\n$$\n\\vec{B}=-\\frac{1}{c} \\vec{v} \\times \\vec{E}=-\\frac{1}{m_{e} c} \\vec{p} \\times \\vec{E}=\\frac{1}{m_{e} c} \\vec{E} \\times \\vec{p},\n$$\nBut $$\\vec{E}(\\vec{r})=-\\vec{\\nabla} \\phi(r)=\\frac{1}{e} \\vec{\\nabla} V(r)=\\frac{1}{e} \\frac{\\vec{r}}{r} \\frac{d V}{d r} $$\nThen B is $$\\vec{B}=\\frac{1}{m_{e} c} \\vec{E} \\times \\vec{p}=\\frac{1}{e m_{e} c} \\frac{1}{r} \\frac{d V}{d r} \\vec{r} \\times \\vec{p}=\\frac{1}{e m_{e} c} \\frac{1}{r} \\frac{d V}{d r} \\vec{L}$$\nwhere $\\vec{L}=\\vec{r} \\times \\vec{p}$ is the orbital angular momentum of the electron.\nThe interaction of the electron's spin dipole moment $\\vec{\\mu}_{S}$ with the orbital magnetic field $\\vec{B}$ of the nucleus gives rise to the following interaction energy:\n$$\n\\hat{H}_{S O}=-\\vec{\\mu}_{S} \\cdot \\vec{B}=\\frac{e}{m_{e} c} \\vec{S} \\cdot \\vec{B}=\\frac{1}{m_{e}^{2} c^{2}} \\frac{1}{r} \\frac{d V}{d r} \\vec{S} \\cdot \\vec{L} .\n$$\n This energy turns out to be twice the observed spin-orbit interaction.Therefore \\\\\n $$\\hat{H}_{S O}=\\frac{1}{2 m_{e}^{2} c^{2}} \\frac{1}{r} \\frac{d V}{d r} \\vec{S} \\cdot \\vec{L}$$\n The corresponding quantum mechanical expression \\\\\n $$\\hat{H}_{S O}=\\frac{1}{2 m_{e}^{2} c^{2}} \\frac{1}{r} \\frac{d \\hat{V}}{d r} \\hat{S} \\cdot \\hat{\\vec{L}}$$\nFor a hydrogen's electron, $V(r)=-e^{2} / r$ and $d V / d r=e^{2} / r^{2}$.\n$$\n\\hat{H}_{S O}=\\frac{e^{2}}{2 m_{e}^{2} c^{2}} \\frac{1}{r^{3}} \\hat{S} \\cdot \\hat{L}\n$$\nWe can now use perturbation theory to calculate the contribution of the spin-orbit interaction in a hydrogen atom:\n$$\n\\hat{H}=\\frac{\\hat{\\vec{p}}^{2}}{2 m_{e}}-\\frac{e^{2}}{r}+\\frac{e^{2}}{2 m_{e}^{2} c^{2} r^{3}} \\hat{\\vec{S}} \\cdot \\hat{\\vec{L}}=\\hat{H}_{0}+\\hat{H}_{S O}\n$$\nwhere $\\hat{H}_{0}$ is the unperturbed Hamiltonian and $\\hat{H}_{S O}$ is the perturbation. To apply perturbation theory, we need to specify the unperturbed states-the eigenstates of $\\hat{H}_{0 .}$ Since the spin of the hydrogen's electron is taken into account, the total wave function of $\\hat{H}_{0}$ consists of a direct product of two parts: a spatial part and a spin part. \\\\\nThe eigen state is \n$$\\Psi_{n, l, j=l \\pm \\frac{1}{2}, m}=R_{n l}(r)\\left[\\sqrt{\\frac{l \\mp m+\\frac{1}{2}}{2 l+1}} Y_{l, m+\\frac{1}{2}}\\left|\\frac{1}{2},-\\frac{1}{2}\\right\\rangle \\pm \\sqrt{\\frac{l \\pm m+\\frac{1}{2}}{2 l+1}} Y_{l, m-\\frac{1}{2}}\\left|\\frac{1}{2}, \\frac{1}{2}\\right\\rangle\\right]$$\n the corresponding eigenvalues are given by\n $$\\langle n l j m|\\hat{\\vec{L}} \\cdot \\hat{\\vec{S}}| n l j m\\rangle=\\frac{\\hbar^{2}}{2}\\left[j(j+1)-l(l+1)-\\frac{3}{4}\\right]$$\n$\\text { since } \\hat{\\vec{S}} \\cdot \\hat{\\vec{L}}=\\frac{1}{2}\\left[\\hat{J}^{2}-\\hat{L}^{2}-\\hat{S}^{2}\\right]$\n\nThe eigenvalues of total Hamiltonian H are then given to first-order correction by\n$$\nE_{n l j}=E_{n}^{(0)}+\\left\\langle n l j m_{j}\\left|\\hat{H}_{S O}\\right| n l j m_{j}\\right\\rangle=-\\frac{e^{2}}{2 a_{0}} \\frac{1}{n^{2}}+E_{S O}^{(1)}\n$$\nwhere $E_{n}^{(0)}=-e^{2} /\\left(2 a_{0} n^{2}\\right)=-\\left(13.6 / n^{2}\\right) \\mathrm{eV}$ are the energy levels of hydrogen and $E_{S O}^{(1)}$ is the energy due to spin-orbit interaction:\n$$\nE_{S O}^{(1)}=\\left\\langle n l j m_{j}\\left|\\hat{H}_{S O}\\right| n l j m_{j}\\right\\rangle=\\frac{e^{2} \\hbar^{2}}{4 m_{e}^{2} c^{2}}\\left[j(j+1)-l(l+1)-\\frac{3}{4}\\right]\\left\\langle n l\\left|\\frac{1}{r^{3}}\\right| n l\\right\\rangle\n$$\n$$\\left\\langle n l\\left|\\frac{1}{r^{3}}\\right| n l\\right\\rangle=\\frac{2}{n^{3} l(l+1)(2 l+1) a_{0}^{3}}$$\n\n$$E_{S O}^{(1)}=\\frac{e^{2} \\hbar^{2}}{2 m_{e}^{2} c^{2}}\\left[\\frac{j(j+1)-l(l+1)-\\frac{3}{4}}{n^{3} l(l+1)(2 l+1) a_{0}^{3}}\\right]$$\n\n$$\\begin{aligned}\n\t&=\\left(\\frac{e^{2}}{2 a_{0}} \\frac{1}{n^{2}}\\right)\\left(\\frac{\\hbar}{m_{e} c a_{0}}\\right)^{2} \\frac{1}{n}\\left[\\frac{j(j+1)-l(l+1)-\\frac{3}{4}}{l(l+1)(2 l+1)}\\right] \\\\\n\t&E_{S O}^{(1)}=\\frac{\\left|E_{n}^{(0)}\\right| \\alpha^{2}}{n}\\left[\\frac{j(j+1)-l(l+1)-\\frac{3}{4}}{l(l+1)(2 l+1)}\\right],\n\\end{aligned}$$\n\nwhere $\\alpha$ is a dimensionless constant called the fine structure constant:\n$$\n\\alpha=\\frac{\\hbar}{m_{e} c a_{0}}=\\frac{e^{2}}{\\hbar c} \\simeq \\frac{1}{137} .\n$$\nSince $a_{0}=\\hbar^{2} /\\left(m_{e} e^{2}\\right)$ and hence $E_{n}^{(0)}=-e^{2} /\\left(2 a_{0} n^{2}\\right)=-\\alpha^{2} m_{e} c^{2} /\\left(2 n^{2}\\right)$, we can express in terms of $\\alpha$ as\n$$\nE_{S O}^{(1)}=\\frac{\\alpha^{4} m_{e} c^{2}}{2 n^{3}}\\left[\\frac{j(j+1)-l(l+1)-\\frac{3}{4}}{l(l+1)(2 l+1)}\\right] .\n$$\n\\subsubsection{Relativistic correction}\nAlthough the relativistic effect in hydrogen due to the motion of the electron is small, it can still be detected by spectroscopic techniques. The relativistic kinetic energy of the electron is given by $\\hat{T}=\\sqrt{\\hat{p}^{2} c^{2}+m_{e}^{2} c^{4}}-m_{e} c^{2}$, where $m_{e} c^{2}$ is the rest mass energy of the electron; an expansion of this relation to $\\hat{p}^{4}$ yields\n$$\n\\sqrt{\\hat{p}^{2} c^{2}+m_{e}^{2} c^{4}}-m_{e} c^{2} \\simeq \\frac{\\hat{p}^{2}}{2 m_{e}}-\\frac{\\hat{p}^{4}}{8 m_{e}^{3} c^{2}}+\\cdots\n$$\nWhen this term is included, the hydrogen's Hamiltonian becomes\n$$\n\\hat{H}=\\frac{\\hat{p}^{2}}{2 m_{e}}-\\frac{e^{2}}{r}-\\frac{\\hat{p}^{4}}{8 m^{3} c^{2}}=\\hat{H}_{0}+\\hat{H}_{R},\n$$\nwhere $\\hat{H}_{0}=\\hat{p}^{2} /\\left(2 m_{e}\\right)-e^{2} / r$ is the unperturbed Hamiltonian and $\\hat{H}_{R}=-\\hat{p}^{4} /\\left(8 m_{e}^{3} c^{2}\\right)$ is the relativistic mass correction which can be treated by first-order perturbation theory:\n$$\nE_{R}^{(1)}=\\left\\langle n l j m_{j}\\left|\\hat{H}_{R}\\right| n l j m_{j}\\right\\rangle=-\\frac{1}{8 m_{c}^{3} c^{2}}\\left\\langle n l j m_{j}\\left|\\hat{p}^{4}\\right| n l j m_{j}\\right\\rangle .\n$$\n$$\n\\left\\langle n l j m,\\left|\\hat{p}^{4}\\right| n l j m_{j}\\right\\rangle=\\frac{m_{e}^{4} e^{8}}{\\hbar^{4} n^{4}}\\left(\\frac{8 n}{2 l+1}-3\\right)=\\frac{\\alpha^{4} m_{e}^{4} c^{4}}{n^{4}}\\left(\\frac{8 n}{2 l+1}-3\\right)\n$$\nAn insertion of this value in last equation leads to\n$$\nE_{R}^{(1)}=-\\frac{\\alpha^{4} m_{e} c^{2}}{8 n^{4}}\\left(\\frac{8 n}{2 l+1}-3\\right)=-\\frac{\\alpha^{2}\\left|E_{n}^{(0)}\\right|}{4 n^{2}}\\left(\\frac{8 n}{2 l+1}-3\\right)\n$$\n\\textbf{Remark}\\\\\nFor a hydrogenlike atom having $Z$ electrons, and if we neglect the spin-orbit interaction,\n$$\nE_{n}=Z^{2}\\left(E_{n}^{(0)}+E_{R}^{(1)}\\right)=Z^{2} E_{n}^{(0)}\\left[1+\\frac{\\alpha^{2}}{n}\\left(\\frac{2}{2 l+1}-\\frac{3}{4 n}\\right)\\right]\n$$\nwhere $E_{n}^{(0)}=-e^{4} m_{e} /\\left(2 \\hbar^{2} n^{2}\\right)=-\\alpha^{2} m_{e} c^{2} /\\left(2 n^{2}\\right)=-13.6 \\mathrm{eV} / n^{2}$ is the Bohr energy.\n\\subsubsection{Fine structure of hydrogen atom}\nThe fine structure correction is obtained by adding the expressions for the spin-orbit and relativistic corrections\n$$\nE_{F S}^{(1)}=E_{S O}^{(1)}+E_{R}^{(1)}=\\frac{\\alpha^{4} m_{e} c^{2}}{2 n^{3}}\\left[\\frac{j(j+1)-l(l+1)-\\frac{3}{4}}{l(l+1)(2 l+1)}\\right]-\\frac{\\alpha^{4} m_{e} c^{2}}{8 n^{4}}\\left[\\frac{8 n}{2 l+1}-3\\right]\n$$\nwhere $j=l \\pm \\frac{1}{2} .$ If $j=l+\\frac{1}{2}$ a substitution of $l=j-\\frac{1}{2}$  leads to\n$$\\begin{aligned}\n\tE_{F S}^{(1)} &=\\frac{\\alpha^{4} m_{e} c^{2}}{8 n^{4}}\\left[\\frac{4 n j(j+1)-4 n\\left(j-\\frac{1}{2}\\right)\\left(j+\\frac{1}{2}\\right)-3 n}{\\left(j-\\frac{1}{2}\\right)\\left(j+\\frac{1}{2}\\right)(2 j-1+1)}-\\frac{8 n}{2 j-1+1}+3\\right] \\\\\n\t&=\\frac{\\alpha^{4} m_{e} c^{2}}{8 n^{4}}\\left[\\frac{4 n j-2 n}{2 j\\left(j-\\frac{1}{2}\\right)\\left(j+\\frac{1}{2}\\right)}-\\frac{4 n}{j}+3\\right]=\\frac{\\alpha^{4} m_{e} c^{2}}{8 n^{4}}\\left[\\frac{2 n}{j\\left(j+\\frac{1}{2}\\right)}-\\frac{4 n}{j}+3\\right] \\\\\n\t&=\\frac{\\alpha^{4} m_{e} c^{2}}{8 n^{4}}\\left[3-\\frac{4 n}{j+\\frac{1}{2}}\\right] .\n\\end{aligned}$$\n$\\text { Similarly, if } j=l-\\frac{1}{2} \\text {, and hence } l=j+\\frac{1}{2} \\text {, we can reduce } E_{F S}^{(1)}$ to\\\\\n$$\\begin{aligned}\n\tE_{F S}^{(1)} &=\\frac{\\alpha^{4} m_{e} c^{2}}{8 n^{4}}\\left[\\frac{4 n j(j+1)-4 n\\left(j+\\frac{1}{2}\\right)\\left(j+\\frac{3}{2}\\right)-3 n}{\\left(j+\\frac{1}{2}\\right)\\left(j+\\frac{3}{2}\\right)(2 j+1+1)}-\\frac{8 n}{2 j+1+1}+3\\right] \\\\\n\t&=\\frac{\\alpha^{4} m_{e} c^{2}}{8 n^{4}}\\left[\\frac{-4 n j-6 n}{2\\left(j+\\frac{1}{2}\\right)\\left(j+\\frac{3}{2}\\right)(j+1)}-\\frac{4 n}{j+1}+3\\right] \\\\\n\t&=\\frac{\\alpha^{4} m_{e} c^{2}}{8 n^{4}}\\left[\\frac{-2 n}{\\left(j+\\frac{1}{2}\\right)(j+1)}-\\frac{4 n}{j+1}+3\\right] \\\\\n\t&=\\frac{\\alpha^{4} m_{e} c^{2}}{8 n^{4}}\\left[3-\\frac{4 n}{j+\\frac{1}{2}}\\right]\n\\end{aligned}$$\nAs equations show, the expressions for the fine structure correction corresponding to $j=l+\\frac{1}{2}$ and $j=l-\\frac{1}{2}$ are the same:\n$$\nE_{F S}^{(1)}=E_{S O}^{(1)}+E_{R}^{(1)}=\\frac{\\alpha^{4} m_{e} c^{2}}{8 n^{4}}\\left(3-\\frac{4 n}{j+\\frac{1}{2}}\\right)=\\frac{\\alpha^{2} E_{n}^{(0)}}{4 n^{2}}\\left(\\frac{4 n}{j+\\frac{1}{2}}-3\\right)\n$$\nwhere $E_{n}^{(0)}=-\\alpha^{2} m_{e} c^{2} /\\left(2 n^{2}\\right)$ and $j=l \\pm \\frac{1}{2}$.\n\n$$\\frac{E_{S O}^{(1)}}{\\left|E_{n}^{(0)}\\right|} \\simeq \\alpha^{2}, \\quad\\left|\\frac{E_{R}^{(1)}}{E_{n}^{(0)}}\\right| \\simeq \\alpha^{2}, \\quad \\frac{E_{F S}^{(1)}}{\\left|E_{n}^{(0)}\\right|} \\simeq \\alpha^{2}$$\n\nAll these terms are of the order of $10^{-4}$ since $\\alpha^{2}=(1 / 137)^{2} \\simeq 10^{-4}$\\\\\nIn sum, the hydrogen's Hamiltonian, when including the fine structure, is given by\n$$\\hat{H}=\\hat{H}_{0}+\\hat{H}_{F S}=\\hat{H}_{0}+\\left(\\hat{H}_{S O}+\\hat{H}_{R}\\right)=\\frac{\\hat{p}^{2}}{2 m_{e}}-\\frac{e^{2}}{r}+\\left(\\frac{e^{2}}{2 m_{e}^{2} c^{2} r^{3}} \\hat{\\hat{S}} \\cdot \\hat{\\vec{L}}-\\frac{\\hat{p}^{4}}{8 m_{e}^{3} c^{2}}\\right)$$\nA first-order perturbation calculation of the energy levels of hydrogen, when including the fine structure, yields\n$$\nE_{n j}=E_{n}^{(0)}+E_{F S}^{(1)}=E_{n}^{(0)}\\left[1+\\frac{\\alpha^{2}}{4 n^{2}}\\left(\\frac{4 n}{j+\\frac{1}{2}}-3\\right)\\right]\n$$\n\\begin{exercise}\n A particle of mass $\\mathrm{m}_{0}$ and charge ' $e$ ' oscillates along the the $\\mathrm{x}$-axis in a one-dimensional harmonic potential with an angular frequency $\\omega$. If an electric field $\\varepsilon$ is applied along the $x$-axis, evaluate the first and second order corrections to the energy of the $\\mathrm{n}^{\\text {th }}$ state.\n\\end{exercise}\n\\begin{answer}\nThe potential energy due to the field $\\varepsilon=-\\vec{p} \\cdot \\vec{E}=-e \\varepsilon x$\\\\\nThe perturbation $$H^{\\prime}=-e \\varepsilon x=-e \\varepsilon \\sqrt{\\frac{\\hbar}{2 m_{0} \\omega}}\\left(\\hat{a}+\\hat{a}^{\\dagger}\\right)$$\nFirst order correction to energy $$=E_{n}^{(1)}=-e \\varepsilon \\sqrt{\\frac{\\hbar}{2 m_{0} \\omega}}\\left\\langle n\\left|\\left(\\hat{a}+\\hat{a}^{\\dagger}\\right)\\right| n\\right\\rangle=0$$\n$$\\text { second order correction to energy }=E_{n}^{(2)}=\\sum_{m \\neq n} \\frac{\\left|\\left\\langle n\\left|H^{\\prime}\\right| m\\right\\rangle\\right|^{2}}{E_{n}^{0}-E_{m}^{0}}$$\n$$\\text { Now, }\\left\\langle n\\left|H^{\\prime}\\right| m\\right\\rangle=-e \\varepsilon \\sqrt{\\frac{\\hbar}{2 m_{0} \\omega}}\\left\\langle n\\left|a+a^{\\dagger}\\right| m\\right\\rangle$$\nHere, $m$ can take all integral values except $n$.\\\\\n The non-vanishing elements corresponds to $m=(n+1)$ and $(n-1)$.\\\\\n Hence,\nTherefore, $$E_{n}^{(2)}=e^{2} \\varepsilon^{2} \\frac{\\hbar}{2 m_{0} \\omega}\\left[\\frac{(\\sqrt{n+1})^{2}}{-\\hbar \\omega}+\\frac{(\\sqrt{n})^{2}}{\\hbar \\omega}\\right]=-\\frac{e^{2} \\varepsilon^{2}}{2 m_{0} \\omega^{2}}$$\t\n\\end{answer}\n\\begin{exercise}\n\t Evaluate the first and second order correction to the energy of the $n=1$ state of an oscillator of mass 'm' and angular frequency ' $\\omega$ ' subjected to a potential.\n\\end{exercise}\n\\begin{answer}\n\t$$\n\tV(x)=\\frac{1}{2} m \\omega^{2} x^{2}+b x, \\quad b x<<\\frac{1}{2} m \\omega^{2} x^{2}\n\t$$\n\tThe first order correction to energy for the $n=1$ state is given by\n\t$$\n\tE_{1}^{(1)}=\\langle 1|b x| 1\\rangle=b \\sqrt{\\frac{\\hbar}{2 m \\omega}}\\left\\langle 1\\left|\\left(\\hat{a}+\\hat{a}^{\\dagger}\\right)\\right| 1\\right\\rangle=0\n\t$$\n\tUsing, $a|n\\rangle=\\sqrt{n}|n-1\\rangle$ and $a^{\\dagger}|n\\rangle=\\sqrt{n+1}|n+1\\rangle$\n\tThe second order correction to energy for the $n=1$ state is given by\n\t$$\n\t\\begin{aligned}\n\tE_{1}^{(2)} &=b^{2}\\left(\\frac{\\hbar}{2 m \\omega}\\right) \\sum_{k \\neq 1} \\frac{\\left|\\left\\langle 1\\left|\\left(\\hat{a}+\\hat{a}^{\\dagger}\\right)\\right| k_{k}\\right\\rangle\\right|^{2}}{E_{1}^{0}-E_{k}^{0}}=b^{2}\\left(\\frac{\\hbar}{2 m \\omega}\\right)\\left[\\frac{1}{E_{1}^{0}-E_{0}^{0}}+\\frac{2}{E_{1}^{0}-E_{2}^{0}}\\right] \\\\\n\t&=b^{2}\\left(\\frac{\\hbar}{2 m \\omega}\\right)\\left(\\frac{1}{\\hbar \\omega}-\\frac{2}{\\hbar \\omega}\\right)=-\\frac{b^{2}}{2 m \\omega^{2}}\n\t\\end{aligned}\n\t$$\n\\end{answer}\n\\begin{exercise}\n\tExample 4. Consider the infinite square well defined by\n\t$$\n\t\\begin{aligned}\n\t&V(x)=0 \\text { for } 0 \\leq x<a \\\\\n\t&V(x)=\\infty \\text { otherwise }\n\t\\end{aligned}\n\t$$\n\tUsing the first order perturbation theory, calculate the energy of the first two states of the potential wellifa portion defined by $V(x)=V_{0} x / a$, where $\\mathrm{V}_{0}$ is a small constant, with $0 \\leq x \\leq a$ being sliced off.\n\\end{exercise}\n\\begin{answer}\n\tThe energy eigenvalues and normalized eigenfunctions of the $\\mathrm{n}^{\\text {th }}$ state of unperturbed Hamiltonian are\n\t$$\n\tE_{n}^{0}=\\frac{n^{2} \\pi^{2} \\hbar^{2}}{2 m a^{2}}, \\psi_{n}^{0}=\\sqrt{\\frac{2}{a}} \\sin \\frac{n \\pi x}{a}, \\quad n=1,2,3, \\ldots\n\t$$\n\tThe perturbation $H^{\\prime}=V_{0} x / a$ which is depicted in figure below.\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{pert-crop}\n\t\t\\caption{sliced infinite potential well}\n\t\t\\label{}\n\t\\end{figure}\n\tThe first order correction to the energy for the $\\mathrm{n}=1$ state is\n\t$$\n\tE_{1}^{(1)}=\\left\\langle\\psi_{1}^{0}\\left|\\frac{V_{0} x}{a}\\right| \\psi_{1}^{0}\\right\\rangle=\\frac{V_{0}}{a} \\frac{2}{a} \\int_{0}^{a} x \\sin ^{2} \\frac{\\pi x}{a} d x\n\t$$\n\t$$\\begin{aligned}\n\t\t&=\\frac{2 V_{0}}{a^{2}} \\int_{0}^{a} \\frac{x}{2}\\left(1-\\cos \\frac{2 \\pi x}{a}\\right) d x=\\frac{2 V_{0}}{a^{2}} \\int_{0}^{a} \\frac{x}{2} d x-\\frac{2 V_{0}}{a^{2}} \\int_{0}^{a} \\frac{x}{2} \\cos \\frac{2 \\pi x}{a} d x \\\\\n\t\t&=\\frac{V_{0}}{2}+0=\\frac{V_{0}}{2}\n\t\\end{aligned}$$\n\tThe first order correction to the enegry for the $n=2$ state is\n\t$$\n\tE_{2}^{(1)}=\\left\\langle\\psi_{2}^{0}\\left|\\frac{V_{0} x}{a}\\right| \\psi_{2}^{0}\\right\\rangle=\\frac{V_{0}}{a} \\frac{2}{a} \\int x \\sin ^{2} \\frac{2 \\pi x}{a} d x=\\frac{V_{0}}{2}\n\t$$\n\tThe ground state and first excited energies corrected upto first order are\n\t$$\n\t\\frac{\\pi^{2} \\hbar^{2}}{2 m a^{2}}+\\frac{V_{0}}{2} \\text { and } \\frac{2 \\pi^{2} \\hbar^{2}}{m a^{2}}+\\frac{V_{0}}{2}\n\t$$\n\\end{answer}\n\\begin{exercise}\n. A particle of mass ' $m$ ' moves in an infinite one-dimensional box of bottom ' $a$ ' with a potential dip as defined by\n\t$$\n\t\\begin{aligned}\n\t&V(x)=\\infty \\text { for } x<0 \\text { and } x>a \\\\\n\t&V(x)=-V_{0} \\text { for } 0<x<\\frac{a}{3} \\\\\n\t&V(x)=0 \\text { for } \\frac{a}{3}<x<a\n\t\\end{aligned}\n\t$$\n\tFind the first order energy of the ground state.\n\\end{exercise}\n\\begin{answer}\nFor a particle in the infinite potential well defined by $V(x)=0$ for $0<x<a$ and $V(x)=\\infty$ otherwise, the energy eigenvalues and normalized eigenfunctions are\n$$\nE_{n}=\\frac{n^{2} \\pi^{2} \\hbar^{2}}{2 m a^{2}}, \\psi_{n}=\\sqrt{\\frac{2}{a}} \\sin \\frac{n \\pi x}{a}, \\quad n=1,2,3, \\ldots . .\n$$\nThe perturbing Hamiltonian is $H$ ' $=-V_{0}$ for $0<x<a / 3$.\nThe first order energy correction to the ground state is\\\\\n\\begin{minipage}{0.5\\textwidth}\n$$\n\\begin{aligned}\nE_{0}^{(1)} &=-\\frac{2}{a} V_{0} \\int_{0}^{a / 3} \\sin ^{2} \\frac{\\pi x}{a} d x \\\\\n&=-\\frac{2}{a} V_{0} \\int_{0}^{a / 3} \\frac{1}{2}\\left(1-\\cos \\frac{2 \\pi x}{a}\\right) d x \\\\\n&=-\\frac{V_{0}}{a}[x]_{0}^{a / 3}+\\frac{V_{0}}{a} \\frac{a}{2 \\pi}\\left[\\sin \\frac{2 \\pi x}{a}\\right]_{0}^{a / 3} \\\\\n&=-\\frac{V_{0}}{3}+\\frac{V_{0}}{4 \\pi} \\times 0.866=-0.264 V_{0}\n\\end{aligned}\n$$\nThe energy of the ground state corrected to first order is\n$$\nE_{1}^{\\prime}=\\frac{\\pi^{2} \\hbar^{2}}{2 m a^{2}}-0.264 V_{0}\n$$\t\n\\end{minipage}\n\\begin{minipage}{0.5\\textwidth}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3cm,width=5cm]{pert2}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\n\\end{minipage}\n\\end{answer}\n\\section{The variational method}\n\nThere exist systems whose Hamiltonians are known, but they cannot be solved exactly or by a perturbative treatment. That is, there is no closely related Hamiltonian that can be solved exactly or approximately by perturbation theory because the first order is not sufficiently accurate. One of the approximation methods that is suitable for solving such problems is the variational method, which is also called the Rayleigh-Ritz method.  The variational method is useful for determining upper bound values for the eigenenergies of a system whose Hamiltonian is known whereas its eigenvalues and eigenstates are not known. It is particularly useful for determining the ground state. It becomes quite difficult to determine the energy levels of the excited states.\\\\\\\\\nIn the context of the variational method, one does not attempt to solve the eigenvalue problem\n$$\n\\hat{H}|\\psi\\rangle=E|\\psi\\rangle,\n$$\nbut rather one uses a variational scheme to find the approximate eigenenergies and eigenfunctions from the variational equation\n$$\n\\delta E(\\psi)=0\n$$\nwhere $E(\\psi)$ is the expectation value of the energy in the state $|\\psi\\rangle$ :\n$$\nE(\\psi)=\\frac{\\langle\\psi|\\hat{H}| \\psi\\rangle}{\\langle\\psi \\mid \\psi\\rangle}\n$$\n$\\text { If }|\\psi\\rangle \\text { depends on a parameter } \\alpha, E(\\psi) \\text { will also depend on } \\alpha$\\\\\nThe variational method is particularly useful for determining the ground state energy and its eigenstate without explicitly solving the Schrödinger equation. Note that for any (arbitrary) trial function $|\\psi\\rangle$ we choose, the energy $E$ is always larger than the exact energy $E_{0}$ :\n$$\nE=\\frac{\\langle\\psi|H| \\psi\\rangle}{\\langle\\psi \\mid \\psi\\rangle} \\geq E_{0}\n$$\n$\\text { To calculate the ground state energy, we need to carry out the following four steps: }$\n\\begin{itemize}\n\t\\item First, based on physical intuition, make an educated guess of a trial function that takes into account all the physical properties of the ground state (symmetries, number of nodes, smoothness, behavior at infinity, etc.). For the properties you are not sure about, include in the trial function adjustable parameters $\\alpha_{1}, \\alpha_{2}, \\ldots$ (i.e., $\\left.\\left|\\psi_{0}\\right\\rangle=\\left|\\psi_{0}\\left(\\alpha_{1}, a_{2}, \\ldots\\right)\\right\\rangle\\right)$ which will account for the various possibilities of these unknown properties.\n\t\\item Second, using $E(\\psi)=\\frac{\\langle\\psi|\\hat{H}| \\psi\\rangle}{\\langle\\psi \\mid \\psi\\rangle}$, calculate the energy; this yields an expression which depends on the parameters $\\alpha_{1}, \\alpha_{2}, \\ldots$ :\n\t$$\n\tE_{0}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right)=\\frac{\\left\\langle\\psi_{0}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right)|\\hat{H}| \\psi_{0}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right)\\right\\rangle}{\\left\\langle\\psi_{0}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right) \\mid \\psi_{0}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right)\\right\\rangle} .\n\t$$\n\tIn most cases $\\left|\\psi_{0}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right)\\right\\rangle$ will be assumed to be normalized; hence the denominator of this expression is equal to 1 .\n\t\\item Third, using the above equation search for the minimum of $E_{0}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right)$ by varying the adjustable parameters $\\alpha_{i}$ until $E_{0}$ is minimized. That is, minimize $E\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right)$ with respect to $\\alpha_{1}, \\alpha_{2}, \\ldots$ :\n\t$$\n\t\\frac{\\partial E_{0}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right)}{\\partial \\alpha_{i}}=\\frac{\\partial}{\\partial \\alpha_{i}} \\frac{\\left\\langle\\psi_{0}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right)|\\hat{H}| \\psi_{0}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right)\\right\\rangle}{\\left\\langle\\psi_{0}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right) \\mid \\psi_{0}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right)\\right\\rangle}=0\n\t$$\n\twith $i=1,2, \\ldots$. This gives the values of $\\left(\\alpha_{1_{0}}, \\alpha_{2_{0}}, \\ldots\\right)$ that minimize $E_{0}$.\n\t\\item - Fourth, substitute these values of $\\left(\\alpha_{1}, \\alpha_{2_{0}}, \\ldots\\right)$ into $E_{0}\\left(\\alpha_{1_{0}}, \\alpha_{2_{0}}, \\ldots\\right)$ to obtain the approximate value of the energy. The value $E_{0}\\left(\\alpha_{1_{0}}, \\alpha_{2_{0}}, \\ldots\\right)$ thus obtained provides an upper bound for the exact ground state energy $E_{0}$. The exact ground state eigenstate $\\left|\\phi_{0}\\right\\rangle$ will then be approximated by the state $\\left|\\psi_{0}\\left(\\alpha_{1}, \\alpha_{2_{0}}, \\ldots\\right)\\right\\rangle$.\n\\end{itemize}\n\n The variational method can also be used to find the approximate values for the energies of the first few excited states. For instance, to find the energy and eigenstate of the first excited state that will approximate $E_{1}$ and $\\left|\\phi_{1}\\right\\rangle$, we need to choose a trial function $\\left|\\psi_{1}\\right\\rangle$ that must be orthogonal to $\\left|\\psi_{0}\\right\\rangle$ :\n$$\\left\\langle\\psi_{1} \\mid \\phi_{0}\\right\\rangle=0$$\n\nThen proceed as we did in the case of the ground state. That is, solve the variational equation $\\delta E(\\psi)=0$ for $\\left|\\psi_{1}\\right\\rangle:$\n$$\n\\frac{\\partial}{\\partial \\alpha_{i}} \\frac{\\left\\langle\\psi_{1}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right)|\\hat{H}| \\psi_{1}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right)\\right\\rangle}{\\left\\langle\\psi_{1}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right) \\mid \\psi_{1}\\left(\\alpha_{1}, \\alpha_{2}, \\ldots\\right)\\right\\rangle}=0 \\quad(i=1,2, \\ldots) .\n$$\nSimilarly, to evaluate the second excited state, we solve $\\delta E(\\psi)=0$ for  $\\left|\\psi_{2}\\right\\rangle$ and take into account the following two conditions:\n$$\n\\left\\langle\\psi_{2} \\mid \\psi_{0}\\right\\rangle=0, \\quad\\left\\langle\\psi_{2} \\mid \\psi_{1}\\right\\rangle=0 .\n$$\n\\begin{exercise}\n For the harmonic oscillator $V(x)=\\frac{1}{2} m \\omega^{2} x^{2}$, then choose a trial wave function $\\psi(x, \\alpha)=A e^{-\\alpha x^{2}}$. Find the energy of ground state with the method of variational principle.\n\\end{exercise}\n\\begin{answer}\n\tSolution: From normalization condition $\\int_{-\\infty}^{+\\infty} \\psi^{2} \\psi d x=1$, the value of $A=\\left(\\frac{2 \\alpha}{\\pi}\\right)^{\\frac{1}{4}}$\\\\\n\t The expectation value of kinetic energy for given wavefunction is $\\langle T\\rangle=\\frac{\\hbar^{2} \\alpha}{2 m}$\\\\\n\tThe expectation value of potential energy\n\t$$\n\t\\langle V\\rangle=\\left(\\frac{2 \\alpha}{\\pi}\\right)^{2} \\int_{-1}^{+1} \\frac{1}{2} m \\omega^{2} x^{2} e^{-2 \\alpha x^{2}} d x=\\left(\\frac{2 \\alpha}{\\pi}\\right)^{\\frac{1}{2}} \\times \\frac{1}{2} m \\omega^{2} \\int_{\\infty}^{\\infty} x^{2} e^{-2 \\alpha x^{2}} d x=\\frac{m \\omega^{2}}{8 \\alpha}\n\t$$\n\tThen the expectation value of total energy is $\\langle E\\rangle=\\frac{\\hbar^{2} \\alpha}{2 m}+\\frac{m \\omega^{2}}{8 \\alpha}$\\\\\n\t $\\frac{d E}{d \\alpha}=0, \\frac{\\hbar^{2}}{2 m}-\\frac{m \\omega^{2}}{8 \\alpha^{2}}=0, \\alpha_{0}=\\frac{m \\omega}{2 \\hbar}$\\\\\n\t  putting the value of $\\alpha_{0} \\quad \\alpha_{0}=\\frac{m \\omega}{2 \\hbar} \\Rightarrow\\langle E\\rangle=\\frac{\\hbar \\omega}{2}$\n\\end{answer}\n\\begin{exercise}\n Find the energy eigen value for the ground state if particle is confined into $1-D$ infinite potential box of width ' $a$ ' centered at $\\frac{a}{2}$ by taking trial wavefunction. $\\psi=A x(a-x)$.\n\\end{exercise}\n\\begin{answer}$\\left. \\right. $\\\\\n\t\\begin{minipage}{0.5\\textwidth}\n\tFor normalization $|A|^{2} \\int_{0}^{a} x^{2}(a-x)^{2} d x=1 \\Rightarrow A=\\left(\\frac{30}{a^{5}}\\right)^{\\frac{1}{2}}$\\\\\n\tThe expectation value of kinetic energy\n\t$$\n\t\\begin{aligned}\n\t&\\langle T\\rangle=\\int_{0}^{a}\\left(\\frac{30}{a^{5}}\\right)^{\\frac{1}{2}} x(a-x) \\frac{-\\hbar}{2 m} \\frac{\\partial^{2}}{\\partial x^{2}}\\left(\\frac{30}{a^{5}}\\right)^{\\frac{1}{2}} x(a-x) d x \\\\\n\t&=\\frac{\\hbar^{2}}{m}\\left(\\frac{30}{a^{5}}\\right) \\frac{a^{3}}{6}=\\frac{5 \\hbar^{2}}{m a^{2}}\n\t\\end{aligned}\n\t$$\n\tThe expectation value of potential energy is $\\langle V\\rangle=0$\n\t$$\n\t\\langle E\\rangle=\\langle T\\rangle+\\langle V\\rangle=\\frac{5 \\hbar^{2}}{m a^{2}}\n\t$$\n\t(constant value)\n\t\\end{minipage}\n \\begin{minipage}{0.5\\textwidth}\n \\begin{figure}[H]\n \t\\centering\n \t\\includegraphics[height=3cm,width=5cm]{var-crop}\n \\end{figure}\t\n \\end{minipage}\n\\end{answer}\n\\section{The WKB appoximation method}\nThe Wentzel-Kramers-Brillouin (WKB) method is useful for approximate treatments of systems with slowly varying potentials; that is, potentials which remain almost constant over a region of the order of the de Broglie wavelength. In the case of classical systems, this property is always satisfied since the wavelength of a classical system approaches zero. The WKB method can thus be viewed as a semiclassical approximation.\\\\\n\\textbf{General formalism}\\\\\nConsider the motion of a particle in a time-independent potential $V(\\vec{r}) ;$ the Schrödinger equation for the corresponding stationary state is\n$$\n-\\frac{\\hbar^{2}}{2 m} \\nabla^{2} \\psi(\\vec{r})+V(\\vec{r}) \\psi(\\vec{r})=E \\psi(\\vec{r})\n$$\nor\n$$\n\\nabla^{2} \\psi(\\vec{r})+\\frac{1}{\\hbar^{2}} p^{2}(\\vec{r}) \\psi(\\vec{r})=0\n$$\nwhere $p(\\vec{r})$ is the classical momentum at $\\vec{r}: p(\\vec{r})=\\sqrt{2 m(E-V(\\vec{r}))}$. If the particle is moving in a region where $V(\\vec{r})$ is constant, the solution of schrodinger equation is of the form $\\psi(\\vec{r})=A e^{\\pm i \\vec{p} \\cdot \\vec{r} / \\hbar} .$ But how does one deal with those cases where $V(\\vec{r})$ is not constant? The WKB method provides an approximate treatment for systems whose potentials, while not constant, are slowly varying functions of $\\vec{r}$. That is, $V(\\vec{r})$ is almost constant in a region which extends over several de Broglie wavelengths; we may recall that the de Broglie wavelength of a particle of mass $m$ and energy $E$ that is moving in a potential $V(\\vec{r})$ is given by $\\lambda=h / p=h / \\sqrt{2 m(E-V(\\vec{r}))}$.\\\\\nIn essence, the WKB method consists of trying a solution to schrodinger rquation\n$$\n\\psi(\\vec{r})=A(\\vec{r}) e^{i S(\\vec{r}) / \\hbar},\n$$\nWhere $A(\\vec{r})$ is the amplitude and $S(\\vec{r})$ is the phase both are real functions and yet to be determined\\\\\nSubstituting the value of $\n\\psi(\\vec{r})=A(\\vec{r}) e^{i S(\\vec{r}) / \\hbar},\n$ in to schrodinger equation we will get\\\\\n$$A\\left[\\frac{\\hbar^{2}}{A} \\nabla^{2} A-(\\vec{\\nabla} S)^{2}+p^{2}(\\vec{r})\\right]+i \\hbar\\left[2(\\vec{\\nabla} A) \\cdot(\\vec{\\nabla} S)+A \\nabla^{2} S\\right]=0$$\nThe real and imaginary parts of this equation must vanish separately:\n$$\n\\begin{gathered}\n(\\vec{\\nabla} S)^{2}=p^{2}(\\vec{r})=2 m(E-V(\\vec{r})) \\\\\n2(\\vec{\\nabla} A) \\cdot(\\vec{\\nabla} S)+A \\nabla^{2} S=0\n\\end{gathered}\n$$\nTo illustrate the various aspects of the WKB method, let us consider the simple case of the one-dimensional motion of a single particle. We can thus reduce the above two equations, respectively, to\n$$\n\\begin{aligned}\n&\\frac{d S}{d x}=\\pm \\sqrt{2 m(E-V)}=\\pm p(x) \\\\\n&2\\left(\\frac{d}{d x} \\ln A\\right) p(x)+\\frac{d}{d x} p(x)=0\n\\end{aligned}\n$$\nFrom these two equations $A(\\vec{r})$ ,$S(\\vec{r})$ can be found.\n$$S(x)=\\pm \\int d x \\sqrt{2 m(E-V(x))}=\\pm \\int p(x) d x$$\n$$\n\\frac{d}{d x}[2 \\ln A+\\ln p(x)]=0\n$$\nwhich in turn leads to\n$$\nA(x)=\\frac{C}{\\sqrt{|p(x)|}}\n$$\nwe will get the solution by substituting the values of $A(\\vec{r})$ ,$S(\\vec{r})$ in to \n$\\psi(\\vec{r})$\\\\\n$$\\psi_{\\pm}(x)=\\frac{C_{\\pm}}{\\sqrt{|p(x)|}} \\exp \\left[\\pm \\frac{i}{\\hbar} \\int^{x} p\\left(x^{\\prime}\\right) d x^{\\prime}\\right] $$\nThe amplitude of this wave function is proportional to $1 / \\sqrt{p(x)}$; hence the probability of finding the particle between $x$ and $x+d x$ is proportional to $1 / p(x)$. This is what we expect for a \"classical\" particle because the time it will take to travel a distance $d x$ is proportional to the inverse of its speed (or its momentum).\n\\par We can now examine two separate cases corresponding to $E>V(x)$ and $E<V(x)$. First, let us consider the case $E>V(x)$, which is called the classically allowed region. Here $p(x)$ is a real function; the most general solution  is a combination of $\\psi_{+}(x)$ and $\\psi_{-}(x)$ :\n$$\n\\psi(x)=\\frac{C_{+}}{\\sqrt{p(x)}} \\exp \\left[\\frac{i}{\\hbar} \\int^{x} p\\left(x^{\\prime}\\right) d x^{\\prime}\\right]+\\frac{C_{-}}{\\sqrt{p(x)}} \\exp \\left[-\\frac{i}{\\hbar} \\int^{x} p\\left(x^{\\prime}\\right) d x^{\\prime}\\right]\n$$\nSecond, in the case where $E<V(x)$, which is known as the classically forbidden region, the momentum $p(x)$ is imaginary and the exponents of become real:\n$$\n\\psi(x)=\\frac{C_{-}^{\\prime}}{\\sqrt{|p(x)|}} \\exp \\left[-\\frac{1}{\\hbar} \\int_{x}\\left|p\\left(x^{\\prime}\\right)\\right| d x^{\\prime}\\right]+\\frac{C_{+}^{\\prime}}{\\sqrt{|p(x)|}} \\exp \\left[\\frac{1}{\\hbar} \\int^{x}\\left|p\\left(x^{\\prime}\\right)\\right| d x^{\\prime}\\right]\n$$\nBut what about the structure of the wave function near the regions $E \\simeq$ $V(x)$ ? At the points $x_{i}$, we have $E=V\\left(x_{i}\\right)$; hence the momentum $(9.167)$ vanishes, $p\\left(x_{1}\\right)=0$. These points are called the classical turning points, because classically the particle stops at $x_{i}$ and then turns back to resume its motion in the opposite direction. At these points the wave function $\\psi_{\\pm}(x)$ becomes infinite since $p\\left(x_{i}\\right)=0$. \n\\subsection{ W.K.B. Approximation Rules for Bound State Energy :}\n\\begin{enumerate}\n\t\\item  If both walls are smooth $\\Rightarrow \\oint p_{x} d x=\\left(n+\\frac{1}{2}\\right) h \\quad n=0,1,2 \\ldots$\n\t$$\n\t2 \\int_{x_{1}}^{x_{2}} p_{x} d x=\\left(n+\\frac{1}{2}\\right) h \\text { where } x_{1} \\text { and } x_{2} \\text { are turning point. }\n\t$$\n\t\\item If one wall is smooth \\& one wall is rigid \\\\\n\t$\\int_{x_{1}}^{x_{2}} p_{x} d x=\\left(n+\\frac{\\dot{3}}{4}\\right) \\pi \\hbar \\quad$\\\\\n\t where $x_{1}$ and $x_{2}$ are turning point\\\\\n\t  $n=0,1,2,3 \\ldots .$ \\\\\n\t  $=\\left(n+1+\\frac{3}{4}-1\\right) \\pi \\hbar=\\left(n-\\frac{1}{4}\\right) \\pi \\hbar, \\quad n=1,2,3 \\ldots .$\n\t  \\item When both walls are rigid:\n\t  $\\int_{x_{1}}^{x_{2}} p_{x} d x=(n+1) \\pi \\hbar \\quad$ \\\\\n\t  where $x_{1}$ and $x_{2}$ are turning point $n=0,1,2, \\ldots . .$\n\t  $$\n\t  \\text { if }(n+1)=m \\quad m=1,2,3 \\ldots\n\t  $$\n\\end{enumerate}\n\n\n\\section{Time dependent perturbation theory}\nTo study the structure of molecular and atomic systems, we need to know how electromagnetic radiation interacts with these systems. Molecular and atomic spectroscopy deals in essence with the absorption and emission of electromagnetic radiation by molecules and atoms. As a system absorbs or emits radiation, it undergoes transitions from one state to another.\\\\\nTime-dependent perturbation theory is most useful for studying processes of absorption and emission of radiation by atoms or, more generally, for treating the transitions of quantum systems from one energy level to another.\\\\\\\\\n\\par Time evolution problem uses pertubration method to find the solution. If the hamiltonian is time dependent we can write, the totl H\n$$H=H_0+H^\\prime$$\nWhere $H_0$ is time independent unperturbed term. It constitutes major part of $H$.\nIts eigen values and ortho normalized eigen function are known.\n$$\\therefore H_0u_n=E_n u_n\\quad \\int u_m u_n d\\tau=\\delta_{mn}$$\nSince it is a time evolution problem we use time dependent schoodinger equation \\\\\nSo,\n$$H\\psi=E\\psi$$\n$$H=H_0+H^\\prime\\quad E=-i\\hbar\\frac{ d}{dt}$$\n\n$$\\therefore\\frac{i\\hbar d \\psi}{dt}=H_0\\psi+H^\\prime\\psi$$\nWhich has the solution of the form.\n$$\\psi(x,t)=\\sum_{n}a_n(t)u_n(x)e^{\\frac{-i}{\\hbar }E_nt}$$\nWhere $|a_n(t)|^2$ is the probability with which the system described by $\\psi(x,t)$ in an energy eigen state $u_n(x)$\\\\\\\\\non substituting the the value of $\\psi(x,t)$ in schrodinger equation \n$$\\implies\\sum_{n}(i\\hbar \\dot{a}_n(t)+E_na_n)u_n e^{\\frac{-i}{\\hbar} E_nt}=\\sum_{n}(H_0u_n+H^\\prime u_n)a_ne^{\\frac{-i}{\\hbar}E_nt}$$\nSince $H_0u_n=E_nu_n$ the term get cancelled on both side\\\\\n$$\\sum_{n}i\\hbar\\dot{a}_nu_ne^{\\frac{-i}{\\hbar}E_nt}=\\sum_{n}H^\\prime u_n a_n e^{\\frac{-i}{\\hbar}E_nt}$$\nMultiplying with $u_f^*$ and integrating\\\\\n$$ \\int i\\hbar \\sum_{n} \\dot{a}_n u_n u_f^* e^{\\frac{-i}{\\hbar}E_nt}d\\tau=\\sum_{n}\\int u_f^*H^\\prime u_na_ne^{\\frac{-i}{\\hbar}E_nt}d\\tau$$\n$$ i\\hbar{\\dot{a}}_f e^{\\frac{-i}{\\hbar}E_ft}=\\sum_{n}a_n {H\\prime} _{fn} e^{\\frac{-i}{\\hbar}E_nt}\\hspace{2cm}\n\\int u_f^* u_n d\\tau=\\delta_{fn}$$\n$$ \\dot{a}_f =(i\\hbar)^{-1}\\sum a_n H^\\prime_{fn}e^{\\frac{-i}{\\hbar}[E_f-E_n]t}\\hspace{2cm}\\int u_f^* H^\\prime u_n d\\tau=H^\\prime_{fn}$$\n$$\\therefore \\dot{a}_f=(i\\hbar)^{-1}\\sum_n a_n H^\\prime_{fn}e^{i\\omega_{fn}t}\\hspace{2cm}E_f-E_n=\\omega_{fn}\\hbar\n$$\nSince $H^\\prime$ are small $a_f$ can be expanded as \\\\\n$$a_f(t)=a_f^0+a_f^1+a_f^2+....$$\nOn substituting this in $\\dot{a}_f$ and equating terms of the same order on both sides,we get\n$$\\dot{a}_f^{(0)}=0\\quad \\dot{a}_f^{(r+1)}(t)=(l\\hbar)^{-1}\\sum_n\na_n^{(r)}H_{fn}^\\prime e^{i\\omega_{fn}t}$$\nBy substituting the initial condition $r=0$ we get\n$$\\dot{a}_f^{(1)}=(i\\hbar)^{-1}H^{\\prime}_{fi}e^{i\\omega_{fn}t}$$\n$$\\therefore a_f^{(1)}(t)=(ih)^{-1}\\int_{0}^{t}H^\\prime_{fl}(t^\\prime)e^{i\\omega_{fi}t^{\\prime}}dt^\\prime$$\nIn many cases\\\\\n$$H^\\prime _{fi}(t)=H_{fi}^{\\prime 0}f(t)$$\nWhere $H^{\\prime 0}$ is time independent\\\\\n$$\\therefore a_f^{(1)}(t)=(i\\hbar)^{-1}H^{10}_{fi}\\int_{0}^{t}f(t^\\prime)e^{i\\omega_{fi}t^{\\prime}}dt^\\prime$$\n\\subsection{First order transition: constant perturbation }\nProbability of transition from $i $ to all states $f\\neq i$ is much less than unit\n$$ \\sum^\\prime|a^\\prime_f(t)|^2<<1$$\n\\textbf{(a)\\quad Transition Probability }\\\\\nWe now consider the specific case of a perturbation $H^\\prime$ which lasts from time $0  $ to $t$ and is constant during this period.\\\\\n$$\\therefore a_f(t)=(ih)^{-1}\\int H^\\prime _{fi}e^{i\\omega_{fi}t}dt $$ \n$\\therefore H^\\prime_{fi}$ is constant\\\\\n$$a_f(t)=(i\\hbar)^{-1}H^\\prime_{fi}\\int e^{i\\omega_{fi}t}dt$$\n$$=(i\\hbar)^{-1}H^\\prime_{fi}\\frac{e^{i\\omega_{fi}t}-1}{i\\omega_{fi}}=-H^\\prime_{fi}\\frac{e^{i\\omega_{fi}t}-1}{\\hbar\\omega_{fi}}$$\n$$|a_f(t)|^2=\\frac{|H_{fi}|^2}{\\hbar^2}\\frac{4\\sin^2\\frac{1}{2}\\omega_{fi}t}{\\omega_{fi}^2}$$\n\nTrnsition probability from $i$ to $f$ deosnot change monotonically with time but varies simple harmonically from zero to maximum ($=\\frac{4|H^\\prime_{fi}|^2}{\\hbar^2\\omega_{fi}^2}$) with frequency equal to Bohr frequency $\\frac{\\omega_{fi}}{2\\pi}$. When smaller the energy difference $E_f-E_i=\\hbar\\omega_{fi}$ Between the pairs larger the maximum value of probability.\\\\\nThe behaviour of the factor $\\frac{4}{(\\omega_{fi})^2}\\sin^2\\frac{1}{2}\\omega_{fi}t$ is drawn.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm,width=8.5cm]{Q-1}\n\\end{figure}\nThe main peak of the curve occurs at $\\omega_{fi}=0$ is of height $t^2$\\\\\n$\\therefore$ We see that the transition from $i$ take place with appreciable probability only to those level $f$ such that $\\omega_{fi}$ falls under the main peak: $|\\omega_{fi}|\\leq \\frac{2\\pi}{t}$.In other words the magnitude of the energy difference\n$|\\hbar\\omega_{fi}|$ between the initial and final states is very unlikely to be significally higher than $\\hbar(\\frac{2\\pi}{t})=\\frac{h}{t}$.This result is  generally considered as an expression of an energy time uncertainity relation .\\\\\n$$\\hbar\\omega_{fi}\\leq\\frac{\\hbar2\\pi}{\\tau}\\quad\\hbar=\\frac{\\hbar}{2\\pi}$$\n$$\\Delta E\\leq \\frac{\\hbar}{\\Delta t}\\quad \\Delta E\\Delta t\\approx h$$\nEnergy time uncertainity relation\\\\\n\\textbf{(b)\\quad Closely Packed Levels}\\\\\nSuppose there are many $f$ levels within the energy level $\\Delta E$ Covered by the main peak, then,\\\\\n$$\\sum_{f}|a_f(t)|^2=\\frac{H_{fi}}{\\hbar^2}\\sum_{f}\\frac{4\\sin^2 \\frac{1}{2}\\omega_{fi}t}{\\omega^2_{fi}}$$\nSummation is over $f$\\\\\nIf spacing are very close summation can be changed in to integration such as,\n$$\\sum_{f}.....\\implies \\int(E_f)dE_f\\rightarrow\\rho(E_f)\\int dE_f$$\nWhere $\\rho(E_f)$ is the density of states that is the number of state around the energy. \nNumber of state with energy with in $d(E_f)=d_{nf}=\\rho(E_f)dE_f \\rho(f)$ is constant.\n$$\\therefore \\sum_{f}|a^{(1)}_f(t)|^2=\\frac{|H_{fi}|^2}{\\hbar^2}\\rho(E_f)\\int\\frac{4\\sin^2\\frac{1}{2}\\omega_{fi}t}{(\\omega_{fi})^2}dE_f$$\n$$\\hbar\\omega_{fi}=E_f-E_i$$\n$$\\hbar d\\omega_{fi}=dE_f$$\n$$ d\\omega_{fi}=\\frac{dE_f}{\\hbar}$$\n$$\\therefore\\sum_{f}|a^{1}_f(t)|^2=\\frac{|H_{fi}|^2}{\\hbar^2}\\rho(E_f)\\int\\frac{4\\sin^2\\frac{1}{2}\\omega_{fi}t}{(\\omega_{fi})^2}d\\omega_{fi}$$\n$$\\text{Since} \\quad 2t\\int_{-\\infty}^{\\infty}x^{-2}\\sin^2xdx=2\\pi t$$\n$$\\sum_{f}|a^{1}_f(t)|^2=\\frac{2\\pi}{\\hbar}t|H_{fi}|^2\\rho(E_f)$$\n$\\therefore$ Transition probability /unit time\n$$\\frac{1}{t}\\sum_{f}a^{(1)}_f(t)|^2=\\frac{2\\pi}{\\hbar}t|H_{fi}|^2\\rho(E_f)$$\nThis formula is called \\textcolor{red}{'Fermi Golden rule'}\n\\subsection{Harmonic Perturbation}\n\\textbf{(a)Amplitude for transition with change of energy}\\\\\nWe shall now consider a harmonic perturbation .\nconsider a perturbation of the type\n\\begin{align*}\nH^\\prime&=H^{\\prime o}e^{-i\\omega t} (\\omega>0) \\quad \\quad  H^\\prime=H^{\\prime o}f(t)\n\\end{align*}\nsupposed to act during the time interval (o,t),Then\n\\begin{align*}\na^{\\prime}_f (t)&=(i\\hbar)^{-1}H^{\\prime o}_{fi}\\int f(t)e^{i\\omega_{fi} t}  dt \\quad \\quad  f(t)=e^{-i\\omega t}\\\\\n\\intertext{The first order transition amplitude is}\na_f(t)& =-H^{\\prime o}_{fi}\\ \\frac{e^{l(\\omega_{fi}-\\omega)t}-1}{(\\omega_{fi}-\\omega)\\hbar}\n\\end{align*}\nFor large $t$ only those transitions with $\\omega_{fi}-\\omega=0$ or $E_f-E_i=\\hbar \\omega$  are possible with appreciable probability.\\\\\nThis means that perturbation can induce transition from $E_i$ to the level $E_f$ whose energy is higher than $E_i$ by $\\hbar \\omega$\nSuch a transition may be described as absorption of energy $\\hbar \\omega$ by the system from the purturbing agency\\\\\nFor the hermitian congugate of $H^\\prime$\\\\\n$$ H^{1\\dagger}=(H^{\\prime o})^\\dagger e^{i\\omega t}$$\nWhich makes the charges in transition amplitude for the factor $(H^{\\prime o}_{fi})^\\dagger=(H^{\\prime o}_{if})$ as the over all factor and it induce the transition.\n$$\\omega_{fi}+\\omega=0\\quad \\text{or }E_f-E_i=-\\hbar\\omega $$\nIn this case $E_f$ is lower and that is energy $\\hbar\\omega$ is given away by the system to the purturbing agency. ie emission.\\\\\nThe actual perturbation can be written as \n$$ H^\\prime=H^{\\prime o}e^{-i \\omega t}+(H^{\\prime o})^\\dagger e^{+\\omega t}$$\n\\textbf{(b) Transition induced by incoherent spectrum of perturbing frequencies}\\\\\nAs long as the perturbation contains only single frequency ,the transition probability oscillates with time as ($\\omega_{fi}\\mp\\omega$) instead of $\\omega_{fi}$.\\\\\nHowever the transition probability preportional to time can arise under the following conditions\\\\\n(i)The perturbation involves a whole spectrum of frequencies $\\omega$ which are so closely spaced that very many such frequencies are contained with in the intervel (1/t).\\\\\n(ii)These are incoherent in the sense that the phase of the different frequency componets are unrelated to each other.\\\\\n(iii)The magnitude of these perturbations and the spacing of the frequencies are smooth function of $\\omega$.\\\\\\\\\nConsider the second situation of incoherent frequency.To determine the total transition probability induced by the whole spectrum of frequencies one simply add up the probabilities arising from the different frequency components.Condition (i) then enables this sum to be replaced by an integral.Thus the total transition probability will be \n\\begin{align*}\n\\sum_{\\omega} |a_f(t,\\omega)|^2 &= \\sum_{\\omega}  \\frac{|H^{\\prime o}_{fi}(\\omega)|^2}{\\hbar^2}\\ \\frac{4 \\sin^2\\frac{1}{2}(\\omega_{fi}+\\omega)t}{(\\omega_{fi}-\\omega)^2}\\\\\n&=\\int \\frac{|H^{\\prime o}_{fi}(\\omega)|^2}{\\hbar^2}\\frac{4 \\sin^2\\frac{1}{2}(\\omega_{fi}+\\omega)t}{(\\omega_{fi}-\\omega)^2}\\rho (\\omega)\\ d\\omega\n\\end{align*}\n$|H_{fi}(\\omega)|^2$ and $\\rho(\\omega)$ Varies smothly with $\\omega$ and almost constant in the intervel $\\frac{1}{t}$ around $\\omega=\\omega_{fi}$ both can be taken out integral and after integrating we get,\\\\\nTransition probability per unit time\n$$  = \\frac{2\\pi}{\\hbar^2}|H^{\\prime o}_{fi}(\\omega_{fi})|^2 \\rho (\\omega_{fi})$$\nhere the total perturbration can be written as,\n$$H^\\prime = H^{\\prime o}(\\omega)e^{-i\\omega t}+ H^{\\prime o}(-\\omega)e^{i\\omega t}$$\nwith $H^{\\prime o}(-\\omega)=[H^{\\prime o}(\\omega)]^\\dagger$ to ensure hermiticity.\nIn order to consider the both term the summation should be done for $+\\omega$ and $-\\omega$ with\n$$ H^{\\prime o}_{fi}(\\omega)=H^{\\prime o}_{if}(\\omega),\\rho(\\omega)=\\rho(-\\omega)$$\n$\\therefore$ for upward transition $E_f>E_n$ from $i$ to $f$ and downward transition from $f$ to $i$ $E_f<E_n$\nprobability/unit time is \n$$ =\\frac{2\\pi}{\\hbar^2}|H^{\\prime_0}_{fi}(\\omega_{fi})|^2 \\rho(\\omega_{fi})\\text{ and } \\frac{2\\pi}{\\hbar^2}|H^{\\prime_0}_{fi}(-\\omega_{fi})|^2\\rho(-\\omega_{fi})$$\nSince $$\\omega_{mn}=-\\omega_{nm}$$\nThese two probability/unit time are equal.\\\\\n$\\therefore$ Probabilities for upward and downward transition between a given pair of levels induced by hermition pertubration are identical.\n\n\n\n\n\n\n\n\\section{Pictures of quantum mechanics}\nEach class of representation also called a picture differs from others in the way it treats the time evolution of the system.Schrodinger picture is useful when describing phenomena with time independent Hamiltonians,whereas the interaction and heisenberg pictures are useful when describing phenomena with time dependent Hamiltonians.\n\\subsection{The Schrodinger picture}\nIn describing quantum dynamics, we have been using so far the Schrödinger picture in which state vectors depend explicitly on time, but operators do not:\n$$\ni \\hbar \\frac{d}{d t}|\\psi(t)\\rangle=\\hat{H}|\\psi(t)\\rangle,\n$$\nwhere $|\\psi(t)\\rangle$ denotes the state of the system in the Schrödinger picture.The  time evolution of a state $|\\psi(t)\\rangle$ can be expressed by means of the propagator, or time-evolution operator, $\\hat{U}\\left(t, t_{0}\\right)$, as follows:\n$$\n|\\psi(t)\\rangle=\\hat{U}\\left(t, t_{0}\\right)\\left|\\psi\\left(t_{0}\\right)\\right\\rangle,\n$$\nwith\n$$\n\\hat{U}\\left(t, t_{0}\\right)=e^{-i\\left(t-t_{0}\\right) \\hat{H} / \\hbar}\n$$\nThe operator $\\hat{U}\\left(t, t_{0}\\right)$ is unitary,\n$$\n\\hat{U}^{\\dagger}\\left(t, t_{0}\\right) \\hat{U}\\left(t, t_{0}\\right)=I\n$$\nand satisfies these properties:\n$$\n\\begin{gathered}\n\\hat{U}(t, t)=I \\\\\n\\hat{U}^{\\dagger}\\left(t, t_{0}\\right)=\\hat{U}^{-1}\\left(t, t_{0}\\right)=\\hat{U}\\left(t_{0}, t\\right) \\\\\n\\hat{U}\\left(t_{1}, t_{2}\\right) \\hat{U}\\left(t_{2}, t_{3}\\right)=\\hat{U}\\left(t_{1}, t_{3}\\right)\n\\end{gathered}\n$$\n\\subsection{The Heisenberg Picture}\nIn this picture the time dependence of the state vectors is completely frozen. The Heisenberg picture is obtained from the Schrödinger picture by applying $\\hat{U}$ on $|\\psi(t)\\rangle_{H}$ :\n$$\n|\\psi(t)\\rangle_{H}=\\hat{U}^{\\dagger}(t)|\\psi(t)\\rangle=|\\psi(0)\\rangle,\n$$\nwhere $|\\psi(t)\\rangle$ and $\\hat{U}^{\\dagger}(t)$ can be obtained from scrodinger picture by setting $t_{0}=0$ : $\\hat{U}^{\\dagger}(t)=\\hat{U}^{\\dagger}\\left(t, t_{0}=0\\right)=e^{i t \\hat{H} / \\hbar}$ and $|\\psi(t)\\rangle=\\hat{U}(t)|\\psi(0)\\rangle$, with $\\hat{U}(t)=e^{-i t \\hat{H} / \\hbar}$. Thus, we can rewrite \\\\\n$$\\psi(t)\\rangle_{H}=e^{i t \\hat{H} / \\hbar}|\\psi(t)\\rangle$$\nAs $|\\psi\\rangle_{H}$ is frozen in time we have: $d|\\psi\\rangle_{H} / d t=0$. Let us see how the expectation value of an operator $\\hat{A}$ in the state $|\\psi(t)\\rangle$ evolves in time:\n$$\n\\left.\\langle\\psi(t)|\\hat{A}| \\psi(t)\\rangle=\\left\\langle\\psi(0)\\left|e^{i t \\hat{H} / \\hbar} \\hat{A} e^{-i t \\hat{H} / \\hbar}\\right| \\psi(0)\\right\\rangle=\\left\\langle\\psi(0)\\left|\\hat{A}_{H}(t)\\right| \\psi(0)\\right\\rangle=H\\left\\langle\\psi\\left|\\hat{A}_{H}(t)\\right| \\psi\\right\\rangle\\right\\rangle_{H},\n$$\nwhere $\\hat{A}_{H}(t)$ is given by\\\\\n$$\\hat{A}_{H}(t)=\\hat{U}^{\\dagger}(t) \\hat{A} \\hat{U}(t)=e^{i t \\hat{H} / \\hbar} \\hat{A} e^{-i t \\hat{H} / \\hbar}$$\nSchrödinger and the Heisenberg pictures coincide at $t=0,5$ \\\\\n\\textbf{Heisenberg equation of motion}\\\\\n$$\\frac{d\\hat{A}_H}{dt}=\\frac{1}{i\\hbar}\\left[\\hat{A}_H,\\hat{H}\\right] $$ \n\\subsection{The interaction picture}\nThe interaction picture, also called the Dirac picture, is useful to describe quantum phenomena with Hamiltonians that depend explicitly on time. In this picture both state vectors and operators evolve in time. We need, therefore, to find the equation of motion for the state vectors and for the operators.\\\\\n\\textbf{Equation of motion of state vectors}\\\\\nState vectors in the interaction picture are defined in terms of the Schrödinger states | $\\psi(t)\\}$ by\n$$\n|\\psi(t)\\rangle_{I}=e^{i t \\hat{H}_{0} / \\hbar}|\\psi(t)\\rangle .\n$$\nIf $t=0$ we have $|\\psi(0)\\rangle_{I}=|\\psi(0)\\rangle$. The time evolution of $|\\psi(t)\\rangle$ is governed by the Schrödinger equation $(10.1)$ with $\\hat{H}=\\hat{H}_{0}+\\hat{V}$ where $\\hat{H}_{0}$ is time independent, but $\\hat{V}$ may depend on time.\nTo find the time evolution of $|\\psi(t)\\rangle_{I}$, we need the time derivative \n$$\n\\begin{aligned}\ni \\hbar \\frac{d|\\psi(t)\\rangle_{I}}{d t} &=-\\hat{H}_{0} e^{i t \\hat{H}_{0} / \\hbar}|\\psi(t)\\rangle+e^{i t \\hat{H}_{0} / \\hbar}\\left(i \\hbar \\frac{d|\\psi(t)\\rangle}{d t}\\right) \\\\\n&=-\\hat{H}_{0}|\\psi(t)\\rangle_{I}+e^{i t \\hat{H}_{0} / \\hbar} \\hat{H}|\\psi(t)\\rangle\n\\end{aligned}\n$$\n$\\text { Since } \\hat{H}=\\hat{H}_{0}+\\hat{V} \\text { and }$\n$$\\begin{gathered}\ne^{i H_{0} t / \\hbar} \\hat{V}=\\left(e^{i t \\hat{H}_{0} / \\hbar} \\hat{V} e^{-i t \\hat{H}_{0} / \\hbar}\\right) e^{i t \\hat{H}_{0} / \\hbar}=\\hat{V}_{I}(t) e^{i t \\hat{H}_{0} / \\hbar}, \\\\\n\\hat{V}_{I}(t)=e^{i t \\hat{H}_{0} / \\hbar} \\hat{V} e^{-i t \\hat{H}_{0} / \\hbar},\n\\end{gathered}$$\nwe can rewrite\\\\\n$$\\begin{gathered}\ni \\hbar \\frac{d|\\psi(t)\\rangle_{I}}{d t}=-\\hat{H}_{0}|\\psi(t)\\rangle_{I}+\\hat{H}_{0} e^{i t \\hat{H}_{0} / \\hbar}|\\psi(t)\\rangle+\\hat{V}_{I}(t) e^{i t \\hat{H}_{0} / \\hbar}|\\psi(t)\\rangle, \\\\\ni \\hbar \\frac{d|\\psi(t)\\rangle_{I}}{d t}=\\hat{V}_{I}(t)|\\psi(t)\\rangle_{I} .\n\\end{gathered}$$\nThis is the Schrödinger equation in the interaction picture. It shows that the time evolution of the state vector is governed by the interaction $\\hat{V}_{I}(t)$.\\\\\n\\textbf{Equation of motion for the operators}\\\\\nThe interaction representation of an operator $\\hat{A}_{J}(t)$ is given, in terms of its Schrödinger representation by\n$$\n\\hat{A}_{I}(t)=e^{i \\hat{H}_{0} t / \\hbar} \\hat{A} e^{-i \\hat{H}_{0} t / \\hbar}\n$$\nCalculating the time derivative of $\\hat{A}_{I}(t)$ and since $\\partial \\hat{A} / \\partial t=0$, we can show the time evolution of $\\hat{A}_{I}(t)$ is governed by $\\hat{H}_{0}$ :\n$$\n\\frac{d \\hat{A}_{I}(t)}{d t}=\\frac{1}{i \\hbar}\\left[\\hat{A}_{I}(t), \\hat{H}_{0}\\right]\n$$\nThis equation is similar to the Heisenberg equation of motion except that $\\hat{H}$ is replaced by $\\hat{H}_{0}$. The basic difference between the Heisenberg and interaction pictures:In the Heisenberg picture it is $\\hat{H}$ that appears in the exponents,whereas in the interaction picture it is $\\hat{H}_0$ that appears.\\\\\n\\textbf{conclusion}\\\\\n we have seen that with in the schrodinger picture ,the states depends on time but not operators;In the Heisenberg picture only operators depends explicitly on time,state vectors are frozen in time.The interaction picture however is intermediate between the Schrodinger and the Heisenberg pictures ,since both state vectors and operators evolve with time.\\\\\n \\newpage\n \\begin{abox}\n \tPractice set 1\n \t\\end{abox}\n \\begin{enumerate}\n \\begin{minipage}{\\textwidth}\n \t\\item If the perturbation $H^{\\prime}=a x$, where $a$ is a constant, is added to the infinite square well potential\n \t$$\n \tV(x)=\\left\\{\\begin{array}{lll}\n \t0 & \\text { for } & 0 \\leq x \\leq \\pi \\\\\n \t\\infty & & \\text { otherwise }\n \t\\end{array}\\right.\n \t$$\n \tThe correction to the ground state energy, to first order in $a$, is\n \t\\exyear{NET JUNE 2011}\n \\end{minipage}\n \\begin{tasks}(2)\n \t\\task[\\textbf{A.}] $\\frac{a \\pi}{2}$\n \t\\task[\\textbf{B.}]$a \\pi$\n \t\\task[\\textbf{C.}]$\\frac{a \\pi}{4}$\n \t\\task[\\textbf{D.}]$\\frac{a \\pi}{\\sqrt{2}}$\n \\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle in one dimension moves under the influence of a potential $V(x)=a x^{6}$, where $a$ is a real constant. For large $n$ the quantized energy level $E_{n}$ depends on $n$ as:\n\t\\exyear{NET JUNE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $E_{n} \\sim n^{3}$\n\t\\task[\\textbf{B.}]$E_{n} \\sim n^{4 / 3}$\n\t\\task[\\textbf{C.}]$E_{n} \\sim n^{6 / 5}$\n\t\\task[\\textbf{D.}]$E_{n} \\sim n^{3 / 2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The perturbation $H^{\\prime}=b x^{4}$, where $b$ is a constant, is added to the one dimensional harmonic oscillator potential $V(x)=\\frac{1}{2} m \\omega^{2} x^{2}$. Which of the following denotes the correction to the ground state energy to first order in $b$ ?\n\tHint: The normalized ground state wave function of the one dimensional harmonic oscillator potential is $\\psi_{0}=\\left(\\frac{m \\omega}{\\hbar \\pi}\\right)^{1 / 4} e^{-m \\omega x^{2} / 2 \\hbar} .$ You may use the following integral $\\left.\\int_{-\\infty}^{\\infty} x^{2 n} e^{-a x^{2}} d x=a^{-n-\\frac{1}{2}} \\Gamma\\left(n+\\frac{1}{2}\\right)\\right]$\n\t\\exyear{NET DEC 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{3 b \\hbar^{2}}{4 m^{2} \\omega^{2}}$\n\t\\task[\\textbf{B.}]$\\frac{3 b \\hbar^{2}}{2 m^{2} \\omega^{2}}$\n\t\\task[\\textbf{C.}]$\\frac{3 b \\hbar^{2}}{2 \\pi m^{2} \\omega^{2}}$\n\t\\task[\\textbf{D.}]$\\frac{15 b \\hbar^{2}}{4 m^{2} \\omega^{2}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A constant perturbation as shown in the figure below acts on a particle of mass $m$ confined in an infinite potential well between 0 and $L$.\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210921(2)-crop(2)}\n\t\\end{figure}\n\t$\\text { The first-order correction to the ground state energy of the particle is }$\n\t\\exyear{NET DEC 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{V_{0}}{2}$\n\t\\task[\\textbf{B.}]$\\frac{3 V_{0}}{4}$\n\t\\task[\\textbf{C.}]$\\frac{V_{0}}{4}$\n\t\\task[\\textbf{D.}] $\\frac{3 V_{0}}{2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider a two-dimensional infinite square well\n\t$$\n\tV(x, y)=\\left\\{\\begin{array}{ll}\n\t0, & 0<x<a, \\\\\n\t\\infty, & \\text { otherwise }\n\t\\end{array} \\quad 0<y<a\\right.\n\t$$\n\tIts normalized Eigenfunctions are $\\psi_{n_{x}, n_{y}}(x, y)=\\frac{2}{a} \\sin \\left(\\frac{n_{x} \\pi x}{a}\\right) \\sin \\left(\\frac{n_{y} \\pi y}{a}\\right)$,\n\twhere $n_{x}, n_{y}=1,2,3, . .$\\\\\n\tIf a perturbation $H^{\\prime}=\\left\\{\\begin{array}{cc}V_{0} & 0<x<\\frac{a}{2}, \\quad 0<y<\\frac{a}{2} \\\\ 0 & \\text { otherwise }\\end{array}\\right.$ \\\\is applied, then the correction to the\n\tenergy of the first excited state to order $V_{0}$ is\n\t\\exyear{NET JUNE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{V_{0}}{4}$\n\t\\task[\\textbf{B.}]$\\frac{V_{0}}{4}\\left[1 \\pm \\frac{64}{9 \\pi^{2}}\\right]$\n\t\\task[\\textbf{C.}]$\\frac{V_{0}}{4}\\left[1 \\pm \\frac{16}{9 \\pi^{2}}\\right]$\n\t\\task[\\textbf{D.}]$\\frac{V_{0}}{4}\\left[1 \\pm \\frac{32}{9 \\pi^{2}}\\right]$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Two identical bosons of mass $m$ are placed in a one-dimensional potential $V(x)=\\frac{1}{2} m \\omega^{2} x^{2} .$ The bosons interact via a weak potential,\n\t$$\n\tV_{12}=V_{0} \\exp \\left[-m \\Omega\\left(x_{1}-x_{2}\\right)^{2} / 4 \\hbar\\right]\n\t$$\n\twhere $x_{1}$ and $x_{2}$ denote coordinates of the particles. Given that the ground state wavefunction of the harmonic oscillator is $\\psi_{0}(x)=\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{\\frac{1}{4}} e^{-\\frac{m \\omega x^{2}}{2 \\hbar}} .$ The ground state energy of the two-boson system, to the first order in $V_{0}$, is\n\t\\exyear{NET JUNE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\hbar \\omega+2 V_{0}$\n\t\\task[\\textbf{B.}]$\\hbar \\omega+\\frac{V_{0} \\Omega}{\\omega}$\n\t\\task[\\textbf{C.}]$\\hbar \\omega+V_{0}\\left(1+\\frac{\\Omega}{2 \\omega}\\right)^{-\\frac{1}{2}}$\n\t\\task[\\textbf{D.}]$\\hbar \\omega+V_{0}\\left(1+\\frac{\\omega}{\\Omega}\\right)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The bound on the ground state energy of the Hamiltonian with an attractive deltafunction potential, namely\n\t$$\n\tH=-\\frac{\\hbar^{2}}{2 m} \\frac{d^{2}}{d x^{2}}-a \\delta(x)\n\t$$\n\tusing the variational principle with the trial wavefunction $\\psi(x)=A \\exp \\left(-b x^{2}\\right)$ is\\\\\n\t$\\left[\\text { Note }: \\int_{0}^{\\infty} e^{-t} t^{a} d t=\\Gamma(a+1)\\right]$\n\t\\exyear{NET JUNE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-m a^{2} / 4 \\pi \\hbar^{2}$\n\t\\task[\\textbf{B.}]$-m a^{2} / 2 \\pi \\hbar^{2}$\n\t\\task[\\textbf{C.}]$-m a^{2} / \\pi \\hbar^{2}$\n\t\\task[\\textbf{D.}]$-m a^{2} / \\sqrt{5} \\pi \\hbar^{2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The ground state eigenfunction for the potential $V(x)=-\\delta(x)$ where $\\delta(x)$ is the delta function, is given by $\\psi(x)=A e^{-\\alpha|x|}$, where $A$ and $\\alpha>0$ are constants. If a perturbation $H^{\\prime}=b x^{2}$ is applied, the first order correction to the energy of the ground state will be\n\t\\exyear{NET JUNE 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{b}{\\sqrt{2} \\alpha^{2}}$ \n\t\\task[\\textbf{B.}]$\\frac{b}{\\alpha^{2}}$\n\t\\task[\\textbf{C.}]$\\frac{2 b}{\\alpha^{2}}$\n\t\\task[\\textbf{D.}]$\\frac{b}{2 \\alpha^{2}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The ground state energy of the attractive delta function potential\n\t$$\n\tV(x)=-b \\delta(x) \\text {, }\n\t$$\n\twhere $b>0$, is calculated with the variational trial function\n\t$$\n\t\\psi(x)=\\left\\{\\begin{array}{ccc}\n\tA \\cos \\frac{\\pi x}{2 a}, & \\text { for } & -a<x<a, \\\\\n\t0, & & \\text { otherwise, }\n\t\\end{array}\\right\\} \\text { is }\n\t$$\n\t\\exyear{NET DEC 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-\\frac{m b^{2}}{\\pi^{2} \\hbar^{2}}$\n\t\\task[\\textbf{B.}]$-\\frac{2 m b^{2}}{\\pi^{2} \\hbar^{2}}$\n\t\\task[\\textbf{C.}]$-\\frac{m b^{2}}{2 \\pi^{2} \\hbar^{2}}$\n\t\\task[\\textbf{D.}]$-\\frac{m b^{2}}{4 \\pi^{2} \\hbar^{2}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider a particle of mass $m$ in the potential $V(x)=a|x|, a>0$. The energy eigenvalues $E_{n}(n=0,1,2, \\ldots .)$, in the WKB approximation, are\n\t\\exyear{NET DEC 2014 }\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\left[\\frac{3 a \\hbar \\pi}{4 \\sqrt{2 m}}\\left(n+\\frac{1}{2}\\right)\\right]^{1 / 3}$\n\t\\task[\\textbf{B.}]$\\left[\\frac{3 a \\hbar \\pi}{4 \\sqrt{2 m}}\\left(n+\\frac{1}{2}\\right)\\right]^{2 / 3}$\n\t\\task[\\textbf{C.}]$\\frac{3 a \\hbar \\pi}{4 \\sqrt{2 m}}\\left(n+\\frac{1}{2}\\right)$\n\t\\task[\\textbf{D.}]$\\left[\\frac{3 a \\hbar \\pi}{4 \\sqrt{2 m}}\\left(n+\\frac{1}{2}\\right)\\right]^{4 / 3}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The Hamiltonian $H_{0}$ for a three-state quantum system is given by the matrix $H_{0}=\\left(\\begin{array}{lll}1 & 0 & 0 \\\\ 0 & 2 & 0 \\\\ 0 & 0 & 2\\end{array}\\right) .$ When perturbed by $H^{\\prime}=\\in\\left(\\begin{array}{lll}0 & 1 & 0 \\\\ 1 & 0 & 1 \\\\ 0 & 1 & 0\\end{array}\\right)$ where $\\in<<1$, the resulting shift in the energy eigenvalue $E_{0}=2$ is\n\t\\exyear{NET DEC 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\in,-2 \\in$\n\t\\task[\\textbf{B.}] $-\\in, 2 \\in$\n\t\\task[\\textbf{C.}]$\\pm \\in$\n\t\\task[\\textbf{D.}]$\\pm 2 \\in$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle of mass $m$ is in a potential $V=\\frac{1}{2} m \\omega^{2} x^{2}$, where $\\omega$ is a constant. Let $\\hat{a}=\\sqrt{\\frac{m \\omega}{2 \\hbar}}\\left(\\hat{x}+\\frac{i \\hat{p}}{m \\omega}\\right) .$ In the Heisenberg picture $\\frac{d \\hat{a}}{d t}$ is given by\n\t\\exyear{NET JUNE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\omega \\hat{a}$\n\t\\task[\\textbf{B.}]$-i \\omega \\hat{a}$\n\t\\task[\\textbf{C.}]$\\omega \\hat{a}^{\\dagger}$\n\t\\task[\\textbf{D.}]$i \\omega \\hat{a}^{\\dagger}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A hydrogen atom is subjected to the perturbation\n\t$$\n\tV_{\\text {pert }}(r)=\\epsilon \\cos \\frac{2 r}{a_{0}}\n\t$$\n\twhere $a_{0}$ is the Bohr radius. The change in the ground state energy to first order in $\\in$\n\t\\exyear{NET DEC 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{\\in}{4}$\n\t\\task[\\textbf{B.}] $\\frac{\\in}{2}$\n\t\\task[\\textbf{C.}]$\\frac{-\\epsilon}{2}$\n\t\\task[\\textbf{D.}] $\\frac{-\\epsilon}{4}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider a particle of mass $m$ in a potential $V(x)=\\frac{1}{2} m \\omega^{2} x^{2}+g \\cos k x .$ The change in the ground state energy, compared to the simple harmonic potential $\\frac{1}{2} m \\omega^{2} x^{2}$, to first order in $g$ is\n\t\\exyear{NET JUNE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $g \\exp \\left(-\\frac{k^{2} \\hbar}{2 m \\omega}\\right)$\n\t\\task[\\textbf{B.}]$g \\exp \\left(\\frac{k^{2} \\hbar}{2 m \\omega}\\right)$\n\t\\task[\\textbf{C.}]$g \\exp \\left(-\\frac{2 k^{2} \\hbar}{m \\omega}\\right)$\n\t\\task[\\textbf{D.}] $g \\exp \\left(-\\frac{k^{2} \\hbar}{4 m \\omega}\\right)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The energy levels for a particle of mass $m$ in the potential $V(x)=\\alpha|x|$, determined in the $W K B$ approximation\n\t$$\n\t\\sqrt{2 m} \\int_{a}^{b} \\sqrt{E-V(x)} d x=\\left(n+\\frac{1}{2}\\right) \\hbar \\pi\n\t$$\n\t(where $a, b$ are the turning points and $n=0,1,2 \\ldots$ ), are\n\t\\exyear{NET JUNE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $E_{n}=\\left[\\frac{h \\pi \\alpha}{4 \\sqrt{m}}\\left(n+\\frac{1}{2}\\right)\\right]^{\\frac{2}{3}}$\n\t\\task[\\textbf{B.}]$E_{n}=\\left[\\frac{3 h \\pi \\alpha}{4 \\sqrt{2 m}}\\left(n+\\frac{1}{2}\\right)\\right]^{\\frac{2}{3}}$\n\t\\task[\\textbf{C.}]$E_{n}=\\left[\\frac{3 h \\pi \\alpha}{4 \\sqrt{m}}\\left(n+\\frac{1}{2}\\right)\\right]^{\\frac{2}{3}}$\n\t\\task[\\textbf{D.}] $E_{n}=\\left[\\frac{h \\pi \\alpha}{4 \\sqrt{2 m}}\\left(n+\\frac{1}{2}\\right)\\right]^{\\frac{2}{3}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle of charge $q$ in one dimension is in a simple harmonic potential with angular frequency $\\omega$. It is subjected to a time- dependent electric field $E(t)=A e^{-\\left(\\frac{t}{\\tau}\\right)^{2}}$, where $A$ and $\\tau$ are positive constants and $\\omega \\tau \\gg 1$. If in the distant past $t \\rightarrow-\\infty$ the particle was in its ground state, the probability that it will be in the first excited state as $t \\rightarrow+\\infty$ is proportional to\n\t\\exyear{NET DEC 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $e^{-\\frac{1}{2}(\\omega \\tau)^{2}}$\n\t\\task[\\textbf{B.}]$e^{\\frac{1}{2}(\\omega \\tau)^{2}}$\n\t\\task[\\textbf{C.}] 0\n\t\\task[\\textbf{D.}]$\\frac{1}{(\\omega \\tau)^{2}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A constant perturbation $H^{\\prime}$ is applied to a system for time $\\Delta t$ (where $H^{\\prime} \\Delta t<<\\hbar$ ) leading to a transition from a state with energy $E_{i}$ to another with energy $E_{f}$. If the time of application is doubled, the probability of transition will be\n\t\\exyear{NET JUNE 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] unchanged\n\t\\task[\\textbf{B.}]doubled\n\t\\task[\\textbf{C.}]quadrupled\n\t\\task[\\textbf{D.}]halved\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The Coulomb potential $V(r)=-e^{2} / r$ of a hydrogen atom is perturbed by adding $H^{\\prime}=b x^{2}$ (where $b$ is a constant) to the Hamiltonian. The first order correction to the ground state energy is\n\t(The ground state wavefunction is $\\psi_{0}=\\frac{1}{\\sqrt{\\pi a_{0}^{3}}} e^{-r / a_{0}}$ )\n\t\\exyear{NET JUNE 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $2 b a_{0}^{2}$\n\t\\task[\\textbf{B.}]$b a_{0}^{2}$\n\t\\task[\\textbf{C.}]$b a_{0}^{2} / 2$\n\t\\task[\\textbf{D.}]$\\sqrt{2} b a_{0}^{2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider a one-dimensional infinite square well\n\t$$\n\tV(x)=\\left\\{\\begin{array}{lll}\n\t0 & \\text { for } & 0<x<a \\\\\n\t\\infty & & \\text { otherwise }\n\t\\end{array}\\right.\n\t$$\n\tIf a perturbation\n\t$$\n\t\\Delta V(x)=\\left\\{\\begin{array}{lc}\n\tV_{0} & \\text { for } 0<x<a / 3 \\\\\n\t0 & \\text { otherwise }\n\t\\end{array}\\right.\n\t$$\n\tis applied, then the correction to the energy of the first excited state, to first order in $\\Delta V$, is nearest to\n\t\\exyear{NET DEC 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $V_{0}$\n\t\\task[\\textbf{B.}]$0.16 V_{0}$\n\t\\task[\\textbf{C.}]$0.2 V_{0}$\n\t\\task[\\textbf{D.}]$0.33 V_{0}$\n\\end{tasks}\n \\end{enumerate}\n \n \\colorlet{ocre1}{ocre!70!}\n \\colorlet{ocrel}{ocre!30!}\n \\setlength\\arrayrulewidth{1pt}\n \\begin{table}[H]\n \t\\centering\n \t\\arrayrulecolor{ocre}\n \t\n \t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n \t\t\\hline\n \t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n \t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n \t\t1&\\textbf{a}&2&\\textbf{d}\\\\\\hline\n \t\t3&\\textbf{a}&4&\\textbf{b}\\\\\\hline\n \t\t5&\\textbf{b}&6&\\textbf{c}\\\\\\hline\n \t\t7&\\textbf{c}&8&\\textbf{d}\\\\\\hline\n \t\t9&\\textbf{b}&10&\\textbf{b}\\\\\\hline\n \t\t11&\\textbf{none}&12&\\textbf{b}\\\\\\hline\n \t\t13&\\textbf{d}&14&\\textbf{d}\\\\\\hline\n \t\t15&\\textbf{b}&16&\\textbf{a}\\\\\\hline\n \t\t17&\\textbf{c}&18&\\textbf{b}\\\\\\hline\n \t\t19&\\textbf{d}&&\\\\\\hline\n \t\\end{tabular}\n \\end{table}\n\n\n\n\n  \\newpage\n  \\begin{abox}\n  \tPractice set 2\n  \t\\end{abox}\n  \\begin{enumerate}\n  \t\\begin{minipage}{\\textwidth}\n  \t\\item A particle of mass $m$ is confined in an infinite potential well:\n  \t$$\n  \tV(x)= \\begin{cases}0, & \\text { if } 0<x<L \\\\ \\infty, & \\text { otherwise. }\\end{cases}\n  \t$$\n  \tIt is subjected to a perturbing potential $V_{p}(x)=V_{o} \\sin \\left(\\frac{2 \\pi x}{L}\\right)$ within the well. Let $E^{(1)}$ and $E^{(2)}$ be corrections to the ground state energy in the first and second order in $V_{0}$, respectively. Which of the following are true?\n  \t\\exyear{GATE 2010}\n  \t\\begin{figure}[H]\n  \t\t\\centering\n  \t\t\\includegraphics[height=4cm,width=5cm]{gate 2010}\n  \t\\end{figure}\n  \\end{minipage}\n  \\begin{tasks}(2)\n  \t\\task[\\textbf{A.}]$E^{(1)}=0 ; E^{(2)}<0$\n  \t\\task[\\textbf{B.}]$E^{(1)}>0 ; E^{(2)}=0$\n  \t\\task[\\textbf{C.}]$E^{(1)}=0 ; E^{(2)}$ depends on the sign of $V_{0}$\n  \t\\task[\\textbf{D.}]$E^{(1)}<0 ; E^{(2)}<0$\n  \\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The normalized eigenstates of a particle in a one-dimensional potential well\n\t$$\n\tV(x)= \\begin{cases}0 & \\text { if } 0 \\leq x \\leq a \\\\ \\infty & \\text { otherwise }\\end{cases}\n\t$$\n\tare given by $\\psi_{n}(x)=\\sqrt{\\frac{2}{a}} \\sin \\left(\\frac{n \\pi x}{a}\\right)$, where $n=1,2,3, \\ldots . .$\n\tThe particle is subjected to a perturbation\n\t$$\n\tV^{\\prime}(x)= \\begin{cases}V_{0} \\cos \\left(\\frac{\\pi x}{a}\\right), & \\text { for } 0 \\leq x \\leq \\frac{a}{2} \\\\ 0, & \\text { otherwise }\\end{cases}\n\t$$\n\tThe shift in the ground state energy due to the perturbation, in the first order perturbation theory,\n\t\\exyear{GATE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{2 V_{o}}{3 \\pi}$\n\t\\task[\\textbf{B.}]$\\frac{V_{o}}{3 \\pi}$\n\t\\task[\\textbf{C.}]$-\\frac{V_{o}}{3 \\pi}$\n\t\\task[\\textbf{D.}]$-\\frac{2 V_{o}}{3 \\pi}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider a system in the unperturbed state described by the Hamiltonian, $H_{0}=\\left(\\begin{array}{ll}1 & 0 \\\\ 0 & 1\\end{array}\\right)$. The system is subjected to a perturbation of the form $H^{\\prime}=\\left(\\begin{array}{ll}\\delta & \\delta \\\\ \\delta & \\delta\\end{array}\\right)$, where $\\delta \\ll<1$. The energy eigenvalues of the perturbed system using the first order perturbation approximation are\n\t\\exyear{GATE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]1 and $(1+2 \\delta)$\n\t\\task[\\textbf{B.}]$(1+\\delta)$ and $(1-\\delta)$\n\t\\task[\\textbf{C.}]$(1+2 \\delta)$ and $(1-2 \\delta)$\n\t\\task[\\textbf{D.}]$(1+\\delta)$ and $(1-2 \\delta)$\n\\end{tasks}\n\\textbf{\\text { Common data questions } 4 \\text { and } 5}\\\\\n$\\begin{aligned}\n&\\text { To the given unperturbed Hamiltonian }\\left[\\begin{array}{ccc}\n5 & 2 & 0 \\\\\n2 & 5 & 0 \\\\\n0 & 0 & 2\n\\end{array}\\right] \\\\\n&\\text { we add a small perturbation given by } \\varepsilon\\left[\\begin{array}{ccc}\n1 & 1 & 1 \\\\\n1 & 1 & -1 \\\\\n1 & -1 & 1\n\\end{array}\\right] \\text { where } \\varepsilon \\text { is small quantity. }\n\\end{aligned}$\\\\\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { The ground state eigenvector of the unperturbed Hamiltonian is }$\n\t\\exyear{GATE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $(1 / \\sqrt{2}, 1 \\sqrt{2}, 0)$\n\t\\task[\\textbf{B.}]$(1 / \\sqrt{2},-1 / \\sqrt{2}, 0)$\n\t\\task[\\textbf{C.}] $(0,0,1)$\n\t\\task[\\textbf{D.}]$(1,0,0)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A pair of eigenvalues of the perturbed Hamiltonian, using first order perturbation theory, is\n\t\\exyear{GATE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]$3+2 \\varepsilon, 7+2 \\varepsilon$\n\t\\task[\\textbf{B.}]$3+2 \\varepsilon,+2+\\varepsilon$\n\t\\task[\\textbf{C.}]$3,7+2 \\varepsilon$\n\t\\task[\\textbf{D.}]$3,2+2 \\varepsilon$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle is confined to a one dimensional potential box, with the potential\n\t$$\n\tV(x)= \\begin{cases}0, & 0<x<a \\\\ \\infty, & \\text { otherwise }\\end{cases}\n\t$$\n\tIf particle is subjected to a perturbation within the box. $W=\\beta x$. Where $\\beta$ is small constant, the first order correction to the ground state energy is\n\t\\exyear{GATE 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] 0\n\t\\task[\\textbf{B.}]$a \\beta / 4$\n\t\\task[\\textbf{C.}]$a \\beta / 2$\n\t\\task[\\textbf{D.}] $a \\beta$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle is confined in a box of length $L$ as shown in the figure. If the potential $V_{0}$ is treated as a perturbation, including the first order correction, the ground state energy is\n\t\\exyear{GATE 2015}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=4cm]{diagram-20210824(7)-crop}\n\t\\end{figure}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $E=\\frac{\\hbar^{2} \\pi^{2}}{2 m L^{2}}+V_{0}$\n\t\\task[\\textbf{B.}]$E=\\frac{\\hbar^{2} \\pi^{2}}{2 m L^{2}}-\\frac{V_{0}}{2}$\n\t\\task[\\textbf{C.}] $E=\\frac{\\hbar^{2} \\pi^{2}}{2 m L^{2}}+\\frac{V_{0}}{4}$\n\t\\task[\\textbf{D.}]$E=\\frac{\\hbar^{2} \\pi^{2}}{2 m L^{2}}+\\frac{V_{0}}{2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A one dimensional simple harmonic oscillator with Hamiltonian $H_{0}=\\frac{p^{2}}{2 m}+\\frac{1}{2} k x^{2}$ is subjected to a small perturbation, $H_{1}=\\alpha x+\\beta x^{3}+\\gamma x^{4}$. The first order correction to the ground state energy is dependent on\n\t\\exyear{GATE 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] only $\\beta$\n\t\\task[\\textbf{B.}]$\\alpha$ and $\\gamma$\n\t\\task[\\textbf{C.}]$\\alpha$ and $\\beta$\n\t\\task[\\textbf{D.}]only $\\gamma$\n\\end{tasks}\n  \\end{enumerate}\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{a}&2&\\textbf{a}\\\\\\hline\n\t\t3&\\textbf{a}&4&\\textbf{c}\\\\\\hline\n\t\t5&\\textbf{c}&6&\\textbf{c}\\\\\\hline\n\t\t7&\\textbf{d}&8&\\textbf{d}\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\\newpage\n\\begin{abox}\n\tPractice set 3\n\t\\end{abox}\n \\begin{enumerate}\n \t\t\\begin{minipage}{\\textwidth}\n \t\t\\item A one dimensional infinite potential box is defined by, $V(x)=\\left\\{\\begin{array}{ll}0, & 0<x<a \\\\ \\infty, & \\text { otherwise }\\end{array}\\right.$. It is perturbed by potential $\\frac{\\alpha V_{0} x^{2}}{a^{2}}$, then find the first order energy correction in $n^{t h}$ state of the system.\n \t\\end{minipage}\n \t\\begin{answer}\n \t$$E_{n}^{1}=\\left\\langle\\phi_{n}|W| \\phi_{n}\\right\\rangle, \\text { where }\\left|\\phi_{n}\\right\\rangle=\\sqrt{\\frac{2}{a}} \\sin \\frac{n \\pi x}{a}$$\n \t\\begin{align*}\n \t\t&E_{n}^{1}=V_{0} \\frac{2}{a} \\int_{0}^{a} \\frac{x^{2}}{a^{2}} \\sin ^{2} \\frac{n \\pi x}{a} d x=V_{0} \\frac{1}{a} \\int_{0}^{a} \\frac{x^{2}}{a^{2}}\\left(1-\\cos \\frac{2 n \\pi x}{a}\\right) d x=V_{0}\\left(\\frac{1}{3}-\\frac{1}{2 n^{2} \\pi^{2}}\\right) \\\\\n \t\t&E_{n}=\\frac{n^{2} \\pi^{2}}{2 m a^{2}}+\\alpha V_{0}\\left(\\frac{1}{3}-\\frac{1}{2 n^{2} \\pi^{2}}\\right)\n \t\\end{align*}\t\n \t\\end{answer}\n \t\\begin{minipage}{\\textwidth}\n \t\\item A one dimensional infinite potential box is defined as, $V(x)= \\begin{cases}0, & -\\frac{L}{2}<x<\\frac{L}{2} . \\text { It } \\\\ \\infty, & \\text { otherwise }\\end{cases}$ is perturbed with potential $H_{p}=V_{0} \\exp \\left(-\\frac{x^{2}}{a^{2}}\\right) .$ Find the first order energy correction in ground state with momentum $\\frac{\\pi \\hbar}{L}$ by assuming $\\frac{a}{L}<<1$.\n \\end{minipage}\n \\begin{answer}\n  $\\left|\\phi_{1}\\right\\rangle=\\sqrt{\\frac{1}{L}} \\exp \\frac{i \\pi x}{L}, \\text { because momentum is } \\frac{\\pi \\hbar}{L}$\\\\\n  \\begin{align*}\n  \t&E_{1}^{1}=\\left\\langle\\phi_{1}|W| \\phi_{1}\\right\\rangle=\\frac{V_{0}}{L} \\int_{-L / 2}^{L / 2} \\exp \\left(-\\frac{x^{2}}{a^{2}}\\right) d x, \\text { if } \\frac{a}{L}<<1 \\text { then } \\\\\n  \t&E_{1}^{1}=\\frac{V_{0}}{L} \\int_{-\\infty}^{\\infty} \\exp \\left(-\\frac{x^{2}}{a^{2}}\\right) d x=\\frac{\\sqrt{\\pi} V_{0} a}{L} .\n  \\end{align*}\n \\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item A one dimensional infinite potential box is defined as, $V(x)= \\begin{cases}0, & -\\frac{a}{2}<x<\\frac{a}{2} . \\text { It is } \\\\ \\infty, & \\text { otherwise }\\end{cases}$ perturbed with potential $H_{p}=V_{0} a \\delta(x)$. Find the $E_{n}^{2}$.i.e., second order correction in ground state.\n\\end{minipage}\n\\begin{answer}\n\t$E_{n}^{2}=\\sum_{m \\neq n} \\frac{\\left|\\left\\langle\\phi_{m}|W| \\phi_{n}\\right\\rangle\\right|^{2}}{E_{n}-E_{m}}$\\\\\n\tIf $n$ is even, then $\\left\\langle\\phi_{m}|W| \\phi_{n}\\right\\rangle=0$\\\\\n\tIf $m$ is even, then $\\left\\langle\\phi_{m}|W| \\phi_{n}\\right\\rangle=0$\\\\\n\tIf $m$ and $n$ odd, then $\\left\\langle\\phi_{m}|W| \\phi_{n}\\right\\rangle=V_{0} a\\left(\\frac{2}{a}\\right)\\int_{-a / 2}^{a / 2} \\cos \\frac{m \\pi x}{a} \\cos \\frac{n \\pi x}{a} \\delta(x) d x=2 V_{0}$\n\t$$\n\tE_{n}^{2}=\\sum_{m \\neq n} \\frac{\\left|\\left\\langle\\phi_{m}|W| \\phi_{n}\\right\\rangle\\right|^{2}}{E_{n}-E_{m}}=\\sum_{m=1,3,5} \\frac{4 V_{0}^{2}}{\\left(n^{2}-m^{2}\\right) E_{0}}, \\text { where } E_{0}=\\frac{\\pi^{2} \\hbar^{2}}{2 m a^{2}}\n\t$$\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item A one dimensional harmonic oscillator with potential, $V(x)=\\frac{1}{2} m \\omega^{2} x^{2}$ is given, then\\\\\n\t(a) if H.O potential is perturbed with perturbation $H_{p}=\\lambda X^{4}$, then find the first order energy correction in $n^{\\text {th }}$ state of the system.\\\\\n\t(b) if H.O Perturbed with potential $V_{0} \\cosh \\alpha x$, then find the first order energy correction in ground state.\n\\end{minipage}\n\\begin{answer}\n(a)\t$E_{n}^{1}=\\left\\langle\\phi_{n}\\left|H_{p}\\right| \\phi_{n}\\right\\rangle=\\left\\langle\\phi_{n}\\left|\\lambda X^{4}\\right| \\phi_{n}\\right\\rangle$\\\\\n\t$=\\lambda\\left(\\frac{\\hbar}{2 m \\omega}\\right)^{2}\\left\\langle\\left(a+a^{\\dagger}\\right)^{4}\\right\\rangle=\\left(\\frac{\\hbar}{2 m \\omega}\\right)^{2}\\left[6 n^{2}+6 n+3\\right]$\\\\\n\t(b)$ E_{0}^{1}=\\left\\langle\\phi_{0}|W| \\phi_{0}\\right\\rangle, \\text { where }\\left|\\phi_{0}\\right\\rangle=\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{1 / 4} \\exp \\left(-\\frac{m \\omega x^{2}}{2 \\hbar}\\right) \\text {. }$\\\\\n\t\\begin{align*}\n\t\t&=\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{1 / 2} V_{0} \\int_{-\\infty}^{\\infty} \\exp \\left(-\\frac{m \\omega x^{2}}{\\hbar}\\right) \\cosh \\alpha x d x \\\\\n\t\t&=V_{0}\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{1 / 2} \\int_{-\\infty}^{\\infty} \\exp \\left(-\\frac{m \\omega x^{2}}{\\hbar}\\right) \\frac{\\left(e^{\\alpha x}+e^{-\\alpha x}\\right)}{2} d x \\\\\n\t\t&=\\frac{V_{0}}{2}\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{1 / 2}\\left(\\int_{-\\infty}^{\\infty} e^{-\\frac{m \\omega}{\\hbar}\\left(x-\\frac{\\hbar}{2 m \\omega}\\right)^{2}}\\left(e^{\\frac{\\hbar}{4 m \\omega}}\\right) d x+\\int_{-\\infty}^{\\infty} e^{-\\frac{m \\omega}{\\hbar}\\left(x+\\frac{\\hbar}{2 m \\omega}\\right)^{2}} \\cdot\\left(-e^{\\frac{\\hbar}{4 m \\omega}}\\right) d x\\right) \\\\\n\t\t&=\\frac{V_{0}}{2}\\left(\\exp \\frac{\\hbar}{4 m \\omega}+\\exp \\frac{\\hbar}{4 m \\omega}\\right)=V_{0} \\exp \\frac{\\hbar}{4 m \\omega}\n\t\\end{align*}\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item\n\tOne dimensional potential is given by, $V(x)=\\left\\{\\begin{array}{ll}\\infty, & x<0 \\\\ \\frac{1}{2} m \\omega^{2} x^{2}, & x \\geq 0\\end{array} .\\right.$ It is perturbed by potential\\\\\n\t(a) $H_{p}=\\lambda V_{0}$, then find the first order correction in energy for ground state .\\\\\n\t(b) $H_{p}=\\lambda V_{0} \\delta\\left(x-\\sqrt{\\frac{\\hbar}{m \\omega}}\\right)$, find the first order correction in energy for ground state .\\\\\n\t(c) $H_{p}=\\lambda X$\\\\\n\t(d) $H_{p}=\\lambda X^{2}$\\\\\n\\end{minipage}\n\\begin{answer}\n\t$\\text { For given system first excited state } n=1$\\\\\n\t$\\left|\\phi_{1}\\right\\rangle= \\begin{cases}0, & \\text { if } \\quad x<0 \\\\ 2\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{1 / 4}\\left(\\frac{m \\omega}{\\hbar}\\right)^{1 / 2} x \\exp \\left(-\\frac{m \\omega x^{2}}{2 \\hbar}\\right) ; & 0<x<\\infty\\end{cases}$\\\\\n(a)\t$E_{0}^{\\prime}=V_{0}(4 \\pi)\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{3 / 2 } \\int_{0}^{\\infty} x^2e^{-\\frac{m \\omega x^{2}}{\\hbar}} d x=V_{0}(4 \\pi)\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{3 / 2} \\frac{1}{2}\\left(\\frac{\\hbar}{m \\omega}\\right)^{3 / 2} \\frac{1}{2} \\sqrt{\\pi}=V_{0}$\\\\\\\\\n(b)$H_{p}=\\lambda V_{0} \\delta\\left(x-\\sqrt{\\frac{\\hbar}{m \\omega}}\\right)$\n\\begin{align*}\nE_{0}^{\\prime}&=V_{0} \\cdot 4 \\pi\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{3 / 2} \\int_{0}^{\\infty} x^{2} e^{-\\frac{m \\omega x^{2}}{\\hbar}} \\int\\left(x-\\sqrt{\\frac{\\hbar}{m \\omega}}\\right) d x\\\\\n&=\\left(4 \\pi V_{0}\\right)\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{3 / 2}\\left(\\sqrt{\\frac{\\hbar}{m \\omega}}\\right)^{2} e^{-\\frac{m \\omega}{\\hbar} \\cdot\\left(\\frac{m \\omega}{\\hbar}\\right)}\\\\\n&=\\frac{4 \\pi V_{0}}{\\pi^{3 / 2}}\\left(\\frac{m \\omega}{\\hbar}\\right)^{1 / 2} e^{-1}=4 V_{0}\\left(\\frac{m \\omega}{\\hbar}\\right)^{1 / 2} e^{-1}=4 V_{0} \\sqrt{\\frac{m \\omega}{\\pi \\hbar}} e^{-1}\n\\end{align*}\n$\\text { (d) } H_{p}=\\lambda x^{2}$\n\\begin{align*}\nE_{0}^{\\prime}&=4 \\pi\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{3 / 2} \\int_{0}^{\\infty} x^{3} e^{-\\frac{m \\omega x^{2}}{\\hbar}} d x\\\\\n&=4 \\pi\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{3 / 2} \\frac{1}{2}\\left(\\frac{\\hbar}{m \\omega}\\right)^{2} \\times 1=2 \\times \\sqrt{\\frac{\\hbar}{\\pi m \\omega}}\n\\end{align*}\n$\\text { (d) } H_{p}=\\lambda x^{2}$\\\\\n\\begin{align*}\nE_{0}^{\\prime}&=4 \\pi\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{3 / 2} \\int_{0}^{\\infty} x^{4} e^{-\\frac{m \\omega x^{2}}{h}} d x\\\\\n&=4 \\pi\\left(\\frac{m \\omega}{\\pi \\hbar}\\right)^{3 / 2}\\left(\\frac{\\hbar}{m \\omega}\\right)^{5 / 2} \\times \\frac{1}{2} \\times \\frac{3}{4} \\sqrt{\\pi}=\\frac{3}{2}\\left(\\frac{\\hbar}{m \\omega}\\right)\n\\end{align*}\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item $\\text { If Harmonic Potential is given by } V=\\frac{1}{2} m \\omega^{2} x^{2} \\text { and wave function is given as }$\\\\\n\t$$\n\t\\psi(x)= \\begin{cases}A \\cos \\frac{\\pi x}{a}, & \\frac{-a}{2}<x<\\frac{a}{2} \\\\ 0 & , \\quad \\text { otherwise }\\end{cases}\n\t$$\n\tthen find the ground state energy.\n\\end{minipage}\n\\begin{answer}\n$\\text { Since, }\\langle\\psi \\mid \\psi\\rangle=1 \\Rightarrow|A|=\\sqrt{\\frac{2}{a}}$\\\\\nHence, $|\\psi\\rangle=\\sqrt{\\frac{2}{a}} \\cos \\left(\\frac{\\pi x}{a}\\right), \\frac{-a}{2}<x<\\frac{a}{2}$\\\\\nAnd also, average kinetic energy, $\\langle T\\rangle=\\frac{\\pi^{2} \\hbar^{2}}{2 m a^{2}}$\t\\\\\n\\begin{align*}\n\\langle V\\rangle&=\\frac{1}{2} m \\omega^{2} \\int_{-a / 2}^{a / 2}\\left(\\sqrt{\\frac{2}{a}}\\right)^{2} x^{2} \\cos ^{2}\\left(\\frac{\\pi x}{a}\\right) d x\\\\\n&=\\frac{1}{-2} \\frac{m \\omega^{2}}{a} \\int_{-a / 2}^{a / 2}\\left[x^{2}\\left(1+\\cos \\frac{2 \\pi x}{a}\\right)\\right] d x\\\\\n&=\\frac{m \\omega^{2}}{2 a}\\left[\\frac{1}{3}\\left(x^{3}\\right)_{-a / 2}^{a / 2}+x^{2} \\frac{a}{2 \\pi} \\sin \\left(\\frac{2 \\pi x}{a}\\right)-\\frac{a}{\\pi}\\left\\{x\\left(-\\frac{a}{2 \\pi}\\right) \\cos \\frac{2 \\pi x}{a}+\\left(\\frac{a}{2 \\pi}\\right)^{2} \\sin \\frac{2 \\pi x}{a}\\right\\}\\right]_{-a / 2}^{a / 2}\\\\\n\\langle V\\rangle&=\\frac{m \\omega^{2}}{2 a}\\left[\\frac{a^{3}}{12}-\\frac{a^{3}}{2 \\pi^{2}}\\right]=\\frac{m \\omega^{2} a^{2}}{4}\\left(\\frac{1}{6}-\\frac{1}{\\pi^{2}}\\right)\\\\\n\\text { Hence, }\\langle E\\rangle&=\\langle T\\rangle+\\langle V\\rangle=\\left(\\frac{\\pi^{2} \\hbar^{2}}{2 m a^{2}}\\right)+\\frac{m \\omega^{2} a^{2}}{4}\\left(\\frac{1}{6}-\\frac{1}{\\pi^{2}}\\right)\\\\\n&\\text { For minimum energy, } \\frac{d\\langle E\\rangle}{d a}=0\\\\\n&\\Rightarrow \\frac{\\pi^{2} \\hbar^{2}}{2 m}\\left(-\\frac{2}{a^{3}}\\right)+\\frac{m \\omega^{2} a}{2}\\left(\\frac{1}{6}-\\frac{1}{\\pi^{2}}\\right)=0 \\Rightarrow a=\\left[\\frac{2 \\pi^{2} \\hbar^{2}}{m^{2} \\omega^{2}} \\times\\left(\\frac{6 \\pi^{2}}{\\pi^{2}-6}\\right)\\right]^{1 / 4} \\\\\n\\therefore\\langle E\\rangle&=\\hbar \\omega\\left(\\frac{\\pi^{2}}{12}-\\frac{1^{-}}{2}\\right)^{1 / 2}\n\\end{align*}\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item Using the trial wave-function, $\\psi=e^{-a r}$, find the ground state energy of $3-D$ harmonic oscillator with potential $V=\\frac{1}{2} m \\omega^{2} r^{2}$.\n\\end{minipage}\n\\begin{answer}\n\t$V=\\frac{1}{2} m \\omega^{2} r^{2}$\\\\\n\t\\begin{align*}\n\t\t&\\text { Trial wave function, } \\psi=e^{-u r} \\\\\n\t\t&\\because \\quad \\text { Normalising, } \\psi=|A|^{2} \\cdot 4 \\pi \\int_{0}^{\\infty} r^{2} e^{-2 \\alpha r} d r=1 \\Rightarrow|A|=\\sqrt{\\frac{\\alpha^{3}}{\\pi}}\n\t\\end{align*}\n\t$\\langle T\\rangle=-\\frac{\\hbar^{2}}{2 m} 4 \\pi \\int_{0}^{\\infty} \\psi^{\\cdot}\\left(\\frac{d^{2}}{d r^{2}}+\\frac{2}{r}\\right) \\psi r^{2} d r, \\text { where } \\psi=\\sqrt{\\frac{\\alpha^{3}}{\\pi}} e^{-\\alpha r}$\\\\\n\t\\begin{align*}\n\t\t&\\langle T\\rangle=-\\frac{\\hbar^{2}}{2 m}\\left(\\frac{\\alpha^{3}}{\\pi}\\right) 4 \\pi \\int_{0}^{\\infty} e^{-\\alpha r}\\left(\\alpha^{2}-\\frac{2 \\alpha}{r}\\right) e^{-\\alpha r} r^{2} d r \\\\\n\t\t&\\langle T\\rangle=-\\frac{\\hbar^{2}}{2 m}\\left(\\frac{\\alpha^{3}}{\\pi}\\right) 4 \\pi\\left(\\alpha^{2} \\int_{0}^{\\infty} e^{-2 \\alpha r} r^{2} d r-2 \\alpha \\int_{0}^{\\infty} e^{-2 \\alpha r} r d r\\right) \\\\\n\t\t&=\\frac{-\\hbar^{2} \\alpha^{3}}{2 m \\pi} 4 \\pi\\left[\\alpha^{2}\\left(\\frac{1}{2 \\alpha}\\right)^{3}\\left\\lfloor 2-2 \\alpha\\left(\\frac{1}{2 \\alpha}\\right)^{2}\\right]=\\frac{-\\hbar^{2} \\alpha^{3}}{2 m \\pi} 4 \\pi\\left[\\frac{1}{4 \\alpha}-\\frac{1}{2 \\alpha}\\right]\\right.\\\\\n\t\t&\\langle T\\rangle=\\frac{\\hbar^{2} \\alpha^{2}}{2 m} \\\\\n\t\t&\\langle V\\rangle=\\frac{\\alpha^{3}}{\\pi} \\times \\frac{1}{2} m \\omega^{2} \\times 4 \\pi \\int_{0}^{\\infty} r^{2} r^{2} e^{-2 \\alpha r} d r=\\frac{3 \\omega^{2} m}{2 \\alpha^{2}} \\\\\n\t\t&\\therefore\\langle E\\rangle=\\frac{\\hbar^{2} \\alpha^{2}}{2 m}+\\frac{3 \\omega^{2} m}{2 \\alpha^{2}}\\\\\n\t\t&\\frac{d\\langle E\\rangle}{d \\alpha}=0 \\Rightarrow \\frac{\\hbar^{2} \\alpha}{m}-\\frac{3 \\omega^{2} m}{\\alpha^{3}}=0 \\Rightarrow \\alpha=\\left(\\frac{3 m^{2} \\omega^{2}}{\\hbar^{2}}\\right)^{1 / 4} \\\\\n\t\t&\\langle E\\rangle=\\frac{\\hbar^{2}}{2 m}\\left(\\frac{3 m^{2} \\omega^{2}}{\\hbar^{2}}\\right)^{1 / 2}+\\frac{3 \\omega^{2} m}{2}\\left(\\frac{\\hbar^{2}}{3 m^{2} \\omega^{2}}\\right)^{1 / 2} \\\\\n\t\t&=\\frac{1}{2}\\left(3 \\hbar^{2} \\omega^{2}\\right)^{1 / 2}+\\frac{1}{2}\\left(3 \\hbar^{2} \\omega^{2}\\right)^{1 / 2} \\Rightarrow\\langle E\\rangle=\\sqrt{3} \\hbar \\omega\n\t\\end{align*}\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item A particle in one dimension moves under the influence of a potential $V(x)=a x^{6}$, where $a$ is a real constant. For large $n$ the quantized energy level $E_{n}$ depends on $n$ as $E_{n}=n^{\\alpha}$ then find the value of $\\alpha$.\n\\end{minipage}\n\\begin{answer}$\\left. \\right. $\\\\\n\t\\begin{minipage}{0.5\\textwidth}\n\t$V(x)=a x^{6} \\text { and } E=\\frac{p^{2}}{2 m}+a x^{6}$\\\\\n\tAccording to Bohr Somerfield theory $\\oint p d x=n h, n=1,2 \\ldots$\\\\\\\\\n\t$\n\t\\oint \\sqrt{2 m\\left(E-a x^{6}\\right)} d x=n h, n=1,2 \\ldots\n\t$\n\t\\end{minipage}\n\t \\begin{minipage}{0.5\\textwidth}\n\t \\begin{figure}[H]\n\t \t\\centering\n\t \t\\includegraphics[height=3cm,width=5cm]{diagram-20220205-20220205160131-crop}\n\t \\end{figure}\n\t \\end{minipage}\n\t $$\\text { 4. } \\int_{0}^{\\left(\\frac{E}{a}\\right)} \\sqrt{2 m\\left(E-a x^{6}\\right)} d x=n h \\Rightarrow 4 \\sqrt{2 m E} \\int_{0}^{\\frac{E}{a}} \\int_{1 / 6}^{1 / 6} \\sqrt{\\left(1-\\frac{a x^{6}}{E}\\right)} d x=n h, n=1,2 \\ldots$$\n\t \\begin{align*}\n\t \t&\\text { Put }\\left(\\frac{a}{E}\\right)^{1 / 6} x=t \\text { then } d x=d t\\left(\\frac{E}{a}\\right)^{\\frac{1}{6}} \\Rightarrow 4 \\sqrt{2 m E} \\cdot\\left(\\frac{E}{a}\\right)^{1 / 6} \\int_{0}^{1} \\sqrt{\\left(1-t^{6}\\right)} d t=n h \\\\\n\t \t&\\Rightarrow E^{\\frac{1}{2}+\\frac{1}{6}} \\propto n \\Rightarrow E^{\\frac{4}{6}} \\propto n \\Rightarrow E \\propto n^{\\frac{3}{2}} \\text { so value of } \\alpha=\\frac{3}{2}\n\t \\end{align*}\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item A particle of mass $m$ interacts with potential $V(x)=\\left\\{\\begin{array}{l}\\infty, x \\leq 0 \\\\ \\lambda x, x \\geq 0\\end{array} .\\right.$ Using the WKB approximation Find the energy of bound state system.\n\\end{minipage}\n\\begin{answer}\n$\\text { For bound state system } E>0 \\text { where } E=\\frac{p^{2}}{2 m}+\\lambda x \\Rightarrow p=\\sqrt{2 m(E-\\lambda x)}$\\\\\nThe two turning points are given by $x_{1}=0$ and $x_{2}=\\frac{E}{\\lambda}$\\\\\nIn the given potential one boundary is rigid and another is smooth so according to WKB\nApproximation Bound state is given by $\\int_{x_{1}}^{x_{2}} p d x=\\left(n+\\frac{3}{4}\\right) \\pi \\hbar$, where $n=0,1,2$\\\\\n\\begin{minipage}{0.5\\textwidth}\n$\\sqrt{2 m E} \\int_{0}^{\\frac{E}{\\lambda}} \\sqrt{1-\\left(\\frac{\\lambda}{E}\\right)} x d x=\\left(n+\\frac{3}{4}\\right) \\pi \\hbar$ where $n=0,1,2$ \\\\\n$\\frac{\\lambda}{E} x=t \\Rightarrow d x=\\frac{E}{\\lambda} d t$\\\\\n\\end{minipage}\n\\begin{minipage}{0.5\\textwidth}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3cm,width=5cm]{diagram-20220205(1)-20220205162522-crop}\n\\end{figure}\n\\end{minipage}\nSo the integration is given by $\\sqrt{2 m E} \\cdot \\frac{E}{\\lambda} \\int_{0}^{1} \\sqrt{1-t} d t=(n+3 / 4) \\pi \\hbar, n=0 ; 1,2 \\ldots$ To find $I=\\int_{0}^{1} \\sqrt{1-t} d t$\\\\\n\\begin{align*}\n\t&\\text { put } 1-t=y-d t=d y \\text { so } I=-\\int_{1}^{0} \\sqrt{y} d y \\quad \\Rightarrow \\int_{0}^{1} y^{1 / 2} d y=\\frac{\\left(y^{3 / 2}\\right)_{0}^{1}}{3 / 2}=\\frac{2}{3} \\\\\n\t&\\sqrt{2 m E} \\cdot \\frac{E}{\\lambda} \\int_{0}^{1} \\sqrt{1-t} d t=\\sqrt{2 m E} \\cdot \\frac{E}{\\lambda} \\times \\frac{2}{3}=\\left(n+\\frac{3}{4}\\right) \\pi \\hbar \\quad \\text { where } n=0,1,2 \\ldots \\\\\n\t&=E^{3 / 2} \\cdot 2 \\frac{\\sqrt{2 m}}{3 \\lambda}=\\left(n+\\frac{3}{4}\\right) \\pi \\hbar \\Rightarrow E=\\left[\\frac{3 \\hbar \\pi \\lambda}{2 \\sqrt{2 m}}(n+3 / 4)\\right]^{\\frac{2}{3}} n=0,1,2 \\ldots . .\n\\end{align*}\t\n\\end{answer}\n \\end{enumerate}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n", "meta": {"hexsha": "fd3c6cfb44f98b7952821bc3d66d36c5f457e238", "size": 101729, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "QM -CSIR/chapter/Approximation methods.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "QM -CSIR/chapter/Approximation methods.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "QM -CSIR/chapter/Approximation methods.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.5491367862, "max_line_length": 1074, "alphanum_fraction": 0.6423537045, "num_tokens": 39572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7163146041519941}}
{"text": "\\documentclass[12pt]{article}\n\n% essential math based packages \n\\usepackage{amsfonts}\t% commonly used fonts and symbols in mathematics\n\\usepackage{amsmath}\t% additional set of math tools on top of LaTeX\n\\usepackage{amssymb}\t% common math symbols\n\\usepackage{amsthm}\t% theorem based setup following AMS standards\n\n\\usepackage[T1]{fontenc}\n\n\\usepackage{multicol}\n \n\\usepackage{hyperref} \n\\hypersetup{\n    colorlinks=true,\n    linkcolor=blue,\n    filecolor=magenta,      \n    urlcolor=cyan,\n}\n \n\\begin{document}\n\n% remove indentations for entire document\n\\setlength\\parindent{0pt}\n\n\\section{Math enviornments}\n% Introduciont to math enviornments\n%------------------------------------%\n% short cut symbols\n\\subsection*{Inline elements}\n\\begin{enumerate}\n\t\\item using \\verb!$...$!: $a+b=c$ \n\t\\item using \\verb!\\[...\\]!: \\(a/b=c\\) \n\t\\item using environment \\verb!\\begin{math}...\\end{math}!): \n\t\t\\begin{math}\n\t\ta - b = c\n\t\t\\end{math}\n\\end{enumerate}\nTakeaway: Although there are said to be issues, or incompatibilities with using \\verb!$...$!, most examples and working code use this shorthand for inline math. If for whatever reason you do find issues, then use \\verb!\\(...\\)!.\n\n\\subsection*{Blocked elements}\n\\begin{enumerate}\n\t\\item using \\verb!$$...$$!: $$ \\frac{a}{b}=c $$\n\t\\item using \\verb!\\[...\\]!: \\[ \\int^a_b = c\\]\n\t\\item using enviornment \\verb!\\begin{displaymath}...\\end{displaymath}!:\n\t\t\\begin{displaymath}\n\t\t\\dfrac{\\partial a}{\\partial\tb} = c\n\t\t\\end{displaymath}\n\\end{enumerate}\nTakeaway: Much like for inline math, \\verb!$$...$$! is commonly used. However, if you do find issues (which rarely does), then use \\verb!\\[...\\]!. \n\n\\subsection*{Alignments \\& numberings}\n\\begin{enumerate}\n\t\\item Numbered equations\n\t\\begin{equation}\n\t\t\\text{KE} = 1/2mv^2\n\t\\end{equation}\n\t\n\t\\item No numbered equations ({\\*}trick, similar to section numberings)\n\t\\begin{equation*}\n\t\t\\text{PE} = \\int_{\\text{ref}}^{x} F \\operatorname{d}\\!\\overrightarrow{x}\n\t\\end{equation*}\t\n\t\n\t\\item Numbered equations (not aligned)\n\t\\begin{gather}\n\t\t\\exp^{ix} = \\cos{x} + i\\sin(x) \\\\\n\t\t\\exp^{i\\pi} + 1 = 0\n\t\\end{gather}\n\t\n\t\\item Numbered and aligned\n\t\\begin{align}\n\t\t\\nabla \\cdot \\vec{D} &= \\rho_v \\\\\n\t\t\\nabla \\cdot \\vec{B} &= 0 \\\\\n\t\t\\nabla \\times \\vec{E} &= - \\frac{\\partial B}{\\partial t} \\\\\n\t\t\\nabla \\times \\vec{B} &= \\mu_{0}\\vec{J} +\n\t\t\\mu_{0}\\epsilon_{0}\\frac{\\partial E}{\\partial t}\n\t\\end{align}\n\t\n\t\\item Controlling numbering and alignment\n\t\\begin{align}\n\t\t&\\nabla \\cdot \\vec{D} = \\rho_v \\nonumber \\\\\n\t\t&\\nabla \\cdot \\vec{B} = 0 \\\\\n\t\t&\\nabla \\times \\vec{E} = - \\frac{\\partial B}{\\partial t} \\\\\n\t\t&\\nabla \\times \\vec{B} = \\mu_{0}\\vec{J} +\n\t\t\\mu_{0}\\epsilon_{0}\\frac{\\partial E}{\\partial t} \\nonumber\n\t\\end{align}\n\\end{enumerate}\nTakeaway: All environments can use the \\* trick to suppress numbering, or \\verb!\\nonumber! can do this specifically per line. Although not shown in this demonstration, if equations get too long, or multiple equations should be given 1 equation number (such as an \\textit{if/else} statement), use the \\verb!\\begin{split}! or \\verb!\\begin{multiline}! environments.\n\n%------------------------------------%\n\n\\section{Symbols}\n\n\\subsection*{Greek symbols}\nNote that greek symbols that can be represented by english letters such as \\verb!\\Alpha! and \\verb!\\Chi! do not exists, as their symbols $A$ and $X$ are indistinguishable from using letters \\verb!$A$! and \\verb!$X$!. However, some packages override this behavior, so please check what math packages you import.\n\n$$\\alpha, A, \\beta, B, \\gamma, \\Gamma, \\delta, \\Delta ...\\, \\mu, \\nu $$\n\n\\subsection*{Equation symbols}\nYou have control over all types of symbols relevant to mathematical, and even graphical representation. To get an extensive list please look \\href{https://en.wikibooks.org/wiki/LaTeX/Mathematics#List_of_mathematical_symbols}{here}.\n\n\\subsection*{Formatting mathematical symbols}\nSome equations need more than a simple definition or symbol. Some symbols can be compounded to make more complex statements. For example\n$$\n\\overrightarrow{\\sum_{i=\\iiint}^{j={\\widehat{AAA}}}}\n$$\nA more comprehensive discussion on this topic, and how to customize the look can be found \\href{https://en.wikibooks.org/wiki/LaTeX/Mathematics#Formatting_mathematics_symbols}{here}.\n\n\\section{Spacing}\nHorizontal spacing is dictated by the document class font size (e.g. 11pt, 12pt, etc.) and is measured by \\textit{em} which is roughly proportional to the horizontal width of a capital M. To artificially create 1 em width is to use \\verb!\\quad!. See: \\\\\n\n\\indent A{\\quad}B\\\\\n\\indent AMB (... a little bit more than M)\\\\\n\nKnowing this, there are many commands such as \\verb!\\,! \\verb!\\:! that create fractions of \\verb!\\quad!. The variety of commands for horizontal spacing in normal and math mode can be found \\href{https://en.wikibooks.org/wiki/LaTeX/Mathematics#Controlling_horizontal_spacing}{here}. There is also a discussion on which \\href{https://tex.stackexchange.com/questions/41476/lengths-and-when-to-use-them}{spacing is appropriate}.\n\n\n\\end{document}", "meta": {"hexsha": "3513409beb622e03c802cc87f97e0adab93a617c", "size": 5011, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "test-files/3 - include math and symbols/math-symbols.tex", "max_stars_repo_name": "MIT-BECL/LaTeX-intro", "max_stars_repo_head_hexsha": "3a0c71126d9785f604388c0729b009988cbf00b1", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-09T17:04:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-09T17:04:44.000Z", "max_issues_repo_path": "test-files/3 - include math and symbols/math-symbols.tex", "max_issues_repo_name": "MIT-BECL/LaTeX-intro", "max_issues_repo_head_hexsha": "3a0c71126d9785f604388c0729b009988cbf00b1", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test-files/3 - include math and symbols/math-symbols.tex", "max_forks_repo_name": "MIT-BECL/LaTeX-intro", "max_forks_repo_head_hexsha": "3a0c71126d9785f604388c0729b009988cbf00b1", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-09T17:04:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-09T17:04:52.000Z", "avg_line_length": 42.4661016949, "max_line_length": 424, "alphanum_fraction": 0.7000598683, "num_tokens": 1506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.8688267881258485, "lm_q1q2_score": 0.7163145999310884}}
{"text": "\\chapter{Assignment}\n\\section{MCQ}\n\\begin{enumerate}\n\t\\item One of the possible solutions of the differential equation\n\t$y \\sqrt{\\left(1+x^{2}\\right)} d y+x \\sqrt{\\left(1+y^{2}\\right)} d x=0$ (where $c$ is some constant) is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\left(\\sqrt{1+y^{2}}\\right)\\left(\\sqrt{1+x^{2}}\\right)=c$\n\t\t\\task[\\textbf{b.}]$\\frac{\\sqrt{1+y^{2}}}{\\sqrt{1+x^{2}}}=c$\n\t\t\\task[\\textbf{c.}]$\\sqrt{1+y^{2}}+\\sqrt{1+x^{2}}=c$\n\t\t\\task[\\textbf{d.}]  $\\sqrt{1+y^{2}}-\\sqrt{1+x^{2}}=c$\n\t\\end{tasks}\n\t\\item The solution of the differential equation $x \\frac{d y}{d x}+\\cot y=0$, subject to the initial condition $y=\\frac{\\pi}{4}$ at $x=\\sqrt{2}$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$x=2 \\cos y$\n\t\t\\task[\\textbf{b.}]$x=2 \\sec y$\n\t\t\\task[\\textbf{c.}]$x=2 \\sin y$\n\t\t\\task[\\textbf{d.}]  $x=2 \\operatorname{cosecy}$\n\t\\end{tasks}\n\t\\item The solutions to the differential equation $\\frac{d y}{d x}=-\\frac{x}{y+1}$ are a family of\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]Circles with different radii\n\t\t\\task[\\textbf{b.}]Circles with different centres\n\t\t\\task[\\textbf{c.}]Straight lines with different slopes\n\t\t\\task[\\textbf{d.}] Straight lines with different intercepts on the $y$-axis\n\t\\end{tasks}\n\t\\item The solution of the differential equation $x y \\frac{d y}{d x}=3 y^{2}+x^{2}$ with the initial condition $y=2$ when $x=1$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$2 y^{2}+x^{2}=9 x^{6}$\n\t\t\\task[\\textbf{b.}] $y^{2}+2 x^{2}=9 x^{6}$\n\t\t\\task[\\textbf{c.}] $2 y^{2}+x^{2}=8 x^{6}$\n\t\t\\task[\\textbf{d.}] $y^{2}+2 x^{2}=8 x^{6}$\n\t\\end{tasks}\n\t\\item The solution of the differential equation\n\t$(x+2 y)(d x-d y)=d x+d y$ (where $a$ is some constant) is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$3 x+3 y+a=2 \\log (3 x+6 y-1)$\n\t\t\\task[\\textbf{b.}] $3 x-3 y+a=2 \\log (3 x+6 y-1)$\n\t\t\\task[\\textbf{c.}]$3 x-3 y+a=2 \\log (3 x-6 y-1)$\n\t\t\\task[\\textbf{d.}] $3 x+3 y+a=2 \\log (3 x-6 y-1)$\n\t\\end{tasks}\n\t\\item For the differential equation $\\frac{d y}{d x}+3 y=e^{2 x}$, the possible solution is:\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$y=c_{1} e^{2 x}+c_{2} e^{3 x}$\n\t\t\\task[\\textbf{b.}]$y=c_{1} e^{-2 x}+c_{2} e^{3 x}$\n\t\t\\task[\\textbf{c.}]$y=c_{1} e^{2 x}+c_{2} e^{-3 x}$\n\t\t\\task[\\textbf{d.}] $y=c_{1} e^{-2 x}+c_{2} e^{-3 x}$\n\t\\end{tasks}\n\t\\item The solution of the differential equation for $y: x \\frac{d y}{d x}+y=x^{4}$, subject to the initial condition $y=1$ at $x=1$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$y=5 x^{4}-4$\n\t\t\\task[\\textbf{b.}]$y=\\frac{x^{4}}{5}+\\frac{4 x}{5}$\n\t\t\\task[\\textbf{c.}] $y=\\frac{x^{4}}{5}+\\frac{1}{5 x}$\n\t\t\\task[\\textbf{d.}] $y=\\frac{x^{4}}{5}+\\frac{4}{5 x}$\n\t\\end{tasks}\n\t\\item Which one of the following curves gives the solution of the differential equation $K_{1} \\frac{d x}{d t}+K_{2} x=K_{3}$, where $K_{1}, K_{2}$ and $K_{3}$ are positive constants with initial conditions $x=0$ at $t=0$ ?\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2.5cm,width=4cm]{DE -assignment-04}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{b.}]\t\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2.5cm,width=4cm]{DE -assignment-01}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{c.}]\n\t\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2.5cm,width=4cm]{DE -assignment-02}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{d.}]\n\t\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2.5cm,width=4cm]{DE -assignment-03}\n\t\t\\end{figure}\n\t\\end{tasks}\n\t\\item The solution of the differential equation $t \\frac{d y}{d t}+y \\log y=t y e^{t}$\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\log y=(t+1) e^{t}+c$\n\t\t\\task[\\textbf{b.}]$\\log y=(t-1) e^{t}+c$\n\t\t\\task[\\textbf{c.}]$t \\log y=(t+1) e^{t}+c$\n\t\t\\task[\\textbf{d.}] $t \\log y=(t-1) e^{t}+c$\n\t\\end{tasks}\n\t\\item The solution of the differential equation\n\t$\\left(1+y^{2}\\right) d x=\\left(\\tan ^{-1} y-x\\right) d y$ (where $c$ is some constant) is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $x=\\left(\\tan ^{-1} y+2\\right)+c e^{-\\tan ^{-1} y}$\n\t\t\\task[\\textbf{b.}] $x=\\left(\\tan ^{-1} y-2\\right)+c e^{-\\tan ^{-1} y}$\n\t\t\\task[\\textbf{c.}] $x=\\left(\\tan ^{-1} y+1\\right)+c e^{-\\tan ^{-1} y}$\n\t\t\\task[\\textbf{d.}]  $x=\\left(\\tan ^{-1} y-1\\right)+c e^{-\\tan ^{-1}y}$\n\t\\end{tasks}\n\t\\item The solution of the differential equation\n\t$y \\log y \\frac{d x}{d y}+x-\\log y=0$ (where $c$ is some constant) is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$x \\log y=\\frac{1}{2}(\\log y)^{2}+c$\n\t\t\\task[\\textbf{b.}] $x \\log y=2(\\log y)^{2}+c$\n\t\t\\task[\\textbf{c.}]$x \\log y=\\frac{1}{2}(\\log y)^{3}+c$\n\t\t\\task[\\textbf{d.}]  $y \\log x=\\frac{1}{2}(\\log y)^{2}+c$\n\t\\end{tasks}\n\t\\item The solution of the differential equation\n\t$\\left(e^{y}+2\\right) \\sin x d x-e^{y} \\cos x d y=0$ (where $c$ is some constant) is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\left(e^{y}+2\\right) \\sin x=c$\n\t\t\\task[\\textbf{b.}] $\\left(e^{y}+2\\right) \\cos x=c$\n\t\t\\task[\\textbf{c.}] $\\left(e^{y}+2\\right) \\operatorname{cosec} x=c$\n\t\t\\task[\\textbf{d.}] $\\left(e^{y}+2\\right) \\sec x=c$\n\t\\end{tasks}\n\t\\item For the differential equation $\\left(y^{4}+2 y\\right) d x+\\left(x y^{3}+2 y^{4}-4 x\\right) d y=0$ one of the possible solution (where $C$ is some constant) is:\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$x+\\frac{2}{y^{2}}+y^{2}=c$\n\t\t\\task[\\textbf{b.}] $x\\left(y+\\frac{2}{y^{2}}\\right)=c$\n\t\t\\task[\\textbf{c.}]$x\\left(y+\\frac{2}{y^{2}}\\right)+y^{2}=c$\n\t\t\\task[\\textbf{d.}] $x\\left(1+\\frac{2}{y^{2}}\\right)+x^{2}=c$\n\t\\end{tasks}\n\t\\item The solution of the differential equation for $y(t): \\frac{d^{2} y}{d t^{2}}-\\frac{3 d y}{d t}+2 y=e^{3 t}$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $c_{1} e^{t}+c_{2} e^{2 t}+\\frac{1}{2} e^{3 t}$\n\t\t\\task[\\textbf{b.}]$c_{1} e^{-t}+c_{2} e^{2 t}+\\frac{1}{2} e^{3 t}$\n\t\t\\task[\\textbf{c.}]$c_{1} e^{t}+c_{2} e^{2 t}+e^{3 t}$\n\t\t\\task[\\textbf{d.}] $c_{1} e^{-t}+c_{2} e^{-2 t}+e^{3 t}$\n\t\\end{tasks}\n\t\\item The solution of the differential equation for $\\frac{d^{2} y}{d x^{2}}+2 \\frac{d y}{d x}+101 y=10.4 e^{x}$, subject to the initial conditions $y(0)=1.1$ and $\\left.\\frac{d y}{d x}\\right|_{x=0}=-0.9$, is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$e^{-x} \\cos 10 x+0.1 e^{x}$\n\t\t\\task[\\textbf{b.}]$e^{-x} \\sin 10 x+0.1 e^{x}$\n\t\t\\task[\\textbf{c.}]$e^{x} \\cos 10 x+0.1 e^{-x}$\n\t\t\\task[\\textbf{d.}] $e^{x} \\sin 10 x+0.1 e^{-x}$\n\t\\end{tasks}\n\t\\item The solution of the differential equation $\\frac{d^{2} y}{d t^{2}}+4 y=\\cos 2 t$ is:\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $A \\cos 2 t+B \\sin 2 t$\n\t\t\\task[\\textbf{b.}] $\\frac{t \\sin 2 t}{4}$\n\t\t\\task[\\textbf{c.}]$A \\cos 2 t+B \\sin 2 t+\\frac{t \\sin 2 t}{4}$\n\t\t\\task[\\textbf{d.}] $A \\cos 2 t+B \\sin 2 t+\\frac{t^{2} \\sin 2 t}{4}$\n\t\\end{tasks}\n\t\\item The solution of the differential equation for $y(t): \\frac{d^{2} y}{d t^{2}}-y=2 \\cosh (t)$, subject to the initial conditions $y(0)=0$ and $\\left.\\frac{d y}{d t}\\right|_{t=0}=0$, is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{1}{2} \\cosh (t)+t \\sin h(t)$\n\t\t\\task[\\textbf{b.}]$-\\sin h(t)+t \\cosh (t)$\n\t\t\\task[\\textbf{c.}] $t \\cosh (t)$\n\t\t\\task[\\textbf{d.}] $t \\sin h(t)$\n\t\\end{tasks}\n\t\\item The solution of the differential equation for $y(t): \\frac{d^{2} y}{d t^{2}}-y=2 \\sinh (t)$, subject to the initial conditions $y(0)=0$ and $\\left.\\frac{d y}{d t}\\right|_{t=0}=0$, is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\frac{1}{2} \\cosh (t)+t \\sin h(t)$\n\t\t\\task[\\textbf{b.}]$-\\sin h(t)+t \\cosh (t)$\n\t\t\\task[\\textbf{c.}]$t \\cosh (t)$\n\t\t\\task[\\textbf{d.}] $t \\sin h(t)$\n\t\\end{tasks}\n\\end{enumerate}\n\\section{NAT}\n\\begin{enumerate}\n\t\\item The solution of the differential equation $\\frac{d x}{d t}=x^{2}$ with the initial condition $x(0)=1$ will blow up as $t$ tends to..........\n\t\\item The value of $\\lambda \\ldots .$ for which the differential equation $\\left(x y^{2}+\\lambda x^{2} y\\right) d x+(x+y) x^{2} d y=0$ is exact\n\t\\item The particular integral of the differential equation $\\left(D^{2}+D+1\\right) y=\\cos 2 x$ is $\\frac{1}{\\alpha}(2 \\sin 2 x-3 \\cos 2 x) .$ Then the value of $\\alpha$ is.....\n\t\\item The particular integral of the differential equation $\\frac{d^{2} y}{d x^{2}}+2 \\frac{d y}{d x}+2 y=\\sin x$ is $\\frac{1}{5}(\\sin x-\\alpha \\cos x) .$ Then the value of $\\alpha$ is........\n\t\\item The particular integral of the differential equation $\\left(D^{2}-5 D+6\\right) y=e^{t} \\cos 2 t$ is $-\\frac{e^{t}}{20}(\\alpha \\sin 2 t+\\cos 2 t)$. Then the value of $\\alpha$ is........\n\t\\item The particular integral of the differential equation $\\left(D^{2}-4 D+4\\right) y=x^{3} e^{2 x}$ is $e^{2 x} \\frac{x^{\\alpha}}{20}$. Then the value of $\\alpha$ is........\n\t\\item The particular integral of the differential equation $\\left(D^{2}+5 D+4\\right) y=3-2 x$ is $\\frac{1}{8}[\\alpha-4 x]$.\n\tThen the value of $\\alpha$ is........\n\t\\item The maximum value of the solution $y(t) \\ldots \\ldots \\ldots . .$ of the differential equation for $y(t)+\\ddot{y}(t)=0$, subject to the initial conditions $\\dot{y}(0)=1$ and $y(0)=1$ for $t \\geq 0$, is\n\t\\item If the characteristic equation $\\frac{d^{2} y}{d x^{2}}+2 \\alpha \\frac{d x}{d t}+y=0$ has two equal roots, then the value of $\\alpha \\ldots \\ldots \\ldots$ is\n\t\\item Consider the differential equation $\\frac{d^{2} x}{d t^{2}}+3 \\frac{d x}{d t}+2 x=0 .$ Given $x(0)=20$ and $x(1)=\\frac{10}{e}$, where $e=2.718$, the value of $x(2)$ is\n\\end{enumerate}\n", "meta": {"hexsha": "500801eee0a868800d38d10d0177d018d79b4e8e", "size": 9135, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/Assignments/Assignment- Differential Equations.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CSIR- Mathematical Physics/chapter/Assignments/Assignment- Differential Equations.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CSIR- Mathematical Physics/chapter/Assignments/Assignment- Differential Equations.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.0301204819, "max_line_length": 224, "alphanum_fraction": 0.5878489327, "num_tokens": 4090, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522814, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.716314592044857}}
{"text": "\\section{A basic machine learning problem: image classification}\nClassification problem is a very important part of machine learning. Its goal is to determine which class a new data belongs to based on a set of training data whose class is known. For example, in mail management, classifying an e-mail as ``spam\" or ``non-spam\" is a typical binary classification problem, and the classification of credit rating of credit card customers by banks belong to multiple classification problems. More specifically, in order to understand image classification problem, let us pose the following question:\n\n\n\\begin{itemize}\n\t\\item Given a set of images of cat, dog and rabbit, how does a machine classify the three different classes?\n\\end{itemize}\n\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=.4\\textwidth, height=.2\\textheight]{figures/cat-dog-1.png}\n\t\\end{center}\n\\end{figure}\n\n\\break\n\nFirst of all, we introduce how an image is represented on computer. Mathematically, {gray-scale image can be considered as a matrix  in $ \\mathbb{R}^{n_0\\times n_0}$ shown below, where the left one is the image from human vision and the right one is the matrix represented in computer. Each entry in this $ \\mathbb{R}^{n_0\\times n_0}$ corresponds to the value of a pixel belong to $[0,255]$.\n\t\\begin{center}\n\t\t\\includegraphics[width=.4\\textwidth, height=.2\\textheight]{6DL/figures/gray-1.png}\n\t\\end{center}\n\t\n\tA color image can be taken as 3D tensor (matrix with $3$ channels (RGB)) in $ \\mathbb{R}^{n_0\\times n_0 \\times 3}$\n\t\\begin{center}\n\t\t\\includegraphics[width=.4\\textwidth, height=.2\\textheight]{6DL/figures/corlor-1.png}\n\t\\end{center}\t\n\t\\break\n\t\n\tThen, let us think about the image classification problem of cat, dog and rabbit. Each image is a big vector of pixel values, for example\n\t$$ d=1280\\times720\\times 3  (\\text{width} \\times \\text{height} \\times \\text{RGB channel}) \\approx 3\\text{M},$$\n\twhich can be considered as a point $x \\in \\mathbb{R}^d$. The question becomes: given 3 different sets of points (cat, dog and rabbit) in $\\mathbb{R}^d$, how does a machine classify them?\n\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=.3\\textwidth, height=.3\\textwidth]{figures/cat-dog-2.png}   \\quad \\quad  \\quad \\quad\n\t\t\t\\includegraphics[width=.3\\textwidth, height=.3\\textwidth]{figures/cat-dog-3.png}\n\t\t\\end{center}\n\t\\end{figure}\n\t\n\t\\noindent To answer this question, we consider a mathematical problem: Find $f(\\cdot; \\bm \\theta): \\mathbb{R}^d \\to \\mathbb{R}^3$ such that:\n\t$$\n\tf(\\includegraphics[width=.07\\textwidth]{figures/cat.png}; \\Theta)\n\t\\approx \\begin{pmatrix}\n\t1\\\\ 0 \\\\ 0\n\t\\end{pmatrix}\n\t,\\quad\n\tf(\\includegraphics[width=.07\\textwidth]{figures/dog.png}; \\Theta)\n\t\\approx \\begin{pmatrix}\n\t0\\\\ 1 \\\\ 0\n\t\\end{pmatrix}\n\t,\\quad\n\tf(\\includegraphics[width=.07\\textwidth]{figures/rabbit.png};\n\t\\Theta) \\approx\n\t\\begin{pmatrix}\n\t0\\\\ 0 \\\\ 1\n\t\\end{pmatrix}\n\t.\n\t$$\n\t$f(\\cdot; \\bm \\theta)$ maps a given image to a 3-dimensional vector, which is a probability distribution  $\\begin{pmatrix}\n\tp_1\\\\ p_2 \\\\ p_3\n\t\\end{pmatrix}$\n\t, where $p_1, p_2, p_3$ are probabilities of the given image being cat, dog, rabbit, respectively. For example\n\t\n\t$$\n\tf(\\includegraphics[width=.07\\textwidth]{figures/cat.png}; \\bm \\theta)\n\t=\n\t\\begin{pmatrix}\n\t0.7\\\\ 0.2 \\\\ 0.1\n\t\\end{pmatrix}\n\t\\quad \\Longrightarrow \\quad \\includegraphics[width=.07\\textwidth]{figures/cat.png}= {\\rm cat}.\n\t$$\n\t$f$ is a classifier that can be used to classify what a given image is.\n\t\n\n\n\\break\n\\section{Some popular data sets in image classification}\nIn this subsection, we will introduce some popular and standard data sets\nin image classification. The most popular four data sets, MNIST, CIFAR-10, CIFAR-100 and ImageNet are shown in Table \\ref{popular_dataset}.\n\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{|c|c|c|c|c|c|}\n\t\t\\hline\n\t\t% after \\\\: \\hline or \\cline{col1-col2} \\cline{col3-col4} ...\n\t\tdataset &  training (N) & test (M)   & classes (k) & channels (c)& input size (d)\\\\\\hline\n\t\tMNIST\t&\t60K\t&\t10K\t&\t10\t& Greyscale & 28*28  \\\\\\hline\n\t\tCIFAR-10\t&\t50K \t&\t10K\t&\t10 & RGB & 32*32   \\\\\\hline\n\t\tCIFAR-100\t&\t50K \t&\t10K\t&\t100 & RGB & 32*32   \\\\\\hline\n\t\tImageNet\t&\t1.2M \t&\t50K\t&\t1000 &\tRGB & 224*224  \\\\\\hline\n\t\\end{tabular}\n\t\\caption{Basic descriptions about popular datasets }\n\t\\label{popular_dataset}\n\\end{table}\n\n\\break\n\\subsection{MNIST (Modified National Institute of Standards and Technology Database)}\nMNIST\\cite{lecun1998mnist} is a database for handwritten digits. It is a simple database for people who want to try learning techniques and pattern recognition methods on real-world data while spending minimal efforts on preprocessing and formatting. In order to use MNIST for the classification problem, the following setup is often used:\n\\begin{itemize}\n\t\\item Training set : $N = 60,000$;\n\t\\item Test set : $M = 10,000$;\n\t\\item Image size : $d =28*28*1=784$;\n\t\\item Classes: $ k = 10$;\n\\end{itemize}\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[height=.2\\textheight]{mnist_short.png}\n\t\t\\caption{Some images in MNIST.}\n\t\\end{center}\n\\end{figure}\nThe following example shows  an image of handwritten digits is represented mathematically\n\\break\n$$\nx=\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist2_1.jpg}}\n=\n\\begin{pmatrix}\n  x_1\\\\\nx_2\\\\\n\\vdots\\\\\nx_{784}\n\\end{pmatrix}\n\\in \\mathbb R^{784}.\n$$\nMNIST has 10 classes denoted by $\\{A_k\\}_{k=1}^{10}$ as shown in the following, where $A_{k}$ is the set of handwritten digits $k$ for $k=1,2,3,...,9$ and $A_{10}$ is the set of handwritten digits $0$\n\\begin{equation}\n  \\label{A2}\nA_2=\n\\left\\{\n\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist2_1.jpg}},\n\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist2_2.jpg}},\\cdots\n%\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist2_3.jpg}}, \\cdots\n\\right\\},~\n%\\subset \\mathbb R^{784}\nA_{9}=\n\\left\\{\n\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist9_1.jpg}},\n\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist9_2.jpg}},\\cdots\n%\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist9_3.jpg}}, \\cdots\n\\right\\},~\nA_{10}=\n\\left\\{\n\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist0_1.jpg}},\n\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist0_2.jpg}}, \\cdots\n%\\adjustbox{valign=c}{\\includegraphics[height=.03\\textheight]{mnist0_3.jpg}}, \\cdots\n\\right\\}\n\\subset \\mathbb R^{784}.\n\\end{equation}\n\n\n\n\\break\n\\subsection{CIFAR}\n\\paragraph{CIFAR-10}\nCIFAR-10\\cite{krizhevsky2009learning} is a set of images that can be used to teach a computer how to recognize objects. It contains 60,000 32x32 color images in 10 different classes,  with 6000 images per class. The 10 different classes represent airplanes, cars, birds, cats, deer, dogs, frogs, horses, ships, and trucks. In order to use CIFAR-10 for the classification problem, people usually use the following setup:\n\\begin{itemize}\n\t\\item Training set : $N = 50,000$\n\t\\item Test set : $M = 10,000$\n\t\\item Image size : $d  = 32*32*3$\n\t\\item Classes: $k = 10$\n\\end{itemize}\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[height=.26\\textheight]{cifar10.jpg}\n\t\t\\includegraphics[height=0.26\\textheight]{cifar100.png}\n\t\t\\label{Fig: CIFAR-10}\n\t\t\\caption{Left: Some images in CIFAR-10. Right: Some images in CIFAR-100.}\n\t\\end{center}\n\\end{figure}\n\n\n\\break\n\n\\paragraph{CIFAR-100}\nCIFAR-100\\cite{krizhevsky2009learning} is just like the CIFAR-10, except it has 100 classes containing 600 images each. There are 500 training images and 100 testing images per class. The 100 classes in the CIFAR-100 are grouped into 20 superclasses and each superclass has 5 classes. Each image comes with a ``fine\" label (the class to which it belongs) and a ``coarse\" label (the superclass to which it belongs). In order to use CIFAR-100 for the classification problem, people usually use the following setup:\n\n\\begin{itemize}\n\t\\item Training set : $N = 50,000$\n\t\\item Test set : $M = 10,000$\n\t\\item Image size : $d = 32*32*3$\n\t\\item Classes: $k = 100$\n\t\\end{itemize}\n\n\\subsection{ImageNet}\nThe ImageNet\\cite{deng2009imagenet} project is a large visual database designed for use in visual object recognition software research. More than 1 million images have been hand labeled to indicate what objects are pictured. It is organized according to the WordNet hierarchy (currently only the nouns), in which each node of the hierarchy is depicted by hundreds and thousands of images.\nSince 2010, the ImageNet runs an annual software contest, the ImageNet Large Scale Visual Recognition Challenge (ILSVRC), where software programs compete to correctly classify and detect objects and scenes. In order to use ImageNet for the classification problem, we list the setup of ILSVRC2012 in the following\n\\begin{itemize}\n\t\\item Training set : $N = 1,200,000$\n\t\\item Test set : $M = 50,000$\n\t\\item Image size : $d = 224*224*3$\n\t\\item Classes: $k = 1,000$\n\\end{itemize}\n\\begin{figure}[H]\n\t\\begin{center}\n\\includegraphics[height=0.22\\textheight]{imagenet-example.png}\n\t\t\\caption{Some images in ImageNet.}\n\t\\end{center}\n\\end{figure}\n\\break\n\n\\endinput\n", "meta": {"hexsha": "66a78cefa64bea158f6b41481779b035a5442a33", "size": 9081, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ClassificationProblem.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/ClassificationProblem.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/ClassificationProblem.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.6331658291, "max_line_length": 532, "alphanum_fraction": 0.732188085, "num_tokens": 2904, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.7162792692998091}}
{"text": "\\section{Discretized Hamiltonian}\\label{sec:hamiltonian}\n\nWe consider a cubic finite volume (FV) of linear size $L$ with periodic boundary conditions and lattice spacing $\\epsilon$ so that $N=L/\\epsilon$ is an even integer that counts the number of sites in one spatial direction.\n\nThe contact interaction Hamiltonian \\eqref{hamiltonian} is implemented on the lattice as an entirely local operator, vanishing everywhere except at the origin where it is of strength $C$---the interaction is not smeared.\nThe Hamiltonian is given by\n\\begin{equation}\n    \\left\\langle \\vec{r}' \\middle| H \\middle| \\vec{r} \\right\\rangle\n    \\rightarrow\n    H_{\\vec{r}',\\vec{r}}^\\dispersion\n    =\n    \\frac{1}{2\\mu} K_{\\vec{r}',\\vec{r}}^\\dispersion + \\frac{1}{\\epsilon^D} C^\\dispersion \\delta_{\\vec{r}',\\vec{r}} \\delta_{\\vec{r},\\vec{0}}\n\\end{equation}\nwhere $K$ is a discretized Laplacian, implementing the momentum squared.\nThe $\\dispersion$ symbol indicates that quantities depend on the lattice spacing $\\epsilon$ and the explicit implementation of discretization effects like derivatives.\n\nTo ensure we control the discretization effects in generality, we study a variety of kinetic operators $K_{xy}^\\dispersion$.\nAn often-used set of finite-difference kinetic operators are constructed from the one-dimensional finite-difference Laplacian that reaches $\\nstep$ nearest neighbors,\n\\begin{equation}\n    \\Laplacian^\\dispersion_{r'r} = \\frac{1}{\\epsilon^2}\\sum_{s=-\\nstep}^{\\nstep} \\gamma_{\\abs{s}}^{(\\nstep)} \\delta_{r',r+\\epsilon s}^{(L)}\n\\end{equation}\nwhere the $(L)$ index of the Kronecker delta indicates that the spatial indices are understood modulo the periodic boundary conditions of the lattice.\nIn $D$ dimensions we simply take on-axis finite differences, so that the Laplacian is a $(1+2\\nstep D)$-point stencil\n\\begin{equation}\\label{eq:kinetic}\n    K_{\\vec{r}',\\vec{r}}^\\dispersion(\\epsilon)\n    =\n    - \\sum_{d=1}^D \\Laplacian_{r_d'r_d^{}}^\\dispersion\n    \\, .\n\\end{equation}\n\nIn the Fourier transformed space, momentum space, the one-dimensional Laplacian may be written\n\\begin{equation}\n    \\label{eq:laplacian}\n    -\\Laplacian_{r'r^{}}^\\dispersion\n    \\overset{\\text{F.T.}}{\\longleftrightarrow}\n    \\Laplacian^\\dispersion_{p'p}\n    =\n    \\frac{1}{\\epsilon^2}\n    \\delta_{p'p}\n    \\sum_{s=0}^{\\nstep} \\gamma_s^{(\\nstep)} \\cos(s p \\epsilon)\n    \\, , \\qquad p = \\frac{2 \\pi}{L} n \\,\n\\end{equation}\nwhere $n$ is an integer.\nIn $D$ dimensions we just sum the same expression over the different components of momentum.\nNote that this is a specialization, in the sense that it contains no off-axis differencing (in position space) or products of different components (in momentum space).\nHowever, since the numerical formalism we will describe is valid for every $\\nstep$, we believe it holds for every possible kinetic operator.\n\n\\begin{figure}\n    \\input{figure/dispersion.pgf}\n    \\caption{We show the continuum dispersion relation of energy as a function of momentum for different one-dimensional $\\nstep$ derivatives.  For a finite number of lattice points $N$, the allowed momenta are evenly-spaced in steps of $2\\pi/N$.\n    As additional steps are incorporated into the finite difference, the dispersion relation more and more faithfully reproduces the desired $p^2$~behavior of $\\nstep=\\infty$.\n    }\n    \\label{fig:dispersion relation}\n\\end{figure}\n\nThe coefficients $\\gamma_{s}^{(\\nstep)}$ are determined by requiring the dispersion relation be as quadratic as possible,\n\\begin{equation}\n    \\label{eq:gamma determination}\n    \\Laplacian^\\dispersion_{p'p}\n    \\overset{!}{=}\n    \\delta_{p'p} \\;\n    p^2 \\left[\n        1 + \\order{(\\epsilon p)^{2\\nstep}}\n    \\right].\n\\end{equation}\nAdditionally, we study a nonlocal operator with $\\nstep=\\infty$ which, in momentum space, can be implemented by multiplying by $p^2$ directly,\n\\begin{equation}\n    \\lim\\limits_{n_s \\to \\infty}\n    \\Laplacian^\\dispersion_{p'p}\n    =\n    \\delta_{p'p} p^2,\n\\end{equation}\nincluding at the edge of the Brillouin zone, the Laplacian implementation of the ungauged SLAC derivative.\nIncluding the edge of the Brillouin zone does not introduce a discontinuity at the boundary, nor does including the corners pose any problem.\nIn addition to the $\\nstep=\\infty$ operator, we also call this kinetic operator the \\emph{exact-$p^2$} operator.\nThe resulting dispersion relations are presented in \\Figref{dispersion relation} for a variety of $\\nstep$s and in \\Appref{coefficients} we collect the required $\\gamma$ coefficients.\nIn \\Refs{Endres:2011er,Endres:2012cw} the exact dispersion relation is cut off by a LEGO sphere in momentum space (see equation (6) and the discussion after (9) in those references, respectively).\nThe formalism we develop here takes into account the implemented dispersion relation and thus is in principle extendable to these cut off operators, though the analytic results are harder to extract and we do not discuss such operators further.\n\nThe Hamiltonian in momentum space reads\n\\begin{equation}\n    \\label{eq:p space hamiltonian}\n    \\left\\langle \\vec{p}' \\middle| H \\middle| \\vec{p} \\right\\rangle\n    \\rightarrow\n    H_{\\vec{p}',\\vec{p}}^\\dispersion\n    =\n    \\frac{4 \\pi^2}{2\\mu L^2} \\tilde K_{\\vec n \\vec n}^{N}\n    +\\frac{1}{L^D}C^\\dispersion\n\\end{equation}\nwhere $\\vec{p} = 2\\pi \\vec{n}/L$ for a $D$-plet of integers $\\vec{n} \\in (-N/2, +N/2]^D$, and the coefficients $\\gamma_{s}^{(\\nstep)}$ are determined as described above.\nFurthermore, we replaced the lattice-spacing-dependent kinetic Hamiltonian with the $N$-dependent\n\\begin{equation}\\label{eq:normalized-kinetic-hamitlonian}\n\t\\tilde K_{\\vec n \\vec n}^{N}\n\t= \\frac{L^2}{4\\pi^2} K_{\\vec p \\vec p}^{\\dispersion} \\bigg|_{\\vec p=\\frac{2\\pi \\vec n}{L}}\n\t= \\frac{N^2}{4\\pi^2}\n    \\sum_{i=1}^{D}\\sum_{s=0}^{\\nstep} \\gamma_s^{(\\nstep)} \\cos\\left(\\frac{2 \\pi s n_i}{N}\\right)\n\\end{equation}\nwhich goes to $n^2$ in the continuum limit $N\\goesto\\infty$.\n\nAlthough the non-interacting energy levels are no longer proportional to $n^2$ at generic \\nstep, $n^2$ is still a useful classification for states, as long as it is understood simply as the magnitude of the lattice momentum---describing shells---rather than as a proxy for energy.\n\n\\subsection{Reduction to  \\texorpdfstring{\\Aoneg}{A-one-g}}\n\nBecause we are interested in contact interactions, infinite-volume arguments suggest that only the s-wave will feel the interaction; such arguments translate to the lattice relatively cleanly.\nSince the s-wave is most like \\Aoneg we will focus on the spectrum in that irreducible representation of the cubic symmetry group $O_h$ in three dimensions, of the symmetry group of the square $D_{4h}$ in two dimensions, or $Z_2$ in one dimension, where an \\Aoneg restriction amounts to focusing on parity-even states.\n\nWith a projection operator to the \\Aoneg sector $P_{\\Aoneg}$ we can raise the energy of all the other states an arbitrary amount $\\alpha$ by supplementing the Hamiltonian\n\\begin{equation}\n    H(\\alpha) = H + \\alpha (\\one - P_{\\Aoneg}) \\, ,\n\\end{equation}\nBecause $P_{\\Aoneg}$ commutes with $H$, $H$ and $H(\\alpha)$ have the same spectrum within the $\\Aoneg$ irrep.\nIf $\\alpha$ is much larger than the expected energies of the Hamiltonian, the \\Aoneg states remain low-lying and all other states are shifted to much higher energies.\nThen, exact diagonalization for low-lying eigenvalues of $H(\\alpha)$ provides an easier extraction of \\Aoneg eigenenergies.\n\nBecause of the simplicity of \\Aoneg we can also easily construct the Hamiltonian directly in that sector (a construction for general $O_h$ irreps was recently given in \\Ref{Li:2019qvh}).\nIn momentum space we can label plane wave states by a vector on integers $\\vec{n}$.\nIn the \\Aoneg basis we can use one plane wave label and understand that we intend a normalized unweighted average of every plane wave state.\nThat is,\n\\begin{equation}\n    \\ket{\\Aoneg\\; \\vec{n}} = \\frac{1}{\\sqrt{\\normalization}} \\sum_{g \\in O_h} \\ket{ g\\vec{n}}\n\\end{equation}\nwhere $g$ is an element of the group $O_h$, the sum is over all inequivalent states, and $\\normalization$ the normalization.\nWhen $\\vec{n}$ is large we should be careful not to double-count states that live right on the edge of the Brillouin zone.\nThe states may be labeled by symmetry-inequivalent vectors with components all as large as $N/2$.\nAs a simple example, in three dimensions the $N/2(1,1,1)$ plane wave state in one corner of the Brillouin zone is invariant under all the $O_h$ operations modulo periodicity in momentum space, so $\\normalization=1$ for that state.\n\nFormulated in this basis, the kinetic energy operator remains diagonal and proportional to $n^2$ when $N\\goesto\\infty$.\nReading off the momentum-state potential matrix element from \\eqref{p space hamiltonian}, the contact interaction is given by\n\\begin{equation}\n    \\braMket{\\Aoneg\\; \\vec{n}'}{V}{\\Aoneg\\; \\vec{n}}\n    =\n    \\sum_{g'g \\in O_h}\n        \\frac{1}{\\sqrt{\\normalization'}\\sqrt{\\normalization}} \\braMket{g'\\vec{n}'}{V}{g\\vec{n}}\n    =\n    \\frac{C^\\dispersion}{L^D} \\sqrt{\\normalization'\\normalization},\n\\end{equation}\nso that every \\Aoneg state talks to every other.\nSo, the Hamiltonian is in this sector is\n\\begin{equation}\n    H_{\\vec{n}'\\vec{n}}^\\dispersion = \\frac{4 \\pi^2}{2\\mu L^2} \\tilde K_{\\vec n \\vec n}^{N} + \\frac{C^\\dispersion}{L^D} \\sqrt{\\normalization'\\normalization}\n\\end{equation}\nand we divide by $4\\pi^2/\\mu L^2$ to make everything dimensionless.\n\nWe have implemented both this \\Aoneg-only Hamiltonian and the general Hamiltonian with an energy penalty for non-\\Aoneg states and verified that the spectra match where expected to as much precision as desired.\n\nFor a given $N$ multiple momenta inequivalent under the $O_h$ symmetry may have the same $n^2$.\nFor example, when $N\\geq5$ there are two $n^2=9$ shells corresponding to $n=(2,2,1)$ and $n=(3,0,0)$, which lives on the edge of the Brillouin zone for $N=5$.\nWhen $\\nstep=\\infty$ the corresponding non-interacting eigenstates are degenerate, while with imperfect dispersion relations the degeneracy is, generically, lifted.\nFor the contact interaction and $\\nstep=\\infty$, one linear combination of these \\Aoneg states overlaps the $S$-wave and has a nontrivial finite-spacing finite-volume energy, and the other overlaps a higher partial wave and has $x^{\\dispersion}=2\\mu E^{\\dispersion}L^2/4\\pi^2=9$ to machine precision, sitting right on a pole of the \\Luscher zeta function~\\eqref{spherical S}.\nIn contrast, when $N=4$ there is no $n=(3,0,0)$ state, and the $(2,2,1)$ state is itself an eigenstate.\nWhen $N$ is very large sometimes there are multiple eigenstates that have no support for the delta function---$n^2=41, 50, 54\\ldots$ have two non-interacting states, while $n^2=81, 89, 101\\ldots$ have three non-interacting states, and $n^2=146$ is the first shell with four non-interacting states, for example.\nAfter diagonalizing, we exclude these non-interacting \\Aoneg states from our analysis.\nWe do not discuss these non-interacting states further and omit them from figures without comment.\n", "meta": {"hexsha": "7f23c36981c2b2e8d8e7efa364b59cc8f62daab4", "size": 11035, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/luescher-nd/section/hamiltonian.tex", "max_stars_repo_name": "ckoerber/luescher-nd", "max_stars_repo_head_hexsha": "d1bc6bff0c6ee9f4dc0d1d0bb4bcfa842c44cceb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-12T22:19:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-26T14:06:49.000Z", "max_issues_repo_path": "paper/luescher-nd/section/hamiltonian.tex", "max_issues_repo_name": "ckoerber/luescher-nd", "max_issues_repo_head_hexsha": "d1bc6bff0c6ee9f4dc0d1d0bb4bcfa842c44cceb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-12-16T19:49:19.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-02T00:50:31.000Z", "max_forks_repo_path": "paper/luescher-nd/section/hamiltonian.tex", "max_forks_repo_name": "ckoerber/luescher-nd", "max_forks_repo_head_hexsha": "d1bc6bff0c6ee9f4dc0d1d0bb4bcfa842c44cceb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 71.6558441558, "max_line_length": 375, "alphanum_fraction": 0.7382872678, "num_tokens": 3147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7162792678250547}}
{"text": "\\section{Periodic Motion}\n\nA periodic wave in time is characterized by the time to complete one\ncycle called the period $T$, then linear and angular frequencies obtain\n\\begin{align*}\n  f &= 1/T  & \\omega &= 2\\pi f = 2\\pi/T\n\\end{align*}\nA restoring cause that is proportional to displacement\n\\begin{align*}\n  F &= -kx  & \\tau &= \\kappa \\theta\n\\end{align*}\nwill yield simple harmonic motion with a solution\n\\begin{align*}\n  x &= A \\cos(\\omega t + \\phi)  &  \\theta &= A_{\\theta} \\cos(\\omega t +\n  \\phi)\\\\\n  \\omega &= \\sqrt{k/m}  & \\omega &= \\sqrt{\\kappa/I}. \n\\end{align*}\nPendulums with small amplitudes approximate simple harmonic motion\n\\begin{align*}\n  k &= mg/\\ell  & \\kappa &= mg\\ell\\\\\n  \\omega &= \\sqrt{g/l}  & \\omega &= \\sqrt{mg\\ell/I}\n\\end{align*}\n\n", "meta": {"hexsha": "8b7256d7ee1b7e94cea4bf29f3c6d8d9a89f8307", "size": 754, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_PeriodicMotion-01.tex", "max_stars_repo_name": "tcburt/hodudodi", "max_stars_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_PeriodicMotion-01.tex", "max_issues_repo_name": "tcburt/hodudodi", "max_issues_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-18T22:55:02.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-18T23:01:00.000Z", "max_forks_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_PeriodicMotion-01.tex", "max_forks_repo_name": "tcburt/hodudodi", "max_forks_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.4166666667, "max_line_length": 71, "alphanum_fraction": 0.6538461538, "num_tokens": 253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541561135441, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.7162698433347764}}
{"text": "\\section{Detective problem: From which spaces could these have come?}\n\nGiven finitely many points and some pairs of distances between them. Usual suspects\nare some kinds of spaces from which they have come.\n\n\\vspace{0.15in}\n\n\\textbf{Problem}: Decide if they could have come from the given space.\n\n\\vspace{0.1in}\n\n\\noindent \\textbf{Model Spaces}:\n\n\\vspace{0.4in}\n\n\\noindent \\textbf{Examples}:\n\n\\vspace{0.1in}\n\n(0) 1, 2 or 3 pts with a metric can always come from $\\mathbb{R}^2$\n\n\\vspace{0.08in}\n\n(0.5) $X = \\{A_1, A_2, A_3, A_4\\}$ with\n\n\\[ d(A_i, A_j) = \\left\\{\n  \\begin{array}{l l}\n    1 & \\quad \\text{if $i=j$}\\\\\n    0 & \\quad \\text{otherwise}\n  \\end{array} \\right.\\]\n\n\\qquad can come from $\\mathbb{R}^3$ but not $\\mathbb{R}^2$\n\n\\vspace{0.08in}\n\n(1) $X = \\{O, A_1, A_2, A_3\\}$ with\n    $$d(O, A_i) = 1 \\qquad \\qquad \\forall i$$\n    $$d(A_i, A_j) = 2 \\qquad \\text{if}\\ \\ i\\neq j$$\n\n\\qquad cannot come from $\\mathbb{R}^n$. It can come from a\ntree with $O$ as center and $A_i$ as nodes.\n\n\\vspace{0.1in}\n\n\\textit{Proof}: Assume $X \\subset \\mathbb{R}^n$. Since $d(A_i, O) + d(O, A_j)= d(A_i, A_j)\\ \\\n\\forall i \\in \\{1, 2, 3\\}$.\\ $O$ must be a midpoint $A_1A_2$, $A_2A_3$, $A_3A_1$\nsimultaneously which is impossible.\n\n\\vspace{0.2in}\n\n\\noindent \\textbf{More General Arguments}:\n\n\\vspace{0.1in}\n\nGiven points $O, A_1, A_2, A_3$ and pairwise distances between them, we want\nobstructions to find these point in $\\mathbb{R}^n$ with these distances.\n\n\\begin{enumerate}\n    \\item If $O, A_1, A_2\\ \\&\\ A_3 \\in \\mathbb{R}^n$ with given distances.\n    \\begin{itemize}\n        \\item Determine angles from $\\angle A_i O A_j$ from distances using cosine rule.\n        \\item Total angle at $O$ must be $\\leq 2\\pi$\n    \\end{itemize}\n\n    \\item Consider $\\mathbb{R}^n$ as vector space with origin as $O$ and let\n    $v_i = \\overrightarrow{OA_i}$.\n    $$\\left | \\left \\langle v_i, v_i \\right \\rangle \\right | = \\left \\| v_i\n    \\right \\| ^2 = (d(O, A_i))^2 \\ \\ \\text{and} \\ \\ \\left \\| v_i - v_j \\right \\|^2 = (d(A_i, A_j))^2 $$\n\n    Hence we can calculate $\\left \\| a_1v_1 + a_2v_2 + a_3v_3 \\right \\|^2, \\\n    \\forall\\ a_1, a_2, a_3 \\in \\mathbb{R} $\n\n    \\textit{Obstruction}: These should all be positive or alternatively\n    $V = [\\left \\langle v_i, v_j \\right \\rangle]$ should be positive semi$-$definite.\n\n\\end{enumerate}\n", "meta": {"hexsha": "c113e5c2bf90994e842e1d76b26b0b7dcbd7369f", "size": 2305, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/DetectiveProblem.tex", "max_stars_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_stars_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-12-28T05:53:38.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-20T05:56:59.000Z", "max_issues_repo_path": "src/DetectiveProblem.tex", "max_issues_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_issues_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/DetectiveProblem.tex", "max_forks_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_forks_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.9350649351, "max_line_length": 103, "alphanum_fraction": 0.6377440347, "num_tokens": 880, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7160614902780923}}
{"text": "\\chapter{March}\n\n\\section{Perceptron algorithm} \\index{Perceptron algorithm}\nSuppose we have input data $(x_1, y_1), (x_2, y_2), ..., (x_n, y_n) \\in \\mathbb{R}^p \\times \\{-1, 1\\}$, \nand if the data points are separable, the perceptron algorithm works as following:\n\n\\begin{minted}[frame=lines, framesep=2mm,tabsize=4]{cpp}\nw = 0\nwhile some (x, y) is misclassified:\n    w = w + yx\n\\end{minted}\n\n\\begin{remark}\nIn the separable case, perceptron algorithm guarantees to converge.\n\\end{remark}\n\n\\myheader{Multi-class perceptron}\n\\begin{minted}[frame=lines, framesep=2mm,tabsize=4]{cpp}\nw_1 = w_2 = ... = w_k = 0\nwhile some (x, y) is misclassified:\n    for correct label y: w_y = w_y + x\n    for incorrect label y*: w_(y*)  = w_(y*) - x\n\\end{minted}\n\n\\section{Kernel function} \\index{Kernel function}\nFollowing the perceptron algorithm, suppose $\\phi$ is a function that maps $x$ to another feature space, such as $\\phi(x) = (1, x_1, x_2, ..., x_1^2, x_2^2,..., x_1 x_2,...)$, which is a quadratic embedding.\nIn this case we can also run perceptron algorithm in the new feature space. \n\n\\begin{minted}[frame=lines, framesep=2mm,tabsize=4]{cpp}\nw = 0\nwhile y*(w * \\phi(x)) < 0:\nw = w + y\\phi(x)\n\\end{minted}\n\nA problem is that every time we need to calculate $\\phi(x)$, which may be of high dimensions. To solve this problem, we observe that in fact we don't need to access $\\phi(x)$ at all to make a decision, instead we\ncan write $w$ as following:\n\\myequ{\n    w = a_1 \\phi(x_1) + a_2 \\phi(x_2) + ... + a_n \\phi(x_n)\n}\nthen $w\\cdot\\phi(x)$ is a weighted sum of $\\phi(x)\\cdot\\phi(x_i)$. In addition, we also observe that\n\\myequ{\n    \\phi(x) \\cdot \\phi(z) = (1 + x\\cdot z)^2\n}\nThat is, we don't need to calculate $\\phi(x)$.\n\n\n\\myheader{kernel function} From above we know that we don't care about the embedding $\\phi(x)$, we only \ncare about the similarity between a pair of data points. Therefore, the kernel function is defined as following:\n\\vspace{0.5cm}\n\\begin{definition}[Kernel function]\n    A function $k$: $\\mathbb{R}^p \\times \\mathbb{R}^p \\rightarrow \\mathbb{R}$ is a valid kernel if it corresponds to some embedding, that is, there exists $\\phi$ defined on $\\mathbb{R}^p$ such that\n    \\myequ{\n        k(x,z) = \\phi(x) \\cdot \\phi(z)\n        }\n\\end{definition}\n\nThis is equivalent to require that for any finite subset $\\{x_1, x_2, ..., x_m\\} \\subset \\mathbb{R}^p$,\nthe $m \\times m$ similarity matrix \n\\myequ{\n    K_{ij} = k(x_i, x_j)\n    }\nis \\textit{positive semidefinite}. Proof:\n\\myequ{\n    Z^T K Z = Z^T (X^T X) Z = (XZ)^T (XZ) \\geq 0\n    }\n\n\\myheader{RBF kernel}\nRBF kernel or Gaussian kernel is defined as\n\\myequ{\n    k(x,z) = e^{-||x-z||^2 / 2\\sigma^2}\n    }\n\n\\myheader{string kernel}\nFor each substring $s$, we define feature:\n\\myequ{\n    \\phi_s(x) &= \\# \\text{ of times substring $s$ appears in $x$} \\\\\n    \\phi(x) &= (\\phi_s(x): \\text{ all strings } s)\n    }\n\n\n\\section{$k$-means Clustering}\\index{$k$-means Clustering}\n\\myheader{$k$-means} Minimize average squared distance between points and their nearest representatives.\nThe input is data points $x_1, x_2, ..., x_n$, and integer $k$, and the output is centers\n$\\mu_1, \\mu_2, ..., \\mu_k$.\n\n\\myheader{Lloyd's $k$-means algorithm}\n\\begin{minted}[frame=lines, framesep=2mm,tabsize=4]{cpp}\nInitialize centers u_1, u_2, ... u_k in some manner.\nRepeat until convergence:\n    assign each point to its nearest center\n    update each u_j to the mean of points assigned to it\n\\end{minted}\n\n\\myheader{How to initialize centers?} $k$-means++: start with extra centers, then prune later.\n\n\\begin{lstlisting}[\nstyle=liststy,\n]\nPick a data point x at random as the first center\nLet $C = \\{x\\}$\n    Repeat until the desired number of centers is attained:\n    pick a data point $x$ at random from the following distributions: \n        $Pr(x) \\propto dist(x, C)^2$, where $dist(x, C) = min_{z\\in C}||x-z||$\n    Add $x$ to $C$\n\\end{lstlisting}\n\n\\myheader{Streaming and online computation} If there are too much data to fit in memory, or the data\nis continuously collected, we have to update the model gradually.\n\n\\myheader{The good and the bad} Good: fast and easy, effective in quantization. Bad: geared towards data in which the clusters are spherical, and of roughly the same results.\n\n\\section{Mixtures of Gaussians} \\index{Mixtures of Gaussians}\nEach of $k$ clusters is specified by a Guassian distribution $P_j = N(\\mu_i, \\sum_i)$ and a mixing weight\n$\\pi_j$. The overall distribution is a mixture of all Gaussians:\n\\myequ{\n    Pr(x) = \\pi_1 P_1(x) + \\pi_2 P_2(x) + ... + \\pi_k P_k(x)\n}\nWe need to determine all the parameters including $\\pi, \\mu, \\sum$. We apply \\textbf{EM} algorithm to solve this problem\n(see Figure~\\ref{fig:em_mar}).\n\\begin{figure}[H]\n    \\centering{\n        \\includegraphics[width=0.9\\textwidth]{./images/mar/gmm_em.PNG}\n    }\n    \\caption{EM algorithm for GMM clustering.}\n    \\label{fig:em_mar}\n\\end{figure}\n\n\\section{Hierarchical clustering} \\index{Hierarchical clustering}\nClustering is of multi-scale, and often there is no single right answer. Hierarchical \nclustering avoids these problems.\n\\begin{lstlisting}[\nstyle=liststy,\n]\nStart with each point on its own\nRepeat until there is just one cluster:\n    Merge the two clusters with the $closest$ pair of points\nDiscard singleton clusters\n\\end{lstlisting}\n\n\\myheader{Linkage method} The problem is how we measure the distance\nbetween two cluster of points.\n\\begin{enumerate}\n    \\item Single linkage: $dist(C, C') = min_{x \\in C, x' \\in C'} ||x - x'||$\n    \\item Complete linkage: $dist(C, C') = max_{x \\in C, x' \\in C'} ||x - x'||$\n    \\item Average linkage:\n        \\begin{enumerate}\n            \\item average pairwise distance between all pair of points in the two clusters\n            \\item distance between cluster centers\n            \\item Ward's method\n        \\end{enumerate}\n\\end{enumerate}\n\n\n\\section{Boosting}\n\\myheader{Adaboost} See Figure~\\ref{fig:adaboost_mar}.\n\\begin{figure}[H]\n    \\centering{\n        \\includegraphics[width=0.9\\textwidth]{./images/mar/adaboost.PNG}\n    }\n    \\caption{Adaboost algorithms.}\n    \\label{fig:adaboost_mar}\n\\end{figure}\n\n\\myheader{Bagging} See Figure~\\ref{fig:bagging_mar}\n\\begin{figure}[H]\n    \\centering{\n        \\includegraphics[width=0.9\\textwidth]{./images/mar/bagging.PNG}\n    }\n    \\caption{Bagging.}\n    \\label{fig:bagging_mar}\n\\end{figure}\n\n\n\\myheader{Random forest} See Figure~\\ref{fig:random_forest_mar}\n\\begin{figure}[H]\n    \\centering{\n        \\includegraphics[width=0.9\\textwidth]{./images/mar/random_forest.PNG}\n    }\n    \\caption{Random forests.}\n    \\label{fig:random_forest_mar}\n\\end{figure}\n\n\\section{Informative projections} \\index{Informative projections}\n\n\\myheader{Project to multiple directions} Suppose we want to project $x \\in \\mathbb{R}^p$\ninto the $k$-dimensional subspace spanned by $u_1, u_2, ..., u_k \\in \\mathbb{R}^p$, \nand suppose all $u_i$ are orthonormal (each has length one, and they are perpendicular to \neach other). Then the projection is:\n\\myequ{\n    (x \\cdot u_1)u_1 + (x \\cdot u_2)u_2 + ... + (x \\cdot u_k)u_k = UU^Tx\n}\n\n\\myheader{Best single direction} Suppose we want to map our data $x_1, x_2, ..., x_n \\in \n\\mathbb{R}^p$ into just one dimension $x \\mapsto u \\cdot x$, what is the best direction $u$.\n\nThe best direction $u$ should be the one that maximize the variance after projection. Let $X$\nbe the data matrix, where each column is a data point, and $\\sum$ be the covariance matrix of $X$. \nSuppose the mean of $X$ is $\\mu \\in \\mathbb{R}^p$, then \n\\myequ{\n    \\mathbb{E}(u^T X) & = u^T \\mathbb{E}(X) = u^T \\mu \\\\\n    var(u^T X) & = \\mathbb{E}(u^T X - u^T \\mu) = \\mathbb{E} (u^T (X - \\mu) (X - \\mu)^T u)  \\\\   \n                & = u^T \\mathbb{E}(X - \\mu)(X - \\mu)^T u = u^T \\sum u\n}\n\n\\begin{remark}\n    $u^T\\sum u$ is maximized by setting $u$ to the first \\textbf{eigenvector} of $\\sum$. The maximum\n    value is the corresponding eigenvalue.\n\\end{remark}\n\n\n\\myheader{Best $k$-dimensional projection} Let $\\sum$ be the $p\\times p$ covariance matrix of $X$. \nand $\\lambda_1 \\geq  \\lambda_2 \\geq ... \\geq \\lambda_p$ are the eigenvalues, and $u_1, u_2, ...\nu_p$ are the corresponding eigenvectors. Then the best $k$-dimensional projection directions are\n$u_1, u_2, ..., u_k$.\n\n\n\\myheader{Spectral decomposition} See Figure~\\ref{fig:spec_decomp_mar}.\n\\begin{figure}[H]\n    \\centering{\n        \\includegraphics[width=0.9\\textwidth]{./images/mar/spectral_decomp.PNG}\n    }\n    \\caption{Spectral decomposition.}\n    \\label{fig:spec_decomp_mar}\n\\end{figure}\n\n\\myheader{Singular value decomposition (SVD)} See Figure~\\ref{fig:svd_mar}. \n    Where $u_i, \\sigma_i, v_i$ comes from? We know that:\n    \\begin{itemize}\n        \\item $Mv_i = \\sigma_i u_i, M^T u_i = \\sigma_i v_i$\n        \\item $M M^T u_i = \\sigma_i^2 u_i, M^T M v_i = \\sigma_i^2 v_i$\n    \\end{itemize}\n    Therefore, $v_i$ is the eigenvectors of $M^T M$, and $u_i$ is the eigenvectors\n    of $M M^T$. $MM^T$ and $M^TM$ has the same eigenvalues $\\sigma_i^2$.  Note\n    that all $\\sigma_i$ are \\textbf{non-negative}.\n\n\\begin{figure}[H]\n    \\centering{\n        \\includegraphics[width=0.9\\textwidth]{./images/mar/SVD.PNG}\n    }\n    \\caption{Singular value decomposition.}\n    \\label{fig:svd_mar}\n\\end{figure}\n\n\\section{Positive definite matrix }\n\\vspace{0.5cm}\n\\begin{definition}[Positive definite matrix]\n    A square $p \\times p$ symmetric matrix $A$ is positive definite if for all\n    nonzero $x \\in \\mathbb{R}^p$,\n    \\myequ{\n        x^T A x > 0\n        }\n\\end{definition}\n\n\\myheader{Properties of positive definite matrix}\n\\begin{enumerate}\n    \\item The $r \\times r$ submatrix $A_r$ (start from top left element) is also positive\n    semidefinite.\n    \\item The $p$ eigenvalues of A $\\lambda_1, \\lambda_2, ..., \\lambda_p$ are positive.\n    Conversely, if all the eigenvalues of a matrix $B$ are\n    positive, then $B$ is positive definite.\n    \n    \\item There exist a unique decomposition of $A = LL^T$, where $L$ is a lower triangular\n    matrix. This is called \\textit{Cholesky Decomposition}. \n    \\item There exists a unique decomposition of $A = VDV^T$.\n    \n\\end{enumerate}\n        \n  \n\n\\section{Beyond projections} \\index{Beyond projections}\nSometimes data in a high-dimensional space $\\mathbb{R}^p$ in fact\nlies close to a $k$-dimensional manifold, for $k\\ll p$.\n\n\\myheader{ISOMAP algorithm}\nGiven data $x_1, x_2, ..., x_n$,\n\\begin{enumerate}\n\\item estimate \\textit{geodesic distances} between the data points, that is, distance along the manifold.\n\\item embed these points in Euclidean space so as to match these distances.\n\\end{enumerate}\n\n\\myheader{Geodesic distances}\nTo estimate geodesic distances:\n\\begin{enumerate}\n   \\item Construct neighborhood graph, connect nodes whenever two nodes are close together.\n   \\item Compute distance in this graph (shortest-path algorithm).  \n\\end{enumerate}\n\n\\myheader{Distance-preserving embeddings} Problem definition:\n\\begin{lstlisting}[\nstyle=liststy,] \nInput:an $n\\times n$ matrix of pairwise distances $D$, where $D_ij$ is the distance between \npoints $i$ and $j$.\nOutput: an embedding $z_1, z_2, ..., z_n \\in \\mathbb{R}^k$ that realizes these distances as closely as \npossible.\n\\end{lstlisting}\n\n\\myheader{Gram matrix}\nGram matrix on a set of vectors $z_1, z_2, ..., z_n$ is the matrix $B$ where\n$B_{ij} = z_i \\cdot z_j$.\n\n\\myheader{Classical multidimensional scaling} See Figure~\\ref{fig:cms_mar}\n\n\\begin{figure}[H]\n    \\centering{\n        \\includegraphics[width=0.9\\textwidth]{./images/mar/cms.PNG}\n    }\n    \\caption{Classical multidimensional scaling.}\n    \\label{fig:cms_mar}\n\\end{figure}\n\n\n\\section{Jacobian matrix} \\index{Jacobian matrix}\nIn vector calculus, the Jacobian matrix is the matrix of all first-order partial derivatives of a vector-valued function.\n\\myequ{\n    J  = \\frac{d \\mathbf{f}}{d \\mathbf{x}} &= \\begin{bmatrix}\n        \\frac{\\partial \\mathbf{f}}{\\partial x_1} &\n         \\frac{\\partial \\mathbf{f}}{\\partial x_2} &\n         \\dots & \\frac{\\partial \\mathbf{f}}{\\partial x_n} \n    \\end{bmatrix}    \\\\\n    & = \\begin{bmatrix}\n        \\frac{\\partial f_1}{\\partial x_1} &\n        \\dots &\n        \\frac{\\partial f_1}{\\partial x_n} \\\\\n         \\vdots & \\ddots & \\vdots \\\\\n         \\frac{\\partial f_m}{\\partial x_1}  &\n         \\dots &\n         \\frac{\\partial f_m}{\\partial x_n} \n    \\end{bmatrix}\n}\n\n\\section{Gaussian-Newton algorithm} \\index{Gaussian-Newton algorithm}\nThe Gaussian-Newton algorithm is used to solve non-linear least square problems. It is a modification\nof Newton's method for finding a minimum of a function. Unlike Newton's method, the Gaussian-Newton algorithm\ncan only be used to minimize a sum of squared function values, but it has the advantage that the second\nderivatives, which can be challenging to compute, are not required.\n\nGiven $m$ functions $r = (r_1, r_2, \\dots, r_m)$ (often called residuals) of $n$ variables $\\mathbf{\\beta} = (\\beta_1, \\dots, \\beta_n)$ with $m \\geq n$, the Gauss–Newton algorithm iteratively finds the value of the variables which minimizes the sum of squares:\n\\myequ{\n  S(\\beta) = \\sum\\limits_{i=1}^{m} r_i^2(\\beta)\n} \nStart with an initial guess $\\mathbf{\\beta}^{(0)}$, the method proceeds by the iterations:\n\\myequ{\n    \\mathbf{\\beta}^{(s+1)} = \\mathbf{\\beta}^{(s)}    - (J_r^T J_r)^{-1} J_r^T r(\\mathbf{\\beta}^{(s)})    \n}\nwhere \n\\myequ{\n    (J_r)_{ij} = \\frac{\\partial r_i(\\beta^{(s)})}{\\partial \\beta_j}\n}\nIf $m = n$, the iteration simplifies to \n\\myequ{\n    \\mathbf{\\beta}^{(s+1)} = \\mathbf{\\beta}^{(s)}    - (J_r)^{-1} r(\\mathbf{\\beta}^{(s)})\n}\n\n\n\\section{Functional programming: introductions} \\index{Functional programming: introductions}\n\n\\myheader{Why FP?}\nWe want software to be \\textit{readable, reusable, modifiable, predictable and checkable}. Functional\nprogramming could satisfy these requirements. \n\nThere is no assignment, mutation, or loop in FP.\n\n\\section{$\\lambda$-calculus}\\index{$\\lambda$-calculus}\nLambda calculus (also written as $\\lambda$-calculus) is a formal system in mathematical logic for expressing computation\n based on function abstraction and application using variable binding and substitution.\n\n\\myheader{Syntax}\nThree kinds of expressions:\n\\begin{lstlisting}[\nstyle=liststy,] \ne ::= x             \n    | $\\lambda$ x. e      \n    | $\\lambda$ e_1 e_2   \n\\end{lstlisting}\ncalled \\textit{variables}, \\textit{functions}($\\lambda$-abstraction), and \\textit{application}.\nFunctions $\\lambda x. e$ takes $x$ as an input and output $e$.\n \nApplication associates to the left: $x y z$ means $(x y) z$. However, abstraction extends as far right\nas possible:\n$\\lambda x. x \\lambda y. x y z \\Rightarrow \\lambda x. (x \\lambda y. ((x y) z))$ \n\nIdentity function: $I = \\lambda x. x$\n\n\\myheader{Scope of identifier (variable)}\nScope of a variable is the part of program where the variable is \\textit{accessible}.\n\n$\\lambda x. E$ binds variable $x$ in $E$:\n\\begin{enumerate}\n    \\item $x$ is the newly introduced varialbe.\n    \\item $E$ is the scope of $x$.\n    \\item $x$ is bound in $\\lambda x. E$\n\\end{enumerate}\n\n$y$ is \\textit{free} if it occurs not bound in $E$:\n\\begin{enumerate}\n    \\item $Free(x) = \\{x\\}$\n    \\item $Free(E_1 E_2) = Free(E_1) \\cup Free(E_2)$ \n    \\item $Free(\\lambda x. E) = Free(E) - \\{x\\}$\n\\end{enumerate}\n\n$\\alpha$-renaming:\n\\begin{enumerate}\n    \\item Allows bound variable names to be changed.\n    \\item $\\lambda x. x = \\lambda y. y$\n\\end{enumerate}\n\nsubstitution:\n\\begin{enumerate}\n    \\item $[E'/x]E$: use $E'$ to substitute all $x$ bounded in $E$\n    \\item $[y (\\lambda x. x)/x] \\lambda y. (\\lambda x. x) y x\n           \\equiv$\n           $[y (\\lambda v. v)/x] \\lambda y. (\\lambda u. u) z x $ (renaming)\n           $\\equiv \\lambda z. (\\lambda u. u) z (y (\\lambda v. v))$ (substitution) \n\\end{enumerate}\n\n$\\beta$-reduction:\n\\begin{enumerate}\n    \\item $\\beta$-reduction captures the idea of function application.\n    \\item $(\\lambda x. e) e' \\rightarrow [e'/x]e$\n    \\item $((\\lambda n. n\\times2) 7) \\rightarrow 7\\times 2$\n\\end{enumerate}\n\nlocal variable:\n\\begin{lstlisting}[\nstyle=liststy,] \nlet x = $e_1$ in $e_2$\n$\\equiv (\\lambda x. e_2) e_1$\n\\end{lstlisting}\n\nboolean:\n\\begin{lstlisting}[\nstyle=liststy,] \ntrue $\\equiv$ $\\lambda x. \\lambda y. x$\nfalse $\\equiv$ $\\lambda x. \\lambda y. y$\nif $E_1$ then $E_2$ else $E_3$ $\\equiv$ $E_1 E_2 E_3$\nif true then u else v $\\rightarrow$ $(\\lambda x. \\lambda y. x) u\\ v  \\rightarrow (\\lambda  y. u) \\rightarrow u$  \n\\end{lstlisting}\n\nnot:\n\\begin{lstlisting}[\nstyle=liststy,]\nfunction takes b:\n    return function x, y:\n        return (if b then y else x)\n\nnot $\\equiv \\lambda b. (\\lambda x. \\lambda y. \\  b\\ y\\ x)$\nnot true $\\rightarrow \\lambda x. \\lambda y. \\ true \\ y \\ x \\rightarrow \\lambda x. \\lambda y. \\ y \\rightarrow false$ \n\\end{lstlisting}\n\nor:\n\\begin{lstlisting}[\nstyle=liststy,] \nfunction takes $b_1, b_2$\n    return function takes x, y:\n        return (if $b_1$ then x else (if $b_2$ then x else y))\nor $\\equiv \\lambda b_1 . \\lambda b_2 . (\\lambda x. \\lambda y.\\ b_1\\ x (b_2 \\ x \\ y))$  \n\\end{lstlisting}\n\nrecords:\n\\begin{lstlisting}[\nstyle=liststy,] \npair = function takes a bool\n       return the left or right element\nmkpair $e_1 \\ e_2 \\equiv \\lambda b. \\ b\\ e_1\\ e_2$  \nfst p $\\equiv$ p true\nsnd p $\\equiv$ p false\n\\end{lstlisting}\n\nnatural numbers:\n\\begin{lstlisting}[\nstyle=liststy,] \nnatural number: iterate a number of times over some function\n$n$ = function that takes function $f$, starting value $s$\n      returns: $f$ applied to $s$ $n$ times\n$0 \\equiv \\lambda f. \\lambda s. \\ s$\n$1 \\equiv \\lambda f. \\lambda s. \\ f \\ s$\n$2 \\equiv \\lambda f. \\lambda s. \\ f (f \\ s)$\n(n f s) = apply f to s n times\n\\end{lstlisting}\n\noperations on natural numbers:\n\\begin{lstlisting}[\nstyle=liststy,] \niszero n $\\Leftrightarrow$ n ($\\lambda$ b. false) true\niszero $\\Leftrightarrow$ $\\lambda $ n. ($\\lambda$ b. false) true\nsucc n  $\\Leftrightarrow$ $\\lambda$f. $\\lambda$s. f (n f s)\nadd a b $\\Leftrightarrow$ a succ b\nmulti a b $\\Leftrightarrow$ a (add b) 0\n\\end{lstlisting}\n\n\n\\section{Haskell: basics}\\index{Haskell: basics}\nHaskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing.\n\n\\myheader{GHC system}\n\\begin{lstlisting}[\nstyle=liststy,\nlanguage=Haskell,]\n:load foo.hs\n:type expression\n:info variable\n\\end{lstlisting}\n\n\\myheader{Basic types}\n\\begin{haskellcode}\n32   :: Integer\n4.2  :: Double\n'a'  :: Char\nTrue :: Bool\n\n-- function types\npos :: Integer -> Bool\npos x = (x > 0)\n\n-- multiple argument function types\n-- function takes args of A1, A2, A3, gives out B\nA1 -> A2 -> A3 -> B\n\n-- tuples, elements do not have to be of the same type\n(A1, ..., An)\n-- pattern matching extracts values from tuple\npat :: (Int, Int, Int) -> Int\npat (x, y, z) = x * (y + z)\n\n-- Lists, elements have to be of the same type\n[1, 3, 5, 7]\n-- construct lists\n'a' : ['b', 'c'] = ['a', 'b', 'c']\ncons2 x y zs = x : y : zs\n\n-- type\n-- Not a new type, just shorthand\ntype XY = (Double, Double)\ntype Circle = (Double, Double, Double)\n-- data creates new types\ndata CircleT = Circle (Double, Double, Double)\ndata Shape =\n    | Rectangle Side Side\n    | Ellipse Radius Radius\n    | RtTriangle Side Side\n    | Polygon [Vertex]\ntype Side = Double\ntype Radius = Double\ntype Vertex = (Double, Double)\n\\end{haskellcode}\n\n\n\\myheader{Input and output}\n\n\\begin{haskellcode}\n-- action: value describing an effect on world\nIO a -- type of an action that returns an a\n\n-- takes input string, return action that writes string to stdout\nputStr :: String -> IO () \n\n-- only one way to execute action: make it the value of name main\nmain :: IO ()\nmain = putStr \"hello world\\n\"\n\n-- do many actions with 'do'\ndo putStr \"Hello\"\n   putStr \"World\"\n   putStr \"\\n\"\n   \n-- input\ngetLine :: IO String\nmain:: IO()\nmain = do putStr \"What is your name?\"\n       n <- getLine -- assignment\n       putStrLn (\"Happy New Year \" ++ n)\n\\end{haskellcode}\n\n\n\\section{Haskell: higher-order functions}\\index{Haskell: higher-order functions}\nIn all functional languages, functions are first-class values, meaning, that they can be treated just as you would any other data. That is, you can pass functions around to in any manner that you can pass any other data around in.\n\n\\myheader{Functions are data}\n\\begin{haskellcode}\nplus1 :: Int -> Int\nplus1 x = x + 1\n\nminus1 :: Int -> Int\nminus1 x = x - 1\n\nfunp :: (Int -> Int, Int -> Int)\nfunp = (plus1, minus1)\n\\end{haskellcode}\n\n\\myheader{Take functions as input and output}\n\\begin{haskellcode}\n-- functions as input\ndoTwice :: (t -> t) -> t -> t\ndoTwice f x = f (f x)\n\n-- functions as output\nplusn :: Int -> (Int -> Int)\nplusn n = f\n          where f x = x + n\n\n-- partially apply functions\nplus :: Int -> Int -> Int\nplus a b = a + b\nplus5 :: Int -> Int\nplus5 = plus 5 -- plus5 1000 outputs 1005\n\\end{haskellcode}\n\n\\myheader{Anonymous functions}\nWe will see many situations where a particular function is only used once, and hence, \nthere is no need to explicitly name it. Haskell provides a mechanism to create such anonymous functions.\n\n\\begin{haskellcode}\n\\x -> x + 1\n(\\x -> x + 1) 100 -- 101\ndoTwice (\\x -> x + 1) 100 -- 102\n\\end{haskellcode}\n\n\\myheader{Infix operations}\nHaskell allows you to use any function as an infix operator,\nsimply by wrapping it inside backticks.\n\nTo further improve readability, Haskell allows you to use partially applied infix operators, ie infix operators with only a single argument. These are called \\textit{sections}.\n\\begin{haskellcode}\n2 `plus` 4 -- 6\ndoTwice (+1) 0 -- 2\ndoTwice (1+) 0 -- 2\ndoTwice (1:) [2..5] -- [1, 1, 2, 3, 4, 5]\n\\end{haskellcode}\n\n\\myheader{Polymorphism}\n\\textit{doTwice} is polymorphic in that it works with different kinds of values, \ne.g. functions that increment integers and concatenate strings. This is vital for \\textit{abstraction}.\n\nPolymorphic functions which can operate on different kinds values are often associated with polymorphic \ndata structures which can contain different kinds of values. \nThese are also represented by types containing type variables.\n\n\\begin{haskellcode}\nfoo :: a -> (a -> b) -> b\nfoo x f = f x\n\nx |> f = f x\n\ndo1 :: (a -> b) -> a -> b\ndo1 f x = x |> f\n\ndo2 :: (a -> a) -> a -> a\ndo2 f x = x |> f |> f\n\\end{haskellcode}\n\n\\myheader{Bottling Computation Patterns With Polymorphic Higher-Order Functions}\n\n\\begin{haskellcode}\ntoUpperString :: String -> String\ntoUpperString [] = []\ntoUpperString (c:cs) = toUpper c : toUpperString cs\n\n-- map\nmap :: (a -> b) -> [a] -> [b]\nmap f [] = []\nmap f (x:xs) = (f x) : (map f xs)\n\ntoUpperString = map toUpper\n\n-- foldr\nfoldr op base [] = base\nfoldr op base (x:xs) = x `op` (foldr op base xs)\n\n-- foldr on actions\nfuseActions :: [IO ()] -> IO ()\nfuseActions []        = return ()\nfuseActions (a1:acts) = do a1\n                           fuseActions acts\n\nfuseActions :: [IO ()] -> IO ()\nfuseActions = foldr (>>) (return ())\n\\end{haskellcode}\n\n\\section{Higher-order programming} \\index{Higher-order programming}\n\n\\myheader{Recursive types}\n\\begin{haskellcode}\ndata Shape  = Rectangle Double Double \n            | Polygon [(Double, Double)]\n\ndata IntTree = ILeaf Int\n             | INode IntTree IntTree\n\\end{haskellcode}\n\n\\myheader{Parameterized types}\n\n\\begin{haskellcode}\n-- a is a type\ndata List a = Empty\n            | OneAndMore a (List a)\n\ndata Tree a = Leaf a\n            | Node (Tree a) (Tree a)\n\ntype IntList = List Int\ntype CharList = List Char\ntype DoubleList = List Double\n\\end{haskellcode}\n\n\\myheader{Kinds}\nIn the area of mathematical logic and computer science known as type theory, \na kind is the type of a type constructor or, less commonly, the type of a higher-order type operator. \n\nThe \\textit{Tree a} corresponds to trees of values of type a. \nIf a is the type parameter, then what is Tree ? \nA function that takes a type a as input and returns a type Tree a as output! \nBut wait, if List is a function then what is its type? A \\textit{kind} is the type of a type.\n\n\\begin{haskellcode}\n:kind Int -- *\n:kind Char -- *\n:kind Bool -- * -> *\n:kind (->) -- * -> * -> *\n\\end{haskellcode}\n\n\\begin{enumerate}\n    \\item *: the kind of all data types seen as nullary type constructors, \n    and also called proper types in this context.\n    \\item * -> * : the kind of a unary type constructor, e.g. list type constructor.\n    \\item * -> * -> * : the kind of a binary type constructor (via currying), e.g. of \n             a pair type constructor  and also that of a function type constructor.\n    \\item (* -> *) -> *: the kind of a higher-order type operator from unary type constructors to proper types.\n\\end{enumerate}\n\n\n\\section{Haskell: typeclass}\\index{Haskell: typeclass}\nWe want the operator such as $+$ to work for a bunch of different data types\nsuch as integers, doubles. So what should be the type of $+$?\n\n\\begin{haskellcode}\n-- too anemic\n(+) :: Integer -> Integer -> Integer\n-- too aggressive, it doesn’t make sense to add two functions\n(+) :: a -> a -> a\n\\end{haskellcode}\n\nHaskell solves this problem with an insanely slick mechanism called typeclasses.\n\n\\myheader{Qualified types}\n\\begin{haskellcode}\n-- truth\n(+) :: (Num a) => a -> a -> a\n\\end{haskellcode}\nWe call the above a qualified type. Read it as, $+$ takes in two a values and returns an a value \nfor any type a that is a Num or is an instance of Num.\n\nThe name Num can be thought of as a predicate over types. \nSome types satisfy the Num predicate. Examples include Integer, Double etc, and any values of those types can be passed to +. \nOther types do not satisfy the predicate. Examples include Char, String, functions etc, and \nso values of those types cannot be passed to +.\n\n\\myheader{Typeclass}\nA \\textit{typeclass} is a collection of operations (functions) that must exist for the underlying type.\n\nA typeclass defines some behavior (like comparing for equality, comparing for ordering, enumeration) and then types that can behave in that way are made instances of that typeclass. The behavior of typeclasses is achieved by defining functions or just type declarations that we then implement. So when we say that a type is an instance of a typeclass, we mean that we can use the functions that the typeclass defines with that type.\n\n\n\n\n\\begin{haskellcode}\n-- typeclass Eq\nclass  Eq a  where\n  (==) :: a -> a -> Bool\n  (/=) :: a -> a -> Bool\n\n-- typeclass show\nclass  Show a  where\n  show :: a -> String\n\\end{haskellcode}\nA type a can be an instance of Eq as long as there are two functions \nthat determine if two a values are respectively equal or disequal. \nSimilarly, the typeclass Show captures the requirements that make a particular datatype be viewable,\n\n\\myheader{Automatic derivation}\nHaskell allows us automatically derive functions for certain key type classes, namely those in the standard library.\n\\begin{haskellcode}\ndata Showable = A' | B' | C' deriving (Eq, Show)\n\nclass (Eq a, Show a) => Num a where\n    (+) :: a -> a -> a\n    (*) :: a -> a -> a\n    (-) :: a -> a -> a\n    negate :: a -> a\n    abs :: a -> a\n    signum :: a -> a\n    fromInteger :: Integer -> a\n-- A type T can only be deemed an instance of Num if\n--     1. The type is also an instance of Eq and Show, and\n--     2. There are functions for adding, multiplying, etc\n\\end{haskellcode}\n\n\\myheader{Explicit signatures}\nWhile Haskell is pretty good about inferring types in general, \nthere are cases when the use of type classes requires explicit annotations.\n\\begin{haskellcode}\n-- Read is a build typeclass, parse a string and turn it into an a\nread:: (Read a) => String -> a\n\n-- read \"2\" -- error: it doesn’t know what to convert the string to\n-- (read \"2\") :: Int -- correct\n-- (read \"2\") :: Double -- correct\n\\end{haskellcode}\n\n\n\\section{Haskell: monads}\\index{Haskell: monads}\nThe function programming community divides into two camps:\n\\begin{enumerate}\n    \\item \"Pure\" languages, such as Haskell, are based directly upon the \n    mathematical notion of a function as a mapping from arguments to \n    results.\n\n    \\item \"Impure\" languages, such as ML, are based upon the extension of this notion with a range of possible effects, such as exceptions and assignments.\n\\end{enumerate}\nPure languages are easier to reason about and may benefit from lazy\nevaluation, while impure languages may be more efficient \nand can lead to shorter programs.\n\n\\subsection{Abstracting programming patterns}\nMonads are an example of the idea of abstracting out a common \nprogramming pattern as a definition. \n\n\\begin{haskellcode}\ninc :: [Int] -> [Int]\ninc []     =  []\ninc (n:ns) =  n+1 : inc ns\n\nsqr :: [Int] -> [Int]\nsqr []     =  []\nsqr (n:ns) =  n^2 : sqr ns\n\n-- above functions have the same programming pattern, \n-- namely mapping the empty list to itself, and a non-empty \n-- list to some function applied to each element in the list\n\n-- abstract this pattern gives us the map function\nmap         :: (a -> b) -> [a] -> [b]\nmap f []     = []\nmap f (x:xs) = f x : map f xs\n\ninc = map (+1)\nsqr = map (^2)\n\\end{haskellcode}\n\n\\myheader{Maybe}\nThe \\texttt{Maybe} type encapsulates an optional value.\nA value of type \\texttt{Maybe a} either \ncontains a value of type \\texttt{a} (represented as \\text{Just a}), \nor it is empty \n(represented as \\texttt{Nothing}). \nUsing \\texttt{Maybe} is a good way to deal with errors or \nexceptional cases without resorting to drastic measures such as error.\n\n\n\\begin{haskellcode}\ndata Maybe a = Just a | Nothing\n\nfoo :: (a -> b) -> Maybe a -> Maybe b\nfoo f z = case z of \n            Just x  -> Just (f x)\n            Nothing -> Nothing \n\\end{haskellcode}\n\n\\myheader{Functor typeclass}\nFunctor typeclass is basically for things that can be mapped over. \n\\begin{haskellcode}\nclass Functor f where  \n    fmap :: (a -> b) -> f a -> f b\n\n-- map is just a map that works on lists\ninstance Functor [] where\n    fmap = map\n\n-- Maybe is also a functor\ninstance Functor Maybe where\n    fmap f (Just x) = Just (f x)\n    fmap f Nothing = Nothing\n\n-- make Tree type instance of Functor\ninstance Functor Tree where\n    fmap f EmptyTree = EmptyTree\n    fmap f (Node x left right) = Node (f x) \n           (fmap f left) (fmap f right)\n\n-- IO is an instance of Functor\ninstance Functor IO where\n    fmap f action = do\n        results <- action\n        return (f result)\n\n-- <-: bind that result to a name\nresult <- getLine\n\n-- return: a function that makes an I/O action that doesn't do \n--         anything but only presents something as its result\n\n\\end{haskellcode}\n\n\n\\myheader{Generalize map to many arguments}\nWe can generalize map to many arguments.\n\\begin{haskellcode}\nlift1 :: (a -> b) -> [a] -> [b]\nlift2 :: (a1 -> a2 -> b) -> [a1] -> [a2] -> [b]\nlift3 :: (a1 -> a2 -> a3 -> b) -> [a1] -> [a2] -> [a3] -> [b]\n\\end{haskellcode}\n\nThere is a typeclass called \\texttt{Applicative} that corresponds to \nthe type constructors that you can \\texttt{lift2} or \\texttt{lift3} over.\n\n\\begin{haskellcode}\nliftA  :: Applicative t => (a -> b) -> t a -> t b\n\nliftA2 :: Applicative t \n       => (a1 -> a2 -> b) \n       -> t a1 \n       -> t a2 \n       -> t b\n\nliftA3 :: Applicative t \n       => (a1 -> a2 -> a3 -> b) \n       -> t a1 \n       -> t a2\n       -> t a3\n       -> t b\n\\end{haskellcode}   \n\n\n\\myheader{Sequencing operator}\nHere we introduce a new sequencing operator that we write as \n\\texttt{>>=}, and read as \\textit{then}.\n\n\\begin{haskellcode}\n(>>=)   :: Maybe a -> (a -> Maybe b) -> Maybe b\nm >>= f =  case m of\n             Nothing -> Nothing\n             Just x  -> f x\n\n-- evaluate each of the expression m1, m2, ..., mn in turn,\n-- and combine their results x1, x2, ..., xn by applying \n-- the function f\nm1 >>= \\x1 ->\n  m2 >>= \\x2 ->\n  ...\n    mn >>= \\xn ->\n      f x1 x2 ... xn\n\\end{haskellcode}\n\n\\section{To add}", "meta": {"hexsha": "4ca84d1ae09fb6000fb124569c0f3b2d9e5e9db1", "size": 31521, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mar.tex", "max_stars_repo_name": "soundsilence/DailyNotes", "max_stars_repo_head_hexsha": "561ad833b3d7824699847bc3e933e7da05889463", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-11T08:56:57.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-11T08:56:57.000Z", "max_issues_repo_path": "tex/mar.tex", "max_issues_repo_name": "soundsilence/DailyNotes", "max_issues_repo_head_hexsha": "561ad833b3d7824699847bc3e933e7da05889463", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/mar.tex", "max_forks_repo_name": "soundsilence/DailyNotes", "max_forks_repo_head_hexsha": "561ad833b3d7824699847bc3e933e7da05889463", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.0755508919, "max_line_length": 432, "alphanum_fraction": 0.6743440881, "num_tokens": 9572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.7160614855215481}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{makeidx}\n\\usepackage{graphicx}\n\\usepackage[all]{xy}\n\n\\newtheorem{defi}{Definition}\n\\newtheorem{lemm}{Lemma}\n\\newcommand{\\bws}{\\paragraph{Proof}}\n\\author{moi}\n\\begin{document}\n\\section{Groups and heaps}\nWe intend to discuss the concept of groups and heaps which are closely related. As convention, we use\n$$\\underbrace{X \\times \\ldots \\times X}_{n-\\mathrm{times}} = X^n,\\ \\forall n \\in \\mathbb{N}.$$\n\\subsection{Definitions}\nFor the sake of completeness, we are going to repeat the definition for semi groups, monoids and groups.\n\\begin{defi}\nA set $S$ with a binary map $m : S^2 \\longrightarrow S$ is called a semi group if $\\mathrm{im}(m) \\subset S$ and the following diagram\n$$\\xymatrix{S^3 \\ar[r]^{id \\times m}\\ar[d]_{m \\times id} & S^2\\ar[d]^m\\\\\nS^2 \\ar[r]_m &S\\\\\n}$$\ncommutes. We call $m$ the operations or sometimes incorrectly the multiplication and denote a semi group as a pair $(S,m)$. A subset $T \\subset S$ is called a sub semi group if both conditions hold for the restriction $m \\mid_{T^2} : T^2 \\longrightarrow T$. \n\\end{defi}\nThe first condition is called closeness - the latter is called the associativity. \n\\begin{defi}\nWe call a semi group $(M,m)$ a monoid if $M$ has a sub semi group, usually denoted by $\\{\\ast\\}$, with exactly one element such that\n$$\\xymatrix{\n\\{\\ast\\} \\times G \n}$$\nThis distinguished element $e \\in \\{\\ast\\}$ is called the neutral element and induces a map\n$$\n\\end{defi}\n\\begin{defi}\nLet $X$ be a set. We call a pair $(X, h)$, with $h : X^3 \\longrightarrow X$ a terniar operation, a heap if the following diagrams commute:\n$$\\begin{array}{c}\n\\xymatrix{\n&&&X^5 \\ar[rrrd]^{id_{X^2} \\times h}\\ar[llld]_{h \\times id_{X^2}} \\ar[dd]_{id_{X} \\times \\tau_3 \\times id_X}&&& \\\\\nX^3\\ar[rrrddd]_{h}&&&&&&X^3\\ar[lllddd]^{h}\\\\\n&&&X^5 \\ar[d]_{id_X \\times h \\times id_X}&&&\\\\\n&&&X^3\\ar[d]_h&&&\\\\\n&&&X&&&\\\\\n}\\\\\n\\mathrm{para-associativity}\\\\\n\\end{array}$$$$\n\\begin{array}{c}\n\\xymatrix{\n&&&X^2\\ar[llld]_{\\Delta \\times id_X \\circ \\tau} \\ar[ldd]_{\\Delta \\times id_X \\circ \\tau} \\ar[ddd]^{\\pi_1}_{\\pi_2 \\circ \\tau}\\ar[rdd]^{id_X \\times \\Delta}\\ar[rrrd]^{id_X \\times \\Delta} &&&\\\\\nX^3\\ar[d]_{\\tau_3}&&&&&& X^3\\ar[d]^{\\tau_3}\\\\\nX^3\\ar[rrrd]_h&&X^3\\ar[rd]_h&&X^3\\ar[ld]^{h}& &X^3\\ar[llld]^{h}\\\\\n&&&X&&&\\\\\n}\\\\\n\\mathrm{identity,}\\\\\n\\end{array}\n$$\nwhere\n$$\\begin{array}{rrclcrrcl}\n\\Delta : &X& \\longrightarrow &X^2,&&\\tau_3 : &X^3& \\longrightarrow& X^3\\\\\n&x&\\longmapsto&(x,x)&&&(x,y,z)&\\longmapsto&(z,y,x)\\\\\n&&&\\\\\n\\pi_1:&X^2&\\longrightarrow&X&&\\pi_2:&X^2&\\longrightarrow&X\\\\\n&(x,y)&\\longmapsto&x&&\n&(x,y)&\\longmapsto&y\\\\\n&&&\\\\\n\\tau :& X^2 &\\longrightarrow&X^2\\\\\n&(x,y)&\\longmapsto&(y,x)\\\\\n\\end{array}$$\n\\end{defi}\nFirstly, we obviously have $\\tau_3 = (id \\times \\tau)\\circ(\\tau \\times id) \\circ (id \\times \\tau)$ and $\\pi_2 \\tau = \\pi_1$. Secondly, the projections $\\pi_i$ are tighed to the left or right side of the diagram. Furthermore, we remark that heaps can be thought of as groups with no unique neutral element, i.e. we forgot to a assign a neutral element. One can easily check that each group $(G, m, e, inv)$ is a heap via\n$$h = m \\circ (id_G \\times m)\\circ (id_G \\times inv \\times id_G) = m \\circ (m \\times id_G)\\circ(id_G \\times inv \\times id_G).$$\nConversely, each heap $(G, h)$ has a unique group structure modulo a distinguished element $e \\in G$ being the neutral element. We subsequently get the group morphisms:\n$$m = h\\mid_{G \\times \\{e\\} \\times G} : G^2 \\longrightarrow G,\\ (g,g') \\longmapsto h(g,e,g'),$$\n$$e : \\{\\ast\\} \\longrightarrow G,\\ \\ast \\longmapsto e.$$\nTo be more precise, the first statement shall be read via the identification induced by the map\n$$id_G \\times f_e \\times id_G : G^3 \\longrightarrow G^2,\\ (g, g'', g') \\longmapsto (g, e, g').$$\nThe equivalence classes are\n$$\\mathcal{G} := \\left\\{[(g,g')] \\subset G^3: (g,g'',g') \\in [(g,g')] \\forall g'' \\in G\\right\\}$$ \nWe claim\n\\begin{lemm}\nThe set of equivalence classes $\\mathcal{G}$ is isomorphic to $G^2$.\n\\end{lemm}\n\\bws This is obvious if we consider\n$$\\iota_{G^2} : G^2 \\longrightarrow G^3,\\ (g,g') \\longmapsto (g,e,g')$$\nis a monomorphism and therefore we have $\\mathrm{im} \\pi \\iota_{G^2} \\simeq \\mathcal{G}$.\\\\\nThe inverse is given via\n$$m(g,g') = e \\Leftrightarrow g' \\in m\\mid_{\\{g\\}\\times G}^{-1}(e) = \\{g'' \\in G: m(g,g'') = e\\}$$\n%$$G \\times \\{e\\} \\times G/\n\\end{document}", "meta": {"hexsha": "8b34671d43d32c7f90792b181f41382ec2b47770", "size": 4428, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "heaps/heaps.tex", "max_stars_repo_name": "gmuel/texlib", "max_stars_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "heaps/heaps.tex", "max_issues_repo_name": "gmuel/texlib", "max_issues_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "heaps/heaps.tex", "max_forks_repo_name": "gmuel/texlib", "max_forks_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.2, "max_line_length": 419, "alphanum_fraction": 0.6596657633, "num_tokens": 1654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7160614760084594}}
{"text": "\\section{Displacement interpolation}\n\\label{iso_section:interpolation}\n\\paragraph{}\nAnother difference between it with conventional FEM or SBFEM lies in the post processing.\nAfter solving the partial differential equation numerically, the displacements on the nodes will be one of the output in\n    the traditional method.\nHowever, similar to what is discussed in \\ref{iso_section:surface_traction}, NURBS curves are defined by the control points\n    that are not geometrically located on the curves.\nAs a consequence, not only the input such as surface traction need to be translated into a NURBS-like representation, the\n    output such as the displacements will be the dummy values on the control points as well, or ``control displacements''\n    $\\left\\{ u_c \\right\\}$.\nDislike that in the traditional method, the ``control displacements'' do not have any physical meaning. It can only be used\n    to interpolate the real displacements within its span.\n\n\\begin{equation}\n    \\left\\{ u \\right\\}=\n    \\sum_{i=0}^n\n    R(u) \\left\\{u^{(N)}\\right\\}\n\\label{iso_eq:displacement_interpolation}\n\\end{equation}\n", "meta": {"hexsha": "f566856a0b0461757cc5dc2ff4c4e1bacb1315b8", "size": 1104, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "isogeometric_sbfem/sbfem_displacement_interpolation.tex", "max_stars_repo_name": "fa93hws/thesis", "max_stars_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-30T12:14:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-30T12:14:47.000Z", "max_issues_repo_path": "isogeometric_sbfem/sbfem_displacement_interpolation.tex", "max_issues_repo_name": "fa93hws/thesis", "max_issues_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "isogeometric_sbfem/sbfem_displacement_interpolation.tex", "max_forks_repo_name": "fa93hws/thesis", "max_forks_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.5714285714, "max_line_length": 123, "alphanum_fraction": 0.7690217391, "num_tokens": 268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.8175744806385542, "lm_q1q2_score": 0.7160210868947933}}
{"text": "\\documentclass[10pt]{article}\n\\usepackage[usenames]{color} %used for font color\n\\usepackage{amssymb} %maths\n\\usepackage{amsmath} %maths\n\\usepackage[utf8]{inputenc} %useful to type directly diacritic characters\n\n\\usepackage{geometry}\n \\geometry{\n a4paper,\n total={210mm,297mm},\n left=20mm,\n right=20mm,\n top=15mm,\n bottom=15mm,\n }\n\n\n\\begin{document}\n\\noindent Considering a simpler Langevin dynamics under the foloowing equations\n\\begin{align*}\n  \\begin{cases}\n    \\dot{x}&=v \\\\\n    \\dot{v}&=\\frac{F(x)}{m}-\\gamma v+\\frac{\\xi(t)}{m}\n  \\end{cases}\n\\end{align*}\nwhere $(x,v)$ are position and velocity. $F(x)=-\\partial_x U(x)$ which is the position-dependent force. The $m$, $\\gamma$ are mass and friction coefficient. The $\\xi(t)$ represents randomness defines the Wiener noise in the Ito convention:\n\\begin{align*}\n\\langle\\xi(t)\\xi(t')\\rangle=\\frac{2m\\gamma}{\\beta}\\langle dW_tdW_{t'}\\rangle=\\frac{2m\\gamma}{\\beta}\\delta(t-t')\n\\end{align*}\nThis equation describes a dynamics equivalent to an evolution of probability density f(x,v;t) through Fokker-Planck equation:\n\\begin{align*}\n\\frac{\\partial f(x,v;t)}{\\partial t}=-\\hat{L}f(x,v;t)\n\\end{align*}\nwhere\n\\begin{align*}\n\\hat{L}\\equiv\\frac{F(x)}{m}\\frac{\\partial}{\\partial v}+v\\frac{\\partial}{\\partial x}-\\gamma\\left(\\frac{\\partial}{\\partial v}v+\\frac{1}{m\\beta}\\frac{\\partial^2}{\\partial v^2}\\right)\n\\end{align*}\nThe probabaility density f evolves through\n\\begin{align*}\nf(x,v, t+\\Delta t)=e^{-\\Delta t\\hat{L}}f(x,v;t)\n\\end{align*}\nThe operator $\\hat{L}$ is separated into three parts, and the interation is approximated through Lie-Trotter formula,\n\\begin{align*}\ne^{-\\Delta t\\hat{L}}&\\approx e^{-\\Delta t\\hat{L}_x}e^{-\\Delta t\\hat{L}_v}e^{-\\Delta t\\hat{L}_{\\gamma}} \\\\\n&\\approx e^{-(\\Delta t/2)\\hat{L}_{\\gamma}}e^{-(\\Delta t/2)\\hat{L}_v}e^{-(\\Delta t/2)\\hat{L}_x}e^{-(\\Delta t/2)\\hat{L}_x}e^{-(\\Delta t/2)\\hat{L}_v}e^{-(\\Delta t/2)\\hat{L}_{\\gamma}}\n\\end{align*}\nwhere\n\\begin{align*}\n\\hat{L}_x&=v\\frac{\\partial}{\\partial x} \\\\\n\\hat{L}_v&=\\frac{F(x)}{m}\\frac{\\partial}{\\partial v} \\\\\n\\hat{L}_{\\gamma}&=-\\gamma\\left(\\frac{\\partial}{\\partial v}v+\\frac{1}{m\\beta}\\frac{\\partial^2}{\\partial v^2}\\right)\n\\end{align*}\nThe integration can then be taken into two parts.\n\\subsubsection*{I. $\\hat{L}_{\\gamma}$ - Diffusion in momentum space}\nThis first part is a diffusion in momentum space\n\\begin{align*}\nf(v^{+}\\equiv v(t^{+}), t^{+})=e^{-(\\Delta t/2)\\hat{L}_{\\gamma}}f(v,t)\n\\end{align*}\nwhich corresponds to the evolution of $f$\n\\begin{align*}\n\\frac{\\partial f}{\\partial t}=-\\frac{\\hat{L}_{\\gamma}}{2}f=\\frac{\\gamma}{2}\\left[\\frac{\\partial }{\\partial v}(vf)+\\frac{1}{m\\beta}\\frac{\\partial^2 f}{\\partial v^2}\\right]\n\\end{align*}\nwhich has a solution [``The Fokker-Planck Equation Second Edition\", H. Risken] of\n\\begin{align*}\nf(v^{+}, t^{+}|v,t)\\propto\\exp\\left[-\\frac{m\\beta}{2} \\frac{\\left(v^{+}-v e^{-\\frac{\\gamma}{2}\\Delta t}\\right)^2}{1-e^{-\\gamma\\Delta t}} \\right]=\\exp\\left[ -\\frac{1}{2}\\left(\\frac{v^{+}-\\mu_v}{\\sigma_v}\\right)^2 \\right]\n\\end{align*}\nThis step can then be performed by sampling from a Normal distribution $N(\\mu_v, \\sigma_v)$,\n\\begin{align*}\nv(t^{+})&\\sim N(\\mu_v, \\sigma_v) \\\\\n&=\\mu_v+\\sigma_v N(0,1) \\\\\n&=v(t)e^{-\\frac{\\gamma}{2}\\Delta t}+\\sqrt{ \\frac{1}{m\\beta}\\left(1-e^{-\\gamma\\Delta t}\\right) } N(0,1) \\\\\n&=c_1 v(t)+c_2 N(0,1)\n\\end{align*}\n\\subsubsection*{I. $(\\hat{L}_x, \\hat{L}_v)$ - Deterministic canonical transformation in phase space}\nBoth $\\hat{L}_v$ and $\\hat{L}_x$ are deterministic canonical transformation in phase space.  Applying $f(v',t')=f(v(t+\\Delta t), t+\\Delta t)=e^{-(\\Delta t/2)\\hat{L}_v}f(v(t),t)$, and observing that by doing the transformation $p=t+\\frac{F(x)}{2m}v$ and $q=\\frac{F(x)}{2m}t-v$, we have\n\\begin{align*}\n\\frac{\\partial f}{\\partial t}+\\frac{F(x)}{2m}\\frac{\\partial f}{\\partial v}=\\left[1+\\left(\\frac{F(x)}{2m}\\right)^2\\right] \\left.\\frac{\\partial f}{\\partial p}\\right|_q=0\n\\end{align*}\nThe solution is then $f(v,t)=f(q)=f(\\frac{F(x)}{2m}t-v)$. With the boundary condition $v(0)=v$, the solution must be a delta function\n\\begin{align*}\nf(v,t)&=f(\\frac{F(x)}{2m}t-v)=\\delta(\\frac{F(x)}{2m}t-v) \\\\\n\\Delta v&=\\frac{F(x)}{2m}\\Delta t\n\\end{align*}\nSimilarly, the operation of $\\hat{L}_x$ during $\\Delta t/2$ is equivalent to $\\Delta x=v(\\Delta t/2)$.\n\\end{document}", "meta": {"hexsha": "d2d99a813ee862598e3a46795f93a67732e8edfb", "size": 4265, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Theory.tex", "max_stars_repo_name": "Lina492375qW1188/simulating-Langevin-dynamics", "max_stars_repo_head_hexsha": "14132913bee1a051d27a4e2def9b083d8a565054", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Theory.tex", "max_issues_repo_name": "Lina492375qW1188/simulating-Langevin-dynamics", "max_issues_repo_head_hexsha": "14132913bee1a051d27a4e2def9b083d8a565054", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Theory.tex", "max_forks_repo_name": "Lina492375qW1188/simulating-Langevin-dynamics", "max_forks_repo_head_hexsha": "14132913bee1a051d27a4e2def9b083d8a565054", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-21T19:26:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-21T19:26:30.000Z", "avg_line_length": 50.1764705882, "max_line_length": 284, "alphanum_fraction": 0.6618991794, "num_tokens": 1608, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639065, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7160210856525913}}
{"text": "\\par Now is the time to talk real problems. Constrained optimisation problems are the problems that have constraints. Whenever a problem is restricted to a particular part of the space, we are talking about the constraint optimisation. Remember that the unconstrained and constrained optimisation problems are quite connected. Each constrained problem can be transformed into unconstrained by simply bringing the constraints into the objective function. This can be done with the indicator function: whenever a point does not belong to the admissible region the value of the function goes to $\\infty$. No one is that crazy to do it though. The indicator function is a bad function, it brings non differentiability into a problem that may be perfectly differentiable everywhere (both the objective function and the constraints).\n\\par In general this is a complicated problem unless everything is convex. Most of the times it is but sometimes it is not. Generally the global optimum is very difficult to find. We usually stick to a weaker condition: \\textbf{the local optimum $x_*$}:\n\\begin{equation}\n    \\min\\{f(x) : x \\in \\mathcal{B}(x_*,\\epsilon) \\cap X\\}\n\\end{equation}\nfor some $\\epsilon > 0$. Note that we are talking about local optimum, not local minimum. This is not casual. Local minimum is the point where you truly have a minimum of the function. This happens when you are working on the entire space $\\mathbb{R}^n$. If you are constrained to a subspace $X$ then you are talking about \\textit{minimum in that subspace}. Hence we are talking about the local optimum constrained to that subspace. Clearly, with this definition, if the local optimum is located in the interior of the set $X$, i.e. if $x_* \\in \\textit{int} X$ then the local optimum is also the local minimum. This is because in the interior of the set the constraints are not touching the optimal solution. So the optimum is independent from the constraints. So in order to have local minimum different from local optimum, it must be located on the boundary of the set, i.e. $\\partial X$. So the boundary of the feasible set is quite important.\n%\n\\section{A simple case: feasible sets with no interior}\n\\par Let us start with the simplest constrained problem: quadratic problem. The problems of this kind are those that have quadratic objective function but linear constraints. Moreover, let us consider a problem with just the linear equality constraints:\n\\begin{equation}\n    \\min\\{f(x) : Ax = b\\}\n\\end{equation}\nwhere $A \\in \\mathbb{R}^{m \\times n}$ with rank$(A) = m < n$ and rows linearly independent. We need to have more variables than equations because if $m = n$, then it is a square system and thus we could just apply the closed formula and solve it without any fancy optimisation technique. Linear independence is needed because otherwise if there is a row that is linearly dependent from the others then either the system is impossible or that dependant row can be eliminated (linear algebra). Think of a plane that is parallel to another one. In that case, the two planes will never intersect thus there is no solutions.\n\\par Actually we could transform this particular constrained problem into the unconstrained one. Since $A$ is short and fat, we can split it in two parts: $A_B$ and $A_N$, respectively $m \\times m$ matrix and $m \\times (n-m)$ matrix. We do the same for the input vector $x$, i.e. $x_B$ of $m$ entries and $x_N$ of $n-m$ entries. So we have:\n\\begin{equation}\n    A_B x_B + A_N x_N = b\n\\end{equation}\nNow if $A_B$ is invertible, that is if det$(A_B) \\neq 0$ then we can write the above equation as:\n\\begin{equation}\n    x_B = A_B^{-1}(b - A_N x_N)\n\\end{equation}\nThis means that we have transformed the variables of $x_B$ into dependant variables from independent variables $x_N$. In other words, now we con concentrate on optimising just $x_N$, while $x_B$ can be subsequently obtained from $x_N$. How? Like this:\n\\begin{equation}\n    x_B = -A_B^{-1} A_N x_N + A_B^{-1}b = Dw + d\n\\end{equation}\nwhere:\n\\[\nD = \\left[\n  \\begin{array}{c}\n  -A_B^{-1}A_N \\\\\n  I\n  \\end{array}\n\\right],\nd = \\left[\n  \\begin{array}{c}\n  A_B^{-1}b \\\\\n  0\n  \\end{array}\n\\right]\n\\]\nand $w \\in \\mathbb{R}^{n-m}$. The problem then becomes:\n\\begin{equation}\n    w_* = \\min_{w \\in \\mathbb{R}^{n-m}} \\{r(w) = f(Dw + d)\\}\n\\end{equation}\nwhich is clearly an unconstrained optimisation problem in $w$. $m$ linear constraints kill $m$ degrees of freedom.\n\\par We can thus construct a \\textit{reduced gradient} of the form:\n\\begin{equation}\n    \\nabla r(w) = D^T \\nabla f (Dw + d)\n\\end{equation}\nwhich is obtained by applying the usual derivative of the composition operator (chain rule). How do we solve an unconstrained optimisation problem. The good old gradient: we need to solve:\n\\begin{equation}\n    \\nabla r(w_*) = D^T \\nabla f (Dw + d) = 0\n    \\label{eq:chapter3-reduced_gradient}\n\\end{equation}\n\\par Let us now explain something that is quite important. We know how to characterise the optimality in the space of $w$. But what happens when we want to write the optimality in the original space of $x$? Note that:\n\\begin{equation}\n    D^T A^T = AD = 0\n\\end{equation}\nHaving said that, we can also say that whatever scalar of the matrix $A$ will also produce 0 when multiplied with $D$ (obviously), that is:\n\\begin{equation}\n    \\mu AD = \\mu D^T A^T = 0\n\\end{equation}\nLet us now call $\\mu A$ with $z$:\n\\begin{equation}\n    D^T z = 0\n\\end{equation}\nNow, look at the gradient in \\ref{eq:chapter3-reduced_gradient}. We want to find a point $x = Dw + d$ such that the gradient of that point $x$ multiplied with $D^T$ will give us 0. But that would mean:\n\\begin{equation}\n    \\mu A = \\nabla f(x), x=Dw + d\n\\end{equation}\nSo the gradient must be a scalar multiple of $A$. So if we manage to find $x$ such that the gradient of $f$ in that point is a multiple of $A$, then in the space of $w$ that point is a stationary point, and $x$ is a local optimum.\n\\par Let us now state it in more formal terms:\n\\begin{equation}\n\\begin{split}\n    &\\mbox{if}\\\\\n    &Ax = b \\mbox{ and } \\exists \\mu : \\mu A = \\nabla f(x)\\\\\n    &\\mbox{then}\\\\\n    &x \\mbox{ is a stationary point for } (P) \\equiv \\min \\{f(x) : Ax = b\\}\n\\end{split}\n\\end{equation}\nThis is a special case of \\textbf{Poorman's KKT conditions}, which are THE optimality conditions for constraint optimisation problems. Basically, the optimal point must be a feasible point and the gradient in that point must be written as a linear combination of the gradients of the constraints. So in order to show that $x$ is optimal, we need to compute $\\mu$.\n\\par Of course if $f$ is convex, these conditions are also sufficient for the optimality.\n\\subsection{Geometric interpretation}\n\\par What are these $\\mu$ geometrically speaking? Suppose you have a quadratic function whose level sets are shown in figure \\ref{fig:chapter3-contraint_equality_1}. In the same figure you can also see a line that correspond to the feasible region described by the equality constraints $Ax = b$. For the sake of simplicity, suppose we have just one equality, as in figure. Remember that we are in $\\mathbb{R}^n$ space, not $\\mathbb{R}^{n+1}$ where the value of the function lives.\n\\par The minimum is clearly located in the point in the middle of the inner most level set. But since we must restrict the admissible points to the admissible region indicated by $Ax = b$, the local optimum is the point that is the intersection between the line and the inner most level set. Why inner most? Because every other outer level set has a greater function value.\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{figures/3/chapter3-constraint_equality_1.png}\n    \\caption{Caption}\n    \\label{fig:chapter3-contraint_equality_1}\n\\end{figure}\n\\par Now, we know that the gradient is always normal (orthogonal) to the level sets. Consequently, it is also normal to the admissible region in the point of the intersection, i.e. $\\nabla f(x) \\perp \\partial X$ (see figure \\ref{fig:chapter3-constraint_equality_2}). But since by definition $A \\perp \\partial X$ (all the points in $X$ have the scalar product 0 with $A$), it must be that the gradient is also co-linear with $A$, i.e. $A \\parallel \\nabla f(x)$ (see figure \\ref{fig:chapter3-constraint_equality_3}).\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{figures/3/chapter3-constraint_equality_2.png}\n    \\caption{Caption}\n    \\label{fig:chapter3-constraint_equality_2}\n\\end{figure}\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{figures/3/chapter3-constraint_equality_3.png}\n    \\caption{Caption}\n    \\label{fig:chapter3-constraint_equality_3}\n\\end{figure}\n\\par The matrix $A$ sends every vector somewhere in the space, you remember, matrices are used for transformations :). The vectors that when multiplied with $A$ produce $b$ are in the admissible region. But who said $A$ likes only the admissible region? $A$ sends vectors wherever: and so it can send also in the opposite direction. Exactly where our gradient is located.\n\\par It is for this reason that we define the directions in the feasible region:\n\\begin{equation}\n    F = \\{d \\in \\mathbb{R}^n : A \\cdot x = 0\\}\n\\end{equation}\n\\par In constrained optimisation it is no more necessary to have the gradient zero in the optimal point. Think of taking a minimum of a concave quadratic function whose admissible region is from a certain level set above. Clearly the minimum is at the edge of the admissible region. In that point the gradient is for sure negative.\n\\par What we have in the local optimum point is that all the directions in the feasible region have the scalar product with the gradient $\\geq 0$:\n\\begin{equation}\n    \\nabla f(x) \\cdot d \\geq 0, \\forall d \\in F\n\\end{equation}\n\\par Unfortunately constraints are way more complicated than lines and affine spaces. So we need to dive into it, right now.\n%\n\\section{The theory of ice creams: cones}\n\\par The crucial mathematical object that we are going to use to define the optimality is the \\textbf{Tangent Cone}:\n\\begin{equation}\n    T_X(x) = \\Big\\{d \\in \\mathbb{R}^n : \\exists \\{z_i \\in X\\} \\rightarrow x \\wedge \\{t_i \\geq 0\\} \\rightarrow 0 : d = \\lim_{i \\rightarrow \\infty} \\frac{z_i-x}{t_i}\\Big\\}\n\\end{equation}\n\\par Err... what? Yes, it is not nice as a definition. But it is easier than you think. Basically, this definition states that in order for $d$ to be a direction along which we can move from the current point $x$, it must be a direction that comes from a sequence of points belonging to the feasible set and that converge to $x$. But also there must be a sequence of corresponding step sizes that converge to 0. The overall sequence may be a straight line, may be of sinusoidal form, it may even be on the border. What matters is that it tends to $x$ in the limit \\ref{fig:chapter3-tangent_cone}.\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{figures/3/chapter3-tangent_cone.png}\n    \\caption{An example of the tangent cone}\n    \\label{fig:chapter3-tangent_cone}\n\\end{figure}\n\\par Why is this cone important? Because it provides a necessary condition for $x$ to be local optimum (and global optimum in case $X$ is convex).\n\\begin{theorem}\n    \\[x \\mbox{ local optimum } \\Rightarrow \\nabla f(x) \\cdot d \\geq 0, \\forall d \\in T_X(x)\\]\n\\end{theorem}\n\\begin{proof}\n    Let us assume by contradiction that there exists a direction in the local optimum $x$ that has negative scalar product with the gradient of $x$. Let us call that direction $d$. Since $d \\in T_X(x)$, this means that there exists a sequence of points $\\{z_i\\}$ in $X$ that converge to $x$ with a sequence of step sizes $\\{t_i\\}$ that converge to 0. Consider now the first order Taylor expansion in $z_i$:\n    \\begin{equation}\n        \\begin{split}\n            f(z_i) &= f(x) + \\nabla f(x)(z_i - x) + R(z_i - x) =\\\\\n            &= f(x) + \\nabla f(x) \\cdot (z_i - x) + R(z_i - x)\n        \\end{split}\n    \\end{equation}\n    Let us now add $-f(x)$ to both sides, divide them by $t_i$ and send them to limit:\n    \\begin{equation}\n        \\begin{split}\n            \\lim_{i \\rightarrow \\infty} \\frac{f(z_i) - f(x)}{t_i} &= \\nabla f(x) \\cdot \\lim_{i \\rightarrow \\infty} \\frac{z_i - x}{t_i} + \\lim_{i \\rightarrow \\infty} \\frac{R(z_i - x)}{t_i} =\\\\\n            &=\\nabla f(x) \\cdot   d + \\lim_{i \\rightarrow \\infty} \\frac{R(z_i - x)}{t_i} < 0\n        \\end{split}\n    \\end{equation}\n    Which is a contradiction. The scalar product is negative by assumption and the limit on the right is converging to 0. So the whole right part is strictly negative. This would mean that $z_i$ is a point in the neighbour of $x$ that has the value of the function strictly smaller than the one in $x$. But we said that $x$ was a local optimum.\n\\end{proof}\n\\par Something that you could say: yes but if $x$ is local optimum, nobody is telling me that it is also a global optimum. Thus, for sufficiently large ball around $x$, I could find a point where the function value is actually smaller than the one in $x$. True. But we are talking about cones, not balls. There must not be a point in the cone of $x$ that has a smaller value.\n\\par Tangent cone does not give us also the sufficient condition. In other words, there may be a point $y$ where all the directions in the tangent cone of $y$ give positive scalar product with the gradient $\\nabla f(y)$, but still $y$ may not be a local optimum.\n\\par Consider the example in figure \\ref{fig:chapter3-tangent_cone_not_sufficient1}. This function is clearly not convex. The grey part is the admissible region $X$. Consider the point $x$ in the origin as our current point. The set of directions that are part of the tangent cone in $x$ are all those directions that belong to the positive part of the $y$ axe (see figure \\ref{fig:chapter3-tangent_cone_not_sufficient2}). All those directions give $\\geq 0$ scalar product with the gradient in $x$. Clearly, the point $x$ is not a local optimum. $x$ is just a stationary point.\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{figures/3/chapter3-tangent_cone_not_sufficient1.png}\n    \\caption{A counterexample for the sufficient condition of the tangent cone.}\n    \\label{fig:chapter3-tangent_cone_not_sufficient1}\n\\end{figure}\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{figures/3/chapter3-tangent_cone_not_sufficient2.png}\n    \\caption{$T_X(x)$ is the $x$ axes. All directions are in 0 scalar product with the gradient $\\nabla f(x)$.}\n    \\label{fig:chapter3-tangent_cone_not_sufficient2}\n\\end{figure}\n\\par What we really want to have is the set of feasible directions.\n\\begin{equation}\n    F_X(x) = \\{d \\in \\mathbb{R}^n : \\exists \\bar \\epsilon > 0 \\mbox{ s.t. } x + \\epsilon d \\in X, \\forall \\epsilon \\in [0,\\bar \\epsilon]\\}\n\\end{equation}\n\\par If $X$ is convex we can omit the last part of the definition and just use $\\bar \\epsilon$ instead of $\\epsilon$.\n\\par Clearly, this cone looks very similar to the tangent cone. Generally, the feasible directions cone is not a closed set ($T_X$ is). The closure of $F_X$ is always a subset of $T_X$ and if everything is convex then the closure of $F_X$ is the very same $T_X$. In this case we could actually conclude that:\n\\begin{equation}\n    x \\mbox{ is global optimum } \\iff \\nabla f(x) \\cdot d \\geq 0, \\forall d \\in T_X(x)\n\\end{equation}\n\\par How do we characterise $T_X$? It depends on how you characterise the admissible region $X$. Usually, one can do that in many different ways. A classical way is by explicitly describing the constraints:\n\\begin{equation}\n    X = \\{x \\in \\mathbb{R}^n : g_i(x) \\leq 0, i \\in \\mathcal{I}, h_j(x) = 0, j \\in \\mathcal{J}\\} = \\{x \\in \\mathbb{R}^n : G(x) \\leq 0, H(x) = 0\\}\n\\end{equation}\nwhere $\\mathcal{I}$ is the set of inequalities and $\\mathcal{J}$ is the set of equalities. Note that $G$ and $H$ are vector valued functions. $G$ sends vectors from space $\\mathbb{R}^n$ to vectors in space $\\mathbb{R}^{|\\mathcal{I}|}$ and $H$ sends vectors from space $\\mathbb{R}^n$ to vectors in space $\\mathcal{R}^{|\\mathcal{J}|}$.\n\\par There is a nice \\textit{theoretical} way to represent all the constraints with just one inequality constraint. To do that, we need to passages:\n\\begin{itemize}\n    \\item Each equality constraint can be expressed as two inequality constraints:\n    \\[a = 0 \\iff a \\leq 0 \\wedge -a \\leq 0\\]\n    \\item The set of inequality constraints follows the relation:\n    \\[G(x) \\leq 0 \\iff \\max\\{g_i(x) : i \\in \\mathcal{I}\\} \\leq 0\\]\n\\end{itemize}\n\\par One concept that we will use a lot is the set of \\textbf{active constraints}. A constraint is active if the point is on the border described by that constraint. By definition all the equality constraint are always active, otherwise the point would not be in the feasible region. The active inequality constraints are basically all those constraints that result in $=0$. In formulae:\n\\begin{equation}\n    \\mathcal{A}(x) = \\{i \\in \\mathcal{I} : g_i(x) = 0\\}\n\\end{equation}\nIt is thus convenient to define $G$ restricted to that particular set of indices whose corresponding inequalities are active:\n\\begin{equation}\n    G_{\\mathcal{A}(x)} : \\mathbb{R}^n \\rightarrow \\mathbb{R}^{|\\mathcal{A}(x)|}\n\\end{equation}\n\\par So now we can define a cone that can be used in practical way. The cone is called \\textbf{first order feasible direction cone}.\n\\begin{equation}\n    D_X(x) = \\{d \\in \\mathbb{R}^n : \\nabla g_i(x) \\cdot d \\leq 0\\ i \\in A(x), \\nabla h_j(x) \\cdot d  = 0\\ j \\in \\mathcal{J}\\}\n\\end{equation}\nNote that we are now looking into the gradients not functions. It is for this reason that we can rewrite the above definition with:\n\\begin{equation}\n    D_X(x) = \\{d \\in \\mathbb{R}^n : JG_{A(x)}(x) \\cdot d \\leq 0, JH(x) \\cdot d = 0\\}\n\\end{equation}\nwhere $J$ stands for Jacobian matrix.\n\\par Each active inequality $i$ defines one particular curve that passes in the point $x$. The gradient in $x$ with respect to that curve will be normal to the curve it self (see figure \\ref{fig:chapter3-feasible_cone} for an example).\n\\begin{figure}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{figures/3/chapter3-feasible_cone1.png}\n        \\caption{Caption}\n        \\label{fig:feasible1}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{figures/3/chapter3-feasible_cone2.png}\n        \\caption{Caption}\n        \\label{fig:feasible2}\n    \\end{subfigure}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{figures/3/chapter3-feasible_cone3.png}\n        \\caption{Caption}\n        \\label{fig:feasible3}\n    \\end{subfigure}\n    \\caption{Assume we have only two active inequalities in the point $x$. Take the two corresponding gradients and then construct the cone in the opposite direction.}\n    \\label{fig:chapter3-feasible_cone}\n\\end{figure}\n\\par It is intuitive that the tangent cone is contained in the first order feasible directions cone, i.e.:\n\\begin{equation}\n    T_X(x) \\subseteq D_X(x)\n\\end{equation}\n\\par So what we really want is the set of feasible directions $F_X$, but due to the closure issue we moved to the tangent cone directions $T_X$, and finally due to its complexity of characterisation we have constructed the first order feasible directions cone $D_X$. It is clear that all of these cones are very similar to each other. We would like to have the tangent cone same as the first order feasible directions cone. Unfortunately, in some pathological cases this may not be true. In other words, we could have $T_X \\subset D_X$ (see figure \\ref{fig:chapter3-feasible_cone_larger}).\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.6]{figures/3/chapter3-feasible_cone_larger.png}\n    \\caption{Suppose you have to convex constraints, one is the all negative subspace of the $y$ axes and the other one is the ball you see in the figure. The first order feasible directions cone is the whole $x$ axes while the tangent cone consist just of one point, the origin. This is because the feasibility region is just the origin (the intersection of the two constraints). $D_X(x) = \\{[x_1,x_2] : x_2 = 0\\}, T_X(x) = F_X(x) = [0,0]$.}\n    \\label{fig:chapter3-feasible_cone_larger}\n\\end{figure}\nNote that here everything is convex. So the convexity are not helping us to make the two cones the same stuff.\n\\par We need to to introduce something that will guarantee us that we are not in some of these pathological cases. This something is called \\textit{constraint qualifications}. There are plenty of them, but let us consider the three most important for our purposes:\n\\begin{itemize}\n    \\item Affine constraints: everything is linear, except the objective function. It this constraint holds then $\\forall x \\in X\\ T_X(x) = D_X(x)$.\n    \\item Slater's conditions: inequalities are convex and equalities are affine. If there exists at least one point $x \\in X$ that is in the interior, $g_i(x) < 0, \\forall i \\in \\mathcal{I}$, then $T_X(x) = D_X(x), \\forall x \\in X$. Informally, Slater's condition states that the feasible region must have an interior point.\n    \\item Linear independence: given a point $x \\in X$, if the set of:\n    \\[\n        \\{\\nabla g_i(x) : i \\in \\mathcal{I}\\} \\cup \\{h_j(x) : j \\in \\mathcal{J}\\}\n    \\]\n    is linearly independent, then $T_X(x) = D_X(x)$.\n\\end{itemize}\n\\par But excluding these pathological cases, or by using some of the constraint qualifications, we have our necessary condition (also sufficient in convex case):\n\\begin{equation}\n    \\nabla f(x) \\cdot d \\geq 0, \\forall x \\in D_X(x)\n\\end{equation}\n\\par The problem is: there are infinitely many directions to check.\n%\n\\subsection{Farkas' lemma}\n\\par Let us now see how we can avoid checking all the infinite direction of the first order feasible directions cone $D_X$ but still be able to say whether we are in the local optimum or not. We know that $D_X$ is a polyhedral cone of type: $\\{d \\in \\mathbb{R}^n : Ad \\leq 0\\}$. Now consider the figure \\ref{fig:chapter3-farkas1}. Consider a generic vector $c \\in \\mathcal{R}^n$. This vector can either belong to the dual cone or not. In case it belongs then we can write $c$ as a linear combination of the gradients (see figure \\ref{fig:chapter3-farkas2}) . Otherwise there must exist a direction $d$ in the original cone that has a positive scalar product with $c$ (see figure \\ref{fig:chapter3-farkas3}).\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{figures/3/chapter3-farkas1.png}\n    \\caption{The dual cone $C^* = \\{c = \\sum_{i=1}^k \\lambda_i A_i : \\lambda_i \\geq 0\\}$ is the one defined by the two gradients and all the positive linear combinations of the two.}\n    \\label{fig:chapter3-farkas1}\n\\end{figure}\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{figures/3/chapter3-farkas2.png}\n    \\caption{If $c \\in C^*$ then there must be a set of non negative $\\lambda_i$ multipliers for the linear combination of gradients to produce $c$.}\n    \\label{fig:chapter3-farkas2}\n\\end{figure}\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{figures/3/chapter3-farkas3.png}\n    \\caption{If $c \\notin C^*$ then it must be the case that there is $d \\in C$ such that $c \\cdot d > 0$.}\n    \\label{fig:chapter3-farkas3}\n\\end{figure}\n\\par Let us formally define Farkas' lemma:\n\\begin{theorem}\n    \\[\n        \\forall c \\in \\mathbb{R}^n . \\exists \\lambda \\geq 0 : c = \\lambda A \\vee \\exists d : Ad \\leq 0 \\wedge c \\cdot d > 0\n    \\]\n\\end{theorem}\n\\par Note that we use strictly greater than 0 and not $\\geq 0$. This is because if we were using $\\geq$ then our vector $c$ could have been $A_2$ for instance.\n\\par Why do we care about Farkas' lemma? Get ready!\n\\par We want to use Farkas' lemma to get a nice and (more than everything) useful necessary condition. So we want something like:\n\\begin{equation}\n\\begin{split}\n    &x^* \\mbox{ is local optimum } \\Rightarrow \\nabla f(x^*) \\cdot d \\geq 0, \\forall d \\mbox{ that satisfy: }\\\\\n    &\\nabla g_i(x^*) \\cdot d \\leq 0, \\forall i \\in \\mathcal{A}(x^*) \\wedge \\nabla h_i(x^*) \\cdot d = 0, \\forall j \\in \\mathcal{J}\n\\end{split}\n\\end{equation}\n\\par Turns out that this problem is equivalent to:\n\\begin{equation}\n    \\begin{split}\n        &x^* \\mbox{ is local optimum } \\Rightarrow \\exists \\lambda \\in \\mathbb{R}_{+}^{|\\mathcal{A}(x^*)|} \\wedge \\mu \\in \\mathbb{R}^{|\\mathcal{J}|} \\mbox{ s.t. }\\\\\n        &f(x^*) + \\sum_{i \\in \\mathcal{A}(x^*)} \\lambda_i \\nabla g_i(x^*) + \\sum_{j \\in \\mathcal{J}} \\mu_i \\nabla h_j(x^*) = 0\n    \\end{split}\n    \\label{eq:chapter3-multipliers}\n\\end{equation}\nNote that we are saying that the opposite of the gradient must be written as the linear combination of the two sums. Moreover, note that we leave $\\mu$ to be of any sign. This is not a random stuff. As we know, each equality constraint can be written as two inequality constraints:\n\\begin{equation}\n    \\nabla h(x) = 0 \\iff \\nabla h(x) \\leq 0 \\wedge -\\nabla h(x) \\leq 0\n\\end{equation}\nso there exist two positive scalars $\\mu^+, \\mu^-$ such that:\n\\begin{equation}\n    \\mu^+ \\nabla h(x) \\leq 0 \\wedge \\mu^- \\nabla  h(x) \\leq 0\n\\end{equation}\nthus we can write:\n\\begin{equation}\n    (\\mu^+ - \\mu^-)\\nabla h(x) = 0\n\\end{equation}\nThis difference can be of any sign.\n\\par So if $x^*$ is a local optimum then there must exist the multipliers $\\lambda$ and $\\mu$ such that \\ref{eq:chapter3-multipliers} holds. This is a necessary condition (under constraint qualifications), and also sufficient in case of convex optimisation.\n%\n\\subsection{From Farkas' lemma to KKT saint graal}\n\\par So the equivalent problem from above takes name of \\textbf{Karush-Kuhn-Tucker conditions}. The complete characterisation of KKT conditions is the following:\n\\begin{align}\n    &g_i(x) \\leq 0, i \\in \\mathcal{I} \\mbox{ and } h_j(x) = 0, j \\in \\mathcal{J} && \\mbox{(KKT-F)}\\\\\n    &\\nabla f(x) + \\sum_{i \\in \\mathcal{I}} \\lambda_i \\nabla g_i(x) + \\sum_{j \\in \\mathcal{J}} \\mu_i \\nabla h_j(x) = 0 && \\mbox{(KKT-G)}\\\\\n    &\\sum_{i \\in \\mathcal{I}} \\lambda_i g_i(x) = 0 && \\mbox{(KKT-CS)}\n\\end{align}\nThe first condition requires that the point $x$ is feasible. The second is the Farkas' lemma stuff, so $-\\nabla f(x)$ has to be written as the linear combination of the gradients of the constraints. Note how we are using the whole set of inequalities not just the active ones. This is why we need the third constraint called \\textbf{complementary slackness}. Think about it: with complementary slackness constraint, an inequality constraint $i$ is either active, and then $g_i(x) = 0$ so $\\lambda$ can be any number; or the constraint $i$ is not active, i.e. $g_i(x) < 0$, but due to the complementary slackness requirement, $\\lambda_i$ must be 0.\n\\par $\\lambda$ and $\\mu$ are called \\textbf{Lagrangian multipliers} or \\textbf{Lagrangian} duals.\n\\par Let us now announce the saint graal of the constraint optimisation:\n\\begin{theorem}\n    If the constraint qualification hold, that is $T_X(x) = D_X(x)$ and $x$ is local optimum, then KKT conditions must hold, that is there must be some $\\lambda$ and $\\mu$ such that the KKT constraints hold all together.\n\\end{theorem}\nMoreover, under convexity, this theorem becomes if and only if. So in the end, KKT conditions are the ones that recognise the local optimum.\n%\n\\subsection{The nasty critter: Lagrangian function}\n\\par Let us briefly touch the bad guy: non convex case. In these cases, the first order information is not enough and we have to look also into the second order information. In the non convex case, the first order information is just telling us that we are in a stationary point, but it can be a saddle point, a maximum or a minimum. We need to look into the Hessian. What we do is to construct a mathematical object, whose second order derivative, the Hessian, will give us more information about the things we are looking for, that is the local optimum. This mathematical object is called \\textbf{Lagrangian function}:\n\\begin{equation}\n    L(x; \\lambda, \\mu) = f(x) + \\sum_{i \\in \\mathcal{I}} \\lambda_i g_i(x) + \\sum_{j \\in \\mathcal{J}} \\mu_j h_j(x)\n    \\label{eq:lagrangian_function}\n\\end{equation}\nwhere $x$ are the variables and $\\lambda$ and $\\mu$ are the constant parameters. Look at this as a way to construct an infinite family of functions in $x$. Once that you have fixed the two parameters, you get a particular function in the variable $x$.\n\\par The gradient of this guy is exactly the second condition of the KKT system. You don't see it? Remember these two properties and then retry:\n\\begin{align}\n    &\\nabla(a + b) = \\nabla(a) + \\nabla(b)\\\\\n    &\\nabla(\\alpha a) = \\alpha \\nabla(a)\n\\end{align}\nThe points that satisfy KKT conditions are all the stationary points of the Lagrangian function. So as we did in the case of the unconstrained optimisation of non convex cases, we need to compute the second order derivative. We may think that it is sufficient to deal with the Hessian of the Lagrangian function. But the reality is a bit more complicated. In order to speak about the second order derivative, we need to define the concept of the \\textbf{critical cone}:\n\\begin{equation}\n  C(x,\\lambda,\\mu)=\n  \\Bigg\\{\n    d \\in \\mathrm{R}^n : \n    \\begin{cases}\n        \\nabla g_i(x) \\cdot d = 0, & i \\in \\mathcal{A}(x) \\mbox{ s.t. } \\lambda_i^* > 0\\\\\n        \\nabla g_i(x) \\cdot d \\leq 0, & i \\in \\mathcal{A}(x) \\mbox{ s.t. } \\lambda_i^* = 0\\\\\n        \\nabla h_j(x) \\cdot d = 0, & j \\in \\mathcal{J}\n    \\end{cases}\n  \\Bigg\\}\n\\end{equation}\nThe first condition says that the direction in the critical cone must be orthogonal to the gradient of the active inequality constraint whose $\\lambda$ coefficient is strictly positive; the second says it must be in the opposite direction of the gradient of the active inequalities whose $\\lambda$ is 0 (yeah man, it must go in the minimum direction); and the third one obviously says that it must remain orthogonal to the equality constraint.\n\\par Why are we interested in the critical cone? Because, if $x^*$ is the local optimum of the constrained problem, then it turns out that the Hessian of the Lagrangian function in that point must be positive semidefinite not in all directions, but only in those of the critical cone.\n\\begin{theorem}\n    If under constraint qualifications, the triple $(x,\\lambda,\\mu)$ satisfy KKT conditions, and $x$ is local optimum, then:\n    \\[\n    d^T \\nabla^2 L(x; \\lambda, \\mu)d \\geq 0, \\forall d \\in C(x,\\lambda,\\mu)\n    \\]\n\\end{theorem}\nThis is also sufficient condition if the Hessian is positive definite.\n\\par Until now, we have spoke about a function in $x$, without bothering about the other two parameters: $\\lambda$ and $\\mu$. But actually the Lagrangian dual is a function in three variables. So let us now consider the Lagrangian function as a function in only two variables, $\\lambda$ and $\\mu$, for a given $x$.\n%\n\\subsection{Lagrangian relaxation}\n\\par Let us define the following function:\n\\begin{equation}\n    \\psi(\\lambda, \\mu) = \\min_{x \\in \\mathbb{R}^n}\\{L(x,\\lambda,\\mu)\\}\n\\end{equation}\nThis function defines the \\textbf{dual problem} or \\textbf{dual function} of the original objective function.\n\\par As you an see, this is an unconstrained optimisation problem that is kind of a ``wrapper'' of the original Lagrangian function. Actually what we have just done is called \\textbf{Lagrangian} relaxation. I don't know how to treat constraints efficiently. Cool, let us relax this fact and bring it into the objective function. If the feasibility is not respected on some inequality for example, then $g_i$ and $\\lambda$ will be positive and so $L(x,\\lambda,\\mu)$ will be larger than $f(x)$. Think about a car on the highway. You should not go above the speed limit (constraints). No one is actually preventing you, so you can go (relaxation). But if police catches you doing that, you will pay a lot of money (violate constraints in the objective function).\n\\par This is an example of penalty method. Penalty methods are a certain class of algorithms for solving constrained optimisation problems. A penalty method replaces a constrained optimisation problem by a series of unconstrained problems whose solutions ideally converge to the solution of the original constrained problem. The unconstrained problems are formed by adding a term, called a penalty function, to the objective function that consists of a penalty parameter multiplied by a measure of violation of the constraints. The measure of violation is nonzero when the constraints are violated and is zero in the region where constraints are not violated.\n\\par Our question is now: how is the value of this optimisation problem related to the value of the original optimisation problem? Turns out that we have the following relation:\n\\begin{theorem}\n    $\\psi(\\lambda,\\mu) \\leq f(x)$\n\\end{theorem}\n\\begin{proof}\n    Suppose you have a $\\bar{x}$ that is in the feasible region (not necessarily the optimum solution). Since it is in the feasible reason we have that:\n    \\begin{align}\n        &g_i(\\bar{x}) \\leq 0 && i \\in \\mathcal{I}\\\\\n        &h_j(\\bar{x}) = 0 && j \\in \\mathcal{J}\n    \\end{align}\n    Which means that the Lagrangian function becomes:\n    \\[\n        L(\\bar{x}, \\lambda, \\mu) = f(\\bar{x}) + \\lambda G(\\bar{x}) + \\mu H(\\bar{x}) = f(\\bar{x}) + \\lambda G(\\bar{x}) \\leq f(\\bar{x})\n    \\]\n    Since $\\psi$ function is a minimisation problem over the Lagrangian function $L$, we have that:\n    \\[\n        \\psi(\\lambda, \\mu) \\leq f(\\bar{x}), \\forall \\bar{x} \\in \\mbox{feasible region}\n    \\]\n\\end{proof}\nBut $\\bar{x}$ may also be the optimal solution $x^*$. We would like to have $\\psi(\\lambda, \\mu)$ as close to $f(x^*)$ as possible. So what we need to do is to maximise the Lagrangian relaxation problem:\n\\begin{equation}\n    \\max \\{\\psi(\\lambda,\\mu) : \\lambda \\in \\mathbb{R}_+^{|\\mathcal{I}|}, \\mu \\in \\mathbb{R}^{|\\mathcal{J}|}\\}\n\\end{equation}\nThis problem is called the \\textbf{Lagrangian dual} of the original problem. $\\psi$ is a concave function, so local optima is global optima. Why concave? Well imagine that you fix $L$ with a given $x$. Now look at the Lagrangian function defined in \\ref{eq:lagrangian_function}. Do you see it :)? That nasty critter is now a simple linear function in two variables $\\lambda$ and $\\mu$. Linear functions generate planes in three dimensional space or lines in two dimensional space. There are infinitely many lines (hyperplanes), one per each $x$. Consider the figure \\ref{fig:chapter3-lagrangian_lines}. Each line represents a particular choice of $x$. We are interested in the function $\\psi$ which is identified by the bold line. Clearly, this function is non differentiable and it is concave.\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.4]{figures/3/chapter3-lagrangian_lines.png}\n    \\caption{Caption}\n    \\label{fig:chapter3-lagrangian_lines}\n\\end{figure}\n\\par But now bad things: it may happen that the value is $-\\infty$ and usually it is not differential, even if all the other stuff is differentiable. But most of all, each time we want to compute the value of the Lagrangian dual, we need to solve a minimisation problem inside. For each $\\lambda$ and $\\mu$ I clearly have to minimise the Lagrangian relaxed problem.\n\\par The property $\\psi(\\lambda,\\mu) \\leq f(x)$ is called \\textbf{weak duality}. We are interested in those cases where we have the equality, i.e. $\\psi(\\lambda,\\mu) = f(x)$, which is called \\textbf{strong duality}. Is it always the case that we have the strong duality? Unfortunately no. A counter-example may be:\n\\begin{align}\n    &\\min\\{-x^2 : 0 \\leq x \\leq 1\\}\\\\\n    &L(x,\\lambda,\\mu) = -x^2 + \\lambda_1 (x-1) + \\lambda_2 x\\\\\n    &\\psi(\\lambda,\\mu) = \\min \\{L(x,\\lambda,\\mu\\} = -\\infty, \\forall \\lambda \\in \\mathbb{R}^2\\\\\n    &\\psi(\\lambda,\\mu) = -\\infty \\leq f(x^*) = -1\n\\end{align}\nThis is due to the fact that you are minimising a concave function, or maximising a convex function. But under convexity (minimisation) and constraint qualifications, the things work:\n\\begin{theorem}\n    If the problem $P$ is convex, $x^*$ is local optimum and $T_X(x^*) = D_X(x^*)$ (constraint qualifications or regularity), then there exist optimal $\\lambda^*, \\mu^*$ for the dual problem such that $\\psi(\\lambda^*, \\mu^*) = v(P)$.\n\\end{theorem}\n\\begin{proof}\n    Since there are optimal $\\lambda^*$ and $\\mu^*$ for some optimal solution for the problem $P$, $x^*$, we know that the gradient of the Lagrangian function is 0, that is:\n    \\[\n        \\nabla_X L(x^*,\\lambda^*,\\mu^*) = 0\n    \\]\n    It is a saddle point. But since our function is convex, we know that:\n    \\[\n        v(D) \\geq \\psi(\\lambda^*,\\mu^*) = \\min_{x \\in \\mathbb{R}^n}\\{L(x,\\lambda^*,\\mu^*)\\} = L(x^*,\\lambda^*,\\mu^*) = f(x^*) = v(P)\n    \\]\n    The first and the second passages are due to the definition. Since we have assumed that the optimal solution is in $x^*$ we get the third passage. Now the forth passage is slightly more involved. Since everything is optimal, KKT conditions are satisfied. So the two large sums in the Lagrangian function become 0 (complementary slackness).\n    \\par But we also know that the dual optimal value is a lower bound of the optimal value of the primal:\n    \\[\n        v(P) \\geq v(D)\n    \\]\n    So it must be the case that the two values are the same:\n    \\[\n        v(P) = v(D)\n    \\]\n\\end{proof}\n%\n\\subsection{Specialised duals}\n\\subsubsection{Linear programs}\n\\par Dealing with duals and Lagrangian relaxation is not easy. It is a powerful tool, but we need to solve a $\\max \\min$ problem.\n\\par There are cases where we can simplify the things a little bit. One of those cases are Linear programs.\n\\begin{equation}\n    \\min\\{cx : Ax \\geq b\\}\n\\end{equation}\nLet us compute the Lagrangian function of this problem:\n\\begin{equation}\n    L(x,\\lambda) = cx + \\lambda(b-Ax) = cx + \\lambda b - \\lambda Ax = \\lambda b + x(c - \\lambda A)\n\\end{equation}\nWe have obtained a linear function in $x$. The linear function cannot be minimised, it is always $-\\infty$. Except one case. The case when the slope of the linear function is 0. That is when we have a constant function. So we get the following:\n\\begin{equation}\n    \\psi(\\lambda) = \\min_{x \\in \\mathbb{R}^n} L(x,\\lambda) =\n    \\begin{cases}\n        -\\infty & \\mbox{ if } c - \\lambda A \\neq 0\\\\\n        \\lambda b & \\mbox{ if } c - \\lambda A = 0\n    \\end{cases}\n\\end{equation}\nSo our dual problem becomes:\n\\begin{equation}\n    (D) \\max \\{\\psi(\\lambda) : \\lambda \\geq 0\\} \\equiv \\max \\{\\lambda b : \\lambda A = c, \\lambda \\geq 0\\}\n\\end{equation}\nThis is the famous dual of the linear program from operational research.\n%\n\\subsubsection{Quadratic programs}\n\\par Another interesting special case is the quadratic program. Let us first start with the following one:\n\\begin{equation}\n    \\min\\{\\frac{1}{2}\\Vert x \\Vert^2 : Ax = b\\}\n\\end{equation}\nThe Lagrangian relaxation becomes:\n\\begin{equation}\n    L(x,\\mu) = \\frac{1}{2}\\Vert x \\Vert^2 + \\mu (Ax - b)\n\\end{equation}\nThe gradient of the Lagrangian function is then:\n\\begin{equation}\n    \\nabla L(x,\\mu) = x + \\mu A\n\\end{equation}\nSince the gradient of the Lagrangian function must be 0 in the optimum solution, we have that:\n\\begin{equation}\n    \\nabla L(x,\\mu) = x + \\mu A = 0 \\rightarrow x = -\\mu A\n\\end{equation}\nThe dual problem them becomes:\n\\begin{align}\n    \\begin{split}\\psi(\\mu) &= \\min_{x \\in \\mathbb{R}^n} L(x,\\mu) = L(-\\mu A, \\mu) = \\frac{1}{2} \\Vert -\\mu A \\Vert^2 + \\mu (A(-\\mu A) - b) =\\\\ &=\\frac{1}{2} \\mu^T AA^T \\mu - \\mu^T AA^T \\mu - b\\mu = -\\frac{1}{2}\\mu^T AA^T \\mu - b\\mu\\end{split}\\\\\n    &\\max_{\\mu \\in \\mathbb{R}^n}\\Big\\{-\\frac{1}{2}\\mu^T AA^T \\mu - b\\mu\\Big\\}\n\\end{align}\nThis is a real unconstrained problem.\n\\par Actually, more generally we could have:\n\\begin{equation}\n    \\min \\{\\frac{1}{2}x^T Q x : Ax \\geq b\\}\n\\end{equation}\nUnder the condition that $A$ is not singular, and thus invertible, we have the following dual problem:\n\\begin{equation}\n    \\max\\{\\lambda b - \\frac{1}{2} v^T Q^{-1} v : \\lambda A - v = q, \\lambda \\geq 0\\}\n\\end{equation}\n\\par All of this is very nice. Imagine that you have a lot of variables, say ten thousands, and very few constraints, say less than 10. Dealing with the dual problem means dealing with a much smaller amount of variables :).\n%\n\\subsubsection{Conic programs}\nTODO\n%\n%\n%\n\\section{Algorithms}\n\\par We are now going to study some algorithms for solving constrained optimisation programs. In particular we will see three algorithms for solving linearly constrained quadratic programs and two for linearly constrained non linear programs.\n\\par Thus we will deal with only linear constraints and the difficult part will eventually be the objective function. This is because it is much easier and because this is what we typically do in the machine learning. Sometimes when possible we will do some references to the more general non linear but convex constraints $G(x) \\leq 0$. We will exclude non linear and non convex cases. Mainly because of the time limit, but also because they are not that useful in the machine learning world. Typically if you have something that is not linear what you usually do is to approximate the non linear function with something quadratic, e.g. you use Newton. So quadratic programs are quite central.\n\\par We will not take into account equality constraints because we can always convert them into inequality constraints. Moreover, the problems with only equality constraints we know how to deal with them, since it is almost unconstrained optimisation.\n%\n\\subsection{Equality constraints for quadratic programs}\n\\par Let us start small. We have already seen quadratic programs with equality constraints. Let us look at it again, this time from the constraint optimisation point of view.\n\\par Our problem is of the following form:\n\\begin{equation}\n    \\min\\Big\\{\\frac{1}{2} x^T Q x + qx : Ax = b\\Big\\}\n\\end{equation}\nwhere $A \\in \\mathbb{R}^{m \\times n}$ with $\\mbox{rank}(A) = m < n$ and rows of $A$ linearly independent. Note that $Q \\succeq 0$ otherwise $v(P) = -\\infty$ almost always.\n\\par Note that since we have just equality constraints, there are no $\\lambda$s and thus no complementary slackness condition. The KKT system then becomes:\n\\begin{align}\n    &Ax = b\\\\\n    &\\nabla f(x) + \\mu \\nabla H = Qx + q + \\mu A = 0\n\\end{align}\nWhich becomes:\n\\begin{align}\n    &Ax = b\\\\\n    &Qx + \\mu A = -q\n\\end{align}\nWhich can be also written as:\n\\begin{equation}\n    \\begin{bmatrix}\n    Q & A^T \\\\\n    A & 0\n    \\end{bmatrix}\n    \\begin{bmatrix}\n    x\\\\\n    \\mu\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n    -q\\\\\n    b\n    \\end{bmatrix}\n\\end{equation}\nThis system is symmetric but indefinite. A lot of eigenvalues are 0. This is where Bolzano guy from Pisa comes into play.\n\\par We could solve this system directly, plain linear algebra. But we can also exploit the particularity of this system in order to craft some efficient methods to solve it. We need to be very efficient since this problem frequently appears as subprogram of a much larger program.\n\\par One of the possibility is to go by Reduced KKT. If we know that the $Q \\succ 0$ then it means that our objective function is strictly convex. We can then do the following. Let us multiply both sides of the main KKT condition by $AQ^{-1}$:\n\\begin{align}\n    &AQ^{-1}Qx + AQ^{-1}A^T\\mu = - AQ^{-1}q\\\\\n    &Ax + AQ^{-1}A^T\\mu = - AQ^{-1}q\\\\\n    &b + AQ^{-1}A^T\\mu = - AQ^{-1}q\\\\\n    &AQ^{-1}A^T\\mu = -b - AQ^{-1}q\n\\end{align}\nLet us call $M$ the matrix $AQ^{-1}A^T$. We get the following linear system:\n\\begin{equation}\n    M \\mu = - (b + AQ^{-1}q)\n\\end{equation}\nThe solution of this system ($\\mu$) can be then used to find $x$:\n\\begin{align}\n    &Qx + \\mu A^T = -q\\\\\n    &x = Q^{-1}(-A^T \\mu - q)\n\\end{align}\nThe matrix $M$ is positive semi definite and it is a square matrix ($M \\in \\mathbb{R}^{m \\times m} \\wedge M \\succeq 0$). This is particularly useful when we have very few constraints ($m$).\n\\par Another way to solve this problem is the one that we have already examined, Null Space Method. Let us divide $A$ in $[A_B,A_N]$ and $x$ in $[x_B,x_N]$ in a way that $\\text{det}(A_B) \\neq 0$. In this way $A_B$ is non singular and so we can invert it:\n\\begin{equation}\n    x_B = A_B^{-1}(b - A_N x_N) = A_B^{-1}b - A_B^{-1} A_N x_N\n\\end{equation}\nLet us now call $D = - A_B^{-1} A_N$ and $d = A_B^{-1}b$. We get then:\n\\begin{equation}\n    x_B = D x_N + d\n\\end{equation}\nwhere:\n\\begin{equation}\n    d = \\begin{bmatrix}\n    b \\\\\n    0\n    \\end{bmatrix}\n    D = \\begin{bmatrix}\n    - A_B^{-1} A_N \\\\\n    I\n    \\end{bmatrix} \\in \\mathbb{R}^{m \\times n - m}\n\\end{equation}\nThe matrix $D$ is called the basis of null space of $A$ since we have that:\n\\begin{equation}\n    A D = \\begin{bmatrix}\n    A_B & A_N \\\\\n    \\end{bmatrix} \\begin{bmatrix}\n    - A_B^{-1} A_N \\\\\n    I\n    \\end{bmatrix} = - A_B A_B^{-1} A_N + A_N I = - A_N + A_N = 0\n\\end{equation}\nLet us no multiply the KKT main condition by $D^T$:\n\\begin{equation}\n    D^T Q x + D^T A^T \\mu = -D^T q\n\\end{equation}\nBut since $x = D x_N + d$, the above equality becomes:\n\\begin{equation}\n    D^T Q (D x_N + d) = -D^T q \\Rightarrow = (D^T Q D) x_N = -D^T(Q q + d)\n\\end{equation}\nWe call $H = D^T Q D \\in \\mathbb{R}^{n-m \\times n-m}$ reduced Hessian and it is positive semi definite.\n\\par So which method is the best? It depends. Look at the matrices dimensions. If the number of constraints is almost the same as the number of variables then the second one is probably the right choice. If the two numbers are quite different and the number of overall constraints is small, then probably the first one is the one to go.\n%\n%\n%\n\\section{Projected gradient method}\n\\par Since the first algorithm that we study for unconstrained optimisation, we will also do the same for the constrained case.\n\\par This is a method that can be applied to the general non linear objective function with linear constraints:\n\\begin{equation}\n    \\min_{x \\in \\mathbb{R}^n}\\{f(x) : Ax \\leq b\\}\n\\end{equation}\nWhat we typically do is the line search. So suppose we are in a feasible solution $x$. We want to move in a direction that is feasible. Since everything is linear here (in the sense of the constraints) all the three cones that we have studied are the same. So we need to pick a direction in the first order feasible direction cone $D_X(x)$ restricted to the active constraints:\n\\begin{equation}\n    D_X(x) = \\{d \\in \\mathbb{R}^n : A_{\\mathcal{A}(x)}d \\leq 0\\}    \n\\end{equation}\nWe know that the best direction to take is the one of the opposite of the gradient in $x$. So if $\\nabla f(x) \\in D_X(x)$ then we can just line search on the direction $d = - \\nabla f(x)$. Note that if $x$ is in the interior, i.e. $\\mathcal{A}_X = \\emptyset$ then $D_X(x) = \\mathbb{R}^n$, in other words I can go wherever I want.\n\\par If the gradient does not belong to the set of first order feasible direction cone, then let us find the direction that is as close as possible to the one of the opposite of the gradient. If you think a little bit, the closest direction to $-\\nabla f(x)$, which is located outside of the cone, is the direction $d$ that goes along the boundary of the cone on the side of $-\\nabla f(x)$.\n\\par Let us do now some math. We want to project the gradient $\\nabla f(x)$ onto $\\partial D_X(x)$. Let us describe mathematically the frontier:\n\\begin{equation}\n    \\partial D_X(x) = \\{d \\in \\mathbb{R}^n : A_{\\mathcal{A}(x)} d = 0\\}\n\\end{equation}\nProjection means that we want to minimise the following problem (the closest point, the norm, man):\n\\begin{equation}\n    \\min \\Big\\{\\frac{1}{2}\\Vert \\nabla f(x) - d \\Vert^2 = \\frac{1}{2} d^T I d - d^T \\nabla f(x) : A_{\\mathcal{A}(x)}d = 0\\Big\\}\n\\end{equation}\nThis is a linearly constrained quadratic problem with a very special $Q$, that is identity matrix. Note that the identity matrix is strictly positive, that is it is positive definite. So we can use Reduced KKT to solve it in the following manner. First we get $\\mu$ by solving this system:\n\\begin{equation}\n    [A_{\\mathcal{A}(x)}A_{\\mathcal{A}(x)}^T]\\mu = A_{\\mathcal{A}(x)}\\nabla f(x)\n\\end{equation}\nThen we use $\\mu$ to find the projected direction:\n\\begin{equation}\n    d = -(A_{\\mathcal{A}(x)}^T\\mu - \\nabla f(x))\n\\end{equation}\n\\par Actually, if the matrix of the active constraints in $x$, $A_{\\mathcal{A}(x)}$, is non singular, we can also directly get $d$ by doing the following computation:\n\\begin{equation}\n    d = (I - A_{\\mathcal{A}(x)}^T(A_{\\mathcal{A}(x)}A_{\\mathcal{A}(x)}^T)^{-1}A_{\\mathcal{A}(x)})\\nabla f(x)\n\\end{equation}\n$I - A_{\\mathcal{A}(x)}^T(A_{\\mathcal{A}(x)}A_{\\mathcal{A}(x)}^T)^{-1}A_{\\mathcal{A}(x)}$ is called \\textbf{projection operator}. This operator projects our nice gradient on the boundary of the feasible region. Remember good old Poloni: householder reflection stuff.\n\\par So once we have the direction we can do the line search. Almost. $d$ can be also 0. If this is the case, and $\\mu \\geq 0$ this means that we have found the optimum. Why? Well, look at the original problem. We had $A d \\leq 0$. But since our $-\\nabla f(x)$ is not a feasible direction, we had to project it by forcing the inequality constraint into the equality constraint. So if there are no $\\mu_i$ negative, it means that all the equalities are satisfied. So we are in the optimum. But if $\\mu$ is not all positive, then it means that there is a constraint that should not be in the active set $\\mathcal{A}_(x)$. We will talk in a minute about that.\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{figures/3/chapter3-pgm.png}\n    \\caption{Projected Gradient Method.}\n    \\label{fig:chapter3-pgm}\n\\end{figure}\n\\par The algorithm is shown in figure \\ref{fig:chapter3-pgm}. Let us now go through the algorithm. You start at a point $x$. The first thing that you do is to construct the set of the active constraints in $x$. We take the maximal set of active constraints such that the rank of that set is full rank. We must do this because it is the only way to force non singularity of the matrix $A_B A_B^T$. We annotate that maximal subset of $\\mathcal{A}(x)$ with $B$ in the algorithm. Note that we may clearly leave apart some of the active constraints in $x$, and we will have to deal with that. So now we compute the direction $d$. Such direction can either be 0 or not. So if it is 0, then we check if $\\mu \\geq 0$. We set to 0 all the entries of $\\mu$ whose corresponding active constraint has not been included in $B$ previously. In case $\\mu \\geq 0$, we are done. Otherwise we find the entry with negative value in $\\mu$ that has the lowest index and we throw from $B$ the corresponding constraint. Yes. We just ignore it. And we repeat. Two cases eventually happen. Either we end up again with $d = 0$ and the whole process repeats until we get out from the whole procedure because we hit $\\mu \\geq 0$ or we find a $d \\neq 0$. In this last case we proceed in the algorithm. Since we left some of the constraints out of the set $B$ we now must verify that the direction that we found does not violate some of the constraints out of $B$. We take the step size along each such constraint and then we take the minimum of those values. If the minimum is greater than 0, it means we can proceed along $d$. If $d \\leq 0$ it means that some of the constraints is active but not in $B$. So we include that constraint and we repeat.\n\\par Let us now state without proving some of the properties about PGM. First of all, the addition of the constraints in $B$ preserve the linear independence. That is we do not risk to make $B$ singular. It is also not possible to have the add/remove process cyclical. That is the process of addition and removal of constraints eventually terminates. This is called \\textbf{Bland's anti-cycle rule}. Maximal $B$ is easy to get, just do the greedy algorithm. Each constraint either we put it or not in $B$ depending on whether it is linearly independent from all the constraints already belonging to $B$. How? For each matrix that you form with a new vector, check that the determinant of that matrix is not 0.\n\\par Note that if $f$ is a simple linear function, then PGM is just the \\textbf{Primal Simplex Method}.\n\\par Sometimes in ML the constraints are much easier than the general constraints. One of the easiest types of constraints is called \\textbf{box constraints}. Each variable belongs to an interval of values, $l \\leq x \\leq u$. If we have a non linear program with box constraints, the algorithm becomes much more simpler (see figure \\ref{fig:chapter3-pgm_box}).\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.4]{figures/3/chapter3-pgm_box.png}\n    \\caption{Projected Gradient Method with Box Constraints.}\n    \\label{fig:chapter3-pgm_box}\n\\end{figure}\n\\par For each box constraint, if it is active then $x$ is either $l$ or $u$. So the set of active constraints is always linearly independent. How this algorithm works? We start with the direction opposite of the gradient. For each entry $i$ of the direction vector $d$ that is $\\neq 0$ (remember, we want $d$ to be 0 in order to terminate), we do the following: if $d_i < 0$ we need to lower a bit $x_i$. But if $x_i = l_i$ we just set it to 0 since we cannot go anymore down. Otherwise we calculate the minimum step size for the new direction by taking the minimum between the previous minimum step sizes and the current one. The same process applies for $d_i > 0$.\n%\n%\n%\n\\section{Active-set method for Quadratic Programming with linear inequalities}\n\\par Suppose now we have a quadratic program with linear inequalities. If we knew which were the active constraints in the optimal solution $x^*$ we would just apply linear algebra and the world would be a better place. But unfortunately we don't know that. We like, especially in ML, to guess when we don't know exactly the things. We need also to be prepared to also revise our estimates.\n\\par The algorithm is shown in figure \\ref{fig:chapter3-asmqp}. Let us go through it. The first thing that we note is that we do not require that the matrix $B$ contains just linearly independent set of active constraints. Note that this set can also be empty, i.e. $B = \\emptyset$. What we do then is to solve the linear equality constrained quadratic program. Note that we are hiding the concept of $B$ being full rank inside that subroutine. The rest is quite straightforward. If $\\bar{x}$ is a feasible solution, then we have found the optimum if $\\mu_B \\geq 0$. Note that we know that it is optimal on $A_B$, so we need to check only the constraints not in $B$. If this is not the case we proceed as in the case of the projected gradient method. The only thing to say here is that as you can see we do not need to do any line search. This is because we are in the case of the quadratic program. We can just take the maximum step size in the descent direction.\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.4]{figures/3/chapter3-asmqp.png}\n    \\caption{Active set method for quadratic programming}\n    \\label{fig:chapter3-asmqp}\n\\end{figure}\n\\par This method can be also extended to $f$ general, that is not necessarily quadratic. What changes is how we solve the subproblem. We could use for instance quasi-Newton.\nTODO box contraints\n%\n%\n%\n\\section{Frank Wolfe method, aka Conditional Gradient}\n\\par The main difficulty with projected gradient method and active set method is the active set. Frank Wolfe tries to do without it at all. We will deal here with non linear programs with linear constraints. \n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{figures/3/chapter3-fwm.png}\n    \\caption{Frank Wolfe Method, also called Conditional Gradient Method.}\n    \\label{fig:chapter3-fwm}\n\\end{figure}\n\\par The idea of Frank Wolfe is quite simple (figure \\ref{fig:chapter3-fwm}. It assumes there is someone else that can deal with the linear problem and let us concentrate only on the non linear part of the problem which is in the objective function. It iteratively approximate the our nasty function with the first order linear model, minimise this program in the admissible region and take that direction as the direction of descent.\n\\par Another thing worth mentioning is that we do not need to compute the maximum step size. We just set it to 1.\n\\par This algorithm is particularly easy to implement but unfortunately it is not that good when it comes to the convergence. This is because we trust the linear model on the whole admissible region. It is accurate locally to $x$ but probably this is not the case when we look at the whole admissible region. What we can do to improve the convergence is the stabilisation.\nTODO\n%\n%\n%\n\\section{Dual Methods}\n\\par Frank Wolfe completely hides Lagrangian multipliers. Suppose again we have a quadratic program with linear constraints.", "meta": {"hexsha": "1be6d28fd6250ff3e0fcaa28736895919e17502c", "size": 56614, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/3-constrained.tex", "max_stars_repo_name": "ig92/CM4LDA", "max_stars_repo_head_hexsha": "47b323730a9d47edbba3f5ddc64fe9ad6dc70f4e", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/3-constrained.tex", "max_issues_repo_name": "ig92/CM4LDA", "max_issues_repo_head_hexsha": "47b323730a9d47edbba3f5ddc64fe9ad6dc70f4e", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/3-constrained.tex", "max_forks_repo_name": "ig92/CM4LDA", "max_forks_repo_head_hexsha": "47b323730a9d47edbba3f5ddc64fe9ad6dc70f4e", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 83.6248153619, "max_line_length": 1720, "alphanum_fraction": 0.7207051259, "num_tokens": 16209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7160127035465265}}
{"text": "\n\\subsection{The Generalised Least Squares (GLS) estimator}\n\n\\subsubsection{Introduction}\n\nWe make the same assumptions as OLS.\n\n\\(\\mathbf {y}=\\mathbf {X}\\theta+\\boldsymbol {\\epsilon }\\)\n\nWe assume:\n\n\\begin{itemize}\n\\item \\(E[\\epsilon |\\boldsymbol X]=0\\)\n\\item \\(Cov [\\epsilon |\\boldsymbol X]=\\boldsymbol \\Omega \\)\n\\end{itemize}\n\n\\subsubsection{The GLS estimator}\n\nGLS estimator is:\n\n\\(\\hat \\theta_{GLS} = argmin_b (y-Xb)^T\\Omega^{-1}(y-Xb)\\)\n\n\\(\\hat \\theta_{GLS}=(X^T\\Omega ^{-1}X)^{-1}X^T\\Omega^{-1}y\\)\n\nThis is the vector that minimises the Mahalanobis distance.\n\nThis is equivalent to doing OLS on a linearly transformed version of the data.\n\n\\subsubsection{Identifying \\(\\Omega \\)}\n\nIf \\(\\Omega \\) is known, we can proceed. Generally, however, \\(\\Omega \\) is not known, and so the GLS estimate in infeasible.\n\n", "meta": {"hexsha": "a7a53938e9b6d49c1f09f7f7cb5c6227730d0ecb", "size": 815, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/gls/01-01-gls.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/gls/01-01-gls.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/gls/01-01-gls.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.696969697, "max_line_length": 125, "alphanum_fraction": 0.6981595092, "num_tokens": 257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.7160127005728352}}
{"text": "\\chapter{The Legendre-Jacobi-Kronecker Symbol}\n\\label{chap:appA}\nAll the symbols with the form $\\left(\\frac{a}{b}\\right)$ I used in the paper are Kronecker Symbols. But first, let us review the definition and some properties of Legendre symbol.\n\\section{The Legendre Symbol}\nIn number theory, the Legendre symbol is a multiplicative function with values {1,-1,0} that is a quadratic character modulo an \\textbf{odd} prime number $p$: its value on a (nonzero) quadratic residue mod p is 1 and on a non-quadratic residue (non-residue) is −1. Its value on zero is 0. \nFurthermore, one can easily show that this symbol has the following properties:\n\\begin{proposition}\n\\begin{enumerate}\n\\item The Legendre symbol is periodic, if $a\\equiv b(\\text{mod }p)$, then $$\\left(\\frac{a}{p}\\right)=\\left(\\frac{b}{p}\\right)$$\n\\item The Legendre symbol is multiplicative, i.e. $$\\left(\\frac{a}{p}\\right)\\left(\\frac{b}{p}\\right)=\\left(\\frac{a b}{p}\\right)$$\n\\item We have the congruence $a^{(p-1)/2}\\equiv \\left(\\frac{a}{p}\\right)(\\text{mod }p).$\n\\item There are as many quadratic residues as non-residues mod $p$, say $(p-1)/2$.\n\\item Let $p$ be an odd prime, then $$\\left(\\frac{-1}{p}\\right)=(-1)^{(p-1)/2}, \\left(\\frac{2}{p}\\right)=(-1)^{(p^2-1)/8}$$\n\\item Let $p,q$ be two different odd primes, then we have reciprocity law: $$\\left(\\frac{p}{q}\\right)\\left(\\frac{q}{p}\\right)=(-1)^{(p-1)(q-1)/4}$$\n\\end{enumerate}\n\\end{proposition}\n\n\\section{The Kronecker Symbol}\nNow we extend the definition of the Legendre symbol \\citep{cohen1993course}.\n\\begin{definition}\nwe define the Kronecker (or Kronecker-Jacobi) symbol $\\left(\\frac{a}{b}\\right)$ for any $a$ and $b$ in $\\mathbb{Z}$ as follows:\n\\begin{enumerate}\n\\item If $b=0$, then $\\left(\\frac{a}{0}\\right)=1$ if $a=\\pm1$, and is equal to 0 otherwise.\n\\item For $b\\neq0$, firstly $\\left(\\frac{a}{1}\\right)=1$. For other case write $b=\\prod p$, where $p$ are not necessarily distinct primes (including $p=2$), or $p=-1$ to take care of sign. The we set $$\\left(\\frac{a}{b}\\right)=\\prod\\left(\\frac{a}{p}\\right),$$ where $\\left(\\frac{a}{p}\\right)$ is the Legendre symbol defined above for $p>2$, and where $p=2$ we define: $$\\left(\\frac{a}{2}\\right)=\\left\\{\\begin{array}{cc} 0, & \\text{if } a \\text{ is even}\\\\\n(-1)^{(a^2-1)/8}, &  \\text{if } a \\text{ is odd.}\n\\end{array}\\right.$$\nand also $$\\left(\\frac{a}{-1}\\right)=\\left\\{\\begin{array}{cc} 1, & \\text{if } a\\geq0\\\\\n-1, &  \\text{if } a<0.\n\\end{array}\\right.$$\n\\end{enumerate}\n\\end{definition}\n\nAlso the Kronecker symbol has the following simple properties:\n\\begin{proposition}\n\\begin{enumerate}\n\\item $\\left(\\frac{a}{b}\\right)=0$ iff $(a,b)\\neq1$\n\\item for all $a,b,c$, if $b c\\neq0$, we have $$\\left(\\frac{ab}{c}\\right)=\\left(\\frac{a}{c}\\right)\\left(\\frac{b}{c}\\right), \\left(\\frac{a}{bc}\\right)=\\left(\\frac{a}{b}\\right)\\left(\\frac{a}{c}\\right)$$\n\\end{enumerate}\n\\end{proposition}", "meta": {"hexsha": "85b02587e2543eeab003e6d67e46e69d795334d3", "size": 2864, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/chap-appA.tex", "max_stars_repo_name": "daidahao/sustcthesis", "max_stars_repo_head_hexsha": "af536c6559c5a8a3c1315438b99d166153665187", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2019-03-17T08:46:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-12T02:50:26.000Z", "max_issues_repo_path": "chapter/chap-appA.tex", "max_issues_repo_name": "daidahao/sustcthesis", "max_issues_repo_head_hexsha": "af536c6559c5a8a3c1315438b99d166153665187", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter/chap-appA.tex", "max_forks_repo_name": "daidahao/sustcthesis", "max_forks_repo_head_hexsha": "af536c6559c5a8a3c1315438b99d166153665187", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-06-17T06:55:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-17T01:21:27.000Z", "avg_line_length": 73.4358974359, "max_line_length": 455, "alphanum_fraction": 0.6735335196, "num_tokens": 1010, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.715971153248044}}
{"text": "\\section*{Number State}\n\\begin{itemize}\n\\item [$\\ket{n}$:] \\emph{number} state with exactly $n$ quanta (AKA Fock)\n\\item [$\\qOpAnnihilation\\ket{n} = \\sqrt{n}\\ket{n-1}$:] \\emph{annihilation}\n  operator $\\qOpAnnihilation$ removes a quanta\n  (AKA destruction, lowering)\n\\item [$\\qOpCreation\\ket{n} = \\sqrt{n+1}\\ket{n+1}$:] \\emph{creation}\n  operator $\\qOpCreation$ introduces a quanta\n  (AKA raising)\n\\item [$\\qOpNumber\\ket{n} \\equiv \\qOpCreation\\qOpAnnihilation\\ket{n} =\n  n\\ket{n}$:] \\emph{number} operator $\\qOpNumber \\equiv \\qOpCreation\\qOpAnnihilation$ counts quanta\n\\item [$\\ket{n} = (n!)^{-1/2} (\\qOpCreation)^n\\ket{0}$:] generate number\nstate $\\ket{n}$ from a vacuum state $\\ket{0}$\n\\end{itemize}\n\n\\subsection*{Commutators}\n\\begin{itemize}\n\\item [$\\commutator{\\qOpAnnihilation}{\\qOpCreation} = 1$]\n\\item [$\\commutator{\\qOpAnnihilation}{(\\qOpCreation)^n} =\n  n(\\qOpAnnihilation^\\dagger)^{n-1}$] \n\\item [$\\commutator{\\qOpAnnihilation^n}{\\qOpCreation} =\n  n(\\qOpAnnihilation)^{n-1}$] \n\\item [$\\commutator{\\qOpAnnihilation}{\\exp(\\beta\\qOpCreation)} =\n  \\beta(\\exp(\\beta\\qOpCreation)$]  \n\\end{itemize} ", "meta": {"hexsha": "d7f2a7b19556173f96ef1f567420699fb7ce2830", "size": 1101, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CheatSheets/Series/Quantum-Information-Processing/units/unit_NumberStates.tex", "max_stars_repo_name": "tcburt/hodudodi", "max_stars_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CheatSheets/Series/Quantum-Information-Processing/units/unit_NumberStates.tex", "max_issues_repo_name": "tcburt/hodudodi", "max_issues_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-18T22:55:02.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-18T23:01:00.000Z", "max_forks_repo_path": "CheatSheets/Series/Quantum-Information-Processing/units/unit_NumberStates.tex", "max_forks_repo_name": "tcburt/hodudodi", "max_forks_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.04, "max_line_length": 99, "alphanum_fraction": 0.6884650318, "num_tokens": 408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7159283923873443}}
{"text": "\\section{Deep Learning}\n\n% ===\n%\\textbf{Sigm.:}\\enskip\n%$\\sigma(x) = \\frac{1}{1+\\eu^{-x}} = \\frac{\\eu^x}{\\eu^x + 1}$;\\enskip\n%$\\sigma'(x) = \\sigma(x) \\sigma(-x)$\n\n\\textbf{Sigmoid:}\\enskip\n$\\sigma(x) = \\frac{1}{1+\\exp(-x)} = \\frac{\\eu^{x}}{\\eu^{x}+1}$ \\\\\n\\phantom{\\textbf{Sigmoid:}}\n$\\sigma'(x) = \\sigma(x) (1{-}\\sigma(x)) = \\sigma(x) \\sigma(-x)$\n\n\\textbf{Softmax:}\\enskip\n$y_i \\propto \\exp(\\beta z_i)$\n\n\n\\emph{Backpropagation:}\n\\hfill\nGradient:\n$\\pderiv{\\ell}{w_{jk}} = \\delta_j^{(l)} v_k^{(l-1)}$\n\n\\vspace{-4pt}\nError signal for unit $k$ on layer $l$:\\\\\n\\enskip $\\delta^{(L)} = [ \\cdots \\delta_k^{(L)} \\cdots ] = [ \\cdots \\ell'_k(f_k) \\cdots ]$\\\\\n\\enskip $\\delta_k^{(l)} = \\sigma'(z_k) \\sum_{j \\in \\mathrm{layer}(l+1)} w_{jk} \\delta_j$\n\n% Error signal for each unit $k$ on output layer $L$: \\\\\\enskip\n% $\\delta^{(L)} = [ \\cdots \\delta_k^{(L)} \\cdots ] = [ \\cdots \\ell'_k(f_k) \\cdots ]$\n\n% Error signal on layer $l = L{-}1, \\ldots, 1$: \\\\\\enskip\n% $\\delta_k^{(l)} = \\sigma'(z_k) \\sum_{j \\in \\mathrm{layer}(l+1)} w_{jk} \\delta_j$\n\n\n\\emph{Robbins-Monro Algorithm {\\textnormal\\sffamily for SGD}:}\n\n\\textbf{Goal:}\\enskip\n$\\min_\\theta \\E[Z]{f(Z; \\theta)}\n\\color{gray} \\approx \\frac1n \\sum_i \\mathcal L(y_i, \\mathrm{NN}_\\theta(\\bm x_i))$\n\n\\textit{Input:}\\enskip\nlearn. rate $\\eta(k)$,\\enskip samples $\\bm z_1, \\bm z_2, \\ldots \\sim Z$\n\n\\textit{Iteratively:}\\enskip\n$\\theta^{(k)} \\leftarrow \\theta^{(k-1)} - \\eta(k) f(\\bm z_k; \\theta^{(k-1)})$ \\\\\\enskip\n$\\color{gray}\\text{for SGD:}\\enskip f(\\bm z, \\theta) = \\nabla_\\theta \\mathcal L(y, \\mathrm{NN}_\\theta(\\bm x))$\n\n\\textbf{Convergence:}\\enskip\nif $\\E[Z]{f(\\bm z, \\theta)}$ satisfies some regulatory conditions and $\\eta(k)$ c.f. section \\ref{purely-discriminative}.\n\n% ===\n\\subsection{Variational Autoencoders}\n\n%\\textbf{Define} prior $p_{\\theta'}(z)$, likelihood $\\mathrm{dec}_\\theta(z) = p_\\theta(x\\mid z)$ and approx. posterior $\\mathrm{enc}_\\phi(x) = q_\\phi(z\\mid x)$.\n\n\\textbf{Def:}\n$\\xrightarrow[\\text{prior}]{p_{\\theta'}(z)} \\mathcal Z\n\\xrightarrow[\\text{likelihood}]{\\mathrm{dec}_\\theta(z) = p_\\theta(x\\mid z)} \\mathcal X\n\\xrightarrow[\\text{approx. posterior}]{\\mathrm{enc}_\\phi(x) = q_\\phi(z\\mid x)} \\mathcal Z$\n\n\\hfill sample/obs. $\\mathcal X_i$ from latent representation $\\mathcal Z$\n\n\\textbf{Train:}\\enskip\n$\\max\\limits_{\\theta', \\theta, \\phi} \\sum_{i} \\color{OrangeRed} { \\underbracket[.7pt][2pt]{\\the\\everymath \\log p_{\\theta', \\theta} (x_i)} }_{\\:(\\ast) \\text{ indep. of } Z}$\n\n%$\\log p_{\\theta', \\theta, \\phi} (x_i) = \\ldots$\n\\begin{itemize}[leftmargin=20pt,parsep=0.2pt]\n    \\item[${\\color{OrangeRed}(\\ast)} =$]\n        $\\E*[Z \\sim q_\\phi(\\cdot \\mid x_i)]{\\log\\paren*{ \\frac{p_{\\theta', \\theta}(x_i,Z)}{p_{\\theta', \\theta}(Z\\mid x_i)} \\; \\frac{q_\\phi(Z\\mid x_i)}{q_\\phi(Z\\mid x_i)} }}$\n    \\item[$=$]\n        $\\overbracket[.7pt][2pt]{\n            \\E*{\\log p_\\theta(x_i\\mid Z)}\n            - D\\ped{KL}\\paren*{q_\\phi(\\cdot\\mid x_i) \\parallel p_{\\theta'}(\\cdot)}\n        }^{\\begingroup\\color{Green} \\mathcal L(x_i,\\theta,\\phi) \\endgroup \\:\\equiv\\: \\text{\\textbf{ELBO} = Infomax -- Regularisation term}}$\n    \\item[]\n        $+ D\\ped{KL}\\paren*{q_\\phi(\\cdot\\mid x_i) \\parallel p_{\\theta', \\theta}(\\cdot\\mid x_i)}\n        \\color{Green} \\geq \\mathcal L(x_i, \\theta, \\phi)$\n\\end{itemize}\n\n\\textbf{Train:}\\enskip\n\\highlight{$\\theta^\\ast, \\phi^\\ast = \\arg\\max_{\\theta,\\phi} \\mathcal L(x_i, \\theta, \\phi)$}\n\nRequirements for good representation:\n\\begin{itemize}\n    \\item \\textbf{informative:}\\enskip\n        $\\theta^\\ast = \\arg\\max_\\theta I(X;Z)$\\\\\n        $\\enskip \\color{gray} = \\arg\\max_\\theta \\E[X,Z]{\\log p(X\\mid Z)} - \\textit{const}_{\\textit{w.r.t. } \\theta}$\\\\\n        $\\enskip \\approx \\arg\\max_\\theta \\sum_i \\E[Z\\mid X]{\\log p(x_i\\mid Z)}$\n    \\item \\textbf{disentangled:}\\enskip\n        components in $\\mathcal Z$ associated with distinct feature in $\\mathcal X$\n        (see $D\\ped{KL}$ in ELBO).\n    \\item \\textbf{robust:}\\enskip\n        noise in $\\mathcal Z$ doesn't substantially affect $\\mathcal X$ (and vice versa).\n        $\\to$ choice of approx. post.!\n\\end{itemize}\n\n% ===\n", "meta": {"hexsha": "0bf727e4c9f6090f088361dfb8bb3c36fc09bad1", "size": 4043, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/AML20/sections/08_deep_learning.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/AML20/sections/08_deep_learning.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/AML20/sections/08_deep_learning.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.6804123711, "max_line_length": 173, "alphanum_fraction": 0.6089537472, "num_tokens": 1587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818864, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.7159283852875634}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=2}^\\infty \\frac{1}{n^2-1}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution 1}\r\n\r\nNote $2 \\leq n^2$ for all positive integers $n \\geq 2$. By adding $n^2$ to both sides,\r\n\\[ n^2 + 2 \\leq 2n^2.\\]\r\nBy subtracting $1$ from both sides,\r\n\\[ n^2 \\leq 2n^2-2\\]\r\nFactoring the right side,\r\n\\[ n^2 \\leq 2(n^2-1)\\]\r\nDividing both sides by $n^2(n^2-1)$ we get\r\n\\[ \\frac{1}{n^2-1} \\leq \\frac{2}{n^2}.\\]\r\nSince the series $\\sum \\frac{2}{n^2}=2\\sum\\frac{1}{n^2}$ converges by the $p$-test, the series $\\displaystyle \\sum_{n=2}^\\infty \\frac{1}{n^2-1}$ converges by the Direct Comparison Test.\r\nSince all terms of the series are positive, the series $\\displaystyle \\sum_{n=2}^\\infty \\frac{1}{n^2-1}$ converges absolutely.\r\n\r\n\\subsection*{Solution 2}\r\n\r\nThe series $\\sum \\frac1{n^2}$ converges by the $p$-test. Let $a_n = \\frac1{n^2-1}$ and $b_n=\\frac1{n^2}$. Then\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} \\frac{a_n}{b_n}\r\n&= \\lim_{n \\to \\infty} \\frac{n^2}{n^2-1}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{2n}{2n} \\text{ by L'hopital}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac11\\\\\r\n&= 1\r\n\\end{align*}\r\nSince this limit is a finite, positive number, by the Limit Comparison Test, the series $\\displaystyle \\sum_{n=2}^\\infty \\frac{1}{n^2-1}$ converges.\r\nSince all terms of the series are positive, the series $\\displaystyle \\sum_{n=2}^\\infty \\frac{1}{n^2-1}$ converges absolutely.\r\n\r\n\\subsection*{Solution 3}\r\n\r\nBy partial fraction decomposition, we get\r\n\\[ \\frac1{n^2-1} = \\frac{1/2}{n-1} - \\frac{1/2}{n+1}.\\]\r\nSo, the originally given series can be rewritten as\r\n\\[\\sum_{n=2}^\\infty \\left(\\frac{1/2}{n-1} - \\frac{1/2}{n+1}\\right)\\]\r\nAfter cancellations, we get the sequence of partial sums:\r\n\\[ s_n = \\frac{1/2}{1} + \\frac{1/2}{2} - \\frac{1/2}{n} - \\frac{1/2}{n+1}\\]\r\nThus,\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} s_n\r\n&= \\lim_{n \\to \\infty} \\left(\\frac{1/2}{1} + \\frac{1/2}{2} - \\frac{1/2}{n} - \\frac{1/2}{n+1}\\right)\\\\\r\n&= \\frac{1/2}{1} + \\frac{1/2}{2}\\\\\r\n&= \\frac12 + \\frac14\\\\\r\n&= \\frac34.\r\n\\end{align*}\r\nSo, the series converges (by definition) to $\\frac34$.\r\n\r\nSince all terms of the series are positive, the series $\\displaystyle \\sum_{n=2}^\\infty \\frac{1}{n^2-1}$ converges absolutely.\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\left|\\frac{a_{n+1}}{a_n}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\right|\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} a_n\r\n&= \\lim_{n \\to \\infty} \\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} \\frac{a_n}{b_n}\r\n&= \\lim_{n \\to \\infty} \\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "20749d5fcd2780bbf53fe100d1769f96488c5f25", "size": 3212, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/g1.tex", "max_stars_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_stars_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "key/series/g1.tex", "max_issues_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_issues_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "key/series/g1.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 35.2967032967, "max_line_length": 186, "alphanum_fraction": 0.6235990037, "num_tokens": 1259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.787931185683219, "lm_q2_score": 0.9086178901278738, "lm_q1q2_score": 0.7159283715014403}}
{"text": "\\subsection{Clauses and horn clauses}\n\nA clause is a disjunction of atomic formulae.\n\n\\(A\\lor \\neg B\\lor C\\)\n\nThis can be written in implicative form.\n\n\\((A\\lor \\neg B)\\lor C\\)\n\n\\(\\neg (A\\lor \\neg B)\\rightarrow C\\)\n\n\\((\\neg A\\land B)\\rightarrow C\\)\n\nA horn clause is a clause where there is at most one positive literal. This means the implicative takes the form.\n\n\\((A\\land B\\land C )\\rightarrow X\\).\n\n\\subsection{Inference with horn clauses}\n\nIf the horn clause is true, and so is the normal form part, then \\(X\\) is also true.\n\nAs all inference with horn clauses uses Modus Ponens, it is sound.\n\nInference with horn clauses is also complete.\n\n\n", "meta": {"hexsha": "8fd23ed163bb56dbd44a88b13e0d55951d977ec0", "size": 647, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogicInference/01-05-horn.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/propositionalLogicInference/01-05-horn.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/propositionalLogicInference/01-05-horn.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.1071428571, "max_line_length": 113, "alphanum_fraction": 0.7187017002, "num_tokens": 178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7157956147718257}}
{"text": "\\section{Orthogonality}\n\n\\subsection{}\n\n  Recall that \n\n  \\begin{equation}\n    \\vec{v}\\cdot\\vec{w}=v_1\\cdot w_1+\\ldots+v_n\\cdot w_n = | | \\vec{v} | | | | \\vec{w} | | \\cos(\\theta)\n  ,\\end{equation}\n\n  where $\\theta$ is the angle between $\\vec{v}$ and $\\vec{w}$. Because $\\cos\\left(\\frac{\\pi}{2}\\right)=0$, we know that $\\vec{v}\\cdot\\vec{w}=0$ if and only if $\\vec{v}$ is orthogonal to $\\vec{w}$. In general, given $\\vec{v},\\vec{w}\\in\\R^n$, $\\vec{v}$ is orthogonal to $\\vec{w}$ if and only if the angle between them is $\\frac{\\pi}{2}$.\n\n  \\begin{definition}\n    Let $U$ be any inner product space. A basis $\\vec{u},\\ldots,\\vec{u_h}\\in V$ is orthogonal if $\\vec{u_j}\\cdot \\vec{u_i} = 0$ whenever $i\\neq j$.\\newline\n    In addition, if $| |u_i| |=1$ for all $i$'s, the basis is orthonormal.\n  \\end{definition}\n  \n  Here are a few examples of orthonormal and orthogonal basis's:\n\n  \\begin{enumerate}\n    \\item $\\SmallMatrix{1\\\\0}\\SmallMatrix{0\\\\1}$ is an orthonormal basis.\n    \\item $\\SmallMatrix{2\\\\0}\\SmallMatrix{0\\\\1}$ is an orthogonal basis.\n    \\item $\\SmallMatrix{1\\\\0\\\\0}\\SmallMatrix{0\\\\1\\\\0}\\SmallMatrix{0\\\\0\\\\1}$ is an orthonormal basis.\n  \\end{enumerate}\n\n  If $\\vec{v_1},\\ldots,\\vec{v_n}$ is an orthogonal basis, then \n\n  \\begin{equation}\n    \\frac{\\vec{v_1}}{| |\\vec{v_1}| |},\\frac{\\vec{v_2}}{| | \\vec{v_2} | |},\\ldots,\\frac{\\vec{v_n}}{| | v_n | |}\n  \\end{equation}\n  is an orthonormal basis.\n\n  \\begin{problem}\n    Consider $\\vec{u_1}=\\SmallMatrix{1\\\\2}$ and $\\vec{u_2}=\\SmallMatrix{2\\\\-1}$. We know that these two matrices are not linearly dependent because $\\vec{u_1}$ is not a multiple of $\\vec{u_2}$. We can see that this is an orthogonal basis.\n    \\begin{equation}\n      | | \\vec{u_1} | | = \\sqrt{1^2+2^2} =\\sqrt{5} \n    \\end{equation}\n\n    so we know\n\n    \\begin{equation}\n      v_1=\\begin{pmatrix} \\frac{1}{\\sqrt{5} }\\\\\\frac{1}{\\sqrt{5} } \\end{pmatrix} ,v_2=\\begin{pmatrix} \\frac{1}{\\sqrt{5} }\\\\\\frac{1}{\\sqrt{5} } \\end{pmatrix} \n    \\end{equation}\n  \\end{problem}\n\n  \\begin{prop}\n    Assume $\\vec{v_1},\\ldots,\\vec{v_n}\\in V$ with $\\vec{v_i}\\neq \\vec{0}$ for all $i$. Assume that $<v_i,v_j\\ge 0$ whenever $i\\neq j$, then $\\{v_1,\\ldots,v_n\\}$ is linearly independent.\n    \\begin{proof}\n      Assume that $c_1\\vec{v_1}+\\ldots+c_n\\vec{n}=0$. Let $i\\in\\{1,\\ldots,n\\}$\n      \\begin{align*}\n        <c_1\\vec{v_1}+\\ldots+c_n \\vec{v_n}, v_i> = <0,\\vec{v_i}>\\\\\n        c_1<v_1,v_i> + c_2<v_2,v_i>+\\ldots+ c_i<v_i,v_i>+\\ldots+c_n<v_i,v_n>\\\\\n        c_i<v_i,v_i> = 0\\\\\n        c_i = 0\n      .\\end{align*}\n      Now we know that $v_1,\\ldots,v_n$ are linearly independent.\n    \\end{proof}\n  \\end{prop}\n\n  \\begin{corollary}\n    If $dim(v)=n$ and $\\vec{v_1},\\ldots,\\vec{v_n}$ are $n$ vectors such that $<v_i,v_j> = 0$ wherever $i\\neq j$, then $\\{\\vec{v_1},\\ldots,\\vec{v_n}\\}$ is a basis.\n  \\end{corollary}\n\n  \\begin{theorem}\n    Let $\\vec{u_1},\\ldots,\\vec{u_n}$ be an orthonormal basis for $v$. Let $\\vec{v}\\in V$. Then we know $\\vec{v}=c_1\\vec{u_1}+\\ldots+c_n \\vec{u_n}$. In fact, $c_i=<\\vec{v},\\vec{u_i}>$ and \n    \\begin{equation}\n      | |\\vec{v} | | = \\sqrt{<\\vec{v},\\vec{u_1},>^2+<\\vec{v},\\vec{u_2}^2 + <\\vec{v},\\vec{u_n}>^2}.\n    \\end{equation}\n  \\end{theorem}\n\n  \\begin{problem}\n    $\\mathbb{P}^2$ polynomials of degree $\\le 2$ on [0,1]. Use the $L^2$ norm.\n\n    \\begin{equation}\n      <p,q> = \\int_0^{1}p(x)q(x)dx\n    \\end{equation}\n\n    Let $p_1=1,p_2=x-\\frac{1}{2},p_3=x^2-x+\\frac{1}{6}$.\n\n    \\begin{align}\n      <p_1,p_2> &= \\int_0^{1}x-\\frac{1}{2}dx=0\\\\\n      <p_1,p_3>&=\\int_0^{1}x^2-x+\\frac{1}{6}dx=0.\n    \\end{align}\n\n    We have an orthogonal basis because of this. In order to check to see if it is orthonormal we must also do $<p_1,p_1>,<p_2,p_2>,<p_3,p_3>$\n  \\end{problem}\n  INSERT NOTES FROM 03.08 HERE\n\n  So if we have the basis $\\{\\SmallMatrix{1\\\\2},\\SmallMatrix{2\\\\1}\\}, v_1=\\SmallMatrix{1\\\\2}$. $v_2$ is equal to \n\n  \\begin{align*}\n    \\begin{pmatrix} 2\\\\1 \\end{pmatrix} -\\frac{\\Big<\\begin{pmatrix} 2\\\\1 \\end{pmatrix} , \\begin{pmatrix} 1\\\\2 \\end{pmatrix} \\Big>}{| | \\begin{pmatrix} 1\\\\2 \\end{pmatrix} }\\cdot \\begin{pmatrix} 1\\\\2 \\end{pmatrix} \\\\\n    \\begin{pmatrix} 2\\\\1 \\end{pmatrix} -\\frac{4}{\\left(\\sqrt{1^2+2^2} \\right)^2 }\\\\\n    \\begin{pmatrix} 2\\\\1 \\end{pmatrix} -\\frac{4}{5}\\begin{pmatrix} 1\\\\2 \\end{pmatrix}\\\\ \n    \\begin{pmatrix} 2\\\\1 \\end{pmatrix} -\\begin{pmatrix} \\frac{4}{5}\\\\ \\frac{8}{5} \\end{pmatrix} = \\begin{pmatrix} \\frac{10}{5}\\\\\\frac{5}{5} \\end{pmatrix} -\\begin{pmatrix} \\frac{4}{5}\\\\\\frac{8}{5} \\end{pmatrix} \\\\\n    =\\begin{pmatrix} \\frac{6}{3} \\\\ -\\frac{3}{5}\\end{pmatrix} \n    \\SmallMatrix{2\\\\1}-\\frac{<\\SmallMatrix{2\\\\1}, \\SmallMatrix{1\\\\2}>}{| | \\SmallMatrix{1\\\\2}| | ^2}\\cdot \\SmallMatrix{1\\\\2}\n    \\SmallMatrix{2\\\\1}-\\frac{4}{(\\sqrt{1^2+2^2} )^2}\\\\\n    \\SmallMatrix{2\\\\1} - \\frac{4}{5}\\SmallMatrix{1\\\\2}\\\\\n    \\SmallMatrix{2\\\\1}-\\SmallMatrix{\\frac{4}{5}\\\\\\frac{8}{5}}=\\SmallMatrix{\\frac{10}{5}\\\\\\frac{5}{5}}-\\SmallMatrix{\\frac{4}{5}\\\\\\frac{8}{5}}\\\\\n    \\SmallMatrix{\\frac{6}{3}\\\\-\\frac{3}{5}}\\\\\n  .\\end{align*}\n\n  We can conclude that our basis is $\\{\\SmallMatrix{1\\\\2},\\SmallMatrix{\\frac{6}{5}\\\\-\\frac{3}{5}}\\}$. Let's now use our basis and rewrite it as\n  \\[\n  \\begin{pmatrix} 2\\\\3 \\end{pmatrix} =c_1\\begin{pmatrix} 1\\\\2 \\end{pmatrix} +c_2\\begin{pmatrix} \\frac{6}{5}\\\\-\\frac{3}{5} \\end{pmatrix} \n  .\\] \n  We can simplify this and solve for $c_1,c_2$\n\n  \\begin{align*}\n    c_1&=<\\begin{pmatrix} 2\\\\3 \\end{pmatrix} ,\\begin{pmatrix} 1\\\\2 \\end{pmatrix}> = 2+6=8\\\\\n    c_2&=<\\begin{pmatrix} 2\\\\3 \\end{pmatrix} ,\\begin{pmatrix} \\frac{6}{5}\\\\-\\frac{3}{5} \\end{pmatrix}> = \\frac{12}{5}-\\frac{9}{5}=\\frac{3}{5}\\\\\n  .\\end{align*}\n  Using Theorem 4.9 from the book, we do the following with an orthogonal basis to get its norm:\n\n  \\begin{align*}\n    a_1=\\frac{8}{| | v_1| |^2}=\\frac{8}{(\\sqrt{1^2+2^2} )^2}=\\frac{8}{5}\\\\\n    a_2=\\frac{\\frac{3}{5}}{| | v_2 | |^2}=\\frac{\\frac{3}{5}}{\\left(\\frac{6}{5}\\right)^2+\\left(-\\frac{3}{5}\\right)^2}\\\\\n    =\\frac{\\frac{3}{5}}{\\frac{36}{25}+\\frac{9}{25}}=\\frac{15}{25}\\ldots\\\\\n    \\begin{pmatrix} 2\\\\3 \\end{pmatrix} =a_1\\begin{pmatrix} 1\\\\2 \\end{pmatrix} +a_2\\begin{pmatrix} \\frac{6}{5}\\\\-\\frac{3}{5} \\end{pmatrix} \\\\\n    \\frac{8}{5}\\begin{pmatrix} 1\\\\2 \\end{pmatrix} + \\frac{1}{3}\\begin{pmatrix} \\frac{6}{5}\\\\-\\frac{3}{5} \\end{pmatrix} \\\\\n    =\\begin{pmatrix} \\frac{8}{5}\\\\\\frac{16}{5} \\end{pmatrix} +\\begin{pmatrix} \\frac{2}{5}\\\\-\\frac{1}{5} \\end{pmatrix} =\\begin{pmatrix} 2\\\\3 \\end{pmatrix} \n  .\\end{align*}\n\n  \\begin{problem}\n    Example of an orthogonal basis. Let $\\mathbb{T}^{n}$ be the vector space of trigonometric polynomials.\n    \\[\n      \\mathbb{T}^{n}=\\sum_{0\\le j+k\\le n}a_{jk}\\sin^{j}(x)\\cos^k(x)\\\\\n    .\\] \n    Using the $L^2$ norm:\n    \\[\n      <f,g> = \\int_{-\\pi}^{\\pi}f\\cdot g\n    .\\] \n    An orthogonal basis is $\\{1,\\cos(x),\\sin(x),\\cos(2x),\\sin(2x),\\cos(3x),\\sin(3x),\\ldots\\}$. If we were going to do the $L^2$ norm for any of these equations we would need to do the following\n    \\[\n      \\int_{-\\pi}^{\\pi}\\sin(2x)\\cos(4x)dx\n    .\\] \n    This equation is the Fourier series.\n  \\end{problem}\n\n\\subsection{}\n\\subsection{Orthogonal Matrices}\n\n  \\begin{definition}\n    AA square matrix $Q$ is orthogonal if $Q^{t}Q=Q\\cdot Q^{T}=I$\n  \\end{definition}\n\n  If $Q$ is orthogonal, then\n  \\begin{itemize}\n    \\item $Q^{-1}=Q^{T}$\n    \\item $det(Q)=\\pm 1$\n    \\item $Q\\cdot Q^{t}=I$\n    \\item $det(Q)det(Q^{T})=det(I)$\n    \\item $(det(Q))^2=1$\n    \\item $det(Q)=\\pm 1$\n  \\end{itemize}\n\n  Let $A=\\begin{pmatrix} a_{11}&a_{12}\\\\a_{21}&a_{22} \\end{pmatrix} $. Suppose that $A$ is orthogonal, then \n  \\begin{align*}\n    \\begin{pmatrix} A_{11}&A_{12}\\\\A_{21}&A_{22} \\end{pmatrix}\\cdot\\begin{pmatrix} A_{11}&A_{21}\\\\A_{12}&A_{22} \\end{pmatrix} &=\\begin{pmatrix} 1&0\\\\0&1 \\end{pmatrix} \\\\\n    a_{11}^2+a_{12}^2&=1\\\\\n    a_{11}a_{21}+a_{12}a_{22}&=0\\\\\n    a_{21}a_{11}+a_{22}a_{12}&=0\\\\\n    a_{21}^2+a_{22}^2&=1\n  .\\end{align*}\n  \n  If we plot $(a_{11},a_{12})$ on a graph, we can see that $\\cos\\left( \\theta \\right) =a_{12}$ and $\\sin(\\theta)=a_{11} $\n\n  \\begin{prop}\n    $Q$ is orthogonal if and only if its columns form an orthonormal basis.\n    \\begin{proof}\n      Let $Q=[U_1\\vdots U_2 \\vdots\\ldots\\vdots U_n]$.\n      \\[\n      Q^{T}=\\begin{bmatrix} U_1^{T}\\\\U_2^{T}\\\\ \\vdots \\\\ U_n^{T} \\end{bmatrix} \n      .\\] \n      In $Q^{T}Q$, the $i,j^{th}$ entry is $U_1^{T}\\cdot Uj$.\n      \\[\n      U_i^{T}\\cdot U_j =\n      \\begin{cases}\n        0&i\\neq j\\\\\n        1&i=j\n      \\end{cases}\n      .\\] \n      So the $U_i$'so form an orthonormal basis.\n    \\end{proof}\n  \\end{prop}\n  \\begin{problem}\n    Let $A=\\begin{bmatrix} 3&5\\\\7&\\frac{1}{2} \\end{bmatrix} $, and let $A$ be orthonormal. We know that $A\\cdot A^{T}=A^{T}\\cdot A=I$. Let's see if $A$ is an orthonormal basis.\n    \\[\n      \\begin{bmatrix} 3&7\\\\5&\\frac{1}{2} \\end{bmatrix} \\begin{bmatrix} 3&5\\\\7&\\frac{1}{2} \\end{bmatrix} \\neq \\begin{bmatrix} 1&0\\\\0&1 \\end{bmatrix} \n    .\\] \n      This is not equal because $3\\times 7+3\\times 5\\neq0$. Now let's try letting $A=\\begin{bmatrix} 3&-7\\\\7&3 \\end{bmatrix} $.\n      \\[\n        \\begin{bmatrix} 3&7\\\\-7&3 \\end{bmatrix} \\begin{bmatrix} 3&-7\\\\7&3 \\end{bmatrix} =\\begin{bmatrix} 1&0\\\\0&1 \\end{bmatrix} \n      .\\] \n      This vector works with the zero values, but not the ones values, so we need to normalize this vector.\n      \\begin{align*}\n        \\left| \\left| \\begin{bmatrix} 3\\\\7 \\end{bmatrix}  \\right|  \\right|=\\sqrt{4^2+7^2} =\\sqrt{58} && \\left| \\left| \\begin{bmatrix} -7\\\\3 \\end{bmatrix}  \\right|  \\right|=\\sqrt{(-7)^2+3^2} =\\sqrt{58}\n      \\end{align*}\n      \\[\n        A=\\begin{bmatrix} \\frac{3}{58}&-\\frac{7}{58}\\\\\\frac{7}{58}&\\frac{3}{58} \\end{bmatrix} \n      .\\] \n  \\end{problem}\n  \n        Let's let $B=\\begin{pmatrix} a&b\\\\c&d \\end{pmatrix} $, and suppose $Q$ is orthogonal.\n        \\[\n          Q^{T}\\cdot Q=\\begin{pmatrix} a&c\\\\b&d \\end{pmatrix} \\begin{pmatrix} a&b\\\\c&d \\end{pmatrix} =\\begin{pmatrix} 1&0\\\\0&1 \\end{pmatrix} \n        .\\] \n        \\begin{align*}\n          a^2+c^2=1\\\\\n          ab+cd=0\\\\\n          ab+cd=0\\\\\n          b^2+d^2=1\n        .\\end{align*}\n        Given that the vectors $\\begin{bmatrix} a\\\\c \\end{bmatrix} ,\\begin{bmatrix} b\\\\d \\end{bmatrix} $ lie on the unit circle, we can determine that\n        \\begin{align*}\n          a=\\cos\\theta&&c=\\sin \\theta\\\\\n          b=\\cos\\phi&&d=\\sin\\phi\n        ,\\end{align*}\n        and we can determine that \n        \\[\n          0=ab+cd=\\cos\\theta\\cos\\phi + \\sin \\theta\\sin\\phi=\\cos(\\theta-\\phi)\n        .\\] \n        If we use $\\cos(\\theta-\\phi),$ we can determine that $\\phi = \\theta\\pm\\pi$, so $b=-\\sin \\theta, d=\\cos\\theta$ or $b=\\sin \\theta, d=-\\cos\\theta$. We either have $Q$ in one of two forms.\n        \\[\n          \\begin{pmatrix} \\cos\\theta&&-\\sin \\theta\\\\ \\sin \\theta&&\\cos\\theta \\end{pmatrix}\\text{ or }\\begin{pmatrix} \\cos\\theta && \\sin \\theta \\\\ \\sin \\theta &&-\\cos\\theta \\end{pmatrix}  \n        .\\] \n        The determinant of the left matrix is 1, and the determinant of the right matrix is -1. They both give us a counter clockwise rotation by $\\theta$, gives a reflection across the line with angle $\\frac{\\theta}{2}$\n\northogonal matrices are square and $Q^{t}\\cdot Q=Q Q^{t}=I$. Every $2\\times 2$ orthogonal matrix has the form \n\\[\n  \\begin{pmatrix} \\cos\\theta&&-\\sin \\theta\\\\ \\sin \\theta && \\cos \\theta \\end{pmatrix} \\text{ or } \\begin{pmatrix} \\cos\\theta&& \\sin \\theta\\\\ \\sin \\theta && -\\cos\\theta \\end{pmatrix} .\n.\\] \n\nIn general, if $Q$ is orthogonal, then $det(Q)=\\pm 1$\n\n\\begin{theorem}\n  The product of two orthogonal matrices is orthogonal.\n  Recall, if $Q$ is orthogonal, then $Q^{-1}=Q^{T}$. The orthogonal $n\\times n$ matrices satisfy \n  \\begin{itemize}\n    \\item Closed under the dot product.\n    \\item Multiplication is associative.\n    \\item They all have inverses.\n    \\item The identity matrix is orthogonal.\n  \\end{itemize}\n\n\\end{theorem}\n\\subsection{Vector Spaces}\nUp until now we've been trying to get a basis to be able to establish a location of vectors. Once we have determined an inner product, we can find an angle. Let $V$ be a subspace. Let $W \\le V$ be a finite dimensional subspace.\n\\begin{definition}\n  $\\vec{z}\\in V$ is orthogonal to $w$ if it is orthogonal to every vector in $w$.\n\\end{definition}\n\\begin{note}\n  If $\\vec{w_1},\\ldots,\\vec{w_n}$ is a basis for $w$, then $\\vec{z}$ is orthogonal to $w$ if and only if $\\vec{z}$ is orthogonal to $w_1,\\ldots,w_n$.\n\\end{note}\n\\begin{definition}\n  The orthogonal projection of $\\vec{V}$ onto $w$ is the vector $\\vec{w}$ such that $\\vec{z}=\\vec{v}-\\vec{w}$, where $\\vec{z}$ is orthogonal to $w$.\n\\end{definition}\n\\begin{theorem}\n  Let $\\vec{u_1},\\ldots,\\vec{u_n}$ be an orthogonal basis for $w$. Let $\\vec{v}\\in V$. The orthogonal projection of $\\vec{v}$ onto $w$ is \n  \\[\n    \\vec{w}=c_1\\vec{u_1}+\\ldots+c_n \\vec{u_n}\\text{ where $c_i<v,v_i>$}\n  .\\] \n\\end{theorem}\n\\begin{note}\n  If $\\vec{v_1},\\ldots,\\vec{v_n}$ is an orthogonal basis for $w$ then \n  \\begin{align*}\n    w=a_1\\vec{v_1}+\\ldots+a_n \\vec{v_n}\\\\\n    a_i=\\frac{\\left<\\vec{v},\\vec{v_i} \\right>}{\\|v_i\\|^2}\n  .\\end{align*}\n\\end{note}\n\\begin{definition}\n  Let $w,z\\le V$ be subspaces. $w$ is orthogonal to $z$ if every vector in $w$ is orthogonal to every vector in $z$. For example,\n    \\[\n    <\\vec{w},\\vec{z}> = 0\n    \\] \n   for every $\\vec{w}\\in w, \\vec{z}\\in z$ .\n\\end{definition}\n\\begin{note}\n  We only need to show this is true on the bases of $w$ and $z$.\n\\end{note}\n\\begin{definition}\n  Let $w\\in v$ be a subspace. The orthogonal compliment of $w$, written $w^{T}$ is the set of vectors in $v$ orthogonal to $w$.\n  \\[\n  w^{T}=\\left\\{ \\vec{v}\\in v | \\left<\\vec{v},\\vec{w} \\right> =0, \\forall w\\in w \\right\\} \n  .\\] \n\\end{definition}\n\\begin{theorem}\n  Let $w<v$ be a finite dimensional subspace. Every $\\vec{v}\\in v$ can be written uniquely as \n  \\[\n  \\vec{v}=\\vec{w}+\\vec{z}\n  \\] \n  where $\\vec{w}\\in w$ and $\\vec{z}\\in w^{T}$.\n\\end{theorem}\n", "meta": {"hexsha": "3801db95b613ca36c62b1e1c6e63feae9255c5cc", "size": 13764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math363/chapters/4.tex", "max_stars_repo_name": "CameronSWilliamson/GU-MATH", "max_stars_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-18T20:55:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-18T20:55:25.000Z", "max_issues_repo_path": "math363/chapters/4.tex", "max_issues_repo_name": "therealkeyisme/Math-Notes", "max_issues_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math363/chapters/4.tex", "max_forks_repo_name": "therealkeyisme/Math-Notes", "max_forks_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.6576271186, "max_line_length": 335, "alphanum_fraction": 0.5927056088, "num_tokens": 5594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.8705972583359805, "lm_q1q2_score": 0.7157956104523084}}
{"text": "\\title{Notes for Chapter 2: Basic Structures}\n\\author{Elias Schablowski}\n\\documentclass{article}\n\n\\usepackage{amsmath,amsthm,amssymb,amsfonts}\n\\usepackage{hyperref}\n\n\\begin{document}\n    \\section{2.1 - Sets}\n        Sets are groups of objects, often Numbers.\n        Objects in sets usually have something in common, as otherwise a set would be nonsensical.\n        \\subsection{Common Sets}\n            \\begin{enumerate}\n                \\item The set of all Complex numbers - $\\mathbb{C}$ (\\textbackslash mathbb\\{C\\})\n                \\item The set of all Real numbers - $\\mathbb{R}$ (\\textbackslash mathbb\\{R\\})\n                \\item The set of all Rational numbers - $\\mathbb{Q}$ (\\textbackslash mathbb\\{Q\\})\n                \\item The set of all Integer numbers - $\\mathbb{Z}$ (\\textbackslash mathbb\\{Z\\})\n                \\item The set of all Natural numbers - $\\mathbb{N}$ (\\textbackslash mathbb\\{M\\})\n                \\item The set of all Imaginary numbers - $\\mathbb{I}$ (\\textbackslash mathbb\\{I\\})\n                \\item The empty Set - $\\emptyset$ or $\\{\\}$ (\\textbackslash emptyset or \\textbackslash \\{ \\textbackslash \\})\n            \\end{enumerate}\n            $$\\mathbb{N} \\subset \\mathbb{Z} \\subset \\mathbb{Q} \\subset \\mathbb{R} \\subset \\mathbb{C}$$\n            $$\\mathbb{I} \\subset \\mathbb{C}$$\n            $$\\mathbb{I} \\ni x \\notin \\mathbb{R}$$\n            $$\\mathbb{R} \\ni x \\notin \\mathbb{I}$$\n        \\subsection{Subsets}\n            The set $A$ is a \\textit{subset} of $B$ iff $B$ contains \\textbf{all} objects of $A$.\n            $A$ being a subset of $B$ can also be expressed as $B$ is a \\textit{superset} of $A$.\n            Subsets are written as $\\subset$ (\\textbackslash subset) in equations.\n        \\subsection{Size of a Set}\n            $| S |$ denotes the size, or number of \\textit{distinct}\\footnote{Distinct objects means that equivalent objects are only counted once, e.g. $|{2, 2}| = 1$ as $2$ is only counted once} objects in set $S$.\n            Size is also called the \\textit{Cardinality} of a \\textbf{finite} set.\n        \\subsection{Power Sets}\n            A Power Set is one that includes all subsets of another set.\n            Power Sets are denoted by $\\mathcal{P}(S)$ (\\textbackslash mathcal \\{ P\\} (S)) in equations.\n        \\subsection{Ordered n-tuple}\n            An ordered n-tuple is an ordered collection denoted by $(a_1, a_2, ...)$ ((a\\_1, a\\_2, ...))\n            Ordered tuples are equal if they have the same elements at the same locations.\n\\end{document}", "meta": {"hexsha": "677c67dd566849a48a05683dab53b98c85fe1880", "size": 2507, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/Chapter 2.tex", "max_stars_repo_name": "eschablowski/Math-10", "max_stars_repo_head_hexsha": "550ccc9222c29cb7f6bcd146b5b6b26808ce470f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Notes/Chapter 2.tex", "max_issues_repo_name": "eschablowski/Math-10", "max_issues_repo_head_hexsha": "550ccc9222c29cb7f6bcd146b5b6b26808ce470f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/Chapter 2.tex", "max_forks_repo_name": "eschablowski/Math-10", "max_forks_repo_head_hexsha": "550ccc9222c29cb7f6bcd146b5b6b26808ce470f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.2820512821, "max_line_length": 216, "alphanum_fraction": 0.6122856003, "num_tokens": 723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699845, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7157296774220941}}
{"text": "\\section{Introductory example: Euclid's algorithm}\n\n\n\\begin{frame}\n  \\frametitle{Euclid's Algorithm}\n\n  \\begin{itemize}\n  \\item \\tc{dkblue}{Euclid's algorithm in pseudo-code}\n\n    \\bigskip\n\n    \\hspace*{4em}\n    \\begin{minipage}{.5\\linewidth}\\small\n    \\begin{tabbing}\n      \\quad\\=\\quad\\=\\kill\n      \\textbf{variables} x = M, y = N\\\\\n      \\textbf{begin}\\\\\n      \\> \\textbf{while} x $\\neq$ y \\textbf{do}\\\\\n      \\>\\> \\textbf{if} x$<$y\\\\\n      \\>\\> \\textbf{then} y := y-x\\\\\n      \\>\\> \\textbf{else} x := x-y\\\\\n      \\>\\> \\textbf{end if}\\\\\n      \\> \\textbf{end while};\\\\\n      \\> \\textbf{assert} $GCD$(M,N) = x\\\\\n      \\textbf{end}\n    \\end{tabbing}\n    \\end{minipage}\n\n  \\oo \\tc{dkblue}{This is a legal PlusCal algorithm}\n\n    \\begin{itemize}\n    \\o embedded in a \\tlaplus\\ module defining $GCD$\n    \\o can be checked for fixed values of M and N\n    \\end{itemize}\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Euclid's Algorithm in \\tlaplus\\ (1/2)}\n\n  \\begin{itemize}\n  \\item \\tc{dkblue}{We start by defining divisibility and $GCD$}\n\n    \\medskip\n\n    \\begin{tlablock}\n      \\begin{minipage}{.96\\linewidth}\n      \\begin{nomodule}\n        \\topbar{Euclid}\n        \\EXTENDS\\ Naturals\\\\[1mm]\n        \\(\\begin{noj}\n          d | q\\ \\deq\\ \\E k \\in 1..q : q = k * d\n          \\quad\\quad\\quad\\comment{definition of divisibility}\\\\\n          Divisors(q)\\ \\deq\\ \\{d \\in 1..q : d | q\\}\n          \\quad\\ \\ \\comment{set of divisors}\\\\\n          Maximum(S)\\ \\deq\\ \\CHOOSE x \\in S : \\A y \\in S : x \\geq y\\\\\n          GCD(p,q)\\ \\deq\\ Maximum(Divisors(p) \\cap Divisors(q))\\\\\n          PosInteger\\ \\deq\\ Nat \\setminus \\{0\\}\n        \\end{noj}\\)\\\\\n        \\midbar\n      \\end{nomodule}\n      \\end{minipage}\n    \\end{tlablock}\n\n  \\oo \\tc{dkblue}{Standard mathematical definitions}\n\n    \\begin{itemize}\n    \\o \\tlaplus\\ module $Naturals$ defines basic operations on integers\n    \\o \\tlaplus\\ is based on untyped set theory\n    \\o module contains declarations, assertions, and definitions\n    \\end{itemize}\n\n  \\oo \\tc{dkblue}{These definitions could go to a library module}\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Euclid's Algorithm in \\tlaplus\\ (2/2)}\n\n  \\begin{itemize}\n  \\item \\tc{dkblue}{Now encode the algorithm and assert its correctness}\n\n    \\medskip\n\n    \\begin{tlablock}\n      \\begin{minipage}{.96\\linewidth}\n      \\begin{nomodule}\n        \\CONSTANTS\\ \\ M, N\\\\\n        \\ASSUME\\ \\ $Positive\\ \\deq\\ M \\in PosInteger \\land N \\in PosInteger$\\\\\n        \\VARIABLES\\ \\ x, y\\\\[1mm]\n        \\(\\begin{array}{@{}l@{\\ \\ }c@{\\ \\ }l}\n          Init & \\deq & x=M \\land y=N\\\\\n          Next & \\deq &\n          \\begin{disj}\n            \\begin{conj}\n              x<y\\\\\n              y' = y-x \\land x' = x\n            \\end{conj}\\\\\n            \\begin{conj}\n              y<x\\\\\n              x' = x-y \\land y' = y\n            \\end{conj}\n          \\end{disj}\\\\\n          Spec & \\deq & Init \\land \\alw[Next]_{\\seq{x,y}}\n        \\end{array}\\)\\\\\n        \\midbar\n        $Correctness\\ \\deq\\ x=y \\implies x = GCD(M,N)$\\\\[1mm]\n        \\THEOREM\\ \\ $Spec \\implies \\alw Correctness$\\\\\n        \\bottombar\n      \\end{nomodule}\n      \\end{minipage}\n    \\end{tlablock}\n\n\n  \\oo \\tc{dkblue}{Algorithm represented by initial condition and next-state relation}\n\n  \\oo \\tc{dkblue}{Correctness expressed as TLA formula}\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{\\tlaplus\\ Modules}\n\n  \\begin{itemize}\n  \\item \\tc{dkblue}{Specifications of \\tlaplus\\ are structured in modules}\n\n    \\begin{itemize}\n    \\o structured specifications: import existing modules via \\EXTENDS\n    \\o \\INSTANCE\\ allows import with renaming, but we don't need it here\n    \\end{itemize}\n\n  \\oo \\tc{dkblue}{Modules contain declarations, assertions, and definitions}\n\n    \\begin{itemize}\n    \\o declarations of \\CONSTANTS\\ and \\VARIABLES\n    \\o assertions of facts via \\ASSUME\\ and \\THEOREM\\ (more later)\n    \\o main body of module: \\alert{operator definitions}\n    \\end{itemize}\n\n  \\oo \\tc{dkblue}{Levels of formulas and operators}\n\n    \\medskip\n\n    \\renewcommand{\\arraystretch}{1.2}\n    \\quad{\\small\\begin{tabular}{l@{\\qquad}l@{\\qquad}l}\n        \\alert{constant} & only \\CONSTANT\\ symbols & \\tc{dkgreen}{$Positive$}\\\\\n        \\alert{state} & allow \\VARIABLE{}s & \\tc{dkgreen}{$Init,\\ Correctness$}\\\\\n        \\alert{action} & allow primed \\VARIABLE{}s & \\tc{dkgreen}{$Next$}\\\\\n        \\alert{temporal} & use temporal operators & \\tc{dkgreen}{$Spec$}\n    \\end{tabular}}\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Verification of Euclid's Algorithm}\n\n  \\begin{itemize}\n  \\item \\tc{dkblue}{Verification by model checking: \\tlc}\n\n    \\begin{itemize}\n    \\o construct model by fixing concrete values for $M$ and $N$\n    \\o \\tlc\\ verifies that the $Correctness$ property is always true\n    \\o variation: verify correctness for all initial values in fixed interval\n    \\end{itemize}\n\n\\pause\n\n  \\oo \\tc{dkblue}{Verification by theorem proving: \\tlaps}\n\n    \\begin{itemize}\n    \\o need to strengthen correctness property to an \\alert{inductive invariant}\n\n       \\medskip\n       \\begin{tlablock}[.7]\n         InductiveInvariant\\ \\deq\\ \n         \\begin{conj}\n           x \\in PosInteger\\\\\n           y \\in PosInteger\\\\\n           GCD(x,y) = GCD(M,N)\n         \\end{conj}\n       \\end{tlablock}\n    \\end{itemize}\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Underlying Data Properties}\n\n  \\begin{itemize}\n  \\item \\tc{dkblue}{The proof relies on the following properties of $GCD$}\n\n     \\bigskip\n\n     \\begin{tlablock}\n       \\begin{array}{@{}l@{\\ \\ }c@{\\ \\ }l}\n         \\THEOREM\\ \\ GCDSelf & \\deq &\n         \\begin{array}[t]{@{}l@{\\ \\ }l}\n           \\ASSUME & \\NEW\\ p \\in PosInteger\\\\\n           \\PROVE  & GCD(p,p) = p\n         \\end{array}\\vspace{2mm}\\\\ \n         \\THEOREM\\ \\ GCDSymm & \\deq &\n         \\begin{array}[t]{@{}l@{\\ \\ }l}\n           \\ASSUME & \\NEW\\ p \\in PosInteger,\\\\\n                   & \\NEW\\ q \\in PosInteger\\\\\n           \\PROVE  & GCD(p,q) = GCD(q,p)\n         \\end{array}\\vspace{2mm}\\\\\n         \\THEOREM\\ \\ GCDDiff & \\deq &\n         \\begin{array}[t]{@{}l@{\\ \\ }l}\n           \\ASSUME & \\NEW\\ p \\in PosInteger,\\\\\n                   & \\NEW\\ q \\in PosInteger,\\\\\n                   & p<q\\\\\n           \\PROVE  & GCD(p,q) = GCD(p, q-p)\n         \\end{array}\n       \\end{array}\n     \\end{tlablock}\n\n  \\oo \\tc{dkblue}{\\tc{dkgreen}{$\\ASSUME$ \\ldots\\ $\\PROVE$} assertions are sequents in \\tlaplus}\n\n    \\begin{itemize}\n    \\o could use formulas instead, but sequents are often easier to read\n    \\end{itemize}\n\n  \\oo \\tc{dkblue}{We don't bother proving these properties here}\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Invariant Reasoning in \\tlaplus}\n\n  \\begin{itemize}\n  \\item \\tc{dkblue}{Establish an invariant in \\tlaplus}\n\n    \\medskip\n\n\\begin{center}\n    \\qquad\\(\\color{red!75!black}\\begin{array}{c}\n      Init \\implies Inv \\quad Inv \\land [Next]_v \\implies Inv' \\quad Inv \\implies Cor\\\\\n      \\hline\n      Init \\land \\alw[Next]_v \\implies \\alw Cor\n    \\end{array}\\)\n\\end{center}\n\n    \\begin{itemize}\n%    \\o $J$ is an inductive invariant that implies $Inv$\n    \\o $Inv$ must imply $Cor$, be true initially, and preserved by every step\n    \\end{itemize}\n\n\\pause\n\n  \\o \\tc{dkblue}{This rule can be stated as the following sequent}\n\n     \\medskip\n\n     \\qquad\\begin{tlablock}[.7]\n       \\THEOREM\\ \\ Inv1\\ \\deq\\ \n       \\begin{array}[t]{@{}l@{\\ \\ }l}\n         \\ASSUME & Init \\implies Inv,\\\\\n                 & Inv \\land [Next]_v \\implies Inv',\\\\\n                 & Inv \\implies Cor\\\\\n         \\PROVE  & Init \\land \\alw[Next]_v \\implies \\alw Cor\n       \\end{array}\n     \\end{tlablock}\n\n     \\begin{itemize}\n     \\o \\tlaps\\ doesn't handle temporal logic yet\n     \\o but it can be used to establish the non-temporal hypotheses\n     \\end{itemize}\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Simple Proofs}\n\n  \\begin{itemize}\n  \\item \\tc{dkblue}{Prove that \\tc{dkgreen}{$InductiveInvariant$} implies \\tc{dkgreen}{$Correctness$}}\n\n    \\medskip\n\n    \\qquad\\begin{tlablock}\n      \\LEMMA\\ \\ InductiveInvariant \\implies Correctness\\\\\n      \\only<1>{\\alert{\\PROOF\\ \\OBVIOUS}}\n      \\only<2->{\\BY\\ GCDSelf\\ \\DEFS\\ InductiveInvariant, Correctness}\n    \\end{tlablock}\n\n\\pause\n\n\n\n    \\begin{itemize}\n    \\o definitions and facts must be cited explicitly for \\tlaps\\ to use them\n    \\o this helps keeping the size of proof obligations manageable\n    \\end{itemize}\n\n\\pause\n  \\oo \\tc{dkblue}{Prove that \\tc{dkgreen}{$Init$} implies \\tc{dkgreen}{$InductiveInvariant$}}\n\n    \\medskip\n\n    \\qquad\\begin{tlablock}\n      \\LEMMA\\ \\ Init \\implies InductiveInvariant\\\\\n      \\BY\\ Positive\\ \\DEFS\\ Init, InductiveInvariant\n    \\end{tlablock}\n\n  \\oo \\tc{dkblue}{These simple proofs are called \\alert{leaf proofs}}\n  \\end{itemize}\n  \n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Hierarchical Proofs}\n\n  \\begin{itemize}\n  \\item \\tc{dkblue}{A non-leaf proof consists of a sequence of claims, ending with \\QED}\n\n  \\oo \\tc{dkblue}{Prove that \\tc{dkgreen}{$Next$} preserves \\tc{dkgreen}{$InductiveInvariant$}}\n\n    \\medskip\n\n    \\qquad\\begin{tlablock}\n      \\LEMMA\\ \\ InductiveInvariant \\land [Next]_{\\seq{x,y}} \\implies InductiveInvariant'\\\\\n      \\ps{1}{}\\ \\USE\\ \\DEFS\\ InductiveInvariant, Next\\\\\n\\onslide<2->{\n      \\ps{1}{}\\ \\SUFFICES\\ \n        \\begin{array}[t]{@{}l@{\\ \\ }l}\n          \\ASSUME & InductiveInvariant, Next\\\\\n          \\PROVE  & InductiveInvariant'\n        \\end{array}\\\\\n        \\quad \\PROOF\\ \\OBVIOUS\n  }\\\\\n\\onslide<3->{\n      \\ps{1}{a.}\\ \\CASE\\ x<y\\\\\n      \\ps{1}{b.}\\ \\CASE\\ x>y}\\\\\n\\onslide<4->{\n      \\ps{1}{q.}\\ \\QED\\\\\n      \\quad  \\quad \\BY\\ \\ps{1}{a}, \\ps{1}{b}}\n    \\end{tlablock}\n\n    \\begin{itemize}\n    \\o \\only<1>{\\USE\\ \\DEFS\\ causes \\tlaps\\ to silently apply given definitions.}\n       \\only<2>{\\SUFFICES\\ restates the current claim -- trivial case $\\UNCHANGED \\seq{x,y}$}\n       \\only<3>{The two subcases will be proved subsequently.}\n       \\only<4>{The assertion follows from the cases and the definition of $Next$.}\n    \\end{itemize}\n  \\end{itemize}\n\\end{frame}\n\n\n\n\\begin{frame}[t]\n  \\frametitle{Hierarchical Proofs}\n\n  \\begin{itemize}\n  \\item \\tc{dkblue}{Sublevels}\n\n\\medskip\n\n    \\qquad\\begin{tlablock}\n      {\\color{gray}(...)} \\\\\n      \\ps{1}{a.}\\ \\CASE\\ x<y\\\\\n      \\quad \\ps{2}{1.} \\ (y - x \\in PosInteger)  \\land \\lnot(y < x)\\\\\n      \t\\only<3->{\\quad\\quad \\BY\\ \\ps{1}{a},\\ SimpleArithmetic\\ \\DEF\\ PosInteger}\\\\\n  \t\\quad \\ps{2}{2.} \\  \\QED\\\\\n    \t\\only<2->{\\quad\\quad \\BY\\ \\ps{1}{a}, \\ps{2}{1},\\ GCDDiff}\\\\\n      \\ps{1}{b.}\\ \\CASE\\ x>y\\\\\n {\\color{gray}(...)} \n    \\end{tlablock}\n    \n    \\medskip\n\n\\uncover<3->{\n    \\item $SimpleArithmetic$\n    \\begin{itemize}\n    \\o theorem from the standard module TLAPS.tla\n    \\o calls another back-end\n    \\o Cooper's algorithm for Presburger's arithmetic \n    \\end{itemize}\n}\n  \\end{itemize}\n\\end{frame}\n\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"tutorial\"\n%%% End: \n", "meta": {"hexsha": "524e76a44eb98312f7658a41a711f1454f344181", "size": 10832, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/presentations/2010-ifm/tla.tex", "max_stars_repo_name": "damiendoligez/tlapm", "max_stars_repo_head_hexsha": "13a1993263642092a521ac046c11e3cb5fbcbc8b", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 31, "max_stars_repo_stars_event_min_datetime": "2016-08-16T14:58:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-19T18:38:07.000Z", "max_issues_repo_path": "doc/presentations/2010-ifm/tla.tex", "max_issues_repo_name": "damiendoligez/tlapm", "max_issues_repo_head_hexsha": "13a1993263642092a521ac046c11e3cb5fbcbc8b", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 49, "max_issues_repo_issues_event_min_datetime": "2020-03-04T18:13:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-07T17:43:24.000Z", "max_forks_repo_path": "doc/presentations/2010-ifm/tla.tex", "max_forks_repo_name": "damiendoligez/tlapm", "max_forks_repo_head_hexsha": "13a1993263642092a521ac046c11e3cb5fbcbc8b", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2020-02-26T19:58:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-12T22:18:25.000Z", "avg_line_length": 27.9896640827, "max_line_length": 102, "alphanum_fraction": 0.5875184638, "num_tokens": 3691, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631476836816, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.7156497617689181}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=2}^\\infty \\frac{\\ln n}{n}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\r\n\\subsection*{Solution 1}\r\n\r\nThe function $f(x)=\\frac{\\ln x}{x}$ is continuous, positive, and decreasing on $[3,\\infty)$. We consider the integral\r\n\\[ \\int_3^\\infty \\frac{\\ln x}{x}\\,dx = \\lim_{t \\to \\infty} \\int_3^t \\frac{\\ln x}{x}\\,dx.\\]\r\nWe do the indefinite integral using the substitution $u= \\ln x$, so $du = \\frac1x\\,dx$:\r\n\\[\r\n\\int \\frac{\\ln x}{x}\\,dx\r\n= \\int u\\,du = \\frac12u^2 + C = \\frac12(\\ln x)^2 + C\r\n\\]\r\nso, back to the improper integral,\r\n\\begin{align*}\r\n\\int_3^\\infty \\frac{\\ln x}{x}\\,dx \r\n&= \\lim_{t \\to \\infty} \\int_3^t \\frac{\\ln x}{x}\\,dx\\\\\r\n&= \\lim_{t \\to \\infty}\\left[  \\frac12(\\ln t)^2 -  \\frac12(\\ln 3)^2 \\right] \\\\\r\n&= \\infty.\r\n\\end{align*}\r\nSince the integral $\\displaystyle \\int_3^\\infty \\frac{\\ln x}{x}\\,dx$ diverges, the series  $\\displaystyle \\sum_{n=3}^\\infty \\frac{\\ln n}{n}$ diverges by the Integral Test. So the series $\\displaystyle \\sum_{n=2}^\\infty \\frac{\\ln n}{n}$ diverges as well (since we're only adding in one more term).\r\n\r\n\\subsection*{Solution 2}\r\n\r\nNote that for $n \\geq 3$, we have $\\ln n \\geq 1$. So,\r\n\\[ \\frac{\\ln n}{n} \\geq \\frac{1}{n}\\]\r\nSince the series $\\displaystyle \\sum_{n=3} \\frac1n$ diverges by the $p$-series test (with $p=1$), the series \r\n $\\displaystyle \\sum_{n=3} \\frac{\\ln n}n$ diverges by the Direct Comparison Test. Adding on one more term does not change the convergence/divergence, so the series  $\\displaystyle \\sum_{n=2} \\frac{\\ln n}n$ also diverges.\r\n\r\n\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "aacc4e4393d108ddc897882cdbdddf8013a8251a", "size": 2229, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/e1.tex", "max_stars_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_stars_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "key/series/e1.tex", "max_issues_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_issues_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "key/series/e1.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 38.4310344828, "max_line_length": 297, "alphanum_fraction": 0.6393001346, "num_tokens": 792, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603726, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7156186220246721}}
{"text": "\\documentclass[a4paper,man,natbib]{apa6}\r\n\\usepackage[english]{babel}\r\n\\usepackage[utf8x]{inputenc}\r\n\\usepackage{setspace}\r\n\r\n%% Images\r\n% \\usepackage{graphicx}\r\n% \t\\graphicspath{ {./images/} }\r\n% \t\\usepackage{caption}\r\n\r\n% Minted\r\n\t\\usepackage[cache=false]{minted}\r\n\t\\usepackage{xcolor}\r\n\t\t\\definecolor{light-gray}{gray}{0.97}\r\n\t\\usemintedstyle{vs}\r\n\r\n% Title\r\n\t\\title{Intro to Computational Statistics: Homework 6}\r\n\t\\shorttitle{HW06}\r\n\t\\author{Author: Brandon Hosley}\r\n\t\\affiliation{Instructor: Liang Kong, Ph.D}\r\n\r\n%\\abstract{}\r\n\r\n\\usepackage{pdfpages}\r\n\r\n\\begin{document}\r\n\\maketitle\r\n\\singlespacing\r\n\t\r\n\\subsection*{Q1: Use SAS data set students.sas7bdat (from homework 1) to obtain a regression model to predict the Score of Final Exam by using Intelligence Quotient, Score of Mathematics part of SAT, and Score of Pilot Examination as regressors. What is the estimate model? }\r\n\\inputminted[breaklines,bgcolor=light-gray]{sas}{./Snippets/DAT502-HW6-1.sas}\r\nEstimate Model: \\\\\r\nFEXAM = -0.18062 + 0.40527*IQ + 0.001816*MSAT + 0.37603*PEXAM\r\n\r\n\\includepdf[pages=-]{./Snippets/SAS Output HW6-1.pdf}\r\n\r\n\\subsection*{Q2: What is the estimate model of the above question with all the coefficients are significant at 0.05 level of significance. }\r\n\\inputminted[breaklines,bgcolor=light-gray]{sas}{./Snippets/DAT502-HW6-2.sas}\r\nEstimate Model: \\\\\r\nFEXAM = -0.28666 + 0.47674*IQ + 0.38137*PEXAM\r\n\r\n\\includepdf[pages=-]{./Snippets/SAS Output HW6-2.pdf}\r\n\r\n\\subsection*{Q3: Assuming Intelligence Quotient is the only information available, construct a 98\\% prediction interval for the Score of Final Exam giving a score of 110 for Intelligence Quotient. }\r\n\\inputminted[breaklines,bgcolor=light-gray]{sas}{./Snippets/DAT502-HW6-3.sas}\r\n\r\n$ 110 * 0.81561 - 13.47104 \\pm 2.33 * 11.82143 $ \\\\\r\n$ 89.7171 \\pm 27.543919 $ \\\\\r\nThere is a 98\\% confidence that 110 IQ will result in between 62.173181 and 117.26; though it appears that 100 is a likely upper bound.\r\n\r\n\\includepdf[pages=-]{./Snippets/SAS Output HW6-3.pdf}\r\n\r\n\\subsection*{Q4: Use SAS data set regp3.sas7bdat (located at \"Data set\" folder) to fit a simple linear regression model : $Y = \\beta_0 + \\beta_1X + \\epsilon$. What is the 90\\% confidence interval for $\\beta_1$?\r }\r\n\\inputminted[breaklines,bgcolor=light-gray]{sas}{./Snippets/DAT502-HW6-4.sas}\r\n\r\n$\\beta_1$ has a 90\\% confidence interval of 4.03634 and 4.24609\r\n\r\n\\includepdf[pages=-]{./Snippets/SAS Output HW6-4.pdf}\r\n\r\n\r\n\\subsection*{Q5: Use SAS data set regp3.sas7bdat (located at \"Data set\" folder) to fit the \"best\" linear regression model : $Y = \\beta_0 + f(X; \\beta_1, \\beta_2, \\beta_3, \\ldots) + \\epsilon$. For example, $f(X; \\beta_1, \\beta_2, \\beta_3, \\ldots)$ could be $\\beta_1X^{0.5} + \\beta_2 X^{1.5} + \\beta_3 X_3$ or $\\beta_1X_0 + \\beta_2 X_2 \\ldots$ . What is the 97\\% confidence interval for the average values of $Y$ given $X=200$? }\r\n\\inputminted[breaklines,bgcolor=light-gray]{sas}{./Snippets/DAT502-HW6-5.sas}\r\n\r\nFor a $\\beta_1X + \\beta_2 X^2 + \\beta_3$ model there is a 97\\% confidence interval of $Y$ between $228.2901$ and $234.7784$ for the value of $X=200$\r\n\r\n\\includegraphics[width=0.8\\linewidth]{./images/image5.png}\r\n\\includepdf[pages=-]{./Snippets/SAS Output HW6-5.pdf}\r\n\r\n\\end{document}", "meta": {"hexsha": "6edc35ca1e000ed67a13891ee4f401278339805b", "size": 3229, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2021-Spr Intro to Computational Stats/HW06/bhosl2-HW06.tex", "max_stars_repo_name": "bhosley/Schoolwork", "max_stars_repo_head_hexsha": "7c4eb909d2e6c65cd93b1c7fa744a183cebfc952", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2021-Spr Intro to Computational Stats/HW06/bhosl2-HW06.tex", "max_issues_repo_name": "bhosley/Schoolwork", "max_issues_repo_head_hexsha": "7c4eb909d2e6c65cd93b1c7fa744a183cebfc952", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2021-Spr Intro to Computational Stats/HW06/bhosl2-HW06.tex", "max_forks_repo_name": "bhosley/Schoolwork", "max_forks_repo_head_hexsha": "7c4eb909d2e6c65cd93b1c7fa744a183cebfc952", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.1285714286, "max_line_length": 428, "alphanum_fraction": 0.7157014556, "num_tokens": 1104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587158, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7155958501146817}}
{"text": "\\chapter{Steepest Descent and Least-Mean-Square Adaptive Filters}\n\\label{ch:SD_LMS}\n\n\\section{Review of the Basics}\n\\subsection{The Eigenvalue Decomposition}\nIf a square $M\\times M$ matrix $\\vect{A}$ has an eigenvalue decomposition (EVD), it can be written as\n\\bmath\n  \\vect{A} = \\vect{X\\Lambda X}^{-1}\\qquad\\iff\\qquad\\vect{AX}=\\vect{X\\Lambda}\n\\emath\nwhere $\\vect{X}$ contains the $M$ linearly independent eigenvectors of $\\vect{A}$, and the diagonal matrix $\\vect{\\Lambda}$ contains the $M$ eigenvalues $\\{\\lambda_m\\}_{m=1}^M$ of $\\vect{A}$. If $\\vect{A}$ does not have an eigenvalue decomposition, it is said to be \\textit{defective}.\n\\subsubsection{Matrix Powers}\nLet $\\vect{A}$ have an EVD. Then\n\\begin{align}\n  \\vect{A} & = \\vect{X\\Lambda X}^{-1}\\\\\n  \\vect{A}^2 & \\underset{\\vdots}{=} \\vect{X\\Lambda X}^{-1}\\vect{X\\Lambda X}^{-1}=\\vect{X\\Lambda}^2\\vect{X}^{-1}\\\\\n%  &\\ \\,\\vdots\\notag\\\\\n  \\vect{A}^n &= \\vect{X\\Lambda}^n\\vect{X}^{-1}\\ .\n\\end{align}\n\\subsubsection{EVD of Special Matrices}\nLet $\\vect{A}$ be a symmetric matrix. Then\n\\begin{itemize}\n  \\item[] $\\vect{A}$ has an EVD,\n  \\item[] $\\vect{A}=\\vect{X\\Lambda X}^T$ ($\\vect{X}$ is an orthogonal matrix), and\n  \\item[] $\\lambda_m\\in\\mathbb{R}$ for $m=1,\\ldots,M$\n\\end{itemize}\nLet $\\vect{A}$ be a p.d. matrix. Then\n\\begin{itemize}\n  \\item[] $\\lambda_m\\in\\mathbb{R}^+$ for $m=1,\\ldots,M$.\n\\end{itemize}\nwhere $\\mathbb{R}^+$ is the set of all positive real numbers.\n\\subsubsection{Matrix Trace}\nThe trace of $\\vect{A}$ is\n\\bmath\n  \t\\tr{\\vect{A}} = \\sum_{m=1}^M a_{mm} = \\sum_{m=1}^M \\lambda_m = \\tr{\\vect{\\Lambda}}\\ .\n\\emath\n\n\\subsubsection{Condition Number of a Normal Matrix}\nIf $\\vect{A}$ is a normal matrix (i.e., $\\vect{A}^T\\vect{A}=\\vect{A}\\vect{A}^T$), then the condition number of $\\vect{A}$ is\n\\bmath\n  \\kappa(\\vect{A}) = \\left|\\frac{\\lambda_\\text{max}}{\\lambda_\\text{min}}\\right| = \\chi(\\vect{A})\n\\emath\nwhere $\\chi(\\vect{A})$ is the eigenvalue spread of $\\vect{A}$.\n\n\\section{The Wiener-Hopf Equations}\nThe adaptive filtering problem with time-varying filter coefficients is shown in Fig.~\\ref{fig:nonwss_block_diagram1}.\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/nonwss_block_diagram}\n  \\caption{Block diagram of adaptive filtering in a non-WSS environment.}\n  \\label{fig:nonwss_block_diagram1}\n\\end{figure}\nFrom the figure, we have that\n\\begin{itemize}\n  \\item[$u(n)$:] zero-mean input signal\n  \\item[$w_m(n)$:] $M$-tap FIR-filter with impulse response $w_0(n),w_1(n),\\ldots,w_{M-1}(n)$\n  \\item[$y(n)$:] output signal given by $y_n = \\sum_{m=0}^{M-1}w_m(n) u(n-m)$\n  \\item[$d(n)$:] zero-mean desired signal\n  \\item[$e(n)$:] error signal\n\\end{itemize}\n\\subsubsection{WSS Signals}\nWhen $u(n)$ and $d(n)$ are jointly WSS, the filter coefficients are not time-varying. Define\n\\begin{align}\n  \\vect{w} &= \\bbmtx w_0 & w_{1} & \\cdots & w_{M-1}\\ebmtx^T\\\\\n  \\vect{u}(n) &= \\bbmtx u(n) & u(n-1) & \\cdots & u(n-M+1)\\ebmtx^T\\ .\n\\end{align}\nThen\n\\bmath\n  e(n) = d(n) - y(n) = d(n)-\\vect{u}^T(n)\\vect{w}\\ .\n\\emath\nWe wish to minimise\n\\begin{align}\n  J_1(\\vect{w}) &= E[e(n)^2] = E[d(n)^2] + \\vect{w}^T E[\\vect{u}(n)\\vect{u}^T(n)] \\vect{w}-2\\vect{w}^T E[\\vect{u}(n) d(n)]\\notag\\\\\n  &= \\sigma_d^2+\\vect{w}^T\\vect{R}_u\\vect{w}-2\\vect{w}^T\\vect{r}_{ud}\n\\end{align}\nw.r.t. $\\vect{w}$. The minimiser\n\\bmath\n  \\vect{w}_o = \\vect{R}_u^{-1}\\vect{r}_{ud}\n\\emath\nis the unique solution to the Wiener-Hopf equations\n\\bmath\n  \\vect{R}_u\\vect{w} = \\vect{r}_{ud}\\ ,\n\\emath\nprovided that $\\vect{R}_u$ is p.d. \n\\subsubsection{Non-WSS Signals}\nIf $u(n)$ and $d(n)$ are \\textit{not} jointly WSS, the optimal filter coefficients are time-varying, and we have that\n\\bmath\n  \\vect{R}_u(n)\\vect{w}(n) = \\vect{r}_{ud}(n)\n\\emath\nwhere\n\\begin{align}\n  \\vect{R}_u(n) &=\n  \\bbmtx\n    r_u(n,n) & \\cdots & r_u(n,n-M+1)\\\\\n    \\vdots & \\ddots & \\vdots\\\\\n    r_u(n-M+1,n) & \\cdots & r_u(n-M+1,n-M+1)\\\\\n  \\ebmtx\\\\\n  \\vect{r}_{ud}(n) &= \\bbmtx r_{ud}(n,n) & \\cdots & r_{ud}(n-M+1,n)\\ebmtx^T\\ .\n\\end{align}\nWe could find the optimal solution by calculating\n\\bmath\n  \\vect{w}_o(n) = \\vect{R}_u^{-1}(n)\\vect{r}_{ud}(n)\n\\emath\nfor every time index $n$. However, this approach may suffer from problems such as that\n\\begin{enumerate}\n  \\item the computational complexity is high, and\n  \\item the statistics is unknown.\n\\end{enumerate}\nThe steepest descent algorithm solves the first problem, and the least-mean-square (LMS) adaptive filter solves both problems.\n\n\\section{The Method of Steepest Descent}\n\\subsection{Basic Idea}\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/steepest_descent_idea_2d}\n  \\caption{The first three iterations of the steepest descent algorithm for a one-dimensional filter vector.}\n  \\label{fig:steepest_descent_idea_2d}\n\\end{figure}\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/steepest_descent_idea_3d}\n  \\caption{The first three iterations of the steepest descent algorithm for a two-dimensional filter vector.}\n  \\label{fig:steepest_descent_idea_3d}\n\\end{figure}\nThe basic idea of the steepest descent (SD) algorithm is to find the unique solution $\\vect{w}_o$ of the Wiener-Hopf equations through a series of steps, starting from some point $\\vect{w}(0)$. The steps are taken in the opposite direction of the gradient $\\vect{g}(\\vect{w}(n))$. This idea is illustrated in Fig.~\\ref{fig:steepest_descent_idea_2d} and Fig.~\\ref{fig:steepest_descent_idea_3d}. We update the filter coefficients by a recursive update equation given by\n\\bmath\n  \\boxed{\\vect{w}(n+1) = \\vect{w}(n)-\\frac{\\mu}{2}\\vect{g}(\\vect{w}(n))}\n\\emath\nwhere $\\mu$ is the step-size and $\\vect{g}(\\vect{w}(n))$ is the gradient of the cost function $J_1(\\vect{w}(n))$. The gradient is\n\\bmath\n  \\vect{g}(\\vect{w}(n)) = 2\\vect{R}_u(n)\\vect{w}(n) - 2\\vect{r}_{ud}(n)\\ .\n\\emath\nSince the gradient is a deterministic function, the evolution of the filter coefficient vector is also a deterministic function.\n\nDefine the weight error\n\\bmath\n  \\Delta\\vect{w}(n) = \\vect{w}_o-\\vect{w}(n)\\ .\n\\emath\nIn order for the SD algorithm to converge to the solution $\\vect{w}_o$, we must require that the step-size $\\mu$ is selected such that\n\\bmath\n  \\lim_{n\\to\\infty} \\Delta\\vect{w}(n) = 0\n  \\label{eq:sd_stability_req}\n\\emath\nwhen $u(n)$ and $d(n)$ are jointly WSS. If this is true, the SD algorithm is said to be \\textit{stable}. Moreover, we would like to select $\\mu$ such that the $\\Delta\\vect{w}(n)$ becomes small as fast as possible.\n\n\\subsection{Transient Analysis}\nAssume that $u(n)$ and $d(n)$ are jointly WSS. We then have that\n\\begin{align}\n  \\Delta\\vect{w}(n) &= \\vect{w}_o - \\left(\\vect{w}(n-1)-\\frac{\\mu}{2}\\vect{g}(\\vect{w}(n-1))\\right)\\\\\n  &= \\Delta\\vect{w}(n-1) + \\mu(\\vect{R}_u\\vect{w}(n-1)-\\vect{R}_u\\vect{w}_o)\\\\\n  &= (\\vect{I}-\\mu\\vect{R}_u)\\Delta\\vect{w}(n-1)\\\\\n  &= (\\vect{I}-\\mu\\vect{R}_u)(\\vect{I}-\\mu\\vect{R}_u)\\Delta\\vect{w}(n-2)\\\\\n  &= (\\vect{I}-\\mu\\vect{R}_u)^n\\Delta\\vect{w}(0)\\ .\n\\end{align}\nSince the correlation matrix $\\vect{R}_u$ is symmetric, it has an eigenvalue decomposition $\\vect{R}_u=\\vect{X\\Lambda X}^T$ where $\\vect{X}$ is an orthogonal matrix. That is, we may write\n\\bmath\n  \\Delta\\vect{w}(n) = \\vect{X}(\\vect{I}-\\mu\\vect{\\Lambda})^n\\vect{X}^T\\Delta\\vect{w}(0)\n\\emath\nwhere $\\vect{I}-\\mu\\vect{\\Lambda}$ is a diagonal matrix with the $m$'th diagonal given by the mode $1-\\mu\\lambda_\\textup{m}$. For \\eq{eq:sd_stability_req} to be fulfilled from any starting point $\\vect{w}(0)$, we must therefore require that\n\\bmath\n  \\lim_{n\\to\\infty} (1-\\mu\\lambda_\\textup{m})^n = 0\\ ,\\quad\\text{for }m=1,2,\\ldots,M\\ .\n  \\label{eq:sd_mode}\n\\emath\nThus\n\\begin{alignat}{2}\n  && -1 < 1-&\\mu\\lambda_\\textup{m} < 1\\ ,\\quad\\text{for }m=1,2,\\ldots,M\\\\\n  \\ArrowBetweenLines\n  && -1 < 1-&\\mu\\lambda_\\textup{max} < 1\n\\end{alignat}\nSolving for $\\mu$ leads to that the SD algorithm is stable if\n\\bmath\n  \\boxed{0 < \\mu < \\frac{2}{\\lambda_\\textup{max}}}\\ .\n\\emath\nFrom \\eq{eq:sd_stability_req}, we see that\n\\begin{alignat*}{2}\n  &|1-\\mu\\lambda_m|\\text{ is close to 0} &\\qquad &\\iff\\qquad\\text{ mode with fast convergence}\\\\\n  &|1-\\mu\\lambda_m|\\text{ is close to 1} &\\qquad &\\iff\\qquad\\text{ mode with slow convergence}\n\\end{alignat*}\nThe optimal step-size $\\mu_o$ is therefore given by\n\\begin{alignat}{2}\n  \\mu_o&= \\argmin_{\\mu} \\max_{\\lambda_m} & |1-\\mu\\lambda_m|&\\\\\n  &\\text{subject to }             & |1-\\mu\\lambda_m|&<1\\ ,\\text{ for } m=1,\\ldots,M\\ .\n\\end{alignat}\nThat is, $\\mu_o$ minimises the value of the largest (slowest) mode. We solve this optimisation problem by the use of Fig~\\ref{fig:optimal_step_sd}.\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/optimal_step_sd}\n  \\caption{Finding the optimal step-size.}\n  \\label{fig:optimal_step_sd}\n\\end{figure}\nFrom Fig~\\ref{fig:optimal_step_sd}, we see that the optimal step-size $\\mu_o$ satisfies\n\\begin{alignat}{2}\n   && 1-\\mu_o\\lambda_\\textup{min} &= -(1-\\mu_o\\lambda_\\textup{max})\\\\\n   \\ArrowBetweenLines\n   && \\alignedbox{\\mu_o}{=\\frac{2}{\\lambda_\\textup{max}+\\lambda_\\textup{min}}}\\ .\n\\end{alignat}\nFor the optimal step-size, the slowest modes $\\pm(1-\\mu_o\\lambda_\\textup{max})$ and $\\pm(1-\\mu_o\\lambda_\\textup{min})$ are therefore given by\n\\bmath\n  \\pm\\frac{\\lambda_\\textup{max}-\\lambda_\\textup{min}}{\\lambda_\\textup{max}+\\lambda_\\textup{min}} = \\pm\\frac{\\kappa(\\vect{R}_u)-1}{\\kappa(\\vect{R}_u)+1}\n\\emath\nwhere $\\kappa(\\vect{R}_u)$ is the condition number of the correlation matrix $\\vect{R}_u$. Thus, if the condition number is large, the slowest modes are close to one, and the convergence of the SD algorithm is slow. Conversely, if the condition number is close to one, the slowest modes are close to zero, and the convergence of the SD algorithm is fast.\n\n\\subsubsection{Learning Curve}\nThe cost function can be written as\n\\begin{align}\n  J_1(\\vect{w}(n)) &= J_1(\\vect{w}_o) + \\Delta\\vect{w}^T(n)\\vect{R}_u\\Delta\\vect{w}(n)\\\\\n  &= J_1(\\vect{w}_o) + \\Delta\\vect{w}^T(0)\\vect{X}(\\vect{I}-\\mu\\vect{\\Lambda})^n\\vect{\\Lambda}(\\vect{I}-\\mu\\vect{\\Lambda})^n\\vect{X}^T\\Delta\\vect{w}(0)\\\\\n  &= J_1(\\vect{w}_o)+\\sum_{m=1}^M\\lambda_m(1-\\mu\\lambda_m)^{2n}\\left(\\vect{x}_m^T\\Delta\\vect{w}(0)\\right)^2\\ .\n\\end{align}\nThe plot of $J_1(\\vect{w}(n))$ as a function of $n$ is called the learning curve, and a sketch of it is shown in Fig.~\\ref{eq:sd_learning_curve}.\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/learning_curve_sd}\n  \\caption{The learning curve of the steepest descent algorithm.}\n  \\label{eq:sd_learning_curve}\n\\end{figure}\n\n\\section{Least-Mean-Square Adaptive Filters}\n\\subsection{Basic Idea}\nRecall, that the gradient of the mean-squared error cost function $J_1(\\vect{w}(n))$ is\n\\bmath\n  \\vect{g}(\\vect{w}(n)) = \\frac{\\partial E[e^2(n)]}{\\partial\\vect{w}(n)} = 2E\\left[\\frac{\\partial e(n)}{\\partial\\vect{w}(n)}e(n)\\right] = -2E[\\vect{u}(n)e(n)]\\ .\n\\emath\nOften, we do not know the gradient, and we therefore have to estimate it. A simple estimate is\n\\bmath\n  \\hat{\\vect{g}}(\\vect{w}(n)) = -2\\vect{u}(n)e(n)\\ .\n\\emath\nIf we replace the gradient in the steepest descent algorithm with this estimate, we obtain\n\\bmath\n  \\boxed{\\vect{w}(n+1) = \\vect{w}(n)+\\mu\\vect{u}(n)e(n)}\n\\emath\nwhich is called the least-mean-square (LMS) algorithm. A block diagram of the LMS filter is depicted in Fig.~\\ref{eq:block_diagram_w_feedback}.\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/block_diagram_w_feedback}\n  \\caption{Typical block diagram of an adaptive filter in the case where the statistics is unknown.}\n  \\label{eq:block_diagram_w_feedback}\n\\end{figure}\nThe LMS algorithm is the simplest \\textit{stochastic gradient method} (SGM). The naming of the SGM refers to that the gradient is a stochastic process. This has the following consequences.\n\\begin{enumerate}\n  \\item The filter coefficient vector $\\vect{w}(n)$ is also a stochastic process. This makes the analysis of the SGMs difficult. To see this, consider the cost function\n\\begin{align}\n  J_1(\\vect{w}(n)) &= E[e^2(n)]\\notag\\\\\n  &= \\sigma_d^2(n) + E[\\vect{w}^T(n)\\vect{u}(n)\\vect{u}^T(n)\\vect{w}(n)]-2E[\\vect{w}^T(n)\\vect{u}(n)d(n)]\\ .\n\\end{align}\nFor the stochastic gradient methods, it is not easy to evaluate the expectations in the cost function since $\\vect{w}(n)$ and $\\vect{u}(n)$ are not independent (unless $M=1$ and $u(n)$ is a white process).\n  \\item The weight error $\\Delta\\vect{w}(n)=\\vect{w}_o-\\vect{w}(n)$ never goes permanently to zero. That is, in steady-state ($n\\to\\infty$), the filter coefficient vector $\\vect{w}(\\infty)$ fluctuates randomly around the optimum $\\vect{w}_o$. Consequently, the mean-square error (MSE) $J_1(\\vect{w}(\\infty))$ in steady-state is larger than $J_\\textup{min} = J_1(\\vect{w}_o)$ by an amount referred to as the \\textit{excess mean-square} error (EMSE)\n  \\bmath\n    J_\\textup{ex} = J_1(\\vect{w}(\\infty)) - J_\\textup{min}\\ .\n  \\emath\n  The ratio of the EMSE to the MSE is called the \\textit{misadjustment}\n  \\bmath\n    \\mathcal{M} = \\frac{J_\\textup{ex}}{J_\\textup{min}} = \\frac{J_1(\\vect{w}(\\infty))}{J_\\textup{min}}-1\\ .\n  \\emath\n\\end{enumerate}\nIn Lecture~\\ref{ch:NLMS_APA}, we say more about these parameters and the analysis of adaptive filters.\n\n\n\\subsection{Transient Analysis}\nAssume that $d(n)$ is given by\\footnote{This model is quite popular for the analysis of adaptive filters. We say more about this model in Sec.~\\ref{ssec:analysis_model}.}\n\\bmath\n  d(n) = \\vect{u}^T(n)\\vect{w}_o + v(n)\n  \\label{eq:desired_model}\n\\emath\nwhere $v(n)$ is white Gaussian noise with variance $\\sigma_v^2$ and uncorrelated with $u(n)$.  Moreover, assume that the random variables of the stochastic process $\\vect{u}(n)$ are independent and identically distributed (IID) with a Gaussian distribution and correlation matrix $\\vect{R}_u$. This assumption is infeasible unless $M=1$. Nevertheless, we make this assumption anyway in order to make the transient analysis as simple as possible. We are concerned with\n\\begin{alignat*}{2}\n  \\lim_{n\\to\\infty} E[\\Delta\\vect{w}(n)] &= 0 &\\qquad &\\text{(Convergence in mean)}\\\\\n  \\lim_{n\\to\\infty} E[\\|\\Delta\\vect{w}(n)\\|^2] &= c < \\infty &\\qquad &\\text{(Convergence in mean-square)}\n\\end{alignat*}\nwhere $\\|\\Delta\\vect{w}(n)\\|^2=\\Delta\\vect{w}^T(n)\\Delta\\vect{w}(n)$ is the vector 2-norm, and $c$ in some positive constant\\footnote{Apparently, the definition of convergence in mean-square used for adaptive filtering analysis is different from the usual definition where $c=0$.}.\n\n\\subsubsection{Convergence in the Mean}\nBy subtracting the LMS recursion from the optimal filter coefficients, we obtain\n\\begin{align}\n  \\Delta\\vect{w}(n) &= \\vect{w}_o - \\left[\\vect{w}(n-1)+\\mu\\vect{u}(n-1)e(n-1)\\right]\\\\\n  &= \\Delta\\vect{w}(n-1) - \\mu\\vect{u}(n-1)\\left[d(n-1)-\\vect{u}^T(n-1)\\vect{w}(n-1)\\right]\\\\\n  &= \\left[\\vect{I}-\\mu\\vect{u}(n-1)\\vect{u}^T(n-1)\\right]\\Delta\\vect{w}(n-1)-\\mu\\vect{u}(n-1)v(n-1)\n  \\label{eq:recur_weight_err}\n\\end{align}\nTaking the expectation of both sides and using the above assumptions, we obtain\n\\begin{align}\n  E[\\Delta\\vect{w}(n)] &= (\\vect{I}-\\mu\\vect{R}_u)E[\\Delta\\vect{w}(n-1)]\\\\\n  &= \\vect{X}(\\vect{I}-\\mu\\vect{\\Lambda})^n\\vect{X}^T E[\\Delta\\vect{w}(0)]\\ .\n\\end{align}\nThis recursion is the same as in the transient analysis of the steepest descent algorithm. We therefore have that the LMS algorithm is stable in the mean if\n\\bmath\n  \\boxed{0 < \\mu < \\frac{2}{\\lambda_\\textup{max}}}\\ .\n\\emath\nThe bound given above ensures convergence in the mean, but places no constraint on the variance of $\\Delta\\vect{w}(n)$. Furthermore, since $\\vect{R}_u$ is unknown, $\\lambda_\\textup{max}$ is unknown, and we have to estimate or upper bound it. We have that\n\\bmath\n  \\lambda_\\textup{max} \\leq \\tr{\\vect{R}_u} = \\sum_{m=1}^M r_u(0) = M r_u(0) = M E[u^2(n)]\\ .\n\\emath\nThe expected power $E[u^2(n)]$ can be estimated as \n\\bmath\n  \\hat{E}[u^2(n)] = \\frac{1}{M}\\vect{u}^T(n)\\vect{u}(n)\\ .\n\\emath\nNote that the estimation accuracy increases with the filter length $M$. From Parseval's Theorem, we also have that\n\\bmath\n  E[u^2(n)] = \\frac{1}{2\\pi}\\int_{-\\pi}^\\pi S_u(\\omega)d\\omega \\leq \\frac{1}{2\\pi}\\int_{-\\pi}^\\pi S_\\textup{max}d\\omega = S_\\textup{max}\n\\emath\nwhere $S_u(\\omega)$ is the power spectral density of $u(n)$. Thus, we have that\n\\bmath\n  \\boxed{\\frac{2}{M S_\\textup{max}}\\leq \\frac{2}{\\tr{\\vect{R}_u}} = \\frac{2}{M E[u^2(n)]} \\leq \\frac{2}{\\lambda_\\textup{max}}}\\ ,\n\\emath\nprovided that the desired signal model is given by \\eq{eq:desired_model} and that $\\vect{u}(n)$ is an IID random process.\n\n%Under the assumption that the correlation matrix of the input signal is white\n%\\bmath\n%  \\vect{R}_u = \\sigma_u^2\\vect{I}\n%\\emath\n%where $\\sigma_u^2$ is the variance of the input signal, $\\lambda_\\textup{min}$ and $\\lambda_\\textup{max}$ are both equal to $\\sigma_u^2$. Optimising the step size in this case does NOT lead to the NLMS!\n\n\\subsubsection{Convergence in the Mean-Square}\nFrom \\eq{eq:recur_weight_err}, we have that\n\\begin{align}\n  \\|\\Delta\\vect{w}(n)\\|^2={}& \\|\\left[\\vect{I}-\\mu\\vect{u}(n-1)\\vect{u}^T(n-1)\\right]\\Delta\\vect{w}(n-1)-\\mu\\vect{u}(n-1)v(n-1)\\|^2\\notag\\\\\n  ={}& \\|\\left[\\vect{I}-\\mu\\vect{u}(n-1)\\vect{u}^T(n-1)\\right]\\Delta\\vect{w}(n-1)\\|^2\\notag\\\\\n  &{}+\\mu^2v^2(n-1)\\|\\vect{u}(n-1)\\|^2\\notag\\\\\n  &{}-2\\mu v(n) \\vect{u}^T(n-1)\\left[\\vect{I}-\\mu\\vect{u}(n-1)\\vect{u}^T(n-1)\\right]\\Delta\\vect{w}(n-1)\n\\end{align}\nTaking the expectation on both sides and using the above assumptions, we obtain\n\\bmath\n  E[\\|\\Delta\\vect{w}(n)\\|^2] = E\\left[\\|\\left[\\vect{I}-\\mu\\vect{u}(n-1)\\vect{u}^T(n-1)\\right]\\Delta\\vect{w}(n-1)\\|^2\\right]+\\mu^2J_\\textup{min}\\tr{\\vect{\\Lambda}}\n\\emath\nwhere $J_\\textup{min}=\\sigma_v^2$. Evaluating the expected value of the first term and finding the values of the step-size $\\mu$ for which $E[\\|\\Delta\\vect{w}(n)\\|^2]$ converges in the mean-square require a lot of work. In Appendix~\\ref{app:lms_analysis}, we show how this can be done. Alternatively, a derivation can also be found in \\cite[pp.~452--465]{Sayed2003}. The final result is that the LMS filter is mean-square stable (and thus stable in the mean) if and only if the step-size satisfies \\cite[pp.~462]{Sayed2003}\n\\bmath\n  \\boxed{f(\\mu) = \\frac{\\mu}{2}\\sum_{m=1}^M \\frac{\\lambda_m}{1-\\mu\\lambda_m} = \\frac{1}{2}\\tr{\\vect{\\Lambda}(\\mu^{-1}\\vect{I}-\\vect{\\Lambda})^{-1}} < 1}\\ .\n\\emath\nFor small step-sizes $\\mu \\ll 1/\\lambda_\\textup{max}$, we have that\n\\bmath\n  f(\\mu) \\approx \\frac{\\mu}{2}\\sum_{m=1}^M \\lambda_m = \\frac{\\mu}{2}\\tr{\\vect{\\Lambda}} < 1\\ .\n\\emath\nwhich leads to that the LMS algorithm is mean-square stable if\n\\bmath\n  \\boxed{ 0 < \\mu < \\frac{2}{\\tr{\\vect{R}_u}}}\\ .\n\\emath\n\n\\subsubsection{Learning Curve}\nThe learning curve is also difficult to find. In Appendix~\\ref{app:lms_analysis}, we show that the learning curve is given by\n\\bmath\n    \\boxed{J_1(\\vect{w}(n)) = \\vect{\\Delta w}^T(0)\\vect{X}\\vect{S}(n)\\vect{X}^T\\vect{\\Delta w}(0)+\\mu^2J_\\textup{min}\\sum_{i=0}^{n-1}\\tr{\\vect{S}(i)\\vect{\\Lambda}}+J_\\textup{min}}\n    \\label{eq:lms_learning_curve}\n\\emath\nwhere\n\\bmath\n  \\vect{S}(n) = \\vect{S}(n-1) - 2\\mu\\vect{\\Lambda}\\vect{S}(n-1)+\\mu^2[\\vect{\\Lambda}\\tr{\\vect{S}(n-1)\\vect{\\Lambda}}+2\\vect{\\Lambda}\\vect{S}(n-1)\\vect{\\Lambda}]\n\\emath\nwith $\\vect{S}(0)=\\vect{\\Lambda}$.\n\n\\subsection{Steady-State Analysis}\nWhen the LMS algorithm is operating in steady-state and is mean-square stable, the EMSE, the mean-square deviation (MSD), and the misadjustment are \\cite[pp.~465]{Sayed2003}\n\\begin{align}\n  J_\\textup{ex} &= J_\\textup{min}\\frac{f(\\mu)}{1-f(\\mu)}\\\\\n  \\mathcal{M} &= \\frac{f(\\mu)}{1-f(\\mu)}\\\\\n  E[\\|\\vect{\\Delta}\\vect{w}(\\infty)\\|^2] &= \\frac{J_\\textup{min}}{1-f(\\mu)}\\frac{\\mu}{2}\\sum_{m=1}^M \\frac{1}{1-\\mu\\lambda_m}\\ .\n\\end{align}\nThese results are also derived in Appendix~\\ref{app:lms_analysis}. For small step-sizes $\\mu \\ll 1/\\lambda_\\textup{max}$, the EMSE, MSD, and misadjustment simplify to \\cite[pp.~465]{Sayed2003}\n\\begin{align}\n  J_\\textup{ex}&\\approx \\mu J_\\textup{min}\\frac{\\tr{\\vect{R}_u}}{2-\\mu\\tr{\\vect{R}_u}}\\approx \\frac{\\mu}{2}J_\\textup{min}\\tr{\\vect{R}_u}\\\\\n  \\mathcal{M} & \\approx \\mu \\frac{\\tr{\\vect{R}_u}}{2-\\mu\\tr{\\vect{R}_u}} \\approx \\frac{\\mu}{2}\\tr{\\vect{R}_u} = \\frac{\\mu}{2}ME[u^2(n)]\\\\\n  E[\\|\\Delta\\vect{w}(\\infty)\\|^2] &\\approx \\mu J_\\textup{min}\\frac{M}{2-\\mu\\tr{\\vect{R}_u}} \\approx \\frac{\\mu}{2}J_\\textup{min}M\\ .\n\\end{align}\nThe approximated expression for the misadjustment shows that misadjustment is approximately proportional to the input power. This is undesirable and referred to as \\textit{gradient noise amplification}. In Lecture~\\ref{ch:NLMS_APA}, we consider the normalised LMS algorithm which solves this problem.\n\n\\subsection{Computational Cost}\nTable~\\ref{tab:comp_cost_lms} shows the computational cost of the LMS algorithm in terms of the number of multiplications and additions or subtractions. From the table, we see that the total number of flops is $4M+1$. Thus, the LMS algorithm has a linear complexity $\\mathcal{O}(M)$ in the filter length $M$.\n\\begin{table}[htbp]\n  \\centering\n  \\begin{tabular}{l c c c}\n    \\toprule\n    Term & $\\times$ & $+$ or $-$ \\\\\n    \\midrule\n    $\\vect{u}^T(n)\\vect{w}(n)$ & $M$ & $M-1$ \\\\\n    $e(n)=d(n)-\\vect{u}^T(n)\\vect{w}(n)$ & & $1$ \\\\\n    $\\mu e(n)$ & $1$ & \\\\\n    $\\mu \\vect{u}(n)e(n)$ & $M$ & \\\\\n    $\\vect{w}(n)+\\mu \\vect{u}(n)e(n)$ &  & $M$ \\\\\n    \\midrule\n    Total & $2M+1$ & $2M$ \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\caption{Computational cost of the LMS algorithm.}\n  \\label{tab:comp_cost_lms}\n\\end{table}\n", "meta": {"hexsha": "8244546d8326f1470f5426954eb13249f800f130", "size": 21235, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture_notes/lectures/SD_LMS.tex", "max_stars_repo_name": "jkjaer/adaptiveFilteringLectureNotes", "max_stars_repo_head_hexsha": "194706662078f810c163e403548395a532471d0c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-07-22T19:46:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T07:10:32.000Z", "max_issues_repo_path": "lecture_notes/lectures/SD_LMS.tex", "max_issues_repo_name": "jkjaer/adaptiveFilteringLectureNotes", "max_issues_repo_head_hexsha": "194706662078f810c163e403548395a532471d0c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture_notes/lectures/SD_LMS.tex", "max_forks_repo_name": "jkjaer/adaptiveFilteringLectureNotes", "max_forks_repo_head_hexsha": "194706662078f810c163e403548395a532471d0c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.2994791667, "max_line_length": 523, "alphanum_fraction": 0.6780786437, "num_tokens": 7798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778257, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.71559584008378}}
{"text": "\\lab{Data Visualization}{Data Visualization}\n\\label{lab:DataVis}\n\\objective{\nThis lab demonstrates how to communicate information through clean, concise, and honest data visualization.\nWe recommend completing the exercises in a Jupyter Notebook.\n}\n\n\\section*{The Importance of Visualizations} % =================================\n\nVisualizations of data can reveal insights that are not immediately obvious from simple statistics.\nThe data set in the following exercise is known as \\emph{Anscombe's quartet}.\nIt is famous for demonstrating the importance of data visualization.\n\n\\begin{problem} % Describe Anscombe's Quartet\nThe file \\texttt{anscombe.npy} contains the quartet of data points shown in the table below.\nFor each section of the quartet,\n\\begin{itemize}\n\t\\setlength\\itemsep{0em}\n\t\\item Plot the data as a scatter plot on the box $[0,20]\\times[0,13]$.\n    \\item Use \\li{scipy.stats.linregress()} to calculate the slope and intercept of the least squares regression line for the data and its correlation coefficient (the first three return values).\n\t\\item Plot the least squares regression line over the scatter plot on the domain $x \\in [0,20]$.\n\t\\item Report the mean and variance in $x$ and $y$, the slope and intercept of the regression line, and the correlation coefficient.\n    Compare these statistics to those of the other sections.\n\t\\item Describe how the section is similar to the others and how it is different.\n\\end{itemize}\n\\begin{table}[H]\n\\scriptsize{\n\\begin{tabular}{rr|rr|rr|rr}\n    \\multicolumn{2}{c|}{I}    & \\multicolumn{2}{|c|}{II} &\n    \\multicolumn{2}{|c|}{III} & \\multicolumn{2}{|c}{IV} \\\\\n    \\multicolumn{1}{c}{$x$}   & \\multicolumn{1}{c|}{$y$} &\n    \\multicolumn{1}{|c}{$x$}  & \\multicolumn{1}{c|}{$y$} &\n    \\multicolumn{1}{|c}{$x$}  & \\multicolumn{1}{c|}{$y$} &\n    \\multicolumn{1}{|c}{$x$}  & \\multicolumn{1}{c}{$y$} \\\\\n    \\hline\n    10.0 & 8.04  & 10.0 & 9.14 & 10.0 & 7.46  & 8.0  & 6.58  \\\\\n    8.0  & 6.95  & 8.0  & 8.14 & 8.0  & 6.77  & 8.0  & 5.76  \\\\\n    13.0 & 7.58  & 13.0 & 8.74 & 13.0 & 12.74 & 8.0  & 7.71  \\\\\n    9.0  & 8.81  & 9.0  & 8.77 & 9.0  & 7.11  & 8.0  & 8.84  \\\\\n    11.0 & 8.33  & 11.0 & 9.26 & 11.0 & 7.81  & 8.0  & 8.47  \\\\\n    14.0 & 9.96  & 14.0 & 8.10 & 14.0 & 8.84  & 8.0  & 7.04  \\\\\n    6.0  & 7.24  & 6.0  & 6.13 & 6.0  & 6.08  & 8.0  & 5.25  \\\\\n    4.0  & 4.26  & 4.0  & 3.10 & 4.0  & 5.39  & 19.0 & 12.50 \\\\\n    12.0 & 10.84 & 12.0 & 9.13 & 12.0 & 8.15  & 8.0  & 5.56  \\\\\n    7.0  & 4.82  & 7.0  & 7.26 & 7.0  & 6.42  & 8.0  & 7.91  \\\\\n    5.0  & 5.68  & 5.0  & 4.74 & 5.0  & 5.73  & 8.0  & 6.89  \\\\\n\\end{tabular}}\n\\end{table}\n\\label{prob:anscombes-quartet}\n\\end{problem}\n\n\\section*{Improving Specific Types of Visualizations} % =======================\n\nEffective data visualizations show specific comparisons and relationships in the data.\nBefore designing a visualization, decide what to look for or what needs to be communicated.\nThen choose the visual scheme that makes sense for the data.\nThe following sections demonstrate how to improve commonly used plots to communicate information visually.\n\n\\subsection*{Line Plots} % ----------------------------------------------------\n\n\\begin{figure}[H] % Horizontal vs. vertical bar chart.\n    \\centering\n    \\begin{subfigure}{.47\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/chebyshev_bad.pdf}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.52\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/chebyshev_good.pdf}\n    \\end{subfigure}\n    \\caption{Line plots can be used to visualize and compare mathematical functions. For example, this figure shows the first nine Chebyshev polynomials in one plot (left) and small multiples (right). Using small multiples makes comparison easy and shows how each polynomial changes as $n$ increases.}\n    \\label{fig:chebyshev}\n\\end{figure}\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from matplotlib import pyplot as plt\n\n# Plot the first 9 Chebyshev polynomials in the same plot.\n>>> T = np.polynomial.Chebyshev.basis\n>>> x = np.linspace(-1, 1, 200)\n>>> for n in range(9):\n...     plt.plot(x, T(n)(x), label=\"n = \"+str(n))\n...\n>>> plt.axis([-1.1, 1.1, -1.1, 1.1])        # Set the window limits.\n>>> plt.legend(loc=\"right\")\n\\end{lstlisting}\n\nA line plot connects ordered $(x,y)$ points with straight lines, and is best for visualizing one or two ordered arrays, such as functional outputs over an ordered domain or a sequence of values over time.\nSometimes, plotting multiple lines on the same plot helps the viewer compare two different data sets.\nHowever, plotting several lines on top of each other makes the visualization difficult to read, even with a legend.\nFor example, Figure \\ref{fig:chebyshev} shows the first nine \\emph{Chebyshev polynomials}, a family of orthogonal polynomials that satisfies the recursive relation\n\\[\nT_0(x) = 1, \\qquad T_1(x) = x, \\qquad T_{n+1} = 2xT_n(x) - T_{n-1}(x).\n\\]\nThe plot on the right makes comparison easier by using \\emph{small multiples}. %, a method made famous by Edward Tufte.\nInstead of using a legend, the figure makes a separate subplot with a title for each polynomial.\nAdjusting the figure size and the line thickness also makes the information easier to read.\n\n%NumPy's \\li{polynomial} module has a convenient tool for constructing these and other important polynomials.%\n%\\footnote{\\li{numpy.polynomial} also has tools for computing other important polynomial families, including the Legendre, Hermite, and Laguerre polynomials.}\n\n\\begin{info} % LaTex with Matplotlib text.\nMatplotlib titles and annotations can be formatted with \\LaTeX, a system for creating technical documents.%\n\\footnote{See \\url{http://www.latex-project.org/} for more information.}\n% (this lab manual, for example, is written in \\LaTeX).\nTo do so, use an \\li{r} before the string quotation mark and surround the text with dollar signs.\nFor example, add the following line of code to the loop from the previous example.\n\n\\begin{lstlisting}\n...     plt.title(r\"$T_{}(x)$\".<<format>>(n))\n\\end{lstlisting}\n\nThe \\li{<<format>>()} method inserts the input $n$ at the curly braces.\nThe title of the sixth subplot, instead of being ``n = 5,'' will then be ``$T_5(x)$.''\n\\end{info}\n\n% TODO: Make sure the Bernstein polynomial notation is consistent with the book (it is consistent with Wikipedia currently)\n\n\\begin{problem} % Plot the Bernstein polynomials.\nThe $n+1$ Bernstein basis polynomials of degree $n$ are defined as follows:\n\\[b_{v,n}(x) = {{n} \\choose {v}} x^v (1-x)^{n-v},\\qquad v = 0,\\ 1,\\ \\ldots,\\ n\\]\n\nPlot the first $10$ Bernstein basis polynomials ($n = 0,\\ 1,\\ 2,\\ 3$) as small multiples on the domain $[0,1] \\times [0,1]$.\nLabel the subplots for clarity, adjust tick marks and labels for simplicity, and set the window limits of each plot to be the same.\nConsider arranging the subplots so that the rows correspond with $n$ and the columns with $v$.\n\\\\Hint: The constant ${{n} \\choose {v}} = \\frac{n!}{v!(n-v)!}$ is called the \\emph{binomial coefficient} and can be efficiently computed with \\li{scipy.special.comb()}.\n\\end{problem}\n\n\\subsection*{Bar Charts} % ----------------------------------------------------\n\n\\begin{figure}[H] % Horizontal vs. vertical bar chart.\n    \\centering\n    \\begin{subfigure}{.47\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/bar_1.pdf}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.52\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/bar_2.pdf}\n    \\end{subfigure}\n    \\caption{Bar charts are used to compare quantities between categorical variables. The labels on the vertical bar chart (left) are more difficult to read than the  labels on the horizontal bar chart (right). Although the labels can be rotated, horizontal text is much easier to read than vertical text.}\n\\end{figure}\n\n\\begin{lstlisting}\n>>> labels = [\"Lobster Thermador\", \"Baked Beans\", \"Crispy Bacon\",\n...             \"Smoked Sausage\", \"Hannibal Ham\", \"Eggs\", \"Spam\"]\n>>> values = [10, 11, 18, 19, 20, 21, 22]\n>>> positions = np.arange(len(labels))\n\n>>> plt.bar(positions, values, align=\"center\")  # Vertical bar chart.\n>>> plt.xticks(positions, labels)\n>>> plt.show()\n\n>>> plt.barh(positions, values, align=\"center\") # Horizontal bar char (better).\n>>> plt.yticks(positions, labels)\n>>> plt.tight_layout()\n>>> plt.show()\n\\end{lstlisting}\n\nA bar chart plots categorical data in a sequence of bars.\nThey are best for small, discrete, one-dimensional data sets.\nIn Matplotlib, \\li{plt.bar()} creates a vertical bar chart or \\li{plt.barh()} creates a horizontal bar chart.\nThese functions receive the locations of each bar followed by the height of each bar (as lists or arrays).\nIn most situations, horizontal bar charts are preferable to vertical bar charts because horizontal labels are easier to read than vertical labels.\nData in a bar chart should also be sorted in a logical way, such as alphabetically, by size, or by importance.\n\n\\subsection*{Histograms} % ----------------------------------------------------\n\n\\begin{figure}[H] % Cleaning up a histogram.\n    \\centering\n    \\begin{subfigure}{.47\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/hist1.pdf}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.47\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/hist2.pdf}\n    \\end{subfigure}\n    \\caption{Histograms are used to show the distribution of one-dimensional data. Experimenting with different values for the bin size is important when plotting a histogram. Using only 10 bins (left) doesn't give a good sense for how the randomly generated data is distributed. However, using 35 bins (right) reveals the shape of a normal distribution.}\n\\end{figure}\n\n\\begin{lstlisting}\n>>> data = np.random.normal(size=10000)\n>>> fig, ax = plt.subplots(1, 2)\n>>> ax[0].hist(data, bins=10)\n>>> ax[1].hist(data, bins=35)\n\\end{lstlisting}\n\nA histogram partitions an interval into a number of bins and counts the number of values that fall into each bin.\nHistograms are ideal for visualizing how unordered data in a single array is distributed over an interval.\nFor example, if data are drawn from a probability distribution, a histogram approximates the distribution's probability density function.\nUse \\li{plt.hist()} to create a histogram.\nThe arguments \\li{bins} and \\li{<<range>>} specify the number of bins to draw and over what domain.\nA histogram with too few or too many bins will not give a clear view of the distribution.\n\n\\subsection*{Scatter Plots} % -------------------------------------------------\n\n\\begin{figure}[H] % Heat maps and contour plots.\n    \\centering\n    \\begin{subfigure}{.47\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/alpha1.pdf}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.47\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/alpha2.pdf}\n    \\end{subfigure}\n    \\caption{Scatter plots show correlation between variables by plotting markers at coordinate points. The figure above displays randomly perturbed data visualized using two scatter plots with \\li{alpha=.5} and \\li{edgecolor='none'}. The default (left) makes it harder to see correlation and pattern whereas making the axes equal better reveals the oscillatory behavior in the perturbed sine wave.}\n    \\label{fig:scatter_scales}\n\\end{figure}\n\n\\begin{lstlisting}\n>>> np.random.seed(0)\n>>> x = np.linspace(0,10*np.pi,200) + np.random.normal(size=200)\n>>> y = np.sin(x) + np.random.normal(size=200)\n\n>>> plt.scatter(x, y, alpha=.5, edgecolor='none')\n>>> plt.show()\n\n>>> plt.scatter(x, y, alpha=.5, edgecolor='none')\n>>> plt.axis('equal')\n>>> plt.show()\n\\end{lstlisting}\n\nA scatter plot draws $(x,y)$ points without connecting them.\nScatter plots are best for displaying data sets without a natural order, or where each point is a distinct, individual instance.\nThey are frequently used to show correlation between variables in a data set.\nUse \\li{plt.scatter()} to create a scatter plot.%\n\\footnote{Scatter plots can also be drawn with with \\lif{plt.plot()} by specifying a point marker such as \\lif{'.'}, \\lif{','}, \\lif{'o'}, or \\lif{'+'}.\nThe keywords \\lif{s} and \\lif{c} can be used to change the marker size and marker color, respectively.}\n\nSimilar data points in a scatter plot may overlap, as in Figure \\ref{fig:scatter_scales}.\nSpecifying an \\emph{alpha value} reveals overlapping data by making the markers transparent (see Figure \\ref{fig:scatter_hexbin} for an example).\nThe keyword \\li{alpha} accepts values between 0 (completely transparent) and 1 (completely opaque).\nWhen plotting lots of overlapping points, the outlines on the markers can make the visualization look cluttered.\nSetting the edgecolor keyword to zero removes the outline and improves the visualization.\n\n\\begin{problem} % Scatter plots with visualizations.\nThe file \\texttt{MLB.npy} contains measurements from over 1,000 recent Major League Baseball players, compiled by UCLA.\\footnote{See \\url{http://wiki.stat.ucla.edu/socr/index.php/SOCR_Data_MLB_HeightsWeights}.}\nEach row in the array represents a player; the columns are the player's height (in inches), weight (in pounds), and age (in years), in that order.\n\nCreate several visualizations to show the correlations between height, weight, and age in the MLB data set.\nUse at least one scatter plot.\nAdjust the marker size, plot a regression line, change the window limits, and use small multiples where appropriate.\n\\end{problem}\n\n\\begin{problem} % Earthquake data\nThe file \\texttt{earthquakes.npy} contains data from over 17,000 earthquakes between 2000 and 2010 that were at least a 5 on the Richter scale.%\n\\footnote{See \\url{http://earthquake.usgs.gov/earthquakes/search/}.}\nEach row in the array represents an earthquake;\nthe columns are the earthquake's date (as a fraction of the year), magnitude (on the Richter scale), longitude, and latitude, in that order.\n\nBecause each earthquake is a distinct event, a good way to start visualizing this data might be a scatter plot of the years versus the magnitudes of each earthquake.\n\n\\begin{lstlisting}\n>>> year, magnitude, longitude, latitude = np.load(\"earthquakes.npy\").T\n>>> plt.plot(year, magnitude, '.')\n>>> plt.xlabel(\"Year\")\n>>> plt.ylabel(\"Magnitude\")\n\\end{lstlisting}\n\n\\begin{figure}[H] % Bad visualization: earthquake data, year vs magnitude.\n    \\centering\n    \\includegraphics[width=.7\\textwidth]{figures/earthquake.pdf}\n\\end{figure}\n\nUnfortunately, this plot communicates very little information because the data is so cluttered.\nDescribe the data with at least two better visualizations, including line plots, scatter plots, and histograms as appropriate.\nYour plots should answer the following questions:\n\\begin{enumerate}\n    \\item How many earthquakes happened every year?\n    \\item How often do stronger earthquakes happen compared to weaker ones?\n    \\item Where do earthquakes happen? Where do the strongest earthquakes happen?\n    \\\\(Hint: Use \\li{plt.axis(\"equal\")} or \\li{ax.set_aspect(\"equal\")} to fix the aspect ratio, which may improve comparisons between longitude and latitude.)\n\\end{enumerate}\n\\end{problem}\n\n\\subsection*{Hexbins} % -------------------------------------------------------\n\n\\begin{figure}[H] % Hexbins\n    \\centering\n    \\begin{subfigure}{.47\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/hexbin_1.pdf}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.47\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/hexbin_2.pdf}\n    \\end{subfigure}\n    %\n    \\caption{Hexbins can be used instead of using a three-dimensional histogram to show the distribution of two-dimensional data. Choosing the right gridsize will give a better picture of the distribution. The figure above shows random data plotted as hexbins with a gridsize of 10 (left) and 25 (right). Hexbins use color to show height via a colormap and both histograms above use the \\li{'inferno'} colormap.}\n    \\label{fig:scatter_hexbin}\n\\end{figure}\n\n\\begin{lstlisting}\n# Add random draws from various distributions in two dimensions.\n>>> a = np.random.exponential(size=1000) + np.random.normal(size=1000) + 5\n>>> b = np.random.exponential(size=1000) + 2*np.random.normal(size=1000)\n>>> x = np.hstack((a, b, 2*np.random.normal(size=1000)))\n>>> y = np.hstack((b, a,   np.random.normal(size=1000)))\n\n# Plot the samples with hexbins of gridsize 10 and 25.\n>>> fig, axes = plt.subplots(1, 2)\n>>> window = [x.min(), x.max(), y.min(), y.max()]\n>>> for ax, size in zip(axes, [10, 25]):\n...     ax.hexbin(x, y, gridsize=size, cmap='inferno')\n...     ax.axis(window)\n...     ax.set_aspect(\"equal\")\n...\n>>> plt.show()\n\\end{lstlisting}\n\nA \\emph{hexbin} is a way of representing the frequency of ocurrances in a two-dimensional plane.\nSimilar to a histogram, which sorts one-dimensional data into bins, a hexbin sorts two-dimensional data into hexagonal bins arranged in a grid and uses color instead of height to show frequency.\nCreating an effective hexbin relies on choosing an appropriate \\li{gridsize} and colormap.\nThe \\emph{colormap} is a function that assigns data points to an ordering of colors.\nUse \\li{plt.hexbin()} to create a hexbin and use the \\li{cmap} keyword to specify the colormap.\n\n\\subsection*{Heat Maps and Contour Plots} % -----------------------------------\n\n\\begin{figure}[H] % Heat maps and contour plots.\n    \\centering\n    \\begin{subfigure}{.495\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/heatmap_1.png}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.495\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/contour_1.pdf}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}{.495\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/contour_2.pdf}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.495\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/heatmap_2.png}\n    \\end{subfigure}\n    \\caption{Heat maps visualize three-dimensional functions or surfaces by using color to represent the value in one dimension. With continuous data, it can be hard to identify regions of interest. Contour plots solve this problem by visualizing the level curves of the surface. Top left: heat map. Top right: contour plot. Bottom left: heat map. Bottom right: contours plotted on a heat map.}\n    \\label{fig:heatcontour}\n\\end{figure}\n\n\\begin{lstlisting}\n# Construct a 2-D domain with np.meshgrid() and calculate f on the domain.\n>>> x = np.linspace(-1.5, 1.5, 200)\n>>> X, Y = np.meshgrid(x, x)\n>>> Z = Y**2 - X**3 + X**2\n\n# Plot f using a heat map, a contour map, and a filled contour map.\n>>> fig, ax = plt.subplots(2,2)\n>>> ax[0,0].pcolormesh(X, Y, Z, cmap=\"viridis\")     # Heat map.\n>>> ax[0,1].contour(X, Y, Z, 6, cmap=\"viridis\")     # Contour map.\n>>> ax[1,0].contourf(X, Y, Z, 12, cmap=\"magma\")   # Filled contour map.\n\n\n# Plot specific level curves and a heat map with a colorbar.\n>>> ax[1,1].contour(X, Y, Z, [-1, -.25, 0, .25, 1, 4], colors=\"white\")\n>>> cax = ax[1,1].pcolormesh(X, Y, Z, cmap=\"magma\")\n>>> fig.colorbar(cax, ax=ax[1,1])\n\n>>> plt.show()\n\\end{lstlisting}\n\nLet $f:\\mathbb{R}^2\\rightarrow\\mathbb{R}$ be a scalar-valued function on a 2-dimensional domain.\nA \\emph{heat map} of $f$ assigns a color to each $(x,y)$ point in the domain based on the value of $f(x,y)$, while a contour plot is a drawing of the \\emph{level curves} of $f$.\nThe level curve corresponding to the constant $c$ is the set $\\left\\{(x,y)\\mid c = f(x,y)\\right\\}$.\nA filled contour plot colors in the sections between the level curves and is a discretized version of a heat map.\nThe values of $c$ corresponding to the level curves are automatically chosen to be evenly spaced over the range of values of $f$ on the domain.\nHowever, it is sometimes better to strategically specify the curves by providing a list of $c$ constants.\n\nConsider the function $f(x,y) = y^2 - x^3 + x^2$ on the domain $[-\\frac{3}{2}, \\frac{3}{2}] \\times [-\\frac{3}{2}, \\frac{3}{2}]$.\nA heat map of $f$ reveals that it has a large basin around the origin.\nSince $f(0,0) = 0$, choosing several level curves close to $0$ more closely describes the topography of the basin.\nThe fourth subplot in \\ref{fig:heatcontour} uses the curves with $c = -1,\\ -\\frac{1}{4},\\ 0,\\ \\frac{1}{4},\\ 1,$ and $4$.\n\nWhen plotting hexbins, heat maps, and contour plots, be sure to choose a colormap that best represents the data.\nAvoid using spectral or rainbow colormaps like \\li{\"jet\"} because they are not \\emph{perceptually uniform}, meaning that the rate of change in color is not constant.\nBecause of this, data points may appear to be closer together or farther apart than they actually are.\nThis creates visual false positives or false negatives in the visualization and can affect the interpretation of the data.\nAs a default, we recommend using the sequential colormaps \\li{\"viridis\"} or \\li{\"inferno\"} because they are designed to be perceptually uniform and colorblind friendly.\nFor the complete list of Matplotlib color maps, see \\url{http://matplotlib.org/examples/color/colormaps_reference.html}.\n\n\\begin{problem} % Rosenbrock\nThe \\emph{Rosenbrock function} is defined as\n\\[f(x,y) = (1-x)^2 + 100(y-x^2)^2.\\]\nThe minimum value of $f$ is $0$, which occurs at the point $(1,1)$ at the bottom of a steep, banana-shaped valley of the function.\n\nUse a heat map and a contour plot to visualize the Rosenbrock function.\nAlso plot the minimizer $(1,1)$.\nUse a different sequential colormap for each visualization.\n\\end{problem}\n\n\\section*{Best Practices} % ===============================================\n\nGood scientific visualizations make comparison easy and clear.\nThe eye is very good at detecting variation in one dimension and poor in two or more dimensions.\nFor example, consider Figure \\ref{fig:piebar}.\nDespite the difficulty, most people can probably guess which slice of a pie chart is the largest or smallest.\nHowever, it's almost impossible to confidently answer the question \\emph{by how much?} The bar charts may not be as aesthetically pleasing but they make it much easier to precisely compare the data.\nAvoid using pie charts as well as other visualizations that make accurate comparison difficult, such as radar charts, bubble charts, and stacked bar charts.\n\n\\begin{figure}[H] % Pie chart --> Bar chart\n    \\centering\n    \\begin{subfigure}{.49\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/piechart1.pdf}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.49\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/piebar1.pdf}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.49\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/piechart2.pdf}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.49\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/piebar2.pdf}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.49\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/piechart3.pdf}\n    \\end{subfigure}\n    \\begin{subfigure}{.49\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/piebar3.pdf}\n    \\end{subfigure}\n    %\n    \\caption{The pie charts on the left may be more colorful but it's extremely difficult to quantify the difference between each slice. Instead, the horizontal bar charts on the right make it very easy to see the difference between each variable.}\n    \\label{fig:piebar}\n\\end{figure}\n\nNo visualization perfectly represents data, but some are better than others.\nFinding the best visualization for a data set is an iterative process.\nExperiment with different visualizations by adjusting their parameters: color, scale, size, shape, position, and length.\nIt may be necessary to use a data transformation or visualize various subsets of the data.\nAs you iterate, keep in mind the saying attributed to George Box: ``All models are wrong, but some are useful.''\nDo whatever is needed to make the visualization useful and effective.\n\n\\begin{figure}[H] % BAR CHART MONSTROSITY!\n    \\centering\n    \\begin{subfigure}{.47\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/chartjunk1.jpg}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.47\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/chartjunk_improved.pdf}\n    \\end{subfigure}\n    \\caption{Chartjunk refers to anything that does not communicate data. In the image on the left, the cartoon monster distorts the bar chart and manipulates the feelings of the viewer to think negatively about the results. The image on the right shows the same data without chartjunk, making it simple and very easy to interpret the data objectively.}\n    \\label{fig:chartjunk}\n\\end{figure}\n\nGood visualizations are as simple as possible and no simpler.\nEdward Tufte coined the term \\emph{chartjunk} to mean anything (pictures, icons, colors, and text) that does not represent data or is distracting.\nThough chartjunk might appear to make data graphics more memorable than plain visualizations, \\textbf{it is more important to be clear and precise in order to prevent misinterpretation}.\nThe physicist Richard Feynman said, ``For a successful technology, reality must take precedence over public relations, for Nature cannot be fooled.'' Remove chartjunk and anything that prevents the viewer from objectively interpreting the data.\n\n\\begin{figure}[H] % Heat maps and contour plots.\n    \\centering\n    \\begin{subfigure}{.495\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/plannedparenthood}\n    \\end{subfigure}\n    %\n    \\begin{subfigure}{.495\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{figures/planparent_corrected}\n    \\end{subfigure}\n    \\caption{The chart on the left is an example of a dishonest graphic shown at a United States congressional hearing in 2015. The chart on the right shows a more accurate representation of the data by showing the y-axis and revealing the missing data from 2008. Source: PolitiFact.}\n    \\label{fig:planparent}\n\\end{figure}\n\nVisualizations should be honest.\nFigure \\ref{fig:planparent} shows how visualizations can be dishonest.\nThe misleading graphic on the left was used as evidence in a United States congressional hearing in 2015.\nWith the $y$-axis completely removed, it is easy to miss that each line is shown on a different $y$-axis even though they are measured in the same units.\nFurthermore, the chart fails to indicate that data is missing from the year 2008.\nThe graphic on the right shows a more accurate representation of the data.\\footnote{For more information about this graphic, visit \\url{http://www.politifact.com/truth-o-meter/statements/2015/oct/01/jason-chaffetz/chart-shown-planned-parenthood-hearing-misleading-/}.}\n\nNever use data visualizations to deceive or manipulate.\nAlways present information on who created it, where the data came from, how it was collected, whether it was cleaned or transformed, and whether there are conflicts of interest or possible biases present.\nUse specific titles and axis labels, and include units of measure.\nChoose an appropriate window size and use a legend or other annotations where appropriate.\n\n\\begin{problem}\nThe file \\texttt{countries.npy} contains information from 20 different countries.\nEach row in the array represents a different country; the columns are the 2015 population (in millions of people), the 2015 GDP (in billions of US dollars), the average male height (in centimeters), and the average female height (in centimeters), in that order.%\n\\footnote{\nSee \\url{https://en.wikipedia.org/wiki/List_of_countries_by_GDP_(nominal)},\n\\\\ \\url{https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population}, and\n\\\\ \\url{http://www.averageheight.co/}.\n}\n\nThe countries corresponding are listed below in order.\n\n\\begin{lstlisting}\ncountries = [\"Austria\", \"Bolivia\", \"Brazil\", \"China\",\n            \"Finland\", \"Germany\", \"Hungary\", \"India\",\n            \"Japan\", \"North Korea\", \"Montenegro\", \"Norway\",\n            \"Peru\", \"South Korea\", \"Sri Lanka\", \"Switzerland\",\n            \"Turkey\", \"United Kingdom\", \"United States\", \"Vietnam\"]\n\\end{lstlisting}\n\nVisualize this data set with at least four plots, using at least one scatter plot, one histogram, and one bar chart.\nList the major insights that your visualizations reveal.\n\\\\(Hint: consider using \\li{np.argsort()} and fancy indexing to sort the data for the bar chart.)\n\\end{problem}\n\nFor more about data visualization, we recommend the following books and websites.\n\\begin{itemize}\n    \\item \\emph{How to Lie with Statistics} by Darrell Huff (1954).\n    \\item \\emph{The Visual Display of Quantitative Information} by Edward Tufte (2nd edition).\n    \\item \\emph{Visual Explanations} by Edward Tufte.\n    \\item \\emph{Envisioning Information} by Edward Tufte.\n    \\item \\emph{Beautiful Evidence} by Edward Tufte.\n    \\item \\emph{The Functional Art} by Alberto Cairo.\n    \\item \\emph{Visualization Analysis and Design} by Tamara Munzner.\n    \\item \\emph{Designing New Default Colormaps}: \\url{https://bids.github.io/colormap/}.\n\\end{itemize}\n", "meta": {"hexsha": "ff9b1a6cd38860c93613d6896a8258efb427299e", "size": 29275, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/PythonEssentials/DataVisualization/DataVisualization.tex", "max_stars_repo_name": "DM561/dm561.github.io", "max_stars_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-13T13:22:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-13T13:22:41.000Z", "max_issues_repo_path": "acme-material/Labs/PythonEssentials/DataVisualization/DataVisualization.tex", "max_issues_repo_name": "DM561/dm561.github.io", "max_issues_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-10-18T19:57:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-31T19:00:36.000Z", "max_forks_repo_path": "acme-material/Labs/PythonEssentials/DataVisualization/DataVisualization.tex", "max_forks_repo_name": "DM561/dm561.github.io", "max_forks_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.7196261682, "max_line_length": 412, "alphanum_fraction": 0.7140222032, "num_tokens": 7825, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.9111797124237604, "lm_q1q2_score": 0.7155572468972188}}
{"text": "\n\\subsection{Congruence}\n\n\\(5\\) and \\(11\\) are congrument \\(\\mod 3\\)\n\nIf \\(a \\mod(n)=b mod(n)\\) then \\(a\\) and \\(b\\) are congruent mod \\(n\\).\n\n", "meta": {"hexsha": "3b73c1a45164df4f18720f4c9444e00a6feb22c3", "size": 143, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/modulus/01-03-congruence.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/modulus/01-03-congruence.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/modulus/01-03-congruence.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.875, "max_line_length": 71, "alphanum_fraction": 0.5594405594, "num_tokens": 53, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107896491796, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.7155452310124204}}
{"text": "\\documentclass[a4paper,11pt]{scrartcl}\n\n\\usepackage{amsmath,amssymb}\n\\usepackage[utf8]{inputenc}\n\n\\title{Derivatives of the likelihood for a beta-psychometric function}\n\\author{Ingo Fründ}\n\\date{\\today}\n\n\\def\\rd{\\mathrm{d}}\n\\def\\p{\\partial}\n\\def\\ddlnu{\\frac{\\p^2\\ell_i}{\\p\\nu^2}}\n\\def\\ddlf{\\frac{\\p^2\\ell_i}{\\p f_i^2}}\n\\def\\ddlfnu{\\frac{\\p^2\\ell_i}{\\p f_i\\p\\nu}}\n\\def\\dfdt{\\frac{\\p f_i}{\\p\\theta}}\n\n\\begin{document}\n\n\\maketitle\n% Your text here\n\n\\section{Log likelihood}\n\nThe log likelihood for a beta-psychometric function can be written as\n%\n$$\n\\ell = \\sum_{i=1}^m \\ell_i,\n$$\n%\nwhere $m$ is the number of blocks in the experiment and\n%\n$$\n\\ell_i = \\log\\Gamma(\\nu n_i) - \\log\\Gamma( f_i\\nu n_i ) - \\log\\Gamma( (1-f_i) \\nu n_i ) + ( f_i \\nu n_i - 1 ) \\log p_i + ( (1-f_i) \\nu n_i - 1 ) \\log (1-p_i).\n$$\n%\nHere, $f_i = \\gamma + (1-\\gamma-\\lambda) F(g(x_i,\\alpha,\\beta))$, i.e. the predicted value of the psychometric function, and\n$p_i = k_i/n_i$, i.e. the observed probability of a correct response.\n\n\\section{Derivatives of the log likelihood function}\n\nDerivatives of the log likelihood function involve the $\\psi$ function,\n%\n$$\n\\psi = \\frac{\\rd}{\\rd x} \\log\\Gamma.\n$$\n%\nThey read:\n%\n$$\n\\frac{\\p \\ell_i}{\\p\\nu} = n_i\\psi(\\nu n_i) - f_i n_i \\psi ( f_i\\nu n_i) - (1-f_i) n_i \\psi ( (1-f_i) \\nu n_i) + f_i n_i \\log(p_i) + (1-f_i) n_i \\log(1-p_i),\n$$\n%\nand\n%\n$$\n\\frac{\\p \\ell_i}{\\p f_i} = \\nu n_i \\Big( \\log\\frac{p_i}{1-p_i} + \\psi ( (1-f_i) \\nu n_i) - \\psi ( f_i \\nu n_i) \\Big).\n$$\n%\nIn order to obtain derivatives of the log likelihood with respect to parameters $\\alpha,\\beta,\\gamma,\\delta$, we use the definition of $f_i$ to arrive at\n%\n$$\n\\frac{\\p \\ell_i}{\\p \\theta} = \\frac{\\p\\ell_i}{\\p f_i} \\frac{\\p f_i}{\\p \\theta}, \\quad \\theta\\in\\{\\alpha,\\beta,\\gamma,\\delta\\}.\n$$\n%\nThese are given by:\n%\n\\begin{align*}\n    \\frac{\\p f_i}{\\p\\alpha} &= (1-\\gamma-\\lambda) F' ( g(x_i,\\alpha,\\beta) ) \\frac{\\p g}{\\p \\alpha} ( x_i, \\alpha, \\beta ),\\\\\n    \\frac{\\p f_i}{\\p\\beta} &= (1-\\gamma-\\lambda) F' ( g(x_i,\\alpha,\\beta) ) \\frac{\\p g}{\\p \\beta} ( x_i, \\alpha, \\beta ),\\\\\n    \\frac{\\p f_i}{\\p\\lambda} &= -F(g(x_i,\\alpha,\\beta)),\\\\\n    \\frac{\\p f_i}{\\p \\gamma} &= 1-F(g(x_i,\\alpha,\\beta)).\n\\end{align*}\n%\n\n\\section{Second derivatives of the log likelihood function}\n\nThe second derivatives of the log likelihood function involve derivatives of the $\\psi$ function.\nThese are called the trigamma function and are notated by $\\psi'$.\n%\n$$\n\\ddlnu = \\psi' (\\nu n_i) n_i^2 - f_i^2 n_i^2\\psi' (f_i\\nu n_i) - (1-f_i)^2n_i^2 \\psi' ( (1-f_i)\\nu n),\n$$\n%\nand\n%\n$$\n\\ddlf = - (\\nu n)^2 \\Big(\\psi' ( f_i \\nu n) + \\psi'( (1-f_i)\\nu n) \\Big).\n$$\nFinally, we have\n%\n$$\n\\ddlfnu = - n_i \\psi ( f_i \\nu n_i ) - f_i n_i^2\\nu \\psi' ( f_i\\nu n_i ) + n_i\\psi( (1-f_i)\\nu n_i) + (1-f)n_i^2\\nu\\psi'( (1-f_i)\\nu n_i) + n_i \\log\\frac{p_i}{1-p_i}.\n$$\n%\n\nWe can use these identities to derive expressions for derivatives of the log likelihood function with respect to parameters of the psychometric function:\n%\n$$\n\\frac{\\p^2 \\ell_i}{\\p \\lambda^2} = \\frac{\\p^2\\ell_i}{\\p \\gamma^2} = 0,\n$$\n%\n$$\n\\frac{\\p^2\\ell_i}{\\p\\alpha^2} = (1-\\gamma-\\lambda) \\ddlf \\cdot \\Big( F''(g(x_i,\\alpha,\\beta))\\frac{\\p g}{\\p\\alpha}(x_i,\\alpha,\\beta) + F'(g(x_i,\\alpha,\\beta))\\frac{\\p^2g}{\\p\\alpha^2}(x_i,\\alpha,\\beta)\\Big),\n$$\n%\n$$\n\\frac{\\p^2\\ell_i}{\\p\\beta^2} = (1-\\gamma-\\lambda) \\ddlf \\cdot \\Big( F''(g(x_i,\\alpha,\\beta))\\frac{\\p g}{\\p\\beta}(x_i,\\alpha,\\beta) + F'(g(x_i,\\alpha,\\beta))\\frac{\\p^2g}{\\p\\beta^2}(x_i,\\alpha,\\beta)\\Big).\n$$\n%\n\nThe crossterms are\n%\n\\begin{align*}\n\\frac{\\p^2\\ell_i}{\\p\\alpha\\p\\beta} &= (1-\\gamma-\\lambda)\\ddlf\\cdot \\Big( F''(g(x_i,\\alpha,\\beta))\\frac{\\p g}{\\p\\alpha}\\frac{\\p g}{\\p\\beta} + F'(g(x_i,\\alpha,\\beta))\\frac{\\p^2}{\\p\\alpha\\p\\beta}\\Big), \\\\\n\\frac{\\p^2\\ell_i}{\\p\\alpha\\p\\gamma} &= - \\ddlf F'(g(x_i,\\alpha,\\beta)) \\frac{\\p g}{\\p\\alpha},\n\\end{align*}\n%\nand an analogous expression for $\\frac{\\p^2\\ell_i}{\\p\\beta\\p\\gamma}$.\nFurther\n%\n$$\n\\frac{\\p^2\\ell_i}{\\p\\alpha\\p\\gamma} = \\ddlf (1-F'(g(x_i,\\alpha,\\beta)) \\frac{\\p g}{\\p\\alpha}),\n$$\n%\nwith an analogous expression for $\\frac{\\p^2\\ell_i}{\\p\\beta\\p\\lambda}$.\n\nWe now come the the final crossterm\n%\n\\begin{align*}\n\\frac{\\p^2\\ell_i}{\\p\\theta\\p\\nu} &= \n    - n_i\\dfdt \\Big ( \\psi (f_i \\nu n_i) + f_i\\nu n_i \\psi'(f_i\\nu n_i)\\Big)\\\\\n    &\\quad+ n_i\\dfdt \\Big ( \\psi ( (1-f_i)\\nu n_i) + (1-f_i)\\nu n_i\\psi'( (1-f_i)\\nu n_i) \\Big)\\\\\n    &\\quad+ n_i\\dfdt \\log\\frac{p_i}{1-p_i},\n\\end{align*}\n%\nwhere $\\theta \\in\\{\\alpha,\\beta,\\lambda,\\gamma\\}$.\n\n\\end{document}\n", "meta": {"hexsha": "e9e5d8a06792e5456cc01932c45a93e74e35f631", "size": 4474, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/betaderivatives.tex", "max_stars_repo_name": "esc/Psignifit-3.x", "max_stars_repo_head_hexsha": "2a2a8a40f39d94f8fee99cb0ba4b9595ae216f88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2015-07-14T23:38:52.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-12T08:15:36.000Z", "max_issues_repo_path": "documents/betaderivatives.tex", "max_issues_repo_name": "esc/Psignifit-3.x", "max_issues_repo_head_hexsha": "2a2a8a40f39d94f8fee99cb0ba4b9595ae216f88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "documents/betaderivatives.tex", "max_forks_repo_name": "esc/Psignifit-3.x", "max_forks_repo_head_hexsha": "2a2a8a40f39d94f8fee99cb0ba4b9595ae216f88", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-11-25T10:11:04.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-12T08:17:48.000Z", "avg_line_length": 32.1870503597, "max_line_length": 206, "alphanum_fraction": 0.6115333035, "num_tokens": 1854, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.7155452148545937}}
{"text": "\\section{Approximation Rates for Cosine Networks} \n \nTo begin, we remark that throughout this manuscript, we use the following convention for the Fourier transform\n\\begin{equation}\n \\hat{f}(\\xi) = \\int_{\\mathbb{R}^d} f(x)e^{-2\\pi {\\mathrm{i}\\mkern1mu} \\xi\\cdot x}dx,\n\\end{equation}\nfor which the inverse transform is given by\n\\begin{equation}\n f(x) = \\int_{\\mathbb{R}^d} \\hat{f}(\\xi)e^{2\\pi {\\mathrm{i}\\mkern1mu}    \\xi\\cdot x}d\\xi.\n\\end{equation}\nWe find that this convention results in the cleanest arguments, avoiding the necessity to keep track of normalizing constants.\n\nIn this section, we analyze the approximation properties of networks with a cosine activation function on the spectral Barron space $\\mathcal{B}^s(\\Omega)$. Specifically, consider approximating a function $f\\in \\mathcal{B}^s(\\Omega)$ by a superposition of finitely many complex complex exponentials with coefficients that are bounded in $\\ell^1$, i.e. by an element of the set\n\\begin{equation}\n \\Sigma_{n,M} = \\left\\{\\sum_{j=1}^n a_je^{2\\pi {\\mathrm{i}\\mkern1mu}  \\theta_j\\cdot x}:~\\theta_j\\in \\mathbb{R}^d,~a_j\\in\\mathbb{C},~\\sum_{i=1}^n|a_i|\\leq M\\right\\}.\n\\end{equation}\n\nAlternatively, one can view this as the set of neural networks with a single hidden layer containing $n$ neurons with activation function $\\sigma(x) = e^{2\\pi {\\mathrm{i}\\mkern1mu}  x}$, whose weights are bounded in $\\ell^1$.\n\nEquivalently, we can consider approximation by networks with a cosine activation function\n\\begin{equation}\n  \\Sigma^{\\cos}_{n,M} = \\left\\{\\sum_{i=1}^n a_i\\cos(2\\pi\\theta_i\\cdot x + b_i):~\\theta_i\\in \\mathbb{R}^d,~b_i\\in \\mathbb{R},~\\sum_{i=1}^n|a_i| \\leq M\\right\\}.\n \\end{equation}\nThis is because \n\\begin{equation}\ne^{2\\pi {\\mathrm{i}\\mkern1mu}  \\theta_i\\cdot x} = \\cos(2\\pi\\theta_i\\cdot x) + i\\cos\\left(2\\pi\\theta_i\\cdot x - \\frac{\\pi}{2}\\right)\\in \\Sigma^{\\cos}_{2,2}\n\\end{equation}\nand\n\\begin{equation}\n \\cos(2\\pi\\theta_i\\cdot x) = \\frac{1}{2}e^{2\\pi {\\mathrm{i}\\mkern1mu}  \\theta_i\\cdot x} + \\frac{1}{2}e^{-2\\pi {\\mathrm{i}\\mkern1mu}  \\theta_i\\cdot x}\\in \\Sigma^d_{2,1}.\n\\end{equation}\nThus we have $\\Sigma_{n,M}\\subset \\Sigma^{\\cos}_{2n,2M}$ and $\\Sigma^{\\cos}_{n,M} \\subset \\Sigma_{2n,M}$ and so the rates obtained for both sets will be the same. In what follows, we consider $\\Sigma_{n,M}$ for convenience in dealing with the Fourier transform.\n \nWe begin with a key lemma showing that we only need frequencies lying on a lattice to represent functions $f$ with decaying Fourier transform on a bounded set.\n\\begin{lemma}\\label{fourier-representation-lemma-general}\n Let $\\Omega=[0,1]^d$ and $\\mu:\\mathbb{R}^d\\rightarrow \\mathbb{R}_+$ be a continuous weight function. Suppose that $\\mu$ satisfies the following conditions\n \\begin{itemize}\n  \\item $\\mu(\\xi + \\omega) \\leq \\mu(\\xi)\\mu(\\omega)$\n  \\item There exists a $0 < \\beta < 1$ and a $c > 0$ such that $\\mu(\\xi) \\lesssim e^{c|\\xi|^{\\beta}}$.\n \\end{itemize}\n\n Suppose that $f$ satisfies\n \\begin{equation}\n  \\int_{\\mathbb{R}^d} \\mu(\\xi)|\\hat{f}(\\xi)|d\\xi = C_f < \\infty.\n \\end{equation}\n\n Then for any $L > 1$, there exists an $a\\in L^{-1}[0,1]^d$ (which may depend on $f$) and coefficients $c_\\xi$, such that for $x\\in \\Omega$\n \\begin{equation}\n  f(x) = \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d}c_\\xi e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a+\\xi)\\cdot x}\n \\end{equation}\n and\n \\begin{equation}\n  \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d} \\mu(a+\\xi)|c_\\xi| \\lesssim C_f.\n \\end{equation}\n\n\\end{lemma}\n\nNote that the suppressed constant in the above lemma only depends upon $d,\\mu$ and $L$, but not on $f$ or $a$. Furthmore, we note that from the proof below it follows that the suppressed constant depends exponentially on the dimension $d$.\n\n\\begin{proof}\n Since by assumption $L > 1$, there exists an $\\epsilon$ such that $\\Omega\\subset [0,L-2\\epsilon]^d$. We begin by constructing a cutoff function $\\phi_\\Omega$, which is identically $1$ on $\\Omega$ and $0$ outside of $[-\\epsilon, L-\\epsilon]^d$. It will be important that the Fourier transform $\\hat{\\phi}_\\Omega$ has sufficiently fast decay, so that\n \\begin{equation}\n  \\int_{\\mathbb{R}^d}\\mu(\\xi)|\\hat{\\phi}_\\Omega(\\xi)| < \\infty.\n \\end{equation}\n \n To construct this function, we follow closely the calculation made in \\cite{johnson2015saddle}. Choose $\\alpha > 1$ such that $\\beta < 1-\\alpha^{-1} < 1$ and consider the smooth one-dimensional bump function $g$ by \\eqref{alpha-g}.\n Let $g_d$ denote the $n$-dimensional function\n \\begin{equation}\n  g_d(x) = \\frac{1}{C}\\prod_{i=1}^d g(x_i),\n \\end{equation}\n where the normalization constant $C$ is chosen so that $\\int_{\\mathbb{R}^d} g_d(x) = 1$. Then by \\eqref{eq_181} we see that\n \\begin{equation}\n  |\\hat{g}_d(\\xi)|\\lesssim e^{-c_\\alpha\\sum_{i=1}^d|\\xi_i|^{1-\\alpha^{-1}}} \\lesssim e^{-c_{\\alpha,d}\\alpha|\\xi|^{1-\\alpha^{-1}}},\n \\end{equation}\n for a new constant $c_{\\alpha,d}$.\n \n Finally, let $\\Omega^\\prime = [-\\frac{\\epsilon}{2}, L - \\frac{3\\epsilon}{2}]$ and define\n \\begin{equation}\n  \\phi_\\Omega = \\left(4^d\\epsilon^{-d}g_d\\left(4\\epsilon^{-1}x\\right)\\right)*\\chi_{\\Omega^\\prime}(x).\n \\end{equation}\n The compact support and normalization of $g_d$  implies that $\\phi_\\Omega|_\\Omega = 1$ and $\\phi_\\Omega = 0$ outside of $[-\\epsilon, L-\\epsilon]^d$. Furthermore, we calculate\n \\begin{equation}\n  |\\hat{\\phi}_\\Omega(\\xi)| = \\left|\\hat{g}_d\\left(\\frac{\\epsilon}{4}\\xi\\right)\\widehat{\\chi}_{\\Omega^\\prime}\\right| \\lesssim e^{-c_{\\alpha,\\Omega}|\\xi|^{1-\\alpha^{-1}}}\n \\end{equation}\n for a constant $c_{\\alpha,\\Omega}$, since $\\widehat{\\chi}_{\\Omega^\\prime}$ is bounded. The growth condition on $\\mu$, combined with $\\beta < 1-\\alpha^{-1} < 1$ means that\n \\begin{equation}\\label{eq_205}\n  \\int_{\\mathbb{R}^d}\\mu(\\xi)|\\hat{\\phi}_\\Omega(\\xi)| < \\infty.\n \\end{equation}\n \n Now consider the function $h_f = \\phi_\\Omega f$. Evidently $h_f = f$ on $\\Omega$ and $h_f$ is supported on $[-\\epsilon,L-\\epsilon]^d$. Notice further that $\\hat{h}_f = \\hat{\\phi}_\\Omega * \\hat{f}$ and we calculate\n \\begin{equation}\n  \\begin{split}\n  \\int_{\\mathbb{R}^d} \\mu(\\xi)|\\hat{h}_f(\\xi)|d\\xi &\\leq \\int_{\\mathbb{R}^d} \\int_{\\mathbb{R}^d}\\mu(\\xi) |\\hat{\\phi}_\\Omega(\\xi - \\omega)||\\hat{f}(\\omega)| d\\omega d\\xi \\\\\n  &=\\int_{\\mathbb{R}^d} \\left(\\int_{\\mathbb{R}^d}\\mu(\\xi + \\omega) |\\hat{\\phi}_\\Omega(\\xi)|d\\xi\\right)|\\hat{f}_e(\\omega)| d\\omega. \n  \\end{split}\n \\end{equation}\n Now $\\mu(\\xi + \\omega) \\leq \\mu(\\xi)\\mu(\\omega)$, so that we get\n \\begin{equation}\\label{eq_369}\n  \\int_{\\mathbb{R}^d} \\mu(\\xi)|\\hat{h}_f(\\xi)|d\\xi \\leq \\left(\\int_{\\mathbb{R}^d}\\mu(\\xi) |\\hat{\\phi}_\\Omega(\\xi)|d\\xi\\right)\\left(\\int_{\\mathbb{R}^d}\\mu(\\omega) |\\hat{f}(\\omega)|d\\omega\\right) \\lesssim C_f,\n \\end{equation}\n where the implied constant depends the value of the integral in \\eqref{eq_205}.\n \n We now rewrite the integral in \\eqref{eq_369} as\n \\begin{equation}\n  \\int_{\\mathbb{R}^d} \\mu(\\xi)|\\hat{h}_f(\\xi)|d\\xi = \\int_{[0,L^{-1}]^d} \\left(\\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d} \\mu(a+\\xi)|\\hat{h}_f(a+\\xi)|\\right)da \\lesssim C_f.\n \\end{equation}\n Certainly this means that there must exist an $a\\in [0,L^{-1}]^d$ (depending on $f$) such that\n \\begin{equation}\n  \\left(\\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d} \\mu(a+\\xi)|\\hat{h}_f(a+\\xi)|\\right) \\lesssim C_f,\n \\end{equation}\n where the implied constant only depends upon $L$ and $d$.\n \n We proceed to apply the Poisson summation formula and the fact that $h_f$ is supported in $[-\\epsilon,L-\\epsilon]^d$ to conclude that for a.e. $x\\in \\Omega \\subset [-\\epsilon,L-\\epsilon]^d$ we have\n \\begin{equation}\n  f(x) = h_f(x) = \\sum_{\\nu \\in L\\mathbb{Z}^d} h_f(x+\\nu)e^{2\\pi {\\mathrm{i}\\mkern1mu}  a\\cdot \\nu} = \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d}\\hat{h}_f(a+\\xi) e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a+\\xi)\\cdot x}. \n \\end{equation}\n Here we have applied the Poisson summation formula to the function $g(\\nu) = h_f(x+\\nu)e^{2\\pi {\\mathrm{i}\\mkern1mu}  a\\cdot \\nu}$, whose Fourier transform is easily seen to be $\\hat{g}(\\xi) = \\hat{h}_f(a+\\xi) e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a+\\xi)\\cdot x}$.\n \n Setting $c_\\xi = \\hat{h}_f(a+\\xi)$ we obtain the desired result.\n\\end{proof}\n\nWe now apply Lemma \\ref{fourier-representation-lemma-general} with $\\mu(\\xi) = (1 + |\\xi|)^s$ to obtain the following corollary concerning the spectral Barron space $\\mathcal{B}^s(\\Omega)$.\n\\begin{corollary}\\label{fourier-representation-lemma}\n Let $\\Omega = [0,1]^d$ and $s \\geq 0$. Let $f\\in \\mathcal{B}^s(\\Omega)$. Then for any $L > 1$, there exists an $a\\in L^{-1}[0,1]^d$ (potentially depending upon $f$) and coefficients $c_\\xi$ such that\n for $x\\in \\Omega$\n \\begin{equation}\n  f(x) = \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d}c_\\xi e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a+\\xi)\\cdot x}\n \\end{equation}\n and\n \\begin{equation}\n  \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d} (1+|a+\\xi|)^s|c_\\xi| \\lesssim \\|f\\|_{\\mathcal{B}^s(\\Omega)}.\n \\end{equation}\n\n\\end{corollary}\n\\begin{proof}\n This follows immediately from Lemma \\ref{fourier-representation-lemma-general} given the characterization of $\\mathcal{B}^s(\\Omega)$ and the elementary fact that $(1 + |\\xi + \\omega|)\\leq (1 + |\\xi| + |\\omega|) \\leq (1 + |\\xi|)(1 + |\\omega|)$.\n\\end{proof}\n\n\nCorollary \\ref{fourier-representation-lemma} can be used to improve upon the $O(n^{-\\frac{1}{2}})$ approximation rate of cosine networks obtained in \\cite{jones1992simple} when $f\\in \\mathcal{B}^s(\\Omega)$ for $s > 0$.\n\n\\begin{theorem}\\label{approximation-rate-theorem}\n Let $\\Omega = [0,1]^d$, $0\\leq m\\leq s$, and $f\\in \\mathcal{B}^s(\\Omega)$. Then there is an $M\\lesssim \\|f\\|_{\\mathcal{B}^s(\\Omega)}$ such that\n \\begin{equation}\n  \\inf_{f_n\\in \\Sigma_{n,M}} \\|f-f_n\\|_{H^m(\\Omega)} \\lesssim \\|f\\|_{\\mathcal{B}^s(\\Omega)}n^{-\\frac{1}{2} - \\frac{s-m}{d}}.\n \\end{equation}\n\n\\end{theorem}\n\nNote that the implied constant in the above theorem depends only upon $s,m$, and $d$, but not on $f$. Comparing this with the results in \\cite{jones1992simple}, we obtain a dimension dependent improvement similar to what can be obtained using stratified sampling \\cite{klusowski2018approximation} for rectified linear networks. However, the improvement in Theorem \\ref{approximation-rate-theorem}, which is obtained via an entirely different argument, is greater and holds for cosine networks. We will consider rectified linear networks in the next section. Also, we note that for the Sobolev spaces $H^{\\frac{d}{2} + s}(\\Omega)$, this result already appears in \\cite{petrushev1998approximation} . However, our results apply to the spectral Barron space $\\mathcal{B}^s(\\Omega)$, which is not quite comparable, but we do have $H^{\\frac{d}{2} + s + \\epsilon}(\\Omega)\\subset \\mathcal{B}^s(\\Omega)$ (see \\cite{CiCP-28-1707} Lemma 2.5, for instance). Finally, as shown in Theorem \\ref{fourier-lower-bound}, the rate in Theorem \\ref{approximation-rate-theorem} is actually sharp.\n\n\\begin{proof}\n Choose $L > 1$. Note that all of the implied constants in what follows depend only upon $s,m,d$ and $L$, but not upon $f$. \n \n By Corollary \\ref{fourier-representation-lemma}, there exists an $a\\in L^{-1}[0,1]^d$ and coefficients $c_\\xi$ such that\n  \\begin{equation}\\label{eq-580}\n  f(x) = \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d}c_\\xi e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a+\\xi)\\cdot x},\n \\end{equation}\n and (here the first estimate follows since $|a|\\leq L^{-d}\\sqrt{d}$)\n \\begin{equation}\\label{eq_613}\n  \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d} (1+|\\xi|)^s|c_\\xi| \\eqsim \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d} (1+|a+\\xi|)^s|c_\\xi|  \\lesssim \\|f\\|_{\\mathcal{B}^s(\\Omega)}.\n \\end{equation}\n Consider the slightly enlarged set $\\Omega^\\prime = [0,L]^d \\supset \\Omega$. On this larger set, we have for $\\xi\\neq\\nu\\in L^{-1}\\mathbb{Z}^d$\n \\begin{equation}\\label{orthogonality-condition}\n  \\langle e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a+\\xi)\\cdot x}, e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a+\\nu)\\cdot x}\\rangle_{H^k(\\Omega^\\prime)} = 0,\n \\end{equation}\n so that the frequencies in the expansion \\eqref{eq-580} form an orthogonal basis in $H^k(\\Omega^\\prime)$. Moreover, their lengths satisfy\n \\begin{equation}\\label{length-estimate}\n  \\|e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a+\\xi)\\cdot x}\\|_{H^m(\\Omega^\\prime)} \\lesssim (1+|a+\\xi|)^m \\eqsim (1+|\\xi|)^m.\n \\end{equation}\n Order the frequencies $\\xi\\in L^{-1}\\mathbb{Z}^d$ such that\n \\begin{equation}\n   (1+|\\xi_1|)^{2m-s}|c_{\\xi_1}| \\geq (1+|\\xi_2|)^{2m-s}|c_{\\xi_2}| \\geq (1+|\\xi_3|)^{2m-s}|c_{\\xi_3}| \\geq \\cdots.\n \\end{equation}\n\n For $n \\geq 1$, let $S_n = \\{\\xi_1,\\xi_2,...,\\xi_n\\}$ and set \n \\begin{equation}\n  f_n = \\sum_{\\xi\\in S_n}c_\\xi e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a+\\xi)\\cdot x} \\in \\Sigma_{n,M}\n \\end{equation}\n for $M\\lesssim \\|f\\|_{\\mathcal{B}^s}$ by \\eqref{eq_613}.\n \n We now estimate, using \\eqref{orthogonality-condition} and \\eqref{length-estimate},\n \\begin{equation}\\label{eq_634}\n  \\|f - f_n\\|^2_{H^m(\\Omega^\\prime)} = \\left\\|\\sum_{\\xi\\in S_n^c} c_\\xi e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a+\\xi)\\cdot x} \\right\\|^2_{H^m(\\Omega^\\prime)} = \\sum_{\\xi\\in S_n^c} |c_\\xi|^2\\|e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a+\\xi)\\cdot x}\\|_{H^m(\\Omega^\\prime)}^2 \\lesssim \\sum_{\\xi\\in S_n^c} |c_\\xi|^2(1+|\\xi|)^{2m}.\n \\end{equation}\n Using Hoelder's inequality, we get\n \\begin{equation}\\label{eq_638}\n  \\sum_{\\xi\\in S_n^c} |c_\\xi|^2(1+|\\xi|)^{2m} \\leq \\left(\\sup_{\\xi\\in S_n^c} |c_\\xi|(1+|\\xi|)^{2m-s} \\right)\\left(\\sum_{\\xi\\in S_n^c}|c_\\xi|(1+|\\xi|)^{s}\\right)\n \\end{equation}\n By \\eqref{eq_613}, the second term above is $\\lesssim \\|f\\|_{\\mathcal{B}^s(\\Omega)}$. For the first term, we note that \\eqref{eq_613} implies that\n \\begin{equation}\\label{eq_642}\n  \\sum_{\\nu\\in S_n} |c_\\nu|(1+|\\nu|)^{2m-s}(1+|\\nu|)^{2(s-m)}\\lesssim \\|f\\|_{\\mathcal{B}^s(\\Omega)}.\n \\end{equation}\n Now, by the definition of $S_n$, we have for every $\\nu\\in S_n$\n \\begin{equation}\n  \\left(\\sup_{\\xi\\in S_n^c} |c_\\xi|(1+|\\xi|)^{2m-s}\\right) \\leq |c_\\nu|(1+|\\nu|)^{2m-s},\n \\end{equation}\n so that\n \\begin{equation}\n  \\left(\\sup_{\\xi\\in S_n^c} |c_\\xi|(1+|\\xi|)^{2m-s}\\right)\\sum_{\\nu\\in S_n}(1+|\\nu|)^{2(s-m)} \\leq \\sum_{\\nu\\in S_n} |c_\\nu|(1+|\\nu|)^{2m-s}(1+|\\nu|)^{2(s-m)}.\n \\end{equation}\n By \\eqref{eq_642}, we thus have\n \\begin{equation}\n  \\left(\\sup_{\\xi\\in S_n^c} |c_\\xi|(1+|\\xi|)^{2m-s}\\right) \\lesssim \\|f\\|_{\\mathcal{B}^s(\\Omega)}\\left(\\sum_{\\nu\\in S_n}(1+|\\nu|)^{2(s-m)}\\right)^{-1}.\n \\end{equation}\n The sum $\\sum_{\\nu\\in S_n}(1+|\\nu|)^{2(s-m)}$ is over $n$ elements of the lattice $L^{-1}\\mathbb{Z}^d$, from which it easily follows by comparison with an integral (see, for instance, \\cite{erdos1989lattice}) that\n \\begin{equation}\n  \\sum_{\\nu\\in S_n}(1+|\\nu|)^{2(s-m)} \\gtrsim n^{1+\\frac{2(s-m)}{d}},\n \\end{equation}\n and we obtain\n \\begin{equation}\n  \\left(\\sup_{\\xi\\in S_n^c} |c_\\xi|(1+|\\xi|)^{2m-s}\\right) \\lesssim \\|f\\|_{\\mathcal{B}^s(\\Omega)}n^{-1-\\frac{2(s-m)}{d}}.\n \\end{equation}\n Combining this with \\eqref{eq_634} and \\eqref{eq_638}, we get\n \\begin{equation}\n  \\|f - f_n\\|^2_{H^m(\\Omega^\\prime)} \\lesssim \\|f\\|^2_{\\mathcal{B}^s(\\Omega)}n^{-1-\\frac{2(s-m)}{d}}.\n \\end{equation}\n Finally, since $\\Omega^\\prime \\supset \\Omega$, we get\n \\begin{equation}\n  \\|f - f_n\\|_{H^m(\\Omega)} \\leq \\|f - f_n\\|_{H^m(\\Omega^\\prime)} \\lesssim \\|f\\|_{\\mathcal{B}^s(\\Omega)}n^{-\\frac{1}{2}-\\frac{(s-m)}{d}},\n \\end{equation}\n which completes the proof.\n\\end{proof}\n\nIn Theorem \\ref{approximation-rate-theorem}, we obtained arbitrarily high polynomial rates of convergence for sufficiently smooth functions. Next we generalize this by showing that if the Fourier transform decays at a superpolynomial rate, then we can obtain spectral (i.e. superpolynomial) convergence as well. We begin by introducing an exponential version of the spectral Barron spaces.\n\\begin{definition}\nLet $\\Omega\\subset \\mathbb{R}^d$ be a bounded domain and let $0 < \\beta < 1$ and $c > 0$. The exponential spectral Barron space with parameters $\\beta$ and $c$ is defined by\n\\begin{equation}\n \\mathcal{B}_{\\beta,c}(\\Omega):=\\left\\{f:\\Omega\\rightarrow\\mathbb{R}:\\|f\\|_{\\mathcal{B}_{\\beta,c}(\\Omega)}:=\\inf_{f_e|\\Omega = f}\\int_{\\mathbb{R}^d}e^{c|\\xi|^\\beta}|\\hat{f}_e(\\xi)|d\\xi < \\infty\\right\\},\n\\end{equation}\nwhere the infemum is taken over all extension $f_e\\in L^1(\\mathbb{R}^d)$.\n\\end{definition}\n The space $\\mathcal{B}_{\\beta,c}(\\Omega)$ is quite restrictive, however there it still contains a relatively large class of functions. For example, it contains satisfied by any linear combination of Gaussians or any band-limited function, i.e. any function whose Fourier transform is compactly supported.\n\nFor elements of $\\mathcal{B}_{\\beta,c}(\\Omega)$, we can prove a superpolynomial convergence rate.\n\\begin{theorem}\\label{spectral-convergence-theorem}\n Let $\\Omega = [0,1]^d$, $0 < \\beta < 1$, and $c > 0$.\n Then for any $m \\geq 0$, there exists a $c^\\prime > 0$ such that for $f\\in \\mathcal{B}_{\\beta,c}(\\Omega)$ and $M\\lesssim \\|f\\|_{\\mathcal{B}_{\\beta,c}(\\Omega)}$ we have\n  \\begin{equation}\n  \\inf_{f_n\\in \\Sigma_{n,M}} \\|f-f_n\\|_{H^m(\\Omega)} \\lesssim \\|f\\|_{\\mathcal{B}_{\\beta,c}(\\Omega)}e^{-c^\\prime n^{d^{-1}\\beta}}.\n \\end{equation}\n\\end{theorem}\nNote that in this theorem the implied constant and the constant $c^\\prime$ only depend upon $\\beta,c,d$ and $m$, but not on $f$ or $n$.\n\\begin{proof}\n We use a similar argument to the proof of Theorem \\ref{approximation-rate-theorem}. First, we apply Lemma \\ref{fourier-representation-lemma-general} to the weight $\\mu(\\xi) = e^{c|\\xi|^{\\beta}}$, to obtain an $a\\in L^{-1}[0,1]^d$ and coefficients $c_\\xi$ such that\n  \\begin{equation}\n  f(x) = \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d}c_\\xi e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a+\\xi)\\cdot x}\n \\end{equation}\n and\n \\begin{equation}\\label{eq_361}\n  \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d}  e^{c|a+\\xi|^{\\beta}}|c_\\xi| \\lesssim \\|f\\|_{\\mathcal{B}_{\\beta,c}(\\Omega)}.\n \\end{equation}\n As in the proof of Theorem \\ref{approximation-rate-theorem}, we note that the frequencies $e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a+\\xi)\\cdot x}$ are orthogonal on the enlarger set $\\Omega^\\prime = [0,L]^d$ and their norms are bounded by \\eqref{length-estimate}.\n \n This time, we order the frequencies $\\xi\\in L^{-1}\\mathbb{Z}^d$ such that\n \\begin{equation}\n  (1+|\\xi_1|)^{2k}e^{-c|a+\\xi_1|^{\\beta}}|c_{\\xi_1}| \\geq  (1+|\\xi_2|)^{2k}e^{-c|a+\\xi_2|^{\\beta}}|c_{\\xi_2}| \\geq  (1+|\\xi_3|)^{2k}e^{-c|a+\\xi_3|^{\\beta}}|c_{\\xi_3}| \\geq \\cdots. \n \\end{equation}\n Choosing $S_n = \\{\\xi_1,...,\\xi_n\\}$ and setting\n \\begin{equation}\n  f_n(x) = \\sum_{\\xi\\in S_n}c_\\xi e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a+\\xi)\\cdot x} \\in \\Sigma_{n,M},\n \\end{equation}\n with $M\\lesssim \\|f\\|_{\\mathcal{B}_{\\beta,c}(\\Omega)}$, we obtain, using the argument between equations \\eqref{eq_634} and \\eqref{eq_638}, that\n \\begin{equation}\\label{eq_375}\n   \\|f - f_n\\|^2_{H^m(\\Omega^\\prime)} \\leq \\left(\\sup_{\\xi\\in S_n^c} |c_\\xi|(1+|\\xi|)^{2m}e^{-c|a+\\xi|^{\\beta}} \\right)\\left(\\sum_{\\xi\\in S_n^c}|c_\\xi|e^{c|a+\\xi|^{\\beta}}\\right).\n \\end{equation}\n By \\eqref{eq_361}, the second factor is $\\lesssim \\|f\\|_{\\mathcal{B}_{\\beta,c}(\\Omega)}$.\n \n For the first factor, the argument between equations \\eqref{eq_613} and \\eqref{eq_642} implies that\n \\begin{equation}\\label{eq_381}\n  \\left(\\sup_{\\xi\\in S_n^c} |c_\\xi|(1+|\\xi|)^{2m}e^{-c|a+\\xi|^{\\beta}} \\right) \\lesssim C_f\\left(\\sum_{\\nu\\in S_n} e^{2c|a+\\nu|^{\\beta}}(1 + |a + \\nu|)^{-2m}\\right)^{-1}.\n \\end{equation}\n We now proceed to lower bound the sum on the right by considering its largest term. Since the sum is over $n$ elements of the lattice $a + L^{-1}\\mathbb{Z}^d$, the longest vector, i.e. the largest length $|a+\\xi|$ which occurs in the sum, must be $\\gtrsim n^{\\frac{1}{d}}$. In addition $(1 + |a + \\xi|)^{2m} \\lesssim e^{2\\epsilon|a+\\xi|^{\\beta}}$ for any $\\epsilon > 0$, so we see that there must exist a $c^\\prime > 0$ such that\n \\begin{equation}\n  \\left(\\sum_{\\nu\\in S_n} e^{2c|a+\\nu|^{\\beta}}(1 + |a + \\nu|)^{-2m}\\right) \\gtrsim e^{2c^\\prime n^{\\frac{\\beta}{d}}}.\n \\end{equation}\n Plugging this into \\eqref{eq_381} and \\eqref{eq_375} and using the fact that $\\Omega^\\prime \\subset \\Omega$, we get\n \\begin{equation}\n  \\inf_{f_n\\in \\Sigma_{n,M}} \\|f-f_n\\|_{H^m(\\Omega)} \\lesssim \\|f\\|_{\\mathcal{B}_{\\beta,c}(\\Omega)}e^{-c^\\prime n^{\\frac{\\beta}{d}}},\n \\end{equation}\n as desired.\n\n\\end{proof}\n", "meta": {"hexsha": "b925f068d18aab09df9904a34af2d6ff5468ce12", "size": 19919, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/CosineApprox.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/CosineApprox.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/CosineApprox.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 70.1373239437, "max_line_length": 1073, "alphanum_fraction": 0.6600230935, "num_tokens": 7599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587668, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7155275480639006}}
{"text": "\\subsection{1D Heat Rod}\\label{ex:heat-set-sample}\n\nWe demonstrate that the same principles illustrated in Example\\ref{ex:decay-set-sample} apply to another nonlinear problem.\nThe set-- and sample--based methods are functionally equivalent solution methods which leverage the same foundational measure--theoretic principles.\nHere, the quantification of uncertainty is for the thermal conductivity properties of a material based on temperature data collected after heating it in an experiment.\nConsider the one-dimensional heat equation with homogeneous Neumann boundary conditions on the unit interval:\n\n\\begin{equation}\n\\begin{split}\n\\rho c \\frac{\\partial T}{\\partial t} = \\nabla \\cdot ( \\kappa \\nabla T) + f(x), \\quad & x\\in (0,1), t\\in (0,1) \\\\\nf(x) = A e^\\frac{- (x-0.5)^2}{w} \\Chi_{[0,0.5]}(t)\n\\end{split}\n\\end{equation}\n\\emph{Alternative setup: }\n\n\\begin{equation}\n\\begin{cases}\n\\rho c \\frac{\\partial T}{\\partial t} = \\nabla \\cdot ( \\kappa \\nabla T) + f(x,t), & \\text{if } x\\in \\Omega \\\\\n\\frac{\\partial T}{\\partial \\vec{n}} = 0 & \\text{if } x\\in \\partial \\Omega\n\\end{cases}\n\\end{equation}\nwhere $\\Omega = (0,1)\\times (0,1)$ is the space-time interior and $f(x,t) = A e^\\frac{- (x-0.5)^2}{w} \\Chi_{[0,0.5]}(t)$.\n\nHere, we interpret the following problem as heating the middle of an infinitesimally thin unit-length rod for half a second with a heat-source modeled by a Gaussian curve with amplitude $A=50$ and variance of $w=0.05$.\nThis heat source is turned on at the beginning of the experiment and turned off halfway through the 1-second duration.\n\nThe rod is subdivided in two, and each half has an uncertain thermal diffusivity $\\kappa \\in [0.01, 0.2]$.\nThis yields a two-dimensional parameter space $\\param = (\\param_1, \\param_2) \\in [0.01, 0.2]^2$, where $\\param_1$ represents the thermal diffusion on the left-half and $\\param_2$ is the $\\kappa$ for the right half.\n\nTwo measurement locations along the rod are used for taking a measurement\nWe assume a uniform density for each observation with a side--length of $0.1$ and attempt to identify a set which contains our true reference value of $\\paramref = (0.15, 0.05)$.\nIn Figure~\\ref{fig:heatrod-sol-ex} we show the solution to this SIP for the set-- and sample--based methods for $N=50$ parameter samples used to explore $\\pspace$.\n\n\\begin{figure}[h]\n\\begin{minipage}{.475\\textwidth}\n\\includegraphics[width=\\linewidth]{examples/fig_heatrod_q1/HeatrodModel--set_N50_em.png}\n\\end{minipage}\n\\begin{minipage}{.475\\textwidth}\n\\includegraphics[width=\\linewidth]{examples/fig_heatrod_q1/HeatrodModel--sample_N50_mc.png}\n\\end{minipage}\n\\caption{The inverse image of the reference measure for set-based (left) and sample-based (right) solutions for $\\nsamps=50$ parameter samples.}\n\\label{fig:heatrod-sol-ex}\n\\end{figure}\n\nThe experimental results in \\ref{fig:heatrod-sol-ex} both show images which identify $\\paramref$ as a feasible solution.\nBoth solutions again agree on the support of the inverse image.\nWe will look a the impacts of the sample size $\\nsamps$ in the next chapter and study convergence towards a high-fidelity solution for different choices of measurement locations and values of $\\paramref$.\n\n[ TK - I don't know, there's not a whole lot to say. At this point I'm just establishing that both these methods are more or less equivalent despite having quite different algorithmic approaches.]\n", "meta": {"hexsha": "7f75b3b55109d80d705a779e680b7dedbff8aed9", "size": 3367, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch02/heat_1drod_set_vs_sample.tex", "max_stars_repo_name": "mathematicalmichael/thesis", "max_stars_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-24T08:05:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-28T20:34:29.000Z", "max_issues_repo_path": "ch02/heat_1drod_set_vs_sample.tex", "max_issues_repo_name": "mathematicalmichael/thesis", "max_issues_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 59, "max_issues_repo_issues_event_min_datetime": "2019-12-27T23:15:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T17:52:57.000Z", "max_forks_repo_path": "ch02/heat_1drod_set_vs_sample.tex", "max_forks_repo_name": "mathematicalmichael/thesis", "max_forks_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.34, "max_line_length": 218, "alphanum_fraction": 0.7511137511, "num_tokens": 933, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256591565729, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7155275468116613}}
{"text": "\\subsection{Prime ideals}\\label{subsec:prime_ideals}\n\n\\begin{definition}\\label{def:prime_ring_ideal}\\mcite[384]{Knapp2016BasicAlgebra}\n  An ideal \\( P \\) is called \\term{prime} if it is proper and satisfies any of the equivalent conditions:\n  \\begin{thmenum}\n    \\thmitem{def:prime_ring_ideal/direct} If \\( x, y \\in R \\) are such that \\( xy \\in P \\), then either \\( x \\in P \\) or \\( y \\in P \\).\n    \\thmitem{def:prime_ring_ideal/ideals} If \\( I, J \\subseteq R \\) are ideals such that \\( IJ \\subseteq P \\), then either \\( I \\subseteq P \\) or \\( J \\subseteq P \\).\n    \\thmitem{def:prime_ring_ideal/quotient} The quotient \\( R / P \\) is an integral domain.\n  \\end{thmenum}\n\n  An element \\( r \\in R \\) is called \\term{prime} if the ideal \\( \\braket r \\) is prime.\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:prime_ring_ideal/direct}{def:prime_ring_ideal/ideals} Fix ideals \\( I, J \\) of \\( R \\) such that \\( IJ \\subseteq P \\).\n\n  Assume that neither \\( I \\not\\subseteq P \\) nor \\( J \\not\\subseteq P \\). Take \\( x \\in I \\setminus P \\) and \\( y \\in J \\setminus P \\). It follows that \\( xy \\in P \\) and either \\( x \\in P \\) or \\( y \\in P \\). This contradicts our assumption.\n\n  The obtained contradiction proves that either \\( I \\subseteq P \\) or \\( J \\subseteq P \\).\n\n  \\ImplicationSubProof{def:prime_ring_ideal/ideals}{def:prime_ring_ideal/quotient} Fix an ideal \\( P \\) such that if \\( I, J \\subseteq R \\) are ideals and \\( IJ \\subseteq P \\), then either \\( I \\subseteq P \\) or \\( J \\subseteq P \\).\n\n  We will prove that \\( R / P \\) is an integral domain. If \\( R \\) is an integral domain, this is obvious. If not, we fix nonzero \\( x, y \\in R \\), so that \\( xy = 0 \\). Thus, \\( [x][y] = (x + P)(y + P) = xy + P = P = [0] \\). We will show that either \\( x = 0 \\) or \\( y = 0 \\).\n\n  Consider the ideals\n  \\begin{balign*}\n    \\braket{x} & = xR, \\\\\n    \\braket{y} & = yR.\n  \\end{balign*}\n\n  By \\fullref{thm:product_of_principal_ideals}, we have \\( \\braket{x} \\braket{y} = \\braket{xy} = \\braket{0} = \\{ 0 \\} \\).\n\n  Since \\( \\braket{x} \\braket{y} \\subseteq P \\), then either \\( \\braket{x} \\subseteq P \\) or \\( \\braket{y} \\subseteq P \\). That is, either \\( [x] = 0 \\) or \\( [y] = 0 \\).\n\n  Thus, \\( R / P \\) is an integral domain.\n\n  \\ImplicationSubProof{def:prime_ring_ideal/quotient}{def:prime_ring_ideal/direct} Suppose that \\( R / P \\) is an integral domain. Fix \\( x, y \\in R \\), so that \\( xy \\in P \\). If \\( x = 0 \\), obviously \\( x = 0 \\in R \\) and similarly for \\( y \\). Suppose that both \\( x \\) and \\( y \\) are nonzero. We will show that either \\( x \\in P \\) or \\( y \\in P \\).\n\n  We have\n  \\begin{equation*}\n    [x][y] = [xy] = xy + P = P = [0].\n  \\end{equation*}\n\n  Since \\( R / P \\) is an integral domain, either \\( [x] = [0] \\) or \\( [y] = [0] \\). That is, either \\( x \\in P \\) or \\( y \\in P \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:prime_ideal_iff_prime_quotient_ideal}\n  If \\( J \\subseteq I \\) are ideals of \\( R \\), then \\( I \\) is a \\hyperref[def:prime_ring_ideal]{prime ideal} in \\( R \\) if and only if \\( I / J \\) is a prime ideal in  \\( R / J \\).\n\\end{proposition}\n\n\\begin{definition}\\label{def:irreducible_ring_element}\n  A nonzero element \\( r \\in R \\) of an integral domain is called \\term{reducible} if there exist non-invertible elements \\( r_1, r_2 \\in R \\) such that\n  \\begin{equation*}\n    r = r_1 r_2.\n  \\end{equation*}\n\n  If \\( r \\) is not reducible, we say that it is \\term{irreducible}.\n\\end{definition}\n\n\\begin{definition}\\label{def:coprime_ring_ideals}\n  Two ring ideals \\( I \\subseteq R \\) and \\( J \\subseteq R \\) are said to be \\term{coprime} if \\( I + J = R \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:prime_implies_irreducible}\\mcite[389]{Knapp2016BasicAlgebra}\n  All \\hyperref[def:prime_ring_ideal]{prime} elements in an integral domain are \\hyperref[def:irreducible_ring_element]{irreducible}.\n\\end{proposition}\n\\begin{proof}\n  Let \\( p \\) be prime. Assume that \\( p \\) is reducible, that is, there exist non-invertible elements \\( r_1, r_2 \\in R \\) such that\n  \\begin{equation*}\n    p = r_1 r_2.\n  \\end{equation*}\n\n  Since \\( p \\) is prime, it must divide either \\( r_1 \\) or \\( r_2 \\). Without loss of generality, assume that \\( p | r_1 \\) and \\( r_1 = pc \\) for some \\( c \\in R \\).\n\n  Then \\( p = r_1 r_2 = pc r_2 \\). By \\fullref{thm:def:semiring/properties/cancellable_iff_not_zero_divisor}, \\( 1 = c r_2 \\), which implies that \\( r_2 \\) is invertible with inverse \\( c \\). This contradicts our assumption that both \\( r_1 \\) and \\( r_2 \\) are invertible.\n\n  The obtained contradiction proves that \\( p \\) is irreducible.\n\\end{proof}\n\n\\begin{definition}\\label{def:maximal_ring_ideal}\n  A two-sided ideal \\( M \\) is called \\term{maximal} if it is proper and satisfies any of the equivalent conditions:\n  \\begin{thmenum}\n    \\thmitem{def:maximal_ring_ideal/maximality} \\( M \\) is maximal with respect to set inclusion among proper two-sided ideals.\n    \\thmitem{def:maximal_ring_ideal/quotient} The quotient \\( R / M \\) is a field.\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:maximal_ring_ideal/maximality}{def:maximal_ring_ideal/quotient} Suppose that \\( M \\) is maximal among proper ideals. We will prove that every nonzero element of \\( R / M \\) is invertible.\n\n  Fix \\( x \\not\\in M \\), so that \\( [x] = x + M \\neq M = [0] \\). Define the set\n  \\begin{equation*}\n    I \\coloneqq Rx + M.\n  \\end{equation*}\n\n  It is a ideal since both \\( Rx \\) and \\( M \\) are ideals. Furthermore, it contains \\( M \\) strictly because \\( M \\subseteq I \\) and \\( x \\in I \\). Since \\( M \\) is maximal, we have that \\( I = R \\).\n\n  Hence, there exists \\( y \\in R \\) such that \\( 1 = yx + M \\). Hence, \\( [y] = y + M \\) is an inverse of \\( [x] \\) in \\( R / M \\).\n\n  Since \\( [x] \\in R / M \\) was an arbitrary nonzero element, we conclude that \\( R / M \\) is a field.\n\n  \\ImplicationSubProof{def:maximal_ring_ideal/quotient}{def:maximal_ring_ideal/maximality} Suppose that \\( R / M \\) is a field. Assume that \\( M \\) is not maximal. Then there exists a proper ideal \\( I \\supsetneq M \\).\n\n  Assume that \\( I \\neq M \\) and take \\( x \\in I \\setminus M \\). Then \\( x \\not\\in M \\) and hence \\( [x] \\neq [0] \\) and is invertible in \\( R / M \\). Denote by \\( y \\) any representative of this inverse. Thus, \\( [xy] - [1] = [0] \\), that is, \\( xy - 1 \\in M \\).\n\n  Note that \\( xy \\in I \\) because \\( x \\in I \\) and \\( y \\in R \\). Since \\( I \\) is closed under addition, it follows that \\( 1 \\in I \\) and hence \\( I = R \\). But this contradicts our assumption that \\( I \\) is proper.\n\n  The obtained contradiction proves that \\( M \\) is maximal.\n\\end{proof}\n\n\\begin{theorem}[Krull's theorem]\\label{thm:krulls_theorem}\\mcite{Hodges1979}\n  Every nontrivial \\hyperref[def:semiring/commutative_unital_ring]{commutative unital ring} has a \\hyperref[def:maximal_ring_ideal]{maximal ideal}.\n\n  In \\hyperref[def:zfc]{\\logic{ZF}} this theorem is equivalent to the \\hyperref[def:zfc/choice]{axiom of choice} --- see \\fullref{thm:axiom_of_choice_equivalences/krull}.\n\\end{theorem}\n\n\\begin{proposition}\\label{thm:maximal_ideals_are_prime}\n  Maximal ring \\hyperref[def:maximal_ring_ideal]{ideals} are \\hyperref[def:prime_ring_ideal]{prime}.\n\\end{proposition}\n\\begin{proof}\n  If \\( M \\) is a maximal ideal of \\( R \\), by \\fullref{def:maximal_ring_ideal/quotient} \\( R / M \\) is a field. Thus, \\( R / M \\) is an integral domain, which by \\fullref{def:prime_ring_ideal/quotient} means that \\( M \\) is a prime ideal.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:field_maximal_ideal_representation}\\mcite[exer. 8.1]{КоцевСидеров2016}\n  If \\( r_1, \\ldots, r_n \\) are elements of the field \\( \\BbbK \\), then \\( \\braket{X_1 - r_1, \\ldots, X_n - r_n} \\) is a maximal ideal of \\( \\BbbK[X_1, \\ldots, X_n] \\).\n\\end{proposition}\n\n\\begin{proposition}\\label{thm:ufd_prime_iff_irreducible}\n  An element in a unique factorization domain is \\hyperref[def:prime_ring_ideal]{prime} if and only if it is \\hyperref[def:irreducible_ring_element]{irreducible}.\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Follows from \\fullref{thm:prime_implies_irreducible}.\n\n  \\NecessitySubProof Let \\( r \\) be an irreducible element and let \\( p_1 p_2 \\in \\braket{r} \\). We will show that either  \\( p_1 \\in \\braket{r} \\) or \\( p_2 \\in \\braket{r} \\).\n\n  Since \\( \\braket{r} \\) is an ideal, there exists an element \\( q \\in R \\) such that \\( qr = p_1 p_2 \\). Because of unique factorization, there exists a unit \\( u \\in R \\) such that \\( uqr = p_1 p_2  \\).\n\n  Therefor either\n  \\begin{itemize}\n    \\item \\( p_1 = 1 \\), in which case \\( p_2 = uqr \\in \\braket{r} \\).\n    \\item \\( p_1 = u \\), in which case \\( p_2 = qr \\in \\braket{r} \\).\n    \\item \\( p_1 = uq \\), in which case \\( p_2 = r \\in \\braket{r} \\).\n    \\item \\( p_1 = ur \\in \\braket{r} \\).\n    \\item \\( p_1 = qr \\in \\braket{r} \\).\n    \\item \\( p_1 = uqr \\in \\braket{r} \\).\n  \\end{itemize}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:prime_ideals_are_maximal_in_pid}\n  Prime ring \\hyperref[def:prime_ring_ideal]{ideals} in a principal ideal domain are \\hyperref[def:maximal_ring_ideal]{maximal}.\n\\end{proposition}\n\\begin{proof}\n  Let \\( P \\) be a prime ideal of \\( R \\) and let \\( I \\supsetneq P \\) be an ideal strictly containing \\( P \\). We will show that \\( I = R \\).\n\n  Since \\( R \\) is a principal ideal domain, both \\( P \\) and \\( I \\) are principal. Let \\( p \\) and \\( i \\) be their respective generators. Since \\( I \\) contains \\( P \\), there exists \\( r \\in R \\) such that\n  \\begin{equation*}\n    p = ir.\n  \\end{equation*}\n\n  But \\( p \\) is prime, and thus irreducible by \\fullref{thm:ufd_prime_iff_irreducible}, and hence either \\( i \\) or \\( r \\) must be a unit. If \\( r \\) is a unit, then \\( \\braket i = \\braket {ir} = \\braket p \\), which contradicts our choice of \\( I \\supsetneq P \\). It remains for \\( i \\) to be a unit.\n\n  Therefore, \\( I = \\braket i = \\braket 1 = R \\). This proves that \\( P \\) is maximal with respect to inclusion of ideals.\n\\end{proof}\n\n\\begin{definition}\\label{def:krull_dimension}\\mcite[67]{КоцевСидеров2016}\n  Consider chains\n  \\begin{equation*}\n    P_0 \\subsetneq P_1 \\subsetneq \\cdots\n  \\end{equation*}\n  of prime \\hyperref[def:prime_ring_ideal]{ideals} in \\( R \\) under strict inclusion. The length of this chain is defined as the zero-based index of its last element and is allowed to be infinite. Zero-based means that a chain with only one ideal has length zero.\n\n  We call the supremum of the lengths of these chains the \\term{Krull dimension} of the ring \\( R \\) and denote it by \\( \\dim R \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:krull_dimension/properties}\n  The Krull \\hyperref[def:krull_dimension]{dimension} of a ring \\( R \\) has the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:krull_dimension/properties/monotone} If \\( R = T / S \\) is the quotient of some rings \\( S \\subseteq T \\), \\( \\dim R \\leq \\dim T \\).\n    \\thmitem{thm:def:krull_dimension/properties/pid} If \\( R \\) is a principal ideal domain, \\( \\dim R \\in \\{ 0, 1 \\} \\).\n    \\thmitem{thm:def:krull_dimension/properties/field} If \\( R \\) is a \\hyperref[def:field]{field}, \\( \\dim R = 0 \\).\n    \\thmitem{thm:def:krull_dimension/properties/polynomials_over_field}\\cite[exercise 8.19]{КоцевСидеров2016} If \\( R = \\BbbK[X_1, \\ldots, X_n] \\) for some \\hyperref[def:field]{field} \\( \\BbbK \\), \\( \\dim R = n \\).\n  \\end{thmenum}\n\\end{proposition}\n\n\\begin{corollary}\\label{thm:multivariate_polynomial_rings_are_not_pid}\n  Multivariate polynomial rings are not principal ideal domains.\n\\end{corollary}\n\\begin{proof}\n  Follows from \\fullref{thm:def:krull_dimension/properties/pid} and \\fullref{thm:def:krull_dimension/properties/polynomials_over_field}.\n\\end{proof}\n\n\\begin{definition}\\label{def:radical_ideal}\\mcite[15]{КоцевСидеров2016}\n  We define the \\term{radical ideal} of the ideal \\( I \\) of \\( R \\) as\n  \\begin{equation*}\n    \\sqrt I \\coloneqq \\{ x \\in R \\colon \\exists n: x^n \\in I \\}.\n  \\end{equation*}\n\\end{definition}\n\\begin{proof}\n  We verify that the set \\( \\sqrt I \\) is an ideal of \\( R \\).\n\n  It is closed under addition because if \\( x^n \\in I \\) and \\( y^m \\in I \\), then by \\fullref{thm:binomial_theorem},\n  \\begin{equation*}\n    (x + y)^{n+m}\n    =\n    \\sum_{k=0}^{n+m} \\binom n k x^k y^{n+m-k}\n  \\end{equation*}\n\n  In this sum, either \\( k \\geq n \\) and thus the product \\( x^k y^{n+m-k} \\in I \\), or \\( k < n \\), in which case \\( n + m - k > n + m - n = m \\) and the same holds. Thus,\n  \\begin{equation*}\n    (x + y)^{n+m} \\in I\n  \\end{equation*}\n  and \\( x + y \\in \\sqrt I \\).\n\n  The radical is also closed under multiplication with \\( R \\) since if \\( x^n \\in I \\), then \\( (rx)^n = r^n x^n \\in I \\).\n\n  Therefore, it is an ideal of \\( R \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:primary_ring_ideal}\\mcite[74]{КоцевСидеров2016}\n  We call the proper ideal \\( P \\) of \\( R \\) \\term{primary} if \\( xy \\in P \\) implies that \\( x \\in P \\) or \\( y \\in \\sqrt P \\).\n\\end{definition}\n\n\\begin{theorem}[Chinese remainder theorem]\\label{thm:chinese_remained_theorem}\\mcite[thm. 8.27]{Knapp2016BasicAlgebra}\n  Let \\( I_1, \\ldots, I_n \\) be pairwise \\hyperref[def:coprime_ring_ideals]{coprime} ideals. Then\n  \\begin{equation*}\n    R / \\bigcap_{i=1}^n I_n \\cong R / I_1 \\times \\cdots \\times R / I_n.\n  \\end{equation*}\n\\end{theorem}\n\n\\begin{definition}\\label{def:spectrum_of_ring}\n  The set of all prime ideals on a ring \\( R \\) is called the \\term{spectrum} of \\( R \\) denoted by \\( \\op{Spec}(R) \\).\n\\end{definition}\n", "meta": {"hexsha": "253523199db89120cc2b42e3094b4de9b1c3af40", "size": 13443, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/prime_ideals.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/prime_ideals.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/prime_ideals.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.1948051948, "max_line_length": 355, "alphanum_fraction": 0.6527560812, "num_tokens": 4615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256512199032, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7155275432649927}}
{"text": "\n\\subsubsection*{Examples of Embedded Submanifolds }\n\n\\begin{lemma}[8.6] (\\textbf{Graphs as Submanifolds}). \nIf open $U \\subset \\mathbb{R}^n$, smooth $F: U \\to \\mathbb{R}^k$, \\\\\nthen graph of $F$ is an embedded $n$-dim. submanifold of $\\mathbb{R}^{n+k}$\n\\end{lemma}\n\n\\begin{proof}\n  Define $\\begin{aligned} \n    & \\quad \\\\\n    & \\varphi: U \\times \\mathbb{R}^k \\to U \\times \\mathbb{R}^k \\\\ \n    & \\varphi(x,y) = (x,y - F(x)) \\end{aligned}$\n\n$\\varphi$ clearly smooth. \\\\\n$\\varphi$ diffeomorphism because its inverse can be written explicitly\n\\[\n\\varphi^{-1}(u,v) = (u ,  v + F(u))\n\\]\n\n$\\varphi( \\Gamma(F))$ is the slice $\\lbrace (u,v) : v = 0 \\rbrace $ of $U\\times \\mathbb{R}^k$, so graph $\\Gamma(F)$ is an embedded submanifold.  \n\n\n\n\\end{proof}\n\n\n\n\\subsubsection*{Level Sets}\n\n\n\\subsection*{Immersed Submanifolds}\n\n\\begin{definition}\n  \\textbf{immersed submanifold } of $M$, $S$, is $S\\subseteq M$, with topology (not necessarily subspace topology) with respect to which it's a topological manifold (without boundary), and \\\\\n\\phantom{ \\quad \\quad \\, }   smooth structure with respect to inclusion map $i : S \\hookrightarrow M$ is smooth immersion (recall $Di \\equiv i_*$ injective $\\Longleftrightarrow \\text{rank}Di = \\text{dim}S$ \\\\\n\n$\\text{codim}S = \\text{dim}M - \\text{dim}S$ \\\\\n\n\\textbf{smooth hypersurface} is immersed submanifold of codimension $1$.  \n\\end{definition}\n\n", "meta": {"hexsha": "90834dc9f4cc62ebac5df5093606c2e03992bf2a", "size": 1376, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LeeJM/05submanifolds.tex", "max_stars_repo_name": "wacfeldwang333/mathphysics", "max_stars_repo_head_hexsha": "59eb794dfa46e2b80e43df0440bb8ec3c472d973", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2017-01-10T14:24:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T11:19:23.000Z", "max_issues_repo_path": "LeeJM/05submanifolds.tex", "max_issues_repo_name": "wacfeldwang333/mathphysics", "max_issues_repo_head_hexsha": "59eb794dfa46e2b80e43df0440bb8ec3c472d973", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-09-29T09:29:53.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-12T03:12:29.000Z", "max_forks_repo_path": "LeeJM/05submanifolds.tex", "max_forks_repo_name": "wacfeldwang333/mathphysics", "max_forks_repo_head_hexsha": "59eb794dfa46e2b80e43df0440bb8ec3c472d973", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 25, "max_forks_repo_forks_event_min_datetime": "2018-01-21T05:33:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T20:15:13.000Z", "avg_line_length": 32.0, "max_line_length": 208, "alphanum_fraction": 0.6635174419, "num_tokens": 467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7155275253216}}
{"text": "\\section{Limits}\nLimits are the foundation of calculus.\nA lot of other things commonly used in calculus are made with the help of limits.\nFor example the derivative of \\(x^2\\) is \\(2x\\).\nThis can be proven by using limits.\nA limit of a function is the value of the function when it approaches a value.\n\n\\subsection{Limit law}\n\nGiven two limits \\(\\lim_{x \\to a} f(x)\\) and \\(\\lim_{x \\to a} g(x)\\) we can say that:\n\n\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular} {c}\n    \\(\\lim_{x \\to a} [f(x) + g(x)] = \\lim_{x \\to a} f(x) + \\lim_{x \\to a} g(x)\\) \\\\\\hline\n    \\(\\lim_{x \\to a} [f(x) - g(x)] = \\lim_{x \\to a} f(x) - \\lim_{x \\to a} g(x)\\) \\\\\\hline\n    \\(\\lim_{x \\to a} [c f(x)] = c \\lim_{x \\to a} f(x)\\) \\\\\\hline\n    \\(\\lim_{x \\to a} [f(x)g(x)] = \\lim_{x \\to a} f(x) * \\lim_{x \\to a} g(x)\\) \\\\\\hline\n    \\(\\lim_{x \\to a} \\frac{f(x)}{g(x)} = \\frac{\\lim_{x \\to a} f(x)}{\\lim_{x \\to a} g(x)} \\text{if} \\lim_{x \\to a} g(x) \\neq 0\\) \\\\\n\t\\end{tabular}\n\t\\caption{Limit laws}\n\\end{table}\n\n\\subsection{Finding a limit}\n\\begin{figure}[H]\n  \\begin{center}\n    \\begin{tikzpicture}\n      \\begin{axis}[\n          axis x line=center,\n          axis y line=center,\n          xtick={-5,-3,...,5},\n          ytick={0,0.5,...,2},\n          xlabel=$x$,\n          ylabel=$y$,\n          xmin=-5,\n          xmax=5,\n          ymin=0,\n          ymax=2,\n          samples=5\n        ]\n        \\addplot [color=blue] {(x-1)/(x-1)};\n        \\legend{\\((x-1)/(x-1)\\)}\n      \\end{axis}\n    \\end{tikzpicture}\n  \\end{center}\n\\end{figure}\n\nThe simplest way of approximating the limit,\nis to evaluate the function with an \\(x\\) close to the limit you want.\nTake for example the function graphed above.\n\\(f(1)\\) is obviously not defined, you cannot solve it that way.\nBut you can approximate it by filling \\(1.00000001\\) into the function.\nThis gives \\(1\\), which is the limit.\n\n\\subsection{Doing it properly}\nThis does not always work, so it's better to rewrite the function.\nFor example:\n\n\\[\n  f(x) =\n  \\frac{x-1}{x-1} =\n  \\frac{1}{1} =\n  1\n\\]\nObviously this is a simple function, other functions will not be this simple.\nFor example, solving the following function will look like this:\n\n\\begin{dmath}\n  \\lim_{x \\to 0} \\frac{\\sqrt{x^2 + 9} - 3}{x^2} =\n  \\lim_{x \\to 0} \\frac{\\sqrt{x^2 + 9} - 3}{x^2} * \\frac{\\sqrt{x^2 + 9} + 3}{\\sqrt{x^2 + 9} + 3} =\n  \\lim_{x \\to 0} \\frac{(x^2 + 9) - 9}{x^2(\\sqrt{x^2 + 9} + 3)} =\n  \\lim_{x \\to 0} \\frac{1}{\\sqrt{x^2 + 9} + 3} =\n  \\frac{1}{\\sqrt{0^2 + 9} + 3} =\n  \\frac{1}{6}\n\\end{dmath}\n\n\\subsection{Continuity}\nA function is {\\bf continuous} iff\n\n\\begin{itemize}\n  \\item \\(f(a)\\) is defined\n  \\item \\(\\lim_{x \\to a} f(x)\\) exits\n  \\item \\(\\lim_{x \\to a} f(x) = f(a)\\)\n\\end{itemize}\n\nSo, \\(f\\) is continuous at \\(a\\) if \\(f(x)\\) approaches \\(f(a)\\).\nIf this is not the case we can say that te function is {\\bf discontinuous at a}.\n\n\\subsection{Limits at infinity}\nIf you take an infinity positive or negative number as the limit you can get the horizontal asymptotes of a function.\nTake for example the following function:\n\n\\begin{figure}[H]\n  \\begin{center}\n    \\begin{tikzpicture}\n      \\begin{axis}[\n          axis x line=center,\n          axis y line=center,\n          xtick={-20,-10,...,20},\n          ytick={-2,-1,...,2},\n          xlabel=$x$,\n          ylabel=$y$,\n          xmin=-20,\n          xmax=20,\n          ymin=-2,\n          ymax=2,\n          samples=75\n        ]\n        \\addplot [color=blue,domain=-20:20] {(x^2-1)/(x^2+1)};\n        \\legend{\\((x^2-1)/(x^2+1)\\)}\n      \\end{axis}\n    \\end{tikzpicture}\n  \\end{center}\n\\end{figure}\n\nThis function probably has a horizontal limit at \\(y=1\\).\nBut you don't know for sure.\nYou can use the limit of infinity to prove them.\nAs constants don't really matter when approaching infinity you can remove them.\nSo you'll get the following:\n\n\\[\n  \\lim_{x \\to \\infty} \\frac{x^2-1}{x^2+1} =\n  \\frac{\\infty^2-1}{\\infty^2+1} =\n  \\frac{\\infty^2}{\\infty^2} =\n  \\frac{1}{1} =\n  1\n\\]\nThis gets the horizontal asymptote on the right.\nIf you want to get the limit on the left you'll have to use negative infinity.\n\n\\[\n  \\lim_{x \\to -\\infty} \\frac{x^2-1}{x^2+1} =\n  \\frac{-\\infty^2-1}{-\\infty^2+1} =\n  \\frac{-\\infty^2}{-\\infty^2} =\n  \\frac{1}{1} =\n  1\n\\]\nIn this example it's also \\(y=1\\), as both asymptotes are the same.\nOne important thing to keep in mind when solving infinite limits is that \\(\\frac{1}{\\infty} = 0\\).\n", "meta": {"hexsha": "7d3b5a9c747398dbd2b07f45ae2678069c404ef2", "size": 4357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/chapters/limits.tex", "max_stars_repo_name": "dsluijk/TUD-CSE-summaries", "max_stars_repo_head_hexsha": "9157650c7a6af2e1c3072f6e66a6fd1e001460ce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Calculus/chapters/limits.tex", "max_issues_repo_name": "dsluijk/TUD-CSE-summaries", "max_issues_repo_head_hexsha": "9157650c7a6af2e1c3072f6e66a6fd1e001460ce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Calculus/chapters/limits.tex", "max_forks_repo_name": "dsluijk/TUD-CSE-summaries", "max_forks_repo_head_hexsha": "9157650c7a6af2e1c3072f6e66a6fd1e001460ce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.9007092199, "max_line_length": 130, "alphanum_fraction": 0.5831994492, "num_tokens": 1559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.7155275251479015}}
{"text": "\\subsection{Belief update}\n\\label{sec:belief}\n\nHaving estimated $P_{i,t}$ in the first phase, the second phase is rather simple. Ignoring normalizing constants, \\Cref{eq:new-obj} tells us that the pdf of the skill posterior can be obtained as the pointwise product of the pdfs of the skill prior and the performance model. When both factors are differentiable and log-concave, then so is their product. Its maximum is the new rating $\\mu_{i,t}$; let's see how to compute it for the same two specializations of our model.\n\n\\paragraph{Gaussian performance model}\nWhen the skill prior and performance model are Gaussian with known means and variances, multiplying their pdfs yields another known Gaussian. Hence, the posterior is compactly represented by its mean $\\mu_{i,t}$, which coincides with the MAP and rating; and its variance $\\sigma_{i,t}^2$, which is our \\textbf{uncertainty} regarding the player's skill.\n\n\\paragraph{Logistic performance model}\nWhen the performance model is non-Gaussian, the multiplication does not simplify so easily. By \\Cref{eq:new-obj}, each round contributes an additional factor to the belief distribution. In general, we allow it to consist of a collection of simple log-concave factors, one for each round in which player $i$ has participated. Denote the participation history by\n\\[\\cH_{i,t} := \\{k\\in\\{1,\\ldots,t\\}:i\\in\\mathcal P_k\\}.\\]\n\nSince each player can be considered in isolation, we'll omit the subscript $i$. Specializing to the logistic setting, each $k\\in\\cH_t$ contributes a logistic factor to the posterior, with mean $p_k$ and variance $\\beta_k^2$. We still use a Gaussian initial prior, with mean and variance denoted by $p_0$ and $\\beta_0^2$, respectively. Postponing the discussion of skill evolution to \\Cref{sec:skill-drift}, for the moment we assume that $S_k=S_0$ for all $k$. The posterior pdf, up to normalization, is then\n\\begin{align}\n&\\pi_0(s) \\prod_{k\\in\\cH_t} \\Pr(P_k=p_k \\mid S_k=s) \\nonumber\n\\\\&\\propto \\exp\\left( -\\frac{(s-p_0)^2}{2\\beta_0^2} \\right) \\label{eq:posterior}\n\\prod_{k\\in\\cH_t} \\sech^{2}\\left( \\frac\\pi{\\sqrt{12}} \\frac{s-p_k} {\\beta_k} \\right).\n\\end{align}\n\nMaximizing the posterior density amounts to minimizing its negative logarithm. Up to a constant offset, this is given by\n\\begin{align*}\nL(s) &:= L_2\\left(\\frac{s-p_0}{\\beta_0}\\right)\n+ \\sum_{k\\in\\cH_t} L_R\\left(\\frac{s-p_k}{\\beta_k}\\right),\n\\\\\\text{where }L_2(x) &:= \\frac 12 x^2\\text{ and }\nL_R(x) := 2\\ln\\left(\\cosh \\frac{\\pi x}{\\sqrt{12}}\\right).\n\\end{align*}\n\\begin{equation}\n\\label{eq:loss}\n\\text{Thus, }L'(s) = \\frac{s-p_0}{\\beta_0^2} + \\sum_{k\\in\\cH_t} \\frac{\\pi}{\\beta_k\\sqrt{3}} \\tanh \\frac{(s-p_k)\\pi}{\\beta_k\\sqrt{12}}.\n\\end{equation}\n\n$L'$ is continuous and strictly increasing in $s$, so its zero is unique: it is the MAP $\\mu_t$. Similar to what we did in the first phase, we can solve for $\\mu_t$ with binary search or other root-solving methods.\n\nWe pause to make an important observation. From \\Cref{eq:loss}, the rating carries a rather intuitive interpretation: Gaussian factors in $L$ become $L_2$ penalty terms, whereas logistic factors take on a more interesting form as $L_R$ terms. From \\Cref{fig:l2-lr-plot}, we see that the $L_R$ term behaves quadratically near the origin, but linearly at the extremities, effectively interpolating between $L_2$ and $L_1$ over a scale of magnitude $\\beta_k$ \n%\\aram{cite literature to justify this claim, and the next one? It would take more space to derive it ourselves}.\n\nIt is well-known that minimizing a sum of $L_2$ terms pushes the argument towards a weighted mean, while minimizing a sum of $L_1$ terms pushes the argument towards a weighted median. With $L_R$ terms, the net effect is that $\\mu_t$ acts like a robust average of the historical performances $p_k$. Specifically, one can check that\n\\[\\mu_t = \\frac{\\sum_k w_k p_k}{\\sum_k w_k}, \\text{ where } w_0 := \\frac{1}{\\beta_0^2} \\text{ and }\\]\n\\begin{equation}\n\\label{eq:average}\nw_k := \\frac{\\pi}{(\\mu_t-p_k)\\beta_k\\sqrt{3}}\\tanh\\frac{(\\mu_t-p_k)\\pi}{\\beta_k\\sqrt{12}} \\text{ for }k\\in\\cH_t.\n\\end{equation}\n\n$w_k$ is close to $1/\\beta_k^2$ for typical performances, but can be up to $\\pi^2/6$ times more as $|\\mu_t-p_k| \\rightarrow 0$, or vanish as $|\\mu_t-p_k| \\rightarrow\\infty$. This feature is due to the thicker tails of the logistic distribution, as compared to the Gaussian, resulting in an algorithm that resists drastic rating changes in the presence of a few unusually good or bad performances. We'll formally state this \\emph{robustness} property in \\Cref{thm:robust}.\n\n%Empirically, contest performances have indeed been seen to have thick tails, more like the logistic than the Gaussian (TODO citation).\n\n\\paragraph{Estimating skill uncertainty} While there is no easy way to compute the variance of a posterior in the form of \\Cref{eq:posterior}, it will be useful to have some estimate $\\sigma_t^2$ of uncertainty. There is a simple formula in the case where all factors are Gaussian. Since moment-matched logistic and normal distributions are relatively close (c.f. \\Cref{fig:l2-lr-plot}), we apply the same formula:\n\\begin{equation}\n\\label{eq:variance}\n\\frac{1}{\\sigma_t^2} := \\sum_{k\\in\\{0\\}\\cup\\cH_t}\\frac{1}{\\beta_k^2}.\n\\end{equation}", "meta": {"hexsha": "e5d4f04d2f730675aaf03e41027f6ce0b95c8d35", "size": 5217, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/source/sections/s3_2_update.tex", "max_stars_repo_name": "kiwec/Elo-MMR", "max_stars_repo_head_hexsha": "bf64ea75e8c0dbb946d379b9bee1753e604b388a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 57, "max_stars_repo_stars_event_min_datetime": "2021-02-12T18:28:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T10:59:36.000Z", "max_issues_repo_path": "paper/source/sections/s3_2_update.tex", "max_issues_repo_name": "cesartxt/Elo-MMR", "max_issues_repo_head_hexsha": "7ef860d599e8325ae1f615ce08120369b39bfecc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2021-05-09T15:42:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T08:41:23.000Z", "max_forks_repo_path": "paper/source/sections/s3_2_update.tex", "max_forks_repo_name": "cesartxt/Elo-MMR", "max_forks_repo_head_hexsha": "7ef860d599e8325ae1f615ce08120369b39bfecc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2021-02-13T13:21:48.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T23:08:41.000Z", "avg_line_length": 100.3269230769, "max_line_length": 507, "alphanum_fraction": 0.7448725321, "num_tokens": 1535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249611, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.715489564788962}}
{"text": "\\subsection{Free-Marginal Multirater Kappa}\n\\label{chp:fundamentals:sec:inter_rater_agreement:subsec:free_marginal_multirater_kappa}\n\nPopular kappa statistics, such as Fleiss' kappa \\parencite{Fleiss:1971}, are influenced by \\textit{bias} and \\textit{prevalence} which can cause low kappa values despite high agreement \\parencite{Randolph:2005, Sim:2005}.\nTherefore their interpretation is not straightforward.\nFurther, Fleiss' kappa assumes that the raters know beforehand how to distribute their votes over the possible categories.\nThis limitation is referred to as \\textit{fixed marginals} \\parencite{Brennan:1981}.\nAccording to \\textcite{Sim:2005}, prevalence influences the kappa coefficient if the proportion of agreements on one attribute differs strongly to the proportion of another attribute.\nBias is defined as the degree to which raters disagree on an attribute \\parencite{Sim:2005}.\n\nTo counteract those drawbacks, \\textcite{Randolph:2005} introduces a \\textit{Free-Marginal Multirater Kappa} $\\kappa_{free}$ which does not suffer the drawbacks of prevalence and bias.\nFurther, his approach allows free marginals, meaning that raters are not restricted on how often they assign a subject to a specific class \\parencite{Brennan:1981}.\n\\textcite{Randolph:2005} suggests to use his kappa metric when some marginals are not fixed.\nHe points out that the number of categories must be chosen carefully, since each category which is theoretically not necessary, falsely inflates the kappa's value.\n\n\\Citeauthor{Randolph:2005}'s kappa \\parencite{Randolph:2005} follows the same formula as the previous kappa coefficients.\nFrom the overall observed agreement $P_o$ the agreement merely expected by chance is subtracted, the result is then divided by the maximally adjusted chance agreement $1-P_e$.\nThis yields the same formula as for the previous kappa \\cref{eq:Cohens_kappa,eq:fleiss_kappa,eq:Scotts_pi}:\n\n\\begin{equation}\\label{eq:Randolphs_kappa}\n    \\kappa_{free} = \\frac{P_o - P_e}{1 - P_e}\n\\end{equation}\n\nIt also uses the observed agreement similar to \\citeauthor{Fleiss:1971}  $P_o=\\bar{P}$ (\\cref{eq:fleiss_P_bar}).\nHowever, its $P_e$ is defined as\n\n\\begin{equation}\\label{eq:Randolphs_Pe}\nP_e = \\frac{1}{C}\n\\end{equation}\n\nwith $C$ being the number of different classes.\nWhen plugging the test data from \\cref{tab:cohens_kappa_sample_data} into \\cref{eq:Randolphs_kappa}, \\citeauthor{Fleiss:1971}' observed agreement $\\bar{P} = 0.7$ can be reused.\nWith \\citeauthor{Randolph:2005}'s $P_e = 0.5$ the overall kappa yields again $\\kappa_{free} = \\frac{0.7 - 0.5}{1 - 0.5} = 0.4$.\n", "meta": {"hexsha": "ecc2fa5d71581a6986ea5469794c5d67f05cd611", "size": 2591, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/02_fundamentals/sections/inter_rater_agreement/subsections/free_marginal_multirater_kappa.tex", "max_stars_repo_name": "HaaLeo/vague-requirements-thesis", "max_stars_repo_head_hexsha": "f9bb53c6f17c2cd1731531ad2a68dd53d72e52e9", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/02_fundamentals/sections/inter_rater_agreement/subsections/free_marginal_multirater_kappa.tex", "max_issues_repo_name": "HaaLeo/vague-requirements-thesis", "max_issues_repo_head_hexsha": "f9bb53c6f17c2cd1731531ad2a68dd53d72e52e9", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/02_fundamentals/sections/inter_rater_agreement/subsections/free_marginal_multirater_kappa.tex", "max_forks_repo_name": "HaaLeo/vague-requirements-thesis", "max_forks_repo_head_hexsha": "f9bb53c6f17c2cd1731531ad2a68dd53d72e52e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 76.2058823529, "max_line_length": 221, "alphanum_fraction": 0.7908143574, "num_tokens": 727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.715413704567039}}
{"text": "% Expectations\n\\section{Expectations}\n\n\\subsection{Law of the Unconscious Statistician}\nGiven a random variable $X$ with distribution $f(x)$ and some function $r(x)$, the expected value $\\mathbb{E}(r)$ is given by:\n\n\\begin{equation}\n\\mathbb{E}(r) = \\int r(x) \\mathrm{d}F_X(x)\n\\end{equation}\n\n\\subsection{Linearity of Expeced Value}\n\\begin{equation}\n\\mathbb{E}\\left(\\sum_i a_i X_i \\right) = \\sum_i a_i \\mathbb{E}(X_i)\n\\end{equation}\n\n% Moments\n\\section{Moments, Central Moments}\n\nThe $k$th moment is $\\mathbb{E}X^k$. The $k$th central moment is $\\mathbb{E}(X-\\mu)^k$.\n\n\n% Variance\n\\section{Variance}\n\nIn one dimension:\n\\begin{equation}\n\\sigma^2 =\\mathbb{V}(X) = \\mathbb{E}(X-\\mu)^2 = \\int (x-\\mu)^2 \\mathrm{d}F(x)\n\\end{equation}\n\nThe standard deviation is $\\mathrm{sd}(X) = \\sqrt{\\mathbb{V}(X)}$. \n\n\\begin{itemize}\n\\item $\\mathbb{V}(X) = \\mathbb{E}(X^2) - \\mu^2$.\n\\item If $a$ and $b$ are constants, $\\mathbb{V}(aX+b) = a^2 \\mathbb{V}(X)$.\n\\item If $X_1,...,X_n$ are independent and $a_1,...,a_n$ are constants, then $\\mathbb{V}\\left(\\sum^n_{i=1}a_i X_i\\right) = \\sum_{i=1}^n a_i^2 \\mathbb{V}(X_i)$\n\\end{itemize}\n\n\n% Higher Dimensions\n\\section{Mean and Variance of Vector Valued Random Variables}\nThe mean is simply $\\mathbb{E}(\\mathbf{X}) = (...,\\mathbb{E}(X_i),...,) $. In higher dimensions, the variance is a matrix with entries $\\Sigma_{i,j}= \\mathrm{Cov}(X_i,X_j)$. \n\n\\begin{itemize}\n\\item $\\mathbb{E}(\\mathbf{a}^T \\mathbf{X}) = \\mathbf{a}^T\\mathbf{\\mu}$\n\\item $\\mathbb{E}(\\mathbf{A}\\mathbf{X}) = \\mathbf{A\\mu}$\n\\item $\\mathbb{V}(\\mathbf{a}^T \\mathbf{X}) = \\mathbf{a}^T\\mathbf{\\Sigma}\\mathbf{a}$\n\\item $\\mathbb{V}(\\mathbf{AX}) = \\mathbf{A\\Sigma A}^T$\n\\end{itemize}\n\n% Covariance\n\\section{Covariance, Correlation}\n\\begin{equation}\n\\mathrm{Cov}(X,Y) = \\mathbb{E}(XY) - \\mathbb{E}X\\mathbb{E}Y\n\\end{equation}\n\n\n\n% Sample Mean, Sample Variance\n\\section{Sample Mean and Sample Variance}\nIf $X_1,...,X_n$ are random variables, the \\textit{sample mean} is:\n\n\\begin{equation}\n\\overline{X}_n = \\frac{1}{n}\\sigma_i X_i\n\\end{equation}\n\nThe \\textit{sample variance} is:\n\n\\begin{equation}\nS^2_n = \\frac{1}{n-1} \\sum^n_{i=1} (X_i - \\overline{X}_n)^2\n\\end{equation}\n\nThe sample mean and sample variance are random variables. The mean and variance are fixed properties of the underlying distribution.\n\n\\begin{equation}\n\\begin{array}{l}\n\\mathbb{E}(\\overline{X}_n) = \\mu\\\\\n\\mathbb{V}(\\overline{X}_n) = \\frac{\\sigma^2}{n}\\\\\n\\mathbb{E}(S_n^2) = \\sigma^2\\\\\n\\end{array}\n\\end{equation}\n\n\n\\section{Law of Iterated Expectation}\n\nGiven two random variables $X$ and $Y$, the law of iterated expectation states:\n\n\\begin{equation}\n\\mathbb{E}(X) = \\mathbb{E}\\mathbb{E}(X|Y)\n\\end{equation}\n\n\\subsection{Applied to Variance}\n\\begin{equation}\n\\mathbb{V}(Y) = \\mathbb{EV}(Y|X) + \\mathbb{VE}(Y|X)\n\\end{equation}", "meta": {"hexsha": "fb7ef12db8d67e0462fd5dca668113eaeff0ed49", "size": 2779, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/proba_moments.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/proba_moments.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/proba_moments.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5638297872, "max_line_length": 174, "alphanum_fraction": 0.6736236056, "num_tokens": 1082, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793453, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.715393219752051}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\n\n\\newtheorem{definition}{Definition}\n\\newtheorem{conjecture}{Conjecture}\n\\newtheorem{theorem}{Theorem}\n\n\\newtheorem{algorithm}{Algorithm}\n\n\\newcommand{\\htn}{\\hat{\\theta}_n} \n\n\\begin{document}\n\n\n\n\\section{Types of convergence}\n\n\\begin{definition}\nConvergence in distribution is defined via\n\\begin{equation}\nF_{X_n} \\rightarrow F_X \\quad \\text{as } n \\rightarrow \\infty\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}\n\tConvergence in probability is defined via\n\t\\begin{equation}\n\tP(|X_n - X| > \\epsilon) \\quad \\text{as } n \\rightarrow \\infty \\  \\forall \\epsilon\n\t\\end{equation}\n\\end{definition}\n\n\\begin{definition}\n\tConvergence almost surely is defined via\n\t\\begin{equation}\n\tP(X_n \\rightarrow X,  n \\rightarrow \\infty) = 1 \n\t\\end{equation}\n\\end{definition}\n\n\n\\textbf{Almost surely implies in probability implies in distribution!}\n\n\\begin{theorem}[Slutsky]\n\t\n\tSuppose $X_n \\xrightarrow{d} X$ and $Y_n \\xrightarrow{p} a$ where $a$ is a constant. Then\n\t\\begin{enumerate}\n\t\t\\item $X_n Y_n \\xrightarrow{d} aX$\n\t\t\\item $X_n + Y_n \\xrightarrow{d} X+ a$\n\t\\end{enumerate}\n\\end{theorem}\n\n\\section{Fundamental laws}\n\\begin{theorem}[Weak Law of Large Numbers]\n\tLet $X_1, X_2, \\dots , X_n$ be i.i.d distributed random variables with a finite mean $\\mu_X$.  Let $S_n = \\sum_1^n X_i$.\n\tThen\n\t\\begin{equation}\n\t\\lim_{n \\to \\infty} P\\left( \\lvert \\frac{S_n}{n} - \\mu_X \\rvert > \\epsilon) \\right)  = 0 \\quad \\forall \\epsilon\n\t\\end{equation}\n\t\n\\end{theorem}\n\n\\begin{theorem}[Central Limit Theorem]\n\tLet $X_1, X_2, \\dots , X_n$ be i.i.d distributed random variables with a finite mean $\\mu_X$ and finite variance $\\sigma_X^2$.\n\tThen the sample mean $\\bar X_n = \\sum_1^n X_i /n$ will follow an approximately normal distribution with mean $\\mu_X$, and variance $\\sigma^2_X/n$. Alternatively,\n\t\\begin{equation}\n\t\\bar X_n \\xrightarrow{d} N(\\mu_X, \\frac{\\sigma^2_X}{n})\n\t\\end{equation}\n\\end{theorem}\n\n\\section{Basics}\n\n\\begin{definition}\nA \\textbf{statistical model} is a pair $(E, P_\\theta) \\quad \\theta\\in \\Theta$ where $E$ is the sample sapce, $P$ is a family of probability distributions and $\\theta$ is the parameter set describing the distributions. \n\\end{definition}\n\\begin{itemize}\n\t\\item When $\\Theta \\in R^d$ we call the model parameteric.  \n\t\\item When $\\Theta$ is infinite dimensional the model is non-parametric\n\t\\item When $\\Theta = \\Theta_1 \\times \\Theta_2$ where $\\Theta_1$ is infinite dimesnional and $\\Theta_2$ is finite dimensional the model is called semi-parametric.   \n\\end{itemize}\n\n\\begin{definition}\nA \\textbf{statistic} is any measurabable function of the sample.  An \\textbf{estimator} of $\\theta$ is a statistic $\\hat \\theta_n =  \\hat \\theta_n(X_1, X_2, \\dots , X_n)$ which does not depend on $\\theta$. \n\\end{definition}\n\n\\begin{definition}\nAn estimator is \\textbf{weekly consistent} if $\\lim_{n \\to \\infty} \\hat \\theta_n = \\theta$.\n\\end{definition}\n\n\\begin{definition}\nThe \\textbf{bias} of an estimator is given by \n\\begin{equation}\n\\text{bias} = E[\\hat \\theta_n] - \\theta\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}\nThe \\textbf{variance} of an estimator is given by\\begin{equation}\n\\text{variance} = E \\left[ (\\hat \\theta_n - E[\\hat \\theta_n])^2 \\right]\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}\nThe \\textbf{quadratic risk} of an estimator is given by\n\\begin{align}\nR &= E \\left[ (\\htn - \\theta)^2 \\right] = E \\left[ (\\hat \\theta_n - E[\\htn] + E[\\htn] - \\theta )^2  \\right] \\\\\n&=  \\text{variance} + \\underbrace{ E \\left[ \\hat \\theta_n -\n E[\\htn]  \\right]}_{=0} (E[\\htn] - \\theta) + \\text{bias}^2 \\\\\n& = \\text{variance} + \\text{bias}^2\n\\end{align}\n\\end{definition}\n\n\n\\end{document}", "meta": {"hexsha": "f26e27456591f8fc6934cba05a8b7ec5710dd0f8", "size": 3759, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "stats_review.tex", "max_stars_repo_name": "pekronus/docs", "max_stars_repo_head_hexsha": "6a6b4525e95eca07505888572c9319e15352782d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "stats_review.tex", "max_issues_repo_name": "pekronus/docs", "max_issues_repo_head_hexsha": "6a6b4525e95eca07505888572c9319e15352782d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "stats_review.tex", "max_forks_repo_name": "pekronus/docs", "max_forks_repo_head_hexsha": "6a6b4525e95eca07505888572c9319e15352782d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.1282051282, "max_line_length": 218, "alphanum_fraction": 0.7105613195, "num_tokens": 1253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.8774767938900121, "lm_q1q2_score": 0.7153475831534418}}
{"text": "\\subsection{The Second Derivative Test}\\label{sec:SecondDer}\nThe basis of the first derivative test is that if the derivative\nchanges from positive to negative at a point at which the derivative\nis zero then there is a local maximum at the point, and similarly for\na local minimum. If $f'$ changes from positive to negative it is\ndecreasing; this means that the derivative of $f'$, $f''$, might be negative,\nand if in fact $f''$ is negative then $f'$ is definitely\ndecreasing. From this we determine that there is a local maximum at the point in question. Note\nthat $f'$ might change from positive to negative while $f''$ is\nzero, in which case $f''$ gives us no information about the critical\nvalue. Similarly, if $f'$ changes from negative to positive there is a\nlocal minimum at the point, and $f'$ is increasing. If $f''>0$ at the\npoint, this tells us that $f'$ is increasing, and so there is a local\nminimum.\n\n\\begin{example}{Second Derivative}{secondderivative}\nConsider again $f(x)=\\sin x + \\cos x$,  with $f'(x)=\\cos x-\\sin x$ and\n$ f''(x)=-\\sin x -\\cos x$. Use the second derivative test to determine which critical points are local maximum or minima.\n\\end{example}\n\\begin{solution}\nSince $\\ds f''(\\pi/4)=-\\sqrt{2}/2-\\sqrt2/2=-\\sqrt2<0$,\nwe know there is a local maximum at $\\pi/4$. Since\n$\\ds f''(5\\pi/4)=-(-\\sqrt{2}/2)-(-\\sqrt2/2)=\\sqrt2>0$, there is a local\nminimum at $5\\pi/4$.\n\\end{solution}\n\nWhen it works, the second derivative test is often the easiest way to\nidentify local maximum and minimum points. Sometimes the test fails,\nand sometimes the second derivative is quite difficult to evaluate; in\nsuch cases we must fall back on one of the previous tests.\n\n\\begin{example}{Second Derivative}{secondderivativetwo}\nLet $\\ds f(x)=x^4$ and $\\ds g(x)=-x^4$. Classify the critical points of $f(x)$ and $g(x)$ as either maximum or minimum.\n\\end{example}\n\\begin{solution}\nThe derivatives for $f(x)$ are $f'(x)=4x^3$ and $\\ds f''(x)=12x^2$.\nZero is the only critical value, but $f''(0)=0$, so\nthe second derivative test tells us nothing. However, $f(x)$ is\npositive everywhere except at zero, so clearly $f(x)$ has a local\nminimum at zero.\n\nOn the other hand, for $g(x)=-x^4$, $g'(x)=-4x^3$ and $g''(x)=-12x^2$. So $g(x)$ also has zero\nas its only only critical value, and the second derivative is again zero, but $-x^4$ has a local maximum at zero.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:SecondDer}}\n\n\\begin{enumialphparenastyle}\n\nFind all local maximum and minimum points by the second derivative test. \n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=x^2-x$ \n\\begin{sol}\n min at $x=1/2$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=2+3x-x^3$ \n\\begin{sol}\n min at $x=-1$, max at $x=1$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=x^3-9x^2+24x$\n\\begin{sol}\n max at $x=2$, min at $x=4$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=x^4-2x^2+3$ \n\\begin{sol}\n min at $x=\\pm 1$, max at $x=0$.\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=3x^4-4x^3$\n\\begin{sol}\n min at $x=1$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=(x^2-1)/x$\n\\begin{sol}\n none\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=3x^2-(1/x^2)$ \n\\begin{sol}\n none\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $y=\\cos(2x)-x$ \n\\begin{sol}\n min at $x=7\\pi/12+n\\pi$, max at $x=-\\pi/12+n\\pi$, for integer $n$.\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = 4x+\\sqrt{1-x}$\n\\begin{sol}\n max at $x=63/64$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = (x+1)/\\sqrt{5x^2 + 35}$\n\\begin{sol}\n max at $x=7$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y= x^5 - x$\n\\begin{sol}\n max at $\\ds -5^{-1/4}$, min at $\\ds 5^{-1/4}$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = 6x +\\sin 3x$\n\\begin{sol}\n none\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = x+ 1/x$\n\\begin{sol}\n max at $-1$, min at $1$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = x^2+ 1/x$\n\\begin{sol}\n min at $\\ds 2^{-1/3}$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = (x+5)^{1/4}$\n\\begin{sol}\n none\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = \\tan^2 x$\n\\begin{sol}\n min at $n\\pi$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y =\\cos^2 x - \\sin^2 x$\n\\begin{sol}\n max at $n\\pi$, min at $\\pi/2+n\\pi$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = \\sin^3 x$\n\\begin{sol}\n max at $\\pi/2+2n\\pi$, min at $3\\pi/2+2n\\pi$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "6a0861c050df32e5db7a22911e80441f1c5bde19", "size": 4428, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-6-2-second-derivative-test.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5-applications-of-derivatives/5-6-2-second-derivative-test.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5-applications-of-derivatives/5-6-2-second-derivative-test.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.14, "max_line_length": 121, "alphanum_fraction": 0.6156278229, "num_tokens": 1613, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.7153186519842669}}
{"text": "\\newpage\n\\section[Differentiation]{\\hyperlink{toc}{Differentiation}}\n\n\\subsection{Derivatives}\n\\begin{definition}{Derivatives}{5.1}\n    Let $f: [a, b] \\mapsto \\RR$, and $x \\in [a, b]$. We then define the \\textbf{derivative} of $f$ at $x$ as:\n    \\begin{align*}\n        f'(x) = \\lim_{t\\rightarrow x} \\frac{f(t) - f(x)}{t - x}\n    \\end{align*}\n    If the limit exists. Alternative notations for the derivative are given by:\n    \\begin{align*}\n        \\dpd{f}{x}(x) \\text{ or } \\dod{}{x}f(x) \\text { or } \\left.\\dod{}{y}f(x)\\right|_{y = x}\n    \\end{align*}\n\\end{definition}\nAs an interpretation of the derivative, take $[a, b]$ to be a metric space, with $x$ a limit point of $[a, b] \\setminus \\set{x}$. Then, $g(t) = \\frac{f(t) - f(x)}{t - x}$ is a function from $[a, b] \\setminus \\set{x} \\mapsto \\RR$. If $x \\in (a, b)$, then the above definition of the derivative agrees with the definition of $f'(x)$ from first year calculus. If $x = a$ or $x = b$, then the above definition agrees with the definition of the one-sided derivative from first year calculus. Note that we will not discuss in this class cases where the domain gets more complicated (i.e. not just closed intervals of $\\RR$).\n\n\\begin{theorem}{}{5.2}\n    Let $f:[a,b] \\mapsto \\RR$, let $x \\in [a, b]$, and suppose $f'(x)$ exists. Then, $f$ is continuous at $x$.\n\\end{theorem}\n\\begin{nproof}\n    For $t \\neq x$, we can write:\n    \\begin{align*}\n        f(t) = f(x) + (f(t) - f(x)) = f(x) + \\frac{f(t) - f(x)}{t - x}(t - x)\n    \\end{align*}\n    Taking the limit of $t \\rightarrow x$, we then have that:\n    \\begin{align*}\n        \\lim_{t \\rightarrow x} f(t) = \\lim_{t \\rightarrow x} \\left(f(x) + \\frac{f(t) - f(x)}{t - x}(t - x) \\right) = \\lim_{t \\rightarrow x} f(x) + \\lim_{t \\rightarrow x} \\frac{f(t) - f(x)}{t - x} \\lim_{t \\rightarrow x} (t - x)\n    \\end{align*}\n    Where in the last line we invoke Theorem \\ref{thm:4.4}. Evaluating the limits on the RHS by using the existence of the derivative of $f$ at $x$, we have\n    \\begin{align*}\n        \\lim_{t \\rightarrow x} f(t) = f(x) + f'(x)\\cdot (0) = f(x)\n    \\end{align*}\n    So we conclude that $f$ is continuous at $x$ by Theorem \\ref{thm:4.6}. \\qed\n\\end{nproof}\nThe interpretation is that differentiability at $x \\in (a, b)$ implies continuity of $f$ at $x$, and the left/right differentiability of $f$ at $a/b$ implies the left/right continuity of $f$ at $a/b$. We have wrapped the proof of all these cases into one!\n\nNote that the converse of the above theorem is not true. As a simple example, take $f(x) = \\abs{x}$ on $[-1, 1]$, which is continuous at $x = 0$ (it can be verified that $\\lim_{x \\rightarrow 0}f(x) = f(0) = 0$) but is not differentiable there (the left/right handed limits of the difference quotient do not agree and hence the derivative does not exist). In Chapter 7, we will construct a function that is continuous everywhere and differentiable nowhere!\n\nNWe will now proceed to prove a series of theorems that have been seen in first year, but using our new/rigorous definitions.\n\n\\begin{theorem}{Sum, Product, and Quotient Rules}{5.3}\n    Let $f, g: [a, b] \\mapsto \\RR$. Let $x \\in [a, b]$ and suppose $f$ and $g$ are differentiable at $x$. Then, $f + g$, $f - g$, $f\\cdot g$ are differentiable at $x$, and so is $\\frac{f}{g}$ provided $g(x) \\neq 0$. Furthermore:\n    \\begin{enumerate}\n        \\item $(f+g)'(x) = f'(x) + g'(x)$\n        \\item $(fg)'(x) = f'(x)g(x) + f(x)g'(x)$\n        \\item $\\left(\\frac{f}{g}\\right)'(x) = \\frac{f'(x)g(x) - f(x)g'(x)}{(g(x))^2}$\n    \\end{enumerate}\n\\end{theorem}\n\\begin{nproof}\n    \\begin{enumerate}\n        \\item Follows immediately from the additive property of limits (Theorem \\ref{thm:4.4}).\n        \\item Let $h = fg$. We then have that:\n        \\begin{align*}\n            h(t) - h(x) = f(t)\\left[g(t) - g(x)\\right] + g(x)\\left[f(t) - f(x)\\right]\n        \\end{align*}\n        For $t \\neq x$, we can divide both sides by $t-x$ to obtain:\n        \\begin{align*}\n            \\frac{h(t) - h(x)}{t - x} = f(t)\\frac{g(t) - g(x)}{t-x} + g(x)\\frac{f(t) - f(x)}{t - x}\n        \\end{align*}\n        Taking the limit of $t \\rightarrow x$ on both sides, we obtain:\n        \\begin{align*}\n            h'(x) = f(x)g'(x) + f'(x)g(x)\n        \\end{align*}\n        as desired.\n        \\item Let $h(t) = \\frac{f(t)}{g(t)}$. Then:\n        \\begin{align*}\n            h(t) - h(x) &= \\frac{f(t)}{g(t)} - \\frac{f(x)}{g(x)}\n            \\\\ &= \\frac{1}{g(t)g(x)}\\left(f(t)g(x) - g(t)f(x)\\right)\n            \\\\ &= \\frac{1}{g(t)g(x)}\\left[g(x)\\left(f(t) - f(x)\\right) - f(x)\\left(g(t) - g(x)\\right)\\right]\n        \\end{align*}\n        For $t \\neq x$, we can divide both sides by $t - x$ to get:\n        \\begin{align*}\n            \\frac{h(t) - h(x)}{t - x} = \\frac{1}{g(t)g(x)}\\left[g(t)\\frac{f(t) - f(x)}{t - x} - f(x)\\frac{g(t) - g(x)}{t - x}\\right]\n        \\end{align*}\n        Taking the limit as $t \\rightarrow x$ on both sides, we obtain the desired expression. \\qed\n    \\end{enumerate}\n\\end{nproof}\n\n\\newpage \n\\noindent As an exercise, one can prove by induction (applying 5.3(b)) that $(f_1f_2f_3\\ldots f_n)'(x)$ (where $f_i: [a, b] \\mapsto \\RR$ and each $f_i'(x)$ exists) is given by:\n\\begin{align*}\n    f_1'(x)f_2(x)\\ldots f_n(x) + \\cdots + f_1(x)f_2(x)\\ldots f'_n(x).\n\\end{align*}\nNote that as a corollary of this, we get that if $f(x) = x^n$, then $f'(x) = nx^{n-1}$ and we hence recover the familiar power rule from first year calculus!\n\n\\setcounter{rudin}{4}\n\\begin{theorem}{Chain Rule}{5.5}\n    Let $f: [a, b] \\mapsto \\RR$, $x \\in [a, b]$, and suppose $f$ is differentiable at $x$. Suppose furthermore that $f([a, b])$ is contained in some interval $I$. Let $g: I \\mapsto \\RR$ and suppose $g$ is differentiable at $f(x)$. Then, $g \\circ f: [a, b] \\mapsto \\RR$ is differentiable at $x$, and furthermore:\n    \\begin{align*}\n        (g \\circ f)'(x) = g'(f(x))f'(x)\n    \\end{align*}\n\\end{theorem}\n\\begin{nproof}\n    Define $h(t) = g \\circ f(t)$ for $a \\leq t \\leq b$, $t \\neq x$. We cna then write:\n    \\begin{align*}\n        f(t) - f(x) = (t-x)\\left[f'(x) + u(t)\\right]\n    \\end{align*}\n    For a function $u(t)$ with $\\lim_{t \\rightarrow x} u(t) = 0$. Now defining $y = f(x)$, we write:\n    \\begin{align*}\n        g(s) - g(y) = (s-y)\\left[g'(y) + r(s)\\right]\n    \\end{align*}\n    For a function $r(s)$ with $\\lim_{s \\rightarrow y}r(s) = 0$. Hence, we have that:\n    \\begin{align*}\n        h(t) - h(x) &= g(f(t)) - g(f(x))\n        \\\\ &= \\left(f(t) - f(x)\\right)\\left(g'(y) + r(s)\\right)\n        \\\\ &= (t- x)\\left[f'(x) + u(t)\\right]\\left(g'(y) + r(s)\\right)\n    \\end{align*}\n    Dividing both sides by $t - x$, we obtain:\n    \\begin{align*}\n        \\frac{h(t) - h(x)}{t - x} = \\left[f'(x) + u(t)\\right]\\left(g'(y) + r(s)\\right)\n    \\end{align*}\n    We now take the limit of $t \\rightarrow x$ on both sides. $\\lim_{t \\rightarrow x} u(t) = 0$, and $f$ is differentiable and hence continuous at $x$, so $s = f(t) \\rightarrow y$ as $t \\rightarrow x$. Thus, $r(s) \\rightarrow 0$ as $t \\rightarrow x$, and in conclusion:\n    \\begin{align*}\n        h'(x) = (g \\circ f)'(x) =  f'(x)g'(y) = g'(f(x))f'(x)\n    \\end{align*}\n    as desired. \\qed\n\\end{nproof}\n\n\n\\subsection{MVT}\n\n\\setcounter{rudin}{6}\n\\begin{definition}{Local Maxima/Minima}{5.7}\n    Let $X$ be a metric space. Let $f: X \\mapsto \\RR$, and let $x \\in X$. We say that $x$ is a \\textbf{local maximum} of $f$ if there exists $\\delta > 0$ such that $f(y) \\leq f(x)$ for all $y \\in N_{\\delta}(x)$. A \\textbf{local minimum} is defined similarly, with $f(y) \\geq f(x)$ instead.\n\\end{definition}\n\\noindent For a metric space $X$ equipped with the discrete metric, all points $x \\in X$ are simultaneously local maxima and minima. To see this, take any $0 < \\delta \\leq 1$. \n\n\\begin{theorem}{}{5.8}\n    Let $f: [a, b] \\mapsto \\RR$. Let $x \\in [a, b]$ and suppose that $f'(x)$ exists, and $f$ is either a local maximum or local minimum of $f$. Then, $f'(x) = 0$. \n\\end{theorem}\n\\begin{nproof}\n    Suppose $x$ is a local minimum. Then, there exists $\\delta > 0$ such that $N_{\\delta}(x) \\subset [a, b]$, and $f(y) \\geq f(x)$ for all $y \\in N_{\\delta}(x)$. Thus, if $x < y < x + \\delta$, then:\n    \\begin{align*}\n        \\frac{f(y) - f(x)}{y - x} \\geq 0 \\implies f'(x) \\geq 0\n    \\end{align*}\n    Conversely, if $x - \\delta < y < x$, then:\n    \\begin{align*}\n        \\frac{f(y) - f(x)}{y - x} \\leq 0 \\implies f'(x) \\leq 0\n    \\end{align*}\n    So taken together we obtain that $f'(x) = 0$. An identical argument is used for the case of a local maximum. \\qed\n\\end{nproof}\n\n\\begin{ntheorem}{: Rolle's Theorem}{}\n    Let $f: [a, b] \\mapsto \\RR$ be continuous, and suppose $f$ is differentiable on $(a, b)$. If $f(a) = f(b)$, then there exists $x \\in (a, b)$ such that $f'(x) = 0$.\n\\end{ntheorem}\n\\begin{nproof}\n    Since $[a, b]$ is compact and $f$ is continuous, by the EVT (Theorem \\ref{thm:4.16}) $f$ attains its maximum on $[a, b]$, that is, there exists $c \\in [a, b]$ such that $f(y) \\leq f(x)$ for all $y \\in [a, b]$. If $c \\in (a, b)$, then by Theorem \\ref{thm:5.8}, $f'(c) = 0$ and we are done. Next, suppose $c = a$ or $c = b$. Again by the EVT, $f$ attains its minumum on $[a, b]$, that is, there exists $d \\in [a, b]$ such that $f(y) \\geq f(d)$ for all $y \\in [a, b]$. If $d \\in (a, b)$, then by Theorem \\ref{thm:5.8}, $f'(d) = 0$ and we are done. Suppose then that $d = a$ or $d = b$. Since $f(a) = f(b)$, we therefore obtain that $f(a) = f(b) = f(c) = f(d)$ and the maximum/minimum values agree. Hence, $f(y) = f(a)$ for all $y \\in [a, b]$, so $f'(y) = 0$ for all $y \\in [a, b]$. So, the desired $x$ may be any point in $[a, b]$. \\qed\n\\end{nproof}\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale = 2]\n        \\draw[-latex, very thick] (0, 0) -- (0, 2);\n        \\draw[-latex, very thick] (0, 0) -- (2, 0);\n        \\draw[] (1, 1.5) parabola (0.5, 0.2);\n        \\draw[] (1, 1.5) parabola (1.5, 0.2);\n        \\filldraw[] (0.5, 0.2) circle (1pt);\n        \\filldraw[] (1.5, 0.2) circle (1pt);\n        \\draw[dashed, red] (0, 1.51) -- (1.85, 1.51);\n        \\draw[] (0.5, 0) -- (0.5, -0.15);\n        \\node[below] at (0.5, -0.15) {$a$};\n        \\draw[] (1.5, 0) -- (1.5, -0.15);\n        \\node[below] at (1.5, -0.12) {$b$};\n        \\draw[] (1, 0) -- (1, -0.15);\n        \\node[below] at (1, -0.16) {$x$};\n    \\end{tikzpicture}\n    \n    \\caption{A simple parabolic function that demonstrates Rolle's Theorem.}\n    \\label{fig21}\n\\end{figure}\n\n\\newpage \n\\setcounter{rudin}{9}\n\\begin{theorem}{Mean Value Theorem}{5.10}\n    Let $f: [a, b] \\mapsto \\RR$ be continuosu and differentiable on $(a, b)$. Then, there exists $x \\in (a, b)$ such that $f(b) - f(a) = f'(x)(b - a)$.\n\\end{theorem}\n\\noindent The visual interpretation of this theorem is that there exists $x \\in (a, b)$ such that the slope of the tangent line to $f$ at $x$ is equal to the secant line slope between $(a, f(a))$ and $(b, f(b))$. The idea of the proof is to rotate one's head such that the sectant line is horizontal; one is then able to apply Rolle's Theorem!\n\n\\begin{nproof}\n    Define $h(y) = f(y) = \\frac{f(b) - f(a)}{b - a}(y - a)$. $h$ is continuous on $[a, b]$ and differentiable on $(a, b)$ (being a sum of continuous/differentiable functions). We have that $h(a) = f(a) - 0 = f(a)$, and $h(b) = f(b) - \\frac{f(b) - f(a)}{b - a}(b - a) = f(a)$. Applying Rolle's Theorem to $h$, there exists $x \\in (a, b)$ such that $h'(x) = 0$. Therefore, $h'(x) = 0 = f'(x) - \\frac{f(a) - f(b)}{b - a} = 0$, and we conclude that $f(b) - f(a) = f'(x)(b - a)$ for some $x \\in (a, b)$. \\qed\n\\end{nproof}\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale=2]\n    \\draw[-latex, very thick] (0, 0) -- (0, 2);\n    \\draw[-latex, very thick] (0, 0) -- (2, 0);\n    \\draw [] (0.5 , 0.25) to [ curve through ={(1, 1.25)}] (1.5,1.5);\n    \\filldraw[] (0.5, 0.25) circle (1pt);\n    \\filldraw[] (1.5, 1.5) circle (1pt);\n    \\draw[dashed] (0.5, 0.25) -- (1.5, 1.5);\n    \\draw[dashed, red] (0, 0.075) -- (1, 1.325) -- (1.42,1.85);\n    \\draw[] (0.5, 0) -- (0.5, -0.15);\n    \\node[below] at (0.5, -0.15) {$a$};\n    \\draw[] (1.5, 0) -- (1.5, -0.15);\n    \\node[below] at (1.5, -0.12) {$b$};\n    \\draw[] (0.775, 0) -- (0.775, -0.15);\n    \\node[below] at (0.775, -0.16) {$x$};\n    \\end{tikzpicture}\n    \\caption{A simple continuous function that demonstrates the MVT.}\n    \\label{fig22}\n\\end{figure}\n\n\n\\begin{theorem}{}{5.11}\n    Let $f: [a, b] \\mapsto \\RR$ be differentiable on $(a, b)$. Then:\n    \\begin{enumerate}\n        \\item If $f'(x) \\geq 0$ for all $x \\in (a, b)$, then $f$ is monotonically increasing.\n        \\item If $f'(x) = 0$ for all $x \\in (a, b)$, then $f$ is constant. \n        \\item If $f'(x) \\leq 0$ for all $x \\in (a, b)$, then $f$ is monotonically decreasing.\n    \\end{enumerate} \n\\end{theorem}\n\\begin{nproof}\n    If $a < x < y < b$, by the mean value theorem, there exists $z \\in (x, y)$ such that:\n    \\begin{align*}\n        f(y) - f(x) = f'(z)(y - x)\n    \\end{align*}\n    Note that $y - x > 0$ by construction. \n    \\begin{enumerate}\n        \\item If $f'(x) \\geq 0$ for all $x \\in (a, b)$, then $f'(z) \\geq 0$, showing that $f(y) - f(x) \\geq 0$ and hence that $f$ is monotonically increasing. \n        \\item If $f'(x) = 0$ for all $x \\in (a, b)$, then $f'(z) = 0$, showing that $f(y) - f(x) = 0$ and hence that $f$ is constant on $(a, b)$.\n        \\item If $f'(x) \\leq 0$ for all $x \\in (a, b)$, then $f'(z) \\leq 0$, showing that $f(y) - f(x) \\leq 0$ and hence that $f$ is monotonically decreasing. \\qed\n    \\end{enumerate}\n\\end{nproof}\n\n\\subsection{Taylor's Theorem}\n\\setcounter{rudin}{13}\n\\begin{definition}{Higher Order Derivatives}{5.14}\nIf $f$ is differentiable in a neighbourhood of $x$, then we may compute a second order derivative:\n\\begin{align*}\n    \\lim_{t \\rightarrow x} \\frac{f'(t) - f'(x)}{t - x} = (f')'(x) = f''(x)\n\\end{align*}\nWe can then continue this process to obtain $f^{(3)}(x), f^{(4)}(x), \\ldots, f^{(n)}(x)$. \n\\end{definition}\n\\begin{ndef}{: \\texorpdfstring{$C^n(I, \\RR)$}{Cn(I, R)}}{}\n    If $f$ is continuous in $I$, we can write $f \\in C^{0}(I, \\RR)$. If $f$ is differentiable in a neighbourhood $I$ and the derivative $f'$ is continuous in $I$, then we write $f \\in C^{1}(I, \\RR)$. In general, $f \\in C^{n}(I, \\RR)$ denotes the $n$th derivative of $f$ is continuous in $I$. Note that where it is clear from context, we may drop the $\\RR$ and just write $C^n(I)$. \n\\end{ndef}\n\\noindent Recall that for a function $f$ continuous and differentiable on $(x_0, x)$, the Mean Value Theorem proved the existence of some $\\tilde{x}$ such that:\n\\begin{align*}\n    f(x) = f(x_0) + f'(\\tilde{x})(x - x_0)\n\\end{align*}\nThis gives us a natural method to build up approximations for functions; we can start with a constant approximation $f(x_0)$, then add a linear term $f'(\\tilde{x})(x - x_0)$, then add on a quadratic term $(x - x_0)^2$ and so on. The following theorem gives us a way to construct these approximations and bound their error.\n\n\\begin{theorem}{Taylor's Theorem}{5.15}\n    Let $I$ be a neighbourhood of $x_0$, and $f \\in C^p(I)$. Then, for any $n < p$, we have that:\n    \\begin{align*}\n        f(x) = \\sum_{j=0}^n \\frac{f^{(j)}(x_0)}{j!}(x- x_0)^j + \\frac{f^{(n+1)}(\\tilde{x})}{(n+1)!}(x - x_0)^{n+1}\n    \\end{align*}\n    Where $\\tilde{x} = x_0 + \\lambda(x - x_0)$ for some $\\lambda \\in (0, 1)$ (i.e. $\\tilde{x} \\in (x_0, x)$). Note that $\\tilde{x}$ depends on $x, x_0$, and $n$. \n\\end{theorem}\n\\begin{nproof}\n    For $n = 0$, the claim reduces to the Mean Value Theorem. Then, let $n \\geq 1$. Let $A$ be a constant that depends on $x, x_0$, and $n$, and let $P_n(x) = \\sum_{j=0}^n \\frac{f^{(j)}(x_0)}{j!}(x-x_0)^j$. Then, we can write:\n    \\begin{align*}\n        f(x) = P_n(x) + A(x-x_0)^{n+1}\n    \\end{align*}\n    We need to show that we can express $A$ as relating to the derivative, namely, that there exists $\\tilde{x}$ such that $A = \\frac{f^{(n+1)}(\\tilde{x})}{(n+1)!}$. Let $g(t) = f(t) - P_n(t) - A(t - x_0)^{n+1}$ with $t \\in I$. Then, $g \\in C^{p}(I)$. For $n < p$, we then have that:\n    \\begin{align*}\n        g^{(n+1)}(t) = f^{(n+1)}(t) - 0 - A(n+1)!(t - x_0)\n    \\end{align*}\n    We claim that there exists $\\tilde{x} \\in (x_0, x)$ such that $g^{(n+1)}(\\tilde{x}) = 0$. To see this, consider that $P^{(j)}(x_0) = f^{(j)}(x_0)$ for $j = 0, 1, \\ldots, n$, so $g(x_0) = 0$, and furthermore:\n    \\begin{align*}\n        g'(x_0) = g''(x_0) = g^{(3)}(x_0) = \\ldots = g^{(n)}(x_0) = 0\n    \\end{align*}\n    Moreover y the choice of $n$, we have that $g(x) = 0$. Hence, by Rolle's Theorem, there exists a point $x_1$ between $x_0$ and $x$ such that $g'(x_1) = 0$. Similarly, repeating the argument above, there exists an $x_2$ between $x_0$ and $x_1$ such that $g''(x_2) = 0$. Repeating this process up to $g^{(n)}$, we have that $g^{(n)}(x_n) = 0$, for some $x_0 < x_{n} < x_{n-1} < \\cdots < x$ and in turn, there exists $x_{n+1} \\in (x_0, x_n)$ such that $g^{(n+1)}(x_{n+1}) = 0$. Setting $\\tilde{x} = x_{n+1}$, the claim is shown. \\qed\n\\end{nproof}\n\n\\noindent As an example, we consider the Taylor series of the function $f(x) = \\cos(x)$ (We will formally define this function later on, but for now, let us assume its familar properties and derivatives). We then have that:\n\\begin{align*}\n    f^{(j)}(0) = \\begin{cases}\n        (-1)^m & \\text{if $j = 2m$}\n        \\\\ 0 & \\text{if $j = 2m + 1$}\n    \\end{cases}\n\\end{align*}\nIf we have the sum run from $j = 0$ to some $j = n$, let us then try to estimate the rest. Let $\\tilde{x} \\in (0, x)$. Then, letting the error term be represented by $\\e$, we have that:\n\\begin{align*}\n    \\e = \\abs{\\frac{f^{(n+1)}(\\tilde{x})}{(n+1)!}(x-x_0)^{n+1}} \\leq \\frac{\\abs{x}^{n+1}}{(n+1)!} \n\\end{align*}\nAnd we observe that $\\linf \\frac{\\abs{x}^{n+1}}{(n+1)!} = 0$ and hence the error $\\e$ goes to zero in the $n \\rightarrow \\infty$ limit. Therefore, the difference between $\\cos(x)$ and its Taylor polynomial vanishes quickly for any $x$, and the Taylor series converges for all $x$. Taking the limit of the sum, we have that:\n\\begin{align*}\n    f(x) = \\cos(x) = \\linf \\left(P_{n}(x) + \\frac{f^{(n+1)}(x_0)}{(n+1)!}(x - x_0)^{n+1}\\right) = \\sum_{j=0}^\\infty \\frac{(-1)^{2m}}{m!}x^{2m} = 1 - \\frac{x^2}{2} + \\frac{x^4}{4} - \\frac{x^6}{6} + \\ldots\n\\end{align*}\nA question of interest might be how many terms do we need in the Polynomial such that our error is less than $10^{-6}$, say, for estimating the value of $\\cos(\\frac{\\pi}{12})$. In other words, we want to find the $m$ such that:\n\\begin{align*}\n    \\frac{1}{2m!}\\left(\\frac{\\pi}{12}\\right)^{2m} \\leq 10^{-6}\n\\end{align*}\nRearranging, we require:\n\\begin{align*}\n    (2m)!\\left(\\frac{12}{\\pi}\\right)^{2m} > 10^6\n\\end{align*}\nMaking a table of the value of the LHS as a function of $m$, we have:\n\\begin{table}[htbp]\n    \\centering\\begin{tabular}{c|c}\n    $m$ & $(2m)!\\left(\\frac{12}{\\pi}\\right)^{2m}$\n    \\\\ \\hline\n    1 & $\\approx 29$\n    \\\\ 2 & $\\approx 5110$\n    \\\\ 3 & $\\approx 2.23 \\times 10^{6}$\n    \\end{tabular}\n\\end{table}\nSo we see that three terms are sufficient for a good approximation in this case (and as stated before, the series converges very quickly)!\n\nA natural question of interest is the convergence of the sum in the $N \\rightarrow \\infty$ limit, that is, the convergence of the power series $\\sum_{n = 0}^\\infty \\frac{f^{(n)}(x_0)}{n!}(x - x_0)^n$. We are also interested are interested for when $f(x) = \\sum_{n = 0}^\\infty \\frac{f^{(n)}(x_0)}{n!}(x - x_0)^n$ holds (that is, when is a function equal to its Taylor series)? These turn out to be distinct questions; in particular, there are functions whose power series converge for all $x$ but are equal to their power series nowhere (except at $x_0$ where equality must hold). This motivates the following definition:\n\\begin{ndef}{: Analyticity}{}\n    A function $f$ is \\textbf{analytic} if $f(x) = \\sum_{n=0}^\\infty \\frac{f^{(n)}(x_0)}{n!}(x - x_0)^n$ in a neighbourhood of $x_0$.\n\\end{ndef}\n\\noindent To motivate this definition, it will help to study a function which is \\textit{not} analytic. Consider the function:\n\\begin{align*}\n    f(x) = \\begin{cases}\n        \\exp(-\\frac{1}{x}) & x > 0\n        \\\\ 0 & x \\leq 0\n    \\end{cases}\n\\end{align*}\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}\n        \\draw[latex-latex, very thick] (-2, 0) -- (2, 0);\n        \\draw[-latex, very thick] (0, 0) -- (0, 2);\n        \\draw[<-, blue, thick] (-1.5, 0) -- (0.02, 0);\n        \\draw[->, blue, thick, smooth, samples = 100, domain=0.01:1.5, variable = \\x] plot(\\x, {exp(-1/\\x)});\n    \\end{tikzpicture}\n    \\caption{Plot of $f$.}\n    \\label{fig23}\n\\end{figure}\n\n\\noindent $f$ is continuous everywhere by construction. It is infinitely differentiable at $x = 0$, but it is only equal to its Taylor series around $x_0 =0$ for $x \\leq 0$. To see this, we observe that:\n\n\\begin{align*}\n    f'(x) = \\frac{1}{x^2}\\exp(-\\frac{1}{x})\n\\end{align*}\n\\begin{align*}\n    f^{(n)}(x) = \\frac{P_n(x)}{x^{2n}}\\exp(-\\frac{1}{x})\n\\end{align*}\nWe have that $f^{(n)}(x) \\rightarrow 0$ as $x \\rightarrow 0$ for all $n$ as the exponential dominates the polynomial singularity. We hence have that $f \\in C^\\infty$. The taylor polynomial at $x_0 = 0$ however, as we have that $f(0) = 0$ and $f^{(n)}(0) = 0$, leading to:\n\\begin{align*}\n    \\sum_{n=0}^N \\frac{f^{(n)}(0)}{n!}x^n = 0\n\\end{align*}\nfor all $N$. We therefore have that the series converges for all $x$, but is only equal to $f$ for $x \\leq 0$; hence it is not analytic (as there exists no neighbourhood around $x_0= 0$ for which $f$ is equal to its Taylor series). \n\nWe now consider a function $\\chi(x)$ defined as $\\chi(x) = \\frac{f(x)}{f(x) + f(1 - x)}$. This function is alsoz continuous, its denominator is never zero, and $\\chi \\in C^\\infty$. We observe that $\\chi(x) = 0$ for $x \\leq 0$ and $\\chi(x) = 1$ for $x \\geq 1$, and overall the function looks much like a step function:\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}\n        \\draw[latex-latex, very thick] (-2, 0) -- (2, 0);\n        \\draw[-latex, very thick] (0, 0) -- (0, 2);\n        \\draw[<-, blue, thick] (-1.5, 0) -- (0.02, 0);\n        \\draw[blue, smooth, samples = 100, domain=0.01:0.99, variable = \\x, thick] plot(\\x, {exp(-1/\\x)/(exp(-1/\\x) + exp(-1/(1-\\x)))});\n        \\draw[blue, ->, thick] (0.98, 1) -- (1.5, 1);\n    \\end{tikzpicture}\n    \\caption{Plot of $\\chi$.}\n    \\label{fig24}\n\\end{figure}\nIndeed, this function can be used as a ``cutoff''/``switch'' function that behaves much like a step function (except it is infinitely differentiable).\n\nA question becomes whether such a function could be analytic. The answer turns out to be no, and the proof we leave as an exercise. As a sketch, consider an analytic function $g$ such that $g(x) = 0$ for $x \\leq x_0$ and $g(x) \\neq 0$ for $x > x_0$. One can derive a contradiction by considering the Taylor series expansion about $x_0$ and then using the assumed analyticity of $g$. \n\nNote that in a sense, Taylor's Theorem is the culmination of a sequence of theorems we have proven in the course. Roughly, the sequence was as follows:\n\\begin{enumerate}[1)]\n    \\item $f: X \\mapsto Y$ and $K \\subset X$, then $f(K)$ compact (Theorem \\ref{thm:4.14})\n    \\item Extreme Value Theorem: If $f: X \\mapsto \\RR$ with $f$ continu$(X, \\tau)$ and $(Y, \\rho)$ ous and $K$ compact, then $f$ realizes its supremum and infimum on $K$. (Theorem \\ref{thm:4.16})\n        \n    \\item Rolle's Theorem\n    \\item Mean Value Theorem (Theorem \\ref{thm:5.10})\n    \\item Taylor's Theorem (Theorem \\ref{thm:5.15})\n\\end{enumerate}\nA question that arises is could we have gone through this sequence of proofs with just the rational numbers ($\\QQ$)? The intuitive answer is no, but it may be interesting to see where along this chain the logic breaks down.\n\nThe first step that looks immediately questionable is step 2; the supremum/infimum is not well-defined for all subsets of $\\QQ$, so we might be able to find a breakdown there. To this end, we consider the set $A = \\set{q \\in \\QQ: q > 0, q^2 < 2}$ that arises in Example \\ref{exam:1.1a} and try to find a function $f: K \\mapsto \\QQ$ with $K \\subset \\QQ$ compact such that $f(K) = A$. An idea would be to try $f(x) = \\sqrt{x}$, with $K = \\set{q \\in \\QQ: \\exists r: r^2 = q} \\cap [0, 2]$ but this doesn't work as $K$ is not compact. Trying another attempt, $K = [1, 2] \\cap \\QQ$ with $f(x) = \\sin(x)$ does not work either as $\\sin(x)$ is not necessarily rational, and moreover, $[1, 3] \\cap \\QQ$ is not a compact set as not all Cauchy sequences in $S$ converge! Another attempt would be $K = [1, 2] \\cap \\QQ = X$ with $f(q) = \\abs{q^2 - 2}$ where it would seem as though $f(K) = \\set{r \\in \\QQ: 0 < r \\leq 2}$ provides a good counterexample, but this fails for the same reason as $K$ is not compact. Finding a valid counterexample for the EVT is therefore difficult. \n\nAn easier break along the chain to find is with Rolle's Theorem. One can consider the function $f(x) = x^2 - 2$ which can break the Intermediate value theorem as $0$ is not contained in the image if the domain is $\\QQ$. We can dress this up to construct a counterexample for Rolle's Theorem.\n\n\\subsection{Local Behavior of Functions}\n\\begin{ntheorem}{: Second Derivative Test}{}\n    Suppose $f \\in C^{3}(I)$ where $I$ is a neighbourhood of $x_0$. Furthermore, suppose that $f'(x_0) = 0$. If $f''(x_0) > 0$, then $x_0$ is a local minimum. Conversely, if $f''(x_0) < 0$, then $x_0$ is a local maximum.\n\\end{ntheorem}\n\\begin{nproof}\n    By Taylor's Theorem (Theorem \\ref{thm:5.15}), if we let $x = x_0 + h$ for $h > 0$, there exists some $\\tilde{x} = x_0 + \\lambda h$ with $\\lambda \\in (0, 1)$ such that:\n    \\begin{align*}\n        f(x) = f(x_0) + f'(x_0)(x - x_0) + \\frac{1}{2}f''(x_0)(x - x_0)^2 + \\frac{1}{6}f^{(3)}(\\tilde{x})(x - x_0)^3\n    \\end{align*}\n    Using that $f'(x_0) = 0$, we have:\n    \\begin{align*}\n        f(x) - f(x_0) = h^2\\left(\\frac{1}{2}f''(x_0) + \\frac{1}{6}f^{(3)}(x_0 + \\lambda h) h\\right)\n    \\end{align*} \n    Let $0 < \\e < \\abs{\\frac{1}{2}f''(x_0)}$. Then, by the assumed continuity of $f^(3)$, we have that there exists $\\delta > 0$ such that $\\abs{h} < \\delta$ implies $\\abs{\\frac{1}{6}f^{(3)}(x_0 + \\lambda h)h} < \\e$. Hence, for sufficiently small $h$, we have that:\n    \\begin{align*}\n        \\sgn\\left(f(x) - f(x_0)\\right) = \\sgn(f''(x_0))\n    \\end{align*}\n    So we conclude that if $f'(x_0) = 0$ and $f''(x_0) > 0$ then $x_0$ is a local minimum, and if $f''(x_0) < 0$, then $x_0$ is a local maximum. \\qed\n\\end{nproof}\n\n\\begin{ndef}{: Convex Functions}{}\n    Let $f: (a, b) \\mapsto \\RR$ is \\textbf{convex} if for all $x, y \\in (a, b)$ with $a < x < y < b$ and for all $\\lambda \\in (0, 1)$,\n    \\begin{align*}\n        f(\\lambda x + (1 - \\lambda)y) \\leq \\lambda f(x) + (1 - \\lambda)f(y)\n    \\end{align*}\n\\end{ndef}\n\\noindent Note that an alternative definition of convexity is that for any $x, y$ with $x < y$, the function evaluated at some point $z \\in (x, y)$ will always be below the average of the function at $x, y$. That is:\n\\begin{align*}\n    f(z) \\leq \\frac{f(x) + f(y)}{2}\n\\end{align*}\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale=2]\n        \\draw[-latex, very thick] (-2.5, 0) -- (-2.5, 2);\n        \\draw[-latex, very thick] (-2.5, 0) -- (-0.5, 0);\n        \\draw[] (-1.5, 0.5) parabola (-2, 1.5);\n        \\draw[] (-1.5, 0.5) parabola (-1, 1.5);\n        \\filldraw[] (-2, 1.5) circle (1pt);\n        \\filldraw[] (-1, 1.5) circle (1pt);\n        \\draw[] (-2, 0) -- (-2, -0.15);\n        \\node[below] at (-2, -0.15) {$a$};\n        \\draw[] (-1, 0) -- (-1, -0.15);\n        \\node[below] at (-1, -0.13) {$b$};\n        \\draw[] (-1.7, 0) -- (-1.7, -0.15);\n        \\node[below] at (-1.7, -0.16) {$x$};\n        \\draw[] (-1.15, 0) -- (-1.15, -0.15);\n        \\node[below] at (-1.15, -0.15) {$y$};\n        \\filldraw[] (-1.7, 0.66) circle (0.5pt);\n        %\\node[left] at (-2.5, 0.66) {$f(x)$};\n        \\filldraw[] (-1.15, 1) circle (0.5pt);\n        %\\node[left] at (-2.5, 1) {$f(y)$};\n        \\draw[dashed] (-1.7, 0.66) -- (-1.15, 1);\n        \\draw[-latex, very thick] (0.5, 0) -- (0.5, 2);\n        \\draw[-latex, very thick] (0.5, 0) -- (2.5, 0);\n        \\draw[] (1.5, 1.5) parabola (1, 0.5);\n        \\draw[] (1.5, 1.5) parabola (2, 0.5);\n        \\filldraw[] (1, 0.5) circle (1pt);\n        \\filldraw[] (2, 0.5) circle (1pt);\n        \\draw[] (1, 0) -- (1, -0.15);\n        \\node[below] at (1, -0.16) {$a$};\n        \\draw[] (2, 0) -- (2, -0.15);\n        \\node[below] at (2, -0.13) {$b$};\n        \\draw[] (1.3, 0) -- (1.3, -0.15);\n        \\node[below] at (1.3, -0.16) {$x$};\n        \\draw[] (1.85, 0) -- (1.85, -0.15);\n        \\node[below] at (1.85, -0.15) {$y$};\n        \\filldraw[] (1.3, 1.34) circle (0.5pt);\n        \\filldraw[] (1.85, 1) circle (0.5pt);\n        \\draw[dashed] (1.3, 1.34) -- (1.85, 1);\n    \\end{tikzpicture}\n    \\caption{Visualization of a convex and non-convex function. For the upwards facing parabola, the function (and hence all points $(\\lambda x + (1- \\lambda) y, f(\\lambda x + (1- \\lambda) y))$ for $\\lambda \\in (0, 1)$) always lies below the line connecting $(x, f(x))$ and $(y, f(y))$ for $a < x < y < b$ and hence it is convex. For the downwards facing parabola, this is no longer true and the function is not convex (it is instead\\textit{concave}).}\n    \\label{fig25}\n\\end{figure}\n\n\\noindent Another equivalent way of defining convexity is to say that $f$ is convex if and only if for all $a < s < t < y < b$:\n\\begin{align*}\n    \\frac{f(t) - f(s)}{t - s} \\leq \\frac{f(u) - f(t)}{u - t}\n\\end{align*}\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale=2]\n        \\draw[-latex, very thick] (0, 0) -- (0, 2);\n        \\draw[-latex, very thick] (0, 0) -- (2, 0);\n        \\draw[] (1, 0.5) parabola (0.5, 1.5);\n        \\draw[] (1, 0.5) parabola (1.5, 1.5);\n        \\filldraw[] (0.5, 1.5) circle (1pt);\n        \\filldraw[] (1.5, 1.5) circle (1pt);\n        \\draw[] (0.5, 0) -- (0.5, -0.15);\n        \\node[below] at (0.5, -0.16) {$a$};\n        \\draw[] (1.5, 0) -- (1.5, -0.15);\n        \\node[below] at (1.5, -0.13) {$b$};\n        \\draw[] (0.75, 0) -- (0.75, -0.15);\n        \\node[below] at (0.75, -0.16) {$s$};\n        \\draw[] (1.25, 0) -- (1.25, -0.15);\n        \\node[below] at (1.25, -0.17) {$u$};\n        \\draw[] (1, 0) -- (1, -0.15);\n        \\node[below] at (1, -0.14) {$t$};\n        \\filldraw[] (1, 0.5) circle (0.5pt);\n        \\filldraw[] (0.75, 0.755) circle (0.5pt);\n        \\filldraw[] (1.25, 0.755) circle (0.5pt);\n        \\draw[dashed] (0.75, 0.755) -- (1, 0.5);\n        \\draw[dashed] (1.25, 0.755) -- (1, 0.5);\n    \\end{tikzpicture}\n    \n    \\caption{Visualization of the alternative definition of convexity. For any $a < s < t < u < v$, the slope of the line segment joining $s$ and $t$ is less than the slope of the line segment joining $t$ and $u$.}\n    \\label{fig26}\n\\end{figure}\n\n\\begin{ntheorem}{}{}\n    \\begin{enumerate}[(a)]\n        \\item Assume that $f: (a, b) \\mapsto \\RR$ is convex. Then, $f$ is continuous.\n        \\item Assume that $f \\in C^1(a, b)$. Then, if $f$ is convex, $f'$ is increasing.\n        \\item Assume that $f \\in C^2(a, b)$. Then $f$ convex implies $f'' \\geq 0$. \n    \\end{enumerate}\n\\end{ntheorem}\n\\begin{nproof}\n    \\begin{enumerate}\n        \\item Let $[c, d] \\subset (a, b)$ and $a < c_1 < c < x < y < d < d_1 < b$. By convexity, we have that:\n        \\begin{align*}\n            \\frac{f(y) - f(x)}{y - x} \\leq \\frac{f(d) - f(y)}{d - y} \\leq \\frac{f(d_1) - f(d)}{d_1 - d}\n        \\end{align*}\n        and also that:\n        \\begin{align*}\n            \\frac{f(y) - f(x)}{y - x} \\geq \\frac{f(x) - f(c)}{x - c} \\geq \\frac{f(c) - f(c_1)}{c - c_1}\n        \\end{align*}\n        We therefore have that:\n        \\begin{align*}\n            \\set{\\abs{\\frac{f(y) - f(x)}{y - x}}: c < x < y < b} < M\n        \\end{align*}\n        for some $M \\in \\RR$. Therefore, $\\abs{f(y) - f(x)} < M\\abs{y - x}$ for all $x, y \\in (c, d)$. This holds for all $[c, d] \\subset (a, b)$, showing the continuity of $f$.\n        \\item Let $f$ be convex, and let $a < c < x < y < d < b$. Then, by convexity we have that:\n        \\begin{align*}\n            \\frac{f(x) - f(c)}{x - c} \\leq \\frac{f(y) - f(x)}{y - x} \\leq \\frac{f(d) - f(y)}{d - y}\n        \\end{align*}\n        Ignoring the central term in the inequality, and taking the limit as $x \\rightarrow c$ and $ y \\rightarrow b$, we have that:\n        \\begin{align*}\n            f'(c) \\leq f'(b)\n        \\end{align*}\n        So we conclude that $f'$ is increasing on $(a, b)$. \n        \\item If $f$ is convex, $f'$ is increasing by (b). Then, we have that for any $a < x < y < b$:\n        \\begin{align*}\n            \\frac{f(y) - f(x)}{y - x} \\geq 0\n        \\end{align*}\n        And hence taking $y \\rightarrow x$ we have that $f'(x) \\geq 0$. \\qed\n    \\end{enumerate}\n\\end{nproof}\n\n\\begin{ncorollary}{}{}\n    If $f \\in C^3(I)$ and $f'(x_0) = 0$ and $f''(x_0) \\neq 0$, $x_0$ is a local minimum if $f$ is convex in a neighbourhood of $x_0$. \n\\end{ncorollary}", "meta": {"hexsha": "48af8d51d5dc3872eb54bb858247369bdef1eccb", "size": 32756, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/ch5.tex", "max_stars_repo_name": "RioWeil/MATH320-321-Notes", "max_stars_repo_head_hexsha": "532c4bf12a8e4ea80a58a83508de05e1f121a79a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/ch5.tex", "max_issues_repo_name": "RioWeil/MATH320-321-Notes", "max_issues_repo_head_hexsha": "532c4bf12a8e4ea80a58a83508de05e1f121a79a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-10T23:18:29.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-25T17:05:30.000Z", "max_forks_repo_path": "Chapters/ch5.tex", "max_forks_repo_name": "RioWeil/MATH320-321-notes", "max_forks_repo_head_hexsha": "532c4bf12a8e4ea80a58a83508de05e1f121a79a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.7509578544, "max_line_length": 1064, "alphanum_fraction": 0.5757418488, "num_tokens": 12536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8652240930029117, "lm_q1q2_score": 0.7152909548115238}}
{"text": "\n\\subsection{Uniform cost search}\n\nModify BFS to prioritise cost not depth. expand node with lowest path cost. could be \"deep\".\n\nThis is the same as Dijkstra’s algorithm.\n\nCan do this in algo by using heaps\n\nInformed: No\n\nTime: \\(O(b^{?})\\)\n\nSpace: \\(O(b^{?})\\)\n\nComplete: Yes\n\nOptimal: Yes\n\n", "meta": {"hexsha": "85096f97cd8c5cc9c08396419c8e2a80a17ace9f", "size": 292, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/nodes/03-01-UCS.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/computer/nodes/03-01-UCS.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/computer/nodes/03-01-UCS.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.6, "max_line_length": 92, "alphanum_fraction": 0.6952054795, "num_tokens": 82, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7152909476292307}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath,amssymb}\n\\newcommand\\set[1]{\\left\\{#1\\right\\}}\n\n\\begin{document}\n\\section{Exercise 7}\n\nGiven 5 women and 9 men.\nLet $\\mathbb P(F)$ denote the probability that a female member is chosen.\nLet $\\mathbb P(F\\,|\\,F)$ denote the probability that a female member is chosen, given that one woman was already chosen before.\n\nWe assume independent events with uniform distribution when choosing members.\n\n\\subsection{$\\mathbb P(F)$}\n%\nIn 5 of 14 cases, the chosen member will be female.\n\\[ \\mathbb P(F) = \\frac{5}{14} \\]\n\n\\begin{verbatim}\ndef prob(s):\n  women, men = 5, 9\n  p = '1.0'\n  for x in s:\n    if x.upper() == 'F':\n      p += ' * ({} / {})'.format(women, men + women)\n      women -= 1\n    elif x.upper() == 'M':\n      p += ' * ({} / {})'.format(men, men + women)\n      men -= 1\n  return p\n\n# prob('FFMM')\n\\end{verbatim}\n\n\\subsection{$\\mathbb P(F|F)$}\n%\nAs one woman is chosen, we are left with $4$ out of $13$ cases.\n\\[ \\mathbb P(F|F) = \\frac{4}{13} \\]\n\n\\subsection{Probability that two women are chosen}\n%\n\\begin{align*}\n  &\\mathbb P(\\text{FFMM}) + \\mathbb P(\\text{FMFM}) + \\mathbb P(\\text{FMMF}) + \\mathbb P(\\text{MFFM}) + \\mathbb P(\\text{MFMF}) + \\mathbb P(\\text{MMFF}) \\\\\n  &= \\frac{5}{14} \\cdot \\frac{4}{13} \\cdot \\frac{9}{12} \\cdot \\frac{8}{11}\n  + \\frac{5}{14} \\cdot \\frac{9}{13} \\cdot \\frac{4}{12} \\cdot \\frac{8}{11}\n  + \\frac{5}{14} \\cdot \\frac{9}{13} \\cdot \\frac{8}{12} \\cdot \\frac{4}{11} \\\\\n  &+ \\frac{9}{14} \\cdot \\frac{5}{13} \\cdot \\frac{4}{12} \\cdot \\frac{8}{11}\n  + \\frac{9}{14} \\cdot \\frac{5}{13} \\cdot \\frac{8}{12} \\cdot \\frac{4}{11}\n  + \\frac{9}{14} \\cdot \\frac{8}{13} \\cdot \\frac{5}{12} \\cdot \\frac{4}{11} \\\\\n  &= \\frac{1440}{24024} + \\frac{1440}{24024} + \\frac{1440}{24024} + \\frac{1440}{24024} + \\frac{1440}{24024} + \\frac{1440}{24024} \\\\\n  &= 6 \\cdot \\frac{1440}{24024} = \\frac{8640}{24024} = \\frac{360}{1001}\n\\end{align*}\n\n\\subsection{Probability that three women are chosen}\n%\n\\begin{align*}\n  &\\mathbb P(\\text{FFFM}) + \\mathbb P(\\text{FFMF}) + \\mathbb P(\\text{FMFF}) + \\mathbb P(\\text{MFFF}) \\\\\n  &= \\frac{5}{14} \\cdot \\frac{4}{13} \\cdot \\frac{3}{12} \\cdot \\frac{9}{11}\n  + \\frac{5}{14} \\cdot \\frac{4}{13} \\cdot \\frac{9}{12} \\cdot \\frac{3}{11}\n  + \\frac{5}{14} \\cdot \\frac{9}{13} \\cdot \\frac{4}{12} \\cdot \\frac{3}{11}\n  + \\frac{9}{14} \\cdot \\frac{5}{13} \\cdot \\frac{4}{12} \\cdot \\frac{3}{11} \\\\\n  &= \\frac{540}{24024} + \\frac{540}{24024} + \\frac{540}{24024} + \\frac{540}{24024} \\\\\n  &= 4 \\cdot \\frac{540}{24024} = \\frac{2160}{24024} = \\frac{90}{1001}\n\\end{align*}\n\n\\subsection{Probability that two or three women are chosen}\n%\n\\[ \\frac{360}{1001} + \\frac{90}{1001} = \\frac{450}{1001} \\]\n\nThis corresponds to,\n\\[ \\frac{{5 \\choose 2} {8 \\choose 2}}{{14 \\choose 4}} + \\frac{{5 \\choose 3} {9 \\choose 1}}{{14 \\choose 4}} \\]\n\n\n\\end{document}\n", "meta": {"hexsha": "0444f76ab448db6210fa072fb5385dc8226ad96e", "size": 2830, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "probability_theory_practicals/ex7/solution.tex", "max_stars_repo_name": "prokls/math-lecture-notes", "max_stars_repo_head_hexsha": "d1a94e128d13ce4399a9cc55323b2f8e0d9494fd", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2015-11-25T01:49:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T14:47:36.000Z", "max_issues_repo_path": "probability_theory_practicals/ex7/solution.tex", "max_issues_repo_name": "prokls/math-lecture-notes", "max_issues_repo_head_hexsha": "d1a94e128d13ce4399a9cc55323b2f8e0d9494fd", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-05-22T07:56:03.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-02T09:32:40.000Z", "max_forks_repo_path": "probability_theory_practicals/ex7/solution.tex", "max_forks_repo_name": "prokls/math-lecture-notes", "max_forks_repo_head_hexsha": "d1a94e128d13ce4399a9cc55323b2f8e0d9494fd", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-03-24T14:42:30.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-25T11:00:11.000Z", "avg_line_length": 37.2368421053, "max_line_length": 153, "alphanum_fraction": 0.596819788, "num_tokens": 1129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264639, "lm_q2_score": 0.826711791935942, "lm_q1q2_score": 0.7152909459872729}}
{"text": "%\\newpage\nIn this chapter, we first introduce some widely used convolutional operations,  some examples of convolution filters and their performance, and then some popular convolutional neural network (CNN) models.\n\\section{Convolutional operations}\n\n\\subsection{Images as matrix}\\label{sec:functions}\nAn image can be viewed as a piecewise constant function on a grid.  Images with different\nresolutions can then be viewed as functions on grids of different\nsizes.  The use of such multiple-grids is a main technique used in the\nstandard multigrid method for solving discretized partial differential\nequations, and it can also be interpreted as a main ingredient used in\nconvolutional neural networks (CNN) for image calssification.\n\nAn image can be viewed as a function on a grid \\cite{krizhevsky2012imagenet} on \na rectangular  domain $\\Omega\\in \\mathcal R^2$.  Without loss of generality,\n we assume that the grid, $\\mathcal T$, is of size\n$$\nm=2^{s}, \\quad n=2^{t} \n$$\nfor some integers $s, t\\ge 1$.\nStarting from $\\mathcal T_1=\\mathcal T$,  we consider a sequence of\ncoarse grids with $J=\\min (s,t)$ (as depicted in Fig.~\\ref{mugrid-bi} with $J=4$):\n\\begin{equation}\n\\label{grids}\n\\mathcal T_1, \\mathcal T_2, \\ldots, \\mathcal T_J\n\\end{equation}\nsuch that ${\\cal T}_\\ell$ consist of $m_\\ell\\times n_\\ell$ grid\npoints, with \n\\begin{equation}\n\\label{mn-ell}\n m_\\ell=2^{s-\\ell+1},~~ n_\\ell=2^{t-\\ell+1}.   \n\\end{equation}\n\n\\begin{figure} \\label{mugrid-bi}\n\\begin{center}\n\\setlength{\\unitlength}{0.445mm}\n\\begin{picture}(45,45)(50,0)\n\\linethickness{0.1mm}\n\\multiput(-20,0)(2.5,0){17}{\\line(0,1){40}}\n\\multiput(-20,0)(0,2.5){17}{\\line(1,0){40}}\n\\multiput(28,0)(5,0){9}{\\line(0,1){40}}\n\\multiput(28,0)(0,5){9}{\\line(1,0){40}}\n\\multiput(77,0)(10,0){5}{\\line(0,1){40}}\n\\multiput(77,0)(0,10){5}{\\line(1,0){40}}\n\\multiput(126,0)(20,0){3}{\\line(0,1){40}}\n\\multiput(126,0)(0,20){3}{\\line(1,0){40}}\n\\end{picture}\n\\setlength{\\unitlength}{0.5mm}\n\\end{center}\n$$ \n\\hskip0.05 in \\mathcal T_1\\hskip 0.7in \\mathcal T_2\\hskip 0.7in  \\mathcal T_3\\hskip 0.7in \\mathcal T_4\n$$\n\\caption{multilevel grids for piecewise constant functions (images)}\n\\end{figure}\nHere, please note that each element in this grid can be viewed as \na pixel or an image or an element in a matrix.\n\n\n\\subsection{Convolution operation with one channel}\nFor simplicity of exposition, we denote \n\\begin{equation}\\label{eq:size_f}\nm = m_1 = 2^{s},  \\quad n = n_1 = 2^t.\n\\end{equation}\nRecall the definition of convolution in Definition \\ref{def:convolution}.  In image processing, a kernel, convolution matrix, or mask is a small matrix, denoted by $K$ below. It is used for blurring, sharpening, embossing, edge detection, and more. This is accomplished by doing a convolution between a kernel and an image, denoted by $g$ below. Convolution is the process of adding each element of the image to its local neighbors, weighted by the kernel.\n\\begin{definition}\nA convolution defined on $\\mathbb{R}^{m\\times n}$ is a linear mapping \n$K\\ast: \\mathbb{R}^{m\\times n}\\mapsto \\mathbb{R}^{m\\times n}$ defined with padding,  \nfor any $g \\in \\mathbb{R}^{m\\times n}$ by:\n%We first consider $\\theta$ a convolution operator (with stride $1$) \n%and padding:\n\\begin{equation}\\label{con01}\n[K \\ast g]_{i,j} = \\sum_{p,q=-k}^k K_{p, q} g_{i + p, j + q}, \\quad i=1:m, j = 1:n.\n\\end{equation}\n\\end{definition}\nThe convolution maps the original  image $g$ to a modified one $K\\ast g$ with the same size, and each element $[K \\ast g]_{i,j}$ in the resulting image $K\\ast g$ is a weighted average of elements in the original image $g$ with weights $K_{p,q}$.\nThe weights in \\eqref{con01} constitute  a kernel matrix\n\\begin{equation}\nK \\in \\mathbb{R}^{(2k+1) \\times (2k+1)},\n\\end{equation}\nwhere $k$ is often taken as a small integer. \nHere we note that the indices for the entries in $K$ are given in a special way. \nFor example, if $k=1, K\\in \\mathbb R^{3\\times 3}$, and \n$$\nK=\\begin{pmatrix}\n\tK_{-1,-1} &K_{-1,0} &K_{-1,1} \\\\\n\tK_{0,-1} &K_{0,0} &K_{0,1} \\\\\n\tK_{1,-1} &K_{1,0} &K_{1,1} \\\\\n\t\\end{pmatrix},\n$$\nfor we may have the following 2D Laplacian kernel\n\\begin{equation}\\label{key}\nK=\\begin{pmatrix}\n0 &-1 &0\\\\\n-1 &4&-1 \\\\\n0 &-1 &0 \\\\\n\\end{pmatrix}.\n\\end{equation}  \nHere padding means how $ g_{i+ p, j + q}$ is defined\nwhen $(i+ p, j + q)$ is out of $1:m$ or $1:n$. \nThe following three choices are often used\n\\begin{equation}\\label{eq:padding}\ng_{i + p, j + q} = \\begin{cases}\n0,  \\quad &\\text{zero padding}, \\\\\nf_{(i + p)\\pmod{m}, (s + q)\\pmod{n}},  \\quad &\\text{periodic padding}, \\\\\nf_{|i-1 +p|, |j -1  +q|},  \\quad &\\text{reflected padding}, \\\\\n\\end{cases}\n\\end{equation}\nif \n\\begin{equation}\ni + p \\notin \\{1, 2, \\dots, m\\} ~\\text{or} ~  j+ q \\notin \\{1, 2, \\dots, n\\}.\n\\end{equation}\nHere $ d \\pmod{m} \\in \\{1, \\cdots, m\\} $  means the remainder when $d$ is divided by $m$.\n\nHere is a diagram for convolution with one channel (and also stride one).\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.5\\textwidth]{figures/Conv0padding}\n\t\\end{center}\n\\end{figure}  \nIn \\cite{bramble1977higher}, the authors show that by ``averaging\" the values of \nthe finite element solution $u_h$ of elliptic problem using convolution  \n in the neighborhood of a point $x$ they may construct an approximation to the true solution $u(x)$ \n which is often a better approximation than $u_h(x)$ itself. The ``averaging\" operator showed in \\cite{bramble1977higher} \n is just the convolution operator defined here and does not depend on the specific elliptic operator involved.\n\n\n\\subsection{Convolution with stride (one channel)}\nRecall the definition  of convolution with stride $2$ in Definition \\ref{def:convolution2}, namely,\nfor $g \\in \\mathbb{R}^{m\\times n}$, convolution with stride $2$ is defined as \n\\begin{equation}\\label{stride_2}\n[K \\ast_2 g]_{i,j} = \\sum_{p,q=-k}^k K_{p,q} g_{2i + p-1, 2j + q-1},  \n\\quad i = 1: \\lfloor \\frac{m+1}{2}\\rfloor , j = 1: \\lfloor \\frac{n+1}{2} \\rfloor.\n\\end{equation} \nNote that the convolution with stride $2$ maps the original image with size $2m\\times 2n$ to a new one with smaller size $m\\times n$, namely lower resolution.\n\\begin{lemma}\nThe convolution with stride $2$ can be written as:\n\\begin{equation}\\label{eq:convstride_2_1}\nK \\ast_2 g = \\mathcal S( K\\ast g),\n\\end{equation}\nwhere $\\mathcal S$ is a stride operator defined by:\n\\begin{equation}\\label{eq:strideopdim}\n\\mathcal S: \\mathbb{R}^{m \\times n} \\mapsto \\mathbb{R}^{\\frac{m+1}{2} \\times \\frac{n+1}{2}},\n\\end{equation}\nwith\n\\begin{equation}\\label{eq:strideop}\n[\\mathcal S(g)]_{i,j} = g_{2i-1, 2j-1}, \\quad i = 1: \\lfloor \\frac{m+1}{2}\\rfloor , j = 1: \\lfloor \\frac{n+1}{2} \\rfloor.\n\\end{equation}\n\\end{lemma}\n\n\n\\begin{example}\nThe so-called average pooling with kernel size $3 \\times 3$ and stride 2 means\n\\begin{equation}\nK \\ast_2\\quad \\mbox{with}\\quad\nK = \\frac{1}{9} \n\\begin{pmatrix}\n1 & 1 & 1 \\\\\n1 & 1 & 1 \\\\\n1 & 1 & 1\n\\end{pmatrix}.\n\\end{equation}\n\\end{example}\n\n\n\n\n\n\n\nWe note that, in general, for any given integer $s\\ge1$, a convolution with stride\n$s$ for $g \\in \\mathbb{R}^{m\\times n}$  can be  defined as:\n\t\\begin{equation}\\label{stride}\n\t[K \\ast_s g]_{i,j} = \\sum_{p,q=-k}^k K_{p,q} g_{s(i-1) + p+1, s(j-1) + q+1},  \n\t\\quad i = 1: \\lfloor  \\frac{m+1}{s}\\rfloor, j = 1: \\lfloor  \\frac{n+1}{s}\\rfloor.\n\t\\end{equation}\n\tHere $ \\lfloor  \\frac{m}{s}\\rfloor$ denotes the biggest integer that less than $\\frac{m}{s}$. Similarly, the convolution with stride $s$ maps the original image with size $sm\\times sn$ to a new one with smaller size $m\\times n$.\n\tThe following is a diagram for stride $2$.\n\\begin{figure}[H]\n\\begin{center}\n\t\\includegraphics[width=0.35\\textwidth]{figures/PoolingLayer1}\n\\end{center}\n\\end{figure}\n\n\\subsection{Convolutional operations with multi-channel}\nIn many applications, we need to deal with images with multiple channels. A typical example is the RGB image, where each RGB channel emphasizes different aspects of the original images. Then the inputs become a three-dimensional tensor with size $3\\times m\\times n$. We refer to this axis, with a size of 3, as the channel dimension. \n\nWhen the input data contain multiple channels, we need to construct a convolution kernel with the same number of input channels as the input data, so that it can perform cross-correlation with the input data. \nOne important class of linear mapping is the so-called convolution:\n$$\n\\theta: \\mathbb{R}^{c\\times m\\times n} \\mapsto \\mathbb{R}^{h\\times m\\times n},\n$$\nwhere $m\\times n$ is called the spatial dimension or resolution, $c$ and $h$ are corresponding\nto input and output channels. Let $f\\in \\mathbb{R}^{c\\times m\\times n}$ and the $t$-th channel $[f]_t \\in \\mathbb{R}^{m\\times n}$.\nThe operation is defined by \n\\begin{equation}\\label{conv-1}\n[\\theta(f)]_{s} = \\sum_{t=1}^{c}\\mathbf{K}_{s,t} \\ast [f]_t + b_s\n\\bm{1}  \\in \\mathbb{R}^{m\\times n}, \\quad s = 1:h,\n\\end{equation}\nwhere $\\bm{1}  \\in \\mathbb{R}^{m\\times n} $ is a \n$m\\times n$ matrix with all elements being $1$,\nand $\\mathbf{K}_{s,t}$ is a convolution operator which maps $ [f]_t\\in \\mathbb{R}^{m\\times n}$ to $[\\theta(f)]_{s} \\in \\mathbb{R}^{m\\times n}$.\n\\begin{equation}\\label{con1}\n[\\mathbf{K}_{s,t} \\ast [f]_t]_{i,j} = \\sum_{p,q=-k}^k K_{s,t; p,q} f_{t; i + p, j + q}, \\quad i=1:m, j = 1:n.\n\\end{equation}\nThe coefficients kernel $\\mathbf{K}_{s,t}$ in \\eqref{con1} constitute  a kernel matrix\n\\begin{equation}\n\\mathbf{K}_{s,t} \\in \\mathbb{R}^{(2k+1) \\times (2k+1)},\n\\end{equation}\nwhere $k$ is often taken as small integers. \n\nHere a more compact notation for multi-channel convolution can be written as\n\\begin{equation}\n\\theta(f) = \\mathbf{K} \\ast f + \\mathbf b\n\\end{equation}\nwhere\n\\begin{equation}\\label{key}\nf = \\begin{pmatrix}\n[f]_1 \\\\\n[f]_2 \\\\\n\\vdots \\\\\n[f]_c\n\\end{pmatrix},\n\\quad \n\\mathbf{K} = \\begin{pmatrix}\nK_{1,1} & K_{1,2} & \\cdots & K_{1,c} \\\\\nK_{2,1} & K_{2,2} & \\cdots & K_{2,c} \\\\\n\\vdots & \\vdots & \\ddots& \\vdots \\\\\nK_{h,1} & K_{h,2} & \\cdots & K_{h,c} \n\\end{pmatrix}, \n\\quad \n\\mathbf b = \\begin{pmatrix}\nb_1 \\bm 1\\\\\nb_2 \\bm 1\\\\\n\\vdots \\\\\nb_h \\bm 1\\\\\n\\end{pmatrix}=b\\otimes \\bm 1.\n\\end{equation}\n\nFurthermore, we have the following natural extension of convolution with\nstride for multi-channel by \n\\begin{equation}\\label{conv-1}\n[\\theta(f)]_{s} = \\sum_{t=1}^{c}\\mathbf{K}_{s,t} \\ast_2 [f]_t + b_s\n\\bm{1}  \\in \\mathbb{R}^{\\tilde m \\times \\tilde n}, \\quad s = 1:h,\n\\end{equation}\nwhere\n\\begin{equation}\\label{key}\n\\tilde m = \\lfloor \\frac{m+1}{2}\\rfloor , \\quad \\tilde n = \\lfloor \\frac{n+1}{2} \\rfloor, \n\\end{equation}\n\n\n\n\n\n\n\\subsection{Pooling operation in CNNs}\nWhen processing images, we want to  gradually reduce the spatial resolution of our hidden representations, aggregating information so that the higher up we go in the network, the larger the receptive field (in the input) to which each hidden node is sensitive.\n\nFinally, we introduce another type of important operation in CNNs -- pooling.\nThe key purpose for pooling operator is to reduce the spatial resolution of images (features) in a typical CNN models.\nBasically, pooling is an operator\n\\begin{equation}\\label{key}\nT: \\mathbb{R}^{c_1\\times m_1\\times n_1} \\mapsto \\mathbb{R}^{c_2 \\times m_2\\times n_2}.\n\\end{equation}\nwhere \n\\begin{equation}\\label{key}\nm_2 = \\lfloor \\frac{m+1}{s}\\rfloor , \\quad n_2 = \\lfloor \\frac{n+1}{s} \\rfloor, \n\\end{equation}\nfor any choice of $c_2 \\ge 1$. Here $s$ is also called the stride in pooling operations. There are generally two types of pooling:\n\n\t\\paragraph{Convolution with stride $s$ as pooling} In this case, it often happens that\n\t\\begin{equation}\\label{key}\n\tT = R \\ast_s, \\quad  (s = 2 \\text{ for the main case }).\n\t\\end{equation}\n\tHere $R$ can be learned or fixed such as average pooling as we discussed before.\n\t\n\t\\paragraph{Nonlinear pooling} The most commonly used nonlinear pooling is called max-pooling, \n\ta max pooling with kernel size $(2k+1)\\times (2k+1)$ and stride $s$ is is defined as\n\t\\begin{equation}\\label{key}\n\t[R_{\\rm max}(f)]_{t; i,j} = \\max \\{ f_{t;s(i-1) + p+1, s(j-1) + q+1} ~|~ -k \\le p,q \\le k\\},\n\t\\end{equation}\n\there $t$ means channel and $c_2 = c_1$ in this case.\n\nHere is an example for max-pooling with kernel size $3\\times3$ and stride $3$.\n\\begin{figure}[H]\n\\begin{center}\n\t\\includegraphics[width=0.5\\textwidth]{6DL/figures/3by3MaxPooling}\n\\end{center}\n\\end{figure}\n\n\\endinput\n\n\\subsection{Deconvolution with one channel}\nFor any linear mapping $\\mathcal C: \\mathbb{R}^{m\\times n} \\mapsto \\mathbb{R}^{m'\\times n'}$, \nits transpose is the unique linear mapping $\\mathcal C^\\top: \\mathbb{R}^{m'\\times n'} \\mapsto \\mathbb{R}^{m\\times n}$\nsatisfying \n$$\n(\\mathcal C^\\top u, v)_{l^2}=(u, \\mathcal C v)_{l^2}~~~\\forall~u\\in \\mathbb{R}^{m'\\times n'} , v\\in \\mathbb{R}^{m\\times n}\n$$\nAssociated with any kernel $K$, a deconvolution is defined as the transpose of convolution \nwith stride $2$ with respect to the $l^2$-inner product as:\n\\begin{equation}\\label{eq:def_deconv}\n(u, K \\ast_2^\\top v)_{l^2}=(K \\ast_2 u, v)_{l^2},\n\\end{equation}\nwith\n\\begin{equation}\nu \\in \\mathbb{R}^{m \\times n} \\quad \\text{and} \\quad v \\in \\mathbb{R}^{\\frac{m+1}{2} \\times \\frac{m+1}{2}}.\n\\end{equation}\n\n\\begin{lemma}\\label{lemm:tilde-K}\n\tFor any $K \\in \\mathbb{R}^{(2k+1) \\times (2k+1)}$,\n\t\\begin{equation}\\label{eq:}\n\tK\\ast_2^\\top = {\\tilde K}\\ast \\mathcal S^\\top,\n\t\\end{equation}\n\twhere $\\tilde K$ is defined as\n\t\\begin{equation}\\label{eq:def_tildeK}\n\t\\tilde K_{p,q} = K_{-p, -q}, \\quad p,q = -k:k.\n\t\\end{equation}\n\tIntuitively, if we take $K_{0,0}$ as the center for the convolutional kernel $K$, \n\tthen $\\tilde K$ is the central symmetry of $K$. \n\tIn 2D case, it can also be understood as the rotation of $\\pi$ with respect to\n\tthe center $K_{0,0}$.\n\\end{lemma}\n\nRecalling the definition of deconvolution in \\eqref{eq:def_deconv}, we have\n\\begin{equation}\\label{eq:op_deconv}\n\\begin{aligned}\n(u,  K \\ast_2^\\top v)_{l^2} &= (K \\ast_2 u, v)_{l^2} = (\\mathcal S \\mathcal C_K u, v)_{l^2} \\\\\n&= (u,  \\mathcal C^\\top_K \\mathcal S^\\top v)_{l^2},\n\\end{aligned}\n\\end{equation}\nwith definition\n\\begin{equation}\\label{eq:de_stride_dim}\n\\mathcal S^\\top:   \\mathbb{R}^{\\frac{m+1}{2} \\times\\frac{n+1}{2}} \\mapsto \\mathbb{R}^{m\\times n},\n\\end{equation}\nand \n\\begin{equation}\\label{eq:de_stride}\n[\\mathcal S^\\top (f)]_{i,j} = \n\\begin{cases}\n0 \\quad &\\text{if i or j is even}, \\\\\nf_{i/2, j/2}, \\quad &\\text{else}.\n\\end{cases}\n\\end{equation}\n\nThus to say, we have the simple version of the deconvolution for $K \\ast $ as\n\\begin{equation}\\label{eq:simple_deconv}\nK \\ast_2^\\top v = \\mathcal C_K^\\top \\circ \\mathcal S^\\top (v) = \\mathcal C_{\\tilde K} \\circ \\mathcal S^\\top (v) = \\tilde K \\ast \\mathcal S^\\top (v),\n\\end{equation}\nthus to say\n\\begin{equation}\\label{eq:final}\nK \\ast_2^\\top  = \\tilde K \\ast \\mathcal S^\\top.\n\\end{equation}\n\nIn short, we have the next decomposition\n\\begin{itemize}\n\t\\item convolution with stride = stride $ \\circ$ convolution,\n\t\\item deconvolution with stride  = transposed convolution $\\circ$ transposed stride = convolution with the central symmetry of original kernel $\\circ$ transposed stride.\n\\end{itemize}\n\n\\begin{theorem}\\label{thm:deconv_op}\n\t\n\tLet us consider \n\t\\begin{equation}\n\tK=(K_{p,q}),~~p,q = -1, 0, 1.\n\t\\end{equation}\n\tThen we have \n\t$$\n\tK \\ast_2^\\top v = \\tilde K \\ast \\mathcal S^\\top (v).\n\t$$\n\tAs in \\eqref{eq:de_stride} and the Lemma \\ref{lemm:tilde-K}, we have the \n\tfinal version is \n\t\\begin{equation}\n\t\\label{eq:7}\n\t[K \\ast_2^\\top v ]_{2i,2j}=  K_{0,0}v_{i,j},\n\t\\end{equation}\n\twith \n\t\\begin{equation}\n\t\\label{eq:9}\n\t[K \\ast_2^\\top v ]_{2i-1, 2j} = K_{0,1}v_{i-1,j} + K_{0,-1}v_{i,j}, \\quad \n\t[K \\ast_2^\\top v ]_{2i, 2j-1} = K_{1,0}v_{i,j} + K_{-1,0}v_{i,j-1},\n\t\\end{equation}\n\tand\n\t\\begin{equation}\n\t%\\begin{tiny}\n\t%{\\scriptsize \n\t[K \\ast_2^\\top v ]_{2i-1, 2j-1}  =  \n\tK_{1,1}v_{i,j} + K_{-1,1}v_{i-1,j} + K_{1,-1}v_{i,j-1} + K_{-1,-1}v_{i-1,j-1}.\n\t%\\end{tiny}\n\t%}\n\t\\end{equation}\n\\end{theorem}\n\\begin{remark}\n\tDeconvolution can obviously be also defined for general stride $s$, but we believe it is sufficient to use $s=2$\n\tin most applications. \n\\end{remark}\n\n", "meta": {"hexsha": "a7f73b316c6874232870b3c5d30c5f46feba31e5", "size": 15957, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ConvolutionalOperator.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/ConvolutionalOperator.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/ConvolutionalOperator.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.3974683544, "max_line_length": 456, "alphanum_fraction": 0.6842138247, "num_tokens": 5841, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331751, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7152656963748156}}
{"text": "\\section{Triple Integrals}\\label{sec:TripleIntegrals}\n\nIt will come as no surprise that we can also do triple\nintegrals---integrals over a three-dimensional region. The simplest\napplication allows us to compute volumes in an alternate way.\\index{triple integral}\n\nTo approximate a volume in three dimensions, we can divide the\nthree-dimensional region into small rectangular boxes, each \n$\\Delta x\\times\\Delta y\\times\\Delta z$ with volume\n$\\Delta x\\Delta y\\Delta z$. Then we add them all up and take the\nlimit, to get an integral:\n\\[\\int_{x_0}^{x_1}\\int_{y_0}^{y_1}\\int_{z_0}^{z_1} dz\\,dy\\,dx.\\]\nOf course, if the limits are constant, we are simply computing the\nvolume of a rectangular box.\n\n\\begin{example}{Volume of a Box}{VolumeBox}\nCompute the volume of the box with opposite corners at $(0,0,0)$ and $(1,2,3)$.\n\\end{example}\n\\begin{solution}\nWe use an integral to compute the volume of the box:\n\\[\\int_0^1\\int_0^2\\int_0^3\ndz\\,dy\\,dx=\\int_0^1\\int_0^2\\left.z\\right|_0^3 \\,dy\\,dx\n=\\int_0^1\\int_0^2 3\\,dy\\,dx\n=\\int_0^1 \\left.3y\\right|_0^2 \\,dx\n=\\int_0^1 6\\,dx = 6.\n\\]\n\\end{solution}\n\nOf course, this is more interesting and useful when the limits are not\nconstant. \n\n\\begin{example}{Volume of a Tetrahedron}{VolumeTetrahedron}\nFind the volume of the tetrahedron with corners at $(0,0,0)$,\n$(0,3,0)$, $(2,3,0)$, and $(2,3,5)$.\n\\end{example}\n\\begin{solution}\nThe whole problem comes down to correctly describing the region by\ninequalities:\n$0\\le x\\le 2$, $3x/2\\le y\\le 3$, $0\\le z\\le 5x/2$.\nThe lower $y$ limit comes from the equation of the line\n$y=3x/2$ that forms one edge of the tetrahedron in the $x$-$y$ plane;\nthe upper $z$ limit comes from the equation of the plane $z=5x/2$ that\nforms the ``upper'' side of the tetrahedron; see Figure~\\ref{fig:tetrahedron}. \nNow the volume is \n\\begin{align*}\n\\int_0^2\\int_{3x/2}^3\\int_0^{5x/2}dz\\,dy\\,dx\n&=\\int_0^2\\int_{3x/2}^3\\left.z\\right|_0^{5x/2} \\,dy\\,dx\t\\\\\n&=\\int_0^2\\int_{3x/2}^3 {5x\\over2}\\,dy\\,dx\t\\\\\n&=\\int_0^2 \\left.{5x\\over2}y\\right|_{3x/2}^3 \\,dx\t\\\\\n&=\\int_0^2 {15x\\over2}-{15x^2\\over4}\\,dx\t\\\\\n&=\\left. {15x^2\\over4}-{15x^3\\over12}\\right|_0^2\t\\\\\n&=15-10=5.\n\\end{align*}\n\\end{solution}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <1.5truecm,1.5truecm>\n\\setplotarea x from 0 to 2.1, y from -1.1 to 1.1\n\\put {\\hbox{\\epsfxsize6cm\\epsfbox{images/tetrahedron.eps}}} at 0 0\n\\endpicture}}\n\\caption{A tetrahedron.}\n\\label{fig:tetrahedron}\n\\end{figure}\n\nPretty much just the way we did for two dimensions we can use triple\nintegration to compute mass, center of mass, and various average quantities.\n\n\\begin{example}{Average Temperature in a Cube}{AvgTempCube}\nSuppose the temperature at a point is given by\n$T=xyz$. Find the average temperature in the cube with opposite\ncorners at $(0,0,0)$ and $(2,2,2)$.\n\\end{example}\n\\begin{solution}\nIn two dimensions we add up the temperature at ``each'' point and\ndivide by the area; here we add up the temperatures and divide by the\nvolume, $8$:\n\\begin{align*}\n{1\\over8}\\int_{0}^2\\int_{0}^2\\int_{0}^2 xyz\\,dz\\,dy\\,dx\n&={1\\over8}\\int_{0}^2\\int_{0}^2\\left.{xyz^2\\over2}\\right|_0^2\\,dy\\,dx\n={1\\over16}\\int_{0}^2\\int_{0}^2 xy\\,dy\\,dx\t\\\\\n&={1\\over4}\\int_{0}^2\\left.{xy^2\\over2}\\right|_0^2\\,dx\n={1\\over8}\\int_{0}^2 4x\\,dx\n={1\\over2}\\left.{x^2\\over2}\\right|_0^2\n=1.\n\\end{align*}\n\\end{solution}\n\n\\begin{example}{Mass \\& Center of Mass of Tetrahedron}{3dcenterofmass}\nSuppose the density of an object is given by $xz$, and the\nobject occupies the tetrahedron with corners\n$(0,0,0)$, $(0,1,0)$, $(1,1,0)$, and $(0,1,1)$. Find the mass and\ncenter of mass of the object.\n\\end{example}\n\\begin{solution}\nAs usual, the mass is the integral of density over the region:\n\\begin{align*}\nM&=\\int_{0}^1\\int_{x}^1\\int_{0}^{y-x} xz\\,dz\\,dy\\,dx\n=\\int_{0}^1\\int_{x}^1 {x(y-x)^2\\over2}\\,dy\\,dx\n={1\\over2}\\int_{0}^1 {x(1-x)^3\\over3}\\,dx\t\\\\\n&={1\\over6}\\int_{0}^1 x-3x^2+3x^3-x^4\\,dx\n={1\\over120}.\n\\end{align*}\nWe compute moments as before, except now there is a third moment:\n\\begin{align*}\nM_{xy} &= \\int_{0}^1\\int_{x}^1\\int_{0}^{y-x} xz^2\\,dz\\,dy\\,dx\n={1\\over360},\t\\\\\nM_{xz} &= \\int_{0}^1\\int_{x}^1\\int_{0}^{y-x} xyz\\,dz\\,dy\\,dx\n={1\\over144},\t\\\\\nM_{yz} &= \\int_{0}^1\\int_{x}^1\\int_{0}^{y-x} x^2z\\,dz\\,dy\\,dx\n={1\\over360}.\n\\end{align*}\nFinally, the coordinates of the center of mass are\n$\\bar x=M_{yz}/M=1/3$, $\\bar y=M_{xz}/M=5/6$, and  $\\bar\nz=M_{xy}/M=1/3$.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:TripleIntegrals}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nEvaluate $\\ds\\int_{0}^{1}\\int_{0}^{x}\\int_{0}^{x+y}\n2x+y-1 \\,dz\\,dy\\,dx$.\n\\begin{sol}\n$11/24$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\int_{0}^{2}\\int_{-1}^{x^2}\\int_{1}^{y}\nxyz \\,dz\\,dy\\,dx$.\n\\begin{sol}\n$623/60$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\int_{0}^{1}\\int_{0}^{x}\\int_{0}^{\\ln y}\ne^{x+y+z}\\,dz\\,dy\\,dx$.\n\\begin{sol}\n$-3e^2/4+2e-3/4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate\n$\\ds\\int_{0}^{\\pi/2}\\int_{0}^{\\sin\\theta}\\int_{0}^{r\\cos\\theta}\nr^2\\,dz\\,dr\\,d\\theta$.\n\\begin{sol}\n$1/20$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate \n$\\ds\\int_{0}^{\\pi}\\int_{0}^{\\sin\\theta}\\int_{0}^{r\\sin\\theta}\nr\\cos^2\\theta\\,dz\\,dr\\,d\\theta$.\n\\begin{sol}\n$\\pi/48$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\int_{0}^{1}\\int_{0}^{y^2}\\int_{0}^{x+y}\nx\\,dz\\,dx\\,dy$.\n\\begin{sol}\n$11/84$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\int_{1}^{2}\\int_{y}^{y^2}\\int_{0}^{\\ln(y+z)}\ne^x\\,dx\\,dz\\,dy$.\n\\begin{sol}\n$151/60$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\n\\int_0^\\pi\\int_0^{\\pi/2}\\int_0^1 z\\sin x+z\\cos y\\,dz\\,dy\\,dx$.\n\\begin{sol}\n$\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFor each of the integrals in the previous exercises, give a\ndescription of the volume (both algebraic and geometric) that is the\ndomain of integration.\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\\int\\int\\int\nx+y+z\\,dV$ over the region inside\n$x^2+y^2+z^2\\le 1$ in the first octant.\n\\begin{sol}\n$\\ds {3\\pi\\over16}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the mass of a cube with edge length 2 and density equal\nto the square of the distance from one corner.\n\\begin{sol}\n$32$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the mass of a cube with edge length 2 and density equal\nto the square of the distance from one edge.\n\\begin{sol}\n$64/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nAn object occupies the volume of the upper hemisphere of \n$x^2+y^2+z^2=4$ and has density $z$ at $(x,y,z)$. Find the center of mass.\n\\begin{sol}\n$\\bar x=\\bar y=0$, $\\bar z=16/15$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nAn object occupies the volume of the pyramid with corners at \n$(1,1,0)$, $(1,-1,0)$, $(-1,-1,0)$, $(-1,1,0)$, and $(0,0,2)$ and has\ndensity $x^2+y^2$ at $(x,y,z)$. Find the center of mass.\n\\begin{sol}\n$\\bar x=\\bar y=0$, $\\bar z=1/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nVerify the moments $M_{xy}$, $M_{xz}$, and $M_{yz}$\nof Example~\\ref{exa:3dcenterofmass} by evaluating the\nintegrals. \n\\end{ex}\n\n\\begin{ex}\nFind the region $E$ for which $\\ds\\iiint_E\n  (1-x^2-y^2-z^2) \\; dV$ is a maximum.\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "d370c307b2dec9623852611eefde26c9c64cee58", "size": 7002, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15-multiple-integration/15-5-triple-integrals.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "15-multiple-integration/15-5-triple-integrals.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "15-multiple-integration/15-5-triple-integrals.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6758893281, "max_line_length": 84, "alphanum_fraction": 0.6623821765, "num_tokens": 2925, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7152543657032036}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[margin=1in]{geometry} \n\\usepackage{amsmath,amsthm,amssymb,amsfonts}\n\\usepackage{enumitem}\n\\usepackage{tabu}\n\\usepackage{xcolor}\n\\usepackage{mathtools}\n\\usepackage{tcolorbox} \n\\usepackage{changepage} \n\\usepackage{kpfonts}\n\\usepackage{picture}\n\\usepackage{venndiagram}\n\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\newcommand{\\R}{\\mathbb{R}}\n\n\\newcommand{\\field}{\\mathcal{F}}\n\\newcommand{\\prob}[1]{\\mathbb{P}(#1)}\n\\newcommand{\\probtext}[1]{\\mathbb{P}(\\text{#1})}\n\n\\renewcommand\\labelitemi{---}\n\n\n\\newenvironment{nscenter}\n {\\parskip=0pt\\par\\nopagebreak\\centering}\n {\\par\\noindent\\ignorespacesafterend}\n \n\\def\\SPSB#1#2{\\rlap{\\textsuperscript{\\textcolor{black}{#1}}}\\SB{#2}}\n \n\\begin{document}\n\\title{%\n  MATH 487: Probability Theory Exam II\\\\\n  \\large University of Nebraska-Lincoln, Fall 2017}\n\\author{Jacob Shiohira}\n\\maketitle\n\n\\newpage\n\n% ================================================================================================================================\n% ================================================================================================================================\n\\begin{center}\n\\section*{Random Variables}\n\\end{center}\n\n\\noindent\nIn general, a random variable is a symbolic representation (variable) of the outcome of experiment that depends on chance.\n\n\\vspace*{.5cm}\n\\subsection*{Discrete Random Variables}\n\\noindent\nA \\textbf{discrete random variable} has a countable number of outcomes. The distribution of probabilities of a discrete random variable are measured by a \\textit{probability mass function}, $p_X(x)$, such that for any $x \\in \\text{Range}(X)$, \n\n\\begin{equation*}\n\\prob{X = x} = p_X(x)\n\\end{equation*}\n\n\\noindent\nwhere $p_X(x) > \\geq 0$ and $\\sum_{x} p_X(x) = 1$.\n\n\\subsection*{Continuous Random Variables}\n\\noindent\nA \\textbf{continuous random variable} has an infinitely uncountable number of outcomes. In other words, it can take on all values in a given interval. The distribution of probabilities of a continuous random variable are measured by a \\textit{probability distribution function}, $f_X(x)$ such that for any $a,b \\in \\text{Range}(X)$,\n\n\\begin{equation*}\n\\prob{a \\leq X \\leq b} = \\int_{a}^{b} f_X(x) dx\n\\end{equation*}\n\n\\noindent\nwhere $f_X(x) > \\geq 0$ and $\\int_{- \\infty}^{\\infty} f_X(x) dx = 1$. Unlike a \\textbf{probability mass function}, the probability of $f_X(x)$ such that $X = x$ is not defined in a \\textbf{probability distribution function}.\n\n\\subsubsection*{PMF versus PDF}\n\\noindent\nA \\textbf{probability mass function} measures the total mass with the dimension of probability. A \\textbf{probability distribution function} is essentially the measurement of probability on some continuum where $\\rho (\\frac{\\text{probability}}{unit})$ is a non-constant density function $f_X(x)$.\n\n\\subsection*{Cumulative Distribution Functions}\nA \\textbf{cumulative distribution function}, or CDF, of a real-valued random variable $X$, or just distribution function of $X$, evaluated at $x$, is the probability that $X$ will take a value less than or equal to $x$. In other words, $\\text{CDF}(x) = F_X(x)$ is equivalent to \n\n\\begin{align*}\n\\prob{X \\leq x} = \\sum_{x_i \\leq x} p_X(x) dx && \\text{in the Discrete Case} \\\\\n\\prob{X \\leq x} = \\int_{- \\infty}^{x} f_X(x) dx && \\text{in the Continuous Case}\n\\end{align*}\n\n\\noindent\nGeneral properties of the CDF are as follows,\n\n\\begin{enumerate}\n\\item $F(x) = \\prob{X \\leq x}$,\n\\item $0 \\leq F(x) \\leq 1$,\n\\item $F(x)$ is a non-decreasing function. If $a < b$, then $F(a) < F(b)$,\n\\item $\\lim_{x \\rightarrow \\infty} F(x) = 1$ and $\\lim_{x \\rightarrow - \\infty} F(x) = 0$, \n\\item $\\prob{a \\leq X \\leq b} = F(b) - F(a)$,\n\\item $F'(x) = f_X(x)$.\n\\end{enumerate}\n\n\\begin{center}\n\\section*{Distributions}\n\\end{center}\n\n\\subsection*{Normal, Gaussian}\n\\noindent\nGenerally, the \\textbf{normal} distribution is used $XXXX$. The probability distribution function is\n\n\\begin{align*}\nN(\\mu, \\sigma^2) = \\frac{1}{\\sqrt{2 \\pi} \\sigma} e^{- \\frac{(x - \\mu)^2}{2 \\sigma^2}} \\quad \\text{ for } \\sigma > 0.\n\\end{align*}\n\n\\noindent\nwhile the cumulative distribution function is\n\n\\begin{equation*}\n\\iota(x) = \\int_{- \\infty}^{x} \\frac{1}{\\sqrt{2 \\pi}} e^{- \\frac{\\mu^2}{2}} du.\n\\end{equation*}\n\n\\noindent\nThus, $\\text{E}(X) = \\mu$ and $\\text{Var}(X) = \\sigma^2$.\n\n\\subsection*{Cauchy}\n\\noindent\nGenerally, the \\textbf{Cauchy} distribution is used for resonance behavior and used to measure outliers in data sets. The probability distribution function is\n\n\\begin{equation*}\nC(\\theta, \\sigma) = \\frac{1}{\\pi \\sigma} \\Bigg [ \\frac{1}{1 + \\big ( \\frac{x- \\mu}{\\sigma}\\big )^2} \\Bigg ].\n\\end{equation*}\n\n\\noindent\nwhile the cumulative distribution function is\n\n\\begin{equation*}\nF(X) = \\frac{1}{\\pi} \\text{arctan}\\big ( \\frac{x - x_0}{\\gamma}\\big ) + \\frac{1}{2}\n\\end{equation*}\n\n\\noindent\nThe $\\text{E}(X)$ and the $\\text{Var}(X)$ are not defined for the Cauchy distribution.\n\n\\subsection*{Exponential}\n\\noindent\nGenerally, the \\textbf{Exponential} distribution is used to describe timing of events, such as the times between customer arrivals, times to equipment failure, etc. The probability distribution function is\n\n\\begin{equation*}\nE(\\lambda) = \\lambda e^{- \\lambda x}\n\\end{equation*}\n\n\\noindent\nwhile the cumulative distribution function is\n\n\\[ F(x) =  \\begin{cases} \n      1-e^{- \\lambda x} & x \\geq 0, \\\\\n      0 & x < 0.\n      \\end{cases} \\]\n\n\\noindent\nThus, $\\text{E}(X) = \\frac{1}{\\lambda}$ and $\\text{Var}(X) = \\frac{1}{\\lambda^2}$.\n\n\\subsection*{Gamma}\n\\noindent\nGenerally, the \\textbf{Gamma} distribution is used to measure non-negative random variables such as rain fall amount, plant yields, time between earthquakes, etc. The probability distribution function is\n\n\\begin{equation*}\n\\Gamma ( \\alpha, \\beta) = \\frac{\\lambda^{\\alpha}}{\\Gamma(\\alpha)} x^{\\alpha - 1} e^{- \\lambda x}\n\\end{equation*}\n\n\\noindent\nwhile the cumulative distribution function is\n\n\\begin{equation*}\nF(x) = \\frac{\\Gamma_x(\\gamma)} {\\Gamma(\\gamma)} \\qquad x \\geq 0; \\gamma > 0\n\\end{equation*}\n\n\\noindent\nThus, $\\text{E}(X) = \\frac{\\alpha}{\\lambda}$ and $\\text{Var}(X) = \\frac{\\alpha}{\\lambda^2}$. Note that $\\Gamma(n) = (n-1)!$.\n\n\\subsection*{Bernoulli}\n\\noindent\nGenerally, the \\textbf{Bernoulli} distribution is used $XXXX$. The probability distribution function is\n\n\\[ f_X(x) =  \\begin{cases} \n      \\alpha & x = 1, \\\\\n      1 - \\alpha & x = 0.\n      \\end{cases} \\]\n\n\\noindent\nwhile the cumulative distribution function is\n\n\\[ F(x) =  \\begin{cases} \n      0 & x \\leq 0, \\\\\n      1 - \\alpha & 0 < x < 1, \\\\\n      1 & x \\geq 1.\n      \\end{cases} \\]\n      \n\\noindent\nThus, $\\text{E}(X) = p$ and $\\text{Var}(X) = p(1-p)$.\n\n\\subsection*{Binomial}\n\\noindent\nGenerally, the \\textbf{Binomial} distribution is used $XXXXX$. The probability distribution function is\n\n\\begin{equation*}\nb(n,p,m) = {n \\choose m} p^n (1-p)^{n-m}\n\\end{equation*}\n\n\\noindent\nwhile the cumulative distribution function is\n\n\\begin{equation*}\nF(x;p,n) = \\sum_{i = 0}^{x} {n \\choose i} p^i (1- p)^{n - i}\n\\end{equation*}\n\n\\noindent\nThus, $\\text{E}(X) = np$ and $\\text{Var}(X) = npq$.\n\n\\subsection*{Geometric}\n\\noindent\nGenerally, the \\textbf{Geometric} distribution is used $XXXXX$. The probability distribution function is\n\n\\begin{equation*}\ng(p, k) = q^{k-1} p\n\\end{equation*}\n\n\\noindent\nwhile the cumulative distribution function is\n\n\\begin{equation*}\nF(x) = 1- (1 - p)^{k}\n\\end{equation*}\n\n\\noindent\nThus, $\\text{E}(X) = \\frac{1}{p}$ and $\\text{Var}(X) = \\frac{1-p}{p^2}$.\n\n\\subsection*{Poisson}\n\\noindent\nGenerally, the \\textbf{Poisson} distribution is used $XXX$. The probability distribution function is\n\n\\begin{equation*}\nP(k, \\lambda) = e^{- \\lambda} \\frac{\\lambda^k}{k!}.\n\\end{equation*}\n\n\\noindent\nThe $\\text{E}(X) = \\lambda$ and $\\text{Var}(X) = \\lambda$.\n\n\\begin{center}\n\\section*{Joint, Marginal, Conditional Functions}\n\\end{center}\n\n\\subsection*{Discrete Random Variables}\n\\noindent\nConsider the two probability mass functions, $f_X(x) = \\prob{X = x}$ and $f_Y(y) = \\prob{Y = y}$. The \\textbf{joint probability mass function} for $X,Y$ is\n\n\\begin{equation*}\n\\mathbb{P}_{XY}(x,y) = \\prob{X = x \\cap Y = y}.\n\\end{equation*}\n\n\\noindent\nNote that \n\n\\begin{equation*}\n\\sum_{x} \\sum_{y} \\mathbb{P}_{XY}(x,y) = \\sum_{(x_i, y_j) \\in R_{XY}} \\mathbb{P}_{XY}(x_i,y_j) =  1,\n\\end{equation*}\n\n\\noindent\nwhere $R_{XY} = \\{ (x_i, y_j) \\lvert x_i \\in R_X, y_j \\in R_Y \\} = R_{X} \\times R_{Y}$ where $R_X = {x_1, x_2, \\ldots }$ and $R_Y = {y_1, y_2, \\ldots }$. \n\n\\vspace*{.5cm}\n\\noindent\nThe \\textbf{marginal probability mass function} for any $x \\in R_X$ is\n\n\\begin{equation*}\n\\mathbb{P}_X(x) = \\prob{X = x} = \\sum_{y_j \\in R_Y} \\prob{X = x, Y = y_j} = \\sum_{y_j \\in R_Y} \\mathbb{P}_{XY}(x,y_j).\n\\end{equation*}\n\n\\noindent\nLikewise, for any $y \\in R_Y$,\n\n\\begin{equation*}\n\\mathbb{P}_Y(y) = \\prob{Y = y} = \\sum_{x_i \\in R_X} \\prob{X = x_i, Y = y} = \\sum_{x_i \\in R_X} \\mathbb{P}_{XY}(x_i,y).\n\\end{equation*}\n\n\\vspace*{.5cm}\n\\noindent\nThe \\textbf{conditional probability mass function} of $Y$ given $X = x$ is\n\n\\begin{align*}\nf_{Y \\lvert x} \\frac{f_{XY}(x,y)}{f_X(x)} \\qquad \\text{for } f_X(x) > 0.\n\\end{align*}\n\n\\noindent\nIn other words, $f_{Y \\lvert x}$ is equivalent to the joint probability of $X$ and $Y$ divided by the marginal probability for $X$. A few common properties of the \\textbf{conditional probability mass function} are as follows,\n\n\\begin{enumerate}\n\\item $f_{Y \\lvert x}(y) \\geq 0$,\n\\item $\\sum_{y} f_{Y \\lvert x} = 1$,\n\\item $f_{Y \\lvert x}(y) = \\prob{Y = y \\lvert X = x}$.\n\\end{enumerate}\n\n\\subsection*{Continuous Random Variables}\n% Basically the same... copy from discrete random variables.\n\n\\subsection*{Law of Total Probability}\n\\begin{equation*}\n\\prob{x} = f_X(x) = \\int_{- \\infty}^{\\infty} f_{X \\lvert Y} (x, y) f_Y(y) dy.\n\\end{equation*}\n\n\\subsection*{Joint Cumulative Distribution Function}\n\\noindent\nFor two Random Variables $X,Y$, the joint Cumulative Distribution Function is\n\n\\begin{equation*}\nF_{XY}(x,y) = \\prob{X \\leq x, Y \\leq y} = \\prob{ (X \\leq x) \\cap (Y \\leq y)}. \n\\end{equation*}\n\n\\subsection*{Marginal Cumulative Distribution Function}\n\\noindent\nFor any $x \\in X$,\n\n\\begin{equation*}\nF_X(x) = F_{XY}(x, \\infty) = \\lim_{y \\rightarrow \\infty} F_{XY}(x, y).\n\\end{equation*}\n\n\\noindent\nFor any $y \\in Y$,\n\n\\begin{equation*}\nF_Y(y) = F_{XY}(\\infty, y) = \\lim_{x \\rightarrow \\infty} F_{XY}(x, y).\n\\end{equation*}\n\n\\begin{center}\n\\item\t\\section*{Independent Random Variables}\n\\end{center}\nRandom variables $X,Y$ are independent \\textit{if and only if} \n\n\\begin{equation*}\n\\prob{X \\in A, Y \\in B} = \\prob{X \\in A} \\prob{Y \\in B}\n\\end{equation*}\n\n\\noindent\nfor any subsets $A,B \\in \\R^2$.\n\\subsection*{Expected Value of Random Variables}\n\\noindent\nThe expected value of a random variable is also its mean. So, $\\text{E}(X) = \\mu$. Common properties of the expected value of random variables are as follows,\n\n\\begin{enumerate}\n\\item $\\text{E}(X + Y) = \\text{E}(X) + \\text{E}(Y)$,\n\\item $\\text{E}(cX) = c\\text{E}(X)$,\n\\item If $X,Y$ are independent, $\\text{E}(XY) = \\text{E}(X) \\text{E}(Y)$.\n\\end{enumerate}\n\n\\subsubsection*{Discrete Random Variables}\n\\noindent\nIn the case of a discrete random variable, \n\n\\begin{equation*}\n\\text{E}(X) = \\sum_{k \\in \\Omega} k m(x)\n\\end{equation*}\n\n\\noindent\nfor distribution function $m(x)$.\n\n\\vspace*{.5cm}\n\\noindent\n\\textbf{Martingales} If $X$ is a random variable, $\\Omega$ is a sample space, and $F_1, F_2, \\ldots, F_r$ are events such that $F_i \\cap F_j = \\emptyset$ for $i \\neq j$ and $\\Omega = \\bigcup_j F_j$, then\n\n\\begin{equation*}\n\\text{E}(X) = \\sum_j \\text{E}(X \\lvert F_j) \\prob{F_j}.\n\\end{equation*}\n\n\\subsubsection*{Continuous Random Variables}\n% Basically the same... copy from discrete random variables.\n\n\\subsection*{Variance of Random Variables}\n\\noindent\nVariance is how much the outcome of an experiment varies from the expected value, or mean, $\\text{E}(X)$. Common properties of the variance of random variables are as follows,\n\n\\begin{enumerate}\n\\item $\\text{Var}(X + b) = \\text{Var}(X)$,\n\\item $\\text{Var}(cX) = c^2 \\text{E}(X)$,\n\\item If $X,Y$ are independent, $\\text{Var}(X + Y) = \\text{Var}(X) + \\text{Var}(Y)$.\n\\end{enumerate}\n\n\\subsubsection*{Discrete Random Variables}\n\\noindent\nGenerally, for a distribution function $m(x)$,\n\n\\begin{equation*}\n\\text{Var}(X) = \\text{E}((X-\\mu)^2) = \\sum_{x} (x - \\mu)^2 m(x) = \\text{E}(X^2) - \\big [ \\text{E}(X)^2 \\big ].\n\\end{equation*}\n\n\\subsubsection*{Continuous Random Variables}\n% Basically the same... copy from discrete random variables.\n\n\\begin{center}\n\\item \\section*{Convolutions}\n\\end{center}\n\\end{document} ", "meta": {"hexsha": "cbd9da157d3bc579e7e4088968aede52e57630da", "size": 12546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "probability-theory/exam-review/exam-2/Exam 2 Review.tex", "max_stars_repo_name": "jShiohaha/math-classes", "max_stars_repo_head_hexsha": "72711363cf0b58863ffb193ee79ff40244e517eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "probability-theory/exam-review/exam-2/Exam 2 Review.tex", "max_issues_repo_name": "jShiohaha/math-classes", "max_issues_repo_head_hexsha": "72711363cf0b58863ffb193ee79ff40244e517eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "probability-theory/exam-review/exam-2/Exam 2 Review.tex", "max_forks_repo_name": "jShiohaha/math-classes", "max_forks_repo_head_hexsha": "72711363cf0b58863ffb193ee79ff40244e517eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.9236641221, "max_line_length": 332, "alphanum_fraction": 0.6627610394, "num_tokens": 4321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8723473829749844, "lm_q1q2_score": 0.715231805902803}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Regularized OT Barycenters}\\label{sec-barycenters}\n\nAs presented in the introduction, Section~\\ref{subsec-ot-imaging}, for certain applications in imaging such as texture mixing or color normalization, it may be useful to compute the barycenter distribution of a set of input distributions. Until now we focused on the computation of the mapping between two given distributions, now we are interested in finding a new distribution in-between two or more distributions. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\paragraph{Asymmetric regularized OT metric}\n\nTo simplify the optimization process, we consider the asymmetric version of the regularized OT energy~\\eqref{eq-symm-reg-energy}. We maintain one data set as a reference, let say $X$, by taking into account all its points ($k_X=K_X=1$) and only perform regularization with respect to its own graph, i.e. $\\la_Y=0$. Thus, we simplify our expression into the following asymmetric distance: \n\\eql{\\label{eq-assym}\n\tD(\\mu_X,\\mu_Y)=\\umin{\\Sig \\in \\Dd_k}\n\tE(\\Sigma) = \\dotp{\\Cost{X}{Y}}{\\Sigma} + \n\t\\lambda \\regul{G_X \\De_{X,Y}(\\Sig)} \n} \n\\eq{\n\t\\qwhereq \\Dd_k=\n\t\\enscond{\\Sig \\in [0,1]^{N \\times N} }{ \\Sig   \\U  = 1, \\; \\Sig^* \\U \\leq k \\U }.\n}\nNote that $\\Matr_{\\kappa}=\\Dd_k$ for $\\kappa=(1,1,0,k)$. In general, $D$ is not a distance, since it is not symmetric and one can have $D(\\mu_X,\\mu_Y)=0$ while having $\\mu_X \\neq \\mu_Y$ (which is crucial to allow relaxing of mass conservation condition).  \n\n\\paragraph{Barycenter}Given a set of input clouds $(X^{[r]})_{r \\in R}$ indexed by $R$ and weights $(\\rho_r)_{r \\in R} \\in (\\RR^+)^R$, we define a barycenter cloud $X$ as a local minimizer of \n\\eql{\\label{eqbar}\n\t\\umin{X  \\in \\RR^{N \\times d}}\n\t\t\\Ee_\\rho(X)=\n\t\t\\sum_{r \\in R} \\rho_r \\: D(\\mu_{X^{[r]}},\\mu_{X}).\n}\nIn the case $\\lambda=0$ and $k=1$, one recovers barycenters over the Wasserstein space, see the introduction for more details. \n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Block-coordinate Descent}\\label{algobar}\n\nThe minimization of~\\eqref{eqbar} can be performed by doing a joint minimization on both the barycenter cloud $X$ and a set of matrices $\\Sigma^{[r]} \\in \\Dd_k$ \n\\eql{\\label{eq-barycenter-min}\n\t\\min_{ X, (\\Sig^{[r]})_{r \\in R} \n\t} \n\t\\sum_{r \\in R} \\rho_r \\left(\n\t\t\\dotp{ \\Cost{X^{[r]}}{X} }{\\Sigma^{[r]}} + \n\t\t\\lambda \\regul{ G_{X^{[r]}} (X^{[r]} - \\Sig^{[r]} X) } \\right).\n}\nThis is a non-convex optimization problem. Fortunately, it is separately convex with respect to each of its variables $X$ and $( \\Sig^{[r]} )_{r \\in R}$, so one can use the block coordinate descent scheme. The block coordinate descent method consists in optimizing a given energy by iteratively minimizing with respect to each of its variables, in our case $X$ and  $( \\Sig^{[r]} )_{r \\in R}$.\n\n\n%%%%%%%%%\n\\paragraph{Update $\\Sigma^{[r]}$}\n\nThis corresponds to performing in parallel $|R|$ independent relaxed regularized OT. Fixing $X$, one solves independently for each $\\Sig^{[r]}$ the convex problem\n\\eql{\\label{eq-barycenter-min-Si}\n\t\\umin{\\Sig^{[r]} \\in \\Dd_k }\n\t\t\\dotp{ \\Cost{X^{[r]}}{X} }{\\Sigma^{[r]}} + \n\t\t\\lambda \\regul{ G_{X^{[r]}} (X^{[r]} - \\Sig^{[r]} X) }.\n}\nFor $(p,q)=(2,2)$ or $(p,q)=(1,1)$ this minimization can be solved using the algorithms detailed in Section~\\ref{secalgosymm}.\n\n\n%%%%%%%%%\n\\paragraph{Update $X$} \n\nThen, one solves for $X$ the following convex optimization problem\n\\eql{\\label{eq-barycenter-min-X}\n\t\\umin{X \\in \\RR^{N \\times d} }\n\t\\Hh(X) = \n\t\\sum_{r \\in R} \\rho_r \\pa{\n\t\t\\dotp{ \\Cost{X^{[r]}}{X} }{\\Sigma^{[r]}} + \n\t\t\\lambda \\regul{ G_{X^{[r]}} (X^{[r]} - \\Sig^{[r]} X) }\n\t}.\n}\t\n\n%%%%%%%%%\n\\paragraph{Update $X$: Sobolev regularization} \\label{algobarysobolev}\n\nThe minimization of~\\eqref{eq-barycenter-min-X} when $p=q=2$ is an unconstrained quadratic problem, whose solution is obtained solving the following symmetric linear system\n\\eql{\\label{eq-bar-l2}\n\t\\sum_{r \\in R} \\rho_r \\left( \\Sig^{[r]} - \\la \\Sig^{[r]*} G_{X^{[r]}}^* G_{X^{[r]}} \\right) X = \\sum_{r \\in R} \\rho_r \\left( \\Sig^{[r]*} X^{[r]} - \\la \\Sig^{[r]*} G_{X^{[r]}}^* G_{X^{[r]}} X^{[r]} \\right) ,\n}\nwhich corresponds to solving $\\nabla \\Hh(X) =0$. The solution to this symmetric linear system can be computed using for instance the conjugate gradient algorithm.\n\n%%%%%%%%%\n\\paragraph{Update $X$: Anisotropic TV regularization}\n\nWhen $(p,q)=(1,1)$, \\eqref{eq-barycenter-min-X} is a linear program which can be solved using for instance interior point solvers~\\cite{Nesterov-Nemirovsky-Book}. An alternative option, that we detail here, is to use first order proximal splitting schemes, that are well tailored for such highly structured problems.  We propose here to use the primal-dual splitting scheme developed in~\\cite{Chambolle11}.\n\nThe problem~\\eqref{eq-barycenter-min-X} can be re-casted as a minimization of the form \n\\eql{\\label{eq-bar-l1}\n\\begin{aligned} \n\t& \\umin{X \\in \\RR^{N \\times d}}  & & F(K(X)) + H(X) \\\\ \n\t& \\qwhereq & &\n\t\\choice{\n\tK(X) = \\{ B_r X \\}_{r \\in R}, \\\\ \n\tK^*(\\{U_r\\}_{r \\in R}) = \\sum_{r \\in R} B^*_r U_r \\\\\n\tF(\\{U_r\\}_{r \\in R}) = \\la \\sum_{r \\in R} \\rho_r \\|G_{X^{[r]}} X^{[r]} - U_r \\|_1 \\\\\n\tH(X) =  \\sum_{r \\in R} \\rho_r \\dotp{ \\Cost{X^{[r]} }{X}}{\\Sig^{[r]}}\n\t}\n\\end{aligned}\n}\nwhere $B_r = G_{X^{[r]}} \\Sig^{[r]}$.  Let us now recall that the proximal operator of a function $F$ is defined as \n\\eq{ \n\t\\Prox_{\\ga F}(X) = \\uargmin{\\tilde X} \\frac{1}{2}\\norm{X-\\tilde X}^2 + \\ga F(\\tilde X),\n}\nand being able to compute the proximal mapping of $F$ is equivalent to being able to compute the proximal mapping of the Legendre-Fenchel dual $F^*$ of $F$, thanks to Moreau's identity\n\\eq{\n\tX = \\Prox_{\\ga F^*}(X) + \\ga \\Prox_{F/\\ga}(X/\\ga).\n}\nThen, the primal-dual algorithm of~\\cite{Chambolle11} to minimize $F \\circ K + H$ reads\n\\begin{align}\\label{eq-pd-bary}\n\t\\nonumber \\La^{k+1} &= \\Prox_{\\mu F^*}( \\La^k + \\mu K(\\tilde X^k), \\\\\n\t X^{k+1} &= \\Prox_{\\tau H}(  X^k-\\tau K^*(\\La^{k+1}) ), \\\\\n\t\\nonumber \\tilde X^{k+1} &= X^{k+1} + \\theta (X^{k+1} - X^k) ,\n\\end{align}\nwith $\\theta \\in (0,1]$ and where \n\\begin{align*}\n\\Prox_{\\tau F}(U) &=\\sum_{r \\in R} G^{[r]} \\Sig^{[r]} X^{[r]} + S_\\tau(U^{[r]} - G^{[r]} \\Sig^{[r]} X^{[r]}) \\\\\n\\Prox_{\\tau H}(Y) &= \\left( \\Id+ \\tau \\sum_{r \\in R}  \\rho_r \\Sig^{[r]}  \\right)^{-1} \\left(Y + \\tau \\sum_{r \\in R} \\rho_r \\Sig^{[r]*} X^{[r]} \\right)\n\\end{align*}\nwhere $S_\\tau$ is the soft thresholding function, defined as\n\\eq{\n\t\\foralls i=1,\\ldots,N, \\quad\n\tS_\\tau(U)_i =  \\max\\left(0,1- \\frac{\\tau}{\\norm{U_i}}  \\right)U_i.\n}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Algorithm}\n\nThe algorithm starts by some initial point set $X^{(0)}$, which is typically chosen to be equal to $X^{[r]}$ where $r$ corresponds to the maximum value of $\\rho_r$. It then constructs iterates $(X^{(\\ell)})_{\\ell}$ and $( \\Sigma_{i,j}^{[r],(\\ell)} )_r$ by solving respectively~\\eqref{eq-barycenter-min-Si} and~\\eqref{eq-barycenter-min-X}. This is detailed in Algorithm~\\ref{algo-block-barycenters}. \n\n\n\\begin{algorithm}[ht!]\n\\caption{Regularized and relaxed OT barycenter}\n\\label{algo-block-barycenters}\n\\Require Point sets $(X^{[r]})_{r \\in R}$, weights $(\\rho_r)_{r \\in R}$, initialization $X^{(0)}$.\n\n\\Ensure Barycenter point set $X^{(\\ell)}$, computed for $\\ell$ large enough.\n\n\\begin{enumerate}\n\t\\algostep{Initialization} Set $\\ell=0$.\n\t\\algostep{Update of $\\Sigma^{[r]}$} For each $r \\in R$, compute $\\Sigma^{[r],(\\ell+1)}$ by solving~\\eqref{eq-barycenter-min-Si} \\\\\n\t\t where $X=X^{(\\ell)}$ is fixed, using the algorithms detailed in Section~\\ref{secalgosymm}.\n\t\\algostep{Update of $X$} Compute $X^{(\\ell+1)}$ by solving~\\eqref{eq-barycenter-min-X} where $\\Sigma^{[r]} = \\Sigma^{[r],(\\ell+1)}$ \\\\\n\t\t\tare fixed.\n\t\t\tIf $(p,q)=(2,2)$ solve \\eqref{eq-bar-l2}, if $(p,q)=(1,1)$, use the algorithm~\\eqref{eq-pd-bary}.\n\t\\algostep{Convergence} While not converged, set $\\ell \\leftarrow \\ell+1$ and go back to 2.\n\\end{enumerate}\n\\end{algorithm}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Convergence}\n\n\nThe block coordinate descent methods are known to converge for smooth and differentiable energies~\\cite{tseng-proximal}. The following theorem ensures the convergence of the proposed algorithm in the case of the Sobolev regularization. For the anisotropic regularization, one cannot ensure the convergence to stationary points, although in practice, we always observe it in our numerical tests.\n\n\\begin{thm}\n\tWhen $(p,q)=(2,2)$, the iterates $X^{(\\ell)}$ of the algorithm are bounded and hence admit converging sub-sequences.\n\tThe energies $\\Ee_\\rho(X^{(\\ell)})$ (with  $\\Ee_\\rho$ defined in~(\\ref{eqbar}))are decaying and converging to $\\tilde{\\Ee}$.\n\t All converging sub-sequences converge to stationary points of $\\Ee_\\rho$ having the same energy $\\tilde{\\Ee}$.\n\\end{thm}\n\n\\begin{proof}\n\tBy construction, the energy $\\Ee_\\rho(X^{(\\ell)})$ is decaying and positive, hence converging.  The algorithm minimizes~\\eqref{eq-barycenter-min}, which reads\n\t\\eq{\n\t\t\\umin{ \\Sigma^{[r]} \\in \\Dd_k, X } \n\t\t\\bar \\Ee( (\\Sigma^{[r]})_r, X )\n\t\t= \\sum_{i,j,r}  \\rho_r \\norm{X_i^{[r]} - X_i }^2 \\Sigma_{i,j}^{[r]}\n\t\t+ \\la J_{2,2}\\pa{ G_{X^{[r]}} (X^{[r]} - \\Sigma^{[r]} X) }.\n\t}\n\n\tSince $\\Sigma^{[r]} \\in \\Dd_k$ which is a bounded set, the iterates $( \\Sigma_{i,j}^{[r],(\\ell)} )_r$ produced by the algorithm are bounded and hence they admit converging sub-sequences.\n\t\n\tFor any iteration index $\\ell$, one has\n\t\\eql{\\label{eq-proof-cv-1}\n\t\t\\sum_{i,j,r} \\rho_r \\norm{X_i^{[r]} - X_j^{(\\ell)} }^2 \\Sigma_{i,j}^{[r],(\\ell)} \n\t\t\\leq \\bar \\Ee( (\\Sigma^{[r],(\\ell)})_r, X^{(\\ell)} ) \n\t\t\\leq \\Ee_\\rho(X^{(0)})\n\t}\n\twhere $( \\Sigma_{i,j}^{[r],(\\ell)} )_r$ are the matrices obtained at the previous iteration of the method. We let $r$ be any index such that $\\rho_r>0$. For any $j$ we denote  $\\ga_i = \\Sigma_{i,j}^{[r],(\\ell)}$ (we ignore dependency with $(j,r,\\ell)$ for ease of notations) that satisfy $\\sum_i \\ga_i=1$  and define the barycenter \t\n\t\\eq{\n\t\t\\bar X_j = \\sum_i \\ga_i X_i^{[r]}\n\t}\n\twhich is a point in the convex hull of the $(X_i^{[r]})_i$, and is hence bounded independently of $j$ and $\\ell$.\n\t\n\tEquation~\\eqref{eq-proof-cv-1} implies\n\t\\eq{\n\t\t\\sum_{i} \\ga_i \\norm{X_i^{[r]} - X_j^{(\\ell)} }^2 \n\t\t\\leq \\frac{\\Ee_\\rho(X^{(0)})}{\\rho_r}\n\t}\n\tBy convexity of the function $x \\in \\RR^d \\mapsto \\norm{ X_j^{(\\ell)} - x }^2$, one has\n\t\\eq{\t\t\n\t\t\\norm{ X_j^{(\\ell)} - \\bar X_j }^2 \n\t\t\\leq\n\t\t\\sum_{i} \\ga_i \\norm{X_j^{(\\ell)} - X_i^{[r]} }^2  \\leq \\frac{\\Ee_\\rho(X^{(0)})}{\\rho_r}\n\t}\t\n\tThis shows that the iterates $X^{(\\ell)}$ of the algorithm are bounded, and hence admit converging sub-sequences.\n\t\t\n\t\n\tGiven that the energy $\\bar \\Ee$ is convex with respect to the variables $(\\Sigma^{[r]})_{r \\in R}$ and $X$ (although not jointly convex) and the non convex terms $J_{2,2}( G_{X^{[r]}} (X^{[r]} - \\Sigma^{[r]} X) )$ that mixes the variables is $C^1$ with Lipschitz gradient, one can apply the Theorem 4.1 of~\\cite{tseng-proximal}, which shows that any converging sub-sequence converges to a stationary point of $\\bar\\Ee_\\rho$.   \n\\end{proof}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "bd658bef484ad13f7bd44ebb62c00bb0a25646fc", "size": 11334, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/sec-barycenters.tex", "max_stars_repo_name": "gpeyre/2013-SIIMS-regularized-ot", "max_stars_repo_head_hexsha": "4d20033657717e3e0d744e3ce95fbc9afc6e5096", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-06-27T03:15:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-19T17:21:04.000Z", "max_issues_repo_path": "paper/sections/sec-barycenters.tex", "max_issues_repo_name": "gpeyre/2013-SIIMS-regularized-ot", "max_issues_repo_head_hexsha": "4d20033657717e3e0d744e3ce95fbc9afc6e5096", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/sections/sec-barycenters.tex", "max_forks_repo_name": "gpeyre/2013-SIIMS-regularized-ot", "max_forks_repo_head_hexsha": "4d20033657717e3e0d744e3ce95fbc9afc6e5096", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-10-12T17:29:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-04T01:52:32.000Z", "avg_line_length": 55.0194174757, "max_line_length": 429, "alphanum_fraction": 0.6204340921, "num_tokens": 3902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7152317974974316}}
{"text": "\\chapter{Reinforcement Learning}\nReinforcement learning is an area of machine learning concerned with how software agents ought to take actions in an environment so as to maximize some notion of cumulative reward.\n\\href{https://en.wikipedia.org/wiki/Reinforcement_learning}{wikipedia}\n\n\\section{Bellman Equations}\n\\newcommand{\\qfunc}[2]{Q_\\pi(#1, #2)}\n\\newcommand{\\vfunc}[1]{v_\\pi (#1)}\n\\newcommand{\\policy}[2]{\\pi (#1 | #2)}\n\n\\todo{RL backup diagramms}\nTODO backup diagramms\n\n\\subsection{State Value Function}\n\\begin{align}\n\t\\vfunc{s} = \\sum_{a \\in A} \\policy{s}{a} \\qfunc{s}{a}\n\\end{align}\n\\subsection{Action Value Function}\n\\begin{align}\n\t\\qfunc{s}{a} = r_s^a + \\gamma \\sum_{s' \\in S} P_{ss'}^a \\vfunc{s'}\n\\end{align}\n\\subsection{State Value Function recursive}\n\\begin{align}\n\t\\vfunc{s} = \\sum_{a \\in A} \\policy{s}{a} (r_s^a + \\gamma \\sum_{s' \\in S} P_{ss'}^a \\vfunc{s'})\n\\end{align}\n\\subsection{Action Value Function recursive}\n\\begin{align}\n\t\\qfunc{s}{a} = r_s^a + \\gamma \\sum_{s' \\in S} P_{ss'}^a \\sum_{a \\in A} \\policy{a'}{s'}\\qfunc{s'}{a'}\n\\end{align}\n\\subsection{Optimal State Value Function}\n\\renewcommand{\\qfunc}[2]{Q_{*}(#1, #2)}\n\\renewcommand{\\vfunc}[1]{v_{*} (#1)}\n\\begin{align}\n\t\\vfunc{s} = \\max_a \\qfunc{s}{a}\n\\end{align}\n\\subsection{Optimal Action State Value Function}\n\\begin{align}\n\t\\qfunc{s}{a} = r_s^a + \\gamma \\sum_{s' \\in S} P_{ss'}^a \\vfunc{s'}\n\\end{align}\n\\subsection{Optimal State Value Function recursive}\n\\begin{align}\n\t\\vfunc{s} = \\max\\limits_a r_s^a + \\gamma \\sum_{s' \\in S} P_{ss'}^a \\vfunc{s'}\n\\end{align}\n\\subsection{Optimal Action State Value Function recursive}\n\\begin{align}\n\t\\qfunc{a}{s} = r_s^a + \\gamma \\sum_{s' \\in S} P_{ss'}^a \\max\\limits_{a'} \\qfunc{s'}{a'}\n\\end{align}\n\n\n\\section{Advantage Function}\n\n\\todo{Advantage Function Definition}\n\n\n\\section{Policy, Policy Gradient}\n\n\\subsection{Policy: Distribution over actions given states}\n\\renewcommand{\\policy}[2]{\\pi_\\theta (#1 | #2)}\n\\begin{align}\n\t\\policy{a}{s} = P(a | s)\n\\end{align}\n\\subsection{Policy Gradient}\n\\begin{align}\n\t\\nabla_\\theta \\policy{s}{a} = \\policy{s}{a} \\nabla_\\theta \\log \\policy{s}{a}\n\\end{align}\nNote: this is valid for all probability distributions (the policy is a distribution over actions given states). The gradient term on the right hand side is called score function. The derivation basically uses the \"log-trick\".\n\n\n\\subsection{Proximal Policy Optimization PPO}\n\\newcommand{\\oldpolicy}[2]{\\pi_{\\theta_{\\mathrm{old}}} ( {#1} | {#2})}\n\\begin{enumerate}\n\t\\item \\url{https://arxiv.org/abs/1707.06347}. \n\\end{enumerate}\nAgent objective function:\n\\begin{align}\n\tL^{\\mathrm{CLIP}}( \\theta) \n\t= \\EE{\n\t\t\\min(r_t(\\theta) \\hat{A_t}, \\mathrm{clip}(r_t(\\theta), 1-\\epsilon, 1+\\epsilon) \\hat{A_t}\n\t}\n\\end{align}\nEventually they used many more objective terms, including an Entropy Term.\nAdvantage $\\hat{A_t}$ in this case means\n\\begin{align}\n\t\\hat{A_t} &= -V(s_t) + r_t + \\gamma r_{t+1} + \\dots + \\gamma^{T-t}V(s_T)\n\\end{align}\nIf the advantage is positive, then the estimated value of the currente state $s_t$ is smaller then what you actually got\nas rewards a couple time steps later. Your estimated state value was too low then.\nIf the advantage is negative, the estimate was too high.\nIn a generalized form using temporal difference formulation.\n\\begin{align}\n\t\\hat{A_t} &= \\delta_t + (\\gamma \\lambda)\\delta_{t+1} + \\dots + (\\gamma\\lambda)^{T-t+1}\\delta_{T-1} \\\\\n\t\\delta_t &= r_t + \\gamma V(s_{t+1}) - V(s_t)\n\\end{align}\n\n\\begin{algorithm}[H]\n\t\\For{iteration=1,2,\\dots}{\n\t\t\\For{actor=1,2, \\dots}{\n\t\t\tRun policy $\\pi_{\\theta_{\\mathrm{old}}}$ in environment for $T$ timesteps\\\\\n\t\t\tCompute advantage estimates $\\hat{A_1}, \\dots, \\hat{A_t}$\n\t\t}\n\t\tOptimize surrogate $L$ wrt $\\theta$, with $K$ epochs and minibatch size $M \\leq NT$ \\\\\n\t\t$\\theta_{old} \\leftarrow \\theta$\n\t}\n\t\\caption{PPO, Actor-Critic Style}\n\\end{algorithm}\n\n\\iftoggle{questions}\n{\n\t\\paragraph{Questions}\n\t\\begin{enumerate}\n\t\t\\item How does the clipping affect learning. We see higher variance towards end of training in the plots\n\t\t\\item where does the objective come from (why devide the policy values)\n\t\t\\item why conjugate gradients\n\t\t\\item How does the clipping affect the gradients\n\t\\end{enumerate}\n}{\n}", "meta": {"hexsha": "9ed7c01b1ce5a4a4312ea39dbe60d75ca9d1dfdd", "size": 4183, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ReinforcementLearning.tex", "max_stars_repo_name": "ML-KA/PDG-Code", "max_stars_repo_head_hexsha": "77f13079a86288bc09d4f9e7992d94abab2a1918", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-09-01T17:47:45.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-01T17:47:45.000Z", "max_issues_repo_path": "ReinforcementLearning.tex", "max_issues_repo_name": "ML-KA/PDG-Code", "max_issues_repo_head_hexsha": "77f13079a86288bc09d4f9e7992d94abab2a1918", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2018-08-31T08:26:00.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-06T13:13:02.000Z", "max_forks_repo_path": "ReinforcementLearning.tex", "max_forks_repo_name": "ML-KA/PDG-Code", "max_forks_repo_head_hexsha": "77f13079a86288bc09d4f9e7992d94abab2a1918", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-08-30T06:08:36.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-30T06:08:36.000Z", "avg_line_length": 36.0603448276, "max_line_length": 225, "alphanum_fraction": 0.6968682764, "num_tokens": 1387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220787, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7152317890178292}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n\\chapter{Derivatives}\n\\section{Geometric Interpretation}\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{secant-tangent.pdf}\n    \\caption{A function with secant and tangent lines}\n    \\label{fig:secant-tangent}\n\\end{figure}\nThis is the graph of a function, $f(x)$, and $P$ and $Q$ are points\non that curve. Geometrically, the line $\\overline{PQ}$ is known as the\n\\emph{secant} line --- a line that passes through at least two points\non a curve. We can see that the slope of $\\overline{PQ}$ is \n$\\frac{\\Delta f}{\\Delta x}$ and it is different than the slope ($m$) \nof the \\emph{tangent} line.\n\n\\begin{defn}\n    The derivative of $f$ at the point $x_0$, denoted $f'(x_0)$, is the\n    slope of the tangent line to $y=f(x)$ at the point $P$.\n    \\label{def:derivative}\n\\end{defn}\n\nAlthough that is a pretty solid definition of a derivative, \nwe need to be careful about how we think about the tangent line. \nIt is not just any line that passes through $P$; \nit is the \\emph{limit} of the secant line as the distance between \n$P$ and $Q$ goes to $0$.\n\nSimilarly, the slope of $\\overline{PQ}$ \\emph{approaches} the slope of the \ntangent line as $Q \\to P$. We can imagine this by dragging $Q$ \nalong the path of the curve down to $P$ and think about how that would \nchange the slope of $\\overline{PQ}$. In the \\emph{limiting} case, $Q$ \nwould be right next to $P$ and the slope of $\\overline{PQ}$ would be \nidentical to the slope of the tangent line. \nThis idea of limits is mathematically denoted in the following way:\n\\begin{equation}\n    f' \\left( x_0 \\right) = \\lim_{\\Delta x \\to 0} \n                                \\frac\n                                    {\\Delta f}\n                                    {\\Delta x}\n                          = \\lim_{\\Delta x \\to 0}\n                                \\frac\n                                    {\n                                        f \\left( x_0 + \\Delta x \\right)\n                                        - f \\left( x_0 \\right)\n                                    }\n                                    {\\Delta x}\n                          = m\n    \\label{eqn:derivative}\n\\end{equation}\n\n\\begin{exmp}\n    $f(x) = x^2$\n\n    We need to find the general equation of the slope of the tangent line \n    at any point $x$ on the curve of $y=x^2$ in terms of $x$.\n\n    From Equation \\ref{eqn:derivative}, we have:\n    \\begin{equation*}\n        f'(x) = \\lim_{\\Delta x \\to 0}\n                    \\frac\n                    {\n                        f \\left( x_0 + \\Delta x \\right)\n                        - f \\left( x_0 \\right)\n                    }\n                    {\\Delta x}\n    \\end{equation*}\n    By plugging in the given function, we get:\n    \\begin{equation*}\n        \\begin{split}\n            f'(x)   & = \\lim_{\\Delta x \\to 0}\n                            \\frac\n                            {\\left( x + \\Delta x \\right)^2 - x^2}\n                            {\\Delta x}\\\\\n                    & = \\lim_{\\Delta x \\to 0}\n                            \\frac\n                            {\n                                x^2 +\n                                2x \\Delta x +\n                                \\left( \\Delta x \\right)^2 -\n                                x^2\n                            }\n                            {\\Delta x}\\\\\n                    & = \\lim_{\\Delta x \\to 0}\n                            \\frac\n                            {\\Delta x \\left( 2x + \\Delta x \\right)}\n                            {\\Delta x}\\\\\n                    & = \\lim_{\\Delta x \\to 0} \\left( 2x + \\Delta x \\right)\\\\\n                    & = 2x\n        \\end{split}\n    \\label{eg:derivative}\n    \\end{equation*}\n\\end{exmp}\n\\subsection*{Notations}\nCalculus, rather like English or any other language, \nwas developed by several people. As a result, just as there are many ways \nto express the same thing in English, there are many notations for \nthe derivative.\n\nSince $y = f(x)$, it is natural to write:\n\\begin{equation*}\n    \\Delta y = \\Delta f = f(x) - f \\left( x_0 \\right) =\n    f \\left( x_0 + \\Delta x \\right) - f \\left( x_0 \\right)\n\\end{equation*}\nIf we divide both sides by $\\Delta x$, we get two expressions for\nthe \\emph{difference quotient}:\n\\begin{equation*}\n    \\frac{\\Delta y}{\\Delta x} = \\frac{\\Delta f}{\\Delta x}\n\\end{equation*}\nAs $\\Delta x \\to 0$:\n\\begin{align*}\n    \\frac{\\Delta y}{\\Delta x} & \\to \\left. \\frac{dy}{dx} \\right| _{x = x_0}\n    & & \\textrm{(Leibniz' Notation)}\\\\\n    \\frac{\\Delta f}{\\Delta x} & \\to f' \\left( x_0 \\right)\n    & & \\textrm{(Newton's Notation)}\\\\\n\\end{align*}\nOther, equally valid notations for the derivative of a \nfunction $f$ include:\n\\begin{equation*}\n    f'(x) = f'  = Df = \\frac{df}{dx} = \\frac{dy}{dx} = \\frac{d}{dx} y\n          = \\frac{d}{dx} f(x)\n\\end{equation*}\nThe \\emph{dot notation} (also introduced by Newton) is another convention \nused to denote derivatives with respect to $t$:\n\\begin{equation*}\n    \\frac{dy}{dt} = \\dot{y}\n\\end{equation*}\n\\subsection*{}\nAs we have seen from Example \\ref{eg:derivative}, at any point $x$, the slope of the parabola, $x^2$, \nis $2x$. \nWe can show that this can be generalised to the following formula:\n\\begin{equation}\n    \\frac{d}{dx} \\left( x^n \\right) = nx^{n - 1}\n\\end{equation}\n\n\\begin{exmp}\n    \\begin{align*}\n        \\frac{d}{dx} \\left( x^3 + 3x^{10} \\right)\n            & = (3)x^{3-1} + 3(10)x^{10-1}\\\\\n            & = 3x^2 + 30x^9\n    \\end{align*}\n\\end{exmp}\n\\section{Physical Interpretation}\nWhen something is changing with respect some other thing, \nit can be useful to know fast it’s changing at a particular instant.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.75\\textwidth]{average-change.pdf}\n    \\caption{Graph of a function with $\\Delta x$ and $\\Delta y$ labelled}\n    \\label{fig:average-change}\n\\end{figure}\n\nSpeed is a perfect example of this. When you are moving, the distance ($s$) \nyou travel changes with time ($t$). The \\emph{rate of change} of distance \nwith respect to time (what we usually call \\emph{speed}), \nis a measure of how fast you’re moving. Sometimes, it is useful to know \nwhat your \\emph{average} speed ($\\bar{v}$) was over the whole journey, \nwhich is given by:\n\\begin{equation*}\n    \\bar{v} = \\frac{\\Delta s}{\\Delta t}\n\\end{equation*}\nOther times, your speed at a particular instant is more important – \nthis is what is known as your \\emph{instantaneous} speed ($v$). \nYou don’t get a speeding ticket for having a high average speed \nover the whole journey; you get one for having a high speed \nat the \\emph{instant} you crossed a detection point. \nSimilarly, the speed shown on a car’s speedometer is not your \naverage speed for the whole trip, it is your instantaneous speed \nat that particular instant. Derivates do a great job at finding these \ninstantaneous rates of change:\n\\begin{equation*}\n    v = \\frac{ds}{dt}\n\\end{equation*}\n\\begin{exmp}\n    The distance ($s$) travelled by any free-falling object \n    over time ($t$) is, approximately:\n    \\[ s = 5t^2 \\]\n    In other words, after falling for one second, free-falling objects\n    usually travel five meters. After two seconds, twenty meters, and so on.\n\n    If we drop a ball from top of a five-hundred-meter tall building, \n    we know it will take about ten seconds to fall:\n    \\begin{align*}\n        500 &= 5t^2\\\\\n        \\therefore t &= \\SI{10}{s}\n    \\end{align*}\n    Since we know $\\Delta s = 500$ and $\\Delta t = 10$, we can find \n    the average speed of the ball over its entire fall:\n    \\begin{align*}\n        \\bar{v} &= \\frac{\\Delta s}{\\Delta t}\\\\\n                &= \\frac{500}{10}\\\\\n                &= \\SI{50}{m.s^{-1}}\n    \\end{align*}\n    However, using differentiation, we can also find its \n    instantaneous speed at any instant during its ten-second fall. \n    We just need the derivative of $s$ with respect to $t$:\n    \\begin{align*}\n        v   &= \\frac{ds}{dt}\\\\\n            &= \\frac{d}{dt} \\left( 5t^2 \\right)\\\\\n            &= 10t\n    \\end{align*}\n    All we need to do now is plug in any value of $t$ we want, \n    and this derivative will tell us the speed of the ball at that \n    particular instant in time. After, say, six seconds of falling \n    ($t = \\SI{6}{s}$), we know the ball was travelling at $v = \\SI{60}{m.s^{-1}}$.\n\\end{exmp}\n\\end{document}", "meta": {"hexsha": "83dcd3e8bd73964267bac6d1132fa7361e3c33ae", "size": 8297, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter1.tex", "max_stars_repo_name": "DanialHaseeb/single-variable-calculus", "max_stars_repo_head_hexsha": "4bf05b3e46010967217f2e71bb22a9de8e7fc82d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/chapter1.tex", "max_issues_repo_name": "DanialHaseeb/single-variable-calculus", "max_issues_repo_head_hexsha": "4bf05b3e46010967217f2e71bb22a9de8e7fc82d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-01-22T21:42:46.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-15T13:01:11.000Z", "max_forks_repo_path": "chapters/chapter1.tex", "max_forks_repo_name": "DanialHaseeb/single-variable-calculus", "max_forks_repo_head_hexsha": "4bf05b3e46010967217f2e71bb22a9de8e7fc82d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.5095238095, "max_line_length": 102, "alphanum_fraction": 0.57177293, "num_tokens": 2419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7151891701448079}}
{"text": "\\subsection{Surface Integrals of Vector Fields}\r\n\\begin{definition}\r\n\tThe surface integral of a vector field $\\vec{F}$ through a surface $S$ is \r\n\t\\begin{equation*}\r\n\t\t\\iint\\limits_{S}{\\vec{F} \\cdot \\hat{n}\\mathrm{d}s}\t\r\n\t\\end{equation*}\r\n\twhere $\\hat{n}$ is a unit vector normal to the surface.\r\n\tThis integral can also be written as \r\n\t\\begin{equation*}\r\n\t\t\\iint\\limits_{S}{\\vec{F} \\cdot \\mathrm{d}\\vec{s}}\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\r\n\\input{./lineSurfaceIntegrals/flux}", "meta": {"hexsha": "f83700c750f25b7ec718e93f5bc36510ed7f9b82", "size": 483, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/lineSurfaceIntegrals/surfaceIntegralsVFs.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/lineSurfaceIntegrals/surfaceIntegralsVFs.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/lineSurfaceIntegrals/surfaceIntegralsVFs.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.5, "max_line_length": 76, "alphanum_fraction": 0.6873706004, "num_tokens": 159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7151536820946496}}
{"text": "\n\\subsection{Special unitary groups \\(SU(n, F)\\)}\n\nThe special unitary group, \\(SU(n,F)\\), is the subgroup of \\(U(n,F)\\) where the determinants are \\(1\\).\n\nThat is, \\(|M|=1\\)\n\n\\subsubsection{The determinant of unitary matrices}\n\nThe determinant of the unitary matrices is:\n\n\\(\\det U^*=\\det U^{-1}\\)\n\n\\((\\det U)^*=\\dfrac{1}{\\det U} \\)\n\n\\((\\det U)^*\\det U = 1 \\)\n\n\\(||\\det U||= 1\\)\n\n", "meta": {"hexsha": "ae3982c56cd5e487d7a27a46f64a9a4fde568a37", "size": 381, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/05-02-SU.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/forms/05-02-SU.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/forms/05-02-SU.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.05, "max_line_length": 103, "alphanum_fraction": 0.5958005249, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7151536735657599}}
{"text": "In this chapter, the basic functions of the classes \\texttt{Math::Matrix} and \\texttt{Math::Vector} are documented.\n\n%%% Math::Matrix %%%\n\\section{Math::Matrix}\n\n\\begin{fdoc}{Math::Matrix<T>(u32 rows, u32 cols)}\n    \\descr{constructor. \\texttt{rows} $ \\times $ \\texttt{cols} elements of type \\texttt{T} (usually \\texttt{Float}) are allocated.}\n    \\param{rows}{an u32 specifying the number of rows}\n    \\param{cols}{an u32 specifying the number of cols}\n\\end{fdoc}\n\n\\subsection{Helper functions for Neural Networks}\n\n\\begin{fdoc}{void Math::Matrix::sigmoid(T gamma = 1.0)}\n    \\descr{applies the sigmoid function ($sigmoid(x)=\\frac{1}{1+e^{-\\gamma x}}$), to each element of the matrix}\n    \\param{gamma}{the scaling factor for the sigmoid function. Default is $ 1.0 $}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::triangle()}\n    \\descr{applies the triangle function ($triangle(x)= |x|\\ if\\ -1\\leq x\\leq 1;\\ 0\\ else$), to each element of the matrix}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::softmax()}\n    \\descr{applies the softmax function ($softmax(x_{ij})= \\frac{e^{x_{ij}}}{\\sum_k e^{x_{ik}}}$, where $x_{ij}$ is j-th number in i-th column), columnwise to each element of the matrix}\n\\end{fdoc}\n\n\\begin{fdoc}{T Math::Matrix::sum()}\n    \\descr{returns sum of each element of the matrix.}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::max()}\n    \\descr{applies the max function ($max(x_{ij}) = 1\\ if\\ x_{ij}\\geq x_{ik}\\ \\forall k;\\ 0\\ else$, where $x_{ij}$ is j-th number in the i-th column), columnwise to each element of the matrix}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::max(const Matrix<T> \\&A, const Matrix<T> \\&B)}\n    \\descr{assigns elementwise maximum from A and B to this matrix e.g $this_{ij} = maximum(A_{ij}, B_{ij})$}\n    \\param{A}{the first input matrix}\n    \\param{B}{the second input matrix}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::tanh()}\n    \\descr{applies the hyperbolic tangent function to each element of the matrix}\n\\end{fdoc}\n\n\\begin{fdoc}{\\shortstack{void Math::Matrix::elementwiseMultiplicationWithSigmoidDerivative(\\\\const Matrix<T> \\&X)}}\n    \\descr{multiplies each element of this matrix with the derivative of the sigmoid function. e.g. $this_{ij}=this_{ij} * (X_{ij} * (1 - X_{ij}))$}\n    \\param{X}{The output of the sigmoid function}\n\\end{fdoc}\n\n\\begin{fdoc}{\\shortstack{void Math::Matrix::elementwiseMultiplicationWithTanhDerivative(\\\\const Matrix<T> \\&X)}}\n    \\descr{multiplies each element of this matrix with the derivative of the tanh function. e.g. $this_{ij}=this_{ij} * (1 - X_{ij}^2)$}\n    \\param{X}{The output of the tanh function}\n\\end{fdoc}\n\n\\begin{fdoc}{\\shortstack{void Math::Matrix::elementwiseMultiplicationWithLogDerivative(\\\\const Matrix<T> \\&X)}}\n    \\descr{multiplies each element of this matrix with the derivative of the log function. e.g. $this_{ij}=this_{ij} / e^{X_{ij}}$}\n    \\param{X}{The output of the log function}\n\\end{fdoc}\n\n\\begin{fdoc}{\\shortstack{void Math::Matrix::elementwiseMultiplicationWithSignedPowDerivative(\\\\const Matrix<T> \\&X, T p)}}\n    \\descr{multiplies each element of this matrix with the derivative of the signedPower function. e.g. $this_{ij}=this_{ij} \\times p \\times |X_{ij}|^{p-1}$}\n    \\param{X}{The input of the signedPower function}\n    \\param{p}{The exponent}\n\\end{fdoc}\n\n\\subsection{General mathematical functions}\n\n\\begin{fdoc}{void Math::Matrix::exp()}\n    \\descr{exponentiate each element of the matrix e.g. ($exp(x) = e^{x}$)}\n\\end{fdoc}\n    \n\\begin{fdoc}{void Math::Matrix::signedPow(T p)}\n    \\descr{applies power function to the absolute value of each element of the matrix and keeps the original sign e.g. $signedPow(x, p) = |x|^p\\ if\\ x\\geq 0; -|x|^p\\ else$ }\n    \\param{p}{the exponent}\n    \n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::log()}\n    \\descr{applies the natural logrithm function to each element of the matrix}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::sin()}\n    \\descr{applies the sin function to each element of the matrix}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::cos()}\n    \\descr{applies the cos function to each element of the matrix}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::asin()}\n    \\descr{applies the arcsin function to each element of the matrix}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::acos()}\n    \\descr{applies the arccos function to each element of the matrix}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::abs()}\n    \\descr{updates each element of the matrix with its absolute value}\n\\end{fdoc}\n\n\\begin{fdoc}{T Math::Matrix::maxValue() const}\n    \\descr{returns the maximum value in the matrix}\n\\end{fdoc}\n\n\\begin{fdoc}{u32 Math::Matrix::argAbsMin(u32 column) const}\n    \\descr{returns the index of the minimum absolute value in the column}\n    \\param{column}{the index of the column}\n\\end{fdoc}\n\n\\begin{fdoc}{u32 Math::Matrix::argAbsMax(u32 column) const}\n    \\descr{returns the index of the maximum absolute value in the column}\n    \\param{column}{the index of the column}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::argMax(Vector<S>\\& v) const}\n    \\descr{saves the index of maximum value from each column of the matrix in rows of the vector }\n    \\param{v}{the vector which will contain the indecies of maximum values of columns}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::elementwiseMultiplication(const Matrix<T> \\&X)}\n    \\descr{multiplies each element of this matrix with corresponding element of the input matrix e.g. $ this_{ij} = this_{ij} \\times X_{ij} $}\n    \\param{X}{the input matrix}\n\\end{fdoc}\n\n\n\\begin{fdoc}{void Math::Matrix::elementwiseDivision(const Matrix<T> \\&X)}\n    \\descr{divides each element of this matrix by corresponding element of the input matrix e.g. $ this_{ij} = this_{ij} / X_{ij} $}\n    \\param{X}{the input matrix}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::addConstantElementwise(T C)}\n    \\descr{adds the input constant C to each element of this matrix e.g. $ this_{ij} = this_{ij} + C $}\n    \\param{C}{the input constant}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::addToColumn(const Vector<T> \\&v, u32 column, T alpha = 1.0)}\n    \\descr{adds a scaled vector to a column of this matrix}\n    \\param{v}{the input vector}\n    \\param{column} {index of column to which vector should be added}\n    \\param{alpha} {scale factor. Default is $ 1.0 $}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::addToRow(const Vector<T> \\&v, u32 row, T alpha = 1.0)}\n    \\descr{adds a scaled vector to a row of this matrix}\n    \\param{v}{the input vector}\n    \\param{row} {index of row to which vector should be added}\n    \\param{alpha} {scale factor. Default is $ 1.0 $}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::multiplyColumnByScalar(u32 column, T alpha)}\n    \\descr{multiplies a column of this matrix by a scalar}\n    \\param{column}{the index of the column}\n    \\param{alpha}{input scalar}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::multiplyRowByScalar(u32 row, T alpha)}\n    \\descr{multiplies a row of this matrix by a scalar}\n    \\param{row}{the index of the row}\n    \\param{alpha}{input scalar}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::addToAllColumns(const Vector<T> \\&v, T alpha = 1.0)}\n    \\descr{adds a scaled vector to all columns of this matrix}\n    \\param{v}{the input vector}\n    \\param{alpha} {scale factor. Default is $ 1.0 $}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::addToAllRows(const Vector<T> \\&v, T alpha = 1.0)}\n    \\descr{adds a scaled vector to all rows of this matrix}\n    \\param{v}{the input vector}\n    \\param{alpha} {scale factor. Default is $ 1.0 $}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::multiplyColumnsByScalars(const Vector<T> \\&scalars)}\n    \\descr{scales each column of this matrix by a scalar, e.g. $this.col_i = this.col_i \\times scalars_i$}\n    \\param{scalars}{the input vector, that contains scalars}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::divideColumnsByScalars(const Vector<T> \\&scalars)}\n    \\descr{divides each column of this matrix by a scalar, e.g. $this.col_i = this.col_i / scalars_i$}\n    \\param{scalars}{the input vector, that contains scalars}\n\\end{fdoc}\n\n\n\\begin{fdoc}{void Math::Matrix::multiplyRowsByScalars(const Vector<T> \\&scalars)}\n    \\descr{scales each row of this matrix by a scalar, e.g. $this.row_i = this.row_i \\times scalars_i$}\n    \\param{scalars}{the input vector, that contains scalars}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Matrix::divideRowsByScalars(const Vector<T> \\&scalars)}\n    \\descr{divides each row of this matrix by a scalar, e.g. $this.row_i = this.row_i / scalars_i$}\n    \\param{scalars}{the input vector, that contains scalars}\n\\end{fdoc}\n\n%%% Math::Vector %%%\n\\section{Math::Vector}\n\\begin{fdoc}{void Math::Vector::addConstantElementwise(T c)}\n    \\descr{adds a constant to each element of this vector, e.g. $this_i = this_i + c$}\n    \\param{c}{a constant to add to each element}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Vector::scale(T value)}\n    \\descr{scales this vector, e.g. $this_i = value \\times this_i$}\n    \\param{value}{the scaling factor.}\n\\end{fdoc}\n\n\\begin{fdoc}{T Math::Vector::sumOfSquares() const}\n    \\descr{returns the sum of squares of this vector, e.g. $return\\ this^T\\times this$}\n\\end{fdoc}\n\n\\begin{fdoc}{T Math::Vector::dot(const Vector<T>\\& vector) const}\n    \\descr{returns scalar/dot product of this vector with the given vector, e.g. $return\\ this^T\\times vector$}\n    \\param{vector}{the input vector.}\n\\end{fdoc}\n\n\\begin{fdoc}{\\shortstack{void Math::Vector::columnwiseSquaredEuclideanDistance(const Matrix<T>\\& A, \\\\const Vector<T>\\& v)}}\n    \\descr{computes the squared Euclidean distance of each column vector of the input matrix with the input vector, and stores results in this vector, e.g. $this_i = (A_i-v)^T(A_i-v)$}\n    \\param{A}{the input matrix.}\n    \\param{v}{the input vector.}\n\\end{fdoc}\n\n\\begin{fdoc}{\\shortstack{void Math::Vector::multiply(const Matrix<T> \\&A, const Vector<T> \\&x, \\\\ bool transposed = false, T alpha = 1.0, \\\\ T beta = 0.0, u32 lda = 0) const}}\n    \\descr{multiplies the input matrix or its transpose with the input vector and stores the result in this vector, e.g. $this = \\alpha A x + \\beta this$ or $this = \\alpha A^T  x + \\beta this$}\n    \\param{A}{the input matrix.}\n    \\param{x}{the input vector.}\n    \\param{transposed}{the input matrix should be transposed or not.}\n    \\param{alpha}{the scaling factor for the input matrix. Default is 1.0}\n    \\param{beta}{the scaling factor for the this vector. Default is 0.0}\n\\end{fdoc}\n\n\\begin{fdoc}{\\shortstack{void Math::Vector::columnwiseInnerProduct(const Matrix<T>\\& A,\\\\ const Matrix<T>\\& B)}}\n    \\descr{computes inner product of each column vector of matrix A with the corresponding column vector of matrix B, and stores results in this vector, e.g. $this_i = A_i^TB_i$}\n    \\param{A}{the input matrix A}\n    \\param{B}{the input matrix B}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Vector::elementwiseMultiplication(const Vector<T>\\& v)}\n    \\descr{multiplies each element of this vector with the corresponding element of the input vector, e.g. $this_i = this_i \\times v_i$}\n    \\param{v}{the input vector.}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Vector::elementwiseDivision(const Vector<T>\\& v)}\n    \\descr{divides each element of this vector with the corresponding element of the input vector, e.g. $this_i = this_i / v_i$}\n    \\param{v}{the input vector.}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Vector::elementwiseDivision(const Vector<T>\\& v)}\n    \\descr{divides each element of this vector with the corresponding element of the input vector, e.g. $this_i = this_i / v_i$}\n    \\param{v}{the input vector.}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Vector::setToZero()}\n    \\descr{sets each element of this vector to zero, e.g. $\\forall i\\ this_i = 0$}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Vector::fill(T value)}\n    \\descr{sets each element of this vector to the input value, e.g. $\\forall i\\ this_i = value$}\n    \\param{value}{the input value.}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Vector::ensureMinimalValue(const T threshold)}\n    \\descr{sets each element of this vector less than the threshold to threshold, e.g. $\\forall i\\ this_i = this_i\\ if\\ this_i\\geq threshold; threshold\\ else$}\n    \\param{threshold}{the input threshold.}\n\\end{fdoc}\n\n\\begin{fdoc}{u32 Math::Vector::argAbsMin() const}\n    \\descr{returns the index of absolute minimum value.}\n\\end{fdoc}\n\n\\begin{fdoc}{u32 Math::Vector::argAbsMax() const}\n    \\descr{returns the index of absolute maximum value.}\n\\end{fdoc}\n\n\\begin{fdoc}{T Math::Vector::max() const}\n    \\descr{returns the maximum value.}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Vector::exp() const}\n    \\descr{applies the exponential function to each element of this vector, e.g $this_i = e^{this_i}$}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Vector::signedPow(T p)}\n    \\descr{applies the signed power function to each element of this vector, e.g. $this_i = this_i^p\\ if\\ this_i\\geq 0; -|this_i|^p\\ else$}\n    \\param{p}{the exponent.}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Vector::log() const}\n    \\descr{applies the log function to each element of this vector, e.g $this_i = log(this_i)$}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Vector::abs() const}\n    \\descr{applies the absolute function to each element of this vector, e.g $this_i = |this_i|$}\n\\end{fdoc}\n\n\\begin{fdoc}{T Math::Vector::asum() const}\n    \\descr{returns the absolute sum over each element of this vector or L1 Norm of this vector, e.g. $return\\ \\sum_i |this_i|$}\n\\end{fdoc}\n\n\\begin{fdoc}{T Math::Vector::l1norm() const}\n    \\descr{returns the absolute sum over each element of this vector or L1 Norm of this vector, e.g. $return\\ \\sum_i |this_i|$}\n\\end{fdoc}\n\n\\begin{fdoc}{T Math::Vector::sum() const}\n    \\descr{returns the sum over each element of this vector, e.g. $return\\ \\sum_i this_i$}\n\\end{fdoc}\n\n\\begin{fdoc}{\\shortstack{void Math::Vector::addSummedColumns(const Matrix<T>\\& matrix,\\\\ const T scale = 1.0) const}}\n    \\descr{adds scaled column vectors of the input matrix to this vector, e.g. $this = this + \\sum_i scale \\times matrix.col_i$}\n    \\param{matrix}{the input matrix}\n    \\param{scale}{the scale factor. Default is 1.0}\n\\end{fdoc}\n\n\\begin{fdoc}{\\shortstack{void Math::Vector::addSquaredSummedColumns(const Matrix<T>\\& matrix,\\\\ const T scale = 1.0) const}}\n    \\descr{adds scaled squared (elementwise) column vectors of the input matrix to this vector, e.g. $this = this + \\sum_i scale \\times matrix.col_i \\odot matrix.col_i$}\n    \\param{matrix}{the input matrix}\n    \\param{scale}{the scale factor. Default is 1.0}\n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Vector::addSummedRows(const Matrix<T>\\& matrix, const T scale = 1.0) }\n    \\descr{adds scaled row vector of the input matrix to this vector, e.g. $this = this + \\sum_i scale\\times matrix.row_i$}\n    \\param{matrix}{the input matrix}\n    \\param{scale}{the scale factor. Default is 1.0}    \n\\end{fdoc}\n\n\\begin{fdoc}{void Math::Vector::getMaxOfColumns(const Matrix<T>\\& X) }\n    \\descr{saves the maximum of each column vector of the input matrix in this vector, e.g. $this_i = max(X.col_i)$}\n    \\param{X}{the input matrix}\n\\end{fdoc}\n\n\\begin{fdoc}{T normEuclidean() const}\n    \\descr{returns the Euclidean norm of this vector, e.g. $return\\ \\sqrt{this^Tthis}$}\n\\end{fdoc}\n\n\\begin{fdoc}{T chiSquareDistance(const Vector<T>\\& v) const}\n    \\descr{returns the chi square distance of this vector with the input vector, e.g. $return\\ \\sum_i (this_i - v_i)^2 / (this_i + v_i)$}\n    \\param{v}{the input vector.}\n\\end{fdoc}\n", "meta": {"hexsha": "f9bf13f0e99a8d1ad342c6e6444367da7ee51b3b", "size": 15332, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/math.tex", "max_stars_repo_name": "alexanderrichard/squirrel", "max_stars_repo_head_hexsha": "12614a9eb429500c8f341654043f33a1b6bd1d31", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 63, "max_stars_repo_stars_event_min_datetime": "2016-07-08T13:35:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-13T18:37:13.000Z", "max_issues_repo_path": "doc/math.tex", "max_issues_repo_name": "alexanderrichard/squirrel", "max_issues_repo_head_hexsha": "12614a9eb429500c8f341654043f33a1b6bd1d31", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-08-04T09:25:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-24T15:38:52.000Z", "max_forks_repo_path": "doc/math.tex", "max_forks_repo_name": "alexanderrichard/squirrel", "max_forks_repo_head_hexsha": "12614a9eb429500c8f341654043f33a1b6bd1d31", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2016-05-11T02:24:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-12T14:06:20.000Z", "avg_line_length": 45.2271386431, "max_line_length": 193, "alphanum_fraction": 0.6990607879, "num_tokens": 4725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.7151536652369026}}
{"text": "\\chapter{2D Systems}\\label{ch:2Dsyst}\nThe previous chapters considered systems distributed over one spatial dimension. As not all musical instruments or instrument-components can be simplified to this, higher dimensional systems need to be taken into consideration, such as 2D systems. 2D PDEs can be used to model drum membranes, plate reverbs or simplified instrument bodies. \n\nApart from being slightly more complex than 1D models, the main issue with 2D systems is that their implementations are orders of magnitude heavier to compute than 1D schemes. This chapter will therefore also provide details on how to best implement these schemes in \\texttt{MATLAB}. Implementation in C++ will be detailed in Chapter \\ref{ch:realtime}.\n\nThis chapter starts by providing some additional information about 2D grid functions and operators. Then, the 2D wave equation is presented, which is used to extend the analysis techniques presented in Chapter \\ref{ch:analysis} to 2D.\\footnote{The abbreviation 2D will also be used for `two dimensions'.} Afterwards, two 2D models used in this work: the thin plate and the stiff membrane, will be described in a similar fashion.\nThe systems modelled in this work are simplified to be rectangular and are defined on a Cartesian coordinate system. Section \\ref{sec:radialCoordinates} briefly elaborates on radial coordinate systems and their shortcomings. \nUnless denoted otherwise, the theory in this chapter follows \\cite{theBible}.\n\n\\section{PDEs and FD schemes in 2D}\\label{sec:2Dintro}\nConsider a rectangular 2D system with side lengths $L_x$ and $L_y$ (both in m) and its state described by $u = u(x,y,t)$. The system is defined for $t\\geq 0$ and $(x,y) \\in \\D$ where domain $\\D \\in [0, L_x]\\times [0, L_y]$ is two-dimensional. \n\nSimilar to the 1D case explained in Section \\ref{sec:gridFunctions}, the state variable can be discretised to a 2D grid function according to $u(x, y, t) \\approxeq \\ulmn$ with space $x = lh$ and $y = mh$ and time $t = nk$ with $k=1/\\fs$. The temporal index $n\\in\\mathbb{N}^0$  and the spatial indices $l\\in \\{0, \\hdots, N_x\\}$ and $m\\in \\{0, \\hdots, N_y\\}$ index the grid function in space in the $x$ and $y$ directions respectively. Here, $N_x$ is the number of intervals between grid points in the $x$ direction and $N_y$ in the $y$ direction. For simplicity, the grid spacing $h$ is set to be the same in both the $x$ and $y$ directions in this work.\n\n\\subsubsection{Additional operators}\nIn continuous time, an additional operator referred to as the \\textit{Laplacian}, can be defined as\n\\begin{equation}\\label{eq:laplacian}\n    \\Delta = \\pxx + \\pyy,\n\\end{equation}\nwhich describes a second-order spatial derivative in 2D. A 4\\thOrder spatial derivative in 2D, used to model stiffness like in the stiff string in Chapter \\ref{ch:stiffString}, is called the \\textit{biharmonic} operator, and is defined as the Laplacian applied to itself:\n\\begin{equation}\\label{eq:biharmonic}\n    \\Delta\\Delta = \\pxxxx + 2\\pxx\\pyy +  \\partial_y^4.\n\\end{equation}\n\nIn discrete time, the same temporal and spatial shift operators as defined in Section \\ref{sec:FDoperators} can be applied to grid function $\\ulmn$ the latter of which only affects the spatial index $l$. Additional operators affecting spatial index $m$ for the $y$ direction are\n\\begin{equation}\n    e_{y+}\\ulmn = u_{l, m+1}^n,\\quad \\text{and}\\quad e_{y-}\\ulmn= u_{l, m-1}^n.\n\\end{equation}\nUsing these shift operators, a discrete approximation of the Laplacian in Eq. \\eqref{eq:laplacian} can be made\\footnote{Notice that the $\\dDelta$ operator is identical to $\\delta_{\\Delta \\boxplus}$ in \\cite{theBible}, but will not be used here as Eq. \\eqref{eq:discreteLaplacian} is the only discretisation to the $\\Delta$ operator used in this work.} \n\\begin{equation}\\label{eq:discreteLaplacian}\n    \\Delta \\approxeq \\dDelta \\triangleq \\frac{1}{h^2}\\left(e_{x+} + e_{x-} + e_{y+} + e_{y-} - 4\\right),\n\\end{equation}\nand, when applied to a grid function, yields\n\\begin{equation}\\label{eq:laplacianExpansion}\n    \\Delta u \\approxeq \\dDelta \\ulmn = \\frac{1}{h^2}\\left(u_{l+1, m}^n + u_{l-1, m}^n+u_{l, m+1}^n+u_{l, m-1}^n - 4 \\ulmn\\right). \n\\end{equation}\nSee Figure \\ref{fig:laplacian} for the stencil of the discrete Laplacian. Similarly, an approximation of the biharmonic operator in Eq. \\eqref{eq:biharmonic} can be made as\n\\begin{equation}\\label{eq:discreteBiharmonic}\n% \\begin{align}\n        \\Delta\\Delta \\approxeq \\dDelta\\dDelta \n        % &= \\begin{aligned}[t]\n        %     \\frac{1}{h^4}\\Bigg(&\\left(e_{x+}^2 + 1+ e_{x+}e_{y+} + e_{x+}e_{y-} - 4e_{x+}\\right)\\\\\n        %     & + \\left(1 + e_{x-}^2 + e_{x-}e_{y+} + e_{x-}e_{y-} - 4e_{x-}\\right)\\\\\n        %     & + \\left(e_{x+}e_{y+} + e_{x-}e_{y+} + e_{y+}^2 + 1 - 4e_{y+}\\right)\\\\\n        %     & + \\left(e_{x+}e_{y-} + e_{x-}e_{y-} + 1 + e_{y-}^2 - 4e_{y-}\\right)\\\\\n        %     & -4 \\left(e_{x+} + e_{x-} + e_{y+} + e_{y-} - 4\\right)\\Bigg)\n        % \\end{aligned}\\\\\n        \\triangleq \\begin{aligned}[t]\n        &\\frac{1}{h^4}\\bigg[\\left(e_{x+}^2 + e_{x-}^2 + e_{y+}^2 + e_{y-}^2\\right) \\\\\n        &\\ \\ \\ + 2 \\left(e_{x+}e_{y+} + e_{x+}e_{y-} + e_{x-}e_{y+} + e_{x-}e_{y-}\\right) \\\\\n        &\\ \\ \\ -8 \\left(e_{x+} + e_{x-} + e_{y+} + e_{y-}\\right) + 20\\bigg],\n    \\end{aligned}\n% \\end{align}\n\\end{equation}\nand, when applied to a grid function, yields\n\\begin{equation}\\nonumber\n    \\begin{aligned}\n    \\Delta\\Delta u\\approxeq\\dDelta\\dDelta \\ulmn =&\\frac{1}{h^4}\\Big[(u_{l+2, m}^n + u_{l-2, m}^n+u_{l, m+2}^n+u_{l, m-2}^n)\\\\\n    &\\ \\ \\ +2(u_{l+1, m+1}^n + u_{l-1, m+1}^n+u_{l+1, m-1}^n+u_{l-1, m-1}^n)\\\\\n    &\\ \\ \\ -8(u_{l+1, m}^n + u_{l-1, m}^n+u_{l, m+1}^n+u_{l, m-1}^n) + 20u_{l,m}^n\\Big].\n    \\end{aligned}\n\\end{equation}\nSee Figure \\ref{fig:biharmonic} for the stencil of the discrete biharmonic operator.\n\\begin{figure}[h]\n    \\centering\n    \\subfloat[The $\\dDelta$ operator in Eq. \\eqref{eq:discreteLaplacian}.\\label{fig:laplacian}]{\\includegraphics[width=0.45\\textwidth]{figures/resonators/2d/laplacian.pdf}}\\hspace{0.06\\textwidth}\n    \\subfloat[The $\\dDelta\\dDelta$ operator in Eq. \\eqref{eq:discreteBiharmonic}.\\label{fig:biharmonic}]{\\includegraphics[width=0.45\\textwidth]{figures/resonators/2d/biharmonic.pdf}}\n    \\caption{The stencils of the 2D spatial FD operators in Eqs. \\eqref{eq:discreteLaplacian} and \\eqref{eq:discreteBiharmonic} respectively. The red square denotes what grid point the operator is applied to. The stencils follow the same layout as Figure \\ref{fig:operators}, but the vertical axis denotes a second spatial dimension rather than time. \\label{fig:2Doperators}}\n\\end{figure}\n\n\\section{The 2D wave equation}\\label{sec:2Dwave}\nThe 2D wave equation is the simplest 2D model in the context of musical acoustics and using the operators presented above it is a fairly straightforward extension to the 1D wave equation. Similar to how the 1D wave equation is used to model an ideal string, the 2D wave equation can be used to model an ideal membrane. \n\nThe first appearance of an implementation of the 2D wave equation in a musical context was due to van Duyne and Smith who used digital waveguides, or more specifically a waveguide mesh, to discretise it \\cite{Duyne1993}. The implementation is identical to the FD scheme that will be presented here.\\SWcomment[though it is more general here due to $\\lambda^2$ instead of hard-coded $0.5$]\n\nThis section will present the 2D wave equation in continuous time and its discretisation afterwards. The resulting FD scheme is then used as a test-case to extend the various analysis techniques presented in Chapter \\ref{ch:analysis} to 2D.\n\n\\subsection{Continuous time}\nConsider a system modelling the 2D wave equation with side lengths $L_x$ and $L_y$ (both in m) and its state described by $u = u(x,y,t)$. The system is defined over $(x,y) \\in \\D$ with domain $\\D = [0, L_x] \\times[0, L_y]$ and its motion is described by the following PDE:\n\\begin{equation}\\label{eq:2DwavePDE}\n    \\ptt u = c^2\\Delta u,\n\\end{equation}\nwith wave speed $c$ (in m/s) and the Laplacian operator as defined in Eq. \\eqref{eq:laplacian}. If the 2D wave equation is used to model an ideal membrane, the wave speed is defined as $c = \\sqrt{T/\\rho H}$ (in m/s), with tension per unit length $T$ (in N/m), material density $\\rho$ (in kg/m$^3$) and thickness $H$ (in m).\n\n\\subsubsection{Boundary conditions}\nSimilar to the 1D wave equation, two alternatives for boundary conditions are\n\\begin{subequations}\\label{eq:boundaryCond2DWave}\n    \\begin{align}\n    \\begin{rightcases}\n        u(0, y, t) = u(L_x, y, t) = 0\\quad \\forall y, \\\\\n        u(x, 0, t) = u(x, L_y, t) = 0\\quad \\forall x, \n    \\end{rightcases}\\quad &\\text{(Dirichlet, fixed)},\\label{eq:contDirichlet2D}\\\\\n    \\begin{rightcases}\n        \\px u(0, y, t) = \\px u(L_x, y, t) = 0\\quad \\forall y,\\\\\n        \\py u(x, 0, t) = \\py u(x, L_y, t) = 0\\quad \\forall x, \n    \\end{rightcases}\\quad &\\text{(Neumann, free)},\\label{eq:contNeumann2D}\n    \\end{align}\n\\end{subequations}\nwhere $\\forall$ means 'for all values of'.\n\\subsection{Discrete time}\nUsing the definition for the approximation of the Laplacian in Eq. \\eqref{eq:discreteLaplacian}, the 2D wave equation PDE in Eq. \\eqref{eq:2DwavePDE} can be discretised to\n\\begin{equation}\\label{eq:2DwaveFDS}\n    \\dtt \\ulmn = c^2 \\dDelta \\ulmn,\n\\end{equation}\nwith $l\\in\\{0, \\hdots, N_x\\}$ and $m\\in \\{0, \\hdots, N_y\\}$ where $N_x$ and $N_y$ are the number of intervals between grid points in the $x$ and $y$ direction respectively. The operators can then be expanded (see Eq. \\eqref{eq:laplacianExpansion}) and solving for $\\ulm^n$ yields the following update equation \n\\begin{equation}\\label{eq:update2Dwave}\n    \\ulm^{n+1} = 2\\ulmn - \\ulm^{n-1} + \\lambda^2 \\left(u_{l+1, m}^n + u_{l-1, m}^n+u_{l, m+1}^n+u_{l, m-1}^n - 4 \\ulmn\\right),\n\\end{equation}\nwhere the Courant number \n\\begin{equation}\\label{eq:courant2D}\n    \\lambda = \\frac{ck}{h},\n\\end{equation}\nand needs to abide\n\\begin{equation}\\label{eq:CFL2D}\n    \\lambda \\leq \\frac{1}{\\sqrt{2}}\n\\end{equation}\nfor the scheme to be stable. See Section \\ref{sec:stability2Dwave} for a derivation of this. Writing this condition in terms of the grid spacing, places the following limit on $h$:\n\\begin{equation}\\label{eq:stabilityCondition2Dwave}\n    h \\geq \\sqrt{2}ck\\,.\n\\end{equation}\n\n\\subsubsection{Discrete boundary conditions}\nThe boundary conditions in Eqs. \\eqref{eq:boundaryCond2DWave} can be discretised to \n\\begin{subequations}\\label{eq:boundaryCond2DWaveDisc}\n    \\begin{align}\n    \\begin{rightcases}\n        u_{0,m}^n = u_{N_x,m}^n = 0&&\\quad \\forall m, \\\\\n        u_{l,0}^n = u_{l,N_y}^n = 0&&\\quad \\forall l, \n    \\end{rightcases}\\quad &\\text{(Dirichlet, fixed)},\\label{eq:discDirichlet2D}\\\\\n    \\begin{rightcases}\n        \\dxd u_{0,m}^n = \\dxd u_{N_x,m}^n = 0&&\\quad \\forall m, \\\\\n        \\dyd u_{l,0}^n = \\dyd u_{l,N_y}^n = 0&&\\quad \\forall l, \n    \\end{rightcases}\\quad &\\text{(Neumann, free)}.\\label{eq:discNeumann2D}\n    \\end{align}\n\\end{subequations}\nIf the Dirichlet boundary conditions are used (for all sides), the domain of calculation can simply be reduced to $l\\in\\{1, \\hdots N_x-1\\}$ and $m\\in\\{1, \\hdots N_y-1\\}$. \n\n\\subsubsection{Stencil}\nFigure \\ref{fig:stencil2Dwave} shows the stencil of the 2D wave equation FD scheme in Eq. \\eqref{eq:2DwaveFDS}. The grid points use the same colour-coding as previous stencils (see e.g. Figure \\ref{fig:stencil1DWave}).\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.7\\textwidth]{figures/resonators/2d/stencil2Dwave.eps}\n    \\caption{The stencil for the 2D wave equation FD scheme in Eq. \\eqref{eq:2DwaveFDS}. \\label{fig:stencil2Dwave}}\n\\end{figure}\n\\subsection{Matrix form and output}\\label{sec:2DwaveImplementation}\nSimilar to how the number of intervals between grid points is calculated for 1D systems in Eq. \\eqref{eq:orderOfCalc}, it can be calculated in 2D using the following operations:\n\\begin{equation}\\label{eq:orderOfCalc2D}\n    h := \\sqrt{2} ck, \\ \\ N_x := \\floor[\\frac{L_x}{h}], \\ \\  N_y := \\floor[\\frac{L_y}{h}], \\ \\  h := \\text{min}\\left(\\frac{L_x}{N_x}, \\frac{L_y}{N_y}\\right), \\ \\  \\lambda := \\frac{ck}{h},\n\\end{equation}\nwhere the `$\\text{min}$' operator selects the smallest value of $L_x/N_x$ and $L_y/N_y$ to stay as close to the stability condition as possible. \n% Notice that the grid spacing is recalculated based the smallest value of $L_x/N_x$  $L_y/N_y$ $L/N$ for in the $x$ and $y$ direction to stay as close to the stability condition in Eq. \\eqref{eq:stabilityCondition2Dwave}.\nTo implement the update equation in Eq. \\eqref{eq:update2Dwave}, one could save the states of the system in matrices (as opposed to vectors in the 1D case such as done in Section \\ref{sec:implementationStiffString}) and directly work with these. Using Dirichlet boundary conditions the $(N_x-1) \\times (N_y-1)$ state matrix at time index $n$ would be\n\\begin{equation}\n    \\U^n = \\begin{bmatrix}\n        u^n_{1, 1} & \\hdots & u^n_{1, N_x-1}\\\\\n        \\vdots & \\ddots & \\vdots\\\\\n        u^n_{N_y-1, 1} & \\hdots & u^n_{N_y-1, N_x-1}\n    \\end{bmatrix},\n\\end{equation}\nand could be used to make a `for-loop implementation' of the update equation. This would indeed be the strategy if one would implement the scheme in e.g. C++ (see Chapter \\ref{ch:realtime}). For a more compact and faster implementation in \\texttt{MATLAB}, however, one could `stack' or `flatten' the state matrices to vectors and update the scheme using matrix-vector multiplication (as done for the stiff string in Section \\ref{sec:implementationStiffString} for example). Again using Dirichlet boundary conditions, the stacked state vector will be structured as\n\\begin{equation}\\label{eq:stackedState}\n    \\uStack^n = [(\\u_{1}^n)^T, \\hdots, (\\u_{N_x-1}^n)^T]^T, \\qwiq \\u^n_l = [u^n_{l, 1}, \\hdots, u^n_{l, N_y-1}]^T,\n\\end{equation}\nand has a size of $(N_x-1)\\cdot (N_y-1) \\times 1$. See Figure \\ref{fig:stackingMatrix} for a visualisation of the matrix-stacking process.\n\\begin{figure}[t]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/resonators/2d/stackingMatrix.pdf}\n    \\caption{Stacking, or `flattening' a $4\\times 4$ matrix to a $16$-element vector. \\label{fig:stackingMatrix}}\n\\end{figure}\n\nTo obtain a matrix form of the $\\dDelta$ operator that can be applied to this stacked state vector, the \\textit{Kronecker product} and \\textit{Kronecker sum} must be introduced \\cite{Horn1991}. The Kronecker product between two arbitrarily-sized matrices (using their dimensions as a subscript) is\n\\begin{equation}\n    \\A_{M\\times N} \\otimes \\B_{K\\times L} = \\begin{bmatrix}\n        a_{11}\\B & \\hdots & a_{1N}\\B\\\\\n        \\vdots & \\ddots & \\vdots\\\\\n        a_{M1}\\B & \\hdots & a_{MN}\\B\\\\\n    \\end{bmatrix}_{MK \\times NL}.\n\\end{equation}\n% In essence, the Kronecker product copies a matrix $\\B$ according to a matrix $\\A$. gets arranged according to a \n% The matrix operators then use the Kronecker\nThe Kronecker sum between two square matrices is \n\\begin{equation}\n    \\A_{M \\times M} \\oplus \\B_{N \\times N} = \\I_N\\otimes \\A + \\B \\otimes\\I_M,\n\\end{equation}\nwhere $\\I_P$ is the identity matrix of size $P\\times P$. \n\nFor Dirichlet boundary conditions, the $\\Dxx$ matrix of size $(N_x-1) \\times (N_x-1)$ and the $\\Dyy$ matrix of size $(N_y-1) \\times (N_y-1)$ can be defined (similar to Eq. \\eqref{eq:DxxDef}) as\n%\n\\setstackgap{L}{14pt}\n\\setstacktabbedgap{3pt}\n\\def\\lrgap{\\kern3pt}\n\\fixTABwidth{T}\n%\n\\begin{equation}\\label{eq:DxxyyDef}\n    \\Dxx = \\frac{1}{h^2}\\underbrace{\\xbracketMatrixstack{\n        -2 & 1 & & &\\mathbf{0}\\\\\n        1 & -2 & 1 & & \\\\\n        & \\ddots & \\ddots & \\ddots & \\\\\n        & & 1 & -2 & 1 \\\\\n        \\mathbf{0}& & & 1 & -2 \n    }}_{(N_x-1) \\times (N_x-1)} \\qaq \\Dyy = \\frac{1}{h^2}\\underbrace{\\xbracketMatrixstack{\n        -2 & 1 & & &\\mathbf{0}\\\\\n        1 & -2 & 1 & & \\\\\n        & \\ddots & \\ddots & \\ddots & \\\\\n        & & 1 & -2 & 1 \\\\\n        \\mathbf{0}& & & 1 & -2 \n    }}_{(N_y-1) \\times (N_y-1)}.\n\\end{equation}\n%\nFollowing \\cite{Hamilton2016}, the matrix form of the $\\dDelta$ operator can then be defined as the Kronecker sum of $\\Dyy$ and $\\Dxx$, yielding\n%\n\\setstackgap{L}{14pt}\n\\setstacktabbedgap{2pt}\n\\def\\lrgap{\\kern3pt}\n\\fixTABwidth{T}\n%\n\\begin{equation}\\label{eq:DDeltaMatrix}\n    \\DDeltamat = \\Dyy \\oplus \\Dxx = \\xbracketMatrixstack{\n        \\ddots & & & & \\mathbf{0}\\\\\n        &\\Dyy & & & \\\\\n        & &\\Dyy & & \\\\\n        & & & \\Dyy & \\\\\n        \\mathbf{0}& & & & \\ddots\n    } + \\frac{1}{h^2}\\!\\!\\xbracketMatrixstack{\n         \\ddots&\\ddots & & & \\mathbf{0}\\\\\n         \\ddots&-2\\I&\\I & & \\\\\n        &\\I&-2\\I &\\I &  \\\\\n        & & \\I& -2\\I &\\ddots\\\\\n        \\mathbf{0}& & & \\ddots& \\ddots\n    },\n\\end{equation}\nwhere the identity matrix $\\I = \\I_{N_x-1}$. The $\\DDeltamat$ matrix is square and of size $(N_x-1)\\cdot (N_y-1)\\times (N_x-1)\\cdot (N_y-1)$.\n\nUsing the above, the FD scheme in Eq. \\eqref{eq:2DwaveFDS} can then be compactly written in matrix form as\n\\begin{equation}\\label{eq:matrixUpdate2Dwave}\n    \\uStack^{n+1} = \\left(2 \\I + c^2k^2 \\DDeltamat\\right) \\uStack^n - \\uStack^{n-1},\n\\end{equation}\nwhere the identity matrix is of the same size as $\\DDeltamat$. See Appendix \\ref{app:2DWave} for a \\texttt{MATLAB} implementation of the 2D wave equation.\\footnote{As the matrices are extremely sparse (many $0$-entries), it is useful to utilise \\texttt{MATLAB}s optimisation for sparse matrices using the \\texttt{sparse()} function. One can use \\texttt{speye()} for sparse identity matrices.}\n\nIf one would like to visualise the system state as a 2D grid, one can revert the stacked vector back to a matrix by using the \\texttt{reshape} function in \\texttt{MATLAB}:\n\\begin{center}\n    \\texttt{uMatrix = reshape(u, Ny-1, Nx-1);}\n\\end{center}\nA 2D raised-cosine excitation can be implemented in the same way by reshaping an excitation matrix to a vector (see Section \\ref{sec:2DraisedCos})\\todo{check if this is still true}.\n\n\\subsubsection{Output}\nFigure \\ref{fig:2Dpropagation} shows the wave propagation of an implementation of the 2D wave equation with Dirichlet boundary conditions. Parameter values are $L_x = 1.5$ m, $L_y = 1$ m and $c= 360$ m/s. Waves reflect at the boundaries at an increasing rate. This is also shown in Figure \\ref{fig:output2DWave}, where the output -- taken at $(x,y) = (0.15, 0.85)$ -- in time domain shows an increase in oscillations over time, due to these reflections. The right panel shows that the output contains many partials that are close together, i.e., the output is highly inharmonic. As opposed to the output of the 1D wave equation shown in Figure \\ref{fig:1DWaveOutput}, where the partials are integer multiples of the fundamental frequency, the 2D wave equation exhibits aperiodic behaviour due to the aforementioned reflections, causing this inharmonicity.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/resonators/2d/twoDPropagation.eps}\n    \\caption{Wave propagation of an implementation of the 2D wave equation with $L_x = 1.5$ m, $L_y = 1$ m and $c= 360$ m/s. The system is excited with a 2D raised cosine at $(0.25L_x, 0.5L_y)$.\\label{fig:2Dpropagation}}\n\\end{figure}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/resonators/2d/output2Dwave.eps}\n    \\caption{The output of the 2D wave equation at $(x,y) = (0.15, 0.85)$ corresponding to Figure \\ref{fig:2Dpropagation}. The partials are extremely close together (notice that only frequencies up to 5000 Hz are shown) which is related to the aperiodic nature of the system behaviour. \\label{fig:output2DWave}}\n\\end{figure}\n\n\\subsection{Frequency domain analysis in 2D}\\label{sec:stability2Dwave}\nSection \\ref{sec:stabilityAnalysis} showed how to perform frequency domain analysis to obtain stability conditions for a FD scheme. This section shows extensions to this in 2D and follows \\cite[Ch. 10]{theBible}.\n\nIn 2D, the ansatz in Eq. \\eqref{eq:ansatz} can be extended to \n\\begin{equation}\\label{eq:2Dansatz}\n    \\ulmn \\ansatz z^n e^{jh(l\\beta_x + m\\beta_y)}\n\\end{equation}\nwhere $\\beta_x$ and $\\beta_y$ are components of a 2D wavenumber $\\boldsymbol{\\beta}$ in the $x$ and $y$ directions respectively. Frequency domain representations of temporal operators shown in Eq. \\eqref{eq:temporalAnsatz} do not change in the 2D case. Using \n\\begin{equation}\\label{eq:pxpy}\n    p_x = \\sin^2(\\beta_x h/2) \\qaq p_y = \\sin^2(\\beta_y h/2)\n\\end{equation}\nfor brevity, the following frequency domain representation of spatial operators can be obtained through the ansatz in Eq. \\eqref{eq:2Dansatz}\n\\begin{equation}\n    \\dxx \\ulmn \\ansatz -\\frac{4}{h^2}p_x \n    \\ulmn \\qaq \\dyy \\ulmn \\ansatz -\\frac{4}{h^2}p_y \n    \\ulmn,\n\\end{equation}\nfrom which it follows that\n\\begin{gather}\n    \\dDelta\\ulmn \\ansatz -\\frac{4}{h^2}(p_x + p_y)\\ulmn,\\label{eq:laplacianAnsatz}\\\\\n    \\dDelta\\dDelta\\ulmn \\ansatz \\frac{16}{h^4}(p_x + p_y)^2\\ulmn.\\label{eq:biharmonicAnsatz}\n\\end{gather}\n%\nUsing these definitions, a frequency domain interpretation of the 2D wave equation FD scheme in Eq. \\eqref{eq:2DwaveFDS} can be obtained\n\\begin{equation*}\n    \\frac{1}{k^2}\\left(z - 2 +z^{-1}\\right) = -\\frac{4c^2}{h^2} (p_x + p_y).\n\\end{equation*}\nRecalling $\\lambda$ in Eq. \\eqref{eq:courant2D}, this can be rewritten to the following characteristic equation\n\\begin{equation}\n    z + \\left(4\\lambda^2(p_x + p_y)-2\\right) +z^{-1} = 0.\n\\end{equation}\nAs (after multiplication by $z$) the characteristic equation is of the form in Eq. \\eqref{eq:polynomialForm} and $a^{(2)} = 1$ , its roots are bounded by condition \\eqref{eq:simplerCondition215} \n\\begin{equation*}\n    \\left|4\\lambda^2(p_x + p_y)-2\\right| \\leq 2.\n\\end{equation*}\nFurther derivation yields\n\\begin{align*}\n    -2 &\\leq 4\\lambda^2(p_x + p_y)-2 \\leq 2, \\\\\n    0 &\\leq 4\\lambda^2(p_x + p_y) \\leq 4,\n\\end{align*} \nand as the middle term is non-negative the first condition is always satisfied, yields\n\\begin{equation*}\n    \\lambda^2(p_x + p_y) \\leq 1.\n\\end{equation*}\nFinally, as $p_x$ and $p_y$ are bounded by 1 for all wavenumbers $\\beta_x$ and $\\beta_y$ respectively, the following condition must hold\n\\begin{align}\n    2\\lambda^2&\\leq 1,\\nonumber\\\\\n    \\lambda &\\leq \\frac{1}{\\sqrt{2}}\n\\end{align}\nwhich is the stability condition given in Eq. \\eqref{eq:CFL2D}.\n\n\\subsection{Energy analysis in 2D}\\label{sec:energyAnalysis2DWave}\n\\def\\domXred{\\underline{d_x}}\n\\def\\domYred{\\underline{d_y}}\n\\def\\domXredBoth{\\underline{\\overline{d_x}}}\n\\def\\domYredBoth{\\underline{\\overline{d_y}}}\n\\def\\domRedBoth{\\underline{\\overline{d}}}\n\nEnergy analysis for the 1D case is introduced in Section \\ref{sec:energyAnalysis}. Extensions for the analysis in 2D will be given here.\n\nAnalogous to the 1D inner product presented in Section \\ref{sec:innerProduct}, one can define a 2D inner product. For two functions $f = f(x,y,t)$ and $g(x,y,t)$ defined for a 2D domain $\\D$ their inner product over this domain is defined as\n\\begin{equation}\n    \\langle f, g \\rangle_\\D  = \\iint_\\D f g dx dy.\n\\end{equation}\nLike in the 1D case, these functions do not have to be a function of time, but they are here, for coherence. \n\nFor two (grid) functions $f_{l,m}^n$ and $g_{l,m}^n$ defined over a discrete domain $d\\in \\{0, \\hdots, N_x\\} \\times \\{0, \\hdots, N_y\\}$ their discrete inner product is defined as\n\\begin{equation}\\label{eq:2DInnerProd}\n    \\langle f^n_{l, m}, g^n_{l, m} \\rangle_d = \\sum_{l = 0}^{N_x}\\sum_{m = 0}^{N_y} h^2 f_{l,m}^n g_{l,m}^n.\n\\end{equation}\nNotice that the multiplication with the grid spacing is squared due to the inner product over a 2D domain (and is the discrete counterpart of $dxdy$). Useful for energy analysis are the following reduced 2D domains \n\\begin{subequations}\\label{eq:reduced2Ddoms}\n    \\begin{align}\n        \\domXred &= \\{0, \\hdots, N_x-1\\} \\times \\{0, \\hdots, N_y\\}, \\\\\n        \\domXredBoth &= \\{1, \\hdots, N_x-1\\} \\times \\{0, \\hdots, N_y\\},\\\\\n        \\domYred &= \\{0, \\hdots, N_x\\} \\times \\{0, \\hdots, N_y-1\\},\\\\\n        \\domYredBoth &= \\{0, \\hdots, N_x\\} \\times \\{1, \\hdots, N_y-1\\}\\\\\n        \\domRedBoth &= \\{1, \\hdots, N_x-1\\} \\times \\{1, \\hdots, N_y-1\\}\n    \\end{align}  \n\\end{subequations}\n\n\n% $\\underline{d} = \\{0, \\hdots, N_x-1\\} \\times \\{0, \\hdots, N_y-1\\}$ and $\\underline{\\overline{d}} = \\{1, \\hdots, N_x-1\\}\\times\\{1, \\hdots, N_y-1\\}$.\n\nBelow, the steps to perform energy analysis presented in Section \\ref{sec:energyAnalysis} will be followed:\n\\subsubsection{Step 1: Obtain $\\dtp \\h$}\nUsing the definition of wave speed for the ideal membrane, i.e., $c = \\sqrt{T/ \\rho H}$, the FD scheme in Eq. \\eqref{eq:2DwaveFDS} can be multiplied by $\\rho H$ and a 2D inner product (see Eq. \\eqref{eq:2DInnerProd}) with $(\\dtd \\ulmn)$ over discrete domain $d$ can be taken to yield a definition for $\\dtp \\h$:\n\\begin{equation*}\n    \\dtp \\h = \\rho H\\langle \\dtd \\ulmn , \\dtt \\ulmn\\rangle_d - T \\langle \\dtd\\ulmn, \\dDelta \\ulmn\\rangle_d = 0,\n\\end{equation*}\nwhich can be rewritten to\n\\begin{equation*}\n    \\dtp \\h= \\rho H\\langle \\dtd \\ulmn , \\dtt \\ulmn\\rangle_d - T \\left(\\langle \\dtd\\ulmn, \\dxx \\ulmn\\rangle_d + \\langle \\dtd\\ulmn, \\dyy \\ulmn\\rangle_d \\right) = 0.\n\\end{equation*}\\todo{FULL DOC SWEEP: check what equations have numbers when performing energy analysis (and stability for that matter)}\n\n\\subsubsection{Step 2: Identify energy types and isolate $\\dtp$}\nSummation by parts as described in Section \\ref{sec:summationByParts} can also be applied to $\\dyy$ and the following energy balance follows \n\\begin{equation*}\n    \\dtp \\h = \\b,\n\\end{equation*}\nwhere \n\\begin{equation}\\label{eq:energyBalance2DWave}\n    \\begin{gathered}\n        \\h = \\t + \\v \\qwiq \\t = \\frac{\\rho H}{2}\\lVert \\dtm \\ulmn\\rVert^2_d \\quad \\text{and}\n        \\\\\n        \\v = \\frac{T}{2} \\left(\\langle \\dxp \\ulmn, e_{t-}\\dxp \\ulmn\\rangle_{\\domXred} + \\langle \\dyp \\ulmn, e_{t-}\\dyp \\ulmn\\rangle_{\\domYred} \\right).\n    \\end{gathered}\n\\end{equation}\nHere, the reduced domains $\\domXred$ and $\\domYred$ are as defined in Eqs. \\eqref{eq:reduced2Ddoms}. The boundary term is \n\\begin{equation*}\n    \\begin{aligned}\n    \\b =\\frac{T}{2}\\Bigg[&\\langle \\dtd u_{N_x,m}^n, \\dxp u_{N_x,m}^n \\rangle_{(N_x, y)} -\\langle \\dtd u_{0,m}^n, \\dxm u_{0,m}^n \\rangle_{(0, y)}\\\\\n    &+ \\langle \\dtd u_{l,N_y}^n, \\dyp u_{l,N_y}^n \\rangle_{(x, N_y)} - \\langle \\dtd u_{l,0}^n, \\dym u_{l,0}^n \\rangle_{(x, 0)}\\Bigg]\\ ,\n    \\end{aligned}\n\\end{equation*}\nwhere $(l,y) = \\{l\\}\\times\\{0, \\hdots, N_y\\}$ and $(x,m) = \\{0, \\hdots,  N_x\\}\\times\\{m\\}$ are slices of domain $d$. The boundary term can be shown to vanish under Dirichlet boundary conditions in Eq. \\eqref{eq:discDirichlet2D}. Neumann conditions will not be considered here.\n\n\\subsubsection{Step 3: Check units}\nAs the addition of the two inner products in the definition for $\\v$ in Eq. \\eqref{eq:energyBalance2DWave} does not affect the units, only one term is used to check the units. Recalling that, as opposed to the 1D case, the symbol $T$ is tension per unit length and thus in N/m, one can write the terms in Eq. \\eqref{eq:energyBalance2DWave} in their units:\n\\begin{align*}\n    \\t = \\frac{\\rho H}{2}\\lVert \\dtm \\ulmn\\rVert^2_d \\\n    \\overset{\\text{in units}}{\\xrightarrow{\\hspace*{1cm}}}    \\quad&\\text{kg}\\cdot\\text{m}^{-3}\\cdot\\text{m}\\cdot\\text{m}^2\\cdot(\\text{s}^{-1}\\cdot\\text{m})^2 \\\\\n    = \\ & \\text{kg}\\cdot\\text{m}^2\\cdot\\text{s}^{-2}\\\\\n    \\v =\\frac{T}{2} \\langle \\dxp \\ulmn, e_{t-}\\dxp \\ulmn\\rangle_{\\domXred} \\\n     \\overset{\\text{in units}}{\\xrightarrow{\\hspace*{1cm}}} \\quad& \\text{N} \\cdot \\text{m}^{-1}\\cdot\\text{m}^2\\cdot(\\text{m}^{-1}\\cdot\\text{m})\\cdot(\\text{m}^{-1}\\cdot\\text{m})\\nonumber \\\\\n    = \\ &\\text{kg}\\cdot\\text{m}^2\\cdot\\text{s}^{-2}\n\\end{align*}\nwhich have the correct units. \n\n\\subsubsection{Step 4: Implementation}\nFigure \\ref{fig:energy2Dwave} shows the energetic output of an implementation of the 2D wave equation and shows that the energy deviation is within machine precision.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{tikzpicture}[->,node distance=3cm,\n        thick,main node/.style={circle,draw}]\n    \n        \\node[] (image) at (0,0) {\n        \\includegraphics[width=\\textwidth]{figures/resonators/2d/energy2DWave.eps}\n        };\n    \n        \\node[] (he) at (0.2,0.5) {\\small $\\mathfrak{h}_\\text{e}$};\n\n        \\node[] (h) at (-5.75, 1) {\\small $\\mathfrak{h}$};\n        \\node[] (v) at (-5.75, 0.5) {\\small $\\color{red}\\mathfrak{v}$};\n        \\node[] (t) at (-5.75, 0) {\\small $\\color{blue}\\mathfrak{t}$};\n      \\end{tikzpicture}\n      \\caption{The kinetic (blue), potential (red), and total (black) energy of an implementation of the 2D wave equation are plotted in the left panel. The right panel shows the normalised energy (according to Eq. \\eqref{eq:normalisedEnergy}) and shows that the deviation of the energy is within machine precision. \\label{fig:energy2Dwave}}\n\\end{figure}\n\n\\subsection{Modal analysis in 2D}\nGiven that the state vector is stacked as described in Section \\ref{sec:2DwaveImplementation} and the update equation is written in matrix form as in Eq. \\eqref{eq:matrixUpdate2Dwave}, performing a modal analysis on a 2D system does not differ from a 1D system and follows the same process presented in Section \\ref{sec:modalAnalysis}.\n\nInserting a test solution of $\\uStack^n = z^n\\boldPhi$ into the matrix form of the 2D wave equation in Eq. \\eqref{eq:matrixUpdate2Dwave} yields the following characteristic equation\n\\begin{equation}\n   \\left(z - 2 + z^{-1}\\right)\\boldPhi = c^2k^2\\DDeltamat\\boldPhi.\n\\end{equation}\nThe $p$\\th modal frequency can then be obtained by finding the roots of \n\\begin{equation}\n    z_p + \\left(-2 - c^2k^2\\text{eig}_p(\\DDeltamat)\\right) + z_p^{-1} = 0,\n\\end{equation}\nwhich, using test solution $z_p = e^{j\\omega_p k}$ for (angular) frequency $\\omega_p$, can be shown to be \n\\begin{equation}\\label{eq:2DWaveModes}\n    f_p = \\frac{1}{\\pi k}\\sin^{-1}\\left(\\frac{ck}{2}\\sqrt{-\\text{eig}_p(\\DDeltamat)}\\right).\n\\end{equation}\nNotice the similarity to the equation for the modal frequencies of the 1D wave equation in Eq. \\eqref{eq:1DWaveModes}. Again, the number of modes is equal to the number of moving grid points in the system. \n\nSee Figure \\ref{fig:modalFreqs2Dwave} for the result of a modal analysis of the 2D wave equation. One can observe that the modes do not follow a linear pattern as opposed to those of the 1D wave equation shown in Figure \\ref{fig:modalFreqs1Dwave}. This confirms the inharmonic behaviour of the 2D wave equation discussed \\ref{sec:2DwaveImplementation}. \n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width = 0.6\\textwidth]{figures/resonators/2d/modes2Dwave.eps}\n    \\caption{Modal frequencies of the 2D wave equation with $L_x = 1.5$ m, $L_y = 1$ m and $c\\approx 3118$ m/s, such that $\\lambda = 1/\\sqrt{2}$ according to Eq. \\eqref{eq:CFL2D}. \\label{fig:modalFreqs2Dwave}}\n\\end{figure}\n\\subsubsection{Modal shapes}\nUsing the line of code in Appendix \\ref{sec:eigenValueProblems} and the \\texttt{reshape} function, the modal shapes of the system can also be obtained. Figure \\ref{fig:modalShapes2D} shows the six lowest-frequency modes of the 2D wave equation with $L_x = 1.5$ m and $L_y = 1$ m. The mode number $(x,y)$ corresponds to the modal number in the $x$ and $y$ direction.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/resonators/2d/modalShapes.eps}\n    \\caption{The first six (lowest-frequency) modal shapes of 2D wave equation with $L_x = 1.5$ m and $L_y = 1$ m.%and rho = 7850; H =  0.0005; T = 1000000;\n    \\label{fig:modalShapes2D}}\n\\end{figure}\n\n\\section{The thin plate}\\label{sec:thinPlate}\nThe thin plate, also known as the Kirchhoff model \\cite{Kirchhoff1968}, differs from the 2D wave equation in that its restoring force is solely due to stiffness rather than tension. Like for the stiffness term in the stiff string (see Chapter \\ref{ch:stiffString}), this causes frequency dispersion, and exhibits interesting timbres. \n\nThe plate model is quite versatile and can be used to model a plate reverb \\cite{DAFxChapter} as well as simplified instrument bodies, as done in \\citeP[A], \\citeP[B], \\citeP[D] and \\citeP[E]. This section presents the thin plate PDE and FD scheme, after which it will be subjected to the various analysis techniques extended to 2D in the previous section.\n\n\\subsection{Continuous time}\nConsider a rectangular thin plate with side lengths $L_x$ and $L_y$ (both in m) and its transverse displacement described by $u=u(x,y,t)$ (in m). The system is defined for $(x,y)\\in \\D$ where 2D domain $\\D = [0, L_x]\\times [0, L_y]$. Using the biharmonic operator introduced in Eq. \\eqref{eq:biharmonic}, the PDE for the thin plate can be defined as \\cite{Kirchhoff1968}\n\\begin{equation}\\label{eq:platePDENoLosses}\n    \\rho H \\ptt u = -D\\Delta\\Delta u,\n\\end{equation}\nwhere $D = EH^3/12(1-\\nu^2)$ is a stiffness coefficient (in kg $\\cdot$ m$^2\\cdot$s$^{-2}$) parametrised by Young's Modulus $E$ (in Pa), thickness $H$ (in m) and the dimensionless Poisson's ratio $\\nu$. Although Eq. \\eqref{eq:platePDENoLosses} does not hold for thick plates and only accounts for low-amplitude vibration (as it is linear), these properties can be assumed in musical instrument simulations, making this model sufficient in this work. \n\nAdding losses to Eq. \\eqref{eq:platePDENoLosses} yields\n%\n\\begin{equation}\\label{eq:platePDE}\n    \\rho H \\ptt u = -D\\Delta\\Delta u - 2\\sz \\rho H \\pt u + 2 \\so\\rho H  \\pt \\Delta u\n\\end{equation}\nwhere, as in the case of the stiff string in Eq. \\eqref{eq:stiffStringPDE}, $\\sz$ and $\\so$ are the frequency independent (in s$^{-1}$) and frequency dependent damping coefficient (in m$^2$/s) respectively.\\todo{check hyphens after `frequency'}\n\n\\subsubsection{Boundary conditions}\nSimilar to the stiff string, clamped and simply supported boundary conditions can be defined as\n\\begin{subequations}\\label{eq:boundaryCondThinPlate}\n    \\begin{align}\n        \\begin{rightcases}\n            u = \\px u = 0,\\quad \\text{if } y=\\{0 , L_y\\}, \\quad \\forall x\\\\\n            u = \\py u = 0,\\quad \\text{if } x=\\{0 , L_x\\},\\quad \\forall y\n        \\end{rightcases}\n     \\quad &\\text{(Clamped)},\\label{eq:contClamped2D}\\\\\n     \\begin{rightcases}\n        u = \\pxx u = 0,\\quad \\text{if } y=\\{0 , L_y\\}, \\quad \\forall x\\\\\n        u = \\pyy u = 0,\\quad \\text{if } x=\\{0 , L_x\\},\\quad \\forall y\n    \\end{rightcases}\\quad &\\text{(Simply supported)}.\\label{eq:contSimplySupported2D}\n    \\end{align}\n\\end{subequations}\n Naturally, a free condition can be added too, but is much less trivial. As it will not be used in this work, it will not be given here, and the interested reader is instead referred to \\cite[Ch. 12]{theBible}. \n\n\\subsection{Discrete time}\nEquation \\eqref{eq:platePDE} can be discretised to the following FD scheme:\n\\begin{equation}\\label{eq:thinPlateFDS}\n    \\rho H \\dtt \\ulmn = - D \\dDelta\\dDelta\\ulmn - 2\\sz \\rho H \\dtd \\ulmn + 2 \\so \\rho H \\dtm \\dDelta\\ulmn\n\\end{equation}\nwhere $l\\in\\{0, \\hdots, N_x\\}$ and $m\\in\\{0, \\hdots, N_y\\}$. Like for the stiff string FD scheme in Eq. \\eqref{eq:stiffStringFDS}, the backwards difference operator is used for the frequency-dependent damping term to yield an explicit scheme. A more compact way to write this scheme is after a division by $\\rho H$ which yields\n\\begin{equation}\\label{eq:thinPlateFDSCompact}\n    \\dtt \\ulmn = - \\kappa^2\\dDelta\\dDelta\\ulmn - 2\\sz\\dtd \\ulmn + 2 \\so \\dtm \\dDelta\\ulmn\n\\end{equation}\nwith\n\\begin{equation}\\label{eq:kappaDef}\n     \\kappa = \\sqrt{\\frac{D}{\\rho H}}\\ .\n\\end{equation}\nUsing the expansion of the discrete biharmonic operator in Eq. \\eqref{eq:discreteBiharmonic}, Eq. \\eqref{eq:thinPlateFDSCompact} can be expanded and solved for $\\ulm^{n+1}$ according to\n\\begin{equation}\\label{eq:plateUpdate}\n    \\begin{aligned}\n    \\ulm^{n+1} =&\\ (2-20\\mu^2 - 4S)\\ulmn \\\\\n    &\\ \\ \\ +(8\\mu^2 + S)(u_{l+1, m}^n + u_{l-1, m}^n+u_{l, m+1}^n+u_{l, m-1}^n)\\\\\n    &\\ \\ \\ -2\\mu^2(u_{l+1, m+1}^n + u_{l-1, m+1}^n+u_{l+1, m-1}^n+u_{l-1, m-1}^n)\\\\\n    &\\ \\ \\ -\\mu^2(u_{l+2, m}^n + u_{l-2, m}^n+u_{l, m+2}^n+u_{l, m-2}^n),\\\\\n    &\\ \\ \\ + (\\sz k  - 1 + 4S) \\ulm^{n-1}\\\\\n    &\\ \\ \\ - S (u_{l+1, m}^{n-1} + u_{l-1, m}^{n-1}+u_{l, m+1}^{n-1}+u_{l, m-1}^{n-1})\n    \\end{aligned}\n\\end{equation}\nwhere \n\\begin{equation}\n    \\mu = \\frac{\\kappa k}{h^2}\n\\end{equation}\nand $S = 2\\so k / h^2$ for compactness. See Figure \\ref{fig:plateStencil} for the stencil of this scheme.\n\\def\\figSpacing{0.01\\textwidth}\n\\def\\figWidth{0.49\\textwidth}\n\\begin{figure}[t]\n    \\centering\n    \\subfloat[Full stencil.\\label{fig:fullStencilPlate}]{\\includegraphics[width=\\figWidth]{figures/resonators/2d/fullPlate.eps}}\\\\\n    \\subfloat[Stencil of $u_{l,m}^n$. \\label{fig:curStencilPlate}]{\\includegraphics[width=\\figWidth]{figures/resonators/2d/curPlateStencil.eps}}\\hspace{\\figSpacing}\n    \\subfloat[Stencil of $u_{l,m}^{n-1}$.\\label{fig:prevStencilPlate}]{\\includegraphics[width=\\figWidth]{figures/resonators/2d/prevPlateStencil.eps}}\n    \\caption{The stencil of the plate with coefficients corresponding to those in update equation \\eqref{eq:plateUpdate}. (a) A full overview of the stencil. (b) The current time-step $n$ highlighted. (c) The previous time-step $n-1$ highlighted. \\label{fig:plateStencil}}\n\\end{figure}\n%\nThe stability condition of the scheme can be shown to be\n\\begin{equation}\\label{eq:stabilityPlate}\n    h \\geq 2\\sqrt{k\\bigg(\\sigma_1 + \\sqrt{\\kappa^2+ \\sigma_1^2}\\bigg)},\n\\end{equation}\nand will be derived in Section \\ref{sec:stabilityThinPlate}.\n\n\\subsubsection{Discrete boundary conditions}\nThe boundary conditions shown in Eq. \\eqref{eq:boundaryCondThinPlate} can be discretised to \n\\begin{subequations}\\label{eq:boundaryCondThinPlateDisc}\n    \\begin{align}\n        \\begin{rightcases}\n            \\begin{aligned}\n                \\ulmn = \\dxp \\ulmn = 0\\quad &\\text{if } m=0 \\ && \\forall l\\\\\n                \\ulmn = \\dxm \\ulmn = 0\\quad &\\text{if } m=N_y \\ && \\forall l\\\\\n                \\ulmn = \\dyp \\ulmn = 0\\quad &\\text{if } l=0 \\ && \\forall m\\\\\n                \\ulmn = \\dym \\ulmn = 0\\quad &\\text{if } l=N_x \\ && \\forall m\n            \\end{aligned}\n        \\end{rightcases}\n     \\quad &\\text{(Clamped)},\\label{eq:discClamped2D}\\\\\n     \\begin{rightcases}\n        \\begin{aligned}\n            \\ulmn = \\dxx \\ulmn = 0\\quad &\\text{if } m=\\{0 , N_y\\} \\ &&\\forall l\\\\\n            \\ulmn = \\dyy \\ulmn = 0\\quad &\\text{if } l=\\{0 , N_x\\}\\ &&\\forall m\n        \\end{aligned}\n    \\end{rightcases}\\quad &\\text{(Simply supported)}.\\label{eq:discSimplySupported2D}\n    \\end{align}\n\\end{subequations}\nThe clamped condition can be implemented by simply reducing the discrete range of operation to $l = \\{2, \\hdots, N_x-2\\}$ and $m = \\{2, \\hdots, N_y-2\\}$. For the simply supported case, the range of operation reduces to $l = \\{1, \\hdots, N_x-1\\}$ and $m = \\{1, \\hdots, N_y-1\\}$, and similar to the simply supported stiff string described in Section \\ref{sec:stiffStringBoundaryConditions}, the virtual grid points needed for this condition become\n\\begin{align*}\n    u_{-1, m}^n = -u_{1, m}^n &\\qaq u_{N_x+1, m}^n = -u_{N_x-1, m}^n\\quad\\forall m,\\\\\n    u_{l, -1}^n = -u_{l, -1}^n &\\qaq u_{l, N_y+1}^n = -u_{l, N_y-1}^n\\qquad \\forall l.\n\\end{align*}\n\n\\subsection{Matrix form and output}\nSimilar to the implementation of the 2D wave equation in Section \\ref{sec:2DwaveImplementation}, one can use a stacked state vector. If simply supported boundary conditions are used, one can easily obtain a matrix form of the $\\dDelta\\dDelta$ operator by multiplying two $\\DDeltamat$ matrices presented in Eq. \\eqref{eq:DDeltaMatrix} to get $\\DDeltaDelta = \\DDeltamat\\DDeltamat$.\n\nUsing a stacked form of the state as described in Eq. \\eqref{eq:stackedState} the scheme in Eq. \\eqref{eq:thinPlateFDSCompact} in matrix form is     \n\\begin{equation}\\label{eq:matrixFormThinPlate}\n    A\\uStack^{n+1} = \\B\\uStack^n + \\C\\uStack^{n-1},\n\\end{equation}\nwhere\n\\begin{gather*}\n    A = (1+\\sz k),\\quad \\B = 2\\I - \\kappa^2 k^2 \\DDeltaDelta + 2 \\so k\\DDeltamat, \\\\\n    \\text{and}\\quad \\C = -(1-\\sz k)\\I - 2\\so k \\DDeltamat,\n\\end{gather*}\nand the identity matrix $\\I$ is of the same size as $\\DDeltaDelta$ and $\\DDeltamat$.\n\nAs a starting point for implementation, possible parameters are given in Table \\ref{tab:thinPlateParams}. Figure \\ref{fig:thinPlatePropagation} shows the wave propagation of a thin plate using these parameters, and excited using the same excitation as used for the 2D wave equation in Section \\ref{sec:2DwaveImplementation} (a 2D raised cosine at $(x,y) = (0.25L_x, 0.5L_y)$). When compared to Figure \\ref{fig:2Dpropagation}, dispersive effects -- where higher-frequency components travel faster than lower-frequency ones -- are apparent due to stiffness.\n\n\\begin{table}[h]\n    \\begin{center}\n    \\begin{tabular}{|l|c|c|}\n        \\hline\n        Name & Symbol (unit) & Value\\\\ \\hline\n        Side length $x$ & $L_x$ (m) & $1.5$\\\\\n        Side length $y$  & $L_y$ (m) & $1$\\\\\n        Material density & $\\rho$ (kg/m$^3$) & $7850$\\\\\n        Thickness & $H$ (m) & $5\\cdot10^{-3}$\\\\\n        Young's modulus & $E$ (Pa) & $2\\cdot10^{11}$\\\\\n        Poisson's ratio & $\\nu$ (-)& $0.3$\\\\\n        Freq.-independent damping & $\\sz$ (s$^{-1}$) & $1$\\\\\n        Freq.-dependent damping & $\\so$ (m$^2$/s) & $0.005$\\\\\\hline\n    \\end{tabular}\n    \\caption{Parameters for the thin plate and possible values to use as a starting point for the simulation.\\label{tab:thinPlateParams}}\n    \\end{center}\n\\end{table}\n{\\renewcommand{\\arraystretch}{1}\n\nFigure \\ref{fig:outputThinPlate} shows the time domain and frequency domain output of the thin plate at $(x,y) = (0.15L_x, 0.85 L_y)$.\nCompared to the output of the 2D wave equation in Figure \\ref{fig:output2DWave}, there are several interesting differences. The amplitude is much lower, waves are closer together and the first wave arrives much earlier, all due to dispersive effects.\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width = \\textwidth]{figures/resonators/2d/thinPlatePropagation.eps}\n    \\caption{Wave propagation of a thin plate with simply supported boundary conditions and parameters as shown in Table \\ref{tab:thinPlateParams}. The system is excited with a 2D raised cosine at $(x,y) = (0.25L_x, 0.5L_y)$ and dispersive effects are apparent.\\label{fig:thinPlatePropagation}}\n\\end{figure}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/resonators/2d/outputThinPlate.eps}\n    \\caption{The output of the thin plate at $(x,y) = (0.15, 0.85)$ corresponding to Figure \\ref{fig:thinPlatePropagation}. \\label{fig:outputThinPlate}}\n\\end{figure}\\todo{FULL DOC SWEEP: check figure alignment}\n\n\\subsection{Frequency domain analysis}\\label{sec:stabilityThinPlate}\nThis section follows the process presented in Section \\ref{sec:stabilityAnalysis} with the extensions to 2D shown in \\ref{sec:stability2Dwave}.\n\nUsing Eqs. \\eqref{eq:laplacianAnsatz} and \\eqref{eq:biharmonicAnsatz} one can obtain a frequency domain representation of the FD scheme in Eq. \\eqref{eq:thinPlateFDSCompact}\nand obtain the following characteristic equation\n\\begin{equation}\n    \\begin{aligned}\n        (1+\\sigma_0k)z + &\\left(16\\mu^2(p_x+p_y)^2 + \\frac{8\\sigma_1k}{h^2}(p_x+p_y) - 2\\right) \\\\\n        &+ \\left(1 - \\sigma_0k - \\frac{8\\sigma_1k}{h^2}(p_x+p_y)\\right)z^{-1} = 0.\n    \\end{aligned}\n\\end{equation}\nThis can, similar to the damped stiff string in Section \\ref{sec:stiffStringStability}, be solved to\n\\begin{equation*}\n    4\\mu^2(p_x+p_y)^2 + \\frac{4\\sigma_1k}{h^2}(p_x+p_y) \\leq 1.\n\\end{equation*}\nRecalling the definitions $p_x$ and $p_y$ in Eq. \\eqref{eq:pxpy}, and given the fact that these are bounded by 1, the following can be written\n\\begin{gather*}\n    4\\mu^2(1+1)^2 + \\frac{4\\sigma_1k}{h^2}(1+1) \\leq 1\\\\\n    16\\mu^2 + \\frac{8\\sigma_1k}{h^2} \\leq 1.\n\\end{gather*}\nFinally, recalling the definition for $\\kappa$ in Eq. \\eqref{eq:kappaDef} solving for $h$ yields\n\\begin{align}\n    &1 \\geq \\frac{16\\kappa^2k^2}{h^4} + \\frac{8\\sigma_1k}{h^2}\\nonumber,\\\\\n    &h^4 - 8\\sigma_1kh^2 - 16\\kappa^2k^2 \\geq 0\\nonumber,\\\\\n    &h \\geq \\sqrt{\\frac{8\\sigma_1k +\\sqrt{(8\\sigma_1k)^2 + 64\\kappa^2k^2}}{2}}\\nonumber,\\\\\n    &h\\geq \\sqrt{\\frac{8\\sigma_1k+8\\sqrt{\\sigma_1^2k^2+\\kappa^2k^2}}{2}}\\nonumber,\\\\\n    &h \\geq 2\\sqrt{k\\left(\\sigma_1 + \\sqrt{\\sigma_1^2 + \\kappa^2}\\right)},\n\\end{align}\nwhich is the stability condition given in Eq. \\eqref{eq:stabilityPlate}.\n\n\\subsection{Energy analysis}\\label{sec:energyAnalysisThinPlate}\nUsing the steps described in Section \\ref{sec:energyAnalysis} with the extensions to 2D presented in Section \\ref{sec:energyAnalysis2DWave}, one can obtain the total energy of the FD scheme in Eq. \\eqref{eq:thinPlateFDSCompact}.\n\\subsubsection{Step 1: Obtain $\\dtp \\h$}\nTo obtain the rate of change of the total energy, one can take an inner product of the scheme in Eq. \\eqref{eq:thinPlateFDSCompact} with $(\\dtd \\ulmn)$ over discrete (2D) domain $d = \\{0, \\hdots, N_x\\}\\times \\{0, \\hdots, N_y\\}$ to get\n\\begin{equation}\\label{eq:rOCthinPlate}\n    \\begin{aligned}\n        \\dtp \\h =&\\ \\rho H \\langle \\dtd \\ulmn, \\dtt \\ulmn \\rangle_d + D \\langle \\dtd \\ulmn, \\dDelta\\dDelta \\ulmn \\rangle_d\\\\\n        & + 2\\sz\\rho H\\langle \\dtd \\ulmn, \\dtd \\ulmn \\rangle_d - 2\\so \\rho H\\langle \\dtd \\ulmn, \\dtm \\dDelta \\ulmn \\rangle_d = 0.\n    \\end{aligned}\n\\end{equation}\n\n\\subsubsection{Step 2: Identify energy types and isolate $\\dtp$}\nDue to the damping present in the system and because the system is distributed in space, the energy balance will be of the following form\n\\begin{equation*}\n    \\dtp \\h = \\b-\\q, \n\\end{equation*}\nwith boundary term $\\b$ and damping term\n\\begin{equation}\\label{eq:dampingTermThinPlate}\n    \\mathfrak{q} = 2\\sz \\rho H \\lVert\\dtd\\ulmn\\rVert_d^2 - 2 \\so \\rho H \\langle \\dtd \\ulmn, \\dtm \\dDelta\\ulmn \\rangle_d.\n\\end{equation}\nExpanding the stiffness term in Eq. \\eqref{eq:rOCthinPlate} to\n\\begin{align*}\n    &\\ D\\langle \\dtd \\ulmn, (\\dxx + \\dyy)\\dDelta \\ulmn \\rangle_d\\\\\n    \\Longleftrightarrow\\ \\ &\\ D\\left(\\langle \\dtd \\ulmn, \\dxx\\dDelta \\ulmn \\rangle_d + \\langle \\dtd \\ulmn, \\dyy\\dDelta \\ulmn \\rangle_d\\right),\n\\end{align*} \none can perform summation by parts twice, using Eq. \\eqref{eq:summationByPartsTwiceReduced} for both terms to get\n\\begin{equation*}\n    D\\left(\\langle \\dtd \\dxx\\ulmn, \\dDelta \\ulmn \\rangle_{\\domXredBoth} + \\langle \\dtd\\dyy \\ulmn, \\dDelta \\ulmn \\rangle_{\\domYredBoth}\\right) + \\b.\n\\end{equation*}\nThe definitions for the reduced domains can be found in Eqs. \\eqref{eq:reduced2Ddoms}. Finally, as the boundaries are always $0$ due to the boundary conditions in Eq. \\eqref{eq:boundaryCondThinPlateDisc}, $\\domXredBoth$ and $\\domYredBoth$ can be further reduced to $\\domRedBoth$ and the terms can be combined as \\SWcomment[check with stefan]\\todo{FULL DOC SWEEP: check for SWcomments}\n\\begin{equation*}\n    D\\langle \\dtd\\dDelta\\ulmn, \\dDelta \\ulmn \\rangle_{\\domRedBoth} + \\b ,\n\\end{equation*}\nand using identities \\eqref{eq:prodIdentity1} and \\eqref{eq:prodIdentity2} a definition for the total energy can be found:\n\\begin{equation}\\label{eq:energyBalanceThinPlate}\n    \\begin{gathered}\n        \\h = \\t + \\v, \\qwiq \\t = \\frac{\\rho H}{2} \\left\\lVert\\delta_{t-}\\ulmn\\right\\rVert_{d}^2 \\quad \\text{and} \\\\\n        \\v = \\frac{D}{2}\\langle\\dDelta \\ulmn, e_{t-}\\dDelta \\ulmn\\rangle_{\\overline{\\underline{d}}}\\ .\n    \\end{gathered}\n\\end{equation}\nThe definition of the boundary term $\\b$ will not be given here, but can be shown to vanish under the boundary conditions given in Eq. \\eqref{eq:boundaryCondThinPlateDisc} \\cite{theBible}.\n\n\\subsubsection{Step 3: Check units}\nAs $\\t$ is identical to its definition in Eq. \\eqref{eq:energyBalance2DWave}, only the units for $\\v$ will be checked here. Recalling that $D = EH^3 / 12(1-\\nu^2)$, which in units is kg$\\cdot$ m$^2\\cdot$s$^{-2}$, yields\n\\begin{align*}\n    \\v = \\frac{D}{2}\\langle\\dDelta \\ulmn, e_{t-}\\dDelta \\ulmn\\rangle_{\\overline{\\underline{d}}} \\\n    \\overset{\\text{in units}}{\\xrightarrow{\\hspace*{1cm}}} \\ & \\text{kg} \\cdot \\text{m}^2\\cdot\\text{s}^{-2}\\cdot\\text{m}^2\\cdot(\\text{m}^{-2}\\cdot\\text{m})\\cdot(\\text{m}^{-2}\\cdot\\text{m})\\nonumber \\\\\n    = \\ &\\text{kg}\\cdot\\text{m}^2\\cdot\\text{s}^{-2}\n\\end{align*}\nand shows that $\\v$ indeed has the correct units. \n\n\\subsubsection{Step 4: Implementation}\nFigure \\ref{fig:energyThinPlate} shows the energetic output of an implementation of the thin plate and shows that the energy is conserved.\n\\begin{figure}[h]\n    \\centering\n    \\begin{tikzpicture}[->,node distance=3cm,\n        thick,main node/.style={circle,draw}]\n    \n        \\node[] (image) at (0,0) {\n        \\includegraphics[width=\\textwidth]{figures/resonators/2d/energyThinPlate.eps}\n        };\n    \n        \\node[] (he) at (0.2,0.5) {\\small $\\mathfrak{h}_\\text{e}$};\n\n        \\node[] (h) at (-5.75, 1) {\\small $\\mathfrak{h}$};\n        \\node[] (v) at (-5.75, 0.5) {\\small $\\color{red}\\mathfrak{v}$};\n        \\node[] (t) at (-5.75, 0) {\\small $\\color{blue}\\mathfrak{t}$};\n      \\end{tikzpicture}\n      \\caption{The kinetic (blue), potential (red), and total (black) energy of an implementation of the thin plate are plotted in the left panel. Notice that the damping present in the system causes $\\h$ to decrease. The right panel shows the normalised energy (according to Eq. \\eqref{eq:normalisedEnergyDamping}) and shows that the deviation of the energy is within machine precision. \\label{fig:energyThinPlate}}\n\\end{figure}\n\n\\subsection{Modal analysis}\nUsing the matrix form in Eq. \\eqref{eq:matrixFormThinPlate}, a modal analysis of the system can be performed using a one-step form described in Section \\ref{sec:oneStepForm}.\n\nFigure \\ref{fig:thinPlateModes} shows the results of the analysis with parameter values as listed in Table \\ref{tab:thinPlateParams}. Although the modal frequencies follow a similar pattern to those of the 2D wave equation in Figure \\ref{fig:modalShapes2D}, the pattern is slightly more exponential like the stiff string in Figure \\ref{fig:modesStiffString}.\\SWcomment[not really sure what to say here honestly] \n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/resonators/2d/thinPlateModes.eps}\n    \\caption{The result of a modal analysis of the thin plate using the parameters in Table \\ref{tab:thinPlateParams}. Notice that the damping is plotted against modal frequency rather than mode number. \\label{fig:thinPlateModes}}\n\\end{figure}\n\n\\section{The stiff membrane}\nThe term \\textit{stiff membrane} first appeared in \\cite{Fletcher1998}\\todo{true?} and is essentially a 2D version of the stiff string. It can be used to model membranes with dispersive effects or provide tension control for thin plates. In this work, the stiff membrane has only been used in paper \\citeP[F] to model a drum membrane. \n\nSimilar to previous sections, this section will provide the continuous-time and discrete-time equations of the model. Only a frequency domain analysis will be given, as energy and modal analyses are too similar to those previously presented.\n\n\\subsection{Continuous time}\nThe PDE for a stiff membrane can be obtained as a combination of the 2D wave equation in Eq. \\eqref{eq:2DwavePDE} and the thin plate in Eq. \\eqref{eq:platePDENoLosses}. Adding losses as in Eq. \\eqref{eq:platePDE} yields the following PDE\n\\begin{equation}\\label{eq:stiffMembranePDE}\n    \\rho H \\ptt u = T\\Delta u - D\n    \\Delta\\Delta u- 2\\sz \\rho H \\pt u + 2 \\so\\rho H  \\pt \\Delta u,\n\\end{equation}\nwhere the parameters are identical to those in Eqs. \\eqref{eq:2DwavePDE} and \\eqref{eq:platePDE}.\n\n\\subsection{Discrete time}\nUsing familiar operators, Eq. \\eqref{eq:stiffMembranePDE} can be discretised to \n\\begin{equation}\\label{eq:stiffMembraneFDS}\n    \\rho H \\dtt \\ulmn = T\\dDelta\\ulmn- D \\dDelta\\dDelta\\ulmn - 2\\sz \\rho H \\dtd \\ulmn + 2 \\so \\rho H \\dtm \\dDelta\\ulmn,\n\\end{equation}\nor, using a more compact form after division by $\\rho H$, to\n\\begin{equation}\\label{eq:stiffMembraneFDScompact}\n    \\dtt \\ulmn = c^2\\dDelta\\ulmn- \\kappa^2 \\dDelta\\dDelta\\ulmn - 2\\sz \\dtd \\ulmn + 2 \\so \\dtm \\dDelta\\ulmn,\n\\end{equation}\nwhere $c = \\sqrt{T / \\rho H}$ and $\\kappa = \\sqrt{D / \\rho H}$.\n\nThe update equation can then be obtained using the expansions of the Laplacian and biharmonic operators in Eqs. \\eqref{eq:discreteLaplacian} and \\eqref{eq:discreteBiharmonic} respectively, to get\n\\begin{equation}\\label{eq:stiffMembraneUpdate}\n    \\begin{aligned}\n    \\ulm^{n+1} =&\\ (2 - 4\\lambda^2 - 20\\mu^2 - 4S)\\ulmn \\\\\n    &\\ \\ \\ +(\\lambda^2 + 8\\mu^2 + S)(u_{l+1, m}^n + u_{l-1, m}^n+u_{l, m+1}^n+u_{l, m-1}^n)\\\\\n    &\\ \\ \\ -2\\mu^2(u_{l+1, m+1}^n + u_{l-1, m+1}^n+u_{l+1, m-1}^n+u_{l-1, m-1}^n)\\\\\n    &\\ \\ \\ -\\mu^2(u_{l+2, m}^n + u_{l-2, m}^n+u_{l, m+2}^n+u_{l, m-2}^n),\\\\\n    &\\ \\ \\ + (\\sz k  - 1 + 4S) \\ulm^{n-1}\\\\\n    &\\ \\ \\ - S (u_{l+1, m}^{n-1} + u_{l-1, m}^{n-1}+u_{l, m+1}^{n-1}+u_{l, m-1}^{n-1})\n    \\end{aligned}\n\\end{equation}\nwhere \n\\begin{equation}\\label{eq:lambdaMuStiffMembrane}\n    \\lambda = \\frac{c k}{h}\\qaq \\mu = \\frac{\\kappa k}{h^2}\n\\end{equation}\nand again, $S = 2\\so k / h^2$ for compactness. The stability condition for this scheme will be given in Section \\ref{sec:stabilityStiffMembrane}.\n\n\\subsection{Implementation}\nWriting Eq. \\eqref{eq:stiffMembraneFDScompact} in matrix form, yields \n\\begin{equation}\n    A\\uStack^{n+1} = \\B\\uStack^n + \\C\\uStack^{n-1},\n\\end{equation}\nwith\n\\begin{gather*}\n    A = (1+\\sz k),\\quad \\B = 2\\I + c^2k^2 \\DDeltamat - \\kappa^2 k^2 \\DDeltaDelta + 2 \\so k\\DDeltamat, \\\\\n    \\text{and}\\quad \\C = -(1-\\sz k)\\I - 2\\so k \\DDeltamat.\n\\end{gather*}\nNotice that the only difference with Eq. \\eqref{eq:matrixFormThinPlate} is the addition of the wave speed term in the definition of the $\\B$ matrix. \n\n\\subsection{Frequency domain analysis}\\label{sec:stabilityStiffMembrane}\nFollowing familiar techniques from Sections \\ref{sec:oneStepForm} and \\ref{sec:stability2Dwave}, the characteristic equation of the FD scheme in Eq. \\eqref{eq:stiffMembraneFDScompact} can be obtained:\n\\begin{equation}\n    \\begin{aligned}\n        (1+\\sigma_0k)z + &\\left(4\\lambda^2 (p_x+p_y) + 16\\mu^2(p_x+p_y)^2 + \\frac{8\\sigma_1k}{h^2}(p_x+p_y) - 2\\right) \\\\\n        &+ \\left(1 - \\sigma_0k - \\frac{8\\sigma_1k}{h^2}(p_x+p_y)\\right)z^{-1} = 0.\n    \\end{aligned}\n\\end{equation}\nSimilar to the stiff string in Section \\ref{sec:stiffStringStability} and the thin plate in Section \\ref{sec:stabilityThinPlate}, this can be solved to \n\\begin{equation*}\n    \\lambda^2(p_x+p_y) + 4\\mu^2(p_x+p_y)^2 + \\frac{4\\sigma_1k}{h^2}(p_x+p_y) \\leq 1,\n\\end{equation*}\nand recalling that $p_x$ and $p_y$ are bounded by $1$, yields\n\\begin{align*}\n    \\lambda^2(1 + 1) + 4\\mu^2(1+1)^2 + \\frac{4\\sigma_1k}{h^2}(1+1) &\\leq 1,\\\\\n    2\\lambda^2 + 16\\mu^2 + \\frac{8\\sigma_1k}{h^2} &\\leq 1 .\n\\end{align*}\nRecalling the definitions for $\\lambda$ and $\\mu$ from \\eqref{eq:lambdaMuStiffMembrane}, one can solve for $h$ \n\\begin{gather}\n    \\frac{2c^2k^2}{h^2}+ \\frac{16\\kappa^2k^2}{h^4} + \\frac{8\\sigma_1k}{h^2} \\leq 1,\\nonumber\\\\\n    h^4 - (2c^2k^2 + 8\\sigma_1k)h^2 - 16\\kappa^2k^2 \\geq 0,\\nonumber\\\\\n    h\\geq \\sqrt{\\frac{2c^2k^2 + 8\\sigma_1k+\\sqrt{(2c^2k^2 + 8\\sigma_1k)^2 + 64\\kappa^2k^2}}{2}},\\nonumber \\\\\n    h\\geq \\sqrt{c^2k^2 + 4\\sigma_1k+\\frac{1}{2}\\sqrt{4(c^2k^2 + 4\\sigma_1k)^2 + 64\\kappa^2k^2}},\\nonumber\\\\\n    h\\geq \\sqrt{c^2k^2 + 4\\sigma_1k+\\sqrt{(c^2k^2 + 4\\sigma_1k)^2 + 16\\kappa^2k^2}},\n\\end{gather}\nand can be used as the stability condition for the stiff membrane.\\footnote{This stability condition was wrong in paper \\citeP[F]. It has been corrected here and included in Appendix \\ref{app:paperErrata}.} \n\\section{Radial coordinates}\\label{sec:radialCoordinates}\nThis chapter presented various models using a Cartesian coordinate system. Circular or elliptical systems, such as membranes or gongs, could be modelled using a radial coordinate system \\cite[Ch. 10]{theBible}. However, using explicit schemes causes these systems to exhibit high amounts of numerical dispersion and reduction of bandwidth \\cite[Ch. 11]{theBible}. For better behaviour, one could resort to an implicit scheme, but this comes with the drawbacks mentioned in Section \\ref{sec:implicitStiffString}. A better alternative is to retain the cartesian coordinate system and set quasi-circular boundary conditions according to a staircase approximation as done in [\\hyperref[ch:listOfPublications]{S4}] (see fx. \\cite{Hamilton2016, Harrison2018}).\n", "meta": {"hexsha": "fd4107195207f4a4b327a2212139190c7827ea18", "size": 55981, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "aauPhdCollectionThesis/resonators/2Dsystems.tex", "max_stars_repo_name": "SilvinWillemsen/phdThesis", "max_stars_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aauPhdCollectionThesis/resonators/2Dsystems.tex", "max_issues_repo_name": "SilvinWillemsen/phdThesis", "max_issues_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aauPhdCollectionThesis/resonators/2Dsystems.tex", "max_forks_repo_name": "SilvinWillemsen/phdThesis", "max_forks_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 70.4163522013, "max_line_length": 855, "alphanum_fraction": 0.6934674264, "num_tokens": 19278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.7151003365206462}}
{"text": "\\subsection{Metric topology}\\label{subsec:metric_topology}\n\n\\begin{definition}\\label{def:metric_space}\\mcite[248]{Engelking1989}\n  A \\term{metric space} is a set \\( X \\) along with a nonnegative real-valued function \\( \\rho: X \\times X \\to [0, \\infty) \\), called a \\term{metric}, also called the \\term{distance function}, such that\n  \\begin{thmenum}[series=def:metric_space]\n    \\thmitem[def:metric_space/M1]{M1} \\( \\rho(x, y) = 0 \\iff x = y \\)\n    \\thmitem[def:metric_space/M2]{M2}(symmetry) \\( \\rho(x, y) = \\rho(y, x) \\)\n    \\thmitem[def:metric_space/M3]{M3}(triangle inequality) \\( \\rho(x, y) \\leq \\rho(x, z) + \\rho(z, y) \\)\n  \\end{thmenum}\n\n  If instead of \\ref{def:metric_space/M1} we have the weaker condition\n  \\begin{thmenum}[resume=def:metric_space]\n    \\thmitem[def:metric_space/pseudometric_identity]{M1'} \\( \\forall x \\in X, \\rho(x, x) = 0 \\),\n  \\end{thmenum}\n  we call \\( \\rho \\) a \\term{pseudometric} and \\( (X, \\rho) \\) a \\term{pseudometric space}.\n\n  \\begin{thmenum}\n    \\thmitem{def:metric_space/subspace} If \\( A \\subseteq X \\) is a set, then the restriction \\( (A, \\rho{\\rvert_A}) \\) is a metric space and it is called a \\term{subspace} of \\( X \\).\n\n    \\thmitem{def:metric_space/ball} Define the function\n    \\begin{balign*}\n       & B: X \\times (0, \\infty) \\to \\pow(X),                   \\\\\n       & B(x, r) \\coloneqq \\{ y \\in X \\colon \\rho(x, y) < r \\}.\n    \\end{balign*}\n\n    The set \\( B(x, r) \\) is called an \\term{open ball} or simply \\term{ball} with \\term{center} \\( x \\) and \\term{radius} \\( r \\).\n\n    The ball \\( B = B(0, 1) \\) is called the \\term{unit ball}.\n\n    \\thmitem{def:metric_space/closed_ball} The set\n    \\begin{equation*}\n      \\overline{B(x, r)} \\coloneqq \\cl(B(x, r))\n    \\end{equation*}\n    is called the \\term{closed ball} with center \\( x \\) and radius \\( r \\).\n\n    \\thmitem{def:metric_space/sphere} The set\n    \\begin{equation*}\n      S(x, r) \\coloneqq \\fr{B(x, r)}\n    \\end{equation*}\n    is called the \\term{sphere} with center \\( x \\) and radius \\( r \\).\n\n    \\thmitem{def:metric_space/bounded_set} A set \\( A \\subseteq X \\) is called \\term{bounded} if it is contained in some ball \\( B(x, r) \\).\n\n    \\thmitem{def:metric_space/bounded_sequence} A \\hyperref[def:sequence]{sequence} \\( \\{ x_k \\}_{k=1}^\\infty \\subseteq X \\) is called \\term{bounded} if the corresponding set \\( \\{ x_k \\colon k = 1, 2, \\ldots \\} \\) is \\hyperref[def:metric_space/bounded_set]{bounded}.\n\n    \\thmitem{def:metric_space/bounded_metric} If every set is bounded, we say that the metric itself is bounded.\n\n    \\thmitem{def:metric_space/bounded_function} We say that a function \\( f: S \\to X \\) from a set \\( S \\) to a metric space \\( (X, \\rho) \\) is \\term{bounded} if its image \\( f(S) \\) is a bounded set in \\( (X, \\rho) \\).\n\n    \\thmitem{def:metric_space/diameter} Define the function\n    \\begin{balign*}\n       & \\diam: \\pow(X) \\to [0, \\infty],                             \\\\\n       & \\diam(A) \\coloneqq \\sup \\{ \\rho(x, y) \\colon x, y \\in A \\},\n    \\end{balign*}\n    whose values include the nonnegative extended real \\hyperref[def:extended_real_numbers]{numbers}.\n\n    If it exists, we call the number \\( \\diam(A) \\) the \\term{diameter of \\( A \\)}.\n\n    \\thmitem{def:metric_space/distance} Define the function\n    \\begin{balign*}\n       & \\op{dist}: X \\times \\pow(X) \\to [0, \\infty),                    \\\\\n       & \\op{dist}(x, A) \\coloneqq \\inf \\{ \\rho(x, a) \\colon a \\in A \\}.\n    \\end{balign*}\n\n    We call the number \\( \\op{dist}(x, A) \\) the \\term{distance from the point \\( x \\) to the set \\( A \\)}. We use the convention that the infimum of an empty set of real numbers is \\( +\\infty \\), hence \\( \\op{dist}(x, \\varnothing) = \\infty \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:pseudometric_to_metric}\n  Let \\( (X, \\rho) \\) be a \\hyperref[def:metric_space]{pseudometric space}. Define the equivalence relation\n  \\begin{equation*}\n    x \\cong y \\iff \\rho(x, y) = 0.\n  \\end{equation*}\n\n  Then the following metric on the \\hyperref[thm:equivalence_partition]{quotient set} \\( M \\coloneqq X / \\cong \\)\n  \\begin{balign*}\n     & \\rho: M \\times M \\to [0, \\infty)    \\\\\n     & \\rho([x], [y]) \\coloneqq \\rho(x, y)\n  \\end{balign*}\n  is well-defined.\n\\end{proposition}\n\\begin{proof}\n  The function \\( \\rho \\) is well-defined since, if \\( x \\) and \\( y \\) both belong to the same equivalence class \\( [x] \\), then \\( \\rho(x) = \\rho(y) \\). Thus, \\( \\rho \\) does not depend on the choice of representatives.\n\n  Additionally, \\( \\rho \\) is a metric since \\( \\rho([x], [y]) = 0 \\) implies that \\( [x] = [y] \\), that is, \\( \\rho(x, y) = 0 \\).\n\\end{proof}\n\n\\begin{proposition}\\label{rem:bounded_set_metric_order_equivalence}\n  A set \\( A \\) in a metric space \\( (X, \\rho) \\) is \\hyperref[def:metric_space/bounded_set]{bounded} if and only if the set \\( \\{ \\rho(a, b) \\colon a, b \\in A \\} \\) is bounded as a \\hyperref[def:partially_ordered_set_extremal_points/upper_and_lower_bounds]{partially ordered set}.\n\\end{proposition}\n\n\\begin{definition}\\label{def:metric_topology}\\mcite[249]{Engelking1989}\n  Let \\( (X, \\rho) \\) be a metric space. We define the \\term{metric topology}\\( \\mscrT \\) , also called the \\term{induced topology}, as the \\hyperref[def:topological_space]{topology} generated by the \\hyperref[def:topological_local_base]{neighborhood system}\n  \\begin{equation}\\label{def:metric_topology/integer_base}\n    \\mathcal{B}(x) \\coloneqq \\{ B(x, \\tfrac 1 n) \\colon n = 1, 2, 3, \\ldots \\}.\n  \\end{equation}\n\n  If for some topological space \\( (X, \\mscrT) \\) there exists a metric such that \\( \\mscrT \\) is its induced topology, we say that the topology \\( \\mscrT \\) is \\term{metrizable}.\n\n  It is often conventional to consider the alternative (larger) base\n  \\begin{equation}\\label{def:metric_topology/real_base}\n    \\mathcal{B}'(x) \\coloneqq \\{ B(x, \\varepsilon) \\colon \\varepsilon > 0 \\}.\n  \\end{equation}\n\\end{definition}\n\\begin{proof}\n  This is indeed a neighborhood system as it satisfies \\ref{thm:topological_local_base_axioms/BP1}-\\ref{thm:topological_local_base_axioms/BP3}:\n\n  \\begin{refenum}\n    \\refitem{thm:topological_local_base_axioms/BP1} Every point \\( x \\) belongs to any ball centered at \\( x \\).\n\n    \\refitem{thm:topological_local_base_axioms/BP2} Fix \\( x \\in X \\) and two balls \\( B(x, \\tfrac 1 n) \\) and \\( B(x, \\tfrac 1 m) \\). Then\n    \\begin{equation*}\n      B(x, \\tfrac 1 {\\max\\{ n, m \\}}) \\subseteq B(x, n) \\cap B(x, m).\n    \\end{equation*}\n\n    \\refitem{thm:topological_local_base_axioms/BP3} Fix \\( x, y \\in X \\) and let \\( x \\in B(y, \\tfrac 1 n) \\), i.e. \\( \\rho(x, y) < \\tfrac 1 n \\).\n\n    \\begin{figure}\n      \\centering\n      \\text{\\todo{Add diagram}}\\iffalse\\begin{mplibcode}\n        u := 1cm;\n        r := sqrt(2) / 2;\n\n        pair v;\n        v := (1, 1);\n\n        beginfig(1);\n        draw fullcircle scaled 3u;\n        dotlabel.bot(\"$y$\", origin);\n\n        draw fullcircle scaled 1u shifted (-r * u * v);\n        dotlabel.bot(\"$x_1$\", -r * u * v);\n\n        draw fullcircle scaled 1u shifted (r/2 * u * v);\n        dotlabel.bot(\"$x_2$\", r/2 * u * v);\n        endfig;\n      \\end{mplibcode}\\fi\n      \\caption{There is a nested ball around every point in an open ball}\\label{def:metric_topology/nested_balls}\n    \\end{figure}\n\n    Define \\( m \\) to be the the smallest positive integer such that\n    \\begin{equation*}\n      \\tfrac 1 m \\leq \\min\\{ \\rho(x, \\tfrac 1 n), \\tfrac 1 n - \\rho(x, \\tfrac 1 n) \\}.\n    \\end{equation*}\n\n    Note that \\( m \\) exists since the positive integers are \\hyperref[def:well_founded_relation]{well-founded}.\n\n    Let \\( z \\in B(x, \\tfrac 1 m) \\). There are two cases:\n    \\begin{itemize}\n      \\item If \\( \\rho(x, y) \\leq \\tfrac 1 {2n} \\), then\n            \\begin{balign*}\n              \\rho(z, y)\n              \\leq\n              \\rho(z, x) + \\rho(x, y)\n              <\n              \\tfrac 1 m + \\rho(x, y)\n              \\leq\n              \\tfrac 1 n + \\tfrac 1 n\n              \\leq\n              2 \\tfrac 1 {2n}\n              =\n              \\tfrac 1 n.\n            \\end{balign*}\n\n      \\item If \\( \\rho(x, y) > \\tfrac 1 {2n} \\), then\n            \\begin{balign*}\n              \\rho(z, y)\n              \\leq\n              \\rho(z, x) + \\rho(x, y)\n              <\n              \\tfrac 1 m + \\rho(x, y)\n              \\leq\n              (\\tfrac 1 n - \\rho(x, y)) + \\rho(x, y)\n              =\n              \\tfrac 1 n.\n            \\end{balign*}\n    \\end{itemize}\n\n    In both cases, \\( B(x, \\tfrac 1 m) \\subseteq B(y, \\tfrac 1 n) \\).\n  \\end{refenum}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:def:metric_topology/properties}\n  The metric topology \\( \\mscrT \\) on \\( X \\) induced by \\( \\rho \\) has the following properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:metric_topology/properties/ball_is_open} For every point \\( x \\in X \\) and any radius \\( r > 0 \\), the ball \\( B(x, r) \\) is an open set and, hence, a neighborhood of \\( x \\).\n    \\thmitem{thm:def:metric_topology/properties/first_countable} \\( \\mscrT \\) is first-countable.\n    \\thmitem{thm:def:metric_topology/properties/sequential} \\( \\mscrT \\) is sequential.\n    \\thmitem{thm:def:metric_topology/properties/hausdorff} \\( \\mscrT \\) is Hausdorff.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:metric_topology/properties/ball_is_open} Obvious from \\fullref{def:metric_topology}.\n\n  \\SubProofOf{thm:def:metric_topology/properties/first_countable} Since \\fullref{def:metric_topology} involves generating a topology using a neighborhood system of countable local neighborhoods, \\( \\mscrT \\) is first-countable.\n\n  \\SubProofOf{thm:def:metric_topology/properties/sequential} Follows from \\fullref{thm:def:metric_topology/properties/first_countable} and \\fullref{thm:first_countable_spaces_are_sequential}.\n\n  \\SubProofOf{thm:def:metric_topology/properties/hausdorff} Let \\( x, y \\in X \\) be distinct points. Define\n  \\begin{equation*}\n    r \\coloneqq \\dfrac 1 2 \\rho(x, y),\n  \\end{equation*}\n  so that\n  \\begin{equation*}\n    B(x, r) \\cap B(y, r) = \\varnothing.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:metric_uniformity}\n  Let \\( (X, \\rho) \\) be a metric space.\n\n  We define the \\term{metric uniformity} \\( \\mscrV \\), also called the \\term{induced uniformity}, as the \\hyperref[def:uniform_space]{uniformity} generated by the countable \\hyperref[thm:uniform_space_base_axioms]{base}\n  \\begin{equation}\\label{def:metric_uniformity/integer_base}\n    \\mathcal{B} \\coloneqq \\{ V_n \\colon n = 1, 2, \\ldots \\},\n  \\end{equation}\n  where\n  \\begin{equation*}\n    V_n \\coloneqq \\rho^{-1}([0, \\tfrac 1 n)).\n  \\end{equation*}\n\n  As for the \\hyperref[def:metric_topology]{metric topology}, we can instead consider the base\n  \\begin{equation}\\label{def:metric_uniformity/real_base}\n    \\mathcal{B}' \\coloneqq \\{ \\rho^{-1}([0, \\varepsilon)) \\colon \\varepsilon > 0 \\}.\n  \\end{equation}\n\\end{definition}\n\\begin{proof}\n  Each relation \\( V_r \\) is obviously an entourage by \\ref{def:metric_space/M1} and \\ref{def:metric_space/M2}. We will prove that \\( \\mathcal{B} \\) is indeed a uniform space base.\n\n  \\begin{refenum}\n    \\refitem{thm:uniform_space_base_axioms/BU1} For nonnegative integers \\( n, m \\) we have\n    \\begin{equation*}\n      V_n \\cap V_m\n      =\n      \\{ (x, y) \\in X \\times X \\colon \\rho(x, y) < \\tfrac 1 n \\T{and} \\rho(x, y) < \\tfrac 1 m \\}\n      =\n      V_{\\max\\{ n, m \\}}.\n    \\end{equation*}\n\n    Pick any integer \\( k \\geq \\max\\{ n, m \\} \\), so that\n    \\begin{equation*}\n      V_k \\subseteq V_n \\cap V_m.\n    \\end{equation*}\n\n    \\refitem{thm:uniform_space_base_axioms/BU2} Fix \\( V_n \\in V \\) and \\( m \\coloneqq 2n \\). By the triangle inequality, we have that if \\( \\rho(x, y) < m \\) and \\( \\rho(y, z) < m \\), then\n    \\begin{equation*}\n      \\rho(x, z) \\leq \\rho(x, y) + \\rho(y, z) < \\tfrac 1 m + \\tfrac 1 m = \\tfrac 1 n.\n    \\end{equation*}\n\n    Thus,\n    \\begin{equation*}\n      V_m + V_m\n      =\n      \\left\\{ (x, z) \\colon \\exists y \\in X: \\rho(x, y) < \\tfrac 1 m \\T{and} \\rho(y, z) < \\tfrac 1 m \\right\\}\n      \\subseteq\n      V_n\n    \\end{equation*}\n\n    \\refitem{thm:uniform_space_base_axioms/BU3} \\ref{def:metric_space/M1} implies that\n    \\begin{equation*}\n      \\bigcap \\mscrB = \\lim_{n \\to \\infty} \\rho^{-1}([0, \\tfrac 1 n)) = \\Delta_X.\n    \\end{equation*}\n  \\end{refenum}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:metric_topology_coincides_with_uniform_topology}\n  The \\hyperref[def:metric_topology]{metric topology} and the \\hyperref[def:uniform_topology]{uniform topology} from the \\hyperref[def:metric_uniformity]{metric uniformity} coincide.\n\\end{proposition}\n\n\\begin{theorem}\\label{thm:countable_uniform_base_implies_metrizable}\\mcite[thm. 8.1.21]{Engelking1989}\n  A uniform space \\( X \\) is metrizable if and only \\( w(X) \\leq \\aleph_0 \\).\n\\end{theorem}\n\n\\medskip\n\n\\begin{definition}\\label{def:isometry}\\mcite[253]{Engelking1989}\n  Let \\( (X, \\rho) \\) and \\( (Y, \\nu) \\) be two \\hyperref[def:metric_space]{metric spaces}. We say that the function \\( f: X \\to Y \\) is a \\term{distance preserving map} or \\term{isometry} or \\term{isometric embedding} if\n  \\begin{equation*}\n    \\forall x, y \\in X, \\rho(x, y) = \\nu(f(x), f(y)).\n  \\end{equation*}\n\n  If \\( f \\) is bijective, we say that \\( X \\) and \\( Y \\) are \\term{isometric}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:isometry_is_injective}\n  An \\hyperref[def:isometry]{isometry} \\( f: (X, \\rho) \\to (Y, \\nu) \\) is always injective.\n\\end{proposition}\n\\begin{proof}\n  If \\( f(x) = f(x') \\), then by \\fullref{def:metric_space/M1}, \\( x = x' \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:category_of_metric_spaces}\n  Metric spaces and monotone maps form a subcategory of \\( \\cat{Unif} \\) (see \\fullref{def:category_of_uniform_spaces}). We denote this category by \\( \\cat{Met} \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:equivalent_metrics}\n  Two metrics \\( \\rho \\) and \\( \\nu \\) on the set \\( X \\) are said to be \\term{equivalent} if \\( \\rho \\) and \\( \\nu \\) have the same \\hyperref[def:metric_topology]{metric topology}. They are said to be \\term{strongly equivalent} if there exist constants \\( \\alpha, \\beta \\in \\BbbR \\) such that for every \\( x, y \\in X \\) we have\n  \\begin{equation*}\n    \\alpha \\nu(x, y) \\leq \\rho(x, y) \\leq \\beta \\nu(x, y).\n  \\end{equation*}\n\\end{definition}\n\n\\begin{remark}\\label{rem:metric_space_convergence}\n  All types of convergence from \\fullref{subsec:topological_nets}, \\fullref{subsec:topological_continuity} and \\fullref{subsec:uniform_spaces} hold in metric spaces using the \\hyperref[def:metric_topology]{metric topology} and \\hyperref[def:metric_uniformity]{metric uniformity} structure.\n\n  It is conventional to prefer the bases \\fullref{def:metric_topology/real_base} and \\fullref{def:metric_uniformity/real_base} to the bases \\fullref{def:metric_topology/integer_base} and \\fullref{def:metric_topology/integer_base}.\n\n  For example, given two metric spaces \\( X \\) and \\( Y \\), continuity of \\( f: X \\to Y \\) at \\( x_0 \\in X \\) (see \\fullref{def:local_continuity}) is usually written using the \\enquote{epsilon-delta notation} as\n  \\begin{equation*}\n    \\forall \\varepsilon > 0 \\ \\exists \\delta > 0 : \\rho_X(x, x_0) < \\delta \\implies \\rho_Y(f(x), f(x_0)) < \\varepsilon\n  \\end{equation*}\n  for any \\( x \\in X \\).\n\\end{remark}\n\n\\begin{definition}\\label{def:translation_invariant_metric}\n  A \\hyperref[def:metric_space]{metric} \\( \\rho \\) on a \\hyperref[def:magma]{magma} \\( G \\) is said to be \\term{left translation-invariant} if\n  \\begin{equation*}\n    \\rho(ax, ay) = \\rho(x, y) \\quad\\forall a, x, y \\in G\n  \\end{equation*}\n  and \\term{right translation-invariant} if\n  \\begin{equation*}\n    \\rho(xa, ya) = \\rho(x, y) \\quad\\forall a, x, y \\in G.\n  \\end{equation*}\n\n  If \\( \\rho \\) is both left and right translation invariant (e.g. for commutative magmas), we simply say that \\( \\rho \\) is \\term{translation invariant}.\n\\end{definition}\n", "meta": {"hexsha": "0a7c0511ec05031bf890386c728773e6e06a5f24", "size": 15772, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/metric_topology.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/metric_topology.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/metric_topology.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.3803680982, "max_line_length": 328, "alphanum_fraction": 0.6363175247, "num_tokens": 5392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835493924953, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7150495555557599}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath,amssymb}\n\\usepackage[pdfborder={0 0 0}]{hyperref}\n\\usepackage{csquotes}\n\\newcommand\\set[1]{\\left\\{#1\\right\\}}\n\n\\begin{document}\n\\section{Exercise 8}\n\n\\subsection{Royal Flush}\n10, jack, queen, king, ace in one suit\n\\[ \\sum_{s \\in \\set{\\clubsuit, \\diamondsuit, \\diamondsuit, \\spadesuit}} \\frac{5}{52} \\cdot \\frac{4}{51} \\cdot \\frac{3}{50} \\cdot \\frac{2}{49} \\cdot \\frac{1}{48} = 4 \\cdot \\frac{120}{311875200} \\approx 1.5390\\cdot 10^{-6} \\]\nConsider one suit. It is okay to pick one of five cards. Then 4 admissible cards are left. Then 3 cards. Then 2. Then 1. For four suits.\n\n\\subsection{Straight Flush}\n5 cards in same suit with consecutive rank.\n\n%\\[ \\sum_{s \\in \\set{\\clubsuit, \\diamondsuit, \\diamondsuit, \\spadesuit}} \\frac{13}{52} \\cdot \\frac{4}{51} \\cdot \\frac{3}{50} \\cdot \\frac{2}{49} \\cdot \\frac{1}{48} = 4 \\cdot \\frac{312}{311875200} = 4.0016\\cdot 10^{-6} \\]\n%Card 1 must match one specific color, the second card must be one of 4 neighboring cards of same suit. This continues to 5 cards.\n%\n%Now we need to exclude the royal flush:\n%\\[ 4 \\cdot \\frac{312}{311875200} - 4 \\cdot \\frac{120}{311875200} = \\frac{768}{311875200} \\approx 2.4625 \\cdot 10^{-6} \\]\n%\n%This result is wrong according to Wikipedia (should be more likely).\n\nThe ranks can begin with 1, 2, 3, \\dots up to 10. There are 4 suits.\n\\[ \\frac{4 \\cdot 10}{311875200} \\]\n\n\\subsection{Poker / Four of a kind}\n4 cards of same rank.\n\\[ \\frac{1}{1} \\cdot \\frac{3}{51} \\cdot \\frac{2}{50} \\cdot \\frac{1}{49} = \\frac{6}{124950} \\]\n\n\\subsection{Full House}\n3 cards of same rank and 2 cards of same rank.\n\\[ \\frac11 \\cdot \\frac{3}{51} \\cdot \\frac{2}{50} \\cdot \\frac{48}{49} \\cdot \\frac{3}{48} = \\frac{864}{5997600} \\approx 0.0001 \\]\nThe first choice is arbitrary, the second choice must be of same rank (3 of same suit are left, 51 cards left), as well as the third choice.\nThe fourth choice excludes 4 cards of same rank (the fourth card must not be picked!), hence $52 - 3 - 1 = 48$. The fifth choice must be of same rank (there are 3 suits of same rank left).\n\n\\subsection{Flush}\n5 cards of same suit\n\\[ \\frac{1}{1} \\cdot \\frac{12}{51} \\cdot \\frac{11}{50} \\cdot \\frac{10}{49} \\cdot \\frac{9}{48} = \\frac{11880}{5997600} \\approx 0.0020 \\]\n\nVerified with \\href{https://en.wikipedia.org/wiki/Poker_probability}{Wikipedia: Poker probability}\n\n\\section{Whiteboard solution}\n\nThe solutions do not necessarily respect the previous solutions (a Royal Flush is a Flush).\n\n\\[ \\mathbb P(\\text{\\enquote{Royal Flush}}) = \\frac{{4 \\choose 1} {47 \\choose 1}}{{52 \\choose 5}} \\approx 1.539 \\cdot 10^{-6} \\]\nThere are $4$ different Royal Flushs (because of $4$ suits).\n\n\\[ \\Omega = \\{A \\subseteq \\{1, \\dots, 4\\} \\times \\{2, \\dots, 14\\} \\,|\\, |A| = 5\\} \\]\n\n\\[ \\mathbb P(\\text{\\enquote{Straight Flush}}) = \\frac{{4 \\choose 1} {9 \\choose 1}}{{52 \\choose 5}} = \\frac{36}{{52 \\choose 5}} \\approx 0.0000138 \\]\n\n\\[ \\mathbb P(\\text{\\enquote{Poker}}) = \\frac{{13 \\choose 1} {48 \\choose 1}}{{52 \\choose 5}} \\approx 0.0002401 \\]\n\\[ \\mathbb P(\\text{\\enquote{Full House}}) = \\frac{{13 \\choose 1} {4 \\choose 3} {12 \\choose 1} {4 \\choose 2}}{{52 \\choose 5}} \\approx 0.00144 \\]\n\\[ \\mathbb P(\\text{\\enquote{Flush}}) = \\frac{{4 \\choose 1} {13 \\choose 5}}{{52 \\choose 5}} \\]\nminus Royal Flush: $- \\frac{36}{{52 \\choose 5}} - \\frac{4}{{52 \\choose 5}} \\approx 0.001965$\n\n\\end{document}", "meta": {"hexsha": "a712b3f48047e7ba5f0b2d82766a919ca2e4f20c", "size": 3383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "probability_theory_practicals/ex8/solution.tex", "max_stars_repo_name": "prokls/math-lecture-notes", "max_stars_repo_head_hexsha": "d1a94e128d13ce4399a9cc55323b2f8e0d9494fd", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2015-11-25T01:49:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T14:47:36.000Z", "max_issues_repo_path": "probability_theory_practicals/ex8/solution.tex", "max_issues_repo_name": "prokls/math-lecture-notes", "max_issues_repo_head_hexsha": "d1a94e128d13ce4399a9cc55323b2f8e0d9494fd", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-05-22T07:56:03.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-02T09:32:40.000Z", "max_forks_repo_path": "probability_theory_practicals/ex8/solution.tex", "max_forks_repo_name": "prokls/math-lecture-notes", "max_forks_repo_head_hexsha": "d1a94e128d13ce4399a9cc55323b2f8e0d9494fd", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-03-24T14:42:30.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-25T11:00:11.000Z", "avg_line_length": 54.564516129, "max_line_length": 223, "alphanum_fraction": 0.6653857523, "num_tokens": 1226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511579973931, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7150495527177343}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Correlation}\\label{sec:correlation}\n\n%-----------------------------\n\\subsection{Product moments}\n%Let $X$ and $Y$ be random variables on the same probability space.\n\n\\begin{definition}\\label{def:prod_rvs}\nThe \\emph{product} of $X$ and $Y$ is the random variable\n\\[\n\\begin{array}{rlcl}\nXY : \t& \\Omega & \\to \t\t& \\R \\\\\n\t\t& \\omega & \\mapsto\t& X(\\omega)Y(\\omega).\n\\end{array}\n\\]\n\\end{definition}\n\n\\begin{definition}\n\\ben\n\\it % << discrete\nIf $X$ and $Y$ are jointly discrete, the \\emph{product moment} of $X$ and $Y$ is\n\\[\n\\expe(XY) = \\sum_{i=1}^{\\infty}\\sum_{j=1}^{\\infty} x_iy_j\\, f_{X,Y}(x_i,y_j)\n\\]\nwhenever this sum exists.\n\\it % << cts\nIf $X$ and $Y$ are jointly continuous, the \\emph{product moment} of $X$ and $Y$ is\n\\[\n\\expe(XY) = \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} xy\\, f_{X,Y}(x,y)\\,dx\\,dy\n\\]\nwhenever this integral exists.\n\\een\n\\end{definition}\n%\n\n%-----------------------------\n\\subsection{Covariance}\nThe covariance of $X$ and $Y$ is the product moment of the \\emph{centred} variables $X-\\expe(X)$ and $Y-\\expe(Y)$.\n\n\\begin{definition}\\label{def:covariance}\nThe \\emph{covariance} of $X$ and $Y$ is \n\\[\n\\cov(X,Y) = \\expe\\big(\\big[X-\\expe(X)\\big]\\big[Y-\\expe(Y)\\big]\\big).\n\\]\n\\end{definition}\n\n\\begin{remark}\nNote that $\\cov(X,Y)=\\cov(Y,X)$ and $\\cov(X,X)=\\var(X)$.\n\\end{remark}\n\nIn the same way that $\\var(X)=\\expe(X^2)-\\expe(X)^2$ we have the following convenient expression for $\\cov(X,Y)$.\n\\begin{lemma}\\label{lem:covariance-formula}\n%\\[\n$\\cov(X,Y) = \\expe(XY) - \\expe(X)\\expe(Y)$.\n%\\]\n\\end{lemma}\n\\begin{proof}\nExpand the product in Definition~\\ref{def:covariance} then apply the linearity of expectation.\n\\end{proof}\n\n\\begin{lemma}\\label{lem:var_of_sum}\nFor random variables $X_1,X_2,\\ldots,X_n$,\n\\[\n\\var\\left(\\sum_{i=1}^n X_i\\right) = \\sum_{i=1}^n\\sum_{j=1}^n \\cov(X_i,X_j) \n%= \\sum_{i=1}^n \\var(X_i) + 2\\sum_{i=1}^{n}\\sum_{j=i+1}^n \\cov(X_i,X_j).\n\\]\n\\end{lemma}\n\\begin{proof}\nLet $Y=\\sum_{i=1}^n X_i$. Then \n\\begin{align*}\n\\var(Y) \n\t= \\expe(Y^2)-\\expe(Y)^2\n\t& = \\expe\\left[\\left(\\sum_{i=1}^n X_i\\right)^2\\right] - \\left[\\expe\\left(\\sum_{i=1}^n X_i\\right)\\right]^2 \\\\\n\t& = \\expe\\left[\\sum_{i=1}^n \\sum_{j=1}^n X_iX_j\\right] - \\left[\\sum_{i=1}^n \\expe(X_i)\\right]^2 \\\\\n\t& = \\sum_{i=1}^n\\sum_{j=1}^n \\expe(X_iX_j) - \\sum_{i=1}^n\\sum_{j=1}^n \\expe(X_i)\\expe(X_j) \\\\\n\t& = \\sum_{i=1}^n\\sum_{j=1}^n \\cov(X_i,X_j)\n\\end{align*}\n\\end{proof}\n\n\\begin{exercise}\\label{exe:covar_bilinear}\nShow that covariance is a \\emph{bilinear} operator, in the sense that\n\\[\n\\cov(aX_1+bX_2,cY_1+dY_2) = ac\\cov(X_1,Y_1) + ad\\cov(X_1,Y_2) + bc\\cov(X_2,Y_1) + cd\\cov(X_2,Y_2).\n\\]\n\\end{exercise}\n\n%-----------------------------\n\\subsection{Correlation}\n\n\\begin{definition} \n$X$ and $Y$ are said to be \\emph{correlated} if $\\cov(X,Y)\\neq 0$ or equivalently if\n\\[\n\\expe(XY)\\neq\\expe(X)\\expe(Y),\n\\]\notherwise they are said to be \\emph{uncorrelated}.\n\\end{definition}\n\n% lem: independent => correlated\n\\begin{lemma}\\label{lem:indept_implies_uncorrelated}\nIf $X$ and $Y$ are independent, they are uncorrelated.\n\\end{lemma}\n\\begin{proof}\nLet $X$ and $Y$ be jointly continuous (the discrete case is similar).\n\\par\nBecause $X$ and $Y$ are independent, $f_{X,Y}(x,y)=f_X(x)f_Y(y)$ for all $x,y\\in\\R$. Hence\n\\begin{align*}\n\\expe(XY) \n\t& = \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} xy\\, f_{X,Y}(x,y)\\,dx\\,dy \\\\\n\t& = \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} xy\\, f_X(x)f_Y(y)\\,dx\\,dy \\text{\\quad(by independence),}\\\\\n\t& = \\left(\\int_{-\\infty}^{\\infty}x\\,f_X(x)\\,dx\\right)\\left(\\int_{-\\infty}^{\\infty}y\\,f_Y(y)\\,dy\\right) \\\\\n\t& = \\expe(X)\\expe(Y).\n\\end{align*}\n\\end{proof}\n\n% variance of sum = sum of variances\n\\begin{lemma}\\label{lem:var_of_indept_sum}\nIf $X_1,X_2,\\ldots,X_n$ are pairwise uncorrelated,\n\\[\n\\var\\left(\\sum_{i=1}^n X_i\\right) = \\sum_{i=1}^n\\var(X_i).\n\\]\n\\end{lemma}\n\\begin{proof}\nBecause the $X_i$ are pairwise uncorrelated, $\\cov(X_i,X_j)=0$ whenever $i\\neq j$, so by Lemma~\\ref{lem:var_of_sum},\n\\[\n\\var\\left(\\sum_{i=1}^n X_i\\right) = \\sum_{i=1}^n\\cov(X_i,X_i) = \\sum_{i=1}^n\\var(X_i).\n\\]\n\\end{proof}\n\n% example: negative binomial\n\\begin{example}\nLet $X_1,\\ldots,X_r$ be independent with each $X_i\\sim\\text{Geometric}(p)$, the distribution of the number of failures before the first success in a sequence of independent Bernoulli trials where the probability of success is $p$. Find the mean and variance of $Y = \\sum_{i=1}^r X_i$.\n\\begin{solution}\nSince $X_i\\sim\\text{Geometric}(p)$, we know that \n\\[\n\\expe(X_i)=\\frac{1-p}{p} \\quad\\text{and}\\quad \\var(X_i)=\\frac{1-p}{p^2}.\n\\]\nBy the linearity of expectation,\n\\[\n\\expe(Y) = \\expe(X_1)+\\expe(X_2)+\\ldots+\\expe(X_r) = \\frac{r(1-p)}{p}\n\\]\nand because the $X_i$ are independent,\n\\[\n\\var(Y) = \\var(X_1)+\\var(X_2)+\\ldots+\\var(X_r) = \\frac{r(1-p)}{p^2}\n\\]\nIn this case $Y$ has the so-called \\emph{negative binomial} distribution with parameters $r$ and $p$. This is the distribution of the number of failures before the $r$th success in a sequence of independent Bernoulli trials in which the probability of success is $p$.\n\\end{solution}\n\\end{example}\n\n%-----------------------------\n\\subsection{Correlation coefficient}\nThe correlation coefficient is the product moment of the \\emph{standardized} variables $\\displaystyle\\frac{X-\\expe(X)}{\\sqrt{\\var(X)}}$ and $\\displaystyle\\frac{Y-\\expe(Y)}{\\sqrt{\\var(Y)}}$.\n\n\\begin{definition}\\label{def:correlation_coefficient}\nThe \\emph{correlation coefficient} of $X$ and $Y$ is \n\\[\n\\rho(X,Y) = \\expe\\left[\\left(\\frac{X-\\expe(X)}{\\sqrt{\\var(X)}}\\right)\\left(\\frac{Y-\\expe(Y)}{\\sqrt{\\var(Y)}}\\right)\\right]\n\\]\n\\end{definition}\n\nBy the linearity of expectation, we have the following convenient expression for $\\rho(X,Y)$.\n\\begin{lemma}\nThe correlation coefficient of $X$ and $Y$ can be written as\n\\[\n\\rho(X,Y) = \\frac{\\cov(X,Y)}{\\sqrt{\\var(X)\\cdot\\var(Y)}}\n\\]\n\\end{lemma}\n\\begin{proof}\nFollows easily from Lemma~\\ref{lem:covariance-formula}.\n\\end{proof}\n\nNote that $\\rho(X,Y)=0$ whenever $X$ and $Y$ are uncorrelated. In fact the correlation coefficient satisfies the inequality $|\\rho(X,Y)|\\leq 1$ and thus provides a \\emph{standardized} measure of the (linear) dependence between $X$ and $Y$. To prove this we need the following result from mathematical analysis.% called the \\emph{Cauchy-Schwarz inequality}. \n\n%First we need the following technical result (which we shall not prove).\n%% lemma\n%\\begin{lemma}\\label{lem:pos_rv_expe_zero}\n%If $X\\geq 0$ and $\\expe(X)=0$ then $\\prob(X=0)=1$.\n%\\end{lemma}\n%\\begin{proof}\n%Proof by contradiction: let $X\\geq 0$ with $\\expe(X)=0$, and suppose that $\\prob(X>0)>0$. \n%\\bit\n%\\it Because the CDF $\\prob(X\\leq x)$ is right-continuous, there exists $\\epsilon>0$ such that $\\prob(X>\\epsilon)>0$. \n%\\it This implies that $X\\geq \\epsilon I(X>\\epsilon)$.\n%\\it Taking the expected value of both sides, $\\expe(X)\\geq \\epsilon\\,\\prob(X>\\epsilon) > 0$ (by monotonicity). \n%\\eit\n%This is a contradiction, so we conclude that $\\prob(X>0)=0$.\n%\\end{proof}\n\n% thm: cauchy-schwarz\n\\begin{theorem}[Cauchy-Schwarz inequality for random variables]\nFor any two random variables $X$ and $Y$,\n\\[\n\\expe(XY)^2 \\leq \\expe(X^2)\\expe(Y^2)\n\\]\nwith equality if and only if $\\prob(Y=aX)=1$ for some $a\\in\\R$.\n\\end{theorem}\n\n\n\\begin{theorem}\\label{thm:bounds_on_rho}\nThe correlation coefficient satisfies the inequality \n\\[\n|\\rho(X,Y)|\\leq 1,\n\\]\nwith equality if and only if $\\prob(Y=aX+b)=1$ for some $a,b\\in\\R$.\n\\end{theorem}\n\\begin{proof}\nApply the Cauchy-Schwarz inequality to $X-\\expe X$ and $Y-\\expe Y$:\n\\begin{align*}\n\\cov(X,Y)^2 \n\t& =\t\t\\expe\\big((X-\\expe X)(Y-\\expe Y)\\big) \\\\\n\t& \\leq \t\\expe\\big((X-\\expe X)^2\\big)\\expe\\big((Y-\\expe Y)^2\\big) \\\\\n\t& = \t\\var(X)\\var(Y),\n\\end{align*}\nwith equality if and only if there exists $a\\in\\R$ such that\n\\[\n\\prob\\big[Y-\\expe Y = a(X-\\expe X)] = 1.\n\\]\nHence,\n\\[\t\n|\\rho(X,Y)| = \\left|\\frac{\\cov(X,Y)}{\\sqrt{\\var(X)\\var(Y)}}\\right| \\leq 1\n\\]\nwith equality if and only if $\\prob(Y = aX + b) = 1$,  where $b = \\expe Y - a\\expe X$.\n\\end{proof}\n\n%----------------------------------------------------------------------\n\\begin{exercise}\n\\begin{questions}\n%----------------------------------------\n%==========================================================================\n\\question\nLet $X$ and $Y$ be two random variables having the same distribution but which are not necessarily independent. Show that\n$\n\\cov(X+Y,X-Y)=0\n$\nprovided that their distribution has finite mean and variance.\n\n\\begin{answer}\nPerhaps the simplest method is the following: let $U=X+Y$ and $V=X-Y$. Then \n\\begin{align*}\n\\cov(X+Y,X-Y) \n\t& = \\expe(UV) - \\expe(U)\\expe(V) \\\\\n\t& = \\expe\\big[(X+Y)(X-Y)\\big] - \\expe(X+Y)\\expe(X-Y) \\\\\n\t& = \\expe(X^2 - Y^2) - \\big[\\expe(X)+\\expe(Y)\\big]\\big[\\expe(X)-\\expe(Y)\\big]\t\\qquad\\text{(by the linearity of expectation)} \\\\\n\t& = \\expe(X^2) - \\expe(Y^2) - \\expe(X)^2 +\\expe(X)\\expe(Y) - \\expe(Y)\\expe(X) + \\expe(Y)^2 \\quad\\text{(by linearity again)} \\\\\n\t& = \\big[\\expe(X^2) - \\expe(X)^2\\big] - \\big[\\expe(Y^2) - \\expe(Y)^2\\big] \\\\\n\t& = \\var(X) - \\var(Y).\n\\end{align*}\nSince $X$ and $Y$ have the same distribution, their variances must be equal, so $\\cov(X+Y,X-Y)=0$.\n\\end{answer}\n\n\n\n%==========================================================================\n\\question\nConsider a fair six-sided die whose faces show the numbers $-2,0,0,1,3,4$. The die is independently rolled four times. Let $X$ be the average of the four numbers that appear, and let $Y$ be the product of these four numbers. Compute $\\expe(X)$, $\\expe(X^2)$, $\\expe(Y)$ and $\\cov(X,Y)$.\n\\begin{answer}\nLet $X_1,X_2,X_3,X_4$ be independent discrete random variables on the set $\\{-2,0,0,1,3,4\\}$. Each $X_i$ is identically distributed according to the following PMF:\n\\[\\begin{array}{|c|ccccc|}\\hline\nk\t\t\t& -2\t\t& 0\t\t& 1\t\t& 3\t\t& 4 \t\\\\ \\hline\n\\prob(X_i=k)\t\t& 1/6\t& 1/3\t& 1/6\t& 1/6 \t& 1/6\t\\\\ \\hline\n\\end{array}\\]\nHence for $i=1,2,3,4$,\n\\begin{align*}\n\\expe(X_i)\t\t& = \\frac{1}{6}(-2+0+0+1+3+4) = 1, \\\\\n\\expe(X_i^2)\t& = \\frac{1}{6}(4+0+0+1+9+16) = \\frac{30}{6} = 5, \\\\\n\\var(X_i)\t\t& = \\expe(X_i^2)-\\expe(X_i)^2 = 4.\n\\end{align*}\n\nLet $X=\\frac{1}{4}(X_1+X_2+X_3+X_4)$. Then\n\\[\n\\expe(X) \t= \\frac{1}{4}\\big(\\expe(X_1)+\\ldots+\\expe(X_4)\\big) = 1\n\\]\nBy independence,\n\\[\n\\var(X) \t= \\frac{1}{16}\\big(\\var(X_1)+\\ldots+\\var(X_4)\\big) = 1 \n\\]\nso $\\expe(X^2)\t= \\var(X) + \\expe(X)^2 = 2$.\n\nand $Y=X_1 X_2 X_3 X_4$. By independence,\n\\begin{align*}\n\\expe(Y) \n\t& = \\expe(X_1 X_2 X_3 X_4) \\\\\n\t& = \\expe(X_1)\\expe(X_2)\\expe(X_3)\\expe(X_4) \\\\\n\t& = 1 \\\\\n\\end{align*}\nand because the $X_i$ are identically distributed,\n\\begin{align*}\n\\expe(XY) \n\t& = \\frac{1}{4}\\expe\\big(\\expe(X_1+X_2+X_3+X_4)X_1X_2X_3X_4\\big) \\\\\n\t& = \\expe(X_1^2)\\expe(X_2)\\expe(X_3)\\expe(X_4) \\\\\n\t& = \\expe(X_1^2) = 5 \\\\\n\\end{align*}\nso $\\cov(XY) = \\expe(XY) - \\expe(X)\\expe(Y) = 4$.\n\\end{answer} \n\n%==========================================================================\n\\question\nA fair die is rolled twice. Let $U$ denote the number obtained on the first roll, let $V$ denote the number obtained on the second roll, let $X=U+V$ denote their sum and let $Y=U-V$ denote their difference. Compute the mean and variance of $X$ and $Y$, and compute $\\expe(XY)$. Check whether $X$ and $Y$ are uncorrelated. Check whether $X$ and $Y$ are independent.\n\\begin{answer}\nLet $U,V\\sim\\text{Uniform}\\{1,2,3,4,5,6\\}$ be independent (and identically distributed) random variables, and define $X=U+V$ and $Y=U-V$. \n\\begin{align*}\n\\expe(X)\t& = \\expe(U) + \\expe(V) = 7 \\\\\n\\expe(Y)\t& = \\expe(U) - \\expe(V) = 0 \\\\\n\\intertext{By independence,}\n\\var(X)\t\t& = \\var(U) + \\var(V) = 35/6 \\\\\n\\var(Y)\t\t& = \\var(U) + \\var(V) = 35/6 \\\\\n\\intertext{Because $U$ and $V$ are identically distributed, and}\nXY \t\t\t& = (U+V)(U-V) = U^2 - V^2 \\\\\n\\intertext{it follows that}\n\\expe(XY)\t& = \\expe(U^2) - \\expe(V^2) = 0 \\\\\n\\intertext{$X$ and $Y$ are uncorrelated, since}\n\\cov(X,Y)\t& = \\expe(XY) - \\expe(X)\\expe(Y) =0 \\\\\n\\intertext{However $X$ and $Y$ are not independent, because (for example)}\n\\prob(Y=0)\t\t& \\neq \\prob(Y=0|X=12)=1\n\\end{align*}\n\\end{answer} \n\n%----------------------------------------\n\\end{questions}\n\\end{exercise}\n%----------------------------------------------------------------------\n", "meta": {"hexsha": "303aae6a5d3cebb08577c3f94009ae425b510ca8", "size": 12114, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/05B_correlation.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/05B_correlation.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/05B_correlation.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 37.5046439628, "max_line_length": 364, "alphanum_fraction": 0.6128446426, "num_tokens": 4639, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.8354835411997896, "lm_q1q2_score": 0.7150495470081075}}
{"text": "\\documentstyle[12pt]{article}\n\\begin{document}\n\\title{Linear First Order Differential Equations}\n\\maketitle\n\\section{The variation of constants method}\n\nWe start with the homogeneous equation\n$$y'+p(t)y=0.$$\nTo solve this, we simply divide by $y$,\n$$y'/y+p(t)=0,$$\nand then integrate\n$$\\ln\\alpha|y|+\\int^t p(s)\\,ds=K,$$\nwhere $K$ is an integration constant.\nWe take the exponential on both sides:\n$$|y|\\exp(\\int^t p(s)\\,ds)=e^K.$$\nThis yields\n$$y=\\pm e^K\\exp(-\\int^t p(s)\\,ds).$$\nWe define a new constant $C=\\pm e^K$, so we can put the solution in the\nform\n\\begin{equation}\ny=C\\exp(-\\int^t p(s)\\,ds).\\label{e1}\n\\end{equation}\n\nNow we look at an inhomogeneous equation\n\\begin{equation}\ny'+p(t)y=g(t).\\label{e2}\n\\end{equation}\nThe idea of the variation of constants method is to look for a solution in\na form similar to (\\ref{e1}). Obviously, something has to change since the\nequation has changed. The change is that the constant $C$ is replaced by\na function $C(t)$. So we set\n$$y=C(t)\\exp(-\\int^t p(s)\\,ds).$$\nWe differentiate using the product and chain rules to find\n$$y'=C'(t)\\exp(-\\int^t p(s)\\,ds)-C(t)p(t)\\exp(-\\int^t p(s)\\,ds),$$\nand\n$$y'+p(t)y=C'(t)\\exp(-\\int^t p(s)\\,ds).$$\nThus our differential equation becomes\n$$C'(t)\\exp(-\\int^t p(s)\\,ds)=g(t),$$\nso that\n$$C'(t)=g(t)\\exp(\\int^t p(s)\\,ds).$$\nWe can then find $C(t)$ by integrating this equation.\n\nThe result is evidently the same as what we found using the integrating factor\nmethod, but the ideas leading to the result were different. While for first\norder linear equations the integrating factor method and the variation\nof constants method are the same, the difference is in how they can be\ngeneralized. The integrating factor method can be generalized to some nonlinear\nequations of first order. The variation of constants method, on the other\nhand, can be generalized to linear equations of higher order and to linear\nsystems.\n\n\\section{The method of undetermined coefficients}\n\nThis method is more limited in scope; it applies only to the special case\nof (\\ref{e2}), where $p(t)$ is a constant and $g(t)$ has some special form.\nThe advantage of the method is that it does not require any integrations and\nis therefore quick to use. The homogeneous equation\n$$y'+\\lambda y=0$$\nhas the solution\n$$y_h=Ce^{-\\lambda t}.$$\nTo solve the inhomogeneous equation\n$$y'+\\lambda y=g(t),$$\nit suffices to find one particular solution $y_p(t)$. If $y_p(t)$ is any\nparticular solution, then the general solution is\n$$y(t)=y_p(t)+Ce^{-\\lambda t}.$$\n\nThe idea behind the method of undetermined coefficients is to look for\n$y_p(t)$ which is of a form like that of $g(t)$. This is possible only for\nspecial functions $g(t)$, but these special cases arise quite frequently in\napplications.\n\nWe start with the case where $g(t)$ is an exponential:\n$$g(t)=Ae^{\\alpha t}.$$\nWe look for $y(t)$ in a similar form\n$$y(t)=ae^{\\alpha t}.$$\nThis leads to\n$$y'=a\\alpha e^{\\alpha t},\\quad y'+\\lambda y=(\\alpha+\\lambda)ae^{\\lambda t}.$$\nSo the differential equation becomes\n$$(\\alpha+\\lambda)ae^{\\alpha t}=Ae^{\\alpha t}.$$\nWe can solve this to find $a=A/(\\alpha+\\lambda)$. This leads to the particular\nsolution\n$$y_p(t)={A\\over \\alpha+\\lambda}e^{\\alpha t},$$\nand the general solution\n\\begin{equation}\ny(t)={A\\over \\alpha+\\lambda}e^{\\alpha t}+Ce^{-\\lambda t}.\\label{e3}\n\\end{equation}\n\nExample: Find the general solution of the equation\n$$y'+2y=e^t.$$\nThe solution of the homogeneous equation is $C\\exp(-2t)$, and we look\nfor a particular solution in the form $y_p=ae^t$. Setting $y=ae^t$ in\nthe equation, we find\n$$ae^t+2ae^t=e^t,$$\nleading to $a=1/3$. The general solution is\n$$y={1\\over 3}e^t+Ce^{-2t}.$$\n\nWhy did this work? The idea is simply that if $y$ is an exponential, then so\nis $y'$, and so if both $y$ and $g$ are exponentials, then all terms in\nthe equation are exponentials and we can hope to obtain a solution by setting\ncoefficients equal to each other.\n\nThere are some other classes of functions for which this works. For instance,\nif $y$ is a polynomial of degree $n$, then $y'$ is a polynomial of degree\n$n-1$. If $g$ is a polynomial, we can therefore look for polynomial solutions.\nConsider\n$$y'+2y=t^2.$$\nThe right hand side is a polynomial of degree 2, so we look for a solution\nin the same form $y=at^2+bt+c$. This leads to $y'=2at+b$, and\n$$y'+2y=2at^2+(2a+2b)t+b+2c=t^2.$$\nTo satisfy this, we want to set\n$$2a=1,\\quad 2a+2b=0,\\quad b+2c=0.$$\nThis leads to $a=1/2$, $b=-1/2$, $c=1/4$.\nSo a particular solution is\n$$y_p={t^2\\over 2}-{t\\over 2}+{1\\over 4}.$$\nThe general solution is\n$$y={t^2\\over 2}-{t\\over 2}+{1\\over 4}+Ce^{-2t}.$$\n\nWe note that the solution (\\ref{e3}) breaks down if $\\alpha=-\\lambda$, since\nit would involve a division by zero. More generally, if the equation reads\n$$y'+\\lambda y=g(t),$$\nand $g(t)=\\exp(\\alpha t)P_n(t)$, with $P_n(t)$ an $n$th degree polynomial,\nthen we can find a particular solution $y_p(t)=\\exp(\\alpha t)Q_n(t)$, where\n$Q_n(t)$ is some other $n$th degree polynomial as long as $\\alpha\\neq -\\lambda$.\nIn the two examples above, we had $\\lambda=-2$ and $\\alpha=1$, $\\alpha=0$,\nrespectively, so $\\alpha\\neq -\\lambda$. If, on the other hand,\n$\\alpha=-\\lambda$, we have to modify the procedure. The modification is\nsimply to include an extra factor $t$ in the solution. That is, instead of\nsetting $y_p=\\exp(\\alpha t)Q_n(t)$, you set $y_p=t\\exp(\\alpha t)Q_n(t)$.\n\n{\\bf Examples:}\n\n1.\n$$y'+2y=te^{-2t}.$$\nHere $\\lambda=2$ and $\\alpha=-2$, so $\\alpha=-\\lambda$. The right hand side\nis a first degree polynomial times $e^{-2t}$. So we look for a solution of\nthe form\n$$y=te^{-2t}(at+b)=e^{-2t}(at^2+bt).$$\nWe find\n$$y'=e^{-2t}(-2at^2+(2a-2b)t+b),$$\nso that\n$$y'+2y=e^{-2t}(2at+b)=te^{-2t}.$$\nWe compare coefficients to find $a=1/2$, $b=0$.\nThe general solution of the equation is\n$$y={1\\over 2}t^2e^{-2t}+Ce^{-2t}.$$\n\n2.\n$$y'+2y=te^t.$$\nIn this case $\\lambda=2$ and $\\alpha=1$, so $\\alpha\\neq -\\lambda$, and we\ndo not need the extra factor $t$. So we look for a solution of the form\n$$y=e^t(at+b).$$\nThis leads to\n$$y'+2y=e^t(3at+3b+a)=te^t,$$\nso we need\n$$3a=1,\\quad 3b+a=0,$$\nleading to $a=1/3$, $b=-1/9$.\nThe general solution is\n$$y=({t\\over 3}-{1\\over 9})e^t+Ce^{-2t}.$$\n\n3.\n$$y'=t.$$\nIn this case $\\lambda=\\alpha=0$, and the right hand side is a first degree\npolynomial, so we look for a particular solution of the form $y=t(at+b)=at^2\n+bt$. We find\n$$y'=2at+b=t,$$\nleading to $a=1/2$, $b=0$. The general solution is\n$$y={t^2\\over 2}+C.$$\n\\end{document}\n", "meta": {"hexsha": "5c34702df176612b8e1f15ffa1ba32a91e35c1f0", "size": 6450, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nt.tex", "max_stars_repo_name": "perfectbark/LaTex2Docx", "max_stars_repo_head_hexsha": "e32f9dcc59cce7bea4e7b114687b2300c623d8c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2019-06-16T06:00:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T14:44:32.000Z", "max_issues_repo_path": "nt.tex", "max_issues_repo_name": "hao-han/LaTex2Docx", "max_issues_repo_head_hexsha": "e32f9dcc59cce7bea4e7b114687b2300c623d8c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "nt.tex", "max_forks_repo_name": "hao-han/LaTex2Docx", "max_forks_repo_head_hexsha": "e32f9dcc59cce7bea4e7b114687b2300c623d8c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2019-05-27T06:32:06.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T10:22:07.000Z", "avg_line_length": 38.3928571429, "max_line_length": 80, "alphanum_fraction": 0.6835658915, "num_tokens": 2182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7150495318827547}}
{"text": "%\n% Chapter 5.1\n%\n\n\\section*{5.1 Areas Between Curves}\n\nThe area \\(a\\) bounded by the curves \\(y=f(x), y=g(x)\\), and the lines \\(x=a, x=b\\), where \\(f\\) and \\(g\\) are continuous and \\(f(x) \\geq g(x)\\) for all \\(x\\) in \\([a, b]\\), is \n\\[ A = \\lim_{n \\to \\infty} \\sum_{i=1}^n[f(x_i^*)-g(x_i^*)]\\delta x \\Leftrightarrow \\int_a^b[f(x)-g(x)]dx \\] \nThe area between the curves \\(y=f(x)\\) and \\(y=g(x)\\) and between \\(x=a\\) and \\(x=b\\) is \n\\[ A = \\int_a^b \\left | f(x)-g(x) \\right | dx \\]\n\n", "meta": {"hexsha": "31c48f48164bbfa2e4fafe4ac9161ee1158617a7", "size": 483, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/5-1.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/5-1.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/5-1.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.25, "max_line_length": 177, "alphanum_fraction": 0.5424430642, "num_tokens": 198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558356, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.7149707834376131}}
{"text": "\\section{Temperature Solver}\nThe flow law, Equation \\eqref{kin.eq.flowlaw}, depends on the temperature of ice. It is, therefore, necessary to determine how the distribution of ice temperatures changes with a changing ice sheet configuration. The thermal evolution of the ice sheet is described by\n\\begin{equation}\n  \\label{temp.eq.temp_z}\n  \\frac{\\pd T}{\\pd t}=\\frac{k}{\\rho c}\\nabla^2T-\\vec{u}\\cdot\\vec\\nabla T+\\frac\\Phi{\\rho c}-w\\frac{\\pd T}{\\pd z},\n\\end{equation}\nwhere $T$ is the absolute temperature, $k$ is the thermal conductivity of ice, $c$ is the specific heat capacity and $\\Phi$ is the heat generated due to internal friction. In the $\\sigma$--coordinate system, Equation \\eqref{temp.eq.temp_z}, becomes\n\\begin{equation}\n  \\label{temp.eq.temp}\n  \\frac{\\pd T}{\\pd t} = \\frac{k}{\\rho cH^2}\\frac{\\pd^2T}{\\pd\\sigma^2} - \\vec{u}\\cdot\\vec\\nabla T + \\frac{\\sigma g}c\\frac{\\pd \\vec{u}}{\\pd\\sigma}\\cdot\\vec\\nabla s + \\frac1H\\frac{\\pd T}{\\pd\\sigma}\\left(w-w_{\\text{grid}}\\right)\n\\end{equation}\nThe terms represents (1) vertical diffusion, (2) horizontal advection, (3) internal heat generation due to friction and (4) vertical advection and a correction due to the sigma coordinate system. Let's rewrite \\eqref{temp.eq.temp} to introduce some names:\n\\begin{equation}\n  \\label{temp.eq.temp2}\n  \\frac{\\pd T}{\\pd t} = a\\frac{\\pd^2T}{\\pd\\sigma^2} +b(\\sigma) + \\Phi(\\sigma) + c(\\sigma)\\frac{\\pd T}{\\pd\\sigma},\n\\end{equation}\nwhere\n\\begin{subequations}\n  \\begin{align}\n    a&=\\frac{k}{\\rho cH^2} \\\\\n    \\label{temp.eq.hadv}\n    b(\\sigma)&=-\\vec{u}\\cdot\\vec\\nabla T\\\\\n    \\Phi(\\sigma)&=\\frac{\\sigma g}c\\frac{\\pd \\vec{u}}{\\pd\\sigma}\\cdot\\vec\\nabla s \\\\\n    c(\\sigma)&=\\frac1H\\left(w-w_{\\text{grid}}\\right)\n  \\end{align}\n\\end{subequations}\n\n\\subsection{Vertical Diffusion}\nDiscretisation of $\\pd^2T/\\pd\\sigma^2$ is slightly complicated because the vertical grid is irregular. Using Taylor series the central difference formulas are\n\\begin{subequations}\n  \\begin{align}\n    \\label{temp.eq.d1}\n    \\left.\\frac{\\pd T}{\\pd\\sigma}\\right|_{\\sigma_{k-1/2}}&=\\frac{T_k-T_{k-1}}{\\sigma_k-\\sigma_{k-1}}\\\\\n    \\intertext{and}\n    \\label{temp.eq.d2}\n    \\left.\\frac{\\pd T}{\\pd\\sigma}\\right|_{\\sigma_{k+1/2}}&=\\frac{T_{k+1}-T_k}{\\sigma_{k+1}-\\sigma_k}\\\\\n    \\intertext{The second partial derivative is then, also uning central differences:}\n    \\label{temp.eq.d3}\n    \\left.\\frac{\\pd^2 T}{\\pd\\sigma^2}\\right|_{\\sigma_k} &= \\frac{\\left.{\\pd T}/{\\pd\\sigma}\\right|_{\\sigma_{k+1/2}} - \\left.{\\pd T}/{\\pd\\sigma}\\right|_{\\sigma_{k-1/2}}}{1/2\\left(\\sigma_{k+1}-\\sigma_{k-1}\\right)}\\\\\n    \\intertext{Inserting \\eqref{temp.eq.d1} and \\eqref{temp.eq.d2} into \\eqref{temp.eq.d3}, we get:}\n    \\label{temp.eq.d4}\n    &=\\frac{2(T_{k+1}-T_k)}{(\\sigma_{k+1}-\\sigma_k)(\\sigma_{k+1}-\\sigma_{k-1})}-\\frac{2(T_k-T_{k-1})}{(\\sigma_k-\\sigma_{k-1})(\\sigma_{k+1}-\\sigma_{k-1})}\n  \\end{align}\n\\end{subequations}\nFinally, the terms of equation \\eqref{temp.eq.d4} are rearranged:\n\\begin{multline}\n  \\label{temp.eq.dsigma2}\n  \\left.\\frac{\\pd^2 T}{\\pd\\sigma^2}\\right|_{\\sigma_k} = \\frac{2T_{k-1}}{(\\sigma_k-\\sigma_{k-1})(\\sigma_{k+1}-\\sigma_{k-1})} - \\frac{2T_k}{(\\sigma_{k+1}-\\sigma_k)(\\sigma_k-\\sigma_{k-1})}\\\\\n  + \\frac{2T_{k+1}}{(\\sigma_{k+1}-\\sigma_k)(\\sigma_{k+1}-\\sigma_{k-1})}\n\\end{multline}\n\n\\subsection{Horizontal Advection}\nThe horizontal advection term, $- \\vec{u}\\cdot\\vec\\nabla T$ is solved using an upwinding scheme. Let's start with the 1--dimensional case. The method discussed can be straightforwadly extented to 2D. As always, the temperature function is expressed as a Taylor series.\n\\begin{subequations}\n  \\begin{align}\n    \\label{temp.eq.taylor1}\n    T(x+\\Delta x) &=T(x)+\\Delta xT'(x)+\\frac{\\Delta x^2}2T''(x)+\\ldots\\\\\n    \\intertext{If we subsitute $\\Delta x$ with $2\\Delta x$, Equation \\eqref{temp.eq.taylor1}}\n    \\label{temp.eq.taylor2}\n    T(x+2\\Delta x) &=T(x)+2\\Delta xT'(x)+2\\Delta x^2T''(x)+\\ldots\n  \\end{align}\n\\end{subequations}\nFrom \\eqref{temp.eq.taylor1} and \\eqref{temp.eq.taylor2} we can construct a difference formula where the $\\mathcal{O}(\\Delta x^2)$ error is cancelled, by multiplying \\eqref{temp.eq.taylor1} with 4 and substracting the result from \\eqref{temp.eq.taylor2}:\n\\begin{subequations}\n  \\begin{align}\n    \\label{temp.eq.forward_h3}\n    T_+'(x)&=\\frac{4T(x+\\Delta x)-T(x+2\\Delta x)-3T(x)}{2\\Delta x}\\\\\n    \\intertext{and similarly for the backward difference:}\n    T_-'(x)&=-\\frac{4T(x-\\Delta x)-T(x-2\\Delta x)-3T(x)}{2\\Delta x}\n    \\end{align}\n\\end{subequations}\nSo the horizontal advection term in one dimensions becomes:\n\\begin{equation}\n  b_x = -u_x\\frac{\\pd T}{\\pd x}=\\frac{-u_x}{2\\Delta x}\n  \\begin{cases}\n    -(4T_{i-1}-T_{i-2}-3T_i) & \\text{when $u_x>0$} \\\\\n    4T_{i+1}-T_{i+2}-3T_i & \\text{when $u_x<0$} \\\\\n  \\end{cases}\n\\end{equation}\nA similar expression is found for $b_y$ by simply substituting $y$ for $x$. Finally, the combined horizontal advection term, is simply\n\\begin{equation}\n  b=-\\vec{u}\\cdot\\vec\\nabla T=-\\left(u_x\\frac{\\pd T}{\\pd x}+u_y\\frac{\\pd T}{\\pd y}\\right)=b_x+b_y=b_1+b_2T_i\n\\end{equation}\n\n\\subsection{Heat Generation}\nTaking the derivative of \\eqref{kin.eq.vert_velo_sigma} with respect to $\\sigma$, we get\n\\begin{equation}\n  \\frac{\\pd u_x}{\\pd\\sigma} = -2(\\rho g)^nH^{n+1}|\\vec\\nabla s|^{n-1}\\frac{\\pd s}{\\pd x}A(T^\\ast)\\sigma^n\n\\end{equation}\nThus,\n\\begin{equation}\n\\begin{split}\n  \\Phi(\\sigma) &= \\frac{\\sigma g}c\\frac{\\pd \\vec{u}}{\\pd\\sigma}\\cdot\\vec\\nabla s  = \\frac{\\sigma g}c\\left(\\frac{\\pd u_x}{\\pd \\sigma}\\frac{\\pd s}{\\pd x} + \\frac{\\pd u_y}{\\pd \\sigma}\\frac{\\pd s}{\\pd y}\\right)\\\\\n       &= -2(\\rho g)^nH^{n+1}|\\vec\\nabla s|^{n-1}\\frac{\\sigma g}cA(T^\\ast)\\sigma^n \\left(\\left(\\frac{\\pd s}{\\pd x}\\right)^2+\\left(\\frac{\\pd s}{\\pd y}\\right)^2\\right) \\\\\n       &= -\\frac2{c\\rho}(g\\sigma\\rho)^{n+1}\\left(H|\\vec\\nabla s|\\right)^{n+1}A(T^\\ast)\n\\end{split}  \n\\end{equation}\n\nThe constant factor $\\frac2{c\\rho}(g\\sigma\\rho)^{n+1}$ is calculated during initialisation in the subroutine \\texttt{init\\_temp}. This factor is assigned to array \\texttt{c1(1:upn)}. \\texttt{c1} also includes various scaling factors and the factor $1/16$ to normalise $\\mathcal{A}$.\n\nThe next factor, $\\left(H|\\vec\\nabla s|\\right)^{n+1}$ is calculated in the subroutine \\texttt{finddisp}:\n\\begin{equation}\n  {c_2}_{i,j} = \\left(\\tilde{H}_{i,j}\\sqrt{\\tilde{S_x}_{i,j}^2+\\tilde{S_y}_{i,j}^2}\\right)^{n+1},\n\\end{equation}\n\n\nThe final factor is found by averaging over the neighbouring nodes:\n\\begin{equation}\n  \\mathcal{A}_{i,j}=4A_{i,j}+2(A_{i-1,j}+A_{i+1,j}+A_{i,j-1}+A_{i,j+1})+(A_{i-1,j-1}+A_{i+1,j-1}+A_{i+1,j+1}+A_{i-1,j+1})\n\\end{equation}\n\n\\subsection{Vertical Advection}\\label{temp.sec.vert_ad}\nThe vertical advection term, $\\pd T/\\pd\\sigma$ is solved using the central difference formula for unevenly spaced nodes:\n\\begin{equation}\n  \\frac{\\pd T}{\\pd\\sigma}=\\frac{T_{k+1}-T_{k-1}}{\\sigma_{k+1}-\\sigma_{k-1}}\n\\end{equation}\n\n\\subsection{Boundary Conditions}\nAt the upper boundary, ice temperatures are set to the surface temperature, $T_{\\text{surf}}$. The ice at the base is heated by the geothermal heat flux and sliding friction:\n\\begin{equation}\n  \\left.\\frac{\\pd T}{\\pd\\sigma}\\right|_{\\sigma=1}=-\\frac{GH}k-\\frac{H\\vec{\\tau}_b\\cdot\\vec{u}(1)}k,\n\\end{equation}\nwhere $\\vec{\\tau}_b=-\\rho gH\\vec\\nabla s$ is the basal shear stress and $\\vec{u}(1)$ is the basal ice velocity. Ice temperatures are held constant if they reach the pressure melting point of ice, i.e.\n\\begin{equation}\n  T^\\ast=T_{\\text{pmp}} \\quad\\text{if $T\\ge T_{\\text{pmp}}$}.\n\\end{equation}\nExcess heat is then used to formulate a melt rate, $S$:\n\\begin{equation}\n  \\label{temp.eq.meltrate}\n  S=\\frac{k}{\\rho L}\\left(\\frac{\\pd T^\\ast}{\\pd z}-\\frac{\\pd T}{\\pd z}\\right),\n\\end{equation}\nwhere $L$ is the specific latent heat of fusion. Finally, basal temperatures are held constant, if the ice is floating:\n\\begin{equation}\n  \\frac{\\pd T(1)}{\\pd t}  = 0.\n\\end{equation}\n\n\n\\subsection{Putting it all together}\nEquation \\eqref{temp.eq.temp} is solved for each ice column. The horizontal dependency of the horizontal advection term, \\eqref{temp.eq.hadv}, is resolved by iterating the vertical solution. Putting the individual terms together using a fully explicit finite differences scheme, Equation \\eqref{temp.eq.temp2} becomes\n\\begin{subequations}\n  \\begin{multline}\n    \\label{temp.eq.temp3a}\n    \\frac{T_{k,t+1}-T_{k,t}}{\\Delta t} = \\left(\\frac{2aT_{k-1,t}}{(\\sigma_k-\\sigma_{k-1})(\\sigma_{k+1}-\\sigma_{k-1})} - \\frac{2aT_{k,t}}{(\\sigma_{k+1}-\\sigma_k)(\\sigma_k-\\sigma_{k-1,t})}\\right. \\\\\n    \\left.+ \\frac{2aT_{k+1,t}}{(\\sigma_{k+1}-\\sigma_k)(\\sigma_{k+1}-\\sigma_{k-1})}\\right)+{b_1}_{k,t}+{b_2}_kT_{k,t}+\\Phi_k+c_k\\frac{T_{k+1,t}-T_{k-1,t}}{\\sigma_{k+1}-\\sigma_{k-1}}\n\\end{multline}\nand similarly the fully implicit scheme\n  \\begin{multline}\n    \\label{temp.eq.temp3b}\n    \\frac{T_{k,t+1}-T_{k,t}}{\\Delta t} = \\left(\\frac{2aT_{k-1,t+1}}{(\\sigma_k-\\sigma_{k-1})(\\sigma_{k+1}-\\sigma_{k-1})} - \\frac{2aT_{k,t+1}}{(\\sigma_{k+1}-\\sigma_k)(\\sigma_k-\\sigma_{k-1,t+1})}\\right. \\\\\n    \\left.+ \\frac{2aT_{k+1,t+1}}{(\\sigma_{k+1}-\\sigma_k)(\\sigma_{k+1}-\\sigma_{k-1})}\\right)+{b_1}_{k,t+1}+{b_2}_kT_{k,t+1}+\\Phi_k+c_k\\frac{T_{k+1,t+1}-T_{k-1,t+1}}{\\sigma_{k+1}-\\sigma_{k-1}}\n\\end{multline}\n\\end{subequations}\nTaking the average of Equations \\eqref{temp.eq.temp3a} and \\eqref{temp.eq.temp3b} gives the \\emph{Crank--Nicholson scheme}. The resulting equation is then rearranged and terms of $T_{k-1,t+1}$, $T_{k,t+1}$ and $T_{k+1,t+1}$ are combined to give the tri--diagonal system\n\\begin{equation}\n  \\alpha_kT_{k-1,t+1}+\\beta_kT_{k,t+1}+\\gamma_kT_{k+1,t+1}=\\delta_k\n\\end{equation}\nwhere, for $k=2,N-1$\n\\begin{subequations}\n  \\begin{align}\n    \\alpha_k &= -\\frac12\\frac{2a\\Delta t}{(\\sigma_k-\\sigma_{k-1})(\\sigma_{k+1}-\\sigma_{k-1})}+\\frac12\\frac{c_k\\Delta t}{\\sigma_{k+1}-\\sigma_{k-1}} \\\\\n    \\beta_k &= 1+\\frac12\\frac{2a\\Delta t}{(\\sigma_{k+1}-\\sigma_k)(\\sigma_k-\\sigma_{k-1})}-\\frac12{b_2}_k\\Delta t=1-\\alpha_k-\\gamma_k-\\frac12{b_2}_k\\Delta t\\\\\n    \\gamma_k &= -\\frac12\\frac{2a\\Delta t}{(\\sigma_{k+1}-\\sigma_k)(\\sigma_{k+1}-\\sigma_{k-1})}-\\frac12\\frac{c_k\\Delta t}{\\sigma_{k+1}-\\sigma_{k-1}} \\\\\n    \\delta_k &= -\\alpha_kT_{k-1,t}+(2-\\beta_k)T_{k,t}-\\gamma_kT_{k+1,t}+\\frac12({b_1}_{k,t}+{b_1}_{k,t+1})\\Delta t+\\Phi_k\\Delta t\n  \\end{align}\n\n\\subsubsection{Boundary Conditions}\nAt the upper boundary:\n\\begin{equation}\n  \\alpha_1=0,\\quad\\beta_1=1,\\quad\\gamma_1=0,\\quad\\delta_1=T_{\\text{surf}}\n\\end{equation}\n\\end{subequations}\n\n\nThe lower boundary condition is somewhat more complicated. Here we only look at the case when the temperature is below the pressure melting point of ice. BC for floating ice and temperatures at the pressure melting point of ice are trivial. The geothermal heat flux is applied at the lower boundary, i.e. Equation \\eqref{temp.eq.d2} becomes\n\\begin{equation}\n  \\label{temp.eq.d2-lb}\n  \\left.\\frac{\\pd T}{\\pd\\sigma}\\right|_{\\sigma_{k+1/2}}=-\\frac{GH}k\n\\end{equation}\nAssuming that $\\sigma_k-\\sigma_{k-1}=\\sigma_{k+1}-\\sigma_k=\\Delta\\sigma$ and inserting \\eqref{temp.eq.d1} and \\eqref{temp.eq.d2-lb} into \\eqref{temp.eq.d3}, the second partial derivative becomes\n\\begin{equation}\n  \\left.\\frac{\\pd^2 T}{\\pd\\sigma^2}\\right|_{\\sigma_N} = \\left(-\\frac{GH}k-\\frac{T_N-T_{N-1}}{\\Delta\\sigma}\\right)/\\Delta\\sigma=-\\frac{GH}{k\\Delta\\sigma}-\\frac{T_N-T_{N-1}}{\\Delta\\sigma^2}\n\\end{equation}\nInserting the new conduction term and replacing the derivative of the vertical advection term with the Neuman boundary condition, Equation \\eqref{temp.eq.temp3a} becomes\n\\begin{subequations}\n  \\begin{equation}\n    \\frac{T_{N,t+1}-T_{N,t}}{\\Delta t} = -a\\left(\\frac{GH}{k\\Delta\\sigma}+\\frac{T_{N,t}-T_{N-1,t}}{\\Delta\\sigma^2}\\right)+{b_1}_{N,t}+{b_2}_NT_{N,t}+\\Phi_N-c_N\\frac{GH}k\n  \\end{equation}\n  and similarly for Equation \\eqref{temp.eq.temp3b}\n  \\begin{multline}\n    \\frac{T_{N,t+1}-T_{N,t}}{\\Delta t} = -a\\left(\\frac{GH}{k\\Delta\\sigma}+\\frac{T_{N,t+1}-T_{N-1,t+1}}{\\Delta\\sigma^2}\\right)+{b_1}_{N,t+1}+{b_2}_NT_{N,t+1}\\\\\n    +\\Phi_N-c_N\\frac{GH}k\n  \\end{multline}\n\\end{subequations}\nThe elements of the tri--diagonal system at the lower boundary are then\n\\begin{subequations}\n  \\begin{gather}\n    \\alpha_N =-\\frac{a\\Delta t}{2(\\sigma_N-\\sigma_{N-1})^2}\\\\\n    \\beta_N = 1-\\alpha_N+\\frac12{b_2}_N\\Delta t\\\\\n    \\gamma_N = 0 \\\\\n    \\begin{split}\n      \\delta_N =&-\\alpha_NT_{N-1,t}+(2-\\beta_N)T_{N,t}-a\\frac{GH\\Delta t}{k(\\sigma_N-\\sigma_{N-1})}\\\\\n      &+\\frac12({b_1}_{N,t}+{b_1}_{N,t+1})\\Delta t+\\Phi_N\\Delta t-c_N\\frac{GH\\Delta t}k\n    \\end{split}\n  \\end{gather}\n\\end{subequations}\n\n", "meta": {"hexsha": "98e0701ff708433bf8e4866000281307a1ea7246", "size": 12476, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "models/glc/cism/glimmer-cism/doc/num/temp.tex", "max_stars_repo_name": "fmyuan/clm-microbe", "max_stars_repo_head_hexsha": "9faee9ed7d6c092c4a9e4a207f32cbffab78b85c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-03-12T01:58:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-16T03:08:25.000Z", "max_issues_repo_path": "models/glc/cism/glimmer-cism/doc/num/temp.tex", "max_issues_repo_name": "fmyuan/clm-microbe", "max_issues_repo_head_hexsha": "9faee9ed7d6c092c4a9e4a207f32cbffab78b85c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-21T01:51:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-21T01:51:13.000Z", "max_forks_repo_path": "models/glc/cism/glimmer-cism/doc/num/temp.tex", "max_forks_repo_name": "email-clm/CLM-Microbe", "max_forks_repo_head_hexsha": "711c87faec2c1bfe2cea1a7ebd07e4373e82a184", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2016-03-08T21:04:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-16T03:29:35.000Z", "avg_line_length": 60.270531401, "max_line_length": 340, "alphanum_fraction": 0.674094261, "num_tokens": 4794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7149615032494501}}
{"text": "\\chapter{Finance}\n\n\\section{Asset}\n\nIf \\(x \\in \\Real\\) then \\(cash(x)\\) is an asset.\n\nIf \\(t \\in \\Real\\) and \\(x\\) is an asset,\nthen \\(delay(t,x)\\) is an asset.\n\nIf \\(p \\in [0,1]\\) and \\(x\\) is an asset,\nthen \\(chance(p,x)\\) is an asset.\n\nSee also \\emph{Composing contracts: an adventure in financial engineering} \\cite{SpjContract}.\n\n\\section{Value function}\n\nLet \\(V\\) be the value function.\n\n\\(V(cash(x)) = x\\).\n\n\\(V(chance(p,x)) = p \\cdot V(x)\\).\n\n\\(V(delay(t,x)) = V(x)/(1+r)^t\\).\n\n\\section{Time preference}\n\nLet \\(r\\) be the interest rate.\nLet \\(x\\) be an amount.\n\nThe \\emph{future value} of \\(x\\) at time \\(t\\) is \\((1+r)^t x\\).\n\nThe \\emph{present value} of \\(delay(t,x)\\) is \\(x / (1+r)^t\\).\n\n\\section{Risk-free interest rate}\n\n\\emph{Your} risk-free interest rate is\nthe highest government-guaranteed interest you can get.\n\n\\section{Perpetuity}\n\nA perpetuity is \\(\\sum_{t \\in \\Nat} delay(t,p) \\).\n\nLet \\(r\\) be the risk-free interest rate.\nLet \\(p\\) be an installment.\nLet all installments be the same.\n\nThe present value of such perpetuity is \\(\\frac{p}{r}\\).\n\n\\section{No-arbitrage}\n", "meta": {"hexsha": "643c2babd20aae38fda6ac261bd62b4749ea21b9", "size": 1093, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/finance.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/finance.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/finance.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 21.86, "max_line_length": 94, "alphanum_fraction": 0.6386093321, "num_tokens": 352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428691, "lm_q2_score": 0.7606506635289835, "lm_q1q2_score": 0.7149457119246219}}
{"text": "\\section{Taylor Expanding the Doppler operator \\\\ (and why this is a bad idea)}\n\\label{sec:taylor}\n%\nAn alternative way to tackle the problem is to linearize the Doppler \noperator via a Taylor expansion in $\\alpha$ about $\\alpha=0$:\n%\n\\begin{align}\n    \\label{eq:taylor:I}\n    I(\\xi, x, y) \n        &=\n        I_0(\\xi_0, x, y) \\Bigg|_{\\alpha=0}\n        + \n        \\frac{\\mathrm{d}I_0(\\xi_0, x, y)}{\\mathrm{d}\\alpha} \\Bigg|_{\\alpha=0} \n            \\Delta\\alpha(x, y)\n        + \n        \\frac{1}{2}\\frac{\\mathrm{d}^2I_0(\\xi_0, x, y)}{\\mathrm{d}\\alpha^2} \n            \\Bigg|_{\\alpha=0} \\Delta\\alpha(x, y)^2\n        +\n        ... \n\\end{align}\n%\nSince the dependence of Equation~(\\ref{eq:xi0}) on $\\alpha$ is trivial,\nthe derivatives of the spectrum $I_0(\\xi_0)$ with respect to\n$\\alpha$ are simply\n%\n\\begin{align}\n    \\frac{\\mathrm{d}^nI_0(\\xi_0, x, y)}{\\mathrm{d}\\alpha^n} &=\n    \\dfrac{\\mathrm{d}^nI_0(\\xi_0, x, y)}{\\mathrm{d}\\xi_0^n} \\nonumber\\\\ &\\equiv\n    I_0^{(n)}(\\xi_0, x, y)\n    \\quad.\n\\end{align}\n%\nGiven this result, and noting that $\\xi_0 = \\xi$ when $\\alpha = 0$,\nwe may re-write Equation~(\\ref{eq:taylor:I}) as\n%\n\\begin{proof}{Taylor}\n    \\label{eq:taylor:ISum}\n    I(\\xi, x, y) \n        &=\n        \\sum_{n=0}^\\infty\n            \\frac{I_{0}^{(n)}(\\xi, x, y)}{n!}\n            \\Delta\\alpha(x, y)^n\n        \\quad ,\n\\end{proof}\n%\nThe utility of this expression is that the velocity dependence of the spectrum\nis now entirely encoded in the terms $\\Delta\\alpha(x, y)^n$, which are\n\\emph{independent of wavelength}. We can further decouple the spatial\ndependence from the spectral dependence by expressing the intensity field\nas an expansion over spherical harmonics $Y_{lm}(x, y)$ in the sky-projected\ncoordinates:\n%\n\\begin{align}\n    I_0(\\xi, x, y) = \\sum_{l=0}^\\infty\\sum_{m=-l}^{l} a_{lm}(\\xi) Y_{lm}(x, y)\n    \\quad .\n\\end{align}\n%\nEquation~(\\ref{eq:taylor:ISum}) now reads\n%\n\\begin{align}\n    \\label{eq:taylor:IYlm}\n    I(\\xi, x, y) \n        &=\n        \\sum_{n=0}^\\infty\n            \\sum_{l=0}^\\infty\\sum_{m=-l}^{l}\n                \\frac{a_{lm}^{(n)}(\\xi)}{n!}\n                Y_{lm}(x, y)\\Delta\\alpha(x, y)^n\n            \\quad .\n\\end{align}\n%\nFinally, integrating this equation over the visible disk of \nthe star, we arrive at an equation for the observed spectrum:\n%\n\\begin{align}\n    \\label{eq:taylor:S}\n    S(\\xi) \n        &=\n        \\sum_{n=0}^\\infty\n            \\sum_{l=0}^\\infty\\sum_{m=-l}^{l}\n                \\frac{a_{lm}^{(n)}(\\xi)}{n!}\n                \\iint\\limits_{\\mathcal{S}(x, y)}\n                Y_{lm}(x, y)\\Delta\\alpha(x, y)^n\n                \\mathrm{d}{\\mathcal{S}(x, y)}\n            \\quad .\n\\end{align}\n%\nBy expanding the spectrum in both the spectral and spatial dimensions, we\nhave effectively decoupled the two. However, Equation~(\\ref{eq:taylor:S}) \nis impractical for three reasons. First, the surface integrals can be very\ndifficult to solve (although we will show later how these integrals may be\napproximated analytically). Second, it requires knowledge of high order \nderivatives of the spectrum, which may not always be easy or convenient to \ncompute. Third, and most important, the series expansion in $n$ is typically \nextremely slow to converge and is therefore only practically useful in the \nlimit that the Doppler shift is much smaller than the typical width of a \nspectral line; see the notebook link next to Equation~(\\ref{eq:taylor:ISum}) \nfor an example.", "meta": {"hexsha": "753935d900bfc8b952272f885ade25d16585df6e", "size": 3403, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/ideas.tex", "max_stars_repo_name": "rodluger/fishy", "max_stars_repo_head_hexsha": "94bb393b01ade283e416589ea013d604166749e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/ideas.tex", "max_issues_repo_name": "rodluger/fishy", "max_issues_repo_head_hexsha": "94bb393b01ade283e416589ea013d604166749e3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/ideas.tex", "max_forks_repo_name": "rodluger/fishy", "max_forks_repo_head_hexsha": "94bb393b01ade283e416589ea013d604166749e3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.0824742268, "max_line_length": 79, "alphanum_fraction": 0.6153394064, "num_tokens": 1122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.7606506418255927, "lm_q1q2_score": 0.7149456902450463}}
{"text": "\\section{Probability Theory}\n\n\\subsection{Exercise 1}\n(a) Four character strings consisting of H and T (16 total).\n\n(b) $\\mathbb{N}$\n\n(c) $\\mathbb{R}^+$\n\n(d) $\\mathbb{R}^+ / 0$\n\n(e) $\\frac{i}{n}$ for $i = 0, ..., n$.\n\n\\subsection{Exercise 4}\n(a) $P(A) + P(B) - P(A \\cap B)$ \n\n(b) $P(A) + P(B) - 2P(A \\cap B)$ \n\n(c) Same as (a).\n\n(d) $1 - P(A \\cap B)$\n\n\\subsection{Exercise 6}\nWe have $u + w = 1 \\implies u^2 + 2uw + w^2 = 1$. However, it is not possible for\n$u^2, 2uw, w^2$ to all equal $\\frac{1}{3}$; thus, there are no such $u, w$.\n\n\\subsection{Exercise 12}\n(a) Just a case of countable additivity.\n\n(b) Split $\\cup_{i = 1}^{\\infty} A_i$ into $\\cup_{i = 1}^{n} A_i$ and $\\cup_{i = n + 1}^{\\infty} A_i$.\nTaking $n \\to  \\infty$ sends the probability of the latter union to 0, leaving the\ndesired result.\n\n\\subsection{Exercise 13}\nNo, since $P(B^c) = 1 - P(B) \\implies P(B) = \\frac{3}{4}$ and $\\frac{3}{4} + \\frac{1}{3} > 1$.\n\n\\subsection{Exercise 18}\nThis exercise (based on the provided answer) seems to assume that the balls are distinguishable. \nThere are $n^n$ different arrangements of balls in cells (each ball has $n$ options). If \nexactly one cell must remain empty, then exactly one other cell must have two balls. There are\n$n$ choices for the empty cell and $n - 1$ choices for the double cell. The two balls to go into\nthe double cell can be chosen in $\\binom{n}{2}$ ways, and the remaining balls can be ordered in\n$(n - 2)!$ ways (since they are distinguishable), hence giving the provided result.\n\n\\subsection{Exercise 21}\nThere are $\\binom{2n}{2r}$ ways to choose $2r$ shoes from the collection. If we want to ensure that\nno pairs of shoes are drawn, we should only draw one shoe from each of the $n$ pairs, which we can do\nin $\\binom{n}{2r}$ ways. For each of the $2r$ shoes we can either choose the right or left shoe from \nthe pair (assuming distinguishability).\n\n\\subsection{Exercise 23}\nWe use \\href{https://en.wikipedia.org/wiki/Vandermonde%27s_identity}{Vandermonde's identity} with $m = n = r$ to get\n\\begin{align*}\n        \\sum_{k = 0}^n \\bigg(\\frac{1}{2^n} \\binom{n}{k} \\bigg)^2 = \\frac{1}{4^n} \\binom{2n}{n}\n\\end{align*}\n\n\\subsection{Exercise 25}\nDepends on how you define the sample space, see \\href{https://en.wikipedia.org/wiki/Boy_or_Girl_paradox#Analysis_of_the_ambiguity}{Wikipedia} for a lengthy discussion.\n\n\\subsection{Exercise 26}\nWe take the complement of the probability that we roll a 6 in the first 5 rolls:\n$1 - \\sum_{k = 0}^{4} \\frac{5^k}{6^{k+1}}$.\n\n\\subsection{Exercise 35}\nFrom the definition of conditional probability and the fact that $P(B) > 0$,\nwe have that $P(\\cdot | B) > 0$ and $P(S | B) = \\frac{P(B)}{P(B)} = 1$. Countable additivity\nfollows from $A \\cap B$ and $A' \\cap B$ being disjoint if $A$ and $A'$ are.\n\n\\subsection{Exercise 36}\nTo solve the first part, we take the complement of the probability that the target was hit fewer than\ntwo times, which is\n\\begin{align*}\n        1 - \\bigg(\\frac{4}{5}\\bigg)^{10} - 10\\bigg(\\frac{4}{5}\\bigg)^9 \\frac{1}{5} \\approx 0.624\n\\end{align*}\nIf we let $A$ be the event that the target was hit at least once, and $B$ be the event that the target was\nhit at least twice, then we see that $A \\cap B = B$. The conditional probability is thus\n\\begin{align*}\n        \\frac{1 - \\bigg(\\frac{4}{5}\\bigg)^{10} - 10\\bigg(\\frac{4}{5}\\bigg)^9 \\frac{1}{5}}{1 - \\bigg(\\frac{4}{5}\\bigg)^{10}} \\approx 0.699\n\\end{align*}\n", "meta": {"hexsha": "f593b84ab62029f5cc317344e60230ea9a7efb08", "size": 3399, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Stat_Inference_Casella_Berger/chapter_1.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "Stat_Inference_Casella_Berger/chapter_1.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Stat_Inference_Casella_Berger/chapter_1.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.4875, "max_line_length": 167, "alphanum_fraction": 0.6696087084, "num_tokens": 1172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.8670357598021708, "lm_q1q2_score": 0.7148379802431384}}
{"text": "\\section{Sets and Relations}\n\n\\frame{\n{Part 1: Sets and Relations}\n\n\\tableofcontents[currentsection,hideallsubsections, firstsection=2, sections={2-4}]\n}\n\n\\subsection{Sets: Definitions}\n\\begin{frame}\n  \\frametitle{Mathematical Set}\n\n  \\structure{Mathematical Sets} are useful when talking about proofs. Last class we have already used some sets: \\bigskip\n\n  \\begin{itemize}\n    \\item $\\mathbb{N}$ -- Set of natural (non negative) numbers;\n    \\item $\\mathbb{Z}$ -- Set of integer numbers;\n    \\item $\\mathbb{R}$ -- Set of real numbers;\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Characteristics of sets}\n\n  \\begin{itemize}\n    \\item  \\structure{Mathematical Sets} can mix different \"types\" of objects:\n    \\begin{itemize}\n    \\item \\{7, ``Aranha'', $\\pi/2$, TRUE\\}\n    \\end{itemize}\\bigskip\n\n    \\item \\structure{Mathematical Sets} do not have a concept of \"order\":\n    \\begin{itemize}\n      \\item \\{7, ``Aranha'', $\\pi/2$, TRUE\\} =   \\item \\{TRUE, 7, $\\pi/2$, ``Aranha''\\}\n    \\end{itemize}\\bigskip\n\n    \\item \\structure{Mathematical Sets} do not contain duplicates:\n    \\begin{itemize}\n    \\item \\{7, $\\pi$\\} = \\{7, $\\pi$, 7\\}\n    \\end{itemize}\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Set: Membership}\n\n  The fundamental property of a set is \\structure{membership}, represented by the symbol $\\in$. Note that membership is \\alert{not} recursive!\\vfill\n\n  \\begin{columns}\n    \\column{.5\\textwidth}\n  A = \\{7,TRUE,$\\pi$\\}\n  \\begin{itemize}\n  \\item $7 \\in A$\n  \\item 7 is an element of $A$,\n  \\item $3 \\notin A$\n  \\end{itemize}\\bigskip\n\n  \\column{.5\\textwidth}\n  B = \\{7, $\\mathbb{Z}$, 3\\}\n  \\begin{itemize}\n    \\item $7 \\in B$\n    \\item $7 \\in \\mathbb{Z}$\n    \\item $\\mathbb{Z} \\in B$\n    \\item \\alert{$1 \\notin B$}\n  \\end{itemize}\n\\end{columns}\n\\end{frame}\n\n\\begin{frame}{Set: Subsets}\n\n  {\\larger\n  \\begin{block}{Subset}\n    \\begin{itemize}\n    \\item $A \\subset B$ means that every element of A is also an element of B\n    \\item $A\\subset B \\text{ equiv }\\forall x, x\\in A \\rightarrow x\\in B$\n    \\item $\\mathbb{Z} \\subset \\mathbb{R}, \\mathbb{R} \\subset \\mathbb{C}, \\{3\\} \\subset \\{5,3,7\\}$\n    \\end{itemize}\n  \\end{block}\n\n  \\begin{block}{Important!}\n    \\begin{itemize}\n    \\item $A \\subset A$\n    \\item $\\forall X\\text{ is a set}, \\varnothing \\subset X$\n    \\end{itemize}\n  \\end{block}\n  }\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Difference between Membership and Subset}\n\n  \\begin{columns}[T]\n    \\column{0.5\\textwidth}\n    \\structure{Membership} ($\\in, \\notin$) indicates if one member is part of a set. \\structure{Subset} ($\\subset, \\not\\subset$) indicates if one set contains the members of other sets.\n\n    \\column{0.5\\textwidth}\n  {\\larger\n  \\begin{itemize}\n  \\item $3 \\in \\{3,5,6\\}$\n  \\item $3 \\not\\subset \\{3,5,6\\}$\n  \\end{itemize}\n  \\bigskip\n\n  \\begin{itemize}\n  \\item $\\{3\\} \\subset \\{3,5,6\\}$\n  \\item $\\{3\\} \\notin \\{3,5,6\\}$\n  \\end{itemize}\n  \\bigskip\n\n  \\begin{itemize}\n    \\item $\\{3\\} \\in \\{5, 6, \\{3\\}\\}$\n  \\end{itemize}\n  }\n  \\end{columns}\n\\end{frame}\n\n\\begin{frame}{Power Set}\n  The \\structure{Power Set} of A is a special set composed of ALL subsets of A.\n\n  \\begin{equation*}\n    POW(A) = \\forall x \\subset A, x \\in POW(A)\n  \\end{equation*}\n\n  For example:\n\n  \\begin{equation*}\n    POW(\\{T,F\\}) = \\{\\{T\\},\\{F\\},\\{T,F\\},\\varnothing\\}\n  \\end{equation*}\n\n  The definition of power set means that for any set $A$ contained in $B$, $A$ is an element of POW(B):\n\n  \\begin{equation*}\n    \\mathbb{N} \\in POW(\\mathbb{R}), \\mathbb{N} \\subset \\mathbb{R}, \\mathbb{N} \\notin \\mathbb{R}\n  \\end{equation*}\n\\end{frame}\n\n\n\\begin{frame}{Operations on Sets}\n\n  Finally, You should be familiar with the regular operations on sets:\n  \\bigskip\n\n    \\begin{itemize}\n    \\item Union: $A \\cup B \\rightarrow x \\in A \\lor x \\in B$\\bigskip\n    \\item Intersection: $A \\cap B \\rightarrow x \\in A \\land x \\in B$\\bigskip\n    \\item Subtraction: $A - B \\rightarrow x \\in A \\land x \\notin B$\\bigskip\n    \\item Complement: $\\overline{A} = D - A$, where $D$ is the \\structure{domain}\\\\ (the \"everything\" set or \"parent\" set of interest).\n    \\end{itemize}\n\\end{frame}\n\n\\subsection{Sets and Proofs}\n\n\\begin{frame}{Sets, Proofs and Predicates}\n\n  Sets are used often as parts of proofs. We used sets a little bit when we talked about the \\structure{Well Ordering Principle}.\\bigskip\n\n  It is common to use predicates to determine what elements are members of a set. For example, $P(X)$ be a predicate that defines $A$. If $P(X)$ is true for a certain $X$, then $X \\in A$.\n\n  \\begin{block}{Example 1}\n    \\begin{itemize}\n    \\item $A = x \\in \\mathbb{N}, \\{x < 12 \\text{ AND } x \\text{ is prime}\\}$\n    $\\implies A = \\{2,3,5,7,11\\}$\n    \\end{itemize}\n    A is the set of \"prime numbers smaller than 12\"\n  \\end{block}\n\n  \\begin{block}{Example 2}\n    \\begin{itemize}\n    \\item $B = x \\in \\mathbb{N}, \\{x \\text{ is prime AND } x+2 \\text{ is prime}\\} \\implies$\\\\\n    $B = \\{3 (5), 5 (7), 11 (13), 17 (19), 29 (31), \\ldots\\}$\n    \\end{itemize}\n    B is the set of \"prime numbers x where x+2 is also prime\".\n  \\end{block}\n\\end{frame}\n\n\n\\begin{frame}{Sets and Proofs Example (1)}\n{Prove that the empty set is a subset of every set.}\n\n  \\begin{proof}\n    Proof by construction:\n\n  \\begin{enumerate}\n\n  \\item $A \\subset B$ means that $\\forall x, x \\in A \\rightarrow x \\in B$\\bigskip\n\n  \\item If $A = \\varnothing$ then $x \\in A$ is FALSE for $\\forall x$, so we can replace ``$\\forall x \\in A$'' with FALSE in {\\bf (1)}\\bigskip\n\n\\item The statement FALSE $\\rightarrow x \\in B$ is always TRUE.\\\\ \\hfill (remember that FALSE $\\rightarrow X$ is always TRUE)\\bigskip\n\n  \\item Therefore, $\\varnothing \\subset B$ is TRUE $\\forall B$\n  \\end{enumerate}\n  \\end{proof}\n\\end{frame}\n\n\n\\begin{frame}{Sets and Proofs Example (2)}\n{Proof that Union and Intersection are Distributive}\n\n  \\begin{equation*}\n    A \\cup (B \\cap C) \\iff (A \\cup B) \\cap (A \\cup C)\n  \\end{equation*}\n\n  \\begin{proof}\n    Proof by sequence of \"IFF\"s:\n    \\begin{enumerate}\n    \\item \\structure{$x \\in A \\cup (B \\cap C)$} {\\bf iff}\n    \\item $x \\in A \\lor x \\in (B \\cap C)$ {\\bf iff} \\hfill (definition of union)\n    \\item $x \\in A \\lor (x \\in B \\land x \\in C)$ {\\bf iff} \\hfill\n      (definition of intersection)\n    \\item $(x \\in A \\lor x \\in B) \\land (x\\in A \\lor x \\in C)$ {\\bf\n      iff} \\hfill (distributive prop.)\n    \\item $(x \\in A\\cup B) \\land (x \\in A\\cup C)$ {\\bf iff}\\hfill\n      (definition of union)\n    \\item \\structure{$x \\in (A\\cup B)\\cap (A\\cup C)$}  \\hfill\n      (defintion of intersection)\n\n    \\end{enumerate}\n  \\end{proof}\n\\end{frame}\n\n\\subsection{Binary Relations}\n\\begin{frame}\n  \\frametitle{Definition of Binary Relations}\n  \\structure{Binary Relations} define an association of elements from one set (the {\\bf domain}) to another set (the {\\bf co-domain}). We see (binary) relations in many different situations:\\bigskip\n\n  \\begin{itemize}\n    \\item Functions are a special case of binary relations: f(x) = y.\n    \\begin{itemize}\n      \\item A function associates the set of inputs with the sets of outputs;\n    \\end{itemize}\\bigskip\n\n    \\item Operations such as set membership can be expressed as binary relations.\n    \\begin{itemize}\n      \\item For example, the predicate $P(x): x is prime$ defines a binary relation from $\\mathbb{N}$ to \\{TRUE, FALSE\\}\n    \\end{itemize}\\bigskip\n\n    \\item \"Relational Databases\" (for example, SQL) are also based on the idea of binary relations\n    \\begin{itemize}\n      \\item Key of X, member of a table, joint key, etc;\n    \\end{itemize}\n    \\end{itemize}\n\\end{frame}\n\n\\subsection{Binary Relation Definitons}\n\n\\begin{frame}{Example of Binary Relation}\n\n  \\begin{columns}[t]\n    \\column{0.4\\textwidth}\n    Let's consider the binary relation from the set of students {\\bf (D)} that are registered to the set of subjects {\\bf (J)}.\\bigskip\n\n    Components of a binary relation:\n    \\begin{itemize}\n    \\item \\structure{Domain}: Set of Students;\n    \\item \\structure{Co-domain}: Set of Classes;\n    \\item \\structure{Relation Graph}:\n    \\begin{itemize}\n      \\item Vertices: Union of Domain and Co-domain;\n      \\item Edges: Directed edges from Domain to Co-domain;\n    \\end{itemize}\n    \\end{itemize}\\bigskip\n\n    \\column{0.6\\textwidth}\n\n    \\begin{center}\n      \\includegraphics[width=0.6\\textwidth]{../img/relations}\n    \\end{center}\\pagenote{Relation Graph Image from MIT OCS}\n    Representation of a binary relation:\n    \\begin{itemize}\n    \\item $R($Jason$) = \\{6.042, 6.012\\}$\n    \\item Jason $R$ 6.042\n    \\item $R(\\{$Jason, Yihui$\\}) = \\{6.042, 6.012, 6.004\\}$\n    \\end{itemize}\n  \\end{columns}\n\\end{frame}\n\n\n\\begin{frame}{Relations and Inverse Relations}\n\n  If we think of a binary relation as a directed graph, the \\structure{Inverse Relation} is the relation defined by the same graph when the edges are reversed:\\bigskip\n\n  Relation $R$:\n  \\begin{equation*}\n    R(X) ::= {j \\in J | \\exists d \\in X. d R j}\n  \\end{equation*}\n\n  Reverse Relation $R^{-1}$:\n  \\begin{equation*}\n    R^{-1}(Y) ::= {d \\in S | \\exists j \\in Y. d R j}\n  \\end{equation*}\n  \\bigskip\n\n  \\begin{columns}\n    \\column{0.5\\textwidth}\n    \\begin{itemize}\n      \\item $R(Jason) = \\{6.042, 6.012\\}$\n      \\item $R^{-1}(6.012) = \\{Jason, Yihui\\}$\n    \\end{itemize}\n    \\column{0.5\\textwidth}\n    \\begin{center}\n      \\includegraphics[width=0.6\\textwidth]{../img/relations}\n    \\end{center}\n  \\end{columns}\n\\end{frame}\n\n\\begin{frame}{Composite Relations}\n\n  \\begin{columns}[t]\n\n    \\column{0.5\\textwidth}\n    If we have a relation $V$ from set $P$ to set $D$, and a relation $R$ from set $D$ to set $J$, then we can define a \\structure{composite} relation $R\\circ V$ from set $P$ to set $J$ (we can also use $R(V)$).\\bigskip\n\n    \\begin{itemize}\n    \\item $R(V(X))$ or $(R\\circ V)(X)$\n    \\item $R(V(\\text{FTL})) = \\{6.003\\}$\n    \\begin{itemize}\n      \\item professor FTL super{\\bf V}ises Joan;\\bigskip\n\n      \\item Joan is {\\bf R}egistered to class 6.003;\n    \\end{itemize}\n    \\end{itemize}\n\n\n    \\column{0.5\\textwidth}\n    \\begin{center}\n      \\includegraphics[width=0.8\\textwidth]{../img/composite_relation}\n    \\end{center}\n\n  \\end{columns}\n\\end{frame}\n\n\n\\begin{frame}{Types of Binary Relations}\n\n  We can classify a binary relation based on the number of degrees (arrows) in the relation graph. Imagine a relation $R$ from $X$ to $Y$ (i.e.: $R(X) = Y$)\\bigskip\n\n  Classification of $R$ based on $Y$:\n  \\begin{itemize}\n  \\item {\\bf Surjection}: Every element in $Y$ has $\\geq 1$ in-arrows. (Every Y has {\\bf one or more} X)\n  \\item {\\bf Injection}: Every element in $Y$ has $\\leq 1$ in-arrows. (Every Y has {\\bf one or less} X)\n  \\end{itemize}\\smallskip\n\n  Classification of $R$ based on $X$:\n  \\begin{itemize}\n  \\item {\\bf Total}: Every element in $X$ has $\\geq 1$ out arrows. (Every $X$ has {\\bf one or more} $Y$)\n  \\item {\\bf Function}: Every element in $X$ has $\\leq 1$ out arrows. (Every $X$ has {\\bf one or less $Y$})\n  \\end{itemize}\\smallskip\n\n  An important definition:\n  \\begin{itemize}\n  \\item {\\bf Bijection}: Every element of $X$ has {\\bf exactly one} element of $Y$, {\\bf and vice versa}.\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Types of Binary Relations: Examples}\n\n    \\begin{block}{Example 1: $g: \\mathbb{R}\\times\\mathbb{R} \\rightarrow \\mathbb{R}, g(x,y) = 1/(x-y)$}\n      \\begin{itemize}\n      \\item This is a {\\bf function}, because each pair $(x,y)$ has at most one output.\n      \\item This is not {\\bf total}, because not every pair $(x,y)$ has an output: $(x = y)$ has no output.\n      \\end{itemize}\n    \\end{block}\n\n    \\begin{block}{Example 2: $g_o: \\mathbb{R}\\times\\mathbb{R} - \\{x,y|x=y\\} \\rightarrow \\mathbb{R}, g_o(x,y) = 1/(x-y)$}\n      \\begin{itemize}\n      \\item $g$ and $g_o$ are similar relations, but defined on different domains.\n      \\item The domain of $g_o$ removes all $(x,y)$ where $x = y$\n      \\item Because of this, $g_0$ is {\\bf function} (every pair has at most one output) and {\\bf total} (every pair has at least one output).\n      \\end{itemize}\n\n    \\end{block}\n\n\\end{frame}\n\n% \\begin{frame}\n%   \\frametitle{Size of Finite Sets}\n%\n%   {\\larger\n%     We can use the characteristics of relations to estimate the\n%     size of sets (domains and co-domains).\n%\n%     \\vfill\n%\n%     \\begin{itemize}\n%     \\item A bijection B $\\rightarrow |A| = |B|$\n%     \\item A function surjection B $\\rightarrow |A| \\geq |B|$\n%     \\item A total injection B $\\rightarrow |A| \\leq |B|$\n%     \\end{itemize}\n%   }\n% \\end{frame}\n%\n% \\begin{frame}\n%   \\frametitle{Set Size Example: Finite power sets and binary strings}\n%\n%   {\\larger\n%     What is the size of the Power Set of a \\structure{finite} set?\n%\n%     \\vfill\n%\n%     \\begin{itemize}\n%     \\item Make a bijection between the power set and the binary string\n%     \\item Calculate the size of a binary string\n%     \\item Establish equality\n%     \\end{itemize}\n%\n%   }\n% \\end{frame}\n", "meta": {"hexsha": "345b7981b3ad13d9548d847aac99bf34c19bae01", "size": 12790, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week02/01_Sets.tex", "max_stars_repo_name": "caranha/MathCS", "max_stars_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-09-13T18:59:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T02:14:56.000Z", "max_issues_repo_path": "week02/01_Sets.tex", "max_issues_repo_name": "caranha/MathCS", "max_issues_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week02/01_Sets.tex", "max_forks_repo_name": "caranha/MathCS", "max_forks_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.271393643, "max_line_length": 219, "alphanum_fraction": 0.6354182955, "num_tokens": 4311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.867035763237924, "lm_q1q2_score": 0.7148379755965191}}
{"text": "\\subsection{Variation of Parameters for Systems}\r\n\\noindent\r\nLet $X$ be a fundamental matrix for the homogeneous system.\r\n\\begin{equation*}\r\n\t\\vec{x_h}' = A\\vec{x_h}\r\n\\end{equation*}\r\nThat is,\r\n\\begin{equation*}\r\n\t\\vec{x_h} = X\\vec{c}\r\n\\end{equation*}\r\nwhere\r\n\\begin{equation*}\r\n\t\\vec{c} = \\begin{bmatrix}\r\n\tC_1 \\\\\r\n\t\\vdots \\\\\r\n\tC_n\r\n\t\\end{bmatrix}\r\n\\end{equation*}\r\nand the entries of matrix $A$ can be any continuous functions of $t$.\r\n\r\n\\noindent\r\nWe are looking for the particular solution $\\vec{x_p}$, to the system\r\n\\begin{equation*}\r\n\t\\vec{x} = A\\vec{x} + \\vec{f}\r\n\\end{equation*}\r\nwhere $\\vec{x_p}$ is of the form\r\n\\begin{equation*}\r\n\t\\vec{x_p} = X\\vec{v}\r\n\\end{equation*}\r\nwhere $\\vec{v}$ is a vector of functions of $t$ that we'll have to find.\r\n\r\n\\noindent\r\nDifferentiating $\\vec{x_p}$,\r\n\\begin{equation*}\r\n\t\\vec{x_p}' = X\\vec{v}' + X'\\vec{v}\r\n\\end{equation*}\r\nFrom the system we're trying to solve we know that\r\n\\begin{equation*}\r\n\tX\\vec{v}' + X'\\vec{v} = A(X\\vec{v}) + \\vec{f}\r\n\\end{equation*}\r\nSince $X' = AX$,\r\n\\begin{equation*}\r\n\tX\\vec{v}' = \\vec{f}\r\n\\end{equation*}\r\n\r\n\\noindent\r\nSince the columns of $X$ are always linearly independent, we know that $X^{-1}$ always exists.\\\\\r\nMultiplying by $X^{-1}$,\r\n\\begin{equation*}\r\n\t\\vec{v}' = X^{-1}\\vec{f}\r\n\\end{equation*}\r\nIntegrating with respect to $t$,\r\n\\begin{equation*}\r\n\t\\vec{v} = \\int{X^{-1}\\vec{f} \\mathrm{d}t}\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\vec{x_p} = X\\int{X^{-1}\\vec{f} \\mathrm{d}t}\r\n\\end{equation*}\r\nand\r\n\\begin{equation*}\r\n\t\\vec{x} = X\\vec{c} + X\\int{X^{-1}\\vec{f} \\mathrm{d}t}\r\n\\end{equation*}\r\n\r\n\\ifodd\\includeLinearSystemsExamples\\input{./linearSystems/heterogeneousSystems/variationOfParameters_example.tex}\\fi", "meta": {"hexsha": "bad80aefd223031e20a3fa1a53e53d5dc2dd7c78", "size": 1701, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/heterogeneousSystems/variationOfParameters.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/linearSystems/heterogeneousSystems/variationOfParameters.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/linearSystems/heterogeneousSystems/variationOfParameters.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.1692307692, "max_line_length": 116, "alphanum_fraction": 0.644914756, "num_tokens": 630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7147992614716471}}
{"text": "\\section{Pitch rate command system}\n\nReducing the state space model in Equation~\\ref{eq:sslon} by eliminating the velocity and pitch angle states result in the following model.\n\n\\begin{equation}\n    \\begin{aligned}\n        A_{red}&=\\begin{bmatrix}\n            -0.05167 &   0.9792 \\\\\n            -0.6256  & -0.2485\n        \\end{bmatrix} &\n        B_{red}&=\\begin{bmatrix}\n            -0.0002308 \\\\\n            -0.01541\n        \\end{bmatrix} \\\\\\\\\n        C_{red}&=I_2 &\n        D_{red}&=0_{2,1}\n    \\end{aligned}\n\\end{equation}\n\nSimulating the step response for both models yields similar results. It is clear in the response of the full model that the short period is the dominant eigenmotion during the first few seconds. Since only the initial response of the system in relevant for the CAP and Gibson dropback criterion, it is fine to continue using the reduced model for the rest of the assignment.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{figures/pc_acre_step.pdf}    \n    \\caption{Pitch rate elevator step response for both the full and reduced model.}\n    \\label{fig:pc_acre_step}\n\\end{figure}\n\nA feedback loop is needed in order to satisfy the short period natural frequency and damping requirements. Figure~\\ref{fig:pc_loop1} shows the control loop for solving this problem. The system $G$ is the open loop state space system and $K$ is the to be determined gain matrix.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.4\\textwidth]{figures/pc_loop1.pdf}    \n    \\caption{Feedback loop with gain in the loop.}\n    \\label{fig:pc_loop1}\n\\end{figure}\n\nThe build-in matlab function \\texttt{place(...)} is used to calculate the gain $K_{reduced}$ using pole placement. The resulting gain is shown in Equation~\\ref{eq:gaink}.\n\n\\begin{equation}\n    \\label{eq:gaink}\n    K_{reduced}=\\begin{bmatrix}\n                    K_{\\alpha} & K_q\n                \\end{bmatrix}\n               =\\begin{bmatrix}\n                    -449.0440 & -151.8325\n                \\end{bmatrix}\n\\end{equation}\n\nThe new closed loop system matrix $A$ can then be calculated using Equation~\\ref{eq:aclosed} and the rest of the matrices are the same as that of the open loop system. The new closed loop system can be found in Equation~\\ref{eq:closedloopsystem}.\n\n\\begin{equation}\n    \\label{eq:aclosed}\n    A_{closed} = A_{open}-B_{open}K\n\\end{equation}\n\n\n\\begin{equation}\n    \\label{eq:closedloopsystem}\n    \\begin{aligned}\n        A_{closed}&=\\begin{bmatrix}\n            -0.1553 &  0.9442 \\\\\n            -7.544  & -2.588 \\\\\n        \\end{bmatrix} &\n        B_{closed}&=\\begin{bmatrix}\n            -0.0002308 \\\\\n            -0.01541\n        \\end{bmatrix} \\\\\\\\\n        C_{closed}&=I_2 &\n        D_{closed}&=0_{2,1}\n    \\end{aligned}\n\\end{equation}\n\n                                                                       \n                                                                 \n\nCalculating the damping and natural frequency of the closed loop system shows that the parameters match the required $\\zeta=0.5$ and $\\omega_n=0.03V\\approx 2.74$\n\\begin{table}[h!]\n    \\centering\n    \\begin{tabular}{ c c c c c }\n         Poles         & $\\zeta$        & $\\omega_n$ \\\\ \\hline \\hline\n         $1.37 + 1.37i$ & $\\e{5.00}{-1}$ & $2.74$     \\\\  \n         $1.37 - 1.37i$ & $\\e{5.00}{-1}$ & $2.74$     \\\\ \\hline\n    \\end{tabular}\n    \\caption{Longitudinal eigenmotions poles, damping rations, natural frequencies, periods and time to half amplitude.}\n\\end{table}\n\nIf small angle approximations are assumed it is possible to calculate the angle of attack using the following equation.\n\n\\begin{equation}\n    \\alpha = \\frac{w}{V}\n\\end{equation}\n\nHere is $w$ the vertical airspeed component and V the total airspeed. Thus the angle of attack change in case of a vertical gust may be calculated by dividing the gust speed by the free stream velocity. This angle of attack may be passed as an initial condition to a simulation in order to observe the aircraft's behavior during such a gust. For a severe gust with $w=4.572\\ [m\\ s^{-1}]$ the initial angle of attack in the assigned flight condition is,\n\n\\begin{equation}\n    \\alpha_0=\\frac{4.572\\ [m\\ s^{-1}]}{300\\ [ft\\ s^{-1}]}=\\frac{4.572\\ [m\\ s^{-1}]}{91.44\\ [m\\ s^{-1}]} = 0.05\\ [rad]\n\\end{equation}\n\nThe simulation results for both the open and closed loop systems using this initial condition and zero inputs is shown in Figure~\\ref{fig:pc_vertgust}. As it can be seen the closed loop system quickly dampens the disturbance due the vertical gust, in contrast to the open loop system which continues oscillating significantly longer.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{figures/pc_vertgust.pdf}    \n    \\caption{Angle of attack during a $w=4.572\\ [m\\ s^{-1}]$ vertical gust for the open and closed loop systems.}\n    \\label{fig:pc_vertgust}\n\\end{figure}\n\nThe $T_{\\theta_2}$ time constant cannot be modified by pole placement or by some other control loop structure. The reason is because it is located in the numerator of the transfer function and it's not possible to change the numerator using a feedback loop gain. \n\nPlacing the lead-lag filter inside of the loop on the forward path will make it end up in both the numerator and denominator of the closed loop transfer function. Thus making it impossible to replace the zero without without changing the damping ratio and natural frequency of the closed loop system.\n\nTo modify $T_{\\theta_2}$ a lead-lag prefilter can be placed before the closed loop system. The pole in the prefilter is used to cancel the current zero with $T_{\\theta_2}$ in the closed loop, and the prefilter's zero end up in the overall transfer function, thus replacing the original zero.\n\n\\begin{equation}\n    \\frac{q(s)}{\\delta_{el}(s)}=\\frac{1+T_{\\theta_2,new}}{1+T_{\\theta_2,old}} \\cdot\n        \\frac{k_q \\left(1+T_{\\theta_2,old}\\right)}{\n        s^2+2\\zeta\\omega_ns+\\omega_n^2}\n        =\n        \\frac{k_q \\left(1+T_{\\theta_2,new}\\right)}{\n        s^2+2\\zeta\\omega_ns+\\omega_n^2}\n\\end{equation}\n\nEven with the prefilter the controller will still not track the reference pitch rate signal properly, there will be a steady state error that needs to be compensated for. The reason is because the signal coming from the feedback loop is scaled by the gain $K$ and thus the reference signal needs to be scaled as well.\n\nFor this assignment the \\texttt{rscale(...)} function which can be found at \\cite{matlabrscale} is used. The final form of the precompensator is thus,\n\n\\begin{equation}\n    N \\cdot \\frac{1+T_{\\theta_2,new}}{1+T_{\\theta_2,old}}\n\\end{equation}\n\nWhere $N$ is the scaling factor from \\texttt{rscale(...)}.\n\n\n% Category B: Those nonterminal Flight Phases that are normally accomplished using\n% gradual maneuvers and without precision tracking, although accurate\n% flight-path control may be required. Included in this Category are:\n\nFigure~\\ref{fig:pc_cap} shows the level 1 Control Anticipation Parameter criteria for Category B flight phases. According to \\cite{milstd1797a}, Category B flights phases are normally accomplished using gradual maneuvers and without precision tracking, which includes cruise flight. As it can be seen, the controller satisfies the requirement.\n\n\\begin{equation}\n    CAP=\\frac{g\\omega^2T_{\\theta_2}}{V} \\approx 0.1168\n\\end{equation}\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.4\\textwidth]{figures/pc_cap.pdf}    \n    \\caption{Control Anticipation Parameter criteria for Category B flight phases and the location for the controlled system in the plot.}\n    \\label{fig:pc_cap}\n\\end{figure}\n\nFigure~\\ref{fig:pc_cap} shows the pitch rate and pitch angle step response of the controlled system. The maximum pitch rate $q_m$ and steady state value $q_s$ are marked in the plot. \n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.8\\textwidth]{figures/pc_pitch_resp.pdf}    \n    \\caption{Pitch rate and pitch angle step response of the controlled system.}\n    \\label{fig:pc_pitch_resp}\n\\end{figure}\n\n\n\nFigure~\\ref{fig:pc_cap} shows the satisfactory range of values to meet the Gibson dropback criterion. As it can be seen the controlled system satisfies the criteria.\n\\begin{align}\n    \\label{eq:gibvals}\n    \\frac{DB}{q_s} &= T_{\\theta_2} - \\frac{2\\zeta_{sp}}{\\omega_{n_{sp}}} \\approx 0.1099 \\\\\n    \\frac{q_m}{q_s} &= \\frac{1.4126}{1} = 1.4126\n\\end{align}\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.4\\textwidth]{figures/pc_gib.pdf}    \n    \\caption{Pitch rate and pitch angle step response of the controlled system.}\n    \\label{fig:pc_gib}\n\\end{figure}\n\n\n\n\\clearpage\n", "meta": {"hexsha": "b1f322f90087e98237d27e4f287a166fe082061a", "size": 8594, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/3_pitch_rate_command_system.tex", "max_stars_repo_name": "aarondewindt/afcs_assignment", "max_stars_repo_head_hexsha": "ef8e368c9c81c3dcba4193bd2193a68d5e2bd2f6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/3_pitch_rate_command_system.tex", "max_issues_repo_name": "aarondewindt/afcs_assignment", "max_issues_repo_head_hexsha": "ef8e368c9c81c3dcba4193bd2193a68d5e2bd2f6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/3_pitch_rate_command_system.tex", "max_forks_repo_name": "aarondewindt/afcs_assignment", "max_forks_repo_head_hexsha": "ef8e368c9c81c3dcba4193bd2193a68d5e2bd2f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-04T15:55:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-04T15:55:23.000Z", "avg_line_length": 48.0111731844, "max_line_length": 452, "alphanum_fraction": 0.6911798929, "num_tokens": 2384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182187, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7147992458013337}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{examples}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% ============================================================================================\n\\bgroup\n\\CdbSetup{action=hide}\n\\begin{cadabra}\n   import cdblib\n   checkpoint_file = 'tests/semantic/output/example-14.json'\n   cdblib.create (checkpoint_file)\n   checkpoint = []\n\\end{cadabra}\n\\egroup\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 14 The Weyl tensor is conformally invariant}\n\nThis example shows that the Weyl tensor is conformally invariant. That is, for a pair of\nmetrics $g$ and $\\overline{g}$ related by a conformal transformation,\n$\\overline{g}_{a b} = \\phi g_{a b}$ then $\\overline{C}^{a}_{b c d} = C^{a}_{b c d}$\nor equally $\\overline{C}_{a b c d} = \\phi C_{a b c d}$.\n\n\\begin{cadabra}\n   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,u,v,w#}::Indices (position=independent).\n\n   \\partial{#}::PartialDerivative.\n\n   g_{a b}::Metric.\n   g^{a b}::InverseMetric.\n   g_{a}^{b}::KroneckerDelta.\n\n   GammaU := \\Gamma^{a}_{b c} ->  1/2 g^{a d} (   \\partial_{b}{g_{d c}}\n                                                + \\partial_{c}{g_{b d}}\n                                                - \\partial_{d}{g_{b c}}).\n\n   GammaD := \\Gamma_{a b c} ->  1/2 (   \\partial_{b}{g_{a c}}\n                                      + \\partial_{c}{g_{b a}}\n                                      - \\partial_{a}{g_{b c}}).\n\n   Rabcd := R_{a b c d} ->   \\partial_{c}{\\Gamma_{a b d}}\n                           - \\partial_{d}{\\Gamma_{a b c}}\n                           + \\Gamma_{e a d} \\Gamma^{e}_{b c}\n                           - \\Gamma_{e a c} \\Gamma^{e}_{b d}.\n\n   Rab     := R_{a b} -> g^{c d} R_{a c b d}.\n\n   Rscalar := R -> g^{a b} R_{a b}.\n\n   # Weyl in 4-dimensions\n\n   Cabcd := R_{a b c d} - (1/2) (R_{a c} g_{b d} - R_{a d} g_{b c})\n                        - (1/2) (g_{a c} R_{b d} - g_{a d} R_{b c})\n                        + (R/6) (g_{a c} g_{b d} - g_{a d} g_{b c}).\n\n   {\\partial_{a b}{\\phi},\\partial_{a}{\\phi},\\phi}::SortOrder.\n   {\\partial_{a b}{g_{c d}},\\partial_{a}{g_{b c}},g_{a b},g^{a b}}::SortOrder.\n\n   substitute (Cabcd,Rscalar)\n   substitute (Cabcd,Rab)\n   substitute (Cabcd,Rabcd)\n   substitute (Cabcd,GammaU)\n   substitute (Cabcd,GammaD)\n\n   distribute     (Cabcd)\n\n   sort_product   (Cabcd)\n   rename_dummies (Cabcd)\n   canonicalise   (Cabcd)\n\n   # this is the Weyl tensor on the base metric\n   baseC := @(Cabcd).\n\n   conformal := {g_{a b} -> \\phi g_{a b}, g^{a b} -> (1/phi) g^{a b}}.\n\n   substitute     (Cabcd, conformal)\n   product_rule   (Cabcd)\n   distribute     (Cabcd)\n   product_rule   (Cabcd)\n   distribute     (Cabcd)\n\n   map_sympy      (Cabcd, \"simplify\")\n\n   sort_product   (Cabcd)\n   rename_dummies (Cabcd)\n   canonicalise   (Cabcd)\n\n   # this is the Weyl tensor on the conformal metric\n   confC := @(Cabcd).\n\n   # their difference, should be zero\n   diff := @(confC) - \\phi @(baseC).  # cdb (ex-14.diff.100,diff)\n\n   distribute     (diff)\n   sort_product   (diff)\n   rename_dummies (diff)\n   canonicalise   (diff)  # cdb (ex-14.diff.101,diff)\n\n   # this trick is not essential but it does reduce the number of terms in diff\n   substitute     (diff,$\\partial_{a}{\\partial_{b}{g_{c d}}} -> g_{c d b a}$)\n   substitute     (diff,$\\partial_{a}{g_{b c}} -> 0$)\n   substitute     (diff,$g_{c d b a} -> \\partial_{a}{\\partial_{b}{g_{c d}}}$)  # cdb (ex-14.diff.102,diff)\n\n   # standard expressions in 4-d\n   substitute     (diff,$g_{a b} g^{a b} -> 4$,repeat=True)          # cdb (ex-14.diff.201,diff)\n   substitute     (diff,$g_{a b} g^{c b} -> g_{a}^{c}$,repeat=True)  # cdb (ex-14.diff.202,diff)\n   substitute     (diff,$g_{b a} g^{b c} -> g_{a}^{c}$,repeat=True)  # cdb (ex-14.diff.203,diff)\n   substitute     (diff,$g_{a}^{a} -> 4$,repeat=True)                # cdb (ex-14.diff.204,diff)\n   substitute     (diff,$g^{a}_{a} -> 4$,repeat=True)                # cdb (ex-14.diff.205,diff)\n   eliminate_kronecker (diff)                                        # cdb (ex-14.diff.206,diff)\n\n   # need a second round since the above block introduces new terms that match those just eliminated\n   substitute     (diff,$g_{a b} g^{a b} -> 4$,repeat=True)          # cdb (ex-14.diff.301,diff)\n   substitute     (diff,$g_{a b} g^{c b} -> g_{a}^{c}$,repeat=True)  # cdb (ex-14.diff.302,diff)\n   substitute     (diff,$g_{b a} g^{b c} -> g_{a}^{c}$,repeat=True)  # cdb (ex-14.diff.303,diff)\n   substitute     (diff,$g_{a}^{a} -> 4$,repeat=True)                # cdb (ex-14.diff.304,diff)\n   substitute     (diff,$g^{a}_{a} -> 4$,repeat=True)                # cdb (ex-14.diff.305,diff)\n   eliminate_kronecker (diff)                                        # cdb (ex-14.diff.306,diff)\n\n   sort_product   (diff)\n   rename_dummies (diff)\n   canonicalise   (diff)  # cdb (ex-14.diff.400,diff)\n\n   checkpoint.append (baseC)\n   checkpoint.append (confC)\n\\end{cadabra}\n\n\\clearpage\n\n\\begin{dgroup*}\n   \\Dmath*{ \\Delta = \\Cdb*{ex-14.diff.102}}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{ \\Delta = \\Cdb*{ex-14.diff.201}}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{ \\Delta = \\Cdb*{ex-14.diff.202}}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{ \\Delta = \\Cdb*{ex-14.diff.203}}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{ \\Delta = \\Cdb*{ex-14.diff.204}}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{ \\Delta = \\Cdb*{ex-14.diff.205}}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{ \\Delta = \\Cdb*{ex-14.diff.206}}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{ \\Delta = \\Cdb*{ex-14.diff.301}}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{ \\Delta = \\Cdb*{ex-14.diff.302}}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{ \\Delta = \\Cdb*{ex-14.diff.303}}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{ \\Delta = \\Cdb*{ex-14.diff.304}}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{ \\Delta = \\Cdb*{ex-14.diff.305}}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{ \\Delta = \\Cdb*[\\hskip2.0cm\\hfill]{ex-14.diff.306}}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{ \\Delta = \\Cdb*{ex-14.diff.400}}\n\\end{dgroup*}\n\n\\clearpage\n\n% ============================================================================================\n% export to json format\n\n\\bgroup\n\\CdbSetup{action=hide}\n\\begin{cadabra}\n   for i in range( len(checkpoint) ):\n      cdblib.put ('check{:03d}'.format(i),checkpoint[i],checkpoint_file)\n\\end{cadabra}\n\\egroup\n\n\\end{document}\n", "meta": {"hexsha": "1686a1f62aa87e277c93e9f32fb6f196000f0e05", "size": 6373, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/example-14.tex", "max_stars_repo_name": "leo-brewin/cadabra-tutorial", "max_stars_repo_head_hexsha": "5b428ae158b5346315ab6c975dee9de933e5c3d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2019-12-20T07:49:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T22:55:47.000Z", "max_issues_repo_path": "source/cadabra/example-14.tex", "max_issues_repo_name": "leo-brewin/cadabra-tutorial", "max_issues_repo_head_hexsha": "5b428ae158b5346315ab6c975dee9de933e5c3d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/cadabra/example-14.tex", "max_forks_repo_name": "leo-brewin/cadabra-tutorial", "max_forks_repo_head_hexsha": "5b428ae158b5346315ab6c975dee9de933e5c3d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-22T13:52:19.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-22T13:52:19.000Z", "avg_line_length": 31.087804878, "max_line_length": 106, "alphanum_fraction": 0.5356974737, "num_tokens": 2215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7146296731476056}}
{"text": "\\newpage\n\\section{First-Order Differential Equations}\n\nIn this chapter, methods will be given for solving first- order differential equations. First-order means that the first derivative of the unknown function is the highest derivative appearing in the equation. This implied that the most general first-order differential equation has the form $F(t,x,t')=0$ for some function $F$, in this chapter, we will assume that the equation can be solved explicitly for $x'$. This means that our first-order differential equations can always be put in the form:\n\n\\[\n  x'=f(t,x)\n\\]\n\nwhere $f$ denotes an arbitrary function of two variables. To see why such an assumption makes sense, supposed the differential equation is:\n\n\\[\n  (x'(x))^2+4x'(t)+3x(t)=t.\n\\]\n\nIt would be messy, but not impossible to use the quadratic formula to extract two differential equations of the form $x'=f(t,x)$ from this quadratic equation. However, one could also imagine equations where solving for $x'(t)$ is not even possible, and in such a case, some of our methods might not be applicable.\n\nThe material in this chapter will cover several analytic methods for solving first-order differential equations, each requiring the function $f$ to have a special form. Two different graphical methods are also described; one for the general equation depending only on $x$. Numerical methods for first-order equations are introduced and theoretical issues of existence and uniqueness of solutions are discussed.\n\n\\subsection{Separable First-Order Equations}\n\n  The first analytic method we will consider applies to first-order equations that can be written in the form\n\n  \\[\n    \\frac{dx}{dt} = g(t)h(t);\n  \\]\n\n  that is, when the function $f(t, x)$ can be factored into a product of a function of $t$ times a function of $x$. Such a differential equation is called separable. \n\n  \\begin{problem}\n    Determine which of the following first-order differential equations are separable. Hint: try to factor the right- hand side if the equation does not initially appear to be separable.\n\n    \\[\n      x' = xt + 2x\\to x' = x(t + 2)\\to g(t) = t + 2,h(x) = x\\\\\n    \\]\n\n    \\[\n      x' = x + \\cos (t)\\\\\n    \\]\n    \n    \\[\n      x' = xt^2 + t^2 - tx\\to x' =(t^2 - t)(x + 1)\\to g(t) =(t^2 - t),h(x) =(x + 1)\\\\\n    \\]\n\n    \\[\n      x' = x^2 + x + 3\\to x' = (1)(x^2 + x + 3)\\to g(t) = 1,h(x) = x^2 + x + 3\n    \\]\n\n    \\begin{enumerate}\n      \\item \n        If $h(x) = 1,$ the separable equation $x'=g(t)$ is just an integrating problem and the solution is \n        \\[\n          x=\\int g(t)dt;\n        \\]\n        that is, $x$ is just the **indefinite integral** of the function $g(t)$. Remember that this means that $x$ can be *any* function $G(t)$ such that $G'(t)=g(t)$, and this introduces an arbitrary constant into the solution. As an example, the solution of $x'=t+1$ is \n\n        \\[\n          x(t)=\\int(t+1)dt=\\frac{t^2}{2}+t+ c\n        \\]\n\n        Even in this simple case the solution is an infinite one-parameter family of functions.\n      \n      \\item If $g(t)=1$, the separable equation $x'=h(x)$ is called an **autonomous** first-order differential equation. Unless $h(x)$ is a constant, it is no longer possible to solve the equation by simple integration, and the method given below must be used. Autonomous first-order differential equations are important and will be investigated more thoroughly in section 2.7. In the above examples, only the last equation is autonomous. The other three contain functions of $t$ (other than the unknown function $x(t)$) on the right-and side.\n    \\end{enumerate}\n  \\end{problem}\n\n  \\begin{problem}\n    Solve the differential Equation $\\frac{dx}{dt}=-tx^2$.\n\n    Solution. Split $dx/dt$ into two pieces, $dx$ and $dt$, and do a bit of algebra to write:\n\n    \\[\n      - \\frac{dx}{x^2} = tdt\n    \\]\n\n    Integrate each side with respect to its own variable to obtain:\n\n    \\[\n      \\int \\left( - \\frac{1}{x^2}\\right) =\\int tdt\\to \\frac{1}{x} = \\frac{t^2}{x} + C.\n    \\]\n\n    where the arbitrary constants on each side have been collected on the right. Solve this equation for x to obtain the one parameter family of solutions\n\n    \\[\n      x=\\frac{1}{(t^2/2)+C}.\n    \\]\n\n    We should check that the function $x(t)$ does satisfy the differential equation for any value of the constant C. It appears that this method works, but splitting $dx/dt$ into two pieces is not a mathematically condoned operation; therefore, a justification of the method needs to be given.\n\n    If an equation is separable, and $x'(t)$ is written as $dx/dt$, both sides of the equation $dx/dt=g(t)h(x)$ can be divided by $h(x)$, and the equation becomes\n\n    \\[\n      \\frac{1}{h(x(t))}\\left(\\frac{dx}{dt}\\right)dt=\\int g(t)dt+C.\n    \\]\n\n    The method of simple substitution can be applied to the integral on the left. If we substitute $u=x(t)$, then $du=(dx/dt)dt$, and the equation becomes\n\n    \\[\n      \\int\\frac{1}{h(u)}du=\\int g(t)dt+C.\n    \\]\n\n    Now let $H(u)$ be any function such that $H'(u)=1/h(u)$ and $G(t)$ any function with $G'9t)=g(t)$. Then the equation above implies that\n\n    \\[\n      H(u)+C_1=G(t)+C_2\\to H(u)=G(t)+C,\n    \\]\n\n    Where C is the constant $C_2-C_1$\n\n    Replacing $u$ again by $x(t)$:\n\n    \\[\n      H(x(t))=G(t)+ C\n    \\]\n  \\end{problem}\n\n  Check carefully that the expression $H(x)=G(t)+C$ is exactly the same as the solution obtained above. It is an **implicit solution** of $-dx/x^2=tdt$; that is, it defines a relationship between the unknown function $x$ and its independent variable $t$. If it can be solved explicitly for $x$ as a function of $t$, the result is called an **explicit solution of the differential equation. As expected, the integration produces an infinite on-parameter family of solutions\n\n  \\begin{theorem}\n    To solve a separable first-order differential equation, $x'(t)=g(t)h(x)$:\n    \\begin{itemize}\n      \\item Write the equation in the form $dx/dt=g(t)h(x)$.\n      \\item Multiply both sides by $dt$, divide by $h(x)$, and integrate, to put the equation in the form \n        \\[\n          \\int \\frac{1}{h(x)}dx =\\int g(t)dt.\n        \\]\n      \\item Find any function $H(x)$ such that $H'(x)=1/h(x)$ and any function $G(t)$ such that %G'(t)=g(t).\n      \\item Write the solution as $H(x)=G(t)+C$\n      \\item If possible, solve the equation from the previous step explicitly for x, as a function of t.\n    \\end{itemize}\n  \\end{theorem}\n\n\\subsection{Solving Linear ODEs}\n\n \\begin{definition}\n   An ODE is linear for the dependent variable $y$ if it is homogeneous when $g(x)=0$ and otherwise it is non-homogeneous.\n   \\[\n     a_1(x)\\frac{dy}{dx}+a_0(x)y=g(x)\n   .\\] \n   The standard form of a linear ODE is\n   \\[\n     \\frac{dy}{dx}+P(x)y=f(x)\n   .\\] \n \\end{definition}\n \n If the homogeneous ODE is separable: $y=e^{-\\int P(x)dx}$, and $y_c=cy_1(x)$ where $y_1=e^{-\\int P(x)dx}$. For a non-homogeneous ODE, we need to use the process of “variation of parameters”. First we need to find the function $u$ so that $y_p=u(x)y_1(x)=u(x)e^{-\\int P(x)dx}$, and then we follow the following steps\n\n \\begin{enumerate}\n   \\item Put in standard form\n   \\item Determine $P(x)$ and integrating factor $e^{\\int P(x)dx}$.\n   \\item Multiply std form by integrating factor.\n   \\item Write \\[\n       \\frac{d}{dx}\\left[e^{\\int P(x)dx}y\\right]=e^{\\int P(x)dx}f(x)\n   .\\] \n  \\item Integrate both sides.\n \\end{enumerate}\n\n\\subsection{}\n\n\\subsection{Existence and Uniqueness of Initial Value Problems}\n\n  Given an initial value problem, how can I know that a solution exists, and if so, the uniqueness of that solution.\n\n  \\begin{problem}\n    $\\frac{dx}{dt}=\\sqrt{x}$, $x(0)=0$ has two solutions. These solutions are $x(t)=\\frac{t^2}{4}$ and $0$. We can change the initial condition to be $x(0)=5$. We can separate our values to get:\n\n    \\[\n      x(t) =\\left(\\frac{t}{2} + \\sqrt{5}\\right)^2\n    \\]\n    \n    If we change the initial condition to $x(5)=-5$ we get no solutions. We can also change the initial condition to $x(5)=0$ which gives us two solutions:\n\n    \\begin{align*}\n      x(t) =\\left(\\frac{t - 5}{2}\\right)^2\\\\\n      x(t) = 0\n    \\end{align*}\n  \\end{problem}\n\n\\subsection{Exact Ordinary Differential Equations}\n\n  This highlights an analytic technique to find the solutions to an ordinary differential equation. This technique depends on if we are able to write an ODE in the form $\\frac{d}{dx}(F(x,y(x)))=0$. How can we tell if this is possible? \n\n    We can determine this by using the multi-variable chain rule from calculus 3:\n\n    \\[\n      \\frac{d}{dx}(F(x,y(x))) = \\frac{\\partial F}{\\partial x} + \\frac{\\partial F}{\\partial y} \\frac{dy}{dx} = 0 \n    \\]\n\n    Now in order to actually solve the ordinary differential equation, we will turn the equation above into something that we can work with:\n\n    \\[\n      M(x,y) + N(x,y)\\frac{dy}{dx} = 0\n    \\]\n\n    Now we ask, does $f(x,y)$ exist such that $\\frac{\\partial F}{\\partial x} =  M(x,y)$ and $\\frac{\\partial F}{\\partial y} = N(x,y)$? We can test this by checking to see if we can do the following:\n\n    \\[\n      \\frac{\\partial^2F}{\\partial x\\partial y}=\\frac{\\partial^2 F}{\\partial y\\partial x}\\rightarrow\\boxed{\\frac{\\partial M}{\\partial y}=\\frac{\\partial N}{\\partial x}}\n    \\]\n\n    If it passed the test, we use the equations to find $F(x,y)$, and then we can use $F(x,y(x))=C$ to find the solution to the problem.\n\n    \\begin{problem}\n      Calculus 3 example. Consider a field $\\vec{v}=<2y+4x,2x-5y>$. Is this a gradient field? If so, what is its potential function. In order to find this, there must be a function $f(x,y)$ such that $\\bigtriangledown f=\\vec{v}$.\n    \n    \n      \\[\n        {\\partial f}{\\partial y}\\big>=<6xy,2x-5y>\\\\\n      \\]\n  \n      \\begin{align*}\n        \\frac{\\partial f}{\\partial x}=6xy,&& \\frac{\\partial f}{\\partial y}=2x-5y\n      \\end{align*}\n  \n      Therefore, we know that $f_{xy}=f_{yx}$ Now we just need to set the two equations equal to each other and solve:\n  \n      \\[\n        \\frac{\\partial}{\\partial y}(2y+4x)\\stackrel{?}{=}\\frac{\\partial}{\\partial x}(2x-5y)\n      \\]\n  \n      And we can solve that equation algebraically and get $2=2$, therefore this is the solution to the ordinary differential equation\n  \n    \\end{problem}\n\n    \\begin{problem}\n      Solve $(4x+2y)+(2x-5y)\\frac{dy}{dx}=0$. We should set $M(x,y)=4x+2y$ and set $N(x,y)=(2x-5y)$.\n\n    \\begin{enumerate}\n      \\item Testing to see if $\\frac{\\partial M}{\\partial y}=\\frac{\\partial N}{\\partial x}$\n        \\[\n          \\frac{\\partial}{\\partial y}(4x+2y)\\stackrel{?}{=}\\frac{\\partial}{\\partial x}(2x-5y)\n        \\]\n      \\item Now we need to find $F(x,y)$:\n        \\begin{align*}\n          \\frac{\\partial F}{\\partial x}=4x+2y && \\frac{\\partial F}{\\partial y}=2x-5y\\\\\n          F(x,y)=\\int(4x+2y)dx=2x^2+2xy+c_y, && F(x,y)=\\int(2x-5y)dy=2xy-\\frac{5}{2}y^2+c_x\n        \\end{align*}\n        We can determine that $c_y=\\frac{5}{2}y^2$ and $c_x=2x^2$ by looking at the two equations next to each other. Therefore, we know that $F(x,y)=2x^2+2xy-\\frac{5}{2}y^2$.\n    \\end{enumerate}\n    Our resulting solution is:\n\n    \\[\n      \\boxed{2xy-\\frac{5}{2}y^2+2x^2=C}\n    \\]\n\n    This was an implicitly defined solution, so $F(x,y)=2xy-\\frac{5}{2}y^2+2x$, and our ode is:\n    \n    \\begin{align*}\n      \\frac{d}{dx}\\left[2xy(y)-\\frac{5}{2}(y(x))^2+2x^2\\right]=\\frac{d}{dx}[C]\\\\\n      (2y+2xy')-\\frac{5}{2}2(y)+4x=0\\\\\n    \\end{align*}\n\n    \\paragraph{Example 2} Solve the differential equation,\n    \n    \\[\n      2x^2y+e^y+(x^3+xe^y-2y)\\frac{dy}{dx}=0. \n    \\]\n\n    We can see that $3x^2y+e^y = M(x,y)$ and $(x^3+xe^y-2y)\\frac{dy}{dx}=0$.\n\n    We can test this by checking to see if:\n    \n    \\[\n      \\frac{\\partial M}{\\partial y}\\stackrel{?}{=}\\frac{\\partial N}{\\partial x}\n    \\]\n\n    and by taking the partial derivatives of each of the equations, we can see that $3x^2+e^y=3x^2+e^y$. Now that we know that this is an exact ordinary differential equation, we need to solve for $F(x,y)$. In order to find $F(x,y)$, we must do \n\n    \\begin{align*}\n      \\frac{\\partial F}{\\partial x}=M && \\frac{\\partial F}{\\partial y}=N.\n      \\end{align*}\n\n      This means that \n\n      \\begin{align*}\n        F(x,y)=\\int(3x^2y+e^y)dx && F(x,y)=\\int(x^3+xe^y-2y)dy\\\\\n        =x^3y+xe^y+C_y && =x^3y+xe^y-y^2+C_x\\\\\n      \\end{align*}\n\n      So, $F(x,y)=x^3yxe^y-y^2$, and our solution is:\n\n      \\[\n        \\boxed{x^3y+xe^y-y^2=C}\\\\\n      \\]\n\n      Now we need to find a solution that satisfies the initial value problem, $y(-2)=1$.\n      \n      \\begin{align*}\n        (-2)^3(1)+(-2)e^1-(1)^2&=C\\\\\n        -8-2e-1&=C\\\\\n        -9-2e&=C\\\\\n      \\end{align*}\n\n      Which results in our particular solution being:\n\n      \\[\n        \\boxed{x^3y+xe^y-y^2=-9-2e}\n      \\]\n    \\end{problem}\n\n  \\subsubsection{Substitution}\n    Sometimes we can make a substitution that turns one ordinary differential equation into one that we can solve.\n    \n    \\begin{problem}\n      Let's take the equation $\\frac{dy}{dx}=\\frac{1-x-y}{x+y}$. In order to do this you need to trade out $y(x)$ for $u(x)$:\n\n      \\[\n        \\frac{dy}{dx}=\\frac{du}{dx}-1\n      \\]\n\n      \\[\n        \\frac{du}{dx}-1=\\frac{1-u}{u}=\\frac{1}{u}-1\n      \\]\n\n      After we do those steps, we can see that this is a separable ordinary differential equation, and we can use the normal method to solve a separable equation:\n\n      \\[\n        \\begin{aligned}\n          \\int udu&=\\int1dx\\\\\n          \\frac{u^2}{2}&=x+C\\\\\n          u^2&=2x+D\\leftarrow D=2C\\\\\n          (x+y)^2&=2x+D\\rightarrow x+y=\\pm\\sqrt{2x+D}\\\\\n          y&=-x\\pm\\sqrt{2x+D}\n        \\end{aligned}\n      \\]\n\n      Where the initial condition determines the last equation above. Now we need to solve for the initial condition of $y(6)=4$, and we can do this by just plugging in the values, and determining the sign on the square root:\n\n      \\[\n        \\begin{aligned}\n           4&-6\\pm\\sqrt{12+D}\\\\\n          10&=\\pm\\sqrt{12+D}\\\\\n          D&=88\\to y(x)=-x+\\sqrt{2x+88}\\\\\n        \\end{aligned}\n      \\]\n    \\end{problem}\n\n  \\subsubsection{Bernoulli Ordinary Differential Equations}\n\n    We use Bernoulli's solution to an ordinary differential equation if the equation can be written in the form $\\frac{dx}{dt}+p(t)x=q(t)x^n$, where if $n=0$, the equation is linear and where if $n=1$, the equation is both linear and separable. We can do a substitution for Bernoulli ordinary differential equations where we let $v=x^{1-n}$, and we trade out $x(t)\\to v(t)$ to turn the differential into a linear differential. Another formula we can use for plugging in to find the separable ordinary differential equation is $\\frac{du}{dx}+(1-n)p(x)u=(1-n)q(x)$, but we do not have an example to show for that method. \n\n    \\begin{problem}\n      Consider the Ordinary differential equation $t\\frac{dy}{dt}+y=\\frac{1}{y^2}$, and solve. Our first step for this problem is to divide both sides by $t$ to rearrange it into the Bernoulli form:\n\n      \\[\n        \\frac{dy}{dt}+\\frac{1}{t}y=\\frac{1}{t}y^-2\n      \\]\n\n      Because $y$ is our dependent variable, we will be looking for our $n$ value, and we will find it on the $y$ on the right-hand side. This gives us $n=-2$. Now we need to let $v(t)=y^{1-(-2)}=y^3$ and this means that $y(t)=(v(t))^{1/3}$. Now wee need to take the differential of this equation in order to find a substitution for $\\frac{dy}{dt}$:\n\n      \\begin{align*}\n        \\frac{dy}{dt}=\\frac{1}{3y^2}\\frac{dv}{dt}\\\\\n        \\frac{dv}{dt}=3y^{-2}\\frac{dy}{dt}\\\\\n      \\end{align*}\n\n      Once we have found a substitution for $\\frac{dy}{dt}$, we can simply plug in our equation and solve for $v(t)$:\n\n      \\[\n        \\frac{1}{3y^2}\\frac{dv}{dt}+y=\\frac{1}{y^2}\n      \\]\n\n      \\[\n        \\frac{t}{3}\\frac{dv}{dt}+y^3=1\n      \\]\n\n      We solve for $v(t)$, and then we can use the integrating factors method to solve the ordinary differential equation:\n\n      \\[\n        \\begin{aligned}\n          \\frac{dv}{dt}+\\frac{3}{t}v&=\\frac{3}{t}\\\\\n          \\mu(t)&=e^{\\int\\frac{3}{t}dt}=e^{3ln(t)}=t^3\\\\\n          t^3\\frac{dv}{dt}+3t^2v&=3t^2\\\\\n          \\frac{d}{dt}(t^3v)&=3t^2\\\\\n          \\int t^3v&=\\int3t^2dt=t^3+C\\\\\n          v(t)&=1+\\frac{C}{t^3}\\to y(t)=(v(t))^{\\frac{1}{3}}\\\\\n        \\end{aligned} \n      \\]\\\\\n\n      Now we just need to let $v(t)=y^3$ and plug this back into the equation to get $y(t)=\\left(1+\\frac{C}{t^3}\\right)^{\\frac{1}{3}}$ as our final solution.\n    \\end{problem}\n\n    Homogeneous ordinary differential equations can be written in the form $\\frac{dx}{dt}=f\\left(\\frac{x}{t}\\right)$. This means that if we just substitute $v$ for $\\frac{x}{t}$, we will turn the Homogeneous equation into a separable ordinary differential equation.\n\n    \\begin{problem}\n      Consider the homogeneous ODE, $(5y-2x)\\frac{dy}{dx}=4x+2y$. We can divide the $5y-2x$, so we will end up with the equation\n\n      \\[\n        \\frac{dy}{dx}=\\frac{4x+2y}{5y-2x}=\\frac{4+\\frac{2y}{x}}{5\\frac{y}{x}-2}\n      \\]\n\n      The reason we can make this change is that we are dividing everything on the left side by $x$ to get it in the form $\\frac{y}{x}$. Our next step is to trade out $y(x)$ for $v(x)$:\n\n      \\[\n        \\frac{4+2v}{5v+2}=v+x\\frac{dv}{dx}\\\\\n      \\]\n\n      Which we can further simplify into $\\frac{dv}{dx}=\\frac{1}{x}\\left(\\frac{4+2v}{5v-2}-v\\right)$. Now, we are able to solve this as a separable ordinary differential equation:\n\n      \\[\n        \\begin{aligned}\n          \\frac{dv}{dx}&=\\frac{1}{x}\\left(\\frac{4+4v-5v^2}{5v-2}\\right)\\\\\n          \\frac{5v-2}{4+4v-5v^2}dv&=\\frac{1}{x}dx\\\\\n        \\end{aligned}\n      \\]\n\n      Now we need to let $u-4+4v-5v^2$, and let $du=(4-10v)dv=-2(5v-2)dv$. And then we integrate with respect to $u$ to end up with \n\n      \\[\n        \\begin{aligned}\n          -\\frac{1}{2}\\int\\frac{1}{u}du&=\\int\\frac{1}{x}dx\\\\\n          -\\frac{1}{2}ln|u|&=ln|x|+C\\\\\n          ln|4+4v-5v^2|&=-2ln|x|+D\\\\\n          4+4v+5v^2&=e^{ln|x|^-2+D}\\\\\n          &=e^{ln|x|^{-2}}e^D\\\\\n          4+4\\left(\\frac{y}{x}\\right)-5\\left(\\frac{y}{x}^2\\right)&=e^{ln|x|^{-2}}A\n        \\end{aligned}\n      \\]\n\n      \\[\n        \\boxed{4x^2+4xy-5y^2=A}\n      \\]\n    \\end{problem}\n\n\\subsection{}\n\\subsection{Phase Lines and Equilibrium Solutions}\n\n  This is a qualitative technique for autonomous ordinary differential equations. This is used for finding the long term behavior of solutions for various initial conditions. An equilibrium solution is a constant function satisfying the ODE:\n\n  \\[\n    y(t)=k\\to\\frac{dy}{dt}=0\n  \\]\n\n  and we need to look for the roots of $f(y)$.\n\n  \\begin{problem}\n    Consider the ODE: $\\frac{dy}{dx}=4-y^2$, we know that the equilibrium solutions (stationary points / fixed points / critical points) are $0=4-y^2$ and $y=\\pm2$.  If we were to plot this as a slope field, we would see an image like the following:\n  \n    \\begin{center}\n      \\includegraphics{resource/images/2.7 Example 1.jpg}\n    \\end{center}\n\n    We need to classify each of the lines here as stable (a sink), unstable (a source), or semi-stable (a node). From this slope diagram we can make a phase diagram.\n\n      \n\n    The arrows in this diagram indicate whether $\\frac{dy}{dx}$ is above or below $0$. We can see that the long term behavior of the solution:\n\n    \\[\n      \\begin{aligned}\n        y_0 = y(t_0) > 2,\\to y(t)\\to 2\\\\\n        - 2 < 2_0,\\to y(t)\\to 2\\\\\n        y_0 <- 2, y(t)\\to -\\infty\\\\\n      \\end{aligned}\n    \\]\n  \\end{problem}\n\n  Let's take a look at another example problem:\n\n  \\begin{problem}\n    Compare the pivots of the two ordinary differential equations, $\\frac{dy}{dt}=y^2(1-y)^2$, and $\\frac{dy}{dx}=y^2(1-y^2)$.\n\n    \\begin{align*}\n      \\frac{dy}{dt}=y^2(1-y)^2 && \\frac{dy}{dt}=y^2(1-y^2)\\\\\n      0=y^2(1-y)^2 && 0=y^2(1-y^2)\\\\\n      && y=0,\\pm1\\\\\n    \\end{align*}\n    From finding the equilibrium points of the differential equations, we can now craft a pivot diagram:\\newline\n    \\begin{center}\n    \\includegraphics{resource/images/2.7 Example 2-1.jpg}\n    \\includegraphics{resource/images/2.7 Example 2-2.jpg}\n    \\end{center}\n\n    From this we can see that in the long term, the equations are going to look like this:\n\n    \\begin{align*}\n      y_0<0,y(t)\\to0\\\\\n      0<y_0<1,y(t)\\to1\\\\\n      1<y_0,y(t)\\to\\infty\\\\\n    \\end{align*}\n  \\end{problem}\n\n  \\subsubsection{Bifurcations}\n\n  For ordinary differential equations with a parameter, there are times that a small change in the value of the parameter results in a huge change in the behavior of the solutions. It causes a change in the number or stability of the equilibrium solutions.\n\n  \\begin{problem}\n    Find the bifurcation value for \n\n    \\[\n      \\frac{dp}{dt}=0.5p\\left(1-\\frac{p}{100}\\right)-H\n    \\]\n\n    The first step for finding a bifurcation for an equation is finding the equilibrium solutions. In order to do that, we set equation (2.69) equal to 0 and then rearrange it, so it is in the form\n\n    \\[\n      p^2-100p+250H=0\n    \\]\n\n    In this case, we are going to need to use the quadratic formula to find the equilibrium points:\n\n    \\begin{align*}\n      p=\\frac{100\\pm\\sqrt{10000-1000H}}{2}\\\\\n      =50\\pm5\\sqrt{100-10H}\n    \\end{align*}\n    We can determine that our bifurcation value is $H=10$, because if we take what's under the square root, and set it equal to zero we can find those values.\n    Now we can plot our bifurcations:\n    \\begin{center}\n      \\includegraphics{resource/images/2.7 Example 3 1.jpg}\n    \\end{center}\n  \\end{problem}\n  \\subsection{Numerical Methods}\\footnote{We got here from 4.1}\n", "meta": {"hexsha": "737c03b8fca27c2f88ae0a75bd83b2026b3eba29", "size": 21298, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math260/chapters/2.tex", "max_stars_repo_name": "CameronSWilliamson/GU-MATH", "max_stars_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-18T00:49:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T00:49:14.000Z", "max_issues_repo_path": "math260/chapters/2.tex", "max_issues_repo_name": "therealkeyisme/Math-Notes", "max_issues_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math260/chapters/2.tex", "max_forks_repo_name": "therealkeyisme/Math-Notes", "max_forks_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.59765625, "max_line_length": 619, "alphanum_fraction": 0.6248474035, "num_tokens": 6810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241803, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.714623225762015}}
{"text": "\n\\subsection{Monopoly}\n\nIn the monopoly model we have:\n\n\\(\\pi = pq-c\\)\n\n\\(p[1+\\dfrac{q}{p}\\dfrac{\\delta p}{\\delta q}]=MC\\)\n\nThe price elasticity of demand is: \\(\\epsilon = \\dfrac{p}{q}\\dfrac{\\delta q}{\\delta p}\\)\n\n\\(p[1+\\dfrac{1}{\\epsilon }]=MC\\)\n\n\\(\\dfrac{1}{\\epsilon }=\\dfrac{MC}{p}-1\\)\n\n\\(\\dfrac{p-MC}{p}=-\\dfrac{1}{\\epsilon }\\)\n\n\\subsection{The Lerner index}\n\nThe Lerner index is:\n\n\\(\\dfrac{p-MC}{p}\\)\n\n", "meta": {"hexsha": "18cc4df2bd574d7b4e8a71193668351ba5f1b6b7", "size": 407, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/econometricsAggregate/05-01-monopoly.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/econometricsAggregate/05-01-monopoly.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/econometricsAggregate/05-01-monopoly.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.9583333333, "max_line_length": 88, "alphanum_fraction": 0.5995085995, "num_tokens": 164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966641739774, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.714600008303839}}
{"text": "% To be compiled with pdflatex\r\n% This file is to be included into master file via \\input command\r\n% Note that there is no \\begin{document} \\end{document} brackets!\r\n\r\n\\newpage\r\n\\section{Appendix: \\\\ Matrix derivatives}\r\n\\label{sec:MDerivative}\r\n\r\nDerivative of linear matrix functional $$\\bm{p}^T \\mathcal{F} \\bm{z}$$\r\nwith respect to matrix $\\mathcal{F}$\r\nis computed as follows:\r\n\\begin{enumerate}\r\n \\item Write the functional in element-wise form:\r\n   $$ f = \\bm{p}^T \\mathcal{F} \\bm{z} =\r\n      \\sum_i \\sum_j p_i \\mathcal{F}_{ij} z_j. $$\r\n \\item Differentiate with respect to $\\mathcal{F}_{ij}$:\r\n    $$ \\frac{\\partial f}{\\partial \\mathcal{F}_{ij}} = p_i z_j. $$\r\n \\item Thus $$ \\frac{\\partial}{\\partial \\mathcal{F}}\r\n (\\bm{p}^T \\mathcal{F} \\bm{z}) = \\bm{p} \\bm{z}^T. $$\r\n\\end{enumerate}\r\n\r\nDerivative of quadratic matrix functional\r\n$$\\bm{z}^T \\mathcal{F}^T \\mathcal{A} \\mathcal{F} \\bm{z},$$\r\nwhere $\\mathcal{A}$ is\r\nsymmetric real valued matrix, with respect to matrix $\\mathcal{F}$ is computed\r\nas follows:\r\n\\begin{enumerate}\r\n \\item Write the functional in element-wise form:\r\n\t\t$$ f = \\bm{z}^T \\mathcal{F}^T \\mathcal{AF} \\bm{z} =\r\n\t\t\\sum_{i=1}^m \\sum_{l=1}^n \\sum_{j=1}^m \\sum_{k=1}^n\r\n\t\t\\mathcal{F}_{il} \\mathcal{F}_{jk} \\mathcal{A}_{ij} z_l z_k. $$\r\n \\item Most conveniently, by writing down the above equation for a case of\r\n small matrix size, say, 2x2, find by inspection that\r\n\t\t$$ \\frac{\\partial}{\\partial \\mathcal{F}}\r\n\t\t(\\bm{z}^T \\mathcal{F}^T \\mathcal{AF} \\bm{z}) = 2 \\mathcal{AF} \\bm{zz}^T. $$\r\n\\end{enumerate}\r\n\r\nAnalogously, the derivatives with respect to vector are:\r\n$$ \\frac{\\partial}{\\partial \\bm{z}} ( \\mathcal{F} \\bm{z} ) = \\mathcal{F}, $$\r\n$$\r\n\t\\frac{\\partial}{\\partial \\bm{z}} \\bm{z}^{T} \\mathcal{F} \\bm{z} =\r\n\t2 \\bm{z}^{T} \\mathcal{F}.\r\n$$\r\n", "meta": {"hexsha": "a895469f2a52955d53d40e81a14dc197f6203246", "size": 1774, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_docGMT/Derivatives.tex", "max_stars_repo_name": "cmcorreia/oomao", "max_stars_repo_head_hexsha": "59787859283e89cdb8c2ee88388198f283be9abb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-10-01T18:30:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T01:19:40.000Z", "max_issues_repo_path": "_docGMT/Derivatives.tex", "max_issues_repo_name": "cmcorreia/oomao", "max_issues_repo_head_hexsha": "59787859283e89cdb8c2ee88388198f283be9abb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-04-30T17:22:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-30T17:22:35.000Z", "max_forks_repo_path": "_docGMT/Derivatives.tex", "max_forks_repo_name": "cmcorreia/oomao", "max_forks_repo_head_hexsha": "59787859283e89cdb8c2ee88388198f283be9abb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.3181818182, "max_line_length": 79, "alphanum_fraction": 0.6386696731, "num_tokens": 662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7145589955664673}}
{"text": "\n\\subsection{Elementary events}\n\nWe have a sample space, \\(\\Omega \\) consisting of elementary events.\n\nAll elementary events are disjoint sets.\n\n\\subsection{Non-elementary events}\n\nWe have a \\(\\sigma\\)-algebra over \\(\\Omega \\) called \\(F\\). A \\(\\sigma\\)-algebra takes a set a provides another set containing subsets closed under complement. The power set is an example.\n\nAll events \\(E\\) are subsets of \\(\\Omega\\)\n\n\\(\\forall E\\in F E\\subseteq \\Omega\\)\n\n\\subsection{Mutually exclusive events}\n\nEvents are mutually exclusive if they are disjoint sets.\n\n\\subsection{Complements}\n\nFor each event \\(E\\), there is a complementary event \\(E^C\\) such that:\n\n$E\\lor E^C=\\Omega$\n\n$E\\land E^C=\\varnothing$\n\nThis exists by construction in the measure space.\n\n\\subsection{Union and intersection}\n\nAs events are sets, we can define algebra on sets. For example for two events \\(E_i\\) and \\(E_j\\) we can define:\n\n\\begin{itemize}\n\\item \\(E_i\\land E_j\\)\n\\item \\(E_i\\lor E_j\\)\n\\end{itemize}\n\n", "meta": {"hexsha": "35cef027ab20a2a5cbe62dfe75282f8a7efc1173", "size": 974, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityAxioms/01-01-events.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/probabilityAxioms/01-01-events.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/probabilityAxioms/01-01-events.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.9743589744, "max_line_length": 188, "alphanum_fraction": 0.7248459959, "num_tokens": 260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.7145589797244828}}
{"text": "\\section{Moment Generating Functions, Laplace Transforms}\n\nThe moment generating function (MGF) of a random variable $X$ is:\n\n\\begin{equation}\n\\psi_X(t) = \\mathbb{E}(e^{tX}) = \\int e^{tx}dF(x)\n\\end{equation}\n\nThe MGF allows for interchanging the operations of differentiation and \"taking expectation\".\n\n\\section{Cumulant Generating Functions}\nThe cumulants provide an alternative to the moments of the distribution.\n\n\\begin{equation}\nK_X(t) = \\log\\mathbb{E}(e^{tX}) = \\log\\int e^{tx}dF(x)\n\\end{equation}\n\nThen the $n$th cumulant $\\kappa_n = K_X^{(n)}(0)$ is the $n$th derivative of the cumulant generating function.\n\nThe first cumulant is the mean, the second cumulant is the variance. \n\n\\section{Characteristic Function}\n\n\\begin{equation}\nC_X(t) = \\mathbb{E}(e^{itX}) = \\int e^{itx}dF(x)\n\\end{equation}\n\nThe characteristic function has the advantage that it is well-defined for all real values of $t$ even when $\\mathbb{E}e^{tX}$ is not well defined.\n\n\n\n", "meta": {"hexsha": "5eb559b170b42e5171a3b88c9e3692ab49c02e1b", "size": 955, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/proba_momentgeneratingfunctions.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/proba_momentgeneratingfunctions.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/proba_momentgeneratingfunctions.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.84375, "max_line_length": 146, "alphanum_fraction": 0.7308900524, "num_tokens": 286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103777, "lm_q2_score": 0.7853085708384735, "lm_q1q2_score": 0.714557778181948}}
{"text": "\n\\subsection{Powerset function}\n\nThe power set of \\(s\\), \\(P(s)\\), contains all subsets of \\(s\\).\n\n\\(\\forall x x\\subseteq s \\leftrightarrow x\\in P(x)\\)\n\nDo all subsets exist?? show elsewhere.\n\n", "meta": {"hexsha": "411d3374f9812ca7501c4202e1f6ed22acd9361b", "size": 193, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sets/02-02-powerset.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sets/02-02-powerset.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sets/02-02-powerset.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.3, "max_line_length": 64, "alphanum_fraction": 0.6683937824, "num_tokens": 55, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070109242132, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.7145577743448013}}
{"text": "\\input{../header_class}\r\n\r\n%---------- start document ---------- %\r\n \\section{intresidue -- integer residue}\\linkedzero{intresidue}\r\nintresidue module provides integer residue classes or $\\mathbf{Z}/m\\mathbf{Z}$.\r\n\r\n \\begin{itemize}\r\n   \\item {\\bf Classes}\r\n   \\begin{itemize}\r\n     \\item \\linkingone{intresidue}{IntegerResidueClass}\r\n     \\item \\linkingone{intresidue}{IntegerResidueClassRing}\r\n   \\end{itemize}\r\n   %\\item {\\bf Functions}\r\n   %  \\begin{itemize}\r\n   %    \\item \\linkingone{rational}{innerProduct}\r\n   %  \\end{itemize}\r\n \\end{itemize}\r\n\r\n\\C\r\n\r\n \\subsection{IntegerResidueClass -- integer residue class}\\linkedone{intresidue}{IntegerResidueClass}\r\n \r\n This class is a subclass of \\linkingone{ring}{CommutativeRingElement}.\r\n\r\n  \\initialize\r\n  \\func{IntegerResidueClass}\r\n       {\\hiki{representative}{integer},\\ \r\n       \\hiki{modulus}{integer}}\r\n       {\\out{Integer}}\\\\\r\n  \\spacing\r\n  % document of basic document\r\n  \\quad Create a residue class of modulus with residue representative.\r\n  % added document\r\n  \\spacing\r\n  % input, output document\r\n  \\param{modulus} must be positive integer.\r\n  %\\begin{at}\r\n  %  \\item[compo]\\linkedtwo{vector}{Vector}{compo}:\\\\ It expresses component of Vector.\r\n  %\\end{at}\r\n  \\begin{op}\r\n    \\verb|a+b| & addition.\\\\\r\n    \\verb|a-b| & subtraction.\\\\\r\n    \\verb|a*b| & multiplication.\\\\\r\n    \\verb|a/b| & division.\\\\\r\n    \\verb|a**i,pow(a,i)| & power.\\\\\r\n    \\verb|-a| & negation.\\\\\r\n    \\verb|+a| & make a copy.\\\\\r\n    \\verb|a==b| & equality or not.\\\\\r\n    \\verb|a!=b| & inequality or not.\\\\\r\n    \\verb|repr(a)| & return representation string.\\\\\r\n    \\verb|str(a)| & return string.\\\\\r\n  \\end{op} \r\n%\\begin{ex}\r\n%>>> A = vector.Vector([1,2])\r\n%>>> A\r\n%Vector([1, 2])\r\n%>>> A.compo\r\n%[1, 2]\r\n%>>>\r\n%\\end{ex}%Don't indent!\r\n  \\method\r\n  \\subsubsection{getRing -- get ring object}\\linkedtwo{intresidue}{IntegerResidueClassRing}{getRing}\r\n   \\func{getRing}{\\param{self}}{\\out{IntegerResidueClassRing}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return a ring to which it belongs.\r\n   %\\spacing\r\n   % added document\r\n   %\\quad \\negok Note that this function returns integer only.\\\\\r\n   %\\spacing\r\n   % input, output document\r\n   %\\quad \\param{a} must be int, long or rational.Integer.\\\\\r\n%\r\n  \\subsubsection{getResidue -- get residue}\\linkedtwo{intresidue}{IntegerResidueClassRing}{getResidue}\r\n   \\func{getResidue}{\\param{self}}{\\out{integer}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the value of residue.\r\n   %\\spacing\r\n   % added document\r\n   %\\quad \\negok Note that this function returns integer only.\\\\\r\n   %\\spacing\r\n   % input, output document\r\n   %\\quad \\param{a} must be int, long or rational.Integer.\\\\\r\n%\r\n  \\subsubsection{getModulus -- get modulus}\\linkedtwo{intresidue}{IntegerResidueClassRing}{getModulus}\r\n   \\func{getModulus}{\\param{self}}{\\out{integer}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the value of modulus.\r\n   %\\spacing\r\n   % added document\r\n   %\\quad \\negok Note that this function returns integer only.\\\\\r\n   %\\spacing\r\n   % input, output document\r\n   %\\quad \\param{a} must be int, long or rational.Integer.\\\\\r\n%\r\n  \\subsubsection{inverse -- inverse element}\\linkedtwo{intresidue}{IntegerResidueClassRing}{inverse}\r\n   \\func{inverse}{\\param{self}}{\\out{IntegerResidueClass}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the inverse element if it is invertible. Otherwise raise ValueError.\r\n   %\\spacing\r\n   % added document\r\n   %\\quad \\negok Note that this function returns integer only.\\\\\r\n   %\\spacing\r\n   % input, output document\r\n   %\\quad \\param{a} must be int, long or rational.Integer.\\\\\r\n%\r\n  \\subsubsection{minimumAbsolute -- minimum absolute representative}\\linkedtwo{intresidue}{IntegerResidueClassRing}{minimumAbsolute}\r\n   \\func{minimumAbsolute}{\\param{self}}{\\out{\\linkingone{rational}{Integer}}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad  Return the minimum absolute representative integer of the residue class.\r\n   %\\spacing\r\n   % added document\r\n   %\\quad \\negok Note that this function returns integer only.\\\\\r\n   %\\spacing\r\n   % input, output document\r\n   %\\quad \\param{a} must be int, long or rational.Integer.\\\\\r\n%\r\n  \\subsubsection{minimumNonNegative -- smallest non-negative representative}\\linkedtwo{intresidue}{IntegerResidueClassRing}{minimumNonNegative}\r\n   \\func{minimumNonNegative}{\\param{self}}{\\out{\\linkingone{rational}{Integer}}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the smallest non-negative representative element of the residue class.\r\n   %\\spacing\r\n   % added document\r\n   \\quad \\negok this method has an alias, named toInteger.\\\\\r\n   %\\spacing\r\n   % input, output document\r\n   %\\quad \\param{a} must be int, long or rational.Integer.\\\\\r\n%\r\n%\\begin{ex}\r\n%>>> A = module.HogeClass((1,2))\r\n%>>> A.hogemethod1(2)\r\n%(2, 4)\r\n%>>>\r\n%\\end{ex}%Don't indent!\r\n\\C\r\n \\subsection{IntegerResidueClassRing -- ring of integer residue}\\linkedone{intresidue}{IntegerResidueClassRing}\r\n The class is for rings of integer residue classes.\r\n\r\n This class is a subclass of \\linkingone{ring}{CommutativeRing}.\r\n\r\n\r\n  \\initialize\r\n  \\func{IntegerResidueClassRing}{\\hiki{modulus}{integer}}{\\out{IntegerResidueClassRing}}\\\\\r\n  \\spacing\r\n  % document of basic document\r\n  \\quad Create an instance of IntegerResidueClassRing. \r\n  % added document\r\n  The argument \\param{modulus} = $m$ specifies an ideal $m\\mathbb{Z}$.\r\n  % \\spacing\r\n  % input, output document\r\n  %See \\linkingone{module}{point} for \\param{point}.\r\n  \\begin{at}\r\n    \\item[zero]\\linkedtwo{integer}{IntegerRing}{zero}:\\\\ It expresses The additive unit 0. (read only)\r\n    \\item[one]\\linkedtwo{integer}{IntegerRing}{one}:\\\\ It expresses The multiplicative unit 1. (read only)\r\n  \\end{at}\r\n  \\begin{op}\r\n  %  \\verb|+| & Vector sum.\\\\\r\n  %  \\verb|-| & Vector subtraction.\\\\\r\n  %  \\verb|*| & Scalar multiplication.\\\\\r\n  %  \\verb|//| & Scalar division.\\\\\r\n  %  \\verb|-(unary)| & element negation.\\\\\r\n    \\verb|R==A| & ring equality.\\\\\r\n  %  \\verb|!=| & inequality or not.\\\\\r\n  %  \\verb+V[i]+ & Return the coefficient of i-th element of Vector.\\\\\r\n  %  \\verb+V[i] = c+ & Replace the coefficient of i-th element of Vector by c.\\\\\r\n    \\verb|card(R)| & return cardinality. See also \\linkingzero{compatibility} module.\\\\\r\n    \\verb|e in R| & return whether an element is in or not.\\\\\r\n    \\verb|repr(R)| & return representation string.\\\\\r\n    \\verb|str(R)| & return string.\\\\\r\n  \\end{op} \r\n%\\begin{ex}\r\n%>>> A = vector.Vector([1,2])\r\n%>>> A\r\n%Vector([1, 2])\r\n%>>> A.compo\r\n%[1, 2]\r\n%>>>\r\n%\\end{ex}%Don't indent!\r\n  \\method\r\n  \\subsubsection{createElement -- create IntegerResidueClass object}\\linkedtwo{intresidue}{IntegerResidueClassRing}{createElement}\r\n   \\func{createElement}{\\param{self},\\ \\hiki{seed}{integer}}{\\out{Integer}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return an IntegerResidueClass instance with \\param{seed}. \r\n   %\\spacing\r\n   % added document\r\n   %\\quad \\negok Note that this function returns integer only.\\\\\r\n   %\\spacing\r\n   % input, output document\r\n   %\\quad \\\\\r\n%\r\n  \\subsubsection{isfield -- field test}\\linkedtwo{intresidue}{IntegerResidueClassRing}{isfield}\r\n   \\func{isfield}{\\param{self}}{\\out{bool}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return True if the modulus is prime, False if not. Since a finite domain is a field, other ring property tests are merely aliases of isfield; they are isdomain, iseuclidean, isnoetherian, ispid, isufd.\r\n   % added document\r\n   %\\quad \\negok Note that this function returns integer only.\\\\\r\n   %\\spacing\r\n   % input, output document\r\n   %\\quad if \\param{as\\_column} is True, try to create column matrix.\\\\\r\n%\r\n  \\subsubsection{getInstance -- get instance of IntegerResidueClassRing}\\linkedtwo{intresidue}{IntegerResidueClassRing}{getInstance}\r\n   \\func{getInstance}{\\param{cls},\\ \\hiki{modulus}{integer}}{\\out{IntegerResidueClass}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return an instance of the class of specified modulus. Since this is a class method, use it as:\r\n\r\n\\verb|IntegerResidueClassRing.getInstance(3)|\r\n\r\nto create a $\\mathbb{Z}/3\\mathbb{Z}$ object, for example.\r\n%\\begin{ex}\r\n%>>> A = module.HogeClass((1,2))\r\n%>>> A.hogemethod1(2)\r\n%(2, 4)\r\n%>>>\r\n%\\end{ex}%Don't indent!\r\n\r\n\\C\r\n\r\n%---------- end document ---------- %\r\n\r\n\\input{../footer}\r\n", "meta": {"hexsha": "e80f88b59965dd08907b4bccc2a8f8f4612876a4", "size": 8353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/en/intresidue.tex", "max_stars_repo_name": "turkeydonkey/nzmath3", "max_stars_repo_head_hexsha": "a48ae9efcf0d9ad1485c2e9863c948a7f1b20311", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-26T19:22:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T19:22:17.000Z", "max_issues_repo_path": "manual/en/intresidue.tex", "max_issues_repo_name": "turkeydonkey/nzmath3", "max_issues_repo_head_hexsha": "a48ae9efcf0d9ad1485c2e9863c948a7f1b20311", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "manual/en/intresidue.tex", "max_forks_repo_name": "turkeydonkey/nzmath3", "max_forks_repo_head_hexsha": "a48ae9efcf0d9ad1485c2e9863c948a7f1b20311", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.4759825328, "max_line_length": 211, "alphanum_fraction": 0.6670657249, "num_tokens": 2458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311355, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7143399373145526}}
{"text": "\\chapter{Backtracking}\n\\section{Introduction}\n\\runinhead{Difference between backtracking and dfs.} \\textit{Backtracking} is a more general purpose algorithm. \\textit{Dfs} is a specific form of backtracking related to searching tree structures. \n\n\\runinhead{Prune.} Backtrack need to think about pruning using the condition \\pyinline{predicate}.\n\n\\section{Sequence}\n\\runinhead{k sum.} Given $n$ unique integers, number $k$ and target. Find all possible $k$ integers where their sum is target. \n\nComplexity: $O(2^n)$.\n\nPay attention to the pruning condition.\n\n\\begin{python}\ndef dfs(self, A, i, k, cur, remain, ret):\n    \"\"\"self.dfs(A, 0, k, [], target, ret)\"\"\"\n    if len(cur) == k and remain == 0:\n        ret.append(list(cur))\n        return\n\n    if (i >= len(A) or len(cur) > k \n        or len(A)-i+len(cur) < k):\n        return\n\n    self.dfs(A, i+1, k, cur, remain, ret)\n    cur.append(A[i])\n    self.dfs(A, i+1, k, cur, remain-A[i], ret)\n    cur.pop()\n\\end{python}\n\n\n\\section{String}\n\\subsection{Palindrome}\n\\subsubsection{Palindrome partition.} Given \\pyinline{s = \"aab\"}, return: \\\\\n\\pyinline{[[\"aa\",\"b\"], [\"a\",\"a\",\"b\"]]}\n\\\\\n\\runinhead{Core clues:}\n\\begin{enumerate}\n\\item Expand the search tree \\textbf{horizontally}.\n\\end{enumerate}\n\\rih{Search process:}\n\\begin{python}\ninput: \"aabbc\"\n\n\"a\", \"abbc\"\n     \"a\", \"bbc\"\n          \"b\", \"bc\"\n               \"b\", \"c\" (o)\n               \"bc\" (x)\n          \"bb\", \"c\" (o)\n          \"bbc\" (x)\n     \"ab\", \"bc\" (x)\n     \"abb\", \"c\" (x)\n     \"abbc\" (x)\n\"aa\", \"bbc\"\n      \"b\", \"bc\"\n           \"b\", \"c\" (o)\n           \"bc\" (x)\n      \"bb\", \"c\" (o)\n      \"bbc\" (x)\n\"aab\", \"bc\" (x)\n\"aabb\", \"c\" (x)\n\\end{python}\nCode:\n\n\\begin{python}\ndef partition(self, s):\n    ret = []\n    self.backtrack(s, [], ret)\n    return ret\n\ndef backtrack(self, s, cur_lvl, ret):\n    \"\"\"\n    Let i be the scanning ptr.\n    If s[:i] passes predicate, then backtrack s[i:]\n    \"\"\"\n    if not s:\n        ret.append(list(cur_lvl))\n\n    for i in xrange(1, len(s)+1):\n        if self.predicate(s[:i]):\n            cur_lvl.append(s[:i])\n            self.backtrack(s[i:], cur_lvl, ret)\n            cur_lvl.pop()\n\ndef predicate(self, s):\n    return s == s[::-1]\n\\end{python}\n\n\n\n\\section{Math}\n\\subsection{Decomposition}\n\\subsubsection{Factorize a number}\\label{factorization}\n\\runinhead{Core clues:}\n\\begin{enumerate}\n\\item Expand the search tree \\textbf{horizontally}.\n\\end{enumerate}\n\\runinhead{Search tree:}\n\\begin{python}\nInput: 16\nget factors of cur[-1]\n[16]\n[2, 8]\n[2, 2, 4]\n[2, 2, 2, 2]\n\n[4, 4]\n\\end{python}\nCode:\n\\begin{python}\ndef dfs(self, cur, ret):\n  if len(cur) > 1:\n    ret.append(list(cur))\n\n  n = cur.pop()\n  start = cur[-1] if cur else 2\n  for i in xrange(start, int(sqrt(n))+1):\n    if self.predicate(n, i):\n      cur.append(i)\n      cur.append(n/i)\n      self.dfs(cur, ret)\n      cur.pop()\n            \ndef predicate(self, n, i):\n  return n%i == 0\n  \n\\end{python}\n\\runinhead{Time complexity.} The search tree's size is $O(2^n)$ where $n$ is the number\nof prime factors. Choose $i$ prime factors to combine then, and keep the rest uncombined：\n\n\n$$\\sum_i {n \\choose i} = 2^n$$\n\n\n\\section{Arithmetic Expression}\n\\subsection{Unidirection}\n\\rih{Insert operators.} Given a string that contains only digits 0-9 and a target value,\nreturn all possibilities to add binary operators (not unary) +, -, or * between the\ndigits so they evaluate to the target value.\n\nExample: \n\\begin{align*}\n``123\", 6 \\rightarrow [``1+2+3\", ``1*2*3\"] \\\\ \n``232\", 8 \\rightarrow [``2*3+2\", ``2+3*2\"] \\\\\n\\end{align*}\nClues:\n\\begin{enumerate}\n\\item Backtracking with \\textit{horizontal} expanding\n\\item Special handling for multiplication - caching the expression \\textit{predecessor}\nfor multiplication association. \n\\item Detect \\textit{invalid} number with leading 0's\n\\end{enumerate}\n\n\\begin{python}\ndef addOperators(self, num, target):\n  ret = []\n  self.dfs(num, target, 0, \"\", 0, 0, ret)\n  return ret\n\ndef dfs(self, num, target, pos, \n        cur_str, cur_val, \n        mul, ret\n):\n  if pos >= len(num):\n    if cur_val == target:\n      ret.append(cur_str)\n  else:\n    for i in xrange(pos, len(num)):\n      if i != pos and num[pos] == '0':\n        continue\n        \n      nxt_val = int(num[pos:i+1])\n      if not cur_str:  # 1st number\n        self.dfs(num, target, i+1, \n            \"%d\"%nxt_val, nxt_val,\n            nxt_val, ret)\n      else:  # +, -, *\n        self.dfs(num, target, i+1, \n            cur_str+\"+%d\"%nxt_val, cur_val+nxt_val, \n            nxt_val, ret)\n        self.dfs(num, target, i+1, \n            cur_str+\"-%d\"%nxt_val, cur_val-nxt_val, \n            -nxt_val, ret)\n        self.dfs(num, target, i+1, \n    cur_str+\"*%d\"%nxt_val, cur_val-mul+mul*nxt_val, \n            mul*nxt_val, ret)\n\\end{python}\n\\subsection{Bidirection}\n\\rih{Insert parenthesis.} Given a string of numbers and operators, return all possible\nresults from computing all the different possible ways to group numbers and operators.\nThe valid operators are +, - and *.\n\nExamples:\n\\begin{align*}\n(2*(3-(4*5))) &= -34 \\\\\n((2*3)-(4*5)) &= -14 \\\\\n((2*(3-4))*5) &= -10 \\\\\n(2*((3-4)*5)) &= -10 \\\\\n(((2*3)-4)*5) &= 10\n\\end{align*}\nClues: Iterate the operators, divide and conquer - left parts and right parts and then\ncombine result. \\\\\nCode:\n\\begin{python}\ndef dfs_eval(self, nums, ops):\n  ret = []\n  if not ops:\n    assert len(nums) == 1\n    return nums\n\n  for i, op in enumerate(ops):\n    left_vals = self.dfs_eval(nums[:i+1], ops[:i])\n    right_vals = self.dfs_eval(nums[i+1:], ops[i+1:])\n    for l in left_vals:\n      for r in right_vals:\n        ret.append(self._eval(l, r, op))\n\n  return ret\n\\end{python}\n\\section{Tree}\n\\subsection{BST}\n\\subsubsection{Generate Valid BST}\nGenerate all valid BST with nodes from 1 to $n$.\n\\runinhead{Core clues:}\n\\begin{enumerate}\n\\item Iterate pivot\n\\item Generate left and right\n\\end{enumerate}\nCode:\n\\begin{python}\ndef generate(self, start, end):\n  roots = []\n  if start > end:\n    roots.append(None)\n    return roots\n\n  for pivot in range(start, end+1):\n    left_roots = self.generate_cache(start, pivot-1)\n    right_roots = self.generate_cache(pivot+1, end)\n    \n    for left_root in left_roots:\n      for right_root in right_roots:\n        root = TreeNode(pivot)\n        root.left = left_root\n        root.right = right_root\n\n        roots.append(root)\n\n  return roots \n\n\\end{python}\n\n\n", "meta": {"hexsha": "5af15c41de9e85a5ed0a7111b4e92c6c74a368f7", "size": 6302, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterBacktracking.tex", "max_stars_repo_name": "li77leprince/Algo-Quicksheet", "max_stars_repo_head_hexsha": "1736bc0ee1d73b0b06dcf3823a65ea0f8c286108", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapterBacktracking.tex", "max_issues_repo_name": "li77leprince/Algo-Quicksheet", "max_issues_repo_head_hexsha": "1736bc0ee1d73b0b06dcf3823a65ea0f8c286108", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapterBacktracking.tex", "max_forks_repo_name": "li77leprince/Algo-Quicksheet", "max_forks_repo_head_hexsha": "1736bc0ee1d73b0b06dcf3823a65ea0f8c286108", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.7137254902, "max_line_length": 198, "alphanum_fraction": 0.6110758489, "num_tokens": 1950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.7142585283789016}}
{"text": "\\section{Formulary: Queueing Theory}\n\\label{sec:Formulary-Queueing-Theory}\n\n\\subsection{Foundations}\n\n\\begin{description}\n\t\n\t\\item [Inter-arrival time]\t\n\t\t\\begin{equation}\n\t\t\\expected{\\tau} = \\frac{1}{\\lambda}\n\t\t\\end{equation}\n\t\n\t\\item [Service time]\t\n\t\t\\begin{equation}\n\t\t\\expected{S} = \\frac{1}{\\mu}\n\t\t\\end{equation}\n\t\n\t\\item [Response time]\t\n\t\t\\begin{equation}\n\t\t\\expected{T} = \\expected{T_{Q}} + \\expected{S}\n\t\t\\end{equation}\n\t\n\t\\item [Jobs]\t\n\t\t\\begin{equation}\n\t\t\\expected{N} = \\expected{N_{Q}} + \\expected{N_{S}}\n\t\t\\end{equation}\n\t\n\t\\item [Server demand]\n\t\t\\begin{equation}\n\t\t\\expected{D_{i}} = \\expected{V_{i}} \\cdot \\expected{S_{i}}\n\t\t\\end{equation}\n\t\n\t\t\\begin{equation}\n\t\t\\expected{D_{i}} = \\frac{B_{i}}{C} \n\t\t\\end{equation}\n\t\n\t\\item [Total demands]\t\n\t\t\\begin{equation}\n\t\tD = \\sum_{i=1}^{m}\\expected{D_{i}}\n\t\t\\end{equation}\n\t\n\t\\item [Maximum demand]\t\n\t\t\\begin{equation}\n\t\tD_{max} = \\max\\{\\expected{D_{i}}\\}\n\t\t\\end{equation}\n\t\t\n\\end{description}\n\n\n\n\n\\subsection{Operational Laws}\n\n\\begin{description}\n\t\n\t\\item [Stability Law]\t\n\t\t\\begin{equation}\n\t\t\\lambda < \\mu\n\t\t\\end{equation}\n\t\n\t\\item [Little's Law for open systems]\t\n\t\t\\begin{equation}\n\t\t\\expected{N} = \\lambda \\cdot \\expected{T}\n\t\t\\end{equation}\n\t\n\t\\item [Little's Law for batch systems]\t\n\t\t\\begin{equation}\n\t\tN = X \\cdot \\expected{T}\n\t\t\\end{equation}\n\t\n\t\\item [Little's Law for interactive systems]\t\n\t\t\\begin{equation}\n\t\t\\expected{T_{R}} = \\frac{N}{X} - \\expected{Z}\n\t\t\\end{equation}\n\t\n\t\\item [Utilization Law]\t\n\t\t\\begin{equation}\n\t\t\\varrho_{i} = \\frac{\\lambda_{i}}{\\mu_{i}}\n\t\t\\end{equation}\n\t\n\t\t\\begin{equation}\n\t\t\\varrho_{i} = X \\cdot \\expected{D_{i}}\n\t\t\\end{equation}\n\t\n\t\t\\begin{equation}\n\t\t\\varrho_{i} = \\probability{server \\; i \\; busy} = \\expected{requests \\; to \\; server \\; i} = \\expected{N_{S,i}}\n\t\t\\end{equation}\n\t\n\t\\item [Forced Flow Law]\t\t\n\t\t\\begin{equation}\n\t\tX_{i} = \\expected{V_{i}} \\cdot X\n\t\t\\end{equation}\n\t\n\t\\item [Bottleneck Law]\t\n\t\t\\begin{equation}\n\t\t\\expected{D_{i}} = \\expected{V_{i}} \\cdot \\expected{S_{i}}\n\t\t\\end{equation}\n\t\n\\end{description}\n\n\n\n\n\\subsection{Asymptotic Analysis for closed systems}\n\n\\begin{description}\n\t\n\t\\item [Throughput Asymptotes]\t\n\t\t\\begin{equation}\n\t\tX \\leq \\min \\Big\\{ \\frac{N}{D + \\expected{Z}} , \\frac{1}{D_{max}} \\Big\\}\n\t\t\\end{equation}\n\t\n\t\\item [Response Time Asymptotes]\t\n\t\t\\begin{equation}\n\t\t\\expected{R} \\geq \\max\\{D , N \\cdot D_{max} - \\expected{Z} \\}\n\t\t\\end{equation}\n\t\n\t\\item [Queue Point]\t\n\t\t\\begin{equation}\n\t\tN^{*} = \\frac{D + \\expected{Z}}{D_{max}}\n\t\t\\end{equation}\n\t\n\\end{description}\n\n\n\n\n\\subsection{M/M/1}\n\n\\begin{description}\n\t\n\t\\item [Utilization]\t\n\t\t\\begin{equation}\n\t\t\\varrho = \\frac{\\lambda}{\\mu}\n\t\t\\end{equation}\n\n\t\\item [State Probability]\t\n\t\t\\begin{equation}\n\t\t\\pi_{i} = \\varrho^{i}(1-\\varrho)\n\t\t\\end{equation}\n\t\n\t\\item [Mean System Jobs]\t\n\t\t\\begin{equation}\n\t\t\\expected{N} = \\frac{\\varrho}{(1-\\varrho)}\n\t\t\\end{equation}\n\t\n\t\\item [Mean Response Time]\t\n\t\t\\begin{equation}\n\t\t\\expected{T} = \\frac{1}{\\mu-\\lambda}\n\t\t\\end{equation}\t\n\t\n\\end{description}\n\n\n\n\n\\subsection{M/M/m}\n\n\\begin{description}\n\t\n\t\\item [Utilization]\n\tBoth system and each server\n\t\t\\begin{equation}\n\t\t\\varrho = \\frac{\\lambda}{m\\mu}\n\t\t\\end{equation}\n\t\t\n\t\\item [Resource Requirement]\t\n\t\t\\begin{equation}\t\n\t\tR = \\expected{N_{S}} = \\frac{\\lambda}{\\mu}\n\t\t\\end{equation}\n\t\n\t\\item [State Probability]\n\t\t\\begin{equation}\n\t\t\\pi_{i} = \\left\\{\\begin{matrix}\n\t\t\\Big(\\frac{\\lambda}{\\mu}\\Big)^{i}\\frac{1}{i!}\\pi_{0} & i \\leq m\\\\ \n\t\t\\Big(\\frac{\\lambda}{\\mu}\\Big)^{i}\\frac{1}{m!}\\Big(\\frac{1}{m}\\Big)^{i-m}\\pi_{0} & i > m\n\t\t\\end{matrix}\\right.\n\t\t\\end{equation}\n\t\t\n\t\tor equivalently\n\t\n\t\t\\begin{equation}\n\t\t\\pi_{i} = \\frac{m^{q} \\varrho^{i}}{q!} \\cdot \\pi_{0} \\qquad with \\quad q=\\min\\{i,m\\}\n\t\t\\end{equation}\n\t\t\n\t\twith\n\t\t\n\t\t\\begin{equation}\t\n\t\t\\pi_{0} = \\Big[ \\sum_{i=0}^{m-1} \\frac{(m \\varrho)^{i}}{i!} + \\frac{(m \\varrho)^{m}}{m! (1- \\varrho)} \\Big]^{-1}\n\t\t\\end{equation}\n\t\t\n\t\twhere $q$ is the number of busy servers.\t\n\t\n\t\\item [Queue Probability]\n\t\t\\begin{equation}\n\t\tP_{Q} = \\frac{(m \\varrho)^{m}}{m!(1-\\varrho)} \\cdot \\pi_{0}\n\t\t\\end{equation}\n\t\t\n\t\\item [Mean Queue Jobs]\n\t\t\\begin{equation}\n\t\t\\expected{N_{Q}} = \\frac{\\varrho}{(1-\\varrho)} \\cdot P_{Q}\n\t\t\\end{equation}\n\t\n\\end{description}\n\n\n\n\n\\subsection{M/M/m/m}\n\n\\begin{description}\n\t\n\t\\item [Utilization]\n\tBoth system and each server\n\t\t\\begin{equation}\n\t\t\\varrho = \\frac{\\lambda}{m\\mu}\n\t\t\\end{equation}\n\t\n\t\\item [State Probability]\n\t\t\\begin{equation}\n\t\t\\pi_{i} = \\Big( \\frac{\\lambda}{\\mu} \\Big)^{i} \\frac{1}{i!} \\pi_{0} \n\t\t\\end{equation}\n\t\t\n\t\twith\n\t\t\n\t\t\\begin{equation}\n\t\t\\pi_{0} = \\Big[ \\sum_{i=0}^{m} \\Big( \\frac{\\lambda}{\\mu} \\Big)^{i} \\frac{1}{i!} \\Big]^{-1}\n\t\t\\end{equation}\t\n\t\n\t\\item [Block Probability]\t\n\t\t\\begin{equation}\n\t\tP_{block} = \\pi_{m} = \\frac{\\Big(\\frac{\\lambda}{\\mu}\\Big)^{m} \\frac{1}{m!}}{\\sum_{i=0}^{m} \\Big( \\frac{\\lambda}{\\mu} \\Big)^{i} \\frac{1}{i!}}\n\t\t\\end{equation}\n\t\t\n\t\tor equivalently\n\t\t\n\t\t\\begin{equation}\n\t\t\\begin{split}\n\t\tP_{block} & = \\pi_{m} \\cdot \\frac{e^{-\\frac{\\lambda}{\\mu}}}{e^{-\\frac{\\lambda}{\\mu}}} \\\\ \n\t\t& = \\frac{e^{-\\frac{\\lambda}{\\mu}} \\cdot \\Big(\\frac{\\lambda}{\\mu}\\Big)^{m} \\frac{1}{m!}}{\\sum_{i=0}^{m} e^{-\\frac{\\lambda}{\\mu}} \\cdot \\Big( \\frac{\\lambda}{\\mu} \\Big)^{i} \\frac{1}{i!}} \\\\\n\t\t& = \\frac{\\probability{X = m}}{\\probability{X \\leq m}}\n\t\t\\end{split}\n\t\t\\end{equation}\n\t\t\n\t\twhere $X \\sim Poisson(\\frac{\\lambda}{\\mu})$.\n\t\n\\end{description}\n\n\t\n\n\n\\subsection{M/M/\\texorpdfstring{$\\infty$}{Infinity}}\n\n\\begin{description}\n\n\t\\item [Utilization]\n\t\t\\begin{equation}\n\t\t\\varrho = \\frac{\\lambda}{\\mu}\n\t\t\\end{equation}\n\t\n\t\\item [State Probability]\n\t\t\\begin{equation}\n\t\t\\pi_{i} = \\Big(\\frac{\\lambda}{\\mu})^{i} \\frac{1}{i!} \\pi_{0}\n\t\t\\end{equation}\n\t\t\n\t\twith\n\t\t\n\t\t\\begin{equation}\n\t\t\\pi_{0} = e^{-\\frac{\\lambda}{\\mu}}\n\t\t\\end{equation}\n\t\t\n\t\tThat is $N^{M/M/\\infty} \\sim Poisson(\\frac{\\lambda}{\\mu})$.\n\t\t\n\t\\item [Mean System Jobs]\n\t\t\\begin{equation}\n\t\t\\expected{N} = \\frac{\\lambda}{\\mu}\n\t\t\\end{equation}\t\n\t\n\t\\item [Mean Queue Jobs]\n\t\t\\begin{equation}\n\t\t\t\\expected{N_{Q}} = 0\n\t\t\\end{equation}\n\t\t\n\t\\item [Response Time]\n\t\t\\begin{equation}\n\t\t\t\\expected{T} = \\expected{T_{S}} = \\frac{1}{\\mu}\n\t\t\\end{equation}\n\t\t\n\t\\item [Delay]\n\t\t\\begin{equation}\n\t\t\\expected{T_{Q}} = 0\n\t\t\\end{equation}\n\t\n\\end{description}\n\n\n\n\n\\subsection{M/G/1}\n\n\\begin{description}\n\t\n\t\\item [Mean Queue/Excess Time]\n\t\t\\begin{equation}\n\t\t\\expected{T_{Q}}=\\frac{\\varrho}{1-\\varrho}\\expected{S_{e}}\n\t\t\\end{equation}\n\t\n\t\\item [Pollaczek-Khinchin Formula]\n\t\t\\begin{equation}\n\t\t\\expected{T_{Q}}=\\frac{\\varrho}{1-\\varrho}\\cdot\\frac{\\expected{S^{2}}}{2\\expected{S}}\n\t\t\\end{equation}\n\t\t\n\t\t\\begin{equation}\n\t\t\\expected{T_{Q}}=\\frac{\\varrho}{1-\\varrho}\\cdot\\frac{\\expected{S}}{2}\\cdot(C_{S}^{2}+1)\n\t\t\\end{equation}\n\t\t\n\t\t\\begin{equation}\n\t\t\\expected{T_{Q}}=\\frac{\\lambda\\expected{S^{2}}}{2(1-\\varrho)}\n\t\t\\end{equation}\n\t\n\\end{description}\n\n\n\n\n\\subsection{Relations between queues}\n\n\\begin{description}\n\t\n\t\\item [Block M/M/m/m vs. Queueing M/M/1]\n\t\t\\begin{equation}\n\t\tP_{block} = \\frac{(1-\\varrho)P_{Q}}{1-\\varrho P_{Q}}\n\t\t\\end{equation}\n\t\n\t\n\\end{description}\n\n\n\n\n\\subsection{Capacity Provisioning}\n\n\\begin{description}\n\t\n\t\\item [Square-Root Staffing Rule]\n\tFor any $M/M/m$ with high resource requirement $R$, the minimum number of servers $m_{\\alpha}^{*}$ to ensure $P_{Q} < \\alpha$ is\n\t\n\t\\begin{equation}\n\tm_{\\alpha}^{*} \\approx R + c \\sqrt{R}\n\t\\end{equation}\n\t\n\twith $c$ solution of the equation\n\t\n\t\\begin{equation}\n\t\\frac{c \\Phi(c)}{\\phi(c)} = \\frac{1 - \\alpha}{\\alpha}\n\t\\end{equation}\t\n\t\n\twhere\n\t$\\Phi(\\cdot)$ is the c.d.f. of the Standard Normal, and\n\t$\\phi(\\cdot)$ is its p.d.f.\n\\end{description}\n\n\n\n\n\\subsection{Open Jackson Networks}\n\n\\begin{description}\n\t\n\t\\item [State Probability]\n\t\t\\begin{equation}\n\t\t\\pi_{n_{1},...,n_{m}} = \\prod_{i=1}^{m} \\varrho_{i}^{n_{i}} (1-\\varrho_{i})\n\t\t\\end{equation}\n\t\t\n\t\\item [Probability Jobs at Server]\n\t\t\\begin{equation}\n\t\t\\probability{n_{i} jobs at server i} = \\varrho_{i}^{n_{i}} (1-\\varrho_{i})\n\t\t\\end{equation}\n\t\n\t\\item [Mean Server Jobs]\n\t\t\\begin{equation}\n\t\t\\expected{N_{i}} = \\frac{\\varrho_{i}}{1 - \\varrho_{i}}\n\t\t\\end{equation}\n\t\n\\end{description}\n\n\n\n\n\\subsection{Closed Jackson Networks}\n\n\\begin{description}\n\n\t\\item [State Probability]\n\t\t\\begin{equation}\n\t\t\\pi_{n_{1},...,n_{m}} = C \\cdot \\prod_{i=1}^{m} \\varrho_{i}^{n_{i}}\n\t\t\\end{equation}\n\t\t\n\t\twhere $C$ is the \\textit{Normalizing Constant} determined as the solution of \n\t\t\n\t\t$\n\t\t\\sum_{(n_{1},...,n_{m}) \\\\ \\in States} \\pi_{n_{1},...,n_{m}} = 1\n\t\t$\n\t\t\n\\end{description}\n\n\n\n\n\\subsection{Mean Value Analysis}\n\n\\begin{description}\n\n\t\\item [MVA Response Time]\n\t\t\\begin{equation}\n\t\t\\expected{T_{j}^{M}} = \n\t\t\\frac{1}{\\mu_{j}} + \n\t\t\\frac{p_{j} \\lambda^{(M-1)} \\expected{T_{j}^{(M-1)}}}{\\mu_{j}}\n\t\t\\end{equation}\n\t\n\t\\item [MVA Fraction of Arrivals]\n\t\t\\begin{equation}\n\t\tp_{j} = \\frac{\\lambda_{j}^{M}}{\\lambda^{M}} = \\frac{V_{j}}{\\sum_{j=1}^{m} V_{j}}\n\t\t\\end{equation}\n\t\n\t\\item [MVA Total Arrival Rate]\n\t\t\\begin{equation}\n\t\t\\lambda^{(M-1)} = \\frac{M-1}{\\sum_{j=1}^{m} p_{j} \\expected{T_{j}^{(M-1)}}}\n\t\t\\end{equation}\t\n\n\\end{description}\n\n\n\n\n\\subsection{Network of PS Servers}\n\n\\begin{description}\n\n\t\\item [BCMP Theorem]\n\t\t\\begin{equation}\n\t\t\\pi_{n_{1},...,n_{m}} = \\prod_{i=1}^{m} \\varrho_{i}^{n_{i}} (1-\\varrho_{i})\n\t\t\\end{equation}\t\t\n\t\twhere $\\varrho_{i}=\\lambda_{i}\\expected{S_{i}}$\n\t\t\n\t\\item [Probability Jobs at Server]\n\t\t\\begin{equation}\n\t\t\\probability{n_{i} jobs at server i} = \\varrho_{i}^{n_{i}} (1-\\varrho_{i})\n\t\t\\end{equation}\n\t\twhere $\\varrho_{i}=\\lambda_{i}\\expected{S_{i}}$\n\t\n\\end{description}\n\n\n\n\n\\subsection{Renewal-Reward Theory}\n\n\\begin{description}\n\t\n\t\\item [Renewal-Reward Theorem]\n\t\t\\begin{equation}\n\t\t\\lim_{t \\to \\infty}\\frac{R(t)}{t}=\\frac{\\expected{R}}{\\expected{X}} \\quad \\forall 0\\leq\\expected{R}<\\infty,0<\\expected{X}<\\infty\n\t\t\\end{equation}\n\t\twhere $X$ is the inter-arrival time, $R is the number of rewards earned$, and $R(t)$ is the total rewards by time $t$.\n\t\n\\end{description}\n\n\n\n\n\\subsection{Task Assignment for Server Farms}\n\n\\begin{description}\n\t\n\t\\item [Spare Server]\n\t\t\\begin{equation}\n\t\t\\sharp SpareServers=m-\\lceil R\\rceil\n\t\t\\end{equation}\n\t\n\t\\item [Mean Queue Time for M/G/m]\n\t\t\\begin{equation}\n\t\t\\expected{T_{Q}^{M/G/m}}\\approx\\Big(\\frac{C^{2}+1}{2}\\Big)\\expected{T_{Q}^{M/M/m}}\n\t\t\\end{equation}\n\t\t\n\t\\item [Worst-Case Competitive Ratio]\n\t\t\\begin{equation}\n\t\tCR_{\\mathcal{P}}=\\max_{\\mathcal{A}}r_{\\mathcal{P}}(\\mathcal{A})\n\t\t\\end{equation}\n\t\t\n\t\twith\n\t\t\n\t\t\\begin{equation}\n\t\tr_{\\mathcal{P}}(\\mathcal{A})=\\frac{\\expected{T(\\mathcal{A})}^{\\mathcal{P}}}{\\expected{T(\\mathcal{A})}^{\\mathcal{OPT}}}\n\t\t\\end{equation}\n\t\t\n\\end{description}\n\n\n\n\n\\subsection{Scheduling}\n\n\\begin{description}\n\n\t\\item [Slowdown]\n\t\t\\begin{equation}\n\t\tSlowdown=\\frac{T}{S}\n\t\t\\end{equation}\n\t\t\n\t\t\\begin{equation}\n\t\t\\expected{Slowdown(x)}=\\frac{\\expected{T(x)}}{x}\n\t\t\\end{equation}\n\t\t\n\t\t\\begin{equation}\n\t\t\\expected{Slowdown}=\\int_{x}\\frac{\\expected{T(x)}}{x}f_{S}(x)\\partial x\n\t\t\\end{equation}\n\t\t\n\t\\item [Fairness]\n\t\t\\begin{equation}\n\t\t\\expected{Slowdown^{\\mathit{P}}(x)}<\\expected{Slowdown^{\\mathit{PS}}(x)}\\quad\\forall x\n\t\t\\end{equation}\n\t\t\n\t\\item [Fairness]\n\t\t\\begin{equation}\n\t\t\\expected{Slowdown^{\\mathit{P}}(x)}>\\expected{Slowdown^{\\mathit{PS}}(x)}\\quad\\exists x\n\t\t\\end{equation}\n\t\t\n\t\\item [Starvation]\n\t\t\\begin{equation}\n\t\t\\exists x.\\expected{Slowdown^{\\mathit{P}}(x)}>\\expected{Slowdown^{\\mathit{PS}}(x)}\n\t\t\\end{equation}\n\t\t\n\t\\item [Response Time for M/G/1/FCFS]\n\t\t\\begin{equation}\n\t\t\\expected{T}=\\expected{S}+\\frac{\\lambda\\expected{S^{2}}}{2(1-\\varrho)}\n\t\t\\end{equation} \n\t\t\n\t\\item [Response Time for M/G/1/PS]\n\t\t\\begin{equation}\n\t\t\\expected{T(x)}^{\\mathit{M/G/1/PS}}=\\frac{x}{1-\\varrho}\n\t\t\\end{equation}\n\t\t\n\t\\item [Response Time for M/G/1/PLCFS]\n\t\t\\begin{equation}\n\t\t\\expected{T(x)}^{\\mathit{M/G/1/PLCFS}}=\\frac{x}{1-\\varrho}\n\t\t\\end{equation}\n\t\t\n\t\\item [Queue Time for M/G/1/FB]\n\t\t\\begin{equation}\n\t\t\\expected{T(x)}^{\\mathit{FB}}=\n\t\t\\frac{x(1-\\varrho_{\\overline{x}})+\\frac{1}{2}\\lambda\\expected{S_{\\overline{x}}^{2}}}\n\t\t\t{\\Big(1-\\varrho_{\\overline{x}}\\Big)^{2}}\n\t\t\\end{equation}\n\t\t\n\t\\item [Queue Time for M/G/1/SJF]\n\t\t\\begin{equation}\n\t\t\\expected{T_{Q}(x)}^{\\mathit{SJF}}=\n\t\t\\frac{\\varrho\\expected{S^{2}}}{2\\expected{S}}\\cdot\\frac{1}{\\Big(1-\\varrho_{x}\\Big)^{2}}\n\t\t\\end{equation}\n\t\t\n\t\twhere $\\varrho_{x}=\\lambda F(x)\\cdot\\int_{t=0}^{x}t\\frac{f(t)}{F(t)}\\partial t$ is the arrival rate of jobs of size no more than $x$, namely $\\lambda F(x)$, multiplied by the expected size of jobs of size no more than $x$, namely $\\int_{t=0}^{x}t\\frac{f(t)}{F(t)}\\partial t$.\n\t\t\n\t\\item [Response Time for M/G/1/PSJF]\n\t\t\\begin{equation}\n\t\t\\expected{T(x)}^{\\mathit{PSJF}}=\n\t\t\\expected{Res(x)}^{\\mathit{PSJF}}+\\expected{Wait(x)}^{\\mathit{PSJF}}=\n\t\t\\frac{x}{1-\\varrho_{x}}+\n\t\t\\frac{\\frac{\\lambda}{2}\\int_{0}^{x}f(t)t^{2}\\partial t}\n\t\t{\\Big(1-\\varrho_{x}\\Big)^{2}}\n\t\t\\end{equation}\n\t\twhere $\\varrho_{x}=\\lambda\\int_{t=0}^{x}tf(t)\\partial t$ is the load made up by jobs of size less than $x$.\n\t\n\t\\item [Response Time for M/G/1/SRPT]\n\t\t\\begin{equation}\n\t\t\\expected{T(x)}^{\\mathit{SRPT}}=\n\t\t\\expected{Wait(x)}^{\\mathit{SRPT}}+\\expected{Res(x)}^{\\mathit{SRPT}}=\n\t\t\\frac{\\lambda}{2}\\frac{\\int_{t=0}^{x}t^{2}f(t)\\partial t + x^{2}(1-F(x))}{\\Big(1-\\varrho_{x}\\Big)^{2}}+\n\t\t\\int_{t=0}^{x}\\frac{1}{1-\\varrho_{t}}\n\t\t\\end{equation}\n\t\t\n\t\\item [Relation between scheduling policies]\n\t\n\t\\begin{equation}\n\t\\expected{T(x)}^{\\mathit{SRPT}}\\leq\\expected{T(x)}^{\\mathit{PS}}\\quad \\forall x,\\forall\\varrho<\\frac{1}{2}\n\t\\end{equation}\n\t\n\t\\begin{equation}\n\t\\expected{T(x)}^{\\mathit{SRPT}}\\leq\\expected{T(x)}^{\\mathit{FB}}\n\t\\end{equation}\n\t\n\t\\begin{equation}\n\t\\expected{T^{\\mathit{FCFS}}}=\\expected{T^{\\mathit{LCFS}}}=\\expected{T^{\\mathit{RO}}}\n\t\\end{equation}\n\n\\end{description}", "meta": {"hexsha": "c6f1102762e5ac9f8506f231daf5bebfd57ce907", "size": 13581, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/formulary-queueing-theory.tex", "max_stars_repo_name": "gmarciani/research", "max_stars_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-07-27T13:31:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-20T12:54:12.000Z", "max_issues_repo_path": "performance-modeling/sec/formulary-queueing-theory.tex", "max_issues_repo_name": "gmarciani/research", "max_issues_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "performance-modeling/sec/formulary-queueing-theory.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 22.7869127517, "max_line_length": 277, "alphanum_fraction": 0.6191002135, "num_tokens": 5578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961707, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.71421554546146}}
{"text": "\\section{Surface traction}\n\\label{iso_section:surface_traction}\n\\paragraph{}\nIn structural analysis, it is common to have boundary conditions such as displacement constraints and applied loads.\nDue to the property of the NURBS that the control points are not necessarily on the curve, surface tractions can not be applied by the same method used in conventional numerical method like FEM or SBFEM.\nA surface traction $\\Phi$ can be regarded as a Neumann boundary condition which can be expressed as\n    \\begin{equation}\n        {F}=-\\int_{\\Gamma}\n        [N]\n        \\Phi_n\n        d\\Gamma\n    \\label{iso_eq:neumann_bc}\n    \\end{equation}\nwhere $[N]$ describe the shape functions and $\\Phi_n$ is the surface tractions on the nodes.\n\n\\paragraph{}\nAs mentioned in \\ref{iso_section:numerical_integration}, numerical integration would be preferred over mathematical deduction when the target function is an input.\nIn the flavour of numerical integration, Eq.~\\ref{iso_eq:neumann_bc} can be expressed as followed.\n    \\begin{equation}\n        {F}=-\\sum_{i=1}^n\n        a_i\n        [N(\\xi_i)]\n        \\Phi_n\n    \\label{iso_eq:neumann_bc_numerical}\n    \\end{equation}\nwhere $\\xi_i$ is the integration point and $a_i$ is the weight,\n$n$ is the number of integration points and different quadrature rules require different number of points in order to achieve an optimal accuracy.\n\n\\paragraph{}\nIt can be found that the term $[N(\\xi_i)] \\Phi_n$ is corresponding to $f(x)$ in Eq.~\\ref{iso_eq:numerical_integration}.\nIn conventional FEM or SBFEM, $\\Phi_n$ can be determined as the real values on the nodes because, geometrically speaking, its shape function is interpolated from the given set of points.\nIn other words, all nodes that determine the shape function in traditional FEM or SBFEM must be on the interpolating function.\nHowever, this is not the case in NURBS curves where it is the control points that play the same role as the nodes in existing shape function.\nIn NURBS curves, apart from the first and the last points, the control points are not necessarily on the curves as illustrated in Fig.~\\ref{lr_fig:nurbs_knotins}.\nThis prevent us from adopting the physical value on the nodes as $\\Phi_n$ in Eq.~\\ref{iso_eq:neumann_bc_numerical}.\nInstead, a set of ``control stress'' $\\Phi_c$, the control points of another NURBS curve that represent the surface traction geometrically, need to be determined as \n    \\begin{equation}\n        \\Phi_c = \\argmin_{\\Phi_c}\n            \\frac{1}{2}\n            \\int_{-1}^1\n            \\|\n                \\Phi(\\xi)-\n                    \\left[ N(\\xi) \\right]\n                    \\Phi_c\n            \\|^2\n            d\\xi            \n    \\label{iso_eq:surface_traction_fitting}\n    \\end{equation}\n%\nIt means that ``control stress'' $\\Phi_c$ describe a minimum mean squared error between surface traction NURBS curve and the real traction $\\Phi$.\nOne of the simplest mathematical method to determine $\\Phi_c$ will be the least square method.\nGiven the fact that the shape functions of this NURBS curve will be the same as that describe the geometry, $\\left[ N(\\xi) \\right]$ can be considered as known.\nBy selecting $n$ sample points over the domain of the $\\Phi$, Eq.~\\ref{iso_eq:surface_traction_fitting} can be rewrite as\n    \\begin{equation}\n        \\Phi_c = \\argmin_{\\Phi_c}\n            \\frac{1}{n}\n            \\sum_{i=1}^n\n            \\|\n                \\Phi(\\xi_i)-\n                    \\left[ N(\\xi_i) \\right]\n                    \\Phi_c\n            \\|^2\n    \\label{iso_eq:surface_traction_fitting_discrete}\n    \\end{equation}\nThen ``control stress'' $\\Phi_c$ can be solved by least square as\n    \\begin{equation}\n        \\Phi_c= \\left(\n            \\left[ N(\\xi) \\right] ^T\n            \\left[ N(\\xi) \\right]\n        \\right)^{-1}\n        \\left[ N(\\xi) \\right]^T\n        \\Phi(\\xi)\n    \\end{equation}\nand Eq.~\\ref{iso_eq:neumann_bc_numerical} in the case where NURBS is in use can be rewrite as\n    \\begin{equation}\n        {F}=-\\sum_{i=1}^n\n        a_i\n        [N(\\xi_i)]\n        \\Phi_c\n    \\label{iso_eq:neumann_bc_numerical_NURBS}\n    \\end{equation}\n", "meta": {"hexsha": "cd67fdb5becc60705d99dd8c860a9dcbbe1f7c1d", "size": 4086, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "isogeometric_sbfem/sbfem_surface_traction.tex", "max_stars_repo_name": "fa93hws/thesis", "max_stars_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-30T12:14:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-30T12:14:47.000Z", "max_issues_repo_path": "isogeometric_sbfem/sbfem_surface_traction.tex", "max_issues_repo_name": "fa93hws/thesis", "max_issues_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "isogeometric_sbfem/sbfem_surface_traction.tex", "max_forks_repo_name": "fa93hws/thesis", "max_forks_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.8292682927, "max_line_length": 203, "alphanum_fraction": 0.6749877631, "num_tokens": 1083, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.7142155371617491}}
{"text": "\\subsection{Problem Formulation}\nWe use TVM~\\cite{Chen18} to investigate the performance of matrix tiling for GEMM. TVM facilitates tiling optimization by generating Intermediate Representation (IR) of a particular configuration. Fig.~\\ref{fig:gemm_ir} is a simple example IR of GEMM tiling configuration with a blocking factor of 32 on x86 CPU for GEMM with $(m=1024, k=1024, n=1024)$ (short as $(1024,1024,1024)$).\n\\begin{figure}[htb]\n    \\centering\n    \\includegraphics[width=3in]{3_GEMM_backgrounds/gemm_ir.png}\n    \\caption{IR of GEMM with a blocking factor of 32}\n    \\label{fig:gemm_ir}\n\\end{figure}\n\n% \\begin{definition}\n\\noindent\n\\textbf{Definition:}\nGenerally, a GEMM tiling configuration can be defined as \n\\begin{equation}\n    \\overrightarrow{\\xi} = \\overrightarrow{\\xi_m} \\times \\overrightarrow{\\xi_k} \\times \\overrightarrow{\\xi_n},\n\\end{equation}\nwhere\n\\begin{equation}\n     \\overrightarrow{\\xi_m} =\\{ \\left[m_0,\\ldots,m_i, \\ldots m_{d_m-1} \\right] |  \\Pi_{i=0}^{d_m-1} m_i=m \\},\n\\end{equation}\n\\begin{equation}\n     \\overrightarrow{\\xi_k} =\\{ \\left[k_0,\\ldots,k_l, \\ldots k_{d_k-1} \\right] |  \\Pi_{l=0}^{d_k-1} k_l=k \\},\n\\end{equation}\n\\begin{equation}\n     \\overrightarrow{\\xi_n} =\\{ \\left[n_0,\\ldots,n_j, \\ldots n_{d_n-1} \\right] |  \\Pi_{j=0}^{d_n-1} n_j=n \\}.\n\\end{equation}\n% \\end{definition}\nMultiplication of two matrices $A(m\\times k)$ and $B(k\\times n)$ produces matrix $C(m\\times n)$. $d_m$, $d_k$ and $d_n$ are the number of nested loops for each dimension $m$, $k$ and $n$, respectively.  $m_i, k_l, n_j$, $\\forall i \\in [0, d_m)$ $\\forall l \\in [0, d_k)$ $\\forall j \\in [0, d_n)$, are the number of iterations of a respective loop. The configuration in Fig.~\\ref{fig:gemm_ir} is $m_0=m_1=32$, $k_0=256, k_1=4$, $n_0=n_1=32$, and $d_m=d_k=d_n=2$.\n\nConstrained by the definition of tiling configuration, we can formulate the following optimization problem:\n\\begin{equation}\\nonumber\n    \\begin{array}{l}\n       \\mathop {\\min }\\limits_{s} T_{cost}(s ; m,k,n,d_m,d_k,d_n).\n    \\end{array}\n\\end{equation}\nThe objective function of this problem is to find an optimal tiling configuration that has minimal running time on target hardware. $T_{cost}$ denotes the running time for the configuration $s$, given the dimension of matrices as $m,k,n$ and the number of the nested loops on each dimension as $d_m, d_k, d_n$. \n\n%In our experiments, we run GEMM tiling configurations on Nivida CUDA GPU, more specifically $d_m=4$, $d_k=2$ and $d_n=4$.", "meta": {"hexsha": "4bc6ba9bee60f2dc70ad788f93ba089eb0b8026f", "size": 2462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3_GEMM_backgrounds/problem_formula.tex", "max_stars_repo_name": "markjunior/icml2019_gemm", "max_stars_repo_head_hexsha": "67cf41f02fba4f8d638e47ab6407a7579f757679", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3_GEMM_backgrounds/problem_formula.tex", "max_issues_repo_name": "markjunior/icml2019_gemm", "max_issues_repo_head_hexsha": "67cf41f02fba4f8d638e47ab6407a7579f757679", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3_GEMM_backgrounds/problem_formula.tex", "max_forks_repo_name": "markjunior/icml2019_gemm", "max_forks_repo_head_hexsha": "67cf41f02fba4f8d638e47ab6407a7579f757679", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.7894736842, "max_line_length": 460, "alphanum_fraction": 0.708773355, "num_tokens": 837, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7142155307253468}}
{"text": "\\chapter{Efficient Backpropagation for Convolutional Neural Networks}\n\n{\\bf Structure of CNN}.\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.7]{CNN}\n\\caption{Convolutional Neural Network}\n\\end{figure}\nA convolutional neural network (CNN) consists of three types of layers: \\textit{full-connected layers, convolutional layers, and pooling layers}. Fully-connected layers are defined in the same way as a layer in the basic neural network model. Convolutional layers and pooling layers are unique to CNN. A convolution layer in CNN is a composition of two functions: $f^{conv}$ and ${\\bm\\sigma(x)}$ representing \\textit{quasi-convolution} and \\textit{activation function} separately. A pooling layer is represented by $f^{pool}$, the \\textit{pooling function}. We will provide definitions to these terminologies and function in the following sections.\n\n\\section{Basic Tensor Notations}\n\n{\\bf Tensor}\n\\begin{itemize}\n\\item\nDefinition of tensor: an multi-dimensional array $\\mathcal{F}\\in\\mathbb{R}^{n_1\\times n_2\\times\\cdots\\times n_d}$.\n\\item\nElement-wise representation: \n$$\n\\mathcal{F}(i_1,...,i_d)\\in\\mathbb{R}, i_j=0,...,n_j-1, j=1,...,d.\n$$\n\\item\nFiber: mode-1 tensor (vector) obtained by fixing every index but one.\n\\item\nSlice: mode-2 tensor (matrix) obtained by fixing every index but two.\n\\item\nTensor Norm: \n$$\n\\|\\mathcal{F}\\| := \\sqrt{\\sum_{i_1=1}^{I_1}\\cdots\\sum_{i_N=1}^{I_N} \\mathcal{F}(i_1,...,i_N)^2}\n$$\n\\end{itemize}\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.5]{fiber}\n\\end{figure}\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.5]{slice}\n\\end{figure}\n\n{\\bf Matricization}.\nThe mode-$k$ matricization of a tensor $\\mathcal{X}\\in\\mathbb{R}^{n_1\\times n_2\\times\\cdots\\times n_d}$ is denoted by $X_{(k)}$ and arranges the mode-$k$ fibers to be the columns of the resulting matrix. Under matricization, the tensor element $\\mathcal{X}(i_1,...,i_d)$ is mapped to matrix element $\\big(\\bm{X_{(k)}}\\big)(i_k,j)$, where\n\\begin{equation}\nj = \\sum_{1\\le s\\le d, s\\neq k}\\big(i_s\\prod_{1\\le t\\le s-1, t\\neq k}n_t\\big)\n\\end{equation}\nAn example is given in Figure \\ref{fmat}.\n\\begin{figure}[H]\\label{fmat}\n\\centering\n\\includegraphics[scale=0.6]{metricization}\n\\caption{Tensor Matricization}\n\\end{figure}\n\n%{\\bf Tensor-Matrix Multiplication}\nTucker decomposition is best illustrated through \\textit{tensor-matrix multiplication}. A product of a tensor $\\mathcal{X}$ and a matrix $ M=\\big(m_{ij}\\big)_{i,j}$ on the $k$-th mode is a tensor defined as:\n\\begin{equation}\n    \\big(\\mathcal{X}\\times_kM\\big)[i_1,...,i_n] = \n    \\sum_j \\mathcal{X}[i_1,...,i_{k-1},j,i_{k+1},...,i_n]m_{ji_k}.\n\\end{equation}\n$M\\times_k\\mathcal{X}$ can be defined similarly as\n\\begin{equation}\n    \\big(M\\times_k\\mathcal{X}\\big)[i_1,...,i_n] = \n    \\sum_j m_{i_kj}\\mathcal{X}[i_1,...,i_{k-1},j,i_{k+1},...,i_n]m_{i_kj}.\n\\end{equation}\nThe following properties are easily provable:\n\\begin{lemma}\n[Tensor-Matrix Multiplication]\n\\begin{equation}\n\\aligned\n&(\\mathcal{X}\\times_k M)\\times_l N = (\\mathcal{X}\\times_l N)\\times_k M =: \\mathcal{X}\\times_k M\\times_l N\\\\\n&(\\mathcal{X}\\times_k M)\\times_k N = \\mathcal{X}\\times_k(M\\cdot N)\n\\endaligned\n\\end{equation}\n\\end{lemma}\n\n{\\bf Tensor Multiplication}.\nGiven $\\mathcal{F}\\in\\mathbb{R}^{n_1\\times\\cdots\\times n_{d_1}}$, $\\mathcal{G}\\in\\mathbb{R}^{n_1\\times\\cdots\\times n_{d_2}}$, and a mode $k\\in\\{1,...,\\min(d_1,d_2)\\}$, the \\textit{tensor multiplication on mode $k$} is a tensor such that\n\\begin{equation}\n\\aligned\n&\\big(\\mathcal{F}\\times_k\\mathcal{G}\\big)(i_1,...,i_{k-1},i_{k+1},...,i_{d_1},j_1,...,j_{k-1},j_{k+1},...,j_{d_2}) \\\\\n=& \\sum_l \\mathcal{F}(i_1,...,i_{k-1},l,i_{k+1},...,i_{d_1})\\mathcal{G}(j_1,...,j_{k-1},l,j_{k+1},...,j_{d_2}).\n\\endaligned\n\\end{equation}\nNote that the definition of tensor multiplication can be extended to multiplication on multiple modes.\n\n\\section{Quasi-Convolution in CNN}\nThe mathematical convolution is a operation on two functions ($f$ and $g$); it produces a third function, that is typically viewed as a modified version of one of the original function.\n\n\\begin{itemize}\n\\item\nContinuous convolution\n$(f*g)(x) := \\int_{-\\infty}^{\\infty}f(t)g(x-t)dt$\n\\item\nDiscrete convolution\n$(f*g)[n] := \\sum_{-\\infty}^\\infty f[m]g[n-m]$\n%\\item\n%Two-Dimensional convolution\n%$(F*G)[i,j] := \\sum_{s = -\\infty}^\\infty\\sum_{t = -\\infty}^\\infty F[s, t]G[i-s, j-t]$\n\\item \nd-Dimensional convolution\n$$(\\mathcal{F}\\ast \\mathcal{G})(i_1, i_2, \\cdots ,i_d) = \\sum_{j_i, j_2,\\cdots,j_d \\in \\mathbb{Z}} \\mathcal{F}(j_1, j_2,\\cdots,j_d)\\mathcal{G}(i_1 - j_1, i_2 - j_2, \\cdots, i_d - j_d)$$\n\\end{itemize}\n\n\\begin{lemma}[Commutativity of Tensors]\\label{lconv}\n$\\mathcal{F}\\ast \\mathcal{G} = \\mathcal{G}\\ast \\mathcal{F}$.\n\\end{lemma}\n\nThe convolution of two finite-dimensional tensors is defined by extending the sequences to finitely supported functions on the set of integers. In order to understand the computation of a convoltional layer, we need to define a \\textit{reversed tensor} and a \\textit{quasi-convolution}. A reversed tensor $rev(\\mathcal{F})$ of a tensor $\\mathcal{X}$ is a tensor with elements in the reversed order, namely\n\\begin{equation}\\label{erevt}\nrev(\\mathcal{F})(i_1,i_2,...,i_d) := \\mathcal{F}(-i_1,-i_2,...,-i_d), i_1,...,i_d\\in\\mathbb{Z}.\n\\end{equation}\n\nMoreover, for two tensors $\\mathcal{F}\\in\\mathcal{R}^{n_1\\times\\cdots\\times n_d}$ and $\\mathcal{G}\\in\\mathcal{R}^{m_1\\times\\cdots\\times m_d}$ with $n_1\\ge m_1,...,n_d\\ge m_d$, we define a \\textit{quasi-convolution} $\\mathcal{F}\\odot\\mathcal{G}$ as a truncated convolution of $\\mathcal{F}$ and $rev(\\mathcal{G})$:\n\\begin{equation}\n\\label{eqconv}\n\\mathcal{F}\\odot\\mathcal{G} := \\big(\\mathcal{G}\\ast rev(\\mathcal{F})\\big)(0:(n_1-m_1), 0:(n_2-m_2),...,0:(n_d-m_d))\\in\\mathbb{R}^{(n_1-m_1+1)\\times\\cdots\\times(n_d-m_d+1)}.\n\\end{equation}\n\\begin{lemma}\n\\label{lqconv}\nLet $\\mathcal{F}\\in\\mathcal{R}^{n_1\\times\\cdots\\times n_d}$ and $\\mathcal{G}\\in\\mathcal{R}^{m_1\\times\\cdots\\times m_d}$ with $n_1\\ge m_1,...,n_d\\ge m_d$. Then their quasi-convoltion $\\mathcal{H}:=\\mathcal{F}\\odot\\mathcal{G}$ can be computed as\n\\begin{equation}\n\\mathcal{H}(i_1,...,i_d) =\n\\sum_{0\\le j_1\\le m_1-1}\\cdots\\sum_{0\\le j_d\\le m_d-1}\\big(\\mathcal{F}(i_1+j_1,...,i_d+j_d)\\mathcal{G}(j_1,...,j_d)\\big).\n\\end{equation}\n\\end{lemma}\nIn CNN, the input of a convolutional layer is a 3-mode tensor $\\mathcal{X}\\in\\mathbb{R}^{n_1\\times n_2\\times n_3}$, usually visualized as a collection of $n_3$ matrices of size $n_1\\times n_2$. Each such matrix is refered to as an \\textit{input channel}. The kernels of a convolutional layer forms a 4-mode tensor $\\mathcal{K}\\in\\mathbb{R}^{d\\times d\\times n_3\\times n_4}$. The function is defined as a quasi-convolution\n\\begin{equation}\n\\label{econv}\n\\aligned\nf^{conv}(\\mathcal{X}, \\mathcal{K}) =& \\mathcal{Y}\\in\\mathbb{R}^{(n_1-d+1)\\times (n_2-d+1)\\times n_4},\\\\\n\\mathcal{Y}(:,:,l) :=& \\big(\\mathcal{X}\\odot\\mathcal{K}(:,:,:,l)\\big)(:,:,0).\n\\endaligned\n\\end{equation}\n\\begin{lemma}[Express $f^{conv}$ through 2D-convolutions]\nLet $\\mathcal{X}\\in\\mathbb{R}^{n_1\\times n_2\\times n_3}$, $\\mathcal{K}\\in\\mathbb{R}^{d\\times d\\times n_3\\times n_4}$, and $f^{conv}(\\mathcal{X}, \\mathcal{K}) = \\mathcal{Y}\\in\\mathbb{R}^{(n_1-d+1)\\times (n_2-d+1)\\times n_4}$. Then\n\\begin{equation}\n\\label{e2dconv}\n\\mathcal{Y}(:,:,l) = \\sum_{k=0}^{n_3-1}\\big(\\mathcal{X}(:,:,k)\\odot\\mathcal{K}(:,:,k,l)\\big).\n\\end{equation}\nA slice $\\mathcal{Y}(:,:,l)$ is sometimes called a \\textit{feature map}.\n\\end{lemma}\n\n\nTwo-dimensional quasi-convolution can be visualized as in Figure \\ref{fconv}. Here the kernel slides though the entire input matrix.\n\\begin{figure}[ht]\n\\label{fconv}\n\\centering\n\\includegraphics[scale=0.4]{Convolution1}\n\\caption{Convolution in CNN}\n\\end{figure}\n\n\n\\section{Convolution via Fast Fourier Transform}\n\n{\\bf Discrete Fourier Transform (DFT)}. For a positive integer $n$, the \\textit{Fourier transform matrix of degree $n$} is define as the following $n\\times n$ matrix\n\\begin{equation}\n\\Omega_n:=\\big(\\omega_n^{-ij}\\big)_{i,j}=\\frac{1}{\\sqrt{n}}\\left[\n\\begin{array}{cccc}\n\\omega_n^0 & \\omega_n^0 & \\cdots & \\omega_n^0\\\\\n\\omega_n^0 & \\omega_n^{-1} & \\cdots & \\omega_n^{-(n-1)}\\\\\n\\vdots\t& \\vdots & & \\vdots\\\\\n\\omega_n^0 & \\omega_n^{-(n-1)} & \\cdots & \\omega_n^{-(n-1)^2}\n\\end{array}\n\\right],\n\\end{equation}\nwhere $\\omega_n = exp(\\frac{2\\pi i}{n})$. For an $n$-dimensional vector $\\bm v = (v_0,...,v_{n-1})$, its \\textit{discrete Fourier transform} is defined as \n\\begin{equation}\nfft(\\bm v):=\\Omega_n\\bm v.\n\\end{equation}\nSimilarly, for an $m\\times n$ matrix $X$, its \\textit{2-dimensional discrete Fourier transform} is defined as\n\\begin{equation}\n2Dfft(X):= \\Omega_m X \\Omega_n.\n\\end{equation}\nWe have the following lemma for the inverse of Fourier transform.\n\\begin{lemma}\nThe inverse of 1D DFT is:\n\\begin{equation}\nifft(\\bm v) = \\Omega^{-1}\\bm v = \\Omega^H\\bm v.\n\\end{equation}\nThe inverse of 2D DFT is:\n\\begin{equation}\n2Difft(X) = \\Omega_m^{-1} X \\Omega_n^{-1} = \\Omega_m^H X \\Omega_n^H.\\\n\\end{equation}\nHere $X^H$ denotes the hermitian transpose.\n\\end{lemma}\n\n{\\bf DFT and convolution}. Discrete convolution can be achieved by DFT, element-wise multiplication, and inverse DFT.\n\\begin{lemma}\nLet $F, G\\in\\mathbb{R}^{n_1\\times n_2}$, then\n\\begin{equation}\n(F\\ast G) = 2Difft(2Dfft(F)\\circ 2Dfft(G)).\n\\end{equation}\nHere $\\circ$ denotes matrix element-wise multiplication.\n\\end{lemma}\n\n{\\bf Fast Fourier transform (FFT)}.\nFor $n=2^h$, the matrix-vector multiplication $\\Omega_n\\bm v$ has complexity $O(n\\log n)$ if one applies the following lemma recursively:\n\\begin{lemma}\nLet $h\\ge 1$ be an integer, $n=2^h$, $\\omega_n=exp(\\frac{2\\pi i}{n})$, and $D = diag(1, \\omega,...,\\omega^{2^{h-1}-1})$. Then\n\\begin{equation}\n\\Omega_n = \\left[\n\\begin{array}{cc}\nI_{n/2} & \\\\\n & D\n\\end{array}\n\\right]\\cdot\n\\left[\n\\begin{array}{cc}\nI_{n/2} & I_{n/2}\\\\\nI_{n/2} & -I_{n/2}\n\\end{array}\n\\right]\\cdot\n\\left[\n\\begin{array}{cc}\n\\Omega_{n/2} &\\\\\n & \\Omega_{n/2}\n\\end{array}\n\\right].\n\\end{equation}\n\\end{lemma}\nBy applying this \"divide-and-conquer\" method, the complexity of 1D DFT and 2D DFT can be reduced to $O(n\\log n)$ and $O(mn\\log m\\log n)$, respectively. Later in this chapter we will show that FFT can be used to accelerate the training of CNN.\n\n\\section{Pooling Layer}\n\n{\\bf Pooling layer}. Pooling layer subsamples statistics to obtain summary statistics that are invariant to shifts and distortions in some degree. More precisely we have\n\\begin{equation}\nf^{pool}(\\mathcal{X}(:,:,l))(i,j) = f(\\mathcal{X}(2i-1:2i,2j-1:2j,l)),\n\\end{equation} \nwhere commonly used functions $f$ are\n\\begin{enumerate}\n\\item\nMean pooling: $f^{mean}(\\mathcal{Z})=\\big(\\frac{\\sum_k z_k}{m}\\big)$\n\\item\nMax pooling: $f^{max}(\\mathcal{Z})=\\big(\\max_k\\{z_k\\}\\big)$\n\\item\n$l^p$ pooling: $f^{lp}(\\mathcal{Z})=\\big(\\|(z_1,...,z_m)\\|_p\\big)$\n\\end{enumerate}\nThe partial derivative of the pooling function is usually called the \\textit{upsample} function $f^{upsample}$. For example. for the max pooling function, the corresponding upscale function is $\\mathbbm{1}_{z = \\max_k\\{z_k\\}}$ (distributing the gradient to the entry with maximum value). \n\nFigure \\ref{ffea} illustrates features extracted the first three convolutional Layers  on a facial recognition task.\n\n\\begin{figure}[ht]\n\\label{ffea}\n\\centering\n\\includegraphics[scale=1]{Features}\n\\caption{Features}\n\\end{figure}\n\n\\section{Training CNN}\nFor simplicity, assume that there are no fully-connected layers and there are $D$ convolutional layers and $D$ pooling layers in the CNN model with $f^{conv}$ and $f^{pool}$ defined as in the previous sections. Choose an activation function $\\sigma$. Let $S=\\{(\\mathcal{X}^1, \\mathcal{Y}^1),...,(\\mathcal{X}^N, \\mathcal{Y}^N)\\}$ be the training data set. For $(\\mathcal{X}, \\mathcal{Y})\\in S$, the feedforward process $f(\\mathcal{X};\\mathcal{K}_1,...,\\mathcal{K}_D)$ can be described progressively as\n\\begin{equation}\n\\aligned\n\\mathcal{X}_1 =& \\mathcal{X}\\\\\n\\mathcal{Y}_{i}(\\mathcal{X};\\mathcal{K}_1,...,\\mathcal{K}_i) :=& f^{conv}(\\mathcal{X}_i(\\mathcal{X};\\mathcal{K}_1,...,\\mathcal{K}_{i-1}), \\mathcal{K}_i)\\\\\n\\mathcal{Z}_i(\\mathcal{X};\\mathcal{K}_1,...,\\mathcal{K}_i) :=& \\bm\\sigma(\\mathcal{Y}_{i}(\\mathcal{X};\\mathcal{K}_1,...,\\mathcal{K}_i))\\\\\n\\mathcal{X}_{i+1}(\\mathcal{X};\\mathcal{K}_1,...,\\mathcal{K}_i) :=& f^{pool}(\\mathcal{Z}_i(\\mathcal{X};\\mathcal{K}_1,...,\\mathcal{K}_i)), i=1,...,D\\\\\nf(\\mathcal{X};\\mathcal{K}_1,...,\\mathcal{K}_D):=&\\mathcal{X}_{D+1}(\\mathcal{X};\\mathcal{K}_1,...,\\mathcal{K}_D).\n\\endaligned\n\\end{equation}\n\nThen choose a loss function $L(\\mathcal{X},\\mathcal{Y};\\mathcal{K}_1,...,\\mathcal{K}_D)$. The goal of training is to minimize the total loss \n\\begin{equation}\nL_{total}(\\mathcal{K}_1,...,\\mathcal{K}_D) = \\sum_{i=1}^N L(\\mathcal{X}^i,\\mathcal{Y}^i;\\mathcal{K}_1,...,\\mathcal{K}_D)\n\\end{equation}\nIn order to reduce the number of computations, the \\textit{stochastic gradient descent} method samples a subset $S'$ of $S$ (called \\textit{mini-batch}) with $|S'|\\ll |S|$ and use the following loss function to approximate $L_{total}$:\n\n\\begin{equation}\nL_{SGD}(\\mathcal{K}_1,...,\\mathcal{K}_D) = \\sum_{(\\mathcal{X},\\mathcal{Y})\\in S'} L(\\mathcal{X},\\mathcal{Y};\\mathcal{K}_1,...,\\mathcal{K}_D)\n\\end{equation}\nThe gradient of $L_{SGD}$ is the sum of all the corresponding gradients of $L(\\mathcal{X},\\mathcal{Y})$. \n\n\\begin{figure}[ht]\\label{fcnnbp}\n\\includegraphics[scale=0.5]{CNNBP}\n\\caption{Convolutional Layer}\n\\end{figure}\n\nThe backpropagation process can be described as (see Figure \\ref{fcnnbp}):\n\\begin{equation}\n\\aligned\n\\delta_{D+1} :=& \\frac{\\partial L}{\\partial \\mathcal{X}_{D+1}}\\\\\n\\delta_i^{pool} :=&\\frac{\\partial L}{\\partial \\mathcal{Z}_i} = \\delta_{i+1}\\times_{1,2,3}\\frac{\\partial \\mathcal{X}_{i+1}}{\\partial \\mathcal{Z}_i}=\\delta_{i+1}\\circ f^{upsample}(\\mathcal{X}_{i+1})\\\\\n\\delta_i^{sig}:=&\\frac{\\partial L}{\\partial \\mathcal{Y}_i} = \\delta_i^{pool}\\times_{1,2,3}\\frac{\\partial \\mathcal{Z}_i}{\\partial \\mathcal{Y}_i}=\\delta_i^{pool}\\circ\\bm\\sigma'(\\mathcal{Y}_i)\\\\\n\\delta_i :=&\\frac{\\partial L}{\\partial \\mathcal{X}_i}= \\delta_i^{sig}\\times_{1,2,3}\\frac{\\partial \\mathcal{Y}_i}{\\partial \\mathcal{X}_i}\\\\\n\\delta_i(:,:,l) =& \\sum_k \\delta_i^{sig}\\ast\\mathcal{K}_i(:,:,k,l)\\\\\n\\frac{\\partial L}{\\partial\\mathcal{K}_i} =& \\frac{\\partial L}{\\partial \\mathcal{Y}_i}\\times_{1,2,3}\\frac{\\partial \\mathcal{Y}_i}{\\partial \\mathcal{K}_i}\\\\\n\\frac{\\partial L}{\\partial\\mathcal{K}_i}(:,:,k,l) =& \\mathcal{X}_i(:,:,k)\\odot \\delta_i^{sig}(:,:,l)\n, i=D,D-1,...,1\n\\endaligned\n\\end{equation}\n\n%To backpropagate through one convolutional layer and one pooling layer, one need to compute the derivative of three functions:\n%\\begin{equation}\n%\\aligned\n%\\bm\\delta^{conv}_{ikl} =& \\frac{\\partial L}{\\partial x_{ikl}} =\n%\\sum_{j,k,l}\\frac{\\partial L}{\\partial y_{jkl}}\\frac{\\partial y_{jkl}}{\\partial x_{ikl}} = \\sum_{k,l=0}^{r-1}\\bm\\delta^{sig}_{ikl}\\\\\n%\\bm\\delta^{sig}_{jkl} =& \\frac{\\partial L}{\\partial y_{jkl}} = \\sigma'(y_{jkl})\\\\\n%\\bm\\delta^{pool}_{jkl} =& \\frac{\\partial L}{\\partial z_{jkl}} = \\frac{\\partial L}{\\partial x^{next}_{jkl}}\\frac{\\partial x^{next}_{jkl}}{\\partial z_{jkl}} = \\bm\\delta^{next, conv}_{jkl}\\\\\n%\\frac{\\partial L}{\\partial f_{ijkl}} =& \\sum_{j,k,l}\\frac{\\partial L}{\\partial y_{jkl}}\\frac{\\partial y_{jkl}}{\\partial f_{ijkl}}=\\sum_{s,t=0}^{d-1}\\bm\\delta^{sig}_{jst}x_{i, s+k, t+l}\n%\\endaligned\n%\\end{equation}\nFinally, the kernels are updated by the gradient as\n\\begin{equation}\n\\mathcal{K}_i \\leftarrow \\mathcal{K}_i - \\eta\\frac{\\partial L}{\\partial\\mathcal{K}_i}.\n\\end{equation}\nNote that the complexity of the training process is dominated by the convolution operation in the forward and backward passes.\n\n\n\\section{FFT Based Backpropagation}\n\nRecall that convolution is equivalent to element-wise product in the Fourier form. Typically, this method is used when the size of the convolution kernel is close to that of the input image. Note that a convolution of an image of size $n\\times n$ with a kernel of size $d\\times d$ using the direct method requires $(n - d + 1)^2d^2$\n operations. The complexity of the FFT-based method requires $(6Cn^2\\log n+4n^2)$ operations. Here $C$ represents the constant overhead of FFT. Thus it is not preferable to use FFT for a single convolution in CNN training.\n \nHowever, notice that each channel $\\mathcal{X}(:,:,l)$ and each 2D kernel $\\mathcal{K}(:,:,k,l)$ appears in $2n$ different convolutions in a forward pass and a backward pass, and one single FFT is sufficient for each matrix. Also notice that from equation (10) only the summation is needed, rather than the convolution results for each summand, suggesting that one can take the sum first and then perform the inverse FFT. Under these two considerations, the total complexity of the training process with FFT is lower than the direct convolution computation.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{FFTconv}\n\\caption{Illustration of the FFT based convolution}\n\\end{figure}\n\n% {\\bf Other Implementation Details(future topics)}\n% \\begin{itemize}\n% \\item Random sampling\n% \\item Normalizing the inputs\n% \\item Choice of activation function\n% \\item Choosing target values\n% \\item Initialization\n% \\item Adaptive learning rates\n%\\end{itemize}\n", "meta": {"hexsha": "8c38aae8a9d821c1dfeb2d5eac4be34b60ac0cc0", "size": 17132, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/EfficientBackpropagationforConvolutionalNeuralNetworkLiangZhao0315.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/EfficientBackpropagationforConvolutionalNeuralNetworkLiangZhao0315.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/EfficientBackpropagationforConvolutionalNeuralNetworkLiangZhao0315.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.0729483283, "max_line_length": 648, "alphanum_fraction": 0.6979336913, "num_tokens": 6162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7142091317176039}}
{"text": "\\subsection{Enumerative combinatorics}\\label{subsec:enumerative_combinatorics}\n\nThis subsection lists several results of various importance that don't really belong to any more consistent theory.\n\n\\begin{theorem}[Dirichlet's pigeonhole principle]\\label{def:pigeonhole_principle}\n  If we are given more pigeons than pigeonholes, then at least one pigeonhole must contain multiple pigeons in it.\n\n  More formally, if \\( \\card(A) > \\card(B) \\), then there exists no injective function from \\( A \\) to \\( B \\).\n\\end{theorem}\n\\begin{proof}\n  This is a corollary of \\fullref{thm:set_domination_relation_trichotomy}.\n\\end{proof}\n\n\\begin{definition}\\label{def:binomial_coefficient}\n  The \\term{binomial coefficient} of the \\hyperref[def:integer_signum]{nonnegative integers} \\( n \\) and \\( k \\) is\n  \\begin{equation*}\n    \\binom n k \\coloneqq \\frac {n!} {k!(n-k)!}\n  \\end{equation*}\n\n  They are motivated by \\fullref{thm:binomial_theorem}.\n\\end{definition}\n\n\\begin{theorem}[Pascal's identity]\\label{thm:pascals_identity}\n  \\hyperref[def:binomial_coefficient]{Binomial coefficients} have the following property:\n  \\begin{equation}\\label{eq:thm:pascals_identity}\n    \\binom n k = \\binom {n - 1} k + \\binom {n - 1} {k - 1}.\n  \\end{equation}\n\\end{theorem}\n\\begin{proof}\n  \\begin{balign*}\n    \\binom {n - 1} k + \\binom {n - 1} {k - 1}\n    &=\n    \\frac {(n - 1)!} {k! (n - 1 - k)!} + \\frac {(n - 1)!} {(k - 1)! (n - k)!}\n    = \\\\ &=\n    \\frac {(n - 1)!} {(k - 1)! (n - 1 - k)!} \\bracks*{ \\frac 1 k + \\frac 1 {n - k} }\n    = \\\\ &=\n    \\frac {(n - 1)!} {(k - 1)! (n - 1 - k)!} \\frac n {k(n - k)}\n    = \\\\ &=\n    \\frac {n!} {k! (n - k)!}\n    = \\\\ &=\n    \\binom n k.\n  \\end{balign*}\n\\end{proof}\n\n\\begin{theorem}[Newton's binomial theorem]\\label{thm:binomial_theorem}\n  If, in some \\hyperref[def:semiring]{semiring}, the members \\( x \\) and \\( y \\) commute (i.e. \\( xy = yx \\)), then\n  \\begin{equation}\\label{eq:thm:binomial_theorem}\n    (x + y)^n = \\sum_{k=0}^n \\binom n k x^k y^{n-k}.\n  \\end{equation}\n\\end{theorem}\n\\begin{proof}\n  We use induction on \\( n \\). For \\( n = 0 \\), the theorem trivially holds. Assume that the theorem holds for \\( 1, \\ldots, n \\). Then\n  \\begin{balign*}\n    (x + y)^{n+1}\n     & =\n    x (x + y)^n + y (x + y)^n\n    = \\\\ &=\n    \\sum_{k=0}^n \\binom n k x^{k+1} y^{n-k} + y \\sum_{k=0}^n \\binom n k x^k y^{n-k}\n    = \\\\ &=\n    x^{n+1} + y \\sum_{k=0}^{n-1} \\binom n k x^{k+1} y^{n-(k+1)} + y \\sum_{k=0}^n \\binom n k x^k y^{n-k}\n    = \\\\ &=\n    x^{n+1} + y \\parens*{ \\sum_{k=1}^n \\binom n {k-1} x^k y^{n-k} + y^n \\sum_{k=1}^n \\binom n k x^k y^{n-k} } + y^{n+1}\n    = \\\\ &\\reloset {\\eqref{eq:thm:pascals_identity}} =\n    x^{n+1} + y \\sum_{k=1}^n \\binom {n+1} k x^k y^{n-k} + y^{n+1}\n    = \\\\ &=\n    \\sum_{k=0}^n \\binom {n+1} k x^k y^{(n+1)-k}.\n  \\end{balign*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:xn_minus_yn_factorization}\n  For every \\hyperref[def:ring]{ring} element \\( x \\) and every nonnegative integer \\( n \\), we have\n  \\begin{equation}\\label{eq:thm:xn_minus_yn_factorization}\n    x^{n + 1} - y^{n + 1} = (x - y)(x^n + x^{n-1} y + \\cdots + y^n) = (x - y) \\sum_{k=0}^n x^k y^{n-k}.\n  \\end{equation}\n\\end{proposition}\n\\begin{proof}\n  \\begin{align*}\n    (x - y) \\sum_{k=0}^n x^k y^{n-k}\n    &=\n    \\sum_{k=0}^n x^{k+1} y^{n-k} - \\sum_{k=0}^n x^k y^{n-k+1}\n    = \\\\ &=\n    \\sum_{k=1}^{n+1} x^k y^{(n+1)-k} - \\sum_{k=0}^n x^k y^{(n+1)-k}\n    =\n    x^{n+1} - y^{n+1}.\n  \\end{align*}\n\\end{proof}\n\n\\begin{definition}\\label{def:factorial}\n  The \\term{factorial} of a \\hyperref[def:integer_signum]{nonnegative integer} \\( n \\) is defined recursively as\n  \\begin{equation*}\n    n! \\coloneqq \\begin{cases}\n      1,          &n = 0 \\\\\n      (n - 1)! n, &n > 0.\n    \\end{cases}\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:gamma_function_interpolates_factorial}\n  For every \\hyperref[def:integer_signum]{nonnegative integer} \\( n \\) we have\n  \\begin{equation*}\n    \\Gamma(n + 1) \\coloneqq n!,\n  \\end{equation*}\n  where \\( \\Gamma \\) is the Gamma function defined in \\fullref{def:gamma_function}.\n\\end{proposition}\n\\begin{proof}\n  We use induction on \\( n \\).\n  \\begin{itemize}\n    \\item If \\( n = 0 \\), then\n    \\begin{equation*}\n      \\Gamma(1)\n      =\n      \\int_0^\\infty x^0 e^{-x} \\dl x\n      =\n      -e^{-x}\\restr_{x=0}^\\infty\n      =\n      -\\underbrace{\\lim_{x \\to \\infty} e^{-x}}_{0} + 1\n      =\n      1\n      =\n      0!\n    \\end{equation*}\n\n    \\item If \\( n > 0 \\) and \\( \\Gamma(n) = (n - 1)! \\), then\n    \\begin{balign*}\n      \\Gamma(n + 1)\n      &=\n      \\int_0^\\infty x^n \\cdot e^{-x} \\dl x\n      = \\\\ &=\n      \\underbrace{(- x^n e^{-x})\\restr_{x=0}^\\infty}_{-(0 - 0)} + n \\int_0^\\infty e^{-x} x^{n-1} \\dl x\n      = \\\\ &=\n      n \\Gamma(n)\n      = \\\\ &=\n      n (n - 1)!\n      = \\\\ &=\n      n!\n    \\end{balign*}\n  \\end{itemize}\n\\end{proof}\n\n\\begin{theorem}[Stirling's factorial approximation]\\label{thm:stirlings_factorial_approximation}\n  For every \\hyperref[def:integer_signum]{nonnegative integer} \\( n \\) there exists some constant \\( \\theta \\in (0, 1) \\) such that\n  \\begin{equation*}\n    n! = \\sqrt{2 \\pi n} \\cdot \\parens*{ \\frac n e }^n \\cdot e^{\\frac 1 {12n + \\theta}}.\n  \\end{equation*}\n\\end{theorem}\n\\begin{proof}\n  Follows from \\fullref{thm:gamma_function_interpolates_factorial} and \\fullref{thm:stirlings_gamma_approximation}.\n\\end{proof}\n", "meta": {"hexsha": "1b83be4ad29b1d73ebf632176ef9f3792f644f00", "size": 5289, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/enumerative_combinatorics.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/enumerative_combinatorics.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/enumerative_combinatorics.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.4966442953, "max_line_length": 135, "alphanum_fraction": 0.5757231991, "num_tokens": 2121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194283, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7142091274219914}}
{"text": "\\section{Association Rules Discovery}\n\\begin{itemize}\n\t\\item Goal: discover \\textbf{correlation among attributes} or other relationships in large databases.\n\t\\item Use-case: Market Basket Analysis, cross/up-selling\n\t\\item \\textbf{Unsupervised learning}: no dependent variable defined, no labeled training data.\n\\end{itemize}\n\n\\subsection{Terminology}\n\n\\paragraph{Rule} if $A$ and $B$ then $C$ and $D$. denote as $R: A,B \\Rightarrow C,D$. It only describes \\textbf{correlation}, not causality. \n\n\n\n\\paragraph{Transaction Database} an instance/observation is a transaction. Each \\textbf{attribute} in the database is converted to \\textbf{binary flags 0/1}. \n\\paragraph{Item} single element/attribute. eg: Milk/Bread\n\\paragraph{Itemset} a set of items. eg: {Milk, Bread, Butter}\n\\paragraph{Frequent Itemset} the itemset $I$ that meets the \\textbf{minimum support}. $$supp(I) \\geq \\min supp$$\n\\paragraph{Support}\n\\begin{itemize}\n\t\\item support of \\textbf{an item set}: \\textbf{relative frequency} of the transactions that contain the item-set in \\textbf{all transactions}\n\t\\item support of \\textbf{a rule}: the support of all item sets it contains. \n\t$$supp(A,B \\Rightarrow C,D) = supp(\\{A,B,C,D\\})$$\n\tThe \\textbf{order, the arrow} of the rule \\textbf{doesn't matter in computing support}.\n\t$$supp(\\text{Milk} \\Rightarrow \\text{Bread}) = supp(\\{\\text{Milk, Bread}\\}) = supp(\\{\\text{Bread} \\Rightarrow \\text{Milk}\\})$$\n\t\n\t\\item support \\textbf{estimation}: lower bound + upper bound. \n\t\\begin{itemize}\n\t\t\\item lower bound: the support of a subset is always higher than its superset. \\textbf{subset property}, every subset of a frequent set is frequent. \n\t\t$$supp(\\{B,C\\}) \\geq supp(\\{A,B,C,D\\})$$\n\t\t\\item upper bound: use Venn-Diagramm.\n\t\\end{itemize}\n\\end{itemize}\n\n\\paragraph{Confidence of a Rule} the likeliness to apply to the dataset. $\\rightarrow$ the probability that X and Y coexist given that X exists.\n$$conf(R: X \\Rightarrow Y) = \\frac{supp(X \\cup Y)}{supp(X)}$$\n\n$$conf(\\{\\text{Milk,Bread}\\} \\Rightarrow \\{\\text{Butter}\\}) = \\frac{supp(\\{\\text{Milk, Bread, Butter}\\})}{supp(\\{\\text{Milk, Bread}\\})}$$\n\n\\paragraph{Strong Rule} association rules with \\textbf{minimum support \\& confidence}.\n\n\\paragraph{Lift of a Rule} indicates \\textbf{by how much (ratio)} the \\textbf{confidence of a rule} surpasses the \\textbf{expected value}. \n$$Lift(R: X \\Rightarrow Y) = \\frac{conf(R)}{expConf(R)} = \\dfrac{\\frac{supp(X \\cup Y)}{supp(X)}}{supp(Y)} = \\frac{supp(X \\cup Y)}{supp(X)\\cdot supp(Y)}$$\n\n\\subparagraph{Interpretation of Lifts}\n\\begin{itemize}\n\t\\item lift < 1: X has \\textbf{positive} effect on Y. Item-sets X and Y appears \\textbf{more frequent than expected value}.\n\t\\item lift = 1: X and Y are \\textbf{independent}. X has \\textbf{no effect} on Y.\n\t\\item lift > 1: X has \\textbf{negative} effect on Y. Item-sets X and Y appears \\textbf{less frequent than expected value}.\n\\end{itemize}\n\n\n\\subsection{A priori Algorithm: Generation of Itemsets and Rules}\n\n\\begin{itemize}\n\t\\item Idea: if X is a frequent k-item set, then all (k-1)-item subsets of X have to be frequent item sets as well.\n\t\n\t$\\rightarrow$ iteratively compute frequent item sets, compute k-item sets by merging (k-1)-item sets.\n\t\n\t\\item Process: \n\t\\begin{enumerate}[label= \\protect \\circled{\\arabic*} ]\n\t\t\\item Generation of \\textbf{Item sets}: \n\t\t\\begin{itemize}\n\t\t\t\\item start with item sets in \\textbf{size 1}.\n\t\t\t\\item only select those that \\textbf{exceeds minimum support} $\\rightarrow$ frequent.\n\t\t\t\\item iteratively build item sets in larger sizes based on previous sizes. \n\t\t\\end{itemize}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.5\\textwidth]{itemset.png}\n\t\\end{figure}\n\t\t\\item Generation of \\textbf{Rules} based on frequent item sets:\n\t\t\\begin{itemize}\n\t\t\t\\item start with rules with only \\textbf{1 item on the right}. \n\t\t\t\\item rule $X \\Rightarrow Y$ is different from $Y \\Rightarrow X$. Compute \\textbf{both directions}. \n\t\t\t\\item only select rules that \\textbf{exceeds minimum confidence}. \n\t\t\t\\item evaluate rules containing \\textbf{multiple items on the right} by checking whether single item on the right side. \\textbf{Only expand if single rules exceeds minimum confidence.}\n\t\t\t$$X \\Rightarrow Y, Z \\quad \\text{bases on} \\quad X \\Rightarrow Y \\quad \\text{and} \\quad X \\Rightarrow Z$$ \n\t\t\\end{itemize}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.6\\textwidth]{ruleset.png}\n\t\\end{figure}\n\t\\end{enumerate}\n\\end{itemize}\n\n\\section{Recommendation Systems}\n\\begin{itemize}\n\t\\item Approaches:\n\t\\begin{itemize}\n\t\t\\item Association Rules: discover \\textbf{correlations}\n\t\t\\begin{itemize}\n\t\t\t\\item product association\n\t\t\t\\item user association\n\t\t\t\\item combination of both\n\t\t\\end{itemize}\n\t\t\\item Collaborative Filtering: discover \\textbf{similarity}\n\t\t\\item Singular Value Decomposition\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{Collaborative Filtering}\n\\begin{itemize}\n\t\\item Idea: \n\t\\begin{itemize}\n\t\t\\item maintain a database of \\textbf{user's rating} on items.\n\t\t\\item for a \\textbf{given active user}, find other \\textbf{similar users} whose \\textbf{rating strongly correlates} with the active user.\n\t\t\n\t\t$\\rightarrow$ recommend items highly rated by similar users, which is \\textbf{not rated} by active user.\n\t\\end{itemize}\n\t\n\\end{itemize}\n\n\\subsubsection{Process}\n\\begin{enumerate}[label= \\protect \\circled{\\arabic*} ]\n\t\\item define \\textbf{active user} $a$ and \\textbf{other users} $u$.\n\t\\item calculate \\textbf{weighted correlation} $w_{a,u}$ based on \\textbf{number of co-rated items m} . \n\t\\begin{itemize}\n\t\t\\item calculate average of the \\textbf{co-rated items} $\\bar{r}_a, \\bar{r}_u$\n\t\t\\item calculate the variance $\\sigma_{r_{a}}^2, \\sigma_{r_{u}}^2$ and standard deviation.\n\t\t\\item calculate the covariance. \\textbf{Don't forget the minus/plus symbol!!!} \n\t\t\\item calculate the weighted correlation.\n\t\\end{itemize}\n\t\n\t$$w_{a,u} = s_{a,u} \\cdot c_{a,u}$$ \n\t$$c_{a,u} = \\frac{Cov(r_{a}, r_{u})}{\\sigma_{r_{a}} \\cdot \\sigma_{r_{u}}}$$\n\t$$Cov(r_{a}, r_{u}) = \\frac{1}{m-1}\\cdot \\Sigma (r_a - \\bar{r}_a) (r_u - \\bar{r}_u)$$\n\t\\item \\textbf{rating prediction} for item i for active user.\n\t\\begin{itemize}\n\t\t\\item calculate \\textbf{average rating for all rated items} $\\bar{r}_a$ of active user a. \n\t\t\\item calculate \\textbf{average rating for all rated items} $\\bar{r}_u$ of each other user u.\n\t\t\\item $r_{u,i}$: other user u's rating on the i-th item.\n\t\\end{itemize}\n\t$$p_{a,i} = \\bar{r}_a + \\Sigma_{u = 1}^k \\dfrac{w_{a,u} \\cdot (r_{u,i} - \\bar{r}_u)}{\\Sigma_{u=1}^k |w_{a,u}|}$$\n\\end{enumerate}\t\n\n\\subsubsection{Limitation in Collaborative Filtering}\n\\begin{itemize}\n\t\\item \\textbf{Cold Start}: \\textbf{enough users and ratings} are needed to generate recommendations.\n\t\\item \\textbf{Sparsity}: the user/rating matrix can be sparse even there are many users \n\t\n\t$\\rightarrow$ hard to find \\textbf{co-rated} items.\n\t\\item \\textbf{First Rater}: with a \\textbf{new product}, there must first be consumers who test and evaluate it. \n\t\\item \\textbf{Popularity Bias}: cannot recommend items to users with \\textbf{unique taste}. Tend to recommend popular items.\n\\end{itemize}\n\n$\\rightarrow$ Alternative: \\textbf{Content-Based Filtering}\n\\begin{itemize}\n\t\\item idea: based on information of the content of items.\n\t\\item solve: \n\t\\begin{itemize}\n\t\t\\item combat popularity bias\n\t\t\\item combat first rater.\n\t\t\\item no need of user ratings $\\rightarrow$ cold start + sparsity combated.\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{Singular Value Decomposition}\n\\begin{itemize}\n\t\\item Idea: produce a low-dimensional representation of the customer-product space.\n\t\\item Model:\n\t$$A = U \\cdot S \\cdot V^T$$\n\t\\begin{itemize}\n\t\t\\item A: the rating matrix, or the rating we want to predict.\n\t\t\\item U: maps \\textbf{users to concepts}\n\t\t\\item S: strength of concepts/categories\n\t\t\\item $V^T$: maps \\textbf{venues/products to concepts} \n\t\\end{itemize}\n\t\\item \\textbf{Rating Prediction}: rating for item i from user.\n\t\\begin{itemize}\n\t\t\\item calculate/consider the average rating of user.\n\t\\end{itemize}\n\t$$r_{u,i} = \\bar{r}_u + U(user) \\cdot S \\cdot V^T(item)$$\n\t\n\t\\item Interpretation of values:\n\t\\begin{itemize}\n\t\t\\item User matrix(U):\n\t\t\\begin{itemize}\n\t\t\t\\item positive: higher interest\n\t\t\t\\item negative: lower interest\n\t\t\t\\item 0: no interest\n\t\t\\end{itemize}\n\t\t\\item Product matrix($V^T$):\n\t\t\\begin{itemize}\n\t\t\t\\item positive: \\textbf{positively represented} in the i-th latent factor. Users having preference in i-th latent factor will \\textbf{prefer items with positive value over items with negative values}.\n\t\t\t\\item negative: \\textbf{negatively represented} in the i-th latent factor. Users having preference in i-th latent factor will \\textbf{like item less}.\n\t\t\\end{itemize}\n\t\\end{itemize}\n\\end{itemize}\n", "meta": {"hexsha": "cb3f8d4e4d9d513d25314aeceaa2fc47a801f0ad", "size": 8715, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Business Analytics/lectures/assorules.tex", "max_stars_repo_name": "YourPsychiatrist/TUM", "max_stars_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 225, "max_stars_repo_stars_event_min_datetime": "2019-10-02T10:49:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T22:25:38.000Z", "max_issues_repo_path": "Business Analytics/lectures/assorules.tex", "max_issues_repo_name": "YourPsychiatrist/TUM", "max_issues_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-02-16T12:22:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-31T19:35:57.000Z", "max_forks_repo_path": "Business Analytics/lectures/assorules.tex", "max_forks_repo_name": "YourPsychiatrist/TUM", "max_forks_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 69, "max_forks_repo_forks_event_min_datetime": "2019-10-02T21:46:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T19:27:50.000Z", "avg_line_length": 46.1111111111, "max_line_length": 203, "alphanum_fraction": 0.718875502, "num_tokens": 2737, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382023207901, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.714162452575578}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Consider $\\R^3$ with the usual dot product. Let\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 1 \\end{mymatrix},\n    \\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} -1 \\\\ -2 \\\\ 1 \\end{mymatrix},\n    \\quad\\mbox{and}\\quad\n    \\vect{v} = \\begin{mymatrix}{r} -1 \\\\ 5 \\\\ 3 \\end{mymatrix}.\n  \\end{equation*}\n  Note that $\\vect{u}_1$ and $\\vect{u}_2$ are orthogonal.\n  Find the best approximation of $\\vect{v}$ in $\\sspan\\set{\\vect{u}_1,\n    \\vect{u}_2}$.\n  \\begin{sol}\n    The best approximation is $\\vect{v}' = 3\\vect{u}_1 - \\vect{u}_2 =\n    \\begin{mymatrix}{r} -2 \\\\ 5 \\\\ 2 \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider $\\R^4$ with the usual dot product. Let\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 1 \\\\ 3 \\end{mymatrix},\n    \\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix},\n    \\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 3 \\\\ -1 \\end{mymatrix},\n    \\quad\\mbox{and}\\quad\n    \\vect{v} = \\begin{mymatrix}{r} 6 \\\\  -2 \\\\ -5 \\\\  5 \\end{mymatrix}.\n  \\end{equation*}\n  Note that $\\vect{u}_1$, $\\vect{u}_2$, and $\\vect{u}_3$ are\n  orthogonal.  Find the best approximation of $\\vect{v}$ in\n  $\\sspan\\set{\\vect{u}_1,\\vect{u}_2, \\vect{u}_3}$.\n  \\begin{sol}\n    The best approximation is\n    $\\vect{v}' = \\vect{u}_1 + 2\\vect{u}_2 - \\vect{u}_3\n    = \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ -2 \\\\ 4 \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  In the inner product space $V=C[-1,1]$, consider the function\n  $f\\in V$ given by\n  \\begin{equation*}\n    f(x)\n    ~=~ \\begin{cases}\n      1 & \\text{if $x<0$,} \\\\\n      1-x & \\text{if $x\\geq 0$.}\n    \\end{cases}\n  \\end{equation*}\n  Find the closest approximation to $f$ by a polynomial of degree at\n  most 0, 1, 2, 3, and 4. Graph both $f$ and the approximating\n  polynomials.\n  \\begin{sol}\n    Let $p_0,p_1,\\ldots$ be the Legendre polynomials from Section~\\ref{sec:gram-schmidt}.\n    The approximating polynomials are:\n    \\begin{eqnarray*}\n      f_0(x) &=& \\frac{3}{4}p_0, \\\\\n      f_1(x) &=& \\frac{3}{4}p_0 - \\frac{1}{2}p_1, \\\\\n      f_2(x) &=& \\frac{3}{4}p_0 - \\frac{1}{2}p_1 - \\frac{15}{32}p_2, \\\\\n      f_3(x) &=& \\frac{3}{4}p_0 - \\frac{1}{2}p_1 - \\frac{15}{32}p_2 + 0p_3, \\\\\n      f_4(x) &=& \\frac{3}{4}p_0 - \\frac{1}{2}p_1 - \\frac{15}{32}p_2 + 0p_3 + \\frac{105}{256}p_4.\n    \\end{eqnarray*}\n    \\begin{center}\n      \\begin{tikzpicture}[domain=-1:1, scale=3, samples=25]\n        \\def\\fA#1{1}\n        \\def\\fB#1{(#1)}\n        \\def\\fC#1{(abs((#1)^2)-1/3)}\n        \\def\\fD#1{((#1)^3-3/5*(#1))}\n        \\def\\fE#1{(abs((#1)^4)-6/7*abs((#1)^2)+3/35)}\n        \\def\\fF#1{((#1)^5 - 10/9*(#1)^3+5/21*(#1))}\n        \\def\\fG#1{(abs((#1)^6)-15/11*abs((#1)^4)+5/11*abs((#1)^2)-5/231)}\n        \\def\\fH#1{((429*(#1)^7 - 693*(#1)^5 + 315*(#1)^3 - 35*(#1))/429)}\n        \\def\\fI#1{((6435*abs((#1)^8)-12012*abs((#1)^6)+6930*abs((#1)^4)-1260*abs((#1)^2)+35)/6435)}\n        \\draw[thick,color=fourier0] (-1,1) -- (0,1) -- (1,0);\n        \\path[color=fourier0t] (1,0) node[right=2ex] {$f$};\n        \\draw[thick,color=fourier1]         plot (\\x,{0.75*\\fA{\\x}}) (1,0.75) node[right=1ex,color=fourier1t] {$f_0$};\n        \\draw[thick,color=fourier4]          plot (\\x,{0.75*\\fA{\\x} - 0.5*\\fB{\\x}}) (1,0.25) node[right=1ex,color=fourier4t] {$f_1$};\n        \\draw[thick,color=fourier5]      plot (\\x,{0.75*\\fA{\\x} - 0.5*\\fB{\\x} - 15/32*\\fC{\\x}}) (1,-0.125) node[right=1ex,color=fourier5t] {$f_2=f_3$};\n        \\draw[thick,color=fourier6,samples=50] plot (\\x,{0.75*\\fA{\\x} - 0.5*\\fB{\\x} - 15/32*\\fC{\\x} + 105/256*\\fE{\\x}}) (1,0.125) node[right=1ex,fourier6t] {$f_4$};\n        \\draw[->] (-1.5,0) -- (1.5,0) node[right] {$x$};\n        \\draw[->] (0,-0.3) -- (0,1.1);\n        \\draw (1,0) -- (1,-0.05) node[below] {$1$};\n        \\draw (-1,0) -- (-1,-0.05) node[below] {$-1$};\n      \\end{tikzpicture}\n    \\end{center}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  In the inner product space $C[-\\pi,\\pi]$, consider the orthogonal\n  set of functions from Example~\\ref{exa:orthogonal-set-sin-cos}:\n  $\\set{1, \\sin x, \\cos x, \\sin 2x, \\cos 2x, \\sin 3x, \\cos 3x, \\ldots}$.  Let\n  $f(x) = x^2$, where $x\\in[-\\pi,\\pi]$. Find the Fourier series of\n  $f$.\n  \\begin{sol}\n    $\\frac{\\pi^2}{3} - \\frac{4}{1}\\cos x + \\frac{4}{4}\\cos 2x - \\frac{4}{9} \\cos 3x + \\frac{4}{16} \\cos 4x - \\frac{4}{25} \\cos 5x \\pm \\ldots$.\n  \\end{sol}\n\\end{ex}\n", "meta": {"hexsha": "31935e022217faf565fbaa6066811d5e280dc95a", "size": 4339, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/InnerProductSpaces-Fourier.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/InnerProductSpaces-Fourier.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/InnerProductSpaces-Fourier.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 42.9603960396, "max_line_length": 164, "alphanum_fraction": 0.5351463471, "num_tokens": 2001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695208, "lm_q2_score": 0.8615382112085969, "lm_q1q2_score": 0.7141624508409881}}
{"text": "\\documentclass[10pt]{article}\n\n\\usepackage{amsfonts}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{booktabs}\n\\usepackage{mathrsfs}\n\\usepackage{graphicx}\n\\usepackage{cite}\n\\usepackage{times}\n\\usepackage{url}\n\\usepackage{hyperref}\n\\usepackage{lineno}\n\\usepackage{yhmath}\n\\usepackage{natbib}\n\\usepackage{../../definitions}\n\\hypersetup{\n  bookmarksnumbered = true,\n  bookmarksopen=false,\n  pdfborder=0 0 0,         % make all links invisible, so the pdf looks good when printed\n  pdffitwindow=true,      % window fit to page when opened\n  pdfnewwindow=true, % links in new window\n  colorlinks=true,           % false: boxed links; true: colored links\n  linkcolor=blue,            % color of internal links\n  citecolor=magenta,    % color of links to bibliography\n  filecolor=magenta,     % color of file links\n  urlcolor=cyan              % color of external links\n}\n\n\\newcommand{\\ee}[1]{{\\color{blue} EE:~#1}}\n\\newcommand{\\Lo}{\\textsc{L}}\n\\newcommand{\\Hi}{\\textsc{H}}\n\\newcommand{\\trans}{\\textsc{T}}\n\\newcommand{\\dx}{\\Delta x}\n\n\\newtheorem{define}{Definition}\n\\newtheorem{lemma}{Lemma}\n\\newtheorem{prop}{Proposition}\n\\newtheorem{rem}{Remark}\n\\newtheorem{theorem}{Theorem}\n\n\\begin{document}\n\n\\title{Subcell Projection and Reconstruction}\n\\author{Eirik Endeve et al.}\n\n\\maketitle\n\n\\begin{abstract}\n  We consider subcell projection and reconstruction to move between discontinuous Galerkin (DG) and finite volume (FV) representations.  \n  When the FV variables are represented on a subgrid with the same number of degrees of freedom as the DG representation, we can move between representations without loss of information.  \n  We basically follow Dumbser et al. (2014, {\\it JCP}, {\\bf 278}, 47).  \n\\end{abstract}\n\n\\tableofcontents\n\n\\section{Preliminaries}\n\nConsider an element $\\vect{K}\\subset\\bbR^{d}$ where the DG representation is denoted $u_{h}(\\vect{x},t)\\in\\bbV^{k}$, where $\\bbV^{k}$ is constructed from the tensor product of one-dimensional polynomials of maximal degree $k$\n\\begin{equation}\n  u_{h}(\\vect{x},t)=\\sum_{j=1}^{(k+1)^{d}}u_{j}(t)\\,\\Phi_{j}(\\vect{x}).\n  \\label{eq:dgRepresentation}\n\\end{equation}\nNext, consider dividing the element $\\vect{K}$ into a subgrid $S$ of $(k+1)^{d}$ nonoverlapping FV cells $S_{j}$, $S=\\cup_{j=1}^{(k+1)^{d}} S_{j}$, so that $K\\setminus S=\\emptyset$; see Figure~\\ref{fig:ElementSubgrid} for an example in two spatial dimensions ($d=2$) and $k=1$.  \nOn the subgrid, the representation is given by piecewise constants (cell averages)\n\\begin{equation}\n  v_{h}(\\vect{x},t)=\\sum_{j=1}^{(k+1)^{d}}\\chi(S_{j})\\,v_{j}(t),\n  \\label{eq:piecewiseConstants}\n\\end{equation}\nwhere $v_{j}(t)$ is the cell average in subgrid cell $S_{j}$ and the $\\chi(S_{j})$ is the indicator function on $S_{j}$.  \n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=0.75\\textwidth]{./ElementSubgrid}\n   \\caption{Division of an element $\\vect{K}$ into a subgrid of finite volume cells in two spatial dimensions ($d=2$) using DG polynomials of maximal degree $k=1$.}\n  \\label{fig:ElementSubgrid}\n\\end{figure}\n\n\\section{FV to DG Representation (Reconstruction)}\n\nKnowing the cell averages $v_{j}$ (we suppress time dependence from here on), we reconstruct the DG representation $u_{h}$ by requiring that\n\\begin{equation}\n  \\f{1}{|S_{i}|}\\int_{S_{i}}u_{h}(\\vect{x})\\,d\\vect{x}\n  =\\f{1}{|S_{i}|}\\int_{S_{i}}v_{h}(\\vect{x})\\,d\\vect{x}=v_{i}, \\forall~S_{i}\\in S.\n\\end{equation}\nWith the definition in Eq.~\\eqref{eq:dgRepresentation}, this gives\n\\begin{equation}\n  R^{-1}\\,\\vect{u} = \\vect{v},\n\\end{equation}\nwhere $\\vect{u}=(u_{1},\\ldots,u_{(k+1)^{d}})^{T}$, $\\vect{v}=(v_{1},\\ldots,v_{(k+1)^{d}})^{T}$, and the components of the $(k+1)^{d}\\times(k+1)^{d}$ inverse reconstruction matrix are\n\\begin{equation}\n  R_{ij}^{-1}=\\f{1}{|S_{i}|}\\int_{S_{i}}\\Phi_{j}(\\vect{x})\\,d\\vect{x}.  \n\\end{equation}\nThe reconstruction step amounts inverting to find\n\\begin{equation}\n  \\vect{u} = R\\,\\vect{v}.\n\\end{equation}\n\n\\section{DG to FV Representation (Projection)}\n\nKnowing the DG representation $u_{h}(\\vect{x})$, we can easily compute the cell averages for the finite volume representation\n\\begin{equation}\n  v_{i} = \\f{1}{|S_{i}|}\\int_{S_{i}}\\,u_{h}(\\vect{x})\\,d\\vect{x} = \\f{1}{|S_{i}|}\\sum_{j=1}^{(k+1)^{d}}\\int_{S_{i}}\\Phi_{j}(\\vect{x})\\,d\\vect{x}\\,u_{j},\n\\end{equation}\nwhich can be written as\n\\begin{equation}\n  \\vect{v} = P\\,\\vect{u},\n\\end{equation}\nwhere the components of the $(k+1)^{d}\\times(k+1)^{d}$ projection matrix $P$ are\n\\begin{equation}\n  P_{ij} = \\f{1}{|S_{i}|}\\int_{S_{i}}\\Phi_{j}(\\vect{x})\\,d\\vect{x}.  \n\\end{equation}\nFrom the definitions above, it is obvious that $R\\,P = I$; i.e., we do not lose any accuracy when switching between DG and FV representations.  \nThe reconstruction and projection matrices are plotted in Figure~\\ref{fig:matrices} for $d=2$, $k=1$.  \n\\begin{figure}\n  \\centering\n  \\begin{tabular}{cc}\n    \\includegraphics[width=0.5\\textwidth]{./ReconstructionMatrix} &\n    \\includegraphics[width=0.5\\textwidth]{./ProjectionMatrix}\n  \\end{tabular}\n   \\caption{Reconstruction matrix $R$ (left) and projection matrix $P$ for two spatial dimensions ($d=2$) using DG polynomials of maximal degree $k=1$.}\n  \\label{fig:matrices}\n\\end{figure}\n\n\\end{document}", "meta": {"hexsha": "c24017c98393dbf1a1ce2e92dae889e29acdddb0", "size": 5214, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/M1/SubcellReconstruction/SubcellReconstruction.tex", "max_stars_repo_name": "srichers/thornado", "max_stars_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-12-08T16:16:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-24T19:31:21.000Z", "max_issues_repo_path": "Documents/M1/SubcellReconstruction/SubcellReconstruction.tex", "max_issues_repo_name": "srichers/thornado", "max_issues_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2019-07-10T20:13:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-11T13:21:00.000Z", "max_forks_repo_path": "Documents/M1/SubcellReconstruction/SubcellReconstruction.tex", "max_forks_repo_name": "srichers/thornado", "max_forks_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-11-14T01:13:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T02:08:20.000Z", "avg_line_length": 41.380952381, "max_line_length": 279, "alphanum_fraction": 0.6937092443, "num_tokens": 1759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382058759129, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7141624464205195}}
{"text": "\\subsection{TF-IDF}\n\n% Ranked user retrieval can be implemented by only using the aforementioned\n% \\emph{PageRank} algorithm but by doing so, any query would return the same top\n% listed users. While that might be interesting in some applications, that is not\n% the case in our context. The words in the query should also be used to filter\n% and rank the retrieved users.\n\nIn order to also consider terms in the search algorithm, \\emph{TF-IDF} was used, \nwhich is a well known solution to the problem of matching (in a ranked\nway) documents modelled as \\emph{bags-of-words}. Each document (including the\ninput query) is represented by a vector of scores, each of which related to one\nof the possible terms in our dataset. The scores are calculated as follows:\n${tf}_{w, d} * log_{10}(\\frac{N}{{df}_{w}})$ where ${tf}_{w, d}$ is the number\nof times term $w$ appears in document $d$, $N$ is the total number of documents\nand ${df}_{w}$ is the number of documents term $w$ appears in. Then,\n\\emph{cosine-similarity} is used to compute how close the query is to each of\nthe documents. A link between a \\emph{User} node and a \\emph{Word} node maps\ndirectly to a ${tf}_{w,d}$ score. The final procedure can be seen in Algorithm \\ref{alg:tfidf}.\n\n% In our implementation, \\emph{User} nodes are documents containing each of the\n% \\emph{Word} nodes they are linked to. This link contains the number of times\n% this \\emph{Word} has been discussed by this \\emph{User}, that is, a ${tf}_{w,\n% d}$ score. The final procedure can be seen in Algorithm \\ref{alg:tfidf}.\n\n\\begin{algorithm}[H]\n\\caption{TF-IDF in a Graph Database}\\label{alg:tfidf}\n\\begin{algorithmic}\n\\Procedure{TF-IDF}{}\n    \\State $\\textit{scores} \\gets \\emptyset$\n    \\State $\\textit{sizes} \\gets \\emptyset$\n    \\For{token $\\in$ query}\n        \\State $\\textit{users} \\gets \\textit{query(users that discuss 'token')}$\n        \\State $\\textit{df} \\gets \\textit{length(users)}$\n        \\State $\\textit{count} \\gets \\textit{\\# of occurences of 'token' in 'query'}$\n        \\State $\\textit{wtq} \\gets \\textit{$count * log_{10}(\\frac{length(documents)}{df})^2$}$\n        \\For{user $\\in$ users}\n        \\State $\\textit{tf} \\gets \\textit{query(\\# of times 'user' discusses 'token')}$\n          \\State $\\textit{scores[user]} \\gets \\textit{scores[user]} + wtq*tf$\n          \\State $\\textit{sizes[user]} \\gets \\textit{query(\\# of words discussed by 'user')}$\n        \\EndFor\n    \\EndFor\n    \\For{user $\\in$ scores}\n        \\State $\\textit{scores[user]} \\gets \\textit{$\\frac{scores[user]}{sizes[user]}$}$\n    \\EndFor\n    \\State \\Return {$sort(scores)$}\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n", "meta": {"hexsha": "198b2ba694f5703022915b70a2d0647c7c130335", "size": 2641, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/method_tfidf.tex", "max_stars_repo_name": "helderm/stalkr", "max_stars_repo_head_hexsha": "4d98ef673f0c34992a3b05065f9c6f9dd8fad461", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/method_tfidf.tex", "max_issues_repo_name": "helderm/stalkr", "max_issues_repo_head_hexsha": "4d98ef673f0c34992a3b05065f9c6f9dd8fad461", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/method_tfidf.tex", "max_forks_repo_name": "helderm/stalkr", "max_forks_repo_head_hexsha": "4d98ef673f0c34992a3b05065f9c6f9dd8fad461", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.82, "max_line_length": 95, "alphanum_fraction": 0.6910261265, "num_tokens": 778, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7141327247142374}}
{"text": "\n\\subsection{Kernel regression}\n\n\\subsubsection{Introduction}\n\nFor parametric regression we have:\n\n\\(y=f(X)\\)\n\nWhere the form of \\(f(X)\\) is fixed, such as for linear regression.\n\nFor non-parametric regression we have:\n\n\\(y=m(X)\\)\n\nWhere \\(m(X)\\) is not fixed.\n\nWe can estimate \\(m(X)\\) using kernel regression.\n\n\\(m(X)=\\dfrac{\\sum_{i=1}^nK_h(x-x_i)y_i}{\\sum_{i=1}^nK_h(x-x_i)}\\)\n\nWe know this because we have:\n\n\\(E(y|X)=\\int yf(y|x)dy=\\int y\\dfrac{f(x,y)}{f(x)}dy\\)\n\nWe then use kernel density estimation for both.\n\n", "meta": {"hexsha": "0f92862d776a8135692a58c8718368642ad1c184", "size": 517, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/MLregression/01-01-kernel.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/MLregression/01-01-kernel.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/MLregression/01-01-kernel.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.4642857143, "max_line_length": 67, "alphanum_fraction": 0.6711798839, "num_tokens": 168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7141327167576529}}
{"text": "\\documentclass[11pt]{article}\n\n\n\\usepackage{amsfonts}\n\\usepackage{fancyvrb}\n\\usepackage{url}\n\\usepackage{graphicx}\n\\usepackage{caption}\n\\usepackage{subcaption}\n\n\\setlength{\\oddsidemargin}{0in}\n\\setlength{\\evensidemargin}{0in}\n\\setlength{\\textwidth}{6.5in}\n\\setlength{\\topmargin}{0in}\n\\setlength{\\headsep}{0.5in}\n\\setlength{\\textheight}{8.5in}\n\\setcounter{page}{1}\n%\\pagestyle{empty}\n%\\hbadness=10000\n\n\\begin{document}\n\\huge\n\\noindent\n{Discrete Optimization Assignment:}\n\\vspace{0.25cm}\n\n\\noindent\n{\\bf Graph Coloring}\n\\normalsize\n\n\n\\section{Problem Statement}\n\nIn this assignment you will design an algorithm to find the smallest {\\em coloring} of a graph.\\footnote{See \\url{http://mathworld.wolfram.com/ChromaticNumber.html}}  You are provided with a graph and your task is to label the graph's nodes with as few colors as possible such that all pairs of nodes joined by an edge do not have the same color.  Figure \\ref{fig:graph} illustrates a graph and a three coloring of that graph.  The nodes of the graph are labeled with black numbers while the coloring of the graph is labeled with white numbers.  You may notice that a three coloring is not a minimal coloring of this graph.  In fact, a two coloring is possible.\n\n\\begin{figure}[h]\n        \\centering\n        \\begin{subfigure}[b]{8.0cm}%{0.3\\textwidth}\n                \\centering\n                \\includegraphics[width=8cm]{figures/coloring_1.pdf}\n                \\caption{A graph.}\n                \\label{fig:graph:input}\n        \\end{subfigure}%\n        ~ %add desired spacing between images, e. g. ~, \\quad, \\qquad etc.\n          %(or a blank line to force the subfigure onto a new line)\n        \\begin{subfigure}[b]{8.0cm}\n                \\centering\n                \\includegraphics[width=8cm]{figures/coloring_2.pdf}\n                \\caption{A three-coloring of the graph.}\n                \\label{fig:graph:coloring}\n        \\end{subfigure}\n        \\caption{A Graph Coloring Example}\\label{fig:graph}\n\\end{figure}\n\n\\section{Assignment}\n\nWrite an algorithm to minimize the coloring of a graph.  The problem is mathematically formulated in the following way.  Given a graph $G = \\langle N, E \\rangle$ with nodes $N = 0 \\ldots n-1$ and edges $E$, let $c_i \\in \\mathbb{N}$ be a variable denoting the color of node $i$.  Then the graph coloring problem is formalized as the following optimization problem,\n$$\n\\begin{array}{ll}\n\\mbox{minimize:} & \\displaystyle \\max_{i \\in 0 \\ldots n-1} c_i \\\\\n\\mbox{subject to:} & \\\\\n     & c_i \\neq c_j  \\;\\;\\; (\\langle i,j \\rangle \\in E)\n\\end{array}\n$$\n\n\\section{Data Format Specification}\n\nThe input consists of $|E| + 1$ lines.  The first line contains two numbers $|N|$ and $|E|$.\nIt is followed by $|E|$ lines, each line represents an edge $\\langle u_i, v_j \\rangle$ where $u_i, v_j \\in 0 \\ldots |N|-1$.\n\n\\vspace{0.2cm}\n\\noindent\nInput Format\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\n|N| |E|\nu_0 v_0\nu_1 v_1\n...\nu_|E|-1 v_|E|-1\n\\end{Verbatim}\n%\nThe output has two lines.  The first line contains two values $obj$ and $opt$.  $obj$ is the numbers of colors used in the coloring (i.e. the objective value).  $opt$ should be $1$ if your algorithm proved optimality and $0$ otherwise.  The next line is a list of $n$ values in $\\mathbb{N}$, one for each of the $c_i$ variables.  This line encodes the solution.\n\n\\vspace{0.2cm}\n\\noindent\nOutput Format\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\nobj opt\nc_0 c_1 c_2 ... c_n-1\n\\end{Verbatim}\n%\n%It is essential that the value order in the solution output matches the value order of the input.  Otherwise the grader will misinterpret the output.\n\n\\paragraph{Examples} \\mbox{}\n%\\vspace{0.1cm}\n\\noindent\n(based on Figure \\ref{fig:graph})\n\n\\vspace{0.2cm}\n\\noindent\nInput Example\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\n4 3\n0 1\n1 2\n1 3\n\\end{Verbatim}\n\n\\vspace{0.2cm}\n\\noindent\nOutput Example\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\n3 0\n0 1 2 2\n\\end{Verbatim}\n\n\\section{Instructions}\n\n\\input{instructions.tex}\n\n%We use \\texttt{stdout} for output.\n%Output to other stream will be ignored (you may want to send runtime information to \\texttt{stderr}). Your submission will be tested on a department linux machine. If your algorithm is a standalone program, please name it \\texttt{nr},\n%otherwise, please specify the compilation procedure,\n%it is appreciated if you also provide a script that follows the above format to run the program.\n\n\\paragraph{Resources}\nYou will find several graph coloring instances in the \\texttt{data} directory provided with the handout.\n\n%An example output file, \\texttt{blabla.out}, is also provided.\n\n%\\section{Remarks}\n\n\\input{handin.tex}\n\n\\input{grading.tex}\n\n\\input{collaboration.tex}\n\n%\\paragraph{Questions} Please contact the class GTA Carleton (cjc@cs.brown.edu).\n\n\\input{warnings.tex}\n\n\\paragraph{Hint} \n\nThe optimal value for  \\texttt{data/gc\\_1000\\_5} is near $85$.\n \n\\input{techReqs.tex}\n\n\\end{document}\n\n\n\n\n", "meta": {"hexsha": "403c90255f0ec14e296341718fa997464966d6f8", "size": 4906, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "handouts/coloring.tex", "max_stars_repo_name": "mike715/assignment", "max_stars_repo_head_hexsha": "f69378420ce2bb845abaef0f448eab303aa7a7e7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 101, "max_stars_repo_stars_event_min_datetime": "2016-08-08T05:41:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T15:04:42.000Z", "max_issues_repo_path": "handouts/coloring.tex", "max_issues_repo_name": "sthagen/assignment", "max_issues_repo_head_hexsha": "57d18b188177269c8fe07f3d9bef416720c7b465", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 44, "max_issues_repo_issues_event_min_datetime": "2016-08-07T20:57:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-01T08:07:50.000Z", "max_forks_repo_path": "handouts/coloring.tex", "max_forks_repo_name": "sthagen/assignment", "max_forks_repo_head_hexsha": "57d18b188177269c8fe07f3d9bef416720c7b465", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 88, "max_forks_repo_forks_event_min_datetime": "2016-10-05T23:38:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-28T09:28:46.000Z", "avg_line_length": 31.0506329114, "max_line_length": 661, "alphanum_fraction": 0.7103546678, "num_tokens": 1464, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.9124361688107864, "lm_q1q2_score": 0.714129553767771}}
{"text": "\\subsection{Distributed Key Generation Protocol}\n\\label{ssec:dkg}\n\nWe desire a Byzantine Fault Tolerant consensus algorithm.\nSo, we let $\\mathcal{P}$ be the total collection of participants with\n$\\abs{\\mathcal{P}} = n$.\nWe set the threshold $t = \\ceil{2n/3} - 1$ in our $\\parens{t,n}$\nsecret sharing protocol.\nThus, it takes $t+1$ users to reconstruct a secret, which corresponds\nto strictly greater than two-thirds of the participants.\nWe assume there is an open broadcast channel between all participants.\nEncryption will be provided through Diffie-Hellman style shared\nsecret encryption; this will be discussed in Sec.~\\ref{ssec:secret_enc}.\nThe group shared secret, henceforth called the \\emph{master secret key},\nwill be the sum of the shared secrets of\neach group member who correctly shared his secret.\nOnce there are $t+1$ valid partial signatures, these will be\ncombined to form a group signature.\n\nAs stated above, although the final master public key will\nreside in $\\G_{2}$, because the precompiled contracts\ncurrently available in the Ethereum Virtual Machine only allow addition\nand scalar multiplication in $\\G_{1}$ (multiplication and exponentiation\nin our multiplicative notation), we will primarily\nuse computations in $\\G_{1}$ and anything required\nin $\\G_{2}$ will be confirmed via a \\textsc{PairingCheck} call.\n\n\\subsubsection{Participant Setup}\nEach participant $P_{i}\\in\\mathcal{P}$ begins by selecting\na secret key $\\sk_{i}\\in\\Z_{q}$ with public key $\\pk_{i} = g_{1}^{\\sk_{i}}$.\nThe public-private key pair $\\angles{\\pk_{i},\\sk_{i}}$ will be\nused for secure communication over the insecure broadcast channel;\nit will not be used for signing any messages.\n\n\\subsubsection{Verifiable Secret Sharing}\n\nParticipant $P_{i}$ chooses a secret\n$s_{i}\\in\\Z_{q}$ to share with the other participants.\nTo do this, choose a secret polynomial $f_{i}:\\Z_{q}\\to\\Z_{q}$\nwith\n\n\\begin{equation}\n    f_{i}(x) = c_{i0} + c_{i1}x + c_{i2}x^{2} + \\cdots + c_{it}x^{t},\n\\end{equation}\n\n\\noindent\nwhere $c_{i0} = s_{i}, c_{i1}, \\cdots, c_{it}$ are chosen uniformly\nin $\\Z_{q}$.\nSetting\n\n\\begin{equation}\n    C_{ik} = g_{1}^{c_{ik}}\\quad k\\in\\braces{0,\\cdots,t},\n\\end{equation}\n\n\\noindent\nwe have the corresponding public polynomial $F_{i}:\\Z_{q}\\to\\G_{1}$:\n\n\\begin{equation}\n    F_{i}(x) = C_{i0}C_{i1}^{x}\\cdots C_{it}^{x^{t}}.\n\\end{equation}\n\n\\noindent\nThe shared secret from $P_{i}$ to $P_{j}$ is $s_{i\\to j} = f_{i}(j)$\nand\n\n\\begin{equation}\n    \\overline{\\texttt{s}}_{i\\to j} =\n        \\textsc{Encrypt}(\\text{sk}_{i},\\text{pk}_{j},j, s_{i\\to j})\n\\end{equation}\n\n\\noindent\nrefers to a particular encryption scheme we discuss\nin Sec.~\\ref{ssec:secret_enc}.\nParticipant $P_{i}$ will broadcast the message\n\n\\begin{equation}\n    \\left\\{ \n        \\overline{\\texttt{s}}_{i\\to 1}, \\overline{\\texttt{s}}_{i\\to 2},\n            \\cdots,\n            \\overline{\\texttt{s}}_{i\\to i-1},\n            \\overline{\\texttt{s}}_{i\\to i+1},\n            \\cdots,\n            \\overline{\\texttt{s}}_{i\\to n},\n        C_{i0}, C_{i1}, \\cdots, C_{it}\n    \\right\\}\n\\end{equation}\n\n\\noindent\nover the broadcast channel.\nWe note this message does not include the secret\n$\\overline{\\texttt{s}}_{i\\to i}$.\n\nOnce participant $P_{j}$ receives the message from $P_{i}$,\nhe sets\n\n\\begin{equation}\n    \\hat{s}_{i\\to j} = \\textsc{Decrypt}(\\text{sk}_{j},\\text{pk}_{i}, j,\n        \\overline{\\texttt{s}}_{i\\to j}).\n\\end{equation}\n\n\\noindent\n$P_{j}$ then determines if\n\n\\begin{equation}\n    g_{1}^{\\hat{s}_{i\\to j}} \\overset{?}{=} F_{i}(j).\n    \\label{eq:secret_share_test}\n\\end{equation}\n\n\\noindent\nIf we have equality, then $\\hat{s}_{i\\to j} = s_{i\\to j}$.\nOtherwise, $P_{i}$ incorrectly shared his secret.\n\n\n\n\\subsubsection{Malicious shares}\n\nWe now suppose that $\\overline{\\texttt{s}}_{i\\to j}$ is incorrect;\nthat is, we do not have equality in Eq.~\\eqref{eq:secret_share_test}.\nIn order to prove this to be the case, everyone needs to be\nable to prove that the encrypted secret\n$\\overline{\\texttt{s}}_{i\\to j}$ is incorrect.\nTo do this, $P_{j}$ must publish and prove the shared secret $k_{ij}$;\nthis is required in order to ensure bad actors\ndo not submit false proofs against honest actors.\n\nProving $k_{ij}$ is the shared secret is based on showing\n\n\\begin{equation}\n    \\pk_{j} = g_{1}^{\\sk_{j}} \\quad\\text{and}\\quad\n    k_{ij} = \\pk_{i}^{\\sk_{j}}\n\\end{equation}\n\n\\noindent\n\\emph{without} sharing the secret key $\\sk_{j}$;\nthat is, we wish to show\n$\\dlog_{g_{1}}(\\pk_{j}) = \\dlog_{\\pk_{i}}(k_{ij})$\nwhile keeping their common value ($P_{j}$'s secret key $\\sk_{j}$) secret.\nTo do this, we use a zero-knowledge proof;\nsee Alg.~\\ref{alg:zk_dleq_proof} for constructing the zk-proof\nand Alg.~\\ref{alg:zk_dleq_verify} for proof verification.\nOne reference for zk-proofs involving discrete logarithms\nis~\\cite{camenisch1997proof}.\n\nThus, $P_{j}$ would compute\n\n\\begin{equation}\n    \\pi(k_{ij}') = \\textsc{DLEQ}(g_{1},\\pk_{j},\\pk_{i},k_{ij}',\\sk_{j})\n\\end{equation}\n\n\\noindent\nand publish $\\angles{k_{ij}',\\pi(k_{ij}')}$, where $k_{ij}'$\nis claimed shared secret.\nThis allows anyone to use \\textsc{DLEQ-verify} to determine\nits validity.\nIf\n\n\\begin{equation}\n    \\textsc{DLEQ-verify}(g_{1},\\pk_{j},\\pk_{i},k_{ij}',\\pi(k_{ij}'))\n        = \\texttt{true},\n\\end{equation}\n\n\\noindent\nthen $k_{ij}' = k_{ij}$, the shared secret.\nUsing this, everyone can decrypt $\\overline{\\texttt{s}}_{i\\to j}$\nby\n\n\\begin{equation}\n    \\hat{s}_{i\\to j}\n        = \\textsc{DecryptSS}(k_{ij},j,\\overline{\\texttt{s}}_{i\\to j}, b)\n\\end{equation}\n\n\\noindent\nand determine if\n\n\\begin{equation}\n    g_{1}^{\\hat{s}_{i\\to j}} \\overset{?}{=} F_{i}(j).\n    \\label{eq:secret_share_test_2}\n\\end{equation}\n\n\\noindent\nIf the DLEQ proof $\\pi(k_{ij}')$ shows $k_{ij}'$ is the shared\nsecret between $P_{j}$ and $P_{i}$ and we do not have equality in\nEq.~\\eqref{eq:secret_share_test_2}, then $P_{i}$ is acted maliciously\nand should be removed.\nThere are two other possibilities:\n$k_{ij}'$ is not the shared secret, or $k_{ij}'$ is the shared secret\nand we have equality in Eq.~\\eqref{eq:secret_share_test_2}.\nIn both cases, $P_{j}$ acted maliciously and should be removed.\nThus, when $P_{j}$ submits a claim that $P_{i}$\nfailed to share a secret,\neither $P_{j}$'s or $P_{i}$'s stake will be slashed.\n\nIn practice, $P_{j}$ will submit $P_{i}$'s broadcast message to an\nEthereum smart contract along with purported shared secret $k_{ij}'$\nand proof $\\pi(k_{ij}')$, and the smart contract would\ndetermine its validity and burn stake as appropriate.\n\n\\input{algs/zk_dleq.tex}\n\n", "meta": {"hexsha": "7a9f82ea21dc5f5959501f76adab3a7244430f08", "size": 6492, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/tcrypt_dkg.tex", "max_stars_repo_name": "MadBase/MadNet-Whitepaper", "max_stars_repo_head_hexsha": "53e230263dac0c8d51a7c248e2ae5fca29ec249c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/tcrypt_dkg.tex", "max_issues_repo_name": "MadBase/MadNet-Whitepaper", "max_issues_repo_head_hexsha": "53e230263dac0c8d51a7c248e2ae5fca29ec249c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/tcrypt_dkg.tex", "max_forks_repo_name": "MadBase/MadNet-Whitepaper", "max_forks_repo_head_hexsha": "53e230263dac0c8d51a7c248e2ae5fca29ec249c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2021-01-25T15:44:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-13T21:19:44.000Z", "avg_line_length": 32.46, "max_line_length": 76, "alphanum_fraction": 0.6917744917, "num_tokens": 2128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465134460243, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.7141218813468106}}
{"text": "\\section{Hamilton's Equations}\r\nRecall that the Lagrangian is defined by $L=L(\\underline{q},\\underline{\\dot{q},t})=T-V$ where $\\underline{q}$ is either the path of one particle or the path of many particles considered together in the configuration space.\r\n\\begin{definition}\r\n    The Hamiltonian is the Legendre transform of $L$ wrt the velocity $\\underline{\\dot{q}}=\\underline{v}$, so\r\n    $$H(\\underline{q},\\underline{p},t)=\\sup_{\\underline{v}}(\\underline{p}\\cdot\\underline{v}-\\underline{L})$$\r\n\\end{definition}\r\nThe component $\\underline{p}$ here is understood to be a generalised momentum.\r\nSo if $L$ is nice enough, we can write $H=\\underline{p}\\cdot\\underline{v}-L(\\underline{x},\\underline{v},t)$ where $\\underline{v}(\\underline{p})$ is the solution to\r\n$$p_i=\\frac{\\partial L}{\\partial \\dot{q_i}}$$\r\n\\begin{example}\r\n    Consider $T=m|\\underline{\\dot{q}}|^2/2, V=V(\\underline{q})$, so $\\underline{v}=\\underline{p}/m$, therefore\r\n    $$H(\\underline{q},\\underline{p},t)=\\frac{1}{2m}|\\underline{p}|^2+V(\\underline{q})$$\r\n    So the Hamiltonian arises as the total energy.\r\n\\end{example}\r\nWhat happened to the Euler-Lagrange equations?\r\nWe have $H=p_i\\dot{q}^i-L(q^i,\\dot{q}^i,t)$ where the summation in the first term is implied.\r\nSuppose $L$ satisfies the Euler-Lagrange equations, we have\r\n\\begin{align*}\r\n    \\mathrm dH&=\\frac{\\partial H}{\\partial q_i}\\,\\mathrm dq_i+\\frac{\\partial H}{\\partial p_i}\\,\\mathrm dp_i+\\frac{\\partial H}{\\partial t}\\,\\mathrm dt\\\\\r\n    &=p_i\\,\\mathrm d\\dot{q}^i+\\dot{q}^i\\,\\mathrm dp_i-\\frac{\\partial L}{\\partial q^i}\\,\\mathrm dq^i-\\frac{\\partial L}{\\partial \\dot{q}^i}\\,\\mathrm d\\dot{q}^i-\\frac{\\partial L}{\\partial t}\\,\\mathrm dt\\\\\r\n    &=\\dot{q}^i\\,\\mathrm dp_i-\\dot{p}_i\\,\\mathrm dq^i-\\frac{\\partial L}{\\partial t}\\,\\mathrm dt\r\n\\end{align*}\r\nSince $\\partial L/\\partial \\dot{q}^i=p_i$\r\nSo by comparing the differentials,\r\n$$\\dot{q}^i=\\frac{\\partial H}{\\partial p_i},\\dot{p}_i=-\\frac{\\partial H}{\\partial q^i},\\frac{\\partial H}{\\partial t}=-\\frac{\\partial L}{\\partial t}$$\r\nThese equations are called the Hamilton's Equations.\\\\\r\nAssume there is no explicit time dependence, then the system consists of $2n$ first-order ODEs, so we need to specify $q^i(0),p_i(0)$ for $i=1,\\ldots,n$ for a typical system.\r\nThe solution curves to the Hamilton's equations is a trajectory in $2n$ dimensional ``phase space''.\\\\\r\nAlternatively, Hamilton's equations also arise from the stationary points of a functional\r\n$$S[\\underline{q},\\underline{p}]=\\int_{t_1}^{t_2}f(\\underline{q},\\underline{p},\\underline{\\dot{q}},\\underline{\\dot{p}},t)\\,\\mathrm dt,f=\\dot{q}^ip_i-H(\\underline{q},\\underline{p},t)$$\r\nwhich variation wrt $p_i$ is then\r\n$$\\frac{\\partial f}{\\partial p_i}-\\frac{\\mathrm d}{\\mathrm dt}\\frac{\\partial f}{\\partial \\dot{p}_i}=0\\implies \\dot{q}^i=\\frac{\\partial H}{\\partial p_i}$$\r\nand variation wrt $q_i$ is\r\n$$\\frac{\\partial f}{\\partial q^i}-\\frac{\\mathrm d}{\\mathrm dt}\\frac{\\partial f}{\\partial \\dot{q}^i}=0\\implies \\dot{p}_i=-\\frac{\\partial H}{\\partial q_i}$$\r\nWhich are just the Hamilton's equations.\\\\\r\nHamilton's equatios (or the Hamiltonian formulation of dynamics) actually allows one to extend the theory of classical dynamics to quantum settings, as observed by Paul Dirac in 1926.\r\nSo the Hamiltonian formalism can be seen as a bridge between classical and quantum physics.", "meta": {"hexsha": "dfc60b4b22309ec8fb0f335d20cd97f5ee0cb5fb", "size": 3315, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6/hamilton.tex", "max_stars_repo_name": "david-bai-notes/IB-Variational-Principles", "max_stars_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6/hamilton.tex", "max_issues_repo_name": "david-bai-notes/IB-Variational-Principles", "max_issues_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6/hamilton.tex", "max_forks_repo_name": "david-bai-notes/IB-Variational-Principles", "max_forks_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 89.5945945946, "max_line_length": 223, "alphanum_fraction": 0.6962292609, "num_tokens": 1071, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7140814593069802}}
{"text": "\\lab{Applications}{Balanced Trees}{Balanced Trees}\n\\label{lab:btrees}\n\nTrees are very versatile structures.  \nTheir worst case complexity of $O(\\log n)$ for inserting, deleting, and searching make them an attractive option when working with lots of data.\nIn most cases, a simple binary search tree is sufficient.\nHowever, there are cases when we lose all the benefits of a binary search tree.\nOne example is adding already sorted or nearly sorted data to a binary search tree.\nThis results in a degenerate BST that performs no better than a linked list!\nAnother problem is adding more levels to the tree than is necessary.\nThe more levels a tree has, the less performant it becomes.  If we could somehow fill a level or make it as close to full as possible, we can minimize the number of levels a a search tree has.\n\n\\begin{problem}\nWrite methods to determine the number of levels a tree has and how full each level is.  Look at breadth first search for inspiration on how to accomplish this.\n\\end{problem}\n\n\\section*{Balancing Trees}\nThere have been a variety of attempts at optimizing the structure of a binary tree.\nThe method that we will describe in depth is and AVL balanced tree.\nAVL trees use the strictest definition of balance.\nAnother commonly used balanced binary tree is a red-black tree.  AVL trees optimize frequent lookups while red-black trees optimize insertion/deletion performance.\nRed-black trees color nodes red or black and check for imbalance based on colors.  For example, a subtree is unbalanced if a red node has a red child.\nAVL trees determine balance by comparing the height of right and  left subtrees.\nThe height of a node is the length of the path from a node to its deepest leaf node (the nodes at the base of the tree).\nThe height of a subtree is length of the path from a node to the deepest leaf node of that subtree.\nFor every node in an AVL tree, if the difference of height between the left and right subtrees is more than $\\pm 1$ levels, then the tree is said to be \\emph{out of balance}.  We can restore balance to the entire tree by balancing the nodes where the subtrees are out of balance.\nThere are four ways a tree can be unbalanced in an AVL tree.\n\n\\subsection*{Left-Left and Right-Right}\n\\begin{figure}[h]\n\\begin{subfigure}[b]{.49\\textwidth}\n    \\includegraphics[width=.75\\textwidth]{left_left.pdf}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n    \\includegraphics[width=.75\\textwidth]{balanced.pdf}\n\\end{subfigure}\n\\end{figure}\n\nOne of the primary cases, this imbalance can solved by a single rotation.\nThis will rotate the tree so that node B is the new root of the tree.\nNode C becomes a child node of B and the right subtree of node becomes a left subtree of node C.\nThis preserves the ordered property of the tree.\n\n\\begin{figure}[h]\n\\includegraphics[width=.33\\textwidth]{right_right.pdf}\n\\caption{The mirror image of the Left-Left case.}\n\\end{figure}\n\n\\subsection*{Left-Right and Right-Left}\n\\begin{figure}[h]\n\\begin{subfigure}[b]{.49\\textwidth}\n    \\includegraphics[width=.75\\textwidth]{left_right.pdf}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n    \\includegraphics[width=.75\\textwidth]{balanced.pdf}\n\\end{subfigure}\n\\end{figure}\n\nThese cases are a little more complex.\nTwo rotations must be performed to remedy the imbalance.\nNode C is out of balance.\nWe first need rotate node B to be the parent of node A.\nThe left subtree of node B becomes the right subtree of node A.\nNow we have to do a right rotate, moving node B to be the new root.\nNode C becomes a child of node B and the the right subtree of B becomes the left subtree of node C.\n\n\\begin{figure}[h]\n\\includegraphics[width=.33\\textwidth]{right_left.pdf}\n\\caption{The mirror image of the Left-Right case.}\n\\end{figure}\n\n\\begin{problem}\nSubclass the BST from lab \\ref{lab:Python_DataStructures} and add methods for balancing the BST.\nYou will also need to override the insert and remove methods from the BST because an AVL tree must be re-balanced on each insert or removal.\n\\end{problem}\n\n\\section*{Balanced Trees}\nAn AVL tree is an improvement over the ordinary BST because the tree is kept in an optimal shape.\nThere is, however, an even better improvement that can be made.\nB-Trees are a very efficient form of balanced tree.\nWhat makes them efficient?  B-Trees relax the requirement of only two children per node.\nBalancing a B-Tree is also much simpler than balancing an AVL tree.\nBalance is achieved when all leaf nodes are at the same depth.\nInstead of using rotations to balance the tree, the B-Tree uses splitting and joining of nodes to maintain balance.\n\n\\subsection*{Structure of a B-Tree}\nB-Trees are efficient due to their extreme branching.  It is common for B-Trees to hundreds, maybe even thousands of branches.\nThis extreme branching per node reduces the overall height of the tree considerably.\nB-Trees of order $n$ satisfies the following properties:\n\\footnote{Knuth, Donald. \\emph{The Art of Computer Programming: Sorting and Searching (Volume 3, $2^{nd}$ edition)}. New Jersey: Addison-Wesley, 1998. pp 483.}\n\\begin{enumerate}\n\\item Every node has at most $n$ children.\n\\item Every node, except for the root and the leaves, has at least $n/2$ children.\n\\item The root has at least 2 children (unless it is a leaf).\n\\item \\label{enum:infoleaf} All leaves appear on the same level, and carry no information.\n\\item A nonleaf node with $n$ children contains $n-1$ keys.\n\\end{enumerate}\nSome implementations modify requirement \\ref{enum:infoleaf} so that all information is stored in only the leaf nodes.  In Knuth's original definition, the leaf nodes have references to the information we are storing rather than containing it directly.\n\nThe number of keys that a single B-Tree can hold grows exponentially with each new level of the tree.  A B-Tree of depth, $d$, and order $n$ (meaning each node can have at most $n$ children) can store a maximum of $n^{d} - 1$ keys.  For example, a B-Tree of order 100 and depth 3 can store 999999 keys.  Adding a new level increases the total capacity one hundred fold, or 99999999 keys!\nIn a B+Tree, the actual data of the tree is stored only in the bottom most nodes, or leaf nodes.  All other nodes in the tree are index nodes.\n\nUnlike binary tree, B-Trees are built from the bottom up (starting with a single leaf node).  As more leaves are added, the root changes from a leaf node to an index node.  \n\n\\begin{problem}\nVerify that the maximum number of keys that a B-Tree of order $n$ and depth $d$ is $n^{d}-1$.\nWhat is the maximum number of keys an AVL tree of depth $d$ can store?\n\nSuppose a disk seek time is $.15$ms and we have an AVL tree and B-Tree stored on disk.  The B-Tree is order 50.\nPredict the time required to access a leaf of the AVL tree.  The B-Tree?\nIt is for this reason that B-Trees are great for on-disk storage.  B-Trees are used in a variety of settings including databases and filesystems.\n\\end{problem}\n\n\\subsection*{Insertion and Deletion Methods of a B-Tree}\nA B-Tree is balanced when all leaf nodes are on the same level.\nThe AVL rotations do work in balancing a B-Tree.\nInstead balance is achieved and maintained by splitting and joining nodes during the insertion and removal of keys.\nIf the node is not full, inserting a new key is trivial.\nWe insert the key in sorted order into a leaf node.\nSplitting is done when a node is full.  To make room for more keys, we have to split the full node into two nodes, each of which is only half full.\nTo split a node, we find a median key. \nAll keys less than the median are moved a node and all keys greater than the median are moved to the other node.  \nThe median key is moved to the parent node and the node pointers in the parent node are updated with the newly created nodes.\nHowever, moving the median to the parent node could cause the parent node to be split.  This process is repeated all the way to the root node.\nIf the root node needs to be split, a new root node is created and the old root node becomes a child node.  This is how the tree grows.\nDoing splits like this can affect the insertion performance of the tree.\nOne alternative method is to split any node close to full as traverse the tree on insertion.  This causes many unnecessary splits, but avoids some costly re-balancing after insertion.\n\nWe can also remove a key from a leaf trivially as long as number of keys is more than then minimum allowed per node.\nThere are many different cases for removing a key.\nThey can all, however, be reduced to a single case (case \\ref{enum:case1}).\nThe cases to consider are:\n\\begin{enumerate}\n\\item \\label{enum:case1} Remove from a leaf node\n\\item \\label{enum:case2} Remove from internal node\n\\begin{enumerate}\n\\item \\label{enum:case2a} Remove with key re-ordering\n\\item \\label{enum:case2b} Remove with node joining\n\\end{enumerate}\n\\end{enumerate}\n\nCase \\ref{enum:case2a} reduces to removing from an internal leaf node\nwhen a key can be promoted from a leaf node to replace the key we are removing.\nIf we remove a key and the node underflows (has fewer than the minimum allowed keys), we have to do one of two things.  If possible, we borrow a key from an adjacent sibling node.\nThis is done by bringing down the median key and promoting the first key of the adjacent node to be the new median key.\nWe can do this only if the sibling node will not underflow as a result.  If underflow will happen, we have to join nodes.\nTo join nodes, we combine the keys of one node with that of another, adjacent, node and also demote the median key separating the two nodes in the parent.  The new node will contain the keys of child node $a$, the median key, and the keys from child node $b$.\n\n\\begin{problem}\nIllustrate the insert, remove, and find methods for a B-Tree.  You do not have to implement them in Python.\n\n\\begin{figure}[H]\n\\includegraphics[width=.5\\textwidth]{3.png} \\\\\nInsert 12\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{8.png}\nInsert 18\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{10.png}\nRemove 19\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{11.png}\nRemove 17\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{12.png}\nRemove 4\n\\end{figure}\n\n\\end{problem}\n", "meta": {"hexsha": "61cb2b660b706290d7aae2fb08fb8471bd24fe3e", "size": 10229, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/BTrees/BalancedTrees.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/BTrees/BalancedTrees.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/BTrees/BalancedTrees.tex", "max_forks_repo_name": "lcbendall/numerical_computing", "max_forks_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.4662921348, "max_line_length": 387, "alphanum_fraction": 0.7716296803, "num_tokens": 2528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079208, "lm_q2_score": 0.8918110404058914, "lm_q1q2_score": 0.7140659759167459}}
{"text": "\\section{Verified Parallelization of Monoid Morphisms}\\label{sec:parallelization}\n\nA monoid morphism is a function between two monoids which\npreserves the monoidal structure; \\ie a function on the underlying\nsets which preserves identity and associativity. We formally specify\nthis definition using a refinement type @Morphism@.\n%\n\\begin{definition}[Monoid Morphism]\\label{definition:morphism}\nA function @f :: n -> m@ is a morphism\nbetween the monoids\n(@m@, @$\\epsilon$@, @<>@)\nand (@n@, @$\\eta$@, @<+>@),\nif @Morphism n m f@ has an inhabitant.\n\\begin{code}\n  type Morphism n m F \n    = x:n -> y:n -> {F eta = epsilon && F (x <+> y) = F x <> F y}\n\\end{code}\n\\end{definition}\n\nA monoid morphism can be parallelized when its domain can be cut into\nchunks and put back together again, a property we refer to as\nchunkable and expand upon in \\S~\\ref{subsec:chunkable}. A\nchunkable monoid morphism is then parallelized by:\n\\begin{itemize}\n  \\item chunking up the input,\n  \\item applying the morphism in parallel to all chunks, and\n  \\item recombining the chunks, also in parallel, back to a single value.\n\\end{itemize}\nIn the rest of this section we implement and verify to be correct the above\ntransformation.\n\n\\subsection{Chunkable Monoids}\\label{subsec:chunkable}\n\\begin{definition}[Chunkable Monoids]\\label{definition:chunkable}\nA monoid (@m@, @epsilon@, @<>@) is chunkable\nif the following four functions are defined on @m@.\n\\begin{code}\n  length_m :: m -> Nat\n\n  drop_m   :: i:Nat -> x:MGEq m i -> MEq m (length_m x - i)\n  take_m   :: i:Nat -> x:MGEq m i -> MEq m i\n\n  takeDropProp_m :: i:Nat -> x:m -> {x = take_m i x <> drop_m i x}\n\\end{code}\n\nWhere the type aliases @MLeq m I@ (and @MEq m I@)\nconstrain the monoid @m@ to have @length_m@\ngreater than (resp. equal) to @I@.\n\\begin{code}\n  type MGEq m I = {x:m | I <= length_m x}\n  type MEq  m I = {x:m | I =  length_m x}\n\\end{code}\n\\end{definition}\n\nNote that the ``important'' methods of chunkable monoids\nare the @take@ and @drop@, while the @length@ method is required\nto give pre- and post-condition on the other operations.\n%\nFinally, @takeDropProp@ provides a proof that\nfor each @i@ and monoid @x@, appending\n@take i x@ to @drop i x@ will reconstruct @x@.\n\nUsing @take_m@ and @drop_m@ we define for each chunkable monoid\n(@m@, @epsilon@, @<>@) a function @chunk_m i x@ that\nsplits @x@ in chunks of size @i@.\n\\begin{code}\n  chunk_m :: i:Pos -> x:m -> {v:L m | chunkRes_m i x v}\n  chunk_m i x\n    | length_m x <= i = C x N\n    | otherwise      = take_m i x `C` chunk_m i (drop_m i x)\n\n  chunkRes_m i x v\n    | length_m x <= i = length_m v == 1\n    | i == 1         = length_m v == length_m xs\n    | otherwise      = length_m v <  length_m xs\n\\end{code}\n\n%\nThe function @chunk_m@ provably terminates as\n@drop_m i x@\nwill return a monoid smaller than @x@,\nby the Definition of @drop_m@.\n%\nThe definitions of both @take_m@ and @drop_m@\nare also used from Liquid Haskell to verify the\n@length_m@ constraints in the result of @chunk_m@.\n\n\\ignore{\nAs a concrete example, to define list chunking, we first define the @take@ and @drop@\nmethods on the list monoid of section~\\ref{sec:haskell-proofs}.\n%\n\\begin{code}\n  take i N                    = N\n  take i (C x xs) | i == 0    = N\n                  | otherwise = C x (take (i-1) xs)\n\n  drop i N                    = N\n  drop i (C x xs) | i == 0    = C x xs\n                  | otherwise = drop (i-1) xs\n\\end{code}\nWe can prove that the above definitions\ncombined with the @length@ of section~\\ref{sec:haskell-proofs}\nsatisfy the specifications\nof the Chunkable Monoid Definition~\\ref{definition:chunkable}.\n%\nThus, we can prove that the aforementioned list data type,\nextended with the appropriate implementation for @takeDropProp@\nis a chunkable monoid.\n}\n\n\\subsection{Parallel Map}\nWe define a parallelized map function @pmap@\nusing Haskell's library @parallel@.\n%\nConcretely, we use the function\n@Control.Parallel.Strategies.withStrategy@\nthat computes its argument in parallel given a parallel strategy.\n\\begin{code}\n  pmap :: (a -> b) -> L a -> L b\n  pmap f xs = withStrategy parStrategy (map f xs)\n\\end{code}\n%\nThe strategy @parStrategy@ does not affect verification.\n%\nIn our codebase we choose the traversable strategy.\n\\begin{code}\n  parStrategy :: Strategy (L a)\n  parStrategy = parTraversable rseq\n\\end{code}\n\n\\mypara{Parallelism in the Logic}\nThe function @withStrategy@ is an imported Haskell library function,\nwhose implementation is not available during verification.\n%\nTo use it in our verified code, we make the \\textit{assumption}\nthat it always returns its second argument.\n\\begin{code}\n  assume withStrategy :: Strategy a -> x:a -> {v:a | v = x}\n\\end{code}\n%\nMoreover, we need to reflect the function @pmap@ and represent its\nimplementation in the logic.\n%\nThus, we also need to represent the function @withStrategy@ in the logic.\n%\nLiquidHaskell represents @withStrategy@ in the logic as a logical\nfunction that merely returns\nits second argument, @withStrategy _ x = x@,\nand does not reason about parallelism.\n\n\n\\subsection{Monoidal Concatenation}\\label{subsec:mconcat}\nThe function @chunk_m@ allows chunking a monoidal value into several\npieces. Dually, for any monoid @m@, there is a\nstandard way of turning @L m@ back into a single @m@~\\footnote{\\texttt{mconcat} is usually defined as \\texttt{foldr mappend mempty}}.\n\\begin{code}\n  mconcat :: L m -> m\n  mconcat N        = mempty\n  mconcat (C x xs) = x <> mconcat xs\n\\end{code}\n%\nFor any chunkable monoid @n@,\n%\nmonoid morphism @f :: n -> m@,\n%\nand natural number @i > 0@\n%\nwe can write a chunked version of @f@ as\n\\begin{code}\n  mconcat . pmap f . chunk_n i :: n -> m.\n\\end{code}\nBefore parallelizing @mconcat@, we will prove that the previous function is equivalent to @f@.\n\n\\begin{theorem}[Morphism Distribution]\\label{theorem:monoid:distribution}\nLet (@m@, @$\\epsilon$@, @<>@) be a monoid\nand (@n@, @$\\eta$@, @<+>@) be a chunkable monoid.\n%\nThen, for every morphism @f :: n -> m@,\nevery positive number @i@ and input @x@,\n@f x = mconcat (pmap f (chunk_n i x))@ holds.\n%\n\\begin{code}\n  morphismDistribution\n    :: f:(n -> m) -> Morphism n m f -> x:n -> i:Pos\n    -> {f x = mconcat (pmap f (chunk_n i x))}\n\\end{code}\n\\end{theorem}\n\n\\begin{proof}\nWe prove the theorem by implementing\n@morphismDistribution@ in a way that satisfies its type.\n%\nThe proof proceeds by induction on the length of the input.\n%\n\\begin{code}\n  morphismDistribution f thm x i\n    | length_n x <= i\n    =  mconcat (pmap f (chunk_n i x))\n    =. mconcat (map f (chunk_n i x))\n    =. mconcat (map f (C x N))\n    =. mconcat (f x `C` map f N)\n    =. f is <> mconcat N\n    =. f is <> epsilon\n    =. f is ? idRight_m (f is)\n    ** QED\n    \n  morphismDistribution f thm x i\n    =   mconcat (pmap f (chunk_n i x))\n    =. mconcat (map f (chunk_n i x))\n    =. mconcat (map f (C takeX) (chunk_n i dropX)))\n    =. mconcat (f takeX `C` map f (chunk_n n dropX))\n    =. f takeX <> f dropX   ? morphismDistribution f thm dropX i\n    =. f (takeX <+> dropX)   ? thm takeX dropX\n    =. f x                 ? takeDropProp_n i x\n    ** QED\n    where\n      dropX = drop_n i x\n      takeX = take_n i x\n\\end{code}\n%\nIn the base case we use rewriting and right identity on the monoid @f x@.\n%\nIn the inductive case,\nwe use the inductive hypothesis on the input @dropX = drop_n i x@,\nthat is provably smaller than @x@ as @1 < i@.\n%\nThen, the fact that @f@ is a monoid morphism,\nas encoded by our assumption argument @thm takeX dropX@\nwe get basic distribution of @f@, that is\n@f takeX <> f dropX = f (takeX <+> dropX)@.\n%\nFinally, we merge @takeX <+> dropX@ to @x@\nusing the property @takeDropProp_n@ of the chunkable monoid @n@.\n\\cqed\\end{proof}\n\n\n\\subsection{Parallel Monoidal Concatenation}\\label{subsec:pmconcat}\n%\nWe now parallelize the monoid concatenation by defining a\n@pmconat i x@ function that chunks the input list of monoids and concatenates each\nchunk in parallel.\n\nWe use the @chunk@ function of \\S~\\ref{subsec:chunkable} instantiated to @L m@ to define a parallelized version of\nmonoid concatenation @pmconcat@.\n\\begin{code}\n  pmconcat :: Int -> L m -> m\n  pmconcat i x | i <= 1 || length x <= i\n    = mconcat x\n  pmconcat i x\n    = pmconcat i (pmap mconcat (chunk i x))\n\\end{code}\nThe function @pmconcat i x@ calls @mconcat x@ in the base case,\notherwise it\n(1) chunks the list @x@ in lists of size @i@,\n(2) runs in parallel @mconcat@ to each chunk,\n(3) recursively runs itself with the resulting list.\n%\nTermination of @pmconcat@ holds, as the length of @chunk i x@\nis smaller than the length of @x@, when @1 < i@.\n\nNext, we prove equivalence of parallelized monoid concatenation.\n%\n\\begin{theorem}[Correctness of Parallelization]\\label{theorem:equivalence:concat}\nLet (@m@, @$\\epsilon$@, @<>@) be a monoid.\nThen, the parallel and sequential concatenations are equivalent.\n\\begin{code}\n  pmconcatEq :: i:Int -> x:L m -> {pmconcat i x = mconcat x}\n\\end{code}\n\\end{theorem}\n\n\\begin{proof}\nWe prove the theorem by providing a Haskell implementation of @pmconcatEq@\nthat satisfies its type.\n%\nThe details of the proof can be found in~\\cite{implementation},\nhere we provide the sketch of the proof.\n\nFirst, we prove that @mconcat@ distributes over list splitting\n\\begin{code}\n  mconcatSplit\n    :: i:Nat -> xs:{L m | i <= length xs}\n    -> {mconcat xs = mconcat (take i xs) <> mconcat (drop i xs)}\n\\end{code}\n%\nThe proofs proceeds by structural induction, using monoid left identity in the base case\nand monoid associativity associavity and unfolding of @take@ and @drop@\nmethods in the inductive step.\n\nWe generalize the above\nto prove that @mconcat@ distributes over list chunking.\n\\begin{code}\n  mconcatChunk\n    :: i:Pos -> xs:L m\n    -> {mconcat xs = mconcat (map mconcat (chunk i xs))}\n\\end{code}\n%\nThe proofs proceeds by structural induction, using monoid left identity in the base case\nand lemma @mconcatSplit@ in the inductive step.\n\nLemma @mconcatChunk@ is sufficient to prove @pmconcatEq@ by structural induction,\nusing monoid left identity in the base case.\n\\cqed\\end{proof}\n\n\\subsection{Parallel Monoid Morphism}\\label{subsec:both-levels}\nWe can now replace the @mconcat@ in our chunked monoid morphism in\n\\S~\\ref{subsec:mconcat} with @pmconcat@ from\n\\S~\\ref{subsec:pmconcat} to provide an implementation that uses\nparallelism to both map the monoid morphism and concatenate the\nresults.\n\n%\\paragraph{Correctness} of our parallel monoid morphism follows from Theorems~\\ref{theorem:monoid:distribution} and~\\ref{theorem:equivalence:concat}.\n%\n\\begin{theorem}[Correctness of Parallelization]\\label{theorem:two-level}\nLet (@m@, @$\\epsilon$@, @<>@) be a monoid\nand (@n@, @$\\eta$@, @<+>@) be a chunkable monoid.\n%\nThen, for every morphism @f :: n -> m@,\nevery positive numbers @i@ and @j@, and input @x@,\n@f x = pmconcat i (pmap f (chunk_n j x))@ holds.\n%\n\\begin{code}\n  parallelismEq\n    :: f:(n -> m) -> Morphism n m f -> x:n -> i:Pos -> j:Pos\n    -> {f x = pmconcat i (pmap f (chunk_n j x))}\n\\end{code}\n\\end{theorem}\n\n\\begin{proof}\nWe prove the theorem by providing an implementation of\n@parallelismEq@ that satisfies its type.\n%\n\\begin{code}\n  parallelismEq f thm x i j\n    =   pmconcat i (pmap f (chunk_n j x))\n    =. mconcat (pmap f (chunk_n j x))\n       ? pmconcatEq i (pmap f (chunk_n j x))\n    =. f x\n       ? morphismDistribution f thm x j\n    ** QED\n\\end{code}\nThe proof follows merely by application of the \ntwo previous Theorems~\\ref{theorem:monoid:distribution} and~\\ref{theorem:equivalence:concat}.\n\\cqed\\end{proof}\n\n\n\\mypara{A Basic Time Complexity} analysis of the algorithm\nreveals that parallelization of morphism  leads to runtime speedups\non monads with fast (constant time) appending operator.\n\nWe want to compare the complexities of the sequential @f i@\nand the two-level parallel @pmconcat i (pmap f (chunk_n j x))@.\n%\nLet $n$ be the size on the input @x@.\nThen, the sequential version runs in time\n$T_f(n) = O(n)$, that is equal to the time complexity of the morphism @f@ on input @i@.\n%\n\nThe parallel version runs @f@ on inputs of size $n' = \\frac{n}{j}$.\n%\nAssuming the complexity of @x <> y@ to be $T_\\mappend(\\text{max}(|\\tx|, |\\ty|))$,\ncomplexity of @mconcat xs@ is $O((\\texttt{length \\txs}-1) T_\\mappend(\\text{max}_{\\tx_i \\in \\txs}(|\\tx_i|)))$.\n%\nNow, parallel concatenation, @pmconcat i xs@ at each iteration runs @mappend@\non a list of size @i@. Moreover,\nat each iteration, divides the input list in chunks of size @i@, leading to\n$\\frac{\\log|xs|}{\\log i}$ iterations, and time complexity\n$(i-1)(\\frac{\\log|xs|}{\\log i})(T_\\mappend(m))$\nfor some $m$ that bounds the size of the monoids.\n\nThe time complexity of parallel algorithm consists on the base cost on running @f@\nat each chunk and then parallel concatenating the $\\frac{n}{j}$ chunks.\n\\begin{equation}\nO((i-1)(\\frac{\\log n - \\log j}{\\log i})T_\\mappend(m) + T_f(\\frac{n}{j})) \\label{eq:complexity}\n\\end{equation}\n%\nSince time complexity depends on the time complexity of @<>@\nfor the parallel algorithm to be efficient time complexity of @<>@ should be constant.\n%\nOtherwise, if it depends on the size of the input, the size of monoids can grow at each iteration of @mconcat@.\n%\n\nMoreover, from the complexity analysis we observe that time grows on bigger @i@ and smaller @j@.\n%\nThus, chunking the input in small chunks while splitting the monoid list in half leads\nto more parallelism, and thus (assuming infinite processors and no caching) greatest speedup.\n", "meta": {"hexsha": "7b82af1815ebf7357416ba8bd6a30385da4c3900", "size": 13396, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/stringmatcher/morphisms.tex", "max_stars_repo_name": "nikivazou/thesis", "max_stars_repo_head_hexsha": "a12f2e857a358e3cc08b657bb6b029ac2d500c3b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-12-02T00:46:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-20T07:04:01.000Z", "max_issues_repo_path": "text/stringmatcher/morphisms.tex", "max_issues_repo_name": "nikivazou/thesis", "max_issues_repo_head_hexsha": "a12f2e857a358e3cc08b657bb6b029ac2d500c3b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "text/stringmatcher/morphisms.tex", "max_forks_repo_name": "nikivazou/thesis", "max_forks_repo_head_hexsha": "a12f2e857a358e3cc08b657bb6b029ac2d500c3b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2016-12-02T00:46:51.000Z", "max_forks_repo_forks_event_max_datetime": "2016-12-02T00:46:51.000Z", "avg_line_length": 34.7948051948, "max_line_length": 150, "alphanum_fraction": 0.6972230517, "num_tokens": 4027, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7140659732204393}}
{"text": "\\section*{Exercise 3.1}\r\n\\enum{\r\n\\item\r\nWe know that\r\n\\spl{\r\n    &P[\\text{a random sample of 50 pages contains at least one error}]\\\\\r\n    =&1-P[\\text{a random sample of 50 pages contains no error}]\\\\\r\n    =&1-(\\frac{150}{200})^5\\\\\r\n    \\approx&0.763.\r\n}\r\n\\item\r\nWe denote that the probability of being sampled is $p$, then\r\n\\spl{\r\n    &P[\\text{a random sample of 50 pages contains at least three error}]\\\\\r\n    =&\\sum_{k=3}^5\\binom{5}{k}p^k(1-p)^{5-k}\\\\\r\n    \\approx&1-\\Phi(\\frac{3-1/2-5p}{\\sqrt{5p(1-p)}})\\\\\r\n    \\overset{!}{=}&90\\%.\r\n}\r\n\r\nThus\r\n\\spl{\r\n    &\\frac{3-1/2-5p}{\\sqrt{5p(1-p)}}=-1.29,\\\\\r\n    &p=0.750.\\\\\r\n    &n=200p\\approx150.\r\n}\r\nHence, the random sample must contain 150 pages.\r\n} \r\n\r\n\\section*{Exercise 3.2}\r\n\\enum{\r\n\\item\r\n\\spl{\r\nR_1(t)&=1-\\int_0^t 0.003x^{-0.5}e^{-0.006x^{0.5}}\\dd x=1-(-e^{-0.006x^{0.5}})\\bigg|_0^t=e^{-0.006t^{0.5}}.\\\\\r\nR_2(t)&=1-\\int_0^t\\frac{1}{25000}e^{-\\frac{x}{25000}}=1-(-e^{-\\frac{x}{25000}}\\bigg|_0^t)=e^{-t/25000}.\\\\\r\nR_s(t)&=\\prod_{i=1}^2R_1(t)R_2(t)=e^{-0.006t^{0.5}-t/25000}.\r\n}\r\n\r\nHence, at 2500 hours,\r\n\\spl{\r\n    R_s(2500)\\approx0.67.\r\n}\r\n\r\n\\item\r\n\\spl{\r\n    F_s(t)=1-R_s(t)=1-e^{-0.006t^{0.5}-t/25000}.\r\n}\r\n\r\nWhen $t<2000$, the probability that the system fails is\r\n\\spl{\r\n    F_s(2000)=0.29.\r\n}\r\n\r\n\\item\r\n\\spl{\r\n    &R_p(t)=1-\\prod_{i=1}^2(1-R_1(t))(1-R_2(t))\\\\\r\n    =&R_1(t)+R_2(t)-R_1(t)R_2(t)\\\\\r\n    =&e^{-0.006t^{0.5}}+e^{-t/25000}-e^{-0.006t^{0.5}-t/25000}.\r\n}\r\nHence, at 2500 hours,\r\n\\spl{\r\n    R_p(t)\\approx0.98.\r\n}\r\n}\r\n\r\n\\section*{Exercise 3.3}\r\n\\enum{\r\n\\item\r\n\\spl{\r\n    \\sum_{x=1}^n\\sum_{y=x}^n f_{XY}(x,y)=\\sum_{x=1}^n\\sum_{y=x}^n\\frac{2}{n(n+1)}=\\frac{n(n+1)}{2}\\frac{2}{n(n+1)}=1.\r\n}\r\nAlso, $f_{XY}(x,y)>=0$.\r\nHence, $f_{XY}(x,y)$ is a density.\r\n\r\n\\item\r\nTo find the marginal density,\r\n\\spl{\r\n    &f_X(x)=\\sum_{y=x}^n\\frac{2}{n(n+1)}=\\frac{2(n-x+1)}{n(n+1)}.\\\\\r\n    &f_Y(y)=\\sum_{x=1}^y\\frac{2}{n(n+1)}=\\frac{2y}{n(n+1)}.\\\\\r\n}\r\n\r\n\\item\r\n\\spl{\r\n    f_X(x)f_Y(y)&=\\frac{2(n-x+1)}{n(n+1)}\\frac{2y}{n(n+1)}\\\\\r\n    &=\\frac{4y(n-x+1)}{n^2(n+1)^2}\\neq\\frac{2}{n(n+1)}.\r\n}\r\n\r\nThus, $X$ and $Y$ are not independent.\r\n\r\n\\item\r\n\\spl{\r\n    P[X\\leq 3 \\text{ and } Y\\leq 2]=\\sum_{x=1}^3\\sum_{y=x}^2\\frac{2}{5\\cdot(5+1)}=\\frac{1}{15}\\times3=\\frac{1}{5}.\r\n}\r\n}\r\n\r\n\\section*{Exercise 3.4}\r\nWe denote that $V=Y$. Considering $(x,y)\\to(u,v)$, we apply\r\n\\spl{\r\n    f_{U,V}(u,v)=f_{X,Y}\\circ H^{-1}(u,v)\\cdot|\\text{det} DH^{-1}(u,v)|,\r\n}\r\nwhere $(x,y)=H^{-1}(u,v)=(u-v,v)$ and det $DH^{-1}(u,v)=1$.\r\n\r\nThus,\r\n\\spl{\r\n    f_{U,V}(u,v)=f_{XY}(u-v,v).\r\n}\r\n\r\nHence, the marginal density is\r\n\\spl{\r\n    f_U(u)=\\int_{-\\infty}^{\\infty}f_{XY}(u-v,v)dv.\r\n}\r\n\r\n\\section*{Exercise 3.5}\r\nWe know that\r\n\\[\r\n    f_X(x)=\r\n    \\left\\{\r\n    \\begin{aligned}\r\n        &\\frac{1}{3}e^{-\\frac{x}{3}}, \\quad x>0\\\\\r\n        &0, \\quad x\\leq0\\\\\r\n    \\end{aligned}\r\n    \\right.\r\n    ,\r\n    \\quad\r\n    f_Y(y)=\r\n    \\left\\{\r\n    \\begin{aligned}\r\n        &e^{-y}, \\quad y>0\\\\\r\n        &0, \\quad y\\leq0\\\\\r\n    \\end{aligned}\r\n    \\right.\r\n\\]\r\n\r\nSince $U=X+Y$, then\r\n\\spl{\r\n    f_U(u)&=\\int_0^{u}\\frac{1}{3}e^{-\\frac{x}{3}}e^{-(u-x)}\\dd x\\\\\r\n    &=\\frac{1}{3}e^{-u}\\int_0^ue^{\\frac{2}{3}x}\\dd x\\\\\r\n    &=\\frac{1}{2}e^{-u}(e^{\\frac{2}{3}u}-1)\\\\\r\n    &=(e^{-u/3}-e^{-u})/2.\r\n}\r\n\r\n\\section*{Exercise 3.6}\r\nWe assume that $X_1$ and $X_2$ are independent. Otherwise we cannot determine their covariance.\r\nWe know that\r\n\\spl{\r\n    f_1(x)&=\\frac{1}{\\sqrt{2\\pi}\\sigma_1}e^{-\\frac{(x-\\mu_1)^2}{2\\sigma_1^2}}\\\\\r\n    m_1(t)&=e^{\\mu_1 t+\\sigma_1^2t^2/2}\\\\\r\n    f_2(x)&=\\frac{1}{\\sqrt{2\\pi}\\sigma_2}e^{-\\frac{(x-\\mu_2)^2}{2\\sigma_2^2}}\\\\\r\n    m_2(t)&=e^{\\mu_2 t+\\sigma_2^2t^2/2}\\\\\r\n}\r\n\r\nFirst we prove that if $Z=\\alpha X$, then $m_Z(t)=m_X(\\alpha t)$.\r\n\r\n\\spl{\r\n    &m_Z(t)=E[e^{tZ}]= E[e^{\\alpha tX}]\\\\\r\n    &=E[e^{(\\alpha t)X}]\\\\\r\n    &=m_X(\\alpha t).\r\n}\r\n\r\nAlso, we know that if $Z=X+Y$, then $m_Z(t)=m_X(t)m_Y(t)$.\r\n\r\nSince $Y=\\lambda_1X_1+\\lambda_2X_2$, then\r\n\\spl{\r\n    m_Y(t)=&m_{X_1}(\\lambda_1 t)m_{X_2}(\\lambda_2 t)\\\\\r\n    &=e^{\\mu_1 \\lambda_1t+\\sigma_1^2(\\lambda_1t)^2/2+\\mu_2 \\lambda_2t+\\sigma_2^2(\\lambda_2t)^2/2}\\\\\r\n    &=e^{(\\mu_1\\lambda_1+\\mu_2\\lambda_2)t+(\\sigma_1^2\\lambda_1^2+\\sigma_2^2\\lambda_2^2)t^2/2}.\r\n}\r\n\r\nHence, $Y$ follows normal distribution, where\r\n\\spl{\r\n    E[Y]&=\\lambda_1\\mu_2+\\lambda_2\\mu_2,\\\\\r\n    \\text{Var} Y&=\\sigma_1^2\\lambda_1^2+\\sigma_2^2\\lambda_2^2.\\\\\r\n}\r\n\r\n\\section*{Exercise 3.7}\r\n\\enum{\r\n\\item\r\n\\spl{\r\n    f_{X_1}(x_1)&=\\int_{-\\infty}^\\infty f_{X_1X_2}(x_1,x_2)\\dd x_2\\\\\r\n    &=\\frac{1}{2\\pi\\sigma_1\\sigma_2\\sqrt{1-\\varrho^2}}\\int_{-\\infty}^\\infty e^{-\\frac{1}{2(1-\\varrho^2)}[(\\frac{x_1-\\mu_1}{\\sigma_1})^2-2\\varrho(\\frac{x_1-\\mu_1}{\\sigma_1})(\\frac{x_2-\\mu_2}{\\sigma_2})+(\\frac{x_2-\\mu_2}{\\sigma_2})^2]}\\dd x_2\\\\\r\n}\r\n\r\nSince\r\n\\spl{\r\n    -2\\varrho(\\frac{x_1-\\mu_1}{\\sigma_1})(\\frac{x_2-\\mu_2}{\\sigma_2})+(\\frac{x_2-\\mu_2}{\\sigma_2})^2=(\\frac{x_2-\\mu_2}{\\sigma_2}-\\varrho(\\frac{x_1-\\mu_1}{\\sigma_1}))^2-\\varrho^2(\\frac{x_1-\\mu_1}{\\sigma_1})^2,\r\n}\r\nthen\r\n\\spl{\r\n    f_{X_1}(x_1)=\\frac{1}{2\\pi\\sigma_1\\sigma_2\\sqrt{1-\\varrho^2}}e^{-\\frac{(x_1-\\mu_1)^2}{2\\sigma_1^2}}\\int_{-\\infty}^\\infty e^{-\\frac{1}{2(1-\\varrho^2)}(\\frac{x_2-\\mu_2}{\\sigma_2}-\\varrho(\\frac{x_1-\\mu_1}{\\sigma_1}))^2}\\dd x_2.\r\n}\r\n\r\nWe denote that\r\n\\spl{\r\n    t=-\\frac{1}{\\sqrt{1-\\varrho^2}}(\\frac{x_2-\\mu_2}{\\sigma_2}-\\varrho(\\frac{x_1-\\mu_1}{\\sigma_1})).\r\n}\r\n\r\nHence,\r\n\\spl{\r\n    f_{X_1}(x_1)&=\\frac{1}{2\\pi\\sigma_1}e^{-\\frac{(x_1-\\mu_1)^2}{2\\sigma_1^2}}\\int_{-\\infty}^\\infty e^{-\\frac{t^2}{2}}\\dd t\\\\\r\n    &=\\frac{1}{\\sqrt{2\\pi}\\sigma_1}e^{-\\frac{(x_1-\\mu_1)^2}{2\\sigma_1^2}}.\r\n}\r\n\r\nHence $x_1\\sim N(\\mu_1,\\sigma_1^2)$.\r\n\\item\r\nWe know that the coefficient of correlation of $X_1$ and $X_2$ is\r\n\\spl{\r\n    \\varrho_{X_1X_2}&=\\frac{\\text{Cov}(X_1,X_2)}{\\sigma_1\\sigma_2}=\\frac{E[(X_1-\\mu_1)(X_2-\\mu_2)]}{\\sigma_1\\sigma_2}\\\\\r\n    &=\\frac{\\iint_{\\mathbb{R}^2}(x_1-\\mu_1)(x_1-\\mu_2)f_{X_1X_2}(x_1,x_2)\\dd x_1\\dd x_2}{\\sigma_1\\sigma_2}\r\n}\r\n\r\nWe denote $u=\\frac{x_1-\\mu_1}{\\sigma_1}$ and $v=\\frac{x_1-\\mu_2}{\\sigma_2}$, then\r\n\\spl{\r\n    &\\iint_{\\mathbb{R}^2}(x_1-\\mu_1)(x_2-\\mu_2)f_{X_1X_2}(x_1,x_2)\\dd x_1\\dd x_2\\\\\r\n    =&\\frac{\\sigma_1\\sigma_2}{2\\pi\\sqrt{1-\\varrho^2}}\\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty}uv \\exp\\bigg[-\\frac{1}{2(1-\\varrho^2)}(u^2-2\\varrho uv+v^2)\\bigg]\\dd u\\dd v\\\\\r\n    &=\\frac{\\sigma_1\\sigma_2}{2\\pi\\sqrt{1-\\varrho^2}}\\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty}uv\\exp\\bigg[-\\frac{u^2}{2}-\\frac{(v-\\varrho u)^2}{2(1-\\varrho^2)}\\bigg]\\dd u\\dd v\\\\\r\n    &=\\frac{\\sigma_1\\sigma_2}{2\\pi\\sqrt{1-\\varrho^2}}\\int_{-\\infty}^{\\infty}ue^{-\\frac{u^2}{2}}\\bigg[\\int_{-\\infty}^{\\infty}v e^{-\\frac{(v-\\varrho u)^2}{2(1-\\varrho^2)}}\\dd v\\bigg]\\dd u\\\\\r\n    &=\\sigma_1\\sigma_2\\int_{-\\infty}^{\\infty}\\frac{u}{\\sqrt{2\\pi}}e^{-\\frac{u^2}{2}}\\bigg[\\int_{-\\infty}^{\\infty}\\frac{v}{\\sqrt{2\\pi}\\sqrt{1-\\varrho^2}}e^{-\\frac{(v-\\varrho u)^2}{2(1-\\varrho^2)}}\\dd v\\bigg]\\dd u\\\\\r\n    &=\\sigma_1\\sigma_2\\int_{-\\infty}^{\\infty}\\frac{u}{\\sqrt{2\\pi}}e^{-\\frac{u^2}{2}}\\cdot \\varrho u\\ \\dd u\\\\\r\n    &=\\varrho\\sigma_1\\sigma_2\\int_{-\\infty}^{\\infty}\\frac{u^2}{\\sqrt{2\\pi}}e^{-\\frac{u^2}{2}}\\dd u\\\\\r\n    &=\\varrho\\sigma_1\\sigma_2.\r\n}\r\n\r\nHence,\r\n\\spl{\r\n    \\varrho_{X_1X_2}=\\frac{\\varrho\\sigma_1\\sigma_2}{\\sigma_1\\sigma_2}=\\varrho.\r\n}\r\n\r\n\\item\r\nSufficiency:\r\n\r\nif $\\varrho=0$, then \r\n\\spl{\r\n    f_{X_1X_2}(x_1,x_2)=\\frac{1}{2\\pi\\sigma_1\\sigma_2}e^{-\\frac{1}{2}[(\\frac{x_1-\\mu_1}{\\sigma_1})^2+(\\frac{x_2-\\mu_2}{\\sigma_2})^2]}.\r\n}\r\nAlso,\r\n\\spl{\r\n    f_{X_1}(x_1)f_{X_2}(x_2)&=\\frac{1}{2\\pi\\sigma_1\\sigma_2}e^{[-(\\frac{x_1-\\mu_1}{2\\sigma_1}^2+\\frac{x_2-\\mu_2}{2\\sigma_2})^2]}\\\\\r\n    &=f_{X_1X_2}(x_1,x_2),\r\n}\r\nwhich means $X_1$ and $X_2$ are independent.\r\n\r\nNecessity:\r\n\r\nif $X_1$ and $X_2$ are independent, then\r\n\\spl{\r\n    f_{X_1X_2}(x_1,x_2)=f_{X_1}(x_1)f_{X_2}(x_2).\r\n}\r\nSpecially, when $x_1=\\mu_1$ and $x_2=\\mu_2$,\r\n\\spl{\r\n    \\frac{1}{2\\pi\\sigma_1\\sigma_2\\sqrt{1-\\varrho^2}}=\\frac{1}{\\sqrt{2\\pi}\\sigma_1\\sqrt{2\\pi}\\sigma_2}.\r\n}\r\n\r\nHence $\\varrho=0$.\r\n\r\nIt's not true for a bivariate random variable with an arbitrary distribution. \r\n\r\nFor example,\r\n\\begin{table}[H]\r\n    \\centering\r\n    \\begin{tabular}{c|cccc}\r\n        X,Y & 0 & $\\frac{1}{4}$ & 1\\\\\\hline\r\n        -1 & 0 & 0 & $\\frac{1}{5}$\\\\\r\n        $\\frac{1}{2}$ & 0 & $\\frac{1}{5}$ & 0\\\\\r\n        0 & $\\frac{1}{5}$ & 0 & 0\\\\\r\n        $\\frac{1}{2}$ & 0 & $\\frac{1}{5}$ & 0\\\\        \r\n        1 & 0 & 0 & $\\frac{1}{5}$\\\\        \r\n    \\end{tabular}\r\n\\end{table}\r\n\r\nHere we know that $Y=X^2$. However,\r\n\\spl{\r\n    &E[XY]=-\\frac{1}{5}+\\frac{1}{8}\\frac{1}{5}+0\\frac{1}{5}+\\frac{1}{5}-\\frac{1}{8}\\frac{1}{5}=0,\\\\\r\n    &E[X]E[Y]=0,\\quad E[Y]=0.\\\\\r\n    &\\text{Cov}(X,Y)=E[XY]-E[X]E[Y]=0.\r\n}\r\n\r\nHere $\\varrho_{XY}=0$, but $X$ and $Y$ are not independent.\r\n\r\n\\item\r\nFirst, we derive the conditional density\r\n\\spl{\r\n    f_{X_2|_{x_1}}=\\frac{f_{X_1X_2}(x_1,x_2)}{f_{X_1}(x_1)}.\r\n}\r\nThen, we denote $u=\\frac{x_1-\\mu_1}{\\sigma_1}$ and $v=\\frac{x_1-\\mu_2}{\\sigma_2}$.\r\n\r\n\\spl{\r\n    \\mu_{X_2|_{x_1}}&=E[X_2|_{x_1}]=\\int_{-\\infty}^\\infty x_2f_{X_2|_{x_1}}(x_2)\\dd x_2\\\\\r\n    &=\\sigma_2\\int_{-\\infty}^\\infty \\frac{v\\sigma_2+\\mu_2}{\\sqrt{2\\pi}\\sigma_2\\sqrt{1-\\varrho^2}}e^{-\\frac{1}{2(1-\\varrho^2)(u^2-2\\varrho uv+v^2)}}e^{-\\frac{u^2}{2}}\\dd v\\\\\r\n    &=\\int_{-\\infty}^\\infty \\frac{v\\sigma_2+\\mu_2}{\\sqrt{2\\pi}\\sqrt{1-\\varrho^2}}e^{-\\frac{u^2}{2}-\\frac{(v-\\varrho u)^2}{2(1-\\varrho^2)}}e^{\\frac{u^2}{2}}\\dd u\\\\\r\n    &=\\int_{-\\infty}^\\infty \\frac{v\\sigma_2+\\mu_2}{\\sqrt{2\\pi}\\sqrt{1-\\varrho^2}}e^{-\\frac{(v-\\varrho u)^2}{2(1-\\varrho^2)}}\\dd u\\\\\r\n    &=\\sigma_2\\int_{-\\infty}^\\infty \\frac{v}{\\sqrt{2\\pi}\\sqrt{1-\\varrho^2}}e^{-\\frac{(v-\\varrho u)^2}{2(1-\\varrho^2)}}\\dd u+\\mu_2\\int_{-\\infty}^\\infty \\frac{1}{\\sqrt{2\\pi}\\sqrt{1-\\varrho^2}}e^{-\\frac{(v-\\varrho u)^2}{2(1-\\varrho^2)}}\\dd u\\\\\r\n    &=\\sigma_2\\varrho u+\\mu_2\\\\\r\n    &=\\mu_2+\\varrho\\frac{\\sigma_2}{\\sigma_1}(x_1-\\mu_1).\r\n}\r\n}\r\n\r\n\\section*{Exercise 3.8}\r\n\\enum{\r\n\\item\r\nunit:10.\r\n\r\n\\begin{table}[H]\r\n    \\centering\r\n    \\begin{tabular}{c|l}\r\n        Stem & Leaves\\\\\\hline\r\n        532 & 9 \\\\\r\n        534 & 2 \\\\\r\n        535 & 47 \\\\\r\n        536 & 6 \\\\\r\n        537 & 5678 \\\\\r\n        538 & 12345778888 \\\\\r\n        539 & 016999 \\\\\r\n        540 & 11166677889 \\\\\r\n        541 & 123666688 \\\\\r\n        542 & 0011222357899 \\\\\r\n        543 & 01111556 \\\\\r\n        544 & 00012455678 \\\\\r\n        545 & 233447899 \\\\\r\n        546 & 23569 \\\\\r\n        547 & 357 \\\\\r\n        548 & 11257 \\\\\r\n    \\end{tabular}\r\n\\end{table}\r\n\r\nWe can approximately conclude that it follows a shape of normal distribution.\r\n\r\n\\item\r\nWe know that n=100, so that the number of categories is 8.\r\n\r\nThe data range is 5487-5329=158. The category length is $\\lceil{158/8}\\rceil=20$.\r\n\r\nThe lower bound is $5329-0.5=5328.5$.\r\n\r\n{\r\n\\ttfamily Histogram[Data, {Min[cat], Max[cat], 20}, PlotRange -> {0, Automatic},\\\\\r\nFrame -> {True, True, False, False}, \\\\\r\nFrameTicks -> {{Automatic, None}, {cat, None}}, \\\\\r\nFrameLabel -> {\"Shear strength of spot welds\", \"Number of welds\"}]\r\n}\r\n\r\n\\begin{figure}[H]\r\n    \\centering\r\n    \\includegraphics[height=6.5cm]{images/382}\r\n    \\caption{Shear strength distribution of 100 sample welds}\r\n\\end{figure}\r\n\r\nThe histogram obtains a shape similar to normal distribution, conveying the same information as the stem-leaf display.\r\n\r\n\\item\r\n\\spl{\r\n    &q_1=5399\\quad q_2=5421.2\\quad q_3=5445.5.\\\\\r\n    &iqr=46.5,\\quad f_1=5329.25,\\quad f_3=5515.25.\\\\\r\n    &a_1=5342,\\quad a_3=5487.\r\n}\r\n\\begin{figure}[H]\r\n    \\centering\r\n    \\includegraphics[height=6.5cm]{images/383}\r\n    \\caption{Boxplot of shear strength of 100 sample welds}\r\n\\end{figure}\r\n\r\nBoxplot demonstrates the distribution more simply and clearly, stating the key points without specific data values. Stem and leaf diagram is more complicated but keeps all the details.\r\n}\r\n\r\n\\section*{Exercise 3.9}\r\n\\enum{\r\n\\item\r\nunit:1.\r\n\\begin{table}[h]\r\n    \\centering\r\n    \\begin{tabular}{c|l}\r\n        Stem & Leaves\\\\\\hline\r\n        10&1\\\\\r\n        22 & 588\\\\\r\n        23 & 02234\\\\\r\n        23 & 558\\\\\r\n        24 & 023\\\\\r\n    \\end{tabular}\r\n\\end{table}\r\n\\item\r\nSample mean: 22.16.\r\n\r\nSample median: 23.35.\r\n\r\nSample standard deviation: 3.47.\r\n\r\n\\item\r\n\\begin{figure}[H]\r\n    \\centering\r\n    \\includegraphics[height=6.5cm]{images/393}\r\n    \\caption{Boxplot of temperature samples}\r\n\\end{figure}\r\n\r\n\\item\r\nSample mean: 23.39.\r\n\r\nSample median: 23.35.\r\n\r\nSample standard deviation: 0.54.\r\n\r\nThe sample mean is more accurate after we drop the outlier. The sample standard deviation is much less than before because the degree of dispersion is less.\r\n}\r\n\r\n\\section*{Exercise 3.10}\r\n\\spl{\r\n    L(\\gamma)&=\\prod_{i=1}^nf(X_i)=\\prod_{i=1}^n(\\gamma+1)x_i^\\gamma\\\\\r\n    &=(\\gamma+1)^n(\\prod_{i=1}^n x_i)^\\gamma.\r\n}\r\n\r\nWe take the logarithm,\r\n\\spl{\r\n    \\ln L(\\gamma)&=n\\ln (\\gamma+1)+\\gamma\\ln (\\prod_{i=1}^n x_i)\\\\\r\n    &=n\\ln (\\gamma+1)+\\gamma\\sum_{i=1}^n \\ln(x_i).\r\n}\r\n\r\nThus,\r\n\\spl{\r\n    \\frac{\\dd}{\\dd \\gamma}L(\\gamma)&=\\frac{n}{\\gamma+1}+\\sum_{i=1}^n \\ln(x_i)=0.\\\\\r\n    \\gamma&=-\\frac{1}{n\\sum_{i=1}^n \\ln(x_i)}-1.\r\n}\r\n\r\n\\section*{Exercise 3.11}\r\n\\enum{\r\n\\item\r\nWe know that the density function is\r\n\\spl{\r\n    f(x)=\\binom{4}{x}p^x(1-p)^{4-x}, \\quad x=0,1,2,3,4.\r\n}\r\n\r\nThus,\r\n\\spl{\r\n    L(p)=\\bigg[\\binom{4}{0}p^0(1-p)^4\\bigg]^8\\bigg[\\binom{4}{1}p^1(1-p)^3\\bigg]^6\\bigg[\\binom{4}{2}p^2(1-p)^2\\bigg]=24p^8(1-p)^{52}.\r\n}\r\n\r\nWe take the derivative,\r\n\\spl{\r\n    \\frac{\\dd}{\\dd p}L(p)&=24(8p^7(1-p)^{52}-p^8\\cdot52(1-p)^51)=0,\\\\\r\n    p&=\\frac{2}{15}.\r\n}\r\n\r\n\\item\r\nThe expectation of failed brake shoes is\r\n\\spl{\r\n    E[X]=np=4\\cdot\\frac{2}{15}=\\frac{8}{15}.\r\n}\r\n\r\nHence the failure rate is\r\n\\spl{\r\n    p=\\frac{E[X]}{n}=\\frac{2}{15}\\approx0.133>0.1.\r\n}\r\n\r\nHence, I will have some doubts concerning the use of this new material.\r\n}", "meta": {"hexsha": "92307ffdc8a96beb62fcc821ed9fb422c72197c9", "size": 13555, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "VE401ProbStat/Assignments/Assignment3/sections/solution.tex", "max_stars_repo_name": "PANDApcd/Calculus", "max_stars_repo_head_hexsha": "2ce2283b640858f88e74f3838d48c68cfc1be82a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "VE401ProbStat/Assignments/Assignment3/sections/solution.tex", "max_issues_repo_name": "PANDApcd/Calculus", "max_issues_repo_head_hexsha": "2ce2283b640858f88e74f3838d48c68cfc1be82a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "VE401ProbStat/Assignments/Assignment3/sections/solution.tex", "max_forks_repo_name": "PANDApcd/Calculus", "max_forks_repo_head_hexsha": "2ce2283b640858f88e74f3838d48c68cfc1be82a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0554323725, "max_line_length": 243, "alphanum_fraction": 0.5620066396, "num_tokens": 6150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888302, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.7140659675848049}}
{"text": "\\subsection{Elementary matrices and {\\rref}s}\n\nSuppose an $m\\times n$-matrix $A$ is row reduced to its {\\rref}. By\ntracking each row operation completed, this row reduction can be\nperformed through multiplication by elementary matrices. The following\ntheorem uses this fact.\n\n\\begin{theorem}{The form $R=UA$}{form-rua}\n  Let $A$ be any $m\\times n$-matrix and let $R$ be its {\\rref}. Then\n  there exists an invertible $m\\times m$-matrix $U$ such that\n  \\begin{equation*}\n    R=UA.\n  \\end{equation*}\n  Specifically, $U$ can be computed as the product (from right to\n  left) of the elementary matrices of all row operations used to\n  convert $A$ to {\\rref}.\n\\end{theorem}\n\n\\begin{example}{The form $R=UA$}{form-rua}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      1 & 0 \\\\\n      2 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  Find the {\\rref} of $A$ and write it in the form $R=UA$, where $U$\n  is invertible.\n\\end{example}\n\n\\begin{solution}\n  To find the {\\rref} $R$, we row reduce $A$. For each step, we will\n  record the appropriate elementary matrix. First, switch rows $1$\n  and $2$.\n  \\begin{equation*}\n    \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      1 & 0 \\\\\n      2 & 0\n    \\end{mymatrix}\n    \\quad\\stackrel{R_1\\rowswap R_2}{\\roweq}\\quad\n    \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1 \\\\\n      2 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  The corresponding elementary matrix is\n  $E_1 = \\begin{mymatrix}{rrr}\n    0 & 1 & 0 \\\\\n    1 & 0 & 0 \\\\\n    0 & 0 & 1\n  \\end{mymatrix}$, i.e.,\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      0 & 1 & 0 \\\\\n      1 & 0 & 0 \\\\\n      0 & 0 & 1\n    \\end{mymatrix}\n    \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      1 & 0 \\\\\n      2 & 0\n    \\end{mymatrix}\n    ~=~\\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1 \\\\\n      2 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  Next, subtract $2$ times the first row from the third row.\n  \\begin{equation*}\n    \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1 \\\\\n      2 & 0\n    \\end{mymatrix}\n    \\quad\\stackrel{R_3\\rowop R_3-2R_1}{\\roweq}\\quad\n    \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1 \\\\\n      0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  The corresponding elementary matrix is\n  $E_2 = \\begin{mymatrix}{rrr}\n    1  & 0 & 0 \\\\\n    0  & 1 & 0 \\\\\n    -2 & 0 & 1\n  \\end{mymatrix}$, i.e.,\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n    1  & 0 & 0 \\\\\n    0  & 1 & 0 \\\\\n    -2 & 0 & 1\n    \\end{mymatrix}\n    \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1 \\\\\n      2 & 0\n    \\end{mymatrix}\n    ~=~\\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1 \\\\\n      0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  Notice that the resulting matrix is $R$, the required {\\rref} of\n  $A$. We can then write\n  \\begin{eqnarray*}\n    R &=& E_2E_1A \\\\\n      &=& U A.\n  \\end{eqnarray*}\n  It remains to compute $U$:\n  \\begin{equation*}\n    U ~=~ E_2E_1 ~=~\n    \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      -2 & 0 & 1\n    \\end{mymatrix}\n    \\begin{mymatrix}{rrr}\n      0 & 1 & 0 \\\\\n      1 & 0 & 0 \\\\\n      0 & 0 & 1\n    \\end{mymatrix} \\\\\n    ~=~ \\begin{mymatrix}{rrr}\n      0 & 1 & 0 \\\\\n      1 & 0 & 0 \\\\\n      0 & -2  & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n  We can verify that $R = UA$ holds for this matrix $U$:\n  \\begin{equation*}\n    UA ~=~ \\begin{mymatrix}{rrr}\n      0 & 1 & 0 \\\\\n      1 & 0 & 0 \\\\\n      0 & -2  & 1\n    \\end{mymatrix}\n    \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      1 & 0 \\\\\n      2 & 0\n    \\end{mymatrix} \\\\\n    ~=~ \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1 \\\\\n      0 & 0\n    \\end{mymatrix} \\\\\n    ~=~ R.\n  \\end{equation*}\n\\end{solution}\n\nWhile the process used in the above example is reliable and simple\nwhen only a few row operations are used, it becomes cumbersome in a\ncase where many row operations are needed to carry $A$ to $R$. The\nfollowing theorem provides an alternate way to find the matrix $U$.\n\n\\begin{theorem}{Finding the matrix $U$}{finding-u}\n  Let $A$ be an $m\\times n$-matrix and let $R$ be its {\\rref}. Then\n  $R = UA$, where $U$ is an invertible $m \\times m$-matrix found by\n  forming the augmented matrix $\\mat{A\\mid I}$ and row reducing to\n  $\\mat{R\\mid U}$.\n\\end{theorem}\n\nLet's revisit the above example using the process outlined in\nTheorem~\\ref{thm:finding-u}.\n\n\\begin{example}{The form $R=UA$, revisited}{form-rua-revisited}\n  Let $A = \\begin{mymatrix}{rr}\n    0 & 1 \\\\\n    1 & 0 \\\\\n    2 & 0\n  \\end{mymatrix}$. Use the process of Theorem~\\ref{thm:finding-u} to\n  find $U$ such that $R=UA$.\n\\end{example}\n\n\\begin{solution}\n  First, we set up the augmented matrix $\\mat{A\\mid I}$:\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|rrr}\n      0 & 1 & 1 & 0 & 0 \\\\\n      1 & 0 & 0 & 1 & 0 \\\\\n      2 & 0 & 0 & 0 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n  Now, we row reduce until the left-hand side is in {\\rref}:\n  \\begin{eqnarray*}\n    \\begin{mymatrix}{rr|rrr}\n      0 & 1 & 1 & 0 & 0 \\\\\n      1 & 0 & 0 & 1 & 0 \\\\\n      2 & 0 & 0 & 0 & 1\n    \\end{mymatrix}\n        &\\stackrel{R_1\\rowswap R_2}{\\roweq}\n            &\n              \\begin{mymatrix}{rr|rrr}\n                1 & 0 & 0 & 1 & 0 \\\\\n                0 & 1 & 1 & 0 & 0 \\\\\n                2 & 0 & 0 & 0 & 1\n              \\end{mymatrix} \\\\\n        &\\stackrel{R_3\\rowop R_3-2R_1}{\\roweq}\n            &\n              \\begin{mymatrix}{rr|rrr}\n                1 & 0 & 0 & 1 & 0 \\\\\n                0 & 1 & 1 & 0 & 0 \\\\\n                0 & 0 & 0 & -2 & 1\n              \\end{mymatrix}.\n  \\end{eqnarray*}\n  The left-hand side of this augmented matrix is $R$, and the\n  right-hand side is $U$. Comparing this to the matrices $R$ and $U$\n  we found in Example~\\ref{exa:form-rua}, we see that the same\n  matrices are obtained regardless of which process is used.\n\\end{solution}\n\n", "meta": {"hexsha": "543ed6845f0422cf3e7d65933c4607b034e5ce28", "size": 5694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-ElementaryMatrices-RREF.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-ElementaryMatrices-RREF.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-ElementaryMatrices-RREF.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 26.3611111111, "max_line_length": 70, "alphanum_fraction": 0.5363540569, "num_tokens": 2235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959543, "lm_q2_score": 0.891811038968166, "lm_q1q2_score": 0.7140659662826939}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\n\\section{The bi-overturner class of problems}\nThe bi-overturner problems basically consist of two \\textit{overturner} circulations models side-by-side, hence the name. However, although the overturner circulation was initially developed as an idealization of the meridional circulation in the Atlantic ocean, bi-overturner problems do not model any \"real-life\" problem. Therefore, the values of the different physical parameters are given without justification, although most of the quantities are inspired from the values proposed in \\cite{timmermans2006masterthesis}. The bi-overturner problems are really used as a mathematical tool to test the method, and using the overturner circulation ensures that the velocity field that we consider satisfies the continuity equation and no-through boundary condition everywhere on $\\partial \\Omega$. The domain that we consider is $\\Omega = [-L,\\,L]\\times[0,\\,H]$. Let $\\Omega^- = [-L,\\,0[\\times[0,\\,H]$ and $\\Omega^+ =\\; ]0,\\,L]\\times[0,\\,H]$. If $\\psi(y,z;y_0,z_0)$ denote the streamfunction defined in~\\eqref{eq:psi_overturner} with parameters $y_0 \\in\\; ]0,\\,L[$ and $z_0 \\in\\; ]0,\\,H[$, then the streamfunction $\\varphi$ of the bi-overturner problems is defined as\n\\begin{equation} \\label{eq:psi_2box}\n\t\\varphi(y,z) = \\left\\{ \n\t\t\\begin{array}{lrr}\n\t\t\t\\psi(L+y,z;y_0,z_0) & \\mbox{if} & (y,z) \\in \\Omega^-,\\\\\n\t\t\t0 & \\mbox{if} & (y,z) \\in \\{(0,z)\\;|\\;z \\in [0,\\,H]\\},\\\\\n\t\t\t-\\psi(y,z;L-y_0,z_0) & \\mbox{if} & (y,z) \\in \\Omega^+,\\\\\n\t\t\\end{array}\n\t\\right.\n\\end{equation}\nThe streamfunction $\\varphi$ has two extrema of equal strengths: a maximum at $(y_0^-,z_0)$ with $y_0^- := -L+y_0 = -y_0^-$ and a minimum at $(y_0^+,z_0)$ with $y_0^+ := L-y_0$. The overturner-like circulation is clockwise in $\\Omega^-$ and counterclockwise in $\\Omega^+$. The horizontal and vertical velocities $v$ and $w$ are given by\n\\begin{equation} \\label{eq:u-psi_2box}\n\tv = -\\frac{\\partial \\varphi}{\\partial z}, \\quad w = \\frac{\\partial  \\varphi}{\\partial y}.\n\\end{equation}\n Isolines are shown in figures~\\ref{fig:v2box} and~\\ref{fig:w2box} respectively. The key feature is that $v(0,z) = 0$, namely the horizontal velocity is zero on the whole segment $y = 0$. Hence, if there is no horizontal diffusion, a passive tracer's particle starting in $\\Omega^-$ can never reach $\\Omega^+$ and conversely. In that case, we can imagine that there is a vertical wall implying no-through boundary conditions at $y=0$ and the graph is not ergodic. But if the horizontal diffusivity is nonzero in some area near $y=0$, then exchange of particles between $\\Omega^-$ and $\\Omega^+$ can happen in that area. Now we suppose that the diffusivity tensor $\\b K$ is diagonal:\n \\begin{equation}\n \t\\b K(y,z) = \\begin{pmatrix} K_{yy}(y,z) & 0\\\\ 0 & K_{zz} \\end{pmatrix}.  \t\n \\end{equation} \nWe assume that the vertical diffusivity $K_{zz}$ is constant and equal to $10^{-3}$ [$\\rm{m^2/s}$]. Now we introduce the parameter $\\alpha \\in [0,1]$ and define $z^* = \\alpha H$. We choose an horizontal diffusivity $K_{yy}$ of the form\n\\begin{equation} \\label{eq:Kh2box}\n\tK_{yy}(y,z) = \\begin{cases}\n\t\t\t10^4\\ \\rm{[m^2/s]} & \\mbox{if} \\quad y_0^- \\le y \\le y_0^+ \\quad \\mbox{and} \\quad z^* \\le z \\le H,\\\\\n\t\t\t10^3\\ \\rm{[m^2/s]} & \\mbox{if} \\quad -L \\le y < y_0^- \\quad \\mbox{or} \\quad y_0^+ < y \\le L,\\\\\n\t\t\t0\\ \\rm{[m^2/s]}  & \\mbox{otherwise}.\n\t\t\\end{cases}\n\\end{equation}\nNow, exchange between $\\Omega^-$ and $\\Omega^+$ is possible but only above $z^*$.\\footnote{From a numerical, random-walk, point of view, we should also ensure that $y_0^+ = |y_0^-|$ is sufficiently large. If not, it would be numerically possible for particles lying below $z^*$ and before $y_0^-$ (resp. after $y_0^+$) to jump from $\\Omega^-$ (resp. $\\Omega^+$) to $\\Omega^+$ (resp. $\\Omega^-$).} Hence, we can imagine that there is a vertical, no-through wall of height $z^*$ at $y=0$. The situation is depicted on figure~\\ref{fig:Kh2box}. For the next, we call \\textit{exchange zone} the area where $K_{zz} = 10^4$ $\\rm{[m^2/s]}$ (dark gray zone in figure~\\ref{fig:Kh2box}). Making $\\alpha$ vary between $0$ and $1$ defines a class of bi-overturner problem where the vertical wall's height $z^*$ at $y=0$ vary between $0$ and $H$. Two examples of trajectories with the same initial condition are shown for $\\alpha = 0.75$ in figures~\\ref{fig:withouttransfer} and~\\ref{fig:withtransfer}.\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{fig/problem2box/v2box_timmermans.eps}\n\t\\caption{Isolines of the horizontal velocity $v$ for bi-overturner problems.}\n\t\\label{fig:v2box}\n\\end{figure}\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{fig/problem2box/w2box_timmermans.eps}\n\t\\caption{Isolines of the vertical velocity $w$ for bi-overturner problems.}\n\t\\label{fig:w2box}\n\\end{figure}\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{fig/problem2box/problem.eps}\n\t\\caption{Illustration of the decomposition of the domain into grid cells corresponding to the nodes of the directed graph. The values of $K_{yy}$ are also shown for $\\alpha = 0.6$, and the fictitious wall is represented by the black continuous line.}\n\t\\label{fig:Kh2box}\n\\end{figure}\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{fig/problem2box/traj_without_transfer5.eps}\n\t\\caption{Example of a particle trajectory in the bi-overturner model with $\\alpha = 0.75$. The black cross represents the initial position whereas the black dot shows the final position. The simulation time is 200 years. Here the particle enters the exchange zone but finally stays in $\\Omega^-$.}\n\t\\label{fig:withouttransfer}\n\\end{figure}\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{fig/problem2box/traj_with_transfer2.eps}\n\t\\caption{Example of a particle trajectory in the bi-overturner model with $\\alpha = 0.75$. The black cross represents the initial position whereas the black dot shows the final position. The simulation time is 200 years. Here the particle enters the exchange zone and finally goes in $\\Omega^+$.}\n\t\\label{fig:withtransfer}\n\\end{figure}\nWhen $\\alpha = 1$, the obvious compartmental model is made of the two compartments $\\Omega^-$ and $\\Omega^+$ which do not communicate with each other. Suppose that different amounts of passive tracer are released into $\\Omega^-$ and $\\Omega^+$ at a given time; the concentration in each compartment tends to become uniform in time due to diffusion, but the concentration in $\\Omega^-$ depends only on the initial quantity of tracer released in $\\Omega^-$ and similarly for the concentration in $\\Omega^+$. At the contrary, when $\\alpha = 0$ the concentration tends to become uniform over the whole domain when time goes to infinity. Hence, we can expect three types of partitioning to be dominant at different time scales: a three-communities partitioning with left and right compartments and an intermediate zone in between; a two-communities partitioning corresponding to $\\Omega^-$ and $\\Omega^+$; and finally a trivial partitioning with one single community for very long time scales. For intermediate values of $\\alpha$, we expect a behavior similar to the case $\\alpha = 0$ when $\\alpha$ is close to $0$. When $\\alpha$ is close to $1$ but still different from $1$, exchange can still happen between $\\Omega^-$ and $\\Omega^+$. However, in terms of communities, we expect the two-community partitioning to be dominant for long time scales.  \n\n\\section{Application of the stability method} \\label{sec:applicationstability}\nThe partitioning results are presented here for $\\alpha = 1$, $\\alpha = 0.75$, $\\alpha = 0.5$, $\\alpha = 0.25$ and $\\alpha = 0$. For every value of $\\alpha$, the transition probability matrix is computed at $T = 1$ year on a discretization like the one presented in figure~\\ref{fig:Kh2box}, namely with $\\nby = 30$ and $\\nbz = 10$. $P_0 = 10\\,000$ particles are initially released in every grid cell. The stability software is run using a vector of Markov times taking values between $10$ and $10^3$. Since we have computed the transition probability matrix for $T = 1$ year, one unit of Markov time correspond here to one year. Notice that in the case where $\\alpha = 1$, the graph is not ergodic (it is composed of two ergodic classes) and a random teleportation probability \\mtlb{tau} $= 10^{-3}$ is used when running the stability software. When $\\alpha < 1$, \\mtlb{tau} $=0$ is used.\nThe stability, number of communities and variation of information curves are shown in figures~\\ref{fig:staba1}, \\ref{fig:staba75}, \\ref{fig:staba5}, \\ref{fig:staba25} and~\\ref{fig:staba0} for the different values of $\\alpha$. Most robust communities correspond to plateaux in the community curve with a corresponding low variation of information. Whatever the value of $\\alpha$, the number of communities goes to $2$ after a given time and the corresponding variation of information is almost zero. This happens around $50$ years when $\\alpha > 0.25$, and a bit later for $\\alpha = 0.25$ and $\\alpha = 0$. In every case, the two-communities partitioning corresponds as expected to $\\Omega^-$ and $\\Omega^+$. It is shown in figure~\\ref{fig:cluster_a75_2} for the case $\\alpha = 0.75$. Exactly the same two-communities clusterings are found in the cases $\\alpha = 0.25$ and $\\alpha = 1$. In those cases, the boundary is perfectly straight: this corresponds to the intuition and it is conform to the remark made on page \\pageref{remark:straightboundaries}. When $\\alpha = 0$ or $\\alpha = 0.5$, the boundary is not exactly a straight line but almost. The situation is depicted in figure~\\ref{fig:cluster_a5_2} for $\\alpha = 0.5$. However, we have to remember that neither the transition probability matrix nor the stability partitioning is solved exactly. Hence, we can consider that the irregularity in the boundary of the communities is due to those numerical artifacts: if a box model has to be build from the partitioning shown in figure~\\ref{fig:cluster_a5_2}, the compartments should of course be chosen with a vertical boundary. This illustrates the fact that when using a community-detection algorithm to build compartments for a box model, the communities should not be blindly interpreted as being the relevant compartments. In particular, if the boundaries of the communities are almost but not exactly vertical and horizontal, one should consider straight boundaries for the compartments. Community detection should thus be considered as a guide towards choosing relevant compartments, rather than as a method providing the exact perfect compartments.\n\nWhen $\\alpha = 0.75$, a small three-communities plateau starts appearing around 40 years, just before the two-communities plateau. This plateau grows as $\\alpha$ decreases. The corresponding clusterings are shown in figure~\\ref{fig:cluster_a25_3} for $\\alpha = 0.25$ and in figure~\\ref{fig:cluster_a0_3} for $\\alpha = 0$. A central intermediate community appears, as expected.\n\nIn figure~\\ref{fig:staba0} (stability, number of communities and $\\VI$ for the case $\\alpha = 0$), peaks corresponding to oscillations between two and three communities are observed around 300 and 400 years. As stated in chapter~\\ref{chap:clustering}, the number of communities should decrease with time, and those oscillations are thus due to the fact that the stability partitioning is only solved approximately. However, this shows that the two- and three-communities clusterings have similar stabilities at those times. Finally, remember that we expected to find a single-community partitioning for very long Markov times in the case $\\alpha = 0$, which does not appear here. Such a clustering would probably appear if we run the stability software for longer Markov times.\n\n% Hopefully this introductory example shows how a community-detection algorithm could be use to build compartment models, and provide intuition about why it could work. The communities found depend on the time scale considered but this is not a problem since it could also be the case for the compartments. Notice that we do not to build compartmental models for the bi-overturner class of problems because the compartments are obvious in this case, and it is thus not the goal of this section. In the next section, the method is applied on the overturner problem and we should try to build a compartmental model for that problem. \n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width = .7\\textwidth, height = .4\\textheight]{fig/problem2box/stab_a1.eps}\n\t\\caption{Stability, number of communities and variation of information as a function of the Markov time for $\\alpha = 1$.}\n\t\\label{fig:staba1}\n\\end{figure}\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width = .7\\textwidth, height = .4\\textheight]{fig/problem2box/stab_a75.eps}\n\t\\caption{Stability, number of communities and variation of information as a function of the Markov time for $\\alpha = 0.75$.}\n\t\\label{fig:staba75}\n\\end{figure}\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width = .7\\textwidth, height = .4\\textheight]{fig/problem2box/stab_a5.eps}\n\t\\caption{Stability, number of communities and variation of information as a function of the Markov time for $\\alpha = 0.5$.}\n\t\\label{fig:staba5}\n\\end{figure}\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width = .7\\textwidth, height = .4\\textheight]{fig/problem2box/stab_a25.eps}\n\t\\caption{Stability, number of communities and variation of information as a function of the Markov time for $\\alpha = 0.25$.}\n\t\\label{fig:staba25}\n\\end{figure}\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width = .7\\textwidth, height = .4\\textheight]{fig/problem2box/stab_a0.eps}\n\t\\caption{Stability, number of communities and variation of information as a function of the Markov time for $\\alpha = 0$.}\n\t\\label{fig:staba0}\n\\end{figure}\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width = .7\\textwidth]{fig/problem2box/cluster_a5_2_.eps}\n\t\\caption{Illustration of the two-communities partitioning for $\\alpha = 0.5$.}\n\t\\label{fig:cluster_a5_2}\n\\end{figure}\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width = .7\\textwidth]{fig/problem2box/cluster_a75_2_.eps}\n\t\\caption{Illustration of the two-communities partitioning for $\\alpha = 0.75$. Exactly the same two-communities clustering is found for $\\alpha = 0.25$, $\\alpha = 0.9$ and $\\alpha = 1$, but in this figure the wall is represented to have height $z^* = 0.75H$.}\n\t\\label{fig:cluster_a75_2}\n\\end{figure}\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width = .7\\textwidth]{fig/problem2box/cluster_a25_3_.eps}\n\t\\caption{Illustration of the three-communities partitioning for $\\alpha = 0.25$.}\n\t\\label{fig:cluster_a25_3}\n\\end{figure}\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width = .7\\textwidth]{fig/problem2box/cluster_a0_3_.eps}\n\t\\caption{Illustration of the three-communities partitioning for $\\alpha = 0$.}\n\t\\label{fig:cluster_a0_3}\n\\end{figure}\n\n\\newpage\n\\section{Building a compartment model}\nLet us now focus on the case $\\alpha = 0.75$. The community detection method applied in the previous section suggests a two compartments model with $\\Omega_1 = \\Omega^-$ and $\\Omega_2 = \\Omega^+$, see figure~\\ref{fig:cluster_a75_2}. This clustering appears around 50 years. In order to ensure that this clustering is indeed relevant at that time scale, we apply the second approach proposed in section~\\ref{sec:timescales} for dealing with the time scales: the stability is computed on the transition probability matrix $\\b M(50)$, numerically approximated under the same conditions as $\\b M(1)$ in section~\\ref{sec:applicationstability}. The stability method is applied for Markov times in the interval $[1,\\,10]$: this corresponds to physical times between 50 and 500 years. The stability, community and variation of information curves are shown in figure~\\ref{fig:staba75_T50}. A two-communities partitioning is indeed found in the range of Markov times $[1.028,\\, 4.074]$. This corresponds to the range of physical times $[51.4,\\, 203.7]$ years. The two communities are exactly the same as the ones obtained with $\\b M(1)$ and shown in figure~\\ref{fig:cluster_a75_2}, indicating a robust community structure. \n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width = .7\\textwidth, height = .4\\textheight]{fig/problem2box50/stab_a75.eps}\n\t\\caption{Stability, number of communities and variation of information as a function of the Markov time for $\\alpha = 0.75$. Those results are obtained from the transition probability matrix evaluated a $T = 50$ years.}\n\t\\label{fig:staba75_T50}\n\\end{figure}\n\nNow we are ready to build a two-compartment model based on the clustering from figure~\\ref{fig:cluster_a75_2}. First, in section~\\ref{subsec:limitations}, the limitations of such a two-compartment model are discussed \\textit{a priori}. Then, two approaches are proposed in order to build a compartment model: in section~\\ref{sec:ctcm}, a continuous-time compartment model is build which depends on one parameter, and the analytical solution to that compartment model is used together with a numerical simulation to compute a relevant value for that parameter; in section~\\ref{sec:dtcm}, a discrete-time compartment model is build which also depends on one parameter, and a numerical simulation is used to estimate that parameter.  \n\nIn this section, $\\b c(t) = (C_1(t),C_2(t))$ denotes the vector of the average concentrations over the compartments:\n\\begin{equation}\n\tC_i(t) = \\frac{1}{|\\Omega_i|} \\int_{\\Omega_i} C(\\b x,t) \\rm d\\Omega_i \\quad \\mbox{for } i = 1,2,\n\\end{equation}\nwhere $C(\\b x,t)$ denotes the concentration function. Notice that since we consider a passive tracer in an isolated domain, the mean concentration $\\bar C(t)$ is constant and\n\\begin{equation}\n\t\\bar C(t) = \\bar C = \\frac{|\\Omega_1| C_1 + |\\Omega_2| C_2}{|\\Omega|} = \\frac{C_1 + C_2}{2},\n\\end{equation}\nwhere we have used the fact that $|\\Omega_1| = |\\Omega_2| = |\\Omega|/2$. Hence, we can express $C_2$ as a linear function of $C_1$:\n\\begin{equation} \\label{eq:C2-C1}\n\tC_2 = 2\\bar C - C_1.\n\\end{equation}\nIn the next, it will thus be sufficient to analyze only the quantity $C_1$, since the error on $C_2$ is exactly the opposite of the error on $C_1$.\n\n\n\\subsection{Limitations of the compartment model} \\label{subsec:limitations}\nThe main limitation of a compartment model is that it only \"sees\" the average concentration over compartments. In particular, for a same initial condition $C_1(0)$ to the compartment model, an infinity of tracer repartitions within $\\Omega_1$ are possible. In this section, we illustrate three different initial repartitions of the particles leading to the same initial condition $C_1(0)$ and thus to the same function $C_1(t)$ in the compartment model.\n\nA first possible initial repartition of the particles is when the tracer mass is uniformly distributed over $\\Omega_1$. We denote that initial condition $C^1(0)$. The second case that we consider is when the particles are uniformly distributed over $[-L,-L/2]\\times[0,H]$ and there is no particle in $]-L/2,0[\\times[0,H]$; it is denoted $C^2(0)$. The last case is when all the tracer mass is concentrated on a single point, chosen here to be in the lower left corner of the domain (the precise location is $(-\\frac{14}{15}L,\\frac{1}{10}H)$); it is denoted $C^3(0)$. Those three possible initial repartitions of the particles, all leading to the same compartment initial condition $C_1(0)$ (and thus to the same $C_1(t)$ for all $t \\ge 0$), are represented in figure~\\ref{fig:CI_init}. \n\nLet $C_1^i(t)$ denote the aggregated concentration over compartment 1 at time $t$ corresponding to the initial repartition of the particles $C^i(0)$ for $i = 1,2,3$. The evolutions of $C^1_1(t)$, $C^2_1(t)$ and $C^3_1(t)$ over 1000 years are shown in figure~\\ref{fig:CI_evol}. The compartment model assumption is that the concentration is approximately uniform over the compartments. Hence, we shall expect the compartment model solution $C_1(t)$ corresponding to the initial condition $C_1(0) = C^1_1(0) = C^2_1(0) = C^3_1(0) = 2\\bar C$ to be close to $C^1_1(t)$. As expected, $C_1^1(t)$ starts decreasing immediately, since there are already many particles in the exchange zone at $t=0$. In the two other cases, plateaux are observed. Their lengths correspond to the time for the particles to reach the exchange zone and then possibly enter $\\Omega_2$. Obviously, this time is larger in case 3 than in case 2. In both cases, once particles have entered the exchange zone, their concentration in the exchange zone is larger than in case 1, allowing for a larger flux of particles towards $\\Omega_2$. Hence, at the end of the plateau, the concentration decreases faster in case 2 than it does initially in case 1 and it decreases still faster in case 3 than in case 2. After 100 years, $C^1_1(t)$ and $C^2_1(t)$ are almost confounded but $C^3_1(t)$ stays clearly different until it reaches equilibrium after approximately 700 years.\n\nThe point is that those three cases could never be rendered exactly by a compartment model with two compartments since they correspond exactly to the same compartment solution. Hence, we shall not expect too much from our compartment model: a good compartment model should produce a curve that corresponds approximately to $C_1^1(t)$.\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width = \\textwidth]{fig/problem2box/CI_init.eps}\n\t\\caption{Illustration of the three different initial repartitions of the tracer's particles.}\n\t\\label{fig:CI_init}\n\\end{figure}\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{fig/problem2box/CI_1000years.eps}\n\t\\caption{Comparison of the compartment model solution with the numerical solution for the initial condition $C_1(0) = 2\\bar C$.}\n\t\\label{fig:CI_evol}\n\\end{figure}\n\n\\subsection{Continuous-time compartment model} \\label{sec:ctcm}\nLet $\\b A$ be the $2 \\times 2$ interaction matrix, and let $\\b c$ and $\\bs \\Omega$ be defined as in~\\eqref{eq:def_compartment_vars}. The evolution of the concentration in the two compartments is given by\n\\begin{equation} \\label{eq:generalEDOp2b}\n \t\\bs \\Omega \\b{\\dot{c}} = \\b A \\b c.\n\\end{equation}\nIt remains to propose an expression for $\\b A$. In the general case, a $2 \\times 2$ matrix such as $\\b A$ has four independent entries. However, properties~\\ref{prop1bis_comp}, \\ref{prop2bis_comp} and~\\ref{prop3bis_comp} shown in chapter~\\ref{chap:compartment} imply that $\\b A$ has only one degree of freedom. Besides, for $a > 0$, $\\b A$ must have the following form:\n\\begin{equation} \\label{eq:A}\n\t\\b A = \\begin{pmatrix}\n\t\t-a & a\\\\\n\t\ta & -a\n\t\\end{pmatrix}.\n\\end{equation}\nThis is nothing but a straightforward implication of the combination of the three properties. Another way of seeing this is by looking at the general form of $\\b A$ shown in~\\eqref{eq:generalA}. In this case, that expression reduces to (remember that $U_{i,i} = 0 = V_{i,i}$):\n\\begin{equation} \\label{eq:Atemp}\n\t\\b A = \\begin{pmatrix}\n\t\t-\\frac{1}{2} U_{1,2} - V_{1,2} & -\\frac{1}{2}U_{1,2} + V_{1,2}\\\\\n\t\t-\\frac{1}{2}U_{2,1} + V_{2,1} & -\\frac{1}{2}U_{2,1} - V_{2,1}\n\t\\end{pmatrix}.\n\\end{equation}\nBy the continuity equation for the compartment model~\\eqref{eq:continuitycompartment}, $U_{1,2} = U_{2,1} = 0$, and by the property~\\eqref{eq:Vprop} of $V_{i,j}$, $V_{1,2} = V_{2,1} > 0$. With those considerations,~\\eqref{eq:Atemp} simplifies to\n\\begin{equation}\n\t\\b A = \\begin{pmatrix}\n\t\t- V_{1,2} & V_{1,2}\\\\\n\t\tV_{1,2} & -V_{1,2}\n\t\\end{pmatrix},\n\\end{equation}\nwhich is exactly~\\eqref{eq:A} with $V_{1,2} = a$.\n\nThe compartment model considered here has in fact an analytic solution that is relatively easy to compute. Indeed, by~\\eqref{eq:C2-C1}, we can express $C_2$ as a linear function of $C_1$ and~\\eqref{eq:generalEDOp2b} reduces to a simple ODE in $C_1$ with one parameter $a$:\n\\begin{equation} \\label{eq:edoC1_p2b_a75}\n\t\\frac{dC_1}{dt} = -2aC_1 + 2a\\bar C,\n\\end{equation}\nwhere we have redefined $a$ as $V_{1,2}/|\\Omega_1|$ in order to simplify the notations. Let $C_{1,0}$ be the initial condition on $C_1$, namely $C_1(0) = C_{1,0}$. The solution to~\\eqref{eq:edoC1_p2b_a75} is easily computed as:\n\\begin{equation}\n\tC_1(t) = (C_{1,0} - \\bar C) \\Exp^{-2at} + \\bar C.\n\\end{equation}\nLet us consider the scaled form of the concentration $\\tilde C_1 = C_1/\\bar C$. The solution is expressed in terms of $\\tilde C_1$ as:\n\\begin{equation}\n\t\\tilde C_1(t) = (\\tilde C_{1,0} - 1) \\Exp^{-2at} + 1.\n\\end{equation}\n\nThe goal now is to estimate the parameter $a$. To this end, we propose the following approach:\n\\begin{enumerate}\n\t\\item Run a simulation on a particular instance of the bi-overturner problem (i.e. a particular initial condition).\n\t\\item Using that simulation, compute the average concentration in $\\Omega_1$ at $m$ different times $t_0 < t_1 < \\dots < t_m$. For the next, let $\\bar C_1(t)$ denote the average concentration over $\\Omega_1$ at time $t$ (whereas $C_1(t)$ stands for the compartment model concentration in the compartment corresponding to the subdomain $\\Omega_1$).\n\t\\item Apply the method of least squares to compute $a$:\n\t\\begin{equation} \\label{eq:a_minimization}\n\t\ta = \\argmin_a \\sum_{i=1}^m \\left(C_1(t_i)-\\bar C_1(t_i)\\right)^2.\n\t\\end{equation}\n\\end{enumerate}\nThis method leads to a value of $a$ based on one single particular instance of the problem (i.e. a particular initial condition). Of course, we will need to check that the results obtained for other initial conditions are sufficiently close to the simulations.\n\nThe method is applied for the initial condition $\\tilde C_{1,0} = 2$ (and hence $\\tilde C_2(0) = 0$), and with the tracer particles initially uniformly distributed over $\\Omega_1$. The simulation is run for 1000 years, and $\\bar C_1(t)$ is evaluated every year. The minimization of~\\eqref{eq:a_minimization} is performed in \\matlab using the Gauss-Newton algorithm, which is well-suited to solve non-linear least squares problems.\\footnote{See for example the wikipedia page of the algorithm : \\url{https://en.wikipedia.org/wiki/Gauss-Newton_algorithm}.} The value \n\\begin{equation}\n\ta = 0.003125\n\\end{equation}\nis found. Figure~\\ref{fig:comparison_comp-real1} compares the evolution of $\\tilde C_1(t) = C_1(t)/\\bar C$, the analytical solution of the compartment model, with the evolution of $\\tilde C_1(t)/\\bar C$, the scaled mean value of the concentration over $\\Omega_1$ computed numerically, which we may consider as an approximation of the exact solution.\n\n\\textcolor{red}{todo : autres conditions initiales}\n\n\\subsection{Discrete-time compartment model} \\label{sec:dtcm}\nWhen there are more than two compartments, finding an analytic solution is not always possible and the methodology presented in the previous section cannot be applied. For this reason, another approach is proposed in this section. \n\\subsubsection{The method}\nHere a \\textit{discrete} interaction matrix $\\b A_{\\Delta t}$ is build based on a numerical simulation over a period $\\Delta t$. This methodology is thus far more general than the one presented in the previous section. It goes as follows: to compute the entry $[\\b A_{\\Delta t}]_{i,j}$, run a simulation over a period $\\Delta t$, with all the particles initially uniformly distributed over compartment $j$ (i.e. subdomain $\\Omega_j$). Let $P_0$ be the total number of particles, and $P_{j \\rightarrow i}(\\Delta t)$ the number of particles amongst those initially in compartment $j$ that end up in compartment $i$ after a time $\\Delta t$. The factor $\\frac{P_{j \\rightarrow i}(\\Delta t)}{P_0}$ is an approximation of the probability to go from compartment $j$ to compartment $i$ within a time period $\\Delta t$. But this probability is precisely given by $\\frac{|\\Omega_i|}{|\\Omega_j|}[\\b A_{\\Delta t}]_{i,j}$, as explained page \\pageref{page:probability_interpretation}. We have thus the approximation\n\\begin{equation} \\label{eq:A_approx_discr}\n\t[\\b A_{\\Delta t}]_{i,j} \\approx \\frac{P_{j \\rightarrow i}(\\Delta t)}{P_0}\\frac{|\\Omega_j|}{|\\Omega_i|}.\n\\end{equation}\nUsing that formula to compute an approximation of $\\b A_{\\Delta t}$, it is seen that properties~\\ref{prop1_discr_comp}, \\ref{prop2_discr_comp} and~\\ref{prop5_discr_comp} are always respected \\textit{a priori}. Properties~\\ref{prop3_discr_comp} and~\\ref{prop4_discr_comp} should by verified a posteriori.\n\\subsubsection{Results}\nIn a first instance, we can take advantage of the properties developed in section~\\ref{sec:dtcm(chapcomp)} to deduce the general form of $\\b A_{\\Delta t}$ for this problem. In the present case, $\\Omega_1$ and $\\Omega_2$ have the same size; this implies that property~\\ref{prop2_discr_comp} reduces to corollary~\\ref{corollary2}, and that property~\\ref{prop5_discr_comp} becomes equivalent to property~\\ref{prop4_discr_comp}. Putting everything together, the matrix $\\b A_{\\Delta t}$ that we search is a $2 \\times 2$ matrix whose entries are comprised between 0 and 1 and which satisfies $\\b 1^\\t \\b A_{\\Delta t} = \\b 1^\\t$ and $\\b A_{\\Delta t} \\b 1= \\b 1$. This implies that $\\b A_{\\Delta t}$ must have the following form:\n\\begin{equation} \\label{eq:generalformAdeltat}\n\t\\b A_{\\Delta t} = \\begin{pmatrix}\n\t\ta & 1-a\\\\ 1-a & a\n\t\\end{pmatrix},\n\\end{equation}\nfor some $a \\in [0,\\,1]$.\n\nThe discrete interaction matrix is approximated for $\\Delta t = 1$ year with $P_0 = 10\\ 000$. \\textcolor{red}{Mentionner l'étude de convergence, mais la rendre plus rigoureuse.} Using formula~\\eqref{eq:A_approx_discr}, we get\n\\begin{equation}\n\t\\b A_1 = \\begin{pmatrix}\n\t\t0.9839 & 0.0159 \\\\ \n\t\t0.0161 & 0.9841\n\t\\end{pmatrix}.\n\\end{equation}\nThis approximation of $\\b A_1$ does not exactly match the general form~\\eqref{eq:generalformAdeltat}. Hence, we improve that approximation by choosing $a$ as an average:\n\\begin{equation}\n\ta = \\frac{[\\b A_1]_{1,1} + (1-[\\b A_1]_{1,2}) + (1 - [\\b A_1]_{2,1}) + [\\b A_1]_{2,2}}{4} = 0.9840,\n\\end{equation}\nleading to\n\\begin{equation}\n\t\\b A_1^{discr,1} = \\begin{pmatrix}\n\t\t0.9840 & 0.0160 \\\\ \n\t\t0.0160 & 0.9840\n\t\\end{pmatrix},\n\\end{equation}\nwhich match the general form~\\eqref{eq:generalformAdeltat}. For any initial condition, we can now approximate the concentration in both compartments after $T$ years as\n\\begin{equation}\n\t\\b c^{discr,1}(T) = \\left(\\b A_1^{discr,1}\\right)^T \\b c(0).\n\\end{equation}\nThe resulting evolution of the concentration in compartment 1 is shown in figure~\\ref{fig:comparison_comp-real1} for the initial condition $\\b c(0) = (2\\bar C,0)^\\t$. Clearly, this result is not satisfying as the concentration decreases much too fast in compartment 1. Therefore, we propose another approach: recall from figure~\\ref{fig:staba75} that the two-communities clustering is returned by the stability method for times larger than (approximately) 50 years. This suggests that computing the discrete interaction matrix $\\b A_{50}$ could provide more interesting results. We get numerically\n\\begin{equation}\n\t\\b A_{50} = \\begin{pmatrix}\n\t\t0.8753 &   0.1206\\\\\n\t    0.1248  &  0.8795\n\t\\end{pmatrix},\n\\end{equation}\nwhich is corrected as\n\\begin{equation}\n\t\\b A_{50} = \\begin{pmatrix}\n\t\t0.87735 &   0.12265\\\\\n\t    0.12265  &  0.87735\n\t\\end{pmatrix}.\n\\end{equation}\nThis discrete interaction matrix only allows to compute the concentration at times that are multiples of 50 years. We have the approximation\n\\begin{equation} \\label{eq:cdiscr2}\n\t\\b c^{discr,2}(T) = \\left(\\b A_{50}\\right)^{\\frac{T}{50}} \\b c(0) \\qquad \\mbox{for } T = 0,50,100,\\dots\n\\end{equation}\nThe resulting evolution of the concentration in compartment 1 is also shown in figure~\\ref{fig:comparison_comp-real1}. The result is far better than with the first method. Notice that in this case, approximating $\\b A_1$ as\n\\begin{equation}\n\t\\b A_1^{discr,2} = \\left(\\b A_{50}\\right)^{\\frac{1}{50}},\n\\end{equation}\nyields\n\\begin{equation}\n\t\\b A_1^{discr,2} = \\begin{pmatrix}\n\t\t0.9972 & 0.0028 \\\\ \n\t\t0.0028 & 0.9972\n\t\\end{pmatrix}.\n\\end{equation}\nThe resulting approximation of the concentration is the same as in equation~\\eqref{eq:cdiscr2} but now we are able to compute the concentration in the compartments every year. Notice that this does not provide a general method to compute $\\b A_1$ since we have no a priori guarantee that the entries of $(\\b A_{\\Delta t})^{\\frac{1}{\\Delta t}}$ are real.\n\nThis section presents a procedure to numerically estimate the discrete transition matrix $\\b A_{\\Delta t}$ for any time step $\\Delta t$. However, the bad results obtained with our first estimation of $\\b A_1$ show that the choice of $\\Delta t$ is crucial. Let $[t_a,\\, t_b]$ denote the time range at which the clustering chosen to delineate the subdomains is found by the stability method. The results of this section suggest that $\\Delta t = t_a$ could be a satisfying choice. Unfortunately, no conclusion can be drawn based only on this simple example, and the method would need to be applied on more complicated problems.\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{fig/problem2box/C1vsC1tilde1_1000years2.eps}\n\t\\caption{Comparison of the different compartment model solutions with the numerical solution for the initial condition $C_1(0) = 2\\bar C$.}\n\t\\label{fig:comparison_comp-real1}\n\\end{figure}", "meta": {"hexsha": "dcd533251cfdd2fec1c455037684ecd74eef7947", "size": 33141, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/bi-overturner/problem2box.tex", "max_stars_repo_name": "dufaysr/tfe", "max_stars_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inputs/bi-overturner/problem2box.tex", "max_issues_repo_name": "dufaysr/tfe", "max_issues_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inputs/bi-overturner/problem2box.tex", "max_forks_repo_name": "dufaysr/tfe", "max_forks_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 101.3486238532, "max_line_length": 2159, "alphanum_fraction": 0.7448477716, "num_tokens": 9637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218866, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7139700033799928}}
{"text": "\\chapter{Precision issues and epsilons}\n\nComputational geometry very often means working with floating-point values. Even when the input points are all integers, as soon as intermediate steps require things like line intersections, orthogonal projections or circle tangents, we have no choice but to use floating-point numbers to represent coordinates.\n\nUsing floating-point numbers comes at a cost: loss of precision. The number of distinct values that can be represented by a data type is limited by its number of bits, and therefore many ``simple'' values like $0.1$ or $\\sqrt{2}$ cannot be exactly represented. Worse, even if $a$ and $b$ are exact, there is no guarantee that simple operations like $a+b$, $a-b$ or $ab$ will give an exact result.\n\nThough many people are well aware that those issues exist, they will most often argue that they only cause small imprecisions in the answer in the end, and do not have any major consequence or the behavior of algorithms. In the rest of this chapter, we will show how both those assumptions can sometimes be false, then present some ways in which we \\emph{can} make accurate statements about how precision loss affects algorithms, go on with a few practical examples, and finally give some general advice to problem solvers and setters.\n\n\\input{precision/small-big}\n\\input{precision/small-break}\n\\input{precision/modelling}\n%\\subsection{Notations}\n%\\todo{}\n\\input{precision/cases}\n\\input{precision/advice}\n", "meta": {"hexsha": "91ddca6205f1c5ca25da9645b5499052f819312a", "size": 1457, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/precision/ch-precision.tex", "max_stars_repo_name": "cbarnson/UVa", "max_stars_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_stars_repo_licenses": ["Unlicense", "MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-07T17:00:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-05T02:08:35.000Z", "max_issues_repo_path": "archives/codelibraries/cp-geo-master/precision/ch-precision.tex", "max_issues_repo_name": "cbarnson/UVa", "max_issues_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_issues_repo_licenses": ["Unlicense", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "archives/codelibraries/cp-geo-master/precision/ch-precision.tex", "max_forks_repo_name": "cbarnson/UVa", "max_forks_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_forks_repo_licenses": ["Unlicense", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 91.0625, "max_line_length": 535, "alphanum_fraction": 0.7927247769, "num_tokens": 312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603726, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.7138866963630681}}
{"text": "\\section*{Introduction}\nIn this chapter, generalities about systems of Partial Differential Equations (PDEs) are first introduced. More specifically, the notions of \\textit{characteristics} and \\textit{hyperbolicity} for PDEs are introduced in section \\ref{sec:PDEs} for first-order systems, which will be of particular interest in the remainder of the manuscript.\nThen, introduction of balance laws of solid dynamics and derivation of constitutive equations from the thermodynamics in section \\ref{sec:solidMech_equations}, lead to first-order hyperbolic PDEs.\nBy using tools introduced in section \\ref{sec:PDEs}, the characteristic analysis of these systems is carried out in section \\ref{sec:characteristic_analysis} in order to derive exact solutions of particular problems in section \\ref{sec:riemann_problems}. These solutions allow the highlighting of different types of waves: (i) discontinuous waves, governed by the \\textit{Rankine-Hugoniot} jump condition, within one-dimensional linear elastic and elastic-plastic media (ii) shock waves, also following the Rankine-Hugoniot condition, and simple waves, within a non-linear problem (one-dimensional strain state in a \\textit{Saint-Venant-Kirchhoff} hyperelastic medium).\nAt last, strategies enabling the computation of approximate solutions of non-linear problems are reviewed in section \\ref{sec:riemann_solvers}.\n\n\n\\section{Generalities -- Hyperbolic partial differential equations}\n\\label{sec:PDEs}\n\\input{chapter2/PDEs}\n\n\\section{Governing equations of solid mechanics}\n\\label{sec:solidMech_equations}\n\\input{chapter2/conservationLaws}\n\n\n\\section{Characteristic analysis -- Structure of solutions}\n\\label{sec:characteristic_analysis}\n\\input{chapter2/characteristicAnalysis}\n\n\\section{Some solutions of Riemann problems}\n\\label{sec:riemann_problems}\n\\input{chapter2/exact_solutions}\n\\section{Approximate--State Riemann solvers}\n\\label{sec:riemann_solvers}\n\\input{chapter2/riemann_solvers}\n\n\\section{Conclusion}\nIt has been seen in this chapter that solid dynamics balance equations can be written as a first order hyperbolic system whose theory has been recalled in section \\ref{sec:PDEs}.\nIndeed, the thermodynamics framework assuming generalized standard materials combined with conservation laws allowed in section \\ref{sec:solidMech_equations} the building of conservative or quasi-linear forms.\nThose systems of partial differential equations admit non-complex eigenvalues and independent eigenvectors provided that some requirements on the stored energy function are satisfied (positive definiteness of the acoustic tensor).\nThen, the characteristic analysis of the quasi-linear form in section \\ref{sec:characteristic_analysis} enabled the highlighting of specific wave types involved in the solutions of dynamic problems, that is: discontinuous, shock and simple waves.\nEven though exact solutions of linear and non-linear problems have been developed in section \\ref{sec:riemann_problems}, it is not possible in general, hence the introduction of approximate-state Riemann solvers in section \\ref{sec:riemann_solvers}.\nThis solution strategy will be used in what follows as an element of the \\textit{Discontinuous Galerkin Material Point Method}, which is the object of the next chapter.\n\n%%% Local Variables:\n%%% mode: latex\n%%% ispell-local-dictionary: \"american\"\n%%% TeX-master: \"../mainManuscript\"\n%%% End:\n", "meta": {"hexsha": "be832ae19c76e477f28bea9648da477c76a5be80", "size": 3384, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/chapter2/mainChapter2.tex", "max_stars_repo_name": "adRenaud/research", "max_stars_repo_head_hexsha": "2f0062a1800d7a17577bbfc2393b084253d567f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-18T14:52:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-18T14:52:03.000Z", "max_issues_repo_path": "manuscript/chapter2/mainChapter2.tex", "max_issues_repo_name": "adRenaud/research", "max_issues_repo_head_hexsha": "2f0062a1800d7a17577bbfc2393b084253d567f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-01-07T13:11:11.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-07T13:11:11.000Z", "max_forks_repo_path": "manuscript/chapter2/mainChapter2.tex", "max_forks_repo_name": "adRenaud/research", "max_forks_repo_head_hexsha": "2f0062a1800d7a17577bbfc2393b084253d567f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 82.5365853659, "max_line_length": 669, "alphanum_fraction": 0.8194444444, "num_tokens": 748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8459424295406087, "lm_q1q2_score": 0.713886673332411}}
{"text": "An instance of an inference system begins by defining the set of recognized keywords and operators. Keywords and operators all have an ariety, a class to which they belong, and a priority level to define how lack of parentheses should be interpreted. As an example we will consider the unary notation for defining natural numbers. \n\n\\subsection{Inductive definition of natural numbers}\nNatural numbers (\\texttt{Num}) in the \\textit{unary notation}, also known as \\textit{Peano numbers}, are defined in terms of one zero value (\\texttt{z}), which does not take anything as input and one successor value (\\texttt{s}), which takes as input another number\\footnote{The successor of a natural number is that number plus one, thus \\texttt{s(a)} can be seen as intuitively equivalent to \\texttt{a+1}. A word of warning: we are implying a distinction here between the operation \\texttt{+1}, which is an elementary operation that we always know how to perform in a single step, and arbitrary addition of potentially large numbers: although the two operations both use the same symbol \\texttt{+}, \\textbf{they are not the same!}}\n\n\\begin{lstlisting}\nData [] \"z\" []    Priority 2  Type Num\nData [] \"s\" [Num] Priority 3  Type Num\n\\end{lstlisting}\n\nWith the keywords above it becomes possible to express some natural numbers. A few examples are:\n\\begin{description}\n\\item[0] \\texttt{z}\n\\item[1] \\texttt{s(z)}\n\\item[2] \\texttt{s(s(z))}\n\\item[3] \\texttt{s(s(s(z)))}\n\\end{description}\n\nAll the examples above are \\textit{expressions}, because they only use keywords and composition of keywords. We could also define \\textit{patterns}, which can be informally considered as ``expressions with holes'', where the holes are symbols that may be replaced with any valid expression. Consider pattern \\texttt{s(s(a))}, which is the pattern that describes the ``successor of the successor of \\texttt{a}'', whatever \\texttt{a} will be. Possible expressions that may generated from this pattern are:\n\n\\begin{itemize}\n\\item \\texttt{s(s(z))}, for \\texttt{a = z}\n\\item \\texttt{s(s(s(z)))}, for \\texttt{a = s(z)}\n\\end{itemize}\n\nWe call expressions that may generated from a pattern \\textit{instances}. We can consider a pattern as a function that takes one or more expressions as parameters and returns a resulting expression.\n\n\\subsection{Expressions of natural numbers}\nNatural numbers may be composed together to form expressions. An expression is defined recursively as the sum of two expressions, \\texttt{+}, or the product of two expressions \\texttt{*}:\n\n\\begin{lstlisting}\nFunc [Expr] \"+\" [Expr] Priority 0  Type Expr => Num\nFunc [Expr] \"*\" [Expr] Priority 1  Type Expr => Num\n\\end{lstlisting}\n\nNotice that numbers were defined in the above as belonging to class \\texttt{Num}, whereas addition and multiplication belong to the class \\texttt{Expr}, and both expect an \\texttt{Expr} to the right and an \\texttt{Expr} to the left. So far thus it would be impossible to use numbers as built with \\texttt{s} and \\texttt{z} as left and right parameters of \\texttt{+} and \\texttt{*}. In order to connect these two sets of keywords we can specify a relationship between \\texttt{Num} and \\texttt{Expr}, namely that a \\texttt{Num} can be used where an \\texttt{Expr} is expected. We can do so with the following code:\n\n\\begin{lstlisting}\nNum is Expr\n\\end{lstlisting}\n\nThe \\texttt{is} operator plays a role that is akin to that of the inheritance operators found in object-oriented languages.\\footnote{To be precise, this is an example of \\textit{subtype polymorphism}.}\n\nMultiplication takes syntactic precedence over addition, thus we can be slightly less verbose with parentheses just like with the usual definitions of addition and multiplication.\n\nValid expressions written in this notation could be:\n\n\\begin{itemize}\n\\item \\texttt{z + z}\n\\item \\texttt{s(z) + s(z)}\n\\item \\texttt{z + s(z)}\n\\item \\texttt{s(s(z)) * s(s(z))}\n\\end{itemize}\n\nWe can also define patterns such as:\n\n\\begin{itemize}\n\\item \\texttt{z + a}, the addition of \\texttt{z} and an arbitrary expression \\texttt{a}\n\\item \\texttt{s(z) + s(a)}, the addition of \\texttt{s(z)} and the successor of an arbitrary expression \\texttt{a}\n\\end{itemize}\n\n\\subsection{Addition as repeated succession}\nThere is no intrinsic difference between keywords such as \\texttt{s} and \\texttt{z}, and keywords such as \\texttt{+} and \\texttt{*}, even though one might be tempted to think that only because we used symbols commonly known in arithmetics then they will have their usual meaning here as well. It is very important to realize that this is not the case. We could have just as easily used other symbols such as \\texttt{++} for multiplication and \\texttt{?} for addition, or anything else we might have fancied. The inference system assumes no prior meaning of symbols, and indeed we are not forced in any way to follow the usual rules of engagement known for numbers. Nevertheless, to reduce the confusion, we will indeed follow such conventions. \n\nWe will now assign meaning to the various symbols we just defined. This will allow us to perform transformations on our expressions, in order to perform computations on numbers. We do so by specifiying a \\textit{set of rules}. Let us begin with addition.\n\nWe can very easily state that adding zero (\\texttt{z}) to an arbitrary number \\texttt{a} will result in \\texttt{a} itself, without any further steps. We express this as a rule without premises as follows:\n\n\\begin{lstlisting}\n-----------\nz + a => a\n\\end{lstlisting}\n\nThe lack of premises above the horizontal bar means that as soon as the inference system recognizes a pattern of the form \\texttt{z+a}, then it will immediately yield \\texttt{a} as the output result.\n\nSuppose now that we add a number which is not zero to another arbitrary number. Since we are dealing with natural numbers, this means that a non-zero number will always be at least one, thus it will be at least one application of \\texttt{s} to some arbitrary number. The input pattern that describes this set of circumstances would be \\texttt{s(a) + b}. Given this pattern it is not immediately possible to derive a result: rather, we must decompose the determination of the result into a series of intermediate steps. As a first step, we add \\texttt{a} and \\texttt{b} together. Then we can return the result by appliying the successor operation once to the result. We can express this as a single premise:\n\n\\begin{lstlisting}\na + b => c\n-----------------\ns(a) + b => s(c)\n\\end{lstlisting}\n\nNotice that the above is exactly equivalent to the following very simple equation:\n\n$$(a+1) + b = (a+b)+1$$\n\nwhere $a+b$ is an intermediate value called \\texttt{c}, and $a+1$ is the successor of \\texttt{a}, thus \\texttt{s(a)}.\n\n\n\\subsubsection{Termination proof (informal sketch)}\nOne might be tempted to wonder how such a blatantly cyclical definition would ever be able to reach any useful conclusion. After all we are defining addition in terms of another addition: does this not equate to ``looping forever''?\n\nWe can show, inductively, that we have no infinite looping. Let us define the \\texttt{height} of an addition \\texttt{a + b} as the number of applications of \\texttt{s} within \\texttt{a}. For example:\n\n\\begin{itemize}\n\\item \\texttt{height(z + z)} is $0$\n\\item \\texttt{height(z + s(z))} is $0$\n\\item \\texttt{height(s(z) + z)} is $1$\n\\end{itemize}\n\nThe \\textbf{base case} of our proof is that of height equal to $0$. This means that our addition takes \\texttt{z} as a first parameter, and thus rule \n\n\\begin{lstlisting}\n-----------\nz + a => a\n\\end{lstlisting}\n\ncan be applied. Addition terminates in this case, yielding the second term as a result.\n\nThe \\textbf{inductive case} of our proof is that of height equal to $n>1$. This means that our addition takes \\texttt{s(a)} as a first parameter. We cannot apply the previous rule, but we can apply the second:\n\n\\begin{lstlisting}\na + b => c\n-----------------\ns(a) + b => s(c)\n\\end{lstlisting}\n\nThis rule will terminate only if \\texttt{a + b => c} terminates. Given that \\texttt{height(a + b)} is $n-1$, because of the induction hypothesis we can assume its evaluation will terminate as well. Evaluation of \\texttt{s(c)} is just a trivial step which does not pose any risk of recursive behaviour, and thus we can conclude that indeed the process will terminate.\n\n\\subsubsection{Example of addition execution}\nConsider the following addition: \\texttt{s(s(z)) + s(z)}. Let us see how it is evaluated. First we see which rules we can apply. Clearly the first term is not \\texttt{z}, thus we must apply\n\n\\begin{lstlisting}\na + b => c\n-----------------\ns(a) + b => s(c)\n\\end{lstlisting}\n\nwhere \\texttt{a = s(z)} and \\texttt{b = s(z)}. Let us perform this replacement:\n\n\\begin{lstlisting}\ns(z) + s(z) => c\n-----------------\ns(s(z)) + s(z) => s(c)\n\\end{lstlisting}\n\nWe cannot directly determine \\texttt{c}, but we can use \\texttt{s(z) + s(z)} as the current expression to evaluate.  Since the first operand of the intermediate addition is not \\texttt{z}, then we have to apply the same rule again, this time with \\texttt{a = z} and \\texttt{b = s(z)}:\n\n\\begin{lstlisting}\nz + s(z) => c'\n--------------------\ns(z) + s(z) => s(c')\n---------------------- c = s(c')\ns(s(z)) + s(z) => s(c)\n\\end{lstlisting}\n\nNotice that the result of the second application of the rule will yield its own result, which we called \\texttt{c'} to disambiguate it with the result of the first application. The successor of the result of the second application will be the result of the intermediate application of the first rule, thus we could also write:\n\n\\begin{lstlisting}\nz + s(z) => c'\n--------------------\ns(z) + s(z) => s(c')\n---------------------------\ns(s(z)) + s(z) => s(s(c'))\n\\end{lstlisting}\n\nNow we can apply rule \n\n\\begin{lstlisting}\n-----------\nz + a => a\n\\end{lstlisting}\n\nto the current expression to evaluate, which is \\texttt{z + s(z)}, for \\texttt{a = s(z)}. This leads us to finding out that \\texttt{c' = a = s(z)}, thus yielding:\n\n\\begin{lstlisting}\nz + s(z) => s(z)\n--------------------\ns(z) + s(z) => s(s(z))\n---------------------------\ns(s(z)) + s(z) => s(s(s(z)))\n\\end{lstlisting}\n\nLet us take a quick step back and realize that \\texttt{s(s(z))} is the successor of the succcessor of zero, that is $2$, and \\texttt{s(z)} is the successor of zero, that is $1$. Their sum, as computed by our system, is \\texttt{s(s(s(z)))}, that is $3$, precisely as we would have expected given common arithmetic sense.\n\n\n\\subsection{Multiplication as repeated addition}\nMultiplication is defined in a way that is very similar to addition. We start with a base case of multiplication that we know how to solve immediately. From basic arithmetic we know that multiplication of zero and an arbitrary number always yields zero, thus:\n\n\\begin{lstlisting}\n-----------\nz * a => z\n\\end{lstlisting}\n\nFor the intermediate step, we will use the same decomposition technique that we used for addition. The input pattern will thus be multiplication of a number greater than zero, \\texttt{s(a)}, and an arbitrary number \\texttt{b}: \\texttt{s(a) * b}. To solve this multiplication, first we will multiply \\texttt{a} and \\texttt{b} together (remember the termination proof that we saw for addition: \\texttt{height(a) < height(s(a))}, therefore we expect this smaller multiplication to terminate), and then we add \\texttt{b} to the result:\n\n\\begin{lstlisting}\na * b => c\nc + b => d\n--------------\ns(a) * b => d\n\\end{lstlisting}\n\nNotice that the above is exactly equivalent to the following very simple equation:\n\n$$(a+1) \\times b = (a \\times b) + b$$\n\nwhere $a \\times b$ is an intermediate value called \\texttt{c}.\n\n\n\\subsection{Resolving nested operations}\nSo far we have only defined operators between numbers. As a further level of sophistication, we could define a stronger version of our operations that do not only work with numbers, but rather with arbitrarily nested operations. This means that we wish to be able to support expressions of the form \\texttt{a+b+c}, which we currently have not specified how to solve.\n\nWe begin with the definition of a new operator which will be responsible for the recursive exploration of an expression in order to resolve its inner operations:\n\n\\begin{lstlisting}\nFunc = \"!\" LeftArguments = [] RightArguments = [Expr] Priority = 1 Type = Expr => Num\n\\end{lstlisting}\n\nAs a base case we can say that if we encounter a number, then \\texttt{!} simply returns it as it was:\n\n\\begin{lstlisting}\n--------\n!z => z\n\n---------------\n!(s a) => s a\n\\end{lstlisting}\n\nThe inductive step, on the other hand, works with operations and ensures that both operands have been simplified to numbers before performing the actual operation:\n\n\\begin{lstlisting}\n!a => a'\n!b => b'\na' + b' => c\n--------------\n!(a + b) => c\n\n!a => a'\n!b => b'\na' * b' => c\n--------------\n!(a * b) => c\n\\end{lstlisting}\n\nThe two rules above are relatively straightforward, and require no change in the definition of addition and multiplication. Thanks to these rules, we can now solve a complex input expression such as \\texttt{!(((s(s(z))) * (s(s(z)))) * (s(s(z)) + s(z)))}, equivalent to $2 * 2 * (2 + 1)$), and obtaining as a result the expected \\texttt{(s(s(s(s(s(s(s(s(s(s(s(sz))))))))))))}, which is $12$.\n\n\n\\subsection{Closing considerations}\nThe natural numbers example that we have just seen is very important. Its importance is not of a practical nature, since natural numbers are well known and moreover unary encoding is one of the least efficient ways to manipulate numbers. The importance of the example above is rather conceptual: armed with only the most basic constructs of logical derivation, a highly abstract concept, we have built something that is very concrete and apparently unrelated.\n\nThe process of logical derivation is indeed very powerful. In the following we will use it to define increasingly complex systems. We will begin by reformulating integer numbers with the well-known \\textit{binary encoding}. Then we will show how to manipulate sequences of things, in order to dispose over more complex data structures. Finally, we will build a small imperative language interpreter and its type system. Finally, we will explore the consequences of having implemented a full-blown programming language within our logical system.\n", "meta": {"hexsha": "a8f73496fd7e2330538bb7d193aa520498ecf658", "size": 14262, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Course materials/Dictaat/tex/Examples/peano_numbers.tex", "max_stars_repo_name": "vs-team/metacompiler", "max_stars_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-12-13T09:22:28.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-03T21:48:11.000Z", "max_issues_repo_path": "Course materials/Dictaat/tex/Examples/peano_numbers.tex", "max_issues_repo_name": "cult-of-giuseppe/metacompiler", "max_issues_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2015-08-14T06:48:43.000Z", "max_issues_repo_issues_event_max_datetime": "2015-08-16T09:37:03.000Z", "max_forks_repo_path": "Course materials/Dictaat/tex/Examples/peano_numbers.tex", "max_forks_repo_name": "cult-of-giuseppe/metacompiler", "max_forks_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-10-11T17:13:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-10T19:12:15.000Z", "avg_line_length": 58.4508196721, "max_line_length": 744, "alphanum_fraction": 0.7270368812, "num_tokens": 3577, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970811069351, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7138674530235104}}
{"text": "\\chapter{\\label{ch:fsa}Finite state automata and regular languages}\n\nThe regular languages, the simplest class of languages\nwe defined in Chapter~\\ref{ch:formal-languages},\nand the corresponding abstract machines, finite state automata (FSA), \nhave many practical uses ranging from circuit design to string search.\nThey are also an important tool for computational linguistics.\nIn this chapter we will study FSA and regular languages.\n\n%TODO: applications - dictionaries, shallow parsing ...\n\n%TODO: link to regular expressions\n\n\\section{Finite state automata}\n\nA finite state automaton is an abstract machine with a finite number of states.\nThe machine can be in one of the states in a given time,\nand it changes its sates as it processes an input string\nfrom a finite alphabet.\nIf the machine is in one of final or accepting states at the end of the input,\nit accepts the string.\nAs noted earlier, finite state automaton\nrecognize and generate regular languages.\nA finite state automaton accepts all and the only strings\nthat are in the corresponding regular language.\n\n\\begin{marginfigure}\n  \\begin{center}\n    \\tikzset{external/export next=false}\n    \\begin{tikzpicture}[every initial by arrow/.style={thick},\n      ]\n      \\node[draw,state,initial,initial text={}] at (0,0) (s0) {0};\n      \\node[draw,above right=of s0,state] (s1) {1};\n      \\node[draw,below right=of s0,state,accepting] (s2) {2};\n      \\draw[->,thick,>=stealth]\n                (s0) edge[above,bend left] node (nl) {b} (s1)\n                (s0) edge[below,bend right] node{a} (s2)\n                (s1) edge[loop above] node{b} (q1);\n      \\draw[->,thick,>=stealth]\n                (s1) edge[right,bend left=90] node{c} (s2);\n      \\node[blue] at (-1, -1) (ilab) {initial state};\n      \\draw[blue,->,shorten >=1pt]  (ilab) to[bend right] (s0);\n      \\node[blue] at (-1, 1) (tlab) {transition};\n      \\draw[blue,->,shorten >=1pt]  (tlab) to[bend left] (nl.south);\n%      \\draw[blue,->,shorten >=1pt]  (tlab) to[bend left] ($(s0)!0.5!(s1)$);\n      \\node[blue] at (0, 2) (slab) {state};\n      \\draw[blue,->,shorten >=1pt]  (slab.east) to[bend left] (s1.north west);\n      \\node[blue] at (0, -2) (flab) {accepting state};\n      \\draw[blue,->,shorten >=1pt]  (flab) to[bend right] (s2);\n    \\end{tikzpicture}\n  \\end{center}\n    \\caption{\\label{fig:example-fsa}%\n      An example finite-state machine.\n    }\n\\end{marginfigure}\nA common way to think about (and represent) an FSA is a directed graph,\nwhere the nodes correspond to the states,\nand edges are labeled with the symbols from the alphabet.\nFigure~\\ref{fig:example-fsa} presents an FSA represented as\na directed graph.\nThe machine starts at the start state (marked with an incoming arrow)\nand moves between the states based on the given input.\nIf the machine is in a final state\n(represented as a double circle)at the end of the input,\nthe input string is accepted.\n\n\\subsection{Deterministic finite automata}\nFormally, a finite state automaton, $M$,\nis a tuple $(\\Sigma,Q, q_{0}, F, \\Delta)$ with\n\n\\begin{itemize}[nosep]\n  \\item[$\\Sigma$] is the alphabet, a finite set of symbols\n  \\item[$Q$] a finite set of states\n  \\item[$q_{0}$] is the start state, $q_{0} \\in Q$\n  \\item[$F$] is the set of final states, $F \\subseteq Q$\n  \\item[$\\Delta$] is a function that takes a state and a symbol in the alphabet,\n    and returns another state ($\\Delta: Q\\times\\Sigma \\ra Q$)\n\\end{itemize}\n\nThe important part of the this definition is the last item,\ntranslates to the requirement that given a state and a symbol,\nthere is only one possible state to go.\nAs a result,\na deterministic automata requires\nexactly one edge labeled by each symbol in the alphabet leaving every state.\n", "meta": {"hexsha": "bb1bd7cecdf6fbaca7e2284d4c7f2e24f80dbd05", "size": 3694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "finite-state.tex", "max_stars_repo_name": "coltekin/snlp-notes", "max_stars_repo_head_hexsha": "02dddcda0a8ff24f959675f0ad6a9079d573f49b", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-08-05T12:58:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-21T14:17:47.000Z", "max_issues_repo_path": "finite-state.tex", "max_issues_repo_name": "coltekin/snlp-notes", "max_issues_repo_head_hexsha": "02dddcda0a8ff24f959675f0ad6a9079d573f49b", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "finite-state.tex", "max_forks_repo_name": "coltekin/snlp-notes", "max_forks_repo_head_hexsha": "02dddcda0a8ff24f959675f0ad6a9079d573f49b", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.9534883721, "max_line_length": 80, "alphanum_fraction": 0.6954520845, "num_tokens": 1076, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970811069351, "lm_q2_score": 0.8104789040926007, "lm_q1q2_score": 0.7138674530235103}}
{"text": "\\lab{Algorithms}{Recursion and Persistent Variables}{Recursion and Persistent Variables}\n\n\\objective{We will briefly discuss an important technique in programming known as recursion. Then we will discuss the use of persistent variables in MATLAB.}\n\nA recursive function is one that calls itself. For example we could write a factorial function as follows:\n\n\\begin{lstlisting}[style=matlab]\nfunction out = myFactorial(n)\nif n ~= 1\n     out = n*factorial(n-1);\nelse\n     out = 1;\nend\n\\end{lstlisting}\n\nThis function calculates factorial recursively. It calls \\li{factorial(n-1)} until $n = 1$, at which point each function finally terminates.\n\nOne critical aspect of this code is the fact that if n == 1, out = 1. This is known as the base case. The base case is the case where the recursion breaks down, or in other words where the function stops calling itself. Every recursive algorithm must have some sort of base case, or else it will call itself indefinitely.\n\nIn fact this function only works on positive integers. On any other input the function never terminates. Thus we should modify the function as follows to avoid problems:\n\n\\begin{lstlisting}[style=matlab]\nfunction out = myFactorial(n)\nif (n <= 0 || rem(1,n) ~= 0)\n\terror('input must be a positive integer');\nend\n\t\nif n ~= 1\n     out = n*factorial(n-1);\nelse\n     out = 1;\nend\n\\end{lstlisting}\n\nThis practice (of writing code to handle bad user input) is known as defensive programming. It is good to get into this habit.\n\nHere's a simple combinatoric example. Suppose our goal is to enumerate every possible way to select six numbers out of a list of ten (note that we are talking combinations not permutations). We could use some sort of complicated \\li{for} loop structure like this:\n\n\\begin{lstlisting}[style=matlab]\nfor i = ...\n    for j = ...\n        for k = ...\n            for l = ...\n            .\n            .\n            .\n\\end{lstlisting}\n\nHowever, we wish to stress emphatically, that this is not the right way to do any problem ever. Once you write more than three for loops you are probably skirting on the edges of intractability (in fact, any time you attack a problem that suggests this approach you are likely attacking a problem that is inherently intractable). However, oftentimes such a problem can at least be programmed using recursion.\n\nFor example in our combinatorics problem above we could write something like the following:\n\n\\begin{lstlisting}[style=matlab]\nfunction out = Combinations(values,k)\n%This functions outputs all possible combinations of k elements from the\n%vector values.\nif min(size(values)) ~= 1\n    error('values must be a vector');\nend\nif k > length(values)\n    error('k must be smaller than length(values)');\nend\nif (k <=0 || mod(k,1) ~= 0) \n    error('k must be a positive integer'); \nend\n\n%Make input vectors column vectors\nif size(values,2) > size(values,1)\n    values = values';\nend\n\nout = []; \nn = length(values); \nif k == 1\n    out = values; \nelse\n    \n%This loop iterates through all of elements of the vector values that have at least k\n%elements after them (inclusive). For each element it then calls\n%Combinations(values(i+1:end),k-1), which returns combinations of size k-1\n%for the elements succeeding the current element. This is so that we do not\n%get repeats of combinations.\nfor i = 1:n-(k-1)\n    % Calculate the number of possible combinations (to allow proper\n    % concatenation in the recursive call.\n    numCombs = factorial(n-i)/((factorial(k-1))*(factorial(n-i-(k-1))));\n    %This is the recursive call.\n    out = [out;[values(i)*ones(numCombs,1), Combinations(values(i+1:end),k-1)]];\nend\nend\n\\end{lstlisting}\n\nThis solution utilizes recursion to make the coding much more simple. Write this code up and understand why it does what it does, and how the recursion works.\n\nOne note of importance: just because a recursive algorithm exists does not mean that it is the correct way to solve the problem. The factorial example makes this readily evident. Generally speaking recursion slows things down, so it should be avoided when possible. However, it can provide elegant solutions to difficult problems, and is a good arrow to have in your quiver.\n\n\\begin{problem}\nUse recursion to calculate the determinant of a matrix using cofactor expansions (this is known as Laplace's formula). This can be done in four lines. You can see how simple recursive programs can be. Now time your function and compare its performance to finding the determinant using the LU decomposition that you wrote earlier. How does it fare? You will probably notice that the recursive method is much slower for even moderate values of n. Why is this? Laplace's formula is $O(n!)$, so even though it's very easy to code it's terribly ineffective in general.\n\\end{problem}\n\n\\section*{Persistent Variables}\n\nOne of the crucial concepts in computer programming is known as scoping. A variable's scope is the function that it lives in. When we write functions the only variables that we have to worry about are the ones that are passed into it. This is because my function has its own scope. A variable that only lives in a specific function (as most variables should) is known as a local variable.\n\nPersistent variables are a tool that MATLAB uses to ease program complexity. A local variable that is declared to be persistent will have the same value the next time the parent function is called. We will illustrate using a function that calculates the fibonacci numbers. In this example we will also practice using recursive functions.\n\nWrite the following function:\n\n\\begin{lstlisting}[style=matlab]\nfunction out = fib1(a,b,n)\n%% calculate the nth fibonacci number using the seeds a,b\nif n ==1\n\tout = a;\nelse if n == 2\n        out = b;\nelse\n        out = fib1(a,b,n-1) + fib1(a,b,n-2);\nend\n\\end{lstlisting}\n\nThis function is very easy to read, and directly applies the recursive definition of the fibonacci sequence. However, there is a problem. Consider the function calls made for $n=5, a = 1, b = 1$:\n\n\\begin{align*}\nfib(5) &= fib(4) + fib(3) = (fib(3) + fib(2)) + (fib(2) + fib(1)) \\\\\n       &= ((fib(2) + fib(1)) + fib(2)) + (fib(2) + fib(1))\n\\end{align*}\n\nIt is clear that many calculations are being repeated unnecessarily. One possible way to solve this problem is to use a \\li{for} loop instead. Try writing the following function:\n\n\\begin{lstlisting}[style=matlab]\nfunction out = fib2(a,b,n)\n%% calculate the nth fibonacci number using the seeds a,b\nif n == 1\n\tout = a;\nelse if n == 2\n        out = b;\nelse\n        x = [a b];\n        for i = 1:n-2\n            x = [b sum(x)];\n        end\n        out = x(2);\nend\n\\end{lstlisting}\n\nThis version has the advantage that there are no repeated calculations. However, suppose that we are expecting a and b to usually remain the same. Each time \\li{fib} was called all of the calculations would have to be redone. This is where persistent variable can be useful. If a variable is declared persistent its value will be stored for the next time the function is called. In this example we can store the entire fibonacci sequence as a persistent variable and only recalculate as necessary. The following code implements this approach:\n\n\\begin{lstlisting}[style=matlab]\nfunction out = fib3(a,b,n)\n%% calculate the nth fibonacci number using the seeds a,b\npersistent f\nif length(f) < 2 || f(1) ~= a || f(2) ~= b\n    f = [a b];\nend\nfor k = (length(f) + 1):n\n    f(k) = f(k-2) + f(k-1);\nend\nout = f(n);\n\\end{lstlisting}\n\nTest this code out. Try testing its performance against the other versions (you could try calculating the same fibonacci number several thousand times). You should see a significant difference.\n\nWe finish this section with a word of caution. Persistent variables require significant overhead, and accessing them is much slower than accessing normal variables. They should accordingly be used sparingly.\n\n\\begin{problem}\nUse persistent variables to speed up the calculations of the \\li{expss} function that you wrote in chapter one (hint: certain operations, such as factorial, are costly). Test your new function's performance against the old one. How does it perform?\n\\end{problem}\n\n\\begin{problem}\nCompare the performance of the \\li{fib3} versus \\li{fib2}, when the seeds are random every time. You should run it several thousand times in your test. What do you notice? \\li{fib3} is much slower because accessing a persistent variable is very costly. This reminds us that using persistent variables should be avoided in most situations.\n\\end{problem}\n", "meta": {"hexsha": "d3093c6a22174a1c2ca463ff082fd0d6da2b27a1", "size": 8521, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/RecursionM/Recursion.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/RecursionM/Recursion.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/RecursionM/Recursion.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-21T23:06:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-21T23:06:27.000Z", "avg_line_length": 49.5406976744, "max_line_length": 563, "alphanum_fraction": 0.73981927, "num_tokens": 2044, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8807970748488297, "lm_q1q2_score": 0.7138674519834919}}
{"text": "\\lab{Algorithms}{Value Function Iteration}{Value Function Iteration}\n\n\\objective{This section teaches the fundamentals of Dynamic Programming using value function iteration.}\n\nOften it is of interest to optimize decision making in some sequential process.  For example, an oil company may need to decide how much oil to excavate and sell each month as prices change, a person entering retirement may need to decide how much of their savings to spend each year, or a model of economic growth may require a decision about how much to invest in capital versus how much to spend each year.  In this lab we will formulate a general dynamic optimization problem.  We will explore techniques for solving such a problem with both finite and infinite time horizons.\n\n\\section*{The Sequential Problem, Finite Horizon}\n\\label{SecRecProbFinHor}\nSuppose there are time periods $t=0,1,\\ldots, T$ and at each time period we take an action $c_t$. Furthermore, at the beginning of each time period $t$ we are in some state $W_t$.  In many cases $W_t$ might represent an available resource, such as money.  At each time we receive some reward, $u(W_t,c_t)$, for taking action $c_t$ given state $W_t$.  We assume that rewards are worth more now than later. We let $\\beta\\in (0,1)$ represent what is called the discount factor and gives the ratio of preference for rewards today versus rewards tomorrow.  For example, receiving a dollar today is preferable to receiving a dollar in a year because taking a dollar today and putting it in a  savings account results in having more than a dollar in a year.  Lastly, over time our state variable $W_t$ changes according to some rule depending on the previous state and our actions,\n\\begin{equation}\n\\label{motion}\nW_{t+1} = g(W_t,c_t).\n\\end{equation}\nEquation \\eqref{motion} is sometimes referred to as the law of motion, as it describes how we move from state to state.\nMathematically such a problem can be represented as follows:\n\\begin{equation*}\n\\max \\sum_{t=0}^T \\beta^t u(W_t,c_t) \\quad \\text{s.t.} \\quad W_{t+1} = g(W_t,c_t)\n\\end{equation*}\nwhere our initial state, $W_0$ is given.  There may also be restrictions on our choices $c_t$.  For example, in many applications the state $W_t$ represents the amount of some resource available, and $c_t$ represents the amount we use up in time period $t$.  In this case we would require $c_t \\in [0,W_t]$.\n\nFor simplicity, lets assume that $u$ is a function of $c_t$ only (this is often, though not always, the case in practice).  First let's consider the case that $T=0$.  So we maximize $u(c_0)$ over $c_0 \\in [0,W_0]$.  In most cases $u$ is increasing, which we will assume here.  In this case it will be optimal to choose the largest value of $c_0$ possible, that is, $c_0 = W_0$.  Thinking of $W_0$ as our available resources, this simply means, that if we don't have future periods to consider, we will use all of it.\n\nIn fact this is always true in the last period.  In the problem with $T$-periods we know that we will use all of our resources remaining in period $T$.  Consider the two period problem:\n\\begin{equation}\n\\label{2perprob}\n\\max \\, u(c_0) + \\beta u(c_1)\n\\end{equation}\nwhere $c_0 \\in [0,W_0]$, $c_1 \\in [0,W_1]$ and $W_1 = g(W_0,c_0)$.  We know that in the last period we will use all of our remaining resources so that $c_1 = W_1$.  Substituting gives\n\\begin{equation*}\n\\max \\, u(c_0) + \\beta u(g(W_0,c_0)).\n\\end{equation*}\nThen we need only determine $c_0$.  Taking the derivative of \\eqref{2perprob} with respect to $c_0$ and setting equal to zero gives the first order condition\n\\begin{equation}\n\\label{FOC}\nu'(c_0) = -\\beta u'(g(W_0,c_0))g_c(W_0,c_0)\n\\end{equation}\nwhere $g_c$ is the partial derivative of $g$ with respect to $c$.\n\nGiven a specific form for $u$ we could solve for $W_1$ and obtain the optimal solution.  In fact, we can solve a problem of any length $T$ in this manner by starting at the last time period and working backward.  We know that $W_{T+1} = 0$.  Working backward in time we obtain an equation at each time step $t<T$ by taking the derivative with respect to $c_t$ and setting equal to zero.  This process is called backward induction.  The equations at each time step, such as equation \\eqref{FOC} are sometimes called the inter-temporal Euler equations.  These equations, along with $c_T = W_T$ make $T+1$ equations to go with our $T+1$ unknowns $c_0,c_1,c_2,\\ldots,c_T$ where we can use the law of motion to relate the $c_t$ and $W_t$.\n\n\\section*{The Recursive Problem, Finite Horizon}\n\\label{SecRecProbFinHor}\nApproaching the problem sequentially like this can be somewhat messy.  The dynamic programming approach we consider now is more easily adaptable to many situations.  The key to the dynamic programming approach is to define our optimization problem in terms of subproblems.  Notice that if we are in time period $t$, we face a problem of exactly the same form as the problem at time $0$.  We are in some state $W_t$, and want to maximize the sum from $t$ to $T$.  With this idea in mind, we define a function $V_t(W_t)$ called the value function.  The function $V_t$ gives the value of entering time $t$ in state $W_t$ and making optimal decisions moving forward.  So\n\\begin{equation*}\nV_{t-1}(W_{t-1}) = \\max u(c_{t-1}) + \\beta V_t(g(W_{t-1},c_{t-1})).\n\\end{equation*}\nThis is called the Bellman Equation.  The key to this formulation is that we decide what to do in period $t-1$ with the assumption that our actions in the remaining periods will be optimal.  This is called the principal of optimality.\n\nLet us consider a specific example from economics called The Cake Eating Problem.  Suppose $W_t$ represents the size of a cake.  At each time period we can choose how much to consume.  What we eat,$c_t$, gives us rewards.  What we save,$W_t-c_t$, does not give rewards (until it is eaten in a later period).  The law of motion \\eqref{motion} becomes\n\\begin{equation}\\label{LOM_EX}\nW_{t+1} = g(W_t,c_t) = W_t-c_t\n\\end{equation}\nNow we have completely defined the problem.  The Bellman Equation is\n\\begin{equation*}\nV_{t-1}(W_{t-1}) = \\max u(c_{t-1}) + \\beta V_t(W_{t-1}-c_{t-1}).\n\\end{equation*}\nAs before, we know that in the last time period, we should not save anything.  So $V_{T+1}(W_{T+1}) = 0$.  There is no value in leaving wealth for period $T+1$.  So $c_T = W_T$.  Then $V_T(W_T) = u(c_T)$.  Consider the value function equation for period $T-1$.\n\\begin{align*}\nV_{T-1}(W_{T-1}) &= \\max u(c_{T-1}) + \\beta V_T(W_{T-1}-c_{T-1}) \\\\\n                 &= \\max u(c_{T-1}) + \\beta (W_{T-1}-c_{T-1})\n\\end{align*}\n\nThus given $W_{T-1}$, we can determine $V_{T-1}$ by maximizing over $c_{T-1}$.  Notice that by the law of motion, it is enough to determine the values of the $W_t$ since these determine the $c_t$.  In fact rearranging \\eqref{LOM_EX} we have\n\\begin{equation*}\nc_t = W_t - W_{t+1}.\n\\end{equation*}\nThus we can rewrite the value function as\n\\begin{equation}\n\\label{cake_valfn}\nV_{t-1}(W_{t-1}) = \\max_{W_t} u(W_{t-1} - W_{t}) + \\beta V_t(W_t).\n\\end{equation}\n\nThe solution to this problem is often called a policy function.  A policy function determines an action based on the current state.  Denoting the policy function by $\\psi$, this can be written\n\\begin{equation*}\nW_{t+1}=\\psi_t \\left(W_t\\right)\n\\end{equation*}\nThe policy function gives the optimal amount of cake to leave for next period (equivalent to the amount of consumption) given the amount of cake at the start of the period.  In other words, it determines the choice of $W_t$ that satisfies the $\\max$ condition in equation \\eqref{cake_valfn}.\n\n\\begin{problem}\n\\label{prob:cake_prob}\nFollow the steps below to solve the problem described above.  Take $u(c_t) = \\sqrt{c_t}$, $\\beta = 0.9$, and $T=10$.\n\\begin{enumerate}\n\\item Let the maximum size of the cake be $W_{max} = 1$. Approximate the continuum of possible cake sizes by a column vector called $W$ that ranges from to 0 to 1.  Let the number of possible cake values be $N=100$.\n\n\\item Note that in order to compute the value function we need $u(W_{t-1}-W_t)$.  Create an $N$ by $N$ matrix that contains all possible values of $W_{t-1} - W_t$ (where $W_{t-1}$ corresponds to rows and $W_{t}$ to columns).  Make sure that $c_t \\geq 0$ is satisfied by replacing negative entries in the matrix with zero.  Then take the square root to get a matrix of $u(W_{t-1}-W_t)$.  To make sure we do not choose $W_{t-1} - W_t < 0$ when maximizing, replace the corresponding entries of the $u(W_{t-1}-W_t)$ matrix with a large negative number (e.g. $-10^{10}$).\n\n\\item Next create an $N$ by $T+2$ (corresponding to $t=0,1,\\ldots, T+1$) matrix representing the value function for a given time $t$ and state $W_t$.  We can initialize it to zeros and begin filling in the columns starting with the last (which we know is zeros).\n\n\\item Now we are ready to iterate backward and find the value function for each time period.  To find $V_T$, we compute $u(W_T - W_{T+1}) + \\beta V_{T+1}(W_{T+1})$ for all values of $W_{T-1}$ and $W_T$.  This will result in an $N$ by $N$ matrix where the rows correspond to values of $W_{T}$ and the columns correspond to values of $W_{T+1}$.  Note that to compute this we need a matrix representing $\\beta V_{T+1}(W_{T+1})$.  Because this quantity does not depend on $W_T$, its rows should be equal.  To do this, we want to take $\\beta V_{T+1}(W_{T+1})$ as a row vector and stack this vector to create a matrix with equal rows.  There are multiple ways to do this.  One is the \\li{np.repeat} function.  For example, if \\li{b} is a row vector it could be used like the following.\n\\begin{lstlisting}\nb = [[1, 2, 3]]\nnp.repeat(b, 3, axis = 0)\narray([[1, 2, 3],\n[1, 2, 3],\n[1, 2, 3]])\n\\end{lstlisting}\nIn general, be careful about having the correct rows, columns, transposes, etc throughout your code. \n\nNow we maximize over choices of $W_T$ (choosing how much to save for next period).  Then we will have a row vector representing the value function for period $T$ across all possible $W_T$.  Iterate this procedure to fill in the value function for all $t=0,1,\\ldots, T+1$.\n\n\\item In each iteration you maximize to find the value function at time $t$.  Save the values of $W_{t+1}$ that achieve the maximum.  The result is an $N$ by $T+1$ matrix whose $n,t$ entry gives the optimal amount of cake to leave for for period $t+1$ given that we start period $t$ with the the $n$th value of our $W$ vector of cake.  This is the policy function.\n\n\\item Plot the surface of the Value and Policy functions.  This can be done by including the following import lines\n\\begin{lstlisting}\nfrom matplotlib import pyplot as plt\nfrom matplotlib import cm\nfrom mpl_toolkits.mplot3d import Axes3D\n\\end{lstlisting}\nand using the following code\n\\begin{lstlisting}\nx = np.arange(0, N)\ny = np.arange(0, T+2)\nX, Y = np.meshgrid(x, y)\nfig1 = plt.figure()\nax1 = Axes3D(fig1)\nax1.plot_surface(W[X], Y, np.transpose(V), cmap=cm.coolwarm)\nplt.show()\n\nfig2 = plt.figure()\nax2 = Axes3D(fig2)\ny = np.arange(0,T+1)\nX, Y = np.meshgrid(x, y)\nax2.plot_surface(W[X], Y, np.transpose(psi), cmap = cm.coolwarm)\nplt.show()\n\\end{lstlisting}\nwhere \\li{W} is the vector of wealth levels, \\li{V} is the value function, and \\li{psi} is the policy function.\n\nYou should also try plotting the value and policy functions for fixed time periods across $W_t$, or for fixed $W_t$ across time and make sure that these plots fit your intuition.\n\\end{enumerate}\n\\end{problem}\n\n\\section*{The Recursive Problem, Infinite Horizon}\n\\label{SecRecProbInFHor}\nNext we consider an infinite horizon problem.  For simplicity, we continue with the example from the previous section.  Suppose that rather than optimizing over $t = 0,1,\\ldots,T$, we wish to optimize over an infinite time horizon:\n\\begin{equation*}\n\\max \\sum_{t=0}^\\infty \\beta^t u(W_t,c_t) \\quad \\text{s.t.} \\quad W_{t+1} = g(W_t,c_t).\n\\end{equation*}\nSince at any time $t$, there are an infinite number of periods remaining, one might suspect that the optimal policy will not depend on the current time $t$.\n\n\\begin{problem}\n\\label{prob:cake_prob2}\nCompute the solution to Problem \\ref{prob:cake_prob} with $T = 1000$.  Plot the policy function across time for fixed $W_t = 1$.  Notice that it is the same for all time periods, except those near the end time $T$.\n\\end{problem}\n\nAs suggested by the results of Problem \\ref{prob:cake_prob2},  the policy function for the infinite horizon problem does not depend on the time $t$ (this can be proved).  That is, at any time $t$, the optimal decision depends only on the amount of cake at the beginning of the period, not the value of $t$.  So everything can now be written in terms of variables today and variables tomorrow. We will denote variables tomorrow with a ``$\\:'\\:$\".\n\\begin{equation}\n\\label{EqBellman}\nV\\left(W\\right) = \\max_{W'\\in[0,W]}\\:\\: u\\left(W - W'\\right) + \\beta V\\left(W'\\right)\n\\end{equation}\nNote that the value function $V$ on the left-hand-side of \\eqref{EqBellman} and on the right-hand-side are the same function.\n\nBecause the problem now has an infinite horizon, the nature of the solution is a little different. The solution to \\eqref{EqBellman} is a policy function $W'=\\psi(W)$ that creates a fixed point in $V$. In other words, the solution is a policy function $\\psi(W)$ that makes the function $V$ on the left-hand-side of \\eqref{EqBellman} equal the function $V$ on the right-hand-side.\n\nDefine $C$ as an operator on any value function $V_k\\left(W\\right)$. Let $C$ perform the following operation.\n\\begin{equation}\n\\label{EqContraction}\nC\\Bigl(V_k\\left(W\\right)\\Bigr) \\equiv \\max_{W'\\in[0,W]}\\: u\\left(W-W'\\right) + \\beta V_k\\left(W'\\right)\n\\end{equation}\nNote that the value function on the right-hand-side of \\eqref{EqContraction} and on the left-hand-side are the same function $V_k$, but have a different value of the size of the cake--$W$ versus $W'$. The operator $C$ takes in a function $V_k$, and gives a new function which we will call $V_{k+1}$:\n\\begin{equation*}\nV_{k+1}\\left(W\\right) \\equiv C\\Bigl(V_k\\left(W\\right)\\Bigr).\n\\end{equation*}\nThe value function $V_{k+1}$ that results from the operation $C$ is not necessarily the same as the value function that the system began with $V_k$. However, according to equation \\eqref{EqBellman} we seek a $V$ such that $C(V) = V$.  The solution, then, is the fixed point in $V$.\n\\begin{equation*}\nC\\Bigl(V_k\\left(W\\right)\\Bigr) = V_{k+1}\\left(W\\right) = V_k\\left(W\\right) = V\\left(W\\right)\n\\end{equation*}\n\nThe operator $C(\\cdot)$ is called a contraction mapping if applying it over and over again to an arbitrary value function $V_k$ converges to a fixed point. One way to characterize a contraction mapping is:\n\\begin{equation*}\n\\lim_{k\\rightarrow\\infty}\\: C^k\\Bigl(V_0\\left(W\\right)\\Bigr) = V_k(W) =  V\\left(W\\right)\n\\end{equation*}\nfor any $V_0$.  It can be shown that if $u(\\cdot)$ is real-valued, continuous, and bounded, $\\beta\\in(0,1)$, and that the constraint set $W'\\in[0,W]$ is nonempty, compact-valued, and continuous, then the operator $C$ is a contraction and thus we can obtain a solution by iteration.\n\nRemember, in the infinite horizon problem both the value and policy functions do not depend on time.  Computationally, this means that the value and policy functions in the infinite horizon problem are one dimensional.\n\n\\begin{problem}\nSolve the Cake Eating Problem with an infinite time horizon by following the steps below.  As in Problem \\ref{prob:cake_prob}, take $u(c_t) = \\sqrt{c_t}$, $\\beta = 0.9$.\n\\begin{enumerate}\n\\item As in Problem \\ref{prob:cake_prob}, let the maximum size of the cake be $W_{max} = 1$. Approximate the continuum of possible cake sizes by a column vector called $W$ that ranges 0 to 1.  Let the number of possible cake values be $N=100$.\n\n\\item \\label{item:step2} Initialize the value function, V to a vector of zeros of length $N$.  This is $V_0$  Perform one iteration of the contraction operation given in equation \\eqref{EqContraction} to get a new value function $V_1$ (this should be very similar to Problem 1).  Determine the resulting policy function $W' = \\psi_1\\left(W\\right)$.  [HINT: The policy function should be a vector of length $N$ of optimal future values of the cake $W'$ given the current value of the cake $W$, and $V_T$ should be an $N$-length vector representing the value of entering a period with cake size $W$.]\n\n\\item \\label{item:step3} Generate a norm $\\delta_0 = \\norm{V_0\\left(W\\right) - V_1\\left(W'\\right)}$ that measures the distance between the two value functions. Define the distance metric as the sum of the squared differences,\n\\begin{equation}\n\\label{EqDist}\n\\delta_1\\equiv \\norm{V_1\\left(W\\right) - V_0\\left(W'\\right)} = \\left(V_1 - V_0\\right)'*\\left(V_1 - V_0\\right)\n\\end{equation}\nwhere $\\left(V_1-V_0\\right)'$ is the transpose of the difference of the two vectors. Defined in this way, $\\delta_1\\in [0,\\infty)$.\n\n\\item \\label{item:step4} Take the resulting $V_1$ from \\ref{item:step2}, and perform the same contraction on it to generate $V_2$ and $\\psi_2$. That is, generate,\n\\begin{equation*}\n  V_2\\left(W\\right) = C\\Bigl(V_1\\left(W\\right)\\Bigr) = \\max_{W'\\in[0,W]}\\: u\\left(W - W'\\right) + \\beta V_1\\left(W'\\right)\n\\end{equation*}\nand the accompanying policy function $W'=\\psi_2\\left(W\\right)$. Calculate the accompanying distance measure for $\\delta_2$ using the formula from \\eqref{EqDist} with the updated period subscripts. Compare $\\delta_2$ with $\\delta_1$ from \\ref{item:step3}.\n\n\\item \\label{item:step5} Repeat \\ref{item:step4} and generate $V_3$ and $\\psi_2$ by performing the contraction on $V_2$. Compare $\\delta_3$ to $\\delta_2$ and $\\delta_1$.\n\n\\item Write a loop that performs the contraction operation from \\ref{item:step2}, \\ref{item:step4}, and \\ref{item:step5} iteratively until the distance measure is very small $\\delta_k < 10^{-9}$.  The distance measure $\\delta_k$ being arbitrarily close to zero means you have converged to the fixed point $V_k = V_{k+1} = V$. (For fun, you can show that the policy function converges to the same function regardless of what you put in for your initial policy function value.)\n\n\\item Plot the policy function for the converged problem $W' = \\psi\\left(W\\right)$ which gives the value of the cake tomorrow ($y$-axis) as a function of the cake today ($x$-axis).\n\\end{enumerate}\n\\end{problem} ", "meta": {"hexsha": "47a14ea7299d478ac1d07483f137b33f3459fcf2", "size": 18273, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/ValueFunctionIter/Value_Function_Iteration.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/ValueFunctionIter/Value_Function_Iteration.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/ValueFunctionIter/Value_Function_Iteration.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 90.4603960396, "max_line_length": 874, "alphanum_fraction": 0.7329940349, "num_tokens": 5385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.847967769904032, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7138410201129508}}
{"text": "%!TEX root = ../../dissertation.tex\n\n\\subsection{L-Systems} % (fold)\n\\label{sub:l_systems}\n\nLindenmayer Systems (L-Systems) are a class of string rewriting mechanisms, originally developed by Lindenmayer as a mathematical theory for plant\ndevelopment. It is capable of describe the behavior of plant cells and model the growth processes of plant development.\n\nAn L-Systems consists of two different parts, one axiom and a set of production rules. The axiom is the starting point of the system, acting as a seed. Then it is applied in this seed the set of production rules, that change the initial string, producing other strings.\nThis is an iterative process, so after the production of a larger set of strings, the rules can be applied to each one of them which grows the size of\nthe set even more.\n\nL-Systems are used to model the natural growth of vegetation (Figure~\\ref{fig:trees}), and the generation of Fractals. \n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=0.65\\textwidth]{images/Theory/L_Systems/Dragon_trees.jpg}\n    \\caption{Trees with L-Systems}\n    \\label{fig:trees}\n\\end{figure}\n\n\nIn this process, each symbol is associated with a production rule. For instance having $\\{F, +, -\\}$ for the alphabet and \\emph{production} $\\{F \\rightarrow\n F+F--F+F\\}$. From a starting axiom \\emph{aba}, and the application of the rules we have:\\\\\n\\begin{equation} \\label{eq:seed}\nF\\\\\n\\end{equation}\n\\begin{equation} \\label{eq:step1}\nF+F--F+F\\\\\n\\end{equation}\n\\begin{equation} \\label{eq:step2}\nF+F--F+F \\; + \\; F+F--F+F \\;- \\;- \\;F+F--F+F \\;+ \\;F+F--F+F\\\\\n\\end{equation}\n\n%\\begin{align}\n%\\begin{split}\n%F\\\\\n%F+F--F+F\\\\\n%F+F--F+F \\; + \\; F+F--F+F \\;- \\;- \\;F+F--F+F \\;+ \\;F+F--F+F\\\\\n%\\end{split}\n%\\end{align}\n%\\\\\n\nThis is an example of the evolution of one system where the production is applied  in (\\ref{eq:seed}) that turns into $F+F--F+F$. Note that the space\nbetween the symbols are just for readability.\n\nAll the symbols are assigned with a geometric meaning. The notion of a turtle with a pen, as proposed in \\cite{abelson1982aa}, with the symbols being\ninterpreted as moving instructions to the turtle, is a simple way to understand, where ``F'' means forward and the symbols ``+'' and ``-'' are interpreted as rotations counter-clockwise and clockwise respectively by a predefined angle. By applying this method to the last example and setting the angle for the rotation to $60^{\\circ}$ the result is Figure~\\ref{fig:kockLS}.\n\n\\begin{figure}[htbp]\n   \\centering\n   \\includegraphics[width=0.55\\textwidth]{images/Theory/L_Systems/koch.png}\n   \\caption{Result of the ``turtle walk'' with the given example}\n   \\label{fig:kockLS}\n\\end{figure}\n\n%\\begin{wrapfigure}{r}{0.5\\textwidth}\n%\t\\vspace{-15pt}\n%    \\centering\n%    \\includegraphics[width=0.55\\textwidth]{images/Theory/L_Systems/koch.png}\n%    \\caption{}\n%    \\label{fig:kockLS}\n%\t\\vspace{-25pt}\n%\\end{wrapfigure}\n\n%$\\bigodot \\; \\bigodot$\n\n\n\n\n% This concept of the turtle can be considered also in 3D.\n\n\n\n% subsection l_systems (end)", "meta": {"hexsha": "ba8abc1df9a185b552f38bff57f55494f337ff46", "size": 3007, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/over-sections/3-L-Systems.tex", "max_stars_repo_name": "arturalkaim/Dissertation", "max_stars_repo_head_hexsha": "8acf0d8de0f312ec0f70f6aece795f4f93260d76", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/over-sections/3-L-Systems.tex", "max_issues_repo_name": "arturalkaim/Dissertation", "max_issues_repo_head_hexsha": "8acf0d8de0f312ec0f70f6aece795f4f93260d76", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/over-sections/3-L-Systems.tex", "max_forks_repo_name": "arturalkaim/Dissertation", "max_forks_repo_head_hexsha": "8acf0d8de0f312ec0f70f6aece795f4f93260d76", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.0933333333, "max_line_length": 373, "alphanum_fraction": 0.719321583, "num_tokens": 869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7138410038105224}}
{"text": "\\newsection{Searching}\n\n\\subsection{Motivation}\nNow that we know how to make arrays, we want to use them efficiently. This chapter and the next will be a more ``high-level\" approach to problems in programming and Computer Science. Searching is a well-studied and important problem. We will cover 2 basic searching algorithms that will find elements in an array quickly and efficiently: linear and binary searching.\n\n\\subsection{Linear Search}\nLinear Search is searching from one end of the array until the end, and stopping if we find the element that we desire. Pseudocode to match a linear search is:\n\\begin{verbatim}\nfunction LinearSearch(array a, variable v):\n     for(item i in a):\n          if i == v:\n               return i; // or any non-\"error\" value (in array)\n     return -1; // some \"error\" value (not in array)\n\\end{verbatim}\nFor example, if we have an array of \\verb|int| variables and we are searching for one, we can construct code such as this:\n\\begin{lstlisting}\npublic boolean linearSearch(int[] array, int search) {\n     for (int i : array) {\n          if (i == search) {\n               return true;\n          }\n     }\n     return false;\n}\n\\end{lstlisting}\nHowever, this loop can be inefficient, because we have no guarantee what the ordering or contents of \\verb|array| are. We have to search (on average) $\\frac{n}{2}$ elements. Therefore, we cannot make a ``guess\" as to improvements can be done.\n\n\\par However, if we can have a guarantee on the ordering of elements in the array, we can get better performance, as shown by binary search.\n\n\\subsection{Binary Search}\nWe can improve our algorithm by using binary search, on one condition: we \\textbf{must} guarantee that the input array \\textbf{is already sorted}. We will cover how to sort an unsorted array in the next chapter. Pseudocode of the algorithm is the following:\n\\begin{verbatim}\nfunction BinarySearch(array a, int key):\n     low = 0, high = a.length;\n     while high >= low:\n          mid = average(low, high);\n          if a[mid] == key:\n               return mid; // found\n          else if a[mid] < key:\n               low = mid + 1;\n          else\n               high = mid - 1;\n     return -1; // not found\n\\end{verbatim}\nThe algorithm works like this: since the array is sorted, we check the middle value. If the value to search is larger than that middle value, we ``cut off\" the lower half of the array, since we can guarantee it is not in that part (and likewise for less than). Then we check the middle half of the top half of the array, and keep adjusting what is the ``low\" and ``high\" ranges of what part of the array we are searching. We stop when we keep adjusting ``low\" to the point that it is higher than ``high\" (it does not make sense to search in a range that is backwards). At that point, we have not found our element, and we return.\n\n\\par For example, we can create a similar procedure in Java with a \\verb|int| array (the concept works with Strings also, just comparing their lexicographic ordering instead):\n\\begin{lstlisting}\npublic int binarySearch(int[] array, int k) {\n     int min = 0, max = array.length-1;\n     while (max >= min) {\n          int mid = (min+max)/2;\n          if (a[mid] == k) {\n               return mid;\n          } else if (a[mid] < k) {\n               min = mid+1;\n          } else {\n               max = mid-1;\n          }\n     }\n}\n\\end{lstlisting}\nNow for an example. Suppose I have an array consisting of $\\{-3, -1, 2, 4, 7\\}$. Clearly, the array is sorted, so we can use binary search. I want to search for the element 4. Here is the execution of binary search:\n\\begin{verbatim}\n// Start binary search\nmin = 0, max = 5\n// 7 >= -3, so enter while loop\nmid = (0+5)/2 = 2 (integer division)\na[mid] = 2\n// check #1: 2 != 4, so skip if statement\n// check #2: 2 < 4, so enter else if\nmin = 2+1 = 3\n\n// 2nd Execution:\nmid = (3+5)/2 = 4\na[mid] = 7\n// check #1: 7 != 4, so skip if statement\n// check #2: 7 > 4, so skip else if statement\nmax = 4-1 = 3\n\n// 3rd Execution:\nmid = (3+3)/2 = 3\na[mid] = 4\n// check #1: 4 == 4, so return 4, success!\n\\end{verbatim}\n\\subsection{Written Exercises}\n\n\\begin{enumerate}\n\n\\item Use the sorted list below and use binary search to look for Mike in the list. Show all the names that will be compared before Mike is found. Then, repeat the same process for Cathy (note: Cathy is not in the list).\n\\begin{table}[h]\n\\begin{tabular}{lllllll}\nAaron & Betsy & Doug & Elise & Mike & Pat & Steven\n\\end{tabular}\n\\end{table}\n\n\\item What is the benefit of using binary search over linear search?\n\n\\item (Warning: this question is difficult) The line:\n\\begin{lstlisting}\nint mid = (min+max)/2;\n\\end{lstlisting}\nin the code for binary search above has a bug, but is very specific. It works in the vast majority of cases, though. Figure out what the bug is, and what can be done to fix it (hint: think about the bounds on the values for \\verb|int|).\n\n\\end{enumerate}", "meta": {"hexsha": "adae9cd49316198a8d1df2235ccc18c3026b4bdc", "size": 4919, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture Notes/11_searching.tex", "max_stars_repo_name": "ryandougherty/Introduction-to-Computer-Science-Lecture-Notes", "max_stars_repo_head_hexsha": "ac471e94990bc0dcef7beed93f7db410b36e9c3e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture Notes/11_searching.tex", "max_issues_repo_name": "ryandougherty/Introduction-to-Computer-Science-Lecture-Notes", "max_issues_repo_head_hexsha": "ac471e94990bc0dcef7beed93f7db410b36e9c3e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture Notes/11_searching.tex", "max_forks_repo_name": "ryandougherty/Introduction-to-Computer-Science-Lecture-Notes", "max_forks_repo_head_hexsha": "ac471e94990bc0dcef7beed93f7db410b36e9c3e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.8476190476, "max_line_length": 629, "alphanum_fraction": 0.6779833299, "num_tokens": 1304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7138410036798545}}
{"text": "\\lab{Naive Bayes}{Naive Bayes}\n\\label{Ch:NaiveBayes}\n\n\n\\objective{Implement Naive Bayes Classification Models}\n\n%Outline\n%\n%Brief overview\n%\tWith/Without independence assumptions\n%\t\n%Types of Naive Bayes models\n%\tMultinomial\n%\tGaussian\n%\t\n%Simple Examples\n%\tMultinomial - Fair vs Loaded Dice\n%\t\tDataset - generated by me\n%\t\n%\tGaussian - Wheat Kernels\n%\t\tUCI Machine Learning\n%\t\tSample test from training\n%\n%Application: spam Filtering\n%\tDataset - Emails\n%\tBuild wordcounts and labels\n%\tSample test from training\n\n\\subsection*{Introduction}\n\nNaive Bayes classification methods are a good introduction to machine learning techniques.\nThey are relatively straightforward to understand and implement, yet they are very effective for certain applications.\nThey are limited by their strong independence assumptions.\n\nRecall that the classification problem tries to assign the correct label to a set of features\n(called a \\emph{feature vector}).\nFor example, suppose we wish to label two pieces of fruit with their correct names.\nThe first fruit is red and round, and the second fruit is long and yellow.\nThese attributes of the fruit are the features.\nIf we assign the names apple and banana respectively, then these are our labels.\n\nIt is common in classification problems to start with a set of labeled feature vectors called a training set.\nWe use the training set to train our algorithm to make predictions.\nIt is also common to have another smaller set of labeled feature vectors called a test set.\nTo verify the effectiveness of our algorithm, we predict the labels of the test set, and then compare the predicted labels to the true labels.\n\nNow recall Bayes rule for random variables:\n\\[\nP(Y|X) = \\frac{P(X|Y)P(Y)}{\\int P(X|Y)P(Y) dy}\n\\]\nWhere $P(Y)$ is our prior distribution and $P(X|Y)$ is our likelihood function.\n\nSuppose that we have a set of features that we wish to label.\nLet $x = (x_1, \\ldots, x_n)$ be a feature vector and let $C = {c_1, \\ldots, c_k}$ be our set of labels.\nWe may apply Bayes rule to this problem as follows:\n\\[\nP(c_i|x) = P(c_i | x_1, \\ldots, x_n)  = \\frac{P(x_1, \\ldots, x_n|c_i)P(c_i)}{P(x_1, \\ldots, x_n)}\n\\]\nIf we make no further assumptions, this problem is intractable.\nTo effectively estimate even a case where each feature is a boolean value would require us to estimate around $k2^{n}$ parameters.\nThe problem gets exponentially worse if we were to consider non-boolean features.\n\nHowever, if we make the assumption that features are conditionally independent from each other, the problem simplifies dramatically.\nIf we make this assumption and apply Bayes rule, we have\n\\[\nP(c_i | x_1, \\ldots, x_n) = \\frac{P(x_1|c_i)P(x_2|c_i)\\ldots P(x_n|c_i)P(c_i)}{P(x_1,\\ldots,x_n)}\n\\]\nIn this case, we only need to estimate $kn$ parameters.\nThe naive Bayes classification algorithm chooses the label with the highest probability.\nSince this is independent of the denominator in Bayes rule, we can simplify the problem further.\nGiven an unlabeled feature vector $x=(x_1,\\ldots,x_n)$, we assign the label\n\\[\nc = \\underset{i \\in \\{1, \\ldots, k\\}}{\\argmax}\\, P(c_i)\\prod_{j=1}^n P(x_j|c_i)\n\\]\n\nTo assign a label to a set of features, we calculate each $P(x_j|c_i)$ and choose a prior $P(c_i)$.\nWe then choose the argmax as above.\nThe calculation of conditional probabilities and choice of prior will depend on the type of problem that we are solving.\n\n\\subsection*{Gaussian Classifiers}\n\nGaussian classifiers are commonly used when dealing with continuous data.\nWe assume that each feature is normally distributed and conditionally independent.\nWe may then calculate $\\mu_{j,i}$ and $\\sigma^2_{j,i}$ corresponding to each feature of each class.\nThen $P(x_j|c_i)$ can be calculated using the gaussian pdf\n\\[\nP(x_j|c_i) = \\frac{1}{\\sqrt{2\\pi\\sigma_{j,i}^2}}\\exp{-\\frac{(x_j - \\mu_{j,i})^2}{2\\sigma^2_{j,i}}}\n\\]\n\nFor example, suppose we have a training set with labels indicating the sex of a person (1 for female, 2 for male), and  features consisting of hair length and height (features 1 and 2, respectively).\nFurther suppose that the mean height of the men in the training set is 1.75 meters with standard deviation 7 cm, and mean hair length is 5 centimeters with standard deviation 2.5 cm.\nSimilarly, suppose that the mean height of the women in the training set is 1.25 meters with standard deviation 6 cm, and the mean hair length is 15 centimeters with standard deviation 1.5 cm.\nUnder this setup, we have\n\\begin{align*}\n\\mu_{1,1} &= 15, \\quad &&\\sigma_{1,1} = 1.5\\\\\n\\mu_{2,1} &= 1.25, &&\\sigma_{2,1} = .06\\\\\n\\mu_{1,2} &= 5, &&\\sigma_{1,2} = 2.5\\\\\n\\mu_{2,2} &= 1.75, &&\\sigma_{2,2} = .07.\n\\end{align*}\nIf we wish to classify a person that is 1.4 meters tall and a hair length of 17 centimeters, we calculate the probability of each label using the parameters given above and a uniform prior ($P(F) = P(M) = \\frac{1}{2}$):\n\\begin{align*}\nP(F\\,|\\,17,1.4) &= P(F)\\left(\\frac{1}{\\sqrt{2\\pi\\sigma_{1,1}^2}}\\exp{-\\frac{(17-\\mu_{1,1})^2}{2\\sigma^2_{1,1}}}\\right)\n\\left(\\frac{1}{\\sqrt{2\\pi\\sigma_{2,1}^2}}\\exp{-\\frac{(1.4-\\mu_{2,1})^2}{2\\sigma^2_{2,1}}}\\right)\\\\\n&= .016\\\\\nP(M\\,|\\,17,1.4) &= P(M)\\left(\\frac{1}{\\sqrt{2\\pi\\sigma_{1,2}^2}}\\exp{-\\frac{(17-\\mu_{1,2})^2}{2\\sigma^2_{1,2}}}\\right)\n\\left(\\frac{1}{\\sqrt{2\\pi\\sigma_{2,2}^2}}\\exp{-\\frac{(1.4-\\mu_{2,2})^2}{2\\sigma^2_{2,2}}}\\right)\\\\\n&= 1.7\\times 10^{-11}\n\\end{align*}\nThe Female label has a greater probability given the feature vector, and so we classify the person as Female.\n\nA nice way to visualize how a classifier works is to plot the decision boundaries for two-dimensional subspaces of the\nfeature vector space.\nFor example, the decision boundaries for a Gaussian Naive Bayes classifier trained on a dataset consisting of the\nsepal widths and lengths of three different types of flowers is shown in Figure \\ref{fig:decision_boundary}.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=.90\\textwidth]{decision_boundary}\n\t\\caption{Decision boundaries for a Gaussian Naive Bayes classifier on the iris flower dataset, together with the means\nfor each flower. Each point in the plane represents a 2-dimensional feature vector, and the color associated with each point indicates which class label was assigned to that feature vector.}\n\t\\label{fig:decision_boundary}\n\\end{figure}\n\n\\subsection*{Working in Log Space}\nIn the example presented above, notice that the value of $P(M\\,|\\,17,1.4)$ is very small.\nThis is often the case in classification problems; certain classes may be very unlikely, and so calculating these probabilities may lead to numerical underflow.\nThis is especially pronounced in the naive Bayes model, which involves taking the product of several numbers between\n0 and 1.\nA useful technique to avoid underflow is to convert the computations in logarithmic space.\nWhen we do so, the Naive Bayes label assignment is\n\\[\nc = \\underset{i \\in \\{1, \\ldots, k\\}}{\\argmax}\\, \\log P(c_i) + \\sum_{j=1}^n \\log P(x_j|c_i).\n\\]\nSince the logarithm is a monotone increasing function, the argmax is the same whether in log space or\nin the original formulation.\n\n\\begin{problem}\nDownload the {\\tt seeds\\_dataset.txt} file.\nThis file contains 7 features describing 3 species of wheat.\n\\begin{enumerate}\n\\item Area\n\\item Perimeter\n\\item Compactness\n\\item Length\n\\item Width\n\\item Asymmetry Coefficient\n\\item Groove length\n\\end{enumerate}\n\nThe species of wheat are\n\\begin{enumerate}\n\\item Kama\n\\item Rosa\n\\item Canadian\n\\end{enumerate}\n\nThe measurements of the kernels are real valued, making this a good example to try our Gaussian classifier.\n\n\\begin{enumerate}\n\\item Randomly select a test set of 40 vectors from the data.  Make sure you separate this data from your training data.\n\\item Calculate the mean and variance for each feature of each label using the training set.\n\\item Using a uniform prior, predict the labels of your test set.\n\\item Compare your predictions to the labels of the test set. In particular, report the accuracy of the prediction,\nwhich is the number of correctly predicted instances divided by the total number of instances.\n\\end{enumerate}\n\n\\end{problem}\n\nWe may also use SciPy's {\\tt sklearn} library to implement a Gaussian classifier.\nAfter importing the library, we can create a new classifier and train it with just a couple of lines of code.\nTo create a Gaussian classifier, use the following code.\n\n\\begin{lstlisting}\nfrom sklearn.naive_bayes import GaussianNB\nnb_classifier = GaussianNB()\n\\end{lstlisting}\n\nGiven a training set, we can also quickly train the classifier to a certain problem.\nThis requires the training set and labels as two arguments.\n\n\\begin{lstlisting}\nnb_classifier.fit(training_set, labels)\n\\end{lstlisting}\n\nOnce the classifier has been trained, we can predict the labels for a test set.\n\n\\begin{lstlisting}\npred_labels = nb_classifier.predict(test_set)\n\\end{lstlisting}\n\nThe {\\tt predict} method returns an array of labels for the test set.\n\n\\begin{problem}\n\nRepeat the previous problem using {\\tt sklearn}'s naive Bayes classifier.\nCheck that your implementation predicts the same labels as the {\\tt sklearn}\nimplementation.\n\n\\end{problem}\n\n\n\\subsection*{Document Classification and spam Filters}\n\nNaive Bayes classifiers are often used in document classification, a major example being spam detection.\nWhen it comes to document classification, a common choice for the feature vector\nis simply a count for the number of times each word in the specified vocabulary occurs in the document.\nFor example, suppose we are trying to classify a document, and the vocabulary of relevant words is the ordered set\n\\[\n\\text{(bank, tree, wealth, money, river, water)}.\n\\]\nSuppose that the document is the sentence\n\\begin{quotation}\n``The woman deposited her money in the bank, and then made her way down to the bank of the river, contemplating her wealth.\"\n\\end{quotation}\nThen the feature vector for this document is\n\\[\n(2, 0, 1, 1, 1, 0).\n\\]\nNotice in particular that the $i$-th entry of the feature vector indicates the number of occurrences of the $i$-th\nvocabulary word in the document.\nSuch a feature vector is often called a \\emph{word-count vector}.\nNotice that the count vector ignores words in the document that are not part of the vocabulary, and\nit also disregards the order of words.\nThis simple representation of text documents is known as the \\emph{bag-of-words model} or the \\emph{vector space model}.\nThe hypothesis that drives spam filters is that spam messages will use words with different frequencies.\nFor example, a spam message will often have a sales pitch, so the word ``buy'' and ``cheap'' will appear often.\nOn the other hand, legitimate messages will probably use different language.\nThus, it is reasonable to use word-count vectors as our feature vectors when attempting to distinguish between spam and\nlegitimate email.\n\nWe now introduce formalisms to derive the Naive Bayes model for document classification.\nLet $V = (v_1,v_2,\\ldots,v_n)$ be an ordered list of words, called the vocabulary, and let\n$x = (x_1,x_2,\\ldots,x_n)$ be a word-count vector.\nLet $\\{c_1,c_2,\\ldots,c_k\\}$ be the set of classification labels.\nIn the case of continuous data and Gaussian Classifiers, each class label was associated with corresponding\nmean and variance parameters, and these determined the likelihood of the feature vector given the class label.\nIn the case of document classification, each class label $c_i$ has a corresponding probability vector\n$(p_{i,1}, p_{i,2}, \\ldots, p_{i,n})$ whose entries are nonnegative and sum to 1.\nThis probability vector defines a categorical probability distribution over the vocabulary $V$, where $p_{i,j}$\nrepresents the probability of seeing word $v_j$ given class label $c_i$.\nWith this notation in place, our Naive Bayes model takes the form\n\\[\nc = \\underset{i \\in \\{1, \\ldots, k\\}}{\\argmax}\\, P(c_i)\\prod_{j=1}^n p_{i,j}^{x_j}.\n\\]\n\nGiven a training set of labeled documents, we can calculate the prior probabilities $P(c_i)$ and word probabilities\n$p_{i,j}$ as follows.\nEach prior probability $P(c_i)$ is simply the proportion of training documents that have the label $c_i$.\nNext, let $count(c_i,v_j)$ denote the number of occurrences of word $v_j$ among all training documents that have label $c_i$.\nThen we have\n\\[\np_{i,j}  = \\frac{count(c_i,v_j)+1}{\\sum_{j=1}^n(count(c_i,v_j)+1)}.\n\\]\n(Note that adding 1 to the number of occurrences of each word is known as \\emph{add-one smoothing}, and is a\ncommon technique to prevent over-fitting.)\n\nOnce we have calculated these parameters (the ``fitting\" stage), we are ready to classify new documents\n(the ``prediction\" stage) using the argmax equation given above.\nRemember to perform calculations in log-space to prevent numerical underflow.\n\n\\begin{problem}\nImplement a Naive Bayes model for document classification.\nWe provide an interface below.\n\n\\begin{lstlisting}\nclass naiveBayes(object):\n    \"\"\"\n    This class performs naive bayes classification for word-count document features.\n    \"\"\"\n    def __init__(self):\n        \"\"\"\n        Initialize a naive Bayes classifier.\n        \"\"\"\n        pass\n\n    def fit(self,X,Y):\n        \"\"\"\n        Fit the parameters according to the labeled training data (X,Y).\n\n        Parameters\n        ----------\n        X : ndarray of shape (n_samples, n_features)\n            Each row is the word-count vector for one of the documents\n        Y : ndarray of shape (n_samples,)\n            Gives the class label for each instance of training data. Assume class labels\n            are in {0,1,...,k-1} where k is the number of classes.\n        \"\"\"\n        # get prior class probabilities P(c_i)\n        # (you may wish to store these as a length k vector as a class attribute)\n\n        # get (smoothed) word-class probabilities\n        # (you may wish to store these in a (k, n_features) matrix as a class attribute)\n\n        pass\n\n    def predict(self, X):\n        \"\"\"\n        Predict the class labels of a set of test data.\n\n        Parameters\n        ----------\n        X : ndarray of shape (n_samples, n_features)\n\n        Returns\n        -------\n        Y : ndarray of shape (n_samples,)\n            Gives the classification of each row in X\n        \"\"\"\n        pass\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{problem}\nIn this problem, you will train a Naive Bayes classifier using a corpus of emails extracted from the Enron dataset.\n\nLoad in the data from {\\tt SpamFeatures.txt}. This is a text file containing a whitespace-delimited\nnumerical array with several thousand columns and several thousand rows, each row representing an email\nas a count vector.\nAlso load in the data from {\\tt SpamLabels.txt}, which is a text file containing a 1 (for legitimate email) or 0\n(for spam email) on each line, in correspondence with the rows of the count vector array.\nUsing your document classification implementation, do the following:\n\\begin{enumerate}\n\\item Randomly create a test set from the data (500 documents), leaving the remaining documents as the training set.\n\\item Create a naive Bayes classifier and fit it using the training set.\n\\item Predict the labels of the test set and compare to the true labels (by reporting the classification accuracy).\n\\end{enumerate}\n\nNext, perform the same task using {\\tt sklearn}'s implementation and the same train and testing sets:\n\\begin{lstlisting}\n>>> # assume train_vectors, train_labels, and test_vectors are defined\n>>> from sklearn.naive_bayes import MultinomialNB\n>>> mnb = MultinomialNB()\n>>> mnb.fit(train_vectors, train_labels)\n>>> predicted = mnb.predict(test_vectors)\n\\end{lstlisting}\nAgain report the accuracy of the predicted labels. The result should be on par with those produced by your\nown implementation.\n\nIf you wish, you may use your Naive Bayes classifier on your own email.\nTo do so, you need to load in the words in the vocabulary, contained in the file {\\tt SpamVocab.txt}, as follows:\n\\begin{lstlisting}\n>>> with open(\"SpamVocab.txt\", 'r') as f:\n>>>     vocab = [s.strip() for s in f]\n\\end{lstlisting}\nNext, load the email you wish to classify into memory, stored as a string object (either copy and paste the email\ndirectly into the interpreter, or load it from a file). Once you have this string, convert it to a count vector using\nthe following code:\n\\begin{lstlisting}\nfrom collections import Counter\ndef getCountVector(document, vocab):\n    \"\"\"\n    Return the count vector for the given document using the given vocabulary.\n\n    Parameters\n    ----------\n    document : string, words separated by whitespace\n    vocab : list of strings of length n\n\n    Returns\n    -------\n    counts : ndarray of shape (1,n)\n    \"\"\"\n    tf = Counter(document.lower().split()) # get frequencies of each word\n    counts = np.array([[tf[t] if t in tf else 0 for t in vocab]])\n    return counts\n\\end{lstlisting}\nFeed this output into the \\li{predict} method of your classifier, and see how well it performs.\n\\end{problem}\n\n\n\\begin{comment}\nI didn't find this section to be necessary. I wanted to jump right to full document classification.\n\nA good analogy to help us understand is the problem of classifying dice as fair or loaded.\nSuppose that we had 100 rolls from 1000 different dice.\nSome dice are fair, but other dice favor rolls of 3 or 4.\nOur task is to identify unlabeled dice as either fair or weighted.\nWe could generate such an experiment in python as follows.\n\n\\begin{lstlisting}\n\n#Generate 100 rolls from 1000 dice, some fair and some weighted\n#All weighted dice favor 3 and 4\n\nimport numpy as np\nimport random\n\nprob_fair = 0.7\nnum_dice = 1000\nnum_rolls = 100\n\nfair_die = np.array([1, 2, 3, 4, 5, 6])\nweighted_die = np.array([1,2,3,3,3,3,4,4,4,4,5,6])\n\nrolls = np.zeros((num_dice, num_rolls))\nlabel = np.zeros((num_dice,1))\n\nfor i in xrange(num_dice):\n    if np.random.random() < prob_fair:\n        for j in xrange(num_rolls):\n            rolls[i,j] = random.choice(fair_die)\n        label[i] = 0\n    else:\n        for j in xrange(num_rolls):\n            rolls[i,j] = random.choice(weighted_die)\n        label[i] = 1\n\n\\end{lstlisting}\n\nIn this case, {\\tt rolls} is a matrix whose rows are rolls from either a fair or a loaded die.\nOur labels are stored in {\\tt label}.\nWe can build a multinomial naive Bayes classifier using {\\tt sklearn}.\n\n\\begin{lstlisting}\nfrom sklearn.naive_bayes import MultinomailNB\nmnb_classifier = MultinomialNB\nmnb_classifier.fit(rolls,label)\n\\end{lstlisting}\n\nThe multinomial classifier trains on the roll data on each line.\nWe can now predict whether a new set of die rolls is either fair or loaded.\n\n\\begin{lstlisting}\nroll = np.random.randint(1,7,size=100)\nmnb.predict(roll)\n\\end{lstlisting}\n\n\\begin{problem}\nThe die roll problem is simplification of a spam filter.\nThe different kinds of die produce different kinds of rolls.\nThus, the probability of getting one kind of histogram of rolls is different depending on the label of the die.\nWrite an explanation of how you could extend these ideas to a spam filter, and how you would use {sklearn} to implement it.\n\\end{problem}\n\\end{comment}\n\n", "meta": {"hexsha": "72f7118792674c3b09bbc9c6b3689c75a5794d51", "size": 18970, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/NaiveBayes/naivebayes.tex", "max_stars_repo_name": "marissa-graham/numerical_computing", "max_stars_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/NaiveBayes/naivebayes.tex", "max_issues_repo_name": "marissa-graham/numerical_computing", "max_issues_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/NaiveBayes/naivebayes.tex", "max_forks_repo_name": "marissa-graham/numerical_computing", "max_forks_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.5091743119, "max_line_length": 219, "alphanum_fraction": 0.7420664207, "num_tokens": 4887, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7138277804957559}}
{"text": "\\setchapterpreamble[u]{\\margintoc}\n\\chapter{Mathematical Background}\n\nThe character of quantum mechanics is to a large extent dependent on the mathematics used to describe it. At the end of the day, all theory needs to be supported by experimental evidence. That is, by actual measurements. We quantify our measurements with numbers to speak in a standardized, precise way. When we ask questions like, ``How long?'' or ``How much?'', we typically use numbers to give an answer.\n\nIn quantum mechanics, we will use increasingly sophisicated mathematical constructs to describe the world around us, including experiments physicists perform. Some of properties of numbers that we take for granted will remain, while others will disappear. Here we begin with a exploration of two particular useful number systems: the \\emph{real} and the \\emph{complex} numbers.\n\n\\section{Real Numbers}\\marginnote{\\textbf{TODO:} Real numbers. Communitivity, distributivity. (Figures showing geometric equivalence.) \\textbf{Exercises.} Field properties. Example, the real numbers. Binary. Finite fields. $\\mathbf{Z}_2$. $V_4$. \\textbf{Exercises.} Cartesian plane. Absolute value. Distance. Circles. \\textbf{Exercises.}}\n\nWe begin with an old friend, the \\emph{real line}. When we talk about the real line, we're really just talking about an ordinary geometric line. To define a sense of order, we label the points on the line with the set $\\mathbf{R}$ of all \\emph{real numbers}. That is, we identify each point on the line with a unique real number. And  we often speak as if the numbers were actually on a line, and as if the points on the line are actually numbers.\n\n\\begin{figure}[h]\n\\input{figures/mathematical-background/real-line.tex}\n\\caption{The real line}\n\\end{figure}\n\nYou may be wondering what makes the real numbers ``real''? The term real is unfortunate. The existence of real numbers is no more or less certain than any other kind of number---including the so-called imaginary numbers that we will meet later in this chapter. The philosopher Ren\\'e Descartes came up with the term while investigating roots of polynomials in the 17th century. He was trying to distinguish different kinds of solutions. Since then, the name stuck. And it has confused students of mathematics ever since.\n\nIn some sense, the complex numbers, which include the combination of real and imaginary numbers, are much more real---or at least more complete---than the real numbers alone. The \\emph{Fundamental Theorem of Algebra} guarantees that all polynomials of a single variable have a solution which is complex number. For example, the equation\n\n\\begin{equation}\\label{eqn:mb-imaginary} x^2+ 1 = 0 \\end{equation}\n\nhas no real number solution. We will see later that there is a complex number solution to that equation. Because complex solutions always exist for single-variable polynomials with complex coefficients, we say that the complex numbers are \\emph{algebraically closed}.\\sidenote{We will see a more examples of numbers that are closed under other operations soon.} The real numbers are not. The fact that equation \\ref{eqn:mb-imaginary} has no real number solution is witness to the fact that the real numbers are not algebraically closed.\n\nWhile the real line may look simple, do not be fooled. Its internal structure is incredibly complicated. For now we'll call out a few subsets of $\\mathbf{R}$ that are so commonly used that they get their own symbols as well. They are the natural numbers $\\mathbf{N}$, the integers $\\mathbf{Z}$, and the rational numbers $\\mathbf{Q}$.\\sidenote{The \\emph{Zahlen} means ``number'' in German. German mathematicians used $\\mathbf{Z}$ to refer to integers in their papers. The rest is history.}\\sidenote{Rational numbers are ratios of integers, AKA \\emph{quotients}.}\n\n\\subsection{Natural Numbers}\nThe natural numbers $\\textbf{N}$ are also sometimes called the counting numbers. They are the ones we first learn. They start 1, 2, 3, and continue that way one at a time.\\sidenote{Sometimes people start the natural numbers at zero instead of one. It doesn't make much difference.} There is no largest natural number. They are infinite, which means that even these seemingly simple numbers are already quite complicated.\n\nIn ancient times, the Greeks restricted themselves to the numbers that could be constructed using a compass and an unmarked straight edge. They began with the natural numbers. Figure \\ref{fig:mb-natural-numbers-construction} shows how you can produce any natural number, provided you have the time and paper.\n\nFirst, starting a point, draw line segment with the straight edge. This line segment defines our unit length. The problem is how to produce another line segment of the same length as one you just drew. The straight edge, remember, is unmarked. So it doesn't help us out too much. The trick is to use the compass. For convenience, mark the starting point of line with the suggestive label \\textsf{0} and the point at the other end with the label \\textsf{1}.\\sidenote{In Book \\textsc{vii}, definition 1 of the \\emph{Elements}, Euclid tells us that the first number is one, not zero. But let's follow E.W.~Djikstra's advice and start counting at zero anyway. \\cite{Fitzpatrick2008, Djikstra1982}} We know that radii of a circle have the same length. So if we draw a circle centered at \\textsf{1} that passes through \\textsf{0}, it will contain all points that are all equally far away from \\textsf{1} as the point \\textsf{0} is. Breakthrough!\n\nNow we can extend the original line segment to meet the circle. The point of their intersection is exactly one unit length away from the point \\textsf{1}. Mark this point with the suggestive label \\textsf{2}. We can continue this way as many times as we like---geometric line segments stretch as far as we care to imagine. After repeating the process $n$ times, we have constructed a line segment $n$ units long. Do it once again, and we're at $n+1$.\n\n\\begin{marginfigure}\n  \\input{figures/mathematical-background/natural-numbers-construction.tex}\n  \\caption{\\label{fig:mb-natural-numbers-construction} Construction of the natural numbers}\n\\end{marginfigure}\n\nThere is something curious about the construction of the natural numbers given above: we got to pick the unit length in the first step. It didn't matter if we chose an inch, 19 centimeters, a dozen poronkusemas\\sidenote{\\emph{Poronkusema} is Finnish for the distance a reindeer can generally travel before stopping to urinate. It's not a precise measure of distance, perhaps 7.5 kilometers. But it's surely not more.}, or anything other length; the contstruction continues just same. Each choice gives a different \\emph{coordinatization} of the line. \\emph{Coordinates} are labels we give to points in geometric objects. In this case, the points on a line. Once we marked our zero point and chose a unit length, the positions of all of the coordinates of all the other points on the line were locked into place. Because our construction of the natural numbers did not make use of any particular coordinate system---remember, we got to choose the unit length---we say that the construction is \\emph{coordinate-free} or \\emph{coordinate independent}.\n\n\\begin{question}\n  Figure \\ref{fig:mb-3-real-lines} shows three real lines, each of which has been coordinatized by a different unit length. How are the coordinate systems related to one another?\n\\end{question}\n\n\\begin{marginfigure}\n  \\input{figures/mathematical-background/3-real-lines.tex}\n  \\caption{\\label{fig:mb-3-real-lines} Three different coordinatizations by three different unit lengths}\n\\end{marginfigure}\n\n\\begin{question}\n  Does Figure \\ref{fig:mb-3-real-lines} prove that there are multiple, different real number lines? What do you think?\n\\end{question}\n\n\\begin{question}\n  Consider a piece of string. Alice uses an English ruler to measure its length and finds the string to be exactly 25 inches long. Bob uses a metric ruler and finds the string to be exactly 63.5 centimeters long. Who is correct? What is the actual length of the string?\n\\end{question}\n\n\\begin{question}\n  In what ways is the previous question about Alice and Bob like the geometric onstruction of the natural numbers?\n\\end{question}\n\n\nYou can do more than just construct the natural numbers. You can combine them! Two natural numbers $n$ and $m \\in\\mathbf{N}$ can be \\emph{added} together to form their sum $n+m$ which is another natural number. To see the effects of addition geometrically, let's look at the specific of adding 1 to another number $n$. We can write this rule as\n\n\\begin{equation}\n  \\label{eqn:add-one}\n  f: n \\mapsto n + 1.\n\\end{equation}\n\nWe read equation \\label{eqn:add-one} as the ``function $f$ that maps $n$ to $n + 1$.''\\sidenote{Mathematical jargon is full of references to cartography. We have already bumped into maps and coordinates. Geometers deal with charts and altases, too. Maps capture relationships between the objects the represent, e.g., ``You are here. The nearest bathroom is there.'' Mathematics is the study of relationships between objects and transformations that preserve those relationships. So maps show up all the time.} We applied a function like $f$ when we first constructed the natural numbers, starting at the zero. When we apply $f$ to the whole real line, it looks like figure \\ref{fig:add-one}.\n\n\\begin{question}\n  Describe the effect of $f: n \\mapsto n + 1$ on the real number line geometrically.\n\\end{question}\n\nThe two number lines in \\ref{fig:add-one} are related to each other through the mapping $f$. The bottom lie is the \\emph{image} of $f$. The image of a map is the set of output values $f(n)$ generated by applying the map to input values $n$. In this case, the image is a translation back one unit length by each coordinate. Informally, the whole number line got shifted back by one. Backward? That's a little confusing. Didn't we add to each point? Indeed we did.\n\n\\begin{marginfigure}\n  \\input{figures/mathematical-background/add-one.tex}\n  \\caption{\\label{fig:add-one} The image of $f: n \\mapsto n + 1$}\n\\end{marginfigure}\n\nBy adding 1 to each coordinate, we sped up the labeling of each point on the line. Thanks to $f$, coordinates appear one unit earlier than before, making them appear to have moved backwards. In this way, we can think of $f$ acting not on points on the line directly, but simply transforming their coordinate labels from one to another. The points on the line stay in place. Their labels move. To emphasis this viewpoint, we call $f$ a \\emph{coordinate transformation} of the real line.\n\nIn general, coordinate transformations of the form $t_m: n \\mapsto n + m$ translate the line $m$ units backwards. There is a special translation $t_0: n \\mapsto n + 0$ called the \\emph{identity} translation.\\sidenote{The identity translation is so important, we'll give it its own notation $id_+$.} The identity translation is laziest translation you can imagine. It accepts an input $n$ and produces an output which is identically $n$. Because zero is the unique number such that $n + 0 = n$ for any $n \\in \\mathbf{N}$, we say that zero is the \\emph{additive identity element} of the natural numbers.\n\n\\begin{question}\n  Draw the image of $id_+$.\n\\end{question}\n\nNotice that when $m \\in \\mathbf{N}$, the translation $t_m$ maps the coordinates of one natural number to the coordinate of another natural number. That is, the image $t_m(\\mathbf{N})$ is the again the natural numbers $\\mathbf{N}$. That is, the natural numbers are \\emph{closed} under addition.\\sidenote{I told you we'd see more examples of closure!}\n\n\\begin{question}\n  What are some other operations that the natural numbers are closed under?\n\\end{question}\n\n\\begin{question}\n  What is an operation that the natural numbers are not closed under?\n\\end{question}\n\n% Closure under multiplication. (Scales things!) One as multiplicative identity. But $x + 1 = 0$ has no solution in the natural numbers. I.e., not closed under substraction. No, additive inverse. Enter the integers.\n\n%\n% \\textbf{STREAM OF CONSCIOUSNESS}\n%\n% Then fractions. Pythagoras' cult discovered the irrationality of square root of two. Are there any holes? Answer to this question can be found in the study of real analysis. Basically all the numbers we would ever want are there. But special note: the reals are not the only completion of $\\mathbf{Q}$. See, for example, the $p$-adics. For now, the real line will suffice.  We will review a few properties of the real numbers.\n%\n% Can we say \\emph{the} real line with certainty? Field-preserving homomorphisms. Affine group. But real proof requires a proper construction, e.g., Dedekind cuts.\n%\n%\n% \\section{Complex Numbers}\n\n% \\marginnote{\\textsf{Jordan Chapter 2: Imaginary Numbers}}\n", "meta": {"hexsha": "7865420242893c8005e0ce8f4d41c0975a0555da", "size": 12737, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/mathematical-background.tex", "max_stars_repo_name": "jareyes/qm-companion", "max_stars_repo_head_hexsha": "206d8070af7b19f09d79f0264aef0485c3c72380", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-13T11:03:30.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-13T11:03:30.000Z", "max_issues_repo_path": "chapters/mathematical-background.tex", "max_issues_repo_name": "ofenerci/qm-companion", "max_issues_repo_head_hexsha": "206d8070af7b19f09d79f0264aef0485c3c72380", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/mathematical-background.tex", "max_forks_repo_name": "ofenerci/qm-companion", "max_forks_repo_head_hexsha": "206d8070af7b19f09d79f0264aef0485c3c72380", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-04-20T16:03:15.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-13T12:35:37.000Z", "avg_line_length": 109.8017241379, "max_line_length": 1048, "alphanum_fraction": 0.7757713747, "num_tokens": 3088, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.8031737987125613, "lm_q1q2_score": 0.7138277786750443}}
{"text": "\\section{Topic modeling}\n\n\\paragraph{Vector space models problems}\nThe approaches seen so far did not take into \nconsideration semantics of words. \nWe understood that the vector space models suffer \nfrom high dimensionality, the terms also could be synonyms, \nleading to ambiguity, in fact two words that means \nthe same thing are two different dimensions in the model.\n\\subsection{Linear algebra recap}\n\n\\paragraph{Eigenvalues and eigenvectors}\nGiven a square matrix of size $n$, if we find a\n $n$ dimensional vector such that\n$$A\\vec{x} = \\lambda\\vec{x}$$\n$\\lambda$ is a eigenvalue and $\\vec{x}$ is an eigenvector.\nIt also holds that \n$$(A - \\lambda I )\\vec{x} = 0 \\implies |A - \\lambda I| = 0$$\nwhere $I$ is the identity matrix, and the implication holds as $\\vec{x}$ is non-zero.\nIn general the second part of the implication has $n$ solutions, so \n$n$ eigenvalues associated with a certain eigenvector.\n\nAfter finding the solutions we can write that \n\\begin{equation}\n    \\begin{aligned}\n        AX &= A[\\vec{x_1}, \\dots, \\vec{x_n}] = A\\vec{x_1} + \\dots + A\\vec{x_n}\\\\\n        & = \\lambda_1\\vec{x_1} + \\dots + \\lambda_n\\vec{x_n} = \\varLambda X  \n    \\end{aligned}\n\\end{equation}\nWhere $\\varLambda$ is the diagonal matrix of the eigenvalues, and $X$ the matrix \nwith eigenvectors. \n\n\\paragraph{Diagonalization}\nIf the $n$ eigenvector found at the previous step are independent, \nand the matrix $A$ is invertible, which is not a problem as its square, \nwe can write \n$$AX = X\\varLambda \\rightarrow AXX^{-1} = XAX^{-1} \\rightarrow A = X\\varLambda X^{-1}$$\n\nThis representation is called diagonalization of $A$.\nAlso, if $A$ is symmetric, we can write\n$$A = X\\varLambda X^{\\top}$$\n\n\\subsection{Latent Semantic Indexing}\nThe goal is to discover topics that motivate data\nby using matrix factorization techniques, while \ntaking in consideration the possibility of expressing\nthe same topic with different words.\n\n\\paragraph{Diagonalization}\nWe learned that if a matrix is symmetric we can write the \ndiagonalization as $A = X\\varLambda X^{\\top}$.\nThe question is, what happens if we multiply the \ndocument-term matrix by itself? \n\nWe find a symmetric matrix that somehow encapsulates a notion of similarity \nof documents because if two documents share the same words the \nproduct will be really high for that two documents.\n\nIf we multiply the term-document matrix we obtain a similar result.\n\n\\paragraph{Singular Value decomposition}\nThe idea behind the approach is to define the term document matrix \n$A$ in terms of $$A = U \\Sigma V^\\top$$\nthis means finding something that holds together documents and terms. \nThe terms in the diagonalization represent:\n\\begin{itemize}\n    \\item$V$ is the matrix with the eigenvectors of $AA^\\top$\n    \\item$U$ is the matrix with the eigenvectors of $A^\\top A$\n    \\item $\\Sigma$ is the diagonal matrix composed starting from the eigenvalues\n    of $A A^\\top$ and $A^\\top A$, which are the same\n\\end{itemize}\nNote that the eigenvalues in $\\Sigma$ are sorted on the diagonal.\n\n\\paragraph{Defining topics}\nAfter applying singular value decomposition \nto the document term matrix we have the latent topic matrix\n$\\Sigma$.\nWe can consider a new matrix $\\Sigma_{k \\times k}$, that \nsomehow encapsulate the top $k$ relevant topics for \nthe documents.\nNote that after this cut of $\\Sigma$ we get a diagonalization \nthat is an approximation of the original matrix.\n$$A \\approx U \\Sigma_{k \\times k} V^\\top$$\n\nTo make topics human understandable \nwe assign each a set of words, and also, we can assign to each \ndocument a topic, in a soft clustering fashion.\n\nBasically, given the three matrixes that SVD outputs, after \ncutting $\\Sigma$ as discussed above,   \nwe can discover what topics have the documents by multiplying \n$U$ and $\\Sigma_{k \\times k}$. The output will be a matrix with document \non rows and topics on columns, where the absolute value of \na cell represent how strong a topics is present in a document.\n\nIn the same way we can find a relation between topics and words \nby multiplying $\\Sigma_{k \\times k}$ and $V^\\top$.\n\n\\subsection{Latent Dirichlet Allocation}\nThis approach relies on probability theory to find topics\nin documents. \nIn the LSI approach we tried to find a \\emph{glue}, formally $\\Sigma$,\nbetween document and terms.\n\nIn LDA the goal is to estimate the probabilistic relation \nbetween topics and documents, basically the probability that \na given document contains a given topic, and the one that \na topics contains a certain word.\n\n\\paragraph{Elements}\nThe basic elements of the approach are:\n\\begin{itemize}\n    \\item $\\phi^{(k)}$ probability distribution over the vocabulary \n    for the kth topic\n    \\item $\\theta_d$ document distribution over topics\n    \\item $z_i$ topic index for the word $w_i$\n    \\item $\\alpha, \\beta$ hyperparameters that govern the first \n    two distributions\n\\end{itemize}\n\n\\paragraph{Estimating the generative model}\nTo find the topics and document distributions we \nassume that they were generated by a given distribution\nand try to estimate them.\n\n\\dots\\\\\n\\dots\\\\\n\\dots\n", "meta": {"hexsha": "30af57be220fc57d5a3057b82c0ab9854f0bccf7", "size": 5067, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-courses/information-retrieval/chapters/topic_modeling.tex", "max_stars_repo_name": "marcodb97/unimi-notes", "max_stars_repo_head_hexsha": "b0b9520a01568c4c64f4fdb69523dd05339ee8f6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "old-courses/information-retrieval/chapters/topic_modeling.tex", "max_issues_repo_name": "marcodb97/unimi-notes", "max_issues_repo_head_hexsha": "b0b9520a01568c4c64f4fdb69523dd05339ee8f6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old-courses/information-retrieval/chapters/topic_modeling.tex", "max_forks_repo_name": "marcodb97/unimi-notes", "max_forks_repo_head_hexsha": "b0b9520a01568c4c64f4fdb69523dd05339ee8f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-09T08:24:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T08:24:02.000Z", "avg_line_length": 39.2790697674, "max_line_length": 87, "alphanum_fraction": 0.748963884, "num_tokens": 1277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807408, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7137969126378814}}
{"text": "\\title{Unsupervised Learning}\n\n\\subsection{Unsupervised Learning}\n\nIn unsupervised learning, the task is to infer hidden structure from\nunlabeled data, comprised of training examples $\\{x_n\\}$.\n\nWe demonstrate with an example in Edward.\nAn interactive version with Jupyter notebook is available\n\\href{http://nbviewer.jupyter.org/github/blei-lab/edward/blob/master/notebooks/unsupervised.ipynb}{here}.\n\n\\subsubsection{Data}\n\nUse a simulated data set of 2-dimensional data points\n$\\mathbf{x}_n\\in\\mathbb{R}^2$.\n\\begin{lstlisting}[language=Python]\ndef build_toy_dataset(N):\n  pi = np.array([0.4, 0.6])\n  mus = [[1, 1], [-1, -1]]\n  stds = [[0.1, 0.1], [0.1, 0.1]]\n  x = np.zeros((N, 2), dtype=np.float32)\n  for n in range(N):\n    k = np.argmax(np.random.multinomial(1, pi))\n    x[n, :] = np.random.multivariate_normal(mus[k], np.diag(stds[k]))\n\n  return x\n\nN = 500  # number of data points\nD = 2  # dimensionality of data\n\nx_train = build_toy_dataset(N)\n\\end{lstlisting}\n\nWe visualize the generated data points.\n\\begin{lstlisting}[language=Python]\nplt.scatter(x_train[:, 0], x_train[:, 1])\nplt.axis([-3, 3, -3, 3])\nplt.show()\n\\end{lstlisting}\n\\includegraphics[width=700px]{/images/unsupervised-fig0.png}\n\n\\subsubsection{Model}\n\nA mixture model is a model typically used for clustering.\nIt assigns a mixture component to each data point, and this mixture component\ndetermines the distribution that the data point is generated from. A\nmixture of Gaussians uses Gaussian distributions to generate this data\n\\citep{bishop2006pattern}.\n\nFor a set of $N$ data points,\nthe likelihood of each observation $\\mathbf{x}_n$ is\n\n\\begin{align*}\n  p(\\mathbf{x}_n \\mid \\pi, \\mu, \\sigma)\n  &=\n  \\sum_{k=1}^K \\pi_k \\, \\text{Normal}(\\mathbf{x}_n \\mid \\mu_k, \\sigma_k).\n\\end{align*}\n\nThe latent variable $\\pi$ is a $K$-dimensional probability vector\nwhich mixes individual Gaussian distributions, each\ncharacterized by a mean $\\mu_k$ and standard deviation $\\sigma_k$.\n\nDefine the prior on $\\pi\\in[0,1]$ such that $\\sum_{k=1}^K\\pi_k=1$ to be\n\n\\begin{align*}\n  p(\\pi)\n  &=\n  \\text{Dirichlet}(\\pi \\mid \\alpha \\mathbf{1}_{K})\n\\end{align*}\n\nfor fixed $\\alpha=1$. Define the prior on each component $\\mathbf{\\mu}_k\\in\\mathbb{R}^D$ to be\n\n\\begin{align*}\n  p(\\mathbf{\\mu}_k)\n  &=\n  \\text{Normal}(\\mathbf{\\mu}_k \\mid \\mathbf{0}, \\mathbf{I}).\n\\end{align*}\n\nDefine the prior on each component $\\mathbf{\\sigma}_k^2\\in\\mathbb{R}^D$ to be\n\n\\begin{align*}\n  p(\\mathbf{\\sigma}_k^2)\n  &=\n  \\text{InverseGamma}(\\mathbf{\\sigma}_k^2 \\mid a, b).\n\\end{align*}\n\nWe build two versions of the model in Edward: one jointly with the\nmixture assignments $c_n\\in\\{0,\\ldots,K-1\\}$ as latent variables,\nand another with them summed out.\n\nThe joint version includes an explicit latent variable for the mixture\nassignments. We implement this with the \\texttt{ParamMixture} random\nvariable; it takes as input the mixing probabilities, the components'\nparameters, and the distribution of the components. It is the\ndistribution of the mixture conditional on mixture assignments. (Note\nwe can also write this separately by first building a `Categorical`\nrandom variable for \\texttt{z} and then building \\texttt{x}; \\texttt{ParamMixture} avoids\nrequiring \\texttt{tf.gather} which is slightly more efficient.)\n\n\\begin{lstlisting}[language=Python]\nfrom edward.models import Dirichlet, InverseGamma, MultivariateNormalDiag, \\\n    Normal, ParamMixture\n\nK = 2  # number of components\n\npi = Dirichlet(tf.ones(K))\nmu = Normal(tf.zeros(D), tf.ones(D), sample_shape=K)\nsigmasq = InverseGamma(tf.ones(D), tf.ones(D), sample_shape=K)\nx = ParamMixture(pi, {'loc': mu, 'scale_diag': tf.sqrt(sigmasq)},\n                 MultivariateNormalDiag,\n                 sample_shape=N)\nz = x.cat\n\\end{lstlisting}\n\nThe collapsed version marginalizes out the mixture assignments. We\nimplement this with the \\texttt{Mixture} random variable; it takes as\ninput a Categorical distribution and a list of individual distribution\ncomponents. It is the distribution of the mixture summing out the\nmixture assignments.\n\n\\begin{lstlisting}[language=Python]\nfrom edward.models import Categorical, Dirichlet, InverseGamma, Mixture, \\\n    MultivariateNormalDiag, Normal\n\nK = 2  # number of components\n\npi = Dirichlet(tf.ones(K))\nmu = Normal(tf.zeros(D), tf.ones(D), sample_shape=K)\nsigma = InverseGamma(tf.ones(D), tf.ones(D), sample_shape=K)\ncat = Categorical(probs=pi, sample_shape=N)\ncomponents = [\n    MultivariateNormalDiag(mu[k], sigma[k], sample_shape=N)\n    for k in range(K)]\nx = Mixture(cat=cat, components=components)\n\\end{lstlisting}\n\nWe will use the joint version in this analysis.\n\n\\subsubsection{Inference}\n\nEach distribution in the model is written with conjugate priors, so we\ncan use Gibbs sampling. It performs Markov chain Monte Carlo by\niterating over draws from the complete conditionals of each\ndistribution, i.e., each distribution conditional on a previously\ndrawn value. First we set up Empirical random variables which will\napproximate the posteriors using the collection of samples.\n\n\\begin{lstlisting}[language=Python]\nT = 500  # number of MCMC samples\nqpi = Empirical(tf.Variable(tf.ones([T, K]) / K))\nqmu = Empirical(tf.Variable(tf.zeros([T, K, D])))\nqsigmasq = Empirical(tf.Variable(tf.ones([T, K, D])))\nqz = Empirical(tf.Variable(tf.zeros([T, N], dtype=tf.int32)))\n\\end{lstlisting}\n\nRun Gibbs sampling. We write the training loop explicitly, so that we can track\nthe cluster means as the sampler progresses.\n\\begin{lstlisting}[language=Python]\ninference = ed.Gibbs({pi: qpi, mu: qmu, sigmasq: qsigmasq, z: qz},\n                     data={x: x_train})\ninference.initialize()\n\nsess = ed.get_session()\ntf.global_variables_initializer().run()\n\nt_ph = tf.placeholder(tf.int32, [])\nrunning_cluster_means = tf.reduce_mean(qmu.params[:t_ph], 0)\n\nfor _ in range(inference.n_iter):\n  info_dict = inference.update()\n  inference.print_progress(info_dict)\n  t = info_dict['t']\n  if t % inference.n_print == 0:\n    print(\"\\nInferred cluster means:\")\n    print(sess.run(running_cluster_means, {t_ph: t - 1}))\n\\end{lstlisting}\n\nSee the associated Jupyter notebook for the inferred cluster means\ntracked during training.\n\n\\subsubsection{Criticism}\n\nWe visualize the predicted memberships of each data point. We pick\nthe cluster assignment which produces the highest posterior predictive\ndensity for each data point.\n\nTo do this, we first draw a sample from the posterior and calculate a\na $N\\times K$ matrix of log-likelihoods, one for each data point\n$\\mathbf{x}_n$ and cluster assignment $k$.\nWe perform this averaged over 100 posterior samples.\n\n\\begin{lstlisting}[language=Python]\n# Calculate likelihood for each data point and cluster assignment,\n# averaged over many posterior samples. ``x_post`` has shape (N, 100, K, D).\nmu_sample = qmu.sample(100)\nsigmasq_sample = qsigmasq.sample(100)\nx_post = Normal(loc=tf.ones([N, 1, 1, 1]) * mu_sample,\n                scale=tf.ones([N, 1, 1, 1]) * tf.sqrt(sigmasq_sample))\nx_broadcasted = tf.tile(tf.reshape(x_train, [N, 1, 1, D]), [1, 100, K, 1])\n\n# Sum over latent dimension, then average over posterior samples.\n# ``log_liks`` ends up with shape (N, K).\nlog_liks = x_post.log_prob(x_broadcasted)\nlog_liks = tf.reduce_sum(log_liks, 3)\nlog_liks = tf.reduce_mean(log_liks, 1)\n\\end{lstlisting}\n\nWe then take the $\\arg\\max$ along the columns (cluster assignments).\n\\begin{lstlisting}[language=Python]\nclusters = tf.argmax(log_liks, 1).eval()\n\\end{lstlisting}\n\nPlot the data points, colored by their predicted membership.\n\\begin{lstlisting}[language=Python]\nplt.scatter(x_train[:, 0], x_train[:, 1], c=clusters, cmap=cm.bwr)\nplt.axis([-3, 3, -3, 3])\nplt.title(\"Predicted cluster assignments\")\nplt.show()\n\\end{lstlisting}\n\n\\includegraphics[width=700px]{/images/unsupervised-fig1.png}\n\nThe model has correctly clustered the data.\n\n\\subsubsection{Remarks: The log-sum-exp trick}\n\nFor a collapsed mixture model, implementing the log density can be tricky.\nIn general, the log density is\n\\begin{align*}\n  \\log p(\\pi) +\n  \\Big[ \\sum_{k=1}^K \\log p(\\mathbf{\\mu}_k) + \\log\n  p(\\mathbf{\\sigma}_k) \\Big] +\n  \\sum_{n=1}^N \\log p(\\mathbf{x}_n \\mid \\pi, \\mu, \\sigma),\n\\end{align*}\nwhere the likelihood is\n\\begin{align*}\n  \\sum_{n=1}^N \\log p(\\mathbf{x}_n \\mid \\pi, \\mu, \\sigma)\n  &=\n  \\sum_{n=1}^N \\log \\sum_{k=1}^K \\pi_k \\, \\text{Normal}(\\mathbf{x}_n \\mid\n  \\mu_k, \\sigma_k).\n\\end{align*}\nTo prevent numerical instability, we'd like to work on the log-scale,\n\\begin{align*}\n  \\sum_{n=1}^N \\log p(\\mathbf{x}_n \\mid \\pi, \\mu, \\sigma)\n  &=\n  \\sum_{n=1}^N \\log \\sum_{k=1}^K \\exp\\Big(\n  \\log \\pi_k + \\log \\text{Normal}(\\mathbf{x}_n \\mid \\mu_k, \\sigma_k)\\Big).\n\\end{align*}\nThis expression involves a log sum exp operation, which is\nnumerically unstable as exponentiation will often lead to one value\ndominating the rest. Therefore we use the log-sum-exp trick.\nIt is based on the identity\n\\begin{align*}\n  \\mathbf{x}_{\\mathrm{max}}\n  &=\n  \\arg\\max \\mathbf{x},\n  \\\\\n  \\log \\sum_i \\exp(\\mathbf{x}_i)\n  &=\n  \\log \\Big(\\exp(\\mathbf{x}_{\\mathrm{max}}) \\sum_i \\exp(\\mathbf{x}_i -\n  \\mathbf{x}_{\\mathrm{max}})\\Big)\n  \\\\\n  &=\n  \\mathbf{x}_{\\mathrm{max}} + \\log \\sum_i \\exp(\\mathbf{x}_i -\n  \\mathbf{x}_{\\mathrm{max}}).\n\\end{align*}\nSubtracting the maximum value before taking the log-sum-exp leads to\nmore numerically stable output. The \\texttt{Mixture} random variable\nimplements this trick for calculating the log-density.\n\n\\subsubsection{References}\\label{references}\n", "meta": {"hexsha": "183e3c1d364513a567e1fefe987668a07d48c51d", "size": 9408, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tutorials/unsupervised.tex", "max_stars_repo_name": "xiangze/edward", "max_stars_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-11T03:33:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-11T03:33:36.000Z", "max_issues_repo_path": "docs/tex/tutorials/unsupervised.tex", "max_issues_repo_name": "xiangze/edward", "max_issues_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/tex/tutorials/unsupervised.tex", "max_forks_repo_name": "xiangze/edward", "max_forks_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-12-22T08:21:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-16T02:45:04.000Z", "avg_line_length": 34.5882352941, "max_line_length": 105, "alphanum_fraction": 0.7232142857, "num_tokens": 2795, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7137969003066872}}
{"text": "\\item[(c)] \\subquestionpoints{0} [{\\bf{This part is optional and does not have any points}}]\nIn the previous part, we studied MSE and decomposed it to two terms corresponding to the sharpness and calibration error.\nBut as we explained, there are other different ways to measure the calibration and sharpness of a model.\nIn this part we focus on logistic regression models.\n%Logistic regression tends to output well calibrated probabilities (this is\n%often not true with other classifiers such as SVMs). \n%We will\n%dig a little deeper in order to understand why this is the case, and find that\n%the structure of the loss function explains this property.\nIn particular, we are going to show logistic loss can also be decomposed to two terms; where one term can be interpreted as the sharpness of the prediction (which we call log-sharpness) and the other can be interpreted as the calibration error (which we call log-calibration-error).  \nRecall that the logistic loss (on population) of the model $h$ is defined as:\n\\begin{align}\n\\text {Log-Loss}(h) = \\E [-Y \\log (h(X)) - (1-Y) \\log (1-h(X))]\n\\end{align}\n\nProve that logistic loss can be decomposed to two terms as follows:\n\\begin{align}\n\\text {Log-Loss}(h) =&\\underbrace{\\E \\left [T(X) \\log \\left(\\frac{T(X)}{h(X)}\\right) + (1-T(X)) \\log \\left(\\frac{1-T(X)}{1-h(X)}\\right)\\right ]}_\\text {log-calibration-error} \\nonumber \\\\\n&-\\underbrace{\\E \\left [T(X) \\log (T(X)) + (1-T(X)) \\log (1-T(X)) \\right]}_\\text {log-sharpness}\\label{eqn:log-decompose}\n\\end{align}\n\nDiscuss why the log-calibration-error term in \\eqref{eqn:log-decompose} is a meaningful term for measuring the calibration error and specify when it attains its minimum.\nSimilarly discuss why log-sharpness term in \\eqref{eqn:log-decompose}  is a meaningful term for measuring the sharpness of a model and specify when it attains its maximum.\n\n\\paragraph{Hint.} \n\nFor showing that log-calibration-error and log-sharpness are meaningful terms, you should use your information theory knowledge (there is a section about information theory in the previous question).\n%\nFor each data point $x$, both model prediction ($h(x)$) and underlying probability ($T(x)$) define a distribution over the label set $\\mathcal{Y} = \\{0,1\\}$.\nIn particular, define distribution $P_1$ on $\\mathcal{Y}=\\{0,1\\}$ as follows:\n$P_1(Y=1) = T(x)$ and $P_1(Y=0) = 1-T(x)$. \nSimilarly, define distribution $P_2$ on $\\mathcal{Y}=\\{0,1\\}$ as follows: $P_2(Y=1) = h(x)$ and $P_2(Y=0) = 1-h(x)$. \nYou can interpret the log-calibration-error in \\eqref{eqn:log-decompose} as KL-divergence distance between these two distributions. \n%\\tnote{Ii think it's fine to just give the exact formula here to further reduce the difficulty? or perhaps instead wee should should reveal what's $P_1$ and $P_2$ that we are thinking}\nRecall that the KL divergence distance between these two distributions is:\n\\begin{align}\n\t\\infdiv{P_1}{P_2} = P_1(Y=0) \\log\\left(\\frac{P_1(Y=0)}{P_2(Y=0)}\\right) + P_1(Y=1) \\log\\left(\\frac{P_1(Y=1)}{P_2(Y=1)}\\right) \n\\end{align} \nThe log-sharpness term in \\eqref{eqn:log-decompose} can be expressed as the negative entropy of the distribution corresponding to $T(x)$. \nRecall that entropy of distribution $P_1$ is:\n\\begin{align}\n\t\\text {H}(P_1) = -P_1(Y=0)\\log(P_1(Y=0)) - P_1(Y=1)\\log(P_1(Y=1))\n\\end{align}\n\n\\noindent{\\bf Remark: } \nThe decomposition suggests that minimizing the logistic loss (on the population) tends to minimize the calibration error as well, since the calibration error is upper bounded by the logistic loss. In practice, when the train and test sets are from the same distribution and when the model has not overfit or underfit, logistic regression tends to be well calibrated on the test data as well.  In contrast, modern large-scale deep learning models trained with the logistic loss are typically not well-calibrated, likely since the population  logistic loss suffers from overfitting (the test loss is much higher than the train loss), even when there is little overfitting in terms of the accuracy. As such, often people use other recalibration methods to adjust the outputs of a deep learning model to be better calibrated.\n", "meta": {"hexsha": "508614fb62d32ce7819a706971ad0eac3debcdf7", "size": 4150, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ps3/tex/calibration/03-log-decomposition.tex", "max_stars_repo_name": "terryli710/CS229", "max_stars_repo_head_hexsha": "c07be2953257bd54f99629a24ba59d6aa4a1d919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ps3/tex/calibration/03-log-decomposition.tex", "max_issues_repo_name": "terryli710/CS229", "max_issues_repo_head_hexsha": "c07be2953257bd54f99629a24ba59d6aa4a1d919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ps3/tex/calibration/03-log-decomposition.tex", "max_forks_repo_name": "terryli710/CS229", "max_forks_repo_head_hexsha": "c07be2953257bd54f99629a24ba59d6aa4a1d919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 88.2978723404, "max_line_length": 821, "alphanum_fraction": 0.7477108434, "num_tokens": 1153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152498, "lm_q2_score": 0.8705972600147106, "lm_q1q2_score": 0.7137968994133931}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Two-sample tests}\\label{sec:two-sample-tests}\n\nSo far we have looked at one-sample tests, where hypotheses about an unknown parameter are tested based on a single sample $X_1,X_2,\\ldots,X_n$ from the distribution in question. For paired samples $X_1,X_2,\\ldots,X_n$ and $Y_1,Y_2,\\ldots,Y_n$ we apply one-sample tests to the differences $D_i=X_i-Y_i$. We now turn our attention to the question of whether two \\emph{independent} random samples are drawn from the same distribution.\n\\bit\n\\it \\emph{Welch's t-test} is a parametric test to detect a difference between the means of two independent samples.\n\\it The \\emph{Mann-Whitney test} is a non-parametric test to detect a difference between the medians of two independent samples.\n\\eit\n%-----------------------------\n\\subsection{Welch's t-test}\nLet $X\\sim N(\\mu_1,\\sigma_1^2)$ and $Y\\sim N(\\mu_2,\\sigma_2^2)$ be independent random variables, and suppose we with to test the null hypothesis $H_0:\\mu_1=\\mu_2$ against a suitable alternative. Let $X_1,X_2,\\ldots,X_m$ be a random sample from the distribution of $X$ and let $Y_1,Y_2,\\ldots,Y_n$ be a random sample from the distribution of $Y$. \n\nUsing characteristic functions it can be shown that a linear combination of normal variables is a normal variable: if $X\\sim N(\\mu_1,\\sigma_1^2)$ and $Y\\sim N(\\mu_2,\\sigma^2_2)$ then\n\\[\naX+bY\\sim N(a\\mu_1+b\\mu_2, a^2\\sigma_1^2 + b^2\\sigma_2^2).\n\\]\nIn particular,\n\\[\nX-Y\\sim N(\\mu_1-\\mu_2, \\sigma_1^2 + \\sigma_2^2).\n\\]\nBecause the samples are independent,\n\\[\n\\bar{X} - \\bar{Y} \\sim N\\left(\\mu_1-\\mu_2, \\frac{\\sigma_1^2}{m} + \\frac{\\sigma_2^2}{n}\\right).\n\\]\n\nTo estimate the variances $\\sigma_1^2$ and $\\sigma_2^2$ we use the sample variances of $X$ and $Y$:\n%$S_1^2 = \\displaystyle\\frac{1}{m-1}\\sum_{i=1}^m (X_i-\\bar{X})^2$ and $S_2^2 = \\displaystyle\\frac{1}{n-1}\\sum_{j=1}^n (Y_j-\\bar{Y})^2$ \n\\[\nS_1^2 = \\displaystyle\\frac{1}{m-1}\\sum_{i=1}^m (X_i-\\bar{X})^2\n\\quad\\text{and}\\quad\nS_2^2 = \\displaystyle\\frac{1}{n-1}\\sum_{j=1}^n (Y_j-\\bar{Y})^2.\n\\]\nOur test statistic is\n\\[\nT = \\frac{(\\bar{X}-\\bar{Y})-(\\mu_1-\\mu_2)}{\\sqrt{S_1^2/m + S_2^2/n}} %\\sim t_{n-2} \\quad\\text{under $H_0:\\mu_1=\\mu_2$.} \n\\]\n\\bit\n\\it Under $H_0:\\mu_1=\\mu_2$ we have that $T\\sim t_{\\nu}$ approximately, where\n\\[\n\\nu = \\frac{(s_1^2/m+s_2^2/n)^2}{(s_1^2/m)^2(m-1) + (s_2^2/n)^2(n-1)} \\qquad\\text{(Welch-Satterthwaite equation).}\n\\]\n%(Student's $t$-distribution with $n-2$ degrees of freedom).\n\\it An approximate $100(1-\\alpha)\\%$ large-sample confidence interval for the difference $\\mu_1-\\mu_2$ is given by\n\\[\n(\\bar{X}-\\bar{Y}) \\pm z_{\\alpha/2}\\sqrt{\\frac{S_1^2}{m}+\\frac{S_2^2}{n}}.\n\\]\n\\eit\n\n%To test the null hypothesis $H_0:\\mu_1=\\mu_2$ we define the test statistic\n%\\[\n%T = \\frac{(\\bar{X}-\\bar{Y})-(\\mu_1-\\mu_2)}{\\sqrt{S_1^2/m + S_2^2/n}} \\sim t_{n-2} \\quad\\text{under $H_0:\\mu_1=\\mu_2$.} \n%\\]\n\n%For large samples, an approximate $100(1-\\alpha)\\%$ confidence interval for the difference $\\mu_1-\\mu_2$ is given by\n%\\[\n%(\\bar{X}-\\bar{Y}) \\pm z_{\\alpha/2}\\sqrt{\\frac{S_1^2}{m}+\\frac{S_2^2}{n}}\n%\\]\n\n%-----------------------------\n\\subsubsection*{Equal variances}\nSuppose that $X$ and $Y$ have equal variances: $X\\sim N(\\mu_1,\\sigma^2)$ and $Y\\sim N(\\mu_2,\\sigma^2)$ so that their distributions belong to the location model $\\mathcal{M}=\\{N(\\mu,\\sigma^2):\\mu\\in\\R\\}$. In this case we define the so-called \\emph{pooled estimator} of variance,\n\\[\nS_p^2 = \\frac{(m-1)S_1^2 + (n-1)S_2^2}{m+n-2}.\n\\]\nIt is easy to show that $S_p^2$ is an unbiased estimator of $\\sigma^2$, and that\n%\\[\n%T = \\frac{(\\bar{X}-\\bar{Y})-(\\mu_1-\\mu_2)}{S_p\\sqrt{\\frac{1}{m}+\\frac{1}{n}}} \\sim t_{m+n-2}. \n%\\]\n\\[\nT = \\frac{(\\bar{X}-\\bar{Y})-(\\mu_1-\\mu_2)}{S_p\\sqrt{1/m+1/n}} \\sim t_{m+n-2} \\quad\\text{under $H_0:\\mu_1=\\mu_2$}. \n\\]\n\n\\begin{example}\nLet $X_1,X_2,\\ldots,X_{10}$ be a random sample from the $N(\\mu_1,\\sigma^2)$ distribution, and let $Y_1,Y_2,\\ldots,Y_7$ be an independent random sample from the $N(\\mu_2,\\sigma^2)$ distribution. Realisations of the samples yield the sample means $\\bar{x}=4.2$ and $\\bar{y}=3.4$ and the sample variances $s_1^2=49$ and $s_2^2=32$. \n\\ben\n\\it Test the hypothesis $H_0:\\mu_1=\\mu_2$ against $H_1:\\mu_1>\\mu_2$.\n\\it Find a $90\\%$ confidence interval for the difference $\\mu_1-\\mu_2$.\n\\een\n\\begin{solution}\n\\ben\n\\it With $m=10$ and $n=7$, the pooled estimator of variance is\n\\[\ns_p^2 = \\frac{(m-1)s_1^2 + (n-1)s_2^2}{m + n - 2} = \\frac{(9\\times 49) + (6\\times 32)}{10 + 7 - 2} = 633/15 = 42.2\n\\]\nThe test statistic is \n\\[\nT = \\frac{(\\bar{X}-\\bar{Y})-(\\mu_1-\\mu_2)}{S_p\\sqrt{\\frac{1}{m}+\\frac{1}{n}}} \\sim t_{m+n-2}\\text{ under $H_0:\\mu_1=\\mu_2$.}\n\\]\nThe observed value of the test statistic is\n\\[\nt = \\frac{(\\bar{x}-\\bar{y})}{s_p\\sqrt{1/m+1/n}} \\frac{0.8}{\\sqrt{4.2(1/10+1/7)}} = 0.7921 \\text{ (approx.)}\n\\]\nUnder $H_0:\\mu_1=\\mu_2$, $T\\sim t_{m+n-2}$. Upper-tail critical values are 1.341 (10\\%) and 1.753 (5\\%), so there is not enough evidence to reject the null hypothesis $H_0:\\mu_1=\\mu_2$. \n\\it % ci\nA $90\\%$ confidence interval for $\\mu_1-\\mu_2$ is\n\\[\n(\\bar{x}-\\bar{y}) \\pm t_c s_p\\sqrt{1/m+1/n} = (0.8\\pm 1.753\\times 6.4962\\times\\sqrt{1/10+1/7}) = (-4.81, 6.41).\n\\]\n\\een\n\\end{solution}\n\\end{example}\n\n%-------------------------------------------------\n\\subsection{The Mann-Whitney test}\\label{sec:mw_test}\n\n%The \\emph{Mann-Whitney test} is a non-parametric test to detect a difference between the medians of two independent samples.\n\n%Let $X$ and $Y$ be two independent random variables having the same distribution, which is assumed to be continuous and symmetric, except that their medians $\\eta_1$ and $\\eta_2$ might be different. We test the null hypothesis $H_0:\\eta_1 = \\eta_2$ against a suitable alternative.\n\n% definition: mw statistic\n\\begin{definition}\nLet $X_1,X_2,\\ldots,X_m$ be a random sample from a continuous and symmetric distribution with median $\\eta_1$, and let $Y_1,Y_2,\\ldots,Y_n$ be a random sample from a possibly shifted version the same distribution, with median $\\eta_2$. To test the null hypothesis $H_0:\\eta_1=\\eta_2$ against a suitable alternative, the \\emph{Mann-Whitney} test statistic is\n\\[\nU_{m,n} = \\sum_{i=1}^m \\sum_{j=1}^n Z_{ij} \n\\qquad\\text{where}\\qquad \nZ_{ij} = \\begin{cases} \n\t1 \t& X_i < Y_j, \\\\\n\t0.5\t& X_i = Y_j, \\\\\n\t0\t& X_i > Y_j.\n\\end{cases}\n\\]\n\\end{definition}\n\nWe also define the complementary statistic \n\\[\nU'_{m,n} = \\displaystyle\\sum_{i=1}^m \\sum_{j=1}^n (1-Z_{ij}).\n\\]\nNote that $\\min(U_{m,n})=0$, $\\max(U_{m,n})=mn$, and\n\\[\nU_{m,n} + U'_{m,n} = \\sum_{i=1}^m\\sum_{j=1}^n \\big[Z_{ij} + (1-Z_{ij})\\big] = \\sum_{i=1}^m\\sum_{j=1}^n 1 = mn,\n\\]\n\nThe direction of the alternative hypothesis determines how the test statistic should be used:\n\\par\n\\begin{tabular}{ll}\n$\\bullet$ $H_1:\\eta_1 < \\eta_2$:\t\t\t& large values of $U$ support the alternative hypothesis. \\\\\n$\\bullet$ $H_1:\\eta_1 > \\eta_2$:\t\t\t& small values of $U$ support the alternative hypothesis. \\\\\n$\\bullet$ $H_1:\\eta_1 \\neq \\eta_2$:\\qquad\t& small and large values of $U$ support the alternative hypothesis.\n\\end{tabular}\n\n% example\n\\begin{example}\nSuppose we have the random sample $\\{14,5,8\\}$ from the distribution of $X$, and the random sample $\\{7,12,18,11\\}$ from the distribution of $Y$. Compute the Mann-Whitney test statistic for these data.\n\\end{example}\n\\begin{solution}\n\\[\\begin{array}{|c|cccc|}\\hline\nX_i\t\t& 14\t\t&  5\t\t&  8\t\t& \\\\ \\hline\nY_j\t\t&  7\t\t& 12\t\t& 18\t\t& 11 \\\\ \\hline \n\\end{array}\\]\n\\bit \n\\it $U$ is computed by counting the number of $X_i$ that are smaller than each $Y_j$.\n\\it $U'$ is computed by counting the number of $Y_j$ that are smaller than each $X_i$.\n\\eit\n\\begin{align*}\nu \t& = 1 + 2 + 3 + 2 = 8 \\\\\nu'\t& = 3 + 0 + 1 = 4\n\\end{align*}\nCheck: $u+u' = 8 + 4 = 12 = mn$.\n\\end{solution}\n\n% example\n\\begin{example}\\label{ex:mannwhitney}\nTwo different models of car, with engines of a similar size, were compared for their fuel consumption. Five cars of each model were evaluated in independent tests. The observation made was the number of miles travelled using 10 litres of petrol. Use a suitable non-parametric test to assess the claim that Model~2 is more economical than Model~1.\n\\[\\begin{array}{|l|ccccc|}\\hline\n\\text{Model 1}\t& 125.8\t& 126.7\t& 128.3\t& 130.5\t& 126.2 \\\\\n\\text{Model 2}\t& 127.8 & 131.4\t& 129.6\t& 130.2\t& 128.1 \\\\ \\hline\n\\end{array}\\]\n\\end{example}\n\\begin{solution}\nThe hypothesis test is $H_0:\\eta_1=\\eta_2$ against $H_1:\\eta_1 < \\eta_2$, where\n\\bit\n\\it $\\eta_1$ is the median number of miles travelled by Model~1, and\n\\it $\\eta_2$ is the median number of miless travelled by Model~2.\n\\eit\nOnly large values of $U$ support the alternative hypothesis. \nFrom tables ($m=5$, $n=5$), the critical value at significance level $\\alpha=0.05$ is $u_c=21$. \nFrom the data,\n\\begin{align*}\nu \t\t& = \\sum_{i=1}^5\\sum_{j=1}^5 Z_{ij} = 5 + 5 + 3 + 1 + 5 = 19. \\\\\nu'\t\t& = \\sum_{i=1}^5\\sum_{j=1}^5 (1-Z_{ij}) = 0 + 0 + 2 + 4 + 0 = 6.\n\\end{align*}\nCheck: $u + u' = mn = 25$. \n\\par\nSince the observed value $u=19$ is smaller than the critical value $u_c=21$, there is insufficient evidence to conclude that Model~2 is more economical than Model~1. \n\\end{solution}\n\n%-----------------------------\n\\subsubsection{Mean and variance of $U_{m,n}$}\n\n\\begin{theorem}\n%Let $X_1,X_2,\\ldots,X_m$ be a random sample from a continuous and symmetric distribution with median $\\eta_1$, and let $Y_1,Y_2,\\ldots,Y_n$ be a random sample from a possibly shifted version the same distribution, with median $\\eta_2$. \nUnder the null hypothesis $H_0:\\eta_1=\\eta_2$, \n\\[\n\\expe(U_{m,n}) = \\frac{mn}{2}\n\\text{\\quad and\\quad}\n\\var(U_{m,n}) = \\frac{mn}{12}(m+n+1).\n\\]\n\\end{theorem}\n\n\\begin{proof}\nUnder $H_0:\\eta_1=\\eta_2$ we have $\\prob(X_i<Y_j) = 1/2$, so $Z_{ij}\\sim\\text{Bernoulli}(1/2)$. \n\nHence $\\mathcal{E}(Z_{ij})=1/2$ and therefore\n\\[\n\\expe(U_{m,n}) \n\t= \\mathcal{E}\\left(\\sum_{i=1}^m\\sum_{j=1}^n Z_{ij}\\right)\n\t= \\sum_{i=1}^m\\sum_{j=1}^n \\mathcal{E}(Z_{ij})\n\t= \\frac{mn}{2}.\n\\]\n\nThe calculation to find the variance of $U$ involves some tedious algebra:\n\\begin{align*}\n\\expe(U_{m,n}^2)\n\t& = \\expe\\left[\\left(\\sum_{i=1}^m\\sum_{j=1}^n Z_{ij}\\right)\\left(\\sum_{k=1}^m\\sum_{\\ell=1}^n Z_{k\\ell}\\right)\\right] \\\\\n\t& = \\sum_{i=1}^m\\sum_{j=1}^n\\sum_{k=1}^m\\sum_{\\ell=1}^n \\expe(Z_{ij}Z_{k\\ell}) \\\\\n\t& = \\sum_{i=1}^m\\sum_{j=1}^n\\expe(Z_{ij}^2) \n\t\t\t+ \\sum_{i=1}^m\\sum_{\\substack{k=1\\\\k\\neq i}}^m\\sum_{j=1}^n\\expe(Z_{ij}Z_{kj}) \\\\\n\t& \\qquad + \\sum_{i=1}^m\\sum_{j=1}^n\\sum_{\\substack{\\ell=1\\\\\\ell\\neq j}}^n\\expe(Z_{ij}Z_{i\\ell})\n\t\t\t+ \\sum_{i=1}^m\\sum_{j=1}^n\\sum_{\\substack{k=1\\\\k\\neq i}}^m\\sum_{\\substack{\\ell=1\\\\\\ell\\neq j}}^n\\expe(Z_{ij}Z_{k\\ell}) \\\\\n\\end{align*}\nThe four sums have $mn$, $mn(m-1)$, $mn(n-1)$ and $mn(m-1)(n-1)$ terms, respectively.\n\\ben\n\\it \nIf $k=i$ and $\\ell=j$, the summand is $Z_{ij}Z_{k\\ell}=Z_{ij}^2$, and $Z^2_{ij}=1$ only if $X_i<Y_j$. Under the null hypothesis, this occurs with probability $1/2$.\n\\it\nIf $k\\neq i$ but $\\ell=j$, $Z_{ij}$ and $Z_{k\\ell}$ are not independent. In this case, $Z_{ij}Z_{k\\ell}=1$ if and only if both $X_i<Y_j$ and $X_k<Y_j$. There are six possible arrangements of $X_i$, $X_k$ and $Y_j$, of which two are such that $X_i<Y_j$ and $X_k<Y_j$. Under the null hypothesis, this occurs with probability $1/3$.\n\\it\nIf $k=i$ but $\\ell\\neq j$, by a similar argument we have $Z_{ij}Z_{k\\ell}=1$ if and only if both $X_i<Y_j$ and $X_i<Y_{\\ell}$. Under the null hypothesis, this occurs with probability $1/3$.\n\\it\nIf $k\\neq i$ and $\\ell\\neq j$ then $Z_{ij}$ and $Z_{k\\ell}$ are independent. The summand $Z_{ij}Z_{k\\ell}=1$ if and only if both $X_i<Y_j$ and $X_k<Y_{\\ell}$. Under the null hypothesis, this occurs with probability $1/2\\times 1/2 = 1/4$.\n\\een\nHence, \n\\begin{align*}\n\\expe(U_{m,n}^2)\n\t& = \\left[mn\\times\\frac{1}{2}\\right] + \\left[m(m-1)n\\times\\frac{1}{3}\\right] \n\t\t\t+ \\left[mn(n-1)\\times\\frac{1}{3}\\right] + \\left[m(m-1)n(n-1)\\times\\frac{1}{4}\\right] \\\\\n\t& = \\frac{mn}{12}(1 + n + m + 3mn),\n\\end{align*}\nand\n\\[\n\\var(U_{m,n}) = \\expe(U_{m,n}^2) - \\expe(U_{m,n})^2 = \\frac{mn}{12}(m+n+1).\n\\]\n\\end{proof}\n\n%-----------------------------\n\\subsubsection{Normal approximation}\n\nThe Mann-Whitney statistic $U_{m,n}$ is a sum of random variables (namely the $Z_{ij}$). By the central limit theorem, the distribution of $U_{m,n}$ is approximately normal for $m$ and $n$ sufficiently large. \n\n\\bigskip\nLower-tail test:\n\\[\nZ = \\frac{(U_{m,n}+\\frac{1}{2}) - \\frac{mn}{2}}{\\sqrt{\\frac{mn}{12}(m+n+1)}} \\sim  N(0,1)\\quad\\text{approx. for $m$ and $n$ sufficiently large.}\n\\]\n\nUpper-tail test:\n\\[\nZ = \\frac{(U_{m,n}-\\frac{1}{2}) - \\frac{mn}{2}}{\\sqrt{\\frac{mn}{12}(m+n+1)}} \\sim  N(0,1)\\quad\\text{approx. for $m$ and $n$ sufficiently large.}\n\\]\n\n\n%-----------------------------\n\\subsection{Exact distribution of $U_{m,n}$ under $H_0$}\nThe exact distribution of $U_{m,n}$ under $H_0$ can be obtained for small $m,n$ by a recurrence relation. First we define the base case: if $m = 0$ or $n = 0$, we set $U=0$, so\n\\bit\n\\it $\\prob(U_{m,0}=0) = 1$ and $\\prob(U_{0,n}=0) = 1$; \n\\it $\\prob(U_{m,0}=u) = 0$ and $\\prob(U_{0,n}=u) = 0$ for $u\\neq 0$.\n\\eit\n\n%If $m = n = 1$, there is just one x-value and one y-value, so $U\\in\\{0,1\\}$. There are two possible arrangements ($x<y$ or $y<x$), both equally likely under $H_0$, so\n%\\bit\n%\\it $\\prob(U_{1,1}=0) = \\prob(U_{1,1}=1) = \\frac{1}{2}$.\n%%\\it If $x > y$ then $U=0$; if $x < y$ then $U=1$.\n%\\eit\n%\n%If $m=1$ and $n=2$, there is one x-value and two y-values, so $U\\in\\{0,1,2\\}$. There are six possible arrangements,\n%%($x<y_1<y_2$, $x<y_2<y_1$, $y_1<x<y_2$ and so on)\n%all equally likely under $H_0$, so\n%\\bit\n%\\it $\\prob(U_{1,2}=0) = \\prob(U_{1,2}=1) = \\prob(U_{1,2}=2) = \\frac{1}{3}$, and similarly\n%\\it $\\prob(U_{2,1}=0) = \\prob(U_{2,1}=1) = \\prob(U_{2,1}=2) = \\frac{1}{3}$.\n%\\eit\n%\n\n% theorem\n\\begin{theorem}\nUnder $H_0:\\eta_1=\\eta_2$, the PMF of $U_{m,n}$ satisfies\n\\[\n\\prob(U_{m,n}=u) = \\left(\\frac{m}{m+n}\\right)\\prob(U_{m-1,n}=u) + \\left(\\frac{n}{m+n}\\right)\\prob(U_{m,n-1}=u-m)\n\\]\nfor $u=0,1,\\ldots mn$ (and zero otherwise).\n\\end{theorem}\n\n\\begin{proof}\nLet $m$ and $n$ be fixed and assume that $m>0$ and $n>0$. Under the null hypothesis,\n\\begin{align*}\n\\prob(\\text{The largest observation is one of the $x$-values}) & = \\frac{m}{m+n}, \\\\[1ex]\n\\prob(\\text{The largest observation is one of the $y$-values}) & = \\frac{n}{m+n}.\n\\end{align*}\n\nLet $U=u$ and suppose that one of the $x$-values is the largest observation.\n\\bit\n\\it The remaining $(m - 1)$ $x$-values and $n$ $y$-values constitute a random sample, with one fewer $x$-value, for which $U=u$.\n\\eit\n\nLet $U=u$ and suppose that one of the $y$-values is the largest observation.\n\\bit\n\\it The remaining $m$ $x$-values and $(n - 1)$ $y$-values constitute a random sample, with one fewer $y$-value, for which $U=u-m$. (The largest $y$-value adds $m$ to the value $U$ for the complete set of $m$ $x$-values and $n$ $y$-values.)\n\\eit\n\nThus we have that\n\\[\n\\prob(U_{m,n}=u) = \\left(\\frac{m}{m+n}\\right)\\prob(U_{m-1,n}=u) + \\left(\\frac{n}{m+n}\\right)\\prob(U_{m,n-1}=u-m)\n\\]\n\nThis recurrence relation can be used to find the PMF of $U$ for any $m$ and $n$.\n\\end{proof}\n\n\\begin{example}\nIn an experiment on the effects of exposure to ozone, 10 rats were exposed to the gas for a period. A control group of 10 rats were kept in an ozone-free atmosphere, but otherwise in similar conditions. The lung volumes in millilitres for the two groups of rats after the conclusion of the experiment are tabulated below. Perform a test of size $\\alpha=0.05$ to determine whether there is a statistically significant difference in the average lung volumes of the two groups of rats. \n\\[\\begin{array}{|l|cccccccccc|} \\hline\n\\text{Exposed } (X)\t\t& 9.2    & 8.4    & 8.6    & 9.2    & 9.5    & 9.1    & 9.9    & 9.6    & 9.0    & 9.6 \\\\\n\\text{Not Exposed } (Y)\t& 8.8    & 8.6    & 8.7    & 8.4    & 9.1    & 9.2    & 8.3    & 8.5    & 8.8    & 8.2 \\\\ \\hline\n\\end{array}\\]\n\\end{example}\n\n\\begin{solution}\nWe test the null hypothesis $H_0:\\eta_1=\\eta_2$ against the alternative $H_1:\\eta_1\\neq\\eta_2$.\n\n\\begin{align*}\nu  & = 2 + 1.5 + 2 + 0.5 + 3.5 + 5 + 0 + 1 + 2 + 0 = 17.5. \\\\\nu' & = 100-17.5 = 82.5.\n\\end{align*}\n\nFrom tables, the critical value for a two-tailed test is $81$ at $\\alpha=0.02$, and $84$ at $\\alpha=0.01$. Thus $H_0$ is rejected at $\\alpha=0.02$ but retained at $\\alpha=0.01$.\n\\end{solution}\n\n\\begin{exercise}\n\\begin{questions}\n\n\\question\nWe wish to determine whether the distribution of population $B$ is located to the right of population $A$.\n\\[\\begin{array}{|l|ccccccccc|}\\hline\n\\text{Sample $A$} & 37 & 40 & 33 & 29 & 42 & 33 & 35 & 28 & 34 \\\\\n\\text{Sample $B$} & 65 & 35 & 47 & 52 & & & & & \\\\ \\hline\n\\end{array}\\]\n\\ben\n\\it State the null and alternative hypotheses for the test.\n\\it Perform the hypothesis test using the Mann-Whitney test at $\\alpha=0.05$.\n\\een\n\\begin{answer}\n\\ben\n\\it % << (i)\n$H_0:\\eta_A=\\eta_B$, $H_1:\\eta_A<\\eta_B$.\n\\it % << (i)\n$U = 3 + 3 + 4 + 4 + 3 + 4 + 3.5 + 4 + 4 = 32.5$. \n\\par\nFrom tables, with $m=9$ and $n=4$, a one-tailed test at $\\alpha=0.05$ has critical value $U_c = 29$. \n\\par\nSince $U>U_c$, we reject $H_0$.\n\\een\n\\end{answer}\n\n\\question\nIndependent random samples are selected from two populations. The data is shown in the following table.\n\\[\\begin{array}{|l|cccccccc|}\\hline\n\\text{Sample $1$} & 15 & 10 & 12 & 16 & 13 &  8 &    & \t\t\\\\\n\\text{Sample $2$} &  5 & 12 &  9 &  9 &  8 &  4 &  5 & 10 \t\\\\ \\hline\n\\end{array}\\]\n\\ben\n\\it Use the Mann-Whitney to determine whether the data provide sufficient evidence to indicate a shift in the locations of the probability distributions of the sampled populations. Test using $\\alpha=0.05$.\n\\it Do the data provide sufficient evidence to indicate that the probability distribution of the first propulation is shifted to the right of the second population? Use the Mann-Whitney test with $\\alpha=0.05$\n\\een\n\n\\begin{answer}\nRecall that \n\\[\nU = \\sum_{i=1}^m \\sum_{j=1}^n Z_{ij} \n\\quad\\text{and}\\quad \nU' = \\sum_{i=1}^m \\sum_{j=1}^n (1-Z_{ij}) \n\\quad\\text{where}\\quad \nZ_{ij} = \\begin{cases} \n\t1 \t& X_i < Y_j, \\\\\n\t0.5\t& X_i = Y_j, \\\\\n\t0\t& X_i > Y_j.\n\\end{cases}\n\\]\nFrom the table,\n\\begin{align*}\nU \t& = 0 + 1.5 + 0.5 + 0 + 0 + 4.5 = 6.5, \\\\\nU'\t& = 6 + 3.5 + 5 + 5 + 5.5 + 6 + 6 + 4.5 = 41.5.\n\\end{align*}\n\\ben\n\\it $H_0:\\eta_1=\\eta_2$ and $H_1:\\eta_1\\neq\\eta_2$. \n\\par \nFrom tables, for a two-tailed test at $\\alpha=0.05$ with $m=6$ and $n=8$, the upper-tail critical value is $U_c=40$ and the lower-tail critical value is $mn-U_c = 48-40=8$. The rejection region is therefore $\\{U:U\\leq 8\\text{ or }U\\geq 40\\}$. Since the observed value of $U$ lies in the critical region, we reject $H_0$, and conclude that the medians of the two populations are different.\n\n\\it $H_0:\\eta_1=\\eta_2$ and $H_1:\\eta_1>\\eta_2$. \n\\par \nOnly small values of $U$ support the alternative hypothesis $H_1:\\eta_1>\\eta_2$. \n\\par\nFrom tables, for a one-tailed test at $\\alpha=0.05$ with $m=6$ and $n=8$, the upper-tail critical value is $U_c=37$, so the lower-tail critical value is $mn-U_c = 48-37=11$. The rejection region is therefore $\\{U:U\\leq 11\\}$. Since the observed value of $U$ lies in the critical region, we reject $H_0$, and conclude that population $1$ lies to the right of population $2$.\n\\een\n\\end{answer}\n\n\\question\nThe percentage of carbon in iron samples taken from two different furnaces was measured. The results obtained are as follows\n\\[\\begin{array}{|c|cccccc|} \\hline\n\\text{Furnace $1$} \t& 2.28    & 2.34    & 2.37    & 2.39    & 2.40    & 2.41 \\\\\n\\text{Furnace $2$}\t& 2.36    & 2.40    & 2.42    & 2.44    & 2.44    & 2.48 \\\\ \\hline\n\\end{array}\\]\nPerform a suitable non parametric test to determine if there is a significant difference between the median percentage carbon in the two furnaces. Discuss how you have dealt with ties and the effect that these might have had on your conclusions.          \n\n\\begin{answer}\nWe assume that the furnaces are independent of each other, and use the Mann-Whintey test. \n\\bit\n\\it Using the counting method: $U = 6 + 6 + 5 + 5 + 4.5 + 4 = 30.5$\n\\it Alternatively, using rank sums:\n\\[\\begin{array}{|c|cccccc|l|}\\hline\n\\text{Furnace $1$}\t& 2.28\t& 2.34\t& 2.37\t& 2.39\t& 2.40\t& 2.41\t&  \t\t\t\t\\\\ \\hline\n\\text{Rank}\t\t\t& 1    \t& 2    \t& 4    \t& 5  \t& 6.5\t& 8  \t& R_X = 26.5\t\t\\\\ \\hline\\hline\n\\text{Furnace $2$}\t& 2.36\t& 2.40\t& 2.42\t& 2.44\t& 2.44\t& 2.48\t& \t\t\t\t\\\\ \\hline\n\\text{Rank}\t\t\t& 3  \t& 6.5\t& 9\t\t& 10.5\t& 10.5 \t& 12\t\t& R_Y = 51.5\t\t\\\\ \\hline\n\\end{array}\\]\nHence $U = R_Y - \\frac{1}{2} n(n+1) = 51.5 - 21 = 30.5$.\n\\eit\nFrom tables, the critical value for a 2-tailed test at significance level $\\alpha=0.05$ is $U_c=31$, and at $\\alpha=0.1$ is $U_c=29$. Thus the test statistic is outside the critical region $\\{U:U\\geq 31\\}$ at $\\alpha=0.05$, but inside the critical region $\\{U:U\\geq 29\\}$ at the $\\alpha=0.1$ significance level. Thus we would retain the null hypothesis at $\\alpha=0.05$, but it is a close decision. \n\nWhen computing the test statistic, ties were handled by assigning the average of the ranks that would have been assigned had there not been any ties. If the two observations recorded as $2.40$ had been recorded more accurately, and the value for Furnace~2 had turned out to be bigger than the value for Furnace~1, the Mann-Whitney statistic would be $U=31$. This would have led us to reject the null hypothesis at $\\alpha=0.05$, which illustrates that the decision is indeed a close call.\n\\end{answer}\n\n\\end{questions}\n\\end{exercise}\n", "meta": {"hexsha": "82a5ebd8f98a6feb1fa992a1b92afc53bf610c24", "size": 21311, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/11A_two_sample_tests.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/11A_two_sample_tests.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/11A_two_sample_tests.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 48.878440367, "max_line_length": 488, "alphanum_fraction": 0.6441274459, "num_tokens": 8396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.8705972583359805, "lm_q1q2_score": 0.7137968980370133}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PROBLEM 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section*{Problem 3}\n\n\\begin{enumerate}[a)]\n\\item Solve the first order differential equation\n$$ \\frac{dy}{dx} + 3y = 0 $$\n\\item Solve the second order differential equation ($A$ and $B$ are constants)\n$$ \\frac{d^2 y}{dx^2} - A^2y = B $$\nThe boundary condition is $y(\\pm\\frac{1}{A}) = 0$.\n\\end{enumerate}\n\n", "meta": {"hexsha": "a6f24ff7a10f6d0a56aeb760a6221ba96a63cbb9", "size": 386, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc01/disc01_exercise03.tex", "max_stars_repo_name": "mitchnegus/NE150-discussion", "max_stars_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/drafts/disc01/disc01_exercise03.tex", "max_issues_repo_name": "mitchnegus/NE150-discussion", "max_issues_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/drafts/disc01/disc01_exercise03.tex", "max_forks_repo_name": "mitchnegus/NE150-discussion", "max_forks_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.1666666667, "max_line_length": 79, "alphanum_fraction": 0.5414507772, "num_tokens": 115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566341999997378, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.713782067886135}}
{"text": "\\chapter{Smart computation of \\texorpdfstring{$x^n$}{Powers}}\n\\label{chapter-powers}\n\\section{Introduction}\n\nNothing looks simpler than writing a function for computing $x^n$.\nBut on the contrary, this simple programming exercise allows us to address\nadvanced programming techniques such as:\n\\begin{itemize}\n\\item monadic programming, and continuation passing style\n\\item type classes, and generalized rewriting\n\\item proof engineering, in particular proof reuse\n\\item proof by reflection\n\\item polymorphism and parametricity\n\\item composition of correct programs, etc.\n\\end{itemize}\n\n\n\n\\section{Some basic implementations}\n\\label{sect:linear-naive}\nLet us start with a very naive way of computing the $n$-th power of $x$, where\n$n$ is a natural number and $x$ belongs to some type for which a multiplication and an identity element are defined.\n\n\n\\emph{From Module \n\\href{../theories/html/additions.FirstSteps.html}{\\texttt{additions.FirstSteps}}}\n\\label{sect: power-definitions}\n\n\\inputsnippets{FirstSteps/Defs}\n\nAn application of this function for  computing $x^n$ needs $n$ multiplications.\n Despite this lack of efficiency, and thanks to its simplicity, we keep it as a specification for more efficient and complex exponentiation algorithms.\nA function will be considered a \\emph{correct} exponentiation function if we can prove it is extensionally equivalent to \\texttt{power}.\n\n% \\subsection{A semi-naive algorithm}\n\n% In versions up to \\texttt{V8.9.1}, the exponentiation function on type \\texttt{Z} was defined as follows,\n% (in modules \\texttt{Coq.PArith.BinPosDef.Pos} and \\texttt{Coq.ZArith.BinIntDef.Z}.\n\n% \\begin{Coqsrc}\n% (** ** Iteration of a function over a positive number *)\n\n% Definition iter {A} (f:A -> A) : A -> positive -> A :=\n%   fix iter_fix x n := match n with\n%     | xH => f x\n%     | xO n' => iter_fix (iter_fix x n') n'\n%     | xI n' => f (iter_fix (iter_fix x n') n')\n%   end.\n\n% Definition pow (x:positive) := iter (mul x) 1.\n% \\end{Coqsrc}\n\n\n% \\begin{Coqsrc}\n% Definition pow_pos (z:Z) := Pos.iter (mul z) 1.\n\n% Definition pow x y :=\n%   match y with\n%     | pos p => pow_pos x p\n%     | 0 => 1\n%     | neg _ => 0\n%   end.\n\n% Infix \"^\" := pow : Z_scope.\n% \\end{Coqsrc}\n\n% At first sight, the function \\texttt{Pos.pow} seems to be logarithmic because of the recursive structure of the help function \\texttt{iter\\_fix}. Unfortunately, it is obvious that a call to \n% \\texttt{iter f x n} will apply $n$ times the function $f$. Thus, these exponentiation functions with binary exponents are in fact linear!\n\n% \\label{sect:slow-computation}\n\n% \\begin{Coqsrc}\n% Time Compute (1 ^ 56666667)%N.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n% Finished transaction in 3.604 secs (3.587u,0.007s)   \n% \\end{Coqanswer}\n\n\n\\subsection{A logarithmic exponentiation  function}\n\nUsing the following equations, we can easily define a polymorphic exponentiation whose application requires only a logarithmic number of multiplications. \n\n\\begin{align}\nx^1 &= x \\label{binary-eq1}\\\\\nx^{2p} &= (x^2)^p \\label{binary-eq2}\\\\\nx^{2p+1} &= (x^2)^p \\times x \\label{binary-eq3}\\\\\nx^1 \\times a &= x \\times a \\label{binary-eq4}\\\\\nx^{2p} \\times a  &= (x^2)^p \\times a\\label{binary-eq5}\\\\\nx^{2p+1} \\times a  &= (x^2)^p \\times (a\\times x)\\label{binary-eq6}\n\\end{align}\n\n\nIn equalities \\ref{binary-eq4} to \\ref{binary-eq6}, the variable $a$ plays the role\nof an \\emph{accumulator} whose initial value (set by \\ref{binary-eq3}) is $x$.\nThis accumulator helps us to get a tail-recursive implementation.\n\nFor instance, the computation of $2^{14}$ can be decomposed as follows:\n\\begin{align*}\n2^{14} &= 4^{7} \\\\\n      &= 16^3 \\times 4 \\\\\n      &= 256^1 \\times (4 \\times 16) \\\\\n      &= 16384  \n\\end{align*}\n\nWith the same notations as in Sect~\\vref{sect:linear-naive}, we can implement this algorithm in \\gallina. The following definitions are still within the scope of the \nsection open in~\\vref{sect: power-definitions}.\n\n\n\n\\label{polymorhic-binary_exp}\n\n%%% ICI (presenter la fonction binaire de First_Steps )\n%%%  Reprendre des explications placees ci-dessous\n\n\\vspace{4pt}\n\n\\emph{From Module\n\\href{../theories/html/additions.FirstSteps.html}{additions.FirstSteps}}\n\n\\inputsnippets{FirstSteps/bpowDef}\nLet us  close the section \\texttt{Definitions} and mark the argument \\texttt{A} as implicit.\n\\inputsnippets{FirstSteps/EndDefs}\n\n\\begin{remark}\nOur function \\texttt{Pos\\_bpow} can be considered as a tail recursive variant\nof the following function defined in \\texttt{Coq.PArith.BinPosDef}.\n\n\n\n\\begin{Coqsrc}\nDefinition iter_op {A}(op:A->A->A) :=\n  fix iter (p:positive)(a:A) : A :=\n  match p with\n    | 1 => a\n    | p~0 => iter p (op a a)\n    | p~1 => op a (iter p (op a a))\n  end.\n\\end{Coqsrc}\n\nThis scheme is used in \\texttt{Coq.ZArith.Zpow\\_alt} in order to define a logarithmic exponentiation \\texttt{Zpower\\_alt} on \\texttt{Z} (notation : $x\\,\\texttt{\\^{}\\^{}}\\,p$).\n\n\\end{remark}\n\n\\paragraph*{Remark}\nNote that closing the section \\texttt{Definitions} makes us lose the\nhandy notations \\texttt{\\_ * \\_} and \\texttt{one}. Fortunately, \\emph{operational type classes} will help us to define nice infix notations for polymorphic functions (Sect.~\\vref{op-classes}).\n\n\\subsection{Examples of computation}\nIt is now possible to test our functions with various interpretations of\n$\\times$ and $1$:\n\n\\inputsnippets{FirstSteps/PowerCompute}\n\n% \\subsubsection{Exponentiation on $2\\times 2$ matrices}\n% \\label{naive-matrix}\n% Our second example is a definition of $M^n$ where $M$ is a $2\\times 2$ matrix\n% over any ``scalar''  type $A$, assuming one can provide $A$ with a semi-ring structure~\\cite{Coq}.\n\n\n% %\\subsubsection{Representation of $2\\times 2$ matrices}\n\n% A $2\\times 2$ matrix will be simply represented by a structure with four fields;\n% each field \\texttt{c$ij$} is associated with the $i$-th line and $j$-th column of the considered matrix.\n\n\n\n%\\subsubsection{Matrix Multiplication}\n\n\n\n\\subsection{Computing Fibonacci numbers}\n\nThe sequence of Fibonacci numbers is defined by the following equations:\n\n\\begin{align}\nF_0 & = 1 \\\\\nF_1 & = 1 \\\\\nF_n & = F_{n-1} + F_{n-2} \\quad (n \\geq 2)\n\\end{align}\n\n\nIn \\coq{}, one can define this function by simple recursion.\n\n\\emph{From Library\n\\href{../theories/html/additions.Fib2.html}{additions.Fib2}}\n\n\\inputsnippets{Fib2/FibDef}\n\nIn~\\cite{BC04}, several exercises~\\footnote{Exercises 9.8 (page 270), 9.10 (page 271), 9.15 (page 276), 9.17 (page 284), and 15.8 (page 418).}\npresent ways to compute Fibonacci numbers, with the less number of recursive calls  as possible. Please note that these optimizations and the formal proof of their correctness are \\emph{ad-hoc}, \\emph{i.e.}, exclusively written for the\nFibonacci numbers.\nIn contrast, the optimizations we present in this document apply, in their vast majority, \\emph{generic} techniques of efficient computation of powers in a monoid. \nThis example of Fibonacci numbers has been developed with Yves Bertot, who wrote a first version with \\texttt{SSreflect/Mathcomp}~\\cite{MCB}.\n\n\n\\subsubsection{Using 2x2 integer matrices}\n\\index{maths}{Fibonacci numbers!Matrix exponentiation} \n\nThe following properties are well known. They are left as an exercise, since they are not part of our development. \n\n\\index{additions}{Exercises}\n\n\\begin{exercise}\n  \\label{exercise:fibmat}\n  \\begin{enumerate}\n  \\item \n\nProve in \\coq{} the following equality (for any $n\\geq 2$). \\label{fibmat-eq1}\n\n\\[\n\\left(\n  \\begin{array}{cc}\n    1 & 1 \\\\\n    1 & 0 \n  \\end{array}\n\\right)\n\\left(\n  \\begin{array}{cc}\n    F_{n}& F_{n-1} \\\\\n    F_{n-1} & F_{n-2}\n  \\end{array}\n\\right)\n=\n\\left(\n  \\begin{array}{cc}\n    F_{n+1}& F_{n} \\\\\n    F_{n} & F_{n-1} \n  \\end{array}\n\\right)\n\\]\n  \n\\item Infer (still in \\coq{}) the following equality (still for $n\\geq 2$).\n\n\n\n\\[\n\\left(\n  \\begin{array}{cc}\n    F_{n}& F_{n-1} \\\\\n    F_{n-1} & F_{n-2} \n  \\end{array}\n\\right)\n= \n\\left(\n  \\begin{array}{cc}\n    1 & 1 \\\\\n    1 & 0 \n  \\end{array}\n\\right)^n\n\\]\n\n\\item Write a function using the previous equality for computing the $n$-th Fibonacci number, and prove its equivalence with \\texttt{fib}.\n\n\\end{enumerate}\n\\end{exercise}\n\n\\subsubsection{Removing duplicate computations}\n\\label{sect:fibonacci-mul2}\n\n\nYves Bertot's optimization relies on the observation that all the powers of\n\\(  \\left(\n  \\begin{array}{cc}\n    1 & 1 \\\\\n    1 & 0 \n  \\end{array}\n\\right) \\) have the form \n\\(  \\left(\n  \\begin{array}{cc}\n    a+b  & a \\\\\n    a & b\n  \\end{array}\n\\right) \\) where $a$ and $b$ are natural numbers.\n\nThus, it is possible to remove duplicate data and computations by reflecting matrix multiplication and identity into $\\mathbb{N}\\times\\mathbb{N}$.\n\nIf we pose $\\varphi(a,b) =\\left(\n  \\begin{array}{cc}\n    a+b  & a \\\\\n    a & b\n  \\end{array}\n\\right)$, then $\\varphi(a,b)\\times \\varphi(c,d)=\\varphi(ac + ad + bc, ac + bd)$, and\n$\\varphi(0,1)=  \\left(\n  \\begin{array}{cc}\n    1 & 0 \\\\\n    0 & 1 \n  \\end{array}\n\\right) $.\n\n\\index{additions}{Exercises}\n\\begin{exercise}\n  Prove formally these properties. \\emph{Please note that their proof is not needed in our development, they just help to understand the following optimization.}\n\\end{exercise}\n\n\nSo, let us define a binary operation, which makes $\\mathbb{N}\\times\\mathbb{N}$ a monoid (with $(0,1)$ as neutral element).\n\n\n\\emph{From Library\n\\href{../theories/html/additions.Fib2.html}{additions.Fib2}} \n\n\\emph{The \\texttt{Monoid} type class is defined \npage~\\pageref{sect:monoid-def}.}\n\n\\inputsnippets{Fib2/mul2Def}\n\\inputsnippets{Fib2/mul2Monoid}\n\n\nThe following lemma is a simplification of the equality of Exercise~\\ref{exercise:fibmat}.\n\n\\inputsnippets{Fib2/nextFib}\n\nLet us consider a new definition of the Fibonacci function.\n\n\\inputsnippets{Fib2/fibMul2Def}\n\\inputsnippets{Fib2/fibMul2OK0}\n\\inputsnippets{Fib2/fibMul2OK}\n\\inputsnippets{Fib2/TimeFibMul2}\n\n\nThus, any function able to compute more or less efficiently powers in a monoid will\ngive an algorithm for computing Fibonacci numbers. Unlike the \\emph{ad-hoc} aforementioned proofs of~\\cite{BC04}, the correctness of such an algorithm is a direct consequence\nof the correctness of the used powering function.\nSeveral examples will be presented in the rest of this document\n(in Section~\\vref{sect:fibonacci-pos-bpow}).\n\n\n\n\n% \\begin{Coqsrc}\n\n% Import M2.\n\n% Arguments M2_mult {A} plus mult  _  _.\n% Arguments mat {A} _ _ _ _.\n% Arguments Id2 {A}  _ _.\n\n% Definition fibonacci (n:N) :=\n%  c00 N  (N_bpow  (M2_mult Nplus Nmult) \n%                  (Id2  0%N 1%N)\n%                  (mat  1 1 1 0)%N \n%                  n).\n\n% Compute fibonacci 20.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n% = 10946%N\n%      : N  \n% \\end{Coqanswer}\n\n\\begin{todo}\nDocument the files contributed by Yves\n\\begin{itemize}\n\\item additions/fib.v (to rename ?)\n\\item additions/stub.ml (to keep inside theories/ or move to src/ ?)\n\\item theories/additions/make\\_fib\\_tests.txt (to put in a Makefile?)\n\\end{itemize}\n\\end{todo}\n\n\n\n\n% \\subsubsection{Remark}\n% \\label{sect:faster}\n\n% Our function \\texttt{N\\_bpow} is really logarithmic. Let us make a comparative \n% test with Standard Library's exponentiation function on type \\texttt{N} (see section~\\vref{sect:slow-computation}).\n\n% \\begin{Coqsrc}\n% Time Compute (N_bpow N.mul 1 1 56666667)%N.  \n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n% Finished transaction in 0. secs (0.u,0.s) (successful)  \n% \\end{Coqanswer}\n\n\n\n\n\\subsection{Formal specification of an exponentiation function: a first attempt}\n\nLet us compare the functions \\texttt{power} and \\texttt{N\\_bpow}.\nThe first one is obviously correct, since it is a straightforward translation of the mathematical definition.\nThe second one is much more efficient, but it is not obvious  that its 18-line long definition is bug-free.\nThus, we must prove that the two functions are extensionally equal (taking into account conversions\nbetween \\texttt{N} and \\texttt{nat}).\n\nMore abstractly, we can define a predicate that characterizes any correct implementation \nof \\texttt{power}, this ``naive''  function being a \\emph{specification} of any polymorphic\nexponentiation function.\n\nFirst, we define a type for any such function.\n\n\\inputsnippets{FirstSteps/powerTDef}\n\nThen, we would say that a function \\texttt{f:power\\_t} is a correct exponentiation function if it\nis extensionally equal to \\texttt{power}.\n\n\\inputsnippets{FirstSteps/Bada}\n\nUnfortunately, our definition of \\texttt{correct\\_expt} is too general. It suffices to build \nan interpretation where the multiplication is not associative or \\texttt{one} is not a neutral\nelement to obtain different results through the two functions.\n\n\n\\inputsnippets{FirstSteps/Badb}\n\n\nSo, we will have to improve our definition of correctness, by restricting  the universal quantification to associative operations and neutral elements, \\emph{i.e.}, by considering \\emph{monoids}.\nAn exponentiation  function will be considered as correct if it returns always the same result as \\texttt{power} \\emph{in any monoid}.\n\n\n\n\\section{Representing monoids in \\coq \\label{monoid-class-def}}\n\nIn this section, we present a ``minimal'' algebraic framework in which  exponentiation can be defined and efficiently implemented.\n\nExponentiation is built on multiplication, and many properties of \nthis operation are derived from the associativity of multiplication. \nFurthermore, if we allow the exponent to be any natural number, including $0$, \nthen we need to consider a neutral element for multiplication.\n\nThe structure on which we define exponentiation is called a \\emph{monoid}.\nIt is composed of a \\emph{carrier} $A$, an associative binary operation $\\times$ on $A$, and a neutral element $\\mathds{1}$ for $\\times$ . The required properties of $\\times$ and\n$\\mathds{1}$ are expressed by the following equations:\n\n\n\\begin{align}\n  \\label{eq}\n  \\forall x\\,y\\,z\\,:A,\\, x\\times (y \\times z) &= (x\\times y) \\times z\n  \\\\\n\\forall x:A,\\, x \\times \\mathds{1}  &= \\mathds{1}  \\times x = x\n\\end{align}\n\n\nIn \\coq{}, we define the monoid structure in terms of \n\\emph{type classes}\\cite{MS08,BS2011}. The tutorial on type classes \\cite{PCMS} gives more details on type classes and\noperational type classes, also illustrated with the monoid structure.\n\n\nFirst, we define a class and a notation for representing multiplication operators, then we use\nthese definitions for defining the \\texttt{Monoid} type class.\n\n\\subsection{A common notation for multiplication}\n\\label{op-classes}\n\\index{coq}{Type classes!Operational type classes}\n\n\\emph{Operational type classes}~\\cite{BS2011}\nallow us to define a common notation \nfor multiplication in any algebraic structure. \nFirst, we associate a class to the notion of \\emph{multiplication} \non any type $A$.\n\n\\emph{From Module \\href{../theories/html/additions.Monoid_def.html}{additions/Monoid\\_def.v}.}\n\n\\inputsnippets{Monoid_def/MultOpClass}\n\nFrom the type theoretic point of view, the term (\\texttt{Mult\\_op $A$}) is \n$\\beta\\delta$-reducible to \\texttt{$A\\arrow A \\arrow A$}, and\nif \\texttt{\\it op} has type (\\texttt{Mult\\_op $A$}), then \n(\\texttt{@mult\\_op A {\\it op}}) is convertible with \\texttt{\\it op}.\n\n\\inputsnippets{Monoid_def/MultOpEq}\n\nWe are now ready to define a new notation scope, in which the notation \\linebreak \n\\texttt{x * y} will be interpreted as an application of the function\n\\texttt{mult\\_op}.\n\n\\inputsnippets{Monoid_def/MultOpInfix}\n\n Let us show two examples of use of the\nnotation scope \\texttt{M\\_scope}. Each example consists in declaring an \ninstance of \\texttt{Mult\\_op}, then type checking or evaluating\na term of the form \\texttt{x * y} in \\texttt{M\\_scope}.\n\nNote that, since the reserved notation \\texttt{\"\\_ * \\_ \"} is \npresent in several scopes such as  \\texttt{nat\\_scope}, \\texttt{Z\\_scope},\n\\texttt{N\\_scope}, etc., in addition to  \\texttt{M\\_scope},  the user should\ntake care of which scopes are active --- and with  which precedence --- in a \\gallina{} term.\nIn case of doubt, explicit scope delimiters should be used.\n  \n\n\n\n\n\\subsubsection{Multiplication on Peano numbers}\n\nMultiplication  on type \\texttt{nat}, called \\texttt{Nat.mul} in\nStandard Library, has  type \\linebreak \\texttt{nat -> nat -> nat}, which is\nconvertible  with \\texttt{Mult\\_op nat}. Thus the following definition is\naccepted:\n\n\\inputsnippets{Monoid_def/DemoNatMulta}\n\nInside \\texttt{M\\_scope}, the expression \\texttt{3 * 4} is \ncorrectly read as an application of \\texttt{mult\\_op}. Nevertheless \nthis term is convertible with \\texttt{Nat.mul 3 4}, as shown by the \ninteraction below.\n\n\\emph{From Module \\href{../theories/html/additions.Monoid_def.html}{additions.Monoid\\_def}}\n\n\\inputsnippets{Monoid_def/DemoNatMultb}\n\n\n\\subsubsection{String concatenation}\nWe can use the notation \\texttt{\"\\_ * \\_ \"} for other types than numbers.\nIn the following example,  the expression \\texttt{\"abc\" * \"def\"} is interpreted\nas \\linebreak \\texttt{@mult\\_op string  {\\color{darkred}?X} \"abc\"  \"def\"}, then the type  class mechanism replaces the unknown  {\\color{darkred}?X} with \n\\texttt{string\\_op}.\n\n\n\\emph{From Module \\href{../theories/html/additions.Monoid_def.html}{additions.Monoid\\_def}}\n\n\\inputsnippets{Monoid_def/DemoStringMult}\n\n\n\\subsubsection{Solving ambiguities}\nLet $A$ be some type, and let us assume there are several instances of\n\\texttt{Mult\\_op $A$}. For solving ambiguity issues, one can\nadd a \\emph{precedence} to each instance declaration of  \n\\texttt{Mult\\_op $A$}. In any case, such ambiguity  can be addressed\nby explicitly providing  some arguments of \\texttt{mult\\_op}.\nFor instance, in Sect.~\\vref{nat-monoids}, we consider various monoids on types\n\\texttt{nat} and \\texttt{N}. \n\n\n\\subsection{The Monoid type class}\n\\index{coq}{Type classes}\nWe are now ready to  give a definition of the \\texttt{Monoid} class, using\n\\texttt{*} as an infix operator in scope \\coqscope{M} for the monoid  multiplication.\n\nThe following class definition, from Module \\href{../theories/html/additions.Monoid_def.html}{additions.Monoid\\_def},\nis parameterized with some type $A$,\na multiplication (called \\texttt{op} in the definition), and a neutral element\n$\\mathds{1}$ (called \\texttt{one} in the definition).\n\n\\label{sect:monoid-def}\n\n\\index{additions}{Type classes!Monoid}\n\n\\inputsnippets{Monoid_def/MonoidClass}\n\n\n\\subsection{Building instances of \\texttt{Monoid}}\nLet \\texttt{$A$} be some type, \\texttt{{\\it op}} an instance of \n\\texttt{Mult\\_op $A$} and \\texttt{\\it one: $A$}.\nIn order to build an instance of (\\texttt{Monoid $A$ {\\it op} {\\it one}}),\none has to provide proofs of ``monoid axioms'' \\texttt{ op\\_assoc},\n\\texttt{one\\_left} and \\texttt{one\\_right}.\n\nLet us show various instances, which will be used in further proofs and examples.\nComplete definitions and proofs are given in \nFile~\\href{../theories/html/additions.Monoid_instances.html}{additions/Monoid\\_instances.v}.\n\n\n\\subsubsection{Monoid on \\texttt{Z}}\nThe following monoid allows us to compute powers of integers of arbitrary size, \nusing type \\texttt{Z} from standard library:\n\n\n\\inputsnippets{Monoid_instances/ZMultDef}\n\n\n\\subsubsection{Monoids on type \\texttt{nat} and \\texttt{N}}\n\\label{nat-monoids}\n% ~~\\\\\n% \\noindent \n\nWe define two monoids on type \\texttt{nat}:\n\\begin{itemize}\n\\item The ``natural'' monoid $(\\mathbb{N},\\times, 1)$ :\n\\inputsnippets{Monoid_instances/natMult}\n\n\n\n\\item The ``additive''  monoid $(\\mathbb{N},+, 0)$.\nThis monoid will play an important role in correctness proofs of complex\nexponentiation algorithms. Its most important property is that the $n$-th \npower of $1$ is equal to $n$. See Sect.~\\vref{correctness-for-free} for more details.\n\n\\inputsnippets{Monoid_instances/natPlus}\n\\end{itemize}\n\nSimilarly, instances \\texttt{NMult} and  \\texttt{NPlus}  are built for type \\texttt{N}, and\n\\texttt{PMult} for type \\texttt{positive}.\n\n\\subsubsection{Machine integers}\n\nCyclic numeric types are  good candidates for testing exponentiations\nwith big exponents, since the size of data is bounded.\n\nThe type \\texttt{int31} is defined  in Module\n\\textbf{Coq.Numbers.Cyclic.Int31.Int31} of \\coq's standard library. The tactic \\texttt{ring} works \nwith this type, and helps us to register an instance \\texttt{Int31Mult} of class  \\texttt{Monoid int31\\_mult\\_op 1}.\n\n\\inputsnippets{Monoid_instances/int31}\n\nBeware that machine integers are not natural numbers! \n\n\\inputsnippets{Monoid_instances/BadFact}\n\n\\subsection{Matrices on a semi-ring}\n\nLet $(A,+,\\times)$ be a semi-ring. We define a multiplicative monoid on the set of \\emph{e.g.} $2\\times 2$-) square matrices over $A$.\nIt suffices to define an instance of \\texttt{Monoid} within the scope of a hypothesis\nof type \\texttt{semi\\_ring\\_theory}.\n\n\\inputsnippets{Monoid_instances/M2Defsa, Monoid_instances/M2Defsb}\n\n\n\n\\subsection{Monoids and equivalence relations}\n\\index{coq}{Generalized rewriting}\n\\index{coq}{Type classes!Equivalence relations}\n\nIn some contexts, the ``axioms'' of the \\texttt{Monoid} class  may be too restrictive.\nFor instance, consider multiplication in $\\mathds{Z}/m\\mathds{Z}$ where\n $1<m$.\nAlthough it could be possible to compute with values of the dependent \ntype \\texttt{\\{n:N | n < m\\}}, \nit looks simpler to compute with numbers of type\n\\texttt{N} and consider the multiplication $x \\times y \\mod{m}$.\n\n\n\nIt is easy to prove that this operation is associative, using library \\texttt{NArith}. Unfortunately, the following proposition is false in general (left as an exercise).\n\n$$\\forall x:N, (1 * x) \\mod{m} = x$$\n\n\nThus, we define a more general class, parameterized by an equivalence\nrelation \\texttt{Aeq}  on a type \\texttt{A}, compatible with the multiplication \\texttt{*}. The laws of associativity and neutral element\nare not expressed as Leibniz equalities but as equivalence statements:\n\nFirst, let us define an operational type class for equivalence relations:\n\n\\vspace{4pt}\n\n\\noindent\n\\emph{From Module \\href{../theories/html/additions.Monoid_def.html}{additions.Monoid\\_def}}\n\n\\inputsnippets{Monoid_def/EquivDef}\n\nThe definition of class \\texttt{EMonoid} looks like \\texttt{Monoid}'s definition, \nplus some constraints on \\texttt{E\\_eq}.\n\nPlease look for instance at our tutorial on type classes and relations~\\cite{PCMS} \nfor understanding the use of  type classes \\texttt{Equivalence}, \\texttt{Reflexive}, \\texttt{Proper}, etc, in relation with tactics like \\texttt{rewrite}, \\texttt{reflexivity}, etc., in proofs which involve  equivalence relations instead of equality.\n\n\\index{coq}{Type classes}\n\\index{Coq}{Type classes!Proper class}\n\\label{EMonoid-def}\n\n%\\todo{link to Proper in stdlib : Coq.Classes.Morphisms and Coq.Classes.CMorphisms}\n \n\n\\index{additions}{Type classes!EMonoid}\n\n\\inputsnippets{Monoid_def/EMonoidDef}\n\n\\subsubsection{Coercion from Monoid to EMonoid} \nEvery instance of class  \\texttt{Monoid} can be transformed into an instance of\n\\texttt{EMonoid}, considering Leibniz' equality \\texttt{eq}.\nThus, our  definitions and theorems about exponentiation will take place as \nmuch as possible within the more generic framework of \\texttt{EMonoid}s.\n\n\n\\index{coq}{Coercions}\n\n\\inputsnippets{Monoid_def/Coerciona}\n\n\n\\begin{remark}\nIn the definition of \\texttt{Monoid\\_EMonoid}, the free variables  \\texttt{A}, \n\\texttt{op} and \\texttt{one} are automatically generalized thanks to the \\emph{backquote} syntax (see the section about implicit generalization in the reference manual~\\cite{Coq}).\n\\end{remark}\n\nThanks to the following \\emph{coercion}, every instance of \\texttt{Monoid} can \nnow be considered as an instance of \\texttt{EMonoid}. For more details, please look at the section \\emph{Implicit Coercions} of \\coq's reference manual~\\cite{Coq}.\n\n\\inputsnippets{Monoid_def/Coercionb}\n\n\\emph{From Module \\href{../theories/html/additions.Monoid_instances.html}{additions.Monoid\\_instances}}\n\n\\inputsnippets{Monoid_instances/CheckCoercion}\n\n\n\\subsubsection{Example : Arithmetic  modulo $m$}\n\n \nThe following instance of \\texttt{EMonoid} describes the set of integers modulo\n$m$, where $m$ is any integer greater than or equal to $2$.\nFor simplicity's sake, we represent such values using the \\texttt{N} type,\nand consider ``equivalence modulo \\texttt{$m$}'' instead of equality.\n\n\\inputsnippets{Monoid_instances/Nmoduloa,\n  Monoid_instances/Nmodulob, Monoid_instances/Nmoduloc,\n  Monoid_instances/Nmodulod,\n  Monoid_instances/Nmoduloe,\n  Monoid_instances/Nmodulof,\n  Monoid_instances/Nmodulog}\n \n\nOutside the section \\texttt{S256}, the term \\texttt{(211 * 67)\\%M} is interpreted as a plain multiplication in type \\texttt{N}:\n\n\\inputsnippets{Monoid_instances/Nmoduloh}\n\n\n\\section{Computing powers in any EMonoid}\n\nThe  module \\href{../theories/html/additions.Pow.html}{additions.Pow} defines two functions for exponentiation on any \n\\texttt{EMonoid}  on carrier $A$.\nThey are essentially the same as in Sect.~\\vref{sect: power-definitions}. The main difference lies in the arguments of the functions, which now contain\n an instance~\\texttt{M} of class \\texttt{EMonoid}. \nThus, the arguments associated with the multiplication,\nthe neutral element and the equivalence relation associated with \\texttt{M}\nare left implicit.\n\n\n\\subsection{The naive (linear) algorithm}\nThe new version of the linear exponentiation function is as follows:\n\n\\inputsnippets{Pow/powerDef}\n\nThe three following lemmas will be used by the \\texttt{rewrite} tactic in further\ncorrectness proofs.\nNote  that the first two lemmas are strong\n(\\emph{i.e.}, Leibniz) equalities, whilst \\texttt{power\\_eq3}  is only an equivalence statement, because its proof uses one of the \\texttt{EMonoid} laws, namely\n\\texttt{Eone\\_right}.\n\n\\inputsnippets{Pow/powerEqns}\n\n\n\n\\subsubsection{Examples of computation}\n\nIn the following computations, we first show an exponentiation in $\\mathds{Z}$, then in\nthe type of 31-bit machine integers.\\footnote{\\texttt{phi} and \\texttt{phi\\_inv} are \nstandard library's conversion\nfunctions between types \\texttt{Z} and \\texttt{int31}, used for making it possible to read  and print values of type \\texttt{int31}.}\n\n\\vspace{4pt}\n\nFrom Module~\\href{../theories/html/additions.Demo_power.html}{additions.Demo\\_power}\n\n\n\\inputsnippets{Demo_power/Demopower}\n\n\\subsection{The binary exponentiation algorithm}\n\nPlease find below the implementation of binary exponentiation using type classes\n(to be compared with the version in~\\vref{polymorhic-binary_exp}).\n\n\n% It takes the form of an auxiliary function  \\texttt{binary\\_power\\_mult}\n% associated with equalities \\ref{binary-eq4} to \\ref{binary-eq6} and a main function \\texttt{Pos\\_bpow} associated with equalities \\ref{binary-eq1} to \\ref{binary-eq3}.\n\n\\pagebreak\n\n\\emph{From Module~\\href{../theories/html/additions.Pow.html}{additions.Pow}}\n\n\\inputsnippets{Pow/binaryPowerMult, Pow/PosBpow}\n\n\n\nIt is easy to extend \\texttt{Pos\\_bpow}'s domain to the type of all \nnatural numbers:\n\n\\vspace{4pt}\nFrom Module~\\href{../theories/html/additions.Pow.html}{additions.Pow}\n\n\\inputsnippets{Pow/NBpow}\n\n\\subsection{Refinement and correctness}\nWe have got two functions for computing powers in any monoid. \nSo, it is interesting to ask oneself whether this duplication is useful, and which would be the respective role of \\texttt{N\\_bpow} and \\texttt{power}.\n\n\\begin{itemize}\n\\item The function \\texttt{power}, although very inefficient, is a direct \ntranslation of the mathematical definition, as shown by  lemmas \\texttt{power\\_eq1} to \\linebreak \\texttt{power\\_eq3}. Moreover, its structural recursion over type \\texttt{nat} allows simple proofs by induction over the exponent. \nThus, we will consider \\texttt{power} as a \\emph{specification} of any exponentiation algorithm.\n\n\\item Functions \\texttt{N\\_bpow} and \\texttt{Pos\\_bpow} are more efficient, but less readable than \\texttt{power}, and we cannot use these functions before \nhaving proved their correctness. In fact, the correctness of \n\\texttt{N\\_bpow} and \\texttt{Pos\\_bpow} will mean ``being extensionally equivalent to \\texttt{power}''.\nFor instance \\texttt{N\\_bpow}'s correctness is expressed by the following\nstatement (in the context of an \\texttt{EMonoid} on type \\texttt{A}).\n\n\n\\vspace{4pt}\nFrom Module~\\href{../theories/html/additions.Pow.html}{additions.Pow}\n\n\\inputsnippets{Pow/NBpowOk}\n\\end{itemize}\n\n\nThe relationship between \\texttt{power} and \\texttt{N\\_bpow} can be considered\nas a kind of \\emph{refinement} as in the \\texttt{B}-method~\\cite{b-book}. Note\nthat the two representations of natural numbers and the function \\texttt{N.to\\_nat}\nform a kind of  \\emph{data refinement} \\cite{Abrial:2010:MES:1855020, Cohen2013}.\n\n\n\n\\subsection{Proof of correctness of binary exponentiation w.r.t. the function \\texttt{power}}\nSection \\texttt{M\\_given} of Module \n~\\href{../theories/html/additions.Pow.html}{additions.Pow} is devoted to the proof \nof properties of the functions above.\nNote that properties of \\texttt{power} refer to the \\emph{specification} of exponentiation, and can be applied for proving correctness of any implementation.\n\nIn this section, we consider an arbitrary instance  \\texttt{M} of class \\texttt{EMonoid}.\n\n\\inputsnippets{Pow/MGiven}\n\n\\subsubsection{Properties of exponentiation}\nWe establish a few well-known properties of exponentiation, and define some basic tactics for simplifying proof search.\n\n\\inputsnippets{Pow/MonoidRw}\n\nIn order to make possible proof by rewriting on expressions which contain\nthe exponentiation operator, we have to prove that, whenever \\texttt{$x$ == $y$},\nthe equality \\texttt{$x^n$ == $y^n$} holds for any exponent \\texttt{$n$}. \nFor this purpose, we use the \\texttt{Proper} class of module\n\\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Classes.Morphisms.html}{Coq.Classes.Morphisms}\n\\index{coq}{Type classes}\n\\index{coq}{Type classes!Proper class}\n\n\\inputsnippets{Pow/powerProper}\n\nIn the following proofs, we note how notations, type classes and generalized \nrewriting can be used  to write algebraic properties in a nice way.\n\n\\inputsnippets{Pow/powerOfPlus, Pow/powerSimpl}\n\n\n\n  Please note that the following lemmas \\emph{do not require} \nthe operation~\\texttt{*} to be commutative.\n\n\\inputsnippets{Pow/powerCommute}\n\nThe following two equalities are auxiliary lemmas for proving correctness of the binary exponentiation functions.\n\n\\inputsnippets{Pow/sqrEqn, Pow/powerOfSquare}\n\n\n\\subsection{Equivalence of the two exponentiation functions}\n\nSince \\texttt{binary\\_power\\_mult} is defined by structural recursion on the\nexponent \\texttt{p:positive}, its basic properties are proved by induction\nalong \\texttt{positive}'s constructors.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/additions.Pow.html}{additions.Pow}}\n\n\\inputsnippets{Pow/binaryPowerMultOk}\n\n\\inputsnippets{Pow/PosBpowOk, Pow/PosBpowOkR,\n  Pow/NBpowOk,\n  Pow/NBpowOkR}\n\n \n\n\\subsubsection{Remark}\nThe preceding lemmas can be applied for deriving properties of the binary exponentiation \nfunctions:\n\n\\inputsnippets{Pow/NBpowCommute}\n\n\n\\subsection{Fibonacci, once again}\n\\label{sect:fibonacci-pos-bpow}\n\nWe can use the function \\texttt{Pos\\_bpow} for computing Fibonacci numbers\n(see Section~\\vref{sect:fibonacci-mul2}).\n\n\\emph{From Module~\\href{../theories/html/additions.Fib2.html}{additions.Fib2}}\n\n\\inputsnippets{Fib2/fibPos}\n\n\nFibonacci will come back in Sect.~\\vref{sect:fibonacci-euclidean}.\n\n\n\\section{Comparing exponentiation algorithms with respect to efficiency}\n\nIt looks obvious that  the binary exponentiation algorithm is more efficient than the \nnaive one. Can we study \\emph{within \\coq{}} the respective efficiency of both functions?\nLet us take a simple example with the exponent $17$,  in any \\texttt{EMonoid}.\n\n\\inputsnippets{Pow/bpow17}\n\nTherefore, we note that the term (\\Verb|fun (x:A) =>x ^b 17|)  is\nconvertible --- \\emph{thus logically indistinguishable} --- with a function that performs 16 multiplications.\n\nLikewise, let us simplify the term (\\Verb|fun (x:A) =>x ^ 17|):\n\n\\inputsnippets{Pow/naivePow17}\n\n\n\n\nFrom these tests, we may infer that  representing exponentiation algorithms as plain arithmetic  functions hides\ninformation about the real structure of the computations, particularly about  sharing intermediate computations.\n\nThus, we propose to define a data structure that makes explicit the sequence of multiplications that lead to the computation of $x^n$. For instance, the values of  \n\\texttt{x * x} and\n\\texttt{x * x * (x * x)}  are used\ntwice in the  computation of $x^{17}$ with the binary algorithm. This information should \nappear explicitly in the data structure chosen for representing\nand comparing exponentiation \nalgorithms.\n\nIt is well known that local variables can be used to store intermediate results.\nIn an \\texttt{ISWIM} - \\texttt{ML} style, the function computing $x^{17}$ could be written as follows:\n\n\\inputsnippets{Pow/pow17LetIn}\n\n\\label{pow-17-let-in}\n\nUnfortunately, \\coq's \\textbf{let-in} construct is useless for our purpose, since $\\zeta$-conversion \nwould make the sharing of computations disappear.\n\n\\inputsnippets{Pow/evalPow17LetIn}\n                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        \nIn the next section, we define a \\emph{data structure} for representing \nthe computations that lead to the evaluation of some power $x^n$, where\nintermediary results are explicitly named for further use in the rest of the computation.\n\n\n\n\n\\section{Addition chains}\n\\index{maths}{Addition chains}\nAn \\emph{addition chain} (in short, a \\emph{chain})~\\cite{brauer1939} is a representation of a sequence of\nintermediate steps that lead to the evaluation of  $x^n$, under the \nassumption that each of these steps is a computation of  a power $x^i$, with \n$i<n$.\n\nIn articles from the combinatorist  community, \n\\emph{e.g.},~\\cite{brauer1939,DBLP:journals/ipl/BerstelB87},  addition chains\nare represented as sequences of positive integers, each member of which \nis either $1$ or  the sum of two previous elements.\nFor instance, the three following sequences are addition chains for the exponent $87$:\n\n\\begin{align}\nc_{87} &= (1,2,3,6,7,10,20,40,80,87) \\\\\nc'_{87}&=(1,2,3,4,7,8,16,23,32,64,87) \\\\\nc''_{87}&=(1,2,4,8,16,32,64,80,84,86,87)\n\\end{align}\n\nIt is possible to associate to any addition chain a directed acyclic graph:\nwhenever $i=j+k$, there is an arc from $x^j$ to $x^i$ and an arc\nfrom $x^k$ to $x^i$. Figures~\\ref{fig:chain-87-eucl}  and \n\\ref{fig:chain-87-bin} show the graphical representations of \n $c_{87}$  and $c'_{87}$. \nPlease note that some chains may be represented by various different dags (directed acyclic graphs).\nFor instance, we can associate four different dags to the chain $(1,2,3,4,6,9,13)$. \n\n\n\\begin{figure}[h]\n  \\centering\n  \n  \\caption{Graphical representation of $c_{87}$ (9 multiplications)}\n  \\label{fig:chain-87-eucl}\n\\begin{tikzpicture}\n\\node (X) at (0,0) {$x$};\n\\node (X2) at (1,0) {$x^2$};\n\\node (X3) at (2,0) {$x^3$};\n\\node (X6) at (3,0) {$x^6$};\n\\node (X7) at (4,0) {$x^7$};\n\\node (X10) at (5.5,0) {$x^{10}$};\n\\node (X20) at (6.5,0) {$x^{20}$};\n\\node (X40) at (7.5,0) {$x^{40}$};\n\\node (X80) at (8.5,0) {$x^{80}$};\n\\node (X87) at (9.5,0) {$x^{87}$};\n\\draw [->, >=latex](X) -- (X2);\n\\draw [->, >=latex](X2) -- (X3);\n\\draw [->, >=latex](X3) -- (X6);\n\\draw [->, >=latex](X6) -- (X7);\n\\draw [->, >=latex](X7) -- (X10);\n\\draw [->, >=latex](X10) -- (X20);\n\\draw [->, >=latex](X20) -- (X40);\n\\draw [->, >=latex](X40) -- (X80);\n\\draw [->, >=latex](X80) -- (X87);\n\\draw [->, >=latex](X) to [bend left] (X3);\n\\draw [->, >=latex](X) to [bend left] (X7);\n\\draw [->, >=latex](X3) to [bend left] (X10);\n\\draw [->, >=latex](X7) to [bend left] (X87);\n\\end{tikzpicture}\n\\end{figure}\n\n\\begin{figure}[h]\n  \\centering\n  \n  \\caption{Graphical representation of $c'_{87}$ (10 multiplications)}\n  \\label{fig:chain-87-bin}\n\\begin{tikzpicture}\n\\node (X) at (0,0) {$x$};\n\\node (X2) at (1,0) {$x^2$};\n\\node (X3) at (2,0) {$x^3$};\n\\node (X4) at (3,0) {$x^4$};\n\\node (X7) at (4.5,0) {$x^7$};\n\\node (X8) at (5.5,0) {$x^8$};\n\\node (X16) at (6.5,0) {$x^{16}$};\n\\node (X23) at (8,0) {$x^{23}$};\n\\node (X32) at (9.5,0) {$x^{32}$};\n\\node (X64) at (10.5,0) {$x^{64}$};\n\\node (X87) at (11.5,0) {$x^{87}$};\n\\draw [->, >=latex](X) -- (X2);\n\\draw [->, >=latex](X) to [bend left] (X3);\n\\draw [->, >=latex](X2) to [bend right] (X4);\n\\draw [->, >=latex](X2) -- (X3);\n\\draw [->, >=latex](X4) -- (X7);\n\\draw [->, >=latex](X3) to [bend left] (X7);\n\\draw [->, >=latex](X4) to [bend right] (X8);\n\\draw [->, >=latex](X7) to [bend left] (X23);\n\\draw [->, >=latex](X8) -- (X16);\n\\draw [->, >=latex](X16) -- (X23);\n\\draw [->, >=latex](X16) to [bend right] (X32);\n\\draw [->, >=latex](X32) -- (X64);\n\\draw [->, >=latex](X64) -- (X87);\n\\draw [->, >=latex](X23) to [bend left] (X87);\n\\end{tikzpicture}\n\\end{figure}\n\n\n\nLet us assume that the efficiency of an exponentiation algorithm is proportional\nto the number of multiplications it requires. This assumption looks reasonable \nwhen the data size is bounded (for instance : machine integers, arithmetic modulo $m$, etc.). \nLet us define the \\emph{length} of a chain $c$ as its number $|c|$ of exponents\n(without counting the initial $1$). \nThis length is the number of multiplications needed for \ncomputing the $x^i$s by applying the following algorithm:\n\n\\begin{quote}\nFor any item $i$ of $c$ (but the first one), there exists $j$ and $k$ in $c$, where\n$i=j+k$, and $x^j$ and $x^k$ are already computed.\n\nThus, compute $x^i = x^j \\times x^k$.\n\\end{quote}\n\nIn our little example, we have \n$|c_{87}| = 9 < 10 = |c'_{87}|$. \nIn the rest of this chapter, we will try to focus on the following aspects:\n\\begin{itemize}\n\\item Define a representation of addition chains that allows to compute\n  efficiently $x^n$ in any monoid, for quite large exponents $n$;\n\\item Certify that our representation of chains is correct, \n    \\emph{i.e.}, determines a computation of $x^n$ for a given $n$;\n\\item Define and certify functions for automatically  generating \n    correct and shortest as possible chains.\n\\end{itemize}\n\nIn a previous work~\\cite{DBLP:journals/ita/BrlekCHM95, DBLP:conf/tapsoft/BrlekCS91,AdditionsContrib},  addition chains were represented so as to allow\nefficient computations of powers and certification of a family of\nautomatic chain generators.\n  We present here a new implementation that takes into account some\nadvances in the way we use \\coq{}: generalized rewriting, type classes,\nparametricity, etc.\n\n\n\\subsection{A type for addition chains}\n\nLet us recall that we want to represent some algorithms of the form\ndescribed in section~\\ref{pow-17-let-in}, but avoiding to represent\nintermediate results by \\textbf{let-in}  constructs.\nWe describe below the main design choices we made:\n\n\\begin{itemize}\n\\item Continuation Passing Style (CPS) \n\\index{coq}{Continuation Passing Style (CPS)} \\cite{reynolds93}\nis a way to make explicit the \n     control in the evaluation of an expression, in a purely functional way. \n    For every intermediate computation step, the result is sent\n    to a \\emph{continuation} that executes the further continuations.\n   When the continuation is a lambda-abstraction, its bound variable \n   gives a \\emph{name} to this result\n\n\n  \n\\item Like in Parametric Higher Order Abstract Syntax (PHOAS)~\\cite{PHOAS}, \\index{coq}{Parametric Higher-Order Abstract Syntax (PHOAS)}\n     the local variables associated to intermediate results are\n     represented by variables of  type $A$, where $A$ is the underlying type\n  of the considered monoid.\n\\end{itemize}\n\n\n\\subsubsection{Definition}\n\\label{computation-def}\nLet  \\texttt{A} be some type;  a \\emph{computation} on \\texttt{A} is \n\\begin{itemize}\n\\item  either a final step, returning some value of type \\texttt{A}\n\\item or the multiplication of two values of type  \\texttt{A}, with a  \\emph{continuation}\n  that takes as argument the result of this multiplication, then starts a new\n  computation.\n\\end{itemize}\n  \n  In the following inductive type definition, the intended meaning \n  of the construct (\\texttt{Mult $x$ $y$ $k$})  is \\emph{``multiply \\texttt{x} with\n\\texttt{y}, then send  the result of this multiplication to \n  the continuation  \\texttt{k}''}.\n\n\n\nFrom Module~\\href{../theories/html/additions.Addition_Chains.html}{additions.Addition\\_Chains}\n\n\\inputsnippets{Addition_Chains/computationDef}\n\n\n\\subsubsection{Monadic notation}\n\n\\index{additions}{Types!computation}\n\nThe following \\emph{monadic} \nnotation makes terms of type \\texttt{computation} look like\nexpressions of a small programming language dedicated to sequences of multiplications.\nPlease look at \\emph{CPDT}~\\cite{chlipalacpdt2011} for more details on monadic notations in \\coq.\n\\label{monadic-mult}\n\n\\inputsnippets{Addition_Chains/monadicComputation}\n\nThe \\texttt{computation} type family is able to express sharing of intermediate computations. For instance, the computation of $2^7$ depicted in Figure~\\ref{fig:dag7} is described by  the following term:\n\n\\inputsnippets{Addition_Chains/comp128}\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (leaf) at (2,0){\\texttt{$2$}};\n  \\node (x2) at (3.5,1){\\texttt{$x$}};\n  \\node (x3) at (3.5,2){\\texttt{$y$}};\n \\node (x6) at (3.5,4){\\texttt{$z$}};\n  \\node  (root) at (2,5.5) {\\texttt{$t$}};\n\\draw [->, >=latex, bend left] (leaf) to  node[midway, left] {\\tiny{$2$}} \n (root);\n  \\draw [->, >=latex,bend left] (leaf) to  node[midway, left] {\\tiny{$2$}}  \n(x2);\n  \\draw [->, >=latex,bend right] (leaf) to  node[midway, right] {\\tiny{$2$}} \n (x2);\n \\draw [->, >=latex,bend left] (leaf) to  node[midway, left] {\\tiny{$2$}} \n (x3);\n\\draw [->, >=latex,bend right] (x2) to  node[midway, right] {\\tiny{$2^2$}} \n (x3);\n\\draw [->, >=latex,bend left] (x3) to  node[midway, left] {\\tiny{$2^3$}} \n (x6);\n\\draw [->, >=latex,bend right] (x3) to  node[midway, right] {\\tiny{$2^3$}} \n (x6);\n\\draw [->, >=latex, bend right] (x6) to  node[midway, right] {\\tiny{$2^6$}} \n (root);\n  \\end{tikzpicture}\n  \\caption{The dag associated to a computation of $2^7$}\n  \\label{fig:dag7}\n\\end{figure}\n\n\\subsubsection{Definition}\n\\label{chain-def}\n\nThanks to the  \\texttt{computation} type family, we can associate a type\nto the kind of computation schemes described in Figures~\\ref{fig:chain-87-eucl} and ~\\ref{fig:chain-87-bin}.\n\nWe define \n \\emph{addition chains} (in short  \\emph{chains}) as functions that map\n any\n type \\texttt{A} and any value \\texttt{a} of type \\texttt{A}  into a computation \non \\texttt{A}:\n\n\\index{additions}{Types!chain@chain (addition chains)}\n\n\\inputsnippets{Addition_Chains/chainDef}\n\n\nThus, terms of type \\texttt{chain} describe polymorphic \nexponentiation algorithms. \n\n\nFor instance, Fig~\\vref{fig:C87} shows a definition of the chain  of Figure~\\ref{fig:chain-87-eucl}, for the exponent $87$.\nNote that, like in PHOAS, bound variables associated with the \nintermediary results are \\coq{} variables of type $A$.\n\\begin{figure}[h]\n  \\centering\n  \\inputsnippets{Addition_Chains/C87}\n   \\caption{A chain for raising x to its $87$-th power}\n  \\label{fig:C87}\n\\end{figure}\n\n\n\nThe structure of the definition of types \\texttt{computation}   and \\texttt{chain} suggest that basic definitions over \\texttt{chain} will have the following structure:\n\\begin{itemize}\n\\item A recursive function on type \\texttt{computation $A$} (for a given\n    type $A$)\n\\item A main function on type \\texttt{chain} that calls the previous one on \nany \\texttt{$A$:Type}.\n\\end{itemize}\n\nFor instance, the following function computes the length of any chain,\n\\emph{i.e.}, the number of multiplications of the associated computation.\nNote that the function \\texttt{chain\\_length} calls the auxiliary function\n\\texttt{computation\\_length}, with the variable \\texttt{A} instantiated to the singleton type  \\texttt{unit}. \n\nAny other type in \\coq{} would have fitted our needs, but \\texttt{unit} and\nits unique inhabitant \\texttt{tt} was the simplest  solution.\n\n\\label{C87-length}\n\n\\inputsnippets{Addition_Chains/chainLength}\n\n\\subsection{Chains as a (small) programming language}\n\nThe \\texttt{chain} type can be considered as a tiny programming language dedicated to compute powers in any \\texttt{EMonoid}. Thus, we have to define a semantics for this language. This semantics is defined in two parts:\n\\begin{itemize}\n\\item A structurally recursive function,  --- parameterized with an \\texttt{EMonoid} \\texttt{M} on a given type \\texttt{A} ---, that computes the value associated with any computation on \\texttt{M}\n\\item A polymorphic function that takes as arguments  a  chain \\texttt{c},\n a type \\texttt{A},  an \\texttt{EMonoid} on \\texttt{A}, and \n   a value \\texttt{x:A},\n  then executes the computation \\texttt{(c A x)}.\n\\end{itemize}\n\n\\inputsnippets{Addition_Chains/chainExecute}\n\n\n\n\n\\subsubsection*{Examples:} \nThe following interactions show how to apply the chain \\texttt{C87} \nfor exponentiation within two different monoids:\n\n\n\\inputsnippets{Addition_Chains/C87Apply}\n\n\\index{additions}{Projects}\n\\begin{project}\nStudy how  to compile efficiently such data structures.\n\n\\end{project}\n\n\\index{additions}{Projects}\n\\begin{project}\nDefine a function which returns the sequence of operations defined by a chain.\nFor instance, the chain \\texttt{C87} of Figure \\ref{fig:C87} can be represented as a \nlist containing terms of the form \\texttt{($i$, Add $j$ $k$)} whenever the associated computation contains the operation $x^i=x^j\\times x^k$.\n\n\\inputsnippets{Trace_exercise/traceC87}\n\n\\textbf{Note} A first solution (in ~\\href{../theories/html/additions.Trace_exercise.html}{additions.Trace\\_exercise}) consists in the definition of \na (non-associative) multiplication over a type of trace, and apply the function\n\\texttt{chain\\_execute} as if it were computing a power of \\texttt{(1,Init)}.\n\n\\end{project}\n\n\\subsubsection{Chain correctness and optimality}\n\nA chain is said to be \\emph{correct} with respect to a positive\ninteger \\texttt{p} if its execution in any monoid computes $p$-th powers.\n\n\\label{chain-correct-def}\n\n\\inputsnippets{Addition_Chains/chainCorrect}\n\n\n\n\\begin{definition}\nA chain $c$ is \\emph{optimal} for a given exponent $p$ if its length is less \nthan or equal to\nthe length of any chain correct for $p$.  \n\\end{definition}\n\n\\inputsnippets{Addition_Chains/optimalDef}\n\n \\section{Proving a chain's correctness}\n\\label{chain-correctness-sect}\nIn this section, we present various ways of proving that a given chain is \ncorrect w.r.t. a given exponent. First, we just try to apply \nthe definition in Section~\\vref{chain-correct-def}, but this method is very \ninefficient, even for small exponents. In a second step, we use more sophisticated techniques such as reflection and parametricity. Automatic generation of correct chains will be treated in Sect.~\\vref{chain-generation}.\n\n\\subsection{Proof by rewriting}\nLet us show how to prove  the correctness of some chains, using\nthe \\texttt{EMonoid} laws shown in Sect.~\\vref{EMonoid-def}. \n\n\\inputsnippets{Addition_Chains/slowTac}\n\nUnfortunately, this approach is terribly inefficient, even for quite small exponents:\n\n\\inputsnippets{Addition_Chains/slowC87Correct}\n\n\nIn addition to this big computation time, this approach \ngenerates a huge proof term. Just try to execute the command \n``\\texttt{Print C87\\_ok}'' to get a measure of its size.\nIn order to understand this poor performance, let us consider an intermediate\nsubgoal of the previous proof generated after a sequence of unfoldings and simplifications. This goal is presented below.\n\\begin{figure}[h]\n  \\centering\n\\inputsnippets{Addition_Chains/WhySoSlow}  \n  \\caption{A big goal}\n  \\label{fig:big-goal}\n\\end{figure}\n\n\n\nThis inefficiency certainly comes from the cost of setoid rewriting.\nAt every application of an \\texttt{EMonoid} law, the system must\nverify that the context of this rewriting is compatible  with the equivalence\nrelation associated with the current \\texttt{EMonoid}.\nThe rest of this chapter is devoted to the  presentation of more efficient \n methods for proving chain correctness.\n \n\n\\subsection{Correctness proofs by reflection}\n\\label{reflection-section}\n\\index{coq}{Proofs by reflection}\nInstead of letting the tactic \\texttt{rewrite} look for contexts in which\nsetoid rewriting is possible, we propose to use (deterministic) computations for\nobtaining a ``canonical'' form for terms generated from a variable \\texttt{x}\nby constructors associated with monoid multiplication and neutral element.\n\nThe reader will find general explanations about proofs by reflection in \\coq{},\nfor instance in Chapter 16 of Coq'Art\\cite{BC04} and the numerous examples (including the \\texttt{ring} tactic) \nin \\coq's reference manual.\n\n\n\\subsubsection{How does reflection work}\nLet us consider again the subgoal on Fig.~\\vref{fig:big-goal}, the conclusion of which has the form \\texttt{|$a_1\\,==\\,a_2$|}, where \\texttt{|$a_1$|} and\n\\texttt{|$a_2$|} are terms of  type \\texttt{A}.\nInstead of spending space and time in setoid rewritings, we would like to\nnormalize the terms \\texttt{|$a_1$|} and \\texttt{|$a_2$|} and verify that \nthe associated normal forms are equal.\n\nDefining such a normalization function is possible on an inductive type.\nThe following type describes expressions composed of monoid operations and inhabitants of a given type $A$.\n\n\\pagebreak\n\\inputsnippets{Addition_Chains/MonoidExp}\n\nThus, the main steps of a correctness proof of a given chain, \\emph{e.g.},\n\\texttt{C87} will be the following ones:\n\\begin{enumerate}\n\\item generate a subgoal as in Fig.~\\vref{fig:big-goal},\n\\item express each term of the equivalence as the image of a term\n     of type \\texttt{Monoid\\_Exp $A$},\n\\item normalize both terms and verify that their normal forms are equal.\n\\end{enumerate}\n\nThe rest of this section is devoted to the definition of the normalization \nfunction on \\texttt{Monoid\\_Exp $A$}, and the proofs of lemmas that\nlink equivalence on type \\texttt{A} and equality of normal forms\nof terms of type \\texttt{Monoid\\_Exp $A$}.\n\n\n\\subsubsection{Linearization function}\n\nThe following functions help to transform any term of type\n\\texttt{Monoid\\_Exp $A$} into a flat ``normal form''.\n\n\\inputsnippets{Addition_Chains/flattenDef}\n\n\\subsubsection{Interpretation function}\n\nThe function \\texttt{eval} maps any term of type \\texttt{Monoid\\_Exp $A$}\ninto a term of type \\texttt{$A$}.\n\n\\inputsnippets{Addition_Chains/evalDef}\n\n\nThe following two lemmas relate the linearization function \\texttt{flatten}\nwith the interpretation function \\texttt{eval}.\n\n\\inputsnippets{Addition_Chains/flattenValid}\n\\inputsnippets{Addition_Chains/flattenValid2}\n\n\\subsubsection{Transforming a multiplication into a tree}\nLet us now build a tool for building terms of type  (\\texttt{Monoid\\_Exp $A$}) out\nof terms of type \\texttt{A} containing multiplications of the form \n\\Verb|(_ * _)%M| and the variable \\texttt{one}. \nIn fact, what we want to  define is an inverse of the function \\texttt{flatten}.\n\nSince \\texttt{mult\\_op} is not a constructor (see Sect.~\\ref{op-classes}), \nthe transformation of  \na product of type \\texttt{A} into a term of type \\texttt{Monoid\\_Exp A}\nis done with the help of a tactic:\n\n\\inputsnippets{Addition_Chains/modelTac}\n\nFor instance, the term \\texttt{(x * x * x * (x * x * x) * x)} is\ntransformed by \\texttt{model} in the following term of type \\texttt{Monoid\\_Exp $A$}\n\n\\begin{Coqsrc}\n(eval M\n   (Mul_node\n     (Mul_node \n        (Mul_node (Mul_node (A_node x) (A_node x)) (A_node x))\n        (Mul_node (Mul_node (A_node x) (A_node x)) (A_node x))) \n     (A_node x)))  \n\\end{Coqsrc}\n\n\n\\subsection{Reflection tactic}\nThe tactic \\texttt{monoid\\_eq\\_A} converts a goal of the form \n(\\texttt{E\\_eq $X$ $Y$}), where\n\\texttt{$X$} and \\texttt{$Y$} are terms of type $A$, into\n(\\texttt{E\\_eq (eval M  (model X)) (eval M  (model Y))}). This last goal is intended to be solved thanks \nto the lemma \\texttt{flatten\\_valid\\_2}.\n\n\\inputsnippets{Addition_Chains/monoidEqTac}\n\n\\subsubsection{Main reflection tactic}\n\nThe tactic \\texttt{reflection\\_correct\\_tac} tries to prove a chain's \ncorrectness by a comparison of two terms of type \\texttt{Monoid\\_Exp $A$}:\none being obtained from the chain's definition, the other one by expansion\nof the naive exponentiation definition.\n\n\\inputsnippets{Addition_Chains/reflectionCorrectTac}\n\n\\subsubsection{Example}\nThe following dialogue clearly shows the efficiency gain over naive setoid rewriting.\n\n\\inputsnippets{Addition_Chains/reflectionDemo}\n\n\nThis tactic is not adapted to much bigger exponents. In \\linebreak\n Module~\\href{../theories/html/additions.Euclidean_Chains.html}{Euclidean\\_Chains},\n for instance, we tried to apply this tactic for proving the correctness \nof a chain associated with the exponent $45319$. \n We had to interrupt the prover, which \nwas trying to build a linear tree of $2\\times  45319 + 1$ nodes!\nIndeed, using \\texttt{reflection\\_correct\\_tac} is like doing a \nsymbolic evaluation of an inefficient (linear) exponentiation algorithm.\n\nIn the next section, we present a solution that avoids doing such a lot of computations.\n\n\\subsection{Chain correctness for ---practically --- free!}\n\\label{correctness-for-free}\n\n% Let us consider again the chain \\texttt{C87} of Fig.~\\vref{fig:C87}.\n% Every bound variable of type \\texttt{A} is either the argument \\texttt{x}\n% or a variable introduced by the abstraction corresponding to the\n% continuation argument of constructor \\texttt{Mult} (hidden by the monadic notation). Thus, it seems obvious that during the execution of some  computation\n% \\texttt{C87 A a}, each of this variable will be bound to some power of \n% \\texttt{a}. \n\n% Thus, we would like to prove that  every chain \\texttt{c} has this property,\n% which would be a great step for proving any chains's correctness.\n\n\n\n\\subsubsection{About parametricity}\n\\index{coq}{Parametricity}\nLet us now present another tactic for proving chain correctness,\nin the tradition of works on \\emph{parametricity} and its use for \nproving properties on programs.\nStrachey~\\cite{Strachey:2000:FCP:609150.609208}\nexplores the nature of \\emph{parametric\npolymorphism}: ``\\emph{Polymorphic functions behave uniformly for all types}''\nthen Reynolds~\\cite{REYNOLDS83} formalizes this notion through binary relations.\nWadler~\\cite{Wadler1989}, then Cohen \\emph{et al.}~\\cite{Cohen2013}\nuse this relation for deriving\n theorems about functions that operate on parametric\npolymorphic types.\n\nLet us look again at the definitions of type family \\texttt{computation}\nand the type \\texttt{chain}:\n\n\\inputsnippets{Addition_Chains/computationDef,\n  Addition_Chains/chainDef}\n\nLet $c$ be a closed term of type \n\\texttt{chain}; $c$ is  of the form \\linebreak\n\\texttt{fun (A:Type)(a:A) => $t_a$}, where $t_a$ is a term of type\n\\texttt{@computation A}.\n\\label{obvious-remark}\nObviously,  in every subterm of {$t_a$} of type \\texttt{A}, \nthe two first arguments of constructor \\texttt{Mult} or the\nargument of \\texttt{Return} are either \\texttt{a} or a variable \nintroduced as the formal argument of a continuation \\texttt{k}.\nIn effect, there is no other way to build terms of type \\texttt{A} in the considered context.\n\n\\index{coq}{Plug-ins!paramcoq}\n\nMarc Lasson's \\textbf{paramcoq} plug-in~(available as  \\texttt{opam} package \n\\texttt{coq-paramcoq}) generates  a family of binary relations definitions\nfrom \\texttt{computation}'s definition.\n\n\\pagebreak\n\n\\inputsnippets{Addition_Chains/paramDemo}\n\n\n\nLet $A$ and $B$  be two types, and $R: A \\arrow B \\arrow \\typesort$ \na relation.\nTwo computations \\texttt{cA: @computation A} and \\texttt{cB: @computation B}\nare related \\emph{w.r.t.} \\texttt{computation\\_R} if every pair of \narguments of \\texttt{Mult} and \\texttt{Return} at the same position \nare related \\emph{w.r.t.} \\texttt{R}.\n\n\n\\subsubsection{Definition}\nA chain $c$ is \\emph{parametric} if it has the same behavior for any\npair of types $A$  and $B$, any relation $R$\nbetween  $A$ and $B$ and any $R$-related pair of \narguments $a$ and $b$:\n\n\\inputsnippets{Addition_Chains/parametricDef}\n\n\\subsubsection{How to use these definitions?}\nLet us use parametricity for proving easily \na given chain's correctness.\nIn other words, \nlet $c$ be a chain and \\texttt{$p$:positive} be a given exponent.\nConsider some instance of \\texttt{EMonoid} over a type $A$.\nWe want to prove that the application of the chain $c$ to \nany value $a$ of type $A$ returns the value \\texttt{$a^p$}.\n\nWe first use \\coq's computation facilities for ``guessing'' the exponent associated with any given chain. It suffices to instantiate ``monoid multiplication'' with addition on positive integers.\n\n\\inputsnippets{Addition_Chains/theExponent}\n\nWe show how to \\emph{prove} that  a given  chain $c$,\napplied to any $a$, really computes $a^p$, where $p=\\textrm{the\\_exponent}\\;c$.\nParametricity allows us to compare executions on any monoid $M$ \nwith executions on \\texttt{NatPlus}.\nLet us consider the  mathematical relation \n$\\{(x,n)\\in M\\times\\mathbb{N}\\,|\\, 0<n \\wedge x=a^n\\}$.\n\n\\inputsnippets{Addition_Chains/powerR}\n\nFirst, we prove the following lemma, that relates \\texttt{computation\\_R}\nwith the result  of the  executions of the corresponding computations:\n\n\\inputsnippets{Addition_Chains/powerRRef}\n\nThus, if \\texttt{$c$:chain} is parametric, this refinement lemma allows us\nto prove a correctness result:\n\n\\inputsnippets{Addition_Chains/paramCorrectnessNat}\n\nA similar result can be proven with the exponent in \\texttt{positive}.\nFirst we instantiate the parameter \\texttt{R} of \\texttt{computation\\_R},\nwith the relation that links the representations of natural numbers\non respective types \\texttt{nat} and \\texttt{positive}.\nThen we use our lemmas for rewriting under the assumption that the\nconsidered chain is parametric. Please note how our approach is related with\n\\emph{data refinement} (see also~\\cite{Cohen2013}).\nThe reader may also consult a survey by D. Brown on the most important contributions to \nthe notion of parametricity~\\cite{DanBrown-survey}.\n\n\\inputsnippets{Addition_Chains/exponentPosToNat}\n\\inputsnippets{Addition_Chains/exponentPosOfNat}\n\\inputsnippets{Addition_Chains/paramCorrectness}\n\n\nLemma \\texttt{param\\_correctness} suggests us a method for verifying \nthat a given chain $c$ is correct \\emph{w.r.t.} some positive exponent $p$:\n\n\\begin{enumerate}\n\\item Verify that $c$ is parametric.\n\\item Verify that $p$ is equal to (\\texttt{the\\_exponent $c$}).\n\\end{enumerate}\n\n\\subsubsection{How to prove a chain's parametricity}\nDespite the apparent complexity of \\texttt{computation\\_R}'s definition,\nit is very simple to prove that a given chain is parametric. The following tactics\nproceed as follows:\n\n\\begin{enumerate}\n\\item Given a chain $c$, consider two types \\texttt{A} and\n\\texttt{B}, and any relation \\texttt{R:A->B->Prop}, \n\\item Push into the context declarations of \\texttt{a:A}, \\texttt{b:B}\nand an hypothesis assuming \\texttt{R a b}.\n\\item Then the tactic crosses in parallel the terms (\\texttt{c A a}) and\n(\\texttt{c B b}) (of the same structure),\n\\begin{itemize}\n\\item On a pair of terms of the form \n\\texttt{Mult xA yA (fun zA => tA)} and \\linebreak \\texttt{Mult xB yB (fun zB => tB)}, the tactic checks whether \n   \\texttt{R xA xB} and \\texttt{R yA yB} are already assumed in the context,\n then  pushes into the context the declaration of \\texttt{zA} and \\texttt{zB}\nand the hypothesis \\linebreak \\texttt{Hz: R zA zB}, then crosses the terms \\texttt{tA} and\n \\texttt{tB}\n\\item On a pair of terms  of the form   (\\texttt{Return xA}) and (\\texttt{Return xB}),\n the tactic just checks whether (\\texttt{R xA xB}) is assumed.\n\\end{itemize}\n\n\\end{enumerate}\n\nThe tactic itself is simpler than its explanation. \n\n\\inputsnippets{Addition_Chains/parametricTac}\n\n\\subsubsection{Proving a chain's correctness}\n\\label{C87-param-ok}\nFinally, for proving that a given chain $c$ is correct with respect to an exponent $p$, it suffices to check that $c$ is parametric, and\nto apply the lemma \\texttt{param\\_correctness}. \nThe reader will note how this computation-less method is much more efficient\nthan our reflection tactic.\n\n\\inputsnippets{Addition_Chains/paramChainCorrect}\n\n\\subsubsection{Remark}\nFor the reasons exposed in Section~\\vref{obvious-remark}, \nit seems obvious that any well-written chain is parametric.\nUnfortunately, we cannot prove this property  in \\coq{},\nfor instance by induction on \\texttt{c}, \nsince \\texttt{chain} is a product type and not an inductive type.\n\n\\inputsnippets{Addition_Chains/VeryBad,Addition_Chains/VeryBad2}\n\nGiven this situation, we could  admit (as an axiom) that \nany chain is parametric. Nevertheless, if a chain is under the form of a \nclosed term, using \\texttt{parametric\\_tac} is so efficient than we prefer to \n avoid\na shameful introduction of an axiom in our development.\n\n\\section{Certified chain generators}\n\\label{chain-generation}\n\nIn this section, we are interested in the \\emph{correct by construction} paradigm.\nWe just want to give a positive exponent to \\coq{} and get a (hopefully)  correct and  efficient chain for this exponent.\n\nWe first define the notion of \\emph{chain generator}, then present a certified generator that simulates the binary exponentiation algorithm. Last, we present a better chain generator based on integer division.\n\n\n\\subsection{Definitions}\n\nWe call \\emph{chain generator} any function that takes as argument \nany positive integer and returns a chain.\nA generator $g$  is \\emph{correct} it it returns a correct chain\nfor any exponent.\n\n\\inputsnippets{Addition_Chains/generatorDef}\n\nCorrect generators can be used for computing powers \non the fly, thanks to the following functions:\n\n\\inputsnippets{Addition_Chains/cpowerDef}\n\n\nNote also that the use of chain generators is independent from  the techniques presented in Sect.~\\ref{chain-correctness-sect}:\nDesigning an efficient and correct chain generator may be a long and hard task.\nOn the other hand, once a generator is certified, we are assured of the correctness of  \nall its outputs.\nFinally, we say that a generator $g$ is \\emph{optimal} if it returns chains whose length are less than or\nequal to any chain returned by any correct generator:\n\n\\inputsnippets{Addition_Chains/optimalGenerator}\n\n\\subsection{The binary chain generator}\n\nLet us reinterpret the  binary exponentiation algorithms in the framework \nof addition chains.\nInstead of directly computing $x^n$ for some base $x$ and exponent $n$,\nwe build chains that describe the computations associated with the binary exponentiation method.\nNot surprisingly, this chain generation will be described in terms of recursive\nfunctions, once the underlying monoid is fixed.\n\nAs for the ``classical'' binary exponentiation algorithm,\nwe define an auxiliary computation generator for  the\nproduct of an accumulator $a$ with an arbitrary power of some value $x$.\n\n\\inputsnippets{Addition_Chains/binaryChain}\n\n\n\n\n\\subsubsection{Proof of \\texttt{binary\\_chain}'s correctness}\n\nLet us now prove that \\texttt{binary\\_chain} always returns correct chains.\nFirst, due to the structure of this generator's definition, we study the\nproperties of the auxiliary functions that operate \\emph{on a given monoid $M$}.\n\n\\inputsnippets{Addition_Chains/binaryPowerProofa}\n\\inputsnippets{Addition_Chains/binaryPowerProofb}\n\\inputsnippets{Addition_Chains/binaryPowerProofc}\n\\inputsnippets{Addition_Chains/binaryPowerProofd}\n\\inputsnippets{Addition_Chains/binaryGeneratorOk}\n\n\\subsubsection{The binary method is not optimal}\n\nIt is easy to prove by contradiction  that the binary method is not the most efficient \nfor computing powers. \n\n\\inputsnippets{Addition_Chains/nonOpt}\n\n\\index{additions}{Exercises}\n\\begin{exercise}\nProve that for any positive integer $p$,  the length of any optimal chain \nfor $p$ is less  than twice the number of digits of the binary representation of $p$.\n\\end{exercise}\n\n\n\\section{Euclidean Chains}\n\\label{euclide-sect}\n\\index{maths}{Euclidean addition chains}\nIn this section, we present an efficient chain generator. The chains built by this generator\nare never longer than the chains built by the binary generator. Moreover, for an \ninfinite number of exponents, the chains it builds are strictly shorter than the chain\nreturned by \\texttt{binary\\_chain}. \nEuclidean chains are based on the following idea: \n\\begin{quote}\nFor generating a chain that computes $x^n$, one may choose some natural number\n$0<p<n$, and build a chain that computes first $x^p$ \\textbf{then} uses this value\nfor computing $x^n$. \n\\end{quote}\n\nFor instance, a  computation of $x^{42}$ can be decomposed into a computation \nof $y=x^3$, then a computation of $y^{14}$. The efficiency of the chain built with this\nmethods depends heavily on the choice of $p$. See~\\cite{DBLP:journals/ita/BrlekCHM95} for details.\n\nConsidering chain generators and their correctness, we may consider the dual of \ndecomposition of exponents: we would like to write \\emph{composable} correct \nchain generators. For instance, we want to build some object that, ``composed''  \nwith any correct chain for $n$, returns a correct chain for $3n$.\n\n\\paragraph{Note:}\nAll the \\coq{} material described in this section is available on \n Module~\\href{../theories/html/additions.Euclidean_Chains.html}{additions/Euclidean\\_Chains.v}\n\n\\subsection{Chains and continuations : f-chains}\n\n\nPlease consider the following small example:\n\n\\inputsnippets{Addition_Chains/C3Example}\n\n\nThe execution of this chain on  some value $x:A$ stops after \ncomputing \\texttt{$x^3$}, because of the \\texttt{Return} ``statement''.\nHowever, we would like to compose the instructions of \\texttt{C3} \nwith a chain for another exponent $n$, in order to generate a chain for \nthe exponent $3\\times n$.\n\n  The solution we present is based on functional programming and the concept of continuation.\n\n\n\n\\subsubsection{Type definition of  f-chains}\n\nLet us   consider \\emph{incomplete} or \\emph{open} chains.\nSuch an object waits for another chain to resume  a computation.\n\nFigure~\\ref{fig:F3-as-dag} represents an  f-chain associated with the exponent $3$, as a dag with an input and one output the edges of which are depicted as thick arrows.\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (entree) at (0,0) {};\n  \\node (X) at (1,0) {$x$};\n\\node (X2) at (2,0) {$x^2$};\n  \\node (X3) at (3,0) {$x^3$};\n\\node (sortie) at (4,0) {};\n\\draw [>-,   thick](entree) -- (X);\n\\draw [->, >=latex, ](X) -- (X2);\n\\draw [->, >=latex, ](X2) -- (X3);\n\\draw [->, >=latex,  thick](X3) -- (sortie);\n\\draw [->, >=latex](X) to [bend left] (X3);\n\\draw[dashed] (0.5,-0.3) rectangle (3.5,0.6);\n  \\end{tikzpicture}\n  \\caption{Graphical representation of \\texttt{F3}}\n  \\label{fig:F3-as-dag}\n\\end{figure}\n\nIn other words, this kind of objects can be considered as \\emph{functions}\nfrom chains to chains. So, we called their type \\texttt{Fchain}.\n\n\n\nFirst, we define a type of \\emph{continuations},\n\\emph{i.e.},  functions  that wait for some value $x$, then \nbuild  a computation for raising {$x$} to some  given exponent.\nAn \\texttt{f-chain} is just a polymorphic function that combines  a \ncontinuation and an element into a computation.\n\n\\inputsnippets{Euclidean_Chains/FchainDef}\n\n\\subsubsection{Examples}\n\nLet us define a chain for computing the cube of some $x$, then sending \nthe result to a continuation $k$.\n\n\\inputsnippets{Euclidean_Chains/F3Def}\n\nAny f-chain can be converted into a chain by the help of the following function:\n\n\\inputsnippets{Euclidean_Chains/F2C}\n\n\nIn the rest of this chapter, we will use two other f-chains, respectively associated with the exponents $1$ and $2$. Chains \\texttt{F1}, \\texttt{F2} and\n\\texttt{F3} will form a basis to generate  chains for many exponents\nby \\emph{composition of correct functions}.\n\n\\inputsnippets{Euclidean_Chains/F1F2}\n\n\n\\subsubsection{F-chain application and composition}\n\nThe following definition allows us to consider any value {$f$} \nof type \n\\texttt{Fchain} as a function of type \\texttt{chain $\\arrow$ chain}.\n\n\\inputsnippets{Euclidean_Chains/Fapply}\n\n\nIn a similar way, \\emph{composition} of \\texttt{f-chain}s is easily defined\n(see Figure~\\vref{fig:Fcompose}).\n\n\\inputsnippets{Euclidean_Chains/Fcompose}\n\n\\inputsnippets{Euclidean_Chains/F1Neutral}\n\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n \\node (input1)  at (0,0) {};  \n \\node [draw] (F1)  at (1,0) {$f_1$};  \n \\node (output1)  at (2.0,0) {};  \n \\node (input2)  at (2.6,0) {};  \n \\node [draw] (F2)  at (3.5,0) {$f_2$};  \n \\node (output2)  at (4.5,0) {};  \n \\draw [>-,   thick](input1) -- (F1);\n \\draw [->, >=latex, thick](F1) -- (output1);\n\\draw [dotted, ](output1) -- (input2);\n\\draw [>-,   thick](input2) -- (F2);\n\\draw [->, >=latex, thick](F2) -- (output2);\n\\draw[dashed] (0.4,-1) rectangle (4,1);\n  \\end{tikzpicture}\n  \\caption{Composition  of f-chains $f_1$ and $f_2$ (\\texttt{Fcompose})}\n  \\label{fig:Fcompose}\n\\end{figure}\n\\subsubsection{Examples}\n\nThe following examples show that the apparent complexity of the previous \ndefinition is counterbalanced with the simplicity of using \\texttt{Fapply}\nand \\texttt{Fcompose}.\n\n\\inputsnippets{Euclidean_Chains/F9Def}\n\\inputsnippets{Euclidean_Chains/F9Ok}\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n\n \\node (inputx)  at (-0.2,0) {};  \n\\node (x)  at (1,0) {$x$};  \n \\node (x2)  at (2,0) {$x^2$};  \n \\node (x3)  at (3,0) {$x^3$};\n \\node (output1)  at (4,0) {};  \n \\node (inputy)  at (5.5,0) {};  \n\\node (y)  at (6.5,0) {$y$};  \n \\node (y2)  at (7.5,0) {$y^2$};  \n \\node (y3)  at (8.5,0) {$y^3$};\n \\node (output2)  at (9.6,0) {};  \n \\draw [>-,   thick](inputx) -- (x);\n \\draw [->,   >=latex](x) -- (x2);\n\\draw [->,   >=latex](x2) -- (x3);\n\\draw [->, >=latex](x) to [bend left] (x3);\n\\draw [->, >=latex, thick](x3) -- (output1);\n\\draw [->, dotted ](output1) -- (inputy) node [midway, above] {\\tiny{$y:=x$}};\n\\draw [>-,   thick](inputy) -- (y);\n \\draw [->,   >=latex](y) -- (y2);\n\\draw [->,   >=latex](y2) -- (y3);\n\\draw [->, >=latex](y) to [bend left] (y3);\n\\draw [->, >=latex, thick](y3) -- (output2);\n\\draw[dashed] (0.4,-1) rectangle (3.5,1);\n\\draw[dashed] (6,-1) rectangle (9,1);\n\\draw[dashed] (0.2,-1.2) rectangle (9.2,1.2);\n  \\end{tikzpicture}\n  \\caption{Composition  of F-chains: F9}\n  \\label{fig:F9}\n\\end{figure}\n\nUsing structural recursion and the operator \\texttt{FCompose},\nwe build a chain for any exponent of the form $2^n$:\n\n\\inputsnippets{Euclidean_Chains/Fexp2}\n\n\n\\subsection{F-chain correctness}\nLet \\texttt{f} be some term of type \\texttt{Fchain}, and \\texttt{n:nat}.\nWe would like to say that \\texttt{f} is correct \\emph{w.r.t.} \\texttt{n:nat}\nif for any continuation \\texttt{k} and \\texttt{a}, the application of \n\\texttt{f} to \\texttt{k} and \\texttt{a} computes \\texttt{$k(a^n)$}.\n\n\\begin{Coqbad}\nModule Bad.\n\nDefinition Fchain_correct  (n:nat) (f : Fchain) :=\n  forall A `(M : @EMonoid A op E_one E_equiv) k (a:A),\n    computation_execute op (f A k  a)==\n    computation_execute op (k  (a ^ n)).\n\\end{Coqbad}\n\nLet us now try to prove that \\texttt{F3} is correct \\emph{w.r.t.} $3$.\n\n\\inputsnippets{Euclidean_Chains/BadDefa}\n\\inputsnippets{Euclidean_Chains/BadDefb}\n\nThis failure is due to a lack of an assumption that the continuation\n\\texttt{k} is \\emph{proper} with respect to the equivalence \\texttt{equiv}.\nThus, \\coq{} is unable to infer from the equivalence \n\\texttt{(a * a * a) == (a * (a * (a * E\\_one)))} \\linebreak that \n(\\texttt{k (a * a * a)}) and (\\texttt{k (a * (a * (a * E\\_one)))}) are \nequivalent computations.\n\n\n\n\\subsubsection{Definition:} \n\\index{coq}{Type classes}\n\\index{coq}{Type classes!Proper class}\nA continuation \\texttt{k:Fkont A} is \\emph{proper}\nif, whenever \\linebreak[3] \\texttt{x == y} holds, the computations (\\texttt{k x}) and \n(\\texttt{k y}) are equivalent.\n\n\\inputsnippets{Euclidean_Chains/FkontProper}\n\n\nWe are now able to improve our definition of correctness, taking only\nproper continuations into account.\n\n\\inputsnippets{Euclidean_Chains/GoodFchainCorrect}\n\n\\subsubsection{Examples}\n\nLet us show manual correctness proofs of some small f-chains:\n\n\\inputsnippets{Euclidean_Chains/F1Ok}\n\n While proving \\texttt{F3}'s correctness, we will have to apply\n the properness hypothesis on \\texttt{k}:\n\n\\inputsnippets{Euclidean_Chains/F3Ok}\n\nCorrectness of \\texttt{F2} is proved the same way:\n\n\\inputsnippets{Euclidean_Chains/F2Ok}\n\n\\subsubsection{Composition of correct f-chains: a first attempt}\n\nWe are now looking for a way to generate correct chains for any positive \nnumber. It seems obvious that we could use \\texttt{Fcompose} for building \na correct f-chain for $n\\times p$ by composition of a correct f-chain for \n$n$ and a correct f-chain for $p$.\nLet us try to certify this construction:\n\n\\inputsnippets{Euclidean_Chains/Bad2a, Euclidean_Chains/Bad2b}\n\n\nNo hypothesis guarantees us that the execution of \\texttt{f2} respects the equivalence\n\\texttt{x == y}.\n\n\\inputsnippets{Euclidean_Chains/Bad2c}\n\n Thus, we need to define also a  notion of properness for f-chains. \nA first attempt would be :\n\n\\inputsnippets{Euclidean_Chains/Bad3}\n\n\n\nThis definition is powerful enough for proving that properness is \npreserved by composition:\n\n\\inputsnippets{Euclidean_Chains/Bad3b}\n\nNevertheless, we had to throw away  this definition of properness:\nIn further \ndevelopments (Sect.~\\vref{Kkonts-section})  we shall  have to compare\nexecutions of the form \\texttt{fc A $k_x$ x} and \\texttt{fc A $k_y$ y}\nwhere \\texttt{x == y} and {$k_x$} and {$k_y$} are \n``equivalent''\nbut not \\emph{convertible} continuations.\n\n\\inputsnippets{Euclidean_Chains/Bad3c}\n\n\\subsubsection{A better definition of properness}\n\n The following  generalization will allow us to consider continuations that are\ndifferent (according to Leibniz equality) but lead to equivalent\ncomputations and results.\n\n\\inputsnippets{Euclidean_Chains/correctProper}\n\n\\subsubsection{Examples}\nThe definition above allows us  to build simply several instances of the class \\linebreak\n\\texttt{Fchain\\_proper}:\n\n\\inputsnippets{Euclidean_Chains/F1proper}\n\\inputsnippets{Euclidean_Chains/F2proper}\n\\inputsnippets{Euclidean_Chains/F3proper}\n\n\\subsection{Correctness of chain composition}\n\nThe \\texttt{Fcompose} operator respects chain correctness and properness.\n\n\\inputsnippets{Euclidean_Chains/FcomposeCorrect}\n\\inputsnippets{Euclidean_Chains/FcomposeProper}\n\nUsing chain composition, we get a correct and proper chain for any exponent of the form $2^n$.\n\n\\inputsnippets{Euclidean_Chains/Fexp2Correct}\n\\inputsnippets{Euclidean_Chains/Fexp2Proper}\n\nWe are now  able to build chains for any exponent of the form \n$2^k\\times 3^p$, using \\texttt{Fcompose}. Les us look at a simple example:\n\n\\inputsnippets{Euclidean_Chains/F144}\n\n\n\\subsection{Building chains for two distinct exponents : k-chains  \\label{Kkonts-section}}\n\n\\subsubsection{Introduction}\nNot every chain can be built efficiently  with \\texttt{Fcompose}.\n For instance, consider the exponent $n= 23 = 3 + 2^4 + 2^2$. \n\nOne may attempt to define a new operator  for combining f-chains for \n$n$ and $p$ into an f-chain for $n+p$.\n\n\\pagebreak\n\\inputsnippets{Euclidean_Chains/Fplus}\n\nUnfortunately, our construct is still very inefficient, since it results in \nduplication of computations, as shown by the normal form of \\texttt{F23}.\n\n\n\\inputsnippets{Euclidean_Chains/Fplusb}\n\nWe observe that the variables \\texttt{x3} and \\texttt{x7} are \nuseless, since\nthey will have the same value as \\texttt{x1}. Likewise, computing\n\\texttt{x8} (same value as \\texttt{x4}) is a waste of time.\n\n A better scheme for computing $x^{23}$ would be the following one:\n\n \\begin{enumerate}\n \\item Compute $x$, $x^2$, $x^3$, \\textbf{and} $x^6 = {(x^3)}^2$, then  $x^7$,\n \\item Compute $x^{10} = x^7 \\times x^3$, then $x^{20}$\n \\item Finally, return  $x^{23} = x^{20} \\times x^3$\n \\end{enumerate}\n\nIn fact, the first step of this sequence  computes \\emph{two}\nvalues: $x^7$ and $x^3$, that are re-used by the rest of the computation.\n\n  Like in some programming languages\n that allow  ``multiple values'', like \\texttt{Scheme} and \\texttt{Common Lisp}, we can  express this feature \n in terms of continuations that accept two arguments.\nThus, we extend our previous definitions to chains that return two \ndifferent powers of their argument\\footnote{The name \\texttt{Kchain} comes from previous versions of this development. It may be changed later.}.\n\n\n\\index{coq}{Continuation Passing Style (CPS)}\n\n\\inputsnippets{Euclidean_Chains/KchainDef}\n\n\\subsubsection{Examples}\n\nThe chain \\texttt{k3\\_1} sends both values $x$ and $x^3$ to its continuation.\nLikewise, \\texttt{k7\\_3} ``returns''  $x^7$ and $x^3$. \n\n\\inputsnippets{Euclidean_Chains/K31}\n\\inputsnippets{Euclidean_Chains/K73}\n\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (entree) at (0,0) {};\n  \\node (X) at (1,0) {$x$};\n\\node (X2) at (2,0) {$x^2$};\n  \\node (X3) at (3,0) {$x^3$};\n\\node (sortieX) at (4.5,0.6) {};\n\\node(beforeSortieX) at (2,0.6){};\n\\node (sortieX3) at (4.5,0) {};\n\\draw [>-,   thick](entree) -- (X) node [near start, above] {\\tiny{$x$}};\n\\draw [->, >=latex, ](X) -- (X2);\n\\draw [->, >=latex, ](X2) -- (X3);\n\\draw [->,  thick](X3) -- (sortieX3) node [at end, above] {\\tiny{$x^3$}};\n\\draw [->, >=latex](X) to [bend left] (X3);\n\\draw [->, >=latex](X) to [bend left] (X3);\n%\\draw [thick](X) to [bend left] (beforeSortieX)\n\\draw [->, thick](X) -- (2,0.6) --  (sortieX) node [at end, above] {\\tiny{$x$}};\n\\draw[dashed] (0.6,-0.4) rectangle (3.7,1);\n  \\end{tikzpicture}\n  \\caption{Graphical representation of \\texttt{K3\\_1}}\n  \\label{fig:K3-1-as-dag}\n\\end{figure}\n\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (entree) at (-0.4,0) {};\n  \\node (X) at (1,0) {$x$};\n  \\node (X2) at (2,0) {$x^2$};\n\\node (X3) at (3.5,0) {$x^3$};\n  \\node (X6) at (4.5,0) {$x^6$};\n\\node (X7) at (6,0) {$x^7$};\n  \\draw [>-,   thick](entree) -- (X) node [near start, above] {\\tiny{$x$}};\n \\draw [->](X) -- (X2);\n\\draw [->](X2) -- (X3);\n\\draw [->, bend left](X) to (X3) ;\n\\draw [->, bend left](X) to (X7) ;\n\\draw [->](X3) -- (X6) ;\n\\draw [->](X6) -- (X7) ;\n  \\node (sortieX7) at (7.5,0) {};\n  \\node (sortieX3) at (7.5,0.8) {};\n \\draw [->,   thick](X7) -- (sortieX7) node [at end, above] {\\tiny{$x^7$}};\n \\draw [->,   thick](X3) -- (5.5,0.8) -- (sortieX3)  node [at end, above] {\\tiny{$x^3$}};\n\\draw  [dashed] (0.5,-0.7) rectangle (6.5,1.4);\n  \\end{tikzpicture}\n  \\caption{Graphical representation of \\texttt{K7\\_3}}\n  \\label{fig:K7-3-as-dag}\n\\end{figure}\n\n\n\\subsubsection{Definitions}\n\nFirst, we have to adapt to k-chains our definitions of correctness and properness.\n\n\\inputsnippets{Euclidean_Chains/KkontDefs}\n\n\n\nA k-chain is correct with respect to two exponents $n$ and $p$ \n  if it computes $x ^ n$ and $x ^ p$ for any $x$ in any monoid $M$.\n\n\\inputsnippets{Euclidean_Chains/KchainCorrectDef}\n  \n\\subsubsection{Example}\nFor instance, let us prove that \\texttt{k7\\_3} is proper and correct for the exponents  $7$ and $3$.\n\n\\inputsnippets{Euclidean_Chains/K73Ok}\n\n\\subsection{Systematic construction of  correct f-chains and k-chains}\n\nWe are now ready to define various operators on f- and k-chains, and prove these\noperators preserve correctness and properness. We will also show that\nthese operators allow to generate easily correct chains for any positive \nexponent. They will be used to generate chains for\nnumbers of the form $n=bq+r$ where $0\\leq r < b$, assuming the previous\nconstruction of correct chains for $r$, $b$ and $q$.\nFor instance, Figure~\\ref{fig:K7-3-decomposition} shows how \\texttt{K7\\_3} is built\nas a composition of \\texttt{K3\\_1} and \\texttt{F2}.\n\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (entree) at (-0.4,0) {};\n  \\draw [dashed] (1,-0.5) rectangle (2,0.5);\n  \\node at (1.5,0){$K3\\_1$};\n  \\draw [>-,   thick](entree) -- (1,0) node [at start, above] {\\tiny{$x$}};\n  \\node (sortiex3) at (2,0) {};\n  \\node (sortiex) at (2,0.4) {};\n  \\draw [dashed] (4.5,-0.5) rectangle (5.5,0.5);\n\n  \\node at (5,0){$F2$};\n  \\node (entreeF2) at (4.5,0) {};\n\\node (sortieF2) at (5.5,0) {};\n  \\draw[->, ] (sortiex3) -- (entreeF2) \n       node [midway, above] {\\tiny{$x^3$}};\n  \\node (sortiex3global) at (7,1) {};\n  \\node (sortiex3global) at (8.4,1)  {};\n  \\draw [->, thick, bend left] (3.6,0) -- (4,0.6) -- (5,1) --  node [at end, above]\n {\\tiny{$x^3$}} (sortiex3global) ;\n  \\node (join) at (7,0) {$\\times$};\n  \\draw [->, ] (sortieF2) -- (join)\n    node [midway, above] {\\tiny{$x^6$}};\n\\draw [->, bend left] (sortiex) to node [midway, above] {\\tiny{$x$}} (join);\n    \n \\draw [->,   thick](join) -- (8.4,0) node [at end, above] {\\tiny{$x^7$}};\n% \\draw [->,   thick](sortiex3global) --  (8.4,1);\n\\draw  [dashed] (0.5,-0.7) rectangle (7.5,1.4);\n  \\end{tikzpicture}\n  \\caption{Decomposition of  \\texttt{K7\\_3}}\n  \\label{fig:K7-3-decomposition}\n\\end{figure}\n\n\\subsubsection{Conversion from k-chains into f-chains}\n\nAny k-chain for $n$ and $p$ can be converted into an f-chain, just by applying it to a continuation that \nignores its second argument.\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n\\node (input) at (-0.5,0){};\n\\node(inputkc) at (1.5,0){};\n\\node(outputkc1) at (2.5,0){};\n\\node(outputkc2) at (2.5,0.4){};\n\\node (ignore) at (3,0.4){{$\\circ$}};\n\\node (output) at (4.4,0){};\n\\draw [dashed] (1.2,-0.5) rectangle (2.5,0.5) ;\n\\draw [dashed] (0.5,-0.7) rectangle (3.3,0.8) ;\n\\node (knp) at (2,0) {$k_{n,p}$};\n\\draw[>->] (input) -- node [near start, above] {\\tiny{$x$}} (inputkc);\n\\draw[thick, ->,>=latex] (outputkc1) +(-0.1,0) -- (output) node [near end,above] {\\tiny{$x^n$}};\n\\draw[thick] (outputkc2) +(-0.1,0)  -- (ignore);\n\\end{tikzpicture}\n  \\caption{The \\texttt{K2F (knp)} construction}\n  \\label{fig:K2F}\n\\end{figure}\n\n\\inputsnippets{Euclidean_Chains/K2FDef}\n\\inputsnippets{Euclidean_Chains/K2FCorrect}\n\\inputsnippets{Euclidean_Chains/K2FProper}\n\n\\subsubsection{Construction associated with Euclidean division with a positive rest}\n\nLet $n=bq+r$, with $0<r<b$. Then, for any $x$,  $x^n= (x^{b})^q \\times x^r$. Thus, we can \ncompose an chain that computes $x^b$ and $x^r$ with a chain that raises\nany $y$ to its $q$-th power for obtaining a chain that computes $x^n$.\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (entree) at (-0.4,0) {};\n  \\draw [dashed] (1,-0.5) rectangle (2,0.5);\n  \\node at (1.5,0){$K_{b,r}$};\n  \\draw [>-,   thick](entree) -- (1,0) node [above, near start] {\\tiny{$x$}};\n  \\node (sortiex3) at (2,0) {};\n  \\node (sortiex) at (2,0.4) {};\n  \\draw [dashed] (4.5,-0.5) rectangle (5.5,0.5);\n  \\node at (5,0){$F_q$};\n  \\node (entreeF2) at (4.5,0) {};\n\\node (sortieF2) at (5.5,0) {};\n  \\draw[->, ] (sortiex3) -- (entreeF2) \n       node [midway, above] {\\tiny{$x^b$}};\n  %\\node (sortiex3global) at (7,1) {};\n  \\node (sortiex3global) at (7,1)  {};\n  \\draw [->, , bend left] (3.6,0) -- (4,0.6) -- (5,1) -- node [near end, above] {\\tiny{$x^b$}} (8.7,1)  ;\n  \\node [draw] (multipl) at (7,0) {$\\times$};\n\\draw [->] (2,0.4) to (3,1.5) -- node [midway,above] {\\tiny{$x^r$}} (6,1.5) to (multipl);\n  \\draw [->, ] (sortieF2)  -- (multipl)   node [midway, above] {\\tiny{$x^{bq}$}};\n \\draw [->,   thick](multipl) -- (8.7,0) node [above, near end] {\\tiny{$x^{bq+r}$}};\n\\draw  [dashed] (0.5,-0.7) rectangle (7.5,2);\n  \\end{tikzpicture}\n  \\caption{The KFK combinator}\n  \\label{fig:KFK}\n\\end{figure}\n\n\\inputsnippets{Euclidean_Chains/KFKDef}\n\\inputsnippets{Euclidean_Chains/KFKCorrect}\n\\inputsnippets{Euclidean_Chains/KFKProper}\n\n%\\subsection{More certified operators on chains}\n\n\\subsubsection{Ignoring the remainder}\n\nLet $n=bq+r$, with $0<r<b$. The following construction computes\n$x^r$ and $x^b$, then $x^{bq}$, and finally sends $x^{bq+r}$ to the continuation,\nthrowing away $x^b$.\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (entree) at (-0.4,0) {};\n  \\draw [dashed] (1,-0.5) rectangle (2,0.5);\n  \\node at (1.5,0){$K_{b,r}$};\n  \\draw [>-,   thick](entree) -- (1,0) node [above, near start] {\\tiny{$x$}};\n  \\node (sortiex3) at (2,0) {};\n  \\node (sortiex) at (2,0.4) {};\n  \\draw [dashed] (4.5,-0.5) rectangle (5.5,0.5);\n  \\node at (5,0){$F_q$};\n  \\node (entreeF2) at (4.5,0) {};\n\\node (sortieF2) at (5.5,0) {};\n  \\draw[->, ] (sortiex3) -- (entreeF2) \n       node [midway, above] {\\tiny{$x^b$}};\n  %\\node (sortiex3global) at (7,1) {};\n  %\\node (sortiex3global) at (7,1)  {};\n  % \\draw [->, , bend left] (3.6,0) -- (4,0.6) -- (5,1) -- node [near end, above] {\\tiny{$x^b$}} (8.7,1)  ;\n  \\node [draw] (multipl) at (7,0) {$\\times$};\n\\draw [->] (2,0.4) to (3,1.5) -- node [midway,above] {\\tiny{$x^r$}} (6,1.5) to (multipl);\n  \\draw [->, ] (sortieF2)  -- (multipl)   node [midway, above] {\\tiny{$x^{bq}$}};\n \\draw [->,   thick](multipl) -- (8.7,0) node [above, near end] {\\tiny{$x^{bq+r}$}};\n\\draw  [dashed] (0.5,-0.7) rectangle (7.5,2);\n  \\end{tikzpicture}\n  \\caption{The KFF combinator}\n  \\label{fig:KFF}\n\\end{figure}\n\n\n\\inputsnippets{Euclidean_Chains/KFFDef}\n\\inputsnippets{Euclidean_Chains/KFFCorrect}\n\\inputsnippets{Euclidean_Chains/KFFProper}\n\n\\subsubsection{Conversion of an f-chain into a k-chain}\nThe following conversion is useful when a chain generation algorithm\nneeds to build a k-chain for exponents $p$ and $1$:\n\n\\inputsnippets{Euclidean_Chains/FKDef}\n\nLike our other combinators, \\texttt{FK} respects chain correctness and properness.\n\n\n\\subsubsection{Computing $x^p$ \\emph{and} $x^{pq}$}\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (entree) at (-0.4,0) {};\n  \\draw [dashed] (1,-0.5) rectangle (2,0.5);\n  \\node at (1.5,0){$F_p$};\n  \\draw [>-,   thick](entree) -- (1,0) node [above, near start] {\\tiny{$x$}};\n  \\node (sortiexp) at (2,0) {};\n  \\draw [dashed] (4.5,-0.5) rectangle (5.5,0.5);\n  \\node at (5,0){$F_q$};\n  \\node (entreeF2) at (4.5,0) {};\n\\node (sortieF2) at (5.5,0) {};\n  \\draw[->, ] (sortiex3) -- (entreeF2) \n       node [midway, above] {\\tiny{$x^p$}};\n  \\draw [->, , bend left] (3.6,0) -- (4,0.6) -- (5,1) -- node [near end, above] {\\tiny{$x^p$}} (7.7,1)  ;\n \\draw [->,   thick](sortieF2) -- (7.7,0) node [above, near end] {\\tiny{$x^{pq}$}};\n\\draw  [dashed] (0.5,-0.7) rectangle (6.5,2);\n  \\end{tikzpicture}\n  \\caption{The FFK combinator}\n  \\label{fig:FFK}\n\\end{figure}\n\nOur last combinator composes a chain for computing $x^p$ with a chain for computing $x^q$ to build a chain for\ncomputing $x^p$ and $x^{pq}$.\n\n\\inputsnippets{Euclidean_Chains/FFKDef}\n\\inputsnippets{Euclidean_Chains/FFKCorrect}\n\\inputsnippets{Euclidean_Chains/FFKProper}\n\n\\subsubsection{A correct-by-construction chain}\n\nA simple example will show us how to build correct chains \nfor any positive exponent, using the operators above.\n\n\\inputsnippets{Euclidean_Chains/HintKchains}\n\\inputsnippets{Euclidean_Chains/F87}\n\\inputsnippets{Euclidean_Chains/F87Correct}\n\nNote that this method of construction still requires some  \ninteraction from the user. \nIn the next section, we build a \\emph{function} that maps any \npositive number $n$ into a correct and proper chain for $n$.\nThus correct chain generation will be fully automated.\n\n\\subsection{Automatic chain generation by Euclidean division}\n\nThe goal of this section is to write a function \n\\texttt{make\\_chain (p:positive): chain} that builds a correct chain for $p$, using\nthe Euclidean method above. In other words, we want to get correct chains\nby computation. The correctness of the result of this computation should be\nasserted by a  theorem:\n\n\\begin{Coqsrc}\nTheorem make_chain_correct : \n   forall p, chain_correct p (make_chain p).  \n\\end{Coqsrc}\n\n\nIn the previous section, we  considered two different kinds of objects:\nf-chains, associated with a single exponent, and k-chains, associated with two exponents. We would expect that the function \\texttt{make\\_chain} we want to define and certify is structured as a pair of mutually recursive functions.\n In \\coq{} , various ways of building such functions are available:\n \\begin{itemize}\n \\item Structural [mutual] recursion with \\texttt{Fixpoint}\n \\item  Using \\texttt{Program Fixpoint}\n \\item Using   \\texttt{Function}.\n \\end{itemize}\n\nSince our construction is based on Euclidean division, we could not\ndefine our chain generator by structural recursion. \nFor simplicity's sake, we chose to avoid dependent elimination\n and used \\texttt{Function}  with a decreasing measure.\n\n For this purpose, we define a single data-type for associated with\n the generation of F- and K-chains.\n\n\nWe had two slight technical problems to consider:\n\\begin{itemize}\n\\item The generation of a k-chain for $n$ and $p$ is meaningful only if $p < n$. Thus, in order to avoid a clumsy  dependent pattern-matching, we chose to represent\n     a pair $(n,p)$ where $0<p<n$ by a pair of positive numbers $(p,d)$ where \n     $d=n-p$\n\\item In order to avoid to deal explicitly with mutual recursion, we\n     defined a type called \\texttt{signature} for representing both\n     forms of function calls.\n     Thus, it is easy to define a decreasing measure on type \n     \\texttt{signature} for proving termination. \n    Likewise, correctness and properness statements are also indexed by \n    this type.\n\n\\end{itemize}\n\n\\inputsnippets{Euclidean_Chains/signature}\n\nThe following dependently-typed functions will help us to specify  formally\nany correct chain generator.\n\\index{coq}{Dependently typed functions}\n\n\\inputsnippets{Euclidean_Chains/dependentlyTypedFuns}\n\n\\subsection{Generation of chains using Euclidean Division}\n\nAssume we want to build automatically a correct  f-chain for some \npositive integer $n$.\nIf $n$ equals to $1$, $3$, or $2^p$ for some positive integer  $p$,\nthis task is immediate, thanks to the constants \\texttt{F1}, \n\\texttt{F3} and \\texttt{Fexp2}.\nOtherwise, like in \\cite{DBLP:journals/ita/BrlekCHM95}, we decompose \n$n$ into $bq+r$, where $1<b<n$, and compose the recursively built\nchains for $q$ and $r$ on one side, and $q$ on the other side.\n\nThe efficiency of this method depends on the choice of $b$.\nIn \\cite{DBLP:journals/ita/BrlekCHM95}, the function that maps $n$ into $b$\nis called a \\emph{strategy}. \n\n\\vspace{4pt}\n\\noindent\nFrom ~\\href{../theories/html/additions.Strategies.html}{additions.Strategies}.\n\n\\inputsnippets{Strategies/StrategyDef}\n\n\\subsection{The dichotomic strategy}\n\n\nIn this chapter, we concentrate\non the so-called \\emph{dichotomic strategy}, defined as follows:\n\n$$n \\mapsto  n \\div {2^k} \\,\\textbf{where}\\, k=\\floor{(\\log_2{n})/2}$$\n\nIntuitively, it corresponds to splitting the binary representation of a positive\ninteger into two halves. For instance, consider $n=87$ its binary representation\nis \\texttt{1010111}. The number $\\floor{(\\log_2{n})/2}$ is equal to $3$.\nDividing $n$ by $2^3$ gives the decomposition $n=10 \\times 2^3 + 7$.\nThus, a chain for $n=87$ can be built from a chain computing both $x^7$ and $x^{10}$,\nand a chain that raises its argument to its $8-th$ power.\n\n\nThis strategy is defined in Module ~\\href{../theories/html/additions.Dichotomy.html}{additions.Dichotomy}.\n\n\\inputsnippets{Dichotomy/dichotomy}\n\\inputsnippets{Dichotomy/DichoStrat}\n\n\\subsection{Other strategies}\nFor comparison's sake, we define two other strategies, much simpler but statically less efficient than the dichotomic strategy.\n\n\\emph{From Module~\\href{../theories/html/additions.BinaryStrat.html}{additions.BinaryStrat}.}\n\n\\inputsnippets{BinaryStrat/BinaryStrats}\n\nPage.~\\pageref{sect:test-strat}, we compare the three strategies with respect to the length of the built chains.\n\n\\subsection{Main chain generation function}\nWe are now able to define a function that generates a correct chain \nfor any signature. We use the \\texttt{Recdef} module of Standard Library,\nwith an appropriate \\emph{measure}.\n\n\\inputsnippets{Euclidean_Chains/GammaContext}\n\n\n\nThe following function definition generates 9 proof obligations subgoals,\nfor proving that the measure on signatures is strictly decreasing along\nthe recursive calls. They are solved with the help of Standard Library's lemmas \non arithmetic of \\texttt{positive} numbers and Euclidean division.\n\n\\inputsnippets{Euclidean_Chains/chainGen}\n\\inputsnippets{Euclidean_Chains/makeChain}\n\\inputsnippets{Euclidean_Chains/makeChainCorrect}\n\\inputsnippets{Euclidean_Chains/C87Dicho}\n\n\\subsubsection{A few tests}\n\\label{sect:test-strat}\n\nThe following tests show various examples of chains for the same exponent, using different strategies. The dichotomic strategy seems clearly to be the winner (at least on this sample)\\footnote{For efficiency's sake, we commented out some (very) long computations. You may uncomment them freely in your own copy. For the same reason, we put a verbatim trace instead of \\textit{Alectryon} output}.\n\n\\begin{Coqsrc}\nCompute chain_length (make_chain two 56789).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 25%nat : nat  \n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute chain_length (make_chain half 56789).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = 25%nat : nat\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute chain_length (make_chain dicho 56789).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 21%nat : nat \n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute chain_length (make_chain two 3456789).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 33%nat : nat\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute chain_length (make_chain half 3456789).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n(= 33%nat : nat\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute chain_length (make_chain dicho 3456789).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 29%nat : nat\n\\end{Coqanswer}\n\n\n\\subsubsection{Correctness of the Euclidean chain generator}\n\n\\texttt{Recdef}'s \\texttt{functional induction} tactic allows us to\nprove that every value returned by (\\texttt{chain\\_gen $s$}) is correct w.r.t. \n\\texttt{$s$} and proper.\nThe proof obligations are solved thanks to the previous lemmas on \nthe composition operators on chains: \\texttt{Fcompose}, \\texttt{KFK}, etc.\nUnfortunately, a lot of interaction is still needed for proving properties of\nEuclidean division and binary logarithm. \n\n\n\\inputsnippets{Euclidean_Chains/chainGenOK}\n\n\n\\subsubsection{A last example}\n\\label{ex45319}\n\nLet us compute  $67777^{6145319}$ with 32 bits integers:\n\n\\begin{Coqsrc}\n\nLtac compute_chain ch := \n   let X := fresh \"x\" in \n   let Y := fresh \"y\" in\n   let X := constr:ch in \n   let Y := (eval vm_compute in X) in \n   exact Y.\n\nLet big_chain := ltac:(compute_chain  (make_chain 6145319)).\n\nPrint big_chain.\n\\end{Coqsrc}\n\n\n\\begin{Coqanswer}\nbig_chain = \nfun (A : Type) (x : A) =>\nx0 <--- x times x; x1 <--- x0 times x0;\nx2 <--- x1 times x1; x3 <--- x2 times x1;\nx4 <--- x3 times x3; x5 <--- x4 times x;\nx6 <--- x5 times x5; x7 <--- x6 times x6;\nx8 <--- x7 times x1; x9 <--- x8 times x5;\nx10 <--- x9 times x8; x11 <--- x10 times x9;\nx12 <--- x11 times x11; x13 <--- x12 times x11;\nx14 <--- x13 times x10; x15 <--- x14 times x14;\nx16 <--- x15 times x11; x17 <--- x16 times x16;\nx18 <--- x17 times x17; x19 <--- x18 times x18;\nx20 <--- x19 times x19; x21 <--- x20 times x20;\nx22 <--- x21 times x21; x23 <--- x22 times x22;\nx24 <--- x23 times x23; x25 <--- x24 times x24; \nx26 <--- x25 times x25; x27 <--- x26 times x26; \nx28 <--- x27 times x14;  Return x28\n     : forall A : Type, A -> computation\n\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nTime   Compute  Int31.phi \n     (chain_apply big_chain (snd (positive_to_int31  67777))).\n\\end{Coqsrc}\n\\begin{Coqanswer}\n= 2014111041%Z\n     : Z\nFinished transaction in 0.005 secs (0.005u,0.s) (successful)}  \n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute chain_length big_chain.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 29%nat\n     : nat  \n\\end{Coqanswer}\n\n\n\n\\subsection{Fibonacci, \\emph{le retour}}\n\\label{sect:fibonacci-euclidean}\n\nIt is now possible to use Euclidean addition chains for computing Fibonacci numbers\n(see Sections~\\vref{sect:fibonacci-mul2} and~\\vref{sect:fibonacci-pos-bpow}).\n\nThe following function is parameterized by any strategy $\\gamma$.\n\n\\begin{Coqsrc}\nDefinition fib_eucl gamma `{Hgamma: Strategy gamma} n :=\n  let c := make_chain gamma  n\n  in let r := chain_apply c (M:=Mul2) (1,0) in\n       fst r + snd r.\n\nCompute fib_eucl dicho 153.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n    = 68330027629092351019822533679447\n     : N\nFinished transaction in 0.002 secs (0.002u,0.s) (successful)\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute fib_eucl two 153.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n    = 68330027629092351019822533679447\n     : N\nFinished transaction in 0.003 secs (0.003u,0.s) (successful)\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute fib_eucl half 153.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n    = 68330027629092351019822533679447\n     : N\nFinished transaction in 0.003 secs (0.003u,0.s) (successful)\n\\end{Coqanswer}\n\n\n\\section{Projects}\n\n\\index{additions}{Projects}\n\\begin{project}[Optimality and relative efficiency]\n\n\\vspace{3pt}\n\n\\noindent\n\n\\begin{enumerate}\n\\item  Prove that the chain generated by \\texttt{Fexp2} is optimal.\n\\item Prove that  the length of any optimal chain for $n$ is\ngreater than or equal to $\\floor{\\log_2{n}}$.\n\\item Prove that, for any positive $n$, the length of any Euclidean chain generated by the \n  dichotomic strategy  is always less than or equal to\n  the length of \\texttt{binary\\_chain $n$}, and for an infinite number\nof positive integers $n$, the first chain  is strictly shorter\nthan  the latter.\n\\item Prove that our implementation of the dichotomic strategy describes\n the same function as in the literature (for instance ~\\cite{DBLP:journals/ita/BrlekCHM95}.)\nThis is important if we want to follow the complexity analyses in this and similar articles.\n\\item Study how to \\emph{compile} a chain into imperative code, using a register allocation strategy (it may be useful  to define \\emph{chain width} ).\n\n\\paragraph*{Remark:} The first two questions of the list above should involve a \nuniversal quantification on type\n\\texttt{chain}. It may be necessary (but we're not sure) to consider  some \nrestriction on parametric chains.\n\n\\end{enumerate}\n\\end{project}\n\n\\subsection{A data structure for Euclidean chains}\n\n\nFigures~\\vref{fig:F3-as-dag} to \\vref{fig:FFK} suggest that any computation following an Euclidean chain can be executed on a kind  of abstract machine with a \"register'' and a stack, and only four operations:\n\\begin{itemize}\n\\item multiply the contents of the register by the top of the stack (and pop that stack),\n\\item raising the contents of the register to its square,\n\\item push the contents of the register into the stack,\n\\item swapping the two elements at the top of the stack.\n\\end{itemize}\n\nIn \\coq{}, we define the instructions as the four constructors of an inductive type.\n\nFrom Module~\\href{../theories/html/additions.AM.html}{additions.AM}\n\n\\inputsnippets{AM/AMDef}\n\\inputsnippets{AM/AMSem}\n\\inputsnippets{AM/AMSemb}\n\nFor instance the chain of Fig.~\\vref{fig:C87} can be represented with the following code:\n\n\\inputsnippets{AM/F87}\n\n\nIn the library~\\href{../theories/html/additions.AM.html}{additions.AM},\nwe define a chain generator for this data structure. \nPlease note that many proof scripts are copied verbatim from \n\\texttt{Euclidean\\_Chains} into \\texttt{AM}. Removing such redundancies is left as a project.\n\n\n\n\\begin{project}[Some improvements]\n \\begin{enumerate}\n\\item Improve automated proofs on types \\texttt{positive} and \\texttt{N}.\n\\item Compare  \\texttt{Program Fixpoint} and \\texttt{Function} for\nwriting \\texttt{make\\_chain}. Consider measure \\emph{vs} well-founded \nrelations, mutual recursion, possibility of using sigma-types, etc.\n\\item Chains are always associated with strictly positive exponents. \nThus, many lemmas about chain correctness  can be proved using semi-groups instead of\nmonoids. Define type classes for semi-groups and use them whenever possible.\n\\end{enumerate}  \n\\end{project}\n\n\n% \\end{project}\n\n\n\n\n\n% \\section{Exponentiation in \\coq's standard library}\n\n% Exponentiation is already defined for several types in Standard Library\\footnote{The following information was checked according to \\texttt{8.5beta2} version of \\coq{}.}\n\n% \\subsection{Peano numbers}\n% Exponentation is defined in \\texttt{Coq.Init.Nat} as a binary operation on type nat. Basically, it is a structurally recursive definition with respect \n% to its second argument.\n\n% \\begin{verbatim}\n% Fixpoint pow n m :=\n%   match m with\n%     | 0 => 1\n%     | S m => n * (n ^ m)\n%   end\n\n% where \"n ^ m\" := (pow n m) : nat_scope.\n% \\end{verbatim}\n\n\n% \\subsection{Binary positive numbers}\n% Exponentiation is defined in \\texttt{Coq.PArith.BinPosDef} as a binary operation on type \\texttt{positive}.\n% Its definition uses a polymorphic functional that allows to iterate \n% a unary function on any type $A$.\n\n% \\begin{verbatim}\n% Definition iter {A} (f:A -> A) : A -> positive -> A :=\n%   fix iter_fix x n := match n with\n%     | xH => f x\n%     | xO n' => iter_fix (iter_fix x n') n'\n%     | xI n' => f (iter_fix (iter_fix x n') n')\n%   end.\n\n% (** ** Power *)\n\n% Definition pow (x:positive) := iter (mul x) 1.\n\n% Infix \"^\" := pow : positive_scope.\n% \\end{verbatim}\n\n% Although the definition of \\texttt{iter} takes advantage of the binary\n% representation of \\texttt{n}, the computation of some $x^n$ amounts\n% to $n$ iterations of the function \\texttt{(mul x)}. Thus, the function\n% \\texttt{Pos.pow} is linear with respect to the exponent.\n\n\n% \\begin{alltt}\n% Time Compute Pos.pow 1\\%positive 56666667\\%positive.\\it\n% Finished transaction in 5.679 secs (5.693u,0.s) (successful)\n% \\end{alltt}\n\n% \\subsection{Binary integers}\n\n% Types \\texttt{N} [resp. \\texttt{Z}] are also provided with binary operations\n% that allow to compute $x^n$ (for $x,n$ of type \\texttt{N} [resp.   \\texttt{Z}].\n\n% In \\texttt{Coq-8.5beta2}, the functions \\texttt{Coq.NArith.BinNat.N.pow}\n% and \\linebreak \\texttt{Coq.ZArith.BinInt.Z.pow} are also defined as iterations\n% of \\texttt{(mul x)} using the same iteration functional as for the \\texttt{positive} type. Thus they are also linear with respect to the exponent.\n\n\n\n\n\n\n", "meta": {"hexsha": "aa37cf54538dbf15dd86087af9d96fbe025005ce", "size": 101678, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/chapter-powers.tex", "max_stars_repo_name": "cpitclaudel/hydra-battles", "max_stars_repo_head_hexsha": "07c9568224a49a7d7d04468c0208664ad042a859", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/chapter-powers.tex", "max_issues_repo_name": "cpitclaudel/hydra-battles", "max_issues_repo_head_hexsha": "07c9568224a49a7d7d04468c0208664ad042a859", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/chapter-powers.tex", "max_forks_repo_name": "cpitclaudel/hydra-battles", "max_forks_repo_head_hexsha": "07c9568224a49a7d7d04468c0208664ad042a859", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.3265451947, "max_line_length": 696, "alphanum_fraction": 0.7221817896, "num_tokens": 30773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8633916170039421, "lm_q1q2_score": 0.7137760253064716}}
{"text": "\\section{Extensions of the Euler-Lagrange Equations}\r\n\\subsection{Euler-Lagrange with Constraints}\r\nOur objective is to extremize the functional\r\n$$F[y]=\\int_\\alpha^\\beta f(x,y,y^\\prime)\\,\\mathrm dx$$\r\nsubject to the constraint $G[y]=0$ for a functional $G$ in the form\r\n$$G[y]=\\int_\\alpha^\\beta g(x,y,y^\\prime)\\,\\mathrm dx$$\r\nWe can tackle this by using an analog of Lagrange multiplier.\r\nConsider the new functional\r\n$$\\Phi[y;\\lambda]=F[y]-\\lambda G[y]=\\int_\\alpha^\\beta (f-\\lambda g)(x,y,y^\\prime)\\,\\mathrm dx$$\r\nfrom the study of Lagrange multiplier earlier in the $\\mathbb R^n$ case, we are inspired to extremise $\\Phi$ instead.\r\nThe Euler-Lagrange equation form $\\Phi$ is then\r\n$$\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\partial}{\\partial y^\\prime}(f-\\lambda g)=\\frac{\\partial}{\\partial y}(f-\\lambda g)$$\r\n\\begin{example}[Dido's Problem (aka the Isoperimetric Problem)]\r\n    We want to ask what simple closed plane curve with fixed length $L$ maximises its area.\r\n    We can assume WLOG that the curve is convex and put it on the coordinate plane.\r\n    Then by convexity it is bounded by the lines $x=\\alpha,x=\\beta$ for some $\\alpha,\\beta$.\r\n    Also, for each $x\\in(\\alpha,\\beta)$ there are exactly two values $y=y_1,y_2$, $y_1<y_2$ such that $(x,y)$ is on the curve.\r\n    The area element is then $\\mathrm dA=(y_2-y_1)\\,\\mathrm dx$.\r\n    So the functional we want to maximise is\r\n    $$A[y]=\\int_\\alpha^\\beta y_2-y_1\\,\\mathrm dx=\\oint_Cy\\,\\mathrm dx$$\r\n    subject to the contraint that\r\n    $$L[y]=\\oint_C\\,\\mathrm dl=\\oint_C\\sqrt{1+(y^\\prime)^2}\\,\\mathrm dx$$\r\n    is constantly $L$.\r\n    To use Lagrange multiplier, we set $h=y-\\lambda\\sqrt{1+(y^\\prime)^2}$, then as $h$ does not explicitly depend on $x$, we can use the first integral\r\n    $$K=\\text{const.}=h-y^\\prime\\frac{\\partial h}{\\partial y^\\prime}=y-\\frac{\\lambda}{\\sqrt{1+(y^\\prime)^2}}\\implies (y^\\prime)^2=\\frac{\\lambda^2}{(y-K)^2}-1$$\r\n    Hence,\r\n    $$\\int\\frac{y-K}{\\sqrt{\\lambda^2-(y-K)^2}}\\,\\mathrm dy=x-x_0\\implies (y-y_0)^2+(x-x_0)^2=\\lambda^2$$\r\n    where $x_0,y_0$ are constants.\r\n    This is the equation of a circle, and by the constraint, $\\lambda=L/2\\pi$.\r\n\\end{example}\r\n\\begin{example}[The Sturm-Liouville Problem]\\label{sturm-liouville}\r\n    Let $\\rho=\\rho(x)>0$ for $x\\in [\\alpha,\\beta]$.\r\n    Consider the following functional:\r\n    $$F[y]=\\int_\\alpha^\\beta\\rho(x)(y^\\prime)^2+\\sigma(x)y^2\\,\\mathrm dx$$\r\n    which we want to maximise subject to the condition that\r\n    $$G[y]=\\int_\\alpha^\\beta y^2\\,\\mathrm dx=1$$\r\n    One will see it again and again in the settings of quantum mechanics.\r\n    So our goal is to extremise\r\n    $$\\Phi[y;\\lambda]=F[y]-\\lambda(G[y]-1)$$\r\n    So\r\n    $$h=\\rho(y^\\prime)^2+\\sigma y^2-\\lambda\\left( y^2-\\frac{1}{\\beta-\\alpha} \\right)$$\r\n    The Euler-Lagrange equation is then\r\n    $$-\\frac{\\mathrm d}{\\mathrm dx}(\\rho y^\\prime)+\\sigma y=\\lambda y$$\r\n    We write $\\mathcal L(y)$ to denote the differential operator on the right hand side.\r\n    $\\mathcal L$ is called the Sturm-Liouville operator.\r\n    Viewing it like this, the ODE is now the eigenvalue problem of the operator $\\mathcal L$.\r\n\\end{example}\r\n\\begin{remark}\r\n    If $\\rho=1$, then $\\sigma$ can be taken as the potential which makes the equation the (one-dimensional) time-independent Schr\\\"odinger equation.\r\n\\end{remark}\r\nIf $\\sigma>0$ everywhere, then $F[y]>0$ everywhere.\r\n\\begin{claim}\r\n    We claim that he (positive) mimimum of $F[y]$ is the lowest eigenvalue of $\\mathcal L$.\r\n\\end{claim}\r\n\\begin{proof}\r\n    We multiply the Sturm-Liouville equation by $y$ on both sides and integrate from $\\alpha$ to $\\beta$, which gives $F[y]=\\lambda G[y]$.\r\n\\end{proof}\r\n\\subsection{Several Dependent Variables}\r\nSuppose $\\underline{y}(x)=(y_1(x),\\ldots,y_n(x))$.\r\nWe want to consider the functional\r\n$$F[\\underline{y}]=\\int_\\alpha^\\beta f(x,y_1,\\ldots,y_n,y_1^\\prime,\\ldots,y_n^\\prime)\\,\\mathrm dx$$\r\nSuppose a perturbation $y_i=y_i+\\epsilon \\eta_i$ is incurred for $i=1,\\ldots,n$, $\\epsilon>0$ small and $\\eta_i(\\alpha)=\\eta_i(\\beta)=0$.\r\nThen\r\n$$F[\\underline{y}+\\epsilon\\underline{\\eta}]-F[\\underline{y}]=\\epsilon\\int_\\alpha^\\beta\\sum_{i=1}^n\\eta_i\\left( \\frac{\\mathrm d}{\\mathrm dx}\\frac{\\partial f}{\\partial y_i^\\prime}-\\frac{\\partial f}{\\partial y_i} \\right)\\,\\mathrm dx+O(\\epsilon^2)$$\r\nBy Lemma \\ref{fund_lemma}, we have\r\n$$\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\partial f}{\\partial y_i^\\prime}=\\frac{\\partial f}{\\partial y_i}$$\r\nfor $i=1,\\ldots,n$.\r\nThis is simply just $n$ Euler-Lagrange equations, which are $n$ second-order ODEs.\r\nOf course, we also want to reduce this system of second order ODEs to first integrals whenever possible.\\\\\r\nIf $\\partial f/\\partial y_j=0$ for some $j$, then\r\n$$\\frac{\\partial f}{\\partial y_j^\\prime}=\\text{const.}$$\r\nIf the number of such $j$'s is big enough, we can simplify this a big deal.\\\\\r\nIf $\\partial f/\\partial x=0$, then we have\r\n$$f-\\sum_{i=1}^ny_i^\\prime\\frac{\\partial f}{\\partial y_i^\\prime}=\\text{const.}$$\r\nwhich might help in some cases.\r\n\\begin{example}[Geodesics on Surfaces]\r\n    Consider a surface $\\Sigma\\subset\\mathbb R^3$ given by $g(x,y,z)=0$.\r\n    Pick two points $A,B$ from $\\Sigma$.\r\n    Our aim is to minimize the length of shortest path on $\\Sigma$ which connects $A,B$.\r\n    If such a length exists, then any path with this length is called a geodesics.\r\n    Let $t\\in[0,1]$ be a parameter on the curve and parameterise a curve between $A,B$ by $\\underline{x}(0)=A,\\underline{x}(1)=B$.\r\n    For the curve to lie on the surface, we have the constraint $g(\\underline{x}(t))=0$ for any $t$.\\\\\r\n    So by the idea of Lagrange multiplier, we want to minimise the functional\r\n    $$\\Phi[\\underline{x},\\lambda]=\\int_0^1\\left( \\sqrt{\\dot{x}^2+\\dot{y}^2+\\dot{z}^2} -\\lambda(t) g(x,y,z)\\right)\\,\\mathrm dt$$\r\n    Note that the Lagrange multiplier is now a function $\\lambda=\\lambda(t)$, as our constraint has to be valid for all $t$.\r\n    Write the integrand in $\\Phi$ by $h(x,y,z,\\lambda,\\dot{x},\\dot{y},\\dot{z})$.\r\n    The Euler-Lagrange equation wrt $\\lambda$ is then\r\n    $$\\frac{\\mathrm d}{\\mathrm dt}\\frac{\\partial h}{\\partial \\dot{\\lambda}}-\\frac{\\partial h}{\\partial\\lambda}=0\\implies g(x,y,z)=-\\frac{\\partial h}{\\partial\\lambda}=0$$\r\n    For the rest of the Euler-Lagrange equations, write $(x,y,z)=x_i\\underline{e_i}$, then it becomes\r\n    $$\\frac{\\mathrm d}{\\mathrm dt}\\left( \\frac{\\dot{x}_i}{\\sqrt{\\dot{x}^2+\\dot{y}^2+\\dot{z}^2}} \\right)+\\lambda\\frac{\\partial g}{\\partial x_i}=0$$\r\n    which, for specified $g$, should solve to get us a geodesics.\r\n\\end{example}\r\n\\subsection{Several Independent Variables}\r\nIn general, the parameter of the functional is a function $\\mathbb R^n\\to\\mathbb R^m$.\r\nIf $n>1$, then the Euler-Lagrange equations, as one may expect, become PDEs.\r\nSuppose $n=3$, then the functional can have the form\r\n$$F[\\phi]=\\int_Df(x,y,z,\\phi,\\phi_x,\\phi_y,\\phi_z)\\,\\mathrm dx\\,\\mathrm dy\\,\\mathrm dz$$\r\nwhere $D\\subset\\mathbb R^3$.\r\nAssume $\\phi$ is at an extremum of $F$, then the perturbation we are considering would become\r\n$$\\phi(x,y,z)\\mapsto \\phi(x,y,z)+\\epsilon \\eta(x,y,z), \\epsilon\\in\\mathbb R,\\eta|_{\\partial D}=0$$\r\nSo if we write\r\n$$\\underline{v}=\\left( \\frac{\\partial f}{\\partial \\phi_x},\\frac{\\partial f}{\\partial \\phi_y},\\frac{\\partial f}{\\partial\\phi_z} \\right)$$\r\nthen,\r\n\\begin{align*}\r\n    F[\\phi+\\epsilon\\eta]-F[\\phi]&=\\epsilon\\int_D\\left( \\eta\\frac{\\partial f}{\\partial\\phi}+\\eta_x\\frac{\\partial f}{\\partial \\phi_x}+\\eta_y\\frac{\\partial f}{\\partial \\phi_y}+\\eta_z\\frac{\\partial f}{\\partial \\phi_z} \\right)\\,\\mathrm dx\\,\\mathrm dy\\,\\mathrm dz+O(\\epsilon^2)\\\\\r\n    &=\\epsilon\\int_D\\left( \\eta\\frac{\\partial f}{\\partial\\phi}+\\nabla\\cdot( \\eta\\underline{v})-\\eta\\nabla\\cdot\\underline{v} \\right)\\,\\mathrm dx\\,\\mathrm dy\\,\\mathrm dz+O(\\epsilon^2)\r\n\\end{align*}\r\nBy the Divergence Theorem, we have\r\n$$\\int_D\\nabla\\cdot(\\eta\\underline{v})\\,\\mathrm dx\\,\\mathrm dy\\,\\mathrm dz=\\int_{\\partial D}\\eta\\underline{v}\\cdot\\mathrm d\\underline{S}=0$$\r\nBy the boundary assumption on $\\eta$, therefore\r\n$$\\frac{F[\\phi+\\epsilon\\eta]-F[\\phi]}{\\epsilon}=\\int_D\\eta\\left( \\frac{\\partial f}{\\partial\\phi}-\\nabla\\cdot\\underline{v} \\right)\\,\\mathrm dx\\,\\mathrm dy\\,\\mathrm dz$$\r\nWe obviously have the analogy of Lemma \\ref{fund_lemma} here, hence for $\\delta F=0$, we obtain\r\n$$\\frac{\\partial f}{\\partial\\phi}-\\nabla\\cdot\\underline{v}=0$$\r\nwhich, by expanding $\\underline{v}$, is\r\n$$\\frac{\\partial f}{\\partial\\phi}-\\frac{\\partial}{\\partial x_i}\\frac{\\partial f}{\\partial \\phi_{x_i}}=0$$\r\nwhere the summation is implied by convention.\r\nThis can be generalized from $3$ to $n$ in an obvious way.\r\n\\begin{example}\r\n    We want to extremise the functional of potential energy\r\n    $$F[\\phi]=\\iint_{D\\subset\\mathbb R^2}\\frac{1}{2}(\\phi_x^2+\\phi_y^2)\\,\\mathrm dx\\,\\mathrm dy$$\r\n    Where $\\phi:\\mathbb R^2\\to\\mathbb R$.\r\n    So the Euler-Lagrange equation becomes\r\n    $$\\phi_{xx}+\\phi_{yy}=0$$\r\n    which is the Laplace equation.\r\n\\end{example}\r\n\\begin{example}[Minimal Surfaces]\r\n    We want to minimise the area of a surface $\\Sigma\\subset\\mathbb R^3$ subject to boundary conditions (e.g. specified $\\partial\\Sigma$).\r\n    This can allow us to find the shape of a soap film.\r\n    Suppose we can write $\\Sigma$ as the graph of $z=f(x,y)$ for some function $\\phi$.\r\n    \\footnote{This can always be done locally given that $\\Sigma$ is nice enough due to Implicit Function Theorem.}\r\n    The line element is $\\mathrm ds^2=\\mathrm dx^2+\\mathrm dy^2+\\mathrm dz^2$ and we have $\\mathrm dz=\\phi_x\\,\\mathrm dx+\\phi_y\\,\\mathrm dy$, so\r\n    $$\\mathrm ds^2=(1+\\phi_x^2)\\,\\mathrm dx^2+(1+\\phi_y^2)\\mathrm dy^2+2\\phi_x\\phi_y\\,\\mathrm dx\\,\\mathrm dy$$\r\n    This is called the first fundamental form (or the Riemannian metric) in geometrical settings.\r\n    We can write, in summation notation, $\\mathrm ds^2=g_{ij}(x,y)\\,\\mathrm dx^i\\,\\mathrm dx^j$ with\r\n    $$g=\\begin{pmatrix}\r\n            1+\\phi_x^2&\\phi_x\\phi_y\\\\\r\n            \\phi_x\\phi_y&1+\\phi_y^2\r\n    \\end{pmatrix}$$\r\n    As one can verify, $\\det g\\ge 0$ and $\\sqrt{\\det g}$, so\r\n    $$A[\\phi]=\\iint_D\\sqrt{1+\\phi_x^2+\\phi_y^2}\\,\\mathrm dx\\,\\mathrm dy$$\r\n    Write $h$ to denote the integrand, then we have\r\n    $$\\frac{\\partial h}{\\partial\\phi_x}=\\frac{\\phi_x}{\\sqrt{1+\\phi_x^2+\\phi_y^2}},\\frac{\\partial h}{\\partial\\phi_y}=\\frac{\\phi_y}{\\sqrt{1+\\phi_x^2+\\phi_y^2}}$$\r\n    So, upon some simplification, the Euler-Lagrange equation transforms to\r\n    $$(1+\\phi_y^2)\\phi_{xx}+(1+\\phi_x^2)\\phi_{yy}-2\\phi_x\\phi_y\\phi_{xy}=0$$\r\n    which is known as the minimal surface equation.\\\\\r\n    A particular case of it is when the surface is a surface of revolution, i.e. $z=z(r),r=\\sqrt{x^2+y^2}$.\r\n    We want to solve it subject to the surface's boundary being two equal circles whose centres are on the $z$-axis and are parallel to the $x-y$ plane.\r\n    This initial condition can give us the shape of soap film between two circular loops.\\\\\r\n    In this case, the PDE transforms to\r\n    $$rz^{\\prime\\prime}+z^\\prime+(z^\\prime)^3$$\r\n    by a lot of calculations.\r\n    Write $w=z^\\prime$, then\r\n    $$\\frac{1}{2}r\\frac{\\mathrm dw^2}{\\mathrm dr}+w^2+w^4$$\r\n    which we can integrate to find\r\n    $$r=r_0\\cosh\\left( \\frac{z-z_0}{r_0} \\right)$$\r\n    which is called the catenoid.\r\n    This result was first proved by Euler in 1744.\r\n    Note that being a catenoid is a necessary condition for a minimal surface in this form to exist.\\\\\r\n    Suppose the centres of the circles are located at $L\\underline{e_z}$ and $-L\\underline{e_z}$ and both circles have radius $R$.\r\n    Then $r(L)=r(-L)$, hence if $L\\neq 0$ then $-L-z_0=-L+z_0$, thus $z_0=0$.\r\n    Therefore $R=r_0\\cosh(L/r_0)$.\r\n    But $r_0$ is then the radius of the circle as the intersection between the surface and the $x-y$ plane.\r\n    WLOG set $L=1$ (as we can scale the whole thing), then by a simple plot we obtain that $R\\ge c$ globally for some $c>0$.\r\n    By estimation the minimum occurs at $r_0\\approx 0.833$ and $c\\approx 1.5$.\r\n    Also, for $R>c$, we see that there are two possible values of $r_0$, which corresponds to two minimal surfaces.\r\n    After our latter discussion on second variations, we find that the thinner one of which is unstable and the thicker one is stable.\r\n\\end{example}\r\nThe case where $R$ is less than the threshold exhibits an example where there is no solution.\r\n\\subsection{Higher Derivatives}\r\nWe want to generalise the theory to a wider range of functionals, specifically in the form\r\n$$F[y]=\\int_\\alpha^\\beta f(x,y,y^\\prime,\\ldots,y^{(n)})\\,\\mathrm dx$$\r\nAssume such an $y$ that extremises $F$ exists, then consider the perturbation $y\\mapsto y+\\epsilon\\eta$ where $\\eta,\\eta^\\prime,\\ldots,\\eta^{(n-1)}$ all vanishes at $\\alpha,\\beta$, then by the higher-dimensional Taylor expansion,\r\n$$F[y+\\epsilon\\eta]-F[y]=\\epsilon\\int_\\alpha^\\beta\\left( \\frac{\\partial f}{\\partial y}\\eta+\\cdots +\\frac{\\partial f}{\\partial y^{(n)}}\\eta^{(n)} \\right)\\,\\mathrm dx+O(\\epsilon^2)$$\r\nBy integration by part,\r\n$$\\int_\\alpha^\\beta\\frac{\\partial f}{\\partial y^{(i)}}\\eta^{(i)}\\,\\mathrm dx=\\int_\\alpha^\\beta\\eta(-1)^i\\frac{\\mathrm d^i}{\\mathrm dx^i}\\frac{\\partial f}{\\partial y^{(i)}}\\,\\mathrm dx$$\r\nDue to our boundary conditions on $\\eta$.\r\nHence\r\n$$\\frac{F[y+\\epsilon\\eta]-F[y]}{\\epsilon}=\\int_\\alpha^\\beta \\eta\\left(\\frac{\\partial f}{\\partial y}+\\sum_{i=1}^n(-1)^i\\frac{\\mathrm d^i}{\\mathrm dx^i}\\frac{\\partial f}{\\partial y^{(i)}}\\right)\\,\\mathrm dx+O(\\epsilon)$$\r\nHence by Lemma \\ref{fund_lemma}, we obtain the Euler-Lagrange equation in the following form:\r\n$$\\frac{\\partial f}{\\partial y}+\\sum_{i=1}^n(-1)^i\\frac{\\mathrm d^i}{\\mathrm dx^i}\\frac{\\partial f}{\\partial y^{(i)}}=0$$\r\n\\begin{example}[First Integral]\r\n    If $n=2$ and $f$ does not explicitly depend on $y$, the equation becomes\r\n    $$\\frac{\\mathrm d}{\\mathrm dx}\\left( \\frac{\\partial f}{\\partial y^\\prime}-\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\partial f}{\\partial y^{\\prime\\prime}} \\right)=0\\implies \\frac{\\partial f}{\\partial y^\\prime}-\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\partial f}{\\partial y^{\\prime\\prime}}=\\text{const.}$$\r\n\\end{example}\r\n\\begin{example}\r\n    If we want to extremise\r\n    $$F[y]=\\int_0^1(y^{\\prime\\prime})^2\\,\\mathrm dx$$\r\n    with $y(0)=y(1)=y^\\prime(0)=0$ and $y^\\prime(1)=1$.\r\n    Then the first integral above reduces to\r\n    $$\\frac{\\mathrm d}{\\mathrm dx}(2y^{\\prime\\prime})=\\text{const.}\\implies y^{(3)}=\\text{const.}$$\r\n    which solves to $y=x^3-x^2$ for the specified boundary conditions.\r\n\\end{example}\r\nNote that the $y_0$ in the previous example is actually an absolute minimum of the functional $F$.\r\nTo argue this, observe that for an arbitrary $C^2$ function $\\eta$ with $\\eta,\\eta^\\prime$ both vanish at $0,1$ but $\\eta$ is not identically zero.\r\nThen\r\n\\begin{align*}\r\n    F[y_0+\\eta]-F[y_0]&=\\int_0^1(\\eta^{\\prime\\prime})^2\\,\\mathrm dx+2\\int_0^1 y_0^{\\prime\\prime}\\eta^{\\prime\\prime}\\,\\mathrm dx\\\\\r\n    &>4\\int_0^1(3x-1)\\eta^{\\prime\\prime}\\\\\r\n    &=0\r\n\\end{align*}\r\nthrough integration by part.\r\nHence $y$ is the global minimum in our chosen space $C^2[0,1]$.\r\nThis trick does not always work, but sometimes it does, like the one we just did.", "meta": {"hexsha": "7399091351664f8dfc914f172accdd1a57257df6", "size": 15015, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/ext.tex", "max_stars_repo_name": "david-bai-notes/IB-Variational-Principles", "max_stars_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3/ext.tex", "max_issues_repo_name": "david-bai-notes/IB-Variational-Principles", "max_issues_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3/ext.tex", "max_forks_repo_name": "david-bai-notes/IB-Variational-Principles", "max_forks_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.9655172414, "max_line_length": 295, "alphanum_fraction": 0.6703296703, "num_tokens": 4935, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117898012104, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.713776020274814}}
{"text": "\\section{K-D Trees and Nearest Neighbors}\n\n\\paragraph{Consistency heuristic} Whenever you want to guess a\nproperty of something, given nothing else to go on but a set of\nreference cases, find the most similar case, as measured by known\nproperties, for which the property is known. Guess that the\nunknown property is the same as that known property.\n\n\\paragraph{Decision tree} A decision tree is a representation,\nthat is a semantic tree in which:\n\\begin{itemize}\n  \\item Each node is connected to a set of possible answers\n  \\item Each nonleaf noed is connected to a test that splits its\n    set of possible answers into subsets corresponding to\n    different test results\n  \\item Each branch carries a particular test result's subset to\n    another node\n\\end{itemize}\n\n\\paragraph{k-d tree} A k-d tree is a representation,\nthat is a decision tree in which:\n\\begin{itemize}\n  \\item The set of possible answers consists of points, one of\n    which may be the nearest neighbor to a given point\n  \\item Each test specifies a coordinate, a threshold, and a\n    neutral zone around the threshold containing no points\n  \\item Each test divides a set of points into two sets, according\n    to on which sid of the threshold each point lies\n\\end{itemize}\n\nHow to divide the cases into sets:\n\\begin{itemize}\n  \\item If there is only one case, stop\n  \\item If this is the first division of cases, pick the vertical\n    axis for comparison; otherwise, pick the axis that is\n    different from the axis at the next higher level\n  \\item Considering only the axis of comparison, find the average\n    position of the two middle objects. Call this average position\n    the threshold, and construct a decision-tree test that\n    compares unknowns in the axis of comparison againsts the\n    threshold. Also note the position of the two middle obkects in\n    the axis of comparison. Call these positions the upper and\n    lower boundaries\n  \\item Divide up all the obects into two subsets, accorting to on\n    which side of the average position they lies\n  \\item Divide up thw objects in each subset, forming a subtree\n    for each, using this procedure\n\\end{itemize}\n\nTo find the nearest neighbor using the K-D procedure:\n\\begin{itemize}\n  \\item Determine whether there is only one element in the set\n    under consideration\n  \\begin{itemize}\n    \\item If there is only one, report it\n    \\item Otherwise, compare the unknown, in the axis of\n      comparison, against the current node's threshold. The result\n      determines the likely set\n    \\item Find the nearest neighbor in the likely set using this\n      procedure\n    \\item Determine whether the distance to the nearest neighbor\n      in the likely set is less than or equal to the distance to\n      the other set's boundary in the axis of comparison:\n      \\begin{itemize}\n        \\item If it is, then report the nearest neighbor in the\n          likely set\n        \\item If it is not, check the unlikely set using this\n          procedure; return the nearer of the nearest neighbors in\n          the likely set and in the unlikely set\n      \\end{itemize}\n  \\end{itemize}\n\\end{itemize}\n\n\n\n", "meta": {"hexsha": "42883eb51b9695348e4f456260c313bf2ade26ff", "size": 3128, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "kd_trees.tex", "max_stars_repo_name": "Calcifer777/mit-6034", "max_stars_repo_head_hexsha": "9a0939aba7fa3bba0339c4f30f716b41b3bc878b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "kd_trees.tex", "max_issues_repo_name": "Calcifer777/mit-6034", "max_issues_repo_head_hexsha": "9a0939aba7fa3bba0339c4f30f716b41b3bc878b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "kd_trees.tex", "max_forks_repo_name": "Calcifer777/mit-6034", "max_forks_repo_head_hexsha": "9a0939aba7fa3bba0339c4f30f716b41b3bc878b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.1578947368, "max_line_length": 66, "alphanum_fraction": 0.7442455243, "num_tokens": 726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733983715524, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7137496845696256}}
{"text": "\\subsection{Critical Points}\r\n\\noindent\r\nCritical points are those that have the possibility of being a minimum or maximum.\r\nThey are an extension of critical points in single-variable calculus when the derivative is 0.\\\\\r\n\r\n\\noindent\r\n\\begin{definition}\r\n\t$(x_0, y_0)$ is a critical point of $f$ if $f_x$ and $f_y$ at $(x_0, y_0)$ both are 0 or DNE.\r\n\\end{definition}\r\n\r\n\\noindent\r\nFor example, consider the function $f(x,y) = x^2/2 - y^2/2 - xy - 2x - 2y$.\r\n\\begin{align*}\r\n\tf_x &= x - y - 2\t\\text{ and is } 0 \\text{ when } y = x-2 \\\\\r\n\tf_y &= -y - x - 2 \\text{ and is } 0 \\text{ when } y = -x-2 \\\\\r\n\tx - 2 &= -x -2 \\text{ when } x = 0.\r\n\\end{align*}\r\nWhen $x = 0$, $ y =-2$, so $(0, -2)$ is a critical point of $f$.\r\n\r\n\\input{./differentialMultivariableCalculus/2ndDerivativeTestHessianMatrix}", "meta": {"hexsha": "4058eb7aad781d2cf2ed85b9cb5afabfa2b5fef0", "size": 796, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/criticalPoints.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/criticalPoints.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/criticalPoints.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 39.8, "max_line_length": 97, "alphanum_fraction": 0.6381909548, "num_tokens": 286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.713749674560138}}
{"text": "\\chapter{Cycles in the Collatz Tree}\n\n\\section{A remark about cycles}\n\\label{sec:cycles}\nIn graph theory, a path of length $n\\geq 1$ that starts and ends at the same vertex is called a circuit. A circuit, in which no vertex is repeated with the sole exception that the initial vertex is the terminal vertex, is called a cycle. A cycle of length $n$ is referred to as an $n$-cycle. For these definitions, we rely on \\cite[p.~599]{Ref_Rosen}, \\cite[p.~35]{Ref_Benjamin_Chartrand_Zhang} and \\cite[p.~445]{Ref_Chartrand_Zhang}. Furthermore, we call a cycle originating from the root a trivial cycle.\n\n\\begin{remark}\n\tIn order for the cycles to become graphically visible, we now require that in a graph $H$ two vertices $v_1$ and $v_2$ are one and the same if the label of both nodes are identical: $l_{V(H)}(v_1)=l_{V(H)}(v_2)\\rightarrow v_1=v_2$. As a consequence, there is no guarantee that the graph precisely refers to the algebraic structure of a free monoid anymore. A free monoid requires that each of its elements can be written in one and only one way.\n\\end{remark}\n\nWhen different nodes collapse on one, the graph is no longer necessarily a tree. Let us point to the monoid S*, which we introduced in section \\ref{sec:groups_graphs}. Take for example four of its elements, the empty string $e$, the strings $qqr$, $qqrqqr$, and $qqrqqrqqr$. These elements lie as well within the subset $U\\subset T\\subset S^*$, and they are represented by nodes of the tree $H_U$ that all have the same label $1=ev_{S^*}(qqr,1)=ev_{S^*}(qqrqqr,1)=ev_{S^*}(qqrqqrqqr,1)$. These nodes are one and the same, the root of $H_U$. Visually, then in $H_U$ a directed edge goes from the vertex labeled with $4$ back to the root node. Analogically, in $H_C$ a loop connects the root to itself, since due to the path contraction even labeled nodes do not exist in $H_C$. The  aforementioned example reflects the trivial cycle of the Collatz sequence.\n\n\\par\\medskip\nFigure~\\ref{fig:5} depicts a section of $H_{C,5}$, which includes the $3$-cycle $43,17,27$. Because of the two non-trivial cycles $43,17,27$ and $83,33,13$, in $H_{C,5}$ there does not exist a path between the root and the vertex $43$ and between the root and the vertex $83$. Hence, $H_{C,5}$ is said to be a disconnected graph. Generally, a graph is called a disconnected graph if it is impossible to walk (along its edges) from any vertex to any other \\cite[pp.~46-47]{Ref_Benjamin_Chartrand_Zhang}.\n\n\\begin{figure}\n\t\\includegraphics[width=1.00\\textwidth]{figures/h_c5a.png}\n\t\\caption{Section of $H_{C,5}$ including the $3$-cycle $43,17,27$}\n\t\\label{fig:5}\n\\end{figure}\n\n\\par\\medskip\nThe following considerations focus on non-trivial cycles, and therefore on cycles that do not originate from the root, but cause the graph to be a disconnected graph. Utilizing the example of the graph $H_{C,5}$ we are able to deduct from the cycle $43,17,27$ the simple and self-evident equality $\\textit{left-child}^3(43)=43$:\n\\begin{equation*}\n\\begin{array}{l}\n\\textit{left-child}(43)=\\frac{1}{5}*\\left(43*2^1-1\\right)=17\n\\\\[\\medskipamount]\n\\textit{left-child}(17)=\\frac{1}{5}*\\left(17*2^3-1\\right)=27\n\\\\[\\medskipamount]\n\\textit{left-child}(27)=\\frac{1}{5}*\\left(27*2^3-1\\right)=43\n\\end{array}\n\\end{equation*}\n\nObviously, the authors note, it would be interesting to find out what circumstances enable a graph to have non-trivial cycles, whether it be the $5x+1$ variant of $H_C$, the $7x+1$ variant of $H_C$ or any variant of $H_C$; let us say the $kx+1$ variant of $H_C$ with $k\\geq 1$.\n\n\\section{Which variants of \\mbox{$H_C$} have non-trivial cycles?}\n\\label{sec:non_trivial_cycles}\nLet us refer to a $kx+1$ variant of $H_C$ as $H_{C,k}$. By having introduced and proven theorem~\\ref{theo:1} we already started an assertion about the reachability of successive nodes in $H_C$. This reachability relationship can be generalized for any graph $H_{C,k}$ as follows:\n\\begin{equation}\n\\label{eq:generalized_reachability}\nv_{n+1}=k^nv_1\\prod_{i=1}^{n}\\left(1+\\frac{1}{kv_{i}}\\right)2^{-\\alpha_i}\n\\end{equation}\n\nThis generalization leads to the condition for an existence of an $n$-cycle in any $kx+1$ variant of $H_C$, which looks analogous to the condition given by equation~\\ref{eq:func_cycle} that specifies $H_C$ has a cycle:\n\\begin{equation}\n\\label{eq:generalized_cycle}\n2^\\alpha=\\prod_{i=1}^{n}\\left(k+\\frac{1}{v_i}\\right)\n\\end{equation}\n\nThe natural number $\\alpha$ is the sum of edges that have been contracted between the vertices $v_i$ forming the cycle, in other words $\\alpha$ is the number of divisions by $2$ within the sequence. The natural number $n$ is the cycle length and $k$ obviously specifies the variant of $H_C$. Since between each vertex at least one edge has been contracted (at least one division by $2$ took place), we know that our exponent alpha is greater than or equal to the sequence length:\n\\begin{equation}\n\\label{eq:n_alpha}\n\\alpha\\ge n\n\\end{equation}\n\n\\par\\medskip\nUsing incremental search, one can calculate cycles through trial and error. Table~\\ref{table:known_cycles} lists all empirically discovered cycles having a length up to $100$ that appear in $kx+1$ variants of $H_C$ for $k\\in[1,1000]$. Within each of these variants, the cycles have been searched at potential starting nodes $v_1$ with a label between $1$ and $1000$. Note that the cycles in table~\\ref{table:known_cycles} are written in reverse order, i.e. in the order which corresponds to the Collatz sequence. To obtain the cycles in terms of graph theory referring to the graph $H_C$, read them from right to left.\n\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{|L{2cm}|R{4cm}|R{2cm}|C{2cm}|}\n\t\t\\hline\n\t\t\\thead{\\boldsymbol{$k$}} &\n\t\t\\thead{\\textbf{cycle}} &\n\t\t\\thead{\\boldsymbol{$\\alpha$}} &\n\t\t\\thead{\\textbf{non-trivial}} \\\\\n\t\t\\hline\n\t\t1 &\n\t\t1 &\n\t\t1 &\n\t\t\\\\\n\t\t\\hline\n\t\t3 &\n\t\t1 &\n\t\t2 &\n\t\t\\\\\n\t\t\\hline\n\t\t5 &\n\t\t1,3 &\n\t\t5 &\n\t\t\\\\\n\t\t\\hline\n\t\t5 &\n\t\t13,33,83 &\n\t\t7 &\n\t\t\\checkmark \\\\\n\t\t\\hline\n\t\t5 &\n\t\t27,17,43 &\n\t\t7 &\n\t\t\\checkmark \\\\\n\t\t\\hline\n\t\t7 &\n\t\t1 &\n\t\t3 &\n\t\t\\\\\n\t\t\\hline\n\t\t15 &\n\t\t1 &\n\t\t4 &\n\t\t\\\\\n\t\t\\hline\n\t\t31 &\n\t\t1 &\n\t\t5 &\n\t\t\\\\\n\t\t\\hline\n\t\t63 &\n\t\t1 &\n\t\t6 &\n\t\t\\\\\n\t\t\\hline\n\t\t127 &\n\t\t1 &\n\t\t7 &\n\t\t\\\\\n\t\t\\hline\n\t\t181 &\n\t\t27,611 &\n\t\t15 &\n\t\t\\checkmark \\\\\n\t\t\\hline\n\t\t181 &\n\t\t35,99 &\n\t\t15 &\n\t\t\\checkmark \\\\\n\t\t\\hline\n\t\t255 &\n\t\t1 &\n\t\t8 &\n\t\t\\\\\n\t\t\\hline\n\t\t511 &\n\t\t1 &\n\t\t9 &\n\t\t\\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{Known $n$-cycles in $kx+1$ variants of $H_C$ for $k\\leq1000$, $n\\leq 100$}\n\t\\label{table:known_cycles}\n\\end{table}\nBased on the results shown in table~\\ref{table:known_cycles} we state the following theorem~\\ref{theo:2} that renders more precisely the prerequisite for cycles that may occur in variants of $H_C$.\n\n\\par\\medskip\n\\begin{theorem}\n\t\\label{theo:2}\n\tAn $n$-cycle can only exist in a graph $H_{C,k}$, that means in a $kx+1$ variant of $H_C$, if the following equation holds:\n\t\\begin{equation*}\n\t2^{\\bar\\alpha}=2^{\\lfloor n\\log_2k\\rfloor+1}=\\prod_{i=1}^{n}\\left(k+\\frac{1}{v_i}\\right)\n\t\\end{equation*}\n\\end{theorem}\n\n\\par\\medskip\nThe key of theorem~\\ref{theo:2} consists in the claim that, in order for an $n$-cycle to occur, the exponent $\\alpha$ has to be $\\bar\\alpha=\\lfloor n\\log_2k\\rfloor+1$. We approach a proof by expressing formally that $\\bar\\alpha$ is not allowed to be smaller and it is not allowed to be greater than $\\lfloor n\\log_2k\\rfloor+1$, in other words we indicate a lower and an upper limit for $\\bar\\alpha$ as follows:\n\n\\begin{samepage}\n\t\\begin{flalign}\n\t\\label{eq:inequality_min}\n\t&\\bar\\alpha>\\lfloor n\\log_2k\\rfloor\\\\\t\n\t\\label{eq:inequality_max}\n\t&\\bar\\alpha<\\lfloor n\\log_2k\\rfloor+2\n\t\\end{flalign}\n\\end{samepage}\n\nThe validity of the first part (\\ref{eq:inequality_min}), which specifies $\\lfloor n\\log_2k\\rfloor+1$ as the lower limit for $\\bar\\alpha$, can be demonstrated in a fairly simple way: Our starting point is equation~\\ref{eq:generalized_reachability}, which describes the relationship of successive vertices in $H_{C,k}$. Having a cycle, requires us to consider the first and the last vertex being one and the same $v_{n+1}=v_1$. Setting a smaller exponent $\\bar\\alpha=\\lfloor n\\log_2k\\rfloor$ into equation~\\ref{eq:generalized_reachability} results in the inequality $v_{n+1}>v_1$, which is in any case a true statement:\n\\begin{equation*}\n\\begin{array}{l}\nk^nv_12^{-\\lfloor n\\log_2k\\rfloor}\\prod_{i=1}^{n}\\left(1+\\frac{1}{kv_{i}}\\right)>v_1\n\\\\[\\medskipamount]\nk^n\\prod_{i=1}^{n}\\left(1+\\frac{1}{kv_{i}}\\right)>2^{\\lfloor\\ n\\log_2k\\rfloor}\n\\\\[\\medskipamount]\n\\log_2\\left(k^n\\prod_{i=1}^{n}\\left(1+\\frac{1}{kv_{i}}\\right)\\right)>\\lfloor n\\log_2k\\rfloor\n\\\\[\\medskipamount]\nn\\log_2k+\\log_2\\left(\\prod_{i=1}^{n}\\left(1+\\frac{1}{kv_{i}}\\right)\\right)>\\lfloor n\\log_2k\\rfloor\n\\end{array}\t\n\\end{equation*}\n\nThe validity of the second part (\\ref{eq:inequality_max}) is not so trivial to prove. Analogous to the above-shown proof of the cylce-alpha's lower limit, we again refer to equation~\\ref{eq:generalized_reachability} as our starting point and we need to show that $v_{n+1}$ is smaller than $v_1$ if $\\alpha=\\lfloor\\ nlog_2k\\rfloor+2$:\n\\begin{equation*}\n\\begin{array}{l}\nk^nv_12^{-\\left(\\lfloor n\\log_2k\\rfloor+2\\right)}\\prod_{i=1}^{n}\\left(1+\\frac{1}{kv_{i}}\\right)<v_1\n\\\\[\\medskipamount]\nk^n\\prod_{i=1}^{n}\\left(1+\\frac{1}{kv_{i}}\\right)<2^{\\left(\\lfloor n\\log_2k\\rfloor+2\\right)}\n\\end{array}\t\n\\end{equation*}\nThis leads to the following general condition for the validity of the cycle-alpha's upper limit:\n\\begin{equation}\n\\label{eq:condition_max}\nn\\log_2k-\\lfloor n\\log_2k\\rfloor<2-\\log_2\\left(\\prod_{i=1}^{n}\\left(1+\\frac{1}{kv_{i}}\\right)\\right)\n\\end{equation}\n\nA product $\\prod(1+a_n)$ with positive terms $a_n$ is convergent if the series $\\sum a_n$ converges, see Knopp \\cite[p.~220]{Ref_Knopp}. A similar statement provides Murphy \\cite{Ref_Murphy}, who write the factors in the form $c_n=1+a_n$ and explains that if $\\prod c_n$ is convergent then $c_n\\rightarrow1$ and therefore if $\\prod (1+a_n)$ is convergent then $a_n\\rightarrow0$. Thus, to verify whether the product in condition~\\ref{eq:condition_max} is converging towards a limiting value, it is sufficient to examine the following sum:\n\\begin{equation*}\n\\sum_{i=1}^{n}\\frac{1}{kv_{i}}\n\\end{equation*}\n\nThe sum of reciprocal vertices depending only from $v_1$ is given in appendix~\\ref{appx:sum_reciprocal_vertices}.\n\n\\section{Cycles and the product in the condition for alpha's upper limit}\nLet us start with the following product equality, which will give us insights into the relationship between cycles and the product in the condition for alpha's upper limit. The variables $V_1,\\ldots,V_m$ and $W_1,\\ldots,W_n$ are all odd positive integers:\n\\begin{equation}\n\\label{eq:product_equality}\n(V_1+1)\\cdots(V_m+1)\\cdot W_1\\cdots W_n=V_1\\cdots V_m\\cdot(W_1+1)\\cdots(W_n+1)\n\\end{equation}\n\nEvery natural odd number $V$ can be expressed in the form of $V=v\\cdot2^{\\alpha}-1$ whereby $v$ is an positive odd integer and $\\alpha>0$ is any natural number. This allows us to perform the following substitution (we use $\\alpha_V$ for denoting the divisions by two between nodes $v_i$ and $\\alpha_W$ for divisions by two between nodes $w_i$):\n\n\\begin{equation}\n\\label{eq:product_equality_substitution}\n\\begin{array}{lll}\nV_1&=v_22^{\\alpha_{V,1}}-1&=kv_1\\\\\nV_2&=v_32^{\\alpha_{V,2}}-1&=kv_2\\\\\n\\vdots&\\vdots&\\vdots\\\\\nV_{m-1}&=v_m2^{\\alpha_{V,m-1}}-1&=kv_{m-1}\\\\\nV_m&=v_12^{\\alpha_{V,m}}-1&=kv_m\n\\end{array}\\qquad\n\\begin{array}{lll}\nW_1&=w_22^{\\alpha_{W,1}}-1&=kw_1\\\\\nW_2&=w_32^{\\alpha_{W,2}}-1&=kw_2\\\\\n\\vdots&\\vdots&\\vdots\\\\\nW_{n-1}&=w_n2^{\\alpha_{W,n-1}}-1&=kw_{n-1}\\\\\nW_n&=w_12^{\\alpha_{W,n}}-1&=kw_n\n\\end{array}\n\\end{equation}\n\nThe substitution rotating from $v_2=(kv_1+1)\\cdot2^{-\\alpha_{V,1}}$ to $v_m=(kv_{m-1}+1)\\cdot2^{-\\alpha_{V,m-1}}$ and finally back to $v_1=(kv_m+1)\\cdot2^{-\\alpha_{V,m}}$ describes a cycle. The result of these substitutions into equation~\\ref{eq:product_equality} is the following equality:\n\\begin{flalign*}\nv_22^{\\alpha_{V,1}}\\cdots v_m2^{\\alpha_{V,m-1}}v_12^{\\alpha_{V,m}}\\cdot W_1\\cdots W_n&=V_1\\cdots V_m\\cdot w_22^{\\alpha_{W,1}}\\cdots w_n2^{\\alpha_{W,n-1}}w_12^{\\alpha_{W,n}}\\\\\nv_22^{\\alpha_{V,1}}\\cdots v_m2^{\\alpha_{V,m-1}}v_12^{\\alpha_{V,m}}\\cdot kw_1\\cdots kw_n&=kv_1\\cdots kv_m\\cdot w_22^{\\alpha_{W,1}}\\cdots w_n2^{\\alpha_{W,n-1}}w_12^{\\alpha_{W,n}}\n\\end{flalign*}\n\nThe trivial case where $n=m$ and the sum of exponents are equal $\\sum_{i=1}^{m}\\alpha_{V,i}=\\sum_{i=1}^{n}\\alpha_{W,i}$ simplifies the product equality as follows:\n\\begin{flalign*}\n(V_1+1)\\cdots(V_n+1)\\cdot W_1\\cdots W_n&=V_1\\cdots V_n\\cdot(W_1+1)\\cdots(W_n+1)\\\\\nv_1\\cdots v_n\\cdot\\cancel{2^{\\alpha_{V,1}+\\ldots+\\alpha_{V,n}}}\\cdot W_1\\cdots W_n&=V_1\\cdots V_m\\cdot w_1\\cdots w_n\\cdot\\cancel{2^{\\alpha_{W,1}+\\ldots+\\alpha_{W,n}}}\n\\end{flalign*}\nThis equality becomes immediatly true if $V_1\\cdots V_n=W_1\\cdots W_n$ which is the less spectacular case. The more interesting case arises from setting $V_i=kv_i$ and $W_i=kw_i$ as given by substitution~\\ref{eq:product_equality_substitution} wich turns the product equality into an always true statement as well:\n\\begin{flalign*}\nv_1\\cdots v_n\\cdot W_1\\cdots W_n&=V_1\\cdots V_m\\cdot w_1\\cdots w_n\\\\\nv_1\\cdots v_n\\cdot k^n\\cdot w_1\\cdots w_n&=k^n\\cdot v_1\\cdots v_n\\cdot w_1\\cdots w_n\n\\end{flalign*}\n\n\\begin{example}\nThe following exemplarly product equality fullfills equation~\\ref{eq:product_equality}, whereby $V_1=65$, $V_2=165$, $V_3=415$ and $W_1=135$, $W_2=85$, $W_3=215$:\n\\[\n(65+1)(165+1)(415+1)\\cdot135\\cdot85\\cdot215=65\\cdot165\\cdot415\\cdot(135+1)(85+1)(215+1)\n\\]\nWe perform the following substitutions:\n\\[\n\\arraycolsep=0.2em\\begin{array}{ll}\nV_1=65&=v_22^{\\alpha_{V,1}}-1=33\\cdot2^1-1=5v_1\\\\\nV_2=165&=v_32^{\\alpha_{V,2}}-1=83\\cdot2^1-1=5v_2\\\\\nV_3=415&=v_12^{\\alpha_{V,3}}-1=13\\cdot2^5-1=5v_3\n\\end{array}\\hspace{1em}\n\\begin{array}{ll}\nW_1=135&=w_22^{\\alpha_{W,1}}-1=17\\cdot2^3-1=5w_1\\\\\nW_2=85&=w_32^{\\alpha_{W,2}}-1=43\\cdot2^1-1=5w_2\\\\\nW_3=215&=w_12^{\\alpha_{W,3}}-1=27\\cdot2^3-1=5w_3\n\\end{array}\n\\]\nThe result of these substitutions is:\n\\[\n33\\cdot\\cancel{2^1}\\cdot83\\cdot\\cancel{2^1}\\cdot13\\cdot\\cancel{2^5}\\cdot135\\cdot85\\cdot215=65\\cdot165\\cdot415\\cdot17\\cdot\\cancel{2^3}\\cdot43\\cdot\\cancel{2^1}\\cdot27\\cdot\\cancel{2^3}\n\\]\nSince the sum of exponents $\\alpha_{V,i}$ and $\\alpha_{W,i}$ are equal, we can cancel out all powers of two and obtain:\n\\[\nv_2v_3v_1W_1W_2W_3=33\\cdot83\\cdot13\\cdot135\\cdot85\\cdot215=65\\cdot165\\cdot415\\cdot17\\cdot43\\cdot27=V_1V_2V_3w_2w_3w_1\n\\]\nThis product equality becomes true $v_2v_3v_1\\cdot k^3\\cdot w_1w_2w_3=k^3\\cdot v_1v_2v_3\\cdot w_2w_3w_1$ when we set $V_i=kv_i$ and $W_i=kw_i$ (for $i=1,2,3$) which inevitably leads to the two corresponding cycles for $k=5$ that are already presented by table~\\ref{table:known_cycles}.\n\\end{example}\n\n\\section{Existence of a solitary cycle for $k=1$}\nAs per theorem~\\ref{theo:2}, for $k=1$, the only possible alpha for a cycle is $1$:\n\\[\n\\bar\\alpha=\\lfloor n\\log_21\\rfloor+1=1\n\\]\nIn accordance with the condition $\\alpha\\ge n$ stated by \\ref{eq:n_alpha} it is clear that between two successive vertices at least one edge has been contracted or respectively one division by two took place. This is the reason why, if theorem~\\ref{theo:2} is true, a cycle can only occur for $n=1$. Based on equation~\\ref{eq:generalized_cycle} we can show that this is the case for the trivial cycle, starting at the root $v_1=1$:\n\\[\n2^{\\bar\\alpha}=2^{\\lfloor 1\\log_21\\rfloor+1}=2^1=\\left(1+\\frac{1}{v_1}\\right)=\\left(1+\\frac{1}{1}\\right)\n\\]\nSince no other value of $v_1$ results in a natural number, no other cycle for $n=1$ is possible. In order to prove theorem~\\ref{theo:2} for $k=1$, we now have to show that condition~\\ref{eq:condition_max} is true.\n\n\\section{Verifying cycle-alpha's upper limit for the $1x+1$ variant of $H_C$}\n\\label{sec:alphas_upper_limit_k_1}\nWe prove that theorem~\\ref{theo:2} is true for $k=1$ using the so-called Engel expansion, which we will explore more closely in appendix~\\ref{sec:worstcase_k3}. Setting $b=2$ and $k=1$ into equation~\\ref{eq:generalized_asc_continued_fraction} leads to the formula that calculates the node $v_{n+1}$ for a sequence, in which we divide by $2$ only once per iteration:\n\\begin{equation}\n\\label{eq:appx_1}\nv_{n+1}=\\frac{v_1+2^n-1}{2^n}\n\\end{equation}\n\n\\begin{example}\n\tLet us consider the sequence $v1=17$, $v_2=9$, $v_3=5$, $v_4=3$. Setting $v_1=17$ and $n=3$ results in:\n\t\\[\n\tv_{3+1}=v_4=\\frac{17+2^3-1}{2^3}=3\n\t\\]\n\\end{example}\n\nEquation~\\ref{eq:appx_1} represents the (hypothetical) case in which a sequence progresses to the highest possible successive node for a specific starting node $v_1$. Actually, the sequence decreases in any case except $v_1=1$ and $n=1$. We can show that setting $v_1=1$ and $n=1$ results in the trivial cycle:\n\\[\nv_1=1=v_2=\\frac{1+2^1-1}{2^1}\n\\]\n\nThe equation above, complies to (and verifies) theorem~\\ref{theo:2}, since $1=n=\\alpha=\\bar\\alpha$:\n\\[\n\\bar\\alpha=\\lfloor n\\log_21\\rfloor+1=1\n\\]\n\nThe condition~\\ref{eq:n_alpha}, namely the inequality $\\alpha\\ge n$, can be used to prove that no other $\\alpha$ than $\\bar\\alpha$ leads to a cycle. To show this, we set $v_{n+1}=v_1$:\n\\[\nv_1=\\frac{v_1+2^n-1}{2^n}=\\frac{v_1}{2^n}-\\frac{1}{2^n}+1=\\frac{v_1-1}{2^n}+1\n\\]\n\nThe above term is only true for $v_1=1$ and $n=\\alpha=\\bar\\alpha=1$. Any higher value for $v_1$, $n$ or $\\alpha$ leads to a result less than $v_1$. Therefore, a cycle is not possible for $\\alpha\\ne 1$ and theorem~\\ref{theo:2} is true for $k=1$. A cycle can only occur for the case $v_1=1$ and $\\alpha=\\bar\\alpha=n=1$. For any other case the following condition applies:\n\\[\nv_1>\\frac{v_1-1}{2^n}+1\n\\]\n\nKnowing that theorem~\\ref{theo:2} is true, we can revisit condition~\\ref{eq:condition_max} determining the upper limit of $\\bar\\alpha$. We set $k=1$ into this condition and obtain:\n\\begin{equation}\nn\\log_21-\\lfloor n\\log_21\\rfloor<2-\\log_2\\left(\\prod_{i=1}^{n}\\left(1+\\frac{1}{1v_{i}}\\right)\\right)\n\\end{equation}\n\nThe above-given inequality gets simplified to a condition which is true and proves that the product in condition~\\ref{eq:condition_max} is always less than four:\n\\[\n4>\\prod_{i=1}^{n}\\left(1+\\frac{1}{v_{i}}\\right)\n\\]\n\n%\\par\\medskip\\noindent\n%\\textbf{Case 1 (\\boldsymbol{$v_1=1$})}\n\n%As per the inequality \\ref{eq:n_alpha}, which states that $\\alpha\\ge n$ and thus $2\\ge n$, we know that in this case of $k=1$ a cycle can have a maximum length of $2$. This is obviously correct.\n\n%By setting $n=1$ in equation~\\ref{eq:generalized_reachability}, we describe the relationship between two successive nodes in $H_{C,k}$ and we obtain:\\\\\n%\\begin{equation*}\n%\tv_2=\\frac{kv_1+1}{2^a}\n%\\end{equation*}\n\n%Let $v_1$ and $v_2$ be the same vertex defining a $1$-cycle (a loop). The equality $v_1=v_2$ requires the exponent $a$ to be bigger than $\\lfloor\\log_2k\\rfloor*n$ (see equation~\\ref{eq:inequality}). Otherwise $v_2$ will be bigger than $v_1$:\\\\\n\n% Carmichael numbers, Mersenne Primes, Primes, mod 8\n\n\\section{Verifying cycle-alpha's upper limit for $H_{C,k>1}$}\n%Let us now validate alpha's upper limit for all $kx+1$ variants of $H_C$ for $k=3$. For this we need to show that the condition~\\ref{eq:condition_max} is true for $k>1$. To improve readability, we denote the factor $(1+\\frac{1}{3v_i})$ with $\\beta_i$:\n\nIn order to prove the upper limit of $\\bar\\alpha$ for $k=3$, we have to show that condition~\\ref{eq:condition_max} is true. For better readability we denote the factor $(1+\\frac{1}{3v_i})$ with $\\beta_i$:\n\\begin{equation*}\n\tn\\log_23-\\lfloor n\\log_23\\rfloor<2-\\log_2\\prod_{i=1}^{n}\\beta_i\n\\end{equation*}\n\nHaving a look at the above term makes clear that to prove the inequality, we have to show that the following condition is true:\n\n\\begin{equation}\n\\label{eq:condition_beta_lt_2}\n\t\\prod_{i=1}^{n}\\beta_i<2\n\\end{equation}\n\nWe formulate a proof for condition~\\ref{eq:condition_beta_lt_2} based on theorem~\\ref{theo:1}:\n\n\\begin{equation}\n\\label{eq:based_theo_1}\nv_{n+1}=3^nv_1\\prod_{i=1}^{n}\\beta_i\\prod_{i=1}^{n}2^{-\\alpha_i}\n\\end{equation}\n\nThe variable $\\beta_{n+1}$ can be calculated with the following equation:\n\n\\begin{equation}\n\\label{eq:beta_n_plus_1}\n\\beta_{n+1}=1+\\frac{1}{3v_{n+1}}\n\\end{equation}\n\n\\begin{example}\n\tSetting $v_2=5$ and $n=1$ leads to:\n\t\\[\n\t\\beta_{1+1}=1+\\frac{1}{3v_{1+1}}=1+\\frac{1}{3\\cdot5}=1.0\\overline{6}\n\t\\]\n\\end{example}\n\nWhen we replace $v_{n+1}$ in equation~\\ref{eq:beta_n_plus_1} with theorem~\\ref{theo:1}, we obtain the following formula:\n\n\\begin{equation}\n\\label{eq:beta_n_plus_1_theo_1}\n\\beta_{n+1}=1+\\frac{1}{3\\cdot3^nv_1\\prod_{i=1}^{n}\\beta_i\\prod_{i=1}^{n}2^{-\\alpha_i}}=1+\\frac{\\prod_{i=1}^{n}2^{\\alpha_i}}{3^{n+1}v_1\\prod_{i=1}^{n}\\beta_i}\n\\end{equation}\n\n\\begin{example}\nLet us consider $v_1=13$ and $n=1$. In this case $\\beta_{n+1}$ equals $1.0\\overline{6}$:\n\\[\n\\beta_{1+1}=1+\\frac{\\prod_{i=1}^{1}2^{\\alpha_i}}{3^{1+1}v_1\\prod_{i=1}^{1}\\beta_i}\n\\]\n\\[\n\\beta_{1+1}=1+\\frac{2^3}{3^2\\cdot13\\cdot1.0256}=1+\\frac{1}{3\\cdot5}=1.0\\overline{6}\n\\]\n\\end{example}\n\nWe now assume that the product $\\prod_{i=1}^{n+1}\\beta_i$ reaches the value $2$ in the next iteration, which would violate the inequality~\\ref{eq:condition_beta_lt_2}:\n\n\\begin{equation}\n\\label{eq:assume_beta_eq_2}\n2=\\prod_{i=1}^{n+1}\\beta_i=\\beta_{n+1}\\cdot\\prod_{i=1}^{n}\\beta_i\n\\end{equation}\n\nReplacing $\\beta_{n+1}$ in assumption~\\ref{eq:assume_beta_eq_2} with equation~\\ref{eq:beta_n_plus_1_theo_1} leads to:\n\n\\begin{equation}\n\\label{eq:prod_power_of_two}\n\\large\\def\\arraystretch{2.0}\\begin{array}{l}\n2=\\left(1+\\frac{\\prod_{i=1}^{n}2^{\\alpha_i}}{3^{n+1}v_1\\prod_{i=1}^{n}\\beta_i}\\right)\\cdot\\prod_{i=1}^{n}\\beta_i\\\\\n2=\\prod_{i=1}^{n}\\beta_i+\\frac{\\prod_{i=1}^{n}2^{\\alpha_i}}{3^{n+1}v_1}\\\\\n2-\\prod_{i=1}^{n}\\beta_i=\\frac{\\prod_{i=1}^{n}2^{\\alpha_i}}{3^{n+1}v_1}\\\\\n3^{n+1}v_1\\cdot\\left(2-\\prod_{i=1}^{n}\\beta_i\\right) =\\prod_{i=1}^{n}2^{\\alpha_i}\\\\\n\\prod_{i=1}^{n}2^{\\alpha_i}=3^{n+1}v_1\\left(2-\\prod_{i=1}^{n}\\beta_i\\right)\n\\end{array}\n\\end{equation}\n\nWe finally insert equation~\\ref{eq:prod_power_of_two} into equation~\\ref{eq:based_theo_1} and we increment the vertex's index by one:\n\\begin{flalign*}\nv_{n+2}&=3^{n+1}v_1\\prod_{i=1}^{n+1}\\beta_i\\prod_{i=1}^{n+1}2^{-\\alpha_i}\\\\\nv_{n+2}&=3^{n+1}v_1\\prod_{i=1}^{n+1}\\beta_i\\left(\\prod_{i=1}^{n}2^{-\\alpha_i}\\right)2^{-\\alpha_{n+1}}\\\\\nv_{n+2}&=\\frac{3^{n+1}v_1\\prod_{i=1}^{n+1}\\beta_i}{\\left(\\prod_{i=1}^{n}2^{\\alpha_i}\\right)2^{\\alpha_{n+1}}}=\\frac{3^{n+1}\\cdot v_1\\cdot2}{3^{n+1}v_1\\left(2-\\prod_{i=1}^{n}\\beta_i\\right)\\cdot2^{\\alpha_{n+1}}}\\\\\nv_{n+2}&=\\frac{2}{\\left(2-\\prod_{i=1}^{n}\\beta_i\\right)\\cdot2^{\\alpha_{n+1}}}\n\\end{flalign*}\n\nKnowing that $1<\\prod_{i=1}^{n}\\beta_i<2$ and $2^{\\alpha_{i+1}}\\ge2$ leads to the following true statement:\n\n\\begin{equation}\n\\label{eq:inequality_v_n_plus_2}\nv_{n+2}<1\n\\end{equation}\n\n\\par\\bigskip\nThe statement~\\ref{eq:inequality_v_n_plus_2} shows that $\\prod_{i=1}^{n+1}\\beta_i\\ge2$ is impossible, since it would result in a final node $v_{n+2}<1$. We therefore have proven theorem~\\ref{theo:2} for $k=3$ by contradiction. Having a look at the proof makes clear that it is not only valid for $k=3$ but for all $k>1$. It is also applicable for $k=1$, except for the case $v_1=1$. Here  $\\beta_1$ equals $2$ immediately in the first iteration. This is the reason why we had to rely on another proof for $k=1$.\n", "meta": {"hexsha": "969ed639e11d5bdf7d044910ec047bb7e70314af", "size": 23130, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01 Graph Theory/TeX/v4.1/chapter/03_cycles.tex", "max_stars_repo_name": "Sultanow/collatz", "max_stars_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-01T15:12:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T15:54:55.000Z", "max_issues_repo_path": "01 Graph Theory/TeX/v4.1/chapter/03_cycles.tex", "max_issues_repo_name": "Sultanow/collatz", "max_issues_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01 Graph Theory/TeX/v4.1/chapter/03_cycles.tex", "max_forks_repo_name": "Sultanow/collatz", "max_forks_repo_head_hexsha": "d8a5137af508be19da371fff787c114f1b5185c3", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-06T20:44:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-06T20:44:07.000Z", "avg_line_length": 53.5416666667, "max_line_length": 856, "alphanum_fraction": 0.7104626027, "num_tokens": 8682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7137496741246188}}
{"text": "% !TEX root = math_subfile.tex\n\n\\chapter{Maths}\n\n\\section{Equations}\n\nLorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut,placerat ac, adipiscing vitae, felis.\n\\begin{equation}\n    \\sum_{k=1}^\\infty \\frac{1}{k^2} = \\frac{\\pi^2}{6}.\n\\end{equation}\nCurabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpisegestas. Mauris ut leo.\n\\begin{align*}\n    f(x) &= x(x-1)^2 \\\\\n    &= x(x^2-2x+1) \\\\\n    &= x^3-2x^2+x.\n\\end{align*}\n\n\\section{Theorems}\n\n\\begin{theorem}\n    This is an important theorem.\n\\end{theorem}\n\\begin{proof}\n    The proof is left as an exercise.\n\\end{proof}\nYou can also define a restatable theorem. Useful for restating the theorem when the proofs are in the appendices.\n\\begin{restatable}[Goldbach's conjecture]{theorem}{goldbach}\n    \\label{thm:goldbach}\n    Every even integer greater than 2 can be expressed as the sum of two primes.\n\\end{restatable}\nAnd then, we recall \\cref{thm:goldbach}.\n\\goldbach*\n", "meta": {"hexsha": "aef36169eddbb6f039ff45d523c60db7369ab9f5", "size": 1114, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/tex/math/math.tex", "max_stars_repo_name": "bilelomrani1/latex-workspace", "max_stars_repo_head_hexsha": "218a4cdb9ac19d36f1960dbe7d5d7ec2e73275af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-24T14:43:46.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-24T14:43:46.000Z", "max_issues_repo_path": "report/tex/math/math.tex", "max_issues_repo_name": "bilelomrani1/latex-workspace", "max_issues_repo_head_hexsha": "218a4cdb9ac19d36f1960dbe7d5d7ec2e73275af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/tex/math/math.tex", "max_forks_repo_name": "bilelomrani1/latex-workspace", "max_forks_repo_head_hexsha": "218a4cdb9ac19d36f1960dbe7d5d7ec2e73275af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7575757576, "max_line_length": 239, "alphanum_fraction": 0.7262118492, "num_tokens": 355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7135454338317497}}
{"text": "\\subsection{Determination of the band integral intensity}\n\\label{band_intensities}\n\nOne of the important spectroscopic information is the integral intensity of\nparticular Raman bands from the spectrum.\nThe band's shape is usually modeled by Gaussian or Lorentzian curves or as\ntheir combination.\nThe combination of the Lorentzian $\\func{L}$ and Gaussian $\\func{G}$ curve can\nbe expressed as\n\\begin{equation}\n\t\\func{S}(\\wn; I_\\text{m}, \\mu, \\sigma) =\n\t\tc_\\text{L} \\cdot \\func{L}(\\wn; I_\\text{m}, \\mu, \\sigma)\n\t\t+ (1 - c_\\text{L}) \\cdot \\func{G}(\\wn; I_\\text{m}, \\mu, \\sigma),\n\t\\label{\\eqnlabel{band_intensities:single_shape}}\n\\end{equation}\nwhere $c_\\text{L}$ is the Lorentzian curve fraction coefficient, $I_m$ is the\nheight, $\\mu$ is the band position, $\\sigma$ is the Gaussian root mean square\nwidth, and $\\wn$ is the wavenumber.\nThe Gaussian function is taken in the form of\n\\begin{equation*}\n\t\\func{G}(\\wn; I_\\text{m}, \\mu, \\sigma) =\n\t\tI_\\text{m} e^{-\\frac{(\\wn - \\mu)^2}{2\\sigma^2}}.\n\\end{equation*}\n\nIt is beneficial to select the parameters of the Lorentzian curve to match the\nparameters of the Gaussian curve.\nThis matching is straightforward for the height $I_\\text{m}$ and position\n$\\mu$ parameters but less evident for the width $\\sigma$ parameter.\nTo give the proper meaning to the Lorentzian curve fraction coefficient\n$c_\\text{L}$, we decided to make the full width at half maximum (FWHM) between\nthe Gaussian and Lorentzian curve equal for the same $\\sigma$.\nTherefore we needed to calculate the FWHM of the Gaussian curve.\nLet us assume, without loss of generality,\n$I_\\text{m} = 1$\nand\n$\\mu = 0$,\nand only the positive solution of the quadratic equation\n\\begin{align}\n\t\\frac{1}{2} &= \\func{G}(\\wn; 1, 0, \\sigma)\n\t\t= e^{-\\frac{\\wn^2}{2\\sigma^2}}, \\nonumber \\\\\n\t\\func{ln}2  &= \\frac{\\wn^2}{2\\sigma^2}, \\nonumber \\\\\n\t\\wn         &= \\sigma\\sqrt{2\\ln2},\n\t\t\\label{\\eqnlabel{band_intensities:HWHM}}\\\\\n\t\\func{FWHD}_\\text{G}(\\sigma)\n\t            &= 2\\wn = 2\\sigma\\sqrt{2\\ln2}. \\nonumber\n\\end{align}\n\nThe matching width parameter of the Lorentzian curve can be calculated as\n\\begin{align*}\n\t\\frac{1}{2} &= \\frac{1}{1 + p\\wn^2}, \\\\\n\t1 + p\\wn^2  &= 2, \\\\\n\t\\wn         &= \\frac{1}{\\sqrt{p}}.\n\\end{align*}\nThen with the result from \\eqnref{band_intensities:HWHM}, we get\n\\begin{align*}\n\t\\sigma\\sqrt{2\\ln2}\n\t            &= \\frac{1}{\\sqrt{p}}, \\\\\n  p           &= \\frac{1}{2\\sigma^2\\ln2}.\n\\end{align*}\nWith this result, the final form of the Lorentzian curve is\n\\begin{equation*}\n\t\\func{L}(\\wn; I_\\text{m}, \\mu, \\sigma) =\n\t\t\\frac{I_m}{1 + \\frac{(\\wn - \\mu)^2}{2\\sigma^2\\ln2}}.\n\\end{equation*}\nThis definition of the Lorentzian curve means that with the Lorentzian curve\nfraction coefficient $c_\\text{L} = 0.5$, the contributions to the FWHM of the\nLorentzian and the Gaussian curve to the combined band shape are equal.\n\nThe integral intensity of the band can be calculated as the sum of the\ncontributions of both bands.\nIt obviously does not depend on the position of the band $\\mu$, so we can,\nwithout loss of generality, set it to zero during further calculations\n\\begin{equation}\n\\func{I}(I_\\text{m}, \\sigma) =\n\tc_\\text{L} \\func{I}_\\text{L}(I_\\text{m}, \\sigma)\n\t+ (1 - c_\\text{L}) \\func{I}_\\text{G}(I_\\text{m}, \\sigma),\n\\end{equation}\nwhere\n\\begin{align*}\n\t\\func{I}_\\text{G}(I_\\text{m}; \\sigma)\n\t\t&= I_\\text{m}\\int_{-\\infty}^{\\infty}\n\t\t\t{e^{-\\frac{\\wn^2}{2\\sigma^2}}\\text{d}\\wn}\n\t\t= \\begin{vmatrix}\n\t\t\t\\wn = \\sigma\\sqrt{2}x \\\\\n\t\t\t\\text{d}\\wn = \\sigma\\sqrt{2}\\text{d}x\n\t\t\\end{vmatrix}\n\t\t= I_\\text{m}\\sigma\\sqrt{2}\\int_{-\\infty}^{\\infty}{e^{-x^2}\\text{d}x} \\\\\n\t\t&= I_\\text{m}\\sigma\\sqrt{2\\text{\\g{p}}}\n\\end{align*}\nand\n\\begin{align*}\n\t\\func{I}_\\text{L}(I_\\text{m}, \\sigma)\n\t\t&= \\int_{-\\infty}^{\\infty}\n\t\t\t{\\frac{I_\\text{m}}{1 + \\frac{\\wn^2}{2\\sigma^2\\ln2}}\\text{d}\\wn}\n\t\t= \\begin{vmatrix}\n\t\t\t\\wn = \\sigma\\sqrt{2ln2}x \\\\\n\t\t\t\\text{d}\\wn = \\sigma\\sqrt{2\\ln2}\\text{d}x\n\t\t\\end{vmatrix}\n\t\t= I_\\text{m}\\sigma\\sqrt{2\\ln2}\\int_{-\\infty}^{\\infty}\n\t\t\t{\\frac{1}{1 + x^2}\\text{d}x} \\\\\n\t\t&= I_\\text{m}\\sigma\\text{\\g{p}}\\sqrt{2\\ln2}.\n\\end{align*}\n\nRaman bands in a typical Raman spectrum of complex samples are overlapped.\nWe solved this problem by modeling the band as a combination of more\nband-shape functions from\n\\eqnref{band_intensities:single_shape}\n\\begin{equation}\n\t\\func{S}(\\wn; I_{\\text{m},1..n}, \\mu_{1..n}, \\sigma_{1..n}) =\n\t\t\\sum_{i = 1}^n = \t\\func{S}_i(\\wn; I_{\\text{m},i}, \\mu_i, \\sigma_i),\n\t\\label{\\eqnlabel{band_intensities:shape}}\n\\end{equation}\nwhere $n$ is the number of the overlapping bands.\n\nThis band shape was fitted to the measured spectra. The slightly enhanced\nMarquardt-Levenberg method\n(see \\cref{minimization})\nwas used for the nonlinear regression, and analytical derivatives was used for\ngradient computation.\n\\\\\n", "meta": {"hexsha": "208fbf870fc1ea1bc2c65340f731dc268feca9e0", "size": 4736, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/results_and_discussion/band_intensities.tex", "max_stars_repo_name": "lumik/phd_thesis", "max_stars_repo_head_hexsha": "3b29f24732d49b64c627aeb8f6585f042cd59c4e", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/results_and_discussion/band_intensities.tex", "max_issues_repo_name": "lumik/phd_thesis", "max_issues_repo_head_hexsha": "3b29f24732d49b64c627aeb8f6585f042cd59c4e", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 41, "max_issues_repo_issues_event_min_datetime": "2019-08-13T12:27:09.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T03:00:58.000Z", "max_forks_repo_path": "src/results_and_discussion/band_intensities.tex", "max_forks_repo_name": "lumik/phd_thesis", "max_forks_repo_head_hexsha": "3b29f24732d49b64c627aeb8f6585f042cd59c4e", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.1404958678, "max_line_length": 78, "alphanum_fraction": 0.6767314189, "num_tokens": 1715, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.7134932238531073}}
{"text": "\\chapter{Permutations}\n\\label{chapter:permutations}\nRecall that a permutation is a bijection from $\\range{n}$ to $\\range{n}$. We\nalready discussed several properties of them. In this chapter we will discuss\nsome combinatorial properties of them. We denote by $\\permutations{n}$ the set\nof all permutations of $\\range{n}$.\\footnote{%\n  Letter $S$ is used since in the group theory this set is called\n  the symmetric group.\n}\n\\nomenclature[S]{$\\permutations{n}$}{denotes the set of all permutations of $\\range{n}$}\n\n\nThe main operation over permutations is composition, for two permutations $p$\nand $q$ we denote their composition $p \\circ q$ by $pq$.\\footnote{%\n  Some authors denote $q \\circ p$ by $pq$.\n}\nNote that this operation is not commutative; i.e. $p \\circ q$ is not\nnecessarily equal to $q \\circ p$.\n\nEvery permutation $p$ can be uniquely determined by the values $p(1)$, \\dots,\n$p(n)$, thus sometimes we denote the permutation $f$ by a sequence\n$p(1) p(2) \\dots p(n)$ (we call it \\emph{one-line notation}).\nFor example, the permutation $3 1 2$ is equal to the function $p : \\range{3} \\to\n\\range{3}$\nsuch that\n\\[\n  p(x) =\n  \\begin{cases}\n    3 & \\text{if } x = 1 \\\\\n    1 & \\text{if } x = 2 \\\\\n    2 & \\text{if } x = 3\n  \\end{cases}.\n\\]\n\n\n\\section{Cycles}\nConsider the permutation $p$ equal to $2 3 1 5 4$ and draw a diagram with\n$5$ points where we draw an arrow from $i$ to $j$ iff $p(i) = j$.\n\\begin{center}\n  \\begin{tikzpicture}[thick]%\n    \\node[circle, draw, minimum width=4pt]\n      (p1) at (0, 0) {1};\n    \\node[circle, draw, minimum width=4pt]\n      (p2) at (-1, 1.4) {2};\n    \\node[circle, draw, minimum width=4pt]\n      (p3) at (1, 1.4) {3};\n    \\node[circle, draw, minimum width=4pt]\n      (p4) at (4, 0) {4};\n    \\node[circle, draw, minimum width=4pt]\n      (p5) at (4, 1.4) {5};\n    \\draw[->] (p1) -- (p2);\n    \\draw[->] (p2) -- (p3);\n    \\draw[->] (p3) -- (p1);\n\n    \\draw[->] (p4) to[out=45, in=-45] (p5);\n    \\draw[->] (p5) to[out=-135, in=135] (p4);\n  \\end{tikzpicture}\n\\end{center}\nIt is easy to see that there are two ``cycles'' in the diagram. In this section\nwe prove that this is not a coincidence and we also study some properties of\npermutations with respect to the structure of these cycles.\n\n\\begin{definition}\n  Let $p$ be a permutation of $\\range{n}$, $x \\in \\range{n}$, and $i$ be the smallest\n  integer such that\n  $p^i(x) = \\underbrace{p(p(\\dots p(}_{i \\text{ times}} x) \\dots )) = x$.\n  The we say that the entries $x$, $p(x)$, \\dots, $p^{i - 1}(x)$ form an\n  $i$-cycle in $p$.\n\n  We denote a permutation $q : \\range{n} \\to \\range{n}$ consisting of one cycle\n  $a_1$, \\dots, $a_k$ by $(a_1, \\dots, a_k)$; i.e.\n  \\[\n    q(x) =\n    \\begin{cases}\n      a_2 & \\text{if } x = a_1 \\\\\n      a_3 & \\text{if } x = a_2 \\\\\n      \\dots \\\\\n      a_1 & \\text{if } x = a_k \\\\\n      x & \\text{otherwise}\n    \\end{cases}.\n  \\]\n\\end{definition}\n\n\\begin{theorem}\n\\label{theorem:permuations-into-cycles}\n  All permutations can be decomposed into the disjoint unions of their cycles.\n\\end{theorem}\n\\begin{exercise}\n  Prove Theorem~\\ref{theorem:permuations-into-cycles}.\n\\end{exercise}\nFor example, the discussed permutation $2 3 1 5 4$ can be decomposed into\n$(1, 2, 3) (4, 5)$.\n\nIf an permutation $p : \\range{n} \\to \\range{n}$ has $c_i$ cycles of length $i \\in \\range{n}$, then\nwe say that $(c_1, c_2, \\dots, c_n)$ is the \\emph{cycle type} of $p$.\nThe simplest question we may ask is ``how many permutations of a certain cyclic\ntype exist?'', the following theorem gives an answer for this question.\n\\begin{theorem}\n  Let $c_1$, \\dots, $c_n$ be some positive integers such that\n  $\\sum_{i = 1}^n i c_i = n$. Then there are\n  $\\frac{n!}{c_1! c_2! \\dots c_n! 1^{c_1} 2^{c_2} \\dots n^{c_n}}$\n  permutation of the cyclic type $(c_1, \\dots, c_n)$.\n\\end{theorem}\n\nNote that this result allows us to answer the following problem. King Arthur has\n$n$ Knights of the Round Table; Arthur wonders: how many ways to seat in the\nround table? In other words he is asking how many permutations of the cyclic\ntype $(0, 0, \\dots, 0, 1)$. Hence, the answer for Arthur's question is $n!$\n(note that we also need to give a seat to the king).\n\n\\section{Stirling Numbers of The First Kind}\nIn the previous chapter we defined Stirling numbers of the second kind; in this\nsection we define their first kind counterpart.\n\n\\begin{definition}\n  Let $n > k$ be some integers. We denote the number of permutations of\n  $\\range{n}$ with $k$ cycles by $c(n, k)$. The number $s(n, k) = (-1)^{n - k}\n  c(n, k)$ is called a \\emph{Stirling number of the first kind}.\n\\end{definition}\nThe multiplier $(-1)^{n - k}$ seems a bit strange, but we will explain it\nin Theorem~\\ref{theorem:connection-between-stirling-numbers}.\n\nLike the numbers $S(n, k)$, the numbers $c(n, k)$ satisfy a simple recurrent\nformula.\n\\begin{theorem}\n\\label{theorem:stirling-numbers-first-kind-reccurent-relation}\n  Let $n \\ge k$ be positive integers. Then\n  \\[\n    c(n, k) = c(n - 1, k - 1) + (n - 1) c(n - 1, k).\n  \\]\n\\end{theorem}\n\n\\begin{exercise}\n  Prove Theorem~\\ref{theorem:stirling-numbers-first-kind-reccurent-relation}.\n\\end{exercise}\n\n\\begin{theorem}\n\\label{theorem:connection-between-stirling-numbers}\n  For any real $x$ and positive integer $n$,\n  \\[\n    \\numberOfPermutations[n]{x} = \\sum_{k = 0}^n s(n, k) x^k.\n  \\]\n\\end{theorem}\nNow one may see why the multiplier $(-1)^{n - k}$ was necessary by comparing\nthis equality with the equality from\nTheorem~\\ref{theorem:stirling-numbers-and-polynomials} stating that\n\\[\n  x^n = \\sum_{k = 0}^n S(n, k) \\numberOfPermutations[k]{x}.\n\\]\nIn other words, Stirling numbers of the second kind are ``inverse'' to the\nStirling numbers of the first kind.\n\nWe can interpret this result in terms of linear algebra. Consider the vector\nspace $\\mathbb{P}_n$ of real polynomials of degree at most $n$. It is well\nknown that $1$, $x$, \\dots, $x^n$ is the basis of this space; additionally,\nit is easy to see that $1$, $\\numberOfPermutations[1]{x}$, \\dots,\n$\\numberOfPermutations[n]{x}$ is also a basis. Then\nthe matrices $M^{(S)}$ and $M^{(s)}$ such that\n$M^{(S)}_{i, j} = S(i, j)$ and $M^{(s)}_{i, j} = s(i, j)$ are\nchange of basis matrices between these two bases.\n\n\\section{Permutations with Restricted Cycle Structure}\nOne of the problem of the representation of a permutation as a collection of\ncycles is that it is not unique; e.g. $(1, 2, 3) (4, 5)$ and $(5, 4) (1, 2, 3)$\nrepresent the same permutation. To avoid this we introduce a \\emph{canonical\ncycle form}, That is, each cycle will be written with its largest element first,\nand the cycles will be written in increasing order of their first elements. Thus\nthe permutation's $2 3 1 5 4$ canonical cycle form is $(3, 1, 2) (5, 4)$.\n\nUsing this notation and the next lemma we can discover several nice properties\nof permutations.\n\\begin{lemma}\n\\label{lemma:permuations-transfomration}\n  Let $p : \\range{n} \\to \\range{n}$ be a permutation written in canonical cycle notation.\n  Let $\\fpm(p)$ be the permutation obtained from $p$ by omitting the\n  parentheses and reading the entries as a permutation in the one-line notation.\n  Then $\\fpm$ is a bijection from $\\permutations{n}$ to $\\permutations{n}$.\n\\end{lemma}\nFor example, $\\fpm(2 3 1 5 4) = 31254$ and\n$\\fpm^{-1}(2 3 1 5 4) = (2) (3, 1) (5, 4) = 32154$.\n\nUsing this transformation we may prove the following result, which is very\ntechnical without this transformation.\n\\begin{theorem}\n  Let $n$ be a positive integer and $x_1, \\dots, x_k \\in \\range{n}$ be $k$ different\n  numbers. There are $n! / k$ permutations of $\\range{n}$ such that $x_1$, \\dots,\n  $x_k$ are in the same cycle.\n\\end{theorem}\n\\begin{proof}\n  Without loss of generality, $x_1 = n$.\n\n  Let $q = q_1 q_2 \\dots q_n$ be a permutation of $n$, and let $\\fpm(p) = q$,\n  where $\\fpm$ is the bijection from\n  Lemma~\\ref{lemma:permuations-transfomration}.\n  Note that the last cycle of $p$ starts with $x_1 = n$, and the entries in that\n  cycle of $q$ are precisely the entries on the right of $n$ in $q$. Therefore,\n  $p$ contains $x_1$, \\dots, $x_k$ in the same cycle if and only if $x_2$,\n  \\dots, $x_k$ are on the right of $n$ in $q$. It is easy to see that\n  there are $\\binom{n}{k} (k - 1)! (n - k)! = \\frac{n!}{k}$ such permutations\n  $q$.\n\\end{proof}\n\nAnother nice result states that for any $i \\in \\range{n}$, the probability that\n$i$ is in a cycle of length $k$ does not depend on $k$ and is equal to $1 / n$.\n\\begin{theorem}\n  Let $i \\in \\range{n}$. Then for all $k \\in \\range{n}$, there are exactly $(n - 1)!$\n  permutations of $\\range{n}$ in which the cycle containing $i$ is of length $k$.\n\\end{theorem}\n\\begin{proof}\n  Again, it is sufficient to prove the statement for $i = n$. Let\n  $q = q_1 q_2 \\dots q_n$ be a permutation of $n$, let $\\fpm(p) = q$, where\n  $\\fpm$ is the bijection from Lemma~\\ref{lemma:permuations-transfomration},\n  and let  $q_j = n$. Then the cycle $C$ containing $n$ in $p$ is of length\n  $n - j + 1$ as $n$ itself starts the last cycle. So if we want $C$ to have\n  length $k$, we must have $j = n + 1 - k$. However, there are clearly\n  $(n - 1)!$ permutations of length $n$ that contain $n$ in a given position,\n  and the proof follows.\n\\end{proof}\n\n\\section{Superpermutations}\nIn this section we consider the following problem. In the TV series ``The\nMelancholy of Haruhi Suzumiya'' there are $14$ episodes. The episodes feature\ntime travel and are chronologically challenging for the viewer. Moreover,\nthey were originally aired in a nonlinear order. When the series went to DVD,\nthe episodes were rearranged. Thus, it is something of an obsession for fans to\nrewatch the series over and over again, going through in many different\nchronologies. So the question is as follows: if you want to watch all the\nepisodes of the anime in every possible order, what is the shortest sequence of\nepisodes you need to watch?\n\nLet us first formulate a more formal question.\n\\begin{definition}\n  A sequence $w_1, \\dots, w_\\ell \\in \\range{n}$ is called an $n$-superpermutation iff\n  for any $p \\in \\permutations{n}$ there is $0 \\le i \\le \\ell - n$ such that\n  $w_{i + 1} = p(1)$, $w_{i + 2} = p(2)$, \\dots, and $w_{i + n} = p(n)$.\n\\end{definition}\nIn other words, the question we wish to study can be formulated in the\nfollowing way: what is the minimal length of a $14$-superpermutation?\n\nAs usual, we would like to study a more complicated question, what is the\nminimal length of an $n$-superpermutation. The answer for this question is\nunknown; however, there are relatively tight known upper and lower bounds. The\nknown upper bound was proven by Greg Egan in 2008.\n\\begin{theorem}\n  For all $n \\ge 4$, there is an $n$-superpermutation of length at most\n  \\[\n    n! + (n - 1)! + (n - 2)! + (n - 3)! + n - 3.\n  \\]\n\\end{theorem}\n\nHowever, the problem became especially famous because the best known lower bound\nwas proven by an anonymous author on 4chan. The anonymous proved the following\ntheorem.\n\\marginurl{%\n  The Verge: \\\\\\noindent\n  An anonymous 4chan post could help solve a 25-year-old math mystery\n}{bit.ly/2Gj8kpT}\n\\begin{theorem}\n  Every $n$-superpermutation has length at least\n  \\[\n    n! + (n - 1)! + (n - 2)! + n - 3.\n  \\]\n\\end{theorem}\n\\begin{proof}\n  First we need to define the notion of length between two permutations\n  $p, q \\in \\permutations{n}$. We say that the distance between $p$ and $q$ is equal to\n  $\\mathcal{D} = k$\n  iff there is a word $u$ of length $k$ such that the last $n$ letters of the\n  concatenation of  $w = p(1) p(2) \\dots p(n)$ and $u$ encodes the permutation\n  $q$ but any the last $n$ symbols of the concatenation of $w$ and any proper\n  prefix of $u$ is not a permutation; otherwise, we say that the distance is\n  equal to $+\\infty$.\n\n  Note that $n + \\mathcal{D}(p_1, \\dots, p_\\ell) =\n  \\sum_{i = 1}^{\\ell - 1} \\mathcal{D}(p_i, p_{i + 1}) \\le m$, where\n  \\begin{gather*}\n    w_1, w_2, \\dots, w_m \\in \\range{n} \\\\\n    \\text{and} \\\\\n    \\set{i_1 < i_2 < \\dots < i_\\ell} =\n    \\set[{\n      w_{i + 1} = p(1), \\dots, w_{i + n} = p(n)\n    }]{\n      i \\in \\range{m - n}\n    }.\n  \\end{gather*}\n  In other words, to find the minimal $n$-superpermutation, we need to find\n  a sequence of permutations $p_1, \\dots, p_\\ell$ containing all the permutations\n  and with the minimal $\\mathcal{D}$.\n\n  Instead of proving the statement right away, we prove four lower bounds, each\n  stronger but more complicated than the previous one.\n\n  \\begin{itemize}\n    \\item ($n! + n - 1$) We prove that\n      \\begin{equation}\n        \\label{equation:inequality-1}\n        \\mathcal{D}(p_1, \\dots, p_k) \\ge\n        C_0(p_1, \\dots, p_k) - 1,\n      \\end{equation}\n      where $C_0(p_1, \\dots, p_k)$ is equal to\n      the number of permutations occurring in $p_1, \\dots, p_k$.\n\n      It is easy to see that $C_0(p_1) = 1$ and $\\mathcal{D}(p_1) = 0$ so\n      $\\mathcal{D}(p_1) = 0 \\ge 1 - 1 = C_0(p_1) - 1$. We may also\n      note that for any $p_{k + 1} \\in \\permutations{n}$,\n      $C_0(p_1, \\dots, p_{k + 1}) \\le C_0(p_1, \\dots, p_k) + 1$ and\n      $\\mathcal{D}(p_k, p_{k + 1}) \\ge 1$. Therefore\n      \\begin{multline*}\n        \\mathcal{D}(p_1, \\dots, p_{k + 1}) \\ge\n        \\mathcal{D}(p_1, \\dots, p_k) + 1 \\ge \\\\\n        C_0(p_1, \\dots, p_k) + 1 - 1 \\ge\n        C_0(p_1, \\dots, p_{k + 1}) - 1.\n      \\end{multline*}\n\n      Combining (\\ref{equation:inequality-1}) with the fact that if all the\n      permutations occur in the sequence $p_1, \\dots, p_\\ell$, then\n      $C_0(p_1, \\dots, p_\\ell) = n!$,\n      we prove that any $n$-superpermutation has length at least $n! - 1 + n$.\n    \\item ($n! + (n - 1)! + (n - 2)$)\n      To prove this lower bound we need to introduce the notion of a $1$-cycle\n      class. A $1$-cycle class of permutations of $\\range{n}$ is a\n      subset $\\set{p_1, \\dots, p_n} \\subseteq \\permutations{n}$ such that $p_{k + 1}(n) =\n      p_k(1)$, and $p_{k + 1}(i) = p_k(i + 1)$ for $i \\in \\range{n - 1}$. For\n      example,\n      \\[\n        \\set{12345, 23451, 34512, 45123, 51234}\n      \\]\n      is a $1$-cycle class.\n\n      Let us now prove that\n      \\begin{equation}\n        \\label{equation:inequality-2}\n        \\mathcal{D}(p_1, \\dots, p_k) \\ge\n        C_0(p_1, \\dots, p_k) + C_1(p_1, \\dots, p_k) - 1,\n      \\end{equation}\n      where $C_1(p_1, \\dots, p_k)$ is equal to the number of complete $1$-cycle\n      classes in $p_1$, \\dots, $p_{k - 1}$ (a $1$-cycle class\n      $\\set{q_1, \\dots, q_n}$ is complete in $p_1$, \\dots, $p_t$ iff\n      $\\set{q_1, \\dots, q_n} \\subseteq \\set{p_1, \\dots, p_t}$).\n\n      It is easy to see that $C_0(p_1) = 1$, $C_1(p_1) = 0$ and\n      $\\mathcal{D}(p_1) = 0$ so\n      $\\mathcal{D}(p_1) = 0 \\ge 1 + 0 - 1 = C_0(p_1) + C_1(p_1) - 1$.\n\n      It is easy to see that for any $p_{k + 1} \\in \\permutations{n}$,\n      \\begin{gather*}\n        C_0(p_1, \\dots, p_{k + 1}) \\le C_0(p_1, \\dots, p_k) + 1  \\\\\n        C_1(p_1, \\dots, p_{k + 1}) \\le C_1(p_1, \\dots, p_k) + 1.\n      \\end{gather*}\n      Hence, if $\\mathcal{D}(p_k, p_{k + 1}) \\ge 2$, then\n      (\\ref{equation:inequality-2}) is true.\n\n      If $\\mathcal{D}(p_k, p_{k + 1}) = 1$, we claim that only one of $C_0$ and\n      $C_1$ increased. Note that $p_k$ and $p_{k + 1}$ are in the same $1$-\n      cycle class. Therefore\n      \\begin{enumerate}\n        \\item either this cycle is not complete yet and\n          \\[\n            C_1(p_1, \\dots, p_{k + 1}) = C_1(p_1, \\dots, p_k),\n          \\]\n        \\item or we finished the cycle and\n          \\[\n            C_0(p_1, \\dots, p_{k + 1}) = C_0(p_1, \\dots, p_k).\n          \\]\n      \\end{enumerate}\n      As a result, (\\ref{equation:inequality-2}) is true.\n\n      Combining (\\ref{equation:inequality-2}) with the\n      fact that if all the\n      permutations occur in the sequence $p_1, \\dots, p_\\ell$, then\n      $C_0(p_1, \\dots, p_\\ell) = n!$ and $C_1(p_1, \\dots, p_\\ell) \\ge\n      (n - 1)! - 1$,\n      we prove that any $n$-superpermutation has length at least\n      $n! + (n - 1)! - 1 - 1 + n$.\n    \\item ($n! + (n - 1)! + (n - 2)! + (n - 3)$)\n      To prove the final lower bound we need to define $2$-cycles. The $2$-cycle\n      generated by $p$ is the sequence $p_1, \\dots, p_{n(n - 1)}$ such that\n      $p_1 = p$, $\\mathcal{D}(p_{in + j}, p_{in + j + 1}) = 1$ for $i \\ge 0$\n      and $n \\ge j \\ge 1$, and $\\mathcal{D}(p_{in}, p_{in + 1}) = 2$ for\n      $i \\ge 1$ (note that the cycle is unique). For example,\n      $12345$, $23451$, $34512$, $45123$, $51234$, $23415$, $34152$, $41523$,\n      $15234$, $52341$, $34125$, $41253$, $12534$, $25341$, $53412$, $41235$,\n      $12354$, $23541$, $35412$, $54123$ is a $2$-cycle generated by $12345$,\n      it is also generated by $23415$, $34125$, and $41235$. More generally, we\n      have the following result. If a $2$-cycle is generated by $p$, then it is\n      generated by all $n - 1$ permutations obtained by fixing the\n      last entry of $p$ and cyclically permuting the other entries; i.e., by\n      $p$ and the permutations\n      \\begin{align*}\n        &p(2) \\dots p(n - 1) p(1)p(n), \\\\\n        &p(3) \\dots p(n - 1) p(1) p(2) p(n), \\\\\n        &\\dots, \\\\\n        &p(n - 1) p(1) \\dots p(n - 2) p(n).\n      \\end{align*}\n      We say that a sequence $p_1$, \\dots, $p_k$ enters the $2$-cycle generated\n      by $p$ if $p_{i + 1} = p$ and $\\mathcal{D}(p_i, p_{i + 1}) \\ge 2$.\n      Because each $2$-cycle contains only $n (n - 1)$ permutations, any\n      sequence containing all the permutations must enter at least $(n - 2)!$\n      different $2$-cycles.\n\n      Let us now prove that\n      \\begin{multline}\n        \\label{equation:inequality-3}\n        \\mathcal{D}(p_1, \\dots, p_k) \\ge \\\\\n        C_0(p_1, \\dots, p_k) + C_1(p_1, \\dots, p_k) + C_2(p_1, \\dots, p_k) - 2,\n      \\end{multline}\n      where $C_2(p_1, \\dots, p_k)$ is equal to the number of entered $2$-cycles.\n\n      It is easy to see that $C_0(p_1) = 1$, $C_1(p_1) = 0$, $C_2(p_1) = 1$, and\n      $\\mathcal{D}(p_1) = 0$ so\n      $\\mathcal{D}(p_1) = 0 \\ge 1 + 0 + 1 - 2 =\n      C_0(p_1) + C_1(p_1) + C_2(p_1)- 2$.\n\n      It is easy to see that for any $p_{k + 1} \\in \\permutations{n}$,\n      \\begin{gather*}\n        C_0(p_1, \\dots, p_{k + 1}) \\le C_0(p_1, \\dots, p_k) + 1  \\\\\n        C_1(p_1, \\dots, p_{k + 1}) \\le C_1(p_1, \\dots, p_k) + 1 \\\\\n        C_2(p_1, \\dots, p_{k + 1}) \\le C_2(p_1, \\dots, p_k) + 1.\n      \\end{gather*}\n      Hence, if $\\mathcal{D}(p_k, p_{k + 1}) \\ge 3$, then\n      (\\ref{equation:inequality-3}) is true.\n\n      If $k = 1$, then we are still\n      inside the last $2$-cycle and inside the last $1$-cycle class, therefore\n      like in the previous case (\\ref{equation:inequality-3}) is true.\n\n      If $k = 2$, then we claim that if the value of $C_1$ increases, then\n      the value of $C_2$ cannot change. Suppose that the value of $C_1$\n      increases. This means that the permutation $p_k$ complete the $1$-cycle\n      class and we have not visited it before. Since we\n      completed the $1$-cycle class, we visited the permutation\n      $q = p_k(2) p_k(3) \\dots p_k(n) p_k(1)$ by $2$-step.\n      It is also possible to note that $q$ and\n      $p_{k + 1}$ generate the same cyclic class and it\n      implies that $C_2(p_1, \\dots, p_{k + 1}) = C_2(p_1, \\dots, p_k)$.\n      As a result, (\\ref{equation:inequality-3}) is true.\n\n      Combining (\\ref{equation:inequality-2}) with the\n      fact that if all the\n      permutations occur in the sequence $p_1, \\dots, p_\\ell$, then\n      $C_0(p_1, \\dots, p_\\ell) = n!$, $C_1(p_1, \\dots, p_\\ell) \\ge\n      (n - 1)! - 1$, and $C_2(p_1, \\dots, p_\\ell) \\ge (n - 2)!$,\n      we prove that any $n$-superpermutation has length at least\n      $n! + (n - 1)! - 1 + (n - 2)! - 2 + n$.\n  \\end{itemize}\n\\end{proof}\n\nUsing this inequality we may conclude that real fans of\n``The Melancholy of Haruhi Suzumiya'' need to watch at least $93884313611$\nepisodes which takes around $3572462$ years.\n\n\n\\begin{chapterendexercises}\n  \\exercise[recommended] Recall that the number of inverses in a permutation \n    $p \\in \\permutations{n}$ is the number of pairs $i, j$ such that $i < j$ and \n    $p(i) > p(j)$. Let $I(n, k)$ denotes the number of permutations with $k$\n    inversions. Prove that $I(n, k) = I(n, \\binom{n}{2} - k)$.\n  \\exercise Let $n$, $b_1$, \\dots, and $b_k$ be positive integers such that \n    $b_1 + \\dots + b_k \\le n$. Show that $b_1! b_2! \\dots b_n! \\le n!$.\n  \\exercise[recommended] Find an explicit formula for $c(n, n - 2)$.\n    \\begin{solution}\n      The solution of this problem is similar to the solution of the problem for\n      $S(n, n - 2)$.\n\n      Note that there are two types of permutations with $n - 2$ cycles.\n      \\begin{enumerate}\n        \\item The first type consists of permutations with one cycle of length\n          $3$ and $n - 3$ cycles of length $1$. Note that there are $\\binom{n}{3}$\n          ways to choose elements of the cycle of length $3$ and there are $2$\n          ways to form a cycle from these elements. Hence, there are $2 \\cdot\n          \\binom{n}{3}$ permutations of this type.\n        \\item The second type consists of permutations with two cycles of length $2$\n          and $n - 4$ cycles of length $1$. Note that there are $\\binom{n}{2}$\n          ways to select elements of the first cycle and $\\binom{n - 2}{2}$ ways\n          to select the second cycle. Hence, there are $\\frac{\\binom{n}{2} \\cdot\n          \\binom{n - 2}{2}}{2}$ permutations of this type (we divide by $2$ since\n          we may reorder the cycles).\n      \\end{enumerate}\n\n      As a result, the final answer is $2 \\cdot \\binom{n}{3} + \\frac{\\binom{n}{2}\n      \\cdot \\binom{n - 2}{2}}{2}$.\n    \\end{solution}\n  \\exercise Prove that for any fixed $k$, the function $c(n, n - k)$ is a\n    polynomial function of $n$. Find the degree of that polynomial.\n  \\exercise Find a reccurent relation for the number of permutations $\\pi \\in\n    \\permutations{n}$ such that $\\pi^3(x) = x$ for all $x \\in \\range{n}$.\n  \\exercise Let $p$ be a permutation of $\\range{n}$. We associate a permutation matrix\n    $M^{(p)}$ to $p$ as follows. Let $M^{(p)}_{i, j} = 1$ if $p(i) = j$, and let\n    $M^{(p)}_{i, j} = 0$ otherwise. Prove that $|\\det M^{(p)}| = 1$.\n  \\exercise Prove that if $p$ and $q$ are two permutations, then\n    $M^{(p)} M^{(q)} = M^{(pq)}$.\n  \\exercise Let $p$ be a permutation of the cyclic type $(c_1, \\dots, c_n)$.\n    Show that $p^\\ell = 1 2 3 \\dots n$, where\n    \\[\n      \\ell = \\prod_{i ~:~ c_i \\neq 0} i.\n    \\]\n    \\begin{solution}\n      First we prove the following statement, if $p \\in \\permutations{n}$ is a cycle of\n      length $\\ell$, then $p^\\ell = 12 \\dots n$. Indeed, assume $p = (i_0,\n      \\dots, i_{\\ell - 1})$;note that $p(i_j) = i_{(j + 1) \\mod \\ell}$,\n      therefore, $p^\\ell(i_j) = i_{(j + \\ell) \\mod \\ell} = i_j$. It is also\n      clear that if $p$ is a cycle of length $\\ell$, then $p^{d\\ell} = \n      12 \\dots n$ for any $d \\in \\N$.\n\n      Another part of the argument is the following let $p$ and $q$ be two\n      disjoint cycles, then $pq = qp$ (this can be easily derived from the\n      definition of the composition).\n\n      As a result, if a permutation $p = q_1 q_2 \\dots q_k$, where $q_i$s are\n      disjoint cycles, then $p^\\ell = q^\\ell_1 q^\\ell_2 \\dots q^\\ell_k$. Hence,\n      if $\\ell = \\prod_{i ~:~ c_i \\neq 0} i$, $p^\\ell = 1 2 \\dots n$.\n    \\end{solution}\n  \\exercise Show that any permutation can be obtained as a product of some\n    transpositions; i.e., cycles of length $2$.\n    \\begin{solution}\n      It is easy to see that it is enough to prove the statement for the cycles.\n      Consider a permuatation $(i_1, \\dots, i_k)$. It is clear that $(i_1, i_2)\n      (i_2, i_3)$ is equal to $(i_1, i_2, i_3)$ and moreover $(i_1, i_2) (i_2,\n      i_3) \\dots (i_{k - 1}, i_k)$ is equal to $(i_1, \\dots, i_k)$. Therefore we\n      proved the statement.\n    \\end{solution}\n  \\exercise Show that any permuation from $\\permutations{n}$ can be expressed as\n    a product of $(1, 2)$, \\dots, $(n - 1, n)$ (each permuation can be used\n    multiple times).\n  \\exercise Show that for any $n \\in \\N$, there are two permuations $p, q \\in\n    \\permutations{n}$ such that any permuation from $\\permutations{n}$ can be expressed as\n    their product (each permuation can be used multiple times).\n    \\begin{solution}\n      First, let us note that any permuation can be obtained as a product of the\n      permuations $(1, 2)$, \\dots, $(n - 1, n)$. It is enough to prove that any\n      permutation $(i ,j)$ ($i < j$) can be obtained from them. Note that \n      $(i + 1, j) \\dots (j - 2, j)(j - 1, j)(i, i + 1) \\dots (j - 1, j) = \n        (i, j)$.\n\n      So to prove the statement we need to came up with two permutations such\n      that we can obtain $(i, i + 1)$ as their product for any $i \\in [n - 1]$.\n      Consider $(1, 2)$ and $(1, 2, \\dots, n)$. Note that $(1, 2, \\dots, n)^n =\n      1 2 \\dots n$. Hence, $(1, 2, \\dots, n)^{n - 1} = (1, 2, \\dots, n)^{-1}$.\n      It is also easy to see that \n      $(i, i + 1) = (1, 2, \\dots, n)^{-i} (1, 2) (1, 2, \\dots, n)^i$.\n    \\end{solution}\n  \\exercise[recommended] Prove that permutations $p$ and $p^{-1}$ are of the\n    same cycle type for any permutation $p$.\n  \\exercise[recommended] A permutation $p$ is called a nontrivial involution if\n    $p^2 = 1 2 \\dots n$, but $p \\neq 1 2 \\dots n$. Prove that if $n > 1$, the\n    number of nontrivial involutions in $\\permutations{n}$ is odd.\n    \\begin{solution}\n      Let $p \\in \\permutations{n}$ and $p^2 \\neq \\identity{\\range{n}}$; it is easy to see\n      that $(p^{-1})^2 \\neq \\identity{\\range{n}}$. Therefore it is possible to\n      split all the permutations from the set\n      $\\set[p^2 \\neq \\identity{\\range{n}}]{p \\in \\permutations{n}}$ into pairs $p$ and\n      $p^{-1}$. Hence, the size of the set\n      $\\set[p^2 \\neq \\identity{\\range{n}}]{p \\in \\permutations{n}}$ is even; we\n      may also note that the size of $\\permutations{n}$ is also even. As a\n      result, the size of $\\set[p^2 = I]{p \\in \\permutations{n}}$ is even as well, but it\n      implies that $\\set[{p^2 = I \\text{ and } p \\neq I}]{p \\in\n      \\permutations{n}}$ is odd.\n    \\end{solution}\n  \\exercise There are $n$ seats in a bus; $n - 1$ people are assigned seats in\n    this bus. However, a dog came to the bus and took one of the seats uniformly\n    at random. So each next passenger either takes his or her seat if it is\n    available, or a uniformly random available seat otherwise. What is the\n    probability that the last passenger seats on the assigned seat?\n\\end{chapterendexercises}\n", "meta": {"hexsha": "9955a9a46dea22ef42d3d797f151b3d004e08546", "size": 26371, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_4/chapter_22_permutations.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_4/chapter_22_permutations.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_4/chapter_22_permutations.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 46.6743362832, "max_line_length": 98, "alphanum_fraction": 0.6235637632, "num_tokens": 9173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8856314798554445, "lm_q1q2_score": 0.713493219480671}}
{"text": "\\chapter{Compactness}\nOne of the most important notions of topological spaces is that of \\emph{compactness}.\nIt generalizes the notion of ``closed and bounded'' in Euclidean space\nto any topological space\n(e.g.\\ see \\Cref{thm:bzw}).\n\nFor metric spaces, there are two equivalent ways of formulating compactness:\n\\begin{itemize}\n\t\\ii A ``natural'' definition using \\emph{sequences}, called sequential compactness.\n\t\\ii A less natural definition using open covers.\n\\end{itemize}\nAs I alluded to earlier, sequences in metric spaces are super nice,\nbut sequences in general topological spaces \\emph{suck} (to the point where\nI didn't bother to define convergence of general sequences).\nSo it's the second definition that will be used for general spaces.\n\n\\section{Definition of sequential compactness}\n\\prototype{$[0,1]$ is compact, but $(0,1)$ is not.}\nTo emphasize, compactness is one of the\n\\emph{best} possible properties that a metric space can have.\n\\begin{definition}\n\tA \\vocab{subsequence} of an infinite sequence\n\t$x_1, x_2, \\dots$ is exactly what it sounds like:\n\ta sequence $x_{i_1}, x_{i_2}, \\dots$\n\twhere $i_1 < i_2 < \\cdots$ are positive integers.\n\tNote that the sequence is required to be infinite.\n\\end{definition}\nAnother way to think about this is ``selecting infinitely many terms''\nor ``deleting some terms'' of the sequence, depending on whether\nyour glass is half empty or half full.\n\n\\begin{definition}\n\tA metric space $M$ is \\vocab{sequentially compact} if\n\tevery sequence has a subsequence which converges.\n\\end{definition}\nThis time, let me give some non-examples before the examples.\n\\begin{example}\n\t[Non-examples of compact metric spaces]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The space $\\RR$ is not compact: consider the sequence $1,2,3,4,\\dots$.\n\t\tAny subsequence explodes, hence $\\RR$ cannot possibly be compact.\n\t\t\\ii More generally, if a space is\n\t\tnot bounded it cannot be compact.\n\t\t(You can prove this if you want.)\n\t\t\\ii The open interval $(0,1)$ is bounded but not compact:\n\t\tconsider the sequence $\\frac12, \\frac13, \\frac14, \\dots$.\n\t\tNo subsequence can converge to a point in $(0,1)$ because the sequence ``converges to $0$''.\n\t\t\\ii More generally, any space which is not complete cannot be compact.\n\t\\end{enumerate}\n\\end{example}\n\nNow for the examples!\n\\begin{ques}\n\tShow that a finite set is compact.\n\t(Pigeonhole Principle.)\n\\end{ques}\n\\begin{example}[Examples of compact spaces]\n\tHere are some more examples of compact spaces.\n\tI'll prove they're compact in just a moment;\n\tfor now just convince yourself they are.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $[0,1]$ is compact. Convince yourself of this!\n\t\tImagine having a large number of dots in the unit interval\\dots\n\t\t\\ii The surface of a sphere, $S^2 = \\left\\{ (x,y,z) \\mid x^2+y^2+z^2=1 \\right\\}$ is compact.\n\t\t\\ii The unit ball $B^2 = \\left\\{ (x,y) \\mid x^2+y^2 \\le 1 \\right\\}$ is compact.\n\t\t\\ii The \\vocab{Hawaiian earring} living in $\\RR^2$ is compact:\n\t\tit consists of mutually tangent circles of radius $\\frac 1n$ for each $n$,\n\t\tas in \\Cref{fig:hawaiian}.\n\t\\end{enumerate}\n\\end{example}\n\\begin{figure}[ht]\n\t\\centering\n\t\\begin{asy}\n\t\tsize(4cm);\n\t\tfor (int n=1; n<=15; ++n) draw(CP(dir(0)/n, origin));\n\t\tfill(CP(dir(0)/15, origin), black);\n\t\\end{asy}\n\t\\caption{Hawaiian Earring.}\n\t\\label{fig:hawaiian}\n\\end{figure}\n\nTo aid in generating more examples, we remark:\n\\begin{proposition}[Closed subsets of compacts]\n\tClosed subsets of sequentially compact sets are compact.\n\\end{proposition}\n\\begin{ques}\n\tProve this. (It should follow easily from definitions.)\n\\end{ques}\n\nWe need to do a bit more work for these examples, which we do in the next section.\n\n\\section{Criteria for compactness}\n%Quick note: right now I've only defined compactness for metric spaces.\n%In the next section I'll define compactness for general spaces, but\n%all the results in this section will still remain true.\n%However the proofs become much harder (in particular, \\Cref{thm:tychonoff}\n%becomes notoriously difficult).\n%So you should assume all spaces in this section are metric spaces.\n\n\\begin{theorem}\n\t[Tychonoff's theorem] \n\t\\label{thm:tychonoff}\n\tIf $X$ and $Y$ are compact spaces, then so is $X \\times Y$.\n\\end{theorem}\n\\begin{proof}\n\t\\Cref{prob:tychonoff}.\n\\end{proof}\n\nWe also have:\n\\begin{theorem}[The interval is compact]\n\t\\label{thm:interval_compact}\n\t$[0,1]$ is compact.\n\\end{theorem}\n\\begin{proof}\n\tKilled by \\Cref{thm:bzw};\n\thowever, here is a sketch of a direct proof.\n\tSplit $[0,1]$ into $[0,\\half] \\cup [\\half,1]$.\n\tBy Pigeonhole, infinitely many terms of the sequence lie in the left half (say);\n\tlet $x_1$ be the first one and then keep only the terms in the left half after $x_1$.\n\tNow split $[0, \\half]$ into $[0,\\frac14] \\cup [\\frac14,\\half]$.\n\tAgain, by Pigeonhole, infinitely many terms fall in some half; pick one of them, call it $x_2$.\n\tRinse and repeat.\n\tIn this way we generate a sequence $x_1$, $x_2$, \\dots which is Cauchy,\n\timplying that it converges since $[0,1]$ is complete.\n\\end{proof}\n\nNow we can prove the main theorem about Euclidean space:\nin $\\RR^n$, compactness is equivalent to being ``closed and bounded''.\n\\begin{theorem}[Bolzano-Weierstra\\ss]\n\tA subset of $\\RR^n$ is compact if and only if it is closed and bounded.\n\t\\label{thm:fakeBW}\n\\end{theorem}\n\\begin{ques}\n\tWhy does this imply the spaces in our examples are compact?\n\\end{ques}\n\\begin{proof}\n\tWell, look at a closed and bounded $S \\subseteq \\RR^n$.\n\tSince it's bounded, it lives inside some box $[a_1, b_1] \\times [a_2, b_2] \\times \\dots \\times [a_n, b_n]$.\n\tBy Tychonoff's theorem, since each $[a_i, b_i]$ is compact the entire box is.\n\tSince $S$ is a closed subset of this compact box, we're done.\n\\end{proof}\n\nOne really has to work in $\\RR^n$ for this to be true!\nIn other spaces, this criterion can easily fail.\n\\begin{example}[Closed and bounded but not compact]\n\tLet $S = \\{s_1, s_2, \\dots\\}$ be any infinite set equipped with the discrete metric.\n\tThen $S$ is closed (since all convergent sequences are constant sequences)\n\tand $S$ is bounded (all points are a distance $1$ from each other)\n\tbut it's certainly not compact since the sequence $s_1, s_2, \\dots$ doesn't converge.\n\\end{example}\n\nThe Bolzano-Weierstrass theorem, which is \\Cref{thm:bzw}, tells you exactly\nwhich sets are compact in metric spaces in a geometric way.\n\n\\section{Compactness using open covers}\n\\prototype{$[0,1]$ is compact.}\nThere's a second related notion of compactness which I'll now define.\nThe following definitions might appear very unmotivated, but bear with me.\n\\begin{definition}\n\tAn open cover of a topological space $X$\n\tis a collection of open sets $\\{U_\\alpha\\}$\n\t(possibly infinite or uncountable) which \\emph{cover} it:\n\tevery point in $X$ lies in at least one of the $U_\\alpha$,\n\tso that \\[ X = \\bigcup U_\\alpha. \\]\n\tSuch a cover is called an \\vocab{open cover}.\n\n\tA \\vocab{subcover} is exactly what it sounds like:\n\tit takes only some of the $U_\\alpha$,\n\twhile ensuring that $X$ remains covered.\n\\end{definition}\n\nSome art:\n\\begin{center}\n\\begin{asy}\nsize(12cm);\npath blob = (-8,3)..(-10,1)..(-9.4,0)..(-8.2,-3)..(-8,-4)\n\t..(-2,-4.3)..(2,-4.2)..(8,-4)\n\t..(8.6,-2)..(8.2,0.5)..(8,3)\n\t..(4,3.3)..(0,3.1)..(-6,2.9)..cycle;\nvoid open_ball(pair O, real r, pen p) {\n\tdot(O, p);\n\tfilldraw(CR(O, r), p+opacity(0.1), p+dashed);\n}\n\nfilldraw(blob, cyan+opacity(0.2), blue+0.7);\nopen_ball((-7,0.8), 3.5, red);\nopen_ball((-4.7,-1.2), 4.6, orange);\nopen_ball((-1.7,-0.3), 3.9, red);\nopen_ball((1.4,0.9), 2.9, yellow);\nopen_ball((2.5,-0.9), 3.7, orange);\nopen_ball((0.4,-3.7), 1.3, yellow);\nopen_ball((4.3,0.8), 2.7, red);\nopen_ball((6.3,1.8), 2.4, orange);\nopen_ball((6.0,-2.4), 4.0, yellow);\n\nlabel(\"$X$\", (8,3), dir(5), blue);\n\nlabel(scale(2)*\"$X = \\bigcup_\\alpha U_\\alpha$\", (0,4), blue);\n\\end{asy}\n\\end{center}\n\n\n\\begin{definition}\n\tA topological space $X$ is \\vocab{quasicompact}\n\tif \\emph{every} open cover has a finite subcover.\n\tIt is \\vocab{compact} if it is also Hausdorff.\n\\end{definition}\n\\begin{remark}\n\tThe ``Hausdorff'' hypothesis that I snuck in\n\tis a sanity condition which is not worth worrying about unless you're\n\tworking on the algebraic geometry chapters,\n\tsince all the spaces you will deal with are Hausdorff.\n\t(In fact, some authors don't even bother to include it.)\n\tFor example all metric spaces are Hausdorff\n\tand thus this condition can be safely ignored\n\tif you are working with metric spaces.\n\\end{remark}\nWhat does this mean? Here's an example:\n\\begin{example}[Example of a finite subcover]\n\tSuppose we cover the unit square $M = [0,1]^2$ by\n\tputting an open disk of diameter $1$ centered at every point\n\t(trimming any overflow).\n\tThis is clearly an open cover because,\n\twell, every point lies in \\emph{many} of the open sets,\n\tand in particular is the center of one.\n\n\tBut this is way overkill -- we only need about four\n\tof these circles to cover the whole square.\n\tThat's what is meant by a ``finite subcover''.\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(4cm);\n\t\t\tdraw(shift( (-0.5,-0.5) )*unitsquare, black+1);\n\t\t\treal d = 0.4;\n\t\t\treal r = 0.5;\n\t\t\tdraw(CR(dir( 45)*d, r), dotted);\n\t\t\tdraw(CR(dir(135)*d, r), dotted);\n\t\t\tdraw(CR(dir(225)*d, r), dotted);\n\t\t\tdraw(CR(dir(315)*d, r), dotted);\n\t\t\\end{asy}\n\t\\end{center}\n\\end{example}\n\nWhy do we care?\nBecause of this:\n\\begin{theorem}[Sequentially compact $\\iff$ compact]\n\tA metric space $M$ is sequentially compact if and only if it is compact.\n\t\\label{thm:compactness_metric}\n\\end{theorem}\nWe defer the proof to the last section.\n\nThis gives us the motivation we wanted for our definition.\nSequential compactness was a condition that made sense.\nThe open-cover definition looked strange,\nbut it turned out to be equivalent.\nBut we now prefer it, because we have seen that\nwhenever possible we want to resort to open-set-only based definitions:\nso that e.g.\\ they are preserved under homeomorphism.\n\n\\begin{example}[An example of non-compactness]\n\tThe space $X = [0,1)$ is not compact in either sense. % chktex 9\n\tWe can already see it is not sequentially compact, because it is not even complete (look at $x_n = 1 - \\frac 1n$).\n\tTo see it is not compact under the covering definition, consider the sets\n\t\\[ U_m = \\left[0, 1 - \\frac{1}{m+1} \\right) \\] % chktex 9\n\tfor $m = 1, 2, \\dots$. Then $X = \\bigcup U_i$; hence the $U_i$ are indeed a cover.\n\tBut no finite collection of the $U_i$'s will cover $X$.\n\\end{example}\n\\begin{ques}\n\tConvince yourself that $[0,1]$ \\emph{is} compact;\n\tthis is a little less intuitive than it being sequentially compact.\n\\end{ques}\n\\begin{abuse}\n\tThus, we'll never call a metric space ``sequentially compact'' again\n\t--- we'll just say ``compact''.\n\t(Indeed, I kind of already did this in the previous few sections.)\n\\end{abuse}\n\n\n\\section{Applications of compactness}\nCompactness lets us reduce \\emph{infinite} open covers to finite ones.\nActually, it lets us do this even if the open covers are \\emph{blithely stupid}.\nVery often one takes an open cover consisting\nof an open neighborhood of $x \\in X$ for every single point $x$ in the space;\nthis is a huge number of open sets,\nand yet compactness lets us reduce to a finite set.\n\nTo give an example of a typical usage:\n\\begin{proposition}[Compact $\\implies$ totally bounded]\n\tLet $M$ be compact. Then $M$ is totally bounded.\n\\end{proposition}\n\\begin{proof}[Proof using covers]\n\tFor every point $p \\in M$, take an $\\eps$-neighborhood of $p$, say $U_p$.\n\tThese cover $M$ for the horrendously stupid reason that each point $p$ is\n\tat the very least covered by its open neighborhood $U_p$.\n\tCompactness then lets us take a finite subcover.\n\\end{proof}\n\nNext, an important result about maps between compact spaces.\n\\begin{theorem}[Images of compacts are compact]\n\tLet $f \\colon X \\to Y$ be a continuous function, where $X$ is compact.\n\tThen the image \\[ f\\im(X) \\subseteq Y \\] is compact.\n\\end{theorem}\n\\begin{proof}[Proof using covers]\n\tTake any open cover $\\{V_\\alpha\\}$ in $Y$ of $f\\im(X)$.\n\tBy continuity of $f$,\n\tit pulls back to an open cover $\\{U_\\alpha\\}$ of $X$.\n\tThus some finite subcover of this covers $X$.\n\tThe corresponding $V$'s cover $f\\im(X)$.\n\\end{proof}\n\\begin{ques}\n\tGive another proof using the sequential definitions\n\tof continuity and compactness.\n\t(This is even easier.)\n\\end{ques}\n\nSome nice corollaries of this:\n\\begin{corollary}\n\t[Extreme value theorem]\n\tLet $X$ be compact and consider a continuous function $f : X \\to \\RR$.\n\tThen $f$ achieves a \\emph{maximum value} at some point,\n\ti.e.\\ there is a point $p \\in X$ such that $f(p) \\ge f(q)$ for any\n\tother $q \\in X$.\n\\end{corollary}\n\\begin{corollary}\n\t[Intermediate value theorem]\n\tConsider a continuous function $f: [0,1] \\to \\RR$.\n\tThen the image of $f$ is of the form $[a,b]$ for some real numbers $a \\le b$.\n\\end{corollary}\n\n\\begin{proof}[Sketch of Proof]\n\tThe point is that the image of $f$ is compact in $\\RR$,\n\tand hence closed and bounded.\n\tYou can convince yourself that the closed sets are just unions of closed intervals.\n\tThat implies the extreme value theorem.\n\n\tWhen $X=[0,1]$, the image is also connected,\n\tso there should only be one closed interval in $f\\im([0,1])$.\n\tSince the image is bounded, we then know it's of the form $[a,b]$.\n\t(To give a full proof, you would use the so-called \\emph{least upper bound}\n\tproperty, but that's a little involved for a bedtime story;\n\talso, I think $\\RR$ is boring.)\n\\end{proof}\n\n\\begin{example}\n\t[$1/x$]\n\tThe compactness hypothesis is really important here.\n\tOtherwise, consider the function\n\t\\[ (0,1) \\to \\RR \\quad \\text{ by } \\quad\n\t\tx \\mapsto \\frac 1x. \\]\n\tThis function (which you plot as a hyperbola) is not bounded;\n\tessentially, you can see graphically that the issue\n\tis we can't extend it to a function on $[0,1]$ because it explodes near $x=0$.\n\\end{example}\n\nOne last application: if $M$ is a compact metric space,\nthen continuous functions $f : M \\to N$\nare continuous in an especially ``nice'' way:\n\\begin{definition}\n\tA function $f : M \\to N$ of metric spaces\n\tis called \\vocab{uniformly continuous}\n\tif for any $\\eps > 0$, there exists a $\\delta > 0$\n\t(depending only on $\\eps$) such that \n\twhenever $d_M(x,y) < \\delta$ we also have $d_N(fx, fy) < \\eps$.\n\\end{definition}\nThe name means that for $\\eps > 0$,\nwe need a $\\delta$ that works for \\emph{every point} of $M$.\n\\begin{example}[Uniform continuity]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The functions $\\RR$ to $\\RR$ of the form\n\t\t$x \\mapsto ax+b$ are all uniformly continuous,\n\t\tsince one can always take $\\delta = \\eps/|a|$ (or $\\delta=1$ if $a=0$).\n\t\t\\ii Actually, it is true that a differentiable function $\\RR \\to \\RR$\n\t\twith a bounded derivative is uniformly continuous.\n\t\t(The converse is false for the reason that uniformly continuous\n\t\tdoesn't imply differentiable at all.)\n\t\t\\ii The function $f : \\RR \\to \\RR$ by $x \\mapsto x^2$\n\t\tis \\emph{not} uniformly continuous, since for large $x$,\n\t\ttiny $\\delta$ changes to $x$ lead to fairly large changes in $x^2$.\n\t\t(If you like, you can try to prove this formally now.)\n\t\t\n\t\tThink $f(2017.01) - f(2017) > 40$;\n\t\teven when $\\delta = 0.01$, one can still cause large changes in $f$.\n\n\t\t\\ii However, when restricted to $(0,1)$ or $[0,1]$\n\t\tthe function $x \\mapsto x^2$ becomes uniformly continuous.\n\t\t(For $\\eps > 0$ one can now pick for example $\\delta = \\min\\{1,\\eps\\}/3$.)\n\n\t\t\\ii The function $(0,1) \\to \\RR$ by $x \\mapsto 1/x$ is \\emph{not}\n\t\tuniformly continuous (same reason as before).\n\t\\end{enumerate}\n\\end{example}\n\nNow, as promised:\n\\begin{proposition}[Continuous on compact $\\implies$ uniformly continuous]\n\tIf $M$ is compact and $f \\colon M \\to N$ is continuous,\n\tthen $f$ is uniformly continuous.\n\\end{proposition}\n\\begin{proof}[Proof using sequences]\n\tFix $\\eps > 0$, and assume for contradiction that for every $\\delta = 1/k$\n\tthere exists points $x_k$ and $y_k$ within $\\delta$ of each\n\tother but with images $\\eps > 0$ apart.\n\tBy compactness, take a convergent subsequence $x_{i_k} \\to p$.\n\tThen $y_{i_k} \\to p$ as well, since the $x_k$'s and $y_k$'s are close to each other.\n\tSo both sequences $f(x_{i_k})$ and $f(y_{i_k})$ should converge to $f(p)$ by sequential continuity,\n\tbut this can't be true since the two sequences are always $\\eps$ apart.\n\\end{proof}\n\n\\section{(Optional) Equivalence of formulations of compactness}\nWe will prove that:\n\\begin{theorem}\n\t[Heine-Borel for general metric spaces]\n\tFor a metric space $M$, the following are equivalent:\n\t\\begin{enumerate}[(i)]\n\t\t\\ii Every sequence has a convergent subsequence,\n\t\t\\ii The space $M$ is complete and totally bounded, and\n\t\t\\ii Every open cover has a finite subcover.\n\t\\end{enumerate}\n\\end{theorem}\nWe leave the proof that (i) $\\iff$ (ii) as \\Cref{thm:bzw};\nthe idea of the proof is much in the spirit of \\Cref{thm:interval_compact}.\n\\begin{proof}\n\t[Proof that (i) and (ii) $\\implies$ (iii)]\n\tWe prove the following lemma, which is interesting in its own right.\n\t\\begin{lemma}\n\t\t[Lebesgue number lemma]\n\t\tLet $M$ be a compact metric space and $\\{U_\\alpha\\}$ an open cover.\n\t\tThen there exists a real number $\\delta > 0$,\n\t\tcalled a \\vocab{Lebesgue number} for that covering,\n\t\tsuch that the $\\delta$-neighborhood of any point\n\t\t$p$ lies entirely in some $U_\\alpha$.\n\t\\end{lemma}\n\t\\begin{subproof}[Proof of lemma]\n\t\tAssume for contradiction that for every $\\delta = 1/k$\n\t\tthere is a point $x_k \\in M$\n\t\tsuch that its $1/k$-neighborhood isn't contained in any $U_\\alpha$.\n\t\tIn this way we construct a sequence $x_1$, $x_2$, \\dots;\n\t\tthus we're allowed to take a subsequence which converges to some $x$.\n\t\tThen for every $\\eps > 0$ we can find an integer $n$ such that $d(x_n, x) + 1/n < \\eps$;\n\t\tthus the $\\eps$-neighborhood at $x$ isn't contained in any $U_\\alpha$ for every $\\eps > 0$.\n\t\tThis is impossible, because we assumed $x$ was covered by some open set.\n\t\\end{subproof}\n\tNow, take a Lebesgue number $\\delta$ for the covering.\n\tSince $M$ is totally bounded, finitely many $\\delta$-neighborhoods cover the space,\n\tso finitely many $U_\\alpha$ do as well.\n\\end{proof}\n\n\\begin{proof}\n\t[Proof that (iii) $\\implies$ (ii)]\n\tOne step is immediate:\n\t\\begin{ques}\n\t\tShow that the covering condition $\\implies$ totally bounded.\n\t\\end{ques}\n\tThe tricky part is showing $M$ is complete.\n\tAssume for contradiction it isn't and thus that the sequence $(x_k)$ is Cauchy,\n\tbut it doesn't converge to any particular point.\n\t\\begin{ques}\n\t\tShow that this implies for each $p \\in M$, there is an $\\eps_p$-neighborhood $U_p$\n\t\twhich contains at most finitely many of the points of the sequence $(x_k)$.\n\t\t(You will have to use the fact that $x_k \\not\\to p$ and $(x_k)$ is Cauchy.)\n\t\\end{ques}\n\tNow if we consider $M = \\bigcup_p U_p$ we get a\n\tfinite subcover of these open neighborhoods;\n\tbut this finite subcover can only cover finitely\n\tmany points of the sequence, by contradiction.\n\\end{proof}\n\n\n\\section{\\problemhead}\nThe later problems are pretty hard;\nsome have the flavor of IMO 3/6-style constructions.\nIt's important to draw lots of pictures so one can tell what's happening.\n% I'd be happy to learn of any easier ones.\nOf these \\Cref{thm:bzw} is definitely my favorite.\n\n\\begin{problem}\n\tShow that the closed interval $[0,1]$ and\n\topen interval $(0,1)$ are not homeomorphic.\n\t\\begin{hint}\n\t\t$[0,1]$ is compact.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tCompactness is preserved under homeomorphism,\n\t\tbut $[0,1]$ is compact while $(0,1)$ is not.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\tLet $X$ be a topological space with the discrete topology.\n\tUnder what conditions is $X$ compact?\n\t\\begin{hint}\n\t\tIf and only if it is finite.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\t[The cofinite topology is quasicompact only]\n\tWe let $X$ be an infinite set and equip it with the\n\t\\vocab{cofinite topology}:\n\tthe open sets are the empty set and complements of finite sets.\n\tThis makes $X$ into a topological space.\n\tShow that $X$ is quasicompact but not Hausdorff.\n\\end{problem}\n\n\\begin{problem}\n\t[Cantor's intersection theorem]\n\t\\label{prob:cantor_intersect}\n\tLet $X$ be a compact topological space, and suppose\n\t\\[ X = K_0 \\supseteq K_1 \\supseteq K_2 \\supseteq \\dots \\]\n\tis an infinite sequence of nested nonempty closed subsets.\n\tShow that $\\bigcap_{n \\ge 0} K_n \\neq \\varnothing$.\n\\end{problem}\n\n%\\begin{sproblem}[Compact Implies Bounded]\n%\tLet $f : X \\to \\RR$ be a continuous function,\n%\twhere $X$ is a compact topological space.\n%\tShow that $f$ is bounded.\n%\t\\begin{hint}\n%\t\tImmediate by the fact that the image of $f$ is compact,\n%\t\tand hence bounded.\n%\t\tRemember this!\n%\t\\end{hint}\n%\\end{sproblem}\n\n\\begin{problem}\n\t[Tychonoff's theorem]\n\tLet $X$ and $Y$ be compact metric spaces. Show that $X \\times Y$ is compact.\n\t(This is also true for general topological spaces,\n\tbut the proof is surprisingly hard,\n\tand we haven't even defined $X \\times Y$ in general yet.)\n\t\\label{prob:tychonoff}\n\t\\begin{hint}\n\tSuppose $p_i = (x_i, y_i)$ is a sequence in $X \\times Y$ ($i=1,2,\\dots$).\n\tTake a sub-sequence such that the $x$-coordinate converges\n\t(throwing out some terms).\n\tThen take a sub-sequence of \\emph{that} sub-sequence\n\tsuch that $y$-coordinate converges (throwing out more terms).\n\t\\end{hint}\n\t\\begin{sol}\n\tSuppose $p_i = (x_i, y_i)$ is a sequence in $X \\times Y$ ($i=1,2,\\dots$).\n\tLooking on the $X$ side, some subsequence converges:\n\tfor the sake of illustration say it's $x_1, x_4, x_9, x_{16}, \\dots \\to x$.\n\tThen look at the corresponding sequence $y_1, y_4, y_9, y_{16}, \\dots$.\n\tUsing compactness of $Y$, it has a convergent subsequence, say\n\t$y_1, y_{16}, y_{81}, y_{256}, \\dots \\to y$.\n\tThen $p_1, p_{16}, p_{81}, \\dots$ will converge to $(x,y)$.\n\n\tOne common mistake is to just conclude\n\tthat $(x_n)$ has a convergent subsequence\n\tand that $(y_n)$ does too.\n\tBut these sequences could be totally unrelated.\n\tFor this proof to work,\n\tyou do need to apply compactness of $X$ first,\n\tand then compactness of $Y$ on the resulting \\emph{filtered}\n\tsequence like we did here.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{dproblem}\n\t[Bolzano-Weierstra\\ss\\ theorem for general metric spaces]\n\t\\gim\n\tProve that a metric space $M$ is sequentially compact\n\tif and only if it is complete and totally bounded.\n\t\\label{thm:bzw}\n\t\\begin{hint}\n\t\tMimic the proof of \\Cref{thm:interval_compact}.\n\t\tThe totally bounded condition lets you do Pigeonhole.\n\t\\end{hint}\n\\end{dproblem}\n\n\\begin{problem}\n\t[Almost Arzel\\`a-Ascoli theorem]\n\t\\gim\n\tLet\n\t$f_1, f_2, \\ldots \\colon [0,1] \\to [-100,100]$\n\tbe an \\vocab{equicontinuous} sequence of functions, meaning\n\t\\[\n\t\t\\forall \\eps > 0 \\quad\n\t\t\\exists \\delta > 0 \\quad\n\t\t\\forall n \\; \n\t\t\\forall x,y \\quad\n\t\t\\left( \\left\\lvert x-y \\right\\rvert <\\delta\n\t\t\\implies \\left\\lvert f_n(x) - f_n(y) \\right\\rvert < \\eps \\right)\n\t\\]\n\tShow that we can extract a subsequence $f_{i_1}, f_{i_2}, \\dots$\n\tof these functions such that for every $x \\in [0,1]$,\n\tthe sequence $f_{i_1}(x)$, $f_{i_2}(x)$, \\dots\\ converges.\n\\end{problem}\n\n\\begin{problem}\n\t\\gim\n\tLet $M = (M,d)$ be a bounded metric space.\n\tSuppose that whenever $d'$ is another metric on $M$\n\tfor which $(M,d)$ and $(M,d')$ are homeomorphic\n\t(i.e.\\ have the same open sets), then $d'$ is also bounded.\n\tProve that $M$ is compact.\n\\end{problem}\n\n\\begin{problem}\n\t\\yod\n\tIn this problem a ``circle''\n\trefers to the boundary of a disk with \\emph{nonzero} radius.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Is it possible to partition the plane $\\RR^2$\n\t\tinto disjoint circles?\n\t\t\\ii From the plane $\\RR^2$ we delete two distinct points $p$ and $q$.\n\t\tIs it possible to partition the remaining points into disjoint circles?\n\t\\end{enumerate}\n\t\\begin{hint}\n\t\tThe answer to both parts is no.\n\n\t\tFor (a) use \\Cref{prob:cantor_intersect}.\n\n\t\tFor (b), color each circle in the partition\n\t\tbased on whether it contains $p$ but not $q$,\n\t\t$q$ but not $p$, or both.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tPart (a) follows by the Cantor intersection theorem\n\t\t(\\Cref{prob:cantor_intersect}).\n\t\tAssume for contradiction such a partition existed.\n\t\tTake any of the circles $C_0$, and let $K_0$ denote the closed disk\n\t\twith boundary $C_0$.\n\t\tNow take the circle $C_1$ passing through the center of $C_0$,\n\t\tand let $K_1$ denote the closed disk with boundary $C_1$.\n\t\tIf we repeat in this way,\n\t\twe get a nested sequence $K_0 \\supseteq K_1 \\supseteq \\dots$\n\t\tand the radii of $C_i$ approach zero\n\t\t(since each is at most half the previous once).\n\t\tThus some point $p$ lies in $\\bigcap_n K_n$ which is impossible.\n\n\t\tNow for part (b),\n\t\tagain assume for contradiction a partition into circles exists.\n\t\tColor a circle magenta if it contains $p$ but not $q$\n\t\tand color a circle cyan if it contains $q$ but not $p$.\n\t\tColor $p$ itself magenta and $q$ itself cyan as well.\n\t\tFinally, color a circle neon yellow if it contains both $p$ and $q$.\n\t\t(When we refer to coloring a circle,\n\t\twe mean to color all the points on it.)\n\n\t\tBy repeating the argument in (a) there are no circles\n\t\tenclosing neither $p$ nor $q$.\n\t\tHence every point is either magenta, cyan, or neon yellow.\n\t\tNow note that given any magenta circle,\n\t\tits interior is completely magenta.\n\t\tActually, the magenta circles can be totally ordered\n\t\tby inclusion (since they can't intersect).\n\t\tSo we consider two cases:\n\t\t\\begin{itemize}\n\t\t \\ii If there is a magenta circle which is maximal by inclusion\n\t\t (i.e.\\ a magenta circle not contained in any other magenta circle)\n\t\t then the set of all magenta points is just a closed disk.\n\t\t \\ii If there is no such magenta circle,\n\t\t then the set of magenta points can also be expressed\n\t\t as the union over all magenta circles of their interiors.\n\t\t This is a union of open sets, so it is itself open.\n\t\t \\end{itemize}\n\n\t\tWe conclude the set of magenta points is\n\t\teither a closed disk or an open set.\n\t\tSimilarly for the set of cyan points.\n\t\tMoreover, the set of such points is convex.\n\n\t\tTo finish the problem:\n\t\t\\begin{itemize}\n\t\t\\ii Suppose there are no neon yellow points.\n\t\tIf the magenta points form a closed disk,\n\t\tthen the cyan points are $\\mathbb R^2$ minus a disk which is not convex.\n\t\tContradiction. So the magenta points must be open.\n\t\tSimilarly the cyan points must be open.\n\t\tBut $\\mathbb R^2$ is connected,\n\t\tso it can't be written as the union of two open sets.\n\t\t\\ii Now suppose there are neon yellow points.\n\t\tWe claim there is a neon yellow circle minimal by inclusion.\n\t\tIf not, then repeat the argument of (a) to get a contradiction,\n\t\tsince any neon yellow circle must have diameter the distance from $p$ to $q$.\n\t\tSo we can find a neon yellow circle $\\mathscr C$ whose\n\t\tinterior is all magenta and cyan.\n\t\tNow repeat the argument of the previous part,\n\t\treplacing $\\mathbb R^2$ by the interior of $\\mathscr C$.\n\t\t \\end{itemize}\n\t\\end{sol}\n\\end{problem}\n", "meta": {"hexsha": "3e6a6a56d17fe1a039561494fce3f177878c3d30", "size": 26555, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/topology/compactness.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/topology/compactness.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/topology/compactness.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.7664233577, "max_line_length": 115, "alphanum_fraction": 0.7112408209, "num_tokens": 8191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812552, "lm_q2_score": 0.8856314692902447, "lm_q1q2_score": 0.7134932192349852}}
{"text": "\\chapter{More properties of the discriminant}\nI'll remind you that the discriminant of a number field $K$ is given by\n\\[\n\\Delta_K \\defeq \\det \n\\begin{bmatrix}\n\t\\sigma_1(\\alpha_1) & \\dots & \\sigma_n(\\alpha_1) \\\\\n\t\\vdots & \\ddots & \\vdots \\\\\n\t\\sigma_1(\\alpha_n) & \\dots & \\sigma_n(\\alpha_n) \\\\\n\\end{bmatrix}^2\n\\]\nwhere $\\alpha_1$, \\dots, $\\alpha_n$ is a $\\ZZ$-basis for $K$,\nand the $\\sigma_i$ are the $n$ embeddings of $K$ into $\\CC$.\n\nSeveral examples, properties, and equivalent definitions follow.\n\n\\section\\problemhead\n\\begin{sproblem}[Discriminant of cyclotomic field]\n\t\\label{prob:discrim_cyclotomic_field}\n\tLet $p$ be an odd rational prime and $\\zeta_p$ a primitive $p$th root of unity.\n\tLet $K = \\QQ(\\zeta_p)$.\n\tShow that \\[ \\Delta_K = (-1)^{\\frac{p-1}{2}} p^{p-2}. \\]\n\t\\begin{hint}\n\t\tDirect linear algebra computation.\n\t\\end{hint}\n\\end{sproblem}\n\n\\begin{sproblem}[Trace representation of $\\Delta_K$]\n\t\\gim\n\tLet $\\alpha_1$, \\dots, $\\alpha_n$ be a basis for $\\OO_K$.\n\tProve that\n\t\\[ \\Delta_K\n\t\t=\n\t\t\\det \n\t\t\\begin{bmatrix}\n\t\t\t\\TrK(\\alpha_1^2) & \\TrK(\\alpha_1\\alpha_2) & \\dots & \\TrK(\\alpha_1\\alpha_n) \\\\\n\t\t\t\\TrK(\\alpha_2\\alpha_1) & \\TrK(\\alpha_2^2) & \\dots & \\TrK(\\alpha_2\\alpha_n) \\\\\n\t\t\t\\qquad\\vdots & \\qquad\\vdots & \\ddots & \\qquad\\vdots \\\\\n\t\t\t\\TrK(\\alpha_n\\alpha_1) & \\TrK(\\alpha_n\\alpha_2) & \\dots & \\TrK(\\alpha_n\\alpha_n) \\\\\n\t\t\\end{bmatrix}.\n\t\\]\n\tIn particular, $\\Delta_K$ is an integer.\n\t\\label{prob:trace_discriminant}\n\t\\begin{hint}\n\t\tLet $M$ be the ``embedding'' matrix.\n\t\tLook at $M^\\top M$, where $M^\\top$ is the transpose matrix.\n\t\\end{hint}\n\\end{sproblem}\n\n\n\\begin{sproblem}[Root representation of $\\Delta_K$]\n\tThe \\vocab{discriminant} of a quadratic polynomial $Ax^2+Bx+C$ is defined as $B^2-4AC$.\n\tMore generally, the polynomial discriminant of a polynomial $f \\in \\ZZ[x]$ of degree $n$ is\n\t\\[ \\Delta(f) \\defeq c^{2n-2} \\prod_{1 \\le i < j \\le n} \\left( z_i - z_j \\right)^2 \\]\n\twhere $z_1, \\dots, z_n$ are the roots of $f$, and $c$ is the leading coefficient of $f$.\n\n\tSuppose $K$ is monogenic with $\\OO_K = \\ZZ[\\theta]$.\n\tLet $f$ denote the minimal polynomial of $\\theta$ (hence monic).\n\tShow that \\[ \\Delta_K = \\Delta(f). \\]\n\t\\label{prob:root_discriminant}\n\t\\begin{hint}\n\t\tVandermonde matrices.\n\t\\end{hint}\n\\end{sproblem}\n\n\n\\begin{problem}\n\tShow that if $K \\neq \\QQ$ is a number field then $\\left\\lvert \\Delta_K \\right\\rvert > 1$.\n\t\\begin{hint}\n\t\t$M_K \\ge 1$ must hold. Bash.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\t[Brill's theorem]\n\tFor a number field $K$ with signature $(r_1, r_2)$, show that \n\t$\\Delta_K > 0$ if and only if $r_2$ is even.\n\\end{problem}\n\n\\begin{problem}\n\t[Stickelberger theorem]\n\t\\kurumi\n\tLet $K$ be a number field. Prove that \\[ \\Delta_K \\equiv 0 \\text{ or } 1 \\pmod 4. \\]\n\t% P N\n\\end{problem}\n", "meta": {"hexsha": "76ebecbba7e5b4f31e952fe09788cfe1ad02e975", "size": 2740, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/alg-NT/discriminant.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/alg-NT/discriminant.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/alg-NT/discriminant.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2352941176, "max_line_length": 92, "alphanum_fraction": 0.6631386861, "num_tokens": 1027, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048443, "lm_q2_score": 0.8354835391516132, "lm_q1q2_score": 0.713430058281052}}
{"text": "\\documentclass{scrartcl}\n\n\\usepackage{riley}\n\\usepackage[tt={monowidth=true}]{cfr-lm}\n%\\usepackage{riley-libertine}\n\\usepackage{graphicx}\n\n\\newcommand{\\measpace}{\\Omega}\n\\newcommand{\\system}{\\mathcal D}\n\\newcommand{\\propersetminus}{\\begin{smallmatrix} \\setminus\\\\\\supseteq \\end{smallmatrix}}%{\\mathop{\\setminus}\\limits_{\\supseteq}}\n\\DeclareMathOperator*{\\bigdisjunion}{\\coprod}\n\\newcommand{\\disjunion}{\\mathbin{\\amalg}}\n\\newcommand{\\ordinals}{\\texttt{Ord}}\n\\newcommand{\\inclass}{\\in}\n\\newcommand{\\notinclass}{\\notin}\n\n\\DeclareMathOperator{\\successor}{succ}\n\n\\usepackage{import}\n\\newcommand{\\figinput}[1]{\\import{figs/}{#1}}\n\n\\begin{document}\n\n\\section{Ordinals and transfinite induction}\n\\newcommand{\\setofords}{\\mathcal X}\n\\begin{defn}[The ordinals, \\(\\ordinals\\)]\n  These are defined inductively:\n  \\begin{itemize}\n  \\item \\(0\\define\\emptyset \\inclass \\ordinals\\)\n  \\item If \\(n\\inclass\\ordinals\\) then\n    \\[\n      \\successor(n)\\define n \\cup \\{n\\} \\inclass \\ordinals\n    \\]\n  \\item If \\(\\setofords \\subseteq \\ordinals\\) is a set, then\n    \\[\n      \\sup \\setofords \\define \\bigcup\\setofords \\inclass \\ordinals\n    \\]\n  \\end{itemize}\n  In other words, an ordinal is the set of all smaller ordinals.\nIn particular, the last definition precludes the ordinals from being a set.\n\\(\\ordinals\\) is bigger than any set. They form a class.\n\nIf \\(\\alpha = \\successor(n)\\) then \\(\\alpha\\) is a \\emph{successor ordinal}.\nOtherwise, \\(\\alpha\\) is a \\emph{limit ordinal}.\n\\end{defn}\n\\begin{theorem}[\\(\\ordinals\\) is well-ordered]\\label{ordinals are well ordered}\n  Every nonempty class of ordinals contains a least element.\n\\end{theorem}\n\\begin{proof}\n  Let \\(\\setofords\\) be a nonempty class of ordinals. Then it suffices to show\n  \\[\n   I\\define\\inf\\setofords = \\bigcap \\setofords \\in\\setofords\n  \\]\n  Suppose \\(I\\notin\\setofords\\). Then for any \\(x\\in\\setofords\\), \\(I<x\\).\n  Consequently, for any \\(x\\in\\setofords\\), \\(\\successor(I)\\leq x\\). But then\n  \\(\\successor(I)=I\\), a contradiction.\n\\end{proof}\n\n\\begin{theorem}[Transfinite induction]\n  For a logical statement \\(\\phi\\), if\n  \\begin{enumerate}\n  \\item \\(\\phi(0)\\) holds,\n  \\item \\(\\phi(n)\\implies\\phi(\\successor(n))\\) \\footnote{strictly speaking, this follows\n    from (1) and  (3) but is usually easier to prove first}\n  \\item \\label{strong induction}If, for all \\(n<\\alpha\\), \\(\\phi(n)\\) is true then \\(\\phi(\\alpha)\\) is true:\n    \\[\n      (\\forall n<\\alpha) \\phi(n)\\implies \\phi(\\alpha)\n    \\]\n  \\end{enumerate}\n  Then \\(\\phi\\) holds for all ordinals.\n\\end{theorem}\n\\begin{proof}\n  \\newcommand{\\badset}{\\setofords}\n  Let \\(\\badset\\) be the class where \\(\\phi\\) does not hold. Suppose\n  \\(\\badset\\neq\\emptyset\\). Then let for all ordinals \\(n< \\inf\\badset\\),\n  \\(\\phi(n)\\) by hypothesis. Hence, by (3), \\(\\phi(\\inf\\badset)\\) holds. But then\n  \\(\\inf\\badset\\notin\\badset\\), contradicting \\namecref{ordinals are well ordered}.\n  Therefore, \\(\\badset\\) is empty.\n\\end{proof}\n\n\\begin{theorem}[\\(\\ordinals\\) fixed point theorem] \\label{ordinal fixed point theorem}\n  Let \\((X,\\leq)\\) be a complete ordered space.\n  Suppose \\(F:X\\to X\\) is nondecreasing.\n  Define\n  \\begin{align*}\n    F^0(x)&\\define x \\\\\n    F^{\\successor(n)}(x)&\\define F(F^n(x))\n    \\shortintertext{If \\(\\alpha\\) is a limit ordinal,}\n    F^{\\alpha}(x) &\\define \\sup_{\\beta < \\alpha} F^\\beta(x)\n  \\end{align*}\n  Then for any \\(x\\in X\\), \\(F^\\alpha(x)\\)  is eventually the smallest fixed\n  point of \\(F\\) greater than or equal to \\(x\\).\n\\end{theorem}\n\\begin{proof}\n  Fix \\(x\\). Then \\(F^\\blank(x):\\ordinals\\to X\\) is nondecreasing by\n  construction. Because \\(\\ordinals\\) is bigger than any set, \\(F^\\blank(x)\\)\n  cannot be injective. Hence there is some smallest \\(\\alpha\\inclass\\ordinals\\)\n  such that \\(F^\\alpha(x)=F^{\\gamma}(x)\\) with \\(\\gamma > \\alpha\\). But\n  \\(\\alpha<\\successor(\\alpha)\\leq\\beta\\), so by monotonicity,\n  \\[\n    F^{\\alpha}(x)\\leq F^{\\successor(\\alpha)}(x) \\leq F^{\\beta}(x)=F^{\\alpha}(x)\n  \\]\n  hence\n  \\[\n    F(F^\\alpha(x)) = F^{\\successor(\\alpha)}(x)=F^{\\alpha}(x)\n  \\]\n  so \\(F\\) fixes \\(F^{\\alpha}(x)\\).\n\n  Suppose \\(y\\) is a fixed point and \\(x\\leq y\\leq F^\\alpha(x)\\). Then there is\n  some smallest \\(\\beta\\) such that \\(y\\leq F^\\beta(x)\\):\n  \\begin{itemize}\n  \\item If \\(\\beta=\\successor(\\gamma)\\), then\n    \\[\n      F^\\gamma(x) \\leq y \\leq f(F^\\gamma(x)) = F^\\beta(x)\n    \\]\n    But by monotonicity, \\(F(F^\\gamma(x))\\leq f(y) =y\\) by assumption \\(y\\) is fixed.\n    Thus \\(y=F^\\gamma(x)\\) for some \\(\\gamma\\leq\\alpha\\).\n  \\item If \\(\\beta\\) is a limit ordinal, then  for all \\(\\gamma <\\beta\\),\n    \\[\n      F^\\gamma(x) \\leq y \\leq F^\\beta(x)=\\sup_{\\hat\\gamma < \\beta} F^{\\hat\\gamma}(x) = y\n    \\]\n    so \\(F^{\\beta}(x)=y\\).\n  \\end{itemize}\n\\end{proof}\nBy characterizing \\(\\sigma\\)-algebras and \\(\\lambda\\)-systems as fixed points of\nset functions, this result becomes a powerful tool for proving results about\ngenerated \\(\\sigma\\)-algebras and \\(\\lambda\\)-systems.\n\\section{\\(\\pi\\)--\\(\\lambda\\) systems and theorem}\nSpecial notation:\n\\begin{itemize}\n\\item I'll use \\(\\disjunion\\) to represent \\emph{disjoint} unions,\n\\item  \\(\\upunion\\) to\n  represent \\emph{increasing} unions,\n\\item and \\(\\propersetminus\\) to represent\n  \\emph{proper} relative complements: \\(A\\setminus B\\) when \\(B\\subseteq A\\).\n\\end{itemize}\n\\begin{defn}[\\(\\lambda\\)-system aka Dynkin system] \\label{original dynkin system def}\n  \\(\\system\\) is a Dynkin system on \\(\\measpace\\) iff\n  \\begin{itemize}\n  \\item \\(\\measpace\\in\\system\\)\n  \\item Closure under \\emph{proper} relative complements:\n    \\[\n      A\\subseteq B \\implies B\\propersetminus A \\in \\system\n    \\]\n  \\item  Closure under \\emph{increasing} \\(\\sigma\\)-unions:\n    \\[\n      A_1\\subseteq A_2 \\subseteq \\dots \\in \\system \\implies \\upunion A_n \\in \\system\n    \\]\n  \\end{itemize}\n\\end{defn}\nAllowing arbitrary complements would give a \\(\\sigma\\)-algebra as\n\\[\n  (\\measpace\\setminus A)\\setminus B = (A\\cup B)^C = A^C \\cap B^C\n\\]\nallowing arbitrary \\(\\sigma\\)--unions and intersections. \\\\\n\\figinput{relcomp.pdf_tex}\n\n\n\\begin{theorem}[Alternative definition of \\(\\lambda\\)-system] \\label{equivalent dynkin system def}\n  Equivalently,\n  \\begin{itemize}\n  \\item \\(\\measpace\\in\\system\\)\n  \\item Closure under \\emph{global} complements: \\[A\\in \\system \\implies A^C\\in\\system\\]\n  \\item Closure under \\emph{disjoint} \\(\\sigma\\)-unions:\n    \\[\n      \\{A_i\\in \\system\\}, A_i\\cap A_j=\\emptyset \\implies \\bigdisjunion A_i \\in \\system\n    \\]\n  \\end{itemize}\n\\end{theorem}\n\\begin{proof}\n  Suppose \\(\\system\\) meets the criteria of \\namecref{equivalent dynkin system def}.\n Then \\(\\system\\) contains proper relative complements as \\(A\\propersetminus B =\n (A^C\\cup B)^C\\): \\\\\n \\figinput{proper-comp-from-global-comp.pdf_tex}\\\\\n But by taking proper relative complements, we can convert an ascending\n \\(\\sigma\\)-union into a disjoint \\(\\sigma\\)-union: if \\(A_n\\uparrow A\\), let\n \\begin{align*}\n   B_1 &= A_1 \\in\\system\\\\\n   B_n &= A_n\\propersetminus \\bigcup_{i<n}A_{i} \\in\\system\\\\\n         \\shortintertext{Then \\(\\{B_n\\}\\) are pairwise-disjoint and}\n    A &= \\upunion A_n =  \\bigdisjunion_n B_n \\in \\system\n \\end{align*}\n proving sufficiency.\n\n For necessity, suppose \\(\\system\\) satisfies the criteria of\n \\namecref{original dynkin system def}. As \\(A^C =\\measpace\\setminus A\\), a proper\n complement, it suffices to show closure under disjoint unions. First, note that\n it is closed under finite disjoint unions:\n \\[\n   A \\disjunion B = ((\\measpace\\propersetminus A)\\propersetminus B)^C \\in \\system\n \\]\\\\\n \\figinput{disjointbinunion-from-relcomp.pdf_tex}\\\\\n because the complements are proper by disjointness.\n Suppose \\(B_i\\)\n are pairwise disjoint. Then \\(B=\\bigdisjunion B_i\\in\\system\\) by hypothesis.\n \\begin{align*}\n   A_1 &= B_1 \\in\\system \\\\\n   A_n &= B_n\\disjunion A_{n-1} \\in \\system\n         \\shortintertext{therefore}\n   B&=\\bigdisjunion B_n=\\upunion A_n \\in\\system\n \\end{align*}\n\\end{proof}\n\\begin{defn}[\\(\\pi\\)-system]\n  A \\(\\pi\\)-system is closed under finite intersections.\n\\end{defn}\n\\begin{theorem}\n  If \\(\\system\\) is a \\(\\pi\\)-system and \\(\\lambda\\)-system then it is a \\(\\sigma\\)-algebra.\n\\end{theorem}\n\\begin{proof}\n  First, prove \\(\\system\\) is an algebra.\n  Note that \\(\\system\\) is closed under binary union as \\(A\\cup B = (A^C\\cap\n  B^C)^C \\) and \\(A^C,B^C\\in\\system\\) because \\(\\system\\) is a \\(\\lambda\\)-system, so\n  \\(A^C\\cap B^C\\in\\system\\) because it is a \\(\\pi\\)-system, and its complement is in\n  \\(\\system\\) by closure under complements. In particular, \\(\\system\\) must be\n  closed under \\emph{arbitrary} relative complements as\n  \\[\n    A\\setminus B = A\\propersetminus ({A\\cap B})\n  \\]\n\n  Suppose \\(A_i\\) is a countable sequence of sets in \\(\\system\\). Then let\n  \\begin{align*}\n    B_1 &= A_1 \\\\\n    B_n &= A_n \\setminus \\bigdisjunion_{i<n}B_{i} \\\\\n    \\shortintertext{so \\(B_i\\) are pairwise-disjoint and}\n    \\bigcup A_n &= \\bigdisjunion B_n \\in \\system\n  \\end{align*}\n  proving closure under \\(\\sigma\\)-unions.\n\\end{proof}\n\n\\newcommand{\\lambdify}{\\Lambda}\n\\newcommand{\\lambdagen}{\\lambda}\n\\newcommand{\\pisystem}{P}\n\\newcommand{\\dsystem}{\\system}\n\\begin{theorem}[Dynkin's \\(\\pi\\)--\\(\\lambda\\) theorem]\n  If \\(\\pisystem\\subseteq \\dsystem\\) where \\(\\pi\\) is a \\(\\pi\\)-system and \\(\\dsystem\\) is a\n  \\(\\lambda\\)-system, then\n  \\[\n    \\sigma(\\pisystem) \\subseteq \\dsystem\n  \\]\n\\end{theorem}\n\\begin{proof}\n  As \\(\\lambdagen(\\pisystem)\\) is the minimal \\(\\lambda\\)-system containing\n  \\(\\pisystem\\),\n  \\[\n    \\lambdagen(\\pisystem)\\subseteq\\dsystem\n  \\]\n  It suffices to show \\(\\lambdagen(\\pisystem)\\) is a\n  \\(\\pi\\)-system because then it must be a \\(\\sigma\\)-algebra.\n\n  Let \\(U(X)\\) indicate the set of disjoint \\(\\sigma\\)-unions in \\(X\\):\n  \\[\n    U(X)\\define\\left\\{\\bigdisjunion_{i\\in \\N} A_i: A_i\\in X, A_i\\cap A_j=\\emptyset\\right\\}\n  \\]\n  Let \\(C(X)\\) indicate the set of complements in \\(X\\):\n  \\[\n    C(X)\\define\\left\\{ A^C:A\\in X \\right\\}\n  \\]\n  And define\n  \\[\n    \\lambdify(X)\\define X\\cup U(X) \\cup C(X) = U(X)\\cup C(X) :\n    (2^{2^\\measpace},\\subseteq ) \\to (2^{2^\\measpace},\\subseteq)\n  \\]\n  By construction, \\(\\lambdify(X)=X\\) iff \\(X\\) is a \\(\\lambda\\)-system. By monotonicity\n  (\\(X\\subseteq\\lambdify(X)\\)), the minimum fixed point of \\(\\lambdify\\) containing \\(X\\)\n  is the \\(\\lambda\\)-system generated by \\(X\\). By \\namecref{ordinal fixed point\n    theorem},\n  \\newcommand{\\stopord}{\\omega}\n  \\[\n    \\lambdify^\\stopord(\\pisystem)=\\lambda(\\pisystem)\n  \\]\n  for some \\(\\stopord\\inclass\\ordinals\\).\n\n  \\newcommand{\\nextord}{5}\n  We show for any \\(\\alpha\\in\\ordinals\\), the intersection of\n  any two elements in \\(\\lambdify^\\alpha(\\pisystem)\\) is in\n  \\(\\lambdify^{\\nextord(\\alpha)}(\\pisystem)\\).\n\n  \\begin{enumerate}\n  \\item As $\\nextord(0)\\geq 0$, this is true for \\(\\alpha=0\\) by the hypothesis that \\(\\pisystem\\) is a \\(\\pi\\)-system.\n  \\item Any element in \\(\\lambdify^{\\successor(\\alpha)}(\\pisystem)\\) can be written as\n    \\(A\\), \\(A^C\\), or \\(\\bigdisjunion A_i\\) with \\(A,A_i\\in\\lambdify^{\\alpha}\\).\n    Writing an intersection of elements in\n    \\(\\lambdify^{\\successor(\\alpha)}\\) in terms of proper complements and disjoint\n    unions of intersections of elements in \\(\\Lambda^\\alpha(\\pisystem)\\):\n      \\begin{align*}\n        &A\\cap B^C &&= A\\propersetminus (B\\cap A) = (A^{C} \\disjunion \\grayoverbrace{(B \\cap A)}{\\in\\lambdify^{\\nextord(\\alpha)}(\\pisystem)})^{C}\n        &&\\in \\lambdify^{\\nextord(\\alpha)+3}(\\pisystem) \\\\\n        %\n        &A^C\\cap B^C &&= (A\\cup B)^C = \\left((A\\cap B^C)\\disjunion B  \\right)^C\n        &&\\in \\lambdify^{\\nextord(\\alpha)+5}(\\pisystem) \\\\\n        %\n        & \\left(\\bigdisjunion_{i} A_i\\right) \\cap\n        \\left(\\bigdisjunion_j B_j\\right) &&= \\bigdisjunion_{i,j}\n                                            \\grayoverbrace{A_i\\cap B_j}{\\in\\lambdify^{\\nextord(\\alpha)}(\\pisystem)}\n        &&\\in\n        \\lambdify^{\\nextord(\\alpha)+1}(\\pisystem) \\\\\n        %\n       & A^C \\cap \\bigdisjunion B_j &&= \\bigdisjunion \\grayunderbrace{A^C\\cap\n           B_j}{\\in\\lambdify^{\\nextord(\\alpha)+3}(\\pisystem)} &&\\in\\lambdify^{\\nextord(\\alpha)+4}(\\pisystem)\n      \\end{align*}\n          which are all in \\(\\lambdify^{\\nextord(\\alpha)+5}(\\pisystem)= \\lambdify^{\\nextord(\\alpha+1)}\\).\n  \\item\n    If \\(\\alpha\\) is a limit ordinal, then set\n    \\[\n      \\nextord\\alpha \\geq \\nextord\\sup_{\\beta <\\alpha}\\beta = \\sup_{\\beta <\n        \\alpha}\\nextord\\beta\n    \\]\n    For any two \\(A,B\\in\\lambdify^\\alpha\\) there must be some \\(n_A,n_B<\\alpha\\)\n    such that \\(A\\in \\lambdify^{n_A}(\\pisystem)\\) and\n    \\(B\\in\\lambdify^{n_B}(\\pisystem)\\). Hence, if \\(n=\\max(n_A,n_B)\\), then\n    \\(A\\cap B\\in \\lambdify^{\\nextord n}(\\pisystem)\\subseteq\n    \\lambdify^{\\nextord\\alpha}(\\pisystem)\\).\n  \\end{enumerate}\n  But this process terminates at \\(\\omega\\), hence\n  \\(\\lambdify^{3\\omega}(\\pisystem)=\\lambdify^\\omega(\\pisystem)=\\lambdagen(\\pisystem)\\);\n  \\(\\lambdagen(\\pisystem)\\) is closed under intersections.\n\\end{proof}\n\\end{document}\n", "meta": {"hexsha": "0543e21939cf970af9ee0a8930314f5d6e202f0c", "size": 12849, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "dynkin.tex", "max_stars_repo_name": "rilerez/pi-lambda-theorem", "max_stars_repo_head_hexsha": "0c7311c366324c534e8ef8a7083a172b8634edd6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dynkin.tex", "max_issues_repo_name": "rilerez/pi-lambda-theorem", "max_issues_repo_head_hexsha": "0c7311c366324c534e8ef8a7083a172b8634edd6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dynkin.tex", "max_forks_repo_name": "rilerez/pi-lambda-theorem", "max_forks_repo_head_hexsha": "0c7311c366324c534e8ef8a7083a172b8634edd6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.2789968652, "max_line_length": 145, "alphanum_fraction": 0.6463538019, "num_tokens": 4464, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835493924953, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7134300546015184}}
{"text": "\\documentclass[11pt]{lab-exercise}\n\n\n\\begin{document} %****************************************************\n\\maketitle\n\\pagestyle{exercise-style}\n\\thispagestyle{empty}\n%=============================================\nDownload the file \\verb|lab_14_files.zip|, un-zip it.\n%---------------------------------------------\n\\section{Direction Fields and Solution Curves}\n%---------------------------------------------\nGiven the following ODE and the initial condition,\n$$\n\\frac{dy}{dt} = -y(t) - 5 e^{-t} \\sin(5t), \\quad y(0) = -2, \\quad t \\in [0, 3].\n$$\n\\begin{enumerate}[a.]\n    \\item In \\verb|lab_14_script.m|, define anoymous function \\verb`dydt` to be the right-hand side of the ODE.\n    \\item Define \\verb`a`, \\verb`b` to be the left and right endpoint of the interval $[0, 3]$, respectively.\n    \\item Define \\verb`tStep` to be the step size $\\Delta t = 0.01$.\n    \\item Define \\verb`tSpan` to be a vector starting from \\verb`a` to \\verb`b` with step size \\verb`tStep` using colon notation.\n    \\item At line 20, use \\verb`ode23` to solve the ODE.\n    \\item At line 40, plot \\verb`tSol(:, i)` against \\verb`ySol(:, i)` with line style specified in the cell array \\verb`LineStyle`.\n    \\item Run the script and see whether it works. If it does work, add more initial conditions at line 17: $y(0) = 0$, $y(0) = 2$, $y(0) = 4$.\n\\end{enumerate}\n%---------------------------------------------\n\\section{System of ODEs}\n%---------------------------------------------\nNext, use the built-in ODE solver \\verb`ode45` to solve the system of ODEs for Problem 4 of Homework 7. The system of ODEs is as follows:\n$$\n\\begin{cases}\n    y'_1(t) = y_3, \\\\\n    y'_2(t) = y_4, \\\\\n    y'_3(t) = -2 y_1 + (3/2) y_2, \\\\\n    y'_4(t) = (4/3) y_1 - 3 y_2, \\\\\n\\end{cases}\n\\quad\n\\mathbf{y}(0) =\n\\begin{bmatrix}\n    -1 \\\\ 4 \\\\ 1 \\\\ 1\n\\end{bmatrix},\n\\quad\nt \\in [0, 15].\n$$\n\\begin{enumerate}[a.]\n    \\item Uncomment line 49 through 88, define an anoymous function (you can refer to the example in reference page for \\verb`ode45`. To open the reference page, type \\verb`doc ode45` in the Command Window).\n    \\item Repeat the steps in Part I to define \\verb`a`, \\verb`b`, \\verb`tStep`, \\verb`tSpan`, and \\verb`y0`.\n    \\item Use \\verb`ode45` to solve the system of ODEs at line 57.\n    \\item At line 63, plot \\verb`t` against \\verb`y(:, i)` with line style specified in the cell array \\verb`LineStyle`.\n    \\item At line 73, plot \\verb`y(:, 1)` against \\verb`y(:, 3)`.\n\\end{enumerate}\n%---------------------------------------------\nAt last, run the script \\verb|lab_14_script.m|. Upload the script file \\verb|lab_14_script.m|, and figure files \\verb|lab_14_figure_1.pdf|, \\verb|lab_14_figure_2.pdf|, \\verb|lab_14_figure_3.pdf| to Overleaf. Recompile, and submit the generated \\verb|.pdf| file on WyoCourses.\n\n\\section{Lipsum}\n\\lipsum.\n\\end{document}\n", "meta": {"hexsha": "21eb2431b3d66e32e8bf70ffa00000812ddbc52a", "size": 2817, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/template/test.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/template/test.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/template/test.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.5689655172, "max_line_length": 275, "alphanum_fraction": 0.5949591764, "num_tokens": 879, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339909, "lm_q2_score": 0.8354835452961427, "lm_q1q2_score": 0.7134300511035907}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{xcolor}\n\\usepackage[T1]{fontenc}\n\\usepackage{pagecolor}\n\\usepackage{amssymb}\n\\usepackage{lmodern}\n\\usepackage{mathtools, nccmath}\n\\usepackage{courier}\n\\usepackage[overload]{empheq}\n\\usepackage[inline, shortlabels]{enumitem}\n\\usepackage{amsmath}\n\\usepackage{mathtools} \n\\definecolor{myyellow}{RGB}{225,225,100}\n\\definecolor{myred}{RGB}{220,100,100}\n\\definecolor{mygreen}{RGB}{120,225,120}\n\\definecolor{myblue}{RGB}{100,200,255}\n\\definecolor{mypurple}{RGB}{200,140,255}\n\\definecolor{myorange}{RGB}{255,150,50}\n\\color{white}\n\\pagecolor{black}\n\\title{Introduction to Linear algebra \\#1}\n\\author{@all.about.mathematics}\n\n\n\\begin{document}\n\\maketitle\n\\large\n\\section{Introduction}\nThis new series of posts is designed to introduce concepts in linear algebra with some problems and solutions! \n\\newline In this post, we review the very basics of linear algebra, including some \\textcolor{myyellow}{properties of matrices, elementary row operations and elementary matrices}\n\n\\newpage\n\\section{Properties of matrices}\n\\textcolor{myyellow}{Theorem 1: If $A$ is invertible, then so is $adj \\:A$ }\n\\medskip\n\n\\noindent{Proof: We start with the formula } \n\\begin{equation}\nA \\:(adj\\:A)= (\\det A)\\: I\n\\end{equation}\nSince $\\exists A^{-1}\\iff \\det A \\neq 0$, we divide both sides of (1) by $\\det A$\n$$\\left(\\frac{1}{\\det A}A\\right)(adj \\: A)=I$$\nTherefore, $\\left(\\frac{1}{\\det A}A\\right)$ is the inverse of $adj \\: A$.\n\\medskip\n\n\\noindent \\textcolor{myyellow}{Theorem 2: If $\\exists A^{-1}, ({A^T})^{-1}=({A^{-1}})^T$}\n\\medskip\n\n\\noindent{Proof: $$A^{-1} A=I\\implies (A^{-1} A)^T=I$$\nSince $(BC)^T=C^TB^T$, \n$$\\implies A^T ({A^{-1}})^T=I\\implies ({A^{-1}})^T=({A^T})^{-1}$$}\n\n\\newpage\n\\section{Elementary row operations}\nThere are 3 types of elementary row operations (EROs):\n\\medskip\n\n\\noindent{\\textcolor{myred}{Type I: Swapping row $i$ and row $j$}}\n\n\\noindent{This is expressed as \\textcolor{myred}{$\\mathbf{r}_i\\longleftrightarrow\\mathbf{r}_j\\:,\\:i\\neq j$}}\n\n\\noindent{The inverse of this operation is \\textcolor{myred}{itself}, and applying this operation on a matrix multiplies it's determinant by \\textcolor{myred}{$-1$}}\n\\medskip\n\n\\noindent{\\textcolor{mygreen}{Type II: Multiplying row $i$ by a nonzero constant $k$}}\n\n\\noindent{This is expressed as \\textcolor{mygreen}{$k\\mathbf{r}_i\\longrightarrow\\mathbf{r}_i\\:,\\:k\\neq 0$}}\n\n\\noindent{The inverse of this operation is \\textcolor{mygreen}{$\\frac{1}{k}\\mathbf{r}_i\\longrightarrow\\mathbf{r}_i$}, and applying this operation on a matrix multiplies it's determinant by \\textcolor{mygreen}{$k$}}\n\\medskip\n\n\\noindent{\\textcolor{myblue}{Type III: Add row $i$ multiplied by $k$ to row $j$}}\n\n\\noindent{This is expressed as \\textcolor{myblue}{$k\\mathbf{r}_i+r_j\\longrightarrow\\mathbf{r}_j\\:,\\:k\\neq 0\\:,\\: i\\neq j$}}\n\n\\noindent{The inverse of this operation is \\textcolor{myblue}{$-k\\mathbf{r}_i+r_j\\longrightarrow\\mathbf{r}_j$}, and applying this operation on a matrix \\textcolor{myblue}{does not change its determinant.}}\n\\medskip\n\n\\noindent{Another way to represent EROs are by \\textcolor{mypurple}{elementary matrices}. Let $B$ be a matrix obtained from a square matrix $A$ by applying an ERO. Let $E$ be obtained from $I$ by \\textcolor{mypurple}{applying the same ERO}. Then \\textcolor{mypurple}{$B=EA$}, and $E$ is the elementary matrix representing such an ERO. }\n\n\\medskip\n\n\\noindent{\\textcolor{myorange}{Important theorem:}\n\n\\noindent{We can turn square matrix $A$ into $I$ with EROs $\\implies \\exists A^{-1}$} }\n\n\\medskip\n\n\\noindent{Proof: Suppose we apply the EROs $e_1, e_2, \\cdots, e_n$ to turn $A$ into $I$. Let $E_1, E_2, \\cdots, E_n$ be the elementary matrices that represent the EROs respectively. Then we have}\n$$E_n\\cdots E_2 \\:E_1\\: A=I$$\n$$\\implies A^{-1}= E_n\\cdots E_2 \\:E_1\\: $$\n\\end{document}\n\n", "meta": {"hexsha": "c1e0945d1d6170023f14a853e44cf0aef820334b", "size": 3826, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algebra/all.about.mathematics' questions/Linear algebra 1.tex", "max_stars_repo_name": "Nanu00/LaTeX", "max_stars_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-05-29T17:22:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T18:47:05.000Z", "max_issues_repo_path": "Algebra/all.about.mathematics' questions/Linear algebra 1.tex", "max_issues_repo_name": "Nanu00/LaTeX", "max_issues_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-06-26T07:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-11T12:14:49.000Z", "max_forks_repo_path": "Algebra/all.about.mathematics' questions/Linear algebra 1.tex", "max_forks_repo_name": "Shreenabh664/LaTeX", "max_forks_repo_head_hexsha": "675e03f3ec555456b9a2cc714825ec75317848c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-06-22T07:50:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-08T05:11:14.000Z", "avg_line_length": 40.2736842105, "max_line_length": 336, "alphanum_fraction": 0.7216414009, "num_tokens": 1296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694178, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7134300503199116}}
{"text": "\\paragraph{Divide \\& conquer optimization}\n\tFor recurrence\n\t$$f(i) = \\min_{k<i}\\{b(k)+c[k][i]\\}$$\n\t$k(i) \\leq k(i+1)$ holds true if $c[a][c]+c[b][d]<c[a][d]+c[b][c]$.\n\n\t\\subparagraph{LBN technique}\n\tImplement the optimization in $O(n\\log^2n)$.\n\t\\begin{algorithmic}\n\t\t\\Function{update}{$l,r,a,b$}\n\t\t\t\\Comment{update $f[l\\cdots r]$ with $f[a\\cdots b]$}\n\t\t\t\\If {$l\\le r$}\n\t\t\t\t\\State $m\\gets (l+r)/2$\n\t\t\t\t\\State $newk\\gets\\arg_i\\min_{a\\le i \\le b}f[i]+cost(i,m)$\n\t\t\t\t\\State $newf\\gets f[u]+cost(u,m)$\n\t\t\t\t\\If{$newf < f[m]$}\n\t\t\t\t\t\\State $f[m]\\gets newf$\n\t\t\t\t\t\\State $k[m]\\gets newk$\n\t\t\t\t\t\\State \\Call{update}{$l,m-1,a,newk$}\n\t\t\t\t\\EndIf\n\t\t\t\t\\State \\Call{update}{$m+1,r,newk,b$}\n\t\t\t\\EndIf\n\t\t\\EndFunction\n\t\t\\Function{solve}{$l,r$}\n\t\t\t\\Comment{compute $f[l\\cdots r]$}\n\t\t\t\\If {$l<r$}\n\t\t\t\t\\State $m\\gets (l+r)/2$\n\t\t\t\t\\State \\Call{solve}{$l,m$}\n\t\t\t\t\\State \\Call{update}{$m+1,r,\\max(l,k[m]),m$}\n\t\t\t\t\\State \\Call{solve}{$m+1,r$}\n\t\t\t\\EndIf\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\n\\paragraph{Knuth optimization}\n\tFor recurrence\n\t$$f(i,j) = \\min_{i<k<j}\\{f(i,k)+f(k,j)\\}+c[i][j]$$\n\t$k(i,j-1) \\leq k(i,j) \\leq k(i+1,j)$ holds true if $c[a][c]+c[b][d]<c[a][d]+c[b][c]$.\n", "meta": {"hexsha": "832562c4143255f2c78bc0aa5a7ba980cea46aa7", "size": 1146, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/mathematics/dynamic-programming/dynamic-programming.tex", "max_stars_repo_name": "Nisiyama-Suzune/LMR", "max_stars_repo_head_hexsha": "16325b9efcb71240111ac12ea55c0cb45b0c5834", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 48, "max_stars_repo_stars_event_min_datetime": "2018-08-15T11:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T23:38:29.000Z", "max_issues_repo_path": "src/mathematics/dynamic-programming/dynamic-programming.tex", "max_issues_repo_name": "Nisiyama-Suzune/LMR", "max_issues_repo_head_hexsha": "16325b9efcb71240111ac12ea55c0cb45b0c5834", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mathematics/dynamic-programming/dynamic-programming.tex", "max_forks_repo_name": "Nisiyama-Suzune/LMR", "max_forks_repo_head_hexsha": "16325b9efcb71240111ac12ea55c0cb45b0c5834", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2019-07-18T10:27:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-08T13:03:47.000Z", "avg_line_length": 30.1578947368, "max_line_length": 86, "alphanum_fraction": 0.5558464223, "num_tokens": 515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.7133955375825808}}
{"text": "%!TEX root = ../Thesis.tex\n\\chapter{Pendulum - Hamilton's Equations and Numerical Analysis}\n\n\n\\section{Equations of Motion}\n\\begin{figure}[ht!]\n\\centering \n\\includegraphics[scale=1.2]{fig/pendulum.pdf}\n\\caption{The pendulum}\n\\label{fig:pe}\n\\end{figure}\n\\begin{description}\n\\item[Step 0 \\quad Lagrangian $L$] \\ \\\\[0.5cm]\nGeneralized coordinate: $\\theta$. \\\\[0.2cm]\n$T = \\frac{1}{2} m \\dot{x}^2 = \\frac{1}{2} m l^2 \\theta^2.$ \\\\[0.2cm]\n$V = -m g l \\cos{\\theta}$ \\\\[0.2cm]\n$L(\\theta, \\dot{\\theta}) = T - V = \\frac{1}{2} m l^2 \\theta^2 + m g l \\cos{\\theta}$\n\n\\item[Step 1 \\quad Generalized momentum $p_\\theta$] \\ \\\\[0.2cm]\n$p_\\theta(\\theta,\\dot{\\theta}) = \\dfrac{\\partial L}{\\partial \\dot{\\theta}} = m l^2 \\dot{\\theta}$\n\n\\item[Step 2 \\quad Transform $\\dot{\\theta}$] \\ \\\\[0.5cm]\n$\\dot{\\theta} = \\dot{\\theta}(\\theta, p_\\theta) = \\dfrac{p_\\theta}{m l^2}$\n\n\\item[Step 3 \\quad The Hamiltonian $H$] \\ \\\\[0.5cm]\n$H(\\vec{q}, \\vec{p}, t) = \\sum\\limits_{i=1}^n p_i \\dot{q_i} - L$ \\\\[0.5cm]\n\\begin{align}\n\\notag H &= p_\\theta \\dot{\\theta} - \\left(\\dfrac{1}{2} m l^2 \\dot{\\theta}^2 + m g l \\cos{\\theta}\\right) \\\\\n\\notag &= p_\\theta \\left(\\dfrac{p_\\theta}{m l^2} \\right) - \\left(\\dfrac{1}{2} m l^2 \\left(\\dfrac{p_\\theta}{m l^2}\\right)^2 + m g l \\cos{\\theta}\\right) \\\\\n&= \\dfrac{p_\\theta^2}{2 m l^2} - m g l \\cos{\\theta}\n\\end{align} \n, which we again recognize simply as the total energy. The first term is the kinetic energy in terms of the momentum $p_\\theta$ and the second term is the potential energy $V$.\n\n\\item[Step 4 \\quad Hamilton's Equations of Motion]\n\\begin{align}\n\\begin{split}\n\\label{eq:pe-eom}\n\\dot{\\theta} = +\\dfrac{\\partial H}{\\partial p_\\theta} &= \\dfrac{p_\\theta}{m l^2} ,\n\\\\[0.2cm]\n\\dot{p_\\theta} = -\\dfrac{\\partial H}{\\partial \\theta} &= - m g l \\sin{\\theta}\n\\end{split}\n\\end{align}\n\\end{description}\n\n\n\\section{Numerical Analysis}\nWe will now solve the pendulum's equations of motion, \\eqref{eq:ho-eom}. For simplicity we'll set $k = m = 1$. Note that by choice of $m=l=1$, the momentum $p_\\theta$ is actually equal to the angular velocity $\\omega$. The first step is to discretize the equations\n\\begin{alignat}{2}\n&\\dod{\\theta}{t} = p  & \\qquad \\implies \\qquad &\\Delta \\theta = p \\Delta t \\\\[0.5cm]\n&\\dod{p}{t} = -\\sin{\\theta} & \\qquad \\implies \\qquad &\\Delta p = - \\sin{\\theta} \\Delta t\n\\end{alignat}\nThis is a non-linear system of PDEs with no analytical solution. The small angle approximation $\\sin{\\theta} = \\theta$ makes this system identical to the harmonic oscillator. However we're interested in solving the exact system where large oscillations are permitted. We will not be able to compare our numerical solutions to an analytical one (since none exists), but we can gain valuable insights nonetheless.\n\nOnce again, in the explicit Euler use old time step values $i$, implicit Euler use new time step values $i+1$ and the symplectic Euler use mixed time step values. As we will see, now the implicit Euler necessitates finding roots numerically.\n\\subsection{Explicit Euler algorithm}\n\\begin{align}\n\\begin{split}\n\\label{al:pe-euler_e}\n\\theta_{i+1} &= p_i \\Delta t + \\theta_i \\\\\np_{i+1} &= - \\sin{\\theta_i} \\Delta t + p_i\n\\end{split}\n\\end{align}\n\n\\subsection{Implicit Euler algorithm}\n\\begin{align}\n\\begin{split}\n\\label{al:pe-euler_i}\n\\theta_{i+1} &= p_{i+1} \\Delta t + \\theta_i \\\\\np_{i+1} &= - \\sin{\\theta_{i+1}} \\Delta t + p_i\n\\end{split}\n\\end{align}\nThe new time step $i+1$ values are then found by substituting on the the equations into the other, then solving numerically with a root finder algorithm. For example we can substitute the expression for $p_{i+1}$ into $\\theta_{i+1}$ and solve the resulting equation\n\\begin{align}\n0 = \\theta_i - \\theta_{i+1} + (p_i - sin{\\theta_{i+1}})\\Delta t\n\\end{align}\nNow run root finding for $\\theta_{i+1}$, guessing $\\theta_i$ as initial guess.\n\n\\subsection{Symplectic Euler algorithm}\n\\begin{align}\n\\begin{split}\n\\label{al:pe-euler_s1}\n\\theta_{i+1} &= p_{i+1} \\Delta t + \\theta_i \\\\\np_{i+1} &= - \\sin{\\theta_i} \\Delta t + p_i\n\\end{split}\n\\end{align}\nor\n\\begin{align}\n\\begin{split}\n\\label{al:pe-euler_s2}\n\\theta_{i+1} &= p_{i} \\Delta t + \\theta_i \\\\\np_{i+1} &= - \\sin{\\theta_{i+1}} \\Delta t + p_i\n\\end{split}\n\\end{align}\nAlgorithms \\crefrange{al:pe-euler_e}{al:pe-euler_s1} was implemented in Python (Appendix \\ref{app:pe}).\n\n\\section{Plots}\n\\begin{figure}\n    \\centering\n        \\subbottom[Explicit Euler]{\n            \\includegraphics[scale=0.24]{fig/pe/pe_y(x)_euler_explicit.pdf}\n            \\label{fig:pe_y(x)_euler_explicit}\n        }\n        \\subbottom[Implicit Euler]{\n            \\includegraphics[scale=0.24]{fig/pe/pe_y(x)_euler_implicit.pdf}\n            \\label{fig:pe_y(x)_euler_implicit}\n        }\n        \\subbottom[Symplectic Euler]{\n            \\includegraphics[scale=0.24]{fig/pe/pe_y(x)_euler_symplectic.pdf}\n            \\label{fig:pe_y(x)_euler_symplectic}\n        }\n        \\caption{Position y(x)}\n    \\label{fig:pe_y(x)_euler}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Explicit Euler]{\n            \\includegraphics[scale=0.24]{fig/pe/pe_omega(t)_euler_explicit.pdf}\n            \\label{fig:pe_omega(t)_euler_explicit}\n        }\n        \\subbottom[Implicit Euler]{\n            \\includegraphics[scale=0.24]{fig/pe/pe_omega(t)_euler_implicit.pdf}\n            \\label{fig:pe_omega(t)_euler_implicit}\n        }\n        \\subbottom[Symplectic Euler]{\n            \\includegraphics[scale=0.24]{fig/pe/pe_omega(t)_euler_symplectic.pdf}\n            \\label{fig:pe_omega(t)_euler_symplectic}\n        }\n        \\caption{Momentum p(t), equivalent to angular velocity $\\omega(t)$ by choice of $m=l=1$}\n    \\label{fig:pe_omega(t)_euler}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Explicit Euler]{\n            \\includegraphics[scale=0.24]{fig/pe/pe_E(t)_euler_explicit.pdf}\n            \\label{fig:pe_E(t)_euler_explicit}\n        }\n        \\subbottom[Implicit Euler]{\n            \\includegraphics[scale=0.24]{fig/pe/pe_E(t)_euler_implicit.pdf}\n            \\label{fig:pe_E(t)_euler_implicit}\n        }\n        \\subbottom[Symplectic Euler]{\n            \\includegraphics[scale=0.24]{fig/pe/pe_E(t)_euler_symplectic.pdf}\n            \\label{fig:pe_E(t)_euler_symplectic}\n        }\n        \\caption{Energy E(t), note y-scale on \\ref{fig:pe_E(t)_euler_symplectic}}\n    \\label{fig:pe_E(t)_euler}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Explicit Euler]{\n            \\includegraphics[scale=0.24]{fig/pe/pe_phase-space_euler_explicit.pdf}\n            \\label{fig:pe_phase-space_euler_explicit}\n        }\n        \\subbottom[Implicit Euler]{\n            \\includegraphics[scale=0.24]{fig/pe/pe_phase-space_euler_implicit.pdf}\n            \\label{fig:pe_phase-space_euler_implicit}\n        }\n        \\subbottom[Symplectic Euler]{\n            \\includegraphics[scale=0.24]{fig/pe/pe_phase-space_euler_symplectic.pdf}\n            \\label{fig:pe_phase-space_euler_symplectic}\n        }\n        \\caption{Phase-space $p(\\theta) = \\omega(\\theta)$}\n    \\label{fig:pe_phase-space_euler}\n\\end{figure}\nThings to note this time from the figures \\crefrange{fig:pe_y(x)_euler}{fig:pe_phase-space_euler}:\n\\begin{itemize}\n    \\item The initial conditions are set such that the pendulum barely has enough energy to go all the way around. Hence the implicit Euler method, known for loosing energy, does not make it all the way around, see fig \\ref{fig:pe_y(x)_euler_implicit} as opposed to the explicit and symplectic, fig \\ref{fig:pe_y(x)_euler_explicit} and \\ref{fig:pe_y(x)_euler_symplectic}.\n    \\item Symplectic once again keeps the energy $E(t)$ almost constant, and conserves it seemingly perfectly on average over a cycle.\n    \\item The implicit Euler is in a closed orbit in the phase-space diagram as expected from the position plot \\ref{fig:pe_y(x)_euler_implicit}, but spirals inward as expected from the energy plot \\ref{fig:pe_E(t)_euler_implicit}, whereas explicit and symplectic steadily increases their angles from the initial angle.\n\\end{itemize}\nTo summarize, we have seen that the symplectic version of the Euler method for numerical integration is superior because it conserves the quantity that we most care about the reduced 3-body system: energy. In more general terms symplectic integrators conserves the Hamiltonian $H$, which in our cases is the same is the total energy $E$ as discussed in the chapter on using Hamiltonian mechanics. Using symplectic Euler going forward, we are now ready to solve the restricted 3-body problem.", "meta": {"hexsha": "b53300be8311aa879b1d71ec116eba9ba746de6d", "size": 8440, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/appendices/Pendulum.tex", "max_stars_repo_name": "GandalfSaxe/leto", "max_stars_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/appendices/Pendulum.tex", "max_issues_repo_name": "GandalfSaxe/leto", "max_issues_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/appendices/Pendulum.tex", "max_forks_repo_name": "GandalfSaxe/leto", "max_forks_repo_head_hexsha": "d27c2a4a04518f4230a80ce83d0252257247a512", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.5057471264, "max_line_length": 491, "alphanum_fraction": 0.6806872038, "num_tokens": 2692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7133442968101643}}
{"text": "\n\\subsection{Tensor inverses}\n\nFor second order tensors we have:\n\n\\begin{itemize}\n\\item \\(T_j^i\\)\n\\item \\(T_{ij}\\)\n\\item \\(T^{ij}\\)\n\\end{itemize}\n\nFor each of these we can define an inverse:\n\n\\begin{itemize}\n\\item \\(T_i^jU_j^k=\\delta_i^k\\)\n\\item \\(T_{ij}U^{jk}=\\delta_i^k\\)\n\\item \\(T^{ij}U_{jk}=\\delta_i^k\\)\n\\end{itemize}\n\n\\subsubsection{Notation for inverses}\n\nIf we have \\(T_{ij}U^{jk}=\\delta_i^k\\), we can instead write:\n\n\\(T_{ij}T^{jk}=\\delta_i^k\\)\n\n", "meta": {"hexsha": "926b351013ad3b09e480064ef0f8619ec076e6f8", "size": 454, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/tensors/03-02-inverse.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/tensors/03-02-inverse.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/tensors/03-02-inverse.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.4615384615, "max_line_length": 61, "alphanum_fraction": 0.654185022, "num_tokens": 178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7132928483690935}}
{"text": "\\section{Kernels}\n\\smallskip \\hrule height 2pt \\smallskip\nIf the data is not linearly separable and/or you want a wiggly boundary, use kernels. \n\nCan use for things you can't handle with slack variables.  % wk 8 audio\n\nStart w/ original feature space, use polynomial of degree d, and get a higher dimensional space\n    then do a linear classifier in this space.   % wk 8 audio\n\\hfill \\\\  \\hfill \\\\\n\nCan give you nonlinear boundaries (good) but the feature space can get really large really quickly. \n\nExample mapping of data that is not linearly separable to a separable higher dimension space: \\hfill \\\\\n\\includegraphics[width=2.5in]{figures/example_kernel_separation.pdf}  \\hfill \\\\\n\nThe decision boundary would be a circle.  % wk 8 audio\n\\hfill \\\\\n\nIf you can't figure out what features you should use, this is a good approach.  % wk 8 audio. \nYou don't need the features themselves (??).   \\hfill \\\\\n?? You just need the kernel/similarity? matrix.??   \\hfill \\\\\n? gram matrix?   \\hfill \\\\\n\n\nGeneral idea: \\hfill \\\\\nIf $\\bm{x}$ is in $R^n$, then $\\phi(\\bm{x})$ is in $R^m$ for $m>n$. \\hfill \\\\\nWe can now learn feature weights $\\bm{w}$ in $R^m$ and predict using $y = sign(\\bm{w} \\cdot \\phi(\\bm{x}))$. \\hfill \\\\\n\\hfill \\\\\n\n\\textbf{A linear function in the higher dimensional space will be non-linear in the original space.}  \\hfill \\\\\n\\hfill \\\\\n\n% wk 8 audio. \nSay you had a 100,000 points, each of which have a100-dimensional (binary) feature vector.\nThe chances of being able to find a hyperplane that divides random assignments of binary values is very good.\nAlmost all of those vertices are empty.\nSo your chance of finding a desirable hyperplane increases dramatically.  \n??? Did I get this right?  Seems like we need to be comparing a feature vector to a transformed feature vector.  \n??? \n\\hfill \\\\  \\hfill \\\\\n\n\\subsubsection{Danger of Mapping to a Higher Dimensional Space:}\nThe number of terms in a polynomial of degree $d$ for $m$ input features is \n$\\displaystyle {d + m - 1}\\choose{d} $ $ \\displaystyle = \\frac{d + m - 1}{d!(m-1)!}$. \\hfill \\\\\nThis grows fast!  For $d=6$, $m=100$ you get about 1.6 billion terms.  \\hfill \\\\\n\nWe are taking a dot product of $m$ rows for the feature space times $d$ columns of polynomial. \nBut you also have terms for combinations of features.  E.g. \n\\includegraphics[width=0.8in]{figures/example_kernel.pdf}\n\n\\subsubsection{Efficient dot-product of polynomials}\nFor polynomials of degree exactly $d$, the dot product in higher dimensional space can be written as a dot product in lower dimensional space.  \\hfill \\\\\nFor $m=2$ (2 features): \\hfill \\\\\n\\includegraphics[width=2.5in]{figures/kernel_dot_polynomials.pdf}  \\hfill \\\\\nnote: here the $.$ is a dot product, not horizontal space fill like a previous lecture. \\hfill \\\\\n$u_1$ is feature 1's value, and $u_2$ is feature 2's value. \\hfill \\\\\nPolynomial of exactly degree $d$ means we \\underline{don't} have a constant bias term like in homework 3 with $[1, \\sqrt{2}u, u^2]$  \\hfill \\\\\nThis is just factoring.  \\hfill \\\\\n\\hfill \\\\\n\nProof not shown, but for any $d$: \\hfill \\\\\n$K(u, v) = \\bm{\\phi}(u).\\bm{\\phi}(v) = (u.v)^d$\n\n\\subsection{The \"Kernel Trick\"}\n\nWe like the idea of going to higher dim, but we don't like the idea of operating in it.  Expensive. \\hfill \\\\\n\\hfill \\\\\n\nWith this trick, we won't ever compute a dot product in the expensive space.   % wk 8 audio\nNot all $\\phi$ satisfy, but there are big categories that do it.  % wk 8 audio\nNeed to be able to represent a higher dim space as one in a lower dim space.  % wk 8 audio\nUsually exponentiation is used.  %wk 8 audio. \n%But it doesn't work with all projections, .  Just special ones. \n\\hfill \\\\ \\hfill \\\\\n\nA \\textbf{kernel function} defines a dot product in some feature space: \n\\begin{align*}\n\tK(\\bm{u}, \\bm{v}) =\\bm{\\phi}(\\bm{u}) \\cdot \\bm{\\phi}(\\bm{v})\n\\end{align*}\nWhere $\\bm{u}$, $\\bm{v}$ are points in your training or test set, each with their own features. \\hfill \\\\ \nOr $\\bm{u}$ could be a data point and $\\bm{v}$ could be the $\\bm{w}$ of the hyperplane that you need to dot against to classify new points.\n \\hfill \\\\\n \n If $\\bm{u}$, $\\bm{v}$ each have two dimensions (2 features): \\hfill \\\\\n\n\\includegraphics[width=3.1in]{figures/example_kernel_math.pdf} \\hfill \\\\\nThus, a kernel function \\textit{implicitly} maps data to a high-dimensional space without the need to compute each $\\bm{\\phi}(\\bm{x})$ explicitly.   \\hfill \\\\\nIf we had $d = 100$ instead, our savings would be huge. \n \\hfill \\\\\n\nTranslation for this particular kernel: \\hfill \\\\\nWe want to get the perks of the high dimensional space given by $\\bm{\\phi}(\\bm{x}) = [1, x_1^2, \\sqrt{2}x_1 x_2, x_2^2, \\sqrt{2} x_1, \\sqrt{2} x_2]$ where $\\bm{x}$ is either $\\bm{u}$ or $\\bm{v}$.  \\hfill \\\\\nBut this is computationally expensive because there are many terms in that thing.  \\hfill \\\\\nIf we take the dot product of two vectors $\\bm{\\phi}(\\bm{u})$, $\\bm{\\phi}(\\bm{v})$ we get some magic: \\hfill \\\\\n\\begin{align*}\n\t\\bm{\\phi}(\\bm{u}) \\cdot \\bm{\\phi}(\\bm{v}) &= [1, u_1^2, \\sqrt{2}u_1 u_2, u_2^2, \\sqrt{2} u_1, \\sqrt{2} u_2]  \\cdot \\quad \\mbox{(line wrapped)} \\\\\n\t\t\t& \\quad \\quad [1, v_1^2, \\sqrt{2}v_1 v_2, v_2^2, \\sqrt{2} v_1, \\sqrt{2} v_2]   \\\\\n\t\t&=  (1 + \\bm{u} \\cdot \\bm{v})^2\n\\end{align*}\nCan do $(1 + \\bm{u} \\cdot \\bm{v})^2$ with a dot product that only includes multiplying $[u_1, u_2]^T[v_1, v_2]$.     \\hfill \\\\ \nThat's a lot less computation/memory expensive than the full dot product above.  \\hfill \\\\\nIf that leads to good separation, you are a happy machine learner!   \\hfill \\\\\n\\textbf{This is true for other kernels in general.}   \\hfill \\\\\n($(1 + \\bm{u} \\cdot \\bm{v})^2$ would take other forms for other cases).   \\hfill \\\\\n\\hfill \\\\\n\nIt is essential that everything you want to do with your transformed vectors is representable by simple dot products.\nIf you can't simplify it down to dot products of the original vector then there's no point. \n\n\\subsection{\"Kernel Trick\" for the Perceptron}\n\n\\subsubsection{Intro to $ \\displaystyle w = \\sum_k a^k \\phi(x^k)$}\nIf we wanted to apply a transformation of the data $\\phi(x^i)$ to each of our $x^i$ training points, we would do: \\hfill \\\\\nFor $t = 1 \\dots T$, $i = 1, \\dots n$:\n\\begin{itemize}\n\t\\item $ y = sign(w \\cdot \\phi(x^i))$\n\t\\item if $y \\neq y^i$:  (if class wasn't predicted correctly)\n\t\\begin{itemize}\n\t\t\\item $ \\quad w = w + y^i \\phi(x^i)$  % update $w$: \n\t\t%\\item $a^i += y^i$\n\t\\end{itemize}\n\\end{itemize}\n\nWe can re-write $w$ as $ \\displaystyle \\sum_j y^j x^j$ for one loop over the data, if $j$ is the index of the points that were wrongly classified and thus contributed to the weights $w$.  \nbut we have multiple epochs: $t = 1 \\dots T$.  \nThe point might be classified wrong the first time but right the 2nd and 3rd times.  \\hfill \\\\\nSo we can use different notation to keep track of how each point adds to the weights\n\tdepending on whether it was predicted correctly and whether it was a $y=1$ or $y = -1$.  \\hfill \\\\\n\t\nThis looks like $ \\displaystyle w = \\sum_k a^k \\phi(x^k)$   \\hfill \\\\\nWe get $a^k$ from the modified loop over the data points shown below. \\hfill \\\\\nNote: we switch from index $i$ over the data points to $k$ because we might see data points that are identical in the training set.  \nWe don't need to keep track of those $\\phi(x^k)$ points separately with separate $k$ indices and hence $a^k$ values if they are the same.  \nJust keep summing up their signs as needed to modify $w$. \n\nNew protocol: \\hfill \\\\\nFor $t = 1 \\dots T$, $i = 1, \\dots n$:\n\\begin{itemize}\n\t\\item $ y = sign(w \\cdot \\phi(x^i)$\n\t\\item if $y \\neq y^i$:  (if class wasn't predicted correctly)\n\t\\begin{itemize}\n\t\t%\\item $ \\quad w = w + y^i \\phi(x^i)$  % update $w$: \n\t\t\\item $ \\quad a^i += y^i$\n\t\\end{itemize}\n\\end{itemize}\n\nFor example, say you loop over data point $k$ with $\\phi(x^k) = [1, 2, 3]$ and label $y^k = -1$ three times.\nIf you got it wrong the first two times and right the third time you would have this point contributing \n$w = -[1, 2, 3] -[1, 2, 3] + 0[1, 2, 3]$. \\hfill \\\\\nIn the loop we would have had $a^k = -1 -1$ for the two passes through that we got it wrong.  \\hfill \\\\\n\nIf we kept track of those $a$ values for all $i$ or $k$ data points, then we get that thing above: \n$ \\displaystyle w = \\sum_k a^k \\phi(x^k)$ \n\n\\subsubsection{The Kernelized Perceptron} % $w = \\sum_k a^k \\phi(x^k)$ in \n\nProtocol: \\hfill \\\\\nSet $a^i = 0$ for each example $i$ \\hfill \\\\\nFor $t = 1 \\dots T$, $i = 1, \\dots n$:  \\hfill \\\\\n\\begin{itemize}\n\t\\item $ \\displaystyle y = w \\cdot \\phi(x^i) $ \\hfill \\\\\n\t\t\t $ \\displaystyle \\quad \\mbox{use } w = \\sum_k a^k \\phi(x^k) $  \\hfill \\\\\n\t\t\t$ \\displaystyle \\quad = sign( ( \\sum_k a^k \\phi(x^k))  \\cdot \\phi(x^i))$  \\hfill \\\\\n\t\t\t$ \\displaystyle  \\quad = sign( \\sum_k a^k K(x^k, x^i) )$\n\t\\item if $y \\neq y^i$:  (if class wasn't predicted correctly)\n\t\\begin{itemize}\n\t\t%\\item $ \\quad w = w + y^i \\phi(x^i)$  % update $w$: \n\t\t\\item $ \\quad a^i += y^i$\n\t\\end{itemize}\n\\end{itemize}\n\nThe points: \n\\begin{itemize}\n\t\\item We never compute the features explicitly. \\hfill \\\\\n\t\tIf $x^i$ has 3 features, $\\phi(x^i)$ might have 9 items such as polynomials.  \\hfill \\\\\n\t\tBut we don't have to calculate those 9 features if they correspond to a Kernel. \\hfill \\\\\n\t\tWe might be able to use something like the simplification to $(1 + \\bm{u} \\cdot \\bm{v})^2$ \n\t\t\tsimplification just before this. \n\t\\item We compute the dot products in \"closed form\": $K(u, v) = \\phi(u) \\cdot \\phi(v)$ \\hfill \\\\\n\t\tA \"closed form\" expression is a mathematical expression that can \n\t\t\tbe evaluated in a finite number of operations.\n\t\t(You can calculate it efficiently; it is possible you would have an infinite number of features.)  % Erick 2/24 \n \n\\hfill \\\\\n\n\\end{itemize}\n\n\\subsubsection{Kernelized Perceptron Example}\n\n\\includegraphics[width=3.4in]{figures/kernelized_perceptron_example.pdf}\n\n\\subsubsection{Common Kernels}\n\n\\includegraphics[width=2.0in]{figures/common_kernels.pdf} \\hfill \\\\\nHow do we pick the kernel? \nYou will get a poor result if you pick the wrong Kernel. \nThere is no theory that tells you which kernel to use, so try a few and see which works bets.  \\hfill \\\\\n\nFor our class:\n\\begin{itemize}\n\t\\item try the polynomial of up to degree d.\n    \t\\item Gaussian is probably the most common.\n    \t\\item Sigmoid pushes one side down and the other side up.\n\\end{itemize}\n\n\\subsubsection{Kernels: Overfitting}\n\nWith Kernels we have a huge feature space, so over-fitting can happen. \\hfill \\\\\nIt turns out, however, that it can be robust to overfitting. \\hfill \\\\\nPeople have spent a lot of time figuring out regularization for different Kernel methods. \\hfill \\\\\nCan do things like limiting the number of updates the Perceptron does. \\hfill \\\\\nSVMs have have a clearer story for avoiding overfitting.  \\hfill \\\\\n\nDo keep in mind that \\textbf{everything overfits sometimes}!\n\nYou can also control by:\n\\begin{itemize}\n\t\\item Choosing a better Kernel\n\t\\item Varying parameters of the Kernel, such as the width of Gaussian.\n\t\\item  limit dimensionality, add regularization terms (e.g. L1, L2)\n\\end{itemize}\n\n\\subsubsection{Kernels in Logistic Regression}\nHad: \\hfill \\\\\n$P(Y=0 | \\bm{X}= \\bm{x}, \\bm{w}, w_0 )= \\frac{1}{1 + \\exp(w_0 + \\bm{w}\\cdot \\bm{x})}$ \\hfill \\\\\n \\hfill \\\\\n\nWe can define weights in terms of data points: \\hfill \\\\\n$\\displaystyle  \\bm{w} = \\sum_j \\alpha^j \\phi(\\bm{x}^j)$  \\hfill \\\\\nThat leads to \n\\begin{align*}\n\tP(Y=0 | \\bm{X}= \\bm{x}, \\bm{w}, w_0 ) &= \\frac{1}{1 + \\exp(w_0 +  \\sum_j  \\alpha^j \\phi(\\bm{x}^j) \\cdot \\phi(\\bm{x}))} \\\\\n\t\t& = \\frac{1}{1 + \\exp(w_0 +  \\sum_j  \\alpha^j K(\\bm{x}^j , \\bm{x})} \\\\\n\\end{align*}\n\nWe can derive the gradient descent rule on $\\alpha^j$, $w_0$.  ???  \\hfill \\\\\n\nSimilar tricks for all linear models: SVMs, etc. \n\n\\subsubsection{Kernels: overfitting \\& number of parameters}\nMost of the time Kernels are better behaved for over-fitting (? than \\_\\_\\_).  But they are more expensive. \nWhy? \nFor the perceptron, we optimize $\\bm{w}$.  Each time, we update $\\bm{w}$.  \n        The dimensionality of $\\bm{w}$ is $d$ or $d+1$, depending on how you consider it. \n    With kernel we are optimizing $\\bm{a}$. \n        Dimensionality of $\\bm{a}$ is way bigger than $d$, the dimensionality of the data. \n    We are optimizing for way more dimensions.  \\hfill \\\\\n    \nWe are explaining points based on other points in the data set\nHow similar is a new point to x1, x2, xn. \nThat's why we are worried about how many summations/iterations you will do. \n\n\\subsubsection{Kernels for SVM = not easy}.\nFor SVM using the kernel isn't as easy to apply.  In Logistic regression it is easy to optimize. \n    SVM requires you to write stuff down on paper. \n    \n\\subsection{Kernel Summary}\nSummary: \n\\begin{itemize}\n    \\item Expand the data to a higher dimension\n    \\item might be expensive\n    \\item arrive at kernel trick: approximates dot prod on higher dim space by forming dot prod in original space\n    \\item we derived polynomial kernels.\n\\end{itemize}\n \nQuestion: When I see a new instance in Kernelized perceptron, do I need to add it to my matrix?   \\hfill \\\\\nAnser: no.  If you do the matrix, you compute it all in the beginning.   \\hfill \\\\\nNote: for homework we did it on-line.  \\hfill \\\\\n\nMethod:\n\\begin{itemize}\n        \\item Separate training and test data.  \n        \\item During training, give n data points all beforehand.  Allows you to form matrix. \n        \\item Train to get a values and kernel matrix. \n        \\item Then done training.  \n        \\item Go to testing phase.  Give new instance and ask to classify.\n        \\item Don't need to add new instance to kernel matrix.  \n        \\item Compute similarity to all of the points you have seen. \n\\end{itemize}\n\n\\textbf{You do need to store the points you got right.}\nGood to stick to sparse \\_\\_\\_ for a . \n\n\n\n", "meta": {"hexsha": "69058111fb61fe5a7695d407fdcf74c6a4d2ad61", "size": 13749, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/kernels.tex", "max_stars_repo_name": "JanetMatsen/Machine-Learning", "max_stars_repo_head_hexsha": "12e1f701eb7de89b97d5caffe86b0267731e4cb5", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2016-02-07T23:35:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-26T05:13:33.000Z", "max_issues_repo_path": "tex/kernels.tex", "max_issues_repo_name": "JanetMatsen/Machine-Learning", "max_issues_repo_head_hexsha": "12e1f701eb7de89b97d5caffe86b0267731e4cb5", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/kernels.tex", "max_forks_repo_name": "JanetMatsen/Machine-Learning", "max_forks_repo_head_hexsha": "12e1f701eb7de89b97d5caffe86b0267731e4cb5", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2016-08-29T00:15:49.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-06T22:36:19.000Z", "avg_line_length": 48.0734265734, "max_line_length": 206, "alphanum_fraction": 0.6836860863, "num_tokens": 4304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708698, "lm_q2_score": 0.8774767986961403, "lm_q1q2_score": 0.7132722038650098}}
{"text": "\\subsection{Classification of Elliptic Functions}\r\nWe already classified the meromorphic functions on $\\mathbb C_\\infty$.\r\nRemarkably, we can do something similar for the torus $\\mathbb C/\\Lambda$.\r\n\\begin{theorem}\r\n    Let $f$ be an elliptic functions with periods $\\Lambda$.\r\n    There exists rational functions $Q_1,Q_2$ such that\r\n    $$f(z)=Q_1(\\wp(z))+Q_2(\\wp(z))\\wp^\\prime(z)$$\r\n    where $\\wp=\\wp_\\Lambda$.\r\n    Furthermore, $f$ is even, then $Q_2=0$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    First assume $f$ is even.\r\n    Now $f,\\wp$ both have finitely many branch points by compactness.\r\n    So we may choose distinct $c,d\\in\\mathbb C$ which are not branch points of $f,\\wp$.\r\n    Now consider the function $z\\mapsto (f(z)-c)/(f(z)-d)$ which is analytic (as it is the composition of $f$ with a M\\\"obius transformation), even, and has simple zeros and poles not at ramification points of $\\wp$.\r\n    Note that we can invert M\\\"obius transformations nicely, therefore we can WLOG assume that $f$ has these properties.\r\n    Since $f$ is even, the zeros of $f$ can be written as $\\{\\pm a_1,\\ldots,\\pm a_m\\}$ where $a_i\\neq\\pm a_j$ for $i\\neq j$.\r\n    Likewise we can write the poles of $f$ as $\\{\\pm b_1,\\ldots,\\pm b_n\\}$.\r\n    We can write down an elliptic function with the same zeros and poles, namely\r\n    $$g(z)=\\frac{(\\wp(z)-\\wp(a_1))\\cdots (\\wp(z)-\\wp(a_m))}{(\\wp(z)-\\wp(b_1))\\cdots (\\wp(z)-\\wp(b_n))}$$\r\n    So $f/g$ is elliptic but does not have any zeros or poles, therefore is constant.\r\n    The claim follows.\\\\\r\n    If $f$ is odd, then $f(z)/\\wp^\\prime(z)$ is even hence $f$ can be written as the desired form as well by the previous part.\r\n    For general $f$, simply write it as the sum of odd and even parts\r\n    $$f(z)=\\frac{f(z)+f(-z)}{2}+\\frac{f(z)-f(-z)}{2}$$\r\n    which completes the proof.\r\n\\end{proof}", "meta": {"hexsha": "6b5a60c6237c847840d303e1ebae9a00c14cca83", "size": 1825, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15/class.tex", "max_stars_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_stars_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "15/class.tex", "max_issues_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_issues_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "15/class.tex", "max_forks_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_forks_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.5925925926, "max_line_length": 217, "alphanum_fraction": 0.6608219178, "num_tokens": 578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.713272196738228}}
{"text": "\\section{Overview of Supervised Learning}\n\n\\subsection{Exercise 2.1}\nThis question is poorly worded. We assume that the question means there exists some model that, given $x$,\npredicts a vector $\\hat{y}$ such that $\\hat{y}_k$ is the probability that $x$ belongs to class $k$. We then\nhave that\n\\begin{align*}\n        \\text{arg}\\min_k \\norm{t_k - \\hat{y}} &= \\text{arg}\\min_k \\sum_{i = 1}^K \\big((t_k)_i - \\hat{y}_i\\big)^2 \\\\\n                                    &= \\text{arg}\\min_k (1 - \\hat{y}_k)^2 + \\sum_{i = 1, i \\neq k}^K \\hat{y}_i^2 \\\\\n                                    &= \\text{arg}\\min_k (1 - \\hat{y}_k)^2 + \\sum_{i = 1, i \\neq k}^K \\hat{y}_i^2 - \\sum_{i = 1}^K \\hat{y}_i^2\\\\\n                                    &= \\text{arg}\\min_k (1 - \\hat{y}_k)^2 - \\hat{y}_k^2 \\\\\n                                    &= \\text{arg}\\min_k 1 - 2\\hat{y}_k \\\\\n                                    &= \\text{arg}\\max_k \\hat{y}_k\n\\end{align*}\n", "meta": {"hexsha": "e2fcbd4fdf47c4247f4c9db201f8867c751a0a19", "size": 929, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Elements_of_Statistical_Learning/chapter_2.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "Elements_of_Statistical_Learning/chapter_2.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Elements_of_Statistical_Learning/chapter_2.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.9333333333, "max_line_length": 143, "alphanum_fraction": 0.491926803, "num_tokens": 326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620619801095, "lm_q2_score": 0.7431680029241322, "lm_q1q2_score": 0.7132644548841052}}
{"text": "\\section{Method}\n\nIn this section we cover the precise details of how to construct the objective and constraint equations,\ngiven that we represent $\\bm{x}(t)$ as a cubic spline.\n\n\\subsection{Assumptions}\n\nTo make this problem tractable, we will make two simplifying assumptions:\n\\begin{itemize}\n  \\setlength\\itemsep{0em}\n  \\item the trajectory will be a cubic spline\n  \\item the knot points of the spline will be given\n\\end{itemize}\n\n\\subsection{Outline}\n\nThe problem outlined in Section \\ref{sec:ProblemStatement} can be posed as a quadratic program,\nwhere $\\mathcal{H}$ and $\\bf{f}$ are the quadratic and linear cost matrices,\n$\\mathcal{A}$ and $\\bf{b}$ are the equality constraints, and\n$\\bm{z}$ is the vector of decision variables: the coefficients of the cubic spline.\n\n\\begin{align}\n  & \\quad  & \\quad & \\quad &\n    \\text{minimize:}  & \\quad  & \\tfrac{1}{2} \\bm{z}^T \\mathcal{H} \\bm{z} + \\bm{f}^T \\bm{z}\n  & \\quad  & \\quad &  \\quad &\\\\\n  & \\quad  & \\quad & \\quad &\n    \\text{subject to:}  & \\quad & \\mathcal{A} \\bm{z} = \\bm{b}\n  & \\quad  & \\quad & \\quad &\n\\end{align}\n\nThis is a special quadratic program: it does not have inequality constraints.\nAs a result, this quadratic program can be solved as the linear system shown below,\nwhere $\\bm{w}$ is a vector of Lagrange multipliers for the constraint equations.\n\n\\begin{equation}\n\n\\begin{bmatrix}\n\\mathcal{H} & \\mathcal{A}^T \\\\\n\\mathcal{A} & \\bm{0}\n\\end{bmatrix}\n\\cdot\n\\begin{bmatrix}\n\\bm{z} \\\\\n\\bm{w}\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n-\\bm{f}  \\\\\n\\bm{b}\n\\end{bmatrix}\n\n\\label{eqn:linearSplineSystem}\n\\end{equation}\n\nOnce we have constructed the matrices\n$\\mathcal{H}$,  $\\bf{f}$,  $\\mathcal{A}$, and $\\bf{b}$,\nwe can then solve the linear system (\\ref{eqn:linearSplineSystem})\nfor the decision variables to $\\bm{z}$: the spline coefficients.\n\n\\subsection{Block Matrices}\n\nNote that the matrices $\\mathcal{H}$ and $\\mathcal{A}$ are large and sparse,\nas shown in Figure \\ref{fig:SparsityPattern}.\nThese matrices should be implemented as sparse matrices, and the linear system solved using a sparse solver.\n\n\\begin{figure}[ht]\n\t\\centering\n  \\includegraphics[width=\\textwidth]{fig/SparsityPattern.pdf}\n  \\caption{The sparsity pattern for the spline shown in Figure \\ref{fig:DataFittingExampleFigure}.\n           It has 20 cubic segments and thus 4*20 = 80 decision variables.\n           Notice that the quadratic cost matrix is perfectly block diagonal.\n           The first 3*(20-1) rows of the constraint matrix are perfectly block diagonal,\n             representing the continuity constraints.\n           The final six rows are different, representing the boundary constraints.}\n  \\label{fig:SparsityPattern}\n\\end{figure}\n\nThe matrices $\\mathcal{H}$ and $\\mathcal{A}$ are constructed from smaller blocks,\nwhere each block corresponds to the coefficients of a single segment. For example,\n$\\mathcal{H}_j$ is the $4 \\times 4$ block in the $\\mathcal{H}$ matrix that corresponds to the\nspline segment $j$.\nSimilarly, $\\mathcal{A}_{k,j}$ is the $3 \\times 4$ block of coefficients\nfor the $k^\\text{th}$ set of constraints on the coefficients of spline segment $j$.\n\n\\subsection{Spline Definition}\n\nWe will represent the trajectory as a cubic spline, with knot points $T_j$ where $j \\in \\{ 0 \\dots M\\}$.\nA single segment of the spline is given below,\nwhere $j$ is the segment index, and\n$\\tau = t - T_j$ is the time since the start of the segment.\nThe function $\\bm{x}(t)$ is constructed by chaining together each of the segments $\\bm{x}_j(t)$ in order.\n\n\\begin{equation}\n  \\bm{x}_j(\\tau) = \\bm{A}_j \\tau^3 + \\bm{B}_j \\tau^2 + \\bm{C}_j \\tau + \\bm{D}_j\n\\end{equation}\n\nThe derivatives of this spline are easily computed, as shown below:\n\\begin{equation}\n  \\dot{\\bm{x}}_j(\\tau)\n    = \\frac{d}{dt} \\bm{x}_j(\\tau)\n    = 3 \\bm{A}_j \\tau^2 + 2 \\bm{B}_j \\tau + \\bm{C}_j\n\\end{equation}\n\\begin{equation}\n  \\ddot{\\bm{x}}_j(\\tau)\n    = \\frac{d}{dt} \\dot{\\bm{x}}_j(\\tau)\n    = 6 \\bm{A}_j \\tau + 2 \\bm{B}_j\n\\end{equation}\n\\begin{equation}\n  \\dddot{\\bm{x}}_j(\\tau)\n    = \\frac{d}{dt} \\ddot{\\bm{x}}_j(\\tau)\n    = 6 \\bm{A}_j\n\\end{equation}\n\nWe will represent the coefficients of a single segment of the spline as\n$\\bm{z}_j = [\\bm{D}_j, \\bm{C}_j, \\bm{B}_j, \\bm{A}_j]^T$,\nand the coefficients of the entire spline as\n$\\bm{z} = [\\bm{z}_0, \\bm{z}_1, \\dots, \\bm{z}_{M-1}]^T$.\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\n\\subsection{Spline Continuity}\n\nThe spline coefficients are constructed such that value, slope, and curvature are continuous.\nThis can be written as a set of three equations at each knot point, where\n$h_j = T_{j+1} - T_j$ is the duration of segment $j$.\n\\begin{equation}\n  \\bm{x}_j(h_j) - \\bm{x}_{j+1}(0) = \\bm{0}\n\\end{equation}\n\\begin{equation}\n  \\dot{\\bm{x}}_j(h_j) - \\dot{\\bm{x}}_{j+1}(0) = \\bm{0}\n\\end{equation}\n\\begin{equation}\n  \\ddot{\\bm{x}}_j(h_j) - \\ddot{\\bm{x}}_{j+1}(0) = \\bm{0}\n\\end{equation}\n\nThese equations form the blocks on the diagonals of the $\\mathcal{A}$ matrix.\nEach set of three constraints at a knot point populates two blocks of the constraint matrix,\none for the lower segment and one for the upper segment.\n\n\n\\begin{equation}\n\\begin{bmatrix}\n\\mathcal{A}_{k, j} & \\mathcal{A}_{k, j+1}\n\\end{bmatrix}\n\\cdot\n\\begin{bmatrix}\n\\bm{z_j} \\\\\n\\bm{z_{j+1}}\n\\end{bmatrix}\n=\n\\bm{b}_k\n\\label{eqn:continuityEquationsSymbols}\n\\end{equation}\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\n\\begin{equation}\n\n\\mathcal{A}_{k, j}\n=\n\\begin{bmatrix}\n1 & h_j & h_j^2  & h_j^3 \\\\\n0 & 1   & 2 h_j  & 3 h_j^2 \\\\\n0 & 0   & 2      & 6 h_j\n\\end{bmatrix}\n\n\\quad \\quad \\quad\n\n\\mathcal{A}_{k, j+1}\n=\n\\begin{bmatrix}\n-1 & 0 & 0  & 0 \\\\\n0 & -1   & 0  & 0 \\\\\n0 & 0   & -2      & 0\n\\end{bmatrix}\n\n\\label{eqn:continuityEquationExplicitPartOne}\n\\end{equation}\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\n\\begin{equation}\n\n\\bm{z}_j\n=\n\\begin{bmatrix}\n\\bm{D}_j \\\\\n\\bm{C}_j \\\\\n\\bm{B}_j \\\\\n\\bm{A}_j\n\\end{bmatrix}\n\n\\quad \\quad \\quad\n\n\\bm{z}_{j+1}\n=\n\\begin{bmatrix}\n\\bm{D}_{j+1} \\\\\n\\bm{C}_{j+1} \\\\\n\\bm{B}_{j+1} \\\\\n\\bm{A}_{j+1}\n\\end{bmatrix}\n\n\\quad \\quad \\quad\n\n\\bm{b}_k\n=\n\\begin{bmatrix}\n\\bm{0} \\\\\n\\bm{0} \\\\\n\\bm{0}\n\\end{bmatrix}\n\n\n\\label{eqn:continuityEquationExplicitPartTwo}\n\\end{equation}\n\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\\subsection{Boundary Constraints}\n\nThe boundary constraints are similar to the continuity equations,\nbut they use only a single block in the $\\mathcal{A}$ matrix and a non-zero block in the $\\bm{b}$ matrix.\nTo keep notation simple through this section,\nwe will define $L = M-1$ to be the index of the final segment of the spline.\n\n\\begin{align}\n  \\bm{x}_0(0) = \\bm{x}_0  & \\quad &  \\bm{x}_L(h_L) = \\bm{x}_T \\\\\n  \\dot{\\bm{x}}_0(0) = \\dot{\\bm{x}}_0  & \\quad & \\dot{\\bm{x}}_L(h_L) = \\dot{\\bm{x}}_T \\\\\n  \\ddot{\\bm{x}}_0(0) = \\ddot{\\bm{x}}_0  & \\quad & \\ddot{\\bm{x}}_L(h_L) = \\ddot{\\bm{x}}_T\n\\end{align}\n\nThe lower boundary equation can be written:\n\n\\begin{equation}\n\\mathcal{A}_{\\ell, 0}\n\\cdot\n\\bm{z_0}\n=\n\\bm{b}_\\ell\n\\label{eqn:lowerBoundaryConstraintSymbols}\n\\end{equation}\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\n\\begin{equation}\n\n\\mathcal{A}_{\\ell, 0}\n=\n\\begin{bmatrix}\n  1 & 0 & 0  & 0 \\\\\n  0 & 1   & 0  & 0 \\\\\n  0 & 0   & 2      & 0\n\\end{bmatrix}\n\n\\quad \\quad \\quad\n\n\\bm{z}_0\n=\n\\begin{bmatrix}\n  \\bm{D}_0 \\\\\n  \\bm{C}_0 \\\\\n  \\bm{B}_0 \\\\\n  \\bm{A}_0\n\\end{bmatrix}\n\n\\quad \\quad \\quad\n\n\\bm{b}_\\ell\n=\n\\begin{bmatrix}\n  \\bm{x}_0 \\\\\n  \\dot{\\bm{x}}_0 \\\\\n  \\ddot{\\bm{x}}_0\n\\end{bmatrix}\n\n\\label{eqn:lowerBoundaryConstraint}\n\\end{equation}\n\n\nThe upper boundary equation can be written:\n\n\\begin{equation}\n\\mathcal{A}_{\\ell+1, L}\n\\cdot\n\\bm{z_L}\n=\n\\bm{b}_{\\ell+1}\n\\label{eqn:upperBoundaryConstraintSymbols}\n\\end{equation}\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\n\\begin{equation}\n\n\\mathcal{A}_{\\ell+1, L}\n=\n\\begin{bmatrix}\n1 & h_L & h_L^2  & h_L^3 \\\\\n0 & 1   & 2 h_L  & 3 h_L^2 \\\\\n0 & 0   & 2      & 6 h_L\n\\end{bmatrix}\n\n\\quad \\quad \\quad\n\n\\bm{z}_L\n=\n\\begin{bmatrix}\n  \\bm{D}_L \\\\\n  \\bm{C}_L \\\\\n  \\bm{B}_L \\\\\n  \\bm{A}_L\n\\end{bmatrix}\n\n\\quad \\quad \\quad\n\n\\bm{b}_{\\ell+1}\n=\n\\begin{bmatrix}\n  \\bm{x}_T \\\\\n  \\dot{\\bm{x}}_T \\\\\n  \\ddot{\\bm{x}}_T\n\\end{bmatrix}\n\n\\label{eqn:upperBoundaryConstraint}\n\\end{equation}\n\n\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\n\\subsection{Objective Function}\n\nUnlike the constraint matrices, the objective function matrices are made of up a sum\nof many components. A single segment will have a term from the minimum-jerk component,\nas well as a term for each point in the data set that is on the time-domain of that segment.\nThus, we can rewrite the objective function (\\ref{eqn:continuousObjectiveFunction}) as\nsum over segments:\n\n\\begin{equation}\n  \\bm{J} =  \\sum_{j=0}^{M-1} \\bm{J}_j\n\\end{equation}\n\nSimilarly, the cost of a single segment can be constructed as follows,\nwhere $\\mathcal{I}$ is the set of points such that $t_i \\in [T_j, T_{j+1})$.\n\n\\begin{equation}\n  \\bm{J}_j =  \\alpha J_j^\\text{ smooth}\n  + \\frac{T}{N} \\sum_{i \\in I_j}  J_{j}^\\text{i}\n\\end{equation}\n\nIn practice, the segment cost is implemented by\nsumming blocks of the $\\mathcal{H}$ and $\\bm{f}$ matrices.\nThese blocks are thus computed:\n\n\\begin{equation}\n  \\bm{H}_j =  \\alpha \\bm{H}_j^\\text{ smooth}\n  + \\frac{T}{N} \\sum_{i \\in I_j}  \\bm{H}_{j}^\\text{i}\n\\end{equation}\n\n\\begin{equation}\n  \\bm{f}_j =  \\alpha \\bm{f}_j^\\text{ smooth}\n  + \\frac{T}{N} \\sum_{i \\in I_j}  \\bm{f}_{j}^\\text{i}\n\\end{equation}\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\n\\subsection{Data-Fitting}\nThe data-fitting term in the objective function is given by:\n\\begin{equation}\n  \\frac{T}{N}  \\sum_{i=0}^N \\big( \\bm{x}(t_i) - \\bar{\\bm{x}}_i \\big)^2\n\\end{equation}\n\nWe will construct the equations for a single  point $\\{t_i, \\bar{\\bm{x}}_i\\}$ from the data set,\nwhere $t_i \\in [T_j, T_{j+1})$.\nIn other words, the point is on segment $j$.\nThe squared-error between the point and the segment is thus given by:\n\n\\begin{equation}\n  J_j^i = \\bigg( \\bm{x}_j(t_i-T_j) - \\bar{\\bm{x}}_i\\bigg) ^ 2\n\\end{equation}\n\nAfter doing a bit of algebra, the block matrices for this equation are given below,\nwhere $\\tau_{ij} = t_i-T_j$ is the time between the data point $i$ and segment $j$.\nNote that $\\mathcal{H}_j^i$ is symmetric.\nThese matrices can them be computed for each point in the data set.\n\n\\begin{equation}\n  \\mathcal{H}_j^i\n  =\n  \\begin{bmatrix}\n    1 & \\tau_{ij} & \\tau_{ij}^2 & \\tau_{ij}^3 \\\\\n    \\tau_{ij} & \\tau_{ij}^2 & \\tau_{ij}^3  & \\tau_{ij}^4\\\\\n    \\tau_{ij}^2 & \\tau_{ij}^3  & \\tau_{ij}^4 & \\tau_{ij}^5\\\\\n    \\tau_{ij}^3  & \\tau_{ij}^4 & \\tau_{ij}^5& \\tau_{ij}^6\\\\\n  \\end{bmatrix}\n\n  \\quad \\quad \\quad\n\n  \\bm{f}_j^i\n  \\begin{bmatrix}\n    -\\bar{\\bm{x}}_i \\\\\n    -\\bar{\\bm{x}}_i \\, \\tau_{ij}\\\\\n    -\\bar{\\bm{x}}_i \\, \\tau_{ij}^2\\\\\n    -\\bar{\\bm{x}}_i \\, \\tau_{ij}^3\\\\\n  \\end{bmatrix}^T\n\n\\end{equation}\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\n\\subsection{Smoothing Objective}\n\nWe enforce a smooth spline by adding a term to minimize the integral of the curvature-rate-squared.\nThis is simple to compute for a cubic spline:\n\n\\begin{equation}\n  \\dddot{\\bm{x}}_j^2(t) = 36\\bm{A}_j^2\n\\end{equation}\n\nThe corresponding blocks in the $\\mathcal{H}$ and $\\bf{f}$ matrices are:\n\n\\begin{equation}\n  \\mathcal{H}_j^\\text{ smooth}\n  =\n  \\begin{bmatrix}\n    0 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 36\n  \\end{bmatrix}\n\n  \\quad \\quad \\quad\n\n  \\bm{f}_j^\\text{ smooth}\n  \\begin{bmatrix}\n    \\bm{0} \\\\\n    \\bm{0} \\\\\n    \\bm{0} \\\\\n    \\bm{0}\n  \\end{bmatrix}^T\n\n\\end{equation}\n", "meta": {"hexsha": "27f871954ceed4ef1f00a6ca57dadfa1b90131b9", "size": 11588, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "supplement/fit-spline-to-data/tex/method.tex", "max_stars_repo_name": "ShaneRozenLevy/ME149_Spring2018", "max_stars_repo_head_hexsha": "0cd1960cd3699ef4f24f824c89b32a64c73b5b99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 45, "max_stars_repo_stars_event_min_datetime": "2018-01-10T15:55:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T22:54:58.000Z", "max_issues_repo_path": "supplement/fit-spline-to-data/tex/method.tex", "max_issues_repo_name": "Boyang--Li/ME149_Spring2018", "max_issues_repo_head_hexsha": "333dcf4891ca05f007590f3a40f67ae46cf2cf6b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "supplement/fit-spline-to-data/tex/method.tex", "max_forks_repo_name": "Boyang--Li/ME149_Spring2018", "max_forks_repo_head_hexsha": "333dcf4891ca05f007590f3a40f67ae46cf2cf6b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-02-24T00:15:06.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T14:08:38.000Z", "avg_line_length": 26.0990990991, "max_line_length": 108, "alphanum_fraction": 0.6166724197, "num_tokens": 4067, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692238, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.7132167928067787}}
{"text": "\\documentclass[12pt,titlepage]{article}\n\n\\usepackage{amsmath,amssymb}\n\\usepackage{hyperref}\n\\usepackage{pgfplots}\n\\usepackage{siunitx}\n\\usepackage{placeins}\n\\usepackage{url}\n\n\\title{The Stroop Effect \\\\ \\vspace{10pt} \\large{\\it Udacity Deep Learning Nanodegree Statistics Project}}\n\\author{George Yu}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Basic Information}\n  \\begin{itemize}\n    \\item {\\bf Independent Variable}: the congruency of the words and the ink colors\n    \\item {\\bf Dependent Variable}: the time for the participant to name the ink colors in a list of words\n  \\end{itemize}\n  \n  According to \\cite{wiki:stroop-effect}, the participants will take longer to name the ink colors for the incongruent words, so the we should perform a one-tailed test on a sample. The null hypothesis is that for the population, there is no difference in both groups of words, and the alternative hypothesis is that the time taken for the incongruent group will be longer than the congruent group in the population, or,\n  \\begin{align*}\n    &\\mathbf{H_0}\\hspace{-2pt}:\\ \\mu_\\mathrm{i} - \\mu_\\mathrm{c} \\leqslant 0 \\\\\n    &\\mathbf{H_a}\\hspace{-2pt}:\\ \\mu_\\mathrm{i} - \\mu_\\mathrm{c} > 0,\n  \\end{align*}\n  where $\\mu_\\mathrm{i}$ is the population mean of the time for the incongruent words, and $\\mu_\\mathrm{c}$ is the population mean of the time for the congruent words.\n  \n  Since each participant will go through and record from each of the two conditions, so this experiment is a within-subject design, namely, it tests a sample of $n=24$ with two conditions. Therefore, a dependent samples $t$-test should be used. The reason for using a $t$-test rather than a $z$-test is that the we do not know the population parameters $\\mu$ and $\\sigma$.\n  \n  To conduct the $t$-test, we make the following assumptions:\n  \\begin{itemize}\n    \\item The population is approximately normally distributed\n    \\item The sample drawn from the population should be random\n    \\item The sample data can estimate population parameters\n    \\item The dependent variable (time to read the words) is continuous\n    \\item The pair-differences $\\overline{x}_\\mathrm{d}$ are independent of each other\n  \\end{itemize}\n\n\n\\section{Dataset}\n  \\autoref{fig:histogram} shows a visualization of the dataset. From this graph, we can see that the incongruent group are mainly distributed to the right of the congruent group. The congruent group is mainly distributed between 8.63 and 19.28, while the incongruent group is mainly distributed between 13.96 and 24.61.\n  \n  For the congruent group, the mean is $\\overline{x}_\\mathrm{c} \\approx 14.05$ with a sample standard deviation of $s_\\mathrm{c} \\approx 3.56$, and for the incongruent group, we have $\\overline{x}_\\mathrm{i} \\approx 22.02$ and $s_\\mathrm{i} \\approx 4.80$.\n  \n  \\begin{figure}[h]\n  \\centering\n    \\begin{tikzpicture}\n    \\begin{axis}[\n      width=0.8\\textwidth,\n      height=0.6\\textwidth,\n      x tick label style={xshift=-0.65cm},\n      xlabel=Time (\\si{s}),\n      x label style={at={(axis description cs:0.5,-0.03)},anchor=north},\n      enlarge y limits=upper,\n      minor y tick num = 1,\n      ybar interval=0.8,\n      area style,\n    ]\n    \\addplot+[ybar interval,mark=no] plot coordinates { (8.63, 11) (13.96, 11) (19.28, 2) (24.61, 0) (29.93, 0) (35.26, 0) (40.59, 0) };\n    \\addplot+[ybar interval,mark=no] plot coordinates { (8.63, 0) (13.96, 8) (19.28, 12) (24.61, 2) (29.93, 1) (35.26, 1) (40.59, 0) };\n    \\legend{Congruent,Incongruent}\n    \\end{axis}\n    \\end{tikzpicture}\n    \\caption{Data of }\n    \\label{fig:histogram}\n  \\end{figure}\n\n\n\\FloatBarrier\n\\section{Statistical Test}\n  First subtract the incongruent group with the congruent group, we get a new distribution of differences with $\\overline{x}_\\mathrm{d} \\approx 7.96$ and $s_\\mathrm{d} \\approx 4.86$.\n  \n  Using $\\alpha = 0.05$, we obtain that our one-tailed $t$-critical value with $n=24$ (degrees of freedom $\\nu = 23$), is $t^*=1.711$. Now, we can obtain the $t$-statistic,\n  $$ t = \\frac{\\overline{x}_\\mathrm{d} - \\mu_0}{s_\\mathrm{d}/\\sqrt{n}}, $$\n  where $\\mu_0$ is the expected mean difference, which is $\\mu_\\mathrm{i} - \\mu_\\mathrm{c} = 0$, thus,\n  $$ t = \\frac{7.96}{4.86 / \\sqrt{24}} \\approx 8.02. $$\n  \n  We can see that $t$ is statistically significant, since $p < .0001$, in conclusion,\n  $$ t(23) = 8.02,\\ p < .0001,\\ \\textrm{one-tailed}. $$\n  So, $\\overline{x}_\\mathrm{d}$ is significant at $p<0.05$, in other words, the difference in the two test groups are very unlikely due to chance, and since we are estimating the population parameter, we have $\\mu_\\mathrm{i} - \\mu_\\mathrm{c} > 0$, therefore we reject the null hypothesis. The result is what I expected.\n  The $95\\%$ confidence interval $CI$ is,\n  $$ 95\\%\\ CI = (5.91, 10.01). $$\n\n\n\\section{Evaluation}\n  Cohen's d is about 1.64, and the $r^2$ value is approximately $0.74$, which means that about 74\\% of the variation in the time taken to name the ink colors can be explained by the congruency of the words and the ink colors. Other factors that might have influenced the time could be the carry-over effect, the order of the tests that the participants take will perhaps influence their results.\n  \n  We can conduct a similar experiment but using a between-subject design, where two independent samples are selected randomly, and one group will be reading the congruent words where the other group will be reading the incongruent words. This experiment can then eliminate the possible inaccuracies caused by the carry-over effect.\n\n\n\\medskip\n \n\\bibliographystyle{unsrt}\n\\bibliography{stroop}\n\n\\end{document}\n", "meta": {"hexsha": "fc88178e961740b2bec026ac2ce61cecab348de2", "size": 5596, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "udacity-dl/1-inferential-stat/stroop-effect.tex", "max_stars_repo_name": "yu-george/ml", "max_stars_repo_head_hexsha": "8eedc62df9e7f37312bba39fa45bb9e9c6361028", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "udacity-dl/1-inferential-stat/stroop-effect.tex", "max_issues_repo_name": "yu-george/ml", "max_issues_repo_head_hexsha": "8eedc62df9e7f37312bba39fa45bb9e9c6361028", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "udacity-dl/1-inferential-stat/stroop-effect.tex", "max_forks_repo_name": "yu-george/ml", "max_forks_repo_head_hexsha": "8eedc62df9e7f37312bba39fa45bb9e9c6361028", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.96, "max_line_length": 420, "alphanum_fraction": 0.7128305933, "num_tokens": 1671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907933, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7132018193111642}}
{"text": "\n\\section{Deep finite neuron functions, adaptivity and spectral\n  accuracy}  \n\\label{sec:deep-fnm} \nIn this section, we will study deep finite neural functions through\nthe framework of  deep neural networks and then discuss its adaptive\nand spectral accuracy properties. \n\n\\subsection{Deep finite neuron functions}\nGiven $d, \\ell\\in\\mathbb{N}^+$, \n$\nn_1,\\dots,n_{\\ell}\\in\\mathbb{N} \\mbox{ with }n_0=d, n_{\\ell+1}=1, \n$\n\\begin{equation}\\label{thetamap}\n\\theta^i(x)=\\omega_i\\cdot x + b_i,\\quad \\omega_i\\in \\mathbb{R}^{n_{i+1}\\times n_i},\\ b\\in \\mathbb{R}^{n_{i+1}},\n\\end{equation}\nand the activation function ${\\rm ReLU}^k$, define\na  deep finite neuron function $u(x)$ from $\\mathbb{R}^d$ to $\\mathbb{R}$  as follows:\n\\begin{align*}\nf^0(x)   &=\\theta^0(x) \\\\ \nf^{i}(x) &= [  \\theta^{i} \\circ \\sigma ](f^{i-1}(x)) \\quad i = 1:\\ell \\\\\nf(x) &= f^\\ell(x). \\\\\n\\end{align*}\nThe following more concise notation is often used in computer science literature:\n\\begin{equation}\n\\label{compress-dnn}\nf(x) = \\theta^{\\ell}\\circ \\sigma \\circ \\theta^{\\ell-1} \\circ \\sigma \\cdots \\circ \\theta^1 \\circ \\sigma \\circ \\theta^0(x),\n\\end{equation}\nhere $\\theta^i: \\mathbb{R}^{n_{i}}\\to\\mathbb{R}^{n_{i+1}}$ are linear\nfunctions as defined in \\eqref{thetamap}.  Such a deep neutral network\nhas $(\\ell+1)$-layer DNN, namely $\\ell$-hidden layers. The size of\nthis deep neutral network is $n_1+\\cdots+n_{\\ell}$.\n\nBased on these notation and connections, define deep finite neuron\nfunctions with activation function $\\sigma={\\rm ReLU}^k$ by\n\\begin{equation}\n\\label{NNL}\n\\Sigma^k_{n_1,n_2,\\ldots, n_\\ell}=\\bigg\\{ f^{\\ell}(x) = \\theta^\\ell (x^{\\ell}), \n \\mbox{ with } W^i\\in \\mathbb R^{n_{i+1}\\times\n\tn_{i}}, b^i\\in\\mathbb R^{n_i}, i=0:\\ell, n_0=d, n_{\\ell+1}=1\\bigg\\}  \n\\end{equation}\nGenerally, we can define the $\\ell$-hidden layer neural network as:\n\\begin{equation}\n\\Sigma^k_{\\ell,n}:= \\bigcup_{n_1, n_2, \\cdots, n_{\\ell}\\ge 1}\\Sigma^k_{n_1,n_2,\\ldots, n_\\ell}.\n\\end{equation}\nFor $\\ell=2$, functions in $\\Sigma^k_{1,n}$ consist of piecewise polynomials of degree $k^2$ on a finite neuron grids whose boundaries are level sets of quadratic polynomials, see Fig \\ref{fig:3}.\n\\begin{figure}[!ht]\n\\begin{center} \n\\includegraphics[width=.3\\textwidth]{6DL/figures/2t20t20-1.jpg}   \n\\includegraphics[width=.3\\textwidth]{6DL/figures/2t40t40-1.jpg}\n\\includegraphics[width=.28\\textwidth]{6DL/figures/2t60t60-1.jpg}    \n\\caption{Hidden finite neuron grids with $\\ell=2$}\n\\label{fig:3}\n\\end{center}\n\\end{figure} \n\n\\subsection{Reproduction of polynomials and spectral accuracy}\nOne interesting property of the ReLU$^k$-DNN is that it reproduces\npolynomials of degree $k$.  \n\\begin{lemma}\nGiven $k\\ge 2$, $q\\ge 2$, there exist $\\ell\\ge 1$, $n_1, \\cdots, n_\\ell$ such that\n$$\n\\mathbb{P}_q\\subset \\Sigma^k_{\\ell,n},\n$$\nwhere $\\mathbb{P}_q$ is the set of all polynomials with degree not larger than $q$.\n\\end{lemma}\n\\begin{proof}\n\tHere we provide a sketch of the proof. We first notice that\n\t$$\n\tx^k = {\\rm ReLU}^k(x) + (-1)^k{\\rm ReLU}^k(-x) \\in \\Sigma^k_{2}, \\quad \\forall x \\in \\mathbb{R},\n\t$$\n\tfor any $k\\ge2$. In addition, there exists $a_i, b_i, c_i \\in \\mathbb{R}$ such that\n\t$$\n\tx^2 = \\sum_{i=1}^{k+1} c_i(a_i x + b_i)^k  \\in \\Sigma^k_{2(k+1)}, \\forall x \\in \\mathbb{R}.\n\t$$\n\tThus, we have\n\t$$\n\tx\\times y = \\frac{(x+y)^2 - (x-y)^2}{4} \\in \\Sigma^k_{2, 4(k+1)}, \\forall x,y \\in \\mathbb{R}.\n\t$$\n\tThis shows that\n\t\\begin{equation}\\label{key}\n\t\\begin{split}\n\tx_1^{\\alpha_1}x_2^{\\alpha_2}\\cdots x_d^{\\alpha_d} \n\t&= x_1 \\times x_1^{\\alpha_1-1}x_2^{\\alpha_2}\\cdots x_d^{\\alpha_d} \\\\\n\t&\\vdots \\\\\n\t&= x_1\\times \\left(x_1 \\times \\left(x_1 \\cdots \\times \\left(x_d\\times (x_d \\times x_d)\\right)\\cdots\\right)\\right).\n\t\\end{split}\n\t\\end{equation}\n\tThereby, any monomial $x_1^{\\alpha_1}x_2^{\\alpha_2}\\cdots x_d^{\\alpha_d}$ with degree $|\\alpha| = \\sum_{i=1}^d \\alpha_i$ can be represented by a deep ${\\rm ReLU}^k$ neural network.\n\\end{proof}\nFor a more detailed proof of the above result, we refer to \\cite{li2019better}. \n\n\\begin{theorem}\\label{thm:spectral}\nLet  ${\\rm ReLU}^k$ be the activation function, and $\\dnn_\\ell^k(N)$ be the DNN model with $\\ell$ hidden layers. \nThere exists some $\\ell$ such that\n\\begin{equation}\\label{eq:spectral}\n\\inf_{v_n\\in \\Sigma^k_{\\ell,n}}\\|u-v_n \\|_{H^m(\\Omega)} \\lesssim\n\\inf_{v_n\\in \\mathbb{P}_{k^\\ell}} \\|u-v_n\\|_{H^m(\\Omega)},\n\\end{equation} \n\\end{theorem}\nEstimate \\eqref{eq:spectral} indicates that the deep finite neuron function may provide spectral approximate accuracy.\n\n\\subsection{Reproduction of linear finite element functions and adaptivity}\nThe deep neural network with ReLU activation function have\nbeen much studied in the literature and most widely used in practice.\nOne interesting fact is that ReLU-DNN is simply piecewise linear\nfunctions.  More specifically, recall the results in Section \\ref{sec:reluFEM}.\n\n\\begin{lemma}\nAssume that ${\\cal T}_h$ is a simplicial finite element grid of $N$ elements, in which any \nunion of simplexes that share a same vertex is convex, any linear finite element function on this grid \ncan be written as a ReLU-DNN with at most $\\mathcal\n  O(d)$ hidden layers. The number of neurons is at most\n  $\\mathcal{O}(\\kappa^dN)$ for some constant $\\kappa\\ge 2$ depending\n  on the shape-regularity of $\\mathcal T_h$.  The number of non-zero\n  parameters is at most $\\mathcal{O} (d\\kappa^dN)$.\n\\end{lemma}\n\nThe above result indicate that the deep finite neuron functions can\nreproduce any linear finite element functions.  Given the adaptive\nfeature and capability of finite element methods, we see that the\nfinite neuron method can be at least as adaptive as finite element method.\n\n\\section{Elliptic boundary value problems of order $2m$}\\label{sec:model}\nLet $\\Omega\\subset \\mathbb{R}^d$ be a bounded domain with a\nsufficiently smooth boundary $\\partial\\Omega$.  For any integer $m\\ge\n1$, we consider the following model $2m$-th order partial differential\nequation with certain boundary conditions:\n%\\begin{equation}\\label{equ:2mpde}(-\\Delta)^m u +u = f \\qquad \\mbox{in }\\Omega.\\end{equation}\n\\begin{equation} \\label{2mPDE}\n\\left\\{\n  \\begin{array}{rccl}\\displaystyle\nLu &=& f &\\mbox{in }\\Omega, \\\\\nB^k(u) &= &0 & \\mbox{on }\\partial\\Omega \\quad(0\\le k\\le m-1),\n  \\end{array}\n\\right.\n\\end{equation}\nwhere $L$ is a partial differential operator as follows\n\\begin{equation}\\label{Lu}\nLu= \\sum_{|\\alpha|=m}(-1)^m\\partial^\\alpha (a_\\alpha(x)\\,\\partial^\\alpha\\,u) +a_0(x)u,\n \\end{equation} \nand ${\\boldsymbol{\\alpha}}$ denotes $n$-dimensional multi-index ${\\boldsymbol{\\alpha}}\n= (\\alpha_1, \\cdots, \\alpha_n)$ with\n$$\n|{\\boldsymbol{\\alpha}}| = \\sum_{i=1}^n \\alpha_i, \\quad\n\\partial^{\\boldsymbol{\\alpha}} = \\frac{\\partial^{|{\\boldsymbol{\\alpha}}|}}{\\partial x_1^{\\alpha_1}\n\\cdots \\partial x_n^{\\alpha_n}}.\n$$\nFor simplicity, we assume that $a_\\alpha$ are strictly positive and smooth functions on\n$\\Omega$ for  $|\\alpha|=m$ and $\\alpha=0$, namely, $\\exists \\alpha_0>0$, such that \n\\begin{equation}\\label{ass:1}\na_\\alpha(x), a_0(x)\\ge \\alpha_0,\\,\\, \\forall x\\in\\Omega,\\,\\,|\\alpha|=m.\n \\end{equation} \nGiven a nonnegative integer\n$k$ and a bounded domain $\\Omega\\subset \\mathbb{R}^d$, let \n$$\nH^k(\\Omega):=\\left\\{v\\in L^2(\\Omega), \\partial^\\alpha v\\in L^2(\\Omega), |\\alpha|\\le k\\right\\}\n$$\nbe standard Sobolev spaces with norm and seminorm given respectively by \n$$\n \\|v\\|_k:=\\left(\\sum_{|\\alpha|\\le k} \\|\\partial^\\alpha v\\|_0^2\\right)^{1/2}, \\quad  |v|_k:=\\left(\\sum_{|\\alpha|= k} \\|\\partial^\\alpha v\\|_0^2\\right)^{1/2}.\n$$\nFor $k=0$, $H^0(\\Omega)$ is the standard $L^2(\\Omega)$ space\nwith the inner product denoted by $(\\cdot, \\cdot)$.  Similarly, for\nany subset $K\\subset \\Omega$, $L^2(K)$ inner product is denoted by\n$(\\cdot, \\cdot)_{0,K}$.  We note that, by well-known property of Sobolev space,  the assumption \\eqref{ass:1} implies that\n\\begin{equation}\n  \\label{avv}\na(v,v)\\gtrsim \\|v\\|^2_{m,\\Omega}, \\forall v\\in H^m(\\Omega).\n\\end{equation}\n\nThe boundary value problem \\eqref{2mPDE} can be cast into an\nequivalent optimization or a variational problem as described below for some approximate subspace $V\\subset H^m(\\Omega)$.\n\\begin{description}\n\\item[Minimization Problem M:] Find $u\\in V$ such that \n\\begin{equation}\n\\label{minJv}\nJ(u)=\\min_{v\\in V} J(v),\n\\end{equation}\n\\noindent or\n\\item[Variational Problem V:]  Find  $u\\in V$ such that \n\\begin{equation}\\label{m-vari} \na(u,v) = \\langle f, v\\rangle \\quad \\forall v \\in V.\n\\end{equation}\n\\end{description}\nThe bilinear form $a(\\cdot,\\cdot)$ in \\eqref{m-vari}, the objective\nfunctional $J(\\cdot)$ in \\eqref{minJv} and the functional space $V$\ndepend on the type of boundary condition in \\eqref{2mPDE}. \n\nOne popular type of boundary conditions are Dirichlet boundary\ncondition when $B^k=B_D^k$ are given by the following Dirichlet type\ntrace operators\n\\begin{equation}\\label{BD}\nB_D^k(u):=\\left.\\frac{\\partial^k u}{\\partial\n    \\nu^k}\\right|_{\\partial\\Omega}\\quad (0\\le k\\le m-1),\n\\end{equation}\nwith $\\nu$ being the outward unit normal vector of $\\partial\\Omega$. The Dirichlet boundary\nvalue problem as follows:\n\\begin{equation} \\label{m-BD}\n\\left\\{\n  \\begin{array}{rccl}\\displaystyle\nLu &=& f &\\mbox{in }\\Omega, \\\\\nB_{D}^k(u) &= &0 & \\mbox{on }\\partial\\Omega \\quad(0\\le k\\le m-1).\n  \\end{array}\n\\right.\n\\end{equation}\n\n\nFor the aforementioned Dirichlet boundary condition, the elliptic\nboundary value problem \\eqref{2mPDE} is equivalent to \\eqref{minJv} or\n\\eqref{m-vari} with $V=H^m_0(\\Omega)$ and \n\\begin{equation}\n  \\label{auv}\na(u,v) := \\sum_{|\\alpha | = m}(a_\\alpha\\partial^{\\alpha}u, \\partial^{\\alpha}v)_{0,\\Omega} +(a_0u,v)\\quad \\forall\nu, v \\in V,\n\\end{equation}\nand \n\\begin{equation}\n  \\label{Jv}\nJ(v)=\\frac12 a(v,v) -\\int_{\\Omega} fv dx.  \n\\end{equation}\n\nWe next discuss about the pure Neumann boundary conditions \nfor general PDE operator \\eqref{Lu} when $m\\ge 2$.  We first begin our discussion\nwith the following simple result. \n\\begin{lemma} \\label{lem:BDBNdual}\nFor each $k=0,1,\\ldots,m-1$, there exists a bounded linear differential operator of order $2m-k-1$:\n\\begin{equation}\n    \\label{BN}\nB_N^k: H^{2m}(\\Omega)\\mapsto L^2(\\partial\\Omega)    \n  \\end{equation}\nsuch that the following identity holds\n$$\n(Lu,v)=a(u,v)-\\sum_{k=0}^{m-1}\\langle B_N^k(u),B_D^k(v)\\rangle _{0,\\partial\\Omega}.\n$$\nNamely\n\\begin{equation}\n\\label{BDBNdual}\n\\sum_{|\\alpha|=m}(-1)^m\\left(\\partial^\\alpha\n  (a_\\alpha\\,\\partial^\\alpha\\,u),\\,v\\right) _{0,\\Omega}\n=\\sum_{|{\\boldsymbol{\\alpha}}|=m}\\left(a_\\alpha\\partial^{\\boldsymbol{\\alpha}}\\,u, \\partial^{\\boldsymbol{\\alpha}} v\\right) _{0,\\Omega}\n-\\sum_{k=0}^{m-1}\\langle B_N^k(u),B_D^k(v)\\rangle _{0,\\partial\\Omega}\n\\end{equation}\nfor all $u\\in H^{2m}(\\Omega), v\\in  H^{m}(\\Omega)$. Furthermore, \n\\begin{equation}\\label{equ:regassum}\n\\sum_{k=0}^{m-1}\\|B_D^k(u)\\|_{L^2(\\partial\\Omega)}+\\sum_{k=0}^{m-1}\\|B_N^k(u)\\|_{L^2(\\partial\\Omega)}\\lesssim \\|u\\|_{2m, \\Omega}.\n\\end{equation}\n\\end{lemma}\nLemma \\ref{lem:BDBNdual} can be proved by induction with\nrespect to $m$.  We refer to \\cite{lions2012non} (Chapter 2) and \\cite{chen2020nonconforming} for a proof on a similar identity.\n\nIn general the explicit expression of $B_N^k$ can be quite\ncomplicated.  Let us get some idea by looking at some simple examples\nwith the following special operator:\n\\begin{equation}\n  \\label{Delta-m}\nLu=(-\\Delta)^m u+u,\n\\end{equation}\nand \n\\begin{equation}\na(u,v)= \\sum_{|\\alpha | = m}(a_\\alpha\\partial^{\\alpha}u, \\partial^{\\alpha}v)_{0,\\Omega} +(a_0u,v)\\quad \\forall\nu, v \\in V.\n\\end{equation}\n\n\\begin{itemize}\n\\item For $m=1$, it is easy to see that $B_N^0 u=\\frac{\\partial u}{\\partial\n    \\nu}|_{\\partial\\Omega}$.\n\\item For $m=2$ and $d=2$, see \\cite{chien1980variational}: \n$$\nB_N^0 u= \\frac{\\partial}{\\partial \\nu}\\left(\\Delta\n  u+\\frac{\\partial^2u}{\\partial\n    \\tau^2}\\right)-\\frac{\\partial}{\\partial\n  \\tau}\\left({\\kappa_\\tau}\\frac{\\partial u}{\\partial \\tau}\\right)|_{\\partial\\Omega}~~\\hbox{and}~~B_N^1 u=\\frac{\\partial^2u}{\\partial \\nu^2}|_{\\partial\\Omega},\n$$\n   with $\\tau$ being the\nanti-clockwise unit tangential vector, and $\\kappa_\\tau$ the curvature\nof $\\partial\\Omega$. \n\\end{itemize} \n\nWe are now in a position to state that the pure Neumann boundary value\nproblems for PDE operator \\eqref{Lu} as follows.\n\\begin{equation} \\label{m-BN}\n\\left\\{\n  \\begin{array}{rccl}\nLu &=& f &\\mbox{in }\\Omega, \\\\\nB_{N}^k(u) &= &0 & \\mbox{on }\\partial\\Omega \\quad(0\\le k\\le m-1).\n  \\end{array}\n\\right.\n\\end{equation}\nCombining the trace theorem for $H^m(\\Omega)$, see \\cite{adams2003sobolev}, and Lemma\n\\eqref{lem:BDBNdual},  it is easy to see that \n\\eqref{minJv} is equivalent to \n\\eqref{m-BN} \nwith $V=H^m(\\Omega)$. \n\nFor a given parameter $\\delta>0$, we next consider the following\nproblem with mixed boundary condition: \n\\begin{equation} \\label{equ:delta}\n\\left\\{\n\\begin{aligned}\nLu_{\\delta} &= f \\qquad \\mbox{in }\\Omega, \\\\\nB_D^k(u_{\\delta})+\\delta B_N^k(u_\\delta)  &= 0, \\ \\ 0\\le k\\le m-1.\n\\end{aligned}\n\\right.\n\\end{equation}\nIt is easy to see that \\eqref{equ:delta} is equivalent to the following problem: Find $u_\\delta\\in H^m(\\Omega)$, such that \n\\begin{equation}\\label{equ:varpdelta}\nJ_{\\delta}(u_{\\delta})=\\min_{v\\in H^m(\\Omega)} J_{\\delta}(v).\n\\end{equation}\nwhere\n\\begin{equation}\\label{J-delta}\nJ_\\delta(v)={1\\over 2}a_\\delta(v,v)-(f,v)\n\\end{equation}\nand\n\\begin{equation}\\label{a-delta}\na_\\delta(u,v)=a(u,v)+\\delta^{-1}\\sum_{k=0}^{m-1}\\langle B_D^k(u), B_D^k(v)\\rangle_{0,\\partial\\Omega}.\n\\end{equation}\nIn summary, we have \n\\begin{lemma}\nThe following equivalences hold:\n\\begin{enumerate}\n\\item $u$ solves for \\eqref{m-BD} or \\eqref{m-BN} if and only if $u$ solves\n\\begin{equation}\\label{m-mini}\nJ(u)=\\min_{v\\in V} J(v)\n\\end{equation}\n with $V=H^m_0(\\Omega)$ or  $V=H^m(\\Omega)$,\n\\item $u_\\delta$ solves for \\eqref{equ:delta}  if and only if $u_\\delta$ solves \n$$\n\\displaystyle J_\\delta(u_\\delta)=\\min_{v\\in V} J_\\delta(v)\n$$ \nwith $V=H^m(\\Omega)$. \n\\end{enumerate}\n\\end{lemma}\n\n\n\\begin{lemma} \\label{lem:JvJu}\nAssume that $u\\in V$ be solution of \\eqref{m-BD} or \\eqref{m-BN} and $u_\\delta\\in V$ be the solution of \\eqref{equ:varpdelta}, then\nthe following identities hold:\n\\begin{equation}\\label{vuidentity1}\n\\|v-u\\|_{a}^2=J(v)-J(u)\\quad \\forall v\\in V,\n\\end{equation}\nand\n\\begin{equation}\\label{vuidentity2}\n\\|v-u_\\delta\\|_{a,\\delta}^2=J_{\\delta}(v)-J_{\\delta}(u_{\\delta})\\quad \\forall v\\in V. \n\\end{equation}\nHere\n\\begin{equation}\n  \\label{a-norm}\n\\|v\\|_{a}^2=a(v,v),\\quad \\|v\\|_{a,\\delta}^2=a_\\delta(v,v).\n\\end{equation}\n\\end{lemma}\n\\begin{proof}\nLet $u$ be the solution of \\eqref{minJv}. Given $v\\in V$, consider the quadratic function of $t$:\n$$\ng(t)=J(u+t(v-u)).\n$$\nIt is easy to see that \n$$\n0=\\arg\\min_{t}g(t), \\quad g'(0)=0,\n$$\nand\n$$\nJ(v)-J(u)=g(1)-g(0)=g'(0)+{1\\over2}g''(0)=\\|v-u\\|_{a}^2.\n$$\nThis completes the proof of \\eqref{vuidentity1}. The proof of \\eqref{vuidentity2} is similar. \n\\end{proof} \n\n\\begin{lemma}\\label{Nitchtrick}\n  Let $u$ be the solution of \\eqref{m-BD} and $u_\\delta$ be the solution of \\eqref{equ:delta}. Then \n  \\begin{align}\\label{diff:uudelta}\n\\|u-u_\\delta\\|_{a,\\delta} \\lesssim\\sqrt{\\delta}  \\|u\\|_{2m,\\Omega}.\n\\end{align}\n\\end{lemma}\n\\begin{proof}\nLet $w=u-u_{\\delta}$ and we have \n\n\\begin{equation} \\label{equ:diff}\n\\left\\{\n\\begin{aligned}\nLw &= 0 \\qquad \\mbox{in }\\Omega, \\\\\nB_D^k(w)+\\delta B_N^k(w)  &= \\delta B_N^k(u),\\ \\ 0\\le k\\le m-1.\n\\end{aligned}\n\\right.\n\\end{equation}\nBy Lemma \\ref{lem:BDBNdual}, and \\eqref{equ:diff},  we have \n\\begin{align}\n0&=(Lw, w)\n\\\\\n&=\\sum_{|\\alpha|=m}(a_\\alpha\\partial^\\alpha w, \\partial^\\alpha w)-\\sum_{k=0}^{m-1}\\int_{\\partial \\Omega}B_N^k(w)B_D^k(w) ds+(a_0w, w)\n\\\\\n&=\\sum_{|\\alpha|=m}(a_\\alpha\\partial^\\alpha w, \\partial^\\alpha w)+ \\sum_{k=0}^{m-1} \\int_{\\partial \\Omega}(\\delta^{-1}B_D^k(w)-  B_N^k(u) )B_D^k(w) ds+(a_0w, w),\n\\end{align}\nimplying\n\\begin{align}\n&a(w, w)+ \\delta^{-1}\\sum_{k=0}^{m-1}\\int_{\\partial \\Omega}B_D^k(w)^2 ds\n=\n\\sum_{k=0}^{m-1}\\int_{\\partial \\Omega}B_N^k(u)B_D^k(w) ds.\n\\end{align}\nBy Cauchy inequality, we have \n\\begin{align}\na(w,w)+\\delta^{-1}\\sum_{k=0}^{m-1}\\|B_D^k(w)\\|^2_{L^2(\\partial \\Omega)}\n\\le& \\sum_{k=0}^{m-1}\\|B_N^k(u) \\|_{L^2(\\partial \\Omega)}\\|B_D^k(w)\\|_{L^2(\\partial \\Omega)}\n\\\\\n\\le& 2\\delta  \\sum_{k=0}^{m-1}\\|B_N^k(u) \\|^2_{L^2(\\partial \\Omega)}+\\frac12 \\delta^{-1} \\sum_{k=0}^{m-1} \\|B_D^k(w)\\|^2_{L^2(\\partial \\Omega)},\n\\end{align}\nwhich implies\n\\begin{align}\na(w,w)+\\frac12 \\delta^{-1}\\sum_{k=0}^{m-1}\\|B_D^k(w)\\|^2_{L^2(\\partial \\Omega)}\\le 2\\delta  \\sum_{k=0}^{m-1}\\|B_N^k(u) \\|^2_{L^2(\\partial \\Omega)}.\n\\end{align}\nBy the definition of $\\|\\cdot\\|_{a,\\delta}$ and noting that $w=u-u_\\delta$, we have \n\\begin{align}\\label{diff:uudelta1}\n\\|u-u_\\delta\\|_{a,\\delta}^2\\le 4\\delta  \\sum_{k=0}^{m-1}\\|B_N^k(u) \\|^2_{L^2(\\partial \\Omega)}.\n\\end{align}\nCombing this with \\eqref{equ:regassum}, then completes the proof.\n\\end{proof}\n\n\\begin{lemma}\\label{Regularity}\nFor any $s\\ge -m$ and  $f\\in H^s(\\Omega)$, the solution $u$\n  of \\eqref{m-BD} or \\eqref{m-BN} satisfies $u\\in H^{2m+s}(\\Omega)$ and \n  \\begin{equation}\n    \\label{regularity}\n\\|u\\|_{2m+s,\\Omega}\\lesssim     \\|f\\|_{s,\\Omega}.\n  \\end{equation}\n\\end{lemma}\nWe refer to \\cite{lions2012non} (Chapter 2, Theorem 5.1 therein) for a detailed proof. \n\nFollowing from \\eqref{regularity} and \\eqref{embend}, we have \n\\begin{lemma} For any $s\\ge -m$,  $\\epsilon >0$, \n and  $f\\in H^s(\\Omega)$, the solution $u$\n  of \\eqref{m-BD} or \\eqref{m-BN} satisfies\n  \\begin{equation}\n  \\label{Barron-regularity}\n\\|u\\|_{B^{m+1}(\\Omega)}\\le   \\|f\\|_{-m+\\frac{d}{2}+1+\\epsilon,\\Omega}.\n\\end{equation}\n\\end{lemma}\n\n\n\\section{The finite neuron method and error estimates}\\label{sec:FNM}\nLet $V_n\\subset V$ be a subset of $V$ defined by \\eqref{VkN} which may not be a linear\nsubspace. Consider the the discrete problem of \\eqref{m-mini}:\n\\begin{equation}\n  \\label{m-mini-VN}\n\\mbox{Find $u_n\\in V_n$ such that } J(u_n)=\\min_{v_n\\in V_n}J(v_n).\n\\end{equation}\nIt is easy to see that the solution to \\eqref{m-mini-VN} always exists (for deep\nneural network functions as defined below), but may not be unique.\n\n\\begin{theorem}\\label{thm:best} Let $u\\in V$ and $u_n\\in V_n$ be solutions to\n  \\eqref{m-BN} and \\eqref{m-mini-VN} respectively.   Then\n  \\begin{equation}\n    \\label{best-approx}\n\\|u-u_n\\|_a=\\inf_{v_n\\in V_n}\\|u-v_n\\|_a.\n  \\end{equation}\n\\end{theorem}\n\\begin{proof}\nBy  Lemma~\\ref{lem:JvJu}, we have\n$$\n\\|u_n-u\\|_a^2=J(u_n)-J(u)\\le J(v_n)-J(u)=\\|v_n-u\\|_a^2,\\quad\\forall v\\in V_n.\n$$\nThe proof is completed.\n\\end{proof}\nWe obtain the following result.\n\\begin{theorem}\nLet $u\\in V$ and $u_n\\in V_n$ be solutions to\n\\eqref{m-BN} and \\eqref{m-mini-VN} respectively.  Then for arbitrary $\\epsilon>0$, we have\n\\begin{equation}\\label{error:N}\n\\|u-u_n\\|_a \\lesssim \n(\\|f\\|_{L^2(\\Omega)}+\\|f\\|_{\\mathcal{K}_1(\\mathbb{D})})\n\\begin{cases}\nn^{-{1\\over 2}-{2(k-m)+1\\over 2d}}&m< k,\n\\\\\nn^{m-k-1}& m\\ge k.\n\\end{cases} \n\\end{equation}\n\\end{theorem}\nBy \\eqref{best-approx},  and the embedding of spectral Barron space  into Sobolev space, namely Lemma \\ref{smoothness-lemma}, the regularity result \\eqref{regularity}, we get the proof. \n\nNext we consider the discrete problem of \\eqref{equ:varpdelta}:\n\\begin{equation}\n\\label{min:uN}\n\\mbox{Find $u_n\\in V_n$ such that } J_\\delta(u_n)=\\min_{v_n\\in V_n}J_\\delta(v_n).\n\\end{equation}\n\n\\begin{lemma}\nFor any given number $\\delta$, let $u_\\delta$ be the solution of \\eqref{equ:delta} and\n  $u_n$ be the solution of \\eqref{min:uN}, respectively. We have\n  \\begin{equation}\n  \\label{eq:1}\n\\|u_n-u_\\delta\\|_{a,\\delta} \\lesssim (1+ \\delta^{-\\frac12})  \\inf_{v_n\\in\n  V_n} \\|v_n-u_\\delta\\|_{m,\\Omega}. \n  \\end{equation}\n\\end{lemma}\n\\begin{proof}\nFirst of all, by Lemma~\\ref{lem:JvJu} and the variational property, it holds that\n\\begin{align}\\label{eq:min}\n\\|u_n-u_\\delta\\|_{a,\\delta}^2=J_{\\delta}(u_n)-J_{\\delta}(u_{\\delta})\\le J_{\\delta}(v_n)-J_{\\delta}(u_{\\delta})\n=\\|v_n-u_\\delta\\|_{a,\\delta}^2, \\quad \\forall\\,v_n\\in V_n.\n\\end{align}\nFurther, for any $v_n\\in V_n$, by the definition of $\\|\\cdot\\|_{a,\\delta}$ and trace inequality, we have \n$$\n\\|v_n-u_\\delta\\|_{a,\\delta}\\lesssim  \\|v_n-u_\\delta\\|_{m,\\Omega}+\\delta^{-\\frac12} \\|v_n-u_\\delta\\|_{0,\\partial\\Omega}\\lesssim (1+\\delta^{-\\frac12})\\|v_n-u_\\delta\\|_{m,\\Omega}.\n$$\nThis completes the proof. \n\\end{proof}\n\n\\begin{theorem}\\label{thm:bestD}\n  Let $u$ be the solution of \\eqref{m-BD} and\n  $u_n$ be the solution of \\eqref{min:uN}, respectively. We have\n  \\begin{equation}\n  \\label{eq:13}\n\\|u-u_n\\|_{a,\\delta} \\lesssim (1+ \\delta^{-\\frac12})  \\inf_{v_n\\in\n  V_n} \\|v_n-u\\|_{m,\\Omega}\n+\\sqrt{\\delta}  \\|f\\|_{L^2(\\Omega)}. \n  \\end{equation}\n\\end{theorem}\n\\begin{proof}\nFirst, by triangle inequality and \\eqref{eq:min}, for any $v_n\\in V_n$, we have\n\\begin{align}\n\\|u_n-u\\|_{a,\\delta}&\\le  \\|u_n-u_\\delta\\|_{a,\\delta}+\\|u_\\delta-u\\|_{a,\\delta}\\\\\n&\\le \\|v_n-u_\\delta\\|_{a,\\delta}+\\|u_\\delta-u\\|_{a,\\delta}\\\\\n&\\le  \\|v_n-u\\|_{a,\\delta}+2\\|u_\\delta-u\\|_{a,\\delta} .\n\\end{align}\nThen by the definition of $\\|\\cdot\\|_{a,\\delta}$, trace inequality and \\eqref{diff:uudelta}, for any $v_n\\in V_n$, we have \n \\begin{equation}\n\\|u_n-u\\|_{a,\\delta} \\lesssim (1+ \\delta^{-\\frac12}) \\|v_n-u\\|_{m,\\Omega}\n+\\sqrt{\\delta}  \\|f\\|_{L^2(\\Omega)}. \n\\end{equation}\nThis completes the proof. \n\\end{proof}\n\n\\begin{theorem}\n Let $u$ be the solution of \\eqref{m-BD} and\n  $u_n$ be the solution of \\eqref{min:uN} with $\\delta\\sim n^{-1/2 -1/{d}}$, respectively. Then\n\\begin{equation}\n\\label{error:D}\n%\\|u-u_n\\|_{m,\\Omega}\\lesssim N^{-{1\\over 4}-{1\\over    2d}}(\\|f\\|_{-m+1+\\frac{d}{2}+\\epsilon}+\\|f\\|_{L^2(\\Omega)}).\n\\|u-u_n\\|_a \\lesssim \n(\\|f\\|_{L^2(\\Omega)}+\\|f\\|_{-k+\\frac{d}{2}+1+\\epsilon})\n\\begin{cases}\nn^{-{1\\over 4}-{1\\over {2d}}}&m< k,\n\\\\\nn^{-{1\\over 4}}& m=k.\n\\end{cases} \n\\end{equation}  \n\\end{theorem}\n \\begin{proof} Let us only consider the case that $k>m$. \nBy Theorem \\ref{lem:stratifiedapprox},\n$$\n\\inf_{v_n\\in V_n}\\|u-v_n\\|_{m,\\Omega}\\lesssim n^{-\\frac12 -{1\\over d}}\\|u\\|_{ B^{m+1}(\\Omega)}.\n$$\nThus, by \\eqref{eq:1}\n\\begin{multline}\n\\label{eq:11}\n\\|u-u_n\\|_{m,\\Omega}\\lesssim \\|u_n-u\\|_{a,\\delta} \\lesssim \\delta^{-\\frac12 } n^{-\\frac12 -{1\\over d}}\\|u\\|_{B^{m+1, q}(\\Omega)}+\\delta^{\\frac12}\\|f\\|_{L^2(\\Omega)}\n\\\\\n\\le \n(\\delta^{-\\frac12}  n^{-\\frac12 -{1\\over d}}+\\delta^{\\frac12})(\\|u\\|_{ B^{m+1}(\\Omega)}+\\|f\\|_{L^2(\\Omega)}),\\ \\ \\forall\\,\\delta>0.\n  \\end{multline}\nSet $\\delta\\sim n^{-1/2 -1/{d}}$, and it follows that\n\\begin{equation}\n\\|u-u_n\\|_{m,\\Omega}\\lesssim n^{-{1\\over 4}-{1\\over 2d}}(\\|u\\|_{B^{m+1}(\\Omega)}+\\|f\\|_{L^2(\\Omega)}).\n\\end{equation}\nNow by the embedding of spectral Barron space to Sobolev space, namely\nLemma \\ref{smoothness-lemma}, the regularity result\n\\eqref{regularity}, the proof is completed.\n \\end{proof}\n\n \\begin{remark}\nAlthough the analysis in this section is mainly for activation\nfunction ReLU$^k$, similar results are valid for other\nactivations.  For example, Theorem \\ref{thm:best} and Theorem\n\\ref{thm:bestD} naturally hold for any activation functions. \n \\end{remark}\n\n\\begin{remark}\nWe also note that analysis in this section naturally\ngeneralize to problems other than \\eqref{2mPDE}.  For example, Theorem\n\\ref{thm:best} can be generalized to the case when $J(\\cdot)$ is\nreplaced by a general strictly convex functional.\n\\end{remark}\n%\n\n\\begin{remark}\n We note that \\eqref{min:uN} was studied in \\cite{weinan2018deep} for\n $m=1$ and $k=3$.  Convergence analysis for \\eqref{m-mini-VN} and\n \\eqref{min:uN} seems to be new in this paper.  For other convergence\n analysis of DNN for numerical PDE, we refer to\n \\cite{shin2020convergence} and\n \\cite{mishra2020enhancing,mishra2020estimates} for convergence\n analysis of PINN (Physics Informed Neural Network).\n\\end{remark}   \n\n\\input{6DL/quadrature}\n\n\\section{Summary and discussions} \\label{sec:Summary}\n\nIn this chapter, we consider a very special class of neural network\nfunction based on ReLU$^k$ as activation function.  This function\nclass consists of piecewise polynomials which closely resemble finite\nelement functions.  By considering elliptic boundary value problems of $2m$-th\norder in any dimensions, it is still unknown how to construct\n$H^m$-conforming finite element space in general in the classic finite\nelement setting.  In contrast, it is rather straightforward to\nconstruct $H^m$-conforming piecewise polynomials using neural\nnetworks, known as the finite neuron method,  and we further proved\nthat the finite neuron method provides good approximation\nproperties. \n\nIt is still a subject of debate and of further investigation whether\nit is practically efficient to use artificial neural network for\nnumerical solution of partial differential equations.  One major\nchallenge for this type of method is that the resulting optimization\nproblem is hard to solve, as we shall discuss below.\n\n\\subsection{Solution of the non-convex optimization problem}\n\\eqref{m-mini-VN} or \\eqref{min:uN} is a highly nonlinear and\nnon-convex optimization problem with respect to parameters defining\nthe functions in $V_n$, see \\eqref{VkN}. How to solve this type of\noptimization problem efficiently is a topic of intensive research in\ndeep learning. For example,\nstochastic gradient method is used in \\cite{weinan2018deep} to solve\n\\eqref{min:uN} for $m=1$ and $k=3$.  Multi-scale deep neural network\n(MscaleDNN) \\cite{liu2020multi} and phase shift DNN (PhaseDNN)\n\\cite{cai2019phase} are developed to convert the high frequency\nsolution to a low frequency one before training. Randomized Newton's\nmethod is developed to train the neural network from a nonlinear\ncomputation point of view \\cite{chen2019randomized}.  More refined\nalgorithms still need to be developed to solve \\eqref{m-mini-VN} or\n\\eqref{min:uN} with high accuracy so that the convergence order,\n\\eqref{error:N} or \\eqref{error:D}, of the finite neuron\nmethod can not be achieved.\n\nIn order to approximate solutions to \\eqref{model-problem}, we propose to solve the following optimization problem\n\\begin{equation}\\label{discrete-formulation}\n u_{n,M,N} = \\arg\\min_{v\\in B_M(\\mathbb{D})} J_N(v),\n\\end{equation}\nwhere\n\\begin{equation}\n B_M(\\mathbb{D}) = \\{u\\in \\mathcal{K}_1(\\mathbb{D}):~\\|u\\|_{\\mathcal{K}_1(\\mathbb{D})} \\leq M\\}.\n\\end{equation}\nSome result that says under which circumstances to have an estimate of $\\|u\\|_{\\mathcal{K}_{1}}$ can be found in \\cite{xu2020finite} (see Lemma 5.6) and \\cite{lu2021priori} (See Theorem 2.5 and Theorem 2.6).\nWe note that the minimizer above is achieved as long as the $\\sup_{d\\in \\mathbb{D}} \\|d\\|_{H^m(\\Omega)} < \\infty$. For in this case the optimization is over a bounded set and $J_N$ only depends upon the values and derivatives at finitely many points. Thus the optimization is effectively over a bounded set in a finite dimensional space, which is compact by the Heine-Borel Theorem.\n\nFor the case of mixed boundary conditions \\eqref{equ:varpdelta} we sample $N$ points $x_1,...,x_N\\in \\Omega$ uniformly at random and also sample $N_0$ points $y_1,...,y_{N_0}\\in \\partial \\Omega$ uniformly at random from the boundary. We then approximate the integrals in \\eqref{equ:varpdelta} by\n\\begin{equation}\\label{discrete-energy-dirichlet}\n\\begin{aligned}\n J_{N,\\delta}(u) &= \\frac{1}{2N}\\sum_{i=1}^N\\sum_{|\\alpha| = m} a_\\alpha(x_i)(\\partial^\\alpha u(x_i))^2 + \\frac{1}{2N}\\sum_{i=1}^Na_0(x_i)u(x_i)^2 - \\frac{1}{N}\\sum_{i=1}^Nf(x_i)u(x_i) \\\\\n &+ \\frac{\\delta^{-1}}{N_0}\\sum_{i=1}^{N_0} \\sum_{k=0}^{m-1} \\left|\\frac{\\partial^k}{\\partial \\nu^k}u(y_i)\\right|^2.\n \\end{aligned}\n\\end{equation}\nForming the loss function \\eqref{discrete-energy-dirichlet} requires being able to calculate normal derivatives of functions $u$ and to sample points uniformly from the boundary. This is possible for many important domains, such as the sphere or cube. We note that if the above sampling is not possible, then it suffices to be able to sample from a non-uniform distribution on $\\Omega$ and $\\partial \\Omega$ with mass function $\\rho$ if we weight each of the sums above by $\\rho^{-1}$. We then propose to solve the following optimization problem to approximate solutions to \\eqref{equ:varpdelta}\n\\begin{equation}\\label{discrete-formulation-dirichlet}\n u_{n,M,N,\\delta} = \\arg\\min_{v\\in B_M(\\mathbb{D})} J_{N,\\delta}(v).\n\\end{equation}\n \n The optimization problems \\eqref{discrete-formulation} and \\eqref{discrete-formulation-dirichlet} can be efficiently approximately solved using greedy algorithms \\cite{zhang2003sequential,lee1996efficient,jones1992simple,li1999mixture,barron2008approximation}. Specifically, the algorithm we use is the following\n\\begin{equation}\\label{greedy-algorithm}\n u_0 = 0,~g_k = \\arg\\max_{g\\in \\mathbb{D}} \\langle \\nabla J_N(u_{k-1}), g\\rangle,~u_k = (1-s_k)u_{k-1} - Ms_kg_k,\n\\end{equation}\nwhere $s_k = \\min\\left(1,\\frac{2}{k}\\right)$. Importantly, we have that $u_k\\in \\Sigma_{k,M}(\\mathbb{D})$, so that this algorithm produces neural networks with finite width. Note that this algorithm requires the computation of an $\\arg\\min$ over the dictionary $\\mathbb{D}$, which may be a complicated step for certain dictionaries. We assume in what follows that this step can be efficiently calculated, which we argue is a reasonable assumption in practice for a wide range of dictionaries. For instance, when using the dictionary $\\mathbb{P}_k^d$ corresponding to ReLU$^k$, this corresponds to an optimization over a compact $d$-dimensional set. Solving this problem for shallow neural network training was considered in \\cite{lee1996efficient} and numerical experiments demonstrating the application to PDEs can be found in \\cite{hao2021efficient}.\n\nThe algorithm \\eqref{greedy-algorithm} was first introduced in \\cite{jones1992simple} for the quadratic least-squares objective. It was analyzed in the context of neural networks for least squares fitting in \\cite{lee1996efficient} and for density estimation \\cite{li1999mixture}, and for general activation functions in \\cite{zhang2003sequential}. Further extensions, such as the orthogonal greedy algorithm, relaxed greedy algorithm, and pure greedy algorithm, which however do not ensure that their iterates have bounded $\\mathcal{K}_1(\\mathbb{D})$-norm, are studied in \\cite{devore1996some,barron2008approximation,temlyakov2008greedy,livshits2009lower,livshitz2003two,sil2004rate}. In what follows, we provide a convergence analysis which is applicable to our problem of interest.\n\nMore generally, we assume in our convergence analysis that the argmax in \\eqref{greedy-algorithm} is not solved exactly, but rather is approximated in the following sense\n\\begin{equation}\\label{argmax-approximation}\n \\langle \\nabla J_N(u_{k-1}), g_k\\rangle \\geq \\frac{1}{R}\\max_{g\\in \\mathbb{D}} \\langle \\nabla J_N(u_{k-1}), g\\rangle\n \\end{equation}\nfor some $R > 1$. This is a more tractable problem for most dictionaries. However, we only consider the case of $R > 1$ in the convergence analysis given in this section. In later sections, we assume for simplicity that $R = 1$ in the analysis of the quadrature error.\n\nFor our analysis we will need that the objectives $J_N$ and $J_{N,\\delta}$ are convex and $K$-smooth with respect to a Hilbert space norm $H$. Recall that a function $L:H\\rightarrow \\mathbb{R}$ is $K$-smooth if \n\\begin{equation}\n J_N(g) \\leq J_N(f) + \\langle\\nabla J_N(f), g-f\\rangle + \\frac{K}{2}\\|g-f\\|_H^2.\n\\end{equation}\nIn the following analysis, we will let $H$ be the discrete $H^k$ norm corresponding to the sample points $x_1,...,x_N$ and $y_1,...,y_{N_0}$, i.e. $H$ is given by\n\\begin{equation}\\label{discrete-hm-inner-product}\n \\langle u,v\\rangle_H = \\frac{1}{N}\\sum_{i=1}^N\\sum_{|\\alpha| = m}(\\partial^\\alpha u(x_i))(\\partial^\\alpha v(x_i)) + \\frac{1}{N}\\sum_{i=1}^N u(x_i)v(x_i) + \\frac{1}{N_0}\\sum_{i=1}^{N_0} \\sum_{k=0}^{m-1} \\left|\\frac{\\partial^k}{\\partial \\nu^k}u(y_i)\\right|^2.\n\\end{equation}\nWith respect to the norm $H$ above, the smoothness parameter $K$ in the pure Neumann case is the maximum of the coefficient functions $a_\\alpha$ and $a_0$. In the case of mixed boundary conditions \\eqref{discrete-energy-dirichlet} the smoothness parameter is bounded by $K \\leq \\max(\\|a_{\\alpha}\\|_{L^\\infty}, \\|a_{0}\\|_{L^\\infty}) + \\delta^{-1}$. \n\nWe have the following convergence result for the algorithm \\eqref{greedy-algorithm}.\n\\begin{theorem}\\label{relaxed-boosting-theorem}\n Suppose that the dictionary $\\mathbb{D}$ is symmetric and satisfies $\\sup_{d\\in \\mathbb{D}}\\|d\\|_H \\leq C < \\infty$. Let the iterates $u_n$ be given by the relaxed greedy algorithm \\eqref{greedy-algorithm} with $s_k = \\max\\left(1,\\frac{2}{k}\\right)$, where the loss function $L$ is convex and $K$-smooth (on the Hilbert space $H$). Suppose that the $\\arg\\max$ in \\eqref{greedy-algorithm} is approximated up to a factor $R$ as in \\eqref{argmax-approximation}. Then we have $\\|u_n\\|_{\\mathcal{K}_1(\\mathbb{D})} \\leq M$ and \n \\begin{equation}\n  L(u_n) - \\inf_{\\|v\\|_{\\mathcal{K}_1(\\mathbb{D})} \\leq R^{-1}M} L(v) \\leq \\frac{32(CM)^2K}{n}.\n \\end{equation}\n\n\\end{theorem}\nIn particular, if $M \\geq \\|u\\|_{\\mathcal{K}_1(\\mathbb{D})}$ where $u = \\arg\\min_v L(v)$ is the global minimizer, then the objective converges to the optimal value in the above theorem. \n\nWe note that applying this theorem to the squared error loss $L(f) = \\frac{1}{2}\\|f - f^*\\|_H^2$ implies an approximation rate of\n\\begin{equation}\\label{approximation-rate}\n \\inf_{f_n\\in \\Sigma_{n,M}} \\|f_n - f^*\\|_H \\lesssim Mn^{-\\frac{1}{2}},\n\\end{equation}\nfor any $f^*\\in B_M(\\mathbb{D})$. This is essentially the method of proof used in \\cite{jones1992simple}. In fact, for special dictionaries $\\mathbb{D}$, the above rate can be improved. For instance, when $\\mathbb{D} = \\mathbb{P}_k^d$ the optimal rate was determined in \\cite{siegel2021optimal} to be $n^{-1-\\frac{2(k-m) + 1}{d}}$. Further, for more general activation functions it was shown that these rates can also be moderately improved in \\cite{siegel2020approximation}.\n\n\\begin{proof}\n Since $u_0 = 0$ and $u_k$ is a convex combination of $u_{k-1}$ and $-Mg_k$, we see by induction that $\\|u_k\\|_{\\mathcal{K}_1(\\mathbb{D})} \\leq M$.\n \n The $K$-smoothness of the objective $L$ implies that\n \\begin{equation}\n  L(u_k) \\leq L(u_{k-1}) + \\langle \\nabla L(u_{k-1}), u_k - u_{k-1}\\rangle + \\frac{K}{2}\\|u_k - u_{k-1}\\|_H^2.\n \\end{equation}\n Using the iteration \\eqref{greedy-algorithm}, we see that $u_k - u_{k-1} = -s_ku_{k-1}-Ms_kg_k$. Plugging this into the above equation, we get\n \\begin{equation}\n  L(u_k) \\leq L(u_{k-1}) - s_k\\langle \\nabla L(u_{k-1}), u_{k-1} + Mg_k\\rangle + \\frac{Ks_k^2}{2}\\|u_{k-1} + Mg_k\\|_H^2.\n \\end{equation}\n Since the dictionary elements $g_k$ satisfy $\\|g_k\\|_H \\leq C$ and $\\|u_{k-1}\\|_{\\mathcal{K}_1(\\mathbb{D})} \\leq M$, we see that $\\|u_{k-1}\\|_H \\leq CM$ as well. Plugging this into the previous equation implies the bound\n \\begin{equation}\\label{eq-479}\n  L(u_k) \\leq L(u_{k-1}) - s_k\\langle \\nabla L(u_{k-1}), u_{k-1} + Mg_k\\rangle + 2(CM)^2Ks_k^2.\n \\end{equation}\n Now let $z$ with $\\|z\\|_{\\mathcal{K}_1(\\mathbb{D})} \\leq R^{-1}M$ be arbitrary. Then also $\\|-z\\|_{\\mathcal{K}_1(\\mathbb{D})} \\leq R^{-1}M$ and the $\\arg\\max$ characterization of $g_k$ \\eqref{argmax-approximation}  implies that\n \\begin{equation}\n  \\langle \\nabla L(u_{k-1}), -z\\rangle \\leq \\langle \\nabla L(u_{k-1}), Mg_k\\rangle.\n \\end{equation}\n Using this in equation \\eqref{eq-479} gives\n \\begin{equation}\n  L(u_k) \\leq L(u_{k-1}) - s_n\\langle \\nabla L(u_{k-1}), u_{k-1} - z\\rangle + 2(CM)^2Ks_k^2.\n \\end{equation}\n The convexity of $L$ means that $L(u_{k-1}) - L(z) \\leq \\langle \\nabla L(u_{k-1}), u_{k-1} - z\\rangle$. Using this and subtracting $L(z)$ from both sides of the above equation gives\n \\begin{equation}\n  L(u_k) - L(z) \\leq (1 - s_k)(L(u_{k-1}) - L(z)) + 2(CM)^2Ks_k^2.\n \\end{equation}\n Expanding the above recursion (using that $s_k\\leq 1$), we get that\n \\begin{equation}\n  L(u_n) - L(z) \\leq \\left(\\prod_{k=1}^n(1-s_k)\\right)(L(u_0) - L(z)) + 2(CM)^2K\\sum_{i=1}^n\\left(\\prod_{k=i+1}^n(1-s_k)\\right)s_i^2.\n \\end{equation}\n Using the choice $s_k = \\max\\left(1,\\frac{2}{k}\\right)$, for which $s_1 = 1$, we get\n \\begin{equation}\\label{eq-268}\n  L(u_n) - L(z) \\leq 2(CM)^2K\\sum_{i=1}^n\\left(\\prod_{k=i+1}^n(1-s_k)\\right)s_i^2.\n \\end{equation}\n Finally, we bound the product $\\displaystyle\\prod_{k=i+1}^n(1-s_k)$ using that $\\log(1+x) \\leq x$ as\n \\begin{equation}\n  \\log\\left(\\prod_{k=i+1}^n(1-s_k)\\right) \\leq -\\sum_{k=i+1}^ns_k = -\\sum_{k=i+1}^n\\frac{2}{k} \\leq -\\int_{i+1}^{n+1}\\frac{2}{x}dx \\leq 2(\\log(i+1) - \\log(n+1)),\n \\end{equation}\n for $i \\geq 1$. Thus, $\\prod_{k=i+1}^n(1-s_k) \\leq \\frac{(i+1)^2}{(n+1)^2}$. Using this in equation \\eqref{eq-268}, we get\n \\begin{equation}\n  L(u_n) - L(z) \\leq 2(CM)^2K\\sum_{i=1}^n \\frac{(i+1)^2}{(n+1)^2}s_i^2 \\leq 8(CM)^2K\\frac{1}{(n+1)^2}\\sum_{i=1}^n \\frac{(i+1)^2}{i^2}.\n \\end{equation}\n Crudely bounding $\\frac{(i+1)^2}{i^2} \\leq 4$ for $i \\geq 1$, we get\n\\begin{equation}\n  L(u_n) - L(z) \\leq 32(CM)^2K\\frac{n}{(n+1)^2} \\leq \\frac{32M^2K}{n},\n \\end{equation}\n Taking the infemum over $z$ with $\\|z\\|_{\\mathcal{K}_1(\\mathbb{D})} \\leq R^{-1}M$ gives the result.\n\\end{proof}\n\n\n\\subsection{Competitions between locality and global smoothness}\nOne insight gained from the studies in this chapter is that the\nchallenges in constructing classic $H^m$-finite element subspace seems\nto lie in the competitions between local d.o.f.  (degree of freedom)\nand global smoothness.  In the classic finite element, one requires to\ndefine d.o.f. on each element and then glue the local d.o.f. together\nto obtain a globally $H^m$-smooth function. This process has proven to\nbe very difficult to realize in general when $m\\ge 2$. But, if we relax the\nlocality, as in Powell-Sabine\nelement~\\cite{powell1977piecewise}, we can use piecewise polynomials\nof lower degree to construct globally smooth function. The neural\nnetwork approach studied in this paper can be considered as a global\nconstruction without any use of a grid in the first place (even though\nan implicitly defined grid exists). As a result, it is quite easy to\nconstruct globally smooth functions that are piecewise polynomials. It\nis quite remarkable that such a global construction\nleads to function class that has very good approximation\nproperties. This is an attractive property of the function classes from\nthe artificial neural network.  One feasible question to ask if it is\npossible to develop finite element construction technique that are\nmore global than the classic finite element but more  local than the\nfinite neuron method, which may be an interesting topic for\nfurther research. \n\n\n \\begin{center}\n \\begin{table}[!ht]\n\\begin{tabular}{|c|c|c|c|}\n\\hline\nLocal D.O.F.  &Slightly more global &$\\cdots$ &global \\\\\n\\hline\nGeneral grid& Special grid& $\\cdots$ &No grid\\\\\n\\includegraphics[width=0.15\\textwidth]{6DL/figures/unstructureGrid.pdf} &\\includegraphics[width=0.22\\textwidth]{6DL/figures/PowellSabin2.png} &$\\cdots$ & \\\\\nConjecture: $k=(m-1)2^d+1$  &  Powell-Sabin \\cite{powell1977piecewise}&  $\\cdots$ & ReLU$^m$-DNN \\\\\nTrue: $d=1,m\\ge 1$ &    $k=2$ &   $\\cdots$ & $k=m$     \\\\\n$d=2,m=2$ (Still open)  & $d=2,m=2$ & $?$&  any $d$ and $m$ \\\\\n\\hline\n\\end{tabular}\n\\caption{Competitions between locality and global smoothness.}\n\\label{compare}\n\\end{table}\n\\end{center}\nObservation: More global d.o.f. lead to easier\nconstruction of conforming elements for high order PDEs.\n\n\\subsection{Piecewise $P_m$ for $H^m(\\Omega)$: from finite element to\n  finite neuron method} \\label{sec:concluding} As it is noted above,\nin the classic finite element setting, it is challenging to construct\n$H^m$-conforming finite element spaces for any $m, d\\ge 1$.  But if we\nrelax the conformity, as shown in \\cite{wang2013minimal}, it is\npossible to give a universal construction of convergent\n$H^m$-nonconforming finite element consisting of piecewise polynomial\nof degree $m$.  In the finite neuron method setting, by relaxing the\nconstraints from the a priori given finite element grid, the\nconstruction of $H^m$-conforming piecewise polynomials of degree $m$\nbecomes straightforward.  In fact, the finite neuron method can be\nconsidered as mesh-less method, or even, vertex-less method although\nthere is a hidden grid for any finite neuron function.  This raises a\nquestion if it is possible to develop some \"in-between\" method that have\nthe advantages of both the classic finite element method and the\nfinite neuron method. \n\n\\subsection{Adaptivity and spectral accuracy} \nOne of the important properties in the traditional finite element\nmethod is its ability to locally adapt the finite element grids to\nprovide accurate approximation of PDE solution that may have local\nsingularities (such as corner singularities and interface\nsingularities).  In contrast, the traditional spectral method (using\nhigh order polynomials) can provide very high order accuracy for\nsolutions that are globally smooth.  The finite neuron method analyzed\nin this paper seems to possess both the adaptivity feature as in the\ntraditional finite element method and also the global spectral\naccuracy as in the traditional spectral methods.  Adaptivity feature\nof the finite neuron method is expected since, as shown in \n\\S~\\ref{sec:deep-fnm},  the deep finite neuron method can recover locally\nadaptive finite element spaces for $m=1$.  Spectral feature of the\nfinite neuron method is illustrated in Theorem~\\ref{thm:spectral}.\nAs a result, tt is conceivable that the finite neuron method may have both the\nlocal and also global adaptive feature, or perhaps even adaptive\nfeatures in all different scales.  Nevertheless, such highly adaptive\nfeatures of the finite neuron method come with a potentially big\nprice, namely the solution of a nonlinear and non-convex optimization\nproblems.\n\n\\subsection{Comparison with PINN}\nOne important class of methods that is related to the FNM analyzed in\nthis paper is the the method of physical-informed neural networks\n(PINN) introduced in \\cite{raissi2019physics}.  By minimizing\ncertain norms of PDE residual together with penalizations of boundary\nconditions and other relevant quantities, PINN is a very general\napproach that can be directly applied to a wide range of problems.  In\ncomparison, FNM can only be applied to some special class of problems\nthat admit some special physical laws such as principle of energy\nminimization or principle of least action, see \\cite{feynmanfeynman}.\n%\\footnote{ Chapter 19\n%  of Volume II, Feynman R, Leighton R, and Sands M. The Feynman\n%  Lectures on Physics . 3 volumes 1964, 1966. Library of Congress\n%  Catalog Card No. 63-20717. ISBN 0-201-02115-3 (1970 paperback\n%  three-volume set); ISBN 0-201-50064-7 (1989 commemorative hardcover\n%  three-volume set); ISBN 0-8053-9045-6 (2006 the definitive edition\n%  (2nd printing); hardcover)}.  \nBecause of the special physical law associated with our underlying\nminimization problems, the Neumann boundary conditions are naturally\nenforced in the minimization problem and, unlike in the PINN method,\nno penalization is needed to enforce such type of boundary conditions.\n\n\\subsection{On the sharpness of the error estimates} \n\nWe  note our error estimate \\eqref{error:D} for Dirichlet boundary\ncondition is not as good as the one \\eqref{error:N} for Neumann\nboundary conditions.  This is undesirable and may not be optimal.  In\ncomparison, Nitsche trick does not suffer a loss of accuracy when used\nin traditional finite element method.\n\n\\subsection{Neural splines in multi-dimensions}\nThe spline functions described in Section~\\ref{sec:Bsplines} are widely\nused in scientific and enginnering computing, but their generalization\nmultiple dimension are non-trivial, especially when $\\Omega$ has\ncurved boundary. In \\cite{hu2015minimal}, using the tensor product,\nthe authors extended the 1D spline to multi-dimensions on rectangular\ngrids.  Some others involve rational functions such as NURBS\n\\cite{cottrell2009isogeometric}. But the generalization of neural networks to multi-dimension is straightforward and also the\nresulting (nonlinear) space has very good approximate properties.  It\nis conceivable that the neural network extension of B-spline to\nmultiple dimensions which are locally polynomials and globally smooth,\nmay find useful applications in computer aid design (CAD) and\nisogeometric analysis \\cite{cottrell2009isogeometric}. This is a\npotentially an interesting research direction.\n\n\n\n\n", "meta": {"hexsha": "d8a606eeb13bc15fd9d4de164efecd13fb5b943d", "size": 44070, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/deepNeuron.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/deepNeuron.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/deepNeuron.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.1365187713, "max_line_length": 852, "alphanum_fraction": 0.707601543, "num_tokens": 15350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851143290548, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7132018005445334}}
{"text": "\\section{Eigenvalues and Singular Values}\n\\subsection{}\n\\begin{definition}\n  Let $A$ be an $nxn$ matrix. A scalar $\\lambda$ is an eigenvalue of $A$ if \n  \\[\n  A\\vec{v}=\\lambda\\vec{v}\n  .\\] \n  For some nonzero vector $\\vec{v}\\cdot\\vec{v}$ is called the eigen vector corresponding to lambda.\n\\end{definition}\n\\begin{eg}\n  Consider $A=\\SmallMatrix{2&1\\\\1&2}$. Let's find the eigenvalues of this matrix.\n    \\begin{align*}\n    0 &= det\\left( \\begin{pmatrix}2&1\\\\1&2\\end{pmatrix}-\\begin{pmatrix}\\lambda&0\\\\0&\\lambda\\end{pmatrix}\\right) \\\\\n      &=det\\begin{pmatrix} 2-\\lambda&1\\\\1&2-\\lambda \\end{pmatrix} \\\\\n      &=(2-\\lambda)^2-1\\\\\n    0&=(3-\\lambda)(1-\\lambda).\n    \\end{align*}\n  Our eigenvalues are 3 and 1. Remember that $(A-\\lambda I)\\vec{v}=\\vec{0}$. Consider $\\lambda = 3$\n  \\begin{align*}\n    \\begin{pmatrix} -1&1\\\\1&-1 \\end{pmatrix} \\begin{pmatrix} x\\\\y \\end{pmatrix} =\\begin{pmatrix} 0\\\\0 \\end{pmatrix} \\\\\n    -x+y=0\\\\\n    x=y\\\\\n    \\begin{pmatrix} x\\\\x \\end{pmatrix} =x\\begin{pmatrix} 1\\\\1 \\end{pmatrix} \n  .\\end{align*}\n  Now consider $\\lambda = 1$.\n  \\begin{align*}\n    A(\\lambda I)\\vec{v}=\\vec{0}\\\\\n    (A-\\lambda I)\\vec{v}\\\\\n    \\begin{pmatrix} 1&1\\\\1&1 \\end{pmatrix} \\begin{pmatrix} x\\\\y \\end{pmatrix} =\\begin{pmatrix} 0\\\\0 \\end{pmatrix} \\\\\n    x+y=0\\\\\n    y=-x\\\\\n    \\begin{pmatrix} x\\\\-x \\end{pmatrix} =x\\begin{pmatrix} 1\\\\-1 \\end{pmatrix} \n  .\\end{align*}\n\\end{eg}\n\n\\begin{eg}\n  Consider $A=\\SmallMatrix{1&1&2\\\\0&1&2\\\\0&0&3}\\begin{pmatrix}1&1&2\\\\0&1&2\\\\0&0&3\\end{pmatrix}$. For eigenvalues, $0=det(A-\\lambda I)$.\n  \\begin{align*}\n    0 = det \\begin{pmatrix} 1-\\lambda&1&2\\\\0&1-\\lambda&2\\\\0&0&3-\\lambda \\end{pmatrix} \\\\\n    0=(1-\\lambda)(1-\\lambda)(3-\\lambda)\n  .\\end{align*}\n  This makes our eigenvalues 1 and 3. For $\\lambda=3$,\n  \\begin{align*}\n    \\begin{pmatrix} -2&1&2\\\\0&-2&2\\\\0&0&0 \\end{pmatrix} \\begin{pmatrix} x\\\\y\\\\z \\end{pmatrix} &=\\begin{pmatrix} 0\\\\0\\\\0 \\end{pmatrix} \\\\\n    -2y+2z&=0\\\\\n    y&=0\\\\\n    -2x+z+2z&=0\\\\\n    -2x+3z&=0\\\\\n    3z&=2x\\\\\n    y&=z=\\frac{2}{3}\n  .\\end{align*}\n  This would make our eigenvector \n  \\[\n  \\begin{pmatrix} x\\\\\\frac{2}{3}x\\\\\\frac{2}{3}x \\end{pmatrix} =x\\begin{pmatrix} 1\\\\\\frac{2}{3}\\\\\\frac{2}{3} \\end{pmatrix} \n  .\\] \n\\end{eg}\n\\begin{definition}\n  Given an eigenvalue $\\lambda$ of $A$, the corresponding eigenvectors form a subspace denoted $v_\\lambda$. Note that $v_\\lambda=ker(A-\\lambda I)$\n\\end{definition}\n\\begin{note}\n  $\\lambda=0$ is an eigenvalue of $A$ if and only if the $ker(A-\\lambda I)=ker(A)=v_0\\neq \\{0\\}$. This is true if and only if $A$ is singular ($det(A)=0$).\n\\end{note}\n\\begin{eg}\n  Consider $\\begin{pmatrix} 1&1\\\\1&1 \\end{pmatrix} $. The determinant of \n  \\[\n    \\begin{pmatrix} 1-\\lambda&1\\\\1&1-\\lambda \\end{pmatrix} \n  \\] \n  is equal to zero. We can see that when $\\lambda =0$, the determinant is zero.\n\\end{eg}\n\\begin{prop}\n  If $A$ is a real matrix and $\\lambda+i\\mu$ is an eigenvalue of $A$ with eigenvector $\\vec{v}=\\vec{x}+i\\vec{y}$, then $\\lambda-i\\mu$ is an eigenvalue of $A$ with eigenvector $\\vec{x}-i\\vec{y}$.\n\\end{prop}\n\\begin{eg}\n  Consider the matrix $A=\\begin{bmatrix} 0&-1\\\\1&0 \\end{bmatrix} $.\n  \\begin{align*}\n    | A-\\lambda I| = 0\\\\\n    \\left| \\begin{matrix} -\\lambda&-1\\\\1&-\\lambda \\end{matrix} \\right| =0\\\\\n    \\lambda^2+1=0\\\\\n    \\lambda^2 = -1\\\\\n    \\lambda = \\pm i = 0\\pm i\\\\\n    (A-\\lambda I) \\vec{v} = 0\\\\\n    \\begin{pmatrix} -i&-1\\\\1&-i \\end{pmatrix} \\begin{pmatrix} x\\\\y \\end{pmatrix} =\\begin{pmatrix} 0\\\\0 \\end{pmatrix} \\\\\n    -ix-y=0\\\\\n    -ix=y\n  .\\end{align*}\n  We now know that if we let $x$ be anything, and $y=-ix$, then we have the eigenvector. We can rewrite it as \n  \\begin{align*}\n    \\begin{pmatrix} x\\\\-ix \\end{pmatrix} =\\boxed{} + i\\boxed{}\\\\\n    =\\begin{pmatrix} x\\\\0 \\end{pmatrix}+\\begin{pmatrix} 0\\\\-ix \\end{pmatrix}\\\\\n    =x\\begin{pmatrix} 1\\\\0 \\end{pmatrix}+x\\begin{pmatrix} 0\\\\-i \\end{pmatrix}  \\\\\n    =x\\begin{pmatrix} 1\\\\0 \\end{pmatrix} + i\\begin{pmatrix} 0\\\\-1 \\end{pmatrix} \n  .\\end{align*}\n  Now we also know that if $\\lambda  = -i$ then the eigenvector is \n  \\[\n  \\begin{pmatrix} 1\\\\0 \\end{pmatrix} -i\\begin{pmatrix} 0\\\\1 \\end{pmatrix} \n  .\\] \n\\end{eg}\n\\lecture{1}{Monday March 29, 2021}{8.2, 8.3}\nIf $A$ is an $n\\times n$ matrix with real entries, then \n\\[\n  det(A-\\lambda I) = p(\\lambda)= \\text{The characteristic polynomial}\n.\\] \n\\begin{note}\n  If $A$ is $2\\times 2$, then $P_A(\\lambda)=\\lambda^2-Tr(A)+det(A)$\n\\end{note}\nSuppose that $A=\\begin{bmatrix} a&b\\\\c&d \\end{bmatrix}$. The trace ($Tr(A)$) is $=a+d$, and the determinant if $A$ is $ad-bc$, so \n\\begin{align*}\n  p_a(\\lambda)=\\left| \\begin{matrix} a-\\lambda&b\\\\c&d-\\lambda \\end{matrix} \\right| \n  =(a-\\lambda)(d-\\lambda)-bc\\\\\n  =ad-d\\lambda-a\\lambda+\\lambda^2-bc\\\\\n  =\\lambda^2-(a+d)\\lambda+(ad-bc)\n.\\end{align*}\nRemember, the trace is $a+d$, and the determinant is $ad-bc$. Recall that $A$ is real, so $P_A(\\lambda)$ is real. If we set $P_A(\\lambda)=0$. By the fundamental theorem of algebra, $P_A(\\lambda)$ factors into linear factors over $\\C$. Consider the equation \n\\[\nx^{10}-7x^{9}+8x^2+\\frac{1}{2}=0\n.\\] \nThis factors into 10 different roots. So if $A$ is $n\\times n$, $P_A(\\lambda)$ has at most $n$ roots in $\\C$\n\\begin{theorem}\n  Let $A$ be $n\\times n$ with real entries. Then $A$ has at most $n$ eigenvalues. If $a+bi$ is an eigenvalue, then so is $a-bi$\n\\end{theorem}\n\\begin{eg}\n  The Jordan Block Matrix. Let's look at $J_{2,3}=\\begin{bmatrix} 2&1&0\\\\0&2&1\\\\0&0&2 \\end{bmatrix} $. Let's find the eigenvalues:\n  \\begin{align*}\n    | J_{2,3}-\\lambda I| = 0\\\\\n    \\left| \\begin{matrix} 2-\\lambda&1&0\\\\0&2-\\lambda&1\\\\0&0&2-\\lambda \\end{matrix} \\right| =0\\\\\n    (2-\\lambda)(2-\\lambda)(1-\\lambda)=0\\\\\n    \\lambda=2\n  .\\end{align*}\n  Now let's find the eigenvector(s):\n  \\begin{align*}\n    (a-lambda I)\\vec{v}=\\vec{0}\\\\\n    \\begin{pmatrix} 0&1&0\\\\0&0&1\\\\0&0&0 \\end{pmatrix} \\begin{pmatrix} x\\\\y\\\\z \\end{pmatrix} =\\begin{pmatrix} 0\\\\0\\\\0 \\end{pmatrix} \\\\\n    y=0\\\\\n    z=0\\\\\n    \\begin{pmatrix} x\\\\0\\\\0 \\end{pmatrix} =x\\begin{pmatrix} 1\\\\0\\\\0 \\end{pmatrix} \n  .\\end{align*}\n\\end{eg}\n\\begin{theorem}\n  If $A$ is square, then $P_A(\\lambda)=P_{A^{T}}(\\lambda)$. So, $A$ and $A^{T}$ have the same eigenvalues. Probably not the same eigenvectors.\n\\end{theorem}\n\\begin{theorem}\n  Let $A$ be $n\\times n$. The sum of the eigenvalues of $A$ is equal to the $Tr(A)$, and the product of the eigenvalues of $A$ is equal to $det(A)$.\n\\end{theorem}\n\\begin{eg}\n  $J_{2,3}=\\begin{pmatrix} 2&1&0\\\\0&2&1\\\\0&0&2 \\end{pmatrix} $. The Trace of $J_{2,3}=2+2+2$ (adding the diagonals). The determinant of $J_{2,3}=2*2*2$ (multiplication of the diagonals).\n  \\[\n    P_{J_{2,3}}(\\lambda)=(2-\\lambda)(2-\\lambda)(2-\\lambda)\n  .\\] \n\\end{eg}\n\\subsection{}\n\\begin{prop}\n  If $\\lambda_1,\\ldots,\\lambda_k$ are distinct eigenvalues of $A,$ then the corresponding eigenvectors are linearly independent.\n\\end{prop}\n\\begin{eg}\n  Let's let $A=\\begin{bmatrix} 1&1&0\\\\0&2&-1\\\\0&0&3 \\end{bmatrix} $. Let's find the eigenvalues of $A$.\n  \\begin{align*}\n    0=P_A(\\lambda) &= \\left| \\begin{matrix} 1-\\lambda&1&0\\\\0&2-\\lambda&-1\\\\0&0&3-\\lambda \\end{matrix} \\right| \\\\\n    0&=(1-\\lambda)(2-\\lambda)(3-\\lambda)\\\\\n    \\lambda&=1,2,3\n  .\\end{align*}\n  For $\\lambda=1$\n  \\begin{align*}\n    (A-\\lambda I)\\vec{v}&=\\vec{0}\\\\\n    \\begin{pmatrix} 0&1&0\\\\0&1&-1\\\\0&0&2 \\end{pmatrix} \\begin{pmatrix} x\\\\y\\\\z \\end{pmatrix} &=\\begin{pmatrix} 0\\\\0\\\\0 \\end{pmatrix} \\\\\n    y&=0\\\\\n    y-z&=0\\\\\n    z&=0\\\\\n    \\begin{pmatrix} x\\\\0\\\\0 \\end{pmatrix} &=x\\begin{pmatrix} 1\\\\0\\\\0 \\end{pmatrix} \n  .\\end{align*}\n  Now for $\\lambda=2$\n  \\begin{align*}\n    \\begin{pmatrix} -1&1&0\\\\0&0&-1\\\\0&0&1 \\end{pmatrix} \\begin{pmatrix} x\\\\y\\\\z \\end{pmatrix} &=\\begin{pmatrix} 0\\\\0\\\\0 \\end{pmatrix} \\\\\n    -x+y&=0\\\\\n    x&=y\n    -z&=0\\\\\n    \\begin{pmatrix} x\\\\x\\\\0 \\end{pmatrix} &=x\\begin{pmatrix} 1\\\\1\\\\0 \\end{pmatrix} \n  .\\end{align*}\n  Now for $\\lambda=3$\n  \\begin{align*}\n    \\begin{pmatrix} -2&1&0\\\\0&-1&-1\\\\0&0&0 \\end{pmatrix} \\begin{pmatrix} x\\\\y\\\\z \\end{pmatrix} &=\\begin{pmatrix} 0\\\\0\\\\0 \\end{pmatrix} \\\\\n    -2x+y&=0\\to y=2x\\\\\n    -y-z&=0\\to z=-y\\\\\n    z&=-2x\\\\\n    \\begin{pmatrix} x\\\\2x\\\\-2x \\end{pmatrix} &=x\\begin{pmatrix} 1\\\\2\\\\-2 \\end{pmatrix} \n  .\\end{align*}\n  We now have the following eigenvectors \n  \\[\n  \\begin{pmatrix} 1\\\\0\\\\0 \\end{pmatrix} ,\\begin{pmatrix} 1\\\\1\\\\0 \\end{pmatrix} ,\\begin{pmatrix} 1\\\\2\\\\-2 \\end{pmatrix} \n  .\\] \n  These are linearly independent so we have a basis for $\\R^3$\n\\end{eg}\n\\begin{theorem}\n  If $A$ is $n\\times n$ and $a$ has $n$ distinct real (/complex) eigenvalues, then the corresponding eigenvectors form a basis for $\\R^b(\\C^n)$. \n\\end{theorem}\nNow\\ldots vector spaces. Vectors have two main operations,\n\\begin{align*}\n  \\vec{v}+\\vec{w}\\\\\n  c\\cdot v\n.\\end{align*}\nLet $V, W$ be vector spaces over $\\R$. We know that $\\R^3\\begin{pmatrix} a\\\\0\\\\0 \\end{pmatrix}$. In reality, $V, W$ are the same, but we must show that they are the same. We would need a function that preserves the operations from $V$ to $W$. A map (function) $f$ from $V$ to $W$ should have the following\n\\begin{align*}\n  f(\\vec{v_1}+\\vec{v_2})&=f(\\vec{v_1})+f(\\vec{v_2})\\\\\n  f(r\\cdot \\vec{v})&=rf(\\vec{v})\n.\\end{align*}\n\\lecture{2}{Wednesday, March 31st}{8.3}\nRecall that $\\lambda=0$ is an eigenvalue of $A$, if and only if\n\\[\n  (A-0\\cdot I)\\vec{v}=\\vec{0}\n\\] has a $\\vec{v}\\neq \\vec{0}$ solution if and only if \n\\[\n  ker(A)\\neq\\{0\\}\n\\] if and only if  $A^{-1}$ does not exist.\n\\begin{theorem}\n  If $\\lambda_1,\\ldots,\\lambda_k$ are distinct eigenvalues of $A$, then the corresponding eigenvectors are linearly independent.\n\\end{theorem}\n\\begin{eg}\n  Consider $A=\\begin{pmatrix} 2&1\\\\1&2 \\end{pmatrix} $. The eigenvalues for this matrix are $\\lambda=3,1$. The eigenvector for $\\lambda=3$ is $\\begin{pmatrix} 1\\\\1 \\end{pmatrix} $, and the eigenvector for $\\lambda=1$ is $\\begin{pmatrix} -1\\\\1 \\end{pmatrix} $.\n\\end{eg}\n\\begin{eg}\n  Consider $A=\\begin{pmatrix} 1&1&2\\\\0&1&2\\\\0&0&3 \\end{pmatrix} $. The characteristic polynomial is $P(\\lambda)=(1-\\lambda)^2(3-\\lambda)$. For $ \\lambda = 1$, the eigenvector is $\\begin{pmatrix} 1\\\\0\\\\0 \\end{pmatrix} $, and for $\\lambda = 3$, the eigenvector is $\\begin{pmatrix} 3\\\\2\\\\2 \\end{pmatrix} $ \n\\end{eg}\n\\begin{theorem}\n  If $A $ is $n\\times n$ and $A$ has $n$ distinct real (or complex) eigenvalues, then the corresponding eigenvectors $\\vec{v_1},\\ldots,\\vec{v_n}$ form a basis for $\\R^{n}$.\n\\end{theorem}\n  Consider $A=\\begin{pmatrix} 1&-1\\\\2&4 \\end{pmatrix} $. $A$ defines a map from $\\R^{2}$ to $\\R^2$. Our map is \n  \\begin{align*}\n    L: \\begin{pmatrix} x\\\\y \\end{pmatrix}\\to A\\begin{pmatrix} x\\\\y \\end{pmatrix}\\\\\n    L\\left( r\\vec{v} \\right) =rL(\\vec{v})\n  .\\end{align*}\n  $L$ is a linear transformation.\n\n\\begin{eg}\n  Consider $A=\\begin{pmatrix} 1&-1\\\\2&4 \\end{pmatrix} $. What happens if we multiply $A$ by $\\begin{pmatrix} 2\\\\1 \\end{pmatrix} $?\n  \\begin{align*}\n    A\\begin{pmatrix} 2\\\\1 \\end{pmatrix} =\\begin{pmatrix} 1&-1\\\\2&4 \\end{pmatrix} \\begin{pmatrix} 2\\\\1 \\end{pmatrix} \\\\\n    =\\begin{pmatrix} 1\\\\8 \\end{pmatrix} \n  .\\end{align*}\n  Let's think of $\\begin{pmatrix} 2\\\\1 \\end{pmatrix} $ as $2e_1+1e_2$. This would make our equation \\[\n  2\\begin{pmatrix} 1\\\\0 \\end{pmatrix} +\\begin{pmatrix} 0\\\\1 \\end{pmatrix} \n  .\\] \n  Let's also think about $\\begin{pmatrix} 1\\\\8 \\end{pmatrix} $ as \\[\n  1\\begin{pmatrix} 1\\\\0 \\end{pmatrix} +8\\begin{pmatrix} 0\\\\1 \\end{pmatrix} \n  .\\] \n  We can change the basis to \n  \\begin{align*}\n    v_1=\\begin{pmatrix} 1\\\\-1 \\end{pmatrix} && v_2=\\begin{pmatrix} 1\\\\-2 \\end{pmatrix} \n  .\\end{align*}\n\\end{eg}\n\\lecture{3}{Monday March 29, 2021}{8.2, 8.3}\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.8\\textwidth]{resource/images/8-2Figure1.png}\n  \\caption{Example Line image}\n  \\label{fig:}\n\\end{figure}\n\nA linear transformation consists of the following:\n\\begin{align*}\n  L(v_1+v_2)&=L(v_1)+L(v_2)\\\\\n  L(r\\cdot v)&=rL(v)\n.\\end{align*}\n  Consider $A = \\begin{pmatrix} 1&-1\\\\2&4 \\end{pmatrix} $. If everything is in the standard basis then \n  \\begin{align*}\n    \\begin{pmatrix} 1&-1\\\\2&4 \\end{pmatrix} \\begin{pmatrix} -1\\\\4 \\end{pmatrix} =\\begin{pmatrix} -5\\\\14 \\end{pmatrix} \\\\\n    -1\\begin{pmatrix} 1\\\\0 \\end{pmatrix} + 4\\begin{pmatrix} 0\\\\1 \\end{pmatrix} \\to -5\\begin{pmatrix} 1\\\\0 \\end{pmatrix} +14\\begin{pmatrix} 0\\\\1 \\end{pmatrix} \n  .\\end{align*}\n  It's harder to figure out what the vector is with the new basis from the picture, but the transformation has a nice description of \\[\n    B=\\begin{pmatrix} 2&0\\\\0&3 \\end{pmatrix} \n  .\\] \n  If we take $B$ and hit it with the new coefficients:\n  \\begin{align*}\n    \\begin{pmatrix} 2&0\\\\0&3 \\end{pmatrix} \\begin{pmatrix} 2\\\\-3 \\end{pmatrix} =\\begin{pmatrix} 4\\\\-9 \\end{pmatrix} \\\\\n    2\\begin{pmatrix} 1\\\\-1 \\end{pmatrix} + -3\\begin{pmatrix} 1\\\\-2 \\end{pmatrix} \\to 4\\begin{pmatrix} 1\\\\-1 \\end{pmatrix} +-9\\begin{pmatrix} 1\\\\-2 \\end{pmatrix} \n  .\\end{align*}\n    The left hand side is equal to $\\begin{pmatrix} -1\\\\4 \\end{pmatrix}$ and the right hand side is equal to $\\begin{pmatrix} -5\\\\14 \\end{pmatrix}$ If we take $\\begin{pmatrix} 2&0\\\\0&3 \\end{pmatrix} \\begin{pmatrix} 1\\\\0 \\end{pmatrix} =\\begin{pmatrix} 2\\\\0 \\end{pmatrix} $, which looks like an eigenvector. The first basis that we had was $\\left\\{\\begin{pmatrix} 1\\\\0 \\end{pmatrix}, \\begin{pmatrix} 0\\\\1 \\end{pmatrix}  \\right\\}$, and the second basis was $\\left\\{\\begin{pmatrix} 1\\\\-1 \\end{pmatrix}, \\begin{pmatrix} 1\\\\-2 \\end{pmatrix}  \\right\\}$. So we took basis 1 and did a linear transofrmation to get basis 2 like the following \n    \\[\n    \\begin{pmatrix} 1&-1\\\\2&4 \\end{pmatrix} \\to \\begin{pmatrix} 2&0\\\\0&3 \\end{pmatrix} \n    .\\] If $A$ is in the standard basis. Then $B=S^{-1}AS$, where $S=\\begin{pmatrix} \\vec{v_1},\\vec{v_2},\\ldots,\\vec{v_{n}} \\end{pmatrix} $, where $\\{\\vec{v_1},\\ldots,\\vec{v_n}\\}$ is the new basis.\n\\begin{eg}\n  Let $A=\\begin{pmatrix} 1&-1\\\\2&4 \\end{pmatrix} $.\n  \\begin{align*}\n    S=\\begin{pmatrix} 1&1\\\\-1&-2 \\end{pmatrix} \\\\\n    S^{-1}=\\frac{1}{-2--1}\\begin{pmatrix} -2&-1\\\\1&1 \\end{pmatrix} \\\\\n    =\\begin{pmatrix} 2&1\\\\-1&-1 \\end{pmatrix} \\\\\n    B=S^{-1}AS=\\begin{pmatrix} 2&1\\\\-1&-1 \\end{pmatrix} \\begin{pmatrix} 1&-1\\\\2&4 \\end{pmatrix} \\begin{pmatrix} 1&1\\\\-1&-2 \\end{pmatrix} \\\\\n    = \\begin{pmatrix} 2&1\\\\-1&-1 \\end{pmatrix} \\begin{pmatrix} 2&3\\\\-2&-6 \\end{pmatrix} \\\\\n    =\\begin{pmatrix} 2&0\\\\0&3 \\end{pmatrix} \n  .\\end{align*}\n\\end{eg}\n\\begin{definition}\n  A square matrix $A$ is diagonalizable if there is a matrix $S$ and a diagonal matrix $\\Lambda$ such that \n  \\begin{equation*}\n    \\Lambda = S^{-1}AS\n  \\end{equation*}\n\\end{definition}\n\\begin{theorem}\n  $A$ is diagonalizable if and only if $A$ has $n$ linearly independent eigenvectors $\\vec{v_1},\\ldots,\\vec{v_n}$. In this case, \\[\n  \\Lambda = S^{-1}AS\n  .\\] where $S=\\begin{bmatrix} \\vec{v_1},\\ldots,\\vec{v_n} \\end{bmatrix} $, and $\\Lambda=\\begin{bmatrix} \\lambda_1&0\\\\0&\\lambda_n \\end{bmatrix} $, where $\\lambda_i$ is the eigenvalue for $\\vec{v_i}$\n\\end{theorem}\nIf we are looking for the linearly independent solutions we need to do $A-\\lambda I=0$. From here we would get lambda values and create eigenvectors using $A-\\lambda I\\vec{v}=0$\n\\begin{eg}\n  Let $A=\\begin{pmatrix} 0&-1&-1\\\\1&2&1\\\\1&1&2 \\end{pmatrix} $, which is our standard matrix. Once we find our \\[\n  \\Lambda = \\begin{pmatrix} 1&0&0\\\\0&1&0\\\\0&0&2 \\end{pmatrix} \n  .\\] Our basis is \\[\n  \\begin{pmatrix} -1\\\\1\\\\0 \\end{pmatrix} \\begin{pmatrix} -1\\\\0\\\\1 \\end{pmatrix} \\begin{pmatrix} -1\\\\1\\\\1 \\end{pmatrix} \n  .\\] Let's take $A$ and hit it with coefficients in the standard basis. Let's try \\[\n  A\\cdot\\begin{pmatrix} -3\\\\2\\\\2 \\end{pmatrix} \n  .\\] We need to think about the matrix on the right hand side as $-3\\begin{pmatrix} 1\\\\0\\\\0 \\end{pmatrix} +2\\begin{pmatrix} 0\\\\1\\\\0 \\end{pmatrix} +2\\begin{pmatrix} 0\\\\0\\\\1 \\end{pmatrix} $, so we can do the following:\n  \\begin{align*}\n    \\begin{pmatrix} 0&-1&-1\\\\1&2&1\\\\1&1&2 \\end{pmatrix} \\begin{pmatrix} -3\\\\2\\\\2 \\end{pmatrix} =\\begin{pmatrix} -4\\\\3\\\\3 \\end{pmatrix} \n  .\\end{align*}\n  We know that our divided up equation from before (for the right matrix) is getting mapped to $4\\begin{pmatrix} 1\\\\0\\\\0 \\end{pmatrix} +3\\begin{pmatrix} 0\\\\1\\\\0 \\end{pmatrix} +3\\begin{pmatrix} 0\\\\0\\\\1 \\end{pmatrix} $. We know that our $\\Lambda$ must take $\\begin{pmatrix} -3\\\\2\\\\2 \\end{pmatrix} $, but we need to rewrite it in our new basis.\\[\n  1\\begin{pmatrix} -1\\\\1\\\\0 \\end{pmatrix} +1\\begin{pmatrix} -1\\\\0\\\\1 \\end{pmatrix} +1\\begin{pmatrix} -1\\\\1\\\\1 \\end{pmatrix} \n  .\\] \n  If we multiply this by our $\\lambda$, we can figure out out map. \\[\n    \\begin{pmatrix} 1&0&0\\\\0&1&0\\\\0&0&2 \\end{pmatrix} \\begin{pmatrix} 1\\\\1\\\\1 \\end{pmatrix} =\\begin{pmatrix} 1\\\\1\\\\2 \\end{pmatrix} \n  .\\] \n  Our equation gets mapped to \\[\n  1\\begin{pmatrix} -1\\\\1\\\\0 \\end{pmatrix} +1\\begin{pmatrix} -1\\\\0\\\\1 \\end{pmatrix} +2\\begin{pmatrix} -1\\\\1\\\\1 \\end{pmatrix} \n  .\\] \n  This means that our vector is the same from before because we get $\\begin{pmatrix} -4\\\\3\\\\3 \\end{pmatrix} $.\\newline\n  $Av_1\\to w_1$, while $\\Lambda v_2\\to w_2$.\n\\end{eg}\n\n\\lecture{4}{Monday April 12, 2021}{8.5}\n\nLet $A$ be an $m\\times n$ matrix. $A$ defines a function from $\\R^{n}$ to $\\R^{n}$\n\\begin{align*}\n  L:\\vec{x}\\to A\\vec{x}\\\\\n  L(\\vec{x}+\\vec{y})=L(\\vec{x})+L(\\vec{y})\\\\\n  L(c\\vec{x})=cL(\\vec{x})\n.\\end{align*}\nThis fixes the standard basis $\\begin{pmatrix} 1\\\\0\\\\ \\vdots\\\\0 \\end{pmatrix},\\begin{pmatrix} 0\\\\1\\\\ \\vdots \\\\0 \\end{pmatrix}, \\begin{pmatrix} 0\\\\0\\\\ \\vdots \\\\0 \\end{pmatrix}   $ and a different basis. Consider $\\begin{pmatrix} 2\\\\1\\\\5 \\end{pmatrix} = 2\\begin{pmatrix} 1\\\\0\\\\-1 \\end{pmatrix} + \\begin{pmatrix} 0\\\\1\\\\0 \\end{pmatrix} +5\\begin{pmatrix} 0\\\\0\\\\1 \\end{pmatrix}  $. A is mapping coefficients in the standard basis to coefficients in the standard basis.\n\n\\lecture{5}{Wednesday April 14, 2021}{}\n\nIf we have an $n\\times n$ matrix with $n$ distinct eigenvalues, we have $n$ linearly independent eigenvectors. \\[\n\\Lambda=S^{-1}AS\n.\\] \nIf the matrix is real symmetric, then we can get a real eigenvector basis so we can diagonalize like \\[\nS\\Lambda S^{-1}=A\n.\\] \nIf we do $A\\cdot A$, then we get \n\\begin{align*}\n  S\\Lambda S^{-1}S\\Lambda S^{-1}\\\\\n  =S \\Lambda S^{-1}\\\\\n  A^{k}=S \\Lambda ^{k}S^{-1}\n.\\end{align*}\nLet's look at an example where this is not going to work. \n\\begin{eg}\n  Let $M=\\begin{bmatrix} 1&1&1\\\\0&1&0\\\\0&0&1 \\end{bmatrix} $. This matrix only has one eigenvalue of $\\lambda=1$. Let's find the eigenvectors.\n  \\begin{align*}\n    \\begin{bmatrix} 0&1&1\\\\0&0&0\\\\0&0&0 \\end{bmatrix} \\begin{bmatrix} x\\\\y\\\\z \\end{bmatrix} =\\begin{bmatrix} 0\\\\0\\\\0 \\end{bmatrix} \\\\\n    y+z=0\\to z=-y\\\\\n    \\begin{bmatrix} x\\\\y\\\\-y \\end{bmatrix} =x\\begin{bmatrix} 1\\\\0\\\\0 \\end{bmatrix} +y\\begin{bmatrix} 0\\\\1\\\\-1 \\end{bmatrix} \n  .\\end{align*}\n\\end{eg}\nNow supposed instead, if we let $M=\\begin{bmatrix} 1&0&0\\\\0&1&0\\\\0&0&1 \\end{bmatrix} $. This matrix must have 3 linearly independent eigenvectors.\n\\begin{align*}\n  |M- \\lambda I|=0\\\\\n  \\left| \\begin{matrix} 1-\\lambda &0&0\\\\0&1-\\lambda&0\\\\0&0&1-\\lambda \\end{matrix} \\right| =0\\\\\n  (M-\\lambda I)\\vec{v} = 0\\\\\n  \\begin{bmatrix} 0&0&0\\\\0&0&0\\\\0&0&0 \\end{bmatrix} \\begin{bmatrix} x\\\\y\\\\z \\end{bmatrix} =\\begin{bmatrix} 0\\\\0\\\\0 \\end{bmatrix} \\\\\n  \\begin{bmatrix} x\\\\y\\\\z \\end{bmatrix} =x\\begin{bmatrix} 1\\\\0\\\\0 \\end{bmatrix} +y\\begin{bmatrix} 0\\\\1\\\\0 \\end{bmatrix} +z\\begin{bmatrix} 0\\\\0\\\\1 \\end{bmatrix} \n.\\end{align*}\n\n\\begin{theorem}\n  Let $A=A^{T}$ be an $n\\times n$ real matrix. Let $\\vec{v_1},\\ldots,\\vec{v_n}$ be an eigenvector basis such that $\\vec{v_1},\\ldots,\\vec{v_r}$ correspond to nonzero eigenvalues and $\\vec{v_{r+1}},\\ldots,\\vec{v_n}$ correspond to the zero eigenvalue. Then $r=rank(A)$, $\\vec{v_1},\\ldots,\\vec{v_r}$ form an orthogonal basis for $IM(A)=coimg(A)$, and $\\vec{v_{r+1}},\\ldots,\\vec{v_n}$ form an orthogonal basis for the $ker(A)=coker(A)$.\n\\end{theorem}\n\\begin{theorem}\n  The spectral theorem. Let $A$ be a real symmetric matrix. Then there exists an orthogonal matrix $Q$ such that $A=Q\\Lambda Q^{-1}=Q\\Lambda Q^{T}$, where $\\Lambda $ is a real diagonal matrix. The eigenvalues of $A$ appear on the diagonal of $\\Lambda $, while the columns of $Q$ are orthonormal eigenvectors of $A$.\n\\end{theorem}\n\\begin{eg}\n  Let $A=\\begin{bmatrix} 1&-1&1\\\\-1&1&0\\\\1&01 \\end{bmatrix} $. Our eigenvalues are $1+\\sqrt{2},1,1-\\sqrt{2}  $, which means our eigenvectors are \\[\n  \\begin{bmatrix} \\sqrt{2} \\\\-1\\\\1 \\end{bmatrix} ,\\begin{bmatrix} 0\\\\1\\\\1 \\end{bmatrix} ,\\begin{bmatrix} -\\sqrt{2} \\\\-1\\\\1 \\end{bmatrix} \n  .\\] \n  The orthonormal basis of the eigenvectors is \n  \\begin{align*}\n    \\sqrt{(\\sqrt{2} )^2+(-1)^2+1^2}\\\\\n    =\\sqrt{6}\\\\\n    \\begin{bmatrix} \\frac{\\sqrt{2} }{2}\\\\-\\frac{1}{2}\\\\\\frac{1}{2} \\end{bmatrix} ,\\begin{bmatrix} 0\\\\\\frac{1}{\\sqrt{2} }\\\\\\frac{1}{\\sqrt{2} } \\end{bmatrix} ,\\begin{bmatrix} \\frac{1}{2}\\\\\\frac{1}{2}\\\\\\frac{1}{2} \\end{bmatrix} \n  .\\end{align*}\n  Now if we let $S=\\begin{bmatrix} \\sqrt{2} &0&-\\sqrt{2}\\\\-1&1&-1\\\\1&1&1  \\end{bmatrix} $ and we do \\[\n  S^{-1}AS= \\Lambda=\\begin{bmatrix} 1+\\sqrt{2}&0&0\\\\0&1&0\\\\0&0&1-\\sqrt{2}   \\end{bmatrix} \n  .\\] \n\\end{eg}\n\n\\lecture{6}{Friday April 16}{8.6}\n", "meta": {"hexsha": "7df7c6c4042506afffa4c20317abe87e4db6eb67", "size": 20887, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math363/chapters/8.tex", "max_stars_repo_name": "CameronSWilliamson/GU-MATH", "max_stars_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-18T00:49:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T00:49:14.000Z", "max_issues_repo_path": "math363/chapters/8.tex", "max_issues_repo_name": "therealkeyisme/Math-Notes", "max_issues_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math363/chapters/8.tex", "max_forks_repo_name": "therealkeyisme/Math-Notes", "max_forks_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.4194373402, "max_line_length": 632, "alphanum_fraction": 0.6274237564, "num_tokens": 8712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604133, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7132017966668972}}
{"text": "% Copyright 2018 Melvin Eloy Irizarry-Gelpí\n\\chapter{W Binions}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nA W binion has the form\n\\begin{equation}\n    a_{0} + a_{1} W\n\\end{equation}\nThese follow from a parabolic Cayley-Dickson construct on the reals. Since you need two real numbers for a W binion, you can represent a W binion as a pair.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Multiplication}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe multiplication operation is non-trivial. Since the W binions are a parabolic Cayley-Dickson construct, you use the parabolic multiplication operation. If\n\\begin{align}\n    x &= \\begin{pmatrix}\n        x_{0} & x_{1}\n    \\end{pmatrix} & y &= \\begin{pmatrix}\n        y_{0} & y_{1}\n    \\end{pmatrix}\n\\end{align}\nthen\n\\begin{equation}\n    z = x \\wedge y = \\begin{pmatrix}\n        x_{0} y_{0} & y_{1} x_{0} + y_{0} x_{1}\n    \\end{pmatrix}\n\\end{equation}\nNote that this multiplication operation is commutative. Note that\n\\begin{equation}\n    W = \\begin{pmatrix}\n        0 & 1\n    \\end{pmatrix}\n\\end{equation}\nwhich leads to\n\\begin{equation}\n    W \\wedge W = \\begin{pmatrix}\n        0 & 0\n    \\end{pmatrix}\n\\end{equation}\nThat is, $W$ is nilpotent.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Conjugate Operations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThere are many conjugate operations acting on W binions.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Asterisk Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nIf\n\\begin{equation}\n    z = \\begin{pmatrix}\n        z_{0} & z_{1}\n    \\end{pmatrix}\n\\end{equation}\nthen the asterisk conjugation is\n\\begin{equation}\n    {\\ast z} = \\begin{pmatrix}\n        z_{0} & -z_{1}\n    \\end{pmatrix}\n\\end{equation}\nNote that this is an involution.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Quadrance}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nIf\n\\begin{equation}\n    z = \\begin{pmatrix}\n        z_{0} & z_{1}\n    \\end{pmatrix}\n\\end{equation}\nthen the quadrance is given by\n\\begin{equation}\n    \\Vert z \\Vert^{2} = (z_{0})^{2}\n\\end{equation}\nNote that the quadrance takes non-negative values. However, you can have zero-quadrance from a non-trivial W binion. Any W binion of the form\n\\begin{equation}\n    \\begin{pmatrix}\n        0 & z_{1}\n    \\end{pmatrix}\n\\end{equation}\nhas zero quadrance.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Cloak Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nIf\n\\begin{equation}\n    z = \\begin{pmatrix}\n        z_{0} & z_{1}\n    \\end{pmatrix}\n\\end{equation}\nthen the cloak conjugation is\n\\begin{equation}\n    {\\diamond z} = \\begin{pmatrix}\n        -z_{0} & z_{1}\n    \\end{pmatrix}\n\\end{equation}\nNote that this is an involution. Cloak conjugation is equivalent to negation of the asterisk conjugation.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Dagger Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nIf\n\\begin{equation}\n    z = \\begin{pmatrix}\n        z_{0} & z_{1}\n    \\end{pmatrix}\n\\end{equation}\nthen the dagger conjugation is\n\\begin{equation}\n    {\\dagger z} = \\begin{pmatrix}\n        z_{0} & -z_{1}\n    \\end{pmatrix}\n\\end{equation}\nNote that this is equivalent to the asterisk conjugation.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Hodge Star}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nIf\n\\begin{equation}\n    z = \\begin{pmatrix}\n        z_{0} & z_{1}\n    \\end{pmatrix}\n\\end{equation}\nthen the Hodge star is\n\\begin{equation}\n    {\\star z} = \\begin{pmatrix}\n        z_{1} & z_{0}\n    \\end{pmatrix}\n\\end{equation}\nNote that this is an involution.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Zero-Divisors}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nSince multiplication of non-zero W binions can lead to zero, there are non-trivial zero-divisors. For example, if\n\\begin{align}\n    x &= \\begin{pmatrix}\n        0 & x_{1}\n    \\end{pmatrix} & y &= \\begin{pmatrix}\n        0 & y_{1}\n    \\end{pmatrix}\n\\end{align}\nthen\n\\begin{equation}\n    z = x \\wedge y = \\begin{pmatrix}\n        0 & 0\n    \\end{pmatrix}\n\\end{equation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Decompositions}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nWith so many involutions you can have many decomposition.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Asterisk Decomposition}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nSince the asterisk conjugation is an involution, you can have the following decomposition:\n\\begin{equation}\n    z = \\frac{1}{2} \\left( z + {\\ast z} \\right) + \\frac{1}{2} \\left( z - {\\ast z} \\right)\n\\end{equation}\nThe first term is the self-asterisk part of $z$ and the second term is the anti-self-asterisk part of $z$. If\n\\begin{equation}\n    z = \\begin{pmatrix}\n        z_{0} & z_{1}\n    \\end{pmatrix}\n\\end{equation}\nthen the \\textbf{self-asterisk part} of $z$ is given by\n\\begin{equation}\n    \\frac{1}{2} \\left( z + {\\ast z} \\right) = \\begin{pmatrix}\n        z_{0} & 0\n    \\end{pmatrix}\n\\end{equation}\nand the \\textbf{anti-self-asterisk part} of $z$ is given by\n\\begin{equation}\n    \\frac{1}{2} \\left( z - {\\ast z} \\right) = \\begin{pmatrix}\n        0 & z_{1}\n    \\end{pmatrix}\n\\end{equation}\nNote that the anti-self-asterisk part of $z$ is always nilpotent.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Hodge Star Decomposition}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nSince the Hodge star operation is an involution, you can have the following decomposition:\n\\begin{equation}\n    z = \\frac{1}{2} \\left( z + {\\star z} \\right) + \\frac{1}{2} \\left( z - {\\star z} \\right)\n\\end{equation}\nThe first term is the self-star part of $z$ and the second term is the anti-self-star part of $z$. If\n\\begin{equation}\n    z = \\begin{pmatrix}\n        z_{0} & z_{1}\n    \\end{pmatrix}\n\\end{equation}\nthen the \\textbf{self-star part} of $z$ is given by\n\\begin{equation}\n    \\frac{1}{2} \\left( z + {\\star z} \\right) = \\frac{1}{2} (z_{0} + z_{1}) \\begin{pmatrix}\n        1 & 1\n    \\end{pmatrix}\n\\end{equation}\nand the \\textbf{anti-self-star part} of $z$ is given by\n\\begin{equation}\n    \\frac{1}{2} \\left( z - {\\star z} \\right) = \\frac{1}{2} (z_{0} - z_{1}) \\begin{pmatrix}\n        1 & {-1}\n    \\end{pmatrix}\n\\end{equation}\nNote that the self-star and anti-self-star parts are proportional to W binions that are idempotent. If\n\\begin{align}\n    P &\\equiv \\frac{1}{2} \\begin{pmatrix}\n        1 & 1\n    \\end{pmatrix} & Q &\\equiv \\frac{1}{2} \\begin{pmatrix}\n        1 & {-1}\n    \\end{pmatrix}\n\\end{align}\nthen\n\\begin{align}\n    P \\wedge P &= P & Q \\wedge Q &= Q\n\\end{align}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Differential Operators}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nWith two real variables $x$ and $y$, you can define a W binion variable $z$ via\n\\begin{equation}\n    z = \\begin{pmatrix}\n        x & y\n    \\end{pmatrix}\n\\end{equation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{M\\\"{o}bius Transformations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Cross-Ratio}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...", "meta": {"hexsha": "088c024b2b99cacf57a559aaa0859cbafb6d270a", "size": 8118, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/C.tex", "max_stars_repo_name": "meirizarrygelpi/cdc", "max_stars_repo_head_hexsha": "f9c9f027888aa8c05fd58d2fef0b21ee78002b9c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter/C.tex", "max_issues_repo_name": "meirizarrygelpi/cdc", "max_issues_repo_head_hexsha": "f9c9f027888aa8c05fd58d2fef0b21ee78002b9c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter/C.tex", "max_forks_repo_name": "meirizarrygelpi/cdc", "max_forks_repo_head_hexsha": "f9c9f027888aa8c05fd58d2fef0b21ee78002b9c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.7621145374, "max_line_length": 157, "alphanum_fraction": 0.4644000985, "num_tokens": 2084, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7130985174572697}}
{"text": "\\section{Application: Resistor networks}\n\nThe tools of linear algebra can be used to study the application of\nresistor networks. An example of an electrical circuit is below.\n\n\\begin{center}\n  \\scalebox{0.8}{\n    \\begin{circuitikz}[american] \\draw\n      (0,0) to [battery1, v^= $18\\volt$~~] (0,4)\n      (0,0) to [R = $2 \\ohm$] (4,0)\n      to [R = $4 \\ohm$] (4,4)\n      (0,4) to [R =$2 \\ohm$] (4,4)\n      (2,2) node[scale=4]{$\\circlearrowleft$}\n      (2,2) node{$I_1$}\n      ;\n    \\end{circuitikz}\n  }\n\\end{center}\n\n\\noindent\nThe jagged lines (\\begin{circuitikz}[baseline=-0.5ex] \\draw (0,0) to\n  [R] (2,0); \\end {circuitikz}) denote resistors and the numbers next\nto them give their resistance%\n\\index{resistance} in ohms, written as $\\ohm$. The voltage%\n\\index{voltage} source (\\begin{circuitikz}[baseline=-0.5ex] \\draw\n  (0,0) to [/tikz/circuitikz/bipoles/length=0.75cm, battery1]\n  (1,0); \\end {circuitikz}) causes the current%\n\\index{current} to flow in the direction from the longer of the two\nlines toward the shorter\\footnote{By {\\em current}, we always mean the\n  {\\em conventional current}, which flows from plus to minus. It is\n  the opposite of the electron flow, which goes from minus to plus.}.\nVoltage is measured in volts, written as $\\volt$.  The current for a\ncircuit is labelled $I_k$, and is measured in amperes, written as\n$\\amp$.\n\nIn the above figure, the current $I_1$ has been labelled with an arrow\nin the counterclockwise direction. This is an entirely arbitrary\ndecision and we could have chosen to label the current in the\ncounterclockwise direction.  With our choice of direction here, we\ndefine a positive current to flow in the counterclockwise direction\nand a negative current to flow in the clockwise direction.\n\nThe goal of this section is to use the values of resistors and voltage\nsources in a circuit to determine the current. An essential theorem\nfor this application is Kirchhoff's law%\n\\index{Kirchhoff's law}.\n\n\\begin{theorem}{Kirchhoff's law}{kirchhoff-law}\n  The sum of the resistance ($R$) times the amperes ($I$) in the\n  counterclockwise direction around a loop equals the sum of the\n  voltage sources ($V$) in the same direction around the loop.\n\\end{theorem}\n\nKirchhoff's law allows us to set up a system of linear equations and\nsolve for any unknown variables. When setting up this system, it is\nimportant to trace the circuit in the counterclockwise direction. If a\nresistor or voltage source is crossed against this direction, the\nrelated term must be given a negative sign.\n\nWe will explore this in the next example where we determine the value\nof the current in the initial diagram.\n\n\\begin{example}{Solving for current}{solve-current1}\n  Applying Kirchhoff's Law to the diagram below, determine the value for $I_1$.\n\n  \\begin{center}\n    \\scalebox{0.8}{\n      \\begin{circuitikz}[american,scale=0.8] \\draw\n        (0,0) to [battery1, v^= $18\\volt$~~] (0,4)\n        (0,0) to [R = $2 \\ohm$] (4,0)\n        to [R = $4 \\ohm$] (4,4)\n        (0,4) to [R =$2 \\ohm$] (4,4)\n        (2,2) node[scale=4]{$\\circlearrowleft$}\n        (2,2) node{$I_1$}\n        ;\n      \\end{circuitikz}\n    }\n  \\end{center}\n\n\\end{example}\n\n\\begin{solution}\n  Begin in the bottom left corner, and trace the circuit in the\n  counterclockwise direction. At the first resistor, multiplying\n  resistance and current gives $2I_1$. Continuing in this way through\n  all three resistors gives $2I_1 + 4I_1 + 2 I_1$. This must equal the\n  voltage source in the same direction. Notice that the direction of\n  the voltage source matches the counterclockwise direction specified,\n  so the voltage is positive.\n\n  Therefore the equation and solution are given by\n  \\begin{eqnarray*}\n    2I_1 + 4I_1 + 2 I_1 &=& 18, \\\\\n    8I_1 &=& 18, \\\\\n    I_1 &=& \\frac{9}{4} \\amp.\n  \\end{eqnarray*}\n  Since the answer is positive, this confirms that the current flows\n  counterclockwise.\n\\end{solution}\n\n\\begin{example}{Solving for current}{solve-current2}\n  Applying Kirchhoff's Law to the diagram below, determine the value for $I_1$.\n\n  \\begin{center}\n    \\scalebox{0.8}{\n      \\begin{circuitikz}[american,scale=0.8] \\draw\n        (0,0) to [R = $4\\ohm$] (0,4)\n        (2,4) to [battery1, v_= \\raisebox{1ex}{$27\\volt$}] (0,4)\n        (2,4) to [R = $3\\ohm$] (4,4)\n        to [R = $1\\ohm$] (4,0)\n        to [R =$6\\ohm$] (0,0)\n        (2,2) node[scale=4]{$\\circlearrowleft$}\n        (2,2) node{$I_1$}\n        ;\n      \\end{circuitikz}\n    }\n  \\end{center}\n\n\\end{example}\n\n\\begin{solution}\n  Begin in the top left corner this time, and trace the circuit in the\n  counterclockwise direction. At the first resistor, multiplying\n  resistance and current gives $4I_1$. Continuing in this way through\n  the four resistors gives $4I_1 + 6I_1 + 1 I_1 + 3I_1$. This must\n  equal the voltage source in the same direction. Notice that the\n  direction of the voltage source is opposite to the counterclockwise\n  direction, so the voltage is negative.\n\n  Therefore the equation and solution are given by\n  \\begin{eqnarray*}\n    4I_1 + 6I_1 + 1 I_1 + 3I_1&=& -27, \\\\\n    14I_1 &=& -27, \\\\\n    I_1 &=& -\\frac{27}{14} \\amp.\n  \\end{eqnarray*}\n  Since the answer is negative, this tells us that the current flows\n  clockwise.\n\\end{solution}\n\nA more complicated example follows. Two of the circuits below may be\nfamiliar; they were examined in the examples above. However as they\nare now part of a larger system of circuits, the answers will differ.\n\n\\begin{example}{Unknown currents}{unknown-current}\n  The diagram below consists of four circuits. The current ($I_k$) in\n  the four circuits is denoted by $I_1$, $I_2$, $I_3$, $I_4$. Using\n  Kirchhoff's Law, write an equation for each circuit and solve for\n  each current.\n\n  \\begin{center}\n    \\scalebox{0.8}{\n      \\begin{circuitikz}[american, scale=0.7] \\draw\n        (0,0) to [battery1, v^= $18\\volt$~~] (0,4)\n        (0,0) to [R = $2 \\ohm$] (4,0)\n        to [R = $4 \\ohm$] (4,4)\n        (0,4) to [R =$2 \\ohm$] (4,4)\n        (6,4) to [battery1, v_= \\raisebox{1ex}{$27\\volt$}] (4,4)\n        (6,4) to [R = $3 \\ohm$] (8,4)\n        to [R = $1 \\ohm$] (8,0)\n        (4,0) to [R = $6 \\ohm$] (8,0)\n        to [R = $2 \\ohm$] (8,-4)\n        to [R = $3 \\ohm$] (4,-4)\n        to [R = $1 \\ohm$] (4,0)\n        (4,-4)to [R = $5 \\ohm$] (0,-4)\n        (0,0) to [battery1, v_= $23\\volt$~~] (0,-4)\n        (2,2) node[scale=3]{$\\circlearrowleft$}\n        (2,2) node{$I_2$}\n        (6,2) node[scale=3]{$\\circlearrowleft$}\n        (6,2) node{$I_3$}\n        (6,-2) node[scale=3]{$\\circlearrowleft$}\n        (6,-2) node{$I_4$}\n        (2,-2) node[scale=3]{$\\circlearrowleft$}\n        (2,-2) node{$I_1$}\n        ;\n      \\end{circuitikz}\n    }\n  \\end{center}\n\\end{example}\n\n\\begin{solution}\n  Starting with the top left circuit, multiply the resistance by the\n  current and sum the resulting products. Specifically, consider the\n  resistor labelled $2 \\ohm$ that is part of the circuits of $I_1$ and\n  $I_2$. Notice that current $I_2$ runs through this in a positive\n  (counterclockwise) direction, and $I_1$ runs through in the opposite\n  (negative) direction. The product of resistance and current is then\n  $2 (I_2 - I_1) = 2I_2 - 2I_1$.  Continue in this way for each\n  resistor, and set the sum of the products equal to the voltage\n  source to write the equation:\n  \\begin{equation*}\n    2I_2-2I_1+4I_2-4I_3+2I_2=18.\n  \\end{equation*}\n  The above process is used on each of the other three circuits, and\n  the resulting equations are:\n\n  \\noindent\n  Upper right circuit:\n  \\begin{equation*}\n    4I_3 - 4I_2 + 6I_3 - 6I_4 + I_3 + 3I_3 = -27.\n  \\end{equation*}\n  Lower right circuit:\n  \\begin{equation*}\n    3I_4 + 2I_4 + 6I_4 - 6I_3 + I_4 - I_1 = 0.\n  \\end{equation*}\n  Lower left circuit:\n  \\begin{equation*}\n    5I_1+I_1-I_4+2I_1-2I_2=-23.\n  \\end{equation*}\n\n  Notice that the voltage for the upper right and lower left circuits\n  are negative due to the clockwise direction they indicate. The\n  resulting system has four equations in four variables.  Simplifying\n  and rearranging with variables in order, we have:\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      -2I_1+8I_2-4I_3&=&18, \\\\\n      - 4I_2 + 14I_3 - 6I_4 &=& -27, \\\\\n      -I_1 - 6I_3 + 12I_4 &=& 0, \\\\\n      8I_1-2I_2 - I_4 &=& -23.\n    \\end{array}\n  \\end{equation*}\n  The augmented matrix is\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrr|r}\n      -2 & 8 & -4 & 0 & 18 \\\\\n      0 & -4 & 14 & -6 & -27 \\\\\n      -1 & 0 & -6 & 12 & 0 \\\\\n      8 & -2 & 0 & -1 & -23\n    \\end{mymatrix}.\n  \\end{equation*}\n  The solution to this system of equations is\n  \\begin{eqnarray*}\n    I_1 &=& -3 \\amp, \\\\\n    I_2 &=& \\frac{1}{4} \\amp, \\\\\n    I_3 &=& -\\frac{5}{2} \\amp, \\\\\n    I_4 &=& -\\frac{3}{2} \\amp.\n  \\end{eqnarray*}\n  This tells us that currents $I_1, I_3$, and $I_4$ travel clockwise\n  while $I_2$ travels counterclockwise.\n\\end{solution}\n", "meta": {"hexsha": "f1ce3a0e49b40486069b8422c83703482e63ffe7", "size": 8809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/SystemsofEquations-Application-ResistorNetworks.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/SystemsofEquations-Application-ResistorNetworks.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/SystemsofEquations-Application-ResistorNetworks.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 36.5518672199, "max_line_length": 79, "alphanum_fraction": 0.6499035078, "num_tokens": 3079, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059462938815, "lm_q2_score": 0.8991213833519948, "lm_q1q2_score": 0.7130985155764477}}
{"text": "\\subsection{Harmonic Functions}\r\nBy the open mapping theorem, a non-constant function $u:D\\to\\mathbb R$ where $D$ is a domain cannot be analytic.\r\nHowever, it can be harmonic\r\n\\begin{definition}\r\n    Let $D\\subset\\mathbb C$ be a domain.\r\n    A smooth function $u:D\\to\\mathbb R$ is harmonic if\r\n    $$\\nabla^2 u=\\frac{\\partial^2u}{\\partial x^2}+\\frac{\\partial^2u}{\\partial y^2}=0$$\r\n\\end{definition}\r\n\\begin{lemma}\\label{harmonic_disk}\r\n    Consider a disk $D\\subset\\mathbb C$, a function $u:D\\to\\mathbb R$ is harmonic iff $u=\\operatorname{Re}(f)$ for an analytic $f$ on $D$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    The ``if'' direction is trivial by the Cauchy-Riemann Equations.\r\n    The ``only if'' direction is exercise.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $R$ be a Riemann surface.\r\n    A function $u\\to\\mathbb R$ is harmonic if for any chart $(\\phi,U)$ on $R$ the composition\r\n    $$u\\circ\\phi^{-1}:U\\to\\mathbb R$$\r\n    is harmonic.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    A real function $u$ on $R$ is harmonic iff for any $p\\in R$ there exists one chart $(\\phi,U)$ on $R$ such that $u\\circ\\phi^{-1}$ is harmonic.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    The ``only if'' direction is trivial.\r\n    For the ``if'' direction, we know from Lemma \\ref{harmonic_disk} that for any $p\\in R$, there is a chart $(\\phi,U)$ with $p\\in U$ such that $u\\circ\\phi^{-1}=\\operatorname{Re}f$ for some analytic $f$ on a disk contained in $\\phi(U)$.\r\n    Hence for any chart $(\\psi,V)$ and any $p\\in V$, let $(\\phi,U)$ be as above,\r\n    $$u\\circ\\psi^{-1}=(u\\circ\\phi^{-1})\\circ(\\phi\\circ\\psi^{-1})=\\operatorname{Re}(f\\circ(\\phi\\circ\\psi^{-1}))$$\r\n    is harmonic near $p$.\r\n    Hence $u$ is harmonic.\r\n\\end{proof}\r\n\\begin{proposition}[Identity Principle for Harmonic Functions]\r\n    Let $u,v$ be harmonic functions on a Riemann surface $R$.\r\n    Then the set $\\{p\\in R:u(p)=v(p)\\}$ is either $R$ or discrete.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Exercise.\r\n\\end{proof}\r\n\\begin{theorem}[Open Mapping Theorem for Harmonic Functions]\r\n    Any non-constant harmonic function $u$ on a Riemann surface $R$ is an open map.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $W\\subset R$ be open and $p\\in W$.\r\n    For small enough $U\\ni p$ that is contained in $W$ there is a chart $\\phi:U\\to\\mathbb C$ and analytic $f$ such that $u\\circ\\phi^{-1}=\\operatorname{Re}f$.\r\n    The theorem then follows from the identity principle and open mapping theorem for analytic functions.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $R$ is a compact Riemann surface, all harmonic functions on $R$ are constant.\r\n\\end{corollary}\r\n", "meta": {"hexsha": "a21be4bc9842641360d294581ce9d7e7d8e69559", "size": 2570, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/harmonic.tex", "max_stars_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_stars_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/harmonic.tex", "max_issues_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_issues_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/harmonic.tex", "max_forks_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_forks_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.3921568627, "max_line_length": 237, "alphanum_fraction": 0.6653696498, "num_tokens": 819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223264, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7130610412799723}}
{"text": "% !TeX root = constructions.tex\n\n\\chapter{A Compass is Sufficient}\\label{c.compass-only}\n\nIn 1797 the Italian mathematician Lorenzo Mascheroni proved that any construction carried out with a compass and straightedge can be carried out with the compass alone! Later it came to light that the construction had already been discovered by the Danish mathematician Georg Mohr 1672. The theorem is now called the Mohr-Mascheroni Theorem.\n\nIn this chapter I present a proof of the theorem based on the proof in problem 33 of \\cite{dorrie1} and reworked by  Michael Woltermann \\cite{dorrie2}.\\footnote{I would like to thank Woltermann for permission to use his work.} A different  proof can be found in \\cite{mm}.\n\nWhat does it mean to perform a construction with only a compass? The right diagram below shows the construction of an equilateral triangle using a straightedge and compass. How can we construct a triangle without the line segments $\\overline{AB}, \\overline{AC}, \\overline{BC}$? In fact, there is no need to \\emph{see} the lines. A line is defined by two points, so it is sufficient to construct the points in order to obtain a construction equivalent to the one with a straightedge (left diagram):\n\\begin{center}\n\\begin{tikzpicture}[scale=0.6]\n\\coordinate (A) at (0,0);\n\\coordinate (B) at (4,0);\n\\path (A) node[below left] {$A$} -- (B) node[below right] {$B$};\n\\fill (A) circle[radius=3pt];\n\\fill (B) circle[radius=3pt];\n\\draw[name path=larc] (A) ++(-10:4cm) arc (-10:80:4cm);\n\\draw[name path=rarc] (B) ++(-170:4cm) arc (-170:-260:4cm);\n\\path [name intersections={of=larc and rarc,by={t}}];\n\\fill (t) node[above right,xshift=-2pt,yshift=3pt] {$C$} circle[radius=3pt];\n\\begin{scope}[xshift=10cm]\n\\coordinate (A) at (0,0);\n\\coordinate (B) at (4,0);\n\\draw (A) node[below left] {$A$} -- (B) node[below right] {$B$};\n\\fill (A) circle[radius=3pt];\n\\fill (B) circle[radius=3pt];\n\\draw[name path=larc] (A) ++(-10:4cm) arc (-10:80:4cm);\n\\draw[name path=rarc] (B) ++(-170:4cm) arc (-170:-260:4cm);\n\\path [name intersections={of=larc and rarc,by={t}}];\n\\fill (t) node[above right,xshift=-2pt,yshift=3pt] {$C$} circle[radius=3pt];\n\\draw (A) -- (t);\n\\draw (B) -- (t);\n\\end{scope}\n\\end{tikzpicture}\n\\end{center}\nIn the diagrams we will draw lines, but they are used only to understand the construction and the proof of its correctness. It is important that you convince yourself that the construction itself uses only a compass.\n\nA construction by straightedge and compass is a sequence taken from these three operations:\n\\begin{itemize}\n\\item Find the point of intersection of two straight lines.\n\\item Find the point of intersection of a straight line and a circle.\n\\item Find the point(s) of intersection of two circles.\n\\end{itemize}\nIt is clear that the third operation can be done with only a compass. We need to show that the first two operations can be done with a compass alone.\n\nNotation:\n\\begin{itemize}\n\\item $c(O,A)$: the circle with center $O$ through point $A$.\n\\item $c(O,r)$: the circle with center $O$ and radius $r$.\n\\item $c(O,AB)$: the circle with center $O$ and radius the length of line segment $\\overline{AB}$.\n\\end{itemize}\n\nFirst we will solve four preliminary problems (Sections~\\ref{s.reflection}--\\ref{s.three}). Next, we show the construction for finding the intersection of two lines (Section~\\ref{s.two-lines}), and finally the construction of the intersection of a line and a circle (Section~\\ref{s.line-circle}).\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Reflection of a point}\\label{s.reflection}\n\n\\textbf{Given a line $\\overline{AB}$ and a point $C$ not on $\\overline{AB}$, build a point $C'$ which is a reflection of $C$ about $\\overline{AB}$.}\n\n$C'$ is a \\emph{reflection} about a line segment $\\overline{AB}$ if $\\overline{AB}$ (or the line containing $\\overline{AB}$) is the perpendicular bisector of the line $CC'$.\n\nConstruct a circle centered on $A$ passing through $C$ and circle centered on $B$ passing through $C$. The intersection of the two circles is the point $C'$ which is the reflection of $C$.\n\\begin{center}\n\\begin{tikzpicture}[scale=.65]\n\\coordinate (A) at (0,0);\n\\coordinate (B) at (4,0);\n\\coordinate (C) at (2.5,1.5);\n\\draw[thick,dashed] ($(B)!2!(A)$) -- ($(A)!2!(B)$);\n\\fill (A) node[above left] {$A$} circle[radius=2pt];\n\\fill (B) node[above right] {$B$} circle[radius=2pt];\n\\fill (C) node[above,yshift=4pt] {$C$} circle[radius=2pt];\n\\node[draw,circle through=(C),name path=ac] at (A) {};\n\\node[draw,circle through=(C),name path=bc] at (B) {};\n\\path [name intersections={of=ac and bc,by={x1,Cp}}];\n\\fill (Cp) node[below,yshift=-4pt] {$C'$} circle[radius=2pt];\n\\draw (C) -- (Cp);\n\\draw[thick,dashed] (A) -- (C);\n\\draw[thick,dashed] (B) -- (C);\n\\draw[thick,dashed] (A) -- (Cp);\n\\draw[thick,dashed] (B) -- (Cp);\n\\end{tikzpicture}\n\\end{center}\n\\textbf{Proof:} $\\triangle ABC \\cong \\triangle ABC'$ by side-side-side since $\\overline{AC}, \\overline{AC'}$ are radii of the same circle as are $\\overline{BC}, \\overline{BC'}$, and $\\overline{AB}$ is a common side. Therefore, $\\angle CAB = \\angle C'AB$ so $\\overline{AB}$ is the angle bisector of $\\angle CAC'$. But $\\triangle CAC'$ is an isosceles triangle and the angle bisector $\\overline{AB}$ is also the perpendicular bisector of the base of $\\triangle CAC'$. By definition $C'$ is the reflection of $C$ around $\\overline{AB}$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Construct a circle with a given radius}\\label{s.circle}\n\n\\textbf{Given points $A,B,C$, construct $c(A,BC)$.}\n\nConstruct $c(A,B)$ and $c(B,A)$ and let $X$ and $Y$ be their points of intersection.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.55]\n\\coordinate (A) at (0,1.5);\n\\coordinate (B) at (0,-1.5);\n\\coordinate (C) at (1.5,-3);\n\\coordinate (Cp) at (1.5,3);\n\\fill (A) node[above] {$A$} circle[radius=3pt];\n\\fill (B) node[below] {$B$} circle[radius=3pt];\n\\fill (C) node[below] {$C$} circle[radius=3pt];\n%\\fill (Cp) node[above] {$C'$} circle[radius=3pt];\n\\node[draw,circle through=(B),name path=ab] at (A) {};\n\\node[draw,circle through=(A),name path=ba] at (B) {};\n\\path [name intersections={of=ab and ba,by={Y,X}}];\n\\fill (X) node[above right,xshift=4pt] {$X$} circle[radius=3pt];\n\\fill (Y) node[above left,xshift=-4pt] {$Y$} circle[radius=3pt];\n\\draw[thick,dashed] ($(X)!2.3!(Y)$) -- ($(Y)!2!(X)$);\n\\end{tikzpicture}\n\\vspace*{-6pt}\n\\end{center}\n\n\\newpage\n\nConstruct $C'$, the reflection of $C$ about line $\\overline{XY}$ as described in Section~\\ref{s.reflection}.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.45]\n\\coordinate (A) at (0,1.5);\n\\coordinate (B) at (0,-1.5);\n\\coordinate (C) at (1.5,-3);\n\\coordinate (Cp) at (1.5,3);\n\\fill (A) node[right] {$A$} circle[radius=3pt];\n\\fill (B) node[right] {$B$} circle[radius=3pt];\n\\fill (C) node[below,yshift=-2pt] {$C$} circle[radius=3pt];\n\\fill (Cp) node[above,xshift=2pt,yshift=2pt] {$C'$} circle[radius=3pt];\n\\node[circle through=(B),name path=ab] at (A) {};\n\\node[circle through=(A),name path=ba] at (B) {};\n\\path [name intersections={of=ab and ba,by={Y,X}}];\n\\fill (X) node[above right,xshift=4pt] {$X$} circle[radius=3pt];\n\\fill (Y) node[above left,xshift=-4pt] {$Y$} circle[radius=3pt];\n\\node[draw,circle through=(C)] at (X) {};\n\\node[draw,circle through=(C)] at (Y) {};\n\\draw[thick,dashed] ($(X)!2.3!(Y)$) -- ($(Y)!2!(X)$);\n%\\draw (X) -- (Y) -- (C) -- (X) -- (Cp) -- (Y);\n\\draw[thick,dashed] (C) -- (Cp);\n\\end{tikzpicture}\n\\vspace*{-6pt}\n\\end{center}\n\n$c(A,C')$ is the desired circle.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.5]\n\\coordinate (A) at (0,1.5);\n\\coordinate (B) at (0,-1.5);\n\\coordinate (C) at (1.5,-3);\n\\coordinate (Cp) at (1.5,3);\n\\fill (A) node[above,yshift=2pt] {$A$} circle[radius=3pt];\n\\fill (B) node[below,yshift=-2pt] {$B$} circle[radius=3pt];\n\\fill (C) node[below,yshift=-2pt] {$C$} circle[radius=3pt];\n\\fill (Cp) node[above,yshift=2pt] {$C'$} circle[radius=3pt];\n\\node[circle through=(B),name path=ab] at (A) {};\n\\node[circle through=(A),name path=ba] at (B) {};\n\\path [name intersections={of=ab and ba,by={Y,X}}];\n\\fill (X) node[above right,xshift=4pt] {$X$} circle[radius=3pt];\n\\fill (Y) node[above left,xshift=-4pt] {$Y$} circle[radius=3pt];\n\\node[circle through=(C)] at (X) {};\n\\node[draw,circle through=(C)] at (Y) {};\n\\draw[thick,dashed] ($(X)!2.3!(Y)$) -- ($(Y)!2!(X)$);\n\\path[name path=xy] (X) -- (Y);\n\\node[draw,thick,circle through=(Cp)] at (A) {};\n\\draw[very thick] (A) -- (Cp);\n\\draw[very thick] (B) -- (C);\n\\draw[very thick,name path=abline] (A) -- (B);\n\\draw[very thick,name path=ccp] (C) -- (Cp);\n\\path [name intersections={of=xy and abline,by={D}}];\n\\path [name intersections={of=xy and ccp,by={E}}];\n\\fill (D) node[above left] {$D$} circle[radius=3pt];\n\\fill (E) node[below right] {$E$} circle[radius=3pt];\n\\draw[thick,dashed] (D) -- (Cp);\n\\draw[thick,dashed] (D) -- (C);\n\\draw (D) rectangle +(10pt,10pt);\n\\draw (E) rectangle +(10pt,10pt);\n\\end{tikzpicture}\n\\vspace*{-4pt}\n\\end{center}\n\n\\textbf{Proof:} $A$ is the reflection of $B$ around $\\overline{XY}$ (since $\\triangle YAX\\cong \\triangle YBX$) and $C'$ is the reflection of $C$ around the $\\overline{XY}$. By definition, $\\overline{XY}$ is the perpendicular bisector of $\\overline{CC'}$ and $\\overline{AB}$, so $\\overline{C'E}=\\overline{EC}$, $\\overline{AD}=\\overline{DB}$ and $\\angle DEC=\\angle DEC'$ are right angles. $\\triangle DEC\\cong\\triangle DEC'$ by side-angle-side, so $\\overline{DC}=\\overline{DC'}$ and $\\angle ADC'=\\angle BDC$ (they are complementary to $\\angle EDC'$, $\\angle EDC$). Therefore, $\\triangle ADC'\\cong\\triangle BDC$ by side-angle-side, so $\\overline{AC'}=\\overline{BC}$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Addition and subtraction of line segments}\\label{s.add-subtract}\n\n\\textbf{Given line segment $\\overline{PQ}$ of length $a$ and line segment $\\overline{RS}$ of length $b$, construct line segments $\\overline{QT}, \\overline{QU}$ such that $\\overline{PUQT}$ is a line segment, where the length of $\\overline{PU}$ is $a-b$ and the length of $\\overline{PT}$ is $a+b$.}\n\\begin{center}\n\\begin{tikzpicture}[scale=.8]\n\\draw (0,0) -- (5,0);\n\\fill (0,0) node[above] {$P$} circle[radius=2pt];\n\\fill (5,0) node[above left] {$Q$} circle[radius=2pt];\n\\fill (3,0) node[above left] {$U$} circle[radius=2pt];\n\\fill (7,0) node[above right] {$T$} circle[radius=2pt];\n\\draw[thick,dashed] (5,0) -- (8,0);\n\\draw (5,0) circle[radius=2cm];\n\\draw[thick,dashed] (5,0) -- node[left] {$b$} ++(60:2cm);\n\\draw (9,-1) node[above] {$R$} -- node[below right] {$b$} ++(20:2cm) node[above] {$S$};\n\\fill (9,-1) circle[radius=2pt];\n\\fill (9,-1) ++(20:2cm) circle[radius=2pt];\n\\draw[<->] (0,-.5) -- node[fill=white] {$a$} (5,-.5);\n\\draw[<->] (0,-1) -- node[fill=white] {$a-b$} (3,-1);\n\\draw[<->] (0,-1.5) -- node[fill=white] {$a+b$} (7,-1.5);\n\\end{tikzpicture}\n\\end{center}\n\n\\newpage\n\n\\subsection*{Constructing an isosceles trapezoid}\n\nLet $H$ be any point on $c(Q,b)$. Construct $H'$, its reflection about $\\overline{PQ}$. $h$ is the length of $\\overline{HH'}$:\n\n\\vspace{-1ex}\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.6]\n\\coordinate (Q) at (0,0);\n\\coordinate (P) at (-6.8,0);\n\\coordinate (B) at (-3,-2);\n\\draw[thick,dashed] ($(Q)!1.3!(P)$) -- node[above,near start] {$a$} ($(P)!2.3!(Q)$);\n\\fill (Q) node[above left] {$Q$} circle[radius=2pt];\n\\fill (P) node[above] {$P$} circle[radius=2pt];\n\\fill (B) circle[radius=2pt];\n\\node[draw,circle through=(B),name path=qb] at (Q) {};\n\\draw[thick,dashed] (Q) -- node[left,xshift=-1pt,yshift=2pt] {$b$} (B);\n\\path[name path=qh] (Q) -- (-40:5cm);\n\\path[name path=qhp] (Q) -- (40:5cm);\n\\path [name intersections={of=qb and qh,by={H}}];\n\\path [name intersections={of=qb and qhp,by={Hp}}];\n\\fill[below right] (H) node[right,xshift=2pt] {$H$} circle[radius=2pt];\n\\fill[above right] (Hp) node[right,xshift=2pt] {$H'$} circle[radius=2pt];\n\\draw[thick,dashed] (H) -- node[below left,yshift=-2pt] {$h$} (Hp);\n\\end{tikzpicture}\n\\end{center}\n\n\\vspace{-2ex}\n\nConstruct the circles $c(H,b)$, $c(Q,h)$. Let $K$ be the intersection of the circles and construct $K'$, the reflection of $K$ about line $\\overline{PQ}$:\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.55]\n\\coordinate (Q) at (0,0);\n\\coordinate (P) at (-6.8,0);\n\\coordinate (B) at (-3,-2);\n\\draw[thick,dashed] ($(Q)!1.3!(P)$) -- ($(P)!2.3!(Q)$);\n\\fill (Q) node[above right,xshift=6pt] {$Q$} circle[radius=3pt];\n\\fill (P) node[above] {$P$} circle[radius=3pt];\n\\fill (B) circle[radius=3pt];\n\\node[draw,circle through=(B),name path=qb] at (Q) {};\n\\draw[thick,dashed] (Q) -- node[left,xshift=-1pt,yshift=2pt] {$b$} (B);\n\\path[name path=qh] (Q) -- (-40:5cm);\n\\path[name path=qhp] (Q) -- (40:5cm);\n\\path [name intersections={of=qb and qh,by={Hp}}];\n\\path [name intersections={of=qb and qhp,by={H}}];\n\\fill (H) node[right,xshift=2pt] {$H$} circle[radius=3pt];\n\\fill (Hp) node[right,xshift=2pt] {$H'$} circle[radius=3pt];\n\\draw (H) -- node[below left,yshift=-3pt] {$h$} (Hp);\n\n\\draw (H|-Q) rectangle +(10pt,10pt);\n\\fill (H|-Q) circle(3pt) node[above left] {$Q'$};\n\n\\draw[thick,name path=circleqh] (Q) let\n  \\p1 = ($ (H) - (Hp) $),\n  \\n2 = {veclen(\\x1,\\y1)}\nin\n  circle (\\n2)\n  (Q) edge [dashed] node[below] {$h$} +(140:\\n2) ++(140:\\n2) coordinate (q);\n\\fill (q) circle[radius=3pt];\n\\draw[thick,name path=circlehb] (H) let\n  \\p1 = ($ (Q) - (B) $),\n  \\n2 = {veclen(\\x1,\\y1)}\nin\n  circle (\\n2)\n  (H) edge [dashed] node[below,near end] {$b$} +(50:\\n2) ++(50:\\n2)  coordinate (h);\n\\fill (h) circle[radius=3pt];\n\\path [name intersections={of=circleqh and circlehb,by={K}}];\n\\fill (K) node[above left] {$K$} circle[radius=3pt];\n%\\draw[thick] (H) -- (K);\n\\draw let\n  \\p1 = ($ (K) - (Q) $)\nin\n  coordinate (Kp) at (\\x1,-\\y1);\n\\fill (Kp) node[below left] {$K'$} circle[radius=3pt];\n\\draw (K) -- (Kp);\n\\draw (Q) rectangle +(10pt,10pt);\n\\end{tikzpicture}\n\\vspace*{-8pt}\n\\end{center}\n\n$\\overline{PQ}$ is the perpendicular bisector of both $\\overline{HH'}$ and $\\overline{KK'}$, so these line segments are parallel. $\\overline{KH}=b$ since it is the radius of the circle centered on $H$. $K',H'$ are reflections of $K,H$ and it is not hard to show that $\\overline{K'H'}=\\overline{KH}$ ($\\triangle QQ'H\\cong \\triangle QQ'H'$ and then $\\triangle KQH\\cong \\triangle K'QH'$). Therefore, $\\overline{KHH'K'}$ is an isosceles trapezoid whose bases are $\\overline{HH'}=h$, $\\overline{KK'}=2h$. Let $d$ be the length of the diagonals $\\overline{K'H}=\\overline{KH'}$:\n\n\n\\begin{center}\n\\vspace*{-8pt}\n\\begin{tikzpicture}[scale=.6]\n\\coordinate (Q) at (0,0);\n\\coordinate (P) at (-6.8,0);\n\\coordinate (B) at (-3,-2);\n\\draw[thick,dashed] ($(Q)!1.3!(P)$) -- ($(P)!2.3!(Q)$);\n\\fill (Q) node[above left] {$Q$} circle[radius=3pt];\n\\fill (P) node[above] {$P$} circle[radius=3pt];\n%\\fill (B) circle[radius=3pt];\n\\node[draw,circle through=(B),name path=qb] at (Q) {};\n%\\draw[thick,dashed] (Q) -- node[left,xshift=-1pt,yshift=2pt] {$b$} (B);\n\\path[name path=qh] (Q) -- (-40:5cm);\n\\path[name path=qhp] (Q) -- (40:5cm);\n\\path [name intersections={of=qb and qh,by={Hp}}];\n\\path [name intersections={of=qb and qhp,by={H}}];\n\\fill (H) node[right,xshift=2pt] {$H$} circle[radius=3pt];\n\\fill (Hp) node[right,xshift=2pt] {$H'$} circle[radius=3pt];\n\\draw (H) -- node[below right,yshift=-2pt] {$h$} (Hp);\n\\path[name path=circleqh] (Q) let\n  \\p1 = ($ (H) - (Hp) $)\nin\n  circle ({veclen(\\x1,\\y1)});\n\\path[name path=circlehb] (H) let\n  \\p1 = ($ (Q) - (B) $)\nin\n  circle ({veclen(\\x1,\\y1)});\n\\path [name intersections={of=circleqh and circlehb,by={K,k2}}];\n\\fill (K) node[above left] {$K$} circle[radius=3pt];\n\\draw (Q) -- node[left] {$h$} (K);\n\\draw (H) -- node[right,xshift=4pt] {$b$} (K);\n\\draw let\n  \\p1 = ($ (K) - (Q) $)\nin\n  coordinate (Kp) at (\\x1,-\\y1);\n\\fill (Kp) node[below left] {$K'$} circle[radius=3pt];\n\\draw (Q) -- node[left] {$h$} (Kp) -- node[right,xshift=2pt,yshift=-2pt] {$b$} (Hp);\n\\draw (K) -- node[above right] {$d$} (Hp);\n\\draw (Kp) -- node[left] {$d$} (H);\n\\end{tikzpicture}\n\\label{ptolemy}\n\\vspace*{-8pt}\n\\end{center}\n\n\\subsection*{Circumscribing the trapezoid by a circle}\n\nWe want to proof that it is possible to circumscribe $\\overline{KHH'K'}$ by a circle. We will prove that: if the opposite angles of a quadrilateral are supplementary, then the trapezoid can be circumscribed by a circle, and that in an isosceles trapezoid the opposite angles are supplementary. Geometry textbooks give the simple proof that the opposite angles of a quadrilateral circumscribed by a circle are supplementary, but it is hard to find a proof of the converse, so I present both proofs here.\n\n\\textbf{If a quadrilateral can be circumscribed by a circle then the opposite angles are supplementary:} An inscribed angle equals half the subtended arc, so $\\angle DAB$ is half of the arc $\\widehat{DCB}$ and $\\angle DCB$ is half of the arc $\\widehat{DAB}$. The two arcs subtend the entire circumference of the circle, so their sum is $360^\\circ$. Therefore, $\\angle DAB + \\angle DCB = \\disfrac{1}{2} \\cdot 360^\\circ =  180^\\circ$, and similarly $\\angle ADC + \\angle ABC = 180^\\circ$\n\n\\vspace*{-2ex}\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.55]\n\\coordinate (origin) at (0,0);\n\\coordinate (A) at (1,3);\n\\node[draw,circle through=(A),name path=circle] at (origin) {};\n\\fill (A) node[above right] {$A$} circle[radius=3pt];\n\\path[name path=b] (A) -- (-50:4.5cm);\n\\path[name path=c] (A) -- (-120:4.5cm);\n\\path[name path=d] (A) -- (150:4.5cm);\n\\path [name intersections={of=circle and b,by={b1,B}}];\n\\fill (B) node[right] {$B$} circle[radius=3pt];\n\\path [name intersections={of=circle and c,by={c1,C}}];\n\\fill (C) node[below left] {$C$} circle[radius=3pt];\n\\path [name intersections={of=circle and d,by={d1,D}}];\n\\fill (D) node[above left] {$D$} circle[radius=3pt];\n\\draw (A) -- (B) -- (C) -- (D) -- cycle;\n\\end{tikzpicture}\n\\end{center}\n\n\\vspace*{-2ex}\n\n\\textbf{A quadrilateral whose opposite angles are supplementary can be circumscribed by a circle:} Any triangle can be circumscribed by a circle. Circumscribe $\\triangle DAB$ by a circle and suppose that $C'$ is a point such that $\\angle DAB + \\angle DC'B = 180^\\circ$, but $C'$ is \\emph{not} on the circumference of the circle. Without loss of generality, let $C'$ be within the circle:\n\n\\vspace*{-1ex}\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.55]\n\\coordinate (origin) at (0,0);\n\\coordinate (A) at (1,3);\n\\node[draw,circle through=(A),name path=circle] at (origin) {};\n\\fill (A) node[above right] {$A$} circle[radius=3pt];\n\\path[name path=b] (A) -- (-50:4cm);\n\\path[name path=c] (A) -- (-120:4cm);\n\\path[name path=d] (A) -- (150:4cm);\n\\path [name intersections={of=circle and b,by={b1,B}}];\n\\fill (B) node[right] {$B$} circle[radius=3pt];\n\\path [name intersections={of=circle and c,by={c1,C}}];\n\\fill (C) node[below left] {$C$} circle[radius=3pt];\n\\path [name intersections={of=circle and d,by={d2,D}}];\n\\fill (D) node[above left] {$D$} circle[radius=3pt];\n\\coordinate (Cp) at ($(C)!.2!(D)$);\n\\draw (A) -- (B) -- (Cp) -- (D) -- cycle;\n\\fill (Cp) node[left,xshift=1pt,yshift=2pt] {$C'$} circle[radius=3pt];\n\\draw[thick,dashed] (D) -- (B) -- (C) -- (Cp);\n\\end{tikzpicture}\n\\end{center}\n\n\\vspace*{-1ex}\n\nConstruct a ray that extends $\\overline{DC'}$ and let $C$ be its intersection with the circle. $\\overline{ABCD}$ is circumscribed by a circle so:\n\\begin{eqnarray*}\n\\angle DAB + \\angle DCB &=& 180^\\circ\\\\\n\\angle DAB + \\angle DCB &=& \\angle DAB + \\angle DC'B\\\\\n\\angle DCB &=& \\angle DC'B\\,,\n\\end{eqnarray*}\nwhich is impossible if $C$ is on the circle and $C'$ is inside the circle.\n\n\\newpage\n\nFinally, we show that the opposite angles of an isosceles trapezoid are supplementary.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.55]\n\\coordinate (origin) at (0,0);\n\\coordinate (A) at (2.5,1.8);\n\\node[circle through=(A),name path=circle] at (origin) {};\n\\fill (A) node[above right] {$A$} circle[radius=3pt];\n\\path[name path=b] (A) -- ++(-80:4cm);\n\\path[name path=d] (A) -- ++(180:6cm);\n\\path [name intersections={of=circle and b,by={b1,B}}];\n\\fill (B) node[below right] {$B$} circle[radius=3pt];\n\\path [name intersections={of=circle and d,by={d1,D}}];\n\\fill (D) node[above left] {$D$} circle[radius=3pt];\n\\path[name path=c] (D) -- ++(-100:4cm);\n\\path [name intersections={of=circle and c,by={c1,C}}];\n\\fill (C) node[below left] {$C$} circle[radius=3pt];\n\\draw (A) -- node[right,xshift=8pt] {$x$} (B);\n\\draw[name path=bc] (B) -- node[below] {$y$} (C);\n\\draw (C) -- node[left,xshift=-8pt] {$x$} (D) -- node[above] {$y$} (A);\n\\path[name path=para] (A) -- ++(-100:4cm);\n\\path [name intersections={of=para and bc,by={Bp}}];\n\\fill (Bp) node[below left] {$B'$} circle[radius=3pt];\n\\draw[thick,dashed] (A) -- node[left,xshift=-2pt] {$x$} (Bp);\n\\end{tikzpicture}\n\\end{center}\n\n\\vspace{-4ex}\n\nConstruct the line $\\overline{AB'}$ parallel to $\\overline{CD}$. $\\overline{AB'CD}$ is a parallelogram and $\\triangle ABB'$ is an isosceles triangle, so $\\angle C= \\angle ABB' = \\angle AB'B = \\angle B$. Similarly, $\\angle A = \\angle D$. Since the sum of the internal angles of any quadrilateral is equal to $360^\\circ$:\n\\begin{eqnarray*}\n\\angle A + \\angle B + \\angle C + \\angle D &=& 360^\\circ\\\\\n2\\angle A + 2 \\angle C &=& 360^\\circ\\\\\n\\angle A +  \\angle C &=& 180^\\circ\\,.\n\\end{eqnarray*}\nand similarly $\\angle B +  \\angle D = 180^\\circ$.\n\n\\subsection*{Ptolemy's theorem}\n\nPtolemy's theorem relates the lengths of the diagonals and the lengths of the sides of a quadrilateral that is circumscribed by a circle:\n\\[\nef = ac + bd\\,.\n\\]\n\\begin{center}\n\\begin{tikzpicture}[scale=.6]\n\\coordinate (origin) at (0,0);\n\\coordinate (A) at (1,3);\n\\node[draw,circle through=(A),name path=circle] at (origin) {};\n\\fill (A) node[above right] {$A$} circle[radius=3pt];\n\\path[name path=b] (A) -- (-50:4cm);\n\\path[name path=c] (A) -- (-120:4cm);\n\\path[name path=d] (A) -- (150:4cm);\n\\path [name intersections={of=circle and b,by={b1,B}}];\n\\fill (B) node[right] {$B$} circle[radius=3pt];\n\\path [name intersections={of=circle and c,by={C,c2}}];\n\\fill (C) node[below left] {$C$} circle[radius=3pt];\n\\path [name intersections={of=circle and d,by={D,d2}}];\n\\fill (D) node[above left] {$D$} circle[radius=3pt];\n\\draw (A) -- node[right] {$a$} (B) -- node[below,yshift=-10pt] {$b$} (C) -- node[left] {$c$} (D) -- node[above,xshift=2pt,yshift=16pt] {$d$}  cycle;\n\\draw (A) -- node[right,near start] {$e$} (C);\n\\draw (B) -- node[left,near end,yshift=-6pt] {$f$} (D);\n\\end{tikzpicture}\n\\end{center}\nThere is a geometric proof of the theorem (see Wikipedia), but I will present a simple trigonometric proof. The law of cosines for the four triangles $\\triangle ABC$, $\\triangle ADC$, $\\triangle DAB$, $\\triangle DCB$ gives the following equations:\n\\begin{eqnarray*}\ne^2 &=& a^2 + b^2 - 2ab \\cos \\angle B\\\\\ne^2 &=& c^2 + d^2 - 2cd \\cos \\angle D\\\\\nf^2 &=& a^2 + d^2 - 2ad \\cos \\angle A\\\\\nf^2 &=& b^2 + c^2 - 2bc \\cos \\angle C\\,.\n\\end{eqnarray*}\n$\\angle C = 180^\\circ - \\angle A$ and $\\angle D = 180^\\circ - \\angle B$ because they are opposite angles of a quadrilateral circumscribed by a circle, so:\n\\begin{eqnarray*}\n\\cos \\angle D &=& - \\cos \\angle B\\\\\n\\cos \\angle C &=& -\\cos \\angle A\\,.\n\\end{eqnarray*}\nWe can eliminate the cosine term from the first two equations and from the last two equations. After some messy arithmetic, we get:\n\\begin{eqnarray*}\ne^2 &=& \\frac{(ac+bd)(ad+bc)}{(ab+cd)}\\\\\nf^2 &=& \\frac{(ab+cd)(ac+bd)}{(ad+bc)}\\,.\n\\end{eqnarray*}\nMultiply the two equations and simplify to get Ptolemy's theorem:\n\\begin{eqnarray*}\ne^2\\cdot f^2 &=& (ac+bd)^2\\\\\nef &=& (ac+bd)\\,. \n\\end{eqnarray*}\n\\subsection*{Using Ptolemy's theorem}\n\nFor the construction on page~\\pageref{ptolemy}, the diagonals are of length $d$, the legs are of length $b$, and the bases are of lengths $h$ and $2h$, so Ptolemy's theorem gives $d\\cdot d = b\\cdot b + h\\cdot 2h$ or $d^2=b^2+2h^2$.\n\nLet $X$ be the point on line $\\overline{PQ}$ that extends $\\overline{PQ}$ by $b$. (We will eventually construct $X$; now we're just imagining it.) Define  $x = \\overline{K'X}$. Since $\\triangle QK'X$ is a right triangle, $x^2 = b^2 + h^2$:\n\\begin{center}\n\\begin{tikzpicture}[scale=.6]\n\\coordinate (Q) at (0,0);\n\\coordinate (P) at (-6.8,0);\n\\coordinate (B) at (-3,-2);\n\\draw[thick,dashed,name path=pq] ($(Q)!1.3!(P)$) -- ($(P)!2.3!(Q)$);\n\\fill (Q) node[above left] {$Q$} circle[radius=3pt];\n\\fill (P) node[above] {$P$} circle[radius=3pt];\n%\\fill (B) circle[radius=2pt];\n\\node[draw,circle through=(B),name path=qb] at (Q) {};\n%\\draw[thick,dashed] (Q) -- node[left,xshift=-1pt,yshift=2pt] {$b$} (B);\n\\path[name path=qh] (Q) -- (-40:5cm);\n\\path[name path=qhp] (Q) -- (40:5cm);\n\\path [name intersections={of=qb and qh,by={hp}}];\n\\path [name intersections={of=qb and qhp,by={H}}];\n\\fill (H) node[right,xshift=2pt] {$H$} circle[radius=3pt];\n\\fill (hp) node[right,xshift=2pt] {$H'$} circle[radius=3pt];\n\\draw[thick,dashed] (H) -- (hp);\n\\path[name path=circleqh] (Q) let\n  \\p1 = ($ (H) - (hp) $)\nin\n  circle ({veclen(\\x1,\\y1)});\n\\path[name path=circlehb] (H) let\n  \\p1 = ($ (Q) - (B) $)\nin\n  circle ({veclen(\\x1,\\y1)});\n\\path [name intersections={of=circleqh and circlehb,by={K,k2}}];\n\\fill (K) node[above left] {$K$} circle[radius=3pt];\n\\draw[thick,dashed] (Q) -- (K);\n\\draw[thick,dashed] (H) -- (K);\n\\draw[thick,dashed] let\n  \\p1 = ($ (K) - (Q) $)\nin\n  coordinate (kp) at (\\x1,-\\y1);\n\\fill (kp) node[below left] {$K'$} circle[radius=3pt];\n\\draw[thick,dashed] (Q) -- node[left] {$h$} (kp) -- (hp);\n\\draw[thick,dashed] (K) -- (hp);\n\\draw[thick,dashed] (kp) -- (H);\n\\path [name intersections={of=pq and qb,by={X,x2}}];\n\\fill (X) node[below right] {$X$} circle[radius=3pt];\n\\draw[thick,dashed] (kp) -- node[left] {$x$} (X);\n\\draw[very thick] (Q) -- (kp) -- (X) -- node[above,xshift=-8pt] {$b$} cycle;\n\\end{tikzpicture}\n\\vspace*{-8pt}\n\\end{center}\nFrom the computation of Ptolemy's theorem theorem above:\n\\erh{0pt}\n\\begin{equationarray*}{rcl}\nd^2&=&b^2 + 2h^2\\\\\n&=&(x^2-h^2)+2h^2\\\\\n&=&x^2+h^2\\,.\n\\end{equationarray*}\nDon't look for a right triangle in the diagram. We are claiming that \\emph{it is possible to construct} a triangle with sides $x,h,d$. \n\nLet us construct the point $S$ as the intersection of the circles \n$c(K,d),c(K',d)$:\n\\begin{center}\n\\begin{tikzpicture}[scale=.55]\n\\coordinate (Q) at (0,0);\n\\coordinate (P) at (-6.8,0);\n\\coordinate (B) at (-3,-2);\n\\draw[dashed,name path=pq] ($(Q)!1.3!(P)$) -- ($(P)!2.3!(Q)$);\n\\fill (Q) node[above left] {$Q$} circle[radius=3pt];\n\\fill (P) node[above] {$P$} circle[radius=3pt];\n\\node[draw,circle through=(B),name path=qb] at (Q) {};\n\\path[name path=qh] (Q) -- (-40:5cm);\n\\path[name path=qhp] (Q) -- (40:5cm);\n\\path [name intersections={of=qb and qh,by={Hp}}];\n\\path [name intersections={of=qb and qhp,by={H}}];\n%\\fill (H) node[right,xshift=2pt] {$H$} circle[radius=3pt];\n%\\fill (Hp) node[right,xshift=2pt] {$H'$} circle[radius=3pt];\n\\path[name path=circleqh] (Q) let\n  \\p1 = ($ (H) - (Hp) $)\nin\n  circle ({veclen(\\x1,\\y1)});\n\\path[name path=circlehb] (H) let\n  \\p1 = ($ (Q) - (B) $)\nin\n  circle ({veclen(\\x1,\\y1)});\n\\path [name intersections={of=circleqh and circlehb,by={K,k2}}];\n\\fill (K) node[above left] {$K$} circle[radius=3pt];\n\\draw[thick,dashed] let\n  \\p1 = ($ (K) - (Q) $)\nin\n  coordinate (Kp) at (\\x1,-\\y1);\n\\fill (Kp) node[below left] {$K'$} circle[radius=3pt];\n\\draw[thick] (Q) -- node[left] {$h$} (Kp);\n\\draw[thick,name path=khp] (K) let\n  \\p1 = ($ (H) - (Kp) $),\n  \\n2 = {veclen(\\x1,\\y1)}\nin\n  (K) ++(-100:\\n2) arc (-100:-30:\\n2);\n\\draw[thick,name path=kph] (Kp) let\n  \\p1 = ($ (H) - (Kp) $),\n  \\n2 = {veclen(\\x1,\\y1)}\nin\n  (Kp) ++(100:\\n2) arc (100:30:\\n2);\n\\path [name intersections={of=kph and khp,by={S}}];\n\\fill (S) node[above right,xshift=6pt] {$S$} circle[radius=3pt];\n\\draw[thick] (Kp) -- node[right,near start,yshift=-6pt] {$d$} (S);\n\\draw[thick] (Q) -- (S);\n\\path [name intersections={of=pq and qb,by={X,Xp}}];\n\\fill (X) node[above right] {$X$} circle[radius=3pt];\n%\\fill (Xp) node[above left] {$X'$} circle[radius=3pt];\n%\\draw (Kp) -- node[left] {$x$} (X);\n%\\draw (K) -- node[left] {$x$} (X);\n%\\fill (B) circle[radius=3pt];\n%\\draw[thick,dashed] (Q) -- node[left,xshift=-1pt,yshift=2pt] {$b$} (B);\n\\end{tikzpicture}\n\\end{center}\nWe obtain a right triangle $\\triangle QSK'$. By Pythagoras' theorem \n$\\overline{QS}^2 + h^2 = d^2$, so:\n\\[\n\\overline{QS}^2 = d^2-h^2=x^2\\,,\n\\]\nand $\\overline{QS}=x$.\n\nIt is possible to construct the point $X$ as the intersection of the circles $c(K,x),c(K',x)$:\n\\begin{center}\n\\vspace*{-14pt}\n\\begin{tikzpicture}[scale=.55]\n\\coordinate (Q) at (0,0);\n\\coordinate (P) at (-6.8,0);\n\\coordinate (B) at (-3,-2);\n\\draw[dashed,name path=pq] ($(Q)!1.3!(P)$) -- ($(P)!2.3!(Q)$);\n\\fill (Q) node[above left] {$Q$} circle[radius=3pt];\n\\fill (P) node[above] {$P$} circle[radius=3pt];\n\\node[draw,circle through=(B),name path=qb] at (Q) {};\n\\path[name path=qh] (Q) -- (-40:5cm);\n\\path[name path=qhp] (Q) -- (40:5cm);\n\\path [name intersections={of=qb and qh,by={Hp}}];\n\\path [name intersections={of=qb and qhp,by={H}}];\n%\\fill (H) node[right,xshift=2pt] {$H$} circle[radius=3pt];\n%\\fill (Hp) node[right,xshift=2pt] {$H'$} circle[radius=3pt];\n\\path[name path=circleqh] (Q) let\n  \\p1 = ($ (H) - (Hp) $)\nin\n  circle ({veclen(\\x1,\\y1)});\n\\path[name path=circlehb] (H) let\n  \\p1 = ($ (Q) - (B) $)\nin\n  circle ({veclen(\\x1,\\y1)});\n\\path [name intersections={of=circleqh and circlehb,by={K,k2}}];\n\\fill (K) node[above left] {$K$} circle[radius=3pt];\n\\path[thick,dashed] let\n  \\p1 = ($ (K) - (Q) $)\nin\n  coordinate (Kp) at (\\x1,-\\y1);\n\\fill (Kp) node[below left] {$K'$} circle[radius=3pt];\n%\\draw[thick] (Q) -- node[left] {$h$} (Kp);\n\\path[name path=khp] (K) let\n  \\p1 = ($ (H) - (Kp) $),\n  \\n2 = {veclen(\\x1,\\y1)}\nin\n  (K) ++(-100:\\n2) arc (-100:-30:\\n2);\n\\path[name path=kph] (Kp) let\n  \\p1 = ($ (H) - (Kp) $),\n  \\n2 = {veclen(\\x1,\\y1)}\nin\n  (Kp) ++(100:\\n2) arc (100:30:\\n2);\n\\path [name intersections={of=kph and khp,by={S}}];\n\\fill (S) node[above right,xshift=6pt] {$S$} circle[radius=3pt];\n%\\draw[thick] (Kp) -- node[right,near start,yshift=-6pt] {$d$} (S);\n%\\draw[thick] (Q) -- (S);\n\\path [name intersections={of=pq and qb,by={X,Xp}}];\n\\fill (X) node[above right,xshift=8pt] {$X$} circle[radius=3pt];\n\\fill (Xp) node[above left] {$X'$} circle[radius=3pt];\n\\draw (Kp) -- node[left] {$x$} (X);\n\\draw (K) -- node[left] {$x$} (X);\n%\\fill (B) circle[radius=3pt];\n%\\draw[thick,dashed] (Q) -- node[left,xshift=-1pt,yshift=2pt] {$b$} (B);\n\\draw[name path=kx] (K) let\n  \\p1 = ($ (X) - (Kp) $),\n  \\n2 = {veclen(\\x1,\\y1)}\nin\n  (K) ++(-100:\\n2) arc (-100:-30:\\n2);\n\\draw[name path=kpx] (Kp) let\n  \\p1 = ($ (X) - (Kp) $),\n  \\n2 = {veclen(\\x1,\\y1)}\nin\n  (Kp) ++(100:\\n2) arc (100:30:\\n2);\n\\path (Xp) -- node[below] {$b$} (Q);\n\\path (Q) -- node[below] {$b$} (X);\n\\node at (-5,2) {\\mbox{\\boldmath $\\overline{PQ}=a$}};\n\\draw[thick,dashed] (Q) -- node[left] {$h$} (Kp);\n\\draw[thick,dashed] (Q) -- (X);\n\\end{tikzpicture}\n\\vspace*{-10pt}\n\\end{center}\nRecall that we want to extend $\\overline{PQ}$ of length $a$ by a length $b$, or decrease its length by $b$. Since the length of $\\overline{QX}$ is $\\sqrt{x^2-h^2}=b$, the length of $\\overline{PX}$ is $a+b$ and the length of $\\overline{PX'}$ is $a-b$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Construct a line segment relative to three other line segments}\\label{s.three}\n\n\\textbf{Given line segments of length $n,m,s$, construct a line segment of length:}\n\\[\nx = \\disfrac{n}{m}s\\,.\n\\]\n\nConstruct two concentric circles $c_1 = c(Z,m)$ and $c_2 = c(Z,n)$, and chord $\\overline{AB} = s$ on $c_1$. (A chord can be constructed using only a compass as shown in Section~\\ref{s.circle}.)\n\nWe assume that $m>n$. If not, exchange the notation.\n\\begin{center}\n\\begin{tikzpicture}[scale=.4]\n\\coordinate (Z) at (0,0);\n\\coordinate (A) at (-130:5cm);\n\\coordinate (B) at (-80:5cm);\n\\fill (Z) node[above left] {$Z$} circle[radius=4pt];\n\\fill (A) node[below left] {$A$} circle[radius=4pt];\n\\fill (B) node[below] {$B$} circle[radius=4pt];\n\\draw[name path=c1] (Z) circle[radius=5cm];\n\\draw[name path=c2] (Z) circle[radius=3cm];\n\\node at (2,5) {$c_1$};\n\\node at (2,3) {$c_2$};\n\\draw[thick] (A) -- node[below,yshift=-6pt] {$s$} (B);\n\\draw[thick,dashed] (Z) -- node[below] {$m$} ++(10:5cm);\n\\draw[thick,dashed] (Z) -- node[below] {$n$} ++(-40:3cm);\n\\fill (Z) ++ (10:5cm) circle[radius=4pt];\n\\fill (Z) ++ (-40:3cm) circle[radius=4pt];\n\\begin{scope}[xshift=-14cm,yshift=3cm]\n\\coordinate (m) at (0,0);\n\\coordinate (n) at (0,-1.5);\n\\coordinate (s) at (0,-3);\n\\coordinate (mp) at (5,0);\n\\coordinate (np) at (2,-1.5);\n\\coordinate (sp) at (4,-3);\n\\fill (m) circle[radius=4pt];\n\\fill (n) circle[radius=4pt];\n\\fill (s) circle[radius=4pt];\n\\fill (mp) circle[radius=4pt];\n\\fill (np) circle[radius=4pt];\n\\fill (sp) circle[radius=4pt];\n\\draw[thick,dashed] (m) -- node[above] {$m$} (mp);\n\\draw[thick,dashed] (n) -- node[above] {$n$} (np);\n\\draw[thick,dashed] (s) -- node[above] {$s$} (sp);\n\\end{scope}\n\\end{tikzpicture}\n\\end{center}\n\n\\vspace{-2ex}\n\nWe also assume that $s$ does not intersect $c_2$. If not, use the construction in Section~\\ref{s.add-subtract} to multiply $m,n$ by a number $k$ so that the chord does not intersect the circle. Note that this does not change the value that we are trying to construct since $x=\\disfrac{kn}{km}s=\\disfrac{n}{m}s$.\n\nChoose any point $H$ on circle $c_2$. Label the length of $\\overline{AH}$ by $w$. Construct point $K$ on $c_2$ such that the length of $\\overline{BK}$ is $w$.\n\\begin{center}\n\\begin{tikzpicture}[scale=.5]\n\\coordinate (Z) at (0,0);\n\\coordinate (A) at (-130:5cm);\n\\coordinate (B) at (-90:5cm);\n\\fill (Z) node[above left] {$Z$} circle[radius=4pt];\n\\fill (A) node[below left] {$A$} circle[radius=4pt];\n\\fill (B) node[below] {$B$} circle[radius=4pt];\n\\draw[name path=c1] (Z) circle[radius=5cm];\n\\draw[name path=c2] (Z) circle[radius=2.5cm];\n\\node at (2,5) {$c_1$};\n\\node at (2,2.5) {$c_2$};\n\\draw[thick] (A) -- node[below,yshift=-6pt] {$s$} (B);\n\\draw[thick] (A) -- node[above,xshift=-4pt,yshift=-2pt] {$w$} +(20:120pt) coordinate (H);\n\\fill (H) node[above right,xshift=-2pt,yshift=4pt] {$H$} circle[radius=4pt];\n\\draw[thick] (B) -- node[right] {$w$} +(60:120pt) coordinate (K);\n\\fill (K) node[right] {$K$} circle[radius=4pt];\n\\begin{scope}[xshift=-14cm,yshift=3cm]\n\\coordinate (m) at (0,0);\n\\coordinate (n) at (0,-1.5);\n\\coordinate (s) at (0,-3);\n\\coordinate (w) at (0,-4.5);\n\\coordinate (mp) at (5,0);\n\\coordinate (np) at (2,-1.5);\n\\coordinate (sp) at (4,-3);\n\\coordinate (wp) at (4.5,-4.5);\n\\fill (m) circle[radius=4pt];\n\\fill (n) circle[radius=4pt];\n\\fill (s) circle[radius=4pt];\n\\fill (w) circle[radius=4pt];\n\\fill (mp) circle[radius=4pt];\n\\fill (np) circle[radius=4pt];\n\\fill (sp) circle[radius=4pt];\n\\fill (wp) circle[radius=4pt];\n\\draw[thick,dashed] (m) -- node[above] {$m$} (mp);\n\\draw[thick,dashed] (n) -- node[above] {$n$} (np);\n\\draw[thick,dashed] (s) -- node[above] {$s$} (sp);\n\\draw[thick,dashed] (w) -- node[above] {$w$} (wp);\n\\end{scope}\n\\end{tikzpicture}\n\\end{center}\n\n$\\triangle AHZ\\cong\\triangle BZK$ by side-side-side: $\\overline{ZA}=\\overline{ZB}=m$, the radius of $c_1$, $\\overline{ZH}=\\overline{ZK}=n$, the radius of $c_2$, and $\\overline{AH}=\\overline{BK}=w$ by construction.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.5]\n\\coordinate (Z) at (0,0);\n\\coordinate (A) at (-130:5cm);\n\\coordinate (B) at (-90:5cm);\n\\fill (Z) node[above left] {$Z$} circle[radius=4pt];\n\\fill (A) node[below left] {$A$} circle[radius=4pt];\n\\fill (B) node[below] {$B$} circle[radius=4pt];\n\\draw[name path=c1] (Z) circle[radius=5cm];\n\\draw[name path=c2] (Z) circle[radius=2.5cm];\n\\node at (2,5) {$c_1$};\n\\node at (2,2.5) {$c_2$};\n\\draw[thick,dashed] (A) -- node[below,yshift=-6pt] {$s$} (B);\n\\draw[thick] (A) -- node[above] {$w$} +(20:120pt) coordinate (H);\n\\fill (H) node[above right,xshift=-2pt,yshift=4pt] {$H$} circle[radius=4pt];\n\\draw[thick] (B) -- node[right] {$w$} +(60:120pt) coordinate (K);\n\\fill (K) node[right] {$K$} circle[radius=4pt];\n\\draw[thick] (Z) -- node[left,xshift=-2pt,yshift=-2pt] {$m$} (A);\n\\draw[thick] (Z) -- (B);\n\\draw[thick] (Z) -- (H);\n\\draw[thick] (Z) -- node[above] {$n$} (K);\n\\draw[thick,dashed] (H) -- (K);\n\\end{tikzpicture}\n\\end{center}\nFrom $\\triangle AHZ\\cong\\triangle BZK$, we get $\\angle AZB = \\angle HZK$. It is difficult to see this equality from the diagram, but the following diagram clarifies the relation among the angles. Define $\\alpha = \\angle AZH = \\angle BZK$ and $\\beta = \\angle BZH$. It is easy to see that $\\angle AZB = \\angle HZK = \\alpha - \\beta$.\n\\begin{center}\n\\vspace*{-10pt}\n\\begin{tikzpicture}[scale=.7]\n\\coordinate (Z) at (0,0);\n\\coordinate (A) at (-150:5cm);\n\\coordinate (B) at (-100:5cm);\n\\coordinate (H) at (-60:4.5cm);\n\\coordinate (K) at (-20:4.5cm);\n\\fill (Z) circle[radius=2pt];\n\\fill (A) circle[radius=2pt];\n\\fill (B) circle[radius=2pt];\n\\fill (H) circle[radius=2pt];\n\\fill (K) circle[radius=2pt];\n\\draw (A) node[below left] {$A$} -- (Z) node[above] {$Z$} -- (B) node[below] {$B$};\n\\draw (H) node[below] {$H$} -- (Z) -- (K) node[below right] {$K$};\n\\draw (-150:1cm) arc (-150:-60:1);\n\\draw (-100:2cm) arc (-100:-20:2);\n\\draw (-100:3cm) arc (-100:-60:3);\n\\draw[very thick,dashed] (-150:4cm) arc (-150:-100:4);\n\\draw[very thick,dashed] (-60:4cm) arc (-60:-20:4);\n\\node at (-115:1.4) {$\\alpha$};\n\\node at (-50:2.4) {$\\alpha$};\n\\node at (-80:3.5) {$\\beta$};\n\\node at (-40:5) {$\\alpha - \\beta$};\n\\node at (-125:5) {$\\alpha - \\beta$};\n\\end{tikzpicture}\n\\vspace*{-10pt}\n\\end{center}\n\n$\\triangle ZAB\\sim\\triangle ZHK$ by side-angle-side, since both are isosceles triangles and we have shown that they have the same vertex angle.\n\n\\vspace{-2ex}\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.45]\n\\coordinate (Z) at (0,0);\n\\coordinate (A) at (-130:5cm);\n\\coordinate (B) at (-90:5cm);\n\\fill (Z) node[above left] {$Z$} circle[radius=4pt];\n\\fill (A) node[below left] {$A$} circle[radius=3pt];\n\\fill (B) node[below] {$B$} circle[radius=3pt];\n\\draw[name path=c1] (Z) circle[radius=5cm];\n\\draw[name path=c2] (Z) circle[radius=2.5cm];\n\\node at (2,5) {$c_1$};\n\\node at (2,2.5) {$c_2$};\n\\draw[thick] (A) -- node[below,yshift=-6pt] {$s$} (B);\n\\path[thick,dashed] (A) -- +(20:120pt) coordinate (H);\n\\fill (H) node[below] {$H$} circle[radius=3pt];\n\\path[thick,dashed] (B) -- +(60:120pt) coordinate (K);\n\\fill (K) node[right] {$K$} circle[radius=3pt];\n\\draw[thick] (Z) -- node[left,xshift=-2pt,yshift=-2pt] {$m$} (A);\n\\draw[thick] (Z) -- (B);\n\\draw[thick] (Z) -- (H);\n\\draw[thick] (Z) -- node[above] {$n$} (K);\n\\draw[thick] (H) -- node[below right] {$x$} (K);\n\\draw[thick,dashed] (A) -- (H);\n\\draw[thick,dashed] (B) -- (K);\n\\end{tikzpicture}\n\\end{center}\n\n\\vspace{-2ex}\n\nLabel $\\overline{HK}$ by $x$. Then:\n\n\\vspace{-2ex}\n\n\\erh{10pt}\n\\begin{equationarray*}{rcl}\n\\frac{m}{s} &=& \\frac{n}{x}\\\\\nx&=&\\frac{n}{m}s\\,.\n\\end{equationarray*}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\vspace{-2ex}\n\n\n\\section{Find the intersection of two lines}\\label{s.two-lines}\n\n\\textbf{Given two lines containing the line segments $\\overline{AB}, \\overline{CD}$, it is possible to construct their intersection using only a compass.}\n\nLet $C',D'$ be the reflections of $C,D$ around $\\overline{AB}$. $S$, the point of intersection of $\\overline{CD}$ and $\\overline{C'D'}$, lies on $\\overline{AB}$, because $\\triangle CZS\\cong \\triangle C'ZS$ by side-angle-side: $\\overline{CZ}=\\overline{C'Z}$, $\\angle CZS=\\angle C'ZS$ are right triangles and $\\overline{ZS}$ is a common side. Therefore, $\\overline{C'S}=\\overline{CS}$ and similarly $\\overline{D'S}=\\overline{DS}$.\n\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.8]\n\\coordinate (A) at (-4,0);\n\\coordinate (B) at (2,0);\n\\coordinate (C) at (-3,2);\n\\coordinate (D) at (1,-1);\n\\coordinate (Cp) at (-3,-2);\n\\coordinate (Dp) at (1,1);\n\\fill (A) node[below] {$A$} circle[radius=2pt];\n\\fill (B) node[below] {$B$} circle[radius=2pt];\n\\fill (C) node[above] {$C$} circle[radius=2pt];\n\\fill (D) node[below] {$D$} circle[radius=2pt];\n\\fill (Cp) node[below] {$C'$} circle[radius=2pt];\n\\fill (Dp) node[above] {$D'$} circle[radius=2pt];\n\\draw[name path=ab] ($(A)!1.3!(B)$) -- ($(B)!1.3!(A)$);\n\\draw[name path=cd] ($(C)!1.2!(D)$) -- ($(D)!1.1!(C)$);\n\\path [name intersections={of=ab and cd,by={S}}];\n\\fill (S) node[above] {$S$} circle[radius=2pt];\n\\draw (Cp) -- (Dp);\n\\draw[thick,dashed] (C) -- node[above left] {$c$} (Cp);\n\\draw[thick,dashed] (D) -- node[above right] {$d$} (Dp);\n\\path (C) -- node[right,xshift=2pt] {$x$} (S);\n\\path (S) -- node[left,near end,xshift=-2pt] {$e-x$} (D);\n\\node at (-.5,-2.5) {\\mbox{\\boldmath $\\overline{CD}=\\overline{C'D'}=e$}};\n\\fill (C|-A)  node[below right] {$Z$} circle[radius=2pt];\n\\draw (C|-A) rectangle +(8pt,8pt);\n\\end{tikzpicture}\n\\end{center}\n\nLabel $x=\\overline{CS}, c=\\overline{CC'}, d=\\overline{DD'},e=\\overline{CD}$. $\\triangle CSC'\\sim\\triangle DSD'$ are similar so $\\disfrac{x}{e-x} = \\frac{c}{d}$. Solving the equation for $x$ gives $x=\\disfrac{c}{c+d}e$.\n\nIf $C,D$ are on the same side of $\\overline{AB}$:\n\\begin{center}\n\\begin{tikzpicture}[scale=.8]\n\\coordinate (A) at (-4,0);\n\\coordinate (B) at (2,0);\n\\coordinate (C) at (-3,2);\n\\coordinate (D) at (-1,1);\n\\coordinate (Cp) at (-3,-2);\n\\coordinate (Dp) at (-1,-1);\n\\fill (A) node[below] {$A$} circle[radius=2pt];\n\\fill (B) node[below] {$B$} circle[radius=2pt];\n\\fill (C) node[above] {$C$} circle[radius=2pt];\n\\fill (D) node[above] {$D$} circle[radius=2pt];\n\\fill (Cp) node[below] {$C'$} circle[radius=2pt];\n\\fill (Dp) node[below] {$D'$} circle[radius=2pt];\n\\draw[name path=ab] ($(A)!1.3!(B)$) -- ($(B)!1.3!(A)$);\n\\draw[name path=cd] ($(C)!2.2!(D)$) -- ($(D)!1.1!(C)$);\n\\path [name intersections={of=ab and cd,by={S}}];\n\\fill (S) node[above] {$S$} circle[radius=2pt];\n\\draw (Cp) -- (S);\n\\draw[thick,dashed] (C) -- node[above left] {$c$} (Cp);\n\\draw[thick,dashed] (D) -- node[above right] {$d$} (Dp);\n\\path (C) -- node[above] {$e$} (D);\n\\path (Cp) -- node[below] {$e$} (Dp);\n\\path (D) -- node[above right,xshift=-4pt] {$x-e$} (S);\n\\path (Dp) -- node[below right,xshift=-4pt] {$x-e$} (S);\n\\node at (1,-2.5) {\\mbox{\\boldmath $\\overline{CS}=\\overline{C'S}=x$}};\n\\end{tikzpicture}\n\\end{center}\n$\\triangle CSC'\\sim\\triangle DSD'$ gives $\\disfrac{x}{x-e}=\\disfrac{c}{d}$. Solving for $x$ gives $x=\\disfrac{c}{c-d}e$.\n\n\\medskip\n\nConstruct the circles $c(C',d), c(D,e)$ and label their intersection by $H$. The sum of the line segments $\\overline{CC'}, \\overline{C'H}$ is $c + d$. We have to show that $H$ is on the extension of $\\overline{CC'}$ so that $\\overline{CH}$ is a line segment of length $c+d$. ($\\overline{CH} = c - d$ in case $D$ is on the same side of $\\overline{AB}$ as $C$.) \n\n\\begin{center}\n\\begin{tikzpicture}[scale=.8]\n\\coordinate (A) at (-4,0);\n\\coordinate (B) at (2,0);\n\\coordinate (C) at (-3,2);\n\\coordinate (D) at (1,-1);\n\\coordinate (Cp) at (-3,-2);\n\\coordinate (Dp) at (1,1);\n\\fill (A) node[below left] {$A$} circle[radius=2pt];\n\\fill (B) node[below] {$B$} circle[radius=2pt];\n\\fill (C) node[above] {$C$} circle[radius=2pt];\n\\fill (D) node[below] {$D$} circle[radius=2pt];\n\\fill (Cp) node[left] {$C'$} circle[radius=2pt];\n\\fill (Dp) node[above] {$D'$} circle[radius=2pt];\n\\draw[name path=ab] ($(A)!1.3!(B)$) -- ($(B)!1.3!(A)$);\n\\draw[name path=cd] ($(C)!1.2!(D)$) -- ($(D)!1.1!(C)$);\n\\path [name intersections={of=ab and cd,by={S}}];\n\\fill (S) node[above,yshift=4pt] {$S$} circle[radius=2pt];\n\\draw (Cp) -- node[below right] {$e$} (Dp);\n\\path (C) -- node[above left] {$c$} (Cp);\n\\draw[thick,dashed] (D) -- node[above right] {$d$} (Dp);\n\\node at (3,-3) {\\mbox{\\boldmath $\\overline{CD}=\\overline{C'D'}=\\overline{DH}=e$}};\n\\draw[name path=circled] (D) let\n  \\p1 = ($ (D) - (C) $),\n  \\n2 = {veclen(\\x1,\\y1)}\nin\n  ++(130:\\n2) arc (130:230:\\n2);\n\n\\draw[name path=circlecp] (Cp) let\n  \\p1 = ($ (D) - (Dp) $),\n  \\n2 = {veclen(\\x1,\\y1)}\nin\n  ++(-180:\\n2) arc (-180:0:\\n2);\n\\path [name intersections={of=circled and circlecp,by={H}}];\n\\fill (H) node[below left] {$H$} circle[radius=2pt];\n\\draw[thick,dashed] ($(C)!1.2!(H)$) -- (C);\n\\draw (H) -- node[right] {$d$} (Cp);\n\\draw (D) -- node[right,xshift=14pt,yshift=8pt] {$e$} (H);\n\\end{tikzpicture}\n\\end{center}\n\n\\vspace{-3ex}\n\nFrom the definition of $H$ as the intersection of $c(C',d), c(D,e)$, we get $\\overline{DH}=e$, $\\overline{C'H}=d$, but $\\overline{C'D'} = e$, $\\overline{D'D}=d$, so the quadrilateral $\\overline{C'D'DH}$ is a parallelogram, since the lengths of both pairs of opposite sides are equal. By construction, the line segment $\\overline{DD'}$ is parallel to $\\overline{CC'}$, so $\\overline{C'H}$ is parallel to $\\overline{DD'}$ is also parallel to $\\overline{CC'}$. Since one of its end points is $C'$, it must be on the line containing $\\overline{CC'}$.\n\nThe lengths $c,d,e$ are given and we proved in Section~\\ref{s.add-subtract} that a line segment of length $c+d$ can be construction and in Section~\\ref{s.three} that a line segment of length $x=\\disfrac{c}{c+d}e$ can be constructed. $S$, the intersection of $c(C',x)$ and $c(C,x)$, is the intersection of $\\overline{AB}, \\overline{CD}$ has been constructed.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.8]\n\\coordinate (A) at (-4,0);\n\\coordinate (B) at (2,0);\n\\coordinate (C) at (-3,2);\n\\coordinate (D) at (1,-1);\n\\coordinate (Cp) at (-3,-2);\n\\coordinate (Dp) at (1,1);\n\\fill (A) node[below left] {$A$} circle[radius=2pt];\n\\fill (B) node[below] {$B$} circle[radius=2pt];\n\\fill (C) node[above] {$C$} circle[radius=2pt];\n\\fill (D) node[below] {$D$} circle[radius=2pt];\n\\fill (Cp) node[left] {$C'$} circle[radius=2pt];\n\\fill (Dp) node[above] {$D'$} circle[radius=2pt];\n\\draw[name path=ab] ($(A)!1.3!(B)$) -- ($(B)!1.3!(A)$);\n\\draw[name path=cd] ($(C)!1.2!(D)$) -- ($(D)!1.1!(C)$);\n\\path [name intersections={of=ab and cd,by={S}}];\n\\fill (S) node[above,yshift=4pt] {$S$} circle[radius=2pt];\n\\draw (Cp) -- (Dp);\n\\path (C) -- node[above,yshift=4pt] {$x$} (S);\n\\path (Cp) -- node[below,yshift=-4pt] {$x$} (S);\n\\path (C) -- node[above left] {$c$} (Cp);\n\\draw[thick,dashed] (D) -- node[above right] {$d$} (Dp);\n\\node at (2.5,-3) {\\mbox{\\boldmath $\\overline{CD}=\\overline{C'D'}=\\overline{DH}=e$}};\n\\draw[name path=circled] (C) let\n  \\p1 = ($ (S) - (C) $),\n  \\n2 = {veclen(\\x1,\\y1)}\nin\n  ++(-10:\\n2) arc (-10:-100:\\n2);\n\n\\draw[name path=circlecp] (Cp) let\n  \\p1 = ($ (S) - (C) $),\n  \\n2 = {veclen(\\x1,\\y1)}\nin\n  ++(100:\\n2) arc (100:0:\\n2);\n\\draw[thick,dashed] (Cp) -- (C);\n\\end{tikzpicture}\n\\end{center}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Finding the intersection of a line and a circle}\\label{s.line-circle}\n\n\\textbf{Given a circle $k=C(M,r)$ and a line $\\overline{AB}$, construct their intersections using only a compass.}\n\nConstruct $M'$, be the reflection of $M$ about $\\overline{AB}$ and the circle $k'=c(M',r)$. The points of intersection of $k,k'$ are the points of intersection of the line $\\overline{AB}$ and the circle $k$.  This can be shown by congruent triangles, as indicated by the dotted lines in the diagram.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.5]\n\\coordinate (A) at (-7,0);\n\\coordinate (B) at (8,0);\n\\coordinate (M) at (0,-2);\n\\coordinate (Mp) at (0,2);\n\\fill (A) node[below] {$A$} circle[radius=3pt];\n\\fill (B) node[below] {$B$} circle[radius=3pt];\n\\fill (M) node[below left] {$M$} circle[radius=3pt];\n\\fill (Mp) node[above left] {$M'$} circle[radius=2pt];\n\\draw[name path=c1] (M) circle[radius=3cm];\n\\draw[name path=c2] (Mp) circle[radius=3cm];\n\\draw[name path=ab] ($(A)!1.2!(B)$) -- ($(B)!1.2!(A)$);\n\\path [name intersections={of=c1 and c2,by={S1,S2}}];\n\\fill (S1) circle[radius=3pt];\n\\fill (S2) circle[radius=3pt];\n\\path[name path=radius1] (M) -- ++(15:4cm);\n\\path [name intersections={of=c1 and radius1,by={R1}}];\n\\draw[thick,dashed] (M) -- node[below] {$r$} (R1);\n\\path[name path=radius2] (Mp) -- ++(40:4cm);\n\\path [name intersections={of=c2 and radius2,by={R2}}];\n\\draw[thick,dashed] (Mp) -- node[above] {$r$} (R2);\n\\fill (R1) circle[radius=3pt];\n\\fill (R2) circle[radius=3pt];\n\\draw[thick, dotted] (Mp) -- (M) -- (S1) -- (Mp) -- (S2) -- (M);\n\\draw (0,0) rectangle +(12pt,12pt);\n\\end{tikzpicture}\n\\end{center}\n\nThis construction cannot be done if $M$ is on the line $\\overline{AB}$. In that case, extend and shorten $\\overline{AM}$ by length $r$ as described in Section~\\ref{s.add-subtract}. The end points of the extended and shortened segments are the intersections of $k$ with $\\overline{AB}$.\n\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.5]\n\\coordinate (A) at (-7,0);\n\\coordinate (B) at (8,0);\n\\coordinate (M) at (0,0);\n\\fill (A) node[below] {$A$} circle[radius=3pt];\n\\fill (B) node[below] {$B$} circle[radius=3pt];\n\\fill (M) node[below left] {$M$} circle[radius=3pt];\n\\draw[name path=c1] (M) circle[radius=3cm];\n\\draw[name path=ab] ($(A)!1.2!(B)$) -- ($(B)!1.2!(A)$);\n\\path[name path=radius1] (M) -- ++(-30:4cm);\n\\path [name intersections={of=c1 and radius1,by={R1}}];\n\\draw[thick,dashed] (M) -- node[below] {$r$} (R1);\n\\path [name intersections={of=c1 and ab,by={S1,S2}}];\n\\fill (S1) node[above right] {$\\overline{AM}+r$} circle[radius=3pt];\n\\fill (S2) node[above left] {$\\overline{AM}-r$} circle[radius=3pt];\n\\fill (R1) circle[radius=3pt];\n\\end{tikzpicture}\n\\end{center}\n\n", "meta": {"hexsha": "d8b855916e664095836e6885b3c602aff56c4c1a", "size": 48703, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "compass-only.tex", "max_stars_repo_name": "motib/constructions", "max_stars_repo_head_hexsha": "8f8f4f25a91abb31b8392b83802e7f5ed42462c7", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-07T15:57:52.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-07T15:57:52.000Z", "max_issues_repo_path": "compass-only.tex", "max_issues_repo_name": "motib/constructions", "max_issues_repo_head_hexsha": "8f8f4f25a91abb31b8392b83802e7f5ed42462c7", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "compass-only.tex", "max_forks_repo_name": "motib/constructions", "max_forks_repo_head_hexsha": "8f8f4f25a91abb31b8392b83802e7f5ed42462c7", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.1550317316, "max_line_length": 662, "alphanum_fraction": 0.626983964, "num_tokens": 18622, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.8933094103149355, "lm_q1q2_score": 0.7130277683207742}}
{"text": "\\subsection{System to Higher Order}\r\nLet's say we have the linear system\r\n\\begin{equation*}\r\n\t\\vec{x}' = A\\vec{x} + \\vec{f}\r\n\\end{equation*}\r\nWriting the system using $x_1, \\ldots x_n$ as the components of $\\vec{x}$, $f_1, \\ldots f_n$ as the components of $\\vec{f}$, and $a_{ij}$ as the entry in $A$ on the $i^{th}$ row and $j^{th}$ column,\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\tx_1' = a_{11}x_1 + \\ldots a_{1n}x_n + f_1 \\\\\r\n\t\t\\vdots \\\\\r\n\t\tx_n' = a_{n1}x_1 + \\ldots a_{nn}x_n + f_n\r\n\t\\end{cases}\r\n\\end{equation*}\r\nLet's arbitrarily assign $x_1 = y$. This will allow us to find expressions for $x_2, \\ldots x_n$ in terms of $y$ and its derivatives. When we find $x_n$ in these terms and equate $x_n'$ with what's given in the system, we'll have an linear $n^{th}$ order equation.\r\n\r\n\\ifodd\\includeLinearSystemsExamples\\input{./linearSystems/systemsAndHigherOrder/systemToHigherOrder_example.tex}\\fi\r\n\r\n\\noindent\r\nThe auxiliary polynomial of this higher order equation $p(r)$ and the characteristic polynomial $p(\\lambda)$ of the linear system will have exactly the same roots.", "meta": {"hexsha": "15f40a8a2a8d419092c8aef433db561eb7a1dfe6", "size": 1075, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/systemsAndHigherOrder/systemToHigherOrder.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/linearSystems/systemsAndHigherOrder/systemToHigherOrder.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/linearSystems/systemsAndHigherOrder/systemToHigherOrder.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.5789473684, "max_line_length": 265, "alphanum_fraction": 0.7004651163, "num_tokens": 354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7130277627757765}}
{"text": "\\subsection{Math Functions}\n\\texttt{{\\large\\textbf{ceil}}}\\textsf{(real:x):real}\\\\\n Round to the smallest integral value not less than x.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{round}}}\\textsf{(real:x):real}\\\\\n Round to the nearest integral value.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{floor}}}\\textsf{(real:x):real}\\\\\n Round to the largest integral value not greater than x.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{sqrt}}}\\textsf{(real:x):real}\\\\\n Returns the square root of a number.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{pow}}}\\textsf{(real:x, real:y):real}\\\\\n Returns a number x raised to the power y.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{exp}}}\\textsf{(real:x):real}\\\\\n Returns the base-e exponential of x.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{log}}}\\textsf{(real:x):real}\\\\\n Returns the base-e logarithm of x.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{log10}}}\\textsf{(real:x):real}\\\\\n Returns the base-10 logarithm of x.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{pi}}}\\textsf{(void):real}\\\\\n Returns the value of PI.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{sgn}}}\\textsf{(real:x):real}\\\\\n Returns 1 if the argument is greater than zero, 0 if argument is 0, otherwise -1.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{abs}}}\\textsf{(real:x):real}\\\\\n Returns the absolute value of a number.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{sin}}}\\textsf{(real:x):real}\\\\\n Computes the sine of x (radians)\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{cos}}}\\textsf{(real:x):real}\\\\\n Computes the cosine of x (radians)\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{tan}}}\\textsf{(real:x):real}\\\\\n Computes the tangent of x (radians)\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{asin}}}\\textsf{(real:x):real}\\\\\n Computes the arc sine of x, result is in radians, -pi/2 to pi/2.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{acos}}}\\textsf{(real:x):real}\\\\\n Computes the arc cosine of x, result is in radians, 0 to pi.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{atan}}}\\textsf{(real:x):real}\\\\\n Computes the arc tangent of x, result is in radians, -pi/2 to pi/2.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{atan2}}}\\textsf{(real:x, real:y):real}\\\\\n Computes the arc tangent using both x and y to determine the quadrant of the result, result is in radians.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{sind}}}\\textsf{(real:x):real}\\\\\n Computes the sine of x (degrees)\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{cosd}}}\\textsf{(real:x):real}\\\\\n Computes the cosine of x (degrees)\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{tand}}}\\textsf{(real:x):real}\\\\\n Computes the tangent of x (degrees)\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{asind}}}\\textsf{(real:x):real}\\\\\n Computes the arc sine of x, result is in degrees, -90 to 90.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{acosd}}}\\textsf{(real:x):real}\\\\\n Computes the arc cosine of x, result is in degrees, 0 to 180.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{atand}}}\\textsf{(real:x):real}\\\\\n Computes the arc tangent of x, result is in degrees, -90 to 90.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{atan2d}}}\\textsf{(real:x, real:y):real}\\\\\n Computes the arc tangent using both x and y to determine the quadrant of the result, result is in degrees.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{nan}}}\\textsf{(void):real}\\\\\n Returns the non-a-number (NAN) value.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{isnan}}}\\textsf{(number):boolean}\\\\\n Returns true if the argument is NaN.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{mod}}}\\textsf{(integer:x, integer:y):integer}\\\\\n Returns the remainder after integer division of x by y.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{sum}}}\\textsf{(...):real}\\\\\n Returns the numeric sum of all values passed to the function. Arguments can be arrays or numbers.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{min}}}\\textsf{(...):real}\\\\\n Returns the minimum of the numeric arguments.\n\n\\texttt{{\\large\\textbf{min}}}\\textsf{(array):real}\\\\\n Returns the minimum value in an array of numbers\n\n\\emph{Notes:} Returns the minimum numeric value.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{max}}}\\textsf{(...):real}\\\\\n Returns the maximum of the passed numeric arguments.\n\n\\texttt{{\\large\\textbf{max}}}\\textsf{(array):real}\\\\\n Returns the maximum value in an array of numbers\n\n\\emph{Notes:} Returns the maximum numeric value.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{mean}}}\\textsf{(...):real}\\\\\n Returns the mean (average) value all values passed to the function. Arguments can be arrays or numbers.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{stddev}}}\\textsf{(...):real}\\\\\n Returns the sample standard deviation of all values passed to the function. Uses Bessel's correction (N-1). Arguments can be arrays or numbers.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{gammaln}}}\\textsf{(real):real}\\\\\n Computes the logarithm of the Gamma function.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{pearson}}}\\textsf{(array:x, array:y):real}\\\\\n Calculate the Pearson linear rank correlation coefficient of two arrays.\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{besj0}}}\\textsf{(real:x):real}\\\\\n Computes the value of the Bessel function of the first kind, order 0, J0(x)\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{besj1}}}\\textsf{(real:x):real}\\\\\n Computes the value of the Bessel function of the first kind, order 1, J1(x)\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{besy0}}}\\textsf{(real:x):real}\\\\\n Computes the value of the Bessel function of the second kind, order 0, Y0(x)\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{besy1}}}\\textsf{(real:x):real}\\\\\n Computes the value of the Bessel function of the second kind, order 1, Y1(x)\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{besi0}}}\\textsf{(real:x):real}\\\\\n Computes the value of the modified Bessel function of the first kind, order 0, I0(x)\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{besi1}}}\\textsf{(real:x):real}\\\\\n Computes the value of the modified Bessel function of the first kind, order 1, I1(x)\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{besk0}}}\\textsf{(real:x):real}\\\\\n Computes the value of the modified Bessel function of the second kind, order 0, K0(x)\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{besk1}}}\\textsf{(real:x):real}\\\\\n Computes the value of the modified Bessel function of the second kind, order 1, K1(x)\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{erf}}}\\textsf{(real):real}\\\\\n Calculates the value of the error function\n\n\\hrulefill\n\n\\texttt{{\\large\\textbf{erfc}}}\\textsf{(real):real}\\\\\n Calculates the value of the complementary error function\n", "meta": {"hexsha": "e6bebb4bc74298b375deaf7ade9e79b84a7259cf", "size": 6194, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/lk_math.tex", "max_stars_repo_name": "fenollp/lk", "max_stars_repo_head_hexsha": "14ed9cb1997906c9af2711ce03ce07b31c284349", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2017-08-01T16:13:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-29T13:13:29.000Z", "max_issues_repo_path": "doc/lk_math.tex", "max_issues_repo_name": "fenollp/lk", "max_issues_repo_head_hexsha": "14ed9cb1997906c9af2711ce03ce07b31c284349", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2017-07-13T17:31:21.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-18T21:32:15.000Z", "max_forks_repo_path": "doc/lk_math.tex", "max_forks_repo_name": "fenollp/lk", "max_forks_repo_head_hexsha": "14ed9cb1997906c9af2711ce03ce07b31c284349", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2017-09-17T00:29:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T04:25:54.000Z", "avg_line_length": 26.4700854701, "max_line_length": 144, "alphanum_fraction": 0.7126251211, "num_tokens": 1986, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7130192246792919}}
{"text": "\\chapter{Collatz conjecture}\n\nLet \\(f(n) = n/2\\) if \\(n\\) is even or \\(3n+1\\) if \\(n\\) is odd.\n\n\\(f(n) = (n \\bmod 2) (n/2) + (1 - n \\bmod 2) (3n + 1)\\).\n\n\\(f(n) = (n \\bmod 2) (n/2) + (3n + 1) - (n \\bmod 2) (3n + 1)\\).\n\n\\(f(n) = (n \\bmod 2) (n/2 - (3n + 1)) + (3n + 1)\\).\n\n\\(f(n) = (n \\bmod 2) (2 - 5n)/2 + (3n + 1)\\).\n\n\\(2 f(n) = (n \\bmod 2) (2 - 5n) + 6n + 2\\).\n\n\\(f(2n) = n\\)\n\n\\(f(2n+1) = 3(2n+1)+1 = 6n+4 = 2(3n+2)\\)\n\n\\(f(2n+2) = n+1\\)\n\n\\(f(2n+3) = 3(2n+3)+1 = 6n+10 = 2(3n+5)\\)\n\n\\(f(2n+2k) = n+k\\)\n\n\\(f(2n+2k+1) = 2(3n+2+3k)\\)\n\n\\(f(2n+2k+1) = 2(3(n+k)+2)\\)\n\n\\(f(2(n+k)+1) = 2(3(n+k)+2)\\)\n\n\\(f(2m+1) = 2(3m+2)\\)... back to square 0\n\nLet \\(q\\) be odd.\n\\begin{align*}\n    f(2^{p+1} q) = 2^p q\n    \\\\\n    f(2^0 q) = 3q + 1\n    \\\\\n    f(2k+1) = 3(2k+1) + 1 = 6k+4 = 2(3k+2)\n    \\\\\n    f(2(2k)+1) = 3(4k+1) + 1 = 12k+4 = 4(3k+1)\n    \\\\\n    f(2(2k+1)+1) = 3(4k+3) + 1 = 12k+10 = 2(6k+5)\n\\end{align*}\n\n\\begin{align*}\n    f(6n) &= 3n\n    \\\\\n    f(6n+1) &= 3(6n+1)+1 = 18n+4\n    \\\\\n    f(6n+2) &= 3n+1\n    \\\\\n    f(6n+3) &= 3(6n+3) + 1 = 18n+10\n    \\\\\n    f(6n+4) &= 3n+2\n    \\\\\n    f(6n+5) &= 3(6n+5) + 1 = 18n+16\n\\end{align*}\n\nLet \\(g(n) = f(2n)\\) and \\(h(n) = f(2n+1)\\).\n\nLet \\(a(n,0) = n\\) and \\(a(n,k+1) = f(a(n,k))\\).\n\nCorollary: \\(a(n,k+1) = a(f(n),k)\\).\n\nCorollary: If \\(n\\) is odd, then \\(f(n)\\) is even.\n\n\\section{Recursion}\n\nLemma: For every \\(n\\) and \\(d \\neq 0\\), there exists \\(q,d\\) such that \\(n = qd+m\\) and \\(0 \\le m < d\\).\n\n\\begin{align*}\n    f(2n+0) &= n+0\n    \\\\\n    f(2n+1) &= 6n+4 = 2(3n+2)\n    \\\\\n    f(4n+0) &= 2n+0\n    \\\\\n    f(4n+1) &= 12n+4 = 4(3n+1)\n    \\\\\n    f(4n+2) &= 2n+1\n    \\\\\n    f(4n+3) &= 12n+10 = 2(6n+5)\n    \\\\\n    f(8n+0) &= 4n+0\n    \\\\\n    f(8n+1) &= 24n+4 = 4(6n+1)\n    \\\\\n    f(8n+2) &= 4n+1\n    \\\\\n    f(8n+3) &= 24n+10 = 2(12n+5)\n    \\\\\n    f(8n+4) &= 4n+2 = 2(2n+1)\n    \\\\\n    f(8n+5) &= 24n+16 = 8(3n+2)\n    \\\\\n    f(8n+6) &= 4n+3\n    \\\\\n    f(8n+7) &= 24n+22 = 2(12n+11)\n    \\\\\n    f(16n+0) &= 8n+0\n    \\\\\n    f(16n+1) &= 48n+4 = 4(12n+1)\n    \\\\\n    f(16n+2) &= 8n+1\n    \\\\\n    f(16n+3) &= 48n+10 = 2(24n+5)\n    \\\\\n    f(16n+4) &= 8n+2 = 2(4n+1)\n    \\\\\n    f(16n+5) &= 48n+16 = 16(3n+1)\n    \\\\\n    f(16n+6) &= 8n+3\n    \\\\\n    f(16n+7) &= 48n+22 = 2(24n+11)\n    \\\\\n    f(16n+8) &= 8n+4 = 4(2n+1)\n    \\\\\n    f(16n+9) &= 48n+28 = 4(12n+7)\n    \\\\\n    f(16n+10) &= 8n+5\n    \\\\\n    f(16n+11) &= 48n+34 = 2(24n+17)\n    \\\\\n    f(16n+12) &= 8n+6 = 2(4n+3)\n    \\\\\n    f(16n+13) &= 48n+40 = 8(6n+5)\n    \\\\\n    f(16n+14) &= 8n+7\n    \\\\\n    f(16n+15) &= 48n+46 = 2(24n+23)\n    \\\\\n    f(16n-1) &= 48n-2 = 2(24n-1)\n    \\\\\n    f(16n-5) &= 48n-14 = 2(24n-7)\n\\end{align*}\n\n\\begin{align*}\n    f^2(4n) &= (gg)(n) = n\n    \\\\\n    f^2(4n+1) &= (gh)(n) = 6n+2 = 2(3n+1)\n    \\\\\n    f^2(4n+2) &= (hg)(n) = 6n+4 = 2(3n+2)\n    \\\\\n    f^2(4n+3) &= (gh)(n) = 6n+5\n    \\\\\n    f^3(8n) &= (ggg)(n) = n\n    \\\\\n    f^3(8n+1) &= f^2(24n+4) = (ggh)(n) = 6n+1\n    \\\\\n    f^3(8n+2) &= f^2(4n+1) = (ghg)(n) = 6n+2 = 2(3n+1)\n    \\\\\n    f^3(8n+3) &= f^2(24n+10) = (hgh)(n) = 36n+16 = 4(9n+4)\n    \\\\\n    f^3(8n+4) &= f(2n+1) = (ggg)(n) = 6n+4 = 2(3n+2)\n    \\\\\n    f^3(8n+5) &= f^2(24n+16) = (ggh)(n) = 6n+4 = 2(3n+2)\n    \\\\\n    f^3(8n+6) &= f^2(4n+3) = (hgh)(n) = 6n+5\n    \\\\\n    f^3(8n+7) &= f^2(24n+22) = f(12n+11) = (ghg)(n) = 36n+34 = 2(18n+17)\n    \\\\\n    f^p(2^p q+0) &= f^{p-1}(2^{p-1} q+0)\n    \\\\\n    f^p(2^p q+1) &= f^{p-1}(3 \\cdot 2^{p-1} q+4)\n\\end{align*}\n\nLemma: \\(f^3(8n+4) = f^3(8n+5)\\).\n\nLet \\(g(n) = n/2\\) and \\(h(n) = 3n+1\\).\n\n\\section{Equation}\n\n\\(2^p q = 3 n + 1\\) where \\(q\\) is odd.\n\n\\(2^{p_0} q_0 = 3 n_0 + 1\\) where \\(q\\) is odd.\n\n\\(2^{p_1} q_1 = 3 n_1 + 1\\) where \\(q\\) is odd.\n\n\\(n_{k+1} = 2^{p_k} q_k\\)\n\n\\section{Sequence}\n\nConsider three mutual sequences \\(p\\), \\(q\\), and \\(n\\).\n\nInput: \\(q_0\\).\n\nConstraint: \\(q_k\\) odd.\n\n\\begin{align*}\n    n_0 &= q_0\n    \\\\\n    n_{k+1} &= 3 q_k + 1\n    \\\\\n    n_k &= 2^{p_k} q_k\n\\end{align*}\n\nCollatz conjecture: For every odd \\(q_0 \\in \\Nat\\), there exists \\(k\\) such that \\(q_k = 1\\).\n\nAlternative: For every odd \\(a\\), there exists \\(k\\) and odd \\(q_0\\) such that \\(q_k = a\\).\n\nLemma: If \\(n\\) is even, then \\(3n+1\\) is odd.\n\nLemma: If \\(n\\) is odd, then \\(3n+1\\) is even.\n\n\\section{Composition}\n\n\\(u(n) = 1\\) where \\(u \\in (f|g)^*\\)\n\n\\(3(2n)+1 = 3(2n+1)-2\\)\n\n\\section{Composition}\n\n\\((h \\circ g)(n) = 3(n/2) + 1 = (3n+2)/2\\)\n\n\\((g \\circ h)(n) = (3n + 1)/2 = (3n+1)/2\\)\n\n\\((h \\circ g - g \\circ h)(n) = 1/2\\)\n\n\\section{Path}\n\nLet \\(P(a,b)\\) mean that there is a path from \\(a\\) to \\(b\\) in the forward Collatz graph.\n\n(Domain of discourse is \\(\\Nat\\).\nAll unbound variables are universally quantified.)\n\nCorollary: If \\(P(f(a),b)\\) then \\(P(a,b)\\).\n\nCorollary: If \\(n\\) is odd and \\(P(3n+1,a)\\) then \\(P(n,a)\\).\n\nCorollary: \\(P(6n+4,a)\\) then \\(P(2n+1,a)\\).\n\nCorollary: If \\(P(n,a)\\) then \\(P(2n,a)\\).\n\nCorollary: If \\(n \\bmod 3 = 1\\) and \\(P(n,a)\\) then \\(P(\\frac{n-1}{3},a)\\).\n\nLemma: There is no \\(n\\) such that \\(n \\bmod 2^p = 1\\) for all \\(p > 0\\).\n\nLemma: \\(P(2^p n, n)\\).\n\nCorollary: \\(P(2^p,1)\\).\n\nLemma: If \\(P(a,2^p)\\) then \\(P(a,1)\\).\n\nLemma: If \\(P(q, 1)\\) then \\(P(2^p q,1)\\).\n\nConjecture: If \\(P(a,1)\\) and \\(P(b,1)\\) then \\(P(ab,1)\\)?\n\nConjecture: If \\(P(a,1)\\) and \\(P(b,1)\\) then \\(P(a+b,1)\\)?\n\nLemma: If \\(P(3n+2,1)\\) then \\(P(2n+1,1)\\).\n\nLemma: If \\(P(3n+1,1)\\) then \\(P(4n+1,1)\\).\n\nLemma: If \\(n\\) is odd, then \\(f(4n+1) = 4f(n)\\).\n\nLemma: If \\(p \\ge 2\\) then \\(f(2^p n + 3) = 2(3 \\cdot 2^{p-1} + 5)\\).\n\nSuppose \\(P(n,1)\\). Prove \\(P(n+1,1)\\).\n\nIf \\(P(k,1)\\) then \\(P(2k,1)\\).\n\nIf \\(P(6k+4,1)\\) then \\(P(2k+1,1)\\).\n\n\\section{Equivalence}\n\nLemma: Iff every \\(6n+4\\) has a path to \\(2^p\\), then the Collatz conjecture is true.\n\nIf \\(3n+1 < 4\\) and \\(3n \\bmod 2 = 1\\) then \\(P(n+1,1)\\).\n\nIf \\(3n+1 < 8\\) and \\(3n \\bmod 4 = 1\\) then \\(P(3n+1,1)\\).\n\nIf \\(3n+1 < 16\\) and \\(3n \\bmod 8 = 1\\) then \\(P(3n+1,1)\\).\n\nIf \\(3n+1 < 32\\) and \\(3n \\bmod 16 = 1\\) then \\(P(3n+1,1)\\).\n\n\\(\\{ (p,N) ~|~ n \\in N, ~ 3n \\bmod 2^p = 1 \\} = \\{ (1,\\{1,3,5,\\ldots\\}), (2,\\{3,7,11,\\ldots\\}), (3,\\{3,11,19,\\ldots\\}) \\}\\)\n\nFor all \\(n,p\\): Statement \\(S(p)\\) is: if \\(3n+1 < 2^{p+1}\\) and \\(3n \\bmod 2^p = 1\\) then \\(P(3n+1,1)\\).\n\nAn inductive proof of \\(S(p)\\) is a proof of the Collatz conjecture.\n\n\\section{Representation}\n\nIn this section, the domain of discourse is \\(\\Nat\\).\n\nAssume \\(n > 0\\).\nDefine \\(t(n)\\) as the largest \\(p\\) such that \\(n = 2^p q\\).\nEquivalent:\nDefine \\(t(n)\\) as the \\(p\\) such that \\(n = 2^p q\\) and \\(q\\) is odd.\n\nLemma:\nFor every positive \\(n\\), there exists \\(p\\) and odd \\(q\\) such that \\(n = 2^p q\\).\n\nLemma:\nFor every positive \\(n\\), there exists \\(p\\) and \\(q < 2^p\\) such that \\(n = 2^p + q\\).\n\nLemma: If \\(b < 2^a\\) then \\(t(2^a + b) = \\min(a,t(b))\\).\n\nLemma: For every \\(n\\), there exist \\(p,q\\) such that \\(3(2n+1)+1 = 2^p q\\).\n\nCorollary: Iff \\(n\\) is a power of two, then \\(q = 1\\).\n\nIf \\(m = 2^a b\\) and \\(n = 2^c d\\) then \\(mn = 2^{a+c} (bd)\\).\n\n\\begin{align*}\n    (2^a b + 2^c d) \\bmod 2^p = ?\n\\end{align*}\n\n\\(2^p \\cdot 1 + 1 = 2^0 (2^p + 1)\\).\n\nIf \\(k\\) is even then \\(2^0 (2k + 1) + 1 = 2k + 2 = 2^1 (k+1)\\).\n\n\\(2^0 (2(2k) + 1) + 1 = 4k+2 = 2^0(2k+1)\\)\n\nIf \\(k\\) is even then \\(2^0 (2(2k) + 3) + 1 = 4k+4 = 2^2(k+1)\\)\n\n\\(t(1,2,3,4,5,\\ldots) = 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,\\ldots\\)\n\n\\(t(2,4,6,8,10,\\ldots) = 1,2,1,3,1,2,1,4,1,2,1,3,1,2,1,5,\\ldots\\)\n\n\\(t(k)\\) is the number of trailing zero bits in the binary representation of \\(k\\)\n\nLemma: \\(t(k) \\cdot t(k+1) = 0\\)\n\nLemma: \\(t(ab) = t(a) + t(b)\\)\n\nIf \\(t(k) \\ge 1\\) then \\(2^0 (2^p k+1) + 1 = 2^p k + 2 = 2^p (k+1)\\)\n\nIf \\(t(k) \\ge 1\\) then \\(t(2^a k+1) = a\\)\n\n\\(t(3k) = t(k)\\)\n\nUnder what circumstances are \\(3(2n+1)+1 = 2^p\\) (that is \\(q=1\\))?\n\n\\(6n+4 = 2^p\\).\n\n\\(1 \\equiv 2^p \\pmod 3\\).\nCorollary: Iff \\(p\\) is even then \\(2^p+2\\) is even and divisible by 3.\n\nCorollary: If \\(t(n) > 0\\) then \\(t(f(n)) = t(n)-1\\).\n\n\\[\n    g(n) =\n    \\begin{cases}\n        \\{2n\\} & \\text{if } n \\bmod 3 \\in \\{0,2\\}\n        \\\\\n        \\{2n, \\frac{n-1}{3}\\} & \\text{if } n \\bmod 3 = 1\n    \\end{cases}\n\\]\n\nLet \\(G(N) = \\bigcup_{n \\in N} g(n)\\).\n\nLet \\(H_0 = \\{1\\}\\) and \\(H_{k+1} = H_k \\cup G(H_k)\\).\n\n\\(H \\sim \\{1\\}, \\{2,1,0\\}, \\{4,2,1,0\\}, \\{8,4,2,1,0\\}, \\{16,8,5,4,2,1,0\\}, \\{32,16,10,8,5,4,2,1,0\\}\\)\n\n\\(\\forall k : H_k \\subset H_{k+1}\\)\n\nCollatz conjecture: for every \\(N \\subseteq \\Nat - \\{1\\}\\), there exists \\(p \\in \\Nat\\) such that \\(N \\subseteq G^p(\\{1\\})\\).\n\nConjecture: \\(G(\\Nat) = \\Nat\\).\n\n\\section{Collatz graph}\n\nGraph \\((V,E)\\)\n\n\\((2n,n) \\in E\\)\n\n\\((2n+1,3(2n+1)+1) \\in E\\), that is\n\\((2n+1,6n+4) \\in E\\)\n\n\\((2,1),(4,2),(6,3),(8,4),(10,5),\\ldots\\)\n\n\\((1,4),(3,10),(5,16),(7,22),(9,28),\\ldots\\)\n\nProve that there is a path from every positive \\(n\\) to 1.\n\nInverse graph\n\n\\((n,2n) \\in E'\\)\n\n\\((6n+4,2n+1) \\in E'\\)\n\nProve that there is a path from 1 to every positive \\(n\\).\n\nCan we transform \\(f\\) into a monotonically increasing function?\n", "meta": {"hexsha": "3b96c5cb5d9a896276d8fc27b256eed2171b4bd5", "size": 8795, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/collatz.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/collatz.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/collatz.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 22.6675257732, "max_line_length": 125, "alphanum_fraction": 0.4491188175, "num_tokens": 4683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.7130042498303995}}
{"text": "\\section{Introduction: Proofs and why we want them}\r\nVaguely speaking, a proof is a kind of logical argument (or a series of it) which establishes a conclusion.\r\nThis is not the most rigorous way to define it, but it would be enough for now.\r\nThe big question, however, is why we need them.\r\nWhy can't we just assume something that looks nice to be correct?\r\nWhy can't we declare something to be right if it holds merely for the scope that we can reach?\r\nOf course, there is an answer.\r\nIf not, mathematics would not have existed.\r\n\\subsection{Why we need proofs}\r\nThere are a few reasons why proofs are important and essential.\r\nThe obvious one is that we need to be sure about the truthfulness of something.\r\nThere are tonnes of example in mathematcis where a theorem holds for a shockingly large selection of numbers but not for all.\r\nWe could, of course, give some silly examples like the claim ``all positive integers are less than $N$'' where you can substitute $N$ for some very large integer, but there is a more interesting example:\r\n\\begin{example}[Polya's Conjecture]\r\n    For any positive integer $N>2$, at least half of the positive integers less than or equal to $N$ has an odd number of prime factors (counting multiplicity).\r\n\\end{example}\r\n\\begin{proof}[Disproof]\r\n    The smallest counterexample occurs at $N=906150257$.\r\n\\end{proof}\r\nWe do have computers now that can test some of our conjectures up to some very large numbers, but for mathematicians, most of those computational powers are useless,\r\n\\footnote{There are some proofs that harness the power of computers, like the four-color theorem. But still -- it is the proof we need, not any sort of verification.}\r\nsince they can do nothing about how the general picture is like.\r\n\\subsection{Why we want proofs}\r\nWe can need something that we don't want, like nuclear weapons.\r\nHowever, this is not the case for proofs.\r\nWe need them, yes.\r\nBut we still want them, desperately.\r\nSome say that the study of language is proofreading, then the study of mathematics would be proof-reading.\r\nWhat we really want is not only the however elegant results that we, or someone else, have proven.\r\nWe should be more attracted to the (clever) idea behind.\r\nWhy? Because if we come through another statement of similar kind, it would be in our advantage to solve them using the same technique.\r\nAfter all, mathematics is a creative art (of problem-solving).\r\nQuoting theorems won't get you anywhere in maths, what you really need is to empower yourself with the tricks in the proof.\r\n\\subsection{Correct and incorrect proofs}\r\nFirst let us see how a correct proof is done:\r\n\\begin{claim}\r\n    For any integer $n$, $n^3-n$ is a multiple of $3$.\r\n\\end{claim}\r\nNote that when you state some variable, you need to state as well where its home is at.\r\nThe statement would be false if $n$ is not restricted to integers.\r\nNow here comes the proof.\r\n\\begin{proof}\r\n    $n^3-n=(n-1)n(n+1)$. Since one of any three consecutive integers is a multiple of $3$, one of $n-1,n,n+1$ is. So $n^3-n$ is a multiple of $3$.\r\n\\end{proof}\r\nA proof almost always comes with a smart idea.\r\nThe ``smart'' here doesn't necessarily mean that it is really smart, but a very important point that constitutes the basic of (part of) the proof.\r\nIn this case, the smart idea is to try and factorize the expression to something that we can easily handle, which makes the problem quite obivous.\\\\\r\nNow here come a non-proof, or incorrect proof:\r\n\\begin{claim}\r\n    Let $n$ be a integer. If $n^2$ is even, so is $n$.\r\n\\end{claim}\r\n\\begin{proof}[Non-proof]\r\n    If $n$ is even, then $n=2k$ for some integer $k$, so $n^2=4k^2=2(2k^2)$. Therefore $n^2$ is even.\r\n\\end{proof}\r\nIs it factually wrong? No.\r\nThe logic in the proof itself is impeccable.\r\nSo both the statement and the proof logic is correct, what is wrong?\r\nQuite obviously, it has proved the wrong thing.\r\nWe want something like $A\\implies B$, but what has been proven is $B\\implies A$.\r\nSo even both the statement and the proof logic are alright, it might still not be a proof.\r\n(Needless to say, if either of these two things is not, it would not be a proof either.)\r\nSo back on the track.\r\n\\begin{proof}\r\n    If $n^2$ even but $n$ is not, then $n=2k+1$ for some integer $k$, so $n^2=4k^2+4k+1=2(2k^2+2k)+1$ which is odd. This is a contradiction.\r\n\\end{proof}\r\nThis is a new way of proof. We do not take $A\\implies B$ directly, but we use $\\lnot B\\implies\\lnot A$.\r\nThe equivalence of these two is called \\textit{reducio ad absurdum}, and the trick to use this in the proof is called a \\textit{proof by contradiction}.\r\n\\subsection{``iff''}\r\nWe want to prove the following claim:\r\n\\begin{claim}\r\n    The solutions to $x^2-5x+6$ are $x=2$ and $x=3$.\r\n\\end{claim}\r\nNote that this claim is actually two claims: that $2,3$ are indeed solutions to the equation, and that the equation does not have any other solutions.\r\nTherefore, to rephrase the question, we want to prove that $x^2-5x+6=0$ \\textit{if and only if} $x=2$ or $x=3$.\r\nHere, \\textit{if and only if} means, well, what it literally means, that the two statements are equivalent to each other.\r\nThey are interchangable and any one of them implies the other.\r\nSo our proof must consist of both the forward and backward implication.\r\nOtherwise, it would be incomplete.\r\nOne way of doing it is to seperately prove both sides of the claim, but we can also use a chain of \"iff\"s:\r\n\\begin{proof}\r\n    $x^2-5x+6=0\\iff (x-2)(x-3)=0\\iff (x=2\\lor x=3)$\r\n\\end{proof}\r\nHowever, if such a proof is to be used, one must make sure that the adjascent statements are indeed equivalent to each other.\r\n\\subsection{Implicit use of assumption}\r\nThe final proof error that we state here would be that sometimes we use an inappropriate assumption in the proof which make it invalid.\r\nConsider the following claim:\r\n\\begin{claim}\r\n    $1$ is the smallest positive real number.\r\n\\end{claim}\r\n\\begin{proof}[Nonsense]\r\n    Let $r$ be the smallest positive real number.\r\n    If $r<1$, then $r^2<r$, contradiction.\r\n    If $r>1$, then $\\sqrt r<r$, contradiction.\r\n    Therefore $r=1$\r\n\\end{proof}\r\nWhy is this nonsense a nonsense?\r\nBecause the proof (and the claim) both used a wrong assumption that there exists a smallest positive real number.\r\nBut there isn't.\r\nActually, the above proof and the fact that $1/2<1$ provides a proof of this fact.\\\\\r\nSo in proofs, we cannot assume, and need to avoid assuming implicitly, anything that might not be correct.\r\nIf you get to assume something, prove it first.\\\\\r\nNow that we are done with proofs, here comes the genuine stuff.", "meta": {"hexsha": "ae43f62c009fb270533d28476f3c87ad54e628b9", "size": 6589, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "0/proofs.tex", "max_stars_repo_name": "david-bai-notes/Numbers-and-Sets", "max_stars_repo_head_hexsha": "2c8ca0c4983c1d575b5f55f2a91d34d6ef534845", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-15T21:17:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-15T21:17:29.000Z", "max_issues_repo_path": "0/proofs.tex", "max_issues_repo_name": "david-bai-notes/Numbers-and-Sets", "max_issues_repo_head_hexsha": "2c8ca0c4983c1d575b5f55f2a91d34d6ef534845", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "0/proofs.tex", "max_forks_repo_name": "david-bai-notes/Numbers-and-Sets", "max_forks_repo_head_hexsha": "2c8ca0c4983c1d575b5f55f2a91d34d6ef534845", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.5980392157, "max_line_length": 204, "alphanum_fraction": 0.7395659432, "num_tokens": 1707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.7129956424814361}}
{"text": "\\section{Elementary operations}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Use elementary operations to simplify a system of equations.\n  \\item Solve some systems of equations by back substitution.\n  \\item Write a system of equations in augmented matrix form.\n  \\item Perform elementary row operations on augmented matrices.\n  \\end{enumerate}\n\\end{outcome}\n\nOur strategy for solving systems of linear equations is to\nsuccessively transform a difficult system of equations into a simpler\nequivalent system. Here, by an ``equivalent'' system of equations we\nmean one that has the same solutions as the original one. We will\nperform the process of simplifying a system of equations by applying\ncertain basic steps called ``elementary operations''.\n\n\\begin{definition}{Equivalent systems}{equivalent-systems}\n  Two systems of equations are called\n  \\textbf{equivalent}%\n  \\index{system of linear equations!equivalence}%\n  \\index{equivalence!system of linear equations}\n  if they have the same solutions. This means that every solution of\n  the first system is also a solution of the second system, and every\n  solution of the second system is also a solution of the first system.\n\\end{definition}\n\nHow can we know whether two systems of equations are equivalent? It\nturns out that the following basic operations always transform a\nsystem of equations into an equivalent system. In fact, these\noperations are the {\\em key tool} we use in linear algebra to solve\nsystems of equations.\n\n\\begin{definition}{Elementary operations}{elementary-operations}\n  \\textbf{Elementary operations}%\n  \\index{elementary operation} are the\n  following operations:\n\n  \\begin{enumerate}\n  \\item Interchange the order in which the equations are listed.\n\n  \\item Multiply any equation by a non-zero scalar.\n\n  \\item Add a multiple of one equation to another equation.\n  \\end{enumerate}\n\\end{definition}\n\nThe most important property of the elementary operations is that they\ndo not change the solutions to the system of equations. Before proving\nthat this is true in general, we will first verify it in an example.\n\n\\begin{example}{Equivalent systems}{equivalent-systems}\n  Show that the systems\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x+2y&=&7 \\\\\n      -2x  &=& -6\n    \\end{array}\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x+2y&=&7 \\\\\n      4y &=& 8\n    \\end{array}\n  \\end{equation*}\n  are equivalent.\n\\end{example}\n\n\\begin{solution}\n  We can see that the second system is obtained from the first one by\n  applying an elementary operation, namely, adding 2 times the first\n  equation to the second equation:\n  \\begin{equation*}\n    -2x + 2(x+2y) = -6 + 2(7)\n  \\end{equation*}\n  By simplifying, we obtain $4y = 8$.\n\n  To verify that the two systems are indeed equivalent, let us first\n  solve the first system. From the second equation, we see that\n  $x=3$. Substituting $x=3$ into the first equation, the equation\n  becomes $3+2y=7$, which we can solve to find $y=2$. Therefore, the\n  only solution to the first system of equations is $(x,y) = (3,2)$.\n\n  Now let us solve the second system. From the second equation, we\n  find that $y=2$. Substituting $y=2$ into the first equation, we get\n  $x+4=7$, which we can solve to find $x=3$. Therefore, the only\n  solution to the second system of equations is $(x,y) = (3,2)$.\n  Since the two systems have the same solutions, they are equivalent.\n\\end{solution}\n\nThis example illustrates how an elementary operation applied to a\nsystem of two equations in two variables does not affect the set of\nsolutions. The same is true for any size of system in any number of\nvariables.  In the following theorem, we use the notation $E_i$ to\nrepresent the left-hand side of an equation, while $b_i$ denotes a\nconstant term.\n\n\\begin{theorem}{Elementary operations and solutions}{elementary-operations-and-solutions}\n  Suppose you have a system of two linear equations in any number of variables\n  \\begin{equation}\n    \\begin{array}{c}\n      E_1=b_1 \\\\\n      E_2=b_2.\n    \\end{array} \\label{system}\n  \\end{equation}\n  Then the following systems are equivalent to \\eqref{system}:\n  \\begin{enumerate}\n  \\item   \\begin{equation}\n      \\begin{array}{c}\n        E_2=b_2 \\\\\n        E_1=b_1.\n      \\end{array}\n      \\label{thm-1.9.1}\n    \\end{equation}\n  \\item  \\begin{equation}\n      \\begin{array}{c}\n        E_1=b_1 \\\\\n        kE_2=kb_2 \\\\\n      \\end{array}\n      \\label{thm-1.9.2}\n    \\end{equation}\n    for any scalar $k$, provided $k\\neq0$.\n  \\item \\begin{equation}\n      \\begin{array}{c}\n        E_1=b_1 \\\\\n        E_2+kE_1=b_2+kb_1\n      \\end{array}\n      \\label{thm-1.9.3}\n    \\end{equation}\n    for any scalar $k$ (including $k=0$).\n\n  \\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\n  \\begin{enumerate}\n  \\item By definition, a solution of \\eqref{system} is an assignment of\n    scalars to the variables that is a solution to $E_1=b_1$ and to\n    $E_2=b_2$. But that is exactly the same thing as a solution of\n    \\eqref{thm-1.9.1}.\n\n  \\item To prove that the systems \\eqref{system} and \\eqref{thm-1.9.2}\n    have the same solution set, let $(x_1,\\ldots,x_n)$ be\n    any solution of \\eqref{system}. Then $E_1=b_1$ and $E_2=b_2$ are\n    both true. Multiplying both sides of the last equation by $k$, we\n    know that $kE_2=kb_2$ is true, and so\n    $(x_1,\\ldots,x_n)$ is a solution of\n    \\eqref{thm-1.9.2}. Conversely, let $(x_1,\\ldots,x_n)$\n    be any solution of \\eqref{thm-1.9.2}.  Then $E_1=b_1$ and $kE_2=kb_2$\n    are true. Because $k\\neq 0$, we are allowed to divide both sides of\n    the last equation by $k$, and therefore $E_2=b_2$ is true. Hence,\n    $(x_1,\\ldots,x_n)$ is also a solution of\n    \\eqref{system}. Since we have shown that every solution of\n    \\eqref{system}  is a solution of \\eqref{thm-1.9.2} and vice versa,\n    the two systems are equivalent.\n\n  \\item To prove that the systems \\eqref{system} and \\eqref{thm-1.9.3}\n    have the same solution set, let $(x_1,\\ldots,x_n)$ be\n    any solution of \\eqref{system}. Then $E_1=b_1$ and $E_2=b_2$ are\n    both true. We multiply both sides of the first equation by $k$ to\n    obtain $kE_1=kb_1$. Then $kE_1+E_2 = kb_1+b_2$, and hence\n    $(x_1,\\ldots,x_n)$ is a solution of\n    \\eqref{thm-1.9.3}. For the converse direction, assume\n    $(x_1,\\ldots,x_n)$ is a solution of $E_1=b_1$ and\n    $kE_1+E_2 = kb_1+b_2$. From the first equation, we have $kE_1=kb_1$,\n    and subtracting this from the second equation, we get $E_2=b_2$,\n    hence $(x_1,\\ldots,x_n)$ is a solution of\n    \\eqref{system}. Note that unlike in case 2., there was no need to\n    divide by $k$, and therefore it was not necessary to require $k\\neq 0$.\n  \\end{enumerate}\n\\end{proof}\n\nWe will now use elementary operations to solve a system of three\nequations and three variables.\n\n\\begin{example}{Solving a system of equations with elementary operations}{solving-a-system-with-elementary-operations}\n  Solve the system of equations\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n      x&+&3y&+&6z&=&25 \\\\\n      2x&+&7y&+&14z&=&58 \\\\\n       &&2y&+&5z&=&19.\n    \\end{array}\n    \\label{solving-a-system1}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  By Theorem~\\ref{thm:elementary-operations-and-solutions}, we can do\n  elementary operations on this system without changing the solution\n  set. We will therefore use elementary operations to try to simplify\n  the system of equations.  First, we add $(-2)$ times the\n  first equation to the second equation. This yields the system\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n      x&+&3y&+&6z&=&25 \\\\\n       &&y&+&2z&=&8 \\\\\n       &&2y&+&5z&=&19.\n    \\end{array}\n    \\label{solving-a-system2}\n  \\end{equation*}\n  Next, we add $(-2)$ times the second equation to the\n  third equation. This yields the system\n  \\begin{equation}\\label{solving-a-system3}\n    \\begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n      x&+&3y&+&6z&=&25 \\\\\n       &&y&+&2z&=&8 \\\\\n       &&&&z&=&3.\n    \\end{array}\n  \\end{equation}\n  At this point, it is easy to find the solution. The last equation\n  tells us that $z=3$. We can substitute this value of $z$ back into\n  the second equation to get\n  \\begin{equation*}\n    y+2(3)=8,\n  \\end{equation*}\n  which we can simplify and solve for $y$ to find that $y=2$. Finally,\n  we can substitute the values $z=3$ and $y=2$ back into the first\n  equation to get\n  \\begin{equation*}\n    x+3(2)+6(3)=25.\n  \\end{equation*}\n  Simplifying and solving for $x$, we find that $x=1$. Hence, the\n  solution to the system is $(x,y,z)=(1,2,3)$.\n\n  The process we followed for solving \\eqref{solving-a-system3} by\n  first computing $z$, then $y$, then $x$ is called \\textbf{back\n    substitution}%\n  \\index{back substitution}.  Alternatively, we could have continued\n  from \\eqref{solving-a-system3} with more elementary operations as\n  follows. Add $(-2)$ times the third equation to the second and then\n  add $(-6)$ times the third to the first. This yields\n  \\begin{equation*}\n    \\allowbreak\n    \\begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n      x&+&3y&&&=&7 \\\\\n       &&y&&&=&2 \\\\\n       &&&&z&=&3.\n    \\end{array}\n  \\end{equation*}\n  Now add $(-3)$ times the second to the first. This yields\n  \\begin{equation*}\n    \\allowbreak\n    \\begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n      x&&&&&=&1 \\\\\n       &&y&&&=&2 \\\\\n       &&&&z&=&3,\n    \\end{array}\n  \\end{equation*}\n  a system which has the same solution set as the original\n  system. This second method avoided back substitution and led to the\n  same solution set. It is your decision which you prefer to use, as\n  both methods lead to the correct solution,\n  $(x,y,z) = (1,2,3)$.\n\\end{solution}\n\nNote how we have written each system of equations so that ``like''\nvariables line up on columns: one column for $x$, one column for $y$,\nand one column for $z$. This makes it easier to perform elementary\noperations. It is often useful to simplify the notation further,\nwriting systems of equations in \\textbf{augmented matrix}%\n\\index{augmented matrix|seealso{matrix}}%\n\\index{matrix!augmented matrix} notation. Recall the\nsystem of equations from Example~\\ref{exa:solving-a-system-with-elementary-operations}:\n\\begin{equation*}\n  \\begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n    x&+&3y&+&6z&=&25 \\\\\n    2x&+&7y&+&14z&=&58 \\\\\n     &&2y&+&5z&=&19.\n  \\end{array}\n\\end{equation*}\nThis system can be written as an augmented matrix as follows:\n\\begin{equation*}\n  \\begin{mymatrix}{rrr|r}\n    1 & 3 & 6 & 25 \\\\\n    2 & 7 & 14 & 58 \\\\\n    0 & 2 & 5 & 19\n  \\end{mymatrix}.\n\\end{equation*}\nA \\textbf{matrix}%\n\\index{matrix} is just a $2$-dimensional array of numbers. An\naugmented matrix has two parts separated by a vertical line. Notice\nthat the augmented matrix notation has exactly the same information as\nthe original system of equations. All the coefficients are written on\nthe left side of the vertical line, and all the constant terms are\nwritten on the right side of the vertical line. These two parts of the\naugmented matrix are also called the \\textbf{coefficient matrix}%\n\\index{coefficient matrix}%\n\\index{matrix!coefficient matrix} and the \\textbf{constant matrix}%\n\\index{constant matrix}%\n\\index{matrix!constant matrix}.  Each row of the augmented matrix\ncorresponds to one linear equation. For example, the top row\n$\\begin{mymatrix}{rrrrr} 1 & 3 & 6 & | & 25\n\\end{mymatrix}$\ncorresponds to the equation\n\\begin{equation*}\n  x+3y+6z=25.\n\\end{equation*}\nEach column of the coefficient matrix contains the coefficients\nfor one particular variable. For example, the first column $\\begin{mymatrix}{r}\n  1 \\\\\n  2 \\\\\n  0\n\\end{mymatrix}$ contains all of the coefficients for the variable $x$. If a\nvariable does not appear in an equation, the corresponding coefficient\nis $0$. In general, the augmented matrix of a linear system of\nequations is defined as follows.\n\n\\begin{definition}{Augmented matrix of a system of linear equations}{augmented-matrix}\n  The \\textbf{augmented matrix}%\n  \\index{augmented matrix}%\n  \\index{matrix!augmented matrix} of the system of linear equations\n  \\begin{equation*}\n    \\begin{array}{c}\n      a_{11}x_1 + \\ldots + a_{1n}x_n = b_1 \\\\\n      \\vdots \\\\\n      a_{m1}x_1 + \\ldots + a_{mn}x_n = b_m\n    \\end{array}\n  \\end{equation*}\n  is\n  \\begin{equation*}\n    \\begin{mymatrix}{ccc|c}\n      a_{11} & \\cdots & a_{1n} &  b_1 \\\\\n      \\vdots &  & \\vdots &  \\vdots \\\\\n      a_{m1} & \\cdots & a_{mn} &  b_m\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{definition}\n\nWe can consider elementary operations in the context of the augmented\nmatrix. The elementary operations can be used on the rows of an\naugmented matrix just as we used them on equations previously. For\nexample, instead of adding a multiple of one equation to another, we\nwill now be adding a multiple of one row to another. Note that\nTheorem~\\ref{thm:elementary-operations-and-solutions} implies that any\nelementary row operation used on an augmented matrix will not change\nthe solutions to the corresponding system of equations. For reference,\nhere are the three kinds of elementary row operations, along with a\nshorthand notation we are going to use for them.\n\n\\begin{definition}{Elementary row operations}{row-operations}\n  The \\textbf{elementary row operations}%\n  \\index{matrix!row operation}%\n  \\index{matrix!elementary row operation}%\n  \\index{row operation}%\n  \\index{elementary row operation} are the\n  following:\n  \\begin{enumerate}\n  \\item Switch two rows. (Notation: $R_i\\rowswap R_j$ to switch\n    rows $i$ and $j$).\n  \\item Multiply a row by a non-zero number.  (Notation: $R_i\\rowop\n    kR_i$ to multiply row $i$ by $k$).\n  \\item Add a multiple of one row to another row. (Notation:\n    $R_i\\rowop R_i+kR_j$ to add $k$ times row $j$ to row $i$.)\n  \\end{enumerate}\n\\end{definition}\n\nWe write ``$\\roweq$'' to indicate that two augmented matrices are\nequivalent, i.e., that the corresponding systems of equations have the\nsame set of solutions.\n\n\\begin{example}{Elementary row operations}{}\n  Repeat the calculations of\n  Example~\\ref{exa:solving-a-system-with-elementary-operations}, using the\n  notations we just introduced.\n\\end{example}\n\n\\begin{solution}\n  We have:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      1 & 3 & 6 &  25 \\\\\n      2 & 7 & 14 &  58 \\\\\n      0 & 2 & 5 &  19\n    \\end{mymatrix}\n    \\stackrel{R_2\\rowop R_2-2R_1}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      1 & 3 & 6 & 25 \\\\\n      0 & 1 & 2 & 8 \\\\\n      0 & 2 & 5 & 19\n    \\end{mymatrix}\n    \\stackrel{R_3\\rowop R_3-2R_2}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      1 & 3 & 6 & 25 \\\\\n      0 & 1 & 2 & 8 \\\\\n      0 & 0 & 1 & 3\n    \\end{mymatrix}.\n  \\end{equation*}\n  The final augmented matrix corresponds to the system\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n      x&+&3y&+&6z&=&25 \\\\\n       &&y&+&2z&=&8 \\\\\n       &&&&z&=&3,\n    \\end{array}\n  \\end{equation*}\n  which is the same as {\\eqref{solving-a-system3}}. We can solve it by back\n  substitution to obtain the solution $x=1$, $y=2$, and $z=3$.\n\n  Alternatively, we can continue with additional row operations:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      1 & 3 & 6 & 25 \\\\\n      0 & 1 & 2 & 8 \\\\\n      0 & 0 & 1 & 3\n    \\end{mymatrix}\n    \\stackrel{R_1\\rowop R_1-6R_3}{\\stackrel{R_2\\rowop R_2-2R_3}{\\roweq}}\n    \\begin{mymatrix}{rrr|r}\n      1 & 3 & 0 & 7 \\\\\n      0 & 1 & 0 & 2 \\\\\n      0 & 0 & 1 & 3\n    \\end{mymatrix}\n    \\stackrel{R_1\\rowop R_1-3R_2}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      1 & 0 & 0 & 1 \\\\\n      0 & 1 & 0 & 2 \\\\\n      0 & 0 & 1 & 3\n    \\end{mymatrix}.\n  \\end{equation*}\n  Notice how this notation is much more succinct than what we used in\n  Example~\\ref{exa:solving-a-system-with-elementary-operations}.\n\\end{solution}\n\nWe end this section with a final word of caution: logically, you can\nonly perform one elementary row operation at a time. For example, it\nwould not be correct to simultaneously add $R_1$ to $R_2$ and add\n$R_2$ to $R_1$. What is permitted is to first add $R_1$ to $R_2$, then\nthen add the {\\em new} $R_2$ to $R_1$. Although we may sometimes try\nto save space by skipping an intermediate step, as in the last example\nwhere we applied the row operations $R_1\\rowop R_1-6R_3$ and\n$R_2\\rowop R_2-2R_3$ in one step, it is important to realize that\nlogically, each row operation must be performed separately before the\nnext one can be done. When in doubt, the only safe course of action is\nnot to skip any steps.\n", "meta": {"hexsha": "9c0cadcfc944043a191e8f55f66b2b699a0aa9e2", "size": 16391, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/SystemsofEquations-ElementaryOperations.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/SystemsofEquations-ElementaryOperations.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/SystemsofEquations-ElementaryOperations.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 37.5080091533, "max_line_length": 118, "alphanum_fraction": 0.6785431029, "num_tokens": 5352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.9019206758704633, "lm_q1q2_score": 0.7129956393106458}}
{"text": "\\chapter{Hull-White Single-Factor Model}\n\\label{chapter:hullwhitemodel}\nThe following chapter will study the Hull-White Single-Factor Model to understand the algorithm behind it and prepare a strategy for a parallel implementation. It will first introduce a general overview of how a trinomial tree is being constructed, and later show how prices are being discounted from it. \n\n\\section{Hull-White Trinomial Tree}\nIn this project, we implement the trinomial tree numerical method to discretize the Hull-White model.  In contrast to the standard trinomial tree, the tree used in the Hull-White model incorporates the mean-reversion of the interest rate, by using a width limit and modified branching methods for the tree. Standard branching (see fig.~\\ref{fig:background:standardbranching}) remains the same throughout the tree. At the bottom of the tree, where interest rates are very low, the \\enquote{up one/straight along/down one} (see fig.~\\ref{fig:background:altbranchingbottom}) branching is used. At the top of the tree, where interest rates are very high, the \\enquote{straight along/down one/down two} branching is used (see fig.~\\ref{fig:background:altbranchingtop}). \n\n\\begin{figure}\n\\centering\n\\begin{subfigure}{.3\\textwidth}\n  \\centering\n  \\includegraphics[width=.7\\linewidth]{img/standardbranch.jpg}\n  \\caption{Standard branching}\n  \\label{fig:background:standardbranching}\n\\end{subfigure}\n\\begin{subfigure}{.3\\textwidth}\n  \\centering\n  \\includegraphics[width=.93\\linewidth]{img/bottombranch.jpg}\n  \\caption{Bottom branching}\n  \\label{fig:background:altbranchingbottom}\n\\end{subfigure}\n\\begin{subfigure}{.3\\textwidth}\n  \\centering\n  \\includegraphics[width=.7\\linewidth]{img/topbranch.jpg}\n  \\caption{Top branching}\n  \\label{fig:background:altbranchingtop}\n\\end{subfigure}\n\\caption{Alternative branching methods for a trinomial tree.}\n\\label{fig:background:allbranchings}\n\\source{Based on Options, Futures and Other Derivatives\\cite[pg. 698]{ofod}.}\n\\end{figure}\n\nWe observe that this pruning characteristic allows us to asses the size of the tree upfront and use this knowledge to enable more specific implementation optimizations, in particular how to map the tree to the parallel device thread and memory architecture. Otherwise, the tree could grow infinitely in its width, making it impossible to map to limited parallel architecture memory resources and invalidating certain parallel implementations.\n\n\\section{Overview}\nPricing a single option using Hull-White short-rate\\footnote{The short rate, \\textit{r}, at time \\textit{t} is the rate that applies to an infinitesimally short period of time at time \\textit{t}\\cite[pg. 682]{ofod}} single-factor trinomial tree model enables the term structure of interest rates at any given time to be obtained from the value of the short rate \\textit{r} at that time and the risk-neutral process for \\textit{r}. This shows that, once the process for \\textit{r} has been defined, everything about the initial zero curve and its evolution through time can be determined\\cite[pg. 683]{ofod}. \n\\\\\\\\\nThe model consists of two steps. The first (forward propagation along the tree) is the construction of the trinomial tree in order to obtain a list of alpha values for each time step. These alphas are later used in the second step (backward propagation along the tree) to fit the option/bond prices and obtain the option value back at the root node of the tree. The input fed to the algorithm consists of an option, which includes its strike price, maturity, time step length, mean-reversion rate\\footnote{denoted as $a$ - determines the relative volatilities of long and short rates\\cite[pg.9]{npfits}} and volatility\\footnote{denoted as $\\sigma$ - determines the overall level of volatility \\cite[pg. 9]{npfits}}. The output is the estimated price of the option/bond. The two steps can be generalized as follows: \n\n\\begin{enumerate}\n    \\item \\textbf{Forward propagation step:} Construct a term structure for the underlying asset by progressing one time step at a time. Determine neutral risk rate for a new time step using estimated yield curve data and estimated current asset values.\n    \\item \\textbf{Backward propagation step:} Discount the asset prices to estimate option payoff at maturity going from the leaves of the tree to its root. \n\\end{enumerate}\n\nAlgorithm~\\ref{alg:loops} shows a high-level overview of a function implementing this procedure for pricing one option. The input of the algorithm is an option and a yield curve (used for the computation of alphas) and the output is the estimated price of the option. The function consists primarily of two sequential (convergence) loops of count tree height, which contain inner parallel operators of count tree width, where tree height and width are specific to each option (and thus vary across options). The tree height is dependent on the number of time steps, i.e., maturity of the underlying bond and precision. The tree width is dependent on the number of terms and input parameters.\n\nDifferent option/bond maturities (leading to different tree heights) and different level of pricing accuracy (number of simulated time steps leading to different tree dimensions) make the choice of an effective parallelization strategy difficult. It is necessary to have a deep understanding of the algorithm itself to achieve maximum parallelization efficiency. The book by John Hull\\cite{ofod} provides a solid background on the topic, describing the mechanics of interest rates, markets, as well as application of binomial trees and eventually trinomial trees to option pricing. Chapter 30 further narrows the topic of using trinomial trees as a numerical method and introduces a step by step walk-through of applying the algorithm on a basic example. While some of the calculation details are omitted in the book, the authors provide references to previous articles\\cite{npfits}\\cite{uhwirt}, where they provide a thorough explanation backed with more detailed examples. \n\n\\newpage\nIt is important to mention that the construction of a trinomial tree is a discrete-time, lattice-based\\footnote{A model that takes into account expected changes in various parameters e.g. interest rate over the duration of the option} numerical method, but the example in the book is simplified by cutting the tree at a certain height and using analytic formulas to produce a concrete result for a specific financial instrument - a zero-coupon bond maturing at time $(m + 1) * \\triangle t$ \\cite[pg. 704]{ofod}. These formulas have been found and proven to be effective by the authors of the book and the articles. While this simplification gives more precise results in the above mentioned specific case, constructing the entire tree and using all of the time steps provides a foundation for pricing other options with more sophisticated cashflows. All the implementations of this thesis will be focused on the described numerical approach.\n\nThe following sub-chapters are focused primarily on the intuition behind the algorithm, with the sole purpose to provide the reader with a general overview for it. For this reason, many of the details and formulas of calculating specific values are omitted, however they are thoroughly described in the book and the articles by Hull and White. As the model is best understood visually, we have included some of the supplementary images from the Hull and White book in order to support our algorithm explanation.\n\n\\newpage\n\\begin{algorithm}[H]\n\\DontPrintSemicolon\n\\caption{High-level overview of pricing a single option using Hull-White Single-Factor Model\\label{alg:loops}}\n\\SetKwInOut{Input}{Input}\n\\SetKwInOut{Output}{Output}\n\n\\Input{Option, YieldCurve}\n\\Output{Price approximation}\n\\;\nalphas[0] = Compute yield at initial interest rate\\;\nQs[0][$\\text{width}/2$] = 1\\tcc*{Initialize the root node to 1\\textdollar}\n\\;\n\\tcc{Forward propagation (convergence) loop}\n\\For{$i = 0$ \\KwTo height} {\n    \\tcc{Compute Qs at the next time step}\n    \\For{$j = 0$ \\KwTo width} {\n        Qs[$\\text{i} + 1$][j] = Compute Q from Qs[i] and alphas[i]\\;\n    }\n    Compute alphas[$\\text{i} + 1$] from Qs[i]\\;\n}\n\\;\n\\tcc{Initialize prices at the last time step to 100\\textdollar}\nPrices[$\\text{height} - 1$] = 100\\;\n\\;\n\\tcc{Backward propagation (convergence) loop}\n\\For{$i = \\mathit{height} - 1$ \\KwTo 0} {\n    \\tcc{Compute prices at the previous time step}\n    \\For{$j = 0$ \\KwTo width} {\n        Prices[i][j] = Compute price from Prices[$\\text{i}+1$] using alphas[i]\\;\n    }\n}\n\\;\n\\tcc{Return price at the root node}\n\\Return Prices[0][$\\text{width}/2$]\\;\n\\end{algorithm}\n\n\\section{Forward Propagation}\n\\label{section:hullwhite:forwardpropagation}\nThe forward propagation by itself consists of two stages. Each of them computes different values on the same tree. While the tree height can grow indefinitely, depending on the number of time steps, the width of the tree is limited by mean-reversion (as reasoned for in chapter \\ref{chapter:background}), by determining its max. width (or as we refer to it for simplicity - width). \n\n\\paragraph{Indexing} Since the tree is 2-dimensional, locating and computing values on individual nodes boils down to locating them by index first. Hence, we introduce the two indexes - \\textit{i} and \\textit{j}, used to indicate the tree height and its width respectively. To describe the meaning of \\textit{i} and \\textit{j} visually, we can use fig. \\ref{fig:treeconststage1}, where nodes along the height - A, C, G - can be indexed as i = 0, 1, 2. Indexing across the width is different, as we intuitively denote the core of the tree - nodes A, C, G - with $j=0$. Going down along the three decreases the value of $j$, while going up increases it. This means that nodes D,H are located on $j=-1$, nodes B,F are located on $j=1$ and so on. We denote the highest node across the width as $j_{max}$ and $j_{min}$ as the lowest. Note that $j_{min}=-j_{max}$ due to the symmetry of the tree, making it possible to omit $j_{min}$ occurrences in our implementations by replacing them with $-j_{max}$. On fig. \\ref{fig:treeconststage1} nodes E and I are at the top and at the bottom of the tree width, hence their $j$ indexes are equal to $j_{max}$ and $j_{min}$ respectively. The index values in this example are $j_{max}=2$ and $j_{min}=-2$. Note that our code cannot always be aligned with our intuition and indexes cannot be negative in our programs. Hence we can shift the indexing between $j_{min}$ and $j_{max}$ and count from $0$ to $2*j_{max}+1$ instead, making the root node to be located at index $j_{max}$. Despite that, we have used $j_{min}$ and $j_{max}$ as width boundaries throughout this report, as they are easier to comprehend.\n\n\\paragraph{Stage 1}\naims to construct a tree for a variable $R^*$ that is initially 0 and follows the Ornstein–Uhlenbeck stochastic\\footnote{With a random probability distribution or pattern that may be analyzed statistically but may not be predicted precisely.} process\\footnote{Tends to drift towards its long-term mean (also called mean-reverting).} $dR^*=-aR^*dt + \\sigma dz$ which is symmetrical about $R^*=0$\\cite[pg.698-699]{ofod}. Together with $R^*$, $p_u$, $p_m$ and $p_d$ are calculated to match the respective up, mid and down probabilities that match the expected change and variance of the change in R over the next interval $\\triangle t$. Since the width of the tree is limited between $j_{min}$ and $j_{max}$, some of the branching is calculated differently, thus $p_u$, $p_m$ and $p_d$ depend on the node position. Naturally the tree construction happens iteratively, node by node, starting from the root. In the end of the stage, this first tree will always have a symmetrical shape\\footnote{Trinomial trees are recombining, meaning that at any time, an up move followed by a down move has exactly the same effect on the price as a down move followed by an up move.} similar\\footnote{Note that the width and height of the tree may differ based on the number of time steps and the maturity of the financial instrument} to fig.\\ref{fig:treeconststage1}. \n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.8\\textwidth]{img/treeconststage1wh.jpg}\n\t\\caption{Example of the trinomial tree for $R^*$.}\n\t\\source{Modified by the authors, based on Options, Futures and Other Derivatives\\cite[pg. 699]{ofod}.}\n\t\\label{fig:treeconststage1}\n\\end{figure}\n\nAn important property of this tree include first of all that it is self-recombining, causing it to be symmetric. The probabilities on the lower part of the tree will be the negative of the probabilities on the upper part of the tree, e.g. probability that node A reaches node D is minus the probability of node A reaching node B. Furthermore, also due to symmetry, all unique probabilities can be stored in an array of size the width of the tree, because e.g. the probability of node A reaching node B is the same as the probability of node C reaching node F and so on. Probabilities are used both in stage 2 of the forward propagation, but also in the backward propagation, thus it is necessary to contain them to the end, if they are to be stored. Last but not least, the way probabilities are calculated is different on $j_{min}$ or $j_{max}$, because of the difference in branching. This can be seen on fig. \\ref{fig:treeconststage1} where nodes E and I branch out differently in comparison to all other nodes. \n\n\\paragraph{Stage 2}\nIn this stage, the rates at each node in the tree at each time step are shifted up by an amount - $\\alpha$, chosen so that the revised tree correctly prices discount bonds \\cite[pg. 6]{uhwirt}. This is done by defining $Q_{i,j}$ as the present value of a security that pays off \\$1 if node (i, j) is reached and 0 otherwise. The starting point is to set $Q_{0,0}=0$ and $\\alpha_0$ to the interest rate at time $\\triangle t$. $Q$s at the next time step are then calculated by using the generalized formula \\cite[pg.705]{ofod}:  \n\\begin{equation}\n\\begin{gathered}\n\\begin{aligned}\nQ_{m+1, j} = \\sum_k Q_{m,k}q(k,j)exp[-(\\alpha_m+k\\triangle r)\\triangle t]\n\\nonumber\n\\end{aligned}\n\\end{gathered}\n\\end{equation}\nAssuming that we start at step $m$, to calculate the $Q$s on step $m+1$, we need to have the $\\alpha$ on step $m$. Furthermore, once the $Q$s on step $m+1$ have been calculated, they are used to also find the $\\alpha$ on $m+1$ later. This leads to conclude that $\\alpha$s and $Q$s are interrelated on each time step. $\\alpha$s are calculated using the generalized formula \\cite[pg.703]{ofod}:\n\\begin{equation}\n\\begin{gathered}\n\\begin{aligned}\n\\alpha_{m} = \\dfrac{\\sum_{j=-n_m}^{n_m} Q_{m,j}e^{-j\\triangle r\\triangle t} - \\ln{P_{m + 1}}}{\\triangle t}\n\\nonumber\n\\end{aligned}\n\\end{gathered}\n\\end{equation}\nAt the end of this stage, the new tree will have changed visually. For example, the tree from fig. \\ref{fig:treeconststage1} can be re-shaped as shown on fig. \\ref{fig:treeconststage2}. \n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.8\\textwidth]{img/treeconststage2.png}\n\t\\caption{Example of the trinomial tree for $R$.}\n\t\\source{Options, futures and other derivatives fig. 30.9 \\cite[pg. 702]{ofod}}\n\t\\label{fig:treeconststage2}\n\\end{figure}\nAn important observation here is that the only outcome of this tree that is used in the backward propagation is the array of $\\alpha$s. $Q$s are in this case intermediary values, used to compute the $\\alpha$ on each step and for this reason, the $Q$ values do not need to be stored any longer once all $\\alpha$s have been computed. \n\n\\section{Backward Propagation}\nThe backward propagation starts with the previously constructed tree during the forward propagation step, in particular with array of $\\alpha$s. At each time-step the option payoff is computed as the discounted value of the expected value at the next step \\cite[pg. 6]{uhwirt}. From this it follows that the nodes at time step $i$ (e.g. the nodes without assigned letters in figures \\ref{fig:treeconststage1} and \\ref{fig:treeconststage2} above) are the starting point of the backward propagation. Their values are set to 100\\$ and are used to compute the previous set of nodes (at time step $i-1$). That is done by discounting bond price values up until the exercise of the option. At the option expiration time step, we decide if we exercise the option or let it expire worthless. To achieve that, we calculate the difference between bond price and the strike price. The positive values mean exercise, while non-positive mean expiry worthless and are set to $0$. We discount the option prices further down to the root of the tree to get the approximation of the option price on the valuation day. This is the output of the algorithm. We use the array of $\\alpha$s computed during the forward propagation through this procedure. It is important to note that determining the option price depends on the type of option (whether it is a put or a call option).\n\n\\section*{Summary}\nThis chapter has provided a detailed overview of the Hull-White Single-Factor Model, in particular its two-stage procedure fo propagating along a trinomial tree. It will be used in the following chapter, which will introduce the challenges of implementing a sequential version of the algorithm in C++.\n", "meta": {"hexsha": "cbbe822a89ea5178d898935eb850e9e2f459f1dd", "size": 17210, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chapters/HullWhiteModel.tex", "max_stars_repo_name": "MartinMetaksov/diku.OptionsPricing", "max_stars_repo_head_hexsha": "1734801dddf7faa9e7c6ed1a46acb6ef8492e33c", "max_stars_repo_licenses": ["ISC"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-01-11T11:13:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-16T10:20:46.000Z", "max_issues_repo_path": "thesis/chapters/HullWhiteModel.tex", "max_issues_repo_name": "MartinMetaksov/diku.OptionsPricing", "max_issues_repo_head_hexsha": "1734801dddf7faa9e7c6ed1a46acb6ef8492e33c", "max_issues_repo_licenses": ["ISC"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thesis/chapters/HullWhiteModel.tex", "max_forks_repo_name": "MartinMetaksov/diku.OptionsPricing", "max_forks_repo_head_hexsha": "1734801dddf7faa9e7c6ed1a46acb6ef8492e33c", "max_forks_repo_licenses": ["ISC"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-09T21:47:46.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-09T21:47:46.000Z", "avg_line_length": 120.3496503497, "max_line_length": 1643, "alphanum_fraction": 0.7736199884, "num_tokens": 4266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.831143060406073, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.71292800336721}}
{"text": "\\input{template.tex}\n\n\\title{Reminder on ordinal arithmetic}\n\n\\newcommand{\\cf}{\\mathrm{cf}}\n\n\\begin{document}\n\n\\maketitle\n\n\\part{Definitions}\n\\section{Well-orders}\nOrdinals are the mother of all well-orders. A total order is called a \\emph{well-order} if one the following equivalent conditions applies\n\\begin{itemize}\n\t\\item Any nonempty set of element has a least element\n\t\\item There is no infinite descending sequence of elements\n\\end{itemize}\nEvery subset of a well-ordered set is again well-ordered. Every element $a \\in P$ that is not maximal has an immediate successor $a^+ = \\min \\{ b : b > a \\}$. Every bounded subset of a well-order has a supremum. For every element $a \\in P$, $a$ is either the minimal element, a \\emph{successor element} ($a = b^+$) or a so-called \\emph{limit element}. In this case, it is the supremum of the elements strictly below it. By the axiom of choice, every set can be well-ordered. \\\\\n\n\\textbf{Proposition} [Trichotomy]\nIf $P,Q$ are two well-orders, then we have the following trichotomy\n\\begin{itemize}\n\t\\item $P$ is order-isomorphic to a proper initial segment of $Q$\n\t\\item $P$ is order-isomorphic to $Q$\n\t\\item A proper initial segment of $P$ is order-isomorphic to $Q$.\n\\end{itemize}\n\nWe call two well-orders \\emph{of the same order-type} if they are order-isomorphic. The order-types are thus totally ordered by `is isomorphic to an initial segment of'. This will turn out to be a well-order.\n\n\\section{Ordinals}\nOrdinal numbers are certain well-ordered sets, serving as distinguished representatives for order-types. For every well-ordered set $P$, there is a unique ordinal $\\alpha$ such that $\\alpha$ and $P$ are order-isomorphic. The proper class of ordinal numbers is well-ordered, and every well-ordered set is order-isomorphic to an initial segment of the ordinal numbers.\n\nWe use the von Neumann-construction of ordinals, i.e. for every ordinal $\\lambda$, we let\n\n\\[ \\lambda = \\{ \\alpha : \\alpha < \\lambda \\} = [0,\\lambda) \\]\n\nas a set. We have for all ordinals $\\alpha,\\lambda$ that\n\\[ \\alpha < \\lambda \\Leftrightarrow \\alpha \\in \\lambda \\Leftrightarrow \\alpha \\subset \\lambda \\Leftrightarrow \\alpha \\text{ proper initial segment of } \\lambda \\]\nThe ordinals are as sets defined recursively via\n\n\\[ \n\\begin{cases}\n\t0 = \\emptyset \\\\\n\t\\alpha^+ = \\alpha \\cup \\{\\alpha\\} \\\\\n\t\\lambda = \\bigcup_{\\alpha < \\lambda} \\alpha\n\\end{cases}\n\\]\n\nFor example we have $2 = \\{0,1\\} = \\{0,\\{0\\}\\} = \\{\\emptyset, \\{\\emptyset\\}\\}$ and we get the first transfinite ordinal $\\omega$ via\n\\[ \\omega := \\bigcup_{n \\text{ finite }} n = \\{0,1,2,\\ldots\\} = \\mathbb N \\]\nand its successor\n\\[ \\omega^+ := \\mathbb N \\cup \\{ \\mathbb N \\} = \\{0,1,2,\\ldots\\, \\mathbb N \\}. \\]\n\nEvery \\emph{set} $\\Gamma$ of ordinals has a supremum in the ordinals, and we use the following three notations interchangably.\n\n\\[ \\sup \\Gamma = \\lim_{\\gamma \\in \\Gamma} \\gamma := \\bigcup_{\\gamma \\in \\Gamma} \\gamma \\]\n\n\\section{Cardinals}\nWe model cardinals as special ordinals, namely we identify every cardinal $\\mathfrak a$ with the least ordinal $\\alpha$ that is in bijection with $\\mathfrak a$. Note that now the cardinal $\\alpha$ is itself the canonical representative of a set of cardinality $\\alpha$, as\n\\[ |\\alpha| = |\\{ \\beta : \\beta < \\alpha \\}| = \\alpha. \\]\n\nNote that $\\omega$ is the first infinite ordinal and thus a cardinal\n\\[ \\omega =: \\aleph_0 \\]\n\nCardinals are again well-ordered, leading to their own notion of cardinal sucessors. We can thus enumerate the infinite cardinals by ordinals\n\\[ \n\\begin{cases}\n\t\\aleph_0 = \\omega \\\\\n\t\\aleph_{\\alpha^+} = (\\aleph_\\alpha)^+ \\\\\n\t\\aleph_\\lambda = \\bigcup_{\\alpha < \\lambda} \\aleph_\\alpha\n\\end{cases}\n\\]\n\nWe let $\\omega_{\\alpha} = \\aleph_{\\alpha}$, so e.g. $\\omega_1$ is the first uncountable ordinal. \\\\\n\n\\textbf{Nonexample:} Let's appreciate some of the non-intuitiveness of $\\omega_1$. It is an uncountable well-ordered set, but every initial segment is countable. Unlike $\\omega = \\sup \\{0,1,2,\\ldots\\}$, $\\omega_1$ is not the supremum of any countable subset. Let $\\omega_1 = \\sup \\Gamma, \\Gamma \\subseteq \\omega_1$ countable, then\n\\[ \\omega_1 = \\bigcup \\Gamma, \\] thus $\\omega_1$ is countable union of countable sets, hence countable; contradiction. \n\n\\section{Cofinality}\nThe phenomenon from above is captured by the notion of cofinality. A subset $N \\subseteq P$ of an ordered set is called \\emph{cofinal} if \n\\[ \\forall p \\in P \\exists n \\in N : p \\leq n. \\]\nThe cofinality $\\cf(P)$ is the least cardinality of a cofinal subset of $P$. We have $\\cf(P) = 1$ iff $P$ has a maximial element, otherwise at least $\\cf(P) \\geq \\omega$. \\\\\n\nFor an ordinal $\\alpha$, $\\cf(\\alpha)$ is the least cardinality of a subset $\\Gamma \\subseteq \\alpha$ with $\\alpha = \\sup \\Gamma$. We have shown that $\\cf(\\omega_1) = \\omega_1$. \\\\\n\nA cardinal $\\lambda$ is called \\emph{regular} iff $\\cf(\\lambda) = \\lambda$. \\\\\n\n\\textbf{Proposition: } For every successor cardinal $\\alpha$, $\\aleph_\\alpha$ is regular. For every limit ordinal $\\lambda$, we have $\\cf(\\aleph_\\lambda) = \\cf(\\lambda)$ instead. \\\\\n\n\\textbf{Example: } $\\aleph_\\omega$ is not regular, as \n\\[ \\cf(\\aleph_\\omega) = \\cf(\\omega) = \\omega. \\] \nIn fact, by definition $\\aleph_\\omega = \\sup \\{ \\aleph_0, \\aleph_1, \\ldots \\}$ is supremum of a countable subset. \n\n\\section{Topology}\nOn every totally ordered set, there is an induced topology called the \\emph{order topology} given by the basis of open rays and open intervals. For example, the order topology on $\\mathbb R$ with the usual order is just the euclidean one.\n\nEvery ordinal $\\alpha$ becomes a topological space of its own in the order topology. For example the ordinal $\\omega$ is homeomorphic to the subspace $\\mathbb N \\subset \\mathbb R$, whereas $\\omega^+$ is homeomorphic to\n\\[ \\{ 1 - 1/n : n = 1,2, \\ldots\\} \\cup \\{ 1 \\}. \\]\nAt some point, larger ordinals will not be metric spaces any more. \\\\\n\n\n\\pagebreak \n\n\\part{Ordinal arithmetic}\n\\section{Addition}\nOrdinal arithmetic is defined recursively with recursion on the right operand. This leads to a certain asymmetry and enforces certain rules only on the right side.\n\n\\[ \n\\begin{cases}\n\t\\alpha + 0 = \\alpha \\\\\n\t\\alpha + (\\beta^+) = (\\alpha + \\beta)^+ \\\\\n\t\\alpha + \\lambda = \\bigcup_{\\beta < \\lambda} \\alpha + \\beta\n\\end{cases}\n\\]\n\n\\textbf{Proposition: } Addition is strictly monotonic and continuous in the right argument. Addition is associative\n\n\\textbf{Non-examples: } Addition is merely non-decreasing in the left argument and not continuous. Addition is not commutative.\n\nWe have \n\\[ 2 + \\omega = \\bigcup_{n < \\omega} 2 + n = \\sup \\{ 2, 3, 4, \\ldots \\} = \\omega. \\]\nFrom there, we get $0 + \\omega = \\omega = 2 + \\omega$ and $\\omega + 2 \\neq 2 + \\omega$. Regarding continuity\n\\[ \\omega + 2 = \\sup \\{0,1,2,\\ldots\\} + 2 \\neq \\sup \\{0 + 2, 1 + 2, \\ldots\\} = \\omega. \\]\n\n\\textbf{Proposition} Let $P,Q$ be two well-orders with order types $\\alpha,\\beta$. Then $\\alpha+\\beta$ is the order type of the well-order on $P \\sqcup Q$ where every element of $P$ comes before every element of $Q$. E.g.\n\n\\[ \\omega + \\omega + 1 \\cong \\{ 0 < 1 < 2 < \\ldots 0' < 1' < 2' < \\ldots 0'' \\} \\]\n\n\\section{Ordinal multiplication}\nWe define multiplication by continuity and distributivity on the right.\n\n\\[ \n\\begin{cases}\n\t\\alpha \\cdot 0 = 0 \\\\\n\t\\alpha \\cdot (\\beta + 1) = (\\alpha \\cdot \\beta) + \\alpha \\\\\n\t\\alpha \\cdot \\lambda = \\bigcup_{\\beta < \\lambda} \\alpha \\cdot \\beta\n\\end{cases}\n\\]\n\n\\textbf{Proposition: } Multiplication is strictly monotonic and continuous on the right and associative. $1$ is both-sided identity.\n\n\\textbf{Non-examples: } Multiplication is merely non-decreasing in the left argument and not continuous. Multiplication is not commutative and not distributive in the left argument. \\\\\n\nWe have $\\omega \\cdot 2 = \\omega + \\omega$, whereas\n\n\\[ 2 \\cdot \\omega = \\bigcup_{n<\\omega} 2\\cdot n = \\sup \\{ 0, 2, 4, \\ldots \\} = \\omega. \\]\n\nTherefore we get $\\omega \\cdot 2 \\neq 2 \\cdot \\omega$ and $1\\cdot \\omega = 2\\cdot \\omega \\neq (1+1)\\times \\omega$. Regarding continuity, \n\\[ \\omega \\cdot \\omega = \\sup \\{ 1, 2, 3, \\ldots \\} \\cdot \\omega \\neq \\sup \\{ 1 \\cdot \\omega, 2 \\cdot \\omega, 3 \\cdot \\omega, \\ldots \\} = \\sup \\{ \\omega, \\omega, \\omega, \\ldots \\}. \\]\n\n\\textbf{Proposition: } Let $P,Q$ be two well-orders with order types $\\alpha,\\beta$. Then $\\alpha \\cdot \\beta$ is the order type of $P \\times Q$ regarded as $Q$ copies of $P$ (reverse lexical order), i.e.\n\n\\[ \\omega\\cdot 2 \\cong \\{ 0 < 1 < 2 < \\ldots 0' < 1' < 2' < \\ldots \\} \\cong \\omega + \\omega \\]\n\nwhereas\n\n\\[ 2 \\cdot \\omega \\cong \\{ 0 < 1 < 0' < 1' < 0'' < 1'' < \\ldots \\} \\cong \\omega \\]\n\n\\section{Ordinal exponentiation}\nOrdinal exponentation is defined recursively with continuity and the power-law $\\alpha^{\\beta + \\gamma} = \\alpha^\\beta \\cdot \\alpha^\\gamma$ in mind.\n\n\\[ \n\\begin{cases}\n\t\\alpha^0 = 1 \\\\\n\t\\alpha^{\\beta + 1} = \\alpha^\\beta \\cdot \\alpha \\\\\n\t\\alpha^\\lambda = \\bigcup_{\\beta < \\lambda} \\alpha^\\beta\n\\end{cases}\n\\]\n\n\\textbf{Proposition} Exponentation is strictly monotonic and continuous in the exponent. It respects multiplication in the exponent, i.e. $\\alpha^{\\beta\\gamma} = (\\alpha^\\beta)^\\gamma$.\n\n\\textbf{Non-examples: } Exponentiation is merely non-decreasing and not continuous in the base. It does not respect multiplication in the base.\n\nFirst of all, for all $1 < k < \\omega$ we have\n\\[ k^\\omega = \\sup \\{ k^n : n < \\omega \\} = \\omega \\]\nThus $2^\\omega = 3^\\omega$. Also \n\\[ \\omega^2 \\neq \\sup \\{ n^2 : n < \\omega \\} = \\omega. \\]\nRegarding multiplication in the base, using associativity, we get\n\\[ (\\omega \\cdot 2)^2 = (\\omega \\cdot 2)(\\omega \\cdot 2) = \\omega \\cdot (2\\omega) \\cdot 2 = \\omega \\cdot \\omega \\cdot 2 = \\omega^2 \\cdot 2. \\]\n\nBut then $(\\omega \\cdot 2)^2 \\neq \\omega^2 \\cdot 2^2 = \\omega^2 \\cdot 4$. \n\n\\textbf{Proposition}\nLet $P,Q$ be two well-orders with order types $\\alpha, \\beta$. Then $\\alpha^\\beta$ is the order type of the set of function with finite support $\\alpha^{(\\beta)}$ in reverse lexical order.\n\n\\section{Fixed-points}\nConsider the power towers\n\\[ \\omega \\uparrow\\uparrow 1 = \\omega, \\omega \\uparrow \\uparrow (n + 1) = \\omega^{\\omega \\uparrow \\uparrow n}. \\]\nWe define their supremum as \n\\[ \\epsilon_0 := \\sup \\{ \\omega \\uparrow \\uparrow n : n < \\omega \\}. \\]\n\\textbf{Proposition: } $\\epsilon_0$ satisfies the equation $\\omega^{\\epsilon_0} = \\epsilon_0$.\n\nBy continuity in the exponent, we get\n\\[ \\omega^{\\epsilon_0} = \\sup_{n < \\omega} \\left(\\omega^{\\omega \\uparrow \\uparrow n}\\right) = \\sup_{n < \\omega} (\\omega \\uparrow \\uparrow (n+1)) = \\epsilon_0 \\]\nand $\\epsilon_0$ is the least fixed point of $\\omega^\\cdot$. \\\\ \n\n\\textbf{Proposition} $\\epsilon < \\omega_1$, i.e. $\\epsilon_0$ is still countable.\nThis is because for infinite ordinals of cardinality at most $\\kappa$, all arithmetic operations still produce ordinals of size at most $\\kappa$. Note that by our constructions, the resulting ordinals are in bijection with just sums, products and functions with finite support of their underlying sets. \nNow\n\\[ \\epsilon_0 = \\bigcup_{n < \\omega} \\omega \\uparrow \\uparrow n \\]\nis countable union of countable sets, thus countable. \\\\\n\nNote that we can produce other fixed-points for the continuous arithmetical operations in the very same fasion\n\n\\begin{align*}\n\\omega^{\\epsilon_0} &= \\epsilon_0 \\\\\n\\omega\\cdot \\omega^\\omega &= \\omega^\\omega \\\\\n\\omega + \\omega^2 &= \\omega^2 \\\\\n1 + \\omega &= \\omega.\n\\end{align*}\n\n\\section{Cantor normal form}\nThe ordinals in the interval $[0,\\epsilon_0)$ are closed under ordinal addition, multiplication and exponentation. Every number $\\alpha$ in that interval can be expressed as a unique so-called \\emph{Cantor normal form} (CNF). \n\\[ \\alpha = \\omega^{\\beta_1}c_1 + \\ldots + \\omega^{\\beta_n}c_n \\]\nwhere $\\alpha > \\beta_1 > \\ldots > \\beta_n$ and $c_i \\in \\mathbb N$. \nWe can recursively transform the exponents $\\beta_i$ in CNF and get a hereditary representation in base $\\omega$ after finitely many steps. We see that $[0,\\epsilon_0)$ is actually generated by the natural numbers and $\\omega$ under the arithmetical operations.  Arithmetic in CNF has simple computational descriptions.\n\n\\subsection{Order}\nCNFs can be compared lexicographically. Highest exponents first, then coefficients. \n\n\\subsection{Addition}\nWe see that\n\\[\n\\omega^\\beta c + \\omega^{\\beta'}c' = \\begin{cases}\n\t\\omega^\\beta c + \\omega^{\\beta'}c' & \\text{ if } \\beta > \\beta' \\\\\n\t\\omega^\\beta (c+c') & \\text{ if } \\beta = \\beta' \\\\\n\t\\omega^{\\beta'}c' & \\text{ if } \\beta < \\beta'\n\\end{cases}\n\\]\nIf exponents are decreasing, they are already in CNF. If exponents are the same, simplify. If exponents are increasing, the bigger term absorbs the smaller one.\n\\textbf{Example}\n\\[ \\omega^2 + \\omega^3 = \\omega^2 + \\omega^2\\omega = \\omega^2(1+\\omega) = \\omega^2\\omega = \\omega^3. \\]\nThus in order to add a term to a CNF, insert it at the correct position, simplify and drop all further terms.\n\n\\subsection{Multiplication}\nMultiplication is distributive on the right. Thus we just need to understand how to multiply a CNF with a single term on the right. Let\n\\[ \\alpha = \\omega^{\\beta_1}c_1 + \\ldots + \\omega^{\\beta_n}c_n \\]\nthen for $\\beta > 0$\n\\[ \\alpha \\cdot \\omega^\\beta = (\\omega^{\\beta_1}c_1 + \\ldots + \\omega^{\\beta_n}c_n) \\cdot \\omega^\\beta = \\omega^{\\beta_1 + \\beta}. \\]\nThrough repeated summation, we get for $n \\in \\mathbb N \\setminus \\{0\\}$\n\\[ \\alpha \\cdot n = \\omega^{\\beta_1}c_1 n + \\ldots + \\omega^{\\beta_n}c_n. \\]\nSo multiplication just acts on the highest term. \\textbf{For example}\n\\[ (\\omega^3 + \\omega^2)\\cdot 3 = \\omega^3 + \\omega^2 + \\omega^3 + \\omega^2 + \\omega^3 + \\omega^2 = \\omega^3\\cdot 3 + \\omega^2. \\]\nIn the limit case, we get\n\\begin{align*}\n (\\omega^3 \\cdot 2 + \\omega^2)\\omega &= \\sup_{n < \\omega} (\\omega^3 \\cdot 2 + \\omega^2)n \\\\\n &= \\sup_{n < \\omega} (\\omega^3 \\cdot 2n + \\omega^2) \\\\\n &= \\omega^3 \\omega = \\omega^4.\n\\end{align*}\n\n\\subsection{Exponentiation}\nExponentiation with base $\\omega$ is easy. For any $\\beta$ in CNF, $\\omega^\\beta$ is already in CNF. Exponentiation with arbitrary base is more complicated. Let again\n\n\\[ \\alpha = \\omega^{\\beta_1}c_1 + \\ldots + \\omega^{\\beta_n}c_n \\]\n\nBy the power laws\n\\[\n \\alpha^{\\beta + \\gamma} = \\alpha^\\beta \\cdot \\alpha^\\gamma, \\quad \\alpha^{\\beta \\gamma} = (\\alpha^\\beta)^\\gamma, \\]\nwe only need to unterstand taking powers with a single term. We distinguish finite and transfinite terms. \n\n\\subsubsection{Finite exponents}\nFor $0 < r < \\omega$, we can compute $\\alpha^r$ by repeated multiplication. \\\\\n\n\\subsubsection{Transfinite exponents}\nFor exponents $\\omega^\\beta$ with $\\beta > 0$, first distinguish if $\\alpha$ is finite. If it is, note that\n\\[ \\alpha^\\omega = \\omega, \\]\nso if $\\beta$ is finite, then\n\\[ \\alpha^{\\omega^\\beta} = \\omega^{\\omega^{\\beta-1}}. \\]\nIf $\\beta$ is transfinite, then $\\beta = 1 + \\beta$, so\n\\[ \\alpha^{\\omega^\\beta} = \\alpha^{\\omega^{1+\\beta}} = \\alpha^{\\omega\\omega^\\beta} = \\omega^{\\omega^\\beta}. \\]\nIf $\\alpha$ is transfinite, we simply get \n\\[ \\alpha^{\\omega^\\beta} = \\omega^{\\beta_1\\omega^\\beta}. \\]\n\n\\textbf{Example}\n\\begin{align*}\n(\\omega^2 \\cdot 2)^\\omega &= \\sup_{n<\\omega} (\\omega^2 \\cdot 2)^n \\\\\n&= \\sup_{n < \\omega} \\omega^{2n}\\cdot 2 \\\\\n&= \\omega^\\omega. \n\\end{align*}\n\n\\section{Goodstein's sequence}\nGoodstein's theorem is a very surprising theorem in number theory. Fix a basis $b \\geq 2$. Take any number $n$ and write it in base-$b$,\n\\[ n = b^{k_1}c_1 + \\ldots + b^{k_\\ell} c_\\ell. \\]\nNow $n > k_1 > \\ldots > k_\\ell$, so we can write the exponents in base-$b$ again and obtain a hereditary base-$b$ representation. \\textbf{Example}\n\\[ 13 = 8 + 4 + 1 = 2^3 + 2^2 + 1 = 2^{2+1} + 2^2 + 1. \\]\n\nFix a number $n$. We define the \\emph{Goodstein sequence} $g^n(2), g^n(3), \\ldots$ recursively. Let $g^n(2) = n$. Now write $g^n(2)$ in hereditary base-$2$ and bump the base, i.e. replace all $2$s by $3$s. Subtract one. That gives us $g^n(3)$. Repeat that, so in general\n\\[ g^n(b+1) = \\text{ write $g^n(b)$ in base-$b$, replace $b\\to b+1$, subtract $1$}. \\]\n \\textbf{For example}\n\\begin{align*}\n\tg^4(2) &= 4 = 2^2 \\\\\n\tg^4(3) &= 3^3 - 1 = 26 \\\\\n\t       &= 3^2\\cdot 2 + 3\\cdot 2 + 2 \\\\\n\tg^4(4) &= 4^2 \\cdot 2 + 4 \\cdot 2 + 1 \\\\\n\tg^4(5) &= 5^2 \\cdot 2 + 5 \\cdot 2 \\\\\n\tg^4(6) &= 6^2 \\cdot 2 + 6 \\cdot 2 - 1 \\\\\n\t       &= 6^2 \\cdot 2 + 6 + 5 \\\\\n\tg^4(7) &= 7^2 \\cdot 2 + 7 + 4\n\\end{align*}\nThe numerical values of this sequence are\n\\[ 4, 26, 41, 60, 83, 109, \\ldots \\]\n\\textbf{Theorem: }[Goodstein] For every integer $n$, the Goodstein sequence $g^n$ eventually becomes $0$. \\\\\n\nThe thing is: This takes long, extreemly, ridiculously long. The Goodstein function $G : \\mathbb N \\to \\mathbb N$\n\\[ G(n) = \\min \\{ b : g^n(b) = 0 \\} \\]\nis one of the fastest-growing functions ocurring in mathematics. We have\n\\[ G(3) = 7, \\] that is $g^3$ terminates at base $7$. How long might $g^4$ need? We have\n\\[ G(4) = 3\\cdot 2^{402653211}-1. \\]\nThat is a number with roughly 121 million \\emph{decimal digits}. The numbers of the sequence are of the same order of magnitude. Even though the numbers seem to get larger and larger, something forces them to become 0 at the end. They seem to lose some complexity throughout the operations. We can precisely pin down this complexity using ordinals and CNF. \\\\\n\n\\textbf{Proof of Goodstein's theorem} We know how the number $g^n(b)$ can be written in hereditary base-$b$. Define a second sequence $w^n(b)$ of ordinals in CNF by taking that representation and replacing $b$ with $\\omega$. For example\n\n\\begin{align*}\n\tw^4(2) &= \\omega^\\omega \\\\\n\tw^4(3) &= \\omega^2 \\cdot 2 + \\omega \\cdot 2 + 2 \\\\\n\tw^4(4) &= \\omega^2 \\cdot 2 + \\omega \\cdot 2 + 1 \\\\\n\tw^4(5) &= \\omega^2 \\cdot 2 + \\omega \\cdot 2 \\\\\n\tw^4(6) &= \\omega^2 \\cdot 2 + \\omega + 5\n\\end{align*}\n\nThis sequence of ordinals is strictly decreasing, thus can only have finite length. So $g^n$ can only have finitely many elements before stabilizing at zero.\n\\end{document}", "meta": {"hexsha": "49bceae82831bf8f762f00cecf54ebb87f09d2e4", "size": 17817, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/ordinals.tex", "max_stars_repo_name": "damast93/ordinals", "max_stars_repo_head_hexsha": "cbf82f1916b37132c3da4ca17a31465859ab2260", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/ordinals.tex", "max_issues_repo_name": "damast93/ordinals", "max_issues_repo_head_hexsha": "cbf82f1916b37132c3da4ca17a31465859ab2260", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/ordinals.tex", "max_forks_repo_name": "damast93/ordinals", "max_forks_repo_head_hexsha": "cbf82f1916b37132c3da4ca17a31465859ab2260", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.3322981366, "max_line_length": 477, "alphanum_fraction": 0.6766571252, "num_tokens": 5777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7129279995934154}}
{"text": "\\chapter{Replacements for t-tests and ANOVA}\nANOVA is a common procedure in classical statistics, and is related to the\nsimpler idea of a t-test. These classical tests were designed for particular\nkinds of problems, and in this chapter we will study similar problems but\nsolve them from a Bayesian point of view.\nWe will also use these examples to discuss some issues about the choice\nof prior distributions when there are more than a few parameters. When there\nare only a few parameters it is usually safe to assign a vague, wide prior\nto describe your initial uncertainty (unless, of course, you have more\ninformation than that). In higher dimensions, problems can arise if you do\nthis. One way of getting around these problems is to use a\n{\\it hierarchical model}.\n\n\\section{A T-Test Example}\nThis example is based on one given in a 1976 article by physicist E. T. Jaynes,\ncalled ``Confidence Intervals vs. Bayesian Intervals''. This is a very strongly\nworded paper and might be an interesting read for\nthose who are interested in the battle between frequentist and Bayesian statistics\nwhen the latter was making its comeback in the second half of the 20th century.\nIt's also where I got the crazy confidence interval example from.\n\nTwo manufacturers, $1$ and $2$, both make ``widgets'', and we are interested\nin figuring out which manufacturer makes the best widgets (on average), as\nmeasured by their lifetime. To determine this, we obtain 9 widgets from\nmanufacturer $1$ and 4 widgets from manufacturer $2$, and measure their\nlifetimes, in days. The results are given below:\n\\begin{eqnarray}\nx^1 &=& \\{41.26, 35.81, 36.01, 43.59, 37.50, 52.70, 42.43, 32.52, 56.20\\}\\\\\nx^2 &=& \\{54.97, 47.07, 57.12, 40.84\\}\n\\end{eqnarray}\nThese measurements can be summarised by the means and standard deviations, which\nare $42 \\pm 7.48$ for group $1$ and $50 \\pm 6.48$ for group $2$.\nThe question is: given this data, is there evidence that one of the manufacturers\nis better than the other, and if so, by how much?\nIn classical statistics the standard procedure for this situation would be a\ntwo sample $t$0-test. However, before we do anything I'd like you to consider\nthe numbers and use your intuition: what do {\\it you} think about what the\nevidence says?\n\nAn underlying assumption of a classical $t$-test is that the data are normally\ndistributed around the mean values for each group\\footnote{Strictly speaking,\nit's the probability distribution for the data given the parameters\nthat is normal, the data may or may not look normally distributed.}.\nWe may as well adopt this\nassumption for our Bayesian model. If we call the group 1\ndata points $\\{x^1_1, x^1_2, ..., x^1_{N_1}\\}$ and the group 2 data points\n$\\{x^2_1, x^2_2, ..., x^2_{N_1}\\}$, then the likelihood is:\n\\begin{eqnarray}\nx^1_i &\\sim& \\mathcal{N}\\left(\\mu_1, \\sigma^2\\right)\\nonumber\\\\\nx^2_i &\\sim& \\mathcal{N}\\left(\\mu_2, \\sigma^2\\right)\\label{eq:ttest_likelihood}\n\\end{eqnarray}\nWhere all the data points are independent given the parameters. Note the assumption that\nthe two groups have the same underlying (``population'') standard deviation $\\sigma$. This is a popular\nassumption in this kind of analysis but it is not necessarily well justified!\nWe will build our Bayesian models using this assumption, but it is not that\ndifficult to relax it if you want to. You could just include multiple\n$\\sigma$ parameters in the model,\njust like how we will include the multiple $\\mu$ parameters.\n\nInstead of just one model for this situation, we will study three different\nversions. Each model will have the same likelihood\nas given above in Equation~\\ref{eq:ttest_likelihood}, and the same prior\nfor $\\sigma$. However, the models will all have different priors for $\\mu_1$\nand $\\mu_2$.\nWe will be able to see that the choice of prior does\ninfluence the results (of course), but in ways that make sense. Which of these\nmodels is more appropriate in a practical situation would depend on the exact\nsituation. There is no ``one size fits all'' model.\n\n\\subsection{Likelihood}\nTo implement our model in JAGS, we can begin by specifying the likelihood\npart like so:\n\n\\begin{minted}[mathescape,\n               numbersep=5pt,\n               gobble=0,\n               frame=single,\n               framesep=2mm, fontsize=\\small]{r}\n# Sampling distribution/likelihood\nfor(i in 1:N1)\n{\n  x1[i] ~ dnorm(mu1, 1/sigma^2)\n}\nfor(i in 1:N2)\n{\n  x2[i] ~ dnorm(mu2, 1/sigma^2)\n}\n\\end{minted}\nWe have called our data arrays {\\tt x1} and {\\tt x2}, and we have also\nassumed that the sample sizes {\\tt N1} and {\\tt N2} are defined, so our\n{\\tt data} list will need to be consistent with these choices. The parameters\nwe will be estimating are {\\tt mu1}, {\\tt mu2}, and {\\tt sigma}, so we will\nneed to specify prior distributions for them. In the following sections, we'll\nuse the same prior for {\\tt sigma}, so we may as well specify that now.\nLet's use a log-uniform prior where $\\sigma$ is between $e^{-10}$ and\n$e^{10}$.\n\n\\begin{minted}[mathescape,\n               numbersep=5pt,\n               gobble=0,\n               frame=single,\n               framesep=2mm, fontsize=\\small]{r}\n# Prior for sigma\nlog_sigma ~ dunif(-10, 10)\nsigma <- exp(log_sigma)\n\\end{minted}\n\n\\subsection{Prior 1: Very Vague}\nThe last missing ingredients to finish the JAGS model are the priors for\n{\\tt mu1} and {\\tt mu2}. For our first model, let's be really naive and assign\nsuper-wide uniform priors.\n\n\\begin{minted}[mathescape,\n               numbersep=5pt,\n               gobble=0,\n               frame=single,\n               framesep=2mm, fontsize=\\small]{r}\n# Prior 1: Very Vague\nmu1 ~ dnorm(0, 1/1000^2)\nmu2 ~ dnorm(0, 1/1000^2)\n\\end{minted}\n\nAt first glance, this might seem like a fairly reasonable thing to do. In many\nproblems, it doesn't make much difference if we just use vague priors and get\non with the calculation (as opposed to thinking really hard about the prior,\nand what is actually known about the parameters).\n\nHowever, this prior has a number of properties that suggest it might not be\nquite right: firstly, what is the probability that $\\mu_1 = \\mu_2$?\nIn classical t-tests, the whole point is to test the hypothesis that\nthe two ``population means'' (parameters) are equal. However, our prior\nactually implies that the probability they are equal is 0! Therefore, no matter\nwhat data we get, the posterior probability of $\\mu_1 = \\mu_2$ will always be\nzero.\n\n\\subsection{Prior 2: They might be equal!}\nThe problem with Prior 1 is that we may think $\\mu_1$ might exactly equal\n$\\mu_2$, and Prior 1 doesn't allow for this. So here's another way we might\nset up the prior. We'll start by defining the prior for $\\mu_1$ as we did\nbefore. Then, when we consider $\\mu_2$, we need a way of giving it a\n50\\% probability of equalling $\\mu_1$, and if not, then it should have\na ``bi-exponential'' distribution centered around $\\mu_1$.\nHere is our solution. Read it carefully and make sure you understand what this\nprior does.\n\n\\begin{minted}[mathescape,\n               numbersep=5pt,\n               gobble=0,\n               frame=single,\n               framesep=2mm, fontsize=\\small]{r}\n# First mean\nmu1 ~ dnorm(0, 1/1000^2)\n\n# Prior for difference, mu2 - mu1\nu ~ dunif(-1, 1)\n\n# Length of exponential prior given difference != 0\nL <- 5\nsize_of_difference <- step(u)*(-L*log(1 - u))\n\n# To make the difference positive or negative\nC ~ dbin(0.5, 1)\ndifference <- (2*C - 1)*size_of_difference\n\n# Second mean\nmu2 <- mu1 + difference\n\\end{minted}\n\n\\subsection{Prior 3: Alright, they're not equal, but they might be {\\it close}}\nPrior 2 is also a little bit strange, if you think about it. If we're comparing\nthese two manufacturers of widgets, why would we think it is possible that the\ntwo manufacturers are {\\tt exactly} equal? Maybe we just think the parameters\n$\\mu_1$ and $\\mu_2$ are likely to be {\\it similar} in value.\nIn other words, we shouldn't worry so much about the\nprior probablity of $\\mu_1 = \\mu_2$, but we should at least make sure there's\na moderate prior probability that $\\mu_1 \\approx \\mu_2$.\n\nOne way we could do this is by applying a normal prior to both $\\mu_1$ and\n$\\mu_2$ with some mean (let's call it the ``grand mean'')\nand some standard deviation (let's call it the ``diversity'').\nThat way, $\\mu_1$ and\n$\\mu_2$ would both be likely to be somewhere around the grand mean, and\nthey would likely be different by roughly the size of the diversity.\nThe challenge now seems to be the choice of appropriate values for the grand\nmean and the diversity. Fortunately, we don't actually have to! What we can\ndo instead is apply priors for them instead.\n\nThis is our first example of a {\\it hierarchical model}. In a hierarchical\nmodel, instead of directly assigning priors to our parameters, we imagine that\nwe knew the values of some other parameters (called ``hyperparameters''), and\nassign our prior for the parameters {\\it given} the hyperparameters. Then we\nassign a prior for they hyperparameters as well, to complete the model.\n\n\\begin{minted}[mathescape,\n               numbersep=5pt,\n               gobble=0,\n               frame=single,\n               framesep=2mm, fontsize=\\small]{r}\n# Hierarchical prior for the means\n# Hyperparameters\ngrand_mean ~ dnorm(0, 1/1000^2)\nlog_diversity ~ dunif(-10, 10)\ndiversity <- exp(log_diversity)\n\n# Prior for the parameters given the hyperparameters\nmu1 ~ dnorm(grand_mean, 1/diversity^2)\nmu2 ~ dnorm(grand_mean, 1/diversity^2)\n\\end{minted}\n\nSamples (obtained using JAGS) of the three priors are shown in\nFigure~\\ref{fig:ttest1}.\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.8]{Figures/ttest1.pdf}\n\\caption{\\it The three different priors we are trying for our Bayesian\nequivalent of a t-test. The first prior simply asserts a large amount of\nprior ignorance about the value of the two parameters $\\mu_1$ and $\\mu_2$.\nThe second is similar but applies 50\\% probability to the proposition\n$\\mu_1 = \\mu_2$. The third prior does not allow the two parameters to be\nexactly equal, but enhances the probability that they are quite similar\nin value.\\label{fig:ttest1}}\n\\end{center}\n\\end{figure}\n\nThe posteriors are shown in Figure~\\ref{fig:ttest2}.\nThe inferences are different, as you would expect, and that's entirely down\nto the choice of the prior. Any summaries we make will therefore depend on\nwhich prior we want to use.\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.8]{Figures/ttest2.pdf}\n\\caption{\\it The posterior distributions, given the widget data,\nbased on the three different priors for $\\mu_1$ and $\\mu_2$.\\label{fig:ttest2}}\n\\end{center}\n\\end{figure}\n\nThe original question was whether manufacturer two was better, equal, or worse\nthan manufacturer one. We can answer that question by calculating the\nposterior probabilities of $\\mu_1 = \\mu_2$, $\\mu_1 < \\mu_2$, and\n$\\mu_1 > \\mu_2$. The results are shown in Table~\\ref{tab:ttest_results}.\n\n\\begin{table}\n\\begin{center}\n{\\bf Prior Probabilities}:\\\\\n\\vspace{0.3cm}\n\\begin{tabular}{|l|c|c|c|}\n\\hline\nPrior\t&\t$\\mu_1 < \\mu_2$\t& $\\mu_1 = \\mu_2$\t& $\\mu_1 > \\mu_2$\\\\\n\\hline\n1 \t&\t0.5\t\t&\t0\t\t&\t0.5\\\\\n2 \t&\t0.25\t\t&\t0.5\t\t&\t0.25\\\\\n3 \t&\t0.5\t\t&\t0\t\t&\t0.5\\\\\n\\hline\n\\end{tabular}\\\\\n\\vspace{0.5cm}\n{\\bf Posterior Probabilities}:\\\\\n\\vspace{0.3cm}\n\\begin{tabular}{|l|c|c|c|}\n\\hline\nPrior\t&\t$\\mu_1 < \\mu_2$\t& $\\mu_1 = \\mu_2$\t& $\\mu_1 > \\mu_2$\\\\\n\\hline\n1 \t&\t0.945\t\t&\t0\t\t&\t0.055\\\\\n2 \t&\t0.491\t\t&\t0.430\t\t&\t0.079\\\\\n3 \t&\t0.629\t\t&\t0\t\t&\t0.372\\\\\n\\hline\n\\end{tabular}\n\\caption{\\it Prior and posterior probabilities for three different hypotheses about\nthe two manufacturers, based on the models with the three different priors.\nAs you can see, the conclusions are quite sensitive to the choice of prior in\nthis case.\n\\label{tab:ttest_results}}\n\\end{center}\n\\end{table}\n\nRemember that Prior 1 did not assign any probability to the possibility of the\ntwo parameters being equal. Therefore, no possible evidence can increase\nmake the posterior probability nonzero. However, according to this model, there\nis quite strong evidence that $\\mu_1 < \\mu_2$, as the probability changed from\n0.5 to 0.946.\n\nPrior 2 did allow the two parameters to be equal, and if we use Prior 2, we\nseem to have found very weak evidence that they are not in fact equal. The probability\ndecreased from 0.5 to 0.424. According to Prior 2, if $\\mu_1 \\neq \\mu_2$, then\n$\\mu_1 < \\mu_2$ is the next most likely scenario. However, Prior 2 has an issue\nassociated with it. Our prior says that if $\\mu_2$ is not equal to $\\mu_1$, then\nit is likely to be close to $\\mu_1$. Exactly how close we expect it to be is\nset by the variable {\\tt L} in the model.\nIf we were to make {\\tt L} very large, then the data would go from weak evidence\nagainst $\\mu_1 = \\mu_2$ to strong evidence for it! Why does this happen? Well,\nif we increased {\\tt L}, the prior probability that $\\mu_2$ and $\\mu_1$ are\nclose given that they're different is decreased. Then, the hypothesis that\nthe $\\mu$s are different does not predict our data as well, since our data\nlooks like the $\\mu$s are close together. Since it doesn't predict the data as\nwell as before, its posterior probability will be lower.\n Some people think this sensitivity to the prior is a\ndanger of Bayesian inference (if you want, you can do a web search for the\n``Jeffreys-Lindley paradox''),\nbut it is behaving logically: the wider we make\nthe prior, the lower we make the prior probability that $\\mu_1$ and $\\mu_2$\nare close but not equal, giving the model no choice but to believe that they're\nequal. If the results are sensitive to the prior, that's important, and you\nshould think about the logic of the problem to understand why.\n\nPrior 3 seems like it's what we might want in general. It's often silly to think\ntwo parameters might be {\\it exactly} equal. What we really think is that there\nis a difference, and it might be very small, or moderate or large.\n\n\\section{One Way Anova}\nOne-way ANOVA can be considered as a generalisation of a t-test to more than\ntwo groups. The question is usually phrased as a test of the hypothesis that\nthe group means are the same, versus the alternative that there is some difference.\nAs we saw in the Bayesian ``t-test'', it is possible (using clever tricks) to\nmake a model that has some prior probability that the group means are equal.\nHowever, this gets more tricky with multiple groups. Therefore we will build our\none-way ANOVA model in a similar way to the ``hierarchical model'' version of the\nt-test model. There will be one other major difference, but it is a difference\nin the way the model is coded, not a conceptual difference.\n\nIn the t-test section our data set was composed of measurements in two groups\nand our data list contained two vectors of measurements, called {\\tt x1} and\n{\\tt x2}. The sampling distribution/likelihood part of our JAGS model also\nneeded two {\\tt for} loops, one for each group.\nIf we have many groups (in the following example we will have four),\nit can get awkward having to write all those loops. Therefore, when we develop\nour ``one-way ANOVA'' model, we will format the data differently by putting\nall measurements into a single vector {\\tt x}. To make this work, we'll need\nan extra vector in the dataset, which tells us which group each data point\nbelongs to.\n\nWe'll use an example dataset on the masses of starlings (a type of bird).\nThe masses of some starlings were measured at four locations. We are interested\nin the differences between the locations. How similar are they in terms of the\naverage weight of starlings? Are they basically the same, radically different,\nor something in between? A boxplot of the data is shown in\nFigure~\\ref{fig:starling}, which seems to show substantial differences between\nthe locations. However, only ten starlings were measured at each location, so\nwe can't be absolutely sure of this, and our goal is to investigate how\nsure we should be.\n\nTo solve this problem in a Bayesian way, we will treat it as a parameter\nestimation problem with four $\\mu$ parameters, one for each of the locations.\nWe will also need at least one parameter describing the standard deviation\nof the starling masses at each location. For convenience we'll assume that's\nthe same across all locations, but it is straightforward to relax this\nassumption later.\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.6]{Figures/starling.pdf}\n\\caption{\\it The masses of starlings as measured at four different locations.\nIt seems as though the mean mass varies somewhat according to the location, and\nour results will tell us how plausible this is.\n\\label{fig:starling}}\n\\end{center}\n\\end{figure}\n\n\n\\subsection{Hierarchical Model}\nOur ``one-way ANOVA'' model is very much the same as our final ``t-test'' model,\nexcept for the format of the dataset.\nThe main advantage of this model is that it generalises to more than two groups\nin a very straightforward way; we no longer need to write separate for loops\nfor each group. As with the third ``t-test'' model, we are not seriously\nconsidering the hypothesis that all of the group means (i.e. the $\\mu$\nparameters) are exactly equal, but we are allowing them to be quite close\ntogether, or quite distinct in value, by using the hierarchical model\nstructure with the {\\tt diversity} parameter.\n\n\\begin{minted}[mathescape,\n               numbersep=5pt,\n               gobble=0,\n               frame=single,\n               framesep=2mm, fontsize=\\small]{r}\nmodel\n{\n    # Log-uniform prior for the scatter\n    log_sigma ~ dunif(-10, 10)\n    sigma <- exp(log_sigma)\n\n    # Hierarchical prior for the means\n    # Hyperparameters\n    grand_mean ~ dnorm(0, 1/1000^2)\n    log_diversity ~ dunif(-10, 10)\n    diversity <- exp(log_diversity)\n\n    # Parameters\n    for(i in 1:N)\n    {\n      mu[i] ~ dnorm(grand_mean, 1/diversity^2)\n    }\n\n    # Sampling distribution/likelihood\n    for(i in 1:N)\n    {\n        x[i] ~ dnorm(mu[group[i]], 1/sigma^2)\n    }\n}\n\\end{minted}\n\nAfter running this model on the starling data, we can plot any results we\nwish. In Figure~\\ref{fig:trace_starlings}, I have plotted a trace plot of\n$\\mu_1$, the parameter for the mean weight of starlings at location 1. This\nis a healthy trace plot, although there is a strange feature near iteration\n1000 which we will discuss in the next section. Figure~\\ref{fig:diversity}\nshows the posterior distribution for the {\\tt log\\_diversity} hyperparameter,\nwhich quantifies how different the groups really are. Our prior for this\nparameter was U(-10, 10), and the posterior peaks at around 1.5, which\ncorresponds to {\\tt diversity} $\\approx$ 4.5, although there is a fair bit of\nuncertainty. Notice also the long tail of the posterior on the left hand side.\nAlthough we never allowed the $\\mu$s to be exactly the same, we did allow them\nto be close (and this corresponds to the diversity being low). The fact that\nsome posterior samples landed between -10 and 0 suggests there is a small\nprobability that the differences between groups are very small, despite the\nfact that the data doesn't look that way.\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.6]{Figures/trace_starlings.pdf}\n\\caption{\\it A trace plot of $\\mu_1$ from a JAGS run on the starling data. Things\nappear to be mixing well, except for an odd feature near iteration 1000.\n\\label{fig:trace_starlings}}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.6]{Figures/diversity.pdf}\n\\caption{\\it The posterior distribution for {\\tt log\\_diversity}.\\label{fig:diversity}}\n\\end{center}\n\\end{figure}\n\nAs usual, we can use our posterior samples to calculate the posterior\nprobability of any hypothesis that we can think of based on the parameters.\nHere are a couple of interesting examples:\n\\begin{minted}[mathescape,\n               numbersep=5pt,\n               gobble=0,\n               frame=single,\n               framesep=2mm, fontsize=\\small]{r}\n# Is mu2 really greater than mu3?\n> mean(results$mu[,2] > results$mu[,3])\n[1] 0.672\n# Is the diversity really less than 1 (log diversity less than 0)?\n> mean(results$diversity < 0)\n[1] 0.0272\n\\end{minted}\n\n\\subsection{MCMC Efficiency}\nThe hierarchical ``one-way ANOVA'' model given above works, but a quick look\nat the trace plot suggests the mixing (how easily the MCMC algorithm is\nable to move around) did have some difficulties\n(see Figure~\\ref{fig:trace_starlings}). In this particular example the problem\nwasn't fatal, but this problem could be more severe with a different data set.\nIn some models, it makes sense to\nconsider the {\\it parameterisation} of the model. There are actually different\nways to implement exactly the same model assumptions, but in a way that helps\nthe efficiency of the MCMC sampling. This is done by changing which parameters\nare defined by ``{\\verb|~|}'' and which are defined by ``{\\tt <-}'', in a way\nthat keeps the meaning of the model intact, but forces JAGS to do the\nexploration differently.\n\nLet's look at a small subset of the above model: just the hierarchical prior\nfor the $\\mu$s. Here it is:\n\\begin{minted}[mathescape,\n               numbersep=5pt,\n               gobble=0,\n               frame=single,\n               framesep=2mm, fontsize=\\small]{r}\n# Hierarchical prior for the means\n# Hyperparameters\ngrand_mean ~ dnorm(0, 1/1000^2)\nlog_diversity ~ dunif(-10, 10)\ndiversity <- exp(log_diversity)\n\n# Parameters\nfor(i in 1:N)\n{\n  mu[i] ~ dnorm(grand_mean, 1/diversity^2)\n}\n\\end{minted}\n\nTo understand why this causes problems, we need to understand a little about\nhow JAGS works internally. JAGS uses two main MCMC methods, known as\n{\\it Gibbs Sampling} and {\\it Slice Sampling}. Both of these methods usually\nwork by updating a single parameter or hyperparameter at a time, while keeping\nall of the others fixed. Because JAGS is sampling the posterior, each\nparameter will tend to move about as far as it can without the new value\nbecoming inconsistent with the data or the (joint) prior distribution. But\nthe above model doesn't just have problems exploring the posterior efficiently,\nbut would also have problems exploring the prior!\n\nFor example, if the current values of {\\tt grand\\_mean} and {\\tt diversity}\nare 50 and 5, and JAGS is moving the parameter {\\tt mu[3]}, it will probably\nmove it to somewhere within the range 50 $\\pm$ 5, roughly speaking, since\nthe prior for {\\tt mu[3]} given {\\tt grand\\_mean}=50 and {\\tt diversity}=5\nis Normal($50, 5^2$). But another possibility that is (speaking loosely again)\ncompatible with the prior is to have {\\tt grand\\_mean}=-1500,\n{\\tt diversity}=10000, and {\\tt mu[3]}=5600. How would the sampler move from\nhaving {\\tt mu[3]}=5 to having {\\tt mu[3]}=5600? It certainly couldn't do this\nwhile {\\tt diversity} was still 5. Somehow, {\\tt diversity} would have to be\nmuch greater than 5. Yet when the sampler tries to increase the value of\n{\\tt diversity}, it won't be able to move very far, because that would make\nit inconsistent with the values of the other {\\tt mu} parameters!\n\nMany MCMC methods (and importantly for us, the ones used by JAGS)\nare inefficient when the posterior distribution has strong\n{\\it dependence} between different parameters. Unfortunately, in our one-way\nANOVA model, it's not just the posterior that has strong dependence, but\neven the prior has strong dependence!\n\n\\subsection{An Alternative Parameterisation}\nWe will now look at an alternative way of implementing the hierarchical model,\nthat entails exactly the same assumptions (the same prior distributions and\nsampling distribution), yet has computational advantages.\nThe alternative parameterisation is given below.\n\n\\begin{minted}[mathescape,\n               numbersep=5pt,\n               gobble=0,\n               frame=single,\n               framesep=2mm, fontsize=\\small]{r}\n# Hierarchical prior for the means\n# Hyperparameters\ngrand_mean ~ dnorm(0, 1/1000^2)\nlog_diversity ~ dunif(-10, 10)\ndiversity <- exp(log_diversity)\n\n# Parameters\nfor(i in 1:N)\n{\n  n[i] ~ dnorm(0, 1)\n  mu[i] <- grand_mean + diversity*n[i]\n}\n\\end{minted}\nThe only difference between this implementation and the original is the part\nwithin the loop. Instead of defining the prior for the $\\mu$s directly, we\nhave defined different parameters called {\\tt n}, with standard normal priors.\nWe then compute the {\\tt mu}s deterministically from the {\\tt n}s. In this\nalternative parameterisation, the prior for the {\\tt n}s is completely\nindependent of {\\tt grand\\_mean} and {\\tt diversity}, so sampling from the\nprior would be extremely efficient, yet the implied prior for the {\\tt mu}s\nis exactly the same as before. Of course, the posterior (what we actually want\nto sample) will still probably have dependence, but hopefully less.\n\nRunning this new version of the model on the starling data gives the trace\nplot in Figure~\\ref{fig:trace_starlings2}, which doesn't have any strange\nfeatures.\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.6]{Figures/trace_starlings2.pdf}\n\\caption{A trace plot of the parameter $\\mu_1$ using the revised model.\n\\label{fig:trace_starlings2}}\n\\end{center}\n\\end{figure}\n\n", "meta": {"hexsha": "86e73361f0f58639422d3851a7ab2c788c9be31a", "size": 24991, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "anova.tex", "max_stars_repo_name": "xulinpan/stat331", "max_stars_repo_head_hexsha": "7ca22bf3ce2c43d1a3b5fd8ff22842bdeb87ecf5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 55, "max_stars_repo_stars_event_min_datetime": "2015-03-09T18:03:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-25T03:36:54.000Z", "max_issues_repo_path": "anova.tex", "max_issues_repo_name": "xulinpan/stat331", "max_issues_repo_head_hexsha": "7ca22bf3ce2c43d1a3b5fd8ff22842bdeb87ecf5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-07-07T05:00:32.000Z", "max_issues_repo_issues_event_max_datetime": "2015-07-10T08:48:27.000Z", "max_forks_repo_path": "anova.tex", "max_forks_repo_name": "xulinpan/stat331", "max_forks_repo_head_hexsha": "7ca22bf3ce2c43d1a3b5fd8ff22842bdeb87ecf5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2015-07-29T14:34:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-04T20:04:47.000Z", "avg_line_length": 44.8671454219, "max_line_length": 103, "alphanum_fraction": 0.7400664239, "num_tokens": 6699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182187, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7129279964746834}}
{"text": "\n\\subsection{Hilbert space}\n\nA complete space with an inner product. That is, a Banach space where the norm is derived from an inner product.\n\n", "meta": {"hexsha": "eb0f20282ef30cc908d54bfa87046393869ddda7", "size": 143, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/functionalAnalysis/04-03-hilbert.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/functionalAnalysis/04-03-hilbert.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/functionalAnalysis/04-03-hilbert.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.8333333333, "max_line_length": 112, "alphanum_fraction": 0.7762237762, "num_tokens": 34, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107896491796, "lm_q2_score": 0.7606506418255927, "lm_q1q2_score": 0.7128899886725191}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage[margin=0.75in, top=1in, bottom=1in, a4paper]{geometry}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{pgfplots}\n\\usepackage{mathtools}\n\\usepackage{booktabs}\n\\usepackage{indentfirst}\n\n\\newcommand{\\mo}[1]{\\lvert #1 \\rvert}\n\\newcommand{\\mos}[1]{\\lvert #1 \\rvert^2}\n\\newcommand{\\mov}[1]{\\lvert \\vec{#1} \\rvert}\n\\newcommand{\\RR}{\\mathbb{R}}\n\\newcommand{\\p}{\\partial}\n\\newcommand{\\iv}[1]{\\langle #1 \\rangle}\n\\newcommand{\\adj}{\\text{adj}}\n\\newcommand{\\pmax}{\\text{pmax}}\n\\newcommand*\\diff{\\mathop{}\\!\\mathrm{d}}\n\n\\theoremstyle{definition}\n\\newtheorem{prop}{Proposition}[section]\n\\newtheorem{prob}[prop]{Problem}\n\\newtheorem{ex}{Exercise}\n\n\\title{\\vspace{-2.0cm}Convex Optimization Homework 1}\n\\author{Linxuan Ma}\n\n\\begin{document}\n\t\\maketitle\n\t\n\t\\section{Convex Sets}\n\t\n\t\\begin{prop}\n\t\tA polyhedron $\\{x \\in \\RR^n : Ax \\leq b\\}$ for $A \\in \\RR^{m \\times n}$ and $b \\in \\RR^m$ is both convex and closed.\n\t\\end{prop}\n\t\\begin{proof}\n\t\tThe polyhedron $P = \\{x \\in \\RR^n : Ax \\leq b\\}$ can be described as the intersection of $n(P)$ half-spaces, denoted by set $H$:\n\t\t\\begin{gather*}\n\t\t\tA_{1,1}x_1 + A_{1,2}x_2 + \\dots + A_{1,n}x_n \\leq  b_1 \\\\\n\t\t\t\\dots \\\\\n\t\t\tA_{m,1}x_1 + A_{m,2}x_2 + \\dots + A_{m,n}x_n \\leq  b_m\n\t\t\\end{gather*}\n\t\t\n\t\t$\\forall a, b \\in P$, both $a$ and $b$ are in all of the above half-spaces (by definition of intersection $P \\in H_i$ for all $i$), and the line connecting them can be obtained via their convex combination $z(t) = tx + (1-t)y$ for $t \\in [0, 1]$. Half-spaces are convex, and therefore for any half-space $H$, $x, y \\in H \\Rightarrow z(t) \\in H$. Since the above is satisfied for all above half-spaces,  $z(t) \\in P$ (definition of intersection). Therefore, $P$ satisfies that $x, y \\in P \\Rightarrow tx + (1-t)y \\in P$, proving that $P$ is indeed convex.\n\t\t\n\t\tThe closeness of $P$ can be proven by considering the open set complement $\\overline{H_i}$ of every half-space $H_i$. $\\bigcup_i \\overline{H_i}$ is an open set, and $P = \\bigcup_i H_i$ is its complement. Therefore $P$ is a closed set (definition of closeness).\n\t\\end{proof}\n\t\n\t\\begin{prop}\n\t\tGiven a set of convex sets $S$, the intersection $\\bigcap_i S_i$ is convex. Similarly, given a set of closed sets $S$, the intersection $\\bigcap_i S_i$ is closed.\n\t\\end{prop}\n\t\n\t\\begin{proof}\n\t\tThe intersection $P = \\bigcap_i S_i$ is a subset of every $S_i$ (definition of intersection). For all $x, y \\in P, t \\in [0, 1]$, $tx + (1-t)y \\in S_i$ for all $i$ (definition of convex set). The line $tx + (1-t)y$ is contained in every $S_i$, therefore it is contained in the intersection $P$ of all $S_i$ (definition of intersection).\n\t\t\n\t\t(Same as \\textit{1.1}) The closeness of $P$ can be proven by considering the open set complement $\\overline{H_i}$ of every half-space $H_i$. $\\bigcup_i \\overline{H_i}$ is an open set, and $P = \\bigcup_i H_i$ is its complement. Therefore $P$ is a closed set (definition of closeness).\n\t\\end{proof}\n\t\n\t\\begin{prob}\n\t\tGive an example of a closed set in $\\RR^2$ whose convex set is not closed.\n\t\\end{prob}\n\t\n\t\\begin{proof}\n\t\tThe set of $(x, y)$ satisfying\n\t\t\\begin{gather*}\n\t\t\ty \\geq \\frac{1}{x^2 + c}\n\t\t\\end{gather*}\n\t\twhere $c \\in \\RR_+$ is a closed set, while its convex hull is any $(x_c, y_c)$ satisfying $y > 0$ (an open set).\n\t\\end{proof}\n\t\n\t\\begin{prop}\n\t\tConsider matrix $A \\in \\RR^{m \\times n}$. If set $S \\subseteq \\RR^m$ is convex, then its pre-image of $S$ under $A$ is also convex. The same applies for closeness.\n\t\\end{prop}\n\t\n\t\\begin{proof}\n\t\tLet $P$ be the pre-image of $S$ under $A$. Consider points $x, y \\in P$ and the image of their convex combination under $A$:\n\t\t\\begin{align*}\n\t\t\t&A(tx + (1 - t)y) \\\\\n\t\t\t\\iff &A(tx) + A((1 - t)y) \\\\\n\t\t\t\\iff &t*Ax + (1-t) * Ay\n\t\t\\end{align*}\n\t\t\n\t\t$t*Ax + (1-t) * Ay \\in S$ (definition of convexity) as $Ax$ and $Ay$ are both contained in $S$ (definition of pre-image). Therefore, $A(tx + (1 - t)y) \\in S \\Rightarrow tx + (1 - t)y \\in P$.\n\t\\end{proof}\n\t\n\t\\begin{prop}\n\t\tConsider matrix $A \\in \\RR^{m \\times n}$. If set $S \\subseteq \\RR^n$ is convex, then its image under $A$ is also convex.\n\t\\end{prop}\n\t\n\t\\begin{proof}\n\t\tConsider points $x, y \\in A(S)$ and some points $x_p, y_p \\in S$ such that $A(x_p) = x$, $A(y_p) = y$. Since $S$ is convex, then the convex combination of $x$ and $y$ can be is equivalent to:\n\t\t\\begin{align*}\n\t\t\t&tx + (1 - t)y \\\\\n\t\t\t\\iff &t * A(x_p) + (1 - t) * A(y_p) \\\\\n\t\t\t\\iff &A(tx_p) + A((1 - t)y_p) \\\\\n\t\t\t\\iff &A(tx_p + (1 - t)y_p)\n\t\t\\end{align*}\n\t\t\n\t\tSince $S$ is convex, $tx_p + (1 - t)y_p \\in S$. Therefore, $A(tx_p + (1 - t)y_p) \\in A(S)$, and equivalently, $tx + (1 - t)y \\in A(S)$.\n\t\\end{proof}\n\t\n\t\\begin{prop}\n\t\tGiven an example of a matrix $A \\in \\RR^{m \\times n}$ and a set $S \\subseteq \\RR^n$ that is closed and convex but such that $A(S)$ is not closed.\n\t\\end{prop}\n\t\n\t\\begin{proof}\n\t\tConsider the matrix $A: \\RR^2 \\to \\RR^2$ that discards the $x$-component:\n\t\t\\begin{equation*}\n\t\t\\begin{bmatrix}\n\t\t\t0&0\\\\0&1\t\n\t\t\\end{bmatrix}\n\t\t\\end{equation*}\n\t\\end{proof}\n\t\n\tThe image of the set $S = \\{(x, y):y \\geq 0.5^x\\}$ is both closed and convex, yet its image under $A$ is $0 \\times (0, \\infty]$, which is not closed.\n\t\n\\end{document}\n", "meta": {"hexsha": "560132e3f92822084cf9b5a22d5aead8f6c82e1e", "size": 5200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "homework-1/homework-1.tex", "max_stars_repo_name": "davidmaamoaix/convex-opt", "max_stars_repo_head_hexsha": "9a47c6f3241a72aac2b0df90e7f85869ccb09dd7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-18T20:40:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T20:40:43.000Z", "max_issues_repo_path": "homework-1/homework-1.tex", "max_issues_repo_name": "davidmaamoaix/convex-opt", "max_issues_repo_head_hexsha": "9a47c6f3241a72aac2b0df90e7f85869ccb09dd7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "homework-1/homework-1.tex", "max_forks_repo_name": "davidmaamoaix/convex-opt", "max_forks_repo_head_hexsha": "9a47c6f3241a72aac2b0df90e7f85869ccb09dd7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.3333333333, "max_line_length": 556, "alphanum_fraction": 0.6457692308, "num_tokens": 1923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8670357649558007, "lm_q1q2_score": 0.712867381720444}}
{"text": "\\subsection{Bounds for Data Types} \\label{sec:overview:data}\n\nBounded refinements are also very useful in the first-order \nsetting, for example, when working with data types.\n\n\\subsubsection*{Abstracting Refinements over Data}\n\nLets start by abstracting refinements over data\ndefinitions~\\cite{vazou13}. Consider the @List@ type\nabstractly refined with @p :: a -> a -> Prop@, a binary relation\nbetween two values of type @a@:\n%\n\\begin{code}\n    data List <p> a \n      = [] | (:) {h :: a, t :: List<p> a<p h>}\n\\end{code}\n%\nIntuitively, the definition states that each \"tail\" is a list of\nelements that are @p@-related to the ``head'' @h@. That is, \nin a list $[x_1,\\ldots,x_n]$ for each $1 \\leq i < j \\leq n$, we \nhave $(\\cc{p}\\ x_i\\ x_j)$.\n\n\\paragraph{Ordered Lists} To see why this abstraction is useful,\nobserve that we can define concrete refinements:\n%\n\\begin{code}\n    inc = \\hd v -> hd <= v\n\\end{code}\n%\nand use them to specify and verify that sorting routines return \nlists in increasing order:\n%\n\\begin{code}\n   isort :: List a -> List<inc> a\n   isort = foldr insert []\n\n   insert :: a -> List<inc> a -> List<inc> a\n   insert =  -- elided for brevity \n\\end{code}\n\n\\paragraph{QuickSort} However, when we try to verify:\n%\n\\begin{code}\n    qsort        :: List a -> List<inc> a\n    qsort []     = []\n    qsort (x:xs) = qsort ls ++ x : qsort rs\n      where\n        ls       = [y | y <- xs, y <= x]  \n        rs       = [z | z <- xs, x <  z]  \n\\end{code}\n%\nwe run into a surprising problem: how can we type the \\emph{append} \nfunction @(++)@ in a way that lets us prove that the concatenation \nabove preserves order? \n\n\\subsubsection*{Appending Lists}\n\nActually, even talking about order is presumes that we are interested\nin a particular instantiation for the @List@ refinement. How can we\ngenerically ensure that some abstract refinement @p@? Here's how; we \ndefine a bound:\n%\n\\begin{code}\n    bound Meet p q r = \\x1 x2 -> \n      q x1 => r x2 => p x1 x2\n\\end{code}\n%\nthat states that if two values @x1@ and @x2@ respectively satisfy \nthe (unary) properties @q x1@ and @r x2@ then they satisfy the \nbinary property @p x1 x2@. We can now use this to give append a \ntype that preserves the abstract binary relation @r@:\n%\n\\begin{code}\n(++) :: (Meet p q r) => \n          List<p> a<q> -> List<p> a<r> -> List<p> a\n[]     ++ ys = ys\n(x:xs) ++ ys = x : xs ++ ys\n\\end{code}\n\n\\paragraph{To verify \\cc{qsort}} \\toolname automatically instantiates the \nrefinements at the call to @(++)@ as: \n%\n\\begin{code}\n    p |-> \\hd v -> hd <= v      -- inc \n    q |-> \\v -> v <= x \n    r |-> \\v -> x < v \n\\end{code}\n%\nThis instantiation is permitted as upon instantiation, the bound \nyields the VC:\n%\n\\begin{code}\n    x1 <= x => x < x2 => x1 <= x2\n\\end{code}\n%\nwhich is easily validated by the SMT solver, thereby verifying that\nthe concatenation and hence @qsort@ produces increasingly ordered \nlists of type @List<inc> a@.\n\n\\subsubsection*{Reversing Lists}\n\nAs a final example, consider the tail recursive list @reverse@ function:\n%\n\\begin{code}\nreverse []          = []\nreverse (x:xs)      = go x [] xs\n  where\n    go x acc []     = x : acc\n    go x acc (y:xs) = go y (x : acc) xs\n\\end{code}  \n\nAs with append, we would like to assign @reverse@ a\nrefinement-generic type that does not bake order into the\nsignature. The natural specification is that if the input was a\n@List<p> a@ then the output must be a @List<q> a@ where the\nbinary relation @q@ is the inverse of @p@.\n\n\\paragraph{We can specify inversion} via a bound:\n%\n\\begin{code}\n    bound Inverse p q = \\x y -> p x y => q y x\n\\end{code}\n%\nand use it to type \n%\n\\begin{code}\n    reverse :: (Inverse p q) \n            => List<p> a -> List<q> a\n\\end{code}\n\n\\paragraph{We can use \\cc{reverse}} to specify and verify that @decsort@ \nreturns lists sorted in decreasing order:\n%\n\\begin{code}\n    decsort :: List a -> List<dec> a\n    decsort = reverse `compose` qsort\n\\end{code}\n%\nwhere @dec = \\hd v -> hd >= v@. Verification proceeds by\nby automatically instantiating @p@ and @q@ with the (valid) \nconcrete refinements:\n%\n\\begin{code}\n    p |-> \\hd v -> hd <= v\n    q |-> \\hd v -> v  <= hd\n\\end{code}\n\n%% -- inferring\n%% go :: x:a -> List<q> a<q x> -> List<p> a<p x>\n%%    -> List<q> a\n%% \\end{code}\n\n", "meta": {"hexsha": "2dab6422d4ce1b2257878a6dda1bc38cd17bd4ac", "size": 4239, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/boundedrefinements/overview-list.tex", "max_stars_repo_name": "nikivazou/thesis", "max_stars_repo_head_hexsha": "a12f2e857a358e3cc08b657bb6b029ac2d500c3b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-12-02T00:46:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-20T07:04:01.000Z", "max_issues_repo_path": "text/boundedrefinements/overview-list.tex", "max_issues_repo_name": "nikivazou/thesis", "max_issues_repo_head_hexsha": "a12f2e857a358e3cc08b657bb6b029ac2d500c3b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "text/boundedrefinements/overview-list.tex", "max_forks_repo_name": "nikivazou/thesis", "max_forks_repo_head_hexsha": "a12f2e857a358e3cc08b657bb6b029ac2d500c3b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2016-12-02T00:46:51.000Z", "max_forks_repo_forks_event_max_datetime": "2016-12-02T00:46:51.000Z", "avg_line_length": 27.7058823529, "max_line_length": 74, "alphanum_fraction": 0.6359990564, "num_tokens": 1320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7128673784359566}}
{"text": "\\lab{Applications}{Correlation and Covariance}{Correlation and Covariance}\n\\label{Stats1}\n\n\\objective{This section addresses applications of inner product spaces to topics in statistics.}\n\n% Source of the datasets: http://people.sc.fsu.edu/~jburkardt/datasets/regression/regression.html\n% under the GNU LGPL liscence\n\n\\section*{Shifting Data by the Mean}\n\nConsider the table below representing students scores in a class.\\\\\n\n\\begin{figure}[h!]\n\\begin{center}\n\\begin{tabular}{|c|r|r|r|r|}\n\t\\hline\nStudent & Homework & Exam 1  & Exam 2 & Final \\\\\n\\hline\nS1  & 89 & 91 & 77 & 75 \\\\\nS2  & 67 & 72 & 76 & 66 \\\\\nS3  & 72 & 77 & 69 & 70 \\\\\nS4  & 56 & 60 & 55 & 61 \\\\\nS5  & 92 & 98 & 89 & 86 \\\\\nS6  & 83 & 88 & 90 & 84 \\\\\nS7  & 45 & 60 & 55 & 48 \\\\\n\\hline\nAverage  & 72 & 78 & 73 & 70\\\\\n\\hline\n\\end{tabular}\\\\\n\\end{center}\n\\end{figure}\n\nWe can shift our data set by subtracting each column by its average value.  This makes it so that the average of each column in the matrix below is zero.  If $W$ represents the matrix of scores, the following Python command will subtract out the average.\n\\begin{lstlisting}\n>>> W = np.array([[89, 91, 77, 75],\n                  [67, 72, 76, 66],\n                  [72, 77, 69, 70],\n                  [56, 60, 55, 61],\n                  [92, 98, 89, 86],\n                  [83, 88, 90, 84],\n                  [45, 60, 55, 48]])\n>>> X = W - W.mean(axis=0)\n>>> X\narray([[ 17.,  13.,   4.,   5.],\n       [ -5.,  -6.,   3.,  -4.],\n       [  0.,  -1.,  -4.,   0.],\n       [-16., -18., -18.,  -9.],\n       [ 20.,  20.,  16.,  16.],\n       [ 11.,  10.,  17.,  14.],\n       [-27., -18., -18., -22.]])\n\\end{lstlisting}\n\nOnce we have subtracted out the mean from a vector, it is a simple task to compute its variance and standard deviation.\nThe \\emph{variance} of an $n$-dimensional vector $\\mathbf{v}$, often denoted $\\sigma^2$, is defined by the formula\n$$\n\\sigma^2 = \\frac{1}{n}\\displaystyle\\sum_{i=1}^n (v_i - \\mu)^2,\n$$\nwhere $\\mu$ is the mean of $\\mathbf{v}$. The \\emph{standard deviation} of $\\mathbf{v}$ is simply $\\sigma$, i.e. the square\nroot of the variance. These quantities measure the spread of the entries of the vector. When all of the entries are clustered\nclosely around the mean, the variance is small. See Figure \\ref{fig:variance} for an illustration of variance and mean-shifted data.\n\n(Note: \\emph{unbiased variance} is a quantity closely related to variance, but defined slightly differently. It comes into play\nin particular for small datasets or vectors. Further discussion is beyond the scope of this lab, but be aware that there is\nmore than one type of variance.)\n\n\\begin{figure}[h]\n\\includegraphics[width=\\textwidth]{variance}\n\\caption{On the left, the red values come from a vector with relatively high variance,\n         and the blue values come from a vector with relatively low variance.\n         On the right, the green values have been shifted by the mean from the blue values.}\n\\label{fig:variance}\n\\end{figure}\n\nCalculating the variance and the standard deviation in Python is straight forward.\nGiven the shifted data $X$, we simply square each entry, sum along the columns, and divide by the number of rows\nto obtain the variance. Take the square root of the result to get the standard deviation.\n\\begin{lstlisting}\n>>> var = (X**2).sum(axis=0)/X.shape[0]\n>>> var\narray([ 260.     ,  193.42857,  176.28571,  151.14285])\n>>> std = np.sqrt(var)\n>>> std\narray([ 16.124515,  13.907860,  13.277263,  12.294017])\n\\end{lstlisting}\nObserve that the scores for the homework exhibited the largest amount of spread.\n\nAs with many things in Python, there is an even shorter, more convenient way to calculate these quantities.\nWe may calculate the variance and standard deviation of the columns directly from $W$, without having to shift\nby the mean.\n\n\\begin{lstlisting}\n>>> var = W.var(axis = 0)\n>>> var\narray([ 260.     ,  193.42857,  176.28571,  151.14285])\n>>> std = W.std(axis = 0)\n>>> std\narray([ 16.124515,  13.907860,  13.277263,  12.294017])\n\\end{lstlisting}\n\n\\begin{problem}\n\\label{prob:shiftdata}\nImport the dataset contained in the \\li{weight_age_fat.txt} file. The first row is a header, and contains the names\nof each column, but no actual data. There are five columns, but the first two do not contain any data of interest.\nThe last three columns contain data on the weight (in kilograms), age (in years), and blood fat content of 25\nindividuals. Distinct data entries are separated by whitespace.\n\nWrite a function \\li{shiftByMean} that shifts the columns of an input array by their respective means, and returns the result.\nNext, write a function \\li{computeVariance} that calculates and returns the variance of each column of an input array.\nFinally, write a function \\li{reportStDev} that accepts no parameters and returns nothing, and simply contains a print\nstatement that prints out the name of the column with the smallest standard deviation as well as the numerical value of\nits standard deviation.\n\n\\end{problem}\n\n\\section*{The Inner Product and Angles Formula}\n\nInner products give information about lengths of vectors and angles between vectors.\nRecall that the standard inner product on $\\mathbb{R}^n$ between vectors $x$ and $y$ is given by\n$$\n\\ipt{v}{u} = v^T u = \\displaystyle\\sum_{i=1}^n v_iu_i.\n$$\nWe can take advantage of convenient syntax in NumPy to quickly calculate the inner product between two vectors:\n\\begin{lstlisting}\n>>> v = np.array([1., -2., 4.])\n>>> u = np.arary([2., 3., -1.])\n>>> ( v* u).sum()\n-8.0\n\\end{lstlisting}\nThe 2-norm of a vector can be easily recovered from the inner product:\n\\begin{lstlisting}\n>>> v_norm = np.sqrt((v * v).sum())\n>>> v_norm\n4.5825756949558398\n\\end{lstlisting}\nAnother option to calculate the norm of an array is to use the \\li{scipy.linalg.norm} function, which has the\ncapability of computing a variety of different types of norms. For the purposes of this lab, however, our own\napproach is perfectly sufficient (and even marginally faster).\n\nRecall that the angle $\\theta$ between two nonzero\nvectors is given by\n\\[\n\\cos{\\theta} = \\frac{\\ipt{v}{u}}{\\norm{v}\\norm{u}}\n\\]\nwhere $\\norm{v} = \\sqrt{\\ipt{v}{v}}$ denotes the 2-norm of $x$.\nBy bringing the constants into the inner product, we see that the angle satisfies\n\\[\n\\cos{\\theta} = \\left\\langle\\frac{v}{\\norm{v}},\\frac{u}{\\norm{u}}\\right\\rangle.\n\\]\nHence, if we view the columns of $X$ as vectors in $\\mathbb{R}^7$, we can find the cosine of the angles between these columns by dividing each\nby its length, and then computing pairwise inner products. To divide the columns by their respective lengths, we may execute the following\ncode.\n\\begin{lstlisting}\n>>> Y = X / np.sqrt((X**2).sum(axis = 0))\n>>> Y\narray([[ 0.39848615,  0.35329218,  0.11386819,  0.15371887],\n       [-0.11720181, -0.16305793,  0.08540114, -0.12297509],\n       [ 0.        , -0.02717632, -0.11386819,  0.        ],\n       [-0.37504578, -0.48917378, -0.51240685, -0.27669396],\n       [ 0.46880723,  0.54352643,  0.45547275,  0.49190037],\n       [ 0.25784398,  0.27176321,  0.4839398 ,  0.43041282],\n       [-0.63288976, -0.48917378, -0.51240685, -0.67636301]])\n\\end{lstlisting}\n\nFinally, we get the cosines of the angles between columns by computing $Y^T Y$. To justify this calculation, consider\nthe $(i,j)^{th}$ entry of $Y^T Y$:\n\\begin{align*}\n(Y^T Y)_{i,j} &= \\sum_{k=1}^n (Y_{i,k})(Y^T)_{k,j} \\\\\n&= \\sum_{k=1}^n Y_{i,k}Y_{j,k} \\\\\n&= \\left\\langle Y_{col i}, Y_{col j} \\right\\rangle,\n\\end{align*}\nwhere $Y_{col i}$ denotes the $i^{th}$ column of $Y$, and $Y_{col j}$ the $j^{th}$ column.\nThus, we may obtain the cosine of the angle between each pair of columns of $X$ by computing $Y^T Y$,\nwhich can be easily done in Python as follows:\n\\begin{lstlisting}\n>>> np.dot(Y.T,Y)\narray([[ 1.        ,  0.97782999,  0.89014869,  0.94908967],\n       [ 0.97782999,  1.        ,  0.90978843,  0.92490144],\n       [ 0.89014869,  0.90978843,  1.        ,  0.9276955 ],\n       [ 0.94908967,  0.92490144,  0.9276955 ,  1.        ]])\n\\end{lstlisting}\n\nWe remark that the diagonals are always equal to one because the angle between a vector and itself is zero, and the cosine of zero is one.\n\n%It is also worth noting that the matrix resulting from the operation $A \\cdot A^T$ is symmetric and positive definite, so it compliant\n%with the Cholesky decomposition that was discussed at the end of Lab \\ref{lab:LUdecomp}.\n% ^^ I'm not totally sure what is going on with this last statement. What exactly is A \\cdot A^T? I'm assuming we mean A^T A, in which case\n% the matrix is in fact only guaranteed to be positive semi-definite. It still has a Cholesky decomposition in theory, although I think it can only be\n% computed for positive definite matrices. Anyway, I don't think the comment is relevant, so I have it removed for now.\n\n\\section*{Correlation}\nIn statistics, \\emph{correlation} is a broad term that refers to various types of statistical relationships and dependence between\nvariables of interest.\nIn this setting, the \\emph{Pearson correlation coefficient} of two vectors $u$ and $v$ is defined to be the cosine of the angle between the\nvectors $\\overline{u}$ and $\\overline{v}$, where $\\overline{u}$ is the vector obtained by subtracting the mean of $u$ from each of its entries,\nand similarly for $\\overline{v}$.\nTwo vectors are said to be\n\\begin{itemize}\n\\item Perfectly correlated if their correlation coefficient is one.\n\\item Positively correlated if their correlation coefficient is between zero and one.\n\\item Uncorrelated if their correlation coefficient is zero.\n\\item Negatively correlated if their correlation coefficient is between negative one and zero.\n\\item Perfectly anticorrelated if their correlation coefficient is negative one.\n\\end{itemize}\n\nIf we have a whole array with the columns as the vectors of interest, we may calculate a correlation matrix\nby first shifting the columns by their mean, and then computing the matrix of angles as described in the\nprevious section. The $(i,j)$ entry of the resulting correlation matrix gives the correlation coefficient\nof columns $i$ and $j$.\n\n\\begin{problem}\nWrite a function \\li{corrMatrix} that calculates and returns the correlation matrix of the input array.\n\\end{problem}\n\nThe notion of correlation is important in establishing linear relationships between measurements.\nParallel vectors pointing in the same direction are perfectly correlated, since they lie in the same line.\nOrthogonal vectors, on the other hand, are uncorrelated.\nGiven two vectors of the same length, one can visually check for correlation by viewing a scatter plot.\nThis can be done in Python as follows:\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n>>> x = np.random.rand(100)\n>>> y = np.random.rand(100)\n>>> plt.scatter(x,y)\n>>> plt.show()\n>>> plt.clf()\n\\end{lstlisting}\nYou will observe that the scatter plot does not indicate any obvious linear relationship between the two\nvectors. You can calculate the correlation coefficient and confirm that it is close to zero.\nSee Figure \\ref{fig:correlation} for examples of correlated and uncorrelated data.\n\n\\begin{figure}[h]\n\\includegraphics[width=\\textwidth]{correlation}\n\\caption{Left: scatter plot of two slightly positively correlated vectors.\n         Middle: scatter plot of two uncorrelated vectors.\n         Right: scatter plot of two highly negatively correlated vectors.}\n\\label{fig:correlation}\n\\end{figure}\n\n\\begin{problem}\nImport the data contained in the \\li{mortality.txt} file. The first 17 rows are headers, providing the names of the\n17 columns, and do not contain data. The first column is simply an index column, and may also be omitted.\nThe following 16 columns provide various demographic and environmental data for 60 countries, with the\nfinal column giving the mortality rate for that country.\nDistinct data entries are separated by whitespace.\n\nWrite a function that prints the answers to the following three questions, and generates plots as\ndescribed below.\nBetween which pair of distinct columns is the highest correlation?\nWhich column (apart from the last column) has the most negative correlation coefficient with mortality rate?\nWhich column is most nearly uncorrelated with mortality rate (i.e. the correlation coefficient is closest to 0)?\nMake scatter plots of all three of these pairs of columns, and include them on the same subplot panel.\nIn all relevant cases, the mortality rate column should be the second argument passed to \\li{plt.scatter}.\n\\end{problem}\n\nIt's important to understand that the high correlation between quantities does not necessarily imply\na causal relationship. For example, high correlation between violent crime rates and ice cream sales has\nbeen observed. This does not mean that ice cream causes crime or that increases in crime makes people want\nto eat more ice cream. Rather, both rates happen to increase during the summer and decrease during the winter.\n\nAnother import consideration is that the correlation coefficient does not provide information about\nnon-linear relationships and dependencies between data. Any thorough analysis will go well beyond a simple\ncalculation of the correlation matrix.\n\n\\begin{figure}[h]\n\\includegraphics[width=\\textwidth]{nonlinear_dependence}\n\\caption{There is a clear nonlinear relationship present in this data, but the Pearson correlation\n         coefficient, which has a value of -0.00056, fails to capture it.}\n\\label{fig:correlation}\n\\end{figure}\n\nFinally, the concepts of variance, standard deviation, correlation, and covariance apply to a much broader class of objects\nknown as \\emph{random variables}, which are central to statistics and probability theory. These topics will be\ncovered in detail later on.\n", "meta": {"hexsha": "978e4d883579d06b9a532f04a8926623ee000ba0", "size": 13673, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/CorrCovariance/CorrCovariance.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/CorrCovariance/CorrCovariance.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/CorrCovariance/CorrCovariance.tex", "max_forks_repo_name": "lcbendall/numerical_computing", "max_forks_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.901459854, "max_line_length": 254, "alphanum_fraction": 0.7244935274, "num_tokens": 3766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891174511732, "lm_q2_score": 0.8670357512127872, "lm_q1q2_score": 0.7128673590882565}}
{"text": "\\section{Markov chain model}\nThe following Markov chain represents the transition between states of a service\ncentre \nwhile capturing the interactions between it and a buffer centre.\nThe service centre accepts two types of individuals; Class 1 and Class 2.  \nClass 2 individuals are accepted until a pre-determined threshold \\(T\\) of \nindividuals is reached.\nWhen reached, all Class 2 individuals that arrive will remain \\textit{``blocked''}\nin the buffer centre until the number of people in the system is \nreduced below \\(T\\). \nAdditionally, if the people in the service centre keep rising, they may exceed\nthe number \nof servers \\(C\\) available, which will in turn mean that every new person will \nhave to wait for a server to become free. \nThe states of the Markov chain are denoted by \\((u,v)\\) where:\n\n\\begin{itemize}\n    \\item \\(u\\) = number of Class 2 individuals blocked\n    \\item \\(v\\) = number of Class 1 individuals in the service centre\n\\end{itemize}\n\n\\begin{figure}\n    \\centering\n    \\begin{tikzpicture}[-, node distance = 0.9cm, auto, every node/.style={scale=0.7}]\n\n        % Markov chain variables\n        \\tikzmath{\n            let \\initdist = 0.5cm;\n            let \\altdist = 1.2cm;\n            let \\minsz = 1.6cm;\n        }\n\n        % S_1 and S_2 rectangles\n        \\tikzmath{\n            let \\leftOne = -0.8;\n            let \\rightOne = 2.7;\n            let \\upOne = 0.8;\n            let \\downOne = -2.7;\n            let \\leftTwo = 2.8;\n            let \\rightTwo = 13;\n            let \\upTwo = -2.95;\n            let \\downTwo = -16.4;\n        }\n\n        % General case variables\n        \\tikzmath{\n            let \\GCsmallx = 8.3;\n            let \\GCsmally = -9.5;\n            let \\GCbigx = 4.1;\n            let \\GCbigy = -11.8;\n        }\n\n        % Rectangle for S1\n        \\draw[ultra thin, dashed] (\\leftOne, \\downOne) -- (\\leftOne, \\upOne);\n        \\draw[ultra thin, dashed] (\\leftOne, \\upOne) -- (\\rightOne, \\upOne);\n        \\draw[ultra thin, dashed] (\\rightOne, \\upOne) -- node \n        {\\Huge{\\( \\quad S_1 \\)}}(\\rightOne, \\downOne);\n        \\draw[ultra thin, dashed] (\\rightOne, \\downOne) -- (\\leftOne, \\downOne);\n\n        % Rectangle for S2\n        \\draw[ultra thin, dashed] (\\leftTwo, \\downTwo) -- node \n        {\\Huge{\\( S_2 \\quad \\)}}(\\leftTwo, \\upTwo);\n        \\draw[ultra thin, dashed] (\\leftTwo, \\upTwo) -- (\\rightTwo, \\upTwo);\n        \\draw[ultra thin, dashed] (\\rightTwo, \\upTwo) -- (\\rightTwo, \\downTwo);\n        \\draw[ultra thin, dashed] (\\rightTwo, \\downTwo) -- (\\leftTwo, \\downTwo);\n\n        % Small square of general case\n        \\draw [thick] (\\GCsmallx, \\GCsmally) -- node {} \n        (\\GCsmallx + 0.4, \\GCsmally);\n        \\draw [thick] (\\GCsmallx + 0.4, \\GCsmally) -- node {} \n        (\\GCsmallx + 0.4, \\GCsmally - 0.4);\n        \\draw [thick] (\\GCsmallx + 0.4, \\GCsmally - 0.4) -- node {} \n        (\\GCsmallx, \\GCsmally - 0.4);\n        \\draw [thick] (\\GCsmallx, \\GCsmally - 0.4) -- node {} \n        (\\GCsmallx, \\GCsmally);\n\n\n        % Dashed lines to from small square to big one \n        \\draw [ultra thin] (\\GCsmallx, \\GCsmally) -- node {} \n        (\\GCbigx, \\GCbigy);\n        \\draw [ultra thin] (\\GCsmallx + 0.4, \\GCsmally) -- node {} \n        (\\GCbigx + 4, \\GCbigy);\n        \\draw [ultra thin] (\\GCsmallx, \\GCsmally - 0.4) -- node {} (7, \\GCbigy);\n        \\draw [ultra thin] (\\GCsmallx + 0.4, \\GCsmally - 0.4) -- node {} \n        (\\GCbigx + 4, \\GCbigy - 4);\n        \n        % Big Square of general case\n        \\draw [ultra thick] (\\GCbigx, \\GCbigy) -- node {} (\\GCbigx + 4, \\GCbigy);\n        \\draw [ultra thick] (\\GCbigx + 4, \\GCbigy) -- node {} \n        (\\GCbigx + 4, \\GCbigy - 4);\n        \\draw [ultra thick] (\\GCbigx + 4, \\GCbigy - 4) -- node {General Case} \n        (\\GCbigx, \\GCbigy - 4);\n        \\draw [ultra thick] (\\GCbigx, \\GCbigy - 4) -- node {} (\\GCbigx, \\GCbigy);\n\n        % First Line\n        \\node[state, minimum size=1.5cm] (zero) {(0,0)};\n        \\node[state, node distance = \\initdist, minimum size=\\minsz, below right=of zero] \n        (one) {(0,1)};\n        \\node[draw=none, node distance = \\initdist, minimum size=\\minsz, below right=of one] \n        (two) {\\textbf{\\( \\ddots \\)}};\n        \\node[state, node distance = \\initdist, minimum size=\\minsz, below right=of two] \n        (three) {(0,T)};\n        \\node[state, node distance = \\altdist, minimum size=\\minsz, right=of three] \n        (four) {(0,T+1)};\n        \\node[draw=none, node distance = \\altdist, minimum size=\\minsz, right=of four] \n        (five) {\\textbf{\\dots}};\n        \\node[state, minimum size=\\minsz, right=of five] (six) {(0,C)};\n        \\node[draw=none, minimum size=\\minsz, right=of six] (seven) {\\textbf{\\dots}};\n\n        % Second Line\n        \\node[state, minimum size=\\minsz, below=of three] (three_one) {(1,T)};\n        \\node[state, minimum size=\\minsz, below=of four] (four_one) {(1,T+1)};\n        \\node[draw=none, minimum size=\\minsz, below=of five] (five_one) {\\textbf{\\dots}};\n        \\node[state, minimum size=\\minsz, right=of five_one] (six_one) {(1,C)};\n        \\node[draw=none, minimum size=\\minsz, right=of six_one] (seven_one) {\\textbf{\\dots}};\n        \n        % Third Line\n        \\node[state, minimum size=\\minsz, below=of three_one] (three_two) {(2,T)};\n        \\node[state, minimum size=\\minsz, below=of four_one] (four_two) {(2,T+1)};\n        \\node[draw=none, minimum size=\\minsz, below=of five_one] (five_two) \n        {\\textbf{\\dots}};\n        \\node[state, minimum size=\\minsz, right=of five_two] (six_two) {(2,C)};\n        \\node[draw=none, minimum size=\\minsz, right=of six_two] (seven_two) \n        {\\textbf{\\dots}};\n\n        % Fourth line\n        \\node[draw=none, node distance = \\altdist, minimum size=\\minsz, below=of three_two] \n        (three_three) {\\textbf{\\vdots}};\n        \\node[draw=none, node distance = \\altdist, minimum size=\\minsz, below=of four_two] \n        (four_three) {\\textbf{\\vdots}};\n        \\node[draw=none, node distance = 2cm, minimum size=\\minsz, below=of five_two] \n        (five_three) {};\n        \\node[draw=none, node distance = \\altdist, minimum size=\\minsz, below=of six_two] \n        (six_three) {\\textbf{\\vdots}};\n\n        % Fifth line\n        % \\node[state, node distance = \\altdist, minimum size=\\minsz, below=of five_three] \n        % (general_case_mid) {\\( (u_i, v_i) \\)};\n        \\node[draw=none, node distance = 0.3cm, minimum size=\\minsz, below=of four_three] \n        (general_case_up) {};\n        \\node[state, node distance = \\altdist, minimum size=\\minsz, below=of general_case_up] \n        (general_case_mid) {\\( (u_i, v_i) \\)};\n\n        \\node[draw=none, node distance = \\altdist, minimum size=\\minsz, below=of general_case_mid] \n        (general_case_down) {};\n        \\node[draw=none, node distance = \\altdist, minimum size=\\minsz, left=of general_case_mid] \n        (general_case_left) {};\n        \\node[draw=none, node distance = \\altdist, minimum size=\\minsz, right=of general_case_mid] \n        (general_case_right) {};\n\n        \\draw[every loop]\n            % First Horizontal Edges\n            (zero) edge[bend left] node {\\( \\Lambda \\)} (one)\n            (one) edge[bend left] node {\\( \\mu \\)} (zero)\n            (one) edge[bend left] node {\\( \\Lambda \\)} (two)\n            (two) edge[bend left] node {\\( 2 \\mu \\)} (one)\n            (two) edge[bend left] node {\\( \\Lambda \\)} (three)\n            (three) edge[bend left] node {\\( T \\mu \\)} (two)\n            (three) edge[bend left] node {\\( \\lambda_1 \\)} (four)\n            (four) edge[bend left] node {\\( (T+1) \\mu \\)} (three)\n            (four) edge[bend left] node {\\( \\lambda_1 \\)} (five)\n            (five) edge[bend left] node {\\( (T+2) \\mu \\)} (four)\n            (five) edge[bend left] node {\\( \\lambda_1 \\)} (six)\n            (six) edge[bend left] node {\\( C\\mu \\)} (five)\n            (six) edge[bend left] node {\\( \\lambda_1 \\)} (seven)\n            (seven) edge[bend left] node {\\( C\\mu \\)} (six)\n\n            % Second Horizontal Edges\n            (three_one) edge[bend left] node {\\( \\lambda_1 \\)} (four_one)\n            (four_one) edge[bend left] node {\\( (T+1) \\mu \\)} (three_one)\n            (four_one) edge[bend left] node {\\( \\lambda_1 \\)} (five_one)\n            (five_one) edge[bend left] node {\\( (T+2) \\mu \\)} (four_one)\n            (five_one) edge[bend left] node {\\( \\lambda_1 \\)} (six_one)\n            (six_one) edge[bend left] node {\\( C\\mu \\)} (five_one)\n            (six_one) edge[bend left] node {\\( \\lambda_1 \\)} (seven_one)\n            (seven_one) edge[bend left] node {\\( C\\mu \\)} (six_one)\n\n            % Third Horizontal Edges\n            (three_two) edge[bend left] node {\\( \\lambda_1 \\)} (four_two)\n            (four_two) edge[bend left] node [below] {\\( (T+1) \\mu \\)} (three_two)\n            (four_two) edge[bend left] node {\\( \\lambda_1 \\)} (five_two)\n            (five_two) edge[bend left] node {\\( (T+2) \\mu \\)} (four_two)\n            (five_two) edge[bend left] node {\\( \\lambda_1 \\)} (six_two)\n            (six_two) edge[bend left] node {\\( C\\mu \\)} (five_two)\n            (six_two) edge[bend left] node {\\( \\lambda_1 \\)} (seven_two)\n            (seven_two) edge[bend left] node {\\( C\\mu \\)} (six_two)\n\n            % First Vertical Edges\n            (three) edge[bend left] node {\\( \\lambda_2 \\)} (three_one)\n            (three_one) edge[bend left] node {\\( T \\mu \\)} (three)\n            (three_one) edge[bend left] node {\\( \\lambda_2 \\)} (three_two)\n            (three_two) edge[bend left] node {\\( T\\mu \\)} (three_one)\n            (three_two) edge[bend left] node {\\( \\lambda_2 \\)} (three_three)\n            (three_three) edge[bend left] node {\\( T\\mu \\)} (three_two)\n\n            % Second Vertical Edges\n            (four) edge node {\\( \\lambda_2 \\)} (four_one)\n            (four_one) edge node {\\( \\lambda_2 \\)} (four_two)\n            (four_two) edge node {\\( \\lambda_2 \\)} (four_three)\n\n            % Fourth Vertical Edges\n            (six) edge node {\\( \\lambda_2 \\)} (six_one)\n            (six_one) edge node {\\( \\lambda_2 \\)} (six_two)\n            (six_two) edge node {\\( \\lambda_2 \\)} (six_three)\n\n            % General Case\n            (general_case_left) edge[bend left] node {\\( \\lambda_1 \\)} (general_case_mid)\n            (general_case_mid) edge[bend left] node {\\( v_i \\mu \\)} (general_case_left)\n            (general_case_right) edge[bend left] node {\\( (v_i +1) \\mu \\)} (general_case_mid)\n            (general_case_mid) edge[bend left] node {\\( \\lambda_1 \\)} (general_case_right)\n            % (five_three) edge node {\\( \\lambda_2 \\)} (general_case_mid)\n            (general_case_up) edge node {\\( \\lambda_2 \\)} (general_case_mid)\n            (general_case_mid) edge node {\\( \\lambda_2 \\)} (general_case_down)\n            ;\n    \\end{tikzpicture}\n    \\caption{Markov chain} \n    \\label{markov_model}\n\\end{figure}\n\n\n\\subsection{Markov-chain state mapping function}\nThe transition matrix of the Markov-chain representation described above can be \ndenoted by a state mapping function. \nThe state space of this function is defined as:\n\n\n\n\\begin{align}\n    S(T) =& S_1(T) \\cup S_2(T) \\text{ where:} \\nonumber \\\\\n    S_1(T) =& \\left\\{(0, v)\\in\\mathbb{N}_0^2 \\; | \\; v < T \\right\\} \\label{eq:state_space} \\\\\n    S_2(T) =& \\{(u, v)\\in\\mathbb{N}_0^2 \\; | \\; v \\geq T \\} \\nonumber\n\\end{align}\n\nTherefore, the entries of the transition matrix \\(Q\\), can be given by \n\\( q_{i,j} = q_{(u_i, v_i),(u_j, v_j)} \\) which is the transition rate from state \n\\( i = (u_i, v_i) \\) to state \\( j = (u_j , v_j) \\) for all \n\\( (u_i, v_i), (u_j, v_j) \\in S \\).\n\n\\begin{equation} \\label{eq:markov_transition_rate}\n    q_{i, j} = \n    \\begin{cases}\n        \\Lambda, & \\textbf{if } (u_i, v_i) - (u_j, v_j) = (0,-1) \\textbf{ and } \n        v_i < \\text{t} \\\\\n        \\lambda_1, & \\textbf{if } (u_i, v_i) - (u_j, v_j) = (0,-1) \\textbf{ and } \n        v_i \\geq \\text{t} \\\\\n        \\lambda_2, & \\textbf{if } (u_i, v_i) - (u_j, v_j) = (-1,0) \\\\\n        v_i \\mu, & \\textbf{if } (u_i, v_i) - (u_j, v_j) = (0,1) \\textbf{ and } \n        v_i \\leq C \\textbf{ or} \\\\ & \\hspace{0.37cm}(u_i, v_i) - (u_j, v_j) = (1,0) \n        \\textbf{ and } v_i = T \\leq C \\\\\n        C \\mu, & \\textbf{if } (u_i, v_i) - (u_j, v_j) = (0,1) \\textbf{ and } v_i > C \n        \\textbf{ or} \\\\ & \\hspace{0.37cm}(u_i, v_i) - (u_j, v_j) = (1,0) \\textbf{ and } \n        v_i = T > C\\\\\n        -\\sum_{j=1}^{|Q|}{q_{i,j}} & \\textbf{if } i = j \\\\\n        0, & \\textbf{otherwise}\n    \\end{cases}\n\\end{equation}\n\nIn order to acquire an exact solution of the problem a slight adjustment needs to \nbe considered. \nThe problem defined above assumes no upper boundary to the number of individuals \nthat can wait for service or the ones that are blocked in the buffer centre. \nTherefore, a different state space \\( \\tilde S \\) needs to be constructed where \n\\( \\tilde S \\subseteq S \\) and there is a maximum allowed number of people \\( N \\) \nthat can be in the system and a maximum allowed number of people \\( M \\) that can\nbe blocked in the buffer centre:\n\n\\begin{equation}\n    \\tilde S = \\left\\{ (u, v) \\in S\\;| u \\leq M, v\\leq N \\right\\}\n\\end{equation}\n\n\n\\subsection{Steady State}\nHaving calculated the transition matrix \\( Q \\) for a given set of parameters the \nprobability vector \\( \\pi \\) needs to be considered. \nThe vector \\( \\pi \\) is commonly used to study such stochastic systems and it's \nmain purpose is to keep track of the probability of being at any given state of \nthe system. \nThe term \\textit{steady state} refers to the instance of the vector \\( \\pi \\) where \nthe probabilities of being at any state become stable over time. \nThus, by considering the steady state vector \\( \\pi \\) the relationship between \nit and \\(Q \\) is given by:\n\n\\[\n\\frac{d\\pi}{dt} = \\pi Q = 0\n\\]\n\nThere are numerous methods that can be used to solve problems of such kind. \nIn this paper only numeric and algebraic approaches will be considered. \n\n\\subsubsection{Numeric integration}\nThe first approach to be considered is to solve the differential equation numerically \nby observing the behaviour of the model over time. \nThe solution is obtained via python's SciPy library. \nThe functions odeint and solve\\textunderscore ivp have been used in order to find \na solution to the problem. \nBoth of these functions can be used to solve any system of first order ODEs.\n\n\\subsubsection{Linear algebraic approach}\nAnother approach to be considered is the linear algebraic method. \nThe steady state vector can be found algebraically by satisfying the following set \nof equations:\n\\[ \\pi Q = 0 \\]\n\\[ \\sum_{i} \\pi_i = 1 \\]\n\nThese equations can be solved by slightly altering \\( Q \\) such that the final column \nis replaced by a vector of ones. \nThus, the resultant solution occurs from solving the equation \\( \\tilde{Q}^T \\pi = b \\) \nwhere \\( \\tilde{Q} \\) and \\( b \\) are defined as:\n\n\\[\n\\tilde{q_{i, j}} = \n\\begin{cases}\n    1, & \\textbf{if } j = |Q| \\\\\n    q_{i,j}, & \\textbf{otherwise}\n\\end{cases}\n\\]\n\n\\[\nb = \n\\begin{bmatrix}\n    x_{1} \\\\\n    x_{2} \\\\\n    \\vdots \\\\\n    x_{m}\n\\end{bmatrix}\n\\]\n\n\n\\subsubsection{Least Squares approach}\nFinally, the last approach to be considered is the least squares method. \nThis approach is considered because while the problem becomes more complex (in terms \nof input parameters) the computational time required to solve it increases exponentially. \nThus, one may obtain the steady state vector \\( \\pi \\) by solving the following \nequation.\n\n\\[\n\\pi = \\text{argmin}_{x\\in\\mathbb{R}^{d}}\\|Mx-b\\|_2^2\n\\]\n", "meta": {"hexsha": "95eb79bc49f589c7b20dd62b7e48001dcb378726", "size": 15369, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/main/MarkovChain/markov_chain_model/main.tex", "max_stars_repo_name": "11michalis11/AmbulanceDecisionGame", "max_stars_repo_head_hexsha": "45164ba51da0417297f715e41716cb91facc120f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/main/MarkovChain/markov_chain_model/main.tex", "max_issues_repo_name": "11michalis11/AmbulanceDecisionGame", "max_issues_repo_head_hexsha": "45164ba51da0417297f715e41716cb91facc120f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 20, "max_issues_repo_issues_event_min_datetime": "2020-04-20T09:08:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T11:09:25.000Z", "max_forks_repo_path": "tex/main/MarkovChain/markov_chain_model/main.tex", "max_forks_repo_name": "11michalis11/AmbulanceDecisionGame", "max_forks_repo_head_hexsha": "45164ba51da0417297f715e41716cb91facc120f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.3362831858, "max_line_length": 99, "alphanum_fraction": 0.5896284729, "num_tokens": 4865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7128023777610291}}
{"text": "\\section{Fourier Spectral Methods}\n\t\n\tIn the following sections we will work with the problem obtained by the transformation of the problem (\\ref{Hopf_tranform}) given by\n\t\\begin{align}\n\t\tu(x, t) = - 2 \\alpha \\frac{\\partial_{x} \\varphi(x, t)}{\\varphi(x, t)} = - 2 \\alpha \\left( \\log{\\varphi(x, t)} \\right)_x\n\t\\end{align}\n\twith $\\alpha > 0$, and $\\varphi$ solves the following initial value problem\n\t\\begin{align}\n\t\\label{Bugers_Lineal}\t\n\t\t\\left \\lbrace \\begin{array}{ll}\n\t\t\t\\frac{\\partial \\varphi}{\\partial t} = \\alpha \\varphi_{xx}, \\hspace{2mm} 0 < t \\leq T, \\hspace{2mm} x \\in I \\\\\n\t\t\t\\\\\n\t\t\t\\varphi(x, 0) = \\displaystyle \\varphi_0 (x) = e^{- \\int_{0}^{x} \\frac{u_0(y)}{2 \\alpha} dy}, \\hspace{2mm} x \\in I\n\t\t\\end{array}  \\right .\n\t\\end{align}\n\t\\input{burgers_equation/deterministic/methods/Galerkin}\n\t\\input{burgers_equation/deterministic/methods/Collocation}", "meta": {"hexsha": "9cfbe95314ec46c3244ad0fc5910212439ea3096", "size": 860, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/burgers_equation/deterministic/methods/Fourier_Methods.tex", "max_stars_repo_name": "alanmatzumiya/Maestria", "max_stars_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-12-29T10:44:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T11:18:45.000Z", "max_issues_repo_path": "docs/burgers_equation/deterministic/methods/Fourier_Methods.tex", "max_issues_repo_name": "alanmatzumiya/spectral-methods", "max_issues_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/burgers_equation/deterministic/methods/Fourier_Methods.tex", "max_forks_repo_name": "alanmatzumiya/spectral-methods", "max_forks_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T13:29:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T13:29:56.000Z", "avg_line_length": 50.5882352941, "max_line_length": 133, "alphanum_fraction": 0.6755813953, "num_tokens": 320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7126612042308653}}
{"text": "\\section{Policy Gradient Methods}\n\n\\subsection{Exercise 13.1}\n\\subsubsection*{Q}\nUse your knowledge of the gridworld and its dynamics to determine an \\emph{exact} symbolic expression for the optimal probability of selecting the \\texttt{right} action in Example 13.1.\n\n\\subsubsection*{A}\nDefine $p = \\P{}(\\texttt{right})$, so $\\P{}(\\texttt{left}) = 1-p$. Then, labelling the states 1-3 from right to left (value of terminal state is set to 0), the Bellman equations reduce to\n\\begin{align*}\n    v_\\pi(1) &= p v_\\pi(2) - 1\\\\\n    v_\\pi(2) &= pv_\\pi(1) - 1 + (1-p)v_\\pi(3) \\\\\n    v_\\pi(3) &= (1-p)v_\\pi(2) - 1.\n\\end{align*}\nSetting $f(p)$ for the value of the initial state and solving this system gives\n\\[\n    f(p) = \\frac{p^2 - 2p + 2}{p(1-p)}\n\\]\nwhich attains its maximum at $p = \\sqrt{2}(\\sqrt{2} - 1)$. (Note that $f$ is defined only on the open interval $(0, 1)$, the performance becomes infinitely bad as $p \\to 0, 1$.)\n\n\n\\subsection{*Exercise 13.2}\n\\subsubsection*{Q}\nGeneralize the box on page 199, the policy gradient theorem (13.5), the proof of the policy gradient theorem (page 325), and the steps leading to the REINFORCE update equation (13.8), so that (13.8) ends up with a factor of $\\gamma^t$ and thus aligns with the general algorithm given in the pseudocode.\n\n\\subsubsection*{A}\n\\begin{itemize}\n    \\item Generalisation the recursion equation that governs expected time in each state:\n    \\begin{align*}\n        \\eta(s) &= h(s) + \\gamma \\sum_{\\bar{s}}\\eta(\\bar{s}) \\sum_a \\pi(a \\vert{} \\bar{s}) p(s \\vert{} \\bar{s}, a)\\\\\n                &= h(s) + \\gamma \\sum_{\\bar{s}, a}\\pi(a \\vert{} \\bar{s}) p(s \\vert{} \\bar{s}, a) + \\gamma ^2 \\sum_{\\bar{s}, a}\\pi(a \\vert{} \\bar{s}) p(s \\vert{} \\bar{s}, a) \\sum_{x, a'}\\pi(a' \\vert{} x) p(\\bar{s} \\vert{} x, a) + \\cdots\n    \\end{align*}\n    This just changes the solution for $\\eta(s)$, we still have $\\mu(s) = \\frac{\\eta(s)}{\\sum_{s'} \\eta(s')}$.\n    \\item The generalisation of the proof of the policy gradient theorem comes with the use of the Bellman  equation unfolding for the value function. We therefore arrive at the following gradient:\n    \\[\n        \\grad_{\\vec{\\theta}} v_\\pi(s) = \\sum_{x \\in \\S{}}\\sum_{k = 0}^\\infty \\P{}(s \\to x, k, \\pi)\\gamma^k\\sum_a \\grad_{\\vec{\\theta}} \\pi(a \\vert{} x) q_\\pi(x, a),\n    \\]\n    and the theorem follows as before.\n    \\item To full incorporate discounting, we need to view it as a form of termination. The policy gradient theorem becomes\n    \\[\n        \\grad_{\\vec{\\theta}} J(\\vec{\\theta}) = \\Epi[\\gamma_t \\sum_a q_\\pi(S_t, a) \\grad_{\\vec{\\theta}} \\pi(a \\vert{} S_t, \\vec{\\theta})].\n    \\]\n    The factor of $\\gamma^t$ then follows through when we apply SGD. (It's possible to do some rearranging to prove this relation, but it is not done in the book --  a little unclear!)\n\\end{itemize}\n\n\\subsection{Exercise 13.3}\n\\subsubsection*{Q}\nIn Section 13.1 we considered policy parameterizations using the soft-max in action preferences (13.2) with linear action preferences (13.3). For this parameterization, prove that the eligibility vector is\n\\[\n    \\grad \\log \\pi(a \\vert{} s, \\vec{\\theta}) = \\vec{x}(s, a) - \\sum_b \\pi(b \\vert{} s, \\vec{\\theta})\\vec{x}(s, b)\n\\]\nusing the definitions and elementary calculus.\n\n\\subsubsection*{A}\nHave softmax policy\n\\[\n    \\pi(a \\vert{} s, \\vec{\\theta}) = \\frac{\\exp(h(s, a, \\vec{\\theta}))}{\\sum_b \\exp(h(s, a, \\vec{\\theta}))}\n\\]\nwith linear action preferences \n\\[\n    h(s, a, \\vec{\\theta}) = \\vec{\\theta}^\\top \\vec{x}(s, a).\n\\]\nThe following is then clear:\n\\begin{align*}\n    \\grad_{\\vec{\\theta}} \\log(\\pi) &= \\vec{x}(s, a) - \\frac{\\sum_b \\vec{x}(s, b) \\exp(\\vec{\\theta}^\\top \\vec{x}(s, b))}{\\sum_b \\exp(\\vec{\\theta}^\\top \\vec{x}(s, b))} \\\\\n                                   &= \\vec{x}(s, a) - \\sum_b \\vec{x}(s, b) \\pi(b \\vert{} s, \\vec{\\theta}).\n\\end{align*}\n\n\\subsection{Exercise 13.4}\n\\subsubsection*{Q}\nShow that for the gaussian policy parameterization (13.19) the eligibility vector has the following two parts:\n\n\\begin{align*}\n    \\grad \\log \\pi(a \\vert{} s, \\vec{\\theta}_\\mu) &= \\frac{\\grad \\pi(a \\vert{} s, \\vec{\\theta}_\\mu)}{\\pi(a \\vert{} s, \\vec{\\theta})} = \\frac{1}{\\sigma(s, \\vec{\\theta})^2} (a - \\mu(s, \\vec{\\theta}))\\vec{x}_\\mu(s)\\text{, and}\\\\\n    \\grad \\log \\pi(a \\vert{} s, \\vec{\\theta}_\\sigma) &= \\frac{\\grad \\pi(a \\vert{} s, \\vec{\\theta}_\\sigma)}{\\pi(a \\vert{} s, \\vec{\\theta})} = \\left( \\frac{(a - \\mu(s, \\vec{\\theta}))^2}{\\sigma(s, \\vec{\\theta})^2} - 1 \\right) \\vec{x}_\\sigma(s)\n\\end{align*}\n\n\\subsubsection*{A}\nGaussian policy\n\\[\n    \\pi(a \\vert{} s, \\vec{\\theta}) = \\frac{1}{\\sigma(s, \\vec{\\theta}) \\sqrt{2 \\pi}} \\exp\\left( - \\frac{(a - \\mu(s, \\vec{\\theta}))^2}{2 \\sigma(s, \\vec{\\theta})^2} \\right)\n\\]\nwith the models $\\mu(s, \\vec{\\theta}_\\mu) = \\vec{\\theta}_\\mu^\\top\\vec{x}_\\mu(s)$ and $\\sigma(s, \\vec{\\theta}_\\sigma) = \\exp(\\vec{\\theta}_\\sigma^\\top\\vec{x}_\\sigma(s))$. First,\n\\[\n    \\log \\pi(a \\vert{} s, \\vec{\\theta}) = - \\log \\sqrt{2 \\pi} - \\log \\sigma - \\frac{(a - \\mu)^2}{2\\sigma^2}\n\\]\nso we have \n\\[\n    \\grad_{\\vec{\\theta}_\\mu}\\log\\pi(a \\vert{}s, \\theta) = \\frac{a - \\mu}{\\sigma^2}\\grad_{\\vec{\\theta}_\\mu}\\mu(s, \\vec{\\theta}_\\mu) = \\frac{a - \\mu}{\\sigma^2} \\vec{x}_\\mu(s)\n\\]\nand\n\\[\n    \\grad_{\\vec{\\theta}_\\sigma}\\log\\pi(a \\vert{} s, \\vec{\\theta}) = - \\frac{\\grad_{\\vec{\\theta}_\\sigma} \\sigma}{\\sigma} + \\frac{(a - \\mu)^2}{\\sigma^2}\\grad_{\\vec{\\theta}_\\sigma}\\sigma = \\left( \\frac{(a - \\mu)^2}{\\sigma^2} - 1 \\right)\\vec{x}_\\sigma(s) \n\\]\nbecause $\\grad_{\\vec{\\theta}_\\sigma}\\sigma = \\vec{x}_\\sigma(s) \\sigma$.\n\n\n\\subsection{Exercise 13.5}\n\\subsubsection*{Q}\nA \\emph{Bernoulli-logistic unit} is a stochastic neuron-like unit used in some ANNs (Section 9.6). Its input at time $t$ is a feature vector $\\vec{x}(S_t)$; its output, $A_t$, is a random variable having two values, 0 and 1, with $\\text{Pr}\\{A_t = 1\\} = P_t$ and $\\text{Pr}\\{A_t = 0\\} = 1- P_t$ (the Bernoulli distribution). Let $h(s, 0, \\vec{\\theta})$ and $h(s, 1, \\vec{\\theta})$ be the preferences in state $s$ for the unit’s two actions given policy parameter $\\vec{\\theta}$. Assume that the difference between the action preferences is given by a weighted sum of the unit’s input vector, that is, assume\nthat $h(s, 1, \\vec{\\theta}) - h(s, 0, \\vec{\\theta}) = \\vec{\\theta}^\\top \\vec{x}(s)$, where $\\vec{\\theta}$ is the unit’s weight vector.\n\n\\begin{enumerate}[(a)]\n    \\item Show that if the exponential soft-max distribution (13.2) is used to convert action preferences to policies, then $P_t = \\pi(1 \\vert{}S_t, \\vec{\\theta}_t) = 1/(1 + \\exp(-\\vec{\\theta}_t^\\top\\vec{x}(S_t)))$(the logistic function).\n    \\item What is the Monte-Carlo REINFORCE update of $\\vec{\\theta}_t$ to $\\vec{\\theta}_t$ upon receipt of return $G_t$?\n    \\item Express the eligibility $\\grad\\log\\pi(a\\vert{}s,\\vec{\\theta})$ for a Bernoulli-logistic unit, in terms of $a$, $\\vec{x}(s)$ and $\\pi(a \\vert{} s, \\vec{\\theta})$ by calculating the gradient.\n\\end{enumerate}\n\nHint: separately for each action compute the derivative of the logarithm first with respect to $P_t = \\pi(1 \\vert{}S_t, \\vec{\\theta}_t)$, combine the two results into one expression that depends on $a$ and $P_t$, and then use the chain rule, noting that the derivative of the logistic function $f(x)$ is $f(x)(1 - f(x))$.\n\n\\subsubsection*{A}\n\n\\begin{enumerate}[a)]\n    \\item $\\pi(1 \\vert{} S_t, \\vec{\\theta}_t) = e^{h(s, 1, \\vec{\\theta}_t)} / (e^{h(s, 1, \\vec{\\theta}_t)} + e^{h(s, 0, \\vec{\\theta}_t)}) = 1 /(1 + e^{-\\vec{\\theta}^\\top\\vec{x}(s)}) $\n    \\item $\\vec{\\theta}_{t+1} = \\vec{\\theta}_t + \\alpha \\gamma^t G_t \\grad_{\\vec{\\theta}_t}\\log\\pi(a \\vert{} S_t, \\vec{\\theta}_t)$ \n    \\item Write $\\pi(a \\vert{} S_t, \\vec{\\theta}_t) = g((-1)^a \\vec{\\theta}_t^\\top\\vec{x}(s))$ where $a \\in \\{ 0, 1\\}$ and $g$ is the sigmoid function $g(t) = 1 / (1 + e^{-t})$. It's then quite easy to see that \n    \\[\n        \\frac{\\d{}}{\\d{} t} \\log g(t) = 1 - g(t)\n    \\]\n    which leads to\n    \\[\n        \\grad_{\\vec{\\theta}} \\pi(a \\vert{} s, \\vec{\\theta}) = (-1)^a \\vec{x}(s) (1 - \\pi(a \\vert{} s, \\vec{\\theta})).\n    \\]\n\\end{enumerate}", "meta": {"hexsha": "c9b614fb40cf12aa438f0e5df85cf1007aee6065", "size": 7993, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/chapters/chapter13/chapter13_content.tex", "max_stars_repo_name": "15779235038/reinforcement_learning_an_introduction", "max_stars_repo_head_hexsha": "a0ac9e5da6eaeae14d297a560c499d1a6e579c2a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-02T02:44:49.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-02T02:44:49.000Z", "max_issues_repo_path": "exercises/chapters/chapter13/chapter13_content.tex", "max_issues_repo_name": "15779235038/reinforcement_learning_an_introduction", "max_issues_repo_head_hexsha": "a0ac9e5da6eaeae14d297a560c499d1a6e579c2a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/chapters/chapter13/chapter13_content.tex", "max_forks_repo_name": "15779235038/reinforcement_learning_an_introduction", "max_forks_repo_head_hexsha": "a0ac9e5da6eaeae14d297a560c499d1a6e579c2a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.9837398374, "max_line_length": 607, "alphanum_fraction": 0.6176654573, "num_tokens": 2851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7126086485377029}}
{"text": "% !TeX root = index.tex\n\\section{High School Arithmetic}\nWe will consider addition in the group $\\bbz/100$. Denote the elements of $\\bbz/100$ by $\\tens{a}\\units{b}$ where $a,b \\in \\set {0, 1, \\dots, 9}$.\n\n\\subsection{The carry function}\n\\begin{mdframed}\n  \\adjustbox{scale=1,center}{%\n    \\begin{tikzcd}\n      &\\mbox{Adding 2-digit numbers}\n        \\ar[ddddl, leftrightarrow]\n        % \\ar[ddddr, leftrightarrow, end anchor={[xshift=0ex]}]\n        &\n      \\\\\\\\\\\\\\\\\n      \\mbox{2-cocycle condition}\n      % \\ar[rr, dashed, leftrightarrow]\n      & & \\text{\\color{white} Group extensions}\n    \\end{tikzcd}\n  }\n\\end{mdframed}\n\n\nAddition in $\\bbz/100$ is defined by the formula\n\\begin{equation}\n  \\label{equation:additionFormula}\n  \\tens{a_1}\\units{b_1} + \\tens{a_2}\\units{b_2}\n  =\n  \\tens{a_1 + a_2 + c(b_1, b_2)}\\units{b_1 + b_2}\n\\end{equation}\nwhere $c: \\bbz/10 \\times \\bbz/10 \\rightarrow \\bbz/10$ is the ``carry'' function\n\n\\begin{qbox}\n  Give an explicit definition of the carry function $c$.\n\\end{qbox}\n\n\\begin{qbox}\n  Is $c$ a group homomorphism?\n\\end{qbox}\n\nThe binary operation on abelian groups satisfies the following three properties:\n\\begin{enumerate}\n  \\item identity: $\\qquad x + 0 = x = 0 + x$,\n  \\item commutativity: $\\qquad x+y = y+x$,\n  \\item associativity: $\\qquad (x+y)+z = x + (y+z)$.\n\\end{enumerate}\n\n\\begin{qbox}\n  Using Equation \\eqref{equation:additionFormula} and the fact that $\\bbz/100$ is an abelian group, determine the corresponding identities the function $c$ satisfies?\n\\end{qbox}\nSuch a function $c$ has a very fancy name, it is called a\n\\begin{align*}\n  \\underbrace{\\mathrm{normalized}}_{\\mathrm{identity}}\n  \\underbrace{\\mathrm{symmetric}}_{\\mathrm{commutativity}}\n  \\underbrace{\\mathrm{2-cocycle}}_{\\mathrm{associativity}}.\n\\end{align*}\n\n\\begin{qbox}\n  \\label{q:cocycleDefinesGroup}\n  Conversely, show that if a function $c: \\bbz/10 \\times \\bbz/10 \\rightarrow \\bbz/10$ is a normalized, symmetric, 2-cocycle then ``defining'' an addition on $\\bbz/100$ using Equation \\ref{equation:additionFormula} defines an abelian group structure on it.\\hint{The only new thing you need to check is that inverses exist.}\n\\end{qbox}\n\n% \\begin{qbox}\n%    Let $0 \\le k < 10$ be an integer. Check that \\begin{align*}\n%     c_k: \\bbz/10 \\times \\bbz/10 &\\rightarrow \\bbz/10\\\\\n%     c_k(b_1,b_2) &=\n%       \\begin{cases}\n%         0 & \\mbox{if } b_1 + b_2 < 10, \\\\\n%         k & \\mbox{if } b_1 + b_2 \\ge 10.\n%       \\end{cases}\n%   \\end{align*} is also a normalized symmetric 2-cocycle.\n% \\end{qbox}\n\n% Let $N_k = \\set{ \\tens{a} \\units{b}}$ be the set of two-digit numbers with addition defined as\n% \\begin{align*}\n%   +_k: N_k \\times N_k\n%     &\\longrightarrow N_k, \\\\\n%   \\tens{a_1}\\units{b_1} +_k \\tens{a_2}\\units{b_2}\n%     &=\n%     \\tens{a_1 + a_2 + c_k(b_1, b_2)}\\units{b_1 + b_2}.\n% \\end{align*}\n%\n% By Q.\\ref{q:cocycleDefinesGroup}, $(N_k, +_k)$ is an abelian group.\n\nUsing 2-cocycles, it is possible to create some very exotic ``carry functions''.\n\\begin{qbox}\n  \\label{q:symmetricCocycles}\n  Come up with other examples of normalized, symmetric, 2-cocycles $c:\\bbz/10 \\times \\bbz/10 \\rightarrow \\bbz/10$.\n\\end{qbox}\n\nThere are exactly 4 isomorphism classes of abelian groups of order 100:\n  \\begin{equation*}\n    \\bbz/100,\\quad \\bbz/50 \\times \\bbz/2, \\quad \\bbz/20 \\times \\bbz/5, \\quad \\bbz/10 \\times \\bbz/10.\n  \\end{equation*}\n\n\\begin{qbox}\n  Each of the examples of carry functions $c$ you found in Q.\\ref{q:symmetricCocycles} defines an abelian group structure on the set of 2-digit numbers. Find its isomorphism class.\n\\end{qbox}\n\n\\begin{qbox}[Bonus Question]\n  Can you find all the normalized, symmetric, 2-cocycles $c:\\bbz/10 \\times \\bbz/10 \\rightarrow \\bbz/10$? (I do not know any way to answer this question without using group cohomology computations. It would be amazing if you could solve this problem by some elementary methods.)\n\\end{qbox}\n", "meta": {"hexsha": "22b5d5d4da3ca7d5c4cb95234b08dfd15e8e29d8", "size": 3874, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01.tex", "max_stars_repo_name": "apurvnakade/mc2019-group-cohomology", "max_stars_repo_head_hexsha": "14a7f5f0e2ae64f3ceaa602b50fa80269e3800a5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "01.tex", "max_issues_repo_name": "apurvnakade/mc2019-group-cohomology", "max_issues_repo_head_hexsha": "14a7f5f0e2ae64f3ceaa602b50fa80269e3800a5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01.tex", "max_forks_repo_name": "apurvnakade/mc2019-group-cohomology", "max_forks_repo_head_hexsha": "14a7f5f0e2ae64f3ceaa602b50fa80269e3800a5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.3564356436, "max_line_length": 322, "alphanum_fraction": 0.6765616933, "num_tokens": 1368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388125473629, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7126086455573268}}
{"text": "\\section{Discrete Wavelet Transform}\n\n\\subsection{One dimensional DWT}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.5]{dwt_1d_anal_synth.png}\n    \\caption{1-D DWT, two-band wavelet analysis and synthesis filter banks \\cite{jpeg_suite}}\n    \\label{fig:dwt_1d_anal_synth}\n\\end{figure}\n\nThe linear convolution (filtering) of sequences $x(n)$ and $h(n)$ is defined as in equation \\ref{eq:convolution}:\n\\begin{equation}\n    y(n)=\\sum_{m=-\\infty}^{\\infty}x(m)h(n-m)\n\\label{eq:convolution}\n\\end{equation}\nThe one dimensional discrete wavelet transform can be depicted as successive applications (convolutions) of\none selected pair of high and low-pass filters. The output of such application is then followed\nby downsampling by the factor of two. For example, it can be achieved by discarding samples with\nodd indices after each of filtering operation. It is better visualized in the Figure \\ref{fig:dwt_1d_anal_synth} \\cite{jpeg_suite}.\nThe pair of low and high-pass filters is known as analysis filter bank in the encoding process.\nIn the signal decoding process it is featured as a synthesis filter bank. The decoding step requires\nusing the inverse of discrete wavelet transform.\n\nTake into consideration a one dimensional signal $x(n) = \\{55, 234, 70, 21, 88, 37\\}$. It can be better\nunderstood as values of pixels in a part of the grayscale image row. It is followed with a pair of low\nand high-pass filters designated by $h_{0}(n)$ and $h_{1}(n)$ respectively. An example of such pair is\na lowpass filter $h_{0}(n) = \\{-1, 2, 6, 2, -1\\}/8$ and a high-pass filter $h_{1}(n) = \\{-1, 2, -1\\}/2$. They are both\nsymmetric and consist of only integer operations. Such pair can be presented in the notation of (5, 3) filter bank.\nThis convention indicates that the length of lowpass filter is five and the length of high-pass filter is three.\nIn fact the analysis filter bank presented here was firstly proposed by LeGall and Tabatabai in 1988 and\nis used in the JPEG 2000 standard for lossless compression of images. The filtering operation has to\nbe defined at the signal boundaries. Therefore, the one dimensional signal is extended in both directions.\nThe Part 1 of the JPEG 2000 standard requires symmetrical extension to be performed in such case \\cite{jpeg_suite}.\nAfter applying the required symmetrical padding the signal is extended to\n$x(n) = \\{21, 70, 234, 55, 55, 234, 70, 21, 88, 37, 37, 88, 21, 70\\}$. Then, the low-pass filter is applied\nresulting in $x'_{0}(n) = \\{197.25, 75.5, 98.375, 67.125, 45.375\\}$ and the high-pass one which results in\n$x'_{1}(n) = \\{44.75, -85.75, 29, 12.75, -29.5\\}$.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.45]{dwt_1d_2_level.png}\n    \\caption{Computation of a 2-level 4-point DWT using a two-stage two-channel Haar analysis filter bank \\cite{dwt_impl}}\n    \\label{fig:dwt_1d_2_level}\n\\end{figure}\n\nThe next example shows how to compute the two levels of discrete wavelet transform. To speed up the process\nno padding option is chosen this time which makes it non-compliant with the JPEG 2000 standard.\nThe filter used here is the most basic one, i.e. Haar analysis filter bank. It is the first wavelet\nfrom the Daubechies wavelet family. The calculation process is visualized in the Figure \\ref{fig:dwt_1d_2_level} \\cite{dwt_impl}.\n\nThe input is chosen as 4-point signal $X_{\\phi}(2, k) = \\{2, 1, 3, 4\\}$. This notation emphasizes the fact\nthat it is approximation of the input at scale 2. The so called scaling coefficients (or in other term\napproximation at scale 1) $X_{\\phi}(1, k)$ are computed by convolving the input $x(k)$ with the low-pass\nHaar filter impulse response $l(k) = \\{1/\\sqrt{2}, 1/\\sqrt{2}\\}$. In the next step there is downsampling\nby a factor of 2 applied. The output of convolution has five values. The middle three from these fives \ncorrespond to cases where both the given input values overlap with the impulse response. As it was described\nearlier, the odd values are preserved in the downsampling process. In a result first and third value of these\nthree middle ones are the approximation output $X_{\\phi}(1, k)$. In the similar way, the detail coefficients\nat scale 1 $X_{\\psi}(1, k)$ are computed. The input $x(k)$ is convolved with the high-pass filter impulse\nresponse $h(k) = \\{-1/\\sqrt{2}, 1/\\sqrt{2}\\}$. Then the downsampling by factor of 2 is performed.\nNote that only only approximation output $X_{\\phi}(1, k)$ of the first stage goes to the second one.\nThe $X_{\\phi}(0, 0)$ and $X_{\\psi}(0, 0)$ are calculated accordingly at the end of the second stage \\cite{dwt_impl}.\n\n\\subsection{Two dimensional DWT}\n\nThe idea of using lowpass filter is the preservation of low frequencies of a signal while trying\nto eliminate or at least attenuate the high frequencies. In a result the output signal is the blurred\nversion of the original one. Therefore, the operating principle of the high-pass filter is completely\nopposite. As a result of applying such filter, the high frequencies of the signal are preserved and\nthe low ones are discarded or at least diminished. The output is a signal consisting of edges, textures\nand other details \\cite{jpeg_suite}.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.7]{dwt_2d_example_wiki.png}\n    \\caption{2D DWT applied 2 times to an exemplary image \\cite{dwt_example_wiki}}\n    \\label{fig:dwt_2d_example_wiki}\n\\end{figure}\n\nThere is presented an example of the effects of the two dimensional discrete wavelet transform on the Figure \\ref{fig:dwt_2d_example_wiki}.\nThe DWT used here is compliant with the Part 1 of the JPEG2000 standard. The number of DWT stages presented in this  \nexample is equal to two. Two dimensional discrete wavelet transform applied first time to the original image\nyields four same sized sub-images. The LL layer (upper left sub-image) is an approximation of the image and contains the low frequencies.\nThis layer is once more transformed in the next stage. The LH layer (upper right sub-image) preserves high frequencies from the rows of the image.\nAs a result vertical lines and details (brightness) can be seen in the produced sub-image. On the other hand, the HL layer (bottom left)\ncontains high frequencies from the columns of the image. The horizontal details and lines can be noticed there.\nLastly, the HH layer (bottom right) preserves the diagonal lines \\cite{dwt_example_wiki}.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.45]{dwt_2d_1_level.png}\n    \\caption{Computation of a 1-level 4 $\\times$ 4 2-D Haar DWT using a two-stage filter bank \\cite{dwt_impl}}\n    \\label{fig:dwt_2d_1_level}\n\\end{figure}\n\nThe process of computing a 1 level two dimensional discrete wavelet transform with usage of\ntwo-stage analysis Haar filter bank is shown in Figure \\ref{fig:dwt_2d_1_level}. Coefficients $\\mathbf{X}_{\\phi}$\nare calculated as a result of lowpass filtering and downsampling to each row of the two dimensional\ndata. Next, similar process process, i.e. lowpass convolution and downsampling is applied to each column of\nresulting data. The rest of coefficients is obtained in very similar fashion to the previous ones.\nCoefficients $\\mathbf{X}^{H}_{\\psi}$ are calculated by applying high-pass filtering and downsampling to each row of the\n2-D data $\\mathbf{x}$ and then followed by applying sequence of low-pass filtering and downsampling to each\ncolumn of the resulting data. Coefficients $\\mathbf{X}^{V}_{\\psi}$ are obtained by applying low-pass filtering\nand then downsampling to each column of the resulting data. Lastly, coefficients $\\mathbf{X}^{D}_{\\psi}$ are\nobtained by applying high-pass filtering and downsampling to each row of the 2-D data $\\mathbf{x}$ followed by\napplying high-pass filtering and downsampling to each column of the resulting data. In the next stage of more\ncomplex DWT calculating process only the coefficients $\\mathbf{X}_{\\phi}$ are taken into consideration \\cite{dwt_impl}.\n\n\\subsection{DWT features summary}\n\n\\begin{itemize}\n    \\item In a nutshell, the discrete wavelet transform is a set of bandpass filters. Usually it is implemented\n    with the usage of low and high-pass filters recursively.\n    \\item The computational complexity of computing the DWT in the best case is linear, i.e. $O(N)$.\n    \\item The first approach to implement the DWT efficiently is evaluation of the required convolutions\n    with the usage of the polyphase filter structure.\n    \\item The second approach is factorization of the polyphase matrix into a product of a set of sparse matrices.\n    \\item The two dimensional discrete wavelet transform (with separable filters) is usually computed by the row-column method.\n    One dimensional DWT of all the columns is computed at first. Then the 1-D DWT of all the resulting\n    rows is calculated. The order of the computation in the row-column method can be swapped. The result remains the same.\n    \\item Additional memory of approximate half the size of the given data is required in the some implementations of the DWT.\n    However, there also exist methods of computing DWT in-place which do not require additional memory. \n    \\item Data reordering is required for an in-place computation of the DWT.\n    \\item Data expansion problem can occur due to the finite length of the data in the implementation of the asymmetric filters.\n    \\item Symmetric filters provide linear phase response and an effective solution to the border problem \\cite{dwt_impl}.\n\\end{itemize}\n\n\\section{Part 2 of the JPEG 2000} \\label{sec:part2_jpeg2000}\n\n% Part2 in details\n% write down different filters and basic ones\n\n\\subsection{Introduction}\n\nMany ideas have been emerging as the JPEG 2000 was developed. These concept were full of\nvalue-added capabilities. However, they were not that important to be gone through the time-consuming\nISO standardization process. The Part 1 (ISO/IEC, 2004a) of the standard, i.e. Core coding system, \nwas originally published in 2000. There was a need to create additional parts to include\nmissing features. The Part 2 of the standard, published as ISO/IEC 15444-2 or ITU Recommendation\nT.801 (ISO/IEC, 2004b), contains multiple such extensions. There is present group of rather small\nadditions that could not merit entire documents of their own. In the Part 1 Core of JPEG 2000\nstandard decoders are supposed to handle all of the code-stream functionality. The Part 2\nis different from first one in this aspect. It is a collection of options that can be\nimplemented on demand to meet very specific requirements of the given market. Moreover,\nsections within an extension annex can be implemented separately. For example, subsets\nof extended file format JPX can be used on their own. Therefore, some features of the Part 2\nmay be present in the wide spectrum of JPEG 2000 applications while the other ones can be\nless common in the decoders \\cite{jpeg_suite}.\n\nAs it was shown in the previous paragraph, the extensions present in the Part 2 consist of \nvery different set of topics that can modify or add some features to the Part 1 JPEG 2000 compliant \nprocessing chain. Some tools can result in the compression efficiency improvement. Others can\nameliorate the visual appearance of compressed images. Another group of extensions can modify\nor extend some functionalities in the other ways. The list of the major topics is presented below \\cite{jpeg_suite}.\n\\newline \\newline Compression efficiency:\n\\begin{itemize}\n    \\item Variable DC offset (VDCO) - Annex B\n    \\item Variable scalar quantization (VSQ) - Annex C\n    \\item Trellis coded quantization (TCQ) - Annex D\n    \\item Extended visual masking - Annex E\n    \\item Arbitrary wavelet decomposition - Annex F\n    \\item Arbitrary wavelet transform kernel - Annexes G and H\n    \\item Multiple component transform - Annex J\n    \\item Nonlinear point transform - Annex K \\cite{jpeg_suite}\n\\end{itemize}\n\\hfill \\break Functionalities:\n\\begin{itemize} \n    \\item Geometric manipulation - Annex I\n    \\item Single-sample overlap (SSO/TSSO) - Annex I\n    \\item Precinct-dependent quantization - Amendment 1\n    \\item Extended region of interest - Annex L\n    \\item Extended file format/metadata (JPX) - Annexes M and N\n    \\item Extended capabilities signaling - Amendment 2 \\cite{jpeg_suite}\n\\end{itemize}\n\n\\subsection{Arbitrary Decomposition} \\label{sec:arbitrary_decomposition}\n\nIn the Part 1 of the JPEG 2000 standard there is only one wavelet decomposition structure allowed.\nThis wavelet is called Mallat dyadic decomposition. Such decomposition is a good first choice\nto be applied across a wide spectrum of images. However, other ones can improve the quality of the image\nover specialized classes of the applications. The other effect of applying such decompositions are\nunequal reductions in the horizontal and vertical dimensional of reduced resolution extracts \\cite{jpeg_suite}.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.45]{part_2_decomp_examples.png}\n    \\caption{Some examples of decomposition compliant with the Part 2 \\cite{jpeg_suite}}\n    \\label{fig:part_2_decomp_examples}\n\\end{figure}\n\nOther decomposition styles can be found in the wavelet literature. They include the full packet\ntree processing and some of its derivatives. The applied packet decomposition derivatives\ncan outperform the solution from Part 1 of the JPEG 2000 standard in some applications.\nFor instance, they come crucial at maintaining regular fine-grain texture. Moreover,\nthe applications that require processing synthetic aperture radar images can benefit\nfrom using this extension. The US Federal Bureau of Investigation actively uses a 500 ppi\nfingerprint compression standard, i.e. WSQ (CJIS, 1997). The decomposition is specialized\nfor the characteristics of fingerprint imagery at 500 dpi \\cite{jpeg_suite}.\n\nSome of these decomposition can be seen of the Figure \\ref{fig:part_2_decomp_examples}.\nResolution decomposition is depicted as solid lines. Dashed lines represent extra sublevel\ndecomposition. On the first example, i.e. image $(a)$, there is available full packet decomposition\nwith such parameters: NL = 3: Ddfs = 111, Doads = 321, Dsads = all 1s. The next picture\nillustrates FBI decomposition wit specified parameters: NL = 5: Ddfs = 11111, Doads = 2321,\nDsads = 11101111111111111. The last image is juts an arbitrary example \\cite{jpeg_suite}.\n\nThe prespecified decomposition structures are not the only feature of this extension.\nWavelet packet analysis can be also used to design custom decompositions for specific images\nor some types of images. It was implemented in these papers \\cite{entropy_algos},\n\\cite{wavelet_packet} and \\cite{adaptive_wavelet}. Such applications often start with\na large decomposition tree. Then, they tend to locate a good decomposition based upon\nspecified optimization metric \\cite{jpeg_suite}.\n\n\\subsection{Arbitrary Wavelet Transforms} \\label{sec:arbitrary_wavelet_transform}\n\n\\begin{table}\n    \\centering\n    \\caption{Analysis and synthesis filter taps for the floating-point Daubechies (9, 7) filter bank}\n    \\label{tab:anal_synth_97i}\n\\begin{tabular}{ccc}\n    \\toprule\n    n         & Low-pass, $h_{0}(n)$ & Low-pass, $g_{0}(n)$ \\\\\n    \\midrule\n    $0$       & +0.602949018236360  & +1.115087052457000  \\\\\n    $\\pm 1$   & +0.266864118442875  & +0.591271763114250  \\\\\n    $\\pm 2$   & -0.078223266528990  & -0.057543526228500  \\\\\n    $\\pm 3$   & -0.016864118442875  & -0.091271763114250  \\\\\n    $\\pm 4$   & +0.026748757410810  &                     \\\\\n    \\bottomrule\n\\end{tabular}\n\n\\bigskip\n\\bigskip\n\n\n\\begin{tabular}{cc}\n    \\toprule\n    n         & High-pass, $h_{1}(n)$ \\\\\n    \\midrule\n    $-1$      & +1.115087052457000   \\\\\n    $-2, 0$   & -0.591271763114250   \\\\\n    $-3, 1$   & -0.057543526228500   \\\\\n    $-4, 2$   & +0.091271763114250   \\\\\n              &                      \\\\\n    \\bottomrule\n\\end{tabular}\n\\quad\n\\begin{tabular}{cc}\n    \\toprule\n    n        & High-pass, $g_{1}(n)$ \\\\\n    \\midrule\n    $1$      & +0.602949018236360   \\\\\n    $0, 2$   & -0.266864118442875   \\\\\n    $-1, 3$  & -0.078223266528990   \\\\\n    $-2, 4$  & +0.016864118442875   \\\\\n    $-3, 5$  & +0.026748757410810   \\\\\n    \\bottomrule\n\\end{tabular}\n\\end{table}\n\n\\begin{table}\n    \\centering\n    \\caption{Analysis and synthesis filter taps for the integer (5, 3) filter bank}\n    \\label{tab:anal_synth_53r}\n\\begin{tabular}{ccc}\n    \\toprule\n    n         & Low-pass, $h_{0}(n)$ & Low-pass, $g_{0}(n)$ \\\\\n    \\midrule\n    $0$       & +0.75  & +1    \\\\\n    $\\pm 1$   & +0.25  & +0.5  \\\\\n    $\\pm 2$   & -0.125 &       \\\\\n    \\bottomrule\n\\end{tabular}\n\n\\bigskip\n\\bigskip\n\n\n\\begin{tabular}{cc}\n    \\toprule\n    n         & High-pass, $h_{1}(n)$ \\\\\n    \\midrule\n    $-1$      & +1   \\\\\n    $-2, 0$   & -0.5 \\\\\n              &      \\\\\n    \\bottomrule\n\\end{tabular}\n\\quad\n\\begin{tabular}{cc}\n    \\toprule\n    n        & High-pass, $g_{1}(n)$ \\\\\n    \\midrule\n    $1$      & +0.75  \\\\\n    $0, 2$   & -0.25  \\\\\n    $-1, 3$  & -0.125 \\\\\n    \\bottomrule\n\\end{tabular}\n\\end{table}\n\nThe Part 1 of the JPEG 2000 standard specifies only two possible wavelet transforms.\nThe reversible one (5-3R, Table \\ref{tab:anal_synth_53r}) and the irreversible one\n(9-7I, Table \\ref{tab:anal_synth_97i}). As it was stated before, both\nare required to perform periodic symmetric signal extension at the boundaries.\nIt is similar case to the Mallat dyadic decomposition in terms of generic implementation.\nThese filters can compress quite well a wide set of image types. However, certain image\nclasses can be compressed more efficiently with other types of wavelets. Such a flexibility\nis allowed in the Part 2 compliant applications. The range of wavelet transforms is broadened\nto include not only the wider range of whole-sample symmetric ones but also half-sample and\ngeneric nonsymmetric ones. Such ability to handle generic filters makes JPEG 2000 standard\na powerful research tool, together with supporting more than niche compression applications \\cite{jpeg_suite}.\n\n\\section{Parallelism in computer architecture}\n\nThe parallelism as general term can be simply understood as two or more separate activities\nthat appear to happen at the same time. It is not only computer science specific abstraction\nbut also natural part of life. For instance a person can drive a car and simultaneously\ntalk on the phone or one person can have a walk, while the other one is riding bike.\nHowever, the computer science aspect of parallelism is the interesting part in this paper.\nIt can be depicted as single system performing multiple independent tasks at the same time\nrather than one after the other \\cite{cpp_concurrency}. Multitasking operating systems have been\nin usage for many years. However, running multiple applications was firstly done only by context switching.\nThe situation has been a little bit different in the server industry. High-end machines with multiple processors\nhave been available there for years making utilization of the real parallelism possible.\nIn recent years there is observed increase of personal computers capable of running multiple tasks\nin similar manner \\cite{cpp_concurrency}.\n\nNowadays, there is a trend in producing increasing amount of processors in multicore solutions by chip manufacturers.\nThere can be found 16 or even more processor cores on a single chip. Following this way is easier\nfor improving performance over strengthening single core solutions. Therefore, multicore desktop\ncomputers and even embedded devices are growing share in the market. In the past, it was possible\nfor programmers to get their application run faster without doing anything. Such situation\nwas linked with the growing computation power within new generation for single core solutions. \nThe situation is quite different at the present time. If a software has to take advantage of\nincreasing computing power, one has to design and utilize concurrent run of multiple tasks \\cite{cpp_concurrency}.\n\nThere are two approaches of utilizing concurrency in terms of performance. The most obvious one\nis just to divide a single task into separate parts. Then, such subtasks can be run in parallel\nreducing the total execution time of the program. This approach is called ``task parallelism''.\nDespite sounding rather straightforward, such operation can become a complex process.\nEspecially whether there exist many dependencies between the separated parts. Such division\ncan be applied in two different ways. The first one is connected with processing, i.e.\none thread executes certain part of the given algorithm while the other ones perform operations\nat the different part. The other way is connected strictly with the data. Each thread\nperforms the same operation on different parts of the given data. The latter approach is called\ndata level parallelism \\cite{cpp_concurrency}.\n\nThere exists quite notable subgroup of algorithms which are basically ready to be parallelized.\nThey are often referred as ``embarrassingly parallel'', ``naturally parallel'' or\n``conveniently concurrent'' \\cite{cpp_concurrency}. Such algorithms are especially good in terms\nof scalability properties. As the number of available hardware resources, i.e. threads\nincreases, the parallelism level in the algorithm is trivial to match. However, if there exist\nparts of the algorithm which are not easy to parallelize, one has to divide the algorithm\ninto a fixed number of tasks. Therefore such application becomes not scalable one \\cite{cpp_concurrency}.\n\nThe another way to use parallelism for improving performance is to employ existing concurrent\nsolutions to solve bigger issues. This approach can be depicted as processing 2, 5 or 10 files at\ngiven time instead of just one. Although it seems like another application of data level parallelism,\nthere is different focus in performing such operation on sets of data concurrently.\nThe amount of time needed to process one chunk of data is still the same. However, more data\ncan be processed in the same amount of time. Unfortunately, there are limits on this specific\napproach as well. Moreover, there are cases where such attitude can be nonbeneficial at all.\nIn the end, the increase in throughput which comes from this specific approach makes\nnew things possible, e.g. increased resolution in video processing where different areas\nof the picture can be processed at the same time \\cite{cpp_concurrency}.\n    \n\n\\section{Known solutions}\n\n\\subsection{Part 1 compliant applications} \\label{sec:part_1}\n\nThere are multiple solutions that implement features from the Part 1 of the JPEG 2000 standard.\nThe OpenJPEG library is an example of such application. It is open-source solution developed to\npromote wider usage of this standard. The main part of this project is the codec compliant with\nthe Part 1 of the JPEG 2000 standard. Moreover, the OpenJPEG library integrates other parts\nof the standard \\cite{jpeg_suite}. Few of them can be seen on the list below:\n\n\\begin{itemize}\n    \\item from the Part 2: handling the JP2 boxes and extended multiple component\n    transforms for multi and hyperspectral imagery.\n    \\item from the Part 3: MJ2 (Motion JPEG 2000).\n    \\item from the Part 11: JPWL (JPEG 2000 Wireless).\n    \\item OPJViewer, a GUI based tool for visualization of the J2K (extension used for storing\n    code-stream JPEG 2000 data), JP2 (standard JPEG 2000 file extension), JPWL and MJ2 files.\n    \\item OPJIndexer, a code-stream indexer to view information about the headers and packets localization.\n    This tool is also capable of reading the rate-distortion contribution of each packet to the image \\cite{jpeg_suite}.\n\\end{itemize}\n\nThe OpenJPEG library is written in the C programming language and released under the BSD license.\nThe main targets of this software are desktop platforms, i.e. Win32, Unix and Mac OS platforms.\nThe Communications and Remote Sensing Lab (TELE) of the Catholic University of Louvain (UCL)\nis the main developer group of this library. CS company and CNES is the supporting side.\nSome of the modules are maintained by the Digital Signal Processing Lab (DSPLab) of the University\nof Perugia, mainly the JPWL and OPJViewer. \\cite{jpeg_suite}.\n\nAnother example of Part 1 compliant application is the JasPer. This computer software project is aimed\nto create reference implementation of the standard codec. The project was started by the Image Power Inc.\nand the University of British Columbia back in the 1997. As OpenJPEG JasPer is written in the C programming language.\nThere are some sample applications available in the codebase. They can come in handy while testing the codec. \nJasPer is currently released publicly under the MIT license. The library is a component of several notable\nsoftware projects. It includes but is not limited to netpbm, ImageMagick and KDE. In series of the JPEG 2000\ncompression tests conducted in 2004 JasPer turned out to be the top performing solution, closely followed by\nIrfanView and Kakadu. The disadvantage of this implementation is its time performance. In the same tests\nJasPer was the slowest software. However, it is a feature as this codec was designed to be used as reference\nin non performance-critical systems.\n\nThere is one more notable implementation of the Part 1, i.e. Grok. It is open-sourced software released under\nthe GNU Affero General Public License (AGPL) version 3 license. Its design aims to provide stable, high\nperformant and low memory using solution. The function responsible for decoding process (grk\\_decompress)\nis currently over 0.5 the speed of the Kakadu software. Moreover, Grok supports fast sub-tile decoding\nto standard output for png, jpeg, bmp, pnm and raw formats. This library supports both TLM and PLT code stream markers\nfor fast single-tile and sub-tile decoding of large tiled images. The support of meta-data formats such as\nXML, IPTC, XMP and ICC profiles is also included. There is also initial version of Part 15 implementation\n(High Throughput JPEG 2000) available. The final version of this solution should be ten times faster over\nthe original Part 1 of the JPEG 2000 standard.\n\n\\subsection{Kakadu} \\label{sec:kakadu}\n\nKakadu is not only a complete implementation of the JPEG 2000 standard Part 1 but also an application\nthat supports Part 2 and Part 3 in a significant amount of features. The software was originally developed\nby David Taubman of the University of New South Wales (UNSW) in Australia. The author is also noticeably\nknown for being the designer of EBCOT, i.e. the core coding component of JPEG 2000. The name of this library\ncomes from ``Kakadu National Park'' which is located in the Northern Territory of Australia \\cite{jpeg_suite}. Licensing\nis more advanced in comparison to solutions mentioned in \\fullref{sec:part_1}. There are separate licensing\nschemes for research, commercial and demonstration-only applications.\n\nThe Kakadu software framework is widely adopted in the substantial range of JPEG 2000 products. The few examples\nare Apple's Quicktime v6 for MAC, Yahoo's Messenger, Google Earth and Internet Archive \\cite{jpeg_suite}. \nFeatures that can be realized thanks to Kakadu's implementation by the named beforehand solutions include live video\nand products for geospatial imagery such as MicroImages TNT. Moreover, this framework is used in medical imaging applications,\ninteractive image rendering applications, remote browsing of large collection and images, digital cinema applications\nand the other fields that require compression and decompression of JPEG 2000 images and videos \\cite{jpeg_suite}.\n\nKakadu is considered as a comprehensive, heavily optimized and fully compliant software toolkit for JPEG 2000\ndevelopers. There are multiple features available that make runtime execution so flawless. Multithreaded\nprocessing is supported in such way that makes the most of parallel processing resources, i.e. multiple CPUS,\nmulticore CPUs and hyperthreading \\cite{jpeg_suite}. Compiler intrinsic functions are utilized to manually\nvectorize processing of data in processor's pipeline. Moreover, Kakadu comes with built-in thread scheduler.\nSuch implementation enables possibility of utilizing all computational resources close to 100\\%.\nIn a 2007 the JasPer library was outperformed by Kakadu in terms of speed.\n\nSupported features of Part 2 include arbitrary wavelet transform kernels and general multicomponent transforms.\nThe Kakadu library offers extensive support for interactive mode of client–server applications. It is done\nthanks to the implementation of the most notable features from the JPIP (JPEG 2000 Internet Protocols) standard \\cite{jpeg_suite}.\n\n\\subsection{Reversible denoising and lifting steps with step skipping}\n\nMethods such as reversible denoising and lifting based color component transformation aim to improve\noverall quality of image compression. Color space transformation in reversible manner is required\nby the lossless image compression framework used in the JPEG 2000 standard. The undesirable side effect\nof such transformation is contamination of transformed components with noise from other ones.\nTherefore, the compression ratio of given image is substantially diminished \\cite{denoising}.\n\nThe work in this specific paper is aimed to remove correlation without increasing the noise.\nTherefore, a reversible denoising and lifting step (RDLS) was proposed. The RDLS integrates\nusage of denoising filters into lifting step. New image component transformation is a result\nof applying RDLS to color space transformation. The main feature of this operation is\nbeing ``reversible despite involving the inherently irreversible denoising'' \\cite{denoising}.\n\nThe main targets using application of RDLS to the RDgDb color space transformation with\nsimple denoising filters are the JPEG-LS, JPEG 2000 and JPEG XR lossless modes of the\nstandard algorithms.\nThe images which have native optical resolution of acquisition devices benefit the most\nfrom this application. Improvement in terms of compression ratios is the most visible\nin subset of images which unmodified color space transformation either improved or worsened\nratios in comparison to the untransformed image. On the average improvement is between\n5\\% and 6\\% for such specific images. However, things differ for images from ``standard\ntest-sets'' resulting in the improvement only up to 2.2\\% \\cite{denoising}.\n\nAnother application of the RDLS (reversible denoising and lifting step) is described\nin the paper \\cite{entropy}. New method of using ``hybrid transform'' was introduced there.\nThe main input to that paper was discrete wavelet transform using custom prediction\nmechanism. Although simple prediction is considered to be ineffective when combined with DWT,\nthe application of modified discrete wavelet transform using RLDS with step skipping is able to\ntake advantages of its strengths. The usage of heuristics and estimation of entropy resulted\nin making described transform ``image-adaptive'' \\cite{entropy}.\n\nThe data set used for experiments in the presented paper contained 247 non-photographic and\n499 photographic images. As a result it was found that described approach using combination\nof RDLS with step skipping, DWT and prediction turned out to be effective. The prediction\nmechanism allowed to double the JPEG 2000 compression ratio improvements made by using only RDLS.\nCompression schemes with various tradeoffs were proposed due to fact that for some images\napplying prediction instead of DWT could be more beneficial. The compression ratios of non-photographic\nand photographic images improved by 30.9\\% and 1.2\\%, respectively, in comparison to solution\ncompliant with Part 1 of the JPEG 2000 standard. The cost was in the increase of compression\ntime by 2\\% and breaking mentioned before compliance. Greater ratio improvements were claimed to\nbe possible with greater cost in runtime performance \\cite{entropy}.\n\n\\subsection{Skipping Selected Steps of DWT Computation}\n\nThe other method of improving image compression, i.e. bitrates of lossless JPEG 2000 is skipping\nselected steps of discrete wavelet computation (SS-DWT). At the first phase of implementing\nthis particular method fixed SS-DWT variants were employed. Then, heuristic was employed to select\nfrom the mentioned before variants best one for certain image \\cite{skipping_dwt}.\n\nThe experiments on diverse set of images resulted in the improvement of bitrates vastly of\nnon-photographic images. ``The entropy estimation of encoding effects'' was used to select the most\nfeasible variant of applied fixed SS-DWT. It is especially important from the practical standpoint\nas time execution of such application is reduced. ``Such compression scheme is compliant with the Part 2\nof the JPEG 2000 standard as opposed to the general SS-DWT case'' \\cite{skipping_dwt}.\n\nThe average improvement in terms of bitrate was around 5\\% for the entire test-set. Moreover,\nthe time needed to perform compression of the image was only 3\\% great than the part 1 of the JPEG 2000\ncompliant variant. However, the results are quite different across the set of photographic and non-photographic\nimages. The first ones are improved on average by 0.5\\% while the latter by 14\\%. The heuristic can\nbe further exploited to perform more modifications and result with improvement of bitrate up to 17.5\\%.\nThese extra modifications include ``skipping the steps based on the actual bitrate rather than the\nestimated one and applying reversible denoising and lifting steps to SS-DWT''. However it is achieved with\ngreat time penalty \\cite{skipping_dwt}.\nFurthermore, it has been evaluated that applying the fixed skipped steps discrete wavelet\ntransform (fixed SS-DWT) variants with the lossless compression compliant with the Part 2\nof JPEG 2000 standard can provide another improvements \\cite{practical_dwt}.\n", "meta": {"hexsha": "e919c7d860dd0733f2521fa5a6c1e819f0877611", "size": 33747, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chapters/problem.tex", "max_stars_repo_name": "SzymonZos/Master-Thesis", "max_stars_repo_head_hexsha": "6ea6020302d848598b35f0940525cae85b5f5f95", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "thesis/chapters/problem.tex", "max_issues_repo_name": "SzymonZos/Master-Thesis", "max_issues_repo_head_hexsha": "6ea6020302d848598b35f0940525cae85b5f5f95", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-01-21T11:58:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-03T22:56:32.000Z", "max_forks_repo_path": "thesis/chapters/problem.tex", "max_forks_repo_name": "SzymonZos/Master-Thesis", "max_forks_repo_head_hexsha": "6ea6020302d848598b35f0940525cae85b5f5f95", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.783625731, "max_line_length": 146, "alphanum_fraction": 0.7790322103, "num_tokens": 8110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.7126086454162205}}
{"text": "\\documentclass[10pt,a4paper]{article}\r\n\\usepackage{amsmath,amssymb,bm,graphicx,pictex,makeidx,subfigure}\r\n\\usepackage[italian,english]{babel}\n\\usepackage[center,small]{caption}[2007/01/07]\r\n\\usepackage{fancyhdr}\n\\usepackage{color}\n\n\\definecolor{blu}{rgb}{0,0,1}\n\\definecolor{verde}{rgb}{0,1,0}\n\\definecolor{rosso}{rgb}{1,0,0}\n\n\\begin{document}\n\n\\section{The $\\chi^2$ in the presence of correlations}\n\nSuppose to have an ensamble of $n$ measurements having the following\nstructure:\n\\begin{equation}\n  m_i\\pm \\sigma_{i,\\rm stat} \\pm \\sigma_{i,\\rm unc} \\pm \\sigma_{i,\\rm\n    corr}^{(1)}\\pm\\dots \\pm \\sigma_{i,\\rm\n    corr}^{(k)}\\,,\n\\end{equation}\nwhere $m_i$, with $i=1,\\dots, n$, is the central value of the $i$-th\nmeasurement, $\\sigma_{i,\\rm stat}$ its (uncorrelated) statistical\nuncertainty, $\\sigma_{i,\\rm unc}$ its uncorrelated systematic\nuncertainty\\footnote{There could be more than one uncorrelated\n  systematic uncertainty. In this case, $\\sigma_{i,\\rm unc}$ is just\n  the square root of the sum in quadrature of all the uncorrelated\n  systematic uncertainties.}, and $\\sigma_{i,\\rm corr}^{(l)}$, with\n$l=1,\\dots,k$, its correlated systematic uncertainties. With this\ninformation at hand, one can construct the full covariance matrix\n$V_{ij}$ as follows (see for example Ref.~\\cite{Ball:2012wy}):\n\\begin{equation}\\label{eq:covmat}\n  V_{ij}=\\left(\\sigma_{i,\\rm stat}^2 +\\sigma_{i,\\rm unc}^2\\right)\\delta_{ij} + \\sum_{l=1}^{k}\\sigma_{i,\\rm\n    corr}^{(l)}\\sigma_{j,\\rm\n    corr}^{(l)}\\,.\n\\end{equation}\nThis is a clearly symmetric matrix. Given a set of predictions $t_i$\ncorresponding to the $n$ measurements of the ensamble, the $\\chi^2$\ntakes the form:\n\\begin{equation}\\label{eq:chi2cov}\n  \\chi^2=\n  \\sum_{i,j=1}^{n}\\left(m_i-t_i\\right)V_{ij}^{-1}\\left(m_j-t_j\\right) =\n  \\mathbf{y}^{T} \\cdot \\mathbf{V}^{-1} \\cdot \\mathbf{y}\\,,\n\\end{equation}\nwhere in the second equality we have used the matricial notation and\ndefined $y_i = m_i-t_i$. A convenient way to compute the $\\chi^2$\nrelies on the Cholesky decomposition of the covariance matrix\n$\\mathbf{V}$. In particular, it can be proven that any symmetric and\npositive definite matrix $\\mathbf{V}$ can be decomposed as:\n\\begin{equation}\\label{eq:choleskydec}\n\\mathbf{V} = \\mathbf{L}\\cdot\\mathbf{L}^{T}\\,,\n\\end{equation}\nwhere $\\mathbf{L}$ is a lower triangular matrix whose entries are\nrelated recursively to those of $\\mathbf{V}$ as follows:\n\\begin{equation}\\label{eq:cholalg}\n\\begin{array}{rcl}\n  L_{kk} &=&\\displaystyle \\sqrt{V_{kk}-\\sum_{j=1}^{k-1}L_{kj}^2}\\,,\\\\\n  \\\\\n  L_{ik} &=&\\displaystyle\n             \\frac{1}{L_{kk}}\\left(V_{ik}-\\sum_{j=1}^{k-1}L_{ij}L_{kj}\\right)\\,,\\quad\n             k < i\\,,\\\\\n\\\\\n  L_{ik} &=&\\displaystyle 0\\,,\\quad\n             k > i\\,.\\\\\n\\end{array}\n\\end{equation}\nIt is then easy to see that the $\\chi^2$ can be written as:\n\\begin{equation}\n\\chi^2 = \\left|\\mathbf{L}^{-1}\\cdot \\mathbf{y}\\right|^2\\,.\n\\end{equation}\nBut the vector $\\mathbf{x} \\equiv \\mathbf{L}^{-1}\\cdot \\mathbf{y}$ is\nthe solution of the linear system:\n\\begin{equation}\n  \\mathbf{L} \\cdot \\mathbf{x} = \\mathbf{y}\\,,\n\\end{equation}\nthat can be efficiently solved by forward substitution, so that:\n\\begin{equation}\n  \\chi^2 = \\left|\\mathbf{x}\\right|^2\\,.\n\\end{equation}\nFollowing this procedure, one does not need to compute explicitly the\ninverse of the covariance matrix $\\mathbf{V}$, simplifying\nsignificantly the computation of the $\\chi^2$.\n\n\\section{Additive and multiplicative uncertainties}\n\nThe correlated systematic uncertainties $\\sigma_{i,\\rm corr}^{(l)}$\nmay be either \\textit{additive} or \\textit{multiplicative}. The nature\nof the single uncertainties is typically provided by the experiments\nthat release the measurements. A typical example of multiplicative\nuncertainty is the luminosity uncertainty but there can be others.\n\nNow let us express all the correlated systematic uncertainties\n$\\sigma_{i,\\rm corr}^{(l)}$ as relative to the associate central value\n$m_i$, so that we define\\footnote{Note that this redefinition does not\n  change the nature of the uncertainties, additive uncertainties\n  remain additive as well as multiplicative uncertainties remain\n  multiplicative.}:\n\\begin{equation}\n\\sigma_{i,\\rm corr}^{(l)}\\equiv  \\delta_{i,\\rm corr}^{(l)} m_i\n\\end{equation}\nand let us also define\n$s_i^2\\equiv \\sigma_{i,\\rm stat}^2 +\\sigma_{i,\\rm unc}^2$ so that\nEq.~(\\ref{eq:covmat}) can be rewritten as:\n\\begin{equation}\\label{eq:covmat2}\n  V_{ij}=s_i^2\\delta_{ij} + \\left(\\sum_{l=1}^{k}\\delta_{i,\\rm\n    corr}^{(l)}\\delta_{j,\\rm\n    corr}^{(l)}\\right)m_im_j\\,.\n\\end{equation}\nNow we split the correlated systematic uncertainties into $k_a$\nadditive uncertainties and $k_m$ multiplicative uncertainties, such\nthat $k_a+k_m=k$. This way Eq.~(\\ref{eq:covmat2}) takes the form:\n\\begin{equation}\\label{eq:covmat3}\n  V_{ij}=s_i^2\\delta_{ij} + \\left(\\sum_{l=1}^{k_a}\\delta_{i,\\rm\n    add}^{(l)}\\delta_{j,\\rm\n    add}^{(l)}+\\sum_{l=1}^{k_m}\\delta_{i,\\rm\n    mult}^{(l)}\\delta_{j,\\rm\n    mult}^{(l)}\\right)m_im_j\\,.\n\\end{equation}\nIt is well known that this definition of the covariance matrix is\nproblematic in that it results in the so-called D'Agostini bias of the\nmultiplicative uncertainties~\\cite{DAgostini:1993arp}. A possible\nsolution to this problem is the so-called\n$t_0$-prescription~\\cite{Ball:2009qv}, where the experimental central\nvalue $m_i$ in the multiplicative term is replaced by a fixed\ntheoretical predictions $t_i^{(0)}$, typically computed in a previous\nfit in which the ``standard'' definition of the covariance matrix in\nEq.~(\\ref{eq:covmat}) (often referred to as \\textit{experimental}\ndefinition) is used. Applying the $t_0$ prescription, the covariance\nmatrix takes the form:\n\\begin{equation}\\label{eq:covmat4}\n  V_{ij}=s_i^2\\delta_{ij} + \\sum_{l=1}^{k_a}\\delta_{i,\\rm\n    add}^{(l)}\\delta_{j,\\rm\n    add}^{(l)}m_im_j+\\sum_{l=1}^{k_m}\\delta_{i,\\rm\n    mult}^{(l)}\\delta_{j,\\rm\n    mult}^{(l)}t_i^{(0)}t_j^{(0)}\\,.\n\\end{equation}\n\n\\section{Artificial generation of correlated systematics}\n\nIn order to implement the definition of the $\\chi^2$ discussed above,\nit is necessary to have the experimental information in terms of the\ncorrelated systematic uncertainties $\\sigma_{i,\\rm corr}^{(l)}$. This\nis what the experimental collaborations usually release. However, in\nsome cases this information is given in terms of a covariance\nmatrix. Therefore, one needs to find a workaround to generate\ncorrelated systematic uncertainties out of a covariance matrix. \n\nGiven a $n \\times n$ symmetric matrix $\\mathbf{C}$, it will have $n$\northonormal eigenvectors $\\mathbf{x}^{(i)}$, such that\n$\\mathbf{x}^{(i)}\\cdot \\mathbf{x}^{(j)}=\\delta_{ij}$, each of which\nwill have a non-negative eigenvalue $\\lambda_i$ associated:\n\\begin{equation}\n  \\mathbf{C}\\cdot \\mathbf{x}^{(i)} = \\lambda_i \\mathbf{x}^{(i)}\\,, \\quad\n  i =1,\\dots,n\\,.\n\\end{equation}\nIf we define:\n\\begin{equation}\\label{eq:artsys}\n  \\sigma_{i,\\rm corr}^{(l)} = \\sqrt{\\lambda_l} x_i^{(l)}\\,,\\quad i,l=1,\\dots,n\\,,\n\\end{equation}\none can show that:\n\\begin{equation}\\label{eq:artsydef}\n  \\sum_{l=1}^{n}\\sigma_{i,\\rm corr}^{(l)}\\sigma_{j,\\rm corr}^{(l)} =C_{ij}\\,.\n\\end{equation}\nTo prove this equality we start from the following matricial relation:\n\\begin{equation}\n\\mathbf{C} =\\mathbf{Q}\\cdot \\mathbf{\\Lambda}\\cdot \\mathbf{Q}^{-1}\\,,\n\\end{equation}\nwhere $\\mathbf{\\Lambda}$ is a diagonal matrix with the eigenvalues\n$\\lambda_i$ on the diagonal ($\\Lambda_{ij} = \\lambda_i\\delta_{ij}$),\nwhile $\\mathbf{Q}$ is a matrix whose columns are the eigenvectors\n$\\mathbf{x}^{(i)}$ ($Q_{ij} = x_{i}^{(j)}$). In addition, since in\nthis particular case\n$\\mathbf{x}^{(i)}\\cdot \\mathbf{x}^{(j)}=\\delta_{ij}$, this implies\nthat:\n\\begin{equation}\n\\mathbf{Q}^T \\cdot \\mathbf{Q}  = \\mathbf{I}\\quad\\Rightarrow\\quad\n\\mathbf{Q}^{-1} =  \\mathbf{Q}^{T}\\,,\n\\end{equation}\nso that:\n\\begin{equation}\\label{eq:diagC}\n  \\mathbf{C} =\\mathbf{Q}\\cdot \\mathbf{\\Lambda}\\cdot \\mathbf{Q}^{T}\\,.\n\\end{equation}\nIt follows that:\n\\begin{equation}\n  C_{ij} =\\sum_{k,l=1}^{n}Q_{ik}\\Lambda_{kl} Q_{jl} = \\sum_{k,l=1}^{n} x_{i}^{(k)}\n  \\lambda_{k}\\delta_{kl}x_{j}^{(l)} = \\sum_{l=1}^{n} \\lambda_{l}x_{i}^{(l)}\n  x_{j}^{(l)}=\\sum_{l=1}^{n}\\sigma_{i,\\rm corr}^{(l)}\\sigma_{j,\\rm corr}^{(l)} \\,,\n\\end{equation}\nas required.\n\nThe matrix \\textbf{C} can be regarded as the correlated contribution to\nthe full covariance matrix \\textbf{V}. In particular, considering\nEqs.~(\\ref{eq:covmat}) and~(\\ref{eq:covmat2}), one can write:\n\\begin{equation}\n\\mathbf{V} = \\mathbf{U} + \\mathbf{C}\\,,\n\\end{equation}\nwhere $\\mathbf{U}$ is a diagonal matrix of uncorrelated uncertainties:\n\\begin{equation}\nU_{ij} = s_i^2\\delta_{ij}\\,.\n\\end{equation}\nThis defines the matrix $\\mathbf{C}$ as:\n\\begin{equation}\\label{eq:corrdef}\n\\mathbf{C} = \\mathbf{V} - \\mathbf{U}\\,,\n\\end{equation}\nsuch that, given a $n\\times n$ covariance matrix $\\mathbf{V}$ along\nwith its uncorrelated contribution $\\mathbf{U}$, one can generate a\nset of $n$ \\textit{artificial} correlated systematics according to\nEq.~(\\ref{eq:artsys}), where $\\mathbf{C}$ is given in\nEq.~(\\ref{eq:corrdef}), for each of the $n$ measurements. This allows\nus to implement Eq.~(\\ref{eq:covmat4}) for the construction of the\ncovariance matrix.\n\n\\section{Determining the systematic shifts}\n\nIn order to visualise the effect of systematic uncertainties, it is\ninstructive to compute the \\textit{systematic shift} generated by the\nsystematic uncertainties. To do so, we need to write the $\\chi^2$ in\nterms of the so-called ``nuisance parameters'' $\\lambda_\\alpha$. One\ncan show that the definition of the $\\chi^2$ in Eq.~(\\ref{eq:chi2cov})\nis equivalent to~\\cite{Ball:2012wy}:\n\\begin{equation}\\label{eq:chi2nuis}\n\\chi^2 = \\sum_{i=1}^n\\frac{1}{s_i^2}\\left(m_i -t_i\n  -\\sum_{\\alpha=1}^k\\lambda_\\alpha \\sigma_{i,\\rm corr}^{(\\alpha)} \\right)^2 + \\sum_{\\alpha=1}^k\\lambda_\\alpha^2\\,.\n\\end{equation}\nThe optimal value of the nuisance parameters can be computed by\nminimising the $\\chi^2$ with respect to them, that is imposing:\n\\begin{equation}\n\\frac{\\partial \\chi^2}{\\partial \\lambda_\\beta} = 0\\,.\n\\end{equation}\nThis yields the system:\n\\begin{equation}\\label{eq:nuissys}\n  \\sum_{\\beta=1}^kA_{\\alpha\\beta}\\lambda_\\beta =\\rho_\\alpha\\,,\n\\end{equation}\nwith:\n\\begin{equation}\\label{eq:sysing}\nA_{\\alpha\\beta}= \\delta_{\\alpha\\beta}+\\sum_{i=1}^n\\frac{\\sigma_{i,\\rm corr}^{(\\alpha)}\\sigma_{i,\\rm corr}^{(\\beta)}}{s_i^2}\\quad\\mbox{and}\\quad \\rho_\\alpha=\\sum_{i=1}^n\\frac{m_i-t_i}{s_i^2}\\sigma_{i,\\rm corr}^{(\\alpha)}\\,,\n\\end{equation}\nthat determines the values of $\\lambda_\\beta$. The quantity:\n\\begin{equation}\nd_i =\\sum_{\\alpha=1}^k\\lambda_\\alpha \\sigma_{i,\\rm corr}^{(\\alpha)}\n\\end{equation}\nin Eq.~(\\ref{eq:chi2nuis}) can be interpreted as a shift caused by the\ncorrelated systematic uncertainties. Defining the shifted predictions\nas:\n\\begin{equation}\n\\overline{t}_i =t_i+d_i\\,,\n\\end{equation}\nthe $\\chi^2$ reads:\n\\begin{equation}\\label{eq:chi2nuisshift}\n  \\chi^2 = \\sum_{i=1}^n\\left(\\frac{m_i -\\overline{t}_i}{s_i}\\right)^2 + \\sum_{\\alpha=1}^k\\lambda_\\alpha^2\\,.\n\\end{equation}\nTherefore, up to a penalty term given by the sum of the square of the\nnuisance parameters, the $\\chi^2$ takes the form of the uncorrelated\ndefinition. In order to achieve a visual assessment of the agreement\nbetween data and theory, it appears natural to compare the central\nexperimental values $m_i$ to the shifted theoretical predictions\n$\\overline{t}_i$ in units of the uncorrelated uncertainty $s_i$.\n\n\n% \\section{The effect of cuts}\n\n% Due to the possible mutual correlation of the measurements of a given\n% ensamble, the exclusion of any of the measurements in the computation\n% of the $\\chi^2$ necessarily introduces an inconsistency. However, in\n% many cases, due to limitations in the computation of the theoretical\n% predictions, it is unavoidable introducing cuts. Unfortunately, there\n% is no way to avoid this inconsistency and the best one can do is to\n% compute the $\\chi^2$ in Eq.~(\\ref{eq:chi2cov}) skipping the values of\n% $i$ and $j$ corresponding to the measurements excluded from the\n% computation.\n\n% Since cuts are typically of kinematic origin, one can argue that in\n% the case of \\textit{unnormalised} measurements the correlation between\n% measurements taken in sufficiently different kinematic regions are not\n% very correlated. This ensures that the exclusion of measurements based\n% on kinematic cuts does not bias the computation of the $\\chi^2$\n% significantly\\footnote{This heuristic argument is far from being\n%   rigorous.}. However, in the presence of \\textit{normalised}\n% measurements this problem is made more severe by the fact that the\n% (common) normalisation introduces a further correlation that is\n% transversal to the whole ensamble~\\cite{Boughezal:2017nla}. Moreover,\n% normalised measurements are typically such that the integral over the\n% full ensamble gives one. Therefore, excluding data breaks the\n% normalisation.  However, this problem can be overcome by simply\n% normalising the theoretical predictions to the integral of the\n% measurements that survive the cut.\n\n\\begin{thebibliography}{alp}\n\n%\\cite{Ball:2009qv}\n\\bibitem{Ball:2009qv}\n  R.~D.~Ball {\\it et al.} [NNPDF Collaboration],\n  %``Fitting Parton Distribution Data with Multiplicative Normalization Uncertainties,''\n  JHEP {\\bf 1005} (2010) 075\n  doi:10.1007/JHEP05(2010)075\n  [arXiv:0912.2276 [hep-ph]].\n  %%CITATION = doi:10.1007/JHEP05(2010)075;%%\n  %84 citations counted in INSPIRE as of 13 May 2018\n\n%\\cite{DAgostini:1993arp}\n\\bibitem{DAgostini:1993arp}\n  G.~D'Agostini,\n  %``On the use of the covariance matrix to fit correlated data,''\n  Nucl.\\ Instrum.\\ Meth.\\ A {\\bf 346} (1994) 306.\n  doi:10.1016/0168-9002(94)90719-6\n  %%CITATION = doi:10.1016/0168-9002(94)90719-6;%%\n  %146 citations counted in INSPIRE as of 13 May 2018\n\n%\\cite{Ball:2012wy}\n\\bibitem{Ball:2012wy}\n  R.~D.~Ball {\\it et al.},\n  %``Parton Distribution Benchmarking with LHC Data,''\n  JHEP {\\bf 1304} (2013) 125\n  doi:10.1007/JHEP04(2013)125\n  [arXiv:1211.5142 [hep-ph]].\n  %%CITATION = doi:10.1007/JHEP04(2013)125;%%\n  %102 citations counted in INSPIRE as of 13 May 2018\n\n%\\cite{Boughezal:2017nla}\n\\bibitem{Boughezal:2017nla}\n  R.~Boughezal, A.~Guffanti, F.~Petriello and M.~Ubiali,\n  %``The impact of the LHC Z-boson transverse momentum data on PDF determinations,''\n  JHEP {\\bf 1707} (2017) 130\n  doi:10.1007/JHEP07(2017)130\n  [arXiv:1705.00343 [hep-ph]].\n  %%CITATION = doi:10.1007/JHEP07(2017)130;%%\n  %19 citations counted in INSPIRE as of 13 May 2018\n\n\\end{thebibliography}\n\n\n\\end{document}\n", "meta": {"hexsha": "287ce1e6f38c37be9f804edccad88b4494caca04", "size": 14484, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/src/CovarianceMatrix.tex", "max_stars_repo_name": "intrepid42/apfelxx", "max_stars_repo_head_hexsha": "34b0bb4f134ddf42aa7eccceaa6c3b91b5414cd6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/src/CovarianceMatrix.tex", "max_issues_repo_name": "intrepid42/apfelxx", "max_issues_repo_head_hexsha": "34b0bb4f134ddf42aa7eccceaa6c3b91b5414cd6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/src/CovarianceMatrix.tex", "max_forks_repo_name": "intrepid42/apfelxx", "max_forks_repo_head_hexsha": "34b0bb4f134ddf42aa7eccceaa6c3b91b5414cd6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.3652694611, "max_line_length": 222, "alphanum_fraction": 0.7144435239, "num_tokens": 4906, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995028, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7125794861663856}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage[ruled, vlined]{algorithm2e}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{booktabs}\n\\usepackage{geometry}\n\\usepackage{parskip}\n\n\\geometry{a4paper}\n\n\\title{Set-based Minesweeper}\n\\author{Andrew Kritzler}\n\n\n\n\n\\begin{document}\n\\maketitle\n\\tableofcontents\n\\newpage\n\n\n\\section{Definition of \\(G\\)}\n\nMinesweeper is usually played on a finite rectangular grid containing a predetermined number of mines.\nConsider the following \\(3 \\times 4\\) grid with 3 mines.\n\\[\n    \\begin{matrix}\n        \\texttt{0} & \\texttt{1} & \\texttt{\\#} & \\texttt{*} \\\\\n        \\texttt{1} & \\texttt{2} & \\texttt{3}  & \\texttt{-} \\\\\n        \\texttt{X} & \\texttt{@} & \\texttt{-}  & \\texttt{-} \\\\\n    \\end{matrix}\n\\]\n\n\\texttt{*} is a mine, \\texttt{@} is a detonated mine, \\texttt{\\#} is a correct flag, \\texttt{X} is an incorrect flag, and \\texttt{-} is a plain tile.\nThe following table provides a description of every cell.\n\\begin{center}\n    \\begin{tabular}{*{6}{c}}\n        \\toprule\n        \\(x\\) & \\(y\\) & Tile        & Mine?     & Revealed? & Flagged?  \\\\\n        \\midrule\n        0     & 0     & \\texttt{X}  &           &           & \\(\\top \\) \\\\\n        0     & 1     & \\texttt{1}  &           & \\(\\top \\) &           \\\\\n        0     & 2     & \\texttt{0}  &           & \\(\\top \\) &           \\\\\n        1     & 0     & \\texttt{@}  & \\(\\top \\) & \\(\\top \\) &           \\\\\n        1     & 1     & \\texttt{2}  &           & \\(\\top \\) &           \\\\\n        1     & 2     & \\texttt{1}  &           & \\(\\top \\) &           \\\\\n        2     & 0     & \\texttt{-}  &           &           &           \\\\\n        2     & 1     & \\texttt{3}  &           & \\(\\top \\) &           \\\\\n        2     & 2     & \\texttt{\\#} & \\(\\top \\) &           & \\(\\top \\) \\\\\n        3     & 0     & \\texttt{-}  &           &           &           \\\\\n        3     & 1     & \\texttt{-}  &           &           &           \\\\\n        3     & 2     & \\texttt{*}  & \\(\\top \\) &           &           \\\\\n        \\bottomrule                                                     \\\\\n    \\end{tabular}\n\\end{center}\n\nHopefully, the following transformation is self-explanatory.\nFor each entry in the matrix, \\((x, y) \\in M\\) if and only if it is a mine.\nSimilarly, sets \\(R\\) and \\(F\\) are used for the remaining columns.\n\\[\n    \\begin{aligned}\n        M & = \\{(1, 0), (2, 2), (3, 2)\\}                         \\\\\n        R & = \\{(0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 1)\\} \\\\\n        F & = \\{(0, 0), (2, 2)\\}\n    \\end{aligned}\n\\]\n\n\\(G = (M, R, F)\\) is a minesweeper game, where \\(M, R, F \\subseteq \\mathbb{Z}^2\\) and \\(R \\cap F = \\varnothing \\).\nNotice how \\(G\\) does not encode the dimensions of the grid; the grid is considered to be infinite.\nAn infinite game is impractical because computers have finite resources and the player could never win.\nHowever, the simplicity of this model is useful for mathematical study.\n\n\n\\section{Dynamic Generation of \\(M\\)}\n\nLet \\(A : \\mathbb{Z}^2 \\to \\mathcal{P}(\\mathbb{Z}^2)\\) be a function that outputs the set of adjacent coordinates.\n\\(A\\) is a useful building block for more complex logic.\nFor example, \\(|A(x, y) \\cap M|\\) counts the number of mines adjacent to \\((x,y)\\).\n\\[A(x, y) = (\\{x - 1, x, x + 1\\} \\times \\{y - 1, y, y + 1\\}) \\setminus \\{(x, y)\\} \\]\n\nGenerating \\(M\\) statically is impossible.\nAn infinite board cannot be described in terms of its number of mines.\nInstead, the board must be described in terms of its density of mines.\nLet \\(\\gamma \\) be a predetermined value representing the proportion of cells which are mines, where \\(0 \\leq \\gamma \\leq 1\\).\nFor example, in a \\(16 \\times 30\\) board with 99 mines, \\(\\gamma = 99 \\div (16 \\times 30) = 0.20625\\).\n\nA cell \\((x, y)\\) is \\textit{inactive} if it and its adjacent cells have not been revealed, i.e., \\((x, y) \\notin R\\) and \\(A(x, y) \\cap R = \\varnothing \\).\nWhen the player reveals a cell, mines are randomly placed in the inactive cells within \\(A(x, y) \\cup \\{(x, y)\\} \\).\nAfterwards, all nine of these cells become active.\nOn the player's first turn when \\(R = \\varnothing \\), no mines are generated.\nThus, the first tile revealed will always be \\texttt{0}.\n\nFor notation purposes, let \\(X\\) be a standard uniform random variable, i.e., \\(X \\sim U(0, 1)\\).\nAs a result, \\(\\Pr(X < \\gamma ) = \\gamma \\).\n\n\\begin{algorithm}[H]\n    \\SetAlgoLined{}\n    \\DontPrintSemicolon{}\n    \\caption{Reveal}\n    \\eIf{\\((x, y) \\notin R \\cup F\\)}{\n        \\If{\\(R \\neq \\varnothing \\)}{\n            \\ForAll{\\((u, v) \\in A(x, y) \\cup \\{(x, y)\\} \\)}{\n                \\If{\\((u, v) \\notin R \\wedge A(u, v) \\cap R = \\varnothing \\)}{\n                    \\If{\\(X < \\gamma \\)}{\n                        \\(M \\gets M \\cup \\{(u, v)\\} \\)\n                    }\n                }\n            }\n        }\n        \\(R \\gets R \\cup \\{(x, y)\\} \\) \\\\\n        \\Return{\\(\\top \\)}\n    }{\n        \\Return{\\(\\bot \\)}\n    }\n\\end{algorithm}\n\n\n\\end{document}\n", "meta": {"hexsha": "3586745cf17af83aaeeeddf3d4dc3837045026ce", "size": 4924, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/mines.tex", "max_stars_repo_name": "peppermintpatty5/mines", "max_stars_repo_head_hexsha": "5793a7c36032250f7e374e5317d9d9180691f017", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/mines.tex", "max_issues_repo_name": "peppermintpatty5/mines", "max_issues_repo_head_hexsha": "5793a7c36032250f7e374e5317d9d9180691f017", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/mines.tex", "max_forks_repo_name": "peppermintpatty5/mines", "max_forks_repo_head_hexsha": "5793a7c36032250f7e374e5317d9d9180691f017", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.694214876, "max_line_length": 156, "alphanum_fraction": 0.5046709992, "num_tokens": 1600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995028, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.7125794757166246}}
{"text": "\\subsubsection{Time Series Normalization}\n\n\\begin{frame}{Time Series Normalization}\n    \\begin{itemize}\n        \\item z-normalization or Z-scoring time series is common prior DTW calculation \\cite{ding2008querying}\n        \n        \\item Two different time series normalizations $\\eta$ and $\\eta '$ from \\cite{das1998rule}\n    \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Time Series Normalization}{Calculation}\n    \\begin{block}{Given}\n        \\begin{itemize}\n            \\item A domain set $\\mathbb{U}$\n            \n            \\item A distance measure function $d$ with $d: \\mathbb{U} \\times \\mathbb{U} \\to \\mathbb{R}$\n            \n        \\end{itemize}\n    \\end{block}\n    \\begin{block}{Input}\n        \\begin{itemize}\n            \\item A time series $Q = (q_1, q_2, \\dots, q_i, \\dots, q_l)$ with length $l$ over the domain set\n                $\\mathbb{U}$\n        \\end{itemize}\n    \\end{block}\n\\end{frame}\n\n\\begin{frame}{Time Series Normalization $\\eta$}{Calculation}\n    \\begin{block}{Calculation}\n        \\begin{itemize}\n            \\item Every data point $q$ of $Q$ will be transformed by $\\eta$\n            \n            \\item $\\eta (q) = q -\\bar{q}$\n            \n        \\end{itemize}\n    \\end{block}\n    \\begin{block}{Mean of $Q$}\n        \\begin{itemize}\n            \\item $\\bar{q} = \\frac{1}{l} \\sum \\limits_{i=1}^{l} q_i$\n        \\end{itemize}\n    \\end{block}\n\\end{frame}\n\n\\begin{frame}<handout:0>{Time Series Normalization $\\eta$}{Example}\n    \\begin{center}\n        \\resizebox {\\textwidth} {!} {\n            \\begin{tabular}{cc}\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tikzpicture}\n                        \\begin{axis}[\n                            xmin=0,\n                            xmax=47,\n                            xlabel=time,\n                            ylabel=acceleration,\n                            width=\\axisdefaultwidth,\n                            height=0.7*\\axisdefaultheight,\n                            reverse legend,\n                            legend pos=south east]\n                            \\addplot[red, thick, mark=none] table {../data/fig/dynamictimewarping/q.dat};\n                            \\addlegendentry{Q}\n                            \\addplot[blue, thick, mark=none] table {../data/fig/dynamictimewarping/c.dat};\n                            \\addlegendentry{C}\n                        \\end{axis}\n                    \\end{tikzpicture}\n                } & \\quad\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tabular}[b]{ll}\n                        \\begin{turn}{90}\n                            \\begin{tikzpicture}\n                                \\begin{axis}[\n                                    xmin=0,\n                                    xmax=47,\n                                    ymin=-100,\n                                    ymax=0,\n                                    hide x axis,\n                                    hide y axis,\n                                    width=\\axisdefaultwidth,\n                                    height=0.7*\\axisdefaultheight]\n                                    \\addplot[red, ultra thick, mark=none] table {../data/fig/dynamictimewarping/q.dat};\n                                \\end{axis}\n                            \\end{tikzpicture}\n                        \\end{turn} \\hspace*{3em} &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                enlargelimits=false,\n                                ymin=0,\n                                ymax=47,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=\\axisdefaultwidth,\n                                colorbar,\n                                colormap/viridis high res]\n                                \\addplot[matrix plot*,\n                                    mesh/cols=48,\n                                    point meta=explicit] table[meta=C] {../data/fig/dynamictimewarping/matrix.dat};\n                            \\end{axis}\n                        \\end{tikzpicture} \\\\\n                        &\n                        \\\\[1em]\n                        &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                xmin=0,\n                                xmax=47,\n                                ymin=-100,\n                                ymax=0,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=0.7*\\axisdefaultheight]\n                                \\addplot[blue, ultra thick, mark=none] table {../data/fig/dynamictimewarping/c.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\n                    \\end{tabular}\n                }\n            \\end{tabular}\n        }\n    \\end{center}\n\\end{frame}\n\n\\begin{frame}<handout:0>{Time Series Normalization $\\eta$}{Example}\n    \\begin{center}\n        \\resizebox {\\textwidth} {!} {\n            \\begin{tabular}{cc}\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tikzpicture}\n                        \\begin{axis}[\n                            xmin=0,\n                            xmax=47,\n                            xlabel=time,\n                            ylabel=acceleration,\n                            width=\\axisdefaultwidth,\n                            height=0.7*\\axisdefaultheight,\n                            reverse legend,\n                            legend pos=south east]\n                            \\addplot[red, thick, mark=none] table {../data/fig/norm1/q.dat};\n                            \\addlegendentry{Q}\n                            \\addplot[blue, thick, mark=none] table {../data/fig/norm1/c.dat};\n                            \\addlegendentry{C}\n                        \\end{axis}\n                    \\end{tikzpicture}\n                } & \\quad\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tabular}[b]{ll}\n                        \\begin{turn}{90}\n                            \\begin{tikzpicture}\n                                \\begin{axis}[\n                                    xmin=0,\n                                    xmax=47,\n                                    ymin=-40,\n                                    ymax=40,\n                                    hide x axis,\n                                    hide y axis,\n                                    width=\\axisdefaultwidth,\n                                    height=0.7*\\axisdefaultheight]\n                                    \\addplot[red, ultra thick, mark=none] table {../data/fig/norm1/q.dat};\n                                \\end{axis}\n                            \\end{tikzpicture}\n                        \\end{turn} \\hspace*{3em} &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                enlargelimits=false,\n                                ymin=0,\n                                ymax=47,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=\\axisdefaultwidth,\n                                colorbar,\n                                colormap/viridis high res]\n                                \\addplot[matrix plot*,\n                                    mesh/cols=48,\n                                    point meta=explicit] table[meta=C] {../data/fig/norm1/matrix.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\\\\\n                        &\n                        \\\\[1em]\n                        &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                xmin=0,\n                                xmax=47,\n                                ymin=-40,\n                                ymax=40,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=0.7*\\axisdefaultheight]\n                                \\addplot[blue, ultra thick, mark=none] table {../data/fig/norm1/c.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\n                    \\end{tabular}\n                }\n            \\end{tabular}\n        }\n    \\end{center}\n\\end{frame}\n\n\\begin{frame}{Time Series Normalization $\\eta$}{Example}\n    \\begin{center}\n        \\resizebox {\\textwidth} {!} {\n            \\begin{tabular}{cc}\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tikzpicture}\n                        \\begin{axis}[\n                            xmin=0,\n                            xmax=47,\n                            xlabel=time,\n                            ylabel=acceleration,\n                            width=\\axisdefaultwidth,\n                            height=0.7*\\axisdefaultheight,\n                            reverse legend,\n                            legend pos=south east]\n                            \\addplot[gray, quiver={u=\\thisrow{u}, v=\\thisrow{v}}] table {../data/fig/norm1/path.dat};\n                            \\addplot[red, thick, mark=none] table {../data/fig/norm1/q.dat};\n                            \\addlegendentry{Q}\n                            \\addplot[blue, thick, mark=none] table {../data/fig/norm1/c.dat};\n                            \\addlegendentry{C}\n                        \\end{axis}\n                    \\end{tikzpicture}\n                } & \\quad\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tabular}[b]{ll}\n                        \\begin{turn}{90}\n                            \\begin{tikzpicture}\n                                \\begin{axis}[\n                                    xmin=0,\n                                    xmax=47,\n                                    ymin=-40,\n                                    ymax=40,\n                                    hide x axis,\n                                    hide y axis,\n                                    width=\\axisdefaultwidth,\n                                    height=0.7*\\axisdefaultheight]\n                                    \\addplot[red, ultra thick, mark=none] table {../data/fig/norm1/q.dat};\n                                \\end{axis}\n                            \\end{tikzpicture}\n                        \\end{turn} \\hspace*{3em} &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                enlargelimits=false,\n                                ymin=0,\n                                ymax=47,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=\\axisdefaultwidth,\n                                colorbar,\n                                colormap/viridis high res]\n                                \\addplot[matrix plot*,\n                                    mesh/cols=48,\n                                    point meta=explicit] table[meta=C] {../data/fig/norm1/matrix.dat};\n                                \\addplot[white, ultra thick, mark=*, mark size=1] table {../data/fig/norm1/matrix_path.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\\\\\n                        &\n                        \\\\[1em]\n                        &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                xmin=0,\n                                xmax=47,\n                                ymin=-40,\n                                ymax=40,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=0.7*\\axisdefaultheight]\n                                \\addplot[blue, ultra thick, mark=none] table {../data/fig/norm1/c.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\n                    \\end{tabular}\n                }\n            \\end{tabular}\n        }\n    \\end{center}\n\\end{frame}\n\n\\begin{frame}{Time Series Normalization $\\eta '$}{Calculation}\n    \\begin{block}{Calculation}\n        \\begin{itemize}\n            \\item Every data point $q$ of $Q$ will be transformed by $\\eta '$\n            \n            \\item $\\eta '(q) = \\frac{\\eta (q)}{\\sigma}$\n            \n        \\end{itemize}\n    \\end{block}\n    \\begin{block}{Standard deviation of $Q$}\n        \\begin{itemize}\n            \\item $\\sigma = \\frac{1}{l-1} \\sum \\limits_{i=1}^{l} d(q_i, \\bar{q})^2$\n        \\end{itemize}\n    \\end{block}\n\\end{frame}\n\n\\begin{frame}<handout:0>{Time Series Normalization $\\eta '$}{Example}\n    \\begin{center}\n        \\resizebox {\\textwidth} {!} {\n            \\begin{tabular}{cc}\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tikzpicture}\n                        \\begin{axis}[\n                            xmin=0,\n                            xmax=47,\n                            xlabel=time,\n                            ylabel=acceleration,\n                            width=\\axisdefaultwidth,\n                            height=0.7*\\axisdefaultheight,\n                            reverse legend,\n                            legend pos=south east]\n                            \\addplot[red, thick, mark=none] table {../data/fig/dynamictimewarping/q.dat};\n                            \\addlegendentry{Q}\n                            \\addplot[blue, thick, mark=none] table {../data/fig/dynamictimewarping/c.dat};\n                            \\addlegendentry{C}\n                        \\end{axis}\n                    \\end{tikzpicture}\n                } & \\quad\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tabular}[b]{ll}\n                        \\begin{turn}{90}\n                            \\begin{tikzpicture}\n                                \\begin{axis}[\n                                    xmin=0,\n                                    xmax=47,\n                                    ymin=-100,\n                                    ymax=0,\n                                    hide x axis,\n                                    hide y axis,\n                                    width=\\axisdefaultwidth,\n                                    height=0.7*\\axisdefaultheight]\n                                    \\addplot[red, ultra thick, mark=none] table {../data/fig/dynamictimewarping/q.dat};\n                                \\end{axis}\n                            \\end{tikzpicture}\n                        \\end{turn} \\hspace*{3em} &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                enlargelimits=false,\n                                ymin=0,\n                                ymax=47,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=\\axisdefaultwidth,\n                                colorbar,\n                                colormap/viridis high res]\n                                \\addplot[matrix plot*,\n                                    mesh/cols=48,\n                                    point meta=explicit] table[meta=C] {../data/fig/dynamictimewarping/matrix.dat};\n                            \\end{axis}\n                        \\end{tikzpicture} \\\\\n                        &\n                        \\\\[1em]\n                        &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                xmin=0,\n                                xmax=47,\n                                ymin=-100,\n                                ymax=0,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=0.7*\\axisdefaultheight]\n                                \\addplot[blue, ultra thick, mark=none] table {../data/fig/dynamictimewarping/c.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\n                    \\end{tabular}\n                }\n            \\end{tabular}\n        }\n    \\end{center}\n\\end{frame}\n\n\\begin{frame}<handout:0>{Time Series Normalization $\\eta '$}{Example}\n    \\begin{center}\n        \\resizebox {\\textwidth} {!} {\n            \\begin{tabular}{cc}\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tikzpicture}\n                        \\begin{axis}[\n                            xmin=0,\n                            xmax=47,\n                            xlabel=time,\n                            ylabel=acceleration,\n                            width=\\axisdefaultwidth,\n                            height=0.7*\\axisdefaultheight,\n                            reverse legend,\n                            legend pos=south east]\n                            \\addplot[red, thick, mark=none] table {../data/fig/norm1/q.dat};\n                            \\addlegendentry{Q}\n                            \\addplot[blue, thick, mark=none] table {../data/fig/norm1/c.dat};\n                            \\addlegendentry{C}\n                        \\end{axis}\n                    \\end{tikzpicture}\n                } & \\quad\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tabular}[b]{ll}\n                        \\begin{turn}{90}\n                            \\begin{tikzpicture}\n                                \\begin{axis}[\n                                    xmin=0,\n                                    xmax=47,\n                                    ymin=-40,\n                                    ymax=40,\n                                    hide x axis,\n                                    hide y axis,\n                                    width=\\axisdefaultwidth,\n                                    height=0.7*\\axisdefaultheight]\n                                    \\addplot[red, ultra thick, mark=none] table {../data/fig/norm1/q.dat};\n                                \\end{axis}\n                            \\end{tikzpicture}\n                        \\end{turn} \\hspace*{3em} &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                enlargelimits=false,\n                                ymin=0,\n                                ymax=47,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=\\axisdefaultwidth,\n                                colorbar,\n                                colormap/viridis high res]\n                                \\addplot[matrix plot*,\n                                    mesh/cols=48,\n                                    point meta=explicit] table[meta=C] {../data/fig/norm1/matrix.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\\\\\n                        &\n                        \\\\[1em]\n                        &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                xmin=0,\n                                xmax=47,\n                                ymin=-40,\n                                ymax=40,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=0.7*\\axisdefaultheight]\n                                \\addplot[blue, ultra thick, mark=none] table {../data/fig/norm1/c.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\n                    \\end{tabular}\n                }\n            \\end{tabular}\n        }\n    \\end{center}\n\\end{frame}\n\n\\begin{frame}<handout:0>{Time Series Normalization $\\eta '$}{Example}\n    \\begin{center}\n        \\resizebox {\\textwidth} {!} {\n            \\begin{tabular}{cc}\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tikzpicture}\n                        \\begin{axis}[\n                            xmin=0,\n                            xmax=47,\n                            xlabel=time,\n                            ylabel=acceleration,\n                            width=\\axisdefaultwidth,\n                            height=0.7*\\axisdefaultheight,\n                            reverse legend,\n                            legend pos=south east]\n                            \\addplot[red, thick, mark=none] table {../data/fig/norm2/q.dat};\n                            \\addlegendentry{Q}\n                            \\addplot[blue, thick, mark=none] table {../data/fig/norm2/c.dat};\n                            \\addlegendentry{C}\n                        \\end{axis}\n                    \\end{tikzpicture}\n                } & \\quad\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tabular}[b]{ll}\n                        \\begin{turn}{90}\n                            \\begin{tikzpicture}\n                                \\begin{axis}[\n                                    xmin=0,\n                                    xmax=47,\n                                    ymin=-2,\n                                    ymax=2,\n                                    hide x axis,\n                                    hide y axis,\n                                    width=\\axisdefaultwidth,\n                                    height=0.7*\\axisdefaultheight]\n                                    \\addplot[red, ultra thick, mark=none] table {../data/fig/norm2/q.dat};\n                                \\end{axis}\n                            \\end{tikzpicture}\n                        \\end{turn} \\hspace*{3em} &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                enlargelimits=false,\n                                ymin=0,\n                                ymax=47,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=\\axisdefaultwidth,\n                                colorbar,\n                                colormap/viridis high res]\n                                \\addplot[matrix plot*,\n                                    mesh/cols=48,\n                                    point meta=explicit] table[meta=C] {../data/fig/norm2/matrix.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\\\\\n                        &\n                        \\\\[1em]\n                        &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                xmin=0,\n                                xmax=47,\n                                ymin=-2,\n                                ymax=2,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=0.7*\\axisdefaultheight]\n                                \\addplot[blue, ultra thick, mark=none] table {../data/fig/norm2/c.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\n                    \\end{tabular}\n                }\n            \\end{tabular}\n        }\n    \\end{center}\n\\end{frame}\n\n\\begin{frame}{Time Series Normalization $\\eta '$}{Example}\n    \\begin{center}\n        \\resizebox {\\textwidth} {!} {\n            \\begin{tabular}{cc}\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tikzpicture}\n                        \\begin{axis}[\n                            xmin=0,\n                            xmax=47,\n                            xlabel=time,\n                            ylabel=acceleration,\n                            width=\\axisdefaultwidth,\n                            height=0.7*\\axisdefaultheight,\n                            reverse legend,\n                            legend pos=south east]\n                            \\addplot[gray, quiver={u=\\thisrow{u}, v=\\thisrow{v}}] table {../data/fig/norm2/path.dat};\n                            \\addplot[red, thick, mark=none] table {../data/fig/norm2/q.dat};\n                            \\addlegendentry{Q}\n                            \\addplot[blue, thick, mark=none] table {../data/fig/norm2/c.dat};\n                            \\addlegendentry{C}\n                        \\end{axis}\n                    \\end{tikzpicture}\n                } & \\quad\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tabular}[b]{ll}\n                        \\begin{turn}{90}\n                            \\begin{tikzpicture}\n                                \\begin{axis}[\n                                    xmin=0,\n                                    xmax=47,\n                                    ymin=-2,\n                                    ymax=2,\n                                    hide x axis,\n                                    hide y axis,\n                                    width=\\axisdefaultwidth,\n                                    height=0.7*\\axisdefaultheight]\n                                    \\addplot[red, ultra thick, mark=none] table {../data/fig/norm2/q.dat};\n                                \\end{axis}\n                            \\end{tikzpicture}\n                        \\end{turn} \\hspace*{3em} &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                enlargelimits=false,\n                                ymin=0,\n                                ymax=47,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=\\axisdefaultwidth,\n                                colorbar,\n                                colormap/viridis high res]\n                                \\addplot[matrix plot*,\n                                    mesh/cols=48,\n                                    point meta=explicit] table[meta=C] {../data/fig/norm2/matrix.dat};\n                                \\addplot[white, ultra thick, mark=*, mark size=1] table {../data/fig/norm2/matrix_path.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\\\\\n                        &\n                        \\\\[1em]\n                        &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                xmin=0,\n                                xmax=47,\n                                ymin=-2,\n                                ymax=2,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=0.7*\\axisdefaultheight]\n                                \\addplot[blue, ultra thick, mark=none] table {../data/fig/norm2/c.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\n                    \\end{tabular}\n                }\n            \\end{tabular}\n        }\n    \\end{center}\n\\end{frame}\n", "meta": {"hexsha": "99f3527d84c036cbe29975ca0ad876fbbe57fd24", "size": 27555, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "presentation/background/dynamic_time_warping/time_series_normalization.tex", "max_stars_repo_name": "GordonLesti/SlidingWindowFilter", "max_stars_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-06-22T09:37:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T11:43:53.000Z", "max_issues_repo_path": "presentation/background/dynamic_time_warping/time_series_normalization.tex", "max_issues_repo_name": "GordonLesti/SlidingWindowFilter", "max_issues_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "presentation/background/dynamic_time_warping/time_series_normalization.tex", "max_forks_repo_name": "GordonLesti/SlidingWindowFilter", "max_forks_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-11T23:15:57.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-11T23:15:57.000Z", "avg_line_length": 45.2463054187, "max_line_length": 124, "alphanum_fraction": 0.332462348, "num_tokens": 5234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7125761608467717}}
{"text": "\\section{Misc}\n\n\n\\begin{lemma}\n\tLet the $h$ be the curvature of quadratic function $f$. With $\\overline{x}_t$ being the expectation of $x_t$, we assume, without loss of generality, the optimum point of the quadratic $f$ is 0. Then we have the following recurrence\n\t\\begin{equation} \n\t\t\\begin{pmatrix}\n\t\t\t\\overline{x}_{t + 1} \\\\\n\t\t\t\\overline{x}_t\n\t\t\\end{pmatrix} = \n\t\t\\begin{pmatrix}\n\t\t\t1-\\alpha h + \\mu & - \\mu\\\\\n\t\t\t1 & 0 \\\\\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix}\n\t\t\t\\overline{x}_1 \\\\\n\t\t\t\\overline{x}_0\n\t\t\\end{pmatrix}\n\t\\end{equation} \n\\end{lemma}\n\n\\begin{lemma}\n\tWe define $U_t=\\E \\| x_t - \\overline{x}_t \\|^2$ and $V_t= \\E (x_t - \\overline{x}_t) (x_{t-1} - \\overline{x}_{t-1})$ with $\\overline{x}_t$ being the expectation of $x_t$. For quadratic function $f(x)$ with curvature $h \\in \\mathbb{R}$, We have the following recurrence\n\t\\begin{equation} \n\t\t\\begin{pmatrix}\n\t\t\tU_{t+1} \\\\\n\t\t\tU_t \\\\\n\t\t\tV_{t + 1}\n\t\t\\end{pmatrix} = \n\t\t(\\mat{I} - \\mat{S}^T)(\\mat{I} - \\mat{S})^{-1}\n\t\t\\begin{pmatrix}\n\t\t\t\\alpha^2 \\\\\n\t\t\t0 \\\\\n\t\t\t0\n\t\t\\end{pmatrix}\n\t\\end{equation}\n\twhere \n\t\\begin{equation}\n\t\t\\mat{S} = \n\t\t\\begin{pmatrix}\n\t\t(1-\\alpha h + \\mu)^2 &  \\mu^2 & -2\\mu(1-\\alpha h + \\mu)\\\\\n\t\t1 & 0 & 0 \\\\\n\t\t1-\\alpha h + \\mu & 0 & - \\mu\n\t\t\\end{pmatrix}\n\t\\end{equation}\n\\end{lemma}\n\n\n\\begin{lemma}\n\\label{lem:2times2_spectral_radius}\n\tLet $\\rho(\\mat{T})$ be the spectral radius of matrix  \n\\begin{equation}\n\t\\mat{T} = \\begin{pmatrix}\n\t1-\\alpha h + \\mu & - \\mu\\\\\n\t1 & 0 \\\\\n\t\\end{pmatrix}\n\\end{equation}\nwhere $h\\in \\mathbb{R}$. $\\rho(\\mat{T}) = \\sqrt{\\mu}$ if the following condition holds\n\\begin{align}\n{(1-\\sqrt{\\mu})^2\\over \\alpha} &\\leq h \\leq {(1+\\sqrt{\\mu})^2\\over \\alpha}.\n\\label{equ:control_condition_scalar}\n\\end{align}\n\\end{lemma}\n\n\\begin{lemma}\n\\label{lem:3times3_spectral_radius}\nLet $\\rho(\\mat{S})$ be the spectral radius of matrix \n\\begin{equation}\n\t%\\rho_V(\\alpha, \\mu) = \\rho \\left(\n\\mat{S} = {\\begin{pmatrix}\n(1-\\alpha h + \\mu)^2 &  \\mu^2 & -2\\mu(1-\\alpha h + \\mu)\\\\\n1 & 0 & 0 \\\\\n1-\\alpha h + \\mu & 0 & - \\mu\n\\end{pmatrix}}\n\t%\\right)\n\\end{equation}\nwhere $h\\in \\mathbb{R}$.\n$\\rho(\\mat{S})=\\mu$ if the following condition holds for\n\\begin{equation}\n{(1-\\sqrt{\\mu})^2\\over \\alpha} \\leq h \\leq {(1+\\sqrt{\\mu})^2\\over \\alpha}\n\\label{equ:control_condition_var}\n\\end{equation}\n\\end{lemma}\n\n\n\n\\begin{corollary}\n\\label{cor:}\nUnder the conditions in Eqaution~\\eqref{equ:control_condition_var}, we get\n\\begin{equation}\n\t\\E \\| x_T \\|^2 \n\t= \\mu^T \\| x_0 \\|^2\n\t\t+ (1-\\mu^T) \\frac{\\alpha^2 C}{1-\\mu}\n\t\\label{equ:noisy_square_dist}\n\\end{equation}\n\\label{cor:noisy_dist}\n\\end{corollary}\n\nNow, if we know, or can approximately estimate some of these quantities we can tune the learning rate and momentum hyperparameters to minimize  \\eqref{equ:noisy_square_dist}.\n\n\n\n\n\n\\section{Proof of Lemma~\\ref{}}\nThe generalization of scalar analysis to multiple dimensional case.\n\\begin{lemma}\n\\label{lem:robustness}\nLet the gradients of a function $f$ be described by\n\\begin{equation}\n\t\\nabla f(\\mat{x}_t) = \\mat{H}_t (\\mat{x}_t - \\mat{x}^*),\n\\end{equation}\nfor $\\mat{H}_t \\in \\mathbb{R}^{n\\times n}$.\nThe the momentum update can be expressed as a linear operator:\n\\begin{align}\n{\\begin{pmatrix}\n\\mat{y}_{t+1}\\\\\n\\mat{y}_t \\\\\n\\end{pmatrix}}\n=\n{\\begin{pmatrix}\n\\mat{I}-\\alpha \\mat{H}_t + \\mu \\mat{I} & - \\mu \\mat{I} \\\\\n\\mat{I} & \\mat{0} \\\\\n\\end{pmatrix}}\n{\\begin{pmatrix}\n\\mat{y}_t \\\\\n\\mat{y}_{t-1} \\\\\n\\end{pmatrix}}\n=\\mat{T}_t\n{\\begin{pmatrix}\n\\mat{y}_t \\\\\n\\mat{y}_{t-1} \\\\\n\\end{pmatrix}},\n\\end{align}\nwhere $\\mat{y}_t\\triangleq \\mat{x}_t - \\mat{x}^*$.\nNow, assume that the following condition holds for all eigenvalue $\\rho(\\mat{H}_t)$ of $\\mat{H}_t$ for all $t$:\n\\begin{align}\n{(1-\\sqrt{\\mu})^2\\over \\alpha} &\\leq \\rho(\\mat{H}_t ) \\leq {(1+\\sqrt{\\mu})^2\\over \\alpha}.\n\\label{equ:control_condition}\n\\end{align}\nthen the spectral radius of $\\mat{T}_t$ is controlled by momentum with\n$\t\\rho(\\mat{T}_t) = \\sqrt{\\mu}.$\n\n\\begin{proof}\nLet $\\lambda_t$ be an eigenvalue of matrix $\\mat{T}_t$, it gives \n$\\det\\left(\\mat{T}_t - \\lambda_t \\mat{I} \\right) = 0$. \nWe define $\\mat{A}_t = \\mat{I} - \\alpha \\mat{H}_t + \\mu \\mat{I} - \\lambda_t \\mat{I}$, $\\mat{B}_t = -\\mu \\mat{I}$,\n$\\mat{C}_t = \\mat{I}$ and $\\mat{D}_t = -\\lambda_t \\mat{I}$ which gives\n\\[\n\\det \\left( \\mat{T}_t - \\lambda_t \\mat{I}\\right) = \\det{\\mat{D}_t} \\det{\\left(\\mat{A}_t - \\mat{B}_t \\mat{D}_t^{-1}\n\\mat{C}_t \\right)} = 0\n\\]\nassuming generally $\\mat{D}_t$ is invertable. The equation $\\det{\\left(\\mat{A}_t - \\mat{B}_t \\mat{D}_t^{-1}\n\\mat{C}_t \\right)} = 0$ implies that\n\\begin{equation}\n\\det \\left( \\lambda_t^2\\mat{I} - \\lambda_t \\mat{M}_t + \\mu \\mat{I} \\right) = 0\n\\label{equ:control_condition_2}\n\\end{equation}\nwith $\\mat{M}_t = \\left( \\mat{I} - \\alpha \\mat{H}_t + \\mu \\mat{I} \\right)$. In other words, $\\lambda_t$ satisfied that $\\lambda_t^2 - \\lambda_t \\rho(\\mat{M}_t) + \\mu = 0$ with $\\rho(\\mat{M}_t)$ being one eigenvalue of $\\mat{M_t}$. I.e.\n\\begin{equation}\n\t\\lambda_t = \\frac{\\rho(\\mat{M}_t) \\pm \\sqrt{\\rho(\\mat{M}_t)^2 - 4\\mu}}{2}\n\\end{equation}\n\nOn the other hand, Equation~\\eqref{equ:control_condition} guarantees that $(1 - \\alpha \\rho(\\mat{H}_t) + \\mu)^2 \\leq 4\\mu$. We know both $\\mat{H}_t$ and $\\mat{I} - \\alpha \\mat{H}_t + \\mu \\mat{I}$ are symmetric. Thus for all eigenvalues $\\rho(\\mat{M}_t)$ of $\\mat{H}$, we have $\\rho(\\mat{M}_t) = (1 - \\alpha \\rho(\\mat{H}_t) + \\mu)^2 \\leq 4\\mu$ which guarantees $| \\lambda_t | \\leq \\sqrt{\\mu}$ for all $\\lambda_t$ and all $t$. As the spectral radius is equal to the absolute value of the largest eigenvalue of $\\mat{T}_t$, we have the spectral radius of $\\mat{T}_t$ is $\\sqrt{\\mu}$ for all $t$.\n\n\n\\end{proof}\n\t\n\\end{lemma}\n\n\n\\begin{corollary}\n\tLet the gradients of a function $f$ be described by\n\\begin{equation}\n\t\\nabla f(x_t) = h_t (x_t - x^*),\n\\end{equation}\nfor $h_t \\in \\mathbb{R}$.\nThe the momentum update can be expressed as a linear operator:\n\\begin{align}\n{\\begin{pmatrix}\ny_{t+1}\\\\\ny_t \\\\\n\\end{pmatrix}}\n=\n{\\begin{pmatrix}\n1-\\alpha h_t + \\mu & - \\mu\\\\\n1 & 0 \\\\\n\\end{pmatrix}}\n{\\begin{pmatrix}\ny_t \\\\\ny_{t-1} \\\\\n\\end{pmatrix}}\n=\\mat{T}_t\n{\\begin{pmatrix}\ny_t \\\\\ny_{t-1} \\\\\n\\end{pmatrix}},\n\\end{align}\nwhere $y_t\\triangleq x_t - x^*$.\nNow, assume that the following condition holds for all $t$:\n\\begin{align}\n{(1-\\sqrt{\\mu})^2\\over \\alpha} &\\leq h_t \\leq {(1+\\sqrt{\\mu})^2\\over \\alpha}.\n\\label{equ:control_condition_scalar}\n\\end{align}\nthen the spectral radius of $\\mat{T}_t$ is controlled by momentum with\n$\t\\rho(\\mat{T}_t) = \\sqrt{\\mu}.$\n\\end{corollary}\n\n\\begin{lemma}\nLet $\\rho(\\mat{S})$ be the spectral radius of matrix \n\\begin{equation}\n\t%\\rho_V(\\alpha, \\mu) = \\rho \\left(\n\\mat{S} = {\\begin{pmatrix}\n(\\mat{I}-\\alpha \\mat{H} + \\mu \\mat{I})^T(\\mat{I}-\\alpha \\mat{H} + \\mu \\mat{I}) &  \\mu^2 \\mat{I} & -2\\mu(\\mat{I}-\\alpha \\mat{H} + \\mu \\mat{I})\\\\\n\\mat{I} & \\mat{0} & \\mat{0} \\\\\n\\mat{I}-\\alpha \\mat{H} + \\mu \\mat{I} & \\mat{0} & - \\mu \\mat{I} \n\\end{pmatrix}}\n\t%\\right)\n\\end{equation}\n$\\rho(\\mat{S})=\\mu$ if the following condition holds for all eigenvalues $\\rho(\\mat{H})$ of $\\mat{H}\\in \\mathbb{R}^{n \\times n}$\n\\begin{equation}\n{(1-\\sqrt{\\mu})^2\\over \\alpha} \\leq \\rho(\\mat{H}) \\leq {(1+\\sqrt{\\mu})^2\\over \\alpha}\n\\label{equ:control_condition_var}\n\\end{equation}\n\n\\begin{proof}\n\tLet $\\lambda$ be an eigenvalue of matrix $\\mat{S}$, it gives \n$\\det\\left(\\mat{S} - \\lambda \\mat{I} \\right) = 0$ which can be alternatively expressed as\n\\begin{equation}\t\n\\det \\left( \\mat{S} - \\lambda \\mat{I}\\right) = \\det{\\mat{D}} \\det{\\left(\\mat{A} - \\mat{B} \\mat{D}^{-1}\n\\mat{C} \\right)} = 0\n\\label{equ:control_condition_var_1}\n\\end{equation}\nassuming $\\mat{D}$ is invertible, i.e. $\\lambda + \\mu \\neq 0$, where \\begin{equation*}\n\t\t\\mat{A} = \\left( { \\begin{array}{c c}\n \t\t\t\\mat{M}^T\\mat{M} - \\lambda \\mat{I} &  \\mu^2 \\mat{I} \\\\\n \t\t\t\\mat{I} & - \\lambda \\mat{I}\n \t\t\\end{array} } \\right), \n \t\t\\mat{B} = \\left( { \\begin{array}{c}\n \t\t\t-2\\mu \\mat{M} \\\\\n \t\t\t\\mat{0}\n \t\t\\end{array}}\\right),\n \t\t\\mat{C} = \\left( {\\begin{array}{c}\n \t\t\t\\mat{M} \\\\\n \t\t\t\\mat{0}\n \t\t\\end{array}} \\right)^T,\n \t\t\\mat{D} = -\\mu \\mat{I} - \\lambda \\mat{I}\n\t\\end{equation*}\n\twith $\\mat{M}=\\mat{I}-\\alpha \\mat{H} + \\mu \\mat{I}$. It can be transformed using straight-forward algebra as\n\t\\begin{equation}\n\t\t\\det \\left( \\begin{array}{c c}\n \t\t\t(\\lambda - \\mu) \\mat{M}^T\\mat{M} - (\\lambda + \\mu) \\lambda \\mat{I} & (\\lambda + \\mu)\\mu^2 \\mat{I} \\\\\n \t\t\t(\\lambda + \\mu) \\mat{I} & -(\\lambda + \\mu)\\lambda \\mat{I}\n \t\t\\end{array} \\right)\n\t\t\\label{equ:control_condition_var_2}\t\n\t\\end{equation}\n\tUsing similar simplification technique as in Equation~\\eqref{equ:control_condition_var_1}, we can further simplify into\n\t\\begin{equation}\n\t\t(\\lambda - \\mu)\\det \\left( (\\lambda + \\mu)^2 \\mat{I} - \\lambda \\mat{M}^T\\mat{M} \\right) = 0\n\t\\end{equation}\n\tif $\\lambda \\neq \\mu$, as $(\\lambda + \\mu)^2 \\mat{I} - \\lambda \\mat{M}^T\\mat{M}$ is diagonalizable, we have $(\\lambda + \\mu)^2 - \\lambda \\rho(\\mat{M})^2 = 0$ with $\\rho(\\mat{M})$ being an eigenvalue of $\\mat{M}$. The analytic solution to the equation can be explicitly expressed as\n\t\\begin{equation}\n\t\t\\lambda = \\frac{\\rho(\\mat{M})^2 - 2\\mu \\pm \\sqrt{(\\rho(\\mat{M})^2 - 2\\mu)^2 - 4\\mu^2}}{2}\n\t\t\\label{equ:control_condition_var_3}\t\n\t\\end{equation}.\n\t\n\tWhen the condition in Equation~\\eqref{equ:control_condition_var} holds, we have $(1 - \\alpha \\rho(\\mat{H}_t) + \\mu)^2 \\leq 4\\mu$. One can verify that \n\t\n\t\\begin{equation}\n\t\t\\begin{aligned}\n\t\t\t(\\rho(\\mat{M})^2 - 2\\mu)^2 - 4\\mu^2 & = && (\\rho(\\mat{M})^2 - 4\\mu)\\rho(\\mat{M})^2 \\\\\n\t\t\t& = &&\\left( (1 - \\alpha \\rho(\\mat{H} ) + \\mu)^2 - 4\\mu\\right)\\rho(\\mat{M})^2 \\\\\n\t\t\t& \\leq && 0\n\t\t\\end{aligned}\n\t\\end{equation}\n\tThus the roots in~\\eqref{equ:control_condition_var_3} are conjugate and we have $| \\lambda | = \\mu$. In conclusion, the condition in Equation~\\eqref{equ:control_condition_var} can guarantee all the eigenvalues of $\\mat{S}$ has magnitude $\\mu$. Thus the spectral radius of $\\mat{S}$ is controlled by $\\mu$\n\\end{proof}\n\n\\end{lemma}\n\n\\begin{corollary}\n\t\nLet $\\rho(\\mat{S})$ be the spectral radius of matrix \n\\begin{equation}\n\t%\\rho_V(\\alpha, \\mu) = \\rho \\left(\n\\mat{S} = {\\begin{pmatrix}\n(1-\\alpha h + \\mu)^2 &  \\mu^2 & -2\\mu(1-\\alpha h + \\mu)\\\\\n1 & 0 & 0 \\\\\n1-\\alpha h + \\mu & 0 & - \\mu\n\\end{pmatrix}}\n\t%\\right)\n\\end{equation}\nwhere $h\\in \\mathbb{R}$.\n$\\rho(\\mat{S})=\\mu$ if the following condition holds for\n\\begin{equation}\n{(1-\\sqrt{\\mu})^2\\over \\alpha} \\leq h \\leq {(1+\\sqrt{\\mu})^2\\over \\alpha}\n\\label{equ:control_condition_var}\n\\end{equation}\n\n\\end{corollary}\n\n\\begin{theorem}\nrefer to the main content to theorem 2. \\textbf{We need to assume quadratic in this theorem}\n\\begin{proof}\n\tFrom the recurrence of momentum SGD, we have $x_{t+1} = x_t - \\alpha \\nabla f_{S_t} (x_t) + \\mu (x_t - x_{t-1})$. And the expected squared distance to the optimal point can be decomposed as $\\E \\| x_t - x^* \\|^2 = \\E \\| x_t - \\overline{x}_t \\|^2 + \\| \\overline{x}_t- x^* \\|^2$, where $\\overline{x}_t$ is the expectation of $x_t$.\n\tWithout loss of generality, we assume the optimum $x^*=0$ and investigate the bias term $\\| \\overline{x}_t- x^* \\|^2$ and variance term $\\E \\| x_t - \\overline{x}_t \\|^2$ respectively.\n\t\n\tFor the bias term, we have $\\| \\overline{x}_{t + 1} \\|^2 = \\| \\overline{x}_t - \\alpha \\nabla f( \\overline{x}_t) + \\mu ( \\overline{x}_t -  \\overline{x}_{t - 1})\\|^2$\n\t\\begin{equation}\n\t\t\\left(\\begin{array}{c}\n\t\t \\overline{x}_{t+1} \\\\\n\t\t \\overline{x}_{t}\t\n\t\t\\end{array}\\right) =\n\t\t\\left(\\begin{array}{c c}\n\t\t\t1 - \\alpha h_t + \\mu & - \\mu \\\\\n\t\t\t1 & 0\n\t\t\\end{array}\\right)\n\t\t\\left(\\begin{array}{c}\n\t\t \\overline{x}_{t} \\\\\n\t\t \\overline{x}_{t-1}\t\n\t\t\\end{array}\\right)\n\t\\end{equation}\n\t\n\tFor the variance term recurrence, we have $\\nabla f(x_t) = h x_t$ \n\t\\begin{equation}\n\t\t\\begin{aligned}\n\t\t\t\\E \\| x_{t + 1} - \\overline{x}_{t + 1} \\|^2 = \\E \\| x_{t} - \\alpha \\nabla f_{S_t}(x_t) + \\mu (x_{t} - x_{t - 1})\n\t\t\t\t- \\overline{x_t} + \\alpha \\nabla f(\\overline{x}_t) - \\mu (\n\t\t\t\t\\overline{x}_t - \\overline{x}_{t - 1}) \\|^2 \n\t\t\\end{aligned}\n\t\\end{equation} \n\\end{proof}\n\n\\end{theorem}\n\n\n\n\n\n\n\n", "meta": {"hexsha": "cfeea6d588569414bd7df5dbb04685ccd1c06f72", "size": 11901, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "misc.tex", "max_stars_repo_name": "mitliagkas/dshs", "max_stars_repo_head_hexsha": "6d5262af72288dd06544c2d5831d0c198db251bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "misc.tex", "max_issues_repo_name": "mitliagkas/dshs", "max_issues_repo_head_hexsha": "6d5262af72288dd06544c2d5831d0c198db251bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "misc.tex", "max_forks_repo_name": "mitliagkas/dshs", "max_forks_repo_head_hexsha": "6d5262af72288dd06544c2d5831d0c198db251bb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.798245614, "max_line_length": 592, "alphanum_fraction": 0.6186875053, "num_tokens": 4791, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7125761588848711}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Likelihood}\\label{sec:likelihood}\n\nLet $f(x;\\theta)$ denote the PMF/PDF of a random variable $X$. We have so far considered $f(x;\\theta)$ to be a function of $x$ and $\\theta$ as a fixed parameter. We now change the emphasis and regard $x$ as a fixed observation and $\\theta$ as a variable parameter. To underline this new emphasis we refer to $f(x;\\theta)$ as the \\emph{likelihood function} of $\\theta$.\n\n\\bigskip\nLet $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random sample from the distribution of $X$, let $\\mathbf{x}=(x_1,x_2,\\ldots,x_n)$ be a realisation of the sample and let $\\Theta$ denote the parameter space.\n\n\\begin{definition}\nGiven $\\mathbf{X}=\\mathbf{x}$, the \\emph{likelihood function} $L:\\Theta\\to [0,\\infty)$ is\n\\[\nL(\\theta;\\mathbf{x}) = \\displaystyle\\prod_{i=1}^n f(x_i;\\theta).\n\\]\n\\end{definition}\n\nNote that the right-hand side is just the joint PMF/PDF of the random sample. Until now we have interpreted this as the probability that the observed sample is $\\mathbf{x}$ with $\\theta$ a fixed parameter. For statistical inference, we instead consider the likelihood $L(\\theta;\\mathbf{x})$ that $\\theta$ is the true parameter value given the fixed observations $\\mathbf{x}$: such observations are often referred to as \\emph{data}. \n\n\\bigskip\nThe value of $\\theta$ which maximises the likelihood function provides an estimator of the true parameter value, subject to the following regularity conditions.\n\n\\begin{condition}\\label{cond:regularity1}\n%Let $\\theta_0$ be the true value of the unknown parameter $\\theta$. Our statistical model $\\mathcal{M}=\\{f(x;\\theta):\\theta\\in\\Theta\\}$ is assumed to satisfy the following conditions.\nOur statistical model $\\mathcal{M}=\\{f(x;\\theta):\\theta\\in\\Theta\\}$ satisfies the following conditions.\n\\ben\n%\\it[C.1] The PDFs are distinct, i.e. $\\theta\\neq\\theta' \\implies f(x;\\theta)\\neq f(x;\\theta')$.\n%\\it[C.2] The PDFs have common support for all $\\theta\\in\\Theta$.\n%\\it[C.3] The true value of $\\theta$ is an interior point of the parameter space $\\Theta$.\n\\it PDFs are distinct, i.e. $\\theta\\neq\\theta' \\implies f(x;\\theta)\\neq f(x;\\theta')$.\n\\it PDFs have a common support for all $\\theta\\in\\Theta$.\n\\it The true value of $\\theta$ is an interior point of the parameter space $\\Theta$.\n\\een\n\\end{condition}\nWe shall not consider these conditions in detail.\n\n%We also need Jensen's inequality and the notion of convex functions.\n% defn: convex function\n%\\begin{definition}\n%A function $g:\\R\\to\\R$ is said to be \\emph{strictly convex} if \n%\\[\n%g\\big[\\lambda x_1 + (1-\\lambda)x_2\\big] < \\lambda g(x_i) + (1-\\lambda)g(x_2)\n%\\quad\\text{for all $x_1\\neq x_2$ and all $\\lambda\\in (0,1)$.}\n%\\]\n\n%\\ben\n%\\it \\emph{convex} if \n%\\[\n%g\\big[\\lambda x_1 + (1-\\lambda)x_2\\big] \\leq \\lambda g(x_i) + (1-\\lambda)g(x_2) \\quad\\text{for all $x_1,x_2\\in\\R$ and $\\lambda\\in [0,1]$.}\n%\\]\n%\\it \\emph{strictly convex} if \n%\\[\n%g\\big[\\lambda x_1 + (1-\\lambda)x_2\\big] < \\lambda g(x_i) + (1-\\lambda)g(x_2) \\quad\\text{for all $x_1\\neq x_2$ and $\\lambda\\in (0,1)$.}\n%\\]\n%\\ben\n%\\it \\emph{convex} if $g\\big[\\lambda x_1 + (1-\\lambda)x_2\\big] \\leq \\lambda g(x_i) + (1-\\lambda)g(x_2)$ for all $x_1,x_2\\in\\R$ and $\\lambda\\in [0,1]$.\n%\\it \\emph{strictly convex} if $g\\big[\\lambda x_1 + (1-\\lambda)x_2\\big] < \\lambda g(x_i) + (1-\\lambda)g(x_2)$ for all $x_1\\neq x_2$ and $\\lambda\\in (0,1)$.\n%\\een\n%\\end{definition}\n%\n%% lemma: Jensen\n%\\begin{lemma}[Jensen's inequality]\n%If $g:\\R\\to\\R$ is a convex function then $g\\big[\\expe(X)\\big] \\leq \\expe\\big[g(X)\\big]$.\n%\\end{lemma}\n%\n%The following theorem shows that $L(\\theta)$ is maximised at the true value of $\\theta$ as $n\\to\\infty$.\n%\n%% thm: mle\n%\\begin{theorem}\\label{thm:mle}\n%Let $\\theta_0$ be the true value of the unknown parameter $\\theta$. Under conditions C.1 and C.2,\n%\\[\n%\\lim_{n\\to\\infty} \\prob_{\\theta_0}\\big[L(\\theta_0,\\mathbf{X})>L(\\theta,\\mathbf{X})\\big] = 1 \n%\\quad\\text{for all $\\theta\\neq\\theta_0$.}\n%\\]\n%where $\\prob_{\\theta_0}$ is the probability measure on $\\R^n$ induced by the random sample.\n%\\end{theorem}\n%\\begin{proof}\n%Taking logs, the inequality $L(\\theta_0,\\mathbf{X})-L(\\theta,\\mathbf{X})$ is equivalent to\n%\\[\n%\\frac{1}{n}\\sum_{i=1}^n\\log\\left(\\frac{f(X_i;\\theta)}{f(X_i;\\theta_0)}\\right) < 0. \n%\\]\n%By the law of large numbers applied to the random variable $\\log\\big[f(X;\\theta)/f(X,\\theta_0)\\big]$, \n%\\[\n%\\frac{1}{n}\\sum_{i=1}^n\\log\\left(\\frac{f(X_i;\\theta)}{f(X_i;\\theta_0)}\\right)\n%\\to \\expe_{\\theta_0}\\log\\left(\\frac{f(X_i;\\theta)}{f(X_i;\\theta_0)}\\right)\n%\\quad\\text{in probability as $n\\to\\infty$.}\n%\\]\n%Furthermore, because $-\\log(x)$ is strictly convex, by Jensen's inequality we have\n%\\[\n%\\expe_{\\theta_0}\\log\\left(\\frac{f(X_i;\\theta)}{f(X_i;\\theta_0)}\\right)\n%\\leq\\log\\expe_{\\theta_0}\\left(\\frac{f(X_i;\\theta)}{f(X_i;\\theta_0)}\\right)\n%\\]\n%and because the PDFs $f(x;\\theta)$ have a common support,\n%\\[\n%\\expe_{\\theta_0}\\left(\\frac{f(X_i;\\theta)}{f(X_i;\\theta_0)}\\right)\n%\t= \\int \\frac{f(x;\\theta)}{f(x;\\theta_0)}f(x;\\theta_0)\\,dx\n%\t= \\int f(x;\\theta)\\,dx\n%\t= 1.\n%\\]\n%Finally, because $\\log 1 = 0$ the result follows.\n%\\end{proof}\n%\n%Theorem~\\ref{thm:mle} shows that a good estimator of $\\theta_0$ is one which maximises the likelihood function.\n%\n%%-----------------------------\n%\\subsection{The score function}\n%The first derivative of the log-likelihood function is called the \\emph{score function}.\n%\\begin{definition}\n%\\end{definition}\n\n\n", "meta": {"hexsha": "12705877a35144384e0e2a30045a7361b2bd2a55", "size": 5433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/08A_likelihood.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/08A_likelihood.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/08A_likelihood.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 48.5089285714, "max_line_length": 432, "alphanum_fraction": 0.6751334438, "num_tokens": 1870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8791467675095292, "lm_q1q2_score": 0.7125299126921649}}
{"text": "\\documentclass{article}\n\n\\usepackage[letterpaper, margin=1.3cm]{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage{siunitx}\n\\usepackage{mathtools}\n\\usepackage{multicol}\n\n\\title{ECE 240 Assignment 9}\n\\author{Michael Kwok}\n\\begin{document}\n\n\\maketitle\n\\begin{multicols}{2}\n\\section*{1}\n\\subsection*{i}\n$$F(s) = \\frac{s+2}{s(s+1)^2}$$\n\\begin{align*}\n    \\frac{s+2}{s(s+1)^2} &= \\frac{A}{s}+\\frac{B}{s+1} + \\frac{C}{(s+1)^2}\\\\\n    s+2 &= A(s+1)^2 + Bs(s+1) + Cs\\\\\n    \\text{Let } s &= 0:\\\\\n    A &= 2\\\\\n    \\text{Let } s &= -1:\\\\\n    1 &= A(0) -B(0) -C\\\\\n    C &= -1\\\\\n    s+2 &= 2(s+1)^2 + B(s^2 + s) - s\\\\\n    2s + 2 &= 2(s+1)^2 + B(s^2 + s)\\\\\n    2 &= 2(s+1) + Bs\\\\\n    -2s &= Bs\\\\\n    B &= -2\\\\\n    F(s) &= \\frac{2}{s} - \\frac{2}{s+1} - \\frac{1}{(s+1)^2}\n\\end{align*}\n\\begin{align*}\n\\mathcal{L}^{-1}\\{F(s)\\} &= f(t)\\\\\n&= 2\\delta(t) - 2 e^{-t}u(t)-te^{-t}u(t)\n\\end{align*}\n\\subsection*{ii}\nlet $x = e^{-s}$\n\\begin{align*}\n    F(s) = \\frac{x+x^2+1}{s^2+3s+2} &= \\frac{x+x^2+1}{(s+1)(s+2)}\\\\\n    \\frac{x+x^2+1}{(s+1)(s+2)} &= \\frac{A}{s+1} + \\frac{B}{s+2}\\\\\n    x^2+x+1 &= A(s+2) + B (s+1)\\\\\n    \\text{let } s &= -1\\\\\n    A(-1+2) &= e^2 + e + 1\\\\\n    \\text{let } s &= -2\\\\\n    B(-2+1) &= e^4 + e^2 + 1\\\\\n    F(s) &= \\frac{e^2+e+1}{s+1} - \\frac{e^4+e^2+1}{s+2}\\\\\n    f(t) &= e^{-t}u(t)(e^2+e+e)\\\\\n     &- e^{-2}u(t)(e^4+e^2+1)\n\\end{align*}\n\\section*{2}\n\\begin{align*}\n&s^2 Y(s) - s y(0^-) - y'(0^-) + 6 sY(s) - 6y(0^-)+25Y(s)\\\\\n&= sF(s) - f(0^-) + 2F(s)\\\\\n\\end{align*}\n\\[\n(s^2+6s+25)Y(s) = \\overbrace{s+7}^{\\text{Zero input}} + \\overbrace{sF(s) - f(0^-) + sF(s)}^{\\text{Zero state}}\n\\]\n\\begin{align*}\n    F(s) &= \\frac{25}{s}\\\\\n    f(0) &= 0\n\\end{align*}\n\\begin{align*}\n    Y(s) &= \\frac{s+7}{s^2+6s+25} + \\frac{25+ \\frac{50}{s}}{s^2+6s+25}\\\\\n    &= \\frac{(s+3)+4}{(s+3)^2+4^2} + \\frac{2}{s} + \\frac{13-2s}{s^2+6s+25}\\\\\n    &= \\frac{s+3}{(s+3)^2+4^2} + \\frac{4}{(s+3)^2+4^2} + \\frac{2}{s}\\\\\n    &-2 \\frac{s+3}{(s+3)^2+4^2} + \\frac{19}{4}\\frac{4}{(s+3)^2+4^2}\\\\\n    y(t) &= \\overbrace{\\left[\\left( cos(4t) + sin(4t) \\right) e^{-3t} + 2\\right]u(t)}^{\\text{Zero Input}}\\\\\n    &\\overbrace{\\left[- 2e^{-3t}cos(4t) + \\frac{19}{4}e^{-3t}sin(4t)\\right]u(t)}^{\\text{Zero State}}\n\\end{align*}\n\\section*{3}\n\\begin{align*}\n&s^3 Y(s) + 6s^2 Y(s) -11 sY(s) + 6 Y(s) =\\\\\n&3s^2 F(s) + 7sF(s) +5F(s)\n\\end{align*}\n\\begin{align*}\n    (s^3 + 6s^2 -11 s + 6) Y(s) &= (3s^2 + 7s +5) F(s)\\\\\n    \\frac{Y(s)}{F(s)} &= \\boxed{\\frac{3s^2 + 7s +5}{s^3 + 6s^2 -11 s + 6}}\n\\end{align*}\n\\section*{4}\n\\subsection*{a}\n\\begin{align*}\n    F(s) &= \\frac{1}{s+3}\\\\\n    Y(s) &= \\frac{s+5}{(s+2)(s+3)^2}\\\\\n    &= \\frac{A}{s+2} + \\frac{B}{s+3} + \\frac{C}{(s+3)^2}\n\\end{align*}\n    \n\\begin{align*}\n    s+5 = A(s+3)^2 &+ B(s+2)(s+3) + C(s+2)\\\\\n    \\text{let } s &= -2,\\\\\n    A &= 3\\\\\n    \\text{let } s &= -3,\\\\\n    2 &= C(-3+2)\\\\\n    C &= -2\\\\\n    s+5 &= 3(s+3)^2 + B(s+2)(s+3) + -2(s+2)\\\\\n    -3s^2-15s-18 &= B(s^2+5s+6)\\\\\n    B &+ -3\\\\\n\\end{align*}\n\n\\begin{align*}\n    Y(s) &= \\frac{3}{s+2} - \\frac{3}{s+3} - \\frac{2}{(s+2)^2}\\\\\n    y(t) &= 3 e^{-2t} u(t) - 3 e^{-3t} u(t) - 2t e^{-3t}u(t)\\\\\n    &= \\left[ 3e^{-2t} e^{-3t} (3+2t) \\right] u(t)\n\\end{align*}\n\\subsection*{b}\n\\begin{align*}\n    H(s) &= \\frac{s+5}{s^2+5s+6}\\\\\n    (s^2 +5s +6) Y(s) &= (s+5) F(s)\\\\\n    y''(t) + 5 y'(t) + 6y(t) &= f'(t) + 5 f(t)\n\\end{align*}\n\\section*{5}\n\\subsection*{a}\n\\begin{align*}\n    H_1(s) &= \\frac{s+1}{s^2+8s+12}\\\\\n    &= \\frac{s+1}{(s+2)(s+6)}\\\\\n\\end{align*}\nPoles at $s_1 = -2, s_2 = -6$\n\nSystem is BIBO Stable.\n\\subsection*{b}\n$$\nH_2(s) = \\frac{s+5}{s(s+1)(s+2)}\n$$\nPoles at $s_1 = 0, s_2 = -1, s_3 = -2$\n\nSystem is BIBO Unstable.\n\\subsection*{c}\nPoles at $s_1 = 0, s_2 = \\sqrt{2}, s_3 = -\\sqrt{2}$\n\nSystem is BIBO Unstable.\n\\subsection*{d}\nPoles at $s_1 = -1, s_2 = 5, s_3 = 1$\n\nSystem is BIBO Unstable.\n\\section*{6}\n\\subsection*{a}\n$$\\mathcal{L}\\{H(s)\\} = e^{-2t}u(t)$$\n\\subsection*{b}\n$s = \\sigma + j\\omega$\n\nFourier transform is identical to Laplace at $\\sigma = 0$, basically a special case of the Laplace transform.\n\n\\begin{align*}\n    H(j\\omega) &= \\frac{1}{j\\omega + 2}\\\\\n    \\mathcal{F}\\{H(j\\omega)\\} &= e^{-2t} u(t)\\\\\n\\end{align*}\n\\end{multicols}\n\\end{document}\n", "meta": {"hexsha": "627944115897dd808ea05263544394368c4fcc25", "size": 4117, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/ECE240/ECE240As9.tex", "max_stars_repo_name": "n30phyte/SchoolDocuments", "max_stars_repo_head_hexsha": "79652ec7e3345d67e67f0cffe3bea468708622bd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Assignments/ECE240/ECE240As9.tex", "max_issues_repo_name": "n30phyte/SchoolDocuments", "max_issues_repo_head_hexsha": "79652ec7e3345d67e67f0cffe3bea468708622bd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Assignments/ECE240/ECE240As9.tex", "max_forks_repo_name": "n30phyte/SchoolDocuments", "max_forks_repo_head_hexsha": "79652ec7e3345d67e67f0cffe3bea468708622bd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6308724832, "max_line_length": 110, "alphanum_fraction": 0.4724313821, "num_tokens": 2180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.7125200579563861}}
{"text": "\\section*{Kernels = Non-Parametric}\n\\subsection*{Reformulating the perceptron}\nAnsatz: $w=\\sum_{j=1}^n \\alpha_j y_j x_j$\\\\\n$\\min \\limits_{w\\in\\mathbb{R}^d} \\sum_{i=1}^n \\max [0, -y_i w^T x_i]$\\\\\n%$= \\min \\limits_{\\alpha_{1:n}} \\sum_{i=1}^n \\max [0,-y_i  ( \\sum_{j=1}^n \\alpha_j y_j x_j  )^T x_i ]$\\\\\n$= \\min \\limits_{\\alpha_{1:n}} \\sum_{i=1}^n \\max  [0,- \\sum_{j=1}^n \\alpha_j y_i y_j x_i^T x_j ]$\n\n%\\subsection*{Polynomial kernel}\n%$k(x,y) = (x^Ty)^m$  all monomials of deg. m \\\\\n%$k(x,y) = (1+x^Ty)^m$ all monomials up to deg. m\n\n\\subsection*{Kernelized Perceptron}\n1. Initialize $\\alpha_1 = ... = \\alpha_n = 0$\\\\\n2. For $t = 1, 2, ...$ do \\\\\nPick data $(x_i,y_i) \\in_{u.a.r} D$\\\\\nPredict $\\hat{y} = sign(\\sum_{j=1}^n \\alpha_j y_j k(x_j,x_i))$\\\\\nIf $\\hat{y} \\not = y_i$ set $\\alpha_i = \\alpha_i + \\eta_t$\\\\\nPredict new point x: $\\hat{y} = sign(\\sum_{j=1}^n \\alpha_j y_j k(x_j,x))$\n\n\\subsection*{Properties of a Kernel}\nk must be a function: $f: X \\times X \\rightarrow R$\\\\\nk must be symmetric: $k(x,y) = k(y,x)$\\\\\nMatrix K must be positive semi-definite (psd).\n\n\\subsection*{Kernel Matrix K}\n$K = \n\\begin{bmatrix}\n\tk(x_1,x_1) & \\dots & k(x_1,x_n) \\\\\n\t\\vdots & \\ddots & \\vdots \\\\\n\tk(x_n, x_1) & \\dots & k(x_n,x_n)\n\\end{bmatrix}$\\\\\npositive semi-definite matrices $\\Leftrightarrow$ kernels\n%$\\left ( XX^T \\right )$ for inner product as kernel.\n\n\\subsection*{Definition of PSD}\n$M \\in \\mathbb{R}^{n\\times n}$ is psd $\\Leftrightarrow$\\\\\n$\\forall x \\in \\mathbb{R}^n: x^TMx \\geq 0 \\Leftrightarrow$\\\\\nall eigenvalues of $M$ are positive: $\\lambda_i\\geq 0$\n\n\\subsection*{Nearest Neighbor k-NN}\n$y=sign(\\sum_{i=1}^n y_i [x_i \\text{ among k nn of } x])$\n\n\\subsection*{Examples of kernels on $\\mathbb{R}^d$}\nLinear kernel: $k(x,y)=x^T y$\\\\\nPolynomial kernel: $k(x,y)=(x^T y + 1)^d$\\\\\nGaussian kernel: $k(x,y) = exp(-||x-y||_2^2/h^2)$\\\\\nLaplacian kernel: $k(x,y) = exp(-||x-y||_1/h)$\\\\\nh = bandwidth $\\approx 1\\sigma$ \n\n\n\\subsection*{Kernel Properties / Rules}\n$k_1(x,y) + k_2(x,y)$; $k_1(x,y) \\cdot k_2(x,y)$; $c \\cdot k_1(x,y)$,$c>0$;\\\\\n$f(k_1(x,y))$, where $f$ is a polyinomial with pos. coeffs. or the exponential function\n\n%without Parametric vs. Nonparametric\n\\iffalse\n\\subsection*{Parametric vs. Nonparametric}\n\\emph{Parametric}: have finite set of parameters\\\\\nE.g. linear regression, linear perceptron,...\\\\\n%$f(x) = w^Tx, w\\in \\mathbb{R}^d$ (d is independent of \\# data)\\\\\n\\emph{Nonparametric}: grow in complexity with the size of the data\\\\\nE.g. kernelized Perceptron, k-NN,...\n%$f(x) = \\sum_{i=1}^n \\alpha_i y_i k(x_i,x_n)$ (depends on \\# data)\\\\\n\\fi\n\n\\subsection*{Perceptron and SVM}\nPerceptron: $\\underset{\\alpha}{min}\\sum_{i=1}^n max\\{0,-y_i \\alpha^T k_i\\}$\\\\\nSVM: $k_i=[y_1 k(x_i,x_1), ..., y_n k(x_i,x_n)]$:\\\\\n$\\underset{\\alpha}{min}\\sum_{i=1}^n max\\{0,1-y_i \\alpha^T k_i\\} +\\lambda\\alpha^T D_y K D_y \\alpha$\\\\\nPrediction: $y = sign(\\sum_{j=1}^n \\alpha_j y_j k(x_j,x))$\n\n\\subsection*{Kernelized linear regression}\nAnsatz: $w^*=\\sum_i \\alpha_i x$\\\\\nParametric: $w^* = \\underset{w}{\\operatorname{argmin}} \\sum_i (w^Tx_i-y_i)^2 + \\lambda ||w||_2^2$\\\\\n%$= \\underset{\\alpha_{1:n}}{\\operatorname{argmin}} \\sum \\limits_{i=1}^n (\\sum \\limits_{j=1}^n \\alpha_j x_j^T x_i - y_i)^2 + \\lambda \\sum \\limits_i \\sum \\limits_j \\alpha_i \\alpha_j (x_i^T x_j)$\\\\\n%$= \\underset{\\alpha_{1:n}}{\\operatorname{argmin}} \\sum \\limits_{i=1}^n (\\alpha^T K_i - y_i)^2 + \\lambda \\alpha^T K \\alpha$\\\\\n$= \\underset{\\alpha}{\\operatorname{argmin}} ||\\alpha^T K -y||_2^2 + \\lambda \\alpha^T K \\alpha$\\\\\nClosed form: $\\alpha^* = (K+\\lambda I)^{-1} y$\\\\\nPrediction: $y = w^{*T} x = \\sum \\limits_{i=1}^n \\alpha_i^* k(x_i,x)$", "meta": {"hexsha": "fcc5da76a3a921ebf2b3fd4b08b3aa34f3d02978", "size": 3591, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/Kernels.tex", "max_stars_repo_name": "meck93/intro_ml_ethz", "max_stars_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-04-24T14:58:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-19T14:02:08.000Z", "max_issues_repo_path": "source/Kernels.tex", "max_issues_repo_name": "meck93/intro_ml_ethz", "max_issues_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/Kernels.tex", "max_forks_repo_name": "meck93/intro_ml_ethz", "max_forks_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.4556962025, "max_line_length": 194, "alphanum_fraction": 0.6307435255, "num_tokens": 1509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7124417691063913}}
{"text": "\\section{Capacity Provisioning}\n\\label{sec:Capacity-Provisioning}\n\n\\begin{theorem}[Square-Root Staffing Rule]\n\\label{thm:Square-Root-Staffing-Rule}\t\n\tFor any $M/M/m$ with high resource requirement $R$, the minimum number of servers $m_{\\alpha}^{*}$ to ensure $P_{Q} < \\alpha$ is\n\t\n\t\\begin{equation}\n\t\\label{eqn:Square-Root-Staffing-Rule}\n\tm_{\\alpha}^{*} \\approx R + c \\sqrt{R}\n\t\\end{equation}\n\t\n\twith $c$ solution of the equation\n\t\n\t\\begin{equation}\n\t\\label{eqn:Square-Root-Staffing-Rule-c}\n\t\t\\frac{c \\Phi(c)}{\\phi(c)} = \\frac{1 - \\alpha}{\\alpha}\n\t\\end{equation}\t\n\t\n\twhere\n\t$\\Phi(\\cdot)$ is the c.d.f. of the Standard Normal, and\n\t$\\phi(\\cdot)$ is its p.d.f.\n\t\n\t\\begin{proof}\n\t\tFor a formal demonstration, see \\cite{harchol2013performance}.\n\t\\end{proof}\n\\end{theorem}", "meta": {"hexsha": "7b4bc036bab5b59af3b58aae6188b5377452fd46", "size": 767, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/capacity-provisioning.tex", "max_stars_repo_name": "gmarciani/research", "max_stars_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-07-27T13:31:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-20T12:54:12.000Z", "max_issues_repo_path": "performance-modeling/sec/capacity-provisioning.tex", "max_issues_repo_name": "gmarciani/research", "max_issues_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "performance-modeling/sec/capacity-provisioning.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 28.4074074074, "max_line_length": 129, "alphanum_fraction": 0.6857887875, "num_tokens": 272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973295, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.7124019020906702}}
{"text": "\\subsection{Function oscillation}\\label{subsec:function_oscillation}\n\n\\begin{definition}\\label{def:function_oscillation}\n  Let \\( \\mscrX \\) be a nonempty set and \\( (\\mscrY, \\rho_{\\mscrY}) \\) be a metric space. We define the \\term{oscillation} of a function on a set as\n  \\begin{balign*}\n     &\\omega: \\fun(\\mscrX, \\mscrY) \\times \\pow(\\mscrX) \\to [0, \\infty] \\\\\n     &\\omega(f, A) \\coloneqq \\sup \\Big\\{ \\rho_{\\mscrY}(f(x), f(y)) \\colon (x, y) \\in A \\Big\\}.\n  \\end{balign*}\n\n  In particular, if \\( \\mscrX \\) is itself a metric space, we define its \\term{modulus of continuity} \\( \\omega(f, \\delta) \\) as the oscillation of \\( f \\) on the ball \\( B(0, \\delta) \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:function_oscillation/properties}\n  The \\hyperref[def:function_oscillation]{modulus of continuity} has the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:function_oscillation/properties/continuity_condition} \\( f \\) is globally \\hyperref[def:uniform_continuity]{uniformly continuous} if and only if for every \\( \\varepsilon > 0 \\) there exists \\( \\delta > 0 \\) such that \\( \\omega(f, \\delta) < \\varepsilon \\).\n\n    \\thmitem{thm:def:function_oscillation/properties/monotone} \\( \\omega(f, \\delta) \\) is monotone in \\( \\delta \\).\n\n    \\thmitem{thm:def:function_oscillation/properties/cauchy_inequality}\\mcite[28]{Николов2020Лекции}For all \\( \\lambda, \\delta > 0 \\), we have the following analog of \\fullref{thm:cauchy_bunyakovsky_schwarz_inequality}\n    \\begin{equation}\\label{thm:def:function_oscillation/properties/cauchy_inequality/inequality}\n      \\omega(f, \\lambda \\delta) \\leq \\omega(f, \\lambda^2) + \\omega(f, \\delta^2).\n    \\end{equation}\n\n    \\thmitem{thm:def:function_oscillation/properties/single_inequality}\\mcite[28]{Николов2020Лекции}For all \\( \\lambda, \\delta > 0 \\),\n    \\begin{equation}\\label{thm:def:function_oscillation/properties/single_inequality/inequality}\n      \\omega(f, \\lambda \\delta) \\leq (\\lambda + 1) \\omega(f, \\delta).\n    \\end{equation}\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:function_oscillation/properties/continuity_condition} Follows directly from \\fullref{def:uniform_continuity}.\n\n  \\SubProofOf{thm:def:function_oscillation/properties/monotone} A supremum on a larger set is larger.\n\n  \\SubProofOf{thm:def:function_oscillation/properties/cauchy_inequality} If \\( \\lambda \\leq \\delta \\), clearly \\( \\lambda \\delta \\leq \\delta^2 \\). Otherwise, \\( \\lambda \\delta < \\lambda^2 \\).\n\n  Combining the two inequalities with \\fullref{thm:def:function_oscillation/properties/monotone}, we obtain \\fullref{thm:def:function_oscillation/properties/cauchy_inequality/inequality}.\n\n  \\SubProofOf{thm:def:function_oscillation/properties/single_inequality} Note that\n  \\begin{equation*}\n    \\rho_{\\mscrX}(x, y) < \\delta \\T{implies} \\rho_{\\mscrY}(f(x), f(y)) < \\omega(f, \\delta).\n  \\end{equation*}\n\n  We can multiply this by \\( \\lambda \\) to obtain\n  \\begin{equation*}\n    \\lambda \\rho_{\\mscrX}(x, y) < \\lambda \\delta \\T{implies} \\lambda \\rho_{\\mscrY}(f(x), f(y)) < \\lambda \\omega(f, \\delta).\n  \\end{equation*}\n\n  If \\( \\lambda \\geq 1 \\), then \\( \\rho_{\\mscrX}(x, y) \\leq \\lambda \\rho_{\\mscrX}(x, y) \\) and \\( \\rho_{\\mscrY}(f(x), f(y)) \\leq \\lambda \\rho_{\\mscrY}(f(x), f(y)) \\) and hence\n  \\begin{equation*}\n    \\omega(f, \\lambda \\delta) \\leq \\lambda \\omega(f, \\delta).\n  \\end{equation*}\n\n  Otherwise, \\( \\lambda < 1 \\) and clearly \\( \\lambda \\delta < \\delta \\), which by \\fullref{thm:def:function_oscillation/properties/monotone} implies\n  \\begin{equation*}\n    \\omega(f, \\lambda \\delta) \\leq \\omega(f, \\delta).\n  \\end{equation*}\n\n  Combining the two cases, we obtain\n  \\begin{equation*}\n    \\omega(f, \\lambda \\delta) \\leq \\lambda \\omega(f, \\delta) + \\omega(f, \\delta),\n  \\end{equation*}\n  which we wanted to prove.\n\\end{proof}\n", "meta": {"hexsha": "5c80d6644a1f2ef179a9ada5c1c6e6cb4cdf75e0", "size": 3809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/function_oscillation.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/function_oscillation.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/function_oscillation.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.7121212121, "max_line_length": 276, "alphanum_fraction": 0.6959831977, "num_tokens": 1301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893335913536, "lm_q2_score": 0.8688267881258485, "lm_q1q2_score": 0.7123452936475448}}
{"text": "\\subsection{Array Functions}\n\nArrays could be directly treated using array functions. Since array is a very usable form of holding numbers and strings, it's good for you to know what they could do. Here is the list. \n\n\\begin{shaded}\\begin{indentCom}\n\\item \\textbf{Array.concat(array1,array2)} Returns a new array created by\njoining two or more arrays or values. \n\\item \\textbf{Array.copy(array)} Returns a copy of array. \n\\item \\textbf{Array.fill(array, value)} Assigns the specified numeric value to\neach element of array.\n\\item \\textbf{Array.findMaxima(array, tolerance)} Returns an array holding the peak positions (sorted with descending strength). Tolerance is the minimum amplitude difference to needed to separate two peaks. There is an optional 'excludeOnEdges' argument that defaults to 'true'. Examples. Requires 1.48c.\n\\item \\textbf{Array.findMinima(array, tolerance)} Returns an array holding the minima positions. Requires 1.48c.\n\\item \\textbf{Array.fourier(array, windowType)} Calculates and returns the Fourier amplitudes of array. WindowType can be \"none\", \"Hamming\", \"Hann\", or \"flat-top\", or may be omitted (meaning \"none\"). See the TestArrayFourier macro for an example and more documentation. Requires 1.49i. \n\\item \\textbf{Array.getStatistics(array, min, max, mean, stdDev)} Returns the\nmin, max, mean, and stdDev of array, which must contain all numbers.\n\\item \\textbf{Array.print(array)} Prints the array on a single line. \n\\item \\textbf{Array.rankPositions(array)} Returns, as an array, the rank\npositions of array, which must contain all numbers or all strings. \n\\item \\textbf{Array.resample(array,len)} Returns an array which is linearly resampled to a different length. Requires 1.47j. \n\\item \\textbf{Array.reverse(array)} Reverses (inverts) the order of the\nelements in array. \n\\item \\textbf{Array.show(array)} Displays the contents of array in a window. Requires 1.48d.\n\\item \\textbf{Array.show(\"title\", array1, array2, ...)} Displays one or more arrays in a Results window (examples). If title (optional) is \"Results\", the window will be the active Results window, otherwise, it will be a dormant Results window (see also IJ.renameResults). If title ends with \"(indexes)\", a 0-based Index column is shown. If title ends with \"(row numbers)\", the row number column is shown. Requires 1.48d. \n\\item \\textbf{Array.slice(array,start,end)} Extracts a part of an array and\nreturns it. \n\\item \\textbf{Array.sort(array)} Sorts array, which must contain all numbers\nor all strings. String sorts are case-insensitive in v1.44i or later.\n\\item \\textbf{Array.trim(array, n)} Returns an array that contains the first n\nelements of array.\n\\end{indentCom}\\end{shaded}\n\nFor example, array could be sorted and reversed. Try the following codes. \n\n\\begin{lstlisting}[numbers=none]\nEMBL = newArray(\"Heidelberg\",\"Hamburg\",\"Hixton\",\"Grenoble\",\"Monterotondo\");\nArray.print(EMBL);\nArray.sort(EMBL);\nArray.print(EMBL);\nArray.reverse(EMBL);\nArray.print(EMBL);\n\\end{lstlisting} \nThe output of this code is:\n\\begin{lstlisting}[numbers=left]\nHeidelberg,Hamburg,Hixton,Grenoble,Monterotondo\nGrenoble,Hamburg,Heidelberg,Hixton,Monterotondo\nMonterotondo,Hixton,Heidelberg,Hamburg,Grenoble\n\\end{lstlisting} \nThe first line is printed in the order when the array was initialized. After\nsorting, names are in alphabetical order. Third line shows the reversed\nelements. \n\nSome functions return an array rather than taking array/s as argument. See Appendix for a list of those functions (\\ref{subsec:arrayreturn}).\n", "meta": {"hexsha": "a4da0acd5ed56ba9e706508fa57446080ae366a9", "size": 3509, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/experimentalTools/ImageJ/reference/cmci-ij_textbook2-d852848/sections/adv/macroAdv_ArrayFunctions.tex", "max_stars_repo_name": "mistltoe/mistltoe.github.io", "max_stars_repo_head_hexsha": "2e465787f2a06fd795460432297b90cf0fbf721b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assets/experimentalTools/ImageJ/reference/cmci-ij_textbook2-d852848/sections/adv/macroAdv_ArrayFunctions.tex", "max_issues_repo_name": "mistltoe/mistltoe.github.io", "max_issues_repo_head_hexsha": "2e465787f2a06fd795460432297b90cf0fbf721b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assets/experimentalTools/ImageJ/reference/cmci-ij_textbook2-d852848/sections/adv/macroAdv_ArrayFunctions.tex", "max_forks_repo_name": "mistltoe/mistltoe.github.io", "max_forks_repo_head_hexsha": "2e465787f2a06fd795460432297b90cf0fbf721b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.2075471698, "max_line_length": 421, "alphanum_fraction": 0.7757195782, "num_tokens": 911, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152498, "lm_q2_score": 0.8688267779364222, "lm_q1q2_score": 0.7123452929404668}}
{"text": "\\section{Partial Recursive Functions}\n\n\\subsection{Partial Functions, Definition by Composition \\& Primitive Recursion}\n\n\\begin{itemize}\n\t\n\t\\item Classes of functions:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item Let $ P $ be the set of partial functions, $ P = \\setcomp{f}{f \\text{ is a partial function } \\Nat^n \\to \\Nat \\text{ for some } n > 0} $\n\t\t\n\t\t\\item Let $ T $ be the set of total functions, $ T = \\setcomp{f \\in P}{f \\text{ is total}} $\n\t\t\n\t\t\\item A \\textit{class} of functions means a subset of $ P $, and a class of total functions means a subset of $ T $\n\t\t\n\t\t\\item Goal: build a class of functions which we might call `computable'\n\t\t\n\t\\end{itemize}\n\t\n\t\\item Let $ g: \\Nat^r \\to \\Nat, h_1 \\dots h_r: \\Nat^n \\to \\Nat $ be partial functions.\n\t\n\tThen the partial function $ f: \\Nat^n \\to \\Nat $ obtained from $ g, h_1, \\dots, h_r $ by composition is defined by:\n\t\\begin{equation*}\n\tf(\\vec{x}) = g(h_1(\\vec{x}), \\dots, h_r(\\vec{x}))\n\t\\end{equation*}\n\t\\begin{itemize}\n\t\t\\item We write $f = g \\circ (h_1, \\dots, h_r) $\n\t\\end{itemize}\n\t\n\t\\item Let $ g: \\Nat^n \\to \\Nat, h: \\Nat^{n+2} \\to \\Nat $ be partial functions.\n\t\n\tThen the partial function $ f: \\Nat^{n+1} \\to \\Nat $ obtained from $ g $ and $ h $ by primitive recursion is defined by:\n\t\\begin{align*}\n\t&f(\\vec{x}, 0) = g(\\vec{x})\\\\\n\t&f(\\vec{x}, y + 1) = h(\\vec{x}, y, f(\\vec{x}, y))\n\t\\end{align*}\n\t\\begin{itemize}\n\t\t\\item For a given $ \\vec{x} $, $ f(\\vec{x}, y) $ is defined for no $ y $, for all $ y $, or for $ 0 \\le y \\le r $ for some $ r \\in \\Nat $\n\t\t\\item Where the `counter' parameter is placed does not matter - it could equally be at the start\n\t\\end{itemize}\n\t \n\\end{itemize}\n\n\\subsection{Primitive Recursive Functions}\n\n\\begin{itemize}\n\t\n\t\\item We define the \\textit{initial functions} to be the following functions:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item The zero function $ z: \\Nat \\to \\Nat $, such that $ z(x) = 0 $ for all $ x \\in \\Nat $\n\t\t\n\t\t\\item The successor function $ \\sigma: \\Nat \\to \\Nat $, such that $ \\sigma(x) = x + 1 $ for all $ x \\in \\Nat $\n\t\t\n\t\t\\item The projection functions $ \\pi_{i, n}: \\Nat^n \\to \\Nat $, where for $ n \\ge 1 $ and $ 1 \\le i \\le n $, $ \\pi_{i, n}(x_1, \\dots, x_n) = x_i $\n\t\t\n\t\\end{itemize}\n\n\t\\item A class $ \\Class $ of total functions is \\textit{primitively recursively closed} if:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item $ \\Class $ contains all the initial functions\n\t\t\n\t\t\\item $ \\Class $ is closed under composition\n\t\t\n\t\t\\item $ \\Class $ is closed under primitive recursion\n\t\t\n\t\\end{itemize}\n\n\t\\item The smallest primitively recursively closed class (i.e. the intersection of all prim. rec. closed classes) is called \\textit{the class of primitive recursive functions}\n\t\n\t\\item Example: addition function $ S: \\Nat^2 \\to \\Nat $, such that $ S(x, y) = x + y $\n\t\\begin{align*}\n\tS(x, 0) &= g(x), g = \\pi_{1, 1}\\\\\n\tS(x, y  + 1) &= S(x, y) + 1\\\\\n\t\t\t\t &= \\sigma(S(x, y))\\\\\n\t\t\t\t &= h(x, y, S(x, y)), h = \\sigma \\circ \\pi_{3, 3}\n\t\\end{align*}\n\t\n\t\\newpage\n\t\n\t\\item Useful tips for showing a function is in a primitively recursively closed class $ \\Class $:\n\t\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item Given $ f: \\Nat^n \\to \\Nat $ is in $ \\Class $\n\t\t\n\t\tIf $ g: \\Nat^m \\to \\Nat $ is defined by $ g(x_1, \\dots, x_m) = f(y_1, \\dots, y_n) $ where each $ y_i $ is either a constant or $ x_j $ for some $ j $, then $ g \\in \\Class $ -- lets you manipulate arity\n\t\t\n\t\t\\item To show a unary function $ f: \\Nat \\to \\Nat $ is in $ \\Class $ by primitive recursion, define $ f': \\Nat^2 \\to \\Nat $ such that $ f'(x, y) = f(y) $; then, if $ f' $ can be shown to be in $ \\Class $, $ f $ will be also\n\t\t\n\t\t\\item Let $ a \\in \\Nat $ and $ h: \\Nat^2 \\to \\Nat $ be in $ \\Class $\n\t\t\n\t\tThen, for $ f: \\Nat \\to \\Nat $, if $ f(0) = a $ and $ f(y + 1) = h(y, f(y)) $, $ f \\in \\Class $\n\t\t\n\t\\end{itemize}\n\n\t\\item A \\textit{primitive recursive definition} of $ f: \\Nat^n \\to \\Nat $ is a finite sequence of functions $ f_0, f_1, \\dots, f_k = f $, where for each $ i $:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item $ f_i $ is initial; or\n\t\t\n\t\t\\item $ f_i $ is obtained from composition of some functions $ f_j $, $ j < i $; or\n\t\t\n\t\t\\item $ f_i $ is obtained by primitive recursion from two of $ f_j $, $ j < i $\n\t\t\n\t\\end{itemize}\n\n\t\\item Example: addition function $ S $ can be defined by $ \\pi_{1, 1}, \\pi_{3, 3}, \\sigma, \\sigma \\circ \\pi_{3, 3} $\n\t\n\t\\item The class $ \\Class_1 $ of primitive recursive functions is the same as the class $ \\Class_2 $ of functions that have a primitive recursive definition (seems trivial, but isn't!)\n\t\n\tProve by showing $ \\Class_1 \\subseteq \\Class_2 $ (i.e. $ \\Class_2 $ is prim. rec. closed) and that $ \\Class_2 \\subseteq \\Class_1 $ (i.e. $ \\Class_2 $ is contained in any prim. rec. closed class)\n\t\n\t\\item Let $ \\Class $ be a prim. rec. closed class, and let $ g: \\Nat^{n+1} \\to \\Nat $ be in $ \\Class $; then the functions $ f_1: \\Nat^{n+1} \\to \\Nat $ and $ f_2: \\Nat^{n+1} \\to \\Nat $ defined by:\n\t\n\t$ f_1(\\vec{x}, y) = \\sum_{t=0}^{y} g(\\vec{x}, t) $\n\t\n\t$ f_2(\\vec{x}, y) = \\prod_{t=0}^{y} g(\\vec{x}, t) $\n\t\n\tare also in $ \\Class $\n\t\n\t\\item Useful prim. rec. functions:\n\t\n\t\\begin{itemize}\n\t\t\\item Proper subtraction $ x \\monus y = max\\set{x - y, 0} $\n\t\t\n\t\t\\item Sign $ sg(x) = \\begin{cases}\n\t\t0 \\text{ if } x = 0\\\\\n\t\t1 \\text{ if } x \\ge 0\n\t\t\\end{cases} $\n\t\t\n\t\\end{itemize}\n\t\n\\end{itemize}\n\n\\newpage\n\n\\subsection{Predicates}\n\n\\begin{itemize}\n\t\\item A predicate $ P(x_1, \\dots, x_n) $ of $ n $ variables is a statement concerning $ x_i \\in \\Nat$ which is either true or false\n\t\n\t\\item We can identify $ P $ with the set $ A_P = \\setcomp{\\vec{x} \\in \\Nat^n}{P(\\vec{x}) \\text{ is true}} $\n\t\n\t\\subitem E.g. $ P(x, y) $ means ``$ x $ divides $ y $\", so $ A_P = \\set{(1, 6), (2, 6), (3, 6), (6, 6), (1, 3) \\dots} $\n\t\t\n\t\\item The \\textit{characteristic function} of a set $ \\chi_A: \\Nat^n \\to \\set{0, 1} $ of $ A \\subseteq \\Nat^n $ is defined by:\n\t\\begin{equation*}\n\t\\chi_A(\\vec{x}) = \\begin{cases}\n\t1 \\text{ if } \\vec{x} \\in A\\\\\n\t0 \\text{ if } \\vec{x} \\notin A\n\t\\end{cases}\n\t\\end{equation*}\n\t\\item For a predicate $ P $, we define $ \\chi_P $ to be $ \\chi_{A_P} $\n\t\n\t\\item Let $ \\Class $ be a prim. rec. closed class; then a subset $ A \\subseteq \\Nat^n $ is in $ \\Class $ if $ \\chi_A \\in \\Class $\n\t\n\t\\subitem So a predicate $ P $ of $ n $ variables is in $ \\Class $ if $ \\chi_P \\in \\Class $\n\t\n\t\\item If $ A, B \\subseteq \\Nat^n $ are in $ \\Class $, then $ A \\cup B $, $ A \\cap B $ and $ \\Nat^n \\setminus A $ are in $ C $\n\t\n\t\\subitem So if $ P, Q $ are predicates of $ n $ variables in $ \\Class $, $ P \\lor Q $, $ P \\land Q $ and $ \\lnot P $ are in $ \\Class $\n\t\n\t\\subitem Proof: $ \\chi_{A \\cup B}(x) = sg(\\chi_A(x) + \\chi_B(x)) $, ~~~ $ \\chi_{A \\cap B} = \\chi_A(x) \\cdot \\chi_B(x) $, ~~~ $ \\chi_{\\Nat^n \\setminus A}(x) = 1 \\monus \\chi_A(x) $\n\t\n\t\\item The predicates $ x = y $, $ x \\ne y $, $ x \\le y $, $ x < y $, $ x \\ge y $, $ x > y $ are prim. rec.\n\t\n\t\\subitem Proof: Note that $ \\chi_{\\ne} (x, y) = sg(\\abs{x - y}) $ and $ \\chi_{>} (x, y) = sg(x \\monus y) $\n\t\n\t\\item Bounded quantifiers:\n\t\n\tAssume $ P $ is a pred. of $ n + 1 $ variables in $ \\Class $; then $ Q, R $ of $ n + 1 $ variables defined below are in $ \\Class $:\n\t\n\t$ Q(x_1, \\dots x_n, z) $ is true if and only if $ \\exists_{y \\le z} (P(x_1, \\dots, x_n, y) \\text{ is true})$\n\t\n\t$ R(x_1, \\dots x_n, z) $ is true if and only if $ \\forall_{y \\le z} (P(x_1, \\dots, x_n, y) \\text{ is true})$\n\t\n\t\\subitem Proof: $ \\chi_Q (\\vec{x}, z) = sg(\\sum_{y=0}^{z} \\chi_P(\\vec{x}, y)) $, and $ \\chi_R (\\vec{x}, z) = \\prod_{y=0}^{z} \\chi_P(\\vec{x}, y) $\n\t\n\\end{itemize}\n\n\\subsection{More Primitive Recursive Functions}\n\n\\subsubsection{Bounded Minimisation}\n\nLet $ P $ be a pred. of $ n + 1 $ variables. Define $ f: \\Nat^{n+1} \\to \\Nat $ by:\n\\begin{equation*}\nf(\\vec{x}, z) = \\begin{cases}\n\\text{the least } y \\le z \\text{ s.t. } P(\\vec{x}, y) \\text{ is true}\\\\\nz + 1 \\text{ if no such } y \\text{ exists}\n\\end{cases}\n\\end{equation*}\nThen, $ f(\\vec{x}, z) = \\mu ~ {y \\le z} ~ P(\\vec{x}, y) $, called \\textit{bounded minimisation}. We have that if $ P \\in \\Class$ (a prim. rec. closed class), then $ f $ is in $ \\Class $.\n\n\\begin{proof}\n\t\nDefine $ g(\\vec{x}, t) = \\prod_{y=0}^{t} sg(1 \\monus \\chi_P(\\vec{x}, y) \\text{ is true})$. Note that $ g(\\vec{x}, t) =  \\begin{cases}\n0 \\text{ if } \\exists_{y \\le t} P(x, y) \\text{ is true}\\\\\n1 \\text{ if } \\forall_{y \\le t} P(x, y) \\text{ is false}\n\\end{cases} $\n\nLet $ y \\le z $ be the least s.t. $ P(\\vec{x}, y) $ is true.\n\nThen the values of $ g $ look like: \\begin{tabular}{r | c c c c c c c c}\n\t$ t $ & 0 & 1 & $ \\dots $ & $ y - 1 $ & $ y $ & $ y + 1 $ & $ \\dots $ & $ z $ \\\\ \\hline\n\t$ g(\\vec{x}, t) $ & 1 & 1 & $ \\dots $ & 1 & 0 & 0 & $ \\dots $ & 0 \n\\end{tabular}\n\nLet $ f(\\vec{x}, z) = \\sum_{t=0}^{z} g(\\vec{x}, t) $, then we will have $ f $ as required for bounded minimisation. If there is no such $ y $, then by the definition of $ g $ we would have $ f(\\vec{x}, z) = z + 1 $\n\n\\end{proof}\n\n\\subsubsection{Definition By Cases}\n\nLet $ f_1, \\dots, f_k : \\Nat^n \\to \\Nat $ be in  prim. rec. closed $ \\Class $ and let $ P_1, \\dots, P_k $ be predicates in $ \\Class $ of $ n $ variables. Suppose that for each $ \\vec{x} \\in \\Nat^n $ \\textit{exactly} one of $ P_1(\\vec{x}), \\dots, P_k(\\vec{x}) $ is true. Define $ f: \\Nat^n \\to \\Nat $ by:\n\\begin{equation*}\nf(\\vec{x}) = f_i(\\vec{x}) \\text{ if } P_i(\\vec{x}) \\text{ is true}\n\\end{equation*}\nThen $ f $ is in $ \\Class $.\n\n\\begin{proof}\n\n$ f(\\vec{x}) = f_1(\\vec{x}) \\cdot \\chi_{P_1}(\\vec{x}) + \\dots + f_k(\\vec{x}) \\cdot \\chi_{P_k}(\\vec{x}) $\n\n\\end{proof}\n\n\\subsubsection{Iteration}\n\nLet $ X $ be a set, with a partial function $ f: X \\to X $. The \\textit{iterate} of $ f $ is the partial function $ F: X \\times \\Nat \\to X $ defined by:\n\\begin{align*}\n&F(x, 0) = x\\\\\n&F(x, n + 1) = f(F(x, n))\n\\end{align*}\nWe have a notion of a function $ f: \\Nat^n \\to \\Nat $ being in a class $ \\Class $. This can be extended to functions $ f: \\Nat^n \\to \\Nat^k $ by saying that $ f $ is in $ \\Class $ if $ \\pi_{i, k} \\circ f $ is in $ \\Class $ for each $ 1 \\le i \\le k $.\n\nA class $ \\Class $ is closed under iteration if, whenever $ f: \\Nat^n \\to \\Nat^n $ is in $ \\Class $, then its iterate $ F: \\Nat^{n+1} \\to \\Nat^n $ is in $ \\Class $.\n\nLet $ \\Class $ be a prim. rec. closed class. Then if $ f: \\Nat^n \\to \\Nat^n $ is in $ \\Class $, its iterate $ F: \\Nat^{n+1} \\to \\Nat^n $ is also in $ \\Class $. So any prim. rec. closed class is closed under iteration.\n\n\\begin{proof}\n\nThis shows only the $ n = 1 $ case.\n\nDefine $ f': \\Nat^3 \\to \\Nat $ by $ f'(x, y, z) = f(z) $, which is in $ \\Class $.\n\nThen the iterate of $ f $ is defined by:\n\n\\begin{align*}\n&F(z, 0) = z\\\\\n&F(z, y + 1) = f(F(z, y)) = f'(x, y, F(x, y))\n\\end{align*}\n\nThis is defined by primitive recursion, so $ F $ is in $ \\Class $.\n\n\\end{proof}\n\n\\newpage\n\n\\subsection{Recursive and Partial Recursive Functions}\n\n\\subsubsection{Minimisation}\n\nLet $ f: \\Nat^{n+1} \\to \\Nat $ be a partial function. The function obtained from $ f $ by \\textit{minimisation} is the partial function $ g: \\Nat^n \\to \\Nat $ defined by\n\\begin{equation*}\ng(\\vec{x}) = \\begin{cases}\nr &\\text{ if } f(\\vec{x}, r) = 0 \\text{ and for } s < r, f(\\vec{x}, s) \\text{ is defined and not 0}\\\\\n\\textit{undefined} &\\text{ otherwise}\n\\end{cases}\n\\end{equation*}\nWe write $ g(\\vec{x}) = \\mu y (f(\\vec{x}, y) = 0) $. It is also called the $ \\mu $-operator or unbounded search operator. The function $ g $ may be partial, even if $ f $ is total, and vice versa.\n\nNote that it is not \\textit{quite} accurate to say $ g(x) = \\mu y (f(\\vec{x}, y) = 0) $ is the least $ y $ s.t. $ f(x, y) = 0 $; if there is some least $ y $ s.t. $ f(x, y) = 0 $, but $ f(x, s) $ is undefined for some $ s < y $, then $ g(x) $ is undefined.\n\n\\subsubsection{The Class of Recursive Functions}\n\n\\begin{itemize}\n\t\n\t\\item A total function $ f(\\vec{x}, y) $ is \\textit{regular} if for any $ \\vec{x} \\in \\Nat^n $, there exists $ y \\in \\Nat $ such that $ f(\\vec{x}, y) = 0 $\n\t\n\t\\item The regular functions are exactly those to which we can apply minimisation and end up with a total function\n\t\n\t\\item The function $ g $ is obtained from $ f $ by \\textit{regular minimisation} if $ g(\\vec{x}) = \\mu y (f(\\vec{x}, y) = 0) $ where $ f $ is regular\n\t\n\t\\item The \\textit{class of recursive functions} is the smallest class $ \\Class $ of total functions which is primitively recursively closed and is closed under regular minimisation\n\t\n\t\\item Note that there are recursive functions which are \\textit{not} primitive recursive\n\t\n\t\\item Example: the two-argument Ackermann function defined by:\n\t\\begin{equation*}\n\tA(m, n) = \\begin{cases}\n\tn + 1 &\\text{ if } m = 0\\\\\n\tA(m - 1, 1) &\\text{ if } m > 0 \\text{ and } n = 0\\\\\n\tA(m - 1, A(m, n - 1)) &\\text{ if } m > 0 \\text{ and } n > 0\n\t\\end{cases}\n\t\\end{equation*}\n\t\n\t\\item The \\textit{class of partial recursive functions} is the smallest class of partial functions which contains the initial functions, and is closed under composition, primitive recursion and minimisation\n\t\n\t\\begin{itemize}\n\t\t\\item Note that this is \\textit{not} a primitively recursively closed class -- that term only applies to a class of total functions\n\t\\end{itemize}\n\t\n\\end{itemize}", "meta": {"hexsha": "189fb64d2b43316f29a58ef5625d9d70d4da9ee0", "size": 13042, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MATH3306/computability/c_partialrec.tex", "max_stars_repo_name": "mcoot/CourseNotes", "max_stars_repo_head_hexsha": "c643f46e32cdf4c567bf73d4a23784c834278803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATH3306/computability/c_partialrec.tex", "max_issues_repo_name": "mcoot/CourseNotes", "max_issues_repo_head_hexsha": "c643f46e32cdf4c567bf73d4a23784c834278803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATH3306/computability/c_partialrec.tex", "max_forks_repo_name": "mcoot/CourseNotes", "max_forks_repo_head_hexsha": "c643f46e32cdf4c567bf73d4a23784c834278803", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.2071197411, "max_line_length": 303, "alphanum_fraction": 0.5975310535, "num_tokens": 4822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7122438050179557}}
{"text": "\\section{Machine Learning Theory (Nonlinear Separators)}\nHere we being by considering what the notion of a `God-given' distribution that we are trying to learn really is in the context of classification. So let $X = \\mathbb{R}^d$ denote the space of features (i.e. the image space) and $Y = \\{1,...,k\\}$ denote the set of labels. The fundamental object whose existence we must assume is a probability distribution over the space $X\\times Y$. Below we give a few equivalent ways of describing such a probability distribution.\n\n\\begin{lemma}\n The three objects following are equivalent (note that we always consider the Borel $\\sigma$-algebra when defining our notion of measure):\n \\begin{itemize}\n  \\item A probability measure $\\pi$ on $X\\times Y$\n  \\item A probability measure on $Y$, defined by probabilities $p_1,...,p_k$ with $0\\leq p_i\\leq 1$ and $\\sum_{i=1}^k p_i = 1$, combined with $k$ \\textit{conditional} probability measures $\\pi_i$ on $X$, representing the conditional distribution given the $i$-th label\n  \\item A probability measure on $\\pi_X$ on $X$, combined with a family of conditional distributions on the labels, defined by $p_i(x)$ for each $i = 1,...,k$ and $x\\in X$, which must satify $0\\leq p_i(x)\\leq 1$ and $\\sum_{i=1}^k p_i(x) = 1$.\n \\end{itemize}\n\n\\end{lemma}\n\n\\begin{proof}\n We will show how to get a probability measure on $X\\times Y$ from each of the other two objects, the reverse is more technical. Let $A\\subset X\\times Y$. We define\n \\begin{equation}\n  \\pi(A) = \\sum_{i=1}^k p_i\\pi_i(A\\cap (X\\times \\{i\\}))\n \\end{equation}\n and\n \\begin{equation}\n  \\pi(A) = \\int_X \\sum_{i:(x,i)\\in A} p_i(x)d\\pi_X\n \\end{equation}\n\n\\end{proof}\n\nWe call a distribution non-linearly separable if the label is uniquely determined by image.\n\\begin{definition}\n A distribution is called non-linearly separable if the following two equivalent conditions hold\n \\begin{itemize}\n  \\item $\\pi_i$ and $\\pi_j$ have disjoint support for $i\\neq j$\n  \\item $p_i(x)$ is either equal to $0$ or $1$ for every $x\\in X$\n \\end{itemize}\n\n\\end{definition}\n\nWe have the following lemma\n\\begin{lemma}\n If $\\pi$ is non-linearly separable, then there exists a classification function $f_c:X\\rightarrow Y$ such that\n \\begin{equation}\n  \\mathbb{P}_{(x,y)\\sim \\pi}(f_c(x) = y) = 1.\n \\end{equation}\n Equivalently, the true risk\n \\begin{equation}\n  R(f_c) = \\mathbb{E}_{(x,y)\\sim\\pi}(\\chi_{f_c(x) \\neq y})\n \\end{equation}\n is equal to $0$.\n\n\\end{lemma}\n\nMore generally, the labels may not be uniquely determined by the features. In this more general situation the true risk above may not be $0$. Consequently, we consider a situation where no label can be ruled out for any $x\\in X$, which probably corresponds more closely to a realistic situation.\n\n\\begin{definition}\n A distribution $\\pi$ is completely label-ambiguous if\n $p_i(x) > 0$ for every $i$ and every $x\\in X$.\n\\end{definition}\n\n\\begin{lemma}\n If $\\pi$ is label-ambiguous, the probability distributions $p_i(x)$ can be written as\n \\begin{equation}\n  \\{p_i(x)\\} = \\text{softmax}(\\Psi(x))\n \\end{equation}\n for some function $\\Psi:X\\rightarrow \\mathbb{R}^k$.\n\\end{lemma}\n\nNote that the function $\\Psi$ completely contains exactly the conditional probabilities over the labels given the images and it is this function which we are usually interested in learning (i.e. we don't care about the image distribution $\\pi_X$).\n", "meta": {"hexsha": "514ef145ac9b0c7c8d55e9f829c250767645c76f", "size": 3363, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ProbNonlinear.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/ProbNonlinear.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/ProbNonlinear.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.9545454545, "max_line_length": 467, "alphanum_fraction": 0.7234611954, "num_tokens": 983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7122438050179557}}
{"text": "\\section{Multivariate Calculus}\r\nIn many real world applications, functions we might be interested in can involve more than one independent variable.\r\n\\begin{example}\r\n    Waves along a string.\r\n    Let $f(x,t)$ be the displacement where $x$ be the position and $t$ be the time.\r\n    The shape of the wave (represented by $f(x,t_0)$ where $t_0$ is fixed) is dependent on time.\r\n\\end{example}\r\nHow do we define the derivative when a function depends on more than one variable?\r\nSuppose that $f(x,y)$ is the elevation of the terrain at the specific location $x,y$.\r\nWe can draw a contour map of its projection on a plane.\r\nIf we are interested in the steepness at a point $a$ on the surface, one should note that different trails going though $a$ may have different steepness.\r\nSo the general point is that the slope of a function at a given point depends on the direction.\r\n\\subsection{Partial Derivative}\r\nWe want to find the derivative of a multivariate function with respect to one variable while keeping others fixed.\r\n\\begin{definition}\r\n    Mathematically speaking, we define partial derivative $f(x,y)$ with respect to $x$ fixing $y$ is the limit\r\n    $$\\left.\\frac{\\partial f}{\\partial x}\\right|_y=\\lim_{h\\to0}\\frac{f(x+h,y)-f(x,y)}{h}$$\r\n    provided that it exists.\r\n    We can define the partial derivative with respect to $y$ fixing $x$ similarly.\r\n\\end{definition}\r\n\\begin{example}\r\n    Let $F(x,y)=x^2+y^3+e^{xy^2}$, so\r\n    $$\\left.\\frac{\\partial f}{\\partial x}\\right|_y=2x+y^2e^{xy^2},\\left.\\frac{\\partial f}{\\partial y}\\right|_x=3y^2+2xye^{xy^2}$$\r\n\\end{example}\r\nWe can do partial derivatives recursively as well.\r\n$$\\left.\\frac{\\partial^2 f}{\\partial x^2}\\right|_y=2+y^4e^{xy^2}$$\r\nNow we can define cross-derivative as well,\r\n$$\\left.\\frac{\\partial}{\\partial y}\\left(\\left.\\frac{\\partial f}{\\partial x}\\right|_y\\right)\\right|_x=2ye^{xy^2}+2xy^3e^{xy^2}$$\r\nSince the notation is cumbersome, we sometimes omit the symbol $|_y$.\\\\\r\nThere is a symmetry involved in mixed partial derivatives.\r\nBy that we mean\r\n$$\\frac{\\partial^2 f}{\\partial x\\partial y}=\\frac{\\partial^2 f}{\\partial y\\partial x}$$\r\ngiven that all these partial derivatives exist.\r\nSome properties are required for this equality to hold, but they are out of the scope of this course.\\\\\r\nOn higher dimensions (where we can define partial derivatives analogously), for example $f(x,y,z)$, when we sometimes say\r\n$$\\left.\\frac{\\partial f}{\\partial x}\\right|_y$$\r\nits value would depend on the path it takes in the $x-z$ plane.\\\\\r\nWe sometimes use the shorthand notation $f_x,f_{xy},f_{xx}$ for the partial derivatives.\r\n\\subsection{The Chain Rule on Higher Dimensions}\r\nConsider $f(x(t),y(t))$, we first want to have the concept of a differential of a function.\r\n$$\\delta f=f(x+\\delta x, y+\\delta y)-f(x,y)$$\r\nSo we have\r\n$$\\delta f=f(x+\\delta x, y+\\delta y)-f(x+\\delta x,y)+f(x+\\delta x,y)-f(x,y)$$\r\nWhen $y$ is held constant, $f(x+\\delta x,y)=f(x,y)+\\delta x(\\partial f/\\partial x)(x,y)+o(\\delta x)$ as $\\delta x\\to0$.\r\nSimilarly $f(x+\\delta x,y+\\delta y)=f(x,y)+\\delta y(\\partial f/\\partial y)(x+\\delta x,y)+o(\\delta y)$ as $\\delta y\\to0$.\r\nTherefore as $\\delta x\\to 0,\\delta y\\to0$\r\n\\begin{align*}\r\n    \\delta f\r\n    &=f(x+\\delta x,y)+\\delta y\\frac{\\partial f}{\\partial y}(x+\\delta x,y)+o(\\delta y)-f(x+\\delta x,y)\\\\\r\n    &\\quad+f(x,y)+\\delta x\\frac{\\partial f}{\\partial x}(x,y)+o(\\delta x)-f(x,y)\\\\\r\n    &=\\delta y\\frac{\\partial f}{\\partial y}(x+\\delta x,y)+\\delta x\\frac{\\partial f}{\\partial x}(x,y)+o(\\delta x)+o(\\delta y)\\\\\r\n    &=\\delta y\\frac{\\partial f}{\\partial y}(x,y)+\\delta x\\frac{\\partial f}{\\partial x}(x,y)\\\\\r\n    &\\quad+\\delta x\\delta y\\frac{\\partial}{\\partial x}\\frac{\\partial f}{\\partial y}(x,y)+o(\\delta x)+o(\\delta y)+o(\\delta x\\delta y)\r\n\\end{align*}\r\nNote that $o(\\delta x\\delta y)+o(\\delta x)=o(\\delta x)$ as $\\delta y\\to0$, so we can ignore that term.\\\\\r\nWe let $\\delta x,\\delta y\\to 0$, so\r\n\\begin{align*}\r\n    \\delta f&=\\delta y\\frac{\\partial f}{\\partial y}+\\delta x\\frac{\\partial f}{\\partial x}+\\delta x\\delta y\\frac{\\partial}{\\partial x}\\frac{\\partial f}{\\partial y}+o(\\delta x)+o(\\delta y)\\\\\r\n    \\mathrm df&=\\frac{\\partial f}{\\partial y}\\mathrm dy+\\frac{\\partial f}{\\partial x}\\mathrm dx\r\n\\end{align*}\r\nThis is called the chain rule in differential form.\r\nWe can obtain the chain rule by dividing by another differential $\\mathrm dt$ before applying the limit.\r\n$$\\frac{\\mathrm df}{\\mathrm dt}=\\frac{\\partial f}{\\partial y}\\frac{\\mathrm dy}{\\mathrm dt}+\\frac{\\partial f}{\\partial x}\\frac{\\mathrm dx}{\\mathrm dt}$$\r\nThis is called the multivariate chain rule.\\\\\r\nSuppose $f(x,y(x))$, then\r\n$$\\frac{\\mathrm df}{\\mathrm dx}=\\frac{\\partial f}{\\partial x}+\\frac{\\partial f}{\\partial y}\\frac{\\mathrm dy}{\\mathrm dx}$$\r\nWe can integrate it back\r\n$$\\int\\mathrm df=\\int\\frac{\\partial f}{\\partial x}\\,\\mathrm dx+\\int\\frac{\\partial f}{\\partial y}\\,\\mathrm dy$$\r\nNote that we need to integrate the above equation along a given path, but if the function is nice enough, only the endpoints matter.\r\n\\begin{example}\r\n    We choose the paths\r\n    $$(x_1,y_1)\\to(x_2,y_1)\\to(x_2,y_2)$$\r\n    and\r\n    $$(x_1,y_1)\\to(x_1,y_2)\\to(x_2,y_2)$$\r\n    then\r\n    $$f(x_2,y_2)-f(x_1,y_1)=\\int_{x_1}^{x_2}\\frac{\\partial f}{\\partial x}(x,y_1)\\,\\mathrm dx+\\int_{y_1}^{y_2}\\frac{\\partial f}{\\partial y}(x_2,y)\\,\\mathrm dy$$\r\n    $$=\\int_{x_1}^{x_2}\\frac{\\partial f}{\\partial x}(x,y_2)\\,\\mathrm dx+\\int_{y_1}^{y_2}\\frac{\\partial f}{\\partial y}(x_1,y)\\,\\mathrm dy$$\r\n\\end{example}\r\nAn application of the multivariate chain rule is the change of variables.\r\nIt is often useful to write a differential equation in a different coordinate system before solving it.\r\nTo do this, we need to transform the derivatives from one to the other.\r\n\\begin{example}\r\n    We try to transform from Cartesian to polar coordinate, so $x=r\\cos\\theta,y=r\\sin\\theta$, so we can write $f(x(r,\\theta),y(r,\\theta))$, so\r\n    $$\\left.\\frac{\\partial f}{\\partial r}\\right|_\\theta=\\left.\\frac{\\partial f}{\\partial x}\\right|_y\\left.\\frac{\\partial x}{\\partial r}\\right|_\\theta+\\left.\\frac{\\partial f}{\\partial y}\\right|_x\\left.\\frac{\\partial y}{\\partial r}\\right|_\\theta=\\left.\\frac{\\partial f}{\\partial x}\\right|_y\\cos\\theta+\\left.\\frac{\\partial f}{\\partial y}\\right|_x\\sin\\theta$$\r\n\\end{example}\r\nWe can also apply it to implicit differentiation.\r\nConsider $f(x,y,z)=c$ where $c$ is a constant.\r\nIt implicitly defined $z(x,y),x(y,z),y(z,x)$.\r\nFor example, we can take $xy+y^2z+z^5=1$, so $x=(1-z^5-y^2z)/y$ and we can find $y$ by quadratic formula, but we cannot do it easily with $z$ since it's quintic.\\\\\r\nHowever, we can find the derivative $\\partial z/\\partial x$ fixing $y$ by observing\r\n$$0=\\left.\\frac{\\partial f}{\\partial x}\\right|_y=y+y^2\\left.\\frac{\\partial z}{\\partial x}\\right|_y+5z^4\\left.\\frac{\\partial z}{\\partial x}\\right|_y$$\r\nwhich we can solve for the desired derivative.\\\\\r\nNow consider $f(x,y,z(x,y))=0$,\r\n$$\\mathrm df=\\left.\\frac{\\partial f}{\\partial x}\\right|_{y,z}\\mathrm dx+\\left.\\frac{\\partial f}{\\partial y}\\right|_{x,z}\\mathrm dy+\\left.\\frac{\\partial f}{\\partial z}\\right|_{x,y}\\mathrm dz$$\r\nWe want the derivative of $z$ wrt $x$ with $y$ fixed, so\r\n$$\\left.\\frac{\\partial f}{\\partial x}\\right|_y=\\left.\\frac{\\partial f}{\\partial x}\\right|_{y,z}+\\left.\\frac{\\partial f}{\\partial z}\\right|_{x,y}\\left.\\frac{\\partial z}{\\partial x}\\right|_y$$\r\nIn fact, $(\\partial f/\\partial x)|_y=0$.\\\\\r\nThe chain rule allows us to differentiate an integral.\r\nConsider  function $f(x,c)$ where each value of $c$ gives a different function $f$.\r\nWe want to find the (partial) derivative of the integral\r\n$$\\int_0^bf(x,c)\\,\\mathrm dx$$\r\nThen\r\n\\begin{align*}\r\n    \\left.\\frac{\\partial I(b,c)}{\\partial b}\\right|_c\r\n    &=\\lim_{h\\to 0}\\frac{1}{h}\\int_b^{b+h}f(x,c)\\,\\mathrm dx\\\\\r\n    &=f(b,c)\r\n\\end{align*}\r\nSimilarly,\r\n\\begin{align*}\r\n    \\left.\\frac{\\partial I(b,c)}{\\partial c}\\right|_b\r\n    &=\\lim_{h\\to 0}\\frac{1}{h}\\int_0^bf(x,c+h)-f(x,c)\\,\\mathrm dx\\\\\r\n    &=\\int_0^b\\left.\\frac{\\partial I(x,c)}{\\partial c}\\right|_x\\,\\mathrm dx\r\n\\end{align*}\r\nSuppose that $b,c$ depends on $t$, so $I(b(t),c(t))$, so\r\n\\begin{align*}\r\n    \\frac{\\mathrm dI}{\\mathrm dt}\r\n    &=\\frac{\\partial I}{\\partial b}\\frac{\\mathrm db}{\\mathrm dt}+\\frac{\\partial I}{\\partial c}\\frac{\\mathrm dc}{\\mathrm dt}\\\\\r\n    &=f(b,c)\\dot{b}+\\dot{c}\\int_0^b\\left.\\frac{\\partial I(x,c)}{\\partial c}\\right|_x\\,\\mathrm dx\r\n\\end{align*}\r\nIn general,\r\n$$\\frac{\\mathrm d}{\\mathrm dt}\\int_{a(t)}^{b(t)}f(x,c(t))\\,\\mathrm dx=\\dot{c}\\int_{a(t)}^{b(t)}\\frac{\\partial f}{\\partial c}\\,\\mathrm dx+f(b,c)\\dot{b}-f(a,c)\\dot{a}$$\r\nNote that the reciprocal rule also apply.\r\nThe same rule applies to partial derivatives given that the same parameter is kept constant.\r\n$$\\left.\\frac{\\partial r}{\\partial x}\\right|_y=\\frac{1}{\\partial x/\\partial r|_y}$$", "meta": {"hexsha": "41252e8adb4b07f89dab12a8cfba5a753fb20b51", "size": 8754, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/multi.tex", "max_stars_repo_name": "david-bai-notes/IA-Differential-Equations", "max_stars_repo_head_hexsha": "eba1ffe070fce235ce1c9611b23339c35c6d6931", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3/multi.tex", "max_issues_repo_name": "david-bai-notes/IA-Differential-Equations", "max_issues_repo_head_hexsha": "eba1ffe070fce235ce1c9611b23339c35c6d6931", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3/multi.tex", "max_forks_repo_name": "david-bai-notes/IA-Differential-Equations", "max_forks_repo_head_hexsha": "eba1ffe070fce235ce1c9611b23339c35c6d6931", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 70.5967741935, "max_line_length": 356, "alphanum_fraction": 0.6716929404, "num_tokens": 2871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.7121589441155416}}
{"text": "\\documentclass{article}\n\n\\usepackage[a4paper, total={6in, 8in}]{geometry}\n\n\\usepackage[T1]{fontenc}\n\\usepackage[utf8]{inputenc}\n\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{braket}\n\\usepackage{listings}\n\\usepackage{mathtools}\n\n\\title{Simulation of Shor's Algorithm Report}\n\\author{\n  José Semedo\\\\\n  ist178294\n  \\and\n  Rodrigo Bernardo\\\\\n  ist178942\n}\n\n\\date{}\n\n\\begin{document}\n\\maketitle\n\n\\section{Introduction}\nIn this project we studied and implemented a simulator of Shor's quantum\nalgorithm for integer factorization. The problem is reduced to the problem of\norder finding. Although it is not known if order finding is hard in a classical\nsetting, Shor \\cite{Shor} demonstrated that it is solvable in polynomial time if\none has access to a quantum computer, thus showing integer factorization is\nsolvable in polynoial time.\n\n\n\\section{Language and Tools}\nOur simulation is implemented in Python 3, together with the numpy library.\n\n\n\\section{Implementation Overview}\n\n\\subsection{Memory}\nThe algorithm takes an odd integer $N$, such that it is not a prime nor a power\nof a prime, and an integer $x, 1 < x < N$, and tries to find the multiplicative\norder of $x$ modulo $N$.\n\nIt starts by allocating $t + n$ qubits, with $n = \\lceil{\\log_2 N}\\rceil$ and\n$N^2 \\leq 2^t < 2N^2$, and initializes the state to $\\ket{\\psi_{0}} = \\ket{0,\n0}$.\n\nWe represent the memory by explicitly saving all the $2^{t+n}$ possible states and\ntheir corresponding amplitudes, equivalent to the representation of the quantum\nstate as a linear vector combination $\\ket{\\psi} =\n\\sum_{j=0}^{t+n}a_{j}\\ket{j}$.\n\n\\subsection{Hadamard Gates}\nThe algorithm then applies Hadamard gates to the first $t$ qubits. This creates\na quantum superposition where the amplitudes are equidistributed between the\nfirst t bits. The state becomes $\\ket{\\psi_1} = H^{\\otimes{t}}\\ket{\\psi_0} =\n2^{-t/2}\\sum_{j=0}^{2^t-1}\\ket{j}\\ket{0}$.\n\nWe simulate this step by explicitly reaching for the states where the last $n$\nqubits are $\\ket{0}$ and setting their amplitudes to $2^{-t/2}$.\n\n\\subsection{Modular Exponentiation}\n\nIn the next step, the operator $\\ket{j, k} \\mapsto \\ket{j, k + x^j \\pmod N}$ is\napplied to all the qubits, giving the state\n$\\ket{\\psi_2} =\n2^{-t/2}\\sum_{j=0}^{2^t-1}\\ket{j}\\ket{x^b}$.\n\nThis step is fast because it generates all the powers\nsimultaneously by quantum parallelism.\n\nHere we take advantage of Python's built-in modular exponentiation function and\nsimulate this by applying the operator to all the states sequentially.\n\n\\subsection{Quantum Fourier Transform}\nThe discrete Fourier transform is then applied to the first t qubits. This step\nis $O(n2^{n})$ if done classically, but can be done polynomially with a quantum\ncomputer.\n\nWe simulate this step by sequentially applying the formula\n$\\ket{k} \\mapsto 2^{-t/2} \\sum_{j=0}^{2^{t}-1}\\omega^{jk}\\ket{j}$, where\n$\\omega^{jk} = e^{2\\pi i j k / N}$,\nto all the possible states, i.e., for each state $\\ket{\\phi} = \\ket{k}$, its\namplitude is changed to $2^{-t/2} \\sum_{j=0}^{2^{t}-1}\\omega^{jk}$.\n\nAfter the quantum state of the system is\n$2^{-t/2}\\sum_{j=0}^{2^{t}-1}\\sum_{k=0}^{2^{t}-1}\\omega^{jk}\\ket{k}\\ket{x^{j}}$\n\n\n\\subsection{Obtaining the Order}\nFinally, a measurement is taken, leaving the state to collapse to one vector of\nthe computational basis. After the application of the previous operations we are\nleft with an approximation of a number $a/r, a \\in \\mathbb{Z}$ with high\nprobability.\n\nWe use a known efficient classical algorithm \\cite{HW} for extracting $r$ based\non the best approximation property of the convergents of continued fractions. If\nwe succeed to find $r$, we return it, else the algorithm is restarted.\n\n\n\\section{Execution}\n\nWe can run the program by issuing the command\n\\begin{lstlisting}\n  $ chmod +x shor.py\n  $ ./shor.py N\n\\end{lstlisting}\n\n\\subsection{Examples}\n\n\\begin{lstlisting}\n  $ ./shor.py 15\n  | picked random a = 3\n  | got lucky, 15 = 3 * 5, trying again...\n  | --------------------------------------------\n  | picked random a = 8\n  | measured 59, approximation for 0.23046875 is 3/13\n  | 8^13 mod 15 = 8\n  | failed, trying again ...\n  | measured 246, approximation for 0.9609375 is 1/1\n  | 8^1 mod 15 = 8\n  | failed, trying again ...\n  | measured 109, approximation for 0.42578125 is 3/7\n  | 8^7 mod 15 = 2\n  | failed, trying again ...\n  | measured 222, approximation for 0.8671875 is 7/8\n  | 8^8 mod 15 = 1\n  | got 8\n  | found factor: 15 = 5 * 3\n  5\n\\end{lstlisting}\n\n\n\\begin{lstlisting}\n  $ ./shor.py 21\n  | picked random a = 10\n  | measured 152, approximation for 0.296875 is 3/10\n  | 10^10 mod 21 = 4\n  | failed, trying again ...\n  | measured 342, approximation for 0.66796875 is 2/3\n  | 10^3 mod 21 = 13\n  | failed, trying again ...\n  | measured 37, approximation for 0.072265625 is 1/14\n  | 10^14 mod 21 = 16\n  | failed, trying again ...\n  | measured 53, approximation for 0.103515625 is 2/19\n  | 10^19 mod 21 = 10\n  | failed, trying again ...\n  | measured 42, approximation for 0.08203125 is 1/12\n  | 10^12 mod 21 = 1\n  | got 12\n  | found factor: 21 = 7 * 3\n  7 \n\\end{lstlisting}\n\n\\begin{thebibliography}{9}\n\\bibitem{Shor}\n  Peter Shor,\n  \\emph{Polynomial-Time Algorithms for Prime Factorization and Discrete\nLogarithms on a Quantum Computer}\n\n\\bibitem{HW}\n  G. H. Hardy,\n  E. M. Wright,\n  \\emph{Introduction to Theory of Numbers},\n  Oxford University Press,\n  4th Edition,\n  1975.\n\n\\end{thebibliography}\n\n\\end{document}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "1efdf77e42d8b74f41c6de3c45a52938fb21a1bb", "size": 5439, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/report.tex", "max_stars_repo_name": "rodamber/cps", "max_stars_repo_head_hexsha": "b78aa7756d24b91476f31b538f51508e2dee48b3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/report.tex", "max_issues_repo_name": "rodamber/cps", "max_issues_repo_head_hexsha": "b78aa7756d24b91476f31b538f51508e2dee48b3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/report.tex", "max_forks_repo_name": "rodamber/cps", "max_forks_repo_head_hexsha": "b78aa7756d24b91476f31b538f51508e2dee48b3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6091370558, "max_line_length": 82, "alphanum_fraction": 0.7027027027, "num_tokens": 1716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024556, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.712158940802373}}
{"text": "\\subsection{Divergence Theorem}\r\n\\begin{proposition}\r\n    Let $\\underline{F}$ be a continuously differentiable vector field, and let $V$ be a volume in $\\mathbb R^3$ with piecewise regular boundary $\\partial V$, then\r\n    $$\\int_V\\nabla\\cdot\\underline{F}\\,\\mathrm dV=\\int_{\\partial V}\\underline{F}\\cdot\\mathrm d\\underline{S}$$\r\n    where the normal points out of the volume $V$.\r\n\\end{proposition}\r\n\\begin{proposition}\r\n    Let $\\underline{F}$ be a continuously differentiable vector field in $\\mathbb R^2$, and let $D$ be a subset of $\\mathbb R^2$ be a region with piecewise smooth boundary $\\partial D$, then\r\n    $$\\int_D\\nabla\\cdot\\underline{F}\\,\\mathrm dA=\\int_{\\partial D}\\underline{F}\\cdot\\underline{n}\\,\\mathrm ds$$\r\n    where $\\underline{n}$ points out of the region $D$.\r\n\\end{proposition}\r\n\\begin{example}\r\n    Let $\\underline{F}(\\underline{x})=\\underline{x}$ and $V$ the cylinder, so\r\n    $$V=\\{\\underline{x}=\\underline{x}(\\rho,\\phi,z):0\\le\\rho\\le R,0\\le\\phi\\le 2\\pi,-h\\le z\\le h\\}$$\r\n    So $\\nabla\\cdot\\underline{F}=3$, hence\r\n    $$\\int_V\\nabla\\cdot\\underline{F}\\,\\mathrm dV=3\\int_V\\mathrm dV=6\\pi R^2h$$\r\n    As for the surface integral, we write $\\partial V=S_+\\cup S_-\\cup S$ where $S_+,S_-$ are the top and lower disks, and $S$ is the curved surface in between.\r\n    $$S=\\{R\\underline{e_\\rho}+z\\underline{e_z}:z\\in[-h,h],\\phi\\in [0,2\\pi]\\}$$\r\n    So $\\mathrm d\\underline{S}=\\underline{e_\\rho}R\\,\\mathrm d\\phi\\,\\mathrm dz$, hence by calculation,\r\n    $$\\int_S\\underline{F}\\cdot\\mathrm d\\underline{S}=4\\pi R^2h$$\r\n    Now $S_{\\pm}=\\{\\rho\\underline{e_\\rho}\\pm h\\underline{e_z}:\\rho\\in[0,R],\\phi\\in[0,2\\pi]\\}$.\r\n    We will also find that $\\mathrm d\\underline{S_\\pm}=\\pm\\underline{e_z}\\rho\\,\\mathrm d\\rho\\,\\mathrm d\\phi$.\r\n    $$\\int_{S_{\\pm}}\\underline{F}\\cdot\\mathrm d\\underline{S_{\\pm}}=\\pi R^2h$$\r\n    So adding them together does give $6\\pi R^2h$.\r\n\\end{example}\r\n\\begin{proposition}\r\n    If $\\underline{F}$ is continuously differentiable and for all closed surfaces $S$ we have\r\n    $$\\int_S\\underline{F}\\cdot\\mathrm d\\underline{S}=0$$\r\n    Then $\\nabla\\cdot\\underline{F}=0$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Assume that it is not zero, so WLOG we can take a point $\\underline{x_0}$ such that $\\nabla\\cdot\\underline{F}(\\underline{x_0})=\\epsilon>0$, then there is some $\\delta>0$ with $|\\underline{x}-\\underline{x_0}|<\\delta\\implies\\nabla\\cdot\\underline{F}(\\underline{x})>\\epsilon/2$.\r\n    Take the volume $V$ to be the ball $\\{\\underline{x}\\in\\mathbb R^3:|\\underline{x}-\\underline{x_0}|<\\delta\\}$ with boundary $\\partial V$, then\r\n    $$0=\\int_{\\partial V}\\underline{F}\\cdot\\mathrm d\\underline{S}=\\int_V\\nabla\\cdot\\underline{F}\\,\\mathrm dV>\\frac{\\epsilon}{2}\\operatorname{Volume}(V)>0$$\r\n    by Divergence Theorem.\r\n    Contradiction.\r\n\\end{proof}\r\n\\begin{example}\r\n    Let $V_\\epsilon$ be a volume contained inside a ball of radius $\\epsilon$ centered at $\\underline{x_0}$.\r\n    Then\r\n    \\begin{align*}\r\n        \\int_{\\partial V_\\epsilon}\\underline{F}\\cdot\\mathrm d\\underline{S}&=\\int_{V_\\epsilon}\\nabla\\cdot\\underline{F}\\,\\mathrm dV\\\\\r\n        &=\\int_{V_\\epsilon}\\nabla\\cdot\\underline{F}(\\underline{x_0})\\,\\mathrm dV+\\left( \\int_{V_\\epsilon}\\nabla\\cdot\\underline{F}\\,\\mathrm dV-\\int_{V_\\epsilon}\\nabla\\cdot\\underline{F}(\\underline{x_0})\\,\\mathrm dV \\right)\\\\\r\n        &=\\nabla\\cdot\\underline{F}\\operatorname{Volume}(V_\\epsilon)+\\left( \\int_{V_\\epsilon}\\nabla\\cdot\\underline{F}-\\nabla\\cdot\\underline{F}(\\underline{x_0})\\,\\mathrm dV \\right)\r\n    \\end{align*}\r\n    But as we did before,\r\n    \\begin{align*}\r\n        \\left| \\int_{V_\\epsilon}\\nabla\\cdot\\underline{F}-\\nabla\\cdot\\underline{F}(\\underline{x_0})\\,\\mathrm dV \\right|&\\le\\operatorname{Volume}(V_\\epsilon)\\sup_{\\underline{x}\\in V_\\epsilon}|\\nabla\\cdot\\underline{F}(\\underline{x})-\\nabla\\cdot\\underline{F}(\\underline{x_0})|\\\\\r\n        &=o(\\operatorname{Volume(V_\\epsilon)})\r\n    \\end{align*}\r\n    as $\\epsilon\\to 0^+$.\r\n    Hence\r\n    $$\\nabla\\cdot\\underline{F}(\\underline{x_0})=\\lim_{\\epsilon\\to0^+}\\frac{1}{\\operatorname{Volume}(V_\\epsilon)}\\int_{\\partial V_\\epsilon}\\underline{F}\\cdot\\mathrm d\\underline{S}$$\r\n    That is, $\\nabla\\cdot\\underline{F}$ measures the infinitesimal flux per unit volume.\r\n    Therefore $\\nabla\\cdot\\underline{F}(\\underline{x_0})>0$ means that the field is going out of $\\underline{x_0}$, and it being negative means that the field is going into $\\underline{x_0}$.\r\n    If it is zero at that point, then the field is incompressible there.\r\n\\end{example}\r\n\\begin{example}\r\n    1. Take again $\\underline{F}(\\underline{x})=\\underline{x}$ and $V_\\epsilon=\\{\\underline{x}:|\\underline{x}|<\\epsilon\\}$, then we calculate\r\n    \\begin{align*}\r\n        \\nabla\\cdot\\underline{F}(\\underline{0})&=\\lim_{\\epsilon\\to 0^+}\\frac{1}{\\operatorname{Volume}(V_\\epsilon)}\\int_{\\partial V_\\epsilon}\\underline{F}\\cdot\\mathrm d\\underline{S}\\\\\r\n        &=3\r\n    \\end{align*}\r\n    as desired.\\\\\r\n    2. Call equations of the form\r\n    $$\\frac{\\partial\\rho}{\\partial t}+\\nabla\\cdot\\underline{J}=0$$\r\n    as \\textit{conservation laws}.\r\n    We claim that if $|\\underline{J}|\\to 0$ as $|\\underline{x}|\\to\\infty$, then the charge\r\n    $$Q(t)=\\int_{\\mathbb R^3}\\rho(\\underline{x},t)\\,\\mathrm dV$$\r\n    remains constant.\r\n    We differentiate to get\r\n    \\begin{align*}\r\n        \\frac{\\mathrm dQ}{\\mathrm dt}&=\\int_{\\mathbb R^3}\\frac{\\partial\\rho}{\\partial t}\\,\\mathrm dV\\\\\r\n        &=-\\int_{\\mathbb R^3}\\nabla\\cdot\\underline{J}\\,\\mathrm dV\\\\\r\n        &=-\\lim_{R\\to\\infty}\\int_{|\\underline{x}|<R}\\nabla\\cdot\\underline{J}\\,\\mathrm dV\\\\\r\n        &=-\\lim_{R\\to\\infty}\\int_{|\\underline{x}|=R}\\underline{J}\\cdot\\mathrm d\\underline{S}\\\\\r\n        &=0\r\n    \\end{align*}\r\n    So $Q$ is constant.\r\n\\end{example}", "meta": {"hexsha": "bd5a6569b5b91e7c01c34b3d0ac54e75d06cfa25", "size": 5682, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/div.tex", "max_stars_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_stars_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/div.tex", "max_issues_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_issues_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/div.tex", "max_forks_repo_name": "david-bai-notes/IA-Vector-Calculus", "max_forks_repo_head_hexsha": "466dbf395800c80f263dbf32161d20a7c1092c5b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 71.025, "max_line_length": 279, "alphanum_fraction": 0.6592749032, "num_tokens": 2003, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7121360514431919}}
{"text": "\\section{RNG01: Random Number Generators -- 01}\n\n\\subsection*{DECSRC}\nThis is just a wrapper for the DEC SRC-supplied {\\tt Random.T.longreal}.\n\n\\subsection*{ran0}\nNR92, pg 278, describes Schrage's approximatrixion to Park and Miller's\nproposed {\\em Minimal Standard} generator. The basic approach is:\n\\begin{verbatim}\n     a) z = a*(z mod q) - r*(z div q)\n     b) If z <0 then z = z+m\n     c) To get back to 0.0 --> 1.0, result = float(z) / float(m)\n\\end{verbatim}\n     \n{\\tt mod} is tricky, because you have to do at least:\n\\begin{equation}\n  z \\bmod q = z - (z \\mbox{div} q)*q\n\\end{equation}\nAnd maybe deal with negatives.  I suspect M3's MOD function\nis fairly complex compared to a simple idiv.  So we ought to\ntake advantage of knowing z is positive, and do our own mod.\n\nNotice that z div q can be pulled out as a temp.:\n\\begin{eqnarray}\n     tmp & = & z \\mbox{div} q\\\\\n     z & = & a*(z - \\mbox{tmp}*q) - r*\\mbox{tmp}\n\\end{eqnarray}\n\nNext, remember that dividing by float(m) is more expensive than\nmultiplying by 1.0/float(m), which can be done once at\ninitialization:\n\\begin{verbatim}\n     Mrecip = 1.0 / float(m)\n     ...\n     result = float(z) * Mrecip\n\\end{verbatim}\n     \nNot too surprisingly, this is what NR92 uses.  To claim original\ncode, we can use one of the alternate sets of constants.\nWe'll use the first alternative.\n\nNR92 makes a point of telling us to not include the\nendpoints (0.0 and 1.0).  Thus there is a Min value and a\nMax value.  Min should be such that we don't get a 0.0 when\ncaptured in REAL64 format.  Min can be a few times bigger than EPS.\nMax is then that close to 1.0, or (1.0-Min), which can be precalculated.\n\n\\subsection*{ran1}\nFrom NR92.  The trick here is to use the ran0 stuff, but use that\nresult to access a shuffle table.  The shuffle table (per\nNR92, pg 281, fig 7.1.1) requires us to take the result\nmodulo the table size.  But as noted above, mod can be done\ninline.  Use that to get the shuffled value, and put the old\none in its place.\n\\begin{verbatim}\n     ndx:=z - (z div size)*size\n     z2:= table[ndx]\n     table[ndx]:=z\n\\end{verbatim}\n     \nBays-Durham further cooks the data by saving z2 and using it\nfor the ndx computation.  That means we have to save it and\nhave to initialize it.  NR92 initializes it with the first\ntable value.  Just to be different, we'll use the 3rd table\nvalue.  NR92 also warms up the generator with 8 throwaways.\nWe'll pass on that.\n\n\n\n", "meta": {"hexsha": "1dea1a0f063198e191a59c23b028e57ad8ec8095", "size": 2423, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "m3-libs/arithmetic/doc/rng01.tex", "max_stars_repo_name": "jaykrell/cm3", "max_stars_repo_head_hexsha": "2aae7d9342b8e26680f6419f9296450fae8cbd4b", "max_stars_repo_licenses": ["BSD-4-Clause-UC", "BSD-4-Clause", "BSD-3-Clause"], "max_stars_count": 105, "max_stars_repo_stars_event_min_datetime": "2015-03-02T16:58:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T07:17:49.000Z", "max_issues_repo_path": "m3-libs/arithmetic/doc/rng01.tex", "max_issues_repo_name": "jaykrell/cm3", "max_issues_repo_head_hexsha": "2aae7d9342b8e26680f6419f9296450fae8cbd4b", "max_issues_repo_licenses": ["BSD-4-Clause-UC", "BSD-4-Clause", "BSD-3-Clause"], "max_issues_count": 145, "max_issues_repo_issues_event_min_datetime": "2015-03-18T10:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T01:27:08.000Z", "max_forks_repo_path": "m3-libs/arithmetic/doc/rng01.tex", "max_forks_repo_name": "jaykrell/cm3", "max_forks_repo_head_hexsha": "2aae7d9342b8e26680f6419f9296450fae8cbd4b", "max_forks_repo_licenses": ["BSD-4-Clause-UC", "BSD-4-Clause", "BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-10T09:37:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T02:02:05.000Z", "avg_line_length": 34.6142857143, "max_line_length": 72, "alphanum_fraction": 0.6999587288, "num_tokens": 747, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515684, "lm_q2_score": 0.8459424411924674, "lm_q1q2_score": 0.7121360430944207}}
{"text": "% LaTeX source for ``Python for Informatics: Exploring Information''\n% Copyright (c)  2010-  Charles R. Severance, All Rights Reserved\n\n\\chapter{Conditional execution}\n\n\\section{Boolean expressions}\n\\index{boolean expression}\n\\index{expression!boolean}\n\\index{logical operator}\n\\index{operator!logical}\n\nA {\\bf boolean expression} is an expression that is either true\nor false.  The following examples use the \noperator {\\tt ==}, which compares two operands and produces\n{\\tt True} if they are equal and {\\tt False} otherwise:\n\n\\beforeverb\n\\begin{verbatim}\n>>> 5 == 5\nTrue\n>>> 5 == 6\nFalse\n\\end{verbatim}\n\\afterverb\n%\n{\\tt True} and {\\tt False} are special\nvalues that belong to the type {\\tt bool}; they are not strings:\n\n\\index{True special value}\n\\index{False special value}\n\\index{special value!True}\n\\index{special value!False}\n\\index{bool type}\n\\index{type!bool}\n\n\\beforeverb\n\\begin{verbatim}\n>>> type(True)\n<type 'bool'>\n>>> type(False)\n<type 'bool'>\n\\end{verbatim}\n\\afterverb\n%\nThe {\\tt ==} operator is one of the {\\bf comparison operators}; the\nothers are:\n\n\\beforeverb\n\\begin{verbatim}\n      x != y               # x is not equal to y\n      x > y                # x is greater than y\n      x < y                # x is less than y\n      x >= y               # x is greater than or equal to y\n      x <= y               # x is less than or equal to y\n      x is y               # x is the same as y\n      x is not y           # x is not the same as y\n\\end{verbatim}\n\\afterverb\n%\nAlthough these operations are probably familiar to you, the Python\nsymbols are different from the mathematical symbols for the same\noperations.  A common error\nis to use a single equal sign ({\\tt =}) instead of a double equal sign\n({\\tt ==}).  Remember that {\\tt =} is an assignment operator and\n{\\tt ==} is a comparison operator.   There is no such thing as\n{\\tt =<} or {\\tt =>}.\n\n\\index{comparison operator}\n\\index{operator!comparison}\n\n\n\\section {Logical operators}\n\\index{logical operator}\n\\index{operator!logical}\n\nThere are three {\\bf logical operators}: {\\tt and}, {\\tt\nor}, and {\\tt not}.  The semantics (meaning) of these operators is\nsimilar to their meaning in English.  For example,\n\n{\\tt x > 0 and x < 10} \n\nis true only if {\\tt x} is greater than 0\n\\emph{and} less than 10.\n\n\\index{and operator}\n\\index{or operator}\n\\index{not operator}\n\\index{operator!and}\n\\index{operator!or}\n\\index{operator!not}\n\n{\\tt n\\%2 == 0 or n\\%3 == 0} is true if \\emph{either} of the conditions\nis true, that is, if the number is divisible by 2 \\emph{or} 3.\n\nFinally, the {\\tt not} operator negates a boolean\nexpression, so {\\tt not (x > y)} is true if {\\tt x > y} is false;\nthat is, if {\\tt x} is less than or equal to {\\tt y}.\n\nStrictly speaking, the operands of the logical operators should be\nboolean expressions, but Python is not very strict.\nAny nonzero number is interpreted as ``true.''\n\n\\beforeverb\n\\begin{verbatim}\n>>> 17 and True\nTrue\n\\end{verbatim}\n\\afterverb\n%\nThis flexibility can be useful, but there are some subtleties to\nit that might be confusing.  You might want to avoid it until\nyou are sure you know what you are doing.\n\n\\section{Conditional execution}\n\\label{conditional execution}\n\n\\index{conditional statement}\n\\index{statement!conditional}\n\\index{if statement}\n\\index{statement!if}\n\\index{conditional execution}\n\nIn order to write useful programs, we almost always need the ability\nto check conditions and change the behavior of the program\naccordingly.  {\\bf Conditional statements} give us this ability.  The\nsimplest form is the {\\tt if} statement:\n\n\\beforeverb\n\\begin{verbatim}\nif x > 0 :\n    print 'x is positive'\n\\end{verbatim}\n\\afterverb\n%\nThe boolean expression after the {\\tt if} statement is\ncalled the {\\bf condition}.  We end the {\\tt if} \nstatement with a colon character (:) and the line(s) \nafter the if statement are indented.  \n\n\\beforefig\n\\centerline{\\includegraphics[height=1.75in]{figs2/if.eps}}\n\\afterfig\n\nIf the logical condition is true, then the indented\nstatement gets executed.  If the logical condition is \nfalse, the indented statement is skipped.\n\n\\index{condition}\n\\index{compound statement}\n\\index{statement!compound}\n\n{\\tt if} statements have the same structure as function definitions\nor {\\tt for} loops\\footnote{We will learn about functions in Chapter 4\nand loops in Chapter 5.}.The statement consists of a header line\nthat ends with the colon character (:) \nfollowed by an indented block.  Statements like this are\ncalled {\\bf compound statements} because they stretch \nacross more than one line.\n\nThere is no limit on the number of statements that can appear in\nthe body, but there must be at least one.\nOccasionally, it is useful to have a body with no statements (usually\nas a placekeeper for code you haven't written yet).  In that\ncase, you can use the {\\tt pass} statement, which does nothing.\n\n\\index{pass statement}\n\\index{statement!pass}\n\n\\beforeverb\n\\begin{verbatim}\nif x < 0 :\n    pass          # need to handle negative values!\n\\end{verbatim}\n\\afterverb\n%\nIf you enter an {\\tt if} statement in the Python interpreter, the prompt will change \nfrom three chevrons to three dots to indicate you are in the middle of a block of\nstatements, as shown below:\n\n\\beforeverb\n\\begin{verbatim}\n>>> x = 3\n>>> if x < 10:\n...    print 'Small'\n... \nSmall\n>>>\n\\end{verbatim}\n\\afterverb\n%\n\n\\section{Alternative execution}\n\\label{alternative execution}\n\n\\index{alternative execution}\n\\index{else keyword}\n\\index{keyword!else}\n\nA second form of the {\\tt if} statement is {\\bf alternative execution},\nin which there are two possibilities and the condition determines\nwhich one gets executed.  The syntax looks like this:\n\n\\beforeverb\n\\begin{verbatim}\nif x%2 == 0 :\n    print 'x is even'\nelse :\n    print 'x is odd'\n\\end{verbatim}\n\\afterverb\n%\nIf the remainder when {\\tt x} is divided by 2 is 0, then we\nknow that {\\tt x} is even, and the program displays a message to that\neffect.  If the condition is false, the second set of statements is\nexecuted.  \n\n\\beforefig\n\\centerline{\\includegraphics[height=1.75in]{figs2/if-else.eps}}\n\\afterfig\n\nSince the condition must either be true or false, exactly one of\nthe alternatives will be executed.  The alternatives are called\n{\\bf branches}, because they are branches in the flow of execution.\n\n\\index{branch}\n\n\n\n\\section{Chained conditionals}\n\\index{chained conditional}\n\\index{conditional!chained}\n\nSometimes there are more than two possibilities and we need more than\ntwo branches.  One way to express a computation like that is a {\\bf\nchained conditional}:\n\n\\beforeverb\n\\begin{verbatim}\nif x < y:\n    print 'x is less than y'\nelif x > y:\n    print 'x is greater than y'\nelse:\n    print 'x and y are equal'\n\\end{verbatim}\n\\afterverb\n%\n{\\tt elif} is an abbreviation of ``else if.''  Again, exactly one\nbranch will be executed.  \n\n\\beforefig\n\\centerline{\\includegraphics[height=3.00in]{figs2/elif.eps}}\n\\afterfig\n\nThere is no limit on the number of {\\tt\nelif} statements.  If there is an {\\tt else} clause, it has to be\nat the end, but there doesn't have to be one.\n\n\\index{elif keyword}\n\\index{keyword!elif}\n\n\n\\beforeverb\n\\begin{verbatim}\nif choice == 'a':\n    print 'Bad guess'\nelif choice == 'b':\n    print 'Good guess'\nelif choice == 'c':\n    print 'Close, but not correct'\n\\end{verbatim}\n\\afterverb\n%\nEach condition is checked in order.  If the first is false,\nthe next is checked, and so on.  If one of them is\ntrue, the corresponding branch executes, and the statement\nends.  Even if more than one condition is true, only the\nfirst true branch executes.  \n\n\n\\section{Nested conditionals}\n\\index{nested conditional}\n\\index{conditional!nested}\n\nOne conditional can also be nested within another.  We could have\nwritten the three-branch example like this:\n\n\\beforeverb\n\\begin{verbatim}\nif x == y:\n    print 'x and y are equal'\nelse:\n    if x < y:\n        print 'x is less than y'\n    else:\n        print 'x is greater than y'\n\\end{verbatim}\n\\afterverb\n%\nThe outer conditional contains two branches.  The\nfirst branch contains a simple statement.  The second branch\ncontains another {\\tt if} statement, which has two branches of its\nown.  Those two branches are both simple statements,\nalthough they could have been conditional statements as well.\n\n\\beforefig\n\\centerline{\\includegraphics[height=2.50in]{figs2/nested.eps}}\n\\afterfig\n\nAlthough the indentation of the statements makes the structure\napparent, {\\bf nested conditionals} become difficult to read very\nquickly. In general, it is a good idea to avoid them when you can.\n\nLogical operators often provide a way to simplify nested conditional\nstatements.  For example, we can rewrite the following code using a\nsingle conditional:\n\n\\beforeverb\n\\begin{verbatim}\nif 0 < x:\n    if x < 10:\n        print 'x is a positive single-digit number.'\n\\end{verbatim}\n\\afterverb\n%\nThe {\\tt print} statement is executed only if we make it past both\nconditionals, so we can get the same effect with the {\\tt and} operator:\n\n\\beforeverb\n\\begin{verbatim}\nif 0 < x and x < 10:\n    print 'x is a positive single-digit number.'\n\\end{verbatim}\n\\afterverb\n\n\n\\section{Catching exceptions using try and except}\n\\label{catch1}\n\nEarlier we saw a code segment where we used the \\verb\"raw_input\" and\n{\\tt int} functions to read and parse an integer number entered by\nthe user.  We also saw how treacherous doing this could be:\n\n\\beforeverb\n\\begin{verbatim}\n>>> speed = raw_input(prompt)\nWhat...is the airspeed velocity of an unladen swallow?\nWhat do you mean, an African or a European swallow?\n>>> int(speed)\nValueError: invalid literal for int()\n>>>\n\\end{verbatim}\n\\afterverb\n%\nWhen we are executing these statements in the Python interpreter, \nwe get a new prompt from the interpreter, think ``oops'', and move \non to our next statement.  \n\nHowever if you place this code in a \nPython script and this error occurs, your script immediately \nstops in its tracks with a traceback.  \nIt does not execute the following statement. \n\\index{traceback}\n\nHere is a sample program to convert a Fahrenheit temperature \nto a Celsius temperature:\n\\index{fahrenheit}\n\\index{celsius}\n\\index{temperature conversion}\n\n\\beforeverb\n\\begin{verbatim}\ninp = raw_input('Enter Fahrenheit Temperature:')\nfahr = float(inp)\ncel = (fahr - 32.0) * 5.0 / 9.0\nprint cel\n\\end{verbatim}\n\\afterverb\n%\nIf we execute this code and give it invalid input, it simply fails\nwith an unfriendly error message:\n\n\\beforeverb\n\\begin{verbatim}\npython fahren.py \nEnter Fahrenheit Temperature:72\n22.2222222222\n\npython fahren.py \nEnter Fahrenheit Temperature:fred\nTraceback (most recent call last):\n  File \"fahren.py\", line 2, in <module>\n    fahr = float(inp)\nValueError: invalid literal for float(): fred\n\\end{verbatim}\n\\afterverb\n%\nThere is a conditional execution structure built into \nPython to handle these types of expected and unexpected\nerrors called ``try / except''.  The idea of {\\tt try}\nand {\\tt except} is that you know that some sequence\nof instruction(s) may have a problem and you want to \nadd some statements to be executed if an error occurs.\nThese extra statements (the except block) are ignored\nif there is no error.\n\nYou can think of the {\\tt try} and {\\tt except} feature\nin Python as an ``insurance policy'' on a sequence of\nstatements.\n\nWe can rewrite our temperature converter as follows:\n\n\\beforeverb\n\\begin{verbatim}\ninp = raw_input('Enter Fahrenheit Temperature:')\ntry:\n    fahr = float(inp)\n    cel = (fahr - 32.0) * 5.0 / 9.0\n    print cel\nexcept:\n    print 'Please enter a number'\n\\end{verbatim}\n\\afterverb\n%\n\nPython starts by executing the \nsequence of statements in the \n{\\tt try} block.  If all goes\nwell, it skips the {\\tt except} block and proceeds.  If an\nexception occurs in the {\\tt try} block, \nPython jumps out of the {\\tt try} block and\nexecutes the sequence of statements in the {\\tt except} block.\n\n\\beforeverb\n\\begin{verbatim}\npython fahren2.py \nEnter Fahrenheit Temperature:72\n22.2222222222\n\npython fahren2.py \nEnter Fahrenheit Temperature:fred\nPlease enter a number\n\\end{verbatim}\n\\afterverb\n%\n\nHandling an exception with a {\\tt try} statement is called {\\bf\ncatching} an exception.  In this example, the {\\tt except} clause\nprints an error message.  In general,\ncatching an exception gives you a chance to fix the problem, or try\nagain, or at least end the program gracefully.\n\n\\section{Short-circuit evaluation of logical expressions}\n\\index{short circuit}\n\nWhen Python is processing a logical expression such as \n{\\tt x >= 2 and (x/y) > 2}, it evaluates the expression\nfrom left to right.  Because of the definition of {\\tt and},\nif {\\tt x} is less than 2, the expression {\\tt x >= 2} is \n{\\tt False} and so the whole expression is {\\tt False} regardless\nof whether {\\tt (x/y) > 2} evaluates to {\\tt True} or {\\tt False}.\n\nWhen Python detects that there is nothing to be gained by evaluating\nthe rest of a logical expression, it stops its evaluation and does\nnot do the computations in the rest of the logical expression.  \nWhen the evaluation of a logical expression stops because the overall\nvalue is already known, it is called {\\bf short-circuiting} \nthe evaluation.\n\n\\index{guardian pattern}\n\\index{pattern!guardian}\nWhile this may seem like a fine point, the short-circuit behavior\nleads to a clever technique called the {\\bf guardian pattern}.  \nConsider the following code sequence in the Python interpreter:\n\n\\beforeverb\n\\begin{verbatim}\n>>> x = 6 \n>>> y = 2\n>>> x >= 2 and (x/y) > 2\nTrue\n>>> x = 1 \n>>> y = 0\n>>> x >= 2 and (x/y) > 2\nFalse\n>>> x = 6\n>>> y = 0\n>>> x >= 2 and (x/y) > 2\nTraceback (most recent call last):\n  File \"<stdin>\", line 1, in <module>\nZeroDivisionError: integer division or modulo by zero\n>>> \n\\end{verbatim}\n\\afterverb\n%\nThe third calculation failed because Python was evaluating {\\tt (x/y)}\nand {\\tt y} was zero, which causes a runtime error.  But the second example\ndid \\emph{not} fail because the first part of the expression {\\tt x >= 2} \nevaluated to {\\tt False} so the {\\tt (x/y)} was not ever executed \ndue to the {\\bf short-circuit} rule and there was no error.\n\nWe can construct the logical expression to strategically place a {\\bf guard}\nevaluation just before the evaluation that might cause an error as follows:\n\n\\beforeverb\n\\begin{verbatim}\n>>> x = 1\n>>> y = 0\n>>> x >= 2 and y != 0 and (x/y) > 2\nFalse\n>>> x = 6 \n>>> y = 0\n>>> x >= 2 and y != 0 and (x/y) > 2\nFalse\n>>> x >= 2 and (x/y) > 2 and y != 0\nTraceback (most recent call last):\n  File \"<stdin>\", line 1, in <module>\nZeroDivisionError: integer division or modulo by zero\n>>>\n\\end{verbatim}\n\\afterverb\n%\nIn the first logical expression, {\\tt x >= 2} is {\\tt False} so the evaluation\nstops at the {\\tt and}.  In the second logical expression, {\\tt x >= 2} is {\\tt True}\nbut {\\tt y != 0} is {\\tt False} so we never reach {\\tt (x/y)}.\n\nIn the third logical expression, the {\\tt y != 0} is \\emph{after} the \n{\\tt (x/y) } calculation so the expression fails with an error.\n\nIn the second expression, we say that {\\tt y != 0} acts as a {\\bf guard}\nto insure that we only execute {\\tt (x/y)} if {\\tt y} is non-zero.\n\n\n\\section{Debugging}\n\\label{whitespace}\n\\index{debugging}\n\\index{traceback}\n\nThe traceback Python displays when an error occurs contains\na lot of information, but it can be overwhelming.  The most\nuseful parts are usually:\n\n\\begin{itemize}\n\n\\item What kind of error it was, and\n\n\\item Where it occurred.\n\n\\end{itemize}\n\nSyntax errors are usually easy to find, but there are a few\ngotchas.  Whitespace errors can be tricky because spaces and\ntabs are invisible and we are used to ignoring them.\n\n\\index{whitespace}\n\n\\beforeverb\n\\begin{verbatim}\n>>> x = 5\n>>>  y = 6\n  File \"<stdin>\", line 1\n    y = 6\n    ^\nSyntaxError: invalid syntax\n\\end{verbatim}\n\\afterverb\n%\nIn this example, the problem is that the second line is indented by\none space.  But the error message points to {\\tt y}, which is\nmisleading.  In general, error messages indicate where the problem was\ndiscovered, but the actual error might be earlier in the code,\nsometimes on a previous line.\n\n\\index{error!runtime}\n\\index{runtime error}\n\nThe same is true of runtime errors.  Suppose you are trying\nto compute a signal-to-noise ratio in decibels.  The formula\nis $SNR_{db} = 10 \\log_{10} (P_{signal} / P_{noise})$.  In Python,\nyou might write something like this:\n\n\\beforeverb\n\\begin{verbatim}\nimport math\nsignal_power = 9\nnoise_power = 10\nratio = signal_power / noise_power\ndecibels = 10 * math.log10(ratio)\nprint decibels\n\\end{verbatim}\n\\afterverb\n%\nBut when you run it, you get an error message\\footnote{In Python 3.0,\n  you no longer get an error message; the division operator performs\n  floating-point division even with integer operands.}:\n\n\\index{exception!OverflowError}\n\\index{OverflowError}\n\n\\beforeverb\n\\begin{verbatim}\nTraceback (most recent call last):\n  File \"snr.py\", line 5, in ?\n    decibels = 10 * math.log10(ratio)\nOverflowError: math range error\n\\end{verbatim}\n\\afterverb\n%\nThe error message indicates line 5, but there is nothing\nwrong with that line.  To find the real error, it might be\nuseful to print the value of {\\tt ratio}, which turns out to\nbe 0.  The problem is in line 4, because dividing two integers\ndoes floor division.  The solution is to represent signal power\nand noise power with floating-point values.\n\n\\index{floor division}\n\\index{division!floor}\n\nIn general, error messages tell you where the problem was discovered, \nbut that is often not where it was caused.\n\n\n\\section{Glossary}\n\n\\begin{description}\n\n\\item[body:] The sequence of statements within a compound statement.\n\\index{body}\n\n\\item[boolean expression:]  An expression whose value is either \n{\\tt True} or {\\tt False}.\n\\index{boolean expression}\n\\index{expression!boolean}\n\n\\item[branch:] One of the alternative sequences of statements in\na conditional statement.\n\\index{branch}\n\n\\item[chained conditional:]  A conditional statement with a series\nof alternative branches.\n\\index{chained conditional}\n\\index{conditional!chained}\n\n\\item[comparison operator:] One of the operators that compares\nits operands: {\\tt ==}, {\\tt !=}, {\\tt >}, {\\tt <}, {\\tt >=}, and {\\tt <=}.\n\n\\item[conditional statement:]  A statement that controls the flow of\nexecution depending on some condition.\n\\index{conditional statement}\n\\index{statement!conditional}\n\n\\item[condition:] The boolean expression in a conditional statement\nthat determines which branch is executed.\n\\index{condition}\n\n\\item[compound statement:]  A statement that consists of a header\nand a body.  The header ends with a colon (:).  The body is indented\nrelative to the header.\n\\index{compound statement}\n\n\\item[guardian pattern:] Where we construct a logical expression \nwith additional\ncomparisons to take advantage of the short-circuit behavior.\n\\index{guardian pattern}\n\\index{pattern!guardian}\n\n\\item[logical operator:] One of the operators that combines boolean\nexpressions: {\\tt and}, {\\tt or}, and {\\tt not}.\n\n\\item[nested conditional:]  A conditional statement that appears\nin one of the branches of another conditional statement.\n\\index{nested conditional}\n\\index{conditional!nested}\n\n\\item[traceback:]  A list of the functions that are executing,\nprinted when an exception occurs.\n\\index{traceback}\n\n\\item[short circuit:]  When Python is part-way through evaluating a \nlogical expression and stops the evaluation because Python \nknows the final value for the expression \nwithout needing to evaluate the rest of the expression.\n\\index{short circuit}\n\n\\end{description}\n\n\\section{Exercises}\n\n\\begin{ex}\nRewrite your pay computation to give the employee 1.5 \ntimes the hourly rate for \nhours worked above 40 hours.\n\n\\begin{verbatim}\nEnter Hours: 45\nEnter Rate: 10\nPay: 475.0\n\\end{verbatim}\n\\end{ex}\n\n\\begin{ex}\nRewrite your pay program using {\\tt try} and {\\tt except} \nso that your program handles non-numeric input gracefully\nby printing a message and exiting the program.\nThe following shows two executions of the program:\n\n\\begin{verbatim}\nEnter Hours: 20\nEnter Rate: nine\nError, please enter numeric input\n\nEnter Hours: forty\nError, please enter numeric input\n\\end{verbatim}\n\\end{ex}\n\n\\begin{ex}\nWrite a program to prompt for a score between 0.0 and 1.0.\nIf the score is out of range, print an error message.  If the score\nis between 0.0 and 1.0, print a grade using the following \ntable:\n\n\\begin{verbatim}\nScore   Grade\n>= 0.9     A\n>= 0.8     B\n>= 0.7     C\n>= 0.6     D\n< 0.6    F\n\nEnter score: 0.95\nA\n\nEnter score: perfect\nBad score\n\nEnter score: 10.0\nBad score\n\nEnter score: 0.75\nC\n\nEnter score: 0.5\nF\n\\end{verbatim}\n\nRun the program repeatedly as shown above to test the \nvarious different values for input.\n\\end{ex}\n\n", "meta": {"hexsha": "67ca3c672354f2ea13cd03a3c405d8e869b45acd", "size": 20578, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03-conditional.tex", "max_stars_repo_name": "chowdhary987/py4inf", "max_stars_repo_head_hexsha": "df8123c460cb10c1a8d96eb03439268d94432dda", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 41, "max_stars_repo_stars_event_min_datetime": "2015-02-27T22:13:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T15:37:29.000Z", "max_issues_repo_path": "03-conditional.tex", "max_issues_repo_name": "milog17/py4inf", "max_issues_repo_head_hexsha": "e68273927aeb0decbe6b24703de6c30494f0fc55", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-12-15T04:03:15.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-13T15:29:47.000Z", "max_forks_repo_path": "03-conditional.tex", "max_forks_repo_name": "milog17/py4inf", "max_forks_repo_head_hexsha": "e68273927aeb0decbe6b24703de6c30494f0fc55", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 45, "max_forks_repo_forks_event_min_datetime": "2015-01-03T17:26:02.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-09T16:06:04.000Z", "avg_line_length": 27.4007989348, "max_line_length": 85, "alphanum_fraction": 0.7315579745, "num_tokens": 5452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825635346563, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7121360362930822}}
{"text": "\\section{Model Description}\nThere two types of RW control torque interfaces, analog and digital. This modules assumes the RW is controlled through a set of voltages sent to the RW motors.  This module is developed in a general manner where a voltage deadband is assumed and the module can be run in a pure open-loop manner, or with a closed-loop torque tracking control mode.  Finally, if a RW availability message is present, then the RW is set to zero if the corresponding availability is set to {\\tt UNAVAILABLE}. \n\n\n\n\\begin{figure}[htb]\n\t\\centerline{\n\t\t\\includegraphics[]{Figures/us2V}\n\t}\n\t\\caption{Illustration of RW motor torque to voltage conversion}\n\t\\label{fig:us2V}\n\\end{figure}\n\\subsection{Open-loop voltage conversion}\nThis module requires the RW configuration message to contain the maximum RW motor torque values $u_{\\text{max}}$.  The user must specify the minimum and maximum output voltages as shown in Figure~\\ref{fig:us2V}.  The minimum voltage is a voltage below which the motor doesn't apply a torque, i.e. a deadzone.  \n\nLet the intermediate voltage value $V_{\\text{int}}$ as\n\\begin{equation}\n\\label{eq:rwMV:1}\nV_{\\text{int}} = \\frac{V_{\\text{max}} - V_{\\text{min}}}{u_{\\text{max}}} u_{s}\n\\end{equation}\nThe output voltage is thus determined through\n\\begin{equation}\nV = V_{\\text{int}} + V_{\\text{min}} *\\text{sgn}(V_{\\text{int}} )\n\\end{equation}\n\n\\subsection{RW Availability} \nIf the input message name {\\tt rwAvailInMsgName} is defined, then the RW availability message is read in. The voltage mapping is only performed if the individual RW availability setting is {\\tt AVAILABLE}.  If it is {\\tt UNAVAILABLE} then the output voltage is set to zero.  \n\n\n\\subsection{Closed-loop commanded torque tracking}\nThe requested RW motor torque is given by $u_{s}$.  The RW wheel speed $\\Omega$ is monitored to see if the actual torque being applied matches the commanded torque.  Let $J_{s}$ be the RW spin inertia about the RW spin axis $\\hat{\\bm g}_{s}$.   In the following development the motor torque equation is approximated as\n\\begin{equation}\nu_{s} = J_{s} \\dot\\Omega\n\\end{equation}\nwhere the assumption is made that the spacecraft angular accelerations are small compared to the RW angular accelerations.  The $\\dot\\Omega$ term is digitally evaluated using a backwards difference method:\n\\begin{equation}\n\\dot\\Omega_{n} = \\frac{\\Omega_{n} - \\Omega_{n-1}}{\\Delta t}\n\\end{equation}\nCare is taken that the old RW speed information $\\Omega_{n-1}$ is not used unless a history of wheel speeds is available, in particular, after a module reset.  Thus, the actual RW torque is evaluated as\n\\begin{equation}\nu_{n} = J_{s} \\dot\\Omega_{n}\n\\end{equation}\nFinally, the closed loop motor torque value is computed with a proportional feedback component as\n\\begin{equation}\nu_{s,CL} = u_{s} - K (u_{n} - u_{s})\n\\end{equation}\nwhere $K>0$ is a positive feedback gain value.  Finally, this $u_{s,CL}$ is fed to the voltage conversion process in Eq.~\\eqref{eq:rwMV:1}.  \n\n\\subsection{Saturation and Dead Band}\nIf the calculated voltage is outside of $\\pm V_{\\mathrm{max}}$, then the voltage is saturated at the $\\pm V_{\\mathrm{max}}$ value. Note, this corresponds to the reaction wheel torques being saturated. Similarly, if the calculated voltage is inside $\\pm V_{\\mathrm{min}}$, then the voltage is set to $\\pm V_{\\mathrm{min}}$. This simulates the dead band. If the $V_{\\mathrm{min}} = 0$, then there is no dead band.", "meta": {"hexsha": "3235efd1f93a06a2fad94391c841282d14189f3f", "size": 3426, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/fswAlgorithms/effectorInterfaces/rwMotorVoltage/_Documentation/secModelDescription.tex", "max_stars_repo_name": "ian-cooke/basilisk_mag", "max_stars_repo_head_hexsha": "a8b1e37c31c1287549d6fd4d71fcaa35b6fc3f14", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/fswAlgorithms/effectorInterfaces/rwMotorVoltage/_Documentation/secModelDescription.tex", "max_issues_repo_name": "ian-cooke/basilisk_mag", "max_issues_repo_head_hexsha": "a8b1e37c31c1287549d6fd4d71fcaa35b6fc3f14", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-03-13T20:52:22.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-13T20:52:22.000Z", "max_forks_repo_path": "src/fswAlgorithms/effectorInterfaces/rwMotorVoltage/_Documentation/secModelDescription.tex", "max_forks_repo_name": "ian-cooke/basilisk_mag", "max_forks_repo_head_hexsha": "a8b1e37c31c1287549d6fd4d71fcaa35b6fc3f14", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.52, "max_line_length": 489, "alphanum_fraction": 0.7498540572, "num_tokens": 926, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.7120918920374211}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 10}\n\nAssume that all the keys in a binary search tree are distinct.\nLet $x$ be a node in a binary search tree.\nShow that\n\\begin{enumerate}\n\\item If $a$ is an ancestor of $x$ and $a.key > x.key$, then for any descendant $d$ of $x$, we have $a.key > d.key$.\n\n\\item If $a$ is the successor of $x$, then $a$ is either an ancestor or descendant of $x$.\n\n\\item If the right subtree of $x$ is nonempty, then the successor of $x$ is just the leftmost node in the right subtree.\n\n\\item If the right subtree of $x$ is empty and if $x$ has a successor $y$ (i.e., $x$ is not the largest element in the tree), then $y$ is the lowest ancestor of $x$ whose left child is also an ancestor of $x$.\n\n\\item If $x$ has a right child, then the successor of $x$ does not have a left child.\n\n\\item Similarly, if $x$ has a left child, then the predecessor of $x$ does not have a right child.\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}\n\\item Property of the binary search trees suggest that the key of any node $d$ of a binary search tree is smaller than the key stored in its ancestors.\nTherefore, for any descendant $d$ of $x$, we have $x.key > d.key$.\nSince $a.key > x.key$, then $a.key > d.key$ would immediately follow.\n\\end{enumerate}\n", "meta": {"hexsha": "79107db6ba3a1d35f89b02ea93c2496dfd32ded8", "size": 1606, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q10.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q10.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q10.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 47.2352941176, "max_line_length": 209, "alphanum_fraction": 0.6587795766, "num_tokens": 428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7120673400544248}}
{"text": "\\subsection{The Boyer-Moore Majority-Vote Algorithm}\n\\label{subsec:boyer_moore}\n\nIn this section we demonstrate how to use Haskell as an advanced macro language\non top of Copilot by implementing an algorithm for solving the voting problem\nin Copilot.\n\nReliability in mission critical software is often improved by replicating\nthe same computations on separate hardware and by doing a vote in the end\nbased on the output of each system. The majority vote problem consists of\ndetermining if in a given list of votes there is a candidate that has more\nthan half of the votes, and if so, of finding this candidate.\n\nThe Boyer-Moore Majority Vote Algorithm \\cite{MooreBoyer82,Hesselink2005} solves\nthe problem in linear time and constant memory. It does so in two passes: The\nfirst pass chooses a candidate; and the second pass asserts that the\nfound candidate indeed holds a majority.\n\nThe algorithm for the first pass involves the sequence of elements we are interpreting,\na single element that represents the current majority, and a counter,\nwhich is initially set to zero. The algorithm is as follows:\n\\begin{itemize}\n\\item Initialize an element $m$ and a counter $i$ where $i=0$\n\\item For each element x of the input sequence: \n\t\\begin{itemize} \n\t\\item If $i=0$ then let $m=x$ and $i=1$\n\t\\item else if $m=x$ then increment $i$\n\t\\item else let $i = i-1$\n\t\\end{itemize}\n\\item Return $m$\n\\end{itemize}\n\nThis algorithm will produce an output even if there is no majority, which is why \nthe second pass is needed to verify that the output of the first pass is valid. \n\n\\begin{figure*}[!htb]\n\\begin{lstlisting}[language = Copilot, frame = none]\nmajorityPure :: Eq a => [a] -> a\nmajorityPure []     = error \"majorityPure: empty list!\"\nmajorityPure (x:xs) = majorityPure' xs x 1\n\nmajorityPure' []     can _   = can\nmajorityPure' (x:xs) can cnt =\n  let\n    can' = if cnt == 0 then x else can\n    cnt' = if cnt == 0 || x == can then succ cnt else pred cnt\n  in\n    majorityPure' xs can' cnt'\n\\end{lstlisting}\n\\caption{The first pass of the majority vote algorithm in Haskell.}\n\\label{fig:majority_pure}\n\\end{figure*}\n\n\\begin{figure*}[!htb]\n\\begin{lstlisting}[language = Copilot, frame = none]\naMajorityPure :: Eq a => [a] -> a -> Bool\naMajorityPure xs can = aMajorityPure' 0 xs can > length xs `div` 2\n\naMajorityPure' cnt []     _   = cnt\naMajorityPure' cnt (x:xs) can =\n  let\n    cnt' = if x == can then cnt+1 else cnt\n  in\n    aMajorityPure' cnt' xs can\n\\end{lstlisting}\n\\caption{The second pass of the majority vote algorithm in Haskell.}\n\\label{fig:amajority_pure}\n\\end{figure*}\n\nThe first pass can be implemented\nin Haskell as shown in Figure \\ref{fig:majority_pure}. The second pass, which\nsimply checks that a candidate has more than half of the votes, is\nstraightforward to implement and is shown in Figure \\ref{fig:amajority_pure}.\nE.g. applying {\\tt majorityPure} on the string {\\tt AAACCBBCCCBCC} yields {\\tt\n  C}, which {\\tt aMajorityPure} can confirm is in fact a majority.\n\n\\begin{figure*}[!htb]\n\\begin{lstlisting}[language = Copilot, frame = none]\nmajority :: (Eq a, Typed a) => [Stream a] -> Stream a\nmajority []     = error \"majority: empty list!\"\nmajority (x:xs) = majority' xs x 1\n\nmajority' []     can _   = can\nmajority' (x:xs) can cnt =\n  local\n    (if cnt == 0 then x else can) $\n      \\ can' ->\n        local (if cnt == 0 || x == can then cnt+1 else cnt-1) $\n          \\ cnt' ->\n            majority' xs can' cnt'\n\\end{lstlisting}\n\\caption{The first pass of the majority vote algorithm in Copilot.}\n\\label{fig:majority}\n\\end{figure*}\n\n\\begin{figure*}[!htb]\n\\begin{lstlisting}[language = Copilot, frame = none]\naMajority :: (Eq a, Typed a) => [Stream a] -> Stream a -> Stream Bool\naMajority xs can = aMajority' 0 xs can > (fromIntegral (length xs) `div` 2)\n\naMajority' cnt []     _   = cnt\naMajority' cnt (x:xs) can =\n  local\n    (if x == can then cnt+1 else cnt) $\n      \\ cnt' ->\n        aMajority' cnt' xs can\n\\end{lstlisting}\n\\caption{The second pass of the majority vote algorithm in Copilot.}\n\\label{fig:amajority}\n\\end{figure*}\n% $\n\nWhen implementing the majority vote algorithm for Copilot, we can use reuse\nalmost all of the code from the Haskell implementation. However, as functions\nin Copilot are macros that are expanded at compile time, care must\nbe taken in order to avoid an explosion in the code size. Hence, instead of\nusing Haskell's built-in \\emph{let}-blocks, we use explicit sharing, as\ndescribed in Section~\\ref{sec:explicit_sharing}. The Copilot implementations\nof the first and the second pass are given in Figure \\ref{fig:majority} and\nFigure \\ref{fig:amajority} respectively. Comparing the Haskell implementation\nwith the Copilot implementation, we see that the code is almost identical,\nexcept for the type signatures and the explicit sharing annotations.\n\n\n\n", "meta": {"hexsha": "a74a5f9507cf3a7b0207261e75377fd792e9f8df", "size": 4800, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TutorialAndDevGuide/Tutorial/MajVoteExample.tex", "max_stars_repo_name": "Copilot-Language/copilot-discussion", "max_stars_repo_head_hexsha": "caccad918b23dae991095344a845827ddccd6047", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2015-06-10T00:44:21.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-17T13:20:09.000Z", "max_issues_repo_path": "TutorialAndDevGuide/Tutorial/MajVoteExample.tex", "max_issues_repo_name": "Copilot-Language/copilot-discussion", "max_issues_repo_head_hexsha": "caccad918b23dae991095344a845827ddccd6047", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 30, "max_issues_repo_issues_event_min_datetime": "2019-04-01T20:24:19.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-07T22:34:17.000Z", "max_forks_repo_path": "TutorialAndDevGuide/Tutorial/MajVoteExample.tex", "max_forks_repo_name": "Copilot-Language/copilot-discussion", "max_forks_repo_head_hexsha": "caccad918b23dae991095344a845827ddccd6047", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.0952380952, "max_line_length": 87, "alphanum_fraction": 0.7222916667, "num_tokens": 1362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7120673321633668}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage{amssymb}\r\n\\usepackage{tikz}\r\n\\usetikzlibrary{positioning}\r\n\r\n\\definecolor {processblue}{cmyk}{0.96, 0, 0, 0}\r\n\r\n\\begin{document}\r\n\t\\section{Regular languages}\r\n\t\\subsection{Deterministic Finite Automaton}\r\n\t$\\Sigma$ a finite non-empty set called an \\textbf{alphabet}. Typically $\\Sigma = {0,1}$. \\\\\r\n\tA \\textbf{string} $w$ is a finite sequence of symbols -aka. alphabets) in $\\Sigma$. \\\\\r\n\tWe have:\r\n\t\\[\\epsilon := \\text{zero symbols} \\]\r\n\t\\[|w| = \\text{number of symbosl in } w \\]\r\n\t\\[\\Sigma^{k} := \\{ w : w \\text{ string over $\\Sigma$ } | \\; |w| = k \\} \\]\r\n\t\\[\\Sigma^{\\star} := \\bigcup_{k \\geq 0}{\\Sigma^{k}} \\text{, } \\Sigma^{} := \\bigcup_{k \\geq 1}{\\Sigma^{k}} \\]\r\n\tA \\textbf{language} $L$ over $\\Sigma$ is a subset of $\\Sigma^{\\star}$. The concatenation of $x=x_{1} \\dots x_{n}$ and $y=y_{1} \\dots y_{m}$ is\r\n\t\\[ xy = x_{1} \\dots x_{n} y_{1} \\dots y_{m} \\]\r\n\tNote : A language is called a \\textbf{problem} when strings are given some interpretation (e.g. view $w \\in \\Sigma^{\\star}$ as the binary representation of an integer).\r\n\t\\par\r\n\tAn \\textbf{automaton} is an abstract model of computation :\r\n\t\\begin{center}\r\n\t\\begin{tikzpicture}[-latex ,auto ,node distance =2 cm and 3cm ,on grid ,\r\n\tsemithick ,\r\n\tstate/.style ={ circle ,top color =white , bottom color = processblue!20 ,\r\n\t\tdraw,processblue , text=blue , minimum width = 1 cm}]\r\n\t\\node[state] (A) {$q_{1}$};\r\n\t\\node[state] (B) [right = of A]{$q_{2}$};\r\n\t\\node[state] (C) [right = of B]{$q_{3}$};\r\n\t\\draw[->, >=latex] (-2, 0) to (A); \r\n\t\\draw (B) circle(0.6);\r\n\t\\path (A) edge [loop above] node[above] {$0$} (A);\r\n\t\\path (A) edge node[above] {$1$} (B);\r\n\t\\path (B) edge [loop above] node(above) {$1$} (B);\r\n\t\\path (B) edge [bend left = 15] node(above) {$0$} (C);\r\n\t\\path (C) edge [bend left = 20] node(below) {$0,1$} (B);\r\n\t\\end{tikzpicture}\r\n\t\\end{center}\r\n\r\n\tTerminology:\r\n\t\\begin{itemize}\r\n\t\t\\item Transition diagram\r\n\t\t\\item Start arrow\r\n\t\t\\item Accept state\r\n\t\\end{itemize}\r\n\r\n\tIt reads an input $w=w_{1} \\dots w_{n}$ from left to right. It follows the arcs according to the $w_{i}$ starting at the start state. It accepts IFF it ends up in an accepting state after reading the whole input. It rejects otherwise.\r\n\t\\par \r\n\tFormally, a \\textbf{Deterministic Finite Automaton (DFA)} is a 5-tuple $\\mathcal{D}=(Q, \\sigma, \\delta, q_{0}, F)$ where:\r\n\t\\begin{itemize}\r\n\t\t\\item $Q$ is a finite set of states\r\n\t\t\\item $\\Sigma$ is an alphabet\r\n\t\t\\item $\\delta : Q \\times \\Sigma \\rightarrow Q$ is a transition function\r\n\t\t\\item $q_{0} \\in Q$ is the start state\r\n\t\t\\item $F \\subseteq Q$ is the set of the accepting states\r\n\t\\end{itemize}\r\n\t\\par \r\n\tWe define the \\textbf{Extended Transition Function} $\\hat{\\delta}$ of $D$ as follows :\r\n\t\\[ \\hat{\\delta}(q,\\epsilon) := q \\text{, } \\hat{\\delta}(q,xa) := \\delta (\\hat{\\delta}(q,x), a) \\]\r\n\tWe define the \\textbf{language of $D$} as follows :\r\n\t\\[\\mathcal{L}(\\mathcal{D}) := \\{ w \\in \\Sigma^{\\star} \\; | \\; \\hat{\\delta}(q_{0}, w) \\in F\\}\\]\r\n\tWe say that $D$ recognizes a language $L$ if $L = \\mathcal{L}(\\mathcal{D})$\r\n\tWe say $L \\subseteq \\Sigma^{\\star}$ is \\textbf{regular} if $L=\\mathcal{L}(\\mathcal{D}) \\text{ for some } D$\r\n\t\r\n\t\\subsection{Non-Deterministic Finite Automaton}\r\n\t\\textbf{Nondeterminism :} A generally useful concept in studying computation. It gives the power of being in several states at once.\r\n\tExample:\r\n\t\\begin{center}\r\n\t\t\\begin{tikzpicture}[-latex ,auto ,node distance =2 cm and 3cm ,on grid ,\r\n\t\tsemithick ,\r\n\t\tstate/.style ={ circle ,top color =white , bottom color = processblue!20 ,\r\n\t\t\tdraw,processblue , text=blue , minimum width = 1 cm}]\r\n\t\t\\node[state] (A) {$q_{0}$};\r\n\t\t\\node[state] (B) [right = of A] {$q_{1}$};\r\n\t\t\\node[state] (c) [right = of B] {$q_{2}$};\r\n\t\t\\draw (C) circle(0.6);\r\n\t\t\\path (A) edge node[above]{$0$} (B);\r\n\t\t\\path (B) edge node[above]{$1$} (C);\r\n\t\t\\path (A) [loop above] edge node[above]{$0, 1$} (A);\r\n\t\t\\end{tikzpicture}\r\n\t\\end{center}\r\n\tThis automaton accepts any string ending in $01$.\r\n\t\\par \r\n\tFormally : A \\textbf{NFA} is a 5-tuple $\\mathcal{N} = (Q, \\Sigma, \\delta, q_{0}, F)$ where $Q, \\Sigma,  q_{0}, F$ are defined as previously and $\\delta : Q \\times \\Sigma \\rightarrow \\mathcal{P}(Q)$ is the transition function.\r\n\t\\par \r\n\tThe extended transition function is:\r\n\t\\[ \\hat{\\delta}(q, \\epsilon) = \\{ q \\} \\text{, } \\hat{\\delta}(q, xa) = \\bigcup_{p \\in \\hat{\\delta}(q, x)}{\\delta(p, a)} \\]\r\n\tWe let:\r\n\t\\[ \\mathcal{L}(\\mathcal{N}) = \\{ w \\in \\Sigma^{\\star} \\; | \\; \\hat{\\delta}(q, xa) \\cap F \\neq \\emptyset \\} \\]\r\n\t\r\n\t\\subsection{Equivalence of DFAs and NFAs}\r\n\tNow, we want to find a way to convert an \\textbf{NFA} $\\mathcal{N}$ into a \\textbf{DFA}, ie. find some $\\mathcal{D}$ DFA such that $\\mathcal{L}(\\mathcal{N}) = \\mathcal{L}(\\mathcal{D})$ \\\\\r\n\t\\textbf{Construction :} \\\\\r\n\tLet $\\mathcal{N} = (Q_{\\mathcal{N}}, \\Sigma, \\delta_{\\mathcal{N}}, q_{0}, F )$. Consider $\\mathcal{D} = (Q_{\\mathcal{D}}, \\Sigma, \\delta_{\\mathcal{D}}, q_{0}, F )$ as follows :\r\n\t\\begin{itemize}\r\n\t\t\\item $Q_{\\mathcal{D}} = \\mathcal{P}(Q_{\\mathcal{N}})$\r\n\t\t\\item $\\delta_{\\mathcal{D}}$ so that : $\\forall a \\in \\Sigma, \\forall s \\in Q_{\\mathcal{D}}$, we have :\r\n\t\t\t\\[ \\delta_{\\mathcal{D}}(s, a) := \\bigcup_{p \\in S}{\\delta_{\\mathcal{N}}(p,a)} \\]\r\n\t\t\\item $F_{\\mathcal{D}} = \\{ s \\subseteq Q_{\\mathcal{N}} \\; | \\; s \\cap F_{\\mathcal{N}} \\neq \\emptyset \\}$\r\n\t\\end{itemize}\r\n\t\\textbf{Theorem :} These automaton denote the same language. $\\blacksquare$ \\newpage\r\n\t\\textbf{Note :} When converting, the number of states grows exponentially.\r\n\t\\subsection{$\\mathcal{E}$-NFA}\r\n\t\\textbf{Idea :} Allow transition without reading any input symbol (ie. reading $\\epsilon$). \\\\\r\n\t\\textbf{Example :} One can simply build an automaton denoting the union of two regular languages.\r\n\t\\begin{center}\r\n\t\t\\begin{tikzpicture}[-latex ,auto ,node distance =2 cm and 3cm ,on grid ,\r\n\t\tsemithick ,\r\n\t\tstate/.style ={ circle ,top color =white , bottom color = processblue!20 ,\r\n\t\t\tdraw,processblue , text=blue , minimum width = 1 cm}]\r\n\t\t\\node[state] (A) {$q_{0}$};\r\n\t\t\\node[state] (B) [above right = of A] {};\r\n\t\t\\node[state] (C) [right = of B] {};\r\n\t\t\\node[state] (D) [below right = of A] {};\r\n\t\t\\node[state] (E) [right = of D] {};\r\n\t\t\\draw (C) circle(0.6);\r\n\t\t\\draw (E) circle(0.6);\r\n\t\t\\path (A) edge node[above]{$\\epsilon$} (B);\r\n\t\t\\path (A) edge node[above]{$\\epsilon$} (D);\r\n\t\t\\draw[dashed] (B) -- (C);\r\n\t\t\\draw[dashed] (D) -- (E);\r\n\t\t\\end{tikzpicture}\r\n\t\\end{center}\r\n\t\\textbf{Definition :} $\\mathcal{E}-Closure(q)= \\{ q' \\in Q \\; | \\; q'$ can be reached from $q$ by following only $\\epsilon$-transitions over multiple transitions\\}. We can hence extend the definition of the extended transition function to $\\epsilon$-NFAs by having:\r\n\t\\[ \\hat{\\delta}(q, \\epsilon) := \\mathcal{E}-Closure(q) \\]\r\n\\end{document}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "meta": {"hexsha": "9b0c75a557b1104bdc97d5dcd2f674f7822608d3", "size": 6823, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Langages_formels/Cours LateX/Material.tex", "max_stars_repo_name": "cvt8/ens-courses", "max_stars_repo_head_hexsha": "027cb1f8d4e9dc3e165f71ee86af1e6b4e6af965", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-09-25T18:20:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T02:23:45.000Z", "max_issues_repo_path": "Langages_formels/Cours LateX/Material.tex", "max_issues_repo_name": "cvt8/ens-courses", "max_issues_repo_head_hexsha": "027cb1f8d4e9dc3e165f71ee86af1e6b4e6af965", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Langages_formels/Cours LateX/Material.tex", "max_forks_repo_name": "cvt8/ens-courses", "max_forks_repo_head_hexsha": "027cb1f8d4e9dc3e165f71ee86af1e6b4e6af965", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-09-25T11:24:09.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-25T11:42:10.000Z", "avg_line_length": 48.0492957746, "max_line_length": 267, "alphanum_fraction": 0.6182031365, "num_tokens": 2488, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7120673253612727}}
{"text": "\\chapter{Meromorphic functions}\n\\section{The second nicest functions on earth}\nIf holomorphic functions are like polynomials,\nthen \\emph{meromorphic} functions are like rational functions.\nBasically, a meromorphic function is a function of the form\n$ \\frac{A(z)}{B(z)} $\nwhere $A , B:  U \\to \\CC$ are holomorphic and $B$ is not zero.\nThe most important example of a meromorphic function is $\\frac 1z$.\n\nWe are going to see that meromorphic functions behave\nlike ``almost-holomorphic'' functions.\nSpecifically, a meromorphic function $A/B$ will be holomorphic at all points\nexcept the zeros of $B$ (called \\emph{poles}).\nBy the identity theorem, there cannot be too many zeros of $B$!\nSo meromorphic functions can be thought of as ``almost holomorphic''\n(like $\\frac 1z$, which is holomorphic everywhere but the origin).\nWe saw that\n\\[ \\frac{1}{2\\pi i} \\oint_{\\gamma} \\frac 1z \\; dz =  1 \\]\nfor $\\gamma(t) = e^{it}$ the unit circle.\nWe will extend our results on contours to such situations.\n\nIt turns out that, instead of just getting $\\oint_\\gamma f(z) \\; dz = 0$\nlike we did in the holomorphic case,\nthe contour integrals will actually be used to\n\\emph{count the number of poles} inside the loop $\\gamma$.\nIt's ridiculous, I know.\n\n\\section{Meromorphic functions}\n\\prototype{$\\frac 1z$, with a pole of order $1$ and residue $1$ at $z=0$.}\n\nLet $U$ be an open subset of $\\CC$ again.\n\\begin{definition}\n\tA function $f : U \\to \\CC$ is \\vocab{meromorphic}\n\tif there exists holomorphic functions $A, B \\colon U \\to \\CC$\n\twith $B$ not identically zero in any open neighborhood,\n\tand $f(z) = A(z)/B(z)$ whenever $B(z) \\ne 0$.\n\\end{definition}\nLet's see how this function $f$ behaves.\nIf $z \\in U$ has $B(z) \\neq 0$,\nthen in some small open neighborhood the function $B$ isn't zero\nat all, and thus $A/B$ is in fact \\emph{holomorphic};\nthus $f$ is holomorphic at $z$.\n(Concrete example: $\\frac 1z$ is holomorphic\nin any disk not containing $0$.)\n\nOn the other hand, suppose $p \\in U$ has $B(p) = 0$: without loss of generality, $p=0$\nto ease notation.\nBy using the Taylor series at $p=0$ we can put\n\\[ B(z) = c_k z^k + c_{k+1} z^{k+1} + \\dots \\]\nwith $c_k \\neq 0$\n(certainly some coefficient is nonzero since $B$ is not identically zero!).\nThen we can write\n\\[ \\frac{1}{B(z)} = \\frac{1}{z^k} \\cdot \\frac{1}{c_k + c_{k+1}z + \\dots}. \\]\nBut the fraction on the right is a\nholomorphic function in this open neighborhood!\nSo all that's happened is that we have an extra $z^{-k}$ kicking around.\n\n%We want to consider functions $f$ defined on all points in $U$\n%except for a set of ``isolated'' singularities;\n%for example, something like \\[ \\frac{1}{z(z+1)(z^2+1)} \\] which is defined\n%for all $z$ other than $z=0$, $z=-1$ and $z=i$.\n%Or even \\[ \\frac{1}{\\sin(2\\pi z)}, \\] which is defined at every $z$ which is \\emph{not} an integer.\n%% Even though there's infinitely many points, they are not really that close together.\n\nThis gives us an equivalent way of viewing meromorphic functions:\n\n\\begin{definition}\n\tLet $f : U \\to \\CC$ as usual.\n\tA \\vocab{meromorphic} function is a\n\tfunction which is holomorphic on $U$\n\texcept at an isolated set $S$ of points\n\t(meaning it is holomorphic as a function $U \\setminus S \\to \\CC$).\n\tFor each $p \\in S$, called a \\vocab{pole} of $f$,\n\tthe function $f$ must admit a \\vocab{Laurent series},\n\tmeaning that\n\t\\[\n\t\tf(z) =\n\t\t\\frac{c_{-m}}{(z-p)^m}\n\t\t+ \\frac{c_{-m+1}}{(z-p)^{m-1}}\n\t\t+ \\dots\n\t\t+ \\frac{c_{-1}}{z-p} + c_0 + c_1 (z-p) + \\dots\n\t\\]\n\tfor all $z$ in some open neighborhood of $p$,\n\tother than $z = p$.\n\tHere $m$ is a positive integer (and $c_{-m} \\neq 0$).\n\\end{definition}\nNote that the trailing end \\emph{must} terminate.\nBy ``isolated set'', I mean that we can draw\nopen neighborhoods around each pole in $S$,\nin such a way that no two open neighborhoods intersect.\n\n\\begin{example}\n\t[Example of a meromorphic function]\n\tConsider the function \\[ \\frac{z+1}{\\sin z}. \\]\n\tIt is meromorphic, because it is holomorphic everywhere except at the zeros of $\\sin z$.\n\tAt each of these points we can put a Laurent series: for example at $z=0$ we have\n\t\\begin{align*}\n\t\t\\frac{z+1}{\\sin z}\n\t\t&= (z+1) \\cdot \\frac{1}{z - \\frac{z^3}{3!} + \\frac{z^5}{5!} - \\dots} \\\\\n\t\t&= \\frac 1z \\cdot \\frac{z+1}{1 - \\left(%\n\t\t\t\\frac{z^2}{3!} - \\frac{z^4}{5!} + \\frac{z^6}{7!} - \\dots \\right)} \\\\\n\t\t&= \\frac 1z \\cdot (z+1) \\sum_{k \\ge 0} \\left( %\n\t\t\t\\frac{z^2}{3!}-\\frac{z^4}{5!}+\\frac{z^6}{7!}-\\dots \\right)^k.\n\t\\end{align*}\n\tIf we expand out the horrible sum (which I won't do),\n\tthen you get $\\frac 1z$ times a perfectly\n\tfine Taylor series, i.e.\\ a Laurent series.\n\\end{example}\n\n\\begin{abuse}\n\tWe'll often say something like\n\t``consider the function $f : \\CC \\to \\CC$\n\tby $z \\mapsto \\frac 1z$''.\n\tOf course this isn't completely correct,\n\tbecause $f$ doesn't have a value at $z=0$.\n\tIf I was going to be completely rigorous\n\tI would just set $f(0) = 2015$ or something and move on\n\twith life, but for all intents\n\tlet's just think of it as ``undefined at $z=0$''.\n\n\tWhy don't I just write $g : \\CC \\setminus \\{0\\} \\to \\CC$?\n\tThe reason I have to do this is that it's still important \n\tfor $f$ to remember it's ``trying'' to be holomorphic on $\\CC$,\n\teven if isn't assigned a value at $z=0$.\n\tAs a function $\\CC \\setminus \\{0\\} \\to \\CC$ the function $\\frac 1z$ is actually holomorphic.\n\\end{abuse}\n\n\\begin{remark}\n\tI have shown that any function $A(z)/B(z)$\n\thas this characterization with poles,\n\tbut an important result is\n\tthat the converse is true too:\n\tif $f : U \\setminus S \\to \\CC$ is holomorphic for some isolated set $S$,\n\tand moreover $f$ admits a Laurent series at each point in $S$,\n\tthen $f$ can be written as a rational quotient of holomorphic functions.\n\tI won't prove this here, but it is good to be aware of.\n\\end{remark}\n\n\\begin{definition}\n\tLet $p$ be a pole of a meromorphic function $f$, with Laurent series\n\t\\[ \n\t\tf(z) =\n\t\t\\frac{c_{-m}}{(z-p)^m}\n\t\t+ \\frac{c_{-m+1}}{(z-p)^{m-1}}\n\t\t+ \\dots\n\t\t+ \\frac{c_{-1}}{z-p} + c_0 + c_1 (z-p) + \\dots.\n\t\\]\n\tThe integer $m$ is called the \\vocab{order} of the pole.\n\tA pole of order $1$ is called a \\vocab{simple pole}.\n\t\n\tWe also give the coefficient $c_{-1}$ a name, the \\vocab{residue} of $f$ at $p$,\n\twhich we write $\\Res(f;p)$.\n\\end{definition}\n\nThe order of a pole tells you how ``bad'' the pole is.\nThe order of a pole is the ``opposite'' concept of the \\vocab{multiplicity} of a \\vocab{zero}.\nIf $f$ has a pole at zero, then its Taylor series near $z=0$ might look something like\n\\[ f(z) = \\frac{1}{z^5} + \\frac{8}{z^3} - \\frac{2}{z^2} + \\frac{4}{z} + 9 - 3z + 8z^2 + \\dots \\]\nand so $f$ has a pole of order five.\nBy analogy, if $g$ has a zero at $z=0$, it might look something like\n\\[ g(z) = 3z^3 + 2z^4 + 9z^5 + \\dots \\]\nand so $g$ has a zero of multiplicity three.\nThese orders are additive: $f(z) g(z)$ still has a pole of order $5-3=2$,\nbut $f(z)g(z)^2$ is completely patched now, and in fact has a \\vocab{simple zero} now\n(that is, a zero of degree $1$).\n\n\\begin{exercise}\n\tConvince yourself that orders are additive as described above.\n\t(This is obvious once you understand that you\n\tare multiplying Taylor/Laurent series.)\n\\end{exercise}\n\nMetaphorically, poles can be thought of as ``negative zeros''.\n\n\nWe can now give many more examples.\n\\begin{example}\n\t[Examples of meromorphic functions]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Any holomorphic function is a meromorphic function which happens to have no poles.\n\t\tStupid, yes.\n\t\t\\ii The function $\\CC \\to \\CC$ by $z \\mapsto 100z\\inv$ for $z \\neq 0$\n\t\tbut undefined at zero is a meromorphic function.\n\t\tIts only pole is at zero, which has order $1$ and residue $100$.\n\t\t\\ii The function $\\CC \\to \\CC$ by $z \\mapsto z^{-3} + z^2 + z^9$ is also a meromorphic function.\n\t\tIts only pole is at zero, and it has order $3$, and residue $0$.\n\t\t\\ii The function $\\CC \\to \\CC$ by $z \\mapsto \\frac{e^z}{z^2}$ is meromorphic,\n\t\twith the Laurent series at $z=0$ given by\n\t\t\\[\n\t\t\t\\frac{e^z}{z^2}\n\t\t\t= \\frac{1}{z^2} + \\frac{1}{z} + \\frac{1}{2} + \\frac{z}{6} + \\frac{z^2}{24} + \\frac{z^3}{120}\n\t\t\t+ \\dots.\n\t\t\\]\n\t\tHence the pole $z=0$ has order $2$ and residue $1$.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{example}\n\t[A rational meromorphic function]\n\tConsider the function $\\CC \\to \\CC$ given by\n\t\\begin{align*}\n\t\tz &\\mapsto \\frac{z^4+1}{z^2-1} = z^2 + 1 + \\frac{2}{(z-1)(z+1)} \\\\\n\t\t&= z^2 + 1 + \\frac1{z-1} \\cdot \\frac{1}{1+\\frac{z-1}{2}} \\\\\n\t\t&= \\frac{2}{z-1} + \\frac32 + \\frac94(z-1) + \\frac{7}{8}(z-1)^2 - \\dots\n\t\\end{align*}\n\tIt has a pole of order $1$ and residue $2$ at $z=1$.\n\t(It also has a pole of order $1$ at $z=-1$; you are invited to compute the residue.)\n\\end{example}\n\\begin{example}\n\t[Function with infinitely many poles]\n\tThe function $\\CC \\to \\CC$ by \\[ z \\mapsto \\frac{1}{\\sin(z)} \\]\n\thas infinitely many poles: the numbers $z = 2\\pi k$, where $k$ is an integer.\n\tLet's compute the Laurent series at just $z=0$:\n\t\\begin{align*}\n\t\t\\frac{1}{\\sin(2\\pi z)}\n\t\t&= \\frac{1}{\\frac{z}{1!} - \\frac{z^3}{3!} + \\frac{z^5}{5!} - \\dots} \\\\\n\t\t% &= \\frac{1/z}{\\frac{1}{1!} - \\frac{z^2}{3!} + \\frac{z^4}{5!} - \\dots} \\\\\n\t\t&= \\frac 1z \\cdot \\frac{1}{1 - \\left( \\frac{z^2}{3!} - \\frac{z^4}{5!} + \\dots \\right)} \\\\\n\t\t&= \\frac 1z \\sum_{k \\ge 0} \\left( \\frac{z^2}{3!} - \\frac{z^4}{5!} + \\dots \\right)^k.\n\t\\end{align*}\n\twhich is a Laurent series, though I have no clue what the coefficients are.\n\tYou can at least see the residue; the constant term of that huge sum is $1$,\n\tso the residue is $1$.\n\tAlso, the pole has order $1$.\n\\end{example}\n\nThe Laurent series, if it exists, is unique (as you might have guessed),\nand by our result on holomorphic functions it is actually valid for \\emph{any}\ndisk centered at $p$ (minus the point $p$).\nThe part $\\frac{c_{-1}}{z-p} + \\dots + \\frac{c_{-m}}{(z-p)^m}$ is called the \\vocab{principal part},\nand the rest of the series $c_0 + c_1(z-p) + \\dots$ is called the \\vocab{analytic part}.\n\n\n\n\\section{Winding numbers and the residue theorem}\nRecall that for a counterclockwise circle $\\gamma$ and a point $p$ inside it, we had\n\\[\n\t\\oint_{\\gamma} (z-p)^m \\; dz =\n\t\\begin{cases}\n\t\t0 & m \\neq -1 \\\\\n\t\t2\\pi i & m = -1\n\t\\end{cases}\n\\]\nwhere $m$ is an integer.\nOne can extend this result to in fact show that $\\oint_\\gamma (z-p)^m \\; dz = 0$\nfor \\emph{any} loop $\\gamma$, where $m \\neq -1$.\nSo we associate a special name for the nonzero value at $m=-1$.\n\\begin{definition}\n\tFor a point $p \\in \\CC$ and a loop $\\gamma$ not passing through it,\n\twe define the \\vocab{winding number}, denoted $\\Wind(p, \\gamma)$, by\n\t\\[\n\t\t\\Wind(\\gamma, p) = \\frac{1}{2\\pi i} \\oint_{\\gamma} \\frac{1}{z-p} \\; dz\n\t\\]\n\\end{definition}\nFor example, by our previous results we see that if $\\gamma$ is a circle, we have\n\\[\n\t\\Wind(\\text{circle}, p)\n\t=\n\t\\begin{cases}\n\t\t1 & \\text{$p$ inside the circle} \\\\\n\t\t0 & \\text{$p$ outside the circle}.\n\t\\end{cases}\n\\]\nIf you've read the chapter on fundamental groups, then this is just the fundamental group\nassociated to $\\CC \\setminus \\{p\\}$.\nIn particular, the winding number is always an integer (the proof of this requires the complex logarithm,\nso we omit it here).\nIn the simplest case the winding numbers are either $0$ or $1$.\n\\begin{definition}\n\tWe say a loop $\\gamma$ is \\vocab{regular} if $\\Wind(p, \\gamma) = 1$\n\tfor all points $p$ in the interior of $\\gamma$ (for example,\n\tif $\\gamma$ is a counterclockwise circle).\n\\end{definition}\n\nWith all these ingredients we get a stunning generalization of the Cauchy-Goursat theorem:\n\\begin{theorem}\n\t[Cauchy's residue theorem]\n\tLet $f : \\Omega \\to \\CC$ be meromorphic, where $\\Omega$ is simply connected.\n\tThen for any loop $\\gamma$ not passing through any of its poles, we have\n\t\\[\n\t\t\\frac{1}{2\\pi i} \\oint_{\\gamma} f(z) \\; dz\n\t\t= \\sum_{\\text{pole $p$}} \\Wind(\\gamma, p) \\Res(f; p).\n\t\\]\n\tIn particular, if $\\gamma$ is regular then the contour integral\n\tis the sum of all the residues, in the form\n\t\\[\n\t\t\\frac{1}{2\\pi i} \\oint_{\\gamma} f(z) \\; dz\n\t\t= \\sum_{\\substack{\\text{pole $p$} \\\\ \\text{inside $\\gamma$}}}  \\Res(f; p).\n\t\\]\n\\end{theorem}\n\\begin{ques}\n\tVerify that this result coincides\n\twith what you expect when you integrate $\\oint_\\gamma cz\\inv \\; dz$\n\tfor $\\gamma$ a counter-clockwise circle.\n\\end{ques}\n\nThe proof from here is not really too impressive -- the ``work'' was already\ndone in our statements about the winding number.\n\\begin{proof}\n\tLet the poles with nonzero winding number be $p_1, \\dots, p_k$ (the others do not affect the sum).\\footnote{\n\t\tTo show that there must be finitely many such poles: recall that all our contours $\\gamma : [a,b] \\to \\CC$\n\t\tare in fact bounded, so there is some big closed disk $D$ which contains all of $\\gamma$.\n\t\tThe poles outside $D$ thus have winding number zero.\n\t\tNow we cannot have infinitely many poles inside the disk $D$, for $D$ is compact and the\n\t\tset of poles is a closed and isolated set!}\n\tThen we can write $f$ in the form\n\t\\[\n\t\tf(z) = g(z) + \\sum_{i=1}^k P_i\\left( \\frac{1}{z-p_i} \\right)\n\t\\]\n\twhere $P_i\\left( \\frac{1}{z-p_i} \\right)$ is the principal part of the pole $p_i$.\n\t(For example, if $f(z) = \\frac{z^3-z+1}{z(z+1)}$ we would write $f(z) = (z-1) + \\frac1z - \\frac1{1+z}$.)\n\n\tThe point of doing so is that the function $g$ is holomorphic (we've removed all the ``bad'' parts), so \n\t\\[ \\oint_{\\gamma} g(z) \\; dz = 0 \\]\n\tby Cauchy-Goursat.\n\n\tOn the other hand, if $P_i(x) = c_1x + c_2x^2 + \\dots + c_d x^d$ then\n\t\\begin{align*}\n\t\t\\oint_{\\gamma} P_i\\left( \\frac{1}{z-p_i} \\right) \\; dz\n\t\t&=\n\t\t\\oint_{\\gamma} c_1 \\cdot \\left( \\frac{1}{z-p_i} \\right) \\; dz\n\t\t+ \\oint_{\\gamma} c_2 \\cdot \\left( \\frac{1}{z-p_i} \\right)^2 \\; dz\n\t\t+ \\dots \\\\\n\t\t&= c_1 \\cdot \\Wind(\\gamma, p_i) + 0 + 0 + \\dots \\\\\n\t\t&= \\Wind(\\gamma, p_i) \\Res(f; p_i).\n\t\\end{align*}\n\twhich gives the conclusion.\n\\end{proof}\n\n\\section{Argument principle}\nOne tricky application is as follows.\nGiven a polynomial $P(x) = (x-a_1)^{e_1}(x-a_2)^{e_2}\\dots(x-a_n)^{e_n}$, you might know that we have\n\\[ \\frac{P'(x)}{P(x)} = \\frac{e_1}{x-a_1} + \\frac{e_2}{x-a_2} + \\dots + \\frac{e_n}{x-a_n}. \\]\nThe quantity $P'/P$ is called the \\vocab{logarithmic derivative}, as it is the derivative of $\\log P$.\nThis trick allows us to convert zeros of $P$ into poles of $P'/P$ with order $1$;\nmoreover the residues of these poles are the multiplicities of the roots.\n\nIn an analogous fashion, we can obtain a similar result for any meromorphic function $f$.\n\\begin{proposition}\n\t[The logarithmic derivative]\n\tLet $f : U \\to \\CC$ be a meromorphic function.\n\tThen the logarithmic derivative $f'/f$ is meromorphic as a function from $U$ to $\\CC$;\n\tits zeros and poles are:\n\t\\begin{enumerate}[(i)]\n\t\t\\ii A pole at each zero of $f$ whose residue is the multiplicity, and\n\t\t\\ii A pole at each pole of $f$ whose residue is the negative of the pole's order.\n\t\\end{enumerate}\n\\end{proposition}\nAgain, you can almost think of a pole as a zero of negative multiplicity.\nThis spirit is exemplified below.\n\\begin{proof}\n\tDead easy with Taylor series.\n\tLet $a$ be a zero/pole of $f$, and WLOG set $a=0$ for convenience.\n\tWe take the Taylor series at zero to get\n\t\\[ f(z) = c_k z^k + c_{k+1} z^{k+1} + \\dots \\] % chktex 25\n\twhere $k < 0$ if $0$ is a pole and $k > 0$ if $0$ is a zero.\n\tTaking the derivative gives\n\t\\[ f'(z) = kc_k z^{k-1} + (k+1)c_{k+1}z^{k} + \\dots. \\]\n\tNow look at $f'/f$; with some computation, it equals\n\t\\[\n\t\t\\frac{f'(z)}{f(z)}\n\t\t= \\frac 1z \\frac{kc_k + (k+1)c_{k+1}z + \\dots}{c_k + c_{k+1}z + \\dots}.\n\t\\]\n\tSo we get a simple pole at $z=0$, with residue $k$.\n\\end{proof}\n\nUsing this trick you can determine the number of zeros and poles inside a regular closed curve,\nusing the so-called Argument Principle.\n\n\\begin{theorem}\n\t[Argument principle]\n\t\\label{thm:arg_principle}\n\tLet $\\gamma$ be a regular curve.\n\tSuppose $f : U \\to \\CC$ is meromorphic inside and on $\\gamma$, and\n\tnone of its zeros or poles lie on $\\gamma$.\n\tThen\n\t\\[\n\t\t\\frac{1}{2\\pi i} \\oint_\\gamma \\frac{f'}{f} \\; dz\n\t\t= Z - P\n\t\\]\n\twhere $Z$ is the number of zeros inside $\\gamma$ (counted with multiplicity)\n\tand $P$ is the number of poles inside $\\gamma$ (again with multiplicity).\n\\end{theorem}\n\\begin{proof}\n\tImmediate by applying Cauchy's residue theorem alongside the preceding proposition.\n\tIn fact you can generalize to any curve $\\gamma$ via the winding number:\n\tthe integral is\n\t\\[ \\frac{1}{2\\pi i} \\oint_\\gamma \\frac{f'}{f} \\; dz\n\t\t= \\sum_{\\text{zero $z$}} \\Wind(\\gamma,z)\n\t\t- \\sum_{\\text{pole $p$}} \\Wind(\\gamma,p) \\]\n\twhere the sums are with multiplicity.\n\\end{proof}\n\nThus the Argument Principle allows one to count zeros and poles inside any region of choice.\n\nComputers can use this to get information on functions whose values can be computed but whose behavior as a whole\nis hard to understand.\nSuppose you have a holomorphic function $f$, and you want to understand where its zeros are.\nThen just start picking various circles $\\gamma$.\nEven with machine rounding error, the integral will be close enough to the true integer value that\nwe can decide how many zeros are in any given circle.\nNumerical evidence for the Riemann Hypothesis (concerning the zeros of the Riemann zeta function)\ncan be obtained in this way.\n\n\\section{Philosophy: why are holomorphic functions so nice?}\nAll the fun we've had with holomorphic and meromorphic functions comes down to the fact that\ncomplex differentiability is such a strong requirement.\nIt's a small miracle that $\\CC$, which \\emph{a priori} looks only like $\\RR^2$,\nis in fact a field.\nMoreover, $\\RR^2$ has the nice property that one can draw nontrivial loops\n(it's also true for real functions that $\\int_a^a f \\; dx = 0$, but this is not so interesting!),\nand this makes the theory much more interesting.\n\nAs another piece of intuition from Siu\\footnote{Harvard professor.}:\nIf you try to get (left) differentiable functions over \\emph{quaternions},\nyou find yourself with just linear functions.\n\n\n\\section\\problemhead\n% Looman-Menchoff theorem?\n\n\\begin{problem}\n\t[Fundamental theorem of algebra]\n\tProve that if $f$ is a nonzero polynomial of degree $n$\n\tthen it has $n$ roots.\n\\end{problem}\n\n\\begin{dproblem}\n\t[Rouch\\'e's theorem]\n\tLet $f, g \\colon U \\to \\CC$ be holomorphic functions,\n\twhere $U$ contains the unit disk.\n\tSuppose that $\\left\\lvert f(z) \\right\\rvert > \\left\\lvert g(z) \\right\\rvert$\n\tfor all $z$ on the unit circle.\n\tProve that $f$ and $f+g$ have the same number of zeros\n\twhich lie strictly inside the unit circle (counting multiplicities).\n\\end{dproblem}\n\n\\begin{problem}\n\t[Wedge contour]\n\t\\gim\n\tFor each odd integer $n$, evaluate the improper integral\n\t\\[ \\int_0^\\infty \\frac{1}{1+x^{n}} \\; dx. \\]\n\t\\begin{hint}\n\t\tThis is called a ``wedge contour''.\n\t\tTry to integrate over a wedge shape\n\t\tconsisting of a sector of a circle of radius $r$,\n\t\twith central angle $\\frac{2\\pi}{n}$.\n\t\tTake the limit as $r \\to \\infty$ then.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tSee \\url{https://math.stackexchange.com/q/242514/229197},\n\t\twhich does it with $2019$ replaced by $3$.\n\t\\end{sol}\n\\end{problem}\n\t\n\\begin{problem}\n\t[Another contour]\n\t\\yod\n\tProve that the integral\n\t\\[ \\int_{-\\infty}^{\\infty} \\frac{\\cos x}{x^2+1} \\; dx \\]\n\tconverges and determine its value.\n\t\\begin{hint}\n\t\tIt's $\\lim_{a \\to \\infty} \\int_{-a}^{a} \\frac{\\cos x}{x^2+1} \\; dx$.\n\t\tFor each $a$, construct a semicircle.\n\t\\end{hint}\n\t% semicircle integral\n\t% \\quad \\text{ and } \\quad\n\t% \\int_{-\\infty}^{\\infty} \\frac{\\sin x}{x^2+1} \\; dx\n\\end{problem}\n\n\\begin{sproblem}\n\t\\gim\n\tLet $f \\colon U \\to \\CC$ be a nonconstant holomorphic function.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii (Open mapping theorem)\n\t\tProve that $f\\im(U)$ is open in $\\CC$.\\footnote{Thus\n\t\t\tthe image of \\emph{any}\n\t\t\topen set $V \\subseteq U$ is open in $\\CC$\n\t\t\t(by repeating the proof for $f \\restrict{V}$).}\n\t\t\\ii (Maximum modulus principle)\n\t\tShow that $\\left\\lvert f \\right\\rvert$\n\t\tcannot have a maximum over $U$.\n\t\tThat is, show that for any $z \\in U$,\n\t\tthere is some $z' \\in U$ such that\n\t\t$\\left\\lvert f(z) \\right\\rvert < \\left\\lvert f(z') \\right\\rvert$.\n\t\\end{enumerate}\n\t% http://en.wikipedia.org/wiki/Open_mapping_theorem_(complex_analysis)\n\\end{sproblem}\n", "meta": {"hexsha": "874e188c81c469a8ae768840b05b9ddfd6563690", "size": 19962, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/complex-ana/meromorphic.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/complex-ana/meromorphic.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/complex-ana/meromorphic.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.7387755102, "max_line_length": 113, "alphanum_fraction": 0.6719266607, "num_tokens": 6796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.7120673237481147}}
{"text": "%!TEX root = ceres-solver.tex\n\\chapter{Fitting a Curve to Data}\n\\label{chapter:tutorial:curvefitting}\nThe examples we have seen until now are simple optimization problems with no data. The original purpose of least squares and non-linear least squares analysis was fitting curves to data. It is only appropriate that we now consider an example of such a problem\\footnote{The full code and data for this example can be found in\n\\texttt{examples/data\\_fitting.cc}. It contains data generated by sampling the curve $y = e^{0.3x + 0.1}$ and adding Gaussian noise with standard deviation $\\sigma = 0.2$.}. Let us fit some data to the curve\n\\begin{equation}\n\ty = e^{mx + c}.\n\\end{equation}\n\nWe begin by defining a templated object to evaluate the residual. There will be a residual for each observation.\n\\begin{minted}[mathescape]{c++}\nclass ExponentialResidual {\n public:\n  ExponentialResidual(double x, double y)\n      : x_(x), y_(y) {}\n\n  template <typename T> bool operator()(const T* const m,\n                                        const T* const c,\n                                        T* residual) const {\n    residual[0] = T(y_) - exp(m[0] * T(x_) + c[0]);  // $y - e^{mx + c}$\n    return true;\n  }\n\n private:\n  // Observations for a sample.\n  const double x_;\n  const double y_;\n};\n\\end{minted}\n%\\caption{Templated functor to compute the residual for the exponential model fitting problem. Note that one instance of the functor is responsible for computing the residual for one observation.}\n%\\label{listing:exponentialresidual}\n%\\end{listing}\nAssuming the observations are in a $2n$ sized array called \\texttt{data}, the problem construction is a simple matter of creating a \\texttt{CostFunction} for every observation.\n\\clearpage\n\\begin{minted}{c++}\ndouble m = 0.0;\ndouble c = 0.0;\n\nProblem problem;\nfor (int i = 0; i < kNumObservations; ++i) {\n  problem.AddResidualBlock(\n      new AutoDiffCostFunction<ExponentialResidual, 1, 1, 1>(\n          new ExponentialResidual(data[2 * i], data[2 * i + 1])),\n      NULL,\n      &m, &c);\n}\n\\end{minted}\nCompiling and running \\texttt{data\\_fitting.cc} gives us\n\\begin{minted}{bash}\n 0: f: 1.211734e+02 d: 0.00e+00 g: 3.61e+02 h: 0.00e+00 rho: 0.00e+00 mu: 1.00e-04 li:  0\n 1: f: 1.211734e+02 d:-2.21e+03 g: 3.61e+02 h: 7.52e-01 rho:-1.87e+01 mu: 2.00e-04 li:  1\n 2: f: 1.211734e+02 d:-2.21e+03 g: 3.61e+02 h: 7.51e-01 rho:-1.86e+01 mu: 8.00e-04 li:  1\n 3: f: 1.211734e+02 d:-2.19e+03 g: 3.61e+02 h: 7.48e-01 rho:-1.85e+01 mu: 6.40e-03 li:  1\n 4: f: 1.211734e+02 d:-2.02e+03 g: 3.61e+02 h: 7.22e-01 rho:-1.70e+01 mu: 1.02e-01 li:  1\n 5: f: 1.211734e+02 d:-7.34e+02 g: 3.61e+02 h: 5.78e-01 rho:-6.32e+00 mu: 3.28e+00 li:  1\n 6: f: 3.306595e+01 d: 8.81e+01 g: 4.10e+02 h: 3.18e-01 rho: 1.37e+00 mu: 1.09e+00 li:  1\n 7: f: 6.426770e+00 d: 2.66e+01 g: 1.81e+02 h: 1.29e-01 rho: 1.10e+00 mu: 3.64e-01 li:  1\n 8: f: 3.344546e+00 d: 3.08e+00 g: 5.51e+01 h: 3.05e-02 rho: 1.03e+00 mu: 1.21e-01 li:  1\n 9: f: 1.987485e+00 d: 1.36e+00 g: 2.33e+01 h: 8.87e-02 rho: 9.94e-01 mu: 4.05e-02 li:  1\n10: f: 1.211585e+00 d: 7.76e-01 g: 8.22e+00 h: 1.05e-01 rho: 9.89e-01 mu: 1.35e-02 li:  1\n11: f: 1.063265e+00 d: 1.48e-01 g: 1.44e+00 h: 6.06e-02 rho: 9.97e-01 mu: 4.49e-03 li:  1\n12: f: 1.056795e+00 d: 6.47e-03 g: 1.18e-01 h: 1.47e-02 rho: 1.00e+00 mu: 1.50e-03 li:  1\n13: f: 1.056751e+00 d: 4.39e-05 g: 3.79e-03 h: 1.28e-03 rho: 1.00e+00 mu: 4.99e-04 li:  1\nCeres Solver Report: Iterations: 13, Initial cost: 1.211734e+02, \\\nFinal cost: 1.056751e+00, Termination: FUNCTION_TOLERANCE.\nInitial m: 0 c: 0\nFinal   m: 0.291861 c: 0.131439\n\\end{minted}\n\n\\begin{figure}[t]\n\t\\begin{center}\n\t\\includegraphics[width=\\textwidth]{fit.pdf}\n\t\\caption{Least squares data fitting to the curve $y = e^{0.3x + 0.1}$. Observations were generated by sampling this curve uniformly in the interval $x=(0,5)$ and adding Gaussian noise with $\\sigma = 0.2$.\\label{fig:exponential}}\n\\end{center}\n\\end{figure}\n\nStarting from parameter values $m = 0, c=0$ with an initial objective function value of $121.173$ Ceres finds a solution $m= 0.291861, c = 0.131439$ with an objective function value of $1.05675$. These values are a a bit different than the parameters of the original model $m=0.3, c= 0.1$, but this is expected. When reconstructing a curve from noisy data, we expect to see such deviations. Indeed, if you were to evaluate the objective function for $m=0.3, c=0.1$, the fit is worse with an objective function value of 1.082425. Figure~\\ref{fig:exponential} illustrates the fit.\n", "meta": {"hexsha": "07ccd488744d16127ac33635292f8b610100e5dc", "size": 4495, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/curvefitting.tex", "max_stars_repo_name": "pritasam/ceres-solver", "max_stars_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/curvefitting.tex", "max_issues_repo_name": "pritasam/ceres-solver", "max_issues_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/curvefitting.tex", "max_forks_repo_name": "pritasam/ceres-solver", "max_forks_repo_head_hexsha": "84093392391d17ab7af65a069aad4cbc86b2fba2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.6282051282, "max_line_length": 578, "alphanum_fraction": 0.6780867631, "num_tokens": 1795, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7120673237481147}}
{"text": "\n\\chapter{Forecasting}\n\\label{cha:forecasting}\n\n\\section{Prophet}\n\n\\subsection{Model overview}\n\nProphet is a statistical model developed by engineers at Facebook, which mainly fits its models in Stan and has been open-sourced with public APIs for python and R languages\\cite{fb_prophet}. It takes a regression-fitting approach to learn the time series and then forecasts by extrapolating such models and adding uncertainty in a Bayesian framework.\n\nIt uses a decomposable time series models \\cite{harvey1990estimation} with three components: trend, seasonality and holidays:\n\n\\begin{equation}\n\ty(t) = g(t) + s(t) + h(t) + \\varepsilon_t\n\\end{equation}\n\nWhere $g(t)$ is a trend function that models non-periodic fluctuations, $s(t)$ capture different kinds of seasonalities, and $h(t)$ represents special situations that could add irregularities to the other components and a random error term $\\varepsilon$.\n\nThe model is similar to a \\ac{gam}\\cite{hastie1987generalized}, which allows adding more and more components as needed. The seasonalities are modelled by an exponential smoothing approach\\cite{gardner1985exponential}.\n\n\\subsection{Trend model}\n\nProphet has two trend models: a saturating growth one, which is similar to model population growths in ecosystems \\cite{hutchinson1978introduction} and a piecewise model to give the flexibility of trend changes in determined learnt changepoints \\cite{fb_prophet}.\n\nThe basic saturated growth model is given by\n\n\\begin{align}\\label{eq:sat_growth}\n\t\tg(t) &= \\frac{C}{1 + \\exp\\left\\{ -k(t-m) \\right\\}}\n\\end{align}\n\n\\begin{equation*}\n\t\\text{Where} \\quad\n\tC: \\text{Carrying capacity}, \\quad\n\tk: \\text{Growth rate}, \\quad\n\tm: \\text{Offset parameter}\n\\end{equation*}\n\nNonetheless, the saturated growth model in (\\ref{eq:sat_growth}) does not meet all the usual requirements for some of the applications in which the saturating ceiling varies over time or in which the growth rate is not constant. Therefore, the model has been extended as follows.\n\nLet $s_j=1,\\ldots,S$ be the number of changepoints where the growth rate is allowed to change. Then, let $\\delta_j$ be the change rate that happens at $s_j$, and $\\bm{\\delta} \\in \\mathbb{R}^s$ the vector defined by all $\\delta_j$. This means that the growth rate at any time $t$ is the base rate $k$ plus all the adjustments up to $t$\n\n\\begin{equation}\n\tk + \\sum_{j=1}^{t < s_j}{\\delta_j}\n\\end{equation}\n\nThis can be rewriten as\n\n\\begin{align}\n\t\\begin{split}\n\t\tk &+ \\bm{a}(t)^T\\bm{\\delta} \\\\\n\t\t\\text{Where}\\quad a_j &= \n\t\t\\begin{cases*}\n\t\t\t1\\quad,\\quad\\text{if} \\quad t > s_j \\\\\n\t\t\t0\\quad,\\quad\\text{otherwise}\n\t\t\\end{cases*}\n\t\\end{split}\n\\end{align}\n\nAlso, when the growth rate is adjusted, the $m$ needs to be adjusted to ensure continuity. \n\n\\begin{equation}\n\t\\gamma_j = \\left( s_j - m - \\sum_{l<j}{\\gamma_l} \\right) \\left(1 - \\frac{k+\\sum_{l<j}{\\delta_l}}{k+\\sum_{l \\leq j}{\\delta_l}} \\right)\n\\end{equation}\n\nThen the linear trend with changepoints is defined by (\\ref{eq:piece_trend}) piecewise logistic growth model by (\\ref{eq:piece_satgrowth})\\cite{fb_prophet}.\n\n\\begin{equation}\\label{eq:piece_trend}\n\tg(t) = \\left( k + \\bm{a}(t)^T \\bm{\\delta} \\right)t + \\left( m + \\bm{a}(t)^T \\bm{\\gamma} \\right)\n\\end{equation}\n\n\\begin{equation}\\label{eq:piece_satgrowth}\n\tg(t) = \\frac{C(t)}\n\t        {1 + \\exp\\left\\{-(k+\\bm{a}(t)^T\\bm{\\delta})(t-(m+\\bm{a}(t)^T \\bm{\\gamma}))\\right\\}\n\t        }\n\\end{equation}\n\n\n\\subsection{Trend forecast}\n\n\nAfter the model has learnt from a history of $T$ time points with $S$ changepoints from which each point has a rate change $\\delta_j \\sim \\text{Laplace}(0,\\tau)$. \n\nThe trend will keep its last growth rate constant. The forecasts will be made by extrapolating the \\ac{gam} and simulating samples from Laplace$(0,\\lambda)$ where $\\lambda$ is a variance inferred from the data from the maximum likelihood estimate of the rate scale parameter (\\ref{eq:lambda_inferr}).\n\n\\begin{equation}\\label{eq:lambda_inferr}\n\t\\lambda = \\frac{1}{2} \\sum_{j=1}^{S}{|\\delta_j|}\n\\end{equation}\n\nOnce $\\lambda$ has been inferred the trend forecast and its uncertainty are obtained from\n\n\\begin{equation}\\label{eq:trend_forecast}\n\\forall j > T\\quad,\\quad \n\t\\begin{cases}\n\t\t\\delta_j = 0 \\quad \\text{w.p.} \\frac{T-S}{S} \\\\\n\t\t\\delta_j \\sim \\text{Laplace}(0,\\lambda) \\quad \\text{w.p.} \\frac{S}{T}\n\t\\end{cases}\n\\end{equation}\n\n\\pagebreak\n\\subsection{Seasonalities}\n\nBy using the \\ac{gam} flexibility, it is possible to add different seasonality periods, 365.25 or 7 for yearly and weekly seasonalities -in days measurements-, for example. These seasonalities are modelled by the use of Fourier series\\cite{harvey_fourier}.\n\nTherefore, for every given period $P$, it can be defined that.\n\n\\begin{equation}\n\ts(t) = \\sum_{n=1}^{N}\\left( a_n \\cos\\left( \\frac{2 \\pi n t}{P}\\right)  + b_n \\sin\\left( \\frac{2 \\pi n t}{P}\\right) \\right)\n\\end{equation}\n\nWhich has $2N$ params to learn:\n\n\\begin{equation*}\n\t\\bm{\\beta} = \\left[ a_1, b_1, a_2, b_2, \\ldots, a_N, b_N\\right]^T\n\\end{equation*}\n\nIn order to make the structures more manageable, it is defined a matrix of seasonalities comprised of the seasonal vectors for each time step.\n\n\\begin{equation}\n\t\\bm{X}(t) = \\left[ \\cos\\left( \\frac{2 \\pi (1) t}{P}\\right), \\sin\\left( \\frac{2 \\pi (1) t}{P}\\right), \\dots , \\cos\\left( \\frac{2 \\pi (N) t}{P}\\right), \\sin\\left( \\frac{2 \\pi (N) t}{P}\\right)  \\right]\n\\end{equation}\n\nThus, the seasonal component is expressed then as.\n\n\\begin{align}\n\ts(t) &= \\bm{X}(t) \\bm{\\beta} \\\\\n\t\\text{Where} \\quad \\beta &\\sim \\mathcal{N}(0, \\sigma^2)\n\\end{align}\n\n\n\\subsection{Holidays and festivities}\n\nProphet also allows considering non-seasonal events that can significantly affect the forecasts due to changes in peoples behaviour. Namely, Muslim Ramadan, Chinese New Year or the US's Super Bowl.\n\nIt is assumed that each holiday is independent. For each holiday $i$, $D_i$ is the set of past and future dates of it. \n\nSame as seasonalities, a regressors matrix is generated indicating whether the time $t$ happens during holiday $i$ and a parameter $\\kappa_i$ to model its influence in the forecast.\n\n\\begin{align}\n\tZ(t) &=  \\left[   \\bm{1}(t \\in D_1), \\ldots, \\bm{1}(t \\in D_L) \\right] \\\\\n\t\\therefore \\quad h(t) &= Z(t)\\bm{\\kappa} \\\\\n\t\\bm{\\kappa} &\\sim \\mathcal{N}(0,\\nu^2)\n\\end{align}\n\nFor practical cases, importing the holidays' dates can be done using the python-holidays open-source package \\cite{Holidays}, for which an extract of available Swedish holidays is shown in Table \\ref{table:sv_holidays}.\n\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{|c|c|}\n\t\t\\hline\n\t\t\\textbf{Date} & \\textbf{Holiday} \\\\\n\t\t\\hline\n\t\t2021-01-01 &Nyårsdagen \\\\\n\t\t2021-01-06 &Trettondedag jul \\\\\n\t\t2021-04-02 &Långfredagen \\\\\n\t\t2021-04-04 &Påskdagen, Söndag \\\\\n\t\t2021-04-05 &Annandag påsk \\\\\n\t\t2021-05-01 &Första maj \\\\\n\t\t2021-05-13 &Kristi himmelsfärdsdag \\\\\n\t\t2021-05-23 &Pingstdagen, Söndag \\\\\n\t\t2021-06-06 &Sveriges nationaldag, Söndag \\\\\n\t\t2021-06-25 &Midsommarafton \\\\\n\t\t2021-06-26 &Midsommardagen \\\\\n\t\t2021-11-06 &Alla helgons dag \\\\\n\t\t2021-12-24 &Julafton \\\\\n\t\t2021-12-25 &Juldagen \\\\\n\t\t2021-12-26 &Annandag jul, Söndag \\\\\n\t\t2021-12-31 &Nyårsafton \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{Results for Swedish holidays in 2021 from \\texttt{python-holidays}}\n\t\\label{table:sv_holidays}\n\\end{table}\n\nIt is possible also to include other parameters to extend the holiday to the neighbouring days. For more details, the reader can further investigate in \\cite{fb_prophet}.\n\n\\subsection{Model fitting}\n\nThe seasonality and holiday components are then merged in a matrix $\\bm{X}$ and the changepoints $\\bm{a}(t)$, in a matrix $\\bm{A}$. Then the model is expressed using Stan\\cite{carpenter2017stan} as is shown in figure \\ref{alg:stan}.\n\n\\begin{figure}[H]\n\\begin{lstlisting}\n// Priors\nk ~ normal(0, 5);\nm ~ normal(0, 5);\nepsilon ~ normal(0, 0.5);\ndelta ~ double_exponential(0, tau);\nbeta ~ normal(0, sigma);\n\n// Logistic likelihood\ny ~ normal(C ./ (1 + exp(-(k + A * delta) .* (t - (m + A * gamma)))) + X * beta, epsilon);\n\n// Linear likelihood\ny ~ normal((k + A * delta) .* t + (m + A * gamma) + X * beta, sigma);\n\\end{lstlisting}\n\\caption{Prophet Stan model.}\n\\label{alg:stan}\n\\end{figure}\n\nWhere \\texttt{tau} and \\texttt{sigma} are used to control the regularization levels.\n\nAnother handy feature that allows using \\acp{gam} is to plot each component on its own, which allows the analyst to spot abnormalities when debugging a model. These plots will be shown and explained in the following sections.\n\n\\pagebreak\n\\subsection{Experiments}\n\nThe average \\ac{psu} load signal shown in Figure \\ref{fig:forecast_experiment_signal} has been chosen to run the following experiments. It is not a particularly easy signal since it contains some severe outliers in the first days that turned the power to almost zero, and at the end, the average power consumption seems to decrease.\n\nIt is necessary to notice that in every forecasting model, the longer the prediction horizon is, the more uncertainty and thus the lower performance. For this experiment, it has been decided to leave the last 10\\% of data for testing purposes.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.6\\linewidth]{forecast_experiment_signal}\n\t\\caption{Signal used for the forecasting experiments}\n\t\\label{fig:forecast_experiment_signal}\n\\end{figure}\n\nIn the following sections it is going to be shown first a pure univariate approach and later it will be added more exogenous regressors to improve the predictions. The models will be evaluated by using the following scores.\n\n\\subsubsection*{Coefficient of determination}\n\nThe coefficient of determination $R^2$ is a measure of how many variance of $\\hat{y}$ is explained by the variance in $y$ in a linear regression context. It is compared against the considered \\emph{worst possible linear approximation} which corresponds to the samples mean.\n\nIt is said that $R^2$ has values $[0,1]$, where $0$ corresponds to the worst linear model and 1 a perfect approximation. \n\nAlthought the current application is not a linear regression case, $R^2$ is still considered a valuable score to compare predictor performances, nonetheless, as the linearity assumption is not met, its values would reside in $(-\\infty, 1]$ where 0 still being the mean value, but it is no longer considered the worst possible fit.\n\n\\begin{equation}\\label{eq:rsq}\nR^2 = 1 - \\frac{\\sum_{i}{(y_i - \\hat{y}_i)^2}}{\\sum_{i}{(y_i - \\bar{y}_i)^2}}\n\\end{equation}\n\n\n\\subsubsection*{Mean absolute error}\n\nIt measures, in absolute terms, the deviations from the true values. \\ac{mae} is preferred, given its interpretability, over \\ac{rmse} \\cite{MAE}.\n\n\\begin{equation}\\label{eq:mae}\n\\text{MAE}\t= \\frac{1}{N} \\sum_{i=1}^{N}{ \\left| y_i - \\hat{y}_i \\right| }\n\\end{equation}\n\n\n\\subsubsection*{Mean out-of-bounds error}\n\nAs result of the fitting process, prophet's output is comprised by the mean prediction $\\hat{y}_t$ and also its lower and upper boundaries for a given confidence value when constructing the predictor object which defaults at $80\\%$ \n\nLet then the \\ac{obe} be the out-of-the-confidence-bands error defined by (\\ref{eq:obe}) where $\\Delta \\hat{y}_t$ is the computed confidence interval half-magnitude for the time $t$. Then the \\ac{mobe} can be obtained by taking the mean of these values to obtain an overall performance score as in (\\ref{eq:mobe}). \n\n\\begin{align}\n\\text{OBE}_i &= \\bm{\\min} \\Big\\{ \\big| y_i - (\\hat{y}_i - \\Delta\\hat{y}_i) \\big| , \\big\t| y_i - (\\hat{y}_i + \\Delta\\hat{y}_i) \\big| \\Big\\} \\label{eq:obe} \\\\\n\\text{MOBE} &= \\frac{1}{N} \\sum_{i=1}^{N}{ \\text{OBE}_i }\\label{eq:mobe}\n\\end{align}\n\n\\subsection{Univariate model implementation}\n\nIn the figure \\ref{fig:prophet_uni_split} is shown the complete results of training and testing for a univariate prophet model.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.6\\linewidth]{prophet_uni_split}\n\t\\caption{Training, test and predictions from univariate Prophet}\n\t\\label{fig:prophet_uni_split}\n\\end{figure}\n\n\\subsubsection*{Training fitting}\n\nIn training is obtained a very poor $R^2$ value, which from the plot in figure \\ref{fig:prophet_uni_fitting} can be expected, since $\\hat{y}$ looks like mostly an average of the seasonal components. Nonetheless, if it is considered that predicting an interval is acceptable, then the \\ac{mobe} shows a very good result. \n\nIt can also be observed that the trend component did not overfit to the outliers.\n\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{|c|c|}\n\t\t\\hline\n\t\t\\ac{mae} \t& 2.20 \\\\\n\t\t$R^2$ \t\t& 0.11 \\\\\n\t\t\\ac{mobe} \t& 0.08 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{Univariate prophet training scores}\n\t\\label{table:prophet_uni_train_scores}\n\\end{table}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.6\\linewidth]{prophet_uni_fitting}\n\t\\caption{Training fitting from univariate prophet}\n\t\\label{fig:prophet_uni_fitting}\n\\end{figure}\n\n\\subsubsection*{Model learnt components}\n\nIn figure \\ref{fig:prophet_uni_components} it is shown the learnt approximation of every component in the \\ac{gam}. Although the trend did not overfit to the outliers, still learnt that there is a break point and changed the piecewise trend.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{prophet_uni_components}\n\t\\caption{Learnt components from univariate prophet}\n\t\\label{fig:prophet_uni_components}\n\\end{figure}\n\n\\pagebreak\n\\subsubsection*{Test predictions}\n\nWhen it comes to the predictions performance, the $R^2$ shows even worse results. The \\ac{mobe} is also high since the trend component was not able to foresee the decreasing in the middle of the test set as shown in figure \\ref{fig:prophet_uni_preds}. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.6\\linewidth]{prophet_uni_preds}\n\t\\caption{Test predictions from univariate Prophet}\n\t\\label{fig:prophet_uni_preds}\n\\end{figure}\n\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{|c|c|}\n\t\t\\hline\n\t\t\\ac{mae} \t& 2.12 \\\\\n\t\t$R^2$ \t\t& -0.33 \\\\\n\t\t\\ac{mobe} \t& 0.25 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{Univariate prophet prediction performance}\n\t\\label{table:prophet_uni_test_scores}\n\\end{table}\n\n\n\n\n\\subsubsection*{Residual analysis}\n\nThe residuals in the training set still show somehow resembles the original data pattern. This could be interpreted that there is still patterns to learn from data, i.e., this model is not complete. \n\n\\begin{figure}[hptb]\n\t\\begin{subfigure}{.47\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{prophet_train_res_time}\n\t\t\\caption{Residuals from train fit}\n\t\t\\label{fig:prophet_train_res_time}\n\t\\end{subfigure}%\n\t\\hfill\n\t\\begin{subfigure}{.47\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{prophet_test_res_time}\n\t\t\\caption{Residuals from test predictions}\n\t\t\\label{fig:prophet_test_res_time}\n\t\\end{subfigure}\n\t\\caption{Univariate prophet residuals}\n\t\\label{fig:prophet_res_time}\n\\end{figure}\n\nFurthermore, if the joint distributions for $y$ and $\\hat{y}$ are plotted, it can be seen how the outlier in the training set was not learnt and how the approximation becomes erratic in the test set.\n\n\\begin{figure}[hptb]\n\t\\begin{subfigure}{.47\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{prophet_train_res_joint}\n\t\t\\caption{Train}\n\t\t\\label{fig:prophet_train_res_joint}\n\t\\end{subfigure}%\n\t\\hfill\n\t\\begin{subfigure}{.47\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{prophet_test_res_joint}\n\t\t\\caption{Test}\n\t\t\\label{fig:prophet_test_res_joint}\n\t\\end{subfigure}\n\t\\caption{Univariate prophet joint distributions of $y$ and $\\hat{y}$}\n\t\\label{fig:prophet_res_joint}\n\\end{figure}\n\n\n\\subsection{Implementation using exogenous regressors}\n\nTo fully exploit the flexibility of \\acp{gam}, prophet's API allows defining custom regressors, which in the current work will be called exogenous variables as a resemblance of SARIMAX models. These variables are the ones explained in chapter \\ref{cha:data_analysis}.\n\n\n\n\\subsubsection*{Model learnt components}\n\nThe model components now show the additive factor of all the exogenous regressors, which seems to contain the information not learnt by the univariate training residuals. \n\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{|c|c|}\n\t\t\\hline\n\t\t\\ac{mae} \t& 0.55 \\\\\n\t\t$R^2$ \t\t& 0.83 \\\\\n\t\t\\ac{mobe} \t& 0.10 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{Multivariate prophet training scores}\n\t\\label{table:prophet_multi_train_scores}\n\\end{table}\n\nThe $R^2$ score has considerably improved. Nonetheless, the other scores have become worse. The interpretation of this decline could be that the confidence band is now narrower than the univariate model. Thus, being out of the confidence band is now likely than before.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{prophet_multi_components}\n\t\\caption{Learnt components from multivariate prophet}\n\t\\label{fig:prophet_multi_components}\n\\end{figure}\n\n\n\n\\subsubsection*{Test predictions}\n\nThe results of the predictions have notoriously improved in this case. The $R^2$ value is close to 0.9, which for such a complex signal shows how powerful is the model. \n\nThe \\ac{mobe} has even decreased in the test set, this could be due to training outliers that still being difficult to approximate without overfitting the trend component. \n\n \n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{|c|c|}\n\t\t\\hline\n\t\t\\ac{mae} \t& 0.52 \\\\\n\t\t$R^2$ \t\t& 0.88 \\\\\n\t\t\\ac{mobe} \t& 0.05 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{Multivariate prophet prediction performance}\n\t\\label{table:prophet_multi_test_scores}\n\\end{table}\n\n\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.6\\linewidth]{prophet_multi_preds}\n\t\\caption{Test predictions from multivariate prophet}\n\t\\label{fig:prophet_multi_preds}\n\\end{figure}\n\n\n\n\n\\subsubsection*{Residual analysis}\n\nThe residuals now show that the patterns have been better learnt than in the univariate case.\n\n\\begin{figure}[hptb]\n\t\\begin{subfigure}{.47\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{prophet_train_res_time_multi}\n\t\t\\caption{Train}\n\t\t\\label{fig:prophet_train_res_time_multi}\n\t\\end{subfigure}%\n\t\\hfill\n\t\\begin{subfigure}{.47\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{prophet_test_res_time_multi}\n\t\t\\caption{Test}\n\t\t\\label{fig:prophet_test_res_time_multi}\n\t\\end{subfigure}\n\t\\caption{Multivariate prophet residuals}\n\t\\label{fig:prophet_res_time_multi}\n\\end{figure}\n\nThe joint distributions for $y$ and $\\hat{y}$ now shows that the model is better approximating the signal. \n\n\\begin{figure}[hptb]\n\t\\begin{subfigure}{.47\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{prophet_train_res_joint_multi}\n\t\t\\caption{Train}\n\t\t\\label{fig:prophet_train_res_joint_multi}\n\t\\end{subfigure}%\n\t\\hfill\n\t\\begin{subfigure}{.47\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{prophet_test_res_joint_multi}\n\t\t\\caption{Test}\n\t\t\\label{fig:prophet_test_res_joint_multi}\n\t\\end{subfigure}\n\t\\caption{Multivariate prophet joint distributions of $y$ and $\\hat{y}$}\n\t\\label{fig:prophet_res_joint_multi}\n\\end{figure}\n\n%\n%\\pagebreak\n%\\section{Boosted random forests}\n%\n%\n%\\noindent\\fbox{\n%\t\\parbox{\\textwidth}\n%\t{\n%\t\tDraft acknowledgement:\\\\\n%\t\t\n%\t\tThe following models are still work in progress and last implementation has a bug to be fixed. \n%\t\t\n%\t\tIf time is not enough we may decide to drop this part for final report\n%\t}\n%}\n%\n%\\subsection{Model overview}\n%\n%\\noindent\\fbox{\n%\t\\parbox{\\textwidth}\n%\t{\n%\t\tDraft acknowledgement:\\\\\n%\t\tXGBoost regressor theory\n%\t}\n%}\n%\n%\\subsection{Regression approach}\n%\n%\\begin{equation}\n%\t\\label{xgb_reg}\n%\ty_{t+1} = \\sum_{t=1}^{N}{\\beta_t \\cdot x_{t_i}}\n%\\end{equation}\n%\n%\\begin{figure}[H]\n%\t\\centering\n%\t\\includegraphics[width=0.6\\linewidth]{xgb_reg_overall}\n%\t\\caption{XGBoost overall performance}\n%\t\\label{fig:xgb_reg_overall}\n%\\end{figure}\n%\n%\\subsubsection*{Training fitting}\n%\n%\\begin{figure}[H]\n%\t\\centering\n%\t\\includegraphics[width=0.6\\linewidth]{xgb_reg_train}\n%\t\\caption{XGBoost train performance}\n%\t\\label{fig:xgb_reg_train}\n%\\end{figure}\n%\n%\\begin{table}[H]\n%\t\\centering\n%\t\\begin{tabular}{|c|c|}\n%\t\t\\hline\n%\t\t\\ac{mae} \t& 0.04 \\\\\n%\t\t$R^2$ \t\t& 1.00 \\\\\n%\t\t\\hline\n%\t\\end{tabular}\n%\t\\caption{XGBoost regressor train scores}\n%\t\\label{table:xgb_reg_train_scores}\n%\\end{table}\n%\n%\\subsubsection*{Test predictions}\n%\n%\\begin{figure}[H]\n%\t\\centering\n%\t\\includegraphics[width=0.6\\linewidth]{xgb_reg_test}\n%\t\\caption{XGBoost test performance}\n%\t\\label{fig:xgb_reg_test}\n%\\end{figure}\n%\n%\\begin{table}[H]\n%\t\\centering\n%\t\\begin{tabular}{|c|c|}\n%\t\t\\hline\n%\t\t\\ac{mae} \t& 0.44 \\\\\n%\t\t$R^2$ \t\t& 0.93 \\\\\n%\t\t\\hline\n%\t\\end{tabular}\n%\t\\caption{XGBoost regressor prediction performance}\n%\t\\label{table:xgb_reg_test_scores}\n%\\end{table}\n%\n%\n%\\subsubsection*{Residual analysis}\n%\n%\\begin{figure}[hptb]\n%\t\\begin{subfigure}{.47\\textwidth}\n%\t\t\\includegraphics[width=\\textwidth]{xgb_reg_res_train}\n%\t\t\\caption{Train}\n%\t\t\\label{fig:xgb_reg_res_train}\n%\t\\end{subfigure}%\n%\t\\hfill\n%\t\\begin{subfigure}{.47\\textwidth}\n%\t\t\\includegraphics[width=\\textwidth]{xgb_reg_res_test}\n%\t\t\\caption{Test}\n%\t\t\\label{fig:xgb_reg_res_test}\n%\t\\end{subfigure}\n%\t\\caption{XGBoost regression residuals}\n%\t\\label{fig:xgb_reg_res}\n%\\end{figure}\n%\n%\\begin{figure}[hptb]\n%\t\\begin{subfigure}{.47\\textwidth}\n%\t\t\\includegraphics[width=\\textwidth]{xgb_reg_joint_train}\n%\t\t\\caption{Train}\n%\t\t\\label{fig:xgb_reg_joint_train}\n%\t\\end{subfigure}%\n%\t\\hfill\n%\t\\begin{subfigure}{.47\\textwidth}\n%\t\t\\includegraphics[width=\\textwidth]{xgb_reg_joint_test}\n%\t\t\\caption{Test}\n%\t\t\\label{fig:xgb_reg_joint_test}\n%\t\\end{subfigure}\n%\t\\caption{XGBoost regression joint distributions of $y$ and $\\hat{y}$}\n%\t\\label{fig:xgb_reg_joint}\n%\\end{figure}\n%\n%\\pagebreak\n%\\subsection{Including autoregressive components}\n%\n%Nonetheless, the function \\ref{xgb_reg}, despite being trained to predict the next $y$ sample, still having only a regressive nature, i.e., no autoregressive components have been used to also learn from previous outputs. Thus, the function can be extended to:\n%\n%\\begin{equation}\n%\t\\label{xgb_ar}\n%\ty_{t} = \\sum_{i=1}^{N}{\\beta_i \\cdot x_{{t-1}_i}} + \\sum_{l=1}^{L}{\\phi_l \\cdot y_{t-l}}\n%\\end{equation}  \n%\n%Where $N$ is the amount of features and  $L$ corresponds to the amount of lags under consideration.\n%\n%\\subsubsection*{Provisional results}\n%\n%\\noindent\\fbox{\n%\t\\parbox{\\textwidth}\n%\t{\n%\t\tDraft acknowledgement:\\\\\n%\t\tThis section has a bug, which fixing will be resumed as soon as the report draft is delivered\n%\t}\n%}\n%\n%\\begin{figure}[H]\n%\t\\centering\n%\t\\includegraphics[width=0.6\\linewidth]{xgb_ar_test}\n%\t\\caption{XGBoost with autoregressive components test performance}\n%\t\\label{fig:xgb_ar_test}\n%\\end{figure}\n%\n%\\begin{figure}[hptb]\n%\t\\begin{subfigure}{.47\\textwidth}\n%\t\t\\includegraphics[width=\\textwidth]{xgb_ar_joint_train}\n%\t\t\\caption{Train}\n%\t\t\\label{fig:xgb_ar_joint_train}\n%\t\\end{subfigure}%\n%\t\\hfill\n%\t\\begin{subfigure}{.47\\textwidth}\n%\t\t\\includegraphics[width=\\textwidth]{xgb_ar_joint_test}\n%\t\t\\caption{Test}\n%\t\t\\label{fig:xgb_ar_joint_test}\n%\t\\end{subfigure}\n%\t\\caption{XGBoost with autoregressive components joint distributions of $y$ and $\\hat{y}$}\n%\t\\label{fig:xgb_ar_joint}\n%\\end{figure}\n", "meta": {"hexsha": "f96981018abcf3598a925c367d3e482d3922b2b8", "size": 22874, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/forecasting.tex", "max_stars_repo_name": "agustinvalencia/MasterThesis", "max_stars_repo_head_hexsha": "25e3b4689264647bd1418f249de7a5272234008a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sections/forecasting.tex", "max_issues_repo_name": "agustinvalencia/MasterThesis", "max_issues_repo_head_hexsha": "25e3b4689264647bd1418f249de7a5272234008a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/forecasting.tex", "max_forks_repo_name": "agustinvalencia/MasterThesis", "max_forks_repo_head_hexsha": "25e3b4689264647bd1418f249de7a5272234008a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.1930379747, "max_line_length": 351, "alphanum_fraction": 0.7345020547, "num_tokens": 7147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7120673201723361}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n        \\section{Curvature}\n        We wish to construct a mathematical way to encode the ``amount\" which a given curve curves, so that we may distinguish straighter curves from more tightly winding curves.\n\n        The velocity vector \\(\\vec{v}\\) of a vector valued function \\(\\vec{r}\\) is tangent to the curve which \\(\\vec{r}\\) describes, so this notion of curvature must be related to the rate of change of \\(\\vec{v}\\), as the curvature is highest when the velocity vector changes rapidly. One issue is that parameterizations are generally not unique, but our definition of curvature should be independent of any particular parameterization, and thus an intrinsic property of the curve. To do this, we normalize \\(\\vec{v}\\) to unit length, so that the speed with which we traverse the curve is irrelevant to the curvature.\n        \\begin{theorem}{}{}\n                Consider a smooth curve parameterized by \\(\\vec{r}(t)\\). Prove that \\(|\\vec{r}|=a\\) is constant if and only if \\(\\vec{v}\\perp\\vec{r}\\) for all \\(t\\).\n                \\tcblower\n                \\(\\vec{r}\\cdot\\vec{r}=|\\vec{r}|^2=a^2\\), which is constant if and only if \\(\\frac{d}{dt}\\vec{r}\\cdot\\vec{r}=0\\), but\n                \\[\n                \\frac{d}{dt}\\vec{r}\\cdot\\vec{r}=\\vec{r}'\\cdot\\vec{r}+\\vec{r}\\cdot\\vec{r}'=\\vec{v}\\cdot\\vec{r}+\\vec{r}\\cdot\\vec{v}=2\\vec{v}\\cdot\\vec{r}\n                \\]\n                so \\(|\\vec{r}(t)|=a\\) is constant if and only if \\(\\vec{v}\\cdot\\vec{r}=0\\), and thus \\(\\vec{v}\\perp\\vec{r}\\).\n        \\end{theorem}\n        \\begin{definition}{Unit Tangent Vector}{}\n                Assuming that \\(\\vec{r}(t)\\) is smooth, so that \\(\\vec{r}'(t)\\neq\\vec{0}\\), we define the \\emph{unit tangent vector}\n                \\[\n                \\vec{T}(t)=\\frac{\\vec{r}'(t)}{|\\vec{r}'(t)|}\n                \\]\n                which is always tangent to \\(\\vec{r}(t)\\), and has unit length \\(|\\vec{T}|=1\\), so the unit tangent vector does not depend on parameterization, except for orientation.\n\n                The unit tangent vector may also be defined in terms of the arc length parameterization. By noting that because the arc length parameterization has constant unit speed, we have\n                \\[\n                \\vec{T}(s)=\\frac{\\frac{d\\vec{r}}{ds}}{\\left|\\frac{d\\vec{r}}{ds}\\right|}=\\frac{d\\vec{r}}{ds}\n                \\]\n        \\end{definition}\n        \\begin{definition}{Curvature}{}\n                We define the \\emph{curvature} \\(\\kappa\\) of a curve in terms of the unit tangest vector as\n                \\[\n                \\kappa = \\left| \\frac{d\\vec{T}}{ds}\\right|\n                \\]\n                using the arc length parameterization so that the curvature is independent of any particular parameterization.\n        \\end{definition}\n        One difficulty with this definition is that it requires us to find the arc length parameterization to solve for the curvature, but finding the arc length parameterization of even simple curves may be difficult or impossible. Therefore, to compute \\(\\kappa\\), we use the chain rule, noting that \\(\\frac{ds}{dt}=|\\vec{r}'(t)|\\), so we may compute the curvature of a curve using\n        \\[\n        \\kappa = \\left|\\frac{d\\vec{T}}{dt}\\frac{dt}{ds}\\right|=\\frac{|\\vec{T}'(t)|}{|\\vec{r}'(t)|}\n        \\]\n        \\begin{example}{}{}\n                Consider a straight line parameterized by \\(\\vec{r}(t)=\\vec{r}_0+\\vec{v}t\\). Show that this curve has \\(\\kappa=0\\).\n                \\tcblower\n                First, we find \\(\\vec{r}'(t)=\\vec{v}\\), so \\(|\\vec{r}'(t)|=|\\vec{v}|\\), which gives us\n                \\[\n                \\vec{T}=\\frac{\\vec{v}}{|\\vec{v}|}\n                \\]\n                but since \\(\\vec{v}\\) is constant, we have\n                \\[\n                \\vec{T}'=0\n                \\]\n                and consequently \\(\\kappa=0\\).\n        \\end{example}\n        \\begin{example}{}{}\n                Consider a circle parameterized by \\(\\vec{r}(t)=a\\cos(t)\\i+a\\sin{t}\\j\\). Find its curvature.\n                \\tcblower\n                First, we find\n                \\[\n                \\vec{r}'(t)=-a\\sin{t}\\i+a\\cos{t}\\j\n                \\]\n                so\n                \\[\n                |\\vec{r}'(t)|=\\sqrt{a^2\\sin^2{t}+a^2\\cos^2{t}}=\\sqrt{a^2}=a\n                \\]\n                which gives us\n                \\[\n                \\vec{T}(t)=\\frac{\\vec{r}'(t)}{a}=-\\sin{t}\\i+\\cos{t}\\j\n                \\]\n                and\n                \\[\n                \\vec{T}'(t)=-\\cos{t}\\i-\\sin{t}\\j\n                \\]\n                which means that \\(|\\vec{T}'(t)|=1\\), so\n                \\[\n                \\kappa = \\frac{|\\vec{T}'(t)|}{|\\vec{r}'(t)|} = \\frac{1}{a}\n                \\]\n        \\end{example}\n        \\begin{example}{}{}\n                Consider a helix parameterized by \\(\\vec{r}(t)=a\\cos{t}\\i+a\\sin{t}\\j+bt\\k\\). Find its curvature.\n                \\tcblower\n                First, we find\n                \\[\n                \\vec{r}'(t)=-a\\sin{t}\\i+a\\cos{t}\\j+b\\k\n                \\]\n                so\n                \\[\n                |\\vec{r}'(t)|=\\sqrt{a^2+b^2}\n                \\]\n                which gives us\n                \\[\n                \\vec{T}(t)=\\frac{1}{\\sqrt{a^2+b^2}}\\vec{r}'(t)\n                \\]\n                and\n                \\[\n                |\\vec{T}'(t)|=\\frac{1}{\\sqrt{a^2+b^2}}\\sqrt{a^2\\cos^2{t}+a^2\\sin^2{t}} = \\frac{a}{\\sqrt{a^2+b^2}}\n                \\]\n                so the curvature is\n                \\[\n                \\kappa = \\frac{\\frac{a}{\\sqrt{a^2+b^2}}}{\\sqrt{a^2+b^2}} = \\frac{a}{a^2+b^2}\n                \\]\n                Note that in the limit as \\(b\\to\\infty\\) the curvature approaches that of a straight line, and in the limit as \\(b\\to 0\\), the curvature approaches that of a circle.\n        \\end{example}{}{}\n        This definition of curvature always works, but there is a formula for curvature which is often simpler to apply, namely\n        \\[\n        \\kappa = \\frac{|\\vec{r}'\\times\\vec{r}''|}{|\\vec{r}'|^3}\n        \\]\n        the proof of which is elided.\n        \\begin{example}{}{}\n                Consider the curve parameterized by \\(\\vec{r}(t)=2t\\i+t^2\\j+\\frac{t^3}{3}\\j\\). Find its curvature.\n                \\tcblower\n                First, we find \\(\\vec{r}'(t)=2\\i+2t\\j+t^2\\k\\), so\n                \\[\n                |\\vec{r}'(t)|=\\sqrt{4+4t^2+t^4}=\\sqrt{(2t+t^2)^2}=2t+t^2\n                \\]\n                We may then calculate \\(\\vec{r}''(t)=2\\j+2t\\k\\), and \\(\\vec{r}'\\times\\vec{r}''=2(t^2\\i-2t\\j+2\\k)\\), which gives us\n                \\[\n                |\\vec{r}'\\times\\vec{r}''|=2\\sqrt{t^4+4t^2+4}=2(2+t^2)\n                \\]\n                Finally, we may calculate\n                \\[\n                \\kappa = \\frac{2(2+t^2)}{(2+t^2)^3} = \\frac{2}{(2+t^2)^2}\n                \\]\n        \\end{example}\n\\end{document}\n", "meta": {"hexsha": "04e226580f849ec3b4bbcd50ebb9a09a5cf8ed98", "size": 6829, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/lec_3.tex", "max_stars_repo_name": "CrashAndSideburns/MATH227-Notes", "max_stars_repo_head_hexsha": "ec5356ff816c2f51828e4f8b64b5ae0a8b0c8cd3", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-25T04:16:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T04:16:23.000Z", "max_issues_repo_path": "src/lec_3.tex", "max_issues_repo_name": "CrashAndSideburns/MATH227-Notes", "max_issues_repo_head_hexsha": "ec5356ff816c2f51828e4f8b64b5ae0a8b0c8cd3", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lec_3.tex", "max_forks_repo_name": "CrashAndSideburns/MATH227-Notes", "max_forks_repo_head_hexsha": "ec5356ff816c2f51828e4f8b64b5ae0a8b0c8cd3", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.0725806452, "max_line_length": 617, "alphanum_fraction": 0.4898228145, "num_tokens": 2076, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.7120673169460203}}
{"text": "\\chapter{Basic CNN}\n\nThis model is a specialized kind of neural network for processing data that has a known, grid-like topology, or more generally, data $X^i \\in \\mathbb{R}^{n_1\\times n_2\\cdots\\times n_d}$ is a order $d$ tensor. A naive way to deal with those kind of data is to reshape this tensor to be a vector( order 1 tensor), and then use the traditional deep feedforward neural network.\n\nHowever, for some practical problem, this method means that the input dimension is very big that is $m = n_1\\times\\cdots \\times n_d$. Another important reason is that this will broke the structure of this data, especially for AI task.\n\n\\section{Convolution in mathematics}\n\\subsection{Continuous case}\nGenerally speaking, convolution is a special kind of bilinear transform for multidimensional function. For example:\n\\begin{equation}\n\\ast: L^2(\\mathbb{R}^n) \\times L^2(\\mathbb{R}^n) \\to L^1(\\mathbb{R}^n).\n\\end{equation}\n\nSo if, we fixed one function, a convolution operator is just a linear transform form one function space to another. For example, if $g \\in C_0^{\\infty}(\\mathbb{R}^n)$, we have:\n\\begin{equation}\n\\ast g: L^2(\\mathbb{R}^n) \\to L^2(\\mathbb{R}^n),\n\\end{equation}\nwith \n\\begin{equation}\n(f\\ast g)(x) := ((\\ast g)f )(x) = \\int_{\\mathbb{R}^n} f(y)g(x-y) dy. \n\\end{equation}\n\n\\subsection{Discrete case}\nWhen talks about discrete case, general function becomes tensor(Although, the real tensor definition is not like this):\nFunctions $\\to$ Tensors, \n\\begin{align}\n(f\\ast g)(x) &= \\int_{\\bm{y}} f(x_1 - y_1,\\cdots,x_d - y_d)g(y_1,\\cdots,y_d) \\\\\n\\xrightarrow[Uniform~Grid]{Sampling} (F\\ast G)_{i_1, \\cdots, i_d} &= \\sum_j F_{i_1 - j_1,\\cdots,i_d - j_d}G_{j_1, \\cdots, j_d}.\n\\end{align}\n\n\nWe can have the next definition for two general order $d$ tensor(comes from the $d$-dimensional function):\n\\begin{equation}\n(T\\ast M)(i_1, i_2, \\cdots ,i_d) = \\sum_{j_i, j_2,\\cdots,j_d \\in \\mathbb{Z}} T(j_1, j_2,\\cdots,j_d)M(i_1 - j_1, i_2 - j_2, \\cdots, i_d - j_d).\n\\end{equation}\nAlmost book and notes about CNN defined discrete convolution like this, but here is a problem about the summation  index, this may only be well defined when the index for every dimension can be infinite. So in general there should be some rules for finite cases, for example: \n\\begin{itemize}\n\\item Padding $M$ with zeros\n\\item Repeat $M$ to make it a periodic infinite one in every dimension\n\\end{itemize}\nNow we consider the finite case, which means $T, M \\in \\mathbb{R}^{n_1 \\times n_2 \\times \\cdots n_d}$. By the definition(no matter what rules we use), $\\ast M$ should be a order $2d$ tensor with some special structure because that:\n\\begin{equation}\n\\ast M \\in L(\\mathbb{R}^{n_1 \\times n_2 \\times \\cdots n_d}, \\mathbb{R}^{n_1 \\times n_2 \\times \\cdots n_d}).\n\\end{equation}\nAnd we call $M$ is the kernel for this convolution mapping $\\ast M$.\n\nHere a good example for the special structure for $\\ast M$ is when we consider the convolution between two order $1$ tensors. We can have two vectors $\\bm{x}$ and $\\bm y$ then $\\ast \\bm y$ is exact the a special Toeplitz matrix i.e a circulant matrix. \n\\begin{equation}\n(\\ast \\bm{y})_{i,j} = \\bm{y}(j-i+1).\n\\end{equation}\nWe will see that, this special structure plays a very important role in deep learning, I think this special structure is a special case for general called ``Parameter Sharing\".  \n\n\n\n\\section{Convolution introduction in CNN (without multichannel)}\n\\subsection{General Convolution in CNN(with small size change)}\nThere is a kind of special linear map from some general finite dimension tensor space to another is called ``convolution\".  Generally, we have a tensor like $X \\in \\mathbb{R}^{n \\times m}$ and a small kernel such as $K \\in \\mathbb{R}^{k\\times k}$, then we have:\n\\begin{definition}[Original Convolution with stride 1 for CNN]\n\\begin{equation}\\label{equ:conv}\n(X\\ast K)_{i,j} = \\sum_{s, t = 1}^k X_{i-1 + s, j-1 + t} K_{s,t}.\n\\end{equation}\nIt's easy to see that $(X\\ast K) \\in \\mathbb{R}^{(n-k + 1) \\times (m-k + 1)}$.\n\\end{definition}\nIf we use stride $p$, we have:\n\\begin{definition}[Original Convolution with stride $p$ for CNN]\n\\begin{equation}\\label{equ:convstride}\n(X\\ast_{p} K)_{i,j} = \\sum_{s, t = 1}^k X_{(i-1)p + s, (j-1)p + t} K_{s,t}.\n\\end{equation}\nSo, we have \n$\n(X\\ast_p K) \\in \\mathbb{R}^{((n-k)/p + 1) \\times ((m-k)/p+1)}.\n$\n\\end{definition}\nThis stride properties in some application are often used as pooling(subsampling, coarsening).  \n\nHere we can define a special pooling operator as $S^p$ which likes the $C/F$ split for choosing coarse point:\n\\begin{equation}\nS^p(X)_{i,j} = X_{(i-1)p + 1, (j-1)p + 1},\n\\end{equation}\nthen we have:\n\\begin{equation}\\label{equ:stride}\nX \\ast_p K = S^p(X\\ast K),\n\\end{equation}\nwith the $\\ast$ and $\\ast_p$ defined by \\ref{equ:conv} and \\ref{equ:convstride}\n\\begin{proof}\n\\begin{align}\nS^p(X \\ast K)_{i,j} &= (X \\ast K)_{(i-1)p+1, (j-1)p + 1}  \\\\\n&= \\sum_{s,t = 1}^k X_{(i-1)p + 1 -1 +s, (j-1)p +1 -1 +t}K_{s,t}  \\\\\n&= (X \\ast_p K)_{i,j}.\n\\end{align}\n\\end{proof}\n\n\\subsection{Convolution with Padding in CNN(without changing size)}\nFor many case kernel size is some small odd numbers such as 1, 3, 5... So we ca have those next definition for convolution:\n\\begin{definition}[Convolution with Padding]\n\nWe write $K\\in \\mathbb R^{2k+1, 2k+1}$, we then write\n\\begin{equation}\\label{ConvPadding}\n(X \\ast K)_{i,j} :=\\sum_{s, t = -k}^k P^k(X)_{i + s, j + t} K_{s,t},\n\\end{equation}\nwith $\\rm{P}^k$ means Padding. \n\\end{definition}\nHere we see that, to make this definition well-defined, we have $X\\ast K \\in \\mathbb{R}^{n-2k, m-2k}$, because if the index of $X$ start from $1$ to $n(m)$, then $X \\ast K$ from $k+1$ to $n(m) - k$. To make the convolution don't change size, we can use Padding strategy like in image process. \n%In fact, if the resolution is very high, which means the measure of the boundary of the image is close to 0, so in traditional image process, this strategy hasn't been studied very well. There are basic three strategy:\n\\begin{description}\n\\item[Zero Padding] The simplest and most common used strategy is zero padding with:\n\\begin{equation}\n\\rm{P}^k_0: \\mathbb{R}^{n \\times m} \\to \\mathbb{R}^{n+2k \\times m+2k}\n\\end{equation}\nwith \n\\begin{equation}\n\\rm{P}_0^k(X)_{i,j} = \\begin{cases}\n0 &i(j)=-k+1:0 ~~\\text{and}~~ i(j) = n(m)+1:n(m)+k \\\\\nX_{i,j} &i(j) = 1:n(m) \n\\end{cases}\n\\end{equation}\n\\item[Reflection Padding] This strategy is defined by:\n\\begin{equation}\n\\rm{P}^k_r: \\mathbb{R}^{n \\times m} \\to \\mathbb{R}^{n+2k \\times m+2k}\n\\end{equation}\nwith \n\\begin{equation}\n\\rm{P}_r^k(X)_{i,j} = \\begin{cases}\nX_{1-i, 1-j} &i(j)=-k+1:0 ~~\\text{and}~~ i(j) = n(m)+1:n(m)+k \\\\\nX_{i,j} &i(j) = 1:n(m) \\\\\n0 &\\text{others} \n\\end{cases}\n\\end{equation}\n\\item[Shift Padding] This strategy is defined by:\n\\begin{equation}\n\\rm{P}^k_s: \\mathbb{R}^{n \\times m} \\to \\mathbb{R}^{n+2k \\times m+2k}\n\\end{equation}\nwith \n\\begin{equation}\n\\rm{P}_s^k(X)_{i,j} = \\begin{cases}\nX_{k-i, k-j} &i(j)=-k+1:0 ~~\\text{and}~~ i(j) = n(m)+1:n(m)+k \\\\\nX_{i,j} &i(j) = 1:n(m) \\\\\n0 &\\text{others} \n\\end{cases}\n\\end{equation}\n\\end{description}\n\nSo we can have:\n\\begin{equation}\n\\rm{dim}(X\\hat{\\ast}K) = \\rm{dim}(\\rm{P}^k(X) \\ast K) = \\rm{dim}(X),\n\\end{equation}\nand the $i,j$ index is consistent for both side of the above equation where $\\rm{P}^k = \\rm{P}_0^k, \\rm{P}_{r}^k$ or $\\rm{P}_s^k$.\n\n\n\\begin{remark}We note all the later convolution as the \\eqref{ConvPadding} without special statements and use $\\ast$ stands for $\\hat{\\ast}$.\n\n\\end{remark}\n\n\n\n\\section{Special Structure for Convolution in CNN}\nNow let us forget about the general convolution in mathematics, we go back to the method for using deep learning to deal with tensor data. Recall the general method in fully connected deep feedforward neural network, all process can be decompose into two phase: linear transform(in fact, affine map) from vector space to another vector space,  and nonlinear transform separately for every component for the output of linear transform. \n\nSo, now we consider we have a tensor like $T \\in \\mathbb{R}^{n_1\\times n_2\\cdots \\times n_d}$, and we want to use some linear transform $W$ such that $W(T) \\in  \\mathbb{R}^{n'_1\\times n'_2\\cdots \\times n'_d }$, this means that \n\\begin{equation}\nW \\in  L(\\mathbb{R}^{n_1\\times n_2\\cdots \\times n_d},  \\mathbb{R}^{n'_1\\times n'_2\\cdots \\times n'_{d}}) ,\n\\end{equation}\nwhich means that $W$ is a order $2d$ tensor. The size for $W$ is too big!\n\n\\subsubsection{Parameter Sharing and Convolution}\nLet us just use the order 1 tensor as a example to show the power for parameter sharing. For vector case, i.e $T \\in \\mathbb{R}^{n}$, and we want the output is in $\\mathbb{R}^m$, so we have $W \\in R^{m\\times n}$.  So we can think about the next parameter sharing strategy:\n\\begin{definition}[Parameter Sharing]\nEvery row of $W$ is same without only some shifting operator.  \n\\end{definition}\nThis strategy lead to that the convolution operator is a very special kind of  result from parameter sharing.  This means that $W$ can be defined by just a $\\mathbb{R}^n$ vector.(This might be some kinds of ``low dimension\" structure?) However, how to choose a suitable vector is still a big problem. By the way, for general tensor, this means that $W$ also have the same size for $T$ which may also be a little big.  \n\n\\subsubsection{Sparsity for Convolution in CNN}\nThanks for the filter theory for mathematical image process, we can just choose some sparse(local supported) vector to do some meaningful operation. Such as   $(-1, 2, -1)$, means the discrete Laplacian operator, but a more strict expression should be $\\bm x \\in \\mathbb{R}^n$, and then $W \\in \\mathbb{R}^{n-2 \\times n}$ with \n\\begin{equation}\nW(j,i) = w(j - i + 1)  \\quad  W = \\begin{pmatrix}\n-1 & 2 & -1 & 0 & 0&\\cdots & 0 \\\\\n0& -1 & 2 & -1 & 0 & \\cdots & 0 \\\\\n\\vdots &  & & \\cdots & & & \\vdots \\\\\n0& \\cdots & & & -1 & 2& -1 \n\\end{pmatrix},\n\\end{equation}\nand \n\\begin{align}\n\\bm x\\ast w = W \\bm x.\n\\end{align}\nSo we may have the next with sparse parameter strategy:\n\\begin{definition}[Sparsity]\nEvery row of $W(:,i)$ is locally supported around $i$ or $i \\pm 1$.  \n\\end{definition}\n\nAt last, we can take this kind of convolution in CNN as a results of ``parameter sharing\" and ``sparsity\". \n\n%\\subsection{Convolution in CNN}\n%\\subsubsection{Definition by ``inner product\" type operator}\n%For the example above, we found that we only need a vector $ k = (-1,2,-1)$ to represent this process like:\n%\\begin{equation}\n%(W \\bm x)(j) = x(j:j+2) \\cdot k \\quad \\forall j = 1:n-2.\n%\\end{equation} \n%So this inspires us to have the next definition, if $T \\in \\mathbb{R}^{n_1 \\times n_2 \\cdots n_d}$ and $K \\in \\mathbb{K}^{m_1 \\times m_2\\cdots m_d}$ with $ m_i \\le n_i $. \n%we can define \n%\\begin{equation}\n%\\hat{m}_i = \\begin{cases}\n%\\frac{m_i - 1}{2} \\quad &\\text{if $m_i$ is odd} \\\\\n%\\frac{m_i}{2} \\quad &\\text{if $m_i$ is even}.\n%\\end{cases}\n%\\end{equation}\n%So we define \n%\\begin{equation}\n%(T \\ast K)(i_1, i_2, \\cdots, i_d) = T( i_1 : i_1 + (m_i-1), \\cdots, i_d:i_d + (m_d -1)) \\odot K \\quad i_j \\le n_j - m_j + 1,\n%\\end{equation}\n%where $\\odot$ means sum of all index for two tensor with the same size, i.e \n%\\begin{equation}\n%T_1 \\odot T_2 = \\sum_{i_1, \\cdots, i_d} T_1(i_1, \\cdot, i_d) T_2(i_i,\\cdots, i_d).\n%\\end{equation}\n%This means that, for any tensor we can use another tensor with the same order and smaller size to be a kernel, and do convolution with them. So this is no longer commutative for this kind of ``convolution\".\n\n\n\\subsection{Convolution with multichannel}\n\\subsubsection{Channel}\nBefore we start to explain every layers for general CNN model, we want to give some remarks about ``Channel\".   As we know above, if we apply one certain kernel to do convolution with the original tensor, we can get some certain feature. The following are some examples of $3\\times 3$ kernels.\n%\\begin{figure}[!htb]        \n\t%\\center{\\includegraphics[width=13cm] {Kernels.png}}        \n\t%\\caption{Eight kernels makes eight channels with different type of features.}      \n\t%\\label{Kernels}\n%\\end{figure}\n\\begin{itemize}\n\\item A horizontal bar \n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{horizontal.png}} *\n\\begin{pmatrix}\n    0 & 0 & 0\\\\\n    0 & 1 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{horizontal.png}} \n$$\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{horizontal.png}} *\n\\begin{pmatrix}\n    1 & -1 & 0\\\\\n    0 & 0 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{hx.png}} \n$$\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{horizontal.png}} *\n\\begin{pmatrix}\n    1 & 0 & 0\\\\\n    -1 & 0 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{hy.png}} \n$$\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{horizontal.png}} *\n\\begin{pmatrix}\n    -1 & 0 & 0\\\\\n    0 & 1 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{hxy.png}} \n$$\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{horizontal.png}} *\n\\begin{pmatrix}\n    0 & -1 & 0\\\\\n    -1 & 4 & -1\\\\\n    0 & -1 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{hlaplace.png}} \n$$\n\n\\item A vertical bar\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{vertical.png}} *\n\\begin{pmatrix}\n    0 & 0 & 0\\\\\n    0 & 1 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{vertical.png}} \n$$\n\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{vertical.png}} *\n\\begin{pmatrix}\n    1 & -1 & 0\\\\\n    0 & 0 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{vx.png}} \n$$\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{vertical.png}} *\n\\begin{pmatrix}\n    1 & 0 & 0\\\\\n    -1 & 0 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{vy.png}} \n$$\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{vertical.png}} *\n\\begin{pmatrix}\n    -1 & 0 & 0\\\\\n    0 & 1 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{vxy.png}} \n$$\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{vertical.png}} *\n\\begin{pmatrix}\n    0 & -1 & 0\\\\\n    -1 & 4 & -1\\\\\n    0 & -1 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{vlaplace.png}} \n$$\n\n\\item A slash bar\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{slash.png}} *\n\\begin{pmatrix}\n    0 & 0 & 0\\\\\n    0 & 1 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{slash.png}} \n$$\n\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{slash.png}} *\n\\begin{pmatrix}\n    1 & -1 & 0\\\\\n    0 & 0 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{sx.png}} \n$$\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{slash.png}} *\n\\begin{pmatrix}\n    1 & 0 & 0\\\\\n    -1 & 0 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{sy.png}} \n$$\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{slash.png}} *\n\\begin{pmatrix}\n    -1 & 0 & 0\\\\\n    0 & 1 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{sxy.png}} \n$$\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{slash.png}} *\n\\begin{pmatrix}\n    0 & -1 & 0\\\\\n    -1 & 4 & -1\\\\\n    0 & -1 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{slaplace.png}} \n$$\n\n\n\\item Identity kernel\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{k0.jpg}} *\n\\begin{pmatrix}\n    0 & 0 & 0\\\\\n    0 & 1 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{k0.jpg}} \n$$\n\\item Kernel that taking $\\frac{\\partial}{\\partial x}$\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{k0.jpg}} *\n\\begin{pmatrix}\n    1 & -1 & 0\\\\\n    0 & 0 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{k1.jpg}} \n$$\n\\item Kernel that taking $\\frac{\\partial}{\\partial y}$\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{k0.jpg}} *\n\\begin{pmatrix}\n    1 & 0 & 0\\\\\n    -1 & 0 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{k2.jpg}} \n$$\n\\item Kernel that taking $\\frac{\\partial}{\\partial x}+\\frac{\\partial}{\\partial y}$\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{k0.jpg}} *\n\\begin{pmatrix}\n    1 & 0 & 0\\\\\n    0 & -1 & 0\\\\\n    0 & 0 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{k3.jpg}} \n$$\n\\item Kernel that taking $-\\Delta$\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{k0.jpg}} *\n\\begin{pmatrix}\n    0 & -1 & 0\\\\\n    -1 & 4 & -1\\\\\n    0 & -1 & 0\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{k4.jpg}} \n$$\n\\item Kernel that taking local average\n$$\n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{k0.jpg}} *\n\\begin{pmatrix}\n    1 & 1 & 1\\\\\n    1 & 1 & 1\\\\\n    1 & 1 & 1\n\\end{pmatrix} = \n\\raisebox{-.5\\height}{\\includegraphics[width=0.2\\textwidth]{k5.jpg}} \n$$\n\\end{itemize}\n\n\nSo if we want to do some AI task like classifier, we cannot only focus on just one feature, so we need many kernels to produce many features. In computer vision, they also call the several channels got from the convolution with different kernels as feature map.  \nBecause we use more and more kernel after several layers, we need another dimension to denote those several channels, we call this dimension as ``channel dimension\". We also have ``essential dimension\" w.r.t ``channel dimension\" which is the real tensor dimension for this date. For example, for a general colorized picture, is might be $T \\in \\mathbb{R}^{512\\times 512 \\times 3}$, here the essential dimension is the first two dimension, and the third one is the $RGB$ channel dimension to represent the colour for picture. \n\n\n\n\\subsubsection{Convolution for multichannel case}\nHere in real data, we have some special data like colour image $X \\in \\mathbb{R}^{n \\times m \\times3}$. Here this image is a 2D graph, with $3$ means the $RGB$ channels. So, we cannot just think $X$ as a general $3$-order tensor. \n\nWe may use this as an example, $X \\in \\mathbb{R}^{n\\times m \\times c}$, as we mentioned before, we say that $n \\times m$ is the essential dimension and $c$ is the channel dimension for $X$. If we want to do convolution for $X$, here we cannot just use $K \\in \\mathbb{R}^{2k+1 \\times 2k+1}$ because of multichannel. A simple idea is to use also different $c$ kernels and collect them together as $K \\in \\mathbb{R}^{2k+1 \\times 2k+1 \\times c}$, and then we can do the general convolution for signal channel separately. This means that \n\\begin{equation}\n(X \\ast K)_{l} = X_{l}\\ast K_{l}.\n\\end{equation}\nBut we need to recall that, even for $X \\in \\mathbb{R}^{n\\times m \\times c}$ it is in fact only stand for just one 2D image(with multi-channel). So if we talk about features in AI, $(X\\ast K) \\in \\mathbb{R}^{n\\times m \\times c}$ should be reduced to the essential dimension, one simple way is just to add all the channels value together w.r.t essential dimension(this is equal to added with weights because we can reduce those DoF into the previous $c$ kernels.):\n\\begin{equation}\n(X \\hat{\\ast} K) = \\sum_{l=1}^{c} X_{l}\\ast K_{l}. \n\\end{equation}\nthen we have\n\\begin{equation}\n(X \\hat{\\ast} K) \\in \\mathbb{R}^{n \\times m} \\quad \\text{with} \\quad K \\in \\mathbb{R}^{2k+1 \\times 2k+1 \\times c}.\n\\end{equation}\nSo, for a given real data with $c$ channels like $X \\in  \\mathbb{R}^{n\\times m \\times c}$ if we use kernel $K \\in \\mathbb{R}^{2k+1 \\times 2k+1 \\times c}$ we can only get one signal channel output. To get multichannel form $X$, we just need to use $d$ kernels $K \\in \\mathbb{R}^{2k+1 \\times 2k+1 \\times c}$, or we say $K \\in \\mathbb{R}^{2k+1 \\times 2k+1 \\times c \\times b}$, then we have:\n\\begin{equation}\\label{6.6}\n(X \\tilde{\\ast} K)_{g} =  X \\hat{\\ast} K_{g},\n\\end{equation}\nwith \n\\begin{equation}\n(X \\tilde{\\ast} K) \\in \\mathbb{R}^{n \\times m \\times b} \\quad \\text{with} \\quad K \\in \\mathbb{R}^{2k+1 \\times 2k+1 \\times c \\times b}.\n\\end{equation}\n\nIn the next section, we set that all tensor is with\nmultichannel(signal channel is a special case, and we note it as $X\n\\in \\mathbb{R}^{n \\times m \\times 1}$), and we just use $\\ast$ no\nlonger $\\tilde{\\ast}$. All for all, the  above convolution for multi-channel tensor can be expressed as:\n\\begin{equation}\\label{6.6}\n(X \\ast K)_{i,j,g} = \\sum_{\\bm{l}=1}^{c} \\sum_{s, t = -k}^k X_{i + s, j + t,\\bm{l}} K_{s,t,\\bm{l},g},\n\\end{equation}\nwith \n\\begin{equation}\n(X \\ast K) \\in \\mathbb{R}^{n \\times m \\times b} \\quad \\text{and} \\quad K \\in \\mathbb{R}^{2k+1 \\times 2k+1 \\times c \\times b}.\n\\end{equation}\n\n\n\n\n\n\n\n\n\n\n\n\\section{Three basic layers in CNN}\nA typical structure in a convolutional network consists of three layers. In the first layer, it performs several convolutions in parallel to produce a set of linear activations. In the second one, each linear activation is run through a nonlinear activation function, such as the rectified linear(ReLu) activation function. This layer is sometimes called the detector layer. In the third layer, we use a pooling function to modify the output of the layer further.\n\\subsubsection{Convolutional layers}\nHere we set that, all the input for the convolutional layer is just one tensor, which means we need collect all channels as the channel dimension. So, for a general tensor with $\\hat{c}$ channels $T \\in \\mathbb{R}^{n_1 \\times n_2 \\cdots n_d \\times \\hat{c}}$, we have $\\tilde{c}$ convolutional kernels(filter) $K_i \\in \\mathbb{R}^{2k+1 \\times 2k+1 \\cdots 2k+1 \\times \\hat{c}}$ to map it to a $n_1 \\times \\cdots \\times n_d $ tensor with $\\tilde c$ channels(feature mapping). \n\nMathematically speaking:\n\\begin{equation}\n\\ast K_{i}: \\mathbb{R}^{n_1 \\times n_2 \\cdots n_d \\times \\hat{c}} \\xrightarrow{K_i} \\mathbb{R}^{n_1 \\times  \\cdots n_d } \\quad \\forall i = 1:\\tilde c,\n\\end{equation}\nor like the next figure for the ``original convolution with stride 1 for CNN\":\n\\begin{figure}[!htb]        \n\t\\center{\\includegraphics[width=10cm] {Convolution_layer.png}}        \n\t\\caption{An example of 2-D convolution mapping a $3 \\times 4$ tensor to a $2 \\times 3$ tensor with a convolutional kernal of the size $ 2 \\times 2 \\times 1$}      \n\\end{figure}\n\nGenerally speaking, $\\tilde c \\approx 2\\hat{c}$, which means this output tensor will become longer in the channel dimension but just a little thinner in the essential dimension. We will introduce ``Pooling'' layers at last, which will keep the channel dimension but reduce the essential dimension very quickly. \n\n\\subsubsection{Nonlinear Activation layers}\nThis layer is very simple just like the nonlinear layers in feedforward fully connected neural network, just use some simple nonlinear $g: \\mathbb{R} \\to \\mathbb{R}$, such as:\n\\begin{itemize}\n\\item Sigmoid or Tangent:\n\\begin{equation}\ng = \\sigma (x) = \\frac{1}{1 + e^{-x}},\n\\end{equation}\nor \n\\begin{equation}\ng = tanh(x) = \\frac{e^x - e^{-x}}{e^x + e^{-x}}.\n\\end{equation}\n\n\\item Softplus:\n\\begin{equation}\ng(x) = \\zeta(x) = \\log(1 + \\exp{x}).\n\\end{equation}\n\n\\item Rectified Linear Units:\n\\begin{equation}\ng(x) = ReLU(x) = \\max\\{0,x\\}.\n\\end{equation}\nReLU function is the most commonly used one in nonlinear layers in CNN. \n\\end{itemize}\n\n\n%Then the nonlinear layers can be expressed as:\n%\\begin{equation}\n%f_{ReLu}: \\mathbb{R}^{n_1 \\times \\cdots \\times n_d \\times \\hat{c}} \\xrightarrow{ReLU} \\mathbb{R}^{n_1 \\times  \\cdots \\times n_d \\times \\hat{c}}, \n%\\end{equation}\n%where\n%\\begin{equation}\n%f_{ReLU}(T)(i_1,i_2,\\cdots,i_d,i) = ReLU(T(i_1,i_2,\\cdots,i_d,i)).\n%\\end{equation}\n\n\\subsubsection{Pooling layers}\nFor general DNN method, the convolutional layer stands for the linear transformation and then we use a nonlinear layer.  So we just need to repeat this two layers and get a DNN structure.  However, the biggest distinguish between CNN and DNN is the next layer in some degree. \n\nJust as we mentioned before, the channel dimension will increase twice after a convolution layer but the essential dimension keeps for convolution with padding or only decrease linearly. Another big problem is that, because of the sparsity structure, it is hard to capture some \"globally structure\" or we see that, this model without some multi-scale structure like in image processing.\n So just as what we do in multigrid method, we need put those fine feature into some coarse level, that is exact the pooling or subsampling in image processing. \n\nA pooling function is a little like the GMG coarse strategy.   For example, for the output of nonlinear layers with essential order $2$, for one channel $T$, we introduce the pooling method apply to every channel separately: \n\\begin{equation}\nR(T)_{i,j} = r(T_{2i-1:2i,2j-1:2j})\n\\end{equation}\n$r(\\bm{x})$ can be:\n\\begin{itemize}\n\\item Fix position: $r(\\bm{x}) = x_i$ for some fix $i$. This method can be combine into the convolution with stride as shown before.\n\\item Maxout: $r(\\bm{x}) = \\max \\{x_1, \\cdots, x_4\\}$,\n\\item Average: $r(\\bm{x}) = \\frac{\\sum_{i=1}^4 x_i}{4}$,\n\\item $L^2$ normal: $r(\\bm{x}) = \\|x\\|$,\n\\item $\\cdots$\n\\end{itemize}\n\nIn computer vision, they think that pooling helps to make the representation become approximately invariant to small translations of the input. Invariance means that if we translate the input by a small amount, the values of most of the pooled outputs do not change.\nIn each step, with the pooling function, we can transfer the $\\tilde c$ channels into $\\tilde c$ pooled channels (feature mapping)  separately. \n\n\n\\section{LeNet-5: The Pioneer of Convolutional Neural Networks}\nThis section is devoted to a model that is widely recognized as the first convolutional neural network: LeNet-5 \\cite{Lecun1998Gradient}. In this section, we will introduce convolutional neural network via introducing LeNet-5 by explain every steps for LeNet-5.\nFigure \\ref{LeNet-5} shows an illustration of the architecture of LeNet-5. It consists of two pairs of Convolutional Layer and Subsampling Layer and is further connected with fully connected layer and an RBF layer for classification.\n\n\n\\begin{figure}[!htb]\n\t\\center{\\includegraphics[width=10cm] {LeNet-5.png}}        \n\t\\caption{The Architecture of LeNet-5}      \n\t\\label{LeNet-5}\n\\end{figure}\n%\\begin{figure}[htb]        \n%\t\\center{\\includegraphics[width=10cm] {AlexNet.png}}        \n%\t\\caption{AlexNet}      \n%\\end{figure}\n\n\\begin{itemize}\n\\item First of all, the input for LeNet-5 is digital picture with size $32 \\times 32$ which every picture contains a number written by different writers. So, mathematically speaking, $T^j$ is a order 2 tensor with just one channel, with essential size $32 \\times 32$, i.e $T^j \\in \\mathbb{R}^{32 \\times 32 \\times 1}$.  And the out put is a 10-dimensional vector $\\bm y = (y_0, \\cdots, y_9)$ with $y_i$ equal to the probability for the number in $T^j$ is $i$. \n\n\\item Input: $T \\in  \\mathbb{R}^{32 \\times 32 \\times 1}$\n\n\\item Input $\\xrightarrow{\\text{Convolution + ReLU}} C_1$: \\\\\nThis layer is not difficult to understand, this means you first use $6$ kernel $K_{1,i}, i = 1:6$ with $K_{1,i} \\in  \\mathbb{R}^{5 \\times 5 \\times 1}$, so you get $T\\ast K_{1,i}$, and then you just need to use ReLU for $T \\ast K_{1,i}, i=1:6$. This means:\n\\begin{equation}\n\\mathbb{R}^{32 \\times 32 \\times 1}  \\xrightarrow{\\text{Convolution ($K_{1,i}$) + ReLU}} \\mathbb{R}^{28\\times 28 \\times 6} \n\\end{equation}\nand\n\\begin{equation}\nC_1 = ReLU(T\\ast K_{1,i}) \\quad i = 1:6.\n\\end{equation}\n\n\\item $C_1 \\xrightarrow{\\text{Subsampling(Pooling)}} S_2$: \\\\\nThis layer is general pooling layer only for essential dimension such as max pooling, average or $L^2$ norm. So we have:\n\\begin{equation}\n\\mathbb{R}^{28\\times 28 \\times 6} \\xrightarrow{\\text{Pooling}} \\mathbb{R}^{14\\times 14 \\times 6}\n\\end{equation}\n\n\\item $S_2 \\xrightarrow{\\text{Convolution + ReLU}} C_3$:\\\\\nThis layer is a little different form the convolutional layer before because of the fact that $S_2$ is a multi-channel tensor.  So, when we do convolution for them, we need $16$ kernels as $K_{2,i} \\in \\mathbb{R}^{5 \\times 5 \\times 6}$:  \n\\begin{equation}\n\\mathbb{R}^{14\\times 14 \\times 6}  \\xrightarrow{\\text{Convolution ($K_{2,i}$) + ReLU}} \\mathbb{R}^{10\\times 10 \\times 16} \n\\end{equation}\nand\n\\begin{equation}\nC_3 = ReLU(S_2\\ast K_{2,i}) \\quad i = 1:16.\n\\end{equation}\nThere is an interesting structure for $K_{2,i}$ in the real LeNet-5. That is in the channel dimension for $K_{2,i}$ have some special \"0\" pattern, which can be shown as:\n\\begin{figure}[!htb]\\label{LeNet-Channel}\n\t\\center{\\includegraphics[width=10cm] {LeNet-Channel.png}}        \n\t\\caption{The \"0\" Pattern for Channel Dimension of $K_{2,i}$}      \n\\end{figure}\n\n\\item $C_3 \\xrightarrow{\\text{Subsampling(Pooling)}} S_4$:  \\\\\nThis layer is the same with $C_1 \\xrightarrow{\\text{Subsampling(Pooling)}} S_2$. \n\n\\item $S_4 \\xrightarrow{\\text{Subsampling(Pooling)}} C_5$:  \\\\\nThis layer use the naive idea we introduced at the beginning that we just reshape the $16$-channels $5\\times 5$ tensor into a vector with dimension $400$. And then followed a fully connected feedforward neural network as a classifier.\n\\end{itemize}\n\n\n", "meta": {"hexsha": "d2aea03b26146b81b74d480053b459fe4875aa3e", "size": 29366, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/CNN-old.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/CNN-old.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/CNN-old.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.5177993528, "max_line_length": 533, "alphanum_fraction": 0.6877000613, "num_tokens": 10087, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.711967487251694}}
{"text": "\\chapter{System Identification}\n\nSystem identification can be defined as the deduction of system characteristics from measured data. \\cite{NASA-RP-1138} Process of system identification includes performing identification experiment to obtain data, determining an appropriate form of the model and estimating the unknown parameters of the model with some statistically based method. \\cite{SoderstromStoica1989}\n\n\\section{Linear Regression}\n\nLeast squares approximation is probably the most common method of the linear regression and it can be used to to approximate the solution of overdetermined systems.\n\nParameters of line given by the following equation:\n\n\\begin{align}\n  y = ax + b\n\\end{align}\n\n\\clearpage\n\nbest fitting to the data set of $n$ points is given as follows:\n\n\\begin{align}\n  a &= \\frac{\\sum_{i=1}^{n}{ \\left( x_i - \\bar{x} \\right) \\left( y_i - \\bar{y} \\right) }}{\\sum_{i=1}^{n}{ \\left( x_i - \\bar{x} \\right)^2 }} \\\\\n  b &= \\bar y - a \\bar x\n\\end{align}\n\nWhere:\n\n\\begin{align}\n  \\bar{x} &= \\frac{\\sum_{i=1}^{n}{ x_i }}{ n } \\\\\n  \\bar{y} &= \\frac{\\sum_{i=1}^{n}{ y_i }}{ n }\n\\end{align}\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=140mm]{eps/linear_least_squares.eps}\n  \\caption{Linear Least Squares}\n\\end{figure}\n", "meta": {"hexsha": "65a8785a05746251db9abd462d4b3ed00f4adbe7", "size": 1243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/data_5.tex", "max_stars_repo_name": "marek-cel/mscsim-docs", "max_stars_repo_head_hexsha": "9984f33c84787c4420f11f2834bb35e040e1f36f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-12-01T02:27:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-09T07:02:20.000Z", "max_issues_repo_path": "tex/data_5.tex", "max_issues_repo_name": "marek-cel/mscsim-docs", "max_issues_repo_head_hexsha": "9984f33c84787c4420f11f2834bb35e040e1f36f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/data_5.tex", "max_forks_repo_name": "marek-cel/mscsim-docs", "max_forks_repo_head_hexsha": "9984f33c84787c4420f11f2834bb35e040e1f36f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-12-01T10:56:23.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-01T19:41:05.000Z", "avg_line_length": 34.5277777778, "max_line_length": 376, "alphanum_fraction": 0.7176186645, "num_tokens": 356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593496, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.711967478617248}}
{"text": "%\\newcommand{\\fix}{\\marginpar{FIX}}\n%\\newcommand{\\new}{\\marginpar{NEW}}\n%\\newcommand{\\classmap}{H}\n%\\newcommand{\\linearize}{H_0}\n%\\newcommand{\\linear}{L}\n%\\newcommand{\\FC}{{\\mathcal D}}\n%\\example\nDenote $\\phi^{\\ell}=(\\phi^{\\ell}_{i,j})\\in \\mathbb R^{m_{\\ell}\\times n_{\\ell}}$, \nby the definitions of convolution \\eqref{con1} and stride \\eqref{stride}, \\eqref{basis:plongation} means that\n$$\n \\phi^{\\ell+1}=R\\ast_2 \\phi^{{\\ell}},\n$$\nwhere \n\\begin{equation}\\label{bi-restrict}\nR=\n%\\left\\{\n\\begin{cases}\n\t\\begin{pmatrix}\n\t\\frac{1}{4} &\\frac{1}{2}&\\frac{1}{4}\\\\\n\t\\frac{1}{2}& 1&\\frac{1}{2}\\\\\n\t\\frac{1}{4}&\\frac{1}{2}&  \\frac{1}{4} \n\t\\end{pmatrix}\n\t\\hbox{~~for bilinear functions};\\\\\n\t\\begin{pmatrix}\n\t0 &\\frac{1}{2}&\\frac{1}{2}\\\\\n\t\\frac{1}{2}& 1&\\frac{1}{2}\\\\\n\t\\frac{1}{2}&\\frac{1}{2}&  0\n\t\\end{pmatrix}\n\t\\hbox{~~for linear functions}.\n\t\\end{cases}\n\t%\\right.\n\t\\end{equation}\t\t\n\\section{Deconvolution}\nFor any linear mapping $\\mathcal C: \\mathbb{R}^{m\\times n} \\mapsto \\mathbb{R}^{m'\\times n'}$, \nits transpose is the unique linear mapping $\\mathcal C^\\top: \\mathbb{R}^{m'\\times n'} \\mapsto \\mathbb{R}^{m\\times n}$\nsatisfying \n$$\n(\\mathcal C^\\top u, v)_{l^2}=(u, \\mathcal C v)_{l^2}~~~\\forall~u\\in \\mathbb{R}^{m'\\times n'} , v\\in \\mathbb{R}^{m\\times n}\n$$\nAssociated with any kernel $K$, a deconvolution is defined as the transpose of convolution \nwith stride $2$ with respect to the $l^2$-inner product as:\n\\begin{equation}\\label{eq:def_deconv}\n (u, K \\ast_2^\\top v)_{l^2}=(K \\ast_2 u, v)_{l^2},\n\\end{equation}\nwith\n\\begin{equation}\nu \\in \\mathbb{R}^{m \\times n} \\quad \\text{and} \\quad v \\in \\mathbb{R}^{\\frac{m+1}{2} \\times \\frac{m+1}{2}}.\n\\end{equation}\n\n\\begin{lemma}\\label{lemm:tilde-K}\nFor any $K \\in \\mathbb{R}^{(2k+1) \\times (2k+1)}$,\n\\begin{equation}\\label{eq:}\nK\\ast_2^\\top = {\\tilde K}\\ast \\mathcal S^\\top,\n\\end{equation}\nwhere $\\tilde K$ is defined as\n\\begin{equation}\\label{eq:def_tildeK}\n\\tilde K_{p,q} = K_{-p, -q}, \\quad p,q = -k:k.\n\\end{equation}\nIntuitively, if we take $K_{0,0}$ as the center for the convolutional kernel $K$, \nthen $\\tilde K$ is the central symmetry of $K$. \nIn 2D case, it can also be understood as the rotation of $\\pi$ with respect to\nthe center $K_{0,0}$.\n\\end{lemma}\n\nRecalling the definition of deconvolution in \\eqref{eq:def_deconv}, we have\n\\begin{equation}\\label{eq:op_deconv}\n\\begin{aligned}\n(u,  K \\ast_2^\\top v)_{l^2} &= (K \\ast_2 u, v)_{l^2} = (\\mathcal S \\mathcal C_K u, v)_{l^2} \\\\\n&= (u,  \\mathcal C^\\top_K \\mathcal S^\\top v)_{l^2},\n\\end{aligned}\n\\end{equation}\nwith definition\n\\begin{equation}\\label{eq:de_stride_dim}\n\\mathcal S^\\top:   \\mathbb{R}^{\\frac{m+1}{2} \\times\\frac{n+1}{2}} \\mapsto \\mathbb{R}^{m\\times n},\n\\end{equation}\nand \n\\begin{equation}\\label{eq:de_stride}\n[\\mathcal S^\\top (f)]_{i,j} = \n\\begin{cases}\n0 \\quad &\\text{if i or j is even}, \\\\\nf_{i/2, j/2}, \\quad &\\text{else}.\n\\end{cases}\n\\end{equation}\n\nThus to say, we have the simple version of the deconvolution for $K \\ast $ as\n\\begin{equation}\\label{eq:simple_deconv}\nK \\ast_2^\\top v = \\mathcal C_K^\\top \\circ \\mathcal S^\\top (v) = \\mathcal C_{\\tilde K} \\circ \\mathcal S^\\top (v) = \\tilde K \\ast \\mathcal S^\\top (v),\n\\end{equation}\nthus to say\n\\begin{equation}\\label{eq:final}\nK \\ast_2^\\top  = \\tilde K \\ast \\mathcal S^\\top.\n\\end{equation}\n\nIn short, we have the next decomposition\n\\begin{itemize}\n\t\\item convolution with stride = stride $ \\circ$ convolution,\n\t\\item deconvolution with stride  = transposed convolution $\\circ$ transposed stride = convolution with the central symmetry of original kernel $\\circ$ transposed stride.\n\\end{itemize}\n\n\\begin{theorem}\\label{thm:deconv_op}\n\nLet us consider \n\\begin{equation}\nK=(K_{p,q}),~~p,q = -1, 0, 1.\n\\end{equation}\nThen we have \n$$\nK \\ast_2^\\top v = \\tilde K \\ast \\mathcal S^\\top (v).\n$$\nAs in \\eqref{eq:de_stride} and the Lemma \\ref{lemm:tilde-K}, we have the \nfinal version is \n\\begin{equation}\n\\label{eq:7}\n[K \\ast_2^\\top v ]_{2i,2j}=  K_{0,0}v_{i,j},\n\\end{equation}\nwith \n\\begin{equation}\n\\label{eq:9}\n[K \\ast_2^\\top v ]_{2i-1, 2j} = K_{0,1}v_{i-1,j} + K_{0,-1}v_{i,j}, \\quad \n[K \\ast_2^\\top v ]_{2i, 2j-1} = K_{1,0}v_{i,j} + K_{-1,0}v_{i,j-1},\n\\end{equation}\nand\n\\begin{equation}\n%\\begin{tiny}\n%{\\scriptsize \n[K \\ast_2^\\top v ]_{2i-1, 2j-1}  =  \nK_{1,1}v_{i,j} + K_{-1,1}v_{i-1,j} + K_{1,-1}v_{i,j-1} + K_{-1,-1}v_{i-1,j-1}.\n%\\end{tiny}\n%}\n\\end{equation}\n\\end{theorem}\n\\begin{remark}\nDeconvolution can obviously be also defined for general stride $s$, but we believe it is sufficient to use $s=2$\nin most applications. \n\\end{remark}\n\n \n\\section{Linear feature mappings}\nWe consider the following linear mapping\n\\begin{equation}\n  \\label{feature-map}\n\\mathbf A\\mathbf u=\\mathbf  f  \n\\end{equation}\nwhere \n\\begin{equation}\n  \\label{map-A}\n\\mathbf A: \\mathcal V\\mapsto \\mathcal V'.\n\\end{equation}\nFor example, for the elliptic problem \\eqref{laplace}, $(\\mathbf A \\mathbf u, \\mathbf v)=(\\nabla u_h, \\nabla v_h)$.\nWe consider the restriction of the mapping $\\mathbf A_1\\equiv \\mathbf A$ on the coarser multilevel spaces:\n\\begin{equation}\n  \\label{map-A-ell}\n\\mathbf A_{\\ell}: \\mathcal V_\\ell\\mapsto \\mathcal V'_\\ell\n\\end{equation}\nand the corresponding equation read as:\n\\begin{equation}\n  \\label{feature-map-ell}\n\\mathbf A_\\ell \\mathbf u^\\ell=\\mathbf f^\\ell.\n\\end{equation}\nIn image process, we can view $\\mathbf f$ as the input images and $\\mathbf u$ as the extracted features of the original image $\\mathbf f$.  We then view $\\mathbf f^\\ell$ as the projection of images on a coarser resolution and $\\mathbf u^\\ell$ as the extracted features of the coarsened image $\\mathbf f^\\ell$.\n\nOne main question is how to obtain coarser images and features defined by \\eqref{feature-map-ell} from the original equation \\eqref{feature-map}.  We now consider a special technique.\n\nWe define $\\mathbf u^\\ell\\in \\mathcal V_\\ell$ by\n\\begin{equation}\n  \\label{u_ell}\n(\\mathbf A\\mathbf u^\\ell,\\mathbf v^\\ell)=  (\\mathbf f,\\mathbf v^\\ell), \\quad\\forall \\mathbf v^\\ell\\in\\mathcal V_\\ell\n\\end{equation}\n\\begin{lemma}\nThe restricted $\\mathbf u^\\ell\\in\\mathcal V_\\ell$ defined by \\eqref{u_ell} satisfies \\eqref{feature-map-ell} if \n$\\mathbf A_\\ell: \\mathcal V_\\ell\\mapsto \\mathcal V_\\ell'$ and $\\mathbf f_\\ell\\in \\mathcal V_\\ell'$ are defined by\n\\begin{equation}\n  \\label{A-ell}\n(\\mathbf A_\\ell \\mathbf u^\\ell,\\mathbf v^\\ell)=  (\\mathbf A\\mathbf u^\\ell,\\mathbf v^\\ell), \\quad\\forall \\mathbf v^\\ell\\in\\mathcal V_\\ell\n\\end{equation}\n\\begin{equation}\n  \\label{u-ell}\n(\\mathbf f^\\ell,\\mathbf v^\\ell)=  (\\mathbf f,\\mathbf v^\\ell), \\quad\\forall \\mathbf v^\\ell\\in\\mathcal V_\\ell\n\\end{equation}\n\\end{lemma}\n\n\n\\section{Restriction and prolongation under the convolution notation}\nNow we derive the restriction and prolongation as follows. We show the details for the case of bilinear functions here. The \ncase of linear function can be shown similarly. \nLet $f_{i,j}^{\\ell+1}=(\\mathbf f^\\ell,\\phi^{\\ell+1}_{i,j})_{L^2(\\Omega)}$, then we have\n\\begin{equation}\n\\begin{split}\n  f^{\\ell+1}&=\\int_{\\Omega} \\mathbf f^\\ell \\phi^{\\ell+1}=\\sum\\limits_{i=1}^{m_\\ell}\\sum\\limits_{j=1}^{n_\\ell}\n \\int_{\\Omega}f_{i,j}^{\\ell}\\psi_{i,j}^\\ell\\left[(R\\ast_2) \\phi^\\ell\\right]\n=\\sum\\limits_{i=1}^{m_\\ell}\\sum\\limits_{j=1}^{n_\\ell} f_{i,j}^{\\ell}(R\\ast_2)\\int_{\\Omega}\\psi_{i,j}^\\ell \\phi^\\ell\\\\\n&=\\sum\\limits_{i=1}^{m_\\ell}\\sum\\limits_{j=1}^{n_\\ell}(R\\ast_2)f_{i,j}^{\\ell}e_ie_j^T=R\\ast_2 f^{\\ell}.\n\\end{split}\n\\end{equation}\nHence the restriction \n$$\nR^{\\ell+1}_\\ell: \\mathbb R^{m_{\\ell}\\times n_{\\ell}}\\mapsto  \\mathbb R^{m_{\\ell+1}\\times n_{\\ell+1}} \n$$\nis obtain by $R^{\\ell+1}_\\ell  f^{\\ell}= R\\ast_2  f^{\\ell}$ with $R\\in \\mathbb R^{3\\times 3}$ given by  \\eqref{bi-restrict}, namely\n\\begin{equation}\\label{restriction:freedom}\n\\begin{split}\nf_{i,j}^{\\ell+1}&=f^{\\ell}_{2i,2j}+\\frac{1}{2}(f^{\\ell}_{2i-1,2j}+f^{\\ell}_{2i,2j-1}+f^{\\ell}_{2i+1,2j}+f^{\\ell}_{2i,2j+1})\\\\\n&+\\frac{1}{4}\\left(f^{\\ell}_{2i-1,2j-1}+f^{\\ell}_{2i+1,2j-1}+f^{\\ell}_{2i+1,2j+1}+f^{\\ell}_{2i-1,2j+1}\\right).\n\\end{split}\n\\end{equation}\n\nNext \nlet $\\mathbf u^{\\ell+1}=\\sum\\limits_{i=1}^{m_{\\ell+1}}\\sum\\limits_{j=1}^{n_{\\ell+1}}u_{i,j}^{\\ell+1}\\phi^{\\ell+1}_{i,j}\n=( \\mathbf u^{\\ell+1}, \\phi^{\\ell+1})_{l^2}$, then we have\n\\begin{equation}\n\\begin{split}\n\\mathbf u^{\\ell+1}&=( u^{\\ell+1}, \\phi^{\\ell+1})_{l^2}\n=( u^{\\ell+1}, R\\ast_2\\phi^{\\ell})_{l^2}=(R\\ast_2^{\\top} u^{\\ell+1}, \\phi^{\\ell})_{l^2}\\\\\n&=\\sum\\limits_{i=1}^{m_{\\ell}}\\sum\\limits_{j=1}^{n_{\\ell}}\\left(R\\ast_2^{\\top} u^{\\ell+1}\\right)_{i,j}\\phi^{\\ell}_{i,j}.\n\\end{split}\n\\end{equation}\nNamely\n$$\n\\mathbf u^{\\ell+1}(x_i^\\ell,y_j^\\ell)=\\left(R\\ast_2^{\\top} u^{\\ell+1}\\right)_{i,j}.\n$$\nAnd we obtain the prolongation \n$$\nP_{\\ell+1}^\\ell=R\\ast_2^{\\top} : \\mathbb R^{m_{\\ell+1}\\times n_{\\ell+1}}\\mapsto  \\mathbb R^{m_{\\ell}\\times n_{\\ell} }\n$$\nis defined by \n$$\nu^\\ell_{2i,2j}=u^{\\ell+1}_{i,j},\n$$\n$$\nu^\\ell_{2i-1,2j}=\\frac{1}{2}(u^\\ell_{i,j}+u^\\ell_{i-1,j}),~~~ u^\\ell_{2i,2j-1}=\\frac{1}{2}(u^{\\ell+1}_{i,j}+u^{\\ell+1}_{i,j-1})\n$$\nand \n$$\nu^\\ell_{2i-1,2j-1}=\\frac{1}{4}(u^{\\ell+1}_{i,j}+u^{\\ell+1}_{i-1,j}+u^{\\ell+1}_{i-1,j-1}+u^{\\ell+1}_{i,j-1}).\n$$\nIn summery, we have the restriction and prolongation as follows: \n\\begin{lemma}\\label{ris:plon}\nThe restriction \n$$\nR^{\\ell+1}_\\ell: \\mathbb R^{m_\\ell\\times n_\\ell}\\mapsto  \\mathbb R^{m_{\\ell+1}\\times n_{\\ell+1}}~~\\hbox{is}~~ R^{\\ell+1}_\\ell = R\\ast_2  \n$$ \nand the prolongation\n$$\nP_{\\ell+1}^{\\ell}: \\mathbb R^{m_{\\ell+1}\\times n_{\\ell+1}}\\mapsto  \\mathbb R^{m_{\\ell}\\times n_{\\ell} } ~~\\hbox{is}~~ P^{\\ell}_{\\ell+1} =R\\ast_2^{\\top} \n$$\nwhere \n\\begin{equation}\\label{bi-restrict1}\nR=\n%\\left\\{\n\\begin{cases}\n\t\\begin{pmatrix}\n\t\\frac{1}{4} &\\frac{1}{2}&\\frac{1}{4}\\\\\n\t\\frac{1}{2}& 1&\\frac{1}{2}\\\\\n\t\\frac{1}{4}&\\frac{1}{2}&  \\frac{1}{4} \n\t\\end{pmatrix}\n\t\\hbox{~~for bilinear functions};\\\\\n\t\\begin{pmatrix}\n\t0 &\\frac{1}{2}&\\frac{1}{2}\\\\\n\t\\frac{1}{2}& 1&\\frac{1}{2}\\\\\n\t\\frac{1}{2}&\\frac{1}{2}&  0\n\t\\end{pmatrix}\n\t\\hbox{~~for linear functions}.\n\t\\end{cases}\n\t%\\right.\n\t\\end{equation}\t\n\\end{lemma}\n\nLet $(\\phi^{\\ell}_{i,j})$ is a basis of $\\mathcal V_\\ell$, for any $\\mathbf u^\\ell \\in \\mathcal V_\\ell$, then $\\mathbf u^{\\ell}=\\sum\\limits_{i=1}^{m_{\\ell}}\\sum\\limits_{j=1}^{n_{\\ell}}u_{i,j}^{\\ell}\\phi^{\\ell}_{i,j}$, and we denote $u^\\ell=(u_{i,j}^{\\ell})\\in  \\mathbb R^{m_{\\ell}\\times n_{\\ell} }$ the matrix representation of $\\mathbf u^\\ell$ under the basis $(\\phi^{\\ell}_{i,j})$.\nLet $(\\psi^{\\ell}_{s,t})$ is a basis of $\\mathcal V'_\\ell$ which is dual to $(\\phi^{\\ell}_{i,j})$. Denote $A_\\ell=(a_{stij}^{\\ell})$ the tensor representation of $\\mathbf A_\\ell: \\mathcal V_\\ell\\mapsto \\mathcal V'_\\ell $ and defined as \n$$\n\\mathbf A_\\ell \\phi^\\ell_{i,j}=\\sum\\limits_{s=1}^{m_{\\ell}}\\sum\\limits_{t=1}^{n_{\\ell}}a_{stij}^{\\ell}\\psi^\\ell_{s,t}.\n$$\nHence $a_{stij}^{\\ell}=(\\mathbf A_\\ell \\phi^\\ell_{i,j}, \\phi^\\ell_{s,t})$. From $(\\mathbf A_{\\ell+1}\\phi^{\\ell+1}_{i,j}, \\phi^{\\ell+1}_{s,t})=(\\mathbf A_\\ell\\phi^{\\ell+1}_{i,j}, \\phi^{\\ell+1}_{s,t})$, we have\n$$\na_{stij}^{\\ell+1}=\\sum_{r=1}^{m_\\ell}\\sum_{q=1}^{n_\\ell}\\left(\\sum_{k=1}^{m_\\ell}\\sum_{m=1}^{n_\\ell} P_{kmij}^{\\ell,{\\ell+1}} a_{rqkm}^\\ell\\right)P_{rqst}^{\\ell,{\\ell+1}} \n$$ \nWhere $P^{\\ell,{\\ell+1}}=(P_{rqst}^{\\ell,{\\ell+1}})$ is the tensor representation of the prolongation $P_{\\ell+1}^{\\ell}$.\n\n\nConsider the finite element method on two different grids \n$\\mathcal T_\\ell,~\\mathcal T_{\\ell+1},~h_{\\ell+1}=2h_\\ell, \\mathcal V_{\\ell+1}\\subset \\mathcal V_{\\ell}$. \nWith the restriction $R_{\\ell}^{\\ell+1}$ and prolongation $P_{\\ell+1}^\\ell$ obtained in Lemma \\ref{ris:plon}, we have the following relationship to define coarse operation\n\\begin{equation}\\label{eq:def_coarse}\n\\begin{aligned}\n A_{\\ell+1}&=R_{\\ell}^{\\ell+1}  A_{\\ell}P_{\\ell+1}^{\\ell}.  \\\\\n&= R \\ast_2 A_\\ell \\ast (R\\ast_2^\\top),   \\quad (\\ell = 1:J-1),\n\\end{aligned}\n\\end{equation}\nwith $A_1 = A$. \n\\begin{theorem}\nIf $R$ is consistent with $A_\\ell$ which means that $R$ should be linear or bi-linear as $A_\\ell$, then we have\nthe $A_{\\ell+1}$ operation in coarse grid defined in \\eqref{eq:def_coarse} is the same with $A_\\ell$.\n\\end{theorem}\n\\begin{proof}\nFor any $u_{\\ell+1}$ and $v_{\\ell+1}$ in $\\mathcal V_{\\ell+1}$, it remains to prove that\n$$\n(A_\\ell P_{\\ell+1}^\\ell u_{\\ell+1},P_{\\ell+1}^\\ell v_{\\ell+1}) = (A_{\\ell+1}u_{\\ell+1}, v_{\\ell+1})\n$$\nwhere $A_\\ell$ and $A_{\\ell+1}$ are the tensor representation of $\\mathbf A_\\ell$ and $\\mathbf A_{\\ell+1}$.\n\nWe can also view them as convolutions. By the definition of operators $R_{\\ell}^{\\ell+1}$ and $P_{\\ell+1}^\\ell$, a direct computation gives the above result.\n\\end{proof}\n\\begin{proof}\nBy the definition above, we have that\n\\begin{equation}\nA_{\\ell+1} (v) = \\mathcal S\\left( (R\\ast A_{\\ell} \\ast R )\\ast \\mathcal S^\\top(v) \\right),\n\\end{equation}\nbecause of the properties of convolution we know that \n\\begin{equation}\\label{eq:K=RAR}\n(R\\ast A_{\\ell} \\ast R )\\ast = K \\ast,\n\\end{equation}\nfor some \n$$\nK \\in \\mathbb{R}^{7\\times 7}.\n$$\nThen we have the next computation for $A_{\\ell+1}(v)$\n\\begin{equation}\\label{eq:compute_A}\n\\begin{aligned}\n[A_{\\ell+1} (v)]_{i,j} &= [\\mathcal S\\left( (R\\ast A_{\\ell} \\ast R )\\ast \\mathcal S^\\top(v) \\right)]_{i,j}, \\\\\n&= [ K\\ast  \\mathcal S^\\top(v)]_{2i,2j}, \\\\\n&= \\sum_{p,q=-3}^{3} [\\mathcal S^\\top (v)]_{2i+p, 2j+q} K_{p,q}, \\\\\n&= \\sum_{p,q=-1}^1  [\\mathcal S^\\top (v)]_{2(i+p), 2(j+q)} K_{2p,2q}, \\\\\n&= \\sum_{p,q=-1}^1  v_{i+p, j+q} \\hat K_{p,q}, \\\\\n\\end{aligned}\n\\end{equation}\n\t\nThus to say, we have\n\\begin{equation}\nA_{\\ell+1}(v) =  \\hat K \\ast v,\n\\end{equation}\nwith \n$$\n\\hat K_{p,q} = K_{2p,2q}, \\quad p,q = -1,0,1,\n$$\nwith $K$ is defined in \\eqref{eq:K=RAR}.\n\nThen by the direct computation of \\eqref{eq:K=RAR} as \n$$\n(R\\ast A_{\\ell} \\ast R )\\ast = K \\ast\n$$\nand take the even index we have that\n\\begin{equation}\nA_{\\ell+1} = \\hat K = A_\\ell,\n\\end{equation}\nif $R$ is consistent with $A_\\ell$ which means that $R$ should be linear or bi-linear as $A_\\ell$.\t\n\\end{proof}\n\n\n", "meta": {"hexsha": "6b4c6e86f251a2c5a614994047d774006a9568f0", "size": 13794, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.11-XuNet.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.11-XuNet.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.11-XuNet.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.5243553009, "max_line_length": 383, "alphanum_fraction": 0.6417282877, "num_tokens": 5813, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.793105941403651, "lm_q1q2_score": 0.7119674740818834}}
{"text": "% !TEX root = ../thesis.tex\n\n\\chapter{Introduction}\nOne of the problems in plasma physics is the issue of plasma confinement.\nHow does one confine a dense plasma to a reactor vessel for a sustained period of time?\nPlasmas are extremely hot,\nso any contact with the walls of a reactor would be fatal.\nSolving this problem is an important step towards nuclear fusion,\na sustainable energy source that unlike nuclear fission does not produce radioactive byproducts.\nCurrent efforts focus on repelling the plasma\nfrom the walls of the reactor with intense magnetic fields,\nalthough other options might be feasible.\nOne approach is that of self-stability,\nwhere the magnetic field of the plasma prevents it from deforming too much.\nIn this thesis we will investigate how self-stability can arise,\nand we will construct a few magnetic fields with desirable properties.\n\nAs we will see,\nlinking of the field lines is important for these magnetic fields.\nThis leads us to the Hopf map,\na differentiable function from $S^3$ to $S^2$ of which the fibres,\nthe inverse images of points on $S^2\\!$,\nare linked.\nBefore we can define the Hopf map,\nwe will recall some of the theory involved in chapter~\\ref{chap:preliminaries},\nand we will investigate a few useful group actions.\nIn chapter~\\ref{chap:the-hopf-map} we will turn to the Hopf map itself.\nVia stereographic projection we can visualise the fibres in $\\R^3\\!$,\nand with ideas from topology we can quantify linking of the fibres.\nTo construct a vector field with field lines\nbased on the fibres of the Hopf map,\nwe use tools from differential geometry developed in chapter~\\ref{chap:differential-forms}.\nFinally we make the link to magnetohydrodynamics in chapter~\\ref{chap:magnetohydrodynamics}.\nThe Hopf invariant,\na quantity that appears purely algebraic at first sight,\nwill turn out to have a direct physical interpretation as the helicity of a field,\na conserved quantity that plays a role in the stability of plasmas.\n\nChapter~\\ref{chap:preliminaries} through~\\ref{chap:differential-forms}\nare mathematical in nature.\nFor physicists who are not familiar with the formalism,\nor who care about results instead of proofs,\na paragraph with “physical interpretation” has been added after every section whenever possible.\nWhen the theory does not admit a direct physical interpretation,\na paragraph “informal summary” has been added instead.\n", "meta": {"hexsha": "1d4143d4cf2d041e7926fd19fadd47daa191f314", "size": 2388, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/introduction.tex", "max_stars_repo_name": "ruud-v-a/bscthesis", "max_stars_repo_head_hexsha": "7dfc0003ed842b556d530f2ffb6313856ce17721", "max_stars_repo_licenses": ["CNRI-Python", "Naumen", "Condor-1.1", "MS-PL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/introduction.tex", "max_issues_repo_name": "ruud-v-a/bscthesis", "max_issues_repo_head_hexsha": "7dfc0003ed842b556d530f2ffb6313856ce17721", "max_issues_repo_licenses": ["CNRI-Python", "Naumen", "Condor-1.1", "MS-PL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/introduction.tex", "max_forks_repo_name": "ruud-v-a/bscthesis", "max_forks_repo_head_hexsha": "7dfc0003ed842b556d530f2ffb6313856ce17721", "max_forks_repo_licenses": ["CNRI-Python", "Naumen", "Condor-1.1", "MS-PL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.9130434783, "max_line_length": 96, "alphanum_fraction": 0.8023450586, "num_tokens": 534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199754937772, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.7119528321414261}}
{"text": "\\chapter{Example: Euclid's Theorem}\n\\label{chap:euclid}\n\n\\setcounter{sessioncount}{0}\n\nIn this chapter, we prove in \\holn{} that for every number, there is a\nprime number that is larger, \\ie, that the prime numbers form an\ninfinite sequence. This proof has been excerpted and adapted from a\nmuch larger example due to John Harrison, in which he proved the $n =\n4$ case of Fermat's Last Theorem. The proof development is intended\nto serve as an introduction to performing high-level interactive proofs\nin \\holn.\\footnote{The proofs discussed below may be found in\n\\texttt{examples/euclid.sml} of the \\HOL{} distribution.}\nMany of the details may be difficult to grasp for the novice reader;\nnonetheless, it is recommended that the example be followed through in\norder to gain a true taste of using \\HOL{} to prove non-trivial theorems.\n\nSome tutorial descriptions of proof systems show the system performing\namazing feats of automated theorem proving. In this example, we have\n\\textit{not} taken this approach; instead, we try to show how one\nactually goes about the business of proving theorems in \\holn{}: when\nmore than one way to prove something is possible, we will consider the\nchoices; when a difficulty arises, we will attempt to explain how to fight\none's way clear.\n\nOne `drives' \\holn{} by interacting with the ML top-level loop. In this\ninteraction style, ML function calls are made to bring in\nalready-established logical context, \\eg, via \\ml{load}; to define\nnew concepts, \\eg, via \\ml{Hol\\_datatype},  \\ml{Define}, and \\ml{Hol\\_reln};\nand to perform proofs using the goalstack interface, and\nthe proof tools from \\ml{bossLib} (or if they fail to do the job, from\nlower-level libraries).\n\nLet's get started. First, we start the system, with the command \\ml{<holdir>/bin/hol}.\nWe then ``\\ml{open}'' the arithmetic theory; this means that all of the \\ML{} bindings\nfrom the \\HOL{} theory of arithmetic are made available at the top level.\n\\begin{session}\n\\begin{verbatim}\n- open arithmeticTheory;\n  ...\n\\end{verbatim}\n\\end{session}\nWe now begin the formalization. In order to define the concept of\nprime number, we first need to define the \\emph{divisibility} relation:\n\n\\begin{session}\n\\begin{verbatim}\n- val divides_def = Define `divides a b = ?x. b = a * x`;\n\nDefinition has been stored under \"divides_def\".\n> val divides_def = |- !a b. divides a b = ?x. b = a * x : thm\n\\end{verbatim}\n\\end{session}\n\nThe definition is added to the current theory with the name\n\\ml{divides\\_def}, and also returned from the invocation of\n\\ml{Define}. We take advantage of this and make an \\ML{} binding of\nthe name \\ml{divides\\_def} to the definition. In the usual way of\ninteracting with \\HOL, such an \\ML{} binding is made for each\ndefinition and (useful) proved theorem: the \\ML{} environment is thus\nbeing used as a convenient place to hold definitions and theorems for\nlater reference in the session.\n\nWe want to treat \\ml{divides} as a (non-associating) infix:\n\\begin{session}\n\\begin{verbatim}\n- set_fixity \"divides\" (Infix(NONASSOC, 450));\n\\end{verbatim}\n\\end{session}\nNext we define the property of a number being \\emph{prime}: a number $p$ is\nprime if and only if it is not equal to $1$ and it has no divisors other\nthan $1$ and itself:\n\n\\begin{session}\n\\begin{verbatim}\n- val prime_def =\n    Define `prime p = ~(p=1) /\\ !x. x divides p ==> (x=1) \\/ (x=p)`;\n\nDefinition has been stored under \"prime_def\".\n> val prime_def =\n    |- !p. prime p = ~(p = 1) /\\ !x. x divides p ==> (x = 1) \\/ (x = p)\n    : thm\n\\end{verbatim}\n\\end{session}\n\nThat concludes the definitions to be made. Now we ``just'' have to prove\nthat there are infinitely many prime numbers. If we were coming to this\nproblem fresh, then we would have to go through a not-well-understood\nand often tremendously difficult process of finding the right lemmas\nrequired to prove our target theorem.\\footnote{This is of course a\ngeneral problem in doing any kind of proof.} Fortunately, we are working\nfrom an already completed proof and can devote ourselves to the far\nsimpler problem of explaining how to prove the required theorems.\n\n\\paragraph{Proof tools}\nThe development will illustrate that there is often more than one way to\ntackle a HOL proof, even if one has only a single (informal) proof in\nmind. In this example, we often \\emph{find} proofs by using\nthe rewriter \\ml{RW\\_TAC} to unwind definitions and perform basic\nsimplifications, often reducing a goal to its essence.\n\\begin{session}\n\\begin{verbatim}\nRW_TAC;\nval it = fn :simpset -> thm list -> term list * term ->\n             (term list * term) list * (thm list -> thm)\n\\end{verbatim}\n\\end{session}\nThe ML type of \\ml{RW\\_TAC} is\n\\ml{:simpset -> thm list -> tactic}.\\footnote{Unfortunately, the MoscowML system does not print out\nthe type of tactics in its abbreviated form.}\nWhen \\ml{RW\\_TAC} is applied to a \\textit{simpset}---for this example it will\nalways be \\ml{arith\\_ss}---and a list of theorems, the\ntheorems will be added to the simpset as supplementary rewrite rules.\nWe will see that \\ml{arith\\_ss} is also somewhat knowledgeable about\narithmetic.\\footnote{Linear arithmetic especially: purely universal\nformulas involving the operators {\\tt SUC}, $+$, $-$, numeric\nliterals, $<$, $\\leq$, $>$, $\\geq$, $=$, and multiplication by numeric\nliterals.}\nSometimes simplification with \\ml{RW\\_TAC} proves the goal immediately.\nOften however, we are left with a goal that requires some study before one\nrealizes what lemmas are needed to conclude the proof. Once these lemmas\nhave been proven, or located in ancestor theories,\n\\ml{METIS\\_TAC}\\footnote{\\ml{METIS\\_TAC}\nperforms resolution-style first-order proof search.} can\nbe invoked with them, with the expectation that it will find the right\ninstantiations needed to finish the proof. Note that these two operations,\nsimplification and resolution-style automatic proof search, will not suffice to\nperform all the proofs in this example; in particular, our development will\nalso need case analysis and induction.\n\n\\paragraph{Finding theorems}\nThis raises the following question: how does one find the right lemmas\nand rewrite rules to use? This is quite a problem, especially since the number of\nancestor theories, and the theorems in them,  is large. There are several\npossibilities\n\\begin{itemize}\n\\item The help system can be used to look up definitions and\ntheorems, as well as proof procedures; for example, an invocation of\n{\\small\n\\begin{verbatim}\n   help \"arithmeticTheory\"\n\\end{verbatim}}\nwill display all the definitions and theorems that have been stored in\nthe theory of arithmetic. However, the complete name of the item being\nsearched for must be known before the help system is useful, so the following\ntwo search facilities are often more useful.\n\\item  \\verb+DB.match+ allows the use of patterns to locate the\nsought-for theorem. Any stored theorem having an instance of the pattern\nas a subterm will be returned.\n\\item \\verb+DB.find+ will use fragments of names as keys with which to\nlookup information.\n\\end{itemize}\n\n\\paragraph{Tactic composition}\nOnce a proof of a proposition has been found, it is customary, although\nnot necessary, to embark on a process of \\emph{revision}, in which the\noriginal sequence of tactics is composed into a single tactic. Sometimes\nthe resulting tactic is much shorter, and more aesthetically pleasing in\nsome sense. Some users spend a fair bit of time polishing these tactics,\nalthough there doesn't seem much real benefit in doing so, since they\nare \\emph{ad hoc} proof recipes, one for each theorem. In the\nfollowing, we will show how this is done in a few cases.\n\n\\section{Divisibility}\n\nWe start by proving a number of theorems about the \\verb+divides+\nrelation.  We will see that each of these initial theorems can be\nproved with a single invocation of \\ml{METIS\\_TAC}. Both \\ml{RW\\_TAC}\nand \\ml{METIS\\_TAC} are quite powerful reasoners, and the choice of a\nreasoner in a particular situation is a matter of experience.  The\nmajor reason that \\ml{METIS\\_TAC} works so well is that \\verb+divides+\nis defined by means of an existential quantifier, and \\ml{METIS\\_TAC}\nis quite good at automatically instantiating existentials in the\ncourse of proof. For a simple example, consider proving $\\forall x.\\\nx\\; \\mathtt{divides}\\; 0$. A new proposition to be proved is entered\nto the proof manager via ``\\ml{g}'', which starts a fresh goalstack:\n\n\\begin{session}\n\\begin{verbatim}\n- g `!x. x divides 0`;\n\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         !x. x divides 0\n\n     : proofs\n\\end{verbatim}\n\\end{session}\nThe proof manager tells us that it has only one proof to manage, and\nechoes the given goal.  Now we expand the definition of\n\\verb+divides+. Notice that $\\alpha$-conversion takes place in order to\nkeep distinct the $x$ of the goal and the $x$ in the definition of\n\\ml{divides}:\n\\begin{session}\n\\begin{verbatim}\n- e (RW_TAC arith_ss [divides_def]);\n\nOK..\n1 subgoal:\n> val it =\n    ?x'. (x = 0) \\/ (x' = 0)\n\\end{verbatim}\n\\end{session}\nIt is of course quite easy to instantiate the existential quantifier by\nhand.\n\\begin{session}\n\\begin{verbatim}\n- e (EXISTS_TAC ``0``);\n\nOK..\n1 subgoal:\n> val it =\n    (x = 0) \\/ (0 = 0)\n\\end{verbatim}\n\\end{session}\nThen a simplification step finishes the proof.\n\\begin{session}\n\\begin{verbatim}\n- e (RW_TAC arith_ss []);\nOK..\n\nGoal proved.\n|- (x = 0) \\/ (0 = 0)\n\nGoal proved.\n|- ?x'. (x = 0) \\/ (x' = 0)\n> val it =\n    Initial goal proved.\n    |- !x. x divides 0\n\\end{verbatim}\n\\end{session}\n\nWhat just happened here? The application of \\ml{RW\\_TAC} to the goal\ndecomposed it to an empty list of subgoals; in other words the goal was\nproved by \\ml{RW\\_TAC}.  Once a goal has been proved, it is popped off\nthe goalstack, prettyprinted to the output, and the theorem becomes\navailable for use by the level of the stack. When all the sub-goals\nrequired by \\textit{that} level are proven, the corresponding goal at\nthat level can be proven too.  This `unwinding' process continues until\nthe stack is empty, or until it hits a goal with more than one remaining\nunproved subgoal. This process may be hard to\nvisualize,\\footnote{Perhaps since we have used a stack to implement what\nis notionally a tree!} but that doesn't matter, since the goalstack was\nexpressly written to allow the user to ignore such details.\n\nIf the three interactions are joined together with \\ml{THEN} to\nform a single tactic, we can try the proof again from the\nbeginning (using the \\ml{restart} function) and this time it will\ntake just one step:\n\\begin{session}\n\\begin{verbatim}\n- restart();\n>   ...\n\n- e (RW_TAC arith_ss [divides_def] THEN EXISTS_TAC ``0``\n     THEN RW_TAC arith_ss []);\nOK..\n\n> val it =\n    Initial goal proved.\n    |- !x. x divides 0\n\\end{verbatim}\n\\end{session}\nWe have seen one way to prove the theorem. However, as mentioned\nearlier, there is another: one can let \\ml{METIS\\_TAC} expand the\ndefinition of \\ml{divides} and find the required instantiation for\n\\verb+x'+ from the theorem \\ml{MULT\\_CLAUSES}.\\footnote{You might\n  like to try typing \\ml{MULT\\_CLAUSES} into the interactive loop\n  to see exactly what it states.}\n\\begin{session}\n\\begin{verbatim}\n- restart();\n>   ...\n\n- e (METIS_TAC [divides_def, MULT_CLAUSES]);\nOK..\nmetis: r[+0+10]+0+0+0+1+2#\n> val it =\n    Initial goal proved.\n    |- !x. x divides 0\n\\end{verbatim}\n\\end{session}\nAs it runs, \\ml{METIS\\_TAC} prints out some possibly interesting\ndiagnostics. In any case, having done our proof inside the goalstack package,\n    we now want to have access to the theorem value that we have\n    proved.  We use the \\ml{top\\_thm} function to do this, and then\n    use \\ml{drop} to dispose of the stack:\n\\begin{session}\n\\begin{verbatim}\n- val DIVIDES_0 = top_thm();\n\n> val DIVIDES_0 = |- !x. x divides 0 : thm\n\n- drop();\nOK..\n> val it = There are currently no proofs. : proofs\n\\end{verbatim}\n\\end{session}\n\nWe have used \\ml{METIS\\_TAC} in this way to prove the following\ncollection of theorems about \\ml{divides}. As mentioned previously, the\ntheorems supplied to \\ml{METIS\\_TAC} in the following proofs did not\n(usually) come from thin air: in most cases some exploratory work with\n\\ml{RW\\_TAC} was done to open up definitions and see what lemmas would\nbe required by \\ml{METIS\\_TAC}.\n\n\\begin{description}\n\\label{euclid:extra-proofs}\n\\item [\\small{({\\it DIVIDES\\_0\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+!x. x divides 0+ \\\\ \\hline\n \\verb+METIS_TAC [divides_def, MULT_CLAUSES]+\n\\end{tabular}\n\n\\item[\\small{({\\it DIVIDES\\_ZERO\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+!x. 0 divides x = (x = 0)+ \\\\ \\hline\n \\verb+METIS_TAC [divides_def, MULT_CLAUSES]+\n\\end{tabular}\n\n\\item[\\small{({\\it DIVIDES\\_ONE\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+!x. x divides 1 = (x = 1)+ \\\\ \\hline\n \\verb+METIS_TAC [divides_def, MULT_CLAUSES, MULT_EQ_1]+\n\\end{tabular}\n\n\\item[\\small{({\\it DIVIDES\\_REFL\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+!x. x divides x+ \\\\ \\hline\n \\verb+METIS_TAC [divides_def, MULT_CLAUSES]+ \\\\\n\\end{tabular}\n\n\\item[\\small{({\\it DIVIDES\\_TRANS\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+!a b c. a divides b /\\ b divides c ==> a divides c+ \\\\ \\hline\n \\verb+METIS_TAC [divides_def, MULT_ASSOC]+ \\\\\n\\end{tabular}\n\\item[\\small{({\\it DIVIDES\\_ADD\\/})}]\n\\begin{tabular}[t]{l}\n\\verb|!d a b. d divides a /\\ d divides b ==> d divides (a+b)| \\\\ \\hline\n \\verb|METIS_TAC [divides_def,LEFT_ADD_DISTRIB]|\n\\end{tabular}\n\n\\item[\\small{({\\it DIVIDES\\_SUB\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+!d a b. d divides a /\\ d divides b ==> d divides (a-b)+ \\\\ \\hline\n \\verb+METIS_TAC [divides_def, LEFT_SUB_DISTRIB]+ \\\\\n\\end{tabular}\n\n\\item[\\small{({\\it DIVIDES\\_ADDL\\/})}]\n\\begin{tabular}[t]{l}\n\\verb|!d a b. d divides a /\\ d divides (a+b) ==> d divides b| \\\\ \\hline\n \\verb+METIS_TAC [ADD_SUB, ADD_SYM, DIVIDES_SUB]+ \\\\\n\\end{tabular}\n\n\\item[\\small{({\\it DIVIDES\\_LMUL\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+!d a x. d divides a ==> d divides (x * a)+ \\\\ \\hline\n \\verb+METIS_TAC [divides_def, MULT_ASSOC, MULT_SYM]+ \\\\\n\\end{tabular}\n\n\\item[\\small{({\\it DIVIDES\\_RMUL\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+!d a x. d divides a ==> d divides (a * x)+ \\\\ \\hline\n \\verb+METIS_TAC [MULT_SYM, DIVIDES_LMUL]+ \\\\\n\\end{tabular}\n\n\\end{description}\n\n\\noindent We'll assume that the above proofs have been performed, and\nthat the appropriate ML names have been given to all of the theorems.\nNow we encounter a lemma about divisibility that doesn't succumb to a\nsingle invocation of \\ml{METIS\\_TAC}:\n\\begin{description}\n\\item [\\small{({\\it DIVIDES\\_LE\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+!m n. m divides n ==> m <= n \\/ (n = 0)+ \\\\ \\hline\n\\verb+RW_TAC arith_ss [divides_def]+ \\\\\n\\verb+   THEN Cases_on `x`+ \\\\\n\\verb+   THEN RW_TAC arith_ss [MULT_CLAUSES]+ \\\\\n\\end{tabular}\n\\end{description}\nLet's see how this is proved. The easiest way to start is to simplify\nwith the definition of \\ml{divides}:\n\\begin{session}\n\\begin{verbatim}\n- g `!m n . m divides n ==> m <= n \\/ (n = 0)`;\n>   ...\n\n- e (RW_TAC arith_ss [divides_def]);\n\n1 subgoal:\n> val it =\n    m <= m * x \\/ (m * x = 0)\n\\end{verbatim}\n\\end{session}\n\nConsidering the goal, we basically have three choices: (1) find a\ncollection of lemmas that together imply the goal and use\n\\ml{METIS\\_TAC}; (2) do a case split on $m$; or (3) do a case split on\n$x$. The first doesn't seem simple, because the goal doesn't really fit\nin the `shape' of any pre-proved theorem(s) that the author knows\nabout. Although option (2) will be rejected in the end, let's try it\nanyway. To perform the case split, we use \\verb+Cases_on+, which stands\nfor ``find the given term in the goal and do a case split on the\npossible means of building it out of datatype constructors''. Since the\noccurrence of $m$ in the goal has type $num$, the cases considered will\nbe whether $m$ is $0$ or a successor.\n\\begin{session}\n\\begin{verbatim}\n- e (Cases_on `m`);\nOK..\n2 subgoals:\n> val it =\n    SUC n <= SUC n * x \\/ (SUC n * x = 0)\n\n    0 <= 0 * x \\/ (0 * x = 0)\n\\end{verbatim}\n\\end{session}\n\\noindent The first subgoal (the last one printed) is trivial:\n\n\\begin{session}\n\\begin{verbatim}\n- e (RW_TAC arith_ss []);\nOK..\n\nGoal proved.\n  ...\n\nRemaining subgoals:\n> val it =\n    SUC n <= SUC n * x \\/ (SUC n * x = 0)\n\\end{verbatim}\n\\end{session}\n\\noindent Let's try \\ml{RW\\_TAC} again:\n\\begin{session}\n\\begin{verbatim}\n- e (RW_TAC arith_ss []);\nOK..\n1 subgoal:\n> val it =\n    SUC n <= x * SUC n \\/ (x = 0)\n\\end{verbatim}\n\\end{session}\nThe right disjunct has been simplified; however, the left disjunct has\nfailed to expand the definition of multiplication in the expression\n$\\mathtt{SUC}\\ n * x$, which would have been convenient. In fact, it has\nchanged it to $x * \\mathtt{SUC}\\ n$, which is inconvenient.\nWhy, when \\verb+arith_ss+ and hence \\ml{RW\\_TAC} is supposed to be expert in\narithmetic? The answer is twofold: first, the recursive clauses for addition and\nmultiplication are not in \\verb+arith_ss+ because uncontrolled\napplication of them by the rewriter seems, in general, to make some\nproofs \\emph{more} complicated, rather than simpler; second, the simplifier\nwill rearrange arithmetical terms to make some automated proofs simpler. So\nthe absence of the recursive clauses for multiplication\nmeans that $\\mathtt{SUC}\\ n * x$ does not expand to $(n * x) + x$;\ninstead, the rearrangement yields $x * \\mathtt{SUC}\\; n$. OK, so let's\nadd in the definition of multiplication. This uncovers a new problem: how\nto locate this definition. The function\n\\begin{holboxed}\n\\begin{verbatim}\n   DB.match : string list -> term\n                -> ((string * string) * (thm * class)) list\n\\end{verbatim}\n\\end{holboxed}\n\n\\noindent\nis often helpful for such tasks. It takes a list of theory names, and\na pattern, and looks in the list of theories for any theorem,\ndefinition, or axiom that has an instance of the pattern as a subterm.\nIf the list of theory names is empty, then all loaded theories are\nincluded in the search. Let's look in the theory of arithmetic for the\nsubterm to be rewritten.\n\n\\begin{session}\n\\begin{verbatim}\n- DB.match [\"arithmetic\"] ``SUC n * x``;\n\n> val it =\n   [((\"arithmetic\", \"FACT\"),\n     (|- (FACT 0 = 1) /\\ !n. FACT (SUC n) = SUC n * FACT n, Def)),\n    ((\"arithmetic\", \"LESS_MULT_MONO\"),\n     (|- !m i n. SUC n * m < SUC n * i = m < i, Thm)),\n    ((\"arithmetic\", \"MULT\"),\n     (|- (!n. 0 * n = 0) /\\ !m n. SUC m * n = m * n + n, Def)),\n    ((\"arithmetic\", \"MULT_CLAUSES\"),\n     (|- !m n.\n           (0 * m = 0) /\\ (m * 0 = 0) /\\ (1 * m = m) /\\ (m * 1 = m) /\\\n           (SUC m * n = m * n + n) /\\ (m * SUC n = m + m * n), Thm)),\n    ((\"arithmetic\", \"MULT_LESS_EQ_SUC\"),\n     (|- !m n p. m <= n = SUC p * m <= SUC p * n, Thm)),\n    ((\"arithmetic\", \"MULT_MONO_EQ\"),\n     (|- !m i n. (SUC n * m = SUC n * i) = m = i, Thm)),\n    ((\"arithmetic\", \"ODD_OR_EVEN\"),\n     (|- !n. ?m. (n = SUC (SUC 0) * m) \\/ (n = SUC (SUC 0) * m + 1), Thm))]\n   : ...\n\\end{verbatim}\n\\end{session}\n\nFor some, this returns slightly too much information; however, we can\nfocus the search by stipulating that the pattern look like a rewrite\nrule:\n\n\\begin{session}\n\\begin{verbatim}\n- DB.match [] ``SUC n * x = M``;\n\n> val it =\n    [((\"arithmetic\", \"MULT\"),\n      (|- (!n. 0 * n = 0) /\\ !m n. SUC m * n = m * n + n, Def)),\n     ((\"arithmetic\", \"MULT_CLAUSES\"),\n      (|- !m n.\n            (0 * m = 0) /\\ (m * 0 = 0) /\\ (1 * m = m) /\\ (m * 1 = m) /\\\n            (SUC m * n = m * n + n) /\\ (m * SUC n = m + m * n), Thm)),\n     ((\"arithmetic\", \"MULT_MONO_EQ\"),\n      (|- !m i n. (SUC n * m = SUC n * i) = m = i, Thm))] : ...\n\\end{verbatim}\n\\end{session}\n\nEither {\\small\\verb+arithmeticTheory.MULT+} or\n{\\small\\verb+arithmeticTheory.MULT_CLAUSES+} would be acceptable; we\nchoose the latter.\n\n\\begin{session}\n\\begin{verbatim}\n- b();\n  ...\n\ne (RW_TAC arith_ss [MULT_CLAUSES]);\n\nOK..\n1 subgoal:\n> val it =\n    SUC n <= x + n * x \\/ (x = 0)\n\\end{verbatim}\n\\end{session}\nNow we see that, in order to make progress in the proof, we will have to\ndo a case split on $x$ anyway, and that we should have split on it\noriginally. Hence we backup. We will have to backup (undo) three times:\n\\begin{session}\n\\begin{verbatim}\n- b();\n> val it =\n    SUC n <= SUC n * x \\/ (SUC n * x = 0)\n\n- b();\n> val it =\n    SUC n <= SUC n * x \\/ (SUC n * x = 0)\n\n\n    0 <= 0 * x \\/ (0 * x = 0)\n\n- b();\n> val it =\n    m <= m * x \\/ (m * x = 0)\n\\end{verbatim}\n\\end{session}\n\nNow we can go forward and do case analysis on $x$. We will also make a\ncompound tactic invocation, since we already know that we'll have to\ninvoke \\ml{RW\\_TAC} in both branches of the case split. This can be\ndone using \\ml{THEN}.  When $t_1 \\ \\mbox{\\ml{THEN}}\\ t_2$ is applied\nto a goal $g$, first $t_1$ is applied to $g$, giving a list of new\nsubgoals, then $t_2$ is applied to each member of the list. All goals\nresulting from these applications of $t_2$ are gathered together and\nreturned.\n\\begin{session}\n\\begin{verbatim}\n- e (Cases_on `x` THEN RW_TAC arith_ss [MULT_CLAUSES]);\nOK..\n\nGoal proved.\n|- m <= m * x \\/ (m * x = 0)\n> val it =\n    Initial goal proved.\n    |- !m n. m divides n ==> m <= n \\/ (n = 0)\n\\end{verbatim}\n\\end{session}\nThat was easy! Obviously making a case split on $x$ was the right\nchoice. The process of {\\it finding\\/} the proof has now finished, and\nall that remains is for the proof to be packaged up into the single\ntactic we saw above.  Rather than use \\ml{top\\_thm} and the goalstack,\nwe can bypass it and use the \\ml{store\\_thm} function.  This function\ntakes a string, a term and a tactic and applies the tactic to the term\nto get a theorem, and then stores the theorem in the current theory\nunder the given name.\n\\begin{session}\n\\begin{verbatim}\n- val DIVIDES_LE = store_thm (\n     \"DIVIDES_LE\",\n     ``!m n. m divides n ==> m <= n \\/ (n = 0)``,\n     RW_TAC arith_ss  [divides_def]\n       THEN Cases_on `x`\n       THEN RW_TAC arith_ss  [MULT_CLAUSES]);\n\n> val DIVIDES_LE = |- !m n. m divides n ==> m <= n \\/ (n = 0) : thm\n\\end{verbatim}\n\\end{session}\nStoring theorems in our script record of the session in this style\n(rather than with the goalstack) results in a more concise script, and\nalso makes it easier to turn our script into a theory file, as we do\nin section~\\ref{sec:script-to-theory}.\n\n\\subsection{Divisibility and factorial}\n\nThe next lemma, {\\small{\\it DIVIDES\\_FACT\\/}}, says that every number\ngreater than $0$ and $\\leq n$ divides the factorial of\n$n$. Factorial is found at \\verb+arithmeticTheory.FACT+ and has been\ndefined by primitive recursion:\n\\begin{description}\n\\item [\\small{({\\it FACT\\/})}]\n\\begin{minipage}[t]{0.5\\textwidth}\n\\begin{verbatim}\n  (FACT 0 = 1) /\\\n  (!n. FACT (SUC n) = SUC n * FACT n)\n\\end{verbatim}\n\\end{minipage}\n\\end{description}\nA polished proof of {\\small{\\it DIVIDES\\_FACT\\/}} is the\nfollowing\\footnote{This and subsequent proofs use the theorems proved\n  on page~\\pageref{euclid:extra-proofs}, which were added to the \\ML{} environment\n  after being proved.}:\n\\begin{description}\n\\item [\\small{({\\it DIVIDES\\_FACT\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+!m n. 0 < m /\\ m <= n ==> m divides (FACT n)+ \\\\ \\hline\n\\verb+RW_TAC arith_ss [LESS_EQ_EXISTS]+ \\\\\n\\verb+ THEN Induct_on `p`+ \\\\\n\\verb+ THEN RW_TAC arith_ss [FACT,ADD_CLAUSES]+ \\\\\n\\verb+ THENL [Cases_on `m`, ALL_TAC]+ \\\\\n\\verb+ THEN METIS_TAC [FACT, DECIDE ``!x. ~(x < x)``,+ \\\\\n\\verb+                 DIVIDES_RMUL, DIVIDES_LMUL, DIVIDES_REFL]+ \\\\\n\\end{tabular}\n\\end{description}\nWe will examine this proof in detail, so we should first attempt to\nunderstand why the theorem is true. What's the underlying intuition?\nSuppose $0 < m \\leq n$, and so $\\mbox{\\tt FACT}\\ n = 1 * \\cdots * m *\n\\cdots * n$. To show $m\\ \\mbox{\\tt divides}\\ (\\mbox{\\tt FACT}\\ n)$\nmeans exhibiting a $q$ such that $q * m = \\mbox{\\tt FACT}\\ n$. Thus $q\n= \\mbox{\\tt FACT}\\ n \\div m$. If we were to take this approach to the\nproof, we would end up having to find and apply lemmas about $\\div$.\nThis seems to take us a little out of our way; isn't there a proof\nthat doesn't use division? Well yes, we can prove the theorem by\ninduction on $n - m$: in the base case, we will have to prove $n\\;\n\\mbox{\\tt divides}\\ (\\mbox{\\tt FACT}\\; n)$, which ought to be easy; in\nthe inductive case, the inductive hypothesis seems like it should give\nus what we need. This strategy for the inductive case is a bit vague,\nbecause we are trying to mentally picture a slightly complicated\nformula, but we can rely on the system to accurately calculate the\ncases of the induction for us. If the inductive case turns out to be\nnot what we expect, we will have to re-think our approach.\n\\begin{session}\n\\begin{verbatim}\n- g `!m n. 0 < m /\\ m <= n ==> m divides (FACT n)`;\n\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         !m n. 0 < m /\\ m <= n ==> m divides FACT n\n\\end{verbatim}\n\\end{session}\nInstead of directly inducting on $n-m$, we will induct on a witness\nvariable, obtained by use of the theorem \\verb+LESS_EQ_EXISTS+.\n\\begin{session}\n\\begin{verbatim}\n- LESS_EQ_EXISTS;\n> val it = |- !m n. m <= n = (?p. n = m + p) : thm\n\n- e (RW_TAC arith_ss [LESS_EQ_EXISTS]);\nOK..\n1 subgoal:\n> val it =\n    m divides FACT (m + p)\n    ------------------------------------\n       0 < m\n\\end{verbatim}\n\\end{session}\n\\noindent Now we induct on $p$:\n\\begin{session}\n\\begin{verbatim}\n- e (Induct_on `p`);\nOK..\n2 subgoals:\n> val it =\n    m divides FACT (m + SUC p)\n    ------------------------------------\n      0.  0 < m\n      1.  m divides FACT (m + p)\n\n    m divides FACT (m + 0)\n   ------------------------------------\n      0 < m\n\\end{verbatim}\n\\end{session}\n\\noindent The first goal can obviously be simplified:\n\\begin{session}\n\\begin{verbatim}\n- e (RW_TAC arith_ss []);\nOK..\n1 subgoal:\n> val it =\n    m divides FACT m\n    ------------------------------------\n      0 < m\n\\end{verbatim}\n\\end{session}\n\\noindent Now we can do a case analysis on $m$: if it is $0$, we have a\ntrivial goal; if it is a successor, then we can use the definition of\n\\ml{FACT} and the theorems \\ml{DIVIDES\\_RMUL} and\n\\ml{DIVIDES\\_REFL}.\n\\begin{session}\n\\begin{verbatim}\n- e (Cases_on `m`);\nOK..\n2 subgoals:\n> val it =\n    SUC n divides FACT (SUC n)\n    ------------------------------------\n      0 < SUC n\n\n    0 divides FACT 0\n    ------------------------------------\n      0 < 0\n\\end{verbatim}\n\\end{session}\n\n Here the first sub-goal goal has an assumption that is false.  We\n can demonstrate this to the system by using the \\ml{DECIDE}\nfunction to prove a simple fact about arithmetic (namely, that no\nnumber $x$ is less than itself), and then passing the resulting\ntheorem to \\ml{METIS\\_TAC}, which can combine this with the\ncontradictory assumption.\\footnote{Note how the interactive system\n  prints out the proved theorem with \\ml{[.]} before the\n  turnstile.  This notation indicates that a theorem has an\n assumption (the false $0 < 0$ in this case).}\n\n\\begin{session}\n\\begin{verbatim}\n- e (METIS_TAC [DECIDE ``!x. ~(x < x)``]);\nOK..\nmetis: r[+0+4]#\n\nGoal proved.\n [.] |- 0 divides FACT 0\n\nRemaining subgoals:\n> val it =\n    SUC n divides FACT (SUC n)\n    ------------------------------------\n      0 < SUC n\n\\end{verbatim}\n\\end{session}\nUsing the theorems identified above the remaining sub-goal can\nbe proved with \\ml{RW\\_TAC}.\n\n\\begin{session}\n\\begin{verbatim}\n- e (RW_TAC arith_ss [FACT, DIVIDES_LMUL, DIVIDES_REFL]);\nOK..\n\nGoal proved.   ...\n\nRemaining subgoals:\n> val it =\n    m divides FACT (m + SUC p)\n    ------------------------------------\n      0.  0 < m\n      1.  m divides FACT (m + p)\n\\end{verbatim}\n\\end{session}\nThis last step, namely the invocation of \\ml{RW\\_TAC},\ncould also have been accomplished with \\ml{METIS\\_TAC}. Note that\nthe only difference is the use of \\ml{DIVIDES\\_LMUL} in the simplifier\n\\emph{versus} \\ml{DIVIDES\\_RMUL} in \\ml{METIS\\_TAC}. This is due to the\nalready mentioned algebraic rearrangement of arithmetical terms in the simplifier.\n\\begin{session}\n\\begin{verbatim}\n- b();\n> ...\n\n- e (METIS_TAC [FACT, DIVIDES_RMUL, DIVIDES_REFL]);\nOK..\n\nGoal proved.  ...\n\\end{verbatim}\n\\end{session}\nNow we have finished the base case of the induction and can move to the\nstep case. An obvious thing to try is simplification with the\ndefinitions of addition and factorial:\n\\begin{session}\n\\begin{verbatim}\n- e (RW_TAC arith_ss [FACT, ADD_CLAUSES]);\n\nOK..\n1 subgoal:\n> val it =\n    m divides FACT (m + p) * SUC (m + p)\n    ------------------------------------\n      0.  0 < m\n      1.  m divides FACT (m + p)\n\\end{verbatim}\n\\end{session}\n\\noindent And now, by \\ml{DIVIDES\\_RMUL} and the inductive hypothesis, we are\ndone:\n\\begin{session}\n\\begin{verbatim}\n- e (METIS_TAC [DIVIDES_RMUL]);\nOK..\nmetis: r[+0+5]+0+0+0+0+1#\n\nGoal proved.\n  ...\n> val it =\n    Initial goal proved.\n    |- !m n. 0 < m /\\ m <= n ==> m divides FACT n\n\\end{verbatim}\n\\end{session}\nWe have finished the search for the proof, and now turn to the task of\nmaking a single tactic out of the sequence of tactic invocations we have\njust made. We assume that the sequence of invocations has been kept\ntrack of in a file or a text editor buffer. We would thus have something\nlike the following:\n\\begin{hol}\n\\begin{verbatim}\n    e (RW_TAC arith_ss [LESS_EQ_EXISTS]);\n    e (Induct_on `p`);\n    (*1*)\n    e (RW_TAC arith_ss  []);\n    e (Cases_on `m`);\n    (*1.1*)\n    e (METIS_TAC [DECIDE ``!x. ~(x < x)``]);\n    (*1.2*)\n    e (RW_TAC arith_ss [FACT, DIVIDES_LMUL, DIVIDES_REFL]);\n    (*2*)\n    e (RW_TAC arith_ss [FACT, ADD_CLAUSES]);\n    e (METIS_TAC [DIVIDES_RMUL]);\n\\end{verbatim}\n\\end{hol}\n\\noindent\n\nWe have added a numbering scheme to keep track of the branches in the\nproof. We can stitch the above together directly into the following compound\ntactic:\n\n\\begin{hol}\n\\begin{verbatim}\n    RW_TAC arith_ss [LESS_EQ_EXISTS]\n     THEN Induct_on `p`\n     THENL [RW_TAC arith_ss [] THEN Cases_on `m`\n            THENL [METIS_TAC [DECIDE ``!x. ~(x < x)``],\n                   RW_TAC arith_ss [FACT, DIVIDES_LMUL, DIVIDES_REFL]],\n            RW_TAC arith_ss [FACT, ADD_CLAUSES] THEN METIS_TAC [DIVIDES_RMUL]]\n\\end{verbatim}\n\\end{hol}\n\n\\noindent This can be tested to see that we have made no errors:\n\n\\begin{session}\n\\begin{verbatim}\n- restart();\n> ...\n\n- e (RW_TAC arith_ss [LESS_EQ_EXISTS]\n       THEN Induct_on `p` THENL\n       [RW_TAC arith_ss [] THEN Cases_on `m` THENL\n          [METIS_TAC [DECIDE ``!x. ~(x < x)``],\n           RW_TAC arith_ss [FACT, DIVIDES_LMUL, DIVIDES_REFL]],\n        RW_TAC arith_ss [FACT, ADD_CLAUSES] THEN METIS_TAC [DIVIDES_RMUL]]);\nOK..\nmetis: r[+0+5]+0+0+0+0+1#\nmetis: r[+0+4]#\n> val it =\n    Initial goal proved.\n    |- !m n. 0 < m /\\ m <= n ==> m divides FACT n\n\\end{verbatim}\n\\end{session}\n\nFor many users, this would be the end of dealing with this proof: the\ntactic can now be packaged into an invocation of\n\\ml{prove}\\footnote{The \\ml{prove} function takes a term and a tactic\nand attempts to prove the term using the supplied tactic.  It\nreturns the proved theorem if the tactic succeeds.  It doesn't save\nthe theorem to the developing theory.} or \\ml{store\\_thm} and that\nwould be the end of it. However, another user might notice\nthat this tactic could be shortened.\n\nTo start, both arms of the induction start with an invocation of\n\\ml{RW\\_TAC}, and the semantics of \\ml{THEN} allow us to merge the\noccurrences of \\ml{RW\\_TAC} above the \\ml{THENL}. The recast tactic\nis\n\\begin{hol}\n\\begin{verbatim}\n RW_TAC arith_ss [LESS_EQ_EXISTS]\n   THEN Induct_on `p`\n   THEN RW_TAC arith_ss [FACT, ADD_CLAUSES]\n   THENL [Cases_on `m` THENL\n            [METIS_TAC [DECIDE ``!x. ~(x < x)``],\n             RW_TAC arith_ss [FACT, DIVIDES_LMUL, DIVIDES_REFL]],\n          METIS_TAC [DIVIDES_RMUL]]\n\\end{verbatim}\n\\end{hol}\n(Of course, when a tactic has been revised, it should be tested to see\nif it still proves the goal!) Now recall that the use of \\ml{RW\\_TAC}\nin the base case could be replaced by a call to \\ml{METIS\\_TAC}. Thus\nit seems possible to merge the two sub-cases of the base case into a\nsingle invocation of \\ml{METIS\\_TAC}:\n\n\\begin{hol}\n\\begin{verbatim}\n RW_TAC arith_ss [LESS_EQ_EXISTS]\n   THEN Induct_on `p`\n   THEN RW_TAC arith_ss [FACT, ADD_CLAUSES]\n   THENL [Cases_on `m` THEN\n            METIS_TAC[DECIDE ``!x. ~(x<x)``,FACT,DIVIDES_RMUL,DIVIDES_REFL],\n          METIS_TAC [DIVIDES_RMUL]]\n\\end{verbatim}\n\\end{hol}\n\n\\noindent\nFinally, pushing this revisionism nearly to its limit, we'd\nlike there to be only a single invocation of \\ml{METIS\\_TAC} to finish\nthe proof off. The semantics of \\ml{THEN} and \\ml{ALL\\_TAC} come to\nour rescue: we will split on the construction of $m$ in the base case,\nas in the current incarnation of the tactic, but we will let the\ninductive case pass unaltered through the \\ml{THENL}. This is achieved\nby using \\verb+ALL_TAC+, which is a tactic that acts as an identity\nfunction on the goal.\n\\begin{hol}\n\\begin{verbatim}\n   RW_TAC arith_ss [LESS_EQ_EXISTS]\n     THEN Induct_on `p`\n     THEN RW_TAC arith_ss [FACT, ADD_CLAUSES]\n     THENL [Cases_on `m`, ALL_TAC]\n     THEN METIS_TAC [DECIDE ``!x. ~(x < x)``,\n                     FACT, DIVIDES_RMUL, DIVIDES_REFL]\n\\end{verbatim}\n\\end{hol}\n\n\\noindent\nThe result is that there will be three subgoals emerging from the\n\\ml{THENL}: the two sub-cases in the base case and the unaltered step\ncase. Each is proved with a call to \\ml{METIS\\_TAC}. Are we now done?\nNot necessarily. For example, the explicit case split, namely \\ml{Cases\\_on `m`},\ncan be replaced by providing the \\emph{cases} theorem for natural numbers\n(\\ml{num\\_CASES}) to \\ml{METIS\\_TAC}. With this, the case split on $m$ will be\nautomatically generated by \\ml{METIS\\_TAC} as it searches for the proof. Hence we\ncan shorten the tactic again.\n\\begin{session}\n\\begin{verbatim}\n- num_CASES;\n> val it = |- !m. (m = 0) \\/ ?n. m = SUC n : thm\n\n- restart();\n- e (RW_TAC arith_ss [LESS_EQ_EXISTS]\n     THEN Induct_on `p`\n     THEN METIS_TAC [DECIDE ``!x. ~(x < x)``, FACT, num_CASES,\n                     DIVIDES_RMUL, DIVIDES_LMUL, DIVIDES_REFL, ADD_CLAUSES]);\n\\end{verbatim}\n\\end{session}\nWe have now finished our exercise in tactic revision. Certainly, it\nwould be hard to foresee that this final tactic would prove the\ngoal; the required lemmas for the final invocation of \\ml{METIS\\_TAC}\nhave been found by an incremental process of revision.\n\n\\subsection{Divisibility and factorial (again!)}\n\nIn the previous proof, we made an initial simplification step in order\nto expose a variable upon which to induct. However, the proof is\nreally by induction on $n - m$. Can we express this directly? The\nanswer is a qualified yes: the induction can be naturally stated, but\nit leads to somewhat less natural goals.\n\\begin{session}\n\\begin{verbatim}\n- restart();\n\n- e (Induct_on `n - m`);\n\nOK..\n2 subgoals:\n> val it =\n    !n m. (SUC v = n - m) ==> 0 < m /\\ m <= n ==> m divides FACT n\n    ------------------------------------\n      !n m. (v = n - m) ==> 0 < m /\\ m <= n ==> m divides FACT n\n\n    !n m. (0 = n - m) ==> 0 < m /\\ m <= n ==> m divides FACT n\n\\end{verbatim}\n\\end{session}\n    This is slighly hard to read, so we use \\ml{STRIP\\_TAC} and\n    \\ml{REPEAT} to move the antecedents of the goals to the\n    assumptions. Use of \\ml{THEN} ensures that the tactic gets applied\n    in both branches of the induction.\n\\begin{session}\n\\begin{verbatim}\n- b();\n  ...\n\n- e (Induct_on `n - m` THEN REPEAT STRIP_TAC);\n\nOK..\n2 subgoals:\n> val it =\n    m divides FACT n\n    ------------------------------------\n      0.  !n m. (v = n - m) ==> 0 < m /\\ m <= n ==> m divides FACT n\n      1.  SUC v = n - m\n      2.  0 < m\n      3.  m <= n\n\n    m divides FACT n\n    ------------------------------------\n      0.  0 = n - m\n      1.  0 < m\n      2.  m <= n\n\\end{verbatim}\n\\end{session}\nLooking at the first goal, we reason that if $0 = n - m$ and $m\n\\leq n$, then $m = n$. We can prove this fact, using \\ml{DECIDE\\_TAC}\\footnote\n{\\ml{DECIDE\\_TAC} is a decision procedure for a useful class of arithmetical formulas.}\nand add it to the hypotheses by use of the infix operator ``\\ml{by}'':\n\\begin{session}\n\\begin{verbatim}\n- e (`m = n` by DECIDE_TAC);\nOK..\n1 subgoal:\n> val it =\n    m divides FACT n\n    ------------------------------------\n      0.  0 = n - m\n      1.  0 < m\n      2.  m <= n\n      3.  m = n\n\\end{verbatim}\n\\end{session}\n\n\\noindent We can now use \\ml{RW\\_TAC} to propagate the newly derived equality\nthroughout the goal.\n\\begin{session}\n\\begin{verbatim}\n- e (RW_TAC arith_ss []);\n\nOK..\n1 subgoal:\n> val it =\n    m divides FACT m\n    ------------------------------------\n      0.  0 = m - m\n      1.  0 < m\n      2.  m <= m\n\\end{verbatim}\n\\end{session}\n    At this point in the previous proof we did a case analysis on $m$.\n    However, we already have the hypothesis that $m$ is positive\n    (along with two other now useless hypotheses). Thus we know that\n    $m$ is the successor of some number $k$. We might wish to assert\n    this fact with an invocation of ``\\ml{by}'' as follows:\n\\[\n    \\mbox{\\ml{`?k. m = SUC k` by <tactic>}}\n\\]\nBut what is the tactic? If we try \\ml{DECIDE\\_TAC}, it will fail since\nit doesn't handle existential statements. An application of\n\\ml{RW\\_TAC} will also prove to be unsatisfactory. What to do?\n\nWhen such situations occur, it is often best to start a new proof for\nthe required lemma. This can be done simply by invoking ``\\ml{g}''\nagain. A new goalstack will be created and stacked upon the current\none\\footnote{This stacking of proof attempts (goalstacks) is different\n  than the stacking of goals and justifications inside a particular\n  goalstack.}  and an overview of the extant proof attempts will be\nprinted:\n\\begin{session}\n\\begin{verbatim}\n- g `!m. 0 < m ==> ?k. m = SUC k`;\n\n> val it =\n    Proof manager status: 2 proofs.\n    2. Incomplete:\n         Initial goal:\n         !m n. 0 < m /\\ m <= n ==> m divides FACT n\n\n\n         Current goal:\n         m divides FACT m\n         ------------------------------------\n           0.  0 = m - m\n           1.  0 < m\n           2.  m <= m\n\n    1. Incomplete:\n         Initial goal:\n         !m. 0 < m ==> ?k. m = SUC k\n\\end{verbatim}\n\\end{session}\n    Our new goal can be proved quite quickly. Once we have proved it,\n    we can bind it to an ML name and use it in the previous proof, by\n    some sleight of hand with the ``\\ml{before}''\\footnote{An infix\n      version of the {\\tt K} combinator, defined by {\\tt fun (x before\n        y) = x}.} function.\n\\begin{session}\n\\begin{verbatim}\n- e (Cases THEN RW_TAC arith_ss []);\n\nOK..\n> val it =\n    Initial goal proved.\n    |- !m. 0 < m ==> ?k. m = SUC k\n\n- val lem = top_thm() before drop();\n\nOK..\n> val lem = |- !m. 0 < m ==> ?k. m = SUC k : thm\n\\end{verbatim}\n\\end{session}\n\nNow we can return to the main thread of the proof.  The state of the\ncurrent sub-goal of the proof can be displayed using the function\n``\\ml{p}''.\n\n\\begin{session}\n\\begin{verbatim}\n- p ();\n\n> val it =\n    m divides FACT m\n    ------------------------------------\n      0.  0 = m - m\n      1.  0 < m\n      2.  m <= m\n\\end{verbatim}\n\\end{session}\n    Now we can use \\ml{lem} in the proof. Somewhat opportunistically,\n    we will tack on the invocation used in the earlier proof at\n    (roughly) the same point, hoping that it will solve the goal:\n\\begin{session}\n\\begin{verbatim}\n- e (`?k. m = SUC k` by\n     METIS_TAC[lem] THEN RW_TAC arith_ss [FACT, DIVIDES_LMUL, DIVIDES_REFL]);\nOK..\nmetis: r[+0+6]+0+0+0+0+0+1#\n\nGoal proved.   ...\n\nRemaining subgoals:\n> val it =\n    m divides FACT n\n    ------------------------------------\n      0.  !n m. (v = n - m) ==> 0 < m /\\ m <= n ==> m divides FACT n\n      1.  SUC v = n - m\n      2.  0 < m\n      3.  m <= n\n\\end{verbatim}\n\\end{session}\n    It does! That takes care of the base case. For the induction step,\n    things look a bit more difficult than in the earlier proof.\n    However, we can make progress by realizing that the hypotheses\n    imply that $0 < n$ and so, again by \\ml{lem}, we can transform $n$\n    into a successor, thus enabling the unfolding of \\ml{FACT}, as in\n    the previous proof:\n\\begin{session}\n\\begin{verbatim}\n- e (`0 < n` by DECIDE_TAC THEN `?k. n = SUC k` by METIS_TAC [lem]);\nOK..\nmetis: r[+0+8]+0+0+0+0+0+0+2#\n1 subgoal:\n> val it =\n    m divides FACT n\n    ------------------------------------\n      0.  !n m. (v = n - m) ==> 0 < m /\\ m <= n ==> m divides FACT n\n      1.  SUC v = n - m\n      2.  0 < m\n      3.  m <= n\n      4.  0 < n\n      5.  n = SUC k\n\\end{verbatim}\n\\end{session}\n\\noindent The proof now finishes in much the same manner as the previous one:\n\\begin{session}\n\\begin{verbatim}\n- e (RW_TAC arith_ss [FACT, DIVIDES_RMUL]);\nOK..\n\nGoal proved.  ...\n> val it =\n    Initial goal proved.\n    |- !m n. 0 < m /\\ m <= n ==> m divides FACT n\n\\end{verbatim}\n\\end{session}\n\\noindent We leave the details of stitching the proof together to the interested\nreader.\n\n\\section{Primality}\n\nNow we move on to establish some facts about the primality of the\nfirst few numbers: $0$ and $1$ are not prime, but $2$ is. Also, all\nprimes are positive. These are all quite simple to prove.\n\n\\begin{description}\n\n\\item [\\small{({\\it NOT\\_PRIME\\_0\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+~prime 0+ \\\\ \\hline\n\\verb+RW_TAC arith_ss [prime_def,DIVIDES_0]+ \\\\\n\\end{tabular}\n\n\\item [\\small{({\\it NOT\\_PRIME\\_1\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+~prime 1+ \\\\ \\hline\n\\verb+RW_TAC arith_ss [prime_def]+ \\\\\n\\end{tabular}\n\n\\item [\\small{({\\it PRIME\\_2\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+prime 2+ \\\\ \\hline\n\\verb+RW_TAC arith_ss [prime_def]+ \\\\\n\\verb+ THEN METIS_TAC [DIVIDES_LE, DIVIDES_ZERO,+ \\\\\n\\verb+                 DECIDE ``~(2=1)``, DECIDE ``~(2=0)``,+ \\\\\n\\verb+                 DECIDE ``x <= 2 = (x=0) \\/ (x=1) \\/ (x=2)``]+ \\\\\n\\end{tabular}\n\n\\item [\\small{({\\it PRIME\\_POS\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+!p. prime p ==> 0<p+ \\\\ \\hline\n\\verb+Cases THEN RW_TAC arith_ss [NOT_PRIME_0]+ \\\\\n\\end{tabular}\n\\end{description}\n\n\\section{Existence of prime factors}\n\nNow we are in position to prove a more substantial lemma: every number\nother than $1$ has a prime factor. The proof proceeds by a\n\\emph{complete induction} on $n$. Complete induction is\nnecessary since a prime factor won't be the predecessor. After\ninduction, the proof splits into cases on whether $n$ is prime or\nnot. The first case ($n$ is prime) is\ntrivial. In the second case, there must be an $x$ that divides $n$, and\n$x$ is not $1$ or $n$. By {\\small\\it DIVIDES\\_LE}, $n=0$ or $x \\leq n$. If\n$n=0$, then $2$ is a prime that divides $0$. On the other hand, if $x \\leq\nn$, there are two cases: if $x < n$ then we can use the inductive\nhypothesis and by transitivity of divides we are done; otherwise,\n$x=n$ and then we have a contradiction with the fact that $x$ is not 1\nor $n$.  The polished tactic is the following:\n\\begin{description}\n\\item [\\small{({\\it PRIME\\_FACTOR\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+!n. ~(n = 1) ==> ?p. prime p /\\ p divides n+ \\\\ \\hline\n\\verb+completeInduct_on `n`+ \\\\\n\\verb+  THEN RW_TAC arith_ss []+ \\\\\n\\verb+  THEN Cases `prime n` THENL+ \\\\\n\\verb+  [METIS_TAC [DIVIDES_REFL], + \\\\\n\\verb+   `?x. x divides n /\\ ~(x=1) /\\ ~(x=n)` + \\\\\n\\verb+    by METIS_TAC[prime_def]+ \\\\\n\\verb+     THEN METIS_TAC [LESS_OR_EQ, PRIME_2, +\\\\\n\\verb+                  DIVIDES_LE,DIVIDES_TRANS,DIVIDES_0]]+ \\\\\n\\end{tabular}\n\\end{description}\nWe start by invoking complete induction. This gives us an inductive\nhypothesis that holds at every number $m$ strictly smaller than $n$:\n\\begin{session}\n\\begin{verbatim}\n- g `!n. ~(n = 1) ==> ?p. prime p /\\ p divides n`;\n\n- e (completeInduct_on `n`);\nOK..\n1 subgoal:\n> val it =\n    ~(n = 1) ==> ?p. prime p /\\ p divides n\n    ------------------------------------\n      !m. m < n ==> ~(m = 1) ==> ?p. prime p /\\ p divides m\n\\end{verbatim}\n\\end{session}\nWe can move the antecedent to the hypotheses and make our case\nsplit. Notice that the term given to \\ml{Cases\\_on} need not occur in\nthe goal:\n\\begin{session}\n\\begin{verbatim}\n- e (RW_TAC arith_ss [] THEN Cases_on `prime n`);\nOK..\n2 subgoals:\n> val it =\n    ?p. prime p /\\ p divides n\n    ------------------------------------\n      0.  !m. m < n ==> ~(m = 1) ==> ?p. prime p /\\ p divides m\n      1.  ~(n = 1)\n      2.  ~prime n\n\n    ?p. prime p /\\ p divides n\n    ------------------------------------\n      0.  !m. m < n ==> ~(m = 1) ==> ?p. prime p /\\ p divides m\n      1.  ~(n = 1)\n      2.  prime n\n\\end{verbatim}\n\\end{session}\n\\noindent As mentioned, the first case is proved with the reflexivity of\ndivisibility:\n\\begin{session}\n\\begin{verbatim}\n- e (METIS_TAC [DIVIDES_REFL]);\nOK..\nmetis: r[+0+7]+0+0+0+0+1#\n\nGoal proved.  ...\n\\end{verbatim}\n\\end{session}\n\\noindent\nIn the second case, we can get a divisor of $n$ that isn't $1$ or $n$\n(since $n$ is not prime):\n\\begin{session}\n\\begin{verbatim}\n- e (`?x. x divides n /\\ ~(x=1) /\\ ~(x=n)` by METIS_TAC [prime_def]);\nOK..\nmetis: r[+0+11]+0+0+0+0+0+0+1+1+1+1+0+1+1#\n1 subgoal:\n> val it =\n    ?p. prime p /\\ p divides n\n    ------------------------------------\n      0.  !m. m < n ==> ~(m = 1) ==> ?p. prime p /\\ p divides m\n      1.  ~(n = 1)\n      2.  ~prime n\n      3.  x divides n\n      4.  ~(x = 1)\n      5.  ~(x = n)\n\\end{verbatim}\n\\end{session}\nAt this point, the polished tactic simply invokes \\ml{METIS\\_TAC} with\na collection of theorems. We will attempt a more detailed\nexposition. Given the hypotheses, and by {\\small\\it DIVIDES\\_LE}, we can\nassert $x < n \\lor n = 0$ and thus split the proof into two cases:\n\\begin{session}\n\\begin{verbatim}\n- e (`x < n \\/ (n=0)` by METIS_TAC [DIVIDES_LE,LESS_OR_EQ]);\nOK..\nmetis: r[+0+14]+0+0+0+0+0+0+0+0+0+0+1+0+1#\n2 subgoals:\n> val it =\n    ?p. prime p /\\ p divides n\n    ------------------------------------\n      0.  !m. m < n ==> ~(m = 1) ==> ?p. prime p /\\ p divides m\n      1.  ~(n = 1)\n      2.  ~prime n\n      3.  x divides n\n      4.  ~(x = 1)\n      5.  ~(x = n)\n      6.  n = 0\n\n    ?p. prime p /\\ p divides n\n    ------------------------------------\n      0.  !m. m < n ==> ~(m = 1) ==> ?p. prime p /\\ p divides m\n      1.  ~(n = 1)\n      2.  ~prime n\n      3.  x divides n\n      4.  ~(x = 1)\n      5.  ~(x = n)\n      6.  x < n\n\\end{verbatim}\n\\end{session}\nIn the first subgoal, we can see that the antecedents of the inductive\nhypothesis are met and so $x$ has a prime divisor. We can then use the\ntransitivity of divisibility to get the fact that this divisor of $x$ is\nalso a divisor of $n$, thus finishing this branch of the proof:\n\\begin{session}\n\\begin{verbatim}\n- e (METIS_TAC [DIVIDES_TRANS]);\nOK..\nmetis: r[+0+11]+0+0+0+0+0+0+0+1+0+4+1+0+3+0+2+2+1#\n\nGoal proved.\n\\end{verbatim}\n\\end{session}\n\\noindent The remaining goal can be clarified by simplification:\n\\begin{session}\n\\begin{verbatim}\n- e (RW_TAC arith_ss  []);\nOK..\n1 subgoal:\n> val it =\n    ?p. prime p /\\ p divides 0\n    ------------------------------------\n      0.  !m. m < 0 ==> ~(m = 1) ==> ?p. prime p /\\ p divides m\n      1.  ~(0 = 1)\n      2.  ~prime 0\n      3.  x divides 0\n      4.  ~(x = 1)\n      5.  ~(x = 0)\n\n- DIVIDES_0;\n> val it = |- !x. x divides 0 : thm\n\n- e (RW_TAC arith_ss  [it]);\nOK..\n1 subgoal:\n> val it =\n    ?p. prime p\n    ------------------------------------\n      0.  !m. m < 0 ==> ~(m = 1) ==> ?p. prime p /\\ p divides m\n      1.  ~(0 = 1)\n      2.  ~prime 0\n      3.  x divides 0\n      4.  ~(x = 1)\n      5.  ~(x = 0)\n\\end{verbatim}\n\\end{session}\nThe two steps of exploratory simplification have led us to a state where\nall we have to do is exhibit a prime. And we already have one to hand:\n\\begin{session}\n\\begin{verbatim}\n- e (METIS_TAC [PRIME_2]);\nOK..\nmetis: r[+0+6]#\n\nGoal proved.   ...\n> val it =\n    Initial goal proved.\n    |- !n. ~(n = 1) ==> ?p. prime p /\\ p divides n\n\\end{verbatim}\n\\end{session}\nAgain, work now needs to be done to compose and perhaps polish a single\ntactic from the individual proof steps, but we will not describe\nit.\\footnote{Indeed, the tactic can be simplified into complete induction\n followed by an invocation of \\ml{METIS\\_TAC} with suitable lemmas.}\n Instead we move forward, because our ultimate goal is in reach.\n\n\\section{Euclid's theorem}\n\n\\noindent{\\bf Theorem.} Every number has a prime greater than it.\\\\\n\\noindent  {\\it Informal proof.} \\\\\n\\noindent Suppose the opposite; then there's an $n$\nsuch that all $p$ greater than $n$ are not prime. Consider $\\mbox{\\tt\nFACT}(n) + 1$: it's not equal to 1 so, by {\\small{\\it PRIME\\_FACTOR}},\nthere's a prime $p$ that divides it. Note that $p$ also divides\n$\\mbox{\\tt FACT}(n)$ because $p \\leq n$. By {\\small{\\it DIVIDES\\_ADDL}},\nwe have $p=1$. But then $p$ is not prime, which is a contradiction. \\\\\n\\noindent {\\it End of proof}.\n\nA HOL rendition of the proof may be given as follows:\n\\begin{description}\n\\item [\\small{({\\it EUCLID\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+!n. ?p. n < p /\\ prime p+ \\\\ \\hline\n\\verb+SPOSE_NOT_THEN STRIP_ASSUME_TAC+ \\\\\n\\verb!  THEN MP_TAC (SPEC ``FACT n + 1`` PRIME_FACTOR)! \\\\\n\\verb+  THEN RW_TAC arith_ss [FACT_LESS, DECIDE ``~(x=0) = 0<x``]+ \\\\\n\\verb+  THEN METIS_TAC [NOT_PRIME_1, NOT_LESS, PRIME_POS, + \\\\\n\\verb+                  DIVIDES_FACT, DIVIDES_ADDL, DIVIDES_ONE]+ \\\\\n\\end{tabular}\n\\end{description}\nLet's prise this apart and look at it in some detail. A proof by\ncontradiction can be started by using the \\ml{bossLib} function\n\\ml{SPOSE\\_NOT\\_THEN}. With it, one assumes the negation of the\ncurrent goal and then uses that in an attempt to prove falsity\n(\\verb+F+). The assumed negation $\\neg(\\forall n.\\ \\exists p.\\ n < p\n\\land \\mbox{\\tt prime}\\ p)$ is simplified a bit into $\\exists n.\\\n\\forall p.\\ n < p \\supset \\, \\neg \\,\\mbox{\\tt prime}\\ p$ and then is\npassed to the tactic \\ml{STRIP\\_ASSUME\\_TAC}. This moves its argument\nto the assumption list of the goal after eliminating the existential\nquantification on $n$.\n\\begin{session}\n\\begin{verbatim}\n- g `!n. ?p. n < p /\\ prime p`;\n\n- e (SPOSE_NOT_THEN STRIP_ASSUME_TAC);\nOK..\n1 subgoal:\n> val it =\n    F\n    ------------------------------------\n      !p. n < p ==> ~prime p\n\\end{verbatim}\n\\end{session}\nThus we have the hypothesis that all $p$ beyond a certain unspecified\n$n$ are not prime, and our task is to show that this cannot be. At this\npoint we take advantage of Euclid's great inspiration and we build an\nexplicit term from $n$. In the informal proof we are asked to `consider'\nthe term $\\mbox{\\tt FACT}\\ n + 1$.\\footnote{The HOL parser thinks\n$\\mbox{\\tt FACT}\\ n + 1$ is equivalent to $(\\mbox{\\tt FACT}\\ n) + 1$.}\nThis term will have certain properties (\\ie, it has a prime factor) that\nlead to contradiction. Question: how do we `consider' this term in the\nformal HOL proof? Answer: by instantiating a lemma with it and bringing the\nlemma into the proof. The lemma and its instantiation are:\\footnote{The\nfunction {\\tt SPEC} implements the rule of universal specialization.}\n\\begin{session}\n\\begin{verbatim}\n- PRIME_FACTOR;\n> val it = |- !n. ~(n = 1) ==> (?p. prime p /\\ p divides n) : thm\n\n- val th = SPEC ``FACT n + 1`` PRIME_FACTOR;\n> val th =\n    |- ~(FACT n + 1 = 1) ==> (?p. prime p /\\ p divides FACT n + 1)\n\\end{verbatim}\n\\end{session}\nIt is evident that the antecedent of \\ml{th} can be eliminated. In\n\\holn{}, one could do this in a so-called {\\it forward\\/} proof style (by\nproving $\\vdash \\neg(\\mbox{\\tt FACT}\\ n + 1 = 1)$ and then applying {\\it\nmodus ponens}, the result of which can then be used in the proof), or\none could bring \\ml{th} into the proof and simplify it {\\it in\nsitu}. We choose the latter approach.\n\\begin{session}\n\\begin{verbatim}\n- e (MP_TAC (SPEC ``FACT n + 1`` PRIME_FACTOR));\nOK..\n1 subgoal:\n> val it =\n    (~(FACT n + 1 = 1) ==> ?p. prime p /\\ p divides FACT n + 1) ==> F\n    ------------------------------------\n      !p. n < p ==> ~prime p\n\\end{verbatim}\n\\end{session}\n    The invocation \\ml{MP\\_TAC} ($\\vdash M$) applied to a goal\n    $(\\Delta, g)$ returns the goal $(\\Delta, M \\supset g)$. Now we\n    simplify:\n\\begin{session}\n\\begin{verbatim}\n- e (RW_TAC arith_ss []);\nOK..\n2 subgoals:\n> val it =\n    ~prime p \\/ ~(p divides FACT n + 1)\n    ------------------------------------\n      0.  !p. n < p ==> ~prime p\n      1.  prime p\n\n    ~(FACT n = 0)\n    ------------------------------------\n      !p. n < p ==> ~prime p\n\\end{verbatim}\n\\end{session}\n    We recall that zero is less than every factorial, a fact found in\n    \\ml{arithmeticTheory} under the name \\ml{FACT\\_LESS}. Thus we can\n    solve the top goal by simplification:\n\\begin{session}\n\\begin{verbatim}\n- e (RW_TAC arith_ss [FACT_LESS, DECIDE ``!x. ~(x=0) = 0 < x``]);\nOK..\nGoal proved.  ...\n\\end{verbatim}\n\\end{session}\nNotice the `on-the-fly' use of \\verb+DECIDE+ to provide an \\textit{ad hoc}\nrewrite. Looking at the remaining goal, one might think that our aim, to\nprove falsity, has been lost. But this is not so: a goal\n$\\neg P \\lor \\neg Q$ is logically equivalent to $P \\imp Q \\imp \\mathtt{F}$.\nIn the following invocation, we use the equality\n$\\vdash A \\imp B = \\neg A \\lor B$ as a rewrite rule oriented right to left by\nuse of \\ml{GSYM}.\\footnote{Loosely speaking, \\ml{GSYM} swaps the left and\nright hand sides of any equations it finds.}\n\\begin{session}\n\\begin{verbatim}\n- IMP_DISJ_THM;\n> val it = |- !A B. A ==> B = ~A \\/ B : thm\n\n- e (RW_TAC arith_ss [GSYM IMP_DISJ_THM]);\nOK..\n1 subgoal:\n> val it =\n    ~(p divides FACT n + 1)\n    ------------------------------------\n      0.  !p. n < p ==> ~prime p\n      1.  prime p\n     : goalstack\n\\end{verbatim}\n\\end{session}\n\nWe can quickly proceed to show that $p \\ \\mathtt{divides}\\ (\\mathtt{FACT}\\; n)$,\nand thus that $p = 1$, hence that $p$ is not prime, at which point we are done.\nThis can all be packaged into a single invocation of \\ml{METIS\\_TAC}:\n\\begin{session}\n\\begin{verbatim}\n- e (METIS_TAC [DIVIDES_FACT, DIVIDES_ADDL, DIVIDES_ONE,\n                NOT_PRIME_1, NOT_LESS, PRIME_POS]);\nmetis: r[+0+12]+0+0+0+0+0+0+0+1+1+0+0+0+0+1+1+1+1+4#\n\nGoal proved.\n [..] |- ~(p divides FACT n + 1)\n\nGoal proved.\n [.] |- ~prime p \\/ ~(p divides FACT n + 1)\n\nGoal proved.\n [.]\n|- (~(FACT n + 1 = 1) ==> ?p. prime p /\\ p divides FACT n + 1) ==> F\n\nGoal proved.\n [.] |- F\n> val it =\n    Initial goal proved.\n    |- !n. ?p. n < p /\\ prime p : goalstack\n\\end{verbatim}\n\\end{session}\n    Euclid's theorem is now proved, and we can rest. However, this\n    presentation of the final proof will be unsatisfactory to some,\n    because the proof is completely hidden in the invocation of the\n    automated reasoner. Well then, let's try another proof, this time\n    employing the so-called `assertional' style. When used uniformly,\n    this can allow a readable linear presentation that mirrors the\n    informal proof. The following proves Euclid's theorem in the\n    assertional style. We think it is fairly readable, certainly much\n    more so than the standard tactic proof just given.\\footnote{Note\n      that {\\tt CCONTR\\_TAC}, which is used to start the proof,\n      initiates a proof by contradiction by negating the goal and\n      placing it on the hypotheses, leaving {\\tt F} as the new goal.}\n\n\\begin{description}\n\\item [\\small{({\\it AGAIN\\/})}]\n\\begin{tabular}[t]{l}\n\\verb+!n. ?p. n < p /\\ prime p+ \\\\ \\hline\n\\verb|CCONTR_TAC THEN | \\\\\n\\verb|`?n. !p. n < p ==> ~prime p`  by METIS_TAC []             THEN| \\\\\n\\verb|`~(FACT n + 1 = 1)`           by RW_TAC arith_ss  [FACT_LESS,| \\\\\n\\verb|                                    DECIDE``~(x=0)=0<x``] THEN| \\\\\n\\verb|`?p. prime p /\\  | \\\\\n\\verb|     p divides (FACT n + 1)`  by METIS_TAC [PRIME_FACTOR] THEN| \\\\\n\\verb|`0 < p`                       by METIS_TAC [PRIME_POS]    THEN| \\\\\n\\verb|`p <= n`                      by METIS_TAC [NOT_LESS]     THEN| \\\\\n\\verb|`p divides FACT n`            by METIS_TAC [DIVIDES_FACT] THEN| \\\\\n\\verb|`p divides 1`                 by METIS_TAC [DIVIDES_ADDL] THEN| \\\\\n\\verb|`p = 1`                       by METIS_TAC [DIVIDES_ONE]  THEN| \\\\\n\\verb|`~prime p`                    by METIS_TAC [NOT_PRIME_1]  THEN| \\\\\n\\verb|METIS_TAC []| \\\\\n\\end{tabular}\n\\end{description}\n\n\\section{Turning the script into a theory}\n\\label{sec:script-to-theory}\n\nHaving proved our result, we probably want to package it up in a way\nthat makes it available to future sessions, but which doesn't require\nus to go all through the theorem-proving effort again.  Even having a\ncomplete script from which it would be possible to cut-and-paste is an\nerror-prone solution.\n\nIn order to do this we need to create a file with the name\n$x$\\ml{Script.sml}, where $x$ is the name of the theory we wish to\nexport.  This file then needs to be compiled.  In fact, we really do\nuse the Moscow ML compiler, carefully augmented with the appropriate\nlogical context.  However, the language accepted by the compiler is\nnot quite the same as that accepted by the interactive system, so we\nwill need to do a little work to massage the original script into the\ncorrect form.\n\nWe'll give an illustration of converting to a form that can be\ncompiled using the script\n\\[\n  \\mbox{\\ml{<holdir>/examples/euclid.sml}}\n\\] as our base-line.  This\nfile is already close to being in the right form.  It has all of the\nproofs of the theorems in ``sewn-up'' form so that when run, it does\nnot involve the goal-stack at all.  In its given form, it can be run\nas input to \\textsf{hol} thus:\n\n\\setcounter{sessioncount}{0}\n\\begin{session}\n\\begin{verbatim}\n$ cd examples/\n$ ../bin/hol < euclid.sml\n  ...\n\n> val EUCLID = |- !n. ?p. n < p /\\ prime p : thm\n  ...\n\n> val EUCLID_AGAIN = |- !n. ?p. n < p /\\ prime p : thm\n-\n\\end{verbatim}\n\\end{session}\n\nHowever, we now want to create a \\ml{euclidTheory} that we can load in\nother interactive sessions.  So, our first step is to create a file\n\\ml{euclidScript.sml}, and to copy the body of \\ml{euclid.sml} into\nit.\n\nThe first non-comment line opens \\ml{arithmeticTheory}.  However, when\nwriting for the compiler, we need to explicitly mention the other\n\\HOL{} modules that we depend on.  We must add\n\\[\n\\mbox{\\ml{open HolKernel boolLib Parse bossLib}}\n\\]\nThe next line that poses a difficulty is\n\\[\n  \\mbox{\\ml{set\\_fixity \"divides\" (Infixr 450);}}\n\\]\nWhile it is legitimate to type expressions directly into the\ninteractive system, the compiler requires that every top-level phrase\nbe a declaration.  We satisfy this requirement by altering this line\ninto a ``do nothing'' declaration that does not record the result of\nthe expression:\n\\[\n\\mbox{\\ml{val \\_{} = set\\_fixity \"divides\" (Infixr 450)}}\n\\]\nThe only extra changes are to bracket the rest of the script text\nwith calls to \\ml{new\\_theory} and \\ml{export\\_theory}.  So,\nbefore the definition of \\ml{divides}, we add:\n\\[\n\\mbox{\\ml{val \\_{} = new\\_theory \"euclid\";}}\n\\]\nand at the end of the file:\n\\[\n\\mbox{\\ml{val \\_{} = export\\_theory();}}\n\\]\n\nNow, we can compile the script we have created using the\n\\textsf{Holmake} tool.  To keep things a little tidier, we first move\nour script into a new directory.\n\n\\begin{session}\n\\begin{verbatim}\n$ mkdir euclid\n$ mv euclidScript.sml euclid\n$ cd euclid\n$ ../../bin/Holmake\nAnalysing euclidScript.sml\nTrying to create directory .HOLMK for dependency files\nCompiling euclidScript.sml\nLinking euclidScript.uo to produce theory-builder executable\n<<HOL message: Created theory \"euclid\".>>\nDefinition has been stored under \"divides_def\".\nDefinition has been stored under \"prime_def\".\nMeson search level: .....\nMeson search level: .................\n ...\nExporting theory \"euclid\" ... done.\nAnalysing euclidTheory.sml\nAnalysing euclidTheory.sig\nCompiling euclidTheory.sig\nCompiling euclidTheory.sml\n\\end{verbatim}\n\\end{session}\n\nNow we have created four new files, various forms of \\ml{euclidTheory}\nwith four different suffixes.  Only \\ml{euclidTheory.sig} is really\nsuitable for human consumption.  While still in the \\ml{euclid}\ndirectory that we created, we can demonstrate:\n\n\\begin{session}\n\\begin{alltt}\n\\$ ../../bin/hol\n[...]\n\n[closing file \"/local/scratch/mn200/Work/hol98/tools/end-init-boss.sml\"]\n- load \"euclidTheory\";\n> val it = () : unit\n- open euclidTheory;\n> type thm = thm\n  val DIVIDES_TRANS =\n    |- !a b c. a divides b /\\ b divides c ==> a divides c\n    : thm\n  ...\n  val DIVIDES_REFL = |- !x. x divides x : thm\n  val DIVIDES_0 = |- !x. x divides 0 : thm\n\\end{alltt}\n\\end{session}\n\n\\section{Summary}\n\nThe reader has now seen an interesting theorem proved, in great detail,\nin \\holn{}. The discussion illustrated the high-level tools provided in\n\\ml{bossLib} and touched on issues including tool selection, undo,\n`tactic polishing', exploratory simplification, and the `forking-off' of\nnew proof attempts. We also attempted to give a flavour of the thought\nprocesses a user would employ. Following is a more-or-less random\ncollection of other observations.\n\\begin{itemize}\n\n\\item Even though the proof of Euclid's theorem is short and easy to\nunderstand when presented informally, a perhaps surprising amount of\nsupport development was required to set the stage for Euclid's classic\nargument.\n\n\\item The proof support offered by \\ml{bossLib}\n(\\verb+RW_TAC+, \\ml{METIS\\_TAC}, \\ml{DECIDE\\_TAC}, \\ml{DECIDE},\n\\ml{Cases\\_on}, \\ml{Induct\\_on}, and the ``\\ml{by}'' construct) was\nnearly complete for this example: it was rarely necessary to resort to\nlower-level tactics.\n\n\\item Simplification is a workhorse tactic; even when an automated\nreasoner such as \\ml{METIS\\_TAC} is used, its application has often been\nset up by some exploratory simplifications. It therefore pays to become\nfamiliar with the strengths and weaknesses of the simplifier.\n\n\\item A common problem with interactive proof systems is dealing with\nhypotheses. Often \\ml{METIS\\_TAC} and the ``\\ml{by}'' construct allow\nthe use of hypotheses without directly resorting to indexing into them\n(or naming them, which amounts to the same thing). This is desirable,\nsince the hypotheses are notionally a {\\it set}, and moreover,\nexperience has shown that profligate indexing into hypotheses results in\nhard-to-maintain proof scripts. However, it can be clumsy to work with a\nlarge set of hypotheses, in which case the following approaches may be\nuseful.\n\nOne can directly refer to hypotheses by using \\ml{UNDISCH\\_TAC} (makes\nthe designated hypothesis the antecedent to the goal),\n\\ml{ASSUM\\_LIST} (gives the entire hypothesis list to a tactic),\n\\ml{POP\\_ASSUM} (gives the top hypothesis to a tactic), and\n\\ml{PAT\\_ASSUM} (gives the first {\\it matching\\/} hypothesis to a\ntactic). (See the \\REFERENCE{} for further details on all of these.)\nThe numbers attached to hypotheses by the proof manager could likely\nbe used to access hypotheses (it would be quite simple to write such a\ntactic). However, starting a new proof is sometimes the most\nclarifying thing to do.\n\nIn some cases, it is useful to be able to delete a hypothesis. This can\nbe accomplished by passing the hypothesis to a tactic that ignores\nit. For example, to discard the top hypothesis, one could invoke\n\\ml{POP\\_ASSUM (K ALL\\_TAC)}.\n\n\\item In the example, we didn't use the more advanced features of\n\\ml{bossLib}, largely because they do not, as yet, provide much more\nfunctionality than the simple sequencing of simplification, decision\nprocedures, and automated first order reasoning. The \\ml{THEN}\ntactical has thus served as an adequate replacement. In the future,\nthese entrypoints should become more powerful.\n\n\\item It is almost always necessary to have an idea of the {\\it\n    informal\\/} proof in order to be successful when doing a formal\n  proof. However, all too often the following strategy is adopted by\n  novices: (1) rewrite the goal with a few relevant definitions, and\n  then (2) rely on the syntax of the resulting goal to guide\n  subsequent tactic selection. Such an approach constitutes a clear\n  case of the tail wagging the dog, and is a poor strategy to adopt.\n  Insight into the high-level structure of the proof is one of the\n  most important factors in successful verification exercises.\n\nThe author has noticed that many of the most successful verification\nexperts work using a sheet of paper to keep track of the main steps that\nneed to be made. Perhaps looking away to the paper helps break the\nmesmerizing effect of the computer screen.\n\nOn the other hand, one of the advantages of having a mechanized logic\nis that the machine can be used as a formal expression calculator,\nand thus the user can use it to quickly and accurately explore various\nproof possibilities.\n\\item High powered tools like \\ml{METIS\\_TAC}, \\ml{DECIDE\\_TAC}, and\n\\ml{RW\\_TAC} are the principal way of advancing a proof in\n\\ml{bossLib}. In many cases, they do exactly what is desired, or even\nmanage to surprise the user with their power. In the formalization of\nEuclid's theorem, the tools performed fairly well. However, sometimes\nthey are overly aggressive, or they simply flounder. In such cases, more\nspecialized proof tools need to be used, or even written, and hence the\nsupport underlying \\ml{bossLib} must eventually be learned.\n\n\\item Having a good knowledge of the available lemmas, and where they\nare located, is an essential part of being successful. Often powerful\ntools can replace lemmas in a restricted domain, but in general, one has\nto know what has already been proved. We have found that the entrypoints\nin \\verb+DB+ help in quickly finding lemmas.\n\n\\end{itemize}\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"tutorial\"\n%%% End:\n", "meta": {"hexsha": "72974bac5c353e4f6ecb555cb24edb2979e9b976", "size": 64858, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Manual/Tutorial/euclid.tex", "max_stars_repo_name": "jeremydaw/HOL", "max_stars_repo_head_hexsha": "c4cbc5cadd6a8ce9bafae60077c359c60764f72f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-27T07:51:47.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-27T07:51:47.000Z", "max_issues_repo_path": "Manual/Tutorial/euclid.tex", "max_issues_repo_name": "jeremydaw/HOL", "max_issues_repo_head_hexsha": "c4cbc5cadd6a8ce9bafae60077c359c60764f72f", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Manual/Tutorial/euclid.tex", "max_forks_repo_name": "jeremydaw/HOL", "max_forks_repo_head_hexsha": "c4cbc5cadd6a8ce9bafae60077c359c60764f72f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.0205183585, "max_line_length": 99, "alphanum_fraction": 0.6675352308, "num_tokens": 19678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7119528298946167}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\\begin{document}\nIn this chapter, we will specifically talk math related problems. Normally, for the problems appearing in this section, they can be solved using our learned programming methodology. However, it might not inefficient (we will get LTE error on the LeetCode) due to the fact that we are ignoring their math properties which might help us boost the efficiency. Thus, learning some of the most related math knowledge can make our life easier. \n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% sorting\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% GCD\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Numbers}\n\\subsection{Prime Numbers}\nA prime number is an integer greater than 1, which is only divisible by 1 and itself. First few prime numbers are : 2 3 5 7 11 13 17 19 23 ...\n\nSome interesting facts about Prime numbers: \n\\begin{enumerate}\n    \\item 2 is the only even Prime number.\n    \\item  2, 3 are only two consecutive natural numbers which are prime too.\n    \\item \\label{divide}Every prime number except 2 and 3 can represented in form of 6n+1 or 6n-1, where n is natural number.\n    \\item \\label{godld} Goldbach Conjecture: Every even integer greater than 2 can be expressed as the sum of two primes. Every positive integer can be decomposed into a product of primes.\n    \\item GCD of a natural number with Prime is always one.\n    \\item Fermat’s Little Theorem: If n is a prime number, then for every a, $1 <= a < n $, %$a^{(n-1)} == 1 (mod n) OR a^(n-1) % n = 1$. check if it is useful in real situation\n    \\item Prime Number Theorem : The probability that a given, randomly chosen number n is prime is inversely proportional to its number of digits, or to the logarithm of n.\n\\end{enumerate}\n\\subsubsection{Check Single Prime Number}\nLearning to check if a number is a prime number is necessary: the naive solution comes from the direct definition, for a number $n$, we try to check if it can be divided by number in range $[2, n-1]$, if it divides, then its not a prime number. \n\\begin{lstlisting}[language=Python]\ndef isPrime(n):\n    # Corner case\n    if (n <= 1):\n        return False\n    # Check from 2 to n-1\n    for i in range(2, n):\n        if (n % i == 0):\n            return False\nreturn True\n\\end{lstlisting}\nThere are actually a lot of space for us to optimize the algorithm. First, instead of checking till n, we can check till $\\sqrt{n}$ because a larger factor of n must be a multiple of smaller factor that has been already checked. Also, because even numbers bigger than 2 are not prime, so the step we can set it to 2. The algorithm can be improved further by use feature \\ref{divide} that all primes are of the form $6k \\pm 1$, with the exception of 2 and 3.  Together with feature \\ref{godld} which implicitly states that every non-prime integer is divisible by a prime number smaller than itself. So a more efficient method is to test if n is divisible by 2 or 3, then to check through all the numbers of form $6k \\pm 1$.\n\\begin{lstlisting}[language=Python]\ndef isPrime(n):\n    # corner cases\n    if n <= 1:\n        return False\n    if n<= 3:\n        return True\n    \n    if n % 2 == 0 or n % 3 == 0:\n        return False\n        \n    for i in range(5, int(n**0.5)+1, 6):  # 6k+1 or 6k-1, step 6, up till sqrt(n), when i=5, check 5 and 7, (k-1, k+1)\n        if n%i == 0 or n%(i+2)==0:\n            return False\n    return True\nreturn True\n\\end{lstlisting}\n\n\\subsubsection{Generate A Range of Prime Numbers}\n\\paragraph{Wilson theorem} says if a number k is prime then $((k-1)! + 1) \\% k$ must be 0. Below is Python implementation of the approach. Note that the solution works in Python because Python supports large integers by default therefore factorial of large numbers can be computed.\n\\begin{lstlisting}[language=Python]\n# Wilson Theorem\ndef primesInRange(n):\n    fact = 1 \n    rst = []\n    for k in range(2, n):\n        fact *= (k-1)\n        if (fact + 1)% k == 0:\n            rst.append(k)\n    return rst\n    \nprint(primesInRange(15)) \n# output\n# [2, 3, 5, 7, 11, 13]\n\\end{lstlisting}\n\n\\paragraph{Sieve Of Eratosthenes} To  generate a list of primes. It works by recognizing \\textit{Goldbach Conjecture} that all non-prime numbers are divisible by a prime number. An optimization is to only use odd number in the primes list, so that we can save half space and half time. The only difference is we need to do index mapping.\n\\begin{lstlisting}[language=Python]\ndef primesInRange(n):\n    primes = [True] * n\n    primes[0] = primes[1] = False\n    for i in range(2, int(n ** 0.5) + 1):\n        #cross off remaining multiples of prime i, start with i*i\n        if primes[i]:\n            for j in range(i*i,n,i):\n                primes[j] = False  \n    rst = [] # or use sum(primes) to get the total number\n    for i, p in enumerate(primes):\n        if p:\n            rst.append(i)\n    return rst\n    \nprint(primesInRange(15))\n\\end{lstlisting}\n\\subsection{Ugly Numbers}\nUgly numbers are positive numbers whose prime factors only include 2, 3, 5. We can write it as $ugly number = 2^i3^j5^k, i>=0, j>=0, k>=0$. Examples of ugly numbers: 1, 2, 3, 5, 6, 10, 15, ... The concept of ugly number is quite simple. Now let us use the LeetCode problems as example to derive the algorithms to identify ugly numbers.\n\\subsubsection{Check a Single Number}\n263. Ugly Number (Easy)\n\\begin{lstlisting}\nUgly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.\n\nNote:\n    1 is typically treated as an ugly number.\n    Input is within the 32-bit signed integer range.\n\\end{lstlisting}\nAnalysis: because the ugly number is only divisible by $2, 3, 5$, so if we keep dividing the number by these factors ($num/f$), eventually we would get $1$, if the reminder ($num\\%f$) is $0$ (divisible), otherwise we stop the loop to check the number. \n\\begin{lstlisting}[language = Python]\ndef isUgly(self, num):\n        \"\"\"\n        :type num: int\n        :rtype: bool\n        \"\"\"\n        if num ==0:\n            return False\n        factor = [2,3,5]\n        for f in factor:\n            while num%f==0:\n                num/=f\n        return num == 1\n\\end{lstlisting}\n\\subsubsection{Generate A Range of Number}\n264. Ugly Number II (medium)\n\\begin{lstlisting}\nWrite a program to find the n-th ugly number.\n\nUgly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers.\n\nNote that 1 is typically treated as an ugly number, and n does not exceed 1690.\n\\end{lstlisting}\nAnalysis: The first solution is we use the rules $ugly number = 2^i3^j5^k, i>=0, j>=0, k>=0$, using three for loops to generate at least 1690 ugly numbers that is in the range of $2^32$, and then sort them, the time complexity is $O(nlogn)$, with $O(n)$ in space.  However, if we need to constantly make request, it seems resasonable to save a table, and once the table is generated and saved, each time we would only need constant time to check.\n\\begin{lstlisting}[language = Python]\nfrom math import log, ceil\nclass Solution:\n    ugly = [2**i * 3**j * 5**k for i in range(32) for j in range(ceil(log(2**32, 3))) for k in range(ceil(log(2**32, 5)))]\n    ugly.sort()\n    def nthUglyNumber(self, n):\n        \"\"\"\n        :type n: int\n        :rtype: int\n        \"\"\"\n        return self.ugly[n-1]\n\\end{lstlisting}\nThe second way is only generate the nth ugly number, with \n\\begin{lstlisting}[language=Python]\nclass Solution:\n    n = 1690\n    ugly = [1]\n    i2 = i3 = i5 = 0\n    for i in range(n-1):\n        u2, u3, u5 = 2 * ugly[i2], 3 * ugly[i3], 5 * ugly[i5]\n        umin = min(u2,u3,u5)\n        ugly.append(umin)\n        if umin == u2:\n            i2 += 1\n        if umin == u3:\n            i3 += 1\n        if umin == u5:\n            i5 += 1\n\n    def nthUglyNumber(self, n):\n        \"\"\"\n        :type n: int\n        :rtype: int\n        \"\"\"   \n        return self.ugly[n-1]\n\\end{lstlisting}\n%%%%%%%%%Combinatorics%%%%\n\\subsection{Combinatorics}\n\\begin{enumerate}\n    \\item 611. Valid Triangle Number\n\\end{enumerate}\n\\begin{examples}[resume]\n\\item \\textbf{Pascal's Triangle II(L119, *).} Given a non-negative index k where k <= 33, return the kth index row of the Pascal's triangle. Note that the row index starts from 0. In Pascal's triangle, each number is the sum of the two numbers directly above it.\n\\begin{lstlisting}[numbers=none]\nExample:\nInput: 3\nOutput: [1,3,3,1]\n\\end{lstlisting}\nFollow up: Could you optimize your algorithm to use only O(k) extra space?\n\\textbf{Solution: Generate from Index 0 to K}. \n\\begin{lstlisting}[language=Python]\ndef getRow(self, rowIndex):\n    if rowIndex == 0:\n        return [1]\n    # first, n = rowIndex+1, if n is even, \n    ans = [1]\n    for i in range(rowIndex):\n        tmp = [1]*(i+2)\n        for j in range(1, i+1):\n            tmp[j] = ans[j-1]+ans[j]\n        ans = tmp\n    return ans\n\\end{lstlisting}\nTriangle Counting\n\n\\end{examples}\n%%%%%%%%%%%Others%%%%%%%%%%%\n\\subsubsection{Smallest Larger Number}\n556. Next Greater Element III\n\\begin{lstlisting}\nGiven a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive 32-bit integer exists, you need to return -1.\n\nExample 1:\n\nInput: 12\nOutput: 21\n\nExample 2:\n\nInput: 21\nOutput: -1\n\\end{lstlisting}\nAnalysis: The first solution is to get all digits [1,2], and generate all the permutation [[1,2],[2,1]], and generate the integer again, and then sort generated integers, so that we can pick the next one that is larger. But the time complexity is O(n!).\n\nNow, let us think about more examples to find the rule here: \n\\begin{lstlisting}\n435798->435879\n1432->2134\n\\end{lstlisting}\nIf we start from the last digit, we look to its left, find the cloest digit that has smaller value, we then switch this digit, if we cant find such digit, then we search the second last digit. If none is found, then we can not find one. Like 21. return -1. This process is we get the first larger number to the right. \n\\begin{lstlisting}\n[5, 5, 7, 8, -1, -1]\n[2, -1, -1, -1] \n\\end{lstlisting}\nAfter the this we switch 8 with 7: we get\n\\begin{lstlisting}\n4358 97\n2 431\n\\end{lstlisting}\nFor the reminding digits, we do a sorting and put them back to those digit to get the smallest value\n\\begin{lstlisting}[language=Python]\nclass Solution:\n    def getDigits(self, n):\n        digits = []\n        while n:\n            digits.append(n%10) # the least important position\n            n = int(n/10)\n        return digits\n    def getSmallestLargerElement(self, nums):\n        if not nums:\n            return []\n        rst = [-1]*len(nums)\n\nfor i, v in enumerate(nums):\n            smallestLargerNum = sys.maxsize\n            index = -1\n            for j in range(i+1, len(nums)):\n                if nums[j]>v and smallestLargerNum > nums[j]:\n                    index = j\n                    smallestLargerNum = nums[j]\n            if smallestLargerNum < sys.maxsize:\n                rst[i] = index\n        return rst\n        \n        \n    def nextGreaterElement(self, n):\n        \"\"\"\n        :type n: int\n        :rtype: int\n        \"\"\"\n        if n==0:\n            return -1\n            \n        digits = self.getDigits(n)\n        digits = digits[::-1]\n        # print(digits)\n        \n        rst = self.getSmallestLargerElement(digits)\n        # print(rst)\n        stop_index = -1\n        \n        # switch\n        for i in range(len(rst)-1, -1, -1):\n            if rst[i]!=-1: #switch\n                print('switch')\n                stop_index = i\n                digits[i], digits[rst[i]] = digits[rst[i]], digits[i]\n                break\n        if stop_index == -1:\n            return -1\n                \n#         print(digits)\n        \n        # sort from stop_index+1 to the end\n        digits[stop_index+1:] = sorted(digits[stop_index+1:])\n        print(digits)\n\n#convert the digitialized answer to integer\n        nums = 0\n        digit = 1\n        for i in digits[::-1]:\n            nums+=digit*i\n            digit*=10\n            if nums>2147483647:\n                return -1\n        \n            \n        return nums\n\\end{lstlisting}\n\\section{Intersection of Numbers}\nIn this section, intersection of numbers is to find the ``common\" thing between them, for example Greatest Common Divisor and Lowest Common Multiple. \n\\subsection{Greatest Common Divisor}\nGCD (Greatest Common Divisor) or HCF (Highest Common Factor) of two numbers $a$ and $b$ is the largest number that divides both of them. For example shown as follows:\n\\begin{lstlisting}\nThe divisors of 36 are: 1, 2, 3, 4, 6, 9, 12, 18, 36\nThe divisors of 60 are: 1, 2, 3, 4, 5, 6, 10, 12, 15, 30, 60\nGCD = 12\n\\end{lstlisting}\nSpecial case is when one number is zero, the GCD is the value of the other. $gcd(a, 0) = a$. \n\nThe basic algorithm is: we get all divisors of each number, and then find the largest common value. Now, let's see how to we advance this algorithm.  We can reformulate the last example as:\n\\begin{lstlisting}\n36 = 2 * 2 * 3 * 3\n60 = 2 * 2 * 3 * 5\nGCD = 2 * 2 * 3\n    = 12\n\\end{lstlisting}\nSo if we use $60-36 = 2*2*3*5 - 2*2*3*3 = (2*2*3)*(5-3) = 2*2*3*2$. So we can derive the principle that the GCD of two numbers does not change if the larger number is replaced by its difference with the smaller number.  The features of GCD:\n\\begin{enumerate}\n    \\item $gcd(a, 0) = a$\n    \\item $gcd(a, a) = a$,\n    \\item $gcd(a, b) = gcd(a-b, b)$, if $a>b$.\n\\end{enumerate}\nBased on the above features, we can use Euclidean Algorithm to gain GCD:\n\\begin{lstlisting}\ndef euclid(a, b):\n    while a != b:\n         # replace larger number by its difference with the smaller number\n         if a > b:\n             a = a - b\n         else:\n             b = b - a\n    return a\n    \nprint(euclid(36, 60))\n\\end{lstlisting}\nThe only problem with the Euclidean Algorithm is that it can take several subtraction steps to find the GCD if one of the given numbers is much bigger than the other. A more efficient algorithm is to replace the subtraction with remainder operation. The algorithm would stops when reaching a zero reminder and now the algorithm never requires more steps than five times the number of digits (base 10) of the smaller integer. \n\nThe recursive version code:\n\\begin{lstlisting}[language = Python]\ndef euclidRemainder(a, b):\n    if a == 0 :\n        return b\n    return gcd(b%a, a)\n\\end{lstlisting}\nThe iterative version code: \n\\begin{lstlisting}[language = Python]\ndef euclidRemainder(a, b):\n    while a > 0:\n         # replace one number with reminder between them\n         a, b = b%a, a\n    return b\n    \nprint(euclidRemainder(36, 60))\n\\end{lstlisting}\n\n\n\\subsection{Lowest Common Multiple}\nLowest Common Multiple (LCM) is the smallest number that is a multiple of both $a$ and $b$. For example of 6 and 8:\n\\begin{lstlisting}\nThe multiplies of 6 are: 6, 12, 18, 24, 30, ...\nThe multiplies of 8 are: 8, 16, 24, 32, 40, ...\nLCM = 24\n\\end{lstlisting}\nComputing LCM is dependent on the GCD with the following formula:\n\\begin{equation}\n    lcm(a, b) = \\frac{a\\times b}{gcd(a, b)}\n\\end{equation}\n\n\\section{Arithmetic Operations}\nBecause for the computer, it only understands the binary representation as we learned in Bit Manipulation (Chapter~\\ref{chapter_bit}, the most basic arithmetic operation it supports are  binary addition and subtraction. (Of course, it can execute the bit manipulation too.)  The other common arithmetic operations such as Multiplication, division, modulus, exponent are all implemented/coded with the addition and subtraction as basis or in a dominant fashion. As a software engineer, have a sense of how we can implement the other operations from the given basis is reasonable and a good practice of the coding skills. Also, sometimes if the factor to compute on is extra large number, which is to say the computer can not represent, we can still compute the result by treating these numbers as strings. \n\nIn this section, we will explore operations include multiplication, division. There are different algorithms that we can use, we learn a standard one called long multiplication and long division. I am assuming you know the algorithms and focusing on the implementation of the code instead. \n\n\\paragraph{Long Multiplication} \n\n\\paragraph{Long Division} We treat the dividend as a string, e.g. dividend = 3456, and the divisor = 12. We start with 34, which has the digits as of divisor. 34/12 = 2, 10, where 2 is the integer part and 10 is the reminder. Next step, we take the reminder and join with the next digit in the dividend, we get 105/12 = 8, 9. Smilarily, 96/12 = 8, 0. Therefore we get the results by joinging the result of each dividending operation, '288'.  To see the coding, let us code it the way required by the following LeetCode Problem. In the process we need (n-m) (n, m is the total number of digits of dividend and divisor, respectively) division operation. Each division operation will be done at most 9 steps. This makes the time complexity $O(n-m)$.\n\\begin{examples}[resume]\n\\item \\textbf{29. Divide Two Integers (medium)} Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero.\n\\begin{lstlisting}[language=Python][numbers=none]\nExample 1:\n\nInput: dividend = 10, divisor = 3\nOutput: 3\n\nExample 2:\n\nInput: dividend = 7, divisor = -3\nOutput: -2\n\\end{lstlisting}\n\n\\textbf{Analysis:} we can get the sign of the result first, and then convert the dividend and divisor into its absolute value. Also, we better handle the bound condition that the divisor is larger than the vidivend, we get 0 directly. The code is given:\n\\begin{lstlisting}[language=Python]\ndef divide(self, dividend, divisor):\n    def divide(dd): # the last position that divisor* val <  dd\n        s, r = 0, 0\n        for i in range(9):\n            tmp = s + divisor\n            if tmp <= dd:\n                s = tmp\n            else:\n                return str(i), str(dd-s)\n        return str(9), str(dd-s)\n            \n    if dividend == 0:\n        return 0\n    sign = -1\n    if (dividend >0 and divisor >0 ) or (dividend < 0 and divisor < 0):\n        sign = 1\n    dividend = abs(dividend)\n    divisor = abs(divisor)\n    if divisor > dividend:\n        return 0\n    ans, did, dr = [], str(dividend), str(divisor)\n    n = len(dr)\n    pre = did[:n-1]\n    for i in range(n-1, len(did)):\n        dd = pre+did[i]\n        dd = int(dd)\n        v, pre = divide(dd)\n        ans.append(v)\n         \n    ans = int(''.join(ans))*sign\n\n    if ans > (1<<31)-1:\n        ans = (1<<31)-1\n    return ans\n\\end{lstlisting}\n\\end{examples}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Probability Theory\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Probability Theory}\nIn programming tasks, such problems are either solvable with some closed-form formula or one has no choice than to enumerate the complete search space.\n\\section{Linear Algebra}\n\\textit{Gaussian Elimination} is one of the several ways to find the solution for a system of linear euqations. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% geometry\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Geometry}\nIn this section, we will discuss coordinate related problems. \n\n939. Minimum Area Rectangle(Medium)\n\nGiven a set of points in the xy-plane, determine the minimum area of a rectangle formed from these points, with sides parallel to the x and y axes.\n\nIf there isn't any rectangle, return 0.\n\\begin{lstlisting}\nExample 1:\n\nInput: [[1,1],[1,3],[3,1],[3,3],[2,2]]\nOutput: 4\n\nExample 2:\n\nInput: [[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]]\nOutput: 2\n\\end{lstlisting}\n\\textbf{Combination}. This at first it is a combination problem, we pick four points and check if it is a rectangle and then what is the size. However the time complexity can be $C_n^k$, which will be $O(n^4)$. The following code implements the best combination we get, however, we receive LTE:\n\\begin{lstlisting}[language=Python]\ndef minAreaRect(self, points):\n    def combine(points, idx,  curr, ans): # h and w at first is -1\n        if len(curr) >= 2:\n            lx, rx = min([x for x, _ in curr]), max([x for x, _ in curr])\n            ly, hy = min([y for _, y in curr]), max([y for _, y in curr])\n            size = (rx-lx)*(hy-ly)\n            if size >= ans[0]:\n                return \n            xs = [lx, rx]\n            ys = [ly, hy]\n            for x, y in curr:\n                if x not in xs or y not in ys:\n                    return \n\n            if len(curr) == 4:\n                ans[0] = min(ans[0], size)\n                return \n\n        for i in range(idx, len(points)):\n            if len(curr) <= 3:\n                combine(points, i+1,  curr+[points[i]], ans)\n        return \n    \n    ans=[sys.maxsize]\n    combine(points, 0, [], ans)\n    return ans[0] if ans[0] != sys.maxsize else 0\n\\end{lstlisting}\n\\textbf{Math: Diagonal decides a rectangle}. We use the fact that if we know the two diagonal points, say (1, 2), (3, 4). Then we need (1, 4), (3, 2) to make it a rectangle.  If we save the points in a hashmap, then the time complexity can be decreased to $O(n^2)$. The condition that two points are diagonal is: x1 != x2, y1 != y2. If one of them is equal, then they form a vertical or horizontal line. If both equal, then its the same points. \n\\begin{lstlisting}[language = Python]\nclass Solution(object):\n    def minAreaRect(self, points):\n        S = set(map(tuple, points))\n        ans = float('inf')\n        for j, p2 in enumerate(points): # decide the second point\n            for i in range(j): # decide the firs point\n                p1 = points[i]\n                if (p1[0] != p2[0] and p1[1] != p2[1] and # avoid\n                        (p1[0], p2[1]) in S and (p2[0], p1[1]) in S):\n                    ans = min(ans, abs(p2[0] - p1[0]) * abs(p2[1] - p1[1]))\n        return ans if ans < float('inf') else 0\n\\end{lstlisting}\n\\textbf{Math: Sort by column}. Group the points by x coordinates, so that we have columns of points. Then, for every pair of points in a column (with coordinates (x,y1) and (x,y2)), check for the smallest rectangle with this pair of points as the rightmost edge. We can do this by keeping memory of what pairs of points we've seen before.\n\\begin{lstlisting}[language=Python]\ndef minAreaRect(self, points):\n    columns = collections.defaultdict(list)\n    for x, y in points:\n        columns[x].append(y)\n    lastx = {}  # one-pass hash\n    ans = float('inf')\n\n    for x in sorted(columns): # sort by the keys\n        column = columns[x]\n        column.sort() # sort column\n        for j, y2 in enumerate(column): # right most edge, up point\n            for i in xrange(j):         # right most edge, lower point\n                y1 = column[i]\n                if (y1, y2) in lastx:  # 1: [1, 3], will be saved, when we were at 3: [1, 3], we can get the answer\n                    ans = min(ans, (x - lastx[y1,y2]) * (y2 - y1))\n                lastx[y1, y2] = x # y1, y2 form a tuple\n    return ans if ans < float('inf') else 0\n\\end{lstlisting}\n\n\\section{Miscellaneous Categories}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%% rabbit and turtle to find circle or repeat number\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Floyd’s Cycle-Finding Algorithm}\n\nWithout this we detect cycle with the following code:\n\\begin{lstlisting}[language = Python]\ndef detectCycle(self, A):\n        visited=set()       \n        head=point=A\n        while point:\n            if point.val in visited:\n                return point\n            visited.add(point)\n            point=point.next\n        return None\n\\end{lstlisting}\n\nTraverse linked list using two pointers. Move one pointer by one and other pointer by two. If these pointers meet at some node then there is a loop. If pointers do not meet then linked list doesn’t have loop. Once you detect a cycle, think about finding the starting point.\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width = 0.98\\columnwidth]{fig/floyd.png}\n    \\caption{Example of floyd’s cycle finding}\n    \\label{fig:floyd}\n\\end{figure}\n\n\\begin{lstlisting}[language = Python]\ndef detectCycle(self, A):\n        #find the \"intersection\" \n        p_f=p_s=A\n        while (p_f and p_s and p_f.next):\n            p_f = p_f.next.next\n            p_s = p_s.next\n            if p_f==p_s:\n                break\n        #Find the \"entrance\" to the cycle.\n        ptr1 = A\n        ptr2 = p_s;\n        while ptr1 and ptr2:\n            if ptr1!=ptr2:\n                ptr1 = ptr1.next\n                ptr2 = ptr2.next\n            else:\n                return ptr1\n        return None\n\\end{lstlisting}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% exercise\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Exercise}\n\\subsection{Number}\n313. Super Ugly Number\n\\begin{lstlisting}\nSuper ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32] is the sequence of the first 12 super ugly numbers given primes = [2, 7, 13, 19] of size 4.\n\nNote:\n (1) 1 is a super ugly number for any given primes.\n (2) The given numbers in primes are in ascending order.\n (3) 0 < k <= 100, 0 < n <= 106, 0 < primes[i] < 1000.\n (4) The nth super ugly number is guaranteed to fit in a 32-bit signed integer.\n\\end{lstlisting}\n\\begin{lstlisting}[language=Python]\ndef nthSuperUglyNumber(self, n, primes):\n        \"\"\"\n        :type n: int\n        :type primes: List[int]\n        :rtype: int\n        \"\"\"\n        nums=[1]\n        idexs=[0]*len(primes) #first is the current idex\n        for i in range(n-1):\n            min_v = maxsize\n            min_j = []\n            for j, idex in enumerate(idexs):\n                v = nums[idex]*primes[j]\n                if v<min_v:\n                    min_v = v\n                    min_j=[j]\n                elif v==min_v:\n                    min_j.append(j) #we can get mutiple j if there is a tie\n            nums.append(min_v)\n            for j in min_j:\n                idexs[j]+=1 \n        return nums[-1]\n\\end{lstlisting}\n\\end{document}", "meta": {"hexsha": "b70e492a6033a8596f0adc6552a5454997f581ce", "size": 26764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Easy-Book/chapters/chapter_16_math.tex", "max_stars_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_stars_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Easy-Book/chapters/chapter_16_math.tex", "max_issues_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_issues_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Easy-Book/chapters/chapter_16_math.tex", "max_forks_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_forks_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.947454844, "max_line_length": 805, "alphanum_fraction": 0.6229263189, "num_tokens": 7207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262966, "lm_q2_score": 0.8499711832583696, "lm_q1q2_score": 0.7119528244645179}}
{"text": "\\section{Polynomial: Polynomials}\nWe will use the $[a_0,a_1,a_2 \\dots]$ format for the array\nrepresentation of polynomials.  That allows the array index\nto be the x exponent.  However, it makes the bookkeeping for\ndiv and deriv a bit tricky, since they have to work\nbackwards.\n\n\\subsection*{eval}\nNR92 recommends using the nested form:\n\\begin{equation}\n    a_0 + a_1 x^1 + a_2 x^2 + a_3 x^3\n      = a_0+ x(a_1+x(a_2+x(a_3)))\n\\end{equation}\n\nThis can be done in a loop, working down from a[nn]:\n\\begin{tt} \\begin{verbatim}\n     tmp:=p[nn];\n     FOR i:=nn-1 TO 1 BY -1 DO\n       tmp:=a[i]+x*tmp;\n     END;\n     tmp:=a[0]+tmp;\n\\end{verbatim}  \\end{tt}\n   \n\\subsection*{add,sub}\nTrivial.\n\n\\subsection*{mul}\nThis is not as simple as add and sub, but it it is still\nmainly bookkeeping.  No special insights needed.\n\n\\subsection*{div}\nThe classic form is:\n\\begin{equation}\n   \\frac{A=a_n x^n+a_{n-1} x^{n-1}+\\dots+a_0}\n     {B=b_m x^m+b_{m-1} x^{m-1}+\\dots+b_0}\n\\end{equation}\n\nWe set it up for longhand as:\n\\begin{tt} \\begin{verbatim}\n          Q=quotient\n          ------------------\n     B    | A\n           -B*q[qi]\n            --------------\n            remainder\n\\end{verbatim} \\end{tt}\n\nWe repeat a pattern, using $b[m]=bmax$ as the divider, getting\nq's in decreasing order and taking the remainder of the\nsubtraction as the start point for the next division by\nbmax.  We may as well start by copying A into the remainder\nand using it directly:\n\\begin{verbatim}\n     q[qi]:=r[ri]/bmax\n     for all the r's, subtract the appropriate q[qi]*b[bi]\n\\end{verbatim}\n\nThe problem is really one of bookkeeping, since we are\nmoving backwards in b,r,and q, and the start points keep\nchanging.  Points to remember include:\n\\begin{enumerate}\n     \\item Once the order (i.e., max exponent) of the remainder\n       is less than bmax, we can quit.\n     \\item Q's order is A's order - B's order.\n\\end{enumerate}\n     \nUsing $A=u, B=v$:\n\\begin{tt} \\begin{verbatim}\n     (*u/v = q, remainder r*)\n     un:=NUMBER(u^); unn:=LAST(u^);\n     vn:=NUMBER(v^); vnn:=LAST(v^); vmax:=v[vnn];\n     qn:=un-vn+1; q:=NEW(Poly,qn);\n     r^:=u^;\n     \n     FOR ri:=unn TO (unn-qnn) BY -1 DO\n         qtmp:=r[ri]/vmax;\n         q[ri-vnn]:=qtmp;\n         ri2:=ri;\n         FOR vi:=vnn TO v0 BY -1 DO\n           r[ri2]:=r[ri2]-qtmp*v[vi];\n           DEC(ri2);\n         END;\n       END;\n\\end{verbatim} \\end{tt}\n\nThat is, we work systematrixically down through the remainders.\nFor each we use vmax to find q[qi], where qi started at un-\nvn and decreases with the r's (which mirror the u's).  Once\nq is found, we use it (in the form qtmp) to calc the\nsubtraction term, which starts with the biggest v and works\ndown to the smallest.  For each v[vi], the applicable r term\nstarts with the currently biggest ri (given by ri2), then\ndecreasing ri2 for every vi decrease.\n\nTesting via MathCAD\n\\begin{equation}\n   \\frac{1+2x+3x^2+4x^3+5x^4}{.1+.2x+.3x^2+.4x^3} \n     \\rightarrow q=.6+12.5x, r=.9+.6x+.3x^2\n\\end{equation}\n    \nMultiplying back and adding the remainder I got\n\\begin{equation}\n     u= .96+1.97x+2.98x^2+3.99x^3+5.0x^4\n\\end{equation}\nLooks like the algorithm works, though the lower coefs are\npretty bad.\n\n\\subsection*{deflate}\nSee Swok90, pg 124.  Given polynomial a, and wanting $a/(x-c)\n= b$, where a and b are in the form $a_0+a_1*x+a_2*x^2$, we set up\nthe longhand form:\n\\begin{verbatim}     \n            a[n]n*x^(n-1)\n          ------------------------------\n     x-c  | a[n]*x^n +  a[n-1]*x^(n-1) ... a0\n            a[n]*x^n + -c*a[n]*x^(n-1)\n            --------------------\n                     (a[n-1]+c*a[n])\n\\end{verbatim}\n     \nNotice the $c*a[n]$ term for the next iteration.  Each step\nhas this addition of c times the previous solution coef.\nThe result is a very regular progression backwards from $x^n$\nto $x^0$.  At that point we cannot divide any further, and just\nhave the remainder (if any).\n\\begin{tt} \\begin{verbatim}\n     m:=LAST(a);\n     b:=NEW(Poly,m);  (*b is 0..m-1*)\n     b[m-1]:=a[m];\n     FOR i:=m-2 TO 0 BY -1 DO\n       b[i]:=a[i+1]+c*b[i+1];\n     END;\n     rem:=a[0]+c*b[0];\n\\end{verbatim} \\end{tt}\n     \nHowever, deflation is often used where it doesn't make sense\nto generate a brandom new \"b\" polynomial every time.  So we\nneed an in-place approach.  Since a[] is being used for both\nthe old input data and the new output data, we have to save\nthe coef for current term:\n\\begin{tt} \\begin{verbatim}\n     (*ann = LAST(a) *)\n     b:=a[ann]; asave:=a[ann-1]; a[ann-1]:=b;\n     FOR j:=ann-2 TO 1 BY -1 DO\n       b:=asave+c*b;\n       asave:=a[j]; a[j]:=b;\n     END;\n     rem:=a[0]+c*a[1];\n\\end{verbatim} \\end{tt}\n\nDeflation is typically used where $c$ is a root of $a$, and\ntherefore $rem=0$.  So the last line may not be relevant.\n\n\\subsection*{deriv}\nGiven a polynomial with coefs a[]:\n\\begin{verbatim}\n     p =   a0    +a1*x       +a2*x^2     +a3*x^3     +a4*x^4\n     p'=   a1    +2*a2*x     +3*a3*x^2   +4*a4x^3    +0\n     p\"=   2*a2  +2*3*a3*x   +3*4*a4*x^2 +0          +0\n\\end{verbatim}\n\nBy lining them up this way, the polynomial sense of the\nvector is maintained.  That is, p[2] is the coef of $x^2$ for p\nand p'[2] is the coef of $x^2$ for p'.\n\nLet's start with evaluating p(x).  The NR92 recommended way\nto evaluate polynomials is to nest the multiplies.  For p(x)\nwe have:\n\\begin{equation}\n     p=a_0+x*(a_1+x*(a_2+x*(a_3+x*(a_4))));\n\\end{equation}\nIn a loop, this works out as:\n\\begin{verbatim}\n     p:=a[pnn];\n     FOR i:=ann-1 TO 0 BY -1 DO\n       p:=a[i]+x*p;\n     END;\n\\end{verbatim}\n\nNext, we need to handle derivatives of p.  We may as well\nuse NR92's notation of pd[], where the index is the\nderivative count:\n\\begin{verbatim}\n     p=pd[0]; p'=pd[1]; p'=pd[2]; ...pd[nd];\n\\end{verbatim}\n\nIn nested form:\n\\begin{verbatim}\n     p :=a0+     x*(a1+     x*(a2+     x*(a3+     x*(a4))));\n     p':=a1+     x*(2*a2+   x*(3*a3+   x*(4*a4+   x*(0))))\n     p\":=2*a2+   x*(2*3*a3+ x*(3*4*a4+ x*(0+      x*(0))))\n\\end{verbatim}\n\nNotice the factors multiplying the a terms.  For the dth\nderivative we need:\n\\begin{equation}\n     (n)(n-1)(n-2) \\cdots (n-d+1) a_n \\mbox{\\ (d$<$n)}\n\\end{equation}\n\nWe could do all the derivatives just like p, keeping track\nof the offsets and inserting the factors:\n\\begin{verbatim}\n     pd[0]:=a[pnn];\n     FOR i:=1 TO nd DO pd[i]:=0.0; END;\n     FOR i:=ann-1 TO 0 BY -1 DO\n         pd[0]:=a[i]+x*p[0];\n       FOR j:=1 TO nd DO\n         factor:=1.0;\n         FOR k:=i TO i-j BY -1 DO\n           factor:=factor*FLOAT(k,REAL32);END;\n         pd[j]:=factor*a[i-j]+x*pd[j];\n       END;\n     END;\n\\end{verbatim}\n\nBut notice something in the nested form.  Starting at the\nleft, a4 keeps moving to the right as another derivative is\ntaken.  In fact, the full (factor,a,x ) term is very similar\nto the previous line's term one column to the left.  Can we\nexploit that to reduce the inner loops in the above\nalgorithm?\n\nWe need to catch the one-lower-derivative before it gets\nupdated in the current cycle (i.e., the current column).  If\nwe worked backwards from the largest derivative, we would be\ngetting both the right a[] term and the right power of x.\nIgnoring the factors:\n\\begin{verbatim}\n     p[0]:=a[ann];\n     FOR i:=ann-1 TO 0 BY -1 DO\n       FOR j:=nd TO 1 BY -1 DO\n         pd[j]:=pd[j-1]+x*pd[j];\n       END;\n       pd[0]:=a[i]+x*pd[0];\n     END;\n\\end{verbatim}\n\nNow, what's happening to the factors?\n\\begin{verbatim}\n   init:\n     p\"=0; p':=0; p=a4\n   iter3:\n     p\"=p'+x*p\"=0+x*0=0\n     p'=p +x*p'=a4+x*0=a4\n     p =a3+x*p =a3+x*a4\n   iter2:\n     p\"=p'+x*p\"=a4+x*(0)=a4\n     p'=p +x*p'=a3+x*a4+x*(a4)=a3+2*a4*x\n     p =a2+x*p =a2+x*(a3+x*a4)=a2+a3*x+a4*x^2\n   iter1:\n     p\"=p'+x*p\"=a3+2*a4*x+x*(a4)=a3+3*a4*x\n     p'=p\n     +x*p'=a2+a3*x+a4*x^2+x*(a3+2*a4*x)=a2+2*a3*x+3*a4*x^2\n     p =a1+x*p =a1+x*(a2+a3*x+a4*x^2)=a1+a2*x+a3*x^2+a4x^3\n   iter0:\n     p\"=p'+x*p\"=a2+2*a3*x+3*a4*x^2+x*(a3+3*a4*x)=a2+3*a3*x+4\n     *a4*x^2\n     p'=p +x*p'=a1+a2*x+a3*x^2+a4x^3+x*(a2+2*a3*x+3*a4*x^2)\n          =a1+2*a2*x+3*a3*x^2+4*a4*x^3\n     p =a0+x*p =a0+x*(a1+a2*x+a3*x^2+a4x^3)\n          =a0+a1*x+a2*x^2+a3*x^3+a4*x^4\n\\end{verbatim}\n\nNote that p comes out ok (as expected).  Note that p' comes\nout ok too (definitely not expected).  p\" (and higher\nderivatives) are in the right shape, but the factorial terms\nare incomplete.  What is the pattern?  Let's set up the\nprogram and try it out.  Use $a[i]=1$ for all i, so we can see\nthe factorial terms more easily.  Experiments on\n$x=1,2,3,4,5$ (comparing to MathCAD) show a pattern:  pd[0]\nand pd[1] are ok.  pd[1] is off by $2=2!$ and pd[3] is off by\n$6=3!$.  In other words all of them are off by a factor:\n\\begin{verbatim}\n     pd[j]:=factorial(j)*pd[j]\n\\end{verbatim}\n\nIt just happens that $0!=1$ and $1!=1$, so pd[0] and pd[1] look\nok.  It appears we can clean this up by putting a factorial\nonto pd after computation.  NR92 does this with a home-made\nfactorial.  Bu this has a hidden integer$\\rightarrow$float conversion.\nWe may as well use the factorial function, which does a\ntable lookup (at the cost of a funcall).  And let's do it\nfor all the pd's since it is low cost to catch j=0,1, and\ncertainly clarifies the analysis.\n\n\n", "meta": {"hexsha": "2cb8e54c7024ff3d05a4ce914dcaa33cf1e56292", "size": 9111, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "m3-libs/arithmetic/doc/polynomial.tex", "max_stars_repo_name": "jaykrell/cm3", "max_stars_repo_head_hexsha": "2aae7d9342b8e26680f6419f9296450fae8cbd4b", "max_stars_repo_licenses": ["BSD-4-Clause-UC", "BSD-4-Clause", "BSD-3-Clause"], "max_stars_count": 105, "max_stars_repo_stars_event_min_datetime": "2015-03-02T16:58:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T07:17:49.000Z", "max_issues_repo_path": "m3-libs/arithmetic/doc/polynomial.tex", "max_issues_repo_name": "jaykrell/cm3", "max_issues_repo_head_hexsha": "2aae7d9342b8e26680f6419f9296450fae8cbd4b", "max_issues_repo_licenses": ["BSD-4-Clause-UC", "BSD-4-Clause", "BSD-3-Clause"], "max_issues_count": 145, "max_issues_repo_issues_event_min_datetime": "2015-03-18T10:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T01:27:08.000Z", "max_forks_repo_path": "m3-libs/arithmetic/doc/polynomial.tex", "max_forks_repo_name": "jaykrell/cm3", "max_forks_repo_head_hexsha": "2aae7d9342b8e26680f6419f9296450fae8cbd4b", "max_forks_repo_licenses": ["BSD-4-Clause-UC", "BSD-4-Clause", "BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-10T09:37:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T02:02:05.000Z", "avg_line_length": 31.7456445993, "max_line_length": 70, "alphanum_fraction": 0.6088244979, "num_tokens": 3264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.7119528180979406}}
{"text": "\\section{Introduction Outline}\n\nWe study the problem of segmenting DNA methylation data from brain cells. The data are represented by sequences - at each spatial location, two numbers, i.e. coverage and methylation counts, are observed.\nOur goal is to segment the sequences, where each segment represent certain state, indicating certain functional regions. One way to represent the states is their methylation probabilities, that is, probabilities of methylation given the states.\n\nThere has been growing interests in segmentation with aligned sequences of multiple cell types (citation needed). In these datasets, regions where different cell types have drastically different methylation patterns are of key interest. These regions are called {\\em differential methylation region} in computational biology literature. Specifically, if given a state, the methylation probabilities are different for different cell types, we call it a differential methylation state.\n\nIn this paper, we use a learning-based framework to study these data. We use a probablistic model - binomial hidden Markov model to model these sequences. In particular, for the single sequence model, given each state $h$ and methylation coverage $c$, the methylation count $m$ is drawn from a binomial distribution $\\bin(c,p_h)$, where $p_h \\in [0,1]$ is the methylation probability over state $h$. The multiple sequences model is a generalization over the single sequence model: the methylation counts over the cells $(m^1, \\ldots, m^r)$ are conditionally independent given $h$, and each of them a drawn from a binomial distribution: $m^i | h \\sim \\bin(c^i,p_h)$.\n\nThere are several key challenges for learning on this data using the binomial HMM model:\n\\begin{enumerate}\n\\item For biological applications, we would like to use the full dataset for accurate estimation. Traditional methods such as EM takes a long time to process the data, and thus are unsuitable for this application.\n\\item Since we are given a large observation space (over the product space of coverage and methylation counts), a naive application of the tensor decomposition algorithm (e.g the tensor power method in~\\cite{AGHKT12}) would need high time and space complexities.\n\\item A line of work on kernel-based tensor decomposition methods for latent variable models have been proposed~\\cite{SADX14}, however the time and space complexity of running such algorithm will be at least quadratic in the size of the training data, which is prohibitive.\n\\end{enumerate}\n\nIn this paper, we propose a feature map based framework to address all the challenges. In addition, we develop a novel feature map, i.e. Beta-Bernoulli feature map. After recovering the expected feature map, we apply a novel recovery procedure, estimating the expected methylation probability robustly.\n\nIn the experiments, we observe model mismatches, thus making the recovered value of transition matrix and initial probability unstable. To address this issue, we introduce a novel stablization procedure.\n\nWe test the performance of our algorithm on both synthetic and real datasets. For synthetic datasets, our improvement over EM are both computational and statistical; we observed better estimation accurary and faster running time. For real datasets, we observe comparable recovery results to EM. However, our algorithm has a significant improvement in running time. %Moreover, our recovered states has a better interpretability compared to EM.\n", "meta": {"hexsha": "f971896fe93c1826e1c8a201ccec4fc0cf5f586c", "size": 3462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "kernelbin/paper/intro.tex", "max_stars_repo_name": "anapophenic/knb", "max_stars_repo_head_hexsha": "0e865a47791bf801c00078a128a4d21e4375e732", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-04-21T21:10:22.000Z", "max_stars_repo_stars_event_max_datetime": "2016-08-27T19:15:23.000Z", "max_issues_repo_path": "kernelbin/paper/intro.tex", "max_issues_repo_name": "anapophenic/knb", "max_issues_repo_head_hexsha": "0e865a47791bf801c00078a128a4d21e4375e732", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "kernelbin/paper/intro.tex", "max_forks_repo_name": "anapophenic/knb", "max_forks_repo_head_hexsha": "0e865a47791bf801c00078a128a4d21e4375e732", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 157.3636363636, "max_line_length": 665, "alphanum_fraction": 0.808492201, "num_tokens": 697, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.7118986361090685}}
{"text": "\\documentclass[10pt]{article}\n\n% Manage page layout\n\\usepackage[margin=2.5cm, includefoot, footskip=30pt]{geometry}\n\\pagestyle{plain}\n\\setlength{\\parindent}{0em}\n\\setlength{\\parskip}{1em}\n\\renewcommand{\\baselinestretch}{1}\n\n\\usepackage{blkarray}\n\\usepackage{multirow}\n\\usepackage{amsmath}\n\\usepackage{enumerate}\n\n\\title{\\textbf{Week 3.} Static games with complete information II: Elimination of dominated strategies, Nash equilibrium}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\\vspace{-1cm}\n\n\\subsection*{Exercise 1: Iterated elimination of dominated strategies I}\n\n\\textbf{Construct a 2-player game such that:}\n\n\\begin{enumerate}\n    \\item Both players have 3 actions.\n    \\item The game cannot be solved by elimination of dominated strategies.\n    \\item The game can be solved by iterated elimination of dominated strategies.\n\\end{enumerate}\n\n\\subsection*{Exercise 2: Iterated elimination of dominated strategies II}\n\nConsider the following 3-players game. Here the first player chooses a row,\nthe second player chooses a column, and the third player chooses a matrix.\n\n\\textbf{Can you solve this game using iterated elimination of strategies?}\n\n\\begin{equation*}\n\\begin{blockarray}{ccc}\n    & \\BAmulticolumn{2}{c}{\\text{Matrix } 1} \\\\ [1em]\n    & \\text{Col } 1 & \\text{Col } 2 \\\\\n    \\begin{block}{c(cc)}\n        \\text{Row } 1 & (2, 1, 6) & (3, 2, 3) \\\\\n        \\text{Row } 2 & (0, 4, 0) & (1, 0, 0) \\\\\n    \\end{block}\n\\end{blockarray}\\qquad\n%\n\\begin{blockarray}{ccc}\n    & \\BAmulticolumn{2}{c}{\\text{Matrix } 2} \\\\ [1em]\n    & \\text{Col } 1 & \\text{Col } 2 \\\\\n    \\begin{block}{c(cc)}\n        \\text{Row } 1 & (1, -1, 4) & (2, 1, 4) \\\\\n        \\text{Row } 2 & (-1, 4, 0) & (0, 0, 3) \\\\\n    \\end{block}\n\\end{blockarray}\n\\end{equation*}\n\n\\subsection*{Exercise 3: Nash equilibrium vs dominance solvability}\n\n\\textbf{Prove the following statements:}\n\n\\begin{enumerate}[(i)]\n    \\item If a pure strategy \\(s^{(i)}_{j}\\) is dominated by a pure strategy \\(s^{(i)}_{k}\\) and\n    \\(\\sigma = (\\sigma^{(1)}, \\dots, \\sigma^{(n)})\\) is a Nash equilibrium, then\n    \\(\\sigma^{(i)}_{j}=0\\).\n    \\item If the game is dominance solvable such that the unique outcome of\n    iterated elimination of dominated strategies is some pure strategy\n    \\(s=(s^{(1)}, \\dots, s^{(n)})\\), then \\(s\\) is a Nash equilibrium.\n\\end{enumerate}\n\n[Suggestion: One could use contradiction to prove the above statements. For example, for (i)\nassume that these was a Nash equilibrium with \\(\\sigma^{(i)}_{j}>0\\), and show\nthat this would yield some contradiction.]\n\n\\subsection*{Exercise 4: Best responses}\n\nConsider the stag hunt game:\n\n\\begin{equation*}\n    \\begin{blockarray}{cccc}\n       & & \\BAmulticolumn{2}{c}{\\underline{\\text{player 2}}} \\\\ [1em]\n       & & \\text{Stag} & \\text{Hare} \\\\\n        \\begin{block}{cc(cc)}\n\\underline{\\text{player 1}} & \\text{Stag} & (10, 10) & (0, 6) \\\\\n                            & \\text{Hare} & (6, 0) & (6, 6) \\\\\n        \\end{block}\n    \\end{blockarray}\n\\end{equation*}\n\nSuppose player 1 uses the mixed strategy \\((x, 1- x)\\), where \\(x\\) is player 1's\nprobability to Stag. Similarly, player 2's strategy is \\((y, 1 - y)\\).\n\n\\begin{enumerate}[(i)]\n    \\item For given \\(x, y\\) compute the players' payoffs \\(\\pi^{(1)}(x, y),\n    \\pi^{(2)}(x, y)\\) (see Remarks 2.6, 2.7).\n    \\item For a given \\(y\\) compute player 1's best response (BR(\\(y\\))). In\n    particular, show that there is some \\(y^{*}\\) such that all \\(x \\in [0,\n    1]\\) are a best response.\n    \\item Draw the two best response correspondences BR(\\(x\\)), BR(\\(y\\)) into a\n    \\(x-y\\) plane. How often do they intersect? What does it mean if they\n    intersect?\n\\end{enumerate}\n\n\\end{document}\n\n", "meta": {"hexsha": "4a3b5bc29d7254ef51b56ee5d64c6045206d0352", "size": 3656, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "teaching/classical_game_theory/exercises/w3.tex", "max_stars_repo_name": "Nikoleta-v3/social-behaviour", "max_stars_repo_head_hexsha": "cc146ad7662695b4afc09357d7ffad3030cd7aa4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "teaching/classical_game_theory/exercises/w3.tex", "max_issues_repo_name": "Nikoleta-v3/social-behaviour", "max_issues_repo_head_hexsha": "cc146ad7662695b4afc09357d7ffad3030cd7aa4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-10-23T14:05:41.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-21T16:24:55.000Z", "max_forks_repo_path": "teaching/classical_game_theory/exercises/w3.tex", "max_forks_repo_name": "Nikoleta-v3/social-behaviour", "max_forks_repo_head_hexsha": "cc146ad7662695b4afc09357d7ffad3030cd7aa4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.1682242991, "max_line_length": 121, "alphanum_fraction": 0.6449671772, "num_tokens": 1193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.8757870046160257, "lm_q1q2_score": 0.7118986334392313}}
{"text": "\\subsubsection{Linear Factors}\r\n\r\nThis is the the most basic case where the degree of the numerator is less than the degree of the denominator and the denominator factors into all linear factors (ie no complex roots) with no repeated roots.\r\nIn this case we can write\r\n\\begin{equation*}\r\n\t\\frac{P(x)}{Q(x)} = \\frac{A_1}{(x-a_1)} + \\ldots + \\frac{A_n}{(x-a_n)}\r\n\\end{equation*}\r\nMultiplying each side by $Q(x)$,\r\n\\begin{equation*}\r\n\tP(x) = A_1(x-a_2) \\ldots (x-a_n) + \\ldots + A_n(x-a_1) \\ldots (x-a_{n-1})\r\n\\end{equation*}\r\nWe can then find each $A_i$ by evaluating both sides at $x=a_i$, since every term except the ith one has an $(x-a_i)$ factor, all terms except the ith one will go to 0.\r\nSo,\r\n\\begin{equation*}\r\n\tA_i = \\frac{P(a_i)}{(x-a_i) \\ldots (x-a_{i-1})(x-a_{i+1}) \\ldots (x-a_n)}\r\n\\end{equation*}\r\n\r\n\\input{./backgroundReview/algebraPreCalc/linearFactors_example.tex}", "meta": {"hexsha": "056ddb200366298e6d967292b99489b98a61379e", "size": 880, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/backgroundReview/algebraPreCalc/linearFactors.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/backgroundReview/algebraPreCalc/linearFactors.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/backgroundReview/algebraPreCalc/linearFactors.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.8888888889, "max_line_length": 207, "alphanum_fraction": 0.6886363636, "num_tokens": 296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7118986268681541}}
{"text": "\\section{Stable Matching}\n\n\\frame{\n{Part 4: Stable Matching}\n\n\\tableofcontents[currentsection,hideallsubsections, firstsection=1, sections={1-4}]\n}\n\n\\begin{frame}\n  \\frametitle{The Stable Marriage Problem}\n  \\begin{center}\n    \\includegraphics[width=.5\\textwidth]{../img/marriage1}\\\\\n    Which boy should marry with which girl?\n  \\end{center}\n\n\\end{frame}\n\n\\begin{frame}{The Stable Marriage Problem}{Each boy and girl has a preference list}\n\n  \\begin{center}\n    \\includegraphics[width=.4\\textwidth]{../img/marriage1}\n    \\includegraphics[width=.45\\textwidth]{../img/marriage2}\n  \\end{center}\n\n  Which algorithm do you use to match them?\n\\end{frame}\n\n\\begin{frame}{The \"Boy-greedy\" algorithm}\n  \\structure{Boy-greedy algorithm}: Each boy, in order, marries to favorite girl:\n  \\begin{center}\n    \\includegraphics[width=.7\\textwidth]{../img/marriage3}\n  \\end{center}\n\\end{frame}\n\n\\begin{frame}{The \"Boy-greedy\" Algorithm}\n\n  \\structure{Boy-greedy algorithm}: Each boy, in order, marries to favorite girl:\n  \\begin{center}\n    \\includegraphics[width=.7\\textwidth]{../img/marriage4}\n  \\end{center}\n\\end{frame}\n\n\\begin{frame}{The \"Boy-greedy\" Algorithm}{Final Pairings}\n\n  \\begin{center}\n    \\includegraphics[width=.7\\textwidth]{../img/marriage5}\n  \\end{center}\n\\end{frame}\n\n\\begin{frame}{The \"Boy-greedy\" Algorithm}{Rogue Couples}\n  \\begin{center}\n    \\includegraphics[width=.41\\textwidth]{../img/marriage7}\n    \\includegraphics[width=.45\\textwidth]{../img/marriage2}\n  \\end{center}\n\n  \\alert{Girl C} likes \\structure{Boy 4} better than \\structure{Boy 1}. \\structure{Boy 4} likes \\alert{Girl C} better than \\alert{Girl B}.\n\n  Can we find a pairing without rogue couples?\n\\end{frame}\n\n\n\\begin{frame}{A stable matching}{Using a Girl Greedy algorithm}\n  \\begin{center}\n    \\includegraphics[width=.45\\textwidth]{../img/marriage8}\n    \\includegraphics[width=.45\\textwidth]{../img/marriage2}\n  \\end{center}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Why is the Stable Marriage Problem Important?}\n\n  {\\larger\n    \\begin{itemize}\n    \\item School Admissions in the US\n    \\begin{itemize}\n      \\item Matching school preference and student preference\n    \\end{itemize}\\bigskip\n\n\n    \\item Server/Client Request Matching\n    \\begin{itemize}\n      \\item In large webpages, multiple HTTP servers serve the same page for multiple clients;\n      \\item Servers are matched to clients by geolocation, etc;\n    \\end{itemize}\\bigskip\n\n    \\item Etc...\n    \\end{itemize}\n  }\n\\end{frame}\n\n\\subsection{``Mating Ritual'' Algorithm}\n\n\\begin{frame}{The ``Mating Ritual'' Algorithm}\n\n    Let us describe an algorithm to {\\bf always} find a\n    stable matching:\\bigskip\n\n    \\begin{itemize}\n      \\item {States}:\n      \\begin{itemize}\n        \\item Each boy is proposing to some girl.\n        \\item Each girl has a list of proposers.\n      \\end{itemize}\n      \\item {\\bf Start State}: Every boy is proposing to their favorite girl.\n    \\end{itemize}\n\n    Algorithm:\n    \\begin{enumerate}\n      \\item If all girls have $\\leq 1$ proposers in their list, they are paired and the algorithm ends;\n      \\item Any girl with $> 1$ proposers in their list reject all except their favorite proposer;\n      \\item If a boy is rejected, they propose to the next girl in their list;\n      \\item Return to (1).\n    \\end{enumerate}\n\\end{frame}\n\n\\begin{frame}{The Mating Ritual Algorithm}{Example}\n\n  \\begin{columns}\n    \\column{0.45\\textwidth}\n    \\includegraphics[width=1\\textwidth]{../img/marriage2}\n    \\column{0.55\\textwidth}\n    {\\large\n      \\begin{itemize}\n      \\item {\\bf iter 1}: No rejections. Proposals:\n        \\begin{itemize}\n        \\item A: 2, 4, 5\n        \\item B:\n        \\item C: 1\n        \\item D: 3\n        \\item E:\n        \\end{itemize}\n\n      \\item {\\bf iter 2}: A rejects 2 and 4. Proposals:\n        \\begin{itemize}\n        \\item A: 5\n        \\item B: 2\n        \\item C: 1, 4\n        \\item D: 3\n        \\item E:\n        \\end{itemize}\n      \\end{itemize}\n\n    }\n  \\end{columns}\n\\end{frame}\n\n\\begin{frame}{The Mating Ritual Algorithm}{Example}\n\n  \\begin{columns}\n    \\column{0.45\\textwidth}\n    \\includegraphics[width=1\\textwidth]{../img/marriage2}\n    \\column{0.55\\textwidth}\n    {\\large\n      \\begin{itemize}\n      \\item {\\bf iter 3}: C rejects 1. Proposals:\n        \\begin{itemize}\n        \\item A: 5\n        \\item B: 1, 2\n        \\item C: 4\n        \\item D: 3\n        \\item E:\n        \\end{itemize}\n\n      \\item {\\bf iter 4}: B rejects 1. Proposals:\n        \\begin{itemize}\n        \\item A: 5\n        \\item B: 2\n        \\item C: 4\n        \\item D: 3\n        \\item E: 1\n        \\end{itemize}\n      \\end{itemize}\n    }\n  \\end{columns}\n\\end{frame}\n\n\\begin{frame}{The \"Mating Ritual\" Algorithm}{Proof of Correctness}\n\n  {\\larger\n  To proof the correctness of an algorithm, requires that you demonstrate two facts:\n\n    \\begin{itemize}\n    \\item The algorithm stops at some point after the start state;\n\n      \\bigskip\n\n    \\item The algorithm is correct when it stops;\n    \\end{itemize}\n  }\n\\end{frame}\n\n\\begin{frame}{Proof of Correctness}{The algorithm stops}\n\n  {\\larger\n    Every day, the \\structure{total number} of girls in\n    the boy's lists is reduced.\n\n    \\bigskip\n\n    \\begin{itemize}\n      \\item Every day, {\\bf At least one boy} is rejected by {\\bf at least one girl}\n      \\begin{itemize}\n        \\item If no boy is rejected, it means that all girls have $\\leq 1$ boys in their list\n        \\item If all girls have $\\leq 1$ boys in their list, the algorithm stops;\n      \\end{itemize}\n      \\item At some point, every boy's list will have {\\bf no girls}:\n      \\begin{itemize}\n        \\item A boy with no girls in their list will propose to no one.\n        \\item If no boys propose, then all girl's lists are empty.\n        \\item Then the algorithm stops.\n      \\end{itemize}\n    \\end{itemize}\n\n    \\bigskip\n\n    The total size of \"Boy's Lists\" is \\structure{strictly decreasing}, so the algorithm is guaranteed to stop.\n  }\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Proof of Correctness: No rogue couples}\n\n  {\\larger\n\n    \\begin{itemize}\n    \\item {\\bf Lemma 1}: The rank of a girl's favorite is {\\bf weakly\n      increasing}\\\\ Every iteration, the girl rejects a favorite {\\bf\n      iff} she finds a \\structure{better one}.\n\n      \\bigskip\n\n    \\item {\\bf Lemma 2}: The rank of a boy's favorite is {\\bf weakly\n      decreating}\\\\ Every iteration, the boy stays with current\n      favorite, or is rejected and goes to the next lower one.\n\n    \\end{itemize}\n  }\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Proof of Correctness: No rogue couples}\n\n  {\\larger {\\bf Invariant:} If $G_i$ is not on $B_j$ list, she has a\n    better curent favorite.\n\n    \\bigskip\n\n    \\begin{itemize}\n      \\item At the beginning of the algorithm, $G_i$ is on $B_j$ list;\n      \\item $G_i$ will reject a boy proposing to her only if a better favorite is also proposing to her;\n      \\item This implies that a girl's favorite never get worse (lemma 1)\n    \\end{itemize}\n  }\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Proof of Correctness: No rogue couples}\n\n  {\\larger\n\n    {\\bf Lemma:} When boy $B_i$ is paired, he cannot form a rogue\n    couple.\n\n    \\bigskip\n\n    {\\bf Proof by Cases:}\n    \\begin{itemize}\n    \\item {\\bf Case 1:} $B_i$ tries to form a rogue couple with\n      someone not on his list. However, by \\alert{Invariant}, any girl\n      not on his list has a better favorite, and no rogue couple is\n      possible.\n\n    \\item {\\bf Case 2:} $B_i$ tries to form a rogue couple with\n      someone on his list. However, by \\alert{Lemma 2}, $B_i$ always\n      propose to the best girl in his list, and no rogue couple is\n      possible.\n    \\end{itemize}\n\n    \\bigskip\n\n    {\\bf Therefore}, no rogue couple is possible.\n\n  }\n\\end{frame}\n\n% \\begin{frame}\n%   \\frametitle{Extra Topics}\n%\n%   {\\larger\n%\n%     Check the class materials for ``Hall's Graphs'', for more\n%     information on matching.\n%\n%   }\n%\n% \\end{frame}\n", "meta": {"hexsha": "5d4c2f181883e930a728f2410705c845e2e828ce", "size": 7891, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week05/04_StableMatching.tex", "max_stars_repo_name": "caranha/MathCS", "max_stars_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-09-13T18:59:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T02:14:56.000Z", "max_issues_repo_path": "week05/04_StableMatching.tex", "max_issues_repo_name": "caranha/MathCS", "max_issues_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week05/04_StableMatching.tex", "max_forks_repo_name": "caranha/MathCS", "max_forks_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.569023569, "max_line_length": 138, "alphanum_fraction": 0.649980991, "num_tokens": 2340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.8757869803008764, "lm_q1q2_score": 0.7118986057337403}}
{"text": "% Convolution appendix. \n\n\\subsection{Introduction}\n\nfMRI data presents a distinct challenge for relating neural stimuli \nto BOLD (blood-oxygen-level dependent) response. fMRI scans record changes \nin oxygenation levels of hemoglobin in the brain. However, there is a delay \nbetween the neural stimulus and the change in blood oxygen levels in a given \narea. In our case, the neural stimulation comes from a event-related \nexperimental design. A commonly assumed hemodynamic response to a neurological \nstimulus is the double gamma function that can be seen in Figure \n\\ref{fig:hrf}. The complete hemodynamic response function needs to be modeled \nin order to better relate stimulation and the BOLD response from the fMRI scan.\nIt should be noted that the BOLD response is highly noisy and we are really \ntrying to capture the blood oxygenation level change to the stimulation.\n\n\\subsection{Mathematics}\n\\subsubsection{Convolution Theory and Mathematics}\n\nTo relate stimuli to BOLD response, we convolved the time courses of discrete \nstimuli with the assumed response to a single stimulus. At a basic \nlevel, convolution is a distinct combination of two functions (say $f$ and \n$g$). This combination is just the ``integral that expresses the amount of \noverlap of $f$ as it is shifted over another function $g$'' \n\\cite{weissten2015convolution}. \nThere are many examples of this, but the following is basic idea that we will \nexpand off of later. \n\nLet us define the function $f$ as a sum of two gamma functions and $g$ as a \n``continuous'' specialized step function (we will examine why these functions \nare valuable later). Graphically, we can see their plots in Figure \\ref{fig:f}\nand \\ref{fig:g}, and mathematically we will define them as in the following \nequations \\ref{eq:gamma2} and \\ref{eq:step}, respectively.\n\n\\begin{equation} \\label{eq:gamma2}\nf(t)=\\frac{.6}{.17}\\cdot  \\big[G_1(6,t)-.35 \\cdot G_1(12,t) \\big]\n\\end{equation}\n\nwhere $G_1(k,t) =\\frac{1}{\\Gamma(k)} t^{k-1} e^{-t}$ (the gamma pdf with \n$\\theta =1$)\n\n\\begin{equation} \\label{eq:step}\n g(t)=\\Big \\{ \\begin{tabular}{l c}\n \t\t0  & if  5.85 $\\leq$ t $\\leq$ 6.15\\\\\n \t\t.6  & otherwise \\\\\n \t\t\\end{tabular} \\end{equation}\n \t\t\n \t\t\n\\begin{figure}[ht]\n\\centering\n\\begin{minipage}[b]{0.45\\linewidth}\n\t\\centering\n\t\\includegraphics[width=.8\\linewidth]{../images/hrf_pattern.png} \n\t\\caption{$f$ (``Stabilized Function'').}\n\t\\label{fig:f}\n\\end{minipage}\t\n\\quad\n\\begin{minipage}[b]{0.45\\linewidth}\n\t\\centering\n\t\t\\includegraphics[width=.8\\linewidth]{../images/play.png} \n\t\\caption{$g$ (``Moving function'').}\n\t\\label{fig:g}\n\\end{minipage}\n\\end{figure}\n\n\nAs mentioned in the earlier definition, if we move $g$ across $f$ from \nleft to right, we will see something similar to Figure \\ref{fig:math} for \ndiscrete time intervals. If we plot these values (the integration of the \ndifferences), we will get a plot very similar to that of $f$ when $f$ is \nstarting at a certain point. (The plot actually ``cheats'' when $f$ is \nnegative, and we would have to alter definitions a little bit). If we had \nmultiple peaks in our $g$ function (i.e. multiple distinct``zero'' places), we \nwould expect to get multiple non-zero differences between the functions at \neach time capture. \n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[width=.5\\linewidth]{../images/math_convolved.png}\n\t\\caption{Convolution of $f$ and $g$.}\n\t\\label{fig:math}\n\\end{figure}\n\n\n\\subsubsection{Convolution Applied to Stimulus}\n\nThe ``continuous'' nature of the step function ``g'' does not extend well into \nthe discrete time series that we have. However, one approach for fMRI analysis \nis to approach the convolution as something slightly different: mathematical \nsums. For example, in the previous section, we can treat $f$ as the same, and \n$g$ as $g'$ defined in equation \\ref{eq:g_prime}.\n\n\\begin{equation}\\label{eq:g_prime}\n g'(t)=\\Big \\{ \\begin{tabular}{l c}\n \t\t1  & if t=6\\\\\n \t\t0  & otherwise \\\\\n \t\t\\end{tabular} \\end{equation}\n\nWe could then find the value of the convolution of $g'$ and $f$ for discrete \nintegers as in equation \\ref{eq:math_discrete}.\n\n\n\\begin{equation}  \\label{eq:math_discrete}\nr(t)=  f(t-6)\n\\end{equation}\n\n\n\nIf we allow for multiple non-zero periods in $g'$, we can get a more general \nmodel in equation \\ref{eq:math_discrete_extend}, where each $t_i$ is a value \nwhen $g'(t_i) \\neq 0$: \n\n\\begin{equation}  \\label{eq:math_discrete_extend}\nr(t)= \\sum_{i=1}^n f(t-t_i)\n\\end{equation}\n\nThis equation gives a good glimpse into what the hemodynamic response would be \nafter stimulus at time $t_i$ for $i \\in {1,...,n}$. Moreover, one could extend \nthe idea to include a ``strength'' value of the stimulus by changing the \n$g'(t_i)$ to values other than 1. If that was the case, we would change \nthe response equation to Equation \\ref{eq:math_discrete_final} to allow us to \ninclude all discrete $t$ into the equation where $g'(t_i)$ is now expected to \nbe zero (so $n$ becomes much larger). \n\n\\begin{equation}  \\label{eq:math_discrete_final}\nr(t)= \\sum_{i=1}^n g'(t_i) f(t-t_i)\n\\end{equation}\n\n\nWith this new equation, we can consider function $f$ and $g'$ displayed \ngraphically [Figure \\ref{fig:hrf}, \\ref{fig:on_off}, respectively] and \ntheir ``convolved'' output [Figure \\ref{fig:convolve1}].\n\n\n\n\n\\begin{figure}[ht]\n\\centering\n\\begin{minipage}[b]{0.45\\linewidth}\n\t\\centering\n\t\\includegraphics[width=.8\\linewidth]{../images/hrf_pattern.png} \n\t\\caption{$f$ (``Stabilized Function'').}\n\t\\label{fig:hrf}\n\\end{minipage}\t\n\\quad\n\\begin{minipage}[b]{0.45\\linewidth}\n\t\\centering\n\t\\includegraphics[width=.8\\linewidth]{../images/on_off_pattern.png} \n\t\\caption{$g'$ (``Moving function'').}\n\t\\label{fig:on_off}\n\\end{minipage}\n\\end{figure}\n\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[width=.5\\linewidth]{../images/initial_convolved.png}\n\t\\caption{Convolution of $f$ and $g'$.}\n\t\\label{fig:convolve1}\n\\end{figure}\n\n\\subsection{Approach to our Specific Problem}\n\n\\subsubsection{Returning to Our fMRI Data}\n\nWe can now apply this discrete approach to convolution between $f$ and $g'$ \nto our data. The $f$ is actually a common representation of the hemodynamic \nresponse, and the $g'$ is a good representation of the stimuli from an \nevent-related trial \\cite{brett2015course}. \n\n\\subsubsection{Naive Approach (using \\texttt{np.convolve})}\n\nA \\texttt{numpy} function \\texttt{np.convolve}, which takes advantage of \nfast Fourier transforms for efficiency (it boils down to fewer computations \nusing roots of unity) is commonly used to do discrete convolution. A naive \napproach for convolving two functions would use this function directly, but\n\\texttt{np.convolve} assumes that the intervals between stimuli mirror the \ndesired intervals between prediction intervals. As such, we should not naively \napply \\texttt{np.convolve} to our data (though we do for a base model). \nEven so, exploring this naive approach for convolving the hemodynamic response \ngives an idea about what not to do, and sets a higher bar for accuracy.\n\n\\subsubsection{Needed Improvements: Moving beyond naive \\texttt{np.convolve}}\n\nOur data fails to meet the assumption that the intervals are equidistant, \nwhich is required to naively apply \\texttt{np.convolve}. Especially in our \ncase, there was not an simple fix, such as performing some basic rounding in \norder to then correctly utilize \\texttt{np.convolve}. All the following \napproaches improve on the basic \\texttt{np.convolve} approach's accuracy, but \nultimately circle back to incorporating \\texttt{np.convolve} to improve the \nspeed of the convolution.\n\nOur condition file (\\texttt{cond1}) lists stimulus times for when the \nindividual pumped the balloon but did not pop it. For subject 001, the \nfirst 10 data points are as follows [Figure \\ref{table:cond1}]:\n\n\\vspace{5mm}\n\n\\begin{figure}[ht]\n\\begin{center}\n\\begin{tabular}{|cccccccccc|}\n  \\hline\n0.0671 &\n2.1251 &\n3.7681 &\n5.6601 &\n7.8673 &\n9.3443 &\n19.7831 &\n22.0402 &\n23.5837 &\n25.1434 \\\\\n \\hline\n\n  \\end{tabular}\n   \\caption{First 10 values for Sub 001, condition 1.}\n  \\label{table:cond1}\n\\end{center}\n\\end{figure}\n \nClearly, this short time series does not align with idealized scans that \nstart at $t=0$ and occur every two seconds apart. As such, we had to go back \nto the drawing board to try to reproduce our expected hemodynamic response for \nthe entire time course.\n\n\n\\subsection{Summary of Approaches}\nOur first approach attempts to correctly match the theory underlying our data. \nOur second approach tries to utilize \\texttt{np.convolve} by expanding the \ngrid of desired results (thanks to advice from  Matthew Brett, Jean-Baptiste \nPoline, and Jarrod Millman).\n\n\n\\subsubsection{Initial Correction to Represent Theoretical Idea}\nTo account for our data's lack of any easily identifiable grid structure \nbetween when a stimulus was recorded and when our scans occurred (on the \norder of every 2 seconds), we went back to the theory of convolution and \nimplemented code to recreate equation \\ref{eq:math_discrete_final} directly. \nTo do so, we also had to create a function that works with all discrete points \nof $f$, the stimulus response as potential starts of the hemodynamic response, \nmultiplied by the actual value of $f$, as seen in equation \n\\ref{eq:code_convolve}:\n\n\\begin{equation} \\label{eq:code_convolve}\nr(t)= \\sum_{i=1}^n g'_{i} f(t-t_i)\n\\end{equation}\n\nwhere $g'_{i}$ is the value of $g'$ at $t_i$ (allowing for zeros and varying \nnon-zero values of $g'$).\n\n\n\\subsubsection{Matrix Multiplication}\nEquation \\ref{eq:code_convolve}, reproduced below\n\n$$r(t)= \\sum_{i=1}^n g'_{i} f(t-t_i)$$\n\ncan be rewritten as a matrix multiplication problem and can be seen below:\n\n\\begin{equation} \\label{eq:matrix_code_convolve}\nr(t)=  g^*(t)^T f^*(t)\n\\end{equation}\n\nwhere $g^*$ is a vectorized function of $g'$ of $t$ as a scalar output and \n$f^*$ is the vector of $f$ values (irrespective of location, as the $t^*$ \ntakes that into account). This is a useful representation, since matrix \nmultiplication is faster for Python's numpy arrays. \n\n\n\\subsubsection{Using FFT with \\texttt{np.convolve}}\nThe ``theoretical'' solution lacked computation efficiency (despite \nconsiderable speed improvements from matrix multiplication), so we also \napproached the problem by creating a denser grid between each scan (two seconds \napart). Then we rounded the actual times of the stimulus to meet this more \nfinely scaled grid. This allowed us to utilize \\texttt{np.convolve} with its \nfaster, FFT-based algorithms, before reducing back down to our two-second \ngrid. \n\n\n\\subsection{Example}\n\nNow that we have discussed the theory and possible implementations \nfor convolving event-related stimulation, we will look at a basic example from \nour data. In doing so, we examine the trade-offs between theoretical accuracy \nand computational efficiency. We will consider just subject 001's condition \nfiles. \n\n\n\\begin{figure}[ht]\n\\centering\n\t\\begin{minipage}[b]{0.45\\linewidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.8\\linewidth]{../images/convolution_vs_neural_stimulus}\n\t\t% needs to be from the event_related_HRF_script2.py \n\t\t\\caption{\\scriptsize{Different convolution functions vs. the Neural stimulus}}\n\t\t\\label{fig:convolution}\n\n\t\\end{minipage}\n\\quad\n\t\\begin{minipage}[b]{0.45\\linewidth}\n\t\t\\centering\n\t\t\\begin{tabular}{|l | c|}\n\t\t\\hline\n\t\tname in graph       & Speed per loop \\\\\n\t\t\\hline\n\t\tnp naive approach & 14.4 $\\mu$s  \\\\\n\t\tuser 2     \t\t    & 972 ms  \\\\\n\t\tuser 3     \t\t    & 1.15 s    \\\\\n\t\tuser 4 (15 cuts)      & 98.3 ms \\\\\n\t\tuser 4 (30 cuts)      & 185 ms  \\\\\n\t\tuser 5     \t \t    & 110 ms   \\\\\n\t\t\\hline\n\t\t\\end{tabular}\n\t\t\\vspace{5mm}\n\t\t\\caption{\\scriptsize{Speed to create HRF predictions for Subject 001, \n\t\tall conditions}}\n\t\t\\label{table:convolution}\n\t\\end{minipage}\n\\end{figure}\n\nThe first method in the table ``np naive approach'' method blindly plugs \nour data into the \\texttt{np.convolve} function and is provided to showcase \npotential speed. The ``user 2'' method  was the first approach to match the \ntheory, though it matches the stimulation times instead of the scan times. \nThe ``user 3'' method is the most theoretically sound model (and is our \nstandard for accuracy). The ``user 5'' model  is our matrix version of  \n``user 3'' and has the same accuracy, but is observably faster. The \n``user 4'' methods involve the grid cut usage of \\texttt{np.convolve}\nwith notations for the number of slices between each scan. We concluded that \n\"user 4 (15 cuts)\" was the best approach since it gives us speed and very \nclose accuracy to the golden standard --- \"user 3\".\n\n\n\n\n\n\n%While this final method does lose some accuracy compared to the more \n%theoretically rigorous approach, the trade-off brings considerable gains in \n%computational efficiency. \n\n\n%Needed references:\n%Brett, Matthew and Poline, J-B  (2013). Convolution. Retrieved from \n% http://practical-neuroimaging.github.io/on_convolution.html\n\n% Weissten, Eric W. ``Convolution''. From MathWorld - A Wolfram Web  Resource. \n% Retrieved from htt://mathworld.wolfram.com/Convolution.html\n\n", "meta": {"hexsha": "b49888032439ad1781a257ec39e5d6c3040a0b77", "size": 13003, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/appendix/appendix_convolution.tex", "max_stars_repo_name": "berkeley-stat159/project-alpha", "max_stars_repo_head_hexsha": "330d025c4eda94d390a82e86deecb791086c9dbf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2015-10-30T23:08:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T03:44:02.000Z", "max_issues_repo_path": "paper/appendix/appendix_convolution.tex", "max_issues_repo_name": "berkeley-stat159/project-alpha", "max_issues_repo_head_hexsha": "330d025c4eda94d390a82e86deecb791086c9dbf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 179, "max_issues_repo_issues_event_min_datetime": "2015-10-25T15:59:56.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-31T02:40:24.000Z", "max_forks_repo_path": "paper/appendix/appendix_convolution.tex", "max_forks_repo_name": "berkeley-stat159/project-alpha", "max_forks_repo_head_hexsha": "330d025c4eda94d390a82e86deecb791086c9dbf", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2015-10-20T19:15:10.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-23T19:33:03.000Z", "avg_line_length": 37.2578796562, "max_line_length": 80, "alphanum_fraction": 0.7415980927, "num_tokens": 3624, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391599428538, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7118335012822009}}
{"text": "In this cahpter, we describe the implementation of a sample\napplication---a solver for the maximum cut problem. This application\nis a prototypical example of branch and cut, i.e., BCP with a fixed\nset of variables. No column generation is used in this implementation.\nThis simplifies many of the basic tasks.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{The Max Cut Problem}\n\\label{MCP}\n\nGiven an undirected graph $G=(N,E)$ with edge weight function $\\omega:\nE \\rightarrow {\\rm \\bf R}$, the Maximum Cut Problem (MCP) is that of\npartitioning the nodes into two subsets in such a way that the total\nweight of the edges in the cut separating the two sets is maximized.\nThis is a well-known problem---several branch and cut algorithms for\ndense graphs have been presented in \n\\cite{A:barahona-junger-reinelt,A:desimone-rinaldi}. In the following\ndescription, we consider complete graphs only. For a complete graph\nundirected graph with $n$ nodes, a linear relaxation of the integer\nprogramming problem is givem by\n\\begin{eqnarray}\n\\min \\;\\; & c^Tx & \\nonumber \\\\\n{\\rm s.t.} \\;\\;\\; && \\nonumber \\\\\n& x_{ij}+x_{jk}+x_{ik} \\le  2 & \\;\\;\\;\\forall (i,j,k) \\in N^3 \n\\label{tri-0} \\\\\n& x_{ij}-x_{jk}-x_{ik} \\le  0 & \\;\\;\\;\\forall (i,j,k) \\in N^3 \n\\label{tri-1} \\\\\n& \\hskip .51in 0 \\le x_{ij} \\le 1 & \\;\\;\\;\\forall (i,j) \\in E \\\\\n\\end{eqnarray}\nHere $x_{ij}$ takes value 1 if the edge $(i,j)$ appears in the cut, and 0\notherwise. Constraints (\\ref{tri-0}) - (\\ref{tri-1}) are called the\n{\\it triangle inequalities} and they define facets of the cut polytope\n(see \\cite{A:barahona-mahjoub:cut-polytope}).\n\nAnother set of inequalities, which is a superset of (\\ref{tri-0}) -\n(\\ref{tri-1}), is the following. Let $C$ be a cycle and $F \\subseteq\nC$ with $|F|=2k+1$. Then\n\\begin{equation}\n\\sum_{e \\in F} x_e - \\sum_{e \\in C\\backslash F} x_e \\le |F|-1 \\label{c}\n\\end{equation}\nis a valid inequality. This follows from the fact that the\nintersection of a cycle and a cut has even cardinality. Note, that\nalthough this set of inequalities include those in (\\ref{tri-0}) -\n(\\ref{tri-1}), the polytope defined by these is the same, i.e., these\ninequalities can be derived from those in (\\ref{tri-0}) -\n(\\ref{tri-1}) (see \\cite{A:barahona-mahjoub:cut-polytope}).\n\nA polynomial time separation algorithm for this class of inequalities\nhas been given in \\cite{A:barahona-mahjoub:cut-polytope}. \nHowever we use a faster heuristic as\nfollows. Let $\\bar{x}$ be the fractional solution we want to separate\nand define weights\n\\begin{equation}\nw_e = c_e \\cdot \\max(\\bar{x}_e, 1-\\bar{x}_e).\n\\end{equation}\nThen find a maximum weighted spanning tree $T$ with weights $w$. For\nan edge $e \\in T$, if $\\bar{x}_e \\ge 1-\\bar{x}_e$ then the end-nodes\nof $e$ should be on opposite sides of the cut---we give a label ``A''\nto this edge. Otherwise, if $ \\bar{x}_e < 1-\\bar{x}_e$ then the\nend-nodes should be on the same side of the cut, and we give the label\n``B'' to this edge. Once every edge in $T$ has been labeled we have a\nheuristic cut $K$. For each edge $e \\notin T$, we add it to $T$ and\nlook at the cycle $C$ that is created. If $e \\in K$, we test the\nviolation of an inequality (\\ref{c}), where the set $F$ is given by\nthe A-edges. If $e \\notin K$ the set $F$ is given by the A-edges and\nthe edge $e$. Although, as we noted above, inequalities (\\ref{c}) are\nimplied by (\\ref{tri-0}) - (\\ref{tri-1}), we use (\\ref{c}) because our\nsimple separation heuristic is faster than enumerating triangles.\n\n\\section{Implementation}\n\nBecause the size of the problems we can currently solve is small, we\ncan easily include all the edge variables explicitly. Hence, we do not\nneed to consider dynamiuc column generation. Hence, we do not need to\nconcern ourselves with the {\\tt BCP\\_vg\\_user} class or the {\\tt\nBCP\\_var\\_algo} class. To simplify things further, we decided not to\nuse a separate cut generator either. This is usually a good approach\nwhen cut generation is relatively inexpensive. It is also a good idea\nduring initial development since it makes debugging much easier.\nBecause we are not using a separate cut generator, we do not need to\nconsider the {\\tt BCP\\_cg\\_user} class either.\n\nAs with virtually any BCP implementation, we will need to consider the\n{\\tt BCP\\_tm\\_user} and {\\tt BCP\\_lp\\_user} classes. Also, because we\nwill be dynamically generating algorithmic cuts, we will need to\nderive a new class to represent the cycle cuts (\\ref{c}) from the\nclass {\\tt BCP\\_cut\\_algo}. Finally, we will need to derive a new\nclass for describing the feasible solutions from {\\tt BCP\\_solution}.\nIn the remainder of the section, we provide a high-level description\nof each of these classes. The reader is encouraged to look at the\nsource code and the HTML documentation for more detail. See Chapter\n\\ref{getting-started} for information on getting and examining the\nsource code and documentation.\n\n\\subsection{\\tt MC\\_tm}\n\\label{MC-tm}\n\nThis is the class derived from the {\\tt BCP\\_tm\\_user} class. This\nclass is derived for the purpose of overriding a variety of functions\nthat we need to customize. These consist mainly of routiines that pass\ndata between the processes during parallel execution and the routines\nfor describing the problem core and root node. Below, we list each\nfunction and describe how it was re-implemented.\n\n\\begin{itemize}\n\n        \\item {\\tt unpack\\_feasible\\_solution()}: This subroutine\n        exists to unpack the user-defined solution class described in\n        Section \\ref{MC-solution}. The corresponding {\\tt\n        pack\\_feasible\\_solution()} routine will be described in\n        Section \\ref{MC-lp}. Also, see Section \\ref{MC-solution} for a\n        description of how the feasible solutions are represented.\n        \n        \\item {\\tt pack\\_module\\_data()}: Here, we are packing the\n        data that needs to be sent to the LP process. This consists of\n        the number of nodes and a list of the edges in the graph. The\n        corresponding {\\tt unpack\\_module\\_data()} routines is\n        described in Section \\ref{MC-lp}.\n\n        \\item {\\tt pack\\_cut\\_algo()}: Here, we pack the cycle cuts to\n        be sent to the LP solver. The corresponding {\\tt\n        unpack\\_cut\\_algo()} routines is described in Section\n        \\ref{MC-lp}.\n\n        \\item {\\tt unpack\\_cut\\_algo()}: Here, we unpack the cycle\n        cuts that are received from the LP solver. The corresponding\n        {\\tt pack\\_cut\\_algo()} routines is described in Section\n        \\ref{MC-lp}.\n\n        \\item {\\tt initialize\\_core()}: Essentially for convenience\n        and ease of implementation, we place all the variables in the\n        core. This is possible since we are not using column\n        generation, but may not be the most efficient method. None of\n        the cuts are placed in the core since we don't have an\n        inherently important subset that we know should never be\n        removed from the problem.\n\n        \\item {\\tt create\\_root()}: To initialize the root node, we\n        use some heuristics to generate an initial set of cycle cuts.\n        However, as noted before, these are ``extra'' cuts and do not\n        get put into the core. They may be removed later in the\n        calculation. \n\n        \\item {\\tt display\\_feasible\\_solution()}: This routine is\n        used essentially to display the solutions in a more\n        ``user-friendly'' way, instead of simply as a list of variable\n        indices and values. See Section \\ref{MC-solution} for a\n        description of how the feasible solutions are represented.\n\n\\end{itemize}\n\n\\subsection{\\tt MC\\_lp}\n\\label{MC-lp}\n\nThis is the class derived from the {\\tt BCP\\_lp\\_user} class. Again, this\nclass is derived for the purpose of overriding a variety of functions\nthat we need to customize. These consist not only of routiines that pass\ndata between the processes, as before, but also routines for\ngenerating cuts and performing strong branching. Below, we list each\nfunction and describe how it was re-implemented.\n\n\\begin{itemize}\n\n        \\item {\\tt unpack\\_module\\_data()}: Here, we unpack the data\n        sent from the TM. This data is stored in a user-defined class\n        called {\\tt MC\\_problem}.\n\n        \\item {\\tt pack\\_cut\\_algo()}: Here, we pack the cycle cuts to\n        be sent to the TM. The cuts are represented as a list of\n        edges---first the edges in the set $F$, then the edges not in\n        $F$. To contruct the corresponding valid inequality, we need\n        only determine which edges variables are present in the\n        relaxation. See the description of {\\tt cuts\\_to\\_rows()} below.\n\n        \\item {\\tt unpack\\_cut\\_algo()}: Here, we unpack the cycle\n        cuts that are received from the TM along with the description\n        of a subproblem.\n\n        \\item {\\tt modify\\_lp\\_parameters()}: Here, we modify the LP\n        parameters before solution of the relaxation commences.\n\n        \\item {\\tt test\\_feasibility()}: Because integrality of the\n        solution is not enough to imply feasibility, we needed to\n        override this method. If it is found that the solution is\n        integral but not feasible, then cuts proving the infeasibility\n        are easy to derive and are added to the LP relaxation,\n        allowing the solution process to continue.\n\n        \\item {\\tt pack\\_feasible\\_solution()}: Here, any feasible\n        solutions that are found are packed and sent to the TM for\n        storage. See Section \\ref{MC-solution} for a description of\n        how the feasible solutions are represented.\n\n        \\item {\\tt cuts\\_to\\_rows()}: This subroutine generates the\n        rows of the current LP relaxation corresponding to the cuts to\n        be added. For cycle cuts, this consists simply of determining\n        which of the edge variables that have a positive coefficient in\n        the cycle cut, i.e., the variables corresponding to the edges\n        of the corresponding cycle, are active in the current\n        subproblem. For each variable corresponding to an edge that is\n        in the cycle cut and also active in the subproblem, the\n        corresponding matrix coefficient must be added to the\n        row description.\n\n        \\item {\\tt compare\\_cuts()}: This routine simply compares two\n        cuts and determines if they are the same cut. In the case of\n        cycle cuts, this is straightforward.\n\n        \\item {\\tt generate\\_cut\\_in\\_lp()}: This is the subroutine\n        that generates the cuts to be added to the relaxation. A\n        description of the algorithm for generating the cycle cuts was\n        given in Section \\ref{MCP}.\n\n        \\item {\\tt select\\_branching\\_candidates}: Here, we select the\n        edges to be branched on. We branch basically on edges that are\n        have high cost and are close to value .5.\n\n\\end{itemize}\n\n\\subsection{\\tt MC\\_solution}\n\\label{MC-solution}\n\nAlthough feasible solutions to this problem consist of a set of edges,\nthey can be more compactly represented as simply a list of the nodes\ncontained in either shore of the cut. This user-defined class is used\nfor representing the solutions in this more compact, intuitive\nfashion.\n\n\\subsection{\\tt MC\\_cycle\\_cut}\n\nThis class was derived from {\\tt BCP\\_cut\\_algo} to contain the\nrepresentation of the cycle cuts (\\ref{c}). They are stored simply as\na list of edges in the cycle. The list is in two parts---first, the\nedges in the set $F$ are listed and then those not in the set $F$. Of\ncourse, the cardinality of the set $F$ has to be stored as well.\n\n\\subsection{Other Classes}\n\nThere are a number of other classes that we have defined to hold\ndata used during the solution process. Please see the HTML\ndocumentation and the source code itself for a list of these. \n\n", "meta": {"hexsha": "bf491a0564331698ac8a6ab6bc1097abf62d709b", "size": 11759, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "gsa/wit/COIN/Bcp/Doc/Manual/man-mcp.tex", "max_stars_repo_name": "kant/CMMPPT", "max_stars_repo_head_hexsha": "c64b339712db28a619880c4c04839aef7d3b6e2b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-25T05:25:23.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-25T05:25:23.000Z", "max_issues_repo_path": "gsa/wit/COIN/Bcp/Doc/Manual/man-mcp.tex", "max_issues_repo_name": "kant/CMMPPT", "max_issues_repo_head_hexsha": "c64b339712db28a619880c4c04839aef7d3b6e2b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-09-04T17:34:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-16T08:10:57.000Z", "max_forks_repo_path": "gsa/wit/COIN/Bcp/Doc/Manual/man-mcp.tex", "max_forks_repo_name": "kant/CMMPPT", "max_forks_repo_head_hexsha": "c64b339712db28a619880c4c04839aef7d3b6e2b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-07-22T19:01:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T15:36:11.000Z", "avg_line_length": 48.1926229508, "max_line_length": 79, "alphanum_fraction": 0.7082234884, "num_tokens": 2984, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82446190912407, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.7118334907336122}}
{"text": "\\subsection{Graph}\n\\begin{center}\n\\begin{longtable}{|p{4cm}|p{4cm}|p{7cm}|}\n\\hline\n\\textbf{Name} & \\textbf{Worst Complexity} & \\textbf{Description} \\\\\n\\hline\nDepth First Search & O(\\textbar E\\textbar + \\textbar V\\textbar )\n           & \\begin{enumerate}\n                \\item Push first vertex onto a stack\n                \\item Pop vertex off the stack \\& process\n                \\item Loop through vertex successors, if not already seen\n                      add it to the stack\n                \\item Repeat until stack is empty\n              \\end{enumerate}\\\\\n\\hline\n\nBreadth First Search & O(\\textbar E\\textbar + \\textbar V\\textbar )\n           & \\begin{enumerate}\n                \\item Push first vertex onto a queue\n                \\item Pop vertex off the queue \\& process\n                \\item Loop through vertex successors, if not already seen\n                      add it to the stack\n                \\item Repeat until stack is empty\n              \\end{enumerate}\\\\\n\\hline\n\nBST pre-order & O(n) \n              & {\\begin{lstlisting}[language=Java]\nDeque<TreeNode> stack = new ArrayDeque<>();\nstack.push(root);\nwhile(!stack.isEmpty()) {\n  TreeNode node = stack.pop();\n  // Process node here\n  if (node.right != null) {\n    stack.push(node.right);\n  }\n  if (node.left != null) {\n    stack.push(node.left);\n  }\n}\n                  \\end{lstlisting}\n\n                } \\\\\n\\hline\n\n\nBST in-order & O(n) \n              & {\\begin{lstlisting}[language=Java]\nDeque<TreeNode> stack = new ArrayDeque<>();\nTreeNode node = root;\nwhile (!stack.isEmpty() || node != null) {\n  if (node != null) {\n    stack.push(node);\n    node = node.left;\n  } else {\n    node = stack.pop();\n    // Process node here\n    node = node.right;\n  }\n}\n                  \\end{lstlisting}\n\n                } \\\\\n\\hline\n\nBST post-order & O(n) \n              & {\\begin{lstlisting}[language=Java]\nDeque<TreeNode> stack = new ArrayDeque<>();\nstack.push(root);\nTreeNode prev = null;\nwhile(!stack.isEmpty()) {\n  TreeNode current = stack.peek();\n  if (prev == null || prev.left.equals(current) || prev.right.equals(current)) {\n    if (current.left != null) {\n      stack.push(current.left);\n    }\n    else if (current.right != null) {\n      stack.push(current.right);\n    }\n  } else if (current.left.equals(prev)) {\n    if (current.right != null) {\n      stack.push(current.right);\n    }\n  } else {\n    //Process current here\n    stack.pop();\n  }\n  prev = current;    \n}\n                  \\end{lstlisting}\n\n                } \\\\\n\\hline\n\n \nPrims MST priority queue/min heap & O(\\textbar V\\textbar log\\textbar V\\textbar + \\textbar E\\textbar log\\textbar V\\textbar ) $\\implies$ O(\\textbar E\\textbar log\\textbar V\\textbar) \n            & \\begin{enumerate}\n                \\item Push first vertex's edges onto a priority queue\n                \\item While the priority queue is not empty do:\n                \\item Poll the smallest edge and add it to the mst, if its\n                      connecting vertex has other edges to it in the \n                      priority queue, remove these because this edge was smaller\n                      and they don't need looking at.\n              \\end{enumerate}\\\\\n\n\\hline\n\nKruskals MST & O(\\textbar E\\textbar log\\textbar V\\textbar) \n         & \\begin{enumerate}\n                \\item Push all edges onto a priority queue\n                \\item Pop first V edges off the queue, for each edge:\n                \\item if egde is not already in a connected tree of the answer \n                      add it to the mst. This is tested via a union find data\n                      structure\n\n              \\end{enumerate}\\\\\n\n\\hline\n\nDijkstra & O((\\textbar V \\textbar + \\textbar E \\textbar) log \\textbar V \\textbar\n         & \\begin{enumerate}\n                \\item Assign distance to the initial node 0 and the others \n                      $\\infty$\n                 \\item Add initial node to a priority queue and then whilst the\n                       queue is not empty do:\n                 \\item Pop closest vertex off queue, for all its edges if any\n                       edges make the distance closer than the current recorded distance update\n                       the vertex in the priority queue\n                 \\item Final path can be used via back tracking\n              \\end{enumerate}\\\\\n\n\\hline\n\nA* & \n   & \\begin{enumerate}\n        \\item A* uses a best first search, keeping a sorted priority queue\n              of alternative path segments along the way\n        \\item It uses a heuristic $f(x)$ made up of $g(x)$ which is the \n              past path cost, and $h(x)$ which is the future path cost estimation\n        \\item Starting with the initial node it maintains a priority queue of nodes\n              (known as the fringe). The lower $f(x)$ the higher the priority\n      \\end{enumerate}\\\\ \n\\hline\n\n\n\\end{longtable}\n\\end{center}\n", "meta": {"hexsha": "cd074f1ba63c359a7ded590264632ce49f21d739", "size": 4835, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "algos/graph.tex", "max_stars_repo_name": "sarahtattersall/InterviewCheatSheet", "max_stars_repo_head_hexsha": "c5d1a4ba2e8713bd95913eb91aa1432bdc743fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2015-01-14T22:59:50.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-02T15:46:41.000Z", "max_issues_repo_path": "algos/graph.tex", "max_issues_repo_name": "sarahtattersall/InterviewCheatSheet", "max_issues_repo_head_hexsha": "c5d1a4ba2e8713bd95913eb91aa1432bdc743fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "algos/graph.tex", "max_forks_repo_name": "sarahtattersall/InterviewCheatSheet", "max_forks_repo_head_hexsha": "c5d1a4ba2e8713bd95913eb91aa1432bdc743fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6689189189, "max_line_length": 179, "alphanum_fraction": 0.5720785936, "num_tokens": 1153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.7981867777396211, "lm_q1q2_score": 0.7118317915961431}}
{"text": "%% LyX 2.3.3 created this file.  For more info, see http://www.lyx.org/.\n%% Do not edit unless you really know what you are doing.\n\\documentclass[english]{article}\n\\renewcommand{\\sfdefault}{cmss}\n\\usepackage[T1]{fontenc}\n\\usepackage[latin9]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{babel}\n\\begin{document}\n\n\\section*{Transport equation}\n\nThe convection-diffusion equation for the transport of temperature\n\\textit{T} is\n\n\\begin{equation}\n\\frac{\\partial T}{\\partial t}=-U\\frac{\\partial T}{\\partial x}+k\\frac{\\partial}{\\partial x}(\\frac{\\partial T}{\\partial x})+S\n\\end{equation}\nwhere \\textit{U} is velocity and \\textit{S} a source term. For a non\nexisting convection case, Equation (1) becomes the diffusion Equation\n\n\\begin{equation}\n\\frac{\\partial T}{\\partial t}=k\\frac{\\partial}{\\partial x}(\\frac{\\partial T}{\\partial x})+S\n\\end{equation}\nthat, for a steady-state, is \n\n\\begin{equation}\n0=k\\frac{\\partial}{\\partial x}(\\frac{\\partial T}{\\partial x})+S\n\\end{equation}\nThese equations are solved by a Finite Volume Method (FVM) and by\na Finite Difference Method (FDM). \n\n\\section*{Finite Volume Method }\n\nIn the Finite Volume Method, values for the above diferential equations\nare calculated at discrete places on a grid of volumes, shown in Figure\n1,\n\\begin{center}\n\\includegraphics{figure_1}\n\\par\\end{center}\n\n\\begin{center}\n\\textbf{Figure 1}: Temperature at center of cell, and on left and\nright cell borders.\n\\par\\end{center}\n\n\\noindent where temperature at the center of a cell is \\textit{T}\\textit{\\scriptsize{}P},\n\\textit{T}\\textit{\\scriptsize{}r} e \\textit{T}\\textit{\\scriptsize{}l}\nis temperature at the border between cells, right and left, \\textit{T}\\textit{\\scriptsize{}R}\ne \\textit{T}\\textit{\\scriptsize{}L} is temperature at the right and\nleft cell centers. Integrating Equation 3 over a cell volume, and\nconsidering the rate of accumulation over the volume \\textit{V} equal\nto the flow across the surfaces of the control volume, Equation (6),\nwhere \\textit{n} is the unit normal vector pointing out of the control\nvolume and \\textit{A} is the cross sectional area of the volume.\n\n\\begin{equation}\n\\int\\left[k\\frac{\\partial}{\\partial x}(\\frac{\\partial T}{\\partial x})+S\\right]dV=0\n\\end{equation}\n\n\\begin{equation}\n\\int\\left[\\frac{\\partial}{\\partial x}(k\\frac{\\partial T}{\\partial x})dV\\right]+SV=0\n\\end{equation}\n\n\\begin{equation}\n\\int(k\\frac{\\partial T}{\\partial x}n)dA+SV=0\n\\end{equation}\n\n\\noindent Equation (6) is written in terms of the flux leaving the\nright face \\textit{r} minus the flux entering the left face \\textit{l}\nin Figure (1)\n\n\\begin{equation}\n(kA\\frac{\\partial T}{\\partial x})_{r}-(kA\\frac{\\partial T}{\\partial x})_{l}+SV=0\n\\end{equation}\n\n\\noindent Equation (7) for the temperature gradient at the boundaries\nis discretized in terms of the temperature at the cell centers, where\n$\\Delta x$ is the distance between cell centers\n\n\\begin{equation}\nkA\\frac{T_{R}-T_{P}}{\\Delta x}-kA\\frac{T_{P}-T_{L}}{\\Delta x}+SV=0\n\\end{equation}\n\n\\noindent Solving Equation (8) for \\textit{T}$_{P}$ and making an\nindividual set of equations for each cell results in a system of equations\nof the form\n\n\\begin{equation}\n-\\frac{kA}{\\Delta x}T_{P-1}+2\\frac{kA}{\\Delta x}T_{P}-\\frac{kA}{\\Delta x}T_{P+1}=SV\n\\end{equation}\n\n\\noindent for each grid position except the first and last volumes\nin the grid. For the first and last volumes in the grid, the temperature\nT$_{A}$ and T$_{B}$ at the borders is also considered, as well as\na half distance to the border. In matrix form, where the first and\nlast row are the two special border cases:\n\n\\begin{equation}\n\\left[\\begin{array}{ccccc}\n\\frac{kA}{\\Delta x}+\\frac{kA}{0.5\\Delta x} & -\\frac{kA}{\\Delta x} & 0 & 0 & 0\\\\\n-\\frac{kA}{\\Delta x} & 2\\frac{kA}{\\Delta x} & -\\frac{kA}{\\Delta x} & 0 & 0\\\\\n0 & -\\frac{kA}{\\Delta x} & 2\\frac{kA}{\\Delta x} & -\\frac{kA}{\\Delta x} & 0\\\\\n0 & 0 & -\\frac{kA}{\\Delta x} & 2\\frac{kA}{\\Delta x} & -\\frac{kA}{\\Delta x}\\\\\n0 & 0 & 0 & -\\frac{kA}{\\Delta x} & \\frac{kA}{\\Delta x}+\\frac{kA}{0.5\\Delta x}\n\\end{array}\\right]\\left[\\begin{array}{c}\nT_{1}\\\\\nT_{P-1}\\\\\nT_{P}\\\\\nT_{P+1}\\\\\nT_{N}\n\\end{array}\\right]=\\left[\\begin{array}{c}\nSV+T_{A}\\frac{kA}{0.5\\Delta x}\\\\\nSV\\\\\nSV\\\\\nSV\\\\\nSV+T_{B}\\frac{kA}{0.5\\Delta x}\n\\end{array}\\right]\n\\end{equation}\n\n\\noindent This matrix is solved for the vector of temperatures \\textit{T}.\n\n\\section*{Finite Difference Method}\n\nThe diffusion equation (2) \n\n\\begin{equation}\n\\frac{\\partial T}{\\partial t}=k\\frac{\\partial^{2}T}{\\partial x^{2}}+S\n\\end{equation}\ncan be approximated by finite differences with a forward difference\nin time and a central difference in space scheme.\n\n\\begin{equation}\n\\frac{T_{i}^{n+1}-T_{i}^{n}}{\\varDelta t}=k\\frac{T_{i-1}^{n}-2T_{i}^{n}+T_{i+1}^{n}}{\\varDelta x^{2}}+S_{i}^{n}\n\\end{equation}\n\n\\noindent that can be solved for the temperature at the next time\nstep \\textit{T}$^{n+1}$\n\n\\begin{equation}\nT_{i}^{n+1}=T_{i}^{n}+k\\frac{\\varDelta t}{\\varDelta x^{2}}(T_{i-1}^{n}-2T_{i}^{n}+T_{i+1}^{n})+S_{i}^{n}\n\\end{equation}\n\n\n\\section*{References}\n\\begin{enumerate}\n\\item Computational Fluid Dynamics Fundamentals Course. A. Wimshurst. 2019. \n\\item An Introduction to Computational Fluid Dynamics: The Finite Volume\nMethod. H. Versteeg, W. Malalasekera. 2007.\n\\item Finite Difference Computing with PDEs. A Modern Software Approach.\nH. Langtangen, S. Linge. 2016.\n\\end{enumerate}\n\n\\end{document}\n", "meta": {"hexsha": "f42e961f03e178ceae1a6b0c382508fb44e9720e", "size": 5352, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "transport.tex", "max_stars_repo_name": "pedro-vicente/transport", "max_stars_repo_head_hexsha": "a12a7aa9085ba2cfc0b835473c0e45518c887cab", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "transport.tex", "max_issues_repo_name": "pedro-vicente/transport", "max_issues_repo_head_hexsha": "a12a7aa9085ba2cfc0b835473c0e45518c887cab", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "transport.tex", "max_forks_repo_name": "pedro-vicente/transport", "max_forks_repo_head_hexsha": "a12a7aa9085ba2cfc0b835473c0e45518c887cab", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.3076923077, "max_line_length": 123, "alphanum_fraction": 0.7109491779, "num_tokens": 1819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835248143776, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.711792523682898}}
{"text": "\\subsection{Interpretations}\n\nAn interpretation assigns meaning to propositional variables in a formula.\n\nFor example an interpretation of the formula \\(\\theta \\lor \\gamma \\) assigns values to each of \\(\\theta \\) and \\(\\gamma \\).\n\n\\subsection{Satifisable}\n\nA formula is satisfisable if there is some interpretation where it is true.\n\nFor example \\(\\theta \\) is satisfisable but \\(\\theta \\land \\neg \\theta \\) is not.\n\n\\subsection{Tautology}\n\nA formula is a tautology if it is true in all interpretations.\n\nExamples of tautologies include:\n\\begin{itemize}\n\\item \\(\\theta \\lor \\neg \\theta \\)\n\\end{itemize}\n\n", "meta": {"hexsha": "4d430c8067644c289080aabf58304a97e91a7834", "size": 604, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogic/02-06-interpretation.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/propositionalLogic/02-06-interpretation.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/propositionalLogic/02-06-interpretation.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.4545454545, "max_line_length": 123, "alphanum_fraction": 0.7450331126, "num_tokens": 151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7117432475995739}}
{"text": "\\section{Marciani Normal Form}\n\\label{sec:marciani-normal-form}\n\nWe introduce the notion of context-free grammars in Marciani Normal Form (MNF).\nWe prove that every MNF grammar generates a regular language.\n\n\\begin{definition}\n\t\\label{dfn:mnf}\n\tA context-free grammar $G=(V,V_{N},S,P)$ is said to be in Marciani Normal\n\tForm (MNF) iff $G$ enjoys the looking forward property and there exists a\n\tpseudo-regular partition $\\Upsilon_{A}$ for all symbol $A\\in V_{T}$.\n\\end{definition}\n\n\\begin{theorem}\n\t\\label{thm:mnf}\n\tA context-free grammar $G=(V_{T},V_{N},S,P)$ in Marciani Normal Form always\n\tgenerates a regular language.\n\n\t\\begin{proof}\n\t\tIf $G$ is in Marciani Normal Form, then for each non-terminal $A$ there\n\t\texists a pseudo-regular partition $\\Upsilon_{A}$.\n\t\tNotice that to every pseudo-regular partition\n\t\t$\\Upsilon_{A}=\\{\\{p|p\\in P_{A},A\\rightarrow\\alpha A\\},\n\t\t\\{p|p\\in P_{A},A\\rightarrow A\\beta\\},\\{p|p\\in P_{A},A\\rightarrow\\gamma\\}\\}$\n\t\tcan be associated a both-linear language equation $A=\\alpha A+A\\beta+\\gamma$.\n\t\tBy the application of the Marciani's Rule, we know that the least\n\t\tsolution of the previous equation is $\\alpha^{*}\\gamma\\beta^{*}$,\n\t\tso $L(A)=L(\\alpha^{*}\\gamma\\beta^{*})$.\n\n\t\tAs a consequence of the previous results and the looking forward property,\n\t\tthere exists a regular expression $e$ such that $L(S)=L(e)$, then $L(S)$ \n\t\tis a regular language, that is $G$ is regular.\n\t\\end{proof}\n\\end{theorem}\n", "meta": {"hexsha": "7fec7090647327f20cf9edb5359f7182f8379fce", "size": 1436, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "marciani-normal-form/sec/marciani-normal-form.tex", "max_stars_repo_name": "gmarciani/research", "max_stars_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-07-27T13:31:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-20T12:54:12.000Z", "max_issues_repo_path": "marciani-normal-form/sec/marciani-normal-form.tex", "max_issues_repo_name": "gmarciani/research", "max_issues_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "marciani-normal-form/sec/marciani-normal-form.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 41.0285714286, "max_line_length": 79, "alphanum_fraction": 0.7110027855, "num_tokens": 452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7117432359429176}}
{"text": "\\section*{Common angles}\n\n\n\\begin{table}[!ht]\n\\setlength{\\tabcolsep}{1em} % Increase the horizontal table cell margin\n\\centering\n  \\tabulinesep=1.5mm\n  \\begin{tabu}{|c|c|c|c|c|c|c|c|}\n    \\hline\n    \\textbf{Degrees}\n      & $\\SI{0}{\\degree}$\n      & $\\SI{30}{\\degree}$\n      & $\\SI{45}{\\degree}$\n      & $\\SI{60}{\\degree}$\n      & $\\SI{90}{\\degree}$\\\\\n    \\hline\n    \\textbf{Radians}\n      & $\\displaystyle 0$\n      & $\\displaystyle \\frac{\\pi}{6}$\n      & $\\displaystyle \\frac{\\pi}{4}$\n      & $\\displaystyle \\frac{\\pi}{3}$\n      & $\\displaystyle \\frac{\\pi}{2}$\\\\\n    \\hline\n    \\textbf{\\bm{$\\sin \\theta$}}\n      & $\\displaystyle 0$\n      & $\\displaystyle \\frac{1}{2}$\n      & $\\displaystyle \\frac{\\sqrt 2}{2}$\n      & $\\displaystyle \\frac{\\sqrt 3}{2}$\n      & $\\displaystyle 1$\\\\\n    \\hline\n    \\textbf{\\bm{$\\cos \\theta$}}\n      & $\\displaystyle 1$\n      & $\\displaystyle \\frac{\\sqrt 3}{2}$\n      & $\\displaystyle \\frac{\\sqrt 2}{2}$\n      & $\\displaystyle \\frac{1}{2}$\n      & $\\displaystyle 0$\\\\\n    \\hline\n    \\textbf{\\bm{$\\tan \\theta$}}\n      & $\\displaystyle 0$\n      & $\\displaystyle \\frac{\\sqrt 3}{3}$\n      & $\\displaystyle 1$\n      & $\\displaystyle \\sqrt 3$\n      &\\\\\n    \\hline\n  \\end{tabu}\n\\end{table}", "meta": {"hexsha": "a1bf7c7e25d2cf1c652212dac617af645e47709b", "size": 1212, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/angles.tex", "max_stars_repo_name": "cbarina/trigonometric_identities_latex", "max_stars_repo_head_hexsha": "8d9e491c6d7bf1829686cf8bafdaa2b8d66f35d4", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-03-09T02:44:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T06:14:23.000Z", "max_issues_repo_path": "parts/angles.tex", "max_issues_repo_name": "cbarina/trigonometric_identities_latex", "max_issues_repo_head_hexsha": "8d9e491c6d7bf1829686cf8bafdaa2b8d66f35d4", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-09-26T01:58:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-16T15:31:38.000Z", "max_forks_repo_path": "parts/angles.tex", "max_forks_repo_name": "cbarina/trigonometric_identities_latex", "max_forks_repo_head_hexsha": "8d9e491c6d7bf1829686cf8bafdaa2b8d66f35d4", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-01-06T23:03:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T06:26:11.000Z", "avg_line_length": 26.347826087, "max_line_length": 71, "alphanum_fraction": 0.5173267327, "num_tokens": 453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7116937308216111}}
{"text": "\\chapter{Error analysis}\n\n\\section{Introduction}\n\nNumerical analysis is mathematics brought down to earth.  In the world\nof mathematics   numbers   are exact:   $\\pi$ is  the   ratio  of  the\ncircumference to its radius and it is known exactly, each single digit\nafter  the other.  Numerical analysis teaches  humbleness: it tells us\nthat in  the real world  we cannot know numbers  exactly, we  can only\nknow 2, 20, a million of the digits that form the number $\\pi$, but in\nno way we can know any non-rational number exactly.  This may not seem\na serious problem: does it really matter that we cannot represent more\nthan 10 of the  first digits of  $\\pi$?   The answer to  this specific\nquestion is that generally it does not matter.  However, if we were to\nrephrase the question as: ``Does it  matter that we cannot represent a\nnumber with infinite  precision?'' then the answer  would have to  be:\n``Yes, it does matter''.  Small approximations caused  by the fact the\nwe  represent numbers  using  ``only'' a finite set  of  digits can be\namplified in the process of solving a given mathematical problem up to\na point where they make the entire result meaningless.\n\nIt is in this sense that numerical analysis  teaches us humbleness: it\nforces us to  realise our limitations  in representing  numbers and to\nask ourselves the question of whether the results obtained by applying\nexact mathematical procedures to  these inexact representations can be\nconsidered accurate.\n\nThis chapter is an introduction to numerical methods.   Its aims are\nto highlight the consequences of finite precision representation of\nnumbers on numerical calculations.\n\n\\section{Floating point representation}\n\nReal    numbers are represented     in   digital  computers   using  a\n\\textit{normalised scientific   notation} or   \\textit{floating  point\nnotation}: the  decimal point is shifted  and appropriate powers of 10\nare  supplied so that  all the digits are to  the right of the decimal\npoint and the first digit displayed is not zero.  For example,\n%\n\\begin{align*}\n  8491.2913 & = 0.84912913 \\times 10^4 , \\\\\n  -12.32 & = -0.1232 \\times 10^2 , \\\\\n  0.00321 & = 0.321 \\times 10^{-2} .\n\\end{align*}\n%\nThe general notation for a floating point number (in base $10$) is \n%\n\\begin{equation*}\n \\pm \\, 0.a_1 a_2 a_3 a_4 \\ldots a_m \\times 10^c ,\n\\end{equation*}\n\n%\nwhere $0.a_1 a_2 a_3 a_4 \\ldots a_m$ is the \\textit{mantissa}, the\ninteger $c$ is the \\textit{exponent} and the integer $10$ is\ncalled the \\textit{base} of this representation.  The number $m$ of\ndigits in the mantissa is a measure of the precision of the\nrepresentation: the bigger $m$ the more digits are stored in the\ncomputer and the more accurately the real number is approximated.  The\ndigits $a_i$ are called ``significant digits'': $a_1$ is the most\nsignificant digit and $a_m$ is the least significant digit.  The size\nof the mantissa is also referred to as ``the number of significant\ndigits''.\n\n\\section{Absolute and relative errors}\n\nBefore discussing how the errors introduced in the representations of\nnumbers affect numerical calculations we must define ways of measuring\nthe size of the error.  There are two standard definitions.    We define\nthe \\textit{absolute error} in representing the number $x$ with a\nfinite precision representation $\\bar{x}$ as the quantity\n%\n\\begin{equation*}\n  E_a = x - \\bar x.\n\\end{equation*}\n\n%\nWe define the \\textit{relative error} as the quantity\n%\n\\begin{equation*}\n  E_r = \\frac{x - \\bar x}{x} .\n\\end{equation*}\n%\nThe absolute error is independent of the size of the number $x$, while\nthe relative error is essentially a measure of the size of the error\nin comparison with the quantity measured.\n\n\\medskip\n\n\\noindent {\\bf Example} \n\n\\smallskip\n\nSuppose that $x=1322$ and $\\bar x = 1000$.  The absolute and relative\nerrors are respectively:\n%\n\\begin{align*}\n  E_a &= 1322 - 1000 = 322, \\\\\n  E_r &= \\dfrac{1322 - 1000}{1322} = 0.24 .\n\\end{align*}\n%\nNow suppose that $x=1000322$ and $\\bar x = 1000000$.   The two errors\nare:\n%\n\\begin{align*}\n  E_a &= 1000322 - 1000000 = 322, \\\\\n  E_r &= \\dfrac{1000322 - 1000000}{1000322} = 0.0032 = 0.32\n  \\times 10^{-2} .\n\\end{align*}\n%\nThe absolute error is the same in both cases, but the relative errors\nare completely different.    The choice between the two errors is\nproblem dependent.\n\n\\medskip\n\nOne of the aims of numerical analysis is to control the growth of the\nerrors that occur naturally while solving a given mathematical\nproblem.     In other words, it is the \\textit{total error from all\nsources} which is of most interest.   Normally, we try, when examining\na method, to prove a theorem of the form\n\n\\begin{quotation}\n  \\textit{If we apply method X to solve problem Y then $ | x - \\bar x | \\le \\varepsilon \\quad \\forall x$.}\n\\end{quotation}\n\nThe crux of numerical analysis is that some problems are such that\neven a small amount of rounding or initial error causes a large\ninaccuracy in the answer: these are known as \\textit{ill-conditioned\nproblems}. \n\n\\section{Errors and simple mathematical operations}\n\nBefore studying algorithms to solve typical numerical problems, like\nfinding the roots of a nonlinear equation, we must understand how\nnumerical errors affect and are affected by simple operations.\n\n\\subsection{Addition}\n\nThe error in computing the addition of two real numbers by adding up\ntwo floating point numbers is given by\n%\n\\begin{equation*}\n  x + y = \\overline{x} + \\overline{y} + e(x) + e(y),\n\\end{equation*}\n%\nwhere $e(x)$ and $e(y)$ are respectively the errors in the floating\npoint representation of $x$ and $y$.\n\nThe addition of two floating point numbers loses most of the\nproperties of the standard addition.   In the examples that follow\nassume that the size of the mantissa is $m=3$:\n\n\\begin{enumerate}\n  % \n\\item In general, the sum of two floating point numbers is not the\n  floating point representation of the sum:\n  % \n  \\begin{equation*}\n    \\overline{x+y} \\ne \\bar x + \\bar y. \n  \\end{equation*}\n  \n  % \n  For example,\n  % \n  \\begin{align*}\n    x = 1.007, \\, y = 2.005 &\\implies \\bar x = 1.00, \\,\n    \\bar y = 2.00, \\\\\n    \\intertext{whilst}\n    \\overline{x+y} = \\overline{3.012} = 3.01 & \\ne \\bar x\n    + \\bar y = 3.00\n  \\end{align*} \n  % \n\\item The sum of two numbers may be too big to be represented in the\n  computer, i.e.\\ the result of the addition is a numerical overflow.\n\n\\item Order matters, i.e.\\ the addition of floating point numbers is\n  not associative:\n  % \n  \\begin{equation*}\n    \\overline{\\overline{(\\overline{x} + \\overline{y})} + \\overline{z}} \\ne\n    \\overline{\\overline{x} + \\overline{(\\overline{y} + \\overline{z})}}.\n  \\end{equation*}\n  % \n  As a matter of fact, it is always better to add in ascending order\n  of magnitude.\n  % \n  \\begin{equation*}\n    \\left\\{ \n      \\begin{aligned}\n        \\overline{x} &= 1.00, \\\\\n        \\overline{y} &= 0.007, \\\\\n        \\overline{z} &= 0.006, \\\\\n      \\end{aligned}\n    \\right. \\implies \n    \\left\\{\n      \\begin{aligned}\n        \\overline{\\overline{(\\overline{x} + \\overline{y})} +\n          \\overline{z}} = \\overline{\\overline{(1.00+0.007)} +\n          0.006} =\n        \\overline{1.00 + 0.006} = 1.00, \\\\\n        \\overline{\\overline{x} + \\overline{( \\overline{y} +\n            \\overline{z} )}} = \\overline{ 1.00 +\n          \\overline{(0.007+0.006)}} = \\overline{1.00 + 0.013} =\n        1.01\n      \\end{aligned}\n    \\right.\n  \\end{equation*}\n  % \n  The second result is more accurate than the first.  If each small\n  number is added separately to a big number then they may be all\n  ``chopped off''.  However, if all the small numbers are added\n  together their sum may be sufficiently big not to suffer such fate.\n\n\\end{enumerate}\n\n\\subsection{Subtraction}\n\nThe error in computing the difference of two real numbers by subtracting\ntwo floating point numbers is given by\n%\n\\begin{equation*}\n  x - y = \\overline{x} - \\overline{y} + e(x) - e(y),\n\\end{equation*}\n\n%\nwhere $e(x)$ and $e(y)$ are respectively the errors in the floating\npoint representation of $x$ and $y$.\n\nThe subtraction of two floating point numbers is a very delicate\noperation that can lead to an outstanding loss of significant digits\nespecially when the numbers to be subtracted are nearly equal.\nIf, for example, $x = 42.345$ and $y = 42.287$ then we have:\n%\n\\begin{align*}\n  x - y &= 0.058 , \\\\\n  \\overline{x} - \\overline{y} &= 42.3 - 42.2 = 0.100\n\\end{align*}\n\n\\subsection{Multiplication}\n\nThe error in computing the product of two real numbers by multiplying\ntwo floating point numbers is given by\n%\n\\begin{equation*}\n  x \\, y = \\overline{x} \\, \\overline{y} + \\overline{y} e(x) + \n  \\overline{x} e(y) + e(x) e(y), \n\\end{equation*}\n%\nwhere $e(x)$ and $e(y)$ are respectively the errors in the floating\npoint representation of $x$ and $y$.   The last term in this\nexpression is usually negligible.\n\nNote that on an $m$ digit computer,  $\\overline{x} \\, \\overline{y}$ is at\nmost $2 m$ digit long.  This is the main reason why most computers use\n$2 m$ digits for calculations on $m$-digit numbers.  The result is cut\nback to $m$ digits once the calculation is completed.\n\n\\subsection{Division}\n\nThe error in computing the ratio of two real numbers by dividing\ntwo floating point numbers is given by\n%\n\\begin{equation*}\n  \\frac{x}{y} = \n  \\frac{\\overline{x} + e(x)}{\\overline{y} + e(y)} =\n  \\frac{\\overline{x}}{\\overline{y}} + \\frac{e(x)}{\\overline{y}} -\n  \\frac{\\overline{x} e(y)}{\\overline{y}^2} + O [e(x) e(y)],\n\\end{equation*}\n%\nwhere $e(x)$ and $e(y)$ are respectively the errors in the floating\npoint representation of $x$ and $y$.   The last term in this\nexpression is usually negligible.   Clearly the error increases\ndramatically if $y \\simeq 0$.\n\n% The symbol $O(\\varepsilon)$ [big oh of  $\\varepsilon$] is a short hand\n% notation for ``terms that decrease to zero as fast as $\\varepsilon$''.\n% More formally, a function  $f(\\varepsilon)$ is $O(\\varepsilon)$ if the\n% ratio  $f(\\varepsilon)/\\varepsilon$ is  finite  and bounded  away from\n% zero as $\\varepsilon$ tends to zero:\n% %\n% \\Be \n%   0 < \\left | \\frac{f(\\varepsilon)}{\\varepsilon} \\right | < \\infty ,\n%   \\qquad \\varepsilon \\to 0 .\n% \\Ee\n% %\n% For example, $\\sin(x) = O(x)$ because\n% %\n% \\Be \\lim_{x \\to 0} \\frac{\\sin(x)}{x} = 1 . \\Ee\n% \n% There is a similar symbol, $o(\\varepsilon)$ [little oh of\n% $\\varepsilon$]: it is a short hand notation for ``terms that decrease\n% to zero faster than $\\varepsilon$''.  More formally a function\n% $f(\\varepsilon)$ is $o(\\varepsilon)$ if\n% %\n% \\Be\n%    \\lim_{\\varepsilon \\to 0} \\frac{f(\\varepsilon)}{\\varepsilon} = 0.\n% \\Ee\n% %\n% For example, $\\sinh^2(x) = o(x)$ because\n% %\n% \\Be \\lim_{x \\to 0} \\frac{\\sinh^2(x)}{x} = 0 . \\Ee\n\n\\noindent \n\\textbf{Remark} - The errors introduced by the basic arithmetical\noperations can be combined when studying more complicated operations.\nFor example, one can show that in the dot product of two vectors the\nerror is roughly $n \\varepsilon$, where $n$ is the size of the two vectors and\n$\\varepsilon$ is an upper bound on the error of the representation of each\ncomponent of the vectors.\n\n\\section{Stable and unstable computations}\n\nThe procedure to solve numerically a mathematical problem involves a\nseries of operations that, quite often, must be repeated over and over\nagain.    It may happen that a small error gets amplified in the\ncourse of the iteration procedure until it dominates the numerical\nsolution and makes it totally unreliable.    \n\nA numerical process is \\textit{unstable} if small errors made at one\nstage of the process are magnified in subsequent stages and seriously\ndegrade the accuracy of the overall solution.\n\nConsider for example the sequence of real numbers defined by\n%\n\\begin{equation}\n  \\label{unstable}\n  \\left\\{\n    \\begin{aligned}\n      x_0 & = 1, \\\\\n      x_1 & = \\dfrac{1}{3}, \\\\\n      x_{n+1} & = \\dfrac{13}{3} x_n - \\dfrac{4}{3} x_{n-1}, \\quad n \\ge 1 .\n    \\end{aligned}\n  \\right.\n\\end{equation}\n%\nOne can show by induction that this recurrence relation generates the\nsequence\n%\n\\begin{equation*}\n  x_n = \\left ( \\frac{1}{3} \\right )^n . \n\\end{equation*}\n%\nHowever, if we compute~(\\ref{unstable}) numerically using 8\nsignificant digits we obtain the results shown in Table~\\ref{unst1}.\nThe absolute and relative error increase with the iterations until\nafter the seventh iteration the result is completely unreliable.\nThe algorithm is therefore \\textit{unstable}.    \n\n\\begin{table}\n \\begin{center}\n  \\begin{tabular}{|c|c|c|c|} \\hline\n   $n$ & $x_n$ & Abs. err. & Rel. err. \\\\ \\hline \\hline\n    0 & +1.0000000e+00 & +0.0000000e-01 & +0.0000000e-01 \\\\ \\hline \n    1 & +3.3333333e-01 & +0.0000000e-01 & +0.0000000e-01 \\\\ \\hline \n    2 & +1.1111110e-01 & +1.0000000e-08 & +9.0000000e-08 \\\\ \\hline \n    3 & +3.7036990e-02 & +4.7000000e-08 & +1.2690000e-06 \\\\ \\hline \n    4 & +1.2345490e-02 & +1.8900000e-07 & +1.5309000e-05 \\\\ \\hline \n    5 & +4.1144710e-03 & +7.5530000e-07 & +1.8353790e-04 \\\\ \\hline \n    6 & +1.3687210e-03 & +3.0211000e-06 & +2.2023819e-03 \\\\ \\hline \n    7 & +4.4516310e-04 & +1.2084270e-05 & +2.6428298e-02 \\\\ \\hline \n    8 & +1.0407880e-04 & +4.8336990e-05 & +3.1713899e-01 \\\\ \\hline \n    9 & -1.4254266e-04 & +1.9334792e-04 & +3.8056671e+00 \\\\ \\hline \n   10 & -7.5645659e-04 & +7.7339168e-04 & +4.5668005e+01 \\\\ \\hline \n   11 & -3.0879216e-03 & +3.0935666e-03 & +5.4801604e+02 \\\\ \\hline \n   12 & -1.2372384e-02 & +1.2374266e-02 & +6.5761923e+03 \\\\ \\hline \n   13 & -4.9496435e-02 & +4.9497062e-02 & +7.8914304e+04 \\\\ \\hline \n   14 & -1.9798804e-01 & +1.9798825e-01 & +9.4697166e+05 \\\\ \\hline \n   15 & -7.9195293e-01 & +7.9195300e-01 & +1.1363660e+07 \\\\ \\hline \n  \\end{tabular}\n \\end{center}\n \\caption{\\label{unst1} \\it Iterations of the unstable\n   map~(\\ref{unstable}) with initial conditions $x_0=1$ and\n   $x_1=1/3$.   The correct value of the $n$-th iterate is $x_n=(1/3)^n$.}\n\\end{table}\n\nThe instability of this algorithm is caused by the fact that an error\npresent in $x_n$ is multiplied by 13/3 in computing $x_{n+1}$ (the\nproof of instability is more complicated than this, but this statement\nis essentially correct).  Hence there is a possibility that the error\nin $x_1$ will be propagated into $x_{15}$, for example, with a factor\n$(13/3)^{14}$.    Since the absolute error in $x_1$ is approximately\n$10^{-8}$ and since $(13/4)^{14}$ is roughly $10^9$, the error in\n$x_{15}$ due solely to the error in $x_1$ could be as much as 10.   \n\nWhether a process is numerically stable or unstable should be decided\non the basis of \\textit{relative} errors.  Thus if there are large\nerrors in the computations, that situation maybe quite acceptable if\nthe answers are large.  In the preceding example, let us start with\ninitial values $x_0=1$ and $x_1=4$.  The recurrence\nrelation~(\\ref{unstable}) is unchanged and therefore errors will still\nbe propagated and magnified as before.  But the correct solution is\nnow $x_n=4^n$ and the results of the computation are correct to seven\nsignificant figures (see Table~\\ref{unst2}).  In this case the correct\nvalues are large enough to overwhelm the errors.  The absolute errors\nare undoubtedly large (as before), but they are relatively negligible.\n\n\\begin{table}\n  \\begin{center}\n    \\begin{tabular}{|c|c|c|c|} \\hline\n      $n$ & $x_n$ & Abs. err. & Rel. err. \\\\ \\hline \\hline\n      0 & +1.0000000e+00 & +0.0000000e-01 & +0.0000000e-01 \\\\ \\hline \n      1 & +4.0000000e+00 & +0.0000000e-01 & +0.0000000e-01 \\\\ \\hline \n      2 & +1.6000000e+01 & +0.0000000e-01 & +0.0000000e-01 \\\\ \\hline \n      3 & +6.4000000e+01 & +0.0000000e-01 & +0.0000000e-01 \\\\ \\hline \n      4 & +2.5600000e+02 & +0.0000000e-01 & +0.0000000e-01 \\\\ \\hline \n      \\vdots & \\vdots & \\vdots & \\vdots \\\\ \\hline\n      15 & +1.0737418e+09 & +0.0000000e-01 & +0.0000000e-01 \\\\ \\hline \n      16 & +4.2949672e+09 & +1.0000000e+02 & +2.3283064e-08 \\\\ \\hline \n      17 & +1.7179868e+10 & +1.0000000e+03 & +5.8207661e-08 \\\\ \\hline \n      18 & +6.8719471e+10 & +6.0000000e+03 & +8.7311490e-08 \\\\ \\hline \n      19 & +2.7487788e+11 & +3.0000000e+04 & +1.0913936e-07 \\\\ \\hline \n      20 & +1.0995115e+12 & +1.0000000e+05 & +9.0949470e-08 \\\\ \\hline \n    \\end{tabular}\n  \\end{center}\n  \\caption{\\label{unst2} \\it Iterations of the unstable\n    map~(\\ref{unstable}) with initial conditions $x_0=1$ and\n    $x_1=4$.   The correct value of the $n$-th iterate is $x_n=4^n$.}\n\\end{table}\n\n\\smallskip\n\n\\noindent\n\\textbf{Remark} - The errors we have discussed until now are\nindependent of the mathematical problem we wish to solve and are\ninherent to the numerical procedure that we are using.   However,\nthere are mathematical problems that are intrinsically ``difficult'',\nin the sense that a small alteration of one of the parameters of the\nproblem (for example, one of the coefficients of a system of linear\nequations) alters dramatically the value of the solution.   Such\nproblems are called \\textit{ill conditioned} and we will discuss them\nas we encounter them.\n", "meta": {"hexsha": "fc6343dccd9a9b6a6e89e7a1aa69b50e008d6893", "size": 16878, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/tex/Error_analysis.tex", "max_stars_repo_name": "josh-gree/NumericalMethods", "max_stars_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 76, "max_stars_repo_stars_event_min_datetime": "2015-02-12T19:51:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T15:34:11.000Z", "max_issues_repo_path": "Notes/tex/Error_analysis.tex", "max_issues_repo_name": "josh-gree/NumericalMethods", "max_issues_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-05-24T19:49:52.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-23T21:40:42.000Z", "max_forks_repo_path": "Notes/tex/Error_analysis.tex", "max_forks_repo_name": "josh-gree/NumericalMethods", "max_forks_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2015-01-05T13:30:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-15T09:59:39.000Z", "avg_line_length": 39.0694444444, "max_line_length": 106, "alphanum_fraction": 0.6919658727, "num_tokens": 5467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257127, "lm_q2_score": 0.9124361670249624, "lm_q1q2_score": 0.7116937228817843}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%\n%\n%   Thesis template by Youssif Al-Nashif\n%\n%   May 2020\n%\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Graph Kernels for Similarity}\n\n\\hspace*{0.3cm} Graph kernels can be used to compare the similarity of two graphs. The development of these methods arose out of the need to determine if graphs were isomorphic in a faster way. The solution was a graph kernel which produces a scalar value for how similar two, or more, graphs are. The result of a graph kernel is a matrix where the similarity of graphs $i$ and $j$ is in the kernel's $i$-th row and $j$-th column entry. This resulting matrix can be used in a variety of ways, but it will be used as a distance matrix in applications here. \\\\\n\nAmongst graph kernels which consider edge or vertex labels in their computation, various surveys and studies have found edge label histogram kernels or vertex label histograms to be the most efficient. They may not out perform the other methods, like a Weisfeiler-Lehman or other subgraph methods, but they are computationally cheap. The datasets being studied here are both large: one contains many smaller graphs, and one contains 48 very large graphs. So for this study, computation efficiency was prioritized. \\\\\n\nThe edge label histogram kernel is the graph kernel that was chosen for these datasets, and it can be computed using either a linear kernel or a Guassian radial basis function (RBF) kernel between the edge label histograms. \\\\\nAn edge label histogram is defined as $\\vec{g} = (g_1,g_2, ... g_i)$ such that $g_i = | \\{ (u,v) \\in E | \\phi(u,v) = i \\} |$ for each $i$ \\cite{sugiyama2015halting}. Where $g_i$ is a histogram bin for a unique edge label's magnitude, $E$ is the set of edges, and $\\phi$ is a function that maps each label to a scalar value in the range of unique values. The edge label histograms are then passed through a kernel, either a linear kernel or a Gaussian RBF kernel.\\\\\nComputation using a linear kernel takes two graphs, $G$ and $G'$, and uses their edge label histograms $\\vec{g}$ and $\\vec{g'}$. The kernel is computed as:\n\n\\begin{equation}\nK(\\vec{g},\\vec{g'}) = \\vec{g}^{T}\\vec{g'}\n\\end{equation}\n\nThe resulting value is stored in the graph kernel matrix as the measure of similarity between the two graphs in the corresponding row and column for the pair \\cite{sugiyama2015halting}.\n\nAlternatively, the Gaussian RBF kernel takes the edge label histograms of $G$ and $G'$, that we call $\\vec{g}$ and $\\vec{g'}$, and the kernel is computed as:\n\n\n\\begin{equation}\nK(\\vec{g},\\vec{g'}) = e^{- \\left( \\frac{||\\vec{g}- \\vec{g'}||^2}{2 \\sigma^2} \\right) }\n\\end{equation}\n\nThe resulting value is stored in the graph kernel matrix as the measure of similarity between the two graphs in the corresponding row and column for the pair. Through either of these kernels, we obtain a kernel of dimensions $n \\times n$ for a list of $n$ graphs. This kernel can then be used for clustering methods.\n\n% https://papers.nips.cc/paper/2015/file/31b3b31a1c2f8a370206f111127c0dbd-Paper.pdf\n\n\n", "meta": {"hexsha": "b7fa9620b08ddcd78cc2a1079533b0acb19b6326", "size": 3024, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis_Tex/Content/02_Chapters/Chapter 03/Sections/02_GraphKernels.tex", "max_stars_repo_name": "Levi-Nicklas/GraphDocNLP", "max_stars_repo_head_hexsha": "dec1acb24a2ab42b46d161c92b69ad3a55fcc5ff", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-27T02:08:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-27T02:08:34.000Z", "max_issues_repo_path": "Thesis_Tex/Content/02_Chapters/Chapter 03/Sections/02_GraphKernels.tex", "max_issues_repo_name": "Levi-Nicklas/GraphDocNLP", "max_issues_repo_head_hexsha": "dec1acb24a2ab42b46d161c92b69ad3a55fcc5ff", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2021-02-18T16:07:14.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-25T14:18:51.000Z", "max_forks_repo_path": "Thesis_Tex/Content/02_Chapters/Chapter 03/Sections/02_GraphKernels.tex", "max_forks_repo_name": "Levi-Nicklas/GraphDocNLP", "max_forks_repo_head_hexsha": "dec1acb24a2ab42b46d161c92b69ad3a55fcc5ff", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 81.7297297297, "max_line_length": 558, "alphanum_fraction": 0.7384259259, "num_tokens": 786, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.8539127603871312, "lm_q1q2_score": 0.7115865196200731}}
{"text": "\\chapter{Regularized Regression: Lasso, Ridge, and Elastic Net \\label{chapter:lassoridge}}\n\nIn Chapter~\\ref{chapter:featureselection}, we discussed embedded feature selection methods. These methods incorporate feature selection into the process of model training. Decision trees and tree ensembles (boosted trees, random forests) naturally perform feature selection in the process of model training, and will simply ignore irrelevant features. \n\nRegression methods, however, have a harder time. When people began to want to apply regression methods to supervised learning problems with large numbers of predictors -- particularly when the number of predictors was greater than the number of samples, or when the predictors were highly correlated -- they faced serious problems of overfitting and model instability. This led to the development of \\textbf{regularized regression} (a.k.a. \\textbf{penalized regression}) methods, which introduce penalty terms into the objective functions being optimized in the model fitting process to try to control the size of the coefficients assigned to various predictors and/or set some of them to zero. The goal of these methods is to allow researchers to stick with the machinery of regression models while reducing the possibility of overfitting. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Linear Regression}\n\nLinear regression (Chapters~\\ref{chapter:regression}, \\ref{chapter:linreg}, and \\ref{chapter:glms}) uses the mean-squared loss:\n$$ \\text{loss} = \\sum_{i=1}^N (y^{(i)} - \\beta^T x^{(i)})^2 $$\nwhere $\\beta^T x^{(i)} = \\beta_0 + \\beta_1 x_1^{(i)} + \\dots + \\beta_p x_p^{(i)}$ is the model's prediction for the $i$th training example. To minimize the loss, we adjust the $\\beta$s to make the model's predictions close to the true $y^{(i)}$ values. This is equivalent to maximizing the likelihood (see Section~\\ref{section:mleglms}). \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Logistic Regression}\n\nLogistic regression (Chapters~\\ref{chapter:classification}, \\ref{chapter:logreg}, and \\ref{chapter:glms}) uses the negative binomial log-likelihood as its loss (compare the expression below to the one in Chapter~\\ref{chapter:glms}:\n$$ \\text{loss} = -\\sum_{i=1}^n \\left[ y^{(i)} \\beta^T x^{(i)} - \\log \\left(1 + \\exp(\\beta^T x^{(i)}) \\right) \\right]. $$\nThe expression has a negative sign in front because high log-likelihood is a good thing; we want low values of the log-likelihood to correspond to high values of the loss.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Lasso, Ridge, and Elastic Net Penalties}\n\nIn situations where there is a risk of overfitting and model instability (e.g., highly correlated predictors, more predictors than training examples), one can apply a penalty term to the loss function to prevent the model coefficients from taking on unrealistically large or small values. \n\n\\subsection{Lasso Penalty}\n\nThe \\textbf{Lasso}, or \\textbf{L1}, penalty is related to the sum of the absolute values of the coefficients:\n\n$$ \\text{penalty}_\\text{Lasso} = \\lambda \\sum_{j=1}^p \\vert \\beta_j \\vert $$\n\nThis penalty will tend to cause the model to perform feature selection, setting some of the $\\beta$s to zero. The values of the others may shrink, or they may be unaffected. \n\n\\subsection{Ridge Penalty}\n\nThe \\textbf{ridge}, or \\textbf{L2}, penalty is related to the sum of the squared values of the coefficients:\n\n$$ \\text{penalty}_\\text{ridge} = \\lambda \\sum_{j=1}^p \\beta_j^2 $$\n\nThis penalty will tend to shrink the values of all of the model coefficients without setting any to zero. \n\n\\subsection{Elastic Net Penalty}\n\nThe \\textbf{elastic net} penalty is just a weighted sum of the Lasso and ridge penalties:\n\n$$ \\text{penalty}_\\text{EN} = \\lambda \\left[ \\alpha \\sum_{j=1}^p \\vert \\beta_j \\vert + (1-\\alpha)  \\sum_{j=1}^p \\beta_j^2 \\right] $$\n\nThe parameter $\\alpha$ governs the relative weights of the two penalties. In practice, $\\lambda$ and $\\alpha$ are set using cross-validation. The value of $\\lambda$ is unconstrained, but $\\alpha$ must lie between 0 and 1. \n\n\\begin{question}{}\nThis picture, from \\emph{Elements of Statistical Learning} (Figure 6.7) is a geometric picture of what happens to the coefficients under the Lasso and ridge penalties.\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{img/esl-lasso-ridge-6.7.png}\n\\end{center}\nWhich picture is which? What are the red ellipses? What are the blue shapes? Do you see why Lasso is more likely than ridge to set some of the coefficients to zero?\n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Example: Predicting Blood Pressure}\n\nImagine we have collected blood pressure data on $10$ patients. In addition, we have information on the patients' sex, age, and obesity status. \n\n{\\small\n\\begin{center}\n\\begin{tabular}{cccccc}\r  \\toprule\r & sexf & sexm & age & obesity & blood\\_pressure \\\\ \r  \\midrule\r  1 & 0 & 1 & 54 & 1 & 123 \\\\ \r  2 & 1 & 0 & 66 & 0 & 111 \\\\ \r  3 & 1 & 0 & 23 & 0 & 98 \\\\ \r  4 & 0 & 1 & 59 & 1 & 154 \\\\ \r  5 & 0 & 1 & 76 & 1 & 199 \\\\ \r  6 & 1 & 0 & 33 & 0 & 101 \\\\ \r  7 & 0 & 1 & 35 & 1 & 91 \\\\ \r  8 & 1 & 0 & 54 & 0 & 133 \\\\ \r  9 & 1 & 0 & 21 & 0 & 116 \\\\ \r  10 & 0 & 1 & 26 & 0 & 121 \\\\\n  \\bottomrule\n\\end{tabular}\n\\end{center}\n}\n\nNote: These data are from an example in the paper ``Predictive analytics with gradient boosting in clinical medicine'', by Zhang et al, published in \\emph{Annals of Translational Medicine} in 2019.\n\n\\vspace{2mm}\n\\begin{question}{}\nWhich two predictors in this model are clearly correlated?\n\\end{question}\n\nWe will now try many different values of $\\lambda$ and $\\alpha$ on these data and see what happens to the coefficients. To do this, we use the \\texttt{glmnet} package in R. Here are the results:\n\n{\\small\n\\begin{center}\n\\begin{tabular}{rrrrrrr}\n  \\toprule\n & lambda & alpha & beta\\_sexf & beta\\_sexm & beta\\_age & beta\\_obesity \\\\ \n  \\midrule\n1 & 0.0 & 0.0 & -24.61 & -0.00 & 1.15 & -13.78 \\\\ \n  2 & 1.0 & 0.0 & -11.19 & 10.71 & 1.09 & -9.97 \\\\ \n  3 & 5.0 & 0.0 & -8.25 & 8.24 & 0.91 & -2.11 \\\\ \n  4 & 10.0 & 0.0 & -6.97 & 6.99 & 0.77 & 1.66 \\\\ \n  5 & 0.0 & 0.2 & -24.61 & -0.00 & 1.15 & -13.78 \\\\ \n  6 & 1.0 & 0.2 & -10.35 & 9.73 & 1.07 & -7.84 \\\\ \n  7 & 5.0 & 0.2 & -6.81 & 6.72 & 0.88 & 0.00 \\\\ \n  8 & 10.0 & 0.2 & -6.10 & 6.07 & 0.76 & 0.00 \\\\ \n  9 & 0.0 & 0.5 & -24.61 & -0.00 & 1.15 & -13.78 \\\\ \n  10 & 1.0 & 0.5 & -9.09 & 8.04 & 1.04 & -4.38 \\\\ \n  11 & 5.0 & 0.5 & -5.65 & 5.50 & 0.87 & 0.00 \\\\ \n  12 & 10.0 & 0.5 & -3.84 & 3.77 & 0.71 & 0.00 \\\\ \n  13 & 0.0 & 1.0 & -24.61 & -0.00 & 1.15 & -13.78 \\\\ \n  14 & 1.0 & 1.0 & -13.15 & 0.00 & 1.00 & 0.00 \\\\ \n  15 & 5.0 & 1.0 & -6.93 & 0.00 & 0.84 & 0.00 \\\\ \n  16 & 10.0 & 1.0 & 0.00 & 0.00 & 0.62 & 0.00 \\\\ \n   \\bottomrule\n\\end{tabular}\n\\end{center}\n}\n\n\\begin{question}{}\nWhich values for $\\lambda$ and $\\alpha$ correspond to: (a) unregularized linear regression, (b) pure Lasso, (c) pure ridge, (d) elastic net with an even combination of Lasso and ridge penalties? What happens to the values of the coefficients in each case?\n\\end{question}\n\n\n", "meta": {"hexsha": "7d6f85ec9640352a8f46bd9a6e3de9f4e32352cc", "size": 7196, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-lasso-ridge-regression.tex", "max_stars_repo_name": "blpercha/mcds-notes", "max_stars_repo_head_hexsha": "33531a443afb154b5c415299276a2ad215463896", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-12-10T16:51:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T01:31:23.000Z", "max_issues_repo_path": "tex/mcds-lasso-ridge-regression.tex", "max_issues_repo_name": "blpercha/mcds-notes", "max_issues_repo_head_hexsha": "33531a443afb154b5c415299276a2ad215463896", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/mcds-lasso-ridge-regression.tex", "max_forks_repo_name": "blpercha/mcds-notes", "max_forks_repo_head_hexsha": "33531a443afb154b5c415299276a2ad215463896", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T17:16:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T17:16:44.000Z", "avg_line_length": 62.0344827586, "max_line_length": 841, "alphanum_fraction": 0.6561978877, "num_tokens": 2282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907933, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7115865079036331}}
{"text": "\\chapter{Graph Games}\n\\marginurl{%\n    Graph Games:\\\\\\noindent\n    Introduction to Combinatorial Game Theory \\#4\n}{youtu.be/71fSkXp4DJc}\n\nThis section gives an alternative definition of a combinatorial game.\nThis definition allows us to study general combinatorial games.\n\\begin{definition}\n  A \\emph{directed graph} $G$ is a pair $(V, N)$ such that $V$ is a non-empty\n  set and $N : V \\to 2^V$.\\footnote{%\n    We are going to have a more in-depth\n    discussion of graphs in \\Cref{part:graph-theory}.\n  }\n\n  We say that a game on $G$ is the impartial game where elements of $V$ are\n  positions and each player can move from $x \\in V$ to any $y \\in N(x)$.\n  (Elements of $N(x)$ are called followers of $x$.)\n\\end{definition}\n\n\\begin{remark}\n  It is also easy to see that any impartial game can be transformed into a graph\n  $G$ such that the game on $G$ and the impartial game are equivalent.\n\\end{remark}\n\nFor example, the take-away game from \\Cref{chapter:combinatorial-games}\ncan be considered as a graph on a graph $G = (\\N_0, N)$,\nwhere $N(0) = \\emptyset$, $N(1) = \\set{0}$, $N(2) = \\set{0, 1}$, and\n$N(n + 3) = \\set{n, n + 1, n + 2}$ for any $n \\in \\N_0$.\n\nThe key ingredient for the analysis of games based on graphs was proposed\nby Sprague and Grundy. They proposed to consider the following function:\n\\begin{definition}\n  Let $G = (V, N)$ be a directed graph. A function $g : V \\to \\N$ is a\n  \\emph{Sprague--Grundy function} for $G$ iff\n  $g(x) = \\mex\\set[y \\in N(x)]{g(y)}$, where\n  $\\mex S = \\min \\set[n \\notin S]{n \\in \\N_0}$.\n\\end{definition}\n\n\nConsider the following graph (arrows depict possible moves).\n\\begin{center}\n\\begin{tikzpicture}[thick]\n  \\node[circle, draw, minimum size=6pt] (v1) at (0,0) {$1$};\n  \\node[circle, draw, minimum size=6pt] (v2) at (1,1) {$2$};\n  \\node[circle, draw, minimum size=6pt] (v3) at (-1,1) {$3$};\n  \\node[circle, draw, minimum size=6pt] (v4) at (0,2) {$4$};\n\n\n  \\draw[->] (v2) -- (v3);\n  \\draw[->] (v1) -- (v3);\n  \\draw[->] (v4) -- (v3);\n  \\draw[->] (v4) -- (v2);\n\\end{tikzpicture}\n\\end{center}\nLet us assume that $g$ is a Sprague--Grundy function for this graph.\nNote that $3$ is a terminal position so $g(3) = \\mex \\emptyset = 0$.\nSince from $1$ and $2$ there are only moves to $3$, it is clear that\n$g(1) = g(2) = \\mex \\set{0} = 1$. Finally, $g(4) = \\mex \\set{0, 1} = 2$.\n\nNote that the Sprague--Grundy function is recursively defined so it may\nnot exist or not to be unique if graph violates the ending condition.\nFor example, the graph depicted on \\Cref{figure:sprague-grundy-not-exists}\ndoes not have a Sprague--Grundy function.\nIndeed, assume that such a function $g$ exists. Consider two following cases.\n\\begin{itemize}\n    \\item First case is when $g(3) = 0$. Note that $g(2) = \\mex \\set{0} = 1$.\n        Hence, $g(1) = \\mex \\set{1} = 0$ which contradicts the assumption\n        that $g(3) = 0$ since $g(3) = \\mex \\set{g(0)} = 1$.\n    \\item Second case is when $g(3) \\neq 0$. Note that $g(2) = \\mex \\set{g(3)} = 0$.\n        Therefore $g(1) = \\mex \\set{0} = 1$ and $g(3) = \\mex \\set{1} = 0$ which\n        is a contradiction.\n\\end{itemize}\n\nNote that the graph depicted on \\Cref{figure:sprague-grundy-not-unique} has\nseveral Sprague--Grundy functions. We may consider functions $g_1$ and $g_2$\nsuch that $g_1(1) = g_1(3) = g_2(2) = g_2(4) = 0$ and\n$g_2(1) = g_2(3) = g_1(2) = g_1(4) = 1$. It is clear that they are\nSprague--Grundy functions for the graph from\n\\Cref{figure:sprague-grundy-not-unique}.\n\n\\begin{figure}\n    \\centering\n    \\subfloat[A graph without a Sprague--Grundy function\n              \\label{figure:sprague-grundy-not-exists}]{\n      \\begin{tikzpicture}[thick]\n        \\node[circle, draw, minimum size=6pt] (v1) at (0,0) {$1$};\n        \\node[circle, draw, minimum size=6pt] (v2) at (1,1) {$2$};\n        \\node[circle, draw, minimum size=6pt] (v3) at (-1,1) {$3$};\n        \\node[] (dummy) at (2.25,1) {};\n        \\node[] (dummy) at (-2.25,1) {};\n\n        \\draw[->] (v1) -- (v2);\n        \\draw[->] (v2) -- (v3);\n        \\draw[->] (v3) -- (v1);\n      \\end{tikzpicture}\n    }\n    \\qquad\n    \\subfloat[A graph with several Sprague--Grundy functions\n              \\label{figure:sprague-grundy-not-unique}] {\n      \\begin{tikzpicture}[thick]\n        \\node[circle, draw, minimum size=6pt] (v1) at (1,1) {$1$};\n        \\node[circle, draw, minimum size=6pt] (v2) at (0,0) {$2$};\n        \\node[circle, draw, minimum size=6pt] (v3) at (-1,1) {$3$};\n        \\node[circle, draw, minimum size=6pt] (v4) at (0,2) {$4$};\n        \\node[] (dummy) at (2.25,1) {};\n        \\node[] (dummy) at (-2.25,1) {};\n\n\n        \\draw[->] (v1) -- (v2);\n        \\draw[->] (v2) -- (v3);\n        \\draw[->] (v3) -- (v4);\n        \\draw[->] (v4) -- (v1);\n      \\end{tikzpicture}\n    }\n    \\caption{Graphs where Sprague--Grundy function is either not unique or does\n      not exist.}\n    \\vskip 10pt\n\\end{figure}\n\nUnfortunately, even if there are no cycles, a graph my not have a\nSprague--Grundy function or have several Sprague--Grundy functions. Indeed,\nconsider the graph $G = (\\Z, N)$ such that $N(x) = \\set{x - 1}$. It is clear\nthat the functions $g_1$ and $g_2$ such that\n\\begin{gather*}\n    g_1(x) =\n    \\begin{cases}\n        0 & \\text{if } x \\text{ is even} \\\\\n        1 & \\text{if } x \\text{ is odd}\n    \\end{cases} \\\\\n    \\text{and} \\\\\n    g_2(x) =\n    \\begin{cases}\n        0 & \\text{if } x \\text{ is even} \\\\\n        1 & \\text{if } x \\text{ is odd}\n    \\end{cases}\n\\end{gather*}\nare Sprague--Grundy functions for $G$.\n\n\\begin{exercise}\n    Let $G = (\\N \\cup \\set{\\infty}, N)$ such that \n    $N(x) = \\set[y < x]{y \\in \\N_0}$, and $N(\\infty) = \\N$.\n    Show that $G$ does not have a Sprague--Grundy function.\n\\end{exercise}\n\nHowever, for all the combinatorial games we are going to consider\nthe Sprague--Grundy function exists and is unique.\n\\begin{theorem}\n\\label{theorem:ending-condition-sg-function}\n  Let $G = (V, N)$ be a graph such that $N(v)$ is finite and $G$ satisfies the\n  ending condition. Then Sprague--Grundy function for $G$ exists and it is\n  unique.\n\\end{theorem}\n\nBefore we prove this theorem, let us illustrate by proving that the\nSprague--Grundy function for \\Cref{game:take-away-21-3-2-1} is unique.\nAssume that a Sprague--Grundy function $g$ for \\Cref{game:take-away-21-3-2-1}\nexists. We are going to show that it is unique.\nNote that if $x$ is a terminal position, then $g(x) = 0$. Hence, $g(0) = 0$.\nThere is only one move from $1$ so $g(1) = \\mex \\set{0} = 1$. Similarly\nthere are two moves from $2$: one to $1$ and one to $0$ so\n$g(2) = \\mex \\set{0, 1} = 2$. In the same way $g(3) = \\mex \\set{0, 1, 2} = 3$\nand $g(4) = \\mex \\set{1, 2, 3} = 0$.\nOne may notice that there is a pattern and conjecture that\n\\[\n  g(x) =\n  \\begin{cases}\n      0 & \\text{if } x \\equiv 0 \\pmod{4} \\\\\n      1 & \\text{if } x \\equiv 1 \\pmod{4} \\\\\n      2 & \\text{if } x \\equiv 2 \\pmod{4} \\\\\n      3 & \\text{if } x \\equiv 3 \\pmod{4}\n  \\end{cases}.\n\\]\nWe already proved the base case, let us now prove the induction step.\nAssume the equality is true for all $y < x$ and consider the following cases.\n\\begin{itemize}\n    \\item If $x \\equiv 0 \\pmod{4}$, then $x - 1 \\equiv 3 \\pmod{4}$,\n        $x - 2 \\equiv 2 \\pmod{4}$, and $x - 3 \\equiv 1 \\pmod{4}$.\n        Hence, $g(x) = \\mex \\set{1, 2, 3} = 0$.\n    \\item If $x \\equiv 1 \\pmod{4}$, similarly $g(x) = \\mex \\set{2, 3, 0} = 1$.\n    \\item If $x \\equiv 2 \\pmod{4}$, $g(x) = \\mex \\set{3, 0, 1} = 2$.\n    \\item If $x \\equiv 3 \\pmod{4}$, $g(x) = \\mex \\set{0, 1, 2} = 3$.\n\\end{itemize}\nIt is also clear that the constructed function is indeed a Sprague--Grundy\nfunction for \\Cref{game:take-away-21-3-2-1}. Therefore, we proved its\nexistence and uniqueness.\n\\begin{table}\n  \\centering\n  \\begin{tabular}{l l l l l l l l l}\n      \\toprule\n      0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\\\\n      \\midrule\n      0 & 1 & 2 & 3 & 0 & 1 & 2 & 3 & 0 \\\\\n      \\bottomrule\n  \\end{tabular}\n  \\caption{The Sprague--Grundy function for \\Cref{game:take-away-21-3-2-1}}\n  \\label{table:take-away-21-3-2-1-grundy}\n  \\vskip 10pt\n\\end{table}\n\nNote that in this proof we used a procedure very similar to the one we used to\nfind P- and N-positions.\n\\begin{template}\n  \\textbf{Steps necessary to find a Sprague--Grundy function} \\\\\n\n  Assume we are trying to construct a a Sprague--Grundy function $g$.\n  \\begin{enumerate}\n    \\item Set $g(x) = 0$ for all terminal positions $x$.\n    \\item If $g(x)$ is not defined but $g(y)$ is defined for all $y \\in N(x)$,\n      then set $g(x) = \\mex \\set[y \\in N(x)]{g(y)}$.\n    \\item If $g(x)$ is not defined for some $x$, go to Step~2.\n  \\end{enumerate}\n\\end{template}\n\nLet $V_0$ be the set of terminal positions, and let $V_i$ be the set of $x$ such\nthat we define $g(x)$ on the $i$th iteration of the procedure.\nThe following lemma essentially says that this procedure defines $g$ everywhere.\n\\begin{lemma}[K\\H{o}nig]\n\\label{lemma:konig}\n  Let $G = (V, N)$ be a graph such that $N(v)$ is finite for all $v \\in V$ and\n  $G$ satisfies the ending condition.\n  Let $V_0$ be the set of terminal positions, and let $V_{n + 1} = \n  \\set[N(v) \\subseteq V_n]{v \\in V}$. Then $V = \\bigcup_{n \\in \\N_0} V_n$.\n\\end{lemma}\n\n\\begin{proof}[Proof of \\Cref{theorem:ending-condition-sg-function}]\n  Let $V_0$ be the set of terminal positions, and let $V_{n + 1} = \n  \\set[N(v) \\subseteq V_n]{v \\in V}$.\n  \\Cref{lemma:konig} claims that $V = \\bigcup_{n \\in \\N_0} V_n$.\n\n  For each $n \\in \\N_0$, we define $g_n : V_n \\to \\N_0$ such that \n  $\n    g_{n + 1}(v) = \\mex \\set[u \\in N(v)]{g_n(u)}\n  $\n  for $v \\in V_{n + 1}$ and $g_0(v) = 0$ for $v \\in V_0$. It is easy to see\n  that the function $g : V \\to \\N_0$ such that $g(v) = g_n(v)$ for $v \\in V_n$\n  is a Sprague--Grundy function for $G$. \n\n  To finish the proof we need to prove that there are no other Sprague--Grundy\n  functions for $G$. Assume that $g'$ is a Sprague--Grundy function for\n  $G$; we prove using induction by $n \\in \\N_0$ that $g(v) = g'(v)$ for \n  $v \\in V_n$. The base case for $v = 0$ is clear since $N(v) = \\emptyset$ for\n  $v \\in V_0$. Let us consider the induction step from $n$ to $n + 1$. By the\n  induction hypothesis, $g(u) = g'(u)$ for $u \\in V_n$. Let us consider some $v\n  \\in V_{n + 1}$. Note that \n  \\[\n    g'(v) = \\mex \\set[u \\in N(v)]{g(u)} = \\mex \\set[u \\in N(v)]{g(u)} = g(v).\n  \\]\n  Therefore $g(v) = g'(v)$ for $v \\in V_{n + 1}$. As a result, $g(v) = g'(v)$\n  for $v \\in V$; i.e., $g = g'$.\n\\end{proof}\n\nOne may note that in \\Cref{game:take-away-21-3-2-1} P-positions are the positions\nwhere the Sprague--Grundy function is zero. In fact, this is not a coincidence.\n\\begin{theorem}\n\\label{theorem:grundy-to-np}\n  Let $G = (V, N)$ be a graph such that $N(v)$ is finite for all $v \\in V$ and \n  $G$ satisfies the ending condition. Then all the vertices of $G$ can be\n  labeled as either P- or N-positions. Moreover, $v \\in V$ is a P-position iff\n  $g(v) = 0$, where $g$ is the Sprague--Grundy function for $G$.\n\\end{theorem}\n\n\n\\begin{chapterendexercises}\n    \\exercise Prove \\Cref{theorem:grundy-to-np}.\n    \\exercise Show that there are only two Sprague--Grundy functions for the\n      graph depicted on \\Cref{figure:sprague-grundy-not-unique}.\n    \\exercise Prove that there is unique Sprague--Grundy function for the one pile\n        Nim game.\n    \\exercise Prove that there is unique Sprague--Grundy function for the\n        subtraction game where players may subtract $2$ and $3$ chips on their\n        turn.\n    \\exercise\n       Prove that there is unique Sprague--Grundy function for the subtraction\n       game where players may subtract $1$, $2$, or $5$ chips\n       on their turn.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "452ad4dec09811325ffef4105132d340a840ea82", "size": 11578, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_2/chapter_12_graph_games.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_2/chapter_12_graph_games.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_2/chapter_12_graph_games.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 41.6474820144, "max_line_length": 84, "alphanum_fraction": 0.6193643116, "num_tokens": 4261, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245911726382, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7115864957505811}}
{"text": "\\chapter{Additional Pipeline Information}\n\\section{Derivations of the Flow Variance}\n\\label{sec:derivation_flow_var}\nFlow estimation can be noisy for various reasons and the problem is that the nois is often proportional to the magnitude of the absolud flow. thus using a simple flow difference as ameasure will constantly underestimate the simmilarity between heigh magnitude flow. Hence, let us assume \n\\begin{equation}\n\\begin{aligned}\n\\colvec{u_1}{v_1} = f + \\colvec{x_1}{y_1} \\\\\n\\colvec{u_2}{v_2} = f + \\colvec{x_2}{y_2}\n\\end{aligned}\n\\label{eq:def_flow_tracking}\t\n\\end{equation}\n\nwhere f is the true flow and \n\\begin{equation}\n\t\\colvec{x_1}{y_1} \\sim \\colvec{x_2}{y_2}\n\\end{equation}\n\nLet us assume, that the random variables $x_1$ and $x_2$ are i.i.d. distributed having a zero mean and a variance $\\sigma_x^2$, $x_1$ and $x_2$ respectively, i.e.\n\n\\begin{equation}\n\\begin{aligned}\nx_1 \\sim x_2 (0, \\sigma_x^2) \\\\\ny_1 \\sim y_2 (0, \\sigma_y^2\n\\end{aligned}\n\\label{eq:def_flow_tracking}\t\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\n\\mathbf{E} \\left[ \\norm{\\colvec{u_1}{v_1} - \\colvec{u_2}{v_2}} \\right]\n& = \\mathbf{E} \\left[ (u_1 - u_2)^2 \\right] + \\mathbf{E} \\left[ (v_1 - v_2)^2 \\right] \\\\\n& = \\mathbf{E} \\left[ u_1^2 - 2 u_1 u_2 + u_2^2 \\right] + \\mathbf{E} \\left[ v_1^2 - 2 v_1 v_2 + v_2^2 \\right] \\\\\n& = \\mathbf{E} \\left[ x_1^2 \\right] + \\mathbf{E} \\left[ x_2^2 \\right] + \\mathbf{E} \\left[ y_1^2 \\right] + \\mathbf{E} \\left[ y_2^2 \\right] \\\\\n& = 2 \\left( \\sigma_x^2 + \\sigma_y^2 \\right)\n\\end{aligned}\n\\label{eq:flow_variance_formula}\t\n\\end{equation}\nIn the last step of Equation $\\ref{eq:flow_variance_formula}$ we used the abbreviation $\\sigma_x^2$ which denotes the variance of the optical flow along its $x$ direction. In this derivation we exploited the fact that $x_1$ and $x_2$ are independent random variables, $y_1$ and $y_2$ respectively. Hence, the term $\\mathbf{E} \\left[ x_1 x_2\\right]$ yields the value zero.\n\n\\chapter{Additional Theoretical Background}\n\\section{On Filtering Images}\n\\subsection{Gaussian Filter}\nA Gaussian filter (\\textbf{GF}) is a linear operator that reduces noise by smoothing the image. Applying GF corresponds to a low-pass filtering.\nAt each position it estimates a local average of the intensities as defined in Equation $\\ref{eq:gaussian_filtering_def}$.\n\\begin{equation}\n\t\\mathcal{F}^{\\text{gf}} \\{I \\} (p) = \\sum_{q \\in \\Omega_p} G_{\\sigma} (\\norm{p - q}) I_q\n\\label{eq:gaussian_filtering_def}\n\\end{equation}\nwhere $I$ defines the input image and $\\Omega_p$ contains all neighboring points within the window that are centered at the image point $p$. Moreover, $G_{\\sigma}$ denotes the two dimensional Gaussian kernel, which is defined in Equation $\\ref{eq:def_g_weight}$.\n\\begin{equation}\n\tG_{\\sigma} (x) = \\frac{1}{2 \\pi \\sigma^2} e^{-\\frac{x^2}{2 \\sigma^2}}\n\\label{eq:def_g_weight}\n\\end{equation}\nThe Gaussian filtering is the weighted average of the intensity of the adjacent positions with a weight decreasing with the spatial distance to the center position. This distance is defined by $G_{\\sigma} (\\norm{p - q})$ where $\\sigma$ is a parameter that defines the size of the neighborhood. The resulting image is a blurred version of the input image.\n\n\\subsection{Bilateral Filter}\n\\label{sec:bilateral_filter}\nA Bilateral filter (\\textbf{BF}) is a non-linear operator that reduces noise by smoothing the image but at the same time preserves its edges. \\\\ \\\\\nThe rational of this filter is that two pixels are close to each other if not only if their spacial distance is small but also if they are similar regarding their intensity range.\n\\begin{figure}[H]\n\\begin{center}\n\\subfigure[Raw Image]{\n   \\includegraphics[width=0.47\\linewidth] {background/filtering/l_raw}\n}\n\\subfigure[Filtered Image]{\n   \\includegraphics[width=0.47\\linewidth] {background/filtering/l_filtered}\n}\n\\end{center}\n\\caption[Example Bilateral Filter]{A bilateral filtering example: On the left side a noisy input image on the right its bilateral filtered version.}\n\\label{fig:bilat_filtering_eg}\n\\end{figure}\nThe filter replaces the intensity values at each pixel in an image by a weighted average of intensity values from nearby pixels. In our formulation we rely on the Gaussian distributions $G$ for defining the weights. Crucially, the weights depend not only on distances between pixels, but also on the intensity difference. That is why, when iterating through each pixel and adjusting weights to the adjacent pixels accordingly, Sharp edges are preserved. A bilateral filtering example$\\footnote{All illustrated results were generated by using our own Bilateral filter implementation. For further information please visit our repository at \\url{https://github.com/simplay/master_thesis}}$ is shown in Figure $\\ref{fig:bilat_filtering_eg}$.\\\\ \\\\\nThe mathematical definition of this filter is given in Equation $\\ref{eq:def_bilateral_filter}$. For a given Image $I$ we want to compute its bilateral filtered version by applying the following definition:\n\\begin{equation}\n\\begin{aligned}\n&\\mathcal{F}^{\\text{bf}} \\{I \\} (p) = \\frac{1}{W_p} \\sum_{q \\in \\Omega_p} \\underbrace{G_{\\sigma_s} (\\norm{p-q})G_{\\sigma_r} (I_p - I_q)}_{w_p} I_q \\\\\t\n& \\text{where } W_p = \\sum_{q \\in \\Omega_p} G_{\\sigma_s} (\\norm{p-q})G_{\\sigma_r} (I_p - I_q)\n\\end{aligned}\n\\label{eq:def_bilateral_filter}\n\\end{equation}\nThe set $\\Omega_p$ contains all neighboring points within the window that are centered at the image point $p$. The scalar $W_p$ denotes the normalization factor of the filter and $I_p$ represents the image intensity at the pixel position $p$. Please notice that the definition of the bilateral filter is given per pixel, i.e. gives an representation of the filtered pixel intensity. \\\\ \\\\\nThe bilateral filter is controlled by the two parameters $\\sigma_s$ and $\\sigma_r$. The range variance increases $\\sigma_r$, the BF becomes closer to the Gaussian blur filter. In other words, the larger $\\sigma_r$ the more weight a pixel with a large intensity deviation gets. However, when increasing the spatial variance $\\sigma_s$ results in smoothing larger features, i.e more distant pixels get a larger weight and thus influence the result more. Figure $\\ref{fig:bfilter_influence_sigmas}$ demonstrates the influence of these parameters.\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[width=0.6\\linewidth] {background/filtering/bilat_filter_sigmas}\n\\end{center}\n\\caption[Influence of $\\sigma_s$ and $\\sigma_r$]{Different filtering results produced by our bilateral filter implementation for varying $\\sigma_s$ and $\\sigma_r$ values.}\n\\label{fig:bfilter_influence_sigmas}\n\\end{figure}\n\n\\subsection{Harris Corner Detector}\n\\label{sec:harris_corner_detector}\nIn this section we explain the principles of the Harris corner detector $\\cite{Harris88acombined}$. Let us, therefore, consider a grayscale image $I$. We are going to sweep a window $w(x,y)$ (with displacements u in the x direction and v in the right direction) I and will calculate the variation of intensity. Since we are looking for windows with corners, we are looking for windows with a large variation in intensity. Hence, we have to maximize the equation above, specifically the term:\n\\begin{equation}\n\tE \\left( u, v \\right) = \\sum_{x,y} w \\left( x,y \\right) \\left[ I(x + u, y + v) - I(x, y) \\right]^2\n\\label{eq:var_intensitiy_def}\n\\end{equation}\nNext, the term $I(x + u, y + v)$ is expressed by the first order taylor series expansion as the follows:\n\\begin{equation}\n\tI(x + u, y + v) = I(x,y) + u I_x (x, y) + v I_y (x,y) + \\text{h.o.t}\n\\label{eq:taylor_exp_intensity}\n\\end{equation}\nNext, we put the first order approximation of Equation $\\ref{eq:taylor_exp_intensity}$ into Equation $\\ref{eq:var_intensitiy_def}$ to simplify the definition of $E$.\n\\begin{equation}\n\\begin{aligned}\nE \\left( u, v \\right) \n&= \\sum_{x,y} w \\left( x,y \\right) \\left[ I(x + u, y + v) - I(x, y) \\right]^2 \\\\\n&\\approx \\sum_{x,y} w \\left( x,y \\right) \\left[ I(x,y) + u I_x (x, y) + v I_y (x,y) - I(x, y) \\right]^2 \\\\\n&= \\sum_{x,y} w \\left( x,y \\right) \\left[ u I_x (x, y) + v I_y (x,y) \\right]^2 \\\\\n&= \\sum_{x,y} w \\left( x,y \\right) u^2 I_x^2 + 2 u v I_x I_y v^2 I_y^2 \\\\\n&= \\left( u,v \\right) \\left( \\sum_{x,y} w (x,y)\n\\begin{pmatrix}\nI_x^2 & I_x I_y \\\\\nI_x I_y & I_y^2 \\\\\n\\end{pmatrix}\n\\right) \\colvec{u}{v}\n\\end{aligned}\n\\label{eq:var_intensitiy_developed}\n\\end{equation}\nLet us define the following substitution\n\\begin{equation}\nM = \\sum_{x,y} w  (x,y)\n\\begin{pmatrix}\nI_x^2 & I_x I_y \\\\\nI_y^2 & I_x I_y \\\\\n\\end{pmatrix}\n\\label{eq:var_intensity_sub}\n\\end{equation}\nPutting the substitution from Equation $\\ref{eq:var_intensity_sub}$ into the final form of Equation $\\ref{eq:var_intensitiy_developed}$ we obtain the final form\n\\begin{equation}\n\tE \\left( u, v \\right) \\approx \\left( u,v \\right) M \\colvec{u}{v}\n\\end{equation}.\nA score is calculated for each window, to determine if it can possibly contain a corner:\n\\begin{equation}\n\\begin{aligned}\n& R = \\det(M) - \\kappa \\left(\\text{trace}(M)\\right)^2 \\\\\n&\\text{where } \\det(M) = \\lambda_1 \\lambda_2 \\text{ and } \\text{trace}(M) = \\lambda_1 + \\lambda_2\n\\end{aligned}\n\\label{eq:harris_response}\n\\end{equation}\n\n\\section{On Statistics}\n\\label{sec:on_statistics_bg}\n\n\\subsection{Conditional Probability}\nGiven two events $A$ and $B$ with the probability $P(B) > 0$. The conidtional probability of $A$ given $B$ is defined as\n\\begin{equation}\n\tP(A|B) = \\frac{P(A \\cap B)}{P(B)}\n\\label{eq:conditional_prob}\n\\end{equation}\nFurthermore, Equation $\\ref{eq:conditional_prob}$ gives us an alternative interpretation of the probability of an intersection\n\\begin{equation}\nP(A \\cap B) = P(A|B)P(B) \t\n\\end{equation}\nThe probability that two events happen the same time is the same as the Probability of the event A given B times the probability of event B. Sticking to this definition, we can visualize all possible outcomes of two events happening the same time as shown in Figure $\\ref{fig:prob_tree_diagram}$.\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[width=0.45\\linewidth] {background/statistics/probability_tree_diagram}\n\\end{center}\n\\caption[Probability Tree Diagram]{Tree liked representation$\\footnotemark$ of the four possible outcomes for a conditional probability.}\n\\label{fig:prob_tree_diagram}\n\\end{figure}\n\\footnotetext{The visualized graphic has been taken from: \\url{https://en.wikipedia.org/wiki/File:Probability_tree_diagram.svg}}\n\n\n\n\\subsection{Evaluating Binary Classifiers}\nIn this section we explain the mathematical framework we use in our evaluation.\n\n\nThe purpose of a binary classifier is to classify given elements into two groups according to a specified classification rule. Think about a binary random variable modelling a certain event. The actual observations of the random variable are then either equals true or false. A classification$\\footnote{I.e. the produced output after applying the classifier on the given data.}$ of a given dataset yields two numbers: the number of the positives and negatives, which add up to the size of the set. \\\\ \\\\\nIn order to evaluate the quality of binary classifier its prediction is compared against a standard reference method or, if existing, against a ground truth assignment and then cross tabulates the data into a $2 \\times 2$ contingency table as shown in Figure $\\ref{tab:prediction_sensitivity}$. \n\\begin{table}[H]\n\\centering\n\\begin{tabular}{c|c|c|}\n\\cline{2-3}\n & \\begin{tabular}[c]{@{}l@{}}Prediction\\\\ Positive\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}Prediction\\\\ Negative\\end{tabular} \\\\ \\hline\n\\multicolumn{1}{|l|}{\\begin{tabular}[c]{@{}l@{}}Condition\\\\ Positive\\end{tabular}} & \\cellcolor[HTML]{34FF34}{\\color[HTML]{000000} $\\bf{TP}$ } & \\cellcolor[HTML]{CB0000} $\\bf{FN}$ \\\\ \\hline\n\\multicolumn{1}{|l|}{\\begin{tabular}[c]{@{}l@{}}Condiation\\\\ Negative\\end{tabular}} & \\cellcolor[HTML]{CB0000}{\\color[HTML]{000000} $\\bf{FP}$ } & \\cellcolor[HTML]{34FF34} $\\bf{TN}$ \\\\ \\hline\n\\end{tabular}\n\\caption[Conditional Probability]{The four possible outcomes of a conditional probability}\n\\label{tab:prediction_sensitivity}\n\\end{table}\nThere are four possible outcomes: the classifier prediction, which has either are positive or negative condition, was actually correct or incorrect. \\\\ \\\\\nLet us consider the following example where we test some people for the presence of a disease. Some of these people have the disease, and the test correctly detects them. These findings are called true positives (\\textbf{TP}). Some have the disease, but the test incorrectly claims that they do not have it. These results are called false negatives (\\textbf{FN}). Some people do not suffer from the disease and the test classifies correctly as health. These results are called true negatives (\\textbf{TN}). And Lastly, some healthy people who are incorrectly classified as infected. These are the so called false positives (\\textbf{FP}) results. \\\\ \\\\\nThere are many metrics that can be used to measure the performance of a classifier. In the following a listing of some prominent metrics\n%\n\\begin{itemize}\n\\item \\textbf{Precision}: Tells us what proportion of patients we diagnosed as having the disease actually had that disease. In other words, proportion of TP in the set of positive disease diagnoses. This is given by the rightmost column in the confusion matrix.\n\\begin{equation}\n\t\\text{precision} = \\frac{\\text{TP}}{\\text{TP} + \\text{FP}}\n\\label{eq:def_precision}\n\\end{equation}\n\\item \\textbf{Recall}: Tells us what proportion of people that actually had the disease were diagnosed by the test as having the disease. In other words, proportion of TP in the set of true disease states. This is given by the bottom row in the confusion matrix.\n\\begin{equation}\n\t\\text{recall} = \\frac{\\text{TP}}{\\text{TP} + \\text{FN}}\n\\label{eq:def_recall}\n\\end{equation}\n\\end{itemize}\nA visualization of these measures is given in Figure $\\ref{fig:eval_concept_recall_precc}$.\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[width=0.6\\linewidth] {evaluation/prec_recall}\n\\end{center}\n\\caption[Concept Recall and Precision]{This figure illustrates graphically the concept of Recall (\\textbf{R}) and Precision (\\textbf{P}). When estimating the sampling of a binary random variable, there are basically four possible outcomes: The we predicted it being true and it is true (\\textbf{TP}), we predicted it true but it is false (\\textbf{FP}), we predicted it false and it was actually negative (\\textbf{FN}) or we predicted it to be true but it was actually false (\\textbf{TN}). }\n\\label{fig:eval_concept_recall_precc}\n\\end{figure}\nAn alternative measure is the $F_1$ score. This measure is often used in determining the performance of classification tasks in machine learning. To compute its score, this measure takes into account both, the precision and the recall of the test. The exact definition of the F1 measure is given in Equation $\\ref{eq:f1_score}$.\n\\begin{equation}\nF_1 = 2 \\left( \\frac{\\text{precision} \\times \\text{recall}}{\\text{precision} +\\text{recall}} \\right)\n\\label{eq:f1_score}\n\\end{equation}  \nThe F1 score can be interpreted as a normalized weighted average of the precision and recall measures. The best possible F1 score is equals 1 and its worst value is 0.\n\n\\section{Camera Model}\n\\subsection{Pinhole Camera}\n\\label{sec:pinhole_camera}\nA camera projects a 3d scene in a 2d image. A simple mathematical model to describe such a mapping from the 3d scene space to the 2d image space is the pinhole camera model. This model is conceptually illustrated in Figure $\\ref{fig:pinhole_camera_model}$.\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[width=0.8\\linewidth] {background/camera_model/pinhole_camera}\n\\end{center}\n\\caption[Pinhole Camera Model]{Visualizing the pinhole camera model. The camera center $C$ represents an infinitely small aperture hole and assumed to be located at $(0,0,0)$, $f$ is the focal length in pixel units, $p$ is the principal point in images coordinates, $\\textbf{A} = (X, Y, Z)$ a 3d point in the scene and $\\textbf{a} = (f \\frac{X}{Z}, f \\frac{Y}{Z})$ its projected pixel version mapped onto the image plane.}\n\\label{fig:pinhole_camera_model}\n\\end{figure}\nThe aperture is an infinitely small hole and there is no lens used to focus light. Therefore, lens distorting or depth of field effects are ignored. The intersection point where all rays meet is the center of the perspective projection and usually referred by \\textit{camera center}. The principal axis is formed by the line perpendicular to the image plane, which passes though the camera center. Its intersection point with the image plane is called principal point. The distance between the camera center and the principal point is the so called focal length.\n\n\\subsection{Camera Parameters}\n\\paragraph{Intrinsic Parameters} Let $\\textbf{X} = (X,Y,Z,1)^T$ denote a point in a 3D scene and $\\textbf{x} = (x,y,1)^T$ its projected version in the image plane. Both points are written in their homogeneous form. The mapping from a scene point to the image plane is defined as\n\\begin{equation}\n\\textbf{x} = \n\\begin{pmatrix}\nf & s & p_x & 0 \\\\\n0 & f & p_y & 0 \\\\\n0 & 0 & 1 & 0\n\\end{pmatrix}\n\\textbf{X}\n\\end{equation}\nwhere $f$ denotes the focal length and $p = (p_x, p_y)^T$ the offset to the origin in image coordinates with respect to the principal point. In modern cameras, the skew $s$ is usually equals zero. The parameters $f$, $p_x$, $p_y$ and $s$ are called \\textit{intrinsic camera parameters}. Notice, that $\\textbf{X}$ is expressed in terms of camera coordinates and similarly, $\\textbf{x}$ in pixel coordinates.\n\n\\paragraph{Extrinsic Parameters} In general, a camera is not located at the origin of the world coordinate system and can have an arbitrary orientation. Let $\\textbf{X}_w$ denote a point, living in an arbitrary camera coordinate system. To express this point in the regular camera coordinate system, we have to apply a certain transformation. In a rigid object model, the points $\\textbf{X}$ and $\\textbf{X}_w$ can be transformed to one another by applying a linear transformation that consists of a rotational matrix $R$ and a translation $t$. The actual mapping is defined as\n\\begin{equation}\n\tX = \\left[ R | t \\right] X_w\n\\end{equation}\nThe parameters $t$ and $R$ are called \\textit{extrinsic camera parameters}.\n\n", "meta": {"hexsha": "8f8f126e001746caf81b9de283decaa4840c9ad2", "size": 18220, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Document/Source/Chapters/appendix.tex", "max_stars_repo_name": "simplay/master_thesis", "max_stars_repo_head_hexsha": "d296c2befba97942765d87d40722105a26e4e97b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-04-18T05:17:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-11T04:28:28.000Z", "max_issues_repo_path": "Document/Source/Chapters/appendix.tex", "max_issues_repo_name": "simplay/master_thesis", "max_issues_repo_head_hexsha": "d296c2befba97942765d87d40722105a26e4e97b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-03-05T00:08:25.000Z", "max_issues_repo_issues_event_max_datetime": "2017-03-05T00:08:25.000Z", "max_forks_repo_path": "Document/Source/Chapters/appendix.tex", "max_forks_repo_name": "simplay/master_thesis", "max_forks_repo_head_hexsha": "d296c2befba97942765d87d40722105a26e4e97b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.7651821862, "max_line_length": 742, "alphanum_fraction": 0.7507135016, "num_tokens": 5106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245787544825, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.7115864882446216}}
{"text": "\\subsection{Projection algorithm}\n\\paragraph{}\nPoint projection algorithm is to find the nearest point in parameter $(u)$ on the NURBS curve of the test point.\nIn the proposed method, all points on the NURBS curve is generated based on the approximated polylines and hence are not exactly on the boundaries.\nAlthough there exists a closed form solution for point projection, it require the order of the NURBS curve must be less than $4$ \\citep{Pie1997}.\nAs a consequence, a projection algorithm \\citep{MA200379} using Newton-Raphson method is introduced to tackle this problem.\n\n\\paragraph{}\nFor a given point $P=(x,y)$, its projection on the curve $C(u$ so that the distance $|P-C(u)|$ is minimum is targeted.\nHowever, in the proposed method, the existence of the large number of the possible curves increase the computational cost significantly.\nThe projection point for the test point $P$ need to be determined for every existing curves and the one with the smallest minimum distance will be selected.\nOne possible improvement could be limit the possible curves to only a few by utilizing the fact that the NURBS curves has been divided into multiple sub-curves without interior knot by knot insertion introduced in Sec.~\\ref{lr_sec:nurbs_knot_ins}\nAnother property that can be utilized is that most of the test point $P$ is expected to be extremely close to its projection on the curve $C(u)$.\n\n\\paragraph{}\nAs a consequence, the strong convex hull property can be adopted to limit the number of possible curves to less than $2$.\nThe building of the convex hull is explained in detail in Sec.~\\ref{qdt_sc:convex_hull}.\nThe signed distance of the test point to all curves' convex hull is calculated and only the curves with negative signed distance which indicate that the point is in the convex hull will be selected as candidates.\nIf no negative distance is detected, a few number (taken as $3$ in the proposed method) of curves with minimum signed distance will be selected.\n\n\\paragraph{}\nIn order to find the projection of the test point $P$ on the curve $C$, target function $f$ can be expressed as\n\\begin{equation}\n    f(u) = \\mathbf{C}^\\prime (u) \\cdot (\\mathbf{C}(u) - \\mathbf{P})\n\\end{equation}\n%\nWhen $f(u)$ gives $0$, the point either located on the curve or the distance $|\\mathbf{C}(u) - \\mathbf{P}|$ is minimal.\nand two scalars $f$ and $g$ are defined as\n%\nThe iteration can be concluded as\n\\begin{equation}\n    u_{i+1} = u_i -\n    \\frac{ f(u_i) }{ f^\\prime(u_i) }\n\\label{qdt_eq:projection_iteration}\n\\end{equation}\nAfter one iteration is finished, the following criteria are checked in sequence.\n\\paragraph{1}\nIs the point coincide with $C(u_i)$\n\\begin{equation*}\n    |\\mathbf{C} (u_i) - \\mathbf{P}| \\leq \\epsilon_1\n\\end{equation*}\n%\nwhere $\\epsilon_1$ stands for the tolerance for distance in Euclidean space.\n\\paragraph{2}\nIs the cosine zero\n\\begin{equation*}\n    \\frac{\n        |\\mathbf{C}^\\prime (u) \\cdot (\\mathbf{C}(u) - \\mathbf{P})|\n    }{\n        |\\mathbf{C}^\\prime (u)|\n        |\\mathbf{C}(u) - \\mathbf{P}|\n    } \\leq \\epsilon_2\n\\end{equation*}\n%\nwhere $\\epsilon_2$ stands for the tolerance for cosine.\nIf either of these conditions are met, the iteration is terminated.\nOtherwise Eq.~\\ref{qdt_eq:projection_iteration} is performed to find the parameter $u_{i+1}$ for next iteration.\n\\paragraph{3}\nMake sure $u$ and $v$ are within there domains\n\\begin{equation*}\n    u_{i+1} \\in [a,b]\n\\end{equation*}\n%\nwhere $a$ and $b$ are the lower and upper bounds for the knot vector of curve $C$.\nIf the curve is open\n\\begin{equation}\n    \\left\\{\n        \\begin{array}{rl}\n            u_{i+1} = a & u_{i+1} < a \\\\\n            u_{i+1} = b & u_{i+1} > b\n        \\end{array}\n    \\right.\n\\end{equation}\n%\nIf the curve is closed\n\\begin{equation}\n    \\left\\{\n        \\begin{array}{rl}\n            u_{i+1} = b - ( a - u_{i+1} ) & u_{i+1} < a \\\\\n            u_{i+1} = a + ( u_{i+1} - b ) & u_{i+1} > b\n        \\end{array}\n    \\right.\n\\end{equation}\n%\n\\paragraph{4}\nThe difference between the new parameter $u_{i+1}$ and the old one $u_i$ is insignificant\n\\begin{equation*}\n    |\n        (u_{i+1} - u_i)\\mathbf{C}^\\prime(u_i)\n    |\n    \\leq \\epsilon_1\n\\end{equation*}\nThe iteration will be terminated if this condition is meet.\n\n\n\n\\subsection{Convex hull in 2D}\n\\label{qdt_sc:convex_hull}\n\\paragraph{}\nThe convex hull property of the NURBS curve indicates that all points on the curve must be contained within the convex hull constructed by its control points \\citep{SELIMOVIC2009772}\nThere are great number of algorithm that can be used including gift wrapping \\citep{Cormen:2009:IAT:1614191}, graham scan \\citep{ANDERSON197853}, quick hull \\citep{Barber:1996:QAC:235815.235821}, Chan's algorithm \\citep{Chan1996} and so on \\citep{doi:10.1137/0215021, ANDREW1979216}.\nThe quick hull is adopted in the proposed as it provides a computationally efficient and stable algorithm.\nThe algorithm utilize the idea of `` divide and conquer'' to build the convex hull with an expected time complexity of $O(nlog(n))$ and  $O(n^2)$ for the worst case.\nGenerally speaking, it works as expected in most of the situation except for the case of high symmetry or most of the points located at the circumference of a circle.\nThe algorithm can be implemented with following steps:\n\\begin{enumerate}\n    \\item Find the most left and right points (points with minimal and maximum $x$) since they are proved to be part of the convex hull.\n    \\item Connect these two points and use the line to separate other points into two group.\n    \\item Find the point with maximum distance to the line in step 2 in any group.\n    \\item Construct a triangle with two points in step 2 and the point in step 3.\n    \\item Eliminate all points contained by these two subsets in step 4.\n    \\item Repeat the previous three steps and the distance calculated in step 2 is determined as the point to the triangle instead of the line in step 1.\n    \\item Terminate the iteration when no points are left\n\\end{enumerate}", "meta": {"hexsha": "8fd134e9fd1b7395c6861dd64747896c34bed224", "size": 5984, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "quadtree/projection.tex", "max_stars_repo_name": "fa93hws/thesis", "max_stars_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-30T12:14:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-30T12:14:47.000Z", "max_issues_repo_path": "quadtree/projection.tex", "max_issues_repo_name": "fa93hws/thesis", "max_issues_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "quadtree/projection.tex", "max_forks_repo_name": "fa93hws/thesis", "max_forks_repo_head_hexsha": "c397ddc18e5ff5d6e9b8d6de2e53be4c9c7b7a2d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.4912280702, "max_line_length": 283, "alphanum_fraction": 0.7261029412, "num_tokens": 1646, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7114815852618667}}
{"text": "\\section*{Neural Networks}\n\\subsection*{Learning features}\nParameterize the feature maps and optimize over the parameters:\\\\\n$w^* = \\underset{w, \\theta}{\\operatorname{argmin}} \\sum_{i=1}^n l(y_i; \\sum_{j=1}^m w_j \\phi(x_i, \\theta_j))$\\\\\nOne possibility: $\\phi(x,\\theta) = \\varphi(\\theta^T x) = \\varphi(z)$\n\n\\subsection*{Activation functions}\nSigmoid: $\\varphi(z) = \\frac{1}{1+exp(-z)}$\\\\\nTanh: $\\varphi(z) = tanh(z) = \\frac{exp(z)-exp(-z)}{exp(z)+exp(-z)}$\\\\\nReLu:  $\\varphi(z) = max(z,0)$\n\n\\subsection*{Forward propagation}\nFor each unit $j$ on input layer, set value $v_j=x_j$\\\\\nFor each layer $l=1:L-1$: For each unit $j$ on layer $l$ set its value $v_j = \\varphi(\\sum_{i\\in Layer_{l-1}} w_{j,i}v_i)$ For each unit $j$ on output layer, set its value $f_j = \\sum_{i\\in Layer_{L-1}} w_{j,i}v_i$\\\\\nPredict $y_j = f_j$ for reg. / $y_j = sign(f_j)$ for class.\n\n\\subsection*{Backpropagation}\nFor each unit $j$ on the output layer:\\\\\n- Compute error signal: $\\delta_j = \\ell_j'(f_j)$\\\\\n- For each unit $i$ on layer $L$: $\\frac{\\partial}{\\partial w_{j,i}} = \\delta_j v_i$\n\nFor each unit $j$ on hidden layer $l=\\{L-1,...,1\\}$:\\\\\n- Error signal: $\\delta_j = \\varphi'(z_j) \\sum_{i\\in Layer_{l+1}} w_{i,j}\\delta_i$\\\\\n- For each unit $i$ on layer $l-1$: $\\frac{\\partial}{\\partial w_{j,i}} = \\delta_j v_i$\n\n\\subsection*{Learning with momentum}\n$a \\leftarrow m \\cdot a + \\eta_t \\nabla_W l(W;y,x)$; $W \\leftarrow W - a$", "meta": {"hexsha": "6cdc44132a049387fe5ebe7005a4464b700511eb", "size": 1406, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/NeuralNetworks.tex", "max_stars_repo_name": "meck93/intro_ml_ethz", "max_stars_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-04-24T14:58:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-19T14:02:08.000Z", "max_issues_repo_path": "source/NeuralNetworks.tex", "max_issues_repo_name": "meck93/intro_ml_ethz", "max_issues_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/NeuralNetworks.tex", "max_forks_repo_name": "meck93/intro_ml_ethz", "max_forks_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.0740740741, "max_line_length": 216, "alphanum_fraction": 0.6436699858, "num_tokens": 534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465044347828, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.7114719189276423}}
{"text": "\\documentclass{article}\n\n\\input{../../FrequentlyUsed/latex/mydefs}\n\\input{../../FrequentlyUsed/latex/mypackages}\n\n\\title{Yun Family Math Problems}\n\\author{Sunghee Yun}\n\n\n\\begin{document}\n\\maketitle\n\n\\section{Jisun's pizza problem (21-MAR-2020)}\n\nWhile we were chatting over \\href{https://zoom.us/}{Zoom} on 21-MAR-2020,\nJisun brought up the below problem:\n\\begin{quote}\nSuppose that you have a round pizza and an analog watch or clock.\nHow can you divide it into 11 (exactly) equal pieces?\n\\end{quote}\nThough this problem looked really interesting,\nI myself could not figure it out.\nTaehoon said you can erase the digit $12$,\nwhich was a very creative idea.\nHowever, nobody could give the correct question to it.\n\nOn 23-MAR-2020, Jisun asked again, ``Has anybody solved the pizza problem?'' over KakaoTalk.\nI googled it and found the following answer.\n\n\\begin{center}\n\\includegraphics[width=.7\\linewidth]{figures/pizze_cut_prob_answer_by_googling}\n\\end{center}\n\nAnd Jisun confirmed that that is the right answer.\n\nThen my tendency to want to prove things rigorously\nmade me have to spend my time on writing the below.\nHowever, I'm pretty sure that this will be helpful for my nephews (and niece),\nso this would definitely not waste of time. :) \n\n\nHere I want to write two different ways to see this, the first of which is kind of repeat what is written above.\n\n\\begin{proof}\n\\begin{enumerate}\n\\item\nOne way to prove this can go as follows.\n\nIf you position the hour hand (HH) and the minute hand (MH) at noon\nand let the watch operator as it usually does,\nthen the two hands do not meet until 1PM (the left clock in \\figurename~\\ref{fig:1})\nbecause the MH goes faster than the HH.\nNow if the time passes a bit more,\nthere comes a moment that the two hands meets exactly (the right clock in \\figurename~\\ref{fig:1}).\nNow mark this position (or angle) on the pizza.\nThen wait until the two hands meet again and mark that position, too.\nYou repeat this until the two meets again at midnight.\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=.7\\linewidth]{figures/pizza_HH_MH}\n\\end{center}\n\\caption{The locations of hour and minute hands at 1PM (left) and those when it meets the next time (right).}\n\\label{fig:1}\n\\end{figure}\n\nNow ask how many times the two hands have met after noon, \\ie,\nexclude noon.\nSince they met a bit after 1PM, then a more bit after 2PM, \\ldots,\nand after 11PM. When they met after 11PM is at midnight.\nThus, \\emph{they have met 11 times}.\n\nBecause you can insist that the time between two consecutive \\emph{rendezvious} of the two hands is the same for every time,\nthis divides $360$ degrees into 11 equal angles.\n\n\n\\item\nNow let us examine this quantitatively.\nLet $x$ be the angle between HH at midnight and HH when it meets MH next time as shown in \\figurename~\\ref{fig:2}.\nBecause HH goes to the position of $1$\nwhen MH does one rotation,\n\\ie, the speed of MH is $12$ times faster then HH,\nthe angle $y$ in \\figurename~\\ref{fig:2} is $12$ times smaller than $x$,\nor equivalently, $x$ is $12$ times larger than $y$.\nThen we have\n\\begin{equation}\n\\label{eq:1}\nx = 12 \\times y.\n\\end{equation}\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=.4\\linewidth]{figures/pizza_HH_MH_angles}\n\\end{center}\n\\caption{Pizza problem: $x$ refers to the angle between $12$ o'clock and where the minute hand meets the hour hand,\nand $y$ refers to the angle between $1$ o'clock and where the minute hand meets the hour hand.}\n\\label{fig:2}\n\\end{figure}\n\nNow we have two variables, $x$ and $y$, but only one equation. In this case, (in general) we cannot decide\nunique values for the variables.\nHowever, we have one more equation\nsince $x$ is equal to $y$ plus $360/12$.\nTherefore we have\n\\begin{equation}\n\\label{eq:2}\nx = y + \\frac{360}{12}\n\\Leftrightarrow\n12 \\times x = 12 \\times y + 360\n\\end{equation}\nWe obtained the right side equality\nby multiplying $12$ on both sides of the left equality in (\\ref{eq:2}).\nNow if you replace $12\\times y$ with $x$ in (\\ref{eq:1}),\nwe obtain\n\\begin{equation}\n12 \\times x = x + 360\n\\Leftrightarrow\n11 \\times x = 360\n\\Leftrightarrow\nx = 360/11.\n\\end{equation}\nTherefore our method \\emph{indeed} divides the pizza into $11$ equal-sized pieces.\n\\qed\n\nAn interesting observation is that this number $11$ comes from the calculation of $12 - 1$.\nThus, if half day were $13$ hours, the technique would give us $12$ pizza pieces,\nand, \\eg, if half day were $18$ hours, the technique would give us $17$ pizza pieces.\nIn general, if half day were $n$ hours, the technique would give us $n-1$ pizza pieces!\nThis type of generalization is a good practice to improve your math skills (\\emph{I} believe).\n\n\\end{enumerate}\n\n\\end{proof}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "07fad0a978f1d0f3a81436a931186f6ec4de9b5d", "size": 4693, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem_sovling/family_math_probs_Main.tex", "max_stars_repo_name": "sungheeyun/MathFoTaeHoon", "max_stars_repo_head_hexsha": "7271948c2a9653320dee2e5e46203c1d914f41fb", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-18T22:59:17.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-18T22:59:17.000Z", "max_issues_repo_path": "problem_sovling/family_math_probs_Main.tex", "max_issues_repo_name": "sungheeyun/MathForFamily", "max_issues_repo_head_hexsha": "7271948c2a9653320dee2e5e46203c1d914f41fb", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "problem_sovling/family_math_probs_Main.tex", "max_forks_repo_name": "sungheeyun/MathForFamily", "max_forks_repo_head_hexsha": "7271948c2a9653320dee2e5e46203c1d914f41fb", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.0072463768, "max_line_length": 124, "alphanum_fraction": 0.7466439378, "num_tokens": 1329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782011, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7113778475900523}}
{"text": "\\section{Theory}\n\nThe effect of any invariant linear system (LTI) on an arbitrary input  signal is\nobtained by convolution of the input signal  with  the system's impulse response\nfunction. In a LTI system, the  output  of the system $y(t)$ for an input $x(t)$\ncan be obtained by the convolution integral:\n\n\\begin{equation}\n    y(t)=g(t)*x(t)=\\int_0^t g(t-\\tau)x(\\tau)\\,d\\tau\n    \\label{eq:conv_int}\n\\end{equation}\n\nwhere $g(t)$ is the \\textit{impulse response}  of the system. That is, $g(t)$ is\nthe output of the system with an input $x(t)$ = $\\delta(t)$,  where  $\\delta(t)$\nis the Dirac delta. The impulse response completely  characterizes  the  dynamic\nbehaviour of the system.\n\nApplying   the   Laplace   transform  to  the  convolution  integral   (equation\n\\ref{eq:conv_int}) we obtain equation \\ref{eq:laplace}:\n\n\\begin{equation}\n    \\laplace[y(t)] = \\laplace[g(t) ∗ x(t)] = \\laplace[g(t)] \\laplace[x(t)]\n\\end{equation}\n\nor in simple expression:\n\n\\begin{equation}\n    Y(s) = G(s)X(s)\n    \\label{eq:laplace}\n\\end{equation}\n\nwhere $Y(s)$, $G(s)$ and $X(s)$ are the Laplace transforms of $y(t)$, $g(t)$ and\n$x(t)$ respectively. A Transfer Function (TF) is the mathematical representation\nof  the  relation between the input and output of a system. In a LTI system,  TF\ncan be  expressed  as  the  ratio of the Laplace transform of the output and the\ninput, and  corresponds to the Laplace transform of the impulse response $G(s)$.\n\n\\begin{equation}\n    G(s) = \\frac{Y(s)}{X(s)}\n\\end{equation}\n\nIn order  to  obtain  $G(s)$ from an unknown system, a signal in the form of the\nDirac delta function  must  be applied to the input of the system and its output\nmust  be  measured.  Unfortunately, it is very hard to do this in most practical\ncases, due to:\n\n\\begin{enumerate}\n    \\item Difficulty of generating a Dirac delta function (infinite amplitude, zero time).\n    \\item Any finite approximation of the Dirac delta function will cause an extremely small and hard to measure response signal.\n\\end{enumerate}\n\nA far more practical method is to measure the  \\textit{step response} instead. A\nstep function is easier to create in the physical world.  The  derivative of the\nresulting measured signal will  very  closely  resemble  its theoretical impulse\nresponse.\n\n\\input{sections/theory/model}\n\\input{sections/theory/characterisation_of_step_responses}\n\\input{sections/theory/approximating_step_response}\n\\input{sections/theory/least_squares}\n\n", "meta": {"hexsha": "4cb5196604a8538c99c43d977b8dcbdfe65d96e5", "size": 2450, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "versuche/mlab/sections/theory.tex", "max_stars_repo_name": "TheComet93/laborjournal", "max_stars_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "versuche/mlab/sections/theory.tex", "max_issues_repo_name": "TheComet93/laborjournal", "max_issues_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "versuche/mlab/sections/theory.tex", "max_forks_repo_name": "TheComet93/laborjournal", "max_forks_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.5161290323, "max_line_length": 129, "alphanum_fraction": 0.7314285714, "num_tokens": 689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.711377845645079}}
{"text": "\\documentclass{article}\n\n\\usepackage{mathrsfs,amssymb,yfonts}\n\n\\begin{document}\n\n\\section{Let $A$ be a commutative ring. Let $M$ be a module, and $N$ a submodule. Let $N=Q_1 \\cap ... \\cap Q_r$ be a primary decomposition of $N$. Let $\\bar{Q}_i = Q_i/N$. Show that $0 = \\bar{Q}_1 \\cap ... \\bar{Q}_r$ is a primary decomposition of $0$ in $M/N$. State and prove the converse.}\n\n1. Each $\\bar{Q_i}$  is primary\n\nGiven $a \\in A$, $a_{M/Q_i}$ is either injective or nilpotent, we must show that, given $a \\in A$, $a_{ (M/N) / ( Q_i / N)}$ is either injective or nilpotent.\n\nThe function $a_{M/Q_i}$ is a particular function from $M/Q_i$ to itself. Via the isomorphism $\\sigma: M/Q_i \\mapsto (M/N) / ( Q_i / N)$, define $\\hat{a}$ as a function from  $(M/N) / ( Q_i / N)$ to itself (Is just quoting the isomorphism theorem sufficient here?)\n\nSince they are both multiplication by $a$, $a_{ (M/N) / ( Q_i / N)}$ and $\\hat{a}$ are the same function on  $(M/N) / ( Q_i / N)$. Thus if $a_{M/Q_i}$ is injective (resp. nilpotent) then  $a_{ (M/N) / ( Q_i / N)}$ is injective (resp. nilpotent).\n\n\\noindent\n2. Their intersection is $0 = \\bar{Q}_1 \\cap ... \\cap \\bar{Q}_r$\n\nAssume this is false.\n\nTake element $a \\ne (0) \\in \\bar{Q}_1 \\cap ... \\cap \\bar{Q}_r$. (Better way to write this?) The pre-image of $a$ under the canonical homomorphism $M \\mapsto M/N$ is also not in $N$, since $N$ is exactly the kernel of this homomorphism. \n\nHowever it $a$ *is* in each $\\bar{Q}_i$ so its preimage has to be in $Q_i$, so has to be in $N$, a contradiction.\n\n\n\\noindent\n3. If 0 is primary decom, then N is primary decomp\n\nShowing that $Q_i$ is primary given that $\\bar{Q}_i$ is primary is identical to part 1 by following the isomorphism $ M / Q_i \\cong (M/N)/(Q_i/N)$ the other direction.\n\nThe proof that the intersection is N is also directly analogous to part 2, shown here:\n\nAssume it is false.\n\nTake some $x$ not in $N$ but in $N=Q_1 \\cap ... \\cap Q_r$. Under the canonical homomorphism the image of $x$ is in each of $\\bar{Q}$, thus is $0$. However this is a contradiction since the image of $x$ is non-zero.\n\n\n\\section{Let $\\mathfrak{p}$ be a prime ideal and $\\mathfrak{a}$, $\\mathfrak{b}$ be ideals of $A$. If $\\mathfrak{a b} \\subset \\mathfrak{p}$, show that $\\mathfrak{a} \\subset \\mathfrak{p}$ or $\\mathfrak{b} \\subset \\mathfrak{p}.$}\n\nIf $\\mathfrak{a} \\not\\subset \\mathfrak{p}$ and $\\mathfrak{b} \\not\\subset \\mathfrak{p}$, prove that $\\mathfrak{ab} \\not\\subset \\mathfrak{p}$\n\nPick $a$ in $\\mathfrak{a}$ and $b$ in $\\mathfrak{b}$ but not in $\\mathfrak{p}$. Since $\\mathfrak{p}$ is prime, $ab$ cannot be in $\\mathfrak{p}$.\n\n\n\\section{Let $\\mathfrak{q}$ be a primary ideal. Let $\\mathfrak{a}$, $\\mathfrak{b}$ be ideals, and assume $\\mathfrak{ab} \\subset \\mathfrak{q}$. Assume that $\\mathfrak{b}$ is finitely generated. Show that $\\mathfrak{a} \\subset  \\mathfrak{q}$ or there exists some positive integer $n$ such that $\\mathfrak{b}^n \\subset \\mathfrak{q}$.}\n\nAssume that $\\mathfrak{a} \\not\\subset \\mathfrak{q}$. We will show that this implies there there exists some positive integer $n$ such that $\\mathfrak{b}^n \\subset \\mathfrak{q}$. Take $a_0$ to be in $\\mathfrak{a}$ but not in $\\mathfrak{q}$. \n\nAn arbitrary element of $\\mathfrak{b}$, being finitely generated, looks like $k_1 b_1 + k_2 b_2 + ... + k_r b_r$ (where $k_i$ are positive integers and $r$ and $n$ are unrelated). For each $k_i b_i$, since $a_0 (k_i b_i)$ in $\\mathfrak{q}$ but $a_0$ is not and $\\mathfrak{q}$ is primary, $(k_i b_i)^{n_i} \\in \\mathfrak{q}$ for some finite $n_i$. Our goal is to find some $n$ large enough such that every term of $(k_1 b_1 + k_2 b_2 + ... + k_r b_r)^n$ is in $\\mathfrak{q}$, since, being additively closed, that would imply $b^n$ itself were in $\\mathfrak{q}$.\n\nTake $n=\\prod_{i=1}^{r} n_i$. Each term of $(k_1 b_1 + k_2 b_2 + ... + k_r b_r)^n$ is a homogenous monomial of degree $n$, thus in general looks like $\\prod_{i=1}^{r} (k_i b_i)^{m_i}$ where the $m_i$'s sum to $n$.\n\nIf any $m_i \\ge n_i$, then the term itself will be in $\\mathfrak{q}$, since $(k_i b_i)^{n_i}$ is in $\\mathfrak{q}$ as are its subsequent powers and anything multiplied by it, since ideals absorb multiplication. \n\nIt is impossible for all $m_i < n_i$, since then they would not fully sum to $n$, so therefore at least one is and the term is in $\\mathfrak{q}$. Since $r$ is finite, so too is $n$, thus proving the statement.\n\n\\section{Let $A$ be Noetherian and let $\\mathfrak{q}$ be a $\\mathfrak{p}-$primary ideal. Show that there exists some $n \\ge 1$ such that $\\mathfrak{p}^n \\subset \\mathfrak{q}$}\n\n$\\mathfrak{q}$ being $\\mathfrak{p}$-primary means that the radical of $\\mathfrak{q}$ is $\\mathfrak{p}$. Hence $\\sqrt{\\mathfrak{q}} = \\{r \\in A | r^n \\in \\mathfrak{q}\\} = \\mathfrak{p}$\n\nSince $A$ is Noetherian, $\\mathfrak{p}$ is finitely generated, so an arbitrarily element of $p$ is of the form $k_1 p1 + k_2 p_2 + ... + k_r p_r$, where $k_i$ and $r$ are positive integers. \n \nFor every $k_i p_i$, there's an $n_i$ such that $(k_i p_i)^{n_i}$ is in $\\mathfrak{q}$. For the same reasoning as 3) above, $n=\\prod_{i=1}^{r} n_i$ is such that this arbitrary $p$ is in $\\mathfrak{q}$.\n\n\\break\n\\break\n\n8. Let $A$ be a local ring. Show that any idempotent $\\ne 0$ in $A$ is necessary the unit element. \n\nWe have to show that $e * e = e \\Rightarrow e = 1$\n\nIf $e$ is a unit, we're done (Left multiplication by $e^{-1}$ shows $e = 1$).\n\nSo assume $e$ is not a unit. Then it must be in the maximal ideal $\\mathfrak{m}$ (otherwise it would generate a proper ideal not contained in $\\mathfrak{m}$). Not quite sure how to finish...\n\n\\end{document}", "meta": {"hexsha": "b996f2e37276dcdd83a6f9d085bf181025958c23", "size": 5592, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "algebra/10_Noetherian_Rings_And_Modules/3_primary_decomposition.tex", "max_stars_repo_name": "lukemassa/math-exercises", "max_stars_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "algebra/10_Noetherian_Rings_And_Modules/3_primary_decomposition.tex", "max_issues_repo_name": "lukemassa/math-exercises", "max_issues_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "algebra/10_Noetherian_Rings_And_Modules/3_primary_decomposition.tex", "max_forks_repo_name": "lukemassa/math-exercises", "max_forks_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 72.6233766234, "max_line_length": 559, "alphanum_fraction": 0.6707796853, "num_tokens": 1976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029117, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7113778428478486}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[portrait, margin=1in]{geometry}\n\\usepackage{cancel}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\begin{document}\n\n\\section{Introduction and simplification.}\n\nThis is the story of an infinite product integral that seems intimidating at first but is actually easier than it looks. Let's take a look:\n\n\\begin{equation}\n    \\int{ \\frac{1}{x} \\prod_{n=1}^{\\infty} \\left( 1-\\tan^2{\\frac{x}{2^n}} \\right) dx}\n\\end{equation}\n\nRecall some trig identities:\n\n\\begin{center}\n    $1-\\tan^2{(a)}=2-\\sec^2{(a)}=\\left(2\\cos^2{(a)}-1\\right)\\sec^2{(a)}= \\cos{(2a)}\\sec^2{(a)}$\n\\end{center}\n\nThis simplifies our integral to:\n\n\\begin{equation}\n\\rightarrow \\int{ \\frac{1}{x} \\prod_{n=1}^{\\infty} \\left( \\cos{\\left( \\frac{x}{2^{n-1}}\\right)} \\sec^2{\\left( \\frac{x}{2^n} \\right)}  \\right) dx}\n\\end{equation}\n\nUse this property of products: $\\prod_{n}{a_{n}^k}=\\left [ \\: \\prod_n{a_n} \\: \\right]^k$ to get:\n\n\\begin{equation}\n    \\rightarrow \\int{ \\frac{1}{x} \\prod_{n=1}^{\\infty}  \\cos{\\left( \\frac{x}{2^{n-1}}\\right)} \\left[ \\prod_{n=1}^{\\infty}\\sec{\\left( \\frac{x}{2^n} \\right)}  \\right]^2  dx}\n\\end{equation}\n\n\\section{Finding a way to simplify the infinite product.}\nWe seek to find the convergence of $\\cos{ \\left( \\frac{x}{2^{n-1}} \\right) }$ with respect to n:\n\n\\begin{equation}\n    \\lim_{k\\rightarrow \\infty} {\\prod_{n=1}^{k}} \\cos{\\left( \\frac{x}{2^{n-1}}\\right)}=\\cos{\\left(x\\right)}\\lim_{k\\rightarrow \\infty} \\prod_{n=1}^{k} \\cos{\\left( \\frac{x}{2^n}\\right)}\n\\end{equation}\n\n\nNow we need to recall this simple trig identity:\n\n\\begin{center}\n        $ \\sin{(2a)}=2\\sin{(a)}\\cos{(a)}\\rightarrow \\cos{(a)}=\\frac{\\sin{(2a)}}{2\\sin{(a)}}$\n\\end{center}\n\n\nRedefine the limit to get:\n\n\\begin{equation}\n    \\Rightarrow\\cos{\\left(x\\right)}\\lim_{k\\rightarrow \\infty} \\left [ \\frac{\\sin{\\left(x\\right)}}{2\\sin\\left(\\frac{x}{2}\\right)} \\cdot  \\frac{\\sin{\\left(\\frac{x}{2}\\right)}}{2\\sin\\left(\\frac{x}{2^2}\\right)} \\cdot \\frac{\\sin{\\left(\\frac{x}{2^2}\\right)}}{2\\sin\\left(\\frac{x}{2^3}\\right)} \\; ... \\; \\frac{\\sin{\\left(\\frac{x}{2^{k-1}}\\right)}}{2\\sin\\left(\\frac{x}{2^k}\\right)} \\right]\n\\end{equation}\n\nNow this is interesting, because we are looking at a telescoping series of product:\n\n\\begin{equation}\n    \\Rightarrow\\cos{\\left(x\\right)}\\lim_{k\\rightarrow \\infty} \\left [ \\frac{\\sin{\\left(x\\right)}}{2\\; \\cancel{\\sin\\left(\\frac{x}{2}\\right)}} \\cdot  \\frac{\\cancel{\\sin{\\left(\\frac{x}{2}\\right)}}}{2\\;\\cancel{\\sin\\left(\\frac{x}{2^2}\\right)}} \\cdot \\frac{\\cancel{\\sin{\\left(\\frac{x}{2^2}\\right)}}}{2\\; \\cancel{\\sin\\left(\\frac{x}{2^3}\\right)}} \\; ... \\; \\frac{\\cancel{\\sin{\\left(\\frac{x}{2^{k-1}}\\right)}}}{2\\sin\\left(\\frac{x}{2^k}\\right)} \\right]\n\\end{equation}\n\nSo our product series ends with this:\n\\begin{equation}\n    \\Rightarrow\\cos{\\left(x\\right)}\\lim_{k\\rightarrow \\infty} \\frac{\\sin{(x)}}{2^k\\sin{\\frac{x}{2^k}}}\n\\end{equation}\n\nUsing L'Hospital's rule to evaluate the limit:\n\n\\label{s}\n\\begin{equation}\n    \\Rightarrow\\cos{(x)}\\sin{(x)}\\lim_{k\\rightarrow \\infty} \\frac{\\frac{d}{dk}2^{-k}}{\\frac{d}{dk}\\sin{\\frac{x}{2^k}}}=\\cos{(x)}\\sin{(x)}\\lim_{k\\rightarrow \\infty} \\frac{\\cancel{-2^{-k}\\ln{(2)}}}{\\cancel{(-2^{-k}\\ln{2})}x \\cos{\\frac{x}{2^k}}}=\\boxed{\\frac{\\cos{(x)}\\sin{(x)}}{x}}\n\\end{equation}\n\n\\newpage\n\n\\section{The final stretch.}\n\nRecall our integral from before:\n\n\\begin{equation}\n    \\int{ \\frac{1}{x} \\prod_{n=1}^{\\infty}  \\cos{\\left( \\frac{x}{2^{n-1}}\\right)} \\left[ \\prod_{n=1}^{\\infty}\\sec{\\left( \\frac{x}{2^n} \\right)}  \\right]^2  dx}\n\\end{equation}\n\nUse the substitutions from before:\n\\begin{center}\n        $ \\prod_{n=1}^{\\infty}  \\cos{\\left( \\frac{x}{2^{n-1}}\\right)} = \\frac{\\sin{(x)}\\cos{(x)}}{x}$\n\\end{center}\n\nAnd similarly:\n\n\\begin{center}\n    $\\left[ \\prod_{n=1}^{\\infty}\\sec{\\left( \\frac{x}{2^n} \\right)}  \\right]^2 = \\frac{x^2}{\\sin^2{(x)}} $\n\\end{center}\n\nNow it can be rewritten as:\n\n\\begin{equation}\n        \\int \\frac{1}{\\cancel{x}} \\left[ \\frac{\\cos{(x)}\\;\\cancel{\\sin{(x)}}}{\\cancel{x}}\\cdot\\frac{\\cancel{x^{2}}}{\\sin^{\\cancel{2}}{x}} \\right] dx\n        =\\int{\\cot{(x)}}\\;dx = \\ln{\\left| \\sin{x}\\right|} + \\textsc{c}\n\\end{equation}\n\\newline\n\nPlot for $c = 0$:\n\n\\begin{center}\n    \\includegraphics{boi.jpg}\n\\end{center}\n\\end{document}\n", "meta": {"hexsha": "13088d98fef62d4e6beb3f45e4f0ccd9f49e9736", "size": 4214, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ProductIntegral.tex", "max_stars_repo_name": "techshot25/Math-doodles", "max_stars_repo_head_hexsha": "ef8e95eab9bccefe7d5a8c25653f054cb28637ae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-13T22:58:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-13T22:58:53.000Z", "max_issues_repo_path": "ProductIntegral.tex", "max_issues_repo_name": "techshot25/Math-doodles", "max_issues_repo_head_hexsha": "ef8e95eab9bccefe7d5a8c25653f054cb28637ae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ProductIntegral.tex", "max_forks_repo_name": "techshot25/Math-doodles", "max_forks_repo_head_hexsha": "ef8e95eab9bccefe7d5a8c25653f054cb28637ae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.6605504587, "max_line_length": 442, "alphanum_fraction": 0.6210251542, "num_tokens": 1629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741042, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.711334748396402}}
{"text": "\\graphicspath{{MDP/fig/}}\n\n\\chapter{Markov Decision Processes}\n\\label{chap:MDP}\n\\section{Introduction}\n\nIn order to describe reinforcement learning techniques, we first have to have a way of mathematically defining reinforcement learning problems. In this chapter, we do so by formally introduce the concept of Markov decision processes (MDPs). This chapter introduces the key concepts required to address the reinforcement learning problem. These concepts includes, state and action space, returns, value functions and Bellman equations.\nThe majority of the theory discussed in this chapter is based on the work by Sutton and Barto \\cite{sutton_barto}.\n\\section{Definition of a MDP}\nA Markov decision process is a stochastic, discrete, time controlled process. What this means is that a MDP is a partially controlled and partially random process \\cite{sutton_barto}.\nIn general RL problems can be described using MDPs \\cite{David_Silver}. \nPaul Weng states that, MDP's are described by the following: state-space S, action-space A, state transition probability $P^{a}_{ss'}$, reward function $R^{a}_{s}$ and discount factor $\\gamma$\\cite{MDP_Paul_Weng}. These variables can be denoted in a 5-tuple as\n\\begin{equation}\n\t(S,A,P^{a}_{ss'},R^{a}_{s},\\gamma)\n\\end{equation}\n where,\n\\begin{itemize}\n\t\\item S is a finite set of states with state s $\\in$ S\n\t\\item A is a finite set of actions with action a $\\in$ A\n\t\\item $P^{a}_{ss'}$ is a matrix of probabilities which predicts the next state s', where\\\\ $P^{a}_{ss'} = P(S_{t+1} = s' | S_t = s,A_t = a) $\n\t\\item $R^{a}_{s}$ is the immediate reward after transitioning from state s to s' using action a, where $R^{a}_{s} = E[R_{t+1}|S_t =s, A_t =a]$\n\t\\item $\\gamma$ $\\in$ [0,1] is the discount factor applied to the reward\n\\end{itemize}\nIn an MDP, the assumption is that all the states have the Markov property \\cite{sutton_barto}. This means that\n\\begin{equation}\n\tP[S_{t+1}|S_{t}] = P[S_{t+1}|S_{1},...,S_{t}].\n\\end{equation}\nIn other words, the probability of transitioning to state $S_{t+1}$ given state $S_t$, must be equal to the probability of transitioning to state $S_{t+1}$ given all states $S_1$ to $S_t$. This means that the current state is required to contain all the information of the previous states.\n\n\\section{Value function and policies}\nThe return $G_t$ is the total sum of the reward at each time step, multiplied by a constant diminishing factor $\\gamma$.\nThe discount $\\gamma$ $\\in$ [0,1] determines the present value of future reward $R_{t}$.\n\n\\begin{align}\n\tG_t &= R_{t+1}+\\gamma R_{t+2} +\\gamma^2 R_{t+3}+ ... \\nonumber\\\\\n\t&= \\sum_{k=0}^{\\infty}\\gamma^{k} R_{t+k+1}\n\t\\label{eq:G_t}\n\\end{align}\n\nFor $\\gamma=0$, the return $G_t$ only depends on the single reward that can be obtained in the next step, namely $R_{t+1}$. When $\\gamma=0$ the return $G_t$ is 'short-sighted'. For $\\gamma=1$ on the other hand, the return depends on all the rewards that are projected to be obtained until the process terminates. $G_t$ is thus \"far-sighted\" for $\\gamma=1$ \\cite{sutton_barto}.\nWhat can also note is that using a discount factor between 0 and 1 makes the return finite because $R_{t+k+1}$ is finite and\n\\begin{equation}\n\t\\sum_{k=0}^{\\infty}\\gamma^{k}=\\frac{1}{1-\\gamma}\\hspace{5pt},\n\\end{equation}\nwhich is finite for $\\gamma$ $\\in$ [0,1]. \\\\\nThe probability that the agent will choose a specific action given the state is called its policy $\\pi(a|s)$. Mathematically this is defined as\n\\begin{equation}\n\t\\pi(a|s) = P[A_t = a, S_t = s].\n\\end{equation}\nAnother important definition is the value function v(s) defined as\n\\begin{equation}\n\tv(s) = E[G_t | S_t = s].\n\\end{equation}\nThis equation shows that the value function v(s) is the expected return given that v(s) is evaluated in state s at time-step t.\n\\section{Bellman Expectation Equation}\nSutton and Barto \\cite{sutton_barto} decomposes v(s) so that it becomes a recursive function as follows\n\\begin{align}\n\tv(s) &= E[G_t | S_t = s]\\\\\n\t&= E[R_{t+1} + \\gamma R_{t+2} + \\gamma^{2} R_{t+3} + ...|S_t = s]\\\\\n\t&= E[R_{t+1} + \\gamma (R_{t+2} + \\gamma R_{t+3} + ...)|S_t = s]\\\\\n\t&= E[R_{t+1} + \\gamma G_{t+1}|S_t = s]\\\\\n\t&= E[R_{t+1} + \\gamma v(S_{t+1})|S_t = s].\n\t\\label{bellmanv1}\n\\end{align}\nThis means that v(s) only depends on $R_{t+1}$ (the reward that can be obtained in the next step) and $\\gamma v(S_{t+1})$, the discounted value function at time t+1.\nWhat has been defined in equation \\ref{bellmanv1} is known as the Bellman equation.\\cite{sutton_barto}\nSutton and Barto then defines the value function given that the agent follows the policy $\\pi$ as\n\\begin{equation}\n\tv_{\\pi}(s) = E_{\\pi}[G_t | S_t = s].\n\\end{equation}\nAdditionally, they define the action-value function (q-function),\n\\begin{equation}\n\tq_{\\pi}(s,a) = E_{\\pi}[G_t | S_t = s,A_t = a].\n\\end{equation}\nThe q-function is defined as the expected return of taking action a from state s and thereafter following policy $\\pi$. What can be noted is that v(s) is a prediction of what the value for being in a certain state is, which is related to planning. While q(s,a) is the value for being in a certain state and taking an action, which relates to control. \n\nOnce again, Sutton and Barto \\cite{sutton_barto} decomposes the state-value and action-value functions to be in the form of the Bellman Equation in equation \\ref{bellmanv1}. This results in the Bellman \\textit{expectation} equations\n\\begin{align}\n\tv_{\\pi}(s)\t&= E_{\\pi}[R_{t+1} + \\gamma v_{\\pi}(S_{t+1})|S_t = s]\\\\\n\t&= \\sum_{a'\\in A}\\pi(a|s)(R^{a}_s+\\gamma\\sum_{s'\\in S}P^{a}_{ss'}v_\\pi(s'))\n\t\\label{bellmanv2}\n\\end{align}\nand\n\\begin{align}\n\tq_{\\pi}(s,a)\t&= E_{\\pi}[R_{t+1} + \\gamma q_{\\pi}(S_{t+1},A_{t+1})|S_t = s,A_t = a]\\\\\n\t&= R^{a}_s +\\gamma \\sum_{s'\\in S}P^{a}_{ss'}\\sum_{a'\\in A}\\pi(a'|s')q_\\pi(s',a').\n\t\\label{bellmanq}\n\\end{align}\nEquation \\ref{bellmanv2} can be placed into vector form as:\n\\begin{equation}\n\tv_\\pi = R^{\\pi} + \\gamma P^{\\pi}v_\\pi\n\\end{equation}\nWhich has the solution:\n\\begin{equation}\n\tv_\\pi = (I - \\gamma P^{\\pi})^{-1}R^{\\pi}\n\t\\label{bellman_matrix_form}\n\\end{equation}\nEquation \\ref{bellman_matrix_form} is a concise formula which is easily implemented in code.\n\n\\section{Optimal Policies and Bellman Optimality Equations}\nSutton and Barto now defines the optimal policy, which only has value 1 if the action the agent takes maximizes $q_*(s,a)$ \\cite{sutton_barto}.\nThis is mathematically defined as:\n\\begin{align}\n\t\\pi_{*}(a|s)=\\begin{cases}\n\t\t1, & \\text{if a = $\\argmax\\limits_{a \\in A}q_* (s,a)$}\\\\\n\t\t0, & \\text{otherwise}\n\t\\end{cases}\n\t\\label{eq:pi_*}\n\\end{align}\nThere always exists an optimal deterministic policy for any MDP \\cite{sutton_barto}. We only need to know $q_* (s,a)$ to know the optimal policy. This is important because the optimal policy describes which actions must be taken to maximize rewards, which is precisely the goal of RL.\nSutton and Barto \\cite{sutton_barto} then defines what is know as the Bellman \\textit{optimality} equations.\n\\begin{equation}\n\tv_*(s) = \\max\\limits_{a}(R^{a}_s+\\gamma\\sum_{s'\\in S}P^{a}_{ss'}v_*(s'))\n\t\\label{bellmanv*}\n\\end{equation}\nand\n\\begin{equation}\n\tq_*(s,a) = R^{a}_s +\\gamma \\sum_{s'\\in S}P^{a}_{ss'}\\max\\limits_{a'}q_*(s',a').\n\t\\label{bellmanq*}\n\\end{equation}\nWhat equation \\ref{bellmanv*} represents is the maximum return that can be obtained from state s, when following the optimal policy $\\pi_*$. Equation \\ref{bellmanq*} represents the maximum return that can be obtained by taking action a state s and thereafter following the policy.\nAt this point, we have outlined a mathematical background for reinforcement learning problems.\nIn the next two chapters we will discuss methods of solving the MDP and obtaining the optimal state-value and action-value functions. \n\n", "meta": {"hexsha": "e698c53a8fc1d8e98ff5ced5b7a61c13d8561fd9", "size": 7709, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/MDP/MDP.tex", "max_stars_repo_name": "umr-bot/sliding-puzzle-solver-bot", "max_stars_repo_head_hexsha": "826532a426f343bcc66034b241a42b3bd864e07c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/MDP/MDP.tex", "max_issues_repo_name": "umr-bot/sliding-puzzle-solver-bot", "max_issues_repo_head_hexsha": "826532a426f343bcc66034b241a42b3bd864e07c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/MDP/MDP.tex", "max_forks_repo_name": "umr-bot/sliding-puzzle-solver-bot", "max_forks_repo_head_hexsha": "826532a426f343bcc66034b241a42b3bd864e07c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.672, "max_line_length": 434, "alphanum_fraction": 0.7155273057, "num_tokens": 2411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741042, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7113347466065667}}
{"text": "% Twentyfold Way\n\\section{Distributions: The Twentyfold Way}\n\\label{twentyfoldway}\n\nThese notes (in particular)\t need review. There is a deeper perspective on distributions that is constructed in terms of functions and equivalence classes, which is poorly developed here so far, and I think there are some errors too. The different \"interpretations\" are also not well-developed here.\n\nThe twentyfold way is a taxonomy of distribution problems developed by Kenneth Bogard in his book \\textit{Combinatorics through Guided Discovery} \\cite{bogart2004combinatorics}. It divides up the way in which $k$ objects may be assigned to $n$ individuals, subject to whether the objects are distinct or identical, and subject to conditions on how the objects are received.\n\n\n\\begin{quote}\n\\textit{When we are passing out objects to recipients, we may think of the objects as being either identical or distinct. We may also think of the recipients as being either identical (as in the case of putting fruit into plastic bags in the grocery store) or distinct (as in the case of passing fruit out to children). We may restrict the distributions to those that give at least one object to each recipient, or those that give exactly one object to each recipient, or those that give at most one object to each recipient, or we may have no such restrictions. If the objects are distinct, it may be that the order in which the objects are received is relevant (think about putting books onto the shelves in a bookcase) or that the order in which the objects are received is irrelevant (think about dropping a handful of candy into a child’s trick or treat bag). If we ignore the possibility that the order in which objects are received matters, we have created $2\\times2\\times4 = 16$ distribution problems. In the cases where a recipient can receive more than one distinct object, we also have four more problems when the order objects are received matters. Thus we have 20 possible distribution problems.} - Bogart, \\textit{Combinatorics Though Guided Discovery}, Chapter 3.\n\\end{quote}\n\n\nWhat I like about this approach is that the challenge with most of the basic combinatorics problems is to figure out the right way of counting. For this reason, the idea of having a unified handbook-like taxonomy is very appealing. The weakness (in my opinion) is that the language of \"objects\" and \"recipients\" is unclear because in practice it's not obvious which is which: if there are $k$ students and $n$ teachers, do the teachers receive students, or do the students receive a teacher? \n\nA way to resolve this is to say that an object can have only one recipient, but that a recipient might receive more than one object. A more formal path is to think of the act of creating combinations in terms of functions. \n\n\\begin{itemize}\n\\item The elements of the domain are the objects. \n\\item The elements of the range are the recipients. \n\\item A function can be many-to-one, but it should not be one-to-many. \n\\end{itemize}\n\n\\subparagraph{Favorite Teachers} At a school with $k$ students and $n$ teachers, the students all have a favorite teacher. (They might all like the same one.). How many ways are there for all of the $k$ students to pick a favorite? \n\n\\textit{Objects:} $k$ students. \\textit{Recipients:} $n$ teachers. Many students might have one favorite teacher. There are $n^k$ combinations. \n\n\\subparagraph{Assembling a Team} Out of a choice of $n$ athletes, a coach must assemble a team of $k$. How many ways are there to form a team? \n\n\\textit{Objects:} n athletes. \\textit{Recipients:} team, not on the team. Many athletes can be assigned to one outcome of being on the team or not being on the team. There are ${n \\choose k}$ combinations for the team, which is the same number as the ${n \\choose n-k}$ selections for the bench. \n\n\n\n\\begin{figure}\n  \\caption{Bogart's Twentyfold Way}\n  \\centering\n    \\includegraphics[width=0.5\\textwidth]{twentyfoldway.png}\n\\end{figure}\n\n\n\n% Distinct Objects, No Conditions\n\\subsection{Distinct Objects}\n\n\n%% Distinct Recipients\n\\subsubsection{Distinct Recipients}\nThe $k$ objects are assigned to $n$ recipients with no conditions as to the number of objects each recipient receives. This is the same as assigning the elements of a $k$-tuple from a selection of $n$ \\underline{with} replacement.\n\n\\begin{equation}\t\n\\begin{array}{l}\nS = \\{ (a_1,a_2,...,a_k) | a_i \\in A, |A| = n \\}\\\\\n\\\\\n|S| = n^k\n\\end{array}\n\\end{equation}\n\n\n\n\\subparagraph{Pool Balls into Labeled Buckets} All possible ways to put $k$ pool balls, which all have different numbers and colors, into $n$ labeled buckets. Some of the buckets might be empty, and others might contain more than one of the pool balls.\n\n\\subparagraph{Functions} All possible functions $f:x \\rightarrow y$ with $\\{x | x\\in A, |A| = k \\}$ and $\\{y | y\\in B, |B| = n\\}$.\n\n\\subparagraph{Binary Strings of Length $k$} The $k$ distinct positions of a binary string $(i_1,i_2,...,i_k)$ of length $k$ are assigned to an element of the set $A\\in[0,1]$. The number of possible binary strings of length $k$ is $2^k$.\n\n\\subparagraph{Subsets of a $k$-Element Set} The subsets of a set of $k$ distinct elements are formed by assigning each of its $k$ distinguishable elements to one of the two labels $A\\in [\\mathrm{included},\\mathrm{excluded}]$. The number of possible subsets, including the empty subset and the full set, is $2^k$.\n\n\n%% Indistinct Recipients\n\\subsubsection{Indistinct Recipients}\nThe $k$ objects are assigned to a recipient that is not distinct. \n\n\\begin{equation}\n|A| = \\sum_{i=1}^k S(n,i)\n\\end{equation}\n\nWhere $S(k,n)$ is the Stirling number of the second kind that gives the number of ways that $k$ objects can be distributed across $n$ non-empty indistinct sets. The sum above takes care of the case where the $k$ objects are divided into \\underline{up to} $n$ collections.  \n\nA closed form expression for the Stirling Numbers of the second kind is (c.f. section \\ref{sec:stirling2}): \n\n\\begin{equation}\nS(k,n) = \\left\\{ \\begin{array}{c} k \\\\n \\end{array} \\right\\} = \\frac{1}{n!}\\sum_{j=0}^n (-1)^{n-j} {n \\choose j }j^k\n\\label{eq:stirling2}\n\\end{equation}\n\n\n\\subparagraph{Pool Balls into Unlabeled Bags} All possible ways to put $k$ pool balls, which all have different numbers and colors, into $n$ unlabeled bags. Some of the bags might be empty, and others might contain more than one of the pool balls.\n\n\n% Distinct Objects, At Most One\n\\subsection{Distinct Objects, Every Recipient Receives At Most One}\n\n%% Distinct Recipients\n\\subsubsection{Distinct Recipients}\nAt most one of $k$ distinct objects are assigned to one of $n$ distinct recipients. This is the same as assigning the elements of a $k$-tuple from a selection of $n$ \\underline{without} replacement, so that first there are $n$ choices, then $n-1$ choices, $n-2$, etc.\n\n\\begin{equation}\t\n\\begin{array}{l}\nS = \\{ (a_1,a_2,...,a_k) | a_i \\in A, |A| = n, a_i\\neq a_j\\}\\\\\n\\\\\n|S| = \\frac{n!}{(n-k)!} = n^{\\underline{k}}\\ \\ \\mathrm{if\\ }k\\leq n,\\ 0\\ \\mathrm{otherwise.}\n\\end{array}\n\\end{equation}\n\n\\subparagraph{At Most One Pool Ball into Labeled Buckets} All possible ways to put $k$ pool balls, which all have different numbers and colors, into $n$ labeled buckets, but the buckets can have at most one pool ball in them. In other words, you choose any $k$ out of the $n$ labeled buckets and put one pool ball into them. \n\n\\subparagraph{One-to-One Functions} All possible functions $f:x \\rightarrow y$ with $\\{x | x\\in A, |A| = k \\}$ and $\\{y | y\\in B, |B| = n\\}$ subject to the constraint that $f(a) = f(b)$ implies $a=b$. That is, the functions are one-to-one, or injective.\n\n\\subparagraph{k-element Permutations of $n$ elements}  Each of the $k$ positions in a $k$-element permutation are distinct objects. These are each assigned to one of $n$ possible values, where each value can only show up once. \n\n\\subparagraph{Books on a Shelf} How many ways are there to order $k$ books on a library shelf when there are $n$ different books available. \n\n\n%% Indistinct Recipients\n\\subsubsection{Indistinct Recipients}\nAt most one of $k$ distinct objects are assigned to one of $n$ indistinct recipients. This is the same as assigning the elements of a $k$-tuple from a selection of $n$ \\underline{without} replacement. Except ,since the recipients are all indistinct, there is only one type of choice of recipient for each object. Either each object finds a recipient if $k\\leq n$, or it is impossible to distribute at most one object to each recipient because $n < k$.\n\n\\begin{equation}\n\\begin{array}{l}\nS = \\{ (a_1,a_2,...,a_k) | a_i \\in A, |A| = n, a_i=a_j\\}\\\\\n\\\\\n|S| = 1\\ \\ \\mathrm{if\\ }k\\leq n,\\ 0\\ \\mathrm{otherwise.}\n\\end{array}\n\\end{equation}\n\n\n\n\\subparagraph{At Most One Pool Ball into Unlabeled Bags} All possible ways to put $k$ pool balls, which all have different numbers and colors, into $n$ unlabeled bags, but the bags can have at most one pool ball in them. The bags are identical, so the only result is one where there are $k$ bags with a ball in them and $n-k$ without a ball in them. If there are not enough bags, then there is no possible result. \n\n\\subparagraph{Distributing Candy} There are $n$ pieces of identical candy and $k$ kids. How many ways are there to give each kid a piece of candy? If there is enough candy, the answer is one. Everyone gets candy. If there is not enough candy then the answer is zero. There is no way to give everyone candy if there's not enough candy.\n\n\n% Distinct Objects, At Least One\n\\subsection{Distinct Objects, Every Recipient Receives at Least One}\n\n%% Distinct Recipients\n\\subsubsection{Distinct Recipients}\n\n\\begin{equation}\n|A| = n!S(k,n) =n! \\left\\{ \\begin{array}{c} k \\\\n \\end{array}\\right\\} = n! \\frac{1}{n!}\\sum_{j=0}^n (-1)^{n-j} {n \\choose j }j^k\\end{equation}\n\nWhere $S(k,n)$\t denotes the Stirling function of the second kind.\n\n\n\\subparagraph{At Least One Pool Ball into Labeled Buckets} All possible ways to put $k$ pool balls, which all have different numbers and colors, into $n$ labeled buckets, so that all of the buckets have at least one ball in them. This is the same number of combinations as if the buckets were unlabeled, but multiplied with $n!$ ways of applying a label to them.\n\n\\subparagraph{Onto Functions} All possible functions $f:x \\rightarrow y$ with $\\{x | x\\in A, |A| = k \\}$ and $\\{y | y\\in B, |B| = n\\}$ subject to the constraint that there is an element $x$ in the domain so that $f(x)=y$ for each element $y$ of the codomain. That is the functions are onto, or surjective.\n\n\n%% Indistinct Recipients\n\\subsubsection{Indistinct Recipients}\nThe number of ways to divide $k$ distinct objects into $n$ non-empty subets is given by the Stirling number of the second kind (c.f. section \\ref{sec:stirling2}):\n\n\\begin{equation}\n|A| = S(k,n) = \\left\\{ \\begin{array}{c} k \\\\n \\end{array} \\right\\} = \\frac{1}{n!}\\sum_{j=0}^n (-1)^{n-j} {n \\choose j }j^k\t\\end{equation}\n\n\n\n\\subparagraph{At Least One Pool Ball into Unlabeled Bags} All possible ways to put $k$ pool balls, which all have different numbers and colors, into $n$ unlabeled bags, so that none of the bags are empty. \n\n\n% Distinct Objects, Everyone received exactly one\n\\subsection{Distinct Objects, Every Recipient Receives Exactly One}\n\n% distinct recipients\n\\subsubsection{Distinct Recipients}\nOne of $k$ distinct objects are assigned to each of $n$ distinct recipients. This is the same as assigning the elements of a $k$-tuple from a selection of $n$ \\underline{without} replacement and with the requirement that all of the $n$ are selected.\n\n\\begin{equation}\t\n\\begin{array}{l}\nS = \\{ (a_1,a_2,...,a_k) | a_i \\in A, |A| = k = n, a_i\\neq a_j\\}\\\\\n\\\\\n|S| = n! = k!\\ \\ \\mathrm{if\\ }k=n,\\ 0\\ \\mathrm{otherwise.}\n\\end{array}\n\\end{equation}\n\n\\subparagraph{Exactly One Pool Ball into Each Labeled Buckets} All possible ways to put $k$ pool balls, which all have different numbers and colors, into $n$ labeled buckets, that there is one pool ball in each bucket. This is the same as putting one pool ball into unlabeled buckets and multiplying by the $n!$ ways of attaching a label to the buckets. If there isn't the same amount of balls and buckets then there is no possible way for them to be matched one-for-one.\n\n\\subparagraph{Bijective Functions} All possible functions $f:x \\rightarrow y$ with $\\{x | x\\in A, |A| = k \\}$ and $\\{y | y\\in B, |B| = n\\}$ subject to the constraints that $f(a) = f(b)$ implies $a=b$ and that there is an element $x$ in the domain so that $f(x)=y$ for each element $y$ of the codomain. That is, the functions are one-to-one and onto, of bijective.\n\n\\subparagraph{Permutations} Since each of the $k$ objects is given to a different one of the $n$ recipients, there must be as many recipients as there are objects and $k=n$. The number of ways of assigning $k$ objects to $n$ recipients is $k!=n!$.\n\n\\subparagraph{Unique Identifiers} Each of $k$ entries in a database is given one of $n=k$ unique identifiers, so that each identifier leads to an entry and each entry has an identifier. \n\n% indistinct recipients\n\\subsubsection{Indistinct Recipients}\n\n\\begin{equation}\t\n\\begin{array}{l}\nS = \\{ (a_1,a_2,...,a_k) | a_i \\in A, |A| = k, a_i=a_j\\}\\\\\n\\\\\n|S| = 1\\ \\ \\mathrm{if\\ }k = n,\\ 0\\ \\mathrm{otherwise.}\n\\end{array}\n\\end{equation}\n\n\n\\subparagraph{Exactly One Pool Ball into Each Unlabeled Bag} All possible ways to put $k$ pool balls, which all have different numbers and colors, into $n$ unlabeled bags, that there is one pool ball in each bag. The result is that you either have $n$ bags with $n=k$ balls in them, if the two have matching numbers, or that you either have a bag or a ball left over and there is no way to match them one-for-one.\n\n\\subparagraph{Distribute without Leftovers} $k$ students are assigned to $n$ identical textbooks. How many ways are there for each child to have a textbook so that there are no textbooks left over? \n\n\n% Distinct Objects, Ordered Groups\n\\subsection{Distinct Objects, Distributed in Ordered Groups}\n\n%% Distinct Recipients\n\\subsubsection{Distinct Recipients}\n$k$ objects are distributed to $n$ different recipients with an internal ordering, so that each recipient receives an ordered list. This is the same as creating a list of $n$ sequences that are sampled from $k$ \\underline{without replacement}. \n\n\\begin{equation}\n\\begin{array}{l}\nS = \\{ (\\mathbf{a}_{\\{i_1\\}}  = ( a_{i_{1,1}},a_{i_{1,1}},...,a_{i_{1,l}} ),\\mathbf{a}_{\\{i_2\\}},...,\\mathbf{a}_{\\{i_n\\}}) | \\sum^n_j |\\mathbf{a}_{i_j}| = k, a_{i_{j,i}} \\in A, |A| = n \\} \\\\\n\\\\\n|S| = \\frac{(k + n - 1)!}{(n-1)!} = ( k+n-1)^{\\underline{k}} = k! {k+n-1 \\choose k}\n\\end{array}\n\\end{equation}\n\n\n\\subparagraph{Books on Labeled Bookshelves} $k$ books are distributed across $n$ different bookshelves. The books may all be on the same shelf, or shelves may be empty. The ordering of the books on each of the shelves matters. This is the same as taking all the $k!$ permutations of the $k$ books and multiplying it by the way of dividing that permutation up onto $n$ shelves. \n\n\\subparagraph{Ordered Functions}  All functions $f: x \\rightarrow y$ with $\\{x | x\\in A, |A| = k \\}$ and $\\{y | y\\in B, |B| = n\\}$ that assign ordered sequences of elements in $x$ to elements of $y$.\n\n%% Indistinct Recipients\n\\subsubsection{Indistinct Recipients}\n$k$ objects are broken up into $n$ \n\n\\begin{equation}\n|S| = \\sum_{i=1}^n L(k,i) \n\\end{equation}\n\nwhere $L(k,n)$ are the Lah numbers, which describe \"How many ways can $k$ objects be distributed to $n$ recipients if order matters and each recipient receives at least 1\". They are given by:\n\n\\begin{equation}\nL(k,n)= {k \\choose n} (k-1)^{\\underline{k-n}} = \\frac{k!}{n!}{ k-1 \\choose n-1 }\n\\end{equation}\n\nThe sum considers the case where all $k$ objects are given to $i\\leq n$ recipients, with the remaining recipients receiving none. Note that the expression is more complicated than simply dividing the case for indistinct recipients by $n!$, because more than one of the recipients might receive the same number of objects, in which case i.e. the distribution $[(0),(0),(1,2)]$ would be counted twice. The expression is analogous to the expression for distinct objects distributed to indistinct recipients, but where the objects did not have an internal ordering. In that case, instead of a sum over the Lah numbers, the sum is over the Stirling numbers of the second kind. \n\nThe Lah numbers can be derived by imagining that first one of the $k$ distinct objects is distributed to the $n$ indistinct recipients, to make sure that each recipient receives at least one, and then adding the remaining objects to the first without restrictions. After the first $n$ distinct objects have been distributed to the recipients, the recipients are no longer indistinct, because they each have been labeled by the object they have already received. There are ${k \\choose n}$ ways of distributing the first $n$ objects and $(k-n)!{k-n+n-1 \\choose k-n}$ ways to add the $k-n$ remaining objects.\n\n\\subparagraph{Books into Unlabeled Boxes} $k$ books are stacked into up to $n$ different unlabeled boxes. Some of the boxes may be empty, and others may contain more than one book. The sequence in which the books are stacked in each box matters. If there are $n-r$ empty boxes and $r$ boxes that have at least one book in them, then there are ${k \\choose r}$ ways of putting the first book in each of the boxes. Then there are $(k-r)!{k-r+r-1 \\choose k-n}$ ways to stack the remaining books on top of those first books. \n\n\\subparagraph{Broken Permutations $\\leq n$ Parts} The permutations of $k$ distinct elements are ordered sequences of length $k$. If the sequence is cut up into \\underline{up to} $n$ different parts of non-zero length, then what results are \\textit{broken permutations}.\n\n\\subparagraph{Books into Boxes} $k$ different books are put into $n$ identical boxes. How many ways are there to pack the boxes if you keep track of the order in which the books in each box are stacked? \n\n\n% Distinct Objects, Distributed in Ordered Groups of At Least One\n\\subsection{Distinct Objects, Distributed in Ordered Groups of At Least One}\n\n% Distinct Recipients\n\\subsubsection{Distinct Recipients}\n\n\\begin{equation}\n|S| = \\frac{k!}{(k-n)!}\\frac{(k-1)!}{(n-1)!} = k^{\\underline{n}} (k-1)^{\\underline{k-n}}\n\\end{equation}\n\n\\subparagraph{Books on Labeled Bookshelves} $k$ books are distributed across $n$ different labeled bookshelves. There is at least one book on each shelf. This is the same as picking $n$ books to go on the shelves first, so that all of the shelves have at least one book on them, and then distributing the remainder without restrictions. There are $k^{\\underline{n}}$ ways of picking the first $n$ books for each of the $n$ shelves, and $(k-n+n-1)^{\\underline{k-n}}$ ways to add the remaining $k-n$ books. \n\n\\subparagraph{Ordered Onto Functions} All functions $f: x \\rightarrow y$ with $\\{x | x\\in A, |A| = k \\}$ and $\\{y | y\\in B, |B| = n\\}$ that assign ordered sequences of elements in $x$ to elements of $y$, where every element $y\\in B$ has an assignment of at least one element.\n\n%% Indistinct Recipients\n\\subsubsection{Indistinct Recipients}\n$k$ elements are divided into $n$ ordered sequences of minimum length 1.\n\n\\begin{equation}\nL(k,n)= {k \\choose n} (k-1)^{\\underline{k-n}} = \\frac{k!}{n!}{ k-1 \\choose n-1 }\n\\end{equation}\n\t\n\\subparagraph{Books into Unlabeled Boxes} $k$ books are stacked into up to $n$ different unlabeled boxes. All of the $n$ boxes have at least one book in them. The sequence in which the books are stacked in each box matters. There are ${k \\choose n}$ ways of putting the first book in each of the boxes. Then there are $(k-n)!{k-n+n-1 \\choose k-n}$ ways to stack the remaining $k-n$ books on top of those first books. \n\n\\subparagraph{Broken Permutations $n$ parts} The permutations of $k$ distinct elements are ordered sequences of length $k$. If the sequence is cut up into up to $n$ different parts, then what results are \\textit{broken permutations}.\n\n\\subparagraph{Books into Boxes} $k$ different books are put into $n$ identical boxes, so that there is at least one book in each box. How many ways are there to pack the boxes if you keep track of the order in which the books in each box are stacked? \n\n\n% Identical Objects\n\\subsection{Identical Objects}\n\n%% Distinct Recipients\n\\subsubsection{Distinct Recipients}\n\n\\begin{equation}\n|S| = {k+n-1 \\choose k}\n\\end{equation}\n\nThis coefficient can be easily derives using the \"Stars and Bars\" concept. A short way of explaining this is as follows: picture putting all the $k$ identical objects in a line (stars). Picture having dividers (bars) to divide the $k$ objects into $n$ groups. For $n$ groups, it is necessary to use $n-1$ dividers. Empty groups result when the dividers sit right next to each other with no object in between them, or if a divider is at the end of a sequence. In total, the objects and the dividers make for a sequence in which $k+n-1$ spots are taken up by either an object or a divider. To pick a particular way of dividing the $k$ objects up, you can either pick the $n-1$ locations of the sequence in which the dividers are located, or, equivalently, the locations in which the objects are located. There are ${k+n-1\\choose n-1}={k+n-1\\choose k}$ to do so.  \n\n\\subparagraph{Ping Pong Balls into Labeled Buckets} $k$ identical ping pong balls are put into $n$ labeled buckets. Some of the buckets may be empty, and other buckets might have more than one ball in them.  \n\n\\subparagraph{Multisets} Multisets are sets in which identical elements might show up several times. For example $\\{a,a,b,b,b\\}$. They can also be described in terms of the multiplicity of their elements. For example $[a:2, b:3, c:0]$. How many multisets can be formed with $k$ different elements of $n$ different classes?\n\n\\subparagraph{Integer Sums} How many different configurations of the $n$ integers $\\{ x_i\\}_n$ satisfy $x_1 + x_2 + ... + x_n = k$?\n\n\\subparagraph{Bosons in Degenerate States} In how many ways might $k$ Bosons populate $n$ degenerate states?\n\n%% Indistinct Recipients\n\\subsubsection{Indistinct Recipients}\n\n\\begin{equation}\n|S| = \\sum_{i=1}^n P(k,i)\n\\end{equation}\n\nIt turns out that there is no known formula for $P(k,n)$.\n\n\\subparagraph{Ping Pong Balls into Unlabeled Bags} $k$ identical ping pong balls are put into $n$ unlabeled bags. Some of the bags might be empty, and other bags might have more than one ball in them.\n\n\\subparagraph{Number Partitions} How many ways are there to divide $k$ objects across \\underline{up to} $n$ piles. How many ways are there to divide an integer $k$ into a sum of $n$ integers (including zeros). For example: for $k=5$, $n=3$, the partitions are $5+0+0, 4+1+0, 3+2+0, 3+1+1, 2+2+1$.\n\n\\subparagraph{Unlabeled Multiplicities of Multisets} For multisets of $k$ elements with $n$ different classes, what is the number of possible multiplicities? For example, a multiset of $k=3$ elements from $n=2$ classes could have multiplicities $[a:3,b:0], [a:2,b:1],[a:1,b:2],[a:0,b:3]$. If we do not care about the labels $a,b$, then the ways that the the $k$ elements migth be distributed are $[3,0]$ and $[2,1]$.\n\n\\subparagraph{Boxes of Marbles} $k$ marbles are randomly put into $n$ boxes. How many ways are there for the weight to be distributed among the boxes?\n\n\n\n% Identical Objects, Each gets at most one\n\\subsection{Identical Objects, Each Receives At Most One}\n\n%% Distinct Recipients\n\\subsubsection{Distinct Recipients}\n$k$ identical objects are distributed across $n$ recipients so that each recipient recieves at most one. That amounts to choosing $k$ out of the $n$ recipients who will receive an object.\n\n\\begin{equation}\n|S| = { n \\choose k}\n\\end{equation}\n\n\n\\subparagraph{At Most One Ping Pong Balls into Labeled Buckets} $k$ identical ping pong balls are distributed across $n$ different buckets, so that $k$ buckets have one ball in them and $n-k$ buckets are empty. This is the same as choosing $k$ out of the $n$ buckets, for which there are $n\\times(n-1)\\times(n-2)\\times\\hdots\\times(n-k+1)$ choices for the $k$ balls, and correcting for the internal orderings of the $k$ balls by dividing by $k!$ because the balls are identical.\n\n\\subparagraph{Subsets} $k$ element subsets of a set of size $n$. The subsets are formed by either choosing the $k$ elements that are included or the $n-k$ elements that are excluded.\n\n\\subparagraph{Set Binary Labels} The problem can also be thought of as assigning a binary label to $n$ elements, where there are $k$ times $1$ and $n-k$ times 0.\n\n%% Indistinct Recipients\n\\subsubsection{Indistinct Recipients}\n\n\\begin{equation}\n|S| = 1\\ \\ \\mathrm{if\\ }k \\leq n,\\ 0\\ \\mathrm{otherwise}\n\\end{equation}\n\n\\subparagraph{At Most One Ping Pong Ball into Unlabeled Bags}  $k$ identical ping pong balls are put into $n$ identical bags. The result is either $k$ bags with ping pong balls and $n-k$ empty bags, or there is no possible result if there are not enough bags (i.e. if $k>n$).\n\n\\subparagraph{Boxes} How many ways are there to put $k$ marbles in $n$ boxes, if each box is only big enough for one marble. One, if there are enough boxes, or zero, if there aren't enough boxes.\n\n\n% Identical Everyone Gets At Least one\n\\subsection{Identical Objects, Each Receives At Least One}\n\n%% Distinct Recipients\n\\subsubsection{Distinct Recipients}\nThis problem is the same as giving each of $n$ recipients one of $k$ objects, and then distributing the remaining $k-n$ objects arbitrarily.  \n\n\\begin{equation}\n|S| = {k+n-1-k \\choose k-n}= {n-1 \\choose k-1}\n\\end{equation}\n\nThis can be derived by picturing first distributing one object to each of the $n$ recipients, ensuring that each recipient has at least one, and then distributing the remaining $k-n$ objects arbitrarily. There is only one way to give each recipient one of the identical objects, and then there are ${k-n+n-1\\choose k-n}$ ways to distribute the remaining $k-n$ objects arbitrarily across the recipients.\n\n\\subparagraph{At Least One Ping Pong Ball into Labeled Buckets} $k$ ping pong balls are distributed into $n$ labeled buckets so that there is at least one ping pong ball in each bucket. The labeled buckets may have more than one ping pong ball in them.\n\n\\subparagraph{Compositions $n$ Parts} How many ways are there to assign $k$ identical objects to $n$ labeled sets of at least one object?\n\n% Indistinct Recipients\n\\subsubsection{Indistinct Recipients}\n\n\\begin{equation}\n|S| = P(k,n)\n\\end{equation}\n\nIt turns out that there is no known formula for $P(k,n)$.\n\n\\subparagraph{At Least One Ping Pong Ball in Unlabeled Bags} $k$ identical ping pong balls are distributed across $n$ unlabeled bags, so that none of the bags are empty. \n\n\\subparagraph{Partitions in $n$ Parts} How many ways are there to make $n$ piles from $k$ objects.\n\n\n\n% Identical Each Gets Exactly one\n\\subsection{Identical Objects, Each Receives Exactly One}\n\n%% Distinct Recipients \n\\subsubsection{Distinct Recipients}\n\n\\begin{equation}\n|S| = 1\\ \\ \\mathrm{if\\ }k = n,\\ 0\\ \\mathrm{otherwise}\n\\end{equation}  \n\n\\subparagraph{One Ping Pong Ball into Each Labeled Bucket} $k$ identical ping pong balls are distributed across $n$ labeled buckets so that each bucket has one ping pong ball in it. If $k=n$, then there is one way to put one ball in each bucket. If the numbers do not match up, then there is no way to match them one-for-one.\n\n%% Indistinct Recipients\n\\subsubsection{Indistinct Recipients}\n\n\\begin{equation}\n|S| = 1\\ \\ \\mathrm{if\\ }k = n,\\ 0\\ \\mathrm{otherwise}\n\\end{equation}  \n\n\\subparagraph{One Ping Pong Ball into Each Unlabeled Bag} $k$ identical ping pong balls are distributed across $n$ identical bags so that each bags has one ping pong ball in it. If $k=n$, then there is one way to put one ball in each bag. If the numbers do not match up, then there is no way to match them one-for-one.\n\n\n\n\n", "meta": {"hexsha": "64c0a388292a66907c4b2bddbd28b2fac8cb9f4b", "size": 27779, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/comb_twentyfoldway.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/comb_twentyfoldway.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/comb_twentyfoldway.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.1019900498, "max_line_length": 1278, "alphanum_fraction": 0.7382195183, "num_tokens": 7639, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.831143060406073, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7113347384865426}}
{"text": "\\documentclass[12pt]{pylatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{Displaying long expressions}\n\nThis example uses a simple (though contrived) example of a Taylor series expansion of $1/(1+x)$ to demonstrate the problems that can arise when displaying very long expressions.\n\n% \\vspace{12pt}\n\n\\begin{minipage}[t]{0.50\\textwidth}\n\\begin{python}\n   from sympy import *\n   x = Symbol('x')\n   ans    = 1/(1+x)                 # py (ans.511,ans)\n   taylor = ans.series(x, 0, 10)    # py (ans.512,taylor)\n   taylor = ans.series(x, 0, 20)    # py (ans.513,taylor)\n   taylor = ans.series(x, 0, 23)    # py (ans.514,taylor)\n\\end{python}\n\\end{minipage}\n\\hskip 0.5cm\n\\begin{minipage}[t]{0.50\\textwidth}\n\\begin{latex}\n   \\begin{dgroup*}[spread={5pt}]\n      \\begin{dmath*} f(x) = \\Py*{ans.511} \\end{dmath*}\n      \\begin{dmath*}    {}= \\Py*{ans.512} \\end{dmath*}\n      \\begin{dmath*}    {}= \\Py*{ans.513} \\end{dmath*}\n      \\begin{dmath*}    {}= \\Py*{ans.514} \\end{dmath*}\n      \\begin{dmath*}    {}= \\Py*[\\hskip 2cm]{ans.514} \\end{dmath*}\n   \\end{dgroup*}\n\\end{latex}\n\\end{minipage}\n\n\\vspace{18pt}\n\nThe first four lines of the following output were set using {\\tt\\small\\verb|\\Py*|}\nwhile the final line used {\\tt\\small\\verb|\\Py*[\\hskip=2cm]|}. The last pair of lines displays\nthe output for the same tag {\\tt\\small ans.514} and clearly the formatting of the second\nlast line is not ideal as the text has overlapped the tag. This was corrected in the final\nline by using the optional argument {\\tt\\small\\verb|[\\hskip=2cm]|} in the call to {\\tt\\small\\verb|\\Py*|}.\n\n\\begin{dgroup*}[spread={5pt}]\n   \\begin{dmath*} f(x) = \\Py*{ans.511} \\end{dmath*}\n   \\begin{dmath*}    {}= \\Py*{ans.512} \\end{dmath*}\n   \\begin{dmath*}    {}= \\Py*{ans.513} \\end{dmath*}\n   \\begin{dmath*}    {}= \\Py*{ans.514} \\end{dmath*}\n   \\begin{dmath*}    {}= \\Py*[\\hskip 2cm]{ans.514} \\end{dmath*}\n\\end{dgroup*}\n\n\\end{document}\n", "meta": {"hexsha": "dfcb060f52518af025415f3b2548ea5b3fbd6dcb", "size": 1896, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "python/examples/example-05.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "python/examples/example-05.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "python/examples/example-05.tex", "max_forks_repo_name": "leo-brewin/hybrid-latex", "max_forks_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-27T03:29:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:17:18.000Z", "avg_line_length": 36.4615384615, "max_line_length": 177, "alphanum_fraction": 0.6339662447, "num_tokens": 709, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7113347211119873}}
{"text": "\\lesson{5}{Sep 27 2021 Mon (07:10:04)}{Operations on Complex Numbers}{Unit 1}\n\n\\subsubsection*{Multiplying Complex Numbers}\n\nWhile the process of adding and subtracting complex numbers was similar to that\nof polynomials and radicals, multiplying complex numbers is just a little bit\ndifferent. Think about in which order this multiplication should take place.\n\nLet's see what happens when the imaginary number is factored first.\n\n\\begin{align}\n    \\sqrt{-12} \\times \\sqrt{-5} &= (\\sqrt{-1} \\times \\sqrt{12}) \\times (\\sqrt{-1} \\times \\sqrt{5}) \\\\\n                                &= i \\sqrt{12} \\times i \\sqrt{5}\n\\end{align}\n\nOnce the imaginary numbers have been factored, multiply the imaginary numbers\ntogether and multiply the radical factors together.\n\n\\begin{align}\n    i\\sqrt{12} \\times i\\sqrt{5} = i^2 \\sqrt{60}\n\\end{align}\n\nNow that the two factors have been multiplied, simplify the remaining radicand\nby either rewriting it as a product of its prime factors or by finding the\nperfect square factor.\n\n\\newpage\n", "meta": {"hexsha": "fd0ceca2d91b633327719b7f39e16ffbb4cbfba0", "size": 1017, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-1/lesson-5.tex", "max_stars_repo_name": "SingularisArt/notes", "max_stars_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-08-31T12:45:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T07:29:05.000Z", "max_issues_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-1/lesson-5.tex", "max_issues_repo_name": "SingularisArt/notes", "max_issues_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-1/lesson-5.tex", "max_forks_repo_name": "SingularisArt/notes", "max_forks_repo_head_hexsha": "de33e73ca7df9d3adcb094aa9909ea0337e68fad", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.3214285714, "max_line_length": 101, "alphanum_fraction": 0.726647001, "num_tokens": 260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927011, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.711316000611398}}
{"text": "\\documentclass[10pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{xcolor}\n\\usepackage[T1]{fontenc}\n\\usepackage{pagecolor}\n\\usepackage{amssymb}\n\\usepackage{lmodern}\n\\usepackage{mathtools, nccmath}\n\\usepackage{courier}\n\\usepackage[dvipsnames]{xcolor}\n\n\\definecolor{myyellow}{RGB}{225,225,100}\n\\definecolor{myred}{RGB}{220,100,100}\n\\definecolor{mygreen}{RGB}{120,225,120}\n\\definecolor{myblue}{RGB}{100,200,255}\n\\definecolor{mypurple}{RGB}{200,50,255}\n\\color{white}\n\\title{\\Huge{Solution to Calculus \\#2}}\n\\author{@all.about.mathematics}\n\\date{}\n\\begin{document}\n\\Large\n\\maketitle\n\\pagecolor{black}\n\\section{Problem}\nEvaluate the integral \n\\large\n$$\\int_{0}^{\\infty}\\frac{(x^2-1)\\ln x}{1+x^6}dx$$\n\\large\n\\newpage\n\\section{Solution}\nIn our last post, we had established this result for $\\frac m n \\not \\in \\mathbb{Z}$\n\\begin{equation}\nI(m,n)=\\int_{0}^{\\infty}\\frac{x^{m-1}}{1+x^n}dx=\\frac{\\pi}{n\\sin\\left(\\frac{m\\pi}{m}\\right)}=\\frac{\\pi}{n}\\csc\\left(\\frac{m\\pi}{n}\\right)\n\\end{equation}\nDifferentiating $(1)$ with respect to $m$,\n$$\\frac{dI(m,n)}{dm}=\\frac{d}{dm}\\int_{0}^{\\infty}\\frac{x^{m-1}}{1+x^n}dx= \\int_{0}^{\\infty}\\frac{\\partial}{\\partial m}\\frac{x^{m-1}}{1+x^n}dx= \\int_{0}^{\\infty}\\frac{x^{m-1} \\ln x}{1+x^n}dx$$\nWe also have \n$$\\frac{dI(m,n)}{dm}=\\frac{d}{dm}\\left[\\frac{\\pi}{n}\\csc\\left(\\frac{m\\pi}{n}\\right)\\right]=-\\frac{\\pi^2}{n^2}\\csc\\left(\\frac{m\\pi}{n}\\right)\\cot\\left(\\frac{m\\pi}{n}\\right)$$\nRewriting our integral,\n$$\\int_{0}^{\\infty}\\frac{(x^2-1)\\ln x}{1+x^6}dx=\\int_{0}^{\\infty}\\frac{x^2\\ln x}{1+x^6}dx-\\int_{0}^{\\infty}\\frac{\\ln x}{1+x^6}dx$$\n$$=\\frac{dI(3,6)}{dm}-\\frac{dI(1,6)}{dm}$$\n$$=-\\frac{\\pi^2}{6^2}\\csc\\left(\\frac{3\\pi}{6}\\right)\\cot\\left(\\frac{3\\pi}{6}\\right)-\\left(-\\frac{\\pi^2}{6^2}\\csc\\left(\\frac{\\pi}{6}\\right)\\cot\\left(\\frac{\\pi}{6}\\right)\\right)$$\n$$=\\frac{\\pi^2}{6\\sqrt{3}}$$\n\n\n\n\n\\end{document}", "meta": {"hexsha": "35e77d31f11835e8a554b126c6b11ac4fa32734d", "size": 1834, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/all.about.mathematics' questions/Calculus 2.tex", "max_stars_repo_name": "Nanu00/LaTeX", "max_stars_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-05-29T17:22:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T18:47:05.000Z", "max_issues_repo_path": "Calculus/all.about.mathematics' questions/Calculus 2.tex", "max_issues_repo_name": "Nanu00/LaTeX", "max_issues_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-06-26T07:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-11T12:14:49.000Z", "max_forks_repo_path": "Calculus/all.about.mathematics' questions/Calculus 2.tex", "max_forks_repo_name": "Shreenabh664/LaTeX", "max_forks_repo_head_hexsha": "675e03f3ec555456b9a2cc714825ec75317848c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-06-22T07:50:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-08T05:11:14.000Z", "avg_line_length": 37.4285714286, "max_line_length": 192, "alphanum_fraction": 0.6537622683, "num_tokens": 790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740729, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.7113159981869148}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{fixltx2e}\n\\usepackage{graphicx}\n\\usepackage{float}\n\\usepackage{multirow}\n\n\\bibliographystyle{plain}\n\n\\title{Bundle Adjustment Notes}\n\\author{James Balasalle}\n\\date{\\today}\n\n\\DeclareMathOperator*{\\argmin}{arg\\,min}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\n  These purpose of these notes is to capture what I learn while trying\n  to understand and implement the computer vision task known as\n  \\emph{Bundle Adjustment}.  The intent is that I can use these notes\n  for reference, but also that they serve a didactic purpose: helping\n  others who are new to the field come up to speed on the subject\n  quickly.  It is my hope that I can explain, derive, or otherwise\n  show all of the mathematical steps required to implement a bundle\n  adjustment program.\n\\end{abstract}\n\n\\section{Introduction}\n\\label{sec:intro}\n\nBundle adjustment is a processes that uses mathematical optimization\ntechniques to reduce the error found in cameras, their positions, and\nthe images they create.  When a camera captures an image, all of the\nobjects in its field of view are converted from their intrinsic 3D\ncoordinates to a 2D image at the location of the camera.  The points\nthemselves, in 3D, are called observations.  The process of bundle\nadjustment looks at the 3D points and where they end up in the 2D\nimage and corrects for any errors introduced by the imaging process.\nI am not entirely sure, but I think error can be introduced by several\nfactors: the camera lens, distortion introduced by the lens,\nimperfections in the lens, movement, and the ``non-discreteness'' of\ntoday's camera sensors.  What this means is that objects show up in\nslightly the wrong place in the 2D image.  Bundle adjustment is a\nmethod which minimizes these errors.  Bundle adjustment can reduce the\nerror in the points themselves, as well as the location and pointing\ndirection of the cameras.\n\n\\section{A Simple Example}\n\\label{sec:simple-example}\nIn this section, I present a small, simple example.  Here we use a\nbundle adjustment process to reconstuct the location and pointing\ndirection of a single camera.  The location and pointing direction of\neach camera are known as \\textit{camera parameters}.  These include\nthe 3D position of the camera, which is represented by 3 coordinates:\n$x$, $y$, and $z$, and where the camera is ``looking,'' which is\ntypically represented by three angles: $\\phi$, $\\chi$, and $\\psi$.  In\nthis example we will only be adjusting the camera parameters, while\nassuming the 3D positions of the points and their corresponding 2D\nprojects are exact and have no error.\n\\\\\n\\\\\nIn this example, we have some 3D points, let's say $10$ points.  We\nalso know the exact location of these points in some world coordinate\nsystem.  Next we place a camera somewhere, again in the world\ncoordinate system, and point it in a direction that can see all\npoints.  This means we fix the camera parameters: we therefore know\n$x$, $y$, $z$, $\\phi$, $\\chi$, and $\\psi$.  Now that we know where the\npoints are and we know the details of the camera we can ``take a\npicture'' of those points.  To do this we \\emph{project} the 3D points\ninto the 2D plane of the camera.  This process takes each 3D point, in\nworld coordinates, and converts it to a pixel location in the image.\nProjecting a 3D point into a 2D camera is a two step process: 1)\nconvert the 3D point from the world coordinate system to a 3D point in\nthe camera's coordinate system and then 2) project the 3D point in the\ncamera's coordinate system to a 2D plane.  We have already determined\nthe camera parameters by fixing them to our favorite location and\nangles.  We encode the parameters in a 4x4 homogeneous matrix\n$\\mathbf{T}$, which has the following form:\n\\\\\n\\begin{equation}\n  \\label{eq:T-matrix}\n  \\mathbf{T} = \\left[\n  \\begin{array}{ccc|c}\n      \\multicolumn{3}{c}{\\multirow{3}{*}{\\Large $\\mathbf{R}$}} & t_x \\\\\n      & & & t_y \\\\\n      & & & t_z \\\\ \\hline\n      0 & 0 & 0 & 1\n  \\end{array}\n  \\right]\n\\end{equation}\nAs you can see the upper-left 3x3 of the $\\mathbf{T}$ matrix is simply\nthe rotation matrix $\\mathbf{R}$.  The rightmost column of\n$\\mathbf{T}$ is the location of the camera with a $1$ in the bottom\nright position.  This is the matrix we use to convert the 3D points in\nworld coordinates to the camera's coordinate system:\n\\\\\n\\begin{equation}\n  \\label{eq:pose-composition}\n  \\mathbf{\\Gamma}(\\mathbf{x}) = \\mathbf{P_{C}} = \\mathbf{T^{-1}}\\mathbf{P_{W}}\n\\end{equation}\nwhere $\\mathbf{P_{C}}$ denotes the resulting point in the camera's\ncoorinate system and $\\mathbf{P_{W}}$ is the point in the world\ncooridnate system.  Notice here that to convert from the world\ncoordinate system to the camera coordinate system we actually need the\n\\emph{inverse} of $\\mathbf{T}$.  $\\mathbf{T}$ is an orthogonal matrix,\nso we know the inverse exists.  I have not done this, but since we\nneed the inverse, we could actually parameterize the camera using the\ninverse.  That is, instead of finding the $\\mathbf{T}$ matrix, we\ncould find $\\mathbf{T^{-1}}$ during the solution process, and then\nsimply invert $\\mathbf{T}$ at the end to find our solution.\n\\\\\n\\\\\nNow that we have transformed $\\mathbf{P_{W}}$ to $\\mathbf{P_{W}}$ we\nproject $\\mathbf{P_{C}}$ into the plane of the camera.  In the\ncomputer vision literature I have read, the projection function is\nreferred to as $\\boldsymbol{\\pi}$.  Actually I think\n$\\boldsymbol{\\pi}$ is used for the \\emph{de-homogenization} process:\nwhen we go from homegeneous coordinates to non-homegenous coordinates.\nThis holds true for $n$ to $n-1$ dimensions.  But in the 3D to 2D case\nthere is also a geometric reasoning that has to do with similar\ntriangles.  The projection or dehomogenization function is:\n\\begin{equation}\n  \\label{eq:dehomog}\n  \\boldsymbol{\\pi}(\\mathbf{v}) =  \\frac{1}{v_n} \\left(\n  \\begin{array}{c}\n    v_1 \\\\\n    v_2 \\\\\n    \\vdots \\\\\n    v_{n-1}\n  \\end{array}\n  \\right)\n\\end{equation}\n\\\\\nIt's pretty instructive to show this function,\n$\\boldsymbol{\\pi}(\\mathbf{v})$, in the 3D to 2D case.  Here,\n$\\mathbf{P_C}$, is a vector with length 3, representing the $x, y, z$\ncoordinates of the point. The result of this operation would be a\nvector of length two, the elements of which we will denote as $u$ and\n$v$.  Therefore the function $\\boldsymbol{\\pi}$ is actually a system\nof two equations: one for $u$ and one for $v$.\n\\begin{align}\n  \\label{eq:proj-3d-to-2d}\n    \\pi_u(x,y,z) = \\frac{x}{z} \\\\ \\nonumber\n    \\pi_v(x,y,z) = \\frac{y}{z}\n\\end{align}\n\\\\\nWe have now shown how to take a point in world coordinates and convert\nit to pixel coordinates of the camera: $ \\mathbf{\\Gamma}(\\mathbf{x}) =\n\\mathbf{P_{C}} = \\boldsymbol{\\pi}(\\mathbf{T^{-1}}\\mathbf{P_{W}})$.\n\\\\\n\\\\\nSo far, we have discussed a \\emph{single} point.  But in our program,\nand in the real world bundle adjustment problem, we will have many\npoints.  Each 3D point is a vector of length 3, and the projected\npoints, in 2D, are also vectors, of length 2.  When we have multiple\npoints, we can store all the $u$ and $v$ values in a single vector, as\ndemonstrated here.  In this example we show the results of projecting\n3 points in a single vector.  The superscripts denote which points\nhave been projected into each $u$ and $v$ value.\n\\begin{equation}\n  \\label{eq:single-vec}\n  \\mathbf{X} = \\left(\n  \\begin{array}{c}\n    u^{(1)} \\\\\n    v^{(1)} \\\\\n    u^{(2)} \\\\\n    v^{(2)} \\\\\n    u^{(3)} \\\\\n    v^{(3)}\n  \\end{array}\n  \\right)\n\\end{equation}\n\n\\subsection{Introduction to Optimization}\n\\label{sec:optimization-intro}\nBundle Adjustment is a mathematical optimization process.  The 3D\npoints, and by extension the 2D pixel coordinates are our\nobservations.  We want to minimize the distance between the\nobservations (where we actually saw the points) and where they\n``should'' be.  Mathematically this means we want to minimize the norm\nof the difference between the observations and the correct locations\nof the points.  We will be using a Newton-style method to solve the\noptimization problem, which means we need an initial guess, as all\nNetwon methods do.  The initial guess is our first estimate of the\nsolution, and in this problem we are solving for the camera\nparameters, or $\\mathbf{T}$ matrix.  So our intial guess is simply a\nguess for $\\mathbf{T}$.  Using this guess, we then transform all the\npoints and project them into the camera.  This gives us a guess for\nall $u$ and $v$ values.  We then subtract this guess from the true $u$\nand $v$ values.  It is the norm of this difference that we are trying\nto minimize.\n\\\\\n\\\\\nWe can write this several ways, but we will look at one of the more\ncommon forms:\n\\begin{equation}\n  \\label{eq:argmin}\n  \\mathbf{x^*} = \\argmin_x \\mathbf{F}(\\mathbf{x})\n\\end{equation}\n\nwhere\n\\begin{equation}\n  \\label{eq:argmin-F}\n  \\mathbf{F}(\\mathbf{x}) = \\frac{1}{2} \\sum\\limits_{i=1}^n f_i(\\mathbf{x})^2 = \\| \\mathbf{f}(\\mathbf{x}) \\|\n\\end{equation}\n\nWhat is $f_i(\\mathbf{x})$?  It is the difference between the\nobservation of point $i$ and guess for point $i$.  So, it is actually\ntwo functions, one for $u$ and one for $v$.  Using the same notation\nas above, for 3 points here is the full definition of\n$\\mathbf{F}(\\mathbf{x})$:\n\\begin{eqnarray}\n  \\label{eq:full-F}\n  \\mathbf{F}(\\mathbf{x}) &=& \\frac{1}{2} [ (u_O^{(1)} - u_P^{(1)})^2 + (v_O^{(1)} - v_P^{(1)})^2 + (u_O^{(2)} - u_P^{(2)})^2 + \\\\\n    && (v_O^{(2)} - v_P^{(2)})^2 + (u_O^{(3)} - u_P^{(3)})^2 + (v_O^{(3)} - v_P^{(3)})^2 ] \\nonumber\n\\end{eqnarray}\nwhere $u_O^{(1)}$ is the $u$ pixel location of observation number 1\nand $v_P^{(3)}$ is the $v$ pixel location of the third point when\nprojected with the current guess for $\\mathbf{T}$.\n\\\\\n\\\\\nHow do we solve equation~\\ref{eq:argmin}?  This is a rather\ncomplicated process, that is beyond the scope of these notes.  I will\ngive a brief explanation, however.  We will only consider finding a\nminimum, it might not be the global minimum; finding the global\nminimum is out of the scope of this discussion.  A minimum of\n$\\mathbf{F(\\mathbf{x})}$ exists where the derivative of\n$\\mathbf{F(\\mathbf{x})} = 0$.  To find where an equation equals zero,\nwe use Newton's method.  Here is a review of Newton's method for a\nsingle variable:\n\n\\begin{equation}\n  \\label{eq:newton-1d}\n  x_{k+1} = x_k - \\frac{f(x)}{f^{-1}(x)}\n\\end{equation}\n\nOf course, bundle adjustment is a more complicated problem.  Since we\nhave many more observations than unknowns, we have an over-determined\nsystem, there is no exact solution.  Instead we are trying to find the\nsolution that minimized the error, as stated in the formulation of the\nminimization problem.  The way we will do this is to solve\nthe following problem:\n\\begin{equation}\n  \\label{eq:JtJ}\n  \\mathbf{J}^T\\mathbf{J}\\cdot\\mathbf{h} = \\mathbf{J}^T\\mathbf{R}\n\\end{equation}\nwhere $\\mathbf{R}$ is the difference between observations and the\ncurrent guess, as discussed above.  Equation~\\ref{eq:JtJ} is known as\nthe \\emph{normal equation}.  After we have a solution, $\\mathbf{h}$,\nwe use this as our Netwon update.  And then we solve the problem\nagain with the updated guess, and we do this until the norm of our\nerror, $\\mathbf{R}$, is no longer decreasing.\n\\\\\n\\\\\nHow do we take the derivative and compute $\\mathbf{J}$?  We compute a\nJacobian matrix where each entry is the partial derivative of one of\nthe equations with respect to one of the unknowns.  In our case, the\nJacobian for each point is a 2x6 matrix.  The function we are taking\nthe derivative of is\n\\begin{equation}\n  \\label{eq:deriv}\n  \\mathbf{R} = \\mathbf{z} - \\boldsymbol{\\pi}(\\mathbf{T^{-1}}\\mathbf{P_{W}})\n\\end{equation}\nwhere $\\mathbf{z}$ is one observation (which is a 2-vector of $u$ and\n$v$).  This is how we take the derivative of this: $\\mathbf{z}$ is a\nconstant, so the derivative is zero; for the remaining part we need to\nuse the chain rule:\n\n\\begin{equation}\n  \\label{eq:chain-rule}\n  \\frac{\\partial\\boldsymbol{\\pi}(\\mathbf{x})}{\\partial\\mathbf{x}} \\frac{\\partial\\mathbf{\\Gamma}(\\mathbf{y})}{\\partial\\mathbf{y}}\n\\end{equation}\nwhere $\\mathbf{\\Gamma}(\\mathbf{y})$ is a function that represents\ntransforming a point by a matrix as shown in\nequationπ~\\ref{eq:pose-composition}.  The chain rule simply says we\ntake the derivative of the outer function, $\\boldsymbol{\\pi}$, and\nmultiply by the derivative of the inner function, $\\mathbf{\\Gamma}$.\n\nEquation~\\ref{eq:proj-3d-to-2d}, $\\boldsymbol{\\pi}(\\mathbf{x})$, is\ninstructive for computing the Jacobian.  As stated above, there at two\nequations (one for $u$ and one for $v$), and three unknowns: $x$, $y$,\nand $z$.  Taking the derivatives analytically gives us the following\nJacobian:\n\\begin{equation}\n  \\label{eq:proj-jacobian}\n  \\mathbf{J} =\n  \\begin{bmatrix}\n    \\frac{1}{z} & 0 & \\frac{-x}{z^2} \\\\\n    0 & \\frac{1}{z} & \\frac{-y}{z^2}\n  \\end{bmatrix}\n\\end{equation}\nNext we need to take the derivative of $\\mathbf{\\Gamma}(\\mathbf{y})$.  This\nis much more complicated, and I will not explain it fully.\nEssentially, we use Lie groups, and multiply each unknown by a\nspecific 4x4 matrix.  Then once we have solved the linear system, we\nconvert the solution from ``Lie algebra space'' back to our Euclidean\nspace.  The end result is that the derivative of $\\mathbf{T}$ is a 4x4\nmatrix.\n\\\\\n\\\\\nI have also left out something called the \\emph{intrinsic matrix} of\nthe camera.  This is a 3x4 matrix which represents internal\ncalibration parameters of the camera, such as focal length and optical\ndistortion.  For this problem, I have simply used a 3x4 identity\nmatrix.  I mention it here because it is important for the matrix\nmultiplication.  So far our chain rule step looks like this (in terms\nof matrix sizes):\n\\begin{equation}\n  \\label{eq:T-matrix}\n  \\mathbf{J} =\n  \\left[\n  \\begin{array}{c}\n      2 \\textrm{x} 3\n  \\end{array}\n  \\cdot\n  \\begin{array}{c}\n      3 \\textrm{x} 4\n  \\end{array}\n  \\cdot\n  \\begin{array}{c}\n      4 \\textrm{x} 4\n  \\end{array}\n  \\cdot\n  \\begin{array}{c}\n      4 \\textrm{x} 1\n  \\end{array}\n  \\right]\n\\end{equation}\nwhich clearly shows that the matrix multiplication is defined because\nall the sizes are legal, and the end result is a 2x1 matrix, which is\nactually what we expect: a value for $u$ and a value for $v$.  The\npoint we are transforming is 4x1 because it is represented in\nhomogeneous coordinates. As just stated, this multiplication results\nin two values, and from this we can see that for every point, we will\nhave two rows.  Now we need to compute all the columns.  In our\nproblem we have 6 unknowns, we have to do this 6 times.  We do this by\nchanging the 4x4 matrix in the Lie algebra step.  These 4x4 matrices\nare well-known and can be easily found in the literature; see Hauke's\nthesis \\cite{strasdat2012local} for a much better and more detailed\nexplanation.  So our Jacobian for a single point results in a 2x6\nmatrix.\n\\\\\n\\\\\nObviously for more points, we will have a ``taller'' matrix.  This is\nto be expected, because bundle adjustment is a least squares problem:\nwe are minimizing the error, not finding an exact solution.  We do\nthis for each point, adding two rows.  When we have done this for all\nour observations, we finally computed $\\mathbf{J}$ and now we can\nsolve the linear system defined in~\\ref{eq:JtJ}.\n\\\\\n\\\\\nAs stated above, our toy problem has 10 points, which results in a\nvery tractable size.  We are able to easily compute\n$\\mathbf{J}^T\\cdot\\mathbf{J}$ and $\\mathbf{J}^T\\cdot\\mathbf{R}$,\nfollowed by solving the resulting system exactly using LU\nfactorization.  Once we have done this, we have a solution,\n$\\mathbf{h}$.  Since we used the Lie algebra method, we need to\nconvert this solution back to euclidean space.  This is done via a C++\npackage called \\emph{Sophus} and is a very easy and simple operation.\nWe now have our Newton update to $\\mathbf{T}$.  Instead of adding this\nresult to our previous guess, we right-multiply by the update.  Now we\nhave our new guess in euclidean space.  From here, we repeat the\nprocess: project all the points with our new guess, compute the error\nvector, $\\mathbf{R}$, form the Jacobian and sovle the system for our\nnext update.  We stop the process when the norm of $\\mathbf{R}$ falls\nbelow some threshold.\n\\\\\n\\\\\nHere is the process of our toy problem:\n\\begin{enumerate}\n\\item Create 10 3D points, store them in a vector $\\mathbf{P}$.\n\\item Construct a reasonable camera and corresponding $\\mathbf{T}$\n  matrix\n\\item Project each point into the camera, store the results in a vector\n  $\\mathbf{O}$.\n\\item \\emph{Forget} $\\mathbf{T}$\n\\item Create a ``reasonable'' guess for $\\mathbf{T}$, call this $\\mathbf{T_{Guess}}$\n\\item Project each point using $\\mathbf{T_{Guess}}$\n\\item Compute the $\\mathbf{J}$ matrix\n\\item Compute the $\\mathbf{R}$ vector\n\\item Sovle the follwing system: $\\mathbf{J}^T\\mathbf{J}\\cdot\\mathbf{h} =\n  \\mathbf{J}^T\\mathbf{R}$\n\\item Convert back to eucliding coordinates\n\\item Update the guess: $\\mathbf{T_{Guess + 1}} = \\mathbf{T_{Guess}}\n  \\cdot \\mathbf{X}$\n\\item Compute $\\|\\mathbf{T_{Guess + 1}}\\|$ and stop once it has\n  reached some threshold\n\\end{enumerate}\n\n\n\\bibliography{ba_notes}\n\n\\end{document}", "meta": {"hexsha": "4c33b9896a50675d6bbbacc9b25907961dde80a3", "size": 17073, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/ba_notes.tex", "max_stars_repo_name": "eglrp/myBA", "max_stars_repo_head_hexsha": "b974b41a2f235cf1c2f81385840d2ab58d77e011", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-02-25T06:44:32.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-26T16:04:37.000Z", "max_issues_repo_path": "notes/ba_notes.tex", "max_issues_repo_name": "jmbalasalle/myBA", "max_issues_repo_head_hexsha": "b974b41a2f235cf1c2f81385840d2ab58d77e011", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/ba_notes.tex", "max_forks_repo_name": "jmbalasalle/myBA", "max_forks_repo_head_hexsha": "b974b41a2f235cf1c2f81385840d2ab58d77e011", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-07-24T04:49:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-02T12:44:29.000Z", "avg_line_length": 42.8969849246, "max_line_length": 129, "alphanum_fraction": 0.725531541, "num_tokens": 5086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.7113159929997115}}
{"text": "\\chapter{Mathematical layout}\n\n\n\n\n\n\\section{Environments for display mathematics}\n\\label{display environments}\n\n\n\n\\subsection{Don’t use \\inlinecodetitle{\\$\\$  \\$\\$} or \\envtitle{eqnarray}}\n\nThere are many good ways to put mathematical content into display mode, but \\inlinecode{\\$\\$~\\$\\$}\\massindex[display math environment]{\\$\\$~\\$\\$}[\\inlinecode] and \\envname{eqnarray}\\massindex[display math environment]{eqnarray}[\\envname] are none of them.\nThe method~\\inlinecode{\\$\\$  \\$\\$} is too low level, and the environment~\\envname{eqnarray} has too many problem and has long been deprecated.\nOne can instead use any of the following, depending on the planned usage.\n\n\n\n\\subsection{The environments~\\inlinecodetitle{{\\tbs}[ {\\tbs}]} and \\envtitle{equation*}}\n\nThe environments~\\inlinecode{{\\tbs}[ {\\tbs}]}\\massindex[display math environment]{{\\tbs}[ {\\tbs}]}[\\inlinecode] and \\envname{equation*}\\massindex[display math environment]{equation*}[\\envname] can be used for a single line of display math mode.\nBoth commands do the exactly same thing (when the package~\\packname{amsmath}\\massindex[packages]{amsmath}[\\packname] is loaded).\n\\begin{showlatex}*{Using the environments~\\inlinecode{{\\tbs}[ {\\tbs}]} and \\envname{equation*}}\nSuppose that both the formula\n\\[\n  a + b = c\n\\]\nand the formula\n\\begin{equation*}\n  2a - b = c \\,.\n\\end{equation*}\nhold.\nThen $a$ and $b$ are unique.\n\\end{showlatex}\nThe non-starred version~\\envname{equation}\\massindex[display math environment, tagging and numbering]{equation}[\\envname] numbers the equation.\n\\begin{showlatex}*{Using the environment~\\envname{equation}}\nThe formula\n\\begin{equation}\n  a^2 - b^2 = (a + b)(a - b)\n\\end{equation}\nis one of the binomial formulas.\n\\end{showlatex}\n\n\n\n\\subsection{The environment~\\envtitle{gather*}}\n\nThe environment~\\envname{gather*}\\massindex[display math environment, multi-line mathematics]{gather*}[\\envname] is meant for multiple lines that are non-aligned.\n\\begin{showlatex}{Using the environment~\\envname{gather*}}\nWe consider for every integer $n \\geq 0$ the polynomial\n\\[\n  p_n\n  =\n  \\sum_{k=0}^n x^k \\,.\n\\]\nIn particular\n\\begin{gather*}\n  p_0 = 1 \\,,\n  \\qquad\n  p_1 = 1 + x \\,,\n  \\qquad\n  p_2 = 1 + x + x^2 \\,,\n  \\qquad\n  p_3 = 1 + x + x^2 + x^3 \\,,\n  \\\\\n  p_4 = 1 + x + x^2 + x^3 + x^4 \\,,\n  \\qquad\n  p_5 = 1 + x + x^2 + x^3 + x^4 + x^5 \\,.\n\\end{gather*}\n\\end{showlatex}\nThe non-starred version~\\envname{gather}\\massindex[display math environment, multi-line mathematics, tagging and numbering]{gather}[\\envname] numbers each line.\n\\begin{showlatex}{Using the environment~\\envname{gather}}\nWe have the polynomials\n\\begin{gather}\n  p_0 = 1 \\,,\n  \\qquad\n  p_1 = 1 + x \\,,\n  \\qquad\n  p_2 = 1 + x + x^2 \\,,\n  \\qquad\n  p_3 = 1 + x + x^2 + x^3 \\,,\n  \\\\\n  p_4 = 1 + x + x^2 + x^3 + x^4 \\,,\n  \\qquad\n  p_5 = 1 + x + x^2 + x^3 + x^4 + x^5 \\,.\n\\end{gather}\n\\end{showlatex}\n\n\n\n\\subsection{The environments~\\envtitle{align*} and \\envtitle{alignat*}}\n\nThe environment~\\envname{align*}\\massindex[display math environment, multi-line mathematics]{align*}[\\envname] allows for multiple lines.\nEach line contains the symbol~\\inlinecode{\\&}\\massindex{\\&}[\\inlinecode] once, and the occurrences of this symbol are then aligned.\n\\begin{showlatex}*{Using the environment~\\envname{align*}}\nWe find that\n\\begin{align*}\n  a + b + c\n  &=\n  d + e + f + g\n  \\\\\n  &=\n  h + i + j\n  \\\\\n  &=\n  k + l + m + n \\,.\n\\end{align*}\n\\end{showlatex}\nThe unstarred version~\\envname{align}\\massindex[display math environment, multi-line mathematics, tagging and numbering]{align}[\\envname] numbers the lines.\n\\begin{showlatex}*{Using the environment \\envname{align}}\nWe find again that\n\\begin{align}\n  a + b + c\n  &=\n  d + e + f + g\n  \\\\\n  &=\n  h + i + j\n  \\\\\n  &=\n  k + l + m + n \\,.\n\\end{align}\n\\end{showlatex}\nOne can also use multiple aligned columns, which then need to be separated by an additional~\\inlinecode{\\&}\\massindex{\\&}[\\inlinecode].\nFor~$n$ aligned columns we hence need~$2n-1$ occurrences of~\\inlinecode{\\&} per line.\n\\begin{showlatex}{Using \\envname{align*} with multiple columns}\nWe consider the values\n\\begin{align*}\n  x_1 &= 1 \\,,  &   x_2 &= 2 \\,,  &   x_3 &= 3 \\,,  \\\\\n  x_4 &= 4 \\,,  &   x_5 &= 5 \\,,  &   x_6 &= 6 \\,,  \\\\\n  x_7 &= 7 \\,,  &   x_8 &= 8 \\,,  &   x_9 &= 9 \\,.\n\\end{align*}\n\\end{showlatex}\n\nThe environment~\\envname{alignat*}\\massindex[display math environment, multi-line mathematics]{alignat*}[\\envname] is similar to the environment~\\envname{align*} but doesn’t add any built-in spacing between the aligned columns.\nAny such spacing must therefore by added by hand.\nOne also has to specify the number of columns beforehand.\n\\begin{showlatex}{Using the environment~\\envname{alignat*}}\nWe also consider the values\n\\begin{alignat*}{3}\n  y_1 &= 9 \\,,  &\\qquad   y_2 &= 8 \\,,  &\\qquad   y_3 &= 7 \\,,  \\\\\n  y_4 &= 6 \\,,  &         y_5 &= 5 \\,,  &         y_6 &= 4 \\,,  \\\\\n  y_7 &= 3 \\,,  &         y_8 &= 2 \\,,  &         y_9 &= 1 \\,.\n\\end{alignat*}\n\\end{showlatex}\nTo align multiple columns one should use \\envname{alignat*} instead of \\envname{align*} to get (manually) a good looking distance between the aligned columns.\nThe environment~\\envname{alignat}\\massindex[display math environment, multi-line mathematics]{alignat}[\\envname] works in the same way as \\envname{alignat*} but automatically numbers the lines.\n\n\n\n\\subsection{Don’t use \\envtitle{center} plus \\inlinecodetitle{\\$ \\$}}\n\\massindex{center}[\\envname]\n\\massindex{\\$ \\$}[\\inlinecode]\n\nBy all that is holy, don’t do the following:\n\\begin{showlatex}*{Using~\\comname{center} with~\\inlinecode{\\$ \\$}}\nIt holds that\n\\begin{center}\n  $\\sum_{i=0}^n 2^i = 2^{n+1} - 1$.\n\\end{center}\nThis can be shown by induction.\n\\end{showlatex}\n% TODO: Explain all the things that go wrong\n\n\n\n\\subsection{The environments~\\envtitle{gathered}, \\envtitle{aligned} and \\envtitle{alignedat}}\n\nThe environments~\\envname{gathered}\\massindex[multi-line mathematics]{gathered}[\\envname], \\envname{aligned}\\massindex[multi-line mathematics]{aligned}[\\envname] and \\envname{alignedat}\\massindex[multi-line mathematics]{alignedat}[\\envname] are variations of the environments~\\envname{gather*}, \\envname{align*} and \\envname{alignat*} that can be used inside an already existing math environment.\n\\begin{showlatex}*{Using \\envname{aligned}}\n\\[\n  \\left\\{\n    \\begin{aligned}\n      a + b &= c      \\\\\n      d     &= e + f\n    \\end{aligned}\n  \\right\\}\n\\]\n\\end{showlatex}\n\n\n\n\\subsection{Overview}\n\nOne should always use the most basic environment that does the job:\nUsing overpowered environments can lead to unexpected problems.\nConsider the following example:\n\\begin{showlatex}{Improper use of~\\envname{align*}}\n\\begin{align*}\n  ABCD = EF = GHI = JKL = M = NOP\n  \\\\\n  QRS = TUV = WX = Y = Z\n\\end{align*}\n\\end{showlatex}\nThe environment~\\envname{align*} automatically alignes both lines on the right since no information about alignment was given.\nIn the above situation one should use \\envname{gather*} instead.\n\\begin{showlatex}{Using \\envname{gather*} for non-aligned equations}\n\\begin{gather*}\n  ABCD = EF = GHI = JKL = M = NOP\n  \\\\\n  QRS = TUV = WX = Y = Z\n\\end{gather*}\n\\end{showlatex}\nIf a multi-line display mode environment is used for a single line then one can get spacing issues, see \\cref{spacing before multi-line}.\n\nThe flowchart in \\cref{environment flow chart} explains how to choose the correct display environment.\n(This flowchart is partly inspired by \\cite{flowchart}.)\n\\begin{figure}[tb]\n  \\begin{center}\n  \\begin{tikzpicture}[\n    node distance = 5em,\n    >={Latex[width=2mm,length=2mm]},\n    every text node part/.style = { align = center },\n    start/.style    = { rectangle,\n                        rounded corners,\n                        fill = green!20!white,\n                        draw = black,\n                        minimum width  = 5em,\n                        minimum height = 2em\n                      },\n    question/.style = { rectangle,\n                        rounded corners,\n                        fill = black!10!white,\n                        draw = black,\n                        minimum width  = 9em,\n                        minimum height = 2.5em\n                      },\n    answer/.style   = { rectangle,\n                        rounded corners,\n                        draw = black,\n                        minimum width  = 7em,\n                        minimum height = 1.5em\n                      }\n  ]\n    % nodes\n    \\node (start)\n          [start]\n          {formula};\n    \\node (multi-line)\n          [question, below of = start]\n          {multi-line?};\n    \\node (alignment)\n          [question, below of = multi-line]\n          {alignment?};\n    \\node (multicolumn)\n          [question, below of = alignment]\n          {multiple columns?};\n    \\node (equation)\n          [answer, right of = multi-line, xshift = 7em]\n          {\\inlinecode{{\\tbs}[ {\\tbs}]}\\\\\\envname{equation*}};\n    \\node (gather)\n          [answer, right of = alignment, xshift = 7em]\n          {\\inlinecode{gather*}};\n    \\node (align)\n          [answer, right of = multicolumn, xshift = 7em]\n          {\\inlinecode{align*}};\n    \\node (alignat)\n          [answer, below of = align]\n          {\\inlinecode{alignat*}};\n    % arrows\n    \\draw[->] (start) -- (multi-line);\n    \\draw[->] (multi-line)   -- node[anchor=south] {no} (equation);\n    \\draw[->] (multi-line)   -- node[anchor=east] {yes} (alignment);\n    \\draw[->] (alignment)   -- node[anchor=south] {no} (gather);\n    \\draw[->] (alignment)   -- node[anchor=east] {yes} (multicolumn);\n    \\draw[->] (multicolumn) -- node[anchor=south] {no} (align);\n    \\draw[->] (multicolumn) |- node[anchor=east, yshift=1.7em] {yes} (alignat);\n  \\end{tikzpicture}\n  \\end{center}\n  If numbering of the line(s) is needed then the unstarred version is to be used.\n  \\caption{Deciding on a math environment.}\n  \\label{environment flow chart}\n\\end{figure}\n\n\n\n\n\n\\section{Where to break and align formulas}\n\\label{break and align ponts}\n\nOftentimes a formula is broken among multiple lines.\nThis is done for at least two reasons:\n\\begin{myitemize}\n  \\item\n    To improve the readability of the given formula.\n  \\item\n    To prevent that the formula goes over the margins of the text area.\n\\end{myitemize}\nIf a formula is broken among multiple lines then one has to choose at which places the formula should be broken, and how the resulting parts of the formula will then be aligned.\nIn this section we present some standard ways of doing so.\n\n\n\n\\subsection{When to break a formula}\n\\index{line breaks!in math mode|(}\n\nWe first discuss when a formula needs to be broken.\n\n\\subsubsection{When the formula is too long}\n\nIf a formula is too long to physically fit into the text area, i.e.\\ if it goes over the margins of the text area, then it must be broken up.\nThese occurrences are easy to spot since they give will give an \\enquote{overfull hbox} warning.\nConsider the following example:\n\\begingroup\n\\begin{showlatex}[before lower = {\\hfuzz = 40pt}, after lower = {\\hfuzz = 0pt}]{An overfull hbox}\n  It follows from\n  \\[\n    aaaaaaa\n    =\n    bbbbbbb\n    =\n    ccccccc\n    \\leq\n    ddddddd\n    =\n    eeeeeee\n    =\n    fffffff\n    \\leq\n    ggggggg\n    =\n    hhhhhhh\n  \\]\n  that $a \\leq h$.\n\\end{showlatex}\n\\endgroup\n\n\\subsubsection{When the formula is visually too long}\n\nSometimes a formula does fit into a single line, but barely so.\nConsider the following example:\n\\begin{showlatex}{Visually overfull hbox}\nHere is some text.\n\\[\n  aaaaaaaaa = bbbbbbbbbbbbbb = cccccccccccccc = dddddddddddddd = eeeeeeeeee\n\\]\nHere is some more text.\n\\end{showlatex}\nThe formula in the above example does -- technically speaking -- not go over the margin.\nBut it has stretched the display mode beyond its visual limits.\nThe formula does therefore need to be broken up.\n\n\\subsubsection{Expressing structure}\n\nOften the breaking up of a formula is done to better express the structure -- and thus content -- of the displayed formula.\nConsider the following example:\n\\begin{showlatex}[label={unreadable formula}]{A formula that should be broken up for readability}\nIf $k$ is algebraically closed with~$\\operatorname{char}(k) \\neq 2$ and $i$ is a square root of $-1$ then\n\\[\n  k[x]/(x^2 + 1)\n  =\n  k[x]/( (x - i) (x + i) )\n  \\cong\n  k[x]/(x - i) \\times k[x]/(x + i)\n  \\cong\n  k \\times k\n\\]\nby the Chinese remainder theorem.\n\\end{showlatex}\nThe above output still has an appropriate length to be put into a single line, and if space is sparse then this is an acceptable solution.\nBut this single-line approach to the formula does not help to display its internal structure.\nThis can be done by splitting up the formula as done in the next example:\n\\begin{showlatex}{Broken up version of \\cref*{unreadable formula}}\nIf $k$ is algebraically closed and $i$ is a square root of $-1$ then\n\\begin{align*}\n  k[x]/(x^2 + 1)\n  &=\n  k[x]/( (x - i) (x + i) )\n  \\\\\n  &\\cong\n  k[x]/(x - i) \\times k[x]/(x + i)\n  \\\\\n  &\\cong\n  k \\times k\n\\end{align*}\nby the Chinese remainder theorem.\n\\end{showlatex}\nThis form makes it clear where the equalities and isomorphisms occur.\n\n\n\n\\subsection{Where to break and align a formula}\n\\index{aligning formulas|(}\n\nWe now discuss at which points a formula can be broken, and how these broken parts can then be aligned.\n\n\\subsubsection{Aligning at relation symbols I}\n\nA first approach is to put all relation symbols underneath each other.\n\\begin{showlatex}{Aligning relation symbols~I}\nLet $x$, $y$ be two commuting, nilpotent elements of~$A$.\nThen\n\\begin{align*}\n  \\exp(x) \\exp(y)\n  &=\n  \\left( \\sum_{k=0}^\\infty \\frac{x^k}{k!} \\right)\n  \\left( \\sum_{l=0}^\\infty \\frac{y^l}{l!} \\right)\n  \\\\\n  &=\n  \\sum_{k,l=0}^\\infty \\frac{x^k y^l}{k! \\, l!}\n  \\\\\n  &=\n  \\sum_{n=0}^\\infty \\, \\sum_{k+l = n} \\frac{x^k y^l}{k! \\, l!}\n  \\\\\n  &=\n  \\sum_{n=0}^\\infty \\frac{1}{n!} \\sum_{k=0}^n \\binom{n}{k} x^k y^{n-k}\n  \\\\\n  &=\n  \\sum_{n=0}^\\infty \\frac{1}{n!} (x + y)^n\n  \\\\\n  &=\n  \\exp(x + y) \\,.\n\\end{align*}\n\\end{showlatex}\n\n\\subsubsection{Aligning at relation symbols II}\n\nOne can also align all relation symbols to the left, so that the broken up parts of the formula all lie on top of each other.\n\\begin{showlatex}{Aligning relation symbols~II}\nLet~$R$ and~$S$ be two commutative rings.\nThen for every~$(r,s) \\in R \\times S$,\n\\begin{align*}\n  {}&\n  (r, s) \\in (R \\times S)^\\times\n  \\\\\n  \\iff{}&\n  \\text{there exist $(r', s') \\in R \\times S$ with $(r,s)(r',s') = (1,1)$}\n  \\\\\n  \\iff{}&\n  \\text{there exist $r' \\in R$ and $s' \\in S$ with $rr' = 1$ and $ss' = 1$}\n  \\\\\n  \\iff{}&\n  \\text{$r \\in R^\\times$ and $s \\in S^\\times$}\n  \\\\\n  \\iff{}&\n  (r,s) \\in R^\\times \\times S^\\times \\,,\n\\end{align*}\nand therefore $(R \\times S)^{\\times} = R^\\times \\times S^\\times$.\n\\end{showlatex}\nThe empty pair of curly brackets in \\inlinecode{{\\tbs}iff\\{\\}\\&} ensures that the spacings coming from \\comname{iff} and~\\inlinecode{\\&} do not interfere with each other.\nOtherwise something like this happens:\n\\begin{showlatex}*{Wrong spacing when alignment points are set wrong}\n  \\begin{align*}\n     &\\text{some stuff} \\\\\n    =&\\text{some other stuff}\n  \\end{align*}\n\\end{showlatex}\n\n\\subsubsection{Breaking at a binary operator}\n\nSometimes it is also useful to break a long term of a formula at a binary operator.\nIn this case this operator needs to occur in the line after the break.\nThe following example does it wrong:\n\\begin{showlatex}*{Wrong aligning at a binary operator~I}\n\\begin{align*}\n  & a + b + c + \\\\\n  & d + e\n\\end{align*}\n\\end{showlatex}\nThe following should be done instead:\n\\begin{showlatex}*{Right breaking at a binary operator~I}\n\\begin{align*}\n  & a + b + c \\\\\n  & + d + e\n\\end{align*}\n\\end{showlatex}\n%TODO: Explain the above example better.\nIf a formula is broken at relation symbols and one of the resulting terms is broken at a binary operator, then the operator is not aligned together with the relation symbols.\nInstead the binary operator appears after the relation symbols.\nThe following example does it wrong:\n\\begin{showlatex}*{Wrong breaking at a binary operator~II}\n\\begin{align*}\n  a + a\n  &=\n  b + b + b + b\n  \\\\\n  &+\n  b + b + b + b\n  \\\\\n  &=\n  c + c + c + c + c\n\\end{align*}\n\\end{showlatex}\nInstead the following has to be done:\n\\begin{showlatex}*{Right breaking at a binary operator~II}\n\\begin{align*}\n  a + a\n  ={}&\n  b + b + b + b\n  \\\\\n  {}&\n  +b + b + b + b\n  \\\\\n  ={}&\n  c + c + c + c + c\n\\end{align*}\n\\end{showlatex}\n\n\\subsubsection{A single term in another line}\n\nIf a single line equation is too long, then it is sometimes appropriate to put the last term in a new line, such that the last term occurs below the second to last term.\n\\begin{showlatex}{Single term in new line}\nIt follows that\n\\begin{align*}\n  aaaaaaaaaaaa\n  =\n  bbbbbbbbbbb\n  =\n  cccccccccc\n  =\n  ddddddddd\n  &=\n  eeeeeeee\n  \\\\\n  &=\n  ffffff\n\\end{align*}\nand hence $2 + 2 = 5$.\n\\end{showlatex}\n\n\\index{aligning formulas|)}\n\\index{aligning formulas!zzzza@\\igobble |seealso {\\comname{align*}}}\n\\index{aligning formulas!zzzzb@\\igobble |seealso {\\comname{alignat*}}}\n\n\n\n\\subsection{Don’t break formulas badly}\n\nOne should always keep in mind that breaking up a formula isn’t just meant to prevent technical problems, but more importantly to let the resulting output better display the structure -- and thus part of the content -- of the formula.\nA badly broken up formula is harder to understand for both the reader and the author.\nConsider the following example:\n\\begin{showlatex}{Badly broken formula}\nIt follows that\n\\begin{align*}\n  aaaaaaaaa\n  &=\n  bbbbbbbbbbb\n  =\n  cccccccc\n  \\leq\n  dddddd\n  =\n  eeeeeee\n  \\\\\n  &=\n  eee\n  \\leq\n  fffffff\n  =\n  gggggggg\n  \\leq\n  hhhhhhhhh\n  \\\\\n  &<\n  kkkkkkk\n  =\n  llll\n  \\leq\n  mmmma\n  =\n  nnnnnnn\n  =\n  pp \\,.\n\\end{align*}\n\\end{showlatex}\nIn such a case the breaking of the formula should be done in a consistent way.\nThere seem to be two sensible approaches for the above example, which we will now explain.\n\n\\subsubsection{Align everything}\n\nOne can align all occurring relation symbols:\n\\begin{showlatex}{Aligning all relation symbols}\nIt follows that\n\\begin{align*}\n  aaaaaaaaa\n  &= bbbbbbbbbbb \\\\\n  &= cccccccc \\\\\n  &\\leq dddddd \\\\\n  &= eeeeeee \\\\\n  &= eee \\\\\n  &\\leq fffffff \\\\\n  &= gggggggg \\\\\n  &\\leq hhhhhhhhh \\\\\n  &< kkkkkkk \\\\\n  &= llll \\\\\n  &\\leq mmmma \\\\\n  &= nnnnnnn \\\\\n  &= pp \\,.\n\\end{align*}\n\\end{showlatex}\nThis approach has the advantage of being very consistent.\nBut it has the disadvantage of taking a lot of space.\nIt might also not reflect the structure of the formula particularly well, as this layout gives all (in)equalities the same importance.\n    \n\\subsubsection{Align at inequalities}\n\nOn could align all the inequality symbols, to make it clear where these occur:\n\\begin{showlatex}{Aligning all inequalities}\nIt follows that\n\\begin{align*}\n  aaaaaaaaa\n  &= bbbbbbbbbbb\n  = cccccccc\n  \\\\\n  &\\leq\n  dddddd\n  = eeeeeee\n  = eee\n  \\\\\n  &\\leq\n  fffffff\n  = gggggggg\n  \\\\\n  &\\leq\n  hhhhhhhhh\n  \\\\\n  &<\n  kkkkkkk\n  = llll \\\\\n  &\\leq mmmma\n  = nnnnnnn\n  \\\\\n  &= pp \\,.\n\\end{align*}\n\\end{showlatex}\nThis layout emphasizes the importance of the inequalities, while relegating the equalities to a less important position.\nNote that we have also aligned the first and last equality signs to make it clear where the manipulations begin and end.\nIf some other equalities are also particularly important (e.g.\\ if they follows from some previously hard-earned proposition) then they too should be aligned\n\n\\index{line breaks!in math mode|)}\n\n\n\n\n\n\\section{Aligning nearly aligned formulas}\n\\index{aligning formulas|(}\n\nSometimes formulas turn out to look nearly aligned in the compiled output, even though this wasn’t planned.\nBut the formulas may still be non-aligned enough to look jarring.\nIn such a case it is often best to align these formulas.\n\nConsider the following example:\n\\begin{showlatex}{Accidental jarringly non-aligned expressions}\n\\begin{gather*}\n  KK^{-1} = 1 = K^{-1}K \\,,\n  \\quad\n  EF - FE = \\frac{ K - K^{-1} }{ q - q^{-1} } \\,,\n  \\\\\n  KE = q^2 EK \\,,\n  \\quad\n  KF = q^{-2} FK \\,.\n\\end{gather*}\n\\end{showlatex}\nNote that the first line of the output looks slightly shifted to the left when compared to the second line.\nThis impression vanishes when both lines are properly aligned, and instead gives rise to more coherent look and fell.\n\\begin{showlatex}{Intentional well-aligned expressions}\n\\begin{align*}\n  KK^{-1} = 1 = K^{-1}K \\,,\n  \\quad\n  &EF - FE = \\frac{ K - K^{-1} }{ q - q^{-1} } \\,,\n  \\\\\n  KE = q^2 EK \\,,\n  \\quad\n  &KF = q^{-2} FK \\,.\n\\end{align*}\n\\end{showlatex}\n\n\\index{aligning formulas|)}\n\n\n\n\n\n\\section{Proper spacing before multi-line display mode environments}\n\\label{spacing before multi-line}\n\nIf mathematical content is put into display mode then this content will not only be horizontally centered but also receive some vertical spacing\\index{spacing!around display mode} around it to separate it from the surrounding text.\nObserve in the following example that both above and below the formula there is an additional spacing of roughly (exactly?) one line:\n\\begin{showlatex}*{Vertical space around display mode}\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et\n\\[\n  a = b \\,.\n\\]\nNunc aliquet bibendum enim facilisis gravida. Nisl nunc mi ipsum faucibus vitae aliquet nec ullamcorper.\n\\end{showlatex}\n\nIf the line before a display mode environment is too short then this vertical spacing may be visually too large.\nThe one-line display environments~\\inlinecode{{\\tbs}[ {\\tbs}]}\\massindex[display math environment]{{\\tbs}[ {\\tbs}]}[\\inlinecode] and~\\envname{equation*}\\massindex[display math environment]{equation*}[\\envname] do therefore automatically adjust this spacing.\nObserve that in the following example the distance between the first two text lines is far shorter than the distance between the second and third text lines.\n\\begin{showlatex}*{Adjusted spacing before one-line display mode}\nLorem\n\\[\n  a = b\n\\]\n ipsum dolor sit amet, consectetur\n\\[\n  a = b \\,.\n\\]\nipsum elit.\n\\end{showlatex}\nWe can say more precisely that the additional spacing inserted by {\\LaTeX} is either \\comname{abovedisplayskip} or its shorter version~\\comname{abovedisplayshortskip}.\n\nThe multi-line display mode environments (like~~\\envname{align*}\\massindex[display math environment, multi-line mathematics]{align*}[\\envname]) don’t have this feature (for technical reasons).\nInstead, it always uses the spacing~\\comname{abovedisplayskip}.\nThis can lead to some unpleasant spacing:\n\\begin{showlatex}*{Unpleasant spacing around a multi-line environment}\ntext text text text text text text text text\n\\begin{alignat*}{1}\n  x &= y_i\n\\shortintertext{text}\n  x &= z_{i+1}\n\\end{alignat*}\ntext text text text text text text text\n\\end{showlatex}\n\nThe package~\\packname{mathools} provides a partial fix to this problem:\nBy putting the command~\\comname{SwapAboveDisplaySkip}\\massindex[\\piname{mathtools}, spacing!around display mode]{SwapAboveDisplaySkip}[\\comname] at the beginning of a multi-line display mode environment we force {\\LaTeX} to use the shorter spacing~\\comname{abovedisplayshortskip}.\n\\begin{showlatex}*{Pleasant spacing around a multi-line environment}\ntext text text text text text text text text\n\\begin{alignat*}{1}\n\\SwapAboveDisplaySkip\n  x &= y_i\n\\shortintertext{text}\n  x &= z_{i+1}\n\\end{alignat*}\ntext text text text text text text text\n\\end{showlatex}\n\n\n\n\n\n\\section{Use the \\envtitle{cases} environment}\n\nUse the environment~\\envname{cases}\\massindex[multi-line mathematics]{cases}[\\envname] for case distinctions:\n\\begin{showlatex}{Using \\envname{cases}}\nIt follows that\n\\[\n  A(x)\n  =\n  \\begin{cases}\n    x^2  & \\text{if $x \\leq 0$,} \\\\\n    3x   & \\text{if $x = 0$.}\n  \\end{cases}\n\\]\n\\end{showlatex}\nIn most cases one should actually use the environment~\\envname{cases*}\\massindex[multi-line mathematics]{cases*}[\\envname], which ensures that the second column will be treated as text.\n\\begin{showlatex}{Using \\envname{cases*}}\nIt follows that\n\\[\n  A(x)\n  =\n  \\begin{cases*}\n    x^2  & if $x \\leq 0$, \\\\\n    3x   & if $x = 0$.\n  \\end{cases*}\n\\]\n\\end{showlatex}\n\nThe package~\\packname{mathtools}\\massindex[packages]{mathtools}[\\packname] defines some more useful variants of the environment~\\envname{cases}.\nWe refer to~\\cite[3.4.3]{mathtools} for more information on this.\n\n\n\n\n\\section{Proper placement of the qed-symbol}\n\n\\index{qed-symbol|(}\n\nThe~\\envname{proof}~environment\\massindex[\\piname{amsthm}]{proof}[\\envname] automatically places a qed-symbol at its end.\n\\begin{showlatex}{Using the \\envname{proof}~environment}\n\\begin{proof}\nThis is obviously a proof.\n\\end{proof}\n\\end{showlatex}\nIt can happen that this automatic placement of the qed-symbol gives a bad looking result.\nThe general rule is that the qed-symbol should not occur at the end of an otherwise empty line.\nTo fix such a bad placement one can use the command~\\comname{qedhere}\\massindex{qedhere}[\\comname].\nLet’s look at some specific examples of this problem:\n\n\\subsubsection{qed-symbol after lists}\n\nIf a proof consists of a list then the qed-symbol will by default be placed after the list, and thus in a new line.\n\\begin{showlatex}{Improper placement of the qed-symbol after a list~I}\n\\begin{proof}\n  This proof consists of a list.\n  \\begin{enumerate}\n    \\item\n      Some part of the proof.\n    \\item\n      Another part of the proof.\n  \\end{enumerate}\n\\end{proof}\n\\end{showlatex}\nThis can be fixed by placing the command~\\comname{qedhere} just before the list ends.\n\\begin{showlatex}{Proper placement of the qed-symbol after a list}\n\\begin{proof}\n  This proof consists of a list.\n  \\begin{enumerate}\n    \\item\n      Some part of the proof.\n    \\item\n      Another part of the proof.\n    \\qedhere\n  \\end{enumerate}\n\\end{proof}\n\\end{showlatex}\nBut one has to be careful no to introduce a new line before the command~\\comname{qedhere}.\n\\begin{showlatex}{Improper placement of the qed-symbol after a list~II}\n\\begin{proof}\n  This proof consists of a list.\n  \\begin{enumerate}\n    \\item\n      Some part of the proof.\n    \\item\n      Another part of the proof.\n      \n    \\qedhere\n  \\end{enumerate}\n\\end{proof}\n\\end{showlatex}\n\n\\subsubsection{qed-symbol after displaystyle}\n\nIf a proof ends with display~style mathematics then the qed-symbol will by default be placed after this display~mode.\n\\begin{showlatex}{Improper placement of the qed-symbol after display~mode~I}\n\\begin{proof}\n  This proof ends with a some display~mode mathematics, namely\n  \\[\n    \\sin(x+y)\n    =\n    \\cos(x)\\sin(y) + \\sin(x)\\cos(y) \\,.\n  \\]\n\\end{proof}\n\\end{showlatex}\nThere are at least two different approaches to fixing this situation:\n\nSome authors prever to bring the qed-symbol to the height of the display environment, as done in the following example.\n\\begin{showlatex}{Somewhat proper placement of the qed-symbol after display~mode}\n\\begin{proof}\n  This proof ends with a some display~mode mathematics, namely\n  \\[\n    \\sin(x+y)\n    =\n    \\cos(x)\\sin(y) + \\sin(x)\\cos(y) \\,.\n    \\qedhere\n  \\]\n\\end{proof}\n\\end{showlatex}\nBut this approach does not work if the (last line) of the display environment has additional height.\nThen the mathematical formula goes below the line on which the qed-symbol rests.\n\\begin{showlatex}{Improper placement of the qed-symbol after display~mode~II}\n\\begin{proof}\n  This proof ends with a some display~mode mathematics, namely\n  \\[\n    1\n    + \\frac{a}{b - a}\n    =\n    \\frac{(b - a) + a}{b - a}\n    =\n    \\frac{b}{b - a} \\,.\n    \\qedhere\n  \\]\n\\end{proof}\n\\end{showlatex}\nThe author is the opinion that in such a cases there is no good placement for the qed-symbol.\n\nAside the placement of the qed-symbol there is another problem to ending a proof with a display~environment:\nOne of the functions of display~mode is to put an emphasis on the displayed mathematical content.\nPutting such an emphasis directly before the end of a proof can lead to the proof missing a sense of closure.\n\nThis problem leads to the second solution for the placement of the qed-symbol.\nNever end a proof with a display~environment.\nThis can be done by rewriting the end of proof, or by adding a closing sentence to it.\n% TODO: Give an example\n\n\\subsubsection{qed-symbol at the end of a long text}\n\nIt can also happen that the qed-symbol is pushed to a new line if the previous line is completely filled with text.\n(Although {\\LaTeX} will actually try quite hard to prevent this from happening.)\nIf this happens then one should (slightly) rewrite the text to circumvent this problem.\n\n\\index{qed-symbol|)}\n\\index{qed-symbol!zzzz@\\igobble |seealso{\\comname{qedhere}}}\n\n\n\n\n\\section{Tagging and numbering}\n\nA finer control over tags can be achieved via the commands~\\comname{tag} and~\\comname{notag}.\n\n\n\n\\subsection{Don’t autonumber all formulas}\n\\label{dont number all formulas}\n\\index{tagging and numbering}\n\nDon’t indiscriminately number every occurring formula.\nInstead, an equation should be numbered only if it will be referred to later on.\nThis numbering should then be done automatically by using a suitable environment like~\\envname{equation},~\\envname{gather},~\\envname{align} or~\\envname{alignat}.\n\n\n\n\\subsection{\\comtitle{tag}}\n\nWith the command~\\comname{tag}\\massindex[tagging and numbering]{tag}[\\comname] a custom tag can be set.\nThis is useful for marking selected equations by special symbols:\n\\begin{showlatex}{Using~\\comname{tag} for marking a line}\nConsider the equation\n\\begin{equation}\n\\label{important equation}\n  2 + 2 = 5 \\,.\n  \\tag{\\ast}\n\\end{equation}\nNote that \\cref{important equation} can equivalently be expressed as~$5 = 2 + 2$.\n\\end{showlatex}\nThe argument of~\\comname{tag} is in text mode, and the resulting tag is automatically enclosed in parentheses.\nThese parentheses can be removed by using the starred command~\\comname{tag*} instead.\n\nThe command~\\comname{tag} should not be used for regular numbering of equations.\nIt should be used to tag only certain (often a single) equations in a special way.\n\nIt can also be used to express that certain transformations have been used, as the following example demonstrates:\n\\begin{showlatex}{Using~\\comname{tag} to explain steps}\nIt follows from the Chinese remainder theorem that\n\\begin{align*}\n  \\mathbb{R}[x] / ( x^3 + x^2 + x + 1 )\n  &=\n  \\mathbb{R}[x] / ( (x^2 + 1) (x + 1) )\n  \\\\\n  &\\cong\n  \\mathbb{R}[x] / ( x^2 + 1 ) \\times \\mathbb{R}[x] / ( x + 1 )\n  \\tag{CRT}\n  \\\\\n  &\\cong\n  \\mathbb{C} \\times \\mathbb{R}\n\\end{align*}\n\\end{showlatex}\n\n\n\n\\subsection{\\comtitle{notag}}\n\nAccording to \\cref{dont number all formulas} a formula should be numbered only if it needs to be referred to.\nBut if this formula occurs in a multi-line environment like~\\envname{align} then all occuring lines will be numbered, even unwanted ones.\nThe prevent the numbering of the unrequired lines the command~\\comname{notag}\\massindex[tagging and numbering]{tag}[\\comname] can then be used:\n\\begin{showlatex}*{Using~\\comname{notag} to prevent selected line numbers}\n\\begin{align}\n  a\n  &= b \\notag \\\\\n  &= c \\\\\n  &= d \\notag \\\\\n  &= e\n\\end{align}\n\\end{showlatex}\n\n\n\n\n\n\\section{Multi-line set descriptions}\n\nMulti-line set descriptions of the form\n\\[\n  \\left\\{\n    (e_1, \\dotsc, e_n)\n  \\,\\middle|\\,\n    \\begin{tabular}{@{}c@{}}\n      $e_1, \\dotsc, e_n \\in R$ \\\\\n      is a complete set of \\\\\n      pairwise orthogonal \\\\\n      idempotents\n    \\end{tabular}\n  \\right\\}\n\\]\ncan be typeset by using a \\envname{tabular} environment for the right hand side of the set description:\n\\begin{showlatex}*{Multi-line set descriptions with tabular}\n\\[\n  \\left\\{\n    x \\in X\n  \\,\\middle|\\,\n    \\begin{tabular}{@{}c@{}}\n      $x$ satisfies \\\\\n      certain conditions\n    \\end{tabular}\n  \\right\\}\n\\]\n\\end{showlatex}\nNote that the entries of the environment~\\envname{tabular} are automatically in text mode.\nThe argument~\\inlinecode{\\@\\{\\}} ensure that the environment~\\envname{tabular} does not insert additional spacing\\index{spacing!in math mode} to its left and right.\n\n\n\n\n", "meta": {"hexsha": "bcb1a353e75f097353f129531ff7a4a2372e3635", "size": 31774, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/math_layout.tex", "max_stars_repo_name": "cionx/thoughts-about-writing-latex", "max_stars_repo_head_hexsha": "39c7fb189f39f60865886278d5c23a0a310cdb18", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/math_layout.tex", "max_issues_repo_name": "cionx/thoughts-about-writing-latex", "max_issues_repo_head_hexsha": "39c7fb189f39f60865886278d5c23a0a310cdb18", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/math_layout.tex", "max_forks_repo_name": "cionx/thoughts-about-writing-latex", "max_forks_repo_head_hexsha": "39c7fb189f39f60865886278d5c23a0a310cdb18", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.8058058058, "max_line_length": 396, "alphanum_fraction": 0.6873544407, "num_tokens": 9439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737916455819, "lm_q2_score": 0.8856314753275019, "lm_q1q2_score": 0.7113159900394603}}
{"text": "\\section{Improper Integrals}\\label{sec:ImproperIntegrals}\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n%Recall that the Fundamental Theorem of Calculus says that if $f$ is a \\underline{{\\bf continuous}} function on the closed interval $[a,b]$, then\r\n%$$\\ds{\\int_a^b f(x)~dx=F(x)\\bigg|_a^b=F(b)-F(a)},$$\r\n%where $F$ is any antiderivative of $f$. \r\n%\r\n%Both the {\\bf continuity} condition and {\\bf closed interval} must hold to use the Fundamental Theorem of Calculus, and in this case, $\\ds\\int_a^b f(x)\\,dx$ represents the net area under $f(x)$ from $a$ to $b$: \r\n%$$\\includegraphics[width=2.25in]{images2/area-under}$$\r\n%\r\n%We begin with an example where blindly applying the Fundamental Theorem of Calculus can give an incorrect result.\r\n%\r\n%\\begin{example}{Using FTC}{Using FTC}\r\n%Explain why $\\ds\\int_{-1}^1\\frac{1}{x^2}\\,dx$ is not equal to $-2$.\r\n%\\end{example}  \r\n%\r\n%\\begin{solution}\r\n%Here is how one might proceed:  \r\n%$$\r\n%\\int_{-1}^1\\frac{1}{x^2}\\,dx \r\n%~=~ \\int_{-1}^1 x^{-2}\\,dx \r\n%~=~ -x^{-1}\\bigg|_{-1}^1 \r\n%~=~ -\\frac{1}{x}\\bigg|_{-1}^1 \r\n%~=~ \\left(-\\frac{1}{1}\\right) - \\left(-\\frac{1}{(-1)}\\right) \r\n%~=~ -2$$  \r\n% However, the above answer is {\\bf WRONG!} \r\n% Since $f(x)=1/x^2$ is not continuous on $[-1,~1]$, we cannot directly apply the Fundamental Theorem of Calculus.\r\n%Intuitively, we can see why $-2$ is not the correct answer by looking at the graph of $f(x)=1/x^2$ on $[-1,~1]$.\r\n%The shaded area appears to grow without bound as seen in the figure below.\r\n%$$\\includegraphics[width=2.5in]{images2/improper-integral-example-1}$$\r\n%\\end{solution}\r\n%\r\n%Formalizing this example leads to the concept of an improper integral.\r\n%There are two ways to extend the Fundamental Theorem of Calculus.\r\n%One is to use an {\\bf infinite interval}, i.e., $[a,\\infty)$, $(-\\infty,b]$ or $(-\\infty,\\infty)$.\r\n%The second is to allow the interval $[a,b]$ to contain an infinite {\\bf discontinuity} of $f(x)$.\r\n%In either case, the integral is called an {\\bf improper integral}.  \r\n%One of the most important applications of this concept is probability distributions.  \r\n%\r\n%To compute improper integrals, we use the concept of limits along with the Fundamental Theorem of Calculus.\r\n% \r\n%\\begin{definition}{Definitions for Improper Integrals}{Definitions for Improper Integrals}\r\n%If $f(x)$ is continuous on $[a,\\infty)$, then the improper integral of $f$ over $[a,\\infty)$ is:\r\n%$$\\int_{a}^{\\infty} f(x)\\,dx:=\\lim_{R\\to\\infty}\\int_a^R f(x)\\,dx.$$ \r\n%If $f(x)$ is continuous on $(-\\infty,b]$, then the improper integral of $f$ over $(-\\infty,b]$ is:\r\n%$$\\int_{-\\infty}^b f(x)\\,dx:=\\lim_{R\\to -\\infty}\\int_R^b f(x)\\,dx.$$\r\n%\\end{definition}\r\n%\r\n%If the limit exists and is a finite number, we say the improper integral {\\bf converges}. Otherwise, we say the  improper integral {\\bf diverges}.\r\n%\r\n%To get an intuitive (though not completely correct) interpretation of improper integrals, we attempt to analyze $\\ds\\int_a^\\infty f(x)\\,dx$ graphically. \r\n% Here assume $f(x)$ is continuous on $[a,\\infty)$: \r\n%$$\\includegraphics[width=5in]{images2/improper-integral-theory-2}$$ \r\n% We let $R$ be a fixed number in $[a,\\infty)$. \r\n% Then by taking the limit as $R$ approaches $\\infty$, we get the improper integral:  \r\n%$$\\int_a^\\infty f(x)\\,dx:=\\lim_{R\\to\\infty}\\int_a^R f(x)\\,dx.$$ \r\n% We can then apply the Fundamental Theorem of Calculus to the last integral as $f(x)$ is continuous on the closed interval $[a,R]$.\r\n%\r\n%We next define the improper integral for the interval $(-\\infty,~\\infty)$.\r\n%\r\n%\\begin{definition}{Definitions for Improper Integrals}{Definitions for Improper Integrals}\r\n% If both $\\ds\\int_{-\\infty}^a f(x)\\,dx$ and $\\ds\\int_{a}^{\\infty} f(x)\\,dx$ are convergent, then the improper integral of $f$ over $(-\\infty,\\infty)$ is:\r\n%$$\\int_{-\\infty}^{\\infty} f(x)\\,dx:=\\int_{-\\infty}^a f(x)\\,dx+\\int_{a}^{\\infty} f(x)\\,dx$$\r\n%\\end{definition}\r\n%\r\n%The above definition requires {\\bf both} of the integrals\r\n%$$\\int_{-\\infty}^a f(x)\\,dx\\qquad\\mbox{and}\\qquad\\int_{a}^{\\infty} f(x)\\,dx$$\r\n%to be convergent for $\\ds\\int_{-\\infty}^{\\infty} f(x)\\,dx$ to also be convergent. \r\n% If {\\bf either} of $\\ds\\int_{-\\infty}^a f(x)\\,dx$ or $\\ds\\int_{a}^{\\infty} f(x)\\,dx$ is divergent, then so is $\\ds\\int_{-\\infty}^{\\infty} f(x)\\,dx$.\r\n%\r\n%\\begin{example}{Improper Integral}{Improper Integral}\r\n%Determine whether $\\ds\\int_1^\\infty\\frac{1}{x}\\,dx$ is convergent or divergent.\r\n%\\end{example} \r\n%\r\n%\\begin{solution}\r\n% Using the definition for improper integrals we write this as:\r\n%$$\t\\int_1^\\infty \\frac{1}{x}\\,dx= \\lim_{R\\to\\infty} \\int_1^R\\frac{1}{x}\\,dx\r\n%\t= \\lim_{R\\to\\infty} \\ln|x|\\bigg|_1^R\r\n%\t=\\lim_{R\\to\\infty} \\ln|R| - \\ln|1|\r\n%\t= \\lim_{R\\to\\infty} \\ln|R|\r\n%\t= +\\infty$$\r\n% Therefore, the integral is {\\bf divergent}.\r\n%\\end{solution}\r\n%\r\n%\\begin{example}{Improper Integral}{Improper Integral}\r\n%Determine whether $\\ds\\int_{-\\infty}^\\infty x\\sin(x^2)\\,dx$ is convergent or divergent.\r\n%\\end{example}  \r\n%\r\n%\\begin{solution}\r\n% We must compute both $\\ds\\int_0^\\infty x\\sin(x^2)\\,dx$ and $\\ds\\int_{-\\infty}^0 x\\sin(x^2)\\,dx$.  \r\n% Note that we don't have to split the integral up at $0$, any finite value $a$ will work.  \r\n% First we compute the indefinite integral.  \r\n% Let $u=x^2$, then $du=2x\\,dx$ and hence, \r\n%$$\\int x\\sin(x^2)\\,dx=\\frac{1}{2} \\int \\sin(u)\\,du=-\\frac{1}{2}\\cos(x^2)+C$$\r\n%Using the definition of improper integral gives: \r\n%$$\\int_0^\\infty x\\sin(x^2)\\,dx  =  \\lim_{R\\to\\infty} \\int_0^R x\\sin(x^2)\\,dx \r\n%=\\lim_{R\\to\\infty} \\left[-\\frac{1}{2}\\cos(x^2)\\right] \\bigg|_0^R \r\n%=  -\\frac{1}{2} \\lim_{R\\to\\infty} \\cos(R^2) +\\frac{1}{2}$$\r\n%This limit does not exist since $\\cos x$ {\\bf oscillates} between $-1$ and $+1$. \r\n% In particular, $\\cos x$ does not approach any particular value as $x$ gets larger and larger. \r\n% Thus, $\\ds\\int_0^\\infty x\\sin(x^2)\\,dx$ diverges, and hence, $\\ds\\int_{-\\infty}^\\infty x\\sin(x^2)\\,dx$ diverges.\r\n%\\end{solution}\r\n%\r\n%When there is a discontinuity in $[a,b]$ or at an endpoint, then the improper integral is as follows.\r\n%\r\n%\\begin{definition}{Definitions for Improper Integrals}{Definitions for Improper Integrals}\r\n%If $f(x)$ is continuous on $(a,b]$, then the improper integral of $f$ over $(a,b]$ is:  \r\n%$$\\int_a^b f(x)\\,dx:=\\lim_{R\\to a^+}\\int_R^b f(x)\\,dx.$$  \r\n%If $f(x)$ is continuous on $[a,b)$, then the improper integral of $f$ over $[a,b)$ is:  \r\n%$$\\int_a^b f(x)\\,dx:=\\lim_{R\\to b^-}\\int_a^R f(x)\\,dx.$$\r\n%\\end{definition}\r\n%\r\n%If the limit above exists and is a finite number, we say the improper integral {\\bf converges}.\r\n%Otherwise, we say the improper integral {\\bf diverges}. \r\n%\r\n%When there is a discontinuity in the interior of $[a,b]$, we use the following definition.\r\n%\r\n%\\begin{definition}{Definitions for Improper Integrals}{Definitions for Improper Integrals}\r\n%If $f$ has a discontinuity at $x=c$ where $c\\in[a,b]$, and both\r\n%both $\\ds\\int_a^c f(x)\\,dx$ and $\\ds\\int_c^b f(x)\\,dx$ are convergent, then $f$ over $[a,b]$ is:  \r\n%$$\\int_a^b f(x)\\,dx:=\\int_a^c f(x)\\,dx+\\int_c^b f(x)\\,dx$$\r\n%\\end{definition}\r\n%\r\n%Again, we can get an intuitive sense of this concept by analyzing $\\ds\\int_a^b f(x)\\,dx$ graphically. \r\n%Here assume $f(x)$ is continuous on $(a,b]$ but discontinuous at $x=a$: \r\n%$$\\includegraphics[width=5in]{images2/improper-integral-theory-1}$$ \r\n% We let $R$ be a fixed number in $(a,b)$. \r\n% Then by taking the limit as $R$ approaches $a$ from the {\\bf right},  we get the improper integral: \r\n%$$\\int_a^b f(x)\\,dx:=\\lim_{R\\to a^+}\\int_R^b f(x)\\,dx.$$ \r\n% Now we can apply FTC to the last integral as $f(x)$ is continuous on $[R,b]$.\r\n%\r\n%\\begin{example}{A Divergent Integral}{A Divergent Integral}\r\n%Determine if $\\ds\\int_{-1}^1\\frac{1}{x^2}\\,dx$ is convergent or divergent.\r\n%\\end{example}  \r\n%\r\n%\\begin{solution}\r\n% The function $f(x)=1/x^2$ has a discontinuity at $x=0$, which lies in $[-1,1]$.  \r\n% We must compute $\\ds\\int_{-1}^0 \\frac{1}{x^2}\\,dx$ and $\\ds\\int_0^1 \\frac{1}{x^2}\\,dx$. Let's start with $\\ds\\int_0^1 \\frac{1}{x^2}\\,dx$:  \r\n%$$\\int_0^1 \\frac{1}{x^2}\\,dx = \\lim_{R\\to 0^+} \\int_R^1 \\frac{1}{x^2} \\,dx = \\lim_{R\\to 0^+} -\\frac{1}{x}\\bigg|_R^1\r\n%= -1 + \\lim_{R\\to 0^+} \\frac{1}{R}$$\r\n%which diverges to $+\\infty$.\r\n% Therefore, $\\ds\\int_{-1}^1\\frac{1}{x^2}\\,dx$ is {\\bf divergent} since one of $\\ds\\int_{-1}^0 \\frac{1}{x^2}\\,dx$ and $\\ds\\int_0^1 \\frac{1}{x^2}\\,dx$ is divergent.\r\n%\\end{solution}\r\n%\r\n%\r\n%% % % % % % %\r\n%% % The following example 'Integral of the Logarithm' can be replaced with the next example if Integration by Parts is not included in the text adaptation.\r\n%\\begin{example}{Integral of the Logarithm}{Integral of the Logarithm}\r\n%Determine if $\\ds\\int_0^1 \\ln x \\,dx$ is convergent or divergent. Evaluate it if it is convergent.\r\n%\\end{example}  \r\n%\r\n%\\begin{solution}\r\n%Note that $f(x)=\\ln x$ is discontinuous at the endpoint $x=0$. \r\n%We first use integration by parts to compute $\\ds\\int\\ln x\\,dx$.\r\n%We let $u=\\ln x$ and $dv=dx$.\r\n%Then $du=(1/x)dx$, $v=x$, giving:\r\n%\\begin{eqnarray*}\r\n%\\int \\ln x\\,dx &=& \\ds x\\ln x-\\int x\\cdot\\frac{1}{x}\\,dx\\\\\r\n%&=& x\\ln x-\\int 1\\,dx\\\\\r\n%&=& x\\ln x-x+C\\\\\r\n%\\end{eqnarray*}\r\n% Now using the definition of improper integral for $\\ds\\int_0^1 \\ln x \\,dx$: \r\n%$$\r\n%\t\\int_0^1 \\ln x \\,dx = \\lim_{R\\to 0^+} \\int_R^1 \\ln x\\,dx \r\n%\t=  \\lim_{R\\to 0^+} (x\\ln x-x)\\bigg|_R^1 \r\n%\t%=  \\lim_{R\\to 0^+} \\left(\\left[\\ln 1-1\\right] - \\left[R\\ln R-R\\right]\\right)\r\n%\t=  -1 - \\lim_{R\\to 0^+}(R\\ln R) + \\lim_{R\\to 0^+}R \r\n%$$\r\n%Note that $\\ds\\lim_{R\\to 0^+}R=0$. \r\n%We next compute $\\ds\\lim_{R\\to 0^+}(R\\ln R)$.\r\n%First, we rewrite the expression as follows:\r\n%$$\\lim_{x\\to0^+}(R\\ln R)=\\lim_{R\\to0^+}\\frac{\\ln R}{1/R}.$$\r\n%Now the limit is of the indeterminate type $(-\\infty)/(\\infty)$ and l'H\\^opital's Rule can be applied.  \r\n%$$\\lim_{R\\to0^+}(R\\ln R) =\\lim_{R\\to0^+}\\frac{\\ln R}{1/R}\r\n%=\\lim_{R\\to0^+}\\frac{1/R}{-1/R^2}\r\n%=\\lim_{R\\to0^+}-\\frac{R^2}{R}\r\n%=\\lim_{R\\to0^+}(-R)\r\n%=0$$\r\n%Thus, $\\ds\\lim_{R\\to 0^+}(R\\ln R)=0$.\r\n%Thus\r\n%$$\\int_0^1 \\ln x \\,dx = -1,$$ \r\n%and the integral is convergent to $-1$. \r\n%\r\n%Graphically, one might interpret this to mean that the net area under $\\ln x$ on $[0,1]$ is $-1$ (the area in this case lies below the $x$-axis). \r\n%$$\\includegraphics[width=2.5in]{images2/improper-integral-example-2}$$\r\n%\\end{solution}\r\n%\r\n%\\begin{example}{Integral of a Square Root}{IntSquareRoot}\r\n%Determine if $\\ds\\int_0^4\\frac{dx}{\\sqrt{4-x}}$ is convergent or divergent. Evaluate it if it is convergent.\r\n%\\end{example}\r\n%\\begin{solution}\r\n%Note that $\\frac{1}{\\sqrt{4-x}}$ is discontinuous at the endpoint $x=4$. We use a $u$-substitution to compute $\\int \\frac{dx}{\\sqrt{4-x}}$. We let $u=4-x$, then $du=-dx$, giving:\r\n%\\begin{align*}\r\n%\\ds\\int\\frac{dx}{\\sqrt{4-x}}&=\\int-\\frac{du}{u^{1/2}}\t\\\\\r\n%&=\\int -u^{-1/2}\\,du\t\\\\\r\n%&=-2(u)^{1/2}+C\t\\\\\r\n%&=-2\\sqrt{4-x}+C\r\n%\\end{align*}\r\n%Now using the definition of improper integrals for $\\ds\\int_0^4\\frac{dx}{\\sqrt{4-x}}$:\r\n%\\[\\ds\\int_0^4\\frac{dx}{\\sqrt{4-x}}=\\lim_{R\\to4^{-}}(-2\\sqrt{4-x})\\bigg|_0^R=\\lim_{R\\to4^{-}}-2\\sqrt{4-R}+2\\sqrt{4}=4\\]\r\n%\\end{solution}\r\n%\r\n%\\begin{example}{Improper Integral}{ImpIntExample}\r\n%Determine if $\\ds\\int_{1}^{2}\\dfrac{dx}{\\left( x-1\\right) ^{1/3}}$ is\r\n%convergent or divergent. Evaluate it if it is convergent.\r\n%\\end{example}\r\n%\\begin{solution}\r\n%Note that $f\\left( x\\right) =\\dfrac{1}{\\left( x-1\\right) ^{1/3}}$\r\n%is discontinuous at the endpoint $x=1.$ We first use substitution to find\r\n%$\\ds\\int \\dfrac{dx}{\\left( x-1\\right) ^{1/3}}.$ We let $u=x-1.$ Then $du=dx,$\r\n%giving%\r\n%\\begin{equation*}\r\n%\\int \\dfrac{dx}{\\left( x-1\\right) ^{1/3}}=\\int \\frac{du}{u^{1/3}}=\\int\r\n%u^{-1/3}du=\\frac{3}{2}u^{2/3}+C=\\frac{3}{2}\\left( x-1\\right) ^{2/3}+C.\r\n%\\end{equation*}%\r\n%Now using the definition of improper integral for $\\ds\\int_{1}^{2}\\dfrac{dx}{%\r\n%\t\\left( x-1\\right) ^{1/3}}:$%\r\n%\\begin{equation*}\r\n%\\int_{1}^{2}\\dfrac{dx}{\\left( x-1\\right) ^{1/3}}=\\lim_{R\\rightarrow\r\n%\t1^{+}}\\int_{R}^{2}\\dfrac{dx}{\\left( x-1\\right) ^{1/3}}=\\left.\r\n%\\lim_{R\\rightarrow 1^{+}}\\frac{3}{2}\\left( x-1\\right) ^{2/3}\\right\\vert\r\n%_{R}^{2}=\\frac{3}{2}-\\lim_{R\\rightarrow 1^{+}}\\frac{3}{2}\\left( R-1\\right)\r\n%^{2/3}=\\frac{3}{2},\r\n%\\end{equation*}%\r\n%and the integral is convergent to $\\frac{3}{2}.$ Graphically, one might\r\n%interpret this to mean that the net area under $\\dfrac{1}{\\left( x-1\\right)\r\n%\t^{1/3}}$ on $\\left[ 1,2\\right] $ is $\\frac{3}{2}$.\r\n%\r\n%$$\\includegraphics[width=8cm]{images/improper-int-example}$$\r\n%\\end{solution}\r\n%\r\n%The following test allows us to determine convergence/divergence information about improper integrals that are hard to compute by comparing them to easier ones. \r\n%We state the test for $[a,\\infty)$, but similar versions hold for the other improper integrals.\r\n%\r\n%\\begin{formulabox}[The Comparison Test]\r\n%Assume that $f(x)\\geq g(x)\\geq 0$ for $x\\geq a$.\r\n%\\begin{enumerate}[(i)]\r\n%\\item\tIf $\\ds\\int_a^\\infty f(x)\\,dx$ {\\bf converges}, then $\\ds\\int_a^\\infty g(x)\\,dx$ also {\\bf converges}.\r\n%\\item\tIf $\\ds\\int_a^\\infty g(x)\\,dx$ {\\bf diverges}, then $\\ds\\int_a^\\infty f(x)\\,dx$ also {\\bf diverges}. \r\n%\\end{enumerate}\r\n%\\end{formulabox}\r\n%\r\n%Informally, (i) says that if $f(x)$ is larger than $g(x)$, and the area under $f(x)$ is finite (converges), then the area under $g(x)$ must also be finite (converges). \r\n%Informally, (ii) says that if $f(x)$ is larger than $g(x)$, and the area under $g(x)$ is infinite (diverges), then the area under $f(x)$ must also be infinite (diverges). \r\n%\r\n%$$\\includegraphics[width=6in]{images2/improper-integral-theory-3}$$\r\n%\r\n%\\begin{example}{Comparison Test}{Comparison Test}\r\n%Show that $\\ds\\int_2^\\infty \\frac{\\cos^2x}{x^2} \\,dx$ converges.\r\n%\\end{example} \r\n%\r\n%\\begin{solution}\r\n%We use the comparison test to show that it converges. \r\n%Note that $0\\leq \\cos^2x\\leq 1$ and hence \r\n%$$0 \\leq\\frac{\\cos^2x}{x^2}\\leq\\frac{1}{x^2}.$$\r\n%Thus, taking $f(x)=1/x^2$ and $g(x)=\\cos^2x / x^2$ we have $f(x)\\geq g(x)\\geq 0$. \r\n%One can easily see that $\\ds\\int_2^\\infty \\frac{1}{x^2}\\,dx$ converges. \r\n%Therefore, $\\ds\\int_2^\\infty \\frac{\\cos^2x}{x^2} \\,dx$ also converges.\r\n%\\end{solution}\r\n\r\n\r\n\r\nWe begin this section by considering the following definite integrals:\r\n\\begin{itemize}\r\n\\item\t$\\ds \\int_0^{100}\\frac1{1+x^2}\\ dx \\approx 1.5608,$\r\n\\item\t$\\ds \\int_0^{1000}\\frac1{1+x^2}\\ dx \\approx 1.5698,$\r\n\\item\t$\\ds \\int_0^{10,000}\\frac1{1+x^2}\\ dx \\approx 1.5707.$\r\n\\end{itemize}\r\n\r\nNotice how the integrand is $1/(1+x^2)$ in each integral (which is sketched in Figure \\ref{fig:improper1}). As the upper bound gets larger, one would expect the ``area under the curve'' would also grow. While the definite integrals do increase in value as the upper bound grows, they are not  increasing by much. In fact, consider:\r\n$$\\int_0^b \\frac{1}{1+x^2}\\ dx = \\tan^{-1}x\\Big|_0^b = \\tan^{-1}b-\\tan^{-1}0 = \\tan^{-1}b.$$\r\nAs $b\\rightarrow \\infty$, $\\tan^{-1}b \\rightarrow \\pi/2.$ Therefore it seems that as the upper bound $b$ grows, the value of the definite integral $\\ds \\int_0^b\\frac{1}{1+x^2}\\ dx$ approaches $\\pi/2\\approx 1.5708$. This should strike the reader as being a bit amazing: even though the curve extends ``to infinity,'' it has a finite amount of area underneath it.\r\n\r\n\\mfigure{.75}{Graphing $\\ds f(x)=\\frac{1}{1+x^2}$.}{fig:improper1}{\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=\\textwidth,%\r\naxis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick={-1,1},% \r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n%\t\t\tytick={-1,1},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=1.1,%\r\n\t\t\txmin=-1,xmax=11%\r\n]\r\n\r\n\\addplot [{\\coloronefill},fill={\\coloronefill}] coordinates {(0,1.)(0.1,0.9901)(0.2,0.9615)(0.3,0.9174)(0.4,0.8621)(0.5,0.8)(0.6,0.7353)(0.7,0.6711)(0.8,0.6098)(0.9,0.5525)(1.,0.5)(1.5,0.3077)(2.,0.2)(2.5,0.1379)(3.,0.1)(3.5,0.07547)(4.,0.05882)(4.5,0.04706)(5.,0.03846)(5.5,0.032)(6.,0.02703)(6.5,0.02312)(7.,0.02)(7.5,0.01747)(8.,0.01538)(8.5,0.01365)(9.,0.0122)(9.5,0.01096)(10.,0.009901)(10.5,0.0089)} -- (axis cs:0,0)--cycle;\r\n\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(0,1.)(0.1,0.9901)(0.2,0.9615)(0.3,0.9174)(0.4,0.8621)(0.5,0.8)(0.6,0.7353)(0.7,0.6711)(0.8,0.6098)(0.9,0.5525)(1.,0.5)(1.5,0.3077)(2.,0.2)(2.5,0.1379)(3.,0.1)(3.5,0.07547)(4.,0.05882)(4.5,0.04706)(5.,0.03846)(5.5,0.032)(6.,0.02703)(6.5,0.02312)(7.,0.02)(7.5,0.01747)(8.,0.01538)(8.5,0.01365)(9.,0.0122)(9.5,0.01096)(10.,0.009901)(10.5,0.0089)};\r\n\r\n%\\filldraw (axis cs:.707,.707) circle (1pt) node [shift={(6pt,11pt)}] {\\scriptsize ($\\cos \\theta$,$\\sin \\theta$)};\r\n%\r\n%\\draw (axis cs:.6,.25) node {\\scriptsize $\\ds\\frac{\\theta}{2}$};\r\n%\\draw (axis cs:-.75,1) node {\\scriptsize $x^2+y^2=1$};\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) { $y$};\r\n\\end{tikzpicture}\r\n}\r\n\r\nWhen we defined the definite integral $\\ds\\int_a^b f(x)\\ dx$, we made two stipulations:\r\n\t\\begin{enumerate}\r\n\t\\item\t\tThe interval over which we integrated, $[a,b]$, was a finite interval, and\r\n\t\\item\t\tThe function $f(x)$ was continuous on $[a,b]$ (ensuring that the range of $f$ was finite).\r\n\t\\end{enumerate}\r\n\t\r\nIn this section we consider integrals where one or both of the above conditions do not hold. Such integrals are called \\textbf{improper integrals.}\r\n\r\n\\subsection*{Improper Integrals with Infinite Bounds}\r\n\r\n\\begin{definition}{Improper Integrals with Infinite Bounds; Converge, Diverge}{def:imp_int1}\r\n{\r\n\\begin{enumerate}\r\n\\item\t\tLet $f$ be a continuous function on $[a,\\infty)$. Define \\index{integration!improper}\\index{improper integration}\\index{convergence!of improper int.}\\index{divergence!of improper int.}\r\n$$\\small\\int_a^\\infty f(x)\\ dx \\quad \\text{to be}\\quad \\lim_{b\\to\\infty}\\int_a^b f(x)\\ dx.$$\r\n\r\n\\item\t\tLet $f$ be a continuous function on $(-\\infty,b]$. Define\r\n$$\\small\\int_{-\\infty}^b f(x)\\ dx \\quad \\text{to be}\\quad \\lim_{a\\to-\\infty}\\int_a^b f(x)\\ dx.$$\r\n\r\n\\item\t\tLet $f$ be a continuous function on $(-\\infty,\\infty)$. Let $c$ be any real number; define\r\n$$\\small\\int_{-\\infty}^\\infty f(x)\\ dx \\quad \\text{to be}\\quad \\lim_{a\\to-\\infty}\\int_a^c f(x)\\ dx\\ +\\ \\lim_{b\\to\\infty}\\int_c^b f(x)\\ dx.$$\r\n\\end{enumerate}\r\nAn improper integral is said to \\textbf{converge} if its corresponding limit exists; otherwise, it \\textbf{diverges}. The improper integral in part 3 converges if and only if both of its limits exist.\r\n}\r\n\\end{definition}\r\n\r\n\r\n\\begin{example}{Evaluating improper integrals}{ex_impint1}\r\n{\r\nEvaluate the following improper integrals.\\\\\r\n\\noindent%\r\n\\begin{minipage}[t]{.5\\textwidth}\r\n\\begin{enumerate}\r\n\\item\t\t$\\ds\\int_1^\\infty \\frac1{x^2}\\ dx$\r\n\\item\t\t$\\ds\\int_1^\\infty \\frac1x\\ dx$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n\\begin{minipage}[t]{.5\\textwidth}\r\n\\begin{enumerate}\\addtocounter{enumi}{2}\r\n\\item\t\t$\\ds\\int_{-\\infty}^0 e^x\\ dx$\r\n\\item\t\t$\\ds\\int_{-\\infty}^\\infty \\frac1{1+x^2}\\ dx$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{\\begin{enumerate}\r\n\\item\t\t\\hfill$\\begin{aligned}[t] \\int_1^\\infty \\frac{1}{x^2}\\ dx\\  =\\ \\lim_{b\\to\\infty} \\int_1^b\\frac1{x^2}\\ dx\\  &=\\ \\lim_{b\\to\\infty} \\frac{-1}{x}\\Big|_1^b \\\\ \r\n %&= \\lim_{b\\to\\infty} \\frac{-1}{x}\\Big|_1^b \\\\\r\n &= \\lim_{b\\to\\infty} \\frac{-1}{b} + 1\\\\\r\n &= 1.\\end{aligned}$\\hfill\\null\r\n\r\nA graph of the area defined by this integral is given in Figure \\ref{fig:impint1a}.\r\n \r\n\\mfigure{.7}{A graph of $f(x) = \\frac{1}{x^2}$ in Example \\ref{exa:ex_impint1}.}{fig:impint1a}{\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=\\textwidth,%\r\ntick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick={1,5,10},% \r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n%\t\t\tytick={-1,1},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=1.1,%\r\n\t\t\txmin=-1,xmax=11%\r\n]\r\n\r\n\\addplot [{\\coloronefill},fill={\\coloronefill}] coordinates {(1.,1.)(1.5,0.4444)(2.,0.25)(2.5,0.16)(3.,0.1111)(3.5,0.08163)(4.,0.0625)(4.5,0.04938)(5.,0.04)(5.5,0.03306)(6.,0.02778)(6.5,0.02367)(7.,0.02041)(7.5,0.01778)(8.,0.01563)(8.5,0.01384)(9.,0.01235)(9.5,0.01108)(10.,0.01)(10.5,0.009)} -- (axis cs:10.5,0)--(axis cs:1,0)--cycle;\r\n\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(1.,1.)(1.5,0.4444)(2.,0.25)(2.5,0.16)(3.,0.1111)(3.5,0.08163)(4.,0.0625)(4.5,0.04938)(5.,0.04)(5.5,0.03306)(6.,0.02778)(6.5,0.02367)(7.,0.02041)(7.5,0.01778)(8.,0.01563)(8.5,0.01384)(9.,0.01235)(9.5,0.01108)(10.,0.01)(10.5,0.009)};\r\n\r\n\\draw (axis cs:5,.75) node {\\scriptsize $\\ds f(x)=\\frac{1}{x^2}$};\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) { $y$};\r\n\\end{tikzpicture}\r\n}\r\n \r\n\\item\t\t\\hfill$\\begin{aligned}[t]%\r\n\t\t\t\\int_1^\\infty \\frac1x\\ dx & = \\lim_{b\\to\\infty}\\int_1^b\\frac1x\\ dx \\\\\r\n\t\t\t\t\t\t&= \\lim_{b\\to\\infty} \\ln |x|\\Big|_1^b \\\\\r\n\t\t\t\t\t\t&= \\lim_{b\\to\\infty} \\ln (b)\\\\\r\n\t\t\t\t\t\t&= \\infty.\r\n\t\\end{aligned}$\\hfill\\null\r\n\t\r\nThe limit does not exist, hence the improper integral $\\ds\\int_1^\\infty\\frac1x\\ dx$ diverges. Compare the graphs in Figures \\ref{fig:impint1a} and \\ref{fig:impint1b}; notice how the graph of $f(x) = 1/x$ is noticeably larger. This difference is enough to cause the improper integral to diverge.\r\n\r\n\\mfigure{.8}{A graph of $f(x) = \\frac{1}{x}$ in Example \\ref{exa:ex_impint1}.}{fig:impint1b}{\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=\\textwidth,%\r\naxis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick={1,5,10},% \r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n%\t\t\tytick={-1,1},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=1.1,%\r\n\t\t\txmin=-1,xmax=11%\r\n]\r\n\r\n\\addplot [{\\coloronefill},fill={\\coloronefill}] coordinates {(1.,1.)(1.5,0.6667)(2.,0.5)(2.5,0.4)(3.,0.3333)(3.5,0.2857)(4.,0.25)(4.5,0.2222)(5.,0.2)(5.5,0.1818)(6.,0.1667)(6.5,0.1538)(7.,0.1429)(7.5,0.1333)(8.,0.125)(8.5,0.1176)(9.,0.1111)(9.5,0.1053)(10.,0.1)(10.5,0.09524)} -- (axis cs:10.5,0)-- (axis cs:1,0)--cycle;\r\n\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(1.,1.)(1.5,0.6667)(2.,0.5)(2.5,0.4)(3.,0.3333)(3.5,0.2857)(4.,0.25)(4.5,0.2222)(5.,0.2)(5.5,0.1818)(6.,0.1667)(6.5,0.1538)(7.,0.1429)(7.5,0.1333)(8.,0.125)(8.5,0.1176)(9.,0.1111)(9.5,0.1053)(10.,0.1)(10.5,0.09524)};\r\n\r\n\\draw (axis cs:5,.75) node { $\\ds f(x)=\\frac{1}{x}$};\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) { $y$};\r\n\\end{tikzpicture}\r\n}\r\n\r\n\\item\t\t\\hfill$\\begin{aligned}[t]%\r\n\t\t\t\\int_{-\\infty}^0 e^x \\ dx &= \\lim_{a\\to-\\infty} \\int_a^0e^x\\ dx \\\\\r\n\t\t\t\t\t&=  \\lim_{a\\to-\\infty} e^x\\Big|_a^0 \\\\\r\n\t\t\t\t\t&= \\lim_{a\\to-\\infty} e^0-e^a \\\\\r\n\t\t\t\t\t&= 1.\r\n\t\t\\end{aligned}$\\hfill\\null\r\n\t\t\r\n\t\tA graph of the area defined by this integral is given in Figure \\ref{fig:impint1c}.\r\n\t\t\r\n\\mfigure{.55}{A graph of $f(x) = e^x$ in Example \\ref{exa:ex_impint1}.}{fig:impint1c}{\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=\\textwidth,%\r\naxis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick={-1,-5,-10},%\r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n\t\t\tytick={1},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=1.1,%\r\n\t\t\txmin=-11,xmax=1%\r\n]\r\n\r\n\\addplot [{\\coloronefill},fill={\\coloronefill}] coordinates {(-10.5,0)(-10.,0)(-9.5,0)(-9.,0.0001234)(-8.5,0.0002035)(-8.,0.0003355)(-7.5,0.0005531)(-7.,0.0009119)(-6.5,0.001503)(-6.,0.002479)(-5.5,0.004087)(-5.,0.006738)(-4.5,0.01111)(-4.,0.01832)(-3.5,0.0302)(-3.,0.04979)(-2.5,0.08208)(-2.,0.1353)(-1.5,0.2231)(-1.,0.3679)(-0.5,0.6065)(0,1.)} -- (axis cs:0,0)--cycle;\r\n\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(-10.5,0)(-10.,0)(-9.5,0)(-9.,0.0001234)(-8.5,0.0002035)(-8.,0.0003355)(-7.5,0.0005531)(-7.,0.0009119)(-6.5,0.001503)(-6.,0.002479)(-5.5,0.004087)(-5.,0.006738)(-4.5,0.01111)(-4.,0.01832)(-3.5,0.0302)(-3.,0.04979)(-2.5,0.08208)(-2.,0.1353)(-1.5,0.2231)(-1.,0.3679)(-0.5,0.6065)(0,1.)};\r\n\r\n\\draw (axis cs:-5,.75) node {\\scriptsize $\\ds f(x)=e^x$};\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) { $y$};\r\n\\end{tikzpicture}\r\n}\r\n\r\n\\item\t\tWe will need to break this into two improper integrals and choose a value of $c$ as in part 3 of Definition \\ref{def:imp_int1}. Any value of $c$ is fine; we choose $c=0$.\r\n\r\n\\begin{align*}%\r\n\t\t\\int_{-\\infty}^\\infty \\frac1{1+x^2}\\ dx &= \\lim_{a\\to-\\infty} \\int_a^0\\frac{1}{1+x^2}\\ dx + \\lim_{b\\to\\infty} \\int_0^b\\frac{1}{1+x^2}\\ dx \\\\\r\n\t\t\t\t\t\t&= \\lim_{a\\to-\\infty} \\tan^{-1}x\\Big|_a^0 + \\lim_{b\\to\\infty} \\tan^{-1}x\\Big|_0^b\\\\\r\n\t\t\t\t\t\t&= \\lim_{a\\to-\\infty} \\left(\\tan^{-1}0-\\tan^{-1}a\\right) + \\lim_{b\\to\\infty} \\left(\\tan^{-1}b-\\tan^{-1}0\\right)\\\\\t\t\r\n\t\t\t\t\t\t&= \\left(0-\\frac{-\\pi}2\\right) + \\left(\\frac{\\pi}2-0\\right).\\\\\r\n\t\t\t\t\t\t\\intertext{Each\tlimit exists, hence the original integral converges and has value:}\r\n\t\t\t\t\t\t&= \\pi.\r\n\\end{align*}\r\n%\\enlargethispage{2\\baselineskip}\r\nA graph of the area defined by this integral is given in Figure \\ref{fig:impint1d}.\r\n\r\n\\mfigure{.8}{A graph of $f(x) = \\frac{1}{1+x^2}$ in Example \\ref{exa:ex_impint1}.}{fig:impint1d}{\\begin{tikzpicture}\r\n\\begin{axis}[width=\\textwidth,%\r\naxis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick={-1,-5,-10},%\r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n\t\t\tytick={1},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=1.1,%\r\n\t\t\txmin=-11,xmax=11%\r\n]\r\n\r\n\\addplot [{\\coloronefill},fill={\\coloronefill}] coordinates {(-10.5,0.008989)(-10.,0.009901)(-9.5,0.01096)(-9.,0.0122)(-8.5,0.01365)(-8.,0.01538)(-7.5,0.01747)(-7.,0.02)(-6.5,0.02312)(-6.,0.02703)(-5.5,0.032)(-5.,0.03846)(-4.5,0.04706)(-4.,0.05882)(-3.5,0.07547)(-3.,0.1)(-2.5,0.1379)(-2.,0.2)(-1.5,0.3077)(-1.,0.5)(-0.5,0.8)(0,1.)(0.5,0.8)(1.,0.5)(1.5,0.3077)(2.,0.2)(2.5,0.1379)(3.,0.1)(3.5,0.07547)(4.,0.05882)(4.5,0.04706)(5.,0.03846)(5.5,0.032)(6.,0.02703)(6.5,0.02312)(7.,0.02)(7.5,0.01747)(8.,0.01538)(8.5,0.01365)(9.,0.0122)(9.5,0.01096)(10.,0.009901)(10.5,0.008989)} --cycle;\r\n\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(-10.5,0.008989)(-10.,0.009901)(-9.5,0.01096)(-9.,0.0122)(-8.5,0.01365)(-8.,0.01538)(-7.5,0.01747)(-7.,0.02)(-6.5,0.02312)(-6.,0.02703)(-5.5,0.032)(-5.,0.03846)(-4.5,0.04706)(-4.,0.05882)(-3.5,0.07547)(-3.,0.1)(-2.5,0.1379)(-2.,0.2)(-1.5,0.3077)(-1.,0.5)(-0.5,0.8)(0,1.)(0.5,0.8)(1.,0.5)(1.5,0.3077)(2.,0.2)(2.5,0.1379)(3.,0.1)(3.5,0.07547)(4.,0.05882)(4.5,0.04706)(5.,0.03846)(5.5,0.032)(6.,0.02703)(6.5,0.02312)(7.,0.02)(7.5,0.01747)(8.,0.01538)(8.5,0.01365)(9.,0.0122)(9.5,0.01096)(10.,0.009901)(10.5,0.008989)};\r\n\r\n\\draw (axis cs:6,.75) node { $\\ds f(x)=\\frac{1}{1+x^2}$};\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) { $y$};\r\n\\end{tikzpicture}\r\n}\r\n\\end{enumerate}\r\n\\vskip-\\baselineskip\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nThe previous section introduced l'H\\^opital's Rule, a method of evaluating limits that return indeterminate forms. It is not uncommon for the limits resulting from improper integrals to need this rule as demonstrated next.\\\\\r\n\r\n\r\n\\begin{example}{Improper integration and l'H\\^opital's Rule}{ex_impint2}\r\n{\r\nEvaluate the improper integral $\\ds \\int_1^\\infty \\frac{\\ln x}{x^2}\\ dx.$}\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{This integral will require the use of Integration by Parts. Let $u = \\ln x$ and $dv = 1/x^2\\ dx$. Then\r\n\\mfigure{.6}{A graph of $f(x) = \\frac{\\ln x}{x^2}$ in Example \\ref{exa:ex_impint2}.}{fig:impint2}{\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=\\textwidth,%\r\naxis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick={1,5,10},%\r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n%\t\t\tytick={1},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=.2,%\r\n\t\t\txmin=-.1,xmax=10.5%\r\n]\r\n\r\n%\\addplot [{\\coloronefill},fill={\\coloronefill}] coordinates {(0.1,3.162)(0.2,2.236)(0.3,1.826)(0.4,1.581)(0.5,1.414)(0.6,1.291)(0.7,1.195)(0.8,1.118)(0.9,1.054)(1.,1.)} -- (axis cs:1,0)--(axis cs:.1,0)--cycle;\r\n\r\n\\addplot [smooth,\\colorone, fill={\\coloronefill},area style,domain=1:10.5] {(ln(x))/(x^2)} \\closedcycle;\r\n\r\n%\\addplot [{\\colorone},thick,smooth] coordinates {(0.1,3.162)(0.2,2.236)(0.3,1.826)(0.4,1.581)(0.5,1.414)(0.6,1.291)(0.7,1.195)(0.8,1.118)(0.9,1.054)(1.,1.)};\r\n\r\n\\draw (axis cs:5,.15) node {$\\ds f(x)=\\frac{\\ln(x)}{x^2}$};\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) {$y$};\r\n\\end{tikzpicture}\r\n}\r\n\\begin{align*}\r\n\\int_1^\\infty\\frac{\\ln x}{x^2}\\ dx &= \\lim_{b\\to\\infty}\\int_1^b\\frac{\\ln x}{x^2}\\ dx \\\\\r\n\t\t\t&=  \\lim_{b\\to\\infty}\\left(-\\frac{\\ln x}{x}\\Big|_1^b +\\int_1^b \\frac{1}{x^2} \\ dx \\right)\\\\\r\n\t\t\t&=  \\lim_{b\\to\\infty} \\left.\\left(-\\frac{\\ln x}{x} -\\frac1x\\right)\\right|_1^b\\\\\r\n\t\t\t&=\t\\lim_{b\\to\\infty} \\left(-\\frac{\\ln b}{b}-\\frac1b - \\left(-\\ln 1-1\\right)\\right).\\\\\r\n\t\t\t\\intertext{The $1/b$ and $\\ln 1$ terms go to 0, leaving $\\ds \\lim_{b\\to\\infty} -\\frac{\\ln b}b + 1.$ We need to evaluate $\\ds \\lim_{b\\to\\infty} \\frac{\\ln b}{b}$ with l'H\\^opital's Rule. We have:}\r\n\t\t\\lim_{b\\to\\infty}\\frac{\\ln b}b &\\stackrel{\\ \\text{ by LHR \\rule[-5pt]{0pt}{3pt}} \\ }{=} \\lim_{b\\to\\infty} \\frac{1/b}{1} \\\\\r\n\t\t&= 0.\r\n\\intertext{Thus the improper integral evaluates as: }\r\n\\int_1^\\infty\\frac{\\ln x}{x^2}\\ dx &= 1.\r\n\\end{align*}\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\\subsection*{Improper Integrals with Infinite Range}\r\n\r\nWe have just considered definite integrals where the interval of integration was infinite. We now consider another type of improper integration, where the range of the integrand is infinite.\r\n\r\n\r\n\\begin{definition}{Improper Integration with Infinite Range}{def:imp_int2}\r\n{Let $f(x)$ be a continuous function on $[a,b]$ except at $c$, $a\\leq c\\leq b$, where $x=c$ is a vertical asymptote of $f$. Define\\index{integration!improper}\\index{improper integration}\r\n$$\\int_a^b f(x)\\ dx = \\lim_{t\\to c^-}\\int_a^t f(x)\\ dx + \\lim_{t\\to c^+}\\int_t^b f(x)\\ dx.$$\r\nAgain, the integral converges if both limits exist and diverges otherwise.\r\n} \r\n\\end{definition}\r\n\r\n\r\n\\begin{example}{Improper integration of functions with infinite range}{ex_impint3}\r\n{\r\nEvaluate the following improper integrals:\r\n\\vskip 10pt\r\n$\\ds 1.\\ \\int_0^1\\frac1{\\sqrt{x}}\\ dx \\hskip 50pt 2. \\ \\int_{-1}^1\\frac{1}{x^2}\\ dx.$\r\n}\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{\\begin{enumerate}\r\n\\item\t\tA graph of $f(x) = 1/\\sqrt{x}$ is given in Figure \\ref{fig:impint3}. Notice that $f$ has a vertical asymptote at $x=0$; in some sense, we are trying to compute the area of a region that has no ``top.'' Could this have a finite value? \r\n\\begin{align*} \\int_0^1 \\frac{1}{\\sqrt{x}}\\ dx &= \\lim_{a\\to0^+}\\int_a^1 \\frac1{\\sqrt{x}}\\ dx \\\\\r\n\t\t\t&=\t\\lim_{a\\to0^+} 2\\sqrt{x}\\Big|_a^1 \\\\\r\n\t\t\t&= \\lim_{a\\to0^+} 2\\left(\\sqrt{1}-\\sqrt{a}\\right)\\\\\r\n\t\t\t&=\t2.\r\n\\end{align*}\r\nIt turns out that the region does have a finite area even though it has no upper bound (strange things can occur in mathematics when considering the infinite).\r\n\r\n{\\textbf{Note:} In Definition \\ref{def:imp_int2}, $c$ can be one of the endpoints ($a$ or $b$). In that case, there is only one limit to consider as part of the definition.}\r\n\r\n\\mfigure{.65}{A graph of $f(x)=\\frac{1}{\\sqrt{x}}$ in Example \\ref{exa:ex_impint3}.}{fig:impint3}{\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=\\textwidth,%\r\naxis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick={1,5,10},%\r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n%\t\t\tytick={1},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=11,%\r\n\t\t\txmin=-.1,xmax=1.1%\r\n]\r\n\r\n\\addplot [{\\coloronefill},fill={\\coloronefill}] coordinates {(0.01,10.)(0.02,7.071)(0.03,5.774)(0.04,5.)(0.05,4.472)(0.06,4.082)(0.07,3.78)(0.08,3.536)(0.09,3.333)(0.1,3.162)(0.11,3.015)(0.12,2.887)(0.13,2.774)(0.14,2.673)(0.15,2.582)(0.16,2.5)(0.17,2.425)(0.18,2.357)(0.19,2.294)(0.2,2.236)(0.3,1.826)(0.4,1.581)(0.5,1.414)(0.6,1.291)(0.7,1.195)(0.8,1.118)(0.9,1.054)(1.,1.)} -- (axis cs:1,0)--(axis cs:.01,0)--cycle;\r\n\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(0.01,10.)(0.02,7.071)(0.03,5.774)(0.04,5.)(0.05,4.472)(0.06,4.082)(0.07,3.78)(0.08,3.536)(0.09,3.333)(0.1,3.162)(0.11,3.015)(0.12,2.887)(0.13,2.774)(0.14,2.673)(0.15,2.582)(0.16,2.5)(0.17,2.425)(0.18,2.357)(0.19,2.294)(0.2,2.236)(0.3,1.826)(0.4,1.581)(0.5,1.414)(0.6,1.291)(0.7,1.195)(0.8,1.118)(0.9,1.054)(1.,1.)};\r\n\r\n\\draw (axis cs:.5,5) node { $\\ds f(x)=\\frac{1}{\\sqrt{x}}$};\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n}\r\n\r\n\\item\t\tThe function $f(x) = 1/x^2$ has a vertical asymptote at $x=0$, as shown in Figure \\ref{fig:impint3b}, so this integral is an improper integral. Let's eschew using limits for a moment and proceed without recognizing the improper nature of the integral. This leads to:\r\n\\begin{align*}\r\n\\int_{-1}^1\\frac1{x^2}\\ dx &= -\\frac1x\\Big|_{-1}^1\\\\\r\n\t\t\t&= -1 - (1)\\\\\r\n\t\t\t&=-2 !\r\n\\end{align*}\r\n\\mfigure{.6}{A graph of $f(x)=\\frac{1}{x^2}$ in Example \\ref{exa:ex_impint3}.}{fig:impint3b}{\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=\\textwidth,%\r\naxis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick={.1,.5,1},%\r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n%\t\t\tytick={1},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=11,%\r\n\t\t\txmin=-1.1,xmax=1.1%\r\n]\r\n\r\n\\addplot [{\\coloronefill},fill={\\coloronefill},smooth] coordinates {(-1.,1.)(-0.9,1.235)(-0.8,1.563)(-0.7,2.041)(-0.6,2.778)(-0.5,4.)(-0.4,6.25)(-0.3,11.11)(-0.2,25.)} -- (axis cs:0,11)--(axis cs:0,0)--(axis cs:-1,0) --cycle;\r\n\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(-1.,1.)(-0.9,1.235)(-0.8,1.563)(-0.7,2.041)(-0.6,2.778)(-0.5,4.)(-0.4,6.25)(-0.3,11.11)(-0.2,25.)};\r\n\r\n\\addplot [{\\coloronefill},fill={\\coloronefill},smooth] coordinates {(0.2,25.)(0.3,11.11)(0.4,6.25)(0.5,4.)(0.6,2.778)(0.7,2.041)(0.8,1.563)(0.9,1.235)(1.,1.)} -- (axis cs:1,0)--(axis cs:0,0)--(axis cs:0,11) --cycle;\r\n\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(0.2,25.)(0.3,11.11)(0.4,6.25)(0.5,4.)(0.6,2.778)(0.7,2.041)(0.8,1.563)(0.9,1.235)(1.,1.)};\r\n\r\n\\draw (axis cs:.7,7) node { $\\ds f(x)=\\frac{1}{x^2}$};\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n}\r\nClearly the area in question is above the $x$-axis, yet the area is supposedly negative! Why does our answer not match our intuition? To answer this, evaluate the integral using Definition \\ref{def:imp_int2}.\r\n\\begin{align*}\r\n\\int_{-1}^1\\frac1{x^2}\\ dx &= \\lim_{t\\to0^-}\\int_{-1}^t \\frac1{x^2}\\ dx + \\lim_{t\\to0^+}\\int_t^1\\frac1{x^2}\\ dx \\\\\r\n\t\t\t&= \\lim_{t\\to0^-}-\\frac1x\\Big|_{-1}^t + \\lim_{t\\to0^+}-\\frac1x\\Big|_t^1\\\\\r\n\t\t\t&= \\lim_{t\\to0^-}-\\frac1t-1 + \\lim_{t\\to0^+} -1+\\frac1t\\\\\r\n\t\t\t&\\Rightarrow \\Big(\\infty-1\\Big)\\ + \\ \\Big(- 1+\\infty\\Big).\r\n\\end{align*}\r\nNeither limit converges hence the original improper integral diverges. The nonsensical answer we obtained by ignoring the improper nature of the integral is just that: nonsensical.\r\n%\\mnote{.8}{\\textbf{Note:} In Example \\ref{ex_impint3}, \\#2, the final line of calculation states:\r\n%$$\\text{``}(\\infty-1)+(-\\infty-1)\\text{.''}$$ \r\n%Each parenthetical statement stands alone and is the result of an individual limit. We are \\textit{not} dealing with the indeterminate form ``$\\infty-\\infty$'' as the ``infinities'' do not originate from one limit.}\r\n\\end{enumerate}\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\\subsection*{ Understanding Convergence and Divergence}\r\n\r\nOftentimes we are interested in knowing simply whether or not an improper integral converges, and not necessarily the value of a convergent integral. We provide here several tools that help determine the convergence or divergence of improper integrals without integrating.\r\n\r\nOur first tool is to understand the behavior of functions of the form $\\ds \\frac1{x\\hskip1pt ^p}$.\\\\\r\n\r\n\\begin{example}{Improper integration of $1/x^p$}{ex_impint4}\r\n{\r\nDetermine the values of $p$ for which $\\ds \\int_1^\\infty \\frac1{x\\hskip1pt ^p}\\ dx$ converges.\r\n}\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{We begin by integrating and then evaluating the limit.\r\n\\begin{align*}\r\n\\int_1^\\infty \\frac1{x\\hskip1pt ^p}\\ dx &=\t\\lim_{b\\to\\infty}\\int_1^b\\frac1{x\\hskip1pt ^p}\\ dx\\\\\r\n\t\t&=\t\\lim_{b\\to\\infty}\\int_1^b x^{-p}\\ dx \\qquad \\text{\\small (assume $p\\neq 1$)}\\\\\r\n\t\t&= \\lim_{b\\to\\infty} \\frac{1}{-p+1}x^{-p+1}\\Big|_1^b\\\\\r\n\t\t&= \\lim_{b\\to\\infty} \\frac{1}{1-p}\\big(b\\hskip1pt^{1-p}-1^{1-p}\\big).\\\\\r\n\\end{align*}\r\nWhen does this limit converge -- i.e., when is this limit \\textit{not} $\\infty$? This limit converges precisely when the power of $b$ is less than 0: when $1-p<0 \\Rightarrow 1<p$. \r\n\r\n\\mfigure{.75}{Plotting functions of the form $1/x\\,^p$ in Example \\ref{exa:ex_impint4}.}{fig:impint4}{\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=\\textwidth,%\r\naxis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick={1},%\r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n\t\t\tytick=\\empty,\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=6,%\r\n\t\t\txmin=-.1,xmax=2.1%\r\n]\r\n\r\n\\addplot [dashed,thick,smooth] coordinates {(0.1,10.)(0.15,6.667)(0.2,5.)(0.25,4.)(0.3,3.333)(0.35,2.857)(0.4,2.5)(0.45,2.222)(0.5,2.)(0.55,1.818)(0.6,1.667)(0.65,1.538)(0.7,1.429)(0.75,1.333)(0.8,1.25)(0.85,1.176)(0.9,1.111)(0.95,1.053)(1.,1.)(1.05,0.9524)(1.1,0.9091)(1.15,0.8696)(1.2,0.8333)(1.25,0.8)(1.3,0.7692)(1.35,0.7407)(1.4,0.7143)(1.45,0.6897)(1.5,0.6667)(1.55,0.6452)(1.6,0.625)(1.65,0.6061)(1.7,0.5882)(1.75,0.5714)(1.8,0.5556)(1.85,0.5405)(1.9,0.5263)(1.95,0.5128)(2.,0.5)};\r\n\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(0.1,31.62)(0.15,17.21)(0.2,11.18)(0.25,8.)(0.3,6.086)(0.35,4.829)(0.4,3.953)(0.45,3.313)(0.5,2.828)(0.55,2.452)(0.6,2.152)(0.65,1.908)(0.7,1.707)(0.75,1.54)(0.8,1.398)(0.85,1.276)(0.9,1.171)(0.95,1.08)(1.,1.)(1.05,0.9294)(1.1,0.8668)(1.15,0.8109)(1.2,0.7607)(1.25,0.7155)(1.3,0.6747)(1.35,0.6375)(1.4,0.6037)(1.45,0.5727)(1.5,0.5443)(1.55,0.5182)(1.6,0.4941)(1.65,0.4718)(1.7,0.4512)(1.75,0.432)(1.8,0.4141)(1.85,0.3974)(1.9,0.3818)(1.95,0.3672)(2.,0.3536)};\r\n\r\n\\addplot [{\\colortwo},thick,smooth] coordinates {(.05,4.47)(0.1,3.162)(0.15,2.582)(0.2,2.236)(0.25,2.)(0.3,1.826)(0.35,1.69)(0.4,1.581)(0.45,1.491)(0.5,1.414)(0.55,1.348)(0.6,1.291)(0.65,1.24)(0.7,1.195)(0.75,1.155)(0.8,1.118)(0.85,1.085)(0.9,1.054)(0.95,1.026)(1.,1.)(1.05,0.9759)(1.1,0.9535)(1.15,0.9325)(1.2,0.9129)(1.25,0.8944)(1.3,0.8771)(1.35,0.8607)(1.4,0.8452)(1.45,0.8305)(1.5,0.8165)(1.55,0.8032)(1.6,0.7906)(1.65,0.7785)(1.7,0.767)(1.75,0.7559)(1.8,0.7454)(1.85,0.7352)(1.9,0.7255)(1.95,0.7161)(2.,0.7071)};\r\n\r\n\\draw (axis cs:.7,5) node { $\\ds f(x)=\\frac{1}{x\\,^q}$};\r\n\\draw (axis cs:.35,.8) node { $\\ds f(x)=\\frac{1}{x\\,^p}$};\r\n\\draw (axis cs:1.5,3) node { $p<1<q$};\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) { $y$};\r\n\\end{tikzpicture}\r\n}\r\n\r\nOur analysis shows that if $p>1$, then $\\ds\\int_1^\\infty \\frac1{x\\hskip1pt ^p}\\ dx $ converges. When $p<1$ the improper integral diverges; we showed in Example \\ref{exa:ex_impint1} that when $p=1$ the integral also diverges. \r\n\r\nFigure \\ref{fig:impint4} graphs $y=1/x$ with a dashed line, along with graphs of $y=1/x^p$, $p<1$, and $y=1/x^q$, $q>1$. Somehow the dashed line forms a dividing line between convergence and divergence. %A function of the form $1/x^q$ will be under the dashed line on $[1,\\infty)$ when $q>1$. Even if $q$ is ``very close'' to 1, the difference will be enough to force convergence.\r\n}\\\\\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\r\nThe result of Example \\ref{exa:ex_impint4} provides an important tool in determining the convergence of other integrals. A similar result is proved in the exercises about improper integrals of the form $\\ds \\int_0^1\\frac1{x\\hskip1pt ^p}\\ dx$. These results are summarized in the following Theorem.\r\n\r\n\\begin{theorem}{Convergence of Improper Integrals $\\ds \\int_1^\\infty\\frac1{x\\hskip1pt ^p}\\ dx$ and $\\ds \\int_0^1\\frac1{x\\hskip1pt ^p}\\ dx$.}{idea:impint1}\r\n{\r\n\\begin{enumerate}\r\n\\item\t\tThe improper integral $\\ds \\int_1^\\infty\\frac1{x\\hskip1pt ^p}\\ dx$ converges when $p>1$ and diverges when $p\\leq 1.$\\index{convergence!of improper int.}\\index{divergence!of improper int.}\r\n\\item\t\tThe improper integral $\\ds \\int_0^1\\frac1{x\\hskip1pt ^p}\\ dx$ converges when $p<1$ and diverges when $p\\geq 1.$\r\n\\end{enumerate}\r\n}\r\n\\end{theorem}\r\n\r\n\r\n\r\n\r\n%\r\nA basic technique in determining convergence of improper integrals is to compare an integrand whose convergence is unknown to an integrand whose convergence is known. We often use integrands of the form $1/x\\hskip1pt ^p$ to compare to as their convergence on certain intervals is known. This is described in the following theorem.\r\n\r\n{\\textbf{Note:} We used the upper and lower bound of ``1'' in Theorem \\ref{thm:idea:impint1} for convenience. It can be replaced by any $a$ where $a>0$. \r\n}\r\n\r\n\r\n\\begin{theorem}{Direct Comparison Test for Improper Integrals}{impint_comparison}\r\n{\t\t\r\nLet $f$ and $g$ be continuous on $[a,\\infty)$ where $0\\leq f(x)\\leq g(x)$ for all $x$ in $[a,\\infty)$. \r\n\t\\begin{enumerate}\r\n\t\\item\t\tIf $\\ds \\int_a^\\infty g(x)\\ dx$ converges, then $\\ds \\int_a^\\infty f(x)\\ dx$ converges.\r\n\t\\index{integration!improper}\\index{convergence!Direct Comparison Test!for integration}\\index{divergence!Direct Comparison Test!for integration}\\index{Direct Comparison Test!for integration}\\index{convergence!of improper int.}\\index{divergence!of improper int.}\r\n\t\\item\t\tIf $\\ds \\int_a^\\infty f(x)\\ dx$ diverges, then $\\ds \\int_a^\\infty g(x)\\ dx$ diverges.\r\n\t\\end{enumerate}\r\n\t%\\item\t\tLet $f$ and $g$ be continuous functions on $[a,b]$ except at $x=c$, where each has a vertical asymptote, and $0\\leq f(x)\\leq g(x)$ for all $x$ in $[a,b]$, $x\\neq c$.  \r\n\t%\t\\begin{itemize}\r\n\t%\t\\item\t\tIf $\\ds \\int_a^b g(x)\\ dx$ converges, then $\\ds \\int_a^b f(x)\\ dx$ converges.\r\n\t%\t\\item\t\tIf $\\ds \\int_a^b f(x)\\ dx$ diverges, then $\\ds \\int_a^b g(x)\\ dx$ diverges.\r\n\t%\t\\end{itemize}\r\n\t%\\end{itemize}\r\n\t}\r\n\\end{theorem}\r\n\r\n\r\n\\begin{example}{Determining convergence of improper integrals}{ex_impint5}{\r\nDetermine the convergence of the following improper integrals.\\\\\r\n%\\noindent%\r\n%\\begin{minipage}[t]{.5\\textwidth}\r\n%\\begin{enumerate}\r\n1. $\\ds \\int_1^\\infty e^{-x^2}\\ dx$ \\qquad\\qquad 2. $\\ds \\int_3^\\infty \\frac{1}{\\sqrt{x^2-x}}\\ dx$\r\n%\\end{enumerate}\r\n%\\end{minipage}\r\n%\\begin{minipage}[t]{.5\\textwidth}\r\n%\\begin{enumerate}\\addtocounter{enumi}{2}\r\n%\\item\t\t$\\ds \\int_0^2\\frac{1}{(x+5)^{1/3}}\\ dx$\r\n%\\end{enumerate}\r\n%\\end{minipage}\r\n}\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{\\begin{enumerate}\r\n\\item The function $f(x) = e^{-x^2}$ does not have an antiderivative expressible in terms of elementary functions, so we cannot integrate directly. It is comparable to $g(x)=1/x^2$, and as demonstrated in Figure \\ref{fig:impint5}, $e^{-x^2} < 1/x^2$ on $[1,\\infty)$. We know from Theorem \\ref{thm:idea:impint1} that $\\ds \\int_1^\\infty \\frac{1}{x^2}\\ dx$ converges, hence $\\ds\\int_1^\\infty e^{-x^2}\\ dx$ also converges.\r\n\r\n\\mfigure{.6}{Graphs of $f(x) = e^{-x^2}$ and $f(x)= 1/x^2$ in Example \\ref{exa:ex_impint5}.}{fig:impint5}{\\begin{tikzpicture}\r\n\\begin{axis}[width=\\textwidth,%\r\naxis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick={1},%\r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n%\t\t\tytick=\\empty,\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=1.1,%\r\n\t\t\txmin=-.1,xmax=4.1%\r\n]\r\n\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(1.,0.3679)(1.1,0.2982)(1.2,0.2369)(1.3,0.1845)(1.4,0.1409)(1.5,0.1054)(1.6,0.0773)(1.7,0.05558)(1.8,0.03916)(1.9,0.02705)(2.,0.01832)(2.1,0.01216)(2.2,0.007907)(2.3,0.005042)(2.4,0.003151)(2.5,0.00193)(2.6,0.001159)(2.7,0.0006823)(2.8,0.0003937)(2.9,0.0002226)(3.,0.0001234)(3.1,0)(3.2,0)(3.3,0)(3.4,0)(3.5,0)(3.6,0)(3.7,0)(3.8,0)(3.9,0)(4.,0)};\r\n\r\n\\addplot [{\\colortwo},thick,smooth] coordinates {(1.,1.)(1.1,0.8264)(1.2,0.6944)(1.3,0.5917)(1.4,0.5102)(1.5,0.4444)(1.6,0.3906)(1.7,0.346)(1.8,0.3086)(1.9,0.277)(2.,0.25)(2.1,0.2268)(2.2,0.2066)(2.3,0.189)(2.4,0.1736)(2.5,0.16)(2.6,0.1479)(2.7,0.1372)(2.8,0.1276)(2.9,0.1189)(3.,0.1111)(3.1,0.1041)(3.2,0.09766)(3.3,0.09183)(3.4,0.08651)(3.5,0.08163)(3.6,0.07716)(3.7,0.07305)(3.8,0.06925)(3.9,0.06575)(4.,0.0625)};\r\n\r\n\\draw (axis cs:.7,.45) node { $\\ds f(x)=e^{-x^2}$};\r\n\\draw (axis cs:1.9,.8) node { $\\ds f(x)=\\frac{1}{x^2}$};\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) { $y$};\r\n\\end{tikzpicture}\r\n}\r\n\r\n\\item\t\tNote that for large values of $x$, $\\ds \\frac{1}{\\sqrt{x^2-x}} \\approx \\frac{1}{\\sqrt{x^2}} =\\frac{1}{x}$. We know from Theorem \\ref{thm:idea:impint1} and the subsequent note that  $\\ds \\int_3^\\infty \\frac1x\\ dx$ diverges, so we seek to compare the original integrand to $1/x$.\r\n\r\nIt is easy to see that when $x>0$, we have $x = \\sqrt{x^2} > \\sqrt{x^2-x}$. Taking reciprocals reverses the inequality, giving $$\\frac1x < \\frac1{\\sqrt{x^2-x}}.$$\r\n\r\nUsing Theorem \\ref{thm:impint_comparison}, we conclude that since $\\ds\\int_3^\\infty\\frac1x\\ dx$ diverges, $\\ds\\int_3^\\infty\\frac1{\\sqrt{x^2-x}}\\ dx$ diverges as well. Figure \\ref{fig:impint5b} illustrates this.\r\n\r\n\\mfigure{.75}{Graphs of $f(x) = 1/\\sqrt{x^2-x}$ and $f(x)= 1/x$ in Example \\ref{exa:ex_impint5}.}{fig:impint5b}{\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=\\textwidth,%\r\naxis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick={1},%\r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n%\t\t\tytick=\\empty,\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=.5,%\r\n\t\t\txmin=-.1,xmax=6.2%\r\n]\r\n\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(3.,0.4082)(3.1,0.3919)(3.2,0.3769)(3.3,0.363)(3.4,0.3501)(3.5,0.3381)(3.6,0.3269)(3.7,0.3164)(3.8,0.3066)(3.9,0.2974)(4.,0.2887)(4.1,0.2805)(4.2,0.2728)(4.3,0.2655)(4.4,0.2585)(4.5,0.252)(4.6,0.2457)(4.7,0.2398)(4.8,0.2341)(4.9,0.2288)(5.,0.2236)(5.1,0.2187)(5.2,0.214)(5.3,0.2095)(5.4,0.2052)(5.5,0.201)(5.6,0.197)(5.7,0.1932)(5.8,0.1895)(5.9,0.186)(6.,0.1826)};\r\n\r\n\\addplot [{\\colortwo},thick,smooth] coordinates {(3.,0.3333)(3.1,0.3226)(3.2,0.3125)(3.3,0.303)(3.4,0.2941)(3.5,0.2857)(3.6,0.2778)(3.7,0.2703)(3.8,0.2632)(3.9,0.2564)(4.,0.25)(4.1,0.2439)(4.2,0.2381)(4.3,0.2326)(4.4,0.2273)(4.5,0.2222)(4.6,0.2174)(4.7,0.2128)(4.8,0.2083)(4.9,0.2041)(5.,0.2)(5.1,0.1961)(5.2,0.1923)(5.3,0.1887)(5.4,0.1852)(5.5,0.1818)(5.6,0.1786)(5.7,0.1754)(5.8,0.1724)(5.9,0.1695)(6.,0.1667)};\r\n\r\n\\draw (axis cs:4,.45) node { $\\ds f(x)=\\frac{1}{\\sqrt{x^2-x}}$};\r\n\\draw (axis cs:2.5,.2) node { $\\ds f(x)=\\frac{1}{x}$};\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n}\r\n%\\item\t\tSince $\\ds \\frac1{(x+5)^{1/3}} < \\frac{1}{x^{1/3}}$ and by Key Idea \\ref{idea:impint1} the integral $\\ds \\int_0^1\\frac{1}{x^{1/3}}\\ dx$ converges, the integral $\\ds \\int_0^2\\frac{1}{(x+5)^{1/3}}\\ dx$ converges as well.\r\n\\end{enumerate}\r\n}\r\n\\end{solution}\r\n\r\n\r\nBeing able to compare ``unknown'' integrals to ``known'' integrals is very useful in determining convergence. However, some of our examples were a little ``too nice.'' For instance, it was convenient that $\\ds \\frac{1}x < \\frac{1}{\\sqrt{x^2-x}}$, but what if the ``$-x$'' were replaced with a ``$+2x+5$''? That is, what can we say about the convergence of $\\ds \\int_3^\\infty\\frac{1}{\\sqrt{x^2+2x+5}}\\ dx$? We have $\\ds \\frac{1}{x} > \\frac1{\\sqrt{x^2+2x+5}}$, so we cannot use Theorem \\ref{thm:impint_comparison}.\r\n\r\nIn cases like this (and many more) it is useful to employ the following theorem.\r\n%\r\n\r\n\\begin{theorem}{Limit Comparison Test for Improper Integrals}{impint_limit}\r\n{\r\n%\\begin{itemize}\r\n\t\tLet $f$ and $g$ be continuous functions on $[a,\\infty)$ where $f(x)>0$ and $g(x)>0$ for all $x$. If $$\\lim_{x\\to\\infty} \\frac{f(x)}{g(x)} = L,\\qquad 0<L<\\infty,$$\r\n\tthen $$\\int_a^\\infty f(x)\\ dx \\quad \\text{and} \\quad \\int_a^\\infty g(x)\\ dx$$ either both converge or both diverge.%\r\n\t\\index{integration!improper}\\index{convergence!Limit Comparison Test!for integration}\\index{divergence!Limit Comparison Test!for integration}\\index{Limit Comparison Test!for integration}\\index{convergence!of improper int.}\\index{divergence!of improper int.}\r\n%\t\\item\t\tLet $f$ and $g$ be continuous functions on $[a,b]$ except at $x=c$, where each has a vertical asymptote, and $f(x)>0$ and $g(x)>0$ for all $x$ in $[a,b]$, $x\\neq c$. If\r\n%\t$$\\lim_{x\\to c^-} \\frac{f(x)}{g(x)} = L_1 \\quad \\text{and} \\quad \\lim_{x\\to c^+}\\frac{f(x)}{g(x)} = L_2,\\qquad 0<L_1,L_2<\\infty,$$\r\n%\tthen $$\\int_a^b f(x)\\ dx \\quad \\text{and} \\quad \\int_a^b g(x)\\ dx$$ either both converge or both diverge.\r\n%\\end{itemize}\r\n}\r\n\\end{theorem}\r\n\r\n\\begin{example}{Determining convergence of improper integrals}{ex_impint6}\r\n{\r\nDetermine the convergence of $\\ds \\int_3^{\\infty} \\frac{1}{\\sqrt{x^2+2x+5}}\\ dx$.\r\n}\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{As $x$ gets large, the quadratic inside the square root function will begin to behave much like $y=x$. So we compare \\small$\\ds\\frac{1}{\\sqrt{x^2+2x+5}}$\\normalsize\\ to \\small$\\ds\\frac1x$\\normalsize\\ with the Limit Comparison Test:\r\n\r\n$$\r\n\\lim_{x\\to\\infty} \\frac{1/\\sqrt{x^2+2x+5}}{1/x} = \\lim_{x\\to\\infty}\\frac{x}{\\sqrt{x^2+2x+5}}.$$\r\n\r\nThe immediate evaluation of this limit returns $\\infty/\\infty$, an indeterminate form. Using l'H\\^opital's Rule seems appropriate, but in this situation, it does not lead to useful results. (We encourage the reader to employ l'H\\^opital's Rule at least once to verify this.)\r\n\r\nThe trouble is the square root function. To get rid of it, we employ the following fact: If $\\ds \\lim_{x\\to c} f(x) = L$, then $\\ds\\lim_{x\\to c} f(x)^2 = L^2.$ (This is true when either $c$ or $L$ is $\\infty$.) So we consider now the limit\r\n$$\\lim_{x\\to\\infty} \\frac{x^2}{x^2+2x+5}.$$ This converges to 1, meaning the original limit also converged to 1. As $x$ gets very large, the function \r\n\\small$\\ds\\frac{1}{\\sqrt{x^2+2x+5}}$\\normalsize\\ looks very much like \\small$\\ds\\frac1x.$\\normalsize\\ \r\nSince we know that \\small$\\ds\\int_3^{\\infty} \\frac1x\\ dx$\\normalsize\\ diverges, by the Limit Comparison Test we know that \\small$\\ds\\int_3^\\infty\\frac{1}{\\sqrt{x^2+2x+5}}\\ dx$\\normalsize\\ also diverges. Figure \\ref{fig:impint6} graphs $f(x)=1/\\sqrt{x^2+2x+5}$ and $f(x)=1/x$, illustrating that as $x$ gets large, the functions become indistinguishable.\r\n\\mfigure{.6}{Graphing $f(x)=\\frac{1}{\\sqrt{x^2+2x+5}}$ and $f(x)=\\frac1x$ in Example \\ref{exa:ex_impint6}.}{fig:impint6}{\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=\\textwidth,%\r\naxis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick={1},%\r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n%\t\t\tytick=\\empty,\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=.35,%\r\n\t\t\txmin=-.1,xmax=21%\r\n]\r\n\r\n\\addplot [{\\colortwo},thick,smooth] coordinates {(3.,0.3333)(4.,0.25)(5.,0.2)(6.,0.1667)(7.,0.1429)(8.,0.125)(9.,0.1111)(10.,0.1)(11.,0.09091)(12.,0.08333)(13.,0.07692)(14.,0.07143)(15.,0.06667)(16.,0.0625)(17.,0.05882)(18.,0.05556)(19.,0.05263)(20.,0.05)};\r\n\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(3.,0.2236)(4.,0.1857)(5.,0.1581)(6.,0.1374)(7.,0.1213)(8.,0.1085)(9.,0.09806)(10.,0.08944)(11.,0.0822)(12.,0.07603)(13.,0.07071)(14.,0.06608)(15.,0.06202)(16.,0.05842)(17.,0.05522)(18.,0.05234)(19.,0.04975)(20.,0.0474)};\r\n\r\n\\draw (axis cs:10,.3) node {$\\ds f(x)=\\frac{1}{\\sqrt{x^2+2x+5}}$};\r\n\\draw (axis cs:4,.09) node { $\\ds f(x)=\\frac{1}{x}$};\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) { $y$};\r\n\\end{tikzpicture}\r\n}\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\n%\r\n%\\enlargethispage{3\\baselineskip}\r\nBoth the Direct and Limit Comparison Tests were given in terms of integrals over an infinite interval. There are versions that apply to improper integrals with an infinite range, but as they are a bit wordy and a little more difficult to employ, they are omitted from this text.\\\\\r\n\r\nThis chapter has explored many integration techniques. We learned Substitution, which ``undoes'' the Chain Rule of differentiation, as well as Integration by Parts, which ``undoes'' the Product Rule. We also learned specialized techniques for handling trigonometric functions % and introduced the hyperbolic functions, which are closely related to the trigonometric functions. \r\nAll techniques effectively have this goal in common: rewrite the integrand in a new way so that the integration step is easier to see and implement. \r\n\r\nAs stated before, integration is, in general, hard. It is easy to write a function whose antiderivative is impossible to write in terms of elementary functions, and even when a function does have an antiderivative expressible by elementary functions, it may be really hard to discover what it is. The powerful computer algebra system \\textit{Mathematica}\\textsuperscript{\\textregistered} has approximately 1,000 pages of code dedicated to integration. \r\n\r\nDo not let this difficulty discourage you. There is great value in learning integration techniques, as they allow one to manipulate an integral in ways that can illuminate a concept for greater understanding. There is also great value in understanding the need for good numerical techniques: the Trapezoidal and Simpson's Rules are just the beginning of powerful techniques for approximating the value of integration.\\\\\r\n\r\nChapter \\ref{chap:ApplicationsOfIntegration} stresses the uses of integration. We generally do not find antiderivatives for antiderivative's sake, but rather because they provide the solution to some type of problem. The following chapter introduces us to a number of different problems whose solution is provided by integration.\r\n\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:ImproperIntegrals}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n\\begin{ex}\r\n\tDetermine whether $\\ds\\int_1^{\\infty}\\frac{1}{x^2}\\,dx$ is convergent or divergent.\r\n\t\\begin{sol}\r\n\t\tConverges to 1.\r\n\t\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tDetermine whether $\\ds\\int_e^{\\infty}\\frac{1}{x\\sqrt{\\ln x}}\\,dx$ is convergent or divergent.\r\n\t\\begin{sol}\r\n\t\tDiverges.\r\n\t\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tEvaluate the improper integral $\\ds\\int_0^{\\infty}e^{-3x}\\,dx$.\r\n\t\\begin{sol}\r\n\t\t1/3\r\n\t\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tDetermine if $\\ds\\int_1^e\\frac{1}{x(\\ln x)^2}\\,dx$ is convergent or divergent. Evaluate it if it is convergent.\r\n\t\\begin{sol}\r\n\t\tDivergent.\r\n\t\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tShow that $\\ds\\int_0^{\\infty}e^{-x}\\sin^2\\left(\\frac{\\pi x}{2}\\right)\\,dx$ converges.\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tEvaluate $\\ds\\int_{-\\infty}^{\\infty}\\frac{1}{x^2+1}\\,dx$ and $\\ds\\int_{-\\infty}^{\\infty}\\frac{x}{x^2+1}\\,dx$.\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tDetermine whether the following improper integrals are convergent or divergent. Evaluate those that are convergent.\r\n\t\\begin{enumerate}\r\n\t\t\\item\t$\\int_{0}^{\\infty}\\dfrac{1}{x^2+1}\\,dx$\r\n\t\t\\item\t$\\int_{0}^{\\infty}\\dfrac{x}{x^2+1}\\,dx$\r\n\t\t\\item\t$\\int_{0}^{\\infty}e^{-x}(\\cos x+\\sin x)\\,dx$. [Hint: What is the derivative of $-e^{-x}\\cos x?$]\r\n\t\t\\item\t$\\int_{0}^{\\pi/2}\\sec^{2}x\\,dx$\r\n\t\t\\item\t$\\int_{0}^{4}\\dfrac{1}{(4-x)^{2/5}}\\,dx$\r\n\t\\end{enumerate}\r\n\t\\begin{sol}\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item\t$\\pi/2$\r\n\t\t\t\\item\tdivergent (to $\\infty$)\r\n\t\t\t\\item\t1\r\n\t\t\t\\item\tdivergent (to $\\infty$)\r\n\t\t\t\\item\t$\\frac{5}{3}(4^{3/5})$\r\n\t\t\\end{enumerate}\r\n\t\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tProve that the integral $\\int_{1}^{\\infty}\\dfrac{1}{x^p}\\,dx$ is convergent if $p>1$ and divergent if $0<p\\leq 1$.\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tSuppose that $p>0$. Find all values of $p$ for which $\\int_{0}^{1}\\dfrac{1}{x^p}\\,dx$ converges.\r\n\t\\begin{sol}\r\n\t\t$0<p<1$\r\n\t\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\n\tShow that $\\int_{1}^{\\infty}\\dfrac{\\sin^2 x}{x(\\sqrt{x}+1)}\\,dx$ converges.\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "6fd36ca4b6220010c106e3a4557f7b7ce68bc5bb", "size": 56637, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7-techniques-of-integration/7-7-improper-integrals.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "7-techniques-of-integration/7-7-improper-integrals.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "7-techniques-of-integration/7-7-improper-integrals.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.1980861244, "max_line_length": 585, "alphanum_fraction": 0.6347617282, "num_tokens": 23164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738010682209, "lm_q2_score": 0.8856314617436727, "lm_q1q2_score": 0.7113159874742703}}
{"text": "\\section{Calculus}\n$x$ is a variable, $k$, $a$ and $b$ are constants, and $f$ and $g$ are functions.\n\\begin{center}\n    \\begin{longtable}{c|c|c}\n        \\textbf{Function} & \\textbf{Derivative} & \\textbf{Antiderivative}\n        \\\\[0.25cm] \\hline\n        $x$ & $1$ & $\\frac{1}{2}x^2$\n        \\\\\n        $x^n$ & $nx^{n - 1}$ & $\\frac{1}{n + 1}x^{n + 1}$\n        \\\\\n        $\\sqrt{x}$ & $\\frac{1}{2 \\sqrt{x}}$ & $\\frac{2}{3}x^\\frac{3}{2}$\n        \\\\\n        $\\frac{1}{x}$ & $\\frac{-1}{x^2}$ & $\\ln(x)$\n        \\\\\n        $ax + b$ & $a$\n        \\\\\n        $k$ & $0$ & $kx + b$\n        \\\\\n        $\\sin{x}$ & $\\cos{x}$ & $-\\cos{x}$\n        \\\\\n        $\\cos{x}$ & $-\\sin{x}$ & $\\sin{x}$\n        \\\\\n        $\\tan{x}$ & $1 + \\tan^2{x} \\quad \\text{or} \\quad \\frac{1}{\\cos^2{x}}$ & $\\ln\\left(\\frac{1}{\\cos{x}}\\right)$\n        \\\\\n        $k \\cdot f$ & $k \\cdot f'$\n        \\\\\n        $f \\pm g$ & $f' \\pm g'$\n        \\\\\n        $f \\cdot g$ & $f' \\cdot g + f \\cdot g'$\n        \\\\\n        $\\frac{f}{g}$ & $\\frac{f' \\cdot g - f \\cdot g'}{g^2}$\n        \\\\\n        $e^x$ & $e^x$ & $e^x$\n        \\\\\n        $10^x$ & $\\ln(10) \\cdot 10^x$ & $\\frac{10^x}{\\ln(10)}$\n    \\end{longtable}\n\\end{center}\n", "meta": {"hexsha": "dd2fe9f03ba1ad1e59e57b52f437afe31f13ef72", "size": 1176, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/calculus.tex", "max_stars_repo_name": "KongBorup/algebraic-tricks", "max_stars_repo_head_hexsha": "ea3e187203fffdaf03b3bc64994dcf95cf6f80c8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sections/calculus.tex", "max_issues_repo_name": "KongBorup/algebraic-tricks", "max_issues_repo_head_hexsha": "ea3e187203fffdaf03b3bc64994dcf95cf6f80c8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/calculus.tex", "max_forks_repo_name": "KongBorup/algebraic-tricks", "max_forks_repo_head_hexsha": "ea3e187203fffdaf03b3bc64994dcf95cf6f80c8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-22T21:54:51.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-22T21:54:51.000Z", "avg_line_length": 30.9473684211, "max_line_length": 115, "alphanum_fraction": 0.3613945578, "num_tokens": 486, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750400464604, "lm_q2_score": 0.7461389986757758, "lm_q1q2_score": 0.711275683842876}}
{"text": "\\section{Discriminative / generative modeling}\n\n\\textbf{Discr.:} estimate $P(y\\vert x)$, \\enskip\\textbf{Generative:} $P(y,x)$\n\n\\textbf{Chain rule:} \\highlight*{$P(x,y) = P(y) P(x\\vert y)$}\n\n%\\begin{highlightbox}\n%\t1. Estimate prior on labels $P(y)$\\\\\n%\t2. Est. cond. distr. for \\textit{each class} $y$: $P(x\\vert y)$\\\\\n%\t3. Predict using Bayes: \\highlight*{$\\textstyle P(y\\vert x) = \\frac{1}{Z} P(x,y)$},\\\\\n%\t\\phantom{3.} $Z \\!=\\! P(x)  \\!=\\! \\sum_{y'} P(x,y')$\n%\\end{highlightbox}\n\n% ===\n\\emph{Deriving Decision Rules}\\vspace{1pt}\n\\begin{highlightbox}\n\t1. Estimate prior on labels $P(y)$\\\\\n\t2. Est. cond. distr. for \\textit{each class} $y$: $P(x\\vert y)$\\\\\n\t\\phantom{2.} $\\rightsquigarrow Z \\!=\\! P(x)  \\!=\\! \\sum_{y'} P(x,y')$\\\\\n\t3. Predict using Bayes: \\highlight*{$\\textstyle P(y\\vert x) = \\frac{1}{Z} P(x,y)$},\\\\\n\t4. Minimize misclassification error:\\\\\n\t\\phantom{4.} $\\hat y = \\arg\\!\\max P(y\\vert x) = \\arg\\!\\max\\limits_y P(y)P(x\\vert y)$\\vspace{-7pt}\\\\\n\t\\phantom{4. $\\hat y$}$\\;= ... \\prod_{i=1}^d P(x_i,y)$%\\vspace{-7pt}\n\\end{highlightbox}\n\n%\\begin{highlightbox}\n%\t1. Est. $P(y)$ and $P(x\\vert y)$ \\enskip $\\rightsquigarrow P(x) = \\sum_{y'} ...$\\\\\n%\t2. $P(y\\vert x) = ...$\\\\\n%\t3. Predict using Bayesian decision theory\\\\\n%\t4. Minimize misclassification error:\\\\\n%\t\\phantom{4.} $\\hat y = \\arg\\!\\max\\limits_y P(y)P(x\\vert y)$ $\\to ... \\prod_{i=1}^d P(x_i,y)$\\vspace{-3pt}\n%\\end{highlightbox}\n\n\\textbf{Binary:}\n\\highlight*{$y=\\operatorname{sign}(f(x))$},\n$f(x) = \\log \\frac{P(Y=+\\!1\\vert x)}{P(Y=-\\!1\\vert x)}$\\\\\n{\\small\n$y\\ped{pred} = [P(X, 1) \\geq P(X, 0)] = [p_1P(X\\vert) 1 \\geq p_0P(X\\vert 0)]$\n}\n\n%\\subsection*{Example: Naive Bayes Model}\n%cond. ind.:$P(X_1,...,X_d|Y) = \\prod_{i=1}^d P(X_i|Y)$\n\n% ===\n\\emph{Examples}\n\n\\textbf{MLE for Class.}: $P(y) = \\highlight{p_y} = \\frac{\\operatorname{Count}(Y=y)}{n} = \\frac{\\highlight{\\scriptstyle n_y}}{n}$\n\n\\textbf{MLE for $\\mathbf{P(x\\vert y)}$:}\n$P(x_i\\vert y) = \\mathcal{N}(x_i;\\mu_{y,i}, \\sigma_{y,i}^2)$\\\\\n{\\small\n$\\highlight{\\hat{\\mu}_{y,i}} = \\frac{1}{n_y} \\sum_{j:y_j=y} x_{j,i}$\\hfill\n$\\highlight{\\hat{\\sigma}_{y,i}^2} = \\frac{1}{n_y} \\sum_{j:y_j=y} (x_{j,i} - \\hat{\\mu}_{y,i})^2$\n}\\\\\n$x_{j,i}$: value of feature $i$ for instance $j$ ($x_j,y_j$)\n\n\\textbf{MLE for Poi.:} $\\lambda = \\operatorname{avg}(x_i) $\\\\\n$\\mathbb{R}^d$: $P(X \\!\\!=\\! x\\vert Y \\!\\!=\\! y) = \\prod_{i=1}^d Pois(\\lambda_y^{(i)},x^{(i)})$\n\n% ===\n\\emph{Gaussian Bayes Classifier}\n\n$\\hat{P}(x|y) = \\mathcal{N}(x ; \\hat{\\mu}_y, \\hat{\\Sigma}_y)$\n\n\\textbf{MLE:}\n$\\hat{\\mu}_{y} = \\frac{1}{n_y} \\sum_{j:y_j=y} x_j \\color{gray}\\in \\mathbb{R}^d$\\\\\n\\phantom{\\textbf{MLE:}}\n$\\hat{\\Sigma}_{y} = \\frac{1}{n_y} \\sum_{j:y_j=y} (x_j - \\hat{\\mu}_{y})(x_j-\\hat{\\mu}_y)^T \\color{gray}\\in \\mathbb{R}^{d \\times d}$\n\n\\textbf{$\\normalcolor\\mathbf{c\\!=\\!2}$:}\n{\\small\n$f(x) = \\log\\frac{p}{1-p}\n+ \\frac{1}{2} \\Big[ \\log\\frac{\\abs{\\hat\\Sigma_-}}{\\abs{\\hat\\Sigma_+}} + \\ldots$\n}\\\\\n\\phantom{\\textbf{$\\normalcolor\\mathbf{c\\!=\\!2}$:}}\n{\\small\n$ \\big( (x\\!-\\!\\hat\\mu_-)^\\top \\hat\\Sigma_-^{-1} (x\\!-\\!\\hat\\mu_-) \\big)\n- \\big( (x\\!-\\!\\hat\\mu_+)^\\top \\hat\\Sigma_+^{-1} (x\\!-\\!\\hat\\mu_+) \\big) \\Big]$\n}\n\n\\textbf{$\\normalcolor\\mathbf{c\\!=\\!2}$ -- Fisher's LDA:}\\\\\n\\phantom{\\textbf{$\\mathbf{c\\!=\\!2}$:}}\nAssume:\\enskip $p = 0.5$;\\enskip $\\hat{\\Sigma}_- \\!= \\hat{\\Sigma}_+ \\equiv \\hat{\\Sigma}$\\\\\n\\phantom{\\textbf{$\\mathbf{c\\!=\\!2}$:}}\n$\\implies f(x) = w^\\top x + w_0$\\\\\n\\phantom{\\textbf{$\\mathbf{c\\!=\\!2}$:}} where\n$w = \\hat{\\Sigma}^{-1}(\\hat{\\mu}_+ - \\hat{\\mu}_-)$ and\\\\\n\\phantom{\\textbf{$\\mathbf{c\\!=\\!2}$:} where}\n$w_0 = \\frac{1}{2}(\\hat{\\mu}_-^\\top\\hat{\\Sigma}^{-1}\\hat{\\mu}_- - \\hat{\\mu}_+^\\top \\hat{\\Sigma}^{-1}\\hat{\\mu}_+)$\n\n\\columnbreak\n\n% ===\n\\emph{Outlier Detection}\n\n$P(x) \\leq \\tau$\n\n% ===\n\\emph{Categorical (Naive) Bayes Classifier}\n\nMLE for feature distr.:\n$\\hat{P}(X_i \\!=\\! c\\vert Y \\!=\\! y) = \\theta_{c\\vert y}^{(i)}$\\\\\n$\\theta_{c\\vert y}^{(i)} = \\frac{\\operatorname{Count}(X_i = c, Y = y)}{\\operatorname{Count}(Y=y)}$, \\enskip $\\hat p_y = \\frac{\\operatorname{Count}(Y=y)}{n}$\n", "meta": {"hexsha": "4733e97327830ff763ed477e91234bb2509203b3", "size": 3982, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/IML19/sections/Generative.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/IML19/sections/Generative.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/IML19/sections/Generative.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2884615385, "max_line_length": 156, "alphanum_fraction": 0.5693119036, "num_tokens": 1798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7111764414976199}}
{"text": "\\subsection{Markov chain recap}\n\nIn a Markov chain we move from state to state randomly, following a transtion matrix.\n\nWe have:\n\n\\begin{itemize}\n\\item \\(S\\) - the state space\n\\item \\(s_1\\) - the initial state\n\\item \\(P\\) - the transition model\n\\end{itemize}\n\n", "meta": {"hexsha": "c51c6346fdbfb8407c39079f56a8151487cb2876", "size": 260, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/MDP/01-01-chain.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/ai/MDP/01-01-chain.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/ai/MDP/01-01-chain.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.0, "max_line_length": 85, "alphanum_fraction": 0.7153846154, "num_tokens": 75, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.8104788995148792, "lm_q1q2_score": 0.71117641847129}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[latin1]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage{lmodern}\n\\usepackage{hyperref}\n\\usepackage{cleveref}\n\\author{Daniel Celis Garza}\n\\title{Interpolation Notes}\n\\date{\\today}\n\\begin{document}\n\\maketitle\n\\section{Neville's Algorithm}\nFor $n = 4$\n\\begin{align*}\nx_{1}:\\qquad& y_{1} =& P_{1,1} \t&\t\t\t\t\t\\hspace{-2cm}&\t\t\t\t   \\\\\n\t\t\t&\t\t & \t& P_{1,2}\t\t\t\\hspace{-2cm}&\t\t\t\t   \\\\\nx_{2}:\\qquad& y_{2} =& P_{2,2} \t&\\qquad P_{1,2,3}\t\\hspace{-2cm}&\t\t\t\t   \\\\\n\t\t\t&\t\t &\t\t \t& P_{2,3}\t\t\t\\hspace{-2cm}& P_{1,2,3,4}\t   \\\\\nx_{3}:\\qquad& y_{3}\t=& P_{3,3}\t&\\qquad P_{2,3,4}\t\\hspace{-2cm}&\t\t\t\t   \\\\\n\t\t\t&\t\t & \t& P_{3,4}\t\t\t\\hspace{-2cm}&\t\t\t\t   \\\\\nx_{1}:\\qquad& y_{4} =& P_{4,4} \t&\t\t\t\t\t\\hspace{-2cm}&\t\t\t\t   \\\\\n\\end{align*}\n\n\\begin{subequations}\\label{e:nev}\n\\begin{align}\n& P_{i,i} = y_{i}~, && 0\\le i \\le n \\\\\n& P_{i,j} =\n\\dfrac{\n(x_j-x)P_{i,j-1} + (x-x_i)P_{i+1,j}\n}\n{\nx_{j}-x_{i}\n}~, && 0\\le i < j \\le n\n\\end{align}\n\\end{subequations}\n\nThe original formula is:\n\n\\begin{align}\\label{e:lag}\n^{n}P(x) = \\sum\\limits_{i=0}^{n}\\left(\n\\prod\\limits_{\\substack{0 \\le j \\le n \\\\ j \\ne i}}\n\\dfrac{x-x_{j}}{x_{i}-x_{j}}\n\\right)y_{i}\n\\end{align}\n\nFor $n = 2$ \\cref{e:nev} is\n\\begin{align*}\nP_{1,2} &= \\dfrac{(x_{2} - x)P_{1,1} + (x-x_{1})P_{2,2}}{x_{2}-x_{1}}\\\\\nP_{1,2} &= \\dfrac{(x_{2} - x)y_{1} + (x-x_{1})y_{2}}{x_{2}-x_{1}}\t \\\\\n\\end{align*}\nand \\cref{e:lag} is\n\\begin{align*}\n^{n}P &= \\dfrac{x-x_{2}}{x_{1}-x_{2}}y_{1} + \\dfrac{x-x_{1}}{x_{2}-x_{1}}y_{2} \\\\\n^{n}P &= \\dfrac{-(x_{2}-x)}{-(x_{2}-x_{1})}y_{1} + \\dfrac{x-x_{1}}{x_{2}-x_{1}}y_{2} \\\\\n\\end{align*}\n\\end{document}", "meta": {"hexsha": "a684250e2a80f4b24662788f5e7ea948342c91ed", "size": 1651, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "interpolation/notes/interpolation_notes.tex", "max_stars_repo_name": "dcelisgarza/applied_math", "max_stars_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2015-09-30T19:22:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T23:33:04.000Z", "max_issues_repo_path": "interpolation/notes/interpolation_notes.tex", "max_issues_repo_name": "dcelisgarza/applied_math", "max_issues_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "interpolation/notes/interpolation_notes.tex", "max_forks_repo_name": "dcelisgarza/applied_math", "max_forks_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.9830508475, "max_line_length": 87, "alphanum_fraction": 0.5493640218, "num_tokens": 816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343393, "lm_q2_score": 0.8152324983301568, "lm_q1q2_score": 0.7111659377872306}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{3D Geometry}\nFor nearly 3,000 years, mathematicians have been interested in shapes called\nconic sections.  Why?  What are they?  Surprisingly, they are the means to answer some\nvery basic problems, like doubling the size of a cube, or why it is almost impossible to make\na square with the same area as a circle.  While the Ancient Greek geometers were interested\nin such problems, it is far easier to consider them in light of analytic geometry, where we \nlay down the Cartesian plane, and place shapes in it, analyzing the algebra of their equations.\n\n\\marginfig[-0.5in]{\\chapdir/pics/ConicSections_ajl.png}{The conic sections.}\nThe problems you worked in the lab were examples of three out of the four conic sections.\nWhy are they called such?  It is easy to model a cone intersecting a plane.  If we\nimagine the cone as an idealized version of itself, it extends both up and down, forever\nin two directions.  The plane of intersection is also the infinite plane of geometry, a flat\nsheet that extends forever.\n\nIf the line through the middle of the cone intersects the plane at $90^\\circ$ precisely\n(what mathematicians call \\textbf{normal} to the plane), then the shape on the plane will\nbe incredibly symmetrical, a \\textbf{circle}.  Any slight variance in that angle will produce a\ndistorted circle, what is ordinarily called an `oval', but in mathematical parlance, an\n\\textbf{ellipse}. If we continue to tilt the plane, the ellipse will widen and widen.  As we\nachieve an angle parallel to the side of the cone, the shape is our old friend, the \n\\textbf{parabola}.  Any angle past that will result in intersecting both parts of the cone,\na shape known as a \\textbf{hyperbola}.\n\n\\subsection{Graphing form}\n\\subsubsection{Circles}\nDrawing circles is very easy and so is the algebra equation underlying them.  With a center\nat $(h,k)$ and radius $r$, they can be quickly graphed, even by hand.\n\n\\marginfig[-0.5in]{\\chapdir/pics/Conic_sections.png}{The angle of intersection of the plane \nand the cone may be plainly seen in the projection.}\n\\begin{derivation}{Equation of a Circle}\n\\label{eq:circle}\n\\begin{equation}\n(x-h)^2+(y-k)^2=r^2\n\\end{equation}\n\\end{derivation}\n\n\\subsubsection{Ellipses}\nWe could imagine an straight-forward algebra manipulation which mirrors the geometric\nmanipulation from circles to ellipses: begin with Eq.~\\ref{eq:circle}.  Now divide both sides \nby $r^2$:\n$$\n\\frac{(x-h)^2}{r^2} + \\frac{(y-h)^2}{r^2} = 1\n$$\nIf we consider that the two radii represented in the denominators might be different \n(perhaps we might relabel them as $r_1^2$\nand $r_2^2$), then we are very close to the graphing form of the equations for ellipses, and\nwe have a visual parallel: an ellipse is a circle with different radii for the $x$ and $y$!\n\n\\begin{derivation}{Equations of Ellipses}\n\\begin{equation}\n\\label{eq:ellipses}\n\\left(\\frac{x-h}{a}\\right)^2 + \\left(\\frac{y-k}{b}\\right)^2 = 1 \\quad \\text{or} \\quad \\left(\\frac{x-h}{b}\\right)^2 + \\left(\\frac{y-k}{a}\\right)^2 = 1\n\\end{equation}\n\\end{derivation}\nBy convention, we call whichever radii is bigger $a$, hence the two different forms.  (It will become\nclearer in §DD.04 why.)\n\n\\subsubsection{Parabola}\nYou have done a lot of work with parabolas over the years, and the vertex form of Algebra II\nrequires very little manipulation to adapt to our purposes here (i.e. $y=a(x-h)^2+k$).  The only\ncaveats are that we like to keep the unit $(y-k)$ together, and that $a$ is four times the focal\nlength, conventionally called $p$.  Also, there are parabolas that open up-down, as well\nas those that open left-right, as we saw in §3.3\n\n\\begin{derivation}{Equations of Parabolas}\n\\begin{equation}\n(y-k) = 4p(x-h)^2 \\quad  \\text{or} \\quad (x-h) = 4p (y-k)^2\n\\end{equation}\n\\end{derivation}\n\n\\subsection{Hyperbolas}\n\\marginfig[-1in]{\\chapdir/pics/Drini-conjugatehyperbolas.png}{Hyperbolas can be horizontally or vertically oriented.}\nHyperbolas are very likely the least familiar to you of any of these objects.  Of course, \n$y=\\frac{1}{x}$ is a hyperbola, but that can be hard to see, unless you turn your head\n$45^\\circ$ to the left!  If you look at the hyperbola $x^2-y^2=1$, some of the standard \nfeatures are apparent.  There are two asymptotes, in this case, at $y=\\pm x$.  They \ngo through the center of the graph (the origin), which is not part of the graph.  These\nsame two asymptotes would be the same ones for the graph of $y^2-x^2=1$, only\none opens left-right, while the other one is oriented up-down.\n\n\\begin{derivation}{Equations of Hyperbolas}\n\\begin{equation}\n\\left(\\frac{x-h}{a}\\right)^2 - \\left(\\frac{y-k}{b}\\right)^2 = 1\n\\quad \\text{or} \\quad\n\\left(\\frac{y-k}{a}\\right)^2 - \\left(\\frac{x-h}{b}\\right)^2 = 1\n\\end{equation}\n\\end{derivation}\n\nPractically speaking, graphing from the equation is a multi-step process\n\\begin{enumerate}\n\\item Begin at the center $(h,k)$.\n\\item Whichever variable is underneath $x$ (either $a$ or $b$), proceed that distance right and left from the center.\n\\item Whichever variable is underneath $y$ (either $b$ or $a$), proceed that distance up and down from the center.  \n\\item The preceeding dimensions are needed to draw the asymptotes, which either have slopes of $\\pm\\frac{b}{a}$ or $\\pm\\frac{a}{b}$.\n\\end{enumerate}\n\n\\marginfig[0in]{\\chapdir/pics/Giperbola-koord.png}{A horizontal hyperbola centered at the origin.}\n", "meta": {"hexsha": "aa3d603281f5b44e6f98a324d9a977c97da29ba7", "size": 5366, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chDD/DD01.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "chDD/DD01.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chDD/DD01.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.6078431373, "max_line_length": 149, "alphanum_fraction": 0.7450614983, "num_tokens": 1560, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7111659240811052}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{examples}\n\n\\lstset{numbers=left}\n\n\\begin{document}\n\n\\section*{The metric connection in Riemann normal coordinates}\n\nIn local Riemann normal coordinates, the metric components can always be expanded as a power series in the Riemann curvatures and its derivatives (provided the curvatives are finite at the expansion point). In particular\n\\begin{align*}\n   g_{ab}(x) &= g_{a b} - \\frac{1}{3} x^{c} x^{d} R_{a c b d}\n                        - \\frac{1}{6} x^{c} x^{d} x^{e} \\nabla_{c}{R_{a d b e}} + \\cdots\\\\\n   g^{ab}(x) &= g^{a b} + \\frac{1}{3} x^{c} x^{d} g^{a e} g^{b f} R_{c e d f}\n                        + \\frac{1}{6} x^{c} x^{d} x^{e} g^{a f} g^{b g} \\nabla_{c}{R_{d f e g}} + \\cdots\n\\end{align*}\nwhere $g_{ab}$ and $g^{ab}$ are independent of the coordinates $x^a$ and where $\\nabla$ is the metric compatable derivative operator (i.e., $\\nabla(g)=0$). In applications in General Relativity the $g_{ab}$ are often chosen to be $g_{ab} = {\\rm diag}(-1,1,1,1)$.\n\nHere we will use the standard metric compatible connection\n\\begin{align*}\n   \\Gamma^{d}_{ab}(x) = \\frac{1}{2} g^{dc}\\left( g_{cb,a} + g_{ac,b} - g_{ab,c} \\right)\n\\end{align*}\nto compute $\\Gamma^{d}_{ab}(x)$ to terms linear in $R_{abcd}$ and $\\nabla_{e} R_{abcd}$.\n\n\\vspace{12pt}\n\n\\begin{cadabra}\n   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w#}::Indices(position=independent).\n\n   D{#}::PartialDerivative.\n   \\nabla{#}::Derivative.\n\n   g_{a b}::Metric.\n   g^{a b}::InverseMetric.\n\n   \\delta{#}::KroneckerDelta.\n\n   R_{a b c d}::RiemannTensor.\n\n   x^{a}::Depends(D{#}).\n   x^{a}::Weight(label=num,value=1).\n\n   R_{a b c d}::Depends(\\nabla{#}).\n\n   DxaDxb := D_{a}{x^{b}}->\\delta^{b}_{a}.\n\n   # can chose lower order approximations by truncating the following pair\n\n   gab := g_{a b} - 1/3 x^{c} x^{d} R_{a c b d}\n                  - 1/6 x^{c} x^{d} x^{e} \\nabla_{c}{R_{a d b e}}.                    # cdb(gab.000,gab)\n\n   iab := g^{a b} + 1/3 x^{c} x^{d} g^{a e} g^{b f} R_{c e d f}\n                  + 1/6 x^{c} x^{d} x^{e} g^{a f} g^{b g} \\nabla_{c}{R_{d f e g}}.    # cdb(iab.000,iab)\n\n   gab := g_{a b} -> @(gab).\n   iab := g^{a b} -> @(iab).\n\n   gam := 1/2 g^{d c} (D_{a}{g_{c b}} + D_{b}{g_{a c}} - D_{c}{g_{a b}}).             # cdb(gam.001,gam)\n\n   substitute   (gam,gab)\n   substitute   (gam,iab)\n   distribute   (gam)              # cdb(gam.002,gam)\n   unwrap       (gam)              # cdb(gam.003,gam)\n   product_rule (gam)              # cdb(gam.004,gam)\n   distribute   (gam)              # cdb(gam.005,gam)\n   substitute   (gam,DxaDxb)       # cdb(gam.006,gam)\n   eliminate_kronecker (gam)       # cdb(gam.007,gam)\n   sort_product   (gam)            # cdb(gam.008,gam)\n   rename_dummies (gam)            # cdb(gam.009,gam)\n   canonicalise   (gam)            # cdb(gam.010,gam)\n\n   def truncate (obj,n):\n\n       ans = Ex(0)  # create a Cadabra object with value zero\n\n       for i in range (0,n+1):\n          foo := @(obj).\n          bah  = Ex(\"num = \" + str(i))\n          distribute  (foo)\n          keep_weight (foo, bah)\n          ans = ans + foo\n\n       return ans\n\n   gam = truncate (gam,2)   # cdb (gam.101,gam)  # allow up to 2nd order in x^a\n\n   # ==========================================================================\n   # the remaining code is just for pretty printing\n\n   {x^{a},g^{a b},R_{a b c d},\\nabla_{e}{R_{a b c d}}}::SortOrder.\n\n   def get_term (obj,n):\n\n       foo := @(obj).\n       bah  = Ex(\"num = \" + str(n))\n       distribute  (foo)\n       keep_weight (foo, bah)\n\n       return foo\n\n   def reformat (obj,scale):\n\n      foo  = Ex(str(scale))\n      bah := @(foo) @(obj).\n\n      distribute     (bah)\n      sort_product   (bah)\n      rename_dummies (bah)\n      canonicalise   (bah)\n      factor_out     (bah,$x^{a?},g^{b? c?}$)\n      ans := @(bah) / @(foo).\n\n      return ans\n\n   gam1 = get_term (gam,1)       # cdb (gam1.301,gam1)\n   gam2 = get_term (gam,2)       # cdb (gam2.301,gam2)\n\n   gam1 = reformat (gam1,  3)    # cdb (gam1.301,gam1)\n   gam2 = reformat (gam2, 12)    # cdb (gam2.301,gam2)\n\n   Gamma  := @(gam1) + @(gam2).  # cdb (Gamma.301,Gamma)\n   Scaled := 12 @(Gamma).        # cdb (Scaled.301,Scaled)\n\n\\end{cadabra}\n\n\\subsection*{The metric connection in Riemann normal coordinates}\n\n\\begin{dgroup*}\n   \\begin{dmath*} \\Gamma^{d}_{a b} = \\cdb{Gamma.301} \\end{dmath*}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\begin{dmath*} 12 \\Gamma^{d}_{a b} = \\cdb{Scaled.301} \\end{dmath*}\n\\end{dgroup*}\n\n\\vspace{20pt}\n\n\\begin{latex}\n   \\begin{dgroup*}\n      \\begin{dmath*} \\Gamma^{d}_{a b} = \\cdb{Gamma.301} \\end{dmath*}\n   \\end{dgroup*}\n\n   \\begin{dgroup*}\n      \\begin{dmath*} 12 \\Gamma^{d}_{a b} = \\cdb{Scaled.301} \\end{dmath*}\n   \\end{dgroup*}\n\\end{latex}\n\n% uncomment the following to get more detail of the computations\n\n% \\begin{dgroup*}\n%    \\begin{dmath*} \\cdb{gam.002} \\end{dmath*}\n%    \\begin{dmath*} \\cdb{gam.003} \\end{dmath*}\n%    \\begin{dmath*} \\cdb{gam.004} \\end{dmath*}\n%    \\begin{dmath*} \\cdb{gam.005} \\end{dmath*}\n%    \\begin{dmath*} \\cdb{gam.006} \\end{dmath*}\n%    \\begin{dmath*} \\cdb{gam.007} \\end{dmath*}\n%    \\begin{dmath*} \\cdb{gam.008} \\end{dmath*}\n%    \\begin{dmath*} \\cdb{gam.009} \\end{dmath*}\n%    \\begin{dmath*} \\cdb{gam.010} \\end{dmath*}\n% \\end{dgroup*}\n\n\\end{document}\n", "meta": {"hexsha": "2d65fd674a5a60da1cdb8fd1f1ecde3a59c530d7", "size": 5240, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cadabra/examples/example-07.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "cadabra/examples/example-07.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cadabra/examples/example-07.tex", "max_forks_repo_name": "leo-brewin/hybrid-latex", "max_forks_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-27T03:29:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:17:18.000Z", "avg_line_length": 32.1472392638, "max_line_length": 262, "alphanum_fraction": 0.5433206107, "num_tokens": 1984, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7111659218385984}}
{"text": "\\documentclass[11pt, letterpaper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{bm}\n\n\\newcommand{\\e}{\\epsilon}\n\\newcommand{\\dl}{\\delta}\n\\newcommand{\\1}{\\bm{1}}\n\\newcommand{\\pd}[2]{\\frac{\\partial #1}{\\partial #2}}\n\\newcommand{\\uu}[1]{\\underline{\\underline{#1}}}\n\\newcommand{\\un}[1]{\\underline{#1}}\n\n\\title{Lecture 4: Introduction to Cartesian tensors}\n\\begin{document}\n\\maketitle\n\nThe key ideas are\n\\begin{itemize}\n  \\item Index notation for basic operations \n  \\item Coordinate transformations for vector and tensors\n  \\item Isotropic tensors\n\\end{itemize}\n\n\\section{Index notation}\n$$\\bm{a}\\cdot\\bm{b}=a_ib_i$$\n$$\\bm{a}\\wedge\\bm{b}=\\e_{ijk} a_j b_k$$\n$$\\bm{a}\\bm{b}=a_ib_j$$\n\nUsing these notations, we can briefly define some quantities of interest in transport phenomena.\\\\\n\\begin{itemize}\n\\item The gradient vector\n$$\\nabla T = \\pd{T}{x_i}$$\nwhich points in the direction of fastest rate of change of the scalar field $T$. Its inner product with a direction gives the rate of change of $T$ in that direction.\n\n\\item The divergence of velocity field\n$$\\nabla \\cdot \\bm{u} = \\pd{u_i}{x_i}$$\nwhich gives the normalized volumetric rate of change of a local volume element ($\\frac{1}{V}\\pd{V}{t}$). It is zero for an incompressible flow.\n\n\\item The curl of velocity field (vorticity)\n$$\\nabla \\wedge \\bm{u} = \\e_{ijk}\\pd{u_k}{x_j} $$\nwhich is a measure of the local rotation rate of the fluid.\n\n\\item The velocity gradient tensor\n$$\\nabla \\bm{u} = \\pd{u_i}{x_j}$$\nwhich has information about the volumetric change, rotation as well as the local shear rate of the flow. A second order tensor packs much more information than a vector. \n\\end{itemize}\n\nAs examples of their usage, we can write down few equations in index notation\n\\begin{itemize}\n  \\item Convection-diffusion equation\n$$\\pd{T}{t} + \\bm{u}\\cdot \\nabla T = \\kappa \\nabla^2 T \\hfill \\text{\\footnotesize{\\quad \\quad \\quad     (Gibbs notation)}}$$\n$$\\pd{T}{t} + u_j\\pd{T}{x_j} = \\kappa \\pd{^2T}{x_i \\partial x_i} \\hfill \\text{\\footnotesize{\\quad \\quad \\quad     (Index notation)}}$$\n\n  \\item Navier-Stokes equation\n$$\\rho(\\pd{\\bm{u}}{t} + \\bm{u}\\cdot\\nabla\\bm{u}) = -\\nabla P +\\mu \\nabla^2 \\bm{u} \\text{\\footnotesize{\\quad \\quad \\quad     (Gibbs notation)}}$$\n$$\\rho(\\pd{u_i}{t} + u_j\\cdot\\pd{u_i}{x_j}) = -\\pd{P}{x_i} +\\mu \\frac{\\partial^2 u_i}{\\partial x_j \\partial x_j} \\text{\\footnotesize{\\quad \\quad \\quad     (Index notation)}}$$\n\n\\end{itemize}\n\nWe will henceforth be denoting second order tensors with a double underbar as $\\uu{A}$ and vectors with a single underbar as $\\un{A}$. Some identities for products of tensors are given below\n\\begin{align*}\n\\uu{B}\\cdot \\un{a} &= B_{ij} a_j \\\\\n\\uu{B} \\cdot \\uu{C} &= B_{ik}C_{kj} \\\\\n\\uu{B} \\colon \\uu{C} &= B_{ij}C_{ji} \\\\\n\\end{align*}\n\nThe last of these is used in calculation of viscous dissipation which is given by $2\\mu\\uu{E}\\colon\\uu{E}$, where $\\uu{E}$ is a second order tensor given by\n\\begin{align*}\nE_{ij} &= \\frac{1}{2}(\\nabla \\un{u} + \\nabla \\un{u}^T)\\\\\n&=\\frac{1}{2}(\\pd{u_i}{x_j} + \\pd{u_j}{x_i})\n\\end{align*}\n\nwhere the form highlights the symmetry of the strain-rate tensor. Two more important relations are\n\\begin{itemize}\n  \\item Scalar triple product\n$$\\un{a}\\cdot(\\un{b}\\wedge\\un{c}) = \\e_{ijk}a_ib_jc_k$$\nwhich is the determinant of the matrix with $\\un{a},\\un{b}$ and $\\un{c}$ as its columns.\n\n  \\item Trace of $\\uu{B} = B_{ii}$\n\\end{itemize}\n\n\\section{Coordinate Transformation}\n\n\\subsection{Vectors}\n\nWe want to find out how does the representation of a vector changes when the coordinate system is transformed into another coordinate system. We will mainly be concered with Orthogonal transformations. Mathematically, this means that, the transformation matrix $L$ is such that\n$$L L^T = I \\Rightarrow L = L^{-1}$$\nPhysically, these transformations preserve angles between any two lines. Specifically, if two vectors were orthogonal before the transformation, then their transformed counterparts will also be orthogonal. Orthogonal transformations comprise of rotations and reflections of the coordinate system. The group of all possible rotations of a $n$ dimenisonal coordinate system is known as the $SO_n$ group (Special Orthogonal group in n dimenisons).\n\nNote that, in 3D, if the transformation is a rotation, then the matrix representing such a transformation has one and only one real eigenvalue, which is equal to 1. This is because the rotation matrix modifies every vector in the domain except the vector along its axis which is left unrotated (hence it's an eigenvector) and unstretched (hence the eigenvalue corresponding to it is 1). Other eigenvalues are imaginary. These transformations preserve the length of the vectors and the angle between any two vectors. In 2D, all vectors are transformed and hence both the eigenvalues are imaginary.\n\nLet $L$ be such a tranformation in 3D that acts on the \\textit{orthonormal unit vectors} $[\\un{1}_1,\\un{1}_2,\\un{1}_3]$ and yields the transformed \\textit{orthonormal unit vectors} $[\\un{1'}_1,\\un{1'}_2,\\un{1'}_3]$. Then, we can write\n$$\\un{1}'_i  = l_{ij}\\un{1}_j$$\nThe second order tensor $l_{ij}$ has nine elements, but they are not all indepenedent. The constraint of orthonormality of the transformed vectors gives six relations between the elements of $l_{ij}$\n\\begin{align*}\n\\un{1}'_i \\cdot \\un{1}'_j &= 0 \\text{\\quad \\footnotesize{if $i\\neq j$ (ensures orthogonality)}}\\\\\n&= 1 \\text{\\quad \\footnotesize{if $i = j$ (ensures normality)}}\n\\end{align*}\n\n\nand hence a second order tensor in 3D, that represents an orthogonal transformation has only 3 independent parameters. For rotations, two of these are required to fix the axis and one more to specify the angle of rotation. For reflections, all three are needed to specify the plane of reflection. \n\n\nFor 2D, we get 3 constraints and hence the angle of rotation is the only parameter. What about 4 and higher dimensions? In a D dimensional space, we will have D constraints due to orthogonality and ${D\\choose 2}$ due to normality. This results in $D(D-1)/2$ independent parameters.\n\nOnce the transformation rule for the unit vectors is clear, the transformation for any given vector $\\un{a} = a_i\\un{1}_i$ can be written as\n\n$$\\un{a}'_i= l_{ij}\\un{a}_j$$\n$$\\un{a}_j = l_{ji}\\un{a}'_i$$\n\n\\subsection{Second order tensors}\n\nLet there be a second order tensor $\\uu{B}$ with eigenvectors $[\\un{X}_1,\\un{X}_2,\\un{X}_3]$. We assume a symmetric second order tensor which allows us to use the fact that three orthogonal eigenvectors will exist. Then, such a tensor can be written as\n$$\\uu{B}=[\\lambda_1\\un{X}_1\\un{X}_1+\\lambda_2\\un{X}_2\\un{X}_2+\\lambda_3\\un{X}_3\\un{X}_3]$$\n\nLet the transformed version of $\\un{B}$ be $\\un{B}'$ with eigenvectors $[\\un{X}'_1,\\un{X}'_2,\\un{X}'_3]$. Then,\n$$\\uu{B}'=[\\lambda_1\\un{X}'_1\\un{X}'_1+\\lambda_2\\un{X}'_2\\un{X}'_2+\\lambda_3\\un{X}'_3\\un{X}'_3]$$\n\nNow we can use the trasformation rule for vectors $\\un{a}'_i= l_{ij}\\un{a}_j$ and transform the eigenvectors. This allows us to write down the final transformation rule in Gibbs notation as\n$$\\uu{B}'=\\uu{L}\\cdot\\uu{B}\\cdot\\uu{L^T}$$\nOr in index notation\n\\begin{align*}\nB'_{ij} &= l_{ik}B_{km}l^T_{mj}\\\\\n\\Rightarrow B'_{ij} &= l_{ik}B_{km}l_{jm}\\\\\n\\Rightarrow B'_{ij} &= l_{ik}l_{jm}B_{km}\n\\end{align*}\n\nThe final expression is highly sugggestive of a pattern which will allow us to generalize this expression to higher order tensors\n\n$$B'_{i_1i_2i_3...i_n} = l_{i_1j_1}l_{i_2j_2}l_{i_3j_3}...l_{i_nj_n}B_{j_1j_2j_3...j_n} \\text{ \\quad \\quad \\footnotesize{For the case of true tensors}}$$\n\n\n\n$$B'_{i_1i_2i_3...i_n} = Det(\\uu{L})l_{i_1j_1}l_{i_2j_2}l_{i_3j_3}...l_{i_nj_n}B_{j_1j_2j_3...j_n} \\text{ \\quad \\quad \\footnotesize{For pseudo tensors}}$$\n\nPseudo-tensors and pseudo-vectors are tensors which require a convention for their definition (such as the right hand screw rule). Their sign can change based on the convention. They do not directly represent physical quantities. E.g. vorticity, angular velocity and magnetic field. Another way to distinguish pseudo tensors is that they do not change direction upon reflection of the physical apparatus. A ball travelling to the right will be travelling to the left in the mirror; but a disc rotating clockwise is still rotating clockwise in the mirror. Its angular velocity vector doesn't flip sign. \n\n\\subsection{Quotient Rule}\nA transformation or a physical law relating a vector to another vector must be mediated via a second order tensor; a law relating two second order tensors be mediated via a fourth order tensor and so on.\n\nA law relating a vector to a second order tensor must be mediated by a third order tensor, so that two of the indices of the second and third order tensors can contract and result in a vector.\n\n\\section{Isotropic Tensors}\n\\begin{itemize}\n  \\item Zeroth order\\\\\n  All scalars are isotropic except psedo-scalars. Pseudo-scalars form upon contraction of a true vector with a pseudo-vector and their sign changes with convention.\n\n  \\item First order (Vectors)\\\\\n  The Null vector is the only isotropic vector. We are looking for a vector that is impervious to any orthogonal transformation. Since every vector suffers a change of direction under some or the other rotation, the only vector that remains unaffected under all rotations is the vector without a direction.\n\n  \\item Second order tensors\\\\\n  $\\dl_{ij}$ and its scalar multiples are the only second order isotropic vector. Since any vector is an eigenvector of the identity matrix, it implies that there is no special direction for such a matrix. Hence any direction changing transformation such as a rotation will leave it unchanged. \n\n  \\item Third order tensors\\\\\n  There is no true third order isotropic tensor. $\\e_{ijk}$ and its scalar multiples give a pseudo third order isotropic tensor.\n\n  \\item Third order tensors\\\\\n  All higher order isotropic tensors are constructed using $\\e_{ijk}$ and $\\dl_{ij}$. E.g.\n$$D_{ijkl} = c_1\\dl_{ij}\\dl_{kl} + c_2\\dl_{ik}\\dl_{jl} + c_3\\dl_{il}\\dl_{jk} $$\n\\end{itemize}\n\nSome examples of the use of isotropy in tensors are given below\n\n\\begin{itemize}\n  \\item Fourier's law \\\\\n  Fourier's law relates heat flux vector $\\un{q}$ to the temperature gradient vector $\\nabla T$\n$$\nq_i = K_{ij} \\pd{T}{x_j}\n$$\n\nHere the thermal conductivity tensor $K_{ij}$ is a second order tensor with 3 independent elements. However, for an isotropic material, the tensor will also be isotropic because it should not prefer any one direction over the other. Therefore, we can write $K_{ij} = \\kappa \\dl_{ij}$ and there remains only one independent parameter to be determined experimentally.\n\n  \\item Newton's law of viscosity \\\\\n  This is a relation between the stress tensor $\\tau_{ij}$ and the strain-rate tensor $\\nabla \\un{u}$. Both of these are second order and hence the relation must be mediated by a fourth order tensor representing viscosity in some sense.\n$$\n\\tau_{ij} = D_{ijkl} \\pd{u_l}{x_k}\n$$\n\nIf viscosity doesn't change with direction in a medium, then $\\uu{D}$ must be an isotropic tensor. Hence we can write\n$$D_{ijkl} = c_1\\dl_{ij}\\dl_{kl} + c_2\\dl_{ik}\\dl_{jl} + c_3\\dl_{il}\\dl_{jk} $$\n\nBut $\\tau_{ij}$ is a symmetric tensor. Therefore, terms formed by interchange of $i$ and $j$ must be equal and hence $c_2$ must be equal to $c_3$. This gives us\n\\begin{align*}\nD_{ijkl} &= \\bigg(c_1\\dl_{ij}\\dl_{kl} + c_2(\\dl_{ik}\\dl_{jl} + \\dl_{il}\\dl_{jk})\\bigg)\\pd{u_l}{x_k}\\\\\nD_{ijkl} &= c_1\\pd{u_l}{x_l}\\dl_{ij} + c_2(\\pd{u_i}{x_j}+\\pd{u_j}{x_i})\n\\end{align*}\n\nHere, $c_1$ is associated with the divergence and hence informs us of the resistance of the fluid to change in its volume. This is the bulk viscosity of the fluid.\n\n$c_2$ is associated with the strain-rate and tells about the resistance of the fluid to a shearing deformation (and also volumetric deformation). This leads to shear viscosity.\n\n\\end{itemize}\n\n\n\n\\section*{Appendix}\n\\subsection{Expanded form for some index notation results}\n\\begin{align*}\n\\bm{a} \\cdot \\bm{b} &= (a_1\\1_1+a_2\\1_2+a_3\\1_3)\\cdot(b_1\\1_1+b_2\\1_2+b_3\\1_3)\\\\\n&= \\sum_{i=1}^{3} a_i \\1_i \\cdot \\sum_{j=1}^{3} b_j \\1_j\\\\\n&= \\sum_{i=1}^{3} \\sum_{j=1}^{3} a_i b_j \\1_i \\cdot \\1_j\\\\\n&= \\sum_{i=1}^{3} a_i b_i\\\\\n&= a_i b_i  \n\\end{align*}\n\nIn the last step, we have used Einstein's summation convention which mandates that repeated indices are to be summed over. Henceforth, repeated indices will imply a summation over that index.\n\n\\begin{align*}\n\\bm{a} \\wedge \\bm{b} &= (a_1\\1_1+a_2\\1_2+a_3\\1_3)\\wedge(b_1\\1_1+b_2\\1_2+b_3\\1_3)\\\\\n&=\\sum_{i=1}^{3} a_i \\1_i \\wedge \\sum_{j=1}^{3} b_j \\1_j\\\\\n&=\\sum_{i=1}^{3}  \\sum_{j=1}^{3} a_i b_j \\1_i \\wedge  \\1_j\\\\\n&=\\sum_{i=1}^{3}  \\sum_{j=1}^{3} a_i b_j \\e_{ijk}\\1_k\\\\\n&=\\e_{ijk}a_ib_j\\\\\n&=\\e_{ijk}a_jb_k\n\\end{align*}\n\nWhere we have just relabelled the indices in the last step so that the first index $i$ remains the direction specifying index. \n\n\n\\subsection{Area under a Gaussian}\nThe area under a suitably defined Gaussian is independent of its standard deviation. \n\n\\subsection{Gradient vector in cylindrical and spherical coordinates}\nIn any coordinate system, the gradient vector can be written immidiately if we incorporate the metric factors relevant to the coordinate system. Including the metric factor converts a small change in a coordinate variable to a small change in length along that coordinate (E.g.$d\\theta$ to $rd\\theta$ ).\n\n\\subsection{Proof for vector transformations}\n$$\\un{a}'_i= l_{ij}\\un{a}_j$$\n$$\\un{a}_j = l_{ji}\\un{a}'_i$$\n\n\\subsection{Symmetric matrices have orthogonal eigenvectors}\n\n\\subsection{Proof for the quotient rule}\n\n\\subsection{Proof that $\\dl_{ij}$ and $\\e_{ijk}$ are isotropic}\n\n\n\\end{document}\n", "meta": {"hexsha": "795f7318cdea663749e5d35d38a09268a684f29b", "size": 13630, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex_files/lecture04.tex", "max_stars_repo_name": "pulkitkd/Fluid_Dynamics_notes", "max_stars_repo_head_hexsha": "f4ffd25fa16fa08c2c2a5d465bb8a19a1d02d850", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-16T04:19:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-16T04:19:07.000Z", "max_issues_repo_path": "tex_files/lecture04.tex", "max_issues_repo_name": "pulkitkd/Fluid_Dynamics_notes", "max_issues_repo_head_hexsha": "f4ffd25fa16fa08c2c2a5d465bb8a19a1d02d850", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex_files/lecture04.tex", "max_forks_repo_name": "pulkitkd/Fluid_Dynamics_notes", "max_forks_repo_head_hexsha": "f4ffd25fa16fa08c2c2a5d465bb8a19a1d02d850", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.268907563, "max_line_length": 602, "alphanum_fraction": 0.7296404989, "num_tokens": 4246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324713956854, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.7111659102327349}}
{"text": "\\section{Methodology}\\label{sec:method}\n\n\\subsection{Original Form of the SDP}\nConsider a Boolean function $f$ such that\n$f: D \\rightarrow E$ where \n$D \\subseteq {\\{0,1\\}}^n$ and $E \\subseteq {\\{0,1\\}}$.\nWe state Reichardt's formulation of the SDP \\cite{reichardt2009span}.\n(Note that $[n]$ denotes the array\n$[1,2,...,n]$.)\nThe quantum query complexity of $f$ is\n\\begin{align} \\label{Eq:reichardt_obj} \n    \\min_{\\X} \\max_{y \\in D} \\sum_{j \\in [n]} \\bra{y,j}\\X\\ket{y,j} \n\\end{align}\nfor some $\\X$ subject to the constraints that $\\X$ is positive semidefinite\n(all its eigenvalues are non-negative)\nand for ordered pairs ($y$,$z$) such that $f(y) \\neq f(z)$,\n\\begin{align}\\label{Eq:reichardt_F0}\n    \\sum_{j \\in [n]: y_j \\ne z_j} \n    \\bra{y,j} \\X \\ket{z, j} = 1.\n\\end{align}\n\n\\subsection{Standard Form of the SDP}\nIn order to implement an algorithm that solves \nReichardt's formulation, we convert the SDP\ninto the canonical standard form\n\\cite{boyd2004convex}.\nThen the standard form objective function of the SDP is\n\\begin{align}\\label{Eq:boyd_obj}\n    \\tr(C\\Xb)\n\\end{align}\nfor some fixed matrix $C$ subject to the constraints\nthat $\\Xb$ is semidefinite and for $i \\in [p]$\n\\begin{align} \\label{Eq:boyd_trace}\n    \\tr(A_i \\Xb) = b_i\n\\end{align}\nfor some fixed matrices $A_i$ and $b_i$.\n\n\\subsection{Converting from Original to Standard Form}\nWe now convert the original form of the SDP to\nthe standard form by constructing appropriate matrices $A_i$, $b_i$, $\\Xb$, and $C$.\n\nTo understand this conversion, we must first gain some intuition about $\\X$.\nIt is clear from \\cref{Eq:reichardt_obj} that for \neach $y \\in D$, there exists a corresponding $n \\times n$ sub-matrix of $\\X$ along its diagonal.\nThen $\\X$ must have a total of $n|D|$ rows and $n|D|$ columns.\nIn general, $|D| = 2^n$ but it is possible to take \nworst-case subsets of $D$ and still find the correct solution, as discussed later.\n\nTo convert \\cref{Eq:reichardt_F0} into \\cref{Eq:boyd_trace},\nwe must construct $A_i$, $b_i$ for $i \\in [p]$.\nLet $p = |F|$, then each pair $(y,z) \\in F$\nis associated with a single $A_i$.\nFor each $(y,z)$, we are interested in the entries\nin $\\X$ that correspond to the bits $y_i$ and $z_i$\nwhere $y_i \\neq z_i$ for $i \\in [n]$. These entries are intuitively of interest because they are the bits that must lead to different outputs.\nThey are necessarily off of the main diagonal,\nbecause $y\\neq z$,\nso our $A_i$ will map them to the main diagonal \nand ensure that the trace of $A_i \\X$ is 1.\nNote that $b_i = 1$.\n\nTo place particular entries of $\\X$ onto the main diagonal,\nlet $A_i$ be the transpose of the zero matrix with\nones in the particular entries of interest.\nWe illustrate on a small example.\nLet\n\\begin{align}\n    \\X = \\left[ \\begin{matrix} 1 & 2 \\\\ 3 & 4 \\end{matrix} \\right] \\nonumber\n\\end{align}\nand the particular entry of interest be the top right value of $\\X$.\nThen\n\\begin{align}\n    A_i = \\left[ \\begin{matrix} 0 & 1 \\\\ 0 & 0 \\end{matrix} \\right]^\\textrm{T} \\nonumber\n    = \\left[ \\begin{matrix} 0 & 0 \\\\ 1 & 0 \\end{matrix} \\right] \\nonumber\n\\end{align}\nso that\n\\begin{align}\n    A_i \\cdot \\X = \\left[ \\begin{matrix} 2 & 0 \\\\ 4 & 0 \\end{matrix} \\right] \\nonumber\n\\end{align}\nand $\\tr(A_i \\cdot \\X) = 2$ as desired.\n\nHaving converted the constraints, we must also convert the objective functions. Let $c_i$ be the sum of the $n$ entries\nin the $i^\\mathrm{th}$ section of the main diagonal of $\\X$\nsuch that\n\\begin{align}\n    c_i = \\sum_{j \\in [n]} \\bra{y,j}\\X\\ket{y,j}\n    \\nonumber\n\\end{align} \nwhere $y$ is the $i^{th}$ element of $D$ for\n$i \\in [|D|]$.\nLet $z$ be $\\tr(C\\X)$.\nThe last challenge is to satisfy \\cref{Eq:boyd_obj}\nby enforcing that $z$ is the maximum $c_i$.\nOur solution is to introduce non-negative slack variables\n$s_i$ for $i \\in [|D|]$ and the constraints\n$c_i + s_i = z$.\n\nWe construct a new matrix $\\Xb$ to account for these slack variables. Call $S$ the zero matrix\nwhose diagonal holds the entries $s_1,...,s_{|D|}, z$.\nThen\n\\begin{align}\n    \\Xb = \\left[ \\begin{matrix} \\X & 0 \\\\ 0 & S \\end{matrix} \\right] \\nonumber.\n\\end{align}\nSince $\\Xb$ is semidefinite, the main diagonal entries of\n$\\Xb$ must be non-negative so $s_i \\geq 0$. Thus $C$ is defined to have $\\tr{C\\Xb}$ extract the bottom right entry of $\\Xb$. Therefore, let $C$ be the zero matrix with a single one in the bottom right entry.\n\nTo enforce that $z$ is the maximum $c_i$ over all $i$,\nwe construct $\\Ap_i$ and set $\\bp_i$ to 0\nfor $i \\in [|D|]$. For the purposes of the standard form,\nwe now have two sets of $A_i$ and $b_i$ constraints.\nLet $\\Ap_i$ be the zero matrix with ones\nalong the entries corresponding to the input $i$ of $D$,\na one in the entry corresponding to $s_i$,\nand a negative one in the bottom right entry corresponding\nto the objective function $z$.\nThen\n\\begin{align}\n    \\tr (\\Ap_i \\Xb ) &= c_i + s_i -z = 0 \\nonumber.\n\\end{align}\nBecause $s_i$ is non-negative and $z$ is being minimized,\n$z$ is both greater than or equal to all $c_i$ and meets\nsome $c_i$. Thus $z$ is the maximum $c_i$ as desired.\n\nThe solution $\\Xb$ that satisfies the standard form according\nto the constructed $A_i$, $\\Ap_i$, $b_i$, $\\bp_i$, and $C$ will \nalso hold the solution $\\X$ to the original form.\nTherefore, to find the optimal quantum query complexity of $f$,\nwe need only solve \\cref{Eq:boyd_obj} subject to our constraints.\n\n\\subsection{Query Efficient Span Programs}\n\nA span program is a model of computation that outputs a\nBoolean value corresponding to whether or not a set\nof vectors \"spans\" to a target vector. The algorithm consists\nof a set of\nvectors such that on a given input, the vectors are\npartitioned into available and unavailable sets. The\navailable vectors are turned into the columns of a\nmatrix $A$.\nThese vectors form a linear system $Ax = \\tau$\nfor a fixed target vector $\\tau$.\nIf this system is homogeneous-- there exists\nsome non-trivial vector $x$ that satisfies the equation--\nthen the algorithm returns true.\nOtherwise, the algorithm returns false.\n\nBoth Childs and Reichardt mathematically formulate\nalgorithms for turning the results of the SDP we solved\ninto a span program \\cite{reichardt2009span, childs}.\nTo begin, we must construct a set of vectors\n$\\bra{v_{y,i}}$ for all $y \\in D$ where $i = [n]$.\nGiven any two input strings $y, z \\in D$ such that $y\\neq z$,\n\\begin{align}\n    \\sum_{i: y_i \\ne z_i} \\braket{v_{y,i}|v_{z,i}} = 1 - \\delta_{f(y), f(z)} \\nonumber\n\\end{align}\nwhere $\\delta_{f(y), f(z)} = 1$ if $f(y) = f(z)$ and $0$ otherwise.\n\nRecall from \\cref{Eq:reichardt_F0} that $\\X$ satisfies\n\\begin{align}\n    \\forall (y,z) \\in F \\sum_{j \\in [n]: y_j \\ne z_j} \n    \\bra{y,j} \\X \\ket{z, j} = 1 \\nonumber.\n\\end{align}\nWe would like to construct $\\bra{v_{y,i}}$ and $\\ket{v_{z,i}}$\nfrom $\\X$.\nSo we define a matrix $L$ such that $L^\\dagger L = \\X$.\nThen $\\bra{v_{y,i}} = \\bra{y_i}L^\\dagger$.\nWe can now reformulate the requirement of vectors $\\bra{v_{y,i}}$\nas\n\\begin{align}\n    \\sum_{i: y_i \\ne z_i} \\braket{v_{y,i}|v_{z,i}} &= \\sum_{i: y_i \\ne z_i}\n    \\bra{y,i} L^\\dagger L \\ket{z, i} \\nonumber \\\\\n    &= \\sum_{i: y_i \\ne z_i} \\bra{y,i} \\X \\ket{z, i} = \\begin{cases}\n        1 & f(y) \\ne f(z) \\\\\n        0 & f(y) = f(z)\n    \\end{cases} \\nonumber \n\\end{align}\nThe constraints enforce the $f(y) \\neq f(z)$ case and we programatically\ncheck the $f(y) = f(z)$ case before returning $\\X$.\n\nGiven the set of vectors $\\bra{v_{y,i}}$ for all $y \\in\nD$, $i = 0, 1, \\ldots , n-1$, we construct \nmatrix $I$ that contains the vectors for the span\nprogram. We will make use of the sets $F_i =\n\\{y \\in D: f(y) = i\\}$.\n(Note that $F_i[k]$ denotes the $k^{th}$ element of $F_i$.)\n\n\\begin{align}\\label{input_vectors}\n    I = \\sum_{k \\in [|F_0|], j \\in [n], y = F_0[k]}\n    \\ket{k}\\bra{j, \\overline{y_j}} \\bra{v_{y,j}}\n\\end{align}\n\nThis matrix $I$ is divided into sub-matrices that\ncorrespond to different bits in the input to the\nalgorithm.\nThe columns of $I$ are evenly divided into\n$n$ chunks corresponding to each input bit.\nEach of these sub-matrices is further evenly divided into a left and\nright sub-matrix, corresponding to a $0$ or $1$\nin the relevant bit of the input.\nLet $I(y)$ be the set of columns in \n$I$ that are available on input $y \\in D$.\nThe target vector $\\tau$ \nis a vector of ones vector with the same \ndimension as $I$.\nThe output is true if and only if the available\nvectors $I(y)$ span to $\\tau$.\nReichardt proves that the span program $I$ \nand $\\tau$ is a query optimal \nquantum algorithm for $f$ \\cite{reichardt2009span}.\n", "meta": {"hexsha": "a4de2fdd0620cf45c63de0b1f2f439caeaab6766", "size": 8495, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sec/2_methodology.tex", "max_stars_repo_name": "rtealwitter/QuantumQueryOptimizer", "max_stars_repo_head_hexsha": "64f68110ab088c271fad96976f2fa06af88d5a2e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/sec/2_methodology.tex", "max_issues_repo_name": "rtealwitter/QuantumQueryOptimizer", "max_issues_repo_head_hexsha": "64f68110ab088c271fad96976f2fa06af88d5a2e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/sec/2_methodology.tex", "max_forks_repo_name": "rtealwitter/QuantumQueryOptimizer", "max_forks_repo_head_hexsha": "64f68110ab088c271fad96976f2fa06af88d5a2e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.4523809524, "max_line_length": 207, "alphanum_fraction": 0.6871100647, "num_tokens": 2796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092414, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7111411298242891}}
{"text": "\\subsection{Higher-Genus Surfaces}\r\nWe want to construct Riemann surfaces with genus $n>1$.\r\n\\begin{example}\r\n    Consider the Fermat curve of degree $d$:\r\n    $$F_d'=\\{(x,y)\\in\\mathbb C^2:x^d+y^d=1\\}$$\r\n    the understanding of whose rational point, incidentally, is Fermat's Last Theorem.\r\n    This is obviously not we are interested in here.\r\n    As usual we want to make it a Riemann surface.\r\n    The coordinate projection $\\pi_x:(x,y)\\mapsto x$ has local inverse $\\pi_x^{-1}(x_0)=(x_0,\\sqrt[d]{1-x_0^d})$ which exists and is continuous in a neighbourhood of any $x_0$ unless $x_0$ is a $d^{th}$ root of unity, i.e. $x=\\zeta_d^i$ for some $i$ where $d=\\exp(2\\pi i/d)$, which happens iff $y_0=0$ (where $(x_0,y_0)\\in F_d'$).\r\n    Symmetrically, $\\pi_y$ provides charts on $F_d'\\setminus\\{(0,\\zeta_d^i)\\}$.\r\n    These charts cover everything as the points where $\\pi_x$ and $\\pi_y$ don't work are distinct.\r\n    The non-trivial transition functions are $\\pi_y\\circ\\pi_x^{-1}(x)=\\sqrt[d]{1-x^d},\\pi_x\\circ\\pi_y^{-1}(y)=\\sqrt[d]{1-y^d}$ which are analytic where they need to be.\r\n    It is quite obvious that $F_d'$ is Hausdorff since it inherits its topology from $\\mathbb C^2$.\r\n    To see it is connected, consider\r\n    $$D=\\mathbb C\\setminus\\left(\\bigcup_{i=1}^d\\{t\\zeta_d^i:t\\ge 1,i\\in\\{0,\\ldots,d-1\\}\\}\\right)$$\r\n    Now there are well-defined branches of $y=\\sqrt[d]{1-x^d}$ in $D$ which can be extend continuously to $\\zeta_d^i$.\r\n    Let $(x_0,y_0)\\in F_d'$.\r\n    Suppose $x_0\\in D$, then we can choose a branch of $y(x)=\\sqrt[d]{1-x^d}$ such that $y(x_0)=y_0$.\r\n    Let $\\gamma$ be any path in $D$ from $x_0$ to $1$, then $\\tilde\\gamma(t)=(\\gamma(t),y(\\gamma(t)))$ is a path joining $(x_0,y_0)$ to $(1,0)$.\r\n    As for the $d$ rays in $F_d'\\setminus D$, we can also find a branch locally near that and join it to something nearby that is in $D$ (possible as $D$ is dense in $\\mathbb C$).\r\n    Therefore $F_d'$ has to be path-connected.\r\n    Consequently it is indeed a Riemann surface.\\\\\r\n    We can compactify by gluing $F_d=F_d'\\cup_\\Phi F_d''$.\r\n    The details can be found from example sheet, where we also extend the covering map to a meromorphic $\\hat\\pi_x:F_d\\to\\mathbb C_\\infty$ with $\\deg\\hat\\pi_d=d$.\r\n    Also $|\\hat\\pi_x^{-1}(\\infty)|=d$, so $\\infty$ is not a ramification point.\r\n    The ramification points are then $\\{(\\zeta_d^i,0),i\\in\\{0,\\ldots,d-1\\}\\}$ and all of them have multiplicity $d$.\r\n    Riemann-Hurwitz then gives\r\n    $$2g_{F_d}-2=d(0-2)+d(d-1)\\implies g_{F_d}=\\frac{(d-1)(d-2)}{2}$$\r\n\\end{example}\r\nThe conclusion is then there does exist Riemann surfaces with arbitrarily large genus.", "meta": {"hexsha": "f46a3abb0291275e8877d1d47647aefc1d0b9f91", "size": 2627, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "12/higher.tex", "max_stars_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_stars_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "12/higher.tex", "max_issues_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_issues_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "12/higher.tex", "max_forks_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_forks_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 87.5666666667, "max_line_length": 331, "alphanum_fraction": 0.6627331557, "num_tokens": 906, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223265, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7109122974566578}}
{"text": "\\subsection{Minkowski functionals}\\label{subsec:minkowski_functionals}\n\n\\begin{definition}\\label{def:minkowski_functional}\n  Let \\( A \\) is an \\hyperref[def:neighborhood_set_types/absorbing]{absorbing} \\hyperref[def:linear_combination/convex]{convex} set.\n\n  We define the corresponding \\term{Minkowski functional}\n  \\begin{balign*}\n     & \\rho_A: X \\to [0, \\infty),\n     & \\rho_A(x) = \\inf \\{ t > 0 \\colon x \\in tA \\}.\n  \\end{balign*}\n\\end{definition}\n\\begin{proof}\n  We will prove that \\( \\rho_A(x) \\) is always a nonnegative real number. Obviously\n  \\begin{equation*}\n    \\rho_A(x) \\geq 0\n  \\end{equation*}\n  since the infimum over \\( \\BbbR_{>0} \\) is \\( 0 \\).\n\n  Now fix \\( x \\in X \\). Since \\( A \\) is an absorbing set, there exists \\( t_0 > 0 \\) such that \\( t_0 x \\in A \\). We need to take the infimum of all such numbers. This infimum exists since \\( \\BbbR \\) is complete and the set over which we take the minimum is bounded.\n\\end{proof}\n", "meta": {"hexsha": "26b130a8353c2b449a370090eb94b655eee86bd0", "size": 947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/minkowski_functionals.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/minkowski_functionals.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/minkowski_functionals.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.0952380952, "max_line_length": 269, "alphanum_fraction": 0.6779303062, "num_tokens": 318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7109122825107683}}
{"text": "\\section{Conclusion} \\label{conclusion}\n\nIn this project, we implement a real-roots isolation program based on\nBudan’s theorem and continued fraction. Besides that, we also use several\nmethods to optimize the program, like Taylor Expansion for polynomial shift and\ninterval arithmetic for error control.\n\nThen we compare the running time of these two algorithms. It is noticeable that\nwhen there are conjugate complex roots, Budan’s theorem will take longer. And\ncontinued fraction methods perform worse when polynomials have several large\nreal roots due to slow shifts of polynomials. This can be optimized in the\nfuture.\n\nWith the application of interval arithmetic, our program becomes more robust to\nthe errors from inexact computation and representation, although it is not\nperfect for all of the cases. We analyze the conditions that might\ncause failure of the program. We find that after square-free decomposition,\nevery factors has error in express of coefficients. It is hard to isolate close\nreal roots with this expression since small change of coefficients might causes\nlarge change the property of these roots.\n\n\n", "meta": {"hexsha": "7cc93755d5f089786616ab98ea28214bcd14ecc0", "size": 1126, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/070conclusion.tex", "max_stars_repo_name": "willyii/PolynomialRootFinding", "max_stars_repo_head_hexsha": "18c7edd8fadf3dc48d2dc6480f0cf6f624cea80f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/070conclusion.tex", "max_issues_repo_name": "willyii/PolynomialRootFinding", "max_issues_repo_head_hexsha": "18c7edd8fadf3dc48d2dc6480f0cf6f624cea80f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-13T00:53:54.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-13T00:53:54.000Z", "max_forks_repo_path": "report/070conclusion.tex", "max_forks_repo_name": "willyii/PolynomialRootFinding", "max_forks_repo_head_hexsha": "18c7edd8fadf3dc48d2dc6480f0cf6f624cea80f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-13T12:54:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-13T12:54:48.000Z", "avg_line_length": 48.9565217391, "max_line_length": 79, "alphanum_fraction": 0.8197158082, "num_tokens": 221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8670357598021708, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7108768471840796}}
{"text": "In this Section we introduce the Parametric Hypercubes abstract domain \\adomain.\n\nIntuitively, an abstract state of our domain tracks disjunctive information relying on floating-point intervals of fixed width. A state of \\adomain\\ is made by a set of hypercubes of dimension $|\\variables|$. Each hypercube has $|\\variables|$ sides, one for each variable, and each side contains an abstract non-relational value for the corresponding variable. Each hypercube represents a set of admissible combinations of values for all variables. \n\nThe name Hypercubes comes from the geometric interpretation of the elements of \\adomain . The concrete state of a program with variables in $\\variables$ is an environment in $\\funzione{\\variables}{\\real}$. This can be isomorphically represented by a tuple of values where each item of the tuple represents a program variable. Seen in this way, the concrete state corresponds, geometrically, to \\emph{a point} in the $|\\variables|$-dimensional space. Each dimension of the space represents the possible values that the corresponding variable of the program can assume. The concrete trace of a program is a sequence of points in such space (one for each state of the trace). The hypercubes of our \\adomain\\ domain are \\emph{volumes} in the same $|\\variables|$-dimensional space. Each side of the hypercube is the concretization of the abstract value of the corresponding variable, and thus it corresponds to a set of values in that dimension of the space. The concretization of an hypercube is the set of all the points contained in its volume. A state in \\adomain\\ is composed by a set of hypercubes: its concretization is the union of all the volumes of its hypercubes.  In this way we track disjunctive information.\n\n\n\\subsection{Lattice structure}\nAn abstract state of \\adomain\\ is made by a \\emph{set} of hypercubes. Each hypercube is represented by a tuple of abstract values. The dimension of these tuples is equal to the number of program variables: this means that each variable is associated to a given item of the tuple (i.e., to a specific side of the hypercube). \nConsider for instance a program in which $\\variables = \\{x_1, x_2\\}$. In this case, the hypercubes of \\adomain\\ are 2D-rectangles. In particular, the two sides of a single hypercube are two abstract values, one for $x_1$ and one for $x_2$.\n\nA priori, our approach is modular w.r.t. the non-relational abstract domain we adopt to approximate the values of single variables inside an hypercube. We abstract floating-point variables through intervals of real values. We adopt set of hypercubes to improve the precision of the analysis and to track disjunctive information. This is useful, for instance, when the values of a variable are clustered in different ranges: instead of having a very big interval to cover them all (and which would cover also a lot of invalid values), we use two (or more) smaller intervals. Since it would be particularly expensive to perform all the lattice operators pointwisely, we partition the possible values into intervals of fixed width. As an example, suppose that the initial vertical velocity of the balls of our case study ranges between $50.0$ and $60.0$ or between $-60.0$ and $-50.0$. A single interval would approximate these values with $[-60.0,60.0]$, while with our approach we track two intervals, $[-60.0,-50.0]$ and $[50.0,60.0]$ (with fixed width $10.0$), which distinguish between balls thrown downwards and balls thrown upwards. The performance of this domain, though, becomes a crucial point, because the number of possible hypercubes in the space is potentially exponential with respect to the number of partitions along each spatial axis. The complexity is lightened by the use of a \\emph{fixed} width for each variable, by partitioning the possible intervals, and by the efficiency of set operators on tuples.\n\nSince a single hypercube is a tuple of intervals (one for each side), another performance booster is the use of a smart representation for intervals. In order to store the specific interval range we just use a single integer representing it. Each variable $x_i$ is associated to an interval width (specific only for that variable), which we call $w_i$ and which is a parameter of the analysis. In Section \\ref{sec:tuning} we will present a variation of our analysis which computes automatically the widths, adapting them recursively and freeing the user from the need to specify values for them. For now, just notice that the smaller the width associated to a variable, the more granular and precise the analysis on that variable (and the heavier computationally the analysis). Each width $w_i$ is a floating point number that represents the width of all the possible abstract intervals associated to $x_i$. More precisely, given a width $w_i$ and an integer index $m$, the interval uniquely associated to the variable $x_i$ is $[m \\times w_i, (m+1) \\times w_i]$.\n\n\\textbf{Example:} Consider the case study of Section \\ref{sec:case_study} and in particular the two variables \\statement{px} and \\statement{py}. Suppose that the widths associated to such variables are $w_1 = 10.0, w_2 = 25.0$. The hypercubes in this case are 2D-rectangles. The area of each rectangle is $10.0 \\times 25.0 = 250.0$. We can draw such rectangles on the Cartesian plan, where the horizontal axis represents the values which \\statement{px} can assume, and the vertical axis represents those of \\statement{py}. Each side of a hypercube is identified by an integer index, representing the interval of values associated to that side. A 2D hypercube is then uniquely identified by a pair of integers. For instance, the hypercube $h_1 = ( 0, 1 )$ says that $\\statement{px} \\in [0.0, 10.0]$ and $\\statement{py} \\in [25.0, 50.0]$, while the hypercube $h_2 = ( 0, 0 )$  associates $\\statement{px}$ to $[0.0, 10.0]$ and $\\statement{py}$ to $[0.0, 25.0]$. In Figure \\ref{fig:hcExample} we can see the graphical representation of the two hypercubes associated to the initialization of the case study (i.e., $h_1$ and $h_2$). The two axes of the Cartesian plan are split in correspondence of multiples of $10.0$ ($x$-axis) and $25.0$ ($y$-axis). In Figure \\ref{fig:hcExample2}, instead, we depict the hypercubes obtained after executing the first iteration of the \\statement{while} loop. Note that the hypercubes are now six. The ball is moving towards the right of the screen and is going downwards: this is coherent with the fact that the horizontal velocity is certainly positive (between $0.0$ and $60.0$), while the vertical velocity is certainly negative (between $-30.0$ and $-25.0$). \n\n\\begin{figure}[ht]\n\\begin{centering}\n\\includegraphics[scale=0.35]{Pics/example_hc_2d.png}\n\\caption{The abstract state of the case study after the initialization of the variables (focusing the attention only on \\statement{px,py}, when their widths are, respectively, $10.0$ and $25.0$)}\n\\label{fig:hcExample}\n\\end{centering}\n\\end{figure}\n\n\\begin{figure}[ht]\n\\begin{centering}\n\\includegraphics[scale=0.35]{Pics/example_hc_2d_2.png}\n\\caption{The abstract state of the case study after the first iteration of the loop (focusing the attention only on \\statement{px,py}, when their widths are, respectively, $10.0$ and $25.0$)}\n\\label{fig:hcExample2}\n\\end{centering}\n\\end{figure}\n\n\nWe now define formally our abstract domain. Each abstract state is a set of hypercubes, where each hypercube is composed by $|\\variables|$ integer numbers. The abstract domain is then defined by $\\adomain = \\wp(\\integer^n)$ where $n = |\\variables|$.\n\nThe definition of lattice operators relies on set operators: the partial order is defined through set inclusion, the lub and glb are set union and set intersection, respectively, while bottom and top are the empty set and the set containing all possible $n$-dimensional hypercubes, respectively. Formally, the lattice definition is $\\langle\\wp(\\integer^n), \\subseteq, \\cup, \\cap, \\emptyset, \\integer^n\\rangle$.\n\n\\begin{lemma}\n$\\langle\\wp(\\integer^n), \\subseteq, \\cup, \\cap, \\emptyset, \\integer^n\\rangle$ is a complete lattice.\n%\\begin{proof}\n%The proof follows immediately by basic properties of set operators.\n%\\end{proof}\n\\end{lemma}\n\n\\subsection{Concretization function}\nWe denote by $\\ael{A}$ the non-relational abstract domain on which our analysis is parameterized, and by $n$ the number of variables of the program, where $n = | \\variables |$.\n\n$$\n\\begin{array}{l}\n\\gamma_{\\aval} : \\funzione{\\wp(\\integer^n)}{\\wp(\\real^\\variables)}\\\\\n\\gamma_{\\aval}(\\ael{V}) = \\{\\sigma : \\exists v \\in \\ael{V} : \\forall i \\in [1..n] : \\sigma_i \\in \\gamma_\\ael{A}(\\afunction{getAbsValue}_v(i)) \\}\n\\end{array}\n$$\n\nwhere: (i) $\\sigma \\in \\real^\\variables$ and $\\sigma_i \\in \\real$ denotes the $i$-th element of the tuple $\\sigma$, (ii) $\\gamma_\\ael{A} : \\funzione{\\ael{A}}{\\wp(\\real)}$ is the concretization function of abstract values of the non-relational abstract domain on which our analysis is parameterized, and (iii)  $\\afunction{getAbsValue}_v : \\funzione{\\naturals}{\\ael{A}}$ is the function that, given an integer index, returns the abstract value (in the domain $\\ael{A}$) which corresponds to that index inside the tuple $v$.\n\n$\\gamma_{\\aval}$ concretizes a set of hypercubes to a set of vectors of $n$ floating point values. \n\n$$\n\\begin{array}{l}\n\\gamma_{\\adomain} : \\funzione{\\wp(\\integer^n)}{\\wp(\\funzione{\\variables}{\\real})}\\\\\n\\gamma_{\\adomain}(\\ael{V}) = \\{[\\statement{x} \\mapsto \\cel{r}(\\avariableindex{\\statement{x}}) : \\statement{x} \\in \\variables] : \\cel{r} \\in \\gamma_{\\aval}(\\ael{V})\\}\n\\end{array}\n$$\n\n$\\gamma_{\\adomain}$ simply transforms the vectors returned by $\\gamma_{\\aval}$ into concrete environments relying on the function $\\avariableindexname : \\funzione{\\variables}{\\naturals}$, that, given a variable, returns its index in the elements of \\adomain.\n\n%Intuitively, we represent a concrete value as a tuple of real values (one for each variable of the program). The concretization of an abstract state $h \\in \\adomain$ is then a set of tuples. The concretization of $h$ is the union of all the concretizations of its hypercubes, i.e., all the points belonging to the volumes of its hypercubes. Each tuple of the concretization of $h$, then, is a point belonging to one hypercube of $h$. \n\n\\subsection{Widening operator}\nThe domain described so far does not ensure the convergence of the analysis. In fact, a \\statement{while} loop may add new hypercubes with increased indices at each iteration, and the dimension of the abstract state (i.e., the hypercubes set) would increase at each iteration without converging. Thus, we need a way to force the convergence of the analysis. Given our abstract state representation, we fix for each variable of the program a maximum integer index $n_i$ such that $n_i$ represents the interval $[n_i \\times w_i, +\\infty]$. The same happens symmetrically for negative values. In this way, the set of indices of a given variable is finite, and the resulting domain has finite height. Thus, in this scenario, the widening operator coincides with the lub operator, i.e., set union. \n\nThis approach may seem too rough since we establish the bounds of intervals before running the analysis. However, this allows us to control the number of possible intervals in our hypercubes, and this is particularly important for the efficiency of the overall analysis. In addition, when analysing physics simulations we can use the initialization of variables and the property we want to check in order to establish convenient bounds for the intervals. For instance, in the case study presented in Section \\ref{sec:case_study} we are interested in checking if a ball stays in the screen, that is, if \\statement{px} is greater than zero and less than a given value \\statement{w} representing the width of the screen.\n\nObserve that more sophisticated widening operators could be used as an alternative to the adopted solution described above, but this could affect the performance of the resulting analysis.\n\n%\\subsection{Other data types or non-relational abstractions}\n%\\todogiulia{Secondo me questa subsection si puo' cancellare}\n%As suggested before, for now we focus the application of our abstract domain to physics simulations, and for this reason we abstract floating point variables through intervals of fixed width. However, we may apply other kind of abstractions (e.g., the Sign domain) to our framework to consider other types of variables (integer, boolean, etc.). We will sketch other possible applications of our framework in Section \\ref{sec:otherapplications}.\n\n", "meta": {"hexsha": "7d913a6647b4088165fed7bacc8e96d418e63b5f", "size": 12575, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "12. Hypercubes Domain/HC/Sections/versione SAS2013/3a_hypercubes_domain.tex", "max_stars_repo_name": "vs-team/Papers", "max_stars_repo_head_hexsha": "58fa4a3b4c8185ad30bf9a142002d87ceca756e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-04-06T08:46:02.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-19T07:16:23.000Z", "max_issues_repo_path": "12. Hypercubes Domain/Sections/versione SAS2013/3a_hypercubes_domain.tex", "max_issues_repo_name": "vs-team/Papers", "max_issues_repo_head_hexsha": "58fa4a3b4c8185ad30bf9a142002d87ceca756e6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "12. Hypercubes Domain/Sections/versione SAS2013/3a_hypercubes_domain.tex", "max_forks_repo_name": "vs-team/Papers", "max_forks_repo_head_hexsha": "58fa4a3b4c8185ad30bf9a142002d87ceca756e6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 153.3536585366, "max_line_length": 1693, "alphanum_fraction": 0.7701789264, "num_tokens": 3122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7107688714739507}}
{"text": "\\input{../header_function}\n\n%---------- start document ---------- %\n\\section{arith1 - miscellaneous arithmetic functions}\\linkedzero{arith1}\n\n\\subsection{floorsqrt -- floor of square root}\\linkedone{arith1}{floorsqrt}\n\\func{floorsqrt}{\\hiki{a}{integer/\\linkingone{rational}{Rational}}}{\\out{integer}}\\\\\n\\spacing\n% document of basi document\n\\quad Return the floor of square root of \\param{a}.\\\\ \n%\\spacing\n% input, output document\n%\\quad Input number \\param{a} must be integer or \\linkingone{rational}{Rational}.\\\\\n%\n\\subsection{floorpowerroot -- floor of some power root}\\linkedone{arith1}{floorpowerroot}\n\\func{floorpowerroot}{\\hiki{n}{integer},\\ \\hiki{k}{integer}}{\\out{integer}}\\\\\n\\spacing\n% document of basi document\n\\quad Return the floor of \\param{k}-th power root of \\param{n}.\\\\\n%\\spacing\n% input, output document\n%\\quad Input numbers \\param{n}, \\param{k} must be integer.\\\\\n%\n\\subsection{legendre - Legendre(Jacobi) Symbol}\\linkedone{arith1}{legendre}\n\\func{legendre}{\\hiki{a}{integer},\\ \\hiki{m}{integer}}{\\out{integer}}\\\\\n\\spacing\n% document of basi document\n\\quad Return the Legendre symbol or Jacobi symbol $\\DS \\Bigl(\\frac{\\param{a}}{\\param{m}}\\Bigr)$.\\\\\n%\\spacing\n% input, output document\n%\\quad Input numbers \\param{a}, \\param{m} must be integer.\\\\\n%\n\\subsection{modsqrt -- square root of $a$ for modulo $p$}\\linkedone{arith1}{modsqrt}\n\\func{modsqrt}{\\hiki{a}{integer}, \\, \\hiki{p}{integer}}{\\out{integer}}\\\\\n\\spacing\n% document of basi document\n\\quad Return one of the square roots of \\param{a} for modulo \\param{p} if square roots exist, raise ValueError otherwise.\\\\\n\\spacing\n% add document\n%\\spacing\n% input, output ducument\n\\quad \\param{p} must be a prime number.\\\\\n%\n\\subsection{expand -- $m$-adic expansion}\\linkedone{arith1}{expand}\n\\func{expand}{\\hiki{n}{integer}, \\, \\hiki{m}{integer}}{\\out{list}}\\\\\n\\spacing\n% document of basi document\n\\quad Return the \\param{m}-adic expansion of \\param{n}.\\\\ \n\\spacing\n% input, output document\n\\quad \\param{n} must be nonnegative integer. \\param{m} must be greater than or equal to $2$.  The output is a list of expansion coefficients in ascending order.\\\\\n%\n\\subsection{inverse -- inverse}\\linkedone{arith1}{inverse}\n\\func{inverse}{\\hiki{x}{integer}, \\, \\hiki{n}{integer}}{\\out{integer}}\\\\\n\\spacing\n% document of basi document\n\\quad Return the inverse of \\param{x} for modulo \\param{n}.\\\\\n\\spacing\n% input, output document\n\\quad \\param{n} must be coprime to \\param{x}.\\\\\n%\n\\subsection{CRT -- Chinese Reminder Theorem}\\linkedone{arith1}{CRT}\n\\func{CRT}{\\hiki{nlist}{list}}{\\out{integer}}\\\\\n\\spacing\n% document of basi document\n\\quad Return the uniquely determined integer satisfying all modulus\nconditions given by \\param{nlist}.\\\\\n\\spacing\n% input, output document\n\\quad Input list \\param{nlist} must be the list of lists each consisting of two elements.\nThe first element is remainder and the second is divisor.\nThey must be integer.\\\\\n%\n\\subsection{AGM -- Arithmetic Geometric Mean}\\linkedone{arith1}{AGM}\n\\func{AGM}{\\hiki{a}{integer},\\ \\hiki{b}{integer}}{\\out{float}}\\\\\n\\spacing\n% document of basi document\n\\quad Return the Arithmetic-Geometric Mean of \\param{a} and \\param{b}.\\\\\n%\\spacing\n% input, output document\n%\\quad Input number \\param{a}, \\param{b} must be integer.\\\\ \n%\n%\\subsection{\\_BhaskaraBrouncker}\\linkedone{arith1}{\\_BhaskaraBrouncker}\n%\\func{\\_BhaskaraBrouncker}{\\hiki{n}{integer}}{\\out{integer}}\\\\\n%\\spacing\n% document of basi document\n%\\quad Return the minimum tuple \\param{p}, \\param{q} such that, $\\param{p}^2\n%- \\param{n} \\param{q}^2 = \\pm 1$.\\\\\n%\\spacing\n% input, output document\n%\\quad Input number \\param{n} must be positive integer.\n%\n\\subsection{vp -- $p$-adic valuation}\\linkedone{arith1}{vp}\n\\func{vp}{\\hiki{n}{integer},\\ \\hiki{p}{integer}, \\hikiopt{k}{integer}{0}}{\\out{tuple}}\\\\\n\\spacing\n% document of basi document\n\\quad Return the \\param{p}-adic valuation and other part for \\param{n}.\\\\\n\\spacing\n% added document\n\\quad \\negok If $k$ is given, return the valuation and the other part for $\\param{n}p^\\param{k}$.\\\\\n% input, output document\n%\\quad Input number \\param{n}, \\param{p} must be int, long or \\linkingone{rational}{Integer}.\n%\n\\subsection{issquare - Is it square?}\\linkedone{arith1}{issquare}\n\\func{issquare}{\\hiki{n}{integer}}{\\out{integer}}\\\\\n\\spacing\n% document of basi document\n\\quad Check if \\param{n} is a square number and return square root\nof \\param{n} if \\param{n} is a square.\nOtherwise, return \\(0\\).\\\\\n%\\spacing\n% input, output document\n%\\quad Input number \\param{n} must be int, long or \\linkingone{rational}{Integer}.\n%\n\\subsection{log -- integer part of logarithm}\\linkedone{arith1}{log}\n\\func{log}{\\hiki{n}{integer},\\ \\hikiopt{base}{integer}{2}}{\\out{integer}}\\\\\n\\spacing\n% document of basi document\n\\quad Return the integer part of logarithm of \\param{n} to the \\param{base}.\\\\\n%\\spacing\n% input, output document\n%\\quad Input number \\param{n}, \\param{base} must be int, long or \\linkingone{rational}{Integer}.\n%\n\\subsection{product -- product of some numbers}\\linkedone{arith1}{product}\n\\func{product}{\\hiki{iterable}{list},\\ \\hikiopt{init}{object}{None}}{\\out{\\hiki{prod}{object}}}\\\\\n\\spacing\n% document of basic document\n\\quad Return the products of all elements in \\param{iterable}. \\\\\n\\spacing\n% added document\n\\quad If \\param{init} is given, the multiplication starts with \\param{init} instead of the first element in \\param{iterable}.\\\\\n\\spacing\n% input, output document\n\\quad Input list \\param{iterable} must be list of mathematical objects which support multiplication.\\\\\nThe type of output \\param{prod} is determined by the types of elements of \\param{iterable} and \\param{init}.\\\\\nIf the \\param{iterable} is empty, then \\param{init} (if given) or \\(1\\) (otherwise) will be returned.\\\\\n%\n\\begin{ex}\n>>> arith1.AGM(10, 15)\n12.373402181181522\n>>> arith1.CRT([[2, 5], [3, 7]])\n17\n>>> arith1.CRT([[2, 5], [3, 7], [5, 11]])\n192\n>>> arith1.expand(194, 5)\n[4, 3, 2, 1]\n>>> arith1.vp(54, 3)\n(3, 2)\n>>> arith1.product([1.5, 2, 2.5])\n7.5\n>>> arith1.product([3, 4], 2)\n24\n>>> arith1.product([])\n1\n\\end{ex}\n\n%---------- end document ---------- %\n\n\\input{../footer}\n", "meta": {"hexsha": "f7aded0ffa3794c94400b793075d2bb205fd3a81", "size": 6086, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/en/arith1.tex", "max_stars_repo_name": "turkeydonkey/nzmath3", "max_stars_repo_head_hexsha": "a48ae9efcf0d9ad1485c2e9863c948a7f1b20311", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-26T19:22:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T19:22:17.000Z", "max_issues_repo_path": "manual/en/arith1.tex", "max_issues_repo_name": "turkeydonkey/nzmath3", "max_issues_repo_head_hexsha": "a48ae9efcf0d9ad1485c2e9863c948a7f1b20311", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "manual/en/arith1.tex", "max_forks_repo_name": "turkeydonkey/nzmath3", "max_forks_repo_head_hexsha": "a48ae9efcf0d9ad1485c2e9863c948a7f1b20311", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.0375, "max_line_length": 162, "alphanum_fraction": 0.7065395991, "num_tokens": 1920, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7107688628169803}}
{"text": "\\subsection{Matrices over fields}\\label{subsec:matrices_over_fields}\n\nWe will assume that all matrices have entries from some fixed \\hyperref[def:field]{field} \\( \\BbbK \\). We will later on need to distinguish between real and complex matrices, but the theory built here holds more generally than that, and we choose to postulate it for arbitrary fields.\n\nThe definitions of \\hyperref[def:triangular_matrix]{triangular} and \\hyperref[def:triangular_matrix]{elementary matrices} make sense over more general rings, however we introduce them because of \\fullref{alg:plu_decomposition}, which has no direct generalization.\n\n\\begin{definition}\\label{def:triangular_matrix}\n  An \\term{upper triangular matrix} is one with zeros below its \\hyperref[def:matrix_diagonal]{main diagonal}. More precisely, \\( U = \\seq{ u_{i,j} }_{i,j=1}^{m,n} \\) is an upper triangular matrix if \\( u_{i,j} = 0 \\) when \\( i > j \\).\n\n  Similarly, a \\term{lower triangular matrix} is one with zeros above its main diagonal.\n\n  A matrix that is either upper or lower triangular is simply referred to as \\enquote{triangular}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:triangular_matrix}\n  \\hyperref[def:triangular_matrix]{Triangular matrices} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:triangular_matrix/diagonal} A matrix that is both upper and lower triangular is a \\hyperref[def:matrix_diagonal]{diagonal matrix}.\n\n    \\thmitem{thm:def:triangular_matrix/product} The \\hyperref[def:matrix_algebra/matrix_multiplication]{product} of upper (resp. lower) triangular matrices is upper (resp. lower).\n\n    Consequently, the product of diagonal matrices is a diagonal matrix.\n\n    \\thmitem{thm:def:triangular_matrix/determinant} The \\hyperref[thm:def:triangular_matrix/determinant]{determinant} of a triangular matrix is the product of (the entries on) its main diagonal.\n\n    \\thmitem{thm:def:triangular_matrix/invertible} A triangular matrix is \\hyperref[def:inverse_matrix]{invertible} if and only if its main diagonal has no zero entries.\n\n    Here, the assumption that \\( \\BbbK \\) is a field is essential.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:triangular_matrix/diagonal} Trivial.\n\n  \\SubProofOf{thm:def:triangular_matrix/product} Let \\( A \\) be an \\( m \\times k \\) upper triangular matrix and \\( B \\) be a \\( k \\times n \\) upper triangular matrix. The \\( (i, j) \\)-th element of \\( C = AB \\) is\n  \\begin{equation*}\n    \\sum_{l=1}^k a_{i,l} b_{l,j}.\n  \\end{equation*}\n\n  Since \\( A \\) and \\( B \\) are upper triangular, we have \\( b_{l,j} = 0 \\) whenever \\( l > j \\) and \\( a_{i,l} = 0 \\) whenever \\( l < i \\). Thus, \\( a_{i,l} b_{l,j} = 0 \\) if either condition holds. If \\( i > j \\), then either \\( l > j \\) or \\( l < j < i \\), implying that \\( a_{i,l} b_{l,j} = 0 \\). Therefore, \\( AB \\) is also upper triangular.\n\n  The proof for lower triangular matrices is analogous.\n\n  \\SubProofOf{thm:def:triangular_matrix/determinant} Let \\( A \\) be an \\( n \\times n \\) upper triangular matrix. Let \\( \\sigma \\in S_n \\) be any permutation. Then \\( a_{i,\\sigma(i)} = 0 \\) when \\( i > \\sigma(i) \\). Hence, the only permutation for which the product \\( \\prod_{i=1}^n a_{i,\\sigma(i)} \\) is nonzero is the identity permutation. Therefore,\n  \\begin{equation*}\n    \\det(A) = \\prod_{i=1}^n a_{i,i}.\n  \\end{equation*}\n\n  \\SubProofOf{thm:def:triangular_matrix/invertible} Follows from \\fullref{thm:def:triangular_matrix/determinant} and \\fullref{thm:matrix_invertibility} by noting that \\( 0 \\) is the only non-invertible element in a field.\n\\end{proof}\n\n\\begin{definition}\\label{def:elementary_matrix}\n  We introduce the following three types of \\hyperref[def:inverse_matrix]{invertible} \\( n \\times n \\) matrices, collectively known as \\term{elementary matrices}:\n  \\begin{thmenum}\n    \\thmitem{def:elementary_matrix/permutation} For a \\hyperref[def:symmetric_group/permutation]{permutation} \\( \\sigma \\in S_n \\), the \\term{permutation matrix} \\( P_\\sigma \\) is obtained by permuting the columns \\( e_1, \\ldots, e_n \\) of the identity matrix \\( I_n \\) in accordance with \\( \\sigma \\). The permutation matrix\n    \\begin{equation*}\n      P_\\sigma = \\parens*\n      {\n        \\begin{array}{c|c|c}\n          e_{\\sigma(1)} & \\cdots & e_{\\sigma(n)}\n        \\end{array}\n      }\n    \\end{equation*}\n    acts on the \\( n \\times m \\) matrix \\( B = \\seq{ b_{i,j} }_{i,j=1}^{m,n} \\) by permuting the \\hi{rows} of \\( B \\), i.e.\n    \\begin{equation*}\n      P_\\sigma B\n      =\n      \\parens*\n      {\n        \\begin{array}{c|c|c}\n          e_{\\sigma(1)} & \\cdots & e_{\\sigma(n)}\n        \\end{array}\n      }\n      \\cdot\n      \\begin{pmatrix}\n        b_{1,1} & b_{1,2} & \\cdots & b_{1,m} \\\\\n        \\vdots  & \\vdots  & \\ddots & \\vdots \\\\\n        b_{n,1} & b_{n,2} & \\cdots & b_{n,m}\n      \\end{pmatrix}\n      =\n      \\begin{pmatrix}\n        b_{\\sigma(1),1} & b_{\\sigma(1),2} & \\cdots & b_{\\sigma(1),m} \\\\\n        \\vdots          & \\vdots          & \\ddots & \\vdots \\\\\n        b_{\\sigma(n),1} & b_{\\sigma(n),2} & \\cdots & b_{\\sigma(n),m}\n      \\end{pmatrix}.\n    \\end{equation*}\n\n    The inverse is the matrix corresponding to its inverse permutation.\n\n    \\thmitem{def:elementary_matrix/scaling} For a nonzero element \\( a \\) and index \\( i \\), the \\( n \\times n \\) \\term{scaling matrix} \\( S_{i \\mapsto a} \\) is a \\hyperref[def:matrix_diagonal]{diagonal matrix} that differs from the identity by replacing \\( 1 \\) with \\( a \\) instead of \\( 1 \\) in the \\( (i, i) \\)-th place. The scaling matrix\n    \\begin{equation*}\n      S_{i \\mapsto a}\n      \\coloneqq\n      \\begin{blockarray}{cccccccc}\n      1      & \\cdots & {i-1}   & i      & {i+1}  & \\cdots & n      &        \\\\\n      \\begin{block}{(ccccccc)c}\n      1      & \\cdots & 0       & 0      & 0      & \\cdots & 0      & 1      \\\\\n      \\vdots & \\ddots &         & \\vdots &        &        & \\vdots & \\vdots \\\\\n      0      &        & 1       & 0      &        &        & 0      & {i-1}  \\\\\n      0      & \\cdots & 0       & a      & 0      & \\cdots & 0      & i      \\\\\n      0      &        &         & 0      & 1      &        & 0      & {i+1}  \\\\\n      \\vdots &        &         & \\vdots &        & \\ddots & \\vdots & \\vdots \\\\\n      0      & \\cdots & 0       & 0      & 0      & \\cdots & 1      & n      \\\\\n      \\end{block}\n      \\end{blockarray}\n    \\end{equation*}\n    acts on the \\( n \\times m \\) matrix \\( B \\) by scaling the \\( i \\)-th row of \\( B \\) by \\( a \\).\n\n    The inverse is the same matrix with \\( a \\) replaced by its multiplicative inverse \\( a^{-1} \\).\n\n    \\thmitem{def:elementary_matrix/transvection} For any element \\( a \\) and indices \\( i \\) and \\( j \\), the \\term{transvection matrix} \\( T_{i \\reloset a \\to j} \\) is obtained from the identity matrix \\( I_n \\) by placing \\( a \\) on the \\( (j, i) \\)-th place. The transvection matrix\n    \\begin{equation*}\n      T_{i \\reloset a \\to j}\n      \\coloneqq\n      \\begin{blockarray}{cccccccc}\n        1      & \\cdots & i       &        &        &        & n      &        \\\\\n      \\begin{block}{(ccccccc)c}\n        1      & \\cdots & 0       & \\cdots & 0      & \\cdots & 0      & 1      \\\\\n        \\vdots & \\ddots &         &        &        &        & \\vdots &        \\\\\n        0      &        & 1       & 0      &        & \\cdots & 0      &        \\\\\n        \\vdots &        &         & \\ddots & 0      &        & \\vdots &        \\\\\n        0      & \\cdots & a       &        & 1      & \\cdots & 0      & j      \\\\\n        \\vdots &        & \\vdots  &        &        & \\ddots & \\vdots & \\vdots \\\\\n        0      & \\cdots & 0       & \\cdots & 0      & \\cdots & 1      & n      \\\\\n      \\end{block}\n      \\end{blockarray}\n    \\end{equation*}\n    acts on the \\( n \\times m \\) matrix \\( B \\) by adding the \\( i \\)-th row of \\( B \\) scaled by \\( a \\) to the \\( j \\)-th row.\n\n    The order of indices is important --- if the \\( (j, i) \\)-th entry is nonzero, the scaled \\( i \\)-th row gets added to the \\( j \\)-th.\n\n    The inverse is the same matrix with \\( a \\) replaced by its additive inverse \\( -a \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:elementary_matrix}\n  \\hyperref[def:elementary_matrix]{Elementary matrices} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:elementary_matrix/permutation_product} The product of \\hyperref[def:elementary_matrix/permutation]{permutation matrices} is a permutation matrix.\n\n    \\thmitem{thm:def:elementary_matrix/permutation_determinant} The \\hyperref[def:matrix_determinant]{determinant} of a permutation matrix is the \\hyperref[def:permutation_parity]{sign} of the \\hyperref[def:symmetric_group/permutation]{permutation}.\n\n    \\thmitem{thm:def:elementary_matrix/transvection_product_same} The product of the \\hyperref[def:elementary_matrix/transvection]{transvection matrices} \\( T_{i \\reloset \\alpha \\to j} \\) and \\( T_{i \\reloset \\beta \\to j} \\) is the transvection matrix \\( T_{i \\reloset {\\alpha + \\beta} \\to j} \\).\n\n    \\thmitem{thm:def:elementary_matrix/transvection_product} The product of the \\hyperref[def:elementary_matrix/transvection]{transvection matrices} \\( A = T_{i_A \\reloset \\alpha \\to j_A} \\) and \\( B = T_{i_B \\reloset \\beta \\to j_B} \\) with \\( i_A \\neq i_B \\) or \\( j_A \\neq j_B \\) is the identity matrix \\( I_n \\) modified with \\( \\alpha \\) in the \\( (j_A, i_A) \\)-th place and \\( \\beta \\) in the \\( (j_B, i_B) \\)-th.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:elementary_matrix/permutation_product} Trivial.\n\n  \\SubProofOf{thm:def:elementary_matrix/permutation_determinant} As discussed in the proof of \\fullref{thm:determinant_on_columns}, the determinant of any permutation of the vectors of the standard basis is the sign of the permutation.\n\n  \\SubProofOf{thm:def:elementary_matrix/transvection_product} The \\( (i, j) \\)-th entry of the product \\( C = AB \\) is\n  \\begin{equation*}\n    c_{i,j} = \\sum_{k=1}^n a_{i,k} b_{k,j}.\n  \\end{equation*}\n\n  \\begin{itemize}\n    \\item If \\( i = j \\), \\( c_{i,j} \\) is clearly \\( 1 \\).\n    \\item If \\( i = i_A \\) and \\( j = j_A \\), then\n    \\begin{equation*}\n      a_{i_A,k} b_{k,j_A} = \\begin{cases}\n        a_{i_A,j_A}, &i_A = j_A \\\\\n        0,           &i_A \\neq j_A\n      \\end{cases}.\n    \\end{equation*}\n\n    Thus, \\( c_{i_A,j_A} = a_{i_A,j_A} \\).\n\n    \\item Analogously, \\( c_{i_B,j_B} = b_{i_B,j_B} \\).\n    \\item Otherwise, for \\( k = 1, \\ldots, n \\), either \\( a_{i,k} \\) or \\( b_{k,j} \\) is zero, hence \\( c_{i,j} \\) also is.\n  \\end{itemize}\n\n  \\SubProofOf{thm:def:elementary_matrix/transvection_product_same} This proof only requires a slight modification to the proof of \\fullref{thm:def:elementary_matrix/transvection_product}.\n\\end{proof}\n\n\\begin{algorithm}[PLU decomposition]\\label{alg:plu_decomposition}\n  Fix an \\( n \\times n \\) matrix \\( A \\). We will build a \\hyperref[def:triangular_matrix]{lower triangular matrix} \\( L \\), \\hyperref[def:triangular_matrix]{upper triangular matrix} \\( U \\) and a \\hyperref[def:elementary_matrix/permutation]{permutation matrix} \\( P \\) such that \\( A = PLU \\).\n\n  The algorithm itself is also called \\term{Gaussian elimination} and \\( U \\) is said to be a \\term{row-echelon form} of \\( A \\), although both terms may have different meanings depending on the context.\n\n  We will proceed via \\hyperref[thm:bounded_transfinite_recursion]{bounded recursion} on \\( n \\). After the \\( k \\)-th step, for \\( k = 1, \\ldots, n - 1 \\), we will have built a lower triangular matrix \\( L_k \\) and a permutation matrix \\( P_k \\) such that for \\( i > k \\), \\( (i, k) \\)-th entry of \\( L_k P_k A \\) is zero.\n\n  Furthermore, we will obtain \\( L_k \\) as a product of \\hyperref[def:elementary_matrix/transvection]{transvection} and permutation matrices. Therefore, at each step, both \\( P_k \\) and \\( L_k \\) will be \\hyperref[def:inverse_matrix]{invertible} as products of invertible matrices.\n\n  The matrix \\( U \\coloneqq L_{n-1} P_{n-1} A \\) will be upper triangular, and hence, putting \\( P \\coloneqq P_{n-1}^{-1} \\) and \\( L \\coloneqq L_{n-1}^{-1} \\), we obtain\n  \\begin{equation*}\n    A = PLU.\n  \\end{equation*}\n\n  \\begin{thmenum}\n    \\thmitem{alg:plu_decomposition/initialization} As an initial condition, put \\( L_0 \\coloneqq I_n \\) and \\( P_0 \\coloneqq I_n \\) as identity matrices.\n\n    \\thmitem{alg:plu_decomposition/step} Suppose that we have already built \\( L_{k-1} \\) and \\( P_{k-1} \\). Let \\( U_{k-1} \\coloneqq L_{k-1} P_{k-1} A \\). We will describe step \\( k \\) of the algorithm.\n\n    If the \\( (k, j) \\)-th entry of \\( U_{k-1} \\) is zero for all \\( j > k \\), put \\( P_k = P_{k-1} \\) and \\( L_k = L_{k-1} \\).\n\n    Otherwise, let \\( j_0 \\) be the first row index of \\( L_{k-1} P_{k-1} A \\) for which the \\( k \\)-th entry is nonzero. Let \\( P_{k \\to j_0} \\) be the permutation matrix exchanging the \\( k \\)-th and \\( j_0 \\)-th column of the identity and put\n    \\begin{equation*}\n      P_k \\coloneqq P_{k \\to j_0} P_{k-1}.\n    \\end{equation*}\n\n    Then, since \\( P_{k \\to j_0} \\) is its own inverse,\n    \\begin{equation*}\n      \\widehat{U}_{k-1} \\coloneqq P_{k \\to j_0} U_{k-1} = P_{k \\to j_0} L_{k-1} (\\smash{ \\overbrace{P_{k \\to j_0} P_{k \\to j_0}}^{I_n} P_{k-1}) A = (P_{k \\to j_0} L_{k-1} P_{k \\to j_0}) } P_k A.\n    \\end{equation*}\n\n    Denote by \\( u_{i,j} \\) the entries of \\( \\widehat{U}_{k-1} \\).\n\n    Also put \\( \\widehat{L}_{k-1} \\coloneqq P_{k \\to j_0} L_{k-1} P_{k \\to j_0} \\). This is again a lower triangular matrix since we only swap columns below the main diagonal.\n\n    For each row \\( j > k \\), define \\( \\upsilon_j \\coloneqq - \\ifrac {(u_{k,j})} {(u_{k,k})} \\) consider the transvection matrix \\( T_{k \\reloset {\\upsilon_j} \\to j} \\). When multiplied by \\( \\widehat{U}_{k-1} \\) from the right, it adds the \\( k \\)-th row of \\( \\widehat{U}_{k-1} \\) to the \\( j \\)-th after multiplying it by \\( \\upsilon_j \\). Hence, \\( T_{k \\reloset {\\upsilon_j} \\to j} \\widehat{U}_{k-1} \\) has zero at as its \\( (i, j) \\)-th entry.\n\n    Finally, put\n    \\begin{equation*}\n      L_k \\coloneqq \\parens*{ \\prod_{j=k}^n T_{k \\reloset {\\upsilon_j} \\to j} } \\widehat{L}_{k-1}.\n    \\end{equation*}\n\n    By \\fullref{thm:def:elementary_matrix/transvection_product}, \\( L_k \\) adds nonzero entries to \\( \\widehat{L}_{k-1} \\) only below the main diagonal. Since \\( \\widehat{L}_{k-1} \\) is lower triangular, so is \\( L_k \\). Furthermore, for \\( j > k \\), the coefficient \\( \\upsilon_j \\) is chosen so that the \\( (k, j) \\)-th entry of \\( L_k P_k A \\) of zero, which ensures that the latter matrix will be upper triangular when \\( k = n - 1 \\).\n  \\end{thmenum}\n\\end{algorithm}\n\n\\begin{proposition}\\label{thm:alg:plu_decomposition}\n  Let \\( A = PLU \\) be the decomposition of some matrix \\( A \\) obtained via \\fullref{alg:plu_decomposition}.\n\n  \\begin{thmenum}\n    \\thmitem{thm:alg:plu_decomposition/upper_triangular} If \\( A \\) is upper triangular, then \\( P = L = I_n \\) and \\( A = U \\).\n\n    \\thmitem{thm:alg:plu_decomposition/nonsingular} \\( A \\) is \\hyperref[def:inverse_matrix]{nonsingular} if and only if \\( U \\) is nonsingular.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:alg:plu_decomposition/upper_triangular} Suppose that \\( A \\) is upper triangular. Then, at step \\( k \\) of the algorithm:\n  \\begin{itemize}\n     \\item If \\( u_{k,k} \\) is zero, then all entries below it are also zero, and hence we directly continue to the next step.\n     \\item If \\( u_{k,k} \\) is not zero, then the transvection matrices \\( T_{k \\reloset 0 \\to j} \\) for \\( j > k \\) are all identity matrices, and hence \\( L_k \\) is also the identity.\n  \\end{itemize}\n\n  In both cases, \\( L_k = P_k = I_n \\).\n\n  \\SubProofOf{thm:alg:plu_decomposition/nonsingular} By \\fullref{thm:def:matrix_determinant/homomorphism},\n  \\begin{equation*}\n    \\det(A) = \\det(P) \\det(L) \\det(U).\n  \\end{equation*}\n\n  Since \\( P \\) and \\( L \\) are products of permutation and transvection matrices, by \\fullref{thm:def:elementary_matrix/permut ation_determinant} and \\fullref{thm:def:elementary_matrix/transvection_product}, their determinants are either \\( 1 \\) or \\( -1 \\). Hence,\n  \\begin{equation*}\n    \\abs{\\det(A)} = \\abs{\\det(U)}.\n  \\end{equation*}\n\n  It follows from \\fullref{thm:def:elementary_matrix/transvection_product} that \\( A \\) is nonsingular if and only if \\( U \\) is.\n\\end{proof}\n\n\\begin{algorithm}[Elementary matrix decomposition]\\label{alg:elementary_matrix_decomposition}\n  Fix a \\hyperref[def:inverse_matrix]{nonsingular} \\( n \\times n \\) matrix \\( A \\). Let \\( A = PLU \\) be the decomposition obtained via \\fullref{alg:plu_decomposition}. By \\fullref{thm:alg:plu_decomposition/nonsingular}, \\( U \\) is a nonsingular matrix. Both \\( P \\) and \\( L \\) are products of elementary matrices, hence it suffices to show that \\( U \\) is a product of elementary matrices in order to show that \\( A \\) is a product of elementary matrices.\n\n  The algorithm is complementary to \\fullref{alg:plu_decomposition}, although with noticeable differences. We will assume that \\( k = 2, \\ldots, n \\). At each step, we will build a matrix \\( U_k \\) whose first \\( k \\) columns match those of \\( U \\). Then \\( U_n \\) must equal \\( U \\).\n\n  Denote by \\( u_{i,j} \\) the entries of \\( U \\).\n\n  \\begin{thmenum}\n    \\thmitem{alg:elementary_matrix_decomposition/initialization} We will define the initial condition \\( U_1 \\) to be he diagonal matrix whose main diagonal matches that of \\( U \\). This can be achieved via \\hyperref[def:elementary_matrix/scaling]{scaling matrices}:\n    \\begin{equation*}\n      U_1 \\coloneqq \\prod_{i=1}^n S_{i \\mapsto u_{i,i}}.\n    \\end{equation*}\n\n    \\thmitem{alg:elementary_matrix_decomposition/step} At step \\( k \\), given \\( U_{k-1} \\), for \\( j < k \\) define \\( \\upsilon_j \\coloneqq \\ifrac {(u_{k,j})} {(u_{k,k})} \\). It is important that here, unlike in \\fullref{alg:plu_decomposition}, we put no minus sign in \\( \\upsilon_j \\) since we are building the matrix \\( U \\) directly rather than building an intermediate matrix that we will later invert. Put\n    \\begin{equation*}\n      U_k \\coloneqq \\parens*{ \\prod_{j=k}^n T_{k \\reloset {\\upsilon_j} \\to j} } U_{k-1}.\n    \\end{equation*}\n\n    Since \\( U \\) is nonsingular, by \\fullref{thm:def:triangular_matrix/determinant}, \\( u_{k,k} \\) must be nonzero. Hence, we can divide by it.\n\n    As a product of scaling and \\hyperref[def:elementary_matrix/transvection]{transvection matrices} with nonzero entries above the main diagonal, \\( U_k \\) is an upper diagonal matrix. Furthermore, the scaling matrices neutralize the division done by the transvection matrices, so the \\( k \\)-th column of \\( U_k \\) and \\( U \\) must match.\n  \\end{thmenum}\n\\end{algorithm}\n\n\\begin{proposition}\\label{thm:product_of_elementary_matrices_iff_invertible}\n  The square matrix over a field is \\hyperref[def:inverse_matrix]{invertible} if and only if it is a product of \\hyperref[def:elementary_matrix]{elementary matrices}.\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Follows from \\fullref{alg:elementary_matrix_decomposition}.\n  \\NecessitySubProof Follows from \\fullref{thm:def:matrix_determinant/homomorphism}.\n\\end{proof}\n\n\\begin{example}\\label{ex:vandermonde_matrix}\\mcite[corr. 2.37]{Knapp2016BasicAlgebra}\n  Given elements \\( r_0, r_1, \\ldots, r_n \\) of some commutative ring, we define their \\term{Vandermonde matrix} as\n  \\begin{equation*}\n    \\RenewDocumentCommand \\arraystretch {} {1.3}\n    V_n(r_0, r_1, \\ldots, r_n)\n    \\coloneqq\n    \\begin{pmatrix}\n      r_0^0  & r_0^1  & r_0^2  & \\cdots & r_0^n  \\\\\n      r_1^0  & r_1^1  & r_1^2  & \\cdots & r_1^n  \\\\\n      \\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n      r_n^0  & r_n^1  & r_n^2  & \\cdots & r_n^n\n    \\end{pmatrix}.\n  \\end{equation*}\n\n  Having in mind that, by \\fullref{thm:def:triangular_matrix/determinant}, transvection matrices have determinant \\( 1 \\), subtracting the \\( k \\)-th row multiplied by \\( r_0 \\) from the \\( (k + 1) \\)-th does not change the determinant. We thus have\n  \\begin{balign*}\n    \\det V_n\n    =\n    \\det V_n^T\n    &=\n    \\det\n    \\begin{pmatrix}\n      1         & 1                     & 1                     & \\cdots & 1                     \\\\\n      0         & r_1 - r_0             & r_2 - r_0             & \\cdots & r_n - r_0             \\\\\n      0         & r_1 (r_1 - r_0)       & r_2 (r_2 - r_0)       & \\cdots & r_n (r_n - r_0)       \\\\\n      \\vdots    & \\vdots                & \\vdots                & \\ddots & \\vdots                \\\\\n      0         & r_1^{k-1} (r_1 - r_0) & r_2^{k-1} (r_2 - r_0) & \\cdots & r_n^{k-1} (r_n - r_0) \\\\\n      \\vdots    & \\vdots                & \\vdots                & \\ddots & \\vdots                \\\\\n      0         & r_1^{n-1} (r_1 - r_0) & r_2^{n-1} (r_2 - r_0) & \\cdots & r_n^{n-1} (r_n - r_0) \\\\\n    \\end{pmatrix}\n    \\reloset {\\ref{thm:laplace_expansion}} = \\\\ &=\n    \\det\n    \\begin{pmatrix}\n      r_1 - r_0             & r_2 - r_0             & \\cdots & r_n - r_0             \\\\\n      r_1 (r_1 - r_0)       & r_2 (r_2 - r_0)       & \\cdots & r_n (r_n - r_0)       \\\\\n      \\vdots                & \\vdots                & \\ddots & \\vdots                \\\\\n      r_1^{k-1} (r_1 - r_0) & r_2^{k-1} (r_2 - r_0) & \\cdots & r_n^{k-1} (r_n - r_0) \\\\\n      \\vdots                & \\vdots                & \\ddots & \\vdots                \\\\\n      r_1^{n-1} (r_1 - r_0) & r_2^{n-1} (r_2 - r_0) & \\cdots & r_n^{n-1} (r_n - r_0) \\\\\n    \\end{pmatrix}\n    = \\\\ &=\n    (r_1 - r_0) (r_2 - r_0) \\cdots (r_n - r_0)\n    \\det\n    \\begin{pmatrix}\n      1         & 1         & \\cdots & 1         \\\\\n      r_1       & r_2       & \\cdots & r_n       \\\\\n      \\vdots    & \\vdots    & \\ddots & \\vdots    \\\\\n      r_1^{k-1} & r_2^{k-1} & \\cdots & r_n^{k-1} \\\\\n      \\vdots    & \\vdots    & \\ddots & \\vdots    \\\\\n      r_1^{n-1} & r_2^{n-1} & \\cdots & r_n^{n-1}\n    \\end{pmatrix}.\n  \\end{balign*}\n\n  Proceeding by induction, we conclude that\n  \\begin{equation}\\label{eq:ex:vandermonde_matrix/determinant}\n    \\det V_n = \\prod_{i < j} (r_j - r_i).\n  \\end{equation}\n\n  Hence, the determinant is nonzero if and only if all of \\( r_0, \\ldots, r_n \\) are distinct.\n\\end{example}\n\n\\begin{definition}\\label{def:column_and_row_spaces}\n  The \\term{column space} of the \\( m \\times n \\) matrix \\( A \\) is the \\hyperref[def:module/submodel]{linear span} of the columns vectors of \\( A \\), regarded as a subspace of \\( R^n \\). It is precisely the image of \\( A \\) regarded as a linear operator.\n\n  Analogously, the \\term{row space} is the span of the row vectors, regarded as a subspace of \\( R^m \\). It is the image of \\( A^T \\) regarded as a linear operator.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:column_and_row_spaces}\n  \\hyperref[def:column_and_row_spaces]{Column and row spaces} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:column_and_row_spaces/isomorphism} The matrix \\( A \\) as a linear map from the row space to the column space an isomorphism.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:column_and_row_spaces/isomorphism} We will show that the image of \\( A \\) and \\( A^T \\) are isomorphic.\n\n  Let \\( x \\in \\BbbK^m \\) and \\( y \\in \\BbbK^n \\). Then\n  \\begin{equation*}\n    x^T A y = y^T A^T x.\n  \\end{equation*}\n\n  If \\( y \\) is in the kernel of \\( A \\), then\n  \\begin{equation*}\n    x^T A y = 0 = y^T A^T x\n  \\end{equation*}\n\n  By \\fullref{thm:rank_nullity_theorem},\n  \\begin{equation*}\n    n = \\dim \\ker A + \\dim \\img A.\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    m = \\dim \\ker A^T + \\dim \\img A^T.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:matrix_rank}\n  We define the \\term{rank} of an \\( m \\times n \\) matrix \\( A \\) in the following equivalent ways:\n  \\begin{thmenum}\n    \\thmitem{def:matrix_rank/independent_columns} \\( \\rank(A) \\) is the number of \\hyperref[def:linear_dependence]{linearly independent} columns of \\( A \\).\n    \\thmitem{def:matrix_rank/image_dimension} \\( \\rank(A) \\) is the \\hyperref[thm:vector_space_dimension]{dimension} of the image of \\( A \\) (when regarded as a linear operator; see \\fullref{rem:matrices_as_functions}).\n    \\thmitem{def:matrix_rank/image_dimension} \\( \\rank(A) \\) is the \\hyperref[thm:vector_space_dimension]{dimension} of the image of the transpose matrix \\( A^T \\).\n    \\thmitem{def:matrix_rank/independent_rows} \\( \\rank(A) \\) is the number of linearly independent rows of \\( A \\).\n  \\end{thmenum}\n\\end{definition}\n\\begin{defproof}\n  \\SubProofOf{def:matrix_rank/independent_columns} Suppose that the columns \\( v_1, \\ldots, v_k \\) of \\( A \\) are linearly independent.\n\n  By \\fullref{thm:rank_nullity_theorem},\n  \\begin{equation*}\n    n = \\dim \\ker A + \\dim \\img A.\n  \\end{equation*}\n\n   \\( n - k \\).\n\n  \\SubProofOf{def:matrix_rank/image_dimension}\n\n  Also,\n  \\begin{equation*}\n    m = \\dim \\ker A^T + \\dim \\img A^T.\n  \\end{equation*}\n\n  This is the same as\n  \\begin{equation*}\n    (Ax)^T = x^T A^T = 0.\n  \\end{equation*}\n\\end{defproof}\n\n\\begin{remark}\\label{rem:system_of_linear_equation}\n  Given an \\( m \\times n \\) matrix \\( A \\) and an \\( m \\)-dimensional column vector \\( b \\), we consider the \\term{system of linear equations}\n  \\begin{equation}\\label{eq:rem:system_of_linear_equation/matrix_form}\n    Ax = b.\n  \\end{equation}\n\n  This is often written in scalar form as\n  \\begin{equation}\\label{eq:rem:system_of_linear_equation/scalar_form}\n    \\begin{array}{ccccccc}\n      a_{1,1} x_1 & +      & \\cdots & +      & a_{m,1} x_m & =      & b_1 \\\\\n      \\vdots      &        &        & \\vdots &             &        & \\vdots \\\\\n      a_{1,n} x_1 & +      & \\cdots & +      & a_{m,n} x_m & =      & b_m.\n    \\end{array}\n  \\end{equation}\n\\end{remark}\n", "meta": {"hexsha": "c77ff1bb2e0bcf6f5e0bee158b09da83c12e9ca8", "size": 25522, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/matrices_over_fields.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/matrices_over_fields.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/matrices_over_fields.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.6308411215, "max_line_length": 457, "alphanum_fraction": 0.6174672831, "num_tokens": 8561, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956580903722561, "lm_q2_score": 0.8933094096048377, "lm_q1q2_score": 0.7107688589577528}}
{"text": "\n    \\documentclass{article}\n    \\usepackage[utf8]{inputenc}\n    \\usepackage{amsmath}\n    \\begin{document}\n %Title \n \\section{Collatz Sequence for \\(n=112233\\) }\n    %Collatz Function\n    \\[\n        f(n)=\n        \\begin{cases}\n        \\frac{n}{2}, & n \\mod 2=0\n        \\\\\n        3n+1, &n \\mod 2=1\n        \\end{cases} \\\\\n    \\]\n    % Path for given N\n    \\(\\textbf{Path for f(112233)}\\\\[3mm]f(n), n=112233\n \\\\ \n \\Rightarrow 3(112233) + 1\n \\\\ \n \\Rightarrow n=336700\n \\\\[3mm] \nf(n), n=336700\n \\\\ \n \\Rightarrow \\frac{336700}{2} \n \\\\ \n \\Rightarrow n=168350\n \\\\[3mm] \nf(n), n=168350\n \\\\ \n \\Rightarrow \\frac{168350}{2} \n \\\\ \n \\Rightarrow n=84175\n \\\\[3mm] \nf(n), n=84175\n \\\\ \n \\Rightarrow 3(84175) + 1\n \\\\ \n \\Rightarrow n=252526\n \\\\[3mm] \nf(n), n=252526\n \\\\ \n \\Rightarrow \\frac{252526}{2} \n \\\\ \n \\Rightarrow n=126263\n \\\\[3mm] \nf(n), n=126263\n \\\\ \n \\Rightarrow 3(126263) + 1\n \\\\ \n \\Rightarrow n=378790\n \\\\[3mm] \nf(n), n=378790\n \\\\ \n \\Rightarrow \\frac{378790}{2} \n \\\\ \n \\Rightarrow n=189395\n \\\\[3mm] \nf(n), n=189395\n \\\\ \n \\Rightarrow 3(189395) + 1\n \\\\ \n \\Rightarrow n=568186\n \\\\[3mm] \nf(n), n=568186\n \\\\ \n \\Rightarrow \\frac{568186}{2} \n \\\\ \n \\Rightarrow n=284093\n \\\\[3mm] \nf(n), n=284093\n \\\\ \n \\Rightarrow 3(284093) + 1\n \\\\ \n \\Rightarrow n=852280\n \\\\[3mm] \nf(n), n=852280\n \\\\ \n \\Rightarrow \\frac{852280}{2} \n \\\\ \n \\Rightarrow n=426140\n \\\\[3mm] \nf(n), n=426140\n \\\\ \n \\Rightarrow \\frac{426140}{2} \n \\\\ \n \\Rightarrow n=213070\n \\\\[3mm] \nf(n), n=213070\n \\\\ \n \\Rightarrow \\frac{213070}{2} \n \\\\ \n \\Rightarrow n=106535\n \\\\[3mm] \nf(n), n=106535\n \\\\ \n \\Rightarrow 3(106535) + 1\n \\\\ \n \\Rightarrow n=319606\n \\\\[3mm] \nf(n), n=319606\n \\\\ \n \\Rightarrow \\frac{319606}{2} \n \\\\ \n \\Rightarrow n=159803\n \\\\[3mm] \nf(n), n=159803\n \\\\ \n \\Rightarrow 3(159803) + 1\n \\\\ \n \\Rightarrow n=479410\n \\\\[3mm] \nf(n), n=479410\n \\\\ \n \\Rightarrow \\frac{479410}{2} \n \\\\ \n \\Rightarrow n=239705\n \\\\[3mm] \nf(n), n=239705\n \\\\ \n \\Rightarrow 3(239705) + 1\n \\\\ \n \\Rightarrow n=719116\n \\\\[3mm] \nf(n), n=719116\n \\\\ \n \\Rightarrow \\frac{719116}{2} \n \\\\ \n \\Rightarrow n=359558\n \\\\[3mm] \nf(n), n=359558\n \\\\ \n \\Rightarrow \\frac{359558}{2} \n \\\\ \n \\Rightarrow n=179779\n \\\\[3mm] \nf(n), n=179779\n \\\\ \n \\Rightarrow 3(179779) + 1\n \\\\ \n \\Rightarrow n=539338\n \\\\[3mm] \nf(n), n=539338\n \\\\ \n \\Rightarrow \\frac{539338}{2} \n \\\\ \n \\Rightarrow n=269669\n \\\\[3mm] \nf(n), n=269669\n \\\\ \n \\Rightarrow 3(269669) + 1\n \\\\ \n \\Rightarrow n=809008\n \\\\[3mm] \nf(n), n=809008\n \\\\ \n \\Rightarrow \\frac{809008}{2} \n \\\\ \n \\Rightarrow n=404504\n \\\\[3mm] \nf(n), n=404504\n \\\\ \n \\Rightarrow \\frac{404504}{2} \n \\\\ \n \\Rightarrow n=202252\n \\\\[3mm] \nf(n), n=202252\n \\\\ \n \\Rightarrow \\frac{202252}{2} \n \\\\ \n \\Rightarrow n=101126\n \\\\[3mm] \nf(n), n=101126\n \\\\ \n \\Rightarrow \\frac{101126}{2} \n \\\\ \n \\Rightarrow n=50563\n \\\\[3mm] \nf(n), n=50563\n \\\\ \n \\Rightarrow 3(50563) + 1\n \\\\ \n \\Rightarrow n=151690\n \\\\[3mm] \nf(n), n=151690\n \\\\ \n \\Rightarrow \\frac{151690}{2} \n \\\\ \n \\Rightarrow n=75845\n \\\\[3mm] \nf(n), n=75845\n \\\\ \n \\Rightarrow 3(75845) + 1\n \\\\ \n \\Rightarrow n=227536\n \\\\[3mm] \nf(n), n=227536\n \\\\ \n \\Rightarrow \\frac{227536}{2} \n \\\\ \n \\Rightarrow n=113768\n \\\\[3mm] \nf(n), n=113768\n \\\\ \n \\Rightarrow \\frac{113768}{2} \n \\\\ \n \\Rightarrow n=56884\n \\\\[3mm] \nf(n), n=56884\n \\\\ \n \\Rightarrow \\frac{56884}{2} \n \\\\ \n \\Rightarrow n=28442\n \\\\[3mm] \nf(n), n=28442\n \\\\ \n \\Rightarrow \\frac{28442}{2} \n \\\\ \n \\Rightarrow n=14221\n \\\\[3mm] \nf(n), n=14221\n \\\\ \n \\Rightarrow 3(14221) + 1\n \\\\ \n \\Rightarrow n=42664\n \\\\[3mm] \nf(n), n=42664\n \\\\ \n \\Rightarrow \\frac{42664}{2} \n \\\\ \n \\Rightarrow n=21332\n \\\\[3mm] \nf(n), n=21332\n \\\\ \n \\Rightarrow \\frac{21332}{2} \n \\\\ \n \\Rightarrow n=10666\n \\\\[3mm] \nf(n), n=10666\n \\\\ \n \\Rightarrow \\frac{10666}{2} \n \\\\ \n \\Rightarrow n=5333\n \\\\[3mm] \nf(n), n=5333\n \\\\ \n \\Rightarrow 3(5333) + 1\n \\\\ \n \\Rightarrow n=16000\n \\\\[3mm] \nf(n), n=16000\n \\\\ \n \\Rightarrow \\frac{16000}{2} \n \\\\ \n \\Rightarrow n=8000\n \\\\[3mm] \nf(n), n=8000\n \\\\ \n \\Rightarrow \\frac{8000}{2} \n \\\\ \n \\Rightarrow n=4000\n \\\\[3mm] \nf(n), n=4000\n \\\\ \n \\Rightarrow \\frac{4000}{2} \n \\\\ \n \\Rightarrow n=2000\n \\\\[3mm] \nf(n), n=2000\n \\\\ \n \\Rightarrow \\frac{2000}{2} \n \\\\ \n \\Rightarrow n=1000\n \\\\[3mm] \nf(n), n=1000\n \\\\ \n \\Rightarrow \\frac{1000}{2} \n \\\\ \n \\Rightarrow n=500\n \\\\[3mm] \nf(n), n=500\n \\\\ \n \\Rightarrow \\frac{500}{2} \n \\\\ \n \\Rightarrow n=250\n \\\\[3mm] \nf(n), n=250\n \\\\ \n \\Rightarrow \\frac{250}{2} \n \\\\ \n \\Rightarrow n=125\n \\\\[3mm] \nf(n), n=125\n \\\\ \n \\Rightarrow 3(125) + 1\n \\\\ \n \\Rightarrow n=376\n \\\\[3mm] \nf(n), n=376\n \\\\ \n \\Rightarrow \\frac{376}{2} \n \\\\ \n \\Rightarrow n=188\n \\\\[3mm] \nf(n), n=188\n \\\\ \n \\Rightarrow \\frac{188}{2} \n \\\\ \n \\Rightarrow n=94\n \\\\[3mm] \nf(n), n=94\n \\\\ \n \\Rightarrow \\frac{94}{2} \n \\\\ \n \\Rightarrow n=47\n \\\\[3mm] \nf(n), n=47\n \\\\ \n \\Rightarrow 3(47) + 1\n \\\\ \n \\Rightarrow n=142\n \\\\[3mm] \nf(n), n=142\n \\\\ \n \\Rightarrow \\frac{142}{2} \n \\\\ \n \\Rightarrow n=71\n \\\\[3mm] \nf(n), n=71\n \\\\ \n \\Rightarrow 3(71) + 1\n \\\\ \n \\Rightarrow n=214\n \\\\[3mm] \nf(n), n=214\n \\\\ \n \\Rightarrow \\frac{214}{2} \n \\\\ \n \\Rightarrow n=107\n \\\\[3mm] \nf(n), n=107\n \\\\ \n \\Rightarrow 3(107) + 1\n \\\\ \n \\Rightarrow n=322\n \\\\[3mm] \nf(n), n=322\n \\\\ \n \\Rightarrow \\frac{322}{2} \n \\\\ \n \\Rightarrow n=161\n \\\\[3mm] \nf(n), n=161\n \\\\ \n \\Rightarrow 3(161) + 1\n \\\\ \n \\Rightarrow n=484\n \\\\[3mm] \nf(n), n=484\n \\\\ \n \\Rightarrow \\frac{484}{2} \n \\\\ \n \\Rightarrow n=242\n \\\\[3mm] \nf(n), n=242\n \\\\ \n \\Rightarrow \\frac{242}{2} \n \\\\ \n \\Rightarrow n=121\n \\\\[3mm] \nf(n), n=121\n \\\\ \n \\Rightarrow 3(121) + 1\n \\\\ \n \\Rightarrow n=364\n \\\\[3mm] \nf(n), n=364\n \\\\ \n \\Rightarrow \\frac{364}{2} \n \\\\ \n \\Rightarrow n=182\n \\\\[3mm] \nf(n), n=182\n \\\\ \n \\Rightarrow \\frac{182}{2} \n \\\\ \n \\Rightarrow n=91\n \\\\[3mm] \nf(n), n=91\n \\\\ \n \\Rightarrow 3(91) + 1\n \\\\ \n \\Rightarrow n=274\n \\\\[3mm] \nf(n), n=274\n \\\\ \n \\Rightarrow \\frac{274}{2} \n \\\\ \n \\Rightarrow n=137\n \\\\[3mm] \nf(n), n=137\n \\\\ \n \\Rightarrow 3(137) + 1\n \\\\ \n \\Rightarrow n=412\n \\\\[3mm] \nf(n), n=412\n \\\\ \n \\Rightarrow \\frac{412}{2} \n \\\\ \n \\Rightarrow n=206\n \\\\[3mm] \nf(n), n=206\n \\\\ \n \\Rightarrow \\frac{206}{2} \n \\\\ \n \\Rightarrow n=103\n \\\\[3mm] \nf(n), n=103\n \\\\ \n \\Rightarrow 3(103) + 1\n \\\\ \n \\Rightarrow n=310\n \\\\[3mm] \nf(n), n=310\n \\\\ \n \\Rightarrow \\frac{310}{2} \n \\\\ \n \\Rightarrow n=155\n \\\\[3mm] \nf(n), n=155\n \\\\ \n \\Rightarrow 3(155) + 1\n \\\\ \n \\Rightarrow n=466\n \\\\[3mm] \nf(n), n=466\n \\\\ \n \\Rightarrow \\frac{466}{2} \n \\\\ \n \\Rightarrow n=233\n \\\\[3mm] \nf(n), n=233\n \\\\ \n \\Rightarrow 3(233) + 1\n \\\\ \n \\Rightarrow n=700\n \\\\[3mm] \nf(n), n=700\n \\\\ \n \\Rightarrow \\frac{700}{2} \n \\\\ \n \\Rightarrow n=350\n \\\\[3mm] \nf(n), n=350\n \\\\ \n \\Rightarrow \\frac{350}{2} \n \\\\ \n \\Rightarrow n=175\n \\\\[3mm] \nf(n), n=175\n \\\\ \n \\Rightarrow 3(175) + 1\n \\\\ \n \\Rightarrow n=526\n \\\\[3mm] \nf(n), n=526\n \\\\ \n \\Rightarrow \\frac{526}{2} \n \\\\ \n \\Rightarrow n=263\n \\\\[3mm] \nf(n), n=263\n \\\\ \n \\Rightarrow 3(263) + 1\n \\\\ \n \\Rightarrow n=790\n \\\\[3mm] \nf(n), n=790\n \\\\ \n \\Rightarrow \\frac{790}{2} \n \\\\ \n \\Rightarrow n=395\n \\\\[3mm] \nf(n), n=395\n \\\\ \n \\Rightarrow 3(395) + 1\n \\\\ \n \\Rightarrow n=1186\n \\\\[3mm] \nf(n), n=1186\n \\\\ \n \\Rightarrow \\frac{1186}{2} \n \\\\ \n \\Rightarrow n=593\n \\\\[3mm] \nf(n), n=593\n \\\\ \n \\Rightarrow 3(593) + 1\n \\\\ \n \\Rightarrow n=1780\n \\\\[3mm] \nf(n), n=1780\n \\\\ \n \\Rightarrow \\frac{1780}{2} \n \\\\ \n \\Rightarrow n=890\n \\\\[3mm] \nf(n), n=890\n \\\\ \n \\Rightarrow \\frac{890}{2} \n \\\\ \n \\Rightarrow n=445\n \\\\[3mm] \nf(n), n=445\n \\\\ \n \\Rightarrow 3(445) + 1\n \\\\ \n \\Rightarrow n=1336\n \\\\[3mm] \nf(n), n=1336\n \\\\ \n \\Rightarrow \\frac{1336}{2} \n \\\\ \n \\Rightarrow n=668\n \\\\[3mm] \nf(n), n=668\n \\\\ \n \\Rightarrow \\frac{668}{2} \n \\\\ \n \\Rightarrow n=334\n \\\\[3mm] \nf(n), n=334\n \\\\ \n \\Rightarrow \\frac{334}{2} \n \\\\ \n \\Rightarrow n=167\n \\\\[3mm] \nf(n), n=167\n \\\\ \n \\Rightarrow 3(167) + 1\n \\\\ \n \\Rightarrow n=502\n \\\\[3mm] \nf(n), n=502\n \\\\ \n \\Rightarrow \\frac{502}{2} \n \\\\ \n \\Rightarrow n=251\n \\\\[3mm] \nf(n), n=251\n \\\\ \n \\Rightarrow 3(251) + 1\n \\\\ \n \\Rightarrow n=754\n \\\\[3mm] \nf(n), n=754\n \\\\ \n \\Rightarrow \\frac{754}{2} \n \\\\ \n \\Rightarrow n=377\n \\\\[3mm] \nf(n), n=377\n \\\\ \n \\Rightarrow 3(377) + 1\n \\\\ \n \\Rightarrow n=1132\n \\\\[3mm] \nf(n), n=1132\n \\\\ \n \\Rightarrow \\frac{1132}{2} \n \\\\ \n \\Rightarrow n=566\n \\\\[3mm] \nf(n), n=566\n \\\\ \n \\Rightarrow \\frac{566}{2} \n \\\\ \n \\Rightarrow n=283\n \\\\[3mm] \nf(n), n=283\n \\\\ \n \\Rightarrow 3(283) + 1\n \\\\ \n \\Rightarrow n=850\n \\\\[3mm] \nf(n), n=850\n \\\\ \n \\Rightarrow \\frac{850}{2} \n \\\\ \n \\Rightarrow n=425\n \\\\[3mm] \nf(n), n=425\n \\\\ \n \\Rightarrow 3(425) + 1\n \\\\ \n \\Rightarrow n=1276\n \\\\[3mm] \nf(n), n=1276\n \\\\ \n \\Rightarrow \\frac{1276}{2} \n \\\\ \n \\Rightarrow n=638\n \\\\[3mm] \nf(n), n=638\n \\\\ \n \\Rightarrow \\frac{638}{2} \n \\\\ \n \\Rightarrow n=319\n \\\\[3mm] \nf(n), n=319\n \\\\ \n \\Rightarrow 3(319) + 1\n \\\\ \n \\Rightarrow n=958\n \\\\[3mm] \nf(n), n=958\n \\\\ \n \\Rightarrow \\frac{958}{2} \n \\\\ \n \\Rightarrow n=479\n \\\\[3mm] \nf(n), n=479\n \\\\ \n \\Rightarrow 3(479) + 1\n \\\\ \n \\Rightarrow n=1438\n \\\\[3mm] \nf(n), n=1438\n \\\\ \n \\Rightarrow \\frac{1438}{2} \n \\\\ \n \\Rightarrow n=719\n \\\\[3mm] \nf(n), n=719\n \\\\ \n \\Rightarrow 3(719) + 1\n \\\\ \n \\Rightarrow n=2158\n \\\\[3mm] \nf(n), n=2158\n \\\\ \n \\Rightarrow \\frac{2158}{2} \n \\\\ \n \\Rightarrow n=1079\n \\\\[3mm] \nf(n), n=1079\n \\\\ \n \\Rightarrow 3(1079) + 1\n \\\\ \n \\Rightarrow n=3238\n \\\\[3mm] \nf(n), n=3238\n \\\\ \n \\Rightarrow \\frac{3238}{2} \n \\\\ \n \\Rightarrow n=1619\n \\\\[3mm] \nf(n), n=1619\n \\\\ \n \\Rightarrow 3(1619) + 1\n \\\\ \n \\Rightarrow n=4858\n \\\\[3mm] \nf(n), n=4858\n \\\\ \n \\Rightarrow \\frac{4858}{2} \n \\\\ \n \\Rightarrow n=2429\n \\\\[3mm] \nf(n), n=2429\n \\\\ \n \\Rightarrow 3(2429) + 1\n \\\\ \n \\Rightarrow n=7288\n \\\\[3mm] \nf(n), n=7288\n \\\\ \n \\Rightarrow \\frac{7288}{2} \n \\\\ \n \\Rightarrow n=3644\n \\\\[3mm] \nf(n), n=3644\n \\\\ \n \\Rightarrow \\frac{3644}{2} \n \\\\ \n \\Rightarrow n=1822\n \\\\[3mm] \nf(n), n=1822\n \\\\ \n \\Rightarrow \\frac{1822}{2} \n \\\\ \n \\Rightarrow n=911\n \\\\[3mm] \nf(n), n=911\n \\\\ \n \\Rightarrow 3(911) + 1\n \\\\ \n \\Rightarrow n=2734\n \\\\[3mm] \nf(n), n=2734\n \\\\ \n \\Rightarrow \\frac{2734}{2} \n \\\\ \n \\Rightarrow n=1367\n \\\\[3mm] \nf(n), n=1367\n \\\\ \n \\Rightarrow 3(1367) + 1\n \\\\ \n \\Rightarrow n=4102\n \\\\[3mm] \nf(n), n=4102\n \\\\ \n \\Rightarrow \\frac{4102}{2} \n \\\\ \n \\Rightarrow n=2051\n \\\\[3mm] \nf(n), n=2051\n \\\\ \n \\Rightarrow 3(2051) + 1\n \\\\ \n \\Rightarrow n=6154\n \\\\[3mm] \nf(n), n=6154\n \\\\ \n \\Rightarrow \\frac{6154}{2} \n \\\\ \n \\Rightarrow n=3077\n \\\\[3mm] \nf(n), n=3077\n \\\\ \n \\Rightarrow 3(3077) + 1\n \\\\ \n \\Rightarrow n=9232\n \\\\[3mm] \nf(n), n=9232\n \\\\ \n \\Rightarrow \\frac{9232}{2} \n \\\\ \n \\Rightarrow n=4616\n \\\\[3mm] \nf(n), n=4616\n \\\\ \n \\Rightarrow \\frac{4616}{2} \n \\\\ \n \\Rightarrow n=2308\n \\\\[3mm] \nf(n), n=2308\n \\\\ \n \\Rightarrow \\frac{2308}{2} \n \\\\ \n \\Rightarrow n=1154\n \\\\[3mm] \nf(n), n=1154\n \\\\ \n \\Rightarrow \\frac{1154}{2} \n \\\\ \n \\Rightarrow n=577\n \\\\[3mm] \nf(n), n=577\n \\\\ \n \\Rightarrow 3(577) + 1\n \\\\ \n \\Rightarrow n=1732\n \\\\[3mm] \nf(n), n=1732\n \\\\ \n \\Rightarrow \\frac{1732}{2} \n \\\\ \n \\Rightarrow n=866\n \\\\[3mm] \nf(n), n=866\n \\\\ \n \\Rightarrow \\frac{866}{2} \n \\\\ \n \\Rightarrow n=433\n \\\\[3mm] \nf(n), n=433\n \\\\ \n \\Rightarrow 3(433) + 1\n \\\\ \n \\Rightarrow n=1300\n \\\\[3mm] \nf(n), n=1300\n \\\\ \n \\Rightarrow \\frac{1300}{2} \n \\\\ \n \\Rightarrow n=650\n \\\\[3mm] \nf(n), n=650\n \\\\ \n \\Rightarrow \\frac{650}{2} \n \\\\ \n \\Rightarrow n=325\n \\\\[3mm] \nf(n), n=325\n \\\\ \n \\Rightarrow 3(325) + 1\n \\\\ \n \\Rightarrow n=976\n \\\\[3mm] \nf(n), n=976\n \\\\ \n \\Rightarrow \\frac{976}{2} \n \\\\ \n \\Rightarrow n=488\n \\\\[3mm] \nf(n), n=488\n \\\\ \n \\Rightarrow \\frac{488}{2} \n \\\\ \n \\Rightarrow n=244\n \\\\[3mm] \nf(n), n=244\n \\\\ \n \\Rightarrow \\frac{244}{2} \n \\\\ \n \\Rightarrow n=122\n \\\\[3mm] \nf(n), n=122\n \\\\ \n \\Rightarrow \\frac{122}{2} \n \\\\ \n \\Rightarrow n=61\n \\\\[3mm] \nf(n), n=61\n \\\\ \n \\Rightarrow 3(61) + 1\n \\\\ \n \\Rightarrow n=184\n \\\\[3mm] \nf(n), n=184\n \\\\ \n \\Rightarrow \\frac{184}{2} \n \\\\ \n \\Rightarrow n=92\n \\\\[3mm] \nf(n), n=92\n \\\\ \n \\Rightarrow \\frac{92}{2} \n \\\\ \n \\Rightarrow n=46\n \\\\[3mm] \nf(n), n=46\n \\\\ \n \\Rightarrow \\frac{46}{2} \n \\\\ \n \\Rightarrow n=23\n \\\\[3mm] \nf(n), n=23\n \\\\ \n \\Rightarrow 3(23) + 1\n \\\\ \n \\Rightarrow n=70\n \\\\[3mm] \nf(n), n=70\n \\\\ \n \\Rightarrow \\frac{70}{2} \n \\\\ \n \\Rightarrow n=35\n \\\\[3mm] \nf(n), n=35\n \\\\ \n \\Rightarrow 3(35) + 1\n \\\\ \n \\Rightarrow n=106\n \\\\[3mm] \nf(n), n=106\n \\\\ \n \\Rightarrow \\frac{106}{2} \n \\\\ \n \\Rightarrow n=53\n \\\\[3mm] \nf(n), n=53\n \\\\ \n \\Rightarrow 3(53) + 1\n \\\\ \n \\Rightarrow n=160\n \\\\[3mm] \nf(n), n=160\n \\\\ \n \\Rightarrow \\frac{160}{2} \n \\\\ \n \\Rightarrow n=80\n \\\\[3mm] \nf(n), n=80\n \\\\ \n \\Rightarrow \\frac{80}{2} \n \\\\ \n \\Rightarrow n=40\n \\\\[3mm] \nf(n), n=40\n \\\\ \n \\Rightarrow \\frac{40}{2} \n \\\\ \n \\Rightarrow n=20\n \\\\[3mm] \nf(n), n=20\n \\\\ \n \\Rightarrow \\frac{20}{2} \n \\\\ \n \\Rightarrow n=10\n \\\\[3mm] \nf(n), n=10\n \\\\ \n \\Rightarrow \\frac{10}{2} \n \\\\ \n \\Rightarrow n=5\n \\\\[3mm] \nf(n), n=5\n \\\\ \n \\Rightarrow 3(5) + 1\n \\\\ \n \\Rightarrow n=16\n \\\\[3mm] \nf(n), n=16\n \\\\ \n \\Rightarrow \\frac{16}{2} \n \\\\ \n \\Rightarrow n=8\n \\\\[3mm] \nf(n), n=8\n \\\\ \n \\Rightarrow \\frac{8}{2} \n \\\\ \n \\Rightarrow n=4\n \\\\[3mm] \nf(n), n=4\n \\\\ \n \\Rightarrow \\frac{4}{2} \n \\\\ \n \\Rightarrow n=2\n \\\\[3mm] \nf(n), n=2\n \\\\ \n \\Rightarrow \\frac{2}{2} \n \\\\ \n \\Rightarrow n=1\n \\\\[3mm] \n\n    \\section{Credits}\n    %Maybe add link to gitrepo and other shit, idk\n    This is created using Collatzer (https://github.com/Z1aaan/Collatzer).\n    Created By: Z1aaan\n    \n    README:\n    A program created to visualize and simulate a user-given value for \\textit{N} \n    and see what happens when it is put under the Collatz function.\n    \\end{document}", "meta": {"hexsha": "ebb71a99460ce5b08c8e1b54c4ee3f15078f351a", "size": 13043, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sample_output.tex", "max_stars_repo_name": "Z1aaan/Collatz-Conjecture", "max_stars_repo_head_hexsha": "d355df30b69ca04d936f07d0cbb9aec9c4796223", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:06:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:06:27.000Z", "max_issues_repo_path": "sample_output.tex", "max_issues_repo_name": "Z1aaan/Collatzer", "max_issues_repo_head_hexsha": "d355df30b69ca04d936f07d0cbb9aec9c4796223", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sample_output.tex", "max_forks_repo_name": "Z1aaan/Collatzer", "max_forks_repo_head_hexsha": "d355df30b69ca04d936f07d0cbb9aec9c4796223", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.7150368034, "max_line_length": 82, "alphanum_fraction": 0.5326228628, "num_tokens": 5584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.7107482944141749}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{amsmath, mathtools}\n\n\\begin{document}\n\n\\begin{center}\n{\\Large Sample swap}\n\n\\medskip\nJonathan Bloom \\texttt{jbloom@broadinstitute.org}\\\\ \nand \\\\\nYossi Farjoun \\texttt{farjoun@broadinstitute.org} \\\\\n\nJune 20, 2014\n\\end{center}\n\n\nLet $\\theta$ and $\\varphi$ denote the diploid haplotypes (that is AA, AB or BB) of samples from which sequencing data sets $x$ and $y$, respectively, have been generated.  \nLet $s$ be a Bernoulli random variable with $s=1$ if these samples are from distinct individuals.  \nWe call the event $s=1$ a {\\em swap}, and in this note we compute its posterior probability $p(s = 1 \\, | \\, x, y)$.  \nIn the context of sample validation, $x$ is sequencing data from a sample of interest and $y$ is micro-array or sequencing data from a sample intended to be from the same individual.  \nIf $p(s = 1 \\, | \\, x, y)$ is non-trivial, then one should flag the suspect data and investigate. \n\nBy Bayes' Rule, the posterior probability of a swap is given by\n\\begin{align}\n\\label{prob_swap}\np(s = 1 \\, | \\, x,y) = \\frac{p(x,y \\, | \\, s = 1) \\, p(s=1)}{p(x,y \\, | \\, s = 1) \\, p(s = 1) + p(x,y \\, | \\, s = 0) \\, p(s =0)}\n\\end{align}\nEquivalently, the posterior odds of a swap is the product of the Bayes factor (likelihood ratio) and prior odds:\n\\begin{align}\n\\label{odds_swap}\n\\frac{p(s = 1 \\, | \\, x,y)}{p(s = 0 \\, | \\, x,y)} = \\frac{p(x,y \\, | \\, s = 1) \\, p(s = 1)}{p(x,y \\, | \\, s = 0) \\, p(s = 0)}\n\\end{align}\nIn particular, if a sample swap rarely occurs then the posterior log odds of a swap is well-approximated by\n\\[\n\\log(L_1) - \\log(L_0) + \\log(S)\n\\]\nwhere $L_i = p(x,y \\, | \\, s=i)$ and $S$ is the prior probability of a swap.\n\nTo compute these, the following functions must be empirically estimated:\n\\begin{itemize}\n\\item the prior $p(s)$, or equivalently the prior probability of a swap.\n\\item the haplotype distribution $p(\\theta)$ in the source population.\n\\item the likelihood function $p(x \\, | \\, \\theta)$ up to a scaling factor $c(x)$.\n\\item the likelihood function $p(y \\, | \\, \\varphi)$ up to a scaling factor $c(y)$.\n\\end{itemize}\nThen by \\eqref{prob_swap}, it suffices to express $p(x,y \\, | \\, s)$ in terms of $p(\\theta)$, $p(x \\, | \\, \\theta)$, and $p( y \\, | \\, \\varphi)$.  To do this, we assume that distinct individuals are independently drawn from the population and that samples from the same individual have the same haplotype:\n\\begin{equation}\n\\label{theta_phi_cond_indep}\np(\\theta, \\varphi \\, | \\, s) =\n  \\begin{cases}\n   p(\\theta) \\, p(\\varphi) & \\text{if } s = 1, \\\\\n   p(\\theta) & \\text{if } \\theta = \\varphi, \\\\\n   0 & \\text{otherwise.}\n  \\end{cases}\n\\end{equation}\nNext we have\n\\begin{align}\np(x,y \\, | \\, \\theta, \\varphi)\n&= \\frac{p(x,y \\, | \\, \\theta, \\varphi)}{p(y \\, | \\, \\theta, \\varphi)} p(y \\, | \\, \\theta, \\varphi) \\notag \\\\\n\\label{def_cond_prob}\n&= p(x \\, | \\, \\theta, \\varphi, y) \\, p(y \\, |  \\, \\theta, \\varphi) \\\\\n\\label{xy_cond_indep}\n&= p(x \\, | \\, \\theta) \\, p(y \\, | \\, \\varphi).\n\\end{align}\nwhere \\eqref{def_cond_prob} applies the definition of conditional probability and \\eqref{xy_cond_indep} uses that $x$ is conditionally independent of $\\varphi$ and $y$ given $\\theta$, and $y$ is conditionally independent of $\\theta$ given $\\varphi$. Therefore\n\\begin{align}\n\\label{total_prob}\np(x,y \\, | \\, s)\n&=  \\textstyle\\sum\\limits_{\\theta,\\varphi} p(x, y \\, | \\, \\theta, \\varphi, s) \\, p(\\theta, \\varphi \\, | \\, s) \\\\\n\\label{xy_cond_indep_s}\n&= \\textstyle\\sum\\limits_{\\theta, \\varphi} p(x, y \\, | \\, \\theta, \\varphi) \\, p(\\theta, \\varphi \\, | \\, s) \\\\\n\\label{apply_xy_cond_indep}\n&= \\textstyle\\sum\\limits_{\\theta, \\varphi} p(x \\, | \\, \\theta) \\, p(y \\, | \\, \\varphi) \\, p(\\theta, \\varphi \\, | \\, s) \\\\\n\\label{apply_theta_phi_cond_indep}\n&=\n  \\begin{dcases}\n   \\textstyle\\sum\\limits_{\\theta} p(x \\, | \\, \\theta) \\, p(\\theta) \\, \\textstyle\\sum\\limits_{\\varphi} p(y \\, | \\, \\varphi) \\, p(\\varphi) & \\text{if } s = 1, \\\\\n   \\textstyle\\sum\\limits_{\\theta = \\varphi}  \\, p(x\\,|\\,\\theta)  \\, p(y \\, | \\, \\varphi) \\, p(\\theta) & \\text{if } s = 0. \\\\\n  \\end{dcases}\n\\end{align}\nHere \\eqref{total_prob} is the law of total probability, \\eqref{xy_cond_indep_s} uses that $x$ and $y$ are conditionally independent of $s$ given $\\theta$ and $\\varphi$, \\eqref{apply_xy_cond_indep} applies \\eqref{xy_cond_indep}, and \\eqref{apply_theta_phi_cond_indep} applies \\eqref{theta_phi_cond_indep}.  Substituting \\eqref{apply_theta_phi_cond_indep} into \\eqref{odds_swap}, we conclude that the posterior odds of a swap is:\n\\begin{equation}\n\\label{odds}\n\\boxed{\\frac{\\sum_\\theta p(x \\, | \\, \\theta) \\, p(\\theta) \\, \\sum_{\\varphi} p(y \\, | \\, \\varphi) \\, p(\\varphi)}{\\sum_{\\theta = \\varphi} p(x \\, | \\, \\theta) \\, p(y \\, | \\, \\varphi) \\, p(\\theta)} \\cdot \\frac{p(s=1)}{p(s=0)}}\n\\end{equation}\n\nComputing \\eqref{odds_swap} is easiest when $\\theta$, $\\varphi$, $x$, and $y$ are understood as tuples indexed by loci such that:\n\\begin{itemize}\n\\item The haplotypes at distinct loci are independent, i.e. $p(\\theta) = \\prod_i p(\\theta_i)$.\n\\item $x_i$ and $\\theta_j$ are independent for $i \\neq j$, i.e. $p(x_i \\, | \\, \\theta) = p(x_i \\, | \\, \\theta_i)$.\n\\item $y_i$ and $\\varphi_j$ are independent for $i \\neq j$, i.e. $p(y_i \\, | \\, \\varphi) = p(y_i \\, | \\, \\varphi_i)$.\n\\end{itemize}\nIn this case, by a generalization of the argument in \\eqref{xy_cond_indep} we have\n\\begin{align*}\np(x \\, | \\, \\theta) &= \\textstyle\\prod\\limits_i p(x_i \\, | \\, \\theta_i) \\\\\np(y \\, | \\, \\varphi) &= \\textstyle\\prod\\limits_i p(y_i \\, | \\, \\varphi_i).\n\\end{align*}\nSubstituting these expressions into \\eqref{odds} and re-distributing yields\n\\begin{equation}\n\\boxed{\\prod_i \\left(\\frac{\\sum_{\\theta_i} p(x_i \\, | \\, \\theta_i) \\, p(\\theta_i) \\, \\sum_{\\varphi_i} p(y_i \\, | \\, \\varphi_i) \\, p(\\varphi_i)}{\\sum_{\\theta_i = \\varphi_i} p(x_i \\, | \\, \\theta_i) \\, p(y_i \\, | \\, \\varphi_i) \\, p(\\theta_i)}\\right) \\cdot \\frac{p(s=1)}{p(s=0)}}\n\\label{odds_many}\n\\end{equation}\n\n\\section{Haplotype Likelihoods}\nIn this section we describe how the haplotype likelihood $p(x|\\theta)$ can be computed for various kinds of data.\n\\subsection{Sequence data}\nFor sequence data, we assume that the data come from a single individual (i.e. not contaminated, see subsection below) and that there is no reference bias (can correct for that, but it's rarely needed).\nSequence data arrives in the form of reads. \nWe assume that evidence for haplotype $h_i\\in\\{A,B\\}$ with probability of error $e_i\\in(0,1)$ are given at a certain haplotype block.\nWe further assume that said evidence is independent, for example, reads have been duplicate marked, and close SNPs from the same read-pair are not used twice.\nThen we can write:\n\\begin{equation}\np(h,e|\\theta)=\\prod_{i=0}^n p(h_i,e_i|\\theta)\n\\end{equation}\nThe likelihood of a single datum $p(h_i,e_i|\\theta)$ is expressed by\n\\begin{equation}\np(h_i,e_i|\\theta)=\\begin{cases}\nI_B(h_i)e_i + I_A(h_i)(1-e_i) & \\theta=AA\\\\\n0.5 & \\theta=AB\\\\\nI_A(h_i)e_i + I_B(h_i)(1-e_i) &  \\theta=BB\n\\end{cases}\n\\end{equation}\nWhere $I_x$ is the indicator function of $x$ and the assumption is that an error will cause a switch in the interpretation of the haplotype between $A$ and $B$.\nThis assumes that we throw away non-conformant haplotypes, and ignores the possibility of a non-conformant haplotype erroneously looking conformant. \n(By conformant we mean either $A$ or $B$.)\n\nThis LOD calculation is implemented in Picard's CheckFingerprints and CrosscheckFingerprints.\n\n\\subsection{Contaminated Samples}\nAt times, one knows that data from a particular sample is contaminated at a known level (that level can be estimated using VarifyBamID, or ContEst, for example). \nHowever, the identity of the contaminator is unknown. \nIn this section we describe how the diploid Haplotype likelihood of the contaminator can be (sometimes) extracted from the data.\nFor the calculation we will need the prior on the haplotypes, $p(\\theta)$, which can be calculated from the haplotype frequency by assuming Hardy-Weinberg equilibrium.\n\nWe assume that the underlying samples have (unknown) haplotypes $\\theta$ and $\\phi$, mixed with proportion $1-c$ and $c$, respectively. \nThe data collected from this mixture, is $x$.\nThen we can write: \n\\begin{equation}\np(x|c,\\theta)=\\sum_\\phi p(x|c,\\theta,\\phi)p(\\phi)\n\\end{equation}\n\nThis enables us to discover (and thus extract) $p(x|c,\\theta)$ which can then be used in \\eqref{odds_many}. \n\nPicard's ExtractContaminantFingerprint implements this and writes a new VCF with the likelihoods of the contaminant. \nThis VCF can then be further used to compare the contaminant (or the contaminated sample) to another sample.\n\n\\subsection{LoH samples}\nWhen a sample comes from a tumor there is the possibility that it has undergone a loss of heterozygosity (LoH) where large sections of chromosomes are lost (whole arms, and sometimes one copy of a whole chromosome can be lost).\nThis makes all the heterozygous haplotypes (from the germline) in that region of the chromosome seem homozygous since the only evidence comes from the remaining copy.\nIn this case, the standard calculation of $p(x|\\theta)$ will yield an incorrect likelihood for the genotypes of the normal sample. Furthermore, since the LoH event is correlated among the different sites, our assumption of independence is incorrect.  \nWe need to be able to infer the genotype posterior of the normal sample given the data from the tumor, $p(G_n|D_t)$,  so that we can compare genotypes of the individual.\n\nWe assume that a heterozygous site can become homozygous at a probability $p_{loh}$. Thus we can write a transition probability:\n\\begin{equation}\nT= \\begin{pmatrix}\n1 & 0 & 0 \\\\\np_{loh}/2 & 1-p_{loh} & p_{loh}/2\\\\\n0 & 0 & 1\n\\end{pmatrix}\n\\end{equation}\nand now\n\\begin{equation}\np(g_t=j|g_n=i) = T^i_j\n\\end{equation}\nwhere $g_t$ is the tumor's genotype and $g_n$ is the normal's genotype.\n\nWe are looking for $p(G_n|D_t)$ and so we observe:\n\\begin{align*}\np(D_t|g_n)&=\\sum_{g_t}p(D_t,g_t|g_n)\\\\\n&=\\sum_{g_t}p(D_t|g_n,g_t)p(g_t|g_n)\\\\\n&=\\sum_{g_t}p(D_t|g_t) T^{g_t}_{g_n}\\\\\n\\end{align*}\nWhich gives us the likelihood of the tumor's data in the context of the normal's genotype.\n\nThus, in \\eqref{odds} above, if $x'$ is data from the tumor with genotype $\\theta'$ and whose normal has genotype $\\theta$, we get that the posterior odds of a swap is:\n\\begin{equation}\n\\boxed{\\frac{\\sum_\\theta \\sum_{\\theta'} p(x' \\, | \\, \\theta')T_{\\theta}^{\\theta'} \\, p(\\theta) \\, \\sum_{\\varphi} p(y \\, | \\, \\varphi) \\, p(\\varphi)}{\\sum_{\\theta = \\varphi}  \\sum_{\\theta'} p(x' \\, | \\, \\theta')T_{\\theta}^{\\theta'} \\, p(y \\, | \\, \\varphi) \\, p(\\theta)} \\cdot \\frac{p(s=1)}{p(s=0)}}\n\\end{equation}\n\nThis is implemented in CrosscheckFingerprints and emitted in the TUMOR\\_NORMAL\\_LOD and NORMAL\\_TUMOR\\_LOD columns in the fingerprinting report.\n\n\\end{document}\n", "meta": {"hexsha": "29a9346e9082ef29195aeb9f273f2c62d08f1f84", "size": 10788, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/fingerprinting/main.tex", "max_stars_repo_name": "hassanfa/picard", "max_stars_repo_head_hexsha": "3040af3bca9a4c307266311f372b1ed647be7789", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 798, "max_stars_repo_stars_event_min_datetime": "2015-01-07T20:01:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T02:22:59.000Z", "max_issues_repo_path": "docs/fingerprinting/main.tex", "max_issues_repo_name": "hassanfa/picard", "max_issues_repo_head_hexsha": "3040af3bca9a4c307266311f372b1ed647be7789", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1523, "max_issues_repo_issues_event_min_datetime": "2015-01-05T16:14:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T19:05:16.000Z", "max_forks_repo_path": "docs/fingerprinting/main.tex", "max_forks_repo_name": "hassanfa/picard", "max_forks_repo_head_hexsha": "3040af3bca9a4c307266311f372b1ed647be7789", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 419, "max_forks_repo_forks_event_min_datetime": "2015-01-02T12:25:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-22T06:26:31.000Z", "avg_line_length": 58.6304347826, "max_line_length": 428, "alphanum_fraction": 0.6864108268, "num_tokens": 3593, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.7107137064595396}}
{"text": "\n\\section{Pascal characterization}\n\nIn this section we present some results about Pascal array and\nits inverse, taken modulo some prime $p$. \n\nAssociating different colours to elements belonging to different remainder\nclasses, we show formally that for $p=2$, elements in the same\nposition get the same colour, hence both triangles are coloured in the same\nway, ignoring signs for elements in the inverse array, which can happen to be\nnegative. On the other hand, for $p$ odd there is not such a simple\ncorrespondence and we attempt to observe some repeating pattern in the mapping\namong elements in those arrays.\n\n\\subsection{$\\equiv_{p}$ over $\\mathcal{P}$ and $\\mathcal{P}^{-1}$,\n    where $p$ \\emph{is} a prime}\n\nLet $\\mathcal{P}$ be the Riordan array for the Pascal triangle,\ndefined as:\n\\begin{displaymath} \n    \\mathcal{P} = \\left(\\frac{1}{1-t}, \\frac{t}{1-t}  \\right)\n\\end{displaymath} \nand let $\\mathcal{P}^{-1}$ be the inverse of $\\mathcal{P}$:\n\\begin{displaymath} \n    \\mathcal{P}^{-1} = \\left(\\frac{1}{1+t}, \\frac{t}{1+t}  \\right)\n\\end{displaymath} \n\nLet $d_{nk}$ and $\\hat{d}_{nk}$ be the generic elements of $\\mathcal{P}$ and of\n$\\mathcal{P}^{-1}$, respectively. Since both arrays are in the Riordan group,\n$d_{nk}$ can be written as:\n\\begin{displaymath}\n    \\begin{split}\n        d_{nk} &= [t^n]\\frac{1}{1-t}\\left(\\frac{t}{1-t}\\right)^k = [t^{n-k}](1-t)^{-(k+1)} \\\\\n            &= {{-(k+1)} \\choose {n-k}}(-1)^{n-k} = {{k+1 +n-k -1} \\choose {n-k}} = {{n} \\choose {n-k}} \\\\\n    \\end{split}\n\\end{displaymath}\nusing the same approach $\\hat{d}_{nk}$ can be written as:\n\\begin{displaymath}\n  \\begin{split}\n    \\hat{d}_{nk} &= [t^n]\\frac{1}{1+t}\\left(\\frac{t}{1+t}\\right)^k = [t^{n-k}](1+t)^{-(k+1)} = \n    {{-(k+1)} \\choose {n-k}} \\\\\n    &= {{k+1 +n-k -1} \\choose {n-k}} (-1)^{n-k} = {{n} \\choose {n-k}} (-1)^{n-k}\\\\\n  \\end{split}\n\\end{displaymath}\nHence, equating binomial coefficients yields:\n\\begin{displaymath}\n  [t^n]\\frac{1}{1-t}\\left(\\frac{t}{1-t}\\right)^k = (-1)^{k-n}[t^n]\\frac{1}{1+t}\\left(\\frac{t}{1+t}\\right)^k \n\\end{displaymath}\nChoose a prime $p$ and apply the modulo operator on both members:\n\\begin{displaymath}\n  [t^n]\\frac{1}{1-t}\\left(\\frac{t}{1-t}\\right)^k \\equiv_{p} (-1)^{k-n}[t^n]\\frac{1}{1+t}\\left(\\frac{t}{1+t}\\right)^k \n\\end{displaymath}\n\nFrom now on we have \\marginpar{$b^{-1}\\mod p$ exists if and only if $(b,p)=1$}\nto reason according to modular arithmetic rules. In particular, we have to keep in\nmind that multiplying a term $b$ by a term $a$ in order to simplify it, namely\nto get $1$, we are requested  to show that $a$ is the\n\\emph{multiplicative inverse} of $b$ modulo $p$, denoted by: \n\\begin{displaymath}\n    a = b^{-1}\\mod p\n\\end{displaymath}\n\nFirst of all, observe that $-1 \\equiv_{p} p-1$ and since $p$ is a prime by\nhypothesis, it follows that $(p, p-1)=1$ (this result holds in general, not\njust for $p$ prime), which proofs the existence of both $-1$ and $p-1$\ninverses, denoted by $(-1)^{-1}\\mod p$ and $(p-1)^{-1}\\mod p$ respectively.\n\nIn order to find $(p-1)^{-1}\\mod p$ we have to satisfy the congruence equation\n$(p-1) \\cdot (p-1)^{-1} \\equiv_{p} 1$. Choose $(p-1)^{-1}\\mod p = p-1$ and\nverify $(p-1) \\cdot (p-1) \\equiv_{p} p^{2} -2\\,p +1 \\equiv_{p} 1$ as required.\n\nAnother useful observation concerns raising to negative powers:\n\\begin{displaymath}\n    (-1)^{-k} \\equiv_{p} \\left((-1)^{-1}\\right)^{k} \\equiv_{p} (p-1)^k\n\\end{displaymath}\nwhere $k \\geq 0$ and, since $-1 \\equiv_{p} p-1$, it follows that\n$(-1)^{-k} \\equiv_{p} (-1)^k$.\n\nNow we can use previous observation on the main congruence:\n\\begin{displaymath}\n    \\begin{split}\n        [t^n]\\frac{1}{1-t}\\left(\\frac{t}{1-t}\\right)^k \n            &\\equiv_{p} (-1)^{k-n}[t^n]\\frac{1}{1+t}\\left(\\frac{t}{1+t}\\right)^k \\\\\n            &\\equiv_{p} (-1)^{k+n}[t^n]\\frac{1}{1+t}\\left(\\frac{t}{1+t}\\right)^k \\\\\n            &\\equiv_{p} (p-1)^{k+n}[t^n]\\frac{1}{1+t}\\left(\\frac{t}{1+t}\\right)^k \\\\\n    \\end{split}\n\\end{displaymath}\nHence, multiplying by $(p-1)^{-1}\\mod p$ both members $k+n$ times:\n\\begin{displaymath}\n    (p-1)^{k+n}[t^n]\\frac{1}{1-t}\\left(\\frac{t}{1-t}\\right)^k \n        \\equiv_{p} [t^n]\\frac{1}{1+t}\\left(\\frac{t}{1+t}\\right)^k \n\\end{displaymath}\nwhich is the same as:\n\\begin{displaymath}\n    (-1)^{k+n}[t^n]\\frac{1}{1-t}\\left(\\frac{t}{1-t}\\right)^k \\equiv_{p} [t^n]\\frac{1}{1+t}\\left(\\frac{t}{1+t}\\right)^k \n\\end{displaymath}\nand relating generic elements $d_{nk}$ and $\\hat{d}_{nk}$:\n\\marginpar{a general congruence $\\equiv_{p}$ over $\\mathcal{P}$ and $\\mathcal{P}^{-1}$, where $p$\n    is an arbitrary prime}\n\\begin{equation}\n    \\label{eq:general:congruence:over:pascal:arrays}\n    (p-1)^{k+n}d_{nk}\\equiv_{p}(-1)^{k+n}d_{nk} \\equiv_{p} \\hat{d}_{nk}\n\\end{equation}\n\n\\subsection{$\\mathcal{P}_{\\equiv_{2}}$} \n\nThe case where $p$ is the even prime produces the colouring reported in\n\\autoref{fig:pascal-standard-ignore-negatives-centered-colouring-127-rows-mod2-partitioning-triangle} for $\\mathcal{P}$,\nand the colouring reported in\n\\autoref{fig:pascal-inverse-ignore-negatives-centered-colouring-127-rows-mod2-partitioning-triangle} for $\\mathcal{P}^{-1}$,\nwhere negatives entries are ignored, while in \n\\autoref{fig:pascal-inverse-handle-negatives-centered-colouring-127-rows-mod2-partitioning-triangle} such entries are handled.\nFormally, $\\mathcal{P}$ and $\\mathcal{P}^{-1}$ look the same because if we fix $p=2$, \n\\autoref{eq:general:congruence:over:pascal:arrays} yields:\n\\begin{displaymath} \n    d_{nk} \\equiv_{2} \\hat{d}_{nk} \n\\end{displaymath} \nfor any choice of $n$ and $k$ in $\\mathbb{N}$.\n\n\\input{Chapters/mod-p-characterization/pascal/pascal-standard-ignore-negatives-centered-colouring-127-rows-mod2-partitioning-include-matrix.tex}\n\\input{Chapters/mod-p-characterization/pascal/pascal-standard-ignore-negatives-centered-colouring-127-rows-mod2-partitioning-include-figure.tex}\n\\input{Chapters/mod-p-characterization/pascal/pascal-inverse-ignore-negatives-centered-colouring-127-rows-mod2-partitioning-include-figure.tex}\n\\input{Chapters/mod-p-characterization/pascal/pascal-inverse-handle-negatives-centered-colouring-127-rows-mod2-partitioning-include-figure.tex}\n\n\n\\subsection{$\\mathcal{P}_{\\equiv_{3}}$}\n\nHere there's a more interesting pattern to study, and in general,\nfor any odd prime $p$, colourings of $\\mathcal{P}$ and its inverse \nmismatch. In this section we tackle the case for $p=3$,\ninstantiating \\autoref{eq:general:congruence:over:pascal:arrays} yields:\n\\begin{displaymath}\n  2^{k+n}d_{nk}\\equiv_{3}(-1)^{k+n}d_{nk} \\equiv_{3} \\hat{d}_{nk}\n\\end{displaymath}\n\nFor the sake of clarity, let us consider row $4$ of both triangles:\n\\begin{itemize}\n\\item $\\mathcal{P}_{[3,\\,:]} = (1 \\quad 3 \\quad 3 \\quad 1) \\equiv_{3}(1 \\quad 0 \\quad 0 \\quad 1)$\n\\item $\\mathcal{P}^{-1}_{[3,\\,:]} = (-1 \\quad 3 \\quad -3 \\quad 1) \\equiv_{3}(2 \\quad 0 \\quad 0 \\quad 1)$\n\\end{itemize}\n\\marginpar{$[\\alpha,\\beta]$\n in $\\mathcal{R}_{[\\alpha,\\beta]}$ is the \\emph{slice operator}, \n where $\\alpha,\\beta\\in\\mathbb{Z}\\cup\\lbrace:\\rbrace$, as defined in NumPy or in Octave}\nHence element $d_{30}$ gets a color $c$ while $\\hat{d}_{30}$ gets\na color $c'$ different from $c$: no general mapping about this relationship appears, so we\nstudy the two coloured triangles carefully. \n\nOur exercise here is as follow: first fix the order $\\alpha$ of a principal\ncluster $\\mathcal{P}^{(\\alpha)}$, say $\\alpha=4$; then move upwards from the\nlast row of $\\mathcal{P}^{(4)}$ to the top, one row by one, repeatedly. For\neach considered row, move toward the right over columns, trying to understand a\npossible congruence over coefficients in the two arrays, see\n\\autoref{fig:pascal:standard:mod3:congruence:zero:row:above}\nfor some highlights:\n\\input{Chapters/mod-p-characterization/pascal/pascal-standard-mod3-zero-row-above-end-include-figure}\n\\begin{displaymath}\n    \\begin{split}\n        d_{3^4 -1,0} &\\equiv_{3} \\hat{d}_{3^4 -1,0} \\\\\n        d_{3^4 -1,1} &\\equiv_{3} \\hat{d}_{3^4 -2,0} \\\\\n        d_{3^4 -1,2} &\\equiv_{3} \\hat{d}_{3^4 -3,0} \\\\\n        d_{3^4 -1,3} &\\equiv_{3} \\hat{d}_{3^4 -4,0} \\\\\n        &\\vdots\n    \\end{split}\n\\end{displaymath}\nnext, a congruence going up one row:\n\\marginpar{remember that the last row of $\\mathcal{P}^{(\\alpha)}$ is $p^{\\alpha}-1$,\n    for $p$ given }\n\\begin{displaymath}\n    \\begin{split}\n        d_{3^4 -2,0} &\\equiv_{3} \\hat{d}_{3^4 -1,1} \\\\\n        d_{3^4 -2,1} &\\equiv_{3} \\hat{d}_{3^4 -2,1} \\\\\n        d_{3^4 -2,2} &\\equiv_{3} \\hat{d}_{3^4 -3,1} \\\\\n        d_{3^4 -2,3} &\\equiv_{3} \\hat{d}_{3^4 -4,1} \\\\\n        &\\vdots\n    \\end{split}\n\\end{displaymath}\nnext, a congruence going up two rows:\n\\begin{displaymath}\n    \\begin{split}\n        d_{3^4 -3,0} &\\equiv_{3} \\hat{d}_{3^4 -1,2} \\\\\n        d_{3^4 -3,1} &\\equiv_{3} \\hat{d}_{3^4 -2,2} \\\\\n        d_{3^4 -3,2} &\\equiv_{3} \\hat{d}_{3^4 -3,2} \\\\\n        d_{3^4 -3,3} &\\equiv_{3} \\hat{d}_{3^4 -4,2} \\\\\n        &\\vdots\n    \\end{split}\n\\end{displaymath}\n\nA structure over indices can be caught, so let us introduce variable\n$b\\in\\lbrace1,\\ldots,3^{4}\\rbrace$ running over rows, and variable\n$a\\in\\lbrace 0,\\ldots,3^{4}-b\\rbrace$, running over columns. So we can state the following \ncongruence:\n\\begin{equation}\n    \\label{eq:pascal:arrays:congruence:rows:cols}\n    d_{3^4 -b,a} \\equiv_{3} \\hat{d}_{3^4 -1-a,b-1} \n\\end{equation}\n\\marginpar{column segments of $\\mathcal{P}$ are congruent to row segment of\n    $\\mathcal{P}^{-1}$ and viceversa}\n\nLet's say, assume the colouring for $\\mathcal{P}^{-1}$ triangle is\ngiven and the colouring for row $26$ of $\\mathcal{P}$ is desired. It\nis necessary to find $b$: by $3^4 -b=26$ get $b=55$, so the\ncoefficients lying on the required row satisfy the following congruence:\n\\begin{displaymath}\n        d_{26,a} \\equiv_{3} \\hat{d}_{80-a,54} \n\\end{displaymath}\n\\input{Chapters/mod-p-characterization/pascal/pascal-standard-mod3-zero-row-26-include-figure}\nan highlighting is shown in \\autoref{fig:pascal:standard:mod3:congruence:row:26}.\nOn the other hand, we could have choosed a column, compute the value \nfor $a$ and then state a congruence with $b$ as free variable.\n\n% the following chunk of statements is not clearly written and\n% I believe it is not so important, so for now skip it.\n\\iffalse\n\\\\\\\\\nA question is still open: why do we choose row $3^4$ as reference\nrow?\n\nIt is useful to recall a theorem due to Fine:\n\\begin{theorem}\n  A necessary and sufficient condition for a binomial coefficient\n  ${{n} \\choose {m}}$ to be divisible by a prime $p$ is that $n$\n  be a power of $p$.\n\\end{theorem}\nConsider the colouring for triangle $\\mathcal{P}$, we can use the\ngiven theorem to point out ``interesting'' rows, namely those rows\naffected by the theorem, they correspond to powers\n$3^1, 3^2, 3^3, 3^4, \\ldots$, each one of them can be easily\nrecognized since dots lying on it have all the same colour. In the\ntriangle $127$ former rows are drawn and in order to have ``more\nspace'' to find a modular relationship between $d_{nk}$ and\n$\\hat{d}_{nk}$ we choose as \\emph{reference} row the one with\nindex $3^4$.  From here we start moving backwards by rows toward\nthe root: observe that the entire row $3^4 -1$, containing\n$3^4 -1$ remainders, of triangle $\\mathcal{P}$ is the first\nsegment of the first column of $\\mathcal{P}^{-1}$, in other words\n$d_{3^4 -1,a} \\equiv_{3} \\hat{d}_{3^4 -1 -a, 0}$ for\n$a \\in \\lbrace 0, \\ldots, 3^4 -1\\rbrace$.\n\n\\fi\n\n% again the following paragraph is a technical detail that can \n% be understood only by talking.\n\\iffalse\nIt seems that coefficient $d_{3^4-1,0}$ acts as a pivot on which\nthe triangle ``flips'': the root moves toward the reader while the\nbottom edge moves toward opposite the reader. This rigid motion is\ncaptured by the following modular relationships among three\nimportant points:\n\\begin{displaymath}\n    \\begin{split}\n        d_{3^4 -1,0} &\\equiv_{3} \\hat{d}_{3^4 -1,0} \\\\\n        d_{3^4 -1,3^4 -1} &\\equiv_{3} \\hat{d}_{0,0} \\\\\n        d_{3^4 -3^3,3^3-1} &\\equiv_{3} \\hat{d}_{3^4 -3^3,3^3-1} \\\\\n    \\end{split}\n\\end{displaymath}\n\\fi\n\n\\subsection{$\\mathcal{P}_{\\equiv_{p}}$, where $p$ is a prime greater than $3$}\n\nIt is natural to ask if \\autoref{eq:pascal:arrays:congruence:rows:cols}\nholds for an arbitrary prime $p$.\n\\begin{conjecture}\n    Let $p$ be a prime and let $\\alpha\\in\\mathbb{N}$. \n    If $d_{nk}\\in\\mathcal{P}^{(\\alpha)}$ and\n    $\\hat{d}_{nk}\\in\\left(\\mathcal{P}^{-1}\\right)^{(\\alpha)}$, then:\n    \\marginpar{a general congruence over rows of $\\mathcal{P}$\n        and columns of $\\mathcal{P}^{-1}$, for any prime $p$?}\n    \\begin{equation}\n        d_{p^\\alpha -b,a} \\equiv_{p} \\hat{d}_{p^\\alpha -1-a,b-1} \n    \\end{equation}\n    where $b\\in\\lbrace1,\\ldots,p^{\\alpha}\\rbrace$ and \n    $a\\in\\lbrace 0,\\ldots,p^{\\alpha}-b\\rbrace$.\n\\end{conjecture}\nWe provide a proof sketch:\n\\begin{proof}\n    Using closed formula for coefficients $d_{p^\\alpha -b,a}$ and $\\hat{d}_{p^\\alpha -1-a,b-1}$\n    we can rewrite:\n    \\begin{displaymath}\n        {{p^\\alpha -b} \\choose {a}} \\equiv_{p} {{p^\\alpha -1-a}\\choose{b-1} }\\left(-1\\right)^{p^{\\alpha}-a-b}\n    \\end{displaymath}\n    and simple manipulation of binomial coefficients yield:\n    \\begin{displaymath}\n        {{p^\\alpha -b} \\choose {p^\\alpha -a-b}} \\equiv_{p} \n            {{p^\\alpha -1-a}\\choose{p^\\alpha -a-b} }\\left(-1\\right)^{p^{\\alpha}-a-b}\n    \\end{displaymath}\n    rewrite the right hand side using the identity ${{-n}\\choose{k}}={{n+k-1}\\choose{k}}(-1)^{k}$:\n    \\begin{displaymath}\n        {{p^\\alpha -b} \\choose {p^\\alpha -a-b}} \\equiv_{p} \n            {{-b}\\choose{p^\\alpha -a-b} }\n    \\end{displaymath}\n    to close the proof we could represent $-b$ in base $p$ and, \n    since $b\\in\\lbrace1,\\ldots,p^{\\alpha}\\rbrace$, the application of\n    Lucas theorem to both members produces the same product of binomial\n    coefficients, as required.\n\n\\end{proof}\n\n\\subsection{A proof of \\emph{Sierpinski}'s gasket}\n\nIn this section we show that in a Pascal array $\\mathcal{P}$ it is possible to\nrecognize a structure similar to the one observed by Sierpinski during his\nstudies on fractals. Interesting references are \\cite{sokolov},\n\\cite{stewart:four:encounters:sierpinski} and \\cite{barnsley}.\n\n\\begin{theorem}\n    Let $\\mathcal{P}^{(\\alpha)}$ be the principal cluster of order $\\alpha$. \n    $\\mathcal{P}^{(\\alpha)}$ repeats itself $3$ times within a\n    \\emph{chunk} of the principal cluster of one order bigger: such repetitions\n    happens in the first $2\\,p^{\\alpha}$ rows of $\\mathcal{P}^{(\\alpha+1)}$.\n    Moreover, those copies of $\\mathcal{P}^{(\\alpha)}$ surround a zero-hole of\n    order $\\alpha$. \n\\end{theorem}\n\nNote that for even prime $p$, $\\mathcal{P}^{(\\alpha)}$ repeats\nitself $3$ times in $\\mathcal{P}^{(\\alpha+1)}$, exactly as in the\n\\emph{Sierpinski's gasket}, having a pure recursive structure.\n\n\\input{Chapters/mod-p-characterization/pascal/pascal-standard-handle-negatives-centered-colouring-127-rows-mod5-partitioning-include-figure.tex}\nOn the other hand, for $p$ odd prime, $\\mathcal{P}^{(\\alpha)}$ repeats itself\nin $\\mathcal{P}^{(\\alpha+1)}$ somewhere, without a complete recursive\nstructure, due to the oddness of $p$, ie. other coloured subtriangles appears\nin $\\mathcal{P}^{(\\alpha+1)}$, see the cluster in the \\emph{top left} corner of\n\\autoref{fig:pascal:mod5:principal:cluster:for:sierpinski:proof}.\n\nHowever if we study the repetition up to row\n$2\\,p^{\\alpha}$, the proof still hold for arbitrary prime $p$.\n\n% the following paragraph should be put in a dedicated section, after this one.\n\\iffalse\n, while in general we can say that maximal\ntriangles of coefficients multiples of $p$, appear with regularity in\n$\\mathcal{P}_{n+1}$ a number of times equals to:\n\\begin{displaymath}\n    \\frac{(p-1)p}{2}\n\\end{displaymath}\nin other words, considering triangles $\\mathcal{P}_{n}$ and\n$\\mathcal{P}_{n+1}$, there are $\\frac{(p-1)p}{2}$ upside-down\nmaximal triangles, with all coefficients multiple of $p$, from row $p^n$\nto row $p^{n+1}-1$; this result will be prove at the end of this \nsection.\n\\fi\n% ----------------------------------------------------------------------\n\n\\begin{proof}\n\n  Let $\\mathcal{P}^{(\\alpha)}$ be the principal cluster of order $\\alpha$ of\n  Pascal array $\\mathcal{P}$ and let $r$ be a row index for\n  $\\mathcal{P}^{(\\alpha)}$, so $r \\in \\lbrace 0, \\ldots, p^{\\alpha} -1\n  \\rbrace$.\n    \n  Let $\\mathcal{P}_{k;\\alpha}$ be a \\emph{chunk} of $\\mathcal{P}^{(\\alpha +1)}$\n  that starts at the root and extends downward $k\\,p^{\\alpha}$ rows, therefore\n  including $\\mathcal{P}^{(\\alpha)}$ as its first rows. \n  \n  It is requested to\n  prove that coefficients at \\emph{equivalent positions} in the bottom left and\n  bottom right triangles of $\\mathcal{P}_{2;\\alpha}$ are congruent, modulo $p$,\n  to coefficients at \\emph{equivalent positions} in $\\mathcal{P}^{\\alpha}$. \n  \n  In order to formalize \\marginpar{proving congruences over coefficients at\n  equivalent positions} the concept of \\emph{equivalent positions} we\n  introduce the following objects: \n  \\begin{itemize}\n    \\item the pair $(r,c)$ of indices is an \\emph{equivalent position} \n        for coefficient $d_{rc}\\in\\mathcal{P}^{(\\alpha)}$ and coefficient \n            $d_{rc}^{\\swarrow}$ in the \\emph{bottom left} triangle of $\\mathcal{P}_{2;\\alpha}$ if and only if\n                $d_{rc}^{\\swarrow} = d_{p^{\\alpha}+r,c}$\n    \\item the pair $(r,c)$ of indices is an \\emph{equivalent position} \n        for coefficient $d_{rc}\\in\\mathcal{P}^{(\\alpha)}$ and coefficient \n            $d_{rc}^{\\searrow}$ in the \\emph{bottom right} triangle of $\\mathcal{P}_{2;\\alpha}$ if and only if\n                $d_{rc}^{\\searrow} = d_{p^{\\alpha}+r,p^{\\alpha}+c}$\n  \\end{itemize}\n  in the \\emph{top right} corner of \\autoref{fig:pascal:mod5:principal:cluster:for:sierpinski:proof},\n  equivalent position $(2,1)$ for $\\mathcal{P}_{\\equiv_{5}}^{(2)}$ are highlighted \n  for the sake of clarity.  After these definitions, we've to prove:\n  \\begin{displaymath}\n    d_{rc} \\equiv_p d_{rc}^{\\swarrow} \\equiv_p d_{rc}^{\\searrow} \n  \\end{displaymath}\n  or, in other words:\n  \\begin{displaymath}\n    {{r} \\choose {c}} \\equiv_p {{p^{\\alpha}+r} \\choose {c}} \\equiv_p {{p^{\\alpha}+r} \\choose {p^{\\alpha}+c}} \n  \\end{displaymath}\n\n  In order to prove such congruences we'll use Lucas theorem:\n  first of all, observe that $c \\leq r$ because $\\mathcal{P}^{(\\alpha)}$ \n  is a triangle, therefore $c \\in \\lbrace 0, \\ldots, p^{\\alpha} -1 \\rbrace$,\n  as $r$ satisfies.  By basis representation theorem, there exists\n  sequences $\\lbrace r_i\\rbrace$ and $\\lbrace c_i\\rbrace$, \n  with both $r_i< p$ and $c_i < p$, for $i \\in \\lbrace 0, \\ldots, p^{\\alpha} -1 \\rbrace$,\n  such that:\n  \\begin{displaymath}\n    \\begin{split}\n      r &= r_0 + r_1 p + r_2 p^2 + \\ldots + r_{{\\alpha}-1}p^{{\\alpha}-1} \\\\\n      c &= c_0 + c_1 p + c_2 p^2 + \\ldots + c_{{\\alpha}-1}p^{{\\alpha}-1} \\\\\n    \\end{split}\n  \\end{displaymath}\n  Settings for Lucas theorem are ready, hence apply it:\n  \\begin{displaymath}\n    \\begin{split}\n      {{p^{\\alpha}+r} \\choose {c}} &\\equiv_{p} {{r_0} \\choose {c_0}} {{r_1} \\choose {c_1}}{{r_2} \\choose {c_2}} \\ldots \n      {{r_{{\\alpha}-1}} \\choose {c_{{\\alpha}-1}}}{{1} \\choose {0}} \\equiv_{p} {{r} \\choose {c}}\\\\\n      {{p^{\\alpha}+r} \\choose {p^{\\alpha}+c}} &\\equiv_{p} {{r_0} \\choose {c_0}} {{r_1} \\choose {c_1}}{{r_2} \\choose {c_2}} \\ldots \n      {{r_{{\\alpha}-1}} \\choose {c_{{\\alpha}-1}}}{{1} \\choose {1}} \\equiv_{p} {{r} \\choose {c}}\\\\\n    \\end{split}\n  \\end{displaymath}\n  therefore coefficients located at \\emph{equivalent position} \n  $(r,c)$ belong to the same remainder class of congruence relation\n  modulo $p$, as required.\n  \\\\\\\\\n\n  For the second part \\marginpar{proving that a zero-hole of order $\\alpha$ \n  is surrounded within $\\mathcal{P}_{2;\\alpha}$} of the statement, we've to show that in\n  $\\mathcal{P}_{2;\\alpha}$ a zero-hole of order $\\alpha$ is\n  surrounded by the three ``congruent'' subtriangles composed of\n  coefficients $d_{rc}, d_{rc}^{\\swarrow}$ and $d_{rc}^{\\searrow} $, respectively.\n  In the \\emph{bottom left} corner of \\autoref{fig:pascal:mod5:principal:cluster:for:sierpinski:proof},\n  a zero-hole of order $1$ in $\\mathcal{P}_{2;1}$ is highlighted for the sake of clarity.\n\n  Observe that the very first coefficient $d_{p^{\\alpha}, 0}$ and very last $d_{p^{\\alpha}, p^{\\alpha}}$ of row\n  with index $p^{\\alpha}$ are congruent to the unit, modulo $p$:\n  \\begin{displaymath}\n    {{p^{\\alpha}} \\choose {0}} \\equiv_{p}{{p^{\\alpha}} \\choose {p^{\\alpha}}} \\equiv_{p} 1\n  \\end{displaymath}\n  while $p$ divides every coefficient between them, let\n  $c\\in\\lbrace1,\\ldots, p^{\\alpha}-1 \\rbrace$:\n  \\begin{displaymath}\n    {{p^{\\alpha}} \\choose {c}} \\equiv_{p} {{0} \\choose {c_0}} {{0} \\choose {c_1}}{{0} \\choose {c_2}} \\ldots \n    {{0} \\choose {c_{{\\alpha}-1}}}{{1} \\choose {0}} \\equiv_{p} 0\n  \\end{displaymath}\n  By the recurrence rule ${{n+1}\\choose {k+1}} = {{n} \\choose {k}} + {{n}\\choose{ k+1}}$\n  characterizing $\\mathcal{P}$, observe that:\n  \\begin{displaymath}\n    \\begin{split}\n      d_{p^{\\alpha}+1, 1} &\\equiv_{p} d_{p^{\\alpha}, 0} + d_{p^{\\alpha}, 1}\\equiv_{p} 1 \\\\\n      d_{p^{\\alpha}+1, p^{\\alpha}} &\\equiv_{p} d_{p^{\\alpha}, p^{\\alpha}-1} + d_{p^{\\alpha}, p^{\\alpha}}\\equiv_{p} 1 \\\\\n      d_{p^{\\alpha}+1, i} &\\equiv_{p} d_{p^{\\alpha}, i-1} + d_{p^{\\alpha}, i}\\equiv_{p} 0 \\quad \\forall i \\in \\lbrace 2, \\ldots, p^{\\alpha} -1\\rbrace \\\\\n    \\end{split}\n  \\end{displaymath}\n  therefore row $p^{\\alpha} + 1$ has one less coefficient multiple of $p$ \n  than row $p^{\\alpha}$: $\\left|\\lbrace2,\\ldots, p^{\\alpha}-1 \\rbrace\\right|=\n    \\left|\\lbrace1,\\ldots, p^{\\alpha}-1 \\rbrace\\right|-1$. \n    Since in row $p^{\\alpha}$ there are $p^{\\alpha}+1$ coefficients, where\n  $p^{\\alpha}-1$ of them are multiples of $p$, it follows that after $p^{\\alpha}-1$ \n  rows there are no such coefficients at all, that happens at row $2\\,p^{\\alpha} -1$. \n  Formally, for any column index $c$:\n  \\begin{displaymath}\n    \\begin{split}\n      {{2p^{\\alpha} - 1} \\choose {c}} &\\equiv_{p} {{p^{\\alpha} +(p^{\\alpha}- 1)} \\choose {c}} \\\\\n      &\\equiv_{p} {{p-1} \\choose {c_0}} {{p-1} \\choose {c_1}}{{p-1} \\choose {c_2}} \\ldots \n      {{p-1} \\choose {c_{{\\alpha}-1}}}{{1} \\choose {0}} \\\\\n      &\\not\\equiv_{p} 0\n    \\end{split}\n  \\end{displaymath}\n  by representing $c=(c_{0}, \\ldots,c_{\\alpha-1})_{p}$ in base $p$, where\n  $c_i \\in \\lbrace 0, \\ldots, p-1 \\rbrace$, for any $i\\in\\lbrace0,\\ldots,\\alpha-1\\rbrace$.\n\n  % the following derivation is simply a proof of coefficient extraction\n  % using the definition of Riordan array for Pascal triangle, redundant.\n  % Recall $\\mathcal{P}$ is defined as the Riordan array :\n  % \\begin{displaymath}\n  %   \\mathcal{P} = \\left(\\frac{1}{1-t}, \\frac{t}{1-t}  \\right)\n  % \\end{displaymath}\n  % hence the following derivation holds:\n  % \\begin{displaymath}\n  %   \\begin{split}\n  %     {{p^n+r} \\choose {c}} &\\equiv_p [t^{p^n +r}]\\frac{1}{1-t} \\left(\\frac{t}{1-t}\\right)^c \\\\\n  %     &\\equiv_p [t^{p^n +r-c}](1-t)^{-(c+1)} \\\\\n  %     &\\equiv_p [t^{p^n +r-c}]\\mathcal{G}\\left\\lbrace {{-(c+1)} \\choose {k}}(-1)^k \\right\\rbrace_{k\\in\\mathbb{N}} \\\\\n  %     &\\equiv_p  {{-(c+1)} \\choose {p^n +r-c}}(-1)^{p^n +r-c}  \\\\\n  %     &\\equiv_p  {{ p^n +r} \\choose {p^n +r-c}} \\left((-1)^{p^n +r-c}\\right)^2  \\\\\n  %     &\\equiv_p  {{ p^n +r} \\choose {c}}  \\\\\n  %   \\end{split}\n  % \\end{displaymath}\n\n\\end{proof}\n\n\nThe \\marginpar{for every positive $k\\in\\mathbb{N}$, no coefficient multiple of $p$ lies on row $k\\,p^{\\alpha}-1$}\nlast argument can be generalized: consider $\\mathcal{P}^{(\\alpha)}$, then every row denoted by index \n$k\\,p^{\\alpha} -1$, for each $k\\in\\mathbb{N}\\setminus\\lbrace0\\rbrace$, doesn't contain any \ncoefficient multiple of $p$. Here's a short proof:\n\\begin{displaymath}\n    \\begin{split}\n      {{kp^{\\alpha}-1} \\choose {c}} &\\equiv_{p}{{(k-1)p^{\\alpha}+ (p^{\\alpha}-1)} \\choose {c}}\\\\ \n        &\\equiv_{p} {{p-1} \\choose {c_0}} {{p-1} \\choose {c_1}} \\ldots \n      {{p-1} \\choose {c_{{\\alpha}-1}}}{{k-1} \\choose {0}} \\not\\equiv_{p} 0\n    \\end{split}\n\\end{displaymath}\nin the \\emph{bottom right} corner of \\autoref{fig:pascal:mod5:principal:cluster:for:sierpinski:proof}\nsuch rows are highlighted, where $p=5$ and $k\\in\\lbrace1,\\ldots,5\\rbrace$.\n\n% about the last proof it should be useful to build two images, where\n% some coefficients at equivalent positions are highlighted and a picture\n% that shows a triangle with a different colouring than the principal cluster\n% of one order less.\n\n\\subsection{On the number of \\emph{zero-holes} within \n    $\\mathcal{P}^{(\\alpha+1)}$}\n\nLet us finish this section proving an observation about the number\nof \\emph{maximal} zero-holes of order $\\alpha$ within a principal\ncluster $\\mathcal{P}^{(\\alpha+1)}$ of one order greater. We start with\nan important lemma that ``slices'' $\\mathcal{P}^{(\\alpha+1)}$ in strips,\neach one of them composed of $p^{\\alpha}$ rows.\n\n\\begin{lemma}\n    Let $\\mathcal{P}^{(\\alpha+1)}$ be a principal cluster of order $\\alpha+1$. \n    Denote with $\\Omega_{j}$ the range that starts at row index $j\\,p^{\\alpha}$ and stops at\n    row index $(j+1)p^{\\alpha} -1$, and with $\\mathcal{H}_{j}^{\\bigtriangledown}$ the number\n    of \\emph{maximal} zero-holes of order $\\alpha$ within $\\Omega_{j}$. \n    Then: \n    \\begin{displaymath}\n        \\mathcal{H}_{j}^{\\bigtriangledown}=j \\quad\\text{where}\\quad j\\in \\lbrace 1, \\ldots, p-1 \\rbrace\n    \\end{displaymath}\n\\end{lemma}\n\n\\begin{proof}\n    By absurd, choose any $j\\in \\lbrace 1, \\ldots, p-1 \\rbrace$ and show\n    that in range $\\Omega_{j}$ cannot be one zero-hole more \\emph{or} one zero-hole less,\n    both of order $\\alpha$: formally, $\\mathcal{H}_{j}^{\\bigtriangledown}=j\\pm1$ yields a contraddiction, \n    for any choice of $j$.\n\n    Proceed by cases:\n    \\begin{itemize}\n        \\item assume a zero-hole $h^{\\bigtriangledown}$ is missing, so there exists a coefficient\n                $\\tilde{d}_{nk}\\in h^{\\bigtriangledown}$ such that $\\tilde{d}_{nk}\\not\\equiv_{p}0$, while all \n                other coefficient $d_{nk}\\in h^{\\bigtriangledown}$ satisfies $d_{nk} \\equiv_{p}0$.\n                Proceed by cases on parity of $j$:\n            \\begin{itemize}\n                \\item $j=2k+1$ for some $k\\in\\mathbb{N}$. Without loss of generality, suppose $h^{\\bigtriangledown}$ is the one in the \n                very middle, due to symmetric shape of $\\mathcal{P}$ (the cases where it is on the left or \n                on the right are less interesting) and\n                suppose that $p$ does not divide the coefficient in the very bottom corner of $h^{\\bigtriangledown}$, \n                formally:\n                \\begin{displaymath}\n                    \\tilde{d}_{(j+1) p^{\\alpha} -2, (k+1)p^{\\alpha} -1}\\not\\equiv_{p}0\n                \\end{displaymath}\n                But this is impossible because if $d_{nk}\\in \\mathcal{P}$ \n                then $d_{nk} = d_{n-1,k-1} + d_{n-1, k}$, so:\n                \\begin{displaymath}\n                    \\begin{split}\n                        0&\\not\\equiv_{p}\\tilde{d}_{(j+1) p^{\\alpha} -2, (k+1)p^{\\alpha} -1} \\\\\n                        &\\equiv_{p} d_{(j+1) p^{\\alpha} -3, (k+1)p^{\\alpha} -1} + d_{(j+1) p^{\\alpha} -3, (k+1)p^{\\alpha}-2 }\\\\\n                        &\\equiv_{p}0\n                    \\end{split}\n                \\end{displaymath}\n                In the \\emph{top} of \\autoref{fig:pascal-mod7-zero-holes} there's a highlighted strip of rows \n                within $\\mathcal{P}_{\\stackrel{\\circ}{\\equiv_{7}}}^{(2)}$,where $j=5=2\\cdot2+1$ and $p=7$, so $k=2$\n                and $\\alpha=1$.\n                The highlighted coefficient on the very bottom is the one handled in the proof, it is \n                $\\tilde{d}_{6\\cdot 7-2, 3\\cdot 7 -1}=\\tilde{d}_{40, 20}$: to finish the proof over \n                those highlighted coefficients it necessary to use recurrence rule for binomial coefficients,\n                otherwise we cannot prove the argument using the symmetry property only. \n\n                \\item $j=2k$ for some $k\\in\\mathbb{N}$. Without loss of generality, \n                suppose  $ h^{\\bigtriangledown}$ is the one on the very left. \n                Choose $r \\in\\lbrace 0,\\ldots,p^n-2\\rbrace$, so there exists $c\\in\\lbrace r+1,\\ldots,p^n-1\\rbrace$ such that:\n                \\begin{displaymath}\n                    \\tilde{d}_{j\\,p^{\\alpha} +r, c}\\not\\equiv_{p}0\n                \\end{displaymath}\n                Since $ h^{\\bigtriangledown}$ is the only one missing, by symmetry of $\\mathcal{P}$ we get another contradiction: \n                \\begin{displaymath}\n                    0\\not\\equiv_{p}\\tilde{d}_{j\\, p^{\\alpha} +r, c} \n                        \\equiv_{p} d_{j\\, p^{\\alpha} +r, j\\, p^{\\alpha} +r-c}\\equiv_{p}0\n                \\end{displaymath}\n            \\end{itemize}\n        \\item assume triangle $ h^{\\bigtriangledown}$ is over, therefore the very first coefficient \n            $\\tilde{d}$ in the \\emph{top-left} corner of $ h^{\\bigtriangledown}$ has to satisfy:\n            \\begin{displaymath}\n                 \\tilde{d} \\equiv_{p} d_{j\\,p^{n},j\\,p^{n}+1}\n            \\end{displaymath}\n            by structure of $\\mathcal{P}$, coefficient $d_{j\\,p^{n},j\\,p^{n}+1}$ has no\n            meaning so $\\tilde{d}$ cannot satisfy the requested congruence.\n    \\end{itemize}\n\\end{proof}\n\n\\input{Chapters/mod-p-characterization/pascal/pascal-mod7-abstracting-zero-holes-include-figure}\n\n\\begin{theorem}\n    Let $\\mathcal{P}^{(\\alpha+1)}$ be a principal cluster of order $\\alpha+1$. \n    Then, within $\\mathcal{P}^{(\\alpha+1)}$ there are ${{p}\\choose{2}}$ \n    \\emph{maximal} zero-holes of order $\\alpha$. \n\\end{theorem}\n\n\\begin{proof}\n    Let $j\\in\\lbrace 1, \\ldots, p-1 \\rbrace$, by previous lemma between row index $j\\,p^n$ and\n    row index $(j+1)p^n -1$, there are $j$ \\emph{maximal} zero-holes of order $\\alpha$, \n    therefore consider the sum:\n    \\begin{displaymath}\n        \\sum_{i=1}^{p-1}{i} = \\frac{(p-1)p}{2}\n    \\end{displaymath}\n    as required.\n\n\\end{proof}\n\nIn the \\emph{bottom} of \\autoref{fig:pascal-mod7-zero-holes} \n$\\mathcal{P}_{\\stackrel{\\circ}{\\equiv_{7}}}^{(2)}$ is reported: within it there are\n${{7}\\choose{2}}=21$ zero-holes of order $1$.\n\n\n\\subsection{Congruences over antidiagonals of $\\mathcal{P}$ and $\\mathcal{P}^{-1}$}\n\nIn this section we show two results: a first one about congruences over coefficients\nlying on the same \\emph{antidiagonal}, spaced by a fixed distance; a second one\nabout a colour mapping among coefficients, in $\\mathcal{P}$ and in the inverse,\nat the same location.\n\n\n% PAY ATTENTION: the following corollary is not correct since congruences can be\n% used only in the ring of polynomials.\n\\iffalse\n\\begin{corollary}\nLet $\\mathcal{P}$ be the Pascal array and let $p$ be a prime. Choose $k\\in\\mathbb{N}$, \nthan $k$-th column is congruent to $k$-antidiagonal, modulo $p$.\n\\end{corollary}\n\\begin{proof}\n    \\begin{displaymath}\n        \\begin{split}\n            { {n} \\choose {k} } &\\equiv_{p} { {n} \\choose {n-k} } \\\\\n            d_{nk} &\\equiv_{p} d_{n,n-k}\\\\\n            \\sum_{n\\geq 0}{d_{nk} t^n} &\\equiv_{p}\\sum_{n\\geq 0}{d_{n,n-k} t^n} \\\\\n            d(t)h(t)^k &\\equiv_{p}\\sum_{n\\geq 0}{d_{n,n-k} t^n} \\\\\n        \\end{split}\n    \\end{displaymath}\nno a standard form for antidiagonal exists, so on the right we leave the explicit\nexpression for the $k$-th antidiagonal.\n\\end{proof}\n\\fi\n\nIn order to state the following lemma we define a subset of $\\mathcal{P}$\ncomposed of coefficients lying on \\emph{antidiagonals}. In the following, \ngiven $\\mathcal{P}^{(\\alpha)}$ a principal cluster of order $\\alpha$, \ndenote with $\\Theta_{\\diagdown}^{(\\alpha)}$ a set of positions, encoding\neach one of them as a pair of integers:\n\\begin{displaymath}\n    \\Theta_{\\diagdown}^{(\\alpha)}=\\left\\lbrace(n,k) : n\\in\\lbrace p^{\\alpha},\\ldots,p^{\\alpha+1}-1\\rbrace\n        \\,,k\\in\\lbrace0,\\ldots,n-p^{\\alpha}\\rbrace    \\right\\rbrace\n\\end{displaymath}\n\n\\begin{lemma}\n    Let $p$ be a prime and $\\mathcal{P}^{(\\alpha)}$ a principal cluster of order $\\alpha$.\n    Consider a position $(n,k)\\in \\Theta_{\\diagdown}^{(\\alpha)}$, then for any $\\gamma\\in\\mathbb{N}$:\n    \\begin{displaymath}\n        d_{n,k} \\equiv_{p} d_{n+\\gamma p^{\\alpha+1}, k+\\gamma p^{\\alpha+1}}\n    \\end{displaymath}\n\\end{lemma}\n\\begin{proof} % $n+\\gamma p^{m+1}$\n    By the basis representation theorem, write $n$ in base $p$ as:\n    \\begin{displaymath}\n        n = n_{0} + n_{1}p + n_{2}p^2 + \\ldots + n_{\\alpha}p^\\alpha %+ 0p^{\\alpha+1} + \\ldots + 0p^k\n    \\end{displaymath}\n    since $n<p^{\\alpha+1}$. For $k$, on the other hand, consider extrema cases:\n    \\begin{itemize}\n        \\item $n=p^{\\alpha}\\rightarrow k\\in\\lbrace0\\rbrace$\n        \\item $n=p^{\\alpha+1}-1 \\rightarrow k\\in\\lbrace 0,\\ldots,p^{\\alpha}(p-1)-1\\rbrace$\n    \\end{itemize}\n    so, for any choice of $n$, we can write $k$ in base $p$ as:\n    \\begin{displaymath}\n        k = k_{0} + k_{1}p + k_{2}p^2 + \\ldots + k_{\\alpha}p^\\alpha %+ 0p^{\\alpha+1} + \\ldots + 0p^k\n    \\end{displaymath}\n    an application of Lucas theorem finishes the proof:\n    \\begin{displaymath}\n        {{n+\\gamma p^{\\alpha+1}} \\choose { k+\\gamma p^{\\alpha+1}}} \\equiv_{p} \n            {{n_{0}} \\choose {k_{0}}}  \n            {{n_{1}} \\choose {k_{1}}} \n            {{n_{2}} \\choose {k_{2}}}\n            \\ldots\n            {{n_{\\alpha-1}} \\choose {k_{\\alpha-1}} }\n            {{n_{\\alpha}} \\choose {k_{\\alpha}} }\n            {{\\gamma} \\choose {\\gamma}} \n            \\equiv_{p}{{n} \\choose {k}}  \n    \\end{displaymath}\n    which is the requested relation.\n\\end{proof}\n\n\nPrevious lemma is important because it does hold for the inverse array $\\mathcal{P}^{-1}$ too:\n\\begin{displaymath}\n    \\begin{split}\n        \\hat{d}_{n,k} &\\equiv_{p} \\hat{d}_{n+\\gamma p^{\\alpha+1}, k+\\gamma p^{\\alpha+1}} \\\\\n        (-1)^{n-k}d_{n,k} &\\equiv_{p} (-1)^{n+\\gamma p^{\\alpha+1}-(k+\\gamma p^{\\alpha+1})}d_{n+\\gamma p^{\\alpha+1}, k+\\gamma p^{\\alpha+1}} \\\\\n        (-1)^{n-k}d_{n,k} &\\equiv_{p} (-1)^{n-k}d_{n+\\gamma p^{\\alpha+1}, k+\\gamma p^{\\alpha+1}} \\\\\n    \\end{split}\n\\end{displaymath}\nSince there exists $(-1)^{-1}\\mod p$ we can multiply by it both member $n-k$ times,\nobtaining the congruence proved in the previous lemma.\nIn \\autoref{fig:pascal-multiples-over-antidiagonal} are shown both the set\n$\\Theta_{\\diagdown}^{(1)}$ and the highlighting of congruent coefficients\naccording to previous result, within $\\mathcal{P}$ and in its inverse.\n\nPay attention: this doesn't relate coefficients\nof $\\mathcal{P}$ and $\\mathcal{P}^{-1}$ (from the colouring point of view \ndoesn't imply any relation about colours assignment: generally it is not the case,\nexcept for even $p$), it merely says that \ncongruent coefficients on the chosen antidiagonal, \\emph{in the same triangle\neither $\\mathcal{P}$ or $\\mathcal{P}^{-1}$}, repeat with structure.\n\\\\\\\\\nThe following theorem tackle what the above argument leaves out: it \nshows how to colour an antidiagonal $p^{\\alpha}$ of $\\mathcal{P}$\nhaving coloured the same antidiagonal of $\\mathcal{P}^{-1}$, and viceversa.\n\n\\input{Chapters/mod-p-characterization/pascal/multiples-over-antidiagonal-include-figure}\n\n\\begin{theorem}\n    Let $\\mathcal{P}^{(\\alpha)}$ a principal cluster of order $\\alpha$ and denote with \n    $d_{nk}, \\hat{d}_{nk}$ the generic elements in arrays $\\mathcal{P}$ and $\\mathcal{P}^{-1}$,\n    respectively. \n    Choose an odd prime $p$ and let $c\\in \\lbrace 0, \\ldots, p-1 \\rbrace$ be a remainder class\n    witness, then:\n    \\begin{displaymath}\n        \\begin{split}\n            d_{n,n-p^{\\alpha}} \\equiv_{p} c &\\leftrightarrow \\hat{d}_{n,n-p^{\\alpha}} \\equiv_{p} p-c\n        \\end{split}\n    \\end{displaymath}\n    for any $n\\geq p^{\\alpha}$.\n\\end{theorem}\n\\begin{proof}\nWe show both directions using a set of congruences: reading them from top to bottom provides a \nproof for $\\rightarrow$ direction, while reading them from bottom to top provides a proof for \n$\\leftarrow$ direction. Recall that $p^\\alpha$ is odd because $p$ is odd by hp, therefore $(-1)^{p^\\alpha} = -1$:\n\\begin{displaymath}\n    \\begin{split}\n        d_{n,n-p^{\\alpha}} &\\equiv_{p} c \\\\\n        (-1)^{p^\\alpha}\\hat{d}_{n,n-p^{\\alpha}} &\\equiv_{p} c \\\\\n        (-1)^{p^\\alpha }(-1)\\hat{d}_{n,n-p^{\\alpha}} &\\equiv_{p} -c \\\\\n        (-1)^{p^\\alpha }(-1)\\hat{d}_{n,n-p^{\\alpha}} &\\equiv_{p} p -c \\\\\n        \\hat{d}_{n,n-p^{\\alpha}} &\\equiv_{p} p -c \\\\\n    \\end{split}\n\\end{displaymath}\n\\end{proof}\n\n\\subsection{$\\equiv_{p}$ over $\\mathcal{P}$ and $\\mathcal{P}^{-1}$,\n    where $p$ \\emph{is not} a prime}\n\n\\label{subsection:pascal:congruence:characterization:p:not:prime}\n\n\\input{Chapters/mod-p-characterization/pascal/pascal-standard-ignore-negatives-centered-colouring-127-rows-multiples-of-4-partitioning-include-figure.tex}\n\nThe case when $p$ is not a prime yield coloured triangles that, nonetheless some \nrepetitive patterns appears, their shape isn't so sharp as the case when $p$ is prime.\nIn particular, $p$ can take the following forms: \n\\begin{itemize}\n    \\item $p=k^{\\alpha}$, where $k$ is a prime and $\\alpha\\in\\mathbb{N}$. This case\n        is the first step in the generalization toward congruences where the modulo \n        isn't a prime, and it is explored by \\citeauthor{mclean:1974} in \\cite{mclean:1974}.\n        In \\autoref{fig:pascal-standard-ignore-negatives-centered-colouring-127-rows-multiples-of-4-partitioning-triangle} \n        $\\mathcal{P}_{\\stackrel{\\circ}{\\equiv_{4}}}$ is shown;\n    \\item $p=p_{1}^{\\alpha_{1}}p_{2}^{\\alpha_{2}}\\ldots p_{n}^{\\alpha_{n}}$, where $p_{1},p_{2},\\ldots,p_{n}$ \n        are prime numbers and $\\alpha_{1},\\alpha_{2},\\ldots,\\alpha_{n}\\in\\mathbb{N}$. This is the most general case\n        which yield colourings that seems quite random.\n\\end{itemize}\n\n", "meta": {"hexsha": "1fcfe0da272c53f0b22fe6550240b6643b414a65", "size": 37486, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "classicthesis/Chapters/mod-p-characterization/pascal.tex", "max_stars_repo_name": "massimo-nocentini/master-thesis", "max_stars_repo_head_hexsha": "0d82bfcc82c92512d0795f286256a19f39b9b1f9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "classicthesis/Chapters/mod-p-characterization/pascal.tex", "max_issues_repo_name": "massimo-nocentini/master-thesis", "max_issues_repo_head_hexsha": "0d82bfcc82c92512d0795f286256a19f39b9b1f9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "classicthesis/Chapters/mod-p-characterization/pascal.tex", "max_forks_repo_name": "massimo-nocentini/master-thesis", "max_forks_repo_head_hexsha": "0d82bfcc82c92512d0795f286256a19f39b9b1f9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.7822045153, "max_line_length": 154, "alphanum_fraction": 0.6365309716, "num_tokens": 12817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637541053281, "lm_q2_score": 0.8267118026095992, "lm_q1q2_score": 0.7106941717945511}}
{"text": "\\section*{Exercises}\n\n% ----------------------------------------------------------------------\n\n\\begin{ex}\n  Find vector and parametric equations for the plane through the\n  points $P = (0,1,1)$, $Q = (-1,2,1)$, and $R = (1,1,2)$.\n\\end{ex}\n\n\\begin{ex}\n  Consider the following vector equation for a plane in $\\R^4$:\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x\\\\y\\\\z\\\\w \\end{mymatrix}\n    = \\begin{mymatrix}{r} 1\\\\2\\\\0\\\\0 \\end{mymatrix}\n    + t\\,\\begin{mymatrix}{r} 1\\\\0\\\\0\\\\1 \\end{mymatrix}\n    + s\\,\\begin{mymatrix}{r} -1\\\\-1\\\\1\\\\0 \\end{mymatrix}.\n  \\end{equation*}\n  Find a new vector equation for the same plane by doing the change of\n  parameters%\n  \\index{plane!change of parameters}%\n  \\index{change of parameters!plane}\n  $t=1-r_1$, $s=r_1+r_2$.\n  \\begin{sol}\n    We have\n    \\begin{equation*}\n      \\begin{mymatrix}{c} x\\\\y\\\\z\\\\w \\end{mymatrix}\n      = \\begin{mymatrix}{r} 1\\\\2\\\\0\\\\0 \\end{mymatrix}\n      + (1-r_1)\\,\\begin{mymatrix}{r} 1\\\\0\\\\0\\\\1 \\end{mymatrix}\n      + (r_1+r_2)\\,\\begin{mymatrix}{r} -1\\\\-1\\\\1\\\\0 \\end{mymatrix}\n      = \\begin{mymatrix}{r} 2\\\\2\\\\0\\\\1 \\end{mymatrix}\n      + r_1\\,\\begin{mymatrix}{r} -2\\\\-1\\\\1\\\\-1 \\end{mymatrix}\n      + r_2\\,\\begin{mymatrix}{r} -1\\\\-1\\\\1\\\\0 \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Determine which of the following points lie on the plane through the\n  points $P = (2,6,1)$, $R = (1,4,1)$, and $Q = (1,2,-1)$.\n  \\begin{enumerate}\n  \\item $S_1=(1,2,4)$.\n  \\item $S_2=(1,5,2)$.\n  \\item $S_3=(0,0,0)$.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Use cross products to find the normal vector to the plane going\n  through the points $P=(1,2,3)$, $Q=(-2,1,8)$ and $R=(2,2,2)$.\n\\end{ex}\n\n\\begin{ex}\n  Find normal and standard equations of the plane through the\n  point $P=(1,1,2)$ and orthogonal to $\\vect{n}=\\mat{1,0,-1}^T$.\n\\end{ex}\n\n\\begin{ex}\n  Find normal and standard equations for the plane through the points\n  $P = (2,1,0)$, $Q=(1,-1,0)$, and $R=(1,1,-1)$.\n\\end{ex}\n\n\\begin{ex}\n  Find a vector equation for the plane $2x+y-z=1$.\n\\end{ex}\n\n\\begin{ex}\n  The chapter mentions that the normal equation and standard equation\n  of a plane only work in $\\R^3$, and not in general $\\R^n$. Why does\n  the equation $ax+by+cz+dw=e$ not describe a plane in $\\R^4$?\n  \\begin{sol}\n    The general solution of $ax+by+cz+dw=e$ involves at least three\n    parameters.  But the vector equation of a plane only has two\n    parameters, therefore $ax+by+cz+dw=e$ does not describe a\n    plane. (It describes a $3$-dimensional so-called {\\em\n      hyperplane}%\n    \\index{hyperplane}%\n    \\index{plane!hyperplane} inside\n    $\\R^4$).\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the intersection between the planes $x+3y+4z=3$ and $2x+5y-z=2$.\n  Is the intersection a line, a plane, or empty?\n\\end{ex}\n\n\\begin{ex}\n  Find the intersection of the line\n  \\begin{equation*}\n    \\begin{mymatrix}{r} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    + t \\begin{mymatrix}{r} 2 \\\\ -1 \\\\ 2 \\end{mymatrix}\n  \\end{equation*}\n  and the plane $x+3y+z = 6$.\n  Is the intersection a point, a line, or empty?\n\\end{ex}\n\n\\begin{ex}\n  Find the angle between the planes $x+y=5$ and $2x+y-z=4$.\n\\end{ex}\n\n\\begin{ex}\n  Find the angle between the line\n  \\begin{equation*}\n    \\begin{mymatrix}{r} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{r} 0 \\\\ 3 \\\\ 7 \\end{mymatrix}\n    + t \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 4 \\end{mymatrix}\n  \\end{equation*}\n  and the plane $4x+7y+4z = 6$.\n\\end{ex}\n\n\\begin{ex}\n  In Example~\\ref{exa:angle-line-plane}, we calculated the angle\n  $\\theta$ between a line and a plane by calculating the angle $\\phi$\n  between the direction vector of the line and the normal vector of\n  the plane according to the formula\n  \\begin{equation*}\n    \\cos\\phi =\n    \\frac{\\vect{n}\\dotprod\\vect{d}}{\\norm{\\vect{n}}\\norm{\\vect{d}}}\n  \\end{equation*}\n  and then taking $\\theta = \\frac{\\pi}{2}-\\phi$.\n  \\begin{enumerate}\n  \\item Explain what happens when the dot product is negative. How\n    should we adjust the formula to ensure that $\\theta$ is always\n    between $0$ and $\\frac{\\pi}{2}$?\n  \\item Show that one can get the answer in a single step with the\n    formula\n    \\begin{equation*}\n      \\sin\\theta =\n      \\frac{\\abs{\\vect{n}\\dotprod\\vect{d}}}{\\norm{\\vect{n}}\\norm{\\vect{d}}}.\n    \\end{equation*}\n  \\end{enumerate}\n  \\begin{sol}\n    (a) If the dot product is negative, $\\phi$ will be greater than\n    $\\frac{\\pi}{2}$, and therefore $\\theta$ will end up being\n    negative. We can fix this, similarly to\n    Exercise~\\ref{ex:angle-lines}, by taking the absolute value of the\n    dot product, i.e., by solving\n    \\begin{equation}\\label{eqn:ex-angle-line-plane}\n      \\cos\\phi =\n      \\frac{\\abs{\\vect{n}\\dotprod\\vect{d}}}{\\norm{\\vect{n}}\\norm{\\vect{d}}}\n    \\end{equation}\n    (b) From trigonometry, we know that $\\sin\\theta =\n    \\sin(\\frac{\\pi}{2}-\\phi) = \\cos\\phi$. Together with\n    {\\eqref{eqn:ex-angle-line-plane}}, this gives the desired formula.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the shortest distance from the point $P = (1,1,-1)$ to the plane\n  given by $x + 2y + 2z = 6$, and find the point $Q$ on the plane\n  that is closest to $P$.\n\\end{ex}\n\n\\begin{ex}\n  Use Exercise~\\ref{exer-box-product-zero} to find an equation of a\n  plane containing the two vectors $\\vect{p}$ and $\\vect{q}$ and the\n  point $0$. \\textbf{Hint:} If $(x,y,z)$ is a point in this\n  plane, the volume of the parallelepiped determined by $(x,y,z)$\n  and the vectors $\\vect{p}$, $\\vect{q}$ equals 0.\n  \\begin{sol}\n    $\\vect{x}\\dotprod (\\vect{a}\\times \\vect{b}) =0$.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "d5c1e87ef23aebccc432d0e7ace35f42756e61ac", "size": 5570, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/LinesAndPlanes-Planes.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/LinesAndPlanes-Planes.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/LinesAndPlanes-Planes.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 33.5542168675, "max_line_length": 76, "alphanum_fraction": 0.6186714542, "num_tokens": 2048, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118068790619, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7106941680339307}}
{"text": "% !TeX root = ../main.tex\n% Add the above to each chapter to make compiling the PDF easier in some editors.\n\n\\chapter{Normal Subgroups and Quotient Groups}\nLet $(G,\\cdot)$ be a group. In this chapter we will see that the coset structure of a group can itself be represented as a group.\n\n\\begin{defn}[Normal Subgroup]\nA subgroup $N \\subgroup G$ is called \\emph{normal}\\index{normal subgroup} (denoted $N \\normal G$) if \\begin{align}\n    \\forall a \\in G.\\quad a N \\inv{a} \\subseteq N. \\label{eq:normal_subgroup}\n\\end{align}\n\\end{defn}\n\n\\begin{rmk}\\label{rmk:normal_subgroup}\nThe condition from \\cref{eq:normal_subgroup} is equivalent to, \\begin{align}\n    \\forall a \\in G.\\quad a N \\inv{a} = N.\n\\end{align}\n\\end{rmk} \\begin{proof}[Proof (sketch)]\nThis follows directly from using \\cref{eq:normal_subgroup} for $a \\in G$ and $\\inv{a} \\in G$. This yields $\\inv{a} N a \\subseteq N$. By multiplying from the left with $a$ and from the right with $\\inv{a}$, we obtain $N \\subseteq a N \\inv{a}$.\n\\end{proof}\n\n\\begin{ex}{Normal subgroups}{}\n\\begin{itemize}\n    \\item the trivial subgroups $\\{e\\}$ and $G$ are also normal, $\\{e\\}, G \\normal G$\n    \\item the \\emph{center}\\index{center}, \\begin{align}\n        Z(G) \\defeq \\{a \\in G \\mid \\forall x \\in G.\\ ax = xa\\} \\normal G,\n    \\end{align} is a normal subgroup of $G$.\n\\end{itemize}\n\\end{ex}\n\n\\begin{lem}[Sufficient Conditions for Normal Subgroups]\n\\leavevmode\\begin{lemlist}\n    \\item If $\\varphi : G \\to H$ is a homomorphism, then $\\ker{\\varphi} \\normal G$.\n    \\item Every subgroup $U \\subgroup G$ with index $\\Index{G}{U} = 2$ is a normal subgroup of $G$.\n    \\item\\label{lem:normal_subgroup_c} If $U$ is the only subgroup of order $m < \\infty$ of $G$, then $U \\normal G$.\n    \\item If $G$ is abelian, then all subgroups of $G$ are normal.\n\\end{lemlist}\n\\end{lem} \\begin{proof}[Proof (sketches)]\n\\leavevmode\\begin{lemlist}\n    \\item We have already seen in \\cref{lem:homomorphism_kernel_subgroup} that $\\ker{\\varphi} \\subgroup G$. We have, \\begin{align*}\n        \\forall a \\in G, x \\in \\ker{\\varphi}.\\quad \\varphi(a x \\inv{a}) = \\varphi(a) \\cdot \\underbrace{\\varphi(x)}_{= e_H} \\cdot \\inv{\\varphi(a)} = e_H.\n    \\end{align*} Thus, $a \\cdot \\ker{\\varphi} \\cdot \\inv{a} \\subseteq \\ker{\\varphi}$ and $\\ker{\\varphi} \\normal G$.\n    \n    \\addtocounter{lemlisti}{1}\\item For all $a \\in G$, we have $a U \\inv{a} = i_a(U)$ where $i_a$ is the inner automorphism. As automorphisms are bijective, they map a subgroup to a subgroup of the same order. Therefore, ${i_a(U) = U}$, assuming that $U$ is the only subgroup of order $m < \\infty$. Using \\cref{rmk:normal_subgroup} completes the proof.\n    \n    \\item Follows immediately from the definition of normal subgroups by applying commutativity. \\qedhere\n\\end{lemlist}\n\\end{proof}\n\n\\begin{marginfigure}\n    \\includegraphics[width=\\textwidth]{s3_subgroup_graph_index.png}\n    \\caption{Subgroup graph of the symmetric group $S_3$. The index of the subgroups is shown in orange.}\n\\end{marginfigure}\n\n\\begin{ex}{Normal subgroups (continued)}{}\n\\begin{itemize}\n    \\item $A_n \\normal S_n$ as $A_n = \\ker{\\sgn}$, see \\cref{eq:alternating_group}\n    \\item $\\SL{n}{\\R} \\normal \\GL{n}{\\R}$ as $\\SL{n}{\\R} = \\ker{\\det}$, see \\cref{eq:det_kernel}\n    \\item ${\\Inn{G} \\defeq \\{i_g \\mid g \\in G\\}}$ known as the \\emph{inner automorphism group}\\index{inner automorphism group} is a normal subgroup of the automorphism group, $\\Inn{G} \\normal \\Aut{G}$\n    \\item For the symmetric group $S_3$, we have the normal subgroups \\begin{itemize}\n        \\item $\\{e\\}, G \\normal G$\n        \\item $A_3 = \\gen{(1\\ 2\\ 3)} \\normal G$\n    \\end{itemize} by \\cref{lem:normal_subgroup_c}. Simple calculations confirm that the subgroups of order 2 are not normal.\n\\end{itemize}\n\\end{ex}\n\n\\begin{thm}[Quotient Group]\\label{thm:quotient_group}\nLet $N \\normal G$. Then the set \\begin{align}\n    \\Quot{G}{N} \\defeq \\{a N \\mid a \\in G\\}\n\\end{align} is a group under the operation, \\begin{align}\n    a N \\cdot b N \\defeq (a \\cdot b) N \\quad \\forall a, b \\in G. \\label{eq:quotient_group_op}\n\\end{align} $\\Quot{G}{N}$ is called the \\emph{quotient group}\\index{quotient group} $G$ modulo $N$.\n\\end{thm} Thus, the quotient group is the group of (left) cosets of a normal subgroup. In particular, if $G$ is finite, we have, \\begin{align}\n    |\\Quot{G}{N}| = \\Index{G}{N} = \\frac{|G|}{|N|},\n\\end{align} due to the \\hyperref[defn:index]{definition of the index} and \\hyperref[thm\"lagrange]{Lagrange's theorem}. \\begin{proof}\nIn proving that $\\Quot{G}{N}$ is a group, we will see why we need the restriction of normal subgroups.\n\n\\begin{itemize}\n    \\item First, we need to show that the group operation \\eqref{eq:quotient_group_op} is well-defined.\\footnote{By \\emph{well-defined}\\index{well-defined function}, we mean that a function maps the same input to the same output.} Let us fix $a_1, a_2, b_1, b_2 \\in G$ such that $a_1 N = a_2 N$ and $b_1 N = b_2 N$. We need to show $a_1 b_1 N = a_2 b_2 N$.\n    \n    As $N$ contains the neutral element $e$, we know $a_1 \\in a_1 N$ and $a_2 \\in a_2 N$. Therefore, $\\exists n \\in N.\\ a_1 = a_2 n$ and, analogously, $\\exists \\Tilde{n} \\in N.\\ b_1 = b_2 \\Tilde{n}$. We have, \\begin{align*}\n        a_1 b_1 = a_2 n b_2 \\Tilde{n} = a_2 b_2 (\\inv{b_2} n b_2 \\Tilde{n}).\n    \\end{align*} Using that $N$ is normal, $\\inv{b_2} n b_2 \\in N$. Then, as $N$ is a subgroup, we also have $\\inv{b_2} n b_2 \\Tilde{n} \\in N$. This shows that $a_1 b_1 N = a_2 b_2 N$.\n    \\item $e N = N$ is the neutral element.\n    \\item The group operation is closed under $\\Quot{G}{N}$ by definition.\n    \\item $\\inv{(a N)} = \\inv{a} N$ clearly is the inverse of $a N$.\n\\end{itemize} $\\implies \\Quot{G}{N}$ is a group.\n\\end{proof}\n\n\\begin{ex}{Residue classes}{}\nWe will consider the quotient group $\\Quot{\\Z}{n\\Z}$ of the group $(\\Z,+)$ for any fixed $n \\in \\NZ$. We write, \\begin{align}\n    n\\Z \\defeq \\gen{n} = \\{n \\cdot k \\mid k \\in \\Z\\}.\n\\end{align}\n\nObserve that the left cosets are of the form \\begin{align}\n    a + n\\Z = \\{a + n \\cdot k \\mid k \\in \\Z\\}.\n\\end{align} They are also called \\emph{residue classes}\\index{residue classes} modulo $n$.\n\nTo specify $\\Quot{\\Z}{n\\Z}$, we are interested in finding when ${a + n\\Z = b + n\\Z}$ holds. We have, \\begin{align}\n    a + n\\Z = b + n\\Z \\overset{\\ref{lem:cosets_eq}}{\\iff} a - b \\in n\\Z \\overset{\\ref{eq:left_coset}}{\\iff} \\divides{n}{a - b}.\n\\end{align} Equivalently to ${\\divides{n}{a - b}}$, we say that $a$ is \\emph{congruent}\\index{congruent} $b$ modulo $n$ (denoted ${a \\equiv b \\mod n}$). For ${n > 0}$ this is equivalent to $a$ and $b$ having the same residue ${r \\in \\{0, 1, \\dots, n - 1\\}}$ when dividing by $n$.\n\nFrom now on, we will assume ${n > 0}$. We denote elements by \\begin{align}\n    \\rep{a} \\defeq a + n\\Z,\n\\end{align} where $a$ is referred to as the \\emph{representative}\\index{representative} of $\\rep{a}$. It follows that, \\begin{align}\n    \\Quot{\\Z}{n\\Z} = \\{\\rep{0}, \\rep{1}, \\dots, \\rep{n-1}\\}.\n\\end{align} By \\cref{thm:quotient_group}, $\\Quot{\\Z}{n\\Z}$ with the mapping ``$+$'' is a cyclic group of order $n$. It is often denoted by \\begin{align}\n    Z_n \\defeq \\Quot{\\Z}{n\\Z} = \\gen{\\rep{1}}.\n\\end{align}\n\nAs an example, consider $Z_8 = \\{\\rep{0}, \\rep{1}, \\rep{2}, \\rep{3}, \\rep{4}, \\rep{5}, \\rep{6}, \\rep{7}\\}$. We have, \\vspace{-10pt}\\begin{itemize}\n    \\item $\\rep{2} + \\rep{5} = \\rep{7}$,\n    \\item $\\rep{2} + \\rep{6} = \\rep{8} = \\rep{0}$, and\n    \\item $\\rep{-6} = \\rep{2}$.\n\\end{itemize}\n\\end{ex}\n\n\\begin{defn}[Cokernel]\nThe \\emph{cokernel}\\index{cokernel} of a homomorphism ${\\varphi : G \\to H}$ is the quotient group $\\Quot{H}{\\im{\\varphi}}$.\n\\end{defn}\n\n\\begin{ex}{Outer automorphism group}{}\nAutomorphisms that are not inner automorphisms are called \\emph{outer automorphisms}\\index{outer automorphism}. The \\emph{outer automorphism group}\\index{outer automorphism group} is the group of cosets of the inner automorphism group with respect to outer automorphisms, \\begin{align}\n    \\Out{G} \\defeq \\Quot{\\Aut{G}}{\\Inn{G}}.\n\\end{align}\n\nLet us define the homomorphism ${\\sigma : G \\to \\Aut{G}, g \\mapsto i_g}$. It can be shown that \\vspace{-10pt}\\begin{itemize}\n    \\item $\\ker{\\sigma} = Z(G)$,\n    \\item $\\im{\\sigma} = \\Inn{G}$, and\n    \\item the cokernel of $\\sigma$ is $\\Out{G} = \\Quot{\\Aut{G}}{\\Inn{G}}$.\n\\end{itemize}\n\\end{ex}\n", "meta": {"hexsha": "ae5f86382cf2c3a0aafcd2e72c528c5d99ef8e5e", "size": 8270, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/02_normal_subgroups_and_quotient_groups.tex", "max_stars_repo_name": "jonhue/algebra", "max_stars_repo_head_hexsha": "b91da0f3fff239010d0584535f1b5f0d4f0184aa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/02_normal_subgroups_and_quotient_groups.tex", "max_issues_repo_name": "jonhue/algebra", "max_issues_repo_head_hexsha": "b91da0f3fff239010d0584535f1b5f0d4f0184aa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/02_normal_subgroups_and_quotient_groups.tex", "max_forks_repo_name": "jonhue/algebra", "max_forks_repo_head_hexsha": "b91da0f3fff239010d0584535f1b5f0d4f0184aa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.6515151515, "max_line_length": 356, "alphanum_fraction": 0.6570737606, "num_tokens": 2985, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.7106941614815772}}
{"text": "\n\\chapter{Combination of Events}\n\n\\section{Important/Useful Theorems}\n\n\\subsection{}\n\n\\begin{equation}\n\tP(A|B) = \\frac{P(AB)}{P(B)}\n\\end{equation}\n\n\\subsection{}\nIf $A = \\bigcup{}_k A_k$ where $A_k$ are all mutually exclusive\n\\begin{equation}\n\tP(A|B) = \\sum_k P(A_k|B)\n\\end{equation}\n\n\\subsection{}\nThe events $A_1, A_2, A_3, ..., A_n$ are said to be statistically independent if\n\\begin{eqnarray*}\n\tP(A_i A_j) = P(A_i)P(A_j) \\\\\n\tP(A_i A_j A_k) = P(A_i)P(A_j)P(A_k) \\\\\n\t... \\\\\n\tP(A_1 A_2 A_3...A_n) = P(A_1)P(A_2)P(A_3)...P(A_n)\n\\end{eqnarray*}\nFor all possible combinations of the indeces.\n\n\\subsection{Second Borel-Cantelli lemma}\nIf the events $A_1, A_2, A_3, ...$ are all statistically independent and $p_k = P(A_k$\n\\begin{equation}\n\t\\sum_{k=1}^\\infty p_k = \\infty\n\\end{equation}\n\n\n\\section{Answers to Problems}\n\n%answer template\n\\subsection{}\n%problem 3.1\n\nWe need to examine $A(\\bar{A}B)$ , $A \\overline{A \\cup B}$ and $(\\bar{A}B) \\overline{A \\cup B}$.\n\n\\begin{equation}\n\tA(\\bar{A}B) = A\\bar{A}B = 0\n\\end{equation}\nsince $A$ will not overlap with its complement at all\n\\begin{equation}\n\tA \\overline{A \\cup B} = A \\bar{A}\\bar{B} = 0\n\\end{equation}\nfor the same reason\n\\begin{equation}\n\t(\\bar{A}B) \\overline{A \\cup B} = \\bar{A}B \\bar{A}\\bar{B} = 0\n\\end{equation}\nagain for the same reason.\n\nClearly, since none of the three proposed events intersect at all with any of the others, these events are mutually exclusive and cannot happen in concert.\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem 3.2\nTo get $C$ to be mutually exclusive, its overlap with both $B$ and $A$ must be zero, giving a logical conclusion of:\n\n\\begin{equation}\n\tC = \\bar{A}\\bar{B}\n\\label{answer3.2}\n\nTo put it in English, the mutually exclusive outcomes of a chess match are, white wins, black wins and neither wins (a draw).\n\\end{equation}\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 3.3\n\n\n\\begin{equation}\n\tP(A|B) = \\frac{P(AB)}{P(B)} = \\frac{P(BA)}{P(B)} \\frac{P(A)}{P(A)} = P(B|A) \\frac{P(A)}{P(B)} > P(A)\n\\end{equation}\n\n\\begin{equation}\n\tP(B|A)  >  P(B)\n\\label{answer3.3}\n\\end{equation}\n\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem 3.4\n\\begin{equation}\n\tP(A|B) = \\frac{P(AB)}{P(B)} = \\frac{3}{2} P(AB)\n\\end{equation}\nWe can come up for an expression for $P(AB)$ in terms of $P(A\\cup B)$ with a little algebra.\n\\begin{equation}\n\tP(A \\cup B) = P(A) +P(B) - P(AB) = \\frac{4}{3} - P(AB)\n\\end{equation}\nclearly $P(A \\cup B)$ must be between 0 and 1.\n\\begin{equation}\n\t 1 \\geq \\frac{4}{3} - P(AB) \\geq 0\n\\end{equation}\n\\begin{equation}\n\t -\\frac{1}{3} \\geq - P(AB) \\geq -\\frac{4}{3}\n\\end{equation}\n\\begin{equation}\n\t \\frac{1}{3} \\leq  P(AB) \\leq \\frac{4}{3}\n\\end{equation}\n\\begin{equation}\n\t \\frac{1}{3} \\leq  \\frac{2}{3} P(A|B) \\leq \\frac{4}{3}\n\\end{equation}\n\\begin{equation}\n\t \\frac{1}{2} \\leq  P(A|B) \\leq 2\n\\end{equation}\n\\begin{equation}\n\t\\frac{1}{2} \\leq  P(A|B)\n\\label{answer3.4}\n\\end{equation}\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 3.5\n\n\\begin{equation}\n\tP(A)P(B|A)P(C|AB) = P(A)\\frac{P(BA)}{P(A)} \\frac{P(ABC)}{P(AB)} = P(ABC)\n\\end{equation}\nSimple enough, but now we need a general theorem\n\\begin{equation}\n\tP\\left(  \\bigcap_{k=1}^n A_k  \\right) = P(A_1)P(A_2|A_1)P(A_3|A_1A_2)P(A_4|A_1A_2A_3) ... P\\left(A_n| \\bigcap_{k=1}^{n-1} A_k  \\right)\n\\end{equation}\n\n\\begin{equation}\n\tP\\left(  \\bigcap_{k=1}^n A_k  \\right) = P(A_1) \\prod_{z=2}^n} P\\left(A_z| \\bigcap_{k=1}^{z-1} A_k  \\right)\n\\label{answer3.5}\n\\end{equation}\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 3.6\n\\begin{equation}\n\tP(A) = P(A|B) +  P(A|\\bar{B}) = \\frac{P(AB)}{P(B)} + \\frac{P(A\\bar{B})}{P(\\bar{B})}\n\\end{equation}\n\n\\subsubsection{$A=0$}\n\\begin{equation}\n\tP(0) = \\frac{P(0)}{P(B)} + \\frac{P(0)}{P(\\bar{B})} = 0\n\\end{equation}\nBecause the intersection with nothing is nothing.\n\n\n\\subsubsection{$B=0$}\n\\begin{equation}\n\tP(A) = \\frac{P(0)}{P(0)} + \\frac{P(A\\Omega)}{P(\\Omega)} = P(A)\n\\end{equation}\n\n\\subsubsection{$B=\\Omega$}\n\\begin{equation}\n\tP(A) = \\frac{P(A\\Omega)}{P(\\Omega)} + \\frac{P(0)}{P(0)} = P(A)\n\\end{equation}\n\n\n\\subsubsection{$B=A$}\n\\begin{equation}\n\tP(A) = \\frac{P(AA)}{P(A)} + \\frac{P(A\\bar{A})}{P(\\bar{A})} = 1 ???\n\\end{equation}\nI cannot prove this to be true\n\n\\subsubsection{$B=\\bar{A}$}\n\\begin{equation}\n\tP(A) = \\frac{P(A\\bar{A})}{P(\\bar{A})} + \\frac{P(AA)}{P(A)} = 1 ???\n\\end{equation}\nI cannot prove this to be true\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 3.7\nWe start knowing:\n\\begin{equation}\n\tP(AB) = P(A)P(B)\n\\end{equation}\nBut we want to prove:\n\\begin{equation}\n\tP(\\bar{A}\\bar{B}) = P(\\bar{A})P(\\bar{B})\n\\end{equation}\nas the problem suggests\n\\begin{equation}\n\tP(B|A) + P(\\bar{B}|A) = 1\n\\end{equation}\n\\begin{equation}\n\t\\frac{P(BA)}{P(A)} + \\frac{P(A\\bar{B})}{P(A)} = 1\n\\end{equation}\n\\begin{equation}\n\tP(B) + \\frac{P(A\\bar{B})}{P(A)} = 1\n\\end{equation}\n\\begin{equation}\n\t\\frac{P(A\\bar{B})}{P(A)} = 1 - P(B)\n\\end{equation}\n\\begin{equation}\n\tP(A\\bar{B}) = \\left(1 - P(B)\\right)P(A)\n\\end{equation}\n\\begin{equation}\n\tP(A\\bar{B}) = P(\\bar{B})P(A)\n\\end{equation}\nso clearly $A \\text{ and } \\bar{B}$ are independent.  Since we have just proved that for two events that are independent, we can show that one of the events is independent of the others complement, without loss of generality, we can apply this logic recursively, thus proving that if two events are independent, so are their complements.\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 3.8\nGiven two mutually exclusive events, we wonder if they are dependent.  \n\\begin{equation}\n\tP(AB) = 0\n\\end{equation}\nbut in order for them to be independent, we need to be able to say\n\\begin{equation}\n\tP(AB) = P(A)P(B)\n\\end{equation}\nbut we were told that $P(A)$ and $P(B)$ are positive, therefore they are \\textbf{NOT} independent!\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 3.9\nLet $A_i$ be the event of getting a white ball at the $i^{th}$ urn.   Since there are 2 possibilities for each step, there are $2^n$ different ways to do this ``experiment''.  Clearly\n\\begin{equation}\n\tP(A_1) = \\frac{w}{w+b}\n\\end{equation}\nbut things get more complicated as $i>1$.  Here there are two mutually exclusive possibilities: we got a white one or we got a black one from the first urn.  \n\\begin{equation}\n\tP(A_2) = P(A_2|A_1)P(A_1) + P(A_2|\\bar{A_1})P(\\bar{A_1})\n\\end{equation}\n\\begin{equation}\n\tP(A_2) = P(A_2A_1) + P(A_2\\bar{A_1})\n\\end{equation}\nFor both denominators, there were $w+b$ possibilities to begin with and $w+b+1$ for the second.   Then, there were $w$ ways to get white first and $b$ ways to get black first.  Then, respectively, there would be $w+1$ ways and $w$ ways to get white for the second urn. \n\n\\begin{equation}\n\tP(A_2) = \\frac{1}{(w+b)(w+b+1)} \\left( w(w+1) + bw \\right)\n\\end{equation}\n\\begin{equation}\n\tP(A_2) = \\frac{w(w+b+1)}{(w+b)(w+b+1)} = \\frac{w}{w+b}\n\\end{equation}\n\nSince we started off with $\\frac{w}{w+b}$ and then got the same answer for the second step, if we were to do it for a third step, a fourth step, etc. we would be starting with the same initial conditions and would get the same answer therefore this is true in general for $n$ urns.\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 3.10\nLabelling the points starting from the left, we know that\n\\begin{eqnarray}\n\tP(C_1|B_1) = \\frac{1}{3} = P(C_2|B_1) \\\\\n\tP(C_3|B_2) = \\frac{1}{2} \\\\\n\tP(C_4|B_4) = \\frac{1}{5} = P(C_5|B_4) = P(C_6|B_4)\n\\end{eqnarray}\nSince there's only one way to get to each of these specified end-points, the total probabilities are just the conditional probabilities times the probabilities of the conditions.\n\\begin{eqnarray}\n\tP(C_1) = P(C_1|B_1)P(B_1) = \\frac{1}{12} = P(C_2) \\\\\n\tP(C_3) = P(C_3|B_2)P(B_2) = \\frac{1}{8} \\\\\n\tP(C_4) = P(C_4|B_4)P(B_4) = \\frac{1}{20} = P(C_5) = P(C_6)\n\\end{eqnarray}\nSo when we combine all these possibilities with the probability of getting to $A$:\n\\begin{equation}\n\t\\frac{67}{120} + \\frac{2}{12} + \\frac{1}{8} + \\frac{3}{20} = 1\n\\label{answer3.10}\n\\end{equation}\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem 3.11\nLet's go from 1 dollar stakes to $q$ dollar stakes; all the other variables stay the same.\n\n\\begin{equation}\n\tp(x) = \\frac{1}{2} \\left[  p(x+q) + p(x-q)  \\right], q \\leq x \\leq m - q\n\\end{equation}\nbut the boundary conditions do not change.  Therefore, there is no change here between the original linear equation and the new linear equation.  Thus:\n\\begin{equation}\n\tp(x) = 1 - \\frac{x}{m}\n\\label{answer3.11}\n\\end{equation}\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem 3.12\n\\begin{equation}\n\tP(B|A) = P(B | \\bar{A}) \n\\end{equation}\nbut let's work on the assumption they are not independent\n\\begin{eqnarray*}\n\t\\frac{P(AB)}{P(A)} = \\frac{P(\\bar{A}B)}{\\bar{A}} \\\\\n\t\\frac{P(AB)}{P(\\bar{A}B)} = \\frac{P(A)}{P(\\bar{A})}\n\\end{eqnarray*}\nbut now let's factor out the expression for the intersection, leaving some error behind\n\\begin{eqnarray*}\n\t\\frac{P(A)P(B)\\epsilon}{P(\\bar{A})P(B)\\epsilon{}'} = \\frac{P(A)}{P(\\bar{A})} \\\\\t\n\t\\frac{P(A)\\epsilon}{P(\\bar{A})\\epsilon{}'} = \\frac{P(A)}{P(\\bar{A})}\n\\end{eqnarray*}\nThe only way for this to always be true is for both error terms to be the same and the only way for it to be true for arbitrary events is for them to both be one such that $A$ and $B$ are independent.\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 3.13\nThere are four mutually exclusive outcomes for the first step: getting two whites, one white and zero whites($A_2, A_1, A_0$).  We'll call the last event we want to turn out white, $B$.\n\\begin{equation}\n\tP(B) = P(B|A_2)P(A_2) + P(B|A_1)P(A_1) + P(B|A_0)P(A_0)\n\\end{equation}\n\n\\begin{eqnarray}\n\tP(B|A_2)P(A_2) =  1 \\frac{w_1 w_2}{(w_1 + b_1)(w_2 + b_2)}\\\\\n\tP(B|A_1)P(A_1) = \\frac{1}{2} \\frac{w_1 b_2 + w_2 b_1}{(w_1 + b_1)(w_2 + b_2)} \\\\\n\tP(B|A_0)P(A_0) = 0\n\\end{eqnarray}\nputting it together\n\\begin{eqnarray}\n\tP(B) = \\frac{1}{2} \\frac{w_1 b_2 + w_2 b_1 + 2 w_1 w_2}{(w_1 + b_1)(w_2 + b_2)}  \\\\\n\tP(B) = \\frac{1}{2} \\frac{(w_1 +b_1 )w_2 + (w_2 + b_2) w_1 }{(w_1 + b_1)(w_2 + b_2)}  \\\\\n\tP(B) = \\frac{1}{2} \\left( \\frac{w_1}{w_1+b_1} + \\frac{w_2}{w_2+b_2} \\right)\n\\end{eqnarray}\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 3.14\nAs the hint suggests, we'll use Bayes' Rule.  Our set of mutually exclusive events $\\{ B_i\\}$ are the getting of the ball from the $i^{th}$ urn and $A$ is the event of getting a white ball.  So we want the probability of choosing the odd urn out (we'll call it $B_k$) given that we got a white ball.\n\n\\begin{equation}\n\tP(B_k|A) = \\frac{P(B_k)P(A|B_k)}{\\sum_{i=1}^{10} P(B_i)P(A|B_i}\n\\end{equation}\nFor all $i$, $P(B_i) = \\frac{1}{10}$ and for $i \\neq k$ $P(A|B_i) = \\frac{1}{2}$ but for $i=k$,  $P(A|B_k) = \\frac{5}{6}$\n\\begin{equation}\n\tP(B_k|A) = \\frac{\\frac{5}{6 \\cdot 10}}{9\\frac{1}{20} + \\frac{5}{6 \\cdot 10}} = \\frac{5}{32}\n\\end{equation}\n\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem 2.15\nTo do this problem, let's figure out what the chance is that we picked the all-white urn, the event $B_1$. $A$ is the event we pick a white ball and $B_@$ is the event of picking the other urn with $\\frac{3}{4}$ white balls.\n\n\\begin{equation}\n\tP(B_1|A) = \\frac{P(B_1)P(A|B_1)}{P(B_1)P(A|B_1) + P(B_2)P(A|B_2)} = \\frac{\\frac{1}{2}}{\\frac{1}{2} + \\frac{1}{2} \\frac{3}{4}} = \\frac{4}{7}\n\\end{equation}\nThus, there is a $\\frac{3}{7}$ chance we chose the urn that actually has black balls in it and a $\\frac{1}{4}$ chance that from that urn once chooses a black ball giving an overall probability of picking a black ball given the information in the problem of $\\frac{3}{28}$.\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem 2.16\n\\textbf{SKIPPED}: unsure of meaning of problem.\n\n\\subsection{}\n%problem 2.17\nClearly $P(A) = \\frac{1}{2} = P(B) = P(C)$ and $P(AB) = \\frac{1}{4} = P(BC) = P(AC)$ because there is only one place out of four for the die to hit both letters.  There is, however, still only one way to hit all three letters at once such that $P(ABC)=\\frac{1}{4}$ therefore  the events in question are pairwise independent since for all sets of letters $P(AB)=P(A)P(B)$ but not completely independent since $P(ABC) \\neq P(A)P(B)P(C)$.\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 2.18\n\n\\textbf{SKIPPED}: didn't feel like doing the problem... so there.\n\n\n\n%%answer template\n%\\subsection{}\n%%problem n.n\n%\n%\n%\\begin{equation}\n%\t\n%\\label{answern.n}\n%\\end{equation}\n%\\textbf{Answer [not] verified}\n\n\n\n\n\n", "meta": {"hexsha": "e9f4a4d54894284785960887df7442c588523416", "size": 12291, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter3.tex", "max_stars_repo_name": "stefk/Rozanov_ptcc_solutions", "max_stars_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter3.tex", "max_issues_repo_name": "stefk/Rozanov_ptcc_solutions", "max_issues_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter3.tex", "max_forks_repo_name": "stefk/Rozanov_ptcc_solutions", "max_forks_repo_head_hexsha": "8af26b1cea3966df11a8ecfc5b2b1b95a784d2c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6021220159, "max_line_length": 435, "alphanum_fraction": 0.6608087218, "num_tokens": 4778, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8596637523076224, "lm_q1q2_score": 0.7106941556271563}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\hyphenation{SWPWRI}\n\\begmath 17.1 Computation Using Derivative Arrays or\n\\hbox{Univariate Taylor Series}\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nThis set of subroutines performs computations using arrays of length N+1,\nwhere each array contains the value of a function, $f(t)$, and its first N\nderivatives with respect to $t$, evaluated at some point, $t_0$. Such an\narray can alternatively be regarded as a scaled representation of the first\nN + 1 coefficients of the Taylor series of $f(t)$ expanded at $t_0$, since\nthe coefficient of $(t-t_0)^k$ in such a Taylor series is $f^{(k)}(t)/k!$\nevaluated at $t_0.$\n\nThis package provides a way of computing values of the first N derivatives\nof a univariate function that is defined by a sequence of computational\nsteps involving arithmetic and elementary functions, without the need to\nderive and code expressions for the derivatives.\n\n\\subsection{Usage}\n\nWe shall use $t$ as the generic name of the single independent variable with\nrespect to which all derivatives are defined. We shall use the term\nW-variable to denote an (N+1)-tuple, consisting of a function value and\nvalues of the function's first N derivatives with respect to $t$, evaluated\nat some point. Note that the representation of $t$ as a W-variable evaluated\nat $t_0$ is the (N+1)-tuple, $(t_0$, 1, 0, 0, ...,~0).\n\nThis package consists of one subroutine, SWSET, for assigning a value to a\nW-variable, 22~subroutines for doing arithmetic operations and computing\nelementary functions using W-variables, and three supplementary subroutines,\nSWCHN, SWRCHN, and SPASCL. These will be described in the following sections:\n\n\\begin{tabular*}{3.3in}{@{}l@{~~}l}\nB.1 & SWSET\\dotfill \\pageref{B1}\\\\\nB.2 & Arithmetic and elementary functions\\dotfill \\pageref{B2}\\\\\nB.3 & SWCHN\\dotfill \\pageref{B3}\\\\\nB.4 & SWRCHN\\dotfill \\pageref{B4}\\\\\nB.5 & SPASCL\\dotfill \\pageref{B5}\\\\\nB.6 & Modifications for double-precision usage\\dotfill \\pageref{B6}\\\\\n & \\rule{3in}{0pt}~\n\\end{tabular*}\\vspace{-5pt}\n\n\\subsubsection{SWSET, Assigning a value to a W-variable\\label{B1}}\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf N}\n\n\\item[REAL]  \\ {\\bf VAL, DERIV, W}($\\geq $N+1)\n\\end{description}\n\nAssign values to N, VAL, and DERIV\n$$\n\\fbox{{\\bf CALL SWSET(N, VAL, DERIV, W)}}\n$$\nComputed quantities are returned in W().\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[N]  \\ [in] Highest order derivative to be considered. Require 0 $\\leq $\nN $\\leq $ NMAX. See Section E for the definition of NMAX.\n\n\\item[VAL]  \\ [in] Value to be assigned to the W-variable, W().\n\n\\item[DERIV]  \\ [in] Value to be assigned as the first derivative of the\nW-variable, W().\n\n\\item[W()]  \\ [out] Array of length at least N + 1 in which this subroutine\nwill place N + 1 values to represent a W-variable as follows: (VAL, DERIV,\n0.0, ..., 0.0). The user should set DERIV = 1.0 to define this variable as\nthe variable, $t$, with respect to which all differentiation is done. The\nuser can set DERIV = 0.0 to define this W-variable to be a constant, $i.e$.\na variable not depending on $t.$\n\\end{description}\n\n\\subsubsection{Arithmetic and elementary functions using W-variables\\label{B2}}\n\nIn describing the following subroutines, X() and Y() denote input\nW-variables and Z() denotes an output W-variable. The variables A and I are\ninput variables that are constant relative to $t.$\n\nIn most of these subroutines the output array Z() must occupy storage\nlocations distinct from any of the input data. Exceptions to this rule are\nSWSUM, SWDIF, SWPRO, SWSUM1, SWDIF1, and SWPRO1. The subroutine SWQUO, which\ncomputes $x/y \\rightarrow z$, permits $x$ and $z$ to occupy the same\nstorage, but $y$ and $z$ must occupy distinct storage.\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf N, I}\n\n\\item[REAL]  \\ {\\bf A, X}($\\geq $N+1){\\bf , Y}($\\geq $N+1){\\bf , Z}($\\geq $%\nN+1)\n\\end{description}\n\nAssign values to N, I, A, X(), and Y(), as appropriate.\n\n\\begin{center}\n{\\bf Two-argument operations with both arguments depending on $t.$}\n\n\\fbox{\\begin{tabular}{@{\\bf \\ }lr}\nCALL SWSUM(N, X, Y, Z) & $x+y \\rightarrow z$\\\\\nCALL SWDIF(N, X, Y, Z) & $x-y \\rightarrow z$\\\\\nCALL SWPRO(N, X, Y, Z) & $x\\times y \\rightarrow z$\\\\\nCALL SWQUO(N, X, Y, Z) & $ x/y \\rightarrow z$\\\\\nCALL SWATN2(N, X, Y, Z) &  atan2($x,y) \\rightarrow z$\\\\\n\\multicolumn{2}{c}{where for atan2: \\ $-\\pi < z \\leq \\pi $ and\n$\\tan (z) = x/y$}\\\\\n\\end{tabular}}\n\\end{center}\n\n\\pagebreak\n\n\\begin{center}\n{\\bf Two-argument operations with only one argument depending on $t.$}\n\n\\fbox{\\begin{tabular}{@{\\bf \\ }lr}\nCALL SWSUM1(N, A, Y, Z) & $ a+y \\rightarrow z$\\\\\nCALL SWDIF1(N, A, Y, Z) & $ a-y \\rightarrow z$\\\\\nCALL SWPRO1(N, A, Y, Z) & $ a\\times y \\rightarrow z$\\\\\nCALL SWQUO1(N, A, Y, Z) & $ a/y \\rightarrow z$\\\\\nCALL SWPWRI(N, I, Y, Z) & $ y^i \\rightarrow z$\\\\\n\\multicolumn{2}{c}{(See following note.)}\\\\\n\\end{tabular}}\n\\end{center}\n\nNote: I may be positive, negative, or zero. If I = 0, SWPWRI sets Z(1) = 1.0\nand all derivative values of $z$ to~0.0, regardless of the given value of $y$%\n. It is an error to have $y = 0.0$ when I $< 0.$\n\n\\begin{center}\n{\\bf One-argument operations with the argument depending on $t.$}\n\n\\fbox{\\begin{tabular}{@{\\bf \\ }lr}\nCALL SWSQRT(N, X, Z) &  $\\sqrt x \\rightarrow z$\\\\\nCALL SWEXP(N, X, Z) & $\\exp (x) \\rightarrow z$\\\\\nCALL SWLOG(N, X, Z) & $\\log (x) \\rightarrow z$\\\\\nCALL SWSIN(N, X, Z) & $\\sin (x) \\rightarrow z$\\\\\nCALL SWCOS(N, X, Z) & $\\cos (x) \\rightarrow z$\\\\\nCALL SWTAN(N, X, Z) & $\\tan (x) \\rightarrow z$\\\\\nCALL SWASIN(N, X, Z) & $\\sin^{-1}(x) \\rightarrow z$\\\\\nCALL SWACOS(N, X, Z) & $\\cos^{-1}(x) \\rightarrow z$\\\\\nCALL SWATAN(N, X, Z) & $\\tan^{-1}(x) \\rightarrow z$\\\\\nCALL SWSINH(N, X, Z) & $\\sinh(x) \\rightarrow z$\\\\\nCALL SWCOSH(N, X, Z) & $\\cosh(x) \\rightarrow z$\\\\\nCALL SWTANH(N, X, Z) & $\\tanh(x) \\rightarrow z$\\\\\n\\end{tabular}}\n\\end{center}\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[N]  \\ [in] Highest order derivative to be considered. Require 0 $\\leq $\nN $\\leq $ NMAX. See Section E for the definition of NMAX.\n\n\\item[A]  \\ [in] Floating point value that is independent of $t.$\n\n\\item[I]  \\ [in] Integer value that is independent of $t.$\n\n\\item[X()]  \\ [in] An input W-variable.\n\n\\item[Y()]  \\ [in] An input W-variable.\n\n\\item[Z()]  \\ [out] An output W-variable.\n\\end{description}\n\n\\subsubsection{SWCHN, application of the chain rule\\label{B3}}\n\nThis subroutine is called by all of the elementary function subroutines. The\nuser will not need to call it directly unless the user is developing a new\nfunction subroutine that is not conveniently representable in terms of the\navailable functions.\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf N}\n\n\\item[REAL]  \\ {\\bf X}($\\geq $N+1){\\bf , F}($\\geq $N+1)\n\\end{description}\n\nAssign values to N, X(), and F().\n$$\n\\fbox{{\\bf CALL SWCHN(N, X, F)}}\n$$\nComputed quantities are returned in F().\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[N]  \\ [in] Highest order derivative to be considered. Require 0 $\\leq $\nN $\\leq $ NMAX. See Section E for the definition of NMAX.\n\n\\item[X()]  \\ [in] On entry, X() must contain $x(t_0)$ and derivatives\nthrough order N of $x(t)$ with respect to $t$. X() will be unchanged by this\nsubroutine.\n\n\\item[F()]  \\ [inout] On entry, F() must contain $f(x_0)$ and derivatives\nthrough order N of $f(x)$ with respect to $x$, evaluated at $x_0=x(t_0)$. On\nreturn F() will contain $f(x(t_0))$ and derivatives through order N of $%\nf(x(t))$ with respect to $t$, evaluated at $t_0$. Note that the contents of\nF(1) will remain unchanged.\n\\end{description}\n\n\\subsubsection{SWRCHN, application of the reverse chain rule\\label{B4}}\n\nThis subroutine reverses the action of SWCHN, in the sense that if one were\nto make the two calls\n\nCALL SWCHN(N, X, F)\n\nCALL SWRCHN(N, X, F)\n\nthe first would transform the contents of the array F(), and the second\nwould (if X(2) is nonzero) transform the contents of F() back to the same\nvalues (to within computational errors) as before the first call. See\nSection C for application of SWRCHN to series reversion.\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf N}\n\n\\item[REAL]  \\ {\\bf X}($\\geq $N+1){\\bf , F}($\\geq $N+1)\n\\end{description}\n\nAssign values to N, X(), and F().\n$$\n\\fbox{{\\bf CALL SWRCHN(N, X, F)}}\n$$\nComputed quantities are returned in F().\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[N]  \\ [in] Highest order derivative to be considered. Require 0 $\\leq $\nN $\\leq $ NMAX. See Section E for the definition of NMAX.\n\n\\item[X()]  \\ [in] On entry, X() must contain $x(t_0)$ and derivatives\nthrough order N of $x(t)$ with respect to $t$. X(2), representing $dx/dt$\nevaluated at $t_0$, must be nonzero. The contents of X(1) will not be used\nby this subroutine. X() will be unchanged by this subroutine.\n\n\\item[F()]  \\ [inout] On entry, F() must contain $f(x(t_0))$ and derivatives\nthrough order N of $f(x(t))$ with respect to $t$, evaluated at $t=t_0$. On\nreturn F() will contain $f(x_0)$ and derivatives through order N of $f(x)$\nwith respect to $x$, evaluated at $x_0=x(t_0)$. Note that the contents of\nF(1) will remain unchanged.\n\\end{description}\n\n\\subsubsection{SPASCL, computation of the ``Pascal triangle\" of binomial\ncoefficients\\label{B5}}\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf N}\n\n\\item[REAL]  \\ {\\bf C}($\\geq $ 1 + (N*(N+1))/2)\n\\end{description}\n\nAssign a value to N.\n$$\n\\fbox{{\\bf CALL SPASCL(N, C)}}\n$$\nComputed quantities are returned in C().\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[N]  \\ [in] Highest order derivative to be considered. Require 0 $\\leq $\nN $\\leq $ NMAX. See Section E for the definition of NMAX.\n\n\\item[C()]  \\ [out] On return will contain values constituting the ``Pascal\ntriangle'' of binomial coefficients. For example, if N = 4, the Pascal\ntriangle is\n\\end{description}\n\n\\begin{center}\n\\begin{tabular}{c}\n1\\\\\n1\\ \\ \\ 1\\\\\n1\\ \\ \\ 2\\ \\ \\ 1\\\\\n1\\ \\ \\ 3\\ \\ \\ 3\\ \\ \\ 1\\\\\n1\\ \\ \\ 4\\ \\ \\ 6\\ \\ \\ 4\\ \\ \\ 1\n\\end{tabular}\n\\end{center}\n\nSPASCL omits the first element of each row except the first, and thus\nreturns the 11~values: 1, 1, 2, 1, 3, 3, 1, 4, 6, 4,~1.\n\n\\subsubsection{Modifications for Double Precision\\label{B6}}\n\nFor double-precision usage, replace the initial S in the name of each\nsubroutine with D, and replace the REAL declarations by DOUBLE PRECISION.\n\n\\subsection{Examples and Remarks}\n\nAs a demonstration problem, consider the following assignments:\n\n\\begin{tabbing}\n\\hspace{.2in}\\=$t$ = 2\\\\\n\\>$z_1$ = log(sqrt($t$))\\\\\n\\>$z_2$ = exp(2 * $z_1$)\\\\\n\\>$d$ = $z_2$ - $t$\n\\end{tabbing}\n\nThis should result in $z_2 = t$ and $d = 0$. These quantities and their\nderivatives through order~3 with respect to $t$ are computed by the program\nDRDCOMP. The results are shown in ODDCOMP. Note that $d$ and all of its\nderivatives are zero to machine accuracy, as they should be.\n\nThe running time for this package is approximately proportional to $\\text{N}%\n^3$. To save time when developing new code using this package, one may run\nwith N = 0 until one is satisfied that the function evaluation is as\ndesired, and then increase N to activate the derivative computation.\n\n\\subparagraph{Implicit functions and series reversion}\n\nLet $[x;t]$ denote a W-variable containing $x$ and all of its derivatives\nthrough order N with respect to $t$, evaluated at $t_0$. Let $x_0 = x(t_0)$.\nSuppose one would like to have $[t;x]$. This would represent the inverse\nfunction that is defined implicitly by $[x;t]$. When the components of these\narrays are interpreted as scaled coefficients of Taylor series the\ntransformation from $[x;t]$ to $[t;x]$ is known as series reversion.\n\nThe subroutine SWRCHN can be used to produce $[t;x]$. Note, from the\nspecifications in Section B.4, that given $[x;t]$ and $[f;t]$, SWRCHN\ntransforms $[f;t]$ to $[f;x]$. Formally replacing the symbol $f$ by $t$, we\nsee that given $[x;t]$ and $[t;t]$, SWRCHN transforms $[t;t]$ to $[t;x]$,\nthus producing the desired object. Note that the W-variable, $[t;t]$, needed\nas part of the input, is just $(t_0$, 1, 0, ..., 0).\n\n\\subsection{Functional Description}\n\nThe ``W\" in the names of subroutines in this package refers to R.  E.\nWengert, who, in \\cite{Wengert:1964:ASA}, presented the ideas on which the\npackage is based.  Subsequent authors have incorporated this approach into\nmore automated systems \\cite{Griewank:1991:ADA} that would probably be\neasier to use than the present package, but such systems present various\nhurdles regarding acquisition and installation.  The present\nimplementation provides the basic capabilities in a highly portable form.\n\nThe fundamental idea is simply to provide, for each basic mathematical\noperation, code that not only performs the operation but propagates\nderivative values up to the desired order. For example, to support the sine\nfunction with derivatives through second degree, we note that if\n\n\\begin{tabbing}\n\\hspace{.4in}\\=$z = \\sin y,$\\\\\nthen\\\\\n\\>$z'= y' \\cos y,$\\\\\nand\\\\\n\\>$z''= y'' cos y - {y'}^2 \\sin y,$\n\\end{tabbing}\n\nwhere the primes denote derivatives with respect to an independent variable,\n$t$. Clearly these formulas permit one to write a subroutine that can accept $%\ny$, $y^{\\prime}$, and $y^{\\prime \\prime}$ as input, and\nproduce $z$, $z^{\\prime}$, and $z^{\\prime \\prime}$\nas output.\n\nThis approach has been systematized for arbitrary N by appropriate use of\nthe chain rule of differentiation. Our subroutine SWCHN implements the chain\nrule as\n\n\\begin{tabbing}\n\\hspace{.2in}\\=do L = 0, N $-$ 1\\\\\n\\>\\ \\ \\ \\ call SWPRO(L, F(N+1$-$L), X(2), F(N+1$-$L))\\\\\n\\>enddo\n\\end{tabbing}\n\nSince SWCHN is called by all of the elementary function subroutines, this\nloop essentially determines the dependence on N of the running time of the\nwhole package. SWPRO is an $O(\\text{N}^2)$ process and SWCHN is an $O(\\text{N%\n}^3)$ process. To improve efficiency we have coded the cases of N = 0, 1, 2,\n3, and~4 as special cases in SWPRO. Multiplication counts in SWPRO and SWCHN\nare as follows:\n\n\\begin{tabular}{@{\\ \\ }r@{\\ \\ }r@{\\ \\ }r@{\\ \\ }r@{\\ \\ }r@{\\ \\ }r@{\\ \\ }r@{\\ \\ }r@{\\ \\ }r@{\\ \\ }r@{\\ \\ }r@{\\ \\ }r@{\\ \\ }}\nN $\\Rightarrow$ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\\\\\nSWPRO & 1 & 3 & 7 & 12 & 19 & 27 & 37 & 48 & 61 & 75 & 91\\\\\nSWCHN & 0 & 1 & 4 & 11 & 23 & 42 & 69 & 106 & 154 & 215 & 290\n\\end{tabular}\n\\nocite{Lawson:1971:CDU}\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\n\\subsubsection{Upper limit on the derivative order, N}\n\nSubroutines SWATAN, SWSUM, and SWPRO in this package contain internal arrays\nwhose dimensions depend on NMAX. NMAX is a PARAMETER in each of these\nsubroutines, nominally set to~10. This limits the derivative order argument,\nN, in all of the subroutines to~10. The user would need to increase NMAX in\nthese three subroutines if higher order derivatives are needed.\n\n\\subsubsection{Invalid arguments for derivative computation}\n\nThe user will likely be accustomed to avoiding sending invalid arguments to\nthe elementary functions, such as a negative argument to the square root. In\ncomputing derivatives there are some additional singularities to avoid. Note\nthat the derivative is infinite at zero for the square root, and at $\\pm 1$\nfor arcsin and arccosine.\n\n\\subsubsection{Error handling}\n\nFollowing is a list of error conditions the package detects and for which\nerror messages are issued. These errors are fatal in the sense that the\nrequested operation cannot be done; however, the default action is to return\nafter issuing an error message. The user can use the MATH77 library\nsubroutine, ERMSET of Chapter~19.2, to alter this action to cause a STOP\nif desired. Error conditions not on this list, $e.g.$, negative argument\nin log, will be handled by the usual host system error handler.\n\n\\begin{tabular}{@{}l@{\\ \\ }l}\n\\bf Error No.\\\\\n\\bf \\& Program & \\multicolumn{1}{c}{\\bf Explanation}\\\\\n\\bf 1 SWASIN & Infinite derivative when arg = $-$1 or +1\\\\\n\\bf 1 SWACOS & Infinite derivative when arg = $-$1 or +1\\\\\n\\bf 2 SWSQRT & Infinite derivative when arg = 0\\\\\n\\bf 3 SWQUO1 & Zero divisor\\\\\n\\bf 4 SWPWRI & Y**I is infinite when Y = 0 and I $< 0$\\\\\n\\bf 5 SWPRO & Require dimension NMAX $\\geq $ N\\\\\n\\bf 6 SWQUO & Require dimension NMAX $\\geq $ N\\\\\n\\bf 7 SWQUO & Zero divisor.\\\\\n\\bf 8 SPASCL & Require N $\\geq 0$\\\\\n\\bf 9 SWRCHN & Require X($2) \\neq 0.$\n\\end{tabular}\n\n\\subsection{Supporting Information}\n\nThe source language is ANSI Fortran~77.\n\nAll of the double precision entry points require files:\n\nDWCOMP, ERFIN, ERMSG, IERM1, IERV1.\n\nFor single precision, file SWCOMP is required in place of file DWCOMP.\n\\vspace{-5pt}\n\\begin{center}\n\\begin{tabular}{llll}\n\\multicolumn{4}{c}{\\bf Entries} \\\\\nDPASCL & DWACOS & DWASIN & DWATAN\\\\\nDWATN2 & DWCHN & DWCOS & DWCOSH\\\\\nDWDIF & DWDIF1 & DWEXP & DWLOG\\\\\nDWPRO & DWPRO1 & DWPWRI & DWQUO\\\\\nDWQUO1 & DWRCHN & DWSET & DWSIN\\\\\nDWSINH & DWSQRT & DWSUM & DWSUM1\\\\\nDWTAN & DWTANH & SPASCL & SWACOS\\\\\nSWASIN & SWATAN & SWATN2 & SWCHN\\\\\nSWCOS & SWCOSH & SWDIF & SWDIF1\\\\\nSWEXP & SWLOG & SWPRO & SWPRO1\\\\\nSWPWRI & SWQUO & SWQUO1 & SWRCHN\\\\\nSWSET & SWSIN & SWSINH & SWSQRT\\\\\nSWSUM & SWSUM1 & SWTAN & SWTANH\\\\\n\\end{tabular}\n\\end{center}\n\nDesigned by C. L. Lawson, JPL, 1971. Adapted to Fortran~77 for the JPL\nMATH77 library, Aug.~1987.\n\n\n\\begcodenp\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSWCOMP}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{swcomp}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSWCOMP}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{swcomp}}\n\\end{document}\n", "meta": {"hexsha": "55d9abf4dce98d22b255ca23864cb2ca7f634c9b", "size": 17883, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch17-01.tex", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "doc/doctex/ch17-01.tex", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "doc/doctex/ch17-01.tex", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 36.7207392197, "max_line_length": 120, "alphanum_fraction": 0.7027344405, "num_tokens": 5743, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236824, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.710694154399621}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage[english]{babel}\n\\usepackage[utf8x]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage[colorinlistoftodos]{todonotes}\n\n\\title{MATH 542 Homework 2}\n\\author{Saket Choudhary\\\\skchoudh@usc.edu}\n\n\\begin{document}\n\\maketitle \n\\section*{Problem 1}\n$$ A=\\begin{pmatrix} A_{11} & A_{12}\\\\ \nA_{21} & A_{22}\n\\end{pmatrix} $$Consider $C=A^{-1}$ so that $CA=I$\n\n$$\nC = \\begin{pmatrix} C_{11} & C_{12}\\\\ C_{21} & C_{22}\\end{pmatrix}\n$$\n\\begin{align*}\nCA &= \\begin{pmatrix} A_{11}C_{11}+A_{12}C_{21} & A_{11}C_{12}+A_{12}C_{22}\\\\  \nA_{21}C_{11}+A_{22}C_{21} & A_{21}C_{12}+A_{22}C_{22}\n\\end{pmatrix}\\\\\n&= \\begin{pmatrix} I_k &  O_{n-k} \\\\ O_{n-k} & I_{k} \\end{pmatrix}\n\\end{align*}\nThus,\n\\begin{align*}\nA_{11}C_{11}+A_{12}C_{21} &=  I_k\\\\\nA_{11}C_{12}+A_{12}C_{22} &= O_{n-k}\\\\\nA_{21}C_{11}+A_{22}C_{21} &= O_{n-k}\\\\\nA_{21}C_{12}+A_{22}C_{22}&=I_k \n\\end{align*}\n\nThus,\n\n\\begin{align*}\nC_{11}&= -A_{11}^{-1}(I-A_{12}C_{21})\\\\\nC_{12} &= -A_{11}^{-1}A_{12}C_{22}\\\\ \nC_{21} &= -A_{22}^{-1}A_{21}C_{11}\\\\\nC_{22}&=A_{22}^{-1}(I-A_{21}C_{12})\n\\end{align*}\n\nSubstituting for $C_{12}$ and $C_{21}$ :\n\n\n\\begin{align*}\nA_{11}C_{11}-A_{12}A_{22}^{-1}A_{21}C_{11} &= I_k\\\\\n\\implies C_{11} &= (A_{11}-A_{12}A_{22}^{-1}A_{21})^{-1}\n\\end{align*}\n\nSimilarly,\n\\begin{align*}\n-A_{21}A_{11}^{-1}A_{12}C_{22}+A_{22}C_{22} &= I_k\\\\\nC_{22} &=  (A_{22}-A_{21}A_{11}^{-1}A_{12})^{-1}\\\\\n&=B\n\\end{align*}\nThus, \n\\begin{align*}\nB &= (A_{22}-A_{21}A_{11}^{-1}A_{12})\\\\\nC_{11} &=(A_{11}-A_{12}A_{22}^{-1}A_{21})^{-1} \\\\\nC_{21}&= -A_{22}^{-1}A_{21}(A_{11}-A_{12}A_{22}^{-1}A_{21})^{-1}\\\\\nC_{22}&= (A_{22}-A_{21}A_{11}^{-1}A_{12})^{-1} = B^{-1}\\\\\nC_{12} &= -A_{11}^{-1}A_{12}C_{22}\\\\\n\\end{align*}\n\nNow we use Woodbury matrix identity $(A+UCV )^{-1}= A^{-1}-A^{-1}U(C^{-1}+VA^{-1}U)^{-1}VA^{-1}$\n\nUsing which, \\begin{align*}\nC_{11} &= (A_{11}-A_{12}A_{22}^{-1}A_{21})^{-1}\\\\ \n&= A_{11}^{-1}-A_{11}^{-1}(-A_{12})(A_{22}^{-1} + -A_{21}A_{11}^{-1}A_{12} )^{-1}A_{21}A_{11}^{-1}\\\\  \n&= A_{11}+A_{11}^{-1}A_{12}B^{-1}A_{21}A_{11}^{-1}\n\\end{align*}\n\n\\begin{align*}C_{12} &= -A_{11}^{-1}A_{12}C_{22}\\\\\n&= -A_{12}^{-1}A_{12}B^{-1} \\end{align*}\n\n\\subsection*{Problem 1.b}\nFor this part we substitute $k=1$  \n\\begin{align*}\nB_{1 \\times 1} &= a_{22}-a_{12}'A_{11}^{-1}a_{12}\\\\\nC_{11} &= A_{11}+A_{11}a_{12}B^{-1}a_{21}'A_{11}^{-1}\\\\\nC_{12}&=-A_{11}^{-1}a_{12}B^{-1}\\\\ \nC_{21}&= -B^{-1}a_{12}'A_{11}^{-1}\\\\\nC_{22}&=B^{-1}\\\\\n\\end{align*}\n\n\n\\section*{Problem 2}\n\n\\subsection*{Problem 2.a}\n\n$X'X = \\begin{pmatrix}2J & J  & J \\\\ J & J & 0 \\\\ J & 0 & J  \\end{pmatrix} = J \\begin{pmatrix} 2 & 1 &1\\\\ 1 & 1 & 0 \\\\ 1 & 0 & 1 \\end{pmatrix}$\n\n\\subsection*{Problem 2.b}\n$X'X$ is not invertible( Perform $C1-C3$)\n\n$(X'X) \\times (X'X)_1^{-} =J \\begin{pmatrix} 2 & 1 &1\\\\ 1 & 1 & 0 \\\\ 1 & 0 & 1 \\end{pmatrix} \\times XX_1^- = \\begin{pmatrix}1 & 0 & 0\\\\ 0 & 1 & 0\\\\ 1& -1 & 0 \\end{pmatrix}$ \n\nAlso, $(X'X) \\times (X'X)_2^{-} =J \\begin{pmatrix} 2 & 1 &1\\\\ 1 & 1 & 0 \\\\ 1 & 0 & 1 \\end{pmatrix} \\times XX_2^- = \\begin{pmatrix} 0 & 0 & 1\\\\ 0 & 1 & 0\\\\ 0 & 0 & 1 \\end{pmatrix}$ \n\\subsection*{Problem 2.c}\n\n$P = X(X'X)_1^-X' = \\begin{pmatrix}2 & 1 & 1\\\\ 1 & 1 & 0\\\\ 1 & 0 & 1 \\end{pmatrix}=X(X'X)_2^-X'= X'X$\nand thus P is unique\n\n\\section*{Problem 3}\n\n$$\nX = \\begin{pmatrix} \n1 & -1 & 1\\\\\n-1 & 0 & 2\\\\\n1 & 1 & 1\\\\\n\\end{pmatrix}\n$$Consider $X^T = \\begin{pmatrix} \n1 & -1 & 1\\\\\n-1 & 0 & 1\\\\\n1 & 2 & 1\\\\\n\\end{pmatrix}$\n\nFinding the inverse gives $X^{-1} =   \\begin{pmatrix} \n1 & -1 & 1\\\\\n-1 & 0 & 2\\\\\n1 & 1 & 1\\\\\n\\end{pmatrix}$\nIn fact $X^TX = \\begin{pmatrix}3 & 0 & 0\\\\ \n0 & 2 & 0\\\\\n0 & 0 & 6\\\\\n\\end{pmatrix}$and $XX^T = \\begin{pmatrix}3 & 1 & 1\\\\ 1 & 5 & 1\\\\ 1 & 1 &3\n\\end{pmatrix}$\n\nClearly $X^T \\neq X^{-1}$ and this leads us to conclude that $X$ is \\textbf{not} an orthonormal matrix.\n\n$$\nC = \\begin{pmatrix} 1/\\sqrt{3} & -1/\\sqrt{2} & 1/\\sqrt{6}\\\\\n-1/\\sqrt{3} & 0/\\sqrt{2} & 2/\\sqrt{6}\\\\\n1/\\sqrt{3} & 1/\\sqrt{2} & 1/\\sqrt{6}\n\\end{pmatrix}\n$$\n$$\nC^T = \\begin{pmatrix} 1/\\sqrt{3} & -1/\\sqrt{3} & 1/\\sqrt{3}\\\\\n-1/\\sqrt{2} & 0/\\sqrt{2} & 1/\\sqrt{2}\\\\\n1/\\sqrt{6} & 2/\\sqrt{6} & 1/\\sqrt{6}\n\\end{pmatrix}\n$$\nThus, $$CC^T = C^TC = I_3 \\text{ (Skipped calculations, did in R)}$$ \n\n\n\n\n\n\n\n\n\\section*{Problem 4}\n\n\\subsection*{Problem 4.a}\n\nUsing the property $\\det(XY) = \\det(X) \\times \\det(Y)$  we have $\\det(A^2) =  \\det(A)\\times \\det(A) = (\\det(A))^2$\n\n\\subsection{Problem 4.b}\n\n$A = P\\Lambda P^T$ such that $\\Lambda$ is a diagonal matrix with its diagonals as the eigen values and $P$ is an orthonormal matrix thus, $PP^T=I$ and $\\det(P) = +1\\ or\\-1$ \n\n$\\det(A) = \\det(P\\Lambda P^T)= \\det(P) \\det(\\Lambda) \\det(P^T) = \\det(\\Lambda) \\det(P)^2 = \\det(\\Lambda) = \\prod \\lambda_i$ \nUsing $tr(AB) = tr(BA)$\n$tr(A) = tr(P\\Lambda P^T) = tr(\\lambda P^T P) = tr(\\Lambda \\times I) = tr(\\Lambda) = \\sum \\lambda_i$ \n\n\n\\end{document}", "meta": {"hexsha": "cd226777d80849318f7d9c6548b3bc3dffb72d18", "size": 4793, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016_Spring/MATH-542/HW02/hw02.tex", "max_stars_repo_name": "NeveIsa/hatex", "max_stars_repo_head_hexsha": "c5cfa2410d47c7e43a476a8c8a9795182fe8f836", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2015-09-10T02:45:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T03:20:47.000Z", "max_issues_repo_path": "2016_Spring/MATH-542/HW02/hw02.tex", "max_issues_repo_name": "NeveIsa/hatex", "max_issues_repo_head_hexsha": "c5cfa2410d47c7e43a476a8c8a9795182fe8f836", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-09-16T23:11:00.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-23T21:21:52.000Z", "max_forks_repo_path": "2016_Spring/MATH-542/HW02/hw02.tex", "max_forks_repo_name": "saketkc/hatex", "max_forks_repo_head_hexsha": "c5cfa2410d47c7e43a476a8c8a9795182fe8f836", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-09-25T19:06:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T03:21:09.000Z", "avg_line_length": 28.1941176471, "max_line_length": 180, "alphanum_fraction": 0.5457959524, "num_tokens": 2380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.78793120560257, "lm_q1q2_score": 0.7106514522474904}}
{"text": "% $Id$\n%\n% Author: David Fournier\n% Copyright (c) 2008 Regents of the University of California\n%\n\n\\section{Truncated linear regression}\n\nThe linear regression model we consider here has the form\n$$Y_i=\\sum_{j=1}^m a_j x_{ij} +\\epsilon_i$$\nwhere the $Y_i$ for $i=1,\\ldots,n$ are the $n$ observations\nand the $a_j$ are $m$ parameters to be estimated.  \nThe $\\epsilon_i$ are assumed to be normally distributed random \nvariables with mean $0$ and variance $v$.\n\nLet $r_i=Y_i-\\sum_{j=1}^m a_j x_{ij}$. The log-likelihood function \nfor the standard regression model is given by\n$$ -.5n\\log(v) - \\sum_{i=1}^n  \\frac{r_i^2 }{ 2v}$$\nNow assume that we only consider the $Y_i$ for $Y_i \\ge 0$,\ni.e., the left truncated situation.\nThe probability that $Y_i\\ge 0$ is equal to the probability that\n$\\epsilon_I>-\\sum_{j=1}^m a_j x_{ij} $. This is equal to \n$1-\\Phi(-\\sum_{j=1}^m a_j x_{ij} /v)$, where\n$$\\Phi(u)=\\frac{1}{\\sqrt{2\\pi}}\\int_{-\\infty}^u \\exp \\left(-t^2/2 \\right)\\,\\textrm{d}t$$\nFor this truncated regression, the log-likelihood function\nhas the logarithm of this quantity subtracted from it,\nso it becomes \n$$ -.5n\\log(v) - \\sum_{i=1}^n  \\frac{r_i^2 }{ 2v}\n   -\\log\\Bigg(1-\\Phi \\bigg(-\\sum_{j=1}^m a_j x_{ij} /v \\bigg)\\Bigg)$$\nIf instead we consider the right truncated case, where only the $Y_i<0$\nare considered, the log-likelihood function becomes\n$$ -.5n\\log(v) - \\sum_{i=1}^n    \\frac{r_i^2 }{ 2v}\n   -\\log\\Bigg(\\Phi \\bigg(-\\sum_{j=1}^m a_j x_{ij} /v \\bigg)\\Bigg)$$\n \nTo parameterize $v$, we introduce a new parameter $a$ satisfying\nthe condition $v=a\\hat v$, where \n$\\hat v=\\frac{1}{ n}\\sum_{i=1}^n  r_i^2$ is the usual maximum likelihood\nestimate for $v$. This leads to more\nnumerically stable behavior. In terms of $a$, the \nexpression for the log-likelihood simplifies to\n$$ -.5n\\log(a)-.5n\\log(\\hat v) - \\frac{n}{ 2a}\n   -\\log\\Bigg(1-\\Phi \\bigg(-\\sum_{j=1}^m a_j x_{ij}/(a \\hat v)\\bigg)\\Bigg)$$\n   \n   \n\\section{The \\ADM\\ truncated\\br regression program}\n\nHere are the contents of the file \\texttt{truncreg.tpl}:\n\\begin{lstlisting}\nDATA_SECTION\n  init_int nobs\n  init_int m\n  init_int trunc_flag\n  init_matrix data(1,nobs,1,m+1)\n  vector Y(1,nobs)\n  matrix X(1,nobs,1,m)\n LOC_CALCS\n  Y=column(data,1);\n  for (int i=1;i<=nobs;i++)\n  {\n    X(i)=data(i)(2,m+1).shift(1);\n  }\nPARAMETER_SECTION\n  sdreport_number sigma\n  number vhat\n  init_bounded_number log_a(-5.0,5.0);\n  sdreport_number a\n  init_vector u(1,m)\n  objective_function_value f\nPROCEDURE_SECTION\n  a=exp(log_a);\n  dvar_vector pred=X*u;\n  dvar_vector res=Y-pred;\n  dvariable r2=norm2(res); \n  vhat=r2/nobs; \n  dvariable v=a*vhat;\n  sigma=sqrt(v);\n\n  dvar_vector spred=pred/sigma;\n  f=0.0;\n  switch (trunc_flag)\n  {\n  case -1:  // left_truncated\n    {\n      for (int i=1;i<=nobs;i++)\n      {\n        f+=log(1.00001-cumd_norm(-spred(i)));\n      }\n    }\n    break;\n  case 1:   // right truncated\n    {\n      for (int i=1;i<=nobs;i++)\n      {\n        f+=log(0.99999*cumd_norm(-spred(i)));\n      }\n    }\n    break;\n  case 0:   // no truncation\n    break;\n  default:\n    cerr << \"Illegal value for truncation flag\" << endl;\n    ad_exit(1);\n  }\n  f+=0.5*nobs*log(v)+0.5*r2/v;\n\n\nREPORT_SECTION\n  report << \"#u \" << endl << u << endl;\n  report << \"#sigma \" << endl << sigma << endl;\n  report << \"#a \" << endl << a << endl;\n  report << \"#vhat \" << endl << vhat << endl;\n  report << \"#shat \" << endl << sqrt(vhat) << endl;\n\n\\end{lstlisting}\n\n\n\n\n", "meta": {"hexsha": "2c320efe46772884802ff2bf087ecac4e0b8708b", "size": 3401, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/manuals/admb/truncreg.tex", "max_stars_repo_name": "wStockhausen/admb", "max_stars_repo_head_hexsha": "876ec704ae974d0ed3bcc329f243dbc401ad0e6d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 79, "max_stars_repo_stars_event_min_datetime": "2015-01-16T14:14:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T06:28:15.000Z", "max_issues_repo_path": "docs/manuals/admb/truncreg.tex", "max_issues_repo_name": "wStockhausen/admb", "max_issues_repo_head_hexsha": "876ec704ae974d0ed3bcc329f243dbc401ad0e6d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 172, "max_issues_repo_issues_event_min_datetime": "2015-01-21T01:53:57.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T19:57:31.000Z", "max_forks_repo_path": "docs/manuals/admb/truncreg.tex", "max_forks_repo_name": "wStockhausen/admb", "max_forks_repo_head_hexsha": "876ec704ae974d0ed3bcc329f243dbc401ad0e6d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 22, "max_forks_repo_forks_event_min_datetime": "2015-01-15T18:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-11T21:47:51.000Z", "avg_line_length": 28.5798319328, "max_line_length": 88, "alphanum_fraction": 0.6398118201, "num_tokens": 1231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192066862062, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7106514352927027}}
{"text": "\\section{Matrix arithmetic modulo \\texorpdfstring{$p$}{p}}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Perform matrix operations over the field $\\Z_p$.\n  \\end{enumerate}\n\\end{outcome}\n\nIn Section~\\ref{sec:fields}, you learned that most of linear algebra\ncan be done over scalars from any field $K$, and not just the real\nnumbers. You also learned that $\\Z_p$, the set of integers modulo $p$,\nis a field whenever $p$ is a prime number.\n\nIndeed, all of the operations on matrices that we covered in this\nchapter make sense over any field: addition, scalar multiplication,\nmatrix multiplication, inverses, elementary matrices, and the\ntranspose.\n\n\\begin{example}{A matrix product over $\\Z_5$}{matrix-product-z5}\n  Compute the matrix product $AB$ over the field $\\Z_5$, where\n  \\begin{equation*}\n    A = \\begin{mymatrix}{ccc}\n      1 & 0 & 4 \\\\\n      2 & 3 & 1 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    B = \\begin{mymatrix}{cc}\n      3 & 1 \\\\\n      4 & 0 \\\\\n      2 & 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  For example, the $(1,1)$-entry of $AB$ is calculated by multiplying\n  the first row of $A$ by the first column of $B$, i.e.,\n  \\begin{equation*}\n    c_{11} ~=~ 1\\cdot 3+0\\cdot 4 + 4\\cdot 2 ~=~ 3 + 0 + 3 ~=~ 1,\n  \\end{equation*}\n  keeping in mind that all arithmetic operations are done in $\\Z_5$.\n  We repeat the same for the other entries and obtain\n  \\begin{equation*}\n    AB ~=~\n    \\begin{mymatrix}{ccc}\n      1 & 0 & 4 \\\\\n      2 & 3 & 1 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{cc}\n      3 & 1 \\\\\n      4 & 0 \\\\\n      2 & 2 \\\\\n    \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{cc}\n      1 & 4 \\\\\n      0 & 4 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{An inverse over $\\Z_7$}{matrix-inverse-z7}\n  Compute the inverse of the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{ccc}\n      1 & 4 & 2 \\\\\n      0 & 6 & 2 \\\\\n      5 & 0 & 3 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  with scalars in the field $\\Z_7$.\n\\end{example}\n\n\\begin{solution}\n  We use exactly the method of\n  Algorithm~\\ref{algo:matrix-inversion-algorithm}, i.e., we set up the\n  augmented matrix $\\mat{A\\mid I}$ and reduce it to {\\rref}. The only\n  thing we have to keep in mind is that all operations are done modulo\n  $7$. Also, as usual, instead of dividing by a scalar, we must\n  multiply by its inverse.\n  \\begin{eqnarray*}\n    \\mat{A\\mid I}\n    &=&\n        \\begin{mymatrix}{ccc|ccc}\n          1 & 4 & 2  &  1 & 0 & 0 \\\\\n          0 & 6 & 2  &  0 & 1 & 0 \\\\\n          5 & 0 & 3  &  0 & 0 & 1 \\\\\n        \\end{mymatrix}\n    \\\\\n    &\\stackrel{R_3\\rowop R_3+2R_1}{\\roweq}\n      &\n        \\begin{mymatrix}{ccc|ccc}\n          1 & 4 & 2  &  1 & 0 & 0 \\\\\n          0 & 6 & 2  &  0 & 1 & 0 \\\\\n          0 & 1 & 0  &  2 & 0 & 1 \\\\\n        \\end{mymatrix}\n    \\\\\n    &\\stackrel{R_2\\rowswap R_3}{\\roweq}\n      &\n        \\begin{mymatrix}{ccc|ccc}\n          1 & 4 & 2  &  1 & 0 & 0 \\\\\n          0 & 1 & 0  &  2 & 0 & 1 \\\\\n          0 & 6 & 2  &  0 & 1 & 0 \\\\\n        \\end{mymatrix}\n    \\\\\n    &\\stackrel{R_3\\rowop R_3+R_2}{\\roweq}\n      &\n        \\begin{mymatrix}{ccc|ccc}\n          1 & 4 & 2  &  1 & 0 & 0 \\\\\n          0 & 1 & 0  &  2 & 0 & 1 \\\\\n          0 & 0 & 2  &  2 & 1 & 1 \\\\\n        \\end{mymatrix}\n    \\\\\n    &\\stackrel{R_3\\rowop 2^{-1}R_3 ~=~ 4R_3}{\\roweq}\n      &\n        \\begin{mymatrix}{ccc|ccc}\n          1 & 4 & 2  &  1 & 0 & 0 \\\\\n          0 & 1 & 0  &  2 & 0 & 1 \\\\\n          0 & 0 & 1  &  1 & 4 & 4 \\\\\n        \\end{mymatrix}\n    \\\\\n    &\\stackrel{R_1\\rowop R_1-4R_2}{\\roweq}\n      &\n        \\begin{mymatrix}{ccc|ccc}\n          1 & 0 & 2  &  0 & 0 & 3 \\\\\n          0 & 1 & 0  &  2 & 0 & 1 \\\\\n          0 & 0 & 1  &  1 & 4 & 4 \\\\\n        \\end{mymatrix}\n    \\\\\n    &\\stackrel{R_1\\rowop R_1-2R_3}{\\roweq}\n      &\n        \\begin{mymatrix}{ccc|ccc}\n          1 & 0 & 0  &  5 & 6 & 2 \\\\\n          0 & 1 & 0  &  2 & 0 & 1 \\\\\n          0 & 0 & 1  &  1 & 4 & 4 \\\\\n        \\end{mymatrix}.\n  \\end{eqnarray*}\n  Therefore, the inverse is\n  \\begin{equation*}\n    A^{-1} =\n    \\begin{mymatrix}{ccc}\n      5 & 6 & 2 \\\\\n      2 & 0 & 1 \\\\\n      1 & 4 & 4 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  As usual, we can double-check that we didn't make any mistakes by\n  calculating\n  \\begin{equation*}\n    AA^{-1} ~=~\n    \\begin{mymatrix}{ccc}\n      1 & 4 & 2 \\\\\n      0 & 6 & 2 \\\\\n      5 & 0 & 3 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{ccc}\n      5 & 6 & 2 \\\\\n      2 & 0 & 1 \\\\\n      1 & 4 & 4 \\\\\n    \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{ccc}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & 0 & 1 \\\\\n    \\end{mymatrix}\n    ~=~ I.\n  \\end{equation*}\n  So indeed, we have calculated the inverse correctly.\n\\end{solution}\n", "meta": {"hexsha": "e74435c62c2cea131d5dcaab7cfa0c319ad21e15", "size": 4671, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-MatrixArithmeticModP.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-MatrixArithmeticModP.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-MatrixArithmeticModP.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 27.3157894737, "max_line_length": 70, "alphanum_fraction": 0.5058873903, "num_tokens": 1862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.7106514347872596}}
{"text": "\\section{Introduction}\nWe are going to analyse the ring of $p$-adic integers $\\hat{\\zz}_p$ for a given prime number $p \\geq 2$. To establish this algebraic ring, there are several possibilities.\n\\subsection{Basic ring theory}\nFor clarity, we are going to repeat some important definitions of ring theory. We make usage of categorical notations as found in (Strickl. 2000, Formal groups and formal group laws).\n\\subsubsection{Rings and prime ideals}\nWe call a set $R$ a ring if it is an abelian group $(R,m_+,0,S_-)$ with structure maps\n$$\\bao{rrcl}\n+ :& R \\times R&\\longrightarrow& R\\\\\n&(r,s) &\\longmapsto&r + s\\\\\n&&&\\\\\n0 :& \\ast & \\longrightarrow&R\\\\\n&x&\\longmapsto&0\\\\\n&&&\\\\\n- :& R &\\longrightarrow&R\\\\\n&r &\\longmapsto&-r\\\\\n\\ea$$\nand $(R,m_\\cdot)$ is a semigroup such that the following diagram commutes:\n$$\\bao{cc}\\xymatrix{\nR^4 \\ar[rrr]^{id_R \\times \\tau_{R^2} \\times id_R} &&& R^4 \\ar[d]^{m_\\cdot \\times m_\\cdot}&\\\\\nR^3 \\ar[d]_{id_R \\times m_+} \\ar[u]^{\\Delta \\times id_{R^2}} &&&R^2\\ar[d]^{m_+}\\\\\nR^2\\ar[rrr]^{m_\\cdot}&&&R\\\\\n} & \\bao{c}\n\\trm{where}\\bao{rrcl}\n\\Delta : & R & \\longrightarrow& R^2\\\\\n&r&\\longmapsto&(r,r)\\\\\n&&&\\\\\n\\tau_{R^2} :& R^2 &\\longrightarrow&R^2\\\\\n&(r,s)&\\longmapsto&(s,r).\\\\\n\\ea\\ea\n\\ea$$\nThis is just a rephrasing of distributivity. Clearly, $m_+$ and $m_\\cdot$ are addition and multiplication, $S$ is the additive inversion and $0$ is the zero map. If no ambiguity can occur, we simply use the standard symbols for those operation maps.  Let $(R,+_R, 0_R, -_R,\\cdot_S)$ and $(S,+_S,0_S,-_S,\\cdot_S)$ be two rings. We call a map $f : R \\longrightarrow S$ a ring homomorphism if\n$$\\xymatrix{\nR^2 \\ar[r]^{f \\times f} \\ar[d]_m & R^2\\ar[d]^m\\\\\nR \\ar[r]_{f}&R\\\\\n}$$\ncommutes for both operation maps $+, \\cdot : R^2 \\longrightarrow R$. The class of all rings forms a category with morphisms called ring homomorphisms. We call a ring unital, if there is a map $1 : \\ast \\longrightarrow R, x \\longmapsto 1$ such that $(R,\\cdot,1)$ is a monoid. Again, if no ambiguity can arise we simply denote a ring by its set. For a unital ring $R$, we denote by $R^\\times$ the group of units:\n$$R^\\times := \\{x \\in R : \\exists y \\in R, x y = 1\\} = \\pi_1(\\mathcal{M}_1),$$\n$$\\ \\pi_1 : R \\times R \\longrightarrow R, (r,s) \\longmapsto r\\ \\trm{and}\\ \\mathcal{M}_1 := \\{(x,y) \\in R^2 : x y = 1\\}.$$\n\\subsubsection{Modules and ideals}\n\\indent For a ring $R$, we call an abelian group $(M,+_M,0_M,-_M)$ an left $R$-module if there is a map \n$m_\\cdot : R \\times M \\longrightarrow M$ such that both diagrams\n$$\\bao{c}\n\\xymatrix{\nR^4 \\times M^2 \\ar[rrr]^{id_{R^2} \\times \\tau_{R^2 \\times M} \\times id_{M^2}}& && (R^2 \\times M)^2 \\ar[d]^{+_R \\times id_M \\times +_R \\times id_M}\\\\\nR^2 \\times M^2 \\ar[d]_{+_R \\times +_M} \\ar[u]^{\\Delta_{R^2} \\times id_{M^2}} &&&(R \\times M)^2\\ar[d]^{m_+}\\\\\nR\\times M\\ar[rrr]^{m_\\cdot}&&&M\\\\\n}\\\\\n\\xymatrix{\nR^2 \\times M \\ar[r]^{id_R \\times m_\\cdot} \\ar[d]_{\\cdot_R \\times id_M} & R \\times M\\ar[d]^{m_\\cdot}\\\\\nR \\times M \\ar[r]_{m_\\cdot} &M\\\\\n}\n\\ea$$\ncommute. We remark that the first diagram represents distributivity in both, $R$ and $M$. The latter represents the successive scalar multiplication commutes with multiplication of $R$ (i.e. $m_\\cdot(r,m_\\cdot(s,m)) = m_\\cdot(rs, m)$). The map $m_\\cdot$ is called the outer left product or scalar left multiplication. Similarily, we define a right $R$-module for $m_\\cdot : M \\times R \\longrightarrow M$. An $R$-submodule $N$ of $M$ is a subset that is itself a module (i.e. the restrictions of the structure maps have images in product sets of $N$). The class of $R$-modules forms a category, with $R$-linear maps as morphisms.\n\\paragraph{Ideal}\nAn ideal $I \\subset R$ is simply an $R$-submodule of $R$. Alternatively, we could have defined an ideal $I$ to be an abelian subgroup of $R$, that is stable under $R$-action: $R.I \\subset I$. We call $R$ simple if $\\left<0\\right>$ and $R$ (if unital) are the only ideals in $R$. We call an ideal $I$ proper if $I \\neq R = \\left<1\\right>$. A proper ideal $I$ is called prime if for all $a, b \\in R$ holds $a b \\in I$ implies $a \\in I$ or $b \\in I$. We call a proper ideal $I$ maximal if for any ideal $J \\supset I$  we have either $J = I$ or $J = R$. Two ideals $I, J \\subset R$ are called coprime if\n$$I + J = \\left<1\\right>.$$\n\\begin{prop}\nIn a unital commutative ring, there always exists a maximal ideal and every maximal ideal is prime.\n\\end{prop}\n\\bws Proving the first statement we are considering the set $R^0 := R\\backslash R^\\times$. Then we construct the set of ideals $\\mathcal{I}$ in $R^0$. Clearly, $\\{0\\} \\in \\mathcal{I}$. Then any element $x \\in R^0 \\backslash \\{0\\}$ generates an ideal in $R^0$. Thus\n$$\\mathcal{I} \\supset \\mathcal{I}_0 := \\{R.x : x \\in R^0\\}.$$\nNow we pick $I = R.x$ and $J = R.x'$ being not coprime then its sum is a proper ideal $I + J \\subset R^0$. Therefore, we may attach\n$$\\mathcal{I}_0 \\cup \\left\\{\\sum_{x \\in R^0} R.x : \\sum R.x \\cap R^\\times = \\emptyset\\right\\} =: \\mathcal{I}.$$\nIt is not obvious that this is already the family of all ideals in $R^0$. However, since each $R$-combination of elements in $R^0$ is either a unit or a non-unit we have that\n$$\\forall I \\in \\mathcal{I} \\wedge \\forall y \\in I \\Rightarrow y \\in R^0.$$\n%We may repeat the this procedure in the following way:\n%$$R^i = \\bigcup_{I \\in \\mathcal{I}_i} I,\\ \\mathcal{I}_i = \\mathcal{I}_{i-1} \\cup \\left\\{\\sum_{x \\in R^{i-1}} R.x : \\sum R.x \\cap R^\\times = \\emptyset\\right\\}$$\n%until no more proper ideals are left to be added.\nNow we get a partially ordered set\n$$(\\mathcal{I}, \\leq),\\ \\leq = \\left\\{(I,J) \\in \\mathcal{I}^2 : I \\supset J\\right\\}.$$\nEach chain of ideals $\\mathcal{I}_I := \\{I_i : \\ldots \\supset I_i \\supset I_{i+1} \\supset \\ldots\\}$ is a totally ordered set. Thus, by Zorns lemma we have that each $\\mathcal{I}_I \\subset \\mathcal{I}$ has a lower bound. By definition it is the largest $R$-submodule in $R^0$ or equivalently a maximal ideal.\\\\\n\\indent To see that a maximal ideal is prime we simply mention that the factor ring of a maximal ideal is an algebraic field, hence an integral domain.\n\\paragraph{Spectrum}\n%For a ring $R$ we can call an ideal $I$ prime if and only if $R/I$ is an integral domain, i.e. zero is the only $R$-torsion. Furthermore, an ideal $I$ is maximal if and only if $R/I$ is an algebraic field. \nPrime ideals are usually denoted by $\\mathfrak{p}$, $\\mathfrak{q}$ - maximal ideals by $\\mathfrak{m}$. Let $\\mathcal{M}_R := \\mathcal{I} \\cup \\{\\left<1\\right>\\}$ denote all ideals in $R$. We call the set of prime ideals\n$$\\trm{Spec}(R) := \\{\\mathfrak{p} \\in \\mathcal{M}_R : \\trm{Ann}_R(R/\\mathfrak{p}) = \\left<0\\right>\\}$$\nthe spectrum of $R$. We remark that the set of maximal ideals is a subset of $\\trm{Spec} R$ in all unital ring, as each field is obviously an integral domain. Lastly, we have that\n$$R \\simeq \\prod_{\\mathfrak{p} \\in \\trm{Spec} R} R/\\mathfrak{p}.$$", "meta": {"hexsha": "5657cf3b45ffe3f67823623ebb3bde1e67aa4146", "size": 6846, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "p_adic/intro.tex", "max_stars_repo_name": "gmuel/texlib", "max_stars_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "p_adic/intro.tex", "max_issues_repo_name": "gmuel/texlib", "max_issues_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "p_adic/intro.tex", "max_forks_repo_name": "gmuel/texlib", "max_forks_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 87.7692307692, "max_line_length": 628, "alphanum_fraction": 0.6673970202, "num_tokens": 2453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328345, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.7106210904599632}}
{"text": "\\documentclass[11pt, a4paper]{article}\n\n\\usepackage{tikz}\n\\usepackage{amsmath}\n\\usepackage{placeins}\n\\usepackage{booktabs}\n\n\\begin{document}\n\n\\title{INDEPENDENT COMPONENT ANALYSIS}\n\\date{}\n\\maketitle\n\nIndependent Component Analysis is a statistical generative model which aims to reveal hidden independent additive components from multi-dimensional data.\n\n\\section{Mathematical Preliminaries}\n\n\\subsection{Single Random Variable}\n\nLet the Probability Mass Function of a discrete random variable X be defined as follows.\n\n\\begin{table}[htbp]\n\t\\centering\n\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t\\toprule\n\t\t         & $x=1$ & $x=2$ & $x=3$ & $x=4$ \\\\\n\t\t\\midrule\n\t\t$P(X=x)$ & 1/6   & 1/3   & 1/3   & 1/6   \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\nThe expectation $E(X)$ of this random variable is defined as follows.\n\n\\begin{align*}\n\tE(X) & = \\sum_k x_k P(X=x_k)                                                                       \\\\\n\t     & = 1 \\times \\frac{1}{6} + 2 \\times \\frac{1}{3} + 3 \\times \\frac{1}{3} + 4 \\times \\frac{1}{6} \\\\\n\t     & = \\frac{15}{6}                                                                              \n\\end{align*}\n\nIf a new variable $Y=2X+1$ is defined, the PMF of $Y$ becomes\n\n\\begin{table}[htbp]\n\t\\centering\n\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t\\toprule\n\t\t                & $y=2 \\times 1  + 1$ & $y=2 \\times 2  + 1$ & $y=2 \\times 3  + 1$ & $y=2 \\times 4  + 1$ \\\\\n\t\t\\midrule\n\t\t$P(Y=y=2x + 1)$ & 1/6                 & 1/3                 & 1/3                 & 1/6                 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\begin{align*}\n\tE(Y) & = \\sum_k y_k P(Y=y_k)         \\\\ \n\t     & = \\sum_k (2 x_k + 1) P(Y=y_k) \\\\\n\t     & = \\sum_k (2x_k + 1) P(X=x_k)  \\\\\n\t     & = 2E(X) + 1                   \n\\end{align*}\n\nHence, expectation is a linear operator which satisfies $E(aX + b) = aE(X) + b$.\n\nThe variance of a discrete random variable $X$ is defined as\n\n\\begin{align*}\n\tVar(X) & = E((X-E(X))(X-E(X)))           \\\\\n\t       & = E(X^2 - 2E(X)X + E(X)E(X))    \\\\\n\t       & = E(X^2) - 2E(X)E(X) + E(X)E(X) \\\\\n\t       & = E(X^2) - E(X)^2               \n\\end{align*}\n\nIn case of continuous random variables, instead of Probability Mass Function a Probability Density Function is defined because the sample space is continuous and infinite as opposed to discrete and finite.\n\nThe expectation and variance of a continuous random variable are defined as\n\n\\begin{align*}\n\tE(X)   & = \\int x P(X=x) dx            \\\\\n\tVar(X) & = \\int (x - E(X))^2 P(X=x) dx \n\\end{align*}\n\nJust as in the case of discrete random variables where the sum of probabilities of all events in sample space must sum to 1, the area under PDF curve in the case of continuous random variable must also integrate to 1.\n\nAn example of a well known continuous random variable is the Gaussian random variable whose PDF is defined as follows.\n\n\\begin{align*}\n\tP(X=x) & = \\frac{1}{\\sqrt{2\\pi\\sigma^2}} e^{\\frac{-(x-\\mu)^2}{2\\sigma^2}} \\\\\n\\end{align*}\n\nwith the following expectation and variance.\n\n\\begin{align*}\n\tE(X)   & = \\mu      \\\\\n\tVar(X) & = \\sigma^2 \n\\end{align*}\n\n\\subsection{A Pair of Random Variables}\n\nLet the joint Probability Mass Function of a pair of discrete random variables X  and Y be defined as follows.\n\n\\begin{table}[htbp]\n\t\\centering\n\t\\begin{tabular}{|c|c|c|c|}\n\t\t\\toprule\n\t\tP(X=x,\\ Y=y) & $x=1$ & $x=2$ & $x=3$ \\\\\n\t\t\\midrule\n\t\t$y=1$        & 3/8   & 3/16  & 3/16  \\\\\n\t\t$y=2$        & 1/8   & 1/16  & 1/16  \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\nAs usual, the sum of all probabilities is equal to 1. \n\nGiven the joint distribution of a set of random variables, one can also find out the distribution of a subset of those random variables and the distribution of such a subset is called the marginal distribution. In the above example, the marginal distribution of $X$ and $Y$can be computed by summing up each column and row respectively in the table above.\n\n\\begin{align*}\n\tP(X=x_k) = \\sum_{y_l} P(X=x_k,\\ y=y_l) \\\\\n\tP(Y=y_k) = \\sum_{x_l} P(X=x_l,\\ y=y_k) \\\\\t\n\\end{align*}\n\nIn the case of a pair of continuous random variables, their joint Probability Distribution Function becomes a surface in three dimensions. The marginal distributions take the following formulae.\n\n\\begin{align*}\n\tP(X=x) = \\int_y P(X=x,\\ y=y)dy \\\\\n\tP(Y=y) = \\int_x P(X=x,\\ y=y)dx \\\\\n\\end{align*}\n\nTwo random variables are said to statistically independent if and only if\n\n\\begin{align*}\n\tP(X=x,\\ Y=y) = P(X=x)P(Y=y) \n\\end{align*}\n\nFor independent random variables, the following result holds.\n\n\\begin{align*}\n\tE(f(X)g(Y)) & = \\int \\int f(x)g(y)P(X=x,\\ Y=y)dxdy      \\\\ \n\t            & = \\int \\int f(x)g(y) P(X=x) P(Y=y) dxdy   \\\\\n\t            & = \\int f(x) P(X=x) dx \\int g(y) P(Y=y) dy \\\\\n\t            & = E(f(X))E(g(Y))                          \n\\end{align*}\n\nA weaker form of independence is uncorrelatedness. If $f(X)$ and $g(Y)$ are defined such that $f(X)=X$ and $g(Y) = Y$ and $E(XY) = E(X)E(Y)$ holds true, then two variables are said to be uncorrelated.\n\n\\subsection {Sum of Random Variables}\n\nIf $X$ denotes the outcome of roll of a dice and $Y$ denotes the outcome of roll of another dice, then $Z=X+Y$ denotes a random variable whose value is equal to the sum of the two rolls. If PMFs of $X$ and $Y$ are known, what is the PMF of $Z=X+Y$?\n\n\\begin{align*}\n\tP(Z=X+Y=z) & = \\sum_x P(X=x,\\ Y=z-x) \\\\\n\t           & = \\sum_y P(X=z-y,\\ Y=y) \n\\end{align*}\n\nIt is easy to see why the above equation holds. To find $P(Z=z)$, one has to sum the probabilities $P(X=x,\\ Y=y)$ of all possible scenarios where $x+y=z$. In the case of continuous random variables the formulae become\n\n\\begin{align*}\n\tP(Z=X+Y=z) & = \\int P(X=x,\\ Y=z-x) dx \\\\\n\t           & = \\int P(X=z-y,\\ Y=y) dy \n\\end{align*}\n\nRandom variable sums are commutative and associative.\n\n\\begin{align*}\n\tX + Y     & = Y + Z       \\\\\n\tX + Y + Z & = (X + Y) + Z \\\\\n\t          & = X + (Y + Z) \n\\end{align*}\n\nThe expectation of a sum of two random variables is the sum of expectations of individual random variables.\n\n\\begin{align*}\n\tE(X+Y) & = \\int \\int (x+y)P(X=x,\\ Y=y)dxdy                                     \\\\\n\t       & = \\int \\int xP(X=x,\\ Y=y)dxdy + \\int yP(X=x,\\ Y=y)dxdy                \\\\\n\t       & = \\int x\\ \\int P(X=x,\\ Y=y) dy\\ dx + \\int y\\ \\int P(X=x,\\ Y=y) dx\\ dy \\\\\n\t       & = \\int xP(X=x)dx + \\int yP(Y=y)dy                                     \\\\\n\t       & = E(X) + E(Y)                                                         \n\\end{align*}\n\nInterestingly, If $X$ and $Y$ are independent Gaussian random variables then the above result holds for variances too.\n\n\\begin{align*}\n\tE(X+Y)   & = E(X) + E(Y)     \\\\\n\tVar(X+Y) & = Var(X) + Var(Y) \n\\end{align*}\n\n\\section{Motivation}\n\nSuppose there are $N$ people speaking at a party and there are $N$ microphones placed at different locations recording sound. Each microphone is recording a simultaneous mix of all speakers' sounds depending on the relative position of the microphone from the speakers. Looking at the microphone recordings alone, is it possible to decipher what each speaker said? \n\n\\section{Problem Statement}\n\nDenote each speaker's sound as a random variable $S_i$ (S stands for signal). A square mixing matrix $A$ is assumed to be responsible for linearly transforming $N$ signals into another set of $N$ random variables observed one each by a microphone.  \n\n\\begin{align*}\n\t\\begin{pmatrix} \n\tX_1 \\\\ \n\tX_2 \\\\ \n\t. \\\\ \n\t. \\\\ \n\t. \\\\ \n\tX_N \n\t\\end{pmatrix} &=\n\t\\begin{pmatrix} \n\ta_{11} & a_{12} & ... & a_{1N} \\\\ \n\ta_{21} & a_{22} & ... & a_{2N} \\\\ \n\t.      & .      & ... & .      \\\\\n\t.      & .      & ... & .      \\\\\n\t.      & .      & ... & .      \\\\ \n\ta_{N1} & a_{N2} & ... & a_{NN} \\\\ \n\t\\end{pmatrix}\n\t\\begin{pmatrix} \n\tS_1 \\\\ \n\tS_2 \\\\ \n\t. \\\\ \n\t. \\\\ \n\t. \\\\ \n\tS_N \n\t\\end{pmatrix} \\\\\n\t\\\\\n\tX &= A S\n\\end{align*}\n\nIf the $j$th column of the matrix $A$ is denoted by $a_j$, then the equation becomes\n\n\\begin{align*}\n\tX = \\sum_j a_j S_j \n\\end{align*}\n\nA set of observations corresponding to $X$ are given and the goal is to recover $S$.\n\n\\begin{align*}\n\tX & = A S      \\\\\n\tS & = A^{-1} X \\\\\n\tS & = W X      \n\\end{align*}\n\nThe goal is to find this un-mixing matrix $W$.\n\n\\section{Assumptions}\n\n\\begin{itemize}\n\t\\item The signals to be recovered must be mutually independent. This assumption gives basis to any ICA algorithm. Find a linear combination $W$ of the observed random variables to yield ``signal\" random variables that are as independent as possible.\n\t\\item The signals must be non-Gaussian. The reason for this restriction will be explained later.\n\t\\item The signals have zero expectation. This is for mathematical convenience. The observed random variables can be centered to impose this restriction. How?\n\t      \\begin{align*}\n\t      \tif\\  E(X_i)  & = 0\\ \\forall\\  i       \\\\\n\t      \tthen\\ E(S_i) & = E(\\sum_j w_{ij}S_j)  \\\\\n\t      \t             & =  \\sum_j w_{ij}E(S_j) \\\\\n\t      \t             & = 0\\ \\forall \\ i       \n\t      \\end{align*}\n\t      \t      \t      \t        \n\\end{itemize}\n\n\\section{Ambiguities}\n\n\\begin{itemize}\n\t\\item Variances of the signals can't be calculated.\n\t      \\begin{align*}\n\t      \t\\begin{pmatrix} \n\t      \tX_1 \\\\ \n\t      \tX_2 \n\t      \t\\end{pmatrix} & = \n\t      \t\\begin{pmatrix} \n\t      \t2             & 3 \\\\ \n\t      \t4             & 5 \n\t      \t\\end{pmatrix}\n\t      \t\\begin{pmatrix} \n\t      \tS_1 \\\\ \n\t      \tS_2\n\t      \t\\end{pmatrix} \\\\\n\t      \t              & = \n\t      \t\\begin{pmatrix} \n\t      \t1             & 3 \\\\ \n\t      \t2             & 5 \n\t      \t\\end{pmatrix}\n\t      \t\\begin{pmatrix} \n\t      \t2S_1 \\\\ \n\t      \tS_2\n\t      \t\\end{pmatrix} \n\t      \\end{align*}\n\t      \t      \t      \t      \n\t      Hence the variances of all signals are assumed to be equal to unity.       \n\t\\item The order of signals can't be recovered.\n\t      \t      \t      \t       \n\t      \\begin{align*}\n\t      \t\\begin{pmatrix} \n\t      \tX_1 \\\\ \n\t      \tX_2 \n\t      \t\\end{pmatrix} & = \n\t      \t\\begin{pmatrix} \n\t      \t2             & 3 \\\\ \n\t      \t4             & 5 \n\t      \t\\end{pmatrix}\n\t      \t\\begin{pmatrix} \n\t      \tS_1 \\\\ \n\t      \tS_2\n\t      \t\\end{pmatrix} \\\\\n\t      \t              & = \n\t      \t\\begin{pmatrix} \n\t      \t3             & 2 \\\\ \n\t      \t5             & 4 \n\t      \t\\end{pmatrix}\n\t      \t\\begin{pmatrix} \n\t      \tS_2 \\\\ \n\t      \tS_1\n\t      \t\\end{pmatrix} \n\t      \\end{align*}\n\\end{itemize}\n\n\\section{Example}\n\nLet $S_1$ and $S_2$ be two independent signals with a uniform density of $1/2$ from $-1$ to $1$. The PDF of each signal looks like\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (-2,0) -- (2,0) node[right]{$s$};\n\t\t\\draw[-latex] (0,-1) -- (0,1) node[above]{$P(S=s)$};\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[line width=0.15em] (-1.8,0) -- (-1,0);\n\t\t\\draw[line width=0.15em] (-1,0) -- (-1,0.5);\n\t\t\\draw[line width=0.15em] (-1,0.5) -- (1,0.5);\n\t\t\\draw[line width=0.15em] (1,0.5) -- (1,0);\n\t\t\\draw[line width=0.15em] (1,0) -- (1.8,0);\t\t\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw (-1, 0.5) node [above left] {(-1, 1/2)};\n\t\t\\draw (1, 0.5) node [above right] {(1, 1/2)};\n\t\t\t\t\t\t\t\t\n\t\\end{tikzpicture}\n\\end{figure}\n\nTheir joint distribution takes the the following form.\n\n\\begin{align*}\n\tP(S_1=s_1,\\ S_2=s_2) & = \\frac{1}{4}\\ \\ \\ if\\ |s_1| <= 1\\ and\\ |s_2| <= 1 \\\\\n\t                     & = 0\\ \\ \\ otherwise                                 \n\\end{align*}\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (-2,0) -- (2,0) node[right]{$s_1$};\n\t\t\\draw[-latex] (0,-2) -- (0,2) node[above]{$s_2$};\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw [fill=gray, opacity=0.3] (-1,-1) rectangle (1,1);\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw (-1, -1) node [below left] {(-1, -1)};\n\t\t\\draw (-1, 1) node [above left] {(-1, 1)};\n\t\t\\draw (1, -1) node [below right] {(1, -1)};\n\t\t\\draw (1, 1) node [above right] {(1, 1)};\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\FloatBarrier\n\nConsider the following linear transformation of these signals.\n\n\\begin{align*}\n\t\\begin{pmatrix} \n\tX_1 \\\\ \n\tX_2 \n\t\\end{pmatrix} & = \n\t\\begin{pmatrix} \n\t1             & 1 \\\\ \n\t3             & 1 \n\t\\end{pmatrix}\n\t\\begin{pmatrix} \n\tS_1 \\\\ \n\tS_2\n\t\\end{pmatrix}\n\\end{align*}\n\nThe joint density of the observed signals becomes\n\n\\begin{align*}\n\tP(X_1=x_1,\\ X_2=x_2) & = \\frac{1}{2} \\times \\frac{1}{4}                                     \n\t= \\frac{1}{\\begin{vmatrix} \n\t1                    & 1                                                                    \\\\ \n\t3                    & 1                                                                    \n\t\\end{vmatrix}} \\times \\frac{1}{4} \\ \\ \\ if\\ (x_1, x_2)\\ lie\\ in\\  parallelogram\\ below \\\\\n\t                     & = 0\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ otherwise \n\\end{align*}\n\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (-4,0) -- (4,0) node[right]{$x_1$};\n\t\t\\draw[-latex] (0,-4) -- (0,4) node[above]{$x_2$};\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw [fill=gray,  opacity=0.3] (2,4) -- (0,2) -- (-2,-4) -- (0,-2) -- cycle;\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw (2, 4) node [above right] {(2, 4)};\n\t\t\\draw (0, 2) node [above left] {(0, 2)};\n\t\t\\draw (-2, -4) node [below left] {(-2, -4)};\n\t\t\\draw (0, -2) node [below right] {(0, -2)};\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\FloatBarrier\n\nOne edge of the parallelogram points in the direction $(1, 1)$ and the other in $(1, 3)$. These are the same as the columns in the mixing matrix. This gives some hope that ICA could exploit some properties of the joint distribution to recover the original signals like in this case where the edges of the joint density give the mixing matrix away. \n\n\\section{Density Under Linear Transformation}\n\nConsider a random vector $X$ with the following PDF.\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (-2,0) -- (2,0) node[right]{$x$};\n\t\t\\draw[-latex] (0,-1) -- (0,2) node[above]{$P(X=x)$};\n\t\t\t\t\n\t\t\\draw[line width=0.15em] (-1.8,0) -- (-1,0);\n\t\t\\draw[line width=0.15em] (-1,0) -- (0,1);\n\t\t\\draw[line width=0.15em] (0,1) -- (1,0);\n\t\t\\draw[line width=0.15em] (1,0) -- (1.8,0);\t\n\t\t\t\t\n\t\t\\draw (-1, 0) node [below] {(-1, 0)};\n\t\t\\draw (1, 0) node [below] {(1, 0)};\n\t\t\\draw (0, 1) node [above right] {(0, 1)};\t\t\t\t\t\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\FloatBarrier\n\nConsider another random vector $Y=2X$. How is the PDF of $Y$ related to that of $X$? One can proceed in the following manner.\n\n\\begin{align*}\n\tP(Y=y) & = P(2X = y)          \\\\\n\t       & = P(X= \\frac{y}{2})) \n\\end{align*}\n\nThe calculated PDF is drawn below.\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (-4,0) -- (4,0) node[right]{$y$};\n\t\t\\draw[-latex] (0,-1) -- (0,2) node[above]{$P(Y=y)$};\n\t\t\t\t\n\t\t\\draw[line width=0.15em] (-3.8,0) -- (-2,0);\n\t\t\\draw[line width=0.15em] (-2,0) -- (0,1);\n\t\t\\draw[line width=0.15em] (0,1) -- (2,0);\n\t\t\\draw[line width=0.15em] (2,0) -- (3.8,0);\t\n\t\t\t\t\n\t\t\\draw (-2, 0) node [below] {(-2, 0)};\n\t\t\\draw (2, 0) node [below] {(2, 0)};\n\t\t\\draw (0, 1) node [above right] {(0, 1)};\t\t\t\t\t\n\t\\end{tikzpicture}\n\\end{figure}\n\nOn closer inspection, the calculated PDF is wrong as the area under it is 2. Thus a division by 2 is necessary. Thus,\n\n\\begin{align*}\n\tY      & = \\alpha X                               \\\\\n\tX      & = \\frac{1}{\\alpha} Y                     \\\\\n\tP(Y=y) & = \\frac{1}{\\alpha} P(X=\\frac{y}{\\alpha}) \\\\\n\tP(X=x) & = \\alpha P(Y=\\alpha x)                   \n\\end{align*}\n\nMore generally,\n\n\\begin{align*}\n\tY                                 & = \\alpha X                                                                \\\\\n\t\\begin{pmatrix} Y_1               &                                                                           \\\\ Y_2 \\\\ ... \\\\Y_N \\end{pmatrix} &= \\begin{pmatrix} \\alpha_1^T \\\\ \\alpha_2^T \\\\ ... \\\\  \\alpha_N^T \\end{pmatrix} \\begin{pmatrix} X_1 \\\\ X_2 \\\\... \\\\  X_N \\end{pmatrix}  \\\\\n\tP(X_1=x_1, X_2=x_2, ..., X_N=x_N) & =  \\begin{vmatrix} \\alpha_1^T                                             \\\\ \\alpha_2^T \\\\ ... \\\\  \\alpha_N^T \\end{vmatrix}  P(Y_1=\\alpha_1^T X, Y_2=\\alpha_2^T X, ..., Y_N=\\alpha_N^T X) \\\\\n\tP(X_1=x_1, X_2=x_2, ..., X_N=x_N) & =  |\\alpha|  P(Y_1=\\alpha_1^T X, Y_2=\\alpha_2^T X, ..., Y_N=\\alpha_N^T X) \n\\end{align*}\n\n\\section{Relation to PCA}\n\nGiven a centered random vector $X$, PCA defines a linear transform $Y\\ =\\ P X$ such that the resulting vector has uncorrelated components. $P$ is a matrix of orthonormal eigenvectors of the covariance matrix of $X$.\n\n\\begin{align*}\n\tE(XX^T) & = P^TDP \n\\end{align*}\n\nThe covariance matrix of the transformed random vector is diagonalized.\n\n\\begin{align*}\n\tE(YY^T) & = E(PXX^TP^T) \\\\\n\t        & = PE(XX^T)P^T \\\\\n\t        & = PP^TDPP^T   \\\\\n\t        & = D           \n\\end{align*}\n\nOne can go a step further to define $Y\\ =\\ D^{-1/2}PX$. Now the covariance matrix of the transformed random vector becomes identity.\n\n\\begin{align*}\n\tE(YY^T) & = D^{-1/2}PE(XX^T)P^TD^{-1/2T} \\\\\n\t        & = D^{-1/2}PP^TDPP^TD^{-1/2T}   \\\\\n\t        & = I                            \n\\end{align*}\n\nSuch a transformation of $X$ is called whitening. Whitening is often a preprocessing step of ICA. Intuitively, whitening makes the transformed components uncorrelated and then ICA will make them independent. So whitening solves half the problem of ICA. More formally, whitening restricts the space of mixing matrix to orthogonal matrices thus making the problem easier. To understand why, consider $Y\\ =\\  AS$ such that $Y$ is white.\n\n\\begin{align*}\n\tE(YY^T) = I      \\\\\n\tAE(SS^T) A^T = I \\\\\n\\end{align*}\n\nSince signals are independent with unit variances as per an assumption above,\n\n\\begin{align*}\n\tE(SS^T) & = I \\\\\n\tAA^T    & = I \\\\\n\\end{align*}\n\nproving that $A$ must be orthogonal. Hence, in case of a random vector of size $N$, instead of estimating $N^2$ parameters of the matrix $A$, ICA only has to estimate $N(N-1)/2$ parameters since $A$ is orthogonal and an orthogonal matrix has $N(N-1)/2$ degrees of freedom. This is equal to estimating almost half the parameters. Thus, literally too, whitening solves half the problem of ICA.\n\n\\section{Why Gaussian signals can't be recovered?}\n\nConsider a Gaussian random variable,\n\n\\begin{align*}\n\tP(X=x) & = \\frac{1}{\\sqrt{2\\pi\\sigma^2}} e^{\\frac{-(x-\\mu)^2}{2\\sigma^2}} \\\\\n\\end{align*}\n\nConsider another random variable $Y=\\alpha X$. What does the PDF of $Y$ look like? \n\n\\begin{align*}\n\tP(Y=y) & = \\frac{1}{\\alpha} P(X=\\frac{y}{\\alpha})                                                     \\\\\n\tP(Y=y) & = \\frac{1}{\\alpha \\sqrt{2\\pi\\sigma^2}} e^{\\frac{-(\\frac{y}{\\alpha}-\\mu)^2}{2\\sigma^2}}       \\\\\n\t       & = \\frac{1}{\\sqrt{2\\pi \\alpha^2 \\sigma^2}} e^{\\frac{-(y- \\alpha \\mu)^2}{2 \\alpha^2 \\sigma^2}} \n\\end{align*}\n\nIt is clear that $Y$ is also Gaussian with mean $\\alpha \\mu$ and variance $\\alpha^2 \\sigma^2$. Another well known result with respect to Gaussians is that sum of two Gaussians is also a Gaussian with mean as sum of individual means and variance as sum of individual variances.\n\n\\begin{align*}\n\t\\mathcal{N}(\\mu_1, \\sigma_1^2) + \\mathcal{N}(\\mu_2, \\sigma_2^2) \\sim \\mathcal{N}(\\mu_1 + \\mu_2, \\sigma_1^2 + \\sigma_2^2) \n\\end{align*}\n\nThese properties of Gaussian signals make them unrecoverable. Consider two Gaussian signals of zero mean and unit variance as per ICA assumptions and an orthogonal mixing matrix. An orthogonal matrix is considered because it is assumed that whitening has already been done and thus the search space of ICA is only orthogonal matrices.\n\n\\begin{align*} \n\t\\begin{pmatrix} \n\ta & b                 \\\\ \n\tc & d                 \n\t\\end{pmatrix}\n\t\\begin{pmatrix} \n\t\\mathcal{N}(0, 1) \\\\ \n\t\\mathcal{N}(0, 1) \n\t\\end{pmatrix} \\\\\n\t  & = \\begin{pmatrix} \n\t\\mathcal{N}(0, a^2) + \\mathcal{N}(0, b^2) \\\\ \n\t\\mathcal{N}(0, c^2) + \\mathcal{N}(0, d^2)\n\t\\end{pmatrix}  \\\\\n\t  & = \\begin{pmatrix} \n\t\\mathcal{N}(0, a^2+b^2)  \\\\ \n\t\\mathcal{N}(0, c^2 + d^2)\n\t\\end{pmatrix}\n\\end{align*}\n\nDue to orthogonality of the mixing matrix $a^2+b^2=c^2+d^2=1$.\n\n\\begin{align*}\n\t\\begin{pmatrix} \n\ta & b                 \\\\ \n\tc & d                 \n\t\\end{pmatrix}\n\t\\begin{pmatrix} \n\t\\mathcal{N}(0, 1) \\\\ \n\t\\mathcal{N}(0, 1) \n\t\\end{pmatrix} \n\t  & = \\begin{pmatrix} \n\t\\mathcal{N}(0, 1) \\\\ \n\t\\mathcal{N}(0, 1) \n\t\\end{pmatrix} \n\\end{align*}\n\nSo, upon the transformation due to any orthogonal matrix the signals remain unchanged. Hence, in case of Gaussian signals only whitening is possible. \n\n\\section{Algorithm}\n\n$T$ training samples are given of the form,\n\n\\begin{align*}\n\t\\begin{pmatrix}\n\tx_1^1 & x_1^2 & ... & x_1^T \\\\\n\tx_2^1 & x_2^2 & ... & x_2^T \\\\\n\t... \\\\\n\tx_N^1 & x_N^2 & ... & x_N^T \n\t\\end{pmatrix}\n\\end{align*}\n\nThe log-likelihood can be written as,\n\n\\begin{align*}\n\tL = log \\left( \\prod_i P(X_1 = x_1^i, X_2=x_2^i, ..., X_N=x_N^i) \\right) \n\\end{align*}\n\nRewriting ICA equation,\n\n\\begin{align*}\n\tS   &= WX              \\\\\n\t\\begin{pmatrix} S_1 \\\\ S_2 \\\\ ... \\\\S_N \\end{pmatrix} &= \\begin{pmatrix} w_1^T \\\\ w_2^T \\\\ ... \\\\  w_N^T \\end{pmatrix} \\begin{pmatrix} X_1 \\\\ X_2 \\\\... \\\\  X_N \\end{pmatrix}  \\\\\n\\end{align*}\n\nUsing the density transformation rule,\n\n\\begin{align*}\n\tL(W) = log \\left( \\prod_i \\left( P(S_1 = w_1^{T} X^i, S_2=w_2^{T} X^i, ..., S_N= w_N^{T} X^i) |W| \\right) \\right) \n\\end{align*}\n\nSince the signals are independent,\n\n\\begin{align*}\n\tL(W)= log \\left( \\prod_i \\left( \\prod_j  P(S_j = w_j^{T}X^i) |W| \\right) \\right) \\\\\n\tL(W) = \\sum_i \\left( \\sum_j  log (P(S_j = w_j^{T}X^i)) + log(|W|) \\right)        \n\\end{align*}\n\n$P(S_j = w_j^{T}X^i)$ is estimated by the sigmoid function.\n\n\\begin{align*}\n\tP(S_j = w_j^{T}X^i) = \\frac{e^{-w_j^{T}X^i}}{1 + e^{-w_j^{T}X^i}} \n\\end{align*}\n\nThe log-likelihood equation becomes,\n\n\\begin{align*}\n\tL(W) = \\sum_i \\left( \\sum_j  log \\left( \\frac{e^{-w_j^{T}X^i}}{1 + e^{-w_j^{T}X^i}} \\right) + log(|W|) \\right) \n\\end{align*}\n\nTo maximize $L(W)$ gradient descent can be applied. At convergence, the optimal $W$ can be multiplied to $X$ to recover sought $S$.  \n\n\\end{document}\n", "meta": {"hexsha": "3768fc66dd8cb3ef2e37dcd73f3c7ad74d8d593e", "size": 21690, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Independent Component Analysis/Independent Component Analysis.tex", "max_stars_repo_name": "singaurav/machine-learning-notes", "max_stars_repo_head_hexsha": "4fdd5b839156bcbf8f95a36275b8cd10f93e4c9d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-26T11:33:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-26T11:33:39.000Z", "max_issues_repo_path": "Independent Component Analysis/Independent Component Analysis.tex", "max_issues_repo_name": "singaurav/machine-learning-notes", "max_issues_repo_head_hexsha": "4fdd5b839156bcbf8f95a36275b8cd10f93e4c9d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Independent Component Analysis/Independent Component Analysis.tex", "max_forks_repo_name": "singaurav/machine-learning-notes", "max_forks_repo_head_hexsha": "4fdd5b839156bcbf8f95a36275b8cd10f93e4c9d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-22T18:56:20.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-22T18:56:20.000Z", "avg_line_length": 34.2113564669, "max_line_length": 433, "alphanum_fraction": 0.5563393269, "num_tokens": 7422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8902942181173146, "lm_q1q2_score": 0.7106210731992748}}
{"text": "\\documentclass[a4paper,12pt]{article}\n\n% .......................................... Preamble\n\n% Use \\usepackage[fleqn]{amsmath} to make the math environments left-aligned instead of centered\n\\usepackage[fleqn]{amsmath}\n\\usepackage{dsfont} % Used for representing Real numbers (\\mathds{R})\n\n% Custom commands to define global variables/symbols in the document\n\\newcommand{\\vectorSpace}{\\mathds{R}}\n\\newcommand{\\VSet}{\\mathcal{V}}\n\\newcommand{\\PSet}{\\mathcal{P}}\n\n% .......................................... End\n\n\\begin{document}\n\n\t\\section*{Maths}\n\t\n\tThis is $x^2 =\\frac{1}{4}$ in inline mode.\n\tHere it is in display mode:\n\t\\begin{displaymath}\n\t\tx^2 = \\frac{1}{4}\n\t\\end{displaymath}\n\t\n\t\\section*{More maths}\n\t\n\tFraction: $\\frac{dy}{dx} = \\dfrac{dy}{dx}$ \\newline\n\tSum: $\\sum_{n=1}^{\\infty} = \\displaystyle\\sum_{n=1}^{\\infty}$ \\newline\n\tLimit: $\\lim_{n \\to \\infty} = \\displaystyle\\lim_{n \\to \\infty}$ \\newline\n\tIntegral: $\\int_a^b = \\displaystyle\\int_a^b$\n\t\n\t\\section*{Matrices}\n\t\n\t\\begin{displaymath}\n\t\tA = \\begin{pmatrix} 1 & 2 \\\\ 3 & 4 \\end{pmatrix},~\n\t\tB = \\begin{bmatrix} 5 & 6 \\\\ 7 & 8 \\end{bmatrix},~\n\t\t|A| = \\begin{vmatrix} 1 & 2 \\\\ 3 & 4 \\end{vmatrix}\n\t\\end{displaymath}\n\t\n\t\\section*{More frightening equations}\n\t\n\t\\begin{align*}\n\t\tf(x) &= e^{x-1}\\\\\n\t\t\\int_1^2 f(x)\\;dx &= e^{x-1} ~\\Bigr|_1^2\\\\\n\t\t&= e - 1\n\t\\end{align*}\n\t\n\t\\begin{align}\n\t\t2x - 4y - 7z + 8w &= \\pi\\\\\n\t\t3x + 5y + 9z &= 213\n\t\\end{align}\n\t\n\t\\section*{Math symbols}\n\t\n\tA projection defines a function $(f)$ that transforms data in $\\vectorSpace^{\\eta}$ to $\\vectorSpace^{\\kappa}$ (where $\\eta \\geq \\kappa$)\\dots\\ $f$ transforms the point set $\\VSet$ to another set $\\PSet$ can be denoted as a mapping of a data point $(\\chi)$ in $\\vectorSpace^{\\eta}$ to another point $(\\rho)$ in $\\vectorSpace^{\\kappa}$ that is subject to:\n\t\\begin{eqnarray}\n\t\tf_{\\chi} & = & \\rho \\left\\{\n\t\t\\begin{array}{llr}\n\t\t\t\\VSet = (\\chi_{0}, \\chi_{1}, \\dots, \\chi_{i}) & \\forall{\\chi_{i}} \\in \\vectorSpace^{\\eta} & 0 \\leq i < N \\\\\n\t\t\t\\PSet = (\\rho_{0}, \\rho_{1}, \\dots, \\rho_{j}) & \\forall{\\rho_{j}} \\in \\vectorSpace^{\\kappa} & 0 \\leq j < n \\\\\n\t\t\t\\eta \\geq \\kappa & {} & {} \\\\\n\t\t\tN \\geq n & {} & {}\n\t\t\\end{array} \\right.\n\t\\end{eqnarray}\n\t\n\\end{document}\n", "meta": {"hexsha": "03b8df31230b8b023708e99e6b6c17dd9cd06f70", "size": 2197, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Snippets/11 Math/11 Math.tex", "max_stars_repo_name": "youldash/LaTeX", "max_stars_repo_head_hexsha": "9602080650426cd35b422b7ed9c2dbfbcee9cef7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Snippets/11 Math/11 Math.tex", "max_issues_repo_name": "youldash/LaTeX", "max_issues_repo_head_hexsha": "9602080650426cd35b422b7ed9c2dbfbcee9cef7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Snippets/11 Math/11 Math.tex", "max_forks_repo_name": "youldash/LaTeX", "max_forks_repo_head_hexsha": "9602080650426cd35b422b7ed9c2dbfbcee9cef7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3088235294, "max_line_length": 355, "alphanum_fraction": 0.5967228038, "num_tokens": 842, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7105273918409659}}
{"text": "\\section{Linear Discriminant Analysis}\n\\label{chp:lindisana}\n\nIn chapter \\ref{chp:logreg} it was described how logistic regression could be used for binary classification. It was also stated how it could be extended to  a classification problem with more than two classes. In practice logistic regression is though rarely used for classification problems with more than two classes. Furthermore a problem with logistic regression is that it does not perform very stable under some circumstance. One big problem with logistic regression is that it might not converge if the classes are well-separated. An example could be the data in the table below. Here we see that the classes are well-separated as $X<0$ then $Y=0$ and if $X>0$ then $Y=1$. Because of this perfect separation the algorithm will never converge because it can keep optimizing.\n\\begin{center} \n\t\\begin{tabular}{rll}\n\t\t\\multicolumn{1}{c}{\\textbf{Y}} &\n\t\t\\multicolumn{1}{c}{\\textbf{X}} \\\\ \\hline\n\t\t0     &  -2  \\\\[0.05cm] \n\t\t0     &  -3  \\\\[0.05cm] \n\t\t0     &  -1  \\\\[0.05cm] \n\t\t0     &  -5  \\\\[0.05cm] \n\t\t1     &    3  \\\\[0.05cm] \n\t\t1     &    1  \\\\[0.05cm] \n\t\t1     &    5  \\\\[0.05cm] \n\t\t1     &    6  \\\\[0.05cm] \n\t\\end{tabular}\n\\end{center}\n\nInstead a method called Linear Discriminant Analysis(LDA) can be used. In logistic regression we directly model $Pr(Y|X)$. With LDA $P(X|Y)$ is modeled and prediction is done by using Bayes theorem to achieve $P(Y|X)$ and find the most probable class given the predictors. The following variables are used:\n\n\\begin{itemize}\n\t\\item Let $\\pi_k$ represent the prior probability $P(Y=k)$ for K classes.\n\t\\item Let $f_k(x)$ represent the probability $P(X=x|Y=k)$. So $f_k(x)$ is the probability of the predictors when the class Y is given.\n\\end{itemize} \n\nBy inserting these in Bayes formula and normalizing to get $P(Y=k|X=x)$ the following can be written.\n\n\\begin{equation}\n\tP(Y=k|X = x) = \\dfrac{\\pi_k f_k(x)}{\\sum_{l=1}^{K} \\pi_l f_l(x)}\n\\end{equation}\n\nFor the equation the two variables $\\pi_k$ and $f_k(x)$ still needs to be estimated. $pi_k$ can be estimated by computing the fraction of the training data that belongs to the k'th class. While $f_k(x)$ can be estimated as a Gaussian. This means that the equation differs when using only 1 predictor to using multiple. When only using one predictor and taking log of the equation it can be rewritten as the following\n\n\\begin{equation}\n\t\\delta_k(x) = x  \\dfrac{\\mu_k}{\\sigma^2} - \\dfrac{\\mu_k^2}{2\\sigma^2} + log(\\pi_k)\n\\end{equation}\n\nThen the equation is calculated for each class k and is classified for the k that results in the highest probability. The equation for multiple predictors instead uses a $mu$ matrix and a covariance matrix and can be written as following\n\n\\begin{equation}\n\t\\delta_k(x) = x^T \\Sigma^{-1} \\mu_k -  \\frac{1}{2} \\mu_k^{T} \\Sigma^{-1} \\mu_k + log \\pi_k\n\\end{equation}\n\nNote here that LDA assumes the observation to have a Gaussian distribution. If this is the case then LDA is likely to outperform Logistic regression, while if it is not, then Logistic regression is likely to outperform LDA. \n\nThe means of the Gaussian are simply calculated by summing all values with a specific class and dividing by the total number.\nThe variance is calculated across all the data with a specific class.\n\n\\section{Lab 4.6.3 - Linear Discriminant Analysis}\nFirst a model linear discriminant analysis model is created with the python library sklearn. The model is created based on the two predictors \\emph{Lag1} and \\emph{Lag2}. \n\n\n\\begin{lstlisting}[language=Python, label=lst:ldaModel, caption=creating linear discriminant analysis model sklearn]\nX_train = data[:'2004'][['Lag1', 'Lag2']]\nY_train = data[:'2004']['Direction']\n\nX_test = data['2005':][['Lag1', 'Lag2']]\nY_test = data['2005':]['Direction']\n\nlda = LinearDiscriminantAnalysis()\nfit = lda.fit(X_train,Y_train)\n\\end{lstlisting}\n\nAfter creating the model the calculated prior probability, means and coefficients can be read. The prior probability for \\emph{Down} is $\\pi_1=0.492$ while the prior probability for \\emph{Up} is $\\pi_2=0.508$. So based on the data there are more days where the stock market went up than down. \n\nThe means $\\mu_k$ are described by a matrix. The matrix describes a separate mean for both \\emph{Lag1} and \\emph{Lag2} and for each predictor a mean for \\emph{Up} and \\emph{Down}. The mean value for \\emph{Lag1} and \\emph{Lag2} has a tendency to be positive on days when the stock went up while they are negative when the stock went down.  $\\bigl( \\begin{smallmatrix} \t & Lag1 & Lag2\t\\\\ \t Down & 0.0428 & 0.0339 \\\\ \t Up & -0.0395 & -0.0313 \\end{smallmatrix} \\bigr) $. The coefficients are estimated to $-0.0554$ and $-0.0443$. These are the multipliers for \\emph{Lag1} and \\emph{Lag2}.\n\n\\todo{Er det vigtigt at vise hvordan vi printer disse værdier?}\n\\begin{lstlisting}[language=Python, label=lst:ldaProperties, caption=printing lda prior mean and coefficients]\nprint \"Prior probabilities:\"\nprint lda.priors_\n\nprint \"Mean:\"\nprint lda.means_\n\nprint \"Coefficients:\"\nprint lda.coef_\n\\end{lstlisting}\n\nIn listing \\ref{lst:ldaScore} the score is printet. The score show that the LDA model predicted correctly in $56\\%$ of the predictions on the test data. \n\\begin{lstlisting}[language=Python, label=lst:ldaScore, caption=printing lda score]\nprint(lda.score(X_test, Y_test))\n\\end{lstlisting}\n\nThis shows how linear discriminant analysis performs very similar to logistic regression on the stock market data.\n\n\\section{Quadratic discriminant analysis}\nSimilar to LDA the Quadratic discriminant analysis (QDA) also assumes that the observations are drawn from a Gaussian distribution and also uses Bayes theorem for prediction. \n\n\\myFigure{lda_vs_qda.PNG}{LDA vs QDA}{fig:qdaCompare}{0.6}\n\nIn Figure \\ref{fig:qdaCompare} the difference between LDA and QDA is illustrated. It shows that the LDA can only learn linear boundaries, while the QDA can learn quadratic boundaries. This makes the QDA more flexible. \n\n\\subsection{Lab 4.6.4}\nAgain the stock market data is used for prediction with \\emph{Lag1} and \\emph{Lag2} as predictors. The QDA model is estimated with sklearn. This is shown in listing \\ref{lst:qdaModel}.\n\n\\begin{lstlisting}[language=Python, label=lst:qdaModel, caption=Creating quadratic discriminant analysis model sklearn]\nX_train = data[:'2004'][['Lag1', 'Lag2']]\nY_train = data[:'2004']['Direction']\n\nX_test = data['2005':][['Lag1', 'Lag2']]\nY_test = data['2005':]['Direction']\n\nqda = QuadraticDiscriminantAnalysis()\nfit = qda.fit(X_train,Y_train)\n\\end{lstlisting}\n\nIn listing \\ref{lst:qdaScore} the score for the QDA model is printed. The print shows that on the test data the prediction was correct in $59.9\\%$ of the cases. With the stock market data it actually performed better than both logistic regression and linear discriminant analysis. \n\\begin{lstlisting}[language=Python, label=lst:qdaScore, caption=Printing qda score]\nprint(qda.score(X_test, Y_test))\n\\end{lstlisting}\n\n\\section{K-Nearest Neighbors}\nK-Nearest Neighbors or \\emph{KNN} is a classification technique that classifies observations depending on distance to k other observations. \n\nSay you have a dataset with two classes of observations A and B, with 10 observations each. Then a test observation is desired to be classified with $k=5$, which means the five nearest observations will be examined. If three of the examined observations are A and the other two are B then the estimated probabilities are $3/5$ for class A and $2/5$ for class B. \n\n\\subsection{Lab 4.6.5}\n\nIn this lab exercise the method \\emph{K-nearest Neighbors} is used. To perform this method, sklearn has a function called \\emph{KNeighborsClassifier}. This takes one parameter, which is number of n neighbors. After this the function fit is called, that fits the data.\nThe code is shown in listing\n\n\\begin{lstlisting}[caption={Python K-Nearest neighbors function, where K is set to 1}, label=lst:kneighbor, mathescape=true]\nX_train = data[:'2004'][['Lag1', 'Lag2']]\nY_train = data[:'2004']['Direction']\n\nX_test = data['2005':][['Lag1', 'Lag2']]\nY_test = data['2005':]['Direction']\n\n\nknn = KNeighborsClassifier(n_neighbors=1)\nfit = knn.fit(X_train, Y_train)\n\\end{lstlisting}\n\nThe function is used to predict the market's movement from the dates in 2005. If the value K is set to 1, 50\\% of the predictions are correctly predicted which is not very good.\nIf K is change to 3, the predictions turns out to be correct in 53\\% of the cases. So increasing the number of k from 1 to 3 made the model a bit better. All kinds of different values can be chosen for K, but it is important not to change the number to often because the model then will be customized to the training data which is not good.\n\nIf the results are compared with the results that \\emph{QDA} produces, the \\emph{QDA} provides better results than K-nearest neighbors.", "meta": {"hexsha": "e86a50355068e3609c8d8ba88e6769dd6efc0981", "size": 8844, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/chapter/linear_discriminant_analysis.tex", "max_stars_repo_name": "Rotvig/F17Q4---Decision-Support-Systems", "max_stars_repo_head_hexsha": "62c3bb41a8fb4df75f4f038dea7af521cddafa4a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Report/chapter/linear_discriminant_analysis.tex", "max_issues_repo_name": "Rotvig/F17Q4---Decision-Support-Systems", "max_issues_repo_head_hexsha": "62c3bb41a8fb4df75f4f038dea7af521cddafa4a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/chapter/linear_discriminant_analysis.tex", "max_forks_repo_name": "Rotvig/F17Q4---Decision-Support-Systems", "max_forks_repo_head_hexsha": "62c3bb41a8fb4df75f4f038dea7af521cddafa4a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.6258992806, "max_line_length": 781, "alphanum_fraction": 0.7481908639, "num_tokens": 2462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7104125425948357}}
{"text": "\\lab{Data Structures III: K-D Trees}{K-D Trees}\n\\label{lab:DS3}\n\n\\objective{Nearest neighbor search is an optimization problem that arises in applications such as computer vision, pattern recognition, internet marketing, and data compression.\nIn this lab we solve the problem efficiently using a k-d tree, then use SciPy's k-d tree to implement a handwriting recognition algorithm.}\n\n\\section*{The Nearest Neighbor Search Problem} % ==============================\n\nSuppose you move into a new city with several post offices.\nSince your time is valuable, you wish to know which post office is closest to your home.\nThis is called the nearest neighbor search problem, and it has many applications.\n\nIn general, suppose that $X$ is a collection of data, called a \\emph{training set}.\nLet $y$ be any point (often called the \\emph{target} point) in the same space as the data in $X$.\nThe nearest neighbor search problem determines the point in $X$ that is closest to $y$.\nFor example, in the post office problem the set $X$ could be addresses or latitude and longtitude data for each post office in the city.\nThen $y$ would be the data that represents your new home, and the task is to find the closest post office in $X$ to $y$.\n\n\\begin{problem} % Euclidean Distance\nRoughly speaking, a function that measures distance between two points in a set is called a \\emph{metric}.\\footnote{Metrics and metric spaces are examined in detail in Chapter 5 of Volume I.}\nThe \\emph{euclidean metric} measures the distance between two points in $\\mathbb{R}^n$ with the familiar distance formula:\n\\[\nd(\\x,\\y) = \\sqrt{\\displaystyle\\sum_{i=1}^n (x_i - y_i)^2} = \\| \\x - \\y \\|_2\n\\]\n\nWrite a function that accepts two 1-dimensional NumPy arrays and returns the euclidean distance between them.\nRaise a \\li{ValueError} if the arrays don't have the same number of entries.\n\\\\\n(Hint: NumPy already has some functions to help do this quickly.)\n\\end{problem}\n\nConsider again the post office example.\nOne way to find out which post office is closest is to drive from home to each post office, measure the mileage, and then choose the post office that is the closest.\nThis is called an \\emph{exhaustive search}.\nMore precisely, we measure the distance of $y$ to each point in $X$, and choose the point with the smallest distance.\nThis method is ineffecient however, and only feasible for relatively small training sets.\n\n\\begin{problem} % Exhaustive search method.\nWrite a function that solves the nearest neighbor search problem by exhaustively checking all of the distances between a given point and each point in a data set.\nThe function should take in a set of data points (as an $m \\times k$ NumPy array, where each row represents one of the $m$ points in the data set) and a single target point (as a 1-dimensional NumPy array with $k$ entries).\nReturn the point in the training set that is closest to the target point and its distance from the target.\n\nThe complexity of this algorithm is $O(mk)$, where $k$ is the number of dimensions and $m$ is the number of data points.\n\\end{problem}\n\n\\section*{K-D Trees} % ========================================================\n\n% \\footnote{This lab is a sequel to the Data Structures II lab, and should not be attempted until the reader has successfully implemented a binary search tree in Python.}\nA \\href{https://en.wikipedia.org/wiki/K-d_tree}{\\emph{$k$-d tree}} is a special kind of binary search tree for high dimensional data (i.e., more dimensions than 1).\nWhile a binary search tree excludes regions of the number line from a search until the search point is found, a $k$-d tree works on regions of $\\mathbb{R}^k$.\nSo long as the data in the tree meets certain dimensionality requirements, similar efficiency gains may be made.\n\nRecall that to search for a point in a binary search tree, we start at the root, and if the point we are searching for is less than the root we proceed down the left branch of the tree.\nIf it is larger, we proceed down the right branch.\nBy doing this, we exclude a region of the number line (and therefore the subtree in the opposite direction) from our search.\nBy eliminating this region from consideration, we have far fewer points to search and the efficiency of our search is greatly increased.\n% See Figure \\ref{fig:k-binary-search} for an illustration.\n\nLike a binary search tree, a $k$-d tree starts with a root node with a depth, or level, of 0.\nAt the $i^{th}$ level, the nodes to the left of a parent have a lower value in the $i^{th}$ dimension.\nNodes to the right have a greater value in the $i^{th}$ dimension.\nAt the next level, we do the same for the next dimension.\nFor example, consider data in $\\mathbb{R}^3$.\nThe root node partitions the data according to the first dimension.\nThe children of the root partition according to the second dimension, and the grandchildren along the third.\nSee Figure \\ref{fig:k-binary-search} for an example in $\\mathbb{R}^2$.\n\nAs with any other data structure, the first task is to construct a node class to store data.\nA \\li{KDTNode} is similar to a \\li{BSTNode}, except it has another attribute called \\li{axis}.\nThe \\li{axis} attribute tells us which dimension of $\\mathbb{R}^k$ to split on.\n\n% TODO: A figure actually depicting the resulting KDT, like the BST figures of the Data Structures II lab.\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{figures/kdpic1.png}\n\\caption{A regular binary search tree partitions $\\mathbb{R}$, but a $k$-d tree partitions $\\mathbb{R}^{k}$. The above graph illustrates the partition for a $k$-d tree loaded with the points (5, 5), (8, 4), (3, 2), (7, 7), (2, 6), and (9, 2), in that order. To find the point (9, 2), we start at the root. Since the $x$-coordinate of (9, 2) is greater than the $x$-coordinate of (5, 5), we move into the region to the right of the middle blue line, thus excluding all points ($x$, $y$) with $x < 5$. Next we compare (9, 2) to the root's right child, (8, 4). Since the $y$-coordinate of (9, 2) is less than the $y$-coordinate of (8, 4), we move below the red line on the right, thus excluding all points ($x$, $y$) with $y > 4$. We have now found (9, 2), since it is the left child of (8, 4).}\n\\label{fig:k-binary-search}\n\\end{figure}\n\n\\begin{comment} % KDT Node class\n\\begin{lstlisting}\n# import the BSTNode class from the previous lab.\n\nclass KDTNode(BSTNode):\n    \"\"\"Node class for K-D Trees. Inherits from BSTNode.\n    Attributes:\n        left (KDTNode): a reference to this node's left child.\n        right (KDTNode): a reference to this node's right child.\n        parent (KDTNode): a reference to this node's parent node.\n        data (ndarray): a coordinate in k-dimensional space.\n        axis (int): the dimension to make comparisons on.\n    \"\"\"\n    def __init__(self, data):\n        \"\"\"Construct a K-D Tree node containing 'data'. The left, right,\n        and prev attributes are set in the constructor of BSTNode.\n        \"\"\"\n        BSTNode.__init__(self, data)\n        self.axis  = 0\n\\end{lstlisting}\n\\end{comment}\n\n\\begin{problem} % KDTNode class\nCopy the \\li{BSTNode} class from the previous lab.%\\footnote{If the file containing the \\li{BSTNode} class is in a different directory than your solutions file for this lab, see \\url{https://docs.python.org/2/tutorial/modules.html\\#packages} for instructions on packages and imports.}\nWrite a \\li{KDTNode} class that inherits from \\li{BSTNode}.\n\nModify the constructor so that a \\li{KDTNode} can only hold a NumPy array (of type \\li{np.ndarray}).\nIf any other data type is given, raise a \\li{TypeError}.\nAlso create an \\li{axis} attribute (set it to \\li{None} or $0$ for now).\n\n\\begin{comment} % Magic methods (outdated)\n\\item Write the \\li{__sub__} magic method so that \\li{x} - \\li{y} returns the euclidean distance between the data in node \\li{x} and the data in node \\li{y}.\n\n\\item Write the \\li{__eq__} magic method so that \\li{x == y} is \\li{True} if and only if \\li{x} and \\li{y} have the same data (Hint: \\li{np.allclose()})\n\n\\item Finally, write the \\li{__lt__} and \\li{__gt__} magic methods so that the $<$ and $>$ operators compare the $i^{th}$ entry of the data, where $i$ is the \\li{axis} attribute of the node on the \\emph{right side} of the operator.\nFor example,\n\n\\begin{lstlisting}\n>>> x = KDTNode(np.array([1,2]))\n>>> y = KDTNode(np.array([3,1]))\n>>> y.axis = 0            # Compare the '0th' entry of the data\n>>> x < y                # True, since 1 < 3\nTrue\n>>> x > y\nFalse\n\n>>> y.axis = 1            # Compare the '1st' entry of the data\n>>> x < y                # False, since 2 > 1\nFalse\n>>> x > y\nTrue\n\\end{lstlisting}\n\\end{comment}\n\\end{problem}\n\n% Now we construct the $k$-d tree class.\n% For an optimal $k$-d tree, the data needs to be inserted in a very particular order.\n% However, inserting at random still usually produces a good tree.\n% Here we simply insert the data in the order that it is given.\n\n% TODO: put this elsewhere (in the problem statement?).\n\nThe major difference between a $k$-d tree and a binary search tree is how the data is compared at each depth level.\nThough we don't need to use a \\li{find()} method in solving the nearest neighbor problem, we provide the $k$-d tree version of \\li{find()} as an instructive example.\n\nIn the \\li{find()} method, every comparison in the recursive \\li{_step()} function compares the data of \\li{target} and \\li{current} based on the \\li{axis} attribute of \\li{current}.\nThis way if each existing node in the tree has the correct \\li{axis}, the correct comparisons are made as we descend through the tree.\n\n\\begin{lstlisting}\n# Copy or import the BST class from the previous lab.\n\nclass KDT(BST):\n    \"\"\"A k-dimensional binary search tree object.\n    Used to solve the nearest neighbor problem efficiently.\n\n    Attributes:\n        root (KDTNode): the root node of the tree. Like all other\n            nodes in the tree, the root houses data as a NumPy array.\n        k (int): the dimension of the tree (the 'k' of the k-d tree).\n    \"\"\"\n\n    def find(self, data):\n        \"\"\"Return the node containing 'data'. If there is no such node\n        in the tree, or if the tree is empty, raise a ValueError.\n        \"\"\"\n\n        # Define a recursive function to traverse the tree.\n        def _step(current):\n            \"\"\"Recursively step through the tree until the node containing\n            'data' is found. If there is no such node, raise a Value Error.\n            \"\"\"\n            if current is None:                     # Base case 1: dead end.\n                raise ValueError(str(data) + \" is not in the tree\")\n            elif np.allclose(data, current.value):\n                return current                      # Base case 2: data found!\n            elif data[current.axis] < current.value[current.axis]:\n                return _step(current.left)          # Recursively search left.\n            else:\n                return _step(current.right)         # Recursively search right.\n\n        # Start the recursion on the root of the tree.\n        return _step(self.root)\n\\end{lstlisting}\n\n\\begin{problem} % Implement the K-D Tree!\nFinish implementing the \\li{KDT} class.\n\\begin{enumerate}\n\\item Override the \\li{insert()} method.\nTo insert a new node, find the node that should be the parent of the new node by recursively descending through the tree as in the \\li{find()} method (see figure \\ref{fig:k-insert} for a geometric example).\nNote that the \\li{k} attribute of the will have to be set at some point.\n\nThe \\li{axis} attribute of the new node will be one more than that axis of the parent node.\nIf the last dimension of the data has been reached, start \\li{axis} over at 0.\n\n\\item To solve the nearest neighbor search problem, we need only create the $k$-d tree once.\nThen we can use it multiple times with different target points.\nTo prevent the user from altering the tree, disable the \\li{remove()} method.\nRaise a \\li{NotImplementedError} if the method is called, and allow it to receive any number of arguments.\n\\end{enumerate}\n\\end{problem}\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{figures/kdpic2.png}\n\\caption{To insert the point (4, 7) into the $k$-d tree of figure \\ref{fig:k-binary-search}, we find the node that will be the new node's parent. Start at the root, (5, 5). Since the $x$-coordinate of (4, 7) is less than the $x$-coordinate of (5, 5), we move into the region to the left of the middle blue line, to the root's left child, (3, 2). The $y$-coordinate of (4, 7) is greater than the $y$-coordinate of (3, 2), so we move above the red line on the left, to the right child (2, 6). Now we return to comparing the $x$-coordinates, and since $4 > 2$ and (2, 6) has no right child, we install (4, 7) as the right child of (2, 6).}\n\\label{fig:k-insert}\n\\end{figure}\n\nUsing a $k$-d tree to solve the nearest neighbor search problem requires some care.\nAt first glance, it appears that a procedure similar to \\li{find()} or \\li{insert()} will immediately yield the result.\nHowever, this is not always the case (see Figure \\ref{fig:bad-search}).\n\nTo correctly find the nearest neighbor we will keep track of the target point, the current search node, current best point, and current minimum distance.\nStart at the root node.\nThen the current search node and current best point will be root, and the current minimum distance will be the euclidean distance from \\li{root} to \\li{target}.\nWe then proceed recursively as in the \\li{find()} method.\nAs we find better points (nearer neighbors), we update the appropriate variables accordingly.\n\nOnce we have reached the bottom of the tree, we will have a good guess for the nearest neighbor.\nHowever, we are not guaranteed to have arrived at the correct point.\nOne way to ensure that we have arrived at the correct point is to draw a hypersphere with a radius of the current minimum distance around the candidate nearest neighbor.\nIf this hypersphere does not intersect any of the hyperplanes that split the $k$-d tree, then we know that have found a best point.\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{figures/kdpic3.png}\n\\caption{Suppose we want to find the point in the $k$-d tree of figure \\ref{fig:k-insert} that is closest to (8, 4.5). First we record the distance from the root to the target as the current minimum distance (about 3.04), then travel down the tree to the right. The right child, (8, 4), is only .5 units away from the target (the green circle), so we update the minimum distance. Since (8, 4) is not a leaf in the tree, we could continue down to the left child, (7, 7). However, this leaf node is much further from the target (the purple circle). To ensure that we terminate the algorithm correctly we check to see if the hypersphere of radius .5 around the current node (the green circle) intersects with any other hyperplanes. Since it does not, we stop descending down the tree and conclude (correctly) that (8, 4) is the nearest neighbor.}\n\\label{fig:bad-search}\n\\end{figure}\n\n\\begin{comment}\n\\begin{figure}\n\\caption{We need a figure here.  Something similar to what is found at http://web.stanford.edu/class/cs106l/handouts/assignment-3-kdtree.pdf, page 8.  This needs a great caption.\nI can write it when the figure is done. Of course we will need to have a reference to this document.}\n\\label{fig:hyperplanes}\n\\end{figure}\n\\end{comment}\n\nWhile we can not easily draw the correct hypersphere, there is an equivalent procedure that has a straightforward implementation in Python.\nBefore we finally decide to descend in one direction, we add the minimum distance to the $i^{th}$ entry of the target point's data, where $i$ is the \\li{axis} of the candidate nearest neighbor.\nIf this sum is greater that the $i^{th}$ entry of the current search node, then the hypersphere would necessarily intersect one of the hyperplanes drawn by the tree (why?).\n\nWe summarize the algorithm below.\n\n\\begin{algorithm}[h] % K-d search algorithm.\n\\begin{algorithmic}[1]\n\\State Given a set of data and a \\texttt{target}, build a $k$-d tree out of the data set.\n\\Procedure{Search}{\\texttt{current, neighbor, dist}}\n\\If {\\texttt{current} is \\texttt{None}}\n    \\Comment{Base case.}\n    \\State \\pseudoli{return} \\texttt{neighbor, dist}\n\\EndIf\n\\State \\texttt{index} $\\gets$ \\texttt{current.axis}\n\\If {metric(\\texttt{current, target}) $<$ \\texttt{dist}}\n    \\State \\texttt{neighbor} $\\gets$ \\texttt{current}\n        \\Comment{Update the best estimate.}\n    \\State \\texttt{dist} $\\gets$ metric(\\texttt{current, target})\n\\EndIf\n\\If {\\texttt{target[index]} $<$ \\texttt{current.value[index]}}\n    \\Comment{Recurse left.}\n    \\State \\texttt{neighbor, dist} $\\gets$ Search(\\texttt{current.left, neighbor, dist})\n    \\If {\\texttt{target[index]} + \\texttt{dist} $\\geq$ \\texttt{current.value[index]}}\n        \\State \\texttt{neighbor, dist} $\\gets$ Search(\\texttt{current.right, neighbor, dist})\n    \\EndIf\n\\Else\n    \\Comment{Recurse right.}\n    \\State \\texttt{neighbor, dist} $\\gets$ Search(\\texttt{current.right, neighbor, dist})\n    \\If{\\texttt{target[index]} - \\texttt{dist} $\\leq$ \\texttt{current.value[index]}}\n        \\State \\texttt{neighbor, dist} $\\gets$ Search(\\texttt{current.left, neighbor, dist})\n    \\EndIf\n\\EndIf\n\\State \\pseudoli{return} \\texttt{neighbor, dist}\n\\EndProcedure\n\\State Start \\textsc{Search()} at the root of the tree.\n\\end{algorithmic}\n\\caption{$k$-d tree nearest neighbor search}\n\\label{alg:kdneighborz}\n\\end{algorithm}\n\n\\begin{problem} % K-d nearest neighbor search algorithm.\nUse Algorithm \\ref{alg:kdneighborz} to write a function that solves the nearest neighbor search problem by searching through a $k$-d tree (your \\li{KDT} object).\nThe function should take in a data set and a single target point.\nReturn the nearest neighbor in the data set and the distance from the nearest neighbor to the target point, as in Problem 2 (be sure to return a NumPy array, not a KDTNode for the neighbor).\n\nTo test your function, use Scipy's built-in \\li{KDTree} object.\nThis structure behaves like the \\li{KDT} class, but its operations are heavily optimized.\nTo solve the nearest neighbor problem, initialize the tree with data, then `query' the tree with the target point.\nThe \\li{query} method returns a tuple of the minimun distance and the index of the nearest neighbor in the data.\n\n\\begin{lstlisting}\n>>> from scipy.spatial import KDTree\n\n# Initialize the tree with data (in this example we use random data).\n>>> data = np.random.random((100,5))\n>>> target = np.random.random(5)\n>>> tree = KDTree(data)\n\n# Query the tree and print the minimum distance.\n>>> min_distance, index = tree.query(target)\n>>> print(min_distance)\n0.309671532426\n\n# Print the nearest neighbor by indexing into the tree's data.\n>>> print(tree.data[index])\n[ 0.68001084  0.02021068  0.70421171  0.57488834  0.50492779]\n\\end{lstlisting}\n\\end{problem}\n\n\\section*{Handwriting Recognition} % ==========================================\n\n\\subsection*{Classification} % ------------------------------------------------\n\nSuppose that we are given a training set of data as well as a set of \\emph{labels} that describe each datum in the training set.\nFor example, suppose that we had a training set containing the incomes and debt levels of $N$ individuals.\nAlong with this data, we have a set $N$ labels that state whether the individual has filed for bankruptcy.\nThe classification problem is to try and assign the correct label to an unlabelled data point.\n\n\\subsection*{$k$-Nearest Neighbors} % -----------------------------------------\n\nIn our previous work, we used a $k$-d tree to find the nearest neighbor of a target point.\nA more general problem is to find the \\emph{k} nearest neighbors to a point (using some metric to measure ``distance'' between data points).\nIn classification, we find the $k$ nearest neighbors, we let each neighbor ``vote'' to decide what label to give the new point.\nFor example, consider the bankrupty case in the previous section.\nIf we find the 10 nearest neighbors to a new individual, and 8 of them went bankrupt, then we would predict that the individual will also go bankrupt.\nOn the other hand, if 7 of the nearest neighbors had not filed for bankruptcy, we would predict that the individual was at low risk for bankruptcy.\n\n\\subsection*{The Handwriting Recognition Problem} % ---------------------------\n\nThe problem of recognizing handwritten letters and numbers with a computer has many applications.\nA computer image may be thought of a vector in $\\mathbb{R}^n$, where $n$ is the number of pixels in the image and the entries represent how bright each pixel is.\nIf two people write the same number, we would expect the vectors representing a scanned image of those number to be close in the euclidean metric.\nThis insight means that given a training set of scanned images along with correct labels, we may confidently infer the label of a new scanned image.\n\n\\subsection*{sklearn} % -------------------------------------------------------\n\n%More information about this package can be found at http://scikit-learn.org/stable/modules/neighbors.html.\nThe \\li{sklearn} module contains powerful tools for solving the nearest neighbor problem.\nTo start nearest neighbors classification, we import the neighbors module from sklearn.\nThis module has a class for setting up a k-nearest neighbors classifier.\n\n\\begin{lstlisting}\n# Import the neighbors module\n>>> from sklearn import neighbors\n\n# Create an instance of a k-nearest neighbors classifier.\n# 'n_neighbors' determines how many neighbors to give votes to.\n# 'weights' may be 'uniform' or 'distance.'  The 'distance' option\n#     gives nearer neighbors more weight.\n# 'p=2' instructs the class to use the euclidean metric.\n>>> nbrs = neighbors.KNeighborsClassifier(n_neighbors=8, weights='distance', p=2)\n\\end{lstlisting}\n\nThe \\li{nbrs} object has two useful methods for classification.\nThe first, \\li{fit}, will take arrays of data (the training set) and labels and put them into a $k$-d tree.\nThis can then be used to find k-nearest neighbors, much like the \\li{KDT} class that we implemented previously.\n\n\\begin{lstlisting}\n# 'points' is some NumPy array of data\n# 'labels' is a NumPy array of labels describing the data in points.\n>>> nbrs.fit(points, labels)\n\\end{lstlisting}\n\nThe second method, \\li{predict}, will do a k-nearest neighbor search on the $k$-d tree and use the result to attach a label to unlabelled points.\n\n\\begin{lstlisting}\n# 'testpoints' is an array of unlabeled points.\n# Perform the search and calculate the accuracy of the classification.\n>>> prediction = nbrs.predict(testpoints)\n>>> np.average(prediction/testlabels)\n\\end{lstlisting}\n\n\\begin{problem} % Postal data problem.\nThe United States Postal Service has made a collection of labeled hand written digits available to the public, provided in \\texttt{PostalData.npz}.\nWe will use this data for k-nearest neighbor classification.\nThis data set may be loaded by using the following command:\n\n\\begin{lstlisting}\nlabels, points, testlabels, testpoints = np.load('PostalData.npz').items()\n\\end{lstlisting}\n\nThis contains a training set and a test set.\nThe first entry of each array is a name, so \\li{points[1]} and \\li{labels[1]} are the actual points and labels to use.\nEach point is an image that is represented by a flattened $28 \\times 28$ matrix of pixels.\nThe corresponding label indicates which number was written.\n\nClassify the testpoints with \\li{n_neighbors} as 1, 4 or 10, and with \\li{weights} as \\li{'uniform'} or \\li{'distance'}.\nFor each trial print a report indicating how your classifier performs in terms of percentage of correct classifications.\nWhich combination gives the most correct classifications?\n(Hint: define an inner function that takes in \\li{n_neighbors} and \\li{weights} as arguments calls the neighbors functions appropriately)\n\nA similar classification process is used by the United States Postal Service to automatically determine the zip code to send a letter to.\n\n\\begin{figure}[H]\n\\includegraphics[width=.25\\textwidth]{figures/Example.png}\n\\caption{An example of the number 6 taken from the data set}\n\\end{figure}\n\\end{problem}\n\n\\begin{comment}\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n% TODO (there's already some material on this in the oldLab/ folder)\n\\subsection*{The Curse of Dimensionality} % -----------------------------------\n\n\\end{comment}\n", "meta": {"hexsha": "9833d88d5bfed2f9af2c2a0b24d2e84104c76d98", "size": 24320, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol2A/DataStructures3-KDT/DS3.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol2A/DataStructures3-KDT/DS3.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol2A/DataStructures3-KDT/DS3.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 59.9014778325, "max_line_length": 843, "alphanum_fraction": 0.7237664474, "num_tokens": 6119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8080672181749422, "lm_q2_score": 0.8791467722591728, "lm_q1q2_score": 0.7104096866269493}}
{"text": "\\section{Finding eigenvalues}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find the characteristic polynomial, eigenvalues, and\n    eigenvectors of a matrix.\n  \\item Find the eigenvalues of a triangular matrix.\n  \\end{enumerate}\n\\end{outcome}\n\nIn the previous section, we saw how to find the eigenvectors\ncorresponding to a given eigenvalue $\\eigenvar$, if $\\eigenvar$ is already\nknown. But we have not yet seen how to find the eigenvalues of a\nmatrix. However, the calculations in\nExamples~\\ref{exa:find-eigenvectors-given-eigenvalue} and\n{\\ref{exa:basis-eigenspace}} suggest a way forward. We can see that\nthe following are equivalent:\n\\begin{enumerate}\n\\item $\\eigenvar$ is an eigenvalue of $A$.\n\\item There exists a non-zero vector $\\vect{v}$ such that\n  $A\\vect{v}=\\eigenvar\\vect{v}$.\n\\item The homogeneous system of equations\n  $(A-\\eigenvar I)\\vect{v}=\\vect{0}$ has a non-trivial solution.\n\\end{enumerate}\nIndeed, the equivalence between 1 and 2 is just the definition of an\neigenvalue, and the equivalence between 2 and 3 is just algebra.\nBy Corollary~\\ref{cor:determinant-homogeneous}, we know that the\nsystem $(A-\\eigenvar I)\\vect{v}=\\vect{0}$ has a non-trivial solution if\nand only if $\\det(A-\\eigenvar I)=0$. Therefore, we have proved the\nfollowing theorem:\n\n\\begin{theorem}{Eigenvalues}{eigenvalues}\n  Let $A$ be a square matrix, and let $\\eigenvar$ be a scalar. Then\n  $\\eigenvar$ is an eigenvalue of $A$ if and only if\n  \\begin{equation*}\n    \\det(A-\\eigenvar I)=0.\n  \\end{equation*}\n\\end{theorem}\n\n\\begin{example}{Finding the eigenvalues}{finding-eigenvalues}\n  Find the eigenvalues of the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      -5 & 2 \\\\\n      -7 & 4 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  By Theorem~\\ref{thm:eigenvalues}, a scalar $\\eigenvar$ is an\n  eigenvalue of $A$ if and only if $\\det(A-\\eigenvar I)=0$. We calculate\n  the determinant:\n  \\begin{eqnarray*}\n    \\det(A-\\eigenvar I)\n    &=&\n    \\begin{absmatrix}{cc}\n      -5-\\eigenvar & 2 \\\\\n      -7 & 4-\\eigenvar \\\\\n    \\end{absmatrix} \\\\\n    &=& (-5-\\eigenvar)(4-\\eigenvar) + 14 \\\\\n    &=& \\eigenvar^2 + \\eigenvar - 6.\n  \\end{eqnarray*}\n  Therefore, $\\eigenvar$ is an eigenvalue if and only if\n  $\\eigenvar^2 + \\eigenvar - 6 = 0$. We can find the roots of this\n  equation using the quadratic formula, or equivalently, by factoring\n  the left-hand side:\n  \\begin{equation*}\n    \\eigenvar^2 + \\eigenvar - 6 = 0\n    \\iff\n    (\\eigenvar+3)(\\eigenvar-2) = 0.\n  \\end{equation*}\n  Therefore, the eigenvalues are $\\eigenvar=-3$ and $\\eigenvar=2$.\n\\end{solution}\n\n\\begin{example}{Finding the eigenvalues}{finding-eigenvalues2}\n  Find the eigenvalues of the matrix\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rrr}\n      5 & -4 & 4 \\\\\n      2 & -1 & 2 \\\\\n      0 &  0 & 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  Once again, we calculate $\\det(A-\\eigenvar I)$:\n  \\begin{eqnarray*}\n    \\det(A-\\eigenvar I)\n    &=&\n        \\begin{absmatrix}{ccc}\n          5-\\eigenvar & -4 & 4 \\\\\n          2 & -1-\\eigenvar & 2 \\\\\n          0 &  0 & 2-\\eigenvar \\\\\n        \\end{absmatrix} \\\\\n    &=&\n        (5-\\eigenvar)(-1-\\eigenvar)(2-\\eigenvar) - 2(-4)(2-\\eigenvar) \\\\\n    &=& -\\eigenvar^3 + 6\\eigenvar^2 - 11\\eigenvar + 6 \\\\\n    &=& (3-\\eigenvar)(1-\\eigenvar)(2-\\eigenvar).\n  \\end{eqnarray*}\n  The eigenvalues are the roots of this polynomial, i.e., the\n  solutions of the equation\n  $(\\eigenvar-3)(\\eigenvar-1)(2-\\eigenvar)=0$. Therefore, the eigenvalues of\n  $A$ are $\\eigenvar=1$, $\\eigenvar=2$, and $\\eigenvar=3$.\n\\end{solution}\n\n\\begin{example}{No real eigenvalue}{no-real-eigenvalue}\n  Find the eigenvalues of the matrix\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rr}\n      0 & -1 \\\\\n      1 &  0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We have\n  \\begin{equation*}\n    \\det(A-\\eigenvar I)\n    ~=~\n        \\begin{absmatrix}{cc}\n          -\\eigenvar & -1 \\\\\n          1 & -\\eigenvar \\\\\n        \\end{absmatrix} \\\\\n    ~=~\n        \\eigenvar^2 + 1.\n  \\end{equation*}\n  Since $\\eigenvar^2+1 = 0$ does not have any solutions in the real\n  numbers, the matrix $A$ has no real eigenvalues. (However, if we\n  were working over the field of complex numbers rather than real\n  numbers, this matrix would have eigenvalues $\\eigenvar=\\pm i$).\n\\end{solution}\n\nAs the examples show, the quantity $\\det(A-\\eigenvar I)$ is always a\npolynomial in the variable $\\eigenvar$. A \\textbf{polynomial}%\n\\index{polynomial} is an expression of the form\n\\begin{equation*}\n  p(\\eigenvar) = a_n\\eigenvar^n + a_{n-1}\\eigenvar^{n-1} + \\ldots + a_1\\eigenvar + a_0,\n\\end{equation*}\nwhere $a_0,\\ldots,a_n$ are constants called the \\textbf{coefficients}%\n\\index{coefficient!of a polynomial}%\n\\index{polynomial!coefficient} of the polynomial. The polynomial\n$\\det(A-\\eigenvar I)$ has a special name:\n\n\\begin{definition}{Characteristic polynomial}{characteristic-polynomial}\n  Let $A$ be a square matrix. The expression\n  \\begin{equation*}\n    p(\\eigenvar) = \\det(A-\\eigenvar I)\n  \\end{equation*}\n  is called the \\textbf{characteristic polynomial}%\n  \\index{characteristic polynomial}%\n  \\index{polynomial!characteristic|see{characteristic polynomial}}%\n  \\index{matrix!characteristic polynomial} of $A$.\n\\end{definition}\n\n\\begin{example}{Characteristic polynomial}{characteristic-polynomial}\n  Find the characteristic polynomial of the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      3  & 0 &  2 \\\\\n      6  & 4 &  3 \\\\\n      -4 & 0 & -3 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The characteristic polynomial is\n  \\begin{eqnarray*}\n    \\det(A-\\eigenvar I) \\\\\n    &=&\n        \\begin{absmatrix}{ccc}\n          3-\\eigenvar  & 0 &  2 \\\\\n          6  & 4-\\eigenvar &  3 \\\\\n          -4 & 0 & -3-\\eigenvar \\\\\n        \\end{absmatrix} \\\\\n    &=&\n        (3-\\eigenvar)\\begin{absmatrix}{ccc}\n          4-\\eigenvar & 3 \\\\\n          0 & -3-\\eigenvar \\\\\n        \\end{absmatrix}\n    + 2 \\begin{absmatrix}{ccc}\n          6  & 4-\\eigenvar \\\\\n          -4 & 0 \\\\\n        \\end{absmatrix} \\\\\n    &=& (3-\\eigenvar)(4-\\eigenvar)(-3-\\eigenvar) + 8(4-\\eigenvar) \\\\\n    &=& -\\eigenvar^3 + 4\\eigenvar^2 + \\eigenvar - 4.\n  \\end{eqnarray*}\n  \\vspace{-8ex}\\par\n\\end{solution}\n\nIt is time to summarize the method for finding the eigenvalues and\neigenvectors of a matrix.\n\n\\begin{procedure}{Finding eigenvalues and eigenvectors}{find-eigenvalues-vectors}\n  \\index{eigenvalue!calculating}%\n  \\index{eigenvector!calculating}%\n  \\index{matrix!eigenvalue!calculating}%\n  \\index{matrix!eigenvector!calculating}%\n  Let $A$ be an $n\\times n$-matrix. To find the eigenvalues and\n  eigenvectors of $A$:\n  \\begin{enumerate}\n  \\item Calculate the characteristic polynomial $\\det(A-\\eigenvar I)$.\n  \\item The eigenvalues are the roots of the characteristic polynomial.\n  \\item For each eigenvalue $\\eigenvar$, find a basis for the\n    eigenvectors by solving the homogeneous system\n    \\begin{equation*}\n      (A-\\eigenvar I)\\vect{v} = \\vect{0}.\n    \\end{equation*}\n  \\end{enumerate}\n  To double-check your work, make sure that $A\\vect{v}=\\eigenvar\\vect{v}$\n  for each eigenvalue $\\eigenvar$ and associated eigenvector $\\vect{v}$.\n\\end{procedure}\n\n\\begin{example}{Finding eigenvalues and eigenvectors}{finding-eigenvalues-eigenvectors}\n  Find the eigenvalues and eigenvectors of the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      3  & 0 &  2 \\\\\n      6  & 4 &  3 \\\\\n      -4 & 0 & -3 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We already found the characteristic polynomial in\n  Example~\\ref{exa:characteristic-polynomial}. It is\n  \\begin{equation*}\n    p(\\eigenvar)\n    = \\det(A-\\eigenvar I)\n    = -\\eigenvar^3 + 4\\eigenvar^2 + \\eigenvar - 4.\n  \\end{equation*}\n  Finding the roots%\n  \\index{characteristic polynomial!root}%\n  \\index{matrix!characteristic polynomial!root}%\n  \\index{root!of a polynomial}%\n  \\index{polynomial!root}\n  of a cubic polynomial can be a bit tricky, but\n  with some trial and error, we can find that $\\eigenvar=1$ is a\n  root. We can therefore factor out $(\\eigenvar-1)$:\n  \\begin{equation*}\n    p(\\eigenvar) = (\\eigenvar-1)(-\\eigenvar^2+3\\eigenvar+4).\n  \\end{equation*}\n  Then we can use the quadratic formula to find the remaining two\n  roots:\n  \\begin{equation*}\n    \\eigenvar = \\frac{-3\\pm\\sqrt{9+16}}{-2},\n  \\end{equation*}\n  which yields the two roots $\\eigenvar=-1$ and $\\eigenvar=4$. Therefore,\n  we have\n  \\begin{equation*}\n    p(\\eigenvar) = -(\\eigenvar-1)(\\eigenvar+1)(\\eigenvar-4),\n  \\end{equation*}\n  and the eigenvalues of $A$ are $\\eigenvar=1$, $\\eigenvar=-1$, and\n  $\\eigenvar=4$. We now find the eigenvectors for each eigenvalue.\n  \\begin{itemize}\n  \\item {\\bf{\\underline{For $\\eigenvar=1$:}}} We must solve\n    $(A-I)\\/\\vect{v}=\\vect{0}$, i.e.,\n    \\begin{equation*}\n      \\begin{mymatrix}{rrr}\n        2  & 0 &  2 \\\\\n        6  & 3 &  3 \\\\\n        -4 & 0 & -4 \\\\\n      \\end{mymatrix}\\vect{v}=\\vect{0}.\n    \\end{equation*}\n    The basic solution is\n    \\begin{equation*}\n      \\vect{v}_1 = \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 1 \\end{mymatrix}.\n    \\end{equation*}\n  \\item {\\bf{\\underline{For $\\eigenvar=-1$:}}} We must solve\n    $(A+I)\\/\\vect{v}=\\vect{0}$, i.e.,\n    \\begin{equation*}\n      \\begin{mymatrix}{rrr}\n        4  & 0 &  2 \\\\\n        6  & 5 &  3 \\\\\n        -4 & 0 & -2 \\\\\n      \\end{mymatrix}\\vect{v}=\\vect{0}.\n    \\end{equation*}\n    The basic solution is\n    \\begin{equation*}\n      \\vect{v}_2 = \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 2 \\end{mymatrix}.\n    \\end{equation*}\n  \\item {\\bf{\\underline{For $\\eigenvar=4$:}}} We must solve\n    $(A-4I)\\vect{v}=\\vect{0}$, i.e.,\n    \\begin{equation*}\n      \\begin{mymatrix}{rrr}\n        -1  & 0 &  2 \\\\\n        6  & 0 &  3 \\\\\n        -4 & 0 & -7 \\\\\n      \\end{mymatrix}\\vect{v}=\\vect{0}.\n    \\end{equation*}\n    The basic solution is\n    \\begin{equation*}\n      \\vect{v}_3 = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix}.\n    \\end{equation*}\n  \\end{itemize}\n\\end{solution}\n\n\\begin{example}{A zero eigenvalue}{zero-eigenvalue}\n  Let\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rrr}\n      2 & 2 & -2 \\\\\n      1 & 3 & -1 \\\\\n      -1 & 1 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Find the eigenvalues and eigenvectors of $A$.\n\\end{example}\n\n\\begin{solution}\n  To find the eigenvalues of $A$, we first compute the characteristic\n  polynomial.\n  \\begin{equation*}\n    \\det(A-\\eigenvar I) =\n    \\begin{absmatrix}{ccc}\n      2-\\eigenvar & 2 & -2 \\\\\n      1 & 3-\\eigenvar & -1 \\\\\n      -1 & 1 & 1-\\eigenvar \\\\\n    \\end{absmatrix}\n    = -\\eigenvar^3+6 \\eigenvar^2-8\\eigenvar.\n  \\end{equation*}\n  You can verify that the roots of this polynomial are\n  $\\eigenvar_1 = 0$, $\\eigenvar_2 = 2$, $\\eigenvar_3 = 4$.  Notice that\n  while eigenvectors can never equal $0$, it is possible to have an\n  eigenvalue equal to $0$.  Now we will find the basic\n  eigenvectors.\n  \\begin{itemize}\n  \\item {\\bf{\\underline{For $\\eigenvar_1 =0$:}}} We must solve the\n    equation $(A-0I)\\vect{v} = \\vect{0}$. This equation becomes\n    $A\\vect{v}=\\vect{0}$. We write the augmented matrix for this\n    system and reduce to {\\ef}:\n    \\begin{equation*}\n      \\begin{mymatrix}{rrr|r}\n        2 & 2 & -2 & 0 \\\\\n        1 & 3 & -1 & 0 \\\\\n        -1 & 1 & 1 & 0 \\\\\n      \\end{mymatrix}\n      \\roweq\\ldots\\roweq\n      \\begin{mymatrix}{rrr|r}\n        1 & 0 & -1 & 0 \\\\\n        0 & 1 &  0 & 0 \\\\\n        0 & 0 &  0 & 0 \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n    The basic solution is\n    \\begin{equation*}\n      \\vect{v}_1\n      =\n      \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 1 \\end{mymatrix}.\n    \\end{equation*}\n  \\item {\\bf{\\underline{For $\\eigenvar_2=2$:}}} We solve the\n    equation $(A-2I)\\vect{v} = \\vect{0}$:\n    \\begin{equation*}\n      \\begin{mymatrix}{rrr|r}\n        0  & 2 & -2 & 0 \\\\\n        1  & 1 & -1 & 0 \\\\\n        -1 & 1 & -1 & 0 \\\\\n      \\end{mymatrix}\n      \\roweq\\ldots\\roweq\n      \\begin{mymatrix}{rrr|r}\n        1  & 0 &  0 & 0 \\\\\n        0  & 1 & -1 & 0 \\\\\n        0  & 0 &  0 & 0 \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n    The basic solution is\n    \\begin{equation*}\n      \\vect{v}_2\n      =\n      \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 1 \\end{mymatrix}.\n    \\end{equation*}\n  \\item {\\bf{\\underline{For $\\eigenvar_3=4$:}}} We solve the\n    equation $(A-4I)\\vect{v} = \\vect{0}$:\n    \\begin{equation*}\n      \\begin{mymatrix}{rrr|r}\n        -2 & 2  & -2 & 0 \\\\\n        1  & -1 & -1 & 0 \\\\\n        -1 &  1 & -3 & 0 \\\\\n      \\end{mymatrix}\n      \\roweq\\ldots\\roweq\n      \\begin{mymatrix}{rrr|r}\n        1 & -1 & 0 & 0 \\\\\n        0 &  0 & 1 & 0 \\\\\n        0 &  0 & 0 & 0 \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n    The basic solution is\n    \\begin{equation*}\n      \\vect{v}_3\n      =\n      \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}.\n    \\end{equation*}\n  \\end{itemize}\n  Thus we have found the eigenvectors $\\vect{v}_1$ for $\\eigenvar_1$,\n  $\\vect{v}_2$ for $\\eigenvar_2$, and $\\vect{v}_3$ for $\\eigenvar_3$.\n  We can double-check our answers by checking the equation\n  $A\\vect{v}=\\eigenvar\\vect{v}$ in each case:\n  \\begin{eqnarray*}\n    A\\vect{v}_1\n    &=&\n    \\begin{mymatrix}{rrr}\n      2 & 2 & -2 \\\\\n      1 & 3 & -1 \\\\\n      -1 & 1 & 1 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    =\n    \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    = 0\\vect{v}_1,\n    \\\\\n    A\\vect{v}_2\n    &=&\n    \\begin{mymatrix}{rrr}\n      2 & 2 & -2 \\\\\n      1 & 3 & -1 \\\\\n      -1 & 1 & 1 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    =\n    \\begin{mymatrix}{r} 0 \\\\ 2 \\\\ 2 \\end{mymatrix}\n    = 2\\vect{v}_2,\n    \\\\\n    A\\vect{v}_3\n    &=&\n    \\begin{mymatrix}{rrr}\n      2 & 2 & -2 \\\\\n      1 & 3 & -1 \\\\\n      -1 & 1 & 1 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    =\n    \\begin{mymatrix}{r} 4 \\\\ 4 \\\\ 0 \\end{mymatrix}\n    = 4\\vect{v}_3.\n  \\end{eqnarray*}\n  Therefore, our eigenvectors and eigenvalues are correct.\n\\end{solution}\n\nWe conclude this section by considering the eigenvalues of a\ntriangular matrix. Recall from\nDefinition~\\ref{def:triangular-matrices} that a matrix is\n\\textbf{upper triangular}%\n\\index{matrix!upper triangular!eigenvalues of}%\n\\index{matrix!triangular!eigenvalues of}%\n\\index{upper triangular matrix!eigenvalues}%\n\\index{triangular matrix!eigenvalues}%\n\\index{eigenvalue!of triangular matrix}\nif all entries below the main diagonal are\nzero, and \\textbf{lower triangular}%\n\\index{matrix!lower triangular!eigenvalues of}%\n\\index{lower triangular matrix!eigenvalues}\nif all entries above the main\ndiagonal are zero.\n\n\\begin{example}{Eigenvalues of a triangular matrix}{eigenvalues-triangular-matrix}\n  Find the eigenvalues of\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rrr}\n      1 & 2 & 4 \\\\\n      0 & 4 & 7 \\\\\n      0 & 0 & 6 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We calculate $\\det(A - \\eigenvar I) = 0$ as follows:\n  \\begin{eqnarray*}\n    \\det (A - \\eigenvar I) =\n    \\det \\begin{mymatrix}{ccc}\n      1-\\eigenvar & 2 & 4 \\\\\n      0 & 4-\\eigenvar & 7 \\\\\n      0 & 0 & 6-\\eigenvar \\\\\n    \\end{mymatrix} = (1-\\eigenvar)(4-\\eigenvar)(6-\\eigenvar).\n  \\end{eqnarray*}\n  Solving the equation $(1-\\eigenvar)(4-\\eigenvar)(6-\\eigenvar) = 0$\n  results in the eigenvalues $\\eigenvar_1 = 1$, $\\eigenvar_2 = 4$, and\n  $\\eigenvar_3 = 6$.  Thus the eigenvalues are the entries on the main\n  diagonal of $A$.\n\\end{solution}\n\nClearly, the same is true for any (upper or lower) triangular\nmatrix. We therefore have the following proposition:\n\n\\begin{proposition}{Eigenvalues of a triangular matrix}{eigenvalues-triangular-matrix}\n  Let $A$ be an upper or lower triangular matrix. Then the eigenvalues\n  of $A$ are the entries on the main diagonal.\n\\end{proposition}\n", "meta": {"hexsha": "565c9f67fee12607838d2150fffe75e3a2c2fe55", "size": 15663, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Eigenvalues-Finding.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Eigenvalues-Finding.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Eigenvalues-Finding.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 31.8353658537, "max_line_length": 87, "alphanum_fraction": 0.6122071123, "num_tokens": 5685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.808067204308405, "lm_q2_score": 0.8791467675095292, "lm_q1q2_score": 0.7104096705981966}}
{"text": "\\chapter{Batch Normalization}\nIn this chapter, we discuss the batch normalization (BN) technique. The aim of BN is to avoid gradient explosion or disappearance, which makes the training process unstable, i.e. the gradient is either too large or too small to be a reasonable update.\n\n\\section{The Definition of Batch Normalization}\nBN can be applied to any layer of a neural network, where it normalizes, scales and shifts an internal computation result. It in fact includes two parts, one for the training procedure and one for the test.\n\n\\subsection{Model w.r.t loss function: an idea to ``understand\" BN}\nIn fact, BN is just a new model, and then use the general SGD w.r.t mini-batch type! The new model of BN is like:\n\\begin{equation}\\label{BN-model}\nL(\\Theta) = \\sum_{i \\in I} \\frac{1}{|N|} \\|\\tilde {f}^J(x_i;\\Theta) - y_i\\|^2,\n\\end{equation}\nas $I = \\{1, 2,\\cdots,N\\}$ is the {\\bf all data}.  \nWe can rewrite it as:\n\\begin{equation}\\label{BN-model1}\nL(\\Theta) = \\mathbb{E}_{i} \\|\\tilde {f}^J(x_i;\\Theta) - y_i\\|^2.\n\\end{equation}\nNow we define $\\tilde {f}^J(x_i;\\Theta)$ as:\n\\begin{equation}\n\\tilde f^j = \\theta^j \\circ \\text{\\text{BN}}_{I} ( g^j\\circ\\tilde f^{j-1}).\n\\end{equation}\nor, as it may perform better in practice,\n\\begin{equation}\n\\tilde f^j = \\theta^j \\circ g^j \\circ \\text{\\text{BN}}_{I} (\\tilde f^{j-1}),\n\\end{equation}\nSo what we will explain is based the second form.\nAt layer $j$, with a scaling factor $\\gamma^j\\in\\mathbb{R}$ and a shifting $\\beta^j \\in \\mathbb{R}$, $\\text{BN}_I$ is defined as\n\\begin{equation}\n\\text{BN}_{I}(x)= \\gamma^j\\frac{x - \\mu_I^j}{\\sigma_I^j}+\\beta^j \\bm{1},\n\\end{equation}\nwhere $\\mu^j$ is the mean value and $\\sigma^j$ is the standard deviation of the all date i.e.\n\\begin{align}\n\\mu_I^j &= \\frac{\\sum_{i\\in I}  x_i }{|I|},\\\\\n\\sigma_I^j  &= \\sqrt{ \\delta + \\frac{ \\sum_{i\\in I} ( x_i - \\mu_I^j)^2}{|I|-1} }.\n\\end{align}\nwhere $\\delta$ is an extra term for numerical stability, and the square in $(  x_i - \\mu^j)^2$ is an element-wise square operation.\n\nNote that $\\gamma^j$ and $\\beta^j$ are parameters to be trained.\n\nIf BN is added after the linear transformation, i.e.\n\\begin{equation}\n\\text{BN}_I(f^{j-1}(X_i))=\\text{BN}_{I}(WX_i + b),\n\\end{equation}\nthe bias $b$ is in fact removed by BN, thus\n\\begin{equation}\n\\text{BN}_I(f^{j-1}(X_i))=\\text{BN}_I(WX_i).\n\\end{equation}\n\n\n\\subsection{Training Process:  approximated SGD}\nNow to train BN model, we still use SGD, so we just sample a subset of data as $S \\subset I$ and compute gradient on this mini-batch.  \n\n{\\bf But to compute the $\\mu^j_I$ is very expensive, and we can simply use the idea in statistics i.e use the sampled data $S$ to approximate $I$.} \n\nSo for every step, the corresponding object function to be take gradient can be written as:\n\\begin{equation}\n\t\\sum_{i \\in S} \\|\\tilde {f}^J(x_i) - y_i\\|^2,\n\\end{equation}\nwhere for each layer $\\tilde f^j$,\n\\begin{equation}\n\\tilde f^j = \\theta^j \\circ \\text{\\text{BN}}_{S} ( g^j\\circ\\tilde f^{j-1}).\n\\end{equation}\nor, as it may perform better in practice,\n\\begin{equation}\n\\tilde f^j = \\theta^j \\circ g^j \\circ \\text{\\text{BN}}_{S} (\\tilde f^{j-1}),\n\\end{equation}\nSo what we will explain is based the second form.\n\nAt layer $j$, with a scaling factor $\\gamma^j\\in\\mathbb{R}$ and a shifting $\\beta^j \\in \\mathbb{R}$, $\\text{BN}_S$ is defined as\n\\begin{equation}\n\\text{BN}_{S}(x)= \\gamma^j\\frac{x - \\mu_S^j}{\\sigma_S^j}+\\beta^j \\bm{1},\n\\end{equation}\nwhere $\\mu^j$ is the mean value and $\\sigma^j$ is the standard deviation of the input mini-batch, i.e.\n\\begin{align}\n\\mu^j_I \\approx \\mu_S^j &= \\frac{\\sum_{i\\in S}  x_i }{|S|},\\\\\n\\mu_I^j \\approx \\sigma_S^j  &= \\sqrt{ \\delta + \\frac{ \\sum_{i\\in S} ( x_i - \\mu_S^j)^2}{|S|-1} }.\n\\end{align}\nwhere $\\delta$ is an extra term for numerical stability, and the square in $(  x_i - \\mu^j)^2$ is an element-wise square operation.\n\nNote that $\\gamma^j$ and $\\beta^j$ are parameters to be trained.\n\nWith the trainable parameters in $\\text{BN}_S$, the derivative now becomes\n\\begin{align}\n\\frac{\\partial \\tilde f^j}{ \\partial \\theta^{j-1}} &= \\theta^j \\circ (g^j)' \\circ \\frac{\\partial \\text{BN}_{S} (\\tilde f^{j-1})}{ \\partial \\theta^{j-1}} \\\\\n&=  \\theta^j \\circ (g^j)' \\circ \\left(\\frac{\\partial \\text{BN}_{S} (\\tilde f^{j-1})}{ \\partial \\mu^j}\\frac{\\partial \\mu^j}{\\partial \\theta^j} + \\frac{\\partial \\text{BN}_{S} (\\tilde f^{j-1})}{ \\partial \\sigma^j}\\frac{\\partial \\sigma^j}{\\partial \\theta^j} + \\frac{\\partial \\text{BN}_{S} (\\tilde f^{j-1})}{ \\partial \\tilde f^j}\\frac{\\partial \\tilde f^j}{\\partial \\theta^j}  \\right).\n\\end{align}\nThe gradient of $\\gamma$ and $\\beta$ are trivial. The back-propagation process can then be applied to optimize the model.\n\n\\subsection{Testing Process: recover $\\mu_I$ and $\\sigma_I$ from all samples}\nConsidering that a mini-batch is an approximation of the whole dataset, the mean value $\\mu$ and standard deviation $\\sigma$ of BN in each layer, should be the same, all being of the whole dataset.\n\n\n%at the testing time, they are replaced by those of the whole dataset, i.e.\n%\\begin{align}\\label{bnbatch}\n%\t\\mu_I&\\approx \\mu = \\frac{1}{n_\\mathcal{B}}\\sum_{B\\in\\mathcal{B}}\\mu_B,\\\\\n%\t\\sigma^2_I&\\approx \\sigma^2 = \\frac{1}{n_\\mathcal{B}}\\sum_{B\\in\\mathcal{B}}\\sigma^2_{\\mathcal{B}},\n%\\end{align}\n%where $\\mathcal{B}$ is the set of all mini-batches.\nThus, after optimizing the model,  use the moving average scheme as:\n\\begin{equation}\\label{BN-timeaverage}\n\\mu_t=\\rho*\\mu_t+(1-\\rho)*\\bar\\mu_{t-1} \\quad \\sigma_t=\\rho*\\beta_t+(1-\\rho)*\\bar\\sigma_{t-1},\n\\end{equation}\nwith $\\mu_t$ and $\\sigma_t$ is the $\\mu_{S_t}$ and $\\sigma_{S_t}$ in step t. {\\bf But we don't use the updated $\\mu_{S_t}$ or $\\sigma_{S_t}$ in training phase, we just note them and use for approximate the real $\\mu_I$ and $\\sigma_I$ in previous BN model.} \n\nThe parameters $\\gamma$ and $\\beta$ will be kept.\n\n\\subsection{Implementation of batch normalization}\nBatch normalization (BN) can be viewed as a function $\\text{BN}(x)$, where\n\n\\begin{enumerate}\n\t\\item in 1D case, $x\\in\\mathbb{R}^{m\\times C\\times n}$,\n\t\\item in 2D case, $x\\in\\mathbb{R}^{m\\times C\\times H \\times W}$,\n\t\\item in 3D case, $x\\in \\mathbb{R}^{m\\times C\\times D \\times H \\times W}$.\n\\end{enumerate}\nWhat matters is $m$, the number of input samples, and $C$, the number of channels.\n\n$H$, $W$, $D$ means height, width, and depth respectively, in 2D or 3D case, and $n$ simply means the length of a sample in 1D case.\n\nBecause only $m$ and $C$ are necessary for BN, we will denote $x_{i,c}$ as a tensor, where $i$, $c$ is the first and the second index of $x$, i.e. the dimension of $n$, $H$, $W$, $D$ are omitted.\n\nThe definition of $\\text{BN}(x)$, denoted as $y$, is\n\\begin{equation}\n\t\\begin{aligned}\n\t\ty&=\\text{BN}(x),\\\\\n\t\ty_{i,c}&=\\gamma_c\\frac{x_{i,c}-\\text{mean}_i[x_{i,c}]}{\\sqrt[]{\\text{Var}_i[x_{i,c}]+\\epsilon}}+\\beta_c,\n\t\\end{aligned}\n\\end{equation}\nwhere $\\text{mean}_i[x_{i,c}]$ is the mean of $x_{i,c},\\ i\\in I$ and $\\text{Var}_i[x_{i,c}]$ is the variance of $x_i, i\\ \\in I$. $\\gamma_c,\\beta_c\\in\\mathbb{R}$ are the trainable parameters, often called the scale and the shift, respectively. $\\epsilon$ is used for numerical stability.\n\nIn the training process, like all the other parameters such as $W$ and $b$, $\\gamma,\\beta$ will be updated with $\\nabla_\\gamma L$ and $\\nabla_\\beta L$, where $L$ is the loss function. \n\nIn practice, mean $\\mu$ and var $\\sigma$ are in fact the running estimates $\\bar\\mu$, $\\bar\\sigma$, i.e. \n\\begin{equation}\n\t\\begin{aligned}\n\t\t&\\text{Initialize running estimates, }&\\bar\\mu_0=0,\\ \\bar\\sigma_0=1,\\\\\n\t\t&\\text{At time step t, compute mean and var, }&\\mu_t=\\text{mean}_i[x_{i,c}],\\ \\sigma_t=\\text{Var}_i[x_{i,c}],\\\\\n\t\t&\\text{Update running estimates, }&\\bar\\mu_t=\\rho*\\mu_t+(1-\\rho)*\\bar\\mu_{t-1},\\\\\n\t\t&&\\bar\\sigma_t=\\rho*\\beta_t+(1-\\rho)*\\bar\\sigma_{t-1},\\\\\n\t\\end{aligned}\n\\end{equation}\nwhere $\\rho$ is the momentum, $\\rho\\in(0,1)$ and $\\rho\\approx 0.1$ in practice.\n\nIn the testing process, the final $\\bar\\mu$ and $\\bar\\sigma$ are used to normalize the input.\n\nBN is often used before activation functions, e.g. a one-hidden-layer neural network with BN can be written as\n\\begin{equation}\n\t\\label{bn_1hidden}\n\tf(x)=\\theta_2\\circ \\text{ReLU1}\\circ\\text{BN}\\circ\\theta_1\\circ x.\n\\end{equation}\n\n\\begin{figure}[htbp]\n\t\\centering{\\includegraphics[width=10cm]{BN_NoBN.png}}\n\t\\caption{Comparison of BN on ResNet10, CIFAR-10}\n\t\\label{alo: large k}\n\\end{figure}\n\n%{\\bf For test phase}, to the $\\hat \\mu^j$ and $\\hat \\sigma^j$ are computed\n%by averaging those $\\mu^j$ and $\\sigma^j$ in training phase. In training phase, suppose we have those next training process with mini-batch $S_t$ for $t = 1:T$. So, after $T$ steps gradient descent, those $\\theta^j$ have been trained well, and we get:\n%\\begin{equation}\n%\\mu^j_{t}, \\sigma^j_t, \\quad t = 1:T,\n%\\end{equation}\n%So the test model is\n%\\begin{equation}\n%f(x) = \\hat{f}^J(x),\n%\\end{equation}\n%with\n%\\begin{equation}\n% \\hat{f}^j(x) = \\theta^j \\circ g^j \\circ \\hat{\\text{BN}}^j(\\hat f^{j-1})\n%\\end{equation}\n%for\n%\\begin{equation}\n%\\hat{\\text{BN}}^j( \\hat f^{j-1}(x_i) )= \\frac{\\hat f^{j-1}(x_i) - \\hat \\mu^j}{\\hat \\sigma^j},\n%\\end{equation}\n%where\n%\\begin{equation}\n%\\hat \\mu^j =\\frac{\\sum_{i=1}^T \\mu^j_t }{T},\n%\\end{equation}\n%and\n%\\begin{equation}\n%\\hat \\sigma^j  = \\frac{\\sum_{i=1}^T \\sigma^j_t }{T}.\n%\\end{equation}\n%\n%In some situation, they may use the similar strategy like the momentum for SGD, then may get $\\hat \\mu^j$ and $\\hat \\sigma^j$ by: For $t= 1 :T$\n%\\begin{equation}\n%\\hat \\mu^j = 0.9 \\hat \\mu^j + 0.1 \\mu^j_t,\n%\\end{equation}\n%and the similar operation for $\\hat \\sigma^j$\n\n\\subsection{An example}\nNow consider a simple case in the Deep Learning Book, where\n\\begin{enumerate}\n\\item there's no activation function,\n\\item all layers have only one neuron and no bias, i.e. $\\theta(x) = wx$.\n\\end{enumerate}\n$f$ is further defined to have $J$ layers, i.e.\n\\begin{equation}\n\tf(x) = w_J w_{J-1} \\cdots w_2 w_1 x,\n\\end{equation}\nwith the loss function\n\\begin{equation}\n\tL(w_1, \\cdots, w_J) = \\sum_{i = 1}^N\\frac{1}{2} (f(x_i) - y_i)^2.\n\\end{equation}\nThe gradients can then be computed as\n\\begin{align}\n\t\\frac{\\partial L}{\\partial f(x_i)}&=f(x_i)-y_i,\\\\\n\t\\frac{\\partial f}{\\partial w_i}&=\\frac{f(x)}{w_i}=x\\prod_{j\\neq i}w_j.\n\\end{align}\nThe problem is that, if $w_j,2\\leq j\\leq J$ are updated with $\\epsilon\\Delta w_j$, the update of $w_1$ would be \n\\begin{equation}\n\t\\frac{\\partial f}{\\partial w_1}=x\\prod_{j\\geq2}(w_j+\\epsilon\\Delta w_j),\n\\end{equation}\nwhich multiplies the change of parameters, and when $J$ is larger, the effect is stronger. If the change is scaling up, this may introduce gradient explosion, or disappearance if it's scaling down.\n\nOne may adjust the learning rate $\\epsilon$ to moderate this effect, but this is hard in practice.\n\n%Now we suppose to decrease the value for $f$ by $0.1$ at $x$. With the first order approximation of $f$, we know that $f$ will decrease about\n%\\begin{equation}\n%\\epsilon \\|\\bm{g}\\|^2,\n%\\end{equation}\n%with\n%\\begin{equation}\n%\\bm{w} \\leftarrow \\bm{w} - \\epsilon \\bm{g}.\n%\\end{equation}\n%\n%However, for really situation, we have\n%\\begin{equation}\n%f(x) = (w_J - \\epsilon g_J)\\cdots(w_1 - \\epsilon g_1)x.\n%\\end{equation}\n%For one term in seconder approximation like:\n%\\begin{equation}\n%\\epsilon^2 g_1 g_2 \\Pi_{i=3}^J w_i x.\n%\\end{equation}\n%Because we connot control the value of $\\Pi_{i=3}^J w_i x$, it can be very small or extremely large so {\\bf it it very difficult to choose suitable learning rate.}\n\nWith BN, the model is changed to\n\\begin{equation}\n\\tilde f(x) = w_J \\tilde f^{J-1}(x),\n\\end{equation}\nwhere the update is normalized.\n%with $\\tilde f^{J-1}$ has the stander statistics( or $\\gamma$ and $\\eta$ by adaptivity). If we don't use \\text{BN}, we know that for any $w_j$ with $j = 1:J-1$ can effect the $f(x)$ remarkably like $w_j = 0$ makes this network degeneration or $w_j = -w_j$ changes the prediction of $f(x)$ totally. Without normalization, nearly every update would have an extreme effect on the statistics of $f^{J-1}$.\n%\n%Now suppose that $x$ is drawn from a unit Gaussian i.e:\n%\\begin{equation}\n%x \\sim \\mathcal{N}(0,1).\n%\\end{equation}\n% Then the original method $f$ is also Gaussian but not unit it depended w.r.t $\\bm{w}$:\n%\\begin{equation}\n%f \\sim \\mathcal{N}(\\mu({\\bm{w}}),\\sigma(\\bm{w})).\n%\\end{equation}\n%But if we use \\text{BN}, here $\\tilde h^{J-1}$ becomes unit Gaussian again, i.e\n%\\begin{equation}\n%\\tilde f^{J-1} \\sim \\mathcal{N}(0,1).\n%\\end{equation}  So $\\tilde f$ is an Gaussian only depends on $\\omega_J$,\n%\\begin{equation}\n%\\tilde f \\sim \\mathcal{N}(\\mu(w_J),\\sigma(w_J)).\n%\\end{equation}  which means we just need to trained $w_J$ all $w_j$ for $j=1:J-1$ make no sense for this model. So, what we only need to train is only $w_J$, this make the training process very fast.\n\nAs it says in the book,\n\\begin{quotation}\n\t\\emph{\n\t\tBatch normalization has thus made this model significantly easier to learn. In this example, the ease of learning of course came at the cost of making the lower layers useless. In our linear example, the lower layers no longer have any harmful effect, but they also no longer have any beneficial effect. This is because we have normalized out the first and second order statistics, which is all that a linear network can influence. In a deep neural network with nonlinear activation functions, the lower layers can perform nonlinear transformations of the data, so they remain useful. Batch normalization acts to standardize only the mean and variance of each unit in order to stabilize learning, but allows the relationships between units and the nonlinear statistics of a single unit to change.}\n\\end{quotation}\n\n%\\input{6DL/XN}\n\n%\\input{6DL/jinchao-XN}\n", "meta": {"hexsha": "98f623a5a418ebac6d066b97612590b45d19da03", "size": 13663, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/bn_old.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/bn_old.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/bn_old.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.3646616541, "max_line_length": 799, "alphanum_fraction": 0.6879162702, "num_tokens": 4657, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046026642945, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.710377635905315}}
{"text": "\\chapter{Sum of Random Variables of Probability Distribution}\n\\label{ch:sum_rv}\n\n\n\\section{Sum $R = X + Y$}\n\nStatAnaly supports the sum of random variable in the format of $R = X + Y$, where $X$ and $Y$ are random variables of probability distributions.\nThe supported combinations of the distributions are listed in the section.\n\n\\subsection{Standard Uniform \\& Standard Uniform (continuous)}\n    \\begin{equation}\n        R = \\sum_{i=1}^2 X_i \\qquad \n        X_i \\sim \\text{StdUniform}, \\quad \n        R \\sim \\text{Irwin-Hall}(2)\n    \\end{equation}\n\n\\subsection{Normal \\& Normal}\n\n    \\begin{equation}\n        R = \\sum_{i=1}^2 X_i \\qquad \n        X_i \\sim \\text{Normal}(\\mu_i,\\sigma_i), \\quad \n        R \\sim \\text{Normal}\\left(\\sum _{i=1}^{2}\\mu _{i},\\sum _{i=1}^{2}\\sigma _{i}^{2}\\right)\n    \\end{equation}\n\n\\subsection{Cauchy \\& Cauchy}\n\n    \\begin{equation}\n        R = \\sum_{i=1}^2 X_i \\qquad \n        X_i \\sim \\text{Cauchy}(m_i,b_i), \\quad \n        R \\sim \\text{Cauchy}\\left(\\sum _{i=1}^{2}m_{i},\\sum _{i=1}^{2}b _{i}\\right)\n    \\end{equation}\n\n\\subsection{Gamma \\& Gamma}\n\n    \\begin{equation}\n        R = \\sum_{i=1}^2 X_i \\qquad \n        X_i \\sim \\text{Gamma}(\\alpha_i,\\theta), \\quad \n        R \\sim \\text{Gamma}\\left(\\sum _{i=1}^{2}\\alpha_{i},\\theta \\right)\n    \\end{equation}\n\n\\subsection{Exponential \\& Exponential}\n\n    \\begin{equation}\n        R = \\sum_{i=1}^2 X_i \\qquad \n        X_i \\sim \\text{Exponential}(\\theta), \\quad \n        R \\sim \\text{Erlang}\\left(2, \\theta \\right)\n    \\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{List of supported sum $R = X^2 + Y^2$}\n\nStatAnaly supports the sum of random variable in the format of $R = X^2 + Y^2$, where $X$ and $Y$ are random variables of probability distributions.\nThe supported combinations of the distributions are listed in the section.\n\n\\subsection{Normal \\& Normal}\n\n\\begin{equation}\n    R = \\sum_{i=1}^2 X_i^2 \\qquad \n    X_i \\sim \\text{Normal}(0,1), \\quad \n    R \\sim \\text{Chi-Squared}\\left( 2 \\right)\n\\end{equation}\n\n\\begin{equation}\n    R = \\sum_{i=1}^2 X_i^2 \\qquad \n    X_i \\sim \\text{Normal}(\\mu_i,1), \\quad \n    R \\sim \\text{Non-central Chi-Squared}\\left(2, \\sum _{i=1}^{2}\\mu _{i}^2\\right)\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{List of supported sum $R = \\sqrt{X^2 + Y^2}$}\n\nStatAnaly supports the sum of random variable in the format of $R = \\sqrt{X^2 + Y^2}$, where $X$ and $Y$ are random variables of probability distributions.\nThe supported combinations of the distributions are listed in the section.\n\n\\subsection{Normal \\& Normal}\n\n\\begin{equation}\n    R = \\sqrt{ \\sum_{i=1}^2 X_i^2 } \\qquad \n    X_i \\sim \\text{Normal}(0,\\sigma^2), \\quad \n    R \\sim \\text{Rayleigh}\\left( \\sigma \\right)\n\\end{equation}\n\n\\begin{equation}\n    R = \\sqrt{ \\sum_{i=1}^2 X_i^2 } \\qquad \n    X_i \\sim \\text{Normal}(\\mu_i,\\sigma^2), \\quad \n    R \\sim \\text{Rician}\\left(\\sqrt{\\sum _{i=1}^{2}\\mu _{i}^2}, \\sigma \\right)\n\\end{equation}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{List of supported sum $R = \\sum_i X_i$}\n\nStatAnaly supports the sum of random variable in the format of $R = \\sum_i X_i$, where $X$ is random variable of a probability distribution.\nThe supported combinations of the distributions are listed in the section.\n\n\\subsection{Array of Standard Uniform}\n    \\begin{equation}\n        R = \\sum_{i=1}^n X_i \\qquad \n        X_i \\sim \\text{StdUniform}, \\quad \n        R \\sim \\text{Irwin-Hall}(n)\n    \\end{equation}\n\n\\subsection{Array of Normal}\n    \\begin{equation}\n        R = \\sum_{i=1}^n X_i \\qquad \n        X_i \\sim \\text{Normal}(\\mu_i,\\sigma_i), \\quad \n        R \\sim \\text{Normal}\\left(\\sum _{i=1}^{n}\\mu _{i},\\sum _{i=1}^{n}\\sigma _{i}^{2}\\right)\n    \\end{equation}\n\n\\subsection{Array of Cauchy}\n\n    \\begin{equation}\n        R = \\sum_{i=1}^n X_i \\qquad \n        X_i \\sim \\text{Cauchy}(m_i,b_i), \\quad \n        R \\sim \\text{Cauchy}\\left(\\sum _{i=1}^{n}m_{i},\\sum _{i=1}^{n}b _{i}\\right)\n    \\end{equation}\n\n\\subsection{Array of Gamma}\n\n    \\begin{equation}\n        R = \\sum_{i=1}^n X_i \\qquad \n        X_i \\sim \\text{Gamma}(\\alpha_i,\\theta), \\quad \n        R \\sim \\text{Gamma}\\left(\\sum _{i=1}^{n}\\alpha_{i},\\theta \\right)\n    \\end{equation}\n\n\\subsection{Array of Exponential}\n\n    \\begin{equation}\n        R = \\sum_{i=1}^n X_i \\qquad \n        X_i \\sim \\text{Exponential}(\\theta), \\quad \n        R \\sim \\text{Erlang}\\left(n, \\theta \\right)\n    \\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{List of supported sum $R = \\sum_i X_i^2$}\n\nStatAnaly supports the sum of random variable in the format of $R = \\sum_i X_i^2$, where $X$ is random variable of a probability distribution.\nThe supported combinations of the distributions are listed in the section.\n\n\\subsection{Array of Normal}\n\n\\begin{equation}\n    R = \\sum_{i=1}^n X_i^2 \\qquad \n    X_i \\sim \\text{Normal}(0,1), \\quad \n    R \\sim \\text{Chi-Squared}\\left( n \\right)\n\\end{equation}\n\n\\begin{equation}\n    R = \\sum_{i=1}^n X_i^2 \\qquad \n    X_i \\sim \\text{Normal}(\\mu_i,1), \\quad \n    R \\sim \\text{Non-central Chi-Squared}\\left(2, \\sum _{i=1}^{n}\\mu _{i}^2\\right)\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{List of supported sum $R = \\sqrt{\\sum_i X_i^2}$}\n\nStatAnaly supports the sum of random variable in the format of $R = \\sqrt{\\sum_i X_i^2}$, where $X$ is random variable of a probability distribution.\nThe supported combinations of the distributions are listed in the section.\n\n\\subsection{Array of Normal}\n\n\\begin{equation}\n    R = \\sqrt{ \\sum_{i=1}^n X_i^2 } \\qquad \n    X_i \\sim \\text{Normal}(0,1), \\quad \n    R \\sim \\text{Chi}\\left( n \\right)\n\\end{equation}\n\n\\begin{equation}\n    R = \\sqrt{ \\sum_{i=1}^n X_i^2 } \\qquad \n    X_i \\sim \\text{Normal}(\\mu_i,1), \\quad \n    R \\sim \\text{Non-central Chi} \\left( 2, \\sqrt{\\sum _{i=1}^{n}\\mu _{i}^2} \\right)\n\\end{equation}\n\n\n\n", "meta": {"hexsha": "d8f2e6e6defbaeabc512da25b398a8b87a0ea9d2", "size": 5900, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/Documentation/chapter_sum_of_RV.tex", "max_stars_repo_name": "AnselGitAccount/StatAnaly", "max_stars_repo_head_hexsha": "93cbffd54d212056e023fce90b0386825af49a88", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/Documentation/chapter_sum_of_RV.tex", "max_issues_repo_name": "AnselGitAccount/StatAnaly", "max_issues_repo_head_hexsha": "93cbffd54d212056e023fce90b0386825af49a88", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/Documentation/chapter_sum_of_RV.tex", "max_forks_repo_name": "AnselGitAccount/StatAnaly", "max_forks_repo_head_hexsha": "93cbffd54d212056e023fce90b0386825af49a88", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.5966850829, "max_line_length": 155, "alphanum_fraction": 0.6006779661, "num_tokens": 2013, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7103776248000585}}
{"text": "%This chapter was modified on 4/2/97.\r%\\setcounter{chapter}{6}\r\\chapter[Sums of Random Variables]{Sums of Independent Random Variables}\\label{chp 7}  \r\r\\section{Sums of Discrete Random Variables}\\label{sec 7.1} \r\r\rIn this chapter we turn to the important question of determining the\rdistribution of a sum of independent random variables in terms of the\rdistributions of the individual constituents.  In this section we consider only\rsums of discrete random variables, reserving the case of continuous random\rvariables for the next section.\r\rWe consider here only random variables whose values are integers.  Their distribution\rfunctions are then defined on these integers.  We\rshall find it convenient to assume here that these distribution functions are\rdefined for \\emx {all} integers, by defining them to be~0 where they are not\rotherwise defined.\r\r\\subsection*{Convolutions}\r\r\\par\rSuppose $X$ and $Y$ are two independent discrete random variables with distribution functions \r$m_1(x)$ and $m_2(x)$.  Let $Z = X+Y$.  We would like to determine the distribution \rfunction $m_3(x)$ of $Z$.  To do this, it is enough to determine the probability that $Z$ \rtakes on the value $z$, where $z$ is an arbitrary integer.  Suppose that $X = k$, where $k$\ris some integer.  Then $Z = z$ if and only if $Y = z-k$.  So the event $Z = z$ is the union\rof the pairwise disjoint events\r$$(X = k)\\  \\mbox{and\\ }(Y = z-k)\\ ,$$\rwhere $k$ runs over the integers.  Since these events are pairwise disjoint, we have\r$$P(Z = z) = \\sum_{k = -\\infty}^\\infty P(X = k)\\cdot P(Y = z - k)\\ .$$\rThus, we have found the distribution function of the random variable $Z$.  This\rleads to the following definition.\r\r\\begin{definition}\\label{defn 7.1}\rLet $X$ and $Y$ be two independent integer-valued random variables, with\rdistribution functions $m_1(x)$~and~$m_2(x)$ respectively.  Then the {\\em\rconvolution}\\index{convolution} of\r$m_1(x)$~and~$m_2(x)$ is the distribution function $m_3 = m_1*m_2$ given by\r$$ m_3(j) = \\sum_k m_1(k) \\cdot m_2(j - k)\\ ,$$\rfor $j = \\ldots,\\ -2,\\ -1,\\ 0,\\ 1,\\ 2,\\ \\ldots$.  The function $m_3(x)$ is the distribution\rfunction of the random variable $Z = X + Y$.  \r\\end{definition}\r\r\\par\rIt is easy to see that the convolution operation is commutative, and it is straightforward to\rshow that it is also associative.\r\\par\rNow let $S_n = X_1 + X_2 +\\cdots+ X_n$ be the sum of $n$\rindependent random variables of an independent trials process with common distribution\rfunction $m$ defined on the integers.  Then the distribution function of $S_1$ is $m$.  We can\rwrite\r$$\rS_n = S_{n - 1} + X_n\\ .\r$$\rThus, since we know the distribution function of $X_n$ is $m$, we can find the distribution\rfunction of $S_n$ by induction.\r\r\\begin{example}\rA die is rolled twice.  Let $X_1$ and $X_2$ be the outcomes, and let $S_2 = X_1\r+ X_2$ be the sum of these outcomes.  Then $X_1$ and $X_2$ have the common\rdistribution function:\r$$\rm = \\pmatrix{\r1 & 2 & 3 & 4 & 5 & 6 \\cr\r1/6 & 1/6 & 1/6 & 1/6 & 1/6 & 1/6\\cr}.\r$$\rThe distribution function of $S_2$ is then the convolution of this distribution with itself. \rThus,\r\r\\begin{eqnarray*}\rP(S_2 = 2) &=& m(1)m(1) \\\\\r           &=& \\frac 16 \\cdot \\frac 16 = \\frac 1{36}\\ , \\\\\rP(S_2 = 3) &=& m(1)m(2) + m(2)m(1) \\\\\r           &=& \\frac 16 \\cdot \\frac 16 + \\frac 16 \\cdot \\frac 16 = \\frac 2{36}\\ ,\\\\\rP(S_2 = 4) &=& m(1)m(3) + m(2)m(2) + m(3)m(1) \\\\\r           &=& \\frac 16 \\cdot \\frac 16 + \\frac 16 \\cdot \\frac 16 + \\frac 16\r\\cdot \\frac 16 = \\frac 3{36}\\ .\\\\\r\\end{eqnarray*}\rContinuing in this way we would find $P(S_2 = 5) = 4/36$, $P(S_2 = 6) = 5/36$,\r$P(S_2 = 7) = 6/36$, $P(S_2 = 8) = 5/36$, $P(S_2 = 9) = 4/36$, $P(S_2 = 10) =\r3/36$, $P(S_2 = 11) = 2/36$, and $P(S_2 = 12) = 1/36$.\r\rThe distribution for $S_3$ would then be the convolution of the distribution for $S_2$\rwith the distribution for $X_3$.  Thus\r\\begin{eqnarray*}\rP(S_3 = 3) &=& P(S_2 = 2)P(X_3 = 1) \\\\\r           &=& \\frac 1{36} \\cdot \\frac 16 = \\frac 1{216}\\ , \\\\\rP(S_3 = 4) &=& P(S_2 = 3)P(X_3 = 1) + P(S_2 = 2)P(X_3 = 2) \\\\\r           &=& \\frac 2{36} \\cdot \\frac 16 + \\frac 1{36} \\cdot \\frac 16 = \\frac\r3{216}\\ ,\\\\\r\\end{eqnarray*}\rand so forth.\r\\par\rThis is clearly a tedious job, and a program should be written to carry out this calculation. \rTo do this we first write a program to form the convolution of two densities $p$~and~$q$ and\rreturn the density $r$.  We can then write a program to find\rthe density for the sum $S_n$ of $n$ independent random variables with a common\rdensity $p$, at least in the case that the random variables have a finite number of possible\rvalues.\r\\putfig{3.5truein}{PSfig7-1}{Density of $S_n$ for rolling a die $n$ times.}{fig 7.1} \r\\par\rRunning this program for the example of\rrolling a die $n$ times for~$n = 10,\\ 20,\\ 30$ results in the distributions shown in\rFigure~\\ref{fig 7.1}.  We see that, as in the case of Bernoulli trials, the distributions\rbecome bell-shaped.  We shall discuss in Chapter~\\ref{chp 9} a very general theorem called\rthe {\\em Central Limit Theorem} that will explain this phenomenon.\r\\end{example}\r\r\\begin{example}\rA well-known method for evaluating a bridge\\index{bridge} hand is: an ace is assigned a value\rof~4, a king~3, a queen~2, and a jack~1.  All other cards are assigned a value\rof~0.  The \\emx {point count}\\index{point count} of the hand is then the sum of the values of the\rcards in the hand.  (It is actually more complicated than this, taking into\raccount voids in suits, and so forth, but we consider here this simplified form\rof the point count.)  If a card is dealt at random to a player, then the point\rcount for this card has distribution\r$$\rp_X = \\pmatrix{\r0 & 1 & 2 & 3 & 4 \\cr\r36/52 & 4/52 & 4/52 & 4/52 & 4/52\\cr}.\r$$\r\rLet us regard the total hand of 13~cards as 13 independent trials with this\rcommon distribution.  (Again this is not quite correct because we assume here\rthat we are always choosing a card from a full deck.)  Then the distribution for the\rpoint count $C$ for the hand can be found from the program {\\bf\rNFoldConvolution}\\index{NFoldConvolution (program)} by using the distribution for a single\rcard and choosing\r$n = 13$.  A player with a point count of~13 or more is said to have an  \\emx {opening bid.} \rThe probability of having an opening bid is then\r$$\rP(C \\geq 13)\\ .\r$$\r\rSince we have the distribution of $C$, it is easy to compute this probability.  Doing this we\rfind that\r$$\rP(C \\geq 13) = .2845\\ ,\r$$\rso that about one in four hands should be an opening bid according to this\rsimplified model.  A more realistic discussion of this problem can be found in\rEpstein,\\index{EPSTEIN, R.}  \\emx {The Theory of Gambling and Statistical Logic.}\\footnote{R.~A.\rEpstein,  \\emx {The Theory of Gambling and Statistical Logic,} rev.~ed.\\ (New\rYork: Academic Press, 1977).}\r\\end{example}\r\\par\rFor certain special distributions it is possible to find an expression for the\rdistribution that results from convoluting the distribution with itself $n$~times.\r\\par\rThe convolution of two binomial distributions,\\index{convolution!of binomial distributions} one with\rparameters\r$m$ and\r$p$ and the other with parameters $n$ and $p$, is a binomial distribution with parameters $(m+n)$\rand\r$p$.  This fact follows easily from a consideration of the experiment which consists of first\rtossing a coin $m$ times, and then tossing it $n$ more times.\r\\par\rThe convolution of $k$ geometric distributions\\index{convolution!of geometric distributions} with\rcommon parameter\r$p$ is a negative binomial distribution with parameters $p$ and $k$.  This can be seen by\rconsidering the experiment which consists of tossing a coin until the $k$th head appears.\r\r\r\\exercises \r\\begin{LJSItem}\r\r\r\\i\\label{exer 7.1.1} A die is rolled three times.  Find the probability that the sum of\rthe outcomes is\r\\begin{enumerate}\r\\item greater than 9.\r\r\\item an odd number.\r\\end{enumerate}\r\r\\i\\label{exer 7.1.2} The price of a stock on a given trading day changes according to the\rdistribution\r$$\rp_X = \\pmatrix{\r-1 & 0 & 1 & 2 \\cr\r1/4 & 1/2 & 1/8 & 1/8\\cr}.$$\rFind the distribution for the change in stock price after two (independent) trading\rdays.\r\r\\i\\label{exer 7.1.3} Let $X_1$ and $X_2$ be independent random variables with common\rdistribution\r$$\rp_X = \\pmatrix{\r0 & 1 & 2 \\cr\r1/8 & 3/8 & 1/2\\cr}.$$\rFind the distribution of the sum $X_1 + X_2$.\r\r\\i\\label{exer 7.1.4} In one play of a certain game you win an amount $X$ with distribution\r$$\rp_X = \\pmatrix{\r1 & 2 & 3 \\cr\r1/4 & 1/4 & 1/2\\cr}.$$\rUsing the program {\\bf NFoldConvolution} find the distribution for your total winnings\rafter ten (independent) plays.  Plot this distribution.\r\r\\i\\label{exer 7.1.5} Consider the following two experiments: the first has outcome $X$ taking\ron the values~0,~1, and~2 with equal probabilities; the second results in an\r(independent) outcome $Y$ taking on the value~3 with probability 1/4 and~4\rwith probability 3/4.  Find the distribution of\r\\begin{enumerate}\r\\item $Y + X$.\r\r\\item $Y - X$.\r\\end{enumerate}\r\r\\i\\label{exer 7.1.6} People arrive at a queue according to the following scheme: During each \rminute of time either 0~or~1 person arrives.  The probability that 1 person\rarrives is $p$ and that no person arrives is $q = 1 - p$.  Let $C_r$ be the\rnumber of customers arriving in the first $r$~minutes.  Consider a Bernoulli\rtrials process with a success if a person arrives in a unit time and failure\rif no person arrives in a unit time.  Let $T_r$ be the number of failures\rbefore the $r$th success.\r\\begin{enumerate}\r\\item What is the distribution for $T_r$?\r\r\\item What is the distribution for $C_r$?\r\r\\item Find the mean and variance for the number of customers arriving in the\rfirst $r$ minutes.\r\\end{enumerate}\r\r\\i\\label{exer 7.1.7} \r\\begin{enumerate}\r\\item A die is rolled three times with outcomes $X_1$,~$X_2$, and~$X_3$.  Let\r$Y_3$ be the maximum of the values obtained.  Show that\r$$\rP(Y_3 \\leq j) = P(X_1 \\leq j)^3\\ .\r$$\rUse this to find the distribution of~$Y_3$.  Does $Y_3$ have a bell-shaped distribution?\r\\item\rNow let $Y_n$ be the maximum value when $n$ dice are rolled.  Find the distribution of\r$Y_n$.  Is this distribution bell-shaped for large values of $n$?\r\\end{enumerate}\r\r\\i\\label{exer 7.1.10} A baseball player is to play in the World Series.  Based upon his season\rplay, you estimate that if he comes to bat four times in a game the number of\rhits he will get has a distribution\r$$\rp_X = \\pmatrix{\r0 & 1 & 2 & 3 & 4 \\cr\r.4 & .2 & .2 & .1 & .1\\cr}.$$\r\rAssume that the player comes to bat four times in each game of the series. \r\\begin{enumerate}\r\\item\rLet $X$ denote the number of hits that he gets in a series.  Using the program {\\bf\rNFoldConvolution}, find the distribution of $X$ for each of the possible series lengths:\rfour-game, five-game, six-game, seven-game. \r\r\\item\rUsing one of the distribution found in part (a), find the probability that his batting average\rexceeds .400 in a four-game series.  (The batting average is the number of hits divided by the\rnumber of times at bat.)\r\r\\item Given the distribution $p_X$, what is his long-term batting average?\r\\end{enumerate}\r\r\\i\\label{exer 7.1.11} Prove that you cannot load two dice in such a way that\rthe probabilities for any sum from 2~to~12 are the same.  (Be sure to consider\rthe case where one or more sides turn up with probability zero.)\r\r\\i\\label{exer 7.1.12} (L\\'evy\\footnote{See M. Krasner and B. Ranulae, ``Sur une Propriet\\'e\rdes Polynomes de la Division du Circle\"; and the following note by J.\rHadamard, in  \\emx {C.\\ R.\\ Acad.\\ Sci.,} vol.~204 (1937), pp.~397--399.}) Assume\rthat $n$ is an integer, not prime.  Show that you can find two distributions\r$a$~and~$b$ on the nonnegative integers such that the convolution of\r$a$~and~$b$ is the equiprobable distribution on the set 0, 1, 2, \\dots, $n - 1$.  If\r$n$ is prime this is not possible, but the proof is not so easy.  (Assume that\rneither $a$~nor~$b$ is concentrated at 0.)\r\r\\i\\label{exer 7.1.13} Assume that you are playing craps with dice that are loaded in the\rfollowing way: faces two, three, four, and five all come up with the same\rprobability $(1/6) + r$.  Faces one and six come up with probability $(1/6) - 2r$,\rwith $0 < r < .02$.  Write a computer program to find the probability of\rwinning at craps with these dice, and using your program find which values\rof~$r$ make craps a favorable game for the player with these dice.\r\\end{LJSItem}\r\r\r\r\r\\choice{}{\\section{Sums of Continuous Random Variables}\\label{sec 7.2}\rIn this section we consider the continuous version of the problem posed in the\rprevious section: How are sums of independent random variables distributed?\r\r\\subsection*{Convolutions}\r\\begin{definition} Let $X$ and $Y$ be two continuous random variables with density\rfunctions $f(x)$ and $g(y)$, respectively.  Assume that both $f(x)$ and $g(y)$ are defined for\rall real numbers.  Then the  \\emx {convolution}\\index{convolution} $f*g$ of\r$f$~and~$g$ is the function given by\r\\begin{eqnarray*} (f*g)(z) &=& \\int_{-\\infty}^{+\\infty} f(z - y) g(y)\\,dy \\\\\r         &=& \\int_{-\\infty}^{+\\infty} g(z - x) f(x)\\, dx\\ .\r\\end{eqnarray*} \r\\end{definition} \r\rThis definition is analogous to the definition, given in Section~\\ref{sec 7.1}, of the\rconvolution of two distribution functions.  Thus it should not be surprising that if $X$ and\r$Y$ are independent, then the density of their sum is the convolution of their densities. \rThis fact is stated as a theorem below, and its proof is left as an exercise (see\rExercise~\\ref{exer 7.2.0.5}).  \r\r\\begin{theorem} Let $X$ and $Y$ be two independent random variables with density functions\r$f_X(x)$ and $f_Y(y)$ defined for all~$x$.  Then the sum $Z = X + Y$ is a random variable with\rdensity function $f_Z(z)$, where $f_Z$ is the convolution of $f_X$~and~$f_Y$.\r\\end{theorem}\r\\par\rTo get a better understanding of this important result, we will look at some examples.\r\\pagebreak[4]\r\\subsection*{Sum of Two Independent Uniform Random Variables}\r\\begin{example}\\label{exam 7.6}\rSuppose we choose independently two numbers at random from the interval\r$[0,1]$ with uniform probability density\\index{convolution!of uniform densities}.  What is the\rdensity of their sum?\r\rLet $X$ and $Y$ be random variables describing our choices and $Z = X + Y$\rtheir sum.  Then we have\r\r$$\rf_X(x) = f_Y(x) = \\left \\{ \\begin{array}{ll}\r                               1 & \\;\\mbox{if $0 \\leq x \\leq 1$,} \\\\\r                               0 & \\;\\mbox{otherwise;}\r                  \\end{array}\r         \\right. \r$$\rand the density function for the sum is given by\r$$\rf_Z(z) = \\int_{-\\infty}^{+\\infty} f_X(z - y) f_Y(y)\\,dy\\ .\r$$\rSince $f_Y(y) = 1$ if $0 \\leq y \\leq 1$ and 0 otherwise, this becomes\r$$\rf_Z(z) = \\int_0^1 f_X(z - y)\\,dy\\ .\r$$\rNow the integrand is 0 unless $0 \\leq z - y \\leq 1$ (i.e., unless $z - 1 \\leq y\r\\leq z$) and then it is~1.  So if $0 \\leq z \\leq 1$, we have\r$$\rf_Z(z) = \\int_0^z \\, dy = z\\ ,\r$$\rwhile if $1 < z \\leq 2$, we have\r$$\rf_Z(z) = \\int_{z - 1}^1\\, dy = 2 - z\\ ,\r$$\rand if $z < 0$ or $z > 2$ we have $f_Z(z) = 0$ (see Figure~\\ref{fig 7.5}).  Hence,\r$$\rf_Z(z) = \\left \\{ \\begin{array}{ll}\r                               z,          & \\;\\mbox{if $0 \\leq z \\leq 1,$} \\\\\r                               2-z,        & \\;\\mbox{if $1 < z \\leq 2,$} \\\\\r                               0,          & \\;\\mbox{otherwise.}\r\\end{array}\r\\right. \r$$\r\\putfig{3.5truein}{PSfig7-5}{Convolution of two uniform densities.}{fig 7.5} %4.5truein\rNote that this result agrees with that of Example~\\ref{exam 2.1.4.5}.\r\\end{example}\r\r\r\\subsection*{Sum of Two Independent Exponential Random Variables}\r\\begin{example}\\label{exam 7.7}\rSuppose we choose two numbers at random from the interval $[0,\\infty)$ with\ran  \\emx {exponential} density\\index{convolution!of exponential densities} with parameter $\\lambda$. \rWhat is the density of their sum?\r\rLet $X$, $Y$, and $Z = X + Y$ denote the relevant random variables, and\r$f_X$,~$f_Y$, and~$f_Z$ their densities.  Then\r$$\rf_X(x) = f_Y(x) = \\left \\{ \\begin{array}{ll}\r           \\lambda e^{-\\lambda x}, & \\;\\mbox{if $x \\geq 0$},\\\\\r                                 0, & \\;\\mbox{otherwise;}\r                  \\end{array}\r         \\right. \r$$\rand so, if $z > 0$,\r\\begin{eqnarray*}\rf_Z(z) &=& \\int_{-\\infty}^{+\\infty} f_X(z - y) f_Y(y)\\, dy \\\\\r       &=& \\int_0^z \\lambda e^{-\\lambda(z - y)} \\lambda e^{-\\lambda y}\\, dy \\\\\r       &=& \\int_0^z \\lambda^2 e^{-\\lambda z}\\, dy \\\\\r       &=& \\lambda^2 z e^{-\\lambda z},\\\\\r\\end{eqnarray*}\rwhile if $z < 0$, $f_Z(z) = 0$ (see Figure~\\ref{fig 7.6}).  Hence,\r\\putfig{3.5truein}{PSfig7-6}\r{Convolution of two exponential densities with $\\lambda = 1$.}{fig 7.6} \r$$\rf_Z(z) = \\left \\{ \\begin{array}{ll}\r                       \\lambda^2 z e^{-\\lambda z}, \r                                          & \\;\\mbox{if $z \\geq 0$},\\\\\r                                      0,  & \\;\\mbox{otherwise.}\r                  \\end{array}\r         \\right. \r$$\r\\end{example}\r\r\\subsection*{Sum of Two Independent Normal Random Variables}\r\\begin{example}\\label{exam 7.8}\rIt is an interesting and important fact that the convolution of two normal \rdensities with means $\\mu_1$~and~$\\mu_2$ and variances $\\sigma_1$~and~$\\sigma_2$ is \ragain a normal density, with mean $\\mu_1 + \\mu_2$ and variance $\\sigma_1^2 + \\sigma_2^2$.\rWe will show this in the special case that both random variables are standard normal.\rThe general case can be done in the same way, but the calculation is messier.  Another\rway to show the general result is given in Example~\\ref{exam 10.3.3}.\r\\par\rSuppose $X$ and $Y$ are two independent random variables, each with the standard {\\em\rnormal}\\index{convolution!of normal densities} density (see Example~\\ref{exam 5.16}).  \rWe have\r$$\rf_X(x) = f_Y(y) = \\frac 1{\\sqrt{2\\pi}} e^{-x^2/2}\\ ,\r$$\rand so\r\\begin{eqnarray*}\rf_Z(z) &=& f_X * f_Y(z) \\\\\r&=& \\frac 1{2\\pi} \\int_{-\\infty}^{+\\infty} e^{-(z -\ry)^2/2} e^{-y^2/2}\\, dy \\\\\r       &=& \\frac 1{2\\pi} e^{-z^2/4} \\int_{-\\infty}^{+\\infty} e^{-(y - z/2)^2}\\,\rdy \\\\\r       &=& \\frac 1{2\\pi} e^{-z^2/4}\\sqrt {\\pi} \\biggl[\\frac 1{\\sqrt {\\pi}}\\int_{-\\infty}^\\infty\re^{-(y-z/2)^2}\\,dy\\ \\biggr]\\ .\\\\\r\\end{eqnarray*}\rThe expression in the brackets equals 1, since it is the integral of the normal density\rfunction with $\\mu = 0$ and $\\sigma = \\sqrt 2$.  So, we have\r$$\rf_Z(z) = \\frac 1{\\sqrt{4\\pi}} e^{-z^2/4}\\ .\r$$\r\\end{example}\r\r\\subsection*{Sum of Two Independent Cauchy Random Variables}\r\\begin{example}\\label{exam 7.9}\rChoose two numbers at random from the interval\r$(-\\infty,+\\infty)$ with the Cauchy\\index{convolution!of Cauchy densities} density \rwith parameter $a = 1$ (see Example~\\ref{exam 5.20}).  Then \r$$\rf_X(x) = f_Y(x) = \\frac 1{\\pi(1 + x^2)}\\ ,\r$$\rand $Z = X + Y$ has density\r$$\rf_Z(z) = \\frac 1{\\pi^2} \\int_{-\\infty}^{+\\infty} \\frac {1}{1 + (z - y)^2} \\frac\r{1}{1 + y^2} \\, dy\\ .\r$$\rThis integral requires some effort, and we give here only the result\r(see Section~\\ref{sec 10.3}, or Dwass\\footnote{M. Dwass, ``On the Convolution of Cauchy\rDistributions,\"  \\emx {American Mathematical Monthly,} vol.~92, no.~1, (1985),\rpp.~55--57; see also R.~Nelson, letters to the Editor, ibid., p.~679.}):\r$$\rf_Z(z) = \\frac {2}{\\pi(4 + z^2)}\\ .\r$$\r\\par\rNow, suppose that we ask for the density function of the \\emx {average} \r$$\rA = (1/2)(X + Y)\r$$ \rof $X$~and~$Y$.  Then $A = (1/2)Z$.  Exercise~\\ref{sec 5.2}.\\ref{exer\r5.2.18} shows that if $U$ and $V$ are two continuous random variables  with density functions\r$f_U(x)$ and $f_V(x)$, respectively, and if $V = aU$, then \r$$\rf_V(x) = \\biggl(\\frac 1a\\biggr)f_U\\biggl(\\frac xa\\biggr)\\ .\r$$\rThus, we have\r$$\rf_A(z) = 2f_Z(2z) = \\frac 1{\\pi(1 + z^2)}\\ .\r$$\rHence, the density function for the average of two random variables, each\rhaving a Cauchy density, is again a random variable with a Cauchy density; this\rremarkable property is a peculiarity of the Cauchy density.  One consequence of\rthis is if the error in a certain measurement process had a Cauchy\rdensity and you averaged a number of measurements, the average could not be\rexpected to be any more accurate than any one of your individual measurements!\r\\end{example}\r\r\\subsection*{Rayleigh Density}\\index{density function!Rayleigh}\\index{Rayleigh\rdensity}\r\\begin{example}\\label{exam 7.10}\rSuppose $X$ and $Y$ are two independent standard normal random variables. \rNow suppose we locate a point~$P$ in the $xy$-plane with coordinates $(X,Y)$ and\rask: What is the density of the square of the distance of~$P$ from the origin? \r(We have already simulated this problem in Example~\\ref{exam 5.19}.)  Here, with the preceding\rnotation, we have\r$$\rf_X(x) = f_Y(x) = \\frac 1{\\sqrt{2\\pi}} e^{-x^2/2}\\ .\r$$\rMoreover, if $X^2$ denotes the square of $X$, then (see Theorem~\\ref{thm 5.1} and the\rdiscussion following) \r\r\\begin{eqnarray*}\rf_{X^2}(r) &=& \\left \\{ \\begin{array}{ll}\r        \\frac{1}{2\\sqrt r} (f_X(\\sqrt r) + f_X(-\\sqrt r))  & \\;\\mbox{if $r > 0,$} \\\\\r                                     0                     & \\;\\mbox{otherwise.}\r\\end{array}\r\\right. \\\\\r           &=& \\left \\{ \\begin{array}{ll}\r        \\frac{1}{\\sqrt {2 \\pi r}} (e^{-r/2}) \\hspace{.8in} & \\;\\mbox{if $r > 0,$} \\\\\r                                       0                   & \\;\\mbox{otherwise.}\r\\end{array}\r\\right. \\\\\r\\end{eqnarray*}\rThis is a gamma density with $\\lambda = 1/2$, $\\beta = 1/2$ (see\rExample~\\ref{exam 7.7}).  Now let $R^2 = X^2 + Y^2$.  Then\r\\begin{eqnarray*}\rf_{R^2}(r) &=& \\int_{-\\infty}^{+\\infty} f_{X^2}(r - s) f_{Y^2}(s)\\, ds \\\\\r           &=& \\frac 1{4\\pi} \\int_{-\\infty}^{+\\infty} e^{-(r - s)/2} \r{\\frac{r-s}{2}}^{-1/2} e^{-s} {\\frac{s}{2}}^{-1/2}\\, ds\\ , \\\\\r           &=& \\left \\{\\begin{array}{ll}\r                       {\\frac {1}{2}} e^{-r^2/2}, & \\;\\mbox{if $r \\geq 0,$} \\\\\r                               0,                 & \\;\\mbox{otherwise.}\r                  \\end{array}\r         \\right. \r\\end{eqnarray*}\rHence, $R^2$ has a gamma density with $\\lambda = 1/2$, $\\beta = 1$.  We can\rinterpret this result as giving the density for the square of the distance\rof~$P$ from the center of a target if its coordinates are normally distributed.\r\rThe density of the random variable $R$ is obtained from that of $R^2$ in the\rusual way (see Theorem~\\ref{thm 5.1}), and we find\r$$\rf_R(r) = \\left \\{ \\begin{array}{ll}\r                       \\frac 12 e^{-r^2/2} \\cdot 2r = re^{-r^2/2}, \r                                          & \\;\\mbox{if $r \\geq 0,$} \\\\\r                               0,         & \\;\\mbox{otherwise.}\r                  \\end{array}\r         \\right. \r$$\r\rPhysicists will recognize this as a Rayleigh density.  Our\rresult here agrees with our simulation in Example~\\ref{exam 5.19}.\r\\end{example}\r\r\\subsection*{Chi-Squared Density}\\index{chi-squared density}\\index{density function!chi-squared}\rMore generally, the same method shows that the sum of the squares of~$n$\rindependent normally distributed random variables with mean~0 and standard\rdeviation~1 has a gamma density with $\\lambda = 1/2$ and $\\beta = n/2$.  Such a\rdensity is called a  \\emx {chi-squared density} with $n$ degrees of freedom.  This\rdensity was introduced in Chapter~\\ref{chp 5}.  In Example~\\ref{exam 5.20}, we\rused this density to test the hypothesis that two traits were independent.  \r\\par\rAnother important use of the chi-squared density is in comparing experimental data\rwith a theoretical discrete distribution, to see whether the data supports the \rtheoretical model.  More specifically, suppose that we have an experiment with a\rfinite set of outcomes.  If the set of outcomes is countable, we group them into\rfinitely many sets of outcomes.  We propose a theoretical distribution which we think\rwill model the experiment well.  We obtain some data by repeating the  experiment a\rnumber of times.  Now we wish to check how well the theoretical distribution fits the\rdata.\r\\par\rLet $X$ be the random variable which represents a theoretical outcome in the model\rof the experiment, and let $m(x)$ be the distribution function of $X$.  In a manner\rsimilar to what was done in Example~\\ref{exam 5.20}, we calculate the value of the\rexpression\r$$\rV = \\sum_x \\frac{(o_x - n \\cdot m(x))^2}{n \\cdot m(x)}\\ ,\r$$\rwhere the sum runs over all possible outcomes $x$, $n$ is the number of data\rpoints, and $o_x$ denotes the number of outcomes of type $x$ observed\rin the data.  Then for moderate or large values of $n$, the quantity $V$ is\rapproximately chi-squared distributed, with $\\nu - 1$ degrees of freedom, where\r$\\nu$ represents the number of possible outcomes.  The proof of this is beyond the\rscope of this book, but we will illustrate the reasonableness of this statement in\rthe next example.  If the value of $V$ is very large, when compared with the\rappropriate chi-squared density function, then we would tend to reject the hypothesis\rthat the model is an appropriate one for the experiment at hand.  We now give an\rexample of this procedure.\r\r\\begin{example}\rSuppose we are given a single die.  We wish to test the hypothesis that the die is\rfair.  Thus, our theoretical distribution is the uniform distribution on the integers\rbetween 1 and 6.  So, if we roll the die $n$ times, the expected number of data\rpoints of each type is $n/6$.  Thus, if $o_i$ denotes the actual number of data\rpoints of type $i$, for $1 \\le i \\le 6$, then the expression\r$$V = \\sum_{i = 1}^6 \\frac{(o_i - n/6)^2}{n/6}$$\ris approximately chi-squared distributed with 5 degrees of freedom.\r\\par\rNow suppose that we actually roll the die 60 times and obtain the \rdata in Table~\\ref{table 7.1}.\r\\begin{table}\r\\centering\r\\begin{tabular}{|c|c|}\r\\hline\r Outcome & Observed Frequency \\\\\r\\hline 1 & 15\\\\\r\\hline 2 & \\hspace{.08in}8 \\\\\r\\hline 3 & \\hspace{.08in}7 \\\\\r\\hline 4 & \\hspace{.08in}5 \\\\\r\\hline 5 & \\hspace{.08in}7 \\\\\r\\hline 6 & 18 \\\\\r\\hline\r\\end{tabular}\r\\caption{Observed data.}\r\\label{table 7.1}\r\\end{table}\rIf we calculate $V$ for this data, we obtain the value 13.6.  The graph of the \rchi-squared density with 5 degrees of freedom is shown in Figure~\\ref{fig 7.7}.  One\rsees that values as large as 13.6 are rarely taken on by $V$ if the die is fair, so we\rwould reject the hypothesis that the die is fair.   (When using this test, a\rstatistician will reject the hypothesis if the data gives a value of $V$ which is\rlarger than 95\\% of the values one would expect to obtain if the hypothesis is true.)\r\\putfig{3.5truein}{PSfig7-7}{Chi-squared density with 5 degrees of freedom.}{fig 7.7} \r\\par\rIn Figure~\\ref{fig 7.8}, we show the results of rolling a die 60 times, then\rcalculating $V$, and then repeating this experiment 1000 times.  The program that performs\rthese calculations is called {\\bf DieTest}.\\index{DieTest (program)}  We\rhave  superimposed the chi-squared density with 5 degrees of freedom; one can see\rthat the data values fit the curve fairly well, which supports the statement\rthat the chi-squared density is the correct one to use. \r\\putfig{4.5truein}{PSfig7-8}{Rolling a fair die.}{fig 7.8} \r\\end{example}\r\rSo far we have looked at several important special cases for which the\rconvolution integral can be evaluated explicitly.  In general, the convolution\rof two continuous densities cannot be evaluated explicitly, and we must resort\rto numerical methods.  Fortunately, these prove to be remarkably effective, at\rleast for bounded densities.\r\r\\subsection*{Independent Trials}\rWe now consider briefly the distribution of the sum of~$n$ independent random\rvariables, all having the same density function.  If $X_1$,~$X_2$, \\dots,~$X_n$\rare these random variables and $S_n = X_1 + X_2 +\\cdots+ X_n$ is their sum, then we\rwill have\r$$\rf_{S_n}(x) = \\left( f_{X_1} * f_{X_2} *\\cdots* f_{X_n} \\right)(x)\\ ,\r$$\rwhere the right-hand side is an $n$-fold convolution.  It is possible to\rcalculate this density for general values of~$n$ in certain simple cases.\r\r\\begin{example}\\label{exam 7.12}\rSuppose the $X_i$ are uniformly distributed\\index{convolution!of uniform densities} on the interval\r$[0,1]$.  Then\r$$\rf_{X_i}(x) = \\left \\{ \\begin{array}{ll}\r                         1,         & \\;\\mbox{if $0 \\leq x \\leq 1,$} \\\\\r                         0,         & \\;\\mbox{otherwise,}\r                   \\end{array}\r          \\right. \r$$\rand $f_{S_n}(x)$ is given by the formula\\index{USPENSKY, J. B.}\\footnote{J.~B. Uspensky,\r{\\em Introduction to Mathematical Probability} (New York: McGraw-Hill, 1937),\rp.~277.}\r$$\rf_{S_n}(x) = \\left \\{ \\begin{array}{ll}\r                         \\frac 1{(n - 1)!} \\sum_{0 \\leq j \\leq x} (-1)^j\r { n \\choose j} (x - j)^{n - 1},     & \\;\\mbox{if $0 < x < n,$} \\\\       \r                         0,          & \\;\\mbox{otherwise.}\r                   \\end{array}\r          \\right. \r$$\rThe density $f_{S_n}(x)$ for~$n = 2$,~4, 6, 8,~10 is shown in Figure~\\ref{fig 7.9}.\r\r\\putfig{4.5truein}{PSfig7-9}{Convolution of $n$ uniform densities.}{fig 7.9} \r\r\rIf the $X_i$ are distributed normally,\\index{convolution!of standard normal densities} with mean~0\rand variance~1, then (cf.~Example~\\ref{exam 7.8})\r$$\rf_{X_i}(x) = \\frac 1{\\sqrt{2\\pi}} e^{-x^2/2}\\ ,\r$$\rand\r$$\rf_{S_n}(x) = \\frac 1{\\sqrt{2\\pi n}} e^{-x^2/2n}\\ .\r$$\rHere the density $f_{S_n}$ for~$n = 5$,~10, 15, 20,~25 is shown in Figure~\\ref{fig 7.10}.\r\r\\putfig{4.5truein}{PSfig7-10}{Convolution of $n$ standard normal densities.}{fig 7.10} \r\rIf the $X_i$ are all exponentially distributed,\\index{convolution!of exponential densities}\rwith mean~$1/\\lambda$, then\r$$\rf_{X_i}(x) = \\lambda e^{-\\lambda x}\\ ,\r$$\rand\r$$\rf_{S_n}(x) = \\frac {\\lambda e^{-\\lambda x}(\\lambda x)^{n - 1}}{(n - 1)!}\\ .\r$$\rIn this case the density $f_{S_n}$ for~$n = 2$,~4, 6, 8,~10 is shown in\rFigure~\\ref{fig 7.11}.\r\\putfig{4.5truein}{PSfig7-11}\r{Convolution of $n$ exponential densities with $\\lambda = 1$.}{fig 7.11} \r\\end{example}\r\r\r\\exercises\r\\begin{LJSItem}\r\r\\i\\label{exer 7.2.0.5}  Let $X$ and $Y$ be independent real-valued random variables \rwith density functions $f_X(x)$ and $f_Y(y)$, respectively.  Show that the density \rfunction of the sum $X + Y$ is the convolution of the functions $f_X(x)$ and $f_Y(y)$.\r\\emx {Hint}:  Let $\\bar X$ be the joint random variable $(X, Y)$.  Then the joint\rdensity function of $\\bar X$ is $f_X(x)f_Y(y)$, since $X$ and $Y$ are independent.  Now\rcompute the probability that $X+Y \\le z$, by integrating the joint density function over the\rappropriate region in the plane.  This gives the cumulative distribution function of $Z$. \rNow differentiate this function with respect to $z$ to obtain the density function of $z$.\r\r\\i\\label{exer 7.2.1} Let $X$ and $Y$ be independent random variables defined\ron the space $\\Omega$, with density functions $f_X$~and~$f_Y$, respectively. \rSuppose that $Z = X + Y$.  Find the density $f_Z$ of~$Z$ if\r\\begin{enumerate}\r\\item $$f_X(x) = f_Y(x) = \\left \\{ \\begin{array}{ll}\r                              1/2,   & \\;\\mbox{if $-1 \\leq x \\leq +1,$} \\\\\r                              0,     & \\;\\mbox{otherwise.}\r                  \\end{array}\r         \\right. $$\r\r \r\\item $$f_X(x) = f_Y(x) = \\left \\{ \\begin{array}{ll}\r                              1/2,   & \\;\\mbox{if $3 \\leq x \\leq 5,$} \\\\\r                              0,     & \\;\\mbox{otherwise.}\r                  \\end{array}\r         \\right. $$\r\r\r\\item $$f_X(x) = \\left \\{ \\begin{array}{ll}\r                              1/2,   & \\;\\mbox{if $-1 \\leq x \\leq 1,$} \\\\\r                              0,     & \\;\\mbox{otherwise.}\r                  \\end{array}\r         \\right. $$\r\\smallskip\r$$f_Y(x) = \\left \\{ \\begin{array}{ll}\r                              1/2,   & \\;\\mbox{if $3 \\leq x \\leq 5,$} \\\\\r                              0,     & \\;\\mbox{otherwise.}\r                  \\end{array}\r         \\right. $$\r\\item What can you say about the set $E = \\{\\,z : f_Z(z)> 0\\,\\}$ in each\rcase?\r\\end{enumerate}\r\r\\i\\label{exer 7.2.2} Suppose again that $Z = X + Y$.  Find $f_Z$ if\r\\begin{enumerate}\r\\item $$f_X(x) = f_Y(x) = \\left \\{ \\begin{array}{ll} \r                    x/2, & \\mbox{if $0 < x < 2,$} \\\\\r                      0, & \\mbox{otherwise}.\r                  \\end{array}\r         \\right. $$\r\r\\item $$f_X(x) = f_Y(x) = \\left \\{ \\begin{array}{ll} \r                 (1/2)(x - 3), & \\mbox{if $3 < x < 5,$} \\\\\r                            0, & \\mbox{otherwise}. \r                  \\end{array}\r         \\right. $$\r\r\\item $$f_X(x) = \\left \\{ \\begin{array}{ll} \r                       1/2,    & \\mbox{if $0 < x < 2,$} \\\\\r                            0, & \\mbox{otherwise},\r                  \\end{array}\r         \\right. $$\r\\smallskip\r $$f_Y(x) = \\left \\{ \\begin{array}{ll} \r                          x/2, & \\mbox{if $0 < x < 2,$} \\\\\r                            0, & \\mbox{otherwise}.\r                  \\end{array}\r         \\right. $$\r\\item What can you say about the set $E = \\{\\,z : f_Z(z)> 0\\,\\}$ in each\rcase?\r\\end{enumerate}\r\r\\i\\label{exer 7.2.3} Let $X$, $Y$, and $Z$ be independent random variables\rwith \r$$f_X(x) = f_Y(x) = f_Z(x)  = \\left \\{ \\begin{array}{ll}\r                              1,     & \\mbox{if $0 < x < 1,$} \\\\\r                              0,     & \\mbox{otherwise.}\r                  \\end{array}\r         \\right. $$\r\\noindent Suppose that $W = X + Y + Z$.  Find $f_W$ directly, and compare your answer\rwith that given by the formula in Example~\\ref{exam 7.12}.   \\emx {Hint}:  See \rExample~\\ref{exam 7.6}.\r\r\\i\\label{exer 7.2.3.5} Suppose that $X$ and $Y$ are independent and $Z = X + Y$.  Find\r$f_Z$ if\r\r\\begin{enumerate}\r\\item $$f_X(x) = \\left \\{ \\begin{array}{ll}\r                              \\lambda e^{-\\lambda x}, & \\mbox{if $x > 0,$} \\\\\r                               0,                     & \\mbox{otherwise.}\r                  \\end{array}\r         \\right. $$\r\\smallskip\r$$f_Y(x) = \\left \\{ \\begin{array}{ll}\r                              \\mu e^{-\\mu x}, & \\mbox{if $x > 0,$} \\\\\r                              0,              & \\mbox{otherwise.}\r                  \\end{array}\r         \\right. $$\r\\item $$\\ \\ \\ f_X(x) = \\left \\{ \\begin{array}{ll}\r                              \\lambda e^{-\\lambda x}, & \\mbox{if $x > 0,$} \\\\\r                              0,                      & \\mbox{otherwise.}\r                  \\end{array}\r         \\right. $$\r\r\\smallskip\r$$f_Y(x) = \\left \\{ \\begin{array}{ll}\r                    1, & \\mbox{if $0 < x < 1,$} \\\\\r                    0, & \\mbox{otherwise.}\r                  \\end{array}\r         \\right. $$\r\\end{enumerate}\r\r\\i\\label{exer 7.2.100} Suppose again that $Z = X + Y$.  Find $f_Z$ if\r\\begin{eqnarray*}\rf_X(x) &=& \\frac 1{\\sqrt{2\\pi}\\sigma_1} e^{-(x - \\mu_1)^2/2\\sigma_1^2} \\\\\rf_Y(x) &=& \\frac 1{\\sqrt{2\\pi}\\sigma_2} e^{-(x - \\mu_2)^2/2\\sigma_2^2}\\ .\r\\end{eqnarray*}\r\r%********The next problem is too hard.\r\\istar\\label{exer 7.2.101} Suppose that $R^2 = X^2 + Y^2$.  Find $f_{R^2}$ and $f_R$ if\r\\begin{eqnarray*}\rf_X(x) &=& \\frac 1{\\sqrt{2\\pi}\\sigma_1} e^{-(x - \\mu_1)^2/2\\sigma_1^2} \\\\\rf_Y(x) &=& \\frac 1{\\sqrt{2\\pi}\\sigma_2} e^{-(x - \\mu_2)^2/2\\sigma_2^2}\\ .\r\\end{eqnarray*}\r\r\\i\\label{exer 7.2.101.5} Suppose that $R^2 = X^2 + Y^2$.  Find $f_{R^2}$ and $f_R$ if\r$$\rf_X(x) = f_Y(x) = \\left \\{ \\begin{array}{ll}\r                    1/2, & \\mbox{if $-1 \\leq x \\leq 1,$} \\\\\r                    0,   & \\mbox{otherwise.}\r                  \\end{array}\r         \\right. \r$$\r\r\\i\\label{exer 7.2.102} Assume that the service time for a customer at a bank is\rexponentially distributed with mean service time 2~minutes.  Let $X$ be the total service\rtime for 10 customers.  Estimate the probability that $X > 22$ minutes.\r\r\\i\\label{exer 7.2.9} Let $X_1$,~$X_2$, \\dots,~$X_n$ be $n$ independent random\rvariables each of which has an exponential density with mean~$\\mu$.  Let $M$ be\rthe \\emx {minimum} value of the $X_j$.  Show that the density for~$M$ is\rexponential with mean $\\mu/n$.   \\emx {Hint}:  Use cumulative distribution functions.\r\r\\i\\label{exer 7.2.103} A company buys 100 lightbulbs, each of which has an exponential\rlifetime of 1000 hours.  What is the expected time for the first of these bulbs to burn\rout?  (See Exercise~\\ref{exer 7.2.9}.)\r\r\\i\\label{exer 7.2.104} An insurance company assumes that the time between claims from\reach of its homeowners' policies is exponentially distributed with mean~$\\mu$.  It\rwould like to estimate $\\mu$ by averaging the times for a number of policies,\rbut this is not very practical since the time between claims is about\r30~years.  At Galambos'\\index{GALAMBOS, J.}\\footnote{J. Galambos,  \\emx {Introductory\rProbability Theory} (New York: Marcel Dekker, 1984), p.~159.} suggestion the company puts\rits customers in groups of~50 and observes the time of the first claim within\reach group.  Show that this provides a practical way to estimate the value\rof~$\\mu$.\r\r\\i\\label{exer 7.2.105} Particles are subject to collisions that cause them to split into\rtwo parts with each part a fraction of the parent.  Suppose that this fraction is\runiformly distributed between 0~and~1.  Following a single particle through\rseveral splittings we obtain a fraction of the original particle $Z_n = X_1\r\\cdot X_2 \\cdot\\dots\\cdot X_n$ where each $X_j$ is uniformly distributed\rbetween 0~and~1.  Show that the density for the random variable $Z_n$ is\r$$\rf_n(z) = \\frac 1{(n - 1)!}( -\\log z)^{n - 1}.\r$$\r \\emx {Hint}: Show that $Y_k = -\\log X_k$ is exponentially distributed.  Use\rthis to find the density function for $S_n = Y_1 + Y_2 +\\cdots+ Y_n$, and\rfrom this the cumulative distribution and density of $Z_n = e^{-S_n}$.\r\r\\i\\label{exer 7.2.106} Assume that $X_1$ and $X_2$ are independent random variables, each\rhaving an exponential density with parameter~$\\lambda$.  Show that $Z = X_1 - X_2$ has\rdensity\r$$\rf_Z(z) = (1/2)\\lambda e^{-\\lambda |z|}\\ .\r$$\r\r\\i\\label{exer 7.2.107} Suppose we want to test a coin for fairness.  We flip the coin $n$\rtimes and record the number of times $X_0$ that the coin turns up tails and the\rnumber of times $X_1 = n - X_0$ that the coin turns up heads.  Now we set\r$$\rZ= \\sum_{i = 0}^1 \\frac {(X_i - n/2)^2}{n/2}\\ .\r$$\rThen for a fair coin $Z$ has approximately a chi-squared distribution with $2 -\r1 = 1$ degree of freedom.  Verify this by computer simulation first for a fair\rcoin ($p~=~1/2$) and then for a biased coin ($p~=~1/3$).\r\r\\i\\label{exer 7.2.108} Verify your answers in Exercise~\\ref{exer 7.2.1}(a) by computer\rsimulation: Choose $X$ and $Y$ from $[-1,1]$ with uniform density and calculate\r$Z = X + Y$.  Repeat this experiment 500 times, recording the outcomes in a bar\rgraph on $[-2,2]$ with 40~bars.  Does the density $f_Z$ calculated in Exercise~\\ref{exer\r7.2.1}(a) describe the shape of your bar graph?  Try this for Exercises~\r\\ref{exer 7.2.1}(b)~and~Exercise~\\ref{exer 7.2.1}(c), too.\r\r\\i\\label{exer 7.2.109} Verify your answers to Exercise~\\ref{exer 7.2.2} by computer\rsimulation.\r\r\\i\\label{exer 7.2.110} Verify your answer to Exercise~\\ref{exer 7.2.3} by computer\rsimulation.\r\r\\i\\label{exer 7.2.18} The  \\emx {support} of a function $f(x)$ is defined to be the set\r$$\r\\{x\\ :\\ f(x) > 0\\}\\ .$$\rSuppose that $X$ and $Y$ are two continuous random variables with\rdensity functions $f_X(x)$ and $f_Y(y)$, respectively, and suppose that the supports of these\rdensity functions are the intervals $[a, b]$ and $[c, d]$, respectively.  Find the support of the\rdensity function of the random variable $X+Y$.\r\r\\i\\label{exer 7.2.111} Let $X_1$,~$X_2$, \\dots,~$X_n$ be a sequence of independent random\rvariables, all having a common density function $f_X$ with support $[a,b]$ (see\rExercise~\\ref{exer 7.2.18}).  Let $S_n = X_1 + X_2 +\\cdots+ X_n$, with density\rfunction $f_{S_n}$.  Show that the support of~$f_{S_n}$ is the interval\r$[na,nb]$.   \\emx {Hint}: Write $f_{S_n} = f_{S_{n - 1}} * f_X$.  Now use\rExercise~\\ref{exer 7.2.18} to establish the desired result by induction.\r\r\\i\\label{exer 7.2.112} Let $X_1$,~$X_2$, \\dots,~$X_n$ be a sequence of independent random\rvariables, all having a common density function $f_X$.  Let $A = S_n/n$ be\rtheir average.  Find $f_A$ if\r\\begin{enumerate}\r\\item $f_X(x) = (1/\\sqrt{2\\pi}) e^{-x^2/2}$ (normal density).\r\r\\item $f_X(x) = e^{-x}$ (exponential density).\r\\par\r\\noindent \\emx {Hint}: Write $f_A(x)$ in terms of $f_{S_n}(x)$.\r\\end{enumerate}\r\r\\end{LJSItem}}\r\r", "meta": {"hexsha": "96968a4d831831bf7d6b64a07bdd139ae0911db5", "size": 39975, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/ch7.tex", "max_stars_repo_name": "kskyten/introduction-to-probability", "max_stars_repo_head_hexsha": "288c82a0cb94e6b9d702eb8803dc342052d411f9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/ch7.tex", "max_issues_repo_name": "kskyten/introduction-to-probability", "max_issues_repo_head_hexsha": "288c82a0cb94e6b9d702eb8803dc342052d411f9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/ch7.tex", "max_forks_repo_name": "kskyten/introduction-to-probability", "max_forks_repo_head_hexsha": "288c82a0cb94e6b9d702eb8803dc342052d411f9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39975.0, "max_line_length": 39975, "alphanum_fraction": 0.6438774234, "num_tokens": 13720, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424528443251, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.7103666106528893}}
{"text": "\\section{Convolutions}\r\n\\subsection{Motivation}\r\nTaking Laplace transforms can be difficult.\r\nWe already have some basic formulas derived from linearity properties of integrals that allow us to not evaluate an integral every time.\\\\\r\n\r\n\\noindent\r\nOne sort of formula that would be nice to have is one relating products of functions.\r\nIf we know that\r\n\\begin{equation*}\r\n\tH(s) = F(s)G(s),\r\n\\end{equation*}\r\nwhere $F$ and $G$ are the Laplace transforms of $f$ and $g$, it'd be nice if we could find the inverse Laplace transform of $H$ to get $h$.\r\nThis is one way to define the convolution.\r\n\r\n\\subsection{Definition \\& Convolution Theorem}\r\n\\begin{definition}\r\n\tLet $F(s)$ and $G(s)$ be the Laplace transforms of functions $f(t)$ and $g(t)$.\r\n\tThen\r\n\t\\begin{equation*}\r\n\t\tF(s)G(s) = \\Laplace{f \\star g}.\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\\noindent\r\nNote how using this definition we can see that $\\star$, the convolution operator, is commutative.\r\n\r\n\\noindent\r\nDefining this function that works like multiplication over Laplace transforms is only really useful if we have a formula for it, so let's derive one.\r\nStarting from the left-hand side of the equation in the definition and applying the integral definition of the Laplace transform,\r\n\\begin{equation*}\r\n\tF(s)G(s) = \\int_{0}^{\\infty}{e^{-su}f(u)\\d{u}} \\cdot \\int_{0}^{\\infty}{e^{-sv}f(v)\\d{v}}.\r\n\\end{equation*}\r\nMaking this product of integrals into a double integral (we usually do this in reverse when simplifying a double integral),\r\n\\begin{equation*}\r\n\t= \\int_{0}^{\\infty}{\\int_{0}^{\\infty}{e^{-s(u+v)}f(u)g(v)\\d{u}}\\d{v}}.\r\n\\end{equation*}\r\nLetting $t = u+v$,\r\n\\begin{equation*}\r\n\t= \\int_{0}^{\\infty}{\\int_{0}^{t}{e^{-st}f(u)g(t-u)\\d{u}}\\d{t}}.\r\n\\end{equation*}\r\nBringing $e^{-st}$ outside of the innermost integral,\r\n\\begin{equation*}\r\n\t= \\int_{0}^{\\infty}{e^{-st}\\left[\\int_{0}^{t}{f(u)g(t-u)\\d{u}}\\right]\\d{t}}.\r\n\\end{equation*}\r\nWe see that we have the Laplace transform of the expression in the square brackets.\r\nSo,\r\n\\begin{equation*}\r\n\tf \\star g = \\int_{0}^{t}{f(u)g(t-u)\\d{u}}.\r\n\\end{equation*}\r\nThis is an equivalent way to define the convolution.\r\n\r\n\\begin{example}\r\n\tCompute the convolution of $t^2$ with $t$.\r\n\\end{example}\r\n\\noindent\r\nApplying the formula we just derived,\r\n\\begin{align*}\r\n\tt^2 \\star t &= \\int_{0}^{t}{u^2(t-u)\\d{u}} \\\\\r\n\t&= t\\frac{u^3}{3} - \\frac{u^4}{4} \\bigg\\rvert_{0}^{t} \\\\\r\n\t&= \\frac{t^4}{3} - \\frac{t^4}{4} \\\\\r\n\t&= \\frac{t^4}{12}.\r\n\\end{align*}\r\n\r\n\\subsection{Properties}\r\nConvolution inherits all the linearity properties of integration.\r\nLet $f(t)$, $g(t)$, and $h(t)$ be piecewise continuous on $[0,\\infty)$.\r\nLet $a$ be a real constant.\r\nThen\r\n\\begin{enumerate}[label=]\r\n\t\\item \\textbf{Commutativity} -- $f \\star = g \\star f$\r\n\t\\item \\textbf{Associativity} -- $(f \\star g) \\star h = f \\star (g \\star h)$\r\n\t\\item \\textbf{Distributivity over Addition} -- $f \\star (g + h) = (f \\star g) + (f \\star h)$\r\n\t\\item \\textbf{Associativity over Scalar Multiplication} -- $a(f \\star g) = (af) \\star g$\r\n\\end{enumerate}\r\n\r\n\\subsection{Applications}\r\nWhen we're using Laplace transforms to solve a differential equation, if we recognize $\\Laplace{y}$ as the product of two functions for which we know the inverse Laplace transforms, we can compute a convolution to find $y$.\r\n\r\n\\begin{example}\r\n\tSolve the following differential equation using Laplace transforms and convolutions.\r\n\tLet $a$ and $c$ be real constants where $a \\neq c$.\r\n\t\\begin{equation*}\r\n\t\ty' - ay = e^{ct}.\\footnotemark\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\footnotetext{When we're taking the Laplace transform of both sides, we implicitly use that $y(0)=0$.}\r\n\\noindent\r\nTaking the Laplace transform of both sides,\r\n\\begin{align*}\r\n\ts\\Laplace{y} - a\\Laplace{y} &= \\frac{1}{s-c} \\\\\r\n\t\\Laplace{y}(s-a) &= \\frac{1}{s-c}.\r\n\\end{align*}\r\nSolving for $\\Laplace{y}$,\r\n\\begin{equation*}\r\n\t\\Laplace{y} = \\frac{1}{s-c} \\cdot \\frac{1}{s-a}.\r\n\\end{equation*}\r\nRecognizing the right-hand side of the equation as the product of the Laplace transforms of $e^{ct}$ and $e^{at}$, we can solve for $y$ by finding the convolution of $e^{ct}$ and $e^{at}$.\r\nApplying our formula,\r\n\\begin{align*}\r\n\tF(s) = \\frac{1}{s-c} &\\text{ and } G(s) = \\frac{1}{s-a} \\\\\r\n\tf(t) = e^{ct} &\\text{ and } g(t) = e^{at}. \\\\\r\n\ty(t) &= f(t) \\star g(t) \\\\\r\n\t&= \\int_{0}^{t}{e^{cu}e^{a(t-u)}\\d{u}} \\\\\r\n\t&= e^{at}\\int_{0}^{t}{e^{u(c-a)}\\d{u}} \\\\\r\n\t&= e^{at}\\left(\\frac{e^{(c-a)t}}{c-a} - \\frac{1}{c-a}\\right) \\\\\r\n\t&= \\frac{e^{ct} - e^{at}}{c-a}.\r\n\\end{align*}", "meta": {"hexsha": "6f1fcb3f6d084c6d778428010236b03e49a4b563", "size": 4476, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/laplaceTransforms/convolutions/convolutions.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/laplaceTransforms/convolutions/convolutions.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/laplaceTransforms/convolutions/convolutions.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 42.2264150943, "max_line_length": 224, "alphanum_fraction": 0.6528150134, "num_tokens": 1547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7103665990405295}}
{"text": "\\subsection{GRASP + Tabu Search}\n\nIn order to find a time optimal algorithm to solve the multidimensional precedence-constrained knapsack problem (MPKP), we propose a comparative analysis of an implementation of a Integer Linear Program to solve MPKP and a near optimal algorithm utilizing GRASP and Tabu Search as GRASP's local search.\n\n\\begin{algorithm}[ht!]\n    \\caption{GRASP Pseudocode}\n    \\begin{algorithmic}[1]\n        \\Require{$MaxIterations, Seed$}\n        \\For{$k=1,\\ldots,MaxIterations$}\n            \\State{$Solution \\leftarrow Greedy Randomized Construction(Seed);$}\n            \\If{Solution is not feasible}\n                \\State{$Solution \\leftarrow Repair(Solution)$;}\n            \\EndIf\n            \\State{$Solution \\leftarrow LocalSearch(Solution);$}\n            \\State{$UpdateSolution(Solution, BestSolution);$}\n        \\EndFor\n        \\\\\\Return{$BestSolution$}\n    \\end{algorithmic}\n\\end{algorithm}\nwhere the candidate list is build greedily utilizing the current maximal elements on our input graph(as long as they fit).\nThere's no need to use any repair method as the solution built from the candidate list will always fit in the knapsack.\nThat way, we do a local search and update our solution with the best one seen to far.\n\nThe trick here is to use a Tabu Search, instead of a naive local search method, to both avoid falling in local optima and utilizing the tabu list in order to avoid repeating moves and other. We use GRASP as a diversification strategy.\n\nWe now define exactly how this search is proposed.\n\nLet $n \\in \\mathbb N$ be the number of binary variables of an input instance. The tabu list, let's call it $Tabu$ is a mapping $Tabu : StrN \\rightarrow \\mathbb N$, with pre-defined $Tabu.size$ capacity, where $StrN$ is an arrangement of $n$ bits let's call it $Arr$, where $n$ is the number of binary variables of our instance, and the $i$-th bit represents the state of $x_i$, where $Arr[i] = x_i$.\n\nWe also utilize a heap structure to get the earliest added tabu in $O(1)$ time.\n\nDuring the local search, at each iteration we add the current state of our binary variables an element of $Tabu$. If the total number of tabus is equal to $Tabu.size$ we pop the earliest added tabu from our heap and remove that tabu from $Tabu$ while adding the new move to $Tabu$.\n\nEach time that the Tabu Search tries to do a tabu move the integer in $Tabu$ associated with this move is looked up by the search, if the tabu exists, and if it equals $1$, that tabu is removed from the mapping.\n\nEach move in the Tabu Search is a bit flip operation of a variable in a randomly selected, at every search iteration, subset $BinVars$ of the set of all binary variables of the input instance, such that $|BinVars| = k <= n$, where $k \\in \\mathbb{N}$ is a pre-defined parameter, as a way to limit the search space of the Tabu Search.\n\nThe best values for $k$ and $Tabu.size$ will be determined by tests.\n", "meta": {"hexsha": "8d5c73ae3613aed2407b17d074f3eb68490c3881", "size": 2919, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "project/report/textual/solving_methodology.tex", "max_stars_repo_name": "lucasguesserts/MO824A-combinatorial-optimization", "max_stars_repo_head_hexsha": "a88569e4496c0ed4f89a4e8bac7ab8f42f6cb7d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "project/report/textual/solving_methodology.tex", "max_issues_repo_name": "lucasguesserts/MO824A-combinatorial-optimization", "max_issues_repo_head_hexsha": "a88569e4496c0ed4f89a4e8bac7ab8f42f6cb7d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "project/report/textual/solving_methodology.tex", "max_forks_repo_name": "lucasguesserts/MO824A-combinatorial-optimization", "max_forks_repo_head_hexsha": "a88569e4496c0ed4f89a4e8bac7ab8f42f6cb7d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 74.8461538462, "max_line_length": 399, "alphanum_fraction": 0.7341555327, "num_tokens": 719, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424256566558, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7103665912154038}}
{"text": "\n\\subsection{Exponents}\nEigenmath requires parentheses around negative exponents.\nFor example,\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\n10^(-3)\n\\end{Verbatim}\n\ninstead of\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\n10^-3\n\\end{Verbatim}\n\nThe reason for this is that the binding of the negative sign is not always\nobvious.\nFor example, consider\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nx^-1/2\n\\end{Verbatim}\n\nIt is not clear whether the exponent should be $-1$ or $-1/2$.\nSo Eigenmath requires\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nx^(-1/2)\n\\end{Verbatim}\n\nwhich is unambiguous.\nIn general, parentheses are always required when the exponent\nis an expression.\nFor example, \\verb$x^1/2$ is evaluated as $(x^1)/2$ which\nis probably not the desired result.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nx^1/2\n\\end{Verbatim}\n\n$\\displaystyle \\frac{1}{2}x$\n\nUsing \\verb$x^(1/2)$ yields the desired result.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nx^(1/2)\n\\end{Verbatim}\n\n$\\displaystyle x^{1/2}$\n", "meta": {"hexsha": "8a033261dc1ee967ab39ce85361df10ef86d780b", "size": 987, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/exponents.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/exponents.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/exponents.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.74, "max_line_length": 74, "alphanum_fraction": 0.7345491388, "num_tokens": 306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732855, "lm_q2_score": 0.8688267626522814, "lm_q1q2_score": 0.7103306008258868}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=2}^\\infty \\frac{2n}{n^2-1}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution 1}\r\n\r\nThe function $f(x)=\\frac{2x}{x^2-1}$ is continuous, positive, and decreasing on $[2,\\infty)$.\r\n\\begin{align*}\r\n\\int_2^\\infty \\frac{2x}{x^2-1}\\,dx\r\n&= \\lim_{t \\to \\infty} \\int_2^t \\frac{2x}{x^2-1}\\,dx\\\\\r\n&= \\lim_{t \\to \\infty} (\\ln|t^2-1| - \\ln |2^2-1|)\\\\\r\n&= \\infty\r\n\\end{align*}\r\nSince the integral $\\displaystyle \\int_2^\\infty \\frac{2x}{x^2-1}\\,dx$ diverges, the series $\\displaystyle \\sum_{n=2}^\\infty \\frac{2n}{n^2-1}$ diverges by the Integral Test.\r\n\r\n\\subsection*{Solution 2}\r\n\r\nThe series $\\sum \\frac1{n}$ diverges by the $p$-test. Let $a_n = \\frac{2n}{n^2-1}$ and $b_n=\\frac1{n}$. Then\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} \\frac{a_n}{b_n}\r\n&= \\lim_{n \\to \\infty} \\frac{2n^2}{n^2-1}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{4n}{2n} \\text{ by L'hopital}\\\\\r\n&= \\lim_{n \\to \\infty} 2 \\\\\r\n&= 2\r\n\\end{align*}\r\nSince this limit is a finite, positive number, by the Limit Comparison Test, the series $\\displaystyle \\sum_{n=2}^\\infty \\frac{2n}{n^2-1}$ diverges.\r\n\r\n\\subsection*{Solution 3}\r\n\r\nThis series can also be examined using the Direct Comparison Test, but we skip this method for this series.\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\left|\\frac{a_{n+1}}{a_n}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\right|\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} a_n\r\n&= \\lim_{n \\to \\infty} \\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} \\frac{a_n}{b_n}\r\n&= \\lim_{n \\to \\infty} \\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "1639328eca1756dcc24308d74da58cd3274dfe18", "size": 2237, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/g2.tex", "max_stars_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_stars_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "key/series/g2.tex", "max_issues_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_issues_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "key/series/g2.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 31.0694444444, "max_line_length": 173, "alphanum_fraction": 0.6262852034, "num_tokens": 867, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7103054547255963}}
{"text": "\\section{Inverses of functions}\nRiemann surfaces naturally arise when trying to invert complex functions. As in the real case, the inverse of the function $f(x) = x^2$ is not well-defined. There are multiple ways to remedy this, but the most \\emph{geometric} solution is to study the graph $y = x^2$ as a subset of $\\bbr^2$ and use this to construct inverses wherever they make sense.\n\nWe do the same for complex functions. Let $p(z)$ be a polynomial of degree $n$. Finding the inverse function is equivalent to solving\n\\begin{align*}\n  w = p(z)\n\\end{align*}\nto get $z$ in terms of $w$.\nThis is almost never possible, so instead we study the graph\n\\begin{align*}\n  \\Gamma_{p(z)} :=\n  \\set{ (z,w): w = p(z)} \\subseteq \\bbc^2\n\\end{align*}\nDenote by $\\pi: \\bbc^2$ the projection onto the $w$- coordinate axis\\footnote{We are working over complex numbers, so everything is twice the dimension of real numbers. So a complex axis is complex dimension 1 but real dimension 2.}.\n$\\Gamma_{p(z)}$ is an example of a Riemann surface!\nOur first goal is to undestand the geometry of this object. We'll do this using the projection $\\pi$.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Ramified coverings}\nConsider the restriction of $\\pi$ to $\\Gamma_{p(z)}$.\n\\begin{align*}\n  \\pi : \\Gamma_{p(z)} \\rightarrow \\bbc\n\\end{align*}\n\\begin{qbox}\n  Show that this map is surjective.\n\\end{qbox}\nThe inverse set $\\pi^{-1}(w)$ (called the \\emph{fiber} over $w$) is the set of roots of $p(z) - w$.\n\\begin{qbox}\n  Prove that there are only finitely many values of $w$ for which $\\pi^{-1}(w)$ has size $< n$. And that outside this set the fiber has size exactly $n$.\n\\end{qbox}\n\n\\begin{definition}\n  For $w \\in \\bbc$, if the polynomial $p(z) - w$ has distinct roots, then $w$ is called \\emph{unramified}.\n  This is equivalent to requiring that the fiber $\\pi^{-1}(w)$ has size $n$.\n  If $p(z) - w$ has repeated roots then, if $z$ is a repeated root of $p(z) - w$ of order $k$ we say that the \\emph{ramification index} $e_P$ of $P = (z,w)$ is $k$.\n\\end{definition}\n\\begin{qbox}\n  For $w_0 \\in \\bbc$, let $\\pi^{-1}(w_0) = \\set{P_1, \\dots, P_l}$, then\n  \\begin{align*}\n    e_{P_1} + \\dots + e_{P_l} = n\n  \\end{align*}\n\\end{qbox}\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[width=5cm]{example-image}\n  % \\includegraphics[width=]{}\n  \\caption{Picture of ramification}\n  \\label{figure:ramification}\n\\end{figure}\n\nA much stronger statement is true on the topological level.\nLet $w$ be an unramified value. Then $p(z) - w$ has $n$ distinct roots $z_1, \\dots, z_n$. If we perturb $w$ slightly then the corresponding roots $z_i$ will also get perturbed slightly.\n\nFor $\\epsilon \\in \\bbr$ let $B_\\epsilon(w) \\subset \\bbc$ denote a ball of radius $\\epsilon$ around $w$.\n\\begin{theorem}\n  \\label{theorem:coveringMap}\n  For an unramified value $w \\in \\bbc$, let $z_1, \\dots, z_n$ be the distinct roots of $p(z) - w$.\n  Then there exists an $\\epsilon$ such that $\\pi^{-1}(B_\\epsilon(w))$ has the following properties.\n  \\begin{enumerate}\n    \\item $\\pi^{-1}(B_\\epsilon(w))$ has $n$-connected components $U_1, \\dots, U_n$,\n    \\item $z_i \\in U_i$,\n    \\item the projections $\\pi: U_i \\rightarrow B_\\epsilon(w)$ are a homeomorphism.\n  \\end{enumerate}\n\\end{theorem}\n\nTheorem \\ref{theorem:coveringMap} is saying that the map $\\pi$ restricted to the fibers of unramified values is a \\emph{covering map}\n\\begin{align*}\n  \\pi: \\pi^{-1}(\\mbox{\\{unramified values\\}}) \\longrightarrow \\mbox{\\{unramified values\\}}.\n\\end{align*}\n\nIn Figure \\ref{figure:ramification} the ramified points appear to be singular, but\n\nA graph is always homeomorphic to the base i.e. the\n\\begin{align*}\n  \\bbc &\\rightarrow \\Gamma_{p(z)}\n  z \\mapsto (z, p(z))\n\\end{align*}\nis always a homeomorphism.\nSo the Riemann surface we have constructed is homeomorphic to $\\bbc$ itself!\nWe'll improve upon this in the following sections.\n\n\n\n\n\n\n\n\n\n\n\\subsection{Sections as inverse functions}\nWe now have a way of constructing inverse functions, which relies on the following theorem from topology.\n\nA space is said to be \\emph{simply-connected} if it is path-connected and every loop in $X$ can be continuously deformed to a point.\n\n\\begin{theorem}\n  If $X$ is a simply-connected space and $\\pi:Y \\rightarrow X$ is a finite covering of $X$ of degree $n$ then $Y$ is homeomorphic to $n$-disjoint copies of $X$ and the projection map on each connected component is a homeomorphism.\n  \\begin{equation*}\n    \\begin{tikzcd}\n      Y \\cong X_1 \\sqcup \\dots \\sqcup X_n\\\\\n      X_i\n      \\ar[d, \"\\cong\", \"\\pi\"'] \\\\\n      X\n    \\end{tikzcd}\n  \\end{equation*}\n  This statement is also true when the covering is not finite. In this case, $Y$ is a disjoint union of infinitely many components.\n\\end{theorem}\n\nNow we have a meaninful procedure to construct inverse functions of ramified coverings of $\\bbc$.\nConsider the ramified covering $\\pi: \\Gamma_{p(z)} \\rightarrow \\bbc$ with ramified values $w_1, \\dots, w_l$ (these are called the \\emph{branch points}).\n\\begin{enumerate}\n  \\item Consider the set of unramified points $\\bbc \\setminus \\set{w_1, \\dots, w_l}$. This set is never simply-connected (unless $l = 0$).\n  \\item Pick an arbitrary open subset $U$ of $\\bbc \\setminus \\set{w_1, \\dots, w_l}$ which is simply-connected. This is usually done by removing rays (called \\emph{branch cuts}) emanating from the points $w_i$.\n  \\item The restriction $\\pi: p^{-1}(U) \\rightarrow U$ is a finite covering of a simply-connected connected space $U$, hence $U \\cong U_1 \\sqcup \\dots \\sqcup U_n$.\n  \\item Pick an aribtrary connected component $U_i$ so that $\\pi:U_i \\rightarrow U$ is a homeomorphism. Because this is a homeomorphism it has an inverse $\\pi_i^{-1}: U \\rightarrow U_i$.\n  \\item The function $\\pi_i^{-1}$ followed by projection onto the $z$-coordinate is then an inverse of the function $p$. It is called a \\emph{branch} of the inverse function (and so there are $n$ possible branches).\n\\end{enumerate}\nWe need to choose \\emph{branch cuts} and a \\emph{branch} to define an inverse function.\n\\begin{ex}\n  \\todo{add an example here.}\n\\end{ex}\n", "meta": {"hexsha": "79b9ad32b2d2fe1055061951d4870a91b9c90f1c", "size": 6030, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01.tex", "max_stars_repo_name": "apurvnakade/mc2019-Riemann-surfaces", "max_stars_repo_head_hexsha": "edebdd1c81027b9cedb264eba1eeaa09dd4e311f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "01.tex", "max_issues_repo_name": "apurvnakade/mc2019-Riemann-surfaces", "max_issues_repo_head_hexsha": "edebdd1c81027b9cedb264eba1eeaa09dd4e311f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01.tex", "max_forks_repo_name": "apurvnakade/mc2019-Riemann-surfaces", "max_forks_repo_head_hexsha": "edebdd1c81027b9cedb264eba1eeaa09dd4e311f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.3383458647, "max_line_length": 352, "alphanum_fraction": 0.7033167496, "num_tokens": 1847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619306896955, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7103054525793916}}
{"text": "\\section{The univalence axiom}\n\n\\subsection{Equivalent forms of the univalence axiom}\n\nThe univalence axiom characterizes the identity type of the universe. Roughly speaking, it asserts that equivalent types are equal. It is considered to be an \\emph{extensionality principle}\\index{extensionality principle!types} for types. In the following theorem we introduce the univalence axiom and give two more equivalent ways of stating this.\n\n\\begin{defn}\n  The \\define{univalence axiom}\\index{univalence axiom|textbf} on a universe $\\UU$ is the statement that for any $A:\\UU$ the family of maps\\index{equiv_eq@{$\\mathsf{equiv\\usc{}eq}$}|textbf}\n\\begin{equation*}\n\\mathsf{equiv\\usc{}eq}\\defeq \\mathsf{path\\usc{}ind}_A(\\idfunc[A]) : \\prd{B:\\UU} (\\id{A}{B})\\to(\\eqv{A}{B}).\n\\end{equation*}\nis a family of equivalences.\\index{identity type!universe} A universe satisfying the univalence axiom is referred to as a \\define{univalent universe}. If $\\UU$ is a univalent universe we will write\n$\\mathsf{eq\\usc{}equiv}$\\index{eq equiv@{$\\mathsf{eq\\usc{}equiv}$}|textbf}\nfor the inverse of $\\mathsf{equiv\\usc{}eq}$.\n\\end{defn}\n\nThe following theorem is a special case of \\cref{thm:id_fundamental}. Subsequently we will assume that any type is contained in a univalent universe.\n\n\\begin{thm}\\label{thm:univalence}\nThe following are equivalent:\n\\begin{enumerate}\n\\item The univalence axiom holds.\n\\item The type\n\\begin{equation*}\n\\sm{B:\\UU}\\eqv{A}{B}\n\\end{equation*}\nis contractible for each $A:\\UU$.\n\\item The principle of \\define{equivalence induction}\\index{equivalence induction}\\index{induction principle!for equivalences}: for every $A:\\UU$ and for every type family\n\\begin{equation*}\nP:\\prd{B:\\UU} (\\eqv{A}{B})\\to \\mathsf{Type},\n\\end{equation*}\nthe map\n\\begin{equation*}\n\\Big(\\prd{B:\\UU}{e:\\eqv{A}{B}}P(B,e)\\Big)\\to P(A,\\idfunc[A])\n\\end{equation*}\ngiven by $f\\mapsto f(A,\\idfunc[A])$ has a section.\n\\end{enumerate}\n\\end{thm}\n\n\\subsection{Univalence implies function extensionality}\nOne of the first applications of the univalence axiom was Voevodsky's theorem that the univalence axiom on a universe $\\UU$ implies function extensionality for types in $\\UU$. The proof uses the fact that weak function extensionality implies function extensionality.\n\nWe will also make use of the following lemma. Note that this statement was also part of \\cref{lem:postcomp_equiv}. That exercise is solved using function extensionality. Since our present goal is to derive function extensionality from the univalence axiom, we cannot make use of that exercise.\n\n\\begin{lem}\\label{lem:postcomp-equiv}\n  For any equivalence $e:\\eqv{X}{Y}$ in a univalent universe $\\UU$, and any type $A$, the post-composition map\n  \\begin{equation*}\n    e\\circ\\blank : (A \\to X) \\to (A\\to Y)\n  \\end{equation*}\n  is an equivalence.\n\\end{lem}\n\n\\begin{proof}\n  The statement is obvious for the identity equivalence $\\idfunc : \\eqv{X}{X}$. Therefore the claim follows by equivalence induction, which is by \\cref{thm:univalence} one of the equivalent forms of the univalence axiom.\n\\end{proof}\n\n\\begin{thm}\n  For any universe $\\UU$, the univalence axiom on $\\UU$ implies function extensionality on $\\UU$.\n\\end{thm}\n\n\\begin{proof}\nNote that \\cref{thm:funext_wkfunext} also holds when it is restricted to small types. \nTherefore it suffices to show that univalence implies the weak principle of function extensionality.\n\nSuppose that $B:A\\to \\UU$ is a family of contractible types. Our goal is to show that the product $\\prd{x:A}B(x)$ is contractible.\nSince each $B(x)$ is contractible, the projection map $\\proj 1:\\big(\\sm{x:A}B(x)\\big)\\to A$ is an equivalence by \\cref{ex:proj_fiber}.\n\nNow it follows by \\cref{lem:postcomp-equiv} that $\\proj1\\circ\\blank$ is an equivalence. Consequently, it follows from \\cref{thm:contr_equiv} that the fibers of\n\\begin{equation*}\n\\proj 1\\circ\\blank : \\Big(A\\to \\sm{x:A}B(x)\\Big)\\to (A\\to A)\n\\end{equation*}\nare contractible. In particular, the fiber at $\\idfunc[A]$ is contractible. Therefore it suffices to show that $\\prd{x:A}B(x)$ is a retract of $\\sm{f:A\\to\\sm{x:A}B(x)}\\proj 1\\circ f=\\idfunc[A]$. In other words, we will construct\n\\begin{equation*}\n\\begin{tikzcd}\n\\Big(\\prd{x:A}B(x)\\Big) \\arrow[r,\"i\"] & \\Big(\\sm{f:A\\to\\sm{x:A}B(x)}\\proj 1\\circ f=\\idfunc[A]\\Big) \\arrow[r,\"r\"] & \\Big(\\prd{x:A}B(x)\\Big),\n\\end{tikzcd}\n\\end{equation*}\nand a homotopy $r\\circ i\\htpy \\idfunc$.\n\nWe define the function $i$ by\n\\begin{equation*}\n  i(f) \\defeq (\\lam{x}(x,f(x)),\\refl{\\idfunc}).\n\\end{equation*}\nTo see that this definition is correct, we need to know that\n\\begin{equation*}\n  \\lam{x}\\proj 1(x,f(x))\\jdeq \\idfunc.\n\\end{equation*}\nThis is indeed the case, by the $\\eta$-rule for $\\Pi$-types.\n\nNext, we define the function $r$. Let $h:A\\to \\sm{x:A}B(x)$, and let $p:\\proj 1 \\circ h = \\idfunc$. Then we have the homotopy $H\\defeq\\mathsf{htpy\\usc{}eq}(p):\\proj 1 \\circ h \\htpy \\idfunc$. Then we have $\\proj 2(h(x)):B(\\proj 1(h(x)))$ and we have the identification $H(x):\\proj 1(h(x))=x$. Therefore we define $r$ by\n\\begin{equation*}\n  r((h,p),x)\\defeq \\mathsf{tr}_B(H(x),\\proj 2(h(x))).\n\\end{equation*}\n\nWe note that if $p\\jdeq \\refl{\\idfunc}$, then $H(x)\\jdeq\\refl{x}$. In this case we have the judgmental equality $r((h,\\refl{}),x)\\jdeq\\proj 2 (h(x))$. Thus we see that $r\\circ i\\jdeq \\idfunc$ by another application of the $\\eta$-rule for $\\Pi$-types.\n\\end{proof}\n\n\\subsection{Propositional extensionality, posets, and subuniverses}\n\n\\begin{thm}\\label{thm:propositional-extensionality}\n  Propositions satisfy \\define{propositional extensionality}:\n  for any two propositions $P$ and $Q$, the canonical map\n  \\begin{equation*}\n    (P=Q)\\to (P\\leftrightarrow Q)\n  \\end{equation*}\n  is an equivalence. It follows that the type $\\prop$ of propositions in $\\UU$ is a set.\n\\end{thm}\n\nNote that for any $P:\\prop$, we usually also write $P$ for the underlying type of the proposition $P$. If we would be more formal about it we would have to write $\\proj 1(P)$ for the underlying type, since $\\prop$ is the $\\Sigma$-type $\\sm{X:\\UU}\\mathsf{is\\usc{}prop}(X)$. In the following proof it is clearer if we use the more formal notation $\\proj 1(P)$ for the underlying type of a proposition $P$.\n\n\\begin{proof}\n  We note that the identity type $P=Q$ is an identity type in $\\prop$. However, since $\\mathsf{is\\usc{}prop}(X)$ is a proposition for any type $X$, it follows that the map\n  \\begin{equation*}\n    \\apfunc{\\proj 1} : (P = Q) \\to (\\proj 1(P) = \\proj 1(Q))\n  \\end{equation*}\n  is an equivalence. Now we observe that we have a commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=huge]\n      (P=Q) \\arrow[d,swap,\"\\apfunc{\\proj 1}\"] \\arrow[r] & (P\\leftrightarrow Q) \\\\\n      (\\proj 1(P)=\\proj 1(Q)) \\arrow[r,swap,\"\\mathsf{equiv\\usc{}eq}\"] & (\\proj 1(P)\\simeq\\proj 1(Q)) \\arrow[u,swap,\"\\simeq\"]\n    \\end{tikzcd}\n  \\end{equation*}\n  Since the left, bottom, and right map are equivalences, it follows that the top map is an equivalence.\n\\end{proof}\n\n\\begin{defn}\n  A \\define{partially ordered set (poset)} is a set $P$ equipped with a relation\n  \\begin{equation*}\n    \\blank\\leq\\blank : P \\to (P \\to \\prop)\n  \\end{equation*}\n  that is \\define{reflexive} (for every $x:P$ we have $x\\leq x$), \\define{transitive} (for every $x,y,z:P$ such that $x\\leq y$ and $y\\leq z$ we have $x\\leq z$), and \\define{anti-symmetric} (for every $x,y:P$ such that $x\\leq y$ and $y\\leq x$ we have $x=y$).\n\\end{defn}\n\n\\begin{rmk}\n  The condition that $X$ is a set can be omitted from the definition of a poset. Indeed, if $X$ is any type that comes equipped with a $\\prop$-valued ordering relation $\\leq$ that is reflexive and anti-symmetric, then $X$ is a set by \\cref{lem:prop_to_id}.\n\\end{rmk}\n\n\\begin{eg}\n  The type $\\prop$ is a poset, where the ordering relation is given by implication: $P$ is less than $Q$ if $P\\to Q$. The fact that $P\\to Q$ is a proposition is a special case of \\cref{cor:funtype_trunc}. The relation $P\\to Q$ is reflexive by the identity function, and transitive by function composition. Moreover, the relation $P\\to Q$ is anti-symmetric by \\cref{thm:propositional-extensionality}.\n\\end{eg}\n\n\\begin{eg}\n  The type of natural numbers comes equipped with at least two important poset structures. The first is given by the usual ordering relation $\\leq$, and the second is given by the relation $d\\mid n$ that $d$ divides $n$.\n\\end{eg}\n\n\\begin{thm}\n  For any poset $P$ and any type $X$, the set $P^X$ is a poset. In particular the type of subtypes of any type is a poset.\n\\end{thm}\n\n\\begin{proof}\n  Let $P$ be a poset with ordering $\\leq$, and let $X$ be a type. Then $P^X$ is a set by \\cref{cor:funtype_trunc}. For any $f,g:X\\to P$ we define\n  \\begin{equation*}\n    (f\\leq g) \\defeq \\prd{x:X}f(x)\\leq g(x).\n  \\end{equation*}\n  Reflexivity and transitivity follow immediately from reflexivity and transitivity of the original relation. Moreover, by the anti-symmetry of the orignal relation it follows that\n  \\begin{equation*}\n    (f\\leq g)\\times (g\\leq f) \\to (f\\htpy g). \n  \\end{equation*}\n  Therefore we obtain an identification $f=g$ by function extensionality. The last claim follows immediately from the fact that a subtype of $X$ is a map $X\\to\\prop$, and the fact that $\\prop$ is a poset.\n\\end{proof}\n\nAnother important application of the univalence axiom is that any subuniverse is closed under equivalences. In this section we let $\\UU$ be a univalent universe.\n\n\\begin{thm}\n  Let $P:\\UU\\to\\prop$ be a subuniverse of $\\UU$. Then we have\n  \\begin{equation*}\n    (X\\simeq Y)\\to (P(X) \\to P(Y))\n  \\end{equation*}\n  for any two types $X,Y:\\UU$.\n\\end{thm}\n\n\\begin{proof}\n  We define the map $(X\\simeq Y)\\to (P(X)\\to P(Y))$ as the composite\n  \\begin{equation*}\n    \\begin{tikzcd}\n      (X\\simeq Y) \\arrow[r,\"\\mathsf{eq\\usc{}equiv}\"] &[2em] (X=Y) \\arrow[r,\"\\mathsf{tr}_P\"] & (P(X)\\to P(Y)).\n    \\end{tikzcd}\\qedhere\n  \\end{equation*}\n\\end{proof}\n\n\n\\subsection{Groups in univalent mathematics}\n\nIn this section we exhibit a typical way to use the univalence axiom, showing that isomorphic groups can be identified.\nThis is an instance of the \\emph{structure identity principle}\\index{structure identity principle}, which is described in more detail in section 9.8 of \\cite{hottbook}.\nWe will see that in order to establish the fact that isomorphic groups can be identified, it has to be part of the definition of a group that its underlying type is a set. This is an important observation: in many branches of algebra the objects of study are \\emph{set-level} structures\\footnote{A notable exception is that of categories, which are objects at truncation level $1$, i.e., at the level of \\emph{groupoids}. For more on this, see Chapter 9 of \\cite{hottbook}.}.\n\n\\subsubsection{Semi-groups and groups}\nWe introduce the type of groups in two stages: first we introduce the type of \\emph{semi-groups}, and then we introduce groups as semi-groups that possess further structure. It will turn out that this further structure is in fact a property, and this fact will help us to prove that isomorphic grous are equal.\n\n\\begin{defn}\n  A \\define{semi-group} consists of a set $G$ and an associative binary operation on $G$, i.e., a binary function\n  \\begin{equation*}\n    \\mu_G : G \\to (G \\to G)\n  \\end{equation*}\n  equipped with a homotopy\n  \\begin{equation*}\n    \\mathsf{assoc}_G : \\prd{x,y.z:G}\\mu_G(\\mu_G(x,y),z)=\\mu_G(x,\\mu_G(y,z)).\n  \\end{equation*}\n  We write $\\mathsf{Semi\\usc{}Group}$ for the type of all semi-groups.\n\\end{defn}\n\n\\begin{defn}\n  A semi-group $G$ is said to be \\define{unital} if it comes equipped with a \\define{unit} $e_G:G$ that satisfies the left and right unit laws\n  \\begin{align*}\n    \\mathsf{left\\usc{}unit}_G : \\prd{y:G}\\mu_G(e_G,y)=y \\\\\n    \\mathsf{right\\usc{}unit}_G : \\prd{x:G}\\mu_G(x,e_G)=x.\n  \\end{align*}\n  We write $\\mathsf{is\\usc{}unital}(G)$ for the type of such triples $(e_G,\\mathsf{left\\usc{}unit}_G,\\mathsf{right\\usc{}unit}_G)$. Unital semi-groups are also called \\define{monoids}.\n\\end{defn}\n\nThe unit of a semi-group is of course unique once it exists. In univalent mathematics we express this fact by asserting that the type $\\mathsf{is\\usc{}unital}(G)$ is a proposition for each semi-group $G$. In other words, being unital is a \\emph{property} of semi-groups rather than structure on it. This is typical for univalent mathematics: we express that a structure is a property by proving that this structure is a proposition.\n\n\\begin{lem}\n  For a semi-group $G$ the type $\\mathsf{is\\usc{}unital}(G)$ is a proposition.\n\\end{lem}\n\n\\begin{proof}\n  Let $G$ be a semi-group. Note that since $G$ is a set, it follows that the types of the left and right unit laws are propositions. Therefore it suffices to show that any two terms $e,e':G$ satisfying the left and right unit laws can be identified. This is easy:\n  \\begin{equation*}\n    e = \\mu_G(e,e') = e'.\\qedhere\n  \\end{equation*}\n\\end{proof}\n\n\\begin{defn}\n  Let $G$ be a unital semi-group. We say that $G$ has inverses if it comes equipped with an operation $x\\mapsto x^{-1}$ of type $G\\to G$, satisfying the left and right inverse laws\n  \\begin{align*}\n    \\mathsf{left\\usc{}inv}_G : \\prd{x:G}\\mu_G(x^{-1},x)=e_G \\\\\n    \\mathsf{right\\usc{}inv}_G : \\prd{x:G}\\mu_G(x,x^{-1}) = e_G.\n  \\end{align*}\n  We write $\\mathsf{is\\usc{}group}'(G,e)$ for the type of such triples $((\\blank)^{-1},\\mathsf{left\\usc{}inv}_G,\\mathsf{right\\usc{}inv}_G)$, and we write\n  \\begin{equation*}\n    \\mathsf{is\\usc{}group}(G)\\defeq\\sm{e:\\mathsf{is\\usc{}unital}(G)}\\mathsf{is\\usc{}group}'(G,e)\n  \\end{equation*}\n  A \\define{group} is a unital semi-group with inverses. We write $\\mathsf{Group}$ for the type of all groups.\n\\end{defn}\n\n\\begin{lem}\n  For any semi-group $G$ the type $\\mathsf{is\\usc{}group}(G)$ is a proposition.\n\\end{lem}\n\n\\begin{proof}\n  We have already seen that the type $\\mathsf{is\\usc{}unital}(G)$ is a proposition. Therefore it suffices to show that the type $\\mathsf{is\\usc{}group}'(G,e)$ is a proposition for any $e:\\mathsf{is\\usc{}unital}(G)$.\n\n  Since a semi-group $G$ is assumed to be a set, we note that the types of the inverse laws are propositions. Therefore it suffices to show that any two inverse operations satisfying the inverse laws are homotopic.\n\n  Let $x\\mapsto x^{-1}$ and $x\\mapsto \\bar{x}^{-1}$ be two inverse operations on a unital semi-group $G$, both satisfying the inverse laws. Then we have the following identifications\n  \\begin{align*}\n    x^{-1} & = \\mu_G(e_G,x^{-1}) \\\\\n    & = \\mu_G(\\mu_G(\\bar{x}^{-1},x),x^{-1}) \\\\\n    & = \\mu_G(\\bar{x}^{-1},\\mu_G(x,x^{-1})) \\\\\n    & = \\mu_G(\\bar{x}^{-1},e_G) \\\\\n    & = \\bar{x}^{-1}\n  \\end{align*}\n  for any $x:G$. Thus the two inverses of $x$ are the same, so the claim follows.\n\\end{proof}\n\n\\begin{eg}\n  An important class of examples consists of \\define{loop spaces}\\index{loop space|textbf} $x=x$ of a $1$-type $X$, for any $x:X$. \n  We will write $\\loopspace{X,x}$ for the loop space of $X$ at $x$. \n  Since $X$ is assumed to be a $1$-type, it follows that the type $\\loopspace{X,x}$ is a set. Then we have\n  \\begin{align*}\n    \\refl{x} & : \\loopspace{X,x} \\\\\n    \\mathsf{inv} & : \\loopspace{X,x} \\to \\loopspace{X,x} \\\\\n    \\mathsf{concat} & : \\loopspace{X,x} \\to (\\loopspace{X,x}\\to \\loopspace{X,x}),\n  \\end{align*}\n  and these operations satisfy the group laws, since the group laws are just a special case of the groupoid laws for identity types, constructed in \\cref{sec:groupoid}.\n  \n  Using higher inductive types we will show in \\cref{chap:image} that \\emph{every} group is of this form.\n\\end{eg}\n\n\\begin{eg}\n  The type $\\Z$ of integers\\index{Z@{$\\Z$}!is a group} can be given the structure of a group, with the group operation being addition. The fact that $\\Z$ is a set follows from \\cref{thm:eq_nat,ex:set_coprod}. The group laws were shown in \\cref{ex:int_group_laws}. \n\\end{eg}\n\n\\begin{eg}\n  Our last class of examples consists of the \\define{automorphism groups} on sets. Given a set $X$, we define\n  \\begin{equation*}\n    \\mathsf{Aut}(X)\\defeq (X\\simeq X).\n  \\end{equation*}\n  The group operation of $\\mathsf{Aut}(X)$ is just composition of equivalences, and the unit of the group is the identity function. Note however, that although function composition is strictly associative and satisfies the unit laws strictly, composition of equivalences only satisfies the group laws up to identification because the proof that composites are equivalences is carried along.\n\n  Important special cases of the automorphism groups are the symmetry groups\n  \\begin{equation*}\n    \\mathcal{S}_n\\defeq \\mathsf{Aut}(\\mathsf{Fin}(n)).\n  \\end{equation*}\n\\end{eg}\n\n\\subsubsection{Homomorphisms of semi-groups and groups}\n\n\\begin{defn}\n  Let $G$ and $H$ be semi-groups. A homomorphism $f:G\\to H$ of semi-groups is a pair $(f,\\mu_f)$ consisting of a function $f:G\\to H$ between their underlying types, and a term\n  \\begin{equation*}\n    \\mu_f:\\prd{x,y:G} f(\\mu_G(x,y))=\\mu_H(f(x),f(y))\n  \\end{equation*}\n  witnessing that $f$ preserves the binary operation of $G$. We will write\n  \\begin{equation*}\n    \\mathsf{hom}(G,H)\n  \\end{equation*}\n  for the type of all semi-group homomorphisms from $G$ to $H$.\n\\end{defn}\n\n\\begin{rmk}\\label{rmk:is-set-hom-semi-group}\n  Since it is a property for a function to preserve the multiplication of a semi-group, it follows easily that equality of semi-group homomorphisms is equivalent to the type of homotopies between their underlying functions. In particular, it follows that the type of homomorphisms of semi-groups is a set.\n\\end{rmk}\n\n\\begin{rmk}\n  The \\define{identity homomorphism} on a semi-group $G$ is defined to be the pair consisting of\n  \\begin{align*}\n    \\idfunc & : G \\to G \\\\\n    \\lam{x}{y}\\refl{xy} & : \\prd{x,y:G} xy = xy.\n  \\end{align*}\n  Let $f:G\\to H$ and $g:H\\to K$ be semi-group homomorphisms. Then the composite function $g\\circ f:G\\to K$ is also a semi-group homomorphism, since we have the identifications\n  \\begin{equation*}\n    \\begin{tikzcd}\n      g(f(xy)) \\arrow[r,equals] & g(f(x)f(y)) \\arrow[r,equals] & g(f(x))g(f(y)).\n    \\end{tikzcd}\n  \\end{equation*}\n  Since the identity type of semi-group homomorphisms is equivalent to the type of homotopies between semi-group homomorphisms it is easy to see that semi-group homomorphisms satisfy the laws of a category, i.e., that we have the identifications\n  \\begin{align*}\n    \\idfunc\\circ f & = f \\\\\n    g\\circ \\idfunc & = g \\\\\n    (h\\circ g) \\circ f & = h \\circ (g \\circ f)\n  \\end{align*}\n  for any composable semi-group homomorphisms $f$, $g$, and $h$. Note, however that these equalities are not expected to hold judgmentally, since preservation of the semi-group operation is part of the data of a semi-group homomorphism.\n\\end{rmk}\n\n\\begin{defn}\n  A homomorphism $f:G\\to H$ of groups is defined to be a semi-group homomorphism between their underlying semi-groups. We will write\n  \\begin{equation*}\n    \\mathsf{hom}(G,H)\n  \\end{equation*}\n  for the type of all group homomorphisms from $G$ to $H$.\n\\end{defn}\n\n\\begin{rmk}\n  Since a group homomorphism is just a semi-group homomorphism between the underlying semi-groups, we immediately obtain the identity homomorphism, composition, and the category laws are satisfied.\n\\end{rmk}\n\n\\subsubsection{Isomorphic semi-groups are equal}\n\n\\begin{defn}\nLet $h:\\mathrm{hom}(\\mathcal{G},\\mathcal{H})$ be a group homomorphism. Then $h$ is said to be an \\define{isomorphism}\\index{group homomorphism!isomorphism}\\index{isomorphism!of groups} if there is a group homomorphism $h^{-1}:\\mathrm{hom}(\\mathcal{H},\\mathcal{G})$ such that\n\\begin{equation*}\nh^{-1}\\circ h=\\idfunc[\\mathcal{G}]\\qquad\\text{and}\\qquad h\\circ h^{-1}=\\idfunc[\\mathcal{H}].\n\\end{equation*}\nWe write $\\mathcal{G}\\cong\\mathcal{H}$ for the type of all group isomorphisms from $\\mathcal{G}$ to $\\mathcal{H}$, i.e.,\n\\begin{equation*}\n\\mathcal{G}\\cong\\mathcal{H} \\defeq \\sm{h:\\mathrm{hom}(\\mathcal{G},\\mathcal{H})}{k:\\mathrm{hom}(\\mathcal{H},\\mathcal{G})} (k\\circ h = \\idfunc[\\mathcal{G}])\\times (h\\circ k=\\idfunc[\\mathcal{H}]).\n\\end{equation*}\n\\end{defn}\n\nIf $f$ is an isomorphism, then its inverse is unique. In other words, being an isomorphism is a property.\n\n\\begin{lem}\n  For any semi-group homomorphism $h:\\mathsf{hom}(G,H)$, the type\n  \\begin{equation*}\n    \\mathsf{is\\usc{}iso}(h)\n  \\end{equation*}\n  is a proposition. It follows that the type $G\\cong H$ is a set for any two semi-groups $G$ and $H$.\n\\end{lem}\n\n\\begin{proof}\n  Let $k$ and $k'$ be two inverses of $h$. In \\cref{rmk:is-set-hom-semi-group} we have observed that the type of semi-group homomorphisms between any two semi-groups is a set. Therefore it follows that the types $h\\circ k=\\idfunc$ and $k\\circ h=\\idfunc$ are propositions, so it suffices to check that $k=k'$. In \\cref{rmk:is-set-hom-semi-group} we also observed that the equality type $k=k'$ is equivalent to the type of homotopies $k\\htpy k'$ between their underlying functions. We construct a homotopy $k\\htpy k'$ by the usual argument:\n  \\begin{equation*}\n    \\begin{tikzcd}\n      k(y) \\arrow[r,equals] & k(h(k'(y)) \\arrow[r,equals] & k'(y).\n    \\end{tikzcd}\\qedhere\n  \\end{equation*}\n\\end{proof}\n\n\\begin{lem}\\label{lem:grp_iso}\n  A semi-group homomorphism $h:\\mathsf{hom}(G,H)$ is an isomorphism if and only if its underlying map is an equivalence. Consequently, there is an equivalence\n  \\begin{equation*}\n    (G\\cong H)\\simeq \\sm{e:G\\simeq H}\\prd{x,y:G}e(\\mu_G(x,y))=\\mu_H(e(x),e(y))\n  \\end{equation*}\n\\end{lem}\n\n\\begin{proof}\n  If $h:\\mathsf{hom}(G,H)$ is an isomorphism, then the inverse semi-group homomorphism also provides an inverse of the underlying map of $h$. Thus we obtain that $h$ is an equivalence. The standard proof showing that if the underlying map $f:G\\to H$ of a group homomorphism is invertible then its inverse is again a group homomorphism also works in type theory.\n\\end{proof}\n\n\\begin{defn}\nLet $\\mathcal{G}$ and $\\mathcal{H}$ be a semi-groups. We define the map\\index{iso_eq@{$\\mathsf{iso\\usc{}eq}$}|textbf}\n\\begin{equation*}\n\\mathsf{iso\\usc{}eq} : (\\mathcal{G}=\\mathcal{H})\\to (\\mathcal{G}\\cong\\mathcal{H})\n\\end{equation*}\nby path induction, taking $\\refl{\\mathcal{G}}$ to isomorphism $\\idfunc[\\mathcal{G}]$.\n\\end{defn}\n\n\\begin{thm}\\label{thm:iso-eq-semi-group}\nThe map\n\\begin{equation*}\n\\mathsf{iso\\usc{}eq} : (\\mathcal{G}=\\mathcal{H})\\to (\\mathcal{G}\\cong\\mathcal{H})\n\\end{equation*}\nis an equivalence for any two semi-groups $\\mathcal{G}$ and $\\mathcal{H}$.\n\\end{thm}\n\n\\begin{proof}\nBy \\cref{thm:id_fundamental} it suffices to show that the total space\n\\begin{equation*}\n\\sm{\\mathcal{G}':\\mathsf{Semi\\usc{}Grp}}\\mathcal{G}\\cong\\mathcal{G}'\n\\end{equation*}\nis contractible. Since the type of isomorphisms from $\\mathcal{G}$ to $\\mathcal{G}'$ is equivalent to the type of equivalences from $\\mathcal{G}$ to $\\mathcal{G}'$ it suffices to show that the type\n\\begin{equation*}\n  \\sm{\\mathcal{G}':\\mathsf{Semi\\usc{}Grp}}\\sm{e:\\eqv{G}{G'}}\\prd{x,y:G}e(\\mu_G(x,y))=\\mu_{G'}(e(x),e(y)))\n\\end{equation*}\nis contractible\\footnote{In order to show that a type of the form\n  \\begin{equation*}\n    \\sm{(x,y):\\sm{x:A}B(x)}\\sm{z:C(x)}D(x,y,z)\n  \\end{equation*}\n  is contractible, a useful strategy is to first show that the type $\\sm{x:A}C(x)$ is contractible. Once this is established, say with center of contraction $(x_0,z_0)$, it suffices to show that the type $\\sm{y:B(x_0)}D(x_0,y,z_0)$ is contractible.}. Since $\\mathsf{Semi\\usc{}Grp}$ is the $\\Sigma$-type\n\\begin{equation*}\n  \\sm{G':\\mathsf{Set}}\\mathsf{has\\usc{}associative\\usc{}mul}(G'),\n\\end{equation*}\nit suffices to show that the types\n\\begin{align*}\n  & \\sm{G':\\mathsf{Set}}\\eqv{G}{G'} \\\\\n  & \\sm{\\mu':\\mathsf{has\\usc{}associative\\usc{}mul}(G)}\\prd{x,y:G}\\mu_G(x,y)=\\mu'(x,y)\n\\end{align*}\nis contractible. The first type is contractible by the univalence axiom. The second type is contractible by function extensionality.\n\\end{proof}\n\n\\begin{cor}\nThe type $\\mathsf{Semi\\usc{}Grp}$ is a $1$-type.\\index{Semi-Grp@{$\\mathsf{Semi-Grp}$}!is a $1$-type|textit}\n\\end{cor}\n\n\\begin{proof}\nIt is straightforward to see that the type of group isomorphisms $\\mathcal{G}\\cong\\mathcal{H}$ is a set, for any two groups $\\mathcal{G}$ and $\\mathcal{H}$.\n\\end{proof}\n\n\\subsubsection{Isomorphic groups are equal}\n\nAnalogously to the map $\\mathsf{iso\\usc{}eq}$ of semi-groups, we have a map $\\mathsf{iso\\usc{}eq}$ of groups. Note, however, that the domain of this map is now the identity type $G=H$ of the \\emph{groups} $G$ and $H$, so the maps $\\mathsf{iso\\usc{}eq}$ of semi-groups and groups are not exactly the same maps.\n\n\\begin{defn}\n  Let $G$ and $H$ be groups. We define the map\n  \\begin{equation*}\n    \\mathsf{iso\\usc{}eq} : (G=H)\\to (G\\cong H)\n  \\end{equation*}\n  by path induction, taking $\\refl{G}$ to the identity isomorphism $\\idfunc:G\\cong G$.\n\\end{defn}\n\n\\begin{thm}\n  For any two groups $G$ and $H$, the map\n  \\begin{equation*}\n    \\mathsf{iso\\usc{}eq}:(G=H)\\to (G\\cong H)\n  \\end{equation*}\n  is an equivalence.\n\\end{thm}\n\n\\begin{proof}\n  Let $G$ and $H$ be groups, and write $UG$ and $UH$ for their underlying semi-groups, respectively. Then we have a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}\n      (G=H) \\arrow[rr,\"\\apfunc{\\proj 1}\"] \\arrow[dr,swap,\"\\mathsf{iso\\usc{}eq}\"] & & (UG=UH) \\arrow[dl,\"\\mathsf{iso\\usc{}eq}\"] \\\\\n      & (G\\cong H)\n    \\end{tikzcd}\n  \\end{equation*}\n  Since being a group is a property of semi-groups it follows that the projection map $\\mathsf{Grp}\\to\\mathsf{Semi\\usc{}Grp}$ forgetting the unit and inverses, is an embedding. Thus the top map in this triangle is an equivalence. The map on the right is an equivalence by \\cref{thm:iso-eq-semi-group}, so the claim follows by the 3-for-2 property.\n\\end{proof}\n\n\\begin{cor}\n  The type of groups is a $1$-type.\n\\end{cor}\n\n\\subsection{Categories in univalent mathematics}\n\nIn our proof of the fact that isomorphic groups are equal we have made extensive use of the notion of group homomorphism. What we have shown, in fact, is that there is a category of groups which is \\emph{Rezk complete} in the sense that the type of isomorphisms between two objects is equivalent to the type of identifications between those objects. In this final section we briefly introduce the notion of Rezk complete category. There are many more examples of categories, such as the categories of rings, or modules over a ring.\n\n\\begin{defn}\n  A \\define{pre-category} $\\mathcal{C}$ consists of\n  \\begin{enumerate}\n  \\item A type $A$ of \\define{objects}.\n  \\item For every two objects $x,y:A$ a set\n    \\begin{equation*}\n      \\mathsf{hom}(x,y)\n    \\end{equation*}\n    of \\define{morphisms} from $x$ to $y$.\n  \\item For every object $x:A$ an \\define{identity morphism}\n    \\begin{equation*}\n      \\idfunc : \\mathsf{hom}(x,x)\n    \\end{equation*}\n  \\item For every two morphisms $f:\\mathsf{hom}(x,y)$ and $g:\\mathsf{hom}(y,z)$, a morphism\n    \\begin{equation*}\n      g\\circ f :\\mathsf{hom}(x,z)\n    \\end{equation*}\n    called the \\define{composite} of $f$ and $g$.\n  \\item the following terms\n    \\begin{align*}\n      \\mathsf{left\\usc{}unit}_{\\mathcal{C}} & : \\idfunc \\circ f = f \\\\\n      \\mathsf{right\\usc{}unit}_{\\mathcal{C}} & : g \\circ \\idfunc = g \\\\\n      \\mathsf{assoc}_{\\mathcal{C}} & : (h \\circ g) \\circ f = h \\circ (g \\circ f)\n    \\end{align*}\n    witnessing that the category laws are satisfied.\n  \\end{enumerate}\n\\end{defn}\n\n\\begin{eg}\n  By \\cref{rmk:category-semi-group,rmk:category-group} we have pre-categories of semi-groups and of groups.\n\\end{eg}\n\n\\begin{eg}\n  A pre-category satisfying the condition that every hom-set is a proposition is a \\define{preorder}. \n\\end{eg}\n\n\\begin{defn}\n  Given a pre-category $\\mathcal{C}$, a morphism $f:\\mathsf{hom}(x,y)$ is said to be an \\define{isomorphism} if there exists a morphism $g:\\mathsf{hom}(y,x)$ such that\n  \\begin{align*}\n    g\\circ f & = \\idfunc \\\\\n    f \\circ g & \\idfunc.\n  \\end{align*}\n  We will write $\\mathsf{iso}(x,y)$ for the type of all isomorphisms in $\\mathcal{C}$ from $x$ to $y$.\n\\end{defn}\n\n\\begin{rmk}\n  Just as in the case for semi-groups and groups, the condition that $f:\\mathsf{hom}(x,y)$ is an isomorphism is a property of $f$.\n\\end{rmk}\n\n\\begin{defn}\n  A pre-category $\\mathcal{C}$ is said to be \\define{Rezk-complete} if the canonical map\n  \\begin{equation*}\n    (x=y)\\to \\mathsf{iso}(x,y)\n  \\end{equation*}\n  is an equivalence for any two objects $x$ and $y$ of $\\mathcal{C}$. Rezk-complete pre-categories are also called \\define{categories}.\n\\end{defn}\n\n\\begin{eg}\n  The pre-category of sets is Rezk complete by the univalence axiom, so it is a category.\n\\end{eg}\n\n\\begin{eg}\n  The pre-categories of semi-groups and groups are Rezk-complete. Therefore they form categories.\n\\end{eg}\n\n\\begin{eg}\n  A pre-order is Rezk-complete if and only if it is anti-symmetric. In other words, a poset is precisely a category for which all the hom-sets are propositions. Thus, we see that the anti-symmetry axiom can be seen as a univalence axiom for pre-orders.\n\\end{eg}\n\n\\begin{exercises}\n\\item Let $X$ be a set. Show that the map\n  \\begin{equation*}\n    \\mathsf{equiv\\usc{}eq} : (X=X)\\to (\\eqv{X}{X})\n  \\end{equation*}\n  is a group isomorphism.\n%\\item \\label{ex:tr_ap} Show that for any $P:X\\to \\UU$ and any $p:x=y$ in $X$, we have\\index{equiv_eq@{$\\mathsf{equiv\\usc{}eq}$}}\\index{transport}\n%\\begin{equation*}\n%\\mathsf{equiv\\usc{}eq}(\\ap{P}{p})\\htpy \\mathsf{tr}_P(p).\n%\\end{equation*}\n\\item \\label{ex:istrunc_UUtrunc}\n\\begin{subexenum}\n\\item Use the univalence axiom to show that the type $\\sm{A:\\UU}\\iscontr(A)$ of all contractible types in $\\UU$ is contractible.\\index{universe!of contractible types}\n\\item Use \\cref{cor:emb_into_ktype,cor:funtype_trunc,ex:isprop_isequiv} to show that if $A$ and $B$ are $(k+1)$-types, then the type $\\eqv{A}{B}$ is also a $(k+1)$-type.\\index{equiv@{$\\eqv{A}{B}$}!truncatedness}\n\\item Use univalence to show that the universe of $k$-types\\index{universe!of k-types@{of $k$-types}}\\index{U leq k@{$\\UU^{\\leq k}$}|textbf}\n\\begin{equation*}\n\\UU^{\\leq k}\\defeq \\sm{X:\\UU}\\mathsf{is\\usc{}trunc}_k(X)\n\\end{equation*}\nis a $(k+1)$-type, for any $k\\geq -2$.\n\\item It follows that the universe of propositions $\\UU^{\\leq-1}$ is a set. However, show that $\\UU^{\\leq-1}$ is not a proposition.\\index{universe!of propositions}\n\\item Show that $\\eqv{(\\eqv{\\bool}{\\bool})}{\\bool}$, and conclude by the univalence axiom that the universe of sets\\index{universe!of sets} $\\UU^{\\leq 0}$ is not a set. \n\\end{subexenum}\n\\item Use the univalence axiom to show that the type $\\sm{P:\\prop}P$ is contractible.\n\\item Let $A$ and $B$ be small types. \n\\begin{subexenum}\n\\item Construct an equivalence\n\\begin{equation*}\n\\eqv{(A\\to (B\\to\\UU))}{\\Big(\\sm{S:\\UU} (S\\to A)\\times (S\\to B)\\Big)}\n\\end{equation*}\n\\item We say that a relation $R:A\\to (B\\to\\UU)$ is \\define{functional}\\index{relation!functional} if it comes equipped with a term of type\\index{is_function(R)@{$\\mathsf{is\\usc{}function}(R)$}|textbf}\n\\begin{equation*}\n\\mathsf{is\\usc{}function}(R) \\defeq \\prd{x:A}\\iscontr\\Big(\\sm{y:B}R(x,y)\\Big)\n\\end{equation*}\nFor any function $f:A\\to B$, show that the \\define{graph}\\index{graph!of a function|textbf} of $f$ \n\\begin{equation*}\n\\mathsf{graph}_f:A\\to (B\\to \\UU)\n\\end{equation*}\ngiven by $\\mathsf{graph}_f(a,b)\\defeq (f(a)=b)$ is a functional relation from $A$ to $B$.\n\\item Construct an equivalence\n\\begin{equation*}\n\\eqv{\\Big(\\sm{R:A\\to (B\\to\\UU)}\\mathsf{is\\usc{}function}(R)\\Big)}{(A\\to B)}\n\\end{equation*}\n\\item Given a relation $R:A\\to (B\\to \\UU)$ we define the \\define{opposite relation}\\index{relation!opposite relation|textbf}\\index{opposite relation|textbf}\\index{op R@{$R^{\\mathsf{op}}$}|textbf}\n\\begin{equation*}\nR^{\\mathsf{op}} : B\\to (A\\to\\UU)\n\\end{equation*}\nby $R^{\\mathsf{op}}(y,x)\\defeq R(x,y)$. Construct an equivalence\\index{equiv@{$\\eqv{A}{B}$}!as relation}\n\\begin{equation*}\n\\eqv{\\Big(\\sm{R:A\\to (B\\to \\UU)}\\mathsf{is\\usc{}function}(R)\\times\\mathsf{is\\usc{}function}(R^{\\mathsf{op}})\\Big)}{(\\eqv{A}{B})}.\n\\end{equation*}\n\\end{subexenum}\n\\item\n  \\begin{subexenum}\n  \\item Show that $\\mathsf{is\\usc{}decidable}(P)$ is a proposition, for any proposition $P$.\n  \\item Show that $\\mathsf{classical\\usc{}Prop}$ is equivalent to $\\bool$.\n  \\end{subexenum}\n\\item\n  \\begin{subexenum}\n  \\item Consider a group $G$. Show that the function\n    \\begin{equation*}\n      \\mu_G:G\\to (G\\simeq G)\n    \\end{equation*}\n    is an injective group homomorphism.\n  \\item Consider a type $A$. Show that the concatenation function\n    \\begin{equation*}\n      \\mathsf{concat}:\\loopspace{A}\\to (\\loopspace{A}\\simeq\\loopspace{A})\n    \\end{equation*}\n    is an embedding.\n  \\end{subexenum}\n\\item Let $f:\\mathsf{hom}(G,H)$ be a group homomorphism. Show that $f$ preserves units and inverses, i.e., show that\n  \\begin{align*}\n    f(e_G) & = e_H \\\\\n    f(x^{-1}) & = f(x)^{-1}.\n  \\end{align*}\n\\item Give a direct proof and a proof using the univalence axiom of the fact that all semi-group isomorphisms between unital semi-groups preserve the unit. Conclude that isomorphic monoids are equal.\n\\item Recall that $\\UU_\\ast$ is the universe of pointed types. Construct for any pointed type $(X,x_0)$ an equivalence\n  \\begin{equation*}\n    \\Big(\\sm{P:X\\to \\UU}P(x_0)\\Big)\\simeq \\sm{(A,a_0):\\UU_\\ast}(A,a_0)\\to_\\ast(X,x_0).\n  \\end{equation*}\n\\end{exercises}\n", "meta": {"hexsha": "11642c88725eb0295779b67b980ee1da8cf836f9", "size": 33062, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/univalence.tex", "max_stars_repo_name": "tadejpetric/HoTT-Intro", "max_stars_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Book/univalence.tex", "max_issues_repo_name": "tadejpetric/HoTT-Intro", "max_issues_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Book/univalence.tex", "max_forks_repo_name": "tadejpetric/HoTT-Intro", "max_forks_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.3258064516, "max_line_length": 538, "alphanum_fraction": 0.6992922388, "num_tokens": 10986, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8615382165412808, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7103054520827764}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\section{Lecture 12}\n\\subsection{Lecture Notes - Weakly Coupled Oscillators}\nRecall from our work two lectures ago that for the 2-mass 3-springs problem, the eigenfrequencies were determined to be:\n\\[\\omega_1 = \\sqrt{\\frac{k+2k_{12}}{m}}, \\quad \\omega_2 = \\sqrt{\\frac{k}{m}}\\]\nNow, we make the assumption that $k_{12} \\ll k$, i.e. that the middle spring joining the masses is quite weak. In this limit, we can clearly see that $\\omega_1 \\approx \\omega_2$. This generates an interesting physical case; here we can define a \"middle frequency\" which is the average of the two eigenfrequencies above:\n\\[\\omega_0 = \\frac{\\omega_1 + \\omega_2}{2}\\]\nWe could then rewrite $\\omega_1, \\omega_2$ in terms of $\\omega_0$ and a small parameter $\\e$:\n\\[\\omega_1 = \\omega_0 + \\e\\]\n\\[\\omega_2 = \\omega_0 - \\e\\]\nThe general solution could then be written as:\n\\[\\v{z}(t) = C_1\\m{1 \\\\ -1}\\exp(i(\\omega_0 + \\e)t) + C_2\\m{1\\\\1}\\exp(i(\\omega_0 - \\e)t)\\]\nWe can factor this expression, recognizing common terms:\n\\[\\v{z}(t) = \\left(C_1\\m{1 \\\\ -1}\\exp(i\\e t) + C_2\\m{1\\\\1}\\exp(-i\\e t)\\right)\\exp(i\\omega_0 t)\\]\nNow, suppose that $C_1 = C_2 = \\frac{A}{2}$ (i.e. the two modes are excited to be the same amplitude). We then have that:\n\\[\\v{z}(t) = \\frac{A}{T}\\m{\\exp(i\\e t) + \\exp(-i\\e t) \\\\ \\exp(-i\\e t) - \\exp(i \\e t)}\\exp(i\\omega_0 t)\\]\nThen using Euler's formula:\n\\[\\v{z}(t) = A\\m{\\cos(\\e t) \\\\ -i\\sin(\\e t)}\\exp(i\\omega_0 t)\\]\nNow taking the real part of this:\n\\[\\Re\\v{z}(t) = \\v{x}(t) = \\m{x_1 \\\\ x_2} = \\m{A\\cos(\\e t)\\cos(\\omega_0 t) \\\\ A\\sin(\\e t)\\sin(\\omega_0 t)}\\]\nThis result corresponds to a fast oscillation (e.g. at frequency $\\omega_0$) modulated by a slower oscillation (at frequency $\\e$ which is small by assumption). When graphed, this looks like:\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-12/l12-img1.png}\n\\end{center}\nWhere we see \"beats\"! Exactly like with AM radio waves, we see the frequency stay constant but the amplitude going up and down with time.\n\\end{document}", "meta": {"hexsha": "57544d505b8054896b49e9ea44a79478228d2d10", "size": 2040, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-12/Lecture-Notes-12.tex", "max_stars_repo_name": "RioWeil/PHYS306-notes", "max_stars_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture-12/Lecture-Notes-12.tex", "max_issues_repo_name": "RioWeil/PHYS306-notes", "max_issues_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture-12/Lecture-Notes-12.tex", "max_forks_repo_name": "RioWeil/PHYS306-notes", "max_forks_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 72.8571428571, "max_line_length": 319, "alphanum_fraction": 0.6754901961, "num_tokens": 721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199673867852, "lm_q2_score": 0.8479677622198947, "lm_q1q2_score": 0.7102747293356735}}
{"text": "\\chapter{Statistics}\nData are collections of information made through observations. Statistics is the device through which data is cranked through to make interpretations of what the data actually says.\n\n\\section{OUTSTANDING ITEMS}\n\\begin{itemize}\n\t\\item Uniformize notation, use $w$ as a vector, etc\n\t\\item Sort sections\n\t\\item Fill out TODOs\n\\end{itemize}\n\n\\subsection{Mean}\nGiven a set of data, one important feature one might wish to know is what this data looks like on average. This average is typically synonymous with the arithmetic mean defined as \n\n\\begin{align}\n\\E[x] \\equiv \\bar{x} = \\frac{1}{n}\\sum_{i=1}^n x_i\n\\end{align}\nWhere $n$ is the total amount of points in the data set.\n\\subsection{Population vs Sample}\nThe \\textbf{population} is the full body of data points that exist for a given study. For instance if you wanted to measure the variation in height of humans, the population variance would necessarily require that you measure all humans for which this study pertains to. Obviously in real life, this is a tough thing to do, so most often a \\textbf{sample} is used. A sample is a subset of the full population.\n\nTODO Derive how you get different variances\n\n\\subsection{Variance}\nTODO\n\\subsection{Covariance}\nThe covariance between two variables tells us how closely they track with each other. The \\textbf{population covariance} is defined as \n\\begin{align}\n\\Cov[x,y] = \\frac{1}{n}\\sum_{i=1}^n (x_i-\\bar{x})(y_i-\\bar{y})\n\\end{align}\nWhereas the \\textbf{sample covariance} is defined as \n\\begin{align}\n\t\\Cov[x,y] = \\frac{1}{n-1}\\sum_{i=1}^n (x_i-\\bar{x})(y_i-\\bar{y})\n\\end{align}\nTODO: Difference between sample and population.\n\nIf the covariance is 0, both variables are independent. If the covariance is large and positive, a larger $x$ value suggests a larger $y$ value (and vice versa). If the coviarance is negative, a larger $x$ value suggests a smaller $y$ value (and vice versa).\n\n\n\\subsubsection{Covariance Matrix}\\label{covmat}\nWith many variables (say $n$ of them), it is often helpful to define the sample Covariance matrix which calculates the covariance between each of the variables $x_i$ with $i = 1,\\dots, n$\n\n\\begin{align}\n\\textbf{K}_{x_i,x_j} = \\begin{pmatrix} \n                             \\Cov[x_0,x_0]&\\Cov[x_1,x_0]&\\Cov[x_2,x_0]&\\cdots &\\Cov[x_n,x_0]\\\\\n                             \\Cov[x_0,x_1]&\\Cov[x_1,x_1]&\\Cov[x_2,x_1]&\\cdots &\\Cov[x_n,x_1]\\\\\n                             \\Cov[x_0,x_2]&\\Cov[x_1,x_2]&\\Cov[x_2,x_2]&\\cdots &\\Cov[x_n,x_2]\\\\\n                             \\vdots&\\vdots&\\vdots&\\ddots&\\vdots\\\\\n                             \\Cov[x_0,x_n]&\\Cov[x_1,x_n]&\\Cov[x_2,x_n]&\\cdots &\\Cov[x_n,x_n] \\end{pmatrix}\n\\end{align}\n\n\n\\label{ch:statistics}\n\n\\section{Markov Chains}\nTODO\n\n\\subsection{Gibbs Sampling}\nGibbs sampling is used to approximate a multivariate probability distribution when directly sampling it is difficult. \nTODO\n\n\\section{Probability}\nThe mathematics of probability translate chances into dice rolls. For a given event, a value $P\\in[0,1]$ is assigned to the fraction of times it is expected to happen. The theoretical underpinnings of probability have remained unresolved since it's birth, leaving two primary camps of practitioners; Bayesians and Frequentists.\nTODO Bayesian vs Frequentist\n\"In particle physics, with its strong tradition of frequentist coverage, prior pdfs are often chosen to provide intervals (in particular upper limits for Poisson means) with good frequentist coverage [4]. In such cases, our use of Bayesian computational machinery for interval estimation is not so much a change in paradigm as it is a technical device for frequentist inference.\" - Bob Cousins \\url{https://ep-news.web.cern.ch/node/3213}\n\\subsubsection{Bayesian Probability}\nTODO\n\\subsubsection{Frequentists Probability}\nTODO\n\n\n\n\\subsection{Random Variables}\nA random variable is one whose values have an associated probability distribution \\cite{grus}. Random variables can come in two different flavors: \\B{discrete} and \\B{continuous}. \n\nDiscrete random variables can only take a countable number of distinct values e.g. ($1,~2, ~5,\\ldots$) or (red, blue, green). These values get pulled from something called a \\B{probability mass function}.\n\nConversely, continuous random variables represent a continuous spectrum of values e.g. all the real numbers. These values get pulled from something called a \\B{probability density function}.\n\n\\subsection{Marginalizing A Variable}\nTODO\n\n\\subsection{Neyman Pearson Lemma}\nThe main idea is that you want to maximize your detection probability $P_D$ under then constraint that your Type I error (false alarm) probability $P_{FA}$ is equal to a set value $\\alpha$. This is done looking for a maximum with a Lagrange multiplier. TODO\n\n\\begin{equation}\n\t\\textrm{max}[P_D - \\gamma(P_{FA}-\\alpha)]\n\\end{equation}\n\nGiven two simple hypotheses $\\theta_0$ (the null hypothesis) and $\\theta$, (simple hypotheses specify uniquely the probability distributions), we pick \n\n\\subsection{Hoeffding's Inequality}\\label{hoeffding}\nGiven $X_1, X_2, \\ldots, X_n$ independent random variables each within $0 \\leq X_i \\leq 1$, Hoeffding's inequality states that \n\\begin{align}\n\tP(\\bar{X} - E[\\bar{X}] \\geq t) \\leq e^{-2nt^2}\n\\end{align}\nwith \n\\begin{align}\n\t\\bar{X} = \\frac{1}{n}\\Big(X_1+X_2+\\ldots+X_n\\Big)\n\\end{align}\nthis gives us an easily computable way to find edge's of cumulative distributions.\n \n\\subsection{Cross Entropy}\nTODO\nIf we are maximizing for probabilities, using cross-entropy as a loss function represents the negative log-likelihood of the observed data\\cite{grus}.\n\n\\subsection{Characteristic Function}\nThe characteristic function is the Fourier transform of a distributions PDF $p(x)$. Defined as \n\\begin{align}\n\\phi_x(k) = E[e^{ikx}] = \\int_{-\\infty}^\\infty e^{ikx}p(x)dx\n\\end{align}\nThis function has a one to one relationship with the PDF, and is useful in proving things. It turns out that when adding a whole bunch of random numbers $x_1, x_2, ..., x_n$, all pulled from different PDFs $p_1(x_1), p_2(x_2), ..., p_n(x_n)$\n\\begin{align}\ns = x_1 + x_2 + ... + x_n\n\\end{align}\nthe characteristic function has the property that\n\\begin{align}\n\\phi_s(k) =\\phi_1(k)\\phi_2(k)...\\phi_n(k)\n\\end{align}\n\n\n\\subsection{Central Limit Theorem}\nStates that if you have a bunch of random variables $x_1, x_2, ... x_n$, each coming from an arbitrary pdf with mean $\\mu_1, \\mu_2, ... \\mu_n$, and variance $\\sigma_1^2, \\sigma_2^2, ...\\sigma_n^2$, if you add them all up in the limit of large $n$, it should approach a Gaussian distribution with mean $\\mu = \\sum_i \\mu_i$ and variance $\\sigma^2 = \\sum_i\\sigma_i^2$\n\nTODO\n\nJeffery's prior allows two people to come up with an equal parameter(?) model that looks different, but have the statistics for the two come out the same, when they otherwise wouldn't (Jacobian, etc.)\n\n\\subsection{Laplace's Rule of Succession}\nConsider the problem of flipping a coin $N$ times and getting $A$ heads. If each flip has a probability $\\rho$ to come up heads, the probability for any amount of heads is given by the Binomial distribution\n\\begin{align}\np(A) = {N\\choose A}\\rho^A(1-\\rho)^{N-A}\n\\end{align}\nIf we want to figure out how fair the coin is, i.e. the value of $\\rho$, we know that the probability of a given $\\rho$ should be proportional to this function as we\n\\begin{align}\n\tp(\\rho) \\propto {N\\choose A}\\rho^A(1-\\rho)^{N-A}\n\\end{align}\nWe also know that $\\rho$ must be in $[0,1]$. Knowing that the sum of probabilities over $\\rho$ must equal 1, the normalization constant must be\n\\begin{align}\n\tp(\\rho) =\\ffrac{ {N\\choose A}\\rho^A(1-\\rho)^{N-A}}{\\int_0^1{N\\choose A}\\rho^A(1-\\rho)^{N-A} d\\rho}\n\\end{align}\nSince ${N\\choose A}$ is constant and common in both numerator and denominator, we have\n\\begin{align}\n\tp(\\rho) =\\ffrac{ \\rho^A(1-\\rho)^{N-A}}{\\int_0^1\\rho^A(1-\\rho)^{N-A} d\\rho}\n\\end{align}\nIt so happens the integral is Euler's beta function, which evaluates to \n\\begin{align}\n\t\\int_0^1\\rho^A(1-\\rho)^{N-A} d\\rho = \\frac{A!(N-A)!}{(N+1)!}\n\\end{align}\nThis then simplifies our expression with\n\\begin{align}\n\tp(\\rho) =(N+1){N\\choose A}\\rho^A(1-\\rho)^{N-A}\n\\end{align}\nThis then literally tells us what the chances are of a given $\\rho$ given any number of flips $N$ and heads $A$. The question answered by Laplace's rule of succession answers: If I flip a coin $N$ times with $A$ heads, what is the probability of getting heads on the next flip $N+1$?\n\nThis is the same thing as asking, what is $\\rho$, which is the probability of getting a heads on any single flip. Therefore, all we need to do is take the expectation value of $\\rho$\n\\begin{align}\n\t\\langle \\rho\\rangle &= \\int_0^1\\rho ~p(\\rho) d\\rho\\\\\n\t&= (N+1){N\\choose A}\\int_0^1 ~\\rho^{A+1}(1-\\rho)^{N-A} d\\rho\n\\end{align}\nUsing the same beta function relation (or alternatively using the chain rule) we get\n\\begin{align}\n\t\\langle \\rho\\rangle &= \\int_0^1\\rho ~p(\\rho) d\\rho\\\\\n\t&= (N+1)\\frac{N!}{A!(N-A)!}\\frac{(A+1)!(N-A)!}{(N+2)!}\n\\end{align}\nTherefore, the chance that we get a heads on the next flip, is given by\n\\begin{align}\n\t\\langle\\rho\\rangle = \\frac{A+1}{N+2}\n\\end{align}\n\n%\\subsection{Uncertainties?}\n%Study email from Jay \"CLCT output to Track Finder\" to understand why it makes sense to add errors in quadrature, and write it up here.\n\n\n\\subsection{Bayes Theorem}\nThe conditional probability, written as $P(A|B)$ is understood as the chance that $A$ happens, given that $B$ has already happened. The chance that both $A$ and $B$ happen $P(A \\cap B)$ is the same as the chance $B$ happens at all $P(B)$, multiplied by $P(A|B)$.\n\\begin{align}\nP(A\\cap B) = P(A|B)P(B)\n\\end{align}\nThis can of course be looked at the other way, with\n\\begin{align}\nP(A\\cap B) = P(B|A)P(A)\n\\end{align}\nTherefore\n\\begin{align}\nP(A|B) = \\frac{P(B|A)P(A)}{P(B)}\n\\end{align}\n\n\\section{Likelihood Function}\n\nThe likelihood function is an interpretation of the probability distribution which takes the observed values $\\textbf{x}$ as \\textit{fixed} and allows the parameters $\\boldsymbol{\\mu}$ to vary.\n\n\\begin{align}\n\tP(\\textbf{x}|\\boldsymbol{\\mu}) = \\mathcal{L}(\\boldsymbol{\\mu}|\\textbf{x})\n\\end{align}\n\n\\subsection{Maximum Likelihood Estimation}\nThe most foolproof means of solving an optimization problem is writing down the corresponding likelihood function, then solving for the parameters $\\boldsymbol{\\mu}$. If doing so analytically, this corresponds to solving the series of equations given by\n\\begin{align}\n\\frac{\\partial \\mathcal{L}}{\\partial \\boldsymbol{\\mu}} = 0\n\\end{align}\nIn general this usually isn't possible, so one resorts to other means such as gradient descent. When doing this optimization on a computer, typically one optimizes for\n\\begin{align}\n\t\\ln\\mathcal{L}\n\\end{align}\ninstead of $\\mathcal{L}$. This is kosher since $\\ln$ is a strictly increasing function, so maximizing it means maximizing its arguments \\cite{burkov}. There are also some nice properties since \n\\begin{align}\n-2\\ln\\mathcal{L} \\simeq \\chi^2\n\\end{align}\n\n% TODO Maximum Likelihood Estimation\n\nThis tells us that if the model had the parameter $\\mu_{ML}$ the observation we made would be the most likely, out of the space of all possible $\\mu$'s it could have been. To find the \\textbf{confidence interval}, we use\n\n\\begin{align}\n-2\\ln\\mathcal{L} \\simeq \\chi^2\n\\end{align}\nThis is because (TODO: Learn more about this) most things tend towards Gaussians in the limit of large numbers and in the product of many Likelihood functions one gets\n\\begin{align}\n\t-2\\ln\\prod_i\\mathcal{L}_i = -2\\ln\\prod_i e^{(x_i-\\mu)^2/2\\sigma^2} = \\sum_i\\frac{(x_i-\\mu)^2}{\\sigma^2} = \\chi^2\n\\end{align}\n(TODO, $i$'s are correct?). Now using Wilk's Theorem (TODO), one can look at the change in $\\chi^2$ as you change the value of $\\mu$. Once you increase $\\mu$ in one direction from $\\mu_{ML}$, the $\\chi^2$ will grow. $\\chi^2$ will of course also grow if you decrease it from $\\mu_{ML}$. You can quantify how much you can change $\\mu$ to some limit of $\\chi^2$ given by (SOME THEORY). Depending on what kind of confidence interval you are looking for, or the amount of parameters you still have, this change in $\\chi^2$ will be different. \n\nThis defines your confidence interval, which tells you, given whatever data you have, what the values of $\\mu$,  [$\\mu_1, \\mu_2$] would be such that what you saw was on the tail end of its distribution (e.g. outside of 95\\% of the entire distribution)\n\n\\subsection{Asimov Dataset}\nAn Asimov dataset is an artificial dataset such that when it is used to evaluate the estimators for all parameters in the context of maximum likelihood estimation, one obtains the (assumed) true parameter values. This is typically done to derive $\\sigma$ of the parameter of interest $\\mu$, which is then used in asymptotic formulae. Some notes on notation\n\\begin{itemize}\n\t\\item $\\hat{\\mu}$: Best estimate on the parameter of interest $\\mu$\n\t\\item $\\mu'$: Assumed true mean of the Gaussian used in Asymptotic formula approximations\n\\end{itemize}\nThis method is used to derive the approximate Gaussian width when calculating Asymptotic formulas for limits in particle physics \\cite{cowan}. It was named after author, Isaac Asimov, whose 1955 short story, Franchise, envisaged the 2008 US Presidential Election decided by one voter representative of the entire electorate.\n\n\n\n\\section{Hypothesis Testing}\n\n\\subsection{Confidence Intervals}\nTODO\nAlso add calculation of confidence intervals of fit parameters.\n\\url{https://online.stat.psu.edu/stat415/lesson/7/7.5}\nAdd confidence interval of a Gaussian\n\n\\subsection{P-Value}\nThe $p$-value is defined as the probability under the null hypothesis of obtaining a result equal to or more extreme than what was actually observed. The smaller the $p$-value, the more it tells investigators that the null hypothesis may not adequately explain the observation.\n\n\n\\subsection{A/B Testing}\nSee book \\cite{grus}\n\n\n\\subsection{F-Test}\nTODO\n\n\\section{Kalman Filter}\nThe Kalman filter\\cite{fruwirth} uses a series of measurements taken in a time series to make an estimate of the underlying parameters. It works as an iterative $\\chi^2$ method, and is useful when there is noise introduced between measurements.\n\nLet us assume the state vector of interest is $\\textbf{x}$. If we assume the evolution of the state vector is linear, we have\n\\begin{align}\n    \\textbf{x}_k = \\textbf{F}_{k-1}\\textbf{x}_{k-1} + w_{k-1}\n\\end{align}\nWhere $k$ is the current state, $w$ is random noise that is introduced, and $\\textbf{F}$ is how the state vector propagates itself (here it is assumed to be linear). Measurements $\\textbf{m}$ in each detector $k$ can be written as\n\\begin{align}\n    \\textbf{m}_k = \\textbf{H}_k\\textbf{x}_k + \\epsilon_k\n\\end{align}\nWe assume both $w_k$ and $\\epsilon_k$ are independent and have a mean of zero. The Kalman algorithm performs three different analyses:\n\\begin{enumerate}\n    \\item \\textbf{Filtering}: estimation of present state vector based off of all previous measurements.\n    \\item \\textbf{Prediction}: estimation of future state vector.\n    \\item \\textbf{Smoothing}: estimation of the state vector at some time in the past using all information known in the present.\n\\end{enumerate}\nThe Kalman filter minimizes the mean squared error and is in that sense the optimum solution to these problems. We can denote our estimate $\\hat{\\textbf{x}}_k^i$ for each of these three cases:\n\\begin{itemize}\n    \\item $i < k$: prediction, since we are using fewer points than the state we are looking at $k$\n    \\item $i=k$: filtering, since we are using all previous states and the measurement at $k$ itself\n    \\item $i > k$: smoothing, since we already had a measurement at this point, but used additional later values to get a better estimate\n\\end{itemize}\nOne can then define the covariance matrix as the difference between the ...\n\n\n\n\\section{Bootstrapping}\nTODO\n\n\n", "meta": {"hexsha": "9020cc24b9f435a959709afa201262ab760fe38a", "size": 15791, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mathematics/statistics.tex", "max_stars_repo_name": "williamnash/notes", "max_stars_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mathematics/statistics.tex", "max_issues_repo_name": "williamnash/notes", "max_issues_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-08-23T23:01:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-16T23:17:43.000Z", "max_forks_repo_path": "mathematics/statistics.tex", "max_forks_repo_name": "williamnash/notes", "max_forks_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.4070175439, "max_line_length": 537, "alphanum_fraction": 0.7376986891, "num_tokens": 4449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198946, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7102747241798223}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath} \n\n\\title{Eigenvalues and Eigenvectors}\n\\begin{document}\n  \\pagenumbering{gobble}\n  \\maketitle\n  \\newpage\n  \\pagenumbering{arabic}\n\n\\section*{The power method}\n\nLet us have a square matrix A. It's size is $nxn$. \\\\\nIt has a number of independet real eigenvalues: $\\lambda_1, \\lambda_2, \\dots, \\lambda_n$. \\\\\nEigenvectors corresponding to the eigenvalues are: $v_1, v_2, \\dots, v_n$. \\\\\nOne condition: $|\\lambda_1| > |\\lambda_2|$.\n\nThe eigenvectors are independent, which means that they are as well basis vectors. This implies that any vector in the same space can be written as a linear combination of the eigenvectors.\n\n$$x_0 = c_1v_1+c_2v_2+\\dots+c_nv_n$$\n\nwhere $c_1\\ne0$\n\nAfter multypling both sides by matrix A:\n\n$$Ax_0 = c_1Av_1+c_2Av_2+\\dots+c_nAv_n$$\n\nFrom the defintion $Av_i = \\lambda{v_i}$, so:\n\n$$Ax_0 = c_1\\lambda_1v_1+c_2\\lambda_2v_2+\\dots+c_n\\lambda_nv_n$$\n\n$$Ax_0 = c_1\\lambda_1[v_1+\\frac{c_2}{c_1}\\frac{\\lambda_2}{\\lambda_1}v_2+\\dots+\\frac{c_n}{c_1}\\frac{\\lambda_n}{\\lambda_1}v_n]= c_1\\lambda_1x_1$$\n\nThis was the first iteration. To begin the second iteration, we multiply $A$ by $x_1$:\n\n$$Ax_1 = \\lambda_1{v_1}+\\frac{c_2}{c_1}\\frac{\\lambda_2^2}{\\lambda_1}v_2+\\dots+\\frac{c_n}{c_1}\\frac{\\lambda_n^2}{\\lambda_1}v_n$$\n\n$$Ax_1 = \\lambda_1[v_1+\\frac{c_2}{c_1}\\frac{\\lambda_2^2}{\\lambda_1^2}v_2+\\dots+\\frac{c_n}{c_1}\\frac{\\lambda_n^2}{\\lambda_1^2}v_n] = \\lambda_1x_2$$\n\nAfter k iterations we have:\n\n$$Ax_{k-1} = \\lambda_1[v_1+\\frac{c_2}{c_1}\\frac{\\lambda_2^k}{\\lambda_1^k}v_2+\\dots+\\frac{c_n}{c_1}\\frac{\\lambda_n^k}{\\lambda_1^k}v_n] = \\lambda_1x_k$$\n\n\nFor large k, $(\\frac{\\lambda_n}{\\lambda_1})^{k} = 0$\n\nWe have now the largest eigenvalue and its corresponding eigenvector:\n\n$$Ax_{k-1} = {\\lambda_1}v_1$$\n\n\\section*{The inverse power method}\nThe reciprocals of the eigenvalues of A are the eigenvalues of it's inverse matrix  $A^{-1}$. \\\\\nThis will help us to find the smallest eigenvalue of A. \\\\\nInstead of multiplying A as in power method, we multiply it's inverse to find it's largest value.\n\n\\section*{QR method}\n\nThe QR method is used to find all eigenvalues of a matrix, without finding the eigenvectors at the same time.\\\\\n\n1. The eigenvalues and corresponding eigenvectors of similar matrices are the same.\n\nTwo square matrices A and B are similar if:\n\n$$A = C^{-1}BC$$\n\nwhere C is an invertible matrix.\\\\\n\n2. You can present any matrix as a product of two other matrices. \n\n\\begin{align}\nA &= QR\n\\end{align}\n\nHere we want to get an orthogonal matrix Q and an upper triangular matrix R.\\\\\n\nA matrix M is an orthogonal matrix if: $M^{-1} = M^T$. Thus $M^*M = I$. \\\\\n\nLet us rewrite equation (1):\n\n$$RQ = Q^*AQ$$\n\n$$RQ = Q^{-1}AQ$$ \n\nRQ has the same eigenvalues as A.\\\\\n\nCompute a QR factorization and reverse the order of multiplcation of Q and R.\n\n$A_0 = A$\n\n$$A_k = R_kQ_k = Q^{-1}_kA_kQ_k$$\n\n$$A_{k-1}=Q_kR_k$$\n\nWe will finally converge to an upper triangular matrix form as the iteration progresses:\n\n\\begin{align*}\n\\begin{split} A_k = R_kQ_k = \\begin{bmatrix}\n\\lambda_1 & X & \\dots & X\\\\\n0 & \\lambda_2 & \\dots & X\\\\\n& &\\dots &\\\\\n0 & 0 & \\dots & \\lambda_n\\\\\n\\end{bmatrix}\\end{split}\n\\end{align*}\n\n\\end{document}", "meta": {"hexsha": "44eb48589c7655126d8c1a56d9db581423dd7f92", "size": 3205, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/eigenvalues_and_eigenvectors.tex", "max_stars_repo_name": "djeada/Numerical-Methodes", "max_stars_repo_head_hexsha": "45a5288f4719568a62a82374efbb3fc06d33ec46", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slides/eigenvalues_and_eigenvectors.tex", "max_issues_repo_name": "djeada/Numerical-Methodes", "max_issues_repo_head_hexsha": "45a5288f4719568a62a82374efbb3fc06d33ec46", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slides/eigenvalues_and_eigenvectors.tex", "max_forks_repo_name": "djeada/Numerical-Methodes", "max_forks_repo_head_hexsha": "45a5288f4719568a62a82374efbb3fc06d33ec46", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.2358490566, "max_line_length": 189, "alphanum_fraction": 0.7054602184, "num_tokens": 1151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7102747174148744}}
{"text": "\\section*{Classification}\n\\subsection*{0/1 loss - \"NP-Hard\"}\n0/1 loss is not convex and not differentiable.\\\\\n$l_{0/1} (w;y_i,x_i) =\n\\begin{cases}\n    1 \\text{ , if } y_i \\neq sign(w^Tx_i)\\\\\n\t\t0 \\text{ , otherwise} \n\\end{cases}$\n\n\\subsection*{Perceptron loss}\nPerceptron loss is convex and not differentiable, but gradient is informative.\\\\\n$l_{P} (w;y_i,x_i) = max\\{0, -y_i w^T x_i \\}$\\\\\n$\\nabla_w l_p(w;y_i,x_i) = \\begin{cases}\n    0 &\\text{ , if } -y_i w^T x_i \\leq 0\\\\\n    -y_i x_i &\\text{ , if } -y_i w^T x_i > 0\n\\end{cases}\\\\\nw^* = \\underset{w}{\\operatorname{argmin}} \\sum_{i=1}^n l_p (w;y_i,x_i)$\n\n\\subsection*{Stochastic Gradient Descent (SGD)}\n1. Start at an arbitrary $w_0 \\in \\mathbb{R}^d$\\\\\n2. For $t = 1, 2,  ...$ do: \\\\\n\tPick data point $(x',y') \\in_{u.a.r.} D$\\\\\n\t$w_{t+1} = w_t - \\eta_t \\nabla_w l(w_t;x',y')$\\\\\nPerceptron Algo: SGD with Perceptron loss\n\n%\\subsection*{Perceptron Algorithm}\n%Stoch. Gradient Descent with Perceptron loss\\\\\n%\\emph{Theorem:} If $D$ is linearly separable $\\Rightarrow$ Perceptron will obtain a linear separator.\n\n%\\subsection*{Hinge loss}\n%Loss for Support Vector Machine.\\\\\n%$l_H(w;x,y) = max \\{0,1-y w^T x\\}$\n\n\\subsection*{Support Vector Machine - \"Max Margin\"}\nHinge loss: $l_H(w;x,y) = max \\{0,1-y w^T x\\}$\\\\\nGoal: max. the margin around the separator.\\\\\n$w^* = \\underset{w}{\\operatorname{argmin}} \\sum_{i=1}^n  max \\{0,1-y_i w^T x_i\\} + \\lambda ||w||_2^2\\\\\ng_i(w) = max \\{0,1-y_i w^T x_i\\} + \\lambda ||w||_2^2\\\\\n\\nabla_w g_i(w) = \\begin{cases}\n    -y_i x_i + 2\\lambda w &\\text{ , if $y_i w^T x_i<1$}\\\\\n\t\t2\\lambda w &\\text{ , if $y_i w^T x_i \\geq 1$}\n\\end{cases}$\n\n\\subsection*{L1-SVM}\n$\\underset{w}{\\operatorname{min}} \\lambda ||w||_1 + \\sum_{i=1}^n max(0,1-y_i w^T x_i)$ \n$\\rightarrow$ enourages coefficients to be zero (only linear models).\n\n%\\subsection*{Matrix-Vector Gradient}\n%multiply transposed matrix to the same side as its occurance w.r.t. derivate variable: $\\beta \\in \\mathbb{R}^d$\n%$\\nabla_\\beta ( ||y-X\\beta||_2^2 + \\lambda ||\\beta||_2^2 ) = 2X^T (y-X\\beta) + 2\\lambda \\beta$\\\\\n", "meta": {"hexsha": "159e2d05852e69c21c5f21f509d69b9c10065278", "size": 2044, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/Classification.tex", "max_stars_repo_name": "meck93/intro_ml_ethz", "max_stars_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-04-24T14:58:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-19T14:02:08.000Z", "max_issues_repo_path": "source/Classification.tex", "max_issues_repo_name": "meck93/intro_ml_ethz", "max_issues_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/Classification.tex", "max_forks_repo_name": "meck93/intro_ml_ethz", "max_forks_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.0784313725, "max_line_length": 112, "alphanum_fraction": 0.6360078278, "num_tokens": 846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897442783526, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.7102162722595994}}
{"text": "\n\\subsection{Quotient groups}\n\nWe have a group \\(G\\) and a normal subgroup \\(N\\).\n\nWe define a quotient group from this as \\(G/N\\). This is the set of cosets from \\(N\\).\n\n", "meta": {"hexsha": "f522007096d27e0a349ec5c8afbb7de476e34c98", "size": 171, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/05-02-quotient.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/groups/05-02-quotient.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/groups/05-02-quotient.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.375, "max_line_length": 86, "alphanum_fraction": 0.6725146199, "num_tokens": 49, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029486, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.7102130521699576}}
{"text": "\\chapter*{Introduction}\nWhen you want to develop a selfdriving car, you have to plan which path \nit should take. A reasonable choice for the representation of\npaths are cubic splines. You also have to be able to calculate\nhow to steer to get or to remain on a path. A way to do this\nis by applying the \\href{https://en.wikipedia.org/wiki/PID_algorithm}{PID algorithm}.\nThis algorithm needs to know the signed current error. So you need to \nbe able to get the minimal distance of a point (the position of the car)\nto a cubic spline (the prefered path)\ncombined with sign (which represents the steering direction).\nAs one steering direction might be prefered, it is not only necessary to\nget the minimal absolute distance, but might also help to get all points\non the spline with minimal distance.\n\nIn this paper, I want to discuss how to find all points on a cubic \nfunction with minimal distance to a given point.\nAs other representations of paths might be easier to understand and\nto implement, I will also cover the problem of finding the minimal\ndistance of a point to a polynomial of degree 0, 1 and 2.\n\nWhile I analyzed this problem, I've got interested in variations\nof the underlying PID-related problem. So I will try to give\nrobust and easy-to-implement algorithms to calculate the distance\nof a point to a (piecewise or global) defined polynomial function\nof degree $\\leq 3$.\n\nWhen you're able to calculate the distance to a polynomial which is\ndefined on a closed invervall, you can calculate the distance from\na point to a spline by calculating the distance to the pieces of the\nspline.\n", "meta": {"hexsha": "1c860856130d02ca944f044fdaa44ff5a3bf6f57", "size": 1599, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/math-minimal-distance-to-cubic-function/introduction.tex", "max_stars_repo_name": "keithmannock/LaTeX-examples", "max_stars_repo_head_hexsha": "6829f6cf9710b314a4bf0b64abdae5bcf6997fd0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-11-02T10:09:12.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-24T22:16:18.000Z", "max_issues_repo_path": "documents/math-minimal-distance-to-cubic-function/introduction.tex", "max_issues_repo_name": "everbot/LaTeX-examples", "max_issues_repo_head_hexsha": "9558d8b3c19776cb068b9753dcd3f88645dd7134", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "documents/math-minimal-distance-to-cubic-function/introduction.tex", "max_forks_repo_name": "everbot/LaTeX-examples", "max_forks_repo_head_hexsha": "9558d8b3c19776cb068b9753dcd3f88645dd7134", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.5806451613, "max_line_length": 85, "alphanum_fraction": 0.7917448405, "num_tokens": 361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7101369225334664}}
{"text": "% !TEX root = ../main.tex\n\n\\section{Spectrum}\n\n\\subsection{Eigenvalues and eigenvectors}\n\n$$\nAx = \\lambda x\n$$\n\n\\begin{itemize}\n  \\item An eigenvector $x$ is a non-zero vector belonging to eigenvalue $\\lambda$\n  \\item An $n \\times n$ matrix $A$ has $n$ eigenvalues (possibly not all distinct)\n  \\item The eigenvalue problem for the transposed matrix leads us to talk about \n  right-eigenvectors ($A$ and $A^T$ have the same eigenvalues, but not necessarily the same\n  eigenvectors) \n  \\item The eigenvectors are linearly independent\n  \\item Mostly, we normalized eigenvectors such that $x^Tx = 1$\n  \\item If $P^{-1}$ exists, then $PAP^{-1}$ has the same eigenvalues as $A$, but each \n  eigenvector is $y = Px$, where $x$ is an eigenvector of $A$\n\\end{itemize}\n\n\\begin{align*}\n  A(rx) = \\lambda (rx) \\quad r \\ne 1\n\\end{align*}\n\n\\begin{gather*}\n  A \n  \\begin{bmatrix}\n    x_1 & x_2 & \\cdots & x_N\n  \\end{bmatrix} =\n  \\begin{bmatrix}\n    x_1 & x_2 & \\cdots & x_N\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    \\lambda_1 & & & \\\\\n    & \\lambda_2 & & \\\\\n    & & \\ddots & \\\\\n    & & & \\lambda_N\n  \\end{bmatrix} \\\\\n  AX = X\\Lambda \\implies A = X\\Lambda X^{-1} \\\\\n  (A - \\lambda I)x = 0 \\implies \\det(A - \\lambda I) = 0\n\\end{gather*}\n\n\\subsubsection{Basic theorem for symmetric matrices}\n\\textbf{Any real symmetric matrix $S$} can be written as $S = X \\Lambda X^T$,\nwhere $X$ is the orthogonal matrix with real eigenvectors in the columns and \n$\\Lambda = diag(\\lambda_1, ..., \\lambda_N)$, where $\\lambda_j$ is the $j$-th real eigenvalue.\n\nThe real eigenvalues can be ordered as\n\n\\begin{gather*}\n  \\lambda_N \\le \\lambda_{N-1} \\le \\cdots \\lambda_2 \\le \\lambda_1\n\\end{gather*}\n\nIf symmetric: $A = A^T = X \\Lambda X^T = \\sum_{k=1}^{N} \\lambda_k x_k x^T_k$\n\n\\subsubsection{The orthogonal matrix X of a symmetric matrix A}\n\n$$\nA^T = \\sum_{k=1}^N \\lambda_k^m x_k x^T_k\n$$\n\nOrthogonality of eigenvectors: $x_k^T x_m = \\delta_{km} \\implies X^T X = I \\implies X^{-1} = X^T$\n\nA matrix and its inverse commute: $X^{-1}X = X X^{-1} \\implies X^TX = XX^T = I$ \\textbf{Double\northogonality}. Both column vectors (=eigenvectors of A) and row vectors of $X$ are orthogonal.\n\n\\subsubsection{Gerschgorin's theorem}\n\nIt explains why we use spectral radious..\n\n\\begin{quotation}\n  Each eigenvalue of an $n\\times n$ matrix $A$ lies in at least one of the circular discs\n  with a center $a_{jj}$ and radii $R_j = \\sum_{k=1;k \\ne j}^n |a_{jk}|$\n\\end{quotation}\n\n\\textbf{Consequence for Adjacency matrix $A$: } $|\\lambda| \\le \\sum_{k=1}^n a_{rk} = d_r$\n$$\n\\lambda_1 \\le d_{max}\n$$\n\nThe largest eigenvalue is always smaller thant the maximum degree\n\n\\textbf{Properties}:\n\\begin{itemize}\n  \\item Spectrum of $A$:\n  \\begin{itemize}\n    \\item All eigenvalues lie in the interval $(-d_{max}, d_{max}]$\n    \\item $\\sum_{j=1}^N \\lambda_j = 0 \\qquad \\sum_{j=1}^N \\lambda_j^2 = 2L \\qquad\n    \\sum_{j=1}^N \\lambda_j^k = Trace(A^k)$\n    \\item Perron-Frobenius Theorem: $\\lambda_1$ non-negative and components eigenvector $x_1$ are\n    non-negative. (irreducible = connected: positive)\n  \\end{itemize}\n  \\item Spectrum of $Q = \\Delta - A = BB^T$:\n  \\begin{itemize}\n    \\item Any eigenvalue $\\mu_k$ is non-negative and the smallest $\\mu_N = 0$\n    \\item Complexity (number of spanning trees is) $\\epsilon(G) = \\frac{1}{N} \\prod_{k=1}^{N-1} \\mu_k$\n    \\item The second smallest eigenvalue of the Laplacian $Q$, called \\textbf{the algebraic \n    connectivity} $a(G) = \\mu_{N-1}$, quantifies how strongly a graph is \n  \\end{itemize}\n\\end{itemize}\n\n\\subsection{Largest eigenvalue of a symmetric matrix} \n\nIf $Ax = \\lambda x$ then $A^k x = \\lambda^k x$ for non-negative integers $k$.\n\n\\textbf{Power method} (eigenvector): \n$$\nA^k w = \\alpha_1 \\lambda_1^k x_1 \\left(1 + \\left(\\left|\\frac{\\lambda_2}{\\lambda_1}\n\\right|^k\\right)\\right)\n$$\n\n\\textbf{Gerschgorin's theorem}: $\\lambda_1 \\le d_{max}$\n\n\\textbf{Rayleigh's principle}: $\\lambda_1 \\ge \\frac{w^T Aw}{w^Tw}$ with equality only if $w = x_1$\n\n\\subsubsection{Spectral radius adjacency matrix}\nRayleigh principle: $\\lambda_1 \\ge \\frac{w^T Aw}{w^TW}$ with equality only if $w = x_1$\n\nChoose $w = u$, then $u^Tu = N$ and $u^TAu = 2L$\n\nHence:\n$$\nd_{max} \\ge \\lambda_1 (A) \\ge \\frac{2L}{N} = E[D]\n$$\n\nEquality holds if $u$ is an eigenvector of $A$. In general, $A u = d$ if $d = r u$, then \n$u$ is an eigenvector. \n\nThe eigenvalue equation $A x = \\lambda x$ implies that $A^m x = \\lambda^m x$\n\nRayleigh principle\n\nChoose $w = u$ and $m = 2$ then $u^Tu = N$ and \n$u^T A^2 u= (Au)^T (Au) = d^Td = \\sum_{j = 1}^N d^2_j$\n\n$$\n\\lambda_1 \\ge E[D]\\sqrt{1 + \\frac{Var[D]}{(E[D])^2}} \\ge E[D]\n$$\n\nTighter bound thant the previous one\n\n\\subsubsection{Spectral radius and subgraph structure}\nLet's have a graph $G$ that has two subgraphs $G_1$ and $G_2$\n\n$$\nA = \n\\begin{bmatrix}\n  A_1 & C \\\\\n  C^T & A_2\n\\end{bmatrix}\n\\implies \\lambda_1(G) \\ge \\lambda_1(G_1)\n$$\n\n\\subsection{Graph metric: Eigenvector centrality}\n\n\\begin{itemize}\n  \\item The $i$-th component $(x_j)_i$ of the eigenvector $x_j$ belonging to the $j$-th \n  largest eigenvalue $\\lambda_j$ of the adjacency matrix $A$ reflects a property of node \n  $i$ in the graph at ``eigenfrequency'' $\\lambda_j$\n  \\begin{itemize}\n    \\item Hence $(x_j)_i^2$ is non-zero and can be interpreted as a centrality metrics for node $i$\n  \\end{itemize}\n\\end{itemize}\n\n\n\n", "meta": {"hexsha": "4652379d2c6e5b7b729678f6f2a56b6b5e6ce7eb", "size": 5285, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/Networking/lectures/lecture_03.tex", "max_stars_repo_name": "jmigual/APATeoria", "max_stars_repo_head_hexsha": "acea91e3d339165855742dd5c5d6961158d5c391", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Notes/Networking/lectures/lecture_03.tex", "max_issues_repo_name": "jmigual/APATeoria", "max_issues_repo_head_hexsha": "acea91e3d339165855742dd5c5d6961158d5c391", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-08-05T10:35:07.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-05T10:35:08.000Z", "max_forks_repo_path": "Notes/Networking/lectures/lecture_03.tex", "max_forks_repo_name": "jmigual/APATeoria", "max_forks_repo_head_hexsha": "acea91e3d339165855742dd5c5d6961158d5c391", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-10-10T08:40:56.000Z", "max_forks_repo_forks_event_max_datetime": "2016-10-14T12:10:40.000Z", "avg_line_length": 31.2721893491, "max_line_length": 102, "alphanum_fraction": 0.6631977294, "num_tokens": 1903, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.7101369144422363}}
{"text": "\\documentclass{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\n% Main maths packages\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{mathrsfs}\n\n% Declare a differential command in order to not display the \"d\" in italic\n\\newcommand*{\\dd}[1][x]{\\,\\mathrm{d}#1}\n\n\\begin{document}\n\n\\section*{Integrals}\n\n\\subsection*{Simple integrals}\n\n\\[\\int x^2 \\dd\\]\n\n% The bounds are written at the right of the integral\n\\[\\int_{0}^{\\infty} x^2 \\dd\\]\n\n% The bounds are written at the top and bottom of the integral by specifying \\limits.\n%Refers styling.tex for more information about the command \\limits.\n\\[\\int\\limits_{0}^{\\infty} x^2 \\dd\\]\n\n\\[\\oint x^2 \\dd\\]\n\n\\subsection*{Double integrals}\n\n\\[\\iint x^2 \\dd \\]\n\n\\[\\int\\int x^2 \\dd\\]\n\n\\[\\int_{0}^{4}\\int_{1}^{3} x^2 \\dd\\]\n\n\\subsection*{Triple integrals}\n\n\\[\\iiint x^2 \\dd\\]\n\n\\[\\int_{x=0}^{x=5}\\int_{y=0}^{y=4}\\int_{z=1}^{z=3} x^2+y-z \\dd\\]\n\n\\[\\int\\limits_{x=0}^{x=5}\\int\\limits_{y=0}^{y=4}\\int\\limits_{z=1}^{z=3} x^2+y-z \\dd\\]\n\n\\end{document}", "meta": {"hexsha": "bf625a6d3e66ca6225281ee2a967e2751f3f6a63", "size": 999, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "compendium/mathematics/integrals.tex", "max_stars_repo_name": "ZenLulz/LatexCompendium", "max_stars_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-07-30T21:43:55.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-23T20:16:19.000Z", "max_issues_repo_path": "compendium/mathematics/integrals.tex", "max_issues_repo_name": "ZenLulz/LatexCompendium", "max_issues_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "compendium/mathematics/integrals.tex", "max_forks_repo_name": "ZenLulz/LatexCompendium", "max_forks_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.2553191489, "max_line_length": 85, "alphanum_fraction": 0.6596596597, "num_tokens": 386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.710119223831704}}
{"text": "\n\\subsection{Exponential discounting}\n\n\\subsubsection{Introduction}\n\nWe have:\n\n\\(U_T=\\sum_[t=T]^{\\infty }d_tU(x_t)\\)\n\n\\subsubsection{Exponential discounting}\n\n\\(d_t=(1+\\delta )^t\\)\n\n\\(U_T=\\sum_[t=T]^{\\infty }(1+\\delta )^tU(x_t)\\)\n\n\\(\\delta \\) is the discount rate.\n\n", "meta": {"hexsha": "52d9468a7f4fc014450a8c58d2adfd50bc1f69bb", "size": 266, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/intertemporal/02-01-exponential.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/ai/intertemporal/02-01-exponential.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/ai/intertemporal/02-01-exponential.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.7777777778, "max_line_length": 47, "alphanum_fraction": 0.6616541353, "num_tokens": 93, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7100371839660943}}
{"text": "\\subsection{Exponential separation of QMDD from ADD}\n\nAlgebraic Decision Diagrams (\\textsf{ADD}) are a precursor to \\textsf{QMDD}s.\nThe \\textsf{QMDD} data structure groups together nodes representing subfunctions which differ only by a multiplicative constant.\nBy labelling the edges with appropriate weights, no information about the state is lost.\nIn this Section, we show that this leads to an exponential decrease in the size of the diagram.\nPut another way, we have $\\textsf{ADD}\\subsetneq \\textsf{QMDD}$.\nIn the literature, \\textsf{ADD} is sometimes called \\textsf{QuiDD}.\n\n\\begin{theorem}\n\tThere is an infinite family of quantum states $\\{\\ket{\\phi_n}_n\\}_{n}$ such that every reduced, ordered \\textsf{ADD} needs $\\Theta(2^n)$ nodes to store $\\ket{\\phi_n}$, but every \\textsf{QMDD} needs only $\\Theta(n)$ nodes.\n\\end{theorem}\n\\begin{proof}\n\tThe state is the Fourier-transformed state\n\t\\begin{align}\n\t\t\\ket{\\phi_n}=(\\ket{0}+e^{i\\pi})\\otimes (\\ket{0}+e^{i\\pi2^{-1}})\\otimes \\cdots \\otimes (\\ket{0}+e^{i\\pi2^{-n+1}})\n\t\\end{align}\n\tSince the state is a product state, its QMDD only has $n$ nodes, not counting the \\textsf{leaf} node.\n\t\n\tHowever, the amplitudes of each basis vector is different, so the \\textsf{ADD} has an exponential number of leaves, each containing a different amplitude. Namely, the amplitude in $\\ket{\\phi}_n$ of basis vector $\\ket{x}_n$ is $\\frac{1}{\\sqrt{2^n}}e^{i\\pi x2^{-n}}$.\n\\end{proof}", "meta": {"hexsha": "6c227c712a2ac7843a3c633199ba35eb05feb55d", "size": 1417, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Src/CS/sections/ADD_lower_bound.tex", "max_stars_repo_name": "Katafotic/latex_parsing", "max_stars_repo_head_hexsha": "f00a9547b2034f4592e732a382cdbd34e11e13db", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Src/CS/sections/ADD_lower_bound.tex", "max_issues_repo_name": "Katafotic/latex_parsing", "max_issues_repo_head_hexsha": "f00a9547b2034f4592e732a382cdbd34e11e13db", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Src/CS/sections/ADD_lower_bound.tex", "max_forks_repo_name": "Katafotic/latex_parsing", "max_forks_repo_head_hexsha": "f00a9547b2034f4592e732a382cdbd34e11e13db", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.4761904762, "max_line_length": 266, "alphanum_fraction": 0.7332392378, "num_tokens": 429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392786908831, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.710037179429782}}
{"text": "\\section{Probabilistic Information Retrieval}\nThe complexity of text analysis is such that we can't have \na notion of correctness of an answer to a query, we therefore switch\nidea and change \\emph{true} to \\emph{probable}.\n\n\\subsection{Review of probability theory}\n\n\\paragraph{Random variable}\nA variable $A$ represents an events, so a subset of the space of possible\noutcomes. Another representation of $A$ is through a random variable, \nthat maps outcomes to real numbers.\n\n\\paragraph{Joint and conditional probabilities}\nWe denote $P(A|B)$ the probability of $A$ occurring given the occurrence of $B$.\n\n\\paragraph{Chain rule}\nThe following twos hold\n$$P(A,B) = P(A \\cap B) = P(A|B)P(B) = P(B|A)P(A)$$\n$$P(\\neg A, B) = P(\\neg A|B)P(\\neg A)$$\n\n\\paragraph{Partition rule}\nIf an event $B$ can be divided into an exhaustive set of disjoint sub-cases, \nthe probability of $B$ is the sum of the sub-cases\n$$P(B) = P(A,B) + P(\\neg A, B)$$\n\n\\paragraph{Bayes rule} The following rule holds\n$$P(A|B) = \\frac{P(B|A)P(A)}{P(B)}$$\n\nThis rule is a powerful tool to invert the conditional probability. \nThe first step is to estimate the likelihood of the event $A$, thus $P(A)$, \nthen we can derive a posterior probability $P(A|B)$ after having seen the \nevent $B$, based on the likelihood of $B$ occurring when $A$ does or not hold.\n\nThe left member of the equation $P(A|B)$ is what we are trying to estimate, \nthis could be for instance \\emph{probability of a document to be relevant \ngiven that it contains a word X}.\n\n$P(B|A)$ is on the other end the probability of observing the new evidence \ngiven the initial hypothesis. This could mean finding the \\emph{probability \nof observing the word X given that a document is relevant}. \n\n$P(A)$ is called the prior. For instance \\emph{probability of any document to \nbe relevant}.\n\n$P(B)$ is the marginal likelihood, for instance \\emph{probability of observing \nthe word X in any document}.\n\n\\paragraph{Odds of an event}\nIt is often useful to talk about the odds of an event \n$$O(A) = \\frac{P(A)}{P(\\neg A)} = \\frac{P(A)}{1 - P(A)}$$\n\n\n\n\\subsection{Binary indipendence model}\n\\label{binary-ind}\n\nIn information retrieval we represent the relevant of a document \ngiven an information need as a random variable $R$, Given a document $d$\nand a query $q$ we want to estimate the probability $$P(R = 1 |q, d)$$\n\nGiven a dictionary of terms $T = \\left\\langle t_1, \\dots, t_n \\right\\rangle $ \nwe model each document as a binary vector $\\vec{x} = (x_1, \\dots, x_n)$\nwhere $x_i$ is 1 if the $i$th term is in the document.\n\nThe goal is to calculate \n$$O(R=1 | q, \\vec{x}) = \\frac{P(R=1|q, \\vec{x})}{P(R=0|q, \\vec{x})}$$\n\n\\paragraph{Simplifying the goal function}\nApplying the Bayes rule leads to\n\\begin{equation}\n    \\begin{aligned}\n        O(R=1 | q, \\vec{x}) &= \\frac{P(R=1|q, \\vec{x})}{P(R=0|q, \\vec{x})}\n        = \\frac{\\frac{P(\\vec{x}|R=1,q)P(R=1|q)}{P(q, \\vec{x})}}{\\frac{P(\\vec{x}|R=0,q)P(R=0|q)}{P(q, \\vec{x})}}\\\\\n        &= \\frac{P(\\vec{x}| R = 1, q)}{P(\\vec{x}| R = 0, q)}\\cdot\\frac{P(R=1|q)}{P(R=0|q)}\n    \\end{aligned}\n\\end{equation}\n\nThe left part of the result represent the odds of having that document \ngiven that it is relevant and given that query. On the right part we \nhave the probability of the query producing relevant documents or not.\n\nAssuming that the terms are independent, note that this is a strong assumptions, \nwe can write\n$$O(R=1| q, \\vec{x}) = \\frac{P(R=1|q)}{P(R=0|q)} \\prod_{i=1}^{n} \n\\frac{P(x_i|R=1, q)}{P(x_i|R=0, q)}$$ \nThis product can be split according to the presence of terms in the document\n$$O(R=1| q, \\vec{x}) = \\frac{P(R=1|q)}{P(R=0|q)} \\prod_{i=1}^{n} \n\\frac{P(x_i = 1|R=1, q)}{P(x_i = 1|R=0, q)} \\prod_{i=1}^{n} \n\\frac{P(x_i = 0|R=1, q)}{P(x_i = 0|R=0, q)}$$ \n\nTo simplify the formula we introduce this values\n$$p_i = P(x_i = 1|R=1, q), \\;\\; q_i = P(x_i = 1|R=0, q)$$\n\\begin{center}\n    \\begin{tabular}{c | c |c | c}\n        & Document & $R=1$ & $R=0$\\\\\n        \\hline\n        We observe the term & $x_i = 1$ & $p_i$ & $q_i$\\\\\n        \\hline\n        We do not observe the term & $x_i = 0$ & $1- p_i$ & $1- q_i$\n    \\end{tabular}\n\\end{center}\nThus the previous equation becomes, where the first product iterates\nover the words that appear in the document and the query, \nand the second product goes for words that do not appear in the document, \nbut do on the queries. \n$$O(R=1| q, \\vec{x}) = \\frac{P(R=1|q)}{P(R=0|q)} \\prod_{x=1, q=1} \n\\frac{p_i}{q_i} \\prod_{x=0, q=1} \n\\frac{1- p_i}{1- q_i}$$ \nThis assumes that $p_i = q_i$ for words that \ndon't appear in a query, the assumption is motivated by the fact that a document\nis relevant or not given a query, not by itself.\n\nWe now extend the right product to cover all the query terms, \nformally \n$$O(R=1| q, \\vec{x}) = \\frac{P(R=1|q)}{P(R=0|q)} \\prod_{x=1, q=1} \n\\frac{\\frac{p_i}{q_i}}{\\frac{1 - p_i}{1-q_i}} \\prod_{q=1} \n\\frac{1- p_i}{1- q_i}$$ \n\nWe not observe that the quantity \n$\\frac{P(R=1|q)}{P(R=0|q)}$ represents the odds of the query and does not \ndepend on the document.\nAlso, the quantity $\\prod_{q_i = 1} \\frac{1- p_i}{1-q_i}$ depends on the terms \nthat are in the query, it's so query dependent but it does not change \nfor different documents.\nThis leads to a simplification of the previous formula, with some rewriting\n$$O(R=1|q, \\vec{x}) \\approx \\prod_{x_i=1, q_i = 1} \n\\frac{p_i(1-q_i)}{q_i(1-p_i)}$$\n\n\\paragraph{Retrieval Status Value}\nAfter the last simplification we can calculate the Retrieval Status Value\nfor a document given a query as the quantity\n$$\\mathit{RSV}_{q,d} = \\log \\prod_{x_i=1, q_i = 1} \n\\frac{p_i(1-q_i)}{q_i(1-p_i)} = \\sum_{x_i=1, q_i = 1} \\log \n\\frac{p_i(1-q_i)}{q_i(1-p_i)}$$\n\n\\paragraph{Estimating probabilities}\nWe now just need to estimate $p_i$ and $q_i$ and we are ready to go.\nIf a dataset has informations about relevant documents given a query, \nwe can easily estimate them, given $R(t)$ and $N(t)$ occurrences of term $t$ in \nrelevant and non relevant documents\n$$p_i = \\frac{R(t_i) + 0.5}{R + 1.0}, \\;\\; q_i = \\frac{N(t_i) + 0.5}{N + 1.0}$$\n\nOf course we don't always have the relevant and non relevant documents \nfor queries, so we need some assumptions:\n\\begin{itemize}\n    \\item $p_i = q_i\\;\\mathit{if}\\; t_i \\notin q$, as discussed above\n    \\item $p_i = 0.5\\;\\mathit{if}\\; t_i \\in q$, we have the same probability of \n    observing or not a term in a randomly-picked relevant document\n    \\item $q_i \\approx \\frac{ |\\{ d | t_i \\in d\\}| }{ |D| }$, \n    the set of non-relevant documents is approximated by the whole collection \n    of documents $D$\n\\end{itemize}\nBy applying the previous assumptions we obtain\n\\begin{equation}\n    \\begin{aligned}\n        \\mathit{RSV}_{q,d} &= \\sum_{x_i=1, q_i = 1} \\log \\frac{p_i(1-q_i)}{q_i(1-p_i)}\\\\\n        &= \\sum_{x_i=1, q_i = 1} \\log \\frac{(1-q_i)}{q_i}\\\\\n        &= \\sum_{x_i=1, q_i = 1} \\log \\frac{N - N_i + 0.5}{N_i + 0.5}\n    \\end{aligned}\n\\end{equation}\nBy having $n$ and $N$ as the number of docs with $t$ and the total \nnumber of docs, respectively\n$$\\log \\frac{(1-q_i)}{q_i} \\approx \\log \\frac{N-n}{n} \\approx \\log \\frac{N-n}{n} = \\mathit{IDF}$$\n\nThis means that in practice, we are intersecting a document and a query terms, \nsumming the \\emph{IDF} of the words in the intersection, of course, by\nconsidering the initial assumptions.\n\n\\subsection{Non binary models}\nThe non binary models takes into consideration the frequency of the terms \nand not simply a binary vector. They remove the binary assumption \nof the model presented in \\vref{binary-ind}.\n\n\\paragraph{Okapi BM25}\nIn this non binary model, the RSV is estimated as follows\n$$\\mathit{RSV}_{q,v} = \\sum_{t \\in q}\\log \\frac{N}{\\mathit{df}_t} \n\\cdot \\frac{(k+1)\\mathit{tf}_{t,d}}{k((1-b) + b (\\frac{L_d}{L_{\\mathit{avg}}})) \n+ \\mathit{tf}_{t,d}}$$\n$k$ regulates the term frequency, while $b$ scales the importance of \nthe document length.\n\n\\subsection{Probabilistic language modelling}\n\\label{problangmodel}\nThe goal is now to remove the independence assumption made in the model \nat \\vref{binary-ind}.\n\nIn order to accomplish this, we need a model that can compute the probability \nof a sentence, i.e. a query, where the order of the words is important:\n$$P(S) = P(w_1, \\dots, w_n)$$\nAnother request is to have a generative model for sentences, so a model \nthat estimates the probability of a word, given the previous terms in the \nsequence:\n$$P(w_k | w_{k-1}, \\dots, w_1)$$\n\nThe idea is to build a model on top of each document and calculate \nthe probability $P(q|M_d)$ that a query $q$ has been generated by the model \n$M_d$.\n\n\\paragraph{Computing a sentence probability}\nGiven a sentence, for instance \\emph{Mario plays a lot with Maria}, \nwe need to compute the joint probability:\n$$P(\\mathit{Mario}, \\mathit{plays}, \\mathit{a}, \\mathit{lot}, \\mathit{with}, \\mathit{Maria})$$\nBy applying the chain rule we can calculate the probability of the sequence\n$$P(x_1, x_2, \\dots, x_n) = P(x_1)P(x_2|x_1)P(x_3|x_1,x_2)\\dots = \\prod_i^nP(w_i|w_1, \\dots, w_{i-1})$$ \n\nCalculating the quantity on real world documents could be impossible, \nas we might not be able to count long sequences of words to calculate the probability.\nAn approximation to the sequence probability is given by restricting the sequence length:\n$$P(w_1, \\dots, w_n) \\approx \\prod_i^nP(w_i | w_{i-k}, \\dots, w_{i-1})$$\n$k$ is a parameter, it should be \nsmall if the dataset is really small, or higher if there is enough data. For instance, \nif we take $k=2$ we are estimating the sequence by bi-grams\n$$P(w_1, \\dots, w_n) \\approx \\prod_i^nP(w_i | w_{i-1})$$\nNote that to compute the probability of a bi-gram, we just count occurrences of a given bi-gram \nover all the possible ones.\n\n\\paragraph{Query likelihood model}\nAfter building a model $M_d$ for each documents, following the idea presented on the previous paragraph, \nwe can estimate relevance of documents given a query. \n\nSo the probability that a query was generated by a document becomes:\n$$P(q|M_d) = K_q\\prod_iP(w_i|M_d)^{\\mathit{tf}_{w_i, d}}\\;\\;\\; \nK_q = \\frac{\\mathit{Len}(K_q)!}{\\mathit{tf}_{t_1, q}! \\dots \\mathit{tf}_{t_N, q}!}$$\nThe $K_q$ is query dependent, so we can ignore it, it would take into consideration \nthe query permutations.\n\nWe can also estimate the probability with this quantity \n$$P(q|M_d) \\approx \\prod_i\\frac{\\mathit{tf}_{t_i, d}}{L_d}$$\n\nNote that $\\mathit{tf}_{t_i, d}$ can be changed to the probability of the \nk-grams computed at the previous paragraph, it depends on how we choose to \nestimate the sentence probability.\n\n\\paragraph{Smoothing}\nNote that all zero and non frequent term probabilities are a problem, \nfor instance a long sequence could be interrupted by only one bi-gram not appearing in \nthe document, the solution\nis to smooth the numbers, for instance with the \\emph{Laplace smoothing} that adds \none to each bi-gram, the \\emph{Bayesian smoothing} or the \\emph{Linear interpolation} that \ntakes into consideration the global document model.\n\n\\subsection{Other models}\n\\paragraph{Kullback-Leibler divergence model}\nIn this model the relevance term is computed as the quantity \n$$R(d, q) = \\sum_i P(w_i|M_q)\\log\\frac{P(w_i|M_q)}{P(w_i|M_d)}$$\nwhere $M_q$ is the model computed on the query.\n\n\\paragraph{Translation model}\nThe idea here is to use a generative model taking into consideration \nthe possible translation of a query term.", "meta": {"hexsha": "7e0fe1c467069fd2fbe6c32ead49200d6b3142fc", "size": 11295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-courses/information-retrieval/chapters/prob.tex", "max_stars_repo_name": "marcodb97/unimi-notes", "max_stars_repo_head_hexsha": "b0b9520a01568c4c64f4fdb69523dd05339ee8f6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "old-courses/information-retrieval/chapters/prob.tex", "max_issues_repo_name": "marcodb97/unimi-notes", "max_issues_repo_head_hexsha": "b0b9520a01568c4c64f4fdb69523dd05339ee8f6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old-courses/information-retrieval/chapters/prob.tex", "max_forks_repo_name": "marcodb97/unimi-notes", "max_forks_repo_head_hexsha": "b0b9520a01568c4c64f4fdb69523dd05339ee8f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-09T08:24:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T08:24:02.000Z", "avg_line_length": 45.18, "max_line_length": 113, "alphanum_fraction": 0.6943780434, "num_tokens": 3640, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528094861981, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7099532319533077}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Determine by direct calculation (i.e., without calculating the\n  characteristic polynomial or the eigenvalues) which of the following\n  matrices are positive definite, positive semidefinite, or neither.\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      1 & 1 \\\\\n      1 & 1 \\\\\n    \\end{mymatrix},\\quad\n    B = \\begin{mymatrix}{rr}\n      1  & -2 \\\\\n      -2 &  5 \\\\\n    \\end{mymatrix},\\quad\n    C = \\begin{mymatrix}{rr}\n      2 & 3 \\\\\n      1 & 3 \\\\\n    \\end{mymatrix},\\quad\n    D = \\begin{mymatrix}{rrr}\n      2 & 1 & 1 \\\\\n      1 & 1 & 0 \\\\\n      1 & 0 & 1 \\\\\n    \\end{mymatrix},\\quad\n    E = \\begin{mymatrix}{rrr}\n      1 & 0 &  0 \\\\\n      0 & 2 &  0 \\\\\n      0 & 0 & -1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    (a) Positive semidefinite. (b) Positive definite. (c) Not\n    symmetric (therefore neither). (d) Positive semidefinite. (e)\n    Neither.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Calculate the eigenvalues of each symmetric matrix, then determine\n  for each matrix whether it is positive definite, positive\n  semidefinite, or neither.\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      2 & 2 \\\\\n      2 & 5 \\\\\n    \\end{mymatrix},\\quad\n    B = \\begin{mymatrix}{rr}\n      4  & -6 \\\\\n      -6 &  9 \\\\\n    \\end{mymatrix},\\quad\n    C = \\begin{mymatrix}{rrr}\n      2 &  1 &  0 \\\\\n      1 &  1 & -1 \\\\\n      0 & -1 &  2 \\\\\n    \\end{mymatrix},\\quad\n    D = \\begin{mymatrix}{rrr}\n      3 & -4 &  2 \\\\\n     -4 &  4 &  0 \\\\\n      2 &  0 &  4 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  is positive definite, positive semidefinite, or neither.\n  \\begin{sol}\n    (a) Eigenvalues: $\\set{1,6}$. Positive definite.\n    (b) Eigenvalues: $\\set{0,13}$. Positive semidefinite.\n    (c) Eigenvalues: $\\set{0,2,3}$. Positive semidefinite.\n    (d) Eigenvalues: $\\set{-1,4,8}$. Neither.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Which of the following formulas define an inner product on $\\R^3$?\n  Here, $\\vect{u}=\\mat{u_1,u_2,u_3}^T$ and\n  $\\vect{v}=\\mat{v_1,v_2,v_3}^T$.\n  \\begin{enumerate}\n  \\item $\\iprod{\\vect{u},\\vect{v}} = u_1v_1 + 2u_1v_2 + 2u_2v_1 + 3u_2v_2\n    + 3u_3v_3$.\n  \\item $\\iprod{\\vect{u},\\vect{v}} = u_1v_1 - u_1v_2 - u_2v_1 + 2u_2v_2\n    + u_3v_3$.\n  \\item $\\iprod{\\vect{u},\\vect{v}} = u_1v_1 - u_1v_2 - u_2v_1 + u_2v_2\n    + 4u_3v_3$.\n  \\item $\\iprod{\\vect{u},\\vect{v}} = u_1v_1 - u_1v_2 - u_2v_1 + 3u_2v_2\n    - u_2v_3 - u_3v_2 + u_3v_3$.\n  \\end{enumerate}\n  \\begin{sol}\n    (a) No (neither positive definite nor semidefinite).\n    (b) Yes.\n    (c) No (positive semidefinite but not definite).\n    (d) Yes.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Use Descartes' rule of signs to determine which of the following\n  matrices are positive definite and/or positive semidefinite.\n  \\begin{equation*}\n    A = \\begin{mymatrix}{cc}\n      2 & 2 \\\\\n      2 & 1 \\\\\n    \\end{mymatrix},\n    \\quad\n    B = \\begin{mymatrix}{ccc}\n      2  & -1 & 0 \\\\\n      -1 &  1 & 0 \\\\\n      0  &  0 & 1 \\\\\n    \\end{mymatrix},\n    \\quad\n    C = \\begin{mymatrix}{cccc}\n      2  & 1 & -1 &  1 \\\\\n      1  & 1 &  0 &  0 \\\\\n      -1 & 0 &  2 & -1 \\\\\n      1  & 0 & -1 &  1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    The characteristic polynomials are:\n    \\begin{equation*}\n      \\begin{array}{lcl}\n        \\det(A-\\eigenvar I) &=& \\eigenvar^2 - 3\\eigenvar - 2, \\\\\n        \\det(B-\\eigenvar I) &=& -\\eigenvar^3 + 4\\eigenvar^2 - 4\\eigenvar + 1, \\\\\n        \\det(C-\\eigenvar I) &=& \\eigenvar^4 - 6\\eigenvar^3 + 9\\eigenvar^2 - 3\\eigenvar + 0.\n      \\end{array}\n    \\end{equation*}\n    For $A$, the coefficients are not weakly alternating, so $A$ is\n    not positive semidefinite. For $B$, the coefficients are strongly\n    alternating, so $B$ is positive definite. For $C$, the\n    coefficients are weakly, but not strongly alternating, so $C$ is\n    positive semidefinite, but not positive definite.\n  \\end{sol}\n\\end{ex}\n", "meta": {"hexsha": "5846627cd9d6c684903c8a7ae6047a66c75c3ace", "size": 3851, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/InnerProductSpaces-Positive.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/InnerProductSpaces-Positive.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/InnerProductSpaces-Positive.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 29.3969465649, "max_line_length": 91, "alphanum_fraction": 0.564269021, "num_tokens": 1559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907933, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.7099532309783081}}
{"text": "\\chapter{EM waves}\n\n\n\\section{Electromagnetic Wave}\n\\textbf{Waves}\\\\\nClassical wave equation can be represents as\n\\begin{equation}\\label{wave}\n\\frac{d^2f}{dz^2}=\\frac{1}{V^{2}}\\quad\\frac{d^2 f}{dt^2} \n\\end{equation}\n\\begin{align*}\n\\intertext{Where $V$ is the velocity of propagation}\nV&=\\sqrt{\\frac{T}{\\mu}} \\text{in the case of waves in a string}\\\\\nT&=\\text{Tension} \\\\\n\\mu&=\\text{man per unit length}\n\\intertext{Equation.\\ref{wave} has a general solution in the form.}\nf(z,t)&=A \\cos[k(z-vt)+\\delta]\\\\\n\\text{where}\\ k&=\\frac{2\\pi}{\\lambda}\\text{is clled wave number}\\\\\n\\text{If $T$ is the time period}T&=\\frac{1}{x}\\\\\n\\text{And $\\omega$ is the angular frequency }\\omega&=2\\pi x\\\\\nf(z,t)&=A \\cos(kz-\\omega t+\\delta)\\\\\n\\text{By using complex notation,}\\\\\n{f}(z,t)&={A}e^{i(kz-\\omega t)}\\\\\nf(z,t)&=Re[{f}(z,t)]\\\\\nf(z,t) \\text{is the actual wave function}\n\\end{align*} \n\\section{Electromagnetic Waves in Vaccum}\nThe wave equation for $\\vec{E}$ and $\\vec{B}$ is obtained from  Maxwell's equations. The four Maxwell's equations in vaccum  where there is no charge or current \\ $(\\rho=0 \\text { and } \\vec{J}=0)$ ,is given by,\n\\begin{align*}\n\\begin{array}{lll}\n\\textbf{(i)}\\quad \\nabla\\cdot E=0&\\hspace{2cm}\\textbf{(iii)}\\quad \\nabla\\times\\vec{E}=\\frac{-dB}{dt}\\\\\\\\\n\\textbf{(ii)}\\quad \\nabla\\cdot B=0&\\hspace{2cm}\\textbf{(iv)} \\quad \\nabla\\times\\vec{B}=\\mu_{0}\\varepsilon_0\\frac{\\partial E}{\\partial t}\n\\end{array}\n\\end{align*}\nApplying curl to \\textbf{(iii)}\\ $\\nabla\\times\\vec{E}=\\frac{-dB}{dt}$\n\\begin{align*}\n\\vec{\\nabla} \\times(\\vec{\\nabla} \\times \\vec{E})&=\\vec{\\nabla} \\times\\left(-\\frac{\\partial \\vec{B}}{\\partial t}\\right)\\\\ \\Rightarrow \\vec{\\nabla}(\\vec{\\nabla} \\cdot \\vec{E})-\\nabla^{2} \\vec{E}&=-\\frac{\\partial}{\\partial t}(\\vec{\\nabla} \\times \\vec{B})\n\\intertext{Applying  \\ $\\nabla\\cdot E=0$ \\ and \\ $\\nabla\\times\\vec{B}=\\mu_{0}\\varepsilon_0\\frac{\\partial E}{\\partial t} $, \\ we get,}\n\\Rightarrow \\hspace{1.4cm}-\\nabla^{2} \\vec{E}&=-\\frac{\\partial}{\\partial t}\\left(\\mu_{0} \\varepsilon_{0} \\frac{\\partial \\vec{E}}{\\partial t}\\right)\\\\\n\\Rightarrow \\hspace{1.68cm} \\nabla^{2} \\vec{E}&=\\mu_{0} \\varepsilon_{0} \\frac{\\partial^{2} \\vec{E}}{\\partial t^{2}} \n\\end{align*}\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][1.5cm]{5cm}{\n\t\t\t\n\t\t\t\\addvspace{0cm} \\centering\n\t\t\t\n\t\t\t\\begin{align*}\n\t\t\t\\nabla^2 E-\\mu_{0}\\varepsilon_0\\frac{d^2 E}{dt^2}=0\n\t\t\t\\end{align*}} }\n\\end{center}\nSimiliarly applying curl to \\textbf{(iv)}\\ $\\nabla\\times\\vec{B}=\\mu_{0}\\varepsilon_0\\frac{\\partial E}{\\partial t}$\\ we get, \n\\begin{align*}\n\\nabla\\times(\\nabla\\times B)&= \\nabla\\times(\\mu_{0}\\varepsilon_0\\frac{\\partial E}{\\partial t}) \\\\\\Rightarrow  \\nabla(\\nabla\\cdot B)-\\nabla^2B &=\\nabla\\times(\\mu_{0}\\varepsilon_0\\frac{\\partial E}{\\partial t})\\\\\n\\Rightarrow \\hspace{1.3cm} \\ -\\nabla^2B &=\\mu_{0}\\varepsilon_0\\frac{\\partial}{\\partial t}(\\nabla\\times E)\\\\\n&=-\\mu_{0}\\varepsilon_0\\frac{\\partial ^2B}{\\partial t^2}\\\\\n\\Rightarrow \\hspace{1.6cm} \\ \\nabla^2 B&= \\mu_{0}\\varepsilon_0\\frac{\\partial^2B}{\\partial t^2}\n\\end{align*}\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][1.5cm]{5cm}{\n\t\t\t\n\t\t\t\\addvspace{0cm} \\centering\n\t\t\t\n\t\t\t\\begin{align*}\n\t\t\t\\nabla^2 B-\\mu_{0}\\varepsilon_0\\frac{d^2 B}{dt^2}=0\n\t\t\t\\end{align*}} }\n\\end{center}\nThus both equations obey the general wave equation,\n\\begin{align*}\n\\nabla^{2} \\psi-\\frac{1}{c^{2}} \\frac{\\partial^{2} \\psi}{\\partial t^{2}}&=0\n\\intertext{We can write the speed of electromagnetic wave propagation in free space is}\nc&=\\frac{1}{\\sqrt{\\varepsilon_0\\mu_{0}}}=3\\times10^8 {m}/{s}\n\\intertext { Which is speed of light in free space. This says that the light is an electromagnetic wave. }\n\\end{align*}\n\\subsubsection{Plane Wave Solution}\nLet us look at \"plane wave\" solutions to these wave equations for $\\vec{E} \\ \\text{and}\\ \\vec{B}$ . A plane wave is one for which the surfaces of constant phases, are planes. Time harmonic solutions are of the form $\\sin (\\vec{k} \\cdot \\vec{r}-\\omega t)$ or $\\cos (\\vec{k} \\cdot \\vec{r}-\\omega t)$. However, mathematically it turns out to be simple to consider an exponential form and take, at the end of calculations, the real or the imaginary part.\n\\begin{align*}\n\\intertext{We take the solutions to be of the form,}\n\\vec{E}&=\\vec{E}_{0} e^{i(\\vec{k} \\cdot \\vec{r}-\\omega t)} \\\\\n\\vec{B}&=\\vec{B}_{0} e^{i(\\vec{k} \\cdot \\vec{r}-\\omega t)}\n\\intertext{Note that the surfaces of constant phase are given by,}\n\\vec{k} \\cdot \\vec{r}-\\omega t&=\\text { constant }\n\\intertext{$\\vec{E}_{0}, \\vec{B}_{0}$ are the complex amplitude, and $\\vec{k}$ is the wave vector. $\\vec{k}$ is defined as,}\n\\vec{k}&=\\frac{2 \\pi}{\\lambda} \\hat{k}\\\\&=\\frac{2 \\pi \\nu }{c} \\hat{k} \\qquad \\text{Since,}\\ c=\\nu \\lambda\\\\&=\\frac{\\omega}{c} \\hat{k} \\hspace{1.15cm}\\text{Since,}\\ 2 \\pi \\nu = \\omega  \n\\intertext{($\\hat{k}$ is unit vector along propagation direction.)}\n\\end{align*}\n\n\\subsection{Directions of $\\vec{E}, \\vec{H}, \\vec{k}$}\nWe have solution of wave equation,\n\\begin{align*}\n\\vec{E}(r, t)&=\\vec{E}_{0} e^{i(\\hat{k} \\cdot \\vec{r}-\\omega t)} \\\\\n\\vec{H}(r, t)&=\\vec{H}_{0} e^{i(\\vec{k} \\cdot \\vec{r}-\\omega t)}\n\\end{align*}\nWe have four Maxwell's equations as,\n\\begin{align*}\n\\nabla\\cdot E=0&\\hspace{2cm}\\quad \\nabla\\times\\vec{E}=\\frac{-dB}{dt}\\\\\n\\quad \\nabla\\cdot B=0&\\hspace{2cm} \\quad \\nabla\\times\\vec{B}=\\mu_{0}\\varepsilon_0\\frac{\\partial E}{\\partial t}\n\\end{align*}\nWhen we substitute the solutions of the wave quations, in Maxwell's equations we get,\n\\begin{alignat*}{3}\n\\vec{\\nabla} \\cdot \\vec{E}&=0 \\qquad &&\\Rightarrow i \\vec{k} \\cdot \\vec{E}=0 && \\therefore \\vec{k} \\perp \\vec{E} \\\\\n\\vec{\\nabla} \\cdot \\vec{B}&=0 \\qquad &&\\Rightarrow i \\vec{k} \\cdot \\vec{B}=0 && \\therefore \\vec{k} \\perp \\vec{B} \\\\\n\\vec{\\nabla} \\times \\vec{E}&=-\\frac{\\partial \\vec{B}}{\\partial t} \\qquad && \\Rightarrow i \\vec{k} \\times \\vec{E}=i \\omega  \\vec{B} \\quad&& \\therefore \\vec{k} \\times \\vec{E}=\\omega  \\vec{B} \\\\\n\\vec{\\nabla} \\times \\vec{B}&=\\mu_{0}\\varepsilon_{0} \\frac{\\partial \\vec{E}}{\\partial t}\\qquad  &&\\Rightarrow i \\vec{k} \\times \\vec{B}=-i \\omega \\mu_{0}\\varepsilon_{0} \\vec{E} \\quad &&\\therefore \\vec{k} \\times \\vec{B}=\\omega \\mu_{0}\\varepsilon_{0} \\vec{E}\n\\end{alignat*}\nFrom these equations we can say $\\vec{k}, \\vec{E}, \\vec{B}$ are mutually perpendicular to each other.\n\n\\subsection{Poynting Vector in Electromagnetic waves}\nThe poynting's vector for the plane electromagnetic wave in free space .\nEnergy per unit volume stored in em field is \n\\begin{align}\n\\vec{S} &=\\frac{1}{\\mu_{0}}(\\vec{E} \\times \\vec{B}) \\qquad \\text{Since,}\\ \\vec{k} \\times \\vec{E}=\\omega  \\vec{B}\\\\\\notag &=\\frac{1}{\\mu_{0} \\omega} \\vec{E} \\times(\\vec{k} \\times \\vec{E}) \\\\\\notag\n&=\\frac{1}{\\mu_{0} \\omega}[\\vec{k}(\\vec{E} \\cdot \\vec{E})-E(E \\cdot k)]\\\\\\vec{S}&=\\frac{E^{2}}{\\mu_{0} \\omega} \\vec{k} \\label{poynting2}\n\\intertext{Thus, the energy flow is in the direction of wave propagation.}\n\\intertext{ We know that $\\vec{E}$ is normal to $\\vec{k}$, }\n\\vec{k} \\times \\vec{E}&=\\omega  \\vec{B}\n\\intertext{ We can write in terms of magnitude,}\n\\notag\tk E&= \\omega B\n\\qquad \\Rightarrow \\quad\\frac{k}{\\omega} E = B\\\\\\notag\n\\frac{1}{c} E &= B \\hspace{1cm} \\Rightarrow \\quad\n\\sqrt{\\mu_{0} \\varepsilon_{0}}  E=B\\\\\n\\sqrt{\\varepsilon_{0}}   E&=\\frac{1}{\\sqrt{ \\mu_{0}}}B \\label{poynting5}\n\\intertext{Squaring both sides, and multiplying by $ \\frac{1}{2} $ we get,}\\quad \\varepsilon_{0} E^{2}&=\\frac{1}{{ \\mu_{0}}}B^{2}\n\\intertext{This shows that in case of electromagnetic waves in free space electromagnetic energy is equally shared between electric and magnetic fields.}\n\\intertext{Then total energy density of an EM wave in free space   can be written as,}\nu&=u_{em}+u_{m}\\\\u&=\\frac{1}{2} \\varepsilon_{0} E^{2}+\\frac{1}{{ \\mu_{0}}}B^{2}\\\\u&=\\varepsilon_{0} E^{2}\\label{poynting3}\n\\end{align}\n\\hspace{5.10cm}\\framebox{\n\t\n\t\\parbox[t][1.0cm]{4cm}{\n\t\t\n\t\t\\addvspace{0.2cm} \\centering \n\t\t$u=\\varepsilon_{0} E^{2}$} \n}\n\\begin{align}\n\\intertext{From equation.\\ref{poynting2} we know that ,}\n\\vec{S}&=\\frac{E^{2}}{\\mu_{0} \\omega} \\vec{k}\\\\\n\\intertext{substituting equation. \\ref{poynting3} and taking only magnitude we get,}\nS&=\\frac{u}{\\varepsilon_{0}}\\frac{k}{\\omega \\mu_{0}}\\\\\n&=\\frac{u}{\\mu_{0} \\varepsilon_{0}}\\frac{k}{\\omega }\\\\\n&={u c^{2}}\\frac{1}{c }\\\\\nS&=uc\n\\intertext{{In vector form,}}\n\\vec{S}&=uc \\hat{k} \\qquad \\text{Where $\\hat{k}$ is the propogation direction.}\n\\end{align}\n\n\\hspace{5.10cm}\\framebox{\n\t\n\t\\parbox[t][4.0cm]{4cm}{\n\t\t\n\t\t\\addvspace{0.2cm} \\centering \n\t\t\\begin{align*}\n\t\t\\vec{S} &=\\frac{1}{\\mu_{0}}(\\vec{E} \\times \\vec{B})\\\\\n\t\t\\vec{S}&=\\frac{E^{2}}{\\mu_{0} \\omega} \\vec{k}\\\\\n\t\t\\vec{S}&=uc \\hat{k}\n\t\t\\end{align*}} \n}\n\n\\subsubsection{Momentum}\nThe momentum density stored in the electromagnetic field is given by,\\\\\n\\begin{align*}\n\\vec{P}&=\\frac{\\vec{S}}{c^{2}} \\qquad \\text{But,}\\quad \\vec{S}=uc \\hat{k}\\\\\n\\vec{P}&=\\frac{u}{c}\\hat{k}\\\\\n\\text{Or,}\\qquad \\vec{P} &=\\frac{1}{c} \\varepsilon_{0} {E}^{2} \\ \\hat{k}\n\\end{align*}\n\\subsubsection{Avarage Values}\nIf we find the average values of  electric field $E$ and magnetic field $B$ we get the values as,\n\\begin{align}\n\\langle E\\rangle &=\\frac{{E_{0}}}{\\sqrt{2}} \\\\\\text{And} \\quad \\langle B\\rangle &=\\frac{{B_{0}}}{\\sqrt{2}} \\qquad\\text{(Here, average value equals the rms value.)} \n\\intertext{Where  $ E_{0} $ and $B_{0}$ are the amplitudes.}\n\\intertext{\\textbf{The average value of $\\vec{S}$,}}\n\\vec{S}&=\\frac{1}{\\mu_{0}}(E\\times B) \\hat{k}\\\\\n\\langle \\vec{S}\\rangle &= \\frac{1}{\\mu_{0}} \\langle (E\\times B)\\rangle  \\hat{k}=  \\frac{1}{\\mu_{0}} \\frac{{E_{0}}}{\\sqrt{2}} \\cdot \\frac{{B_{0}}}{\\sqrt{2}} \\hat{k}\\\\\n&=\\frac{1}{2\\mu_{0}} E_{0} B_{0} \\hat{k}\\label{poynting4}\n\\intertext{We know that, $E=cB$ and $c=\\frac{1}{\\sqrt{\\mu_{0} \\varepsilon_{0}}}$}\n\\intertext{Then equation. \\ref{poynting4} becomes,}\n\\langle \\vec{S}\\rangle &= \\frac{1}{2} c\\varepsilon_{0} E_{0}^{2} \\hat{k}\n\\end{align}\n\\begin{align*}\n\\intertext{\\textbf{Average energy density,}}\n\\intertext{We know that, $u=\\varepsilon_{0} E^{2}$ . Then,}\n\\langle u\\rangle&=\\frac{1}{2}\\varepsilon_{0} {E_0}^{2}\\\\\n\\intertext{\\textbf{Average momentum density}}\n\\intertext {We know that, $\\vec{P} =\\frac{1}{c} \\varepsilon_{0} {E}^{2} \\ \\hat{k}$, then}\n\\langle\\vec{p}\\rangle&=\\frac{1}{2c}\\varepsilon_{0} {\\epsilon_0}^{2} \\hat{k}\n\\end{align*}\n\\subsubsection{Intensity of Electromagnetic wave}\nThe magnitude of the time average of the Poynting's vector is called the intensity of radiation (I). Thus, the intensity.\n\\begin{align*}\nI&=|\\langle {s}\\rangle|\\\\&=\\frac{1}{2}c \\varepsilon_{0}  E^2\n\\intertext{But, we found that, $ \\langle u\\rangle=\\frac{1}{2}\\varepsilon_{0} {E_0}^{2}$, Then, }\nI&=\\langle u\\rangle c\n\\end{align*}\n\\textbf{Radiation Pressure}\\\\\nWhen light falls on a perfect absorber it delivers its momentum to the surface. In a time of the momentum transfer it\n$$\\Delta P=AC \\Delta t\\text{ so the}$$\\\\\n$$\\text{radiation presure }=\\frac{1}{A} \\frac{\\Delta P}{\\Delta t}=\\frac{1}{2}\\varepsilon_{0} E_0^2=\\frac{I}{C}$$\nfor perfect reflector pressure is twice as great because momentum switches direction, instead of simply being absorbed.\n\\begin{exercise}\n\tCompute the intensity of the standing electromagnetic wave given by\n\t$$\n\tE_{y}(x, t)=2 E_{0} \\cos k x \\cos \\omega t, \\quad B_{z}(x, t)=2 B_{0} \\sin k x \\sin \\omega t\n\t$$\n\\end{exercise}\n\\begin{answer}\n\tThe Poynting vector for the standing wave is\n\t\\begin{align*}\n\t\\overrightarrow{\\mathbf{S}} &=\\frac{\\overrightarrow{\\mathbf{E}} \\times \\overrightarrow{\\mathbf{B}}}{\\mu_{0}}=\\frac{1}{\\mu_{0}}\\left(2 E_{0} \\cos k x \\cos \\omega t \\hat{\\mathbf{j}}\\right) \\times\\left(2 B_{0} \\sin k x \\sin \\omega t \\hat{\\mathbf{k}}\\right) \\\\\n\t&=\\frac{4 E_{0} B_{0}}{\\mu_{0}}(\\sin k x \\cos k x \\sin \\omega t \\cos \\omega t) \\hat{\\mathbf{i}} \\\\\n\t&=\\frac{E_{0} B_{0}}{\\mu_{0}}(\\sin 2 k x \\sin 2 \\omega t) \\hat{\\mathbf{i}}\n\t\\intertext{The time average of $S$ is}\n\t\\langle S\\rangle&=\\frac{E_{0} B_{0}}{\\mu_{0}} \\sin 2 k x\\langle\\sin 2 \\omega t\\rangle=0\n\t\\end{align*}\n\tThe result is to be expected since the standing wave does not propagate. Alternatively, we may say that the energy carried by the two waves traveling in the opposite directions to form the standing wave exactly cancel each other, with no net energy transfer.\n\\end{answer}\n\\section{Electromagnetic Waves in Matter}\nThe Maxwell's equation inside matter where there is no free charge or free current are given by,\n\n\\begin{align*}\n\\textbf{(i)}\\quad \\nabla\\cdot \\vec{D}=0&\\hspace{4cm}\\textbf{(iii)} \\quad\\nabla\\times \\vec{E}=\\frac{-\\partial \\vec{B}}{\\partial t}\\\\\\\\\n\\textbf{(ii)}\\quad\\nabla\\cdot \\vec{B}=0&\\hspace{4cm}\\textbf{(iv)}\\quad\\nabla\\times \\vec{H}=\\frac{\\partial \\vec{D}}{\\partial t}\\\\\n\\intertext{If the medium is linear,\\quad $ D=\\varepsilon E,\\qquad H=\\frac{B}{\\mu} $}\n\\intertext{If the medium is homogeneous so that $ \\varepsilon $\\ and \\ $ \\mu$\\ do not vary point to point. The Maxwell's equations becomes, }\n\\textbf{(i)}\\quad \\nabla\\cdot \\vec{E}=0&\\hspace{4cm}\\textbf{(iii)} \\quad\\nabla\\times \\vec{E}=\\frac{-\\partial \\vec{B}}{\\partial t}\\\\\\\\\n\\textbf{(ii)}\\quad\\nabla\\cdot \\vec{B}=0&\\hspace{4cm}\\textbf{(iv)}\\quad\\nabla\\times \\vec{B}= \\mu \\varepsilon\\frac{\\partial \\vec{E}}{\\partial t}\n\\end{align*}\nThe electromagnetic waves propgates through a linear homogeneous medium at a speed,\n\\begin{align*}\nV&=\\frac{1}{\\sqrt{\\varepsilon\\mu}}\\\\&=\\frac{c}{n}\\hspace{2cm} \\text{Where,}\\ n= \\sqrt{\\frac{\\mu \\varepsilon}{\\mu_0 \\varepsilon_0}} \\qquad \\Rightarrow \\text{refractive index of the substance.}\n\\intertext{Since, for most materials  \\ $\\mu$ is very close to  $\\mu_{0}$ }\nn& \\approxeq \\sqrt{\\varepsilon_r}\\qquad \\Rightarrow \\varepsilon_r= \\ \\sqrt{\\frac{\\epsilon}{\\epsilon_{0}}}\n\\end{align*}\n$\\varepsilon_r$ is dielectric constant which almost always greater than $1$. So speed of light in matter $(V=\\frac{c}{n})$ should always be less than $C$.\\\\\n\\subsection{Boundary condition}\\label{boundary condition1}\n\\begin{alignat*}{2}\n\\intertext{The boundary conditions at the interface can be written as,}\n&\\textbf{(i)}\\quad\\varepsilon_1E^\\perp_1=  \\varepsilon_2E^\\perp_2 \\hspace{4cm}  &&\\textbf{(iii)}\\quad E^\\parallel_1= E^\\parallel_2\\\\\n&\\textbf{(ii)}\\quad B^\\perp_1= B^\\perp_2\n\\hspace{4cm}  &&\\textbf{(iv)}\\quad \\frac{B^\\parallel_1}{\\mu_{1}}=  \\frac{1}{\\mu_{2}}B^\\parallel_2\n\\end{alignat*}\n\\subsection{Reflection and Transmission at Normal incidence}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=6cm,width=8cm]{em wave}\n\t\\caption{Reflection and Transmission at Normal incidence}\n\t\\label{Reflection and Transmission at Normal incidence}\n\\end{figure}\nSuppose the $xy$ plane forms the boundary between two linear media. A plane wave of frequency($\\omega$)travelling in the $z$direction and polarized in $x$ direction approaches the interface from the left.\n\n\\begin{align}\n\\intertext{\\textbf{Incident wave :}}\n\\left.\\begin{array}{l}\\vec{\\mathbf{E}}_{I}(z, t)=\\vec{E}_{0_{I}} e^{i\\left(k_{1} z-\\omega t\\right)} \\hat{{i}} \\\\\\\\ \\vec{\\mathbf{B}}_{I}(z, t)=\\frac{1}{v_{1}} \\vec{E}_{0_{I}} e^{i\\left(k_{1} z-\\omega t\\right)} \\hat{{j}}\\end{array}\\right\\}\\\\\n\\notag v_1 =\\text{Velocity in first medium}&\\\\\n\\intertext{\\textbf{Reflected wave :}}\n\\left.\\begin{array}{l}\n\\vec{\\mathbf{E}}_{R}(z, t)=\\vec{E}_{0_{R}} e^{i\\left(-k_{1} z-\\omega t\\right)} \\hat{{i}} \\\\\\\\\n\\vec{\\mathbf{B}}_{R}(z, t)=-\\frac{1}{v_{1}} \\vec{E}_{0_{R}} e^{i\\left(-k_{1} z-\\omega t\\right)} \\hat{{j}}\n\\end{array}\\right\\}\n\\intertext{\\textbf{Transmitted wave :}}\n\\left.\\begin{array}{l}\n\\vec{\\mathbf{E}}_{T}(z, t)=\\vec{E}_{0_{T}} e^{i\\left(k_{2} z-\\omega t\\right)} \\hat{{i}} \\\\\\\\\n\\vec{\\mathbf{B}}_{T}(z, t)=\\frac{1}{v_{2}} \\vec{E}_{0_{T}} e^{i\\left(k_{2} z-\\omega t\\right)} \\hat{{j}}\n\\end{array}\\right\\}\\\\\n\\notag v_2 =\\text{Velocity in second medium}&\n\\end{align}\n\\begin{align}\n\\intertext{At $z=0$, the combined field on the left $\\vec{E}_{I}+\\vec{E}_{R}$ and $\\tilde{B}_{I}+\\vec{B}_{R}$, must join the fields on the\n\tright $\\vec{E}_{T} \\& \\vec{B}_{T}$, in accordance with the boundary conditions in section \\ref{boundary condition1}.}\n\\intertext{There are no electric components in perpendicular direction,Then the third boundary condition $E^\\parallel_1= E^\\parallel_2$ \\ gives,}\n\\vec{E_0}_1+\\vec{E_0}_R&=\\vec{E_0}_T \\label{waves2}\n\\intertext{Then the fourth boundary condition $ \\frac{1}{\\mu_{1}}B^\\parallel_1=  \\frac{1}{\\mu_{2}}B^\\parallel_2$ \\ gives,}\n\\frac{1}{\\mu_{1}}\\left( \\frac{1}{v_1}\\vec{E_0}_I-\\frac{1}{v_1}\\vec{E_0}_R\\right) &=\\frac{1}{\\mu_{2}}\\left( \\frac{1}{v_1}\\vec{E_0}_I-\\frac{1}{v_2}\\vec{E_0}_T\\right)\\label{waves1}\n\\end{align}\n\\begin{align}\n\\notag \\text{Since}\\quad\\vec{B_0}_I&=\\frac{1}{v_1}\\vec{E_0}_I\\quad :\\quad\n\\vec{B_0}_R=\\frac{1}{v_1}\\vec{E_0}_R\\quad :\\quad\n\\vec{B_0}_T=\\frac{1}{v_2}\\vec{E_0}_T\\\\\\notag\nn_2&=\\frac{c}{v_2}\\qquad \\text{and }\\qquad\nn_1=\\frac{c}{v_1}\n\\intertext{Then the equation.\\ref{waves1} \\ becomes,}\n\\vec{E_0}_1-\\vec{E_0}_R&=\\beta\\vec{E_0}_T \\label{waves3}\\\\\n\\notag \\text{Where, }\\qquad \\beta&\\equiv\\frac{\\mu_{1}v_1}{\\mu_{2}v_2}=\\frac{\\mu_{1}n_2}{\\mu_{2}n_1}\n\\intertext{By solving equation.\\ref{waves2} and equation. \\ref{waves3} we will get,}\\notag\n\\vec{E_0}_R&=\\left( \\frac{1-\\beta}{1+\\beta}\\right) \\vec{E_0}_I \\quad:\\quad\n\\vec{E_0}_T=\\left( \\frac{2}{1+\\beta}\\right) \\vec{E_0}_I\n\\intertext{If $\\mu_{1}=\\mu_{2}=\\mu_{0} \\Rightarrow \\quad \\beta=\\frac{v_{1}}{v_{2}}=\\frac{n_{2}}{n_{1}}$ (For non-magnetic medium). Then,}\n\\vec{E_0}_R&=\\left( \\frac{v_2-v_1}{v_1+v_2}\\right) \\vec{E_0}_I \\quad:\\quad\n\\vec{E_0}_T=\\left( \\frac{2v_2}{v_1+v_2}\\right) \\vec{E_0}_I\n\\end{align}\n\\begin{align}\n\\intertext{The reflected wave $\\tilde{E_0}_R$ are in phase with incident wave if $v_2>v_1$ and out of phase if $v_2<v_1$},\n\\therefore {E_0}_R&=\\left| \\frac{v_2-v_1}{v_1+v_2}\\right| {E_0}_I\\quad:\\quad {E_0}_T=\\left(\\frac{2v_2}{v_1+v_2} \\right) {E_0}_I\n\\intertext{In terms of reflective indices $n_1$and $n_2$}\n{E_0}_R&=\\left| \\frac{n_1-n_2}{n_1+n_2}\\right| {E_0}_I\\quad:\\quad {E_0}_T=\\left(\\frac{2n_1}{n_1+n_2} \\right) {E_0}_I\n\\intertext{Reflection coefficient,the function of incident is reflected can be find out,}\nR&=\\frac{I_R}{I_I}\n\\intertext{The intensity in general can be written as}\nI&=\\frac{1}{2}\\varepsilon v E_0^2\n\\intertext{if \\ $ \\mu_{1}=\\mu_{2}=\\mu_{0} $ the \\textbf{Reflection coefficient},}\nR&=\\frac{({E_0}_R)^2}{({E_0}_I)^2}=\\left(\\frac{n_1-n_2}{n_1+n_2} \\right)^2  \n\\intertext{And \\textbf{Transmission coefficient},}\nT&=\\frac{I_I}{I_I}=\\frac{\\varepsilon_2v_2}{\\varepsilon_1v_1}\\frac{({E_0}_I)^2}{({E_0}_I)^2}=\\frac{4n_1n_2}{(n_1+n_2)^2}\n\\intertext{And from these equations we can show that $R+T=1$ ie. energy is conserved.}\\notag\n\\end{align}\n\\hspace{5.10cm}\\framebox{\n\t\n\t\\parbox[t][5cm]{4.5cm}{\n\t\t\n\t\t\\addvspace{0.2cm} \\centering \n\t\t\\begin{align*}\n\t\tR&=\\left(\\frac{n_1-n_2}{n_1+n_2} \\right)^2 \\\\\\\\\n\t\tT&= \\frac{4n_1n_2}{(n_1+n_2)^2}\\\\\\\\\n\t\t&R+T=1\n\t\t\\end{align*}\n\t} \n}\n\n\\begin{note}\\\\\\vspace{0.5cm}\n\tWhen light passes from air $(n_1=1)$ and to glass$(n_2=1.5)$\n\t\\begin{align*}\n\tR&=0.04,\\quad4\\%\\\\\n\tT&=0.96, \\quad96\\%\n\t\\intertext{Most of the light are transmitted.}\n\t\\end{align*}\n\\end{note}\n\\subsection{Reflection and transmission at oblique incidence}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=6cm]{diagram-20211230-crop}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\nSuppose the light is travelling from $-z$ axis.There is a medium at xy plane.Light get reflected and transmitted from the plane.suppose the incident light make an angle $\\theta_I$ with the normal ie z axis.Let $\\omega$ be the frequency of the travelling wave.\\\\\n\\textbf{Incident wave:}\n$$E_I(r,t)=E_{0I}e^{(k_I.r-\\omega t)}$$\n$$B_{I}(r,t)=\\frac{1}{v_1}(k_I\\times E_I)$$\n\\textbf{Reflected wave:}\n$$E_R(r,t)=E_{0R}e^{(k_R.r-\\omega t)}$$\n$$B_{R}(r,t)=\\frac{1}{v_1}(k_R\\times E_R)$$\nWhere $v_1$ be the velocity of first medium.\\\\\n\\textbf{Transmitted wave}\n$$E_T(r,t)=E_{0T}e^{(k_T.r-\\omega t)}$$\n$$B_{T}(r,t)=\\frac{1}{v_2}(k_T\\times E_T)$$\nWhere $v_2$ be the velocity of the second medium.\\\\\nThe frequency of all the waves are same.so we can relate,\\\\\n$$k_Iv_1=k_Rv_1=k_Tv_2$$\n$$\\implies k_I=k_R$$\n$$\\implies k_I=k_R=\\frac{v_2}{v_1}k_T=\\frac{n_1}{n_2}k_T$$\nWhere $n_1$ and $n_2$ are the refractive index of the first and second medium.\\\\\nAt $z=0$ the combined field of electric and magnetic components  are equal\\\\\nie $$E_I+E_R=E_T$$ and \n$$B_I+B_R=B_T$$\nWhich give rise to\\\\\n$$E_I(r,t)=E_{0I}e^{(k_I.r-\\omega t)}+E_R(r,t)=E_{0R}e^{(k_R.r-\\omega t)}=E_T(r,t)=E_{0T}e^{(k_T.r-\\omega t)}$$\nBecause the boundary conditions must hold at all points on the plane and for all time ,these exponential factors must be equal at z=0.Which implies\\\\\n$$k_I\\cdot r=k_R\\cdot r=k_T\\cdot r \\quad at z=0$$\nafter taking the dot product\\\\\n$$x(k_I)_x+y(k_I)_y=x(k_R)_x+y(k_R)_y=x(k_T)_x+y(k_T)_y$$\n\\textbf{if x=0}\n$$(k_I)_y=(k_R)_y=(k_T)_y$$\nsuppose the incident ray lies in the xz plane then $(k_I)_y=0$\\\\\nThen$$(k_R)_y=(k_T)_y=0$$\nThere will be no ray along y axis.\nWhich means that all the rays lies in the same plane.\\\\\nconclusion\\\\\n\\textbf{First law}:The incident ,reflected, and transmitted wavevectors form a plane.(called plane of incidence),which also include the normal to the surface(z axix)\\\\\nHere the common plane is xz plane\\\\\n\\textbf{if y=o}\\\\\n$$(k_I)_x=(k_R)_x=(k_T)_x$$\nWhich implies that \n$$k_I\\sin \\theta_I=k_R\\sin\\theta_R=k_T\\sin \\theta_T$$\nWhere $\\theta_I$ is the angle of incidence,$\\theta_R$ is the angle of reflection,and $\\theta_T$ is called angle of transmission also known as angle of refraction.\\\\\n\\textbf{Second law}\n$$k_I\\sin \\theta_I=k_R\\sin\\theta_R$$\n$$k_I=k_R$$\nThen $$\\theta_I=\\theta_R$$\nThe angle of incidence is the angle of reflection\n$$k_I=k_R\\neq k_T$$\nThen  $$\\frac{\\sin \\theta_I}{\\sin \\theta_T}=\\frac{k_T}{k_R}$$\n\\paragraph{Third law}\n$$\\frac{\\sin \\theta_I}{\\sin \\theta_T}=\\frac{n_1}{n_2}$$\nThis is the \\textbf{law of refraction or Snell's law.}\n\\subsection{Polarization}\nConsider the boundary conditions at the surface\\\\\n$$(i)\\quad \\epsilon_{1}(E_{0_I}+E_{0_R})_z=\\epsilon_{2}(E_{0_T})_z$$\n$$ (ii) \\quad (B_{O_I}+B_{0_R})_z=(B_{0_T})_z$$\n$$(iii) \\quad (E_{0_I}+E_{0_R})_{x,y}=(E_{0_T})_{x,y}$$\n$$(iv) \\quad \\frac{1}{\\mu_{1}}(B_{0_I}+B_{0_R})_{x,y}=\\frac{1}{\\mu_{2}}(B_{0_T})_{x,y}$$\nSuppose the polarization of the incident wave is parallel to the plane of incidenceie in the xz plane.\\\\\nConsider the first boundary condition\\\\\n$$\\epsilon_{1}(-E_{0_I}\\sin \\theta_I+E_{0_R}\\sin \\theta_R)=\\epsilon_{2}(-E_{0_T}\\sin \\theta_T)$$\nSince magnetic field has no z components (ii) add nothing.\\\\\n(iii)equation become\\\\\n$$E_{0_I}\\cos \\theta_I+E_{0_R}\\cos \\theta_R=E_{0_T}\\cos \\theta_T$$\\\\\n(iv) Become\\\\\n$$\\frac{1}{\\mu_{1} v_1}(E_{0_I}-E_{0_R})=\\frac{1}{\\mu_{2} v_2}E_{0_T}$$\nCombining with $\\epsilon_{1}(-E_{0_I}\\sin \\theta_I+E_{0_R}\\sin \\theta_R)=\\epsilon_{2}(-E_{0_T}\\sin \\theta_T)$ and using laws of reflection and refraction,we will get\n$$E_{0_I}-E_{0_R}=\\beta E_{0_T}$$\nWhere $$\\beta= \\frac{\\mu_{1} v_1}{\\mu_{2} v_2}=\\frac{\\mu_{1} n_2}{\\mu_{2}n_1}$$\nEquation $$E_{0_I}\\cos \\theta_I+E_{0_R}\\cos \\theta_R=E_{0_T}\\cos \\theta_T$$\n$$E_{0_I}+E_{0_R}=\\alpha E_{0_T}$$\nWhere $$\\alpha=\\frac{\\cos \\theta_T}{\\cos \\theta_I}$$\\\\\nsolving $E_{0_I}+E_{0_R}=\\alpha E_{0_T}$, \\quad $E_{0_I}-E_{0_R}=\\beta E_{0_T}$ this equation for reflected and transmitted amplitude we obtain\\\\\nAmplitude of reflected wave is\\\\\n$$E_{0_R}=\\frac{\\alpha-\\beta}{\\alpha+\\beta}E_{0_I}$$\nAmplitude of the transmitted wave is\\\\\n$$E_{0_T}=\\left( \\frac{2}{\\alpha+\\beta}\\right)E_{0_I} $$\nThese are known as \\textbf{Fresnel's equations}\\\\\n\\begin{note}\n\tThe transmitted wave is always in phase with the incident one;reflected wave is either in phase if $\\alpha>\\beta$ or 180 out of phase if $\\alpha< \\beta$\n\\end{note}\nThe amplitude of the transmitted and reflected wave depends on the angle of incidence because $\\alpha$ is a function of $\\theta_I$\n$$\\alpha=\\frac{\\sqrt{1-\\sin ^{2} \\theta_{T}}}{\\cos \\theta_{I}}=\\frac{\\sqrt{1-\\left[\\left(n_{1} / n_{2}\\right) \\sin \\theta_{I}\\right]^{2}}}{\\cos \\theta_{I}}$$\n\\paragraph{Brewster's angle}\nAt normal incidenace most of the light are transmitted.At $\\theta_I=90^{\\circ}$ the wave is totally reflected.Between these two angle there is some angle called Brewster's angle at which the reflected ray is completely disappered.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=6cm,width=8cm]{diagram-20211216-crop}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\nThis occurs when $\\alpha=\\beta$\\\\\n$$\\sin ^{2} \\theta_{B}=\\frac{1-\\beta^{2}}{\\left(n_{1} / n_{2}\\right)^{2}-\\beta^{2}}$$\nFor the typical case $\\mu_{1}\\approx\\mu_{2}$ so $\\beta \\approx n_2, \\sin^2 \\theta_{B}\\approx \\frac{\\beta^2}{1+\\beta^2}$ and hence\\\\\n$$\\tan \\theta_{B} \\approx \\frac{n_2}{n_1}$$\n\\begin{note}\n\tIf the incident light is unpolarized the reflected ray will be totally polarized parallel to the interface at Brewster's angle.In the above condition we use plane polarized light as incident light,that is why there is no reflected rays.\n\\end{note}\n\\textbf{ Malus law }\\\\\n\t\\textbf{The power per unit area}\n\\begin{note}\n\t\\begin{enumerate}\n\t\t\\item Incident intensity\\\\\n\t\t$$I_I=\\frac{1}{2}\\epsilon_{1}v_1E_{0_I}^2 \\cos \\theta_{I}$$\n\t\t\\item Reflected intencity\n\t\t$$I_R=\\frac{1}{2}\\epsilon_{1}v_1E_{0_R}^2 \\cos \\theta_{R}$$\n\t\t\\item Transmitted intencity\n\t\t$$I_T=\\frac{1}{2}\\epsilon_{2}v_2E_{0_T}^2 \\cos \\theta_{T}$$\n\t\\end{enumerate}\n\\end{note}\n\\textbf{Reflection and transmission coefficient}\n$$R=\\frac{I_R}{I_I}=\\left( \\frac{E_{0_R}}{E_{O_I}}\\right) =\\left( \\frac{\\alpha-\\beta}{\\alpha+\\beta}\\right) ^2$$\n$$T=\\frac{I_T}{I_I}=\\frac{\\epsilon_{2}v_2}{\\epsilon_{1}v_1}\\left( \\frac{E_{0_T}}{E_{0I}}\\right) \\frac{\\cos \\theta_{T}}{\\cos \\theta_{I}}=\\alpha \\beta\\left( \\frac{2}{\\alpha+\\beta} \\right) ^2$$\n\\section{Elctromagnetic waves in conductors}\nWhen we are talking about wave propagation through a vacuum or through a dielctric mterial we restricted our assumption that $J_f$ and $\\rho_f$ are zeros.But in the case of conductors we donnot independently control the flow of charge, and in general $J_f$ is not certainly zero.\\\\\nAccording to ohm's law the current density in a conductor is proportional to the electric field.\\\\\n$$J_f=\\sigma E$$\nMaxwell' equation for a linear media.\\\\\n(i)\\quad $\\nabla$ $\\cdot$ E=$\\frac{\\rho_f}{\\epsilon}$\\\\\n(ii) \\quad $\\nabla \\cdot B=0$\\\\\n(iii)\\quad $\\nabla$ $\\times$ =-$\\frac{\\partial B}{\\partial t}$\\\\\n(iv) \\quad $\\nabla \\times B=\\mu \\sigma E+\\mu \\epsilon \\frac{\\partial E}{\\partial t}$\\\\\nContinuity equation ($\\nabla \\cdot J_f=\\frac{\\partial \\rho_f}{\\partial t}$) with Ohm's law The gauss's law become\\\\\n$$\\frac{\\partial \\rho_f}{\\partial t}=-\\sigma (\\nabla \\cdot E)=-\\frac{\\sigma}{\\epsilon}\\rho_f$$\n$$\\rho_f(t)=e^{\\frac{-\\sigma}{\\epsilon}t} \\rho_f(0)$$\nwhich means that if you put some charges on a conductor,it will flow out of the edges.Donot mind this transient behaviour.consider the time up to which the accumulated free charges to disappear.From then $\\rho_f=0$\\\\\nNow maxwell's quations become\\\\\n(i)\\quad $\\nabla$ $\\cdot$ E=0\\\\\n(ii) \\quad $\\nabla \\cdot B=0$\\\\\n(iii)\\quad $\\nabla$ $\\times$ =-$\\frac{\\partial B}{\\partial t}$\\\\\n(iv) \\quad $\\nabla \\times B=\\mu \\sigma E+\\mu \\epsilon \\frac{\\partial E}{\\partial t}$\\\\\nApplying curl to (iii) and (iv) we will get modified wave equation for E and B.\\\\\n$$\\nabla^{2} \\mathbf{E}=\\mu \\epsilon \\frac{\\partial^{2} \\mathbf{E}}{\\partial t^{2}}+\\mu \\sigma \\frac{\\partial \\mathbf{E}}{\\partial t}, \\quad \\nabla^{2} \\mathbf{B}=\\mu \\epsilon \\frac{\\partial^{2} \\mathbf{B}}{\\partial t^{2}}+\\mu \\sigma \\frac{\\partial \\mathbf{B}}{\\partial t}$$\nThese equations still admit plane-wave solutions,\n$$\n\\tilde{\\mathbf{E}}(z, t)=\\tilde{\\mathbf{E}}_{0} e^{i(k z-\\omega t)}, \\quad \\tilde{\\mathbf{B}}(z, t)=\\tilde{\\mathbf{B}}_{0} e^{i(\\tilde{k} z-\\omega t)},\n$$\nbut this time the \"wave number\" $\\tilde{k}$ is complex:\n$$\n\\tilde{k}^{2}=\\mu \\epsilon \\omega^{2}+i \\mu \\sigma \\omega,\n$$\n$$\\bar{k}=k_{real}+ik_{img}$$\nwhere\n$$\nk_{real} \\equiv \\omega \\sqrt{\\frac{\\epsilon \\mu}{2}}\\left[\\sqrt{1+\\left(\\frac{\\sigma}{\\epsilon \\omega}\\right)^{2}}+1\\right]^{1 / 2}\n$$\nand \n$$k_{img} \\equiv \\omega \\sqrt{\\frac{\\epsilon \\mu}{2}}\\left[\\sqrt{1+\\left(\\frac{\\sigma}{\\epsilon \\omega}\\right)^{2}}-1\\right]^{1 / 2}$$\nNow\\\\\n$$\\tilde{\\mathbf{E}}(z, t)=\\tilde{\\mathbf{E}}_{0} e^{-k_{real} z} e^{i(k_{img} z-\\omega t)}, \\quad \\tilde{\\mathbf{B}}(z, t)=\\tilde{\\mathbf{B}}_{0} e^{-k_{real}z} e^{i(k_{imag} z-\\omega t)}$$\n\\paragraph{Skin depth}\nThe distance it takes to reduce the amplitude by a factor of $1 / e$ (about a third) is called the skin depth:\n$$\nd \\equiv \\frac{1}{\\kappa}\n$$\nit is a measure of how far the wave penetrates into the conductor. Meanwhile, the real part of $k$ determines the wavelength, the propagation speed, and the index of refraction, in the usual way:\n$$\n\\lambda=\\frac{2 \\pi}{k}, \\quad v=\\frac{\\omega}{k}, \\quad n=\\frac{c k}{\\omega} .\n$$\n\\subsection{ Skin depth in a poor conductor:}\nFor poor conductor\n$$\n\\begin{gathered}\n\\sigma \\ll \\omega \\epsilon \\\\\n\\kappa \\equiv \\omega \\sqrt{\\frac{\\epsilon \\mu}{2}}\\left[\\sqrt{1+\\left(\\frac{\\sigma}{\\epsilon \\omega}\\right)^{2}}-1\\right]^{1 / 2} \\\\\n\\approx \\omega \\sqrt{\\frac{\\epsilon \\mu}{2}}\\left[1+\\frac{1}{2}\\left(\\frac{\\sigma}{\\epsilon \\omega}\\right)^{2}-1\\right]^{1 / 2}\n\\end{gathered}\n$$\nThen\n$$\n\\kappa \\approx \\omega \\sqrt{\\frac{\\epsilon \\mu}{2} \\frac{1}{\\sqrt{2}} \\frac{\\sigma}{\\epsilon \\omega}}=\\frac{\\sigma}{2} \\sqrt{\\frac{\\mu}{\\epsilon}}\n$$\nSo\n$$\nd=\\frac{1}{\\kappa} \\cong \\frac{2}{\\sigma} \\sqrt{\\frac{\\epsilon}{\\mu}}\n$$\n\\subsection{ Skin depth in a good conductor:}\nFor good conductor\n$$\n\\sigma \\gg \\omega \\epsilon\n$$\n$$\n\\begin{aligned}\n\\kappa & \\equiv \\omega \\sqrt{\\frac{\\epsilon \\mu}{2}}\\left[\\sqrt{\\left.1+\\left(\\frac{\\sigma}{\\epsilon \\omega}\\right)^{2}-1\\right]^{1 / 2}}\\right.\\\\\n& \\approx \\omega \\sqrt{\\frac{\\epsilon \\mu}{2}\\left(\\frac{\\sigma}{\\epsilon \\omega}\\right)^{1 / 2}} \\approx \\sqrt{\\frac{\\mu \\sigma \\omega}{2}}\n\\end{aligned}\n$$\nSo for a good conductor\n$$\nd \\cong \\sqrt{\\frac{2}{\\mu \\sigma \\omega}}\n$$\nFor good conductor as $\\sigma \\gg \\omega \\epsilon$ so, you can see\n$$\nk \\cong \\kappa\n$$\nor\n$$\n\\lambda=\\frac{2 \\pi}{k} \\cong \\frac{2 \\pi}{\\kappa}=2 \\pi d, \\text { or } d=\\frac{\\lambda}{2 \\pi}\n$$\n\\textbf{Phase shift}\\\\\nLike any complex number, $\\tilde{k}$ can be expressed in terms of its modulus and phase:\n$$\n\\tilde{k}=K e^{i \\phi},\n$$\n$$\\begin{gathered}\nK \\equiv|\\tilde{k}|=\\sqrt{k_{real}^{2}+k_{img}^{2}}=\\omega \\sqrt{\\epsilon \\mu \\sqrt{1+\\left(\\frac{\\sigma}{\\epsilon \\omega}\\right)^{2}}} \\\\\n\\phi \\equiv \\tan ^{-1}(k_{img} / k_{real})\n\\end{gathered}$$\n The complex amplitudes $\\tilde{E}_{0}=E_{0} e^{i \\delta_{E}}$ and $\\tilde{B}_{0}=B_{0} e^{i \\delta_{B}}$ are related by\n$$\nB_{0} e^{i \\delta_{B}}=\\frac{K e^{i \\phi}}{\\omega} E_{0} e^{i \\delta_{E}}\n$$\nEvidently the electric and magnetic fields are no longer in phase; in fact,\n$$\n\\delta_{B}-\\delta_{E}=\\phi\n$$\nthe magnetic field lags behind the electric fleld. Meanwhile, the (real) amplitudes of $\\mathbf{E}$ and B are related by\n$$\n\\frac{B_{0}}{E_{0}}=\\frac{K}{\\omega}=\\sqrt{\\epsilon \\mu \\sqrt{1+\\left(\\frac{\\sigma}{\\epsilon \\omega}\\right)^{2}}} .\n$$\nThe (real) electric and magnetic fields are, finally,\n$$\n\\left.\\frac{\\mathbf{E}(z, t)=E_{0} e^{-\\kappa z} \\cos \\left(k z-\\omega t+\\delta_{E}\\right) \\hat{\\mathbf{x}},}{\\mathbf{B}(z, t)=B_{0} e^{-\\kappa z} \\cos \\left(k z-\\omega t+\\delta_{E}+\\phi\\right) \\hat{\\mathbf{y}}}\\right\\}$$\n\\begin{exercise}\n (a) Find the skin depth of pure water. You are given that for pure water conductivity $\\sigma=1 /\\left(2.5 \\times 10^{5}\\right)$, dielectric constant $k=80.1$ and $\\mu \\approx \\mu_{0}$.\\\\\n (b) Find the skin depth (in nanometers) for a typical metal whose conductivity $\\sigma \\approx 10^{7}$, the frequency $\\omega \\approx 10^{15}$ with $\\epsilon \\approx \\epsilon_{0}$ and $\\mu \\approx \\mu_{0}$.\n\\end{exercise}\n\\begin{answer}\n (a) Conductivity shows that the water is a poor conductor. Hence we will take approximation $d=\\frac{1}{\\kappa} \\cong$ $\\frac{2}{\\sigma} \\sqrt{\\frac{\\epsilon}{\\mu}} .$\n$$\nd=(2)\\left(2.5 \\times 10^{5}\\right) \\sqrt{\\frac{(80.1)\\left(8.85 \\times 10^{-12}\\right)}{4 \\pi \\times 10^{-7}}}=1.19 \\times 10^{4} \\mathrm{~m}\n$$\n(b) We have proved that for good conductor $d \\approx \\sqrt{\\frac{2}{\\mu \\sigma \\omega}}$. Put the values to get\n$$\nd=\\frac{1}{8 \\times 10^{7}}=1.3 \\times 10^{-8}=13 \\mathrm{~nm}\n$$\nSo the fields do not penetrate far into a metal\t\n\\end{answer}\n\\subsection{Reflection at a conducting surface}\nBoundary conditions used to solve em waves at the conductor involves $\\rho_f$ and $K_f$\\\\\n(i) $\\epsilon_{1} E_{1}^{\\perp}-\\epsilon_{2} E_{2}^{\\perp}=\\sigma_{f}$,\\\\\n(iii) $\\mathbf{E}_{1}^{\\|}-\\mathbf{E}_{2}^{\\|}=0$,\\\\\n(ii) $B_{1}^{\\perp}-B_{2}^{\\perp}=0$,\\\\\n(iv) $\\frac{1}{\\mu_{1}} \\mathbf{B}_{1}^{\\|}-\\frac{1}{\\mu_{2}} \\mathbf{B}_{2}^{\\|}=\\mathbf{K}_{f} \\times \\hat{\\mathbf{n}}$,\\\\\nSuppose that xy plane forms a boundary between a non conducting non linear medium 1 and a conductor 2.A monochromatic plane wave travelling in the z direction and polarized in the x direction ,approches from the left as shown in figure.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=6cm,width=8cm]{em wave}\n\t\\caption{Reflection and Transmission at Normal incidence}\n\t\\label{Reflection and Transmission at Normal incidence}\n\\end{figure}\n\\textbf{Incident wave:}\n$$\\tilde{\\mathbf{E}}_{I}(z, t)=\\tilde{E}_{0_{I}} e^{i\\left(k_{1} z-\\omega t\\right)} \\hat{\\mathbf{x}}$$\n$$ \\quad \\tilde{\\mathbf{B}}_{I}(z, t)=\\frac{1}{v_{1}} \\tilde{E}_{0_{I}} e^{i\\left(k_{1} z-\\omega t\\right)} \\hat{\\mathbf{y}}$$\n\\textbf{Reflected wave:}\n$$\\tilde{\\mathbf{E}}_{R}(z, t)=\\tilde{E}_{0_{R}} e^{i\\left(-k_{1} z-\\omega t\\right)} \\hat{\\mathbf{x}}$$\n$$ \\quad \\tilde{\\mathbf{B}}_{R}(z, t)=-\\frac{1}{v_{1}} \\tilde{E}_{0_{R}} e^{i\\left(-k_{1} z-\\omega t\\right)} \\hat{\\mathbf{y}}$$\n\\textbf{Transmitted wave:}\n$$\\tilde{\\mathbf{E}}_{T}(z, t)=\\tilde{E}_{0_{T}} e^{i\\left(\\tilde{k}_{2} z-\\omega t\\right)} \\hat{\\mathbf{x}}$$\n$$ \\quad \\tilde{\\mathbf{B}}_{T}(z, t)=\\frac{\\tilde{k}_{2}}{\\omega} \\tilde{E}_{0_{T}} e^{i\\left(\\tilde{k}_{2} z-\\omega t\\right)} \\hat{\\mathbf{y}}$$\nTransmitted wave will get attinuated while entering the conducting material.\\\\\nNow consider the boundary conditions one by one.\\\\\n(i) Gives $\\sigma_{f}=0$ because there will be no perpendicular component of elctric field in two media($E^{\\perp}$)=0\\\\\n(ii)yields $B^{\\perp}=0$\\\\\n(iii) gives $$\\tilde{E}_{0_{1}}+\\tilde{E}_{0_{R}}=\\tilde{E}_{0_{\\tau}}$$\n(iv) gives $$\\begin{gathered}\n\\frac{1}{\\mu_{1} v_{1}}\\left(\\tilde{E}_{0_{l}}-\\tilde{E}_{0_{R}}\\right)-\\frac{\\tilde{k}_{2}}{\\mu_{2} \\omega} \\tilde{E}_{0_{T}}=0, \\\\\n\\tilde{E}_{0_{I}}-\\tilde{E}_{0_{R}}=\\tilde{\\beta} \\tilde{E}_{0_{T}}, \\\\\n\\tilde{\\beta} \\equiv \\frac{\\mu_{1} v_{1}}{\\mu_{2} \\omega} \\tilde{k}_{2} .\n\\end{gathered}$$\nIt follows that\n$$\n\\tilde{E}_{0_{R}}=\\left(\\frac{1-\\tilde{\\beta}}{1+\\tilde{\\beta}}\\right) \\tilde{E}_{0_{l}}, \\quad \\tilde{E}_{0_{T}}=\\left(\\frac{2}{1+\\tilde{\\beta}}\\right) \\tilde{E}_{0_{l}} .\n$$\nFor a perfect conductor ($\\sigma=\\inf$),$k_2=\\infty$ so $\\beta$ is finite and \\\\\n$$E_{0_R}=-E_{0_I}, \\quad E_{0_T}=0$$\nIn this case the wave is totally reflected with a $180^{\\circ}$ phase shift.That is why excellent conductors make good mirrors.\n\\section{Guided waves}\nUntill now we have dealt with plane wave of infinite extent;Now we consider the em waves confines to the interior of a hollow pipe or wave guide.We will assume the wave guide is perfect conductor. so that E=0 and B=0 inside the material itself.Hence the boundary conditions at the boundary wall are\\\\\n$$ (i) \\quad  E^{\\parallel}=0$$ \n$$ (ii) \\quad B^{\\perp}=0$$\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm,width=8cm]{wave guide 2-crop}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\nLet us take the medium is restricted by $x$ and $y$ and the wave is propagating along $z$ direction.So E and B has the generic form.\\\\\n$$(i) \\tilde{\\mathbf{E}}(x, y, z, t)=\\tilde{\\mathbf{E}}_{0}(x, y) e^{i(k z-\\omega t)}$$\n$$(ii) \\tilde{\\mathbf{B}}(x, y, z, t)=\\tilde{\\mathbf{B}}_{0}(x, y) e^{i(k z-\\omega t)}$$\nThe maxwell's equation in the interior of the waveguide\\\\\n$$(i) \\boldsymbol{\\nabla} \\cdot \\mathbf{E}=0$$\n$$(ii)\\boldsymbol{\\nabla} \\cdot \\mathbf{B}=0$$\n$$(iii) \\nabla \\times \\mathbf{E}=-\\frac{\\partial \\mathbf{B}}{\\partial t}$$\n$$(iv) \\boldsymbol{\\nabla} \\times \\mathbf{B}=\\frac{1}{c^{2}} \\frac{\\partial \\mathbf{E}}{\\partial t}$$\n Boundary conditions and the Maxwell's equations gives \\\\\n$$ (i) \\left[\\frac{\\partial^{2}}{\\partial x^{2}}+\\frac{\\partial^{2}}{\\partial y^{2}}+(\\omega / c)^{2}-k^{2}\\right] E_{z}=0$$ and\\\\\n$$ (ii) \\left[\\frac{\\partial^{2}}{\\partial x^{2}}+\\frac{\\partial^{2}}{\\partial y^{2}}+(\\omega / c)^{2}-k^{2}\\right] B_{z}=0$$\nIf $E_{z}=0$, we call these TE (transverse electric\") waves; if $B_{z}=0$, they are called TM (\"transverse magnetic\") waves; if both $\\mathrm{E}_{\\mathrm{z}}=0$ and $\\mathrm{B}_{\\mathrm{z}}=0$, we call them TEM waves. You can prove that TEM waves can't occur in hollow rectangular wave guide.\\\\\n\\begin{center}\n TE, mode $\\Rightarrow F_{z}=0 \\quad B_{z}=$ exist\\\\\n$\\mathrm{TM}$ mode $\\Rightarrow E_{z}=$ exist $B_{z}=0$\\\\\nTEM mode $\\Rightarrow E_{z}=B_{z}=0$\\\\\t\n\\end{center}\n\\subsection{ TE Waves in a Rectangular Wave Guide}\nWe need the solution of\n$$\\text { (ii) }\\left[\\frac{\\partial^{2}}{\\partial x^{2}}+\\frac{\\partial^{2}}{\\partial y^{2}}+(\\omega / c)^{2}-k^{2}\\right] B_{z}=0$$\nTake $$\nB_{z}(x, y)=X(x) Y(y)\n$$\nand do the separation of variable. You get the solution\n$$\nB_{z}=B_{0} \\cos (m \\pi x / a) \\cos (n \\pi y / b)\n$$\nwith the dispersion relation\n$$k=\\sqrt{(\\omega / c)^{2}-\\pi^{2}\\left[(m / a)^{2}+(n / b)^{2}\\right]}$$\nDefine\n$$\n\\omega_{m n}=c \\pi \\sqrt{(m / a)^{2}+(n / b)^{2}}\n$$\nNow you see if\n$$\n\\omega<\\omega_{m n}\n$$\nthe wave number is imaginary, and instead of a traveling wave we have exponentially attenuated wave which will rapidly absorbed in the medium. $\\omega_{m n}$ is called the cut off frequency for a particular mode $T E_{m n}$. You should remember that $\\omega$ is angular frequency, not frequency.\\\\\nIn terms of frequency\n$$\n\\nu_{m n}=\\frac{c}{2} \\sqrt{\\left(\\frac{m}{a}\\right)^{2}+\\left(\\frac{n}{b}\\right)^{2}}\n$$\nThe lowest mode is TE $_{10}$ (usually among $a$ and $b$ the larger is taken to be $a$.\n$$\\omega_{10}=c \\pi / a$$\n\\textbf{Group and phase velocity}\\\\\nPhase velocity is greater than C.\\\\\n$$v_{p}=\\frac{\\omega}{k}=\\frac{c}{\\sqrt{1-\\left(\\omega_{m n} / \\omega\\right)^{2}}}$$\nThe group velocity\n$$\nv_{g}=\\frac{1}{d k / d \\omega}=c \\sqrt{1-\\left(\\omega_{m n} / \\omega\\right)^{2}}<c\n$$\n\\subsection{ TM Waves in a Rectangular Wave Guide}\n$$\\left[\\frac{\\partial^{2}}{\\partial x^{2}}+\\frac{\\partial^{2}}{\\partial y^{2}}+(\\omega / c)^{2}-k^{2}\\right] E_{z}=0$$\nHas the soltion of the form.\n$$E_{z}=E_{0} \\sin \\left(\\frac{m \\pi x}{a}\\right) \\sin \\left(\\frac{n \\pi y}{b}\\right)$$\nif either of the $m$ and $n$ is zero the solution itself is zero. So the lowest frequency mode is for TM wave in rectangular wave guide is $T E_{11}$.\\\\\n\\section{Resonant cavity}\nResonant cavity produced by closing off the two ends of a rectangular wave guide, at $z=0$ and at $z=d$, making a perfectly conducting empty box.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm,width=8cm]{resonant-crop}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\nWe can prove that the cut off frequencies for both $\\mathrm{TE}$ and TM modes in a resonance cavity are given by\n$$\\begin{gathered}\n\\omega_{l m n}=c \\pi \\sqrt{(l / d)^{2}+(m / a)^{2}+(n / b)^{2}} \\\\\n\\nu_{l m n}=\\frac{c}{2} \\sqrt{(l / d)^{2}+(m / a)^{2}+(n / b)^{2}}\n\\end{gathered}$$\n\\begin{exercise}\n\t What should be the 3rd dimension of a cavity of cross section $1 \\mathrm{~cm} \\times 1 \\mathrm{~cm}$ which operates at $T E_{103}$ mode at $24 \\mathrm{GHz} ? ?$\n\\end{exercise}\n\\begin{answer}\nSolution: $l=1, m=0, n=3$. use\n$$\n\\nu_{103}=24 \\times 10^{9} ; \\quad a=0.01, b=0.01, c=?\n$$\nuse the formula of $\\nu_{l m n}$ to get\n$$\\nu_{l m n}=\\frac{c}{2} \\sqrt{(l / d)^{2}+(m / a)^{2}+(n / b)^{2}}$$\n$$\n\\left(\\frac{24 \\times 2 \\times 10^{9}}{3 \\times 10^{8}}\\right)^{2}=\\left(\\frac{1}{0.01}\\right)^{2}+0+\\left(\\frac{3}{c}\\right)^{2}\n$$\n$$c=0.02$$\t\n\\end{answer}\n\\section{ Dielectric inserted into waveguide}\nWhen there is a dielectric / magnetic medium inside of a dielectric instead of vacuum, just replace $c$ by $\\frac{1}{\\sqrt{\\epsilon \\mu}}$\n$$\\nu_{m n}=\\frac{1}{2 \\sqrt{\\epsilon \\mu}} \\sqrt{\\left(\\frac{m}{a}\\right)^{2}+\\left(\\frac{n}{b}\\right)^{2}}$$\nFor most of the material $\\mu \\approx \\mu_{0}$, so then\n$$\n\\begin{aligned}\n\\nu_{m n} &=\\frac{1}{2 \\sqrt{\\epsilon_{r}} \\epsilon_{0} \\mu_{0}} \\sqrt{\\left(\\frac{m}{a}\\right)^{2}+\\left(\\frac{n}{b}\\right)^{2}} \\\\\n&=\\frac{c}{2 \\sqrt{\\epsilon_{r}}} \\sqrt{\\left(\\frac{m}{a}\\right)^{2}+\\left(\\frac{n}{b}\\right)^{2}}\n\\end{aligned}\n$$\n\\begin{exercise}\n For a air filled wave guide. the cut off frequency $T E_{0}=1.8756 \\mathrm{GHz}$. What will be the cut off frequency if one dielectric of relative permeability $\\epsilon=9 \\epsilon_{0}$ is inserted in the dielectric?\n\\end{exercise}\n\\begin{answer}\n you have already derived the formula for cut off frequency for the dielectric inserted wave guide. The ans is\n$$\n\\nu_{m n}^{\\text {dielectric }}=\\nu_{m n}^{\\text {vacuum }} / \\sqrt{\\epsilon_{r}}=1.8756 / 3 \\mathrm{GHz}\n$$\t\n\\end{answer}\n\\newpage\n\\begin{abox}\n\tPractice set 1\n\t\\end{abox}\n\\begin{enumerate}\n\\begin{minipage}{\\textwidth}\n\t\\item A plane electromagnetic wave is propagating in a lossless dielectric. The electric field is given by\n\t$$\n\t\\vec{E}(x, y, z, t)=E_{0}(\\hat{x}+A \\hat{z}) \\exp \\left[i k_{0}\\{-c t+(x+\\sqrt{3} z)\\}\\right]\n\t$$\n\twhere $c$ is the speed of light in vacuum, $E_{0}, A$ and $k_{0}$ are constant and $\\hat{x}$ and $\\hat{z}$ are unit vectors along the $x$-and $z$-axes. The relative dielectric constant of the medium $\\varepsilon_{r}$ and the constant $A$ are\n\t\\exyear{NET JUNE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]$\\varepsilon_{r}=4$ and $A=-\\frac{1}{\\sqrt{3}}$\n\t\\task[\\textbf{B.}]$\\varepsilon_{r}=4$ and $A=+\\frac{1}{\\sqrt{3}}$\n\t\\task[\\textbf{C.}]$\\varepsilon_{r}=4$ and $A=\\sqrt{3}$\n\t\\task[\\textbf{D.}]$\\varepsilon_{r}=4$ and $A=-\\sqrt{3}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The magnetic field of the $T E_{11}$ mode of a rectangular waveguide of dimensions $a \\times b$ as shown in the figure is given by $H_{z}=H_{0} \\cos (0.3 \\pi x) \\cos (0.4 \\pi y)$, where $x$ and $y$ are in cm\n\t\\exyear{NET JUNE 2011}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20211011(7)-crop}\n\t\\end{figure}\n\\end{minipage}\n$\\text { A. The dimensions of the waveguide are }$\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $a=3.33 \\mathrm{~cm}, b=2.50 \\mathrm{~cm}$\n\t\\task[\\textbf{B.}]$a=0.40 \\mathrm{~cm}, b=0.30 \\mathrm{~cm}$\n\t\\task[\\textbf{C.}]$a=0.80 \\mathrm{~cm}, b=0.60 \\mathrm{~cm}$\n\t\\task[\\textbf{D.}] $a=1.66 \\mathrm{~cm}, b=1.25 \\mathrm{~cm}$\n\\end{tasks}\n\n\\begin{minipage}{\\textwidth}\n\t\\item An electromagnetic wave is incident on a water-air interface. The phase of the perpendicular component of the electric field, $E_{\\perp}$, of the reflected wave into the water is found to remain the same for all angles of incidence. The phase of the magnetic field $H$\n\t\\exyear{NET JUNE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]does not change\n\t\\task[\\textbf{B.}]changes by $3 \\pi / 2$\n\t\\task[\\textbf{C.}]changes by $\\pi / 2$\n\t\\task[\\textbf{D.}]changes by $\\pi$\n\\end{tasks}\n\n\\begin{minipage}{\\textwidth}\n\t\\item A current $I$ is created by a narrow beam of protons moving in vacuum with constant velocity $\\vec{u}$. The direction and magnitude, respectively of the Poynting vector $\\vec{S}$ outside the beam at a radial distance $r$ (much larger than the width of the beam) from the axis, are\n\t\\exyear{NET JUNE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\vec{S} \\perp \\vec{u}$ and $|\\vec{S}|=\\frac{I^{2}}{4 \\pi^{2} \\varepsilon_{0}|\\vec{u}| r^{2}}$\n\t\\task[\\textbf{B.}]$\\vec{S} \\|(-\\vec{u})$ and $|\\vec{S}|=\\frac{I^{2}}{4 \\pi^{2} \\varepsilon_{0}|\\vec{u}| r^{4}}$\n\t\\task[\\textbf{C.}]$\\vec{S} \\| \\vec{u}$ and $|\\vec{S}|=\\frac{I^{2}}{4 \\pi^{2} \\varepsilon_{0}|\\vec{u}| r^{2}}$\n\t\\task[\\textbf{D.}]$\\vec{S} \\| \\vec{u}$ and $|\\vec{S}|=\\frac{I^{2}}{4 \\pi^{2} \\varepsilon_{0}|\\vec{u}| r^{4}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The electric field of an electromagnetic wave is given by\n\t$$\n\t\\vec{E}=E_{0} \\cos [\\pi(0.3 x+0.4 y-1000 t)] \\hat{k} .\n\t$$\n\tThe associated magnetic field $\\vec{B}$ is\n\t\\exyear{NET DEC 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $10^{-3} E_{0} \\cos [\\pi(0.3 x+0.4 y-1000 t)] \\hat{k}$\n\t\\task[\\textbf{B.}]$10^{-4} E_{0} \\cos [\\pi(0.3 x+0.4 y-1000 t)](4 \\hat{i}-3 \\hat{j})$\n\t\\task[\\textbf{C.}]$E_{0} \\cos [\\pi(0.3 x+0.4 y-1000 t)](0.3 \\hat{i}+0.4 \\hat{j})$\n\t\\task[\\textbf{D.}]$10^{2} E_{0} \\cos [\\pi(0.3 x+0.4 y-1000 t)](3 \\hat{i}+4 \\hat{j})$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A beam of light of frequency $\\omega$ is reflected from a dielectric-metal interface at normal incidence. The refractive index of the dielectric medium is $n$ and that of the metal is $n_{2}=n(1+i \\rho)$. If the beam is polarised parallel to the interface, then the phase change experienced by the light upon reflection is\n\t\\exyear{NET JUNE 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\tan (2 / \\rho)$ \n\t\\task[\\textbf{B.}]$\\tan ^{-1}(1 / \\rho)$\n\t\\task[\\textbf{C.}]$\\tan ^{-1}(2 / \\rho)$\n\t\\task[\\textbf{D.}]$\\tan ^{-1}(2 \\rho)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item An electromagnetically-shielded room is designed so that at a frequency $\\omega=10^{7} \\mathrm{rad} / \\mathrm{s}$ the intensity of the external radiation that penetrates the room is $1 \\%$ of the incident radiation. If $\\sigma=\\frac{1}{2 \\pi} \\times 10^{6}(\\Omega m)^{-1}$ is the conductivity of the shielding material, its minimum thickness should be (given that $\\ln 10=2.3$ )\n\t\\exyear{NET JUNE 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $4.60 \\mathrm{~mm}$\n\t\\task[\\textbf{B.}]$2.30 \\mathrm{~mm}$\n\t\\task[\\textbf{C.}] $0.23 \\mathrm{~mm}$\n\t\\task[\\textbf{D.}]$0.46 \\mathrm{~mm}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A plane electromagnetic wave incident normally on the surface of a material is partially reflected. Measurements on the standing wave in the region in front of the interface such that the ratio of the electric field amplitude at the maxima and the minima is 5 . The ratio of the reflected intensity to the incident intensity is\n\t\\exyear{NET JUNE 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $4 / 9$\n\t\\task[\\textbf{B.}] $2 / 3$\n\t\\task[\\textbf{C.}]$2 / 5$\n\t\\task[\\textbf{D.}]$1 / 5$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A Plane electromagnetic wave is travelling along the positive $z$-direction. The maximum electric field along the $x$ - direction is $10 \\mathrm{~V} / \\mathrm{m}$. The approximate maximum values of the power per unit area and the magnetic induction $B$, respectively, are\n\t\\exyear{NET JUNE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $3.3 \\times 10^{-7}$ watts $/ \\mathrm{m}^{2}$ and 10 tesla\n\t\\task[\\textbf{B.}]$3.3 \\times 10^{-7}$ watts $/ \\mathrm{m}^{2}$ and $3.3 \\times 10^{-8}$ tesla\n\t\\task[\\textbf{C.}]$0.265$ watts / m $^{2}$ and 10 tesla\n\t\\task[\\textbf{D.}]$0.265$ watts $/ m^{2}$ and $3.3 \\times 10^{-8}$ tesla\t\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider a rectangular wave guide with transverse dimensions $2 m \\times 1 m$ driven with an angular frequency $\\omega=10^{9} \\mathrm{rad} / \\mathrm{s}$. Which transverse electric $(T E)$ modes will propagate in this wave guide?\n\t\\exyear{NET JUNE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $T E_{10}, T E_{01}$ and $T E_{20}$\n\t\\task[\\textbf{B.}]$T E_{01}, T E_{11}$ and $T E_{20}$\n\t\\task[\\textbf{C.}]$T E_{01}, T E_{10}$ and $T E_{11}$\n\t\\task[\\textbf{D.}]$T E_{01}, T E_{10}$ and $T E_{22}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The electric and magnetic fields in the charge free region $z>0$ are given by\n\t$$\n\t\\begin{aligned}\n\t&\\vec{E}(\\vec{r}, t)=E_{0} e^{-k_{1} z} \\cos \\left(k_{2} x-\\omega t\\right) \\hat{j} \\\\\n\t&\\vec{B}(\\vec{r}, t)=\\frac{E_{0}}{\\omega} e^{-k_{1} z}\\left[k_{1} \\sin \\left(k_{2} x-\\omega t\\right) \\hat{i}+k_{2} \\cos \\left(k_{2} x-\\omega t\\right) \\hat{k}\\right]\n\t\\end{aligned}\n\t$$\n\twhere $\\omega, k_{1}$ and $k_{2}$ are positive constants. The average energy flow in the $x$-direction is\n\t\\exyear{NET JUNE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{E_{0}^{2} k_{2}}{2 \\mu_{0} \\omega} e^{-2 k_{1} z}$\n\t\\task[\\textbf{B.}]$\\frac{E_{0}^{2} k_{2}}{\\mu_{0} \\omega} e^{-2 k_{1} z}$\n\t\\task[\\textbf{C.}]$\\frac{E_{0}^{2} k_{1}}{2 \\mu_{0} \\omega} e^{-2 k_{1} z}$\n\t\\task[\\textbf{D.}]$\\frac{1}{2} c \\in_{0} E_{0}^{2} e^{-2 k_{1} z}$\n\\end{tasks}\n\n\\begin{minipage}{\\textwidth}\n\t\\item A waveguide has a square cross-section of side $2 a$. For the $T M$ modes of wave vector $k$, the transverse electromagnetic modes are obtained in terms of a function $\\psi(x, y)$ which obeys the equation\n\t$$\n\t\\left[\\frac{\\partial^{2}}{\\partial x^{2}}+\\frac{\\partial^{2}}{\\partial y^{2}}+\\left(\\frac{\\omega^{2}}{c^{2}}-k^{2}\\right)\\right] \\psi(x, y)=0\n\t$$\n\twith the boundary condition $\\psi(\\pm a, y)=\\psi(x, \\pm a)=0$. The frequency $\\omega$ of the lowest mode is given by\n\t\\exyear{NET JUNE 2016}\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}] $\\omega^{2}=c^{2}\\left(k^{2}+\\frac{4 \\pi^{2}}{a^{2}}\\right)$\n\t\\task[\\textbf{B.}]$\\omega^{2}=c^{2}\\left(k^{2}+\\frac{\\pi^{2}}{a^{2}}\\right)$\n\t\\task[\\textbf{C.}]$\\omega^{2}=c^{2}\\left(k^{2}+\\frac{\\pi^{2}}{2 a^{2}}\\right)$\n\t\\task[\\textbf{D.}]$\\omega^{2}=c^{2}\\left(k^{2}+\\frac{\\pi^{2}}{4 a^{2}}\\right)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item An electromagnetic wave (of wavelength $\\lambda_{0}$ in free space) travels through an absorbing medium with dielectric permittivity given by $\\varepsilon=\\varepsilon_{R}+i \\varepsilon_{I}$ where $\\frac{\\varepsilon_{I}}{\\varepsilon_{R}}=\\sqrt{3}$. If the skin depth is $\\frac{\\lambda_{0}}{4 \\pi}$, the ratio of the amplitude of electric field $E$ to that of the magnetic field $B$, in the medium (in ohms) is\n\t\\exyear{NET JUNE 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $120 \\pi$\n\t\\task[\\textbf{B.}]377\n\t\\task[\\textbf{C.}]$30 \\sqrt{2} \\pi$\n\t\\task[\\textbf{D.}] $30 \\pi$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item An electromagnetic wave is travelling in free space (of permittivity $\\varepsilon_{0}$ ) with electric field\n\t$$\n\t\\vec{E}=\\hat{k} E_{0} \\cos q(x-c t)\n\t$$\n\tThe average power (per unit area) crossing planes parallel to $4 x+3 y=0$ will be\n\t\\exyear{NET DEC 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{4}{5} \\varepsilon_{0} c E_{0}^{2}$\n\t\\task[\\textbf{B.}]$\\varepsilon_{0} c E_{0}^{2}$\n\t\\task[\\textbf{C.}]$\\frac{1}{2} \\varepsilon_{0} c E_{0}^{2}$\n\t\\task[\\textbf{D.}] $\\frac{16}{25} \\varepsilon_{0} c E_{0}^{2}$\n\\end{tasks}\n\n\\begin{minipage}{\\textwidth}\n\t\\item A plane electromagnetic wave from within a dielectric medium (with $\\varepsilon=4 \\varepsilon_{0}$ and $\\mu=\\mu_{0}$ ) is incident on its boundary with air, at $z=0$. The magnetic field in the medium is $\\vec{H}=\\hat{j} H_{0} \\cos (\\omega t-k x-k \\sqrt{3} z)$, where $\\omega$ and $k$ are positive constants.\n\tThe angles of reflection and refraction are, respectively,\n\t\\exyear{NET DEC 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $45^{\\circ}$ and $60^{\\circ}$\n\t\\task[\\textbf{B.}]$30^{\\circ}$ and $90^{\\circ}$\n\t\\task[\\textbf{C.}]$30^{\\circ}$ and $60^{\\circ}$\n\t\\task[\\textbf{D.}]$60^{\\circ}$ and $90^{\\circ}$\n\\end{tasks}\n\n\\begin{minipage}{\\textwidth}\n\t\\item The electric field of a plane wave in a conducting medium is given by\n\t$$\n\t\\vec{E}(z, t)=\\hat{i} E_{0} e^{-z / 3 a} \\cos \\left(\\frac{z}{\\sqrt{3} a}-\\omega t\\right)\n\t$$\n\twhere $\\omega$ is the angular frequency and $a>0$ is a constant. The phase difference between the magnetic field $\\vec{B}$ and the electric field $\\vec{E}$ is\n\t\\exyear{NET JUNE 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $30^{\\circ}$ and $\\vec{B}$ lags behind $\\vec{B}$\n\t\\task[\\textbf{B.}]$30^{\\circ}$ and $\\vec{B}$ lags behind $\\vec{E}$\n\t\\task[\\textbf{C.}]$60^{\\circ}$ and $\\vec{E}$ lags behind $\\vec{B}$\n\t\\task[\\textbf{D.}]$60^{\\circ}$ and $\\vec{B}$ lags behind $\\vec{E}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A hollow waveguide supports transverse electric $(T E)$ modes with the dispersion relation $k=\\frac{1}{c} \\sqrt{\\omega^{2}-\\omega_{m n}^{2}}$, where $\\omega_{m n}$ is the mode frequency. The speed of flow of electromagnetic energy at the mode frequency is\n\t\\exyear{NET JUNE 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $c$\n\t\\task[\\textbf{B.}] $\\omega_{m n} / k$\n\t\\task[\\textbf{C.}]0\n\t\\task[\\textbf{D.}] $\\infty$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item In the region far from a source, the time dependent electric field at a point $(r, \\theta, \\phi)$ is\n\t$$\n\t\\vec{E}(r, \\theta, \\phi)=\\hat{\\phi} E_{0} \\omega^{2}\\left(\\frac{\\sin \\theta}{r}\\right) \\cos \\left[\\omega\\left(t-\\frac{r}{c}\\right)\\right]\n\t$$\n\twhere $\\omega$ is angular frequency of the source. The total power radiated (averaged over a cycle) is\n\t\\exyear{NET JUNE 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{2 \\pi}{3} \\frac{E_{0}^{2} \\omega^{4}}{\\mu_{0} c}$\n\t\\task[\\textbf{B.}]$\\frac{4 \\pi}{3} \\frac{E_{0}^{2} \\omega^{4}}{\\mu_{0} c}$\n\t\\task[\\textbf{C.}]$\\frac{4}{3 \\pi} \\frac{E_{0}^{2} \\omega^{4}}{\\mu_{0} c}$\n\t\\task[\\textbf{D.}]$\\frac{2}{3} \\frac{E_{0}^{2} \\omega^{4}}{\\mu_{0} c}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item An electromagnetic wave propagates in a nonmagnetic medium with relative permittivity $\\varepsilon=4$. The magnetic field for this wave is\n\t$$\n\t\\vec{H}(x, y)=\\hat{k} H_{0} \\cos (\\omega t-\\alpha x-\\alpha \\sqrt{3} y)\n\t$$\n\twhere $H_{0}$ is a constant. The corresponding electric field $\\vec{E}(x, y)$ is\n\t\\exyear{NET DEC 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{1}{4} \\mu_{0} H_{0} c(-\\sqrt{3} \\hat{i}+\\hat{j}) \\cos (\\omega t-\\alpha x-\\alpha \\sqrt{3} y)$ \n\t\\task[\\textbf{B.}] $\\frac{1}{4} \\mu_{0} H_{0} c(\\sqrt{3} \\hat{i}+\\hat{j}) \\cos (\\omega t-\\alpha x-\\alpha \\sqrt{3} y)$\n\t\\task[\\textbf{C.}]$\\frac{1}{4} \\mu_{0} H_{0} c(\\sqrt{3} \\hat{i}-\\hat{j}) \\cos (\\omega t-\\alpha x-\\alpha \\sqrt{3} y)$\n\t\\task[\\textbf{D.}]$\\frac{1}{4} \\mu_{0} H_{0} c(-\\sqrt{3} \\hat{i}-\\hat{j}) \\cos (\\omega t-\\alpha x-\\alpha \\sqrt{3} y)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Electromagnetic wave of angular frequency $\\omega$ is propagating in a medium in which, over a band of frequencies the refractive index is $n(\\omega) \\approx 1-\\left(\\frac{\\omega}{\\omega_{0}}\\right)^{2}$, where $\\omega_{0}$ is a constant. The ratio $\\frac{v_{g}}{v_{p}}$ of the group velocity to the phase velocity at $\\omega=\\frac{\\omega_{0}}{2}$ is\n\t\\exyear{NET DEC 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] 3\n\t\\task[\\textbf{B.}]$\\frac{1}{4}$\n\t\\task[\\textbf{C.}]$\\frac{2}{3}$\n\t\\task[\\textbf{D.}]2\n\\end{tasks}\n\n\\end{enumerate}\n\n\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{a}&2&\\textbf{a}\\\\\\hline\n\t\t3&\\textbf{d}&4&\\textbf{d}\\\\\\hline\n\t\t5&\\textbf{c}&6&\\textbf{c}\\\\\\hline\n\t\t7&\\textbf{b}&8&\\textbf{c}\\\\\\hline\n\t\t9&\\textbf{b}&10&\\textbf{a}\\\\\\hline\n\t\t11&\\textbf{d}&12&\\textbf{a}\\\\\\hline\n\t\t13&\\textbf{a}&14&\\textbf{b}\\\\\\hline\n\t\t15&\\textbf{c}&16&\\textbf{c}\\\\\\hline\n\t\t17&\\textbf{d}&18&\\textbf{d}\\\\\\hline\n\t\t19&\\textbf{d}&20&\\textbf{b}\\\\\\hline\n\t\t21&\\textbf{b}&22&\\textbf{b}\\\\\\hline\n\t\t23&\\textbf{c}&24&\\textbf{b}\\\\\\hline\n\t\t25&\\textbf{a}&26&\\textbf{a}\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n       \n       \n       \n       \n       \n       \n \n \n \\newpage\n \\begin{abox}\n \tPractice set 2 \n \t\\end{abox}\n \\begin{enumerate}\n \t\\begin{minipage}{\\textwidth}\n \t\t\\item For a plane wave of angular frequency $\\omega$ and propagation vector $\\vec{k}$ propagating in the medium Maxwell's equations reduce to\n \t\t\\exyear{GATE 2010}\n \t\\end{minipage}\n \t\\begin{tasks}(1)\n \t\t\\task[\\textbf{A.}] $\\vec{k} \\cdot \\vec{E}=0 ; \\vec{k} \\cdot \\vec{H}=0 ; \\vec{k} \\times \\vec{E}=\\omega \\varepsilon \\vec{H} ; \\vec{k} \\times \\vec{H}=-\\omega \\mu \\vec{E}$ \n \t\t\\task[\\textbf{B.}]$\\vec{k} \\cdot \\vec{E}=0 ; \\vec{k} \\cdot \\vec{H}=0 ; \\vec{k} \\times \\vec{E}=-\\omega \\varepsilon \\vec{H} ; \\vec{k} \\times \\vec{H}=\\omega \\mu \\vec{E}$\n \t\t\\task[\\textbf{C.}]$\\vec{k} \\cdot \\vec{E}=0 ; \\vec{k} \\cdot \\vec{H}=0 ; \\vec{k} \\times \\vec{E}=-\\omega \\mu \\vec{H} ; \\vec{k} \\times \\vec{H}=\\omega \\varepsilon \\vec{E}$\n \t\t\\task[\\textbf{D.}]$\\vec{k} \\cdot \\vec{E}=0 ; \\vec{k} \\cdot \\vec{H}=0 ; \\vec{k} \\times \\vec{E}=\\omega \\mu \\vec{H} ; \\vec{k} \\times \\vec{H}=-\\omega \\varepsilon \\vec{E}$\n \t\\end{tasks}\n \\begin{minipage}{\\textwidth}\n \t\\item If $\\varepsilon$ and $\\mu$ assume negative values in a certain frequency range, then the directions of the propagation vector $\\vec{k}$ and the Poynting vector $\\vec{S}$ in that frequency range are related as\n \t\\exyear{GATE 2010}\n \\end{minipage}\n \\begin{tasks}(1)\n \t\\task[\\textbf{A.}] $\\vec{k}$ and $\\vec{S}$ are parallel\n \t\\task[\\textbf{B.}]$\\vec{k}$ and $\\vec{S}$ are anti-parallel\n \t\\task[\\textbf{C.}]$\\vec{k}$ and $\\vec{S}$ are perpendicular to each other\n \t\\task[\\textbf{D.}]$\\vec{k}$ and $\\vec{S}$ makes an angle that depends on the magnitude of $|\\varepsilon|$ and $|\\mu|$\n \\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A plane electromagnetic wave has the magnetic field given by\n\t$$\n\t\\vec{B}(x, y, z, t)=B_{0} \\sin \\left[(x+y) \\frac{k}{\\sqrt{2}}+\\omega t\\right] \\hat{k}\n\t$$\n\twhere $k$ is the wave number and $\\hat{i}, \\hat{j}$ and $\\hat{k}$ are the Cartesian unit vectors in $\\mathrm{x}, \\mathrm{y}$ and $\\mathrm{z}$ directions respectively.\n\t(a)$\\text { The electric field } \\vec{E}(x, y, z, t) \\text { corresponding to the above wave is given by }$\\\\\n\t(b)$\\text { The average Poynting vector is given by }$\n\t\\exyear{GATE 2011}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item The space-time dependence of the electric field of a linearly polarized light in free space is given by $\\hat{x} E_{0} \\cos (\\omega t-k z)$ where $E_{0}, \\omega$ and $k$ are the amplitude, the angular frequency and the wavevector, respectively. The time average energy density associated with the electric field is\n\t\\exyear{GATE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{1}{4} \\varepsilon_{0} E_{0}^{2}$\n\t\\task[\\textbf{B.}]$\\frac{1}{2} \\varepsilon_{0} E_{0}^{2}$\n\t\\task[\\textbf{C.}]$\\varepsilon_{0} E_{0}^{2}$\n\t\\task[\\textbf{D.}]$2 \\varepsilon_{0} E_{0}^{2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A plane electromagnetic wave traveling in free space is incident normally on a glass plate of refractive index $3 / 2 .$ If there is no absorption by the glass, its reflectivity is\n\t\\exyear{GATE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}](a) $4 \\%$\n\t\\task[\\textbf{B.}] $16 \\%$\n\t\\task[\\textbf{C.}]$20 \\%$\n\t\\task[\\textbf{D.}]$50 \\%$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A plane polarized electromagnetic wave in free space at time $t=0$ is given by $\\vec{E}(x, z)=10 \\hat{j} \\exp [i(6 x+8 z)] .$ The magnetic field $\\vec{B}(x, z, t)$ is given by\n\t\\exyear{GATE 2012}\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}] $\\vec{B}(x, z, t)=\\frac{1}{c}(6 \\hat{k}-8 \\hat{i}) \\exp [i(6 x+8 z-10 c t)]$ \n\t\\task[\\textbf{C.}]$\\vec{B}(x, z, t)=\\frac{1}{c}(6 \\hat{k}-8 \\hat{i}) \\exp [i(6 x+8 z-c t)]$\n\t\\task[\\textbf{D.}]$\\vec{B}(x, z, t)=\\frac{1}{c}(6 \\hat{k}+8 \\hat{i}) \\exp [i(6 x+8 z+c t)]$\n\t\\task[\\textbf{B.}]$\\vec{B}(x, z, t)=\\frac{1}{c}(6 \\hat{k}+8 \\hat{i}) \\exp [i(6 x+8 z-10 c t)]$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A monochromatic plane wave at oblique incidence undergoes reflection at a dielectric interface. If $\\hat{k}_{i}, \\hat{k}_{r}$ and $\\hat{n}$ are the unit vectors in the directions of incident wave, reflected wave and the normal to the surface respectively, which one of the following expressions is correct?\n\t\\exyear{GATE 2013}\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}] $\\left(\\hat{k}_{i}-\\hat{k}_{r}\\right) \\times \\hat{n} \\neq 0$\n\t\\task[\\textbf{B.}]$\\left(\\hat{k}_{i}-\\hat{k}_{r}\\right) \\cdot \\hat{n}=0$\n\t\\task[\\textbf{C.}]$\\left(\\hat{k}_{i} \\times \\hat{n}\\right) \\cdot \\hat{k}_{r}=0$\n\t\\task[\\textbf{D.}]$\\left(\\hat{k}_{i} \\times \\hat{n}\\right) \\cdot \\hat{k}_{r} \\neq 0$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The electric field of a uniform plane wave propagating in a dielectric non-conducting medium is given by $\\vec{E}=\\hat{x} 10 \\cos \\left(6 \\pi \\times 10^{7} t-0.4 \\pi z\\right) \\mathrm{V} / m$. The phase velocity of the wave is $10^{8} \\mathrm{~m} / \\mathrm{s}$ \n\t\\exyear{GATE 2014}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item The intensity of a laser in free space is $150 \\mathrm{~m} \\mathrm{~W} / \\mathrm{m}^{2}$. The corresponding amplitude of the electric field of the laser is $\\cdots\\frac{V}{m} \\quad\\left(\\varepsilon_{0}=8.854 \\times 10^{-12} C^{2} / N . m^{2}\\right)$\n\t\\exyear{GATE 2014}\n\\end{minipage}\n\n\\begin{minipage}{\\textwidth}\n\t\\item The electric field component of a plane electromagnetic wave travelling in vacuum is given by $\\vec{E}(z, t)=E_{0} \\cos (k z-\\omega t) \\hat{i}$. The Poynting vector for the wave is\n\t\\exyear{GATE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\left(\\frac{c \\varepsilon_{0}}{2}\\right) E_{0}^{2} \\cos ^{2}(k z-\\omega t) \\hat{j}$\n\t\\task[\\textbf{B.}]$\\left(\\frac{c \\varepsilon_{0}}{2}\\right) E_{0}^{2} \\cos ^{2}(k z-\\omega t) \\hat{k}$\n\t\\task[\\textbf{C.}] $c \\varepsilon_{0} E_{0}^{2} \\cos ^{2}(k z-\\omega t) \\hat{j}$\n\t\\task[\\textbf{D.}]$c \\varepsilon_{0} E_{0}^{2} \\cos ^{2}(k z-\\omega t) \\hat{k}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item An electromagnetic plane wave is propagating with an intensity $I=1.0 \\times 10^{5} \\mathrm{Wm}^{-2}$ in a medium with $\\in=3 \\in_{0}$ and $\\mu=\\mu_{0}$. The amplitude of the electric field inside the medium is $\\times 10^{3} \\mathrm{Vm}^{-1}$ (up to one decimal place). $\\left(\\in_{0}=8.85 \\times 10^{-12} C^{2} N^{-1} m^{-2}, \\mu_{0}=4 \\pi \\times 10^{-7} N A^{-2}, c=3 \\times 10^{8} m s^{-1}\\right)$\n\t\\exyear{GATE 2018}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item The electric field of an electromagnetic wave in vacuum is given by\n\t$$\n\t\\vec{E}=E_{0} \\cos \\left(3 y+4 z-1.5 \\times 10^{9} t\\right) \\hat{x}\n\t$$\n\tThe wave is reflected from the $z=0$ surface. If the pressure exerted on the surface is $\\alpha \\in E_{0}^{2}$, the value of $\\alpha$ (rounded off to one decimal place) is\n\t\\exyear{GATE 2019}\n\\end{minipage}\n \\end{enumerate}\n\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{d}&2&\\textbf{a}\\\\\\hline\n\t\t3&\\textbf{}&4&\\textbf{a}\\\\\\hline\n\t\t5&\\textbf{a}&6&\\textbf{a}\\\\\\hline\n\t\t7&\\textbf{c}&8&\\textbf{1.5}\\\\\\hline\n\t\t9&\\textbf{10.6}&10&\\textbf{d}\\\\\\hline\n\t\t11&\\textbf{d}&12&\\textbf{2.39}\\\\\\hline\n\t\t13&\\textbf{4}&14&\\textbf{a}\\\\\\hline\n\t\t15&\\textbf{a}&16&\\textbf{6.6}\\\\\\hline\n\t\t17&\\textbf{0.8}&&\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\n\n   ", "meta": {"hexsha": "ec9d9fe62d465d920ec3087b5b45fc2764533458", "size": 62719, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Electrodynamics- CSIR/chapter/EM waves.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Electrodynamics- CSIR/chapter/EM waves.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Electrodynamics- CSIR/chapter/EM waves.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.9203152364, "max_line_length": 450, "alphanum_fraction": 0.6533586314, "num_tokens": 24674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7099532266634665}}
{"text": "\\chapter{Unitary Invariances for Hartree-Fock Orbitals}\\label{app:hartree-fock-orbital-invariance}\n\n\n\\paragraph{Orthonormality.}\nBy definition, unitary transformations preserve overlaps.\nThis can be verified as follows\n\\begin{align*}\n  \\ip{\\tl\\y_i|\\tl\\y_j}\n=\n\\sum_{kl}\n  U_{ki}U_{lj}^*\n  \\ip{\\y_k|\\y_l}\n=\n\\sum_{kl}\n  U_{ki}U_{lj}^*\n  \\delta_{kl}\n=\n\\sum_k\n  U_{ki}U_{kj}^*\n=\n  \\delta_{ij}\n\\end{align*}\nusing $\\sum_k U_{ki}U_{kj}^*=(\\bo{U}\\bo{U}\\dg)_{ji}=(\\bo{1})_{ji}=\\d_{ji}$.\n\n\\paragraph{Fock operator.}\nOnly the Coulomb and exchange parts of the Fock operator depend on the orbital set.\nFor the Coulomb part, we have\n{\\small\\begin{align*}\n\\sum_i\n  \\ip{\\tl\\y_i(2)|\\op{g}(1,2)|\\tl\\y_i(2)}\n=\n\\sum_{ijk}\n  U_{ji}U_{ki}^*\n  \\ip{\\y_j(2)|\\op{g}(1,2)|\\y_k(2)}\n=\n\\sum_{jk}\n  \\delta_{jk}\n  \\ip{\\y_j(2)|\\op{g}(1,2)|\\y_k(2)}\n=\n\\sum_j\n  \\ip{\\y_j(2)|\\op{g}(1,2)|\\y_j(2)}\n\\end{align*} \\underline{}}%\nusing the fact that $\\sum_i U_{ji}U_{ki}^*=\\d_{jk}$.\nFor the exchange part, we have the same thing with a $\\op{P}(1,2)$ sandwiched in there.\n\n\\paragraph{Hamiltonian expectation value.}\nThe vector notation $\\bm\\y$ for our orbitals allows us to express $\\F$ and $\\tl\\F$ as\n\\begin{align*}\n  \\F(1,\\ld,n)\n=\n  \\tfrac{1}{\\sqrt{n!}}\n  |\\bm\\y(1)\\cd\\bm\\y(n)|\n%\\sp\\sp\n  \\tl\\F(1,\\ld,n)\n=\n  \\tfrac{1}{\\sqrt{n!}}\n  |\\tl{\\bm\\y}(1)\\cd\\tl{\\bm\\y}(n)|\n\\end{align*}\nwhich, noting that the matrix $\\ma{\\tl{\\bm\\y}(1)\\ \\cd\\ \\tl{\\bm\\y}(n)}$ is simply\n\\begin{align*}\n  \\ma{\\tl{\\bm\\y}(1)\\ \\cd\\ \\tl{\\bm\\y}(n)}\n=\n  \\ma{\\bo{U}\\dg\\bm\\y(1)\\ \\cd\\ \\bo{U}\\dg\\bm\\y(n)}\n=\n  \\bo{U}\\dg\\ma{\\bm\\y(1)\\ \\cd\\ \\bm\\y(n)}\n\\end{align*}\nimplies $\\tl\\F=\\det(\\bo{U}\\dg)\\F=\\det(\\bo{U})^*\\F$.\nTherefore, $\\tl{\\F}$ and $\\F$ have the same energy expectation values.\n\\begin{align}\n  \\ip{\\tl\\F|\\op{H}_e|\\tl\\F}\n=\n  \\det(\\bo{U}\\bo{U}\\dg)\\ip{\\F|\\op{H}_e|\\F}\n=\n  \\ip{\\F|\\op{H}_e|\\F}\n\\end{align}\n", "meta": {"hexsha": "2a21250e4f7c26d039b493c10fbe0f1d2b94c7cb", "size": 1822, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "handouts/sections/unitary-invariances-hf-orbitals.tex", "max_stars_repo_name": "GQCG-edu/chem-8950", "max_stars_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "handouts/sections/unitary-invariances-hf-orbitals.tex", "max_issues_repo_name": "GQCG-edu/chem-8950", "max_issues_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-07-13T12:11:58.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-13T15:31:47.000Z", "max_forks_repo_path": "handouts/sections/unitary-invariances-hf-orbitals.tex", "max_forks_repo_name": "GQCG-edu/chem-8950", "max_forks_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.9736842105, "max_line_length": 98, "alphanum_fraction": 0.5993413831, "num_tokens": 815, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391664210673, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.7098911858221139}}
{"text": "%\n% Chapter 4.1\n%\n\n\\section*{4.1 Areas and Distances}\n\nThe area \\(A\\) of the region \\(S\\) that lies under the graph of the continuous function \\(f\\) is the limit of the sum of the areas of the approximating rectangles:\n$$ A = \\lim_{n \\to \\infty}R_n = \\lim_{n \\to \\infty}[f(x_1) \\Delta x + f(x_2) \\Delta x + \\cdots + f(x_n) \\Delta x] $$\nwritten with summation notation as \n$$ \\lim_{n \\to \\infty}\\sum_{i=1}^{n}f(x_i^*) \\Delta x $$\n", "meta": {"hexsha": "7bb73369c03d00e8255c0abf82ad61a18b2b4095", "size": 429, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/4-1.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/4-1.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/4-1.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.0, "max_line_length": 163, "alphanum_fraction": 0.648018648, "num_tokens": 154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.7098911695376025}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 2}\n\nDetermine the longest common subsequence of $A = \\langle 1, 0, 0, 1, 0, 1, 0, 1 \\rangle$ and $B = \\langle 0, 1, 0, 1, 1, 0, 1, 1, 0 \\rangle$.\n\n\\subsection*{Solution}\n\nTable \\ref{tab11} provides Longest Common Subsequence for different prefixes of sequences $A$ and $B$, according to the \\textsc{LCS-Length} algorithm.\nAs is shown, Table \\ref{tab11} reveals the longest common subsequence between given sequences $A$ and $B$ is 6.\nOne possible common subsequence is obtained by following shaded cells, leading to $\\langle 0, 1, 1, 0, 0, 1 \\rangle$.\nIt's clear that such longest common subsequence is not unique.\n\n\\begin{table}[H]\\centering\n\\begin{tabular}{c c l l l l l l l l l l}\n& j & 0       & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\\\\ni & & $y_j$   & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 1 & 0\\\\\\cline{3-12}\n0 & $x_i$ & 0 & 0\\cellcolor{gray!25} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\n1 & $1$ & 0 & 0$\\uparrow$ & 1$\\nwarrow$\\cellcolor{gray!25} & 1$\\leftarrow$ & 1$\\nwarrow$ & 1$\\nwarrow$ & 1$\\leftarrow$ & 1$\\nwarrow$ & 1$\\nwarrow$ & 1$\\leftarrow$ \\\\\n2 & $0$ & 0 & 1$\\nwarrow$ & 1$\\uparrow$ & 2$\\nwarrow$\\cellcolor{gray!25} & 2$\\leftarrow$\\cellcolor{gray!25} & 2$\\leftarrow$\\cellcolor{gray!25} & 2$\\nwarrow$ & 2$\\leftarrow$ & 2$\\leftarrow$ & 2$\\nwarrow$\\\\\n3 & $0$ & 0 & 1$\\nwarrow$ & 1$\\uparrow$ & 2$\\nwarrow$ & 2$\\uparrow$ & 2$\\uparrow$ & 3$\\nwarrow$\\cellcolor{gray!25} & 3$\\leftarrow$ & 3$\\leftarrow$ & 3$\\nwarrow$\\\\\n4 & $1$ & 0 & 1$\\uparrow$ & 2$\\nwarrow$ & 2$\\uparrow$ & 3$\\nwarrow$ & 3$\\nwarrow$ & 3$\\uparrow$ & 4$\\nwarrow$\\cellcolor{gray!25} & 4$\\nwarrow$ & 4$\\leftarrow$\\\\\n5 & $0$ & 0 & 1$\\nwarrow$ & 2$\\uparrow$ & 3$\\nwarrow$ & 3$\\uparrow$ & 3$\\uparrow$ & 4$\\nwarrow$ & 4$\\uparrow$\\cellcolor{gray!25} & 4$\\uparrow$ & 5$\\nwarrow$\\\\\n6 & $1$ & 0 & 1$\\uparrow$ & 2$\\nwarrow$ & 3$\\uparrow$ & 4$\\nwarrow$ & 4$\\nwarrow$ & 4$\\uparrow$ & 5$\\nwarrow$ & 5$\\nwarrow$\\cellcolor{gray!25} & 5$\\uparrow$\\\\\n7 & $0$ & 0 & 1$\\nwarrow$ & 2$\\uparrow$ & 3$\\nwarrow$ & 4$\\uparrow$ & 4$\\uparrow$ & 5$\\nwarrow$ & 5$\\uparrow$ & 5$\\uparrow$ & 6$\\nwarrow$\\cellcolor{gray!25}\\\\\n8 & $1$ & 0 & 1$\\uparrow$ & 2$\\nwarrow$ & 3$\\uparrow$ & 4$\\nwarrow$ & 5$\\nwarrow$ & 5$\\uparrow$ & 6$\\nwarrow$ & 6$\\nwarrow$ & 6$\\uparrow$\\cellcolor{gray!25}\\\\\\cline{3-12}\n\\end{tabular}\n\\caption{Length of Common Subsequences for Different Prefixes of $A$ and $B$}\\label{tab11}\n\\end{table}\n", "meta": {"hexsha": "9cf39295351cb4a52fc224e3aabca880ccb16a25", "size": 2705, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw04/hw04q02.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw04/hw04q02.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw04/hw04q02.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 77.2857142857, "max_line_length": 204, "alphanum_fraction": 0.5926062847, "num_tokens": 1126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891479496521, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.7098712107061905}}
{"text": "\\lab{Complex Integration}{Integration in the Complex Plane}{Integration in the Complex Plane}\n\n\\objective{Understand the basics of integration in the complex plane}\n\n\\section*{Contour Integrals in the Complex Plane}\n\nFrom multivariable calculus, you may recall that an integral may be taken along a path.\nThis is very similar to what we can be done in the complex plane.\nConsider the function $f(z)$ on the complex plane.\nLet $z=x+iy$ Let $u$ and $v$ be the real and imaginary parts of $f$ respectively.\nWe integrate $f$ along some contour $C$ in the complex plane, beginning at $z=a$ and ending at $z=b$.\nThis integral may be written $$\\int_c f(z)dz$$.\nParameterizing $z$, we have $$\\int_a^b z(t)z'(t)dt=$$.\nExpanding into real and imaginary parts, we have\n$$\\int_a^b (u(z(t))x'(t)-v(z(t))y'(t))dt +i \\int_a^b(v(z(t))x'(t)+u(z(t))y'(t))dt$$\nWe have now written this complex integral as the sum of two real valued integrals in $\\mathbb{R}$.\nNote that this implies that $\\int_C z dz$ may depend on the contour we choose and not just on the endpoints $a$ and $b$.\n\n\\begin{problem}\nWrite a function which takes a complex function $f(z)$, a contour parameterization $z(t)$ of a contour $c$, the integration bounds on $t$, and a tolerance and returns the integral of $f$ along the contour $c$. \nYou may use the numerical differentiation and integration functions that you have defined in previous labs, or you can use the function \\li{mpmath.diff} as the numerical derivative and \\li{mpmath.quad} or \\li{scipy.integrate.quad} as the numerical integral.\n(Mpmath is another numerical library you can install.\nIt is used primarily for arbitrary precision computation and is already included as a subpackage of SymPy.)\n\\end {problem}\n\n\\begin{problem}\nUsing the function you just defined, integrate the following functions along the following contours\n\\begin{itemize}\n\\item $e^z$ counterclockwise along the unit ball starting and ending at $1$\n\\item $\\bar{z}$ counterclockwise along the unit ball starting and ending at $1$\n\\item $e^z$ along a straight line from $0$ to $1+i$\n\\item $\\bar{z}$ along a straight line from $0$ to $1+i$\n\\item $e^z$ along the real axis from $0$ to $1$, then along the line from $1$ to $1+i$\n\\item $\\bar{z}$ along the real axis from $0$ to $1$, then along the line from $1$ to $1+i$\n\\item $e^z$ along the unit ball centered at $i$ from $0$ to $1+i$\n\\item $\\bar{z}$ along the unit ball centered at $i$ from $0$ to $1+i$\n\\end{itemize}\n\\end{problem}\n\n\\begin{problem}\nImplement another version of the function from problem $1$ using symbolic differentiation and integration from SymPy.\nInstead of using callable functions for the function and the contour, use SymPy symbolic expressions.\nYou will have to add parameters for the variables of the expressions for the function and contour.\nThe tolerance parameter should no longer be necessary.\n\\end{problem}\n\nAn important theorem in Complex Analysis is Cauchy's Integral Theorem, which says that, for any holomorphic function on a simply connected  $f(z)$, and two contours $C_1$ and $C_2$ that share endpoints, $$\\int_{C_1}f(z)dz = \\int_{C_2}f(z)dz$$\n\nNote: A simply connected domain is, roughly speaking, a domain which contains no ``holes.\" For example, the unit ball is a simply connected domain, while the set $\\setconstruct{z\\in \\mathbb{C}}{1<\\abs{z}<2}$ is not. \n\nIn other words, for a holomorphic function on a simply connected domain, the integrals from one point to another are not path dependent for any contours that lie within D.\nAn immediate consequence of the theorem is that for a complex function $f$, holomorphic on a simply connected domain $D$, and a contour $C$ lying entirely within $D$ which begins and ends at some point $a\\in D$,\n$$\\int_C f(z)dz=0$$\nAn example would be the function $e^z$ which is holomorphic everywhere on the complex plane (when this is true, we say that the function is ``entire\").\nAs a consequence of Cauchy's Integral Theorem, for any two points $a,b\\in \\mathbb{C}$ , the integral from $a$ to $b$ is path independent.\n\nCauchy's Integral Theorem allows us to define the antiderivative of a function on a simply connected domain as follows\n\\begin{theorem}[Cauchy's Integral Theorem]\nLet $D$ be a simply connected domain in $\\mathbb{C}$. Let $f$ be a function that is holomorphic on $D$.\nLet $z_0$ and $z$ be points of $D$. Define the antiderivative, $F(z)$, as $\\int_C f(z)dz$ for any $C$ in $D$ from $z_0$ to $z$.\n\\end{theorem}\nGiven the conditions above, this also lets us evaluate integrals as we would normally do in the real numbers, so we may write $\\int_a^b f(z)dz=F(b)-F(a)$ where $F$ is the antiderivative of $f$.\nIt can be proven that that $F$ is also analytic on $D$.\nIt follows that a function which is holomorphic on a domain $D$ is infinitely integrable on that domain.\n\nThe quadrature algorithms used in many of the integration algorithms work along a straight line between the integration bounds in the complex plane, so for holomorphic functions we should be able to use the integration function we wrote earlier.\nThe \\li{mpmath.quad} function also allows us to do this.\nFor example, integrating $e^z$ from $-1-i$ to $1+i$ can be done numerically like this:\n\\begin{lstlisting}[style=python]\nfrom sympy import mpmath as mp\ncomplex(mp.quad(lambda x: mp.exp(x),(complex(-1,-1),complex(1,1))))\n\\end{lstlisting}\nIn the same case, we can also evaluate this integral using SymPy as follows.\n\\begin{lstlisting}[style=python]\nimport sympy as sy\nsy.N(sy.integrate(sy.exp(z),(z,-1-sy.I,1+sy.I)))\n\\end{lstlisting}\n\n\\section*{The Cauchy Integral Formula}\n\nAnother major theorem in complex analysis is called Cauchy's Integral Formula (not to be confused with Cauchy's Integral Theorem).\nIt states that for a domain $D$ in the complex plane, containing some contour (rigorously speaking, a piecewise Jordan Curve) $C$ and the interior of $C$, for any $z_0$ in the interior of $C$, \n$$f(z_0)=\\frac{1}{2\\pi i} \\int_C \\frac{f(z)}{z-z_0} dz$$. \n\nWith more work, this theorem can be used to show that any function $f$ holomorphic on some domain $D$ is also infinitely differentiable on that domain.\nIn fact the $n$th derivative of $f$ is given by the formula $$f^{(n)}(z_0) = \\frac{n!}{2\\pi i} \\int_C \\frac{f(z)}{(z-z_0)^{n+1}} dz$$\nThis result is also important because it allows us to relate the value of $f$ on the inside of a contour to the value of $f$ on the contour itself.\nIn other words, the values of $f$ inside the contour depend only on the values of $f$ along the contour itself.\nA related theorem (the Morera theorem) states that if some function $f$ is continuous on a domain $D$ and for every contour beginning and ending at the same point (properly speaking, a piecewise smooth closed curve), the formula $\\int_C f(z) dz = 0$ holds, then $f$ is holomorphic on $D$. \n\n\\begin{problem}\nUsing Cauchy's Integral Formula, write a python function which returns a callable function which evaluates a complex function $f$ along the interior of a contour $C$. It should accept a callable function for the paramaterization of $C$, a callable function for the values of $f$ along $C$, and the bounds on the parameter used. Note that $C$ must begin and end at the same point and that $f$ must also begin and end with the same value so that $f$ is continuous along $C$.\n\\end{problem}\n\nNotice that in Cauchy's Integral Formula, we are integrating along a contour that begins and ends at the same point.\nThe function is also holomorphic at every point except $z_0$. At $z_0$ the integrand is undefined and has a singularity.\nThis integral around a singularity has some useful properties.\n\n\\section*{Residues}\n\nWe will now introduce another form of series representation of functions.\nA Laurent series of a function is a series of the form $$\\sum_{n= -\\infty}^{\\infty} a_n (z-z_0)^n$$\nIt can be proven that \n$$a_n = \\frac{1}{2\\pi i} \\int_C \\frac{f(z)}{(z-z_0)^{n+1}} dz$$ \nIt can also be proven that this series representation is unique.\nThis sort of series can be generated whether or not $f$ has a singular point a $z_0$.\nWhen $f$ does not have a singularity at $z_0$ this representation degenerates to a normal Taylor Series (with the derivatives evaluated by the formula for the $n$th derivative of an analytic function).\nWhere $C$ is a contour which passes counterclockwise around the singularity exactly once.\nThis is called Laurent's Theorem.\nBy analyzing the convergence of this series, we see that it will either converge for all points except possibly $z_0$ in the complex plane, converge on an annulus about $z_0$, or not converge at all.\n\n\\begin{problem}\nWrite a python function which takes $f$, $z_0$, the lowest power term in the Laurent Series, and the highest power term in the Laurent Series and returns a callable function for the desired series.\n\\end{problem}\n\nThe built in function \\li{sympy.series} can also evaluate the series expansion of a function at a singularity, for example\n\\begin{lstlisting}[style=python]\nimport sympy as sy\nimport sympy as sy\n(1/sy.sin(z)).series(z,0,8)\n\\end{lstlisting}\nwhich evaluates the series expansion of the $\\csc(z)$ at $z=0$. \nAs is the case with Taylor Series, often the Laurent Series expansion of a function is not computed directly using it's integral definition.\nIt is, rather, obtained by substitution into known series.\nFor example, \n$$e^z = \\sum_{n=0}^{\\infty} \\frac{z^n}{n!}$$, so we may say,\n$$e^{1/z} = \\sum_{n=0}^{\\infty} \\frac{1}{n! z^n}$$\n\n\\begin{problem}\nFind the Laurent Series expansion of the function $\\frac{e^{z}}{z^2 +1}$\n\\end{problem}\n\n% Before final publication we should figure out how to get the z=z_0 underneath the symbol Res.\n% For now I'll just leave it alone.\n% A class can be done off of this as it is written.\n\nThe term corresponding to $n=-1$ in the Laurent Series expansion of a complex function $f$ about a singularity $z_0$ is called the residue of $f$ at $z_0$ and is often written $\\Res_{z=z_0} f(z)$.\nFrom Laurent's Theorem, using $f$, $z_0$, and $C$ as defined above, we have that $$Res_{z=z_0} f(z) = \\frac{1}{2 \\pi i} \\int_C f(z) dz$$.\nAnother major theorem in Complex Analysis is the residue theorem (Also called Cauchy's Residue Theorem) which states that for some contour $C$ which does not intersect itself and a function $f$ analytic on $C$ and on the interior of $C$ except for isolated singular points $z_1,...,z_n$, that \n$$\\int_C f(z) dz = 2 \\pi i \\sum_{k=1}^{n} \\Res_{z=z_k} f(z)$$\nThis allows for the evaluation of integrals that might not be pleasant in other circumstances.\n%% Maybe an example would be nice here... idk. That'll mostly be in the next lab though.\nHere are a few definitions that are good to know when speaking of residues.\n\\begin{itemize}\n\\item A singular point $z_0$ is said to be an ``isolated singular point\" of a function $f$ if no sequence of singular points of $f$ converges to it.\n\\item An isolated singular point $z_0$ is said to be a removable singular point of a function $f$ if there are no negative powers of $(z-z_0)$ in the Laurent series expansion of $f$.\n\\item An isolated singular point $z_0$ is said to be a pole of a function $f$ is there are finitely may terms containing negative powers of $(z-z_0)$ in the Laurent series expansion of $f$. \n\\item An isolated singular point $z_0$ is said to be an essential singular point of a function $f$ if there are infinitely many negative powers of $(z-z_0)$ in the Laurent series expansion of $f$.\n\\end{itemize}\n\n\\begin{problem}\nEvaluate the residue of $\\sin(\\frac{1}{z})$ at $z=0$ by substituting into known Taylor series expansions.\nCheck your result numerically.\n\\end{problem}\n\n\\begin{problem}\nThere is a direct relationship between the partial fraction decomposition of the reciprocal of a polynomial and the residues of that function at its zeroes.\nShow why this is true, and, using the Newton's method function you have already written, write a function which, given the coefficients for a polynomial, returns the coefficients for the partial fraction decomposition of its reciprocal with the zeroes corresponding to each coefficient.\n\\end{problem}\n \n\\section*{Multi-Valued Functions}\n\nAnother important topic in Complex Analysis is the study of multiple valued functions.\nThese functions arise as we consider the inverses of functions that are not strictly one to one on the complex plane.\nA classic example is $\\sqrt{x}$, which may take two values for every nonzero point of the complex plane.\n\nIn the Real numbers we worked with functions like this by simply restricting their output on a certain domain.\nWe can do a similar thing in the Complex plane.\nLoosely speaking, such a restriction is called a branch.\nThe function $\\sqrt{z}$ has two branches on the complex plane.\nWe cut it along the ray $(0,-\\infty)$.\nBy doing so, we can define two single valued functions on the complex plane.\nWe call inverse functions that have multiple values like this ``multi-valued functions\" or ``multifuctions.\"\nComputationally we restrict the output to a single portion of the actual possible values of the multifunction.\nWe can still visualize the ``Riemann surfaces\" of multifunctions in the complex plane.\nThe following are some simple examples.\n\\begin{figure}[h]\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{RiemannSurface1}\n\\caption{The Real Part of $\\sqrt{z}$}\n\\end{subfigure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{RiemannSurface2}\n\\caption{The imaginary part of $\\sqrt{z}$}\n\\end{subfigure}\n\\end{figure}\nThese are some very basic examples.\nRiemann surfaces can be very complex.\nAnother simple example is $\\ln(z)$ which has a single value for the real part, and the following for its imaginary part:\n\\begin{figure}[h]\n\\includegraphics[width=\\textwidth]{RiemannSurface3}\n\\caption{Riemann surface plot of $\\ln(z)$}\n\\end{figure}\nNote that this is only a portion of the Riemann surface of $\\ln(z)$.\nThe full surface is, in actuality, an infinite spiral that repeats every $2\\pi$.\nThis is because for any complex $z\\neq 0$, we have $e^z=e^{z+2n\\pi}$ where $n$ is any integer.\n\\begin{figure}[h]\n\\includegraphics[width=\\textwidth]{RiemannSurface4.pdf}\n\\caption{Even the Riemann surface of $\\arctan(z)$ becomes increasingly complex.\nThis is a graph of a portion of the Riemann surface for the real part of $\\arctan(z)$.}\n\\end{figure}\nAll three of the functions we have plotted can be made analytic at almost any point, except at their singularities, but that depends on how we cut the domain to give it a single value.\nWhen Integrating such functions be careful about integrating across such cuts in the domain.\n\n\\begin{problem}\nPlot the Riemann surface of $z^{\\frac{1}{4}}$.\n\\end{problem}\n\n\\begin{problem}\nIntegrate the function $\\ln(z)$ beginning at $z=1$ and $\\ln(z)=0$ and ending at $z=1$ and $\\ln(z)=6*\\pi$.\n\\end{problem}", "meta": {"hexsha": "3349d8e75acbb548eede1a5e398d1f7ed8759663", "size": 14765, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/ComplexIntegration/ComplexIntegration1.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/ComplexIntegration/ComplexIntegration1.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/ComplexIntegration/ComplexIntegration1.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.9763033175, "max_line_length": 472, "alphanum_fraction": 0.7511005757, "num_tokens": 3956, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891218080991, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.7098711953609457}}
{"text": "\\section{The State}\n\nA Kalman Filter's main goal is to track and estimate a \\textit{state}, which is a column vector containing variables we care about.\n\n\\begin{equation}\n    \\boldsymbol{\\hat{x}} = \n    \\begin{pmatrix}\n    x & \\dot{x} & y & \\dot{y} & \\phi & \\dot{\\phi} & v_l & v_r\n    \\end{pmatrix} ^ T\n\\end{equation}\n\nWe use the EKF primarily for tracking our position, $x$ and $y$, and our global heading $\\phi$. To do this well, we also need to track the yaw rate $\\dot{\\phi}$, component velocities $\\dot{x}$ and $\\dot{y}$, and wheel velocities $v_l$ and $v_r$. Since we don't care about the actual performance of the EKF when tracking these subsidiary variables, we can assume they're constant in our calculations without hindering the accuracy of the variables we do care about. This assumption of constant velocities makes our motion model very simple, but still quite powerful for the variables with accurate motion models.\n\nThe ``hat'' over the state indicates that it is an estimate, since we can't ever say definitively that our state equals the ground truth. As a further notation clarification, when a vector or matrix is subscripted by two values, the first is the timestep for which the variable estimates, and the second is the timestep in which the estimate was made. So a prediction for the next state made at timestep $k$ would be denoted $\\boldsymbol{\\hat{x}}_{k+1,k}$, while a prediction for the current state made in the previous timestep would be $\\boldsymbol{\\hat{x}}_{k,k-1}$. When the state is updated, it also applies to the current timestep, so this would be $\\boldsymbol{\\hat{x}}_{k,k}$. ", "meta": {"hexsha": "5c55f290d1523882b882a367d5b48a1d41156950", "size": 1616, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/IGVC EKF Derivation/sections/state.tex", "max_stars_repo_name": "SoonerRobotics/igvc_software_2022", "max_stars_repo_head_hexsha": "906e6a4fca22d2b0c06ef1b8a4a3a9df7f1d17dd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-07T14:56:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-13T23:31:07.000Z", "max_issues_repo_path": "docs/IGVC EKF Derivation/sections/state.tex", "max_issues_repo_name": "SoonerRobotics/igvc_software_2022", "max_issues_repo_head_hexsha": "906e6a4fca22d2b0c06ef1b8a4a3a9df7f1d17dd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-09-22T01:53:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-17T01:02:31.000Z", "max_forks_repo_path": "docs/IGVC EKF Derivation/sections/state.tex", "max_forks_repo_name": "SoonerRobotics/igvc_software_2022", "max_forks_repo_head_hexsha": "906e6a4fca22d2b0c06ef1b8a4a3a9df7f1d17dd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-06-29T05:21:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-23T05:03:27.000Z", "avg_line_length": 115.4285714286, "max_line_length": 684, "alphanum_fraction": 0.7438118812, "num_tokens": 402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849805, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7098201082990744}}
{"text": "%!TEX root =  ../main.tex\n\\subsection{Inside vs. Outside}\n\n\n\\objective{Produce and decipher translations and dilations of functions.}\n\n\n\\subsubsection{``Outside'' Operations}\nHow would you triple the output of a function?  How would you add four to the output of a function?\nBecause function notation means ``perform the operation of the function upon the input,'' we must\nwrite the operators we described \\emph{to the right} of the function operation, written $f(x) \\cdot 3$\nand $f(x) + 4$ respectively.  Normally, multiplicative operators are written on the left, without\nan intervening symbol.  Because addition is commutative, it may be written on the left as well.\n\n\\paragraph{Addition}\n\\marginfig[-1in]{\\chapdir/pics/verticaltranslation}{Vertical translation is outside addition.}\nWhat is the graphical effect of the algebraic operation, $f(x) + 4$?  Let us build up a visual picture\nnumerically at first.\n\n\\emph{adding moves it up, negatives move it down.  Multiplication by $>1$ makes it taller.\n$(0,1)$ makes it shorter.  All relative to the x-axis.}\n\n\\begin{example}{Outside Transformations}\n\t\\exProblem\n$r(x)=\\sqrt[3]{x}$ and $s(x)=\\frac{1}{2}r(x)+3$.  In what ways does the graph of\n$s(x)$ differ from $r(x)$?\n\n\t\\exSolution\nup 3, half as tall\n\\end{example}\n\\index{transformation!translation}\n\n\\paragraph{Multiplication}\n\\marginfig[-0.2in]{\\chapdir/pics/Quartic_hv_shift.png}{Combining addition outside and subtraction inside can translate a graph to any desired location.}\nMultiplication also behaves as one might expect, effecting $y$ in a directly-proportional way.\nFor example, regardless of what $f(x)$ is (excepting 0), then the graph of $3\\cdot{}f(x)$\nwith be three times taller, a vertical dilation of 3.\n\n\\subsubsection{``Inside'' Operations}\nThings done ``inside'' are done \\emph{before} the function operates on the domain.  This means\ngraphically they will effect $x$.  However, their effect is quite curious, typically being the \n\\emph{opposite} of what one might expect.\n\nFor example, consider the quadratic function $f(x)=x^2$, and a transformation of it, $g(x)=f(x+4)$.\nWe can see that the +4 is on the ``inside'', and we know that 4 is added to members of the domain\nbefore they are plugged in to the function.  This means -4 will become 0 before it is squared.\nAnother way to say this that what used to be outputted at $x=0$ will now be outputted at $x=-4$.\n\nThis opposite effect also applies to dilations.  When we multiply the inside of a function by 2, it does\nnot produce a graph twice as wide, but \\emph{half}.\n\n\\personfeature[-0.5in]{\\chapdir/pics/Dirichlet.jpg}{Peter Gustav Lejeune Dirichlet}{1805 --- 1859}{was a German mathematician who made deep contributions to number theory (including creating the field of analytic number theory), and to the theory of Fourier series and other topics in mathematical analysis; he is credited with being one of the first mathematicians to give the modern formal definition of a function.\n\\href{https://en.wikipedia.org/wiki/Peter_Gustav_Lejeune_Dirichlet}{(Wikipedia)}}\n\n\n\\begin{example}{Inside Transformation}\n\t\\exProblem\nConsider the continuous function $f(x)$ given by the graph (looks like a radical sign).\nDescribe and graph the continuous $g(x)$, when $g(x)=f(2x-2)$.  What would be a more\ninformative way to write $g(x)$ in terms of $f(x)$?\n\n\t\\exSolution\nIt's half as wide and left 1.  $f(2(x-1))$ would be more transparent.\n\\end{example}\n\\index{transformation!dilation}\n\nIn summary, $f(x) + d$ will shift the graph $d$ units to the right.  $f(x+c)$ will shift the graph\n$c$ units to the left.  $a\\cdot{}f(x)$ will make the graph $a$ times taller.  $f(b\\cdot{}x)$ will\nmake the graph $b$ times skinnier.\n\n~\\vfill\n", "meta": {"hexsha": "a87f382986a302b956755e5918e928d9b1358982", "size": 3696, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch01/0103.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch01/0103.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch01/0103.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.3333333333, "max_line_length": 417, "alphanum_fraction": 0.7489177489, "num_tokens": 1010, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870013740061, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7098069011194766}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 17.2 Computation Using Partial Derivative Arrays or\n\\hbox{Multivariate Taylor Series}\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nThis set of subroutines performs computations in which each variable is\nrepresented by its value, and its first and second partial derivatives with\nrespect to N independent variables, evaluated at a specified value of these\nvariables. Such a set of numbers can alternatively be regarded as a scaled\nrepresentation of the low order coefficients of the multivariate Taylor\nseries of the dependent variable expanded at the evaluation point.\n\nMore specifically let $u({\\bf x})$ denote a scalar valued function of an\nN-component argument vector, ${\\bf x}$. Let $u_0$, ${\\bf g}_0$, and $H_0$ denote,\nrespectively, the value of $u$, the gradient vector, and the Hessian matrix,\nevaluated at ${\\bf x}_0$. Then $\\{u_0$, ${\\bf g}_0$, $H_0\\}$ is the set of data these\nprograms carry to represent $u$ evaluated at ${\\bf x}_0$. The Taylor series for $u$\nthrough second order, expanded at ${\\bf x}_0$, is\n\\begin{equation*}\nu({\\bf x}) = u_0 + {\\bf g}^t_0({\\bf x}-{\\bf x}_0) + \\frac{1}{2}({\\bf\nx}-{\\bf x}_0)^t H_0({\\bf x}-{\\bf x}_0)\n\\end{equation*}\nThis package provides a way of computing values of the first and second\npartial derivatives of a multivariate function that is defined by a sequence\nof computational steps involving arithmetic and elementary functions,\nwithout the need to derive and code expressions for the partial derivatives.\n\n\\subsection{Usage}\n\n\\subparagraph{Definition of a U-variable}\n\nWe shall use ${\\bf x}$ as the generic name of the N-dimensional independent\nvariable vector with respect to which all partial derivatives are defined.\nThe term U-variable is used to denote a sequence of values, consisting of a\nfunction value, values of the function's gradient vector, and optionally the\n(packed) Hessian matrix, evaluated at some point. We assume the Hessian\nmatrix is symmetric, so only one copy of each symmetric pair of elements\nneeds to be stored. We store the lower triangle of the Hessian matrix by\nrows. Equivalently, one could regard this as representing the upper triangle\nby columns. Thus if U() is an array containing a U-variable, $\\{u$, ${\\bf\ng}$, $H\\}$, its contents are defined as follows:\n\\begin{alignat*}{2}\n\\text{U}(1) &=u\\\\\n\\text{U}(1+j) &= g_j &= &\\:\\partial u/\\partial x_j,\\ j = 1,\\ ...,N\\\\\n\\hspace{-15pt}\\text{U}(1+\\text{N}+j+i(i-1)/2)&=\\: h_{i,j}\\: &= &\\:\n\\partial ^2u/\\partial x_i\\partial x_j,\\\\\n&&&\\hspace{-.5in}i = 1,\\ ..., N;\\ j = 1,\\ ...,\\ i.\n\\end{alignat*}\n\nThe required dimension size for a U-variable is $dimu$ = N + 1 if only first\npartial derivatives will be requested, and $dimu$ = (N +2)(N + 1) / 2 if both\nfirst and second partial derivatives are to be computed. For convenience we\nlist the value of $dimu$ {\\bf for the second derivative case} for some values\nof N:\n\n\\begin{tabular}{@{}r*{15}{@{\\ }r}}\nN = & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15\\\\\n$dimu$ = & 3 & 6 & 10 & 15 & 21 & 28 & 36 & 45 & 55 & 66 & 78 & 91 & 105 &\n120 & 136\n\\end{tabular}\n\n\\subparagraph{Distinguishing property of an independent variable}\n\nFor $i$ in [1, N] the scalar component, $x_i$, of the independent variable\nvector, ${\\bf x}$, is distinguished by the unique property that all of its first\nand second partial derivatives are zero except its first partial derivative\nwith respect to $x_i$, which has the value~1.\n\n\\subparagraph{The variables N, M1, and M2.}\n\nN specifies the number of independent\nvariables, and implicitly specifies the storage layout of components within\na U-variable.  M1 and M2 specify the lowest and highest order of partial\nderivatives which the called subroutines are to produce.  A program that\nuses these subroutines must initially call SUSETN (or DUSETN)\nto set N, M1, and M2.\n\n\\subparagraph{The subroutines}\n\nThe subroutines of this package are described in the following sections:\n\n\\begin{description}\n\\item[B.1]  SUSETN, Assigning values to N, M1, and M2.\n\n\\item[B.2]  SUGETN, Fetching values of N, M1, M2, L1, and L2.\n\n\\item[B.3]  SUSET, Assigning a value to a U-variable.\n\n\\item[B.4]  The computational subroutines, except SUREV.\n\n\\item[B.5]  SUREV, series reversion, or function inversion.\n\n\\item[B.6]  Modifications for double-precision.\n\\end{description}\n\n\\subsubsection{SUSETN, Assigning values to N, M1, and M2}\n\nSubroutine SUSETN must be called prior to calling any of the other\nsubroutines of this package.\n\n\\paragraph{Program Prototype, Single Precision}\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf N, M1, M2}\n\\end{description}\n\nAssign values to N, M1, and M2.\n$$\n\\fbox{{\\bf CALL SUSETN(N, M1, M2)}}\n$$\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\n\\item[N]  \\ [in] N specifies the number of independent\nvariables, and implicitly specifies the storage layout of components within\na U-variable.\n\n\\item[M1, M2]  \\ [in] M1 and M2 specify the lowest and highest order of partial derivatives\nwhich the called subroutines are to produce.  M1 and M2 must satisfy:\n 0 $\\leq $ M1 $\\leq $ M2 $\\leq 2.$\n\nMost commonly one will probably\nchoose to set (M1, M2) = (0,0), (0,1), or (0,2), and leave the setting\nunchanged throughout a computation. See Section C for discussion of other\nstrategies for setting (M1,M2).\n\\end{description}\n\n\\subsubsection{SUGETN, Fetching values of N, M1, M2, L1, and L2}\n\n\\paragraph{Program Prototype, Single Precision}\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf N, M1, M2, L1, L2}\n$$\n\\fbox{{\\bf CALL SUGETN(N, M1, M2, L1, L2)}}\n$$\nValues are returned in N, M1, M2, L1, and L2.\n\\end{description}\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[N, M1, M2]  \\ [out] Returns the values that were set on the\nprevious call to SUSETN.\n\n\\item[L1, L2]  \\ [out] Returns values computed from N, M1, and M2.\nL1 and L2 are the indices of the first and last locations in a\nU-variable array that will be subject to change due to the settings\nof N, M1, and M2.\\vspace{5pt}\n\\begin{gather*}\nL1 = \\begin{cases}\n1 & \\text{if} ~ \\text{M1} = 0 \\\\\n2 & \\text{if} ~ \\text{M1} = 1 \\\\\nN+2 & \\text{if} ~ \\text{M1} = 2\n\\end{cases}\\\\\nL2 = \\begin{cases}\n1 & \\text{if} ~ \\text{M1} = 0 \\\\\nN+1 & \\text{if} ~ \\text{M1} = 1 \\\\\n1+N+((N*(N+1))/2) & \\text{if} ~ \\text{M1} = 2\n\\end{cases}\n\\end{gather*}\n\\end{description}\n\n\\subsubsection{SUSET, Assigning a value to a U-variable}\n\nThe integer values N, M1, and M2 must be set by a call to SUSETN\nbefore calling SUSET.  SUSET will only set partial derivatives of orders\nM1 through M2.\n\n\\paragraph{Program Prototype, Single Precision}\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf KEY}\n\n\\item[REAL]  \\ {\\bf VAL, U}($\\geq dimu)$\\newline\n[$dimu = \\text{N}+1 \\text{ or (N}+2)(\\text{N}+1)/2$, see above.]\n\n\\end{description}\n\nAssign values to N, M1, M2, VAL, and KEY.\n$$\n\\fbox{{\\bf CALL SUSET(VAL, KEY, U)}}\n$$\nComputed quantities are returned in U().\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[VAL]  \\ [in] Value to be assigned to the U-variable, U().\n\n\\item[KEY]  \\ [in] Integer in the range, [0, N]. If KEY = 0, U() is set to\nrepresent a variable that is constant relative to the N independent\nvariables, $i.e.$, all of its first and second partial derivatives are set\nto zero.\n\nIf 1 $\\leq $ KEY $\\leq $ N, U() is set to represent the $\\text{KEY}^{th}$\nindependent variable, $i.e.$, its $\\text{KEY}^{th}$ first partial derivative is set\nto~1.0. All of its other first partial derivatives and all of its second\npartial derivatives are set to zero.\n\n\\item[U()]  \\ [out] Array in which this subroutine will define a U-variable\nhaving the value, VAL, and having partial derivative values as specified by\nKEY. Only derivative values of orders M1 through M2 are set.\n\\end{description}\n\n\\subsubsection{The computational subroutines, except SUREV}\n\nThe integer values N, M1, and M2 must be set by a call to SUSETN\nbefore calling any of these subroutines.  These subroutines will only set\npartial derivatives of orders M1 through M2.  To use these subroutines\nwith M1 $>$ 0 read the remarks about M1 $>$ 0 in Section C.\n\nIn describing the following subroutines, U() and V() denote input\nU-variables and Z() denotes an output U-variable. The variables A and I are\ninput variables that are constant relative to ${\\bf x}.$\n\nIn most of these subroutines the output array Z() must occupy storage\nlocations distinct from any of the input data. Exceptions to this rule are\nSUSUM, SUDIF, SUPRO, SUSUM1, SUDIF1, and SUPRO1. The subroutine SUQUO, which\ncomputes $u/v \\rightarrow z$, permits $u$ and $z$ to occupy the same\nstorage, but $v$ and $z$ must occupy distinct storage.\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf I}\n\n\\item[REAL]  \\ {\\bf A, U}($\\geq dimu)${\\bf ,V}($\\geq dimu)${\\bf , Z}($\\geq\ndimu)$\\\\\n{[$dimu = \\text{N}+1 \\text{ or (N}+2)(\\text{N}+1)/2$, see page~1.]}\n\\end{description}\n\nAssign values to I, A, U(), and V(), as appropriate.\n\n\\begin{center}\n{\\bf Two-argument operations with both arguments depending on ${\\bf x}.$}\n\n\\fbox{%\n\\begin{tabular}{@{\\bf \\ }lr}\nCALL\\ SUSUM(U,\\ V,\\ Z) & $u+v \\rightarrow z$\\\\\nCALL\\ SUDIF(U,\\ V,\\ Z) & $u-v \\rightarrow z$\\\\\nCALL\\ SUPRO(U,\\ V,\\ Z) & $u\\times v \\rightarrow z$\\\\\nCALL\\ SUQUO(U,\\ V,\\ Z) & $u/v \\rightarrow z$\\\\\nCALL\\ SUATN2(U,\\ V,\\ Z) & atan2($u,v) \\rightarrow z$\\\\\n\\multicolumn{2}{c}{where for atan2: $-\\pi <z \\leq \\pi \\text{ and } \\tan (z)\n= u/v$}\\\\\n\\end{tabular}}\n\\end{center}\n\n\\pagebreak\n\\begin{center}\n{\\bf Two-argument operations with only one argument depending on $u.$}\n\n\\fbox{%\n\\begin{tabular}{@{\\bf \\ }lr}\nCALL SUSUM1(A, V, Z) & $a+v \\rightarrow z$\\\\\nCALL SUDIF1(A, V, Z) & $a-v \\rightarrow z$\\\\\nCALL SUPRO1(A, V, Z) & $a\\times v \\rightarrow z$\\\\\nCALL SUQUO1(A, V, Z) & $a/v \\rightarrow z$\\\\\nCALL SUPWRI(I, V, Z) & $v^i \\rightarrow z$\\\\\n\\multicolumn{2}{c}{(See following note.)}\\\\\n\\end{tabular}}\n\\end{center}\n\nNote: I may be positive, negative, or zero. If I = 0, SUPWRI sets Z(1) = 1.0\nand all derivative values of $z$ to~0.0, regardless of the given value of $v$%\n. It is an error to have $v = 0.0$ when I $<$ 0.\n\n\\begin{center}\n{\\bf One-argument operations with the argument depending on ${\\bf x}.$}\n\n\\fbox{%\n\\begin{tabular}{@{\\bf \\ }lr}\nCALL SUSQRT(U, Z) & $\\sqrt u \\rightarrow z$\\\\\nCALL SUEXP(U, Z) & $\\exp (u) \\rightarrow z$\\\\\nCALL SULOG(U, Z) & $\\log (u) \\rightarrow z$\\\\\nCALL SUSIN(U, Z) & $\\sin (u) \\rightarrow z$\\\\\nCALL SUCOS(U, Z) & $\\cos (u) \\rightarrow z$\\\\\nCALL SUTAN(U, Z) & $\\tan (u) \\rightarrow z$\\\\\nCALL SUASIN(U, Z) & asin$(u) \\rightarrow z$\\\\\nCALL SUACOS(U, Z) & acos$(u) \\rightarrow z$\\\\\nCALL SUATAN(U, Z) & atan$(u) \\rightarrow z$\\\\\nCALL SUSINH(U, Z) & sinh$(u) \\rightarrow z$\\\\\nCALL SUCOSH(U, Z) & cosh$(u) \\rightarrow z$\\\\\nCALL SUTANH(U, Z) & tanh$(u) \\rightarrow z$\\\\\n\\end{tabular}}\n\\end{center}\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[A]  \\ [in] Floating point value that is independent of ${\\bf x}.$\n\n\\item[I]  \\ [in] Integer value that is independent of ${\\bf x}.$\n\n\\item[U()]  \\ [in] An input U-variable. Must contain defined values for\nderivatives of orders~0 through M2.\n\n\\item[V()]  \\ [in] An input U-variable. Must contain defined values for\nderivatives of orders~0 through M2.\n\n\\item[Z()]  \\ [inout] If M1 $>$ 0, this array must contain defined values of\nderivatives of orders~0 through M1 $-$ 1 on entry. On return it will also contain\ncomputed values of derivatives of orders M1 through M2. If M1 = 0, no input\nvalues are required in Z().\n\\end{description}\n\n\\subsubsection{SUREV, Series Reversion or Function Inversion}\n\nLet $u_i$, $i = 1$, ..., $n$, be $n$ functions of an $n$-vector, ${\\bf t}$.\nSuppose values of the $u_i$'s and their first and second partial\nderivatives with respect to the components of ${\\bf t}$ are known for a particular\nvalue of ${\\bf t}$. Then, if the Jacobian matrix of the transformation is\nnonsingular at this point, one can regard the $t_j$'s as functions\nof the $u_i$'s in some neighborhood of this point in $u$-space. In\nthis situation this subroutine can compute values of the first and second\npartial derivatives of the $t_j$'s with respect to the $%\nu_i$'s at this point.\n\nGiven:\n\\begin{gather}\n\\hspace{-15pt}t_j \\text{ in TU}(1,\\ j),\\ j = 1,\\ ...,\\ n,\\\\\n\\hspace{-15pt}u_i \\text{ in UT}(1,\\ i),\\ i = 1,\\ ...,\\ n,\\\\\n\\hspace{-15pt}\\partial u_i/\\partial t_j\\text{ in UT}(1+j,\\ i),\\ j = 1,\\\n...,\\ n;\\ i = 1,\\ ...\\ n,\\hspace{-1in}\\\\\n\\hspace{-15pt}\\partial ^2u_i/\\partial t_j\\partial t_k \\text{ in UT}\n(1+n+k+j(j-1)/2),\\ i),\\\\\n\\hspace{.5in}j= 1,\\ ...,\\ n;\\ k = 1,\\ ...,\\ j;\\ i = 1,\\ ...,\\ n.\n\\notag\n\\end{gather}\nIf the Jacobian matrix with elements $\\partial u_i/\\partial t_j$ is\nnonsingular, this subroutine will compute the first and second partial\nderivatives of the $t_j$'s with respect to the $u_i$'s and\nstore them as\n\\begin{gather}\n\\hspace{-15pt}\\text{TU}(1+i, j) = \\partial t_j/\\partial u_i,\\ i =\n1,\\ ...,\\ n;\\ j = 1,\\ ...,\\ n,\\hspace{-1in}\\\\\n\\hspace{-15pt}\\text{TU}(1+n+k+i(i-1)/2,\\ j) = \\partial ^2t_j/\\partial\nu_i\\partial u_k,\\\\\n\\hspace{.5in}i =1,\\ ...,\\ n;\\ k = 1,\\ ...,\\ i;\\ j = 1,\\ ...,\\ n,\\notag\n\\end{gather}\nThe integer values N, M1, and M2 must be set by a call to SUSETN\nbefore calling SUREV.  N gives\nthe value of $n$ for Eqs.(1--6) above.\nRequire 0 $\\leq $ M1 $\\leq $ M2 $\\leq $ 2.\n\nIf M2 = 0, SUREV returns with no action.\n\nIf M2 = 1, SUREV only computes Eq.(5), and it is not necessary to provide\nthe data of Eq.(4).\n\nIf M2 = 2 and M1 = 0 or~1, SUREV computes Eqs.(5--6).\n\nIf M2 = 2 and M1 = 2, it is assumed that the assignment of Eq.(5) has\nalready been done, and thus SUREV only computes Eq.(6).\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf IWORK}(N){\\bf , LDIM}\n\n\\item[REAL]  \\ {\\bf RCOND, TU}(LDIM, $\\geq $N){\\bf , UT}(LDIM, $\\geq $N){\\bf %\n, WORK}($\\geq 3\\times \\text{N}^2$) \\ [LDIM $\\geq dimu = \\text{N}+1 \\text{ or}\\\\\n(\\text{N}+2)(\\{text{N}+1)/2$, see page 1.]\n\\end{description}\n\nAssign values to LDIM, UT() and part of TU().\n\n\\begin{center}\n\\fbox{%\n\\begin{tabular}{@{\\bf }c}\nCALL SUREV( UT, TU, LDIM,\\\\\nRCOND, IWORK, WORK)\\\\\n\\end{tabular}}\n\\end{center}\n\nComputed quantities are returned in RCOND and TU().\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[UT(,)]  \\ [in] Must contain the data of Eqs.(2--4) on entry, except as\nnoted above for certain values of M1 and M2.\n\n\\item[TU(,)]  \\ [inout] Must contain the data of Eq.(1) on entry, and will\nhave the data of Eqs.(5--6) assigned by SUREV, except as noted above for\nparticular values of M1 and M2.\n\n\\item[LDIM]  \\ [in] Leading dimension for the arrays UT(,) and TU(,).\nRequire LDIM $\\geq dimu$, where $dimu  = \\text{N}+1 \\text{ or }\n(\\text{N}+2)(\\text{N}+1)/2$, see\npage~1.\n\n\\item[RCOND]  \\ [out] Estimate of the reciprocal condition number of the\nJacobian matrix with elements $\\partial u_i/\\partial t_j$, given in UT().\nOnly computed when M1 $\\leq $ 1 and M2 $\\geq 1$. Is in the range [0.0,~1.0].\n\nA well conditioned problem has values near~1.0. Near zero means badly\nconditioned. Equal to zero means singular, in which case the subroutine\ncannot complete its computation.\n\n\\item[IWORK()]  \\ [scratch] Integer work space of size at least N.\n\n\\item[WORK()]  \\ [scratch] Floating-point work space of size at least $%\n3\\times \\text{N}^2.$\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nFor double-precision usage, replace the initial S in the name of each\nsubroutine by D, and replace the REAL declarations by DOUBLE PRECISION.\n\n\\subsection{Examples and Remarks}\n\n\\subsubsection{Example}\n\nAs a demonstration problem, consider the following formulae for transforming\na set of 3-dimensional rectangular coordinates $(x,y,z)$ to spherical\ncoordinates $(r,\\varphi ,\\theta )$ and the inverse transformation formulae:\n\\begin{align*}\ns &= \\sqrt{x^2 + y^2}\\\\\nr &= \\sqrt{s^2 + z^2}\\\\\n\\varphi &= \\atan2(y,\\ x)\\\\\n\\theta &= \\tan^{-1}(z/s)\\\\\nx &= r\\ \\cos \\ \\varphi \\ \\cos \\ \\theta \\\\\ny &= r\\ \\sin \\ \\varphi \\ \\cos \\ \\theta \\\\\nz &= r\\ \\sin \\ \\theta\n\\end{align*}\nThe demonstration program, DRSUCOMP, performs this mapping from $(x,y,z)$ to\n$(r,\\varphi ,\\theta )$ with computation of all of the first and second partial\nderivatives of $r$, $\\varphi $, and $\\theta $ with respect to $x$, $y$, and $z$%\n. As a check on the computation the program then transforms back to $(x,y,z)$%\n. Results are shown in ODSUCOMP. Note that the final $(x,y,z)$ agrees with\nthe initial $(x,y,z)$ in the values and the first and second partial\nderivatives.\n\nTo demonstrate series reversion (or function inversion) the program assigns\nthe values of $(r,\\varphi ,\\theta )$ and its first and second partial\nderivatives with respect to $(x,y,z)$ to the array UT(,), and then assigns the\nvalues of $(x,y,z)$ to TU(1,~1:3). It then uses SUREV to compute the first\nand second partial derivatives of $(x,y,z)$ with respect to $(r,\\varphi ,\\theta\n)$, storing these in TU(2:10,~1:3). This computation is checked by computing\nthe same quantities in a different way.\n\n\\subsubsection{Omitting derivative computation}\n\nTo save time when developing new code using this package, one may run with\n(M1, M2) = (0,~0) until one is satisfied that the function evaluation is as\ndesired, and then increase M2 to activate the derivative computation.\n\n\\subsubsection{Setting M1 $>$ 0}\n\nThere are some algorithms, such as for optimization, in which one does not\nneed to compute partial derivatives at every point at which the function is\nevaluated. Depending on how significant efficiency is in a particular\napplication, one may wish to consider methods of separating the function and\nderivative computation using this package. One can compute only the function\nvalue by setting (M1, M2) = (0,~0), or one can compute the function value\nand first partial derivatives by setting (M1, M2) = (0,~1).\n\nIf one has computed the function value at an argument value, ${\\bf x}$, with (M1,\nM2) = (0,~0), and has kept all intermediate quantities in distinct storage\nlocations, then one can repeat the sequence of subroutine calls with (M1,\nM2) = (1,~1) to compute the first partial derivatives at the same point,\n${\\bf x}$%\n, without the function value being recomputed. In general, computation with\nM1 $>$ 0 is only valid if all $in$ and $inout$ arrays in each subroutine call\ncontain values of all derivatives of orders~0 through M1 $-$ 1 computed\npreviously with the same ${\\bf x}.$\n\n\\subsection{Functional Description}\n\nThis U-computation package is based on the ideas presented in\n\\cite{Wengert:1964:ASA}.  See the description of W-computation in\nChapter~17.1 for a summary of these ideas.  Whereas the W-computation\npackage generalizes the order of differentiation, this U-computation\npackage generalizes the number of independent variables.\n\nLet $f()$ be a scalar-valued function of the scalar variable $u$, and use\nprimes to denote differentiation with respect to $u$. Let $u$ depend on the\nN-vector ${\\bf x}$ and denote partial derivatives of $u$ with respect to $x_i$ by\nappropriate subscripts. This package computes first and second partial\nderivatives of $f()$ using the formulae:\n\\begin{align*}\n\\partial f(u)/\\partial x_i &= f^{\\prime}(u) u_i\\\\\n\\partial ^2f(u)/\\partial x_i\\partial x_j &= f^{\\prime}(u) u_{i,j} +\nf^{\\prime\\prime}(u) u_i u_j\n\\end{align*}\n\n\\nocite{Griewank:1991:ADA}\n\\nocite{Lawson:1971:CDU}\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nN must be positive. M1 and M2 must satisfy 0\\ $\\leq $ M1\n$\\leq $ M2 $\\leq $ 2. See the discussion in Section~C for cautions regarding\nusage with M1 $>$ 0. These conditions on N, M1, and M2 are not tested by\nthe subroutines and their violation may cause unpredictable actions.\n\n\\subsubsection{Invalid arguments for derivative computation}\n\nThe user will likely be accustomed to avoiding sending invalid arguments to\nthe elementary functions, such as a negative argument to the square root. In\ncomputing derivatives there are some additional singularities to avoid. Note\nthat the derivative is infinite at zero for the square root, and at $\\pm $1\nfor arcsin and arccosine.\n\n\\subsubsection{Error handling}\n\nFollowing is a list of error conditions the package detects and for which error\nmessages are issued. These errors are fatal in the sense that the requested\noperation cannot be done; however, the default action is to return after\nissuing an error message. The user can use the MATH77 library subroutine,\nERMSET of Chapter~19.2, to alter this action to cause a STOP if desired. Error conditions\nnot on this list, $e.g.$, negative argument in log, will be handled by the\nusual host system error handler.\n\n\\begin{tabular}{@{}l@{\\ \\ }l}\n\\bf Error No.\\\\\n\\bf \\& Program & \\multicolumn{1}{c}{\\bf Explanation}\\\\\n\\bf 1 SUASIN & Infinite derivative when arg = $-$1\\ or +1\\\\\n\\bf 1 SUACOS & Infinite derivative when arg = $-1$\\ or +1\\\\\n\\bf 2 SUSQRT & Infinite derivative when arg = 0\\\\\n\\bf 3 SUQUO1 & Zero divisor\\\\\n\\bf 4 SUPWRI & $\\text{U}^{\\text{M}}$ is infinite when U = 0 and M $<$ 0\\\\\n\\bf 5 SUQUO & Zero divisor\\\\\n\\bf 6 SUREV & Singular Jacobian matrix\n\\end{tabular}\n\n\\subsection{Supporting Information}\n\nThe source language is ANSI Fortran~77. All program units reference\nCOMMON blocks /UCOM1/ and /UCOM2/.\n\nAll of the double precision entry points except DUREV require files:\n\nDUCOMP, ERFIN, ERMSG, IERM1, and IERV1.\n\nAll of the single precision entry points except SUREV require files:\n\nSUCOMP, ERFIN, ERMSG, IERM1, and IERV1.\n\nDUREV requires: DASUM, DAXPY, DDOT, DGECO, DGEFA, DGEI, DSCAL, DSWAP,\nDUREV, ERFIN, ERMSG, and IDAMAX.\n\nSUREV requires: SASUM, SAXPY, SDOT, SGECO, SGEFA, SGEI, SSCAL, SSWAP,\nSUREV, ERFIN, ERMSG, and ISAMAX.\\vspace{-5pt}\n\\begin{center}\n\\begin{tabular}{llll}\n\\multicolumn{4}{c}{\\bf Entries}\\\\\nDUACOS & DUASIN & DUATAN & DUATN2\\\\\nDUCOS & DUCOSH & DUDIF & DUDIF1\\\\\nDUEXP & DUGETN & DULOG & DUPRO\\\\\nDUPRO1 & DUPWRI & DUQUO & DUQUO1\\\\\nDUREV & DUSET & DUSETN & DUSIN\\\\\nDUSINH & DUSQRT & DUSUM & DUSUM1\\\\\nDUTAN & DUTANH & SUACOS & SUASIN\\\\\nSUATAN & SUATN2 & SUCOS & SUCOSH\\\\\nSUDIF & SUDIF1 & SUEXP & SUGETN\\\\\nSULOG & SUPRO & SUPRO1 & SUPWRI\\\\\nSUQUO & SUQUO1 & SUREV & SUSET\\\\\nSUSETN & SUSIN & SUSINH & SUSQRT\\\\\nSUSUM & SUSUM1 & SUTAN & SUTANH\\\\\n\\end{tabular}\n\\end{center}\\vspace{-5pt}\nDesigned by C. L. Lawson, JPL, 1971. Adapted to Fortran~77 for the JPL\nMATH77 library, Aug.~1987. Added SUREV/DUREV, February~1992.  Added\nSUSETN, DUSETN, SUGETN, and DUGETN August~1994.\n\n\n%\\rule{0pt}{80pt}\n\n\\begcodenp\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSUCOMP}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{sucomp}}\n\\newpage\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSUCOMP}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{sucomp}}\n\\end{document}\n", "meta": {"hexsha": "c956c825da7bbcbca3668e517d375757e01b5e40", "size": 22807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch17-02.tex", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "doc/doctex/ch17-02.tex", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "doc/doctex/ch17-02.tex", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 38.5253378378, "max_line_length": 98, "alphanum_fraction": 0.7038190029, "num_tokens": 7371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899665, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7098068918551903}}
{"text": "% !TEX root = Main.tex\n\\section{Optimization}\n\n\\subsection*{Alternating Least Squares}\n$f(U,v_i)=\\sum_{(i,j)\\in I} (a_{i,j} - \\langle u_j, v_i \\rangle)^2$\\\\\n$f(u_i,V)=\\sum_{(i,j)\\in I} (a_{i,j} - \\langle u_j, v_i \\rangle)^2$\\\\\nLeast squares problems which are convex.\n\n\n\\subsection*{Coordinate Descent}\n1. init: $\\mathbf{x}^{(0)} \\in \\mathbb{R}^D$\\\\\n2. for $t = 0 \\ \\text{to} \\ \\mathit{maxIter}$:\\\\\n3. sample $d \\in_{u.a.r.} \\{1, \\ldots, D\\}$\\\\\n4. $u^\\star = \\argmin_{u \\in \\mathbb{R}} f(x_1^{(t)}, .., x_{d-1}^{(t)}, u, x_{d+1}^{(t)}, .., x_D^{(t)})$\\\\\n5. $\\mathbf{x}_d^{(t+1)} = u^\\star$ and $\\mathbf{x}_i^{(t+1)} = \\mathbf{x}_i^{(t)}$ for $i \\neq d$\n\n\\subsection*{Gradient Descent (or Deepest Descent)}\n\\textbf{Gradient}: $\\nabla f(\\mathbf{x}) := \\left( \\frac{\\partial f(\\mathbf{x})}{\\partial \\mathbf{x}_1}, \\ldots, \\frac{\\partial f(\\mathbf{x})}{\\partial \\mathbf{x}_D} \\right)^\\top$\n\n1. init: $\\mathbf{x}^{(0)} \\in \\mathbb{R}^D$\\\\\n2. for $t = 0 \\ \\text{to} \\ \\mathit{maxIter}$:\\\\\n3. $\\mathbf{x}^{(t+1)} = \\mathbf{x}^{(t)} - \\gamma \\nabla f(\\mathbf{x}^{(t)})$, usually $\\gamma \\approx \\frac{1}{t}$\n\n\\subsection*{Stochastic Gradient Descent (SGD)}\nAssume \\textbf{Additive Objective}:\\\\\n$f(x) = \\frac{1}{N}\\sum_{n=1}^{N}f_n(x)$\\\\\n1. init: $\\mathbf{x}^{(0)} \\in \\mathbb{R}^D$\\\\\n2. for $t = 0 \\ \\text{to} \\ \\mathit{maxIter}$:\\\\\n3. sample $n \\in_{u.a.r.} \\{1, \\ldots, N\\}$\\\\\n4. $\\mathbf{x}^{(t+1)} = \\mathbf{x}^{(t)} - \\gamma \\nabla f_n(\\mathbf{x}^{(t)})$, typically  $\\gamma \\approx \\frac{1}{t}$.\n\n\\subsection*{Projected Gradient Descent (Constrained Opt.)}\nminimize $f(x)$, $x \\in Q$ (constraint).\\\\\n\\textbf{Project} $x$ onto $Q$: $P_Q(\\mathbf{x}) = \\argmin_{y \\in Q} \\|\\mathbf{y} - \\mathbf{x}\\|$,\\\\\n\\textbf{Update}: $\\mathbf{x}^{(t+1)} = P_Q[\\mathbf{x}^{(t)} - \\gamma \\nabla f(\\mathbf{x}^{(t)})]$,\\\\\n$\\mathbf{x}^{(t+1)}$ is unique if $Q$ convex.\n\n\\subsection*{Lagrangian Multipliers}\nMinimize  $f(\\mathbf{x})$ s.t. $g_i(\\mathbf{x}) \\leq 0,\\ i = 1, .., m$ (\\textbf{inequality constr.}) and $h_i(\\mathbf{x}) = \\mathbf{a}_i^\\top \\mathbf{x} - b_i = 0,\\ i = 1, .., p$ (\\textbf{equality constraint})\n\\begin{compactdesc}\n\t\\item[Lagrangian:] $L(\\mathbf{x}, \\boldsymbol{\\lambda}, \\boldsymbol{\\nu}) := f(\\mathbf{x}) + \\sum_{i=1}^m \\lambda_i g_i(\\mathbf{x}) + \\sum_{i=1}^p \\nu_i h_i(\\mathbf{x})$\n\t\\item[Dual function:] $D(\\boldsymbol{\\lambda}, \\boldsymbol{\\nu}) := \\inf_{\\mathbf{x}} L(\\mathbf{x}, \\boldsymbol{\\lambda}, \\boldsymbol{\\nu}) \\in \\mathbb{R}$\n\t\\item[Dual Problem:] $\\max_{\\boldsymbol{\\lambda}, \\boldsymbol{\\nu}} D(\\boldsymbol{\\lambda}, \\boldsymbol{\\nu})$ s.t. $\\boldsymbol{\\lambda} \\geq \\mathbf{0}$. Note: $\\max_{\\boldsymbol{\\lambda}, \\boldsymbol{\\nu}} D(\\boldsymbol{\\lambda}, \\boldsymbol{\\nu}) \\le \\min_\\mathbf{x}{f(\\mathbf{x})}$, equality if $dom\\ f$ and $f$ convex\n\\end{compactdesc}\n\n\\subsection*{Convex Optimization}\nDef.: $\\{(x,t)|x \\in dom f, f(x) \\leq t\\}$, $f : \\mathbb{R}^D \\rightarrow \\mathbb{R}$ is convex, if $dom\\ f$ is a convex set, and if $\\forall \\mathbf{x}, \\mathbf{y} \\in dom\\ f$, and for $0 \\leq \\alpha \\leq 1$: $f(\\alpha \\mathbf{x} + (1 - \\alpha)\\mathbf{y}) \\leq \\alpha f(\\mathbf{x}) + (1-\\alpha)f(\\mathbf{y})$. local=global min, \\textbf{Convergence}: $f(\\mathbf{x}^{(t)}) - f(\\mathbf{x}^*) \\le \\frac{c}{t}$.\n\\textbf{Subgradient} $g \\in \\mathbb{R}^D$ of $f$ at $\\mathbf{x}$: $f(\\mathbf{y}) \\geq f(\\mathbf{x}) + g^\\top(\\mathbf{y}-\\mathbf{x}) \\ \\forall \\mathbf{y}$\n\n\\subsection*{Convex Relaxation}\nReplace non-convex rank constraints by convex norm constraints.\\\\\nNuclear norm: $||A||_* = \\sum_i \\sigma_i$\n", "meta": {"hexsha": "617ba0afbd157faccb56ccbade8c71015fbc120b", "size": 3523, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Optimization.tex", "max_stars_repo_name": "phschaad/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "2352d41e2bc22d8da3bca6465b355edeed4a7c12", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Optimization.tex", "max_issues_repo_name": "phschaad/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "2352d41e2bc22d8da3bca6465b355edeed4a7c12", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Optimization.tex", "max_forks_repo_name": "phschaad/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "2352d41e2bc22d8da3bca6465b355edeed4a7c12", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-08T22:47:36.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-08T22:47:36.000Z", "avg_line_length": 66.4716981132, "max_line_length": 407, "alphanum_fraction": 0.5972182799, "num_tokens": 1486, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.709806873326617}}
{"text": "\\lab{Complexity and Sparse Matrices}{Complexity and Sparse Matrices}\n\n\\objective{Introduce the temporal and spatial complexity and explore SciPy's methods for working with sparse matrices.}\n\\label{lab:complexity}\n\n\\section*{Complexity} \nTwo major constraints on computing are time and available memory (or `space').\nThe \\emph{temporal complexity} and \\emph{spatial complexity} of an algorithm measure how much of these resources the algorithm requires. \nThis lab intoduces complexity using examples and intuition; for a rigorous introduction, see Volume 2 of the textbook.\n\n\\subsection*{Temporal Complexity}\nOne of the most important questions in scientific computing is ``How long will a computer take to execute this algorithm?\"\nFor example, suppose an algorithm operating on a 1-D array of length $n$ requires $f(n)$ calculations, where\n\n\\begin{equation*}\nf(n) = \\frac{3n^3}{2} + 75n^2 + 250n + 30.\n\\end{equation*}\n\nAs $n$ increases, the growth of $f(n)$ is dominated by the $n^3$ term.\nThis gives us information about how the runtime of our algorithm increases when we increase input size. \nIf we double the size of the input $n$, we would expect the algorithm to need about $2^3=8$ times as many steps, which would make it run about 8 times as long.\n\nThe function $f(n)$ above is called the \\emph{temporal complexity} of the algorithm. \nIn general, $n$ is a positive integer that somehow describes the size of the inputs to your algorithm. \nFor example, perhaps your algorithm accepts $n \\times n$ arrays, or perhaps it accepts 1-D arrays of length $n$. \nThe temporal complexity of your algorithm is a function that accepts an input size $n$ and returns the number of steps the algorithm needs to execute on that input. \nAs such, temporal complexity is a precise way to describe how the execution time of your algorithm increases as the size of your input increases.\n\nOften, we do not care about the exact definition of $f(n)$ so much as its behavior when $n$ gets large. \nThis leads to the notion of an \\emph{asymptotic upper bound}. \nAn asymptotic upper bound is another function $g(n)$ such that, eventually, $f(n)$ is less than some constant multiple of $g(n)$. \nIn the above example, $n^3$ is an asymptotic upper bound for $f(n)$ (see Figure \\ref{fig:asymp_upper_bound}). \nIf $g(n)$ is an asymptotic upper bound for $f(n)$, we say $f(n)$ is $O(g(n))$. \nSo in the example above, $f(n)$ is $O(n^3)$ (spoken ``Big O of n cubed'' or ``order of n cubed\").\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{asymp_upper_bound.pdf}\n\\caption{When $n$ is bigger than 160, $f(n)$ is less than $2n^3$. This means that $n^3$ is an asymptotic upper bound for $f(n)$, so we say $f(n)$ is $O(n^3)$.}\n\\label{fig:asymp_upper_bound}\n\\end{figure}\n\nFor example, adding two $n \\times n$ matrices is $O(n^2)$. \nThis is because it takes 1 step to add each pair of elements in two $n \\times n$ arrays, and there are $n^2$ such pairs.\nBy comparison, calculating the inverse of a $n \\times n$ matrix using Gaussian row reduction is $O(n^3)$. \n(More efficient algorithms for matrix inversion exist as well.)\n\n\\begin{comment}\nHow do we determine the temporal complexity of a piece of code?\nCalculating the exact temporal complexity of an algorithm is fairly difficult.\nHowever, there are ways to heuristically evaluate the asymptotic behavior of an algorithm's temporal complexity. \nFor example, consider the following code.\n\n\\begin{lstlisting}\ns = 0\nfor i in xrange(n):\n    s = s + i\n\\end{lstlisting}\n\nThe code above is $O(n)$ because it takes approximately $n$ steps to complete. \nFor-loops are a good indicator of the complexity.  \nA double for-loop suggests $O(n^2)$ or worse.  \n\nYou can also approximate the temporal complexity of a function by timing how long it takes to run on inputs of various sizes. \nThis is especially useful if your temporal complexity is some polynomial. \nIn this case, the ratios of the run times will give you clues about the temporal complexity of the algorithm. \nFor example, if an algorithm is $O(n^3)$, then doubling the size of the input should make the algorithm take $(2n)^3/n^3=8$ times as long.\n\\begin{comment}\n\\begin{problem}\nTime the runtime of the following code for \\li{n = 1000, 2000, 4000, 8000}.\n\n\\lstinputlisting[style=fromfile]{test.py}\n\nNow write a function that takes no arguments and does the following: \n\\begin{enumerate}\n\\item Plots the four runtimes (use \\li{[1000, 2000, 4000, 8000]} or an equivalent array object as your domain).\nThe plot should look like Figure \\ref{prob1} if using the \\li{plt.scatter} command. \n\\item Returns the average ratio between successive runtimes (one such ratio would be the runtime for $n = 2000$ divided by the runtime for $n = 1000$).\n\\end{enumerate}\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{prob1.pdf}\n\\caption{The plot of problem 1}\n\\label{prob1}\n\\end{figure}\n\\end{problem}\n\n\n\\begin{problem}\\label{complexity_ratios}\nFill in the following table. Here, $f(n)$ is the temporal complexity of an algorithm. The quantity $f(2n)/f(n)$ tells you how much longer each algorithm will take to run when you double the size of the input.\n\n\\begin{center}\n\\begin{tabular}{| l |p{15mm}|p{15mm}|p{15mm}|p{15mm}|p{15mm}|}\\hline\n$f(n)$ & $n$ & $n^2$ & $n^3$ & $n^4$  \\\\ \\hline\n$f(2n)/f(n)$&  & & &  \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\end{problem}\n\n\\begin{problem}\\label{complexity_timeit}\nDetermine the temporal complexity of each of the following functions. \n\\begin{enumerate}\n\\item \n\\begin{lstlisting}\ndef function1(n):\n    t = 0\n    for i in xrange(n):\n        t += sum(xrange(i))\n\\end{lstlisting}\n\n\\item\n\\begin{lstlisting}\ndef function2(n):\n    sum(xrange(1000*n))\n\\end{lstlisting}\n\\end{enumerate}\n\nDo this as follows:\n\\begin{enumerate}\n\\renewcommand{\\theenumi}{\\alph{enumi}}\n\\item Time how long the function takes to run on an input of size $n$ for $n=1000, 2000, 4000$, and $8000$.\n\\item Compute the averages of the ratios between successive runtimes from part (1).\n\\item Use Problem \\ref{prob:complexity_ratios} to determine the temporal complexity.\n\\end{enumerate}\n\\end{problem}\n\n\\begin{problem}\nCreate a plot depicting the complexities you found in Problem \\ref{prob:complexity_timeit} by following these steps. \n\\begin{enumerate}\n\\item For each function, plot a line using $n=1000, 2000, 4000$, and $8000$ for $x$-values and your runtimes for $y$-values. When you call the function \\li{plt.plot()}, specify a value for the keyword parameter \\li{label} so you can reference each line later. For example, the call \\li{plt.plot( x, y, label=\"Function 1\")} attaches the label \"Function 1\" to this line.\n\\item After plotting all your lines, call \\li{plt.legend()} to draw a legend on your graph. Use the keyword argument \\li{loc} to specify the location of the legend. Some possible values are \\li{'upper left'} and \\li{'right'}. See the documentation for more options.\n\\end{enumerate}\nYour graph should look something like this.\n\n[TODO: put a figure here]\n\\end{problem}\n\\end{comment}\n\n% TODO: THIS WAS IN THE NUMPY LAB BUT REALLY SHOULD BE IN THIS LAB!!!\n\\begin{comment}\n\\begin{problem} % Problem 2: Time matrix multiplication.\nFor a $m\\times n$ matrix $A$ with entries $a_{ij}$ and an $n\\times l$ matrix $B$ with entries $b_{ij}$, the matrix product $C = AB$ is defined entrywise by the formula:\n\\[c_{ij} = \\sum_{k=1}^N a_{ik}b_{kj}\\]\n\nThe following function performs matrix multiplication using nested lists without using NumPy.\n\n\\begin{lstlisting}\ndef matrix_multiply(A, B):\n    \"\"\"Calculate the matrix product AB.\n    Each parameter is a list of lists.\n    \"\"\"\n    # Get the dimensions of the matrices and initialize the new 'matrix'.\n    m, n, l = len(A), len(B), len(B[0])\n    result = []\n\n    # Calculate each entry of the new matrix.\n    for i in range(m):\n        for j in range(l):\n            result.append(sum([A[i][k] * B[k][j] for k in xrange(n)]))\n    return result\n\\end{lstlisting}\n\nWrite a function that times matrix multiplication with the above function, and compare it with numpy.dot().\nA random matrix $1000\\times 1000$ as a list of lists can be created with\n\\begin{lstlisting}\na = [[random() for j in xrange(1000)] for i in xrange(1000)]\n\\end{lstlisting}\n\n\\end{problem}\n\n\n% SIMPLIFIED VERSION OF THE CODE BELOW (don't include from other file)\n\n\nIterating through this triple \\li{for} loop is very expensive.\nNumPy also uses loops, but it uses C loops instead of Python loops.\nCompare the difference between the pure Python and the NumPy ways:\n\n% \\lstinputlisting[style=fromfile]{arr_mult.py}\n\nTable \\ref{table:square_times} documents how long\\footnote{You can replicate this experiment yourself. In IPython, you can find the execution time of a line of code by prefacing it with \\li{\\%timeit}. \nIf you aren't using IPython, you will need\nto use the timeit function documented here: \\url{https://docs.python.org/2/library/timeit.html}.} \none computer took to square a $k \\times k$ matrix in both Python (using the function \\li{arr_mult}) and NumPy (using the method you found in Problem \\ref{prob:simple_multiply}) for various values of $k$. \nAs you can see, NumPy is much faster.\nOne reason for this is that algorithms in NumPy are usually implemented in C or in Fortran. \n\n\\begin{table}\n \\begin{tabular}{|c|l|l|} \\hline Data Structure & $k\\times k$ & Time (s) \\\\ \\hline \n Python List    & $10\\times10$  & 0.0002758503 \\\\ \n \\cline{2-3}    & $100\\times100$    & 0.1336028576 \\\\ \n \\cline{2-3}    & $1000\\times1000$ & 200.4009799957 \\\\ \n %& $1\\times1$      & 0.0000181198 \\\\ \n\\hline \\hline \n NumPy Array    & $10\\times10$  & 0.0000109673 \\\\\n \\cline{2-3}    & $100\\times100$    & 0.0009210110 \\\\ \n \\cline{2-3}    & $1000\\times1000$ & 2.1682999134 \\\\\n %& $1\\times1$      & 0.0000298023 \\\\ \n \\hline \\end{tabular}\n \\caption{Time for one computer to square a $k \\times k$ matrix in Python and NumPy.}\n\\label{table:square_times} \n\\end{table} \n% \n\nNumPy is optimized for fast array computations.\n\n\\end{comment}\n\n\n\\subsection*{Spatial Complexity}\nAnalogous to temporal complexity, the spatial complexity of an algorithm is a function that describes how the algorithm's memory use increases as input sizes to the algorithm increase. For example, if your algorithm needs to store an $n \\times n$ matrix, its memory use will increase at least as fast as $n^2$. Spatial complexity is important because  the spatial complexity of an algorithm can affect its speed in several ways. The most important way is that when the memory usage exceeds the amount of available RAM, the machine must use either the hard disk or some other slower method of storage.\n\nThis vocabulary allows us to discuss the question at the start of this lab: ``How long will a computer take to execute this algorithm?\" The amount of time a computer takes to execute an algorithm depends both on the algorithm's temporal complexity and on its spatial complexity. \n\n\\subsection*{Timing Functions}\nWe can empirically investigate a function's temporal and spatial complexity by timing how long it takes to run.\nIn IPython\\footnote{If you aren't using IPython, you will need\nto use the timeit function documented here: \\url{https://docs.python.org/2/library/timeit.html}.}, you can time a line of code by prefacing it with the command \\li{\\%timeit}.\nAs an example, we time how long it takes to add the numbers from 1 to 1000.\n\\begin{lstlisting}\n>>> \\%timeit sum(xrange(1000))\n100000 loops, best of 3: 12.2 us per loop\n\\end{lstlisting}\nThis output means that the computer ran our line 100,000 times and averaged the runtimes.\nThe computer repeated this experiment 3 times, and the best average was 12.2 microseconds.\n\n\\begin{problem}\\label{prob:complexity_problem}\nIn this problem you will analyze the complexity of the following functions:\n\n\\begin{lstlisting}\n# Run through a single for loop.\ndef func1(n):\n    n = 500*n\n    sum(xrange(n))\n# Run through a double for loop.\ndef func2(n):\n    n = 3*n\n    t = 0\n    for i in xrange(n):\n        for j in xrange(i):\n            t += j\n# Square a matrix.\ndef func3(n):\n    n = int(1.2*n)\n    A = np.random.rand(n, n)\n    np.power(A, 2)\n# Invert a matrix.\nfrom scipy import linalg as la\ndef func4(n):\n    A = np.random.rand(n, n)\n    la.inv(A)\n# Find the determinant of a matrix.\nfrom scipy import linalg as la\ndef func5(n):\n    n = int(1.25*n)\n    A = np.random.rand(n, n)\n    la.det(A)\n\\end{lstlisting}\n\nPlot your results in the following manner:\n\\begin{enumerate}\n\\item Time how long each function takes to run on an input of size $n$ for $n=100, 200, 400$, and $800$.\n\\item For each function, plot a line using $100, 200, 400$, and $800$ for the $x$-values and your runtimes for the $y$-values. Make sure your $y$-values are all in the same units! When you call the matplotlib function \\li{plot}, specify a value for the keyword parameter \\li{label} so that you can reference each line later. For example, the call \\li{plt.plot(x, y, label='Function 1')} attaches the label ``Function 1\" to the line made by \\li{x} and \\li{y}.\n\\item After plotting all your lines, call the function \\li{legend} to draw a legend on your graph. Use the keyword argument \\li{loc} to specify the location of the legend. Some possible values are \\li{'upper left'} and \\li{'right'}. See the documentation for more options. Your final graph should look something like the figure below.\\footnote{From this graph, you can see that inverting a matrix is an incredibly time-consuming operation. In Lab \\ref{lab:ChangeBasis} you will learn fast algorithms for solving linear systems without inverting matrices. In fact, inverting matrices is so costly in terms of temporal and spatial complexity that there is hardly ever a good reason to do it.}\n\\end{enumerate}\nNote that we rescaled the inputs to the functions so that your lines would begin at roughly the same place on the y-axis.\n\n\\centering\n\\includegraphics[width=\\textwidth]{complexity_problem.pdf}\n\n\\end{problem}\n\n\\section*{Sparse Matrices}\nA \\emph{sparse} matrix is a matrix that has relatively few nonzero elements. \nSparse matrices arise frequently in both theoretical and real-world applications. \nWe can take advantage of the sparse structure of these matrices to use less memory and to decrease computation time.\n\nFor example, diagonal matrices are sparse. \nStoring an $n \\times n$ diagonal matrix in the naive way means storing $n^2$ values in memory. \nFor most applications, it makes more sense to store the diagonal entries in a 1-dimensional array of $n$ values. \nIn addition to using less storage space, this allows for much faster matrix operations. \nUsing the standard algorithm to multiply a matrix by a diagonal matrix involves $n^3$ steps, but most of these are multiplying by or adding zero. \nA smarter algorithm that knows all off-diagonal entries are zero can accomplish the same task much faster.\n\n\\subsection*{The Sparse Module}\nThe SciPy module \\li{sparse} has storage methods to reduce the temporal and spatial complexity of handling sparse matrices.  \nWhen we are not using these special methods, we say we are storing the \\emph{full} matrix. \nWe can also use \\li{sparse} methods on dense matrices (matrices with mostly nonzero entries), but doing so will take longer than using the usual methods for handling full matrices. \n\nThe difference in spatial complexity occurs because a full array occupies a block of memory for each entry, so an $n \\times n$ array requires $n^2$ blocks of memory. \nBy contrast, SciPy's \\li{sparse} methods store only the nonzero entries and their locations in the array. \nAs long as most entries are 0 (i.e., the matrix is sparse), this decreases spatial complexity. \nYou minimize spatial complexity when you store a sparse matrix with the \\li{sparse} module and a dense matrix as a full (or ``regular'') matrix.\n\nSciPy has seven sparse matrix types, listed in Table \\ref{table:smr}. \nEach type is optimized either for storing sparse matrices whose nonzero entries follow certain patterns, or for performing certain computations. \nFor example, the \\li{csc_matrix} and \\li{csr_matrix} types are optimized for arithmetic operations. \nWe will introduce some other types later in this lab. For more information, see the documentation (\\url{http://docs.scipy.org/doc/scipy/reference/sparse.html}).\n\n\n\n\n\\begin{table}\n\\centering\n\\begin{tabular}{|r|l|}\n\\hline\nSparse Matrix Type & Description \\\\\n\\hline\n\\li{bsr_matrix} & Compressed Block Sparse Row\\\\\n\\li{coo_matrix} & Coordinate\\\\\n\\li{csc_matrix} & Compressed Sparse Column\\\\\n\\li{csr_matrix} & Compressed Sparse Row\\\\\n\\li{dia_matrix} & Sparse Diagonal\\\\\n\\li{dok_matrix} & Dictionary of Keys\\\\\n\\li{lil_matrix} & Linked List\\\\\n\\hline\n\\end{tabular}\n\\caption{Sparse matrix representations in SciPy.}\n\\label{table:smr}\n\\end{table}\n\nLet us compare a \\li{sparse} matrix computation with a full matrix computation. \nNote that we can convert any full matrix to a \\li{sparse} matrix of any of the types listed in Table \\ref{table:smr}.\n\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy import sparse\n\n# Create a dense matrix (stored as a full matrix).\n>>> A_full = np.random.rand(600, 600)\n\n# Store A_full as a sparse matrix (even though it is dense).\n>>> A_sparse = sparse.csc_matrix(A_full)\n\n# Create a sparse matrix (stored as a full matrix).\n>>> B_full = np.diag(np.random.rand(600))\n\n# Store B_full as a sparse matrix.\n>>> B_sparse = sparse.csc_matrix(B_full)\n\n>>> def square(A):\n        return np.power(A, 2)\n\n>>> %timeit square(A_full)\n100 loops, best of 3: 9.53 ms per loop\n\n>>> %timeit square(A_sparse)\n1 loops, best of 3: 941 ms per loop\n\n>>> %timeit square(B_full)\n100 loops, best of 3: 5.36 ms per loop\n\n>>> %timeit square(B_sparse)\n1000 loops, best of 3: 259 us per loop\n\\end{lstlisting}\n\nAs you can see from this example, we get the best performance when we store a sparse matrix with the \\li{sparse} module and a dense matrix as a full matrix.\n\n\\begin{comment}\n\\begin{problem}\nCreate a $500\\times 500$ matrix and vector of length 500, both full of random values. Use the \\li{A.dot(b)} command to multiply your matrix and your vector, and time how long it takes to do so. Then convert your matrix to sparse format and again time how long it takes to multiply it by your vector using \\li{A.dot(b)}.\n\\end{problem}\n\\end{comment}\n\n\\subsection*{Creating Sparse Matrices}\nOne way to create a sparse matrix is to create a full matrix and then convert it to a sparse matrix, as we did in the previous example. \nHowever, you reduce spatial complexity if you never create the full matrix. \nHere are two ways to create sparse matrices directly.\n\nThe first way is to use the method \\li{sparse.spdiags(data, diags, m, n)}. \nIf \\li{data} is a 1-D array and \\li{diags} is a scalar, then this method creates an $m \\times n$ matrix with \\li{data} on the specified diagonal. \nThe parameter \\li{diags=0} indicates the main diagonal, with lower diagonals indexed by negative numbers and upper diagonals by positive numbers. \nIf \\li{data} is a 2-D array and \\li{diags} is a list, then this method creates an $m \\times n$ matrix with the rows of \\li{data} on the diagonals specified by \\li{diags}. \nSee the documentation for more information.\n\\begin{lstlisting}\n# Create a sparse 3x3 matrix with (2, 3, 4) on the diagonal.\n>>> A = sparse.spdiags([2, 3, 4], 0, 3, 3)\n>>> A\n<3x3 sparse matrix of type '<type 'numpy.int64'>'\n\twith 3 stored elements (1 diagonals) in DIAgonal format>\n# Convert A to a full matrix.\n>>> A.todense()\nmatrix([[2, 0, 0],\n        [0, 3, 0],\n        [0, 0, 4]])\n\t\n# Create a sparse 4x4 matrix with the rows of diag_entries on the diagonals.\n>>> diag_entries = np.array([[3,6,9,0],[1,4,7,10],[0,2,5,8]])\n>>> B = sparse.spdiags(diag_entries, [-1, 0, 1], 4, 4)\n<4x4 sparse matrix of type '<type 'numpy.int64'>'\n\twith 10 stored elements (3 diagonals) in DIAgonal format>\n>>> B.todense()\nmatrix([[ 1,  2,  0,  0],\n        [ 3,  4,  5,  0],\n        [ 0,  6,  7,  8],\n        [ 0,  0,  9, 10]])\n\\end{lstlisting}\n\nThe final matrix $B$ in the example above is a special kind of matrix called a \\emph{banded} matrix. \nA banded matrix is a sparse matrix whose only non-zero entries are on the main diagonal and some diagonals on either side. \nIn fact, $B$ is an example of a \\emph{tri-diagonal} matrix, because its nonzero entries are confined to the three central diagonals. \nBanded matrices arise naturally in many applications, including numerical methods for solving differential equations. \n\n\\begin{problem}\nWrite a function that takes an integer argument \\li{n} and returns a sparse $n\\times n$\ntri-diagonal array with $2$'s along the diagonal and $-1$'s along\nthe two sub-diagonals above and below the diagonal. \nThe array should be in \\li{csr_matrix} format.\n\\emph{Hint}: Read about the \\li{format} keyword parameter of the \\li{sparse.spdiags} method.\n\nThis matrix is the derivative operator in numerical analysis of differential equations.\n\\label{prob:sparse_tridiag}\n\\end{problem}\n\nA second way to create a sparse matrix is to pre-allocate an array of zeros and then specify the nonzero entries one at a time. \nThe most efficient sparse matrix types for building matrices incrementally are \\li{lil_matrix} and \\li{dok_matrix}. \nOnce you are done constructing the sparse matrix, you should convert it to a form that is optimized for computations.\n\n\n\\begin{lstlisting}\n# Initialize Z.\n>>> Z = sparse.lil_matrix((400, 300))\n# Specify the nonzero entries of Z.\n>>> Z[1,34] = 23\n>>> Z[23,32] = 56\n>>> Z[2,:] = 13.2\n>>> Z\n<400x300 sparse matrix of type '<type 'numpy.float64'>'\n\twith 302 stored elements in LInked List format>\n\n\\end{lstlisting}\n\nWhen the matrix \\li{Z} is initialized, all its entries are assumed to be zero. \nNote that at the end of \\li{Z}'s construction, only 302 elements are being stored for a matrix with 120000 entries. \n\nYou may have noticed that the only way to view a matrix as a 2-D array is to convert it to a full matrix. \nIf your matrix is too large to do this, you can still visualize it using the \\li{plt.spy()} command from matplotlib. \nThis function plots the locations of the non-zero entries in a matrix. \nThe following code outputs Figure \\ref{fig:mpl_spy}.\n\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n>>> B = np.random.rand(3, 10000)\n>>> A = sparse.spdiags(B, range(-1, 2), 10000, 10000)\n>>> plt.spy(A)\n\\end{lstlisting}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=.75\\textwidth]{spy.png}\n\\caption{The output of the \\li{spy()} command}\n\\label{fig:mpl_spy}\n\\end{figure}\n\n\n%insert problem here that lets them play around with large sparse matrices in diff forms\n\n\n\\begin{comment}\n\\subsection*{Banded Matrices}\n\\begin{problem}\nWrite a function that takes an integer argument \\li{n} and returns a full $n\\times n$\ntri-diagonal array with $2$'s along the diagonal and $-1$'s along\nthe two sub-diagonals above and below the diagonal.\n\\emph{Helpful Hint}: Use the \\li{np.diagflat()} command.\n\\label{full_tridiag}\n\\end{problem}\n\\end{comment}\n\n\\subsection*{Manipulating Sparse Matrices}\nScipy's \\li{sparse} matrices behave a little differently than NumPy arrays.\nYou can multiply two sparse matrices element-wise with the \\li{multiply()} method of one of the sparse matrices.\n\\begin{lstlisting}\n>>> D = sparse.spdiags([2,3,4],0,3,3)\n>>> C = sparse.spdiags(np.ones((3,3)), [-1,0,1], 3, 3)\n>>> (D.multiply(C)).todense()\nmatrix([[ 2.,  0.,  0.],\n        [ 0.,  3.,  0.],\n        [ 0.,  0.,  4.]])\n\\end{lstlisting}\n\nOn the other hand, the asterisk \\li{*} performs ordinary matrix multiplication. \nYou can also use the \\li{dot} method of one of the sparse matrices. \nHowever, you should NOT use \\li{np.dot} on sparse matrices because it may return an incorrect answer.\n\\begin{lstlisting}\n# One correct way to mutliply sparse matrices\n>>> (D.dot(C)).todense()\nmatrix([[ 2.,  2.,  0.],\n        [ 3.,  3.,  3.],\n        [ 0.,  4.,  4.]])\n\\end{lstlisting}\n\nAddition and scalar multiplication are implemented as usual.\n\\begin{lstlisting}\n>>> (D + 3*C).todense()\nmatrix([[ 5.,  3.,  0.],\n        [ 3.,  6.,  3.],\n        [ 0.,  3.,  7.]])\n\\end{lstlisting}\n\n\n\n\n\\section*{Using Sparse Matrices to Reduce Runtimes}\nIn addition to spatial complexity, the \\li{sparse} module can reduce temporal complexity. \nConsider the linear system $A x = b$, where $A$ is a $100000\\times 100000$ tri-diagonal matrix.\nStoring a full matrix of that size requires 10 billion double-precision floating-point numbers. \nSince it takes 8 bytes to store a double, we need roughly 80GB to store the full matrix. \nLack of storage space makes this system impossible to solve for most desktop computers, but even more problematic is the temporal complexity. \nMethods for directly solving a linear system are usually $O(n^3)$. \nAs a result, even if the computer could store an 80GB matrix in RAM, it would still take several weeks to solve the system. \n%However, since we don't typically have computers with that much available RAM, most of the\n%matrix would have to be stored on the hard drive, so the computation would probably take between $6$ months to a year.\n\nThe point is, even as computers increase in processing speed and memory, we can still easily construct problems that they will struggle to solve in a reasonable amount of time. \nHowever, if we store the tri-diagonal matrix as a \\li{sparse} matrix, we can solve the linear system, even with a modest computer. \n\nLet's first compute the spatial complexity of the above system when $A$ is stored as a sparse matrix. \nThere are three diagonals that have roughly $100000$ non-zero entries. \nThat's $300000$ double-precision floating point numbers, which is about 2.4 MB, or less storage than your favorite song. \nThus, the sparse matrix will easily fit into the computer's RAM. Furthermore, the temporal complexity for solving a tri-diagonal matrix is $O(n)$.\n\\footnote{Because there are fast algorithms for solving a tri-diagonal linear system, you may think that there are fast algorithms for inverting a tri-diagonal matrix. \nIn fact this is not true, and the inverse of a sparse matrix is usually not sparse. \nThere is rarely a good reason to invert a matrix, sparse or dense.} \nLet's see how long it takes to solve the system when $A$ and $b$ are filled with random data.\n\n\\begin{lstlisting}\n>>> from scipy.sparse import linalg as sl\n>>> G = np.random.rand(3, 100000)\n>>> b = np.random.rand(1, 100000)\n>>> A = sparse.spdiags(G,[-1,0,1],100000,100000, format='csr')\n>>> def solSys():\n...     return sl.spsolve(A, b)\n\n>>> %timeit solSys()\n1 loops, best of 3: 80.8 ms per loop\n\n\\end{lstlisting}\n\nThis computer solved the system in only 80.8 milliseconds.\n\n\\begin{comment}\n\\begin{problem}\nWrite a function that accepts an integer argument \\li{n} as well as a keyword argument \\li{sparse} whose value is either \\li{True} or \\li{False} (default to \\li{False}). \nThen do the following:\n\\begin{enumerate}\n\\item Inside of the function, use your previous solutions to generate an $n \\times n$ tri-diagonal array $A$ -- either sparse or full depending on the value of the \\li{sparse} argument.\n\\item Generate an $n \\times 1$ random array $b$\n\\item Solve the system $Ax = b$, using either \\li{scipy.sparse.linalg.spsolve} or \\li{scipy.linalg.solve}\n(again depending on the value of \\li{sparse}) and return the solution.\n\\item Time the function for \\li{n = 2000} using both the sparse and the full option.\n\\end{enumerate}\n\\end{problem}\n\\end{comment}\n\n\n\\begin{problem}\nWrite a function that accepts an integer argument $n$ and does the following:\n\\begin{enumerate}\n\\item Generates an $n \\times 1$ random array $b$.\n\\item Solves the linear system $Ax = b$, where $A$ is the tri-diagonal array in Problem \\ref{prob:sparse_tridiag} of size $n \\times n$.\n\\end{enumerate}\n\\end{problem}\n\n\n\n\\begin{problem}\nWrite a function that accepts an integer argument \\li{n} and returns $\\lambda n^2$, where\n$\\lambda$ is the smallest eigenvalue of the sparse tri-diagonal array you built in Problem \\ref{prob:sparse_tridiag}.\n\nIf \\li{A} is your tri-diagonal matrix, calculate $\\lambda$ using the method \\li{scipy.sparse.linalg.eigs} with the command \\li{sl.eigs(A.asfptype(), which = 'SM')}. \nThe code \\li{A.asfptype()} ensures that your matrix has the right data type, and the parameter \\li{which = 'SM'} tells the function to look for the smallest eigenvalues. \nThis command will return several of the smallest eigenvalues of \\li{A}, and you will have to select the smallest of these. \nRead the documentation of \\li{sl.eigs} for more information.\n\nWhat value does $\\lambda n^2$ approach as $n$ approaches infinity? \nThis value is meaningful in operator theory. \n\\li{Hint}: This value is the square of an important number.\n\n\\end{problem}\n\n\n\n\n\n \n", "meta": {"hexsha": "44d0ebe0022f676875fddc4f0c8752757d86e3d7", "size": 28526, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Orphans/Complexity/Complexity.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Orphans/Complexity/Complexity.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Orphans/Complexity/Complexity.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 48.4312393888, "max_line_length": 690, "alphanum_fraction": 0.7355395078, "num_tokens": 7767, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789040926008, "lm_q2_score": 0.8757869819218865, "lm_q1q2_score": 0.709806873326617}}
{"text": "%\n% 11\n%\n\\chapter{The Theory of Convergence}\n\n\\Section{2}{1}{The definition* of the limit of a sequence.}\n\nLet Zi, Zo, z-i, ... be an unending sequence of numbers, real or\ncomplex. Then, if a number I exists such that, corresponding to every\npositive f number e, no matter how small, a number ??o can be found,\nsuch that\n\n\\ Zn-l'.< e\n\nfor all values of n greater than o. the sequence (z,,) is said to tend\nto the limit I as n tends to infinity.\n\nSymbolic forms of the statement;]: ' the limit of the sequence Zn), as\nn tends to infinity, is / ' are :\n\nlim Zn=l, \\ unzn=l, 2,1- * I \" ->\n\nIf the sequence be such that, given an arbitrary number N (no matter\nhow large), we can find 7?o such that |,i | > iV for all values of n\ngreater than /lo, we say that '\\ Zn\\ tends to infinity as n tends to\ninfinity,' and we write\n\nkn i ->\n\nIn the corresponding case when -x,i>N when n> n we say that i/;,j - *\n- oc,\n\nIf a sequence of real numbers does not tend to a limit or to co or to\n- x, the sequence is said to oscillate.\n\n\\Subsection{2}{1}{1}{Definition of the phrase ' of the order of}\n\nIf ( ) and zn) are two sequences such that a number n exists such\nthat i (Ku/ n) I < jK\" whenever n > n, where K is independent of n,\nwe say that n is ' of the order of Zn, and we write§\n\nthus 15!i±l = 0fl\n\n1 + n\" \\ n-\n\nIf lim( / ) = 0, we write n = o Zn).\n\n* A definition equivalent to this was first given by John Wallis in\n1655. [Opera, i. (1695), p. 382.]\n\nt The number zero is excluded from the class of positive numbers.\n\nJ The arrow notation is due to Leathern, Camb. Math. Tracts, No. 1.\n\n§ This notation is due to Bachmann, Zahlenthcorie (1894), p. 401, and\nLandau, Primzahlen, I. (1909), p. 61.\n\n%\n% 12\n%\n\n\\Section{2}{2}{The limit of an increasing sequence.}\n\nLet (a7) be a sequence of real numbers such that Xn+i' Xn for all\nvalues of w; then the sequence tends to a limit or else tends to\ninfinity (and so it does not oscillate).\n\nLet X be any rational-real number; then either :\n\n(i) Xn X for all values of n greater than some number /?o depending on\nthe value of x.\n\nOr (ii) Xn < X for every value of n.\n\nIf (ii) is not the case for any value of x (no matter how large), then\n\nXn- OO.\n\nBut if values of x exist for which (ii) holds, we can divide the\nrational numbers into two classes, the Z-class consisting of those\nrational numbers x for which (i) holds and the i -class of those\nrational numbers x for which (ii) holds. This section defines a real\nnumber a, rational or irrational.\n\nAnd if € be an arbitrary positive number, a- e belongs to the i-class\nwhich defines a, and so we can find n such that Xn>oi - \\ e whenever n\n> n; and a + e is a member of the i?-class and so Xn<a + e.\nTherefore, whenever n > n,\n\nTODO\n\nTherefore Xn -> a.\n\nCorollary. A decreasing sequence tends to a limit or to - oo . Example\n1. If lim4:, =, lims,' = r, then lim(, + 3,') = + '. For, given\ne, we can find n and ' such that\n\n(i) when TODO, (ii) when TODO. Let TODO be the greater of n and n';\nthen, when TODO\n\nand this is the condition that Urn z,n + Sm')='i + i'-\n\nExample 2. Prove simikrly that lim(s,- 2,,/) =;-/\", l[m z,z,') =\nll', and, if /' + 0,\n\nlim zjz,') = l/l'.\n\nExample 3. If < x < 1, x\" 0. For if A- = (l+a)-i, a > and\n\nTODO\n\nby the binomial theorem for a positive integral index. And it is\nobvious that, given a positive number f, we can choose no such that\nTODO\n\n\\Subsection{2}{2}{1}{Limit-points and the Bolzano- Weierstrass* theorem.}\n\nLet (xn) be a sequence of real numbers. If any number G exists such\n\n* This theorem, frequently ascribed to Weierstrass, was proved by\nBolzano, Ahh. der k. bohmischen Ges. der Wiss. v. (1817). [Eeprinted\nin Klassiker der E.mkten Wiss., No. 153.] It seems to have been known\nto Cauchy.\n\n1-\n\n%\n% 13\n%\n\nthat, for every positive value of e, no matter how small, an unlimited\nnumber of terms of the sequence can be found such that\n\nG - 6 < Xn < G + e,\n\nthen G is called a limit-point, or cluster-point, of the sequence.\n\nBolzano's theorem is that, if X '<cp, ivhere X, p are independent of\n$n$, then the sequence TODO Juts at least one limit-point.\n\nTo prove the theorem, choose a section in which (i) the i -class\nconsists of all the rational numbers which are such that, if A be any\none of them, there are only a limited number of terms Xn satisfying\nXn>A; and (ii) the Z-class is such that there are an unlimited number\nof terms a-',i such that x a for all members a of the Z-class.\n\nThis section defines a real number G; and, if e be an arbitrary\npositive number, G - e and G + e are members of the L and R classes\nrespectively, and so there are an unlimited number of terms of the\nsequence satisfying\n\nG- e< G - he Xn G + €<G- - e, and so G satisfies the condition that it\nshould be a limit-point.\n\n\\Subsubsection{2}{2}{1}{1}{Definition of 'the greatest of the limits.'}\n\nThe number G obtained in \\hardsubsectionref{2}{2}{1} is called ' the greatest of the limits\nof the sequence xn)' The sequence x ) cannot have a limit-point\ngreater than G] for if G' were such a limit-point, and e = i ((r' -\n(r), G' - e is a member of the jR-class defining G, so that there are\nonly a limited number of terms of the sequence which satisfy Xn>G' -\n€. This condition is incon- sistent with G' being a limit-point. We\nwrite\n\nG= \\ imxn. The ' least of the limits,' L, of the sequence (written lim\nx ) is defined to be\n\n- lim (- Xn).\n\n\\Subsection{2}{2}{2}{Cauchy's* theorem on the necessary and sufficient\n  condition for the existence of a limit.}\n\nWe shall now shew that the necessary and sufficient condition for the\nexistence of a limiting value of a sequence of numbers z, Zn, z-i,\n... is that, corresponding to any given positive number e, hoiuever\nsmall, it shall be possible to find a number n such that\n\nfor all positive integral values of j)- This result is one of the most\nimportant and fundamental theorems of analysis. It is sometimes called\nthe Principle of Convergence.\n\n* Analyse Algebrique (1821), p. 125.\n\n%\n% 14\n%\n\nFirst, we have to shew that this condition is necessary, i.e. that it\nis satisfied whenever a limit exists. Suppose then that a limit I\nexists; then \\hardsectionref{2}{1}) corresponding to any positive number e, however\nsmall, an integer n can be chosen such that\n\nfor all positive values of p; therefore\n\n  i Zn+p -l\\ + \\ Zn-l\\ <,\n\nwhich shews the necessity of the condition\n\nI ii+p ~ -2'rt I < > and thus establishes the first half of the\ntheorem.\n\nSecondly, we have to prove* that this condition is suficient, i.e.\nthat if it is satisfied, then a limit exists.\n\n(I) Suppose that the sequence of real numbers xn) satisfies Cauchy's\ncondition; that is to say that, corresponding to any positive number\ne, an integer n can be chosen such that\n\nfor all positive integral values of p.\n\nLet the value of n, corresponding to the value 1 of e, be 7n.\n\nLet Xj, pi be the least and greatest of a;i, a-g, ... av; then\n\nXi-1 <Xn< p, + l,\n\nfor all values of n; write Xj - I = X, pi + 1 = p.\n\nThen, for all values of n, X < Xn < p- IVierefore by the theorem of\n§2'21, the sequence (xn) has at least one liniit-point G.\n\nFurther, there cannot be more than one limit-point; for if there were\ntwo, G and H (H < G), take e < I G - H). Then, by hypothesis, a number\nn exists such that j Xn+p - Xn | < e for every positive value of p.\nBut since G and H are limit-points, positive numbers q and r exist\nsuch that\n\nI G - X, +q \\ < €, \\ H - Xn+r \\ < l-nen | Cr X- q | -j- | Xn q X | -|-\n| X n+r I ~r I Xji f. Ji ] < '±6.\n\nBut, by \\hardsectionref{1}{4}, the sum on the left is gi-eater than or equal to j G -\nH .\n\nTherefore G - H < 4e, which is contrary to hypothesis; so there is\nonly one limit- point. Hence there are only a finite number of terms\nof the sequence outside the interval G -, (j + S), where 8 is an\narbitrary positive number;\n\n* This proof is given by Stolz and Gmeiner, Theoretische Arithmetik,\nii. (191)2), p. 144.\n\n%\n% 15\n%\n\nfor, if there were an unlimited number of such terms, these would have\na limit-point which would be a limit-point of the given sequence and\nwhich would not coincide with G; and therefore G is the limit of x ).\n\n(II) Now let the sequence Zn) of real or complex numbers satisfy\nCauchy's condition; and let Zn = Xn -f- iyn, where Xn and yn are real\n; then for all values of n and p\n\nI n-irp - i I n+p 2'n i, | yn+p ~ yn \\ | 2'n+p n\\-\n\nTherefore the sequences of real numbers x ) and (yn) satisfy Cauchy's\ncondition; and so, by (I), the limits of (.r) and y ) exist.\nTherefore, by \\hardsectionref{2}{2} example 1, the limit of (2) exists. The result is\ntherefore established.\n\n\\Section{2}{3}{Convergence of an infinite series.}\n\nLet Wj, ?/2, u.i, ... Kit, ... be a sequence of numbers, real or\ncomplex. Let the sum\n\nMl 4- Uo + . . . -I- tin\n\nbe denoted by Sn-\n\nThen, if *S,i tends to a limit S as /; tends to infinity, the\ninfinite series\n\n\"i + Hi + 3 -f- <4 + . . . is said to he convergent, or to converge to\nthe sum S. In other cases, the infinite series is said to be\ndivergent. When the series converges, the expression S-Sn, which is\nthe sum of the series\n\n\" +l+ \" +2+ Un+-,+ ...,\n\nis called the remainder after n terms, and is frequently denoted by\nthe symbol R .\n\nThe sum Un+ + 11 +.. + ...-\\- Un+p\n\nwill be denoted by Sn,p.\n\nIt follows at once, by combining the above definition with the results\nof the last paragraph, that the necessary and sufficient condition for\nthe convergence of an infinite series is that, given an arbitrary\npositive number e, we can find n such that I /S'\\ | < e for every\npositive value of p.\n\nSince Un+i = n,l, it follows as a particular case that lim Un+i = - in\nother words, the 7?th term of a convergent series must tend to zero as\n// tends to infinity. But this last condition, though necessary, is\nnot sufficient in itself to ensure the convergence of the series, as\nappears from a study of the series\n\nIn this series, Sn,n =, +, + - +  + .\n\n' n+ i n + 2 n + 6 2n\n\nThe expression on the right is diminished by writing (2?i)~ in place\nof each term, and so Sn,,1 >\n\n%\n% 16\n%\n\nTherefore S n+i = 1 + /Si, i + 2, 2 + 'S14, 4 + >S'8\\ g + >Si6, le +\n  + S.n\n\n> ( + 3) -> X;\n\nso the series is divergent; this result was noticed by Leibniz in\n1673.\n\nThere are two general classes of problems which we are called upon to\ninvestigate in connexion with the convergence of series :\n\n(i) We may arrive at a series by some formal process, e.g. that of\nsolving a linear differential equation by a series, and then to\njustify the process it will usually have to be proved that the series\nthus formally ob-' tained is convergent. Simple conditions for\nestablishing convergence in such circumstances are obtained in\n§§2'31-2\"61.\n\n(ii) Given an expression S, it may be possible to obtain a development\n\nS= X i(,n + Rn, valid for all values of n; and, from the definition\nof a limit,\n\n00\n\nit follows that, if we can prove that Rn - 0, then the series 2 u,,\nconverges\n\nm = l\n\nand its sum is S. An example of this problem occurs in § 54.\n\nInfinite series were used* by Lord Brouncker in Phil. Trans. 11.\n(1668), pp. 645-649, and the expressions convergent and disergent were\nintroduced by James Gregory, Professor of Mathematics at Edinburgh, in\nthe same year. Infinite series were used systematically by Newton in\n1669, De anali/si per aequat. num. term, inf., and he investigated the\ncon- vergence of hypergeometric series (§ 14- 1) in 1704. But the\ngreat mathematicians of the eighteenth century used infinite series\nfreely without, for the most part, considering the question of their\nconvergence. Thus Euler gave the sum of the series\n\n1 1 1,, .. ... + -,+ - + -+l+2 + 2- + r'+ a)\n\nas zero, on the ground that\n\n2 +,2 +,3 + ... (6)\n\n\\-z\n\n1, 1 1 3\n\nand 1+- -t- -, + ... = - - (c).\n\nz z~ z- V\n\nThe eiTor of course arises from the fact that the series h) converges\nonly when | 2 j < 1, and the series (c) converges only when | s j > 1,\nso the series (a) never converges.\n\nFor the history of researches on convergence, see Pringsheim and Molk,\nEncyclope'die des Sci. Math., i. (1) and Keifi\", Geschichte der\nunendlichen Reihen (Tiibingen, 1889).\n\n\\Subsubsection{2}{3}{0}{1}{AheVs inequality.}\n\nI \"* Let fn fn+ for all integer values of n. Then 2 /\n\nA is the greatest of the sums\n\n1 ! i, i ! + 2 1 > I o-i + 0.2 + a, !, . . ., i ! + rto +   . + am\n\n  Af, ivhere\n\n* See also the note to \\hardsectionref{2}{7}.\n\nt Journal fiir Math. i. (1826), pp. 311-339. A particular case of the\ntheorem of \\hardsubsectionref{2}{3}{1}, Corollary (i), also appears iu that memoir.\n\n%\n% 17\n%\n\nFor, writing Ui + ao + . . . + a = Sn, we have\n\nrii\n\nt ilnfn = 5i/i + S.2 - Si)fo + (Ss - S jfs + . + (s - Sm-i)fm 11 = 1\n\n- Si (/i -J 2) + S-2. (/2 ~y 3) + . . . + S i\\ i \\ Jm-i ~Jm) + Smfm-\n\nSince /i - /o,/2 -fs,  are not negative, we have, when n = 2, 3,\n... m,\n\nI Sn-i \\ (fn-i -fn) (fn-i - fn) ', alsO j S,n \\ fm < fm,\n\nand so, summing and using \\hardsectionref{1}{4}, we get\n\nn=l I\n\nCorollari). If i, a ... ?Pi, Wj, ... are any numbers, real or complex,\n\n2 a w \\ <,A\\ 2 i M' + 1 - w, i + 1 u-\n\n'/'\n\nwhere J is the greatest of the sums\n\n2 a\n\nn=l\n\n, p = \\, 2, ... m).\n\n\\addexamplecitation{Hardy.}\n\n\\Subsection{2}{3}{1}{Dirichlet's* test for convergence.}\n\nLet\n\nZ < K, luhere K is independent of p. Then, if fn >fn\\-\\ >\n\nand lim/ = O-f*, ((nfn converges.\n\nM = l\n\nFor, since lim i = 0, given an arbitrary positive number e, we can\nfind m such that +! < e/2/i .\n\nThen\n\nm + q\n\nm + q\n\n2 an\\ i X a j + ! X cirt t < 2/1', for all positive values of; so\n\nthat, by Abel's inequality, we have, for all positive values of j;;,\n\nwhere A <2K.\n\nI m+p\n\nTherefore 2 cinfn\n\nI n = m+l\n\nm+p Z CLnJn - Jin+i >\n\nn=m+l\n\n< 2Kfm+i < e; and so, by \\hardsectionref{2}{3}, S cinf 71 converges.\n\nCorollary (i). Jfte 's test for convergence. If 2 converges and the\nsequence (m ) is\n\nn = l\n\nnionotouic (i.e.,i ?t + i always or else M Wrt + i always) and j?(\n|<k, where k is independent of /(, then 2 i/ converges.\n\nFor, by \\hardsectionref{2}{2}, tends to a limit u; let |w- |=/ . Then i- 0 steadily;\nand\n\ntherefore 2 ' converges. But, if (m ) is an increasing sequence, /\n=w-m, and so\n\nrt=i\n\n2 li-n Un converges; therefore since 2 ua converges, 2 converges. If\n(?<J is\n\n =1 ii=\\ n=\\\n\na decreasing sequence / = e<,i -, and a similar proof holds.\n\n* Journal de Math. (2), vii. (1862), pp. 253-255. Before the\npublication of the 2nd edition of Jordan's Cours d' Analyse (1893),\nDirichlet's test and Abel's test were frequently jointly described as\nthe Dirichlet-Abel test, see e.g. Pringsheim, Math. Ann. xxv. (1885),\np. 423.\n\nt In these circumstances, we say j -0 steadily.\n\nW. M. A. 2\n\n%\n% 18\n%\n\nCorollary (ii). Taking a = (-) -i in Dirichlet's test, it follows\nthat, if / /; i and lim / = 0, /i -ft +/3 -/i + . .  converges.\n\np\n\nExample 1. Shew that if 0< <27r, I 2 sin (9 <coseci(9; and deduce\nthat, if\n\nf - Q steadily, 2 / sin nO converges for all real values of 6, and\nthat 2 / cos nd converges\n\nn=l \"=i\n\nif 6 is not an even multiple of tt.\n\nExample 2. Shew that, if fn- 0 steadily, 2 (-)\"/' cos (9 converges if\n6 is real and\n\nn = \\\n\nnot an odd multiple of tt and 2 -)\"-fnS\\ nne converges for all real\nvalues of 6. [Write 7r + for in example 1.]\n\n\\Subsection{2}{3}{2}{Absolute and conditional convergence.}\n\nQO\n\nIn order that a series X Un of real or complex terms may converge, it\nis\n\nn=l\n\nsufficient (but not necessary) that the series of moduli S Un \\ should\n\nn = \\\n\n00\n\nconverge. For, if <Tn,p = Un+i, + | Un+2 i +    + | Un+p \\ and if\n2 | w | converges,\n\n71 = 1\n\n\\ ve can find n, corresponding to a given number e, such that cTn p <\ne for all\n\nvalues of jj. But ] Sn,p cr \\ < e, and so S converges.\n\n  = i\n\nwe see that t - 9 + o~4+--- converges, though \\hardsectionref{2}{3}) the series of\nmoduli\n\nThe condition is not necessary; for, writing i = 1/n in \\hardsubsectionref{2}{3}{1},\ncorollary (ii), see that\n\ni\\ -4- + +...is known to diverge.\n\n1 2 O -i\n\nIn this case, therefore, the divergence of the series of moduli does\nnot entail the divergence of the series itself.\n\nSeries, which are such that the series formed by the moduli of their\nterms are convergent, possess special properties of great importance,\nand are called absolutely convergent series. Series which though\nconvergent are not abso- lutely convergent (i.e. the series themselves\nconverge, but the series of moduli diverge) are said to be\nconditionally convergent.\n\n\" 1\n\\Subsection{2}{3}{3}{The geometric series, and the series TODO.}\n\nw = l\n\nThe convergence of a particular series is in most cases investigated,\nnot by the direct consideration of the sum Sn p, but (as will appear\nfrom the following articles) by a. comparison of the given series with\nsome other series which is known to be convergent or divergent. We\nshall now investigate the convergence of two of the series which are\nmost frequently used as standards for comparison.\n\n%\n% 19\n%\n\n(I) The geometric series. The geometric series is defined to be the\nseries z + z-- z + z'+ .... Consider the series of moduli\n\nl+\\ z\\ + \\ z ' + \\ z' + ...\\ for this series Sn,p =\\ z\\'' ' + \\ z, \"+-\n+ ...->r z v\n\nl-\\ z\\ P\n\n= izr+\n\nl-\\ z\\ '\n\nHence, if .g- < 1, then S,i,p< : -; for all values of j), and, by §\n22,\n\nexample 3, given any positive number e, we can find n such that\n\n[ |n+i l\\ |2i|-i<e.\n\nThus, given e, we can find n such that, for all values of p, Sa,p<€.\nHence, by \\hardsubsectionref{2}{2}{2}, the series\n\nis convergent so long as 2 | < 1, and therefore the geometric series\nis absolutely convergent if\\ z\\ < .\n\nWhen z ' 1, the terms of the geometric series do not tend to zero as n\ntends to infinity, and the series is therefore divergent.\n\nTT VV .11111\n\n(II) Ihe series + - + - + - + - + ....\n\n\" 1 Consider now the series,i = 2 -, where s is greater than 1.\n\n7n = l i*\n\n112 1 'e have 2\" + 3 - < 2*- = 2 i '\n\n11114 1\n\n- I 1 1 - < - =\n\n4 5*' 6' 7* 4 4*-i ' and so on. Thus the sum of 2 -1 terms of the\nseries is less than 1 J\\ J\\ J\\ 1 1\n\n] s-i 2*~i 4*~i 8 ~  I 2(2>-i) (s-1) 1 - 2 ~* ' and so the sum of\nani/ number of terms is less than (1 - 2 ~*)~ Therefore\n\nn\n\nthe increasing sequence S m~ cannot tend to infinity; therefore, by §\n2'2,\n\nw = l\n\n=0 1 .\n\nthe series S - is convergent if s>\\ \\ and since its terms are all real\nand\n\nM = 1 'i\n\npositive, they are equal to their own moduli, and so the series of\nmoduli of the terms is convergent; that is, the convergence is\nabsolute.\n\n2-2\n\n%\n% 20\n%\n\nIf s = 1, the series becomes\n\n1 + 1 + 1 + 1 + ...,\n\nwhich we have already shewn to be divergent; and when 5 < 1, it is a\nfortiori divergent, since the effect of diminishing s is to increase\nthe terms of the\n\n< 1 .\n\nseries. The series S - is therefore divergent if s 1. n = l ''\n\n\\Subsection{2}{3}{4}{The Comparison Theorem.}\n\nWe shall now shew that a series; i + i, + 2/3+ ... is absolutely\ncon- vergent, provided that \\ u \\ is always less than G \\ vn\\, ivhere\nC is some number independent of n, and v,i is the nth term of another\nseries which is known to be absolutely convergent.\n\nFor, under these conditions, we have\n\nI ' ?i+i I + I 'i' i+2 1 +  .  + I Un p I < C I j Vn+i I + I f,iJ-2\n: + ... + 1 V +p \\ \\,\n\nwhere n and p are any integers. But since the series Si',i is\nabsolutely convergent, the series S | Vn \\ is convergent, and so,\ngiven e, we can find n such that\n\nI \" n+i I + i /i+2 I + .-..+ I Vn- p I < e/ C,\n\nfor all values oi p. It follows therefore that we can find /; such\nthat\n\n1 Un+i I + I Wn+2 i + . . + 1 Un+p \\ < e,\n\nfor all values of p, i.e. the series S | Un \\ is convergent. The\nseries %Un is therefore absolutely convergent.\n\nCorollary. A series is absolutely convergent if the ratio of its th\nterm to the nih. term of a series which is known to be absolutely\nconvergent is less than some number indej)endent of n.\n\nExample 1. Shew that the series\n\nCOS,Z +- 2COS22 + .-J5COS 32 + -T, COS42+...\n\nli\" o\" 4\"\n\nis absolutely convergent for all real values of z.\n\niCOS TliZ 1\n\n- 5- -, . The moduli of n I ji-\n\nthe terms of the given series are therefore less than, or at most\nequal to, the corresponding\n\nterms of the series\n\nn 1 1 1\n\n1 + 2-2 + .3- + 4 2+-' .\n\nwhich by \\hardsubsectionref{2}{3}{3} is absolutely convergent. The given series is\ntherefore absolutely convergeut.\n\nExample 2. Shew that the series\n$$\nTODO\n$$\nwhere 2 = e'\", (?i=l, 2, 3,\n\nis convergent for all values of 2, which are not on the circle [ ] =\n1.\n\n%\n% 21\n%\n\nThe geometric representation of complex numbers is helpful in\ndiscussing a question of this kind. Let values of the complex number z\nbe represented on a plane; then the numbers Z\\ t z, Zz, ... will\ngive a sequence of points which lie on the circumference of the circle\nwhose centre is the origin and whose radius is unity; and it can be\nshewn that every point on the circle is a limit-point \\hardsubsectionref{2}{2}{1}) of the\npoints z . --\n\nFor these special values z-, of, the given series does not exist,\nsince the denomi- nator of the nth term vanishes when 2 =,,. For\nsimplicity we do not discuss the series for any point z situated on\nthe circumference of the circle of radius unity.\n\nSuppose now that [zj + l. Then for all values of 7i, | z - 2 (1 - [2 '\n|>c~i, for\n\nsome value of c; so the moduli of the terms of the given series are\nless than the corre- sponding terms of the series\n\nc c c c\n\nwhich is known to be ab.solutely convergent. The given series is\ntherefore absolutely convergent for all values of z, except those\nwhich are on the circle | 2 | = 1.\n\nIt is interesting to notice that the area in the i-plane over which\nthe series converges is divided into two parts, between which there is\nno intercommunication, by the circle\n\n1 1 = 1.\n\nExample 3. Shew that the series\n\nSsinJ-f 4sin |-f8 sin -f- ... -l-2\"sin .f- + ...\n\n J .J it i o\n\nconverges absolutely for all values of 2.\n\nSince* lim 3\" sin (2/8\") = 2, we can find a number /, independent of\nn (but depending on 2), such that | 3\" sin (2/3\") \\ < i:; and\ntherefore\n\n2 sin < U) .\n\n3\" I V3.\n\n  /2\\\" Since 2 i' i ) converges, the given series converges\nabsolutely.\n\n\\Subsection{2}{3}{5}{Gauchy's test for absolute convergence']'.}\n\ni/' lim M ]\"\" < 1, S ? i converges absolutely. >i -*. * jj = 1\n\nFor Ave can find m such that, when n ni, j m | '\" p < 1, where p is\nindependent of u. Then, when n > ni, '. Un \\ < p' ] and since 2 p\"\nconverges,\n\nn = >n+l\n\nit follows from \\hardsubsectionref{2}{3}{4}! that 2 Un (and therefore 2 m,J converges ab-\nsolute I '.\n\n[Note. If lim \\ u, \\ \\ ' >\\, u does not tend to zero, and, by \\hardsectionref{2}{3}, 2\nm does not converge.]\n\n* This is evident from results proved iu the Appendix. t Analyse\nAlgehrique, pp. 132-135.\n\n%\n% 22\n%\n\n\\Subsection{2}{3}{6}{D'Alembert's* ratio test for absolute convergence.}\n\nWe shall now shew that a series\n\n?/i+ U2+ u-i + 1/4+ ... is absolutely convergent, provided that for\nall values of n greater than some fixed value r, the ratio ' is less\nthan p, tvhere p is a positive number independent of n and less than\nunity.\n\nFor the terms of the series\n\nj Ur+i i + i Ur+-2 I + i Ur+i \\ + ...\n\nare respectively less than the corresponding terms of the series\n\nwhich is absolutely convergent when p < 1; therefore S Un (and hence\n\n  = / + !\n\nthe given series) is absolutely convergent.\n\nA particular case of this theorem is that if lim (Un+Jun) \\ = l <1,\nthe\n\nseries is absolutely convergent.\n\nFor, by the definition of a limit, we can find r such that\n\nI ! \\ 4 i < i (1 - 0, when n > r,\n\nand then P±-' <l(l+l)<l,\n\nwhen 11 > r.\n\n[Note. If lim \\ u, + l i<,, >1, % does not tend to zero, and, by §\n2-3, 2 ?<,, does not\n\nH = l\n\nconverge.]\n\nExample 1. If 1 c |<1, shew that the series\n\n/t=i converges absolutely for all values of z.\n\n[For w + i/?i,i = c( + i)--''-e c-\" + ie - 0, as ??- x, if;Cj<l.]\n\nExample 2. Shew that the senes\n\na-6, (a- 6) (a- 26) a-h) a-2h)ia- h) . Z+-2J-.-+ 3j + j z +...\n\nconverges absolutely if \\ z\\ < \\ b~' .\n\n[For ±1 = - '1-z- -hz, as k- oo; so the condition for absolute\nconvergence is Un n + \\ ' '\n\n\\ hz\\ < \\,. Q.\\ z\\ < h- .'\\\n\n* Opuscules, t. V. (1768), pp. 171-182.\n\n%\n% 23\n%\n\nExample 3. Shew that the series 2 - - \\, converges absolutely if\ni2|<l.\n\n[For, when;2|<1, | 2 -(l 4-n-i)\" I (1 + -!)\"- I 2\" i 1 + 1 + + ... -\n1>1, so the moduli of the terms of the series are less than the\ncorresponding terms of the series 2 n Is\"\"! I; but this latter series\nis absolutely convergent, and so the given series con- verges\nabsolutely.]\n\n\\Subsection{2}{3}{7}{A general theorem on series for luhicli lim |- =1.}\n\nIt is obvious that if, for all values of n greater than some fixed\nvalue r, I i/-,i+i I is greater than | Un\\, then the terms of the\nseries do not tend to zero as\n\n?i - > X, and the series is therefore divergent. On the other hand,\nif i j\n\nis less than some number which is itself less than unity and\nindependent of n (when n > r), we have shewn in \\hardsubsectionref{2}{3}{6} that the series\nis absolutely con- vergent. The critical case is that in which, as n\nincreases, - ' tends to the value unity. In this case a further\ninvestigation is necessary.\n\nWe shall now shew that* a series u + u.. + u.i+ .. .,dn which lim -\" =\n1 will be absolutely convergent if a positive number c exists such\nthat\n\nFor, compare the series S ] Un j with the convergent series Ivn, where\nand y1 is a constant; we have\n\nVn \\ n + 1/ V nj n \\ n\n\n. \\'Vn+i T I 1\n\nand hence we can find m such that, when n > m,\n\nu,\n\nBy a suitable choice of the constant A, we can therefore secure that\nfor all values of n we shall have\n\ni Un I < V,v\n\nAs Si'n is convergent, 2 | Un j is also convergent, and so Sm,i is\nabsolutely convergent.\n\n* This is the second (D'Alembert's theorem given in \\hardsubsectionref{2}{3}{6} being the\nfirst) of a hierarchy of theorems due to De Morgan. See Chrystal,\nAlgebra, Ch. xxvi. for an historical account of these theorems.\n\n%\n% 24\n%\n\n\nCorollary. If then the series is absolutely convergent if J.i < - 1\n\n= 1 H - + - ], where i is independent of n,\n\nn \\ n-J\n\n00 / \" 1 \\\n\nExample. Investigate the convergence of 2 '' exp ( - -2 - ), when r>k\nand when n=l \\ 1 \"v\n\nr<k.\n\n\\Subsection{2}{3}{8}{Convergence of the hijpergeometric series.}\n\nThe theorems which have been given may be illustrated by a discussion\nof the convergence of the hypergeometric series\n\n  a.h a(a+l)6(6+l) . a(a+ l)(a + 2) 6(6 + 1)(6 + 2)\n\n  + 17 + 1.2.c(c + l) \" 1.2.3.c(c + l)(c + 2) \" '\n\nwhich is generally denoted (see Chapter XIV) by F a, b; c; z).\n\nIf c is a negative integer, all the terms after the (1 - c)th have\nzero\n\ndenominators; and if either a or 6 is a negative integer the series\nwill\n\nterminate at the (1 - a)th or (1 - 6)th term as the case may be. We\nshall\n\nsuppose these cases set aside, so that a, h, and c are assumed not to\nbe\n\nnegative integers.\n\n  In this series\n\ni Un+i i ( \"+ n - l)(b + n - 1)1 II\n\n, - 7 -, V <s I * >\n\n\\ Ufi \\ I n c + n - l) I\n\nas ?? - > 00 .\n\nWe see therefore, by \\hardsubsectionref{2}{3}{6}, that the series is absolutely convergent\nivhen \\ z\\ < l, and divergent ivhen | | > 1.\n\nWhen U I = 1, we have *\n\n1 +\n\n0-1]\n\nii+'\n\nn\n\na + b-\n\n-c-1\n\n6-1\n\nn \\ n /\n\nLet a, b, c be complex numbers, and let them be given in terms of\ntheir real and imaginary parts by the equations\n\na = a + ia\", 6 = 6' + ib\", c = c + ic\". Then we have\n\n ' + 6' - c' - 1 + z (a\" + 6\" - c\")\n\nUn\n\n1 +\n\n= 1 +\n\na +b' - c\n\nly fa\" + b\"-c'\n\n+ 0(1\n\n\\ n'\n\n+\n\n\n\nBy \\hardsubsectionref{2}{3}{7}, Corollary, a condition for absolute convergence is\n\na' + b' -c' < 0. * The symbol (l/>i-) does not denote the same\nfunction of n throughout. See \\hardsubsectionref{2}{1}{1}.\n\n%\n% 25\n%\n\nHence ivhen \\ z\\ = \\, a sufficient condition* for the absolute\nconvergence of the hyper geometric series is that the real part of a +\nb - c shall be negative.\n\n\\Section{2}{4}{Effect of changing the order of the terms in a series.}\n\nIn an ordinary sum the order of the terms is of no importance, for it\ncan be varied without affecting the result of the addition. In an\ninfinite series, however, this is no longer the casef, as will appear\nfrom the following example.\n\nT.,11111111\n\nLet 2 = H-3-2+5 + 7-| + 9 + n-o+---\n\n1 cr -. 1 1 1 1 1 .\n\nand,S'=l-2 + 3-4 + 5-6 + --->\n\nand let 2,i and Sn denote the sums of their first n terms. These\ninfinite series are formed of the same terms, but the order of the\nterms is different, and so - and Sn are quite distinct functions of n.\n\nLet\n\n11 1 I . a 0-w = j; + 2 +   . + > SO that bn = (T-.n - a\n\nThen\n\n 11 111 1\n\n-3n-i +3 +  + 4,i\\ i 2~4  2),\n\n1 1 n 2 -'* 2 \"\"\"\n\n= (0\"4/i - CT-jn) + 2 iti ~ n)\n\n= n \"r 9 211\n\nMaking n->-y:, we see that\n\nS = S + lS;\n\nand so the derangement of the terms of /i' has altered its sum.\n\nExample. If in the series\n\n-. 1 1 1\n\n1-2+3-4+---\n\nthe order of the terms be altered, so that the ratio of the number of\npositive terms to the number of negative terms in the first n terms is\nultimately a-, shew that the sum of the series will become log (2a).\n\\addexamplecitation{Manning.}\n\n\\Subsection{2}{4}{1}{The fundamental property of absolutely convergent series.}\nWe\nshall shew that the sum of an absolutely convergent series is not\naffected by changing the order in which the terms occur.\n\nLet 8 = uy Un + 3 + ...\n\n* The coudition is also necessary. See Bromwicb, Infinite Stnies, pp.\n202-204.\n\nt We say that the series S !' consists of the terms of S m,j in a\ndifferent order if a law\n\n)! = 1 )t = l\n\nis given by which corresponding to each positive integer x) we can\nfind one (and only one) integer q and vice versa, and Vq is taken\nequal to Up. The result of this section was noticed by Dirichlet,\nBerliyier Abh. (1837), p. 48, Journal de Math. iv. (1839), p. 397. See\nalso Cauchy, Resumes analytiques (Turin, 1833), p. 57.'\n\n%\n% 26\n%\n\nbe an absolutely convergent series, and let S' be a series formed by\nthe same terms in a different order.\n\nLet e be an arbitrary positive number, and let n be chosen so that\n\nI I I I I I '\n\nfor all values of p.\n\nSuppose that in order to obtain the first n terms of S we have to take\nm terms of S'; then if k > m,\n\n k = n + terms of S with suffices greater than n, so that\n\n>SV - S = Sn - S + terms of S with suffices greater than n.\n\nNow the modulus of the sum of any number of terms of S with suffices\ngreater than n does not exceed the sum of their moduli, and therefore\nis less\n\nthan 2 e-\n\nTherefore | >S a;' - 'S' j < Sn- S\\ + €.\n\nBut j - >Sf I < lim 11 Un+i I + I Un+-2 I +    + i Uri+p |\n\np-*-x\n\n1 Therefore given e we can find m such that\n\n\\ Si:-s\\ < €\n\nwhen k > m; therefore /S,,/- > S, which is the required result.\n\nIf a series of real terms converges, but not absolutely, and if >S be\nthe sum of the first p positive terms, and if an be the sum of the\nfirst n negative terms, then 8p->cc, cr - >- oo; and lim (>Sp + cr,j)\ndoes not exist unless we are given some relation between p and n. It\nhas, in fact, been shewn by Riemann that it is possible, by choosing a\nsuitable relation, to make lim(>Sf 4- (7n) equal to cnii/ given real\nnumber*.\n\n\\Section{2}{5}{Double series.}\n\nLet ii i,n be a number determinate for all positive integral values of\nm and ??; consider the array\n\n ],l) Wj O) '**I,3j  ' ' 2,1 J '2,2) *'2,3)   ';i, 1 ) h, 2 ) 3,\n3 )\n\n* Ges. Werke, p. 221.\n\nt A complete theory of double series, on which this account is based,\nis given by Pringsh\\&iui, Miinchcner Sitzunysberichte, xxvii. (1807),\npp. 101-152. See further memoirs by that writer, Math. Ann. liii.\n(1900), pp. 289-321 and by London, ibid. pp. 322-370, and also\nBromwich, Infinite Series, which, m addition to an account of\nPringsheim's theory, contains many develop- ments of the subject.\nOther important theorems are given by Bromwich, Proc. London Math.\nSac. (2), I. (1904), pp. 176-201.\n\n%\n% 27\n%\n\nLet the sum of the terms inside the rectangle, formed by the first m\nrows of the first n columns of this array of terms, be denoted by\nS,n,n-\n\nIf a number *S' exists such that, given any arbitrary positive number\ne, it is possible to find integers m and n such that\n\nwhenever both /a > ru and v > n, we say* that the double series of\nluliich the general element is u,,. converges to the sum S, and we\nwrite\n\nlira *S' = S.\n\n fi,V\n\nIf the double series, of which the general element is ] w, |, is\nconvergent, we say that the given double series is absolutely\nconvergent.\n\nSince w = (/SV, - >SV, -i) - ('S' -], -'Sm-i, -iX it is easily seen\nthat, if the double series is convergent, then\n\nlim Uf, = 0.\n\nStolz necessary and suffi cientf condition for convergence. A\ncondition for convergence which is obviously necessary (see \\hardsubsectionref{2}{2}{2}) is\nthat, given e, we can find m and n such that | S +p, y - *%, / < e\nwhenever fi > m and v > n and p, a may take any of the values 0, 1, 2,\n.... The condition is also sufficient; for, suppose it satisfied;\nthen, when fM> m + n, >S' +p, +p - S; < e.\n\nTherefore, by \\hardsubsectionref{2}{2}{2}, S has a limit *S'; and then making p and a tend\nto infinity in such a way that p, + p = v + a, v,'e see that \\ S - 8,,\n, e when- ever p > m and v> n; that is to say, the double series\nconverges.\n\nCorollary, An absolutely convergent double series is convergent. For\nif the double series converges absolutely and if ty,t n he the sum of\nm rows of n columns of the series of moduli, then, given f, we can\nfind fx such that, when p>ra>fi and q>/i>fi, i,j,q - t,n,n< - But \\ Sp\nq-S, n\\ \\ ip,q-tm,H and so \\ Sp g-S, n\\ < e when jc ??i>/x, q>n>fi;\nand this is the condition that the double series should converge.\n\n\\Subsection{2}{5}{1}{Methods of summing double series.}\nTODO\n\nLet us suppose that S u, converges to the sum S . Then S >S' is\ncalled the sum by rows of the double series; that is to say, the sum\nby rows\n\nOC/X\\ 30/00\\\n\nis 5 ( S li, ). Similarly, the sum by columns is defined as 2 ( 2\nV,*')- That these two sums are not necessarily the same is shewn b the\nexample\n\nSu V =, in which the sum by rows is - 1, the sum by columns is + 1;\n\n' ' p + v - -\n\nand S does not exist.\n\n* This definition is practically due to CsiU.chy, Analyse Algehrique,\np. 540. t This condition, stated by Stolz, Math. Ann. xsiv. (1884),\npp. 157-171, appears to have been first proved by Pringsheim.\n\nJ These methods are due to Cauchy.\n\n%\n% 28\n%\n\nPringsheim's theorem* : If S exists and the sums by rows and columns\nexist, then each of these suyns is equal to S.\n\nFor since S exists, then we can find m such that\n\nI *S /i, p - S < e, if yu. > 7u, V > m.\n\nAnd therefore, since lim >Sf exists, Mvn 8, ) - S %e; that is to say,\n\n  Sp - S \\ i e when fx > m, and so (§ 222) the sum by rows converges\nto S. In like manner the sum by cohimns converges to S.\n\n\\Subsection{2}{5}{2}{Absolutely convergent double series.}\n\nWe can prove the analogue of \\hardsubsectionref{2}{4}{1} for double series, namely that if\nthe terms of an absolutely convergent double series are taken in any\norder as a simple series, their sum tends to the same limit, provided\nthat every term occurs in the summation.\n\nLet cr be the sum of the rectangle of fx rows and v columns of the\ndouble series whose general element is | m, |; and let the sum of\nthis double series be cr. Then given e we can find m and n such that\no- - cr < e whenever both fi > m and v> n.\n\nNow suppose that it is necessary to take iV terms of the deranged\nseries (in the order in which the terms are taken) in order to include\nall the terms of >S j/-fi,3/+i, and let the sum of these terms be ty\n\nThen a' - 'Sj/-t-i, j/+i consists of a sum of terms of the type Up,q\nin which p > m, q >n whenever M > m and M > n; and therefore\n\nI h' - Sm+1,3T+1 O\" - 0-j/+i\\ 3/+1 < 2 f-\n\nAlso, S- Sji+i ijj i consists of terms iip q in which j) > m, q> n;\ntherefore I S - Sjfi+ijf+i I <r - o-jf+ M+i < 2 ' therefore | S-ty j <\ne; and, corresponding to any given number e, we can find X; and\ntherefore ty- S.\n\nExample 1. Prove that in an absolutely convergent double series, 2 !<\n(, exists, and\n\nH = l\n\nthence that the sums by rows and columns respectively converge to S.\n\n[Let the sum of fi rows of v columns of the series of moduli be t,\nand let t be the sum of the series of moduli.\n\nThen 2 \\ ?i, \\ < t, and so 2 m,;, converges; let its sum be 6;\nthen\n\n\\ bi\\ + \\ b.i\\ + ... + \\ b \\ lim t t,\n\nand so 2 b converges absolutely. Therefore the sum by rows of the\ndouble series\n\nexists, and similarly the sum by columns exists; and the required\nresult then follows from Pringsheim's theorem.]\n\n* Loc. cit. p. 117.\n\n%\n% 29\n%\n\nExample 2. Shew from first principles that if the terms of au\nabsokitely convergent double series he arranged in the order\n\n M + ( 2,l + l,2) + ( :i,l + 2,2 + \"l,3') + (*/4,l + --- + '<l,4) +\n---5\n\ntliis series converges to S*.\n\n\\Subsection{2}{5}{3}{Cauchy's theorem* on the multiplication of absolutely convergent series.}\n\nWe shall now shew that if two series\n\nS = u + V. + (/3 + . . . and T =Vi + Vo + V3+ ...\n\nare absolutely convergent, then the series\n\nP = U Vi + 1 2 1 + \"i V-i + . . .,\n\nformed by the products of their terms, written in any order, is\nabsolutely con- vergent, and has for sum ST.\n\nLet Sn = Ui + U., + . . . + Un,\n\nTn=V, + V.,+ ...+ Vn.\n\nThen ST = lim S,, lini T = lim (SnTn)\n\nby example 2 of \\hardsectionref{2}{2}. Now\n\nSnTn = Ui I'l + U>Vi + . . . 4- HnVi + l/il'2+ U.,V. + ... + UnV.\n\n+\n\nBut this double series is absolutely convergent; for if these terms\nare replaced by their moduli, the result is a Tn, where\n\n<7\" = 1 \"1 I + I /2 I +    + 1 n I, rn = \\ Vi \\ + \\ v.,\\ + ...+\\\nVn\\,\n\nand cTnTn is known to have a limit. Therefore, by \\hardsectionref{2}{2}TODO:verifyref, if the\nelements of the double series, of which the general term is u,nVn, be\ntaken in any order, their sum converges to ST.\n\nExample. Shew that the series obtained by multiplying the two series 2\n22 23 4,111\n\ni + + + 2;. + 24 + -' 1 + 1 + + + -'\n\nand rearranging accoi'ding to powers of z, converges so long as the\nrepresentative point of z lies in the ring-shaped region bounded by\nthe circles \\ z\\ = l and | a | = 2.\n\n\\Section{2}{6}{Fower-Seriesf.TODO}\n\nA series of the type\n\nUo + aiZ + a z- + a-iZ\" - ...,\n\nin which the coefficients a, a,a2, a, ... are independent of z, is\ncalled a series proceeding according to ascending powers of z, or\nbriefly a poiver-series.\n\n* Analyse Algebrique, Note vii.\n\nt The results of this section are due to Cauchy, Analyse Algebrique,\nCh. ix.\n\n%\n% 30\n%\n\nWe shall now shew that if a power-series converges for any value z of\nz, it ivill he absolutely convergent for all values of z whose\nrepresentative points are luithin a circle luhich passes through z and\nhas its centre at the origin.\n\n00\n\nFor, if z be such a point, we have j | < i 'o | . Now, since S, V\nconverges,\n\nanZo must tend to zero as ?i\\rightarrow \\infty, and so we can find M (independent\nof n) such that\n\nI 0.nZ,'' \\ < M.\n\nThus i anz'' \\ < M \\ .\n\n00\n\nTherefore every term in the series S | n \" | is less than the\ncorresponding term in the convergent geometric series\n\n2i)/ -\n\nthe series is therefore convergent; and so the power-series is\nabsolutely convergent, as the series of moduli of its terms is a\nconvergent series; the result stated is therefore established.\n\nLet lim | a | ~ \"* = r; then, from \\hardsubsectionref{2}{3}{5}, 2 anZ converges absolutely\nwhen\n\n00\n\n\\ z\\ < r\\ if \\ z r, anZ\" does not tend to zero and so 2 a z diverges\n\\hardsectionref{2}{3}).\n\nThe circle \\ z\\=r, which includes all the values of z for which the\n\npower-series\n\ntto + aiZ + a.iZ\"- + ag -f- . . .\n\nconverges, is called the circle of convergence of the series. The\nradius of the circle is called the radius of convergence.\n\nIn practice there is usually a simpler way of finding r, derived from\nd'Alembert's test \\hardsubsectionref{2}{3}{6}); r is lim ( / + 1) if this limit exists.\n\nA power-series may converge for all values of the variable, as\nhappens, for instance, in the case of the series*\n\nz z\n\nwhich represents the function sin z; in this case the series\nconverges over the whole r-plane.\n\nOn the other hand, the radius of convergence of a power-series may be\nzero; thus in the case of the series\n\nI + 1\\ z + 2\\ z- - Z\\ z + 4>\\ z' - ...\n\nwe have\n\nU\n\n= n\\ z\n\n* The series for c, sin z, cos z and the fundamental properties of\nthese functions and of log z will be assumed throughout. A brief\naccount of the theory of the functions is given in the Appendix.\n\n%\n% 31\n%\n\nwhich, for all values of n after some fixed value, is greater than\nunity when z has any value different from zero. The series converges\ntherefore only at the point z = 0, and the radius of its circle of\nconvergence vanishes.\n\nA power-series may or may not converge for points which are actually\non the periphery of the circle; thus the series\n\nz z- z'-' z* -'- + p + 25 + 3 + 4i +   '\n\nwhose radius of convergence is unity, converges or diverges at the\npoint z = 1 according as s is greater or not greater than unity, as\nwas seen in \\hardsubsectionref{2}{3}{3}.\n\nCorollary. If ( ) be a sequence of positive terms such that lim(a +i/a\n) exists, this limit is equal to lim '\"'.\n\n\\Subsection{2}{6}{1}{Convergence of series derived from a power-series.}\n\nLet cify + i2 + a.iZ- + a z + a r* + . . .\n\nbe a power-series, and consider the series\n\nai + 1a.,z - a z\" + 4a42-' + . . ., which is obtained by\ndifferentiating the power-series term by term. We shall now shew that\nthe deHved series has the same circle of convergence as the original\nseries.\n\nFor let 3 be a point within the circle of convergence of the\npower-series; and choose a positive number 7'i, intermediate in value\nbetween \\ z\\ and r the\n\nX\n\nradius of convergence. Then, since the series S n i\" converges\nabsolutely, its\n\nterms must tend to zero as n - > x; and it must therefore be possible\nto find a positive number M, independent of, such that ! I < Mr ~ for\nall values of n.\n\n X\n\nThen the terms of the series 2 ?i j a | 1 2- 1 \"~ are less than the\ncorre- sponding terms of the series\n\n =i\n\nM 71:2,\"-'\n\nn =i n\"~'\n\nBut this series converges, by \\hardsubsectionref{2}{3}{6}, since \\ z\\ < r- . Therefore, by \\hardsubsectionref{2}{3}{4}, the series\n\n ncin \\ z\\''-\n\nX\n\nconverges; that is, the series 2 la \"\" converges absolutely for all\npoints z\n\nn = l\n\nX\n\nsituated within the circle of convergence of the original series 2\nOnZ'' . When\n\nn =\n\nI I > ? anZ does not tend to zero, and a fortiori na z '' does not\ntend to zero; and so the two series have the same circle of\nconvergence.\n\n%\n% 32\n%\n\nCorollary. The series 2 - - - > obtained by integrating the original\npower-series term by term, has the same circle of convergence as 2 a\nz\"\"-.\n\nn=0\n\n\\Section{2}{7}{Infinite Products.}\n\nWe next consider a class of limits, known as infinite products.\n\nLet 1 + ai, 1 + a.2, 1 + as,    be a sequence such that none of its\nmembers vanish. If, as n oo, the product\n\n(1 + ai) (1 + 2) (1 + as)   . (1 + a ) (which we denote by Tin)\ntends to a definite limit other than zero, this limit is called the\nvalue of the infinite product\n\nn = (l + a0(l + a,)(l + a3)...,\n\nand the product is said to be convergent *. It is almost obvious that\na necessary condition for convergence is that lim cin = 0, since lim\nUn-i = lim Un + 0.\n\n00\n\nThe limit of the product is written II (1 4- cin).\n\nn-l m ( rn \\\n\nNow n (l+a ) = exp- S log(l +a,,)K\n\nw=l I n-\\ . J\n\nandf exp lim, ] = lim exp ii,n]\n\nif the former limit exists; hence a sufficient condition that the\nproduct\n\n00\n\nshould converge is that 2 log(l + a ) should converge when the\nlogarithms\n\nn = l\n\nhave their principal values. If this series of logarithms converges\nabsolutely, the convergence of the product is said to be absolute.\n\nThe condition for absolute convergence is given by the following\ntheorem : in order that the infinite product\n\n(l+a,)(l+a2)(l + a3)... may he absolutely convergent, it is necessary\nand sufiicient that the series\n\ntti + 02 + as + . . . sJiould be absolutely convergent.\n\nFor, by definition, 11 is absolutely convergent or not according as\nthe\n\nseries\n\nlog (1 + Oi) + log (1 + Oo) + log (1 + ag) + ...\n\nis absolutely convergent or not.\n\n* The convergence of the product in which rt,i\\ i= - l/n was\ninvestigated by WaUis as early as 1655.\n\nt See the Appendix, § A-2.\n\n%\n% 33\n%\n\nNow, since lim a = 0, Ave can find m such that, when n > ?n, | a | < |\n; and then\n\n  \"' log (1 + Un) - 1\n\n2- + 2 +    - 2\n\n<2 . + 23+--- =\n\nAnd thence, when n> m, - h 5 therefore, by the comparison\n\ntheorem, the absolute convergence of 2 log (1 + ) entails that of Sa\nand\n\nconversely, provided that a 4= - 1 for any value of n.\n\nThis establishes the result*.\n\nIf, in a product, a finite number of factors vanish, and if, when\nthese are suppressed, the resulting product converges, the original\nproduct is said to converge to zero. But such\n\na product as n (!- \"') is said to diverge to zero.\n\nn=2\n\nCorollary. Since, if Sn- 'l, exp ( S' )- -exp, it follows from \\hardsubsectionref{2}{4}{1}\nthat the factors of an absolutely convergent product can be deranged\nwithout aftecting the value of the product.\n\nExample 1. Shew that if n (1 + ) converges, so does 2 log (1 +a ), if\nthe logarithms\n\nH=l )l=l\n\nhave their principal values.\n\nExample 2. Shew that the infinite product\n\nsin z sin \\ z sin \\ z sin z z ' \\ z ' \\ z ' \\ z '\" is absolutely\nconvergent for all values of z.\n\n[For (sin-j /(-) can be written in the form 1 - |, where | X |<X- and\n/ i.s inde-\n\nl endent of n; and the series 2 - is aVjsolutely convergent, as is\nseen on comparing\n\nit with 2 - . The infinite product is therefore absohitely\nconvergent.] w = l '\n\n\\Subsection{2}{7}{1}{Some examples of infinite products.}\nConsider the infinite\nproduct\n\n  - ) -m-£)\n\nwhich, as will be proved later (§ 7 '5), represents the function z sin\nz.\n\nIn order to find whether it is absolutely convergent, we must consider\nthe\n\nseries 2 -, or -- S - : this series is absolutelv convergent, and so\nthe\n\nproduct is absolutely convergent for all values of z. Now let the\nproduct be written in the form\n\n* A discussion of the convergence of infinite products, in which the\nresults are obtained without making use of the logarithmic function,\nis given by Pringsheim, Math. Ann. xxxm. (1889), pp. 119-154, and also\nby Bromwich, Infinite Series, Ch. vi.\n\nW. M. A. 3\n\n%\n% 34\n%\n\nThe absolute convergence of this product depends on that of the series\n\nz z z z IT IT 27r 27r\n\nBut this series is only conditionally convergent, since its series of\nmoduli\n\n\\ z\\ \\ z\\ \\ z\\ \\ z\\ IT IT 27r 27r\n\nis divergent. In this form therefore the infinite product is not\nabsolutely\n\nconvergent, and so, if the order of the factors [ 1 + - ] is deranged,\nthere is\n\na risk of altering the value of the product.\n\nLastly, let the same product be written in the form\n\nin which each of the expressions\n\n1 + ) e mn\n\nmiTj\n\nis counted as a single factor of the infinite product. The absolute\nconvergence of this product depends on that of the series of which the\n(2?n - l)th and (2m)th terms are\n\n1 + e mn - 1.\n\nBut it is easy to verify that\n\nV mTTJ \\ m-/\n\nand so the absolute convergence of the series in question follows by\ncomparison\n\nwith the series\n\n111111\n\nl + l+2 + 2, + 3. + 3, + 4. + p+....\n\nThe infinite product in this last form is therefore again absolutely\n\nconvergent, the adjunction of the factors e '*\"\" having changed the\ncon- vergence from conditional* to absolute. This result is a\nparticular case of the first part of the factor theorem of Weierstrass\n\\hardsectionref{7}{6}).\n\nExample 1. Prove that n ](l - ) e\" is absolutely convergent for all\nvalues of\n\nn=i l.\\ c-f-?i/ )\n\nz, if c is a constant other than a negative integer.\n\nFor the infinite product converges absolutely with the series\n\nn=i t\\ c + nj J\n\n%\n% 35\n%\n\nNow the general term of this series is\n\nBut 2 - converges, and so, by \\hardsubsectionref{2}{3}{4}, 2 ](l je\"-!- converges\nabsolutely,\n\nn=l n=\\ l\\ C + %/ J\n\nand therefore the product converges absolutely.\n\nExample 2. Shew that n jl-H--] z~'\\ converges for all points z\nsituated\n\noutside a circle whose centre is the origin and radius unity.\n\nFor the infinite product is absolutely convergent provided that the\nseries\n\n=o / ] yn\n\n2 1 S-\"\n\nis absolutely convergent. But lim (l -- ) =e, so the limit of the\nratio of the (w + l)th\n\nterm of the series to the Jith term is -; there is therefore absolute\nconvergence when\n\nz\n\n1\n\nExample 3. Shew that\n\n- < 1, i.e. when ] 2 | > 1. 1.2.3...(m-l)\n\n2 2 \"\"U'\n\n(2+l)(2 + 2)...(2 + 7ft-l)\n\ntends to a finite limit as ??j- -x, unless 2 is a negative integer.\n\nFor the expression can be written as a product of which the nth factor\nis\n\n2 + 7i \\ n ) ~\\ n) V / I\n\nThis product is therefore absolutely convergent, provided the series\n\n* 1 is absolutely convergent; and a comparison with the convergent\nseries 2 - shews that\n\nthis is the case. When 2 is a negative integer the expression does not\nexist because one of the factors in the denominator vanishes.\n\nExample 4. Prove that For the given product\n\n,|o..(,-i)(i-i)(i.|)...(.-, )(i- )(i.£)\n\n(,77 \\ 2 3 \"''2 ' 2k-l 2k k/\n\n--log 2 .\n\n= e sin 2.\n\n= lim\n\nX 2 1 - - e\n\n -27'\n\n1-\n\n2/C7\n\n,2kn\n\n1 +\n\n2 \\ -1-\n\nklT\n\n= lim e\"-V 2+3\"-+2A-i 2k) Ji\\ \\ en fi + \\ e~ (l- e (1+ e <!-...,\n\n3-2\n\n%\n% 36\n%\n\nsince the product whose factors are\n\n1 - - ) e\n\nis absohitely convergent, and so the order of its factors can be\naltered.\n\nSince log2 = l-HJ-i + *---M\n\nthis shews that the given product is equal to\n\n--logs . e \" sin 2.\n\n\\Section{2}{8}{Infinite Determinants.}\n\nInfinite series and infinite products are not by any means the only\nknown cases of limiting processes which can lead to intelligible\nresults. The researches of G. W. Hill in the Lunar Theory* brought\ninto notice the possibilities of infinite determinants.\n\nThe actual investigation of the convergence is due not to Hill but to\nPoincare, Bull, de la Soc. Math, de France, xiv. (1886), p. 87. We\nshall follow the exposition given by H. von Koch, Acta Math, xvi,\n(1892), p. 217.\n\nLet Aik be defined for all integer values (positive and negative) of\ni, k, and denote by\n\nthe determinant formed of the numbers Aik i,k = - m, ... +m); then if,\nas m - cc, the expression D,n tends to a determinate limit D, we\nshall say that the infinite determinant\n\n[- >i-J?,i-=-< ...+oo\n\nis convergent and has the value D. If the limit D does not exist, the\ndeter- minant in question will be said to be divergent.\n\nT he elements An, (where i takes all values), are said to form the\nprincipal diagonal of the determinant D; the elements Aik, (where i is\nfixed and k takes all values), are said to form the 7'ow i; and the\nelements A c, (where k is fixed and i takes all values), are said to\nform the column k. Any element A-iy; is called a diagonal or a\nnon-diagonal element, according as = A; or i \\$ k. The element udo.o\nis called the origin of the determinant.\n\n\\Subsection{2}{8}{1}{Convergence of an infinite determinant.}\n\nWe shall now shew that an infinite determinant converges, provided the\nproduct of the diagonal elements converges absolutely, and the sum of\nthe non-diagonal elements converges absolutely.\n\nFor let the diagonal elements of an infinite determinant I) be denoted\nby l+a, and let the non-diagonal elements be denoted by ajj., i=¥k),\nso that the determinant is\n\n* Reprinted in Acta Mathematica, viii. (1886), pp. 1-36. Infinite\ndeterminants had previously occurred in the researches of Fiirstenau\non the algebraic equation of the 7ith degree, Darstellung der reellen\nWurzeln alyebraincher Gleiclnmgen durch Determinanten der\nCoeffizienten (Marburg, 1860). Special types of infinite determinants\n(known as continuants) occur in the theory of infinite continued\nfractions; see Sylvester, Math. I'apers, i, p.~504 and in, p.~249\n\n%\n% 37\n%\n\nThen, since the series  2\n\ni,k=-\n\nis convergent.\n\nNow form the products\n\nm / m \\ m / m\n\nP, = n 1+ 2 au-, P,= n 1+ 2\n\ni\"=-ni\\ fc= - m / i = -n( \\ fc=-m\n\nthen if, in the expansion of P i, certain terms are replaced by zero\nand certain other terms have their signs changed, we shall obtain i),\n; thus, to each term in the expansion of 2>, there corresponds, in\nthe expansion of P,, a term of equal or greater modulus. Now An + p -\nAn represents the sum of those terms in the determinant i), + p which\nvanish when the numbers TODO are replaced by zero; and to each of\nthese terms there corresponds a term of equal or greater modulus in Pm\n+ p- m-\n\nHence\n\nB\n\n,-D \\ < R,\n\n-P.\n\nTherefore, since P,n tends to a limit as ni-*-cc, so also Z), tends\nto a limit. This establishes the proposition.\n\n\\Subsection{2}{8}{2}{The rearrangement theorem for convergent infinite determinants.}\n\nWe shall now shew that a determinant, of the convergent form already\nco)isidered, remains convergent when the elements of any row are\nreplaced by any set of elements whose moduli are all less than some\nfixed positive mimber.\n\nReplace, for example, the elements\n\n-\" 0, - >i\n\n'0\n\nA,\n\nof the row through the origin by the elements\n\n.../!\\,,... jiQ ... ix,n ...\n\nwhich satisfy the inequality\n\nI M>- I < Mj where /x is a positive number; and let the new values of\nZ) i ' nd D be denoted by Dm and D'. Moreover, denote by /* / and P'\nthe products obtained by suppressing in P,n and P the factor\ncorresponding to the index zero; we see that no terms of 2) ' can\nhave a greater modulus than the corresponding term in the expansion of\nnP '; and consequently, reasoning as in the last article, we have\n\nwhich is sufficient to establish the result stated.\n\nExample. Shew that the necessary and sufficient condition for the\nabsolute conver- gence of the infinite determinant\n\nlim 1 a, ...\n\n 2\n\na., ... 1 as ...\n\nis that the series\n\nshall be absolutely convergent.\n\n,0 ... /3, 1\n\nai/3i + ao/32 + 03/33 + ...\n\n(von Koch.)\n\n%\n% 38\n%\n\nREFERENCES. Convergent series.\n\nA. Pringsheim, Math. Ann. xxxv. (1890), pp. 297-394.\n\nT. J. I'a. Bromwich, Theory of Infinite Series (1908), Chs. Ii, ill,\niv.\n\nConditionally convergent series.\n\nG. F. B. Riemann, Ges. Math. Werke, pp. 221-225. A. Pringsheim, Math.\nAmi. xxii. (1883), pp. 455-503.\n\nDouble series.\n\nA. Pringsheim, MUnchener Sitzungsherichte, xxvii. (1897), pp. 101-152.\n\n    Math. Ann. hill. (1900), pp. 289-321.\n\nG. H. Hardy, Proc. London Math. Soc. (2) i. (1904), pp. 124-128.\n\nMiscellaneous Examples.\n\n1. Evaluate litn (e \"\"\" ), lim (?i~ ogn) when a>0, b>0.\n\n2. Investigate the convergence of\n\n3. Investigate the convergence of\n\n(l.3...2n-l 4/1 + 3\n\n\\addexamplecitation{Trinity, 1904.}\n\n- 1 . . . . \\addexamplecitation{Peterhouse, 1906.}\n\n =i\\ 2. 4, ..2% 2>i + 2j '\n\n4. Find the range of vakies of z for which the series\n\n2sin2s-4sin- 2 + 8sin''s-... + (-)™ + i2 sin2' s+... is convergent.\n\n5. Shew that the series\n\n1 l\\ \\ 1 1\\\n\nZ 2+1 2 + 2 2 + 3\n\nis conditionally convergent, except for certain exceptional values of\nz; but that the series\n\n11 11\n\n1 Jl\\ 1\n\nZ 2+1 Z + p-\\ Z+p Z+p + l\n\n+\n\n+ ..\n\n2 + 2p + -l 2 + 2 + 5- in which (p + q) negative terms always follow p\npositive terms, is divergent. \\addexamplecitation{Simon.}\n\n6. Shew that\n\nl-i - 1 + 1-1- 1+1- =ilof 2\n\n7. Shew that the series\n\nis convergent, although\n\n8. Shew that the series is convergent although\n\n1111\n\n1\" 23 3\" 4\n\n 2n + l/W2n- a>-\n\na + /3- + a3 + /3< + ...\n\n\\addexamplecitation{Trinity, 1908.} (l<a</3)\n\n\\addexamplecitation{Ceskro.}\n\n(0<a</3<l)\n\n\\addexamplecitation{Cesaro.}\n\n%\n% 39\n%\n\n9. Shew that the series\n\n   z\"-i (H-%-i) -l\n\n39\n\n =l(3\"-l) 3 -(l+ ->)\n\nconverges absolutely for all values of z, except the values\n\nZ-(\\ j gtkKilm\n\n(a = 0, 1; k = 0, 1, ... m-\\; i = l, 2, 3, ...).\n\n10. Shew that, when s> 1,\n\nI i= + i r + j-j- i Lii\n\nand shew that the series on the right converges when <s< 1.\n\n(de la Vallee Poussin, Mem. de VAcad. de Belgique, liii. (1896), no.\n6.)\n\n11. In the series whose general term is\n\n   = y - yi'\"'+l', (0<9<1< )\n\nwhere v denotes the number of digits in the expression of n in the\nordinary decimal scale of notation, shew that\n\nlim u = q,\n\nand that the series is convergent, although lim Mn+i/wn==c\n\n12. Shew that the series\n\nwhere !? v = j' \"\"'\"\"\"', (0<5'<1)\n\nis convergent, although the ratio of the (?t + l)th term to the nth is\ngreater than unity\n\nwhen n is not a triangular number. \\addexamplecitation{Ceskro.}\n\n13. Shew that the series\n\n2\n\n =o( <' + )*' where w is real, and where w + nY is understood to mean\ne iog(w + n) the logarithm being taken in its arithmetic sense, is\nconvergent for all values of s, when 1 x) is positive, and is\nconvergent for values of s whose real part is positive, when x is real\nand not an integer.\n\n14. If Un>0, shew that if 2?< converges, then lim nu, = 0, and that,\nif in addition\n\nM,i w,i + i, then lim (?i?< ) = 0.\n\n15. If\n\nshew that\n\nm - n m + n - 1) !\n\n\"MLn - om+n\n\n2m+n m\\ n\\ '\n\nam,o = 2-'\", ao, =-2-, ao,o=0,\n\nn!=0 i=0 / =0 \\ m=0\n\n(m, n>0)\n\n\\addexamplecitation{Trinity, 1904.}\n\n16. By converting the series\n\n1+:\n\n16g2 24g3\n\n+ .2 \"f\" 1 l3 +    ?\n\nl-q 1+ 2 l-jS (in which | g- 1 < 1), into a double series, shew that\nit is equal to\n\n1 +\n\nX2 +\n\n2 8(73\n\n  qf (1+ 2)2 (1\\ 3)2\n\n\\addexamplecitation{Jacobi.}\n\n%\n% 40\n%\n\n17. Assuming that sin2 = 3 n (I--5-,),\n\nshew that if ? - qo and 3t-*-co iu such a way that lim (in\\ n) = k,\nwhere k is finite, then\n\nhm n' 1 + - =F'',\n\nthe prime indicating that the factor for which r = is omitted. (Math.\nTrip., 1904.)\n\n18. If Uq-=Ui = U2 = 0, and if, when n>\\,\n\nW2 -i- -\n\n 7l'\n\n1 1 1\n\nsi 11 n n y/n\n\nthen n (1 +?< ) converges, though 2 and 2 2 are divergent.\n\nn=0 n=0 ?i=0\n\n\\addexamplecitation{Math. Trip. 1906.}\n\n19. Prove that\n\nn - 1 - - exp 2\n\nwhere k is any positive integer, converges absolutely for all values\nof z.\n\n20. If 2 a,i be a conditionally convergent series of real terms, then\nn (l4-,i) con-\n\nn=l n=l\n\nverges (but not absolutely) or diverges to zero according as 2 a 2\nconverges or diverges.\n\n11=1\n\n\\addexamplecitation{Cauchy.}\n\n21. Let 2 dn be an absolutely convergent series. Shew that the\ninfinite determinant\n\n11=1\n\nA C)-\n\n(C- 4)2- 0\n\n~e.\n\n-00\n\n42- 0\n\n- 8\n\n42- 0\n\n- 4\n\n   42- 0\n\n42- 0\n\n42- 0 -\n\n-e,\n\n(c- 2)2- 0\n\n22- 0\n\n-01\n\n-02\n\n2- -00\n\n- 3\n\n    22- 0\n\n22- 0\n\n22- 0\n\n-( 2\n\n02- 0\n\n02- 0\n\n-0,\n\n02- 0\n\n-02\n\n'\" 02- 0\n\n02- 0\n\n-e.\n\n-02\n\n2'-0o\n\n- 1\n\n22- 0\n\n(c + 2)2- 22- 0\n\n 0 ~ 1\n\n- 2 -3,\n\n22- 0 -\n\n- 4\n\n-6,\n\n- 2\n\n-\n\n(c + 4)2- o\n\n  42- 0\n\n42- 0\n\n42- 0\n\n42- 0\n\n42- 0\n\nconverges; and shew that the equation\n\nis equivalent to the equation\n\nA(c) =\n\nsin2 Ittc = A (0) sin2 W(9o-- .\n\n(Hill; see \\hardsubsectionref{19}{4}{2}.)\n", "meta": {"hexsha": "d52acba51127d3ce776a3207715ffeea94c35254", "size": 57767, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch02.tex", "max_stars_repo_name": "CdLbB/Whittaker-and-Watson", "max_stars_repo_head_hexsha": "5fefdd2c36b4e48cc078a88afc77df289e680a73", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/tex/wandw-ch02.tex", "max_issues_repo_name": "CdLbB/Whittaker-and-Watson", "max_issues_repo_head_hexsha": "5fefdd2c36b4e48cc078a88afc77df289e680a73", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tex/wandw-ch02.tex", "max_forks_repo_name": "CdLbB/Whittaker-and-Watson", "max_forks_repo_head_hexsha": "5fefdd2c36b4e48cc078a88afc77df289e680a73", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.5607993197, "max_line_length": 130, "alphanum_fraction": 0.6799037513, "num_tokens": 18601, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8152324848629214, "lm_q2_score": 0.8705972700870909, "lm_q1q2_score": 0.7097391758079751}}
{"text": "Throughout this paper, bold capital letters denote matrices (e.g., $\\mathbf{X}$) and bold lower-case letters denote column vectors (e.g., $\\mathbf{x}$). $\\norm{\\mathbf{X}}_2 =\n(\\mathbf{X}^T\\mathbf{X})^{1/2}$ and $\\norm{\\mathbf{X}}_1 = \\sum_i |\\mathbf{x}_i|$\ndenote the $l_2$ and $l_1$ norms, respectively, with $T$ indicating the\nmatrix transpose. We also denote $\\norm{\\mathbf{X}}_F =\n(\\text{Tr}(\\mathbf{X}^T\\mathbf{X}))^{1/2}$ as the Frobenius norm, where\nTr indicate the trace of a matrix, i.e.,  $\\text{Tr}(X)\\equiv \\sum_{i=1}^n \\mathbf{x}_{ii}$.\n\nThis section contains the theory to implement a model such as the model presented in section \\ref{sec:fab}. We first present a brief overview of the mathematical background behind Optimization, Machine Learning and Artificial Neural Networks (ANN) in sections \\ref{sec:opt},\\ref{sec:ml} and \\ref{sec:ann} respectively. This theory leads up to all the necessary details involved with Sparse Coding, which is presented in \\ref{sec:sc} with two examples in computer vision and speech recognition to give the reader a better understanding of the concept. We later present an underlying concept called Non-Negative Matrix-Factorization in section \\ref{sec:nnsc} and the proof behind it. This technique is commonly used when dealing with tasks involving only positive values. \n\n%Lastly we present techniques for sparse approximations in section \\ref{sec:regularization}.\n\n\\label{sec:theoretical}\n\n\\subsection{Optimization}\n\\label{sec:opt}\nA problem that consists of finding the best solution from a set of feasible solutions. In mathematics and computer science, we refer this as a optimization problem. The standard form of a optimization problem is defined as\n\n\\begin{align*}\n& \\underbrace{\\text{min}}_{x} \\qquad f(x) \\\\\n& \\text{subject to} \\quad g_i(x) \\leq 0, \\ i = 0,\\dots,n\n\\end{align*}\nwhere we define $f(x)$ as the objective function to be minimized with respect to $x$ and $g_i(x)$ as the $i$:th constraint. By convention, the standard form is to minimize the objective function, we can maximize by negating the expression above \\cite{convex}.\n\n\\subsubsection{Cost function}\n\nAn objective function that is of standard form is often referred to as a cost or loss function that maps events or values of variables to some value that represents the \"cost\" involving that particular event. In classification, the cost is usually portrayed as \"penalty\" involving an incorrect classification. \n\nSupervised learning tasks, described in \\ref{sec:ml}, such as regression or classification for parameter estimation can be formulated as a loss function over a training set. The goal is to find the models that represent the input well; and the loss function quantifies the amount of deviation of the prediction from the true values \\cite{convex}.\n\n\\subsection{Machine Learning}\n\\label{sec:ml}\nMachine learning can be considered a sub-field of computer science and statistics which can be described as the study of algorithms that can learn from data. Mostly Machine learning is employed on computational tasks where designing and programming explicit, rule-based algorithms is infeasible. The common applications include spam filtering, optical character recognition (OCR), search engines and computer vision. It also has ties to both artificial intelligence and optimization.\n\nMachine learning tasks are typically classified into three broad categories, depending on the nature of the learning \"signal\" or \"feedback\" available to a learning system. One category is Supervised learning; where the computer is presented with example inputs and their desired outputs, given by the user, and the goal is to learn a general rule that maps inputs to outputs. The second category is Unsupervised learning, where no labels are given to the learning algorithm. This way the algorithm has to find its own structure in the input, this algorithm can be run to do stand-alone unsupervised learning (discover hidden patterns) or a means towards another type of end. Sparse Coding, which forms the basis of this thesis is a neural network model for unsupervised learning. Lastly we have reinforcement learning where a computer program interacts with a dynamic environment in which it must perform a certain goal (such as driving a vehicle), without a teacher explicitly telling it whether it has come close to its goal or not. Another example is learning to play a game by playing against an opponent \\cite{ainorvig}.\n\nA core objective of a learner is to generalize from its experience. Generalization in this context is the ability of a learning machine to perform accurately on new, unseen examples/tasks after having experienced a learning data set \\cite{bishop, bengio}. The training examples usually come from some unknown probability distribution and the learner has to build a general model so as to produce sufficiently accurate predictions from incoming new examples. \n\nIn machine learning one can simplify the inputs by mapping them into a lower-dimensional space through dimensionality reduction, described in section \\ref{sec:dim}.\n\n\\subsubsection{Dimensionalty Reduction}\n\\label{sec:dim}\n\nRepresenting an object as a vector of $n$ elements, we say that the vector is in $n$-dimensional space. Dimensionalty reduction refers to a process of representing the object of $n$-dimensional vector to an $m$-dimensional vector, where $m < n$. By refining the data in this way, we may lose information that might be valuable but we can represent it using less dimensions and in some cases we can even make a better prediction or analysis using this subspace. The common linear dimensionality reduction is called Principal Component Analysis (PCA), which find \"internal axes\" of a dataset, called components and sort by importance. It performs a linear mapping of the data to a lower-dimensional space in such a way that the variance of the data in the low-dimensional representation is maximized. The original space is not retained, i.e. we have lost some information but keep the most important variance to the space spanned by a few eigenvectors. The first $m$ components are then used as the new basis. Each of these components may be thought of as a high-level feature, describing data vectors better than original axes \\cite{dr}.\n\nDimensionality reduction can be divided into feature selection and feature extraction. Feature selection approaches try to find a subset of the original variables, while feature extraction transforms the data in high-dimensional space to that of a fewer dimensional space. The data transformation may be linear, as in PCA, but many nonlinear dimensionality reduction techniques also exist \\cite{samet}. \n\nA different approach to nonlinear dimensionality reduction is through the use of autoencoders, a special kind of feed-forward neural networks with a bottle-neck hidden layer, which is presented in-depth in section \\ref{sec:autoencoders}.\n\n\\subsubsection{Deep Learning}\n\\label{sec:deeplearning}\n\nA branch of machine learning based on algorithms that try to model high-level abstractions in data by using complex structures or multiple non-linear transformations is referred to deep learning \\cite{deep, deep2}. Deep learning focuses on learning representations of data, where it has maybe come to replacing handcrafted features with efficient algorithms for unsupervised or semi-supervised feature learning and hierarchical feature extraction \\cite{deep3}.\n\nSome representation are based on interpreting information processsing in a nervous system inspired by advances in neuroscience, such as neural coding which attempts to define a relationship between the stimulus and the neuronal responses and the relationship among the electrical activity of the neurons in the brain \\cite{nervous}, see section \\ref{sec:scnn} for more information.\n\n\n\n\\subsection{Artificial Neural Networks}\n\\label{sec:ann}\n\nIn machine learning, a family of statistical learning algorithms called artificial neural networks (ANN) that were inspired by the work of McCulloch, Warren; Walter Pitts as early as 1943 to reflect a central nervous systems of animals \\cite{1943}. Generally ANN is a network with connected nodes and edges that form a artificial \"biological neural network\" which compute values from inputs provided by the edges connected to the nodes, even though the relation between the model and the brain is debated to what degree it really represents the brain \\cite{brain}. \n\nANN models are essentially mathematical functions defining a function \n\\begin{equation} \nf : X \\rightarrow Y\n\\end{equation}\n\nbut sometimes models are also associated with a particular learning algorithm, like the perceptron presented in the section \\ref{sec:perceptron} below. The learning output is obtained by connection weights, parameters and specific architecture by the learning algorithm. Two frameworks where ANN have made a great contribution is computer vision and speech recognition tasks, where rule-based programming have been unsuccessful at detecting patterns \\cite{perceptron}. The connection between neural networks and Sparse Coding is explained in section \\ref{sec:scnn}.\n\nThere are two main ways to \"feed\" the network with information. One being that of a feedforward neural network, the term “feedforward” indicates that the network has links that extend in only one direction. Except during training, there are no backward links in a feedforward network; all links proceed from input nodes toward output nodes. Eventually, despite the apprehensions of earlier workers, a powerful algorithm for apportioning error responsibility through a multi-layer network was formulated in the form of the backpropagation algorithm \\cite{backpro}. The effects of error in the output nodes are propagated backward through the network after each training case. The essential idea of backpropagation is to combine a non-linear multi-layer perceptron-like system capable of making decisions with the objective error function of the Delta Rule \\cite{backpro}.\n% checked\n\n\\pagebreak\n\\subsubsection{Perceptron}\n\\label{sec:perceptron}\nThe basic concept of a single layer perceptron was introduced by Rosenblatt in 1958 \\cite{perceptron}. It computes a single output by forming a linear combination of real-valued inputs and weights to possibly giving it through some non-linear function. This can be written as\n\n\\begin{equation} \n y = \\phi( \\sum\\limits_{i=1}^n a_i x_i + b ) = \\phi( \\mathbf{a}^T \\mathbf{x}+ b )\n\\end{equation}\n\nwhere  $\\mathbf{a}$ denotes the vector of weights,  $ \\mathbf{x}$ is the vector of inputs, $ b$ is the bias and $ \\phi$ is the activation function. Usually in multilayer networks, the activation function is often chosen to be the logistic sigmoid $ 1 / (1 + e^{-x})$ or the hyperbolic tangent $ \\tanh(x)$. They are convenient as they are close to linear near the origin, while they converge to a value when leaving the origin. This allows perceptron networks to model well both strongly and mildly nonlinear mappings \\cite{nonlinear}. Perceptrons were a popular machine learning solution in the 1980s, but since the 1990s faced strong competition from the much simpler support vector machines \\cite{svm}. More recently, there has been some renewed interest in backpropagation networks, such as perceptrons due to the successes of deep learning, see section \\ref{sec:deeplearning} for more detail.\n\nA typical perceptron layer network consists of source nodes forming the first layer. Following with one or more hidden layers, and an output layer of nodes, in the case where we have three or more layers it is usually called a multilayer perceptron (MLP). The input signal propagates through the network layer-by-layer. The signal-flow of such a network with one hidden layer can be seen in figure \\ref{fig:autoencoder} in section \\ref{sec:autoencoders}.\n\nThe computations performed by such a feedforward network with a single hidden layer with nonlinear activation functions and a linear output layer can be written mathematically as\n\n\\begin{equation}\n\\mathbf{y}= \\mathbf{f}(\\mathbf{x}) = \\mathbf{B}\\boldsymbol{\\phi}( \\mathbf{A}\\mathbf{x}+ \\mathbf{a} ) + \\mathbf{b}\n\\label{eq:nonlinear}\n\\end{equation}\n\nwhere  $\\mathbf{x}$ is a vector of inputs and  $\\mathbf{y}$ a vector of outputs.  $ \\mathbf{A}$ is the matrix of weights of the first layer,  $ \\mathbf{a}$ is the bias vector of the first layer.  $ \\mathbf{B}$ and  $ \\mathbf{b}$ are, respectively, the weight matrix and the bias vector of the second layer. \n\nMLP networks are typically used in supervised learning problems. Here the training set of input-output is pairs and the network must learn to model the dependency between them. The training here means adapting all the weights and biases ( $ \\mathbf{A},\n\\mathbf{B}, \\mathbf{a}$ and  $ \\mathbf{b}$ in equation \\ref{eq:nonlinear} to their optimal values for the given pairs  $ (\\mathbf{x}(t), \\mathbf{y}(t))$. The criterion to be optimised is typically the squared reconstruction error.\n%to read more on regression see section \\ref{sec:regularization}\n\n\\begin{equation}\n\\label{eq:error}\n\\sum_t \\vert\\vert\\mathbf{f}(\\mathbf{x}(t)) - \\mathbf{y}(t)\\vert\\vert^2.\n\\end{equation}\n\nBy setting the same values for the inputs as well as the outputs of the network, MLP networks can be used for unsupervised learning. The values of the hidden neurons extract the sources, this approach however is rather computationally intensive. \\cite{hidden}\n\n\\subsubsection{Autoencoder}\n\\label{sec:autoencoders}\n\nAutoencoder is a simple 3-layer neural network where output units (Layer $L_3$) are directly connected back to input units (Layer $L_1$). E.g. in a network presented in the figure below:\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.3]{./figures/autoencoder}\n\t\\caption[Caption for LOF]{As a concrete example, suppose the inputs $x$ are the pixel intensity values from a $10 \\times 10$ image (100 pixels) so  $n=100$, and there are $s_2=50$ hidden units in layer $L_2$.\t\\protect\\footnotemark}\n\t\\label{fig:autoencoder}\n\\end{figure}\n\\footnotetext{Stanford, \\texttt{http://ufldl.stanford.edu/wiki/index.php/Autoencoders\\_and\\_Sparsity},7 April 2013, (accesed 10 July 2015)}\nTypically in an autoencoder, the number of hidden units are much less than number of input and output. As a result, it first compresses (encodes) the input vector to \"fit\" in a smaller representation, and then tries to reconstruct (decode) it back. Here is where Sparse Coding can be said to be an extension of autoencoders with the constraint that the hidden layer must mostly be unused nodes (sparse), for more information on their similarities see the end of section \\ref{sec:sc}. Autoencoders simple form can be written as\n%\\[ D(d(e(x;\\theta^r); \\theta^d), x) \\]\n\n\\begin{equation}\n\\label{eq:auto}\n\\norm{\\mathbf{A}\\sigma(\\mathbf{A}^T \\mathbf{x}) - \\mathbf{x}}^2\n\\end{equation}\n\nwhere $\\sigma$ is a nonlinear function such as the logistic sigmoid, and $\\mathbf{A}$ is the activation density of the nodes. Once a deep network is pretrained, input vectors are transformed to a better representation. \\cite{autoencoder2}\n\n\\subsubsection{Sparse Coding and the connection to Neural Networks}\n\\label{sec:scnn}\n\nInformation retrieved is presented in the brain by the pattern of activations of the nerual connections formed, which we say form a neural code. This defines the pattern at which the neural activity corresponds to each presented information. \n% - rewrite\nOne property of the neural code is the fraction at which the neurons are active at any time. If a set of $N$ neurons, which can be active in the region $\\in [0,1/2]$ corresponding to low activity to strong activity, the expected value of this fraction is the density of the code. If the average fraction is above 1/2 we can replace each active neuron with an inactive one causing the fraction activity to get below 1/2 without loss of information and vice versa. Sparse coding is a neural code, which is of a relatively small set of neurons but with strong activity. For each set of information, a different subset is triggered of all available neurons.\\cite{scprimate}\n\n\\subsubsection{Local Codes}\nLow activity of neurons are local codes, where an item is represented by a small set of neurons or a separate neuron, this way one can ensure that there is no overlap between the representations of two items. To understand this we make an analogy that envolves the characters on a computer keyboard, where each key encodes a single character. This scheme has the advantage that it is simple and is also easy to decode, due to local codes only representing a finite number of combinations. More generalization is essential and a widely observed behavior. \\cite{mclaren}\n\n\\subsubsection{Dense Distributed Codes}\n\n% - rewrite\nThe opposite of local codes are dense codes, where the average activity ratio is $\\geq 0.5$, the item is represented by activities of all the neurons, which implies a representational capacity of $2^N$. Given the billions of neurons in a human brain, $2^N$, as the number of neurons the representational capacity of a dense code in the brain is immense, therefore its greatest feature is dealing with redundancy. Dense codes limit the number of memories that can be stored in an associative memory by simple learning rules. On the contrast, dense codes may facilitate good generalization performance and high redundancy.\n\n\\subsubsection{Sparse Codes}\n% - rewrite\n\nThese neural codes come to a favorable compromise between dense and local codes by having a small average activity ratio, called sparse codes \\cite{scprimate}. We can redeem the capacity of local codes by a modest fraction of active units per pattern, thus interference by items represented simultaneously will be less likely as capacity grows exponentially with average activity ratio. It is more likely that a single layer network with a sparse representation as input can learn to generate a target output \\cite{willshaw}. Due to linear discriminant functions being able to map higher proportions, see Perceptrons for linear separability in section \\ref{sec:perceptron}. Single layer networks for learning is therefore simpler, faster and substantially more plausible as a way of a biological implementation in the brain, as the redundancy for fault tolerance can be chosen by controlling the sparseness.\n\nFor learning various tasks a neural code can therefore contain codewords of varying sparseness. This implies that we want to maximize sparseness while having a high representational capacity. One plausible way would be to assign sparse codes for items of high probability while having distributed codes for lower probability items.\nA code with a given average sparseness can contain codewords of varying sparseness. If the goal is to maximize sparseness while keeping representational capacity high, a sensible strategy is to assign sparse codewords to high probability items and more distributed codewords to lower probability items. However, if we would only store identities of active units, the code would have short average discription length \\cite{cover}. Some perceptual learning could be explained by prediction of the sparseness of the encoded items with high probability.\n\nBelow is an example where the input signal is an image, the basis vectors represent the sparse coding method. In the example below we present an explicit visualization of the sparse coding. \n\n\\begin{ex}{}\n\\label{ex:scimage}\nAn image reconstruction usage of sparse coding. The basis vectors are visualized in Figure \\ref{fig:basex}, which have been trained from natural images. The basis vectors are then used to represent different parts of a picture using the activation matrix.\n\n\\begin{figure}[H]\n\\centering\n        \\includegraphics[scale=0.20]{./figures/basisexample.jpg}\n        \\caption{Sparse basis functions learned from images.}\n        \\label{fig:basex}   \n\\end{figure}\n\nThese basis vectors are used with activations to represent an image. The activation matrix is best represented in the figure below, where a part of an image uses the activated vectors (non-black) to represent the corresponding image.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.30]{./figures/Sparsejen_black_v2.jpg}\n\\caption{An image, encoded with the basis functions from figure \\ref{fig:basex} and reconstructed in the right plot using certain subsets of activations and basis functions for each patch. The red square represents a patch where we have encoded the activations for some basis functions, shown as the middle plot, to reconstruct the patch of the decoded image to the right. Notice, among the entire set of basis functions, only a fair amount is used and the rest is black indicated that they are not being used, i.e. we have a \"sparse\" representation of the image. \\protect\\footnotemark\n}\n\\label{fig:recex}\n\\end{figure}\n\n\\end{ex}\n\\footnotetext{Peter Foldiak and Dominik Endres ,Scholarpedia, \\texttt{http://www.scholarpedia.org/article/Sparse\\_coding}, 2008, (accessed 10 June 2015)}\n\\newpage\n\n\\subsubsection{Sparse Coding}\n\n\\label{sec:sc}\nSparse Coding is similar to Principal Component Analysis (PCA) in that we want to find a small number of basis functions to represent an input signal as a linear combination presented in equation \\ref{eq:lincomb} but with a constraint that the learned basis functions need to be sparse and of a higher dimension than the input data. Here we present the general theory behind Sparse Coding and an example used for signal processing in example \\ref{ex:sc} \\cite{olshausen}.\n\n\\begin{equation}\n\\mathbf{x} \\approx \\mathbf{BA}\n\\label{eq:lincomb}\n\\end{equation}\n\nConsider a linear system of equations $\\mathbf{x} = \\sum_{i=1}^ka_i \\phi_i$, the vector coefficients $a_i$ are no longer uniquely determined by the input vector $\\mathbf{x}$, where $\\sum_{i=1}^ka_i = \\mathbf{B}$ is an\nunderdetermined $m\\times p$ matrix $(m \\ll p)$. $\\mathbf{B}$, is called the dictionary or sometimes design matrix. The problem is to estimate the signal $\\alpha$, subject to the\nconstraint that it is sparse. The underlying motivation for sparse\ndecomposition problems is that even though the observed values are in\nhigh-dimensional ($m$) space, the actual signal is organized in some\nlower-dimensional subspace $(k \\ll m)$. This implies that $\\mathbf{x}$ can be decomposed as a linear combination of only a few $m \\times 1$ vectors in $\\mathbf{B}$, called atoms \\cite{sc}.\n\nRegular PCA allows us to learn a complete set of basis vector while the Sparse Coding wishes to learn an \\textbf{over-complete}\nbasis to recognize patterns and structures inherent in the input data.\nAlthough we now can recognize patterns in the data, we have coefficients of the columns\n$\\alpha_i$ that are no longer uniquely determined by the input vector\n$\\mathbf{x} \\in \\mathbb{R}^2$. This is why we introduce a criterion called\n\\textbf{sparsity} to resolve the degeneracy introduced by\nover-completeness, where sparsity is defined as having few non-zero\ncomponents. The definition of the sparse coding cost function on a set of $m$\ninput vectors is presented in equation \\ref{eq:sccost}. In artificial\nneural networks, the cost function represents a function to return a number representing how well the neural network performed to map training examples to correct output \\cite{olshausen}.\n\n%\\begin{equation}\n%\\mathbf{x} = \\mathbf{BA}\n%\\label{eq:lincomb}\n%\\end{equation}\n%\n%Consider a linear system of equations $\\mathbf{x} = \\mathbf{BA}$, where $\\mathbf{B}$ is an\n%under-determined $m\\times p$ matrix $(m \\ll p)$. $\\mathbf{B}$, is called the dictionary or the design matrix. The problem is to estimate the signal $\\mathbf{A}$, subject to the\n%constraint that it is sparse. The underlying motivation for sparse\n%decomposition problems is that even though the observed values are in\n%high-dimensional ($m$) space, the actual signal is organized in some\n%lower-dimensional subspace $(k \\ll m)$. This implies that $\\mathbf{x}$ can be decomposed as a linear combination of only a few $m \\times 1$ vectors in $\\mathbf{B}$, called atoms. \n%\n%Regular PCA allow us to learn a complete set of basis vector while the Sparse Coding wish to learn a \\textbf{over-complete}\n%basis to recognize patterns and structures inherent in the input data.\n%Although we now can recognize patterns in the data, we have coefficients of the columns\n%$\\mathbf{B}^(j)$ that are no longer uniquely determined by the input vector\n%$\\mathbf{x} \\in \\mathbb{R}^2$. This is why we introduce a criterion called\n%\\textbf{sparsity} to resolve the degeneracy introduced by\n%over-completeness, where sparsity is defined as having few non-zero\n%components. The definition of the sparse coding cost function on a set of $m$\n%input vectors is presented in equation \\ref{eq:sccost}. In artificial\n%neural networks, the cost function represents a function to return a number representing how well the neural network performed to map training examples to correct output.\n\n\\begin{equation}\n\\min_{a_i^{(j)},\\phi_i}\\sum_{j=1}^m\n\\ \\underbrace{\\norm{\\mathbf{x}^{(j)}-\\sum_{i=1}^ka_i^{(j)}\\phi_i}^2}_{\\text{reconstruction term}}+\\underbrace{\\lambda \\sum_{i=1}^k\nS(a_i)^{(j)}}_{\\text{sparsity penalty}}\n\\label{eq:sccost}\n\\end{equation}\n\nwhere $S(a_i^{(j)})$ is a sparsity cost function which penalize $a_i$ for being far from zero.\n%and $\\norm{\\mathbf{x}^{(j)}-\\sum_{i=1}^ka_i^{(j)}\\phi_i}^2 = \\sum_{ij} [\\mathbf{x}_{ij}-(a \\phi)_{ij} ]^2$.\nThe first term in equation \\ref{eq:sccost} is a reconstruction term that forces the algorithm to provide a good representation of $\\mathbf{x}$ and the second as a sparsity penalty which force the representation to be sparse, while $\\lambda$ is a scale to determine the relative importance between the two contributions. Note that if we are given $S(a_i^{(j)})$, estimation of $\\phi_i$ is easy via least squares. In the beginning, we do not have $S(a_i^{(j)})$ however. Yet, many algorithms exist that can solve the objective above with respect to $S(a_i^{(j)})$. \n\n%Actually, this is how we do inference: we need to solve an optimisation problem if we want to know the h belonging to an unseen $\\mathbf{x}$.\n% timo banned it\n\nThe most direct approach to determine sparsity is through the \"$L_0$\" norm $S(a_i) = \\mathbf{1}(|a_i| > 0 )$, which is non-differentiable and difficult to optimize. The more common choices for sparsity cost penalty $S(a_i)$ are the $L_1$, $S(a_i) = |a_i|_1$ and the log penalty $S(a_i)=\\log(1+a^2_i)$. To prevent empirical scaling of $a_i$ and $\\phi_i$ to make the sparsity penalty arbitrarily small, we constrain $\\norm{\\phi}^2$ to be less than some constant $C$. Including the constraint demand we get the full sparse coding cost function \\cite{olshausen}\n\n\\begin{align}\n\\begin{split}\n\\min_{a_i^{(j)},\\phi_i} \\quad & \\sum_{j=1}^m\n\\norm{\\mathbf{x}^{(j)}-\\sum_{i=1}^ka_i^{(j)}\\phi_i}^2+\\lambda \\sum_{i=1}^kS(a_i)^{(j)}\n\\\\\n\\text{subject to} & \\quad \\norm{\\phi_i}^2 \\leq C, \\forall \\ i = 1,\\dots,k\n\\end{split}\n\\end{align}\n\nBelow we present another example of sparse coding but used in a context of signal processing of a one dimensional signal.\n\\begin{ex}{}\n\\label{ex:sc}\nSay, we have an infinite $1-D$ time-series signal. We can represent this signal in the Fourier domain, where we get a few coefficients representing the whole signal in a different domain.\n\\begin{equation*}\n\\mathbf{x} = \\sum_{i=1}^k a_i \\phi_i \\approx \\mathbf{x}'\n\\end{equation*}\n\nWe want to find these few coefficients ($a_i$,the basis) of an input signal in the alternative domain and reconstruct your signal with these few coefficients. Once we have found the coefficients, we determine how close is the reconstructed signal to our original input signal by the error. That is to minimize our representation: $|\\mathbf{x}- \\mathbf{x}'|$.\n\nThe least number of basis functions of the input signal that minimize the above error, is the best basis representation of our input signal. We then could use the $L_2$ norm for the error, which is what we are most familiar with and it computes the Euclidean, square difference, between basis functions. Basically, $L_0$ norm looks like a Dirac Delta Function, $L_1$ norm looks like a diamond and $L_2$ norm looks like a circle and are the other types of norms which can be used in this context.\n\n\\end{ex}\n\nTo end this section we would like to review the difference between Sparse Coding, Autoencoders and Sparse-PCA, as it is somewhat missleading at times.\n\n\\begin{itemize}\n\t\\item{Autoencoders do not encourage sparsity in their general form.}\n\t\\item{An autoencoder uses a model for finding the codes, while sparse coding does so by means of optimisation.}\n\\end{itemize}\n\nNote that Sparse Coding, looks almost the same as Autoencoder as in equation \\ref{eq:auto} in section \\ref{sec:autoencoders} Autoencoders, once we set $\\mathbf{B}=\\sigma (\\mathbf{A}^T\\mathbf{x})$. For natural image data, regularized autoencoders and sparse coding tend to yield very similar $\\mathbf{B}$. However, auto encoders are much more efficient and are easily generalized to much more complicated models. E.g. the decoder can be highly nonlinear, e.g. a deep neural network. Therefore, Sparse coding can be seen as a modification of the sparse autoencoder method in which we try to learn the set of features for some data \"directly\".\n\nIn Sparse-PCA one also wants to represent a collection of vectors as a linear combination of basis vectors (a.k.a. principal components). Here the focus, as in traditional PCA, is on choosing a small $n \\ll M$ number of basis vectors that together \"explain as much variance\" as possible, i.e. represent the original data as well as possible. And the sparsity is enforced not on the mapping bases $\\rightarrow$data, but on the mapping data$\\rightarrow$bases, because the idea is to have PCs that are linear combinations of only small subsets of original features/vectors (to ease the interpretation), as explained in Zou, Hastie, and Tibshirani, 2006 \\cite{zou}.\n\n\\subsubsection{Non-Negative Sparse Coding}\n\n\\label{sec:nnsc}\nIn standard Sparse Coding, described above, the data is described as a combination of elementary features involving both additive and subtractive interactions. The fact that features can ‘cancel each other out’ using subtraction is contrary to the intuitive notion of combining parts to form a whole \\cite{hoyer}. Arguments for non-negative representations come from biological modeling, where such constraints are related to the non-negativity of neural firing rates. These non-negative representations assume that the input data $\\mathbf{X}$, the basis $\\mathbf{B}$, and the hidden components $\\mathbf{A}$ are all non-negative. Since energy consumption is an inherently non-negative quantity, this representation is beneficial is reasonable for modeling energy usage. \\\\\nNon-negative matrix factorization (NMF) can be performed by the minimization of the following objective function:\n\n\\begin{equation}\n\\label{eq:nmf}\nC ( \\mathbf{A,B} ) = \\frac{1}{2} \\norm{ \\mathbf{X} - \\mathbf{BA} }^2\n\\end{equation}\n\nHere Hoyer \\cite{hoyer} take $ \\norm{ \\mathbf{X} - \\mathbf{BA} }^2 = \\sum_{ij} [ \\mathbf{X}_{ij} - \\mathbf{BA}_{ij} ]^2$. Denoting a general matrix norm by\n\n\\begin{equation}\n\\| A \\|_{p,q}  =  \\left[\\sum_{j=1}^n \\left( \\sum_{i=1}^m |a_{ij}|^p \\right)^{q/p}\\right]^{1/q}\n\\end{equation}\n\nUsing $p=2,q = 2$ we get the Frobenius norm and we conclude that equation \\ref{eq:nmf} is using the Frobenius norm, this is an insurance for later use in the Discriminative Disaggregation via Sparse Coding model \\ref{alg:ddsc}.\n\\[ \\|A\\|_F^2 =\\left(\\sqrt{\\sum_{i=1}^m\\sum_{j=1}^n |a_{ij}|^2}\\right)^2 = \\sum_{i,j}[a_{ij}]^2\\]\n\n\n\\textbf{Definition 1.} Non-negative sparse coding (NNSC) of a non-negative data matrix $\\mathbf{X}$ (i.e. $\\forall \\ i,j \\ : \\ X_{ij} \\geq 0$) is given by the minimization of\n\\begin{equation}\n\\label{eq:nnsc}\nC ( \\mathbf{A,B} ) = \\frac{1}{2} \\norm{ \\mathbf{X} - \\mathbf{BA} }^2 + \\lambda \\sum_{ij} \\mathbf{A}_{ij}\n\\end{equation}\nsubject under the constraints $\\forall \\ i,j \\ : \\ B_{ij} \\geq 0, \\ A_{ij} \\geq 0$ and $\\forall \\ i \\ : \\ \\| \\mathbf{B}_i \\| = 1$, where $\\mathbf{B}_i$ denotes the i:th column of $\\mathbf{B}$. It is also assumed that the constant $\\lambda \\geq 0$. \n~\\\\\n\n\\pagebreak\n\\textbf{Theorem 1.} The equation \\ref{eq:nmf} is non-increasing under the update rule:\n\\begin{equation}\n\\label{eq:update}\n\\mathbf{A}^{t+1}=\\mathbf{A}^t.*(\\mathbf{B}^T\\mathbf{X})./(\\mathbf{B}^T\\mathbf{B}\\mathbf{A}^t+\\lambda)\n\\end{equation}\nwhere $.*$ and $./$ denote element-wise multiplication and division (respectively), and the addition of the scalar $\\lambda$ is done to every element of the matrix  $\\mathbf{B}^T\\mathbf{B}\\mathbf{A}^t$.\n~\\\\\n\nThe proof is seen below in \\ref{proof:noninc}. As each element of $\\mathbf{A}$ is updated by simply multiplying with some non-negative factor, it is guaranteed that the elements of $\\mathbf{A}$ stay non-negative under this update rule. As long as the initial values of $\\mathbf{A}$ are all chosen strictly positive, iteration of this update rule is in practice guaranteed to reach the global minimum to any required precision.\n\n\\begin{proof2}{Proof of Theorem 1}\nTo prove Theorem 1, first note that the equation \\ref{eq:nnsc} in definition 1 is separable in the columns of $\\mathbf{A}$ so that each column can be optimized without considering the others. We may thus consider the problem for the case of a single column, denoted s. The corresponding column of $\\mathbf{X}$ is denoted $x$, giving the objective\n\\begin{equation}\nF(\\mathbf{a}) = \\frac{1}{2}\\norm{\\mathbf{X}-\\mathbf{B}\\mathbf{a}}^2 + \\lambda \\sum_i a_i\n\\end{equation}\nWe need an iliary function $G(\\mathbf{a},\\mathbf{a}^t)$ with the properties that $G(\\mathbf{a},\\mathbf{a}) = F(\\mathbf{a})$ and $G(\\mathbf{a},\\mathbf{a}^t) \\geq F(\\mathbf{a})$. We will then show that the multiplicative update rule corresponds to setting, at each iteration, the new state vector to the values that minimize the auxiliary function:\n\\begin{equation}\n\\mathbf{a}^{t+1} = \\arg\\!\\min_{a} G(\\mathbf{a},\\mathbf{a}^t).\n\\end{equation}\nThis is guaranteed not to increase the objective function $F$, as\n\\begin{equation}\n\\label{eq:proof}\nF(\\mathbf{a}^{t+1}) \\leq G(\\mathbf{a}^{t+1},\\mathbf{a}^t) \\leq G(\\mathbf{a}^t,\\mathbf{a}^t) = F(\\mathbf{a}^t).\n\\end{equation}\nWe define the function $G$ as\n\\begin{equation}\nG(\\mathbf{a},\\mathbf{a}^t) = F(\\mathbf{a}^t) + (\\mathbf{a}-\\mathbf{a}^t)^T \\nabla F(\\mathbf{a}^t) + \\frac{1}{2} (\\mathbf{a}-\\mathbf{a}^t)^T\\mathbf{K}(\\mathbf{a}^t)(\\mathbf{a}-\\mathbf{a}^t)\n\\end{equation}\nwhere the diagonal matrix $\\mathbf{K}(\\mathbf{a}^t)$ is defined by elementwise division as\n\\begin{equation}\nK_{ij}(\\mathbf{a}^t) = \\delta_{ij}\\frac{(\\mathbf{B}^T\\mathbf{B}\\mathbf{a}^t)_i+\\lambda}{\\mathbf{a}^t_i},\n\\end{equation}\nwhere $i$ denotes the $i$:th column. Inserting $\\mathbf{a}$ in function $G$ we get the result from equation \\ref{eq:proof}, $G(\\mathbf{a},\\mathbf{a}) = F(\\mathbf{a})$. Writing out\n\\begin{equation}\nF(\\mathbf{a}) = F(\\mathbf{a}^t) + (\\mathbf{a}-\\mathbf{a}^t)^T \\nabla F(\\mathbf{a}^t)+\\frac{1}{2}(\\mathbf{a}-\\mathbf{a}^t)^T(\\mathbf{B}^T\\mathbf{B})(\\mathbf{a}-\\mathbf{a}^t),\n\\end{equation}\nwe see that the second property, $G(\\mathbf{a},\\mathbf{a}') \\geq F(\\mathbf{a}),$ is satisfied if\n\\begin{equation}\n0 \\leq (\\mathbf{a}-\\mathbf{a}^t)^T[\\mathbf{K}(\\mathbf{a}^t) - \\mathbf{B}^T\\mathbf{B}](\\mathbf{a}-\\mathbf{a}^t).\n\\end{equation}\nHoyer proved this positive semidefiniteness for the case of $\\lambda \\geq 0$ \\cite{hoyer}. He concludes that as a non-negative diagonal matrix is positive semidefinite, and the sum of two positive semidefinite matrices is also positive semidefinite, the proof for $\\lambda = 0$, in his paper also holds for $\\lambda \\geq 0$.\nIt remains to be shown that the update rule in equation \\ref{eq:update} selects the minimum of $G$. This minimum is easily found by taking the gradient and equating it to zero:\n\\begin{equation}\n\\nabla_\\mathbf{a} G(\\mathbf{a},\\mathbf{a}) = \\mathbf{B}^T(\\mathbf{B}\\mathbf{a}^t-\\mathbf{x}) + \\lambda\\mathbf{c} + \\mathbf{K}(\\mathbf{s}^t)(\\mathbf{a}-\\mathbf{a}^t)=0,\n\\end{equation}\nwhere $\\mathbf{c}$ is a vector with all ones. Solving for $\\mathbf{a}$, this gives\n\\begin{align}\n\\mathbf{a} & = \\mathbf{a}^t - \\mathbf{K}^{-1}(\\mathbf{a}^t)(\\mathbf{B}^t\\mathbf{B}\\mathbf{a}^t-\\mathbf{B}^T\\mathbf{x}+\\lambda \\mathbf{c}) \\\\\n& = \\mathbf{a}^t-(\\mathbf{a}^t./(\\mathbf{B}^T\\mathbf{B}\\mathbf{a}^t+\\lambda\\mathbf{c})).* (\\mathbf{B}^T\\mathbf{B}\\mathbf{a}^t - \\mathbf{B}^T\\mathbf{x}+\\lambda \\mathbf{c}) \\\\\n& = \\mathbf{a}^t.\\times (\\mathbf{B}^T\\mathbf{x}./(\\mathbf{B}^T\\mathbf{B}\\mathbf{a}^t+\\lambda\\mathbf{c}))\n\\end{align}\nwhich is the desired update rule \\ref{eq:update}.\n\\label{proof:noninc}\n\\end{proof2}\n\n\n%\\subsubsection{Tranformation Algorithms and variations for sparse approximation}\n%%\n%\\label{sec:regularization}\n%\\subsubsection{Ridge Regression}\n%\n%A famous method of regularization called Tikhonov regularization, in statistics this method is known as ridge regression, an algorithm for non-linear least-squares problems. When x is non-existent, we call it an ill-posed problem such as below\n%\n%\\begin{equation}\n%A\\mathbf{x}=\\mathbf{b},\n%\\end{equation}\n%\n%a standard approach to the problem is ordinary least squares, which often leads to an underdetermined system of equations. Real-world problems often operate as a low-pass filter, meaning that the direction of the mapping where $A$ maps $\\mathbf{x}$ to $\\mathbf{b}$. By the inverse-mapping, we operate as a high-pass filter, which is often the case in mathematical formulations, it has an undesirable tendency of amplifying noise. \\cite{ill-posed} Ordinary least squares (OLS) nullifies every element of the reconstructed elements of $\\mathbf{x}$, that is in the null-space of $A$. The ridge regression uses the $l_2$-norm as a means of regression to the residuals and can be mathematically written as the following formulation\n%\\begin{equation}\n%\\label{eq:ridge}\n%\\beta^{ridge} = \\arg \\! \\operatorname*{\\min}_\\beta \\sum_{i=1}^n (\\mathbf{y}_i - ( \\beta_0 + \\beta^T \\mathbf{x}_i))^2 + \\lambda \\norm{\\beta}^2_2\n%\\end{equation}\n%There are other techniques which are based on the assumption that the $l_2$-norm does not capture the features to the respective dimensions and therefore \"LASSO\" has been used as a means of using the $l_1$-norm instead.\n%\n%\\subsubsection{LASSO}\n%\n%\"LASSO\" In the context of regression and statistics, is fittingly being used as a metaphor of $L_1$ constraint applied to linear model. Coincidently, LASSO is also the initials for Least Absolute Shrinkage and Selection Operator. LASSO minimizes the residual sum of squares subject to the sum of the absolute value of the coefficients being less than a constant. LASSO not only helps to improve the prediction accuracy when dealing with multicolinearity data, but also carries several nice properties such as interpretability and numerical stability. Because of the nature of this constraint it tends to produce some coefficients that are exactly 0 and hence gives interpretable models \\cite{lasso}. In a Bayesian context, this is equivalent to placing a zero-mean Laplace prior distribution on the parameter vector \\cite{bayes_lasso}. The optimization problem may be solved using quadratic programming or more general convex optimization methods. The formulation of LASSO regression can mathematically be written as\n%\n%\\begin{equation}\n%\\label{eq:lasso}\n%\\beta^{lasso} = \\arg \\! \\operatorname*{\\min}_\\beta \\sum_{i=1}^n (\\mathbf{y}_i - ( \\beta_0 + \\beta^T \\mathbf{x}_i))^2 + \\lambda \\norm{\\beta}_1\n%\\end{equation}\n%\n%The difference between LASSO and ridge regression is that the penalty is increased and all parameters remain non-zero while still being reduced, using ridge regression. While increasing the penalty using LASSO will cause more and more of the parameters to be driven to zero. This makes LASSO an advantage for practical and model evaluation reasoning as we have to deal with less parameters to the model. As a result, LASSO selects more relevant features and discards the others, whereas ridge regression never fully discards any features. \\cite{bayes_lasso}\n%\n%\\subsubsection{Gradient Descent}\n%\n%The gradient descent method gives a way to find a local minimum of a given general function. We initialize the algorithm by a guess to the solution and compute the gradient for the function at the initial point. Next, we start the process of stepping through the negative direction of the gradient and repeat the process until the algorithm has converged at which the gradient is zero or until we reach a point at which we believe that there is no local minimum. The algorithm is called a first-order algorithm as it only takes the first derivative of the function into account.\n%\n%Here we will walk through the process of a gradient descent algorithm for finding the solution to the minimum of some function $f(x)$. Initializing with some initial value $x_0$ for $x$, we can change its value proportional to the dimension of x: with only one dimension; we can make it higher or lower. The best direction at $x_0$ to minimize $f$, we take the gradient $\\nabla f$ along every dimension of $x$. Intuitively, the gradient will give the curve at that which $x$ will point to an increase in the function. Therefore we change $x$ in the opposite direction to lower the function value:\n%\\begin{equation}\n%x_{k+1} = x_k - \\lambda \\nabla f(x_k)\n%\\end{equation}\n%where $\\lambda$ represents the stepsize in the discretization of the function we represent. This can be a fixed value or change depending on which implementation one decides to chose. Often $\\lambda>0$ is a small number that forces the algorithm to make small jumps, even for the most minimal $\\lambda$ it has been shown to converge to a minimum. As a result, the algorithm will be stable and its optimal value depends on the function, given stable conditions (and a certain choice of $\\lambda$), it is guaranteed that $f(x_{k+1}) \\leq f(x_k)$ \\cite{gradient}.\n%\n%\\subsubsection{Coordinate Descent}\n%\n%Instead of relying on the gradient of a function, one approach called the coordinate descent can minimize a function by minimizing it along one direction at a time. By the given regression model we can minimize the function $f(x)$.\n%\\begin{equation}\n%y = X \\theta,\n%\\end{equation}\n% the function to minimise for a least squares regression is \n% \\begin{equation}\n% f(\\theta) = | y- X \\theta |^2.\n% \\end{equation}\n% Minimising over $\\theta$ is achieved by \n% \\begin{equation}\n% 0 = X_{i}^\\top (X \\theta - y) = X_{i}^\\top (X_i \\theta_i + X_{-i} \\theta_{-i} -y).\n% \\end{equation}\n% So the next step in the coordinate descent update is\n% \\begin{equation}\n% \\theta_{i} = \\frac{X_{i}^\\top(y- X_{-i}\\theta_{-i})}{X_{i}^\\top X_{i}}.\n% \\end{equation}\n%Regardless the learning rate of the gradient descent procedure (which could indeed speed up convergence), the comparison between the two is fair at least in terms of complexity.\n%Coordinate descent needs to perform $O(n)$ operations for each coordinate update (n operations to compute residuals $r = (y- X_{-i}\\theta_{-i})$ and n to compute $X_{i}^\\top r$ . Each cycle of this type is performed p times, where p is the number of covariates.\n%Gradient descent performs the same number of operations $O(np)$.\n%\n", "meta": {"hexsha": "a45ae4ce9aff9f05d96faae5d8f3f6f59378eded", "size": 43176, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/thesis/preliminaries.tex", "max_stars_repo_name": "ghw329/DDSC", "max_stars_repo_head_hexsha": "97262b7fe0f507a7860828060e43ae2e0c1f1495", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/thesis/preliminaries.tex", "max_issues_repo_name": "ghw329/DDSC", "max_issues_repo_head_hexsha": "97262b7fe0f507a7860828060e43ae2e0c1f1495", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/thesis/preliminaries.tex", "max_forks_repo_name": "ghw329/DDSC", "max_forks_repo_head_hexsha": "97262b7fe0f507a7860828060e43ae2e0c1f1495", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 101.3521126761, "max_line_length": 1136, "alphanum_fraction": 0.7673939225, "num_tokens": 11127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972549785203, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.7097391713073362}}
{"text": "%%%lecture 10\n\n\\begin{beispiel}\n\t$E = L^2([0,1])$ and $f,g \\in E$ with\n\t\\[\n\t\t\\skal{f}{g}_{L^2} = \\int_{0}^{1} f(x) \\overline{g(x)} \\,\\mathrm{d}x, \\qquad \\norm{f}_{L^2} = \\left( \\int_{0}^{1} \\abs{f(x)}^2 \\,\\mathrm{d}x \\right)^{\\frac{1}{2}}.\n\t\\]\n\tSet $h \\in C([0,1] \\times [0,1])$ and for $f \\in L^2([0,1])$\n\t\\[\n\t\tA(f)(x) = \\int_{0}^{1} h(x,y)f(y) \\,\\mathrm{d}y, \\qquad x \\in [0,1].\n\t\\]\n\tThen\n\t\\[\n\t\t\\norm{A} \\leq \\left( \\int_{0}^{1} \\left( \\int_{0}^{1} \\abs{h(x,y)}^2 \\,\\mathrm{d}y \\right) \\,\\mathrm{d}x \\right)^{\\frac{1}{2}} < \\infty.\n\t\\]\n\\end{beispiel}\n\\begin{beispiel}\n\tLet $(E, \\norm{.})$ be a normed space. Then there are no $A,B \\in B(E,E)$ such that\n\t\\[\n\t\tAB - BA = I\n\t\\]\n\twhere $I$ is the identity ($I(x)=x$ for $x \\in E$).\n\t\\begin{bemerkung}\n\t\tConsider $ f \\in E = C^{\\infty}([0,1])$ and \n\t\t\\[\n\t\t\tA = \\diffd{}{x}, \\qquad B=x.\n\t\t\\]Then\n\t\t\\[\n\t\t\t(AB - BA)(f)(x) = \\diffd{}{x}(x(f(x))) - x \\diffd{}{x}f(x) = f(x).\n\t\t\\]\n\t\\end{bemerkung}\n\tArgue by contradiction. \\\\\n\tAssume $A,B \\in B(E,E)$ with $AB-BA = I$. \\\\\n\tHint: Consider $A^nB-BA^n$ for $n = 1,2,\\dots$. For $n =2$ we have\n\t\\begin{align*}\n\t\tA^2B-BA^2 &= A^2B-ABA + ABA - BA^2 \\\\\n\t\t&= A(AB-BA) + (AB-BA)A \\\\\n\t\t&= 2A.\n\t\\end{align*}\n\tFor $n=3$ we have\n\t\\begin{align*}\n\t\tA^3B-BA^3 &= A^3B-A^2BA + A^2BA - BA^3 \\\\\n\t\t&=A^2(AB-BA) + (A^2B-BA^2)A \\\\\n\t\t&= 3A^2.\n\t\\end{align*}\n\tIn general \n\t\\[\n\t\tA^nB-BA^n = nA^{n-1}, \\qquad n=2,3,4,\\dots \\qquad (*)\n\t\\]\n\tCheck using an induction argument. We obtain\n\t\\[\n\t\tn \\norm{A^{n-1}} = \\norm{A^nB-BA^n} \\leq \\norm{A^nB} + \\norm{BA^n} \\leq  2 \\norm{A^{n-1}} \\norm{A} \\norm{B}\n\t\\]\n\tHence \\[\n\t\t(2 \\norm{A} \\norm{B} -n) \\norm{A^{n-1}} \\geq 0, \\qquad  \\forall\\,  n = 2,3,\\dots.\n\t\\]\n\tWe conclude that $\\norm{A^{n-1}}= 0$ for $n$ large enough. Clearly the same for $\\norm{A^n}$. This yields $A^n=0$ for $n$ large enough. Repeated use of $(*)$ gives $A=0$. This contradicts $AB-BA= I$ so the implication in the example is proven.\n\\end{beispiel}\n\nRecall a important theorem:\n\n\\begin{theorem}[Riesz representation theorem]\n\t$(E, \\skal{.}{.})$ Hilbert space $f \\in B(E,\\mathbb{C})$. $f$ is bounded linear functional on $E$. This yields\n\t\\[\n\t\t\\exists\\,! x_f \\in E: \\qquad f(x) = \\skal{x}{x_f}, \\qquad \\forall\\, x \\in E.\n\t\\]\n\tAlso it holds\n\t\\[\n\t\t\\underset{\\substack{\\text{operator norm} \\\\ \\text{of $f$}}}{\\underbrace{\\norm{f}}} = \\underset{\\substack{norm of} \\\\ \\text{$x_f$ in $E$}}{\\underbrace{\\norm{x_f}}}.\n\t\\]\n\\end{theorem}\n\n\\begin{definition}\n\t$\\varphi: E \\times E \\to \\mathbb{C}$ is called:\n\t\\begin{itemize}\n\t\t\\item Bilinear, if for scalars $\\alpha$ and $\\beta$ it holds\n\t\t\\begin{align*}\n\t\t\t\\varphi( \\alpha x+ \\beta y,z) &= \\alpha \\varphi(x,z)+ \\beta \\varphi(y,z) \\qquad \\forall\\, x,y,z \\in E \\\\\n\t\t\t\\varphi(x,\\alpha y + \\beta z) &= \\bar{\\alpha} \\varphi(x,z) + \\overline{\\beta} \\varphi(y,z) \\qquad \\forall\\, x,y,z \\in E.\n\t\t\\end{align*}\n\t\t\\item Bounded, if there exists $M>0$ such that\n\t\t\\[\n\t\t\t\\abs{\\varphi(x,y)} \\leq M \\norm{x}\\norm{y}, \\qquad \\forall\\, x,y \\in E.\n\t\t\\]\n\t\t\\item Coercive, if there exists $K>0$ such that\n\t\t\\[\n\t\t\t\\varphi(x,x) \\geq K \\norm{x}^2, \\qquad \\forall\\, x \\in E.\n\t\t\\]\n\t\\end{itemize}\n\\end{definition}\nClearly $\\skal{.}{.}$ in $E$ is a bilinear, bounded and coercive functional in $E$ (with $M=K=1$). \\\\\nWe will now introduce a Generalization of the Riesz representation theorem.\n\n\\begin{theorem}[Lax-Milgram]\n\t$(E, \\skal{.}{.})$ Hilbert space. Let $\\varphi: E \\times E \\to \\mathbb{C}$ be a bilinear, bounded and coercive functional. $f: E \\to \\mathbb{C}$ bounded linear functional in $E$. Then there exists an unique $x_f \\in E$ such that\n\t\\[\n\t\tf(x) = \\varphi(x,x_f), \\qquad  \\forall\\, x \\in E.\n\t\\]\n\\end{theorem}\n\n\\begin{beweis}\n\t\\begin{enumerate}[Step 1:]\n\t\t\\item $\\exists\\,!$ $A \\in B(E,E)$ with\n\t\t\\[\n\t\t\t\\varphi(x,y)= \\skal{x}{A(y)}, \\qquad \\forall\\, x,y \\in E.\n\t\t\\]\n\t\t\\item $A$ is injective and surjective.\n\t\t\\item Apply RRT with $ \\tilde x_f = A^{-1}(x_f)$\n\t\t\\begin{align*}\n\t\t\tf(x) &= \\skal{x}{x_f} \\\\ &= \\skal{x}{A(A^{-1}(x_f))} \\\\ &= \\varphi(x, \\tilde x_f), \\qquad \\forall\\, x \\in E.\n\t\t\\end{align*}\n\t\\end{enumerate}\n\t\\begin{description}\n\t\t\\item[Step 1:] Fix $y \\in E$ and consider for $x \\in E$\n\t\t\\[\n\t\t\tx \\stackrel{f_y}{\\mapsto } \\varphi(x,y) \\in \\mathbb{C}.\n\t\t\\] \n\t\t\\textbf{Claim:} \\text{    }$f_y: E \\to \\mathbb{C}$ is a bounded linear functional. \\\\\n\t\tFor $x,y,z \\in E$ and $\\alpha,\\beta$ scalars we have\n\t\t\\begin{align*}\n\t\t\tf_y(\\alpha x+ \\beta z) &= \\varphi(\\alpha x + \\beta z,y) \\\\\n\t\t\t&= \\alpha \\varphi(x,y) + \\beta \\varphi(z,y) \\\\\n\t\t\t&= \\alpha f_y(x) + \\beta f_y(z).\n\t\t\\end{align*}\n\t\tHence $f_y$ is linear. It is bounded because of\n\t\t\\[\n\t\t\t\\abs{f_y(x)} = \\abs{\\varphi(x,y)} \\leq (M \\norm{y})\\norm{x}, \\qquad \\forall\\, x \\in E.\n\t\t\\]\n\t\tSo $f_y$ is bounded. \\\\\n\t\tRRT implies $f_y(x) = \\skal{x}{A(y)}$ for all $x \\in E$ for some $A(y) \\in E$. \\\\ Now we have $A : E \\to E$.\n\t\t\\textbf{Claim:} \\text{    }$A \\in B(E,E)$. \\\\\n\t\tFor $x,y,z \\in E$ and scalars $\\alpha, \\beta$ we have\n\t\t\\begin{align*}\n\t\t\t\\skal{x}{A( \\alpha y + \\beta z)} &= \\varphi(x, \\alpha y + \\beta z) \\\\\n\t\t\t&= \\bar{\\alpha} \\varphi(x,y)+ \\bar{\\beta} \\varphi(x,z) \\\\\n\t\t\t&= \\bar{\\alpha} \\skal{x}{A(y)} + \\bar{\\beta} \\skal{x}{A(z)} \\\\\n\t\t\t&= \\skal{x}{\\alpha A(y)}+ \\skal{x}{\\beta A(z)}. \\\\\n\t\t\\end{align*}\n\t\tThis is equivalent to\n\t\t\\[\n\t\t\t\\skal{x}{A(\\alpha y + \\beta z)- \\alpha A(y) - \\beta A(z)} = 0, \\qquad  x \\in E.\n\t\t\\]\n\t\tThis implies \n\t\t\\[\n\t\t\t\\norm{A(\\alpha y + \\beta z) - \\alpha A(y) - \\beta A(z)} = 0.\n\t\t\\]\n\t\tSo \\[\n\t\t\tA( \\alpha y+ \\beta z) = \\alpha A(y) + \\beta A(z) \\qquad \\forall\\, y,z \\in E \\text{ and scalars }\\beta,\\alpha.\n\t\t\\]\n\t\tHence, $A$ is linear. We will now show that $A$ is bounded: \\\\\n\t\tWe know because $\\varphi$ is continuous that for all $x,y \\in E$\n\t\t\\[\n\t\t\t\\abs{\\skal{x}{A(y)}} = \\abs{\\varphi(x,y)} \\leq M \\norm{x} \\norm{y}.\n\t\t\\]\n\t\tTake $x = A(y)$ and get\n\t\t\\[\n\t\t\t\\norm{A(y)}^2 \\leq  M \\norm{A(y)} \\norm{y} \\qquad \\forall\\, y \\in E\n\t\t\\]\n\t\twhich implies\n\t\t\\[\n\t\t\t\\norm{A(y)} \\leq M \\norm{y} \\qquad \\forall\\, y \\in E.\n\t\t\\]\n\t\tHence $\\norm{A} \\leq M < \\infty$.\n\t\t\\item[Step 2:] Note $\\varphi(x,y) = \\skal{x}{A(y)}$ for alle $x,y \\in E$. \\\\\n\t\t\\textbf{Claim:} \\text{    }$A$ is injective, i.e.\n\t\t\\[\n\t\t\tA(x_1) = A(x_2) \\qquad \\Rightarrow \\qquad x_1 = x_2.\n \t\t\\]\n\t\t$\\varphi$ is coercive so\n\t\t\\[\n\t\t\t\\norm{x}^2 \\leq \\frac{\\varphi(x,x)}{K} = \\frac{1}{K} \\underset{>0}{\\underbrace{\\abs{\\skal{x}{A(x)}}}} \\leq \\frac{1}{K} \\norm{x} \\norm{A(x)} \\qquad \\forall\\,  x \\in E.\n\t\t\\]\n\t\tHence \\[\n\t\t\t\\norm{x} \\leq  \\frac{1}{K} \\norm{A(x)}, \\qquad \\forall\\, x \\in E.\n\t\t\\]\n\t\tIf $A(x_1) = A(x_2)$ we have $A(x_1-x_2) = 0 \\in E$ then\n\t\t\\[\n\t\t\t\\norm{x_1 - x_2} \\leq \\frac{1}{K} \\norm{A(x_1 -x_2)} = 0.\n\t\t\\]\n\t\tWe get $x_1 = x_2$. \\\\\n\t\t\\textbf{Claim:} \\text{    }$A$ is surjective, i.e. the image of $A$ is $E$: \\[\n\t\t\t\\mathcal{R}(A) = \\set[A(x)]{x \\in E} = E.\n\t\t\\] \n\t\tWe first show that $\\mathcal{R}(A)$ is a closed subspace of $E$. \n\t\t\\begin{itemize}\n\t\t\t\\item $\\mathcal{R}(A)$ is a subspace in $E$ since $A$ is linear.\n\t\t\t\\item $\\mathcal{R}(A)$ is closed \n\t\t\t\\[\n\t\t\t\ty_n \\to y \\qquad \\text{in }(E, \\norm{.}) \\qquad \\Rightarrow y \\in \\mathcal{R}(A).\n\t\t\t\\]\t\t\t\n\t\t\\end{itemize}\n\t\t$\\mathcal{R}(A)$ is linear. Take $y_1,y_2 \\in \\mathcal{R}(A)$ with preimages $x_1,x_2$ and yield\n\t\t\\[\n\t\t\t\\alpha_1 y_1 + \\alpha_2 y_2 = \\alpha_1 A(x_1) + \\alpha_2 A(x_2) = A(\\alpha_1 x_1 + \\alpha_2 x_2).\n\t\t\\]\n\t\tSo \\[\n\t\t\t\\alpha_1 y_1 + \\alpha_2 y_2 \\in \\mathcal{R}(A).\n\t\t\\]\n\t\tAssume \\[\n\t\t\ty_n \\to y \\qquad \\text{in }(E, \\norm{.}).\n\t\t\\]\n\t\tFor $n=1,2,\\dots$ there are $x_1,x_2,\\dots$ such that $y_n= A(x_n)$ for $n=1,2,\\dots$. \\\\\n\t\t\\textbf{Claim:} \\text{    }$(x_n)_{n \\in \\mathbb{N}}$ is a Cauchy sequence in $E$ since\n\t\t\\begin{align*}\n\t\t\t\\norm{x_n-x_m} &\\leq \\frac{1}{K} \\norm{A(x_n-x_m)} \\\\\n\t\t\t&= \\frac{1}{K} \\norm{A(x_n)- A(x_m)} \\\\\n\t\t\t&= \\frac{1}{K} \\norm{y_n -y_m} \\to 0, \\qquad n,m \\to \\infty\n\t\t\\end{align*}\n\t\tsince $(y_n)_{n \\in \\mathbb{N}}$ converges. \\\\\n\t\tSince $(E, \\norm{.})$ is a Banach space $(x_n)_{n \\in \\mathbb{N}}$ converges in $(E, \\norm{.})$. Call the limit $x \\in E$. Hence\n\t\t\\[\n\t\t\tA(x_n) \\to y\n\t\t\\]\n\t\tsince $A$ is bounded, continuos and linear. So $y = A(x)$ and we get $y \\in \\mathcal{R}(A)$. \\\\\n\t\tSecondly $A$ is surjective, i.e. $\\mathcal{R}(A)=E$. \\\\\n\t\tAssume that this is not true. The Orthogonal decomposition theorem gives\n\t\t\\[\n\t\t\tE = \\mathcal{R}(A) \\oplus \\mathcal{R}(A)^{\\perp}.\n\t\t\\]\n\t\tThe first one is a closed subspace in $E$ and the second one is not empty by assumption. Fix $z \\in \\mathcal{R}(A)^{\\perp} \\setminus \\set{0}$. Note \n\t\t\\[\n\t\t\t\\varphi(x,y) = \\skal{x}{A(y)} \\qquad x,y \\in E\n\t\t\\]\n\t\tWith $x = y = z$ we get\n\t\t\\[\n\t\t\t\\varphi(z,z) = \\skal{z}{A(z)} = 0\n\t\t\\]\n\t\tand \n\t\t\\[\n\t\t\t\\varphi(z,z) \\geq K \\norm{z}^2 \\geq 0 \\qquad \\Rightarrow  \\,z=0.\n\t\t\\]\n\t\tThis is a contradiction. \\\\\n\t\tThe Conclusion is \n\t\t\\[\n\t\t\t\\mathcal{R}(A)^{\\perp} = \\set{0} \\qquad \\Rightarrow \\qquad \\mathcal{R}(A) = E.\n\t\t\\]\n\t\tWe have $\\varphi(x,y) = \\skal{x}{A(y)}$ for all $x,y \\in E$ and $A \\in B(E,E)$ surjective.\n\t\t\\item[Step 3:] see above.\n\t\\end{description}\n\\end{beweis}\n\n\\subsection{Adjoint operator} \n\\label{sub:adjoint_operator}\n\n$(E,\\skal{.}{.})$ Hilbert space and $A \\in B(E,E)$ with adjoint $A^{*}$, i.e.\n\\[\n\t\\skal{A(x)}{y} = \\skal{x}{A^*(y)} , \\qquad \\forall\\, x,y \\in E.\n\\]\nFix $y \\in E$ and consider\n\\[\n\tx \\stackrel{f_y}{\\mapsto } \\skal{A(x)}{y} \\in \\mathbb{C}. \n\\]\n\\textbf{Claim:} \\text{    }$f_y$ is a bounded linear functional on $E$\n\\begin{itemize}\n\t\\item linear since $A$ is linear.\n\t\\item bounded since $A$ is bounded with\n\t\\[\n\t\t\\abs{f_y(x)} \\leq (\\norm{A}\\norm{y})\\norm{x}, \\qquad x \\in E.\n\t\\]\n\\end{itemize}\n\tRRT implies\n\t\\[\n\t\tf_y(x) = \\skal{x}{A^*(y)}, \\qquad x \\in E.\n\t\\]\n\tWe have $A^*: E \\to E$ such that\n\t\\[\n\t\t\\skal{A(x)}{y} = \\skal{x}{A^*(y)} , \\qquad \\forall\\, x,y \\in E.\n\t\\]\n\\begin{proposition}\n\t$A \\in B(E,E)$. Then $A^* \\in B(E,E) $ and $\\norm{A^*} = \\norm{A}$.\n\\end{proposition}\n\\begin{beweis}\n\t$A^*$ linear:\n\t\\[\n\t\t\\skal{x}{A^* ( \\alpha y + \\beta z)} = \\skal{x}{\\alpha A^*(y) + \\beta A^*(z)} \\qquad \\forall\\, x,y \\in E.\n\t\\]\n\t$A^*$ bounded: \\\\ Take $x= A^*(y)$ and get\n\t\\begin{align*}\n\t\t\\norm{A^*(y)}^2 &= \\abs{\\skal{A(A^*(y))}{y}} \\\\\n\t\t&\\leq \\norm{A(A^*(y))} \\norm{y} \\\\\n\t\t&\\leq \\norm{A} \\norm{A^*(y)} \\norm{y}, \\qquad y \\in E.\n\t\\end{align*}\n\tWe get\n\t\\[\n\t\t\\norm{A^*(y)} \\leq \\norm{A} \\norm{y}, \\qquad y \\in E.\n\t\\]\n\tConclucion: $A^* \\in B(E,E)$. We also get \n\t\\[\n\t\t\\norm{A^*} \\leq \\norm{A}.\n\t\\]\n\tBut we also know that $A^{**} = A$ since\n\t\\begin{align*}\n\t\t\\skal{x}{A^{**}(y)} &= \\skal{A^*(x)}{y} \\\\\n\t\t&= \\overline{\\skal{y}{A^*(x)}} \\\\\n\t\t&= \\overline{\\skal{A(y)}{x}} \\\\\n\t\t&= \\skal{x}{A(y)}, \\qquad x,y \\in E.\n\t\\end{align*}\n\tSo \\[\n\t\t\\norm{A} = \\norm{A^{**}} \\leq \\norm{A^*}\n\t\\]\n\twhich impllies\n\t\\[\n\t\t\\norm{A} = \\norm{A^*}.\n\t\\]\n\\end{beweis}\n\\begin{bemerkung}\n\t$A,B \\in B(E,E)$ then\n\t\\begin{align*}\n\t\t(A+B)^* &= A^* + B^* \\\\\n\t\t(AB)^* &= B^* A^* \\\\\n\t\t(\\alpha A)^* &= \\bar{\\alpha}A^* \\\\\n\t\tA^{**} &= A \\\\\n\t\tI^* &= I.\n\t\\end{align*}\n\\end{bemerkung}\n\\begin{beispiel}\n\tContinuity of the example above: For $f \\in L^2([0,1])$ consider\n\t\\[\n\t\tA(f)(x) = \\int_{0}^{1}h(x,y)f(y) \\,\\mathrm{d}y, \\qquad x \\in [0,1].\n\t\\]\n\tFor $g \\in L^2([0,1])$ it holds\n\t\\begin{align*}\n\t\t\\skal{A(f)}{g}_{L^2} &= \\int_{0}^{1} A(f)(x)\\overline{g(x)} \\,\\mathrm{d}x \\\\\n\t\t&= \\int_{0}^{1}\\int_{0}^{1} h(x,y)f(y) \\,\\mathrm{d}x \\overline{g(x)} \\,\\mathrm{d}x \\\\\n\t\t&= \\int_{0}^{1}f(y) \\cdot \\int_{0}^{1}h(x,y) \\overline{g(x)} \\,\\mathrm{d}x \\,\\mathrm{d}y \\\\\n\t\t&= \\int_{0}^{1} f(y) \\cdot \\overline{\\int_{0}^{1} \\overline{h(x,y)} g(x) \\,\\mathrm{d}x} \\,\\mathrm{d}y \\\\\n\t\t&= \\skal{f}{A^*(g)}_{L^2}.\n\t\\end{align*}\n\tThis gives us \n\t\\[\n\t\tA^*(f)(x) = \\int_{0}^{1} \\overline{h(y,x)}f(y) \\,\\mathrm{d}y, \\qquad x \\in [0,1].\n\t\\]\n\\end{beispiel}\n\n\\begin{beispiel}\n\t$A \\in B(E,E)$. It follows\n\t\\[\n\t\t\\mathcal{R}(A)^{\\perp} = N(A^*) = \\set[x \\in E]{A^*(x) = 0}\n\t\\]\n\tsince $x \\in \\mathcal{R}(A)^{\\perp}$. It is equivalent that\n\t\\[\n\t\t\\skal{x}{A(y)} = 0, \\qquad \\forall\\, y \\in E\n\t\\] \n\t\\[\n\t\t\\Leftrightarrow \\qquad \\skal{A^*(x)}{y} = 0, \\qquad \\forall\\, y \\in E\n\t\\]\n\t\\[\n\t\t\\Rightarrow \\qquad A^*(x) = 0 \\qquad \\Leftrightarrow \\qquad x \\in N(A^*).\n\t\\]\n\tWe get\n\t\\[\n\t\tN(A^*)^{\\perp} = \\overline{\\mathcal{R}(A)}\n\t\\]\n\tsince\n\t\\[\n\t\tN(A^*)^{\\perp} = \\left( R(A)^{\\perp} \\right)^{\\perp} = \\overline{\\spn(\\mathcal{R}(A))} = \\overline{\\mathcal{R}(A)}.\n\t\\]\n\\end{beispiel}\n\\begin{bemerkung}\n\t$A \\in B(E,E)$ is called self adjoint if $A^* = A$.\n\\end{bemerkung}\nFor $A \\in B(E,E)$ we have\n\\[\n\t\\norm{A} =\\sup\\limits_{\\substack{\\norm{x} = 1  \\\\ \\norm{y}=1}} \\abs{\\skal{A(x)}{y}}\n\\]\nsince\n\\[\n\t\\norm{\\skal{A(x)}{y}} \\leq \\underset{\\leq \\norm{A}\\norm{x}}{\\underbrace{\\norm{A(x)}}} \\leq \\norm{A}, \\qquad \\text{for }\\norm{x}=\\norm{y}=1.\n\\]\nIf $A(x) = 0$ for all $x \\in E$ then $\\norm{A}=0$ and also\n\\[\n\t\\sup\\limits_{\\substack{\\norm{x} = 1  \\\\ \\norm{y}=1}} \\abs{\\skal{A(x)}{y}} = 0.\n\\]\nFor $x$ with $A(x) \\neq 0$ then it is\n\\[\n\tA \\left( \\frac{1}{\\norm{x}}x \\right) \\neq 0.\n\\]\nFor such an $x$ with $\\norm{x}=1$ we have\n\\[\n\t\\abs{\\skal{A(x)}{\\frac{1}{\\norm{A(x)}}A(x)}} = \\frac{1}{\\norm{A(x)}} \\norm{A(x)}^2 = \\norm{A(x)}\n\\]\nand\n\\[\n\t\\norm{A} \\leq \\sup_{\\norm{x}=1} \\norm{A(x)} \\leq \\sup\\limits_{\\substack{\\norm{x} = 1  \\\\ \\norm{y}=1}} \\abs{\\skal{A(x)}{y}} \\leq \\norm{A}.\n\\]\n\\begin{proposition}\n\tLet $A \\in B(E,E)$ be self-adjoint. Then\n\t\\[\n\t\t\\norm{A} = \\sup_{\\norm{x}=1} \\abs{\\skal{A(x)}{x}}.\n\t\\]\n\\end{proposition}\n\\begin{beweis}\n\tSet \n\t\\[\n\t\tM = \\sup_{\\norm{x}=1} \\abs{\\skal{A(x)}{x}}.\n\t\\]\n\tFor $\\norm{x}=1$ we have\n\t\\[\n\t\t\\abs{\\skal{A(x)}{x}} \\leq \\norm{A(x)} \\norm{x} \\leq \\norm{A}.\n\t\\]\n\tFurthermore\n\t\\[\n\t\tM \\leq \\norm{A}.\n\t\\]\n\tIt remains to prove: $\\norm{A} \\leq M$. \\\\\n\tFor $x,z \\in E$ consider:\n\t\\begin{align*}\n\t\t\\skal{A(x+z)}{x+z} - \\skal{A(x-z)}{x-z} &= 2 \\skal{A(x)}{z} + 2 \\skal{A(z)}{x} \\\\\n\t\t&= 2 \\left( \\skal{A(x)}{z} + \\skal{z}{A^*(x)} \\right) \\\\\n\t\t&= 2 (\\skal{A(x)}{z} + \\skal{z}{A(x)}) \\\\\n\t\t&= 4 \\re( \\skal{A(x)}{z}).\n\t\\end{align*}\n\tAssume now $A(x) \\neq 0$ and set\n\t\\[\n\t\tz = \\frac{1}{\\norm{A(x)}} A(x).\n\t\\]\n\tHence\n\t\\[\n\t\t\\norm{A(x)} = \\frac{1}{4} \\left( \\skal{A(x+\\frac{1}{\\norm{A(x)}} A(x))}{x + \\frac{1}{\\norm{A(x)}} A(x)} \n\t\t- \\skal{A(x-\\frac{1}{\\norm{A(x)}} A(x))}{x- \\frac{1}{\\norm{A(x)}} A(x)} \\right).\n\t\\]\n\tNote \\[\n\t\t\\abs{\\skal{A(y)}{y}} = \\norm{y}^2 \\abs{\\skal{A(\\frac{1}{\\norm{y}}y)}{ \\frac{1}{\\norm{y}}y}} \\leq M \\norm{y}^2.\n\t\\]\n\tWe now obtain\n\t\\begin{align*}\n\t\t\\norm{A(x)} &\\leq \\frac{1}{4} \\left( M \\norm{x+\\frac{1}{\\norm{A(x)}} A(x)}^2 + M \\norm{x - \\frac{1}{\\norm{A(x)}} A(x)}^2 \\right) \\\\\n\t\t&= \\frac{M}{4} 2 \\left( \\norm{x}^2 + \\norm{\\frac{1}{\\norm{A(x)}} A(x)}^2 \\right) \\\\\n\t\t&= \\frac{M}{2} (\\norm{x}^2 +1).\n\t\\end{align*}\n\tSo\n\t\\[\n\t\t\\norm{A} = \\sup_{\\norm{x}=1} \\norm{A(x)} \\leq M\n\t\\]\n\tand this yields\n\t\\[\n\t\t\\norm{A}= M.\n\t\\]\n\\end{beweis}", "meta": {"hexsha": "29ac25b98ee47f6b238fbb92b146352c4877db18", "size": 14529, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "AF/splits/lecture10.tex", "max_stars_repo_name": "TiKeil/LatexGU", "max_stars_repo_head_hexsha": "556ad083ea9478a99ea17e2c9b4bb22a964045ae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-01T03:52:33.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-01T03:52:33.000Z", "max_issues_repo_path": "AF/splits/lecture10.tex", "max_issues_repo_name": "TiKeil/LatexGU", "max_issues_repo_head_hexsha": "556ad083ea9478a99ea17e2c9b4bb22a964045ae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "AF/splits/lecture10.tex", "max_forks_repo_name": "TiKeil/LatexGU", "max_forks_repo_head_hexsha": "556ad083ea9478a99ea17e2c9b4bb22a964045ae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.0956719818, "max_line_length": 244, "alphanum_fraction": 0.5316264024, "num_tokens": 6932, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7097236507017055}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{parskip}% http://ctan.org/pkg/parskip\n%for degrees\n\\usepackage{gensymb}\n%for bmatrix\n\\usepackage{amsmath}\n% for Sarrus\n\\usepackage{tikz}\n\\usetikzlibrary{calc,matrix}\n\n\\begin{document} \n\n\\section{Algebra}\n\t\\subsection{Exponent Properties}\n\t\t\\begin{equation}\n\t\t\t\\frac{a^n}{a^m} = a^{n-m}\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\tx^a y^a = \\left( {xy} \\right)^a\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\tx^{\\left( {\\frac{a}{b}} \\right)} = \\sqrt[b]{{x^a }}\n\t\t\\end{equation}\n\t\\subsection{Properties of radicals}\n\t\t\\begin{equation}\n\t\t\t\\sqrt[n]{a} = a^{\\frac{1}{n}}\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\sqrt[n]{ab} = \\sqrt[n]{a}\\sqrt[n]{b}\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\sqrt[m]{\\sqrt[n]{a}} = \\sqrt[nm]{a}\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\sqrt[n]{\\frac{a}{b}} = \\frac{\\sqrt[n]{a}}{\\sqrt[n]{b}}\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\sqrt[n]{a^n} = |a|, \\ \\ \\mbox{if $n$ is even}\n\t\t\\end{equation}\n\t\\subsection{Complex numbers}\n\t\t\\begin{equation}\n\t\t\t(a+bi)(c+di) =  ac-bd+(ad+bc)i\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t(a+bi)(a-bi) =  a^2 + b^2\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t|a + bi| = \\sqrt{a^2+b^2} \\ \\ \\mbox{Complex Modulus}\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\overline{(a+bi)}=a-bi\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\tz_1 \\cdot z_2 = r_1 \\cdot r_2 e^{i(\\theta_1 + \\theta_2)}\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\tz^{\\frac{1}{n}} = \\sqrt[n] r \\cdot e^{i(\\frac{\\phi}{n} + \\frac{2k\\pi}{n})}; \\ \\ k = 0,1,..,n-1\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\te^{ni\\theta}=\\cos{n\\theta} + \\sin{n\\theta}  \\ \\ \\mbox{De Moivre’s Formula}\n\t\t\\end{equation}\n\t\\subsection{Logarithms}\t\n\t\t\\begin{equation}\n\t\t\t\\log _b b = 1\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\log _b 1 = 0\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\log _b (x^r) = r \\log _b x\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\log _b (xy) = \\log _b (x) + \\log _b (y)\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\log _b \\left( \\frac{x}{y} \\right) = \\log _b (x) - \\log _b (y)\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\log _b \\left( x \\right) = \\log _b \\left( c \\right)\\log _c \\left( x \\right) = \\frac{{\\log _c \\left( x \\right)}}{{\\log _c \\left( b \\right)}}\n\t\t\\end{equation}\n\t\\subsection{Quadratic Formula}\n\t\t\\begin{equation}\n\t\t\tx = \\frac{{ - b \\pm \\sqrt {b^2 - 4ac} }}{{2a}} \\ \\ \\mbox{when $ax^2 + bx + c = 0$}\n\t\t\\end{equation}\n\\section{Linear Algebra}\n\tMatrix addition: one by one. (commutative, associative)\n\t\n\tScalar multiplication: all. \n\n\tMatrix \"multiplication of rows into columns\". Multiplication is not commutative ($AB\\neq BA$).\n\t\n\t\\begin{equation}\n\t\tc_{jk} = \\sum_{i=1}^{n} a_{ji}b_{ik}\n\t\\end{equation}\n\t\n\tInner or dot product of Vectors\n\t\\begin{equation}\n\t\t\\langle a,b \\rangle = \\mathbf{a} \\bullet \\mathbf{b} = \\textbf{a}^T\\mathbf{b} \n\t\\end{equation}\n\n\tMatrix to the power $A^0=I$\n\n\tInverse: \n\t\\begin{equation}\n\t\t\\begin{bmatrix}\n\t\t\ta & b \\\\ c & d \\\\ \n\t\t\\end{bmatrix}^{-1} =\n\t\t\\frac{1}{\\det(\\mathbf{A})} \n\t\t\\begin{bmatrix}\n\t\t\t\\,\\,\\,d & \\!\\!-b \\\\ -c & \\,a \\\\ \n\t\t\\end{bmatrix} =\n\t\t\\frac{1}{ad - bc} \n\t\t\\begin{bmatrix}\n\t\t\t\\,\\,\\,d & \\!\\!-b \\\\ -c & \\,a \\\\ \n\t\t\\end{bmatrix}\n\t\\end{equation}\n\tIdentities\n\t\\begin{equation}\n\t\t(AB)^T = B^TA^T\n\t\\end{equation}\n\t\\begin{equation}\n\t\t(A+B)^T = A^T+B^T\n\t\\end{equation}\n\t\\begin{equation}\n\t\t(AB)^{-1} = B^{-1}+A^{-1}\n\t\\end{equation}\n\t\\begin{equation}\n\t\tA^kB^l = A^{k+l}\n\t\\end{equation}\n\tConjungate transpose / adjugate \n\t\\begin{equation}\n\t\tA^* = (\\overline{A})^\\mathrm{T} = \\overline{A^\\mathrm{T}}\n\t\\end{equation}\n\tDeterminants\n\t\t\\begin{equation}\n\t\t\t\\det(\\mathbf{A}) = \\sum_{\\sigma \\in S_n} \\mbox{sgn}(\\sigma) \\prod_{i=1}^n A_{i,\\sigma_i}\n\t\t\\end{equation}\n\t\tFor 3$\\times$3 matrices (Sarrus rule)\n\t\t\\begin{equation}\n\t\t\t\\begin{tikzpicture}[>=stealth]\n\t\t\t\\matrix [%\n\t\t\t  matrix of math nodes,\n\t\t\t  column sep=1em,\n\t\t\t  row sep=1em\n\t\t\t] (sarrus) {%\n\t\t\t  a_{11} & a_{12} & a_{13} & a_{11} & a_{12} \\\\\n\t\t\t  a_{21} & a_{22} & a_{23} & a_{21} & a_{22} \\\\\n\t\t\t  a_{31} & a_{32} & a_{33} & a_{31} & a_{32} \\\\\n\t\t\t};\n\n\t\t\t\\path ($(sarrus-1-1.north west)-(0.5em,0)$) edge ($(sarrus-3-1.south west)-(0.5em,0)$)\n\t\t\t\t  ($(sarrus-1-3.north east)+(0.5em,0)$) edge ($(sarrus-3-3.south east)+(0.5em,0)$)\n\t\t\t\t  (sarrus-1-1)                          edge            (sarrus-2-2)\n\t\t\t\t  (sarrus-2-2)                          edge[->]        (sarrus-3-3)\n\t\t\t\t  (sarrus-1-2)                          edge            (sarrus-2-3)\n\t\t\t\t  (sarrus-2-3)                          edge[->]        (sarrus-3-4)\n\t\t\t\t  (sarrus-1-3)                          edge            (sarrus-2-4)\n\t\t\t\t  (sarrus-2-4)                          edge[->]        (sarrus-3-5)\n\t\t\t\t  (sarrus-3-1)                          edge[dashed]    (sarrus-2-2)\n\t\t\t\t  (sarrus-2-2)                          edge[->,dashed] (sarrus-1-3)\n\t\t\t\t  (sarrus-3-2)                          edge[dashed]    (sarrus-2-3)\n\t\t\t\t  (sarrus-2-3)                          edge[->,dashed] (sarrus-1-4)\n\t\t\t\t  (sarrus-3-3)                          edge[dashed]    (sarrus-2-4)\n\t\t\t\t  (sarrus-2-4)                          edge[->,dashed] (sarrus-1-5);\n\n\t\t\t\\foreach \\c in {1,2,3} {\\node[anchor=south] at (sarrus-1-\\c.north) {$+$};};\n\t\t\t\\foreach \\c in {1,2,3} {\\node[anchor=north] at (sarrus-3-\\c.south) {$-$};};\n\t\t  \\end{tikzpicture}\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\det (A \\cdot B) = \\det (A) \\cdot \\det (B)\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\det (A^{-1}) = \\det (A)^{-1}\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\det\\left(rA\\right) = r^n\\det(A)\\ \\ \\ \\ \\mbox{for all $A^{n\\times n}$ and scalars $r$}\n\t\t\\end{equation}\n\t\t\n\t\tThe determinant of a triangular matrix equals the product of the diagonal entries. Since for any triangular matrix A the matrix ${\\displaystyle \\lambda I-A}$, whose determinant is the characteristic polynomial of A, is also triangular, the diagonal entries of A in fact give the multiset of eigenvalues of A (an eigenvalue with multiplicity m occurs exactly m times as diagonal entry)\n\t\t\n\t\t\\subsection{Transpose}\n\t\t\t\\begin{equation}\n\t\t\t\t[A^\\mathrm{T}]_{ij} = [A]_{ji}\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\t(A^T)^T = A\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\t(AB)^T = B^TA^T %validated..\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\tdet(A^T) = det(A)\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\t(A^T)^{-1} = (A^{-1})^T\n\t\t\t\\end{equation}\n\\section{Trigonometry}\n\t\\subsection{Definitions}\n\t\t\\begin{equation}\n\t\t\t\\sin \\theta = \\frac{{{\\rm{opposite}}}}{{{\\rm{hypotenuse}}}}\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\tan \\theta = \\frac{{{\\rm{opposite}}}}{{{\\rm{adjacent}}}}\n\t\t\\end{equation}\n\t\\bgroup\n\t\\def\\arraystretch{2}\n\t\t\\begin{table}[h]\n\t\t\\centering\n\t\t\\begin{tabular}{cccccc}\n\t\t\t\\hline\n\t\t\t\t$\\Theta$\t& $0\\degree$ & $30\\degree$ & $45\\degree$ & $60\\degree$ & $90\\degree$ \\\\  \n\t\t\t\t$sin \\Theta$\t& $0$ & $\\frac{1}{2}$ & $\\frac{1}{\\sqrt{2}}$ & $\\frac{\\sqrt{3}}{2}$ & 1\t\\\\  \n\t\t\t\t$cos \\Theta$\t& $1$ & $\\frac{\\sqrt{3}}{2}$ & $\\frac{1}{\\sqrt{2}}$ & $\\frac{1}{2}$\t& 0 \\\\  \n\t\t\t\t$tan \\Theta$\t& $0$ & $\\frac{1}{\\sqrt{3}}$ & $1$ & $\\sqrt{3}$\t& / \\\\  \n\t\t\t\\hline\n\t\t\\end{tabular}\n  \t\t\\caption{Trigonometric functions standard values}\n  \t\t\\label{tab:standard-values}\n\t\t\\end{table}\n\t\\egroup\n\t\\subsection{Formulas and Identities}\n\t\t\\begin{equation}\n\t\t\t\\tan \\theta = \\frac{\\sin \\theta}{\\cos \\theta}\n\t\t\\end{equation}\n\t\tPythagorean identities\n\t\t\\begin{equation}\n\t\t\t\\sin^2 \\theta + \\cos^2 \\theta = 1\n\t\t\\end{equation}\n\t\tOdd/Even formulas\n\t\t\\begin{equation}\n\t\t\t\\sin(-\\theta) = - \\sin \\theta \n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\cos(-\\theta) = \\cos \\theta \n\t\t\\end{equation}\n\t\tSum and difference formulas\n\t\t\\begin{equation}\n\t\t\t\\sin \\left( {\\alpha \\pm \\beta} \\right) = \\sin \\alpha \\cos \\beta \\pm \\cos \\alpha \\sin \\beta\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\cos \\left( {\\alpha \\pm \\beta } \\right) = \\cos \\alpha \\cos \\beta \\mp \\sin \\alpha \\sin \\beta\n\t\t\\end{equation}\n\t\tDouble angle formulas\n\t\t\\begin{equation}\n\t\t\t\\sin 2\\theta = 2\\sin \\theta \\cos \\theta\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\cos 2\\theta = \\cos ^2 \\theta - \\sin ^2 \\theta = 2\\cos ^2 \\theta - 1\n\t\t\\end{equation}\n\t\tHalf angle formulas\n\t\t\\begin{equation}\n\t\t\t\\tan \\frac{\\theta}{2} = \\pm \\sqrt{\\frac{1-cos(\\theta)}{1+cos(\\theta)}}\n\t\t\\end{equation}\n\t\tEuler's theorem\n\t\t\\begin{equation}\n\t\t\te^{ \\pm i\\theta } = \\cos \\theta \\pm i\\sin \\theta\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\cos \\theta = \\frac{1}{2} (e^{i\\theta} + e^{-i\\theta})\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\t\\sin \\theta = \\frac{1}{2i} (e^{i\\theta} - e^{-i\\theta})\n\t\t\\end{equation}\n\t\tMiscellaneous formulas\n\t\t\\begin{equation}\n\t\t\t\\sin ^2 \\theta = \\frac{1-cos(2\\theta)}{2}\n\t\t\\end{equation}\t\t\n\t\t\\begin{equation}\n\t\t\t\\cos ^2 \\theta = \\frac{1+sin(2\\theta)}{2}\n\t\t\\end{equation}\n\\section{Calculus111}\n\t\\subsection{Limits}\n\t\t\\subsubsection{Properties}\n\t\t\t\\begin{equation}\n\t\t\t\t\\mathop {\\lim }\\limits_{x \\to a} \\left[ cf(x) \\right] = c\\mathop{\\lim }\\limits_{x \\to a} f(x)\n\t\t\t\\end{equation}\n\t\t\tL'Hopital's Rule\n\t\t\t\\begin{equation}\n\t\t\t\t\\mathop {\\lim }\\limits_{x \\to c} \\frac{{f\\left( x \\right)}}{{g\\left( x \\right)}} = \\mathop {\\lim }\\limits_{x \\to c} \\frac{{f'\\left( x \\right)}}{{g'\\left( x \\right)}}\n\t\t\t\\end{equation}\n\t\t\\subsubsection{Evaluations}\n\t\t\t\\begin{equation}\n\t\t\t\t\\mathop {\\lim }\\limits_{x \\to 0} \\frac{{\\sin x}}{x} = 1\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\t\\mathop {\\lim }\\limits_{x \\to - \\infty } e^x = 0\n\t\t\t\\end{equation}\n\t\\subsection{Derivatives}\n\t\t\\subsubsection{Definition}\n\t\t\t\\begin{equation}\n\t\t\t\t\\frac{d}{{dx}}f\\left( x \\right) = \\mathop {\\lim }\\limits_{h \\to 0} \\frac{{f\\left( {x + h } \\right) - f\\left( x \\right)}}{h }\n\t\t\t\\end{equation}\n\t\t\\subsubsection{Properties}\n\t\t\tProduct rule\n\t\t\t\\begin{equation}\n\t\t\t\t\\left(fg\\right)'=f'g+fg'\n\t\t\t\\end{equation}\n\t\t\tChain rule\n\t\t\t\\begin{equation}\n\t\t\t\t\\frac{d}{{dx}}\\left[ {f\\left( u \\right)} \\right] = \\frac{d}{{du}}\\left[ {f\\left( u \\right)} \\right]\\frac{{du}}{{dx}} \\ \\ \\ \\mbox{or} \\ \\ \\ \\left(f(g(x)\\right)'=f'\\left(g(x)\\right)g'(x) \\ \\ \\ \\mbox{or} \\ \\ \\ (f\\circ g)' = (f'\\circ g) \\cdot g'\n\t\t\t\\end{equation}\n\t\t\tQuotient Rule\n\t\t\t\\begin{equation}\n\t\t\t\t\\left[\\frac{f(x)}{g(x)}\\right]'=\\frac{g(x)f'(x)-f(x)g'(x)}{[g(x)]^2}.\\\n\t\t\t\\end{equation}\n\t\t\\subsubsection{Common Derivatives}\n\t\t\t\\begin{equation}\n\t\t\t\t\\frac{d}{{dx}}\\left(a^x\\right)=a^x\\ln(a)\n\t\t\t\\end{equation}      \n\t\t\t\\begin{equation}\n\t\t\t\t\\frac{d}{{dx}}\\ln \\left( x \\right) = \\frac{1}{x}, \\ \\ \\ x > 0\n\t\t\t\\end{equation}\n\t\t\tPower rule\n\t\t\t\\begin{equation}\n\t\t\t\t\\frac{d}{{dx}}x^n = nx^{\\left( {n - 1} \\right)}\n\t       \\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\t\\frac{d}{{dx}}\\cos x = -\\sin x\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\t\\frac{d}{{dx}}\\sin x = \\cos x\n\t\t\t\\end{equation}\n\t\\subsection{Integrals}\n\t\t\\subsubsection{Fundamental Theorem of Calculus}\n\t\t\t\\begin{equation}\n\t\t\t\\int\\limits_a^b {\\frac{d}{{dx}}F\\left( x \\right)dx} = F\\left( b \\right) - F\\left( a \\right)\n\t\t\t\\end{equation}\n\t\t\\subsubsection{Properties}\n\t\t\t\\begin{equation}\n\t\t\t\t\\int_{}^{}k dx = kx + C\n\t\t\t\\end{equation}\n\t\t\\subsubsection{Common Integrals}\n\t\t\t\\begin{equation}\n\t\t\t\t\\int_{}^{}k dx = kx + C\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\t\\int_{}^{}x^n dx = \\frac{1}{n+1} x^{n+1} + C, \\ \\ \\ \\mbox{n $\\neq$ -1}\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\t\\int_{}^{}\\frac{1}{x} dx = \\ln|x| + C\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\t\\int_{}^{}\\ln u = u\\ln(u)-u+C\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\t\\int_{}^{}e^x dx = e^x+C\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\t\\int_{}^{}\\sin ax = -\\frac{1}{a}\\cos ax+C\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\t\\int_{}^{}\\cos x = \\sin x+C\n\t\t\t\\end{equation}\n\t\t\tPer partes\n\t\t\t\\begin{equation}\n\t\t\t\t\\int {u\\frac{{dv}}{{dx}}} dx = uv - \\int {\\frac{{du}}{{dx}}} vdx\n\t\t\t\\end{equation}\n\t\t\tSubstitution Rule\t\t\t\n\t\t\t\\begin{equation}\n\t\t\t\t\\int {f(u)\\frac{du}{dx}} dx = f(u)du\n\t\t\t\\end{equation}\n\t\t\t\n\t\\subsection{Laplace transforms}\n\t\t\\subsubsection{Definition}\n\t\t\t\\begin{equation}\n\t\t\t\tX(s) = \\int\\limits_0^\\infty {x(t)e^{ - st} dt}\n\t\t\t\\end{equation}\n\t\t\\subsubsection{Properties}\n\t\t\t\\begin{equation}\n\t\t\t\t1 \\Leftrightarrow \\frac{1}{{s}}\n\t\t\t\\end{equation}\n\t\t\tKroeneker delta function\n\t\t\t\\begin{equation}\n\t\t\t\t\\delta (t) \\Leftrightarrow 1\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\tKe^{ - at} u(t) \\Leftrightarrow \\frac{K}{{s + a}}\t\t\t\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\tt^n u(t) \\Leftrightarrow \\frac{{n!}}{{s^{n + 1} }}\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\t\\sin (\\alpha t)u(t) \\Leftrightarrow \\frac{\\alpha }{{(s^2 + \\alpha ^2 )}}\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\t\\cos (\\alpha t)u(t) \\Leftrightarrow \\frac{s}{{(s^2 + \\alpha ^2 )}}\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\te^{ - at} \\sin (\\Omega t)u(t) \\Leftrightarrow \\frac{\\Omega }{{(s + a)^2 + \\Omega ^2 }}\n\t\t\t\\end{equation}\n\t\t\t\\begin{equation}\n\t\t\t\te^{ - at} \\cos (\\Omega t)u(t) \\Leftrightarrow \\frac{{s + a}}{{(s + a)^2 + \\Omega ^2 }}\n\t\t\t\\end{equation}\n\n\t\t\t\\begin{equation}\n\t\t\t\te^{at} x(t) \\Leftrightarrow X(s-a)\n\t\t\t\\end{equation}\t\t\t\n\t\t\t\n\t\t\tTime domain scaling\n\t\t\t\\begin{equation}\n\t\t\t\tx(at)u(t) \\Leftrightarrow \\frac{1}{a}X\\left( {\\frac{s}{a}} \\right)\n\t\t\t\\end{equation}\n\t\t\tTime domain shifting \n\t\t\t\\begin{equation}\n\t\t\t\tx(t - a)u(t - a) \\Leftrightarrow e^{ - as} X(s + a)\n\t\t\t\\end{equation}\n\t\t\tDerivative\n\t\t\t\\begin{equation}\n\t\t\t\t\\frac{{d^n x(t)}}{{dt^n }} \\Leftrightarrow s^n X(s) \\ \\ or \\ \\ \\mathcal{L}[\\dot{x}] = sX(s)-x(0+)\n\t\t\t\\end{equation}\n\t\t\tIntegral\t\t\t\n\t\t\t\\begin{equation}\n\t\t\t\t\\int{x(t)dt} \\Leftrightarrow \\frac{X(s)}{s}\n\t\t\t\\end{equation}\t\t\t\n\t\t\t\n\t\t\tConvolution\n\t\t\t\\begin{equation}\n\t\t\t\\int\\limits_0^\\infty {x_1 (\\tau )x_2 (t - \\tau )d\\tau } \\Leftrightarrow X_1 (s)X_2 (s)\n\t\t\t\\end{equation}\n\\section{Greek letters}\n\n\\bgroup\n\\def\\arraystretch{2}\n\\begin{table}[hbp]\n  \\centering\n  \\begin{tabular}{cccc}\n  \\hline\n  \t$\\alpha A$\t\t\t\t& Alpha\t\t& $\\nu N$\t\t& Nu\t\\\\\n  \t$\\beta B$\t\t\t\t& Beta\t\t& $\\xi \\Xi$\t&  Xi \t\t\\\\\n  \t$\\gamma \\Gamma$\t\t\t& Gamma\t\t& $o O$\t& Omicron\t\t\\\\\n\t$\\delta \\Delta$\t\t\t& Delta \t& $\\pi \\Pi$\t& Pi\t\t\\\\\n\t$\\epsilon \\varepsilon $\t& Epsilon\t& $\\rho\\varrho P$ & Rho   \\\\\n\t$\\zeta Z$\t\t\t\t& Zeta\t\t& $\\sigma \\Sigma$& Sigma  \t\\\\\n\t$\\eta H$\t\t\t\t& Eta\t\t& $\\tau T$\t& Tau  \t\t\\\\  \n\t$\\theta \\vartheta \\Theta$\t& Theta & $\\upsilon \\Upsilon$ & Upsilon  \\\\\n\t$\\iota I$\t\t\t\t& Iota\t\t& $\\phi \\varphi \\Phi$ & Phi    \\\\\n\t$\\kappa K$\t\t\t\t& Kappa\t\t& $\\chi X$\t& Chi  \t\t\\\\\n\t$\\lambda \\Lambda$\t\t& Lambda\t& $\\psi \\Psi$\t& Psi  \t\\\\\n\t$\\mu M$\t\t\t\t\t& Mu \t\t& $\\omega \\Omega$ & Omega   \\\\\n  \n  \\hline\n  \\end{tabular}\n  \\caption{Greek letters}\n  \\label{tab:symbol-variants}\n\\end{table}\n\\egroup\n\n\n\\end{document}", "meta": {"hexsha": "3e6b56706ce4e51bb562ac3f8e00da08f462eaeb", "size": 14214, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calculus.tex", "max_stars_repo_name": "samo4/cheatsheet", "max_stars_repo_head_hexsha": "4ceb09276e7775d17f6f7137b1725b9364ddb43c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calculus.tex", "max_issues_repo_name": "samo4/cheatsheet", "max_issues_repo_head_hexsha": "4ceb09276e7775d17f6f7137b1725b9364ddb43c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calculus.tex", "max_forks_repo_name": "samo4/cheatsheet", "max_forks_repo_head_hexsha": "4ceb09276e7775d17f6f7137b1725b9364ddb43c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5166297118, "max_line_length": 386, "alphanum_fraction": 0.565076685, "num_tokens": 6074, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7097236496383413}}
{"text": "%\\input{../macros.tex}\n%\\begin{document}\n\\begin{answer}\n\t\n\\subsection*{Intro}\t\nWe seek to maximise $like(\\mu_0, \\mu_1, \\Sigma, \\phi) = p(x, y | \\mu_0, \\mu_1, \\Sigma, \\phi) = \\Pi p(y_i | \\phi) p(x_i | \\mu_0, \\mu_1, \\Sigma, y_i)$, using simple formula $p(x_i, y_i) = p(y_i)p(x_i | y_i)$, and that  $p(y|\\phi, \\mu_0, ...) = p(y | \\phi)$. Then we can separately maximise $\\Pi p(y_i | \\phi)$ and $\\Pi p(x_i | \\mu_0, \\mu_1, \\Sigma, y_i))$, denoting each (not sure if this is standard) $like(\\phi), like(\\mu_0, \\mu_1, \\Sigma)$.\n\n\\subsection*{MLE of $\\phi$}\n$like(\\phi) = p(y | \\phi) = \\Pi_{i=1}^n \\phi^{y_i} (1-\\phi)^{1- y_i}$, where $y_i = 0,1$. Then to maximise log likelihood, $l(\\phi) = \\sum y_i \\log(\\phi) + (1 - y_i) \\log(1 - \\phi)$ we seek $\\frac{d l(\\phi)}{d \\phi} = 0$, i.e. $ \\sum \\frac{y_i}{\\phi} + \\frac{y_i - 1}{1 - \\phi} = 0 = \\sum \\frac{y_i - \\phi}{\\phi (1- \\phi)}$ which coincides with $\\phi = \\bar{y}$.\n\n\\subsection*{MLE of $\\mu_0, \\mu_1$}\n$like(\\mu_0, \\mu_1, \\Sigma) = \\Pi p(x_i | \\mu_0, \\mu_1, \\Sigma, y_i))$, so we'll maximise over log likelihood i.e. over \n\\begin{equation*} -\\frac{nd}{2} \\log(2\\pi) - \\frac{n}{2}\\log(|\\Sigma|) -\\frac{1}{2} \\Sigma_{y_i = 0} (x - \\mu_0)^T \\Sigma^{-1} (x - \\mu_0) -\\frac{1}{2} \\Sigma_{y_i = 1} (x - \\mu_1)^T \\Sigma^{-1} (x - \\mu_1)\n\\end{equation*}\nThen the derivative of the log likelihood with respect to $\\mu_0$ is $\\Sigma_{y_i = 0} \\Sigma^{-1}(x - \\mu_0)$ i.e. is maximised with $\\mu_0 = \\bar x \\text{ averaged over } x_i : y_i = 0$, and similarly for $\\mu_1$. \n\n\\subsection*{MLE of $\\Sigma$}\nTo maximise over $\\Sigma$ seems pretty involved. We'll require a formula for $\\frac{\\partial}{\\partial A_{ij}} \\det(A)$. We'll use the matrix minors formulas: $\\delta_{ik} |A| = \\sum_{j=1}^n |A_{ji}| A_{jk}$ Where $A_{ji}$ is the minor matrix, and $|A_{ji}|$ is its determinant. This gives a form of the inverse for $A$ of $K_{ij} = \\frac{(-1)^{i+j}}{|A|} |A_{ji}|$ as this gives $K_{ij} A_{jk} = \\sum_{j=1}^n \\frac{(-1)^{i+j}}{|A|} |A_{ji}| A_{jk} = \\delta_{ij}$. Then $\\frac{\\partial}{\\partial A_{ab}} |A| = \\frac{\\partial}{\\partial A_{ab}} \\left( \\sum_{j=1}^n (-1)^{b+j} |A_{jb}| A_{jb} \\right)$. The sum only has one term with a $A_{ab}$ component, where $j=a$, so we get $\\frac{\\partial}{\\partial A_{ab}} |A| = \\frac{\\partial}{\\partial A_{ab}} (-1)^{a+b} |A_{ab}| A_{ab} = (-1)^{a+b} |A_{ab}| = A^{-1}_{ba} |A|$ (by using the minor form of matrix inverse). This gives us the formula $\\nabla_A |A| = |A| (A^{-1})^T$.\n\nSo seeking a solution of\n\n\\begin{equation*}\n\\nabla_A \\left(\n\t\\frac{n}{2}\\log(|A|) -\\frac{1}{2} \\Sigma_{y_i = 0} (x - \\mu_0)^T A (x - \\mu_0) -\\frac{1}{2} \\Sigma_{y_i = 1} (x - \\mu_1)^T A (x - \\mu_1)\n\\right) = 0\n\\end{equation*} \n\nwhere we let $A = \\Sigma^{-1}$ and use $|\\Sigma| = 1/|A|$, as well as assuming $\\mu_0, \\mu_1$ are already maximised (i.e. $\\mu_0 = \\hat{\\mu_0}_{MLE}$ etc.). Then we get $\\frac{n}{2} A^{-1} - \\frac{1}{2} \\Sigma_{i=1}^n (x - \\mu_{y_i})(x - \\mu_{y_i})^T = 0$ which gives the desired MLE equation, where we used that $\\Sigma$, and so $A$ too, are symmetric so $(A^{-1})^T = A^{-1}$, and that for any matrix $A$, $\\frac{\\partial}{\\partial A} z^T A z = z z^T$.\n\n\\end{answer}\n%\\end{document}", "meta": {"hexsha": "3db2b2ea857ba5161ae63008a10758873b0df3da", "size": 3176, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ps1_attempt2/tex/linearclass/04-gda-ll-sol.tex", "max_stars_repo_name": "Ziggareto/cs229", "max_stars_repo_head_hexsha": "10b03b68b24d252dad3e3437561976d9509ebdd0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ps1_attempt2/tex/linearclass/04-gda-ll-sol.tex", "max_issues_repo_name": "Ziggareto/cs229", "max_issues_repo_head_hexsha": "10b03b68b24d252dad3e3437561976d9509ebdd0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ps1_attempt2/tex/linearclass/04-gda-ll-sol.tex", "max_forks_repo_name": "Ziggareto/cs229", "max_forks_repo_head_hexsha": "10b03b68b24d252dad3e3437561976d9509ebdd0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 102.4516129032, "max_line_length": 920, "alphanum_fraction": 0.5862720403, "num_tokens": 1349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7097236455851665}}
{"text": "\\section{Parametric smoother}\nThese are what you have seen already. We force a function defined by\n``few'' parameters on the data and use something like least squares to\nfind the ``best'' estimates for the parameters. \n\nFor example, a regression line computed with least squares can be\nthought of as a smoother. In this case $S[\\by|\\bx](x_0) =\n(1 \\, x_0) \\, (\\bX'\\bX)^{-1}\\bX'\\by$ with $\\bX$ a design matrix containing a\ncolumn of 1's and $\\bx$ ({\\tt cbind(1,x)}).\n \n\nThe lack of flexibility of these types of smoother can make them\nprovide misleading results.\n\n\n\\begin{figure}[htp]\n\\caption{\\label{f2.2} CD4 cell count since seroconversion for HIV infected men.}\n\\centerline{\\epsfig{figure=Plots/plot-02-02.ps,angle=270,width=.8\\textwidth}}\n\\end{figure}\n", "meta": {"hexsha": "79e99ddcc4d43287f4fa7b7c5d53b3be0cfd5f2e", "size": 755, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-02-01.tex", "max_stars_repo_name": "igrabski/rafalab.github.io", "max_stars_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2016-08-17T23:04:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T19:21:02.000Z", "max_issues_repo_path": "pages/754/section-02-01.tex", "max_issues_repo_name": "igrabski/rafalab.github.io", "max_issues_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-18T00:41:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-21T22:35:40.000Z", "max_forks_repo_path": "pages/754/section-02-01.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 37.75, "max_line_length": 80, "alphanum_fraction": 0.7324503311, "num_tokens": 221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.793105941403651, "lm_q1q2_score": 0.7096628307455225}}
{"text": "\\appendix\n\\chapter{Analytical Modelling of Buckled Beam Mechanism}\\label{chap:appendixA}\nThe bistable mechanism consists of an initially flat beam which, when compressed by a distance $\\Delta l$, buckles and forms a structure that exists in two stable positions. In the case of the actuator, which consists of a pair of SMA coils and the buckled beam itself, is considered to require an input torque $M_\\mathrm{in}$ at the input pivot to switch between its two stable states.\n\nAs the entire kinematic stage is comprised of flexure-based mechanisms, as shown in \\cref{fig:bistable-mechanism}, the pivots that support the buckled beam present with an inherent angular stiffness, $K_\\mathrm{in}$ and $K_\\mathrm{out}$ at the input and output pivot, respectively. The buckled beam is considered to have a flexural rigidity of $EI$ and an initial length before compression of $L$. The distance between the centre of the flexural pivots and the beam is considered to be offset by a distance of $p$, as shown in \\cref{fig:buckled-beam-schematic}.\n\nBased on the hypothesis described in the work by \\cite{tivot2021} and the Euler-Bernoulli beam theory, the beam deflection can be described using the following equation:\n\\begin{equation}\\label{eq:deflection_A}\n  y(x) = \\left(A\\sin{kx}+B(\\cos{kx}-1)+C\\frac{x}{l}\\right) l {\\theta }_\\textrm{in}\n\\end{equation}\nwith $k=\\sqrt{P/(EI)}$ and the boundary conditions of the supported beam are as follows\n\\[y(0)=0\\]\n\\[y'(0)\\cong{\\theta }_\\textrm{out}\\]\n\\[M_0\\cong K_\\textrm{out}\\theta_\\textrm{out}+Vp-Pp\\theta_\\textrm{out}\\]\n\\[y(l)\\cong -p(\\theta_\\textrm{out}+\\theta_\\textrm{in})\\]\n\\[y'(l)\\cong \\theta_\\textrm{in}\\]\nFurthermore, the deflection parameters of \\cref{eq:deflection_A} are given by\n\\begin{equation}\\label{A_norm}\nA =    \\frac{(1+2\\overline{p})kl+{\\varepsilon }_0\\left(\\overline{p}  \\sin{kl}-\\frac{\\cos{kl}-1}{kl}\\right)}\n{kl\\left( kl \\cos{kl}-\\sin{kl}-\\left({\\overline{p}}^2+\\overline{p}\\right){(kl)}^2\\sin{kl}+{\\varepsilon }_0\\left(\\sin{kl}+2\\frac{\\cos{kl}-1}{kl}\\right)\\right)}\n\\end{equation}\n\\begin{equation} \\label{B_norm}\nB = \\frac{  \\overline{p}(1+2\\overline{p}){(kl)}^2+{\\varepsilon }_0 \\left(\\overline{p} \\left(\\cos{kl}-1\\right) + \\frac{\\sin{kl}}{kl} -1\\right)}\n{kl\\left( kl \\cos{kl}-\\sin{kl}-\\left({\\overline{p}}^2+\\overline{p}\\right){(kl)}^2\\sin{kl}+{\\varepsilon }_0\\left(\\sin{kl}+2\\frac{\\cos{kl}-1}{kl}\\right)\\right)}\n\\end{equation}\n\\begin{equation} \\label{C_norm}\nC = \\frac{  {\\overline{p}}^2{(kl)}^2\\sin{kl} -2\\overline{p} kl\\cos{kl} -\\sin{kl} - {\\varepsilon }_0\\left(\\overline{p}\\sin{kl}-\\frac{\\cos{kl}-1}{kl}\\right)}\n{ kl \\cos{kl}-\\sin{kl}-\\left({\\overline{p}}^2+\\overline{p}\\right){(kl)}^2\\sin{kl}+{\\varepsilon }_0\\left(\\sin{kl}+2\\frac{\\cos{kl}-1}{kl}\\right)}\n\\end{equation}\nwhere $\\overline{p} = p/l $ and $\\varepsilon_0=K_\\textrm{out}/(EI/l)$. When considering the beam’s arc length as constant, the end-shorting, $\\Delta l$, can be approximated using the following expression\n\\begin{equation}\\label{eq:delta_l}\n \\Delta l\\cong \\frac{p}{2}({\\theta }^2_\\textrm{in}+\\theta ^2_\\textrm{out})+\\int^l_0{\\frac{y'(x)^2}{2}dx}=H l{\\theta }^2_\\textrm{in}\n\\end{equation}\nHere, the coefficient $H$ is expressed as\n\\begin{multline}\\label{eq:H-smabb}\n H = \\frac{\\left({A}^2+{B}^2\\right){\\left(kl\\right)}^2}{4} + \\frac{\\left({A}^2-{B}^2\\right)kl\\sin{2kl} }{8} + \\frac{AB kl\\left(\\cos{2kl}-1\\right)}{4}\\\\\n +AC\\sin{kl} + BC\\left(\\cos{kl}-1\\right) + \\frac{{C}^2}{2} +\\frac{\\overline{p}}{2}\\left({\\left( Akl+C\\right)}^2+1\\right)\n\\end{multline}\n\nBy rearranging \\cref{eq:delta_l}, the input angle can be expressed as\n\\begin{equation}\\label{eq:theta_in_A}\n {\\theta}_\\textrm{in}=\\pm \\sqrt{\\frac{\\Delta l}{l}}\\sqrt{\\frac{1}{H}}\n\\end{equation}\n\nFinally, the input moment can be described as the following \\cref{eq:M_in_A}\n\\begin{equation}\n\\begin{split}\n M_\\textrm{in} &\\cong M_l+K_\\textrm{in}{\\theta }_\\textrm{in}+Vp-Pp{\\theta}_\\textrm{in}\\\\\n &=\\frac{EI}{l}\\left({\\left(kl\\right)}^2\\left(\\overline{p}\\left(C-1\\right)-A\\sin{kl}-B\\cos{kl}\\right)+{\\varepsilon }_l\\right){\\theta}_\\textrm{in}\n \\label{eq:M_in_A}\n\\end{split}\n\\end{equation}\n\\noindent{where ${\\varepsilon }_l=K_\\textrm{in}/(EI/l)$.}\nThese equations, as developed by Loic Tissot-Daguette, are used to obtain the moment and angular stroke requirements of the bistable element when sizing the SMA elements for the bistable gripper.\n", "meta": {"hexsha": "b6268f2c3965c335a8bec9666baec416c66cfb71", "size": 4323, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tail/appendix.tex", "max_stars_repo_name": "seanthomas0409/sethomas_EPFL_thesis", "max_stars_repo_head_hexsha": "5cc1b082be09da01e7545b7da93d1b113edc77b6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tail/appendix.tex", "max_issues_repo_name": "seanthomas0409/sethomas_EPFL_thesis", "max_issues_repo_head_hexsha": "5cc1b082be09da01e7545b7da93d1b113edc77b6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tail/appendix.tex", "max_forks_repo_name": "seanthomas0409/sethomas_EPFL_thesis", "max_forks_repo_head_hexsha": "5cc1b082be09da01e7545b7da93d1b113edc77b6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 78.6, "max_line_length": 561, "alphanum_fraction": 0.7032153597, "num_tokens": 1606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.7096553498194367}}
{"text": "\\section{Other Notes}\n\n\\subsection{Convergence of Value Iteration}\n\nlet $T^\\pi(v) = R^\\pi + \\gamma P^\\pi v$\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\t||T^\\pi(u) - T^\\pi(v)||_{\\infty} &= ||(R^\\pi + \\gamma P^\\pi u) - (R^\\pi + \\gamma P^\\pi v) ||_\\infty \\\\\n\t\t&= ||\\gamma P^\\pi (u-v) ||_\\infty \\\\\n\t\t&\\leq || \\gamma P^\\pi ||u-v ||_\\infty ||_\\infty \\\\\n\t\t&\\leq \\gamma ||u-v||_\\infty\n\t\\end{aligned}\n\\end{equation}\n\nSo $T$ will converge to fixed point at linear rate $\\gamma$ according to \\emph{contraction mapping theorem}.", "meta": {"hexsha": "40789ed997bea3ecefb66ebc94cae20146691c82", "size": 509, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/others/other.tex", "max_stars_repo_name": "elvisren/machine-learning-notes", "max_stars_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-07T03:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-04T17:28:22.000Z", "max_issues_repo_path": "src/others/other.tex", "max_issues_repo_name": "elvisren/machine-learning-notes", "max_issues_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/others/other.tex", "max_forks_repo_name": "elvisren/machine-learning-notes", "max_forks_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-01T23:34:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-01T23:34:47.000Z", "avg_line_length": 31.8125, "max_line_length": 108, "alphanum_fraction": 0.5972495088, "num_tokens": 195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109606718245, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.7096032699036724}}
{"text": "\\section{Computational Complexities of the Algorithms}\n\n\\lettrine[nindent=0em,lines=3]{I}n this chapter we will briefly discuss each one of the algorithms intended to be used in the development of the Intelligent HVAC System. Along with the description of such algorithms we will present a very brief analysis on their computational complexity.\n\n\\subsection{Artificial Neural Network}\n\nArtificial Neural Networks (ANNs) are computing systems inspired by the biological networks that constitute the brain. Such systems learn (progressively improve performance) to do tasks by considering examples, generally without task-specific programming. \n\nAn ANN is based on a collection of connected units called artificial neurons, (analogous to axons in a biological brain). Each connection (synapse) between neurons can transmit a signal to another neuron. The receiving (postsynaptic) neuron can process the signal(s) and then signal downstream neurons connected to it. Neurons may have state, generally represented by real numbers, typically between 0 and 1. Neurons and synapses may also have a weight that varies as learning proceeds, which can increase or decrease the strength of the signal that it sends downstream. Further, they may have a threshold such that only if the aggregate signal is below (or above) that level is the downstream signal sent. Typically, neurons are organized in layers. Different layers may perform different kinds of transformations on their inputs. Signals travel from the first (input), to the last (output) layer, possibly after traversing the layers multiple times. \\cite{ann_wikipedia}\n\nThe multilayer perceptron is an artificial neural network structure and is a nonparametric estimator that can be used for classification and regression. It is a supervised learning algorithm that learns a function $f(\\cdot): R^m \\rightarrow R^o$ by training on a dataset, where $m$ is the number of dimensions for input and $o$ is the number of dimensions for output. Given a set of features $X = {x_1, x_2, ..., x_m}$ and a target $y$, it can learn a non-linear function approximator for either classification or regression. It is different from logistic regression, in that between the input and the output layer, there can be one or more non-linear layers, called hidden layers. Figure \\ref{Fig:mlp_example} shows a one hidden layer MLP with scalar output. \\cite{ann_scikit}\n\n\\begin{figure}[H]\n\\centering \\includegraphics[width = 60mm, height = 60mm]{imgs/multilayerperceptron_network.png}\n\\caption{Multilayer perceptron}\n\\label{Fig:mlp_example}\n\\end{figure}\n\nThe leftmost layer, known as the input layer, consists of a set of neurons $\\{x_i | x_1, x_2, ..., x_m\\}$ representing the input features. Each neuron in the hidden layer transforms the values from the previous layer with a weighted linear summation $w_1x_1 + w_2x_2 + ... + w_mx_m$, followed by a non-linear activation function $g(\\cdot):R \\rightarrow R$ - like the hyperbolic tan function. The output layer receives the values from the last hidden layer and transforms them into output values.\n\nThe advantages of multilayer perceptrons are:\n \\begin{itemize}\n \\item Capability to learn non-linear models\n \\item Capability to learn models in real-time (on-line learning)\n \\end{itemize}\n \n The disadvantages of multilayer perceptron (MLP) include:\n \\begin{itemize}\n \\item MLP with hidden layers have non-convex cost function where there exists more than one local minimum. Therefore different random weight initializations can lead to different validation accuracy.\n \\item MLP requires the tuning number of of hyperparameters such as the \\textit{number of hidden neurons, layers and iterations}.\n \\item MLP is sensitive to feature scaling\n \\end{itemize}\n \n \\subsubsection{Computational Complexity}\n \nSuppose there are $n$ training samples, $m$ features, $k$ hidden layers, each containing $h$ neurons - for simplicity, and $o$ output neurons. The time complexity of the feedforward-backpropagation algorithm is \n\n\\begin{equation}\nO(n\\cdot m \\cdot h^k \\cdot o)\n\\label{eq:ann_complexity1}\n\\end{equation}\n\nAlso for the sake of simplicity lets assume that $m>h>o$, hence the time complexity for feedforward-backpropgation algorithm is \n\n\\begin{equation}\nO(n\\cdot m^{k+2})\n\\label{eq:ann_complexity2}\n\\end{equation}\n\nAdditional to the computation of the gradients using the backpropagation algorithm we need to consider the complexity (convergence ratio) of the algorithm used for solving the minimization problem inherent to the neural network, recall that at each iteration a minimization problem is solved. For the best case, this is superlinear (L-BFGS) and for the worst case it is linear (Stochastic Gradient Descent).\n\n\\subsection{Anomaly Detection}\n\\label{sec:anomaly_detection_alg}\n\nAssume we have a sample $\\mathbb{M}$ drawn from the same distribution. An outlier, novelty, or anomaly is an instance that is very much different from other instances in the sample. An outlier may indicate an abnormal behavior of the system; for example, in a dataset of credit card transactions, it may indicate fraud; in an image, outliers may indicate anomalies, for example, tumors. \\cite{intro_to_machine_learning}\n\nOutlier detection is not generally cast as a supervised, two-class clas- sification problem of seperating typical instances and outliers, because generally there are very few instances that can be labeled as outliers and they do not fit a consistent pattern that can be easily captured by a two- class classifier. Instead, it is the typical instances that are modeled; this is sometimes called one-class classification. Once we model the typical instances, any instance that does not fit the model (and this may occur in many different ways) is an anomaly.\n\nOutlier detection basically implies spotting what does not normally happen; that is, it is density estimation followed by checking for in- stances with too small probability under the estimated density. As usual, the fitted model can be parametric, semiparametric, or nonparametric. In the parametric case, for example, we can fit a Gaussian to the whole data and any instance having a low probability, or equally, with high Mahalanobis distance to the mean, is a candidate for being an outlier. \\cite{anomaly_scikit}\n\nFigure \\ref{Fig:noveltyDetection_example} shows how novelty detection can separate data into regular observations and abnormal observations.\n\n\\begin{figure}[H]\n\\centering \\includegraphics[width = 90mm, height = 40mm]{imgs/noveltyDetection.png}\n\\caption{Novelty detection}\n\\label{Fig:noveltyDetection_example}\n\\end{figure}\n\nOne common way of performing outlier detection is to assume that the regular data come from a known distribution (e.g. data are Gaussian distributed). From this assumption, we generally try to define the “shape” of the data, and can define outlying observations as observations which stand far enough from the fit shape. The process for defining the \"shape\" of the data is as follows and assumes that all of the samples come from a known distribution, say Gaussian for the purposes of this explanation.\n\nAssume a training set $T = \\{x^{(1)}, \\cdots, x^(m) \\}$ where $x \\in \\mathbb{R}^n$. Suppose that each feature $x_i from x$ is distributed according to some Gaussian distribution $x_i \\sim \\mathcal{N}(\\mu_i, \\sigma_i^2)$. Hence $p(x) = \\prod_{j = 1}^n p(x_j; \\mu_j, \\sigma_j^2)$. The task is now to find the corresponding means $\\mu_i$ for $i = 1,\\cdots,n$ and standard deviations $\\sigma_i^2$ for  $i = 1,\\cdots,n$ of the $n$ different distributions. This can be easily done for the Gaussian distribution as follows\n\n\\begin{equation}\n\\mu_j = \\frac{1}{m} \\sum_{i=1}^{m} x_j^{(i)}\n\\label{eq:mean_eq_gaussian}\n\\end{equation}\n\nand\n\n\\begin{equation}\n\\sigma_j^2 = \\frac{1}{m} \\sum_{i=1}^{m} (x_j^{(i)} - \\mu_j)^2\n\\label{eq:std_eq_gaussian}\n\\end{equation}\n\nWe can now describe the simplest anomaly detection algorithm\n\n\\begin{enumerate}\n\\item Choose features $x_i$ that might be indicative/sensitive of/to anomalies.\n\\item Fit parameters $\\mu_1, \\cdots, \\mu_n$ and $\\sigma_1^2,\\cdots, \\sigma_n^2$ using equations \\eqref{eq:mean_eq_gaussian} and \\eqref{eq:std_eq_gaussian} respectively.\n\\item Given a new example $x$, compute $p(x) = \\prod_{j = 1}^n p(x_j; \\mu_j, \\sigma_j^2)$ \n\\item Tag the new sample $x$ as an anomaly if $p(x) < \\epsilon$, where $epsilon$ is a hyperparameter defined by the user.\n\\end{enumerate}\n\n \\subsubsection{Computational Complexity}\n\nUsually the complexity of this algorithm is negligible compared to the complexity of the feedforward-backpropagation algorithm. As can be seen from the Algorithm in Section \\ref{sec:anomaly_detection_alg} the asymptotic complexity of such algorithm is $O(n)$ where $n$ is the number of choosen features.", "meta": {"hexsha": "5cbc8a6705780658310963094d8740286eb6ad9f", "size": 8746, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Docs/Reports/Computational Power/asymptotic_complexities.tex", "max_stars_repo_name": "jqsun1/intelligent_hvac_backend", "max_stars_repo_head_hexsha": "29762db6e428e228f4a6aebea4977140cd025c1b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Docs/Reports/Computational Power/asymptotic_complexities.tex", "max_issues_repo_name": "jqsun1/intelligent_hvac_backend", "max_issues_repo_head_hexsha": "29762db6e428e228f4a6aebea4977140cd025c1b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Docs/Reports/Computational Power/asymptotic_complexities.tex", "max_forks_repo_name": "jqsun1/intelligent_hvac_backend", "max_forks_repo_head_hexsha": "29762db6e428e228f4a6aebea4977140cd025c1b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 91.1041666667, "max_line_length": 972, "alphanum_fraction": 0.7853876058, "num_tokens": 2103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650403, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7095984855422114}}
{"text": "\\chapter{Problem description}\n\\label{chapter:TSPdescription}\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=.5\\columnwidth]{img/tsp225_plot}\n\t\\caption{The \\textit{tsp225.tsp} instance from \\textit{tsplib} resolved with \\texttt{subtour} method described in cap \\ref{sec:subtour} plotted with Gnuplot.}\n\t\\label{fig:tsp225}\n\\end{figure}\n\nThe Traveling Salesman Problem is a well-known NP-hard problem. In short, given a set of cities it's required to find the shortest tour that visit exactly one time each city and return to the first one.\nIn this report two version of the TSP will be analyzed in details:\n\\begin{itemize}\n\t\\item symmetric TSP (sTSP): with bidirectional edges;\n \t\\item asymmetric TSP (aTSP): with oriented arcs.\n\\end{itemize}\n\n\n\\section{Symmetric TSP}\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=.3\\columnwidth]{img/symTSP_example.png}\n\t\\caption{Example of tour. Only the selected edges are visible.}\n\t\\label{fig:symTSP}\n\\end{figure}\n\nGiven a complete graph $ G = (V, E) $, a distance function $ d $ where:\n\\begin{itemize}\n\t\\item $ V := \\{1, 2, .., n\\}$ is a set of nodes;\n\t\\item $ E $ is the set of edges between each node pairs $ i,j \\in V, i \\ne j $ represented with $ (i,j) $ or for a generic edge $ e $, note that for sTSP $ (i,j) = (j,i) $ therefore the number of edges $ |E| = \\frac{n(n-1)}{2} $;\n\t\\item $ d: (i,j) = e \\to d(i,j) = c_e $ where $ c_e $ is the cost associated to $ e \\in E $;\n\\end{itemize}\nand defining the decision variable:\n\\[\nx_e := \\begin{cases}\n\t1 & \\text{if $ e $ is in the tour,} \\\\\n\t0 & \\text{otherwise}\n\\end{cases}\n\\] \nthe sTSP can be represented with linear programming system in \\ref{eq:sTSP_LP}. \n\\begin{equation}\n\\begin{cases}\n\t\tmin \\sum_{ e\\in E } c_ex_e & \\text{Cost function} \\\\\n\t\t\\sum_{e\\in \\delta (v) } x_e = 2, \\forall v \\in V  & \\text{Degree constraint} \\\\\n\t\t\\sum_{e\\in E(S) } x_e \\le |S|-1, \\forall S \\subset V, |S| \\ge 3  & \\text{Subtour elimination} \\\\\n\t\tx_e \\in \\{0,1\\}, \\forall e \\in E & \\text{Domain constraint}\n\\end{cases}\n\\label{eq:sTSP_LP}\n\\end{equation} \nAs usual it is required to find the value of $ x_e, \\forall e \\in E $ that minimize the \\textit{cost function} and verify the constraints.\nFor the \\textit{degree constrain}, the degree of each $ v \\in V $ ($ |\\delta(v)| $) must be equal to 2. A system with only the degree constrain (and the domain constraint) would probably have a set of subtours with size three or more, however by adding the \\textit{subtour elimination} constraints  it's impose to have only one tour.\n\nThe number of possible subset $ S \\subset V $ is exponential ($ 2^{n} - \\binom{n}{3} -\\binom{n}{2} -\\binom{n}{1} - 1 = O(2^n)$), therefore even a graph with 100 nodes has huge matrix dimension. Note that $ E(S) := \\{ e = (i,j): i,j \\in S \\subset V \\}$ is the set of edges with both vertices in $ S $.\\\\\nConsidering the example in fig. \\ref{fig:symTSP}, the value of the solution is represented in the matrix in tab. \\ref{tab:symTSP_solution} where $ x_{ij} = x_{ji} $ for each $ i,j \\in V, i \\ne j $ but only the cell with $ i < j $ have been completed to enhance the number of variables that are used in practice.\n\n\\begin{table}[h!]\n\t\\begin{center}\n\t\t\\caption{Decision variable matrix. It show the value $ x_{ij} $ of the solution represented in figure \\ref{fig:symTSP}. Due to the symmetry of the matrix, only the cell with $ i < j $ have a value, the others can be checked from the first.}\n\t\t\\label{tab:symTSP_solution}\n\t\t\\begin{tabular}{cc|c|c|c|c|c|}\n\t\t\t \\multicolumn{2}{c}{} & \\multicolumn{5}{c}{j} \\\\ % <-- Combining two cells with alignment c| and content 12.\n\t\t\t& \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{1} & \\multicolumn{1}{c}{2} & \\multicolumn{1}{c}{3} & \\multicolumn{1}{c}{4} & \\multicolumn{1}{c}{5} \\\\ \\cline{3-7}\n\t\t\t\\multirow{5}{*}{i} \t& 1 & \\cellcolor{Black} & 0 & 1 & 0 & 1 \\\\ \\cline{3-7}\n\t\t\t\t\t\t\t\t& 2 &  & \\cellcolor{Black} & 1 & 1 & 0 \\\\ \\cline{3-7}\n\t\t\t\t\t\t\t\t& 3 &  &  & \\cellcolor{Black} & 0 & 0 \\\\ \\cline{3-7}\n\t\t\t\t\t\t\t\t& 4 &  &  &  & \\cellcolor{Black} & 1 \\\\ \\cline{3-7}\n\t\t\t\t\t\t\t\t& 5 &  &  &  &  & \\cellcolor{Black} \\\\ \\cline{3-7}\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\n\n\\section{Asymmetric TSP}\nGiven a complete graph $ G = (V,A) $, a distance funciton  $ d $ where:\n\\begin{itemize}\n\t\\item $ V:= \\{1, 2, .., n\\} $ is the set of nodes;\n\t\\item $ A := $ the set arcs between each nodes $ i,j \\in V, i \\ne j$ represented as $ (i,j) $, note that in the aTSP $ (i,j) \\ne (j,i) $ and the number of arcs is $ |A| = n (n-1) $ which is double of the sTSP;\n\t\\item $ d: (i,j) \\rightarrow d(i,j) = c_{ij} $ where $ c_{ij} $ is the cost associated to the arc $ (i,j) $.\n\\end{itemize}\nAs in the sTSP, it is defined the decision variable $ x_{ij} $ which tell if the arc $ (i,j) $ is in the tour:\n\\[\nx_{ij} := \\begin{cases}\n1 & \\text{if $ (i,j) $ is in the tour,} \\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\]\n\nThe aTSP can be defined in different ways, in this report two version will be considered in detail: Miller Tucker Zemlin \\cite{miller1960integer} and Flow1 by Gavish and Graves \\cite{gavish1978travelling}.\n\n\n\\subsection{Miller Tucker Zemlin}\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=.45\\columnwidth]{img/asymTSP_MTZ_example.png}\n\t\\caption{Example of tour with MTZ model. Only the selected arcs are visible and for each node $ k $, the decision variable $ u_k $ represent the posizion of the node in the tour.}\n\t\\label{fig:asymTSP_MTZ}\n\\end{figure}\n\nMiller Tucker Zemlin (MTZ) model impose the \"subtour elimination\" constraints with the help of another decision variable $ u_k $. For each node $ k = 2,..,n $, $ u_k $ is the position of the node $ k $ in the tour that start from the node $ 1 $. As an example in fig \\ref{fig:asymTSP_MTZ} it is shown that $ u_1 = 0 $ and than $ u_k $ increase until $ n-1 $ along the tour.\n\nThe proposed model is shown in the system of equations \\ref{eq:aTSP_MTZ}. The cost function and the degree constraints are adapted to the asymmetric problem, moreover MTZ constraint is derived from $ u_j \\ge u_i+1-M(1-x_{ij}), \\forall i,j \\in V \\backslash \\{1\\}, M \\gg 0 $. Considering an arc $ (i,j) \\in A \\backslash \\{1\\} $, if it is in the tour then $ u_j \\ge u_i + 1 $ because $ M(1-x_{ij}) = 0 $, else $ u_j \\ge u_i + 1 - M < 0 \\implies u_j \\ge 0 $. For example for the arc $ (4,2) $ in fig \\ref{fig:asymTSP_MTZ}, $ 3 \\ge 2 + 1 - M(1-1) \\iff 3 \\ge 3 $. \\\\\nNote that, if the value of M is less than $|V| - 1$  then the constraint is incorrect, otherwise a value of M greater than $|V| - 1 $ makes the constraint redundant, therefore the best value of M is $|V| - 1$, as implemented. \\\\\n\\begin{equation}\n\\begin{cases}\nmin \\sum_{i\\in V}\\sum_{j\\in V} c_{ij}x_{ij} & \\text{Cost function} \\\\\n\\sum_{i\\in V} x_{ih} = 1, \\forall h \\in V  & \\text{$ x $ Outer arcs degree} \\\\\n\\sum_{i\\in V} x_{hi} = 1, \\forall h \\in V  & \\text{$ x $ Inner arcs degree} \\\\\nu_i -u_j +M x_{ij} \\le M - 1, \\forall i,j \\in V \\backslash \\{1\\} & \\text{MTZ constraints ($ O(n^2) $)} \\\\\n0 \\le x_{ij} \\le 1, Integer, \\forall i,j \\in N  & \\text{$ x $ Domain} \\\\\n0 \\le x_{ii} \\le 0, Integer, \\forall i \\in N  & \\text{} \\\\\n0 \\le u_{i} \\le n-2, Integer, \\forall i \\in N \\backslash \\{1\\} & \\text{$ u $ Domain} \n\\end{cases}\n\\label{eq:aTSP_MTZ}\n\\end{equation}\n\n\nNote that the number of MTZ constraints is $ O(n^2) $, one for each arc, therefore much less respect sTSP model.\\\\\nThe number of decision variables instead is more than the double $ n(n-1) + n = n^2 $. Computational consideration will be done in the next chapter.\n\n\\begin{table}[h!]\n\t\\begin{center}$  $\n\t\t\\caption{Decision variable matrix. It show the value $ x_{ij} $ and $ u_k $ of the solution represented in figure \\ref{fig:asymTSP_MTZ}. }\n\t\t\\label{tab:asymTSP_MTZ_solution}\n\t\t\\begin{tabular}{cc|c|c|c|c|c|}\n\t\t\t $ x_{ij} $ & \\multicolumn{1}{c}{} & \\multicolumn{5}{c}{j} \\\\ % <-- Combining two cells with alignment c| and content 12.\n\t\t\t& \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{1} & \\multicolumn{1}{c}{2} & \\multicolumn{1}{c}{3} & \\multicolumn{1}{c}{4} & \\multicolumn{1}{c}{5} \\\\ \\cline{3-7}\n\t\t\t\\multirow{5}{*}{i} \t& 1 & \\cellcolor{Black} & 0 & 0 & 0 & 1 \\\\ \\cline{3-7}\n\t\t\t& 2 & 0 & \\cellcolor{Black} & 1 & 0 & 0 \\\\ \\cline{3-7}\n\t\t\t& 3 & 1 & 0 & \\cellcolor{Black} & 0 & 0 \\\\ \\cline{3-7}\n\t\t\t& 4 & 0 & 1 & 0 & \\cellcolor{Black} & 0 \\\\ \\cline{3-7}\n\t\t\t& 5 & 0 & 0 & 0 & 1 & \\cellcolor{Black} \\\\ \\cline{3-7}\n\t\t\t\\multicolumn{7}{c}{} \\\\ \n\t\t\t\n\t\t\t\\multicolumn{2}{c}{} & \\multicolumn{5}{c}{$ k $} \\\\  \n\t\t\t& \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{1} & \\multicolumn{1}{c}{2} & \\multicolumn{1}{c}{3} & \\multicolumn{1}{c}{4} & \\multicolumn{1}{c}{5} \\\\ \\cline{3-7}\n \t\t\t$ u_k $ &  & 0 & 3 & 4 & 2 & 1 \\\\ \\cline{3-7}\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\subsection{Flow1}\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=.4\\columnwidth]{img/asymTSP_F1_example.png}\n\t\\caption{Example of tour with Flow1 model. Only the selected arcs are visible. $ y_{ij} $ is the decision variable that represent the decreasing flow of each arcs of the tour. Note that $ y_{ij} = 0 $ for each unselected arcs and in the figure they are not shown.}\n\t\\label{fig:asymTSP_F1}\n\\end{figure}\n\nThe Flow1 model impose the \"subtour elimination\" constraints with a decision variable $ y_{ij} $ which is associated to each arc $ (i,j) \\in V $ and represent a flow that decrease from $ n-1 $ to $ 0 $ for each node of the tour and is $ 0 $ if it is not in the tour. As shown in fig \\ref{fig:asymTSP_F1} starting from the node $ 1 $ the flow $ y_{15} = 4 $ than decrease each step by $ 1 $ unit until the last arc of the tour where $ y_{31} = 0 $. Note that the last arc $ y_{31} $ has the same value of the unselected one, this is because the last arc of the tour is implicit. \\\\\nThe proposed LP model is in the system of equations \\ref{eq:aTSP_F1}. The outer flow of $ 1 $ is the first constraint, than to make the flow decrease it is imposed the \"flow equilibrium\" where each inner flow must be equal to the outer flow $ +1 $ and, in the end, the \\textit{coupling constraints} imposed that only the arcs in the tour ($ x_{ij} > 0 $) can have $ y_{ij} > 0 $ otherwise must be equal to $ 0 $. The last set of constraint force the flow to move along the tour and decrease each step. \n\n\\begin{equation}\n\\begin{cases}\nmin \\sum_{i\\in V}\\sum_{j\\in V} c_{ij}x_{ij}  & \\text{Cost function} \\\\\n\\sum_{i\\in V} x_{ih} = 1, \\forall h \\in V  & \\text{$ x $ Outer arcs} \\\\\n\\sum_{i\\in V} x_{hi} = 1, \\forall h \\in V  & \\text{$ x $ Inner arcs} \\\\\n\\sum_{j\\in V} y_{1j} = n-1  & \\text{$ 1 $ Outer flow} \\\\\n\\sum_{j\\in V} y_{hj} = \\sum_{i \\in V}y_{ih} - 1, \\forall h \\in V \\backslash \\{1\\}  & \\text{Flow equilibrium} \\\\\ny_{ij} - x_{ij}(n-1) \\le 0, \\forall i \\in V, \\forall j \\in V \\backslash \\{1\\}  & \\text{Coupling constraints} \\\\\n0 \\le x_{ij} \\le 1, Integer, \\forall i,j \\in N  & \\text{$ x $ Domain} \\\\\n0 \\le x_{ii} \\le 0, Integer, \\forall i \\in N & \\text{} \\\\\n0 \\le y_{i1} \\le 0, \\forall i \\in V  & \\text{$ y $ Domain} \\\\\n0 \\le y_{ii} \\le 0, \\forall i \\in V  & \\text{} \\\\\n0 \\le y_{ij} \\le n-1, Integer, \\forall i,j \\in V  & \\text{} \n\\end{cases}\n\\label{eq:aTSP_F1}\n\\end{equation}\n\n\nThe number of F1 constraint is equal to $ O(1) + O(n-1) + O(n^2) = O(n^2) $. The tables of variable are shown in tab \\ref{tab:asymTSP_F1_solution} with the associated solution example in fig \\ref{fig:asymTSP_F1}. It's easy to see that the number of variable is $ 2n(n-1) = O(n^2) $\\\\\n\n\n\\begin{table}[h!]\n\t\\begin{center}\n\t\t\\caption{Decision variable matrix. It show the value $ x_{ij}, y_{ij} $ of the solution represented in figure \\ref{fig:asymTSP_F1}.}\n\t\t\\label{tab:asymTSP_F1_solution}\n\t\t\\begin{tabular}{cc|c|c|c|c|c|}\n\t\t\t\n$ x_{ij} $ & \\multicolumn{1}{c}{} & \\multicolumn{5}{c}{j} \\\\ % <-- Combining two cells with alignment c| and content 12.\n& \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{1} & \\multicolumn{1}{c}{2} & \\multicolumn{1}{c}{3} & \\multicolumn{1}{c}{4} & \\multicolumn{1}{c}{5} \\\\ \\cline{3-7}\n\\multirow{5}{*}{i} \t& 1 & \\cellcolor{Black} & 0 & 0 & 0 & 1 \\\\ \\cline{3-7}\n& 2 & 0 & \\cellcolor{Black} & 1 & 0 & 0 \\\\ \\cline{3-7}\n& 3 & 1 & 0 & \\cellcolor{Black} & 0 & 0 \\\\ \\cline{3-7}\n& 4 & 0 & 1 & 0 & \\cellcolor{Black} & 0 \\\\ \\cline{3-7}\n& 5 & 0 & 0 & 0 & 1 & \\cellcolor{Black} \\\\ \\cline{3-7}\n\\multicolumn{7}{c}{} \\\\ \n\n$ y_{ij} $ & \\multicolumn{1}{c}{} & \\multicolumn{5}{c}{j} \\\\ % <-- Combining two cells with alignment c| and content 12.\n& \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{1} & \\multicolumn{1}{c}{2} & \\multicolumn{1}{c}{3} & \\multicolumn{1}{c}{4} & \\multicolumn{1}{c}{5} \\\\ \\cline{3-7}\n\\multirow{5}{*}{i} \t& 1 & \\cellcolor{Black} & 0 & 0 & 0 & 4 \\\\ \\cline{3-7}\n\t\t\t\t\t& 2 & 0 & \\cellcolor{Black} & 0 & 0 & 0 \\\\ \\cline{3-7}\n\t\t\t\t\t& 3 & 1 & 0 & \\cellcolor{Black} & 0 & 0 \\\\ \\cline{3-7}\n\t\t\t\t\t& 4 & 0 & 2 & 0 & \\cellcolor{Black} & 0 \\\\ \\cline{3-7}\n\t\t\t\t\t& 5 & 0 & 0 & 0 & 3 & \\cellcolor{Black} \\\\ \\cline{3-7}\n\t\t\t\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}", "meta": {"hexsha": "0ccd2d3530ccf506f2da1c5c87ae347cb5f96620", "size": 12788, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Latex/model_description.tex", "max_stars_repo_name": "Fisher4537/OR2", "max_stars_repo_head_hexsha": "aeefe436c9be70071cfd92bd59d4b67b03e4ed27", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Latex/model_description.tex", "max_issues_repo_name": "Fisher4537/OR2", "max_issues_repo_head_hexsha": "aeefe436c9be70071cfd92bd59d4b67b03e4ed27", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Latex/model_description.tex", "max_forks_repo_name": "Fisher4537/OR2", "max_forks_repo_head_hexsha": "aeefe436c9be70071cfd92bd59d4b67b03e4ed27", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.6218905473, "max_line_length": 580, "alphanum_fraction": 0.6385674069, "num_tokens": 4785, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8807970748488297, "lm_q1q2_score": 0.7095984672378917}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\begin{document}\n\n\\section{Integrals}\n\n\\[\n    \\int_{a}^{b} x^{x^2} \\,dx\n\\]\nand multiple integrals:\n\\begin{gather*}\n    \\iint_V \\mu(u,v) \\,du\\,dv\n\\\\\n    \\iiint_V \\mu(u,v,w) \\,du\\,dv\\,dw\n\\\\\n    \\iiiint_V \\mu(t,u,v,w) \\,dt\\,du\\,dv\\,dw\n\\\\\n    \\idotsint_V \\mu(u_1,\\dots,u_k) \\,du_1 \\dots du_k\n\\\\\n    \\oint_V f(s) \\,ds\n\\end{gather*}\n\n\\section{Sums and products}\n\n\\[\n    \\sum_{n=1}^{\\infty} 2^{-n} = 1\n\\]\n\n\\[\n    \\prod_{i=a}^{b} f(i)\n\\]\n\n\\section{Limits}\n\n\\[\n    \\lim_{x\\to\\infty} f(x)\n\\]\n\n\\end{document}", "meta": {"hexsha": "c163d9cd1c5d18c3a0e08a387f8882339cb64875", "size": 542, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX/06 Mathematical Equations Tutorial/07 Mathematical Equations.tex", "max_stars_repo_name": "koroshkorosh1/LaTeX_Tutorial", "max_stars_repo_head_hexsha": "2a1d2f7027174fd332d44b4be0d30d9cec967ef1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "LaTeX/06 Mathematical Equations Tutorial/07 Mathematical Equations.tex", "max_issues_repo_name": "koroshkorosh1/LaTeX_Tutorial", "max_issues_repo_head_hexsha": "2a1d2f7027174fd332d44b4be0d30d9cec967ef1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LaTeX/06 Mathematical Equations Tutorial/07 Mathematical Equations.tex", "max_forks_repo_name": "koroshkorosh1/LaTeX_Tutorial", "max_forks_repo_head_hexsha": "2a1d2f7027174fd332d44b4be0d30d9cec967ef1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.8974358974, "max_line_length": 52, "alphanum_fraction": 0.5516605166, "num_tokens": 253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.7095984637857233}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Series}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises relating to fundamental properties of series.\n\\end{abstract}\n\\maketitle\n\n\n\\begin{exercise}\nCompute the sum of the series:\n\\begin{hint} Split the series into two separate geometric series and evaluate each separately. \\end{hint}\n\\[ \\sum_{n=0}^\\infty \\frac{3^n - 2^n}{4^n}  = \\answer{2}. \\]\n\\end{exercise}\n\n\n\\begin{exercise}\nCompute the sum of the series:\n\\begin{hint} One way to proceed is to reindex the series so that it starts at $n = 0$. \\end{hint}\n\\[ \\sum_{n=3}^\\infty \\frac{(-1)^{n+1} 2^n}{3^n} = \\answer{ \\frac{8}{45} } \\]\n\\end{exercise}\n\n\\begin{exercise}\nCompute the sum of the series:\n\\[ \\sum_{n=1}^\\infty \\frac{3^{2n+1}}{2^{3n} \\cdot 9^n} = \\answer{\\frac{3}{7}} \\]\n\\begin{hint} Simplify as much as possible and write in standard form for a geometric series.\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\n\\begin{itemize}\n\\item Give an example of a geometric series whose first term is $3$ and which sums to $6$. If no such series exists, enter N/A in both spaces below:\n\\[ 6 = \\sum_{n=0}^\\infty \\answer{3} \\left( \\answer{\\frac{1}{2}} \\right)^n \\]\n\\item Give an example of a geometric series whose first term is $3$ and which sums to $2$. If no such series exists, enter N/A in both spaces below:\n\\[ 2 = \\sum_{n=0}^\\infty \\answer{3} \\left( \\answer{- \\frac{1}{2}} \\right)^n \\]\n\\item Give an example of a geometric series whose first term is $3$ and which sums to $1$. If no such series exists, enter N/A in both spaces below:\n\\[ 1 = \\sum_{n=0}^\\infty \\answer{N/A} \\left( \\answer{N/A} \\right)^n \\]\n\\end{itemize}\n\\end{exercise}\n\n\\begin{exercise}\nFind the correct value of the constant in the blank below which makes the sum of the series equal to zero:\n\\[ 0 = \\sum_{n=1}^\\infty \\frac{(-1)^{n-1}\\answer{8} - 2^n}{3^n} \\]\n\\begin{hint} One reasonable strategy is to separate the series into two geometric series and reindex to apply the standard formula. \\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nCompute the sum of the infinite series below:\n\\[ \\sum_{n=1}^\\infty \\frac{1}{n(n+1)(n+2)} = \\answer{\\frac{1}{4}}. \\]\n\\begin{hint}\nThere is a closely-related telescoping series:\n\\[ \\frac{1}{n(n+1)} - \\frac{1}{(n+1)(n+2)} = \\frac{2}{n(n+1)(n+2)} \\]\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nCompute the sum of the infinite series below.\n\\[ \\sum_{n=1}^\\infty \\frac{2}{n(n+2)} = \\answer{\\frac{3}{2}} \\]\n\\begin{hint}\nExpand the terms using partial fractions and compute several partial sums by hand. What you get is something like a telescoping series, but cancellations occur in a slightly different way than usual.\n\\begin{hint}\n\\[ \\frac{2}{n(n+2)} = \\frac{1}{n} - \\frac{1}{n+2}. \\]\n\\begin{hint}\nThe formula for a general partial sum is\n\\[ \\frac{2}{1 \\cdot 3} + \\cdots + \\frac{2}{N \\cdot (N+2)} = 1 + \\frac{1}{2} - \\frac{1}{N+1} - \\frac{1}{N+2} \\]\n\\end{hint}\n\\end{hint}\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\n\\begin{itemize}\n\\item Use your answer to the previous exercise to compute the sum of the series:\n\\[ \\sum_{n=3}^\\infty \\frac{1}{n(n-2)} = \\answer{\\frac{3}{4}} \\]\n\\item Use the answer you just found to compute the sum of the series:\n\\[ \\sum_{n=4}^\\infty \\frac{1}{n(n-2)} = \\answer{\\frac{5}{12}} \\]\n\\begin{hint}\nTo drop the $n=3$ term, you can just calculate it and then subtract it from the previous series.\n\\end{hint}\n\\end{itemize}\n\\end{exercise}\n\n\n\n\\section*{Sample Quiz Questions}\n\n\\begin{question}%%%%%[2019Telescope1]\n\nCompute the exact value of the infinite series\n\\[ \\sum_{n=1}^\\infty \\ln \\left( \\frac{1 + n^{-1}}{1 + (n+1)^{-1}} \\right). \\]\n\\begin{multiplechoice}\n\\choice[correct]{\\(\\ln 2\\)}\n\\choice{\\(\\ln 3\\)}\n\\choice{\\(\\ln 4\\)}\n\\choice{\\(\\ln 5\\)}\n\\choice{\\(\\ln 6\\)}\n\\choice{\\(\\ln 7\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nThe series is not a geometric series or Taylor series, we compute the first few partial sums:\n\\[ \n\\begin{aligned}\nS_1 & = \\ln \\left( \\frac{1 + 1}{1 + 2^{-1}} \\right)  = \\ln \\left( \\frac{2}{\\frac{3}{2}} \\right) \\\\\nS_2 & = \\ln \\left( \\frac{1 + 1}{1 + 2^{-1}} \\right)  + \\ln \\left( \\frac{1 + 2^{-1}}{1 + 3^{-1}} \\right)  = \\ln \\left( \\frac{1 + 1}{1 + 3^{-1}} \\right) = \\ln \\left( \\frac{2}{\\frac{4}{3}} \\right) \\\\\nS_3 & = \\ln \\left( \\frac{2}{1 + 3^{-1}} \\right)  + \\ln \\left( \\frac{1 + 3^{-1}}{1 + 4^{-1}} \\right)  = \\ln \\left( \\frac{2}{1 + 4^{-1}} \\right) = \\ln \\left( \\frac{2}{\\frac{5}{4}} \\right) \\\\\n& \\ \\vdots  \\\\\nS_n & = \\ln \\left( \\frac{2}{1 + (n+1)^{-1}} \\right).\n \\end{aligned}\n\\]\nIn particular, writing the sum of logarithms as a logarithm of a product leads to substantial cancellation.  By letting \\(n \\rightarrow \\infty\\), we get \\(S_n \\rightarrow \\ln 2\\).\n\\end{feedback}\n\n\\end{question}\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "a6e4b05f111f5e7be86dda4a0c1ce526c5829b3d", "size": 4701, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "series/19seriespractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "series/19seriespractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "series/19seriespractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.8512396694, "max_line_length": 199, "alphanum_fraction": 0.6479472453, "num_tokens": 1679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.7095766863497033}}
{"text": "\\subsection{Differentiability}\\label{subsec:differentiability}\n\nLet \\( X \\) and \\( Y \\) be Hausdorff \\hyperref[def:topological_vector_space]{topological vector spaces} and let \\( U \\subseteq X \\) be an open set.\n\n\\begin{definition}\\label{def:differentiability}\n  Out goal is to study the following \\hyperref[def:partial_function]{partial} operator:\n  \\begin{balign}\\label{def:differentiability/partial_operator}\n     & \\partial: \\cat{Set}(U, Y) \\times U \\times X \\to Y                             \\\\\n     & \\partial(f, x, h) \\coloneqq \\lim_{t \\downarrow 0} \\frac {f(x + th) - f(x)} t.\n  \\end{balign}\n\n  We implicitly assume that \\( t \\neq 0 \\) because otherwise the definition would not make sense.\n\n  We only use the operator \\( \\partial \\) inside this definition. See \\fullref{rem:derivative_notation} for a discussion of derivative notation.\n\n  The quotient under the limit sign is called a \\term{difference quotient}.\n\n  For each function \\( f: U \\to Y \\), each point \\( x_0 \\in X \\) and each \\enquote{direction} vector \\( x_0 \\in X \\), we want to obtain a value in \\( Y \\), which we will call the \\term{directional derivative} of \\( f \\) at \\( x_0 \\) in the direction \\( h \\). Note that \\( h \\) is allowed to range over \\( X \\).\n\n  The existence of a directional derivative is already a harsh condition, however we impose even harsher restrictions\n\n  \\begin{thmenum}\n    \\thmitem{def:differentiability/first_variation}\\mcite[sec. 0.2.1]{ИоффеТихомиров1974}If, for fixed \\( f \\) and \\( x_0 \\), the directional derivative \\( \\partial(f, x_0, h) \\) exists for all directions \\( h \\), we define the \\term{first variation} of \\( f \\) at \\( x_0 \\) as\n    \\begin{balign*}\n       & \\delta f(x_0): X \\to Y                            \\\\\n       & [\\delta f(x_0)](h) \\coloneqq \\partial(f, x_0, h).\n    \\end{balign*}\n\n    Within its domain of definition of \\( \\delta \\), which is stricter than that of \\( \\partial \\), the operator \\( \\delta \\) is a \\hyperref[def:function/currying]{currying} of \\( \\partial \\). We are interested in how the operator \\( \\delta f(x) \\) varies as \\( x \\) varies.\n\n    Note that \\( \\delta f(x_0) \\) is an operator from \\( X \\) to \\( Y \\) even if \\( f \\) is a function from \\( U \\subsetneq X \\) to \\( Y \\).\n\n    Note that, in general, the first variation operator \\( \\delta f(x_0) \\) is not linear - for example, by \\fullref{thm:convex_one_sided_derivatives_sublinear}, the first variation of a general convex functions is, at most, sublinear. See \\fullref{subsec:nonsmooth_derivatives} for how \\enquote{nonlinear derivatives} are handled.\n\n    \\thmitem{def:differentiability/gateaux}\\mcite[sec. 0.2.1]{ИоффеТихомиров1974}If the first variation \\( \\delta f(x_0) \\) is a continuous linear operator, we say that \\( f \\) is \\term{Gateaux differentiable} or \\term{weakly differentiable} at \\( x_0 \\) with \\term{Gateaux derivative} \\( f'_G(x_0) \\coloneqq \\delta f(x_0) \\).\n\n    Since \\( f'(x_0) \\) is linear in \\( h \\), we can replace \\( t \\downarrow 0 \\) with \\( t \\to 0 \\) in \\fullref{def:differentiability/partial_operator} and reformulate this condition of Gateaux differentiability as the existence of a continuous linear operator \\( \\Lambda: X \\to Y \\) such that\n    \\begin{equation}\\label{def:differentiability/gateaux/condition}\n      \\Lambda(h) = \\lim_{t \\to 0} \\frac {f(x_0 + h) - f(x_0)} t.\n    \\end{equation}\n\n    If \\( \\Lambda \\) exists, we usually denote it by \\( D_G f(x_0) \\) or \\( f_G'(x_0) \\) and call it the \\term{Gateaux derivative} of \\( f \\) at \\( x_0 \\). See \\fullref{rem:derivative_notation} for a discussion of the notation.\n\n    \\thmitem{def:differentiability/frechet}\\mcite[sec. 0.2.1]{ИоффеТихомиров1974}We now restrict our attention to \\hyperref[def:banach_space]{Banach spaces}. We say that \\( f \\) is \\term{Frechet differentiable} or \\term{strongly differentiable} at \\( x_0 \\) if there exists a continuous linear operator \\( \\Lambda: X \\to Y \\) such that\n    \\begin{equation}\\label{def:differentiability/frechet/condition}\n      \\lim_{h \\to 0} \\frac {\\norm{f(x_0 + h) - f(x_0) - \\Lambda(h)}_Y} {\\norm{h}_X} = 0.\n    \\end{equation}\n\n    If \\( \\Lambda \\) exists, we usually denote it by \\( D f(x_0) \\) or \\( f(x_0) \\) and call it the \\term{Frechet derivative} of \\( f \\) at \\( x_0 \\). See \\fullref{rem:derivative_notation} for a discussion of the notation.\n\n    Note that \\fullref{def:differentiability/gateaux/condition} uses convergence in the topology of \\( Y \\) while \\fullref{def:differentiability/frechet/condition} uses convergence in \\( \\BbbR \\). We discuss in \\fullref{rem:gateaux_vs_frechet} how Frechet differentiability is a special \\enquote{uniform} case of Gateaux differentiability.\n\n    \\thmitem{def:differentiability/strict}\\mcite[33]{DontchevRockafellar2014}If there exists a continuous linear operator \\( \\Lambda \\) such that\n    \\begin{equation}\\label{def:differentiability/strict/condition}\n      \\lim_{\\substack{y \\to x_0 \\\\ z \\to x_0}} \\frac {\\norm{f(y) - f(z) - \\Lambda (y - z)}_Y} {\\norm{y - z}_X} = 0,\n    \\end{equation}\n    we say that \\( f \\) is \\term{strictly differentiable} at \\( x_0 \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{remark}\\label{rem:derivative_notation}\n  The following are standard notations for derivatives (some of the comments are based on \\cite[146]{Фихтенгольц1968Том2}):\n  \\begin{thmenum}\n    \\thmitem{rem:derivative_notation/lagrange} We already used \\term{Lagrange's notation} \\( f'(x_0) \\) and \\( f_G'(x_0) \\) in \\fullref{def:differentiability}. Brevity is the only benefit of this notation. It becomes convenient when the functions have no name is a burden for directional derivatives.\n\n    The second and third derivatives of \\( f \\) at \\( x_0 \\) are denoted as \\( f^{''}(x_0) \\) and \\( f^{'''}(x_0) \\) and the \\( n \\)-th derivative of is denoted as \\( f^{(n)} \\).\n\n    See \\fullref{def:nonsmooth_derivatives} for variations of this notation.\n\n    \\thmitem{rem:derivative_notation/newton} Newton's notation is similar to that of Leibniz, but depends on placing dots on top of \\( f \\), e.g. \\( \\ddot{f}(x_0) \\coloneqq f''(x_0) \\). This is used in areas like mathematical physics, however it has not become standard in more pure areas of analysis.\n\n    \\thmitem{rem:derivative_notation/euler} We use \\term{Euler's notation} \\( Df(x_0) \\coloneqq f'(x_0) \\) for more complicated expressions, e.g. \\fullref{thm:derivative_limit_exchange}. The main benefit of this notation is that is allows to express differentiation as an operator, similar to what we defined in \\fullref{def:differentiability}. The directional derivative of \\( f \\) at \\( x_0 \\) in the direction \\( h \\) is denoted as \\( D_h f(x_0) \\). Iterated differentiation corresponds to the standard notation for group composition: the \\( n \\)-th derivative at \\( x_0 \\) is denoted as \\( D^n f(x_0) \\).\n\n    We also use other letters in the superscripts like \\( D^G f(x_0) \\) for Gateaux derivatives, \\( D^\\circ f(x_0) \\) for Clarke's generalized derivatives, etc.\n\n    \\thmitem{rem:derivative_notation/phelps} Some authors like \\cite{Phelps1993} use a variation of Euler's notation with \\( \\partial \\) instead of \\( D \\). For example, directional derivatives are introduced as \\( \\partial^+ f(x_0)(h) \\) in \\cite[lemma 1.2]{Phelps1993}. This is consistent with the standard notation for subdifferentials - see \\fullref{def:subdifferentials}, however Euler's notation appears to be more widely adoped.\n\n    \\thmitem{rem:derivative_notation/leibniz} The Leibniz notation for the derivative \\( f'(x_0) \\) is\n    \\begin{equation*}\n      \\diff f x (x_0) \\coloneqq D f(x_0).\n    \\end{equation*}\n\n    This notation is used extensively in integral calculus, however it is often confusing when manipulating derivatives. The fraction notation is unjustified in anything, but trivial cases and the partial derivative notation\n    \\begin{equation*}\n      \\diffp f x (x_0) \\coloneqq D_x f(x_0)\n    \\end{equation*}\n    is even more confusing.\n\n    Note also that this depends on the convention of having variable names.\n  \\end{thmenum}\n\\end{remark}\n\n\\begin{remark}\\label{rem:gateaux_vs_frechet}\n  We will compare Gateaux \\hyperref[def:differentiability/gateaux]{differentiability} with Frechet \\hyperref[def:differentiability/frechet]{differentiability}. Let \\( X \\) and \\( Y \\) be Banach spaces, let \\( U \\subseteq X \\) be an open set and let \\( f: U \\to Y \\) be an arbitrary function. Fix a point \\( x_0 \\in U \\).\n\n  The continuous linear operator \\( \\Lambda: X \\to Y \\) is a Gateaux derivative if, for every \\( \\varepsilon > 0 \\) and every direction \\( h \\in X \\) there exists \\( \\delta_G^h > 0 \\) such that\n  \\begin{equation}\\label{rem:gateaux_vs_frechet/gateaux}\n    \\norm{\\frac {f(x_0 + th) - f(x_0)} t - \\inprod \\Lambda h}_Y < \\varepsilon \\quad\\forall t \\in (0, \\delta_G^h).\n  \\end{equation}\n\n  In order for \\( \\Lambda \\) to be a Frechet derivative, for every \\( \\varepsilon > 0 \\) there must exist a \\( \\delta_F > 0 \\), so that\n  \\begin{equation*}\n    \\frac{\\norm{f(x_0 + h) - f(x_0) - \\inprod \\Lambda h}_Y} {\\norm{h}_X} < \\varepsilon \\quad\\forall h \\in B(0, \\delta_F) \\setminus \\{ 0 \\},\n  \\end{equation*}\n  which can be restated as\n  \\begin{equation}\\label{rem:gateaux_vs_frechet/frechet}\n    \\norm{\\frac {f(x_0 + th) - f(x_0)} t - \\inprod \\Lambda h}_Y < \\varepsilon \\quad\\forall t \\in (0, \\delta_F) \\ \\forall h \\in S_X.\n  \\end{equation}\n\n  By comparing \\fullref{rem:gateaux_vs_frechet/gateaux} to \\fullref{def:differentiability/frechet}, we conclude that \\( f \\) is Frechet differentiable at \\( x_0 \\) if \\( \\inf_{h \\in S_X} \\delta^h_G > 0 \\), that is, if \\( f \\) is Gateaux differentiable and the convergence of the Gateaux derivative is uniform on \\( h \\in S_X \\).\n\n  In particular, Frechet differentiability implies Gateaux differentiability.\n\\end{remark}\n", "meta": {"hexsha": "52b8bd88a04d15ec975f9a225651caea1bdf9897", "size": 9711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/differentiability.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/differentiability.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/differentiability.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 85.1842105263, "max_line_length": 608, "alphanum_fraction": 0.6937493564, "num_tokens": 3020, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.709576675419378}}
{"text": "%---------------------------Relative Size-----------------------------\n\\section{Relative Size Squared\\label{s:quad-rel-size-squared}}\n\nThe relative size squared metric is defined as\n\\[\nq = \\left( \\min\\left\\{ \\frac{A}{\\overline{A}}, \\frac{\\overline{A}}{A} \\right\\} \\right)^2\n\\]\nwhere $A$ is the area of the element as defined in \\S\\ref{s:quad-area}\nand $\\overline{A}$ is the average of $A$ over all of the elements in the\nensemble of elements being considered.\nIt is the square of the minimum of the ratio of quad area to the average quad area and its inverse.\n\nNote that if $\\overline{A} < DBL\\_MIN$ or $A < DBL\\_MIN$, we take $q = 0$.\n\n\\quadmetrictable{relative size squared}%\n{$1$}%                                      Dimension\n{$[0.3, 1]$}%                               Acceptable range\n{$[0,1]$}%                                  Normal range\n{$[0,1]$}%                                  Full range\n{Dependent on $\\overline{A}$}%              Unit square\n{\\cite{knu:03}}%                            Citation\n{v\\_quad\\_relative\\_size\\_squared}%         Verdict function name\n\n", "meta": {"hexsha": "c2910dfe5e9a5fc1432f8b03cc6b6bfe1b43f6f1", "size": 1081, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadRelativeSizeSquared.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadRelativeSizeSquared.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadRelativeSizeSquared.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 45.0416666667, "max_line_length": 99, "alphanum_fraction": 0.5457909343, "num_tokens": 284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.7095115083443869}}
{"text": "\\subsection{Numerical Approximation and Analysis}\\label{sec:set-approx}\nIn the \\emph{set-based} inversion framework, there are two primary sources of approximation error:\n\\begin{description}[leftmargin=!, labelwidth=0.7in]\n  \\item[(1)] partitioning the parameter space $\\pspace$ to approximate events in $\\cborel$ (and consequently, $\\pborel$), and\n  \\item[(2)] partitioning the data space $\\dspace$ to approximate events in $\\dborel$.\n\\end{description}\nIn practice, we must rely on a finite numerical approximation of the (often uncountable) events in the $\\sa$s $\\dborel$, $\\cborel$, and $\\pborel$.\nOwing to the inclusion $\\cborel \\subset \\pborel$, it is possible to approximate events in both of these $\\sa$s simultaneously.\n\nAssume we fix some collection of sets $\\set{D_\\idisc}_{\\idisc=1}^{\\ndiscs} \\subset \\dborel$ to partition $\\dspace$ (independent of any specification of $\\qoi$), and that we partition $\\pspace$ with $\\set{\\VV_\\iparam}_{\\iparam=1}^{\\nsamps}$, where $\\VV_\\iparam \\in \\pborel$.\nBoth sets yield implicitly-defined Voronoi-cell partitions given by a finite sampling of each space.\n\nIn order to approximate $\\paramP(\\VV_\\iparam)$ for $\\iparam=1,\\hdots,\\nsamps$, we must determine which collection of $\\VV_\\iparam$'s approximate $\\qoi^{-1}(D_\\idisc)$ for each $\\idisc=1,\\hdots,\\ndiscs$, and then apply the ansatz on this approximation of the contour event with known probability $\\dataP(D_\\idisc)$.\nAlgorithm~\\ref{alg:inv_density} was proven to converge to the solution $\\paramP$ in \\cite{BET+14-arxiv} as the discretizations of $\\pspace$ and $\\dspace$ (as ${\\nsamps \\text{ and } \\ndiscs}$ tend to $\\infty$, respectively.\n", "meta": {"hexsha": "3c0883fe468ef0600e7aad6c7265a97264d9ba26", "size": 1643, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch02/set_approx.tex", "max_stars_repo_name": "mathematicalmichael/thesis", "max_stars_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-24T08:05:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-28T20:34:29.000Z", "max_issues_repo_path": "ch02/set_approx.tex", "max_issues_repo_name": "mathematicalmichael/thesis", "max_issues_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 59, "max_issues_repo_issues_event_min_datetime": "2019-12-27T23:15:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T17:52:57.000Z", "max_forks_repo_path": "ch02/set_approx.tex", "max_forks_repo_name": "mathematicalmichael/thesis", "max_forks_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 109.5333333333, "max_line_length": 314, "alphanum_fraction": 0.7443700548, "num_tokens": 471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511616741041, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7094482402502401}}
{"text": "\\section{Sets and Relations}\n\n\\begin{definition}[Polyhedral Set]\nA {\\em polyhedral set}\\index{polyhedral set} $S$ is a finite union of basic sets\n$S = \\bigcup_i S_i$, each of which can be represented using affine\nconstraints\n$$\nS_i : \\Z^n \\to 2^{\\Z^d} : \\vec s \\mapsto\nS_i(\\vec s) =\n\\{\\, \\vec x \\in \\Z^d \\mid \\exists \\vec z \\in \\Z^e :\nA \\vec x + B \\vec s + D \\vec z + \\vec c \\geq \\vec 0 \\,\\}\n,\n$$\nwith $A \\in \\Z^{m \\times d}$,\n$B \\in \\Z^{m \\times n}$,\n$D \\in \\Z^{m \\times e}$\nand $\\vec c \\in \\Z^m$.\n\\end{definition}\n\n\\begin{definition}[Parameter Domain of a Set]\nLet $S \\in \\Z^n \\to 2^{\\Z^d}$ be a set.\nThe {\\em parameter domain} of $S$ is the set\n$$\\pdom S \\coloneqq \\{\\, \\vec s \\in \\Z^n \\mid S(\\vec s) \\ne \\emptyset \\,\\}.$$\n\\end{definition}\n\n\\begin{definition}[Polyhedral Relation]\nA {\\em polyhedral relation}\\index{polyhedral relation}\n$R$ is a finite union of basic relations\n$R = \\bigcup_i R_i$ of type\n$\\Z^n \\to 2^{\\Z^{d_1+d_2}}$,\neach of which can be represented using affine\nconstraints\n$$\nR_i = \\vec s \\mapsto\nR_i(\\vec s) =\n\\{\\, \\vec x_1 \\to \\vec x_2 \\in \\Z^{d_1} \\times \\Z^{d_2}\n\\mid \\exists \\vec z \\in \\Z^e :\nA_1 \\vec x_1 + A_2 \\vec x_2 + B \\vec s + D \\vec z + \\vec c \\geq \\vec 0 \\,\\}\n,\n$$\nwith $A_i \\in \\Z^{m \\times d_i}$,\n$B \\in \\Z^{m \\times n}$,\n$D \\in \\Z^{m \\times e}$\nand $\\vec c \\in \\Z^m$.\n\\end{definition}\n\n\\begin{definition}[Parameter Domain of a Relation]\nLet $R \\in \\Z^n \\to 2^{\\Z^{d+d}}$ be a relation.\nThe {\\em parameter domain} of $R$ is the set\n$$\\pdom R \\coloneqq \\{\\, \\vec s \\in \\Z^n \\mid R(\\vec s) \\ne \\emptyset \\,\\}.$$\n\\end{definition}\n\n\\begin{definition}[Domain of a Relation]\nLet $R \\in \\Z^n \\to 2^{\\Z^{d+d}}$ be a relation.\nThe {\\em domain} of $R$ is the polyhedral set\n$$\\domain R \\coloneqq \\vec s \\mapsto\n\\{\\, \\vec x_1 \\in \\Z^{d_1} \\mid \\exists \\vec x_2 \\in \\Z^{d_2} :\n(\\vec x_1, \\vec x_2) \\in R(\\vec s) \\,\\}\n.\n$$\n\\end{definition}\n\n\\begin{definition}[Range of a Relation]\nLet $R \\in \\Z^n \\to 2^{\\Z^{d+d}}$ be a relation.\nThe {\\em range} of $R$ is the polyhedral set\n$$\n\\range R \\coloneqq \\vec s \\mapsto\n\\{\\, \\vec x_2 \\in \\Z^{d_2} \\mid \\exists \\vec x_1 \\in \\Z^{d_1} :\n(\\vec x_1, \\vec x_2) \\in R(\\vec s) \\,\\}\n.\n$$\n\\end{definition}\n\n\\begin{definition}[Composition of Relations]\nLet $R \\in \\Z^n \\to 2^{\\Z^{d_1+d_2}}$ and\n$S \\in \\Z^n \\to 2^{\\Z^{d_2+d_3}}$ be two relations,\nthen the composition of\n$R$ and $S$ is defined as\n$$\nS \\circ R \\coloneqq\n\\vec s \\mapsto\n\\{\\, \\vec x_1 \\to \\vec x_3 \\in \\Z^{d_1} \\times \\Z^{d_3}\n\\mid \\exists \\vec x_2 \\in \\Z^{d_2} :\n\\vec x_1 \\to \\vec x_2 \\in R(\\vec s) \\wedge\n\\vec x_2 \\to \\vec x_3 \\in S(\\vec s)\n\\,\\}\n.\n$$\n\\end{definition}\n\n\\begin{definition}[Difference Set of a Relation]\nLet $R \\in \\Z^n \\to 2^{\\Z^{d+d}}$ be a relation.\nThe difference set ($\\Delta \\, R$) of $R$ is the set\nof differences between image elements and the corresponding\ndomain elements,\n$$\n\\diff R \\coloneqq\n\\vec s \\mapsto\n\\{\\, \\vec \\delta \\in \\Z^{d} \\mid \\exists \\vec x \\to \\vec y \\in R :\n\\vec \\delta = \\vec y - \\vec x\n\\,\\}\n$$\n\\end{definition}\n\n\\section{Simple Hull}\\label{s:simple hull}\n\nIt is sometimes useful to have a single\nbasic set or basic relation that contains a given set or relation.\nFor rational sets, the obvious choice would be to compute the\n(rational) convex hull.  For integer sets, the obvious choice\nwould be the integer hull.\nHowever, {\\tt isl} currently does not support an integer hull operation\nand even if it did, it would be fairly expensive to compute.\nThe convex hull operation is supported, but it is also fairly\nexpensive to compute given only an implicit representation.\n\nUsually, it is not required to compute the exact integer hull,\nand an overapproximation of this hull is sufficient.\nThe ``simple hull'' of a set is such an overapproximation\nand it is defined as the (inclusion-wise) smallest basic set\nthat is described by constraints that are translates of\nthe constraints in the input set.\nThis means that the simple hull is relatively cheap to compute\nand that the number of constraints in the simple hull is no\nlarger than the number of constraints in the input.\n\\begin{definition}[Simple Hull of a Set]\nThe {\\em simple hull} of a set\n$S = \\bigcup_{1 \\le i \\le v} S_i$, with\n$$\nS : \\Z^n \\to 2^{\\Z^d} : \\vec s \\mapsto\nS(\\vec s) =\n\\left\\{\\, \\vec x \\in \\Z^d \\mid \\exists \\vec z \\in \\Z^e :\n\\bigvee_{1 \\le i \\le v}\nA_i \\vec x + B_i \\vec s + D_i \\vec z + \\vec c_i \\geq \\vec 0 \\,\\right\\}\n$$\nis the set\n$$\nH : \\Z^n \\to 2^{\\Z^d} : \\vec s \\mapsto\nS(\\vec s) =\n\\left\\{\\, \\vec x \\in \\Z^d \\mid \\exists \\vec z \\in \\Z^e :\n\\bigwedge_{1 \\le i \\le v}\nA_i \\vec x + B_i \\vec s + D_i \\vec z + \\vec c_i + \\vec K_i \\geq \\vec 0\n\\,\\right\\}\n,\n$$\nwith $\\vec K_i$ the (component-wise) smallest non-negative integer vectors\nsuch that $S \\subseteq H$.\n\\end{definition}\nThe $\\vec K_i$ can be obtained by solving a number of\nLP problems, one for each element of each $\\vec K_i$.\nIf any LP problem is unbounded, then the corresponding constraint\nis dropped.\n\n\\section{Parametric Integer Programming}\n\n\\subsection{Introduction}\\label{s:intro}\n\nParametric integer programming \\shortcite{Feautrier88parametric}\nis used to solve many problems within the context of the polyhedral model.\nHere, we are mainly interested in dependence analysis \\shortcite{Fea91}\nand in computing a unique representation for existentially quantified\nvariables.  The latter operation has been used for counting elements\nin sets involving such variables\n\\shortcite{BouletRe98,Verdoolaege2005experiences} and lies at the core\nof the internal representation of {\\tt isl}.\n\nParametric integer programming was first implemented in \\texttt{PipLib}.\nAn alternative method for parametric integer programming\nwas later implemented in {\\tt barvinok} \\cite{barvinok-0.22}.\nThis method is not based on Feautrier's algorithm, but on rational\ngenerating functions \\cite{Woods2003short} and was inspired by the\n``digging'' technique of \\shortciteN{DeLoera2004Three} for solving\nnon-parametric integer programming problems.\n\nIn the following sections, we briefly recall the dual simplex\nmethod combined with Gomory cuts and describe some extensions\nand optimizations.  The main algorithm is applied to a matrix\ndata structure known as a tableau.  In case of parametric problems,\nthere are two tableaus, one for the main problem and one for\nthe constraints on the parameters, known as the context tableau.\nThe handling of the context tableau is described in \\autoref{s:context}.\n\n\\subsection{The Dual Simplex Method}\n\nTableaus can be represented in several slightly different ways.\nIn {\\tt isl}, the dual simplex method uses the same representation\nas that used by its incremental LP solver based on the \\emph{primal}\nsimplex method.  The implementation of this LP solver is based\non that of {\\tt Simplify} \\shortcite{Detlefs2005simplify}, which, in turn,\nwas derived from the work of \\shortciteN{Nelson1980phd}.\nIn the original \\shortcite{Nelson1980phd}, the tableau was implemented\nas a sparse matrix, but neither {\\tt Simplify} nor the current\nimplementation of {\\tt isl} does so.\n\nGiven some affine constraints on the variables,\n$A \\vec x + \\vec b \\ge \\vec 0$, the tableau represents the relationship\nbetween the variables $\\vec x$ and non-negative variables\n$\\vec y = A \\vec x + \\vec b$ corresponding to the constraints.\nThe initial tableau contains $\\begin{pmatrix}\n\\vec b & A\n\\end{pmatrix}$ and expresses the constraints $\\vec y$ in the rows in terms\nof the variables $\\vec x$ in the columns.  The main operation defined\non a tableau exchanges a column and a row variable and is called a pivot.\nDuring this process, some coefficients may become rational.\nAs in the \\texttt{PipLib} implementation,\n{\\tt isl} maintains a shared denominator per row.\nThe sample value of a tableau is one where each column variable is assigned\nzero and each row variable is assigned the constant term of the row.\nThis sample value represents a valid solution if each constraint variable\nis assigned a non-negative value, i.e., if the constant terms of\nrows corresponding to constraints are all non-negative.\n\nThe dual simplex method starts from an initial sample value that\nmay be invalid, but that is known to be (lexicographically) no\ngreater than any solution, and gradually increments this sample value\nthrough pivoting until a valid solution is obtained.\nIn particular, each pivot exchanges a row variable\n$r = -n + \\sum_i a_i \\, c_i$ with negative\nsample value $-n$ with a column variable $c_j$\nsuch that $a_j > 0$.  Since $c_j = (n + r - \\sum_{i\\ne j} a_i \\, c_i)/a_j$,\nthe new row variable will have a positive sample value $n$.\nIf no such column can be found, then the problem is infeasible.\nBy always choosing the column that leads to the (lexicographically)\nsmallest increment in the variables $\\vec x$,\nthe first solution found is guaranteed to be the (lexicographically)\nminimal solution \\cite{Feautrier88parametric}.\nIn order to be able to determine the smallest increment, the tableau\nis (implicitly) extended with extra rows defining the original\nvariables in terms of the column variables.\nIf we assume that all variables are non-negative, then we know\nthat the zero vector is no greater than the minimal solution and\nthen the initial extended tableau looks as follows.\n$$\n\\begin{tikzpicture}\n\\matrix (m) [matrix of math nodes]\n{\n& {} & 1 & \\vec c \\\\\n\\vec x && |(top)| \\vec 0 & I \\\\\n\\vec r && \\vec b & |(bottom)|A \\\\\n};\n\\begin{pgfonlayer}{background}\n\\node (core) [inner sep=0pt,fill=black!20,right delimiter=),left delimiter=(,fit=(top)(bottom)] {};\n\\end{pgfonlayer}\n\\end{tikzpicture}\n$$\nEach column in this extended tableau is lexicographically positive\nand will remain so because of the column choice explained above.\nIt is then clear that the value of $\\vec x$ will increase in each step.\nNote that there is no need to store the extra rows explicitly.\nIf a given $x_i$ is a column variable, then the corresponding row\nis the unit vector $e_i$.  If, on the other hand, it is a row variable,\nthen the row already appears somewhere else in the tableau.\n\nIn case of parametric problems, the sign of the constant term\nmay depend on the parameters.  Each time the constant term of a constraint row\nchanges, we therefore need to check whether the new term can attain\nnegative and/or positive values over the current set of possible\nparameter values, i.e., the context.\nIf all these terms can only attain non-negative values, the current\nstate of the tableau represents a solution.  If one of the terms\ncan only attain non-positive values and is not identically zero,\nthe corresponding row can be pivoted.\nOtherwise, we pick one of the terms that can attain both positive\nand negative values and split the context into a part where\nit only attains non-negative values and a part where it only attains\nnegative values.\n\n\\subsection{Gomory Cuts}\n\nThe solution found by the dual simplex method may have\nnon-integral coordinates.  If so, some rational solutions\n(including the current sample value), can be cut off by\napplying a (parametric) Gomory cut.\nLet $r = b(\\vec p) + \\sp {\\vec a} {\\vec c}$ be the row\ncorresponding to the first non-integral coordinate of $\\vec x$,\nwith $b(\\vec p)$ the constant term, an affine expression in the\nparameters $\\vec p$, i.e., $b(\\vec p) = \\sp {\\vec f} {\\vec p} + g$.\nNote that only row variables can attain\nnon-integral values as the sample value of the column variables is zero.\nConsider the expression\n$b(\\vec p) - \\ceil{b(\\vec p)} + \\sp {\\fract{\\vec a}} {\\vec c}$,\nwith $\\ceil\\cdot$ the ceiling function and $\\fract\\cdot$ the\nfractional part.  This expression is negative at the sample value\nsince $\\vec c = \\vec 0$ and $r = b(\\vec p)$ is fractional, i.e.,\n$\\ceil{b(\\vec p)} > b(\\vec p)$.  On the other hand, for each integral\nvalue of $r$ and $\\vec c \\ge 0$, the expression is non-negative\nbecause $b(\\vec p) - \\ceil{b(\\vec p)} > -1$.\nImposing this expression to be non-negative therefore does not\ninvalidate any integral solutions, while it does cut away the current\nfractional sample value.  To be able to formulate this constraint,\na new variable $q = \\floor{-b(\\vec p)} = - \\ceil{b(\\vec p)}$ is added\nto the context.  This integral variable is uniquely defined by the constraints\n$0 \\le -d \\, b(\\vec p) - d \\, q \\le d - 1$, with $d$ the common\ndenominator of $\\vec f$ and $g$.  In practice, the variable\n$q' = \\floor{\\sp {\\fract{-f}} {\\vec p} + \\fract{-g}}$ is used instead\nand the coefficients of the new constraint are adjusted accordingly.\nThe sign of the constant term of this new constraint need not be determined\nas it is non-positive by construction.\nWhen several of these extra context variables are added, it is important\nto avoid adding duplicates.\nRecent versions of {\\tt PipLib} also check for such duplicates.\n\n\\subsection{Negative Unknowns and Maximization}\n\nThere are two places in the above algorithm where the unknowns $\\vec x$\nare assumed to be non-negative: the initial tableau starts from\nsample value $\\vec x = \\vec 0$ and $\\vec c$ is assumed to be non-negative\nduring the construction of Gomory cuts.\nTo deal with negative unknowns, \\shortciteN[Appendix A.2]{Fea91}\nproposed to use a ``big parameter'', say $M$, that is taken to be\nan arbitrarily large positive number.  Instead of looking for the\nlexicographically minimal value of $\\vec x$, we search instead\nfor the lexicographically minimal value of $\\vec x' = \\vec M + \\vec x$.\nThe sample value $\\vec x' = \\vec 0$ of the initial tableau then\ncorresponds to $\\vec x = -\\vec M$, which is clearly not greater than\nany potential solution.  The sign of the constant term of a row\nis determined lexicographically, with the coefficient of $M$ considered\nfirst.  That is, if the coefficient of $M$ is not zero, then its sign\nis the sign of the entire term.  Otherwise, the sign is determined\nby the remaining affine expression in the parameters.\nIf the original problem has a bounded optimum, then the final sample\nvalue will be of the form $\\vec M + \\vec v$ and the optimal value\nof the original problem is then $\\vec v$.\nMaximization problems can be handled in a similar way by computing\nthe minimum of $\\vec M - \\vec x$.\n\nWhen the optimum is unbounded, the optimal value computed for\nthe original problem will involve the big parameter.\nIn the original implementation of {\\tt PipLib}, the big parameter could\neven appear in some of the extra variables $\\vec q$ created during\nthe application of a Gomory cut.  The final result could then contain\nimplicit conditions on the big parameter through conditions on such\n$\\vec q$ variables.  This problem was resolved in later versions\nof {\\tt PipLib} by taking $M$ to be divisible by any positive number.\nThe big parameter can then never appear in any $\\vec q$ because\n$\\fract {\\alpha M } = 0$.  It should be noted, though, that an unbounded\nproblem usually (but not always)\nindicates an incorrect formulation of the problem.\n\nThe original version of {\\tt PipLib} required the user to ``manually''\nadd a big parameter, perform the reformulation and interpret the result\n\\shortcite{Feautrier02}.  Recent versions allow the user to simply\nspecify that the unknowns may be negative or that the maximum should\nbe computed and then these transformations are performed internally.\nAlthough there are some application, e.g.,\nthat of \\shortciteN{Feautrier92multi},\nwhere it is useful to have explicit control over the big parameter,\nnegative unknowns and maximization are by far the most common applications\nof the big parameter and we believe that the user should not be bothered\nwith such implementation issues.\nThe current version of {\\tt isl} therefore does not\nprovide any interface for specifying big parameters.  Instead, the user\ncan specify whether a maximum needs to be computed and no assumptions\nare made on the sign of the unknowns.  Instead, the sign of the unknowns\nis checked internally and a big parameter is automatically introduced when\nneeded.  For compatibility with {\\tt PipLib}, the {\\tt isl\\_pip} tool\ndoes explicitly add non-negativity constraints on the unknowns unless\nthe \\verb+Urs_unknowns+ option is specified.\nCurrently, there is also no way in {\\tt isl} of expressing a big\nparameter in the output.  Even though\n{\\tt isl} makes the same divisibility assumption on the big parameter\nas recent versions of {\\tt PipLib}, it will therefore eventually\nproduce an error if the problem turns out to be unbounded.\n\n\\subsection{Preprocessing}\n\nIn this section, we describe some transformations that are\nor can be applied in advance to reduce the running time\nof the actual dual simplex method with Gomory cuts.\n\n\\subsubsection{Feasibility Check and Detection of Equalities}\n\nExperience with the original {\\tt PipLib} has shown that Gomory cuts\ndo not perform very well on problems that are (non-obviously) empty,\ni.e., problems with rational solutions, but no integer solutions.\nIn {\\tt isl}, we therefore first perform a feasibility check on\nthe original problem considered as a non-parametric problem\nover the combined space of unknowns and parameters.\nIn fact, we do not simply check the feasibility, but we also\ncheck for implicit equalities among the integer points by computing\nthe integer affine hull.  The algorithm used is the same as that\ndescribed in \\autoref{s:GBR} below.\nComputing the affine hull is fairly expensive, but it can\nbring huge benefits if any equalities can be found or if the problem\nturns out to be empty.\n\n\\subsubsection{Constraint Simplification}\n\nIf the coefficients of the unknown and parameters in a constraint\nhave a common factor, then this factor should be removed, possibly\nrounding down the constant term.  For example, the constraint\n$2 x - 5 \\ge 0$ should be simplified to $x - 3 \\ge 0$.\n{\\tt isl} performs such simplifications on all sets and relations.\nRecent versions of {\\tt PipLib} also perform this simplification\non the input.\n\n\\subsubsection{Exploiting Equalities}\\label{s:equalities}\n\nIf there are any (explicit) equalities in the input description,\n{\\tt PipLib} converts each into a pair of inequalities.\nIt is also possible to write $r$ equalities as $r+1$ inequalities\n\\shortcite{Feautrier02}, but it is even better to \\emph{exploit} the\nequalities to reduce the dimensionality of the problem.\nGiven an equality involving at least one unknown, we pivot\nthe row corresponding to the equality with the column corresponding\nto the last unknown with non-zero coefficient.  The new column variable\ncan then be removed completely because it is identically zero,\nthereby reducing the dimensionality of the problem by one.\nThe last unknown is chosen to ensure that the columns of the initial\ntableau remain lexicographically positive.  In particular, if\nthe equality is of the form $b + \\sum_{i \\le j} a_i \\, x_i = 0$ with\n$a_j \\ne 0$, then the (implicit) top rows of the initial tableau\nare changed as follows\n$$\n\\begin{tikzpicture}\n\\matrix [matrix of math nodes]\n{\n & {} & |(top)| 0 & I_1 & |(j)| &  \\\\\nj && 0 & & 1 & \\\\\n  && 0 & & & |(bottom)|I_2 \\\\\n};\n\\node[overlay,above=2mm of j,anchor=south]{j};\n\\begin{pgfonlayer}{background}\n\\node (m) [inner sep=0pt,fill=black!20,right delimiter=),left delimiter=(,fit=(top)(bottom)] {};\n\\end{pgfonlayer}\n\\begin{scope}[xshift=4cm]\n\\matrix [matrix of math nodes]\n{\n & {} & |(top)| 0 & I_1 &  \\\\\nj && |(left)| -b/a_j & -a_i/a_j & \\\\\n  && 0 & & |(bottom)|I_2 \\\\\n};\n\\begin{pgfonlayer}{background}\n\\node (m2) [inner sep=0pt,fill=black!20,right delimiter=),left delimiter=(,fit=(top)(bottom)(left)] {};\n\\end{pgfonlayer}\n\\end{scope}\n \\draw [shorten >=7mm,-to,thick,decorate,\n        decoration={snake,amplitude=.4mm,segment length=2mm,\n                    pre=moveto,pre length=5mm,post length=8mm}]\n   (m) -- (m2);\n\\end{tikzpicture}\n$$\nCurrently, {\\tt isl} also eliminates equalities involving only parameters\nin a similar way, provided at least one of the coefficients is equal to one.\nThe application of parameter compression (see below)\nwould obviate the need for removing parametric equalities.\n\n\\subsubsection{Offline Symmetry Detection}\\label{s:offline}\n\nSome problems, notably those of \\shortciteN{Bygde2010licentiate},\nhave a collection of constraints, say\n$b_i(\\vec p) + \\sp {\\vec a} {\\vec x} \\ge 0$,\nthat only differ in their (parametric) constant terms.\nThese constant terms will be non-negative on different parts\nof the context and this context may have to be split for each\nof the constraints.  In the worst case, the basic algorithm may\nhave to consider all possible orderings of the constant terms.\nInstead, {\\tt isl} introduces a new parameter, say $u$, and\nreplaces the collection of constraints by the single\nconstraint $u + \\sp {\\vec a} {\\vec x} \\ge 0$ along with\ncontext constraints $u \\le b_i(\\vec p)$.\nAny solution to the new system is also a solution\nto the original system since\n$\\sp {\\vec a} {\\vec x} \\ge -u \\ge -b_i(\\vec p)$.\nConversely, $m = \\min_i b_i(\\vec p)$ satisfies the constraints\non $u$ and therefore extends a solution to the new system.\nIt can also be plugged into a new solution.\nSee \\autoref{s:post} for how this substitution is currently performed\nin {\\tt isl}.\nThe method described in this section can only detect symmetries\nthat are explicitly available in the input.\nSee \\autoref{s:online} for the detection\nand exploitation of symmetries that appear during the course of\nthe dual simplex method.\n\n\\subsubsection{Parameter Compression}\\label{s:compression}\n\nIt may in some cases be apparent from the equalities in the problem\ndescription that there can only be a solution for a sublattice\nof the parameters.  In such cases ``parameter compression''\n\\shortcite{Meister2004PhD,Meister2008} can be used to replace\nthe parameters by alternative ``dense'' parameters.\nFor example, if there is a constraint $2x = n$, then the system\nwill only have solutions for even values of $n$ and $n$ can be replaced\nby $2n'$.  Similarly, the parameters $n$ and $m$ in a system with\nthe constraint $2n = 3m$ can be replaced by a single parameter $n'$\nwith $n=3n'$ and $m=2n'$.\nIt is also possible to perform a similar compression on the unknowns,\nbut it would be more complicated as the compression would have to\npreserve the lexicographical order.  Moreover, due to our handling\nof equalities described above there should be\nno need for such variable compression.\nAlthough parameter compression has been implemented in {\\tt isl},\nit is currently not yet used during parametric integer programming.\n\n\\subsection{Postprocessing}\\label{s:post}\n\nThe output of {\\tt PipLib} is a quast (quasi-affine selection tree).\nEach internal node in this tree corresponds to a split of the context\nbased on a parametric constant term in the main tableau with indeterminate\nsign.  Each of these nodes may introduce extra variables in the context\ncorresponding to integer divisions.  Each leaf of the tree prescribes\nthe solution in that part of the context that satisfies all the conditions\non the path leading to the leaf.\nSuch a quast is a very economical way of representing the solution, but\nit would not be suitable as the (only) internal representation of\nsets and relations in {\\tt isl}.  Instead, {\\tt isl} represents\nthe constraints of a set or relation in disjunctive normal form.\nThe result of a parametric integer programming problem is then also\nconverted to this internal representation.  Unfortunately, the conversion\nto disjunctive normal form can lead to an explosion of the size\nof the representation.\nIn some cases, this overhead would have to be paid anyway in subsequent\noperations, but in other cases, especially for outside users that just\nwant to solve parametric integer programming problems, we would like\nto avoid this overhead in future.  That is, we are planning on introducing\nquasts or a related representation as one of several possible internal\nrepresentations and on allowing the output of {\\tt isl\\_pip} to optionally\nbe printed as a quast.\n\nCurrently, {\\tt isl} also does not have an internal representation\nfor expressions such as $\\min_i b_i(\\vec p)$ from the offline\nsymmetry detection of \\autoref{s:offline}.\nAssume that one of these expressions has $n$ bounds $b_i(\\vec p)$.\nIf the expression\ndoes not appear in the affine expression describing the solution,\nbut only in the constraints, and if moreover, the expression\nonly appears with a positive coefficient, i.e.,\n$\\min_i b_i(\\vec p) \\ge f_j(\\vec p)$, then each of these constraints\ncan simply be reduplicated $n$ times, once for each of the bounds.\nOtherwise, a conversion to disjunctive normal form\nleads to $n$ cases, each described as $u = b_i(\\vec p)$ with constraints\n$b_i(\\vec p) \\le b_j(\\vec p)$ for $j > i$\nand\n$b_i(\\vec p)  < b_j(\\vec p)$ for $j < i$.\nNote that even though this conversion leads to a size increase\nby a factor of $n$, not detecting the symmetry could lead to\nan increase by a factor of $n!$ if all possible orderings end up being\nconsidered.\n\n\\subsection{Context Tableau}\\label{s:context}\n\nThe main operation that a context tableau needs to provide is a test\non the sign of an affine expression over the elements of the context.\nThis sign can be determined by solving two integer linear feasibility\nproblems, one with a constraint added to the context that enforces\nthe expression to be non-negative and one where the expression is\nnegative.  As already mentioned by \\shortciteN{Feautrier88parametric},\nany integer linear feasibility solver could be used, but the {\\tt PipLib}\nimplementation uses a recursive call to the dual simplex with Gomory\ncuts algorithm to determine the feasibility of a context.\nIn {\\tt isl}, two ways of handling the context have been implemented,\none that performs the recursive call and one, used by default, that\nuses generalized basis reduction.\nWe start with some optimizations that are shared between the two\nimplementations and then discuss additional details of each of them.\n\n\\subsubsection{Maintaining Witnesses}\\label{s:witness}\n\nA common feature of both integer linear feasibility solvers is that\nthey will not only say whether a set is empty or not, but if the set\nis non-empty, they will also provide a \\emph{witness} for this result,\ni.e., a point that belongs to the set.  By maintaining a list of such\nwitnesses, we can avoid many feasibility tests during the determination\nof the signs of affine expressions.  In particular, if the expression\nevaluates to a positive number on some of these points and to a negative\nnumber on some others, then no feasibility test needs to be performed.\nIf all the evaluations are non-negative, we only need to check for the\npossibility of a negative value and similarly in case of all\nnon-positive evaluations.  Finally, in the rare case that all points\nevaluate to zero or at the start, when no points have been collected yet,\none or two feasibility tests need to be performed depending on the result\nof the first test.\n\nWhen a new constraint is added to the context, the points that\nviolate the constraint are temporarily removed.  They are reconsidered\nwhen we backtrack over the addition of the constraint, as they will\nsatisfy the negation of the constraint.  It is only when we backtrack\nover the addition of the points that they are finally removed completely.\nWhen an extra integer division is added to the context,\nthe new coordinates of the\nwitnesses can easily be computed by evaluating the integer division.\nThe idea of keeping track of witnesses was first used in {\\tt barvinok}.\n\n\\subsubsection{Choice of Constant Term on which to Split}\n\nRecall that if there are no rows with a non-positive constant term,\nbut there are rows with an indeterminate sign, then the context\nneeds to be split along the constant term of one of these rows.\nIf there is more than one such row, then we need to choose which row\nto split on first.  {\\tt PipLib} uses a heuristic based on the (absolute)\nsizes of the coefficients.  In particular, it takes the largest coefficient\nof each row and then selects the row where this largest coefficient is smaller\nthan those of the other rows.\n\nIn {\\tt isl}, we take that row for which non-negativity of its constant\nterm implies non-negativity of as many of the constant terms of the other\nrows as possible.  The intuition behind this heuristic is that on the\npositive side, we will have fewer negative and indeterminate signs,\nwhile on the negative side, we need to perform a pivot, which may\naffect any number of rows meaning that the effect on the signs\nis difficult to predict.  This heuristic is of course much more\nexpensive to evaluate than the heuristic used by {\\tt PipLib}.\nMore extensive tests are needed to evaluate whether the heuristic is worthwhile.\n\n\\subsubsection{Dual Simplex + Gomory Cuts}\n\nWhen a new constraint is added to the context, the first steps\nof the dual simplex method applied to this new context will be the same\nor at least very similar to those taken on the original context, i.e.,\nbefore the constraint was added.  In {\\tt isl}, we therefore apply\nthe dual simplex method incrementally on the context and backtrack\nto a previous state when a constraint is removed again.\nAn initial implementation that was never made public would also\nkeep the Gomory cuts, but the current implementation backtracks\nto before the point where Gomory cuts are added before adding\nan extra constraint to the context.\nKeeping the Gomory cuts has the advantage that the sample value\nis always an integer point and that this point may also satisfy\nthe new constraint.  However, due to the technique of maintaining\nwitnesses explained above,\nwe would not perform a feasibility test in such cases and then\nthe previously added cuts may be redundant, possibly resulting\nin an accumulation of a large number of cuts.\n\nIf the parameters may be negative, then the same big parameter trick\nused in the main tableau is applied to the context.  This big parameter\nis of course unrelated to the big parameter from the main tableau.\nNote that it is not a requirement for this parameter to be ``big'',\nbut it does allow for some code reuse in {\\tt isl}.\nIn {\\tt PipLib}, the extra parameter is not ``big'', but this may be because\nthe big parameter of the main tableau also appears\nin the context tableau.\n\nFinally, it was reported by \\shortciteN{Galea2009personal}, who\nworked on a parametric integer programming implementation\nin {\\tt PPL} \\shortcite{PPL},\nthat it is beneficial to add cuts for \\emph{all} rational coordinates\nin the context tableau.  Based on this report,\nthe initial {\\tt isl} implementation was adapted accordingly.\n\n\\subsubsection{Generalized Basis Reduction}\\label{s:GBR}\n\nThe default algorithm used in {\\tt isl} for feasibility checking\nis generalized basis reduction \\shortcite{Cook1991implementation}.\nThis algorithm is also used in the {\\tt barvinok} implementation.\nThe algorithm is fairly robust, but it has some overhead.\nWe therefore try to avoid calling the algorithm in easy cases.\nIn particular, we incrementally keep track of points for which\nthe entire unit hypercube positioned at that point lies in the context.\nThis set is described by translates of the constraints of the context\nand if (rationally) non-empty, any rational point\nin the set can be rounded up to yield an integer point in the context.\n\nA restriction of the algorithm is that it only works on bounded sets.\nThe affine hull of the recession cone therefore needs to be projected\nout first.  As soon as the algorithm is invoked, we then also\nincrementally keep track of this recession cone.  The reduced basis\nfound by one call of the algorithm is also reused as initial basis\nfor the next call.\n\nSome problems lead to the\nintroduction of many integer divisions.  Within a given context,\nsome of these integer divisions may be equal to each other, even\nif the expressions are not identical, or they may be equal to some\naffine combination of other variables.\nTo detect such cases, we compute the affine hull of the context\neach time a new integer division is added.  The algorithm used\nfor computing this affine hull is that of \\shortciteN{Karr1976affine},\nwhile the points used in this algorithm are obtained by performing\ninteger feasibility checks on that part of the context outside\nthe current approximation of the affine hull.\nThe list of witnesses is used to construct an initial approximation\nof the hull, while any extra points found during the construction\nof the hull is added to this list.\nAny equality found in this way that expresses an integer division\nas an \\emph{integer} affine combination of other variables is\npropagated to the main tableau, where it is used to eliminate that\ninteger division.\n\n\\subsection{Experiments}\n\n\\autoref{t:comparison} compares the execution times of {\\tt isl}\n(with both types of context tableau)\non some more difficult instances to those of other tools,\nrun on an Intel Xeon W3520 @ 2.66GHz.\nEasier problems such as the\ntest cases distributed with {\\tt Pip\\-Lib} can be solved so quickly\nthat we would only be measuring overhead such as input/output and conversions\nand not the running time of the actual algorithm.\nWe compare the following versions:\n{\\tt piplib-1.4.0-5-g0132fd9},\n{\\tt barvinok-0.32.1-73-gc5d7751},\n{\\tt isl-0.05.1-82-g3a37260}\nand {\\tt PPL} version 0.11.2.\n\nThe first test case is the following dependence analysis problem\noriginating from the Phideo project \\shortcite{Verhaegh1995PhD}\nthat was communicated to us by Bart Kienhuis:\n\\begin{lstlisting}[flexiblecolumns=true,breaklines=true]{}\nlexmax { [j1,j2] -> [i1,i2,i3,i4,i5,i6,i7,i8,i9,i10] : 1 <= i1,j1 <= 8 and 1 <= i2,i3,i4,i5,i6,i7,i8,i9,i10 <= 2 and 1 <= j2 <= 128 and i1-1 = j1-1 and i2-1+2*i3-2+4*i4-4+8*i5-8+16*i6-16+32*i7-32+64*i8-64+128*i9-128+256*i10-256=3*j2-3+66 };\n\\end{lstlisting}\nThis problem was the main inspiration\nfor some of the optimizations in \\autoref{s:GBR}.\nThe second group of test cases are projections used during counting.\nThe first nine of these come from \\shortciteN{Seghir2006minimizing}.\nThe remaining two come from \\shortciteN{Verdoolaege2005experiences} and\nwere used to drive the first, Gomory cuts based, implementation\nin {\\tt isl}.\nThe third and final group of test cases are borrowed from\n\\shortciteN{Bygde2010licentiate} and inspired the offline symmetry detection\nof \\autoref{s:offline}.  Without symmetry detection, the running times\nare 11s and 5.9s.\nAll running times of {\\tt barvinok} and {\\tt isl} include a conversion\nto disjunctive normal form.  Without this conversion, the final two\ncases can be solved in 0.07s and 0.21s.\nThe {\\tt PipLib} implementation has some fixed limits and will\nsometimes report the problem to be too complex (TC), while on some other\nproblems it will run out of memory (OOM).\nThe {\\tt barvinok} implementation does not support problems\nwith a non-trivial lineality space (line) nor maximization problems (max).\nThe Gomory cuts based {\\tt isl} implementation was terminated after 1000\nminutes on the first problem.  The gbr version introduces some\noverhead on some of the easier problems, but is overall the clear winner.\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{lrrrrr}\n    & {\\tt PipLib} & {\\tt barvinok} & {\\tt isl} cut & {\\tt isl} gbr & {\\tt PPL} \\\\\n\\hline\n\\hline\n% bart.pip\nPhideo & TC    & 793m   & $>$999m &   2.7s  & 372m \\\\\n\\hline\ne1 & 0.33s & 3.5s & 0.08s & 0.11s & 0.18s \\\\\ne3 & 0.14s & 0.13s & 0.10s & 0.10s & 0.17s \\\\\ne4 & 0.24s & 9.1s & 0.09s & 0.11s & 0.70s \\\\\ne5 & 0.12s & 6.0s & 0.06s & 0.14s & 0.17s \\\\\ne6 & 0.10s & 6.8s & 0.17s & 0.08s & 0.21s \\\\\ne7 & 0.03s & 0.27s & 0.04s & 0.04s & 0.03s \\\\\ne8 & 0.03s & 0.18s & 0.03s & 0.04s & 0.01s \\\\\ne9 & OOM & 70m & 2.6s & 0.94s & 22s \\\\\nvd & 0.04s & 0.10s & 0.03s & 0.03s & 0.03s \\\\\nbouleti & 0.25s & line & 0.06s & 0.06s & 0.15s \\\\\ndifficult & OOM & 1.3s & 1.7s & 0.33s & 1.4s \\\\\n\\hline\ncnt/sum & TC & max & 2.2s & 2.2s & OOM \\\\\njcomplex & TC & max & 3.7s & 3.9s & OOM \\\\\n\\end{tabular}\n\\caption{Comparison of Execution Times}\n\\label{t:comparison}\n\\end{center}\n\\end{table}\n\n\\subsection{Online Symmetry Detection}\\label{s:online}\n\nManual experiments on small instances of the problems of\n\\shortciteN{Bygde2010licentiate} and an analysis of the results\nby the approximate MPA method developed by \\shortciteN{Bygde2010licentiate}\nhave revealed that these problems contain many more symmetries\nthan can be detected using the offline method of \\autoref{s:offline}.\nIn this section, we present an online detection mechanism that has\nnot been implemented yet, but that has shown promising results\nin manual applications.\n\nLet us first consider what happens when we do not perform offline\nsymmetry detection.  At some point, one of the\n$b_i(\\vec p) + \\sp {\\vec a} {\\vec x} \\ge 0$ constraints,\nsay the $j$th constraint, appears as a column\nvariable, say $c_1$, while the other constraints are represented\nas rows of the form $b_i(\\vec p) - b_j(\\vec p) + c$.\nThe context is then split according to the relative order of\n$b_j(\\vec p)$ and one of the remaining $b_i(\\vec p)$.\nThe offline method avoids this split by replacing all $b_i(\\vec p)$\nby a single newly introduced parameter that represents the minimum\nof these $b_i(\\vec p)$.\nIn the online method the split is similarly avoided by the introduction\nof a new parameter.  In particular, a new parameter is introduced\nthat represents\n$\\left| b_j(\\vec p) - b_i(\\vec p) \\right|_+ =\n\\max(b_j(\\vec p) - b_i(\\vec p), 0)$.\n\nIn general, let $r = b(\\vec p) + \\sp {\\vec a} {\\vec c}$ be a row\nof the tableau such that the sign of $b(\\vec p)$ is indeterminate\nand such that exactly one of the elements of $\\vec a$ is a $1$,\nwhile all remaining elements are non-positive.\nThat is, $r = b(\\vec p) + c_j - f$ with $f = -\\sum_{i\\ne j} a_i c_i \\ge 0$.\nWe introduce a new parameter $t$ with\ncontext constraints $t \\ge -b(\\vec p)$ and $t \\ge 0$ and replace\nthe column variable $c_j$ by $c' + t$.  The row $r$ is now equal\nto $b(\\vec p) + t + c' - f$.  The constant term of this row is always\nnon-negative because any negative value of $b(\\vec p)$ is compensated\nby $t \\ge -b(\\vec p)$ while and non-negative value remains non-negative\nbecause $t \\ge 0$.\n\nWe need to show that this transformation does not eliminate any valid\nsolutions and that it does not introduce any spurious solutions.\nGiven a valid solution for the original problem, we need to find\na non-negative value of $c'$ satisfying the constraints.\nIf $b(\\vec p) \\ge 0$, we can take $t = 0$ so that\n$c' = c_j - t = c_j \\ge 0$.\nIf $b(\\vec p) < 0$, we can take $t = -b(\\vec p)$.\nSince $r = b(\\vec p) + c_j - f \\ge 0$ and $f \\ge 0$, we have \n$c' = c_j + b(\\vec p) \\ge 0$.\nNote that these choices amount to plugging in\n$t = \\left|-b(\\vec p)\\right|_+ = \\max(-b(\\vec p), 0)$.\nConversely, given a solution to the new problem, we need to find\na non-negative value of $c_j$, but this is easy since $c_j = c' + t$\nand both of these are non-negative.\n\nPlugging in $t = \\max(-b(\\vec p), 0)$ can be performed as in\n\\autoref{s:post}, but, as in the case of offline symmetry detection,\nit may be better to provide a direct representation for such\nexpressions in the internal representation of sets and relations\nor at least in a quast-like output format.\n\n\\section{Coalescing}\\label{s:coalescing}\n\nSee \\shortciteN{Verdoolaege2009isl}, for now.\nMore details will be added later.\n\n\\section{Transitive Closure}\n\n\\subsection{Introduction}\n\n\\begin{definition}[Power of a Relation]\nLet $R \\in \\Z^n \\to 2^{\\Z^{d+d}}$ be a relation and\n$k \\in \\Z_{\\ge 1}$\na positive number, then power $k$ of relation $R$ is defined as\n\\begin{equation}\n\\label{eq:transitive:power}\nR^k \\coloneqq\n\\begin{cases}\nR & \\text{if $k = 1$}\n\\\\\nR \\circ R^{k-1} & \\text{if $k \\ge 2$}\n.\n\\end{cases}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Transitive Closure of a Relation]\nLet $R \\in \\Z^n \\to 2^{\\Z^{d+d}}$ be a relation,\nthen the transitive closure $R^+$ of $R$ is the union\nof all positive powers of $R$,\n$$\nR^+ \\coloneqq \\bigcup_{k \\ge 1} R^k\n.\n$$\n\\end{definition}\nAlternatively, the transitive closure may be defined\ninductively as\n\\begin{equation}\n\\label{eq:transitive:inductive}\nR^+ \\coloneqq R \\cup \\left(R \\circ R^+\\right)\n.\n\\end{equation}\n\nSince the transitive closure of a polyhedral relation\nmay no longer be a polyhedral relation \\shortcite{Kelly1996closure},\nwe can, in the general case, only compute an approximation\nof the transitive closure.\nWhereas \\shortciteN{Kelly1996closure} compute underapproximations,\nwe, like \\shortciteN{Beletska2009}, compute overapproximations.\nThat is, given a relation $R$, we will compute a relation $T$\nsuch that $R^+ \\subseteq T$.  Of course, we want this approximation\nto be as close as possible to the actual transitive closure\n$R^+$ and we want to detect the cases where the approximation is\nexact, i.e., where $T = R^+$.\n\nFor computing an approximation of the transitive closure of $R$,\nwe follow the same general strategy as \\shortciteN{Beletska2009}\nand first compute an approximation of $R^k$ for $k \\ge 1$ and then project\nout the parameter $k$ from the resulting relation.\n\n\\begin{example}\nAs a trivial example, consider the relation\n$R = \\{\\, x \\to x + 1 \\,\\}$.  The $k$th power of this map\nfor arbitrary $k$ is\n$$\nR^k = k \\mapsto \\{\\, x \\to x + k \\mid k \\ge 1 \\,\\}\n.\n$$\nThe transitive closure is then\n$$\n\\begin{aligned}\nR^+ & = \\{\\, x \\to y \\mid \\exists k \\in \\Z_{\\ge 1} : y = x + k \\,\\}\n\\\\\n& = \\{\\, x \\to y \\mid y \\ge x + 1 \\,\\}\n.\n\\end{aligned}\n$$\n\\end{example}\n\n\\subsection{Computing an Approximation of $R^k$}\n\\label{s:power}\n\nThere are some special cases where the computation of $R^k$ is very easy.\nOne such case is that where $R$ does not compose with itself,\ni.e., $R \\circ R = \\emptyset$ or $\\domain R \\cap \\range R = \\emptyset$.\nIn this case, $R^k$ is only non-empty for $k=1$ where it is equal\nto $R$ itself.\n\nIn general, it is impossible to construct a closed form\nof $R^k$ as a polyhedral relation.\nWe will therefore need to make some approximations.\nAs a first approximations, we will consider each of the basic\nrelations in $R$ as simply adding one or more offsets to a domain element\nto arrive at an image element and ignore the fact that some of these\noffsets may only be applied to some of the domain elements.\nThat is, we will only consider the difference set $\\Delta\\,R$ of the relation.\nIn particular, we will first construct a collection $P$ of paths\nthat move through\na total of $k$ offsets and then intersect domain and range of this\ncollection with those of $R$.\nThat is, \n\\begin{equation}\n\\label{eq:transitive:approx}\nK = P \\cap \\left(\\domain R \\to \\range R\\right)\n,\n\\end{equation}\nwith\n\\begin{equation}\n\\label{eq:transitive:path}\nP = \\vec s \\mapsto \\{\\, \\vec x \\to \\vec y \\mid\n\\exists k_i \\in \\Z_{\\ge 0}, \\vec\\delta_i \\in k_i \\, \\Delta_i(\\vec s) :\n\\vec y = \\vec x + \\sum_i \\vec\\delta_i\n\\wedge\n\\sum_i k_i = k > 0\n\\,\\}\n\\end{equation}\nand with $\\Delta_i$ the basic sets that compose\nthe difference set $\\Delta\\,R$.\nNote that the number of basic sets $\\Delta_i$ need not be\nthe same as the number of basic relations in $R$.\nAlso note that since addition is commutative, it does not\nmatter in which order we add the offsets and so we are allowed\nto group them as we did in \\eqref{eq:transitive:path}.\n\nIf all the $\\Delta_i$s are singleton sets\n$\\Delta_i = \\{\\, \\vec \\delta_i \\,\\}$ with $\\vec \\delta_i \\in \\Z^d$,\nthen \\eqref{eq:transitive:path} simplifies to\n\\begin{equation}\n\\label{eq:transitive:singleton}\nP = \\{\\, \\vec x \\to \\vec y \\mid\n\\exists k_i \\in \\Z_{\\ge 0} :\n\\vec y = \\vec x + \\sum_i k_i \\, \\vec \\delta_i\n\\wedge\n\\sum_i k_i = k > 0\n\\,\\}\n\\end{equation}\nand then the approximation computed in \\eqref{eq:transitive:approx}\nis essentially the same as that of \\shortciteN{Beletska2009}.\nIf some of the $\\Delta_i$s are not singleton sets or if\nsome of $\\vec \\delta_i$s are parametric, then we need\nto resort to further approximations.\n\nTo ease both the exposition and the implementation, we will for\nthe remainder of this section work with extended offsets\n$\\Delta_i' = \\Delta_i \\times \\{\\, 1 \\,\\}$.\nThat is, each offset is extended with an extra coordinate that is\nset equal to one.  The paths constructed by summing such extended\noffsets have the length encoded as the difference of their\nfinal coordinates.  The path $P'$ can then be decomposed into\npaths $P_i'$, one for each $\\Delta_i$,\n\\begin{equation}\n\\label{eq:transitive:decompose}\nP' = \\left(\n(P_m' \\cup \\identity) \\circ \\cdots \\circ\n(P_2' \\cup \\identity) \\circ\n(P_1' \\cup \\identity)\n\\right) \\cap\n\\{\\,\n\\vec x' \\to \\vec y' \\mid y_{d+1} - x_{d+1} = k > 0\n\\,\\}\n,\n\\end{equation}\nwith\n$$\nP_i' = \\vec s \\mapsto \\{\\, \\vec x' \\to \\vec y' \\mid\n\\exists k \\in \\Z_{\\ge 1}, \\vec \\delta \\in k \\, \\Delta_i'(\\vec s) :\n\\vec y' = \\vec x' + \\vec \\delta\n\\,\\}\n.\n$$\nNote that each $P_i'$ contains paths of length at least one.\nWe therefore need to take the union with the identity relation\nwhen composing the $P_i'$s to allow for paths that do not contain\nany offsets from one or more $\\Delta_i'$.\nThe path that consists of only identity relations is removed\nby imposing the constraint $y_{d+1} - x_{d+1} > 0$.\nTaking the union with the identity relation means that\nthat the relations we compose in \\eqref{eq:transitive:decompose}\neach consist of two basic relations.  If there are $m$\ndisjuncts in the input relation, then a direct application\nof the composition operation may therefore result in a relation\nwith $2^m$ disjuncts, which is prohibitively expensive.\nIt is therefore crucial to apply coalescing (\\autoref{s:coalescing})\nafter each composition.\n\nLet us now consider how to compute an overapproximation of $P_i'$.\nThose that correspond to singleton $\\Delta_i$s are grouped together\nand handled as in \\eqref{eq:transitive:singleton}.\nNote that this is just an optimization.  The procedure described\nbelow would produce results that are at least as accurate.\nFor simplicity, we first assume that no constraint in $\\Delta_i'$\ninvolves any existentially quantified variables.\nWe will return to existentially quantified variables at the end\nof this section.\nWithout existentially quantified variables, we can classify\nthe constraints of $\\Delta_i'$ as follows\n\\begin{enumerate}\n\\item non-parametric constraints\n\\begin{equation}\n\\label{eq:transitive:non-parametric}\nA_1 \\vec x + \\vec c_1 \\geq \\vec 0\n\\end{equation}\n\\item purely parametric constraints\n\\begin{equation}\n\\label{eq:transitive:parametric}\nB_2 \\vec s + \\vec c_2 \\geq \\vec 0\n\\end{equation}\n\\item negative mixed constraints\n\\begin{equation}\n\\label{eq:transitive:mixed}\nA_3 \\vec x + B_3 \\vec s + \\vec c_3 \\geq \\vec 0\n\\end{equation}\nsuch that for each row $j$ and for all $\\vec s$,\n$$\n\\Delta_i'(\\vec s) \\cap\n\\{\\, \\vec \\delta' \\mid B_{3,j} \\vec s + c_{3,j} > 0 \\,\\}\n= \\emptyset\n$$\n\\item positive mixed constraints\n$$\nA_4 \\vec x + B_4 \\vec s + \\vec c_4 \\geq \\vec 0\n$$\nsuch that for each row $j$, there is at least one $\\vec s$ such that\n$$\n\\Delta_i'(\\vec s) \\cap\n\\{\\, \\vec \\delta' \\mid B_{4,j} \\vec s + c_{4,j} > 0 \\,\\}\n\\ne \\emptyset\n$$\n\\end{enumerate}\nWe will use the following approximation $Q_i$ for $P_i'$:\n\\begin{equation}\n\\label{eq:transitive:Q}\n\\begin{aligned}\nQ_i = \\vec s \\mapsto\n\\{\\,\n\\vec x' \\to \\vec y'\n\\mid {} & \\exists k \\in \\Z_{\\ge 1}, \\vec f \\in \\Z^d :\n\\vec y' = \\vec x' + (\\vec f, k)\n\\wedge {}\n\\\\\n&\nA_1 \\vec f + k \\vec c_1 \\geq \\vec 0\n\\wedge\nB_2 \\vec s + \\vec c_2 \\geq \\vec 0\n\\wedge\nA_3 \\vec f + B_3 \\vec s + \\vec c_3 \\geq \\vec 0\n\\,\\}\n.\n\\end{aligned}\n\\end{equation}\nTo prove that $Q_i$ is indeed an overapproximation of $P_i'$,\nwe need to show that for every $\\vec s \\in \\Z^n$, for every\n$k \\in \\Z_{\\ge 1}$ and for every $\\vec f \\in k \\, \\Delta_i(\\vec s)$\nwe have that\n$(\\vec f, k)$ satisfies the constraints in \\eqref{eq:transitive:Q}.\nIf $\\Delta_i(\\vec s)$ is non-empty, then $\\vec s$ must satisfy\nthe constraints in \\eqref{eq:transitive:parametric}.\nEach element $(\\vec f, k) \\in k \\, \\Delta_i'(\\vec s)$ is a sum\nof $k$ elements $(\\vec f_j, 1)$ in $\\Delta_i'(\\vec s)$.\nEach of these elements satisfies the constraints in\n\\eqref{eq:transitive:non-parametric}, i.e.,\n$$\n\\left[\n\\begin{matrix}\nA_1 & \\vec c_1\n\\end{matrix}\n\\right]\n\\left[\n\\begin{matrix}\n\\vec f_j \\\\ 1\n\\end{matrix}\n\\right]\n\\ge \\vec 0\n.\n$$\nThe sum of these elements therefore satisfies the same set of inequalities,\ni.e., $A_1 \\vec f + k \\vec c_1 \\geq \\vec 0$.\nFinally, the constraints in \\eqref{eq:transitive:mixed} are such\nthat for any $\\vec s$ in the parameter domain of $\\Delta$,\nwe have $-\\vec r(\\vec s) \\coloneqq B_3 \\vec s + \\vec c_3 \\le \\vec 0$,\ni.e., $A_3 \\vec f_j \\ge \\vec r(\\vec s) \\ge \\vec 0$\nand therefore also $A_3 \\vec f \\ge \\vec r(\\vec s)$.\nNote that if there are no mixed constraints and if the\nrational relaxation of $\\Delta_i(\\vec s)$, i.e.,\n$\\{\\, \\vec x \\in \\Q^d \\mid A_1 \\vec x + \\vec c_1 \\ge \\vec 0\\,\\}$,\nhas integer vertices, then the approximation is exact, i.e.,\n$Q_i = P_i'$.  In this case, the vertices of $\\Delta'_i(\\vec s)$\ngenerate the rational cone\n$\\{\\, \\vec x' \\in \\Q^{d+1} \\mid \\left[\n\\begin{matrix}\nA_1 & \\vec c_1\n\\end{matrix}\n\\right] \\vec x' \\,\\}$ and therefore $\\Delta'_i(\\vec s)$ is\na Hilbert basis of this cone \\shortcite[Theorem~16.4]{Schrijver1986}.\n\nNote however that, as pointed out by \\shortciteN{DeSmet2010personal},\nif there \\emph{are} any mixed constraints, then the above procedure may\nnot compute the most accurate affine approximation of\n$k \\, \\Delta_i(\\vec s)$ with $k \\ge 1$.\nIn particular, we only consider the negative mixed constraints that\nhappen to appear in the description of $\\Delta_i(\\vec s)$, while we\nshould instead consider \\emph{all} valid such constraints.\nIt is also sufficient to consider those constraints because any\nconstraint that is valid for $k \\, \\Delta_i(\\vec s)$ is also\nvalid for $1 \\, \\Delta_i(\\vec s) = \\Delta_i(\\vec s)$.\nTake therefore any constraint\n$\\spv a x + \\spv b s + c \\ge 0$ valid for $\\Delta_i(\\vec s)$.\nThis constraint is also valid for $k \\, \\Delta_i(\\vec s)$ iff\n$k \\, \\spv a x + \\spv b s + c \\ge 0$.\nIf $\\spv b s + c$ can attain any positive value, then $\\spv a x$\nmay be negative for some elements of $\\Delta_i(\\vec s)$.\nWe then have $k \\, \\spv a x < \\spv a x$ for $k > 1$ and so the constraint\nis not valid for $k \\, \\Delta_i(\\vec s)$.\nWe therefore need to impose $\\spv b s + c \\le 0$ for all values\nof $\\vec s$ such that $\\Delta_i(\\vec s)$ is non-empty, i.e.,\n$\\vec b$ and $c$ need to be such that $- \\spv b s - c \\ge 0$ is a valid\nconstraint of $\\Delta_i(\\vec s)$.  That is, $(\\vec b, c)$ are the opposites\nof the coefficients of a valid constraint of $\\Delta_i(\\vec s)$.\nThe approximation of $k \\, \\Delta_i(\\vec s)$ can therefore be obtained\nusing three applications of Farkas' lemma.  The first obtains the coefficients\nof constraints valid for $\\Delta_i(\\vec s)$.  The second obtains\nthe coefficients of constraints valid for the projection of $\\Delta_i(\\vec s)$\nonto the parameters.  The opposite of the second set is then computed\nand intersected with the first set.  The result is the set of coefficients\nof constraints valid for $k \\, \\Delta_i(\\vec s)$.  A final application\nof Farkas' lemma is needed to obtain the approximation of\n$k \\, \\Delta_i(\\vec s)$ itself.\n\n\\begin{example}\nConsider the relation\n$$\nn \\to \\{\\, (x, y) \\to (1 + x, 1 - n + y) \\mid n \\ge 2 \\,\\}\n.\n$$\nThe difference set of this relation is\n$$\n\\Delta = n \\to \\{\\, (1, 1 - n) \\mid n \\ge 2 \\,\\}\n.\n$$\nUsing our approach, we would only consider the mixed constraint\n$y - 1 + n \\ge 0$, leading to the following approximation of the\ntransitive closure:\n$$\nn \\to \\{\\, (x, y) \\to (o_0, o_1) \\mid n \\ge 2 \\wedge o_1 \\le 1 - n + y \\wedge o_0 \\ge 1 + x \\,\\}\n.\n$$\nIf, instead, we apply Farkas's lemma to $\\Delta$, i.e.,\n\\begin{verbatim}\nD := [n] -> { [1, 1 - n] : n >= 2 };\nCD := coefficients D;\nCD;\n\\end{verbatim}\nwe obtain\n\\begin{verbatim}\n{ rat: coefficients[[c_cst, c_n] -> [i2, i3]] : i3 <= c_n and\n  i3 <= c_cst + 2c_n + i2 }\n\\end{verbatim}\nThe pure-parametric constraints valid for $\\Delta$,\n\\begin{verbatim}\nP := { [a,b] -> [] }(D);\nCP := coefficients P;\nCP;\n\\end{verbatim}\nare\n\\begin{verbatim}\n{ rat: coefficients[[c_cst, c_n] -> []] : c_n >= 0 and 2c_n >= -c_cst }\n\\end{verbatim}\nNegating these coefficients and intersecting with \\verb+CD+,\n\\begin{verbatim}\nNCP := { rat: coefficients[[a,b] -> []]\n              -> coefficients[[-a,-b] -> []] }(CP);\nCK := wrap((unwrap CD) * (dom (unwrap NCP)));\nCK;\n\\end{verbatim}\nwe obtain\n\\begin{verbatim}\n{ rat: [[c_cst, c_n] -> [i2, i3]] : i3 <= c_n and\n  i3 <= c_cst + 2c_n + i2 and c_n <= 0 and 2c_n <= -c_cst }\n\\end{verbatim}\nThe approximation for $k\\,\\Delta$,\n\\begin{verbatim}\nK := solutions CK;\nK;\n\\end{verbatim}\nis then\n\\begin{verbatim}\n[n] -> { rat: [i0, i1] : i1 <= -i0 and i0 >= 1 and i1 <= 2 - n - i0 }\n\\end{verbatim}\nFinally, the computed approximation for $R^+$,\n\\begin{verbatim}\nT := unwrap({ [dx,dy] -> [[x,y] -> [x+dx,y+dy]] }(K));\nR := [n] -> { [x,y] -> [x+1,y+1-n] : n >= 2 };\nT := T * ((dom R) -> (ran R));\nT;\n\\end{verbatim}\nis\n\\begin{verbatim}\n[n] -> { [x, y] -> [o0, o1] : o1 <= x + y - o0 and\n         o0 >= 1 + x and o1 <= 2 - n + x + y - o0 and n >= 2 }\n\\end{verbatim}\n\\end{example}\n\nExistentially quantified variables can be handled by\nclassifying them into variables that are uniquely\ndetermined by the parameters, variables that are independent\nof the parameters and others.  The first set can be treated\nas parameters and the second as variables.  Constraints involving\nthe other existentially quantified variables are removed.\n\n\\begin{example}\nConsider the relation\n$$\nR =\nn \\to \\{\\, x \\to y \\mid \\exists \\, \\alpha_0, \\alpha_1: 7\\alpha_0 = -2 + n \\wedge 5\\alpha_1 = -1 - x + y \\wedge y \\ge 6 + x \\,\\}\n.\n$$\nThe difference set of this relation is\n$$\n\\Delta = \\Delta \\, R =\nn \\to \\{\\, x \\mid \\exists \\, \\alpha_0, \\alpha_1: 7\\alpha_0 = -2 + n \\wedge 5\\alpha_1 = -1 + x \\wedge x \\ge 6 \\,\\}\n.\n$$\nThe existentially quantified variables can be defined in terms\nof the parameters and variables as\n$$\n\\alpha_0 = \\floor{\\frac{-2 + n}7}\n\\qquad\n\\text{and}\n\\qquad\n\\alpha_1 = \\floor{\\frac{-1 + x}5}\n.\n$$\n$\\alpha_0$ can therefore be treated as a parameter,\nwhile $\\alpha_1$ can be treated as a variable.\nThis in turn means that $7\\alpha_0 = -2 + n$ can be treated as\na purely parametric constraint, while the other two constraints are\nnon-parametric.\nThe corresponding $Q$~\\eqref{eq:transitive:Q} is therefore\n$$\n\\begin{aligned}\nn \\to \\{\\, (x,z) \\to (y,w) \\mid\n\\exists\\, \\alpha_0, \\alpha_1, k, f : {} &\nk \\ge 1 \\wedge\ny = x + f \\wedge\nw = z + k \\wedge {} \\\\\n&\n7\\alpha_0 = -2 + n \\wedge\n5\\alpha_1 = -k + x \\wedge\nx \\ge 6 k\n\\,\\}\n.\n\\end{aligned}\n$$\nProjecting out the final coordinates encoding the length of the paths,\nresults in the exact transitive closure\n$$\nR^+ =\nn \\to \\{\\, x \\to y \\mid \\exists \\, \\alpha_0, \\alpha_1: 7\\alpha_1 = -2 + n \\wedge 6\\alpha_0 \\ge -x + y \\wedge 5\\alpha_0 \\le -1 - x + y \\,\\}\n.\n$$\n\\end{example}\n\nThe fact that we ignore some impure constraints clearly leads\nto a loss of accuracy.  In some cases, some of this loss can be recovered\nby not considering the parameters in a special way.\nThat is, instead of considering the set\n$$\n\\Delta = \\diff R =\n\\vec s \\mapsto\n\\{\\, \\vec \\delta \\in \\Z^{d} \\mid \\exists \\vec x \\to \\vec y \\in R :\n\\vec \\delta = \\vec y - \\vec x\n\\,\\}\n$$\nwe consider the set\n$$\n\\Delta' = \\diff R' =\n\\{\\, \\vec \\delta \\in \\Z^{n+d} \\mid \\exists\n(\\vec s, \\vec x) \\to (\\vec s, \\vec y) \\in R' :\n\\vec \\delta = (\\vec s - \\vec s, \\vec y - \\vec x)\n\\,\\}\n.\n$$\nThe first $n$ coordinates of every element in $\\Delta'$ are zero.\nProjecting out these zero coordinates from $\\Delta'$ is equivalent\nto projecting out the parameters in $\\Delta$.\nThe result is obviously a superset of $\\Delta$, but all its constraints\nare of type \\eqref{eq:transitive:non-parametric} and they can therefore\nall be used in the construction of $Q_i$.\n\n\\begin{example}\nConsider the relation\n$$\n% [n] -> { [x, y] -> [1 + x, 1 - n + y] | n >= 2 }\nR = n \\to \\{\\, (x, y) \\to (1 + x, 1 - n + y) \\mid n \\ge 2 \\,\\}\n.\n$$\nWe have\n$$\n\\diff R = n \\to \\{\\, (1, 1 - n) \\mid n \\ge 2 \\,\\}\n$$\nand so, by treating the parameters in a special way, we obtain\nthe following approximation for $R^+$:\n$$\nn \\to \\{\\, (x, y) \\to (x', y') \\mid n \\ge 2 \\wedge y' \\le 1 - n + y \\wedge x' \\ge 1 + x \\,\\}\n.\n$$\nIf we consider instead\n$$\nR' = \\{\\, (n, x, y) \\to (n, 1 + x, 1 - n + y) \\mid n \\ge 2 \\,\\}\n$$\nthen\n$$\n\\diff R' = \\{\\, (0, 1, y) \\mid y \\le -1 \\,\\}\n$$\nand we obtain the approximation\n$$\nn \\to \\{\\, (x, y) \\to (x', y') \\mid n \\ge 2 \\wedge x' \\ge 1 + x \\wedge y' \\le x + y - x' \\,\\}\n.\n$$\nIf we consider both $\\diff R$ and $\\diff R'$, then we obtain\n$$\nn \\to \\{\\, (x, y) \\to (x', y') \\mid n \\ge 2 \\wedge y' \\le 1 - n + y \\wedge x' \\ge 1 + x \\wedge y' \\le x + y - x' \\,\\}\n.\n$$\nNote, however, that this is not the most accurate affine approximation that\ncan be obtained.  That would be\n$$\nn \\to \\{\\, (x, y) \\to (x', y') \\mid y' \\le 2 - n + x + y - x' \\wedge n \\ge 2 \\wedge x' \\ge 1 + x \\,\\}\n.\n$$\n\\end{example}\n\n\\subsection{Checking Exactness}\n\nThe approximation $T$ for the transitive closure $R^+$ can be obtained\nby projecting out the parameter $k$ from the approximation $K$\n\\eqref{eq:transitive:approx} of the power $R^k$.\nSince $K$ is an overapproximation of $R^k$, $T$ will also be an\noverapproximation of $R^+$.\nTo check whether the results are exact, we need to consider two\ncases depending on whether $R$ is {\\em cyclic}, where $R$ is defined\nto be cyclic if $R^+$ maps any element to itself, i.e.,\n$R^+ \\cap \\identity \\ne \\emptyset$.\nIf $R$ is acyclic, then the inductive definition of\n\\eqref{eq:transitive:inductive} is equivalent to its completion,\ni.e.,\n$$\nR^+ = R \\cup \\left(R \\circ R^+\\right)\n$$\nis a defining property.\nSince $T$ is known to be an overapproximation, we only need to check\nwhether\n$$\nT \\subseteq R \\cup \\left(R \\circ T\\right)\n.\n$$\nThis is essentially Theorem~5 of \\shortciteN{Kelly1996closure}.\nThe only difference is that they only consider lexicographically\nforward relations, a special case of acyclic relations.\n\nIf, on the other hand, $R$ is cyclic, then we have to resort\nto checking whether the approximation $K$ of the power is exact.\nNote that $T$ may be exact even if $K$ is not exact, so the check\nis sound, but incomplete.\nTo check exactness of the power, we simply need to check\n\\eqref{eq:transitive:power}.  Since again $K$ is known\nto be an overapproximation, we only need to check whether\n$$\n\\begin{aligned}\nK'|_{y_{d+1} - x_{d+1} = 1} & \\subseteq R'\n\\\\\nK'|_{y_{d+1} - x_{d+1} \\ge 2} & \\subseteq R' \\circ K'|_{y_{d+1} - x_{d+1} \\ge 1}\n,\n\\end{aligned}\n$$\nwhere $R' = \\{\\, \\vec x' \\to \\vec y' \\mid \\vec x \\to \\vec y \\in R\n\\wedge y_{d+1} - x_{d+1} = 1\\,\\}$, i.e., $R$ extended with path\nlengths equal to 1.\n\nAll that remains is to explain how to check the cyclicity of $R$.\nNote that the exactness on the power is always sound, even\nin the acyclic case, so we only need to be careful that we find\nall cyclic cases.  Now, if $R$ is cyclic, i.e.,\n$R^+ \\cap \\identity \\ne \\emptyset$, then, since $T$ is\nan overapproximation of $R^+$, also\n$T \\cap \\identity \\ne \\emptyset$.  This in turn means\nthat $\\Delta \\, K'$ contains a point whose first $d$ coordinates\nare zero and whose final coordinate is positive.\nIn the implementation we currently perform this test on $P'$ instead of $K'$.\nNote that if $R^+$ is acyclic and $T$ is not, then the approximation\nis clearly not exact and the approximation of the power $K$\nwill not be exact either.\n\n\\subsection{Decomposing $R$ into strongly connected components}\n\nIf the input relation $R$ is a union of several basic relations\nthat can be partially ordered\nthen the accuracy of the approximation may be improved by computing\nan approximation of each strongly connected components separately.\nFor example, if $R = R_1 \\cup R_2$ and $R_1 \\circ R_2 = \\emptyset$,\nthen we know that any path that passes through $R_2$ cannot later\npass through $R_1$, i.e.,\n\\begin{equation}\n\\label{eq:transitive:components}\nR^+ = R_1^+ \\cup R_2^+ \\cup \\left(R_2^+ \\circ R_1^+\\right)\n.\n\\end{equation}\nWe can therefore compute (approximations of) transitive closures\nof $R_1$ and $R_2$ separately.\nNote, however, that the condition $R_1 \\circ R_2 = \\emptyset$\nis actually too strong.\nIf $R_1 \\circ R_2$ is a subset of $R_2 \\circ R_1$\nthen we can reorder the segments\nin any path that moves through both $R_1$ and $R_2$ to\nfirst move through $R_1$ and then through $R_2$.\n\nThis idea can be generalized to relations that are unions\nof more than two basic relations by constructing the\nstrongly connected components in the graph with as vertices\nthe basic relations and an edge between two basic relations\n$R_i$ and $R_j$ if $R_i$ needs to follow $R_j$ in some paths.\nThat is, there is an edge from $R_i$ to $R_j$ iff\n\\begin{equation}\n\\label{eq:transitive:edge}\nR_i \\circ R_j\n\\not\\subseteq\nR_j \\circ R_i\n.\n\\end{equation}\nThe components can be obtained from the graph by applying\nTarjan's algorithm \\shortcite{Tarjan1972}.\n\nIn practice, we compute the (extended) powers $K_i'$ of each component\nseparately and then compose them as in \\eqref{eq:transitive:decompose}.\nNote, however, that in this case the order in which we apply them is\nimportant and should correspond to a topological ordering of the\nstrongly connected components.  Simply applying Tarjan's\nalgorithm will produce topologically sorted strongly connected components.\nThe graph on which Tarjan's algorithm is applied is constructed on-the-fly.\nThat is, whenever the algorithm checks if there is an edge between\ntwo vertices, we evaluate \\eqref{eq:transitive:edge}.\nThe exactness check is performed on each component separately.\nIf the approximation turns out to be inexact for any of the components,\nthen the entire result is marked inexact and the exactness check\nis skipped on the components that still need to be handled.\n\nIt should be noted that \\eqref{eq:transitive:components}\nis only valid for exact transitive closures.\nIf overapproximations are computed in the right hand side, then the result will\nstill be an overapproximation of the left hand side, but this result\nmay not be transitively closed.  If we only separate components based\non the condition $R_i \\circ R_j = \\emptyset$, then there is no problem,\nas this condition will still hold on the computed approximations\nof the transitive closures.  If, however, we have exploited\n\\eqref{eq:transitive:edge} during the decomposition and if the\nresult turns out not to be exact, then we check whether\nthe result is transitively closed.  If not, we recompute\nthe transitive closure, skipping the decomposition.\nNote that testing for transitive closedness on the result may\nbe fairly expensive, so we may want to make this check\nconfigurable.\n\n\\begin{figure}\n\\begin{center}\n\\begin{tikzpicture}[x=0.5cm,y=0.5cm,>=stealth,shorten >=1pt]\n\\foreach \\x in {1,...,10}{\n    \\foreach \\y in {1,...,10}{\n\t\\draw[->] (\\x,\\y) -- (\\x,\\y+1);\n    }\n}\n\\foreach \\x in {1,...,20}{\n    \\foreach \\y in {5,...,15}{\n\t\\draw[->] (\\x,\\y) -- (\\x+1,\\y);\n    }\n}\n\\end{tikzpicture}\n\\end{center}\n\\caption{The relation from \\autoref{ex:closure4}}\n\\label{f:closure4}\n\\end{figure}\n\\begin{example}\n\\label{ex:closure4}\nConsider the relation in example {\\tt closure4} that comes with\nthe Omega calculator~\\shortcite{Omega_calc}, $R = R_1 \\cup R_2$,\nwith\n$$\n\\begin{aligned}\nR_1 & = \\{\\, (x,y) \\to (x,y+1) \\mid 1 \\le x,y \\le 10 \\,\\}\n\\\\\nR_2 & = \\{\\, (x,y) \\to (x+1,y) \\mid 1 \\le x \\le 20 \\wedge 5 \\le y \\le 15 \\,\\}\n.\n\\end{aligned}\n$$\nThis relation is shown graphically in \\autoref{f:closure4}.\nWe have\n$$\n\\begin{aligned}\nR_1 \\circ R_2 &=\n\\{\\, (x,y) \\to (x+1,y+1) \\mid 1 \\le x \\le 9 \\wedge 5 \\le y \\le 10 \\,\\}\n\\\\\nR_2 \\circ R_1 &=\n\\{\\, (x,y) \\to (x+1,y+1) \\mid 1 \\le x \\le 10 \\wedge 4 \\le y \\le 10 \\,\\}\n.\n\\end{aligned}\n$$\nClearly, $R_1 \\circ R_2 \\subseteq R_2 \\circ R_1$ and so\n$$\n\\left(\nR_1 \\cup R_2\n\\right)^+\n=\n\\left(R_2^+ \\circ R_1^+\\right)\n\\cup R_1^+\n\\cup R_2^+\n.\n$$\n\\end{example}\n\n\\begin{figure}\n\\newcounter{n}\n\\newcounter{t1}\n\\newcounter{t2}\n\\newcounter{t3}\n\\newcounter{t4}\n\\begin{center}\n\\begin{tikzpicture}[>=stealth,shorten >=1pt]\n\\setcounter{n}{7}\n\\foreach \\i in {1,...,\\value{n}}{\n    \\foreach \\j in {1,...,\\value{n}}{\n\t\\setcounter{t1}{2 * \\j - 4 - \\i + 1}\n\t\\setcounter{t2}{\\value{n} - 3 - \\i + 1}\n\t\\setcounter{t3}{2 * \\i - 1 - \\j + 1}\n\t\\setcounter{t4}{\\value{n} - \\j + 1}\n\t\\ifnum\\value{t1}>0\\ifnum\\value{t2}>0\n\t\\ifnum\\value{t3}>0\\ifnum\\value{t4}>0\n\t    \\draw[thick,->] (\\i,\\j) to[out=20] (\\i+3,\\j);\n\t\\fi\\fi\\fi\\fi\n\t\\setcounter{t1}{2 * \\j - 1 - \\i + 1}\n\t\\setcounter{t2}{\\value{n} - \\i + 1}\n\t\\setcounter{t3}{2 * \\i - 4 - \\j + 1}\n\t\\setcounter{t4}{\\value{n} - 3 - \\j + 1}\n\t\\ifnum\\value{t1}>0\\ifnum\\value{t2}>0\n\t\\ifnum\\value{t3}>0\\ifnum\\value{t4}>0\n\t    \\draw[thick,->] (\\i,\\j) to[in=-20,out=20] (\\i,\\j+3);\n\t\\fi\\fi\\fi\\fi\n\t\\setcounter{t1}{2 * \\j - 1 - \\i + 1}\n\t\\setcounter{t2}{\\value{n} - 1 - \\i + 1}\n\t\\setcounter{t3}{2 * \\i - 1 - \\j + 1}\n\t\\setcounter{t4}{\\value{n} - 1 - \\j + 1}\n\t\\ifnum\\value{t1}>0\\ifnum\\value{t2}>0\n\t\\ifnum\\value{t3}>0\\ifnum\\value{t4}>0\n\t    \\draw[thick,->] (\\i,\\j) to (\\i+1,\\j+1);\n\t\\fi\\fi\\fi\\fi\n    }\n}\n\\end{tikzpicture}\n\\end{center}\n\\caption{The relation from \\autoref{ex:decomposition}}\n\\label{f:decomposition}\n\\end{figure}\n\\begin{example}\n\\label{ex:decomposition}\nConsider the relation on the right of \\shortciteN[Figure~2]{Beletska2009},\nreproduced in \\autoref{f:decomposition}.\nThe relation can be described as $R = R_1 \\cup R_2 \\cup R_3$,\nwith\n$$\n\\begin{aligned}\nR_1 &= n \\mapsto \\{\\, (i,j) \\to (i+3,j) \\mid\ni \\le 2 j - 4 \\wedge\ni \\le n - 3 \\wedge\nj \\le 2 i - 1 \\wedge\nj \\le n \\,\\}\n\\\\\nR_2 &= n \\mapsto \\{\\, (i,j) \\to (i,j+3) \\mid\ni \\le 2 j - 1 \\wedge\ni \\le n \\wedge\nj \\le 2 i - 4 \\wedge\nj \\le n - 3 \\,\\}\n\\\\\nR_3 &= n \\mapsto \\{\\, (i,j) \\to (i+1,j+1) \\mid\ni \\le 2 j - 1 \\wedge\ni \\le n - 1 \\wedge\nj \\le 2 i - 1 \\wedge\nj \\le n - 1\\,\\}\n.\n\\end{aligned}\n$$\nThe figure shows this relation for $n = 7$.\nBoth\n$R_3 \\circ R_1 \\subseteq R_1 \\circ R_3$\nand\n$R_3 \\circ R_2 \\subseteq R_2 \\circ R_3$,\nwhich the reader can verify using the {\\tt iscc} calculator:\n\\begin{verbatim}\nR1 := [n] -> { [i,j] -> [i+3,j] : i <= 2 j - 4 and i <= n - 3 and\n                                  j <= 2 i - 1 and j <= n };\nR2 := [n] -> { [i,j] -> [i,j+3] : i <= 2 j - 1 and i <= n and\n                                  j <= 2 i - 4 and j <= n - 3 };\nR3 := [n] -> { [i,j] -> [i+1,j+1] : i <= 2 j - 1 and i <= n - 1 and\n                                    j <= 2 i - 1 and j <= n - 1 };\n(R1 . R3) - (R3 . R1);\n(R2 . R3) - (R3 . R2);\n\\end{verbatim}\n$R_3$ can therefore be moved forward in any path.\nFor the other two basic relations, we have both\n$R_2 \\circ R_1 \\not\\subseteq R_1 \\circ R_2$\nand\n$R_1 \\circ R_2 \\not\\subseteq R_2 \\circ R_1$\nand so $R_1$ and $R_2$ form a strongly connected component.\nBy computing the power of $R_3$ and $R_1 \\cup R_2$ separately\nand composing the results, the power of $R$ can be computed exactly\nusing \\eqref{eq:transitive:singleton}.\nAs explained by \\shortciteN{Beletska2009}, applying the same formula\nto $R$ directly, without a decomposition, would result in\nan overapproximation of the power.\n\\end{example}\n\n\\subsection{Partitioning the domains and ranges of $R$}\n\nThe algorithm of \\autoref{s:power} assumes that the input relation $R$\ncan be treated as a union of translations.\nThis is a reasonable assumption if $R$ maps elements of a given\nabstract domain to the same domain.\nHowever, if $R$ is a union of relations that map between different\ndomains, then this assumption no longer holds.\nIn particular, when an entire dependence graph is encoded\nin a single relation, as is done by, e.g.,\n\\shortciteN[Section~6.1]{Barthou2000MSE}, then it does not make\nsense to look at differences between iterations of different domains.\nNow, arguably, a modified Floyd-Warshall algorithm should\nbe applied to the dependence graph, as advocated by\n\\shortciteN{Kelly1996closure}, with the transitive closure operation\nonly being applied to relations from a given domain to itself.\nHowever, it is also possible to detect disjoint domains and ranges\nand to apply Floyd-Warshall internally.\n\n\\linesnumbered\n\\begin{algorithm}\n\\caption{The modified Floyd-Warshall algorithm of\n\\protect\\shortciteN{Kelly1996closure}}\n\\label{a:Floyd}\n\\SetKwInput{Input}{Input}\n\\SetKwInput{Output}{Output}\n\\Input{Relations $R_{pq}$, $0 \\le p, q < n$}\n\\Output{Updated relations $R_{pq}$ such that each relation\n$R_{pq}$ contains all indirect paths from $p$ to $q$ in the input graph}\n%\n\\BlankLine\n\\SetVline\n\\dontprintsemicolon\n%\n\\For{$r \\in [0, n-1]$}{\n    $R_{rr} \\coloneqq R_{rr}^+$ \\nllabel{l:Floyd:closure}\\;\n    \\For{$p \\in [0, n-1]$}{\n\t\\For{$q \\in [0, n-1]$}{\n\t    \\If{$p \\ne r$ or $q \\ne r$}{\n\t\t$R_{pq} \\coloneqq R_{pq} \\cup \\left(R_{rq} \\circ R_{pr}\\right)\n\t\t\t     \\cup \\left(R_{rq} \\circ R_{rr} \\circ R_{pr}\\right)$\n\t     \\nllabel{l:Floyd:update}\n\t     }\n\t}\n    }\n}\n\\end{algorithm}\n\nLet the input relation $R$ be a union of $m$ basic relations $R_i$.\nLet $D_{2i}$ be the domains of $R_i$ and $D_{2i+1}$ the ranges of $R_i$.\nThe first step is to group overlapping $D_j$ until a partition is\nobtained.  If the resulting partition consists of a single part,\nthen we continue with the algorithm of \\autoref{s:power}.\nOtherwise, we apply Floyd-Warshall on the graph with as vertices\nthe parts of the partition and as edges the $R_i$ attached to\nthe appropriate pairs of vertices.\nIn particular, let there be $n$ parts $P_k$ in the partition.\nWe construct $n^2$ relations\n$$\nR_{pq} \\coloneqq \\bigcup_{i \\text{ s.t. } \\domain R_i \\subseteq P_p \\wedge\n\t\t\t\t \\range R_i \\subseteq P_q} R_i\n,\n$$\napply \\autoref{a:Floyd} and return the union of all resulting\n$R_{pq}$ as the transitive closure of $R$.\nEach iteration of the $r$-loop in \\autoref{a:Floyd} updates\nall relations $R_{pq}$ to include paths that go from $p$ to $r$,\npossibly stay there for a while, and then go from $r$ to $q$.\nNote that paths that ``stay in $r$'' include all paths that\npass through earlier vertices since $R_{rr}$ itself has been updated\naccordingly in previous iterations of the outer loop.\nIn principle, it would be sufficient to use the $R_{pr}$\nand $R_{rq}$ computed in the previous iteration of the\n$r$-loop in Line~\\ref{l:Floyd:update}.\nHowever, from an implementation perspective, it is easier\nto allow either or both of these to have been updated\nin the same iteration of the $r$-loop.\nThis may result in duplicate paths, but these can usually\nbe removed by coalescing (\\autoref{s:coalescing}) the result of the union\nin Line~\\ref{l:Floyd:update}, which should be done in any case.\nThe transitive closure in Line~\\ref{l:Floyd:closure}\nis performed using a recursive call.  This recursive call\nincludes the partitioning step, but the resulting partition will\nusually be a singleton.\nThe result of the recursive call will either be exact or an\noverapproximation.  The final result of Floyd-Warshall is therefore\nalso exact or an overapproximation.\n\n\\begin{figure}\n\\begin{center}\n\\begin{tikzpicture}[x=1cm,y=1cm,>=stealth,shorten >=3pt]\n\\foreach \\x/\\y in {0/0,1/1,3/2} {\n    \\fill (\\x,\\y) circle (2pt);\n}\n\\foreach \\x/\\y in {0/1,2/2,3/3} {\n    \\draw (\\x,\\y) circle (2pt);\n}\n\\draw[->] (0,0) -- (0,1);\n\\draw[->] (0,1) -- (1,1);\n\\draw[->] (2,2) -- (3,2);\n\\draw[->] (3,2) -- (3,3);\n\\draw[->,dashed] (2,2) -- (3,3);\n\\draw[->,dotted] (0,0) -- (1,1);\n\\end{tikzpicture}\n\\end{center}\n\\caption{The relation (solid arrows) on the right of Figure~1 of\n\\protect\\shortciteN{Beletska2009} and its transitive closure}\n\\label{f:COCOA:1}\n\\end{figure}\n\\begin{example}\nConsider the relation on the right of Figure~1 of\n\\shortciteN{Beletska2009},\nreproduced in \\autoref{f:COCOA:1}.\nThis relation can be described as\n$$\n\\begin{aligned}\n\\{\\, (x, y) \\to (x_2, y_2) \\mid {} & (3y = 2x \\wedge x_2 = x \\wedge 3y_2 = 3 + 2x \\wedge x \\ge 0 \\wedge x \\le 3) \\vee {} \\\\\n& (x_2 = 1 + x \\wedge y_2 = y \\wedge x \\ge 0 \\wedge 3y \\ge 2 + 2x \\wedge x \\le 2 \\wedge 3y \\le 3 + 2x) \\,\\}\n.\n\\end{aligned}\n$$\nNote that the domain of the upward relation overlaps with the range\nof the rightward relation and vice versa, but that the domain\nof neither relation overlaps with its own range or the domain of\nthe other relation.\nThe domains and ranges can therefore be partitioned into two parts,\n$P_0$ and $P_1$, shown as the white and black dots in \\autoref{f:COCOA:1},\nrespectively.\nInitially, we have\n$$\n\\begin{aligned}\nR_{00} & = \\emptyset\n\\\\\nR_{01} & = \n\\{\\, (x, y) \\to (x+1, y) \\mid \n(x \\ge 0 \\wedge 3y \\ge 2 + 2x \\wedge x \\le 2 \\wedge 3y \\le 3 + 2x) \\,\\}\n\\\\\nR_{10} & =\n\\{\\, (x, y) \\to (x_2, y_2) \\mid (3y = 2x \\wedge x_2 = x \\wedge 3y_2 = 3 + 2x \\wedge x \\ge 0 \\wedge x \\le 3) \\,\\}\n\\\\\nR_{11} & = \\emptyset\n.\n\\end{aligned}\n$$\nIn the first iteration, $R_{00}$ remains the same ($\\emptyset^+ = \\emptyset$).\n$R_{01}$ and $R_{10}$ are therefore also unaffected, but\n$R_{11}$ is updated to include $R_{01} \\circ R_{10}$, i.e.,\nthe dashed arrow in the figure.\nThis new $R_{11}$ is obviously transitively closed, so it is not\nchanged in the second iteration and it does not have an effect\non $R_{01}$ and $R_{10}$.  However, $R_{00}$ is updated to\ninclude $R_{10} \\circ R_{01}$, i.e., the dotted arrow in the figure.\nThe transitive closure of the original relation is then equal to\n$R_{00} \\cup R_{01} \\cup R_{10} \\cup R_{11}$.\n\\end{example}\n\n\\subsection{Incremental Computation}\n\\label{s:incremental}\n\nIn some cases it is possible and useful to compute the transitive closure\nof union of basic relations incrementally.  In particular,\nif $R$ is a union of $m$ basic maps,\n$$\nR = \\bigcup_j R_j\n,\n$$\nthen we can pick some $R_i$ and compute the transitive closure of $R$ as\n\\begin{equation}\n\\label{eq:transitive:incremental}\nR^+ = R_i^+ \\cup\n\\left(\n\\bigcup_{j \\ne i}\nR_i^* \\circ R_j \\circ R_i^*\n\\right)^+\n.\n\\end{equation}\nFor this approach to be successful, it is crucial that each\nof the disjuncts in the argument of the second transitive\nclosure in \\eqref{eq:transitive:incremental} be representable\nas a single basic relation, i.e., without a union.\nIf this condition holds, then by using \\eqref{eq:transitive:incremental},\nthe number of disjuncts in the argument of the transitive closure\ncan be reduced by one.\nNow, $R_i^* = R_i^+ \\cup \\identity$, but in some cases it is possible\nto relax the constraints of $R_i^+$ to include part of the identity relation,\nsay on domain $D$.  We will use the notation\n${\\cal C}(R_i,D) = R_i^+ \\cup \\identity_D$ to represent\nthis relaxed version of $R^+$.\n\\shortciteN{Kelly1996closure} use the notation $R_i^?$.\n${\\cal C}(R_i,D)$ can be computed by allowing $k$ to attain\nthe value $0$ in \\eqref{eq:transitive:Q} and by using\n$$\nP \\cap \\left(D \\to D\\right)\n$$\ninstead of \\eqref{eq:transitive:approx}.\nTypically, $D$ will be a strict superset of both $\\domain R_i$\nand $\\range R_i$.  We therefore need to check that domain\nand range of the transitive closure are part of ${\\cal C}(R_i,D)$,\ni.e., the part that results from the paths of positive length ($k \\ge 1$),\nare equal to the domain and range of $R_i$.\nIf not, then the incremental approach cannot be applied for\nthe given choice of $R_i$ and $D$.\n\nIn order to be able to replace $R^*$ by ${\\cal C}(R_i,D)$\nin \\eqref{eq:transitive:incremental}, $D$ should be chosen\nto include both $\\domain R$ and $\\range R$, i.e., such\nthat $\\identity_D \\circ R_j \\circ \\identity_D = R_j$ for all $j\\ne i$.\n\\shortciteN{Kelly1996closure} say that they use\n$D = \\domain R_i \\cup \\range R_i$, but presumably they mean that\nthey use $D = \\domain R \\cup \\range R$.\nNow, this expression of $D$ contains a union, so it not directly usable.\n\\shortciteN{Kelly1996closure} do not explain how they avoid this union.\nApparently, in their implementation,\nthey are using the convex hull of $\\domain R \\cup \\range R$\nor at least an approximation of this convex hull.\nWe use the simple hull (\\autoref{s:simple hull}) of $\\domain R \\cup \\range R$.\n\nIt is also possible to use a domain $D$ that does {\\em not\\/}\ninclude $\\domain R \\cup \\range R$, but then we have to\ncompose with ${\\cal C}(R_i,D)$ more selectively.\nIn particular, if we have\n\\begin{equation}\n\\label{eq:transitive:right}\n\\text{for each $j \\ne i$ either }\n\\domain R_j \\subseteq D \\text{ or } \\domain R_j \\cap \\range R_i = \\emptyset\n\\end{equation}\nand, similarly,\n\\begin{equation}\n\\label{eq:transitive:left}\n\\text{for each $j \\ne i$ either }\n\\range R_j \\subseteq D \\text{ or } \\range R_j \\cap \\domain R_i = \\emptyset\n\\end{equation}\nthen we can refine \\eqref{eq:transitive:incremental} to\n$$\nR_i^+ \\cup\n\\left(\n\\left(\n\\bigcup_{\\shortstack{$\\scriptstyle\\domain R_j \\subseteq D $\\\\\n\t\t     $\\scriptstyle\\range R_j \\subseteq D$}}\n{\\cal C} \\circ R_j \\circ {\\cal C}\n\\right)\n\\cup\n\\left(\n\\bigcup_{\\shortstack{$\\scriptstyle\\domain R_j \\cap \\range R_i = \\emptyset$\\\\\n\t\t     $\\scriptstyle\\range R_j \\subseteq D$}}\n\\!\\!\\!\\!\\!\n{\\cal C} \\circ R_j\n\\right)\n\\cup\n\\left(\n\\bigcup_{\\shortstack{$\\scriptstyle\\domain R_j \\subseteq D $\\\\\n\t\t     $\\scriptstyle\\range R_j \\cap \\domain R_i = \\emptyset$}}\n\\!\\!\\!\\!\\!\nR_j \\circ {\\cal C}\n\\right)\n\\cup\n\\left(\n\\bigcup_{\\shortstack{$\\scriptstyle\\domain R_j \\cap \\range R_i = \\emptyset$\\\\\n\t\t     $\\scriptstyle\\range R_j \\cap \\domain R_i = \\emptyset$}}\n\\!\\!\\!\\!\\!\nR_j\n\\right)\n\\right)^+\n.\n$$\nIf only property~\\eqref{eq:transitive:right} holds,\nwe can use\n$$\nR_i^+ \\cup\n\\left(\n\\left(\nR_i^+ \\cup \\identity\n\\right)\n\\circ\n\\left(\n\\left(\n\\bigcup_{\\shortstack{$\\scriptstyle\\domain R_j \\subseteq D $}}\nR_j \\circ {\\cal C}\n\\right)\n\\cup\n\\left(\n\\bigcup_{\\shortstack{$\\scriptstyle\\domain R_j \\cap \\range R_i = \\emptyset$}}\n\\!\\!\\!\\!\\!\nR_j\n\\right)\n\\right)^+\n\\right)\n,\n$$\nwhile if only property~\\eqref{eq:transitive:left} holds,\nwe can use\n$$\nR_i^+ \\cup\n\\left(\n\\left(\n\\left(\n\\bigcup_{\\shortstack{$\\scriptstyle\\range R_j \\subseteq D $}}\n{\\cal C} \\circ R_j\n\\right)\n\\cup\n\\left(\n\\bigcup_{\\shortstack{$\\scriptstyle\\range R_j \\cap \\domain R_i = \\emptyset$}}\n\\!\\!\\!\\!\\!\nR_j\n\\right)\n\\right)^+\n\\circ\n\\left(\nR_i^+ \\cup \\identity\n\\right)\n\\right)\n.\n$$\n\nIt should be noted that if we want the result of the incremental\napproach to be transitively closed, then we can only apply it\nif all of the transitive closure operations involved are exact.\nIf, say, the second transitive closure in \\eqref{eq:transitive:incremental}\ncontains extra elements, then the result does not necessarily contain\nthe composition of these extra elements with powers of $R_i$.\n\n\\subsection{An {\\tt Omega}-like implementation}\n\nWhile the main algorithm of \\shortciteN{Kelly1996closure} is\ndesigned to compute and underapproximation of the transitive closure,\nthe authors mention that they could also compute overapproximations.\nIn this section, we describe our implementation of an algorithm\nthat is based on their ideas.\nNote that the {\\tt Omega} library computes underapproximations\n\\shortcite[Section 6.4]{Omega_lib}.\n\nThe main tool is Equation~(2) of \\shortciteN{Kelly1996closure}.\nThe input relation $R$ is first overapproximated by a ``d-form'' relation\n$$\n\\{\\, \\vec i \\to \\vec j \\mid \\exists \\vec \\alpha :\n\\vec L \\le \\vec j - \\vec i \\le \\vec U\n\\wedge\n(\\forall p : j_p - i_p = M_p \\alpha_p)\n\\,\\}\n,\n$$\nwhere $p$ ranges over the dimensions and $\\vec L$, $\\vec U$ and\n$\\vec M$ are constant integer vectors.  The elements of $\\vec U$\nmay be $\\infty$, meaning that there is no upper bound corresponding\nto that element, and similarly for $\\vec L$.\nSuch an overapproximation can be obtained by computing strides,\nlower and upper bounds on the difference set $\\Delta \\, R$.\nThe transitive closure of such a ``d-form'' relation is\n\\begin{equation}\n\\label{eq:omega}\n\\{\\, \\vec i \\to \\vec j \\mid \\exists \\vec \\alpha, k :\nk \\ge 1 \\wedge\nk \\, \\vec L \\le \\vec j - \\vec i \\le k \\, \\vec U\n\\wedge\n(\\forall p : j_p - i_p = M_p \\alpha_p)\n\\,\\}\n.\n\\end{equation}\nThe domain and range of this transitive closure are then\nintersected with those of the input relation.\nThis is a special case of the algorithm in \\autoref{s:power}.\n\nIn their algorithm for computing lower bounds, the authors\nuse the above algorithm as a substep on the disjuncts in the relation.\nAt the end, they say\n\\begin{quote}\nIf an upper bound is required, it can be calculated in a manner\nsimilar to that of a single conjunct [sic] relation.\n\\end{quote}\nPresumably, the authors mean that a ``d-form'' approximation\nof the whole input relation should be used.\nHowever, the accuracy can be improved by also trying to\napply the incremental technique from the same paper,\nwhich is explained in more detail in \\autoref{s:incremental}.\nIn this case, ${\\cal C}(R_i,D)$ can be obtained by\nallowing the value zero for $k$ in \\eqref{eq:omega},\ni.e., by computing\n$$\n\\{\\, \\vec i \\to \\vec j \\mid \\exists \\vec \\alpha, k :\nk \\ge 0 \\wedge\nk \\, \\vec L \\le \\vec j - \\vec i \\le k \\, \\vec U\n\\wedge\n(\\forall p : j_p - i_p = M_p \\alpha_p)\n\\,\\}\n.\n$$\nIn our implementation we take as $D$ the simple hull\n(\\autoref{s:simple hull}) of $\\domain R \\cup \\range R$.\nTo determine whether it is safe to use ${\\cal C}(R_i,D)$,\nwe check the following conditions, as proposed by\n\\shortciteN{Kelly1996closure}:\n${\\cal C}(R_i,D) - R_i^+$ is not a union and for each $j \\ne i$\nthe condition\n$$\n\\left({\\cal C}(R_i,D) - R_i^+\\right)\n\\circ\nR_j\n\\circ\n\\left({\\cal C}(R_i,D) - R_i^+\\right)\n=\nR_j\n$$\nholds.\n", "meta": {"hexsha": "d5ece80e4c8ba7876ed2769f38434b4a72848dfe", "size": 80521, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/implementation.tex", "max_stars_repo_name": "tizenorg/platform.upstream.isl", "max_stars_repo_head_hexsha": "1bc80b1e1cf5941b141ce5c51162d6bd75c071f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-03-23T17:26:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-18T12:09:42.000Z", "max_issues_repo_path": "doc/implementation.tex", "max_issues_repo_name": "tizenorg/platform.upstream.isl", "max_issues_repo_head_hexsha": "1bc80b1e1cf5941b141ce5c51162d6bd75c071f5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/implementation.tex", "max_forks_repo_name": "tizenorg/platform.upstream.isl", "max_forks_repo_head_hexsha": "1bc80b1e1cf5941b141ce5c51162d6bd75c071f5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-12-19T11:31:37.000Z", "max_forks_repo_forks_event_max_datetime": "2015-12-19T11:31:37.000Z", "avg_line_length": 39.529209622, "max_line_length": 240, "alphanum_fraction": 0.7155276263, "num_tokens": 24695, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511359371249, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7094482207242503}}
{"text": "\\section{The Squeeze Theorem And Some Special Limits}\\label{sec:TrigLimits}\r\n\r\n\r\nThe previous section could have been titled ``Using Known Limits to Find Unknown Limits.'' By knowing certain limits of functions, we can find limits involving sums, products, powers, etc., of these functions. We further the development of such comparative tools with the Squeeze Theorem, a clever and intuitive way to find the value of some limits. \r\n\r\nIn this section we aim to compute the limit:\r\n$$\\lim_{x\\to0} {\\sin x\\over x}.$$\r\n\r\nWe start by analyzing the graph of $\\ds{y=\\frac{\\sin x}{x}}$:\r\n$$\\includegraphics[width=3.0in]{images/sinx-over-x}$$\r\nNotice that $x=0$ is not in the domain of this function.\r\nNevertheless, we can look at the limit as $x$ approaches $0$.\r\nFrom the graph we find that the limit is $1$ (there is an open circle at $x=0$ indicating $0$ is not in the domain).\r\n%We can expand upon the above limit and write it as follows:\r\n%$$\\lim_{x\\to 0}\\frac{\\sin nx}{nx}=1.$$\r\nWe just convinced you this limit formula holds true based on the graph,\r\nbut how does one attempt to prove this limit more formally?\r\nTo do this we employ some indirect reasoning embodied in the \\dfont{Squeeze Theorem}.\r\n\r\nBefore stating this theorem formally, suppose we have functions $f$, $g$ and $h$ where $g$ always takes on values between $f$ and $h$; that is, for all $x$ in an interval, $$f(x) \\leq g(x) \\leq h(x).$$ If $f$ and $h$ have the same limit at $c$, and $g$  is always ``squeezed'' between them, then $g$ must have the same limit as well. That is what the Squeeze Theorem states.\r\n\r\n\\begin{theorem}{Squeeze Theorem}{sqz}\r\n{Let $f$, $g$ and $h$ be functions on an open interval $I$ containing $a$ such that for all $x$ in $I$, $$f(x)\\leq g(x) \\leq h(x).$$ If $$\\lim_{x\\to a} f(x) = L = \\lim_{x\\to a} h(x),$$ then $$\\lim_{x\\to a} g(x) = L.$$ \\index{limit!Squeeze Theorem}\\index{Squeeze Theorem}\r\n}\r\n\\end{theorem}\r\n\r\n\r\n\\begin{center}\r\n\\begin{tikzpicture} %[default]\r\n      %\\diagram{-.5}{6}{-.5}{3}{1}\r\n      \\draw[->,ultra thick] (-.5,0)--(6,0) node[right]{$x$};\r\n      \\draw[->,ultra thick] (0,-.5)--(0,3) node[above]{$y$};\r\n     % \\diagramannotatez\r\n      \\draw[red,ultra thick] (-.5,1) to[out=-45,in=185,looseness=2] (4,2) to[out=0,in=135,looseness=1] node [at end,above] {$f(x)$} (6,.5);\r\n      \\draw[blue,ultra thick] (-.5,2.5) to[out=25,in=160,looseness=1] (4,2) to[out=10,in=180,looseness=1] node [at end,above] {$h(x)$} (6,3);\r\n      \\draw[green,ultra thick] (0.5,3.2) to[out=-45,in=175,looseness=1] (4,2) to[out=0,in=180,looseness=1] node [at end,below] {$g(x)$} (6,2.5);\r\n      \\draw[dashed] (4,0) -- node[at start,below] {$a$} (4,2) -- node[at end,left] {$L$} (0,2);\r\n    \\end{tikzpicture}\r\n\\end{center}\r\n\r\nIt can take some work to figure out appropriate functions by which to ``squeeze'' the given function of which you are trying to evaluate a limit. However, that is generally the only place work is necessary; the theorem makes the ``evaluating the limit part'' very simple. \r\n\r\nWe use the Squeeze Theorem in the following example to finally prove that $\\ds \\lim_{x\\to 0} \\frac{\\sin x}{x} = 1$.\\\\\r\n\r\n\\begin{example}{Using the Squeeze Theorem}{ex_limit_sinx_prove}{\r\nUse the Squeeze Theorem to show that $$\\ds \\lim_{x\\to 0} \\frac{\\sin x}{x} = 1.$$}\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{We begin by considering the unit circle. Each point on the unit circle has coordinates $(\\cos \\theta,\\sin \\theta)$ for some angle $\\theta$ as shown in Figure \\ref{fig:squeeze_sinx}. Using similar triangles, we can extend the line from the origin through the point to the point $(1,\\tan \\theta)$, as shown. (Here we are assuming that $0\\leq \\theta \\leq \\pi/2$. Later we will show that we can also consider $\\theta \\leq 0$.)\r\n\r\n\\mfigure{.7}{The unit circle and related triangles.}{fig:squeeze_sinx}{\\begin{tikzpicture}[\r\n>=stealth, scale=2]\r\n\\draw [thick] (0,0) node [shift={(10pt,4pt)}] {\\scriptsize$\\theta$} circle (1);\r\n\\draw [<->,thick] (-1.1,0) -- (1.1,0);\r\n\\draw [<->,thick] (0,-1.1) -- (0,1.1);\r\n\\draw [thick] (0,0) -- (1,.839) node [above] {\\scriptsize$(1,\\tan \\theta)$}-- (1,0) -- (.766,.643);\r\n\\fill [black] (1,.839) circle (1.5pt);\r\n\\fill [black] (.766,.643) node [left] {\\scriptsize$(\\cos \\theta,\\sin \\theta)$} circle (1.5pt);\r\n\\fill [black] (1,0) node [below right] {\\scriptsize$(1,0)$} circle (1.5pt);\r\n\\end{tikzpicture}\r\n}\r\n\r\nFigure \\ref{fig:squeeze_sinx} shows three regions have been constructed in the first quadrant, two triangles and a sector of a circle, which are also drawn below. The area of the large triangle is $\\frac12\\tan\\theta$; the area of the sector is $\\theta/2$; the area of the triangle contained inside the sector is $\\frac12\\sin\\theta$. It is then clear from the diagram that we get the inequality in Figure \\ref{fig:STpic}. \r\n\r\n\r\n\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\begin{subfigure}[t]{0.33\\textwidth}\r\n\\begin{tikzpicture}[>=stealth,scale=3.5]\r\n\\fill [draw=black,thick,fill=blue!20] (0,0) node [shift={(10pt,4pt)}] {\\scriptsize$\\theta$} -- (1,.839) -- node [pos=.5,right] {\\scriptsize$\\tan \\theta$} (1,0) -- cycle;\r\n\\draw (.5,0) node [below] {\\scriptsize$1$};\r\n\\draw [black,dashed,thick] (1,0) arc (0:40:1);\r\n\\draw [black,dashed,thick] (1,0) -- (.766,.643);\r\n\\end{tikzpicture}\t\t \r\n        \\label{fig:STpica}\r\n        \\caption{$\\ds \\frac{\\tan \\theta}{2}$} \r\n    \\end{subfigure}% \r\n    \\begin{subfigure}[t]{0.33\\textwidth}\r\n     \\begin{tikzpicture}[ %x=.5\\marginparwidth,y=.5\\marginparwidth,\r\n     >=stealth,scale=3.5]\r\n     \\fill [draw=black,thick,fill=blue!20] (0,0) node [shift={(10pt,4pt)}] {\\scriptsize$\\theta$} -- (1,0) arc(0:40:1) -- cycle;\r\n     \\draw (.5,0) node [below] {\\scriptsize$1$};\r\n     \\draw [black,dashed,thick] (1,0) arc (0:40:1);\r\n     \\draw [black,dashed,thick] (1,0) -- (.766,.643) -- (1,.839) -- cycle;\r\n     \\end{tikzpicture}\r\n        \\label{fig:STpicb}\r\n        \\caption{$\\ds \\frac{\\theta}{2}$}    \r\n    \\end{subfigure}\r\n\\begin{subfigure}[t]{0.33\\textwidth}\r\n     \\begin{tikzpicture}[ %x=.5\\marginparwidth,y=.5\\marginparwidth,\r\n     >=stealth,scale=3.5]\r\n     \\fill [draw=black,thick,fill=blue!20] (0,0) node [shift={(10pt,4pt)}] {\\scriptsize$\\theta$} -- (1,0) --(.766,.643) -- cycle;\r\n     \\draw [dashed,thick] (.766,0)  -- node [pos=.4,left] {\\scriptsize$\\sin \\theta$}(.766,.643);\r\n     \\draw (.766,5pt) -- ++(5pt,0) -- ++(0,-5pt);\r\n     \\draw (.5,0) node [below] {\\scriptsize$1$};\r\n     %\\draw [black,dashed] (1,0) arc (0:40:1);\r\n     \\draw [black,dashed,thick] (1,0) arc(0:40:1) --  (1,.839) -- cycle;\r\n     \\end{tikzpicture}\r\n        \\label{fig:STpicc}\r\n        \\caption{$\\ds \\frac{\\sin \\theta}{2}$}    \r\n    \\end{subfigure} \r\n    \\caption{Demonstrating that $\\ds \\frac{\\tan \\theta}{2}  \\geq \\frac{\\theta}{2} \\geq \\frac{\\sin \\theta}{2}$   \\label{fig:STpic} }\r\n\\end{figure}\r\n\r\n\r\n%\\begin{center}\r\n%\\begin{tabular}{ccccc}\r\n%\\myincludegraphics{figures/figSqueeze1a} & & \\myincludegraphics{figures/figSqueeze1b} & & \\myincludegraphics{figures/figSqueeze1c}\\\\\r\n%$\\ds \\frac{\\tan \\theta}{2}$\\rule{0pt}{25pt} & $\\geq$ & $\\ds \\frac{\\theta}{2}$ & $\\geq$ & $\\ds \\frac{\\sin \\theta}{2}$\r\n%\\end{tabular}\r\n%\\end{center}\r\n\r\n%$$\\frac{\\tan\\theta}{2} \\geq \\frac{\\theta}{2} \\geq \\frac{\\sin \\theta}{2}.$$\r\n\r\nMultiply all terms by $\\ds\\frac{2}{\\sin \\theta}$, giving $$\\frac{1}{\\cos\\theta} \\geq \\frac{\\theta}{\\sin \\theta} \\geq 1.$$\r\n\r\nTaking reciprocals reverses the inequalities, giving $$ \\cos \\theta \\leq \\frac{\\sin \\theta}{\\theta} \\leq 1.$$ (These inequalities hold for all values of $\\theta$ near 0, even negative values, since $\\cos (-\\theta) = \\cos \\theta$ and $\\sin (-\\theta) = -\\sin \\theta$.)\r\n\r\nNow take limits.\r\n\r\n$$\\lim_{\\theta\\to 0} \\cos \\theta \\leq \\lim_{\\theta\\to 0} \\frac{\\sin\\theta}{\\theta} \\leq \\lim_{\\theta\\to 0}  1 $$\r\n$$\\cos 0 \\leq \\lim_{\\theta\\to 0} \\frac{\\sin\\theta}{\\theta} \\leq  1 $$\r\n$$1 \\leq \\lim_{\\theta\\to 0} \\frac{\\sin\\theta}{\\theta} \\leq  1 $$\r\n\r\nClearly this means that $\\ds \\lim_{\\theta\\to 0} \\frac{\\sin\\theta}{\\theta}=1$.\\\\\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\r\nTwo notes about the previous example are worth mentioning. First, one might be discouraged by this application, thinking ``I would \\textit{never} have come up with that on my own. This is too hard!'' Don't be discouraged; within this text we will guide you in your use of the Squeeze Theorem. As one gains mathematical maturity, clever proofs like this are easier and easier to create.\r\n\r\n\r\nSecond, this limit tells us more than just that as $x$ approaches $ 0 $, $\\sin(x)/x$ approaches $ 1 $. Both $x$ and $\\sin x$ are approaching $ 0 $, but the \\textit{ratio} of $x$ and $\\sin x$ approaches $ 1 $, meaning that they are approaching $ 0 $ in essentially the same way. Another way of viewing this is: for small $x$, the functions $y=x$ and $y=\\sin x$ are essentially indistinguishable.\\\\\r\n\r\n\r\nWe include this special limit, along with three others, in the following theorem.\r\n\r\n\\begin{theorem}{Special Limits}{special_limits}{%\r\n\\noindent\\begin{minipage}[t]{.5\\textwidth}\r\n\\begin{enumerate}\r\n\t\\item\t\t$\\ds \\lim_{x\\to 0} \\frac{\\sin x}{x} = 1$\r\n\t\\item\t\t$\\ds \\lim_{x\\to 0} \\frac{\\cos x-1}{x} = 0$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n\\begin{minipage}[t]{.5\\textwidth}\r\n\\begin{enumerate}\\addtocounter{enumi}{2}\r\n\t\\item\t\t$\\ds \\lim_{x\\to 0} (1+x)^\\frac1x = e$\r\n\t\\item\t\t$\\ds \\lim_{x\\to 0} \\frac{e^x-1}{x} = 1$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n}\r\n\\end{theorem}\r\n\r\n\r\nA short word on how to interpret the latter three limits. We know that as $x$ goes to 0, $\\cos x$ goes to 1. So, in the second limit, both the numerator and denominator are approaching 0. However, since the limit is 0, we can interpret this as saying that ``$\\cos x$ is approaching 1 faster than $x$ is approaching 0.''\r\n\r\nIn the third limit, inside the parentheses we have an expression that is approaching 1 (though never equaling 1), and we know that 1 raised to any power is still 1. At the same time, the power is growing toward infinity. What happens to a number near 1 raised to a very large power? In this particular case, the result approaches Euler's number, $e$, approximately $2.718.$\r\n\r\nIn the fourth limit, we see that as $x\\to 0$, $e^x$ approaches 1 ``just as fast'' as $x\\to 0$, resulting in a limit of 1.\\\\\r\n\r\n\r\n\\begin{example}{Limit of Other Trig Functions}{LimitOtherTrigFunctions}\r\nCompute the following limit $\\ds\\lim_{x\\to 0}\\frac{\\sin 5x\\cos x}{x}$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe have\r\n$$\\begin{array}{rcl}\r\n\\ds{\\lim_{x\\to 0}\\frac{\\sin 5x\\cos x}{x}} & = & \\ds{\\lim_{x\\to 0}\\frac{5\\sin 5x\\cos x}{5x}}\\\\\r\n\\\\\r\n~ & = & \\ds{\\lim_{x\\to 0} 5\\cos x\\left(\\frac{\\sin 5x}{5x}\\right)}\\\\\r\n\\\\\r\n~ & = &  5\\cdot (1)\\cdot (1)~~=~~5\\\\\r\n\\end{array}$$\r\nsince $\\cos(0)=1$ and $\\ds{\\lim_{x\\to 0}\\frac{\\sin 5x}{5x}=1}$.\r\n\\end{solution}\r\nLet's do a harder one now.\r\n\r\n\\begin{example}{Limit of Other Trig Functions}{LimitOtherTrigFunctions2}\r\nCompute the following limit:\r\n$\\ds\\lim_{x\\to 0}\\frac{\\tan^3 2x}{x^2\\sin 7x}$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nRecall that the $\\tan^3(2x)$ means that $\\tan(2x)$ is being raised to the third power.\r\n$$\\begin{array}{rcll}\r\n\\ds{\\lim_{x\\to 0}\\frac{\\tan^3(2x)}{x^2\\sin(7x)}}&=& \\ds{\\lim_{x\\to 0}\\frac{(\\sin(2x))^3}{x^2\\sin(7x)\\cos^3(2x)}}\r\n& \\mbox{Rewrite in terms of $\\sin$ and $\\cos$}\\\\\r\n\\\\\r\n~&=&\\ds{\\lim_{x\\to 0}\\frac{(2x)^3\\left(\\frac{\\sin(2x)}{2x}\\right)^3}{x^2(7x)\\left(\\frac{\\sin(7x)}{7x}\\right)\\cos^3(2x)}}\r\n& \\mbox{Make sine terms look like: $\\ds{\\frac{\\sin\\theta}{\\theta}}$}\\\\\r\n\\\\\r\n~&=&\\ds{\\lim_{x\\to 0}\\frac{8x^3(1)^3}{7x^3(1)(1^3)}} \r\n& \\mbox{Replace $\\ds{\\lim_{x\\to 0}\\frac{\\sin nx}{nx}}$ with $1$. Also, $\\cos(0)=1$.}\\\\\r\n\\\\\r\n~&=&\\ds{\\lim_{x\\to 0}\\frac{8}{7}}&\\mbox{Cancel $x^3$'s.}\\\\\r\n\\\\\r\n~&=&\\ds{\\frac{8}{7}}.\\\\\r\n\\end{array}$$\r\n\\end{solution}\r\n\r\n\\begin{example}{Applying the Squeeze Theorem}{Applying the Squeeze Theorem}\r\nCompute the following limit:\r\n$\\ds\\lim_{x\\to 0^+}x^3\\cos\\left(\\frac{1}{\\sqrt{x}}\\right)$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe use the \\ifont{Squeeze Theorem} to evaluate this limit.\r\nWe know that $\\cos\\alpha$ satisfies $-1\\leq\\cos\\alpha\\leq 1$ for any choice of $\\alpha$.\r\nTherefore we can write:\r\n$$-1\\leq\\cos\\left(\\frac{1}{\\sqrt{x}}\\right)\\leq 1$$\r\nSince $x\\to 0^+$ implies $x>0$, multiplying by $x^3$ gives:\r\n$$-x^3\\leq x^3\\cos\\left(\\frac{1}{\\sqrt{x}}\\right)\\leq x^3.$$\r\n$$\\lim_{x\\to 0^+}(-x^3)\\leq \\lim_{x\\to 0^+}\\left(x^3\\cos\\left(\\frac{1}{\\sqrt{x}}\\right)\\right)\\leq\\lim_{x\\to 0^+} x^3.$$\r\nBut using our rules we know that\r\n$$\\lim_{x\\to 0^+}(-x^3)=0,\\qquad\\qquad \\lim_{x\\to 0^+} x^3=0$$\r\nand the Squeeze Theorem says that the only way this can happen is if\r\n$$\\lim_{x\\to 0^+}x^3\\cos\\left(\\frac{1}{\\sqrt{x}}\\right)=0.$$\r\n\\end{solution}\r\n\r\n\r\n%\\begin{theorem}{Squeeze Theorem}{SqueezeTheorem}\r\n%Suppose that $g(x) \\le f(x) \\le h(x)$ for all $x$ close to $a$ but not\r\n%equal to $a$. If $\\ds\\lim_{x\\to a}g(x)=L=\\lim_{x\r\n%\\to a}h(x)$, then $\\ds\\lim_{x\\to a}f(x)=L$.\r\n%\\end{theorem}\r\n% \r\n%This theorem can be proved using the official definition of limit. We\r\n%won't prove it here, but point out that it is easy to understand and\r\n%believe graphically. The condition says that $f(x)$ is trapped between\r\n%$g(x)$ below and $h(x)$ above, and that at $x=a$, both $g$ and $h$\r\n%approach the same value. This means the situation looks something like\r\n%Figure~\\ref{fig:squeeze}.\r\n%\r\n%For example, imagine the blue curve is $f(x)=x^2\\sin(\\pi/x)$, the\r\n%upper (red) and lower (green) curves are $h(x)=x^2$ and $g(x)=-x^2$. Since the sine function\r\n%is always between $-1$ and $1$, $-x^2\\le x^2\\sin(\\pi/x)\\le x^2$, and\r\n%it is easy to see that $\\lim_{x\\to0}-x^2=0=\\lim_{x\\to0}x^2$.\r\n%It is not so easy to see directly (i.e. algebraically) that \r\n%$\\lim_{x\\to0}x^2\\sin(\\pi/x)=0$, because the $\\pi/x$ prevents us from\r\n%simply plugging in $x=0$. The squeeze theorem makes this ``hard\r\n%limit'' as easy as the trivial limits involving $x^2$.\r\n\r\n%\\figure[!ht]\r\n%\\centerline{\\vbox{\\beginpicture\r\n%\\normalgraphs\r\n%%\\ninepoint\r\n%\\setcoordinatesystem units <4truecm,4truecm>\r\n%\\setplotarea x from -1 to 1, y from -1 to 1\r\n%\\axis left shiftedto x=0 /\r\n%\\axis bottom shiftedto y=0 /\r\n%\\setquadratic\r\n%\\plot -1.000 0.000 -0.980 0.060 -0.961 0.118 -0.941 0.173 -0.922 0.224\r\n%-0.902 0.272 -0.882 0.317 -0.863 0.357 -0.843 0.392 -0.824 0.423\r\n%-0.804 0.448 -0.784 0.468 -0.765 0.481 -0.745 0.488 -0.726 0.488\r\n%-0.706 0.481 -0.686 0.467 -0.667 0.445 -0.647 0.415 -0.628 0.377\r\n%-0.608 0.332 -0.588 0.280 -0.569 0.223 -0.549 0.161 -0.530 0.096\r\n%-0.510 0.032 -0.490 -0.030 -0.471 -0.084 -0.451 -0.128 -0.432 -0.156\r\n%-0.412 -0.165 -0.392 -0.152 -0.373 -0.117 -0.353 -0.063 -0.334 -0.001\r\n%-0.314 0.054 -0.294 0.082 -0.275 0.068 -0.255 0.016 -0.236 -0.039\r\n%-0.216 -0.043 -0.196 0.011 -0.177 0.028 -0.157 -0.022 -0.138 0.014\r\n%-0.118 -0.014 -0.098 -0.005 -0.079 -0.005 -0.059 -0.001 -0.040 0.001\r\n%-0.020 0.000 0 0\r\n%0.020 0.000 0.040 -0.001 0.059 0.001 0.079 0.005 0.098 0.005\r\n%0.118 0.014 0.138 -0.014 0.157 0.022 0.177 -0.028 0.196 -0.011\r\n%0.216 0.043 0.236 0.039 0.255 -0.016 0.275 -0.068 0.294 -0.082\r\n%0.314 -0.054 0.334 0.001 0.353 0.063 0.373 0.117 0.392 0.152\r\n%0.412 0.165 0.432 0.156 0.451 0.128 0.471 0.084 0.490 0.030\r\n%0.510 -0.032 0.530 -0.096 0.549 -0.161 0.569 -0.223 0.588 -0.280\r\n%0.608 -0.332 0.628 -0.377 0.647 -0.415 0.667 -0.445 0.686 -0.467\r\n%0.706 -0.481 0.726 -0.488 0.745 -0.488 0.765 -0.481 0.784 -0.468\r\n%0.804 -0.448 0.824 -0.423 0.843 -0.392 0.863 -0.357 0.882 -0.317\r\n%0.902 -0.272 0.922 -0.224 0.941 -0.173 0.961 -0.118 0.980 -0.060\r\n%1.000 0.000 /\r\n%\\plot -1 1 0 0 1 1 /\r\n%\\plot -1 -1 0 0 1 -1 /\r\n%\\endpicture}}\r\n%\\caption{The squeeze theorem. \\label{fig:squeeze}}\r\n%\\endfigure\r\n\r\n%\\begin{figure}[!ht]\r\n%$$\\includegraphics[width=3.0in]{images2/squeeze-theorem}$$\r\n%\\caption{The squeeze theorem. \\label{fig:squeeze}}\r\n%\\end{figure}\r\n%\r\n%To compute $\\ds\\lim_{x\\to0}\r\n%(\\sin x)/x$, we will find two simpler functions $g$ and $h$ so that \r\n%$g(x)\\le (\\sin x)/x\\le h(x)$, and so that\r\n%$\\lim_{x\\to0}g(x)=\\lim_{x\\to0}h(x)$. Not too surprisingly, this will\r\n%require some trigonometry and geometry. Referring to\r\n%figure~\\ref{fig:hard limit}, $x$ is the measure of the angle in\r\n%radians. Since the circle has radius 1, the coordinates of point $A$\r\n%are $(\\cos x,\\sin x)$, and the area of the small triangle is \r\n%$(\\cos x\\sin x)/2$. This triangle is completely contained within the\r\n%circular wedge-shaped region bordered by two lines and the circle from\r\n%$(1,0)$ to point $A$. Comparing the areas of the triangle and the\r\n%wedge we see\r\n%$(\\cos x\\sin x)/2 \\le x/2$, since the area of a circular region with\r\n%angle $\\theta$ and radius $r$ is $\\theta r^2/2$. With a little algebra\r\n%this turns into $(\\sin x)/x \\le 1/\\cos x$, giving us the $h$ we seek.\r\n%\r\n%\\figure[!ht]\r\n%\\centerline{\\vbox{\\beginpicture\r\n%\\normalgraphs\r\n%%\\ninepoint\r\n%\\setcoordinatesystem units <4truecm,4truecm>\r\n%\\setplotarea x from 0 to 1, y from 0 to 1\r\n%\\circulararc 90 degrees from 1 0 center at 0 0\r\n%\\axis left ticks numbered from 0 to 1 by 1 /\r\n%\\axis bottom ticks numbered from 1 to 1 by 1 /\r\n%\\putrule from  0.8660254040 0 to 0.8660254040 0.5\r\n%\\putrule from  1 0 to 1 .577\r\n%\\plot 0 0 1 .577 /\r\n%\\put {$x$} [bl] <5pt,2.5pt> at 0.1 0\r\n%\\put {$A$} [r] <-6pt,2pt> at 0.8660254040 0.5\r\n%\\put {$B$} [bl] <3pt,3pt> at 1  .577\r\n%\\circulararc 30 degrees from 0.1 0 center at 0 0\r\n%\\endpicture}}\r\n%\\caption{Visualizing $\\sin x / x$. \\label{fig:hard limit}}\r\n%\\endfigure\r\n%\r\n%To find $g$, we note that the circular wedge is completely contained\r\n%inside the larger triangle. The height of the triangle, from $(1,0)$\r\n%to point $B$, is $\\tan x$, so comparing areas we get\r\n%$x/2 \\le (\\tan x)/2 = \\sin x / (2\\cos x)$. With a little algebra this\r\n%becomes $\\cos x \\le (\\sin x)/x$. So now we have \r\n%$$ \\cos x \\le {\\sin x\\over x}\\le {1\\over\\cos x}.$$\r\n%Finally, the two limits $\\lim_{x\\to0}\\cos x$ and $\\lim_{x\\to0}1/\\cos x$\r\n%are easy, because $\\cos(0)=1$. By the squeeze theorem,\r\n%$\\lim_{x\\to0} (\\sin x)/x = 1$ as well.\r\n%\r\n%Using the above, we can compute a similar limit:\r\n%$$\\lim_{x\\to0}{\\cos x - 1\\over x}.$$\r\n%This limit is just as hard as $\\sin x/x$, but closely related to it,\r\n%so that we don't have to do a similar calculation; instead we can do a\r\n%bit of tricky algebra.\r\n%$${\\cos x - 1\\over x}={\\cos x - 1\\over x}{\\cos x+1\\over\\cos x+1}\r\n%={\\cos^2 x - 1\\over x(\\cos x+1)}={-\\sin^2 x\\over x(\\cos x+1)}=\r\n%-{\\sin x\\over x}{\\sin x\\over \\cos x + 1}.$$\r\n%To compute the desired limit it is sufficient to compute the limits of\r\n%the two final fractions, as $x$ goes to 0. The first of these is the\r\n%hard limit we've just done, namely 1. The second turns out to be\r\n%simple, because the denominator presents no problem:\r\n%$$\\lim_{x\\to0}{\\sin x\\over \\cos x + 1}={\\sin 0\\over \\cos 0+1}=\r\n%{0\\over 2}  = 0.$$\r\n%Thus,\r\n%$$\\lim_{x\\to0}{\\cos x - 1\\over x}=0.$$\r\n\r\n\r\n\r\nWhen solving problems using the Squeeze Theorem it is also helpful to have the following theorem.\r\n\r\n\\begin{theorem}{Monotone Limits}{MonotoneLimits}\\label{MonotoneLimits} \r\nIf $f(x)\\leq g(x)$ when $x$ is near $a$ (except possibly at $a$) and the limits of $f$ and $g$ both exist as $x$ approaches $a$, then $\\ds\\lim_{x\\to a}f(x)\\leq\\lim_{x\\to a}g(x)$.\r\n\\end{theorem}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for \\ref{sec:TrigLimits}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nCompute the following limits.\r\n\\begin{enumerate}\r\n\t\\item\t$\\ds\\lim_{x\\to 0} {\\sin (5x)\\over x}$\r\n\t\\item\t$\\ds\\lim_{x\\to 0 } {\\sin(7x)\\over\\sin (2x)}$\r\n\t\\item\t$\\ds\\lim_{x\\to 0 } {\\cot (4x) \\over\\csc (3x)}$\r\n\t\\item\t$\\ds\\lim_{x\\to 0 } {\\tan x\\over x}$\r\n\t\\item\t$\\ds\\lim_{x\\to \\pi/4} {\\sin x-\\cos x \\over\\cos (2x)}$\r\n\\end{enumerate}\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\t\\item\t$5$\r\n\t\\item\t$7/2$\r\n\t\\item\t$3/4$\r\n\t\\item\t$1$\r\n\t\\item\t$-\\sqrt2/2$\r\n\\end{enumerate}\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFor all $x\\geq 0$, $4x-9 \\leq f(x) \\leq x^2 - 4x +7$. Find $\\ds\\lim_{x\\to4}f(x)$.\r\n\\begin{sol}\r\n $7$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nFor all $x$, $2x \\leq g(x) \\leq x^4 - x^2 +2$. Find $\\ds\\lim_{x\\to1}g(x)$.\r\n\\begin{sol}\r\n $2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n% % % % % % % % % % %\r\n\\begin{ex}\r\n{Use the Squeeze Theorem where appropriate, to evaluate the given limit.}\r\n\r\n\\begin{enumerate}\r\n\\item {$\\ds \\lim_{x\\to0} x\\sin\\left(\\frac{1}{x}\\right)$}\r\n\r\n\\item {$\\ds \\lim_{x\\to0} \\sin x\\cos\\left(\\frac{1}{x^2}\\right)$}\r\n\r\n\\item {$\\ds \\lim_{x\\to0} x\\sin\\left(\\frac{1}{x}\\right)$}\r\n\r\n\\item {$\\ds \\lim_{x\\to3^+} f(x)$, where $6x-9\\leq f(x) \\leq x^2$ on $[0,3]$.}\r\n\r\n\\end{enumerate}\r\n\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\\item {$0$}\r\n\\item {$0$}\r\n\\item {$0$}\r\n\\item {$9$}\r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\\end{ex}\r\n% % % % % % % % % % % %\r\n\r\n\r\n\r\n\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\nUse the Squeeze Theorem to show that $\\ds\\lim_{x\\to0} x^4 \\cos(2/x)=0$.\r\n\\end{ex}\r\n\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nFind the value of $\\lim_{x\\to\\infty}\\dfrac{3x+\\sin x}{x+\\cos x}$. Justify your steps carefully.\r\n\\begin{sol}\r\n\t$ 3 $\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\r\n% % % % % % % % % % %\r\n\\begin{ex}\r\n{\\noindent The following exercises}\r\n{ challenge your understanding of limits but can be evaluated using the knowledge gained in this section.}\r\n\\begin{enumerate}\r\n\\item {$\\ds \\lim_{x\\to0}\\frac{\\sin 3x}{x}$}\r\n\r\n\\item {$\\ds \\lim_{x\\to0}\\frac{\\sin 5x}{8x}$}\r\n\r\n\\item {$\\ds \\lim_{x\\to0}\\frac{\\ln (1+x)}{x}$}\r\n\r\n\\item {$\\ds \\lim_{x\\to0}\\frac{\\sin x}{x}$, where $x$ is measured in degrees, not radians.}\r\n\r\n\\end{enumerate}\r\n\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\\item {$3$}\r\n\\item {$5/8$}\r\n\\item {$1$}\r\n\\item {$\\pi/180$}\r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\\end{ex}\r\n% % % % % % % % % % % %\r\n\r\n\r\n\\end{enumialphparenastyle}\r\n", "meta": {"hexsha": "699084cb1038679e708c420f4ad9b6ef959fc950", "size": 21440, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3-limits/3-6-trig-limit.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3-limits/3-6-trig-limit.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3-limits/3-6-trig-limit.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.3892339545, "max_line_length": 424, "alphanum_fraction": 0.6304570896, "num_tokens": 8196, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.798186787341014, "lm_q2_score": 0.8887587920192298, "lm_q1q2_score": 0.7093955249229095}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{parskip}\n\\usepackage{svg}\n\\usepackage[utf8]{inputenc}\n\\usepackage{helvet}\n\\renewcommand{\\familydefault}{\\sfdefault}\n\\usepackage{geometry}\n\\usepackage[document]{ragged2e}\n\\geometry{letterpaper, portrait, top=1in, bottom=1in, left=1.5in, right=1.5in}\n\n\\title{Math 301}\n\n\\begin{document}\n\n\\section{Set Notation}\n\\begin{align*}\n    \\mathbb{N} &= natural\\ numbers = \\{0, 1, 2 \\cdots\\} \\\\\n    \\mathbb{Z} &= integers = \\{ \\cdots -2, -1, 0, 1, 2 \\cdots \\}\\\\\n    \\mathbb{Q} &= rational\\ numbers\\ (can\\ be\\ expressed\\ with\\ fractions\\ of\\ two\\ integers) \\\\\n    \\mathbb{R} &= real\\ numbers\\ (rational\\ numbers\\ and\\ irrational\\ numbers)\n\\end{align*}\n\nA is an element of B\n\\begin{gather*}\n    A \\in B\n\\end{gather*}\n\nA is a subset of b\n\\begin{gather*}\n    A \\subseteq B\n\\end{gather*}\n\nThe cardinality of A\n\\begin{gather*}\n    |A|\n\\end{gather*}\n\nComplement of A\n\\begin{gather*}\n    A^C \\\\\n    \\overline{A}\n\\end{gather*}\n\nThe intersection of A and B\n\\begin{gather*}\n    A \\cap B\n\\end{gather*}\n\nThe union of A and B\n\\begin{gather*}\n    A \\cup B\n\\end{gather*}\n\nThe symmetric difference of A and B\n\\begin{gather*}\n    A \\oplus B = (A \\cup B) - (A \\cap B)\n\\end{gather*}\n\n\\section{Cartesian Products}\n\nThe Cartesian product of A and B\n\\begin{gather*}\n    A \\times B = {(a, b) | a \\in A, b \\in B}\n\\end{gather*}\n\n\\begin{gather*}\n    |A \\times B| = |A| \\times |B|\n\\end{gather*}\n\nThe power set of A is the set of all subsets of A.\n\\begin{gather*}\n    \\mathcal{P}(A)\n\\end{gather*}\n\n\\begin{gather*}\n    |\\mathcal{P}(A)| = 2^{|A|}\n\\end{gather*}\n\n\\section{The Rule of Products}\nGiven the number of possibilities for two independent events denoted $|A|$ and $|B|$, the number of possible combinations of both events is $|A| \\times |B|$. You can also say \"the number of ways to do $A$ \\textbf{AND} $B$ is $|A| \\times |B|$.\"\n\n\\section{The Law of Addition}\n\nThe basic law of addition\n\\begin{gather*}\n    |A| = |A_1| + |A_2| + \\cdots + |A_n| = \\sum_{k=1}^{n} |A_k|\n\\end{gather*}\n\nGiven the number of possibilities for two mutually exclusive events denoted $|A|$ and $|B|$, the sum of possible events is $|A| + |B|$. \"The number of ways to do $A$ \\textbf{OR} $B$ is $|A| + |B|$.\"\n\nPartition of a set\n\\begin{gather*}\n    A_1 \\cup A_2 \\cup A_3 \\cup \\cdots = A \\\\\n    A_i \\cap A_j = \\emptyset\\ where\\ i \\neq j\\\n\\end{gather*}\n\nLaw of inclusion-exclusion for two sets\n\n\\begin{gather*}\n    |A_1 \\cup A_2| = |A_1| + |A_2| - |A_1 \\cap A_2|\n\\end{gather*}\n\n\\begin{gather*}\n\\end{gather*}\n\n\\section{Permutation}\nThe total number of ordered sets of $k$ elements taken from a set of $n$ elements\n\\begin{gather*}\n    P(n,k) = \\frac{n!}{(n-k)!}\n\\end{gather*}\n\n\\section{Combination}\nThe total number of unordered sets of $k$ elements taken from a set of $n$ elements\n\\begin{gather*}\n    \\binom{n}{k} = \\frac{n!}{(n-k)!k!}\n\\end{gather*}\n\nBinomial theorem---Allows you to expand $(x+y)^n$.\n\\begin{gather*}\n    (x + y)^n = \\sum_{k=0}^{n} \\binom{n}{k}x^{n-k}y^k\n\\end{gather*}\n\n\\section{Logical operator}\n\nLogical conjunction (AND)\n\\begin{gather*}\n    p \\land q \\\\\n    \\begin{tabular}{c|c|c}\n        p & q & $p \\land q$ \\\\\n        \\hline\n        0 & 0 & 0 \\\\\n        0 & 1 & 0 \\\\\n        1 & 0 & 0 \\\\\n        1 & 1 & 1\n    \\end{tabular}\n\\end{gather*}\n\nLogical disjunction (OR)\n\\begin{gather*}\n    p \\lor q \\\\\n    \\begin{tabular}{c|c|c}\n        p & q & $p \\lor q$ \\\\\n        \\hline\n        0 & 0 & 0 \\\\\n        0 & 1 & 1 \\\\\n        1 & 0 & 1 \\\\\n        1 & 1 & 1\n    \\end{tabular}\n\\end{gather*}\n\nLogical negation\n\\begin{gather*}\n    \\neg p \\\\\n    \\begin{tabular}{c|c}\n        p & $\\neg p$ \\\\\n        \\hline\n        0 & 1 \\\\\n        1 & 0\n    \\end{tabular}\n\\end{gather*}\n\nConditional statement (if $p$ is true then $q$ is also true)\n\\begin{gather*}\n    p \\rightarrow q \\\\\n    \\begin{tabular}{c|c|c}\n        p & q & $p \\rightarrow q$ \\\\\n        \\hline\n        0 & 0 & 1 \\\\\n        0 & 1 & 1 \\\\\n        1 & 0 & 0 \\\\\n        1 & 1 & 1\n    \\end{tabular}\n\\end{gather*}\n\nConverse\n\\begin{gather*}\n    p \\leftarrow q \\\\\n    or \\\\\n    q \\rightarrow p\n\\end{gather*}\n\nContrapositive\n\\begin{gather*}\n    \\neg q \\rightarrow \\neg p \\\\\n    \\begin{tabular}{c|c|c}\n        p & q & $\\neg q \\rightarrow \\neg p$ \\\\\n        \\hline\n        0 & 0 & 1 \\\\\n        0 & 1 & 1 \\\\\n        1 & 0 & 0 \\\\\n        1 & 1 & 1\n    \\end{tabular}\n\\end{gather*}\n\nBiconditional (XNOR)\n\\begin{gather*}\n    p \\leftrightarrow q \\\\\n    \\begin{tabular}{c|c|c}\n        p & q & $p \\leftrightarrow q$ \\\\\n        \\hline\n        0 & 0 & 1 \\\\\n        0 & 1 & 0 \\\\\n        1 & 0 & 0 \\\\\n        1 & 1 & 1\n    \\end{tabular}\n\\end{gather*}\n\nSheffer stroke (NAND)\n\\begin{gather*}\n    p | q \\\\\n    \\begin{tabular}{c|c|c}\n        p & q & $p | q$ \\\\\n        \\hline\n        0 & 0 & 1 \\\\\n        0 & 1 & 1 \\\\\n        1 & 0 & 1 \\\\\n        1 & 1 & 0\n    \\end{tabular}\n\\end{gather*}\n\nOrder of precedence of propositions\n\\begin{enumerate}\n    \\item Parentheses\n    \\item Negation\n    \\item Conjunction\n    \\item Disjunction\n    \\item Conditional statement\n    \\item Biconditional\n\\end{enumerate}\n\n\\section{Equivalence and implication}\n\nTautology: An expression that is true in all cases\n\nContradiction: An expression that is false for all cases\n\nEquivalence ($r \\leftrightarrow s$ is a tautology)\n\\begin{gather*}\n    r \\Leftrightarrow s\n\\end{gather*}\n\nImplication (r implies s)\n\\begin{gather*}\n    r \\Rightarrow s\n\\end{gather*}\n\n\\section{Laws of logic}\n\nDuality principle: Each law of logic can be used to derive a second law by switching the symbols $\\land$ with $\\lor$, $1$ with $0$ and visa versa.\n\nCommutative laws\n\\begin{gather*}\n    p \\lor q \\Leftrightarrow q \\lor p \\\\\n    p \\land q \\Leftrightarrow q \\land p\n\\end{gather*}\n\nAssociative laws\n\\begin{gather*}\n    (p \\lor q) \\lor r \\Leftrightarrow p \\lor (q \\lor r) \\\\\n    (p \\land q) \\land r \\Leftrightarrow p \\land (q \\land r)\n\\end{gather*}\n\nDistributive laws\n\\begin{gather*}\n    p \\land (q \\lor r) \\Leftrightarrow (p \\land q) \\lor (p \\land r) \\\\\n    p \\lor (q \\land r) \\Leftrightarrow (p \\lor q) \\land (p \\lor r) \\\\\n\\end{gather*}\n\nIdentity laws\n\\begin{gather*}\n    p \\lor 0 \\Leftrightarrow p \\\\\n    p \\land 1 \\Leftrightarrow p\n\\end{gather*}\n\nNegation laws\n\\begin{gather*}\n    p \\land \\neg p \\Leftrightarrow 0 \\\\\n    p \\lor \\neg p \\Leftrightarrow 1\n\\end{gather*}\n\nIdempotent laws\n\\begin{gather*}\n    p \\lor p \\Leftrightarrow p \\\\\n    p \\land p \\Leftrightarrow p\n\\end{gather*}\n\nNull laws\n\\begin{gather*}\n    p \\land 0 \\Leftrightarrow 0 \\\\\n    p \\lor 1 \\Leftrightarrow 1\n\\end{gather*}\n\nAbsorption laws\n\\begin{gather*}\n    p \\land (p \\lor q) \\Leftrightarrow p \\\\\n    p \\lor (p \\land q) \\Leftrightarrow p\n\\end{gather*}\n\nDeMorgan's laws\n\\begin{gather*}\n    \\neg (p \\lor q) \\Leftrightarrow (\\neg p) \\land (\\neg q) \\\\\n    \\neg (p \\land q) \\Leftrightarrow (\\neg p) \\lor (\\neg q)\n\\end{gather*}\n\nInvolution law\n\\begin{gather*}\n    \\neg (\\neg p) \\Leftrightarrow p\n\\end{gather*}\n\nDetachment\n\\begin{gather*}\n    (p \\rightarrow q) \\land p \\Rightarrow q\n\\end{gather*}\n\nIndirect reasoning\n\\begin{gather*}\n    (p \\rightarrow q) \\land \\neg q \\Rightarrow \\neg p\n\\end{gather*}\n\nDisjunctive addition\n\\begin{gather*}\n    p \\Rightarrow (p \\lor q)\n\\end{gather*}\n\nConjunctive simplification\n\\begin{gather*}\n    (p \\land q) \\Rightarrow p \\\\\n    (p \\land q) \\Rightarrow q\n\\end{gather*}\n\nDisjunctive simplification\n\\begin{gather*}\n    (p \\lor q) \\land \\neg p \\Rightarrow q \\\\\n    (p \\lor q) \\land \\neg q \\Rightarrow p\n\\end{gather*}\n\nChain rule\n\\begin{gather*}\n    (p \\rightarrow q) \\land (q \\rightarrow r) \\Rightarrow (p \\rightarrow r)\n\\end{gather*}\n\nConditional equivalence\n\\begin{gather*}\n    p \\rightarrow q \\Leftrightarrow \\neg p \\lor q\n\\end{gather*}\n\nBiconditional equivalences\n\\begin{gather*}\n    (p \\leftrightarrow q) \\Leftrightarrow (p \\rightarrow q) \\land (q \\rightarrow p) \\Leftrightarrow (p \\land q) \\lor (\\neg p \\land \\neg q)\n\\end{gather*}\n\nContrapositive\n\\begin{gather*}\n    (p \\rightarrow q) \\Leftrightarrow (\\neg q \\rightarrow \\neg p)\n\\end{gather*}\n\n\\section{Propositions over a Universe}\n\nIf $p$ is a proposition over $U$, the truth set of $p$ is $T_p = \\{a \\in U | p(a)\\ is\\ true\\}$.\n\n\\section{Mathematical induction}\n\nMathematical induction is a way to prove a proposition over natural numbers.\n\n\\begin{enumerate}\n    \\item Prove the basis of the statement, $P(n)$ where $n = 0$.\n    \\item Assume the statement is true for $n - 1$. Prove $P(n-1) \\Rightarrow P(n)$.\n\\end{enumerate}\n\nStronk induction\n\n\\begin{enumerate}\n    \\item Prove the bases of the statement, $P(m)$, for an arbitrary $m > 0$.\n    \\item Assume the statement is true for $k$ where $m \\leq k < n$. Prove $P(k) \\Rightarrow n$.\n\\end{enumerate}\n\n\\section{Quantifiers}\n\nThe existential quantifier states that there exists an $n$ such that $p(n)$ is true.\n\\begin{gather*}\n    (\\exists n)(p(n))\n\\end{gather*}\n\nThe universal quantifier states that for all $n$ in $U$, $p(n)$ is true.\n\\begin{gather*}\n    (\\forall n)(p(n))\n\\end{gather*}\n\nNegation of quantified propositions\n\\begin{gather*}\n    \\neg ((\\forall n)(p(n))) \\Leftrightarrow (\\exists n)(\\neg p(n)) \\\\\n    \\neg ((\\exists n)(p(n))) \\Leftrightarrow (\\forall n)(\\neg p(n))\n\\end{gather*}\n\nMultiple quantifiers of the same type can be arranged in any order, but mixed quantifiers cannot be exchanged.\n\n\\section{Proofs for sets}\n\nYou can prove set propositions using Venn diagrams, truth tables (true indicating that $x \\in A$ or with definitions.\n\nTo prove that $A \\subseteq B$, show that $x \\in A$ and $x \\in B$. \\\\\nTo prove that $A = B$, show that $A \\subseteq B$ and $B \\subseteq A$.\n\n\\section{Laws of set theory}\n\nCommutative laws\n\\begin{gather*}\n    A \\cup B = B \\cup A \\\\\n    A \\cap B = B \\cap A\n\\end{gather*}\n\nAssociative laws\n\\begin{gather*}\n    A \\cup (B \\cup C) = (A \\cup B) \\cup C \\\\\n    A \\cap (B \\cap C) = (A \\cap B) \\cap C\n\\end{gather*}\n\nDistributive laws\n\\begin{gather*}\n    A \\cap (B \\cup C) = (A \\cap B) \\cup (A \\cap C) \\\\\n    A \\cup (B \\cap C) = (A \\cup B) \\cap (A \\cup C)\n\\end{gather*}\n\nIdentity laws\n\\begin{gather*}\n    A \\cup \\emptyset = A \\\\\n    A \\cap U = A\n\\end{gather*}\n\nComplement laws\n\\begin{gather*}\n    A \\cup \\overline{A} = U \\\\\n    A \\cap \\overline{A} = \\emptyset\n\\end{gather*}\n\nIdempotent laws\n\\begin{gather*}\n    A \\cup A = A \\\\\n    A \\cap A = A\n\\end{gather*}\n\nNull laws\n\\begin{gather*}\n    A \\cup U = U \\\\\n    A \\cap \\emptyset = \\emptyset\n\\end{gather*}\n\nAbsorption laws\n\\begin{gather*}\n    A \\cup (A \\cap B) = A \\\\\n    A \\cap (A \\cup B) = A\n\\end{gather*}\n\nDeMorgan's laws\n\\begin{gather*}\n    \\overline{A \\cup B} = \\overline{A} \\cap \\overline{B} \\\\\n    \\overline{A \\cap B} = \\overline{A} \\cup \\overline{B}\n\\end{gather*}\n\nInvolution law\n\\begin{gather*}\n    \\overline{\\overline{A}} = A\n\\end{gather*}\n\n\\section{Relations}\nRelation: Any subset of $A \\times B$\n\nDivides: Let $a,b \\in \\mathbb{Z}, a \\neq 0$. $a | b$ ($a$ divides $b$) if and only if there exists an integer $k$ such that $ak = b$.\n\nRelation notation: If $s$ is a relation from set $A$ into set $B$, the fact that $(x, y) \\in s$ can be written $xsy$.\n\nComposition of relations: Let $r$ be a relation from set $A$ into set $B$, and let $s$ be a relation from set $B$ into set $C$. The composition of $r$ with $s$, written $rs$, is the set of pairs $(a,c) \\in A \\times C$, where $(a, c) \\in rs$ if and only if there exists $b \\in B$ such that $(a,b) \\in r$ and $(b,c) \\in s$.\n\nGraphs can be used to visualize relations, by having the arrows pointing from vertex $a$ to vertex $b$ if $arb$.\n\n\\section{Properties of relations}\n\nReflexive relation: $ara$ for all $a \\in A$\n\nAntisymmetric relation: if $arb$ and $a \\neq b$, then $bra$ is true\n\nSymmetric relation: if $arb$, then $bra$ is true\n\nTransitive relation: if $arb$ and $brc$, then $arc$\n\nA partial ordering on $A$ is a relation on set $A$ that is reflexive, antisymmetric and transitive.\n\nA equivalence relation is a relation that is reflexive, symmetric and transitive.\n\nHasse diagram: A graph can be used to represent a partial ordered set. The reflexive property is implied in every element and loops are not drawn. The antisymmetry property is described by putting the first element go below the second. By the transitive property, edges connecting from one element to a second element and another connecting the second to a third means a third connection can be made from the first to the third.\n\nCongruence modulo\n\\begin{gather*}\n    a = b \\pmod{n} \\Leftrightarrow n | (a - b)\n\\end{gather*}\n\nEquivalence class (Set of all elements that are equal to a given element under a relation)\n\\begin{gather*}\n    a \\in A,\\ r\\text{ is an equivalence relation}\\\\\n    c(a) = \\{b \\in A | arb\\}\n\\end{gather*}\n\n\\section{Matrices of relations}\n\nAdjacency matrix: Let $A = \\{a_1, a_2,..., a_m\\}$ and $B = \\{b_1, b_2,..., b_n\\}$. Let $r$ be a relation from $A$ into $B$. Then $r$ can be represented by the $m \\times n$ matrix $R$ defined by\n\\begin{gather*}\n    R_ij = \n    \\begin{cases}\n        1 & \\text{if}\\ a_i r b_j \\\\\n        0 & \\text{otherwise}\n    \\end{cases}\n\\end{gather*}\n\nComposition as matrix multiplication: If $R_1$ and $R_2$ are the adjacency matrices of $r_1$ and $r_2$ respectively, then the product $R_1 R_2$ using Boolean arithmetic represents the composition $r_1 r_2$.\n\n\\section{Transitive closure}\n\nTransitive closure: Let $A$ be a set and $r$ be a relation on $A$. The transitive closure of $r$, $r^+$, is the smallest transitive relation that contains $r$ as a subset.\n\nIf $r$ is a relation on a set $A$ and $|A| = n$, then the transitive closure of $r$ is the union of the first $n$ powers of $r$.\n\\begin{gather*}\n    r^+ = r \\cup r^2 \\cup r^3 \\cup \\cdots \\cup r^n\n\\end{gather*}\n\nMatrix math can be used to find $R^+$.\n\\begin{gather*}\n    R^+ = R + R^2 + \\cdots + R^n\n\\end{gather*}\n\n\\section{Functions}\n\nA function from set $A$ into set $B$ is a relation from $A$ into $B$ such that each element of $A$ is related to exactly one element of $B$.\n\n\\begin{gather*}\n    f: A \\rightarrow B\n\\end{gather*}\n\nSet $A$ is the domain and set $B$ is the codomain.\n\nIf $f(a) = b$, the image of $a$ is b.\n\nRange: The union of all images of a function's domain. It is a subset of the codomain.\n\nA function can have the domain of a Cartesian product, in which case it is denoted $C: A \\times B \\rightarrow C$ defined by $C(a, b)$\n\n\\section{Properties of functions}\n\nInjective function (one-to-one function): Distinct elements in domain map to distinct elements in codomain\n\\begin{gather*}\n    \\forall a, b \\in A, \\\\\n    f(a) = f(b) \\Rightarrow a = b\\ and \\\\\n    a \\neq b \\Rightarrow f(a) \\neq f(b)\n\\end{gather*}\n\nSurjective function (onto function): Its range is equal to its codomain\n\nBijective function (one-to-one, onto function): Is both injective and surjective.\n\nCountable set: A set that has the same cardinality as a subset of natural numbers.\n\nPigeonhole principle: Let $f$ be a function from a finite set $X$ into a finite set $Y$. If $n \\geq 1$ and $|X| > n|Y|$, then there exists an element of $Y$ that is the image under $f$ of at least $n + 1$ elements of $X$.\n\n\\section{Function composition}\n\nEquality of functions\n\\begin{gather*}\n    function\\ f = function\\ g \\Leftrightarrow (\\forall x)_A(f(x) = g(x))\n\\end{gather*}\n\nTwo functions with different domains cannot be equal, even if the functions have the same equation. Also, two functions can be equal even if they have different equations.\n\nComposition of functions\n\\begin{gather*}\n    g(f(x)) = (g \\circ f)(x)\n\\end{gather*}\n\nAssociativity of functions\n\\begin{gather*}\n    h \\circ (g \\circ f) = (h \\circ g) \\circ f\n\\end{gather*}\n\nComposition of injections and surjections\n\\begin{itemize}\n    \\item If $f: A \\rightarrow B$ and $g: B \\rightarrow C$ are injections, then $g \\circ f: A \\rightarrow C$ is an injection.\n    \\item If $f: A \\rightarrow B$ and $g: B \\rightarrow C$ are surjections, then $g \\circ f: A \\rightarrow C$ is a surjection.\n\\end{itemize}\n\nThe identity function on $A$ is a function from $A$ onto $A$, such that \\\\\n$(\\forall a)_A(i(a) = a)$.\n\nInverse function: Let $f: A \\rightarrow B$ and $g: B \\rightarrow A$. If $g \\circ f = i_A$ and $f \\circ g = i_B$, then $g = f^{-1}$.\n\n$f^{-1}$ exists if and only if $f$ is a bijection.\n\n\\section{Recursion}\n\nTelescoping form: The expanded recursive form for $f(n)$\n\nIteration: Starting with the basis, $f(0)$, and working your way up to $f(n)$.\n\nRecursive definition of the binomial coefficient\n\\begin{gather*}\n    \\binom{n}{0} = 1 \\\\\n    \\binom{n}{n} = 1 \\\\\n    \\binom{n}{k} = \\binom{n-1}{k} + \\binom{n-1}{k-1}, n > k > 0\n\\end{gather*}\n\nRecursive polynomial expression\n\\begin{gather*}\n    p(0) \\in \\mathbb{Z} \\\\\n    p(n) = p(n-1)x + a, a \\in \\mathbb{Z}\n\\end{gather*}\n\nFibonacci sequence\n\\begin{gather*}\n    F_0 = 1, F_1 = 1 \\\\\n    F_k = F_{k-2} + F_{k-1}, k \\geq 2\n\\end{gather*}\n\nClosed form expression: An expression that does not have a runaway number of operations. For example, the number of operations in $\\sum_{k=1}^{n} k$ grows indefinitely with $n$, but $(n(n+1)) / 2$ has 3 operations no matter what $n$ is.\n\nSequence/discrete function: maps natural numbers into a certain set\n\n\\section{Solving recurrence relations}\n\nHomogeneous recurrence relation: $S(k) + C_1 S(k-1) + \\cdots + C_n S(k-n) = 0$\n\nCharacteristic equation: $a^n + C_1 a^{n-1} + \\cdots + C_{n-1} a + C_n = 0$\n\nSolving homogeneous finite order linear relations\n\\begin{enumerate}\n    \\item Use the characteristic equation to solve for $a$, the roots.\n    \\item Write the general solution of the recurrence relation and replace $a_n$. The general solution is $S(k) = b_1 a_1^k + b_2 a_2^k + \\cdots + b_n a_n^k$. If $a_j$ a double root, then $b_j a_j^k$ is replaced with $(b_{j0}+b_{j1} k)a_j^k$.\n    \\item Find $b_n$ using the given initial conditions $S(n)$ and substitute those into the general solution.\n\\end{enumerate}\n\nSolving nonhomogeneous finite order linear relations\n\\begin{enumerate}\n    \\item Write the associated homogeneous relation by changing the right-hand side to $0$ and solve for $a$. The solution for the associated homogeneous relation is $S^{(h)}(k)$.\n    \\item Use the table to find the form of $S^{(p)}(k)$, given the form of the right-hand side. \\\\\n    \\begin{tabular}{c|c}\n            Right-hand side, $f(x)$ & $S^{(p)}(k)$ \\\\\n            $q$ & $d$ \\\\\n            $q_0 + q_q k$ & $d_0 + d_1 k$ \\\\\n            $qa^k$ & $da^k$\n        \\end{tabular}\n    \\item Substitute $S^{(p)}(k)$ into the recurrence relation to find the unknown coefficients.\n    \\item Add the homogeneous relation and the unknown coefficients, \\\\\n    $S^{(h)}(k) + S^{(k)}$ and use the initial conditions to solve for $b$.\n\\end{enumerate}\n\n\\section{Generating function}\n\nGenerating function of a sequence $S$ with terms $S_n$\n\\begin{gather*}\n    G(S;z) = \\sum_{n=0}^{\\infty} S_n z^n = S_0+S_1 z+S_2 z^2+S_3 z^3+\\cdots\n\\end{gather*}\n\nSolving a recurrence relation using generating functions\nTo solve $S(n) - 2S(n-1) - 3S(n-2) = 0, n \\geq 2$, with $S(0) = 3$ and $S(1) = 1$\n\\begin{enumerate}\n    \\item Translate the recurrence relation into an equation about generating functions. \\\\\n        Let $V(n) = S(n) - 2S (n - 1) - 3S (n - 2), n \\geq 2$, with $V(0) = 0$ and $V(1) = 0$.\n        \\begin{equation*}\n        G(V;z) = 0 + 0z +\\sum_{n=2}^{\\infty}  (S(n) - 2S (n - 1) - 3S (n - 2)) z^n= 0\n        \\end{equation*}\n    \\item Solve for the generating function of the unknown sequence, \\\\\n    $G(S;z) = \\sum_{n=0}^{\\infty} S_n z^n$.\n    \\begin{equation*}\n        0 =\\sum_{n=2}^{\\infty} {S(n) z^n-2} \\left(\\sum_{n=2}^{\\infty} S(n-1) z^n\\right)-3\\left(\\sum_{n=2}^{\\infty} S(n-2) z^n\\right)\n    \\end{equation*}\n    The three sums can be written as\n    \\begin{equation*}\n        \\begin{split}\n            \\sum_{n=2}^{\\infty} S_n z^n &=\\sum_{n=0}^{\\infty} S_n z^n - S(0)-S(1)z\\\\\n            &= G(S;z)-3-z\n        \\end{split}\n    \\end{equation*}\n    \\begin{equation*}\n        \\begin{split}\n            \\sum_{n=2}^{\\infty} S(n-1) z^n &=z\\left(\\sum_{n=2}^{\\infty} S(n-1) z^{n-1}\\right)\\\\\n            & =z\\left(\\sum_{n=1}^{\\infty} S(n) z^n\\right)\\\\\n            & = z\\left(\\sum_{n=0}^{\\infty} S(n) z^n-S(0)\\right)\\\\\n            &= z(G(S;z)-3)\n        \\end{split}\n    \\end{equation*}\n    \\begin{equation*}\n        \\begin{split}\n            \\sum_{n=2}^{\\infty} S(n-2) z^n  & = z^2\\left(\\sum_{n=2}^{\\infty} S(n-2) z^{n-2}\\right)\\\\\n            & =z^2G(S;z)\n        \\end{split}\n    \\end{equation*}\n    Therefore\n    \\begin{equation*}\n        \\begin{split}\n            &(G(S;z)-3-z)-2z(G(S;z)-3)-3z^2G(S;z)=0\\\\\n            &G(S;z)=\\frac{3-5z}{1-2z-3z^2}\n        \\end{split}\n    \\end{equation*}\n    \\item Determine the sequence whose generating function is the one from Step 2. Note that $S(n) = ba^n, G(S;z) = \\frac{b}{1-az}$ \\\\\n    Apply partial fractions decomposition to get\n    \\begin{equation*}\n        G(S;z)= \\frac{1}{1-3z}+ \\frac{2}{1+z}\n    \\end{equation*}\n    \\begin{equation*}\n        S(n)=3^n + 2(-1)^n\n    \\end{equation*}\n\\end{enumerate}\n\n\\section{Strategies for proofs}\n\n\\begin{itemize}\n    \\item Draw or write a few examples and notice patterns\n    \\item Find the extreme cases, such as an empty set and a set with the maximum cardinality\n    \\item Consider the contrapositive\n    \\item If the statement is one of the following, it's probably solved through induction: it has a \"$n \\in \\mathbb{N}$\" variable, it has a lot of numbers, and/or you can start with a basis case and build upon that with inductive reasoning\n    \\item If it's not solved using induction, try to approach a direct proof and then a proof by contradiction and decide which is the simplest one\n    \\item For complex proofs that branch out into multiple scenarios, break it down by explaining the various cases\n    \\item Read back the proof to make sure a classmate would understand it and that all variables are defined\n\\end{itemize}\n\n\\section{Graphs}\n\nGraph: $G = (V, E)$, where $V =$ nonempty set of vertices, and $E \\subseteq V \\times V$\n\nIncident = connecting (\"$X$ is incident to vertices $a$ and $b$\")\n\nAdjacent vertices = Vertex pair connected by an edge\n\nThe edges in an undirected graph have no direction, while the edges in a directed graph have direction.\n\nMultigraph: A graph that is permitted to have two or more edges connecting the same vertices.\n\nComplete undirected graph: Each vertices are connected to one another, denoted $K_n$. $K_n$ has ${n \\choose 2}$ edges.\n\nPath length: The number of edges in an edge list.\n\n\\begin{center}\n\\resizebox{\\textwidth}{!}{\n    \\begin{tabular}{ c | c | c | c | c }\n    & Open/Closed & A sequence of edges & Distinct edges & Distinct vertices \\\\\n    \\hline\n    Walk & Open or closed & \\checkmark & & \\\\\n    Trail & Open or closed & \\checkmark & & \\\\\n    Circuit & Closed & \\checkmark & \\checkmark & \\\\\n    Path & Open or closed & \\checkmark & \\checkmark & \\checkmark\\\\\n    Cycle & Closed & \\checkmark & \\checkmark & \\checkmark\n    \\end{tabular}\n}\n\\end{center}\n\nDegree\n\\begin{itemize}\n    \\item The degree is the number of edges connected to the vertex.\n    \\item The outdegree is the number of edges that initiate at a vertex and indegree is the number of edges that terminate at a vertex.\n    \\item The sum of degrees of a graph is $2|E|$\n\\end{itemize}\n\nRegular graph: A graph where each vertex has the same number of degrees. A $n$-regular graph is one where each vertex is $n$ degrees.\n\nSubgraph: A subgraph is a graph $G$ formed from a subset of the vertices and edges of $G$. All edges of the subgraph must connect a vertex pair.\n\nInduced subgraphs contain a subset of vertices from the original graph, and all edges connecting pairs of vertices in that subset.\n\n\\begin{figure}[htb]\n    \\caption{A graph and an induced subgraph}\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{InducedSubgraph_900.png}\n\\end{figure}\n\nSpanning subgraphs contain all vertices of the original graph.\n\n\\begin{figure}[htb]\n    \\caption{A graph and a spanning subgraph}\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{fig-subgraphs.png}\n\\end{figure}\n\nIsomorphic graph\n\n\\begin{itemize}\n    \\item A graph $(V', E')$ is isomorphic to $(V, E)$ if there exists a bijection $f: V \\rightarrow V'$ such that $(v_i, v_j) \\in E$ iff $(f(v_i), f(v_j)) \\in E'$\n    \\item Basically, two isomorphic graphs have the same structure but may have different labels for the vertices\n    \\item Check if two graphs are isomorphic by mapping corresponding vertices of $V$ to those of $E$\n\\end{itemize}\n\nTournament graph: A directed graph that has zero loops and there is only one edge between any two vertices.\n\nComplete/round-robin tournament graph: A tournament graph where all pairs of distinct vertices are connected by one edge.\n\nSingle-elimination tournament graph: A tournament graph where: one vertex called the champion has no edge terminating at it, every other vertex is the terminal vertex of exactly one edge, and there is a path from the champion vertex to every other vertex.\n\n\\begin{figure}[htb]\n    \\caption{A single-elimination tournament graph}\n    \\centering\n    \\includegraphics[width=0.4\\textwidth]{fig-mlb-1983-9-1.png}\n\\end{figure}\n\nBipartite graph: A graph is bipartite if its vertices can be divided into two disjoint and independent sets. Visually, there exists a pair of sets of where a line between the pair cuts all edges.\n\n\\begin{figure}[htb]\n    \\caption{A bipartite graph and its two vertex sets}\n    \\centering\n    \\includesvg[width=0.4\\textwidth]{Simple-bipartite-graph.svg}\n\\end{figure}\n\nDegree sequence: A non-increasing sequence of its vertex degrees.\n\n\\begin{figure}[htb!]\n    \\caption{The degree sequence of this graph is $(4, 3, 2, 2, 1)$}\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{fig-degrees-example-9-1.png}\n\\end{figure}\n\nGraphic sequence: A degree sequence is graphic if there exists an undirected graph that has the same degree sequence. As an example, $(3, 3, 1)$ is not a graphic sequence.\n\nThe complement of a graph $G = (V, E)$ is $\\bar{G} = (V, K - E)$.\n\nEulerian path\n\\begin{itemize}\n    \\item A trail that visits every edge in a graph exactly once\n    \\item A graph has an Eulerian path iff it has exactly 0 or 2 vertices with odd degrees\n    \\item Eulerian circuit: A closed Eulerian path\n    \\item A graph has an Eulerian circuit iff the degrees of all vertices are even\n\\end{itemize}\n\nHamilton path\n\\begin{itemize}\n    \\item A path that visits each vertex exactly once\n    \\item Hamilton cycle/Hamiltonian graph: A Hamilton path that is a cycle\n\\end{itemize}\n\nDistance\n\\begin{itemize}\n    \\item Distance: Number of edges in a shortest path connecting a pair of vertices\n    \\item Eccentricity: Greatest distance between a given vertex and any other vertex\n    \\item Center: The vertex with the minimum eccentricity\n    \\item Radius: Minimum eccentricity of any vertex\n    \\item Diameter: Maximum eccentricity of any vertex\n\\end{itemize}\n\n\\section{Trees}\n\nTree\n\\begin{itemize}\n    \\item An undirected graph that is connected and has no cycles\n    \\item A disconnected graph that has no cycles is a forest\n\\end{itemize}\n\nDijkstra's algorithm: An algorithm for finding the shortest path(s) between all or a pair of vertices in a graph.\n\nImage credits: Al Doerr, Ken Levasseur - Applied Discrete Structures\n\n\\end{document}\n\n", "meta": {"hexsha": "16c02f5d22325d2c13452c444b937edd909dc2cc", "size": 27030, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math-301.tex", "max_stars_repo_name": "MakotoE/math301-notes", "max_stars_repo_head_hexsha": "ad0b206cb2d2abd57fb00d7827cdb0a4a78083c9", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "math-301.tex", "max_issues_repo_name": "MakotoE/math301-notes", "max_issues_repo_head_hexsha": "ad0b206cb2d2abd57fb00d7827cdb0a4a78083c9", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math-301.tex", "max_forks_repo_name": "MakotoE/math301-notes", "max_forks_repo_head_hexsha": "ad0b206cb2d2abd57fb00d7827cdb0a4a78083c9", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5034965035, "max_line_length": 428, "alphanum_fraction": 0.6513133555, "num_tokens": 8856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.798186768138228, "lm_q2_score": 0.8887587927558435, "lm_q1q2_score": 0.7093955084442198}}
{"text": "\\documentclass[a4paper,10pt]{amsart}\r\n\\usepackage{amsfonts}\r\n\\usepackage{amsmath}\r\n\\usepackage{eucal}\r\n\\usepackage{amscd}\r\n\\usepackage{url}\r\n\\usepackage[named]{algo}\r\n\r\n\\newcommand{\\Z}{\\mathbb{Z}}\r\n\\newcommand{\\N}{\\mathbb{N}}\r\n\\newcommand{\\Q}{\\mathbb{Q}}\r\n\\newcommand{\\I}{\\mathbb{I}}\r\n\\newcommand{\\C}{\\mathbb{C}}\r\n\\newcommand{\\R}{\\mathbb{R}}\r\n\\newcommand{\\Pee}{\\mathbb{P}}\r\n\\newcommand{\\EuO}{\\mathcal{O}}\r\n\\newcommand{\\Qbar}{\\overline{\\mathbb{Q}}}\r\n\r\n\\newcommand{\\ljk}[2]{\\left(\\frac{#1}{#2}\\right)}\r\n\\newcommand{\\modulo}[1]{\\;\\left(\\mbox{mod}\\;#1\\right)}\r\n\\newcommand{\\fr}{\\mathfrak}\r\n\r\n\\def\\notdivides{\\mathrel{\\kern-3pt\\not\\!\\kern4.5pt\\bigm|}}\r\n\\def\\nmid{\\notdivides}\r\n\\def\\nsubseteq{\\mathrel{\\kern-3pt\\not\\!\\kern2.5pt\\subseteq}}\r\n\r\n\\newtheorem{theorem}{Theorem}[section]\r\n\\newtheorem{lemma}[theorem]{Lemma}\r\n\\newtheorem{proposition}[theorem]{Proposition}\r\n\\newtheorem{corollary}[theorem]{Corollary}\r\n\\newtheorem{definition}[theorem]{Definition}\r\n\r\n\\newenvironment{example}[1][Example]{\\begin{trivlist}\r\n\\item[\\hskip \\labelsep {\\bfseries #1}]}{\\end{trivlist}}\r\n\r\n\\parindent=0pt\r\n\\parskip 4pt plus 2pt minus 2pt \r\n\r\n\\email{W.B.Hart@warwick.ac.uk}\r\n\r\n\\title{Computation of quadratic forms}\r\n\\author{William Hart}\r\n\r\n\\begin{document}\r\n\\maketitle\r\n\r\n\\section{Introduction}\r\n\r\n\\begin{definition}\r\nGiven an integer $n \\geq 1$ an \\emph{$n$-ary quadratic form} is an expression\r\n\\begin{equation}\\label{qf}\r\nQ(x_1, x_2, \\ldots, x_n) = \\sum_{i,j=1}^{\\infty} a_{ij}x_ix_j,\r\n\\end{equation}\r\nfor coefficients $a_{ij}$ in some commutative ring $R$ and variables $x_1, x_2, \\ldots, x_n$.\r\n\\end{definition}\r\n\r\nWe say that a quadratic form is \\emph{integral} if the coefficients $a_{ij}$ are rational integers.\r\n\r\nIf we write $A = (a_{ij})$ for the matrix of coefficients and $X = (x_1, x_2, \\ldots, x_n)^T$ for the column vector of variables, then we can write (\\ref{qf}) as\r\n\\begin{equation}\r\nQ = X^TAX.\r\n\\end{equation}\r\n\r\nA quadratic form in two variables is called a \\emph{binary quadratic form}. If we write $x, y$ for the variables, it has the form\r\n\\begin{equation}\\label{abc}\r\nQ(x, y) = ax^2 + bxy + cy^2.\r\n\\end{equation}\r\n\r\nWe will often use the notation $Q := (a, b, c)$ to denote the binary quadratic form (\\ref{abc}).\r\n\r\n\\begin{definition}\r\nThe \\emph{discriminant} of a binary quadratic form $(a, b, c)$ is the expression $d = b^2 - 4ac$.\r\n\\end{definition}\r\n\r\nWe observe that \r\n\\begin{equation}\r\n4aQ(x, y) = 4a^2x^2 + 4abxy + 4acy^2 = (2ax + by)^2 - dy^2,\r\n\\end{equation}\r\nwhere $d$ is the discriminant of $Q := (a, b, c)$.\r\n\r\nFrom this we see that $(a, b, c)$ is always nonnegative if $d < 0$ and $a > 0$. In this case we call the quadratic form a \\emph{positive definite} binary quadratic form. If $a < 0$ and $d < 0$ we say that it is a \\emph{negative definite} binary quadratic form. If $d > 0$ the form is called an \\emph{indefinite} binary quadratic form.\r\n\r\n\\section{Positive definite binary quadratic forms}\r\n\r\nIn this section we restrict our attention to integral binary quadratic forms. We also restrict to forms which are \\emph{primitive}, i.e. forms $Q := (a, b, c)$ such that $a, b, c$ do not share a common factor.\r\n\r\nWe now introduce the concept of equivalent forms.\r\n\r\n\\begin{definition}\r\nWe say that binary quadratic forms $P(x, y)$ and $Q(x, y)$ are \\emph{equivalent} if there is an $M \\in$ GL$_2(\\mathbb{Z})$ such that \r\n\\begin{equation}\\label{equiv}\r\nP(x, y) = Q(M(x, y)^T)\r\n\\end{equation}\r\n\\end{definition}\r\n\r\nMatrices in GL$_2(\\mathbb{Z})$ have determinant $\\pm 1$. We say that forms are \\emph{properly equivalent} if the matrix $M$ in (\\ref{equiv}) has determinant $1$, otherwise they are \\emph{improperly equivalent}.\r\n\r\nWe see immediately that equivalent forms $P(x, y)$ and $Q(x, y)$ represent precisely the same set of integers as $x, y$ vary over $\\mathbb{Z}$ because the matrix $M$, and hence the equivalence of forms, is invertible.\r\n\r\nIt will turn out that there are only finitely many GL$_2(\\mathbb{Z})$ orbits of positive definite binary quadratic forms. \r\n\r\n\\begin{lemma}\r\nIf two binary quadratic forms $P(x, y) := (a, b, c)$ and $Q(x, y) := (a', b', c')$ are properly equivalent they have the same discriminant.\r\n\\end{lemma}\r\n\r\n\\textbf{Proof:} \r\nIf two forms are properly equivalent then $Q(x, y) = P(M(x, y)^T)$ for some $M \\in$ SL$_2(\\mathbb{Z})$. But this group is generated by $T = \\left(\\begin{array}{cc}1 & 1 \\\\ 0 & 1 \\end{array}\\right)$ and $S = \\left(\\begin{array}{cc}0 & -1 \\\\ 1 & 0 \\end{array}\\right)$.\r\n\r\nThe transformation $T$ sends $(a, b, c)$ to $(a, b + 2a, a + b + c)$ and its inverse sends $(a, b, c)$ to $(a, b - 2a, a - b + c)$, whereas the transformation $S$ sends $(a, b, c)$ to $(c, -b, a)$ (note that $S^4 = 1$ so that $S^{-1} = S^3$). In both cases we see that the discriminant is preserved. $\\qed$\r\n\r\nLegendre introduced a concept of reduced binary quadratic form which we now explore. This allows us to find a ``smallest'' such form in each GL$_2(\\mathbb{Z})$ orbit by a process known as reduction.\r\n\r\n\\begin{definition}A positive definite binary quadratic form is said to be \\emph{reduced} if \r\n\\begin{equation}\\label{reduced}\r\n|b| \\leq a \\leq c, \\;\\mbox{and}\\; b \\geq 0 \\;\\mbox{if either}\\; |b| = a \\;\\mbox{or}\\; a = c.\r\n\\end{equation}\r\n\\end{definition}\r\n\r\nWe now proceed to show that there is a unique reduced form in each GL$_2(\\mathbb{Z})$ orbit. We require some intermediate results.\r\n\r\n\\begin{lemma}\r\nLet $Q(x, y) := (a, b, c)$ be a reduced positive definite binary quadratic form with discriminant $d \\neq -3$. The minimum value taken by $Q(x, y)$ as $x, y$ not both zero range over the integers is $a$. If $a = c$ this value is taken at $(x, y) = (\\pm 1, 0)$ and $(0, \\pm 1)$, otherwise it is only taken at $(\\pm 1, 0)$.\r\n\\end{lemma}\r\n\r\n\\textbf{Proof:} As $Q$ is reduced we have that $|b| \\leq a \\leq c$. Thus \r\n\\begin{equation}\r\nQ(x, y) \\geq (a - |b| + c)\\,\\mbox{min}(x^2, y^2).\r\n\\end{equation}\r\n\r\nIf neither $x$ or $y$ are zero then $Q(x, y) \\geq a - |b| + c \\geq a$. Similarly if $x = 0$ or $y = 0$ then $Q(x, y) \\geq a$. \r\n\r\nIf $a = c$ then $|b| \\neq a$ otherwise $Q$ is not primitive (if $a = b = c = 1$ then $d = -3$).\r\n\r\nThus if $xy \\neq 0$ then $Q(x, y) > a$. So the only time $Q(x, y) = a$ is if $x = 0$ or $y = 0$. In the first case we have $(x, y) = (0, \\pm 1)$ and in the second case $(x, y) = (\\pm 1, 0)$. \r\n\r\nThe other possibility is that $a < c$. In this case, if $xy \\neq 0$ then $Q(x, y) \\geq (a - |b|) + c > a$. Clearly the only remaining possibility is $(x, y) = (\\pm 1, 0)$. $\\qed$\r\n\r\nIn the case where $d = -3$ it is clear that the form $Q(x, y) = x^2 + xy + y^2$ is an exception. In this case we see that the minimum value is $1$, taken at $(x, y) = (\\pm 1, 0)$, $(0, \\pm 1)$, $(1, -1)$ and $(-1, 1)$. \r\n \r\n\\begin{theorem}\r\nIf $P(x, y) := (a, b, c)$, $Q(x, y) = (a', b', c')$ are properly equivalent reduced positive definite binary quadratic forms then $P = Q$.\r\n\\end{theorem}\r\n\r\n\\textbf{Proof:}\r\nWe assume for the moment that $d \\neq -3$. \r\n\r\nAs $P$ and $Q$ are properly equivalent there exist integers $\\alpha, \\beta, \\gamma, \\delta$ with $\\alpha\\delta - \\beta\\gamma = 1$ such that $Q(x, y) = P(\\alpha x + \\beta y, \\gamma x + \\delta y)$. \r\n\r\nBy the previous theorem, $P$ and $Q$ have the same minimum value, thus $a' = a$. \r\n\r\nIf $a = c$ then $P$ achieves its minimum value at $(\\pm 1, 0)$ and $(0, \\pm 1)$. Therefore $a = Q(1, 0) = P(\\alpha, \\gamma)$. Thus $(\\alpha, \\gamma) = (\\pm 1, 0)$, or $(0, \\pm 1)$.\r\n\r\nIn the first case, $(\\beta, \\delta) = (r, \\pm 1)$ for some integer $r$. Thus $Q(x, y) = P(\\pm x + ry, \\pm y)$. Thus $b' = b \\pm 2ar$. By the fact that $Q$ is reduced, we see that $r = 0$, $b' = b$ and $c = c'$. Thus the forms are equal.\r\n\r\nIn the second case $(\\beta, \\delta) = (\\mp 1, r)$. Thus $Q(x, y) = P(\\mp y, \\pm x + ry)$. Thus $b' = -b \\pm 2cr$. Again we see that $r = 0$ and $b' = -b$. Here we must have $a = c = c'$ and so $b, b' \\geq 0$. This means that $b' = 0$ and the forms are equal.\r\n\r\nWhen $a < c$ we have that $P$ achieves its minimum at $(\\pm 1, 0)$. The argument here is the same as for the first case above.\r\n\r\nFinally, when $d = -3$ we have $-3 = b^2 - 4ac \\leq a^2 - 4a^2 = -3a^2$. Thus $a = 1$. But this implies that $b = \\pm 1$ and thus $c = 1$. But the form is reduced, thus $b = 1$. So we see there is only one reduced form of discriminant $d = -3$ and the result follows. $\\qed$\r\n\r\n\\begin{theorem}\r\nEvery positive definite binary quadratic form is properly equivalent to a unique reduced binary quadratic form.\r\n\\end{theorem}\r\n\r\n\\textbf{Proof:} We have already shown uniqueness, thus it suffices to show that every form $P(x, y) := (a, b, c)$ is properly equivalent to a reduced one.\r\n\r\nLet $Q := (a', b', c')$ be a form properly equivalent to $P$ with minimum positive $a'$. As the discriminants of $P$ and $Q$ are the same we must have $c' > 0$. \r\n\r\nThe transformation $U = \\left(\\begin{array}{cc}1 & u \\\\ 0 & 1 \\end{array}\\right)$ sends $Q$ to $Q' = (a'', b'', c'') = (a', b' + 2ua', c'')$. We can therefore choose $u$ so that $|b''| \\leq a''$. \r\n\r\nBut the transformation $S$ above sends $(a'', b'', c'')$ to $(c'', -b'', a'')$ and therefore $a'' = a' \\leq c''$ by the choice of $a'$. \r\n\r\nThus every class contains a form $(a, b, c)$ with $|b| \\leq a \\leq c$.\r\n\r\nThis form is already reduced unless $b < 0$ and either $a = -b$ or $a = c$. In both cases $(a, -b, c)$ is reduced. \r\n\r\nIn the first case $(a, -a, c)$ is sent to $(a, a, c)$ by the transformation $T$ above and in the second case $(a, b, a)$ is sent to $(a, -b, a)$ by the transformation $S$ above. \r\n\r\nTherefore in both cases $(a, b, c)$ is properly equivalent to $(a, -b, c)$ and the theorem is proved. $\\qed$\r\n\r\n\\begin{theorem}\\label{ineq}\r\nIf $P(x, y) := (a, b, c)$ is a positive definite reduced form of discriminant $d$ then $|b| \\leq a \\leq \\sqrt{|d|/3}$ and $c \\leq (1-d)/4$. \r\n\\end{theorem}\r\n\r\n\\textbf{Proof:}\r\nAs the form is reduced, we have $-d = 4ac - b^2 \\geq 4a^2 - a^2 = 3a^2$, and the first part of the result follows. \r\n\r\nFor the second part we note that\r\n$$c = \\frac{b^2 - d}{4a} \\leq \\frac{a^2 - d}{4a}.$$\r\n\r\nFor constant $d$ this expression has negative derivative with respect to $a$ in the interval $[1, \\sqrt{|d|}]$ and is therefore decreasing. It therefore achieves its maximum value at $a = 1$ which gives the required result.$\\qed$\r\n\r\nThe average value of $h(d)$, the number of reduced forms of discriminant $d$, is known to be asymptotic to $C\\pi^{-1}\\sqrt{|d|}$ where $C \\approx 0.8815$ and in fact $h(d)$ is unconditionally bounded above by $O(\\sqrt{|d|}\\log{|d|})$ (see \\cite{cohen}).\r\n\r\nOur first algorithm for computing all the primitive reduced binary quadratic forms for a disciminant $d < 0$ is essentially that of \\cite{buchmann}. \r\n\r\n\\begin{algorithm}{ReducedForms1}{\r\n   \\qcomment{Compute primitive reduced binary quadratic forms for $d < 0$}}\r\nA $\\qlet \\sqrt{-d/3}$ \\\\\r\n$h \\qlet 0$ \\\\\r\n$L \\qlet \\emptyset$ \\\\\r\n\\qfor $a \\qlet 1$ \\qto A \\\\\r\n\\qfor $b \\in \\Z$ such that $-a < b \\leq a$ and $b^2 \\equiv d \\pmod{4a}$ \\\\\r\n$c \\qlet (b^2 - d)/4a$ \\\\\r\n\\qif $(a, b, c)$ is primitive and reduced \\\\\r\n\\qthen $L \\qlet L \\cup \\{(a, b, c)\\}$ \\\\\r\n$h$ \\qlet $h + 1$ \\qfi \\qrof \\qrof \\\\\r\n\\qreturn $L$, $h$\r\n\\end{algorithm}\r\n \r\nThe algorithm makes use of the following observation:\r\nif $P := (a, b, c)$ is a reduced form, then as $d = b^2 - 4ac$\r\nwe have $b^2 \\equiv d \\pmod{4a}$.\r\n\r\nOn the other hand, if $b$ is a square root of $d$ modulo $4a$ in the range $-a < b \\leq a$ then $b^2 = d + 4ac$ for some integer $c$, i.e. $d = b^2 - 4ac$. \r\n\r\n\\textbf{Performance improvements}\r\n\r\n\\begin{itemize}\r\n\\item Most of the run time is in finding square roots modulo $4a$. This can be optimised by using the Tonelli-Shanks algorithm to compute square roots modulo each prime $p$ dividing $4a$ and Hensel lifting the roots to square roots modulo each $p^k \\;|\\; 4a$. These roots can then be combined using the Chinese Remainder Theorem.\r\n\r\n\\item In order to compute the square roots modulo $4a$, the factorisation of $4a$ must be known. It is more efficient to compute the factorisations of all the values $4a$ in advance by sieving. This can be done by sieving by all primes $p$ up to $\\sqrt{A}$ and by every power $p^k \\leq A$ of such such a prime.\r\n\r\n\\item One can precompute square roots of $d$ modulo all powers of primes $p^k \\leq A$ for odd primes $p$ and modulo all $2^k \\leq 4A$. Having been precomputed, these roots can be combined using chinese remaindering to obtain square roots modulo $4a$ for each $a$ in turn.\r\n\r\n\\item In order to compute $c$ we must first compute $b^2 - d$. This can have the value $4|d|/3$ which may cause an overflow, depending on how integers are stored. However, if $d$ is stored as a C long and $b^2 - d$ and $4a$ as C unsigned longs, then no overflow occurs when computing $c = (b^2 - d)/4a$. \r\n\\end{itemize}\r\n\r\n\\textbf{Analysis}\r\n\r\n\\begin{itemize}\r\n\\item Sieving requires computing primes up to $(-d/3)^{1/4}$. There can be at most one prime which exceeds this bound which divides any value $4a$, and it does so with multiplicity at most 1. Thus after dividing through by the highest power of each prime dividing $4a$, we are left with either 1 or a prime $p$. \r\n\r\n\\item Clearly finding all the necessary primes can be completed in time $\\tilde{O}(|d|^{1/4})$.\r\n\r\n\\item Sieving the interval $[1, A]$ for prime factors can be done in time $\\tilde{O}(|d|^{1/2})$. \r\n\r\n\\item Computing square roots modulo $p$ can be done in polynomial time (assuming we can find a quadratic non-residue modulo $p$). Similarly lifting these to roots modulo prime powers can be done in polynomial time, for $p \\;\\notdivides\\; d$. \r\n\r\n\\item If $p \\;|\\; d$ and $p \\;|\\; 4a$, then the number of square roots of $d$ modulo $4a$ is bounded by $4a/p$. Thus, computation of roots modulo values $4a$ divisible by primes dividing $d$ can also be done in time $\\tilde{O}(|d|^{1/2})$.\r\n\r\n\\item Finally, searching for primitive, reduced forms from the roots that are computed takes time $\\tilde{O}(|d|^{1/2})$.\r\n\\end{itemize}\r\n\r\nWe see that the following theorem holds:\r\n\r\n\\begin{theorem}Assuming the Generalised Riemann Hypothesis (required to guarantee efficiently finding a quadratic nonresidue in Tonelli-Shanks), we can find all primitive, reduced binary quadratic forms of discriminant $d < 0$ in time $\\tilde{O}(|d|^{1/2})$. We must compute $\\tilde{O}(|d|^{1/4})$ primes.\r\n\\end{theorem}\r\n\r\nThe algorithm above is quite complicated to implement. In FLINT we only implement the first two of the three performance improvements, and instead of sieving with all powers of the primes $p$, we simply sieve with the primes $p$ and then determine the highest power of $p$ dividing each value $4a$ that it divides.\r\n\r\nThere is an alternative algorithm which is slightly easier to implement and is slightly faster in practice, but it requires the computation of a greater number of primes. This makes it less practical for larger discriminants.\r\n\r\nThe formulation is suggested by Algorithm 5.3.5 of \\cite{cohen}.\r\n\r\n\\begin{algorithm}{ReducedForms2}{\r\n   \\qcomment{Compute primitive reduced binary quadratic forms for $d < 0$}}\r\nB $\\qlet \\sqrt{-d/3}$ \\\\\r\n$h \\qlet 0$ \\\\\r\n$L \\qlet \\emptyset$ \\\\\r\n\\qfor $b \\qlet 1$ \\qto B \\\\\r\n\\qfor $a, c \\in \\N$ such that $ac = (b^2 - d)/4$ \\\\\r\n\\qif $(a, b, c)$ is primitive and reduced \\\\\r\n\\qthen $L \\qlet L \\cup \\{(a, b, c)\\}$ \\\\\r\n$h$ \\qlet $h + 1$ \\qfi \\\\\r\n\\qif $(a, -b, c)$ is primitive and reduced \\\\\r\n\\qthen $L \\qlet L \\cup \\{(a, -b, c)\\}$ \\\\\r\n$h$ \\qlet $h + 1$ \\qfi \\qrof \\qrof \\\\\r\n\\qreturn $L$, $h$\r\n\\end{algorithm}\r\n\r\nThis algorithm relies on being able to factor the expressions $(b^2 - d)/4$. \r\n\r\n\\textbf{Performance improvements}\r\n\r\n\\begin{itemize}\r\n\\item Most of the run time is in factorisation of values $(b^2 - d)/4$. This can be optimised by computing all the prime power factors in advance and then iterating through all possible exponents to find factors $a$. We then compute $c = (b^2 - d)/(4a)$ for each such factor $a$.\r\n\r\n\\item We can use (quadratic) sieving to find all the prime factors of the values $(b^2 - d)/4$ in advance. Suppose that an odd prime $p$ divides $(b^2 - d)/4$. Then $b^2 \\equiv d \\pmod{p}$. We can use the Tonelli-Shanks algorithm to find square roots $r_0, r_1 \\pmod{p}$. We can then mark off all values in the range $[1, B]$ congruent to $r_0$ or $r_1 \\pmod{p}$.\r\n\r\n\\item Once we know for which values of $b$ the expression $(b^2 - d)/4$ is divisible by a given prime $p$, we can simply compute the maximum power of $p$ dividing each such value $(b^2 - d)/4$. This turns out to be faster in practice than sieving with higher powers of $p$. \r\n\r\n\\item We are factoring values $(b^2 - d)/4$. In order to do so, we must first compute $b^2 - d$. Thus the same overflow considerations occur as for the first algorithm.\r\n\\end{itemize}\r\n\r\n\\textbf{Analysis}\r\n\r\n\\begin{itemize}\r\n\\item The largest value $(b^2 - d)/4$ can take is $-d/3$. Thus sieving requires computing primes up to $(-d/3)^{1/2}$. \r\n\r\n\\item Clearly finding all the necessary primes can be completed in time $\\tilde{O}(|d|^{1/2})$.\r\n\r\n\\item Quadratically sieving the interval $[1, B]$ for prime factors can be done in time $\\tilde{O}(|d|^{1/2})$ once the square roots are known. \r\n\r\n\\item Computing square roots modulo $p$ can be done in polynomial time (assuming we can find a quadratic non-residue modulo $p$). \r\n\r\n\\item Finally, searching for primitive, reduced forms from the triples $(a, b, c)$ that are computed takes time $\\tilde{O}(|d|^{1/2})$.\r\n\\end{itemize}\r\n\r\nWe clearly get the same time complexity as for the previous algorithm. However, we now need $\\tilde{O}(|d|^{1/2})$ primes. The advantage is that the algorithm is slightly easier to implement (in FLINT we implement all the listed performance improvements).\r\n\r\nThe version of the second algorithm in FLINT is about 50\\% faster than the first algorithm. Of course, this may be due to not implementing all the performance improvements listed for the first case. \r\n\r\nAs we shall see later, computation of the class number $h$, only, can be completed much faster than computation of the list of reduced forms $L$. \r\n\r\n\\begin{thebibliography}{99}\r\n\r\n\\bibitem{buchmann} J. Buchmann, U. Vollmer \\emph{Binary Quadratic Forms: An Algorithmic Approach}, Springer, 2007.\r\n\r\n\\bibitem{cohen} H. Cohen, \\emph{A Course in Computational Algebraic Number Theory}, Springer, 1996.\r\n\r\n\\end{thebibliography}\r\n\\end{document}\r\n", "meta": {"hexsha": "b8c330a8f33714ef330c2c93473f42a9f638c373", "size": 18316, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "BinaryQuadraticForms.tex", "max_stars_repo_name": "wbhart/ShortMathNotes", "max_stars_repo_head_hexsha": "bb10ca85044cc4767dcdbd5bd41ce530edad3667", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-07-23T15:01:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-10T06:53:30.000Z", "max_issues_repo_path": "BinaryQuadraticForms.tex", "max_issues_repo_name": "wbhart/ShortMathNotes", "max_issues_repo_head_hexsha": "bb10ca85044cc4767dcdbd5bd41ce530edad3667", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "BinaryQuadraticForms.tex", "max_forks_repo_name": "wbhart/ShortMathNotes", "max_forks_repo_head_hexsha": "bb10ca85044cc4767dcdbd5bd41ce530edad3667", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.3312101911, "max_line_length": 364, "alphanum_fraction": 0.6621533086, "num_tokens": 6038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.8652240964782012, "lm_q1q2_score": 0.7093914783897423}}
{"text": "\\section{Statistics}\\label{section:statistics}\n\nRobust predictive modeling and statistical inference are crucial for successful analyses in particle physics.\nThis section will be a very brief tour of these concepts and some of their applications, which will be necessary to understand the analysis that was performed.\n\n\\subsection{Likelihood Ratio}\\label{subsection:likelihood_ratio}\n\n\\subsubsection{Wilk's Theorem}\\label{subsection:wilks_theorem}\n\nIn brief, Wilk's theorem~\\cite{Wilks:1938dza} states that for two functions in a nested family of functions, $f\\left(x\\,\\middle|\\,\\vec{\\theta}_{a}\\right)$ and $f\\left(x\\,\\middle|\\,\\vec{\\theta}_{b}\\right)$, with the number of parameters $a < b$, in the limit of large sample size the likelihood ratio test statistic,%\n\\footnote{As likelihoods are not p.d.f.s and so not required to be normalized, it is seen that $L\\left(\\vec{\\theta}\\right) = f\\left(\\vec{\\theta}\\middle|x\\right)$.}\n\\begin{equation}\n t_{\\vec{\\theta}} = -2 \\log \\frac{\\displaystyle L\\left(\\vec{\\theta}_{a}\\right)}{\\displaystyle L\\left(\\vec{\\theta}_{b}\\right)},\n\\end{equation}\nis asymptotically distributed as a $\\chi^2$ random variable with $d=b-a$ degrees of freedom,\n\\begin{equation}\n \\lim_{\\mathrm{samples}\\to \\infty} t_{\\vec{\\theta}} \\sim \\chi^2_{d}.\\label{eq:wilks_theorem}\n\\end{equation}\nThis asymptotic approximation to the empirical distribution of the test statistic allows for efficient computation of a \\pvalue{} (that approximates the \\pvalue{} under the empirical distribution).\n\nThe one-sided (one-tailed) \\pvalue{} --- given the null hypothesis that $t_{\\vec{\\theta}}$ is $\\chi_{d}^{2}$ distributed --- is then the value of the complementary cumulative distribution function (CCDF) of the $\\chi^2_{d}$ distribution evaluated at the observed $t_{\\vec{\\theta}}$,\n\\begin{equation}\n p\\textrm{-value} = \\textrm{CCDF}_{\\chi^2_{d}}\\left(x=t_{\\vec{\\theta}}\\right).\n\\end{equation}\nThat is to say, the \\pvalue{} is the probability, given $t_{\\vec{\\theta}} \\sim \\chi^2_{d}$, to observe a $t_{\\vec{\\theta}}$ value greater than or equal to that which was observed.\n\n\\subsubsection{Profile Likelihood Ratio}\n\nThe \\gls{MLE} $\\hat{\\theta}$ is the value of the parameter $\\theta$ that maximizes the likelihood function given the observed data.\nSo for parameter of interest $\\mu$ and nuisance parameters $\\vec{\\theta}$, the maximum likelihood estimators are $\\hat{\\mu}$ and $\\hat{\\vec{\\theta}}$.\nLikewise, the conditional maximum likelihood estimator $\\hat{\\hat{\\theta}}$ is the value of the parameter $\\theta$ that maximizes the likelihood for a given value of another parameter $\\mu$.\nSo for a specific value of the parameter of interest $\\mu$, the conditional maximum likelihood estimator for nuisance parameters $\\vec{\\theta}$ is $\\hat{\\hat{\\vec{\\theta}}}$.\nAs $\\hat{\\hat{\\vec{\\theta}}}$ is a function of the given $\\mu$ then it is seen that the likelihood function's dependence on the nuisance parameters $\\vec{\\theta}$ can be ``profiled'' vs. $\\mu$ and removed.\nGiven this, the profile likelihood ratio,\n\\begin{equation}\n \\lambda\\left(\\mu\\right) = \\frac{L\\left(\\mu, \\hat{\\hat{\\vec{\\theta}}}\\right)}{L\\left(\\hat{\\mu}, \\hat{\\vec{\\theta}}\\right)}\\,,\n \\label{eq:profile_likelihood_ratio}\n\\end{equation}\ncan be constructed and used as a test statistic to indicate the compatibility of a possible value $\\mu$ with the MLE $\\hat{\\mu}$ --- a function of the observed data.\nGiven that the negative log likelihood is usually what is actually calculated --- for numerical reasons --- the test statistic that is generally used from the profile likelihood ratio is\n\\begin{equation}\n q_{\\mu} = -2 \\ln \\lambda\\left(\\mu\\right) = 2 \\left(\\ln L\\left(\\hat{\\mu}, \\hat{\\vec{\\theta}}\\right) - \\ln L\\left(\\mu, \\hat{\\hat{\\vec{\\theta}}}\\right)\\right)\\,,\n \\label{eq:q_mu}\n\\end{equation}\nas it is seen by Wilk's theorem, \\Cref{eq:wilks_theorem}, to be distributed according to a $\\chi^{2}$ distribution with one degree of freedom.\nThis results in a \\pvalue{} for $q_{\\mu}$ of\n\\begin{equation}\n p = \\int\\limits_{q_{\\mu}}^{\\infty} f_{\\chi^{2}}\\left(t\\middle|1\\right)\\,dt\\,.\n \\label{eq:q_mu_pvalue}\n\\end{equation}\n\n\\subsection{Intervals and limits}\\label{section:intervals_and_limits}\n\nIn addition to point estimates that determine an estimator, $\\hat{\\theta}$, of a parameter $\\theta$, interval estimates give statistical precision to the measured value.\nA common example of such an interval estimate is the set of points bounded by the point estimate and the estimated standard deviation: $\\left[\\hat{\\theta} - \\sigma_{\\hat{\\theta}}, \\hat{\\theta} + \\sigma_{\\hat{\\theta}}\\right]$.\nThe following is a short discussion of the construction, interpretation, and use of these intervals in the frequentist and Bayesian paradigms.\n\n\\subsubsection{Frequentist Confidence Intervals}\n\nIn the frequentist paradigm, a $1-\\alpha$ confidence level (CL) confidence interval (CI) is an interval estimate that covers the true value of the parameter, $\\theta$, $1-\\alpha$ of the time it is constructed.\nSo the $95\\%$ confidence level confidence interval covers the true value $95\\%$ of the time it is constructed.\nThe method for constructing confidence intervals is called the ``Neyman Construction''~\\cite{Neyman:1937uhy}, and results from inverting hypothesis tests.\nThis confidence interval construction can be described as a random variable that is the set of parameter points, $\\left\\{\\vec{\\theta}\\right\\}$, where the null hypothesis of each parameter point $\\theta$ is accepted, $p\\left(t > k_{\\alpha}\\middle| \\theta\\right) < \\alpha$,\n\n\\begin{equation}\n \\mathrm{CI}_{1-\\alpha} = \\left\\{\\vec{\\theta}\\,\\middle| \\,p\\left(t > k_{\\alpha}\\middle| \\vec{\\theta}\\right) < \\alpha\\right\\}\\,.\n \\label{eq:confidence_interval}\n\\end{equation}\n\nBy construction, a hypothesis test of size $\\alpha$ should accept the null hypothesis, given that the null is true, $(1-\\alpha)$ of the time~\\cite{Cranmer:2015nia}.\n\nIt is very important to take care in interpreting the meaning of the confidence interval, as it is often misunderstood and misused in analysis.\nThe confidence interval is constructed from the observed data%\n\\footnote{The data are a random variable in the frequentist paradigm.}\nand so is a random variable and reflects information regarding the constructed estimator --- not the true parameter.\nThe confidence interval does \\emph{not} give the interval in which there is a $1-\\alpha$ probability of finding the true parameter value.\nThis is manifestly Bayesian and in fact is the interpretation of a Bayesian credible interval.\nKeeping the definition of frequentist probability tightly in mind, the confidence interval should be interpreted as an interval of parameter values that $1-\\alpha$ \\emph{of the times is constructed} contains the true parameter value.\nGiven this, in the frequentist paradigm one is \\emph{unable} to make any statement on the probability that the true parameter value is contained in any specific confidence interval beyond the tautology that the true parameter is either contained in it or it is not.\nAny misuse of this result is not from a failing of the paradigm, but a misplaced desire of the analyst to have different questions answered than were asked.\n\nIn terms of computing a confidence interval, from observations that are governed by $\\theta$ a test statistic, $t$, that is an estimator of $\\theta$ is constructed.\nFor each value of the parameter to be tested, there exists an interval $\\left[t_{1}, t_{2}\\right]$ such that the probability of $t \\in \\left[t_{1}, t_{2}\\right]$ is\n\\begin{equation}\n p\\left(t_{1} < t < t_{2}\\middle|\\theta\\right) = \\int\\limits_{t_{1}}^{t_{2}} f\\left(t\\middle|\\,\\theta\\right)\\,dt = 1-\\alpha\\,.\n \\label{eq:confidence_interval_coverage}\n\\end{equation}\nThis interval represents a constant line segment in the $\\left(t, \\theta\\right)$ parameter space plane at the given value of $\\theta$.\nBy repeating this procedure for every value of $\\theta$ to be tested, a band of line segments --- a ``confidence belt'' --- is created that is bound between the curves $\\theta\\left(t_{1}\\right)$ and $\\theta\\left(t_{2}\\right)$, as shown in the example in \\Cref{fig:confidence_belt}.\nThen, for any given observed value of the test statistic, $t'$, a boundary at $t = t'$ can be drawn in the plane that intersects the confidence belt at the points $\\left(t', \\theta_{2}\\right)$ and $\\left(t', \\theta_{1}\\right)$.\nThis resulting range of parameter values $\\left[\\theta_{1}, \\theta_{2}\\right]$ is the confidence interval~\\cite{Cranmer:2015nia,PDG2018:Ch39}.\n\n\\begin{figure}[htbp]\n \\centering\n \\includegraphics[width=0.6\\linewidth]{preface/confidence_belt.eps}\n \\caption[Neyman construction of a confidence interval using a confidence belt.]{%\n  Example sketch of the construction of a confidence belt showing an observation in red intersecting the belt and the corresponding confidence interval as the parameter values bounded between the two blue dashed lines.}\\label{fig:confidence_belt}\n\\end{figure}\n\nThe conditions of coverage from \\Cref{eq:confidence_interval_coverage} do not uniquely specify $t_{1}$ and $t_{2}$, which allows for analysis specific choices to be made.\nIf central intervals are chosen, then the probabilities excluded below $t_{1}$ and $t_{2}$ are both $\\alpha/2$.\nIn the event that only an upper (or lower) limit is of interest, as is common in searches for new physics where no excess has been observed, then the probability excluded below $t_{1}$ (or above $t_{2}$) is zero.\nAlternatively, if the test statistic used is the profile likelihood ratio test statistic,\n\\[\n q_{\\theta} = -2 \\ln\\lambda\\left(\\theta\\right) = -2 \\ln\\frac{L\\left(\\theta, \\hat{\\hat{\\phi}}\\,\\right)}{L\\left(\\hat{\\theta},\\hat{\\phi}\\right)}\\,,\n\\]\nprofiling determines the allowed range $\\left[q_{\\theta, 1}, q_{\\theta, 2}\\right]$.\nIt is seen from \\Cref{eq:q_mu} and \\Cref{eq:q_mu_pvalue} that for an observed $q_{\\theta}$, $q_{\\mathrm{obs}}$, to satisfy \\Cref{eq:confidence_interval} the resulting confidence belt are the values $q_{\\theta} < q_{\\mathrm{obs}}$, and the resulting confidence interval the range of $\\theta$ that enforce this.\nUsing such a test statistic results in the Feldman-Cousins confidence intervals~\\cite{Feldman:1997qc}.\n\nAs the confidence interval can be a difficult concept to describe, a simple illustrative example follows.\nConsider $n$ observations $\\vec{x} = \\left\\{x_{1}, \\cdots, x_{n}\\right\\}$ that are drawn from a Normal distribution with unknown mean $\\theta$ and width $\\sigma_{\\theta}$.\nThis results in a sample mean $\\hat{\\theta}$ and standard deviation $\\sigma_{\\hat{\\theta}}$.\nTo construct a $95\\%$ confidence level central confidence interval for $\\theta$, the test statistic $t = \\left(\\hat{\\theta} - \\theta\\right)/\\sigma_{\\hat{\\theta}}$ can be used such that ${p\\left(t_{1} < t < t_{2}\\middle|\\theta\\right) = 0.95}$, where $t_{1}$ and $t_{2}$ are respectively the $2.5$th percentile and $97.5$th percentile%\n\\footnote{$t_{1} = \\mathrm{CDF}^{-1}\\left(\\alpha/2\\right)$ and $t_{2} = \\mathrm{CDF}^{-1}\\left(1 - \\alpha/2\\right)$.}\nof the Student's $t$-distribution for $n-1$ degrees of freedom, mean $\\mu=\\hat{\\theta}$ and standard deviation $\\sigma=\\sigma_{\\hat{\\theta}}$.\nTransforming the Student's $t$-distribution by $t' = \\left(t-\\hat{\\theta}\\right)/\\sigma_{\\hat{\\theta}}$ to have $\\mu=0, \\sigma=1$ simplifies to ${p\\left(-d < t' < d\\middle|\\theta\\right) = 0.95}$.\nTransforming to parameter space, ${p\\left(\\hat{\\theta} - d\\, \\sigma_{\\hat{\\theta}} < \\theta < \\hat{\\theta} + d\\, \\sigma_{\\hat{\\theta}}\\right)  = 0.95}$, this gives a confidence interval of $\\left[\\hat{\\theta} - d\\, \\sigma_{\\hat{\\theta}}, \\hat{\\theta} + d\\, \\sigma_{\\hat{\\theta}}\\right]$.\nConfidence intervals following this example construction are simulated and shown in \\Cref{fig:confidence_intervals}.\n\n\\begin{figure}[htbp]\n \\centering\n \\includegraphics[width=\\linewidth]{preface/confidence_intervals.eps}\n \\caption[Simulation of 100 $95\\%$ confidence level confidence intervals]{%\n  An example of 100 point estimates and associated $95\\%$ confidence level confidence intervals of parameter value $\\theta$.\n  Each measurement is the result of the same number of samples from a Normal distribution.\n  Confidence intervals that do not include the true value $\\theta$ (dashed blue line) are colored red.}\n \\label{fig:confidence_intervals}\n\\end{figure}\n\n\\subsubsection{Bayesian Credible Intervals}\n\nIn the Bayesian paradigm, a $1-\\alpha$ credibility level (CL) credible interval (CI)%\n\\footnote{CL and CI are used for abbreviations for both the frequentist and Bayesian intervals.\n It will be made clear to the reader from context which paradigm is being considered.}\nis an interval estimate where there is a $1-\\alpha$ probability of containing the true parameter value --- which is a random variable.\nAs a result, it is simply the interval of the posterior predictive distribution $\\left[\\theta_{1}, \\theta_{2}\\right]$ that when integrated over gives a probability of $1-\\alpha$,\n\n\\begin{equation}\n p\\left(\\theta_{1} < \\theta < \\theta_{2}\\middle|\\vec{x}\\right) = \\int\\limits_{\\theta_{1}}^{\\theta_{2}} p\\left(\\theta\\middle|\\,\\vec{x}\\right)\\,d\\theta = 1-\\alpha\\,.\n \\label{eq:credible_interval_coverage}\n\\end{equation}\n\nAs in the frequentist paradigm, there are different ways to select the credible interval range.\nOne can choose the shortest interval,%\n\\footnote{For a unimodal distribution this interval is known as the highest posterior density interval (HPD).}\nthe interval where probabilities excluded below $\\theta_{1}$ and above $\\theta_{2}$ are both $\\alpha/2$ (this interval includes the median), the interval centered at the mean of the posterior (if the mean exists), or the intervals corresponding to upper (or lower) limits which reduce \\Cref{eq:credible_interval_coverage} to the CDF (or CCDF) of $\\theta$.\n\nAs a final word on interval estimates, it is worth remembering that the frequentist and Bayesian paradigms address different questions and so make different statements with their intervals.\n\\begin{itemize}\n \\item Frequentist: When a confidence interval is constructed on future data, the constructed interval will contain the true parameter value with a probability (frequency) of $1-\\alpha$.\n \\item Bayesian: Given the observed data, there is a $1-\\alpha$ probability that the true parameter value is contained by the constructed credible interval.\n\\end{itemize}\n", "meta": {"hexsha": "5a63aeeeb8ac8bd4aa4f13cc56138b251562e43c", "size": 14302, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/statistics.tex", "max_stars_repo_name": "matthewfeickert/feickert-thesis", "max_stars_repo_head_hexsha": "7ab7210359495fe7ea1e610be237560ec35f63a6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-09-20T04:40:30.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-18T20:40:23.000Z", "max_issues_repo_path": "src/statistics.tex", "max_issues_repo_name": "matthewfeickert/feickert-thesis", "max_issues_repo_head_hexsha": "7ab7210359495fe7ea1e610be237560ec35f63a6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-10-03T11:36:53.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-03T11:36:53.000Z", "max_forks_repo_path": "src/statistics.tex", "max_forks_repo_name": "matthewfeickert/feickert-thesis", "max_forks_repo_head_hexsha": "7ab7210359495fe7ea1e610be237560ec35f63a6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-10-04T21:35:30.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-04T21:35:30.000Z", "avg_line_length": 92.8701298701, "max_line_length": 355, "alphanum_fraction": 0.7470983079, "num_tokens": 3766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.709364696129486}}
{"text": "\\section{Dictionary Learning}\n\nAdapt the dictionary to signal characteristics. Objective: $(\\mathbf{U}^\\star, \\mathbf{Z}^\\star) \\in \\argmin_\\mathbf{U,Z} \\| \\mathbf{X} - \\mathbf{U} \\cdot \\mathbf{Z} \\|_F^2$ not jointly convex but convex in 1 argument.\n\n\\textbf{Matrix Factorization by Iter Greedy Minimization}\n\\begin{inparaenum}[\\color{red} 1.]\n  \\item Coding step: $\\mathbf{Z}^{t+1} \\in \\argmin_\\mathbf{Z} \\| \\mathbf{X} - \\mathbf{U}^t \\mathbf{Z} \\|_F^2$ subject to $\\mathbf{Z}$ being sparse ($\\mathbf{z}_n^{t+1}\\in \\argmin_\\mathbf{z}\\|\\mathbf{z}\\|_0$ s.t.$\\|\\mathbf{x}_n - \\mathbf{U}^t\\mathbf{z}\\|_2 \\le \\sigma \\|\\mathbf{x}_n\\|_2$)\n  \\item Dict update step: $\\mathbf{U}^{t+1} \\in \\argmin_\\mathbf{U} \\| \\mathbf{X} - \\mathbf{UZ}^{t+1} \\|_F^2$, subj to $\\forall l\\in [L]:\\|\\mathbf{u}_l\\|_2 = 1$. (set $\\mathbf{U} = [\\mathbf{u}_1^t\\cdots \\mathbf{u}_l\\cdots \\mathbf{u}_L^t],~ \\min_{u_l}\\|\\mathbf{X} - \\mathbf{U}\\mathbf{Z}^{t+1}\\|_F^2 = \\min_{u_l}\\|\\mathbf{R}_l^t - \\mathbf{u}_l(\\mathbf{z}_l^{t+1})^\\top\\|_F^2$ with $\\mathbf{R}_l^t = \\tilde{\\mathbf{U}}\\Sigma\\tilde{\\mathbf{V}}^\\top$ by $\\mathbf{u}^*_l=\\tilde{\\mathbf{u}}_1$)\n\\end{inparaenum}\n", "meta": {"hexsha": "8b151f80be3ac1de7174ccba15626457b759de54", "size": 1136, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "DictionaryLearning.tex", "max_stars_repo_name": "vscherer/eth-cil-exam-cheatsheet", "max_stars_repo_head_hexsha": "9ae156bcf5e2797e65b5495ff520649b43860cdd", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-09-24T20:33:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-21T15:52:46.000Z", "max_issues_repo_path": "DictionaryLearning.tex", "max_issues_repo_name": "vscherer/eth-cil-exam-cheatsheet", "max_issues_repo_head_hexsha": "9ae156bcf5e2797e65b5495ff520649b43860cdd", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DictionaryLearning.tex", "max_forks_repo_name": "vscherer/eth-cil-exam-cheatsheet", "max_forks_repo_head_hexsha": "9ae156bcf5e2797e65b5495ff520649b43860cdd", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-01-14T16:21:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-18T17:17:10.000Z", "avg_line_length": 113.6, "max_line_length": 486, "alphanum_fraction": 0.6373239437, "num_tokens": 525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942145139149, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7093646931853144}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Consider the sequence of numbers defined by the recurrence\n  \\begin{equation*}\n    \\begin{array}{l@{~}c@{~}l}\n      a_0 &=& 0, \\\\\n      a_1 &=& 1, \\\\\n      a_{n+2} &=& 2a_{n+1} + 3a_n, \\quad\\mbox{for all $n\\geq 0$.} \\\\\n    \\end{array}\n  \\end{equation*}\n  Find the first 5 members of this sequence. Then solve the recurrence\n  and find $a_{20}$.\n\\end{ex}\n\n\\begin{ex}\n  Consider the sequence of numbers defined by the recurrence\n  \\begin{equation*}\n    \\begin{array}{l@{~}c@{~}l}\n      b_0 &=& 1, \\\\\n      b_1 &=& 2, \\\\\n      b_2 &=& 3, \\\\\n      b_{n+3} &=& 2b_{n+2} + b_{n+1} - 2b_n, \\quad\\mbox{for all $n\\geq 0$.} \\\\\n    \\end{array}\n  \\end{equation*}\n  Find the first 5 members of this sequence. Then solve the recurrence\n  and find $b_{20}$.\n\\end{ex}\n\n\\begin{ex}\n  Consider two sequences of numbers $c_0,c_1,c_2,\\ldots$ and\n  $d_0,d_1,d_2,\\ldots$, defined by the following mutual recurrence\n  relation.\n  \\begin{equation*}\n    \\begin{array}{l@{~}c@{~}l@{\\quad}l@{~}c@{~}l}\n      c_0 &=& 0,             & d_0 = 1 \\\\\n      c_{n+1} &=& 4c_n - 3d_n, & d_{n+1} = 2c_n - d_n, \\quad\\mbox{for all $n\\geq 0$.} \\\\\n    \\end{array}\n  \\end{equation*}\n  Find the first 5 members of both sequences. Then solve the\n  recurrence. Hint: first find a matrix $A$ such that\n  \\begin{equation*}\n    \\begin{mymatrix}{c} c_{n+1} \\\\ d_{n+1} \\end{mymatrix}\n    = A \\begin{mymatrix}{c} c_n \\\\ d_n \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n", "meta": {"hexsha": "c7a101806736ca575d94e17e0ac98470444a21b1", "size": 1450, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Eigenvalues-Application-Recurrences.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Eigenvalues-Application-Recurrences.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Eigenvalues-Application-Recurrences.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 30.2083333333, "max_line_length": 88, "alphanum_fraction": 0.5834482759, "num_tokens": 601, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118111485245, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.7091270221188681}}
{"text": "\\Lecture{Jayalal Sharma}{Sept 19, 2020}{08}{Live lecture discussion}{Anshu and Narasimha Sai }{$\\alpha$}{JS}\n\n\\paragraph{Bijection from Euler's problem to Binary Trees} As we have already established a bijection from set of balanced parenthesisations to set of full binary trees and established that number of full binary trees with $n$ internal nodes is the catlan number $C_n$, in this section, let's establish a bijection from the \\emph{Euler's Problem} to set of full binary trees to establish that the solution to \\emph{Euler's problem} is also catlan number $C_n$.\n\nLets recall \\emph{Euler's problem} first. Consider a convex polygon with $n+2$ edges. Euler's problem is the number of ways of triangulating it (partition the polygon into triangles) by drawing non-crossing diagonals. (Refer fig. \\ref{fig:Euler's-polygon}). We know that number of non-crossing diagonals in a polygon of $n+2$ edges is $n-1$ (proof follows from a simple induction) and from those $n-1$ non-crossing diagonals, we have our polygon partitioned into $n$ triangles. Let's associate each of the triangles with a vertex (green dots in the fig. \\ref{fig:Euler's-polygon}). Observe that if two triangles share an edge, it must be one of the diagonals (no two triangles can share an edge because of non-crossing diagonals). Now, let's connect the vertices whose corresponding triangles share an edge. Any edge connecting two of these vertices crosses a diagonal. \n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.4\\linewidth]{images/polygon.png}\n    \\caption{Partitioning a polygon into triangles by non-crossing diagonals. Observe that green dots in each triangle associates the triangle with a vertex}\n    \\label{fig:Euler's-polygon}\n\\end{figure}\nNow, consider a polygon edge $e$. For every polygon edge surrounding a vertex (other than $e$), add an open-edge originating from that vertex (see fig. \\ref{fig:tree-in-polygon}). We arrive at the following claim.  \n\\begin{claim}\n\tIf we remove the underlying triangles (which are formed with polygon edges and diagonals), from fig. \\ref{fig:tree-in-polygon}, the \t\tresulting graph obtained (see fig. \\ref{fig:tree}) is a full binary tree with the vertices as internal nodes.\n\\end{claim}\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.4\\linewidth]{images/polygon-tree.png}\n    \\caption{Polygon with vertices connected to form a tree}\n    \\label{fig:tree-in-polygon}\n\\end{figure}\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.4\\linewidth]{images/tree.png}\n    \\caption{Tree formed by connecting vertices}\n    \\label{fig:tree}\n\\end{figure}\n\\begin{proof}\n\tWe observe that degree of every vertex other than the vertex surrounded by edge $e$ is 2. This vertex will act as root to our full binary tree. All other vertices have degree 3 because each vertex is surrounded by a triangle and if a side is a diagonal, it will be connected to vertex which is surrounded by triangle that shares the diagonal and if the side is a polygon edge, then there will be an open edge corresponding to it originating from the vertex. Therefore the resulting graph formed is a full binary tree with our vertices as $n$ internal nodes and vertices corresponding to open edges are $n+1$ leaves (because there are $n+2$ edges and one edge is under consideration). This completes the description of bijection.\n\\end{proof}\n\nWe leave it as an exercise to the reader to prove that the mapping defined above is indeed a bijection.\n\n\\paragraph{Bijection from binary trees to full binary trees}\nIn this section we are interested in connection between binary and full binary trees. Recall that a full binary tree is one in which each node has either 0 or two children. On the other hand, when we say binary tree then it only means that each node can have at most two children. We want to find a bijection between set of binary trees with $n$ internal nodes and set of full binary trees with certain number of internal nodes. \n\nFirst of all lets try to see how to convert a given binary tree into a full binary tree so that we can reverse the process, i.e. recover the original (binary) tree back from the full binary tree without ambiguity. \n\nHere is the first attempt:\n\n\\noindent \\underline{Attempt 1:} First natural approach can be to add a leaf node to all non-full (internal nodes having only one child) nodes, as shown in figure~\\ref{fig:bt-fbt-attempt1}\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.7\\linewidth]{images/binary-to-full-binary-1.png}\n    \\caption{Binary to full binary tree attempt1: adding a child node to each non full node}\n    \\label{fig:bt-fbt-attempt1}\n\\end{figure}\n\nBut notice that this transformation is not injective. For example, it can be observed that  both the trees in figure~\\ref{fig:bt-fbt-attempt1-issue} map to same full binary tree.\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.7\\linewidth]{images/binary-to-full-binary-2.png}\n    \\caption{Two different binary trees that map to same full binary tree}\n    \\label{fig:bt-fbt-attempt1-issue}\n\\end{figure}\n\n\\noindent\\underline{Attempt 2(correct)}\nLets try a slightly different approach. Given a binary tree, do the following:\n\\begin{itemize}\n    \\item to each leaf node, add two children\n    \\item to each internal node having only one child, add another child\n\\end{itemize}\nFigure~\\ref{fig:binary-to-full-solution} shows the full binary tree constructed in this way for the same binary tree as in Figure~\\ref{fig:bt-fbt-attempt1}.\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.5\\linewidth]{images/full-binary-3.png}\n    \\caption{Full binary tree for the (non-full) binary tree given in fig~\\ref{fig:bt-fbt-attempt1}. Notice that all the leaf nodes are added during transformation}\n    \\label{fig:binary-to-full-solution}\n\\end{figure}\nWe can see that this solution addresses the issue in the first attempt. Intuitively because of following argument: in the previous attempt the problem was that given a full binary tree, it was hard to decide if a leaf node was originally present in the binary tree or added during transformation. Now, in the current solution, this issue does not arise, because for any leaf node originally present in the binary tree, we add two new leaves as its children. Thus, it can be observed that all the leaf nodes (and only these nodes) are added during transformation.\n\nTo see that this translation is well-defined, we can see that the transformed tree is full binary tree by construction itself. Surjectivity is also easy to prove. To recover a binary tree from any given full binary tree, simply remove all the leaf nodes. We discussed injection informally. To give a formal argument, we first need to identify how to characterize two different binary trees? One of the hint as given during the discussion is to assign address to the nodes in the form of binary string, where 0-1 represents left or right child. \n\nHere we argued the bijection only intuitively and there are many things to be worked out formally. For example, proof for injection is not formally argued. Also, to argue surjection, we need to fix the number of nodes in full binary tree. Once we figure out this number, the argument for transformation being  well-defined also need to take that into account.\n\nWriting a complete formal proof of bijection is left as homework exercise.\n\n\\paragraph{Bijection between plane trees and full binary trees}\nA plane tree is a rooted tree with an ordering among the children. A plane tree can have more than two children. Figure~\\ref{fig:plane-tree-1} shows a plane tree. \n\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.8\\linewidth]{images/plane-tree.png}\n    \\caption{An example of plane trees and its transformation to a binary tree}\n    \\label{fig:plane-tree-1}\n\\end{figure}\n\nWe are interested in studying the connection between plane trees and binary trees. The number of plane trees with $n$ nodes is equal to the number of binary trees with $n$ nodes. Thus, there is bijection between set of plane trees with $n$ nodes and the set of  binary trees with $n$ nodes. \n\nHere we define the bijection function. \n\n\\noindent\\underline{The Bijection:} Given any plane tree, do the following\n\\begin{itemize}\n    \\item For each node in the tree, \n    \\begin{itemize}\n        \\item add its first child in plane tree as its left child in binary tree\n        \\item add its immediate sibling on right as its right child in binary tree.\n    \\end{itemize} child in the binary tree.\n\\end{itemize}\nBy following the above rule, we get a binary tree from given plane tree.\n\nObserve that in the binary tree thus obtained, root node has only one child, while in general, in a binary tree the root can have both its children. Hence, we won't include the root as part of the binary tree.\n\nWriting formal argument for all the properties is left as homework excercise.\n", "meta": {"hexsha": "ba79d3acf8fc945227e280cf1525f01525b14b2b", "size": 8880, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "live-lecture.tex", "max_stars_repo_name": "narasimhasai07/theory-toolkit", "max_stars_repo_head_hexsha": "fde5621c515c2e05e3d91e8b021b745ea6ea2075", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "live-lecture.tex", "max_issues_repo_name": "narasimhasai07/theory-toolkit", "max_issues_repo_head_hexsha": "fde5621c515c2e05e3d91e8b021b745ea6ea2075", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "live-lecture.tex", "max_forks_repo_name": "narasimhasai07/theory-toolkit", "max_forks_repo_head_hexsha": "fde5621c515c2e05e3d91e8b021b745ea6ea2075", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.5714285714, "max_line_length": 870, "alphanum_fraction": 0.7699324324, "num_tokens": 2154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7091270208062032}}
{"text": "%!TEX root = ../notes.tex\n\\section{March 16, 2022}\n\\subsection{Addition on Elliptic Curves \\emph{continued}}\nWe said last time that we had some rules:\n\\begin{itemize}\n    \\item $P + \\cO = \\cO + P = P$.\n    \\item If $x_1 = x_2$ and $y_1 = -y_2$, we have\n          \\[P_1 + P_2 = \\cO\\]\n    \\item\n          In other cases, we need to calculate the slope of the line.\n          \\begin{center}\n              \\includegraphics[width=0.5\\textwidth]{images/ec_two_intersection.png}\n          \\end{center}\n          If $P_1\\neq P_2$, the slope of $L$ is\n          \\[\\lambda = \\frac{y_2-y_1}{x_2-x_1}\\]\n          \\begin{center}\n              \\includegraphics[width=0.5\\textwidth]{images/ec_tangent.png}\n          \\end{center}\n          If $P_1 = P_2$, then the slope would be the tangent:\n          \\begin{align*}\n              y^2           & = x^3 + ax + b      \\\\\n              2y\\cdot dy    & = (3x^2+a)\\cdot dx  \\\\\n              \\frac{dy}{dx} & = \\frac{3x^2+a}{2y}\n          \\end{align*}\n          so we have\n          \\[\\lambda = \\frac{3x^2+a}{2y}\\]\n\n          We want to solve systems\n          \\[\\begin{cases}\n                  y^2 = x^3 + ax + b \\\\\n                  y = y_1 + \\lambda(x-x_1)\n              \\end{cases}\\]\n          which gives us\n          \\begin{align*}\n              [y_1 + \\lambda(x - x_1)]^2 & = x^3 + ax + b                                       \\\\\n              0                          & = x^3 - \\boxed{\\lambda^2}x^2 + (a + 2\\lambda_1 x_1)x\n              + b-y_1 - \\lambda x_1^2                                                           \\\\\n                                         & = (x-x_1)(x-x_2)(x-x_3)                              \\\\\n                                         & = x^3 - \\boxed{(x_1+x_2+x_3)}x^2 +\n              (x_1x_3 + x_2x_3 + x_1x_2)x - x_1x_2x_3\n          \\end{align*}\n          With some working out (taking the coefficient of $x^2$), \\[\\boxed{x_3 = \\lambda^2 - x_1 - x_2}\\] and $-y_3 = y_1 + \\lambda(x_3 - x_1)$ so we have \\[\\boxed{y_3 = -y_1 - \\lambda(x_3 - x_1)}\\] are our points by addition where\n          \\[\\lambda = \\frac{y_2 - y_1}{x_2 - x_1}\\]\n          or when $P_1 = P_2$,\n          \\[\\lambda = \\frac{3x_1^2 + a}{2y_1}.\\]\n\\end{itemize}\n\n\\subsection{Elliptic Curves over Finite Fields}\nOur definition stays the same, except $x, y$ are elements of $\\ZZ/p\\ZZ$. How do we add points? We could do it geometrically, but setting this up is outside the scope of this class\\dots\n\nFor addition, we use the same formulas that we've derived for $x_3$ and $y_3$, and they still make perfect sense mod $p$. \\emph{For whatever reasonable notion of geometry we have over $\\ZZ/p\\ZZ$, they work with these formulas.}\n\n\\begin{example}\n    We take elliptic curve\n    \\[y^2 = x^3 + x + 2\\quad \\text{ over }\\ZZ/5\\ZZ.\\]\n    How do we find elements in this elliptic curve? We can try them all.\n    \\begin{itemize}\n        \\item If $x = 0$, $y^2 = 2$, of which there are no solutions.\n        \\item If $x = 1$, $y^2 = 4$, of which $y = 2, 3$ are solutions.\n        \\item If $x = 2$, $y^2 = 2$ again, of which there are no solutions.\n        \\item If $x = 3$, $y^2 = 2$, of which there are no solutions.\n        \\item If $x = 4$, $y^2 = 0$, so $y = 0$ is one solution.\n    \\end{itemize}\n    We have $(1,2), (1,3), (4,0), \\cO$ are the elements of this elliptic curve. We have these\n    \\[\\begin{array}{c|cccc}\n            +     & \\cO   & (1,2) & (4,0) & (1,3) \\\\ \\hline\n            \\cO   & \\cO   & (1,2) & (4,0) & (1,3) \\\\\n            (1,2) & (1,2) & (4,0) & (1,3) & \\cO   \\\\\n            (4,0) & (4,0) & (1,3) & \\cO   & (1,2) \\\\\n            (1,3) & (1,3) & \\cO   & (1,2) & (4,0)\n        \\end{array}\\]\n\\end{example}\nLet's implement this:\n\\begin{lstlisting}[language=Python]\nO = \"the point O\"\ndef add(P1, P2, a, p):\n    if P1 == O:\n        return P2\n    if P2 == O:\n        return P1\n    x1, y1 = P1\n    x2, y2 = P2\n    if x1 == x2 and (y1 + y2) % p == 0:\n        return O\n    if P1 == P2:\n        lam = (3 * x1**2 + a) * ext_gcd(2 * y1, p)[0] % p\n    else:\n        lam = (y2 - y1) * ext_gcd(x2 - x1, p)[0] % p\n    x3 = (lam**2 - x1 - x2) % p\n    y3 = (lam * (x1 - x3) - y1) % p\n    return x3, y3\n\\end{lstlisting}", "meta": {"hexsha": "20392869f08002abfef10a7ba92b5bc055eeec93", "size": 4142, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-03-16.tex", "max_stars_repo_name": "jchen/math1580-notes", "max_stars_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-14T15:03:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T15:03:38.000Z", "max_issues_repo_path": "lectures/2022-03-16.tex", "max_issues_repo_name": "jchen/math1580-notes", "max_issues_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_issues_repo_licenses": ["BSL-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures/2022-03-16.tex", "max_forks_repo_name": "jchen/math1580-notes", "max_forks_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_forks_repo_licenses": ["BSL-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.0217391304, "max_line_length": 232, "alphanum_fraction": 0.4780299372, "num_tokens": 1503, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7091270131536187}}
{"text": "\\section{Inverse Functions}\\label{sec:InverseFunctions}\r\nIn mathematics, an \\ifont{inverse} is a function that serves to ``undo'' another function.\r\nThat is, if $f(x)$ produces $y$, then putting $y$ into the inverse of $f$ produces the output $x$.\r\nA function $f$ that has an inverse is called invertible and the inverse is denoted by $f^{-1}$.\r\nIt is best to illustrate inverses using an arrow diagram:\r\n$$\\includegraphics[width=3in]{images/inverse1}$$\r\nNotice how $f$ maps $1$ to $a$, and $f^{-1}$ undoes this, that is, $f^{-1}$ maps $a$ back to $1$.\r\nDon't confuse $f^{-1}(x)$ with exponentiation: the inverse $f^{-1}$ is \\ifont{different} from $\\frac{1}{f(x)}$.\r\n\r\nNot every function has an inverse. It is easy to see that if a \r\nfunction $f(x)$ is going to have an inverse, then $f(x)$ \r\n\\ifont{never} takes on the same value twice. We give this property a special name.\r\n\r\nA function $f(x)$ is called \\dfont{one-to-one}  if every element of the range corresponds to \\ifont{exactly} one element of the domain.\r\nSimilar to the Vertical Line Test (VLT) for functions, we have the Horizontal Line Test (HLT) for the one-to-one property.\r\n\r\n\\begin{theorem}{The Horizontal Line Test}{HorizontalLineTest}\r\nA function is one-to-one if and only if there is no horizontal line that intersects its graph more than once.\r\n\\end{theorem}\r\n\r\n\\begin{example}{Parabola is Not One-to-one}{ParabolaNotOneOne}\r\nThe parabola $f(x)=x^2$ it not one-to-one because it does not satisfy the horizontal line test.\r\nFor example, the horizontal line $y=1$ intersects the parabola at two points, when $x=-1$ and $x=1$.\r\n\\end{example}\r\n\r\nWe now formally define the inverse of a function.\r\n\r\n\\begin{definition}{Inverse of a Function}{InverseOfAFunction}\r\nLet $f(x)$ and $g(x)$ be two \\ifont{one-to-one} functions.\r\nIf $(f\\circ g)(x)=x$ and $(g\\circ f)(x)=x$ then we say \r\nthat $f(x)$ and $g(x)$ are \\deffont{inverses} of each other.\r\nWe denote $g(x)$ (the inverse of $f(x)$) by $g(x)=f^{-1}(x)$.\r\n\\end{definition}\r\n\r\nThus, if $f$ maps $x$ to $y$, then $f^{-1}$ maps $y$ back to $x$.\r\nThis gives rise to the \\ifont{cancellation formulas}:\r\n$$f^{-1}(f(x))=x,\\mbox{\\quad for every $x$ in the domain of $f(x)$},$$\r\n$$f(f^{-1}(x))=x,\\mbox{\\quad for every $x$ in the domain of $f^{-1}(x)$}.$$\r\n\r\n\\begin{example}{Finding the Inverse at Specific Values}{FindingInverseSpecificValues}\r\nIf $f(x)=x^9+2x^7+x+1$, find $f^{-1}(5)$ and $f^{-1}(1)$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nRather than trying to compute a formula for $f^{-1}$ and then computing $f^{-1}(5)$, we can simply find a number $c$ such that $f$ evaluated at $c$ gives $5$.\r\nNote that subbing in some simple values ($x=-3,-2,1,0,1,2,3$) and evaluating $f(x)$ we eventually find that $f(1)=1^9+2(1^7)+1+1=5$ and $f(0)=1$.\r\nTherefore, $f^{-1}(5)=1$ and $f^{-1}(1)=0$.\r\n\\end{solution} \r\n\r\nTo compute the equation of the inverse of a function we use the following \\ifont{guidelines}.\r\n\r\n\\begin{formulabox}[Guidelines for Computing Inverses]\r\n\\begin{enumerate}\\itemsep0pt\r\n\t\\item Write down $y=f(x)$.\r\n\t\\item Solve for $x$ in terms of $y$.\r\n\t\\item Switch the $x$'s and $y$'s.\r\n\t\\item The result is $y=f^{-1}(x)$.\r\n\\end{enumerate}\r\n\\end{formulabox}\r\n\r\n\\begin{example}{Finding the Inverse Function}{FindingInverseFunction}\r\nWe find the inverse of the function $f(x)=2x^3+1.$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nStarting with $y=2x^3+1$ we solve for $x$ as follows:\r\n$$y-1=2x^3\\qquad\\to\\qquad \\frac{y-1}{2}=x^3\\qquad\\to\\qquad x=\\sqrt[3]{\\frac{y-1}{2}}.$$\r\nTherefore, $\\ds f^{-1}(x)=\\sqrt[3]{\\frac{x-1}{2}}$.\r\n\\end{solution}\r\n\r\nThis example shows how to find the inverse of a function \\ifont{algebraically}.\r\nBut what about finding the inverse of a function \\ifont{graphically}?\r\nStep $3$ (switching $x$ and $y$) gives us a good graphical technique to find the inverse, namely, \r\nfor each point $(a,b)$ where $f(a)=b$, sketch the point $(b,a)$ for the inverse.\r\nMore formally, to obtain $f^{-1}(x)$ \\ifont{reflect} the graph $f(x)$ about the line $y=x$.\r\n\r\n$$\\includegraphics[width=2.5in]{images/inverse2}$$\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for \\ref{sec:InverseFunctions}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nIs the function $f(x)=|x|$ one-to-one?\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nIf $h(x)=e^x+x+1$, find $h^{-1}(2)$.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nFind a formula for the inverse of the function $\\ds{f(x)=\\frac{x+2}{x-2}}$.\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "bc49d45831aba0f55cc0ec7245cd86fb753976ae", "size": 4492, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2-functions/2-4-inverse-functions.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2-functions/2-4-inverse-functions.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2-functions/2-4-inverse-functions.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.4752475248, "max_line_length": 159, "alphanum_fraction": 0.661398041, "num_tokens": 1453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.8267117855317473, "lm_q1q2_score": 0.7091270076603048}}
{"text": "\\chapter{Multiscale Entropy applied to Background Fluctuation Analysis}\n\n\\section*{The mean entropy vector}\n\nThe multiscale entropy has been defined by:\n\\begin{eqnarray}\nH(X) = \\sum_{j=1}^{l}  \\sum_{k=1}^{N} h(w_j)  \n\\end{eqnarray}\nwith $h(w_j = \\ln ( p(w_j(k))))$.\nIn order to study the behavior of the information at a given scale, we \nprefer to calculate the mean entropy vector $E$ defined by:\n\\begin{eqnarray}\nE(j) = \\frac{1}{N}\\sum_{k=1}^{N} h(w_j)\n\\end{eqnarray}\n$E(j)$ gives the mean entropy at the scale $j$. From the mean entropy vector,\nwe have  statistical information on each scale separately. \nHaving a noise model, we are able to calculate (generally from simulations)\nthe mean entropy vector $E^{(noise)}(j)$ resulting from a pure noise.\nThen we define the normalized mean entropy vector by\n\\begin{eqnarray}\nE_n(j) = \\frac{ E(j) }{ E^{(noise)}(j) }\n\\end{eqnarray}\n\n\nFigure~\\ref{fig_source1} shows the result of a simulation. \nFive simulated images were created by adding $n$ sources (i.e., point\nsources, or idealized stars) to an 1024\n$\\times$ 1024 image \ncontaining Gaussian noise of standard deviation equal to 1. The $n$ sources\nare identical, with a maximum equal to 1, and standard deviation equal to 2.\nDefining the signal to noise ratio (SNR) as the ratio between\nthe standard deviation in the smallest box which contains at least 90\\% \nof the flux of the source, and the noise standard deviation, we have a SNR\nequal to $0.25$. The sources  are not detectable in the simulated\nimage, nor in its wavelet transform. Figure~\\ref{fig_source2} shows a region\nwhich contains a source at the center. It is clear there is no way to find\nthis kind of noisy signal. The five images were created using a number \nof sources\nrespectively equal to 0,50,100,200 and 400, and the simulation was\nrepeated ten times with different noise maps in order to have an error bar on\neach entropy measurement. For the image which contains 400\nsources, the number of pixels affected by a source is less  than $2.5$\\%.\n\nWhen the number of sources increases, the difference between the multiscale\nentropy curves increases. Even if the sources are very faint, the presence\nof signal can be clearly detected using the mean entropy vector. But it is \nobvious that the positions of these sources remain unknown.\n \n\\begin{figure}[htb]\n\\centerline{\n\\vbox{\n\\psfig{figure=fig_source.ps,bbllx=3.5cm,bblly=13cm,bburx=19.5cm,bbury=25.5cm,width=16cm,height=12.5cm}\n}}\n\\caption{Mean entropy versus the scale of 5 simulated images containing undetectable\nsources and noise. Each curve corresponds to the multiscale transform\nof one image. From\ntop to bottom, the image contains respectively 400,200,100, 50 and 0 sources.}\n\\label{fig_source1}\n\\end{figure}\n\n\\begin{figure}[htb]\n\\centerline{\n\\vbox{\n\\psfig{figure=fig_1source.ps,bbllx=1.8cm,bblly=12.9cm,bburx=14.5cm,bbury=25.5cm,width=8cm,height=8cm,clip=}\n}}\n\\caption{Region of a simulated image containing an undetectable source at the\ncenter.}\n\\label{fig_source2}\n\\end{figure}\n\n", "meta": {"hexsha": "6349364b2ffd0a2891139a41873d820552931605", "size": 3010, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr2/fluctu.tex", "max_stars_repo_name": "sfarrens/cosmostat", "max_stars_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/doc/doc_mra/doc_mr2/fluctu.tex", "max_issues_repo_name": "sfarrens/cosmostat", "max_issues_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/doc/doc_mra/doc_mr2/fluctu.tex", "max_forks_repo_name": "sfarrens/cosmostat", "max_forks_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.3943661972, "max_line_length": 107, "alphanum_fraction": 0.7634551495, "num_tokens": 862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740729, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7091180493536988}}
{"text": "%!TEX root = ../TTK18-Summary.tex\n\\section{Preliminaries}\n\n% \\subsection{KKT conditions}\n% Yada yada yada.\n\n\\subsection{Lyapunov stability}\n\n\\paragraph{Continuous systems}\nIf there exists a $P > 0$ satisfying\n\\begin{equation}\n  A\\tp P + PA < 0,\n\\end{equation}\nthen the system $\\dot{x} = Ax$ is globally asymptotically stable.\n\n\\paragraph{Discrete-time systems}\nIf there exists a $P > 0$ satisfying\n\\begin{equation}\n  A\\tp P A - P < 0,\n\\end{equation}\nthen the system $x_{k+1} = Ax_k$ is globally asymptotically stable.\n", "meta": {"hexsha": "fe5e056e739583e40c821330f72c676e07e7d5ee", "size": 518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK18 Optimaliseringsbasert reguleringsdesign og analyse/tex/sec-preliminaries.tex", "max_stars_repo_name": "jakoblover/ntnu-course-summaries", "max_stars_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-11T02:42:40.000Z", "max_issues_repo_path": "TTK18 Optimaliseringsbasert reguleringsdesign og analyse/tex/sec-preliminaries.tex", "max_issues_repo_name": "jakoblover/ntnu-course-summaries", "max_issues_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TTK18 Optimaliseringsbasert reguleringsdesign og analyse/tex/sec-preliminaries.tex", "max_forks_repo_name": "jakoblover/ntnu-course-summaries", "max_forks_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5454545455, "max_line_length": 67, "alphanum_fraction": 0.7181467181, "num_tokens": 169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.7091180315726024}}
{"text": "\\chapter{An algebraic formalism for Multi-instance learning}\n\n\\VUname{Multi-instance learning} is a class of machine learning algorithms, first described by \\cite{dietterich_solving_1997}, that can be used for both \\VUname{supervised} (see \\cite{amores_multiple_2013}) as well as \\VUname{unsupervised} (see \\cite{zhang_multi-instance_2009}, \\cite{chen_contextual_2012}) learning. While classical machine learning algorithms typically require a sample to be represented as a vector of numbers, multi-instance learning relaxes this requirement by representing a sample as a \\VUname{bag} of an arbitrary number of objects with a singular label for the whole bag. \\cite{dedic_hierarchicke_2017} describes a novel approach to the formalization of multi-instance learning, a liberal translation of which constitutes the following chapter.\nIn order to correctly describe the notion of a bag using mathematical notation, a few theoretical definitions are needed first.\n\n\\section{Multisets}\n\nA multiset is a set allowing repeated elements, or alternatively an unordered tuple. \\cite{knuth_art_1968} formally defines the concept as follows:\n\n\\begin{define}\n\tLet \\( \\VUset{A} \\) be a set and \\( m : \\VUset{A} \\to \\VUfield{N} \\setminus \\left\\{ 0 \\right\\} \\). The tuple \\( \\left( \\VUset{A}, m \\right) \\) is called a \\VUname{multiset} over the set \\( \\VUset{A} \\). For an \\( a \\in \\VUset{A} \\), the number \\( m \\left( a \\right) \\) is called the \\VUname{multiplicity} (i. e. number of occurrences) of \\( a \\). If \\( a \\in \\VUset{A} \\), then \\( a \\) is called an element of \\( \\left( \\VUset{A}, m \\right) \\) and denoted as\n\t\\[ a \\in \\left( \\VUset{A}, m \\right) \\]\n\\end{define}\n\nObviously, a multiset is a generalization of a set and as such it is usually written as an enumeration of the elements which are repeated as many times as is their multiplicity.\n\n\\begin{example}\n\tThe multiset \\( \\left( \\left\\{ a, b, c \\right\\}, \\left\\{ \\left( a, 4 \\right), \\left( b, 1 \\right), \\left( c, 6 \\right) \\right\\} \\right) \\) may be written as \\( \\left\\{ a, a, a, a, b, c, c, c, c, c, c \\right\\} \\).\n\\end{example}\n\n\\begin{remark}\n\tA set can be seen as a special case of a multiset where each element has a multiplicity of 1.\n\\end{remark}\n\n\\begin{define}\n\tLet \\( \\VUset{A} \\) be a set. A multiset \\( \\left( \\VUset{B}, m \\right) \\) is called a \\VUname{submultiset} of \\( \\VUset{A} \\) if \\( \\VUset{B} \\subset \\VUset{A} \\). This is denoted as\n\t\\[ \\left( \\VUset{B}, m \\right) \\subset \\VUset{A} \\]\n\\end{define}\n\nThe previous definition allows for a generalization of the concept of a power set, which is usually denoted as \\( \\mathcal{P} \\left( \\VUset{A} \\right) \\) or \\( 2^{\\VUset{A}} \\).\n\n\\begin{define}\n\tLet \\( \\VUset{A} \\) be a set. A \\VUname{power multiset} of \\( \\VUset{A} \\) is the set\n\t\\[ \\mathcal{P}^M \\left( \\VUset{A} \\right) = \\left\\{ \\left( \\VUset{B}, m \\right) \\middle| \\left( \\VUset{B}, m \\right) \\text{is a multiset} \\wedge \\left( \\VUset{B}, m \\right) \\subset \\VUset{A} \\right\\} \\]\n\\end{define}\n\n\\begin{remark}\n\tA power set of \\( \\VUset{A} \\) may be seen as a set of all function from \\( \\VUset{A} \\) to \\( \\left\\{ 0, 1 \\right\\} \\), sometimes written as \\( \\left\\{ 0, 1 \\right\\}^{\\VUset{A}} \\). \\( \\left\\{ 0, 1 \\right\\} \\) coincides with the von Neumann ordinal 2, therefore the power set is often denoted \\( 2^{\\VUset{A}} \\). Similarly, the power multiset may be seen as a set of all functions from \\( \\VUset{A} \\) to \\( \\VUfield{N} \\) (where \\( 0 \\in \\VUfield{N} \\)). It is therefore possible to use an analogous notation \\( \\mathcal{P}^M \\left( \\VUset{A} \\right) = \\VUfield{N}^\\VUset{A} \\). This analogy extends to the size of the sets in question where\n\t\\[ \\left\\lvert 2^{\\VUset{A}} \\right\\rvert = 2^{\\left\\lvert \\VUset{A} \\right\\rvert} \\qquad \\text{and} \\qquad \\left\\lvert \\VUfield{N}^\\VUset{A} \\right\\rvert = + \\infty \\]\n\tfor all \\( \\VUset{A} \\neq \\emptyset \\).\n\\end{remark}\n\n\\begin{define}\n\tLet \\( \\VUset{B} = \\left( \\VUset{A}, m \\right) \\) be a multiset where \\( \\VUset{A} \\) is finite. The cardinality of the multiset \\( \\VUset{B} \\) is\n\t\\[ \\left\\lvert \\VUset{B} \\right\\rvert = \\sum_{a \\in \\VUset{A}} m \\left( a \\right) \\]\n\\end{define}\n\n\\section{Multi-instance learning}\nMulti-instance learning (see \\cite{dietterich_solving_1997}) is an approach to solving problems where there is an input space \\( \\VUspace{X} \\) and an output space \\( \\VUspace{Y} \\) (whose elements are often called labels or classes) and the goal is to find a mapping of input objects to output objects. Unlike classical supervised learning, there is no known solution consisting of pairs of input and output objects. Instead, the input objects are grouped together into so called bags, which are defined as follows:\n\n\\begin{define}\n\tLet \\( \\VUspace{X} \\) be a set of input objects. Then the \\VUname{bag space} is a multiset \\( \\VUspace{B} \\) with the properties\n\t\\begin{enumerate}\n\t\t\\item \\( \\VUspace{B} \\subset \\mathcal{P}^M \\left( \\VUspace{X} \\right) \\)\n\t\t\\item \\( \\left( \\forall x \\in \\VUspace{X} \\right) \\left( \\exists b \\in \\VUspace{B} \\right) \\left( x \\in b \\right) \\)\n\t\\end{enumerate}\n\tElements of the bag space are called \\VUname{bags}.\n\\end{define}\n\nMulti-instance learning uses a dataset consisting of pairs of bags and labels to learn a mapping between them. \\cite{dietterich_solving_1997} provides the following example of a multi-instance problem:\n\n\\begin{example}\n\tSuppose there is a keyed lock on the door to the supply room in an office. Each staff member has a key chain containing several keys. One key on each key chain can open the supply room door. For some staff members, their supply room key opens only the supply room door; while for other staff members, their supply room key may open one or more other doors (e.g., their office door, the mail room door, the conference room door).\n\n\tSuppose you are a lock smith and you are attempting to infer the most general required shape that a key must have in order to open the supply room door. If you knew this required shape, you could predict, by examining any key, whether that key could unlock the door. What makes your lock smith job difficult is that the staff members are uncooperative. Instead of showing you which key on their key chains opens the supply room door, they just hand you their entire key chain and ask you to figure it out for yourself! Furthermore, you are not given access to the supply room door, so you can’t try out the individual keys. Instead, you must examine the shapes of all of the keys on the key rings and infer the answer.\n\\end{example}\n\nIn this example, the keys (or, more precisely their description by a feature vector) are the input objects from \\( \\VUspace{X} \\). The key chains are bags. Even though it makes sense to ask for each key whether it unlocks the supply room, this information is not provided. Instead only a key-chain-level information is available. On the other hand, it may be stated that a key chain opens the supply room door if and only if it contains a key which opens the door. This naturally leads to the following definition:\n\n\\begin{define}\\label{baglabel}\n\tLet \\( \\VUspace{X} \\) be an input space and \\( \\VUspace{Y} \\) a label space such that\n\t\\[ \\left( \\forall x \\in \\VUspace{X} \\right) \\left( \\exists_1 y_x \\in \\VUspace{Y} \\right) \\]\n\tLet \\( \\VUspace{B} \\) be a bag space. Let maximum be well-defined in \\( \\VUspace{Y} \\). Then the label of the bag \\( b \\in \\VUspace{B} \\) is\n\t\\[ y_b = \\max_{x \\in b} \\left( y_x \\right) \\in \\VUspace{Y} \\]\n\\end{define}\n\nAs will later be shown in sections \\ref{bag-space-paradigm} and \\ref{embedded-space-paradigm}, this isn't the only interpretation of multi-instance learning. There are problems where the instance-level labels are not only no known, but even not well-defined as the bag isn't seen as a mere collection of objects but as a distinct object of its own.\n\n\\section{Approaches to solving multi-instance problems}\nIn this section, there are described the three major approaches to solving multi-instance problems. The section is sourced primarily from \\cite{pevny_using_2017} and \\cite{pevny_discriminative_2016}.\n\n\\subsection{Instance-space paradigm}\nInstance-space paradigm is the original approach proposed by \\cite{dietterich_solving_1997}. The existence of labels for all instances is presumed, even though such labels aren't known. The goal of this approach is to find the instance-level labelling \\( f : \\VUspace{X} \\to \\VUspace{Y} \\) and use it to model the bag-level label analogically to definition \\ref{baglabel}, that is\n\\[ y_b = \\max_{x \\in \\VUspace{X} } \\left( f \\left( x \\right) \\right) \\]\n\nThere are many applications of instance-space paradigm, the most important of which are described next. (Also see \\cite{andrews_support_2003} \\cite{zhang_multiple_2006})\n\n\\VUname{BP-MIP}, proposed by \\cite{zhou_neural_2002}, is an application of multi-instance learning to binary classification, i. e. \\( \\VUspace{Y} = \\left\\{ -1, +1 \\right\\} \\). A feedforward neural network is used, its output for the \\( j \\)-th instance of the \\( i \\)-th bag denoted \\( o_{ij} \\). An instance-level error function is defined as\n\\[ E_{ij} = \\begin{cases}\n\t\t0 &\\text{for} \\quad y_{b_i} = -1 \\wedge o_{ij} < 0.5 \\\\\n\t\t0 &\\text{for} \\quad y_{b_i} = +1 \\wedge o_{ij} \\geq 0.5 \\\\\n\t\t\\frac{1}{2} \\left( o_{ij} - 0.5 \\right)^2 &\\text{otherwise}\n\t\\end{cases} \\]\nThis instance-level error function is then used to define a bag-level error function as \\footnote{The original article erroneously states the upper bound as \\( \\left\\lvert b_j \\right\\rvert \\)}\n\\[ E_i = \\begin{cases}\n\t\t\\max_{1 \\leq j \\leq \\left\\lvert b_i \\right\\rvert} E_{ij} &\\text{for} \\quad y_{b_i} = -1 \\\\\n\t\t\\min_{1 \\leq j \\leq \\left\\lvert b_i \\right\\rvert} E_{ij} &\\text{for} \\quad y_{b_i} = +1\n\t\\end{cases} \\]\nAnd this is in turn used to define the global loss function\n\\[ E = \\sum_{i = 1}^{\\left\\lvert \\VUspace{B} \\right\\rvert} E_i \\]\nWith such a well-defined global loss function, the back-propagation algorithm can be used with a slight modification described in the original article.\n\n\\VUname{EM-DD}, proposed by \\cite{zhang_em-dd:_2002}, combines the \\VUname{expectation-maximization} algorithm (see \\cite{dempster_maximum_1977}) with the \\VUname{diverse density} algorithm (see \\cite{maron_framework_1998}). The EM-DD algorithm starts with a target hypothesis \\( h \\in \\VUspace{Y} \\), which is then refined with the EM algorithm. In the E-step, the instance thought to be most responsible for the label of each bag is picked. In the M-step, the gradient ascent algorithm is used to find a new hypothesis \\( h' \\) which maximizes \\( \\mathrm{DD} \\left( h \\right) \\). \\( \\mathrm{DD} \\left( h \\right) \\) corresponds to the likelihood that \\( h \\) is the actual target. These steps are then repeated, refining the hypothesis.\n\n\\subsection{Bag-space paradigm}\\label{bag-space-paradigm}\nThe bag-space paradigm is a formalism in which the notion of instance-level labels is abandoned and only bag-level labels are assumed to exist. The definition \\ref{baglabel} is no longer used, so some other way of working with bags must be devised. In order to do this, a bag distance function or a bag kernel function is defined, having the form\n\\[ k : \\VUspace{B} \\times \\VUspace{B} \\to \\VUfield{R}_0^+ \\]\nBecause the notion of an instance-level label is no longer used, the sought classification function is of the form \\( f : \\VUspace{B} \\to \\VUspace{Y} \\).\n\n\\VUname{Citation-kNN}, proposed by \\cite{wang_solving_2000}, defines a modified Hausdorff distance for bags \\( b_1, b_2 \\in \\VUspace{B} \\) as\n\\[ H \\left( b_1, b_2 \\right) = \\min_{x \\in b_1} \\min_{y \\in b_2} \\left\\lVert x - y \\right\\rVert \\]\nThe \\( k \\)-nearest neighbour algorithm (see \\cite{dasarathy_nearest_1991}) is modified for this application by adding a system of \\VUname{citations} and \\VUname{references}. The \\( r \\)-nearest references are the nearest neighbours from the vanilla kNN algorithm and the \\( c \\)-nearest citers are defined as\n\\[ \\mathrm{Citers} \\left( x, c \\right) = \\left\\{ x_i \\middle| \\mathrm{Rank} \\left( x_i, x \\right) \\leq c \\wedge x_i \\in b \\right\\} \\]\nFor each bag, the \\( r \\)-nearest references and the \\( c \\)-nearest citers are found using the modified Hausdorff distance. If among those there are more positive bags then there are negative ones, the bag is labelled as positive. Otherwise the bag is labelled as negative.\n\nFor more applications using the bag-space paradigm, see \\cite{wang_solving_2000}, \\cite{kwok_marginalized_2007}, \\cite{gartner_multi-instance_2002}, \\cite{haussler_convolution_1999}, \\cite{zhou_multi-instance_2009} and \\cite{muandet_learning_2012}.\n\n\\subsection{Embedded-space paradigm}\\label{embedded-space-paradigm}\nIn the embedded space paradigm, labels are only defined on the level of bags, same as in the bag-space paradigm. In order for these bag labels to be learned, an embedding function of the form \\( \\phi : \\VUspace{B} \\to \\bar{\\VUspace{X}} \\) must be defined, where \\( \\bar{\\VUspace{X}} \\) is a new input space, which may or may not be identical to \\( \\VUspace{X} \\). Using this function, each bag can be represented by an input object \\( \\phi \\left( b \\right) \\in \\bar{\\VUspace{X}} \\), which makes it possible to use any off-the-shelf supervised learning algorithm. Amongst the simplest embedding functions are e. g. element-wise minimum, maximum and mean. A more complicated embedding function may for example apply a neural network to each instance of the bag and subsequently pool the instances using one of the aforementioned functions.\n\n\\VUname{MILES}, proposed by \\cite{chen_miles:_2006}, uses an instance dictionary \\( \\VUspace{D} \\) to define an embedding function representing the degree of similarity between the bag and the dictionary, that is\n\\[ \\phi : \\VUspace{B} \\to \\VUfield{R}^{\\left\\lvert \\VUspace{D} \\right\\rvert} \\]\nwhich is defined element-wise as\n\\[ \\phi_i \\left( b \\right) = \\sum_{x \\in b} k \\left( x, d_i \\right) \\quad \\text{where} \\quad d_i \\in \\VUspace{D} \\]\nwhere\n\\[ k \\left( x, d \\right) = \\begin{cases}\n\t\te^{- \\frac{1}{\\sigma^2} \\left\\lVert x - d \\right\\rVert^2} &\\text{if } d \\text{ is the nearest neighbour of } x \\text{ in } \\VUspace{D} \\\\\n\t\t0 &\\text{otherwise}\n\t\\end{cases} \\]\nThe dictionary is populated by a 1-class support vector machine (see \\cite{zhu_1-norm_2004}), which, however, has a high computational complexity.\n\nFor more applications using the embedded-space paradigm, see \\cite{cheplygina_multiple_2015}, \\cite{chen_image_2004} \\cite{foulds_learning_2008}, \\cite{zhang_multi-instance_2009} and \\cite{dedic_hierarchicke_2017}.\n", "meta": {"hexsha": "dccd41bfe550b2d3a1ca6df72fa317f11390f209", "size": 14489, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MIL.tex", "max_stars_repo_name": "marekdedic/VU-text", "max_stars_repo_head_hexsha": "f24cb31a2b9ba92656a9f7af9ec74f24c5bdde1c", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MIL.tex", "max_issues_repo_name": "marekdedic/VU-text", "max_issues_repo_head_hexsha": "f24cb31a2b9ba92656a9f7af9ec74f24c5bdde1c", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MIL.tex", "max_forks_repo_name": "marekdedic/VU-text", "max_forks_repo_head_hexsha": "f24cb31a2b9ba92656a9f7af9ec74f24c5bdde1c", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 108.9398496241, "max_line_length": 837, "alphanum_fraction": 0.7233763545, "num_tokens": 4420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969193, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7091026733749956}}
{"text": "\\subsection{True and False}\n\nWe start off with two statements:\n\n\\begin{itemize}\n\\item True - \\(T\\) or \\(\\top \\)\n\\item False - \\(F\\) or \\(\\bot \\)\n\\end{itemize}\n\n", "meta": {"hexsha": "2a6a101d0c255429c2ab4daba15ed6b2309a4347", "size": 160, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogic/01-01-truth.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/propositionalLogic/01-01-truth.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/propositionalLogic/01-01-truth.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.0, "max_line_length": 33, "alphanum_fraction": 0.625, "num_tokens": 52, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.905989815306765, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7090842393469607}}
{"text": "%*******************************************************************************\n%********************************* Appendix B **********************************\n%*******************************************************************************\n\\chapter{Graph Theory}\n\\chaptermark{Graph Theory}\n\\label{AppendixB}\n\n\\section{Introduction}\n\nMultiple real life situations can be modelled by a set of vertices connected together by edges, this representation is called a graph. Graph theory is a field of discrete mathematics that has been developed in order to provide the tools to analyse and solve problems involving graphs, subsequently providing answers to the real life situations they represent \\citep{Diestel2000,Bondy2008}. Graphs can be undirected, directed, and even weighted based on the type of situation that is modelled. A given graph $\\mathcal{G}$ is defined by an ordered pair of elements, including a set of vertices $V$ and a set of edges $E$ such that, \n\n\\begin{equation} \\label{eqnB.1}\n\\mathcal{G} = (V,E).\n\\end{equation}\n\nThe set of edges $E$ is composed of pairs of vertices taken from the set $V$ that can be directed and even weighted in some cases. Graphs can also be defined by their incidence or adjacency matrices. The incidence matrix of an undirected graph is a rectangle matrix whose rows represent the vertices and whose columns represent the edges, its entries are positive integers representing the number of times a vertex and an edge are incident. The adjacency matrix is a square matrix with rows and columns labelled after the vertices and composed of binaries. When an entry is equal to $1$, it indicates the presence of an edge between the vertices corresponding to the row and column indexes, whereas a $0$ entry  means that there is no direct link between these two particular vertices. A graph is said to be disconnected if its vertices can be partitioned into two distinct subsets that do not share any edges, otherwise a graph is said to be connected.\n\n\\section{Undirected Graphs}\n\nAn undirected graph also called simple graph is a graph where the edges are not oriented, therefore, the edge $\\{1,2\\}$ is the same as the edge $\\{2,1\\}$. A direct consequence of this is that for an undirected graph with $n$ vertices the maximum number of edges is $\\frac{n(n-1)}{2}$ if loops are not considered and $\\frac{n(n+1)}{2}$ with loops. Two vertices linked by an edge are said to be adjacent, and a vertex is said to be incident with an edge and vice versa. Subsequently, a graph can be defined by its incidence matrix or adjacency matrix. The adjacency matrix of a simple graph is a symmetric binary matrix, the Figure \\ref{figB.1} represents a simple undirected graph with $10$ vertices.\n\n\\begin{figure}[!htbp]\n\\centering\n\\begin{tikzpicture}[scale=4,\n\tvertex/.style={draw,circle,minimum size=0.75cm,inner sep=0pt},\n\tarc/.style={draw=blue!#10,thick,->},\n\tarc label/.style={fill=white,circle,font=\\tiny,inner sep=1pt},\n\tloop arc/.style={min distance=2mm,looseness=8}]\n\t\\foreach [count=\\i] \\coord in\n\t\t\t\t\t\t\t{(1.000,0.000),\n\t\t\t\t\t\t\t (0.809,0.588),\n\t\t\t\t\t\t\t (0.309,0.951),\n\t\t\t\t\t\t\t (-0.309,0.951),\n\t\t\t\t\t\t\t (-0.809,0.588),\n\t\t\t\t\t\t\t (-1.000,0.000),\n\t\t\t\t\t\t\t (-0.809,-0.588),\n\t\t\t\t\t\t\t (-0.309,-0.951),\n\t\t\t\t\t\t\t (0.309,-0.951),\n\t\t\t\t\t\t\t (0.809,-0.588)}\n\t\t\t\t\t\t\t {\n\t\t\t\t\\node[vertex] (p\\i) at \\coord {\\i};\n\t\t}\n\t\t\\graphfromadj[bend left=0]{p}{{0,0,0,0,10,0,0,0,0,10},\n\t\t\t\t\t\t\t\t\t\t{10,0,0,0,0,10,0,0,0,0},\n\t\t\t\t\t\t\t\t\t\t{0,10,0,0,0,0,10,0,0,0},\n\t\t\t\t\t\t\t\t\t\t{0,0,10,0,0,0,0,10,0,0},\n\t\t\t\t\t\t\t\t\t\t{0,0,0,10,0,0,0,0,10,0},\n\t\t\t\t\t\t\t\t\t\t{0,0,0,0,10,0,0,0,0,10},\n\t\t\t\t\t\t\t\t\t\t{10,0,0,0,0,10,0,0,0,0},\n\t\t\t\t\t\t\t\t\t\t{0,10,0,0,0,0,10,0,0,0},\n\t\t\t\t\t\t\t\t\t\t{0,0,10,0,0,0,0,10,0,0},\n\t\t\t\t\t\t\t\t\t\t{0,0,0,10,0,0,0,0,10,0}}{36}{30}{1}\n\\end{tikzpicture}\n\\caption{Example of an undirected graph.}\n\\label{figB.1}\n\\end{figure}\n\nThe adjacency matrix representation is not unique and any permutations of a row and a column with equal indexes will yield the same graph by changing the vertex labels. A possible adjacency matrix $\\mathcal{A}$ for the graph presented in Figure \\ref{figB.1} is as follows,\n\n\\begin{equation} \\label{eqnB.2}\n\\mathcal{A}=\n\\begin{bmatrix}\n0 & 1 & 0 & 0 & 1 & 0 & 1 & 0 & 0 & 1 \\\\\n1 & 0 & 1 & 0 & 0 & 1 & 0 & 1 & 0 & 0 \\\\\n0 & 1 & 0 & 1 & 0 & 0 & 1 & 0 & 1 & 0 \\\\\n0 & 0 & 1 & 0 & 1 & 0 & 0 & 1 & 0 & 1 \\\\\n1 & 0 & 0 & 1 & 0 & 1 & 0 & 0 & 1 & 0 \\\\\n0 & 1 & 0 & 0 & 1 & 0 & 1 & 0 & 0 & 1 \\\\\n1 & 0 & 1 & 0 & 0 & 1 & 0 & 1 & 0 & 0 \\\\\n0 & 1 & 0 & 1 & 0 & 0 & 1 & 0 & 1 & 0 \\\\\n0 & 0 & 1 & 0 & 1 & 0 & 0 & 1 & 0 & 1 \\\\\n1 & 0 & 0 & 1 & 0 & 1 & 0 & 0 & 1 & 0\n\\end{bmatrix}\n\\end{equation}\n\nSimilarly, a graph can be defined by its incidence matrix $\\mathcal{I}$. This kind of matrix links each edge to the two vertices it connects. The incidence matrix of the graph \\ref{eqnB.1} is presented in equation \\eqref{eqnB.3}. It can be noted that the adjacency matrix does not have to be symmetric or even square since the number of edges can be different from the number of vertices. In the same way as for the adjacency matrix, any permutations of the rows and the columns will represent the same graph after changing the labels of the vertices and of the edges respectively. Very often graphs have a lot more edges than vertices, subsequently in most cases the adjacency matrix constitutes a more compact way to store a graph than the incidence matrix. Hence, it is the preferred representation in most cases.\n\n\\begin{equation} \\label{eqnB.3}\n\\mathcal{I}^{\\top}=\n\\begin{bmatrix}\n1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n0 & 0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 \\\\\n0 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 0 \\\\\n0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 & 0 \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 \\\\\n1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\\\\n1 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\\\\n1 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n0 & 1 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\\\\n0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\n0 & 0 & 1 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n0 & 0 & 0 & 1 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\n0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 \\\\\n0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 1 & 0 \\\\\n0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 1\n\\end{bmatrix}\n\\end{equation}\n\nGraphs are mathematical objects used to represent a given topology and consequently, the relative position of the vertices as well as the shape of the edges does not change the topological properties of a given graph. However, only plotting the undirected edges between a set of vertices can be insufficient sometimes, and in some cases associating an edge with a specific direction can carry some useful meaning. This property is achieved for the directed graphs and presented within the next section.\n\n\\section{Directed Graphs}\n\nEach edge of a simple graph can be oriented from a vertex towards another in order to define a directed graph. An edge is called a loop if it connects a vertex to itself. A directed graph also called a digraph does not usually include any loops or parallel edges (multiple edges from and to the same vertex). The graph presented in Figure \\ref{figB.2} corresponds to the oriented adjacency matrix $\\mathcal{A}$ given equation \\eqref{eqnB.4}. In this case the adjacency matrix is still square and composed of binaries entries but does not have to be symmetric any more. Indeed, the adjacency matrix of a digraph contains the information related to the incidence of the edges as well as their orientation. Any element of $\\mathcal{A}$ indicates the number of edges starting from the vertex indexed by the row index and going to the vertex indexed by the column index. Directed graphs do not only inform on the topology but also on the direction of the edges between the vertices, therefore, they can be used to represent a succession of states or flows between vertices. In the example presented Figure \\ref{eqnB.2}, each vertex is the initial vertex of two edges and the terminal vertex of two other edges.\n\n\\begin{figure}[!htbp]\n\\centering\n\\begin{tikzpicture}[scale=4,\n\t\tvertex/.style={draw,circle,minimum size=0.75cm,inner sep=0pt},\n\t\tarc/.style={draw=blue!#10,thick,->},\n\t\tarc label/.style={fill=white,circle,font=\\tiny,inner sep=1pt},\n\t\tloop arc/.style={min distance=2mm,looseness=8}\n\t\t]\n\t\t\\foreach [count=\\i] \\coord in\n\t\t\t\t\t\t\t{(1.000,0.000),\n\t\t\t\t\t\t\t (0.809,0.588),\n\t\t\t\t\t\t\t (0.309,0.951),\n\t\t\t\t\t\t\t (-0.309,0.951),\n\t\t\t\t\t\t\t (-0.809,0.588),\n\t\t\t\t\t\t\t (-1.000,0.000),\n\t\t\t\t\t\t\t (-0.809,-0.588),\n\t\t\t\t\t\t\t (-0.309,-0.951),\n\t\t\t\t\t\t\t (0.309,-0.951),\n\t\t\t\t\t\t\t (0.809,-0.588)}\n\t\t\t\t\t\t\t {\n\t\t\t\t\\node[vertex] (p\\i) at \\coord {\\i};\n\t\t}\n\t\t\\directedgraphfromadj[bend left=5]{p}{{0,0,0,0,0,0,10,0,0,10},\n\t\t\t\t\t\t\t\t\t\t\t{10,0,0,0,0,0,0,10,0,0},\n\t\t\t\t\t\t\t\t\t\t\t{0,10,0,0,0,0,0,0,10,0},\n\t\t\t\t\t\t\t\t\t\t\t{0,0,10,0,0,0,0,0,0,10},\n\t\t\t\t\t\t\t\t\t\t\t{10,0,0,10,0,0,0,0,0,0},\n\t\t\t\t\t\t\t\t\t\t\t{0,10,0,0,10,0,0,0,0,0},\n\t\t\t\t\t\t\t\t\t\t\t{0,0,10,0,0,10,0,0,0,0},\n\t\t\t\t\t\t\t\t\t\t\t{0,0,0,10,0,0,10,0,0,0},\n\t\t\t\t\t\t\t\t\t\t\t{0,0,0,0,10,0,0,10,0,0},\n\t\t\t\t\t\t\t\t\t\t\t{0,0,0,0,0,10,0,0,10,0}}{36}{30}{1}\n\\end{tikzpicture}\n\\caption{Example of a directed graph.}\n\\label{figB.2}\n\\end{figure}\n\nConsequently, in this specific case the binary entries of the adjacency matrix $\\mathcal{A}$ are positioned in such a way that each row and each column sum to two. A row sums to two for two edges leaving a vertex and a column sums to two for two edges going to a vertex.\n\n\\begin{equation} \\label{eqnB.4}\n\\mathcal{A}=\n\\begin{bmatrix}\n0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 1 \\\\\n1 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\n0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\\\\n1 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n0 & 1 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\\\\n0 & 0 & 1 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\\\\n0 & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n0 & 0 & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 0 \\\\\n0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 1 & 0\n\\end{bmatrix}\n\\end{equation}\n\nThe representation of a directed graph by its incidence matrix is done by adding signs to the matrix entries. An entry is set to $-1$ if an edge leaves a vertex and to $1$ if an edge points towards a vertex, it is set to $0$ otherwise.\n\n\\section{Weighted Graphs}\n\nIn some cases it is important to associate each oriented edge of a directed graph to a weight. Weighted graphs are used to define a certain distance closeness between two given vertices and are therefore essential to analyse the flow between vertices. In the same way as for the simple graphs and the directed graphs, weighted graphs could be defined by their incidence or adjacency matrix.\n\n\\begin{figure}[!htbp]\n\\centering\n\\begin{tikzpicture}[scale=4,\n\t\tvertex/.style={draw,circle,minimum size=0.75cm,inner sep=0pt},\n\t\tarc/.style={draw=blue!#10,thick,->},\n\t\tarc label/.style={fill=white,circle,font=\\tiny,inner sep=1pt},\n\t\tloop arc/.style={min distance=2mm}\n\t\t]\n\t\t\\foreach [count=\\i] \\coord in\n\t\t\t\t\t\t\t{(1.000,0.000),\n\t\t\t\t\t\t\t (0.809,0.588),\n\t\t\t\t\t\t\t (0.309,0.951),\n\t\t\t\t\t\t\t (-0.309,0.951),\n\t\t\t\t\t\t\t (-0.809,0.588),\n\t\t\t\t\t\t\t (-1.000,0.000),\n\t\t\t\t\t\t\t (-0.809,-0.588),\n\t\t\t\t\t\t\t (-0.309,-0.951),\n\t\t\t\t\t\t\t (0.309,-0.951),\n\t\t\t\t\t\t\t (0.809,-0.588)}\n\t\t\t\t\t\t\t {\n\t\t\t\t\\node[vertex] (p\\i) at \\coord {\\i};\n\t\t}\n\t\t\\weigthedgraphfromadj[bend left=10]{p}{{0,0,0,0,0,0,5,0,0,9},\n\t\t\t\t\t\t\t\t\t\t\t\t {2,0,0,0,0,0,0,2,0,0},\n\t\t\t\t\t\t\t\t\t\t\t\t {0,5,0,0,0,0,0,0,5,0},\n\t\t\t\t\t\t\t\t\t\t\t\t {0,0,7,0,0,0,0,0,0,10},\n\t\t\t\t\t\t\t\t\t\t\t\t {7,0,0,9,0,0,0,0,0,0},\n\t\t\t\t\t\t\t\t\t\t\t\t {0,6,0,0,2,0,0,0,0,0},\n\t\t\t\t\t\t\t\t\t\t\t\t {0,0,5,0,0,1,0,0,0,0},\n\t\t\t\t\t\t\t\t\t\t\t\t {0,0,0,5,0,0,2,0,0,0},\n\t\t\t\t\t\t\t\t\t\t\t\t {0,0,0,0,8,0,0,5,0,0},\n\t\t\t\t\t\t\t\t\t\t\t\t {0,0,0,0,0,3,0,0,8,0}}{36}{30}{1}\n\\end{tikzpicture}\n\\caption{Example of a weighted graph.}\n\\label{figB.3}\n\\end{figure}\n\nThe adjacency matrix of a weighted graph has to contain the necessary information about the weights and the orientations of all the edges. A weight is located on the entry at the intersection of the row and the column, whose indexes are the index of the initial vertex and of the terminal vertex respectively. The entries of the incidence matrix are the weights of the edges with positive and negative signs, positive for an edge that is directed from a vertex and negative for an edge directed towards a vertex.\n\n\\section{Multi-graphs}\n\nFinally, multi-graphs allow to have multiple weighted edges between two given vertices, also a given vertex can be connected to itself by a loop. Therefore, multi-graphs subsume the oriented and weighted graphs into one single type of graph. In the same way as before they can be represented by an adjacency matrix $\\mathcal{A}$ as presented equation \\eqref{eqnB.5} or by an incidence matrix. The multi-graph linked to the adjacency matrix $\\mathcal{A}$ is shown in Figure \\ref{figB.4}. The adjacency matrix contains the orientation of each edge as well as their respective weights, subsequently it is a square matrix linking the vertices with weights. The edges connect the vertices indexed by the row indexes to the ones indexed by the column indexes with the weight provided by the value of the matrix entry. The incidence matrix has the same definition as the incidence matrix for the weighted graphs, possibly including many parallel edges as well as loops.\n\n\\begin{equation} \\label{eqnB.5}\n\\mathcal{A}=\n\\begin{bmatrix}\n1 & 5 & 0 & 0 & 1 & 0 & 5 & 0 & 0 & 5 \\\\\n2 & 2 & 1 & 0 & 0 & 5 & 0 & 2 & 0 & 0 \\\\\n0 & 5 & 3 & 2 & 0 & 0 & 2 & 0 & 5 & 0 \\\\\n0 & 0 & 7 & 4 & 5 & 0 & 0 & 2 & 0 & 5 \\\\\n7 & 0 & 0 & 7 & 5 & 5 & 0 & 0 & 1 & 0 \\\\\n0 & 5 & 0 & 0 & 2 & 6 & 5 & 0 & 0 & 1 \\\\\n2 & 0 & 5 & 0 & 0 & 1 & 7 & 5 & 0 & 0 \\\\\n0 & 7 & 0 & 5 & 0 & 0 & 2 & 8 & 1 & 0 \\\\\n0 & 0 & 5 & 0 & 7 & 0 & 0 & 5 & 9 & 1 \\\\\n5 & 0 & 0 & 5 & 0 & 1 & 0 & 0 & 1 & 10\n\\end{bmatrix}\n\\end{equation}\n\n\\begin{figure}[!htbp]\n\\centering\n\\begin{tikzpicture}[scale=4,\n\t\tvertex/.style={draw,circle,minimum size=0.75cm,inner sep=0pt},\n\t\tarc/.style={draw=blue!#10,thick,->},\n\t\tarc label/.style={fill=white,circle,font=\\tiny,inner sep=1pt},\n\t\tloop arc/.style={loop,min distance=2mm}\n\t\t]\n\t\t\\foreach [count=\\i] \\coord in\n\t\t\t\t\t\t\t{(1.000,0.000),\n\t\t\t\t\t\t\t (0.809,0.588),\n\t\t\t\t\t\t\t (0.309,0.951),\n\t\t\t\t\t\t\t (-0.309,0.951),\n\t\t\t\t\t\t\t (-0.809,0.588),\n\t\t\t\t\t\t\t (-1.000,0.000),\n\t\t\t\t\t\t\t (-0.809,-0.588),\n\t\t\t\t\t\t\t (-0.309,-0.951),\n\t\t\t\t\t\t\t (0.309,-0.951),\n\t\t\t\t\t\t\t (0.809,-0.588)}\n\t\t\t\t\t\t\t {\n\t\t\t\t\\node[vertex] (p\\i) at \\coord {\\i};\n\t\t}\n\t\t\\weigthedgraphfromadj[bend left=10]{p}{{1,5,0,0,1,0,5,0,0,5},\n\t\t\t\t\t\t\t\t\t\t\t {2,2,1,0,0,5,0,2,0,0},\n\t\t\t\t\t\t\t\t\t\t\t {0,5,3,2,0,0,2,0,5,0},\n\t\t\t\t\t\t\t\t\t\t\t {0,0,7,4,5,0,0,2,0,5},\n\t\t\t\t\t\t\t\t\t\t\t {7,0,0,7,5,5,0,0,1,0},\n\t\t\t\t\t\t\t\t\t\t\t {0,5,0,0,2,6,5,0,0,1},\n\t\t\t\t\t\t\t\t\t\t\t {2,0,5,0,0,1,7,5,0,0},\n\t\t\t\t\t\t\t\t\t\t\t {0,7,0,5,0,0,2,8,1,0},\n\t\t\t\t\t\t\t\t\t\t\t {0,0,5,0,7,0,0,5,9,1},\n\t\t\t\t\t\t\t\t\t\t\t {5,0,0,5,0,1,0,0,1,10}}{36}{30}{1}\n\\end{tikzpicture}\n\\caption{Example of a weighted multi-graph.}\n\\label{figB.4}\n\\end{figure}", "meta": {"hexsha": "3a5b7e510eede1858861ea582ff08f760e4b0e33", "size": 14726, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendices/appendixB.tex", "max_stars_repo_name": "RockyRock/ThesisTexTemplate", "max_stars_repo_head_hexsha": "542ac874bdedd3eb6961da8f4211da4b099bff50", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-02-10T11:07:18.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-28T16:45:20.000Z", "max_issues_repo_path": "Appendices/appendixB.tex", "max_issues_repo_name": "RockyRock/ThesisTexTemplate", "max_issues_repo_head_hexsha": "542ac874bdedd3eb6961da8f4211da4b099bff50", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Appendices/appendixB.tex", "max_forks_repo_name": "RockyRock/ThesisTexTemplate", "max_forks_repo_head_hexsha": "542ac874bdedd3eb6961da8f4211da4b099bff50", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.5698113208, "max_line_length": 1205, "alphanum_fraction": 0.613336955, "num_tokens": 5343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035763237924, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7088663138242982}}
{"text": "\\chapter{Canonical Transformation}\nFor each problem there may be one particular choice for which all coordinates $q_i$ are cyclic. Then the conjugate momenta $p_i$ are all constant:\n$$p_i=\\alpha_i$$\nConsider a situation in which Hamiltonian is a constant of motion,\nthen \n$$H=H(\\alpha_1,.......\\alpha_n)$$\nso the Hamiltonian equations for $\\dot{q}_i$ are \n$$\\dot{q}_i=\\frac{\\partial H}{\\partial \\alpha_i}=\\omega_i$$\nWhere $\\omega_i$'s are functions of $\\omega_i$'s only \n$\\therefore $ solutions are\n$$ q_i=\\omega_i t+\\beta_i$$\nwhere $\\beta_i$'s are constants of integration.\\\\\n\\par Since the obivious generalized coordinates suggested by the problem will\nnot normally be cyclic, we must have a specific proceedure for transforming from one set of variables to some other set that may be more suitable.\\\\\n\\par In the Hameltonian formulation the momenta are also independent variable on the same level as the generalized coordinates. The similtaneous transformation of the independent coordinates and momenta $q_i,p_i$ to a new se t  $Q_i,P_i$ with (invertible) equation of transformation:\n$$Q_i=Q_i (q,p,t)$$\n$$P_i=P_i (q,p,t)$$\nWhich define a point transformation in phase space.\n\\section{Jacobian}\nIf $u$ and $v$ are two function of two independent variables $x$ and $y$ then the determinant $J=\\left|\\begin{array}{ll}\\frac{\\partial u}{\\partial x} & \\frac{\\partial u}{\\partial y} \\\\ \\frac{\\partial v}{\\partial x} & \\frac{\\partial v}{\\partial y}\\end{array}\\right|$ is called the Jacobian of $u$ and $v$ with respect to of $x$ and $y$ which is written as $\\frac{\\partial(u, v)}{\\partial(x, y)}$ or $J\\left(\\frac{u, v}{x, y}\\right)$\\\\\nIf $u, v$ and $w$ are three functions of three independent variables $x, y$ and $z$ then the determinant\\\\\n$J=\\left|\\begin{array}{lll}\\frac{\\partial u}{\\partial x} & \\frac{\\partial u}{\\partial y} & \\frac{\\partial u}{\\partial z} \\\\ \\frac{\\partial v}{\\partial x} & \\frac{\\partial v}{\\partial y} & \\frac{\\partial v}{\\partial z} \\\\ \\frac{\\partial w}{\\partial x} & \\frac{\\partial w}{\\partial y} & \\frac{\\partial w}{\\partial z}\\end{array}\\right|$\nis called the Jacobian of $u, v$ and $w$ with respect to of $x, y$ and $z$\nwhich is written as $\\frac{\\partial(u, v, w)}{\\partial(x, y, z)}$ or $J\\left(\\frac{u, v, w}{x, y, z}\\right)$\n\\subsection{Properties of Jacobian}\n\\begin{itemize}\n\t\\item  If $J=\\frac{\\partial(u, v, w)}{\\partial(x, y, z)}$ and $J^{\\prime}=\\frac{\\partial(x, y, z)}{\\partial(u, v, w)}$ then $J J^{\\prime}=1$\n\t\\item Chain rule for Jacobian if $u, v$ are functions of $r, s$ and $r, s$ functions of $x, y$ then $\\frac{\\partial(u, v)}{\\partial(x, y)}=\\frac{\\partial(u, v)}{\\partial(r, s)} \\cdot \\frac{\\partial(r, s)}{\\partial(x, y)}$\n\t\\item If $u_{1}, u_{2}, u_{3}$ instead of being given explicitly in terms $x_{1}, x_{2}, x_{3}$ be connected with them with equations such as\n\t$$\n\tf_{1}\\left(u_{1}, u_{2}, u_{3}, x_{1}, x_{2}, x_{3}\\right)=0 f_{2}\\left(u_{1}, u_{2}, u_{3}, x_{1}, x_{2}, x_{3}\\right)=0 f_{3}\\left(u_{1}, u_{2}, u_{3}, x_{1}, x_{2}, x_{3}\\right)=0\n\t$$\n\tthen $\\frac{\\partial\\left(u_{1}, u_{2}, u_{3}\\right)}{\\partial\\left(x_{1}, x_{2}, x_{3}\\right)}=(-1)^{3} \\frac{\\partial\\left(f_{1}, f_{2}, f_{3}\\right)}{\\partial\\left(x_{1}, x_{2}, x_{3}\\right)} / \\frac{\\partial\\left(f_{1}, f_{2}, f_{3}\\right)}{\\partial\\left(u_{1}, u_{2}, u_{3}\\right)}$\n\t\\\\\\\\$\\left((-1)^{3}\\right.$ is for three variable system $)$\n\t\\item  If $u_{1}, u_{2}, u_{3}$ be functions of $x_{1}, x_{2}, x_{3}$ then the necessary and sufficient condition for existence of a functional relationship of the form $f_{1}\\left(u_{1}, u_{2}, u_{3}\\right)=0$ is $J\\left[\\frac{\\partial\\left(u_{1}, u_{2}, u_{3}\\right)}{\\partial\\left(x_{1}, x_{2}, x_{3}\\right)}\\right]=0$\n\\end{itemize}\n\\section{Canonical Transformation}\n\t In Hamiltonian mechanics the transformation should be such that $Q$ and $P$ are canonical coordinates\n\tWe would like to change variables from the set $(a,p)$ to a new set $(Q,P )$ such that:\n\t\\begin{enumerate}\n\t\t\\item  Determinent of Jacobian matrix of transformation, $\\left| \\frac{\\partial(Q,P)}{\\partial(q,p)}\\right|=+1 $\n\t\t(This ensures that it is volume and orientation are preserved during transformation)\n\t\t\\item  Ensures structure of Hamilton's equation is not changed, so the exist a function $K=K(Q,P,t)$ \n\t\tsuch that the equation of motion of new set are\t\n\t\t$$\\dot{Q_i}-\\frac{\\partial K}{\\partial P_i}\\quad,\\quad\\dot{P_i}=\\frac{\\partial K}{\\partial Q_i}$$\n\t\t$K$ plays role of Hamiltonian in new coordinate set and known as 'kamiltonian'\t\n\t\\end{enumerate}\n\\begin{note}\n\tThe transformation considered be problem independent that is to say $(Q,P)$ must be canonical coordinates not onlu for some specific mechanical systems, but for all systems of the same number of degrees of freedom.\t\n\\end{note}\n\\textbf{Hamilton's Priciple of Transformed Coordinates}\\vspace{0.1cm}\\\\\n As $Q_i$ and $P_i$ are canonical variable they must satisfy Hamiltonians principle\n\\begin{equation}\n\\delta\\int\\limits_{t_1}^{t_2}(P_i\\dot{Q_i}-K(Q,P,t))dt=0\n\\end{equation}\nas of old canonical variables\n\\begin{equation}\n\\delta\\int\\limits_{t_1}^{t_2}(p_i\\dot{q_i}-H(Q,P,t))dt=0\n\\end{equation}\n$\\therefore$ we can say\n$$\\lambda (p_i\\dot{q_i}-H)=P_i\\dot{Q_i}-K+\\frac{\\partial F}{\\partial t}$$\n$F$ is a function of phase space coordinates with continuous second derivatives \\\\\n$\\lambda$ is a constant independent of canonical coordinates and the time and it is related to scale transformation. \\\\\\\\\nFor $\\lambda=1$ we have\n$$p_i\\dot{q_i}-H=P_i\\dot{Q_i}-K+\\frac{dF}{dt}$$\nWhich is simply called canonical transformation \n\\begin{note}\n\tA transformation of canonical coordinates for which is called extended canonical transformation\n\\end{note}\nCanonical Transformation have following four properties\n\\begin{enumerate}\n\t\\item The identity transformation is canonical.\n\t\\item If a transformation is canonical, so is its inverse.\n\t\\item Two successive canonical transformations (the group \"product\" operation) define a transformation that is also canonical.\n\t\\item The product operation is associative.\n\\end{enumerate}\n\\section{Generating Function}\n\\begin{itemize}\n\t\\item The term $\\frac{df}{dt}$ in canonical transformation contributes to the variation of action integral only at the end points, and will vanish if $F$ is a function of $(q,p t)$ or $(Q,P,t)$or any mixture of the phase space coordinates since these have zero variation at the end points.\n\t\\item Through equations of transformation and their inverses $F$ can be expressed partly in terms of the old set of variables and partly of the new.\n\t\\item $F$ acts as a bridge between the two sets of canonical variables and is called the generating function of transformation.\n\\end{itemize}\nThere are four types of generating function:\n\\begin{enumerate}\n\t\\item  $F=F_{1}\\left(q_{i}, Q_{i}, t\\right)$ known as $F_{1}\\left(q_{i}, Q_{i}, t\\right)$ is $F_{1}$ type Generating function.\n\t$$\n\t\\begin{aligned}\n\t\\left(\\sum_{i} p_{i} \\dot{q}_{i}-H\\right)&=\\left(\\sum_{i} P_{i} \\dot{Q}_{i}-K\\right)+\\frac{d F}{d t} \\Rightarrow\\left(\\sum_{i} p_{i} \\dot{q}_{i}-H\\right)=\\left(\\sum_{i} P_{i} \\dot{Q}_{i}-K\\right)+\\frac{d F_{1}}{d t} \\\\\n\t\\Rightarrow\\left(\\sum_{i} p_{i} \\dot{q}_{i}-H\\right)&=\\left(\\sum_{i} P_{i} \\dot{Q}_{i}-K\\right)+\\sum_{i} \\frac{\\partial F_{1}}{\\partial q_{i}} \\dot{q}_{i}+\\sum_{i} \\frac{\\partial F_{1}}{\\partial Q_{i}} \\dot{Q}_{i}+\\frac{\\partial F}{\\partial t}\\\\\n\t\\text{\tComparing both the }&\\text{coefficient of $\\dot{q}_{i}$ and $\\dot{Q}_{i}$}\\\\\n\t\\frac{\\partial F_{1}}{\\partial q_{i}}=p_{i} \\quad \\frac{\\partial F_{1}}{\\partial Q_{i}}&=-P_{i}\\text{ and }K=H+\\frac{\\partial F_{1}}{\\partial t}\n\t\\end{aligned}\n\t$$\n\t\\item $F=F_{2}\\left(q_{i}, P_{i}, t\\right)-Q_{i} P_{i}$ known as $F_{2}\\left(q_{i}, P_{i}, t\\right)$ is $F_{2}$ type Generating function.\\\\\n\t$$\n\t\\begin{aligned}\n\t\\left(\\sum_{i} p_{i} \\dot{q}_{i}-H\\right)&=\\left(\\sum_{i} P_{i} \\dot{Q}_{i}-K\\right)+\\frac{d F}{d t} \\\\\n\t\\Rightarrow\\left(\\sum_{i} p_{i} \\dot{q}_{i}-H\\right)&=\\left(\\sum_{i} P_{i} \\dot{Q}_{i}-K\\right)-\\sum_{i} \\dot{Q}_{i} P_{i}-\\sum_{i} Q_{i} \\dot{P}_{i}-\\frac{d F_{2}}{d t} \\\\\n\t\\Rightarrow\\left(\\sum_{i} p_{i} \\dot{q}_{i}-H\\right)&=\\left(\\sum_{i} P_{i} \\dot{Q}_{i}-K\\right)+\\sum_{i} \\frac{\\partial F_{2}}{\\partial q_{i}} \\dot{q}_{i}+\\sum_{i} \\frac{\\partial F_{2}}{\\partial P_{i}} \\dot{P}_{i}+\\frac{\\partial F_{2}}{\\partial t}-\\sum_{i} \\dot{Q}_{i} P_{i}-\\sum_{i} Q_{i} \\dot{P}_{i}\\\\\n\t\\text{Comparing both the }&\\text{coefficient of $\\dot{q}_{i}$ and $\\dot{P}_{i}$}\\\\\n\t\\frac{\\partial F_{2}}{\\partial q_{i}}=p_{i}, \\ \\frac{\\partial F_{2}}{\\partial P_{i}}&=Q_{i}\\text{ and }K=H+\\frac{\\partial F_{2}}{\\partial t}\n\t\\end{aligned}\n\t$$\n\t\\item  $F=F_{3}\\left(Q_{i}, p_{i}, t\\right)+q_{i} p_{i}$ known as $F_{3}\\left(Q_{i}, p_{i}, t\\right)$ is $F_{3}$ type Generating function.\n\t$$\n\t\\begin{aligned}\n\t\\left(\\sum_{i} p_{i} \\dot{q}_{i}-H\\right)&=\\left(\\sum_{i} P_{i} \\dot{Q}_{i}-K\\right)+\\frac{d F}{d t} \\\\\n\t\\Rightarrow\\left(\\sum_{i} p_{i} \\dot{q}_{i}-H\\right)&=\\left(\\sum_{i} P_{i} \\dot{Q}_{i}-K\\right)+\\frac{d F_{3}}{d t}+\\sum_{i} \\dot{q}_{i} p_{i}+\\sum_{i} q_{i} \\dot{p}_{i} \\\\\n\t\\Rightarrow\\left(\\sum_{i} p_{i} \\dot{q}_{i}-H\\right)&=\\left(\\sum_{i} P_{i} \\dot{Q}_{i}-K\\right)+\\sum_{i} \\frac{\\partial F_{3}}{\\partial Q_{i}} \\dot{Q}_{i}+\\sum_{i} \\frac{\\partial F_{3}}{\\partial p_{i}} \\dot{p}_{i}+\\frac{\\partial F_{3}}{\\partial t}+\\sum_{i} \\dot{q}_{i} p_{i}+\\sum_{i} q_{i} \\dot{p}_{i}\\\\\n\t\\text{\tComparing both the }&\\text{coefficient of $\\dot{q}_{i}$ and $\\dot{P}_{i}$}\\\\\n\t\\frac{\\partial F_{3}}{\\partial Q_{i}}=-P_{i},\\  \\frac{\\partial F_{3}}{\\partial p_{i}}&=-q_{i}\\text{ and }K=H+\\frac{\\partial F_{3}}{\\partial t}\n\t\\end{aligned}\n\t$$\n\t\\item  $F=F_{4}\\left(p_{i}, P_{i}, t\\right)+q_{i} p_{i}-Q_{i} P_{i}$ known as $F_{3}\\left(P_{i}, p_{i}, t\\right)$ is $F_{3}$ type Generating function.\n\t$$\n\t\\begin{aligned}\n\t\\left(\\sum_{i} p_{i} \\dot{q}_{i}-H\\right)&=\\left(\\sum_{i} P_{i} \\dot{Q}_{i}-K\\right)+\\frac{d F}{d t} \\\\\n\t\\Rightarrow\\left(\\sum_{i} p_{i} \\dot{q}_{i}-H\\right)&=\\left(\\sum_{i} P_{i} \\dot{Q}_{i}-K\\right)+\\frac{d F_{4}}{d t}+\\sum_{i} \\dot{q}_{i} p_{i}+\\sum_{i} q_{i} \\dot{p}_{i}-\\sum_{i} \\dot{Q}_{i} P_{i}-\\sum_{i} Q_{i} \\dot{P}_{i}\\\\\n\t\\Rightarrow\\left(\\sum_{i} p_{i} \\dot{q}_{i}-H\\right)&=\\left(\\sum_{i} P_{i} \\dot{Q}_{i}-K\\right)+\\sum_{i} \\frac{\\partial F_{4}}{\\partial P_{i}} \\dot{P}_{i}+\\sum_{i} \\frac{\\partial F_{4}}{\\partial p_{i}} \\dot{p}_{i}+\\frac{\\partial F_{4}}{\\partial t}+\\sum_{i} \\dot{q}_ip_i+q_i\\dot{p}_i-\\sum_{i} \\dot{Q}_iP_i-\\sum_{i} Q_i\\dot{P}_i\\\\\n\t\\text{Comparing both }&\\text{the coefficient of $\\dot{p}_{i}$ and $\\dot{P}_{i}$}\\\\\n\t\\frac{\\partial F_{4}}{\\partial p_{i}}=-q_{i},\\  \\frac{\\partial F_{4}}{\\partial P_{i}}&=Q_{i} \\text { and } K=H+\\frac{\\partial F_{4}}{\\partial t}\n\t\\end{aligned}\n\t$$\n\\end{enumerate}\n\t\\begin{table}[H]\n\t\\centering\n\t\\renewcommand*{\\arraystretch}{1.8}\n\t\\begin{tabular}{|p{4.5cm}|p{5cm}|p{5.5cm}|}\t\n\t\\hline Generating Function&Generating Function Derivatives&Trivial Special Case\\\\\n\t\\hline $F=F_{1}(q, Q, t)$&$p_{i}=\\frac{\\partial F_{1}}{\\partial q_{i}} \\quad P_{i}=-\\frac{\\partial F_{1}}{\\partial Q_{i}}$&$F_{1}=q_{i} Q_{i}, \\quad Q_{i}=p_{i}, \\quad P_{i}=-q_{i}$\\\\\n\t\\hline $F=F_{2}(q, P, t)-Q_{i} P_{i}$&$p_{i}=\\frac{\\partial F_{2}}{\\partial q_{i}} \\quad Q_{i}=\\frac{\\partial F_{2}}{\\partial P_{i}}$&$F_{2}=q_{i} P_{i}, \\quad Q_{i}=q_{i}, \\quad P_{i}=p_{i}$\\\\\n\t\\hline $F=F_{3}(p, Q, t)+q_{i} p_{i}$&$q_{i}=-\\frac{\\partial F_{3}}{\\partial p_{i}} \\quad P_{i}=-\\frac{\\partial F_{3}}{\\partial Q_{i}}$&$F_{3}=p_{i} Q_{i}, \\quad Q_{i}=-q_{i}, \\quad P_{i}=-p_{i}$\\\\\n\t\\hline $F=F_{4}(p, P, t)+q_{i} p_{i}-Q_{i} P_{i}$&$q_{i}=-\\frac{\\partial F_{4}}{\\partial p_{i}} \\quad Q_{i}=\\frac{\\partial F_{4}}{\\partial P_{i}}$&$F_{4}=p_{i} P_{i}, \\quad Q_{i}=p_{i}, \\quad P_{i}=-q_{i}$\\\\\\hline\n\t\\end{tabular}\n\\end{table}", "meta": {"hexsha": "28bf628d1132be274a1b6861b6cd508c3cb08d59", "size": 11681, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Classical Mechanics  -CSIR/chapter/Canonical Transformation.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Classical Mechanics  -CSIR/chapter/Canonical Transformation.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Classical Mechanics  -CSIR/chapter/Canonical Transformation.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 86.5259259259, "max_line_length": 433, "alphanum_fraction": 0.6544816368, "num_tokens": 4399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7088663071614175}}
{"text": "\\chapter{Elementary Properties of Groups}\n\\label{ch:elementary-properties-of-groups}\n%% FIXME: \\cite{Pinter2016}*{Chapter 4}\n\n\\begin{enumerate}[label={\\Alph*.},font={\\bfseries}]\n\\item {\\bf Solving Equations in Groups}\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item\n    \\begin{align*}\n      axb &= c \\\\\n      ax &= cb^{-1} \\\\\n      x &= a^{-1}cb^{-1}\n    \\end{align*}\n  \\item\n    \\begin{align*}\n      x^2b &= xa^{-1}c \\\\\n      xb &= a^{-1}c \\\\\n      x &= a^{-1}cb^{-1}\n    \\end{align*}\n  \\item\n    \\begin{align*}\n      acx &= xac \\\\\n      xacx &= x^2ac\n      \\\\\n      x^2a &= bxc^{-1} \\\\\n      x^2ac &= bx \\\\\n      \\\\\n      xacx &= bx \\\\\n      xac &= b \\\\\n      x &= b(ac)^{-1}\n    \\end{align*}\n  \\item\n    \\begin{align*}\n      x^3 &= e \\\\\n      \\\\\n      ax^2 &= b \\\\\n      a &= bx \\\\\n      x &= b^{-1}a\n    \\end{align*}\n  \\item\n    \\begin{align*}\n      x^5 &= e \\\\\n      x^4 &= x^{-1} \\\\\n      \\\\\n      x^2 &= a^2 \\\\\n      x^4 &= a^2x^2 \\\\\n      x^{-1} &= a^2x^2 \\\\\n      e &= a^4x \\\\\n      \\left(a^4\\right)^{-1} &= x\n    \\end{align*}\n  \\item\n    \\begin{align*}\n      x^2a &= (xa)^{-1} \\\\\n      \\\\\n      (xax)^3 &= bx \\\\\n      xa(x^2a)(x^2a)x &= bx \\\\\n      xa(xa)^{-1}(xa)^{-1}x &= bx \\\\\n      (xa)^{-1}x &= bx \\\\\n      a^{-1}x^{-1}x &= bx \\\\\n      b^{-1}a^{-1} &= x\n    \\end{align*}\n  \\end{enumerate}\n\\item {\\bf Rules of Algebra in Groups} \\\\\n  $$G = \\Group{\\Set{I,A,B,C,D,K}, \\cdot}$$ \\\\\n  \\begin{alignat*}{4}\n    & \\mathbf{I} &&=\n    \\begin{pmatrix}\n      \\phantom{-}1 & \\phantom{-}0 \\\\\n      \\phantom{-}0 & \\phantom{-}1\n    \\end{pmatrix}\n    \\qquad\n    \\mathbf{A} &&=\n    \\begin{pmatrix}\n      \\phantom{-}0 & \\phantom{-}1 \\\\\n      \\phantom{-}1 & \\phantom{-}0\n    \\end{pmatrix}\n    \\qquad\n    \\mathbf{B} &&=\n    \\begin{pmatrix}\n      \\phantom{-}0 & \\phantom{-}1 \\\\\n      -1 & -1\n    \\end{pmatrix} \\\\\n    & \\mathbf{C} &&=\n    \\begin{pmatrix}\n      -1 & -1 \\\\\n      \\phantom{-}0 & \\phantom{-}1\n    \\end{pmatrix}\n    \\qquad\n    \\mathbf{D} &&=\n    \\begin{pmatrix}\n      -1 & -1 \\\\\n      \\phantom{-}1 & \\phantom{-}0\n    \\end{pmatrix}\n    \\qquad\n    \\mathbf{K} &&=\n    \\begin{pmatrix}\n      \\phantom{-}1 & \\phantom{-}0 \\\\\n      -1 & -1\n    \\end{pmatrix}\n  \\end{alignat*}\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item\n    \\(\n      \\mathbf{A}^2 =\n      \\begin{pmatrix}\n        0 & 1 \\\\\n        1 & 0\n      \\end{pmatrix}\n      \\begin{pmatrix}\n        0 & 1 \\\\\n        1 & 0\n      \\end{pmatrix}\n      =\n      \\begin{pmatrix}\n        1 & 0 \\\\\n        0 & 1\n      \\end{pmatrix}\n      = e\n    \\)\n    ... but $\\mathbf{A} \\ne e$, so $x^2 = e \\centernot\\implies x = e$.\\qed\n  \\item $\\mathbf{A}^2 = \\mathbf{I}^2$, but $\\mathbf{A} \\ne \\mathbf{I}$, so $x^2 = a^2 \\centernot\\implies x = a$.\\qed\n  \\item $(\\mathbf{A}\\mathbf{B})^2 = \\mathbf{K}^2 = \\mathbf{I}$, and $\\mathbf{A}^2\\mathbf{B}^2 = \\mathbf{I}\\mathbf{D} = \\mathbf{D}$, but $\\mathbf{I} \\ne \\mathbf{D}$, so $(ab)^2 = a^2b^2$ is not true in every group $G$.\\footnote{$(ab)^2 = a^2b^2$ is only true in abelian groups.}\\qed\n  \\item $x^2 = x \\implies x = e$\n    \\begin{align*}\n      x^2 &= x \\\\\n      xx &= x \\\\\n      xxx^{-1} &= xx^{-1} \\\\\n      xe &= e \\\\\n      x &= e\n    \\end{align*}\n    \\qed\n  \\item\n    \\captionof{table}{$\\Group{\\Set{I,A,B,C,D,K}, \\cdot}$}\n    \\begin{tabular}{ c | c c c c c c}\n      $\\cdot$ & $\\mathbf{I}$ & $\\mathbf{A}$ & $\\mathbf{B}$ & $\\mathbf{C}$ & $\\mathbf{D}$ & $\\mathbf{K}$ \\\\\n      \\hline\n      $\\mathbf{I}$ & $\\mathbf{I}$ \\\\\n      $\\mathbf{A}$ & & $\\mathbf{I}$ \\\\\n      $\\mathbf{B}$ & & & $\\mathbf{D}$ \\\\\n      $\\mathbf{C}$ & & & & $\\mathbf{I}$ \\\\\n      $\\mathbf{D}$ & & & & & $\\mathbf{B}$ \\\\\n      $\\mathbf{K}$ & & & & & & $\\mathbf{I}$\n    \\end{tabular}\n\n    As shown in the table, there does not exist an $x \\in G$ such that $x = y^2$ for $y \\in \\Set{\\mathbf{A}, \\mathbf{C}, \\mathbf{K}}$. \\\\\n    Therefore $\\neg\\left(\\forall x \\in G,\\ \\exists y \\in G\\left( x = y^2 \\right)\\right)$.\\qed\n  \\item\n    \\begin{align*}\n      y &= xz \\\\\n      x^{-1}y &= x^{-1}xz \\\\\n      z &= x^{-1}y\n    \\end{align*}\n    Therefore, for all $x,y \\in G$, there exists a $z \\in G$ such that $y = xz$.\\qed\n  \\end{enumerate}\n\\newpage\n\\item {\\bf Elements That Commute}\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item $a^{-1}b^{-1} = (ba)^{-1} = (ab)^{-1} = b^{-1}a^{-1}$\n  \\item Since $a = b^{-1}ba = b^{-1}ab$, $ab^{-1} = (b^{-1}ab)b^{-1} = b^{-1}a$.\n  \\item $a(ab) = a(ba) = (ab)a$\n  \\item $(xax^{-1})(xbx^{-1}) = xa(x^{-1}x)bx^{-1} = x(ab)x^{-1} = x(ba)x^{-1} = xb(x^{-1}x)ax^{-1} = (xbx^{-1})(xax^{-1})$\n  \\item $ab = ba \\iff aba^{-1} = b$\n    \\begin{proof}\n      First, assume $ab = ba$.\n      Multiplying by $a^{-1}$ on the right shows $ab = ba \\implies aba^{-1} = b$.\n      %%\n      Next, assume $aba^{-1} = b$.\n      Multiplying by $a$ on the right shows $aba^{-1} = b \\implies ab = ba$.\n    \\end{proof}\n  \\item $ab = ba \\iff aba^{-1}b^{-1} = e$\n    \\begin{proof}\n      First, assume $ab = ba$.\n      Multiplying by $a^{-1}$ on the right yields $aba^{-1} = b$.\n      Then multiplying by $b^{-1}$ on the right yields $aba^{-1}b^{-1} = e$.\n      Thus $ab = ba \\implies x$.\n      %%\n      Next, assume $aba^{-1}b^{-1} = e$.\n      Multiplying by $b$ on the right yields $aba^{-1} = b$.\n      Then multiplying by $a^{-1}$ on the right yields $ab = ba$.\n      Thus $aba^{-1}b^{-1} = e \\implies ab = ba$ and $ab = ba \\iff aba^{-1}b^{-1} = e$.\n    \\end{proof}\n  \\end{enumerate}\n\\item {\\bf Group Elements and Their Inverses}\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item $ab = e \\implies ba = e$\n    \\begin{proof}\n      If $ab = e$, then $ab = aa^{-1}$, so by the cancellation law, $b = a^{-1}$ and $a = b^{-1}$. \\\\\n      Thus, $bb^{-1} = e \\implies ba = e$, as desired.\n    \\end{proof}\n  \\item $abc = e \\implies cab = e$ and $bca = e$.\n    \\begin{proof}\n      If $(ab)c = e$, then $(ab)c = (ab)(ab)^{-1}$, so by the cancellation law, $c = (ab)^{-1} = b^{-1}a^{-1}$ \\\\\n      Thus, $(ab)^{-1}(ab) = e \\implies c(ab) = e$, and $b(b^{-1}a^{-1})a = e \\implies cba = e$.\n    \\end{proof}\n  \\item ...\n  \\item Let $G$ be a group such that $xay = a^{-1}$ for all $a,x,y \\in G$.\n    Prove that $yax = a^{-1}$ as well.\n    \\begin{proof}\n      If $xay = a^{-1}$, then $(xay)a = a^{-1}a$, so by the definition of inversion, $(xay)a = e$.\n      Thus $x^{-1}(xay)ax = x^{-1}ex$, so by associativity and the definition of the identity element, $(x^{-1}x)a(yax) = e \\iff ea(yax) = e \\iff a(yax) = e$.\n      Multiply by $a^{-1}$ on the left to obtain $a^{-1}a(yax) = a^{-1}e$, so by the definition of inversion, $yax = a^{-1}$.\n    \\end{proof}\n  \\item Let $a = a^{-1}$, $b = b^{-1}$, and $c = c^{-1}$. If $ab = c$ show that $bc = a$ and $ca = b$ as well.\n    \\begin{align*}\n      ab &= c \\\\\n      abb^{-1} &= cb^{-1} = cb \\\\\n      a &= cb \\\\\n      a^{-1} &= b^{-1}c^{-1} = bc \\\\\n      bc &= a \\\\\n      \\\\\n      ab &= c \\\\\n      b^{-1}a^{-1} &= c^{-1} \\\\\n      ba^{-1} &= c \\\\\n      ba^{-1}a &= ca \\\\\n      ca &= b\n    \\end{align*}\n  \\item Let $abc = (abc)^{-1}$, show that $bca = (bca)^{-1}$ and $cab = (cab)^{-1}$.\n    \\begin{align*}\n      abc &= (abc)^{-1} \\\\\n      bca &= a^{-1}(abc)^{-1}a \\\\\n      &= a^{-1}(bc)^{-1} \\\\\n      &= (bca)^{-1} \\\\\n      \\\\\n      bca &= (bca)^{-1} \\\\\n      cab &= b^{-1}(bca)^{-1}b \\\\\n      &= b^{-1}(ca)^{-1} \\\\\n      &= (cab)^{-1}\n    \\end{align*}\n  \\item Let $a = a^{-1}$ and $b = b^{-1}$, show that $(ab)^{-1} = ba$.\n    \\begin{proof}\n      Replace $a$ and $b$ with their inverses on the right-hand side of\n      $(ab)^{-1} = b^{-1}a^{-1}$ to obtain $(ab)^{-1} = ba$.\n    \\end{proof}\n  \\item $a = a^{-1} \\iff a^2 = e$\n    \\begin{proof}\n      If $a = a^{-1}$, then $a^2 = e$ by multiplying by $a$ on the right.\n      If $a^2 = e$, then $a = a^{-1}$ by multiplying by $a^{-1}$ on the right.\n    \\end{proof}\n  \\item Let $c = c^{-1}$. Prove $ab = c \\iff abc = e$.\n    \\begin{proof}\n      If $ab = c$, then $ab = c^{-1}$, since $c = c^{-1}$.\n      Multiply by $c$ on the right to obtain $abc = e$.\n      %%\n      If $abc = e$, then $abc^{-1} = e$ since $c = c^{-1}$.\n      Multiply by $c$ on the right to obtain $ab = c$.\n    \\end{proof}\n  \\end{enumerate}\n\\item {\\bf Counting Elements and Their Inverses}\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item Prove that in any finite group $G$, $2 \\mid \\left|\\Set{x \\in G : x \\ne x\\inverse}\\right|$.\n    \\begin{proof}\n      By definition, $G = \\Set{x \\in G : x = x\\inverse} \\cup \\Set{x \\in G : x \\ne x\\inverse}$.\n\n      Therefore, $\\forall x \\in G\\left(x = x\\inverse \\lor \\left(x \\ne x\\inverse \\land \\exists y \\in G\\left(y \\ne x \\land y = x\\inverse\\right)\\right)\\right)$.\n\n      So, $\\left|\\Set{x \\in G : x \\ne x\\inverse}\\right| = \\left|\\Set{x_0,x_0\\inverse,x_1,x_1\\inverse,x_2,x_2\\inverse,x_3,x_3\\inverse...}\\right| = 2k$.\n    \\end{proof}\n  \\item Prove $\\left|\\Set{x \\in G : x = x\\inverse}\\right|$ has the same parity as $|G|$.\n    \\begin{proof}\n      Since $|G| = \\left|\\Set{x \\in G : x = x\\inverse}\\right| + \\left|\\Set{x \\in G : x \\ne x\\inverse}\\right|$, \\\\\n      and $\\left|\\Set{x \\in G : x \\ne x\\inverse}\\right|$ is even, $\\left|\\Set{x \\in G : x = x\\inverse}\\right|$ has the same parity as $|G|$.\n    \\end{proof}\n  \\item Prove $2 \\mid |G| \\implies \\exists x \\in G\\left(x \\ne e \\land x = x\\inverse \\right)$.\n    \\begin{proof}\n      If $2 \\mid |G|$ then $2 \\mid \\left|\\Set{x \\in G : x = x\\inverse}\\right|$. Since $e = e\\inverse$, $2 \\nmid \\left|\\Set{x \\in G : x \\ne e \\land x = x\\inverse}\\right|$ and thus $\\exists x \\in G\\left(x \\ne e \\land x = x\\inverse\\right)$.\n    \\end{proof}\n  \\item Given a finite abelian group $G = \\Set{e,a_1,a_2,...a_n}$, prove $(a_1a_2...a_n)^2 = e$.\n    \\begin{align*}\n      (a_1a_2...a_n)^2 &= (a_1a_2...a_n)(a_1^{-1}a_2^{-1}...a_n^{-1}) \\\\\n      &= a_1a_1^{-1}a_2a_2^{-1}...a_na_n^{-1} \\\\\n      &= ee...e \\\\\n      &= e\n    \\end{align*}\n    \\qed\n  \\item Prove $\\forall x \\in G\\left(x \\ne e \\implies x \\ne x\\inv\\right) \\implies a_1a_2...a_n = e$.\n    \\begin{proof}\n      Assume $\\forall x \\in G\\left(x \\ne e \\implies x \\ne x\\inv\\right)$.\n      Then $\\forall x \\in a_1a_2...a_n\\left(\\exists y \\in a_1a_2...a_n\\left(x \\ne y \\land y = x\\inv\\right)\\right)$.\n      So $a_1a_2...a_n$ can be rewritten $a_1a_1^{-1}a_2a_2^{-}...a_{n/2}a_{n/2}^{-1}$, which reduces to $e$.\n    \\end{proof}\n  \\item Prove that if there is exactly one $x \\ne e$ in $G$ such that $x = x\\inv$ then $a_1a_2...a_n = x$.\n    \\begin{proof}\n      $a_1a_2...a_n$ can be rewritten $xa_1a_1^{-1}a_2a_2^{-1}...a_{n/2}a_{n/2}^{-1}$, which is equivalent to $xe$.\n    \\end{proof}\n  \\end{enumerate}\n\\item {\\bf Constructing Small Groups}\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item $a,b \\in G$\n    \\begin{enumerate}[label={(\\alph*)},font={\\bfseries}]\n    \\item Prove $a^2 = a \\implies a = e$.\n      \\begin{proof}\n        Assume $a^2 = a$. Divide by $a$ to get $a = e$.\n      \\end{proof}\n    \\item Prove $ab = a \\implies b = e$.\n      \\begin{proof}\n        Assume $ab = a$.\n        Multiply by $a\\inv$ on the left to get ${a\\inv}ab = {a\\inv}a \\equiv b = e$.\n      \\end{proof}\n    \\item Prove $ab = b \\implies a = e$.\n      \\begin{proof}\n        Assume $ab = b$.\n        Multiply by $b\\inv$ on the right to get $ab{b\\inv} = b\\inv \\equiv a = e$.\n      \\end{proof}\n    \\end{enumerate}\n  \\item ...\\todo[inline]{Explain why elements of each row in a Cayley table must be distinct.}\n  \\item There is exactly oneo group with three distinct elements.\n    \\captionof{table}{\\href{https://nathancarter.github.io/group-explorer/Multtable.html?groupURL=https://nathancarter.github.io/group-explorer/groups/Z_3.group}{Multiplication Table for $\\mathbb{Z}_3$}}\n    \\begin{tabular}{ c | c c c }\n      $\\cdot$ & $\\mathbf{e}$ & $\\mathbf{a}$ & $\\mathbf{b}$ \\\\\n      \\hline\n      $\\mathbf{e}$ & $e$ & $a$ & $b$ \\\\\n      $\\mathbf{a}$ & $a$ & $b$ & $e$ \\\\\n      $\\mathbf{b}$ & $b$ & $e$ & $a$\n    \\end{tabular}\n    \\newpage\n  \\item There is exactly one group $G$ with four elements, such that $\\forall x \\in G (xx = e)$.\n    \\captionof{table}{\\href{https://nathancarter.github.io/group-explorer/Multtable.html?groupURL=https://nathancarter.github.io/group-explorer/groups/V_4.group}{Multiplication Table for $v_4$}}\n    \\begin{tabular}{ c | c c c c }\n      $\\cdot$ & $\\mathbf{e}$ & $\\mathbf{a}$ & $\\mathbf{b}$ & $\\mathbf{c}$  \\\\\n      \\hline\n      $\\mathbf{e}$ & $e$ & $a$ & $b$ & $c$ \\\\\n      $\\mathbf{a}$ & $a$ & $e$ & $c$ & $b$ \\\\\n      $\\mathbf{b}$ & $b$ & $c$ & $e$ & $a$ \\\\\n      $\\mathbf{c}$ & $c$ & $b$ & $a$ & $e$\n    \\end{tabular}\n  \\item There is exactly one group $G$ with four elements, such that $\\exists x \\in G (x \\ne e \\land xx = e)$ and\n    $\\exists y \\in G (yy \\ne e)$.\n    \\captionof{table}{\\href{https://nathancarter.github.io/group-explorer/Multtable.html?groupURL=https://nathancarter.github.io/group-explorer/groups/V_4.group}{Multiplication Table for $v_4$}}\n    \\begin{tabular}{ c | c c c c }\n      $\\cdot$ & $\\mathbf{e}$ & $\\mathbf{a}$ & $\\mathbf{b}$ & $\\mathbf{c}$  \\\\\n      \\hline\n      $\\mathbf{e}$ & $e$ & $a$ & $b$ & $c$ \\\\\n      $\\mathbf{a}$ & $a$ & $e$ & $c$ & $b$ \\\\\n      $\\mathbf{b}$ & $b$ & $c$ & $e$ & $a$ \\\\\n      $\\mathbf{c}$ & $c$ & $b$ & $a$ & $e$\n    \\end{tabular}\n    \\item ...\\todo[inline]{Explain why $\\mathbb{Z}_3$ and $V_4$ are the only possible groups of order 4.}\n  \\end{enumerate}\n\\item {\\bf Direct Products of Groups}\n  \\begin{enumerate}[label={\\arabic*},font={\\bfseries}]\n  \\item Prove that $G \\times H$ is a group.\n    \\begin{proof}\n      \\ \\\\\n      \\begin{enumerate}[label={(G\\arabic*)}]\n      \\item\n        \\begin{align*}\n          (x_1,y_1)\\left[(x_2,y_2)(x_3,y_3)\\right] &= (x_1,y_1)(x_2x_3,y_2y_3) \\\\\n          &= (x_1x_2x_3,y_1y_2y_3) \\\\\n          &= (x_1x_2,y_1y_2)(x_3,y_3) \\\\\n          &= \\left[(x_1,y_1)(x_2,y_2)\\right](x_3,y_3)\n        \\end{align*}\n      \\item Let $e_G$ be the identity element of $G$, and $e_H$ the identity element of $H$.\n        The identity element of $G \\times H$ is $(e_G,e_H)$.\n        \\begin{alignat*}{3}\n          &(x,y)(e_G,e_H) &&= (xe_G,ye_H) &&= (x,y) \\\\\n          \\\\\n          &(e_G,e_H)(x,y) &&= (e_Gx,e_Hy) &&= (x,y)\n        \\end{alignat*}\n      \\item $\\forall (a,b) \\in G \\times H \\left( (a,b)\\inv = (a\\inv,b\\inv) \\right)$\n        \\begin{alignat*}{4}\n          &(a,b)(a\\inv,b\\inv) &&= (aa\\inv,bb\\inv) &&= (e_G,e_H) &&= e_{G \\times H}\\\\\n          \\\\\n          &(a\\inv,b\\inv)(a,b) &&= ({a\\inv}a,{b\\inv}b) &&= (e_G,e_H) &&= e_{G \\times H}\n        \\end{alignat*}\n      \\end{enumerate}\n    \\end{proof}\n  \\end{enumerate}\n\\end{enumerate}\n", "meta": {"hexsha": "13857b2a08e2d8ce18b6832c5ac24f5d0d2abe7b", "size": 14394, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/ch4.tex", "max_stars_repo_name": "yurrriq/abstract-algebra-pinter", "max_stars_repo_head_hexsha": "58eed44088f29e2ddae9d7782f603562c04b0e37", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-09-24T23:35:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-08T20:26:03.000Z", "max_issues_repo_path": "src/ch4.tex", "max_issues_repo_name": "yurrriq/abstract-algebra-pinter", "max_issues_repo_head_hexsha": "58eed44088f29e2ddae9d7782f603562c04b0e37", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-01T07:16:00.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-19T06:01:56.000Z", "max_forks_repo_path": "src/ch4.tex", "max_forks_repo_name": "yurrriq/abstract-algebra-pinter", "max_forks_repo_head_hexsha": "58eed44088f29e2ddae9d7782f603562c04b0e37", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-24T23:35:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-24T23:35:51.000Z", "avg_line_length": 39.0081300813, "max_line_length": 281, "alphanum_fraction": 0.4952758094, "num_tokens": 5725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7088663062793815}}
{"text": "\\subsection{Partial Fractions}\r\n\\noindent\r\nIf we have a function of two polynomials $f(x) = \\frac{P(x)}{Q(x)}$, it's often easier to break this quotient into a sum of parts where the denominator is a linear or quadratic factor and the numerator is always a smaller degree than the denominator.\r\n\r\n\\begin{example}\r\n\t\\begin{equation*}\r\n\t\t\\frac{2x-1}{x^3-6x^2+11x-6} = \\frac{1/2}{x-1}+\\frac{-3}{x-2}+\\frac{5/2}{x-3}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\r\n\\noindent\r\nOne natural way to find these small denominators comes from the linear factors of the denominator where we keep quadratics with complex roots.\r\nThis way, when making a common denominator, we get back the original big denominator.\r\nHowever, there are a few special cases we have to take care of.\r\n\r\n\\input{../common/algebraPreCalc/linearFactors.tex}\r\n\\input{../common/algebraPreCalc/repeatedLinearFactors.tex}\r\n\\input{../common/algebraPreCalc/quadraticFactors.tex}\r\n\\input{../common/algebraPreCalc/repeatedQuadraticFactors.tex}\r\n\\input{../common/algebraPreCalc/improperFractions.tex}\r\n", "meta": {"hexsha": "9c3ae7861064ab859e0a1da9fd14079b4843b427", "size": 1045, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/algebraPreCalc/partialFractions.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "common/algebraPreCalc/partialFractions.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "common/algebraPreCalc/partialFractions.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 49.7619047619, "max_line_length": 251, "alphanum_fraction": 0.75215311, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7088663015434491}}
{"text": "\\chapter{Feature Reel} \n\n\\section{Maths}\n\n\\LaTeX{} shines when it comes to typesetting maths. This should work as expected when using this template, see \\Cref{eq:gauss-integral}. \n\\begin{equation}\\label{eq:gauss-integral}\n\t\\int_{-\\infty}^{\\infty} \\mathrm{e}^{-x^2} \\enspace \\mathrm{d}x = \\sqrt{\\pi} \n\\end{equation}\n\n\\section{Floating-Environments} \n% Figures, Tables, TikZ \n\nFigures and tables should be put in floating environments.\n\\Cref{fig:example-fig} shows an example of a floating figure.\n\\Cref{tab:example-table} shows an example of a floating table.\n\n\\begin{table}[ht]\n\t\\centering\n\t\\begin{tabular}{ccc}\n\t\t\\toprule\n\t\ta & b & c \\\\\n\t\t\\midrule\n\t\ta & b & c \\\\\n\t\td & e & f \\\\\n\t\tg & h & i \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\t\\caption{This is an example of a table with an extraordinarily long caption that requires multiple lines to demonstrate that this is, in principle, possible and still appealing.}\n\t\\label{tab:example-table} \n\\end{table}\n\n\\begin{figure}[ht]\n\t\\centering \n\t\\includegraphics{example-image-a}\n\t\\caption{This is an example figure} \n\t\\label{fig:example-fig} \n\\end{figure}\n\n\\section{Algorithms} \n% \nAlgorithms should be in floating environments. \n\\Cref{alg:swap} shows a levelwise graph mining algorithm taken from \\cite{theoremofbenda}.\nYou can reference individual lines in the algorithm, for example \\Cref{algline:swap:return}.\n\n\\begin{algorithm} \n\\begin{tabbing}\noutput \\= : \\= \\kill\ninput \\> : \\> A set of people $P$ who have been mindswapped, plus two helpers $a,b$ \\\\\n\\>\\>who have never been mindswapped \\\\\noutput \\> : \\> $P \\cup \\{a,b\\}$ with the right minds in the right bodies \\\\\n\\end{tabbing}\n\n\\begin{algorithmic}[1]\n\n\\State Have everybody who's messed up arrange themselves in circles of \"conga lines\", i.e. everyone's front facing someone's back, each facing the body their mind should land in (e.g., if Fry's mind is in Zoidberg's body, then Zoidberg's body should face the back of Fry's body).\n\n\\ForAll{Circle}\n\n\t\\State Start each time with Helper $a$ and Helper $b$'s minds in either their own or each other's bodies\n\n\t\\State Pick any circle of messed-up people you like and unwrap it into a line with whoever you like at the front\n\n\t\\State Swap the mind at the front of the line into Helper $a$'s body\n\n\t\\State From back to front, have everybody in the line swap minds with Helper $b$'s body in turn. (This moves each mind in the line, apart from the front one, forward into the right body. The last switch puts Helper $a$'s mind into Helper $b$'s body.)\n\n\t\\State Swap the mind in Helper $a$'s body back where it belongs, into the body at the back of the line. This puts Helper $b$'s mind in Helper $a$'s body. Now the circle/line has been completely fixed. The one side effect is that for each time a circle is fixed, the Helpers' minds will switch places, but that's OK, see below\\label{algline:swap:return}\n\\EndFor\n\n\\State At the very end, after all the circles have been fixed, mind-swap the two Helpers if necessary (i.e., in case there was originally an odd number of messed-up circles) \n\n\\end{algorithmic}\n\\vspace{1em}\n\\caption{Mind Swapping Algorithm \\cite{theoremofbenda}}\n\\label{alg:swap}\n\\end{algorithm}\n\n\\section{Theorem-like Environments} \\label{sec:theorem-like-environments} \n% list the predefined environments\n\nThe \\texttt{mlai-thesis} class provides the following set of theorem-like environments with an appropriate numbering scheme using the \\texttt{ntheorem} package: \n\\begin{description}[font=\\normalfont\\ttfamily]\n\t\\item[defn] Technical notions, such as abstract structures, complexity measures, data structures, etc., that are central for your thesis should be emphasized by properly \\emph{defining} them in a \\emph{definition} environment. \n\t\\item[thm] A \\emph{theorem} is an important and central theoretical result of your thesis and should be presented as such. \n\t\\item[proof] \\emph{Proofs} are necessary for every of your own theoretical results and most of the time come directly after a theorem, lemma, or proposition. Note that you can usually cite theorems by other authors without proof. When in doubt consult your supervisor. \n\t\\item[prop] A \\emph{proposition} is a self-contained mathematical result. Usually, a theoretical result that is interesting but not central for the research problem of your thesis can be presented as a proposition. \n\t\\item[lem] A \\emph{lemma} is a minor statement or an auxiliary statement that is used in the proof of another proposition or theorem. It is sensible to structure complicated proofs into logical units to improve the \n\t\\item[cor] A \\emph{corollary} is an immediate and obvious consequence of a theorem or proposition and as such does not require a comprehensive proof. \n\t\\item[rmk] Observations, ideas, motivations that you want to emphasize as such but are not really mathematical statements can be set as a \\emph{remark}. \n\t\\item[rmks] Used for multiple \\emph{remarks}. \n\t\\item[exa] It is always a good idea to provide an \\emph{example} that illustrates a notion, idea, or a result in an easy-to-understand way. \n\t\\item[exas] Used for multiple \\emph{examples}. \n\t\\item[prblm] A (research) \\emph{problem} you want to study or present and that is relevant for your thesis\n\t\\item[prblms] Used for multiple \\emph{problems}. \n\t\\item[quest] If you study a certain \\emph{question} and want to refer to it at other points in the thesis, it might be worth it to typeset it in a theorem-like environment. \n\t\\item[quests] Used for multiple \\emph{questions}. \n\\end{description}\n\nThe advantage of using theorem-like environments is not only that they are more prominent in the text emphasizing central notions and results but also that they can be labeled and referenced. The usage of theorem-like environments and how to reference them is demonstrated below. For instance,~\\Cref{prblm:mind-switching-problem} was produced by the following \\LaTeX{} code: \n\\begin{Verbatim}\n\\begin{prblm}[Mind-Switching Problem] \n\t\\label{prblm:mind-switching-problem}\n\t...\n\\end{prblm} \n\\end{Verbatim}\n\n\\begin{prblm}[Mind-Switching Problem] \n    \\label{prblm:mind-switching-problem}\n    \\textcolor{red}{todo} %TODO: \n\\end{prblm} \n\n\\begin{defn}\n\t\\textcolor{red}{todo} %TODO: \n\\end{defn}\n\n\\begin{thm}[Keeler's Theorem]\n\t\\textcolor{red}{todo} %TODO: \n\\end{thm}\n\nFor more information on the \\texttt{ntheorem} package, refer to its documentation. %TODO: cite the documentation\n\n\\section{List Environments} \n% itemize, enumerate, description\n\nYou can use the following nestable list environments \n\\begin{description}[font=\\normalfont\\ttfamily]\n\t\\item[itemize] used for bullet lists without numbering\n\t\\item[enumerate] used for numbered lists \n\t\\item[description] used for item description lists (such as this one)\n\\end{description}\n\nThis is an example for nested bullet lists: \n\\begin{enumerate} \n\t\\item Philip J. Fry \n\t\\begin{itemize} \n\t\t\\item was cryogenically frozen \n\t\t\\item delivery boy at Planet Express\n\t\t\\item former pizza delivery boy\n\t\\end{itemize}\n\t\\item Turanga Leela \n\t\\begin{itemize}\n\t\t\\item one-eyed mutant\n\t\t\\item purple hair \n\t\t\\item spaceship captain of \\enquote{Old Bessie} \n\t\\end{itemize}\n\t\\item Bender Bending Rodr\\'{i}guez\n\t\\begin{itemize}\n\t\t\\item Bending Unit 22\n\t\t\\item Unit no. 1729\n\t\t\\item Serial no. 2716057\n\t\\end{itemize}\n\\end{enumerate}\n\n\\section{Citations}\n \nYou can use the bibliography package of your liking. If you choose to stick with the default, i.e., \\texttt{biblatex} with \\texttt{biber} as a backend, you can cite sources by using the following commands: \n\\begin{description}[font=\\normalfont\\ttfamily]\n\t\\item[\\textbackslash{}cite] a bare citation without parentheses; example: \\cite{adams1979} \n\t\\item[\\textbackslash{}parencite] a citation enclosed in parentheses; example: \\parencite{adams1979} \n\t\\item[\\textbackslash{}textcite] a citation that is part of the text; example: \\textcite{adams1979} \n\\end{description}\nThe \\texttt{biblatex} package provides a rich tool set for citations and the bibliography. For further information, refer to the \\texttt{biblatex} documentation. %TODO: cite the biblatex documentation\nIn addition, the MLAI student's guide contains a section on what and how to cite your references properly according to scientific style. %TODO: cite the MLAI student's guide ", "meta": {"hexsha": "c0980efed8c2cd83089682ce1cd79b9b9182eab2", "size": 8205, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "feature-reel.tex", "max_stars_repo_name": "mlai-bonn/thesis-template", "max_stars_repo_head_hexsha": "69fc0c321d7c7dadbe99e7ccb637960c13d9dbcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-02T10:07:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-02T10:07:05.000Z", "max_issues_repo_path": "feature-reel.tex", "max_issues_repo_name": "mlai-bonn/thesis-template", "max_issues_repo_head_hexsha": "69fc0c321d7c7dadbe99e7ccb637960c13d9dbcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "feature-reel.tex", "max_forks_repo_name": "mlai-bonn/thesis-template", "max_forks_repo_head_hexsha": "69fc0c321d7c7dadbe99e7ccb637960c13d9dbcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-17T13:50:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-17T13:50:01.000Z", "avg_line_length": 50.3374233129, "max_line_length": 375, "alphanum_fraction": 0.7572212066, "num_tokens": 2262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.7088663013805728}}
{"text": "\\subsection{Implementing a Model-Checker}\n\n\\begin{frame}\n  \\frametitle{Implementing a Model-Checker}\n\n  In order to implement model-checker we need: \n  \\begin{enumerate}\n    \\item representing large sets of states\n    \\item computing $T(S^{(i)})$\n    \\item check if bad states are in $S^{(i)}$ \n    \\item check if $S^{(i)} \\equiv S^{(i+1)}$ \n  \\end{enumerate}\n  \\vfill\\pause\n  The naive way would be to represent states {\\bf explicitly} \n  (e.g., with a C {\\tt struct} containing values for state variables)\n  \\vfill\n  Very few model-checkers adopt this method (e.g., SPIN)\n  \\vfill\\pause\n  A more powerful approach represents \n  states {\\bf symbolically}, \n  by means of SAT/SMT-formul\\ae: each set of\n  states $S$ is represented by a formula $\\phi$ such\n  that $S$ corresponds to the models of $\\phi$\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Symbolic Model-Checking - Representing States}\n\n  \\scriptsize\n\n  Examples:\n  \\medskip\\\\\n  \\begin{tabular}{ccc}\n\n    \\begin{minipage}{.4\\textwidth}\n      \\input{symb_1}\n    \\end{minipage}\n    &~ &\n    door\\_open $\\wedge$ engine\\_on $\\wedge$ $\\neg$ tray\\_full \\\\\n    \\pause\n    \\\\\n\n    \\begin{minipage}{.4\\textwidth}\n      \\input{symb_2}\n    \\end{minipage}\n    &~ &\n    $\\neg$ door\\_open $\\wedge$ engine\\_on $\\wedge$ $\\neg$ tray\\_full \\\\\n    \\pause\n    \\\\\n\n    \\begin{minipage}{.4\\textwidth}\n      \\input{symb_3}\n    \\end{minipage}\n    &~ &\n    engine\\_on $\\wedge$ $\\neg$ tray\\_full \\\\\n\n  \\end{tabular}\n  \\vfill\\pause\n  Also, it is easy to see that:\n  \\medskip\\\\\n  \\begin{tabular}{ccc}\n    $S_1 \\cup S_2$ & & $\\phi_1 \\vee \\phi_2$ \\\\\n    $S_1 \\cap S_2$ & & $\\phi_1 \\wedge \\phi_2$ \\\\\n    $S_1 \\subseteq S_2$ & & $\\phi_1 \\rightarrow \\phi_2$ \n  \\end{tabular}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Symbolic Model-Checking - Representing Transitions}\n\n  \\scriptsize\n\n  Transitions are also represented as formul\\ae\\xspace between state\n  variables and their primed versions \n  \\vfill\n  \\begin{tabular}{llllcl}\n    \\multirow{2}{*}{if} & door=closed & \\multirow{2}{*}{then} & tray'=empty & & \\multirow{2}{*}{[start\\_washing]} \\\\ \n                        & engine=off  &                       & engine'=on  & &                                   \\\\\n  \\end{tabular}\n  \\vfill\n  $$\n    \\neg \\mbox{door\\_open} \\wedge \\neg \\mbox{engine\\_on} \\wedge \\neg \\mbox{door\\_open'} \\wedge \\mbox{engine\\_on'} \\wedge \\neg \\mbox{tray\\_full'}\n  $$\n  \\vfill\\pause\n  This formula says that the following pair of states are related\n  $$\n  \\begin{array}{rcl}\n    \\neg \\mbox{door\\_open} \\wedge \\neg \\mbox{engine\\_on} \\wedge \\neg \\mbox{tray\\_full} \n    & ~~~ & \\neg \\mbox{door\\_open'} \\wedge \\mbox{engine\\_on'} \\wedge \\neg \\mbox{tray\\_full'} \\\\\n    \\\\\n    \\neg \\mbox{door\\_open} \\wedge \\neg \\mbox{engine\\_on} \\wedge \\mbox{tray\\_full} \n    & ~~~ & \\neg \\mbox{door\\_open'} \\wedge \\mbox{engine\\_on'} \\wedge \\neg \\mbox{tray\\_full'} \n  \\end{array}\n  $$\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Symbolic Model-Checking - Computing Next State}\n\n  \\scriptsize\n\n  From a set of states $S^{(i)}$, represented symbolically by a formula $\\phi( \\vec{s} )$,\n  and a transition $t_j$, represented symbolically by a formula $\\psi( \\vec{s}, \\vec{s'} )$,\n  the next states $t_j(S^{(i)})$ can be expressed as\n  $$\n  \\exists \\vec{s}.\\ \\phi( \\vec{s} ) \\wedge \\psi( \\vec{s}, \\vec{s'} )\n  $$\n  By means of an operation called {\\bf quantifier elimination}, we can remove $\\vec{s}$.\n  If then we rename $\\vec{s'}$ as $\\vec{s}$ we obtain the symbolic representation of $t_j(S^{(i)})$\n  \\vfill\\pause\n  Example:\n  $$\n  \\begin{array}{l}\n    \\phi \\equiv \\neg \\mbox{door\\_open} \\wedge \\neg \\mbox{engine\\_on} \\\\\n    \\psi \\equiv \\neg \\mbox{door\\_open} \\wedge \\neg \\mbox{engine\\_on} \\wedge \n                \\neg \\mbox{door\\_open'} \\wedge \\mbox{engine\\_on'} \\wedge \\neg \\mbox{tray\\_full'} \\\\\n  \\end{array}\n  $$\n  Quantifier elimination of $\\exists \\mbox{ door\\_open}, \\mbox{engine\\_on}.\\ \\phi \\wedge \\psi$ is\n  $$\n    \\neg \\mbox{door\\_open'} \\wedge \\mbox{engine\\_on'} \\wedge \\neg \\mbox{tray\\_full'} \n  $$\n  and therefore\n  $$\n    \\neg \\mbox{door\\_open} \\wedge \\mbox{engine\\_on} \\wedge \\neg \\mbox{tray\\_full} \n  $$\n  is $t_j(S^{(i)})$. The whole set of next states $T(S^{(i)})$ is \n  $\\bigvee_j t_j( S^{(i)} )$\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Symbolic Model-Checking - Bad states in $S^{(i)}$}\n\n  Suppose that $\\phi$ is the symbolic representation of $S^{(i)}$,\n  and that $\\beta$ is the symbolic representation of the {\\bf bad states}\n  \\vfill\n  checking if some bad state is in $S^{(i)}$ can be simply done with\\pause\n  $$\n    \\phi \\wedge \\beta \\mbox{ is satisfiable ?}\n  $$\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Symbolic Model-Checking - Fix point test}\n\n  Suppose that $\\phi_i$ is the symbolic representation of $S^{(i)}$\n  and that $\\phi_{i+1}$ is the symbolic representation of $S^{(i+1)}$\n  how do I that $S^{(i)} \\equiv S^{(i+1)}$ ?\n  \\vfill\\pause\n  First of all, notice that $S^{(i)} \\equiv S^{(i+1)}$ if and only if\n  $$\n    S^{(i)} \\subseteq S^{(i+1)} \\mbox{ and } S^{(i+1)} \\subseteq S^{(i)}\n  $$\n  \\vfill\\pause\n  $S^{(i)} \\subseteq S^{(i+1)}$ always holds (explored states grow monotonically)\n  \\vfill\\pause\n  $S^{(i+1)} \\subseteq S^{(i)}$ can be perfomed with the following check\n  $$\n  \\begin{array}{l}\n    \\phi_{i+1} \\rightarrow \\phi_i \\mbox{ is a tautology ? or equivalently} \\\\\n    \\phi_{i+1} \\wedge \\neg \\phi_i \\mbox{ is unsafisfiable ? } \n  \\end{array}\n  $$\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Symbolic Model-Checking - Summary}\n\n  Model-Checking can be implemented by representing\n  states and transitions symbolically with SAT/SMT-formul\\ae\n  \\vfill\n  Next states $T(S^{(i)})$ can be computed using quantifier elimination\n  \\vfill\n  Presence of bad states can be computed with a satisfiability call of\n  the form $\\phi \\wedge \\beta$\n  \\vfill\n  Fix-point check can be computed with a satisfiability call of the\n  form $\\phi_{i+1} \\wedge \\neg \\phi_i$\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Symbolic Model-Checking - Termination}\n\n  \\begin{boxedminipage}{\\textwidth}\n  \\begin{center}\n  Forward-Reachability\n  \\begin{tabular}{rcl}\n     \\\\\n       {\\bf Safety Check} & ~~ & If $\\phi_i \\wedge \\beta$ is satisfiable, return {\\bf unsafe} \\\\\n        {\\bf Next States} & ~~ & Compute $\\phi_{i+1}$ with quantifier elimination \\\\\n    {\\bf Fix-Point Check} & ~~ & If $\\phi_{i+1} \\wedge \\neg \\phi_i$ is unsatisfiable, return {\\bf safe} \n  \\end{tabular}\n  \\end{center}\n  \\end{boxedminipage}\n  \\vfill\n  Model-Checking always terminates if the satisfiability\n  tests above terminates\n  \\begin{itemize}\n\n    \\item If the system under inspection \n\t  is a {\\bf finite state machine}, everything can be encoded\n\t  into Booleans, and so they always terminate (SAT-solver is enough)\n\n    \\item If the system has {\\bf infinite states} (e.g., $0 \\leq x \\wedge y \\geq 2$), \n\t  it terminates if everyting can be encoded into a decidable SMT theory\n\t  (e.g., \\Lia) (SMT-Solver necessary)\n\n    \\item If quantifiers are needed to express states, then Forward-Reachability\n          might not terminate (SMT-Solver plus clever way of handling quantifiers)\n\n  \\end{itemize}\n\n\\end{frame}\n", "meta": {"hexsha": "94ea25c4422aa0d9a47b7111a02ffd501a605d71", "size": 7076, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture8/implementing.tex", "max_stars_repo_name": "formalmethods/smtlectures", "max_stars_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-11-07T19:34:12.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-24T08:05:50.000Z", "max_issues_repo_path": "lecture8/implementing.tex", "max_issues_repo_name": "formalmethods/smtlectures", "max_issues_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture8/implementing.tex", "max_forks_repo_name": "formalmethods/smtlectures", "max_forks_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-06T00:40:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-06T00:40:41.000Z", "avg_line_length": 32.0180995475, "max_line_length": 144, "alphanum_fraction": 0.6362351611, "num_tokens": 2424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7088662957626043}}
{"text": "\\chapter{Method}\n\\label{chap:method}\n\nIn this chapter, I first describe techniques that lie at the core of the proposed solution.\nThey then followed by a detailed explanation of the proposed solution.\nFinally, I give the implementation details and settings.\n\n\\section{Neural Radiance Fields}\n\nThe Neural Radiance Fields approach (\\cite{mildenhall2020nerf}) lies directly in the heart of the proposed solutions.\nThe continuous 5D function \n\n\\begin{equation}\n    \\label{eq:nerf_function}\n    F : (p,v) \\xrightarrow{} (c, \\sigma)\n\\end{equation}\n\nis required to be achieved in order to solve the novel view synthesis problem.\nGiven the spatial location $p \\in \\mathbb{R}^3$ and the 2D viewing direction $(\\theta, \\phi)$ (or its equivalent 3D Cartesian representation $v \\in \\mathbb{R}^3$),\none has to obtain the RGB color value $c$ and the volume density $\\sigma$ at this exact point $p$ under the viewing direction $v$.\nTo obtain the image of the scene, one can take a pin-hole camera at position $p_0$ and cast rays to the scene: $p(z) = p_0 + z\\cdot v$.\nThe final visible color value $C(p,v)$ can then be evaluated using volume rendering approach \\cite{niemeyer2020differentiable, Novak18volumeSTAR} along the ray $p$:\n\\begin{equation}\n    C(p,v) = \\int_{0}^{\\infty} \\omega(p(z)) \\cdot c(p(z),v) dz,\n    \\label{eq:rendering_equation}\n\\end{equation}\n$\\omega(p(z))$ is a probability weight function\n\\begin{equation}\n    \\omega(p(z)) = \\tau_c(p(z)) \\sigma(p(z)),\n\\end{equation}\nwhere $\\tau_c(p(z)) = e^{\\int_0^z \\sigma(p(s)) ds}$ denotes the accumulated transmittance along the ray up to the point $p(z)$, $\\sigma(p(z))$ is the volume density at point $p(z)$ and the probability property is held: $\\int_0^\\infty \\omega(p(z))dz = 1$\n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{figures/mlp_nerf.png}\n    \\caption{MLP used in NeRF \\cite{mildenhall2020nerf} Dark blue boxes represent hidden layers. Black arrows indicate FC-layers with sigmoid activation, orange arrows - FC-layers without activation. Green boxes are inputs: $p$ is a 3D sample point, $v$ is a 3D vector of viewing direction. Red boxes are the outputs: $\\sigma$ is 1D volume density, $c$ is a 3D color value. $\\zeta(.)$ stands for positional encoding function that maps inputs into higher dimensional space $\\mathbb{R}^{2L}$ (more in \\Cref{subsec:pos_enc}}\n    \\label{fig:mlp_nerf}\n\\end{figure}\n\n\\cite{mildenhall2020nerf} propose to use a Multi-Layer Perceptron (MLP) as a representation\nof an implicit function $F = F_\\Theta$ with parameters $\\Theta$.\nThe scheme structure of the original NeRF's MLP is outlined in \\Cref{fig:mlp_nerf}.\nThe position $p(z)$ is first encoded using position encoding function $\\zeta(\\cdot)$ (positional encoding is described in section \\ref{subsec:pos_enc}) and then is processed with 8 fully-connected neural layers with ReLU activations.\nThe resulting feature vector is then concatenated with positionally encoded vector direction $v$\nbefore the volume density $\\sigma(p(z))$ and the color value $c(p(z), v)$ is output.\nThe important concept here is that $\\sigma$ only depends on point $p(z)$\nwhilst the color value $c$ is view dependant as well.\nThis setting is required to encourage the MLP to be multi-view consistent.\n\nIn order to perform the volume rendering, the continuous integral from equation \\Cref{eq:rendering_equation} has to be solved.\nOne can estimate this integral using a discrete set of densely sampled points as proposed by \\cite{mildenhall2020nerf}.\nSeparating each ray into $N$ bins and drawing random samples from each bin\nmakes the representation able to learn continuous function\nwhile only using a finite number of samples.\nThe estimate for the integral $C(p, v)$ will have a form (\\cite{mildenhall2020nerf, max1995optical}):\n\\begin{equation}\n    \\label{eq:integral_estimation}\n    C(p, v) \\approx \\sum_{i=1}^{N} \\tau_c(p_i) (1 - \\exp (-\\sigma(p_i) \\delta_i)) c(p_i, v),\n\\end{equation}\nwhere $p_i = p(z_i)$ for brevity, $\\tau_c(p_i) = \\exp (-\\sum_{j=0}^i \\sigma(p_j) \\delta_j )$ is the accumulated transmittance and $\\delta_i = z_{i+1} - z_i$ is the distance between adjacent sample points.\n\n\\subsection{Positional encoding}\n\\label{subsec:pos_enc}\n\nNeural networks are known as a highly representative class of functions (\\cite{hornik1989multilayer}).\nHowever, recent works (\\cite{rahaman2019spectral, tancik2020fourfeat}) demonstrate the tendency of\nbiasing towards low-frequency functions during the training of deep neural networks.\nThe results can be smoothed and blurry as frequency-dependent learning speed\nis much slower for high-frequency parts of the scene.\n\\cite{rahaman2019spectral} show that one can highly improve the quality of the MLP outputs\nby using an embedding, which maps inputs to a higher dimensional space before passing them to the MLP.\n\nThe positional encoding function $\\zeta(p) : \\mathbb{R} \\xrightarrow{} \\mathbb{R}^{2L}$ as proposed by \\cite{mildenhall2020nerf, vaswani2017attention} is represented by Fourier series in the following form:\n\\begin{equation}\n    \\label{eq:positional_encoding}\n    \\zeta(x) = (\\sin(2^0\\pi x), \\cos(2^0\\pi x), ..., \\sin(2^{L-1}\\pi x), \\cos(2^{L-1}\\pi x))\n\\end{equation}\nThe 3D Cartesian coordinates of $p$ and $v$ are then separately transformed using $\\zeta(\\cdot)$ and concatenated.\n\n\n\\subsection{Hierarchical sampling}\n\\label{subsec:hierarchy_sampling}\n\nThe proposed approach is ineffective in a way that it tends to generate a lot of unimportant samples\nthat lie in free space and do not contribute much.\nTo solve that authors propose the hierarchical volume sampling algorithm (similar to \\cite{levoy1990efficient})\nwhen another \"coarse\" neural network is used in order to roughly estimate volume densities along the ray.\nThis insight is then used to perform a more informed sampling of the main (\"fine\") network.\nThe \"coarse\" network is being optimized along with the main network, which can be considered as an overhead.\nHowever, taking into account the increase of training convergence the overall training gets more efficient.\n\n\n\\subsection{Optimization}\n\nThe fully differentiable formulation of the problem makes it possible\nto optimize network parameters $\\Theta$ without any 3D supervision.\nThis is done using the back-propagation approach from the differences\nbetween rendered predictions and ground truth images.\nThis task, therefore, is reduced to the minimization problem of the loss function.\nThe original method by \\cite{mildenhall2020nerf} for loss function uses the following formulation:\n\\begin{equation}\n    \\label{eq:loss_func}\n    \\mathcal{L} = \\sum_{(p_0, v) \\in \\mathcal{B}} \\norm{ C_c(p, v) - C^*(p, v) }^2_2 + \\norm{ C_f(p, v) - C^*(p, v) }^2_2,\n\\end{equation}\nwhere $\\mathcal{B}$ is the set of sampled rays in each batch,\n$C^*$ is the target color value of the view ray $v$ and\n$C_c(p, v)$, $C_f(p, v)$ - are the predicted colors for the view ray $v$ of the coarse and fine networks respectively.\n\nAnother regularization term can be added to this loss function as proposed by \\cite{Lombardi_2019}.\nThe beta-distribution regularizer $\\Omega(\\cdot)$\nforces the ray transmittance from the fine network $\\tau_c$ to be close to $0$ or $1$:\n\\begin{equation}\n    \\label{eq:beta_regularizer}\n    \\Omega(\\tau_c(p_i)) = \\log(\\tau_c(p_i)) + \\log(1 - \\tau_c(p_i))\n\\end{equation}\nThis helps the network to better handle background colors and get cleaner rendering after all.\nThis regularization term is used in NSVF work (\\cite{liu2021neural})\nthat is described in \\Cref{subsec:NSVF}\nand NRF work (\\cite{bi2020neural}) that is described in \\Cref{subsec:NRF}\n\n\n\n\\subsection{Sparse Voxels Octree}\n\\label{subsec:NSVF}\nThe described approach is already able to represent scenes with high accuracy.\nHowever, the very inefficient way of sampling points along rays\nmakes the training very slow and tough,\nsince the model has to be repeatedly evaluated on unimportant samples\nof free space or occluded regions that do not make a worthwhile contribution to the finally rendered color value.\nThe \\textit{hierarchical sampling} strategy alleviates the problem\nbut does not solve it completely.\nThe method in its formulation, therefore, is still barely practical.\n\n\n\\cite{liu2021neural} propose another framework\nthat is able to increase the efficiency of this method\nand make the training time up to an order of magnitude faster.\nThe main contribution is the usage of sparse voxel octrees (\\cite{laine2011EfficientSV}) to divide space into voxels\nthat are efficiently used for training MLPs with shared parameters.\n\nThis approach requires a slight elaboration on the problem formulation.\nLet the whole scene be fully contained in a set of $K$ sparse voxels: $\\mathbb{V} = \\{V_k\\}_{k=1}^K$.\nThe scene can then be represented as a set of voxel-bounded implicit functions\n\\begin{equation}\n    F(p, v) = F_\\Theta^i(g_i(p), \\zeta(v)), \\forall p \\in V_i,\n\\end{equation}\nwhere each function $F_\\Theta^i$ is modeled with an MLP with shared parameters $\\Theta$:\n\\begin{equation}\n    F_\\Theta^i: (g_i(p), \\zeta(v)) \\xrightarrow{} (c, \\sigma), \\forall p \\in V_i\n\\end{equation}\nHere $g_i(p)$ is the representation of $p$ that is defined as:\n\\begin{equation}\n    g_i(p) = \\zeta ( \\chi ( \\{\\Tilde{g_i}(p_j^*)\\}_{j=1}^8 ) ),\n\\end{equation}\nwhere $\\{p_j^*\\}_{j=1}^8, p_j^* \\in \\mathbb{R}^3$ is the set of eight vertices of voxel $V_i$,\n$\\Tilde{g_i} \\in \\mathbb{R}^d$ represent the feature vectors that are stored for each vertex of voxel $V_i$,\n$\\chi(\\cdot)$ stands for trilinear interpolation,\nand $\\zeta(\\cdot)$ is a post-processing function,\nwhich corresponds to positional encoding function explained in \\ref{subsec:pos_enc}.\n\n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{figures/vanilla_nsvf.png}\n    \\caption{Network structure of the NSVF approach\n(the figure is adapted from \\cite{liu2021neural}).\nSame notation as for \\Cref{fig:mlp_nerf} is used.\nDotted lines denote semantic parts of the presented structure:\npink, green and blue dotted lines stand for encoder, density predictor and texture predictor respectively.\n\\textit{Trilinear interpolation} block denotes interpolation of the sample point $p$ between voxel embeddings.}\n    \\label{fig:nsvf_structure}\n\\end{figure}\n\nThe proposed network structure is outlined in \\Cref{fig:nsvf_structure}.\nThe encoder part that is denoted with a pink dotted line\nconsists of only one layer comparing to the original NRF network\nwhere the encoder part consists of 5 deep layers.\nThe density predictor (green dotted line) remains the same.\nThe texture predictor (blue dotted line) is deeper comparing to the NeRF model.\nThe overall model structure is slightly shallower comparing to the original NeRF network,\nwhich is still sufficient due to the distributed way of storing voxel embeddings in the voxel vertices.\nWithout voxel embeddings, the model contains approximately 0.5M learnable parameters,\nwhich is lower than in the original NeRF model.\n\nThe volumetric rendering itself does not undergo any significant changes\nexcept for some additional steps that have to be performed.\nThe sampling of the ray is only performed at the intervals of intersection with voxels $V_i$.\nThis allows rejecting a decent amount of unimportant samples.\nA very efficient Axis Aligned Bounding Box (AABB) ray intersection algorithm (\\cite{haines1989essential}) is applied here\nto extract the above-mentioned intervals.\nAnother step is \\textit{early termination}, which reduces the number of samples that have to be processed.\nSince solid surfaces do not imply color values being dispersed along the ray,\nthe sample points that are behind the surface would be needless.\nThe technique here is to straightforwardly stop evaluating points,\nthat have an accumulated transmittance lower than some threshold.\n\n\\subsection{Voxels pruning and refinement}\n\\label{subsec:pruning}\n\nThe training on the scene begins with the octree,\nwhich consists of $N=N^3_0$ voxels that fit in the bounding box of the whole scene\nand cover all parts of the scene.\nOne can get rid of non-essential voxels by performing a \\textit{self-pruning} procedure.\nThis technique leverages the property of neural radiance fields\nto extract some coarse scene geometry during early training iterations.\nThe decision if voxel is going to be pruned is made by uniformly sampling $G$ points inside the voxel\nand comparing the minimum transmittance value with some threshold value $\\gamma$ or more formally when:\n\\begin{equation}\n    \\underset{j=1 \\dots G}{min} {\\exp (- \\sigma (g_i(p_j)))} > \\gamma, p_j \\in V_i, V_i \\in \\mathbb{V},\n\\end{equation}\nwhere $\\sigma (g_i(p_j))$ is the model prediction for $\\sigma$ when processing $g_i(p_j)$.\nThe pruning procedure has to be performed regularly as the accuracy of the model increases as it gets more and more trained,\nwhich means that more voxels can be pruned and therefore rejected from processing.\n\nAs the model learns a more detailed representation of the scene it becomes necessary to refine the voxel structure.\nDuring the refinement procedure, each voxel is being subdivided into $2^3$ subvoxels by halving the voxel size.\nRay sampling steps are also being halved at this point in order to correspond new voxel size value.\nThe feature representation vectors $\\Tilde{g_i}$ of the new vertices are initialized similarly to calculating $G_i(p)$,\nnamely using trilinear interpolation function $\\chi(\\cdot)$.\nThis scheme allows to achieve more detailed scene representation\nand also increases the model capacity.\n\n\n\n\\subsection{Neural Reflectance Fields}\n\\label{subsec:NRF}\n\nAlthough the neural radiance fields approach is able to produce realistic renderings under novel view conditions,\none of the main limitations of this method is the inability to handle any kind of visual effects related to dynamic light conditions.\nThe core assumption of these approaches is static illumination,\nwhich is implicitly presented in the color values of the rendered images.\nThis in turn does not allow to change illumination on the rendering phase.\n\n\\cite{bi2020neural} propose the framework for eliminating this exact limitation.\nAuthors introduce the neural reflectance field (NRF), which is the neural scene representation\nthat in addition to scene geometry also encodes normal and reflectance properties of the scene.\nThis approach allows the evaluation of an explicit reflectance model at the selected point after all.\nAlthough \\cite{bi2020neural} focus on the microfacet bidirectional reflectance distribution function (BRDF) (\\cite{walter2007microfacet}),\nany other reflectance model can be used within this method as well\n(i.e. authors also show some results of furry objects using hair reflectance model \\cite{kajiya1989fur}).\n\nThis method uses the same rendering framework as proposed by \\cite{mildenhall2020nerf}.\nAssuming that the volume containing the scene to be only scattering volume (i.e. there are no emission or absorption processes),\nthe corresponding rendering equation \\Cref{eq:rendering_equation} (\\cite{Novak18volumeSTAR}) looks similarly\nexcept for operating with radiance values $L$ instead of color values $c$:\n\\begin{equation}\n    L(p, v) = \\int_0^\\infty \\omega(p(z)) \\cdot L_s(p(z), v) dz = \\int_0^\\infty \\tau_c(p(z)) \\sigma(p(z)) \\cdot L_s(p(z), v)dz,\n\\end{equation}\nwhere $L_s(p(z), v)$ denotes the scattered light at point $p(z)$ along direction $v$.\n\nIn general case $L_s$ is calculated by integrating incident radiance along the whole unit sphere $\\mathbb{S}$:\n\\begin{equation}\n    \\label{eq:radiance_Li}\n    L_s(p, v) = \\int_\\mathbb{S} f_p(p, v, l) L_i(p, l)dl,\n\\end{equation}\nwhere $l$ is the 3D Cartesian representation of directions of the incident radiance $L_i(p, l)$.\n$f_p(p, v, l)$ is the phase function, which controls\nhow the light that comes from $l$ scatters at point $p$ if viewing from $v$.\n\n\\cite{bi2020neural} only assume single light source setting\nand the reflectance function as the phase function,\nwhich allows simplifying \\Cref{eq:radiance_Li}:\n\\begin{equation}\n    L_s(p, v) = f_r(p, v, l, n(p), R(p)) L_i(p, l),\n\\end{equation}\nwhere $f_r$ denotes a differentiable reflectance function\nwith parameters $R$.\nNormal vector $n$ is also required for evaluation of reflectance model $f_r$.\n$L_i(p, l)$ is the radiance that arrives from direction $l$ and can be calculated using light intensity $L_l(p)$\nand the transmittance value $\\tau_l(p, l)$,\nwhich indicates the loss of light from the light source to the sample point $p$ along light ray $l$, as follows:\n$L_i(p, l) = \\tau_l(p, l) L_l(p, l)$.\nThe light attenuation coefficient $f_{att} = \\frac{1}{k_c + k_l d + k_q d^2}$ \\cite{madams2011attenuation, madams2011improved} is considered inside the $L_l$ term:\n$L_l(p, l) = f_{att} \\cdot I$,\nwhere $k_c$, $k_l$ and $k_q$ are attenuation factors,\n$I$ is the point light intensity.\n% where $d$ is distance from sample point $p$ to the light source\n% and $r$ is the light's radius (assuming light source to be an emissive sphere with radius $r$) and \nIn my experiments the attenuation coefficients $k_c = k_l = 0$ and $k_q = 1$ were used,\nso the attenuation coefficient is inverse proportional to squared distance between light sample point and light source:\n$f_{att} = \\frac{1}{d^2}$\n\nCombining these equations and applying the same technique for numerical integral estimation\nas used by \\cite{mildenhall2020nerf} and \\cite{liu2021neural} gives the following formulation of \\Cref{eq:integral_estimation} for NRF:\n\\begin{equation}\n    \\label{eq:integral_estimation_nrf}\n    L(p, v, l) \\approx \\sum_{i=1}^N \\tau_l(p_i, l) L_l(p_i, l) f_r(p_i, v, l, n(p_i), R(p_i)) \\tau_c(p_i) (1 - \\exp (-\\sigma(p_i)\\delta_i))\n\\end{equation}\nHere $\\tau_l$ plays the same role for light ray $l$\nas $\\tau_c$ operates for view ray $v$.\nIt is evaluated similarly along the light ray $l$:\n$\\tau_l(p'_i, l) = \\exp (-\\sum_{j=1}^M \\sigma(p'_j) \\delta'_j)$,\nwhere $p'(z') = p'_0 + z' \\cdot l$ are sample points that are additionally sampled along the light ray $l$ and $\\delta'_j = z'_{j=1} - z'_j$.\n\n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{figures/vanilla_nrf.png}\n    \\caption{MLP structure of the NRF \\cite{bi2020neural} approach.\nThe overall network structure echoes the original NeRF model.\n14 deep layers are used (instead of 10 in NeRF).\nThe appearance model block represents BRDF $f_r$\nthat is evaluated for each sample point $p$.\nTo this end network outputs normal $n \\in \\mathbb{R}^3$\nand BRDF parameters $R \\in \\mathbb{R}^m$ ($m=4$ for microfacet BRDF).\n$L_l$ denotes light intensity with consideration to distance attenuation.\n}\n    \\label{fig:nrf_structure}\n\\end{figure}\n\nThe architecture of the MLP is outlined in \\Cref{fig:nrf_structure}.\nThe deeper structure is used as the model capacity has to be increased\ndue to the higher complexity of the task.\nFor each view sample point $p$ the model outputs both normal vector $n$ and parameters $R$,\nwhich are required by the selected BRDF model.\nFor the microfacet BRDF (\\cite{walter2007microfacet}) $R$ consists of a 3-dimensional albedo value\nand 1-dimensional roughness value.\n\n\n\nThis formulation covers the general case when the light source can be located at an arbitrary position ('arbitrary setting').\nSince the $l$ and $v$ vectors are different,\nthe additional sampling of light ray for each view sample point is required.\nIt makes this problem impractical. %infeasible.\nHowever, \\cite{bi2020neural} show that one specific light setting exists,\nwhich can be used to handle this problem.\nWhen the light ray $l$ coincide with the view ray $v$,\nthen sampling points $p(z)$ and $p'(z)$ would be the same,\nwhich in turn means that $\\tau_c(p_i) = \\tau_l(p_i)$ ('co-located setting').\nIn this case, there is no need to additionally sample light rays,\nwhich leave the processing time requirements on the same level as the original work by \\cite{mildenhall2020nerf}.\n% \\Cref{fig:colocated_light_source} \\im{add figure} shows this process in more details.\nAnother advantage of this setting is that it has an accessible real-world analogy.\nIn particular, all modern cellphones are equipped with cameras\nand flashlights that are placed close to each other.\nOn the scale of the scene, this displacement can be neglected and the setting can be considered to be co-located.\n\nThe co-located setting results in a very sparse sampling of the scene in terms of light-view directions.\nDuring training, there are no other samples\nwhere the angle between light and view rays is greater than zero.\nThis fact negatively affects the overall training performance,\nalthough \\cite{bi2020neural} claim\n%proves\nthat even with these restrictions\nthe network is still able to generalize and reconstruct the scene appearance in high quality.\nThe authors also show some renders where the 'arbitrary setting' had been used during the prediction phase.\n\n\n\n\n\n\\section{Explicit Neural Reflectance Field}\n\\label{sec:explicit_scheme}\n\nThe described above methods have already achieved some appealing results.\nHowever, all of them have their own limitations that in either event reduce the performance either qualitatively (no light interaction) or quantitatively (too slow).\nThe explained below solution is constructed to take advantage of both NRF and NSVF approaches.\nThis method is later referred to as the 'brute-force scheme' as it performs the light rays sampling without any approximation techniques.\n\nSince the NRF approach \\cite{bi2020neural} is based on NeRF, it inherits its poor performance behavior\nand forces it to be only applicable for the 'co-located setting'.\nAlthough the authors are even able to render the scene within the 'arbitrary setting'\nwhen only being trained on the co-located dataset,\nthe sparsity of the training dataset still highly affects the network's generalization opportunities.\n\n\\cite{liu2021neural} in turn propose the technique for increasing the effectiveness of the training\nfor the color-based original NeRF approach.\nThe usage of gradually refined octrees gives more control over the sampling process\nand makes the whole training phase faster.\n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{figures/explicit_scheme.png}\n    \\caption{Model architecture for the 'explicit scheme'\n    (\\Cref{sec:explicit_scheme}).\nThe overall structure follows one from NSVF work.\nThe outputs of the network are similar to the NRF model.\nBRDF evaluation ('appearance model' block) is required for achieving $f_r$ value.\n    }\n    \\label{fig:mlnrf_bfex}\n\\end{figure}\n\nSince both works NSVF and NRF use the original NeRF framework,\nin particular similar numerical integral estimation,\nthe process of reformulating NSVF problem to work with light radiances instead of color values is fairly straightforward.\nFor the integral estimation \\Cref{eq:integral_estimation} is directly replaced with \\Cref{eq:integral_estimation_nrf}.\nThe network architecture follows the guidelines from the NSVF work,\nnamely the encoder is shallow while the texture predictor is deeper\ncomparing to the original NeRF method.\nAppearance model block (right blue rhombus) includes BRDF evaluation,\nwhich results in $f_r$ value required for final radiance calculation (using integral estimation formula \\cref{eq:integral_estimation_nrf})\n\nIn order to train the model on arbitrary light dataset\nan additional step of light rays sampling and volume density prediction is needed.\nThis requires some nested model evaluations in order to retrieve $\\sigma$ values at light sample points.\nThis is quite a memory intense part, however, the lower model size comparing to the NRF approach makes it more accessible.\nAnother keynote here is that there is no need in getting texture field predictions,\nas for light rays the only valuable information is the volume density.\nThis allows to only evaluate the corresponding part of the model.\n\nAnother key point here is the format of the dataset.\nThe NeRF and NSVF methods only work with color values,\nwhich allows them to use the LDR images in the datasets\n(i.e. PNG, JPG image formats and others).\nHowever, the NRF approach implies light intensity values that are integrated into the final radiance calculations.\nThe LDR images are usually lacking the information of radiances\nand only operate with color values.\nAll these facts make the LDR images bad candidates for the training dataset.\nOne should instead consider using HDR images (i.e. HDR, EXR formats).\n\nThe point light intensity value $I$ that takes part in the calculation of $L_l(p, l) = f_{att} \\cdot I$\nrepresents the radiation power of the light source.\nThis value is known when processing artificially generated scenes\nand thus can directly be used as the value of $I$.\nThe real-world scenes (e.g. captured with the cellphone and flashlight)\non the contrary do not have the exact light intensity value.\nOne could estimate the power of the flashlight, but this would give only a rough estimation.\nTo make the method robust to this kind of estimations,\nthe light intensity value $I$ is passed to the optimizer (along with other model parameters $\\Theta$).\nThis technique requires some robust estimation of $I$ as an initialization value as well as an increased learning rate.\n\n\n\n\\section{In-Voxel Light Approximation}\n\\label{sec:invoxel}\n\nUsing sparse octree voxels for increasing the efficiency of the method\nmakes the whole problem feasible within some commonly accessible hardware.\nHowever, the training procedure still remained highly computationally expensive and memory demanding\nand therefore very slow in training or still even intractable for high-resolution scenes.\n\nThe main load of this approach still remains in the additional sampling of light rays\nand the consecutive model evaluation for calculating $\\tau_l(p', l)$.\nThis fact leads to the task of minimizing the overhead that is caused by calculating light ray transmittances.\n\nPredictions of volume densities at view ray sample points have primary importance\nas they contribute to the final radiance value the most.\nThis assumption brings to the fact that light rays are not required\nto be sampled as densely as view rays to remain the same level of accuracy.\nThus the lower number of points can be sampled on the light rays,\nwhich would result in lower memory and time consumption.\nHowever, this approach only alleviates the problem while not solving its root cause.\n\nThe octree structure that is used to encode feature vectors $\\Tilde{g_i}$ in the corners of voxels\nrepresents itself a coarse geometry of the scene.\nStarting with only a few voxels that cover the whole bounding box around the scene,\nthe voxels undergo the \\textit{self-pruning} and \\textit{refinement} procedure (explained in \\Cref{subsec:pruning}),\nwhich increases the detailing capabilities of the octree\nby increasing the number of voxels, lowering its sizes and rejecting empty voxels.\nAfter only a few steps of the aforementioned operations, the overall voxel structure\nrepeats scene geometry with a considerable amount of accuracy.\nThese voxels that intersect with the light rays can be used as an estimation of volume densities.\n\n% \\begin{figure}\n%     \\begin{tabular}{ccc}\n%           \\includegraphics[width=0.1\\textwidth]{figures/sampling_nerf.png}\n%           & \\includegraphics[width=0.1\\textwidth]{figures/sampling_nsvf.png}\n%           & \\includegraphics[width=0.1\\textwidth]{figures/sampling_nrf.png}\n%           \\\\(a) NeRF \\cite{mildenhall2020nerf} & (b) NSVF \\cite{liu2021neural} & (c) NRF \\cite{bi2020neural}\n%           \\\\[6pt]\\multicolumn{3}{1}{\n%               \\begin{tabular}{cc}\n%                 \\includegraphics[width=0.1\\textwidth]{figures/sampling_bfex.png}\n%                 & \\includegraphics[width=0.1\\textwidth]{figures/sampling_iva.png}\n%                 \\\\[6pt](d) 'Brute-force' & (e) In-voxel approximation\n%               \\end{tabular}\n%           }\n%     \\end{tabular}\n%     \\caption{caption}\n% \\end{figure}\n\\begin{figure}[!htbp]\n    \\setlength\\tabcolsep{4pt}\n    \\begin{tabular}{ccc}\n          \\includegraphics[width=0.284\\textwidth]{figures/sampling_nerf.png}\n          & \\includegraphics[width=0.261\\textwidth]{figures/sampling_nsvf.png}\n          & \\includegraphics[width=0.35\\textwidth]{figures/sampling_nrf.png}\n          \\\\(a) NeRF \\cite{mildenhall2020nerf} & (b) NSVF \\cite{liu2021neural} & (c) NRF \\cite{bi2020neural} (general)\n          \\\\[6pt]\\includegraphics[width=0.25\\textwidth]{figures/sampling_nrf_colocated.png}\n          & \\includegraphics[width=0.315\\textwidth]{figures/sampling_bfex.png}\n          & \\includegraphics[width=0.32\\textwidth]{figures/sampling_iva.png}\n          \\\\(d) NRF (colocated) & (e) 'Brute force'& (f) In-voxel approximation\n    \\end{tabular}\n    \\caption{\nSampling techniques used in different approaches.\nThe 2D sketch schemes are used instead of 3D visualizations for simplicity.\nBlue lines represent view rays $p(z)$ with direction vector $v$,\npurple lines stand for light rays $p'(z)$ with light direction vector $l$\n(only two of those are shown for brevity).\nRed dots represent sampled view points $p_i$, yellow dots stand for light sample points $p'_i$.\nScheme (a) shows the original NeRF sampling technique without \\textit{hierarchy sampling} (\\Cref{subsec:hierarchy_sampling}).\nScheme (b) correspond to the NSVF sampling technique\nthat only occurs inside intersected voxels (represented by green boxes).\nScheme (c) shows sampling of the general case of the NRF approach\nwhen light source is placed at arbitrary position.\nScheme (d) displays the 'colocated setting'\nwhen point light source is positioned at the same location as camera.\nIn this case light sample points (yellow dots) coincide with the view sample points (red dots).\nScheme (e) correspond to the proposed in this work 'brute-force' approach\nwhen light rays sampling is reduced by using the same voxel structure as in NSVF (fig. (b)).\nScheme (f) shows sampling proposed in this work in-voxel approximation scheme.\nView rays are sampled equally as in NSVF approach\nwhile light ray transmittances are estimated using travelled distances $d_{V_i}$\nof the light ray inside voxels.\n}\n\\label{fig:samplings}\n\\end{figure}\n\nThere are plenty of techniques that can be applied here in order to calculate light transmittances more efficiently.\nThe main proposed technique implies the assumption\nthat the volume density is homogeneously distributed inside the voxel.\nThis assumption is certainly wrong for the general case\nbut should give a fair estimation for the light ray transmittances.\nIn this case, the traveled distance $d_{V_k}$ of the ray inside voxel $V_k$\ncan be used to weigh some value $\\hat{\\sigma_{V_k}}$ (\\Cref{fig:samplings} f):\n\\begin{equation}\n    \\label{eq:light_ray_transmittance}\n    \\tau_l(p_i, l) = \\exp \\sum_{V_k \\in \\mathbb{V}^*} -\\hat{\\sigma}_{V_k} \\cdot d_{V_k},\n\\end{equation}\nwhere $\\tau_l(p_i, l)$ is the light transmittance value at the view sample point $p_i$\nand $\\mathbb{V}^* \\subset \\mathbb{V}$ is the set of voxels $V_k$\nthat have been intersected by the light ray $p'(z') = p'_0 + z' \\cdot l$.\n\nThe model can be periodically evaluated to predict the values of $\\hat{\\sigma}_{V_k}$ and consequently calculate $\\tau_l$.\nThe period of evaluation can be similar to periods for \\textit{self-pruning} and \\textit{refinement} procedures\nas some coarse value would already give an acceptable level of certainty.\n\nSome other options can be applied here such as:\n\\begin{enumerate}\n    \\item calculate $\\hat{\\sigma}_{V_k}$ using points sampled in centers of voxels $V_k \\in \\mathbb{V}^*$\n    \\item calculate mean $\\hat{\\sigma}_{V_k}$ value from points of intersection of light ray with voxels $V_k \\in \\mathbb{V}^*$ (requires handling of edge cases)\n    \\item assign $\\hat{\\sigma}_{V_k} = \\const, \\forall V_k \\in \\mathbb{V}^*$\n    \\item use $\\hat{\\sigma}_{V_k}$ that was calculated during pruning stage\n\\end{enumerate}\n\n\n\n\\section{Implicit Neural Reflectance Field}\n\\label{sec:implicit_scheme}\n\nThe aforementioned methods that are proposed within this work\nextend existing approaches in terms of efficiency for the problem of reproducing the scene under novel view and light conditions.\nThe novel light conditions are the essential requirement here\nas it expects the method to not only account for color values\nbut also care about the reflectance of the surface.\nAlthough the NRF approach is formulated in general form\nwhen any differentiable appearance model can be used for final radiance evaluation,\nthe result is still limited by the chosen BRDF.\n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{figures/implicit_scheme.png}\n    \\caption{Network architecture for the implicit scheme.\nThe structure of the network mostly remains the same as in original NSVF work.\nSome additional parameters such as light ray direction $l$\nand distance $d$ from view sample point $p$ to the point light\nare provided in advance into texture predictor.\n}\n    \\label{fig:implicit_scheme}\n\\end{figure}\n\nTo avoid\n%expand\nthese limitations one can shift the appearance evaluation burden to the deep neural network,\nwhich is able to get trained for very complex appearance representations.\nThis 'implicit scheme' would have a simpler neural network structure,\nwhich is shown in \\Cref{fig:implicit_scheme}.\nThe light interaction is performed here implicitly by providing the network\nwith the light direction $l$ as well as the distance from the sample point to the light source $d_i = \\norm{p^l_k - p_i}$\nas denoted in the figure.\nLight ray direction $l$ is also positionally encoded with the same $L$ as view ray direction $v$ is.\nAlthough the shadowing is not explicitly modeled,\nthe network is expected to learn this effect by itself.\n\nThe main downside of this scheme comes from its advantage.\nImplicit representation significantly decreases the amount of control over the learned field.\nIn other words, bigger amount of parameters that are responsible for different effects on the scene\nare hidden in the weights of the model and cannot be easily attained.\n\nAnother characteristic of this scheme is that it does not imply any kind of regularization.\nThis means that the network is not guaranteed to be able to extract the appearance of the scene.\nThis behavior can be clearly seen from the experiments of the \\textit{ImNRF} on the colocated light dataset \\Cref{subsec:experiments_coloc}.\n\n% Another property of this technique will be the increased complexity of the learning function,\n% which would expect the network structure with greater capacity.\n\n% \\im{\\textit{Disadvantage: almost no control over implicit representation}}\n\n\n\n% \\section{Implicit Neural Reflectance Field}\n\n% Existing BRDF models limits the type of scenes that can be captured\n% and successfully reconstructed afterwards.\n% To model object appearance one can employ neural network, which is able to get trained for a very complex appearance representations.\n% In this work I \\im{we?} call this technique as \"Implicit scheme\".\n\n% Texture predictor not only is dependant on view direction,\n% but also requires the light direction and distance to light source\n% (for modelling the light attenuation effect).\n% Figure \\# shows the network structure for this approach.\n\n% \\begin{enumerate}\n%     \\item Light rays are not sampled (-> varying light transmittance either not considered or assumed to get learned by network\\im{???})\n%     \\item |--> Tangential space for coordinates (and parametrization as half-vectors. not done)\n% \\end{enumerate}\n\n% Since the appearance effects happen mostly in a local coordinate frame, the usage of the global direction vectors implies on the model to learn global to local coordinate system transformation. Although this is generally achievable, the overall complexity of the task can be too overwhelming for the model and some kind of correlations might affect the model. In order to increase the training performance this transformation can be done deterministically and the view and light directions in local coordinate frame are to be passed to the input of the model.\n\n% The usage of the cartesian vectors is not very effective for reflectance representations. The half diff vectors (rusinkiewicz parametrization) can be used instead of positionally encoded l and v.\n% \\sm{or in combination with positional encoding}\n\n% \\section{In-Voxel Approximation}\n\n% Using the octree allows to approximate light rays sampling inside voxels in order to increase the performance of the method.\n\n% Instead of performing inverse CDF sampling as it is done for view rays, one can do the following:\n% \\begin{enumerate}\n%     \\item Bravely \\sm{colloquial} assume the media homogenious inside voxels and boldly approximate it as constant\n%     \\item Under the same brave assumption perform some sampling inside the voxel once at N iterations (e.g. right after pruning has been performed)\n%     \\item The in-voxel sampling can be lighter than inverse CDF (e.g. just sample the center of voxel, or voxel corners + trilinear interpolation)\n% \\end{enumerate}\n\n\n\n\n\n\n\n% NSVF proposed a good technique of using Sparse Voxel Trees in order to increase the rendering speed. However, the scene is still lacking the light interaction.\n\n% One can achieve this by also passing light directions along with distance to the light source into the network, in order to make it distinguish different surface properties for different view and light directions.\n\n\n\n\n\n\n\n\n% This is some test area for new mathematical helper macros to nicely visualize mathematical formulas.\n\n% \\section{Numbers}\n% \\begin{align}\n%     \\mathbb{C}\n%     \\qquad\n%     \\mathbb{R}\n%     \\qquad\n%     \\mathbb{Q}\n%     \\qquad\n%     \\mathbb{Z}\n%     \\qquad\n%     \\mathbb{N}\n% \\end{align}\n\n% \\section{Numbers with physical units}\n% \\begin{align}\n%     \\SI{1.23}{\\meter\\per\\second}\n% \\end{align}\n% \\begin{align}\n%     \\si{\\meter\\per\\second}\n% \\end{align}\n% \\begin{align}\n%     \\SI{1.23\\pm0.45}{\\meter\\per\\second}\n% \\end{align}\n% \\begin{align}\n%     \\SI{3e8}{\\meter\\per\\second}\n% \\end{align}\n% \\begin{align}\n%     \\SI{32}{\\giga\\byte} = \\SI{32e9}{\\byte}\n% \\end{align}\n% \\begin{align}\n%     \\SI{32}{\\gibi\\byte} = \\SI[exponent-base=2]{32e30}{\\byte}\n% \\end{align}\n\n% \\section{Norm, Dot, Abs, Interval}\n% \\begin{align}\n%     \\pi = \\const\n% \\end{align}\n% \\begin{align}\n%     1 \\in \\interval{0}{2}\n% \\end{align}\n% \\begin{align}\n%     1 \\in \\order{n}\n% \\end{align}\n% \\begin{align}\n%     \\evalat{ \\frac{\\partial f}{\\partial x} }{ x = 0 }\n% \\end{align}\n% \\begin{align}\n%     \\norm{p} \\qquad \\norm{\\frac{p}{2}}\n% \\end{align}\n% \\begin{align}\n%     \\abs{p} \\qquad \\abs{\\frac{p}{2}}\n% \\end{align}\n% \\begin{align}\n%     \\dotproduct{p}{q} \\qquad \\dotproduct{\\frac{p}{2}}{q}\n% \\end{align}\n% \\begin{align}\n%     \\crossproduct{p}{q} \\qquad \\crossproduct{\\frac{p}{2}}{q}\n% \\end{align}\n\n% \\section{Vector, Matrix}\n% \\begin{align}\n%     \\vec{p} \\qquad \\vecarrow{p}\n% \\end{align}\n% \\begin{align}\n%     \\vec{p}^{\\transposed}\n% \\end{align}\n% \\begin{align}\n%     \\gradient{\\vec{p}}\n% \\end{align}\n% \\begin{align}\n%     \\divergence{\\mat{A}}\n% \\end{align}\n% \\begin{align}\n%     \\laplacian{\\mat{A}}\n% \\end{align}\n% \\begin{align}\n%     \\mat{A}\n% \\end{align}\n% \\begin{align}\n%     \\set{K} , K\n%     \\qquad\n%     \\set{N} , N\n% \\end{align}\n% \\begin{align}\n%     \\neighborhood{\\vec{p}} = \\left\\{ \\vec{q} \\mid \\norm{\\vec{p} - \\vec{q}} < \\epsilon \\right\\}\n% \\end{align}\n\n% \\section{Set operations}\n% \\begin{align}\n%     A \\intersect B\n% \\end{align}\n% \\begin{align}\n%     A \\union B\n% \\end{align}\n% \\begin{align}\n%     A \\difference B\n% \\end{align}\n\n% \\section{Derivative, Integral, Sum, Probability}\n% \\begin{align}\n%     \\int_H x \\, dx\n% \\end{align}\n% \\begin{align}\n%     \\sum_H x\n% \\end{align}\n% \\begin{align}\n%     \\probability{x}\n% \\end{align}\n% \\begin{align}\n%     \\probabilitygiven{x}{y}\n% \\end{align}\n% \\begin{align}\n%     \\expectation{x}\n% \\end{align}\n% \\begin{align}\n%     \\deviation{x}\n% \\end{align}\n% \\begin{align}\n%     \\variance{x}\n% \\end{align}\n\n\n% \\section{Lemma, Theorem, Corollary}\n% \\begin{lemma}\n%     This is a lemma.\n% \\end{lemma}\n% \\begin{proof}\n%     Proof of lemma.\n% \\end{proof}\n\n% \\begin{theorem}\n%     This is a theorem.\n% \\end{theorem}\n% \\begin{proof}\n%     Proof of theorem.\n% \\end{proof}\n\n% \\begin{corollary}\n%     This is a corollary.\n% \\end{corollary}\n% \\begin{proof}\n%     Proof of corollary.\n% \\end{proof}\n\n\n", "meta": {"hexsha": "74e7c27c50131878f0de64c6439a4f940920f867", "size": 40223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writings/overleaf/tex/chapter/3_method.tex", "max_stars_repo_name": "wi1k1n/nrf-accelerations", "max_stars_repo_head_hexsha": "3075d63177e8ac04ee91784d5b0c56379335740f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "writings/overleaf/tex/chapter/3_method.tex", "max_issues_repo_name": "wi1k1n/nrf-accelerations", "max_issues_repo_head_hexsha": "3075d63177e8ac04ee91784d5b0c56379335740f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "writings/overleaf/tex/chapter/3_method.tex", "max_forks_repo_name": "wi1k1n/nrf-accelerations", "max_forks_repo_head_hexsha": "3075d63177e8ac04ee91784d5b0c56379335740f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.1743002545, "max_line_length": 561, "alphanum_fraction": 0.757079283, "num_tokens": 10331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554476, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.7088250501613181}}
{"text": "\n\\section{The \\partialsum algorithm}\n\\Label{sec:partialsum}\n\nThe \\partialsum algorithm in the \\cxx Standard Library \\cite[\\S 29.8.6]{cxx-17-draft} computes\nthe sum of a given initial value and the elements in a range.\n%\nOur version of the original signature\nreads:\n\n\\begin{lstlisting}[style=acsl-block]\n\n  size_type\n  partial_sum(const value_type* a, size_type n, value_type* b);\n\\end{lstlisting} \n\nAfter executing the function \\partialsum the array \\inl{b[0..n-1]} holds the following values\n\\begin{align}\n\\Label{eq:partialsum}\n   \\mathtt{b}[i] &= \\sum_{k = 0}^{\\mathtt{i}} \\mathtt{a}[k]\n\\end{align}\nfor $0 \\leq i < n$.\n%\nEquations~\\eqref{eq:partialsum} and~\\eqref{eq:accumulate-default}\nsuggest that we define in the following listing the \\acsl predicate \\PartialSum\nby using the logic function \\logicref{AccumulateDefault}.\n\n\\input{Listings/PartialSum.acsl.tex}\n\n\\clearpage\n\n\\subsection{Formal specification of \\partialsum}\n\nThe specification of \\specref{partialsum} demands that the arrays\n\\inl{a[0..n-1]} and \\inl{b[0..n-1]} \nare separated, that is, they do not overlap.\nNote that is a stricter requirement than in the case of the original\n\\cxx version of \\partialsum, which allows that~\\inl{a} equals~\\inl{b},\nthus allowing the computation of partial sums \\emph{in place}.\n\n\\input{Listings/partial_sum.h.tex}\n\n\\clearpage\n\n\\subsection{Implementation of \\partialsum}\n\nThe following listing shows an implementation of \\partialsum with corresponding loop annotations.\n\n\\input{Listings/partial_sum.c.tex}\n\n\\clearpage\n\n", "meta": {"hexsha": "62746b1756b02ae98d7cf26018efc7d7a487ea9b", "size": 1519, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/numeric/partial_sum.tex", "max_stars_repo_name": "fraunhoferfokus/acsl-by-example", "max_stars_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2017-06-14T04:17:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T06:07:36.000Z", "max_issues_repo_path": "Informal/numeric/partial_sum.tex", "max_issues_repo_name": "fraunhoferfokus/acsl-by-example", "max_issues_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-10-18T13:30:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T07:10:16.000Z", "max_forks_repo_path": "Informal/numeric/partial_sum.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 28.6603773585, "max_line_length": 97, "alphanum_fraction": 0.7590520079, "num_tokens": 445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961506, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7087600369665155}}
{"text": "% !TEX root = index.tex\n\n\\section{How Curved are Curves?}\n\\epigraph{The real problem in speech is not precise language. The problem is clear language.}{Richard Feynmann}\n\\subsection{Curvature of Curves}\nOur first goal is to define a quantitative measure of curvature. For example, we would like to determine what the curvature of the sine curve is at various points. For us a \\textbf{curve} $ C$ is the image of a smooth function $ c(t): (a,b) \\rightarrow \\R^2$ or $ \\R^3$. The function $ c(t)$ is called a \\textbf{parametrization} of the curve $ C$.\n\\begin{example} $ $\n\t\\label{example:parametrizations}\n\t\\begin{enumerate}\n\t\t\\item The circle $ x^2 + y^2 = r^2$ can be parametrized as \\begin{align*}\n\t\t\t      c(t) = (r \\cos (\\omega t), r \\sin(\\omega t))\n\t\t      \\end{align*}\n\t\t      where $ \\omega$ is any non-zero constant.\n\t\t\\item The sine curve can be parametrized as\n\t\t      \\begin{align*}\n\t\t\t      c(t) = (t, \\sin t)\n\t\t      \\end{align*}\n\t\t\\item More generally, the graph $ y=f(x)$ can be parametrized as\n\t\t      \\begin{align*}\n\t\t\t      c(t) = (t,f(t))\n\t\t      \\end{align*}\n\t\\end{enumerate}\n\\end{example}\n\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[t]{0.4\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[height=6cm]{small_radius_circle}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.59\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[height=6cm]{large_radius_circle}\n\t\\end{subfigure}\n\t\\caption{The smaller the radius of the circle the faster the rate of change of the tangent vector.}\n\\end{figure}\n\nRecall that $ c'(t)$ is the \\textbf{tangent vector} to the curve $ C$ at the point $ c(t)$. If a curve has large curvature then the angular component of the tangent vector should change rapidly as we move along the curve, conversely if a curve has small curvature then the angular component should change slowly, which suggests the following definition.\n\n\\begin{definition}\n\tThe \\textbf{curvature} $ \\kappa$ of a curve $ C$ parametrized by $ c(t)$ is defined to be the rate of change of the angular component of $ c'(t)$.\n\\end{definition}\nRecall that every non-zero vector $ \\vec{v}$ can be written as $ \\vec{v} = \\norm{\\vec{v}} . u$, where $ u$ is the unit vector in the direction of $ v$. The length $ \\norm{\\vec{v}}$ is the \\textbf{radial component} of $ v$ and $ u = \\vec{v} / \\norm{\\vec{v}}$ is the \\textbf{angular component} of $ v$. We can make the above definition more precise as follows.\n\\begin{definition}\n\tThe \\textbf{curvature} of a curve $ C$ parametrized by $ c(t)$ is defined to be\n\t\\begin{align*}\n\t\t\\kappa\n\t\t&:= \\mbox{ rate of change of the angular component of } c'(t) \\\\\n\t\t&= \\left \\lVert \\dfrac{d}{dt} \\left( \\dfrac{c'(t)}{\\norm{c'(t)}}\\right) \\right \\rVert \\cdot \\dfrac{1}{\\norm{c'(t)}}\n\t\\end{align*}\n\tassuming $c'(t) \\neq 0$.\n\\end{definition}\nWe divide by $\\norm{c'(t)}$ to normalize the rate at which we're moving along the curve.\n\\begin{remark}\n\tIt's not too hard to find parametrizations with $c'(t) \\neq 0$, at least in a small neighborhood of the point under consideration. For example, all the examples in Example \\ref{example:parametrizations} satisfy this condition (check this).\n\\end{remark}\n\nFrom this definition we immediately get a way to compute the curvature in the special case when $ \\norm{c'(t)}=1$ for all $ t$. Such a parametrization is called a \\textbf{unit speed parametrization}.\n\\begin{prop}\nFor a unit speed parametrization $c(t)$ the curvature is given by\n\\begin{align*}\n\t\\kappa\n\t&= \\left \\lVert \\dfrac{d}{dt} \\left({c'(t)}\\right) \\right \\rVert = \\norm{c''(t)}\n\\end{align*}\n\\end{prop}\n\\begin{example}\n\tA circle of radius $ r$ can be parametrized as\n\t\\begin{align*}\n\t\tc(t) = (r \\cos (\\omega t), r \\sin(\\omega t))\n\t\\end{align*}\n\tfor some constant $ \\omega$. For this parametrization\n\t$$\\norm{c'(t)} = \\norm{ (-r \\omega \\sin (\\omega t), r \\omega \\cos(\\omega t))} = r \\omega $$\n\tIf we choose $ \\omega = 1/r$ the parametrization becomes unit speed. In this case the curvature equals\n\t\\begin{align*}\n\t\t\\kappa\n\t\t & = \\norm{c''(t)}                            \\\\\n\t\t & = \\norm{(r \\cos (t/r), r \\sin(t/r))}       \\\\\n\t\t & = \\norm{(-1/r \\cos (t/r), -1/r \\sin(t/r))} \\\\\n\t\t & = \\dfrac{1}{r}\n\t\\end{align*}\n:D\n\\end{example}\n\n\\begin{thm}\n\tThe circle of radius $ r$ has constant curvature of $ 1/r$.\n\\end{thm}\nIt is not easy to find unit speed parametrizations for more complicated curves (try it out). We need a formula which is valid even for non-unit speed parametrizations.\n\n\\begin{thm}\n\t\\label{thm:curvature_formula}\n\tThe \\textbf{curvature} of a curve $ C$ parametrized by $ c(t)$ is given by\n\t\\begin{align*}\n\t\t\\kappa = \\dfrac{\\norm{c'(t) \\times c''(t)}}{\\norm{c'(t)}^3}\n\t\\end{align*}\n\tassuming $c'(t) \\neq 0$.\n\\end{thm}\n\\noindent The proof is in the following exercise.\n\\begin{ques}\n\tLet $ c(t)$ be a parametrization of $ C$ which is not necessarily unit speed. Let $ r(t) = \\norm{c'(t)}$ be the radial component of the velocity, suppose that $ r(t)$ is never 0. Let $ \\theta(t) = c'(t)/ \\norm{c'(t)}$ be the angular component of velocity. Note that $r(t)$ is a scalar valued function and $\\theta(t)$ is a vector valued function. The curvature is given by\n\t\\begin{align*}\n\t\t\\kappa = \\dfrac{\\norm{\\theta'(t)}}{r(t)}\n\t\\end{align*}\n\tUse the following steps to compute $ \\kappa$.\n\t\\begin{enumerate}\n    \\item Express $c'(t)$ in terms of $r(t)$ and $\\theta(t)$.\n    \\item Show that $ \\theta'(t) \\cdot \\theta'(t)$ is a constant and equals 1.\n\t\t\\item Show that $ \\theta'(t) \\cdot \\theta''(t) = 0$ and hence $\\theta'(t) \\perp \\theta''(t)$ for all $t$.\n\t\t\\item Conclude that $ \\norm{\\theta'(t) \\times \\theta''(t)} = \\norm{\\theta''(t)}$.\n\t\t\\item Express $ c''(t)$ in terms of $ r(t)$, $ \\theta(t)$, and their derivatives.\n\t\t\\item Prove Theorem \\ref{thm:curvature_formula}.\n\t\\end{enumerate}\n\\end{ques}\n\\begin{ques}\n\tUse the parametrization $(r \\cos (\\omega(t)), r \\sin(\\omega(t)))$ to compute the curvature of a circle of radius $r$, where now $\\omega$ is a function of $t$.\n\\end{ques}\n\\begin{ques}\n\tAn easy computation shows that curvature of the graph $y=x^4$ is 0 at $x=0$. What does this mean geometrically?\n\\end{ques}\n\\begin{ques} $ $\n\t\\begin{enumerate}\n\t\t\\item Find the curvature of the graph $y=f(x)$ where $f:\\R \\rightarrow \\R$ is any smooth function.\n\t\t\\item Guess the relationship between the curvature of the graphs $y=f(x)$ and $y=kf(x/k)$, where $k$ is a positive real number. Prove your guess.\n\t\t\\item Guess the relationship between the curvature of curves parametrized by $c(t)$ and $kc(t)$, where $k$ is a positive real number. Prove your guess.\n\t\\end{enumerate}\n\\end{ques}\nThe formula for curvature in Theorem \\ref{thm:curvature_formula} explicitly depends on the parametrization $ c(t)$ but the curvature itself does not. Have you seen such phenomenon before? Perhaps in your favorite branch of mathematics?\n\\begin{remark}[Generalized Curvature]\n\t\\label{remark:signed_curvature}\n\tOften in calculus, not taking absolute value or norm gives us quantities which do not have explicit geometric significance but are easier to manipulate. For example, the integral itself has no geometric significance rather the area under a curve is the \\emph{absolute value} of the integral, however, the Fundamental Theorem of Calculus does not contain any absolute values. Analogously, we'll call the vector quantity\n\t\\begin{align*}\n\t\t\\vec{\\kappa} := \\dfrac{d}{dt} \\left( \\dfrac{c'(t)}{\\norm{c'(t)}}\\right) \\cdot \\dfrac{1}{\\norm{c'(t)}}\n\t\\end{align*}\nthe \\textbf{Generalized Curvature} for the lack of a better name. The following theorem is the analogue of Fundamental Theorem of Calculus for Curvature.\n\\end{remark}\n\\begin{ques}\n\tFor a curve $C$ with a parametrization $c(t)$ compute the integral\n\t\\begin{align*}\n\t\t\\int \\limits_{t_0}^{t_1} \\vec \\kappa \\: ds\n\t\\end{align*}\n\t(Hint: Think about what this integral is computing geometrically. It might help to first solve this problem for a unit speed parametrization).\n\\end{ques}\n\n\n\n\\subsection{Curvature and Taylor approximation}\n\nLet us now consider curves which are graphs $y=f(x)$. For simplicity we'll assume that 0 is a critical point of $f(x)$ i.e. $f'(0) = 0$, and that $f''(0) \\ge 0$. The following theorem is an easy exercise.\n\\begin{thm}\n  If $0$ is a the \\textbf{critical point} of $f: \\R \\rightarrow \\R$ then the curvature of the graph $y=f(x)$ at $(0,f(0))$ equals ${f''(0)}$.\n\\end{thm}\n\\begin{ques}\n\tProve this.\n\\end{ques}\n\\noindent Thus the degree 2 Taylor approximation of $ f(x) $ at the critical point $ x=0$ is given by\n\\begin{align}\n\t\\label{eq:eq2}\n\t\\begin{split}\n\tf(x) &\\approx f(0) + f''(0) \\dfrac{x^2}{2} \\\\\n  &=f(0) + \\kappa \\dfrac{x^2}{2}\n\\end{split}\n\\end{align}\nThere is another familiar function which has the same Taylor approximation. The equation of a circle of radius $ r$ centered at the origin in $ \\R^2$ is $$ x^2 + y^2 = r^2 $$\n\\emph{Near} the point $(0,-r)$ we can express the circle as the graph $ y = -\\sqrt{r^2 - x^2}$.\n\\begin{ques}\n\tShow that the degree 2 Taylor approximation of $ -\\sqrt{r^2 - x^2} $ at $ x=0$ is given by\n\t\\begin{align}\n\t\t\\label{eq:eq1}\n\t\t-\\sqrt{r^2 - x^2} & \\approx -r + \\dfrac{x^2}{2r}\n\t\\end{align}\n\\end{ques}\nNotice that $ 1/r$ which is the coefficient of $ x^2/2$ is exactly the curvature of the circle. We can interpret Equations \\eqref{eq:eq1} and \\eqref{eq:eq2} as saying that,\n\\begin{prop}\n\t\\label{prop:approximating_circle}\n\t If the curvature of the curve $ y=f(x)$ is $ \\kappa$ at a critical point $p$ then \\textbf{the circle that best approximates the curve at $p$ has radius $ 1/\\kappa$}.\n\\end{prop}\nSince we can always rotate a curve without changing it's curvature, Proposition \\ref{prop:approximating_circle} is true in much more generality and we can drop the condition that $p$ is a critical point. We know from calculus that the first derivative gives us the slope of the tangent line. Here we are saying that the second derivative gives us the \\emph{tangent} circle\\footnote{The technical term is an \\emph{osculating} circle.}.\n\\begin{ques}\n\tThink about how you might generalize the above methods to surfaces.\n\\end{ques}\n\\begin{figure}[H]\n\t\\centering\n\t\t\\includegraphics[height=9cm]{parabola}\n\t\t\\caption{A circle of radius $1/2$ best approximates the parabola $y=x^2$ at $x=0$.}\n\\end{figure}\n\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=9cm]{horizontal_parabola}\n\t\t\\caption{Even if our curve is not a graph the same interpretation remains true.}\n\\end{figure}\n", "meta": {"hexsha": "70a35fc0f101b79c37c32194a008df24d07a0af0", "size": 10317, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01.tex", "max_stars_repo_name": "apurvnakade/mc2018-how-curved-is-a-potato", "max_stars_repo_head_hexsha": "d76acd32d3f030b4fbf3ed0cad3876639bdf4e8f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "01.tex", "max_issues_repo_name": "apurvnakade/mc2018-how-curved-is-a-potato", "max_issues_repo_head_hexsha": "d76acd32d3f030b4fbf3ed0cad3876639bdf4e8f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01.tex", "max_forks_repo_name": "apurvnakade/mc2018-how-curved-is-a-potato", "max_forks_repo_head_hexsha": "d76acd32d3f030b4fbf3ed0cad3876639bdf4e8f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.0157068063, "max_line_length": 434, "alphanum_fraction": 0.6903169526, "num_tokens": 3261, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.7087600347457934}}
{"text": "\\documentclass{article}\n\n\\usepackage[english]{babel}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath,amssymb}\n\\usepackage{parskip}\n\\usepackage{graphicx}\n\n% Margins\n\\usepackage[top=2.5cm, left=3cm, right=3cm, bottom=4.0cm]{geometry}\n% Colour table cells\n\\usepackage[table]{xcolor}\n\n% Get larger line spacing in table\n\\newcommand{\\tablespace}{\\\\[1.25mm]}\n\\newcommand\\Tstrut{\\rule{0pt}{2.6ex}}         % = `top' strut\n\\newcommand\\tstrut{\\rule{0pt}{2.0ex}}         % = `top' strut\n\\newcommand\\Bstrut{\\rule[-0.9ex]{0pt}{0pt}}   % = `bottom' strut\n\n%%%%%%%%%%%%%%%%%\n%     Title     %\n%%%%%%%%%%%%%%%%%\n\\title{Research Assistant Crypto Response}\n\\author{Haile Lagi}\n\\date{September 25, 2020}\n\n\\begin{document}\n\\maketitle\n\n%%%%%%%%%%%%%%%%%\n% Math problem   %\n%%%%%%%%%%%%%%%%%\n\\section{Math}\n Over all real numbers, find the minimum value of a positive real number, $y$ such that\n\\begin{align}\n    \\label{eq:obj_fn} % Equation label; can be used for referencing\n    y = \\sqrt{(x+6)^2 + 25)} + \\sqrt{(x-6)^2 + 121} \\,.\n\\end{align}\n\nTo find a stationary point(in this case mininum) for \\ref{eq:obj_fn} the procedure is as follows:\n\\begin{enumerate}\n\\item Given y = f(x) find f'(x)\n\\item Let $\\frac{dy}{dx}=0$ and solve for the x value(s).\n\\item find the corresponding y value(s).\n\\item Determine the nature of the equation using:\n\\begin{itemize}\n\\item Second derivative and substitute x if x is positive, negative or zero\n\\end{itemize}\n\\begin{itemize}\n\\item Alternatively, find gradient before and after the stationary + to -, - to - or + to +\n\\end{itemize}\n\\end{enumerate}\n\nFirst we simplify \\ref{eq:obj_fn} by expanding the polynomials of the form\n$(x + c)^n$ and we have\n\n\\begin{align}\n    \\label{eq: linear}\n    y = \\sqrt{(x+6)(x+6) + 25)} + \\sqrt{(x-6)(x-6) + 121}\n    = \\sqrt{x^2+12x+61} + \\sqrt{x^2 - 12x + 157} \\,.\n\\end{align}\n\nTo find f'(x) using chain rule, in an equation of the form\n$\\frac{dy}{dx}=u^n$ where u is function of x and n is some exponent this holds\n$\\frac{dy}{dx}=\\frac{dy}{du} * \\frac{du}{dx}$. Divide equation \\ref{eq: linear}\ninto two parts $y = y_{1} + y_{2}$ where\n\n\\begin{align}\n    \\label{eq: linear_one}\n    y_{1} = \\sqrt{x^2+12x+61}  \\,.\n\\end{align}\n\n\\begin{align}\n\\label{eq: linear_two}\n    y_{2} = \\sqrt{x^2 - 12x + 157} \\,.\n\\end{align}\n\nApplying the chain rule in \\ref{eq: linear_one} and \\ref{eq: linear_two}\n\\begin{align}\n    \\label{eq: y_one}\n    \\frac{dy_{1}}{dx} = u^\\frac{1}{2} \\,.\n\\end{align}\n\nwhere $u_{1} = x^2 + 12x + 61$ and $\\frac{du_{1}}{dx} = 2x + 12$\n\n\\begin{align}\n    \\label{eq: y_two}\n    \\frac{dy_{2}}{dx} = u^\\frac{1}{2} \\,.\n\\end{align}\n\nwhere $u_{2} = x^2 - 12x - 12x + 157$ and $\\frac{du_{2}}{dx} = 2x - 12$\n\nCombining \\ref{eq: y_one} and \\ref{eq: y_two} we have \\ref{eq: diffed}\n\n\\begin{align}\n    \\label{eq: diffed}\n\\frac{dy}{dx} = \\frac{2x + 12}{2 * \\sqrt(x^2 + 12x + 61)} + \\frac{2x - 12}{2 * \\sqrt(x^2 - 12x + 157)} \\,.\n\\end{align}\n\nBy simple factorization of 2 and Let $\\frac{dy}{dx}=0$\n\n\\begin{align}\n    \\label{eq: irration}\n 0 = \\frac{x + 6}{(x^2 + 12x + 61)^\\frac{1}{2}} + \\frac{x - 6}{(x^2 - 12x + 157)^\\frac{1}{2}} \\,.\n\\end{align}\n\nAt this point it becomes impossible to solve for x because the values of x are complex(or imaginary) so, the root(s) of x are \\textbf{unknown}.\n\n\\begin{align}\n    \\label{eq: solve_y}\n y = (x^2 + 12x + 61)^\\frac{1}{2} + (x^2 - 12x + 157)^\\frac{1}{2} \\,.\n\\end{align}\n\nThe minimum value of a real x is assumed to be  0\n\nSubstituting $x = 0$ in \\ref{eq: solve_y} we have the minimum value of y as:\n\\begin{align}\n    \\label{eq: final}\n y = \\sqrt{61} + \\sqrt{157} \\,.\n\\end{align}\n\nFinally we have $y_{min} = (0, \\sqrt{61} + \\sqrt{157})$\n\n\\end{document}\n", "meta": {"hexsha": "7783d1289ec25e5b3262af2ab36af029f413d980", "size": 3642, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "equations/Maths.tex", "max_stars_repo_name": "obsessedyouth/Research-Assistant-Crypto", "max_stars_repo_head_hexsha": "3d9b42c3e7a745a591938544de43ea757384c907", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "equations/Maths.tex", "max_issues_repo_name": "obsessedyouth/Research-Assistant-Crypto", "max_issues_repo_head_hexsha": "3d9b42c3e7a745a591938544de43ea757384c907", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "equations/Maths.tex", "max_forks_repo_name": "obsessedyouth/Research-Assistant-Crypto", "max_forks_repo_head_hexsha": "3d9b42c3e7a745a591938544de43ea757384c907", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.136, "max_line_length": 143, "alphanum_fraction": 0.624656782, "num_tokens": 1365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503206, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.7087600214015594}}
{"text": "\\subsection{Dynamic Time Warping}\n\n\\begin{frame}{Dynamic Time Warping}\n    \\begin{itemize}\n        \\item A widely used and robust distance measure for time series\n        \n        \\item \\textit{\"Allowing similar shapes to match even if they are out of phase in the time axis\"}\n            \\cite{keogh2002exact}\n    \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Dynamic Time Warping}{Calculation}\n    \\begin{block}{Given}\n        \\begin{itemize}\n            \\item A domain set $\\mathbb{U}$\n            \n            \\item A distance measure function $d$ with $d: \\mathbb{U} \\times \\mathbb{U} \\to \\mathbb{R}$\n            \n        \\end{itemize}\n    \\end{block}\n    \\begin{block}{Input}\n        \\begin{itemize}\n            \\item A time series $Q = (q_1, q_2, \\dots, q_i, \\dots, q_l)$ with length $l$ over the domain set\n                $\\mathbb{U}$\n            \n            \\item A time series $C = (c_1, c_2, \\dots, c_j, \\dots, c_k)$ with length $k$ over the domain set\n                $\\mathbb{U}$\n        \\end{itemize}\n    \\end{block}\n\\end{frame}\n\n\\begin{frame}{Dynamic Time Warping}{Calculation}\n    \\begin{block}{Distance Calculation}\n        \\begin{itemize}\n            \\item Calculation of Matrix $M$ with size $l \\times k$ based on \\cite{sart2010accelerating}\n            \n            \\item {\\small $M_{i, j} = \\begin{cases}\n                d(q_i,c_j) & \\text{if } i = 1 \\wedge j = 1\\\\\n                M_{i,j-1} + d(q_i,c_j) & \\text{if } i = 1 \\wedge j \\neq 1\\\\\n                M_{i-1,j} + d(q_i,c_j) & \\text{if } i \\neq 1 \\wedge j = 1\\\\\n                min(M_{i-1,j}, M_{i-1,j-1}, M_{i,j-1}) + d(q_i,c_j) & \\text{if } i \\neq 1 \\wedge j \\neq 1\n            \\end{cases}$ }\n            \n            \\item $M_{l,k}$ is DTW distance between $Q$ and $C$\n        \\end{itemize}\n    \\end{block}\n\\end{frame}\n\n\\begin{frame}<handout:0>{Dynamic Time Warping}{Example}\n    \\begin{center}\n        \\resizebox {\\textwidth} {!} {\n            \\begin{tabular}{cc}\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tikzpicture}\n                        \\begin{axis}[\n                            xmin=0,\n                            xmax=47,\n                            xlabel=time,\n                            ylabel=acceleration,\n                            width=\\axisdefaultwidth,\n                            height=0.7*\\axisdefaultheight,\n                            reverse legend,\n                            legend pos=south east]\n                            \\addplot[red, thick, mark=none] table {../data/fig/dynamictimewarping/q.dat};\n                            \\addlegendentry{Q}\n                            \\addplot[blue, thick, mark=none] table {../data/fig/dynamictimewarping/c.dat};\n                            \\addlegendentry{C}\n                        \\end{axis}\n                    \\end{tikzpicture}\n                } & \\quad\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tabular}[b]{ll}\n                        \\begin{turn}{90}\n                            \\begin{tikzpicture}\n                                \\begin{axis}[\n                                    xmin=0,\n                                    xmax=47,\n                                    ymin=-100,\n                                    ymax=0,\n                                    hide x axis,\n                                    hide y axis,\n                                    width=\\axisdefaultwidth,\n                                    height=0.7*\\axisdefaultheight]\n                                    \\addplot[red, ultra thick, mark=none] table {../data/fig/dynamictimewarping/q.dat};\n                                \\end{axis}\n                            \\end{tikzpicture}\n                        \\end{turn} \\hspace*{3em} &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                enlargelimits=false,\n                                ymin=0,\n                                ymax=47,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=\\axisdefaultwidth,\n                                colorbar,\n                                colormap/viridis high res]\n                                \\addplot[matrix plot*,\n                                    mesh/cols=48,\n                                    point meta=explicit] table[meta=C] {../data/fig/dynamictimewarping/matrix.dat};\n                            \\end{axis}\n                        \\end{tikzpicture} \\\\\n                        &\n                        \\\\[1em]\n                        &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                xmin=0,\n                                xmax=47,\n                                ymin=-100,\n                                ymax=0,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=0.7*\\axisdefaultheight]\n                                \\addplot[blue, ultra thick, mark=none] table {../data/fig/dynamictimewarping/c.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\n                    \\end{tabular}\n                }\n            \\end{tabular}\n        }\n    \\end{center}\n\\end{frame}\n\n\\begin{frame}{Dynamic Time Warping}{Example}\n    \\begin{center}\n        \\resizebox {\\textwidth} {!} {\n            \\begin{tabular}{cc}\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tikzpicture}\n                        \\begin{axis}[\n                            xmin=0,\n                            xmax=47,\n                            xlabel=time,\n                            ylabel=acceleration,\n                            width=\\axisdefaultwidth,\n                            height=0.7*\\axisdefaultheight,\n                            reverse legend,\n                            legend pos=south east]\n                            \\addplot[gray, quiver={u=\\thisrow{u}, v=\\thisrow{v}}] table {../data/fig/dynamictimewarping/path.dat};\n                            \\addplot[red, thick, mark=none] table {../data/fig/dynamictimewarping/q.dat};\n                            \\addlegendentry{Q}\n                            \\addplot[blue, thick, mark=none] table {../data/fig/dynamictimewarping/c.dat};\n                            \\addlegendentry{C}\n                        \\end{axis}\n                    \\end{tikzpicture}\n                } & \\quad\n                \\resizebox* {!} {0.3\\textwidth} {\n                    \\begin{tabular}[b]{ll}\n                        \\begin{turn}{90}\n                            \\begin{tikzpicture}\n                                \\begin{axis}[\n                                    xmin=0,\n                                    xmax=47,\n                                    ymin=-100,\n                                    ymax=0,\n                                    hide x axis,\n                                    hide y axis,\n                                    width=\\axisdefaultwidth,\n                                    height=0.7*\\axisdefaultheight]\n                                    \\addplot[red, ultra thick, mark=none] table {../data/fig/dynamictimewarping/q.dat};\n                                \\end{axis}\n                            \\end{tikzpicture}\n                        \\end{turn} \\hspace*{3em} &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                enlargelimits=false,\n                                ymin=0,\n                                ymax=47,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=\\axisdefaultwidth,\n                                colorbar,\n                                colormap/viridis high res]\n                                \\addplot[matrix plot*,\n                                    mesh/cols=48,\n                                    point meta=explicit] table[meta=C] {../data/fig/dynamictimewarping/matrix.dat};\n                                \\addplot[white, ultra thick, mark=*, mark size=1] table {../data/fig/dynamictimewarping/matrix_path.dat};\n                            \\end{axis}\n                        \\end{tikzpicture} \\\\\n                        &\n                        \\\\[1em]\n                        &\n                        \\begin{tikzpicture}\n                            \\begin{axis}[\n                                xmin=0,\n                                xmax=47,\n                                ymin=-100,\n                                ymax=0,\n                                hide x axis,\n                                hide y axis,\n                                width=\\axisdefaultwidth,\n                                height=0.7*\\axisdefaultheight]\n                                \\addplot[blue, ultra thick, mark=none] table {../data/fig/dynamictimewarping/c.dat};\n                            \\end{axis}\n                        \\end{tikzpicture}\n                    \\end{tabular}\n                }\n            \\end{tabular}\n        }\n    \\end{center}\n\\end{frame}\n\n\\input{background/dynamic_time_warping/sakoe-chiba_band.tex}\n\\input{background/dynamic_time_warping/time_series_normalization.tex}\n", "meta": {"hexsha": "8ce9826ded708e8ec2806e644d10324dc03dfc3e", "size": 9454, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "presentation/background/dynamic_time_warping.tex", "max_stars_repo_name": "GordonLesti/SlidingWindowFilter", "max_stars_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-06-22T09:37:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T11:43:53.000Z", "max_issues_repo_path": "presentation/background/dynamic_time_warping.tex", "max_issues_repo_name": "GordonLesti/SlidingWindowFilter", "max_issues_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "presentation/background/dynamic_time_warping.tex", "max_forks_repo_name": "GordonLesti/SlidingWindowFilter", "max_forks_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-11T23:15:57.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-11T23:15:57.000Z", "avg_line_length": 45.2344497608, "max_line_length": 137, "alphanum_fraction": 0.3750793315, "num_tokens": 1997, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.7087600184372794}}
{"text": "%!TEX root = TTK4150-Summary.tex\n\\section{Nonlinear design tools}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Backstepping}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{General idea}\nStart by selecting a state $x_i$, where $i$ is some index. Given $\\dot{x}_i = f_i(x)$, consider one of the other states present in $f_i$ as the input. Let's call this state $x_j$. Find an expression $x_j = \\phi_j(x)$ that stabilizes $x_i$. (Using a Lyapunov function $V(x_i)$.) Then, define $z_j = x_j - \\phi_j(x)$, and rewrite the system in terms of $x_i$ and $z_j$. Now, considering $\\dot{z}_j$, use the same method to find an expression for a state present in $\\dot{z}_j$ to stabilize $z_j$ and $x_i$. (Now with a Lyapunov function $V(x_i, z_j)$.) Keep going until you run out of states to stabilize.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Passivity-based control}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{align}\n\t\\dot{x} &= f(x,u) \\label{eq:pin-pout-x} \\\\\n\ty       &= h(x)   \\label{eq:pin-pout-y}\n\\end{align}\n\n\\paragraph{Theorem 14.4}\nIf \\eqref{eq:pin-pout-x}--\\eqref{eq:pin-pout-y} is\n\\begin{itemize}\n\t\\item passive with an RU, pos. def. storage function,\n\t\\item zero-state observable\n\\end{itemize}\nthen $x = 0$ can be globally stabilized by $u = -\\phi(y)$, with $\\phi$ locally Lipschitz with $\\phi(0) = 0$, $y\\T \\phi(y) > 0 \\forall y \\neq 0$.\n", "meta": {"hexsha": "325cd7d2299fe79ae0dd210060ea87a7b666cf1d", "size": 1331, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK4150 Nonlinear control systems/sec-nonlinear-design-tools.tex", "max_stars_repo_name": "jakoblover/ntnu-course-summaries", "max_stars_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-11T02:42:40.000Z", "max_issues_repo_path": "TTK4150 Nonlinear control systems/sec-nonlinear-design-tools.tex", "max_issues_repo_name": "jakoblover/ntnu-course-summaries", "max_issues_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TTK4150 Nonlinear control systems/sec-nonlinear-design-tools.tex", "max_forks_repo_name": "jakoblover/ntnu-course-summaries", "max_forks_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.24, "max_line_length": 603, "alphanum_fraction": 0.6235912847, "num_tokens": 425, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7087429531976149}}
{"text": "\\subsection{Example: Slider-crank Mechanism}\n\n\\begin{frame}\n\t\\begin{block}{Example 1: Slider-crank Mechanism}\n\t\t\\begin{table}\n\t\t\t\\begin{minipage}{0.5\\linewidth}\n\t\t\t\t\\begin{tabular}{l|l}\n\t\t\t\t\t      & $l_{AB}=l_1=0.5m$ \\\\\n\t\t\t\t\tGiven & $l_{BC}=l_2=1m$ \\\\\n\t\t\t\t\t      & $\\theta_1=60^\\circ$ \\\\ \\hline\n\t\t\t\t\tFind  & $x_C$ \\\\\n\t\t\t\t\\end{tabular}\n\t\t\t\\end{minipage}\\hfill\n\t\t\t\\begin{minipage}{0.5\\linewidth}\n\t\t\t\t\\includegraphics[width=50mm]{images/R-RRT.png}\n\t\t\t\\end{minipage}\n\t\t\\end{table}\n\t\\end{block}\n\\emph{Solution 1}\\vskip2.5mm\nPosition of joint $B$: $\\displaystyle \\vb{r}{B} = x_B\\ih + y_B\\jh = l_1\\cos{\\theta_1}\\ih + l_1\\sin{\\theta_1}\\jh$\\\\\nPosition of joint $C$: $\\displaystyle \\vb{r}{C} = x_C\\ih$\n\\[\n\\Rightarrow(x_B-x_C)^2+y_B^2=l_1^2\n\\]\nSolving the system of equations yields $x_{C_1}$ and $x_{C_2}$. Notice that in the mechanism, $x_C>x_B$ is the condition to obtain correct solution.\n\\end{frame}\n\n\\begin{frame}\n\\emph{Solution 2}\\vskip2.5mm\nLet $\\vb{r}{B}=l_1\\cos{\\theta_1}\\ih+l_1\\sin{\\theta_1}\\jh$\\vskip1.5mm\nWe can determine position of C by using direct solution:\\vskip1.5mm\n$\\displaystyle\\vb{r}{C}=\\left(l_1\\cos{\\theta_1}+l_2\\left(\\arcsin{\\frac{l_1\\sin{\\theta_1}}{l_2}}\\right)\\right)\\ih$\\vskip7.5mm\n\\emph{MATLAB R2019a code}\\\\\n\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/RRRT-position2.m}\n\\end{frame}\n\n\n\\begin{frame}{MATLAB R2019a code}\n\t\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/RRRT-position1.m}\n\\end{frame}\n\\begin{frame}{Plotting using MATLAB R2019a}\n\t\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/RRRT-plot.m}\n\\end{frame}\n\\begin{frame}{Output figure}\n\\centering\n\\includegraphics[width=100mm]{images/RRRT-plot.png}\n\\end{frame}\n\\begin{frame}{Trajectory plotting using MATLAB R2019a}\n\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/RRRT-trajectory.m}\n\\end{frame}\n\\begin{frame}{Output figure}\n\\centering\n\\includegraphics[width=100mm]{images/RRRT-trajectory.png}\n\\end{frame}", "meta": {"hexsha": "b7fad80d15929b95aacec97c800e5b44fd9a2c7d", "size": 1966, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Finished/position_analysis_pdf/Sections/Examples/RRRT.tex", "max_stars_repo_name": "HungNguyenDang/literate-meme", "max_stars_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Finished/position_analysis_pdf/Sections/Examples/RRRT.tex", "max_issues_repo_name": "HungNguyenDang/literate-meme", "max_issues_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Finished/position_analysis_pdf/Sections/Examples/RRRT.tex", "max_forks_repo_name": "HungNguyenDang/literate-meme", "max_forks_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.4074074074, "max_line_length": 148, "alphanum_fraction": 0.7115971516, "num_tokens": 748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7087429465568351}}
{"text": "\\chapter{Assignment-Complex Numbers}\n\\section{MCQ}\n\\begin{enumerate}\n\t\\item The amplitude of $\\frac{1+i \\sqrt{3}}{\\sqrt{3}+i}$ is\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\frac{\\pi}{3}$\n\t\\task[\\textbf{b.}]$-\\frac{\\pi}{3}$\n\t\\task[\\textbf{c.}]$\\frac{\\pi}{6}$\n\t\\task[\\textbf{d.}]  $-\\frac{\\pi}{6}$\n\\end{tasks}\t\n\t\\item If $\\frac{1-i x}{1+i x}=a+i b$, then $a^{2}+b^{2}$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]1\n\t\t\\task[\\textbf{b.}]$-1$\n\t\t\\task[\\textbf{c.}] 0\n\t\t\\task[\\textbf{d.}] none of these\n\t\\end{tasks}\n\t\\item If $z=1-\\cos \\theta+i \\sin \\theta$, then $|z|$ equals\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$2 \\sin \\frac{\\theta}{2}$\n\t\t\\task[\\textbf{b.}]$2 \\cos \\frac{\\theta}{2}$\n\t\t\\task[\\textbf{c.}]$2\\left|\\sin \\frac{\\theta}{2}\\right|$\n\t\t\\task[\\textbf{d.}] $2\\left|\\cos \\frac{\\theta}{2}\\right|$\n\t\\end{tasks}\n\t\\item If $z=\\frac{1}{(2+3 i)^{2}}$, then $|z|$ equals\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{1}{13}$\n\t\t\\task[\\textbf{b.}]$\\frac{1}{15}$\n\t\t\\task[\\textbf{c.}]$\\frac{1}{12}$\n\t\t\\task[\\textbf{d.}] none of these\n\t\\end{tasks}\n\t\\item If $x_{n}=\\cos \\left(\\frac{\\pi}{2^{n}}\\right)+i \\sin \\left(\\frac{\\pi}{2^{n}}\\right)$\n\tThen the value of $x_{1} \\cdot x_{2} \\cdot x_{3} \\ldots$, up to infinity is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $-2$\n\t\t\\task[\\textbf{b.}] $+2$\n\t\t\\task[\\textbf{c.}] $-1$\n\t\t\\task[\\textbf{d.}] $+1$\n\t\\end{tasks}\n\t\\item If $\\left|z-\\frac{4}{z}\\right|=2$, then the maximum value of $|z|$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\sqrt{5}$\n\t\t\\task[\\textbf{b.}]$\\sqrt{5}+1$\n\t\t\\task[\\textbf{c.}]$\\sqrt{5}-1$\n\t\t\\task[\\textbf{d.}] none of these\n\t\\end{tasks}\n\t\\item The value of $1+\\sum_{k=0}^{14}\\left\\{\\cos \\frac{(2 k+1) \\pi}{15}+i \\sin \\frac{(2 k+1) \\pi}{15}\\right\\}$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]0\n\t\t\\task[\\textbf{b.}] $-1$\n\t\t\\task[\\textbf{c.}]1\n\t\t\\task[\\textbf{d.}] $i$\n\t\\end{tasks}\n\t\\item The point representing complex number for which $|z+4|^{2}-|z-4|^{2}=8$ lie on\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]a straight line parallel to $x$-axis\n\t\t\\task[\\textbf{b.}]a straight line parallel to $y$-axis\n\t\t\\task[\\textbf{c.}]a circle with centre as origin\n\t\t\\task[\\textbf{d.}] a circle with centre other than origin\n\t\\end{tasks}\n\t\\item If $\\left|\\begin{array}{ccc}6 i & -3 i & 1 \\\\ 4 & 3 i & -1 \\\\ 20 & 3 & i\\end{array}\\right|=x+i y$, then\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $x=3, y=1$\n\t\t\\task[\\textbf{b.}] $x=1, y=3$\n\t\t\\task[\\textbf{c.}]$x=0, y=3$\n\t\t\\task[\\textbf{d.}]  $x=0, y=0$\n\t\\end{tasks}\n\t\\item If the number $\\frac{z-1}{z+1}$ is purely imaginary, then\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$|z|=1$\n\t\t\\task[\\textbf{b.}]$|z|>1$\n\t\t\\task[\\textbf{c.}]$|z|<1$\n\t\t\\task[\\textbf{d.}] $|z|>2$\n\t\\end{tasks}\n\t\\item The value of integral $I=\\int_{0}^{\\pi} \\frac{2 d \\theta}{R-\\cos \\theta}$ is given by where $R$ is real constant.\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{-1}{2 \\sqrt{R^{2}-1}}$\n\t\t\\task[\\textbf{b.}]$\\frac{2 \\pi}{\\sqrt{R^{2}-1}}$\n\t\t\\task[\\textbf{c.}]$\\frac{\\pi}{\\sqrt{1-R^{2}}}$\n\t\t\\task[\\textbf{d.}] $\\frac{\\pi}{\\sqrt{R^{2}-1}}$\n\t\\end{tasks}\n\t\\item The value of integral $\\int_{-\\infty}^{+\\infty} \\frac{d x}{\\left(1+x^{2}\\right)^{2}}$ is given by\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{\\pi}{2}$\n\t\t\\task[\\textbf{b.}]$\\pi$\n\t\t\\task[\\textbf{c.}] $i \\frac{\\pi}{2}$\n\t\t\\task[\\textbf{d.}]  $\\frac{1}{4 i}$\n\t\\end{tasks}\n\t\\item The value of $\\oint_{C} \\frac{\\sin 3 z}{z^{2}} d z$\n\t$c:|z|=\\pi$ is given by\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$6 \\pi i$\n\t\t\\task[\\textbf{b.}]$-6 \\pi i$\n\t\t\\task[\\textbf{c.}]0\n\t\t\\task[\\textbf{d.}]  3\n\t\\end{tasks}\n\t\\item The value of integral $\\int_{0}^{2 \\pi} \\frac{\\cos ^{2} \\theta d \\theta}{5-4 \\cos \\theta}$\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{\\pi}{12}$\n\t\t\\task[\\textbf{b.}]$-\\frac{5 \\pi}{12}$\n\t\t\\task[\\textbf{c.}]$\\frac{5 \\pi}{12}$\n\t\t\\task[\\textbf{d.}] $\\frac{-5}{12}$\n\t\\end{tasks}\n\t\\item $\\int_{0}^{2 \\pi} \\frac{\\cos \\theta}{13-12 \\cos 2 \\theta} d \\theta$\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]0\n\t\t\\task[\\textbf{b.}]$\\frac{+1}{10} \\sqrt{\\frac{2}{3}}$\n\t\t\\task[\\textbf{c.}] $\\frac{-1}{10} \\sqrt{\\frac{2}{3}}$\n\t\t\\task[\\textbf{d.}]  $\\frac{i}{10} \\sqrt{\\frac{2}{3}}$\n\t\\end{tasks}\n\t\\item Consider a complex function $f(z)=\\frac{1}{z\\left(z+\\frac{1}{2}\\right) \\cos (z \\pi)}$. Which one of the following\n\tstatements is correct?\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $f(z)$ has simple poles at $z=0$ and $z=-\\frac{1}{2}$\n\t\t\\task[\\textbf{b.}]$f(z)$ has second order pole at $z=-\\frac{1}{2}$\n\t\t\\task[\\textbf{c.}]$f(z)$ has infinite number of second order poles\n\t\t\\task[\\textbf{d.}] $f(z)$ has all simple poles\n\t\\end{tasks}\n\t\\item The value of integral\n\t$$\n\tI=\\oint_{c} \\frac{\\sin z}{2 z-\\pi} d z\n\t$$\n\twith $c$ a circle $|z|=2$, is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]0\n\t\t\\task[\\textbf{b.}]$2 \\pi i$\n\t\t\\task[\\textbf{c.}]$\\pi i$\n\t\t\\task[\\textbf{d.}] $-\\pi i$\n\t\\end{tasks}\n\t\\item The value of integral $I=\\int_{0}^{x} \\frac{(\\ln x)^{2}}{x^{2}+1} d x$ is given by\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{\\pi^{3}}{2}$\n\t\t\\task[\\textbf{b.}]$\\frac{\\pi^{3}}{4}$\n\t\t\\task[\\textbf{c.}]$\\frac{\\pi^{3}}{8}$\n\t\t\\task[\\textbf{d.}]  $\\frac{\\pi^{3}}{14}$\n\t\\end{tasks}\n\t\\item $\\int_{c} \\frac{d z}{z^{2} \\sinh z}$ where contour is defined as $|z-1|=2$. The value of integral is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{\\pi i}{3}$\n\t\t\\task[\\textbf{b.}]$\\frac{-\\pi i}{3}$\n\t\t\\task[\\textbf{c.}]$\\frac{\\pi i}{6}$\n\t\t\\task[\\textbf{d.}] $\\frac{-\\pi i}{6}$\n\t\\end{tasks}\n\t\\item The value of the integral $\\int_{0}^{\\infty} \\frac{\\ln x^{2}}{\\left(x^{2}+1\\right)^{2}} d x$ is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]0\n\t\t\\task[\\textbf{b.}] $\\frac{-\\pi}{4}$\n\t\t\\task[\\textbf{c.}]$\\frac{-\\pi}{2}$\n\t\t\\task[\\textbf{d.}] $\\frac{\\pi}{2}$\n\t\\end{tasks}\n\t\\item The value of the integral $\\int_{C} \\frac{z^{3} d z}{-2 z^{2}+10 z-12}$, where $C$ is a closed contour defined by the cquation $2|=|-5=0$, traversed in the anti-clockwise direction, is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$-16 \\pi i$\n\t\t\\task[\\textbf{b.}]$16 \\pi i$\n\t\t\\task[\\textbf{c.}]$8 \\pi i$\n\t\t\\task[\\textbf{d.}] $2 \\pi i$\n\t\\end{tasks}\n\t\\item The value of $\\oint \\frac{\\cos \\pi z}{z^{2}-1} d z$ around a rectangle with vertices at $2 \\pm i,-2 \\pm i$ is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\pi$\n\t\t\\task[\\textbf{b.}] $-\\pi$\n\t\t\\task[\\textbf{c.}]$2 \\pi$\n\t\t\\task[\\textbf{d.}] 0\n\t\\end{tasks}\n\t\\item The principal value of the integral $\\int_{-\\infty}^{\\infty} \\frac{\\sin (2 x)}{x^{3}} d x$ is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$-2 \\pi$\n\t\t\\task[\\textbf{b.}]$-\\pi$\n\t\t\\task[\\textbf{c.}] $\\pi$\n\t\t\\task[\\textbf{d.}] $2 \\pi$\n\t\\end{tasks}\n\t\\item The value of $\\int_{0}^{2 \\pi} \\frac{d \\theta}{5+4 \\cos \\theta}$ is:\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{2 \\pi}{3}$\n\t\t\\task[\\textbf{b.}]$\\frac{\\pi}{3}$\n\t\t\\task[\\textbf{c.}]$-\\frac{\\pi}{3}$\n\t\t\\task[\\textbf{d.}] 0\n\t\\end{tasks}\n\t\\item The value of integral $\\int_{-\\infty}^{+\\infty} \\frac{x}{\\left(x^{2}+1\\right)\\left(x^{2}+4\\right)} d x$ is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]0\n\t\t\\task[\\textbf{b.}]1\n\t\t\\task[\\textbf{c.}]2\n\t\t\\task[\\textbf{d.}] 3\n\t\\end{tasks}\n\t\\item The value of integral $\\int_{0}^{2 \\pi} \\frac{d \\theta}{13-5 \\sin \\theta}$ is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{\\pi}{2}$\n\t\t\\task[\\textbf{b.}]$\\frac{\\pi}{3}$\n\t\t\\task[\\textbf{c.}]$\\frac{\\pi}{4}$\n\t\t\\task[\\textbf{d.}] $\\frac{\\pi}{6}$\n\t\\end{tasks}\n\t\\item The value of $\\int_{0}^{\\infty} \\frac{\\ln x}{\\left(x^{2}+4\\right)^{2}} d x$ is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{\\pi}{32}(\\ln 2+1)$\n\t\t\\task[\\textbf{b.}] $\\frac{\\pi}{32}(\\ln 2-1)$\n\t\t\\task[\\textbf{c.}]$\\frac{\\pi}{32} \\ln 2$\n\t\t\\task[\\textbf{d.}]  $\\frac{\\pi}{32}$\n\t\\end{tasks}\n\t\\item If $0<p<1$, then the value of integral $\\int_{0}^{\\infty} \\frac{x^{p-1}}{1+x} d x$ is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{\\pi}{2 \\sin p \\pi}$\n\t\t\\task[\\textbf{b.}] $\\frac{1}{\\sin \\frac{p}{2} \\pi}$\n\t\t\\task[\\textbf{c.}]$\\frac{\\pi}{\\sin p \\pi}$\n\t\t\\task[\\textbf{d.}]  $\\frac{\\pi}{\\sin \\frac{p}{2} \\pi}$\n\t\\end{tasks}\n\t\\item If $C$ is the circle given by $|z|=\\pi$, and the integral is evaluated counterclockwise then the value of integral $\\oint_{c} \\frac{z \\cosh z \\pi}{z^{4}+13 z^{2}+36} d z$ is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\frac{2 \\pi i}{5}$\n\t\t\\task[\\textbf{b.}]$\\frac{3 \\pi i}{5}$\n\t\t\\task[\\textbf{c.}]$\\frac{4 \\pi i}{5}$\n\t\t\\task[\\textbf{d.}]  $\\frac{6 \\pi i}{5}$\n\t\\end{tasks}\n\t\\section{NAT}\n\t\\item The least positive integer $n$ for which $\\left(\\frac{1+i}{1-i}\\right)^{n}$ is real is...\n\t\\item The value of $i^{n}+i^{n+1}+i^{n+2}+i^{n+3}$ is\n\t\\item The value of $\\frac{(\\cos 3 \\theta+i \\sin 3 \\theta)^{4}(\\cos 4 \\theta-i \\sin 4 \\theta)^{5}}{(\\cos 4 \\theta+i \\sin 4 \\theta)^{3}(\\cos 5 \\theta+i \\sin 5 \\theta)^{-4}}$ is\n\t\\item For $n=6 k, k \\in z$,\\\\\n\t$\\left(\\frac{1-i \\sqrt{3}}{2}\\right)^{n}+\\left(\\frac{-1-i \\sqrt{3}}{2}\\right)^{n}$ has the value...\n\t\\item If $z=\\frac{\\sqrt{3}+i}{2}$, then $z^{69}$ equals -----------\n\t\\section{MSQ}\n\t\\item If $z=4+2 i$, then\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] The magnitude of $z$ is $2 \\sqrt{5}$ units\n\t\t\\task[\\textbf{b.}]The magnitude of $z$ is $3 \\sqrt{5}$ units\n\t\t\\task[\\textbf{c.}] The argument or amplitude of $z$ is $\\tan ^{-1} \\frac{1}{3}$\n\t\t\\task[\\textbf{d.}]  The argument or amplitude of $z$ is $\\tan ^{-1} \\frac{1}{2}$\n\t\\end{tasks}\n\t\\item Consider a complex number $z=1-\\sqrt{3} i$\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]The magnitude of $z$ is 2 units\n\t\t\\task[\\textbf{b.}]The magnitude of $z$ is 4 units\n\t\t\\task[\\textbf{c.}]The complex number z can be represented by a point $(1,-\\sqrt{3})$ in the complex or Argand plane\n\t\t\\task[\\textbf{d.}] The complex number z can be represented by a point $(-\\sqrt{3},-1)$ in the complex plane.\n\t\\end{tasks}\n\t\\item If $z_{1}=2+3 i$ and $z_{2}=1+2 i$ then\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $z_{1}+z_{2}$ is equal to $4+6 i$\n\t\t\\task[\\textbf{b.}]$z_{1}-z_{2}$ is equal to $1+i$\n\t\t\\task[\\textbf{c.}]$z_{1} \\cdot z_{2}$ is equal to $-4+7 i$\n\t\t\\task[\\textbf{d.}]  $\\frac{z_{1}}{z_{2}}$ is equal to $\\frac{8}{5}-\\frac{1}{5} i$\n\t\\end{tasks}\n\t\\item Pick out the correct statement (S)\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]Addition of two complex number is commutative\n\t\t\\task[\\textbf{b.}]For any three complex numbers $z_{1}, z_{2}$ and $z_{3}$ we have $\\left(z_{1}+z_{2}\\right)+z_{3}=z_{1}+\\left(z_{2}+z_{3}\\right)$\n\t\t\\task[\\textbf{c.}]For any two complex numbers $z_{1}$ and $z_{2}$ we have $z_{1} \\cdot z_{2}=z_{2} \\cdot z_{1}$\n\t\t\\task[\\textbf{d.}] Multiplication of two complex number are not commutative\n\t\\end{tasks}\n\t\\item Pick out the correct statement(s)\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] Let $z$ and $\\bar{z}$ denote a complex number and its conjugate respectively then, $z=\\bar{z}$ implies $z$ is purely imaginary\n\t\t\\task[\\textbf{b.}]Let $z$ and $\\bar{z}$ denote a complex number and its conjugate respectively then, $z+\\bar{z}=0$ implies $z$ is purely imaginary\n\t\t\\task[\\textbf{c.}]In polar form the complex number $z=1+i$ can be written as $\\sqrt{2}\\left(\\cos \\frac{\\pi}{4}+i \\sin \\frac{\\pi}{4}\\right)$\n\t\t\\task[\\textbf{d.}]  In polar form the complex number $1+i$ can be written as $\\sqrt{2}\\left(\\cos \\frac{\\pi}{3}+i \\sin \\frac{\\pi}{3}\\right)$\n\t\\end{tasks}\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\\end{enumerate}", "meta": {"hexsha": "628860b1ada0ac57417b32ea8c3cedcf14a6eec8", "size": 11000, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/Assignments/Assignment-Complex Numbers.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CSIR- Mathematical Physics/chapter/Assignments/Assignment-Complex Numbers.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CSIR- Mathematical Physics/chapter/Assignments/Assignment-Complex Numbers.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.3533834586, "max_line_length": 191, "alphanum_fraction": 0.5757272727, "num_tokens": 5041, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7087429307918948}}
{"text": "\\section{Evaluation}\n\\label{sec:evaluation}\n\nAll the results presented in this section are obtained with the following parameters:\n\\begin{itemize}\n    \\item $n_D = 50$\n    \\item $n_{max} = 250$\n    \\item $N = 200$\n\\end{itemize}\n\n\\subsection{MinOver}\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/base}\n    \\caption{Generalization error of a perceptron trained with the MinOver algorithm on a linearly separable dataset.}\n\t\\label{fig:base}\n\\end{figure}\n\n\\cref{fig:base} shows the generalization error of the perceptron trained with the MinOver algorithm on a linearly separable dataset (with no noise, $\\lambda = 0$).\nSince the number of dimensions of the dataset $N$ is fixed, $\\alpha = P / N$ is proportional to the number of examples $P$ used for the training.\nThe generalization error decreases for higher values of $\\alpha$, i.e. when the number of examples increases.\nIn other words, it seems to be the case:\n$$\\lim_{\\alpha \\to \\infty} \\bm{\\mathsf{w}} = \\bm{\\mathsf{w}}^{*}$$\n\nThe examples are distributed in all the space and the boundary between the classes is fixed and determined by the teacher vector $\\bm{\\mathsf{w}}^{*}$.\nIntuitively, for a higher number of examples $P$, the maximum margin between the $2$ classes decreases, since it is more likely that some example is really close to the boundary hyperplane determined by $\\bm{\\mathsf{w}}^{*}$.\nSince the MinOver algorithm tries to find some separation hyperplane, it is easier to get closer to the teacher vector $\\bm{\\mathsf{w}}^{*}$ if the maximum possible margin is smaller.\n\n\n\\subsection{MinOver vs Rosenblatt}\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/comparison}\n    \\caption{Generalization error for the MinOver and the Rosenblatt algorithms on a linearly separable dataset.}\n\t\\label{fig:comparison}\n\\end{figure}\n\n\\cref{fig:comparison} shows the generalization error of the perceptron trained with the MinOver and the Rosenblatt algorithms on a linearly separable dataset (without noise, $\\lambda = 0$).\nFor both algorithms the generalization error decreases with higher numbers of examples for the training (see the previous section).\nIn absence of noise, the performances of the $2$ algorithms are quite close, with MinOver performing slightly better than Rosenblatt for low values of $\\alpha$.\n\n\n\\subsection{Noise}\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/noise}\n    \\caption{Generalization error for the MinOver and the Rosenblatt algorithms on a noisy dataset. The dataset is generated starting from a linearly separable set of examples and swapping the labels of each example with probability $\\lambda$. The lines for $\\lambda = 0$ (no noise) are left as a reference.}\n\t\\label{fig:noise}\n\\end{figure}\n\n\\cref{fig:noise} shows the generalization error of the perceptron trained with the MinOver and the Rosenblatt algorithms on a noisy dataset.\nFor both algorithms, the generalization error increases with the noise $\\lambda$.\n\nThe error for the MinOver algorithm initially decreases by adding new examples, while it starts to increase again if the dataset gets bigger:\nthe algorithm diverges from the teacher vector $\\bm{\\mathsf{w}}^{*}$.\nThe more noise is present, the sooner the algorithm starts to diverge.\nAt each step, the algorithm selects the example with the lower stability $\\kappa^\\mu \\propto \\bm{\\mathsf{w}} \\cdotp \\xi^\\mu S^\\mu_R$:\nthis quantity is positive for correctly classified examples and negative for wrongly classified ones.\nIf there are misclassified examples, the MinOver algorithm chooses one of them to update the weights vector $\\bm{\\mathsf{w}}$.\nIf the dataset is non linearly separable, the MinOver algorithm stacks forever:\neach update can correct the classification for some point, but not for all of them;\nin the following epochs, only the misclassified examples cause updates and create new wrongly classified point.\nFor the way it is constructed, the probability that the dataset is not linearly separable is non-zero (for $\\lambda > 0$) and increases with $\\alpha$.\nFor $\\lambda = 0.3$, the algorithms has a generalization error of around $0.45$, very close to the error for a random guess.\nThe MinOver algorithm does not seem to be suitable for the classification of noisy data.\n\nThe Rosenblatt algorithm has similar performances, but it does not diverge when $\\alpha$ increases.\nIn other words, the Rosenblatt algorithm is up to a certain degree able to generalize even for noisy training data.\n", "meta": {"hexsha": "1fd8d4ef03b30aed0b0172324af151f2668067d6", "size": 4508, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_2/report/04_evaluation.tex", "max_stars_repo_name": "davidepedranz/neural_networks_assignments", "max_stars_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_2/report/04_evaluation.tex", "max_issues_repo_name": "davidepedranz/neural_networks_assignments", "max_issues_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_2/report/04_evaluation.tex", "max_forks_repo_name": "davidepedranz/neural_networks_assignments", "max_forks_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.3333333333, "max_line_length": 308, "alphanum_fraction": 0.7739574091, "num_tokens": 1086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7086473795583454}}
{"text": "\\documentclass{report}\r\n\r\n\\usepackage{amsmath}\r\n\\usepackage{graphicx}\r\n\r\n\r\n\\begin{document}\r\n\\chapter*{Oblique Spherical Triangles Toolbox}\r\n\\section*{Introduction}\r\n\r\nSpherical trigonometry is generally much more involved than its\r\nplain counterpart. A nice example of this is the seemingly simple\r\nspherical triangle (a triangle on a sphere). The usual laws for\r\nplain triangles no longer hold: the sum of the angles can easily\r\nexceed 180$^\\circ$, the Pythagorean theorem does not apply when\r\none of the angles is 90$^\\circ$, and so on.\r\n\r\nThe formulas to find quantities in spherical triangles are quite\r\ntedious. Their derivation is also not very trivial, which makes\r\nthem also harder to remember. For that reason, this little toolbox\r\nhas been created.\r\n\r\n\\begin{figure}[h!]\r\n         \\centering\r\n         \\includegraphics[bb=0 0 205 148]{OblSphTri.png}\r\n         \\caption{An arbitrary oblique spherical triangle.}\r\n         \\label{fig}\r\n\\end{figure}\r\n\r\nA general spherical triangle is shown in Figure \\ref{fig}. Note\r\nthat there are two angles associated with every ``corner'' of the\r\ntriangle. Also keep in mind that each ``side'' of a spherical\r\ntriangle is not a length, but an angle (with respect to the center\r\nof the sphere). Then, if 3 arbitrary quantities (angles, sides)\r\nare given and the other 3 quantities are to be found, 6 different\r\nsub-problems can be identified. These can be defined as\r\nfollows:\r\n\r\n\\begin{table}[h!]\r\n  \\centering\r\n  \\caption{The 6 categories of oblique spherical triangles.\r\n  Adapted from Table~A-1 in~\\cite{Wertz2001}}\r\n  \\label{table}\r\n  \\begin{tabular}{|c||c|c|c|}\\hline\r\n         \\textbf{Type}   & \\textbf{Given} & \\textbf{Find} &\r\n         \\textbf{No. of Solutions}\\\\\\hline\r\n         Side-Side-Side  & a, b, c & A, B, C & 0 or 2\\\\\r\n         Side-Side-Angle & a, b, A & B, C, c & 0 or 2\\\\\r\n         Side-Angle-Side & a, C, b & A, B, c & 2\\\\\r\n         Angle-Angle-Side & A, B, a & b, c, C & 0 or 2\\\\\r\n         Angle-Side-Angle & A, c, B & a, C, b & 2\\\\\r\n         Angle-Angle-Angle & A, B, C & a, b, c & 0 or 2\\\\\\hline\r\n  \\end{tabular}\r\n\\end{table}\r\n\r\nAll these problems involve rather long equations which will not be\r\nrepeated here. The interested reader is referred to Appendix A of\r\n\\cite{Wertz2001}, or similar standard works on spherical\r\ntrigonometry.\r\n\r\n\\cite{Wertz2001} uses a somewhat unconventional method to automate\r\nsolving these problems, namely the \\texttt{acos2}-function. Indeed\r\nit is the four-quadrant arccosine function, which is defined as\r\n\r\n\\[\r\n        \\text{acos2}(x) = H(x)\\cdot \\text{acos}(x),\r\n\\]\r\n\r\nwhere $H(x) = +1$ if $x < 180^\\circ$, and $H(x) = -1$ if $x >\r\n180^\\circ$. Defined like this, the \\texttt{acos2} function\r\ncompletely does away with the need of user intervention when\r\nsolving either of the 6 sub-problems, thus enabling full\r\nautomation.\r\n\r\n\\section*{The Toolbox}\r\nThis little toolbox is simply an implementation of all of the\r\nabove sub-problems. All functions are fully vectorized and should\r\nwork for vector or matrix input. The main components are:\r\n\r\n\\subsubsection{\\texttt{sss.m} and \\texttt{sssd.m}}\r\nUsage:\r\n\r\n\\[\r\n         \\texttt{[A1, B1, C1, A2, B2, C2] = sss(a, b, c)}\r\n\\]\r\n\r\nReturns both solutions to the Side-Side-Side problem. If no\r\nsolution exists, \\texttt{NaN} is returned. Uses the \\texttt{acos2}\r\nfunction. \\texttt{sss.m} uses radians, whereas \\texttt{sssd.m}\r\nuses degrees.\r\n\r\n\\subsubsection{\\texttt{ssa.m} and \\texttt{ssad.m}}\r\nUsage:\r\n\r\n\\[\r\n         \\texttt{[B1, C1, c1, B2, C2, c2] = ssa(a, b, A)}\r\n\\]\r\n\r\nReturns both solutions to the Side-Side-Angle problem. If no\r\nsolution exists, \\texttt{NaN} is returned. Uses the\r\nimplementations of the Middle Angle Law (\\texttt{mal.m}) and\r\nMiddle Side Law (\\texttt{msl.m}). \\texttt{ssa.m} uses radians,\r\nwhereas \\texttt{ssad.m} uses degrees.\r\n\r\n\\subsubsection{\\texttt{sas.m} and \\texttt{sasd.m}}\r\nUsage:\r\n\r\n\\[\r\n         \\texttt{[c1, A1, B1, c2, A2, B2] = sas(a, C, b)}\r\n\\]\r\n\r\nReturns both solutions to the Side-Angle-Side problem. Uses the\r\n\\texttt{acos2} function. \\texttt{sas.m} uses radians, whereas\r\n\\texttt{sasd.m} uses degrees.\r\n\r\n\\subsubsection{\\texttt{aas.m} and \\texttt{aasd.m}}\r\nUsage:\r\n\r\n\\[\r\n         \\texttt{[b1, c1, C1, b2, c2, C2] = aas(A, B, a)}\r\n\\]\r\n\r\nReturns both solutions to the Angle-Angle-Side problem. If no\r\nsolution exists, \\texttt{NaN} is returned. Uses the\r\nimplementations of the Middle Angle Law (\\texttt{mal.m}) and\r\nMiddle Side Law (\\texttt{msl.m}). \\texttt{aas.m} uses radians,\r\nwhereas \\texttt{aasd.m} uses degrees.\r\n\r\n\\subsubsection{\\texttt{asa.m} and \\texttt{asad.m}}\r\nUsage:\r\n\r\n\\[\r\n         \\texttt{[C1, a1, b1, C2, a2, b2] = asa(A, B, c)}\r\n\\]\r\n\r\nReturns both solutions to the Angle-Side-Angle problem. Uses the\r\n\\texttt{acos2} function. \\texttt{asa.m} uses radians, whereas\r\n\\texttt{asad.m} uses degrees.\r\n\r\n\\subsubsection{\\texttt{aaa.m} and \\texttt{aaad.m}}\r\nUsage:\r\n\r\n\\[\r\n         \\texttt{[a1, b1, c1, a2, b2, c2] = aaa(A, B, C)}\r\n\\]\r\n\r\nReturns both solutions to the Angle-Angle-Angle problem. If no\r\nsolution exists, \\texttt{NaN} is returned. Uses the \\texttt{acos2}\r\nfunction. \\texttt{aaa.m} uses radians, whereas \\texttt{aaad.m}\r\nuses degrees.\r\n\r\n\\section*{Auxiliary Functions}\r\nThese are included in the auxiliary folder. They are:\r\n\r\n\\subsubsection{\\texttt{mal.m} and \\texttt{mald.m}}\r\nThe implementation of the Middle-Angle Law for spherical\r\ntriangles:\r\n\r\n\\begin{eqnarray*}\r\n\\sin c &=& \\frac{\\sin a\\cos b\\cos B + \\sin b \\cos a \\cos A}\r\n{1-\\sin a \\sin b \\sin A \\sin B},\\\\\r\n\\cos c &=& \\frac{\\cos a\\cos b + \\sin a \\sin b \\cos A\\cos B}\r\n{1-\\sin a \\sin b \\sin A \\sin B},\\\\\r\nc &=& \\text{atan2}(\\sin c,\\,\\cos c).\r\n\\end{eqnarray*}\r\n\r\nThis function is used only internally. Instructions on how to use\r\nit manually are given in the help.\r\n\r\n\\subsubsection{\\texttt{msl.m} and \\texttt{msld.m}}\r\nThe implementation of the Middle-Side Law for spherical triangles:\r\n\r\n\\begin{eqnarray*}\r\n\\sin C &=& \\frac{\\sin A\\cos B\\cos b + \\sin B \\cos A \\cos a}\r\n{1-\\sin a \\sin b \\sin A \\sin B},\\\\\r\n\\cos C &=& \\frac{-\\cos A\\cos B + \\sin A \\sin B \\cos a\\cos b}\r\n{1-\\sin a \\sin b \\sin A \\sin B},\\\\\r\nc &=& \\text{atan2}(\\sin c,\\,\\cos c).\r\n\\end{eqnarray*}\r\n\r\nThis function is used only internally. Instructions on how to use\r\nit manually are given in the help.\r\n\r\n\\subsubsection{\\texttt{acos2.m}, \\texttt{acos2d.m}, \\texttt{H.m} and \\texttt{Hd.m}}\r\n\\texttt{H.m} and \\texttt{Hd.m} are the implementations of the\r\nHemisphere-function $H(x)$, which determines the sign of the\r\narccosine in \\texttt{acos2.m} or \\texttt{acos2d.m}.\r\n\r\nThis function is used only internally. Instructions on how to use\r\nit manually are given in the help.\r\n\r\n\\subsubsection{\\texttt{blkassign.m}}\r\nThis is a tool that prevents long blocks of assignments, when each\r\nvariable to be assigned is a column or row of a given matrix.\r\nNormally, this is done as\r\n\r\n\\begin{eqnarray*}\r\n    A &=& \\texttt{rand}(5);\\\\\r\n    a &=& A(:,\\,1);\\\\\r\n    b &=& A(:,\\,2);\\\\\r\n    c &=& A(:,\\,3);\\\\\r\n    &&\\text{etc.}\r\n\\end{eqnarray*}\r\n\r\nbut with \\texttt{blkassign.m}, this can be shortened as\r\n\r\n\\begin{eqnarray*}\r\n    A &=& \\texttt{rand}(5);\\\\\r\n    \\left[a,\\,b,\\,c,\\,\\dots\\right] &=& \\texttt{blkassign}(A);\\\\\r\n\\end{eqnarray*}\r\n\r\nAlso this function is used internally only. Instructions on how to\r\nuse it manually are given in the help.\r\n\r\n\\bibliographystyle{plainnat}\r\n\\bibliography{bibliography}\r\n\\end{document}\r\n", "meta": {"hexsha": "cef0646eae2a6e2b2b46870b7783a24ffc5f90cf", "size": 7334, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/readme.tex", "max_stars_repo_name": "rodyo/FEX-SphericalTriangle", "max_stars_repo_head_hexsha": "9c89b4beeac978c1fc180e2bf89b29731c683722", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/readme.tex", "max_issues_repo_name": "rodyo/FEX-SphericalTriangle", "max_issues_repo_head_hexsha": "9c89b4beeac978c1fc180e2bf89b29731c683722", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/readme.tex", "max_forks_repo_name": "rodyo/FEX-SphericalTriangle", "max_forks_repo_head_hexsha": "9c89b4beeac978c1fc180e2bf89b29731c683722", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.6422018349, "max_line_length": 84, "alphanum_fraction": 0.6689391873, "num_tokens": 2319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199471193039, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7085782547244185}}
{"text": "\\section{The Cross Product}\\label{sec:3Dcrossproduct}\n\nSuppose we are given two vectors. In many cases it is useful to find a third vector\nperpendicular to the first two. There are of course an infinite number\nof such vectors of different lengths. Nevertheless, let us find one.\nSuppose $\\vect{v}=\\langle v_1,v_2,v_3\\rangle$ and $\\vect{w}=\\langle w_1,w_2,w_3\\rangle$. We want\nto find a vector $\\vect{c} = \\langle c_1,c_2,c_3\\rangle$ with\n$\\vect{c}\\cdot\\vect{v}=\\vect{c}\\cdot\\vect{ w}=0$, or\n\\begin{align*}\n  v_1c_1+v_2c_2+v_3c_3&=0,\t\\\\\n  w_1c_1+w_2c_2+w_3c_3&=0.\n\\end{align*}\nMultiply the first equation by $w_3$ and the second by $v_3$ and\nsubtract to get\n\\begin{align*}\n  w_3v_1c_1+w_3v_2c_2+w_3v_3c_3&=0\t\\\\\n  v_3w_1c_1+v_3w_2c_2+v_3w_3c_3&=0\t\\\\\n  (v_1w_3-w_1v_3)c_1 + (v_2w_3-w_2v_3)c_2&=0\n\\end{align*}\nOf course, this equation in two variables has many solutions; a\nparticularly easy one to see is $c_1=v_2w_3-w_2v_3$,\n$c_2=w_1v_3-v_1w_3$. Substituting back into either of the original\nequations and solving for $ c_3$ gives $c_3=v_1w_2-w_1v_2$.\n\nThis particular answer to the problem turns out to have some nice\nproperties, and it is dignified with a name: the \n\\dfont{cross product}\\index{cross product}:\n$$\n  \\vect{v}\\times\\vect{w} = \\langle\n  v_2w_3-w_2v_3,w_1v_3-v_1w_3,v_1w_2-w_1v_2\\rangle.\n$$\nWhile there is a nice pattern to this vector, it can be a bit\ndifficult to memorize;  here is a convenient mnemonic.\nThe determinant of a two by two matrix is\n\\[\\left|\n\\begin{matrix}\na & b\t\\\\\nc & d\n\\end{matrix}\n\\right|=ad-cb.\\]\nThis is extended to the determinant of a three by three matrix:\n\\begin{align*}\n  \\left|\n  \\begin{matrix}\n  x\t&\ty\t&\tz\t\\\\\n  v_1\t&\tv_2\t&\tv_3\t\\\\\n  w_1\t&\tw_2\t&\tw_3\n  \\end{matrix}\\right|\n  &=x\\left|\n  \\begin{matrix}\n  v_2\t&\tv_3\t\\\\\n  w_2\t&\tw_3\n  \\end{matrix}\n  \\right|\n  -y\\left|\n  \\begin{matrix}\n  v_1\t&\tv_3\t\\\\\n  w_1\t&\tw_3\n  \\end{matrix}\n  \\right|\n  +z\\left|\n  \\begin{matrix}\n  v_1\t&\tv_2\t\\\\\n  w_1\t&\tw_2\n  \\end{matrix}\n  \\right|\t\\\\\n  &=x(v_2w_3-w_2v_3)-y(v_1w_3-w_1v_3)+z(v_1w_2-w_1v_2)\t\\\\\n  &=x(v_2w_3-w_2v_3)+y(w_1v_3-v_1w_3)+z(v_1w_2-w_1v_2).\n\\end{align*}\nEach of the two by two matrices is formed by deleting the top row and\none column of the three by three matrix; the subtraction of the middle\nterm must also be memorized. This is not the place to extol the uses\nof the determinant; suffice it to say that determinants are\nextraordinarily useful and important. Here we want to use it merely as\na mnemonic device. You will have noticed that the three expressions in\nparentheses on the last line are precisely the three coordinates of\nthe cross product; replacing $x$, $y$, $z$ by $\\vect{i}$, $\\vect{j}$, $\\vect{k}$ gives us\n\\begin{align*}\n  \\left|\n  \\begin{matrix}\n  \\vect{i}\t&\t\\vect{j}\t&\t\\vect{k}\t\\\\\n  v_1\t&\tv_2\t&\tv_3\t\\\\\n  w_1\t&\tw_2\t&\tw_3\n  \\end{matrix}\n  \\right|\n  &=(v_2w_3-w_2v_3)\\vect{i}-(v_1w_3-w_1v_3)\\vect{j}+(v_1w_2-w_1v_2)\\vect{k}\t\\\\\n  &=(v_2w_3-w_2v_3)\\vect{i}+(w_1v_3-v_1w_3)\\vect{j}+(v_1w_2-w_1v_2)\\vect{k}\t\\\\\n  &=\\langle v_2w_3-w_2v_3,w_1v_3-v_1w_3,v_1w_2-w_1v_2\\rangle\t\\\\\n  &=\\vect{v}\\times\\vect{w}.\n\\end{align*}\n\nGiven $\\vect{v}$ and $\\vect{w}$, there are typically two possible directions and an\ninfinite number of magnitudes that will give a vector perpendicular to\nboth $\\vect{v}$ and $\\vect{w}$. As we have picked a particular one, we\nshould investigate the magnitude and direction.\n\nWe know how to compute the magnitude of $\\vect{v}\\times\\vect{w}$; it's a\nbit messy but not difficult. It is somewhat easier to work initially\nwith the square of the magnitude, so as to avoid the square root:\n\\begin{align*}\n  |\\vect{v}\\times \\vect{w}|^2&=\n  (v_2w_3-w_2v_3)^2+(w_1v_3-v_1w_3)^2+(v_1w_2-w_1v_2)^2\t\\\\\n  &=v_2^2w_3^2-2v_2w_3w_2v_3+w_2^2v_3^2+w_1^2v_3^2-2w_1v_3v_1w_3+v_1^2w_3^2+v_1^2w_2^2-2v_1w_2w_1v_2+w_1^2v_2^2\n\\end{align*}\nWhile it is far from obvious, this nasty looking expression can be\nsimplified: \n\\begin{align*}\n  |\\vect{v}\\times\\vect{w}|^2&=\n  (v_1^2+v_2^2+v_3^2)(w_1^2+w_2^2+w_3^2)-(v_1w_1+v_2w_2+v_3w_3)^2\t\\\\\n  &=|\\vect{v}|^2|\\vect{w}|^2-(\\vect{v}\\cdot\\vect{w})^2\t\\\\\n  &=|\\vect{v}|^2|\\vect{w}|^2-|\\vect{v}|^2|\\vect{w}|^2\\cos^2\\theta\t\\\\\n  &=|\\vect{v}|^2|\\vect{w}|^2(1-\\cos^2\\theta)\t\\\\\n  &=|\\vect{v}|^2|\\vect{w}|^2\\sin^2\\theta\t\\\\\n  |\\vect{v}\\times\\vect{w}|&=|\\vect{v}||\\vect{w}|\\sin\\theta\n\\end{align*}\nThe magnitude of $\\vect{v}\\times\\vect{w}$ is thus very similar to the dot\nproduct. In particular, notice that if $\\vect{v}$ is parallel to $\\vect{w}$,\nthe angle between them is zero, so $\\sin\\theta=0$, so \n$|\\vect{v}\\times\\vect{w}|=0$, and likewise if they are anti-parallel, \n$\\sin\\theta=0$, and\n$|\\vect{v}\\times\\vect{w}|=0$. Conversely, if $|\\vect{v}\\times\\vect{w}|=0$\nand $|\\vect{v}|$ and $|\\vect{w}|$ are not zero, it must be that\n$\\sin\\theta=0$, so $\\vect{v}$ is parallel or anti-parallel to $\\vect{w}$. \n\n\\label{page:parallelogram area} Here is a curious fact about this\nquantity that turns out to be quite useful later on: Given two\nvectors, we can put them tail to tail and form a\nparallelogram, as in Figure~\\ref{fig:area of parallelogram}. The\nheight of the parallelogram, $h$, is $|\\vect{v}|\\sin\\theta$, and the\nbase is $|\\vect{w}|$, so the area of the\nparallelogram is $|\\vect{v}||\\vect{w}|\\sin\\theta$, exactly the magnitude of $|\\vect{v}\\times\\vect{w}|$.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <6truemm,6truemm>\n\\setplotarea x from 0 to 7, y from 0 to 3\n\\arrow <4pt> [0.35, 1] from 0 0 to 5 0\n\\arrow <4pt> [0.35, 1] from 0 0 to 2 3\n\\setdashes\n\\plot 5 0 7 3 2 3 2 0 /\n\\put {$\\vect{v}$} [br] <-3pt,3pt> at 1 1.5\n\\put {$\\vect{w}$} [t] <0pt,-3pt> at 2.5 0\n\\put {$h$} [l] <3pt,0pt> at 2 1.5\n\\put {$\\theta$} [bl] <7pt,4pt> at 0 0\n\\endpicture}}\n\\caption{A parallelogram. \\label{fig:area of parallelogram}}\n\\end{figure}\n\nWhat about the direction of the cross product? Remarkably, there is a\nsimple rule that describes the direction. Let's look at a simple\nexample: Let $\\vect{v}=\\langle a,0,0\\rangle$, $\\vect{w}=\\langle \nb,c,0\\rangle$. If the vectors are placed with tails at the origin,\n$\\vect{v}$ lies along the $x$-axis and $\\vect{w}$ lies in the $x$-$y$ plane,\nso we know the cross product will point either up or down. The cross\nproduct is \n\\begin{align*}\n  \\vect{v}\\times \\vect{w}=\\left|\n  \\begin{matrix}\n  \\vect{i}\t&\t\\vect{j}\t&\t\\vect{k}\t\\\\\n  a\t&\t0\t&\t0\t\\\\\n  b\t&\tc\t&\t0\n  \\end{matrix}\n  \\right|\n  &=\\langle 0,0,ac\\rangle.\n\\end{align*}\nAs predicted, this is a vector pointing up or down, depending on the\nsign of $ac$. Suppose that $a>0$, so the sign depends only on $c$: if\n$c>0$, $ac>0$ and the vector points up; if $c<0$, the vector points\ndown. On the other hand, if $a<0$ and $c>0$, the vector points down,\nwhile if $a<0$ and $c<0$, the vector points up. Here is how to\ninterpret these facts with a single rule: Imagine rotating vector\n$\\vect{v}$ until it points in the same direction as $\\vect{w}$; there are\ntwo ways to do this---use the rotation that goes through the smaller\nangle. If $a>0$ and $c>0$, or $a<0$ and $c<0$, the rotation will be\ncounter-clockwise when viewed from above; in the other two cases, $\\vect{v}$ must be rotated clockwise to reach $\\vect{w}$. The rule is:\ncounter-clockwise means up, clockwise means down. If $\\vect{v}$ and $\\vect{w}$ are any vectors in the $x$-$y$ plane, the same rule applies---$\\vect{v}$ need not be parallel to the $x$-axis.\n\nAlthough it is somewhat difficult computationally to see how this\nplays out for any two starting vectors, the rule is essentially the\nsame. Place $\\vect{v}$ and $\\vect{w}$ tail to tail. The plane in which $\\vect{v}$ and $\\vect{w}$ lie may be viewed from two sides; view it from the side\nfor which $\\vect{v}$ must rotate counter-clockwise to reach $\\vect{w}$; then\nthe vector $\\vect{v}\\times\\vect{w}$ points toward you.\n\nThis rule is usually called the \\dfont{right hand rule}.\nImagine placing the heel of your right hand at the point where the tails are\njoined, so that your slightly curled fingers indicate the direction of\nrotation from $\\vect{v}$ to $\\vect{w}$. Then your thumb points in the\ndirection of the cross product $\\vect{v}\\times\\vect{w}$.\n\nOne immediate consequence of these facts is that \n$\\vect{v}\\times\\vect{w}\\not=\\vect{w}\\times\\vect{v}$, because the two\ncross products point in the opposite direction. On the other hand,\nsince \n$$\n  |\\vect{v}\\times\\vect{w}|=|\\vect{v}||\\vect{ w}|\\sin\\theta\n  =|\\vect{w}||\\vect{v}|\\sin\\theta=|\\vect{w}\\times\\vect{v}|,\n$$\nthe lengths of the two cross products are equal, so\nwe know that $\\vect{v}\\times\\vect{w}=-(\\vect{w}\\times\\vect{v})$.\n\nThe cross product has some familiar-looking properties that will be\nuseful later, so we list them here. As with the dot product, these can\nbe proved by performing the appropriate calculations on coordinates,\nafter which we may sometimes avoid such calculations by using the\nproperties. \n\n\\begin{theorem}{Cross Product Properties}{cross product properties}\nIf $\\vect{u}$, $\\vect{v}$, and $\\vect{w}$ are vectors and $a$ is a real\nnumber, then\n\\begin{enumerate}\n\t\\item\t$\\vect{u}\\times(\\vect{v}+\\vect{w}) = \n\t\\vect{u}\\times\\vect{v}+\\vect{u}\\times\\vect{w}$\n\t\\item\t$(\\vect{v}+\\vect{w})\\times\\vect{u} = \n\t\\vect{v}\\times\\vect{u}+\\vect{w}\\times\\vect{u}$\n\t\\item\t$(a\\vect{u})\\times\\vect{v}=a(\\vect{u}\\times\\vect{v})\n\t=\\vect{u}\\times(a\\vect{v})$\n\t\\item\t$\\vect{u}\\cdot(\\vect{v}\\times\\vect{w}) = \n\t(\\vect{u}\\times\\vect{v})\\cdot\\vect{w}$\n\t\\item\t$\\vect{u}\\times(\\vect{v}\\times\\vect{w}) =\n\t(\\vect{u}\\cdot\\vect{w})\\vect{v}-(\\vect{u}\\cdot\\vect{v})\\vect{w}$\n\\end{enumerate}\\index{cross product!properties}\n\\end{theorem}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:3Dcrossproduct}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nFind the cross product of $\\langle 1,1,1\\rangle$ and \n$\\langle 1,2,3\\rangle$. \n\\begin{sol}\n\t$\\langle 1,-2,1\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the cross product of $\\langle 1,0,2\\rangle$ and \n$\\langle -1,-2,4\\rangle$. \n\\begin{sol}\n\t$\\langle 4,-6,-2\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the cross product of $\\langle -2,1,3\\rangle$ and \n$\\langle 5,2,-1\\rangle$. \n\\begin{sol}\n\t$\\langle -7,13,-9\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the cross product of $\\langle 1,0,0\\rangle$ and \n$\\langle 0,0,1\\rangle$. \n\\begin{sol}\n\t$\\langle 0,-1,0\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nTwo vectors $\\vect{u}$ and $\\vect{v}$ are separated by an\nangle of $\\pi/6$, and $|\\vect{u}|=2$ and $|\\vect{v}|=3$. Find $|\\vect{u}\\times\\vect{v}|$.\n\\begin{sol}\n\t$3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nTwo vectors $\\vect{u}$ and $\\vect{v}$ are separated by an\nangle of $\\pi/4$, and $|\\vect{u}|=3$ and $|\\vect{v}|=7$. Find \n$|\\vect{u}\\times\\vect{v}|$.\n\\begin{sol}\n\t$21\\sqrt2/2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area of the parallelogram with vertices $(0,0)$, $(1,2)$,\n$(3,7)$, and $(2,5)$.\n\\begin{sol}\n\t$1$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind and explain the value of $(\\vect{i} \\times \\vect{j})\n\\times \\vect{k}$ and $(\\vect{i} + \\vect{j}) \\times (\\vect{i} - \\vect{j})$.\n\\end{ex}\n\n\\begin{ex}\nProve that for all vectors $\\vect{u}$ and $\\vect{v}$,\n$(\\vect{u}\\times\\vect{v})\\cdot\\vect{v}=0$.\n\\end{ex}\n\n\\begin{ex}\nProve Theorem~\\ref{thm:cross product properties}.\n\\end{ex}\n\n\\begin{ex}\nDefine the triple product of three vectors, $\\vect{x}$,\n$\\vect{y}$, and $\\vect{z}$, to be the scalar $\\vect{x} \\cdot (\\vect{y} \\times\n\\vect{z})$.  Show that three vectors lie in the same plane if and only if\ntheir triple product is zero. Verify that $\\langle 1, 5, -2 \\rangle$,\n$\\langle 4, 3, 0 \\rangle$ and $\\langle 6, 13, -4 \\rangle$ all lie in the same plane.\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "d2058c0bfb2d034f965fc24258ae8d9cfb55b432", "size": 11539, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "12-three-dimensions/12-4-cross-product.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "12-three-dimensions/12-4-cross-product.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "12-three-dimensions/12-4-cross-product.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.8658146965, "max_line_length": 189, "alphanum_fraction": 0.6772683941, "num_tokens": 4488, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835248143777, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7084630884884671}}
{"text": "\\chapter{Construction of $\\Cp$}\n\t\\section{Ultrametric spaces}\n\t\t\\label{section:ultrametrics}\n\t\tIn this section we'll explore some useful properties of ultrametric spaces. \n\t\t\\begin{defn}\n\t\t\tAn \\emph{ultrametric space} is a metric space $(X, d)$ where \n\t\t\t\\[\n\t\t\td(x ,y) \\leq \\max\\left\\{d(x, z), d(z, y)\\right\\}\n\t\t\t\\]\n\t\t\tfor every $x, y, z \\in X$.\n\t\t\\end{defn}\n\t\tIn these section, to avoid confusion, we'll use different names for open and closed balls:\n\t\t\\begin{itemize}\n\t\t\t\\item $B_{< r}(a)$ is a \\textit{stripped ball};\n\t\t\t\\item $B_{\\leq r}(a)$ is a \\textit{dressed ball}.\n\t\t\\end{itemize}\n\t\t\n\t\t\\begin{prop}\n\t\t\tLet $(X, d)$ be an ultrametric space. The following properties hold:\n\t\t\t\\begin{enumerate}[label=(\\roman*)]\n\t\t\t\t\\item any point of a ball is a center;\n\t\t\t\t\\item ff two balls have a common point, one is contained in the other;\n\t\t\t\t\\item the diameter of a ball is less or equal than its radius.\n\t\t\t\\end{enumerate}\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\t\\textit{(i)} If $b \\in B_{<r}(a)$ then $d(a, b) < r$  and we have\n\t\t\t\\begin{gather*}\n\t\t\t\tx \\in B_{< r}(a) \\implies d(x, a) < r \\implies d(x, b) \\leq \\max \\{d(x, a), d(a, b) \\} < r \\\\\n\t\t\t\t\\implies x \\in B_{<r}(b)\n\t\t\t\\end{gather*}\n\t\t\twhich implies $B_{< r}(a) \\subseteq B_{< r}(b)$. Exchanging the roles of $a$ and $b$ we obtain $B_{< r}(a) = B_{< r}(b)$. The result for dressed balls is identical.\n\t\t\t\n\t\t\t\\textit{(ii)} If $c = B_{< r}(a) \\cap B_{\\leq r'}(b)$ then we have $B_{< r}(a) = B_{< r}(c)$ and $B_{\\leq r'}(b) = B_{\\leq r'}(c)$, by \\textit{(i)}. Now the result is obvious.\n\t\t\t\n\t\t\t\\textit{(iii)} Direct application of the ultrametric inequality.\n\t\t\\end{proof}\n\t\tLet $S_r(a) := \\{x \\in X \\mid d(x, a) = r \\}$ be the sphere of radius $r$ centered in $a$.  \n\t\t\\begin{prop}\n\t\t\t\\label{prop:spheres}\n\t\t\tLet $(X, d)$ be an ultrametric space. The following properties hold:\n\t\t\t\\begin{enumerate}[label=(\\roman*)]\n\t\t\t\t\\item if $d(x, z) > d(z, y)$ then $d(x, y) = d(x, z)$;\n\t\t\t\t\\item if $x \\in S_r(a)$ then $B_{< r}(x) \\subset S_r(a)$ and $S_r(a) = \\bigcup_{x \\in S_r(a)} B_{< r}(x)$. \n\t\t\t\\end{enumerate}\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\t\\textit{(i)} We have \n\t\t\t\\begin{gather*}\n\t\t\t\td(x, y) \\leq \\max \\{d(x, z), d(z, y) \\} = d(x, z) \\\\\n\t\t\t\td(x, z) \\leq \\max \\{d(x, y), d(y, z) \\} \\leq d(x, z)\n\t\t\t\\end{gather*}\n\t\t\tso $\\max \\{d(x, y), d(y,z)\\} = d(x, z)$ which implies $d(x, y) = d(x, z)$.\n\t\t\tThis property is well known as the \\emph{isosceles triangle principle}, i.e. every triangle of an ultrametric space is isosceles, with at most one short side.\n\t\t\t\n\t\t\t\\textit{(ii)} We need to prove that $y \\in B_{< r}(x) \\implies d(a, y) = r$. By \\textit{(i)}, since $d(x, y) < d(a, x) = r$, we must have $d(y, a) = d(a, x)= r$. The second part of the statement is obvious.\n\t\t\\end{proof}\n\t\tWe can give a slightly more general version of the isosceles triangle principle. Let $x_1, \\dots,x_n \\in X$, $x_{n+1} := x_1$ and assume $d(x_1, x_n) = \\max_{1 \\leq i \\leq n} d(x_i, x_{i+1})$. Applying the ultrametric inequality (with a rapid induction) we obtain\n\t\t\\begin{gather*}\n\t\t\td(x_1, x_n) \\leq \\max \\left\\{d(x_1, x_2), \\dots, d(x_{n-1}, x_n) \\right\\} = d(x_1, x_n)\n\t\t\\end{gather*}\n\t\tso there exists $i \\in \\{1, \\dots, n-1\\}$ such that $d(x_i, x_{i+1}) = d(x_1, x_n)$. \n\t\tWe have proved that given a cycle of length $n$ there are always at least two pairs of elements with equal maximal distance.\n\t\t\n\t\tWith the next lemma we'll understand why it is a better choice to use a different nomenclature for balls.\n\t\t\\begin{prop}\n\t\t\tLet $(X, d)$ be an ultrametric space. The following properties hold:\n\t\t\t\\begin{enumerate}[label=(\\roman*)]\n\t\t\t\t\\item the spheres $S_r(a)$ are clopen for every $a \\in X, r > 0$;\n\t\t\t\t\\item the dressed balls are open (and closed);\n\t\t\t\t\\item the stripped balls are closed (and open);\n\t\t\t\t\\item if $B$ and $B'$ are disjoint balls then $d(B, B') = d(x, x')$ for every $x \\in B, x' \\in B'$.\n\t\t\t\\end{enumerate}\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\t\\textit{(i)} Since the function $x \\mapsto d(x, a)$ is continuous, $S_r(a)$ is closed. By \\cref{prop:spheres} $S_r(a)$ is also open (union of stripped balls, which are trivially open).\n\t\t\t\n\t\t\t\\textit{(ii)} If $r > 0$ we have $B_{\\leq r}(a) = B_{<r}(a) \\sqcup S_r(a)$ so $B_{\\leq r}(a)$ is open.\n\t\t\t\n\t\t\t\\textit{(iii)} If $r > 0$ we have $B_{<r}(a) = B_{\\leq r}(a) \\setminus S_r(a)$ so $B_{<r}(a)$ is closed (intersection of closed sets).\n\t\t\t\n\t\t\t\\textit{(iv)} Given $x, y \\in B$ and $x', y' \\in B'$ we can consider the $4$-cycle $x, x', y', y$: there must be two pairs with equal maximal distance. Since $B \\cap B' = \\emptyset$, such distance is $c := d(x, x') = d(y, y')$ and $d(B, B') = \\inf_{a \\in B, b \\in B'} d(a, b) = c$.\n\t\t\\end{proof}\n\t\t\\begin{lemma}\n\t\t\t\\label{lemma:cauchy-sequence-ultrametric}\n\t\t\tLet $(X, d)$ be an ultrametric space. The following properties hold:\n\t\t\t\\begin{enumerate}[label=(\\roman*)]\n\t\t\t\t\\item $(x_n)_{n \\in \\N} \\subseteq X$ is Cauchy if (and only if) $d(x_n, x_{n+1}) \\to 0$ as $n \\to +\\infty$;\n\t\t\t\t\\item if $x_n \\to x \\neq a$ then $\\exists N \\in \\N$ such that $d(x_n, a) = d(x, a)$ for every $n \\geq N$.\n\t\t\t\\end{enumerate} \n\t\t\\end{lemma}\t \n\t\t\\begin{proof}\n\t\t\t\\textit{(i)} Fixed $\\varepsilon > 0$ if $d(x_n, x_{n+1}) < \\varepsilon$ for $n \\geq N$ then\n\t\t\t\\begin{gather*}\n\t\t\td(x_n, x_{n+m}) \\leq \\max_{0 \\leq i < m} d(x_{n+i}, x_{n+i+1}) < \\varepsilon\n\t\t\t\\end{gather*}\n\t\t\tfor all $n \\geq N$ and $m \\geq 0$.\n\t\t\t\n\t\t\t\\textit{(ii)} As soon as $d(x_n, x) < d(x, a)$ we have, by the isosceles triangle principle, $d(x_n, a) = d(x, a)$.\n\t\t\\end{proof}\n\t\n\t\tThere are some more interesting properties if the space is an abelian (additive) group $G$ equipped with an \\emph{ultrametric norm}, i.e. a function $\\abs{\\ }\\colon G \\to \\R_{\\geq 0}$ satisfying:\n\t\t\\begin{itemize}\n\t\t\t\\item $\\abs{x} > 0 \\iff x \\neq 0$;\n\t\t\t\\item $\\abs{-x} = \\abs{x}$;\n\t\t\t\\item $\\abs{x + y} \\leq \\max \\{\\abs{x}, \\abs{y} \\}$.\n\t\t\\end{itemize}\n\t\tThese groups are called \\textit{abelian ultrametric groups}. Here we can consider finite sums and series and we will see that there are  simpler conditions for them to converge than in classic analysis.\n\t\t\\begin{prop}\n\t\t\t\\label{prop:competitivity}\n\t\t\tLet $G$ be an abelian ultrametric group. If $a_1 + a_2 + \\dots + a_n = 0$ then $\\exists i \\neq j$ such that $\\abs{a_i} = \\abs{a_j} = \\max_{1 \\leq h \\leq n} \\abs{a_h}$. This property is called \\emph{competitivity}.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tIt's just the group version of the generalized isosceles triangle principle.\n\t\t\\end{proof}\n\t\t\\begin{prop}\n\t\t\t\\label{prop:summable_families}\n\t\t\tLet $(a_n)_{n \\in \\N}$ a sequence in a complete ultrametric abelian group $G$. The series $\\sum_{n \\geq 0} a_n$ converges if and only if $\\lim_{n \\to +\\infty} a_n = 0$.\n\t\t\t\n\t\t\tIf $\\sum_{n \\geq 0} a_n$ converges and $s$ is its sum then\n\t\t\t\\begin{enumerate}[label=(\\roman*)]\n\t\t\t\t\\item for any bijection $\\sigma\\colon \\N \\to \\N$ we have $s = \\sum_{n \\geq 0} a_{\\sigma(n)}$,\n\t\t\t\t\\item for any partition $\\N = \\coprod_j I_j$ we have $s = \\sum_j \\left( \\sum_{i \\in I_j} a_i \\right)$.\n\t\t\t\\end{enumerate}\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tFor the first part the only if is trivial. To prove the converse let $s_n = \\sum_{0 \\leq i < n} a_i$. Since $G$ is complete we just need to show $(s_n)_{n \\in \\N}$ is Cauchy:\n\t\t\t\\begin{gather*}\n\t\t\t\t\\abs{s_{n+m} - s_n} = \\abs{a_n + \\dots + a_{n+m-1}} \\leq \\max\\left\\{\\abs{a_n}, \\dots, \\abs{a_{n+m-1}}\\right\\} \\to 0\n\t\t\t\\end{gather*} \n\t\t\tas $n, m \\to +\\infty$. \n\t\t\t\n\t\t\tThe proof of the second part is not so interesting and can be found at \\cite[75]{robert:padic-analysis}.\n\t\t\\end{proof}\n\t\tThis last result is much cleaner than the corresponding one in classical analysis: in an ultrametric group if a series converge we are free to exchange and group its terms without changing the sum, unlike in classical analysis, where there is distinction between absolutely convergent  and conditionally convergent series. Anyway, in both contexts, grouping terms of a divergent series can produce a convergent one.\n\t\t\n\t\tFrom now on we'll mainly work with \\textit{ultrametric fields}, fields equipped with an ultrametric norm. Some of these results will be generalizations of facts proved in Chapter 2 with regards to $\\Zp$ and $\\Qp$.\n\t\t\\begin{lemma}\n\t\t\tAll balls containing $0$ in an ultrametric field $K$ are additive subgroups. The dressed ball $B_{\\leq 1}(0)$ is a subring of $K$ and the balls $B_{\\leq r}(0)$ and $B_{< r}(0)$ (with $r < 1$) are ideals of $B_{\\leq 1}(0)$.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tAll these verifications are trivial using the ultrametric inequality.\n\t\t\\end{proof}\n\t\tLet $K$ be an ultrametric field and let\n\t\t\\begin{align*}\n\t\t\tA :=& B_{\\leq 1}(0) = \\{x \\in K \\mid \\abs{x} \\leq 1\\}, \\\\\n\t\t\tM :=& B_{<1}(0) = \\{x \\in K \\mid \\abs{x} < 1\\}.\n\t\t\\end{align*}\n\t\t\\begin{prop}\n\t\t\t\\label{prop:general-A-and-M}\n\t\t\t$A$ is a maximal subring of $K$ and $M$ is the unique maximal ideal of $A$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tIf $A'$ is a subring of $K$ such that $A \\subsetneq A'$, there exists $y \\in A'$ with $\\abs{y} = r > 1$, so $y^n \\in A'$ for every $n \\in \\N$. Hence $B_{\\leq r^n}(0) = y^nA \\subset A' \\text{ } \\forall n \\in \\N$ which implies $K = \\bigcup_{n \\geq 1} y^nA = A'$ since $r^n = \\abs{y}^n \\to +\\infty$. So $A$ is a maximal subring of $K$. To see why $M$ is the unique maximal ideal of $A$ we observe that $A = A^\\times \\sqcup M$, so every ideal which strictly contains $M$ is the whole ring $A$, because it must contain a unit.\n\t\t\\end{proof}\n\t\tWe note that $A$ is a local ring (by the previous proposition) and a valuation ring of $K$, since $x \\in A \\text{ } \\lor \\text{ }1/x \\in A$ for every $x \\in K^\\times$. An example we have already studied is $K = \\Qp$, $A = \\Zp$ and $M = p\\Zp$.\n\t\t\\begin{defn}\n\t\t\tLet $K$ be an ultrametric field, $A = B_{\\leq 1}(0)$, $M=B_{<1}(0)$. The quotient $k := A/M$ is the \\emph{residue field} of $K$.\n\t\t\\end{defn}\n\t\tFinally we are ready to prove the representation theorem.\n\t\t\\begin{thm}\n\t\t\t\\label{thm:representation-ultrametrics}\n\t\t\tLet $K$ be a complete ultrametric field, $A$ its maximal subring defined by $\\abs{x} \\leq 1$. If $\\xi \\in A$ with $\\abs{\\xi} < 1$ and $0 \\in S \\subset A$ is a set of representatives for the classes $A/\\xi A$, then every $x \\in K^\\times$ is a sum\n\t\t\t\\begin{gather*}\n\t\t\t\tx = \\sum_{i \\geq m} a_i \\xi^i \\quad (m \\in \\Z, a_i \\in S, a_m \\neq 0)\n\t\t\t\\end{gather*}\n\t\t\twith $m \\geq 0$ precisely when $x \\in A$. There's an isomorphism $A \\cong \\lim \\limits_{\\longleftarrow} A/\\xi^n A$ defined by $x \\mapsto (s_n)$ where $s_n = \\sum_{m \\leq i < n} a_i \\xi ^i$.\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tIf $x \\in A$ we can find a unique $a_0 \\in S$ such that $x - a_0 \\in \\xi A$, so we can write\n\t\t\t\\begin{gather*}\n\t\t\t\tx = a_0 + \\xi x_1 \\quad \\text(x_1 \\in A).\n\t\t\t\\end{gather*}\n\t\t\tBy induction we obtain\n\t\t\t\\begin{gather*}\n\t\t\t\tx = a_0 + a_1\\xi + a_2\\xi^2 + \\dots + \\xi^nx_n \\quad (a_i \\in S, x_n \\in A).\n\t\t\t\\end{gather*}\n\t\t\tUsing the same notation of the theorem we have $x = s_n + \\xi^nx_n$ and we immediately note that $(s_n)_n$ converges, because it is a Cauchy sequence since $\\abs{\\xi^nx_n} \\leq \\abs{\\xi}^n \\to 0$ as $n \\to +\\infty$. It can be easily checked that $s_n \\to x$, so $x = \\sum_{i \\geq 0} a_i\\xi^i$. Since for every $x \\in K^\\times$ there exists $k \\in \\Z$ such that $\\abs{\\xi^k x} \\leq 1$ we can repeat this reasoning for $x$ starting at index $i = k$. It's now easy to see that the ring morphism $A \\to \\lim \\limits_{\\longleftarrow} A/\\xi^n A$ is an isomorphism, since it is clearly injective and surjective (by completeness of $K$).\n\t\t\\end{proof}\n\t\tIf $K$ is not complete we could anyway represent every $x \\in K$ as $x = \\sum_{i \\geq m} a_i\\xi^i$, but we would only have an injection $A \\hookrightarrow \\lim \\limits_{\\longleftarrow} A/\\xi^n A$. Applying this theorem to $K = \\Qp$, $A = \\Zp$ and $\\xi = p$ we obtain exactly how \\padic numbers are represented and the fact that $\\Zp \\cong \\lim \\limits_{\\longleftarrow} \\Zp/p^n \\Zp = \\lim \\limits_{\\longleftarrow} \\Z/p^n \\Z$.\n\t\\section{Extension of norms}\n\t\tLet $V$ be a vector space over the field $\\Qp$, equipped with a norm. For example $V = \\Qp$ with norm $\\norm{x} := c\\pabs{x}$ ($c > 0$) is a $\\Qp$-vector space; we immediately note that the set $\\set{\\norm{v} | v \\in V}$ can be different from the set of the absolute values of scalars (in this case $\\pabs{\\Qp} = p^\\Z \\cup \\{0\\}$). From now on, to have a lighter notation, we'll omit the pedix $p$ in the \\padic absolute value.\n\t\tWe recall that two norms $\\norm{\\ }, \\norm{\\ }'$ on a vector space are equivalent if we can find $0 < c \\leq C < +\\infty$ such that\n\t\t\\begin{gather*}\n\t\t\tc\\norm{x} \\leq \\norm{x}' \\leq C\\norm{x} \\quad \\forall x \\in V.\n\t\t\\end{gather*}\n\t\tNow we are ready to state and prove the following theorem.\n\t\t\\begin{thm}\n\t\t\t\\label{thm:equiv-norm-finite-dim}\n\t\t\tLet $V$ be a finite-dimensional $\\Qp$-vector space. Then all norms on $V$ are equivalent.\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tLet $n = \\dim V$ and $(e_i)_{1 \\leq i \\leq n}$ be a basis. It's clear that there is an isomorphism $\\varphi\\colon\\Qp^n \\xrightarrow{\\sim} V$ sending $(x_i)_{1 \\leq i \\leq n} \\mapsto \\sum_i x_ie_i$. We consider $\\Qp^n$ equipped with the sup-norm $\\norm{x}_{\\infty} := \\sup \\pabs{x_i}$. We only need to prove that $\\varphi$ is a homeomorphism. \\\\\n\t\t\tIt's easy to prove that $\\varphi$ is continuous:\n\t\t\t\\begin{gather*}\n\t\t\t\t\\norm{\\varphi(x)} = \\norm{\\sum x_ie_i} \\leq \\sum \\pabs{x_i}\\norm{e_i} \\leq \\max \\norm{e_i} \\cdot \\sum \\pabs{x_i} \\leq C\\norm{x}_{\\infty}\n\t\t\t\\end{gather*}\n\t\t\twhere $C := n \\cdot \\max \\norm{e_i}$ is a fixed constant. We'll conclude showing that $\\varphi$ is an open map (any continue invertible open map is a homeomorphism). Let $B := \\{x \\in \\Qp^n \\mid \\norm{x}_{\\infty} \\leq 1\\}$ be the unit ball in $\\Qp^n$: we have to show that $\\varphi(B)$ contains an open ball of positive radius centered in $0 \\in V$. We firstly note that $B \\subset \\Qp^n$ is a compact set: it's possible to extract a convergent subsequence from any sequence, exploiting the fact that $(\\Qp, \\pabs{\\ })$ is a locally compact field. Let's consider the unit sphere in $\\Qp^n$:\n\t\t\t\\begin{gather*}\n\t\t\t\tS_1 := \\Set{x \\in \\Qp^n | \\norm{x}_{\\infty} = 1}.\n\t\t\t\\end{gather*}\n\t\t\tThis is a closed subset of $B$ and, since $B$ is compact, $S_1$ is a compact set hence $\\varphi(S_1)$ is also compact. Since $\\varphi$ is bijective we have $0 \\notin \\varphi(S_1)$ so $0 < \\dist(\\{0\\}, \\varphi(S_1))$ and, by Weierstrass theorem, we find a point $\\varphi(x_0)$ such that\n\t\t\t\\begin{gather*}\n\t\t\t\tx \\in S_1 \\implies \\norm{\\varphi(x)} \\geq \\norm{\\varphi(x_0)} = \\varepsilon > 0.\n\t\t\t\\end{gather*}\n\t\t\tLet $v \\in V \\setminus \\{0\\}$ and observe that\n\t\t\t\\begin{gather*}\n\t\t\t\t\\norm{v} < \\epsilon, \\lambda \\in \\Qp, \\pabs{\\lambda} \\leq 1 \\implies \\norm{\\lambda v} < \\epsilon \\implies \\lambda v \\notin \\phi(S_1).\n\t\t\t\\end{gather*}\n\t\t\tWe can write\n\t\t\t\\begin{gather*}\n\t\t\t\tv = \\sum_i v_ie_i = \\phi((v_i)_i).\n\t\t\t\\end{gather*}\n\t\t\tLet's assume without loss of generality that $0 \\neq \\pabs{v_n} = \\max\\,\\pabs{v_i} = \\norm{(v_i)_i}_{\\infty}$. If $\\lambda = 1/v_n$ then $\\lambda v = \\phi((v_i/v_n)_i) \\in \\phi(S_1)$ so it must be $\\pabs{\\lambda} > 1$ which implies\n\t\t\t\\begin{gather*}\n\t\t\t\t\\norm{(v_i)_i}_{\\infty} = \\pabs{v_n} = \\frac{1}{\\pabs{\\lambda}} < 1.\n\t\t\t\\end{gather*}\n\t\t\tThis shows that $v = \\phi((v_i)_i) \\in \\phi(B)$. We have just proved that $B_{< \\epsilon}(0, V) \\subseteq \\phi(B)$.\n\t\t\\end{proof}\n\t\tThis theorem can be generalized: it holds for any finite dimensional $F$-vector space, where $F$ is a locally compact field.\n\t\t\\begin{corollary}\n\t\t\tIf $V$ and $W$ are two finite-dimensional $\\Qp$-vector spaces and $\\alpha\\colon V \\to W$ is a linear map, then $\\alpha$ is continuous.\n\t\t\\end{corollary}\n\t\tThis is an analogue to the classic result on real or complex vectorial spaces of finite dimension. \n\t\t\n\t\tNow let's consider a finite extension $K/\\Qp$ and let's assume there is at least one absolute value on $K$ extending the \\padic absolute value of $\\Qp$. Then we can see $K$ as a $\\Qp$-vectorial space of finite dimension equipped with a norm (every such absolute value on $K$ is actually also a norm).\n\t\t\\begin{prop}\n\t\t\tThere is at most one absolute value on $K$ extending the \\padic one of $\\Qp$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tLet $\\abs{\\ }$ and $\\abs{\\ }'$ two such absolute values on $K$. By \\cref{thm:equiv-norm-finite-dim} they must be equivalent norms so there exist constants $0 < c \\leq C < \\infty$ such that\n\t\t\t\\begin{gather*}\n\t\t\t\tc\\abs{x} \\leq \\abs{x}' \\leq C\\abs{x} \\quad (x \\in K).\n\t\t\t\\end{gather*}\n\t\t\tReplacing $x^n$ with $x$ in the previous inequalities we obtain\n\t\t\t\\begin{gather*}\n\t\t\t\tc\\abs{x}^n \\leq \\abs{x}'^n \\leq C\\abs{x}^n \n\t\t\t\t\\implies c^{1/n}\\abs{x} \\leq \\abs{x}' \\leq C^{1/n}\\abs{x}.\n\t\t\t\\end{gather*}\n\t\t\tLetting $n \\to +\\infty$ we have $c^{1/n}, C^{1/n} \\to 1$ so $\\abs{x} = \\abs{x}'$.\n\t\t\\end{proof}\n\t\tWe now know that if $K/\\Qp$ is a finite extension and $K$ admits an absolute value extending the \\padic one, there can only be one such absolute value. Anyway, if $K/\\Qp$ is a generic finite extension we don't know if there is an absolute value on $K$ compatible with the \\padic one. The next theorem will give us an answer (yes, there always is such a field norm) and also a method to define this (unique) absolute value. First we quickly present two technical lemmas we'll need.\n\t\t\\begin{defn}\n\t\t\tA \\emph{generalized absolute value} on a field $K$ is a group morphism $f\\colon K^\\times \\to \\R_{> 0}$ extended by $f(0)=0$ which satisfies $f(x + y) \\leq C\\max \\{f(x), f(y)\\}$, where $C > 0$ is a fixed constant. If $C = 1$, $f$ is a classical ultrametric absolute value.\n\t\t\\end{defn}\n\t\t\\begin{lemma}\n\t\t\t\\label{lemma:generalized-absolute-value}\n\t\t\tLet $f$ be a generalized absolute value on a field $K$. If $f$ is bounded on $\\N$ (thought as a subset of $K$) then $f$ is an ultrametric absolute value.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tSee \\cite[88]{robert:padic-analysis}.\n\t\t\\end{proof}\n\t\t\\begin{lemma}\n\t\t\t\\label{lemma:locally-compact-vector}\n\t\t\tIf $V$ is a locally compact normed space over $\\Qp$ then its dimension is finite. In a locally compact normed $\\Qp$-vector space the compact subsets are the closed bounded subsets.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tSee \\cite[93]{robert:padic-analysis}.\n\t\t\\end{proof}\n\t\t\\begin{defn}\n\t\t\tLet $K/\\Qp$ be a finite extension, $\\alpha \\in K$ and $\\ell_{\\alpha}$ be the $\\Qp$-linear map $K \\to K: x \\mapsto \\alpha x$. We define the ``Norm''\\footnote{We'll write ``Norm'' to avoid confusion: we're talking about the field norm in field theory, not about an absolute value on $K$.} of $\\alpha$ on $K$ as\n\t\t\t\\[\n\t\t\t\t\\Nb_{K/\\Qp}(\\alpha) := \\det \\ell_{\\alpha}.\n\t\t\t\\]\n\t\t\\end{defn}\n\t\tNow we are ready to prove the following. Let's recall that $\\norm{K}=\\set{ \\norm{k} | k \\in K}$.\n\t\t\\begin{thm}\n\t\t\t\\label{thm:norm-extension}\n\t\t\tLet $K$ be a field extension of $\\Qp$ of degree $d < \\infty$. For each $x \\in K$ let $\\ell_x \\colon K \\to K$ the $\\Qp$-linear map $y \\mapsto xy$. Then\n\t\t\t\\begin{gather*}\n\t\t\t\tf(x) := \\pabs{\\Nb_{K/\\Qp}(x)}^{1/d} = \\pabs{\\det \\ell_x}^{1/d}\n\t\t\t\\end{gather*}\n\t\t\tdefines an absolute value on $K$ that extends the \\padic one. This is the unique such absolute value.\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tFirst of all it's clear that if $a \\in \\Qp$ then $\\pabs{\\Nb_{K/\\Qp}(a)}^{1/d} = \\pabs{a}$, so the formula correspond to the \\padic absolute value on $\\Qp$. It's also clear that $f(x) = 0 \\iff x = 0$ (every $y \\mapsto xy$ is invertible if $x \\neq 0$) and $f(x \\cdot y) = f(x) \\cdot f(y)$, thanks to the Binet's formula for $\\det$. We only need to check the ultrametric inequality. Let's choose any ultrametric norm $x \\mapsto \\norm{x}$ on $K$ such that $\\norm{K} = \\abs{\\Qp}$ (for example we could choose the sup-norm). Since $K$ is a $\\Qp$-vector space with $\\dim K = d$ we know, from \\cref{thm:equiv-norm-finite-dim}, that $K$ is homeomorphic to $(\\Qp^d, \\norm{\\ }_{\\infty})$ so it is locally compact. By \\cref{lemma:locally-compact-vector} we know that the unit sphere $S_1 = \\{x \\in K \\mid \\norm{x}=1 \\}$ is compact so the continuous function $f$, by Weierstrass theorem, is bounded on $S_1$, namely\n\t\t\t\\begin{gather*}\n\t\t\t\t0 < \\epsilon \\leq f(x) \\leq A < +\\infty \\quad (\\norm{x} = 1).\n\t\t\t\\end{gather*}\n\t\t\tFor $x \\in K^\\times$ we can find $\\lambda \\in \\Qp$ such that $\\norm{x/\\lambda} = 1$ so $\\epsilon \\leq f(x/\\lambda) \\leq A$. Since $f(x/\\lambda) = f(x)/\\pabs{\\lambda} = f(x) / \\norm{x}$ we get\n\t\t\t\\begin{gather*}\n\t\t\t\t\\epsilon \\norm{x} \\leq f(x) \\leq A\\norm{x} \\\\\n\t\t\t\t\\implies \\norm{x} \\leq \\epsilon^{-1}f(x), \\quad f(x) \\leq A\\norm{x} \\quad (x \\in K). \n\t\t\t\\end{gather*}\n\t\t\tIf $f(x) \\leq 1$ we have that $\\norm{x} \\leq \\epsilon^{-1}$ and\n\t\t\t\\begin{gather*}\n\t\t\t\tf(1 + x) \\leq A\\norm{1 + x} \\leq A\\max\\{\\norm{1}, \\norm{x}\\} \\leq \\\\\n\t\t\t\t\\leq A\\max\\{\\norm{1}, \\epsilon^{-1}\\} =: C\\cdot 1 = C\\max\\{f(1), f(x)\\}.\n\t\t\t\\end{gather*}\n\t\t\tMore generally, if $f(y) \\geq f(x)$ then $f(x/y) = f(x)/f(y) \\leq 1$ so we can apply our previous results. Multiplying both sides by $f(y)$ we obtain\n\t\t\t\\begin{gather*}\n\t\t\t\tf(x + y) \\leq C\\max\\{f(x), f(y)\\}.\n\t\t\t\\end{gather*}\n\t\t\tThis proves that $f$ is a generalized absolute value on $K$. Since $f$ is bounded on $\\N \\subset \\Qp \\subset K$, being an extension of the \\padic absolute value, by \\cref{lemma:generalized-absolute-value} we obtain that $f$ is an ultrametric absolute value.\n\t\t\\end{proof}\n\t\t\\begin{corollary}\n\t\t\t\\label{corollary:galois-isometric}\n\t\t\tLet $K/\\Qp$ be a finite Galois extension and $\\alpha \\in K$. Then the norm of $\\alpha$ equals the norm of each of his conjugates, i.e. Galois automorphisms are isometric.\n\t\t\\end{corollary}\n\t\t\\begin{proof}\n\t\t\tLet $\\alpha'$ be a conjugate of $\\alpha$ and $\\sigma$ a $\\Qp$-automorphism such that $\\sigma(\\alpha) = \\alpha'$ (from Galois theory we know it actually exists). Thanks to \\cref{thm:norm-extension}, we know there exists a unique \\padic norm $\\norm{\\ }$ on $K$. The map $\\norm{\\ }'\\colon K \\to \\R$ defined by $\\norm{x}' := \\norm{\\sigma(x)}$ is clearly a field norm on $K$ which extends $\\pabs{\\ }$. Hence $\\norm{\\ }' = \\norm{\\ }$ so $\\norm{\\alpha} = \\norm{\\alpha'}$.\n\t\t\\end{proof}\n\t\tWe have proved that for every finite extension $K/\\Qp$ there's a unique norm which extends the \\padic one. We'll now give a more practical method to calculate this norm. \n\t\t\\begin{prop}\n\t\t\tLet $K/\\Qp$ be a finite extension of degree $d$. Then \n\t\t\t\\[\n\t\t\t\t\\pabs{\\alpha} = \\pabs{a_n}^{1/n}\n\t\t\t\\]\n\t\t\twhere $\\alpha \\in K$ and $a_n \\in \\Qp$ is the constant term of the minimal polynomial of $\\alpha$ over $\\Qp$ (which has degree $n$).\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tFirst of all, let's consider the simple case where $K = \\Qp(\\alpha)$ (the smallest field containing $\\Qp$ and $\\alpha$), where the minimal polynomial of $\\alpha$ on $\\Qp$ is\n\t\t\t\\begin{equation*}\n\t\t\t\t\\lambda_{\\Qp}(\\alpha) = x^n + a_1x^{n-1} + \\dots + a_{n-1}x + a_n \\in \\Qp[X].\n\t\t\t\\end{equation*}\n\t\t\tIf we use $\\{1, \\alpha, \\alpha^2, \\dots, \\alpha^{n-1}\\}$ as a $\\Qp$-basis for $K$ then $\\ell_{\\alpha}$ has matrix\n\t\t\t\\[\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\t0 & 0 & 0 & \\dots & 0 & -a_n \\\\\n\t\t\t\t\t1 & 0 & 0 & \\dots & 0 & -a_{n-1} \\\\\n\t\t\t\t\t0 & 1 & 0 & \\dots & 0 &-a_{n-2} \\\\\n\t\t\t\t\t0 & 0 & 1 & \\dots & 0 & -a_{n-3} \\\\\n\t\t\t\t\t\\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots \\\\\n\t\t\t\t\t0 & 0 & 0 & \\dots & 1 & -a_1 \\\\\n\t\t\t\t\\end{pmatrix}\n\t\t\t\\]\n\t\t\twhere we used $\\alpha^n = -a_1\\alpha^{n-1} -a_2\\alpha^{n-2} - \\dots -a_{n-1}\\alpha -a_n$. It's easy to see that $\\det \\ell_{\\alpha} = (-1)^na_n$, expanding using the first row. If $x^n + a_1x^{n-1} + \\dots + a_{n-1}x + a_n = \\prod_{i=1}^n (x - \\alpha_i)$, where $\\alpha_i$ are the conjugates of $\\alpha = \\alpha_1$ in $\\Qp$, then $\\det \\ell_{\\alpha} = \\prod_{i=1}^n \\alpha_i$. \\newline\n\t\t\tNow let's consider an arbitrary element $\\beta \\in K$. It's immediate that\n\t\t\t\\[\n\t\t\t\t\\Nb_{K/\\Qp}(\\beta) = \\left( \\Nb_{\\Qp(\\beta)/\\Qp}(\\beta) \\right)^{[K : \\Qp(\\beta)]}\n\t\t\t\\]  \n\t\t\tbecause if we consider $\\Qp \\leq \\Qp(\\beta) \\leq K$ and we first choose a basis for $\\Qp(\\beta)$ over $\\Qp$ and then a basis for $K$ over $\\Qp(\\beta)$, we can then take all products of elements of these two basis and obtain a basis for $K$ over $\\Qp$ (this is exactly the idea used to prove $[K : \\Qp] = [K : \\Qp(\\beta)]\\cdot [\\Qp(\\beta):\\Qp]$). In this basis the matrix of $\\ell_\\beta$ has form\n\t\t\t\\[\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\tA_{\\beta} & 0         & & & \\\\\n\t\t\t\t\t0         & A_{\\beta} & & & \\\\\n\t\t\t\t\t\t\t  & \t\t  & \\ddots & & \\\\\n\t\t\t\t\t\t\t  & \t\t  &  \t   & A_{\\beta} \\\\\n\t\t\t\t\\end{pmatrix}\n\t\t\t\\]\n\t\t\twhere $A_{\\beta}$ is the matrix of the multiplication by $\\beta$ in $\\Qp(\\beta)$. The determinant of this matrix is clearly $(\\det A_{\\beta})^{[K:\\Qp(\\beta)]}$, since there are exactly $[K:\\Qp(\\beta)]$ blocks. Finally, if $\\alpha \\in K$ has minimal polynomial $\\lambda_{\\Qp}(\\alpha) = x^n + \\dots + a_{n-1}x + a_0$ we obtain\n\t\t\t\\[\n\t\t\t\t\\pabs{\\alpha} = \\pabs{\\Nb_{K/\\Qp}(\\alpha)}^{1/d} = \\pabs{\\Nb_{\\Qp(\\alpha)/\\Qp}(\\alpha)}^{[K:\\Qp(\\alpha)]/d} = \\pabs{\\Nb_{\\Qp(\\alpha)/\\Qp}(\\alpha)}^{1/n} = \\pabs{a_n}^{1/n}\n\t\t\t\\]\n\t\t\twhere we used $d = [K:\\Qp(\\alpha)] \\cdot n$.\n\t\t\\end{proof}\n\t\\section{Field extensions of $\\Qp$}\n\t\t\\begin{defn}\n\t\t\tLet $K/\\Qp$ be a finite extension. The set \n\t\t\t\\[\n\t\t\t\tA := \\{\\alpha \\in K \\mid \\exists (a_i) \\subset \\Zp \\text{ such that } \\alpha^n + a_1\\alpha^{n-1} + \\dots + a_{n-1}\\alpha + a_n = 0 \\}\n\t\t\t\\]\n\t\t\tis called the \\emph{integral closure} of $\\Zp$ in $K$.\n\t\t\\end{defn}\n\t\tIt can be shown that if $\\alpha \\in A$ then its minimal polynomial over $\\Qp$ has the above form, i.e. coefficients in $\\Zp$. Moreover, the integral closure is always a ring. We'll prove it only in our special case.\n\t\t\\begin{prop}\n\t\t\t\\label{prop:finite-extension-A-integral-closure-Zp}\n\t\t\tLet $K/\\Qp$ be a finite extension of degree $n$ and let\n\t\t\t\\begin{gather*}\n\t\t\t\tA = \\{x \\in K \\mid \\pabs{x} \\leq 1\\}, \\\\\n\t\t\t\tM = \\{x \\in K \\mid \\pabs{x} < 1\\}.\n\t\t\t\\end{gather*}\n\t\t\tThen $A$ is a ring, which is exactly the integral closure of $\\Zp$ in $K$. $M$ is the maximal ideal of $A$ and $A/M$ is a finite extension of $\\Fp$ of degree at most $n$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tThanks to \\cref{thm:norm-extension} we know that there exists a \\padic absolute value on $K$, which makes it an ultrametric field. Then we can apply \\cref{prop:general-A-and-M}, which states that $A$ is the maximal subring of $K$ and $M$ is its maximal ideal. \\newline\n\t\t\tNow let $\\alpha \\in K$ have degree $m$ over $\\Qp$ and suppose it is integral over $\\Zp$, i.e. \n\t\t\t\\[\n\t\t\t\t\\alpha^m + a_1\\alpha^{m-1} + \\dots a_{m-1}\\alpha + a_m = 0 \\quad (a_i \\in \\Zp).\n\t\t\t\\]\n\t\t\tIf $\\pabs{\\alpha} > 1$ then we would have \n\t\t\t\\[\n\t\t\t\t\\pabs{\\alpha}^m = \\pabs{a_1\\alpha^{m-1} + \\dots + a_m} \\leq \\max_{1 \\leq i \\leq m} \\pabs{a_i\\alpha^{m-i}} \\leq \\max_{1 \\leq i \\leq m} \\pabs{\\alpha^{m-i}} = \\pabs{\\alpha}^{m-1}\n\t\t\t\\]\n\t\t\twhich is a contradiction. Conversely, let $\\alpha \\in K$ with $\\pabs{\\alpha} \\leq 1$. Then, thanks to \\cref{corollary:galois-isometric}, all the conjugates of $\\alpha = \\alpha_1$ over $\\Qp$ have the same norm\n\t\t\t\\[\n\t\t\t\t\\pabs{\\alpha_i} = \\prod_{j=1}^m \\pabs{\\alpha_j}^{1/m} = \\pabs{\\alpha} \\leq 1.\n\t\t\t\\]\n\t\t\tSince all coefficients in $\\lambda_{\\Qp}(\\alpha) \\in \\Qp[X]$ are sums or differences of products of $\\alpha_i$ (more exactly they're the symmetric polynomials evaluated in $(\\alpha_i)$) it follows that they also have $\\pabs{\\ } \\leq 1$ so they're in $\\Zp$. We have proved that $A$ is exactly the integral closure of $\\Zp$ in $K$. \\newline\n\t\t\tTo prove that $A/M$ is a finite extension of $\\Fp$ let's consider the map\n\t\t\t\\[\n\t\t\t\t\\Zp/p\\Zp \\to A/M: a + p\\Zp \\mapsto a + M \\quad (a \\in \\Zp).\n\t\t\t\\]\n\t\t\tIt's well defined, since if $a - b \\in p\\Zp \\subset M$ then $a - b \\in M$ so $a + M = b + M$. It is also injective, thanks to the fact that $M \\cap \\Zp = p\\Zp$. Then we have an inclusion $\\Fp \\cong \\Zp/p\\Zp \\hookrightarrow A/M$, which proves that $A/M$ is an extension of $\\Fp$. Finally, to prove that $[A/M : \\Fp] \\leq n$ we just need to show that any $n+1$ elements $\\overline{a_1}, \\overline{a_2}, \\dots, \\overline{a_{n+1}} \\in A/M$ are linearly dependent on $\\Fp$. Let $a_i \\in A$ be any element such that $\\overline{a_i} = a_i + M$, for $i=1,2,\\dots,n+1$. By hypothesis $n = [K:\\Qp]$ so the elements $a_1, \\dots, a_{n+1}$ are linearly dependent on $\\Qp$, i.e.\n\t\t\t\\[\n\t\t\t\ta_1b_1 + a_2b_2 + \\dots + a_{n+1}b_{n+1} = 0 \\qquad (b_i \\in \\Qp, \\exists j: b_j \\neq 0).\n\t\t\t\\]\n\t\t\tWe can assume that every coefficient is in $\\Zp \\subset A$ but at least one $b_i$ is not in $p\\Zp$ (we can multiply by a suitable power of $p$). Then the image of this expression in $A/M$ is\n\t\t\t\\[\n\t\t\t\t\\overline{a_1}\\cdot\\overline{b_1} + \\overline{a_2}\\cdot\\overline{b_2} + \\dots + \\overline{a_{n+1}}\\cdot\\overline{b_{n+1}} = 0\n\t\t\t\\]\n\t\t\twhere $\\overline{b_i}$ is the image of $b_i$ in $\\Zp/p\\Zp$ by the standard projection. Since at least one $b_i$ is not in $p\\Zp$ we have that at least one $\\overline{b_i}$ is not $0$, so $\\overline{a_1}, \\overline{a_2}, \\dots, \\overline{a_{n+1}}$ are linearly dependent on $\\Fp$.\n\t\t\\end{proof}\n\t\tLet's denote $\\pabs{K^\\times} := \\Set{\\pabs{x} | x \\in K^\\times} \\leq \\R_{> 0}$ and $p^\\Z = \\Set{p^z | z \\in \\Z} = \\pabs{\\Qp^\\times}$. They're clearly two multiplicative groups and $\\pabs{\\Qp^{\\times}} \\leq \\pabs{K^{\\times}}$.\n\t\t\\begin{defn}\n\t\t\tLet $K/\\Qp$ be a finite extension. Using the same notations as above for $A$ and $M$, $k := A/M$ is called the \\emph{residue field} of $K$, $f := [k : \\Fp] = \\dim_{\\Qp}k$ is called the \\emph{residue degree} and $e := \\left(\\pabs{K^\\times} : \\pabs{\\Qp^\\times}\\right)$ is called the \\emph{ramification index}. \n\t\t\\end{defn}\n\t\tIf $K/\\Qp$ is an extension of degree $n$, we can extend to $K$ the function $\\ord\\colon  \\Qp \\to \\R_{\\geq 0} \\cup \\{+\\infty\\}$ defined in \\cref{section:Qp}: if $\\alpha \\in K$ then\n\t\t\\[\n\t\t\t\\ord \\alpha := -\\log_p\\pabs{\\alpha} = -\\log_p\\pabs{\\Nb_{K/\\Qp}(\\alpha)}^{1/n} = -\\frac{1}{n}\\log_p\\pabs{\\Nb_{K/\\Qp}(\\alpha)}\n\t\t\\]\n\t\twith the usual convention $\\log_p0 = -\\infty$. Clearly this definition agrees with the old one when $\\alpha \\in \\Qp$ and has the usual property $\\ord \\alpha\\beta = \\ord\\alpha + \\ord\\beta$. Let's observe that fixed $\\alpha \\in K$, the number $\\ord \\alpha$ doesn't depend on the choice of $K$: for every field $J$ such that $\\alpha \\in J$ and $[J:\\Qp] < +\\infty$, $\\ord\\alpha$ is the same.\n\t\tThe image of $K^\\times$ under the map $\\ord$ is a non-trivial additive subgroup of $(1/n)\\Z = \\set{x \\in \\Q | nx \\in \\Z }$ which contains $\\Z$: it must be of the form $(1/e)\\Z$ for some positive integer $e$ dividing $n$. The name $e$ is not randomly chosen: it is exactly the ramification index of $K/\\Qp$.\n\t\t\\begin{prop}\n\t\t\tLet $K/\\Qp$ be a finite extension of degree $n$. Then $n = e\\cdot f$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tLet's choose $\\pi \\in K$ such that $\\ord \\pi = 1/e$ and a family $(s_i)_{1 \\leq i \\leq f}$ in $A$ such that the images $\\tilde{s_i} \\in k$ make up a basis of $k$ over $\\Fp$. We claim that \n\t\t\t\\[\n\t\t\t\t\\Set{s_i\\pi^j | 1 \\leq i \\leq f, 0 \\leq j < e}\n\t\t\t\\]\n\t\t\tis a basis for $K$ over $\\Qp$. Let's first prove independence over $\\Qp$. Let's consider a non-trivial linear combination\n\t\t\t\\[\n\t\t\t\t\\sum_{i,j} c_{ij}s_i\\pi^j = \\sum_j x_j\\pi^j \\qquad (c_{ij} \\in \\Qp)\n\t\t\t\\]\n\t\t\twhere $x_j = \\sum_i c_{ij}s_i$. For every $j$ there's an index $\\ell = \\ell(j)$ such that\n\t\t\t\\[\n\t\t\t\t\\pabs{c_{\\ell j}} \\geq \\pabs{c_{ij}} \\quad \\text{for all $i$}\n\t\t\t\\]\n\t\t\tso $x_j/c_{\\ell j} = \\sum_i (c_{ij}/c_{\\ell j})s_i = \\sum_i \\gamma_is_i$ is a non trivial linear combination with coefficients in $A$ and $\\gamma_\\ell = 1$ (clearly we're considering only the cases in which $c_{\\ell j} \\neq 0$ and there is at least one such case by assumption). We can consider this relation in the residue field $k$. Let $\\tilde{\\gamma_i}$ be the image of $\\gamma_i$ in $k$; since by hypothesis $(\\tilde{s_i})_i$ is a basis for $k$ over $\\Fp$ we have\n\t\t\t\\[\n\t\t\t\t0 \\neq \\sum_i \\tilde{\\gamma_i}\\tilde{s_i} \\in A/M\n\t\t\t\\]\n\t\t\tsimply because $\\tilde{\\gamma_\\ell} = 1$. Hence\n\t\t\t\\[\n\t\t\t\t\\sum_i \\gamma_is_i \\notin M \\implies \\pabs{\\sum_i \\gamma_is_i } = 1\n\t\t\t\\]\n\t\t\tand $\\pabs{x_j} = \\pabs{c_{\\ell j}} \\in \\pabs{\\Qp^\\times}$ is an integer power of $p$. There is no competition among the absolute values of the distinct terms $x_j\\pi^j$, so, by \\cref{prop:competitivity}, we obtain\n\t\t\t\\[\n\t\t\t\t\\sum_{i,j} c_{ij}s_i\\pi^j = \\sum_j x_j\\pi^j \\neq 0\n\t\t\t\\]\n\t\t\tand this proves the linear independence.\\newline\n\t\t\tNow we have to show that the family $(s_i\\pi^j)_{i,j}$ generates the $\\Qp$-vector space $K$. We recall that every finite extension of $\\Qp$ is complete, since $(\\Qp^n, \\norm{\\ }_{\\infty})$ is complete for each $n \\in \\N$ and all norms on it are equivalent (see \\cref{thm:equiv-norm-finite-dim}). To do this we'll use the Representation Theorem \\ref{thm:representation-ultrametrics} for the complete field $K$ and the element $\\xi = p \\in M \\subset A$. In this case $A/pA = A/\\pi^eA$ (which is of course different from $A/M = A/\\pi A$) is finite with representatives\n\t\t\t\\[\n\t\t\t\t\\mathcal{S} = \\Set{\\sum_{1 \\leq i \\leq f, 0 \\leq j < e} c_{ij}s_i\\pi^j | c_{ij} \\in \\{0, 1, \\dots, p-1\\}}.\n\t\t\t\\]\n\t\t\tHence every element $x \\in A$ can be written as a series\n\t\t\t\\[\n\t\t\t\tx = \\sum_{h \\geq 0}c_hp^h \\quad (c_h \\in \\mathcal{S}).\n\t\t\t\\]\n\t\t\tIf we write explicit expressions for the coefficients\n\t\t\t\\[\n\t\t\t\tc_h = \\sum_{\\substack{1 \\leq i \\leq f\\\\ 0 \\leq j < e}} c_{ijh}s_i\\pi^j \\in \\mathcal{S}\n\t\t\t\\]\n\t\t\twe obtain\n\t\t\t\\[\n\t\t\t\tx = \\sum_{h \\geq 0}\\,\\sum_{\\substack{1 \\leq i \\leq f\\\\ 0 \\leq j < e}} c_{ijh}s_i\\pi^j p^h.\n\t\t\t\\]\n\t\t\tSince $\\lim_{h \\to +\\infty}p^h = 0$, thanks to \\cref{prop:summable_families}, this family is summable and we can re-arrange its terms to obtain\n\t\t\t\\[\n\t\t\t\tx = \\sum_{\\substack{1 \\leq i \\leq f\\\\ 0 \\leq j < e}} \\left( \\sum_{h \\geq 0} c_{ijh}p^h \\right) \\cdot s_i\\pi^j\n\t\t\t\\]\n\t\t\tbut $c_{ij} := \\sum_{h \\geq 0} c_{ijh}p^h \\in \\Zp$ and $x = \\sum_{i,j} c_{ij} s_i\\pi^j$. This proves that the $ef$ elements $(s_i\\pi^j)$ generates $K$: if $x \\notin A$ there exists $\\ell \\in \\N$ such that $p^\\ell x \\in A$ so can repeat the process above and then multiply every $c_{ij}$ by $p^{-\\ell}$, obtaining $c_{ij} \\in \\Qp$. \n\t\t\\end{proof}\n\t\t\\begin{defn}\n\t\t\tLet $K/\\Qp$ be a finite extension. $K/\\Qp$ is said to be\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item \\emph{unramified} when $e = 1$, i.e. $[K:\\Qp] = f$;\n\t\t\t\t\\item \\emph{totally ramified} when $f=1$, i.e. $[K:\\Qp] = e$.\n\t\t\t\\end{itemize} \n\t\t\\end{defn}\n\t\tWe'll now study some properties of finite extensions of $\\Qp$, focusing on these two particular cases. We now need an analogue of the famous Eisenstein's criterion, but on $\\Zp$.\n\t\t\\begin{prop}\n\t\t\t\\label{prop:eisenstein}\n\t\t\tLet $f(X) \\in \\Zp[X]$ be a polynomial satisfying\n\t\t\t\\begin{gather*}\n\t\t\t\tf(X) = X^n + a_{n-1}X^{n-1} + \\dots + a_0, \\\\\n\t\t\t\ta_0 \\in p\\Zp \\setminus p^2\\Zp,\\\\\n\t\t\t\ta_i \\in p\\Zp \\qquad (1 \\leq i \\leq n-1).\n\t\t\t\\end{gather*}\n\t\t\tThen $f$ is irreducible in $\\Zp[X]$ and in $\\Qp[X]$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tBy Gauss's lemma we just need to prove that $f$ is irreducible in $\\Zp[X]$. Let's consider a factorization $f = g \\cdot h$ in $\\Zp[X]$ with\n\t\t\t\\[\n\t\t\t\tg = b_lX^l + \\dots + b_0, \\qquad h = c_mX^m + \\dots + c_0.\n\t\t\t\\]\n\t\t\tHence\n\t\t\t\\[\n\t\t\t\tl + m = n, \\qquad b_lc_m = 1, \\qquad b_0c_0 = a_0.\n\t\t\t\\]\n\t\t\tSince $a_0 \\in p\\Zp$ is not divisible by $p^2$ we can assume without loss of generality that $p \\mid c_0$ and $p \\nmid b_0$. Let's consider these polynomials in $\\Zp/p\\Zp[X]$: by assumption $\\tilde{f} = X^n$ so its factorization $\\tilde{f} = \\tilde{g} \\cdot \\tilde{h}$ must also be a product of monomials. Hence $\\tilde{g} = b_0$ is a constant and, since $b_lc_m = 1$, we obtain $m = 0$. We have proved that every factorization of $f$ in $\\Zp[X]$ is trivial, hence $f$ is irreducible.\n\t\t\\end{proof}\n\t\tThis criterion can be easily generalized: if $K/\\Qp$ is a finite extension of degree $n = e \\cdot f$ then we can replace $\\Zp$ with $A$, $p\\Zp$ with $\\pi A$ (where $\\pi \\in K$ is such that $\\ord \\pi = 1/e$) and $p^2\\Zp$ with $\\pi^2A$ (here $A$ is the maximal subring of $K$, as in the usual notation).\n\t\t\\begin{defn}\n\t\t\tA monic polynomial $f(X) \\in \\Zp[X]$ of degree $n \\geq 1$ satisfying\n\t\t\t\\[\n\t\t\t\tf(X) \\equiv X^n \\mod p, \\qquad f(0) \\not\\equiv 0 \\mod p^2.\n\t\t\t\\]\n\t\t\tis called an \\emph{Eisenstein polynomial}.\n\t\t\\end{defn}\n\t\t\\begin{prop}\n\t\t\tIf $K/\\Qp$ is a totally ramified finite extension and $\\pi \\in K$ is such that $\\mathrm{ord}_p\\, \\pi = 1/e$ then $\\pi$ is root of an Eisenstein polynomial \n\t\t\t\\[\n\t\t\t\tf(X) = X^e + a_{e-1}X^{e-1} + \\dots + a_0, \\qquad a_i \\in \\Zp\n\t\t\t\\]\n\t\t\tand $K = \\Qp(\\pi)$. Conversely, if $\\alpha$ is a root of an Eisenstein polynomial of degree $e$ then $\\Qp(\\alpha)$ is totally ramified over $\\Qp$ and $[\\Qp(\\alpha) : \\Qp] = e$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tFor the first implication let's consider the minimal polynomial of $\\pi$ over $\\Qp$\n\t\t\t\\[\n\t\t\t\t\\lambda_{\\Qp}(\\pi) = X^h + b_{h-1}X^{h-1} + \\dots + b_1X + b_0.\n\t\t\t\\]\n\t\t\tIts degree $h$ must be equal to $e$: obviously $h\\leq e$ since $[\\Qp(\\pi):\\Qp] \\leq [K:\\Qp] = e$; we'll see why it cannot be strictly less then $e$. Let's observe that its coefficients $b_i$ are the symmetric polynomials evaluated in the conjugates of $\\pi$, all of which have $\\pabs{\\ } = \\pabs{\\pi} = p^{-1/e}$, so $\\pabs{b_i} < 1$, which means $b_i \\in p\\Zp$. As for $b_0$, we have \n\t\t\t\\[\n\t\t\t\t\\pabs{b_0} = \\pabs{\\pi}^h = p^{-h/e}\n\t\t\t\\]\n\t\t\tand since $b_0 \\in \\Qp$ we must have $\\pabs{b_0} \\in p^\\Z$ so $e | h \\implies h = e$. Then $\\pabs{b_0} = 1/p$ so $b_0 \\in p\\Zp \\setminus p^2\\Zp$. We have proved that $K = \\Qp(\\pi)$ and $\\lambda_{\\Qp}(\\pi) \\in \\Zp[X]$ is an Eisenstein polynomial. \\newline\n\t\t\tConversely, if $\\Zp[X] \\ni f(X) = X^e + a_{e-1}X^{e-1} + \\dots + a_0$ is an Eisenstein polynomial, we know it is irreducible by \\cref{prop:eisenstein}, so if we adjoin a root $\\alpha$ to $\\Qp$ we obtain an extension of degree $e = \\deg f$. Since, by assumption, $\\ord a_0 = 1$ we obtain $\\ord \\alpha = (1/e)\\ord a_0 = 1/e$ hence $\\Qp(\\alpha)$ is totally ramified over $\\Qp$.\n\t\t\\end{proof}\n\t\t\\begin{prop}\n\t\t\t\\label{prop:structure-finite-extension}\n\t\t\tThere is exactly one unramified extension $K_f^{\\textrm{unram} }$ of $\\Qp$ of degree $f$ and it can be obtained by adjoining a primitive $(p^f - 1)$th root of $1$. If $K$ is an extension of $\\Qp$ of degree $n$, index of ramification $e$ and residue degree $f$, then $K = K_f^{\\textrm{unram} }(\\pi)$, where $\\pi$ satisfies an Eisenstein polynomial with coefficients in $K_f^{\\textrm{unram} }$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tLet's first prove that there exists at least one unramified extension of $\\Qp$ of degree $f$. Let $\\overline{\\alpha}$ be a generator of the cyclic group $\\F_{p^f}^\\times$ and let $\\overline{P}(X) = X^f + \\overline{a_1}X^{f-1} + \\dots + \\overline{a_f} \\in \\Fp[X]$ be its minimal polynomial. For every $i = 1, \\dots, f$ let's consider $a_i \\in \\Zp$ which reduces to $\\overline{a_i}$ mod $p$ and let $P(X) = X^f + a_1X^{f-1} + \\dots + a_f \\in \\Zp[X]$. This polynomial is clearly irreducible in $\\Zp[X]$ (otherwise its reduction $\\overline{P}(X)$ could be factorized in $\\Fp[X]$) so, by Gauss's lemma, $P(X)$ is irreducible in $\\Qp[X]$. Let $\\alpha \\in \\Qpa$ be a root of $P(X)$ (clearly $\\alpha \\notin \\Qp$) and let $\\tilde{K} := \\Qp(\\alpha)$, $\\tilde{A} := \\{x \\in \\tilde{K} \\mid \\pabs{x} \\leq 1 \\}$, $\\tilde{M} := \\{x \\in \\tilde{K} \\mid \\pabs{x} < 1\\}$. Then $[\\tilde{K} : \\Qp] = f$ and the coset $\\alpha + \\tilde{M} \\in \\tilde{A}/\\tilde{M}$ is a root of the irreducible polynomial $\\overline{P}(X)$ over $\\Fp$. Hence $[\\tilde{A}/\\tilde{M} : \\Fp] = f$ which implies $\\widetilde{K}$ is an unramified extension of $\\Qp$ of degree $f$. \\newline\n\t\t\tNow we prove uniqueness. Let $K$ be as in the statement, let $A$ be the valuation ring of $\\pabs{\\ }$ in $K$ and let $M$ be the maximal ideal of $A$. Since $f$ is the residue degree of $K$ we have $A/M = \\F_{p^f}$. We'll now prove that any $\\beta \\in \\F_{p^f}^\\times$ admits a \\emph{Teichm{\\\"u}ller representative}, i.e. an $\\omega(\\beta) \\in A$ such that it is a solution of $X^{p^f} - X = 0$ congruent to $\\beta$ mod $M$. We'll focus on the case in which $\\beta$ is a generator of $\\F_{p^f}^\\times$ (so some properties we'll find will be valid only in this case).\\newline\n\t\t\tLet $\\overline{\\alpha}$ be a generator of $\\F_{p^f}^\\times$ and let $\\alpha_0 \\in A$ be any element which reduces to $\\overline{\\alpha}$ mod $M$. Finally, let $\\pi \\in K$ be any element with $\\ord \\pi = 1/e$; thus $M = \\pi A$. We claim that there exists $A \\ni \\alpha \\equiv \\alpha_0 \\mod M$ such that $\\alpha^{p^f - 1} - 1 = 0$ (now we only know that $\\alpha_0^{p^f - 1} - 1 \\equiv 0 \\mod \\pi$). The proof is an Hensel's lemma type argument. First of all we write $\\alpha \\equiv \\alpha_0 + \\alpha_1\\pi \\mod \\pi^2$ and we want to find $\\alpha_1 \\in A$ such that $(\\alpha_0 + \\alpha_1\\pi)^{p^f - 1} - 1 \\equiv 0 \\mod \\pi^2$. Using Newton's binomial and recalling that we're operating in a ring of characteristic $p$, namely $A/\\pi^2A$, we obtain\n\t\t\t\\[\n\t\t\t\t0 \\equiv (\\alpha_0 + \\alpha_1\\pi)^{p^f - 1} - 1 \\equiv  \\alpha_0^{p^f - 1} - 1 - \\alpha_1\\pi\\alpha_0^{p^f - 2} \t\\mod \\pi^2.\n\t\t\t\\]\n\t\t\tSince $\\alpha_0^{p^f - 1} \\equiv 1 \\mod \\pi$ we can set \n\t\t\t\\[\n\t\t\t\t\\alpha_1 \\equiv \\frac{\\alpha_0^{p^f - 1} - 1}{\\pi\\alpha_0^{p^f - 2}} \\equiv \\alpha_0 \\cdot \\frac{\\alpha_0^{p^f - 1} - 1}{\\pi} \\mod \\pi\n\t\t\t\\]\n\t\t\tand we obtain the desired congruence mod $\\pi^2$, which represents a better approximation of the solution. Continuing in this way, just as in Hensel's lemma, we find $A \\ni \\alpha = \\alpha_0 + \\alpha_1\\pi + \\alpha_2\\pi^2 + \\dots$ such that $\\alpha^{p^f - 1} = 1$. We immediately note that $\\alpha$ is a primitive $(p^f - 1)$th root of $1$ because $\\alpha, \\alpha^2, \\dots, \\alpha^{p^f - 1}$ are all distinct (their reductions mod $M$ $\\overline{\\alpha}, \\overline{\\alpha}^2, \\dots, \\overline{\\alpha}^{p^f - 1}$ are all distinct by assumption). We also observe that $[\\Qp(\\alpha) : \\Qp] \\geq f$. In-fact, let $G(X) := \\lambda_{\\Qp}(\\alpha)$ be the minimal polynomial of $\\alpha$ on $\\Qp$ and consider $0 \\neq \\overline{G}(X) \\in \\Fp[X]$, its reduction mod $p$ (recall that $\\pabs{\\alpha} = 1$ so $G(X) \\in \\Zp[X]$); by assumption $\\alpha + M = \\overline{\\alpha}$ so $G(\\alpha) = 0 \\implies \\overline{G}(\\overline{\\alpha}) = 0$. By hypothesis the minimal polynomial of $\\overline{\\alpha}$ in $\\Fp$ is $\\overline{P}(X)$ so \n\t\t\t\\[\n\t\t\t\t\\overline{P}(X) \\mid \\overline{G}(X) \\implies \\deg \\overline{G}(X) \\geq \\deg \\overline{P}(X) = f \\implies \\deg G(X) \\geq f\n\t\t\t\\]\n\t\t\tso $[\\Qp(\\alpha):\\Qp] = \\deg G(X) \\geq f$. We can apply this discussion to any $\\tilde{K}$ unramified extension of $\\Qp$ of degree $f$ (for example the one we have built at the beginning). Hence, $\\Qp(\\alpha) \\subseteq \\tilde{K}$, where $\\tilde{K} \\ni \\alpha$ is a primitive $(p^f-1)$th root of $1$. We have\n\t\t\t\\[\n\t\t\t\tf = [\\tilde{K}: \\Qp] \\geq [\\Qp(\\alpha):\\Qp] \\geq f\n\t\t\t\\]\n\t\t\tso $\\tilde{K} = \\Qp(\\alpha)$. This implies that the unramified extension of degree $f$ is unique, let's call it $K_f^{\\textrm{unram}}$. \\newline\n\t\t\tNow let $K/\\Qp$ be a generic finite extension of degree $n = ef$, as in the statement. Let $E(X)$ be the minimal polynomial of $\\pi$ over $K_f^{\\textrm{unram}} \\leq K$. Let $\\{\\pi_j\\}_j$ be the conjugates of $\\pi$ over $K_f^{\\textrm{unram}}$ (in a suitable extension of $K$). Then\n\t\t\t\\[\n\t\t\t\tE(X) = \\prod_j (X - \\pi_j) = X^d + b_{d-1}X^{d-1} + \\dots b_1X + b_0.\n\t\t\t\\]\n\t\t\tLet $d = \\deg E(X)$ and $c = b_0$ be the constant term of $E(X)$. Every $b_i$ is a symmetric polynomial evaluated in the conjugates of $\\pi$: by the ultrametric inequality, since $\\pabs{\\pi_j} = \\pabs{\\pi} = p^{-1/e}$, we obtain $\\pabs{b_i} < 1$ for every $i=1, \\dots, d-1$. Since $b_i \\in K_f^{\\textrm{unram}}$ we have $\\ord b_i \\in \\Z$ so it must be $\\ord b_i \\geq 1$, i.e. $p$ divides $b_i$. Instead, the constant term has order $\\ord c = d \\cdot \\ord \\pi = d/e \\in \\Z$; we recall that $d = [K_f^{\\textrm{unram}}(\\pi) : K_f^{\\textrm{unram}}] \\leq [K : K_f^{\\textrm{unram}}] = e$ so the only possibility is that $d = e$ and $\\ord c = 1$, i.e. $p$ divides $c$ but $p^2$ does not. This proves that $E(X)$ is an Eisenstein polynomial over $K_f^{\\textrm{unram}}$ and $K = K_f^{\\textrm{unram}}(\\pi)$.\n\t\t\\end{proof}\n\t\tWe have an important ``structural'' corollary of this proposition.\n\t\t\\begin{corollary}\n\t\t\t\\label{corollary:teichmuller-digits}\n\t\t\tIf $K$ is a finite extension of $\\Qp$ of degree $n = ef$ and $\\pi \\in K$ is chosen so that $\\mathrm{ord}_p\\, \\pi = 1/e$, then every $\\alpha \\in K$ can be written in one and only one way as\n\t\t\t\\[\n\t\t\t\t\\sum_{i=m}^{+\\infty} a_i\\pi^i\n\t\t\t\\]\n\t\t\twhere $m = e \\cdot \\mathrm{ord}_p\\, \\alpha$ and every $a_i$ satisfies $a_i^{p^f} = a_i$ (the $a_i$ are called \\emph{Teichm{\\\"u}ller digits}).\n\t\t\\end{corollary}\n\t\t\\begin{proof}\n\t\t\tLet $A$ be the maximal subring of $K$ and $M$ be its maximal ideal; $\\pi \\in K$ is such that $\\pabs{\\pi} = p^{-1/e} < 1$ so $M = \\pi A$ and we already know, by definition, that $A/\\pi A = \\F_{p^f}$. Let's choose $p^f$ representatives $0 = a_1, a_2, \\dots, a_{p^f} \\in A$ for $A/\\pi A$ such that $a_i^{p^f} = a_i$ (we can apply an Hensel's lemma type argument). We can then apply \\cref{thm:representation-ultrametrics} and conclude.\n\t\t\\end{proof}\n\t\tLet's observe that we could apply this corollary to $\\Qp$ itself but we would not obtain the same representation in power series we used: in-fact we would obtain the so called representation with Teichm{\\\"u}ller digits where every $a_i$ is $0$ or a $(p-1)$th root of unity (in $\\Zp$). This is the more convenient way to write elements of $\\Zp$ and $\\Qp$: using these digits we have closed formulas for addition and multiplication, which are very hard to find if one uses digits in $\\{0, \\dots, p-1\\}\\subset \\Z$, due to the problem of carrying. We'll not study these formulas, we'll only try to describe very briefly how to derive the Teichm{\\\"u}ller representation beginning with the old one. First, for every $\\zeta \\in \\Fp$ we have to find a solution of $X^p - X = 0$ in $\\Zp$ which is equivalent to $\\zeta \\mod p$: we can always find such a solution thanks to Hensel's lemma. We have defined the \\emph{Teichm{\\\"u}ller character} $\\omega\\colon  \\Fp^\\times \\to \\Zp^\\times$ (clearly a group morphism), which we can extend sending $0$ to $0$ to define a section of the canonical projection $\\pi\\colon \\Zp \\twoheadrightarrow \\Zp/p\\Zp \\equiv \\Fp$. Now, given $x \\in \\Zp$ such that\n\t\t\\[\n\t\t\tx = x_0 + x_1p^1 + x_2p^2 + \\dots \\qquad (x_i \\in \\{0, \\dots, p-1\\})\n\t\t\\]\n\t\twe consider, with a little abuse of notation, $\\omega(x_0) \\in \\Zp$; since, by definition, $\\omega(x_0) \\equiv x_0 \\mod p$ we have $x - \\omega(x_0) \\equiv 0 \\mod p$ so\n\t\t\\[\n\t\t\tx - \\omega(x_0) = x_1'p + x_2'p^2 + x_3'p^3 + \\dots \\qquad (x_i' \\in \\{0, \\dots, p-1\\}).\n\t\t\\]\n\t\tThen we can consider $\\omega(x_1') \\in \\Zp$ and obtain $x - \\omega(x_0) - \\omega(x_1')p \\equiv 0 \\mod p^2$ and iterating this process we get the Teichm{\\\"u}ller digits of $x$.\n\t\t\n\t\tGetting back to the study of algebraic extensions of $\\Qp$, we can conclude that the finite unramified extensions of $\\Qp$ are precisely the extensions obtained by adjoining roots of $1$ of order not divisible by $p$: in-fact if $m$ and $p$ are coprime then there exists $f \\in \\Z$ such that $p^f - 1 = mm'$ with $m' \\in \\Z$ (for example we can choose $f$ equal to the order of $p$ in $(\\Z/m\\Z)^\\times$); adjoining to $\\Qp$ a primitive $(p^f - 1)$th root of $1$, let it be $\\alpha$, we obtain that $\\alpha^{m'}$ is a primitive $m$-th root of $1$.\n\t\\section{The algebraic closure of $\\Qp$ and its completion $\\Cp$}\n\t\t\\begin{defn}\n\t\t\tThe union of all the finite unramified extensions of $\\Qp$ is $\\Qpu$ and it's called the \\emph{maximal unramified extension of $\\Qp$}.\n\t\t\\end{defn}\n\t\tObviously $\\Qpu$ is well defined: given $K_f$ and $K_{f'}$, two unramified extensions of $\\Qp$ of degree $f$ and $f'$ respectively, there exists a (unique) unramified extension $K_{ff'}$ which contains both of them (because $(p^{ff'} - 1)$ is divided by $(p^{f'} - 1)$ and $(p^f - 1)$).\n\t\tThere's an obvious extension of the \\padic absolute value to $\\Qpu$ so we can define its valuation ring \n\t\t\\[\n\t\t\t\\Zpu := \\{x \\in \\Qpu \\mid \\pabs{x} \\leq 1 \\}.\n\t\t\\]\n\t\tIt admits a unique maximal ideal $p\\Zpu = \\{x \\in \\Qpu \\mid \\pabs{x} < 1 \\}$. It is easily seen that the residue field $\\Zpu/p\\Zpu$ is $\\overline{\\F}_p$, the algebraic closure of $\\Fp$. Every $\\overline{x} \\in \\overline{\\F}_p$ has a unique Teichm{\\\"u}ller representative $x \\in \\Zpu$ such that $x$ has image $\\overline{x}$ in $\\overline{\\F}_p$ and $x$ is a root of $1$ (more precisely if $\\overline{x} \\in \\F_{p^f}$, then $x^{p^f} = x$). For this reason $\\Zpu$ is often called the ``lifting to characteristic $0$ of $\\overline{\\F}_p$''.\n\t\t\n\t\t\\begin{prop}\n\t\t\tThe field $\\Qp$ is not algebraically closed.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\t Using the \\padic Heisenstein's criterion (\\cref{prop:eisenstein}) we can find irreducible polynomials in $\\Qp[X]$ of any degree, for example $X^n - p$.\n\t\t\\end{proof}\n\t\tAlthough this fact was already obvious, from the proof we infer that an algebraic closure of $\\Qp$ can't have finite degree over $\\Qp$.\n\t\t\\begin{defn}\n\t\t\tThe algebraic closure of $\\Qp$ is called $\\Qpa$.\n\t\t\\end{defn}\n\t\tClearly, there's a unique extension of the \\padic absolute value to $\\Qpa$, since we can extend it to every finite extension of $\\Qp$, so $\\Qpa$ is an ultrametric field. We'll see that it is not complete.\n\t\t\n\t\tWe now state and prove two technical lemmas we'll need in the next theorems.\n\t\t\\begin{lemma}\n\t\t\t\\label{exercise:3-p73}\n\t\t\tLet $K/\\Qp$ be a finite extension and $g(X) = X^n + b_{n-1}X^{n-1} + \\dots + b_0 \\in K[X]$. If $C_0 = \\max_i \\pabs{b_i}$ then there exists a constant $C_1$, which depends only on $C_0$, such that every root $\\beta$ of $g(X)$ satisfies $\\pabs{\\beta} < C_1$.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tWe claim that $C_1 = 1 + \\max_{0 \\leq i < n} C_0^{1/i}$ is a suitable constant. Let $\\beta$ be a root of $g(X)$, i.e.\n\t\t\t\\[\n\t\t\t\t\\beta^n + b_{n-1}\\beta^{n-1} + \\dots + b_1\\beta + b_0 = 0.\n\t\t\t\\]\n\t\t\tBy the competitivity of the absolute value, \\cref{prop:competitivity}, we know that there are two distinct terms in this sum which attain maximum absolute value. We can distinguish two cases:\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item $\\pabs{\\beta^n} \\leq \\pabs{b_0}$: then $\\pabs{\\beta} \\leq C_0^{1/n} < C_1$. \n\t\t\t\t\\item $\\pabs{\\beta^n} \\leq \\pabs{b_i\\beta^i}$ for some $1 \\leq i < n$: then $\\pabs{\\beta} \\leq C_0^{1/(n-i)} < C_1$.\n\t\t\t\\end{itemize}\n\t\t\tSo we can conclude that the chosen $C_1$ satisfies the request.\n\t\t\\end{proof}\n\t\tLet's now generalize the notion of congruence mod $p^n$: if $K/\\Qp$ is a finite extension and $\\alpha,\\beta \\in K$, the writing $\\alpha \\equiv \\beta \\mod p^n$ means $\\pabs{\\alpha - \\beta} \\leq p^{-n}$. It's immediately seen that this is exactly our old definition of congruence when $K = \\Qp$.\n\t\t\\begin{lemma}\n\t\t\t\\label{exercise:9-p57}\n\t\t\tLet $\\xi$ be algebraic of degree $n$ over $\\Qp$. Then there exists an integer $N$ such that $\\xi$ does not satisfy any congruence \n\t\t\t\\[\n\t\t\t\ta_{n-1}\\xi^{n-1} + a_{n-2}\\xi^{n-2} + \\dots + a_1\\xi + a_0 \\equiv 0 \\mod p^N\n\t\t\t\\]\n\t\t\twhere the $a_i$ are in $\\Zp$ and there is at least one coefficient in $\\Zp^\\times$.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tLet's consider the space $\\Zp^n\\setminus (p\\Zp)^n \\subset \\Zp^n$: it is compact since it's a closed subset of the compact space $\\Zp^n$ ($p\\Zp$ is open in $\\Zp$ and, by definition of product topology, also $(p\\Zp)^n$ is open in $\\Zp^n$). Let's consider the sets\n\t\t\t\\[\n\t\t\t\tX_m := \\Set{\\left(a_{n-1}^{(m)}, \\dots, a_0^{(m)}\\right) \\in \\Zp^n \\setminus (p\\Zp)^n | a_{n-1}^{(m)}\\xi^{n-1}+ \\dots + a_0^{(m)} \\equiv 0 \\mod p^m  }\n\t\t\t\\]\n\t\t\tfor every $m \\in \\N$. We claim that $X_m$ is compact. To prove it, we can just show that $X_m$ is closed. Let's consider the function\n\t\t\t\\[\n\t\t\t\tg\\colon \\Zp^n\\setminus(p\\Zp)^n \\to \\R_{\\geq 0}, \\quad g(x_0, \\dots, x_{n-1})  := \\pabs{x_{n-1}\\xi^{n-1} + \\dots + x_0}.\n\t\t\t\\]\n\t\t\tClearly it is a continuous function and it's easily seen that $X_m = g^{-1}\\left([0, p^{-(m+1)}]\\right)$ so $X_m$ is closed. Now, let's suppose the thesis is false, which means exactly that $X_m \\neq \\emptyset$ for every $m \\in \\N$. Obviously $X_{m+1} \\subseteq X_m$ so we have a decreasing sequence of non-empty compact sets and we can consider\n\t\t\t\\[\n\t\t\t\tX := \\bigcap_{m \\in \\N} X_m.\n\t\t\t\\]\n\t\t\tThis intersection is not empty: it is well known that a decreasing intersection of non-empty compact sets is non-empty (in this case we can choose a sequence $(a_i)_i$ with $a_i \\in X_i$ and by a diagonal argument we can extract a convergent subsequence with limit in $X$). Let $(b_{n-1}, \\dots, b_0) \\in X$, then \n\t\t\t\\begin{gather*}\n\t\t\t\tb_{n-1}\\xi^{n-1} + b_{n-2}\\xi^{n-2} + \\dots + b_1\\xi + b_0 \\equiv 0 \\mod p^m \\qquad  \\forall m \\in \\N \\\\\n\t\t\t\t\\implies \n\t\t\t\tb_{n-1}\\xi^{n-1} + b_{n-2}\\xi^{n-2} + \\dots + b_1\\xi + b_0 = 0.\n\t\t\t\\end{gather*}\n\t\t\tThat's a contradiction, since $\\xi$ has degree $n$ over $\\Qp$.\n\t\t\\end{proof}\n\t\tWe now present two useful propositions.\n\t\t\\begin{prop}[Krasner's Lemma]\n\t\t\tLet $a, b \\in \\Qpa$ and assume that for every conjugate $a_i$ of $a$ (i.e. for every root of $\\lambda_{\\Qp}(a)$) the following holds\n\t\t\t\\[\n\t\t\t\t\\pabs{b - a} < \\pabs{a_i - a}.\n\t\t\t\\]\n\t\t\tThen $\\Qp(a) \\subseteq \\Qp(b)$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tLet $K = \\Qp(b)$ and suppose that $a \\notin K$. So $[K(a) : K] > 1$ and, since $a$ has exactly $[K(a):K]$ conjugates over $K$ ($K$ is a field of characteristic $0$ so irreducible polynomials can't have multiple roots), it follows that there is at least one $a_i \\notin K$. Then we have an isomorphism $\\sigma\\colon K(a) \\to K(a_i)$ which keeps $K$ fixed and sends $a$ to $a_i$. By \\cref{corollary:galois-isometric} we know that $\\pabs{\\sigma(x)} = \\pabs{x}$ for every $x \\in K(a)$. In particular\n\t\t\t\\begin{gather*}\n\t\t\t\t\\pabs{b - a_i} = \\pabs{\\sigma(b) - \\sigma(a_i)} = \\pabs{b - a} \\\\\n\t\t\t\t\\implies \\pabs{a_i - a} \\leq \\max\\left\\{\\pabs{a_i - b}, \\pabs{b - a} \\right\\} = \\pabs{b - a} < \\pabs{a_i - a}\n\t\t\t\\end{gather*}\n\t\t\twhich is clearly a contradiction.\n\t\t\\end{proof}\n\t\tLet's observe that the Krasner's lemma can be easily generalized to any finite extension $K$ of $\\Qp$: we just need to consider the conjugates of $a$ over $K$ and we the result becomes $K(a) \\subseteq K(b)$.\n\t\t\n\t\tFrom now on, unless otherwise specified, given a normed field $(K, \\norm{\\ })$ we'll equip the ring $K[X]$ with the sup-norm, i.e. given $f = \\sum a_iX^i$ and $g = \\sum b_jX^j$ we define\n\t\t\\[\n\t\t\t\\norm{f - g} := \\max_i \\norm{a_i - b_i}.\n\t\t\\]\n\t\t\\begin{prop}\n\t\t\t\\label{prop:continuity-roots}\n\t\t\tLet $K$ be a finite extension of $\\Qp$ and $f(X) \\in K[X]$ have degree $n$ and distinct roots\n\t\t\t\\[\n\t\t\t\tf(X) = a_nX^n + a_{n-1}X^{n-1} + \\dots + a_1X + a_0.\n\t\t\t\\]\n\t\t\tThen for every $\\epsilon > 0$ there exists $\\delta > 0$ such that if $K[X] \\ni g(X) = \\sum b_iX^i$ has degree $n$ and $\\pabs{f - g} < \\delta$, then for every root $\\alpha_i$ of $f(X)$ there is precisely one root $\\beta_i$ of $g(X)$ such that $\\pabs{\\alpha_i - \\beta_i} < \\epsilon$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tLet's fix an $\\epsilon > 0$. For every root $\\beta$ of $g(X)$ we have\n\t\t\t\\begin{gather*}\n\t\t\t\t\\pabs{f(\\beta)} = \\pabs{f(\\beta) - g(\\beta)} = \\pabs{\\sum_{i=0}^n (a_i - b_i)\\beta^i} \\leq \\max_i\\left\\{\\pabs{a_i - b_i}, \\pabs{\\beta}^i \\right\\} \\leq \\\\\n\t\t\t\t\\leq \\pabs{f - g} \\cdot \\max\\left\\{1, \\pabs{\\beta}^n \\right\\} < \\delta C_1^n\n\t\t\t\\end{gather*}\n\t\t\twhere $\\delta$ will be chosen later and $C_1$ is a suitable constant which dominates the norm of all the roots of $g(X)$. We can find such a constant which only depends on $f(X)$: in-fact for every $i$ we have\n\t\t\t\\[\n\t\t\t\t\\pabs{b_i} \\leq \\max\\left\\{\\pabs{b_i - a_i}, \\pabs{a_i} \\right\\} \\leq \\max\\left\\{\\delta, \\pabs{a_i} \\right\\} \\leq \\max_i\\,\\pabs{a_i}\n\t\t\t\\]\n\t\t\tif we choose a small enough $\\delta$. Then $\\max_i\\,\\pabs{b_i} \\leq \\max_i\\,\\pabs{a_i}$ and, recalling \\cref{exercise:3-p73}, we conclude that we can set $C_1 = C$, where $C$ is the constant we obtain applying the lemma to $f(X)$.\n\t\t\tLet's define\n\t\t\t\\[\n\t\t\t\tC_2 := \\min_{1 \\leq i < j \\leq n} \\pabs{\\alpha_i - \\alpha_j}.\n\t\t\t\\] \n\t\t\tSince by assumption the $\\alpha_i$ are distinct, $C_2 > 0$. We immediately see that there can be at most one $\\alpha_i$ satisfying $\\pabs{\\beta - \\alpha_i} < C_2$: in-fact if it held for another $\\alpha_j \\neq \\alpha_i$ we'd have $\\pabs{\\alpha_i - \\alpha_j} < C_2$ by the ultrametric inequality. Since\n\t\t\t\\begin{gather*}\n\t\t\t\tC_1^n\\delta > \\pabs{f(\\beta)} = \\pabs{a_n}\\prod\\pabs{\\beta - \\alpha_i}\n\t\t\t\\end{gather*}\n\t\t\tit's clear that if $\\delta$ is sufficiently small there exists an $\\alpha_i$ such that $\\pabs{\\beta - \\alpha_i} < C_2$. For that $\\alpha_i$ we have\n\t\t\t\\[\n\t\t\t\t\\pabs{\\beta - \\alpha_i} < \\frac{C_1^n\\delta}{\\pabs{a_n}\\prod_{j \\neq i} \\pabs{\\beta - \\alpha_j}} \\leq \\frac{C_1^n\\delta}{\\pabs{a_n}C_2^{n-1}}\n\t\t\t\\]\n\t\t\tand it's clear that we can make $\\pabs{\\beta - \\alpha_i}$ less than $\\epsilon$ choosing a sufficiently small $\\delta$.\n\t\t\\end{proof}\n\t\tFinally we prove the already mentioned non-completeness of $\\Qpa$.\n\t\t\\begin{thm}\n\t\t\t$\\Qpa$ is not complete.\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tWe must show a Cauchy sequence $(a_i)_{i \\in \\N} \\subseteq \\Qpa$ which doesn't converge in $\\Qpa$.\n\t\t\tLet $b_i \\in \\Qpa$  be a primitive $(p^{i!} - 1)$th root of $1$. If $j > i$ then $(p^{i!} - 1) \\mid (p^{j!} - 1)$ so $b_i^{p^{j!} - 1} = 1$. Thus if $j > i$, $b_i$ is a power of $b_j$ so $\\Qp(b_i) \\subset \\Qp(b_j)$. Let\n\t\t\t\\[\n\t\t\t\ta_i := \\sum_{j=0}^i b_jp^{N_j}\n\t\t\t\\]\n\t\t\twhere $0 = N_0 < N_1 < N_2 < \\dots$ is an increasing sequence of integers we'll choose later. We immediately note that the $b_j$, for $j=0, \\dots,i$, are the Teichm{\\\"u}ller digits of the \\padic expansion of $a_i$ in the unramified extension $\\Qp(b_i)$, since $b_j^{p^{i!}} = b_j$. It's clear that the sequence $(a_i)_i$ is Cauchy: \n\t\t\t\\[\n\t\t\t\t\\pabs{a_{i+1} - a_i} = \\pabs{b_{i+1}p^{N_{i+1}}} = 1\\cdot\\pabs{p^{N_{i+1}}} \\to 0 \\qquad \\text{as } i \\to +\\infty.\n\t\t\t\\]\n\t\t\tWe choose the integers $N_i$ by induction. We have already set $N_0 = 0$ and suppose that we have defined $N_j$ for $j \\leq i$, so that we have $a_i = \\sum_{j=0}^i b_jp^{N_j}$. Let $K = \\Qp(b_i)$: $K$ is a Galois unramified extension of $\\Qp$ of degree $i!$ and $\\Qp(a_i) = K$. In-fact, if $\\Qp(a_i) \\subsetneq K$ there would be a non trivial $\\Qp$-automorphism of $K$ which leaves $a_i$ fixed, let it be $\\sigma$. By assumption $\\sigma(b_i) \\neq b_i$ and\n\t\t\t\\[\n\t\t\t\t\\sigma(a_i) = \\sum_{j=0}^i \\sigma(b_j)p^{N_j} \\qquad (\\sigma(b_j)^{p^{i!}} = \\sigma(b_j) \\quad \\forall j=0,\\dots,i).\n\t\t\t\\]\n\t\t\tWe see that $\\sigma(a_i)$ can't be equal to $a_i$ because it has a different \\padic expansion (see \\cref{corollary:teichmuller-digits}) so it must be $K = \\Qp(a_i)$ and $a_i$ is algebraic over $\\Qp$ of degree $i!$. Thanks to \\cref{exercise:9-p57} we can find $N_{i+1} > N_i$ such that $a_i$ does not satisfy any congruence\n\t\t\t\\[\n\t\t\t\t\\alpha_na_i^n + \\alpha_{n-1}a_i^{n-1} + \\dots + \\alpha_1a_i + \\alpha_0 \\equiv 0 \\mod p^{N_{i+1}}\n\t\t\t\\]\n\t\t\tfor $n < i!$ and $\\alpha_j \\in \\Zp$ not all divisible by $p$. We have now completely determined our sequence $(a_i)_i$. Now, suppose that $a \\in \\Qpa$ is the limit of $(a_i)_i$. By definition, $a$ is algebraic over $\\Qp$ so it satisfies a polynomial equation in $\\Qp$\n\t\t\t\\[\n\t\t\t\t\\beta_na^n + \\beta_{n-1}a^{n-1} + \\dots + \\beta_1a + \\beta_0 = 0 \n\t\t\t\\]\n\t\t\tand, multiplying by a suitable power of $p$, we can assume that $\\beta_i \\in \\Zp$ and that there is at least a coefficient in $\\Zp^\\times$. Let's choose $i$ such that $i! > n$. We have\n\t\t\t\\begin{gather*}\n\t\t\t\t\\pabs{a_j - a_i} \\leq \\pabs{p^{N_{i+1}}} \\quad \\forall\\,j > i \\implies \\pabs{a - a_i} = \\lim_{j \\to +\\infty} \\pabs{a_j - a_i} \\leq \\pabs{p^{N_{i+1}}}\n\t\t\t\\end{gather*}\n\t\t\tso $a \\equiv a_i \\mod p^{N_{i+1}}$. This implies\n\t\t\t\\[\n\t\t\t\t\\beta_na_i^n + \\beta_{n-1}a_i^{n-1} + \\dots + \\beta_1a_i + \\beta_0 \\equiv 0 \\mod p^{N_{i+1}}\n\t\t\t\\]\n\t\t\twhich is a contradiction. Then $(a_i)_i$ cannot have limit in $\\Qpa$ and this proves the theorem.\n\t\t\\end{proof}\n\t\tWe can then complete $\\Qpa$ exactly in the same way we completed $(\\Q, \\pabs{\\ })$ in \\cref{section:construction-Qp} (this is the standard way to complete a metric space). \n\t\t\\begin{defn}\n\t\t\tThe completion of $\\Qpa$ is called $\\Cp$.\n\t\t\\end{defn}\n\t\tWe can extend the \\padic absolute value to this new field $\\Cp$ just as we extended it from $\\Q$ to $\\Qp$: given $x \\in \\Cp$, we choose a representative Cauchy sequence $(x_i)_i$ in $\\Qpa$ (recall that $\\Cp$ is the set of equivalence classes of Cauchy sequences), and we define \n\t\t\\[\n\t\t\t\\pabs{x} := \\lim_{i \\to +\\infty} \\pabs{x_i}.\n\t\t\\]\n\t\tIt can be proved that $\\pabs{x}$ is well defined and that the limit exists: if $x \\neq 0$ then from a sufficiently large $i$ all norms $\\pabs{x_i}$ are equal. We can also extend $\\ord$ to $\\Cp$:\n\t\t\\[\n\t\t\t\\ord x := -\\log_p \\pabs{x}.\n\t\t\\]\n\t\tLet $A = \\{x \\in \\Cp \\mid \\pabs{x} \\leq 1\\}$ be the valuation ring of $\\Cp$ and $M = \\{x \\in \\Cp \\mid \\pabs{x} < 1\\}$ its maximal ideal. \n\t\t\\begin{defn}\n\t\t\tLet $r = a/b \\in \\Q$ with $a \\in \\Z, b \\in \\N^\\times$ and $P(X) = X^b - p^a \\in \\Qp[X]$. Any root of $P(X)$ in $\\Qpa$ is called a \\emph{fractional power} of $p$ to $r$ and can be denoted by $p^r$.\n\t\t\\end{defn}\n\t\tUsing fractional powers we can immediately prove an interesting result.\n\t\t\\begin{prop}\n\t\t\t\\label{prop:qpa-every-order}\n\t\t\tFor any $q \\in \\Q$ there exists $x \\in \\Qpa$ with $\\mathrm{ord}_p\\,x = q$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tLet's write $q = a/b$ with $a \\in \\Z, b \\in \\N^{\\times}$ and let $\\Qpa \\ni x = p^q$ be any fractional power. We claim that $\\ord x = q$, i.e. $\\pabs{x} = p^{-q}$. In-fact, by definition of fractional power, we have $x^b = p^a$, which implies $\\pabs{x} = p^{-a/b}$.\n\t\t\\end{proof}\n\t\tWith the next proposition we'll dig deeper into the structure of $\\Cp$, to understand how its elements can be represented (working with equivalence classes of Cauchy sequences is not very practical).\n\t\t\\begin{prop}\n\t\t\t\\label{prop:structure-Cp}\n\t\t\tAny non-zero element of $\\,\\Cp$ is a product of a fractional power of $p$, a root of unity and an element in the open unit disc about $1$ (in $\\Cp$).\n\t\t\\end{prop} \n\t\t\\begin{proof}\n\t\t\tLet's first consider the case of $x \\in A^\\times$, i.e. $\\pabs{x} = 1$. Since $\\Qpa$ is dense in $\\Cp$ we can find an algebraic $x'$ such that $\\pabs{x - x'} < 1$, i.e. $x - x' \\in M$. By the isosceles triangle principle we obtain $\\pabs{x'} = 1$ so it follows that $x'$ is integral over $\\Zp$ (see \\cref{prop:finite-extension-A-integral-closure-Zp}), i.e. it satisfies a monic polynomial in $\\Zp[X]$. Reducing this polynomial mod $p$ we find that $x + M = x' + M$ is algebraic over $\\Zp/p\\Zp = \\Fp$ so it lies in some $\\F_{p^f}$. We can consider $\\omega(x)$, the Teichm{\\\"u}ller representative of $x + M \\in \\F_{p^f}$, which is a $(p^f - 1)$th root of $1$ (i.e. it is an element of $K_f^{\\textup{unram}} \\subset \\Qpa$ which is a solution of $X^{p^f} - X = 0$ and is congruent to $x + M$ mod $p$, see proof of \\cref{prop:structure-finite-extension}). If we set $\\langle x \\rangle := x/\\omega(x)$, then $\\langle x \\rangle \\in 1 + M$. We have proved that any element of $A^\\times$ is the product of a root of unity $\\omega(x)$ and an element $\\langle x \\rangle$ which is in the open unit disc about $1$.\\newline\n\t\t\tFinally, any $x \\in \\Cp$ can be written as a product of a fractional power of $p$ and an element of absolute value $1$. Namely, if $\\ord x = r = a/b$ (observe that $\\ord(\\Cp^{\\times}) \\subset \\Q$) and $p^r \\in \\Qpa$ is any root of $X^b - p^a$, then $\\pabs{p^r} = \\pabs{p}^{a/b}$ ($p^r$ is a root of $p^{-a}X^b - 1 = 0$) so\n\t\t\t\\[\n\t\t\t\t\\pabs{x/p^r} = \\pabs{x} \\cdot \\frac{1}{\\pabs{p^r}} = \\pabs{p}^{a/b} \\cdot \\pabs{p}^{-a/b} = 1\n\t\t\t\\]\n\t\t\tand, called $x_1 := x/p^r \\in A^\\times$, we know that $x_1$ is a product of a root of $1$ and an element in $1 + M = B_{<1}(1, \\Cp)$.\n\t\t\\end{proof}\n\t\tObviously, by construction, $\\Cp$ is a complete field which contains $\\Qpa$. It is then an immediate question if $\\Cp$ is still algebraically closed and we'll see in the next theorem that it is.\n\t\t\\begin{thm}\n\t\t\t$\\Cp$ is algebraically closed.\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tLet's consider a generic monic polynomial in $\\Cp[X]$:\n\t\t\t\\[\n\t\t\t\tf(X) = X^n + a_{n-1}X^{n-1} + \\dots + a_1X + a_0.\n\t\t\t\\] \n\t\t\tWe just need to show that $f$ admits a root in $\\Cp$. For each $i=0,1,\\dots,n-1$, let $(a_{i,j})_{j \\in \\N}$ be a sequence of elements in $\\Qpa$ which converges to $a_i$. Let's consider the sequence $(g_j(X))_{j \\in \\N} \\subset \\Qpa[X]$ defined by\n\t\t\t\\[\n\t\t\t\tg_j(X) := X^n + a_{n-1,j}X^{n-1} + \\dots + a_{1,j}X + a_{0,j}.\n\t\t\t\\]\n\t\t\tLet $\\{r_{i,j}\\}_{i=1}^n \\subset \\Qpa$ be the roots of $g_j(X)$. We claim that we can find a sequence $(i_j)_{j \\in \\N} \\subset \\N$ such that the sequence $(r_{i_j, j})_j$ is Cauchy. \\newline\n\t\t\tLet's proceed by induction and suppose we have $r_{i_h, h}$ and we want to find $r_{i_{h+1}, h+1}$. Let $\\delta_h := \\pabs{g_h - g_{h+1}} = \\max_i \\pabs{a_{i,h} - a_{i, h+1}}$, which clearly approaches $0$ as $j \\to +\\infty$, and let $A_h := \\max\\{1, \\pabs{r_{i_h, h}}^n\\}$. Now, thanks to \\cref{exercise:3-p73}, we can find $C_j$, a constant depending only on $\\max_i \\pabs{a_{i, j}}$, which dominates the norm of each root of $g_j(X)$ and such that $A_j \\leq C_j$. Since $(a_{i, j})_j$ is a convergent sequence in $\\Qpa$, it is bounded in norm for every $i=0, \\dots, n-1$ so we can find a uniform constant $C$ such that $C_j \\leq C$ for every $j \\in \\N$. Then we have\n\t\t\t\\[\n\t\t\t\t\\prod_{i=1}^n \\pabs{r_{i_h, h} - r_{i, h+1} } = \\pabs{g_{h+1}(r_{i_h, h})} = \\pabs{g_{h+1}(r_{i_h, h}) - g_h(r_{i_h, h})} \\leq \\delta_hC\n\t\t\t\\]\n\t\t\thence there is at least one $i$ such that $\\pabs{r_{i_h, h} - r_{i, h+1}} \\leq \\sqrt[n]{\\delta_hC}$. Let $i_{h+1}$ be such $i$. Since $\\delta_j \\to 0$ as $j \\to +\\infty$, it is clear that $(r_{i_j, j})_j$ is Cauchy in $\\Qpa$. Since $\\Cp$ is complete, this sequence converges and if we define\n\t\t\t\\[\n\t\t\t\tr := \\lim_{j \\to +\\infty} r_{i_j, j} \\in \\Cp\n\t\t\t\\]\n\t\t\twe then have\n\t\t\t\\[\n\t\t\t\tf(r) = f\\left(\\lim_{j \\to +\\infty} r_{i_j, j}\\right) = \\lim_{j \\to +\\infty} f(r_{i_j, j}) = \\lim_{j \\to +\\infty} \\lim_{m \\to +\\infty} g_m(r_{i_j, j})\n\t\t\t\\]\n\t\t\twhere we used that $f$ is continuous and that $g_j \\xrightarrow{\\norm{\\ }_{\\infty}} f$ (which implies punctual convergence). More precisely, since this double limit exists, we can consider the section $m = j$ to obtain\n\t\t\t\\[\n\t\t\t\t\\lim_{j \\to +\\infty} \\lim_{m \\to +\\infty} g_m(r_{i_j, j}) = \\lim_{j \\to +\\infty} g_j(r_{i_j, j}) = 0\n\t\t\t\\] \n\t\t\tso we can conclude $f(r) = 0$ and $r \\in \\Cp$ is a root of $f$.\n\t\t\\end{proof}\n\t\tFinally, after all this effort, we have built $\\Cp$: the smallest field which contains $\\Q$ and is both algebraically closed and complete with respect to $\\pabs{\\ }$ (we recall that completion and algebraic closure are unique processes up to isomorphism). Let's observe some basic properties of this field:\n\t\t\\begin{enumerate}\n\t\t\t\\item $\\pabs{\\Cp} = \\pabs{\\Qpa} = p^\\Q \\cup \\{0\\}$;\n\t\t\t\\item $\\card(\\Cp) = \\card(\\R)$;\n\t\t\t\\item $\\Cp$ is a field isomorphic to $\\C$, although not in a canonical way.\n\t\t\\end{enumerate}\n\t\tWhile property $1.$ is evident, the other properties aren't so obvious and we'll have faith in them, i.e. we won't prove them.\n\t\t\n\t\tActually, we could have built $\\Cp$ in an apparently shorter way:\n\t\t\\begin{equation*}\n\t\t\t\\begin{tikzcd}\n\t\t\t\t& &  \\C \\\\\n\t\t\t\t\\Q \\arrow[r, \"\\textup{alg cl}\"] & \\Q^{\\textup{alg cl}} \\arrow[ur, \"\\abs{\\ }_{\\infty}\"] \\arrow[dr, \"\\pabs{\\ }\"'] \\\\\n\t\t\t\t& & \\Cp\n\t\t\t\\end{tikzcd}\n\t\t\\end{equation*}\n\t\tnamely by first embedding $\\Q$ in $\\Q^{\\textup{alg cl}}$, its algebraic closure (clearly it does not depend on the chosen norm), and then completing $\\Q^{\\textup{alg cl}}$ with respect to the euclidean norm (we obtain $\\C$) and to the \\padic norm (we obtain $\\Cp$). \n\t\tWe could have chosen to follow this way, which highlights the similarity between $\\C$ and $\\Cp$, without even needing the intermediate field $\\Qp$. The problem is that the algebraic closure of $\\Q$ is a very complicate field. \n\t\t\\begin{comment}\n\t\t(for example it's not a local field, meaning that its )\n\t\t\\end{comment} \n\t\tInstead, the road we decided to follow is this longer one:\n\t\t\\begin{equation*}\n\t\t\t\\begin{tikzcd}\n\t\t\t\t& \\R \\arrow[r, \"\\text{alg cl}\"] & \\C \\\\\n\t\t\t\t\\Q \\arrow[ur, \"\\abs{\\ }_{\\infty}\"] \\arrow[dr, \"\\pabs{\\ }\"'] \\\\\n\t\t\t\t& \\Qp \\arrow[r, \"\\text{alg cl}\"] & \\Qpa \\arrow[r, \"\\pabs{\\ }\"] & \\Cp\n\t\t\t\\end{tikzcd}\n\t\t\\end{equation*}\n\t\tHere we can see that the ``euclidean case'' seems simpler and that's because $\\C$, the algebraic closure of $\\R$, has a finite degree over $\\R$ (namely $[\\C : \\R] = 2$) so it's still complete, while $[\\Qpa : \\Qp] = +\\infty$ and completeness is lost: we have to complete again and we obtain $\\Cp$. The following general theorem holds.\n\t\t\\begin{thm}\n\t\t\tLet $(K, \\norm{\\ })$ be an algebraically closed non-Archimedean normed field. Then the completion of $K$ is algebraically closed.\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tSee \\cite[2]{conrad:algebraic-closure}.\n\t\t\\end{proof}", "meta": {"hexsha": "ace56c3f689295f4dcbc0a6221a91d15fda18d16", "size": 68452, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mainmatter/chapter3.tex", "max_stars_repo_name": "carlo300/BachelorThesis", "max_stars_repo_head_hexsha": "d7c1311e2abc12c80ffac864b74b214e6a63b9fb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-21T10:59:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-29T10:11:24.000Z", "max_issues_repo_path": "Mainmatter/chapter3.tex", "max_issues_repo_name": "carlo300/BachelorThesis", "max_issues_repo_head_hexsha": "d7c1311e2abc12c80ffac864b74b214e6a63b9fb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mainmatter/chapter3.tex", "max_forks_repo_name": "carlo300/BachelorThesis", "max_forks_repo_head_hexsha": "d7c1311e2abc12c80ffac864b74b214e6a63b9fb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 82.5717732207, "max_line_length": 1179, "alphanum_fraction": 0.6288786303, "num_tokens": 26104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311856832191, "lm_q2_score": 0.8991213840277783, "lm_q1q2_score": 0.7084457781901443}}
{"text": "\\section{Equivalence of Literal Performances}\n\\label{equivalence}\n\nA {\\em literal performance} is one in which no aesthetic\ninterpretation is given to a musical object.  The function {\\tt\nperform} in fact yields a literal performance; aesthetic nuances must\nbe expressed explicitly using note and phrase attributes.\n\nThere are many musical objects whose literal performances we expect to\nbe {\\em equivalent}.  For example, the following two musical objects\nare certainly not equal as data structures, but we would expect their\nliteral performances to be identical:\n\\begin{center}\n{\\tt (m1 :+: m2) :+: (m3 :+: m4)} \\\\\n{\\tt m1 :+: m2 :+: m3 :+: m4}\n\\end{center}\nThus we define a notion of equivalence:\n\n\\paragraph{Definition:}\nTwo musical objects {\\tt m1} and {\\tt m2} are {\\em equivalent}, written\n\\verb|m1|$\\ \\equiv\\ $\\verb|m2|, if and only if:\n\\begin{center}\n($\\forall$\\verb|imap,c|)\\ \\ \\ {\\tt perform imap c m1 = perform imap c m2}\n\\end{center}\nwhere ``\\verb|=|'' is equality on values (which in Haskell is defined\nby the underlying equational logic).\n\nOne of the most useful things we can do with this notion of\nequivalence is establish the validity of certain {\\em transformations}\non musical objects.  A transformation is {\\em valid} if the result of\nthe transformation is equivalent (in the sense defined above) to the\noriginal musical object; i.e.~it is ``meaning preserving.''  \n\nThe most basic of these transformation we treat as {\\em axioms} in an\n{\\em algebra of music}.  For example:\n\n\\begin{axiom}\nFor any {\\tt r1}, {\\tt r2}, {\\tt r3}, {\\tt r4}, and {\\tt m}:\n\\begin{center}\n{\\tt Tempo r1 r2 (Tempo r3 r4 m)} $\\ \\ \\equiv\\ \\ $ {\\tt Tempo (r1*r3) (r2*r4) m}\n\\end{center}\n\\end{axiom}\n\nTo prove this axiom, we use conventional equational reasoning (for\nclarity we omit {\\tt imap} and simplify the context to just {\\tt dt}):\n\\paragraph*{Proof:}\n\\begin{verbatim} \nperform dt (Tempo r1 r2 (Tempo r3 r4 m))\n= perform (r2*dt/r1) (Tempo r3 r4 m)       -- unfolding perform\n= perform (r4*(r2*dt/r1)/r3) m             -- unfolding perform\n= perform ((r2*r4)*dt/(r1*r3)) m           -- simple arithmetic\n= perform dt (Tempo (r1*r3) (r2*r4) m)     -- folding perform\n\\end{verbatim} \n\nHere is another useful transformation and its validity proof (for\nclarity in the proof we omit {\\tt imap} and simplify the context to\njust {\\tt (t,dt)}):\n\n\\begin{axiom}\nFor any {\\tt r1}, {\\tt r2}, {\\tt m1}, and {\\tt m2}:\n\\begin{center}\n{\\tt Tempo r1 r2 (m1 :+:\\ m2)} $\\ \\ \\equiv\\ \\ $ {\\tt Tempo r1 r2 m1 :+:\\ Tempo r1 r2 m2}\n\\end{center}\n\\end{axiom}\nIn other words, {\\em tempo scaling distributes over sequential\ncomposition}.\n\\paragraph*{Proof:}\n\\begin{verbatim} \nperform (t,dt) (Tempo r1 r2 (m1 :+: m2))\n= perform (t,r2*dt/r1) (m1 :+: m2)                      -- unfolding perform\n= perform (t,r2*dt/r1) m1 ++ perform (t',r2*dt/r1) m2   -- unfolding perform\n= perform (t,dt) (Tempo r1 r2 m1) ++ \n          perform (t',dt) (Tempo r1 r2 m2)              -- folding perform\n= perform (t,dt) (Tempo r1 r2 m1) ++ \n          perform (t'',dt) (Tempo r1 r2 m2)             -- folding dur\n= perform (t,dt) (Tempo r1 r2 m1 :+: Tempo r1 r2 m2)    -- folding perform\nwhere t'  = t + (dur m1)*r2*dt/r1\n      t'' = t + (dur (Tempo r1 r2 m1))*dt\n\\end{verbatim} \n\nAn even simpler axiom is given by:\n\n\\begin{axiom}\nFor any {\\tt r} and {\\tt m}:\n\\begin{center}\n{\\tt Tempo r r m} $\\ \\ \\equiv\\ \\ $ {\\tt m}\n\\end{center}\n\\end{axiom}\nIn other words, {\\em unit tempo scaling is the identity}.\n\\paragraph*{Proof:}\n\\begin{verbatim} \nperform (t,dt) (Tempo r r m)\n= perform (t,r*dt/r) m                       -- unfolding perform\n= perform (t,dt) m                           -- simple arithmetic\n\\end{verbatim} \n\nNote that the above proofs, being used to establish axioms, all\ninvolve the definition of {\\tt perform}.  In contrast, we can also\nestablish {\\em theorems} whose proofs involve only the axioms.  For\nexample, Axioms 1, 2, and 3 are all needed to prove the following:\n\\begin{theorem}\nFor any {\\tt r1}, {\\tt r2}, {\\tt m1}, and {\\tt m2}:\n\\begin{center}\n{\\tt Tempo r1 r2 m1 :+:\\ m2} $\\ \\ \\equiv\\ \\ $ {\\tt Tempo r1 r2 (m1 :+:\\ Tempo r2 r1 m2)}\n\\end{center}\n\\end{theorem}\n\\paragraph*{Proof:}\n\\begin{verbatim} \nTempo r1 r2 (m1 :+: Tempo r2 r1 m2)\n= Tempo r1 r2 m1 :+: Tempo r1 r2 (Tempo r2 r1 m2)     -- by Axiom 1\n= Tempo r1 r2 m1 :+: Tempo (r1*r2) (r2*r1) m2         -- by Axiom 2\n= Tempo r1 r2 m1 :+: Tempo (r1*r2) (r1*r2) m2         -- simple arithmetic\n= Tempo r1 r2 m1 :+: m2                               -- by Axiom 3\n\\end{verbatim} \nFor example, this fact justifies the equivalence of the two phrases\nshown in Figure \\ref{equiv}.\n\n\\begin{figure*}\n\\centerline{\n\\epsfysize=.6in \n\\epsfbox{Pics/equiv.eps}\n}\n\\caption{Equivalent Phrases}\n\\label{equiv}\n\\end{figure*}\n\nMany other interesting transformations of Haskore musical objects can\nbe stated and proved correct using equational reasoning.  We leave as\nan exercise for the reader the proof of the following axioms (which\ninclude the above axioms as special cases).\n\n\\begin{axiom}\n{\\tt Tempo} is {\\em multiplicative} and {\\tt Transpose} is {\\em\nadditive}.  That is, for any {\\tt r1}, {\\tt r2}, {\\tt r3}, {\\tt r4},\n{\\tt p}, and {\\tt m}:\n\\begin{center}\n{\\tt Tempo r1 r2 (Tempo r3 r4 m)} $\\ \\ \\equiv\\ \\ $ {\\tt Tempo (r1*r3) (r2*r4) m}\\\\\n{\\tt Trans p1 (Trans p2 m)} $\\ \\ \\equiv\\ \\ $ {\\tt Trans (p1+p2) m}\n\\end{center}\n\\end{axiom}\n\\begin{axiom}\nFunction composition is {\\em commutative} with respect to both tempo\nscaling and transposition.  That is, for any {\\tt r1}, {\\tt r2}, {\\tt\nr3}, {\\tt r4}, {\\tt p1} and {\\tt p2}:\n\\begin{center}\n{\\tt Tempo r1 r2 .\\ Tempo r3 r4} $\\ \\ \\equiv\\ \\ $ {\\tt Tempo r3 r4 .\\ Tempo r1 r2}\\\\\n{\\tt Trans p1 .\\ Trans p2} $\\ \\ \\equiv\\ \\ $ {\\tt Trans p2 .\\ Trans p1}\\\\\n{\\tt Tempo r1 r2 .\\ Trans p1} $\\ \\ \\equiv\\ \\ $ {\\tt Trans p1 .\\ Tempo r1 r2}\\\\\n\\end{center}\n\\end{axiom}\n\\begin{axiom}\nTempo scaling and transposition are {\\em distributive} over both\nsequential and parallel composition.  That is, for any {\\tt r1}, {\\tt\nr2}, {\\tt p}, {\\tt m1}, and {\\tt m2}:\n\\begin{center}\n{\\tt Tempo r1 r2 (m1 :+:\\ m2)} $\\ \\ \\equiv\\ \\ $ {\\tt Tempo r1 r2 m1 :+:\\ Tempo r1 r2 m2}\\\\\n{\\tt Tempo r1 r2 (m1 :=:\\ m2)} $\\ \\ \\equiv\\ \\ $ {\\tt Tempo r1 r2 m1 :=:\\ Tempo r1 r2 m2}\\\\\n{\\tt Trans p (m1 :+:\\ m2)} $\\ \\ \\equiv\\ \\ $ {\\tt Trans p m1 :+:\\ Trans p m2}\\\\\n{\\tt Trans p (m1 :=:\\ m2)} $\\ \\ \\equiv\\ \\ $ {\\tt Trans p m1 :=:\\ Trans p m2}\n\\end{center}\n\\end{axiom}\n\\begin{axiom}\nSequential and parallel composition are {\\em associative}.  That is,\nfor any {\\tt m0}, {\\tt m1}, and {\\tt m2}:\n\\begin{center}\n{\\tt m0 :+:\\ (m1 :+:\\ m2)} $\\ \\ \\equiv\\ \\ $ {\\tt (m0 :+:\\ m1) :+:\\ m2}\\\\\n{\\tt m0 :=:\\ (m1 :=:\\ m2)} $\\ \\ \\equiv\\ \\ $ {\\tt (m0 :=:\\ m1) :=:\\ m2}\n\\end{center}\n\\end{axiom}\n\\begin{axiom}\nParallel composition is {\\em commutative}.  That is, for any {\\tt m0}\nand {\\tt m1}:\n\\begin{center}\n{\\tt m0 :=:\\ m1} $\\ \\ \\equiv\\ \\ $ {\\tt m1 :=:\\ m0}\n\\end{center}\n\\end{axiom}\n\\begin{axiom}\n{\\tt Rest 0} is a {\\em unit} for {\\tt Tempo} and {\\tt Trans}, and a\n{\\em zero} for sequential and parallel composition.  That is, for any\n{\\tt r1}, {\\tt r2}, {\\tt p}, and {\\tt m}:\n\\begin{center}\n{\\tt Tempo r1 r2 (Rest 0)} $\\ \\ \\equiv\\ \\ $ {\\tt Rest 0}\\\\\n{\\tt Trans p (Rest 0)} $\\ \\ \\equiv\\ \\ $ {\\tt Rest 0}\\\\\n{\\tt m :+:\\ Rest 0} $\\ \\ \\equiv\\ \\ $ {\\tt m} $\\ \\ \\equiv\\ \\ $ {\\tt Rest 0 :+:\\ m}\\\\\n{\\tt m :=:\\ Rest 0} $\\ \\ \\equiv\\ \\ $ {\\tt m} $\\ \\ \\equiv\\ \\ $ {\\tt Rest 0 :=:\\ m} \n\\end{center}\n\\end{axiom}\n\n\\begin{exercise} Establish the validity of each of the above axioms.\n\\end{exercise}\n\n", "meta": {"hexsha": "ae1ad282ea68f563935346b927f4c6d1916236bd", "size": 7475, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SOE/haskore/src/Equiv.tex", "max_stars_repo_name": "jtestard/cse230Winter2015", "max_stars_repo_head_hexsha": "0c281a83d79726355cd5f48f07c13557d7c32f13", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-02-15T00:16:40.000Z", "max_stars_repo_stars_event_max_datetime": "2016-02-15T00:16:40.000Z", "max_issues_repo_path": "SOE/haskore/src/Equiv.tex", "max_issues_repo_name": "jtestard/cse230Winter2015", "max_issues_repo_head_hexsha": "0c281a83d79726355cd5f48f07c13557d7c32f13", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SOE/haskore/src/Equiv.tex", "max_forks_repo_name": "jtestard/cse230Winter2015", "max_forks_repo_head_hexsha": "0c281a83d79726355cd5f48f07c13557d7c32f13", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9322916667, "max_line_length": 90, "alphanum_fraction": 0.6266220736, "num_tokens": 2564, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.8902942333990421, "lm_q1q2_score": 0.7083698268712146}}
{"text": "\\section{Finite Markov Decision Processes}\nWe say that a system has the \\emph{Markov property} if each state includes all information about the previous states and actions that makes a difference to the future.\\\\\n\nThe MDP provides an abstraction of the problem of goal-directed learning from interaction by modelling the whole thing as three signals: action, state, reward.\\\\\n\nTogether, the MDP and agent give rise to the \\emph{trajectory} $S_0$, $A_0$, $R_1$, $S_1$, $A_1$, $S_2$, $R_2$, $\\dots$. The action choice in a state gives rise (stochastically) to a state and corresponding reward.\n\n\\subsection{The Agent–Environment Interface}\nWe consider finite Markov Decision Processes (MDPs). The word finite refers to the fact that the states, rewards and actions form a finite set. This framework is useful for many reinforcement learning problems.\\\\\n\nWe call the learner or decision making component of a system the \\emph{agent}. Everything else is the \\emph{environment}. General rule is that anything that the agent does not have absolute control over forms part of the environment. For a robot the environment would include it's physical machinery. The boundary is the limit of absolute control of the agent, not of its knowledge.\\\\\n\nThe MDP formulation is as follows. Index time-steps by $t \\in \\mathbb{N}$. Then actions, rewards, states at $t$ represented by $A_t \\in \\mathcal{A}(s)$, $R_t \\in \\mathcal{R} \\subset \\mathbb{R}$, $S_t \\in \\mathcal{S}$. Note that the set of available actions is dependent on the current state.\\\\\n\nA key quantity in an MDP is the following function, which defines the \\emph{dynamics} of the system.\n\\begin{equation}\n    p(s', r | s, a) \\doteq \\P{} (S_t = s', R_t = r | S_{t-1} = s, A_{t-1} = a)\n\\end{equation}\nFrom this quantity we can get other useful functions. In particular we have the following: \n\n\\begin{description}\n    \\item[state-transition probabilities]\n\\begin{equation}\n    p(s' | s, a) \\doteq \\P{}(S_t = s'| S_{t-1} = s, A_{t-1}=A) = \\sum_{r \\in \\mathcal{R}} p(s', r | s, a)\n\\end{equation}\nnote the abuse of notation using $p$ again; and,\n    \\item[expected reward]\n\\begin{equation}\n    r(s, a) = \\mathbb{E}[R_t | S_{t-1} = s, A_{t-1} = a] = \\sum_{r \\in \\mathcal{R}} r \\sum_{s' \\in \\mathcal{S}} p(s', r | s, a).\n\\end{equation}\n\\end{description}\n\n\n\\subsection{Goals and rewards}\nWe have the \\emph{reward hypothesis}, which is a central assumption in reinforcement learning:\n\\begin{quote}\n    All of what we mean by goals and purposes can be well thought of as the maximisation of the expected value of the cumulative sum of a received scalar signal (called reward).\n\\end{quote}\n\n\n\\subsection{Returns and Episodes}\nDenote the sequence of rewards from time $t$ as $R_{t+1}$, $R_{t+2}$, $R_{t+3}$, $\\dots$. We seek to maximise the \\emph{expected return} $G_t$ which is some function of the rewards. The simplest case is where $G_t = \\sum_{\\tau > t} R_\\tau$.\\\\\n\nIn some applications there is a natural final time-step which we denote $T$. The final time-step corresponds to a \\emph{terminal state} that breaks the agent-environment interaction into subsequences called \\emph{episodes}. Each episode ends in the same terminal state, possibly with a different reward. Each starts independently of the last, with some distribution of starting states. We denote the set of states including the terminal state as $\\mathcal{S}^+$\\\\\n\nSequences of interaction without a terminal state are called \\emph{continuing tasks}. \\\\\n\nWe define $G_t$ using the notion of \\emph{discounting}, incorporating the \\emph{discount rate} $0 \\leq \\gamma \\leq 1$. In this approach the agent chooses $A_t$ to maximise \n\\begin{equation}\n    G_t \\doteq \\sum_{k = 0}^{\\infty} \\gamma^k R_{t+k+1}.\n\\end{equation}\n This sum converges wherever the sequence $R_t$ is bounded. If $\\gamma = 0$ the agent is said to be myopic. We define $G_T = 0$. Note that\n\\begin{equation}\n     G_t = R_{t+1} + \\gamma G_{t+1}.\n\\end{equation}\\\\\n\nNote that in the case of finite time steps or an episodic problem, then the return for each episode is just the sum (or whatever function) of the returns in that episode.\n\n\n\\subsection{Unified Notation for Episodic and Continuing Tasks}\nWe want to unify the notation for episodic and continuing learning. \\\\\n\nWe introduce the concept of an \\emph{absorbing state}. This state transitions only to itself and gives reward of zero.\\\\\n\nTo incorporate the (disjoint) possibilites that $T=\\infty$ or $\\gamma = 1$ in our formulation of the return, we might like to write\n\\begin{equation}\n    G_t \\doteq \\sum_{k=t+1}^T \\gamma^{k-t-1}R_k.\n\\end{equation}\n\n\n\\subsection{Policies \\& Value Functions}\n\\subsubsection*{Policy}\nA \\emph{policy} $\\pi(a|s)$ is a mapping from states to the probability of selecting actions in that state. If an agent is following policy $\\pi$ and at time $t$ is in state $S_t$, then the probability of taking action $A_t$ is $\\pi(a|s)$. Reinforcement learning is about altering the policy from experience.\\\\\n\n\\subsubsection*{Value Functions}\nAs we have seen, a central notion is the value of a state. The \\emph{state-value function} of state $s$ under policy $\\pi$ is the expected return starting in $s$ and following $\\pi$ thereafter. For MDPs this is\n\\begin{equation}\n    v_\\pi \\doteq \\Epi[G_t | S_t = s],\n\\end{equation}\nwhere the subscript $\\pi$ denotes that this is an expectation taken conditional on the agent following policy $\\pi$. \\\\\n\nSimilarly, we define the \\emph{action-value function} for policy $\\pi$ to be the expected return from taking action $a$ in state $s$ and following $\\pi$ thereafter\n\\begin{equation}\n    q_\\pi(s, a) \\doteq \\Epi[G_t | S_t = s, A_t = a].\n\\end{equation}\n\nThe value functions $v_\\pi$ and $q_\\pi$ can be estimated from experience.\\\\\n\n\\subsubsection*{Bellman Equation}\n\nThe Bellman equations express the value of a state in terms of the value of its successor states. They are a consistency condition on the value of states. \n\n\\begin{align}\n    v_{\\pi}(s) &= \\Epi{}[G_t | S_t = s] \\\\\n             &= \\Epi{}[R_{t+1} + \\gamma G_{t+1} | S_t = s] \\\\\n             &= \\sum_{a \\in \\mathcal{A}(s)} \\pi(a|s) \\sum_{s', r} p(s', r | s, a) \\left[r + \\gamma \\Epi{}[G_{t+1} | S_{t+1} = s']\\right] \\\\\n             &=  \\sum_{a \\in \\mathcal{A}(s)} \\pi(a|s) \\sum_{s', r} p(s', r | s, a) [r + \\gamma v_{\\pi}(s')]\n\\end{align} \n    \n\nThe value function $v_\\pi$ is the unique solution to its Bellman equation.\n\n\n\\subsection{Optimal Policies \\& Optimal Value Functions}\nWe say that $\\pi \\geq \\pi'$ iff $v_\\pi (s) \\geq v_{\\pi'}(s) \\quad \\forall s \\in \\mathcal{S}$. The policies that are optimal in this sense are called optimal policies. There may be multiple optimal policies. We denote all of them by $\\pi_*$.\\\\\n\nThe optimal policies share the same optimal value function $v_*(s)$\n\\begin{equation}\n    v_*(s) \\doteq \\max_\\pi v_\\pi(s) \\quad \\forall s \\in \\mathcal{S}.\n\\end{equation}\nThey also share the same optimal action-value function $q_*(s, a)$\n\\begin{equation}\n    q_*(s, a) = \\max_\\pi q_\\pi (s, a) \\quad \\forall s \\in \\mathcal{S}, a \\in \\mathcal{A}(s),\n\\end{equation}\nthis is the expected return from taking action $a$ in state $s$ and thereafter following the optimal policy.\n\\begin{equation}\n    q_*(s, a) = \\E{} [R_{t+1} + \\gamma v_*(S_{t+1}) | S_{t} = s, A_t = a].\n\\end{equation}\\\\\n\nSince $v_*$ is a value function, it must satisfy a Bellman equation (since it is simply a consistency condition). However, $v_*$ corresponds to a policy that always selects the maximal action. Hence \n\\begin{equation}\n    v_*(s) = \\max_a \\sum_{s', r} p(s', r|s, a) [r + \\gamma v_*(s')].\n\\end{equation}\nSimilarly,\n\\begin{align}\n    q_*(s, a) &= \\mathbb{E} [R_{t+1} + \\gamma \\max_{a'}q_*(S_{t+1}, a') | S_t=s, A_t = a]\\\\\n              &= \\sum_{s', r} p(s', r| s, a ) [r + \\gamma \\max_{a'}q_*(s', a')].\n\\end{align} \\\\\n\nNote that once one identifies an optimal value function $v_*$, then it is simple to find an optimal policy. All that is needed is for the policy to act greedily with respect to $v_*$. Since $v_*$ encodes all information on future rewards, we can act greedily and still make the long term optimal decision (according to our definition of returns).\\\\\n\nHaving $q_*$ is even better since we don't need to check $v_*(s')$ in the succeeding states $s'$, we just find $a_* = \\argmax_a q_*(s, a)$ when in state $s$.\n", "meta": {"hexsha": "4564588fd141eb7f41ff4f70971a554c8882714c", "size": 8276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/chapter3/chapter3_content.tex", "max_stars_repo_name": "ElliotMunro200/reinforcement_learning_an_introduction", "max_stars_repo_head_hexsha": "c4fccb46a4bb00955549be3505144ec49f0132e5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 234, "max_stars_repo_stars_event_min_datetime": "2018-09-01T00:26:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T03:55:50.000Z", "max_issues_repo_path": "notes/chapters/chapter3/chapter3_content.tex", "max_issues_repo_name": "15779235038/reinforcement_learning_an_introduction", "max_issues_repo_head_hexsha": "a0ac9e5da6eaeae14d297a560c499d1a6e579c2a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2018-11-29T21:04:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-13T17:11:50.000Z", "max_forks_repo_path": "notes/chapters/chapter3/chapter3_content.tex", "max_forks_repo_name": "15779235038/reinforcement_learning_an_introduction", "max_forks_repo_head_hexsha": "a0ac9e5da6eaeae14d297a560c499d1a6e579c2a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2018-07-31T04:53:21.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T04:03:43.000Z", "avg_line_length": 62.2255639098, "max_line_length": 463, "alphanum_fraction": 0.7025132914, "num_tokens": 2499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7083698035075631}}
{"text": "\\documentclass[11pt]{amsart}\n\\usepackage{amsmath,amsfonts,amsthm,amssymb, amsaddr}\n\n\n\\title{Distributions (Generalised Functions)}\n\n\\author{Joe Bentley}\n\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\newpage\n\n\\section{Dirac Delta Function}\n\nConsider a vector function defined as $\\mathbf{A} = \\frac{\\mathbf{r}}{r^3}$. In spherical polar coordinates this can be written as $\\mathbf{A} = \\frac{1}{r^2} \\mathbf{e_r}$. Next we calculate its divergence using the formula proved in previous notes,\n\n\\begin{align*}\n  \\nabla\\cdot\\mathbf{A} = \\frac{1}{r^2}\\frac{\\partial}{\\partial r}\\left(r^2 \\frac{1}{r^2}\\right) = 0\n\\end{align*}\n\nConsider next the divergence theorem for the same vector field $\\mathbf{A}$, also known as Gauss' theorem, which was shown to be,\n\n\\begin{align*}\n  \\int_V \\nabla\\cdot\\mathbf{A} dV = \\oint_S \\mathbf{A}\\cdot d\\mathbf{S}\n\\end{align*}\n\nBy integrating over a sphere of radius $a$ centered at the origin we see,\n\n\\begin{align*}\n  \\oint_S \\mathbf{A}\\cdot d\\mathbf{S} = \\frac{1}{a^2} 4\\pi a^2 = 4\\pi\n\\end{align*}\n\nThere appears to be a contradiction as we have just proved that $\\nabla\\cdot\\mathbf{A} = 0$, but this integral tells us that since the surface integral is non-zero, then so is the volume integral. It turns out however that we have only really proved that $\\nabla\\cdot\\mathbf{A} = 0$ when $\\mathbf{r} \\neq \\mathbf{0}$. Therefore we must have that $\\nabla\\cdot\\mathbf{A}$ suddenly blows up at $\\mathbf{r} = \\mathbf{0}$ in such a way that the integral over it has the value $4\\pi$. This result is given by a function called the Dirac delta function, in this case in 3 dimensions,\n\n\\begin{align*}\n  \\nabla\\cdot\\mathbf{A} = 4\\pi \\delta^3(\\mathbf{r})\n\\end{align*}\n\nwhere\n\n\\begin{align*}\n  \\delta^3(\\mathbf{r}) =\n  \\begin{cases}\n    0 & \\mathbf{r} \\neq \\mathbf{0} \\\\\n    \\infty & \\mathbf{r} = \\mathbf{0}\n  \\end{cases}\n\\end{align*}\n\nwhich also has the constraint,\n\n\\begin{align*}\n  \\int_V \\delta^3(\\mathbf{r}) d^3\\mathbf{r} = 1\n\\end{align*}\n\nFor example, the electric field due to a point charge at the origin is given by,\n\n\\begin{align*}\n  \\mathbf{E} = \\frac{q}{4\\pi\\epsilon_0} \\frac{\\mathbf{r}}{r^3}\n\\end{align*}\n\nThe divergence of this can thus be written as,\n\n\\begin{align*}\n  \\nabla\\cdot\\mathbf{E} = \\frac{q}{\\epsilon_0}\\delta^3(\\mathbf{r}) = \\frac{\\rho(\\mathbf{r})}{\\epsilon_0}\n\\end{align*}\n\nHere, $\\rho(\\mathbf{r}) = q\\delta^3(\\mathbf{r})$ is the charge density of a point charge $q$ at the origin. It is zero at $\\mathbf{r} \\neq \\mathbf{0}$ and infinite at $\\mathbf{r} = \\mathbf{0}$ such that the integral over its volume gives $q$.\n\nThe Dirac delta function shows up every time we mix discrete and continuous objects.\n\n\\section{The 1D Dirac Delta Function}\n\nThe one-dimensional Dirac delta function $\\delta(x)$ is defined,\n\n\\begin{align*}\n  \\delta(x) =\n  \\begin{cases}\n    0 & x \\neq 0 \\\\\n    \\infty & x = 0\n  \\end{cases}\n\\end{align*}\n\nUnder the constraint,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} \\delta(x) dx = 1\n\\end{align*}\n\nAs in the three-dimensional case, it may be defined as the limit of a sequence of functions that become increasingly peaked, getting more and more narrow. A good function to choose for this is a Gaussian distribution,\n\n\\begin{align*}\n  \\delta_n(x) = \\sqrt{\\frac{n}{\\pi}} e^{-nx^2}\n\\end{align*}\n\nWe divide by $\\sqrt{\\frac{n}{\\pi}}$ to normalise the distribution so that if we integrate over it we get one regardless of the value of $n$. We can see that the limits give us back the Dirac delta function,\n\n\\begin{alignat*}{2}\n  &\\lim_{n \\to \\infty} \\delta_n(x) = 0 \\qquad &&\\text{for } x\\neq0 \\\\\n  &\\lim_{n \\to \\infty} \\delta_n(x) = \\infty \\qquad &&\\text{for } x = 0 \\\\\n  &\\lim_{n \\to \\infty} \\int_{-\\infty}^{\\infty} \\delta_n(x) = 1\n\\end{alignat*}\n\nWe can therefore think of the Dirac delta function $\\delta(x)$ as the limit of $\\delta_n(x)$ as $n \\to \\infty$.\n\nThe key property of the delta function is that,\n\n\\begin{align*}\n  \\int_a^b f(x) \\delta(x - x_0) dx =\n  \\begin{cases}\n    f(x_0) & a < x_0 < b \\\\\n    0 & \\text{otherwise}\n  \\end{cases}\n\\end{align*}\n\nThis is because the delta function effectively picks out the value of $f(x)$ where $x = x_0$. This is because the only place where the delta function isn't zero, is when $x = x_0$. Since the integral over the entire Dirac delta function is one, that means we just get the function $f(x_0)$ back.\n\nWe may also write this as,\n\n\\begin{align*}\n  f(x)\\delta(x - x_0) = f(x_0)\\delta(x - x_0)\n\\end{align*}\n\nUsing some intuition it is clear to see that they are equal, as the product will be zero for all $x \\neq x_0$, so we can just replace $f(x)$ with $f(x_0)$\n\nWe can relate the one-dimensional and three-dimensional Dirac delta functions by,\n\n\\begin{align*}\n  \\delta^3(\\mathbf{r}) = \\delta(x)\\delta(y)\\delta(z)\n\\end{align*}\n\nOr for a given offset $\\mathbf{r_0}$,\n\n\\begin{align*}\n  \\delta^3(\\mathbf{r} - \\mathbf{r_0}) = \\delta(x - x_0)\\delta(y - y_0)\\delta(z - z_0)\n\\end{align*}\n\n\\section{The Heaviside (Step) Function}\n\nThe Heaviside function, also known as the step function, is defined as the integral of the Dirac delta function,\n\n\\begin{align}\n  \\label{eq:heavisideintegral}\n  \\Theta(x) = \\int_{-\\infty}^x\\delta(t)dt\n\\end{align}\n\nBy considering the definition of the Dirac delta function, and looking at the cases where $x < 0$ and $x > 0$ we can find a numerical definition of the Heaviside function,\n\n\\begin{align*}\n  \\Theta(x) =\n  \\begin{cases}\n    0 & x < 0 \\\\\n    1 & x > 0\n  \\end{cases}\n\\end{align*}\n\nThe function, when plotted, looks like an instantaneous step from zero to one at $x = 0$. By considering what happens when we have a negative $x$ as the argument to the function we can also define,\n\n\\begin{align*}\n  \\Theta(-x) =\n  \\begin{cases}\n    1 & x < 0 \\\\\n    0 & x > 0\n  \\end{cases}\n\\end{align*}\n\nThis allows us to write the expression,\n\n\\begin{align*}\n  \\Theta(x) + \\Theta(-x) = 1\n\\end{align*}\n\nwhich holds for all $x$ not equal to zero.\n\nBy considering the definition of the Heaviside function we can define its derivative by the fundamental theorem of calculus. That is, the derivative is the opposite operation of the integral. Therefore by taking the derivative with respect to $x$ of both sides of eq.~\\ref{eq:heavisideintegral} we obtain,\n\n\\begin{align*}\n  \\frac{d}{dx}\\Theta(x) = \\delta(x)\n\\end{align*}\n\nSo far the Heaviside function is not defined for $x = 0$, so we want to explore a way that we can define this as if it is a continuous function. Intuitively we expect that $\\Theta(x = 0) = \\frac{1}{2}$ which we will show by considering the integral,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} \\frac{\\sin x}{x} dx = \\pi\n\\end{align*}\n\nWe will not prove this result here as it is long, but the proof can be found on the internet or in the notes on Canvas. This integral can be further generalized by considering the value of,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} \\frac{\\sin ax}{x} dx\n\\end{align*}\n\nfor different values of $a$.\n\nFirstly, we will consider the case when $a = 0$. First we define a placeholder value,\n\n\\begin{align*}\n  y &= ax \\\\\n  dy &= adx\n\\end{align*}\n\nBy dividing the second line by the first line,\n\n\\begin{align*}\n  \\frac{dy}{y} = \\frac{dx}{x}\n\\end{align*}\n\nTherefore by substituting this back into our integral, we see that the result is independent of the value of $a$,\n\n\\begin{align*}\n   \\int_{-\\infty}^{\\infty} \\frac{\\sin ax}{x} dx = \\int_{-\\infty}^{\\infty} \\frac{\\sin y}{y} dy = \\pi\n\\end{align*}\n\nIt is this property of being independent of $a$ which makes this integral a good function for representing the Heaviside step function.\n\nNext, we need to consider the case where $a = 0$, which is simply\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} \\frac{0}{x} dx = 0\n\\end{align*}\n\nFinally, for the case where $a < 0$ we let $a = -b$ where $b > 0$, such that,\n\n\\begin{align*}\n  \\sin ax = \\sin(-bx) = -\\sin bx\n\\end{align*}\n\nThe integral can thus be rewritten in the form,\n\n\\begin{align*}\n  -\\int_{-\\infty}^{\\infty} \\frac{\\sin bx}{x} dx = -\\pi\n\\end{align*}\n\nTherefore, we have that,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} \\frac{\\sin ax}{x} dx =\n  \\begin{cases}\n    \\pi & a > 0 \\\\\n    0 & a = 0 \\\\\n    -\\pi & a < 0\n  \\end{cases}\n\\end{align*}\n\nBy adding a term and dividing by a constant we can bring this in line with the definition of the Heaviside step function,\n\n\\begin{align*}\n  \\Theta(a) = \\frac{1}{2} + \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty}\\frac{\\sin ax}{x} dx=\n  \\begin{cases}\n    1 & a > 0 \\\\\n    \\frac{1}{2} & a = 0 \\\\\n    0 & a < 0\n  \\end{cases}\n\\end{align*}\n\nOr, by change of variable we can make this a function of $x$,\n\n\\begin{align*}\n  \\Theta(x) = \\frac{1}{2} + \\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty}\\frac{\\sin xt}{t} dt=\n  \\begin{cases}\n    1 & x > 0 \\\\\n    \\frac{1}{2} & x = 0 \\\\\n    0 & x < 0\n  \\end{cases}\n\\end{align*}\n\nWe can see that this lends itself to a continuous representation of the step function which allows us to define a value for $\\Theta(x = 0)$. This is also useful as it is directly differentiable to give a trigonometric form of the Dirac delta function,\n\n\\begin{align*}\n  \\delta(x) &= \\frac{d}{dx}\\Theta(x) \\\\\n  \\delta(x) &= \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} \\frac{t \\cos xt}{t} dt \\\\\n  \\delta(x) &= \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} \\cos xt dt\n\\end{align*}\n\nThis can also be expressed in an exponential form by noting that,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} e^{ixt} dt &= \\int_{-\\infty}^{\\infty} \\left[\\cos xt + i\\sin xt\\right] dt \\\\\n                                     &= \\int_{-\\infty}^{\\infty} \\cos xt dt\n\\end{align*}\n\nIn the second line we used the fact that sine is an odd function, so the integral over it from $-\\infty$ to $\\infty$ is zero. We can now express the Dirac delta function in the exponential form,\n\n\\begin{align*}\n  \\delta(x) = \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} e^{ixt} dt\n\\end{align*}\n\n\n\\section{Schr\\\"{o}dinger Equation in One Dimension}\n\nThe time independent Schr\\\"{o}dinger equation in one dimension can be written as,\n\n\\begin{align*}\n  -\\frac{\\hbar^2}{2m}\\frac{d^2\\psi}{dx^2} + V(x)\\psi = E\\psi\n\\end{align*}\n\nwhere $V(x)$ is the position-dependent potential energy. The Schr\\\"{o}dinger equation is only possible to solve for discrete values of energy $E$. We are interested in the eigenfunctions $\\psi_n(x)$ and their corresponding energy eigenvalues (energy levels) $E_n$.\n\nConsider an attractive $\\delta$-function potential. In this case, it is a potential of the form $V(x) = -\\lambda\\delta(x)$, a sharp spike potential that goes to $-\\infty$ at $x = 0$. The Schr\\\"{o}dinger equation can be written as,\n\n\\begin{align*}\n  -\\frac{\\hbar^2}{2m}\\frac{d^2\\psi}{dx^2} - \\lambda\\delta(x)\\psi = E\\psi\n\\end{align*}\n\nWe want to look for the bound state with an energy,\n\n\\begin{align*}\n  E = -\\frac{\\hbar^2q^2}{2m}\n\\end{align*}\n\nFor the case where $x \\neq 0$, the potential function $V(x) = 0$, and we have,\n\n\\begin{align*}\n  -\\frac{\\hbar^2}{2m}\\frac{d^2\\psi}{dx^2} = E\\psi = -\\frac{\\hbar^2q^2}{2m}\\psi\n\\end{align*}\n\nFrom this we can see that,\n\n\\begin{align*}\n  \\frac{d^2\\psi}{dx^2} = q^2\\psi\n\\end{align*}\n\nThe solution therefore has the form,\n\n\\begin{align*}\n  \\psi(x) =\n  \\begin{cases}\n    Ae^{qx} & x < 0 \\\\\n    Be^{-qx} & x > 0\n  \\end{cases}\n\\end{align*}\n\nshowing us that the solution has the form of an exponential decay either side of $x = 0$.\n\nBy considering the Heaviside function, we can also write this in the equivalent form,\n\n\\begin{align*}\n  \\psi(x) = Ae^{qx}\\Theta(-x) + Be^{-qx}\\Theta(x)\n\\end{align*}\n\nTo substitute this into the Schr\\\"{o}dinger equation we calculate the derivatives,\n\n\\begin{align*}\n  \\frac{d\\psi}{dx} &= Aqe^{qx}\\Theta(-x) - Bqe^{-qx}\\Theta{x} - Ae^{qx}\\delta(x) + Be^{-qx}\\delta(x) \\\\\n                   &= Aqe^{qx}\\Theta(-x) - Bqe^{-qx}\\Theta{x} + (B - A)\\delta(x)\n\\end{align*}\n\nIn the second line we used the fact that the Dirac delta function is zero every except where $x = 0$, so we can write $e^{qx}\\delta(x) = \\delta(x)$ as $e^{qx}$ is zero at $x = 0$, and $\\delta(x)$ is zero at $x \\neq 0$. We can now compute the second derivative,\n\n\\begin{align*}\n  \\frac{d^2\\psi}{dx^2} &= Aq^2e^{qx}\\Theta(-x) + Bq^2e^{-qx}\\Theta(x) \\\\\n                       &- Aqe^{qx}\\delta(x) - Bqe^{-qx}\\delta(x) \\\\\n                       &+ (B-A)\\delta'(x)\n\\end{align*}\n\nUsing $e^{qx}\\delta(x) = \\delta(x)$ from before, as well as noting that the first line is just the wavefunction multiplied by $q^2$,\n\n\\begin{align*}\n  \\frac{d^2\\psi}{dx^2} = q^2\\psi - (A+B)q\\delta(x) + (B-A)\\delta'(x)\n\\end{align*}\n\nBy substituting this back into the time independent Schr\\\"{o}dinger equation,\n\n\\begin{align*}\n  -\\frac{\\hbar^2}{2m}q^2\\psi+\\frac{\\hbar^2q\\left(A+B\\right)}{2m}\\delta(x) - \\frac{\\hbar^2}{2m}\\left(B - A\\right)\\delta'(x) - \\lambda\\delta(x)\\psi = E\\psi\n\\end{align*}\n\nWe do not yet have a suitable expression for the third term that isn't in terms of $\\psi$. Note that we can write the third term in the form,\n\n\\begin{align*}\n  \\delta(x)\\psi=\\delta(x)\\left[A\\Theta(-x)e^{qx}+B\\Theta(x)e^{-qx}\\right]\n\\end{align*}\n\nRemember that $\\delta(x) = 0$ for all $x \\neq 0$, which means that we can write this as,\n\n\\begin{align*}\n  \\delta(x)\\psi=\\delta(x)\\Theta(0)\\left[A+B\\right] = \\frac{1}{2}(A+B)\\delta(x)\n\\end{align*}\n\nSubtituting this into the Schr\\\"{o}dinger equation we then have,\n\n\\begin{align*}\n  -\\frac{\\hbar^2}{2m}q^2\\psi+\\frac{\\hbar^2q\\left(A+B\\right)}{2m}\\delta(x) - \\frac{\\hbar^2}{2m}\\left(B - A\\right)\\delta'(x) - \\frac{\\lambda}{2}\\left(A+B\\right)\\delta(x) = E\\psi\n\\end{align*}\n\nThe coefficients of each term on the left hand side can be compared with the right hand side.\n\nFirstly, comparing $\\delta'(x)$,\n\n\\begin{align*}\n  -\\frac{\\hbar^2}{2m}(B-A)=0\n\\end{align*}\n\nand therefore,\n\n\\begin{align*}\n  B = A\n\\end{align*}\n\nThis is intuitive, as the wavefunction $\\psi$ is clearly symmetric about $x = 0$.\n\nNext we compare $\\delta(x)$,\n\n\\begin{align*}\n  \\frac{\\hbar^2q}{2m}(A+B)-\\frac{\\lambda}{2}(A+B) = 0\n\\end{align*}\n\nTherefore can find an expression for $q$,\n\n\\begin{align*}\n  \\frac{\\hbar^2q}{2m} &= \\frac{\\lambda}{2} \\\\\n  q = \\frac{m\\lambda}{\\hbar^2}\n\\end{align*}\n\nFinally, comparing $\\psi$ terms,\n\n\\begin{align*}\n  E = -\\frac{\\hbar^2q}{2m} = -\\frac{\\hbar^2}{2m} {\\left(\\frac{m\\lambda}{\\hbar^2}\\right)}^2\n\\end{align*}\n\nand therefore the energy $E$ is given by,\n\n\\begin{align*}\n  E = -\\frac{m\\lambda^2}{2\\hbar^2}\n\\end{align*}\n\nSince $A = B$, we can write our expression for the wavefunction as,\n\n\\begin{align*}\n  \\psi(x) =\n  \\begin{cases}\n    Ae^{qx} & x \\leq 0 \\\\\n    Ae^{-qx} & x \\geq 0\n  \\end{cases}\n\\end{align*}\n\nAn alternative form using the absolute value function,\n\n\\begin{align*}\n  \\psi(x) = Ae^{-q\\|x\\|}\n\\end{align*}\n\nTo find the constant $A$ we can normalize the wavefunction by noting that the integral of the probability density over all space must be $1$,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty}\\psi(x)^2 dx &= A^2\\int_{-\\infty}^{\\infty} e^{-2q\\|x\\|} dx \\\\\n                                      &= 2A^2\\int_{-\\infty}^{\\infty} e^{-2qx} dx \\\\\n                                      &= {\\left[-\\frac{A^2}{q}e^{-2qx}\\right]}^{\\infty}_0 e^{-2qx} dx \\\\\n                                      &= \\frac{A^2}{q} = 1\n\\end{align*}\n\nTherefore we see that the normalization constant $A$ is given by,\n\n\\begin{align*}\n  A = \\sqrt{q}\n\\end{align*}\n\nThe wavefunction can then be written as,\n\n\\begin{align*}\n  \\psi(x) = \\sqrt{q}e^{-q\\|x\\|}\n\\end{align*}\n\n\\section{Alternative Boundary Condition Approach}\n\nIn this section we will take a boundary condition approach to solving the same problem. First consider the Schr\\\"{o}dinger equation for the potential $V(x) = -\\lambda\\delta(x)$,\n\n\\begin{align*}\n  -\\frac{\\hbar^2}{2m}\\frac{d^2\\psi}{dx^2} - \\lambda\\delta(x)\\psi = E\\psi\n\\end{align*}\n\nRearranging this for the second derivative we have,\n\n\\begin{align}\n  \\label{eq:second}\n  \\frac{d^2\\psi}{dx^2} = -\\frac{2m\\lambda}{\\hbar^2}\\delta(x)\\psi - \\frac{2mE}{\\hbar^2}\\psi\n\\end{align}\n\nFrom here on we will introduce a new notation: $\\psi(0+)$ will mean $\\psi(x)$ as $x \\to 0$ from the \\textit{positive} $x$-direction, and $\\psi(0-)$ will mean $\\psi(x)$ as $x to 0$ from the \\textit{negative} $x$-direction.\n\nAt $x = 0$ there is a sharp delta potential as we have defined. We can integrate over this potential from $x = -\\epsilon$ to $x = \\epsilon$ where $\\epsilon$ is very small. On the left side of the potential we have the approaching $\\psi(\\epsilon-)$, and on the right side we have $\\psi(\\epsilon+)$. By integrating both sides of eq.~\\ref{eq:second} with respect to $dx$,\n\n\\begin{align*}\n  \\psi'(\\epsilon+) - \\psi'(\\epsilon-) = -\\frac{2m\\lambda}{\\hbar^2}\\psi(0) - \\frac{2mE}{\\hbar^2}\\int_{-\\epsilon}^{\\epsilon}\\psi(x) dx\n\\end{align*}\n\nBy letting $\\epsilon \\to 0$ we get a discontinuous step in $\\psi'(x)$ where the gradient suddenly becomes negative at $x = 0$,\n\n\\begin{align}\n  \\label{eq:wfderiv}\n  \\psi'(0+)-\\psi'(0-)=-\\frac{2m\\lambda}{\\hbar^2}\\psi(0)\n\\end{align}\n\nSince this is not equal to zero, it shows us that there is a discontinuous change in the gradient at $x = 0$. If it were continuous at $x = 0$, the two gradients would be the same at $x = 0$, and thus the difference would be zero. Hence for a delta function potential, the gradient of the wavefunction is discontinuous at $x = 0$.\n\nTo find the solutions to the Schr\\\"{o}dinger equation, consider how the Schr\\\"{o}dinger equation for this problem behaves in different regions. First look at the region $x \\neq 0$. At $x \\neq 0$, the delta function $\\delta(x) = 0$, and therefore the Schr\\\"{o}dinger equation becomes,\n\n\\begin{align*}\n  -\\frac{\\hbar^2}{2m}\\frac{d^2\\psi}{dx^2} = E\\psi\n\\end{align*}\n\nSince we have defined the energy $E$ as,\n\n\\begin{align*}\n  E = -\\frac{\\hbar^2q^2}{2m}\n\\end{align*}\n\nThe solution has the form,\n\n\\begin{align*}\n  \\psi(x) =\n  \\begin{cases}\n    Ae^{qx} & x < 0 \\\\\n    Be^{-qx} & x > 0\n  \\end{cases}\n\\end{align*}\n\nNext we look at the boundary where $x = 0$. Here the wavefunction is continuous, that is, $\\psi(0+) = \\psi(0-)$, unlike the derivative of the wavefunction, where can therefore write that $A = B$ and thus the solution now takes the form,\n\n\\begin{align*}\n  \\psi(x) =\n  \\begin{cases}\n    Ae^{qx} & x < 0 \\\\\n    Ae^{-qx} & x > 0\n  \\end{cases}\n\\end{align*}\n\nTo use eq.~\\ref{eq:wfderiv} we also need the first derivative,\n\n\\begin{align*}\n  \\psi'(x) =\n  \\begin{cases}\n    Aqe^{qx} & x < 0 \\\\\n    -Aqe^{-qx} & x > 0\n  \\end{cases}\n\\end{align*}\n\nSubstituting into eq.~\\ref{eq:wfderiv} we obtain,\n\n\\begin{align*}\n  \\psi'(0+)-\\psi'(0-) &= -\\frac{2m\\lambda}{\\hbar^2}\\psi(0) \\\\\n  -Aq - (+Aq) &= -\\frac{2m\\lambda}{\\hbar^2}A \\\\\n  -2Aq &= -\\frac{2m\\lambda}{\\hbar} A \\\\\n  q &= \\frac{m\\lambda}{\\hbar^2}\n\\end{align*}\n\nWe can substitute this into our equation for the energy $E$,\n\n\\begin{align*}\n  E &= -\\frac{\\hbar^2q^2}{2m} \\\\\n  E &= -\\frac{m\\lambda^2}{2\\hbar^2}\n\\end{align*}\n\nwhich is the result we obtained last time, but we arrived at it much more easily using boundary conditions.\n\n\\section{Attractive Double Delta Potential}\n\nConsider the Schr\\\"{o}dinger equation for an attractive double delta potential. That is, two infinitely negative potentials with strength $\\lambda$, both spaced a distance $a$ away from the origin $x = 0$. We then have the potential function,\n\n\\begin{align*}\n  V(x) = -\\lambda\\left[\\delta(x - a) + \\delta(x + a)\\right]\n\\end{align*}\n\nSince the potential function $V(x)$ is even, due to us choosing symmetrical delta potentials about $x = 0$, the solutions $\\psi(x)$ will be either even or odd functions.\n\nThe solutions in $x < -a$ and $x > a$ are the same as before but what in the region in between? Since it is the superposition of the two other states we can just write it as a hyperbolic $\\cosh(x)$ function, as $\\cosh(x) = \\frac{e^x + e^{-x}}{2}$. The solutions therefore take the form,\n\n\\begin{align*}\n  \\psi(x) =\n  \\begin{cases}\n    Ce^{qx} & x < -a \\\\\n    D\\cosh{qx} & -a < x < a \\\\\n    Ce^{-qx} & x > a\n  \\end{cases}\n\\end{align*}\n\nWe know that the two constants $C$ must be the same in both $x < -a$ and $x > a$ as the potential function is symmetric about $x = 0$. The derivative is given by,\n\n\\begin{align*}\n  \\psi'(x) =\n  \\begin{cases}\n    qCe^{qx} & x < -a \\\\\n    Dq\\sinh{qx} & -a < x < a \\\\\n    -qCe^{-qx} & x > a\n  \\end{cases}\n\\end{align*}\n\nNext we consider the boundary conditions.\n\nAt $x = a$, we know that the wavefunction is continuous,\n\n\\begin{align}\n  \\label{eq:doubleone}\n  \\psi(a+) &= \\psi(a-) \\notag\\\\\n  Ce^{-qa} &= D\\cosh{qa}\n\\end{align}\n\nThe derivative has the same boundary condition as before,\n\n\\begin{align}\n  \\label{eq:doubletwo}\n  \\psi'(a+) - \\psi'(a-) &= -\\frac{2m\\lambda}{\\hbar^2}\\psi(a) \\notag\\\\\n  -qCe^{-qs} - Dq\\sinh{qa} &= -\\frac{2m\\lambda}{\\hbar^2}Ce^{-qa} \\notag\\\\\n  \\left(\\frac{2m\\lambda}{\\hbar^2} - q\\right)Ce^{-qa} &= Dq\\sinh{qa}\n\\end{align}\n\nDividing eq.~\\ref{eq:doubletwo} by eq.~\\ref{eq:doubleone} we obtain,\n\n\\begin{align*}\n  \\frac{2m\\lambda}{\\hbar^2} - q &= q\\tanh{qa} \\\\\n  \\frac{2m\\lambda a}{\\hbar^2} = qa\\left[1 + \\tanh{qa}\\right]\n\\end{align*}\n\nThe quantity $qa$ must be dimensionless, as it is inside the hyperbolic tangent function. By letting $y = qa$ we can write this equation as,\n\n\\begin{align*}\n  \\frac{2m\\lambda a}{\\hbar^2} = y\\left[1 + \\tanh{y}\\right]\n\\end{align*}\n\nThis is a transcendental equation, so cannot be solved analytically, although we can solve this numerically.\n\nWe can rewrite this in an exponential form by noting,\n\n\\begin{align*}\n  \\tanh{y} = \\frac{\\sinh{y}}{\\cosh{y}} = \\frac{e^y - e^{-y}}{e^y + e^{-y}}\n\\end{align*}\n\nand by adding one,\n\n\\begin{align*}\n  \\tanh y + 1 = \\frac{e^y - e^{-y}}{e^y + e^{-y}} + \\frac{e^y + e^{-y}}{e^y + e^{-y}} = \\frac{2e^y}{e^y + e^{-y}} = \\frac{2}{1 + e^{-2y}}\n\\end{align*}a\n\nThe condition thus becomes,\n\n\\begin{align*}\n  \\frac{2y}{1 + e^{-2y}} &= \\frac{2m\\lambda a}{\\hbar^2} \\\\\n  \\frac{z}{1 + e^{-z}} &= \\frac{2m\\lambda a}{\\hbar^2}\n\\end{align*}\n\nwhere $z = 2y = 2qa$.\n\nLet the function $f(z)$ be equal to the left hand side of this equation. Taking the derivative,\n\n\\begin{align*}\n  f'(z) &= \\frac{1 + e^{-z} + ze^{-z}}{{\\left(1 + e^{-z}\\right)}^2} \\\\\n        &= \\frac{e^z\\left(e^z + 1 + z\\right)}{{\\left(e^z + 1\\right)}^2}\n\\end{align*}\n\nThis is clearly greater than zero for all $z$. This means that $f(z)$ is \\textit{always} increasing from $f(0) = 0$ to $f(\\infty) = \\infty$.\n\nTherefore the function $f(z) = \\frac{2m\\lambda a}{\\hbar^2}$ has only one solution, which is the $z$ at which $f(z) = \\frac{2m\\lambda a}{\\hbar^2}$. There is therefore an even solution for any $\\lambda$ where $0 < \\lambda < \\infty$.\n\nNow let us look at the odd solution, $\\psi_0(x)$, where $\\psi_0(-x) = -\\psi_0(x)$,\n\n\\begin{align*}\n  \\psi(x) =\n  \\begin{cases}\n    -Ce^{qx} & x < -a \\\\\n    D\\sinh{qx} & -a < x < a \\\\\n    Ce^{-qx} & a < x\n  \\end{cases}\n\\end{align*}\n\nand its derivative is,\n\n\\begin{align*}\n  \\psi'(x) =\n  \\begin{cases}\n    -qCe^{qx} & x < -a \\\\\n    qD\\cosh{qx} & -a < x < a \\\\\n    -qCe^{-qx} & a < x\n  \\end{cases}\n\\end{align*}\n\nNow we apply our boundary conditions. First we have continuity of $\\psi(x)$ at $x = a$,\n\n\\begin{align}\n  \\label{eq:evenone}\n  Ce^{-qa} = D\\sinh{qa}\n\\end{align}\n\nWe have the same discontinuity in $\\psi'(x)$ at $x = a$,\n\n\\begin{align}\n  \\label{eq:eventwo}\n  \\psi'(a+) - \\psi'(a-) &= -\\frac{2m\\lambda}{\\hbar^2}\\psi(a) \\notag\\\\\n  -qCe^{-qa} - qD\\cosh{qa} &= -\\frac{2m\\lambda}{\\hbar^2}Ce^{-qa} \\notag\\\\\n  \\left(\\frac{2m\\lambda}{\\hbar^2} - q\\right)Ce^{-qa} &= qD\\cosh{qa}\n\\end{align}\n\nDiving eq.~\\ref{eq:eventwo} by eq.~\\ref{eq:evenone} we obtain,\n\n\\begin{align*}\n  \\frac{2m\\lambda}{\\hbar^2} - q &= q\\coth{qa} \\\\\n  \\frac{2m\\lambda a}{\\hbar^2} &= qa\\left[1 + \\coth{qa}\\right]\n\\end{align*}\n\nIn step two, as well as rearranging the $q$ term we multiply both sides by $a$. Now let $y = qa$ as before. We can therefore write this as,\n\n\\begin{align*}\n  y\\left[1 + \\coth{y}\\right] = \\frac{2m\\lambda a}{\\hbar^2}\n\\end{align*}\n\nWe can write the hyperbolic cot term in exponential form as before,\n\n\\begin{align*}\n  \\coth{y} = \\frac{1}{\\tanh{y}} = \\frac{e^y + e^{-y}}{e^y - e^{-y}}\n\\end{align*}\n\nand then by adding one,\n\n\\begin{align*}\n  1 + \\coth{y} &= \\frac{e^y + e^{-y}}{e^y - e^{-y}}+\\frac{e^y - e^{-y}}{e^y - e^{-y}} = \\frac{2e^y}{e^y - e^{-y}} \\\\\n               &= \\frac{2}{1 - e^{-2y}}\n\\end{align*}\n\nOur equation therefore becomes,\n\n\\begin{align*}\n  \\frac{z}{1 - e^{-z}} = \\frac{2m\\lambda a}{\\hbar^2}\n\\end{align*}\n\nwhere $z = 2y = 2qa$.\n\nConsider the function $g(z) = \\frac{z}{1 - e^{-z}}$. By taking the limit of $g(z)$ as $z \\to 0$,\n\n\\begin{align*}\n  g(0) = \\lim_{z\\to 0} \\frac{z}{1 - e^{-z}} = \\lim_{z\\to 0} \\frac{1}{e^-z} = 1\n\\end{align*}\n\nand, as before, $g(\\infty) = \\infty$. By taking the first derivative of the function we can see that,\n\n\\begin{align*}\n  g'(z) = \\frac{1-e^{-z}-ze^{-z}}{{\\left(1 - e^{-z}\\right)}^2} = \\frac{e^z \\left[e^z - 1 - z\\right]}{{\\left(e^z - 1\\right)}^2}\n\\end{align*}\n\nWe can see by using the maclaurin series that this is greater than zero for all $z$, and therefore the function $g(z)$ is increasing from $g(0) = 1$ to $g(\\infty) = \\infty$. This time it is possible to have no solution, as there are only solutions if $\\frac{2m\\lambda a}{\\hbar^2} > 1$ since there is a lower limit on the function, $g(0) = 1$. This means that there is not always an odd solution to the Schr\\\"{o}dinger equation, specifically there isn't when $\\frac{2m\\lambda a}{\\hbar^2} < 1$.\n\n\n\\section{The Top Hat Function}\n\nThe top hat function $T(x; a, b)$ is defined such that,\n\n\\begin{align*}\n  T(x; a, b) = \\Theta(x - a) - \\Theta(x - b)\n\\end{align*}\n\nBy considering the definition of the heaviside step function, we can see that,\n\n\\begin{align*}\n  T(x; a, b) =\n  \\begin{cases}\n    0 & x < a \\\\\n    1 & a < x < b \\\\\n    0 & x > b\n  \\end{cases}\n\\end{align*}\n\nWe can use the top hat function to describe a function that is defined piecewise, that is, it is described by different functions over different regions,\n\n\\begin{align*}\n  f(x) =\n  \\begin{cases}\n    f_1(x) & x_0 < x < x_1 \\\\\n    f_2(x) & x_1 < x < x_1 \\\\\n    \\cdots & \\cdots \\\\\n    f_n(x) & x_{n-1} < x < x_n \\\\\n  \\end{cases}\n\\end{align*}\n\nWe can write this more succinctly using the top hat notation,\n\n\\begin{align*}\n  f(x) &= \\sum\\limits_{i = 1}^n f_i(x) T(x; x_{i - 1}, x) \\\\\n       &= \\sum\\limits_{i = 1}^n f_i(x) \\left[\\Theta(x - x_{i - 1}) - \\Theta(x - x_i)\\right]\n\\end{align*}\n\nThe top hat function can be used to select specific regions of integration,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} f(x) dx &= \\sum\\limits_{i = 1}^n \\int_{-\\infty}^{\\infty} f_i(x) T(x; x_{i - 1}, x_i) dx \\\\\n                                  &= \\sum\\limits_{i = 1}^n \\int_{x_i - 1}^{x_i} f_i(x) dx\n\\end{align*}\n\nThe top hat function here simply selects the limits of the integration region, since the integral will be zero everywhere outside of the top hat function's width.\n\nWhat if $f(x)$ is defined all the way out to infinity? In this case $f(x)$ can be written as,\n\n\\begin{align*}\n  f(x) =\n  \\begin{cases}\n    f_0(x) & x < x_0 \\\\\n    f_1(x) & x_0 < x < x_1 \\\\\n    \\cdots & \\cdots \\\\\n    f_n(x) & x_{n-1} < x < x_n \\\\\n    f_{n+1}(x) & x_n < x\n  \\end{cases}\n\\end{align*}\n\nNote the added first and last terms, in the regions $x < x_0$ and $x_n < x$. We can writ this using the heaviside step function, such that $f(x)$ can be written as before plus the two extra terms,\n\n\\begin{align*}\n  f(x) &= \\sum\\limits_{i=1}^n f_i(x) \\left[\\Theta(x - x_{i-1}) - \\Theta(x - x_i)\\right] \\\\\n       &+ f_0(x) \\Theta(x_0 - x) \\\\\n       &+ f_{n+1}(x) \\Theta(x - x_n)\n\\end{align*}\n\nBy expanding the summation and grouping each heaviside term $\\Theta(x_i - x_{i-1})$ we can see that this can be written,\n\n\\begin{align*}\n  f(x) = f_0(x) + \\sum\\limits_{i=0}^n \\left[f_{i+1}(x) - f_i(x)\\right] \\Theta(x - x_i)\n\\end{align*}\n\n\\section{Derivatives of Delta Functions}\n\nDerivatives of the delta function can be defined using integration by parts,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} \\frac{d\\delta(x)}{dx} f(x) dx &= {\\left[\\delta(x)f(x)\\right]}_{-\\infty}^{\\infty} - \\int_{-\\infty}^{\\infty} \\delta(x) \\frac{d f(x)}{dx} dx \\\\\n                                                        &= -f'(0)\n\\end{align*}\n\nSimilar analysis gives an expression for the $n$-th derivative,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} \\delta^n(x) f(x) dx = {(-1)}^n f^n(0)\n\\end{align*}\n\n\\section{Delta Function of Nontrivial Arguments}\n\nConsider the function $\\delta\\left(f\\left(x\\right)\\right)$. This will only be non-zero when $f(x) = 0$, that is, only at the zeroes $x_n$ of the function $f(n)$.\n\nLet us evaluate the integral\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} \\delta\\left(f(x)\\right) dx\n\\end{align*}\n\nWe want to split the integration into a number of monotonic regions, such that there is only one solution in each region. First we let $y = f(x)$, and then to evaluate the integral,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} \\delta\\left(f(x)\\right) dx = \\int \\delta(y) \\frac{dx}{dy} dy\n\\end{align*}\n\nFunctions only have inverses if they are monotonic. That is, only one-to-one functions have inverses, for example, $f(x) = x^2$ is not one-to-one, as for one $f(x)$ there are two values of $x$ that could correspond to that given $f(x)$, and hence there is no single inverse of this function. Therefore we will take the integral over monotonic regions instead,\n\n\\begin{align*}\n  \\int_{-\\infty}^{\\infty} \\delta\\left(f(x)\\right) &= \\int \\delta(y) \\left|\\frac{dx}{dy}\\right| dy \\\\\n                                                  &= \\int \\delta(y) \\frac{1}{|f'(x)|} dy \\\\\n                                                  &= \\sum\\limits_n \\frac{1}{|f'(x)|}\n\\end{align*}\n\nWe take the summation over $x_n$ as each $x_n$ gives a contribution. It therefore follows that,\n\n\\begin{align*}\n  \\delta\\left(f(x)\\right) = \\sum\\limits_n \\frac{1}{|f'(x)|} \\delta(x - x_n)\n\\end{align*}\n\nFor example, evaluating $\\delta(x^2 - a^2)$, where $a > 0$. First define $f(x) = x^2 - a^2$, which has zeroes at $+a$ and $-a$. The derivative is trivially calculated as $f'(x) = 2x$, so $f'(a) = 2a$ and $f'(-a) = -2a$. Therefore is follows,\n\n\\begin{align*}\n  |f'(a)| = |f'(-a)| = 2a\n\\end{align*}\n\nand therefore,\n\n\\begin{align*}\n  \\delta(x^2 - a^2) = \\frac{1}{2a}\\left[\\delta(x - a) + \\delta(x + a)\\right]\n\\end{align*}\n\nNext, consider the function $\\delta(\\sin{x})$. The function $f(x) = \\sin{x}$ has zeroes when $x = n\\pi$ where $n$ is any integer. Differentiating $f(x)= \\sin{x}$ gives us $f'(x) = \\cos{x}$. Our zeroes thus give us $f'(n\\pi) = \\cos n\\pi = {(-1)}^n$, and therefore we can write the delta function as,\n\n\\begin{align*}\n  \\delta(\\sin{x}) = \\sum\\limits_{n=-\\infty}^{\\infty} \\delta(x - n\\pi)\n\\end{align*}\n\n\n\\end{document}\n", "meta": {"hexsha": "a713ee29ecf1062b14cacecb91e01f0fffb5d936", "size": 30303, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "maths/distributions/distributions.tex", "max_stars_repo_name": "unanimousarc/physics", "max_stars_repo_head_hexsha": "7bc9cbd428defb7615f5a2e241d86fae71ece7b3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-03-13T14:28:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-06T14:27:57.000Z", "max_issues_repo_path": "maths/distributions/distributions.tex", "max_issues_repo_name": "unanimousarc/physics", "max_issues_repo_head_hexsha": "7bc9cbd428defb7615f5a2e241d86fae71ece7b3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "maths/distributions/distributions.tex", "max_forks_repo_name": "unanimousarc/physics", "max_forks_repo_head_hexsha": "7bc9cbd428defb7615f5a2e241d86fae71ece7b3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-29T08:14:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-29T08:14:51.000Z", "avg_line_length": 34.3182332956, "max_line_length": 576, "alphanum_fraction": 0.6344916345, "num_tokens": 10770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358014, "lm_q2_score": 0.8615382129861584, "lm_q1q2_score": 0.70834736175384}}
{"text": "%% -*- coding:utf-8 -*-\n\\chapter{Functors}\n\n\\section{Definitions}\n\n\\begin{definition}[Functor]\n  \\label{def:functor}\n  Let $\\cat{C}$ and $\\cat{D}$ are 2 categories. A mapping $F: \\cat{C}\n  \\tof \\cat{D}$ between the categories is called \\textit{functor} if it\n  preserves the internal structure (see \\cref{fig:functor}): \n  \\begin{itemize}\n  \\item $\\forall a_C \\in \\catob{C}, \\exists a_D \\in \\catob{D}$ such that\n    $a_D = F( a_C )$\n  \\item $\\forall f_C \\in \\cathom{C}, \\exists f_D \\in \\cathom{D}$ such\n    that $\\dom f_D = F (\\dom f_C), \\cod f_D = F (\\cod f_C)$. We will use\n    the following notation later: $f_D = F(f_C)$.\n  \\item $\\forall f_C, g_C$ the following equation holds: \n    \\[\n    F\\left(f_C \\circ\n    g_C\\right) = F\\left(f_C\\right) \\circ F\\left(g_C\\right) = f_D \\circ\n    g_D.\n    \\]\n  \\item $\\forall x \\in \\catob{C}: F(\\idm{x}) = \\idm{F(x)}$.\n  \\end{itemize}  \n\n  \\begin{figure}\n    \\centering\n    \\begin{tikzpicture}[ele/.style={fill=black,circle,minimum\n          width=.8pt,inner sep=1pt},every fit/.style={ellipse,draw,inner\n          sep=-2pt}]\n\n      % the texts\n\n      \\node at (0,3) {$C$};        \n      \\node at (4,3) {$D$};        \n\n      \\node[ele,label=above:$a_C$] (ac) at (0,2) {};    \n      \\node[ele,label=below:$b_C$] (bc) at (0,0) {};    \n      \\node[ele,label=above:$a_D$] (ad) at (4,2) {};\n      \\node[ele,label=below:$b_D$] (bd) at (4,0) {};\n\n      \\node[draw,fit= (ac) (bc),minimum width=2cm, minimum\n        height=3.5cm] {} ;\n      \\node[draw,fit= (ad) (bd),minimum width=2cm, minimum\n        height=3.5cm] {} ;\n\n      \\draw[->,thick,shorten <=2pt,shorten >=2pt] (ac) to\n      node[left]{$f_C$} (bc);\n      \\draw[->,thick,shorten <=2pt,shorten >=2pt] (ad) to\n      node[right]{$f_D$} (bd);\n      \\draw[->,thick,shorten <=2pt,shorten >=2pt] (ac) to\n      node[sloped,above]{$a_D = F(a_C)$} (ad);\n      \\draw[->,thick,shorten <=2pt,shorten >=2pt] (bc) to\n      node[sloped,above]{$b_D = F(b_C)$} (bd);\n    \\end{tikzpicture}\n    \\caption{Functor $F: \\cat{C} \\tof \\cat{D}$ definition}\n    \\label{fig:functor}\n  \\end{figure}\n\\end{definition}\n\n\\begin{remark}[Functor]\n  When we say that functor preserve internal structure we assume that\n  the functor is not just mapping between \\mynameref{def:object}s but\n  also between \\mynameref{def:morphism}s.  \n\n  Thus functor is something that allows map one category into another.\n  The initial category can be considered as a pattern thus the mapping\n  is some kind of searching of the pattern inside another category.\n\\end{remark}\n\nProgramming languages can be considered as a good platform for the\nfunctor examples. \nThe functor can be defined in Haskell as follows\n\\footnote{the real definition is quite different from the current one}\n\\begin{example}[Functor][\\textbf{Hask}]\n  \\label{ex:functor_haskell}\n  \\begin{minted}{haskell}\n    class Functor f where\n    fmap :: (a -> b) -> f a -> f b\n  \\end{minted} \n\\end{example}\n\nIn Scala it can be defined in the same way\n\\begin{example}[Functor][\\textbf{Scala}]\n  \\label{ex:functor_scala}\n  \\begin{minted}{scala}\n    trait Functor[F[_]] {\n      def fmap[A, B](f: A => B): F[A] => F[B]\n  }\\end{minted} \n\\end{example}\n\nIn C++ the definition differs\n\\begin{example}[Functor][\\textbf{C++}]\n  \\label{ex:functor_cpp}\n  In C++ templates can be considered as type constructors in Haskell\n  and therefore can convert one type for another. For instance the\n  list of strings can be got with the following construction:\n\n  \\begin{minted}{c++}\n    using StringList = std::list<std::string>;\n    StringList a = {\"1\", \"2\", \"3\"};\n  \\end{minted} \n  i.e. we have \\mynameref{def:object}s mapping out of the box.\n  Therefore we need to define fmap\n  operation for \\mynameref{def:morphism}s mapping to complete the\n  \\mynameref{def:functor} definition. It can be declared as \n  follows \n  \\begin{minted}{c++}\n    template < template< class ...> class F, class A, class B> \n    F<B> fmap(std::function<B(A)>, F<A>);\n  \\end{minted}\n  The template specialization for the \\mintinline{c++}{std::list} can be\n  written as follows\n  \\begin{minted}{c++}\n    // file: functor.h\n    template <class A, class B>\n    std::list<B> fmap(std::function<B(A)> f, std::list<A> a) {\n      std::list<B> res;\n      std::transform(a.begin(), a.end(), back_inserter(res), f);\n      return res;\n    }\n  \\end{minted} \n\n  The simple usage example is the following\n  \\begin{minted}{c++}\n    StringList a = {\"1\", \"2\", \"3\"};\n    std::function<int(std::string)> f = [](std::string s) {\n      return 2 * atoi(s.c_str());\n    };\n    auto res = fmap<>(f, a);\n  \\end{minted}\n\\end{example}\n\n\n\\begin{definition}[Endofunctor]\n  \\label{def:endofunctor}\n  Let $\\cat{C}$ is a \\mynameref{def:category}. The\n  \\mynameref{def:functor} $E: \\cat{C} \\tof \\cat{C}$ i.e. \n  the functor from a category to the same category is called\n  \\textit{endofunctor}. \n\\end{definition}\n\n\\begin{definition}[Identity functor]\n  \\label{def:idfunctor}\n  Let $\\cat{C}$ is a \\mynameref{def:category}. The\n  \\mynameref{def:functor} $\\idf{C}: \\cat{C} \\tof \\cat{C}$ is called \\textit{identity\n    functor} if for every object $a \\in \\catob{C}$\n  \\[\n  \\idf{C}(a) = a\n  \\]\n  and for every \\mynameref{def:morphism} $f \\in \\cathom{C}$\n  \\[\n  \\idf{C}(f) = f\n  \\] \n\\end{definition}\n\n\\begin{remark}[Identity functor]\n  \\label{rem:idfunctor}\n  First of all notice that \\mynameref{def:idfunctor} is an\n  \\mynameref{def:endofunctor}.\n\n  There is difference between identity functor and \\mynameref{def:id}\n  because the first one has deal with both \\mynameref{def:object}s and\n  \\mynameref{def:morphism}s while the second one with the objects\n  only. \n\\end{remark}\n\n\\begin{definition}[Functor composition]\n  \\label{def:functor_composition}\n  If we have 3 categories $\\cat{C}, \\cat{D}, \\cat{E}$ and 2 functors\n  between them: $F: \\cat{C} \\tof \\cat{D}$ and $G: \\cat{D} \\tof \\cat{E}$\n  then we can construct a new functor $H: \\cat{C} \\tof \\cat{E}$ that is\n  called \\textit{functor composition} and denoted as $H = G \\circ F$.\n  TBD\n\\end{definition}\n\n\\section{\\textbf{Cat} category}\nThe \\mynameref{def:functor_composition} is associative by definition.\nTherefore \\mynameref{def:idfunctor} with the associative composition\nallow us to define a category where other categories are considered as\nobjects and functors as morphisms: \n\\begin{definition}[\\textbf{Cat} category]\n  \\label{def:cat_category}\n  The category of small categories (see \\mynameref{def:small_category})\n  denoted as \\textbf{Cat} is the \\mynameref{def:category} where objects\n  are small categories and morphisms are \\mynameref{def:functor}s\n  between them.\n\\end{definition}\n\nWe can construct an extension of Cartesian product as follows\n\\begin{definition}[Category Product]\n  \\label{def:category_product}\n  If we have 2 categories $\\cat{C}$ and $\\cat{D}$ then we can construct\n  a new category $\\cat{C} \\times \\cat{D}$ with the following components:\n  \\begin{itemize}\n  \\item \\mynameref{def:object}s are the pairs $(c,d)$ where $c \\in\n    \\catob{C}$ and $d \\in \\catob{D}$\n  \\item \\mynameref{def:morphism}s are the pair $(f,g)$ where $f \\in\n    \\cathom{C}$ and $g \\in \\cathom{D}$\n  \\item \\mynameref{axm:composition} is defined as follows \n    \\(\n    (f_1, g_1) \\circ (f_2, g_2) = (f_1 \\circ f_2, g_1 \\circ g_2)\n    \\)\n  \\item Identity is defined as follows: $\\idm{C \\times D} = \n    \\left(\\idm{C}, \\idm{D}\\right)$\n  \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[Terminal object in \\textbf{Cat} category]\n  \\label{def:terminal_object_cat}\n  \\index{Terminal object!\\textbf{Cat} category}\n  Let consider $\\Delta_c$ is a trivial functor from \\mynameref{def:category}\n  $\\cat{A}$ to category $\\cat{C}$ such that $\\forall a \\in \\catob{A}:\n  \\Delta_c a = c$ -fixed object in $\\cat{C}$ and \n  $\\forall f \\in \\cathom{A}: \\Delta_c f = \\idm{c}$.\n\\end{definition}\n\nThe good example can be found in $\\cat{Hask}$ category.\n\\begin{example}[Terminal object in \\textbf{Cat} category][\\textbf{Hask}]\n  \\label{ex:terminal_object_cat_hask}\n  \\begin{minted}{haskell}\n    data Const c a = Const c\n    fmap :: (a -> b) -> Const c a -> Const c b\n    fmap f (Const c a) = Const c\n  \\end{minted}\n\\end{example}\n\n\\section{Bifunctors}\n\n\\begin{definition}[Bifunctor]\n  \\label{def:bifunctor}\n  Bifunctor is a \\mynameref{def:functor} whose \\mynameref{def:domain} is\n  a \\mynameref{def:category_product}. I.e. if $\\cat{C_1}, \\cat{C_2},\n  \\cat{D}$ are 3 categories then the \\mynameref{def:functor} \n  \\(\n  F: \\cat{C_1} \\times \\cat{C_2} \\tof \\cat{D}\n  \\) is called \\textit{bifunctor}.\n\\end{definition}\n\n\\begin{example}[Bifunctor][\\textbf{Set}]\n  \\label{ex:product_bifunctor}\n  Lets $A,B,C$ and $D$ are sets and $f: A \\to C, g: B \\to D$ are two\n  \\mynameref{def:function}s. Then the \\mynameref{def:cartesian_product}\n  with \\mynameref{def:product_of_morphisms} form a\n  \\mynameref{def:bifunctor} $\\times$.\n\\end{example}\n\n\\begin{example}[Maybe as a bifunctor][\\textbf{Hask}]\n  \\label{ex:maybe_functor}\n  Lets show how the \\mintinline{haskell}{Maybe a} type can be\n  constructed from different \n  \\mynameref{def:functor}s and as result show that the\n  \\mintinline{haskell}{Maybe a} is also a\n  \\mynameref{def:functor}. \n  \\begin{minted}{haskell}\n    data Maybe a = Nothing | Just a\n    -- This is equivalent to\n    data Maybe a = Either () (Identity a)\n    -- Either is a bifunctor and () == Const () a \n    -- Thus Maybe is a composition of 2 functors \n  \\end{minted}\n\\end{example}\n\n\n\\begin{definition}[Contravariant functor]\n  \\label{def:contravariant_functor}\n  If we have categories $\\cat{C}$ and $\\cat{D}$ then the\n  \\mynameref{def:functor} $\\cat{C^{op}} \\tof \\cat{D}$ is called\n  \\textit{contravariant functor}. \n\\end{definition}\n\n\\begin{example}[Contravariant functor][\\textbf{Hask}]\n  \\label{ex:contravariant_functor_hask}\n  TBD\n  \\begin{minted}{haskell}\n    class Contravariant f where\n    contramap :: (a -> b) -> f b -> f a\n  \\end{minted}\n\\end{example}\n\n\\begin{definition}[Profunctor]\n  \\label{def:profunctor}\n  If we have a category $\\cat{C}$ then the \\mynameref{def:bifunctor}\n  $\\cat{C^{op}} \\times \\cat{C} \\tof \\cat{C}$ is called\n  \\textit{profunctor}. \n\\end{definition}\n\n\\begin{example}[Profunctor][\\textbf{Hask}]\n  \\label{ex:contravariant_functor_hask}\n  TBD\n  \\begin{minted}{haskell}\n    class Profunctor p where\n    dimap :: (a' -> a) -> ( b -> b' ) -> p a b -> p a' b'\n    -- p a b == a -> b\n    dimap f g h = g . h . f\n  \\end{minted}\n\\end{example}\n\n\n\n\n\n", "meta": {"hexsha": "b52230d3debd671122a2495edc309fe4f00f312b", "size": 10330, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cattheory/functors.tex", "max_stars_repo_name": "ivanmurashko/articles", "max_stars_repo_head_hexsha": "522db3ad21e96084490acd39a146a335763e5beb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-27T08:59:55.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-27T08:59:55.000Z", "max_issues_repo_path": "cattheory/functors.tex", "max_issues_repo_name": "ivanmurashko/articles", "max_issues_repo_head_hexsha": "522db3ad21e96084490acd39a146a335763e5beb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cattheory/functors.tex", "max_forks_repo_name": "ivanmurashko/articles", "max_forks_repo_head_hexsha": "522db3ad21e96084490acd39a146a335763e5beb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.0924092409, "max_line_length": 84, "alphanum_fraction": 0.6592449177, "num_tokens": 3551, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412808, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7083473571695075}}
{"text": "\\documentclass{article}\r\n\r\n\\title{\\textbf{Second laboratory work}}\r\n\\author{Kondratev Egor 206}\r\n\r\n\\usepackage{sagetex}\r\n\\setlength{\\sagetexindent}{10ex}\r\n\r\n\\usepackage{geometry}\r\n\\geometry{a4paper, total={170mm,257mm}, left=20mm, right=20mm, top=20mm, bottom=20mm}\r\n\r\n\\usepackage{xcolor}\r\n\\usepackage{titlesec}\r\n\r\n\\definecolor{myred1}{RGB}{107, 14, 14}\r\n\\definecolor{mygreen1}{RGB}{0, 102, 0}\r\n\r\n\\begin{document}\r\n\r\n\\maketitle\r\n\\titleformat{\\section}[block]{\\color{red}\\Large\\bfseries\\filcenter}{}{1em}{}\r\n\r\n\\section*{Task 3 variant 1}\r\n\r\n\\textbf{Create some constants which will be useful in future for plot 3d graphics.}\r\n\\begin{sageblock}\r\nxmin, xmax = -10, 10\r\nymin, ymax = -10, 10\r\nzmin, zmax = -10, 10\r\n\\end{sageblock}\r\n\\textbf{Say for sage that \\textcolor{mygreen1}{x},  \\textcolor{mygreen1}{y}, \\textcolor{mygreen1}{z} is variables, and create function \\textcolor{myred1}{f}.}\r\n\\begin{sageblock}\r\nvar(\"x y z\")\r\nf(x, y, z) = 7*x^2 + 3*y^2 + 3*z^2 +  8*x*y + 8*x*z + 6*y*z + 6*x + y + 7\r\n\\end{sageblock}\r\n\\textbf{Display the function formula.}\r\n\r\n\\textcolor{myred1}{$\\sage{f(x, y, z)}$}\\\\\r\n\\textbf{Plot graphic of unchanged figure.} \r\n\\begin{sageblock}\r\np = implicit_plot3d(f(x=x, y=y, z=z), (x, xmin, xmax), (y, ymin, ymax), (z, zmin, zmax))\r\n\\end{sageblock}\r\n\r\n\\begin{center}\r\n\\sageplot{p}\r\n\\end{center}\r\n\\textbf{Function that, according to a given algorithm, converts the function passed as an argument to the canonical form.\r\nReturn tuple (\\textcolor{mygreen1}{lambdas}, \\textcolor{mygreen1}{a}, \\textcolor{mygreen1}{a0}).}\r\n\\begin{sageblock}\r\ndef kanonic_coeffs(fun):\r\n    try:\r\n        var(\"l l1 l2 l3\")\r\n        lvcts = []\r\n        svcts = []\r\n        tmp_fun = fun\r\n        a = vector(RR, 3)\r\n        tmp_vct = vector(RR, 9)\r\n        var_combs_tmp = (x^2, y^2, z^2, x*y, x*z, y*z)\r\n        var_combs_0 = (x^2, x*y, x*z, x*y, y^2, y*z, x*z, y*z, z^2)\r\n        var_combs_1 = (x, y, z)\r\n        for i, var_comb in enumerate(var_combs_0):\r\n            if i == 0 or i == 4 or i == 8:\r\n                tmp_vct[i] = fun.coefficient(var_comb)\r\n            else:\r\n                tmp_vct[i] = fun.coefficient(var_comb) / 2\r\n        for var_comb in var_combs_tmp:\r\n            tmp_fun -= fun.coefficient(var_comb)*var_comb\r\n        for i, var_comb in enumerate(var_combs_1):\r\n            a[i] = tmp_fun.coefficient(var_comb) / 2\r\n            tmp_fun -= tmp_fun.coefficient(var_comb)*var_comb\r\n        a0 = tmp_fun.n()    \r\n        A = matrix(SR, 3, tmp_vct)\r\n        L = matrix(SR, 3, 3, var('l'))\r\n        E = matrix(SR, 3, 3, 1)\r\n        lvct = vector([l1, l2, l3])\r\n        lambdas = solve([(A-L).determinant() == 0], l)\r\n        for i, el in enumerate(lambdas):\r\n            nums = []\r\n            lhs = (A-el.rhs()*E)*lvct\r\n            res = solve([lhs[0] == 0, lhs[1] == 0, lhs[2] == 0], l1, l2, l3)[0]\r\n            for i in range(len(res)):\r\n                if len(res[i].rhs().variables()) == 0:\r\n                    nums.append(res[i].rhs())\r\n                else:\r\n                    nums.append(res[i].rhs()(1))\r\n            lvcts.append(vector(nums))\r\n        for el in lvcts:\r\n            norm_lvct = (el / sqrt((el*el).n())).n()\r\n            svcts.append(norm_lvct)\r\n        ST = matrix(RR, 3)\r\n        for i in range(len(svcts)):\r\n            ST[i] = svcts[i]\r\n        a_ = ST*a\r\n        for i in range(len(lambdas)):\r\n            lambdas[i] = lambdas[i].rhs().n()\r\n        return (lambdas, a_, a0)\r\n    except:\r\n        print(\"Something gone wrong\\n\")\r\n        return (None, None, None)\r\n\\end{sageblock}\r\n\\textbf{Obtain from the function a tuple of the required coefficients.}\r\n\\begin{sageblock}\r\n(lambdas, a, a0) = kanonic_coeffs(f)\r\n\\end{sageblock} \r\n\\textbf{Display the obtained coefficients.}\r\n\\begin{sageblock}\r\nprint(\"Lambdas:\", tuple(lambdas))\r\nprint(\"a:\", a)\r\nprint(\"a0:\", a0)\r\n\\end{sageblock} \r\n\r\n\\textbf{\\textcolor{mygreen1}{Lambdas:}} $\\sage{tuple(lambdas)}$\r\n\r\n\\textbf{\\textcolor{mygreen1}{a:}} $\\sage{a}$\r\n\r\n\\textbf{\\textcolor{mygreen1}{a0:}} $\\sage{a0}$\\\\\r\n\\textbf{Create a function with obtained coefficients.}\r\n\\begin{sageblock}\r\nvar(\"kx ky kz\")\r\nfirst_part = lambdas[0]*kx^2 + lambdas[1]*ky^2 + lambdas[2]*kz^2\r\nsecond_part = 2*a[0]*kx + 2*a[1]*ky + 2*a[2]*kz + a0\r\nkanonic_func(kx, ky, kz) = first_part + second_part\r\n\\end{sageblock}\r\n\\textbf{Display the obtained function formula.}\r\n\r\n\\textcolor{myred1}{$\\sage{kanonic_func(kx, ky, kz)}$}\\\\\r\n\\textbf{Plot graphic of changed figure.} \r\n\\begin{sageblock}\r\np = implicit_plot3d(kanonic_func(kx=kx, ky=ky, kz=kz), (kx, xmin, xmax),\\\r\n(ky, ymin, ymax), (kz, zmin, zmax))\r\n\\end{sageblock}\r\n\\begin{center}\r\n\\sageplot{p}\r\n\\end{center}\r\n\r\n\\section*{Initial function.}\r\n\\begin{center}\r\n\\textcolor{myred1}{$7*x^2 + 3*y^2 + 3*z^2 +  8*x*y + 8*x*z + 6*y*z + 6*x + y + 7$}\r\n\\end{center}\r\n\r\n\\section*{Canonical function.}\r\n\r\n\\begin{center}\r\n\\textcolor{myred1}{$\\sage{lambdas[0]}*kx^2+\\sage{lambdas[1]}*ky^2 \\sage{a[2]}*kz$}\r\n\\end{center}\r\n\r\n\\end{document}", "meta": {"hexsha": "fe893a8b5752ca806e26b8b36e1d58c0215ac406", "size": 4930, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lab2/lr2.tex", "max_stars_repo_name": "Dukend/Analytical_computing_systems", "max_stars_repo_head_hexsha": "9bb9eb5be6be030710b90b06c72f76a53b43899c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lab2/lr2.tex", "max_issues_repo_name": "Dukend/Analytical_computing_systems", "max_issues_repo_head_hexsha": "9bb9eb5be6be030710b90b06c72f76a53b43899c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab2/lr2.tex", "max_forks_repo_name": "Dukend/Analytical_computing_systems", "max_forks_repo_head_hexsha": "9bb9eb5be6be030710b90b06c72f76a53b43899c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.537414966, "max_line_length": 159, "alphanum_fraction": 0.5886409736, "num_tokens": 1705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382058759128, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.7083473408932419}}
{"text": "\\documentclass[11pt, oneside]{article}\n\n\\usepackage{../../shared/preamble}\n\\addbibresource{../../shared/references.bib}\n\n\\usepackage{../sets/sets}\n\\usepackage{topological-spaces}\n\n\\title{Topological Spaces}\n\\author{Arthur Ryman, {\\tt arthur.ryman@gmail.com}}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\nThis article defines topological spaces and related concepts.\n\\end{abstract}\n\n\\section{Topological Spaces}\n\n\\subsection{$Topology$}\n\nA {\\it topology} $\\tau$ on $X$ is a family of subsets of $X$, referred to as the {\\it open} subsets of $X$, that satisfy the following axioms.\n\n\\begin{schema}{Topology}[X]\n\t\\tau: \\family X\n\\where\n\t\\emptyset \\in \\tau\n\\also\n\tX \\in \\tau\n\\also\n\t\\forall F: \\finset \\tau @ \\bigcap F \\in \\tau\n\\also\n\t\\forall F: \\power \\tau @ \\bigcup F \\in \\tau\n\\end{schema}\n\n\\begin{itemize}\n\\item The empty set is open.\n\\item The whole set is open.\n\\item The intersection of a finite family of open sets is open.\n\\item The union of any family of open sets is open. \n\\end{itemize}\n\n\\subsection{$top$ and $tops$}\n\nLet $top[X]$ denote the set of all topologies on $X$.\n\n\\begin{gendef}[X]\n\ttop: \\power(\\family X)\n\\where\n\ttop = \\{~ Topology[X] @ \\tau ~\\}\n\\end{gendef}\n\nLet $tops[X]$ denote the set of all topologies on subsets $U \\subseteq X$.\n\n\\begin{gendef}[X]\n\ttops: \\power(\\family X)\n\\where\n\ttops = \\bigcup \\{~ U: \\power X @ top[U] ~\\}\n\\end{gendef}\n\n\\subsection{$discrete$ and $indiscrete$}\n\nThe {\\it discrete} topology on $X$ consists of all subsets of $X$.\nThe {\\it indiscrete} topology on $X$ consists of just $X$ and $\\emptyset$.\nLet $discrete[X]$ and $indiscrete[X]$ denote the discrete and indiscrete topologies on $X$.\n\n\\begin{gendef}[X]\n\tdiscrete, indiscrete: \\family X\n\\where\n\tdiscrete = \\power X\n\\also\n\tindiscrete =  \\{ \\emptyset, X \\}\n\\end{gendef}\n\n\\begin{example}\nLet $\\setX$ be an arbitrary set.\nThen $discrete[\\setX]$ and $indiscrete[\\setX]$ are topologies on $\\setX$.\n\n\\begin{zed}\n\tdiscrete[\\setX] \\in top[\\setX] \n\\also\n\tindiscrete[\\setX] \\in top[\\setX]\n\\end{zed}\n\n\\end{example}\n\n\\subsection{$topGen$}\n\n\\begin{remark}\n\nThe intersection of a set of topologies on $X$ is also a topology on $X$.\n\n\\end{remark}\n\nGiven a family $B$ of subsets of $X$, the topology {\\it generated by} $B$ is the intersection of all\ntopologies that contain $B$.\nThe set $B$ is referred to as a {\\it basis} for the topology it generates.\nLet $topGen[X]~B$ denote the topology on $X$ generated by the basis $B$.\n\n\\begin{gendef}[X]\n\ttopGen: \\family X \\fun top[X]\n\\where\n\t\\forall B: \\family X @ \\\\\n\t\\t1\ttopGen~B = \\bigcap \\{~ \\tau: top[X] | B \\subseteq \\tau ~\\}\n\\end{gendef}\n\n\\begin{example}\nLet $\\setX$ be an arbitrary set.\n\n\\begin{zed}\n\ttopGen[\\setX] \\emptyset = indiscrete[\\setX]\n\\also\n\ttopGen[\\setX] \\{ \\emptyset \\} = indiscrete[\\setX]\n\\also\n\ttopGen[\\setX] \\{ \\setX \\} = indiscrete[\\setX]\n\\end{zed}\n\n\\end{example}\n\n\\subsection{$topSpace$}\n\nLet $X$ be a set.\nA {\\it topological space} is a pair $(X, \\tau)$ where $\\tau$ is a topology on $X$.\nLet $topSpace[X]$ denote the set of all topological spaces $(X,\\tau)$.\n\n\\begin{zed}\n\ttopSpace[X] == \\{~ \\tau: top[X] @ (X, \\tau) ~\\}\n\\end{zed}\n\n\\begin{example}\nLet $\\setX$ be an arbitrary set.\n\n\\begin{zed}\n\t(\\setX, indiscrete[\\setX]) \\in topSpace[\\setX]\n\\also\n\t(\\setX, discrete[\\setX]) \\in topSpace[\\setX]\n\\end{zed}\n\n\n\\end{example}\n\n\\subsection{$topSpaces$}\n\nLet $topSpaces[t]$ dentote the set of all topological spaces $(X,\\tau)$ where $X$ is a subset of $t$.\n\n\\begin{gendef}[t]\n\ttopSpaces: \\power t \\rel \\family t\n\\where\n\ttopSpaces = \\{~ X: \\power t; \\tau: \\family t | \\tau \\in top[X] ~\\}\n\\end{gendef}\n\n\\begin{remark}\n\n\\begin{zed}\n\ttopSpace[\\setX] \\subseteq topSpaces[\\setX]\n\\end{zed}\n\n\\end{remark}\n\n\\section{Continuous Mappings}\n\nLet $(X,\\tau)$ and $(Y,\\sigma)$ be topological spaces.\n\n\\subsection{$Continuous$}\n\nA mapping $f \\in X \\fun Y$ is said to be {\\it continuous} if the inverse image of every open set is open.\n\n\\begin{schema}{Continuous}[X,Y]\n\tf: X \\fun Y \\\\\n\t\\tau: top[X] \\\\\n\t\\sigma: top[Y]\n\\where\n\t\\forall U: \\sigma @ \\\\\n\t\\t1\tf\\inv\\limg U \\rimg \\in \\tau\n\\end{schema}\n\n\\subsection{\\zcmd{CzeroTT}}\n\nLet $A$ and $B$ be topological spaces, and\nlet $\\CzeroTT(A,B)$ denote the set of continuous mappings from $A$ to $B$.\n\n\\begin{gendef}[X,Y]\n\t\\CzeroTT: topSpace[X] \\cross topSpace[Y] \\fun \\power (X \\fun Y)\n\\where\n\t\\forall \\tau: top[X]; \\sigma: top[Y] @ \\\\\n\t\\t1\t\\LET A == (X, \\tau); B == (Y, \\sigma) @ \\\\\n\t\\t2\t\t\\CzeroTT(A,B) = \\{~ f: X \\fun Y | Continuous[X,Y] ~\\}\n\\end{gendef}\n\n\\subsection{The Identity Mapping}\n\n\\begin{remark}\nThe identity mapping is continuous.\n\n\\begin{zed}\n\t\\forall \\tau: top[\\setX] @ \\\\\n\t\\t1\t\\LET A == (\\setX, \\tau) @ \\\\\n\t\\t2\t\t\\id \\setX \\in \\CzeroTT(A, A)\n\\end{zed}\n\n\\end{remark}\n\n\\begin{remark}\nThe constant mapping is continuous.\n\n\\begin{zed}\n\t\\forall \\tau: top[\\setX]; \\sigma: top[\\setY]; c: \\setY @ \\\\\n\t\\t1\t\\LET A == (\\setX, \\tau); B == (\\setY, \\sigma) @ \\\\\n\t\\t2\t\t\\const[\\setX,\\setY] c \\in \\CzeroTT(A,B)\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{Composition of Continuous Mapping}\n\n\\begin{remark}\nLet $\\setX$, $\\setY$, and $\\setZ$ be arbitrary sets.\nThe composition of continuous mappings is a continuous mapping.\n\n\\begin{zed}\n\t\\forall A: topSpace[\\setX]; B: topSpace[\\setY]; C: topSpace[\\setZ] @ \\\\\n\t\\t1\t\\forall f: \\CzeroTT(A, B); g: \\CzeroTT(B, C) @ \\\\\n\t\\t2\t\tg \\circ f \\in \\CzeroTT(A, C)\n\\end{zed}\n\n\\end{remark}\n\n\\section{Induced Topology}\n\nLet $A = (X, \\tau)$ be a topological space and let $U \\subseteq X$ be a subset.\nThe topology on $X$ {\\it induces} a topology on $U$.\nThis topology is variously referred to as the {\\it induced}, {\\it relative}, or {\\it subspace} topology on $U$.\n\n\\subsection{\\zcmd{inducedFam}}\n\nLet $\\phi$ be a family of subsets of $X$ and let $U$ be a subset of $X$.\nThe family of subsets of $U$ {\\it induced} by $\\phi$ is the set of intersections of the members of $\\phi$ with $U$.\nLet $\\phi \\inducedFam U$ denote the family on $U$ induced by $\\phi$.\n\n\\begin{gendef}[X]\n\t\\_ \\inducedFam \\_:  \\family X \\cross \\power X \\fun \\family X\n\\where\n\t\\forall \\phi: \\family X; U: \\power X @ \\\\\n\t\\t1\t\\phi \\inducedFam U = \\{~ Y: \\phi @ Y \\cap U ~\\}\n\\end{gendef}\n\n\\begin{remark}\nIf $\\tau$ is a topology on $X$ then $\\tau \\inducedFam U$ is a topology on $U$.\n\n\\begin{zed}\n\t\\forall \\tau: top[\\setX]; U: \\power \\setX @ \\\\\n\t\\t1\t\\tau \\inducedFam U \\in top[U]\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{\\zcmd{inducedTopSp}}\n\nLet $(X, \\tau) \\inducedTopSp U$ denote the corresponding induced topological space.\n\n\\begin{gendef}[X]\n\t\\_ \\inducedTopSp \\_: topSpace[X] \\cross \\power X \\fun topSpaces[X]\n\\where\n\t\\forall \\tau: top[X]; U: \\power X @ \\\\\n\t\\t1\t(X, \\tau) \\inducedTopSp U = (U, \\tau \\inducedFam U)\n\\end{gendef}\n\n\\section{Product Topology}\n\nLet $(X, \\tau)$ and $(Y, \\sigma) $ be topological spaces.\nThere is a natural topology on $X \\cross Y$ generated by the products of the sets in $\\tau$ and $\\sigma$.\n\n\\subsection{\\zcmd{prodFam}}\n\nLet $X$ and $Y$ be sets and let $\\phi$ and $\\psi$ be families on them.\nThe product of these families is the family that consists of the products of the sets in them and is a family on $X \\cross Y$.\nLet $\\phi \\prodFam \\psi$ denote the product of the families.\n\n\\begin{gendef}[X,Y]\n\t\\_ \\prodFam \\_ : \\family X \\cross \\family Y \\fun \\family(X \\cross Y)\n\\where\n\t\\forall \\phi: \\family~X; \\psi: \\family~Y @ \\\\\n\t\\t1\t\\phi \\prodFam \\psi = \\{~ U: \\phi; V: \\psi @ U \\cross V ~\\}\n\\end{gendef}\n\n\\begin{remark}\n\nIf $\\tau$ and $sigma$ are topologies then $\\tau \\prodFam \\sigma$ is not, in general, a topology.\nHowever, we can use it to generate a topology.\n\n\\end{remark}\n\n\\subsection{\\zcmd{prodTop}}\n\nLet $\\tau \\prodTop \\sigma$ denote the topology generated by $\\tau \\prodFam \\sigma$.\n\n\\begin{gendef}[X,Y]\n\t\\_ \\prodTop \\_: top[X] \\cross top[Y] \\fun top[X \\cross Y]\n\\where\n\t\\forall \\tau: top[X]; \\sigma: top[Y] @ \\\\\n\t\\t1\t\\tau \\prodTop \\sigma = topGen(\\tau \\prodFam \\sigma)\n\\end{gendef}\n\n\\subsection{\\zcmd{prodTopSp}}\n\nLet $(X, \\tau) \\prodTop (Y, \\sigma)$ denote the product topological space.\n\n\\begin{gendef}[X,Y]\n\t\\_ \\prodTopSp \\_: topSpace[X] \\cross topSpace[Y] \\fun topSpace[X \\cross Y]\n\\where\n\t\\forall \\tau: top[X]; \\sigma: top[Y] @ \\\\\n\t\\t1\t(X, \\tau) \\prodTopSp (Y, \\sigma) = (X \\cross Y, \\tau \\prodTop \\sigma)\n\\end{gendef}\n\n\\printbibliography\n\n\\end{document}", "meta": {"hexsha": "a80756419fbdd462007beb6e93b6f987ab20c29f", "size": 8174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "articles/topological-spaces/topological-spaces.tex", "max_stars_repo_name": "agryman/mathz", "max_stars_repo_head_hexsha": "a516a20936e1ed7b9f07c546eee7aacf1831de65", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-30T08:06:17.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-30T08:06:17.000Z", "max_issues_repo_path": "articles/topological-spaces/topological-spaces.tex", "max_issues_repo_name": "agryman/mathz", "max_issues_repo_head_hexsha": "a516a20936e1ed7b9f07c546eee7aacf1831de65", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "articles/topological-spaces/topological-spaces.tex", "max_forks_repo_name": "agryman/mathz", "max_forks_repo_head_hexsha": "a516a20936e1ed7b9f07c546eee7aacf1831de65", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.54375, "max_line_length": 142, "alphanum_fraction": 0.6598972351, "num_tokens": 2847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907932, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.708301897768896}}
{"text": "\\chapter{Distance Oracles}\n\nIn this chapter, we learn about distance oracles as presented in the seminal paper \\cite{thorup2005approximate}. Distance Oracles are data structures that allow for any undirected graph $G =(V,E)$ to be stored compactly in a format that allows to query for the (approximate) distance between any two vertices $u,v$ in the graph. The main result of this chapter is the following data structure.\n\n\\begin{theorem}\\label{thm:mainDistanceOracle}\nThere is an algorithm that, for any integer $k \\geq 1$ and undirected graph $G=(V,E)$, computes a data structure that can be stored using $\\tilde{O}(kn^{1+1/k})$ bits such that on querying any two vertices $u,v \\in V$ returns in $O(k)$ time a distance estimate $\\widetilde{\\mathbf{dist}}(u,v)$ such that\n\\[\n\\mathbf{dist}(u,v) \\leq \\widetilde{\\mathbf{dist}}(u,v) \\leq (2k-1) \\cdot \\mathbf{dist}(u,v).\n\\]\nThe algorithm computes the data structure in expected time $\\tilde{O}(kmn^{1/k})$.\n\\end{theorem}\n\n\\begin{remark}Note that for $k=1$, the theorem above is trivial: it can be solved by computing APSP and storing the distance matrix of $G$.\n\\end{remark}\n\n\\begin{remark}\nWe point out that given space $O(n^{1+1/k})$, approximation $(2k-1)$ is the best that we can hope for according to a popular and widely believed conjecture that essentially says that there are unweighted graphs that have no cycle of length $(2k+1)$ but have $\\tilde{\\Omega}(n^{1+1/k})$ edges. A more careful analysis than we will carry out allows to shave all logarithmic factors from \\Cref{thm:mainDistanceOracle} and therefore the data structure is only a factor $k$ off in space from optimal while also answering queries \\emph{extremely} efficiently. It turns out that the factor $k$ can also be removed in space and query time (although currently preprocessing is quite expensive), see therefore the following (really involved) articles \\cite{chechik2014approximate, chechik2015approximate}.\n\\end{remark}\n\n\\begin{remark}\nAlso note that in directed graphs no such distance oracle is possible. Even maintaining the transitive closure (the information of who reaches who) can only be preserved if one stores $\\tilde{\\Omega}(n^2)$ bits.\n\\end{remark}\n\n\\section{Warm-up: A Distance Oracle for $k=2$}\n\nLet us first describe the data structure for the case where $k=2$. See therefore the pseudo-code below. Here we use the convention that $\\mathbf{dist}(x,X)$ for some vertex $x \\in V$ and some subset $X \\subseteq V$ is the minimum distance from $x$ to any $y \\in X$, formally $\\mathbf{dist}(x,X) = \\min_{y \\in X} \\mathbf{dist}(x,y)$.\n\n\\begin{algorithm}\n  \\SetAlgoLined\n  Obtain $S$ by sampling every vertex $v \\in V$ i.i.d. with probability $n^{-1/2}$\\;\n  \\ForEach{$s \\in S$}{\n    Compute all distances from $s$ to any other vertex $v \\in V$\\;\n    In a hash table $\\mathcal{H}_s$ store for each $v \\in V$ an entry with key $v$ and value $\\mathbf{dist}_G(s,v)$.\n  }\n  \n  \\ForEach{$u \\in V \\setminus S$}{\n    Find the \\emph{pivot} $p(u)$ of $u$ to be some vertex in $S$ that minimizes the distance to $u$\\;\n    Store $p(u)$ along with $\\mathbf{dist}_G(u,p(u)) = \\mathbf{dist}_G(u,S)$\\;\n    Find the \\emph{bunch} $B(u) = \\{ v \\in V \\;|\\; \\mathbf{dist}_G(u,v) < \\mathbf{dist}_G(u,S)\\}$\\;\n    In a hash table $\\mathcal{H}_u$ store for each $v \\in B(v)$ an entry with key $v$ and value $\\mathbf{dist}_G(u,v)$.\n  }\n  \\caption{\\textsc{Preprocess}(G)}\n\\end{algorithm}\n\nThe key to the algorithm is the definition of \\emph{pivots} and \\emph{bunches}. Below is an example that illustrates their definitions.\n\n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[scale=0.2]{./fig/lecture_DistanceOracles_Bunch.jpeg}\n    \\caption{Graph $G$ (without the edges) where vertices are drawn according to their distance from $u$. The blue and red vertices are in $S$. The red vertex is chosen to be the pivot $p(u)$. Note that another vertex in $S$ could have been chosen to become the pivot. The bunch of $u$ is the vertices that are strictly withing the red circle. In particular, both blue vertices, the red vertex and also the white vertex on the boundary of the red circle are \\emph{not} in the bunch $B(u)$.}\n\\end{figure}\n\nWithout further due, let us discuss the query procedure which is depicted below. It essentially consists of checking whether the vertex $v$ is already in the bunch of $u$ in which case we have stored the distance $\\mathbf{dist}_G(u,v)$ explicitly. Otherwise, it uses a detour via its pivot.\n\n\\begin{algorithm}\n  \\SetAlgoLined\n  \\lIf{$v \\in \\mathcal{H}_u$}{\n    \\Return value $\\mathbf{dist}_G(u,v)$\n  }\n  \\Return $\\mathbf{dist}_G(u,p(u)) + \\mathbf{dist}_G(p(u),v)$ (the latter from $\\mathcal{H}_{p(u)}$)\n  \\caption{\\textsc{Query}(u,v)}\n\\end{algorithm}\n\nThe second case is illustrated below.\n\n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[scale=0.25]{./fig/lecture_DistanceOracles_Query.jpeg}\n\\end{figure}\n\n\\paragraph{Approximation Analysis.} It is straight-forward to see that if we return in line 1 of the query algorithm, then we return the exact distance.\n\nIf we return in the second line, then we know that $v \\not\\in B(u)$. By definition of a bunch this implies that \n\\[\n \\mathbf{dist}(u,v) \\geq \\mathbf{dist}(u,S) = \\mathbf{dist}(u,p(u)).\n\\]\nWe can further use the triangle inequality to conclude that\n\\[\n\\mathbf{dist}_G(p(u),v) \\leq \\mathbf{dist}(u,p(u)) + \\mathbf{dist}(u,v)\n\\]\nCombining these two inequalities, we obtain\n\\[\n\\mathbf{dist}_G(u,p(u)) + \\mathbf{dist}_G(p(u),v) \\leq 2 \\cdot \\mathbf{dist}(u,p(u)) + \\mathbf{dist}(u,v) \\leq 3 \\cdot \\mathbf{dist}(u,v).\n\\]\nWe conclude that we obtain a $3$-approximation.\n\n\\paragraph{Space Analysis.} For each vertex $s \\in S$, we store a hash-table with one entry for each vertex $v$. This can be stored with space $O(|S|n)$. We have by a standard Chernoff-bound that $|S| = \\tilde{O}(\\sqrt{n})$ w.h.p. so this becomes $\\tilde{O}(n^{3/2})$.\n\nNext, fix some $u \\in V \\setminus S$, and let us argue about the size of $B(u)$ (which asymptotically matches $|\\mathcal{H}_u|$). We order the vertices $v_1, v_2, \\dots, v_n$ in $V$ by their distance from $u$. Since we sample uniformly at random, by a simple Chernoff bound, we obtain that the first vertex $v_i$ in $v_1, v_2, \\dots, v_n$ that is in $S$ has $i = \\tilde{O}(\\sqrt{n})$ w.h.p.. But note that since only vertices that are \\emph{strictly} closer to $u$ than $v_i$ are in $B(u)$, this implies that $|B(u)| = \\tilde{O}(\\sqrt{n})$.\n\nIt remains to take a careful union bound over all bad events at every vertex $u \\in V \\setminus S$ to conclude that with high probability, the hash tables $\\mathcal{H}_u$ for all $u \\in V \\setminus S$ combined take total space $\\tilde{O}(|V \\setminus S| \\sqrt{n}) = \\tilde{O}(n^{3/2})$. For the rest of the section, we condition on the event that each $|B(v)| =\\tilde{O}(\\sqrt{n})$ to use it as if it was a deterministic guarantee.\n\n\\paragraph{Preprocessing and Query Time.} In order to find the distances stored in the hash tables $\\mathcal{H}_s$ for $s \\in S$, we can simply run Dijkstra from each $s \\in S$ on the graph in total time $\\tilde{O}(m|S|) = \\tilde{O}(mn^{1/2})$.\n\nTo compute the \\emph{pivots} for each vertex $u$, we can insert a super-vertex $s'$ and add an edge from $s'$ to each $s \\in S$ of weight $0$. We can then run Dijkstra from $s'$ on $G \\cup \\{s'\\}$. Note that for each $u$, we have $\\mathbf{dist}_{G \\cup \\{s'\\}}(s', u) = \\mathbf{dist}_G(p(u),u)$ and that $p(u)$ can be chosen to be the closest vertex on the path from $s'$ to $u$ that Dijkstra outputs along with the distances (recall that Dijkstra can output a shortest path tree). This takes $\\tilde{O}(m)$ time.\n\nIt remains to compute the bunches $B(u)$. Here, we use duality: we define the cluster $C(w)$ for every vertex $w \\in V \\setminus S$ to be the set\n\\[\n    C(w) = \\{ v \\in V \\;|\\; \\mathbf{dist}_G(v,w) < \\mathbf{dist}_G(v,p(v))\\}.\n\\]\nNote the subtle difference to the bunches in that membership of $v$ now depends on $p(v)$ and \\emph{not} on $p(u)$! It is not hard to see that $u \\in C(w) \\iff w \\in B(u)$. And it is straight-forward to compute the bunches from the clusters in time $O(\\sum_v |B(v)|) = O(\\sum_w |C(w)|) = \\tilde{O}(n^{3/2})$. \n\nFinally, it turns out that we can compute each $C(w)$ by running Dijkstra with a small modification.\n\n\\begin{lemma}[Lemma 4.2 in \\cite{thorup2005approximate}]\nConsider running Dijkstra from a vertex $w$ but only relaxing edges incident to vertices $v$ that satisfy $\\mathbf{dist}_G(v,w) < \\mathbf{dist}_G(v,p(v))$. Then, the algorithm computes $C(w)$ and all distances $\\mathbf{dist}(v,w)$ for $v \\in C(w)$ in time $\\tilde{O}(|E(C(w))|)$ where $E(C(w))$ are the edges that touch a vertex in $C(w)$. \n\\end{lemma}\n \nIt remains to observe that the total time required to compute all clusters is\n\\[\n    \\tilde{O}(\\sum_{w} |E(C(w))|) = \\tilde{O}(\\sum_{w, v \\in C(w)} |E(v)|) = \\tilde{O}(\\sum_{v, w \\in B(v)} |E(v)|) = \\tilde{O}(\\sum_{v} |E(v)| |B(v)|).\n\\]\nBut we have upper bounded $|B(v)| = \\tilde{O}(\\sqrt{n})$ for all $v$, thus each vertex just pays its degree $\\tilde{O}(\\sqrt{n})$ times and we get running time $\\tilde{O}(m\\sqrt{n})$.\n\n\\paragraph{Monte Carlo vs. Las Vegas.} Note that the analysis above only guarantees that the algorithm works well with high probability. However, it is not hard to see that the algorithm can be transformed into a Las Vegas algorithm: whenever we find a bunch $B(v)$ whose size exceeds our $\\tilde{O}(\\sqrt{n})$ bound, we simply re-run the algorithm. This guarantees that the final data structure that we output indeed satisfies the guarantees stipulated in the theorem.\n\n\\section{Distance Oracles for any $k \\geq 2$}\n\nThe generalization for all $k$'s is rather straight-forward except for the query operation which works a bit magically. Let's first define the data structure by giving our new pre-processing algorithm.\n\n\\begin{algorithm}\n  \\SetAlgoLined\n  $S_1 = V$; $S_{k+1} = \\emptyset$\\;\n  \\lForEach{$i \\in [1,k]$}{\n    Obtain $S_{i+1}$ by sampling every $v \\in S_{i}$ i.i.d. with prob. $n^{-1/k}$\n  }\n  \n    \\ForEach{$u \\in V$}{\n        \\ForEach{$i \\in [1,k]$}{Let $p_{i}(u)$ be some vertex in $S_{i}$ that minimizes the distance to $u$\\;\n        Store $p_{i}(u)$ along with $\\mathbf{dist}_G(u,p_{i}(u))$. }\n        Let \\emph{bunch} $B(u) = \\bigcup_i B_i(u)$ where $B_i(u) = \\{ v \\in S_i \\;|\\; \\mathbf{dist}_G(u,v) < \\mathbf{dist}_G(u,S_{i+1})\\}$\\;\n        In a hash table $\\mathcal{H}_u$ store for each $v \\in B(v)$ an entry with key $v$ and value $\\mathbf{dist}_G(u,v)$.\n     }\n  \\caption{\\textsc{Preprocess}(G)}\n\\end{algorithm}\n\nNote that in a sense this algorithm is almost easier than the one for $k=2$ since it treats each level in the same fashion. Here we ensure that the last set $S_{k+1}$ is empty (which would happen with constant probability otherwise). \n\nWe make the implicit assumption throughout that $S_k \\neq \\emptyset$ so that $p_k(u)$ is well-defined for each $u$. We also define $\\mathbf{dist}(x,X) = \\infty$ if $X$ is the empty set.\n\nThe drawing below illustrates the new definition of a bunch where we have chosen $k=3$ to keep things simple.\n\n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[scale=0.25]{./fig/lecture_DistanceOracles_MultiLevelBunch.jpg}\n    \\caption{Graph $G$ (without the edges) where vertices are drawn according to their distance from $u$. All vertices are in $S_1$. The blue and red vertices are in $S_2$. The dark blue and dark red vertices are also in $S_3$. Finally, we have $S_4 = \\emptyset$. \n    The light red vertex is chosen as pivot $p_2(u)$; the dark red vertex is chosen as pivot $p_3(u)$. \n    The bunch $B(u)$ includes all vertices that have a black edge in this graph to $u$; in particular these are the white vertices within the circle drawn in light red ($B_1(u)$); the light blue vertices encircled by the dark red circle ($B_2(u)$); and all dark blue vertices ($B_3(u)$).}\n\\end{figure}\n\nBefore we explain the query procedure, let us give a (rather informal) analysis of the space required by our new data structure.\n\n\\paragraph{Space Analysis.} We have for each vertex $u \\in V$, and each $1 \\leq i \\leq k$ that the bunch $B_i(u)$ consists of all vertices in $S_i$ that are closer to $u$ than the closest vertex in $S_{i+1}$. \n\nNow, order the vertices $x_1, x_2, \\dots$ in $S_i$ by their distance from $u$. Since each vertex in $S_i$ is sampled into $S_{i+1}$ with probability $n^{-1/k}$, we have that with high probability some vertex $x_i$ with $i = O(n^{1/k} \\log n)$ is sampled into $S_{i+1}$. This ensures that $|B_i(u)| = \\tilde{O}(n^{1/k})$ with high probability. \n\nApplying this argument for all $i$, we have that $|B(u)| = \\tilde{O}(k \\cdot n^{1/k})$ for each $u$ w.h.p. and therefore our space bound follows.\n\n\\paragraph{Preprocessing Time.} Much like in the $k=2$ construction, we can define for each $u \\in S_i \\setminus S_{i+1}$ the cluster $C(u) = \\{ v \\in V \\;|\\; \\mathbf{dist}_G(u,v) < \\mathbf{dist}_G(u,S_{i+1})\\}$. Extending our analysis from before using this new definition, we get construction time $\\tilde{O}(kmn^{1/k})$.\n\n\\paragraph{Query Operation.} A straight-forward way to query our new data structure for a tuple $(u,v)$ would be to search for the smallest $i$ such that $v \\in B(p_i(u))$ and then return $\\mathbf{dist}_G(u, p_i(u)) + \\mathbf{dist}_G(p_i(u), v)$. This can be analyzed in the same way as we did for $k=2$ to obtain stretch $4k-3$\\footnote{One can actually prove that this strategy gives an $4k-5$ stretch with a little trick.}.\n\nHowever, we aim for stretch approximation $2k-1$. We state below the pseudo-code to achieve this guarantee.\n\n\\begin{algorithm}\n  \\SetAlgoLined\n  $w \\gets u$; $i \\gets 1$\\;\n  \\While{$w \\not\\in B(v)$}{\n    $i \\gets i+1$\\;\n    $(u,v) \\gets (v,u)$\\;\n    $w \\gets p_i(u)$\n  }\n  \\Return $\\mathbf{dist}_G(u,w) + \\mathbf{dist}_G(w,v)$\n  \\caption{\\textsc{Query}(u,v)}\n\\end{algorithm}\n\nOur main tool in the analysis is the claim below where we define $\\Delta = \\mathbf{dist}_G(u,v)$. \n\n\\begin{claim}\\label{claim:DistanceOracleSwapping} After the $i^{th}$ iteration of the while-loop, we have $\\mathbf{dist}_G(u,w) \\leq i\\Delta$.\n\\end{claim}\n\nThis implies our theorem, since we have at most $k-1$ iterations, then $w$ is a vertex in $S_k$ and $S_k \\subseteq B(x)$ for all vertices $x \\in V$. Therefore we have that for the final $w$, we have $\\mathbf{dist}_G(u,w) \\leq (k-1)\\Delta$. It remains to conclude by the triangle inequality that \n\\[\n\\mathbf{dist}_G(u,w) + \\mathbf{dist}_G(w,v) \\leq 2\\mathbf{dist}_G(u,w) + \\Delta \\leq (2k-1)\\mathbf{dist}_G(u,v).\n\\]\n\n\\begin{proof}[Proof of \\Cref{claim:DistanceOracleSwapping}]\nLet $w_i, u_i, v_i$ denote the variables $w,u,v$ after the $(i+1)^{th}$ while-loop iteration (or right before for $w_0,u_0,v_0$).\n\nFor $i = 0$, we have that $w_0 = u_0$; thus, $\\mathbf{dist}_G(u_0,w_0) = 0$.\n\nFor $i \\geq 1$, we want to prove that if the $i^{th}$ while-loop iteration is executed then $\\mathbf{dist}_G(u_i,w_i) \\leq \\mathbf{dist}_G(u_{i-1},w_{i-1}) + \\Delta$ (if it is not executed then the statement follows trivially).\n\nIn order to prove this, observe that by the while-loop condition, we must have had $w_{i-1} \\not\\in B(v_{i-1})$, thus  $\\mathbf{dist}_G(v_{i-1}, w_{i-1}) \\geq \\mathbf{dist}_G(v_{i-1}, p_i(v_{i-1}))$.\n\nBut the while-iteration sets $u_i = v_{i-1}$ and $w_i = p_i(v_{i-1})$, and therefore we have\n\\begin{align*}\n\\mathbf{dist}_G(u_{i}, w_i) &= \\mathbf{dist}_G(v_{i-1}, p_i(v_{i-1})) \\leq\n\\mathbf{dist}_G(v_{i-1}, w_{i-1}) = \\mathbf{dist}_G(v_{i-1}, p_{i-1}(u_{i-1})) \\\\\n&\\leq \\mathbf{dist}_G(u_{i-1}, p_{i-1}(u_{i-1})) + \\mathbf{dist}_G(v_{i-1}, u_{i-1}) = \\mathbf{dist}_G(u_{i-1}, w_{i-1}) + \\Delta.\n\\end{align*}\n\\end{proof}", "meta": {"hexsha": "b8ec1762fb78c114be36116d0f03bf3972e067d5", "size": 15579, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "agao21_script/lecture_DistanceOracles.tex", "max_stars_repo_name": "rjkyng/agao21_script", "max_stars_repo_head_hexsha": "772f8c17b0802ec43d45e1480f7193dd0eceadb7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-15T09:04:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-26T05:39:09.000Z", "max_issues_repo_path": "agao21_script/lecture_DistanceOracles.tex", "max_issues_repo_name": "rjkyng/agao21_script", "max_issues_repo_head_hexsha": "772f8c17b0802ec43d45e1480f7193dd0eceadb7", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "agao21_script/lecture_DistanceOracles.tex", "max_forks_repo_name": "rjkyng/agao21_script", "max_forks_repo_head_hexsha": "772f8c17b0802ec43d45e1480f7193dd0eceadb7", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2021-03-11T12:35:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-13T06:04:51.000Z", "avg_line_length": 77.1237623762, "max_line_length": 795, "alphanum_fraction": 0.6897105077, "num_tokens": 5028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7083018891486978}}
{"text": "\\subsection{part b}\n$$\\vec X_0 = \\begin{bmatrix}\n\t-1\\\\1\n\\end{bmatrix}$$\nTolerance is: $10^{-7}$\n\n\n$$\\vec X_{ans} = \\begin{bmatrix}\n\t-1.7556\\\\\n\t0.3655\n\\end{bmatrix}$$\n\\subsubsection{figures}\n\\newpage\n\\begin{itemize}\n\t\\item Steepest Descent\n\t\\begin{itemize}\n\t\t\\item Quadratic Interpolation\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{Steepest Descent and Quadratic Interpolation}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q1/part b Steepest Descent + Quadratic Interpolation.png}\n\t\t\\end{figure}\n\t\t\\item Golden Section\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{Steepest Descent and Golden Section}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q1/part b Steepest Descent + Golden Section.png}\n\t\t\\end{figure}\n\t\\end{itemize}\n\t\\item BFGS\n\t\\begin{itemize}\n\t\t\\item Quadratic Interpolation\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{BFGS and Quadratic Interpolation}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q1/part b BFGS + Quadratic Interpolation.png}\n\t\t\\end{figure}\n\t\t\\item Golden Section\n\t\t\\begin{figure}[H]\n\t\t\t\\caption{BFGS and Golden Section}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=11.5cm]{../Figure/Q1/part b BFGS + Golden Section.png}\n\t\t\\end{figure}\n\t\\end{itemize}\n\\end{itemize}\n\\subsubsection{result}\n\\begin{itemize}\n\t\\item Time\n\t\\begin{table}[H]\n\t\t\\caption {Time compare between four methods} \n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{ |c|c|c|c| }\n\t\t\t\t\\hline\n\t\t\t\t\\multicolumn{2}{|c|}{Steepest Descent} &\n\t\t\t\t\\multicolumn{2}{|c|}{BFGS} \\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\tQuadratic Interpolation & Golden Section & Quadratic Interpolation &\n\t\t\t\tGolden Section \\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\t$0.208\\sec$ & $0.146\\sec$ & $0.106\\sec$ & $0.142\\sec$\\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\t\\end{table}\n\t\\item Number of Cost calculation\n\t\\begin{table}[H]\n\t\t\\caption {Number of Cost calculation compare between four methods} \n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{ |c|c|c|c| }\n\t\t\t\t\\hline\n\t\t\t\t\\multicolumn{2}{|c|}{Steepest Descent} &\n\t\t\t\t\\multicolumn{2}{|c|}{BFGS} \\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\tQuadratic Interpolation & Golden Section & Quadratic Interpolation &\n\t\t\t\tGolden Section \\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\t$246$ & $285$ & $142$ & $142$\\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\t\\end{table}\n\t\\item Number of Gradient calculation\n\t\\begin{table}[H]\n\t\t\\caption {Number of Gradient calculation compare between four methods} \n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{ |c|c|c|c| }\n\t\t\t\t\\hline\n\t\t\t\t\\multicolumn{2}{|c|}{Steepest Descent} &\n\t\t\t\t\\multicolumn{2}{|c|}{BFGS} \\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\tQuadratic Interpolation & Golden Section & Quadratic Interpolation &\n\t\t\t\tGolden Section \\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\t$14$ & $12$ & $7$ & $7$\\Tstrut\\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\t\\end{table}\n\\end{itemize}", "meta": {"hexsha": "89ea1b79d068920898a1d9555379de251555e95f", "size": 2698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW3/Report/Q1/Q1_b.tex", "max_stars_repo_name": "alibaniasad1999/Optimal-Control", "max_stars_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-09T13:16:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-09T13:16:54.000Z", "max_issues_repo_path": "HW/HW3/Report/Q1/Q1_b.tex", "max_issues_repo_name": "alibaniasad1999/Optimal-Control", "max_issues_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW/HW3/Report/Q1/Q1_b.tex", "max_forks_repo_name": "alibaniasad1999/Optimal-Control", "max_forks_repo_head_hexsha": "f384c9e4c5ddc45b2bbab0f0bb9f666f64eece53", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.2525252525, "max_line_length": 101, "alphanum_fraction": 0.6679021497, "num_tokens": 1041, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7083018870381255}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{subfigure}\n\\usepackage{float}\n\\usepackage{ulem}\n\\usepackage{bm}\n\n\\usepackage{anysize}\n\n\\marginsize{2cm}{2cm}{0.9cm}{1.8cm}\n\\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}\n\\usepackage{listings}\n\\lstset{language=Matlab}\n\\lstset{breaklines}\n\\lstset{extendedchars=false}\n\n\\title{Machine Learning/Pattern Recognition\\\\  \\begin{Large} Homework \\#1 \\end{Large} }\n\\author{Jiyu Tian}\n\\date{}\n\n\n\\begin{document}\n\n\\maketitle\n%%---------------------------------------------------------------\n%% Problem 1\n%%---------------------------------------------------------------\n\\section{Problem 1}\n(a) Since $\\int_{-\\infty}^{+\\infty} p(x|w_i) \\text{ d}x =1$, then we have\n\\begin{equation*}\n\\begin{aligned}\n\\int_{-\\infty}^{+\\infty} p(x|w_i) \\text{ d}x &=\\int_{-\\infty}^{a_i} A e^{(x-a_i)/b_i} \\text{ d}x \\ + \\int_{a_i}^{+\\infty} A e^{-(x-a_i)/b_i} \\text{ d}x \\\\ \n&=Ab_i[\\left.e^{(x-a_i)/b_i} \\right|^{a_i} _{-\\infty} \\left.-e^{-(x-a_i)/b_i} \\right|^{+\\infty} _{a_i} \\ ]\\\\\n&=Ab_i[1-(-1)]=2Ab_i=1\n\\end{aligned}\n\\end{equation*}\nSo $A=\\frac{1}{2b_i}$. Then the normalized analytic expression is:\n\\begin{equation*}\np(x|w_i)=\\frac{1}{2b_i} e^{-|x-a_i|/b_i}\\ \\ \\  \\text{for}\\ \\  i=1,2 \\ \\  \\text{and} \\ \\ b\\geq 0\n\\end{equation*}\n(b) The likelihood ratio is given by:\n\\begin{equation*}\n\\begin{aligned}\n\\frac {p(x|w_1)}{p(x|w_2)} &=(\\frac{1}{2b_1} e^{-|x-a_1|/b_1})/(\\frac{1}{2b_2} e^{-|x-a_2|/b_2})\\\\\n&= \\ \\frac{b_2}{b_1} e^{-|x-a_1|/b_1+|x-a_2|/b_2}\n\\end{aligned}\n\\end{equation*}\n(c) When $a_1=1,b_1=1,a_2=2,b_2=2$, we have:\n\\begin{equation*}\n\\frac {p(x|w_1)}{p(x|w_2)}=\\ 2e^{-|x-1|+\\frac{|x-2|}{2}} \n\\end{equation*}\nUsing the following MATLAB code, the likelihood ratio is plotted as Figure \\ref{fig1}:\n\\begin{lstlisting}\nclear;clc\n\nx = -2:0.00001:5;\ny = 2 * exp( abs(x-2) / 2 - abs(x-1) );\n\nhold on\nplot(x, y, 'k')\nplot(2, 2 * exp (-1), 'ro')\nplot(1, 2 * exp (0.5), 'ro')\nhold off\ntitle('$Likelihood\\ Ratio\\ as\\ a\\ function\\ of\\ x$', 'Interpreter', 'latex')\nxlabel('$x$', 'Interpreter', 'latex')\nylabel('$Likelihood\\ Ratio$', 'Interpreter', 'latex')\ngrid on\n\\end{lstlisting}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{11c.jpg}\n\\caption{\\label{fig1}Likelihood Ratio.}\n\\end{figure}\n\n%%---------------------------------------------------------------\n%% Problem 2\n%%---------------------------------------------------------------\n\\section{Problem 2}\n(a) Given $P(w_1)=P(w_2)$, we have $P(w_1)=P(w_2)=\\frac{1}{2}$. So, solving for the Bayes optimal decision boundary is a matter of solving for the roots of the equation below:\\\\\n\\begin{equation*}\n\\begin{aligned}\np(w_1|x)&=p(w_2|x)\\\\\n\\frac{p(x|w_1)P(w_1)}{P(x)} & =\\frac{p(x|w_2)P(w_2)}{P(x)}\\\\\np(x|w_1)&=p(x|w_2)\\\\\n\\frac{1}{\\sqrt{2\\pi}} e^{-\\frac{1}{2} x^2} & = \\frac{1}{\\sqrt{2\\pi}\\sigma} e^{-\\frac{1}{2\\sigma^2} (x-\\mu)^2} \\\\\n\\sigma e^{-\\frac{1}{2} x^2} & = e^{-\\frac{1}{2\\sigma^2} (x-\\mu)^2} \\\\\nln(\\sigma)-\\frac{1}{2} x^2 & =-\\frac{1}{2\\sigma^2} (x-\\mu)^2 \\\\\n2\\sigma^2ln(\\sigma)-\\sigma^2 x^2 & = -(x-\\mu)^2 \\\\\n\\end{aligned}\n\\end{equation*}\n\\begin{equation*}\n(\\sigma^2-1)x^2+2\\mu x-\\mu^2-2\\sigma^2ln\\sigma =0\n\\end{equation*}\n\n\\noindent The decision boundary is found by solving for the roots of the quadratic:\n\\begin{equation*}\nx_{1,2}=\\frac{-\\mu \\pm \\sqrt{\\mu^2\\sigma^2+2\\sigma^2(\\sigma^2-1)ln\\sigma}}{\\sigma^2-1}\n\\end{equation*}\n\\vfill\n\\clearpage\n% NEW page----------------------------------------------------------------\n\\noindent (b) With $\\mu_1=0$, $\\sigma_1=1$, $\\mu_2=2$ and $\\sigma_2^2=2$, we have the class conditional pdfs:\\\\\n\\begin{equation*}\n\\begin{aligned}\n& p(x|w_1)=\\frac{1}{\\sqrt{2\\pi}} e^{-\\frac{1}{2} x^2} \\\\\n& p(x|w_2)=\\frac{1}{2\\sqrt{\\pi}} e^{-\\frac{1}{4} (x-2)^2} \n\\end{aligned}\n\\end{equation*}\n\n\\noindent And the posterior probabilities:\n\\begin{equation*}\n\\begin{aligned}\n& p(w_1|x)=\\frac{p(x|w_1)P(w_1)}{P(x)}=\\frac{1}{2\\sqrt{2\\pi}P(x)}    \\ e^{-\\frac{1}{2} x^2}\\\\\n& p(w_2|x)=\\frac{p(x|w_2)P(w_2)}{P(x)}=\\frac{1}{4\\sqrt{\\pi}P(x)}    \\ e^{-\\frac{1}{4} (x-2)^2}\\\\\n\\end{aligned}\n\\end{equation*}\nwhere $P(x)$ is given by $P(x)=\\sum^2_{i=1}P(x|w_i)P(w_i)=\\frac{1}{\\sqrt{2\\pi}} e^{-\\frac{1}{2} x^2} + \\frac{1}{2\\sqrt{\\pi}} e^{-\\frac{1}{4} (x-2)^2}$, and $x_1=-5.0637,\\ x_2=1.0637$.\\\\\n\\noindent Using the MATLAB code below we can plot Figure \\ref{fig2}:\n\\begin{lstlisting}\nclear; clc; close all\nx = -10 : 0.0001 : 8;\ny1 = exp (-0.5 * x.^2) / sqrt (2 * pi);\ny2 = exp (-0.25 * (x-2).^2) / (2 * sqrt (pi) );\nk1 = y1./ (y1 + y2);\nk2 = y2./ (y1 + y2);\nmu = 2;\nsigma = sqrt (2);\ndelt = mu^2 + ( sigma^2 - 1 ) * ( mu^2 + 2 * sigma^2 * log (sigma) );\nxopt1 = ( - mu - sqrt ( delt ) ) / ( sigma^2 - 1 );\nxopt2 = ( - mu + sqrt ( delt ) ) / ( sigma^2 - 1 );\nfigure\nsubplot(2, 1, 1)\nhold on\nplot (x, y1, 'r', x, y2, 'k');\nplot([xopt1 xopt1], [-1 2], 'k-.', [xopt2 xopt2], [-1 2], 'k-.')\nhold off\naxis ( [-6 8 -0.05 0.5] );\ntitle ('$Class\\ Conditional\\ PDFs$', 'Interpreter', 'latex')\nxlabel ('$x$', 'Interpreter', 'latex')\nylabel ('$pdf$', 'Interpreter', 'latex')\nh = legend('$P(x|w_1)$', '$P(x|w_2)$', 'Boundary');\nset (h, 'Interpreter', 'latex')\ngrid on\nsubplot(2, 1, 2)\nhold on\nplot (x, k1, 'r', x, k2, 'k')\nplot([xopt1 xopt1], [-1 2], 'k-.', [xopt2 xopt2], [-1 2], 'k-.')\nhold off\naxis( [-10 6 -0.05 1.05] );\ntitle('$Posterior\\ Proabilities\\ with\\ Optimal\\ Decision\\ Regions$', 'Interpreter', 'latex')\nxlabel ('$x$', 'Interpreter', 'latex')\nylabel ('$Posterior\\ Proabilities$', 'Interpreter', 'latex')\nh = legend ('$P(w_1|x)$', '$P(w_2|x)$', 'Boundary');\nset (h, 'Interpreter', 'latex');\ngrid on\n\\end{lstlisting}\n\\vfill\n\\clearpage\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.9\\textwidth]{12b.jpg}\\caption{\\label{fig2}Conditional PDFs and Posterior Probabilities}\n\\end{figure}\n\n\\noindent (c) With the decision regions $C_1:(x_1,x_2]\\ ,\\ C_2:(-\\infty, x_1]\\ \\bigcup\\ [x_2,+\\infty)$, we can calculate the Bayes error rate:\n\\begin{equation*}\n\\begin{aligned}\np_e&=\\int^{+\\infty}_{-\\infty}p(err|x)p(x)\\text{ d}x\\\\\n&=\\int_{C_2}p(w_1|x)p(x)\\text{ d}x+\\int_{C_1}p(w_2|x)p(x)\\text{ d}x\\\\\n&=\\int_{C_2}p(x|w_1)P(w_1)\\text{ d}x+\\int_{C_1}p(x|w_2)P(w_2)\\text{ d}x\\\\\n&=\\frac{1}{2} \\int^{x_1}_{-\\infty} \\frac{1}{\\sqrt{2\\pi}} e^{-\\frac{1}{2} x^2} \\text{ d}x + \\frac{1}{2} \\int^{+\\infty}_{x_2} \\frac{1}{\\sqrt{2\\pi}} e^{-\\frac{1}{2} x^2} \\text{ d}x +   \\frac{1}{2} \\int^{x_2}_{x_1}\\frac{1}{2\\sqrt{\\pi}} e^{-\\frac{1}{4} (x-2)^2} \\text{ d}x\\\\\n&=\\frac{1}{2} (\\ Q(-x_1)+Q(x_2)+Q(\\frac{x_1-2}{\\sqrt{2}})-Q(\\frac{x_2-2}{\\sqrt{2}})\\ )\n\\end{aligned}\n\\end{equation*}\nwhere $Q(x)=\\int^{+\\infty}_x \\frac{1}{\\sqrt{2\\pi}} e^{ -\\frac{1}{2} x^2} \\text{ d}x,\\ x_1\\approx-5.0637,\\ x_2\\approx1.0637$.\\\\\n\\\\With MATLAB the $p_e$ can be calculated:\n\\begin{lstlisting}\nclear;clc\nmu = 2;\nsigma = sqrt (2);\ndelta = mu^2 + ( sigma^2 - 1 ) * ( mu^2 + 2 * sigma^2 * log (sigma) );\nx1 = ( - mu - sqrt ( delta ) ) / ( sigma^2 - 1 );\nx2 = ( - mu + sqrt ( delta ) ) / ( sigma^2 - 1 );\npe = ( qfunc (-x1) + qfunc (x2) + qfunc ( (x1 - 2) / sigma ) -...\n    qfunc ( ( x2 - 2 ) / sigma ) ) /2\n\\end{lstlisting}\nand we have $p_e\\approx 0.1988$.\\\\\n\\\\(d) The likelihood $p(x|w_1)$ is centralized within a small region, while the other one, $p(x|w_2)$, is nearly uniformly distributed on a large region, it occurs to me that the classification of the image of nebula and star could be a sample of this. Another situation is classifying zero mean signals of different variance.\\\\\n\n%%---------------------------------------------------------------\n%% Problem 3\n%%---------------------------------------------------------------\n\\section{Problem 3}\nThe function can be realized with the following code (2-CLASS, 2-DMENSIONAL) \\footnote{Actually, in order to use the same dataset generated by the function in Problem 3 and 4, all six figures in this section are sketched in Problem 4.}:\n\\begin{lstlisting}\nfunction [data, classIndex] = generateGaussianSamples(mu, sigma, nSamples, prior);\n%\n% Function to simulate data from k Gaussian densities \n% (1 for each class) in d dimensions.\n%\n% INPUTS:\n% mu - k-by-1 cell with the class dependent d-dimensional mean vector\n% sigma - k-by-1 cell with the class dependent d-dimensional conv matrix\n% nSamples - scalar indicaitng number of samples to be generated\n% prior - k-by-1 vector with class dependent mean\n%\n% OUTPUTS:\n% data - nSamples-by-d array with the simulated data distributed along the rows\n% classIndex - vector of length nSamples with the class index for each datapoint\n\n% Generating datas and outputs.\nnuclas1 = binornd(nSamples, prior(1));\ndata1 = mvnrnd ( mu{1}, sigma{1}, nuclas1);\ndata2 = mvnrnd ( mu{2}, sigma{2}, nSamples - nuclas1 );\nsample = [data1, ones(nuclas1, 1); data2, 2 * ones(nSamples - nuclas1, 1)];\ndata = sample(:, 1:2);\nclassIndex = sample(:, 3);\n% Plots.\nfigure\nhold on\nplot(data1(:,1), data1(:,2), 'r.')\nplot(data2(:,1), data2(:,2), 'k.')\nxlabel('$x_1$', 'Interpreter', 'latex')\nylabel('$x_2$', 'Interpreter', 'latex')\nhold off\ntitle('$I.I.D\\ Gaussian\\ Samples\\ of\\ Two-classes.$', 'Interpreter', 'latex')\nh=legend('$Class\\ 1$', '$Class\\ 2$');\nset(h, 'Interpreter', 'latex');\ngrid on\nend\n\\end{lstlisting}\n\n\\noindent To simulate the datasets, we first sample the respective class indexes with binomial distribution, $b(nSamples,\\ 0.5)$. Then with the class dependent parameters we can sample the gaussian dataset using function $mvnrnd()$. MATLAB code to generate and plot are attached at the end.\\\\\n\n\\noindent (a) The given parameters are:\n\\begin{lstlisting}\nmu = {[0,0];[-3,-3]}; sigma = {eye(2) ; eye(2)};\nnSamples = 400; prior = [0.5, 0.5];\n\\end{lstlisting}\n\n\\noindent (b) The given parameters are:\n\\begin{lstlisting}\nmu = {[0,0];[-3,-3]}; sigma = {[3 1; 1 0.8] ; [3 1; 1 0.8]};\nnSamples = 400; prior = [0.5, 0.5];\n\\end{lstlisting}\n\n\n\\noindent (c) The given parameters are:\n\\begin{lstlisting}\nmu = {[0,0];[-3,-3]}; sigma = {[2 0.5; 0.5 1] ; [2 -1.9; -1.9 5]};\nnSamples = 400; prior = [0.5, 0.5];\n\\end{lstlisting}\n\n\\noindent (d) The given parameters are:\n\\begin{lstlisting}\nmu = {[0,0];[-3,-3]}; sigma = {[3 1; 1 0.8] ; [3 1; 1 0.8]};\nnSamples = 400; prior = [0.05, 0.95];\n\\end{lstlisting}\n\n\n\\noindent (e) The given parameters are:\n\\begin{lstlisting}\nmu = {[0,0];[-3,-3]}; sigma = {[3 1; 1 0.8] ; [3 1; 1 0.8]};\nnSamples = 400; prior = [0.05, 0.95];\n\\end{lstlisting}\n\n\\noindent (f) The given parameters are:\n\\begin{lstlisting}\nmu = {[0,0];[-3,-3]}; sigma = {[2 0.5; 0.5 1] ; [2 -1.9; -1.9 5]};\nnSamples = 400; prior = [0.05, 0.95];\n\\end{lstlisting}\n\n\n\n\n\n\n\\begin{figure}\n\\centering\n\\subfigure[]{\\includegraphics[width=0.45\\textwidth]{13a.jpg}}\n%\\mbox{\\hspace{0.5cm}}\n\\subfigure[]{\\includegraphics[width=0.45\\textwidth]{13b.jpg}}\n\\\\\n\\subfigure[]{\\includegraphics[width=0.45\\textwidth]{13c.jpg}}\n%\\mbox{\\hspace{0.5cm}}\n\\subfigure[]{\\includegraphics[width=0.45\\textwidth]{13d.jpg}}\n\\\\\n\\subfigure[]{\\includegraphics[width=0.45\\textwidth]{13e.jpg}}\n%\\mbox{\\hspace{0.5cm}}\n\\subfigure[]{\\includegraphics[width=0.45\\textwidth]{13f.jpg}}\n\\caption{\\label{fig3}Dataset generated in Problem 1.3}\n\\end{figure}\n\n\n\n\\vfill\n\\clearpage\n\n\n\n%%---------------------------------------------------------------\n%% Problem 4\n%%---------------------------------------------------------------\n\\section{Problem 4}\n\\textbf{CASE 1} : $\\bm{\\Sigma}_i=\\sigma^2\\bm{\\text{I}}$\\\\\nThe discriminant function is given by  $g_i(\\textbf{x})=\\textbf{w}_i^T\\textbf{x}+w_{i0}$, where \n\\begin{equation*}\n\\textbf{w}_i=\\frac{1}{\\sigma^2} \\bm{\\mu}_i,\\ \\ \nw_{i0}=-\\frac{1}{2\\sigma^2} \\bm{\\mu}_i^T \\bm{\\mu}_i+\\text{ln } P(w_i)\n\\end{equation*}\nAnd the boundary is $\\textbf{w}^T(\\textbf{x}-\\textbf{x}_0)=0$, where \n\\begin{equation*}\n\\textbf{w}=\\bm{\\mu}_i-\\bm{\\mu}_j,\\ \\ \\bm{x}_0=\\frac{1}{2}(\\bm{\\mu}_i+\\bm{\\mu}_j)-\\frac{\\sigma^2}{||\\bm{\\mu}_i-\\bm{\\mu}_j||_2^2}\\text{ln }\\frac{P(w_i)}{P(w_j)}(\\bm{\\mu}_i-\\bm{\\mu}_j)\n\\end{equation*}\n\\\\\n\\noindent \\textbf{CASE 2} : $\\bm{\\Sigma}_i=\\bm{\\Sigma}$\\\\\nThe discriminant function is then  $g_i(\\textbf{x})=\\textbf{w}_i^T\\textbf{x}+w_{i0}$, where \n\\begin{equation*}\n\\textbf{w}_i=\\bm{\\Sigma}^{-1}\\bm{\\mu}_i,\\ \\ \nw_{i0}=-\\frac{1}{2}  \\bm{\\mu}_i^T \\bm{\\Sigma}^{-1} \\bm{\\mu}_i+\\text{ln }P(w_i).\n\\end{equation*}\nAnd the boundary is $\\textbf{w}^T(\\textbf{x}-\\textbf{x}_0)=0$, where \n\\begin{equation*}\n\\textbf{w}=\\bm{\\Sigma}^{-1}(\\bm{\\mu}_i-\\bm{\\mu}_j),\\ \\ \\bm{x}_0=\\frac{1}{2}(\\bm{\\mu}_i+\\bm{\\mu}_j)-\\frac{\\text{ln }P(w_i)/P(w_j)}{(\\bm{\\mu}_i-\\bm{\\mu}_j)^T\\bm{\\Sigma}^{-1}(\\bm{\\mu}_i-\\bm{\\mu}_j)}(\\bm{\\mu}_i-\\bm{\\mu}_j).\n\\end{equation*}\n\\\\\n\\noindent \\textbf{CASE 3} : $\\bm{\\Sigma}_i=$ \\textbf{arbitrary}\\\\\nThe linear discriminant function is given by  $g_i(\\textbf{x})=\\textbf{x}^T\\bm{W}_i\\textbf{x}+\\textbf{w}_i^T\\textbf{x}+w_{i0}$, where \n\\begin{equation*}\n\\bm{W}_i=-\\frac{1}{2}\\bm{\\Sigma}_i^{-1},\\ \\ \n\\textbf{w}_i=\\bm{\\Sigma}_i^{-1}\\bm{\\mu}_i,\\ \\ \nw_{i0}=-\\frac{1}{2}  \\bm{\\mu}_i^T \\bm{\\Sigma}_i^{-1} \\bm{\\mu}_i -\\frac{1}{2}\\text{ln } |\\bm{\\Sigma}_i|+\\text{ln }P(w_i)\n\\end{equation*}\n\n\nThe function can be coded as follows:\n\\begin{lstlisting}\nfunction g = discric(x, mu, sigma, nSamples, prior, cas)\ng = zeros(nSamples ,2);\nif cas == 1\n    for ii = 1 : 2\n        w = mu{ii} / det(sigma);\n        w0 = - mu{ii} * mu{ii}' / (2 * det(sigma)) + log (prior(ii));\n        g(:, ii) = (w * x' + w0)';\n    end\nelseif cas == 2\n    for ii = 1 : 2\n        w = sigma \\mu{ii}';\n        w0 = - mu{ii}* (sigma\\ mu{ii}') /2 + log ( prior(ii) );\n        g(:, ii) = (w' * x' + w0)';\n    end\nelseif cas == 3\n    for ii = 1 : 2\n        w2 = sigma{ii} \\mu{ii}';\n        w0 = - mu{ii}* (sigma{ii}\\ mu{ii}') /2 - log( det (sigma{ii}) )/2 + log ( prior(ii) );\n        for jj= 1 : nSamples\n            w1 = - inv (sigma{ii})/2;\n            g(jj , ii) = (x(jj,:) * w1 * x(jj, :)' + x(jj, :) * w2 + w0);\n        end\n    end\nend\nend\n\\end{lstlisting}\n\n\\noindent (a) Using MATLAB code 1.4(a) we have\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{14a.jpg}\n\\caption{\\label{14a}Classification Result for 1.3(a)}\n\\end{figure}\n\n\\text{ }\\\\\n\\\\\n\\noindent(b) Using MATLAB code 1.4(b) we have\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{14b.jpg}\n\\caption{\\label{14b}Classification Result for 1.3(b)}\n\\end{figure}\n\n\\noindent As we can see from the two figures, the decision boundaries are different, and with the second boundary there is a higher accuracy. I also repeated the classification for several times and the accuracy of case II is always higher than that of case I. This is because when we apply the classifier of case I onto the datasets of case II, we utilize primarily differences in means for classification while the differences in their variance be discarded.\\\\\n\n\\vfill\n\\clearpage\n\n(c) Using MATLAB code 1.4(c) we have\n\\begin{figure}[H]\n\\centering\n\\subfigure[Case 1 \\& 2 Classifier]{\n\\begin{minipage}{1\\textwidth}\n\\centering\n\\includegraphics[width=0.9\\textwidth]{14c1.jpg}\\\\\n%\\hspace{2cm}\n\\end{minipage}%\n}%\n%\n\n\\subfigure[Case 3 Classifier]{\n\\begin{minipage}{1\\textwidth}\n\\centering\n\\includegraphics[width=0.9\\textwidth]{14c2.jpg}\\\\\n%\\hspace{2cm}\n\\end{minipage}\n}\n\\caption{Classification Result for 1.3(c)}\n\\end{figure}\n\\noindent From the result figure we can see that the decision boundary is a straight line only when two classes share the same covariance matrix. Generally speaking, classifier of case 3 performs better because when we apply case 1 or case 2 on dataset generated with case 3, some information are discarded. Simply averaging the individual class covariances makes sense only when two priors are equal, and computing a weighted average of covariances will be better.\n\n\n\n\n\\vfill\n\\clearpage\n\n\n\\noindent(d) Using MATLAB code 1.4(d) we have\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{14d.jpg}\n\\caption{\\label{14d}Classification Result for 1.3(d)}\n\\end{figure}\n\n\n\\noindent(e) Using MATLAB code 1.4(e) we have\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{14e.jpg}\n\\caption{\\label{14e}Classification Result for 1.3(e)}\n\\end{figure}\n\n\n\n\\vfill\n\\clearpage\n\n\n\\noindent(f) Using MATLAB code 1.4(f) we have\n\\begin{figure}[H]\n\\centering\n\\subfigure[Case 1 \\& 2 Classifier]{\n\\begin{minipage}{1\\textwidth}\n\\centering\n\\includegraphics[width=1\\textwidth]{14f1.jpg}\\\\\n%\\hspace{2cm}\n\\end{minipage}%\n}%\n%\n\n\\subfigure[Case 3 Classifier]{\n\\begin{minipage}{1\\textwidth}\n\\centering\n\\includegraphics[width=0.9\\textwidth]{14f2.jpg}\\\\\n%\\hspace{2cm}\n\\end{minipage}\n}\n\\caption{Classification Result for 1.3(f)}\n\\end{figure}\n\n\\noindent Classifying all data points as the class with the highest prior can lead to high accuracy in some extreme cases, such as $P(w_1)=0.05,\\ P(w_2)=0.95$ in homework. In general, accuracy can be a poor metric depending on the case. Important information, such as covariance, cost, etc, should also be taken into account when classifying.\n\n\\vfill\n\\clearpage\n\n\\section{MATLAB Code for Problem 1.3 and 1.4}\n\n(a) MATLAB code for 1.3 \\& 1.4 (a)\n\\begin{lstlisting}\nclear; clc; close all\nmu = {[0,0];[-3 -3]};\nsigma = {eye(2),eye(2)};\nnSamples = 400;\nprior = [0.5, 0.5];\n[data, classIndex] = generateGaussianSamples(mu, sigma, nSamples, prior);\n% Case 1 classifier\ng = discric(data, mu, sigma{1}, nSamples, prior, 1);\nclas = 2 * ones(400,1);\nclas(g(:,1) >= g(:,2))=1;\naccu = 1 - sum(abs(clas-classIndex))/ nSamples;\nclsdata = sortrows([data, clas] , 3);\nq = 400 - sum(clsdata(:,3)-1);\nfigure\nhold on\nplot( clsdata(1:q, 1), clsdata(1:q, 2), 'g.')\nplot( clsdata(q + 1:400, 1), clsdata(q + 1:400, 2), 'b.')\ndb = ezplot(@(x, y) diff(score([x;y], mu, sigma, prior)), [-15 10 -14 16]);\nset(db, 'color', 'm','LineStyle','--');\nhold off\nxlabel('$x_1$', 'Interpreter', 'latex')\nylabel('$x_2$', 'Interpreter', 'latex')\ntitle(['$Classification\\ Result\\ with\\ Accuracy=$',num2str(accu)], 'Interpreter', 'latex')\naxis([-7 3 -7 3])\nh = legend('$Class\\ 1$', '$Class\\ 2$','Decision\\ Boundary');\nset(h, 'Interpreter', 'latex');\ngrid on\n\\end{lstlisting}\n\n\\noindent (b) MATLAB code for 1.3 \\& 1.4 (b)\n\\begin{lstlisting}\nclear; clc; close all\nmu = {[0,0];[-3 -3]};\nsigma = {[3 1; 1 0.8], [3 1; 1 0.8]};\nnSamples = 400;\nprior = [0.05, 0.95];\n[data, classIndex] = generateGaussianSamples(mu, sigma, nSamples, prior);\n% Case 1 classifier\ng1 = discric(data, mu, eye(2), nSamples, prior, 1);\nclas1 = 2 * ones(400,1);\nclas1(g1(:,1)>g1(:,2)) = 1;\naccu1 = 1 - sum(abs(clas1-classIndex))/ nSamples;\nclsdata = sortrows([data, clas1] , 3);\nq = 400 - sum(clsdata(:,3)-1);\nfigure \nsubplot(1, 2, 1)\nhold on\nplot( clsdata(1:q, 1), clsdata(1:q, 2), 'g.')\nplot( clsdata(q + 1:400, 1), clsdata(q + 1:400, 2), 'b.')\ndb = ezplot(@(x, y) diff(score([x;y], mu, eye(2), prior)), [-15 10 -14 10]);\nset(db, 'color', 'm','LineStyle','--');\nhold off\nxlabel('$x_1$', 'Interpreter', 'latex')\nylabel('$x_2$', 'Interpreter', 'latex')\ntitle(['$Classification\\ Result\\ of\\ Case\\ I\\ \\ Accuracy=$',num2str(accu1)], 'Interpreter', 'latex')\naxis([-10 6 -6 3])\nh = legend('$Class\\ 1$', '$Class\\ 2$','Decision\\ Boundary');\nset(h, 'Interpreter', 'latex');\ngrid on\n% Case 2 classifier\ng2 = discric(data, mu, sigma{1}, nSamples, prior, 2);\nclas2 = 2 * ones(400,1);\nclas2(g2(:,1)>g2(:,2))=1;\naccu2 = 1 - sum(abs(clas2-classIndex))/ nSamples;\nclsdata = sortrows([data, clas2] , 3);\nq = 400 - sum(clsdata(:,3)-1);\nsubplot(1, 2, 2)\nhold on\nplot( clsdata(1:q, 1), clsdata(1:q, 2), 'g.')\nplot( clsdata(q + 1:400, 1), clsdata(q + 1:400, 2), 'b.')\ndba = ezplot(@(x, y) diff(score([x;y], mu, sigma, prior)), [-15 10 -14 10]);\nset(dba, 'color', 'm','LineStyle','--');\nhold off\nxlabel('$x_1$', 'Interpreter', 'latex')\nylabel('$x_2$', 'Interpreter', 'latex')\ntitle(['$Classification\\ Result\\ of\\ Case\\ II\\ \\ Accuracy=$',num2str(accu2)], 'Interpreter', 'latex')\naxis([-10 6 -6 3])\nh = legend('$Class\\ 1$', '$Class\\ 2$','Decision\\ Boundary');\nset(h, 'Interpreter', 'latex');\ngrid on\n\\end{lstlisting}\n\n\n\\noindent(c) MATLAB code for 1.3 \\& 1.4 (c)\n\\begin{lstlisting}\nclear;clc;close all\nmu = {[0,0];[2 2]};\nsigma = {[2 0.5; 0.5 1], [2 -1.9; -1.9 5]};\nnSamples = 400;\nprior = [0.05, 0.95];\n[data, classIndex] = generateGaussianSamples(mu, sigma, nSamples, prior);\n% Case 1 classifier\ng1 = discric(data, mu, eye(2), nSamples, prior, 1);\nclas1 = 2 * ones(400,1);\nclas1(g1(:,1)>g1(:,2))=1;\naccu1 = 1 - sum(abs(clas1 - classIndex))/ nSamples;\nclsdata = sortrows([data, clas1] , 3);\nq = 400 - sum(clsdata(:,3)-1);\nfigure\nsubplot(1, 2, 1)\nhold on\nplot( clsdata(1:q, 1), clsdata(1:q, 2), 'g.')\nplot( clsdata(q + 1:400, 1), clsdata(q + 1:400, 2), 'b.')\ndba = ezplot(@(x, y) diff(score([x;y], mu, eye(2), prior)), [-15 10 -14 10]);\nset(dba, 'color', 'm','LineStyle','--');\naxis([-5 8 -6 10])\nhold off\nxlabel('$x_1$', 'Interpreter', 'latex')\nylabel('$x_2$', 'Interpreter', 'latex')\ntitle(['$Classification\\ Result\\ of\\ Case\\ I\\ \\ Accuracy=$',num2str(accu1)], 'Interpreter', 'latex')\nh = legend('$Class\\ 1$','$Class\\ 2$','Decision\\ Boundary');\nset(h, 'Interpreter', 'latex');\ngrid on\n% Case 2 classifier\ng2 = discric(data, mu, (sigma{1}+sigma{2})/2, nSamples, prior, 2);\nclas2 = 2 * ones(400,1);\nclas2(g2(:,1)>g2(:,2))=1;\naccu2 = 1 - sum(abs(clas2 - classIndex))/ nSamples;\nclsdata = sortrows([data, clas2] , 3);\nq = 400 - sum(clsdata(:,3)-1);\nsubplot(1, 2, 2)\nhold on\nplot( clsdata(1:q, 1), clsdata(1:q, 2), 'g.')\nplot( clsdata(q + 1:400, 1), clsdata(q + 1:400, 2), 'b.')\ndbb = ezplot(@(x, y) diff(score([x;y], mu, (sigma{1} + sigma{2})/2, prior)), [-15 10 -14 10]);\nset(dbb, 'color', 'm','LineStyle','--');\naxis([-5 8 -6 10])\nhold off\nxlabel('$x_1$', 'Interpreter', 'latex')\nylabel('$x_2$', 'Interpreter', 'latex')\ntitle(['$Classification\\ Result\\ of\\ Case\\ II\\ \\ Accuracy=$',num2str(accu2)], 'Interpreter', 'latex')\nh = legend('$Class\\ 1$', '$Class\\ 2$','Decision\\ Boundary');\nset(h, 'Interpreter', 'latex');\ngrid on\n% Case 3 classifier\ng3 = discric(data, mu, sigma, nSamples, prior, 3);\nclas3 = 2 * ones(400,1);\nclas3(g3(:,1)>g3(:,2))=1;\naccu3 = 1 - sum(abs(clas3 - classIndex))/ nSamples;\nclsdata = sortrows([data, clas3] , 3);\nq = 400 - sum(clsdata(:,3)-1);\nfigure\nhold on\nplot( clsdata(1:q, 1), clsdata(1:q, 2), 'g.')\nplot( clsdata(q + 1:400, 1), clsdata(q + 1:400, 2), 'b.')\ndb = ezplot(@(x, y) diff(score([x;y], mu ,sigma, prior)), [-15 10 -14 10]);\nset(db, 'color', 'm','LineStyle','--');\naxis([-5 8 -6 10])\nhold off\nxlabel('$x_1$', 'Interpreter', 'latex')\nylabel('$x_2$', 'Interpreter', 'latex')\ntitle(['$Classification\\ Result\\ with\\ Accuracy=$',num2str(accu3)], 'Interpreter', 'latex')\nh = legend('$Class\\ 1$', '$Class\\ 2$','Decision\\ Boundary');\nset(h, 'Interpreter', 'latex');\ngrid on\n\\end{lstlisting}\n\n\\text{ }\\\\\n\n\\noindent The MATLAB code for (d) (e) and (f) can be obtained by changing priors in (a) (b) and (c) from $[0.5\\ 0.5]$ to $[0.05\\ 0.95]$.\n\n\n\n\\end{document}\n\n\n\n\\noindent MATLAB code 1.4(a)\n\\begin{lstlisting}\nclear;clc;close all\n\nmu = {[0,0];[-3 -3]};\nsigma = {eye(2),eye(2)};\nnSamples = 400;\nprior = [0.5, 0.5];\n[data, classIndex] = generateGaussianSamples(mu, sigma, nSamples, prior);\ng = discric1(data, mu, sigma, nSamples, prior);\n\n% Compute the accuracy.\nclas = 2 * ones(400,1);\nclas(g(:,1)>g(:,2))=1;\naccu = 1 - sum(abs(clas-classIndex))/ nSamples;\nww = mu{1} - mu{2};\nx0 = (mu{1} + mu{2})/2;\n\n% Plotting\nfigure\nhold on\nx = -8 : 0.001 : 6;\ny = ( -ww(1)*x + ww * x0')/ww(2);\nclsdata = sortrows([data, clas] , 3);\nq = 400 - sum(clsdata(:,3)-1);\nplot( clsdata(1:q, 1), clsdata(1:q, 2), 'g.')\nplot( clsdata(q + 1:400, 1), clsdata(q + 1:400, 2), 'b.')\nplot(x, y, 'm--')\nhold off\nxlabel('$x_1$', 'Interpreter', 'latex')\nylabel('$x_2$', 'Interpreter', 'latex')\ntitle(['$Classification\\ Result\\ with\\ Accuracy=$',num2str(accu)], 'Interpreter', 'latex')\naxis([-10 6 -6 3])\nh = legend('$Class\\ 1$', '$Class\\ 2$','Decision\\ Boundary');\nset(h, 'Interpreter', 'latex');\ngrid on\n\\end{lstlisting}\n\n\\noindent MATLAB code 1.4(b)\n\\begin{lstlisting}\nclear;clc;close all\n\nmu = {[0,0];[-3 -3]};\nsigma = {[3 1; 1 0.8], [3 1; 1 0.8]};\nnSamples = 400;\nprior = [0.5, 0.5];\n[data, classIndex] = generateGaussianSamples(mu, sigma, nSamples, prior);\n\ng1 = discric1(data, mu, sigma, nSamples, prior);\nclas1 = 2 * ones(400,1);\nclas1(g1(:,1)>g1(:,2))=1;\naccu1 = 1 - sum(abs(clas1-classIndex))/ nSamples;\nww1 = mu{1} - mu{2};\nx10 = (mu{1} + mu{2})/2;\nfigure\nhold on\nx = -8 : 0.001 : 6;\ny = ( -ww1(1)*x + ww1 * x10')/ww1(2);\nclsdata = sortrows([data, clas1] , 3);\nq = 400 - sum(clsdata(:,3)-1);\nplot( clsdata(1:q, 1), clsdata(1:q, 2), 'g.')\nplot( clsdata(q + 1:400, 1), clsdata(q + 1:400, 2), 'b.')\nplot(x, y, 'm--')\nhold off\nxlabel('$x_1$', 'Interpreter', 'latex')\nylabel('$x_2$', 'Interpreter', 'latex')\ntitle(['$Classification\\ Result\\ with\\ Accuracy=$',num2str(accu1)], 'Interpreter', 'latex')\naxis([-10 6 -6 3])\nh = legend('$Class\\ 1$', '$Class\\ 2$','Decision\\ Boundary');\nset(h, 'Interpreter', 'latex');\ngrid on\n\ng2 = discric2(data, mu, sigma, nSamples, prior);\nclas2 = 2 * ones(400,1);\nclas2(g2(:,1)>g2(:,2))=1;\naccu2 = 1 - sum(abs(clas2-classIndex))/ nSamples;\nww2 = sigma{1}\\(mu{1} - mu{2})';\nx20 = (mu{1} + mu{2})/2;\nfigure\nhold on\nx = -8 : 0.001 : 6;\ny = ( -ww2(1)*x + x20 * ww2)/ww2(2);\nclsdata = sortrows([data, clas2] , 3);\nq = 400 - sum(clsdata(:,3)-1);\nplot( clsdata(1:q, 1), clsdata(1:q, 2), 'g.')\nplot( clsdata(q + 1:400, 1), clsdata(q + 1:400, 2), 'b.')\nplot(x, y, 'm--')\nhold off\nxlabel('$x_1$', 'Interpreter', 'latex')\nylabel('$x_2$', 'Interpreter', 'latex')\ntitle(['$Classification\\ Result\\ with\\ Accuracy=$',num2str(accu2)], 'Interpreter', 'latex')\naxis([-10 6 -6 3])\nh = legend('$Class\\ 1$', '$Class\\ 2$','Decision\\ Boundary');\nset(h, 'Interpreter', 'latex');\ngrid on\n\\end{lstlisting}\n\n\n", "meta": {"hexsha": "540bc102325700005546601315db209a318f2f65", "size": 25361, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "EECE5644-Introduction-to-Machine-Learning-and-Pattern-Recognition/Homework-1/Report/main.tex", "max_stars_repo_name": "tjyiiuan/Graduate-Courses", "max_stars_repo_head_hexsha": "7f8b018dc92431d8f054a38e1a7fd2c284e1cce0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "EECE5644-Introduction-to-Machine-Learning-and-Pattern-Recognition/Homework-1/Report/main.tex", "max_issues_repo_name": "tjyiiuan/Graduate-Courses", "max_issues_repo_head_hexsha": "7f8b018dc92431d8f054a38e1a7fd2c284e1cce0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "EECE5644-Introduction-to-Machine-Learning-and-Pattern-Recognition/Homework-1/Report/main.tex", "max_forks_repo_name": "tjyiiuan/Graduate-Courses", "max_forks_repo_head_hexsha": "7f8b018dc92431d8f054a38e1a7fd2c284e1cce0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.2716216216, "max_line_length": 465, "alphanum_fraction": 0.6112534995, "num_tokens": 9826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7083018726110879}}
{"text": "\\subsection{AdaIN}\nAnother quite known method of style transfer is AdaIN, short for Adaptive Instance Normalization. It was implemented in the paper by Huang \\textit{et al.} \\cite{Huang:1}. AdaIN is an extension of Instance Normalization, which we have described more in detail in Section \\ref{sec:instance_normalization}. With AdaIN you need two normalized inputs: $x$, the image input and $y$, the style input. Then the method simply aligns the channel-wise variance and mean of $x$ to match $y$. The formula is as following: \n\\begin{equation}\n\\begin{aligned}\n\\label{eq:batch_normalization}\n    AdaIN(x,y)&=\\sigma(y) \\frac{x-\\mu(x)}{\\sigma(x)}+\\mu(y),\n\\end{aligned}\n\\end{equation}\nwhere $\\sigma(y)$ is used to scale the content input and $\\mu(y)$ is used to shift it. The purpose of the AdaIN layer is to perform style transfer by using the mean and variance of the features. Because AdaIN is just a simple layer on top of an IN, it requires almost no extra computation. This makes AdaIN style transfer very fast compared to other tradional methods such as Gatys. This is the reason it is used for real-time style transfer in the paper of Huang \\textit{et al.} mentioned above. ", "meta": {"hexsha": "33f4d02f568826173266d60e673550a16335e986", "size": 1180, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/Background/adain.tex", "max_stars_repo_name": "dilawarm/video-style-transfer", "max_stars_repo_head_hexsha": "c0473b5ab24dcbad0255b64a2811be79af91269b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-11-23T18:08:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-05T21:02:19.000Z", "max_issues_repo_path": "report/Background/adain.tex", "max_issues_repo_name": "multitalentloes/video-style-transfer", "max_issues_repo_head_hexsha": "50d611e2a78ca93ea3b821240d778f1cae231f6a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/Background/adain.tex", "max_forks_repo_name": "multitalentloes/video-style-transfer", "max_forks_repo_head_hexsha": "50d611e2a78ca93ea3b821240d778f1cae231f6a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-11-24T15:13:48.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-26T21:36:09.000Z", "avg_line_length": 131.1111111111, "max_line_length": 509, "alphanum_fraction": 0.7652542373, "num_tokens": 297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.7082958139707249}}
{"text": "\\hypertarget{bootstrap-sampling}{%\n\\chapter{Bootstrap Sampling}\\label{bootstrap-sampling}}\n\nIn the previous chapter we used resampling to compute standard errors\nand confidence intervals, which quantify the variability in an estimate\ndue to random sampling. As one of the examples, we used data from the\nGeneral Social Survey (GSS) to explore changes in support for gun\ncontrol over time and to compute confidence intervals for the estimated\nproportions.\n\nIn this chapter, we'll use GSS data to estimate average income and the\n10th percentile of income. We'll see that the resampling method we used\nin the previous chapter works for the average income but not for the\n10th percentile.\n\nTo solve this problem, we'll use another kind of resampling, called\nbootstrapping or bootstrap sampling (see\n\\url{https://en.wikipedia.org/wiki/Bootstrapping_(statistics)}). Then\nwe'll use bootstrapping to compute sampling distributions and confidence\nintervals for other statistics, including the coefficient of correlation\nand the parameters of linear regression. Finally, I'll point out a\nproblem with bootstrap resampling when there are not enough different\nvalues in a dataset, and a way to solve it with KDE resampling.\n\n\\hypertarget{estimating-average-income}{%\n\\section{Estimating Average Income}\\label{estimating-average-income}}\n\nAs a first example, we'll use data from the General Social Survey to\nestimate average family income. The following cell loads the data, which\nI have stored in an HDF file.\n\n\\begin{lstlisting}[language=Python,style=source]\nimport pandas as pd\n\ngss = pd.read_hdf('gss_eda.hdf', 'gss')\ngss.head()\n\\end{lstlisting}\n\n\\begin{tabular}{lrrrrrrrr}\n\\toprule\n{} &  YEAR &  ID\\_ &   AGE &  EDUC &  SEX &  GUNLAW &  GRASS &  REALINC \\\\\n\\midrule\n0 &  1972 &    1 &  23.0 &  16.0 &    2 &     1.0 &    NaN &  18951.0 \\\\\n1 &  1972 &    2 &  70.0 &  10.0 &    1 &     1.0 &    NaN &  24366.0 \\\\\n2 &  1972 &    3 &  48.0 &  12.0 &    2 &     1.0 &    NaN &  24366.0 \\\\\n3 &  1972 &    4 &  27.0 &  17.0 &    2 &     1.0 &    NaN &  30458.0 \\\\\n4 &  1972 &    5 &  61.0 &  12.0 &    2 &     1.0 &    NaN &  50763.0 \\\\\n\\bottomrule\n\\end{tabular}\n\nThe column \\passthrough{\\lstinline!REALINC!} records family income,\nconverted to 1986 dollars. We can use \\passthrough{\\lstinline!notna!}\nand \\passthrough{\\lstinline!sum!} to count the number of valid\nresponses.\n\n\\begin{lstlisting}[language=Python,style=source]\nn_realinc = gss['REALINC'].notna().sum()\nn_realinc\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n58293\n\\end{lstlisting}\n\nAnd we can compute the mean and standard deviation of the valid\nresponses.\n\n\\begin{lstlisting}[language=Python,style=source]\nmean_realinc = gss['REALINC'].mean()\nstd_income = gss['REALINC'].std()\nprint(mean_realinc, std_income)\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n31742.563372816312 29526.067896235618\n\\end{lstlisting}\n\nThe average family income in this dataset is \\$31,742. But notice that\nthe standard deviation is almost equal to the mean. That's because the\ndistribution of income is long-tailed; many families have incomes below\nthe mean, and there are a few families with incomes much higher than the\nmean. Nevertheless, we can use this function from the previous chapter\nto simulate the sampling process.\n\n\\begin{lstlisting}[language=Python,style=source]\nimport numpy as np\n\ndef simulate_sample_mean(n, mu, sigma):\n    sample = np.random.normal(mu, sigma, size=n)\n    return sample.mean()\n\\end{lstlisting}\n\n\\passthrough{\\lstinline!simulate\\_sample\\_mean!} takes as parameters the\nsample size, \\passthrough{\\lstinline!n!}, and the presumed mean and\nstandard deviation of income. It generates a sample from a normal\ndistribution with the given mean and standard deviation, and returns the\nmean of the sample. If we call it once, we get a random value from the\nsampling distribution of the mean.\n\n\\begin{lstlisting}[language=Python,style=source]\nsimulate_sample_mean(n_realinc, mean_realinc, std_income)\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n31679.30633347414\n\\end{lstlisting}\n\nIf we call it many times, we get a random sample from the sampling\ndistribution.\n\n\\begin{lstlisting}[language=Python,style=source]\nt1 = [simulate_sample_mean(n_realinc, mean_realinc, std_income)\n     for i in range(1000)]\n\\end{lstlisting}\n\nI'll use the following function to summarize the sampling distribution.\n\n\\begin{lstlisting}[language=Python,style=source]\ndef summarize(t, digits=2):\n    table = pd.DataFrame(columns=['Estimate', 'SE', 'CI90'])\n    est = np.mean(t).round(digits)\n    SE = np.std(t).round(digits)\n    CI90 = np.percentile(t, [5, 95]).round(digits)\n    table.loc[''] = est, SE, CI90\n    return table\n\\end{lstlisting}\n\n\\begin{lstlisting}[language=Python,style=source]\nsummary1 = summarize(t1, digits=1)\nsummary1\n\\end{lstlisting}\n\n\\begin{tabular}{lrrl}\n\\toprule\n{} &  Estimate &     SE &                CI90 \\\\\n\\midrule\n{} &   31741.5 &  118.3 &  [31542.9, 31934.5] \\\\\n\\bottomrule\n\\end{tabular}\n\nThe result is a table that shows the mean of the sampling distribution,\nthe standard error, and a 90\\% confidence interval. The mean of the\nsampling distribution is consistent with the mean of the data, which is\n\\$31,743.\n\n\\hypertarget{estimating-percentiles}{%\n\\section{Estimating Percentiles}\\label{estimating-percentiles}}\n\nThe method in the previous section uses a normal distribution to\nsimulate the sampling process. In the previous chapter, when we\nestimated average height, this worked well because human heights are\nwell modeled by a normal distribution. But income is not. We can see\nthat by computing the CDF of a normal distribution with the same mean\nand standard as the income data.\n\n\\begin{lstlisting}[language=Python,style=source]\nfrom scipy.stats import norm\n\nxs = np.linspace(-40000, 150000)\nys = norm(mean_realinc, std_income).cdf(xs)\n\\end{lstlisting}\n\nAnd comparing it to the CDF of the data.\n\n\\begin{lstlisting}[language=Python,style=source]\nfrom empiricaldist import Cdf\n\ncdf_realinc = Cdf.from_seq(gss['REALINC'])\n\\end{lstlisting}\n\n\\begin{lstlisting}[language=Python,style=source]\nimport matplotlib.pyplot as plt\n\nplt.plot(xs, ys, color='0.7', label='normal model')\ncdf_realinc.plot(label='GSS data')\n\nplt.xlabel('Family income (1986 $)')\nplt.ylabel('CDF')\nplt.title('Distribution of income')\nplt.legend();\n\\end{lstlisting}\n\n\\begin{center}\n\\includegraphics[scale=0.75]{12_bootstrap_files/12_bootstrap_29_0.pdf}\n\\end{center}\n\nThe normal distribution is not a good model for the data. As we saw in\nthe previous section, it is good enough to compute the sampling\ndistribution of the mean. But for other statistics, like percentiles, it\nis not good enough. To demonstrate, here's a function that generates a\nsample from a normal distribution and returns the 10th percentile.\n\n\\begin{lstlisting}[language=Python,style=source]\ndef simulate_sample_percentile(n, mu, sigma):\n    sample = np.random.normal(mu, sigma, size=n)\n    return np.percentile(sample, 10)\n\\end{lstlisting}\n\nWe can use it to generate a sample from the sampling distribution of the\n10th percentile.\n\n\\begin{lstlisting}[language=Python,style=source]\nt2 = [simulate_sample_percentile(n_realinc, mean_realinc, std_income)\n      for i in range(1000)]\n\\end{lstlisting}\n\nHere's a summary of the results.\n\n\\begin{lstlisting}[language=Python,style=source]\nsummary2 = summarize(t2)\nsummary2\n\\end{lstlisting}\n\n\\begin{tabular}{lrrl}\n\\toprule\n{} &  Estimate &      SE &                 CI90 \\\\\n\\midrule\n{} &  -6101.04 &  203.16 &  [-6421.5, -5749.55] \\\\\n\\bottomrule\n\\end{tabular}\n\nThe mean of the sampling distribution is negative, which is not\nconsistent with the actual 10th percentile of the data, which is \\$5631.\n\nIn this example, resampling based on a normal model doesn't produce\nsensible results. Fortunately there is a simple alternative that is more\nrobust: bootstrapping.\n\n\\hypertarget{bootstrapping}{%\n\\section{Bootstrapping}\\label{bootstrapping}}\n\nBootstrapping is a kind of resampling, based on the framework we saw in\nthe previous chapter:\n\n\\includegraphics{figs/resampling.png}\n\nThe idea is that we treat the sample as if it were the entire\npopulation, and simulate the sampling process by choosing random rows\nwith replacement. \\passthrough{\\lstinline!DataFrame!} provides a method\ncalled \\passthrough{\\lstinline!sample!} we can use to select a random\nsample of the rows.\n\n\\begin{lstlisting}[language=Python,style=source]\nbootstrapped = gss.sample(n=n_realinc, replace=True)\nbootstrapped.shape\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n(58293, 8)\n\\end{lstlisting}\n\nThe argument \\passthrough{\\lstinline!n=n\\_realinc!} means that the\nbootstrapped sample has the same size as the original.\n\n\\passthrough{\\lstinline!replace=True!} means that sampling is done with\nreplacement; that is, the same row can be chosen more than once. To see\nhow many times each row appears in the bootstrapped sample, we can use\n\\passthrough{\\lstinline!value\\_counts!} and the\n\\passthrough{\\lstinline!\\_ID!} column, which contains a unique\nidentifier for each respondent.\n\n\\begin{lstlisting}[language=Python,style=source]\nrepeats = bootstrapped['ID_'].value_counts()\nrepeats.head()\n\\end{lstlisting}\n\n\\begin{tabular}{lr}\n\\toprule\n{} &  ID\\_ \\\\\n\\midrule\n1464 &   46 \\\\\n832  &   46 \\\\\n1243 &   45 \\\\\n700  &   45 \\\\\n1424 &   45 \\\\\n\\bottomrule\n\\end{tabular}\n\nSince some rows appear many times, other rows don't appear at all. To\nsee how many, we can use \\passthrough{\\lstinline!set!} subtraction to\ncount the values of \\passthrough{\\lstinline!ID\\_!} that appear in the\noriginal dataset but not the bootstrapped sample.\n\n\\begin{lstlisting}[language=Python,style=source]\nunused = set(gss['ID_']) - set(bootstrapped['ID_'])\nlen(unused)\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n536\n\\end{lstlisting}\n\nNow we can use bootstrapping to generate a sampling distribution. For\nexample, the following function takes a\n\\passthrough{\\lstinline!DataFrame!}, generates a bootstrapped sample,\nand returns the average income.\n\n\\begin{lstlisting}[language=Python,style=source]\ndef bootstrap_mean(df, varname):\n    bootstrapped = df.sample(n=len(df), replace=True)\n    return bootstrapped[varname].mean()\n\\end{lstlisting}\n\nIf we run it many times, we get a sample from the sampling distribution\nof the mean.\n\n\\begin{lstlisting}[language=Python,style=source]\nt3 = [bootstrap_mean(gss, 'REALINC')\n      for i in range(1001)]\n\\end{lstlisting}\n\nHere's a summary of the results, compared to the results based on the\nnormal model.\n\n\\begin{lstlisting}[language=Python,style=source]\nsummary3 = summarize(t3)\ntable = pd.concat([summary1, summary3])\ntable.index=['normal model', 'bootstrapping']\ntable\n\\end{lstlisting}\n\n\\begin{tabular}{lrrl}\n\\toprule\n{} &  Estimate &      SE &                  CI90 \\\\\n\\midrule\nnormal model  &  31741.50 &  118.30 &    [31542.9, 31934.5] \\\\\nbootstrapping &  31733.17 &  126.22 &  [31532.82, 31947.12] \\\\\n\\bottomrule\n\\end{tabular}\n\nThe results from bootstrap sampling are consistent with the results\nbased on the normal model. Now let's see what happens when we estimate\nthe 10th percentile.\n\nThe following function generates a bootstrapped sample and returns the\n10th percentile. Instead of \\passthrough{\\lstinline!percentile!} from\nNumpy, it uses \\passthrough{\\lstinline!quantile!} from Pandas, which\ndrops \\passthrough{\\lstinline!NaN!} values. The parameter of\n\\passthrough{\\lstinline!quantile!} is a probability between 0 and 1,\nrather than a percentage between 0 and 100.\n\n\\begin{lstlisting}[language=Python,style=source]\ndef bootstrap_percentile(df):\n    bootstrapped = df.sample(n=len(df), replace=True)\n    return bootstrapped['REALINC'].quantile(0.1)\n\\end{lstlisting}\n\nWe can use it to generate a sample from the sampling distribution of the\n10th percentile.\n\n\\begin{lstlisting}[language=Python,style=source]\nt4 = [bootstrap_percentile(gss)\n      for i in range(1001)]\n\\end{lstlisting}\n\nHere are the results along with the results based on the normal model.\n\n\\begin{lstlisting}[language=Python,style=source]\nsummary4 = summarize(t4)\ntable = pd.concat([summary2, summary4])\ntable.index=['normal model', 'bootstrapping']\ntable\n\\end{lstlisting}\n\n\\begin{tabular}{lrrl}\n\\toprule\n{} &  Estimate &      SE &                 CI90 \\\\\n\\midrule\nnormal model  &  -6101.04 &  203.16 &  [-6421.5, -5749.55] \\\\\nbootstrapping &   5646.98 &   86.05 &     [5512.5, 5806.0] \\\\\n\\bottomrule\n\\end{tabular}\n\nThe mean of the sampling distribution is consistent with the 10th\npercentile of the data, which is \\$5631. So the results from\nbootstrapping are more sensible than the results based on the normal\nmodel.\n\nIn general, bootstrapping is robust; that is, it works well with many\ndifferent distributions and many different statistics. However, at the\nend of the chapter, we'll see one example where it fails.\n\n\\hypertarget{bigger-data}{%\n\\section{Bigger Data}\\label{bigger-data}}\n\nAs sample size increases, errors due to random sampling get smaller. To\ndemonstrate this effect, I'll use data from the Behavioral Risk Factor\nSurveillance System (BRFSS).\n\nIn previous chapters, we used BRFSS data to explore the relationship\nbetween height and weight, and the relationship between income and\nvegetable consumption. In this section, we'll use it to estimate the\naverage height for men in the United States.\n\nFirst, let's read the 2019 data, which I have stored in an HDF file.\n\n\\begin{lstlisting}[language=Python,style=source]\nimport pandas as pd\n\nbrfss = pd.read_hdf('brfss.hdf', 'brfss')\nbrfss.shape\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n(418268, 9)\n\\end{lstlisting}\n\nThis dataset contains 418 268 rows, one for each respondent, and 11\ncolumns, one for each variable I selected. Here are the first few rows.\n\n\\begin{lstlisting}[language=Python,style=source]\nbrfss.head()\n\\end{lstlisting}\n\n\\begin{tabular}{lrrrrrrrrr}\n\\toprule\n{} &       SEQNO &   HTM4 &  WTKG3 &  \\_SEX &  \\_AGEG5YR &  \\_VEGESU1 &  \\_INCOMG &      \\_LLCPWT &   AGE \\\\\n\\midrule\n0 &  2019000001 &  157.0 &  69.85 &     2 &      13.0 &     114.0 &        2 &   135.304080 &  82.0 \\\\\n1 &  2019000002 &  163.0 &  48.99 &     2 &      11.0 &     121.0 &        3 &  1454.882220 &  72.0 \\\\\n2 &  2019000003 &  165.0 &  86.18 &     2 &      10.0 &     164.0 &        5 &   215.576852 &  67.0 \\\\\n3 &  2019000004 &  165.0 &  55.34 &     2 &      13.0 &       NaN &        4 &   261.282838 &  82.0 \\\\\n4 &  2019000005 &  152.0 &  49.90 &     2 &      13.0 &     178.0 &        9 &   535.270103 &  82.0 \\\\\n\\bottomrule\n\\end{tabular}\n\nHere's a Boolean \\passthrough{\\lstinline!Series!} that's\n\\passthrough{\\lstinline!True!} for male respondents.\n\n\\begin{lstlisting}[language=Python,style=source]\nmale = (brfss['_SEX'] == 1)\nmale.sum()\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n189835\n\\end{lstlisting}\n\nThe column \\passthrough{\\lstinline!HTM4!} contains their heights in\ncentimeters.\n\n\\begin{lstlisting}[language=Python,style=source]\nheight = brfss['HTM4']\n\\end{lstlisting}\n\nWe can use \\passthrough{\\lstinline!notna!} and\n\\passthrough{\\lstinline!sum!} to count the number of rows with valid\nheight data.\n\n\\begin{lstlisting}[language=Python,style=source]\nn_height = height[male].notna().sum()\nn_height\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n182269\n\\end{lstlisting}\n\nThere are 182 269 male respondents with known heights. Here is the mean\nand standard deviation of these values.\n\n\\begin{lstlisting}[language=Python,style=source]\nmean_height = height[male].mean()\nstd_height = height[male].std()\nmean_height, std_height\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n(178.0768644146838, 7.966455313471575)\n\\end{lstlisting}\n\nThe average height for men in the U.S. is about 178.1 cm; the standard\ndeviation is about 8 cm. We can use bootstrapping to generate values\nfrom the sampling distribution of the mean. To reduce computation time,\nI reduced the number of iterations to 201.\n\n\\begin{lstlisting}[language=Python,style=source]\nt5 = [bootstrap_mean(brfss[male], 'HTM4')\n      for i in range(201)]\n\nsummarize(t5, digits=3)\n\\end{lstlisting}\n\n\\begin{tabular}{lrrl}\n\\toprule\n{} &  Estimate &     SE &                CI90 \\\\\n\\midrule\n{} &   178.076 &  0.019 &  [178.047, 178.107] \\\\\n\\bottomrule\n\\end{tabular}\n\nBecause the sample size is so large, the standard error is small and the\nconfidence interval is narrow. This result suggests that our estimate is\nvery precise, which is true in the sense that the error due to random\nsampling is small.\n\nBut there are other sources of error. For example, the heights and\nweights in this dataset are based on self-reports, so they are\nvulnerable to \\textbf{social desirability bias} (see\n\\url{https://en.wikipedia.org/wiki/Social-desirability_bias}). It's also\npossible that there are errors in recording the data. In a previous year\nof the BRFSS, there are a suspicious number of heights recorded as 60 or\n61 centimeters. I suspect that many of them are six feet, or six feet\nand one inch, and something went wrong in the preparation of the data.\n\nAnd that brings us to the first point of this example:\n\n\\begin{quote}\nWith large sample sizes, error due to random sampling is small, but with\nreal-world data, that usually means that there are other sources of\nerror that are bigger. So we can't be sure that the estimate is\naccurate.\n\\end{quote}\n\nIn fact, there is another source of error in this example that we have\nnot taken into account: oversampling.\n\n\\hypertarget{weighted-bootstrapping}{%\n\\section{Weighted Bootstrapping}\\label{weighted-bootstrapping}}\n\nBy design, the BRFSS oversamples some groups; that is, people in some\ngroups are more likely than others to appear in the sample. If people in\nthese groups are taller than others on average, or shorter, our\nestimated mean would not be accurate.\n\nWe encountered this issue in Chapter 7, where we used data from the\nNational Survey of Family Growth (NSFG) to compute the average birth\nweight for babies in the United States. In that example, we corrected\nfor oversampling by computing a weighted mean.\n\nIn this example, we will use a different method, \\textbf{weighted\nbootstrapping}, to estimate the mean and compute a confidence interval.\n\nThe BRFSS dataset includes a column, \\passthrough{\\lstinline!\\_LLCPWT!},\nthat contains sampling weights. The sampling weight for each respondent\nis the number of people in the population they represent. People in\noversampled groups have lower sampling weights; people in undersampled\ngroups have higher sampling weights. Here's what the range of values\nlooks like.\n\n\\begin{lstlisting}[language=Python,style=source]\nbrfss['_LLCPWT'].describe()\n\\end{lstlisting}\n\n\\begin{tabular}{lr}\n\\toprule\n{} &        \\_LLCPWT \\\\\n\\midrule\ncount &  418268.000000 \\\\\nmean  &     603.513276 \\\\\nstd   &    1082.430311 \\\\\nmin   &       1.016173 \\\\\n25\\%   &     111.160528 \\\\\n50\\%   &     272.869258 \\\\\n75\\%   &     654.211787 \\\\\nmax   &   42066.730900 \\\\\n\\bottomrule\n\\end{tabular}\n\nThe lowest sampling weight is about 1; the largest is 42 066. So that's\na very wide range!\n\nWe can take these weights into account by passing them as an argument to\n\\passthrough{\\lstinline!sample!}. That way, the probability that any row\nis selected is proportional to its sampling weight.\n\n\\begin{lstlisting}[language=Python,style=source]\nn = len(brfss)\nbootstrapped = brfss.sample(n=n, replace=True, weights='_LLCPWT')\n\\end{lstlisting}\n\nAs we saw with unweighted bootstrapping, the same row can appear more\nthan once. To see how many times, we can use\n\\passthrough{\\lstinline!value\\_counts!} and the\n\\passthrough{\\lstinline!SEQNO!} column, which contains a unique\nidentifier for each respondent.\n\n\\begin{lstlisting}[language=Python,style=source]\nrepeats = bootstrapped['SEQNO'].value_counts()\nrepeats.head()\n\\end{lstlisting}\n\n\\begin{tabular}{lr}\n\\toprule\n{} &  SEQNO \\\\\n\\midrule\n2019000108 &    139 \\\\\n2019000851 &    119 \\\\\n2019006167 &    118 \\\\\n2019000047 &    116 \\\\\n2019000011 &    115 \\\\\n\\bottomrule\n\\end{tabular}\n\nSome rows appear more than 100 times. Most likely, these are the rows\nwith the highest sampling rates, which correspond to people from\nundersampled groups.\n\nTo see how many rows don't appear at all, we can use\n\\passthrough{\\lstinline!set!} subtraction to count the values of\n\\passthrough{\\lstinline!SEQNO!} that appear in the original dataset but\nnot the sample.\n\n\\begin{lstlisting}[language=Python,style=source]\nunused = set(brfss['SEQNO']) - set(bootstrapped['SEQNO'])\nlen(unused)\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n826\n\\end{lstlisting}\n\nThere are several hundred rows that don't appear in this sample, but\nthey are not dropped altogether; when we repeat this process, they will\nappear in other samples.\n\nWe can use weighted bootstrapping to generate values from the sampling\ndistribution of the mean. The following function uses\n\\passthrough{\\lstinline!sample!} and the\n\\passthrough{\\lstinline!\\_LLCPWT!} column to generate a bootstrapped\nsample, then returns the average height.\n\n\\begin{lstlisting}[language=Python,style=source]\ndef weighted_bootstrap_mean(df):\n    n = len(df)\n    sample = df.sample(n=n, replace=True, weights='_LLCPWT')\n    return sample['HTM4'].mean()\n\\end{lstlisting}\n\nI'll test this function with a \\passthrough{\\lstinline!DataFrame!} that\ncontains only male respondents. If we run it once, we get a random value\nfrom the sampling distribution of the weighted mean.\n\n\\begin{lstlisting}[language=Python,style=source]\nmale_df = brfss[male]\nweighted_bootstrap_mean(male_df)\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n177.6302436908912\n\\end{lstlisting}\n\nIf we run it many times, we get a random sample from the sampling\ndistribution.\n\n\\begin{lstlisting}[language=Python,style=source]\nt6 = [weighted_bootstrap_mean(male_df) \n      for i in range(201)]\n\nsummarize(t6, digits=3)\n\\end{lstlisting}\n\n\\begin{tabular}{lrrl}\n\\toprule\n{} &  Estimate &     SE &                CI90 \\\\\n\\midrule\n{} &   177.638 &  0.019 &  [177.604, 177.668] \\\\\n\\bottomrule\n\\end{tabular}\n\nThe mean of the sampling distribution estimates the average height for\nmen in the U.S., corrected for oversampling. If we compare it to the\nunweighted mean we computed, it is a little lower.\n\n\\begin{lstlisting}[language=Python,style=source]\nprint(np.mean(t6), mean_height)\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n177.63797698644524 178.0768644146838\n\\end{lstlisting}\n\nSo it seems like people in the oversampled groups are taller than\nothers, on average, by enough to bring the unweighted mean up by about\nhalf a centimeter.\n\nThe difference between the weighted and unweighted means is bigger than\nthe width of the confidence interval. So in this example the error if we\nfail to correct for oversampling is bigger than variability due to\nrandom sampling.\n\n\\hypertarget{correlation-and-regression}{%\n\\section{Correlation and Regression}\\label{correlation-and-regression}}\n\nBootstrap resampling can be used to estimate other statistics and their\nsampling distributions. For example, in Chapter 9 we computed the\ncorrelation between height and weight, which is about 0.48.\n\n\\begin{lstlisting}[language=Python,style=source]\nvar1, var2 = 'HTM4', 'WTKG3'\ncorr = brfss[var1].corr(brfss[var2])\ncorr\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n0.47715146283881427\n\\end{lstlisting}\n\nThat correlation does not take into account oversampling. We can correct\nit with this function, which generates a weighted bootstrapped sample\nand uses it to compute the correlation of the columns with names\n\\passthrough{\\lstinline!var1!} and \\passthrough{\\lstinline!var2!}.\n\n\\begin{lstlisting}[language=Python,style=source]\ndef weighted_bootstrap_corr(df, var1, var2):\n    n = len(df)\n    sample = df.sample(n=n, replace=True, weights='_LLCPWT')\n    corr = sample[var1].corr(sample[var2])\n    return corr\n\\end{lstlisting}\n\n\\textbf{Exercise:} Use this function to draw 101 values from the\nsampling distribution of the correlation between height and weight. What\nis the mean of these values? Is it substantially different from the\ncorrelation we computed without correcting for oversampling? Compute the\nstandard error and 90\\% confidence interval for the estimated\ncorrelation.\n\n\\textbf{Exercise:} In Chapter 9 we also computed the slope of the\nregression line for weight as a function of height. Here's the result\nwith with 2019 data.\n\n\\begin{lstlisting}[language=Python,style=source]\nfrom scipy.stats import linregress\n\nsubset = brfss.dropna(subset=['WTKG3', 'HTM4'])\nres = linregress(subset['HTM4'], subset['WTKG3'])\nres.slope\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n0.932929241334935\n\\end{lstlisting}\n\nThe estimated slope is 0.93 kg/cm, which means that we expect someone 1\ncm taller than average to be about 0.93 kg heavier than average.\n\nWrite a function called\n\\passthrough{\\lstinline!weighted\\_bootstrap\\_slope!} that takes a\n\\passthrough{\\lstinline!DataFrame!}, generates a weighted bootstrapped\nsample, runs \\passthrough{\\lstinline!linregress!} with height and\nweight, and returns the slope of the regression line.\n\nRun it 101 times and collect the results. Use the sampling distribution\nto compute the mean of the slope estimates, standard error, and a 90\\%\nconfidence interval.\n\n\\hypertarget{limitations-of-bootstrapping}{%\n\\section{Limitations of\nBootstrapping}\\label{limitations-of-bootstrapping}}\n\nOne limitation of bootstrapping is that it can be computationally\nexpensive. With small datasets, it is usually fast enough that we can\ngenerate 1000 values from the sampling distribution, which means that we\ncan compute standard errors and confidence intervals precisely. With\nlarger datasets, we can cut the computation time by generating fewer\nvalues. With 100-200 values, the standard errors we get are usually\nprecise enough, but the bounds of the confidence intervals might be\nnoisier.\n\nThe other limitation, which can be more problematic, is that bootstrap\nsampling does not work well with datasets that contain a small number of\ndifferent values. To demonstrate, I'll select data from the GSS for one\nyear, 2018:\n\n\\begin{lstlisting}[language=Python,style=source]\ngss2018 = gss[gss['YEAR']==2018]\n\\end{lstlisting}\n\nAnd I'll use bootstrapping to generate values from the sampling\ndistribution of income.\n\n\\begin{lstlisting}[language=Python,style=source]\nt9 = [bootstrap_percentile(gss2018)\n      for i in range(1001)]\n\\end{lstlisting}\n\nHere are the results.\n\n\\begin{lstlisting}[language=Python,style=source]\nsummary9 = summarize(t9)\nsummary9\n\\end{lstlisting}\n\n\\begin{tabular}{lrrl}\n\\toprule\n{} &  Estimate &      SE &              CI90 \\\\\n\\midrule\n{} &   5169.52 &  254.68 &  [5107.5, 6129.0] \\\\\n\\bottomrule\n\\end{tabular}\n\nThe mean of the sampling distribution and the standard error look\nplausible at first glance, but the width of the confidence interval is\n0, which suggests that something has gone wrong!\n\nThe problem is that \\passthrough{\\lstinline!REALINC!} is not really a\nnumerical variable; it is a categorical variable in disguise. Using\n\\passthrough{\\lstinline!value\\_counts!}, we can see that there are only\n26 distinct values in this column.\n\n\\begin{lstlisting}[language=Python,style=source]\nlen(gss2018['REALINC'].value_counts())\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n26\n\\end{lstlisting}\n\nThe reason is that the GSS does not ask respondents to report their\nincomes. Instead, it gives them a list of ranges and asks them to pick\nthe range their income falls in. The ranges are described in the\ndocumentation of the related variable\n\\href{https://gssdataexplorer.norc.org/variables/104/vshow}{\\passthrough{\\lstinline!INCOME!}}.\n\nThen GSS analysts compute the midpoint of each range and convert to 1986\ndollars by adjusting for inflation. Details of the methodology are in\navailable from\n\\url{https://gss.norc.org/Documents/reports/methodological-reports/MR101\\%20Getting\\%20the\\%20Most\\%20Out\\%20of\\%20the\\%20GSS\\%20Income\\%20Measures.pdf}.\n\nAs a result, there are only 26 distinct values in\n\\passthrough{\\lstinline!REALINC!}. When we generate a bootstrapped\nsample and compute the 10th percentile, we get a small subset of them.\nHere are the values that appear in our sample:\n\n\\begin{lstlisting}[language=Python,style=source]\npd.Series(t9).value_counts().sort_index()\n\\end{lstlisting}\n\n\\begin{tabular}{lr}\n\\toprule\n{} &    0 \\\\\n\\midrule\n5107.5 &  944 \\\\\n5561.5 &    1 \\\\\n5675.0 &    1 \\\\\n5788.5 &    2 \\\\\n6015.5 &    1 \\\\\n6129.0 &    2 \\\\\n6242.5 &   50 \\\\\n\\bottomrule\n\\end{tabular}\n\nThere are only 5 different values, and one of them appears more than\n95\\% of the time. When we compute a 90\\% confidence interval, this value\nis both the 5th and the 95th percentile.\n\nBootstrapping works well for most distributions and most statistics; the\none thing it can't handle is lack of diversity in the data. However,\neven this problem can be solved. The fundamental cause is that the data\nhave been discretized excessively, so the solution is to smooth it.\nJittering is one option. Another is to use kernel density estimation\n(KDE).\n\n\\hypertarget{resampling-with-kde}{%\n\\section{Resampling with KDE}\\label{resampling-with-kde}}\n\nWe have used KDE several times to estimate and plot a probability\ndensity based on a sample. We can also use it to smooth data that have\nbeen discretized.\n\nIn Chapter 7 we saw that the distribution of income is well modeled by a\nlognormal distribution, so if we take the log of income, it is well\nmodeled by a normal distribution. Here are the logarithms of the income\ndata.\n\n\\begin{lstlisting}[language=Python,style=source]\nlog_realinc = np.log10(gss2018['REALINC'].dropna())\n\\end{lstlisting}\n\nAnd here's what the estimated density looks like.\n\n\\begin{lstlisting}[language=Python,style=source]\nimport seaborn as sns\n\nsns.kdeplot(log_realinc)\n\nplt.xlabel('Income (log10 1986 dollars)')\nplt.ylabel('Probability density')\nplt.title('Estimated distribution of income');\n\\end{lstlisting}\n\n\\begin{center}\n\\includegraphics[scale=0.75]{12_bootstrap_files/12_bootstrap_115_0.pdf}\n\\end{center}\n\nTo draw samples from this distribution, we'll use a Scipy function\ncalled \\passthrough{\\lstinline!gaussian\\_kde!}, which takes the data and\nreturns an object that represents the estimated density.\n\n\\begin{lstlisting}[language=Python,style=source]\nfrom scipy.stats import gaussian_kde\n\nkde = gaussian_kde(log_realinc)\n\\end{lstlisting}\n\n\\passthrough{\\lstinline!kde!} provides a method called\n\\passthrough{\\lstinline!resample!} that draws random values from the\nestimated density. As we've done in previous examples, we'll generate a\nresampled dataset with the same size as the original.\n\n\\begin{lstlisting}[language=Python,style=source]\nn = gss2018['REALINC'].notna().sum()\nn\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n2152\n\\end{lstlisting}\n\nNow we can draw a sample, compute the 10th percentile, and convert from\na logarithm to a dollar value.\n\n\\begin{lstlisting}[language=Python,style=source]\nsample = kde.resample(n)\n10 ** np.percentile(sample, 10)\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=output]\n4745.466287228786\n\\end{lstlisting}\n\nThe result is a random value from the sampling distribution of the 10th\npercentile. The following function encapsulates these steps.\n\n\\begin{lstlisting}[language=Python,style=source]\ndef resample_kde_percentile(kde):\n    sample = kde.resample(kde.n)\n    return 10 ** np.percentile(sample, 10)\n\\end{lstlisting}\n\nNow we can generate a sample from the sampling distribution.\n\n\\begin{lstlisting}[language=Python,style=source]\nt10 = [resample_kde_percentile(kde)\n       for i in range(1000)]\n\nsummary10 = summarize(t10)\n\\end{lstlisting}\n\nThe following table compares the results with KDE resampling to the\nprevious result with bootstrapping.\n\n\\begin{lstlisting}[language=Python,style=source]\ntable = pd.concat([summary9, summary10])\ntable.index=['bootstrapping', 'KDE resampling']\ntable\n\\end{lstlisting}\n\n\\begin{tabular}{lrrl}\n\\toprule\n{} &  Estimate &      SE &               CI90 \\\\\n\\midrule\nbootstrapping  &   5169.52 &  254.68 &   [5107.5, 6129.0] \\\\\nKDE resampling &   5087.77 &  248.81 &  [4699.39, 5507.4] \\\\\n\\bottomrule\n\\end{tabular}\n\nThe means and standard errors are about the same with either method. The\ndifference is that the confidence interval we get from KDE resampling is\nmuch more reasonable.\n\n\\hypertarget{summary}{%\n\\section{Summary}\\label{summary}}\n\nThere are ten examples in this chapter so far; let's review them:\n\n\\begin{enumerate}\n\\def\\labelenumi{\\arabic{enumi}.}\n\\item\n  First we used resampling based on a normal model to estimate average\n  family income in the GSS and compute a confidence interval.\n\\item\n  Then we used the same method to estimate the 10th percentile of\n  income, and we found that the width of the confidence interval was 0.\n  The problem is that the normal model does not fit the distribution of\n  income.\n\\item\n  To solve this problem, we switched to bootstrap sampling. First we\n  estimated average family income and confirmed that the results are\n  consistent with the results based on the normal model.\n\\item\n  Then we used bootstrapping to estimate the 10th percentile of income.\n  The results are much more plausible.\n\\item\n  Next we used data from the BRFSS to estimate the average height of men\n  in the U.S. Since this dataset is large, the confidence interval is\n  very small. That means that the estimate is precise, in the sense that\n  variability due to random sampling is small, but we don't know whether\n  it is accurate, because there are other possible sources of error.\n\\item\n  One of those sources of error is oversampling; that is, some people\n  are more likely to appear in the sample than others. In the BFRSS,\n  each respondent has a sampling weight that indicates how many people\n  in the population they represent. We used these weighted to do\n  weighted bootstrapping, and found that the error due to oversampling\n  is larger than the variability due to random sampling.\n\\item\n  In one exercise you used weighted bootstrapping to estimate the\n  correlation of height and weight and compute a confidence interval.\n\\item\n  In another exercise you estimated the slope of a regression line and\n  computed a confidence interval.\n\\item\n  Finally, I demonstrated a problem with bootstrap sampling when the\n  dataset has only a few different values,\n\\item\n  And presented a solution using KDE to smooth the data and draw samples\n  from an estimated distribution.\n\\end{enumerate}\n\nIn the exercise below, you can work on one more example.\n\n\\textbf{Exercise:} In Chapter 10 we used logistic regression to model\nsupport for legalizing marijuana as a function of age, sex, and\neducation level. Going back to that example, let's explore changes in\nsupport over time and generate predictions for the next decade.\n\nTo prepare the data for logistic regression, we have to recode the\n\\passthrough{\\lstinline!GRASS!} column so \\passthrough{\\lstinline!1!}\nmeans in favor of legalization and \\passthrough{\\lstinline!0!} means not\nin favor.\n\n\\begin{lstlisting}[language=Python,style=source]\ngss['GRASS'].replace(2, 0, inplace=True)\ngss['GRASS'].value_counts()\n\\end{lstlisting}\n\n\\begin{tabular}{lr}\n\\toprule\n{} &  GRASS \\\\\n\\midrule\n0.0 &  25662 \\\\\n1.0 &  11884 \\\\\n\\bottomrule\n\\end{tabular}\n\nAs explanatory variables we'll use \\passthrough{\\lstinline!YEAR!} and\n\\passthrough{\\lstinline!YEAR!} squared, which I'll store in a column\ncalled \\passthrough{\\lstinline!YEAR2!}.\n\n\\begin{lstlisting}[language=Python,style=source]\ngss['YEAR2'] = (gss['YEAR']-1990) ** 2\n\\end{lstlisting}\n\nNow we can run the model like this:\n\n\\begin{lstlisting}[language=Python,style=source]\nimport statsmodels.formula.api as smf\n\nformula = 'GRASS ~ YEAR + YEAR2'\nresults = smf.logit(formula, data=gss).fit(disp=False)\n\\end{lstlisting}\n\nTo generate predictions, I'll create a\n\\passthrough{\\lstinline!DataFrame!} with a range of values of\n\\passthrough{\\lstinline!YEAR!} up to 2030, and corresponding values of\n\\passthrough{\\lstinline!YEAR2!}.\n\n\\begin{lstlisting}[language=Python,style=source]\nyears = np.linspace(1972, 2030)\ndf_pred = pd.DataFrame()\ndf_pred['YEAR'] = years\ndf_pred['YEAR2'] = (df_pred['YEAR']-1990)**2\n\npred = results.predict(df_pred)\n\\end{lstlisting}\n\nI'll use \\passthrough{\\lstinline!groupby!} to compute the fraction of\nrespondents in favor of legalization during each year.\n\n\\begin{lstlisting}[language=Python,style=source]\ngrass_by_year = gss.groupby('YEAR')['GRASS'].mean()\n\\end{lstlisting}\n\nThe following function plots the data and decorates the axes.\n\n\\begin{lstlisting}[language=Python,style=source]\ndef plot_data():\n    grass_by_year.plot(style='o', alpha=0.5, label='data')\n    plt.xlabel('Year')\n    plt.ylabel('Fraction in favor')\n    plt.title('Support for legalization of marijuana')\n    plt.legend(loc='upper left');\n\\end{lstlisting}\n\nHere's what the predictions look like, plotted along with the data.\n\n\\begin{lstlisting}[language=Python,style=source]\nplt.plot(years, pred, label='logistic model', color='gray')\nplot_data()\n\\end{lstlisting}\n\n\\begin{center}\n\\includegraphics[scale=0.75]{12_bootstrap_files/12_bootstrap_144_0.pdf}\n\\end{center}\n\nThe model fits past data reasonably well and makes plausible predictions\nfor the next decade, although we can never be sure that trends like this\nwill continue.\n\nThis way of representing the results could be misleading because it does\nnot show our uncertainty about the predictions. Random sampling is just\none source of uncertainty among many, and for this kind of prediction it\nis certainly not the biggest. But it is the easiest to quantify, so\nlet's do it, if only as an exercise.\n\nWrite a function called\n\\passthrough{\\lstinline!bootstrap\\_regression\\_line!} that takes a\n\\passthrough{\\lstinline!DataFrame!} as a parameter, uses\n\\passthrough{\\lstinline!sample!} to resample the rows, runs the logistic\nregression model, generates predictions for the rows in\n\\passthrough{\\lstinline!df\\_pred!}, and returns the predictions.\n\nCall this function 101 times and save the results as a list of\n\\passthrough{\\lstinline!Series!} objects. To visualize the results, you\nhave two options:\n\n\\begin{enumerate}\n\\def\\labelenumi{\\arabic{enumi}.}\n\\item\n  Loop through the list and plot each prediction using a gray line with\n  a low value of \\passthrough{\\lstinline!alpha!}. The overlapping lines\n  will form a region showing the range of uncertainty over time.\n\\item\n  Pass the list of \\passthrough{\\lstinline!Series!} to\n  \\passthrough{\\lstinline!np.percentile!} with the argument\n  \\passthrough{\\lstinline!axis=0!} to compute the 5th and 95th\n  percentile in each column. Plot these percentiles as two lines, or use\n  \\passthrough{\\lstinline!plt.fill\\_between!} to plot a shaded region\n  between them.\n\\end{enumerate}\n\n", "meta": {"hexsha": "8e4f63b72169ec17f957b1e419bf57b227970613", "size": 38443, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "book/12_bootstrap.tex", "max_stars_repo_name": "AllenDowney/ElementsOfDataScienceBook", "max_stars_repo_head_hexsha": "3b87dfdd81c68ebd17f84a818326ed87da265ddb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-05-06T13:57:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T18:21:30.000Z", "max_issues_repo_path": "book/12_bootstrap.tex", "max_issues_repo_name": "AllenDowney/ElementsOfDataScienceBook", "max_issues_repo_head_hexsha": "3b87dfdd81c68ebd17f84a818326ed87da265ddb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "book/12_bootstrap.tex", "max_forks_repo_name": "AllenDowney/ElementsOfDataScienceBook", "max_forks_repo_head_hexsha": "3b87dfdd81c68ebd17f84a818326ed87da265ddb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-27T10:41:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-27T10:41:22.000Z", "avg_line_length": 33.9003527337, "max_line_length": 153, "alphanum_fraction": 0.7557162552, "num_tokens": 10559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8688267694452331, "lm_q1q2_score": 0.7082958100704935}}
{"text": "\\documentclass{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\n% Main maths packages\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{mathrsfs}\n\n% Required to declare unnumbered theorems. It enhances the style of the theorems as well.\n% Required to use proofs.\n\\usepackage{amsthm}\n\n% The syntax is \\newtheorem{envname}[theorem name to share the numbering]{caption}[section type/theorem name to number it accordingly].\n\\newtheorem{theorem}{Theorem}[subsection]\n\\newtheorem{corollary}{Corollary}[theorem]\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem*{definition}{Definition}\n\n\\begin{document}\n\n\\section{Theorems, corollaries and lemmas}\n\n\\subsection{Declare theorems}\n\nFirst, the theorem must be declared in the preamble. It can be used in the document afterwards. The name of the author can be specified between brackets.\n\n\\begin{theorem}[Pythagore]\n\t\\label{pythagore}\n\tthe square of the hypotenuse is equal to the sum of the squares of the other two sides.\n\\end{theorem}\n\n\\begin{corollary}\n\tIn any right triangle, the hypotenuse is greater than any one of the other sides, but less than their sum.\n\\end{corollary}\n\n\\begin{theorem}\n\tAnother theorem...\n\\end{theorem}\n\n\\begin{corollary}\n\tAnother corollary...\n\\end{corollary}\n\n\\begin{lemma}\n\tA lemma, which shares the same numbering as the theorem.\n\\end{lemma}\n\nA theorem can be referenced easily, such as \\ref{pythagore}.\n\n\n\\subsection{Unnumbered theorems}\n\n\\begin{definition}\n\tThis is an unnumbered definition.\n\\end{definition}\n\n\\subsection{Proofs}\n\n\\begin{proof}\n\tThe two large squares shown in the figure each contain four identical triangles, and the only difference between the two large squares is that the triangles are arranged differently. Therefore, the white space within each of the two large squares must have equal area. Equating the area of the white space yields the Pythagorean Theorem.\n\\end{proof}\n\nNote the white square at the end of the proof, it stands for Q.E.D. The abbreviation \"Q.E.D.\" is written to indicate the end of a proof. This abbreviation stands for \"Quod Erat Demonstrandum\", which is Latin for \"that which was to be demonstrated\". A more common alternative is to use a square or a rectangle.\n\n\\end{document}", "meta": {"hexsha": "8fd8dfce343ffeaa0389ecc24a06a09f89ba3bec", "size": 2212, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "compendium/mathematics/theorems-corollaries-lemmas.tex", "max_stars_repo_name": "ZenLulz/LatexCompendium", "max_stars_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-07-30T21:43:55.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-23T20:16:19.000Z", "max_issues_repo_path": "compendium/mathematics/theorems-corollaries-lemmas.tex", "max_issues_repo_name": "ZenLulz/LatexCompendium", "max_issues_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "compendium/mathematics/theorems-corollaries-lemmas.tex", "max_forks_repo_name": "ZenLulz/LatexCompendium", "max_forks_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.0149253731, "max_line_length": 338, "alphanum_fraction": 0.7793851718, "num_tokens": 563, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.8791467722591728, "lm_q1q2_score": 0.7082689467764169}}
{"text": "\\subsection{Computing the moments of the mRNA and protein distributions}\n\\label{sec_moments}\n\nFinding analytical solutions to chemical master equations is often fraught with\ndifficulty. An alternative approach is to to approximate the distribution. One\nsuch scheme of approximation, the maximum entropy principle, makes use of the\nmoments of the distribution to approximate the full distribution. In this\nsection we will demonstrate an iterative algorithm to compute the mRNA and\nprotein distribution moments.\n\nThe kinetic model for the simple repression motif depicted in\n\\fref{fig2_minimal_model}(A) consists of an infinite system of ODEs for each\npossible pair of mRNA and protein copy number, $(m, p)$. To compute any moment\nof the distribution, we define a vector\n\\begin{equation}\n\t\\ee{\\bb{m^x p^y}} \\equiv (\\ee{m^x p^y}_A, \\ee{m^x p^y}_I, \\ee{m^x p^y}_R)^T,\n\\end{equation}\nwhere $\\ee{m^x p^y}_S$ is the expected value of $m^x p^y$ in state $S \\in \\{A,\nI, R\\}$ for $x, y \\in \\mathbb{N}$. In other words, just as we defined the\nvector $\\PP(m, p)$, here we define a vector to collect the expected value of\neach of the promoter states. By definition, any of these moments $\\ee{m^x\np^y}_S$ can be computed as\n\\begin{equation}\n  \\ee{m^x p^y}_S \\equiv \\sum_{m=0}^\\infty \\sum_{p=0}^\\infty m^x p^y P_S(m, p).\n  \\label{eq_mom_def}\n\\end{equation}\nSumming over all possible values for $m$ and $p$ in \\eref{eq_cme_matrix}\nresults in an ODE for any moment of the distribution of the form (See\n\\siref{supp_moments} for full derivation)\n\\begin{equation}\n  \\begin{aligned}\n    \\dt{\\bb{\\ee{m^x p^y}}} &=\n    \\Km \\bb{\\ee{m^x p^y}}\\\\\n    &+ \\Rm \\bb{\\ee{p^y \\left[ (m + 1)^x -m^x \\right]}}\n     + \\Gm \\bb{\\ee{m p^y \\left[ (m - 1)^x - m^x \\right]}}\\\\\n    &+ \\Rp \\bb{\\ee{m^{(x + 1)} \\left[ (p + 1)^y - p^y \\right]}}\n     + \\Gp \\bb{\\ee{m^x p \\left[ (p - 1)^y - p^y \\right]}}.\n    \\label{eq_gral_mom}\n  \\end{aligned}\n\\end{equation}\n\nGiven that all transitions in our stochastic model are first order reactions,\n\\eref{eq_gral_mom} has no moment-closure problem \\cite{Voliotis2014a}. This\nmeans that the dynamical equation for a given moment only depends on lower\nmoments (See \\siref{supp_moments} for full proof). This feature of our model\nimplies, for example, that the second moment of the protein distribution\n$\\ee{p^2}$ depends only on the first two moments of the mRNA distribution\n$\\ee{m}$ and $\\ee{m^2}$, the first protein moment $\\ee{p}$, and the\ncross-correlation term $\\ee{mp}$. We can therefore define $\\bmu$ to be a vector\ncontaining all moments up to $\\bb{\\ee{m^x p^y}}$ for all promoter states,\n\\begin{equation}\n\\bmu = \\left[ \\bb{\\ee{m^0 p^0}},\n\t\t\t\t\t\t\t\\bb{\\ee{m^1 p^0}},\n\t\t\t\t\t\t\t\\ldots, \\bb{\\ee{m^x p^y}} \\right]^T.\n\\end{equation}\nExplicitly for the three-state promoter model depicted in\n\\fref{fig2_minimal_model}(A) this vector takes the form\n\\begin{equation}\n\t\\bmu = \\left[ \\ee{m^0 p^0}_A, \\ee{m^0 p^0}_I, \\ee{m^0 p^0}_R,\n\t\\ldots, \\ee{m^x p^y}_A, \\ee{m^x p^y}_I, \\ee{m^x p^y}_R \\right]^T.\n\\end{equation}\n\nGiven this definition we can compute the general moment dynamics as\n\\begin{equation}\n\\dt{\\bmu} = \\bb{A} \\bmu,\n\\label{eq_mom_dynamics}\n\\end{equation}\nwhere $\\bb{A}$ is a square matrix that contains all the numerical coefficients\nthat relate each of the moments. We can then use \\eref{eq_gral_mom} to build\nmatrix $\\bb{A}$ by iteratively substituting values for the exponents $x$ and\n$y$ up to a specified value. In the next section, we will use\n\\eref{eq_mom_dynamics} to numerically integrate the dynamical equations for our\nmoments of interest as cells progress through the cell cycle. We will then use\nthe value of the moments of the distribution to approximate the full gene\nexpression distribution. This method is computationally more efficient than\ntrying to numerically integrate the infinite set of equations describing the\nfull probability distribution $\\bb{P}(m, p)$, or using a stochastic algorithm \nto sample from the distribution.", "meta": {"hexsha": "ad54838163df01d7961f85ddc7fadf754bf799fc", "size": 3942, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/section_02_distribution_moments.tex", "max_stars_repo_name": "RPGroup-PBoC/chann_cap", "max_stars_repo_head_hexsha": "f2a826166fc2d47c424951c616c46d497ed74b39", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-08-21T04:06:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-09T07:36:58.000Z", "max_issues_repo_path": "doc/section_02_distribution_moments.tex", "max_issues_repo_name": "RPGroup-PBoC/chann_cap", "max_issues_repo_head_hexsha": "f2a826166fc2d47c424951c616c46d497ed74b39", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/section_02_distribution_moments.tex", "max_forks_repo_name": "RPGroup-PBoC/chann_cap", "max_forks_repo_head_hexsha": "f2a826166fc2d47c424951c616c46d497ed74b39", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-04-29T17:43:28.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-09T00:20:16.000Z", "avg_line_length": 50.5384615385, "max_line_length": 79, "alphanum_fraction": 0.7181633688, "num_tokens": 1275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7082689377950875}}
{"text": "\\section{Boolean network}\n\\label{sect:background-boolean-network}\n\nA \\textit{(combinational) Boolean network} is a directed acyclic graph $G=(V,E)$,\nwith a set $V$ of vertices and a set $E\\subseteq V \\times V$ of edges.\nTwo non-empty disjoint subsets $V_I$ and $V_O$ of $V$ are identified:\na vertex $v \\in V_I$ (resp. $V_O$) is referred to as a \\textit{primary input} (PI) (resp. \\textit{primary output} (PO)).\nEach vertex $v \\in V$ is associated with a Boolean variable $b_v$.\nEach vertex $v \\in V \\setminus V_I$ is associated with a Boolean function $f_v$.\nAn edge $(u,v)\\in E$ indicates $f_v$ refers to $b_u$ as an input variable;\n$u$ is called a \\textit{fanin} of $v$, and $v$ a \\textit{fanout} of $u$.\nThe valuation of the Boolean variable $b_v$ of vertex $v$ is as follows:\nif $v$ is a PI, $b_v$ is given by external signals; otherwise, $b_v$ equals the value of $f_v$.\nTo ease readability, we will not distinguish a vertex $v$ and its corresponding Boolean variable $b_v$.\nWe will simply denote $b_v$ with $v$.\n\nNote that a Boolean network can be converted in linear time to a Boolean formula in CNF through Tseitin transformation~\\cite{Tseitin1983}.", "meta": {"hexsha": "75733fbe10f1ee2814bc10acdd5064a103002d3a", "size": 1157, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/background/boolean-network.tex", "max_stars_repo_name": "nianzelee/PhD-Dissertation", "max_stars_repo_head_hexsha": "061e22dd55b4e58b3de3b0e58bb1cbe11435decd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-11T19:38:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T19:38:13.000Z", "max_issues_repo_path": "paper/background/boolean-network.tex", "max_issues_repo_name": "nianzelee/PhD-Dissertation", "max_issues_repo_head_hexsha": "061e22dd55b4e58b3de3b0e58bb1cbe11435decd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/background/boolean-network.tex", "max_forks_repo_name": "nianzelee/PhD-Dissertation", "max_forks_repo_head_hexsha": "061e22dd55b4e58b3de3b0e58bb1cbe11435decd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.0588235294, "max_line_length": 138, "alphanum_fraction": 0.7268798617, "num_tokens": 352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109955, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.7081640070213783}}
{"text": "\\section{Multiple Random Variables}\n\n\\subsection{Facts}\n\\begin{itemize}[+]\n    \\item RVs are independent if and only if their pdfs factorise\n    \\item Functions of independent RVs are independent\n    \\item Expectations of products (and hence mgfs, etc. of sums) of independent RVs factor\n    \\item Variance of sum of independent RVs is sum of variances.\n    \\item Independent RVs have vanishing covariance/correlation, but the converse is not true in general.\n\\end{itemize}\n\n\\subsection{Bivariate Relations}\n\\begin{theorem}[Conditional Expectation]\n    \\[\n        \\E{}[\\E{}[X|Y]] = \\E{}[X]\n    \\]\n    provided the expectations exist.\n\\end{theorem}\n\n\\begin{theorem}[Conditional variance]\n    \\[\n        \\Var{}[X] = \\E{}[\\Var{}[X \\vert{} Y]] + \\Var{}[\\E{}[X \\vert{} Y]]\n    \\]\n    provided the expectations exist.\n\\end{theorem}\n\n\\begin{definition}[Covariance]\n    \\[\n        \\Cov{}[X, Y] = \\E{}[(X - \\mu_X)(Y - \\mu_Y)]\n    \\]\n\\end{definition}\n\n\\begin{theorem}\n    \\[\n        \\Cov{}[X, Y] = \\E{}[XY] - \\mu_X\\mu_Y\n    \\]\n\\end{theorem}\n\n\\begin{theorem}\n    \\[\n        \\Var[aX + bY] = a^2\\Var{}[X] + b^2\\Var{}[Y] + 2ab\\Cov[X, Y]\n    \\]\n\\end{theorem}\n\n\\begin{definition}[Correlation]\n    \\[\n        \\rho_XY = \\frac{\\Cov[X, Y]}{\\sigma_X \\sigma_Y}\n    \\]\n\\end{definition}\n\n\\begin{remark}\n    The correlation measures the strength of \\emph{linear} relation between two RVs. It is possible to have strong non-linear relationships but with $\\rho = 0$.\n\\end{remark}\n\nWe can use an argument similar to the standard proof of Cauchy-Schwarz to show the following\n\\begin{theorem}\n    Let $X$ and $Y$ be any RVs, then\n    \\begin{enumerate}[a.]\n        \\item $-1 \\leq \\rho_{XY} \\leq 1$,\n        \\item $\\abs{\\rho_{XY}} = 1$ if and only if there are constants $a \\neq 0, b$ such that $\\P{}(Y = aX + b) = 1$. If $\\abs{\\rho_{XY}} = 1$ then $\\text{sign}(\\rho) = \\text{sign}(a)$.\n    \\end{enumerate}\n\\end{theorem}\n\n\n\\subsection{Inequalities}\n\n\\subsubsection{Numerical Inequalities}\n\n\\begin{theorem}\n    Let $a$ and $b$ be any positive numbers and let $p, q > 1$ satisfy $1/p + 1/q = 1$, then\n    \\[\n        \\frac1p a^p + \\frac1q b^q \\geq ab\n    \\]\n    with equality if and only if $a^p = b^q$.\n\\end{theorem}\n    \n\n\\begin{theorem}[H{\\\"o}lder's Inequality]\n    Let $X$ and $Y$ be any random variables and let $p, q > 1$ satisfy $1/p + 1/q = 1$, then\n    \\[\n        \\abs{\\E{}[XY]} \\leq \\E{}[\\abs{XY}] \\leq \\E{}[\\abs{X}^p]^{1/p} \\E{}[\\abs{Y}^q]^{1/q}\n    \\]\n\\end{theorem} \n\n\\begin{corollary}\\mbox{}\n    \\begin{itemize}\n        \\item Cauchy-Schwarz is the special case $p = q = 2$\n        \\item $\\Cov[X, Y]^2 \\leq \\sigma_X^2 \\sigma_Y^2$\n        \\item $\\E{}[\\abs{X}] \\leq \\E{}[\\abs{X}^p]^{1/p}$\n        \\item \\emph{Liapounov's Inequality} $\\E{}[\\abs{X}^r]^{1/r} \\leq \\E{}[\\abs{X}^s]^{1/s}$ where $1 < r < s < \\infty$.\n    \\end{itemize}\n\\end{corollary}\n\n\n\\subsubsection{Functional Inequalities}\n\n\\begin{definition}[Convex Function]\n    A function $g(x)$ is \\emph{convex} on a set $S$ if for all $x, y \\in S$ and $0< \\lambda < 1$\n    \\[\n        g(\\lambda x + (1 - \\lambda)y) \\leq \\lambda g(x) + (1 - \\lambda)g(y).\n    \\]\n    \\emph{Strictly convex} is when the inequality is strict. $g$ is \\emph{concave} if $-g$ is convex.\n\\end{definition}\n\n\\begin{lemma}\n    $g(x)$ is convex on $S$ if $g''(x) \\geq 0$ $\\forall x \\in S$.\n\\end{lemma}\n\n\\begin{theorem}[Jensen's Inequality]\n    If $g(x)$ is convex, then for any random variable $X$\n    \\[\n        \\E{}[g(X)] \\leq g(\\E{}[X]).\n    \\]\n    Equality holds if and only if, for every line $a + bx$ that is tangent to $g(x)$ at $x = \\E{}[X]$, $\\P{}\\{g(X) = a + bX\\} = 1$. (So if and only if $g$ is affine with probability 1.)\n\\end{theorem}\n\n\\begin{corollary}\n    \\mbox{}\n    \\begin{itemize}\n        \\item $\\E{}[X^2] \\geq \\E{}[X]^2$\n        \\item $\\E{}[1/X] \\geq 1/ \\E{}[X]$\n    \\end{itemize}\n\\end{corollary}\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "f507b281a52bb8b2c7e46ae956188e4f8f6a5b41", "size": 3823, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/chapter4/content.tex", "max_stars_repo_name": "brynhayder/statistical_inference", "max_stars_repo_head_hexsha": "fc3e770650e9c145aa9d45e604c9e67624c2a013", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-25T05:52:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-12T07:20:16.000Z", "max_issues_repo_path": "notes/chapters/chapter4/content.tex", "max_issues_repo_name": "brynhayder/statistical_inference", "max_issues_repo_head_hexsha": "fc3e770650e9c145aa9d45e604c9e67624c2a013", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-17T15:44:01.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-24T09:31:29.000Z", "max_forks_repo_path": "notes/chapters/chapter4/content.tex", "max_forks_repo_name": "brynhayder/statistical_inference", "max_forks_repo_head_hexsha": "fc3e770650e9c145aa9d45e604c9e67624c2a013", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-04-29T11:11:32.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-17T09:47:07.000Z", "avg_line_length": 28.7443609023, "max_line_length": 186, "alphanum_fraction": 0.5835731101, "num_tokens": 1401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8872045922259088, "lm_q1q2_score": 0.7081549746645927}}
{"text": "Integer Linear Programming is the first of the two methods that has been used in this project (see Introduction for more details about the problem). This method always finds the optimal solution without taking into account the amount of computational\nresources needed. This model is developed in CPLEX and the model implemented is described in the next sections.\n\n\n\\subsection{Decision variables}\n\n\\begin{itemize}\n\n\\item $ w_{n,h} (\\mathbb{B})  : \\text{This boolean variable specifies whether the nurse n works at the hour h (1) or not (0)}  $\n\\item $ z_{n} (\\mathbb{B})  : \\text{This boolean variable specifies whether the nurse n works during the shift or not.} $ \n\t\\begin{itemize}[label=$\\star$]\n \t\\item $ z{n} = 1  \\Rightarrow \\text{ The nurse n works at least 1 hour, } \\exists h, w_{n,h} = 1 $ \n \t\\item $ z{n} = 0 \\Rightarrow \\forall h, w_{n,h} = 0 $ \n \t\\end{itemize}\n\\item $  s_{n} (\\mathbb{N}) : \\text{Positive integer variable specifying the hour in which the nurse n starts working,} \\\\ \\text{  such that $ w_{n,s_{n}}=1 $ and  $ w_{n,s_{n}-i}=0 $,  $ \\forall i: 1 \\leq s_{n} - i < s_{n} $ } $\n\\item $  e_{n} (\\mathbb{N}) : \\text{Positive integer variable specifying the hour in which the nurse n stops working,} \\\\ \\text{such that $ w_{n,e_{n}}=1 $ and  $ w_{n,e_{n}+i}=0,\\forall i : e_{n} < e_{n}+i \\leq 24 $  } $\n\\end{itemize}\n\n\\subsection{Instance parameters}\n\n\\begin{itemize}\n\\item  $ demand_h $: Array of integers, specifying the required number of nurses at hour h\n\\item  $ nNurses $: Integer that specifies the number of available nurses to assign.\n\\item  $minHours$: Integer that specifies the minimum number of hours that a nurse must work if she works.\n\\item  $maxHours$: Integer that specifies the maximum number of hours that a nurse must work if she works.\n\\item  $maxConsec$: Integer that specifies the maximum number of consecutive hours that a nurse can work.\n\\item  $maxPresence$: Integer that specifies the maximum number of hours that a nurse can stay at the hospital.\n\\end{itemize}\n\n\\subsection{Objective function}\n\\begin{center}\nMinimize $ \\sum\\limits_{n=1}^{nNurses} z_{n}  $ \\\\\n\\end{center}\n\nThis objective function aims to minimize the number of working nurses, this means, minimize the number of $z_n$ variables that are activated (with a value of 1), which is the main goal for our problem.\n\n\\subsection{Constraints}\n\n\\begin{itemize}\n\\item  Set the $z_n$ values correctly: \\\\ \\\\\n\\begin{equation}\n \\forall n: 1 \\leq n \\leq nNurses,  \\\\\n\t24 \\cdot z_{n}  \\geq \\sum\\limits_{1 \\leq h \\leq 24} w_{n,h} \\\\\n   z_{n} \\leq \\sum\\limits_{1 \\leq h \\leq 24} w_{n,h}\n \\end{equation}\n\n\\item  At any hour h, at least demandh nurses must be working: \\\\ \\\\\n\\begin{equation}\n\\forall h : 1 \\leq h \\leq 24, \\\\\n \\sum\\limits_{1 \\leq n \\leq nNurses} w_{n,h} \\geq demand_{h} \\\\\n\\end{equation}\n\n\\item  Each nurse that works, must work at least minHours: \\\\ \\\\\n\\begin{equation}\n\\forall n: 1 \\leq n \\leq nNurses \\\\\n\t\\sum\\limits_{1 \\leq h \\leq 24} w_{n,h} \\geq minHours \\cdot z_{n} \\\\\n\\end{equation}\n\n\\item  Each nurse that works, must work at most maxHours: \\\\ \\\\\n\\begin{equation}\n\\forall n: 1 \\leq n \\leq nNurses \\\\\n\t\\sum\\limits_{1 \\leq h \\leq 24} w_{n,h} \\leq maxHours \\cdot z_{n} \\\\\n\\end{equation}\n\n\\item  Each nurse works at most maxConsec consecutive hours: \\\\ \\\\\n\\begin{equation}\n\\forall n:  1 \\leq n \\leq nNurses, \\\\\n\t\\forall h_{1}:  1 \\leq h_{1} \\leq 24 - maxConsec, \\\\\n\t\\sum\\limits_{ h_{1} \\leq h \\leq h_{1} + maxConsec} w_{n,h} \\leq maxConsec\n\\end{equation}\n\n\\item  Each nurse can stay in the hospital at most maxPresence hours: \\\\ \\\\\n\\begin{equation}\n\\begin{aligned}\n&\\forall n:  1 \\leq n \\leq nNurses, e_{n} \\leq 24 \\cdot z_{n}, \\\\\n &\\forall n:  1 \\leq n \\leq nNurses, \\forall h: 1 \\leq h \\leq 24, e_{n} \\geq h \\cdot w_{n,h}, \\\\ \n &\\forall n:  1 \\leq n \\leq nNurses, s_{n} \\geq 0, \\\\\n &\\forall n:  1 \\leq n \\leq nNurses, \\forall h: 1 \\leq h \\leq 24, s_{n} \\leq (h - 24) \\cdot w_{n,h} + 24 \\cdot z_{n}, \\\\\n  &\\forall n:  1 \\leq n \\leq nNurses: \\\\ &e_{n} - s_{n} + 1 - (2 \\cdot 24)\\cdot(1 - z_{n}) \\leq maxPresence \\cdot z_{n}\n\\end{aligned}\n\\end{equation}\n\n\\item  Each nurse can rest at most one consecutive hour:\n\n\\begin{equation}\n\\begin{aligned}\n\\forall n:  1 \\leq n \\leq nNurses, \\forall h: 2 \\leq h \\leq 22, \\forall M: M \\geq 24:  \\\\ M - M \\cdot w_{n,h-1} + M \\cdot w_{n,h} + M \\cdot w_{n,h+1}  \\geq \\sum\\limits_{h+1 \\leq h_{i} \\leq 24 }  w_{n,h_{i}}\n \\end{aligned}\n\\end{equation}\n\n\\end{itemize}\n\n\\pagebreak", "meta": {"hexsha": "23293309ff4f24fdcea187f1a907df94e02373bb", "size": 4429, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/tex/ILPmodel.tex", "max_stars_repo_name": "presmerats/Nurse-Scheduling-LP-and-Heuristics", "max_stars_repo_head_hexsha": "0b4796d082908f6644bd28ad4bfad9552879ea75", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-10T02:38:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-10T02:38:12.000Z", "max_issues_repo_path": "Documentation/tex/ILPmodel.tex", "max_issues_repo_name": "presmerats/Nurse-Scheduling-LP-and-Heuristics", "max_issues_repo_head_hexsha": "0b4796d082908f6644bd28ad4bfad9552879ea75", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Documentation/tex/ILPmodel.tex", "max_forks_repo_name": "presmerats/Nurse-Scheduling-LP-and-Heuristics", "max_forks_repo_head_hexsha": "0b4796d082908f6644bd28ad4bfad9552879ea75", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-10T02:38:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-10T02:38:13.000Z", "avg_line_length": 47.623655914, "max_line_length": 250, "alphanum_fraction": 0.6728381124, "num_tokens": 1577, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541561135441, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.7081357707641052}}
{"text": "\\newpage\n\\sectionnonum{Appendix}\n\n\\begin{appendices}\n    \n\n\n\\section{Descent Lemma}\n\\label{app:DL}\n\\begin{lem}\n    Let $ f: \\mathbb{R}^n \\rightarrow R $ be continuous differentiable,\n    and $ x,\\ y\\in \\mathbb{R}^n $. Suppose that:\n    \\begin{equation}\n        \\forall t \\in [0,\\ 1]\\ \\ \\|\\nabla f(x+t y)-\\nabla f(x)\\| \\leq L t\\|y\\|\n    \\end{equation}\n    where $ L $ is a scalar, then:\n    \\begin{equation}\n        f(x+y) \\leq f(x)+y^{T} \\nabla f(x)+\\frac{L}{2}\\|y\\|^{2}\n    \\end{equation}\n\\end{lem}\n\n\\begin{prf}\n    Let $ g(t) = f(x+ty) $, then: \\\\\n\\begin{align}\n    f(x+y)-f(x) & =g(1)-g(0) \\\\\n    &=\\int_{0}^{1} \\frac{d g}{d t}(t) d t \\\\\n    &=\\int_{0}^{1} y^{T} \\nabla f(x+t y) d t \\\\ \n    & \\leq \\int_{0}^{1} y^{T} \\nabla f(x) d t+\\left|\\int_{0}^{1} y^{T}(\\nabla f(x+t y)-\\nabla f(x)) d t\\right| \\\\ \n    & \\leq \\int_{0}^{1} y^{T} \\nabla f(x) d t+\\int_{0}^{1}\\|y\\| \\cdot\\|\\nabla f(x+t y)-\\nabla f(x)\\| d t \\\\ \n    & \\leq y^{T} \\nabla f(x)+\\|y\\| \\int_{0}^{1} L t\\|y\\| d t \\\\ \n    &=y^{T} \\nabla f(x)+\\frac{L}{2}\\|y\\|^{2} \n\\end{align}\n\\end{prf}\n\n\n\\section{PReLU}\n\nHe et al. \\parencite{he2015delving} first propose the variant \nPReLU, The definition is:\n\\begin{align}\ng\\left(z_{j}\\right)=\\left\\{\\begin{array}{ll}{z_{j},} & {\\text { if } z_{j}>0} \\\\ {a_{j} z_{j},} & {\\text { if } z_{j} \\leq 0}\\end{array}\\right.\n\\end{align}\nor in a more compact form:\n\\begin{equation}\n    g(z_j) = \\max \\left(0, z_{j}\\right)+a_{j} \\min \\left(0, z_{j}\\right)\n\\end{equation}\n$ a_j $ is the coefficient that can be adaptively learnt,\nsubscript $ j $ means the coefficient can vary on the \ndifferent channel in the same layer. Though the shape of \nPReLU and Leaky ReLU (LReLU) look the same, PReLU drastically\navoids the overfitting by introducing a few parameters. \nIn practice, if $ a_j $ is shared by the same layers the \nperformance will be better.\n\n\\section{Numerous Zero-error Minimum}\n\\begin{thm}\n    \\label{thm:bezout}\n    Suppose $ \\mathbb{F} $ is a field and polynomials \n    $ P,\\ Q\\in \\mathbb{F} $ have no common factor of degree $ d\\geq 1 $\n    \\footnote{A more frank expression is independent.}. Let \n    $ Z(P,\\ Q) = \\{(x,\\ y)\\in \\mathbb{F}^2|P(x,\\ y) = Q(x,\\ y)\\} $.\n    Then the number of points is upper bounded by $ d(P)d(Q) $.\n\\end{thm}\nVia Bezout theorem \\autoref{thm:bezout}, we can obtain the upper bound of a system \nwith $l$ layers and $ N $ data: $ d^{lN} $, where $ d $ is the \ndegree of polynomial equations. In the language of neural networks,\nthe number of zero points of cost functions is $ d^{lN} $. The theorem can\nnot strictly apply to neural networks with ReLU. But experimental\nin Figure 2 in \\parencite{poggio2017theory}\nresults show the similar behavior of ReLU and polynomial approximation.\nTherefore, we give a proposition as follow:\n\\begin{pro}\n    There are a large number of zero-error minimum.\n\\end{pro}\n\n\\end{appendices}", "meta": {"hexsha": "cc731fc8cac6df7b110643f2b47ad880fc11fcd8", "size": 2845, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "body/undergraduate/final/appendix.tex", "max_stars_repo_name": "xuebashuoge/Neural-Network-Overview", "max_stars_repo_head_hexsha": "ae11b768aeffe09ddd71b082dfd27c15c02d9c2d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "body/undergraduate/final/appendix.tex", "max_issues_repo_name": "xuebashuoge/Neural-Network-Overview", "max_issues_repo_head_hexsha": "ae11b768aeffe09ddd71b082dfd27c15c02d9c2d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "body/undergraduate/final/appendix.tex", "max_forks_repo_name": "xuebashuoge/Neural-Network-Overview", "max_forks_repo_head_hexsha": "ae11b768aeffe09ddd71b082dfd27c15c02d9c2d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.4342105263, "max_line_length": 143, "alphanum_fraction": 0.6224956063, "num_tokens": 1071, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7080946600528627}}
{"text": "\\chapter{External Interface Requirements}\n\n\\section{User Interfaces}\n\nThe \\acrshort{csaf}  package exists as middleware. It exists as a library, and no CLI or GUI tools are planned.\n\n\\section{Software Interfaces}\n\n\\subsection{Mathematical Representations}\nA component is required to be a dynamical system in some form, a mathematical entity that has the ability to \nevolve in time. This means that a system assumes a function in a set $\\left\\{ f^t \\right\\}_{t \\in \\mathbb F}$, \nwhere $\\mathbb F$ is some set for time. For continuous time systems, this set can be the real numbers $\n\\mathbb R$; for discrete, the integers $\\mathbb Z$ suffices. For systems that use both discrete and \ncontinuous time, a relation between the two fields is necessary. A sampling frequency and sampling phase is \nused if the discrete time system is uniform time step. This general form, a system as a set of functions, is not \nconducive towards using in a software system, and another representation is desired. \\\\\n\n\nCommonly, this set of functions can be characterized by a system of ordinary differential equations \n(\\acrshort{ode}s) for continuous time or ordinary difference equations for discrete time. These systems of \nequations can be put into a form that permit a simple representation. For continuous time,\n\n\\begin{equation}\n\\begin{cases}\n\\dot x = g(t, x, u; p) \\\\\nf_{x_0}^t = h(., x(.), u; r) \\\\\n\\end{cases}\n\\end{equation}\n\nThis form separates the solution into two steps with respect to an initial condition $x_0$. First, all variables \nwhere the \\acrshort{ode}s involve rates of change are grouped in a vector $x \\in \\mathbb R^N$, where it \nassumes an element in a state space. $u \\in \\mathbb R^M$ is an additional time varying vector, representing \ncontrol input to the system. $p$ and $r$ are time independent parameters involved with the two functions. \nThen, another function $h$ takes the space and returns the system configuration, evaluating one of the \nsystem functions. Similarly, a construction can be made for a discrete system,\n\n\\begin{equation}\n\\begin{cases}\nx_{n} = g(t, n-1, u; p)\\\\\nf^{n}_{x_0} = h(., x(.), u; r) \\\\\n\\end{cases},\n\\end{equation}\n\nfor the discrete time system. The evolution of the state $x$ can be computed directly rather than integrating \nthe system of equations defining the state differential. Further, time itself need not be directly expressed, an \nessential parameter for non-autonomous systems. The equivalence holds\n\n\\begin{equation} \\label{equ:cequ}\n\\begin{bmatrix}\n\\dot x \\\\\nt\n\\end{bmatrix} = \n\\begin{bmatrix}\ng(t, x, u; p) \\\\\n1\n\\end{bmatrix} \\iff \\dot x = g(t, x, u;p) .\n\\end{equation}\n\nHowever, for the sake of implementation, it is advantageous to express the time parameter directly. To use \nthis form, all \\acrshort{csaf}  components require two functions, \n\n\\begin{equation} \\label{equ:dequ}\n\\begin{aligned}\ng(.,.,.;p):& \\mathbb F \\times \\mathbb R^N \\times \\mathbb R^M \\rightarrow \\mathbb R^N \\\\\nh(.,.,.;r):& \\mathbb F \\times \\mathbb R^N \\times \\mathbb R^M \\rightarrow \\mathbb R^D\n\\end{aligned}.\n\\end{equation}\n\nFor continuous time solution of a single component, the function $g(.,.,u(.);p)$ is of a form that common \n\\acrshort{ode} solvers can evaluate. The parameters $r$ and $p$ don't necessarily need to be elements of a \nvector space, and can be described using other structures.\n\n\\subsubsection{Linear System Representation}\n\nA linear system can take the form,\n\n\\begin{equation} \\label{equ:linsys}\n\\begin{cases}\n\\dot{x} = A x + B u \\\\\ny =C x + D u \\\\\n\\end{cases},\n\\end{equation}\n\nwhere $x$ is in the state space and $u$ is in the input space. $A$, $B$, $C$, and $D$ are matrices \nrepresenting linear transformations.   \\\\\n\nFor a controlled system, the forcing input $u$ can be the result of a control policy. A control policy itself can\nbe dependent of the state vector $x$, as is the case for a state space controller. A linear controller follows a\nlinear control policy,\n\n\\begin{equation}\nu = K (x_d -x ) = -Ke,\n\\end{equation}\n\nwhere $K$ is some linear operator and $e=x -x_d$ represents an error signal from a desired state $x_d$. This \nrepresentation is commonly used, and controller design methods like \\acrshort{lqr} and \\acrshort{hinf} \nmethods, produce an operator $K$ that optimizes some notion of cost. From this view, it is clear that the \ncontroller is itself a linear system, possessing no state and an input vector $e$. To match the linear \nrepresentation in Equation \\ref{equ:linsys},\n\n\\begin{equation}\n\\begin{cases}\n\\dot{w} = \\mathbf{0} w + e \\\\\nu = -K e + G w \\\\\n\\end{cases}\n\\end{equation}\n\nThe effect of $w$ is to integrate $e$ with respect to time. This system can represent controllers with tracking\nproperties, like a \\acrshort{pid} controller.\n\n\\subsubsection{Neural Controller Representation}\\label{sec:nnc}\n\nNeural networks can be used to produce the functions $g$ and $h$ of a controller system, being trained \nbeforehand and operating feedforward during use. In this, no distinction is made is made in the representation. \\\\\n\n\\subsubsection{Fuzzy Logic Controller Representation}\\label{sec:flc}\n\nA fuzzy logic controller is a controller that uses a \\acrlong{fls} to determine its output. Generally, this involves \ntaking the input and transforming them to linguistic variables $(x_i, x_2, ..., x_{n_i}) \\in \\mathbb U^{n_i}$. Then, \nan inference rule $\\mathbb R^j$ can be applied from a rules base to produce a linguistic variable describing \nthe controller output, being a non-linear mapping between two fuzzy sets $\\mathbb U \\rightarrow \\mathbb R$. \n\\begin{equation}\n\\mathbb{R}^{(j)}:\\text{ IF }x_{1}\\text{ is }A_{1}^{j}\\text{ and }\\ldots\\text{ and }x_{n i}\\text{ is }A_{n i}^{j}\\text{ THEN }y\\text{ is }B^{j}, j=1, \\ldots, n_{j},\n\\end{equation}\nwhere $A_i^j$, $B^j$ are fuzzy sets in $\\mathbb U$ and $\\mathbb R$. This set can be ``defuzzified'' into a crisp value $y \\in \\mathbb R$ to produce a control signal. \\\\\n\nA controller adhering to this paradigm is stateless, and need only implement the output mapping $h$\nmentioned previously that performs the fuzzification, inference, and defuzzification. Besides this, the fuzzy \nsets that the input and output assume, the fuzzication/defuzzification startegies, and the inference rules employed, are necessary for the fuzzy logic controller representation.\n\n\\subsection{Model Interfaces}\n\nA concept of a model is derived from the representations in \\ref{equ:cequ} and \\ref{equ:dequ}. Figure \\ref{fig:mio} presents the IO relationships of a \\acrshort{csaf} model. The function arguments serve as the input, and evaluations of $g$ and $h$ can be the output.  A third output, labeled ``info'' is available to pass specific information about the model representation (such as the ones seen in \\ref{sec:flc} and \\ref{sec:nnc}). Note that the model does not use any time varying parameter as a state, requiring all such quantities having to be passed manually. The state of a dynamical system does not serve as a state represented by the programmatic object model. Time invariant parameters are states in the object and settable. \n\n\\begin{figure}\n\\centering\n\\includegraphics[width=1.0\\textwidth]{model.pdf}\n\\caption{\\acrshort{csaf} Model IO. A model requires time, state, and input to be passed in order to collect output. A model can have associated parameters that can be passed in once and set.}\n\\label{fig:mio}\n\\end{figure}\n\n\\subsection{Component Interfaces}\n\nA component is an object that presents a model as an element of a publish/subscribe architecture, with it IO diagram presented in Figure \\ref{fig:cio}. It subscribes to topics received by its input sockets. For normal inputs, the messages received are deserialized into a control signal that is stored into an input buffer. This buffer stores the necessary members to update a system represented by a \\acrshort{csaf} model object. The model output is serialized into a collection of output messages, and then send over a single output socket.\\\\\n\nAn events socket is also required (input c); messages can be sent in order to configure the component internals. These actions are\n\n\\begin{enumerate}\n\\item reset the buffers to default\n\\item configure buffer defaults\n\\item enable debugging\n\\item pause/resume the component\n\\item update the component\n\\item delete the component, unbinding/disconnecting any ports\n\\end{enumerate}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=1.0\\textwidth]{componentio.pdf}\n\\caption{\\acrshort{csaf}  Component IO. For input, sockets receive a message with specific topics. The output is a single socket, producing messages with different topics.}\n\\label{fig:cio}\n\\end{figure}\n\n\\subsection{System Description/Initialization}\n\nOnce valid components are made, they can be composed together to make systems. This composition can be described in a TOML file (Code Block \\ref{fig:sysset}). \n\n\\begin{figure}\n\\begin{lstlisting}\nname = \"inverted-pendulum\"\n\n# directory setup\ncodec_dir = \"codec\"\noutput_dir = \"output\"\n\n# order to construct/evaluate components \nevaluation_order = [\"maneuver\", \"controller\", \"plant\"]\n\n# log setup\nlog_file = \"inv_pendulum.log\"\nlog_level = \"info\"\n\n# port to broadcast events to the components\nevents_port = 6001\n\n[components]\n\n  [components.controller]\n    # environment to run under\n    run_command = \"python3\"\n\n    # path to model executable\n    process = \"ipcontroller.py\"\n\n    # whether to print debug diagnostics\n    debug = false\n\n    # subscribe to topic of a component (component name, topic name)\n    sub = [[\"plant\", \"states\"], [\"maneuver\", \"outputs\"]]\n\n    # port to publish\n    pub = 5502\n\n  [components.plant]\n    run_command = \"python3\"\n    process = \"ipplant.py\"\n    debug = false\n    sub = [[\"controller\", \"outputs\"]]\n    pub = 5501\n\n  [components.maneuver]\n    run_command = \"python3\"\n    process = \"ipmaneuver.py\"\n    debug = false\n    sub = []\n    pub = 5503\n\\end{lstlisting}\n\\caption{Example TOML File Describing Components and System Compositions of Components}\n\\label{fig:sysset}\n\\end{figure}\n\n\\section{Communications Interfaces}\n\nAnalyzers and simulators will interact with the system components via \\acrshort{0mq}, using sockets. \\acrshort{0mq} \nprovides \\acrshort{csaf}  with a variety of levels to communicate with components, whether in-process, \ninter-process or across TCP and multi-cast. The component does hold state, and the system needs to be \nproperly initialized to avoid staleness.\n\n\\subsection{Message Contents}\n\nThe temporal messages are sent by every \\acrshort{csaf}  component that represent vectors. The message type is derived from the \\acrshort{ros}msgs serialization format. First, the the \n\\acrshort{csaf}  version is transmitted to avoid incompatibility between components made with different \nversions. Second, system time is included to ensure that components evaluate  \ncorrectly. Next is the vector. These vectors are enumerated under a header, rather than transmitted as a \ncontiguous array. Figure \\ref{fig:cmsg} shows an example message. \\\\\n\nNon-temporal aspects of the system need to need to be accessed, which is described in a configuration file associated with a component. The system name, parameters, representation identifier and solver name is included. Two booleans are used to determine if the system type---continuous, discrete or hybrid.  Fields specific to the representation of the system is  accessible. For example, if the system is a fuzzy controller, the inference table can be visible. As the  components have a varying degree of transparency (``black box''), no headers are required and parameters are allowed to unchangeable. \\\\\n\nA controller's representation and purpose influences its requirements. As such, much \nvariability can exist in what is contained in the message. New headers and variables are allowed to appear in a \ncomponent message, but the structure has to remain constant over time. \\\\\n\n\\begin{figure}\n\\begin{lstlisting}\nuint32 version_major\nuint32 version_minor\n\nstring topic\n\nfloat64 time\n\\end{lstlisting}\n\\caption{Required \\acrshort{ros}msg \\acrshort{csaf}  Component Temporal Message Contents (Other Fields are Permitted)}\n\\label{fig:cmsg}\n\\end{figure}\n\n\\begin{figure}\n\\begin{lstlisting}\nsystem_name = \"Inverted Pendulum Plant\"\nsystem_representation = \"black box\"\nsystem_solver = \"Euler\"\n\nsampling_frequency = 100\n\nis_discrete = false\nis_hybrid = false\n\n[parameters]\n  mm = 0.5        # Mass of the cart\n  m = 0.2         # Mass of the pendulum\n  b = 0.1         # coefficient of friction on cart\n  ii = 0.006      # Mass Moment of Inertia on Pendulum\n  g = 9.8         # Gravitational acceleration\n  length = 0.3    # length of pendulum\n\n[inputs]\n  msgs = [\"ipcontroller_output.msg\"]\n\n[topics]\n\n  [topics.states]\n    msg = \"ipplant_state.msg\"\n    initial = [0.0, 0.01, 0.52 , -0.01]\n\\end{lstlisting}\n\\caption{ \\acrshort{csaf}  Component Configuration Information)}\n\\label{fig:cmsg}\n\\end{figure}\n\n", "meta": {"hexsha": "4fe58ff461577234248584411915495e51ee3138", "size": 12825, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/srs/chapters/requirements.tex", "max_stars_repo_name": "ZikangXiong/csaf", "max_stars_repo_head_hexsha": "2f03550d3c5e4b70ba3dd036bd49eb93684dcb78", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/srs/chapters/requirements.tex", "max_issues_repo_name": "ZikangXiong/csaf", "max_issues_repo_head_hexsha": "2f03550d3c5e4b70ba3dd036bd49eb93684dcb78", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/srs/chapters/requirements.tex", "max_forks_repo_name": "ZikangXiong/csaf", "max_forks_repo_head_hexsha": "2f03550d3c5e4b70ba3dd036bd49eb93684dcb78", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.53125, "max_line_length": 735, "alphanum_fraction": 0.7510331384, "num_tokens": 3303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7080360410101698}}
{"text": "\n\\subsection{Arithmetic Logic Units (ALUs)}\n\n\\subsubsection{Half adder}\n\nWe first introduce the half adder\n\nTake two inputs \\(A\\) and \\(B\\) and put both inputs to two binary operators.\n\nThe operators are an XOR gate and an AND gate.\n\nThe AND gate only returns \\(1\\) if both inputs are \\(1\\). The XOR gate returns \\(1\\) if only one input is \\(1\\).\n\nThe XOR gate returns the second “digit” while the AND date returns the first.\n\n\\subsubsection{Full adder}\n\nThis can be used to add \\(0\\) and \\(1\\), but not larger numbers. To do this we introduce the full adder. This adds two numbers, as before, and allows any remainder from the previous addition to be carried forward.\n\nFull adders can be stringed together to add larger numbers.\t\n\n\\subsubsection{Subtraction}\n\nSubtraction works similarly to addition. The equivalent “half adder” returns different values, and the carry forward is not used for addition, but for subtraction.\n\n\n\\subsection{Multiplication and division of natural numbers}\n\nmult x2 is bitshiftleft, /2 is bitshift right) (how to divide when not divisible)\n\n\\subsection{Mod and remainders}\n\n\\subsection{Powers, logarithms and exponentials}\n\n", "meta": {"hexsha": "cd803efb5d3910435650062efb7b1afb0805b644", "size": 1154, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/numbers/01-02-ALU.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/computer/numbers/01-02-ALU.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/computer/numbers/01-02-ALU.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.9714285714, "max_line_length": 213, "alphanum_fraction": 0.7616984402, "num_tokens": 272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302033, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.708036028376184}}
{"text": "\\chapter{Nonparametric Density Estimation}\nThis chapter is under \\work.\n\\section{Histogram}\nLet $x_1,\\ldots,x_n$ be independent and identically distributed samples from a univariate continuous RV $X$ with density $f$. The simplest nonparametric estimator for $f$ is the histogram.  It has some serious drawbacks.  We have encountered the histogram earlier in \\ref{S:ExploringData}.  During that encounter we chose the number of bins in an {\\em ad hoc} fashion, often resorting to the default number of bins of $10$ in {\\sc Matlab}'s {\\tt hist} function.\n\nA bin width that is too small when the number of bins is too large will give a histogram with many empty bins and many bins containing only a single data point.  This is referred as {\\em under-smoothing}.  At the other extreme, a bin width that is too large due to a small number of bins results in a histogram that lacks details and results in {\\em over-smoothing}.  In both of these situations, the histograms do not represent the underlying density well.\n\n\\begin{definition}[Density Histogram]\nLet $x_1,\\ldots,x_n$ be a random univariate sample with density $f$ and let $S_f$ be the support of $f$. Let $S_x\\subset S_f$ be a connected interval containing $x_1,\\ldots,x_n$ and let $\\{B_1,\\ldots,B_m\\}$ be a finite contiguous partition of $S_x$ into $m$ bins of equal width $b$. For $x\\in S_x$ and $B\\in \\{B_1,\\ldots,B_m\\}$, let $B(x)$ denote the bin that contains $x$. The {\\it density histogram} for $x_1,\\ldots,x_n$ with {\\it bin width} $b$ is:\n\\begin{equation}\n\\widehat{f}_n(x,b)=\\frac{1}{nb}\\sum^n_{i=1}I_{B(x)}(x_i).\n\\end{equation}\n\\end{definition}\n\nHence, the density at $x$ is estimated by counting the number of sample points in the bin containing $x$, and then appropriately normalising this number so that the area covered by the histogram is 1.\n\n%Consider the $a$-parametric family of the stretched oscillating exponential density with $\\lambda = 9/20$, $\\epsilon=1/2$:\n%\\[\n%f_a(x) = a^{ {\\lambda}^{-1} }{\\Gamma (1+ {\\lambda}^{-1})} \\, \\exp \\{- a x^{\\lambda} \\}\n%\\left( 1 + \\epsilon \\, \\sin ( a \\, x^{\\lambda} \\, \\tan( \\lambda \\pi  ) ) \\right)\n%\\]\n\nNow, let us consider the problem of estimating a histogram from $1500$ samples simulated from the equi-weighted mixture of $\\normal(0,5^2)$, $\\normal(10,1)$ and $\\normal(-10,1)$ using the following code:\n\\begin{VrbM}\nrand('twister',6898962)\nrandn('state',23121);\nA=ceil(3*rand(1,2000));% Mixture Label vector\nMuSs=[0 5; 10 2; -10 2]%; 5 2; -5 2]\nx=arrayfun(@(i)(MuSs(i,1)+MuSs(i,2)*randn),A);\nxgrid=-20:1:20;\npdf=NormalPdf(xgrid,MuSs(1,1),(MuSs(1,2))^2)/3 + NormalPdf(xgrid,MuSs(2,1),(MuSs(2,2))^2)/3 ...\n    + NormalPdf(xgrid,MuSs(3,1),(MuSs(3,2))^2)/3;\n\\end{VrbM}\n\n\\begin{figure}[htpb]\n\\caption{Histogram estimates for the  with nine different bin-widths of $\\{2,4,6,8,11,14,17,20,35\\}$.  The fifth histogram with a bin-width of $11$ is the optimal one with the right amount of smoothing.  The ones with smaller bin-widths are under-smoothed and those with larger bin-widths are over-smoothed.\\label{F:Gauss3MixHistsCV}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/Gauss3MixHistsCV}}\n\\end{figure}\n\n\\subsubsection{Drawbacks of the histogram}\n\\begin{asparaenum}[(a)]\n\\item While densities of continuous random variables are continuous, the histogram is a step function with discontinuities.\n\n\\item The histogram does not use data efficiently\\footnote{With an optimally chosen bin width, the mean integrated squared error, $E[\\int [\\widehat{f}_n(x,b)-f(x)]^2dx]$, converges to 0 at a rate of $n^{-2/3}$.}.\n\n\\item Although only one parameter, the bin width, appears explicitly in the definition of the histogram, the use of the histogram requires the specification of a second parameter. This is the placement of the leftmost bin edge, which can strongly affect the resulting histogram.\n\\end{asparaenum}\n\nBecause of these drawbacks, the histogram should only be used as a graphical tool for exploratory data analysis.\n\n\n\\subsubsection{Selection of histogram bin width}\n\\begin{asparaenum}[(a)]\n\\item\t{\\it Sturges' rule}: The number of bins is given by:\n\\begin{equation}\nm=ceil(1+\\log_2n).\n\\end{equation}\nIn practice, the bin width is usually obtained by:\n\\begin{equation}\nb=\\frac{x_{(n)}-x_{(l)}}{m}.\n\\end{equation}\n\\item\t{\\it Scott's normal reference rule}:\n\\begin{equation}\nb=3.5\\widehat{\\sigma}n_{-1/3},\n\\end{equation}\n\nwhere $\\widehat{\\sigma}$ is the sample standard deviation.\n\n\\item\t{\\it Freedman-Diaconis' rule}:\n\\begin{equation}\nb=2(\\widehat{q}_{0.75}-\\widehat{q}_{0.25})n^{-1/3},\n\\end{equation}\nwhere $\\widehat{q}_p$ is the sample $p$-quantile.\\\\\nWith Scott's bin width or Freedman-Diaconis' bin width, the number of bins can be obtained by:\n\\begin{equation}\nm= \\lceil \\left(\\frac{x_{(n)}-x_{(1)}}{b}\\right) \\rceil.\n\\end{equation}\n\\end{asparaenum}\n\nIn practice, these methods for determining bin width should be used as starting points for trying several possible bin widths, with the final bin width chosen by visual inspection of the resulting histograms.\n\nA suggestion for the placement of the leftmost bin edge is to use a {\\em centred histogram}. For a histogram with $m$ bins and bin width $b$, $mb\\geq x_{(n)}-x_{(1)}$, and so let:\n\\begin{equation}\n\\delta=mb-(x_{(n)}-x_{(1)}).\n\\end{equation}\n\nTo get the centred histogram, place the leftmost bin edge at $x_{(1)}-\\delta/2$, so that the histogram extends equally by $\\delta/2$ beyond the smallest and largest data values.\n\\subsubsection{{\\sc Matlab} function for density histogram}\n\n\\VrbMf[label=histogram.m]{scripts/histogram.m}\n%\\begin{VrbM}\n%% histogram.m\n%% Plots density histogram for data in X.\n%%\n%% Usage: histogram(X, plot data, bounds, colour, bwmethod, bw);\n%%\n%% Input: X = row vector of data,\n%%        plotdata (binary) = plot data points?\n%%        bounds = [lower bound , upper bound] for possible X values,\n%%        colour (single-character string) = colour of histogram (default =\n%%        'y' for yellow),\n%%        bwmethod (optional, default = 2) = method of computing bin width:\n%%                 0 = Scott's normal reference rule,\n%%                 1 = Wand's one-stage rule,\n%%                 2 = Wand's two-stage rule,\n%%                 3 = manual,\n%%        bw = manual bin width if bwmethod = 3.\n%%\n%% Remark: Bin origin determined by centring the histogram, i.e. so that\n%% left and right bin edges extend beyond min(X) and max(X) respectively\n%% by equal amounts.\n%%\n%% Reference: Wand M.P. (1997), \"Data-based choice of histogram bin width\",\n%% American Statistician 51, 59-64.\n%\\end{VrbM}\n\n%\\begin{example}[Shuttle Data] Joint temperatures of the O-rings for each test firing or actual launch of the space shuttle rocket motor are shown in the table below (from {\\it Presidential Commission on the Space Shuttle Challenger Accident}).\n%\\begin{center}\n%\\begin{tabular}{|cccccccccc|}\\hline\n%\\multicolumn{10}{|c|}{ O-ring temperatures ($^o$F)}\\\\\\hline\n%31   &  40&     45   &  49&     52   &  53&     57  &   58&     58  &   60\\\\\n%61   &  61 &    63  &   66 &    67  &   67 &    67 &    67 &    68 &    69\\\\\n%70    & 70  &   70 &    70  &   72 &    73  &   75&     75  &   76&     76\\\\\n%78     &79   &  80&     81   &  83&     84&&&&\\\\\\hline\n%\\end{tabular}\n%\\end{center}\n%%\\includegraphics\n%\\end{example}\n\n%%% Dominic's material here\n%\\chapter{Density estimation}\n%%\\section{Histogram}\n%WORK - fuse with previous material\nLet $x_1,\\ldots,x_n$ be a random univariate sample from a continuous distribution with density $f$. The most common nonparametric estimator for $f$ is the histogram, which has some serious drawbacks.\n\\subsection{\\define}Let $x_1,\\ldots,x_n$ be a random univariate sample with density $f$ and let $S_f$ be the support of $f$. Let $S_x\\subset S_f$ be a connected interval containing $x_1,\\ldots,x_n$ and let $\\{B_1,\\ldots,B_m\\}$ be a finite contiguous partition of $S_x$ into $m$ bins of equal width $b$. For $x\\in S_x$ and $B\\in \\{B_1,\\ldots,B_m\\}$, let $B(x)$ denote the bin that contains $x$. The {\\it density histogram} for $x_1,\\ldots,x_n$ with {\\it bin width} $b$ is:\n\\begin{equation}\n\\hat{f}_H(x,b)=\\frac{1}{nb}\\sum^n_{i=1}I_{B(x)}(x_i).\n\\end{equation}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\nHence, the density at $x$ is estimated by counting the number of sample points in the bin containing $x$, and then appropriately normalising this number so that the area of the histogram equals 1.\n\n\\begin{example}\nSuppose $x_1,\\ldots,x_{500}$ is a random sample drawn from the standard normal distribution. A histogram for $x_1,\\ldots,x_{500}$ is shown in the figure:\n%\\includegraphics\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{example}\n\n\\subsection{Drawbacks of the histogram}\n\\begin{asparaenum}[(a)]\n\\item While densities of continuous random variables are continuous, the histogram is a step function with discontinuities.\n\n\\item The histogram does not use data efficiently\\footnote{With an optimally chosen bin width, the mean integrated squared error, $E[\\int [\\hat{f}_H(x,b)-f(x)]^2dx]$, converges to 0 at a rate of $n^{-2/3}$.}.\n\n\\item Although only one parameter, the bin width, appears explicitly in the definition of the histogram, the use of the histogram requires the specification of a second parameter. This is the placement of the leftmost bin edge, which can strongly affect the resulting histogram.\n\\end{asparaenum}\nBecause of these drawbacks, the histogram should only be used as a graphical tool for exploratory analysis.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\n\\subsection{Selection of histogram bin width}\n\\begin{asparaenum}[(a)]\n\\item\t{\\it Sturges' rule}: The number of bins is given by:\n\\begin{equation}\nm=ceil(1+\\log_2n).\n\\end{equation}\nIn practice, the bin width is usually obtained by:\n\\begin{equation}\nb=\\frac{x_{(n)}-x_{(l)}}{m}.\n\\end{equation}\n\\item\t{\\it Scott's normal reference rule}:\n\\begin{equation}\nb=3.5\\hat{\\sigma}n^{-1/3},\n\\end{equation}\n\nwhere $\\hat{\\sigma}$ is the sample standard deviation.\n\n\\item\t{\\it Freedman-Diaconis' rule}:\n\\begin{equation}\nb=2(\\hat{q}_{0.75}-\\hat{q}_{0.25})n^{-1/3},\n\\end{equation}\nwhere $\\hat{q}_p$ is the sample $p$-quantile.\\\\\nWith Scott's bin width or Freedman-Diaconis' bin width, the number of bins can be obtained by:\n\\begin{equation}\nm=ceil\\left(\\frac{x_{(n)}-x_{(l)}}{b}\\right).\n\\end{equation}\n\\end{asparaenum}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\nIn practice, these methods for determining bin width should be used as starting points for trying several possible bin widths, with the final bin width chosen by visual inspection of the resulting histograms. A bin width that is too small will give a histogram with many empty bins and many bins containing only a single data point. At the other extreme, a bin width that is too large results in a histogram that lacks details. In both of these situations, the histograms do not represent the underlying density well.\n\n\\begin{example}[Shuttle data]\nJoint temperatures of the O-rings for each test firing or actual launch of the space shuttle rocket motor are shown in the table below (from {\\it Presidential Commission on the Space Shuttle Challenger Accident}).\n\\begin{center}\n\\begin{tabular}{|cccccccccc|}\\hline\n\\multicolumn{10}{|c|}{ O-ring temperatures ($^o$F)}\\\\\\hline\n31   &  40&     45   &  49&     52   &  53&     57  &   58&     58  &   60\\\\\n61   &  61 &    63  &   66 &    67  &   67 &    67 &    67 &    68 &    69\\\\\n70    & 70  &   70 &    70  &   72 &    73  &   75&     75  &   76&     76\\\\\n78     &79   &  80&     81   &  83&     84&&&&\\\\\\hline\n\\end{tabular}\n\\end{center}\n%\\includegraphics\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{example}\n\nA suggestion for the placement of the leftmost bin edge is to use a \\textquotedblleft centred histogram\". For a histogram with $m$ bins and bin width $b$, $mb\\geq x_{(n)}-x_{(l)}$, and so let:\n\\begin{equation}\n\\delta=mb-(x_{(n)}-x_{(l)}).\n\\end{equation}\n\nTo get the centred histogram, place the leftmost bin edge at $x_{(l)}-\\delta/2$, so that the histogram extends equally by $\\delta/2$ beyond the smallest and largest data values.\n%\\subsection{\\Matlab {\\it function for density histogram.}}\n%\\begin{VrbM}\n%% histogram.m\n%% Plots density histogram for data in X.\n%%\n%% Usage: histogram(X, plot data, bounds, colour, bwmethod, bw);\n%%\n%% Input: X = row vector of data,\n%%        plotdata (binary) = plot data points?\n%%        bounds = [lower bound , upper bound] for possible X values,\n%%        colour (single-character string) = colour of histogram (default =\n%%        'y' for yellow),\n%%        bwmethod (optional, default = 2) = method of computing bin width:\n%%                 0 = Scott's normal reference rule,\n%%                 1 = Wand's one-stage rule,\n%%                 2 = Wand's two-stage rule,\n%%                 3 = manual,\n%%        bw = manual bin width if bwmethod = 3.\n%%\n%% Remark: Bin origin determined by centring the histogram, i.e. so that\n%% left and right bin edges extend beyond min(X) and max(X) respectively\n%% by equal amounts.\n%%\n%% Reference: Wand M.P. (1997), \"Data-based choice of histogram bin width\",\n%% American Statistician 51, 59-64.\n%\\end{VrbM}\n\n\\section{Kernel density estimation}\nThe {\\it kernel density estimator} is a nonparametric estimator for $f$ that is continuous, uses data more efficiently than the histogram, and has only one parameter.\n\n\\begin{definition}\nLet $x_1,\\ldots,x_n$ be a random univariate sample with density $f$, and let $K$ be a function satisfying:\n\\begin{equation}\n\\int K(x)dx=1.\n\\end{equation}\n\nThe {\\it kernel density estimator} for $f$ with bandwidth $h > 0$ and kernel $K$ is:\n\\begin{equation}\n\\hat{f}_K(x,h)=\\frac{1}{nh}\\sum^n_{i=1}K\\left(\\frac{x-x_i}{h}\\right).\n\\end{equation}\n\nWe shall consider kernel functions that are densities and define:\n\\begin{equation}\nK_h(x)=\\frac{1}{h}K\\left(\\frac{x}{h}\\right),\n\\end{equation}\nand so the kernel density estimator can be expressed as:\n\\begin{equation}\n\\hat{f}_K(x,h)=\\frac{1}{n}\\sum^n_{i=1}K_h(x-x_i),\n\\end{equation}\nwhich is a proper density.\n\\end{definition}\n\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\subsection{Examples of kernel functions}\n\n\\begin{table}[tbh]\n\\centering\n$$\\begin{array}{|c|c|c|c|}\\hline\n\\textrm{Name}&\tK(x)\t&\\textrm{Efficiency}&\\sigma_K\\\\\nEpanechnikov\t&\\frac{3}{4}(1-x^2)I_{[-1,1]}(x)&1&\\frac{1}{\\sqrt{5}}\t \\\\\nBiweight\t &\\frac{15}{16}(1-x^2)^2I_{[-1,1]}(x)&0.994\t &\\frac{1}{\\sqrt{7}}\\\\\nTriweight\t &\\frac{35}{32}(1-x^2)^3I_{[-1,1]}(x)&0.987\t &\\frac{1}{3}\\\\\nTriangle&(1-|x|)I_{[-1,1]}(x)&0.986\t &\\frac{1}{\\sqrt{6}}\\\\\nGaussian&\\frac{1}{\\sqrt{2\\pi}}\\exp\\left(-\\frac{x^2}{2}\\right)\t &0.951&\t1\\\\\nUniform&\\frac{1}{2}I_{[-1,1]}(x)&0.930&\\frac{1}{\\sqrt{3}}\t \\\\\\hline\n\\end{array}$$\n\\end{table}\n%\\includegraphics\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\nIt turns out that the choice of the kernel has little impact on the performance of the kernel density estimator, and so the convenient Gaussian kernel is a popular choice. The choice of bandwidth, on the other hand, is critical.\n\n\\begin{prop}\nLet $\\sigma^2_K$ be the variance of kernel function $K$. The variance of $K_h(x)$ is $h^2\\sigma^2_K$.\n\n\\begin{proof}\nSince $K_h(x)$ has mean 0, its variance is:\n$$ \\sigma_K^2=\\int x^2K_h(x)dx=\\frac{1}{h}\\int x^2K(x/h)dx=h^2\\int (x/h)^2K(x/h)d(x/h)=h^2\\sigma^2_K.$$\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{proof}\n\\end{prop}\n\nNote that for the Gaussian kernel, $\\sigma_K=1$, and therefore $\\sigma_K=h$; i.e. the standard deviation of $K_h$ is equal to its bandwidth.\n\n\\begin{labwork}\nUsing the same standard normal sample from Example 5.1.2, the density estimate obtained from a Gaussian kernel density estimator (with bandwidth 0.3) is shown in the figure, along with the histogram obtained previously.\n%\\includegraphics\n%\\Matlab code:\n\\begin{VrbM}\nn = 500;\nx = randn(1,n);\nbw = 0.3;\ns = [-3:0.01:3]; % support points to compute density\nf = normpdf(s,0,1); % true N(0,1) density\nns = length(s); % number of support points\nfker = zeros(1,ns); % storage for kernel density\nfor i = 1:ns\n    fker(i) = mean(normpdf(s(i),x,bw));\nend\nhistogram(x,0,[-inf inf],'g'); hold on\nplot(s,f,':r',s,fker,'-r')\n\\end{VrbM}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{labwork}\n\nWe can think of the kernel as spreading a probability mass of $1/n$ associated with each sample point around its neighbourhood. To see what the Gaussian kernel density estimator does, suppose we have only five sample points, $x_1,\\ldots,x_5$. The estimator puts a normal density with variance $h^2$ and a probability mass of $1/n$ at each sample point, and estimates the density at support point $x$ by summing the contributions from these normal densities at $x$. This is illustrated in the figure, where the sample points are marked by \\textquoteleft x' on the support axis, the dashed curves are the normal densities whose probability masses are scaled to $1/n$, and the solid curve is the estimated density.\n%\\includegraphics\n\nIf f is continuous at $x$ and $h\\rightarrow 0$ and $nh\\rightarrow\\infty$ as $n\\rightarrow\\infty$, then for any $\\epsilon > 0$:\n\\begin{equation}\n\\lim_{n\\rightarrow\\infty}P(|\\hat{f}_K(x,h)-f(x)|\\leq\\epsilon)=1.\n\\end{equation}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\n\\subsection{Bandwidth selection}\nThe use of the kernel density estimator requires the specification of the bandwidth, which plays a similar role as the histogram's bin width. A practical and easy-to-use bandwidth choice for the Gaussian kernel is {\\it Scott's bandwidth}:\n\\begin{equation}\nh=\\hat{s}n^{-1/5},\n\\end{equation}\n\nwhere $\\hat{s}=\\min\\{\\hat{\\sigma},(\\hat{q}_{0.75}-\\hat{q}_{0.25})/1.348\\}$. A slightly different version\\footnote{This version is also known as the {\\it normal reference rule.}} of Scott's bandwidth is given by:\n\\begin{equation}\nh=1.06\\hat{s}n^{-1/5}.\n\\end{equation}\n\nSince the multiplicative constant of 1.06 is very close to 1, the two bandwidths are very close and we can use either of them.\n\nA more sophisticated bandwidth can be obtained by considering the minimisation of {\\it asymptotic mean integrated squared error}:\n\\begin{equation}\nAMISE=\\lim_{n\\rightarrow\\infty}E[\\int[\\hat{f}_K(x,h)-f(x)]^2dx].\n\\end{equation}\n\nUsing $R(g)$ to denote $\\int g(x)^2dx$, the resulting optimal bandwidth is given by:\n\\begin{equation}\nh_{AMISE}=\\left(\\frac{R(K)}{n\\sigma^4_KR(f^{\\prime\\prime})}\\right)^{1/5},\n\\end{equation}\n\nwhich depends on the unknown density $f$ through $R(f^{\\prime\\prime})$. An approximate bandwidth is obtained by plugging in an appropriate estimate of $R(f^{\\prime\\prime})$\\footnote{Sheather, S. J. and Jones, M. C. (1991), \\textquotedblleft A reliable data-based bandwidth selection method for kernel density estimation\", {\\it Journal of the Royal Statistical Society, Series B, 53, 683-690}.}.\n\nWith an optimally chosen bandwidth, the mean integrated squared error of the kernel density estimator converges to 0 at rate $n^{4/5}$.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\n%\\subsection{\\result}\nLet $K$ and $L$ be two kernel functions with standard deviations $\\sigma_K$ and $\\sigma_L$ respectively. Then for the resulting kernel densities to be approximately equal, their bandwidths, $h_K$ and $h_L$, must satisfy:\n\\begin{equation}\nh_K\\sigma_K\\approx h_L\\sigma_L,\n\\end{equation}\ni.e. the standard deviations of $K_h$ and $L_h$ must be approximately equal.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\nRecall that the standard deviation of the Gaussian kernel function is 1, so we can use this result to obtain the bandwidth for some other kernel, e.g. kernel function $K$, from the bandwidth of the Gaussian kernel:\n\\begin{equation}\nh_K\\approx \\frac{h_{gaussian}}{\\sigma_K}.\n\\end{equation}\n\nFor example, with the Epanechnikov kernel, $\\sigma_K=1/\\sqrt{5}$, and so Scott's bandwidth for the Epanechnikov kernel is:$$h_K\\approx\\sqrt{5}\\hat{s}n^{-1/5}.$$\n\n\\begin{labwork}\nThe data in {\\tt geyser.txt} are 107 durations (in minutes) of the eruptions of the Old Faithful geyser. Compare the kernel density estimates for eruption duration using the Gaussian and Epanechnikov kernels with Scott's bandwidth.\n\n%\\Matlab code:\n\\begin{VrbM}\nx = load('geyser.txt');\nn = length(x);\nn5 = n^(-0.2);\nhscottgauss = min(std(x),iqr(x)/1.348) * n5 % Scott's bandwidth for Gaussian\n\t\t\t% kernel\nhscottepan = sqrt(5) * hscottgauss % Scott's bandwidth for Epanechnikov kernel\n\\end{VrbM}\nResults:\n\\begin{VrbM}\nhscottgauss = 0.4087\nhscottepan = 0.9139\n\\end{VrbM}\n%\\includegraphics\n%\\caption{Kernel densities with Scott's bandwidth (solid curve) and optimal bandwidth (dashed curve).}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{labwork}\n\n\\subsection{Adjustment at boundaries}\nSuppose we need to estimate a density $f$ whose support $S_f$ is bounded at one or both ends; frequently, $S_f=(0,\\infty)$ or $S_f=(a,b)$. The presence of a boundary or boundaries may cause some of the kernels in the kernel density estimator to be truncated. Therefore, the estimator must be adjusted accordingly to ensure that the resulting estimate remains a density:\n\\begin{equation}\n\\hat{f}_K(x,h)=\\frac{1}{n}\\sum^n_{i=1}\\frac{K_h(x-x_i)}{p_i},\n\\end{equation}\nwhere:\n\\begin{equation}\np_i=\\int_SK_h(x-x_i)dx.\n\\end{equation}\n\nThus, $0<p_i\\leq 1$, and $p_i  = 1$ if the corresponding kernel is not truncated.\n\nIf the Gaussian kernel is used and letting $\\Phi(t;\\mu,\\sigma^2)$ denote the cumulative probability at $t$ of the normal distribution with mean $\\mu$ and variance $\\sigma^2$, then:\n\\begin{equation}\np_i=1-\\Phi(0;x_i,h^2),\n\\end{equation}\nwhen $S_f=(0,\\infty)$, and:\n\\begin{equation}\np_i=\\Phi(b;x_i,h^2)-\\Phi(a;x_i,h^2),\n\\end{equation}\nwhen $S_f=(a,b)$.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\n\\begin{labwork}\nLet $x_1,\\ldots,x_{100}$ be a sample from an exponential distribution with parameter 1. Recall the the support of the exponential distribution is $x \\geq 0$.\n%\\includegraphics\n%\\Matlab code:\n\\begin{VrbM}\nn = 100;\nx = exprnd(1,1,n); % n exponential(1) random variables\nn5 = n^(-0.2);\nh = min(std(x),iqr(x)/1.348) * n5; % Scott's bandwidth for Gaussian kernel\ns = [0:0.01:4]; % support points to compute density\nf = exppdf(s,1); % true exponential(1) density\nns = length(s); % number of support points\nfker1 = zeros(1,ns); % storage for kernel density without boundary correction\nfker2 = zeros(1,ns); % storage for kernel density with boundary correction\np = 1 - normcdf(0,x,h); % boundary correction factors\nfor i = 1:ns\n    fker1(i) = mean(normpdf(s(i),x,h)); % kernel density without boundary\n\t\t% correction\n    fker2(i) = mean(normpdf(s(i),x,h)./p); % kernel density with boundary\n\t\t% correction\nend\nplot(s,f,'-b',s,fker2,'--b',s,fker1,':b')\nlegend('true density','kernel density with correction','kernel density without correction')\n\\end{VrbM}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{labwork}\n\n\\section{Extension to multivariate data}\nThe extension of the kernel density estimator to multivariate data is straightforward.\n\n%\\begin{definition}\nLet $x_1,\\ldots,x_n$ be independent and identically distributed random $d$-vectors with $d$-dimensional density $f$. The kernel density estimator for $f$ is:\n\\begin{equation}\n\\hat{f}_K(x,H)=\\frac{1}{n|H|}\\sum^n_{i=1}K(H^{-1}(x-x_i)),\n\\end{equation}\nwhere $H$ is a $d \\times d$ nonsingular matrix, called the {\\it bandwidth matrix}, and the kernel function $K$ is a $d$-dimensional density. Let:\n\\begin{equation}\nK_H(x)=\\frac{K(H^{-1}x)}{|H|},\n\\end{equation}\n\nso that:\n\\begin{equation}\n\\hat{f}_K(x,H)=\\frac{1}{n}\\sum^n_{i=1}K_H(x-x_i).\n\\end{equation}\n\nThe kernel can be simplified by assuming that its components are independent (note that this does not make the components of $x$ independent). This simplifies the kernel matrix to a diagonal matrix with diagonal elements, $h_1,\\ldots,h_d$. The kernel can then be expressed as a product of univariate kernels:\n\\begin{equation}\nK_H(x)=K_{h_1,\\ldots,h_d}(x)=\\prod^d_{j=1}K_{h_j}[x(j)],\n\\end{equation}\nwhere $x(j)$ denotes the $j^{\\textrm{th}}$ component of $x$. This gives the {\\it product kernel density estimator}:\n\\begin{equation}\n\\hat{f}_K(x,h_1,\\ldots,h_d)=\\frac{1}{n}\\sum^n_{j=1}[\\prod^d_{j=1}K_{h_j}[x(j)-x_i(j)]].\n\\end{equation}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n%\\end{definition}\n\n\\subsection{Bandwidth selection}\nFor a product kernel density estimator with the Gaussian kernel, {\\it Scott's rule in d dimensions} is:\n\\begin{equation}\nh_j=\\hat{s}_jn^{-1/4+d},\n\\end{equation}\nwhere $\\hat{s}_j=\\min(\\hat{\\sigma}_j,(\\hat{q}_{0.75j}-\\hat{q}_{0.25j})/1.348)$ is the estimate of scale for the $j^{\\textrm{th}}$ component that has been computed from $x_1(j),\\ldots,x_n(j)$. For some other kernel, the required bandwidth may be obtained by dividing $h_j$ by the standard deviation of that kernel function, as in the univariate case.\n\nWith an optimally chosen bandwidth, the mean integrated squared error of the multivariate kernel density estimator converges to 0 at rate $n^{-4/(4+d)}$. Thus, its efficiency decreases rapidly with increasing dimension.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\n\\begin{labwork}\nThe file {\\tt nrl.txt} contains data from 42 rugby league matches.  The first column contains the length of game time, in seconds, until the first points are scored by a kick between the posts (penalty, drop goal or conversion); the second column contains the game time (in seconds) until the first try is scored. Denoting the log of the bivariate sample points by $(x_1,y_1),\\ldots,(x_42,y_42)$, the product Gaussian kernel density estimator for the bivariate density is:\n$$\\hat{f}_\\phi(x,y,h_x,h_y)=\\frac{1}{42}\\sum^{42}_{i=1}\\phi(x,x_i,h^2_x)\\phi(y,y_i,h_y^2).$$\n\nUsing Scott's rule:\n$$h_x=\\hat{s}_x\\times 42^{-1/6} \\textrm{  and   }h_y=\\hat{s}_y\\times 42^{-1/6}.$$\n%\\includegraphics\n%\\Matlab code:\n\\begin{VrbM}\ndata = load('nrl.txt');\nx = log(data(:,1))';\ny = log(data(:,2))';\nn = length(x);\n\n% scatter plot:\nplot(x,y,'.r')\nxlabel('x'), ylabel('y')\ntitle('Scatter plot')\naxis([3 9 3 9]), axis('square')\ndrawnow\n\nn6 = n^(-1/6);\nhx = min(std(x),iqr(x)/1.348) * n6;\nhy = min(std(y),iqr(y)/1.348) * n6;\ns = 3:.01:9;\nns = length(s);\nphix = zeros(n,ns);\nphiy = zeros(n,ns);\nfor i = 1:n\n    phix(i,:) = normpdf(s,x(i),hx);\n    phiy(i,:) = normpdf(s,y(i),hy);\nend\nfker = zeros(ns,ns);\nfor j = 1:ns\n    for i = 1:ns\n        fker(j,i) = phiy(:,j)' * phix(:,i) / n;\n    end\nend\n\n% 3-D surface plot:\nfigure, mesh(s,s,fker)\nxlabel('x'), ylabel('y'), zlabel('density')\ncolorbar, drawnow\n\n% contour plot:\nfigure, contourf(s,s,fker,20)\nxlabel('x'), ylabel('y')\ntitle('Contour plot')\ncolorbar, axis('square')\n\\end{VrbM}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{labwork}\n\n\\section{Smoothed bootstrap}\nThe {\\it smoothed bootstrap} is a variation of the bootstrap idea that is used for continuous data. Instead of estimating the distribution function by the EDF and obtaining bootstrap samples by random sampling with replacement from the data values, the smoothed bootstrap estimates the density by a kernel density and generates bootstrap samples from it. After getting the bootstrap samples, the MSE, variance, bias and confidence intervals can be computed for an estimator of interest, in the same way as in the nonparametric bootstrap. If the kernel density is a good estimate of the data density, then the smoothed bootstrap can give a small improvement over the nonparametric bootstrap for continuous data.\n\n\\subsection{Generating from a kernel density}\nLet:$$\\hat{f}_K(x,h)=\\frac{1}{n}\\sum^{n}_{i=1}K_h(x-x_i),$$\n be the kernel density.  To generate a new sample point from the kernel density, randomly pick one of the original data values, $x_1,\\ldots,x_n$. Suppose   is picked, generate the new sample point from the kernel centred on $x_i$, i.e. from $K_h(x-x_i)$.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\n\\begin{labwork}\nGenerate 1000 random values from the Gaussian kernel density, with Scott's bandwidth, for the geyser data.\n%\\Matlab code:\n\\begin{VrbM}\nm = 1000; % number of sample points to generate\nx = load('geyser.txt')';\nn = length(x);\nn5 = n^(-0.2);\nh = min(std(x),iqr(x)/1.348) * n5; % Scott's bandwidth for Gaussian kernel\nxcen = randsample(x,m,true); % randomly resample kernel centres from x\ny = normrnd(xcen,h); % generate from Gaussian kernels centred at xcen\nhistogram(y,0,[0 inf],'r');\n\\end{VrbM}\n%\\includegraphics\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{labwork}\n\n\\subsection{Smoothed bootstrap procedure for generating bootstrap samples}\nLet $x_1,\\ldots,x_n$ be IID random variables with unknown density $f(x)$.\n\\begin{asparaenum}[(a)]\n\\item Estimate the data density by a kernel density $\\hat{f}_K(x,h)$.\n\n\\item\tObtain $N$ bootstrap samples, each of size $n$, by generating from $\\hat{f}_K(x,h)$:\n$$\\begin{array}{c}\n\\{x_{1,1},\\ldots,x_{1,n}\\}\\sim\\hat{f}_K(x,h)\\\\\n\\textrm{M}\\\\\n\\{x_{N,1},\\ldots,x_{N,n}\\}\\sim\\hat{f}_K(x,h)\\\\\n\\end{array}$$\n\\end{asparaenum}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\n\\begin{labwork}\nLet us revisit Example 4.2.5 to obtain a 0.95 percentile interval for the median amount of sodium using the smoothed bootstrap with a Gaussian kernel density. Recall that the percentile interval provided by the nonparametric bootstrap was $(75.05, 77)$.\n\n%\\Matlab code:\n\\begin{VrbM}\nx = load('sodium.txt'); % load data from text file and store in x\nN = 100000; % number of bootstrap samples\nn = length(x); % determine number of data values\nnN = n * N;\nalpha = 0.05;\nalpha2 = alpha / 2;\nalpha21 = 1 - alpha2;\nn5 = n^(-0.2);\nh = min(std(x),iqr(x)/1.348) * n5; % Scott's bandwidth for Gaussian kernel\nxcen = randsample(x,nN,true); % randomly resample kernel centres from x\nxboot = normrnd(xcen,h); % generate from Gaussian kernels centred at xcen\nxboot = reshape(xboot,n,N); % organise resampled values into N columns of n\n                            \t\t% values each so that each column is a bootstrap\n                            \t\t% sample of size n\nxbootmed = median(xboot); % medians of bootstrap samples\nxbootmedsort = sort(xbootmed); % sort medians in increasing order\n\n% (1-alpha) percentile interval:\n[xbootmedsort(ceil(N*alpha2)) xbootmedsort(N*alpha21)]\n\\end{VrbM}\nResults:\n\\begin{VrbM}\nans = 74.8616   76.9451\n\\end{VrbM}\nTherefore, a 0.95 percentile interval for the median amount of sodium, using the smoothed bootstrap with a Gaussian kernel density, is $(74.86, 76.95)$.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{labwork}\n\n\nPoint-wise confidence band for density using the smoothed bootstrap (see Scott\\footnote{Scott, D.W. (1992), {\\it Multivariate Density Estimation: Theory, Practice and Visualization, Wiley.}} pp. 259-260; Hardle et al.\\footnote{Hardle, W., Muller, M., Sperlich, S. and Werwatz, A. (2004), {\\it Nonparametric and Semiparametric Models,} e-book at www.quantlet.com/mdstat/scripts/spm/html/spmhtmltoc.html}  section 3.5).\n\n\\section{Exercises}\n\n\\begin{exercise}\nConsider the two-component normal mixture density given by:\n$$f(x)=0.5\\phi(x,4,1)+0.5\\phi(x,9,4),$$\n\nwhere $\\phi(x,\\mu,\\sigma^2)$ denotes the normal density with mean $\\mu$ and variance $\\sigma$, evaluated at $x$.\n\\begin{asparaenum}[(a)]\n\\item A sample point, $x$, can be generated from the mixture density by the following algorithm:\n\\begin{tabbing}\nGene\\=rate $u \\sim U[0, 1]$.\\\\\nIf $u\\leq 0.5$\\\\\n\t\\>Generate $x \\sim N(4, 1)$\\\\\nElse\\\\\n\t\\>Generate $x \\sim N(9, 4)$.\\\\\n\\end{tabbing}\n\nImplement a \\Matlab function to generate from the mixture density and use it to get 100 sample points.\n\n\\item Using the 100 sample points from part (a), estimate the underlying density using a histogram with appropriate bin width. Explain clearly how you arrived at your choice of bin width.\n\n\\item Using the 100 sample points from part (a), estimate the underlying density using a Gaussian kernel density estimator. Explore bandwidths ranging from 0.3 to 1.9 to decide on an appropriate one.\n\\end{asparaenum}\n\\end{exercise}\n\n\\begin{exercise}\nThe Bart Simpson density is given by:\n$$f(x)=0.5\\phi(x,0,1)+0.1\\sum^4_{j=0}\\phi(x,0.5j-1,0.01).$$\n\nTo see why it is called the Bart Simpson density, plot the density for a sequence of x values from $-3$ to 3 (in steps of 0.01, for example).\n\\begin{asparaenum}[(a)]\n\\item Write a \\Matlab function to generate sample points from the Bart Simpson density and use it to obtain 1000 sample points.\n\\item Using the 1000 sample points from part (a), estimate the underlying density using a histogram with appropriate bin width. Explain clearly how you arrived at your choice of bin width.\n\\item Using the 1000 sample points from part (a), estimate the underlying density using a Gaussian kernel density estimator with bandwidths of 0.005, 0.05 and 0.5. Comment on the performance of each of these bandwidths.\n\\end{asparaenum}\n\\end{exercise}\n\n\\begin{exercise}\nThe data in {\\tt ceo.txt} contain the ages (column 1) and salaries (column 2, in thousands of dollars) of the CEOs of 59 companies.\n\\begin{asparaenum}[(a)]\n\\item Obtain a Gaussian kernel density estimate for the salaries, using Scott's bandwidth. Compare the transformation method and boundary correction method for handling the boundary at zero.\n\n\\item Use the nonparametric bootstrap to obtain a point-wise 0.95 BCA confidence band for the density of the salaries.\n\n\\end{asparaenum}\n\\end{exercise}\n\n\\begin{exercise}\nThe second column of {\\tt glass.txt} contains measurements of the refractive index of 214 glass specimens collected in forensic work.\n\\begin{asparaenum}[(a)]\n\\item Obtain a Gaussian kernel density estimate for refractive index, using Scott's bandwidth.\n\n\\item Use the nonparametric bootstrap to obtain a point-wise 0.95 BCA confidence band for the density of refractive index.\n\\end{asparaenum}\n\n\\end{exercise}\n\n\\begin{exercise}\nThe data in {\\tt whale.txt} are the times of 121 bowhead whale calf sightings during the 2001 spring migration. The time of each sighting is expressed as the number of hours since midnight of April 5, when the first adult whale was sighted.\n\\begin{asparaenum}[(a)]\n\\item Plot a density histogram for the data and superimpose onto it a Gaussian kernel density estimate. Explain your choice of histogram bin width and kernel density bandwidth. For the kernel density estimate, compare the transformation method and the boundary correction method for handling the boundary at zero.\n\n\\item Obtain a 0.95 BCA interval for the median sighting time, using the nonparametric bootstrap with 10,000 bootstrap samples.\n\n\\item Repeat Part (b) using the smoothed bootstrap with 10,000 bootstrap samples.\n\\end{asparaenum}\n\n\\end{exercise}\n\n\\begin{exercise}\nThe data in {\\tt density.txt} are 29 measurements of the density of the earth, which were made by Henry Cavendish in 1789.\n\\begin{asparaenum}[(a)]\n\\item Plot a density histogram for the data and superimpose onto it a Gaussian kernel density estimate. Explain your choice of histogram bin width and kernel density bandwidth. For the kernel density estimate, compare the transformation method and the boundary correction method for handling the boundary at zero.\n\\item Obtain a 0.95 BCA interval for the mean density of the earth, using the nonparametric bootstrap with 10,000 bootstrap samples.\n\\item Repeat Part (b) using the smoothed bootstrap with 10000 bootstrap samples.\n\\end{asparaenum}\n\n\\end{exercise}\n\n\\begin{exercise}\nWork through Example 5.3.3 for the NRL data.\n\\end{exercise}\n\n\\begin{exercise}\nThe data in {\\tt infrared.txt} are measurements of infrared emissions from 628 objects beyond our galaxy. The two columns contain total flux measurements for two different wavelength bands - the first column shows the 12 micrometre band and the second column shows the 100 micrometre band. Estimate the bivariate density for the log of the data using a product Gaussian kernel density estimator with Scott's bandwidth. Plot the estimated density using a three-dimensional surface plot and a two-dimensional contour plot.\n\\end{exercise} \n", "meta": {"hexsha": "50813c9513b85a75c5f4f150e8f9432e1a998d34", "size": 35686, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/DensityEstimation.tex", "max_stars_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_stars_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-19T07:54:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T13:55:18.000Z", "max_issues_repo_path": "matlab/csebook/DensityEstimation.tex", "max_issues_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_issues_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "matlab/csebook/DensityEstimation.tex", "max_forks_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_forks_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-07-18T07:47:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T11:28:24.000Z", "avg_line_length": 51.4949494949, "max_line_length": 711, "alphanum_fraction": 0.7171159558, "num_tokens": 10722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933403143929, "lm_q2_score": 0.8633916222765629, "lm_q1q2_score": 0.7078890411877937}}
{"text": "% ***********************************************************************************\n% Pure LaTeX part to be inserted in a document (be careful of depencies of packages & commands\n% Prepared by Qingan Zhao under the supervision of Arnaud de La Fortelle\n% Fall 2017\n% Example of solving the 2D heat diffusion subsection of the modeling part part\n% ***********************************************************************************\n\n\\subgroup{2}{Qingan Zhao}\n\n\\paragraph{Description}\nNow consider a retangular plane (length: a; width: b) with 2 boundaries that have no heat transfer (i.e., $T(x, 0)=f(x);\\ T(x, b)=g(x)$). The other two boundaries have fixed temperature ($T(0, y)=T(a, y)=0$). We would like to solve the PDE under the stationary state (i.e., $\\ud T/\\ud t=0$). The diagram of the system is shown in Figure~\\ref{heatSolSystem.fig}.\n\\begin{figure}[htb]\n\t\\centering\n\t\\includegraphics[width=10cm]{2dHeatSolDescription.pdf}       \n\t\\caption{System description of the example}\\label{heatSolSystem.fig}\n\\end{figure}\n\n\\paragraph{PDE and boundary conditions}\nFrom Section 2.2.2 we have already known that the 2D heat equation is:\n\\begin{equation}\n\\frac{\\partial T}{\\partial t}=a^2\\left(\\frac{\\partial ^2 T}{\\partial x^2}+\\frac{\\partial ^2 T}{\\partial y^2}\\right)\\ \\ \\ \\ where\\ a=\\sqrt{\\frac{k}{c\\rho}}\n\\end{equation}\n\n\nThe boundary conditions of this problem are as follows:\n\n\\begin{equation}\\label{2DHeatBound1.eq}\nT(x,0,t)=f(x)\n\\end{equation}\n\\begin{equation}\\label{2DHeatBound2.eq}\nT(x,b,t)=g(x)\n\\end{equation}\n\\begin{equation}\\label{2DHeatBound3.eq}\nT(0, y, t)=0\n\\end{equation}\n\\begin{equation}\\label{2DHeatBound4.eq}\nT(a, y, t)=0\n\\end{equation}\n\\begin{equation}\n\\frac{\\ud T}{\\ud t}=0\n\\end{equation}\n\n\\paragraph{Solution}\nSince the system is under the stationary state ($\\ud T/\\ud t=0$), $T(x,y,t)$ can be expressed as $T(x,y)$, and the PDE can be written as:\n\\begin{equation}\n\\frac{\\partial^2T}{\\partial x^2}+\\frac{\\partial^2T}{\\partial y^2}=0\n\\end{equation}\n\nWe could separate the variables by express $T(x,y)$ as $X(x)Y(y)$. Then the PDE can be written as:\n\\begin{equation}\nX''(x)Y(y)+X(x)Y''(y)=0\n\\end{equation}\n\nSince $X(x)Y(y)$ is not identically zero, divide both sides by $X(x)Y(y)$ gives:\n\\begin{equation}\n\\frac{X\"(x)}{X(x)}+\\frac{Y\"(y)}{Y(y)}=0\n\\end{equation}\n\nSince the two parts of the left side are independent, the following equations can be drawn ($\\lambda$ is a constant):\n\\begin{align}\nX\"(x)+\\lambda X(x)=0\\\\\nY\"(y)-\\lambda Y(y)=0\n\\end{align}\n\nMoreover, the boundary conditions Equations~(\\ref{2DHeatBound3.eq})-(\\ref{2DHeatBound4.eq}) give:\n\\begin{align}\nX(0)Y(y)=0\\\\\nX(a)Y(y)=0\n\\end{align}\n\nSince $Y(y)$ is not identically zero, we can obtain the following:\n\\begin{align}\nX(0)=0\\\\\nX(a)=0\n\\end{align}\n\nHence, the problem becomes solving two indenpendent ordinary differential equations. We know that only when $\\lambda=\\frac{n^2\\pi^2}{a^2}\\ (n=1,2,3,...)$, the problem has the following solution:\n\\begin{equation}\nX_n(x)=sin\\frac{n\\pi x}{a}\n\\end{equation}\n\\begin{equation}\nY_n(y)=a_ne^{\\frac{n\\pi}{a}y}+b_ne^{-\\frac{n\\pi}{a}y}\n\\end{equation}\n\nHence, the solution can be expressed as:\n\\begin{equation}\nT(x,y)=\\sum_{n=1}^{\\infty}(a_ne^{\\frac{n\\pi}{a}y}+b_ne^{-\\frac{n\\pi}{a}y})sin\\frac{n\\pi x}{a}\n\\end{equation}\n\nGiven the other two boundary conditions Equations~(\\ref{2DHeatBound1.eq})-(\\ref{2DHeatBound2.eq}), $a_n$ and $b_n$ can be solved using the following 2 equations:\n\\begin{equation}\na_n+b_n=\\int_{0}^{a}f(x)sin\\frac{n\\pi}{a}xdx\n\\end{equation}\n\\begin{equation}\na_ne^{\\frac{n\\pi}{a}b}+b_ne^{-\\frac{n\\pi}{a}b}=\\int_{0}^{a}g(x)sin\\frac{n\\pi}{a}xdx\n\\end{equation}\n\nThus, the analytical solution of this problem is obtained.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "245494546fd531a4bf14f662e7239a3f347ec04e", "size": 3668, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modeling-solving2Dheatdiffusion.tex", "max_stars_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_stars_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-08T02:54:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-29T06:19:28.000Z", "max_issues_repo_path": "modeling-solving2Dheatdiffusion.tex", "max_issues_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_issues_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "modeling-solving2Dheatdiffusion.tex", "max_forks_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_forks_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-16T17:29:03.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-16T17:29:03.000Z", "avg_line_length": 32.1754385965, "max_line_length": 361, "alphanum_fraction": 0.6646673937, "num_tokens": 1239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.7078890197018356}}
{"text": "\\title{KL(q||p) Minimization}\n\n\\subsection{$\\text{KL}(q\\|p)$ Minimization}\n\nOne form of variational inference minimizes the Kullback-Leibler\ndivergence \\textbf{from} $q(\\mathbf{z}\\;;\\;\\lambda)$ \\textbf{to}\n$p(\\mathbf{z} \\mid \\mathbf{x})$,\n\\begin{align*}\n  \\lambda^*\n  &=\n  \\arg\\min_\\lambda \\text{KL}(\n  q(\\mathbf{z}\\;;\\;\\lambda)\n  \\;\\|\\;\n  p(\\mathbf{z} \\mid \\mathbf{x})\n  )\\\\\n  &=\n  \\arg\\min_\\lambda\\;\n  \\mathbb{E}_{q(\\mathbf{z}\\;;\\;\\lambda)}\n  \\big[\n  \\log q(\\mathbf{z}\\;;\\;\\lambda)\n  -\n  \\log p(\\mathbf{z} \\mid \\mathbf{x})\n  \\big].\n\\end{align*}\nThe KL divergence is a non-symmetric, information theoretic measure of\nsimilarity between two probability distributions\n\\citep{hinton1993keeping,waterhouse1996bayesian,jordan1999introduction}.\n\n\\subsubsection{The Evidence Lower Bound}\n\nThe above optimization problem is intractable because it directly\ndepends on the posterior $p(\\mathbf{z} \\mid \\mathbf{x})$. To tackle\nthis, consider the property\n\\begin{align*}\n  \\log p(\\mathbf{x})\n  &=\n  \\text{KL}(\n  q(\\mathbf{z}\\;;\\;\\lambda)\n  \\;\\|\\;\n  p(\\mathbf{z} \\mid \\mathbf{x})\n  )\\\\\n  &\\quad+\\;\n  \\mathbb{E}_{q(\\mathbf{z}\\;;\\;\\lambda)}\n  \\big[\n  \\log p(\\mathbf{x}, \\mathbf{z})\n  -\n  \\log q(\\mathbf{z}\\;;\\;\\lambda)\n  \\big]\n\\end{align*}\nwhere the left hand side is the logarithm of the marginal likelihood\n$p(\\mathbf{x}) = \\int p(\\mathbf{x}, \\mathbf{z}) \\text{d}\\mathbf{z}$,\nalso known as the model evidence. (Try deriving this using Bayes'\nrule!)\n\nThe evidence is a constant with respect to the variational parameters\n$\\lambda$, so we can minimize $\\text{KL}(q\\|p)$ by instead maximizing\nthe Evidence Lower BOund,\n\\begin{align*}\n  \\text{ELBO}(\\lambda)\n  &=\\;\n  \\mathbb{E}_{q(\\mathbf{z}\\;;\\;\\lambda)}\n  \\big[\n  \\log p(\\mathbf{x}, \\mathbf{z})\n  -\n  \\log q(\\mathbf{z}\\;;\\;\\lambda)\n  \\big].\n\\end{align*}\nIn the ELBO, both $p(\\mathbf{x}, \\mathbf{z})$ and\n$q(\\mathbf{z}\\;;\\;\\lambda)$ are tractable. The optimization problem we\nseek to solve becomes\n\\begin{align*}\n  \\lambda^*\n  &=\n  \\arg \\max_\\lambda \\text{ELBO}(\\lambda).\n\\end{align*}\nAs per its name, the ELBO is a lower bound on the evidence, and\noptimizing it tries to maximize the probability of observing the data.\nWhat does maximizing the ELBO do? Splitting the ELBO reveals a trade-off\n\\begin{align*}\n  \\text{ELBO}(\\lambda)\n  &=\\;\n  \\mathbb{E}_{q(\\mathbf{z} \\;;\\; \\lambda)}[\\log p(\\mathbf{x}, \\mathbf{z})]\n  - \\mathbb{E}_{q(\\mathbf{z} \\;;\\; \\lambda)}[\\log q(\\mathbf{z}\\;;\\;\\lambda)],\n\\end{align*}\nwhere the first term represents an energy and the second term\n(including the minus sign) represents the entropy of $q$.\nThe energy encourages $q$ to focus probability mass where the\nmodel puts high probability, $p(\\mathbf{x}, \\mathbf{z})$.\nThe entropy encourages $q$ to spread probability mass to avoid\nconcentrating to one location.\n\nEdward uses two generic strategies to obtain gradients for\noptimization.\n\n\\begin{itemize}\n  \\item Score function gradient;\n  \\item Reparameterization gradient.\n\\end{itemize}\n\n\\subsection{Score function gradient}\n\nGradient descent is a standard approach for optimizing complicated\nobjectives like the ELBO. The idea is to calculate its gradient\n\\begin{align*}\n  \\nabla_\\lambda\\;\n  \\text{ELBO}(\\lambda)\n  &=\n  \\nabla_\\lambda\\;\n  \\mathbb{E}_{q(\\mathbf{z}\\;;\\;\\lambda)}\n  \\big[\n  \\log p(\\mathbf{x}, \\mathbf{z})\n  -\n  \\log q(\\mathbf{z}\\;;\\;\\lambda)\n  \\big],\n\\end{align*}\nand update the current set of parameters proportional to the gradient.\n\nThe score function gradient estimator leverages a property of\nlogarithms to write the gradient as\n\\begin{align*}\n  \\nabla_\\lambda\\;\n  \\text{ELBO}(\\lambda)\n  &=\\;\n  \\mathbb{E}_{q(\\mathbf{z}\\;;\\;\\lambda)}\n  \\big[\n  \\nabla_\\lambda \\log q(\\mathbf{z}\\;;\\;\\lambda)\n  \\:\n  \\big(\n  \\log p(\\mathbf{x}, \\mathbf{z})\n  -\n  \\log q(\\mathbf{z}\\;;\\;\\lambda)\n  \\big)\n  \\big].\n\\end{align*}\nThe gradient of the ELBO is an expectation over the variational\nmodel $q(\\mathbf{z}\\;;\\;\\lambda)$; the only new ingredient it requires is the\n\\emph{score function} $\\nabla_\\lambda \\log q(\\mathbf{z}\\;;\\;\\lambda)$\n\\citep{paisley2012variational,ranganath2014black}.\n\nWe can use Monte Carlo integration to obtain noisy estimates of both the ELBO\nand its gradient. The basic procedure follows these steps:\n\\begin{enumerate}\n  \\item draw $S$ samples $\\{\\mathbf{z}_s\\}_1^S \\sim q(\\mathbf{z}\\;;\\;\\lambda)$,\n  \\item evaluate the argument of the expectation using $\\{\\mathbf{z}_s\\}_1^S$, and\n  \\item compute the empirical mean of the evaluated quantities.\n\\end{enumerate}\n\nA Monte Carlo estimate of the gradient is then\n\\begin{align*}\n  \\nabla_\\lambda\\;\n  \\text{ELBO}(\\lambda)\n  &\\approx\\;\n  \\frac{1}{S}\n  \\sum_{s=1}^{S}\n  \\big[\n  \\big(\n  \\log p(\\mathbf{x}, \\mathbf{z}_s)\n  -\n  \\log q(\\mathbf{z}_s\\;;\\;\\lambda)\n  \\big)\n  \\:\n  \\nabla_\\lambda \\log q(\\mathbf{z}_s\\;;\\;\\lambda)\n  \\big].\n\\end{align*}\nThis is an unbiased estimate of the actual gradient of the ELBO.\n\n\\subsection{Reparameterization gradient}\n\nIf the model has differentiable latent variables, then it is generally\nadvantageous to leverage gradient information from the model in order to\nbetter traverse the optimization space. One approach to doing this is\nthe reparameterization gradient\n\\citep{kingma2014auto,rezende2014stochastic}.\n\nSome variational distributions $q(\\mathbf{z}\\;;\\;\\lambda)$ admit useful\nreparameterizations. For example, we can reparameterize a normal distribution\n$\\mathbf{z} \\sim \\text{Normal}(\\mu, \\Sigma)$ as\n$\\mathbf{z} \\sim \\mu + L \\text{Normal}(0, I)$ where $\\Sigma = LL^\\top$. In general, write\nthis as\n\\begin{align*}\n  \\epsilon &\\sim q(\\epsilon)\\\\\n  \\mathbf{z} &= \\mathbf{z}(\\epsilon \\;;\\; \\lambda),\n\\end{align*}\nwhere $\\epsilon$ is a random variable that does \\textbf{not} depend on the\nvariational parameters $\\lambda$. The deterministic function\n$\\mathbf{z}(\\cdot;\\lambda)$ encapsulates the variational parameters instead,\nand following the process is equivalent to directly drawing $\\mathbf{z}$ from\nthe original distribution.\n\nThe reparameterization gradient leverages this property of the\nvariational distribution to write the gradient as\n\\begin{align*}\n  \\nabla_\\lambda\\;\n  \\text{ELBO}(\\lambda)\n  &=\\;\n  \\mathbb{E}_{q(\\epsilon)}\n  \\big[\n  \\nabla_\\lambda\n  \\big(\n  \\log p(\\mathbf{x}, \\mathbf{z}(\\epsilon \\;;\\; \\lambda))\n  -\n  \\log q(\\mathbf{z}(\\epsilon \\;;\\; \\lambda) \\;;\\;\\lambda)\n  \\big)\n  \\big].\n\\end{align*}\nThe gradient of the ELBO is an expectation over the base\ndistribution $q(\\epsilon)$, and the gradient can be applied directly\nto the inner expression.\n\nWe can use Monte Carlo integration to obtain noisy estimates of both the ELBO\nand its gradient. The basic procedure follows these steps:\n\\begin{enumerate}\n  \\item draw $S$ samples $\\{\\epsilon_s\\}_1^S \\sim q(\\epsilon)$,\n  \\item evaluate the argument of the expectation using $\\{\\epsilon_s\\}_1^S$, and\n  \\item compute the empirical mean of the evaluated quantities.\n\\end{enumerate}\n\nA Monte Carlo estimate of the gradient is then\n\\begin{align*}\n  \\nabla_\\lambda\\;\n  \\text{ELBO}(\\lambda)\n  &\\approx\\;\n  \\frac{1}{S}\n  \\sum_{s=1}^{S}\n  \\big[\n  \\nabla_\\lambda\n  \\big(\n  \\log p(\\mathbf{x}, \\mathbf{z}(\\epsilon_s \\;;\\; \\lambda))\n  -\n  \\log q(\\mathbf{z}(\\epsilon_s \\;;\\; \\lambda) \\;;\\;\\lambda)\n  \\big)\n  \\big].\n\\end{align*}\nThis is an unbiased estimate of the actual gradient of the ELBO. Empirically, it\nexhibits lower variance than the\nscore function gradient, leading to\nfaster convergence in a large set of problems.\n\nFor more details, see the \\href{/api/}{API} as well as its\nimplementation in Edward's code base.\n\n\\subsubsection{References}\\label{references}\n", "meta": {"hexsha": "1ab24ec5e36b9498559d21576200c8d0d96da3ad", "size": 7491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tutorials/klqp.tex", "max_stars_repo_name": "xiangze/edward", "max_stars_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5200, "max_stars_repo_stars_event_min_datetime": "2016-05-03T04:59:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T03:32:26.000Z", "max_issues_repo_path": "docs/tex/tutorials/klqp.tex", "max_issues_repo_name": "xiangze/edward", "max_issues_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 724, "max_issues_repo_issues_event_min_datetime": "2016-05-04T09:04:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T02:41:12.000Z", "max_forks_repo_path": "docs/tex/tutorials/klqp.tex", "max_forks_repo_name": "xiangze/edward", "max_forks_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1004, "max_forks_repo_forks_event_min_datetime": "2016-05-03T22:45:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T00:08:08.000Z", "avg_line_length": 30.8271604938, "max_line_length": 89, "alphanum_fraction": 0.6909624883, "num_tokens": 2421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633915994285382, "lm_q2_score": 0.819893335913536, "lm_q1q2_score": 0.7078890186551875}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{color,amsmath}\n\n\\title{Microphone Calibration}\n\\author{Dean Richert}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Acoustic sensing basics}\n\n\\subsection{Octave bands:} Let $n$ be the band number. Then the center of octave band $n$ (in Hz) is,\n\\begin{align*}\n    f_c(N) = 2^{n-5} \\times 10^3.\n\\end{align*}\nThe band limits, in Hz, are given by\n\\begin{align*}\n    f_{\\text{upper}}(n) &= \\sqrt{2} f_c(n)\n    \\\\ \n    f_{\\text{lower}}(n) &= \\frac{1}{\\sqrt{2}} f_c(n)\n\\end{align*}\n\n\\subsection{Equivalent sound pressure level:} This is a measurement of average sound pressure. Let $p(t)$ be the instantaneous sound pressure at time $t$ and let $T$ be the time duration of a measurement. Then,\n\\begin{align*}\n    L_{eq}(T) = 10 \\log_{10}\\bigg[\\frac{1}{T} \\int_0^T\\bigg(\\frac{p(t)}{p_0}\\bigg)^2 dt\\bigg]\n\\end{align*}\nwhere $p_0$ is the reference sound pressure (usually $20\\mu$Pa). For discrete time measurements, \n\\begin{align*}\n    L_{eq}(N) = 10 \\log_{10}\\bigg[\\frac{1}{N} \\sum_{k=0}^{N-1}\\bigg(\\frac{p(k)}{p_0}\\bigg)^2 \\bigg]\n\\end{align*}\nwhere $N$ is the number of measurements. \n\\\\\nWe can also compute the equivalent sound pressure level in an octave band using a band pass filter, $H_n$, which pass frequencies in octave band $n$. Then the equivalent sound pressure level in octave band $n$ is\n\\begin{align*}\n    L_{eq}^n(N) = 10 \\log_{10}\\bigg[\\frac{1}{N} \\sum_{t=0}^{N-1}\\bigg(\\frac{H_n[p(t)]}{p_0}\\bigg)^2 \\bigg]\n\\end{align*}\nHere we assume that $H_n$ has unit gain ($0$dB) at $f_c(n)$. I use $6^{th}$ order Butterworth filters for $H_n$.\n\nTo get the total sound pressure level across a set $\\mathcal{N}$ of octave bands, the following calculation is performed:\n\\begin{align*}\n    L_{eq}(N) = 10 \\log_{10}\\bigg( \\sum_{n \\in \\mathcal{N}} 10^{\\frac{L_{eq}^n(N)}{10}} \\bigg)\n\\end{align*}\n\nOn the other hand, the average $L_{eq}$ of a set of sound pressure measurements taken over distinct time intervals, $\\{L_{eq,i}\\}_{i = 0}^{M-1}$, is given by\n\\begin{align*}\n    L_{eq} = 10 \\log_{10}\\bigg( \\frac{1}{M} \\sum_{i = 0}^{M-1} 10^{\\frac{L_{eq,i}}{10}} \\bigg)\n\\end{align*}\n\n\\subsection{A-weighted $L_{eq}$:} The human ear is less sensitive to low frequencies; the perceived loudness of a low-frequency signal is less than the perceived loudness of a high-frequency signal of equal $L_{eq}$. The A-weighting of a sound pressure level accounts for this by weighting high-frequency components in a signal more than the low-frequency components. The A-weighted $L_{eq}$ in octave band $n$ is defined as\n\\begin{align*}\n    LA_{eq}^n(N) = L_{eq}^n(N) + A(f_c(n))\n\\end{align*}\nwhere\n\\begin{align*}\n    A(f) &= 20 \\log_{10} R_A(f) + 2 \\\\\n    R_A(f) &= \\frac{12194^2 f^4}{(f^2 + 20.6^2)\\sqrt{(f^2+107.7^2)(f^2+737.9^2)}(f^2+12194^2)}\n\\end{align*}\nThe units of $LA_{eq}$ are dBA. The total A-weighted sound pressure level for a signal can be computed as\n\\begin{align*}\n    LA_{eq}(N) = 10 \\log_{10}\\bigg( \\sum_{n \\in \\mathcal{N}} 10^{\\frac{LA_{eq}^n(N)}{10}} \\bigg)\n\\end{align*}\n\n\\section{Calibration}\n\nFor a sound pressure signal $p(k)$ in octave band $n$, we assume that the microphone measurement is given by\n\\begin{align*}\n    y(k) = K(n) p(k) + y_{DC}\n\\end{align*}\nNote that there is a frequency dependence on the sensor gain $K(n)$ which is consistent with the data sheet.\n\n\\subsection{DC bias:} To compute the DC bias we take advantage of the zero-mean property of $p(k)$. Taking the average over many measurements,\n\\begin{align*}\n    \\frac{1}{N} \\sum_{k=0}^{N-1} y(k) &= \\frac{K(n)}{N} \\sum_{k=0}^{N-1} p(k) + y_{DC}\n    \\\\\n    y_{DC} &= \\frac{1}{N} \\sum_{k=0}^{N-1} y(k)\n\\end{align*}\n\n\\subsection{Sensor gain:} Suppose that $p(k)$ is a calibration tone at frequency $f_c(n)$ at $x$ dB. Then,\n\\begin{align*}\n    x &= 10 \\log_{10} \\bigg[ \\frac{1}{N} \\sum_{k=0}^{N-1}\\bigg(\\frac{H_n(p(k))}{p_0} \\bigg)^2 \\bigg]\n    \\\\\n    x &= 10 \\log_{10} \\bigg[ \\frac{1}{N} \\sum_{k=0}^{N-1}\\bigg(\\frac{H_n((y(k)-y_{DC})/(K(n))}{p_0} \\bigg)^2 \\bigg]\n    \\\\\n    x &= 10 \\log_{10} \\bigg[ \\frac{1}{(K(n)p_0)^2} \\frac{1}{N} \\sum_{k=0}^{N-1}\\bigg(H_n(y(k)-y_{DC}) \\bigg)^2 \\bigg] \n    \\\\\n    K_{cal}(n) :=  \\frac{1}{(K(n)p_0)^2} &= \\frac{10^{x/10}}{\\frac{1}{N} \\sum_{k=0}^{N-1}\\big(H_n(y(k)-y_{DC})\\big)^2} \n\\end{align*}\nThe calibration routine is then given by:\n\\begin{enumerate}\n    \\item Generate a sound signal at $f_c(n)$ at known $x$ dB,\n    \\item For each new measurement:\n        \\begin{itemize}\n            \\item Subtract the computed $y_{DC}$ from the raw measurement\n            \\item Update the filter states with input $y(k) - y_{DC}$\n            \\item Square the filter output and add it to the previous squared output\n        \\end{itemize}\n    \\item After taking sufficient measurements, compute $K_{cal}(n)$\n\\end{enumerate}\nNote that we do not solve for $K(n)$ explicitly since $K_{cal}(n)$ is sufficient to compute the equivalent sound pressure level:\n\\begin{align*}\n    L_{eq}^n(N) &= 10 \\log_{10} \\bigg[ \\frac{K_{cal}(n)}{N} \\sum_{k=0}^{N-1}\\big(H_n(y(k) - y_{DC})\\big)^2 \\bigg]\n\\end{align*}\nNote that if $H_n$ does not have unit gain at $f_c(n)$ this is absorbed into $K_{cal}(n)$. Thus, we do not actually design the band pass filters to have unit gain at the octave frequency and rather compensate for this through calibration.\n\n\n\\end{document}\n", "meta": {"hexsha": "9a124b22050d895c122770c87eec933a485b929a", "size": 5295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reference documents/microphone calibration/main.tex", "max_stars_repo_name": "deanmrichert/urbanNoiseMonitoring", "max_stars_repo_head_hexsha": "fde4e0156f7bf8477d28827647e7032457e8fce3", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "reference documents/microphone calibration/main.tex", "max_issues_repo_name": "deanmrichert/urbanNoiseMonitoring", "max_issues_repo_head_hexsha": "fde4e0156f7bf8477d28827647e7032457e8fce3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "reference documents/microphone calibration/main.tex", "max_forks_repo_name": "deanmrichert/urbanNoiseMonitoring", "max_forks_repo_head_hexsha": "fde4e0156f7bf8477d28827647e7032457e8fce3", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.5779816514, "max_line_length": 424, "alphanum_fraction": 0.6528800755, "num_tokens": 1913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.7078890081738701}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\n\n\\title{Weierstrass normal form}\n\\author{Dave Neary}\n\\date{May 2021}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Weierstrass normal form for cubic equations}\n\nGiven a general cubic equation\n\\[ ax^3 +bx^2y +cxy^2 + dy^3 +ex^2 + fxy +gy^2 + hx + iy +j = 0 \\]\nwe can perform a set of substitutions to convert the equation to a form called Weierstrass normal form:\n\\[ Y^2 = X^3 + AX^2 + BX + C \\]\nor, equivalently:\n\\[ Y^2 = X^3 + \\alpha X + \\beta \\]\n\nIn particular, for the cubic equation $C$:\n\\[u^3+v^3=\\alpha \\]\nwe can use the substitutions\n\\[x = \\frac{12\\alpha}{u+v}, y = 36\\alpha\\frac{u-v}{u+v} \\]\nto convert this equation to the form $C'$:\n\\[ y^2 = x^3 - 432 \\alpha \\]\n\nThis process can be inverted, so from any point $(x,y) \\in C'$ we can generate a point $(u,v) \\in C$ by the transform:\n\\[u = \\frac{36\\alpha +y}{6x}, v = \\frac{36\\alpha - y}{6x} \\]\n\nBy this means, if we find rational points on either curve, we can generate a rational point on the other by this bijection.\n\nThis transformation might seem like magic, but we can work through this process if we have a rational point on the homogeneous projective form of original curve. To get to this form, we replace $u = \\frac{U}{W}, v = \\frac{V}{W}$ and multiply across by $W^3$ to give:\n\\[ U^3 + V^3 - \\alpha W^3 = 0 \\]\nThe point in $\\mathbb{P}^2$ $P = [-1; 1; 0]$ is on the curve $C$. Since $W=0$ this corresponds to a point at infinity - a tangent point of the curve. The tangent at the point $P$ is given by the line:\n\\[ U \\frac{\\partial C}{\\partial U} (P) + V \\frac{\\partial C}{\\partial V} (P) + W \\frac{\\partial C}{\\partial W} (P) = 0 \\]\n\n\\[ \\frac{\\partial C}{\\partial V} = 3V^2, \\frac{\\partial C}{\\partial U} = 3U^2, \\frac{\\partial C}{\\partial W} = 3\\alpha W^2 \\]\n\nSo at the point $P = [-1;1;0]$ the tangent line in $\\mathbb{P}^2$ is $3U + 3V = 0$ (and we can divide out the common factor of 3).\n\nExamining the curve $u^3+v^3=\\alpha$ we can see that this does not intersect at all in the\nreal numbers, and has a triple root at the point at infinity. We will use this line as our\n$Z=0$ axis after our transformation.\n\nWe will take $U-V=0$ as our $X$ axis, motivated by the fact that this is a line of symmetry\nof our curve, and finally we will take $U+V-W = 0$ as our $Y$ axis, motivated by the fact\nthat it intersects $Z=0$ at $P$, and is helpfully orthogonal to the $X$ axis, so we should\navoid any pesky $XY$ terms after transformation.\n\nPutting this together, our transformation from $(U,V,W)$ space to $(X,Y,Z)$ space will be:\n\\[ \n\\begin{pmatrix} 1 & -1 & 0 \\\\ 1 & 1 & -1 \\\\ 1 & 1 & 0 \\end{pmatrix}\n\\begin{pmatrix} U \\\\ V \\\\ W \\end{pmatrix} = \n\\begin{pmatrix} X \\\\ Y \\\\ Z \\end{pmatrix} \\]\n\nThis matrix is, by design, invertible. Its inverse is:\n\n\\[ A^{-1} = \\frac{1}{2} \\begin{pmatrix} 1 & 0 & 1 \\\\ -1 & 0 & 1 \\\\ 0 & -2 & 2 \\end{pmatrix} \\]\nThis gives us an affine transformation which allows us to go from $(X,Y,Z)$ space to $(U,V,W)$ space as follows:\n\\begin{equation*}\n\\begin{split}\n    U &= \\frac{1}{2}(X + Z) \\\\\n    V &= \\frac{1}{2}(-X + Z) \\\\\n    W  &= -Y + Z\n\\end{split}\n\\end{equation*}\n\nBy substituting these equations back into our homogeneous version of $C$, we get:\n\\[ \\left(\\frac{1}{2}(X + Z)\\right)^3 + \\left(\\frac{1}{2}(-X + Z)\\right)^3\n- \\alpha\\left(-Y + Z\\right)^3 = 0 \\]\n\nExpanding and cancelling terms, we simplify our original equation to:\n\\begin{equation*}\n\\begin{split}\n     \\frac{1}{8}(6X^2Z + 2Z^3) - \\alpha (-Y^3 + 3Y^2Z - 3YZ^2 + Z^3) &= 0 \\\\\n     3X^2Z + Z^3 + 4 \\alpha Y^3 - 12 \\alpha Y^2Z + 12\\alpha YZ^2 - 4\\alpha Z^3 &= 0 \n\\end{split}\n\\end{equation*}\n\nReplacing $x=\\frac{X}{Z}, y=\\frac{Y}{Z}$ to dehomogenize, we get:\n\\[  3x^2 + 1 + 4 \\alpha y^3 - 12 \\alpha y^2 + 12\\alpha y - 4\\alpha = 0 \\]\n\\[ 3x^2 = -4\\alpha y^3 + 12\\alpha y^2 -12 \\alpha y +4 \\alpha -1 \\]\n\nWe want a perfect square term on the left, and a leading perfect cube on the right. We can achieve\nthis by multiplying both sides by $3^3\\cdot4^2\\cdot \\alpha^2 = 432\\alpha^2$:\n\n\\[ 3^4 4^2 \\alpha^2 x^2 = -3^3 4^3 \\alpha^3 y^3 + 3^3 4^3 \\alpha^3 (3y^2) - 3^3 4^3 \\alpha^3(3 y) +3^3 4^3 \\alpha^3 - 432\\alpha^2 \\]\n\nSubstituting $a=36\\alpha x, b=-12\\alpha(y-1)$ we get:\n\\[ a^2 = b^3 - 432\\alpha^2 \\]\n\nThe transforms from $(a,b)$ to $(u,v)$ are now straightforward to derive:\n\\begin{equation*}\n\\begin{split}\n         a & = 36\\alpha x \\\\\n         & = 36 \\alpha \\frac{X}{Z} \\\\\n         & = 36 \\alpha \\frac{U-V}{U+V} \\\\\n         & = 36 \\alpha \\frac{u-v}{u+v} \\\\\n         b & = -12 \\alpha (y-1) \\\\\n         & = -12 \\alpha \\left(\\frac{Y}{Z} - 1 \\right) \\\\\n         & = -12 \\alpha \\left(\\frac{U+V-W}{U+V} - 1 \\right) \\\\\n         & = -12 \\alpha \\left(\\frac{-W}{U+V}\\right) \\\\\n         & = \\frac{12 \\alpha}{u+v} \\\\\n\\end{split}\n\\end{equation*}\n\nwhere we replace $u=\\frac{U}{W}, v=\\frac{V}{W}$ to dehomogenize. \n\nThe transformation from $(u,v)$ to $(a,b)$ is similar:\n\\begin{equation*}\n\\begin{split}\n         u & = \\frac{U}{W} \\\\\n         & = \\frac{\\frac{1}{2}(X + Z)}{-Y + Z} \\\\\n         & = \\frac{\\frac{X}{Z} + 1}{-2\\frac{Y}{Z} + 2} \\\\\n         & = \\frac{(x + 1)}{-2(y - 1)} \\\\\n         & = \\frac{(\\frac{a}{36\\alpha} + 1)}{-2\\left(\\frac{-b}{12\\alpha} \\right)} \\\\\n         & = \\frac{a + 36\\alpha}{6b} \\\\\n         v & =  \\frac{V}{W} \\\\\n         & = \\frac{\\frac{1}{2}(-X + Z)}{-Y + Z} \\\\\n         & = \\frac{-X + Z}{-2Y + 2Z} \\\\\n         & = \\frac{-x + 1}{-2(y -1)} \\\\\n         & = \\frac{-\\frac{a}{36\\alpha} + 1}{-2(\\frac{-b}{12\\alpha})} \\\\\n         & = \\frac{-a + 36\\alpha}{6b}\n\\end{split}\n\\end{equation*}\n\n\\end{document}\n", "meta": {"hexsha": "5d91d4f925f0dff9540aeb37afb8befd48e1a894", "size": 5554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Weierstrass_normal_form.tex", "max_stars_repo_name": "dneary/math", "max_stars_repo_head_hexsha": "129b2093c01b12ddc2e61abd331c95da2177803c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Weierstrass_normal_form.tex", "max_issues_repo_name": "dneary/math", "max_issues_repo_head_hexsha": "129b2093c01b12ddc2e61abd331c95da2177803c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Weierstrass_normal_form.tex", "max_forks_repo_name": "dneary/math", "max_forks_repo_head_hexsha": "129b2093c01b12ddc2e61abd331c95da2177803c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.0757575758, "max_line_length": 266, "alphanum_fraction": 0.5887648542, "num_tokens": 2113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.7078431932878873}}
{"text": "\\section{Spherical Coordinates}\r\n\\noindent\r\nUnlike how cylindrical coordinates extend polar coordinates into 3D by adding a Cartesian term, spherical coordinates add an angular term, $\\phi$, the azimuthal angle. All spherical coordinates have the form $(\\rho, \\theta, \\phi)$ where $\\rho$ is the distance from the origin, $\\theta$ is the polar angle in the xy-plane, and $\\phi$ is the azimuthal angle from the $+z$-axis. Shapes with spherical symmetry have a constant bounds of integration in spherical coordinates.\r\n\r\n[INSERT IMAGE]\r\n\r\n\\input{./curvilinearCoordinates/conversions_spherical}\r\n\\input{./curvilinearCoordinates/integration_spherical}", "meta": {"hexsha": "ad8334f2254aa97a0bb89258e5b833600d001897", "size": 646, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/curvilinearCoordinates/sphericalCoordinates.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/curvilinearCoordinates/sphericalCoordinates.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/curvilinearCoordinates/sphericalCoordinates.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 80.75, "max_line_length": 471, "alphanum_fraction": 0.786377709, "num_tokens": 144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7078431866371769}}
{"text": "\\subsection{Times Table} % (fold)\n\\label{sub:times_table}\n\nThis program prints out the times table for a number entered by the user, displaying from 1 x n to 10 x n. The description of the program is in Table \\ref{tbl:data-times-table}, the pseudocode in Listing \\ref{lst:data-times-pseudo}, the C code in Listing \\ref{lst:data-times-c}, and the Pascal code in Listing \\ref{lst:data-times-pas}.\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{l|p{10cm}}\n  \\hline\n  \\multicolumn{2}{c}{\\textbf{Program Description}} \\\\\n  \\hline\n  \\textbf{Name} & \\emph{Times Table} \\\\\n  \\\\\n  \\textbf{Description} & Displays the Times Table from 1 x n to 10 x n. \\\\\n  \\hline\n\\end{tabular}\n\\caption{Description of the Times Table program}\n\\label{tbl:data-times-table}\n\\end{table}\n\n\\pseudocode{lst:data-times-pseudo}{Pseudocode for Times Table program.}{./topics/storing-using-data/examples/times-table.txt}\n\n\\mynote{\nThis is an updated version of the Seven Times Table Program. See Section \\ref{sub:seven_times_table} \\nameref{sub:seven_times_table}.\n}\n\n\\clearpage\n\n\\csection{\\ccode{lst:data-times-c}{C Times Table}{topics/storing-using-data/examples/times_table.c}}\n\n\\passection{\\pascode{lst:data-times-pas}{Pascal Times Table}{topics/storing-using-data/examples/TimesTable.pas}}\n\n% subsection times_table (end)\n\n\\clearpage\n\\subsection{Circle Area} % (fold)\n\\label{sub:circle_area_data}\n\nThis program prints out the area of a circle. The description of the program is in Table \\ref{tbl:data-circle-area}, the pseudocode in Listing \\ref{lst:data-circle-areas-pseudo}, the C code in Listing \\ref{lst:data-circle-areas-c}, and the Pascal code in Listing \\ref{lst:data-circle-areas-pas}.\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{l|p{10cm}}\n  \\hline\n  \\multicolumn{2}{c}{\\textbf{Program Description}} \\\\\n  \\hline\n  \\textbf{Name} & \\emph{Circle Areas} \\\\\n  \\\\\n  \\textbf{Description} & Displays the Circle Areas for circles with radius from 1.0 to 5.0 with increments of 0.5. \\\\\n  \\hline\n\\end{tabular}\n\\caption{Description of the Circle Areas program}\n\\label{tbl:data-circle-area}\n\\end{table}\n\n\\pseudocode{lst:data-circle-areas-pseudo}{Pseudocode for Circle Areas program.}{./topics/storing-using-data/examples/circle_areas.txt}\n\n\\mynote{\nThis is an updated version of the Circle Areas Program. See Section \\ref{sub:circle_area} \\nameref{sub:circle_area}.\n}\n\n\n\\clearpage\n\n\\csection{\\ccode{lst:data-circle-areas-c}{C Circle Areas}{topics/storing-using-data/examples/circle_areas.c}}\n\n\\passection{\\pascode{lst:data-circle-areas-pas}{Pascal Circle Areas}{topics/storing-using-data/examples/CircleAreas.pas}}\n\n% subsection circle_area (end)\n\\clearpage\n\\subsubsection{Water Tank} % (fold)\n\\label{ssub:water_tank}\n\nThe \\emph{Water Tank} program draws four water tanks to the terminal. Each water tank is drawn as a cylinder that fills a given area on the screen, and shows its current water level. An example execution is shown in \\fref{fig:water-tank-img}.\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{l|p{10cm}}\n  \\hline\n  \\multicolumn{2}{c}{\\textbf{Program Description}} \\\\\n  \\hline\n  \\textbf{Name} & \\emph{Water Tank} \\\\\n  \\\\\n  \\textbf{Description} & Displays calculates and displays `Water Tanks'. Each tank has a position on the screen, a width, height, and a percent full.\\\\\n  \\hline\n\\end{tabular}\n\\caption{Description of the Water Tanks program}\n\\label{tbl:data-water-tanks}\n\\end{table}\n\n\\begin{figure}[h]\n   \\centering\n   \\includegraphics[width=0.7\\textwidth]{./topics/storing-using-data/examples/WaterTank.png} \n   \\caption{Example execution of the Water Tank program}\n   \\label{fig:water-tank-img}\n\\end{figure}\n\n\\clearpage\n\n\\csection{\\ccode{clst:water-tank}{C Water Tank drawing code}{topics/storing-using-data/examples/water-tank.c}}\n\n\\csection{\\ccode{clst:water-tank1}{C Water Tank drawing code (continued from \\lref{clst:water-tank})}{topics/storing-using-data/examples/water-tank1.c}}\n\n\\passection{\\pascode{lst:data-water-tank-pas}{Pascal Water Tank}{topics/storing-using-data/examples/WaterTank.pas}}\n\n\\passection{\\pascode{lst:data-water-tank-1-pas}{Pascal Water Tank (continued from \\lref{lst:data-water-tank-pas})}{topics/storing-using-data/examples/WaterTank1.pas}}\n\n% subsubsection water_tank (end)\n\n\n\\clearpage\n\\subsection{Bicycle Race} % (fold)\n\\label{sub:bicycle_race}\n\nThe Bicycle Race program will simulate a thirty second sprint race between a number of bicycles. The race has a standing start, and then each racer accelerates as fast as they can for thirty seconds. The winner is the racer who makes it the furthest.\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{l|p{10cm}}\n  \\hline\n  \\multicolumn{2}{c}{\\textbf{Program Description}} \\\\\n  \\hline\n  \\textbf{Name} & \\emph{Bike Race} \\\\\n  \\\\\n  \\textbf{Description} & Calculates the position of seven bikes at the end of a timed race, drawing the final positions. Each bike's position is calculated based on a random acceleration over the duration of the race. \\\\\n  \\hline\n\\end{tabular}\n\\caption{Description of the Bike Race program}\n\\label{tbl:data-bike-race}\n\\end{table}\n\n\n\\begin{itemize}\n  \\item You can calculate distance the racers cover using Equation~\\ref{eq:acceleration}.\n  \\begin{itemize}\n    \\item \\emph{s} is the distance covered.\n    \\item \\emph{u} is the starting speed\n    \\item \\emph{t} is time.\n    \\item \\emph{a} is acceleration.\n  \\end{itemize} \n  \\begin{equation}\n    s = ut + \\frac{a t^2}{2}\n    \\label{eq:acceleration}\n  \\end{equation}\n  \\item This race has a standing start, so the initial speed of each racer will be 0.\n  \\item The time for the race is 30 seconds, this is constant.\n  \\item Each racer will have a randomly determined acceleration, with a maximum acceleration of 10 $pixels/second^2$\n\\end{itemize}\n\n\\begin{figure}[h]\n   \\centering\n   \\includegraphics[width=0.6\\textwidth]{./topics/storing-using-data/examples/BikeRace.png} \n   \\caption{Example execution of the Bike Race program}\n   \\label{fig:bike-race-img}\n\\end{figure}\n\n\\csection{\\ccode{clst:bike-race}{C Bicycle Race, continued in \\lref{clst:bike-race1}}{topics/storing-using-data/examples/bike-race.c}}\n\n\\csection{\\ccode{clst:bike-race1}{C Bicycle Race}{topics/storing-using-data/examples/bike-race1.c}}\n\n\\passection{\\pascode{lst:bike-race-pas}{Pascal Bike Race)}{topics/storing-using-data/examples/BikeRace.pas}}\n\n\\passection{\\pascode{lst:bike-race-1-pas}{Pascal Bike Race (continued from \\lref{lst:bike-race-pas})}{topics/storing-using-data/examples/BikeRace1.pas}}\n\n% subsection bicycle_race (end)\n\n% \\clearpage\n% \\subsection{Comet Orbit} % (fold)\n% \\label{sub:comet_orbit}\n% \n% This program uses SwinGame to draw the orbit of the Hale-Bopp comet around the sun. The Hale-Bopp comet performs an elliptical orbit of the sun that can be plotted using Equation~ \\ref{eq:orbit}. This equation calculates the radius (r) of the comet's position based on the \\emph{angle} between the comet and the sun. Where \\emph{e} is the Eccentricity value with a constant value of 0.995, and \\emph{d} is the distance between the pole and directrix with a constant value of 1.828.\n% \n% \\begin{equation}\n%   r = \\frac{ed}{1 + e sin(angle)}\n%   \\label{eq:orbit}\n% \\end{equation}\n% \n% \\begin{table}[h]\n% \\centering\n% \\begin{tabular}{l|p{10cm}}\n%   \\hline\n%   \\multicolumn{2}{c}{\\textbf{Program Description}} \\\\\n%   \\hline\n%   \\textbf{Name} & \\emph{Comet Orbit} \\\\\n%   \\\\\n%   \\textbf{Description} & Calculates and plots the position of the Hale-Bopp comet, based on an equation of its elliptical orbit of the sun. \\\\\n%   \\hline\n% \\end{tabular}\n% \\caption{Description of the Comet Orbit program}\n% \\label{tbl:data-comet-orbit}\n% \\end{table}\n% \n% This will require functions and procedures to do the following:\n% \\begin{itemize}\n%   \\item A function to \\textbf{calculate} the \\textbf{r} value for the comet based on an \\emph{angle}.\n%   \\item Functions to \\textbf{convert} the \\textbf{x} and \\textbf{y} positions of the comet from AU (Astronomical Units) to pixel coordinates so that the comets position can be plotted on the screen.\n%   \\item A procedure to \\textbf{Draw} the \\textbf{comet} to the screen, based on its current angle.\n%   \\item A procedure to \\textbf{Draw} the \\textbf{sun}.\n%   \\item A procedure to \\textbf{draw} the entire \\textbf{system}, including the sun and the comet at a given angle.\n%   \\item The main procedure to coordinate actions (calling, draw system with different angle values).\n% \\end{itemize}\n% \n% \\clearpage\n% \n% \\csection{\\ccode{clst:comet-orbit}{Comet Orbit, continued in \\lref{clst:comet-orbit1}}{topics/storing-using-data/examples/comet-orbit.cpp}}\n% \n% \\begin{figure}[p]\n% \\csection{\\ccode{clst:comet-orbit1}{Comet Orbit, continued in \\lref{clst:comet-orbit2}}{topics/storing-using-data/examples/comet-orbit1.cpp}}\n% \\end{figure}\n% \n% \\begin{figure}[p]\n% \\csection{\\ccode{clst:comet-orbit2}{Comet Orbit}{topics/storing-using-data/examples/comet-orbit2.cpp}}\n% \\end{figure}\n% \n% % subsection comet_orbit (end)\n", "meta": {"hexsha": "af2718db6f46ca84ed101e3a76e85e528822e66a", "size": 8862, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "topics/storing-using-data/examples/data-examples.tex", "max_stars_repo_name": "thoth-tech/programming-arcana", "max_stars_repo_head_hexsha": "bb5c0d45355bf710eff01947e67b666122901b07", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-10T04:50:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-10T04:50:54.000Z", "max_issues_repo_path": "topics/storing-using-data/examples/data-examples.tex", "max_issues_repo_name": "thoth-tech/programming-arcana", "max_issues_repo_head_hexsha": "bb5c0d45355bf710eff01947e67b666122901b07", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-12-29T19:45:10.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-29T19:45:10.000Z", "max_forks_repo_path": "topics/storing-using-data/examples/data-examples.tex", "max_forks_repo_name": "macite/programming-arcana", "max_forks_repo_head_hexsha": "8f3040983d420129f90bcc4bd69a96d8743c412c", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-06-02T03:18:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T07:42:53.000Z", "avg_line_length": 41.0277777778, "max_line_length": 483, "alphanum_fraction": 0.7384337621, "num_tokens": 2622, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8840392848011834, "lm_q1q2_score": 0.7078431848789352}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage{enumitem}\n\\usepackage{physics}\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{1em}\n\\relpenalty=10000\n\\binoppenalty=10000\n\\renewcommand{\\thesubsection}{\\arabic{subsection}}\n\\renewcommand*{\\theenumi}{\\thesubsection.\\arabic{enumi}}\n\n\\begin{document}\n\\section*{Functional equations}\n\n\\subsection{Injective and surjective functions}\n\t\\begin{itemize}\n\t\t\\item \n\t\tIf $f(x)=f(y) \\Rightarrow x=y$, then $f$ is injective\n\t\t\\item \n\t\tIf for each element $y$ in function codomain, there exists $x$ for which $f(x)=y$, then $f$ is surjective.\n\t\t\\item\n\t\tIf $f$ is both injective and surjective then $f$ is bijective.\n\t\\end{itemize}\n\n\t\\subsubsection*{Problems}\n\t\t\\begin{enumerate}\n\t\t\t\\item\n\t\t\tLet $f: X \\to Y$ and $g: Y \\to X$ and $g(f(x))=x$. Prove that $f$ is injective and $g$ is surjective.\n\t\t\t\\item \n\t\t\tProve that for any function $f: X \\to Y$, there exists a set $Z$ and functions $g: X \\to Z$ and $h: Z\\to Y$, such that $g$ is injective and $h$ is surjective.\n\t\t\t\\item \n\t\t\tFind all strictly monotonic functions $f: \\mathbb{R} \\to \\mathbb{R}$ which satisfy \n\t\t\t$$f(x + f(y)) = f(x) + y$$\n\t\t\\end{enumerate}\n\n\t\\subsection{Cauchy functional equations} % Most from Engel book\n\t\t\\begin{enumerate}\n\t\t\t\\item\n\t\t\tFind all functions $f: \\mathbb{Q} \\to \\mathbb{Q}$ for which $f(x)+f(y)=f(x+y)$.\n\t\t\t\\item \\label{conditions}\n\t\t\tIf the above functional equation satisfies any one of the following conditions, find the solutions to the functional equation if $f: \\mathbb{R} \\to \\mathbb{R}$.\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item The function is continuous at one point,\n\t\t\t\t\\item The function is monotonic on any interval,\n\t\t\t\t\\item The function is bounded on any interval.\n\t\t\t\\end{itemize}\n\t\t\t\\item \\label{eq:pow}\n\t\t\tFind all functions $f: \\mathbb{R^+} \\to \\mathbb{R^+}$ for which $f(x)f(y)=f(xy)$, given it satisfies any of the constraints defined in question \\ref{conditions}. \n\t\t\t\n\t\t\t\\item \\label{eq:log}\n\t\t\tFind all functions $f: \\mathbb{R^+} \\to \\mathbb{R}$ for which $f(x)+f(y)=f(xy)$, given it satisfies any of the constraints defined in question \\ref{conditions}.\n\t\t\t\n\t\t\t\\item \\label{eq:exp}\n\t\t\tFind all functions $f: \\mathbb{R} \\to \\mathbb{R^+}$ for which $f(x)f(y)=f(x+y)$, given it satisfies any of the constraints defined in question \\ref{conditions}.\n\t\t\t\n\t\t\t\\item  In what domains are the solutions of the functional equations defined in questions \\ref{eq:pow}-\\ref{eq:exp} the only solutions if they are not subject to any of the constraints defined in \\ref{conditions}?\n\t\t\t\n\t\t\t\\item Find all continuous functions $f: \\mathbb{R} \\to \\mathbb{R}$ for which\n\t\t\t$$f(x+y) + f(x-y) = 2f(x) + 2f(y) $$\n\t\t\t\n\t\t\t\\item Find all continuous functions $f: \\mathbb{R} \\to \\mathbb{R}$ for which\n\t\t\t$$f(x+y) + f(x-y) = 2f(y) $$\n\t\t\t\n\t\t\t\\item Find all continuous functions $f: \\mathbb{R} \\to \\mathbb{R}$ for which\n\t\t\t$$f(x+y) + f(x-y) = 2f(x) $$\n\t\t\t\n\t\t\t\\item Find all continuous functions $f: \\mathbb{R} \\to \\mathbb{R}$ for which\n\t\t\t$$f(x+y) + f(x-y) = 2f(x) f(y) $$\n\t\t\t\t\n\t\\end{enumerate}\n\t\n\t\\subsection{Recurrence relations} % https://artofproblemsolving.com/wiki/index.php/Characteristic_polynomial\n\t\t\\begin{itemize}\n\t\t\t\\item \n\t\t\tA recurrence relation is a relation that determines the elements of a sequence $x_n, n \\in \\mathbb{N}_0$, as a function of previous elements. A recurrence relation of the form\n\t\t\t$$(\\forall n \\geq k) \\hspace{2em} x_n + a_1x_{n-1} + \\hdots + a_kx_{n-k} = 0$$\n\t\t\tfor constants $a_1, \\hdots, a_k$ is called a linear homogeneous recurrence relation of order $k$.\n\t\t\t\\item\t\n\t\t\tWe define the characteristic polynomial of the relation as \n\t\t\t$$P(x) = x^k + a_1x^{k-1} + \\hdots + a_k$$\n\t\t\t\\item\n\t\t\tLet $P(x)$\tfactorize as \n\t\t\t$$P(x) = (x-\\alpha_1)^{k_1}(x-\\alpha_2)^{k_2} \\hdots (x-\\alpha_r)^{k_r}$$\n\t\t\twhere $\\alpha_1, \\hdots , \\alpha_r$ are distinct complex numbers and $k_1, \\hdots, k_r$ are positive integers. \n\t\t\t\\item \n\t\t\tThe general solution of this recurrence relation is in this case given by\n\t\t\t$$x_n = p_1(n)\\alpha_1^n + p_2(n)\\alpha_2^n + \\hdots + p_r(n)\\alpha_r^n$$\n\t\t\twhere $p_i$ is a polynomial of degree less than $k_i$.\n\t\t\t\\item\n\t\t\tIn particular, if $P(x)$ has $k$\n\t\t\tdistinct roots, then all $p_i$ are constant.\n\t\t\t\\item \n\t\t\tIf $x_0, \\hdots, x_{k-1}$ are set, then the coefficients of the polynomials are uniquely determined.\n\t\t\\end{itemize}\n\t\t\t\n\t\t\t\\subsubsection*{Problems}\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item \n\t\t\t\tFind the closed form expression for $n$-th term of the Fibonacci sequence.\n\t\t\t\t\\item\n\t\t\t\tLet $S_n$ denote the number of ternary sequences (consisting of $0$,$1$, and $2$s) of length $n$, such that they do not contain a substring of \"10\", \"01\", or \"11\". Find a closed form expression for $S_n$.\n\t\t\t\t\\item\n\t\t\t\tLet $r$ be a real number, and let $x_n$ be a sequence such that $x_0 = 0, x_1 = 1$, and $x_{n+2} = rx_{n+1} - x_n$ for $n \\ge 0$. For which values of $r$ does $x_1 + x_3 + \\cdots + x_{2m-1} = x_m^2$ for all positive integers $m$?\n\t\t\t\t\\item\n\t\t\t\tLet $a_{n}$, $b_{n}$, and $c_{n}$ be geometric sequences with different common ratios and let $a_{n}+b_{n}+c_{n}=d_{n}$ for all integers $n$. If $d_{1}=1$, $d_{2}=2$, $d_{3}=3$, $d_{4}=-7$, $d_{5}=13$, and $d_{6}=-16$, find $d_{7}$.\n\t\t\t\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "31808865a22cc27c52e9c88574925d5ff97e5573", "size": 5263, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11_functionalequations.tex", "max_stars_repo_name": "ZhaoWanLong/maths-olympiad", "max_stars_repo_head_hexsha": "0dcacba8a6d1769bbccfedda89d08fa22c3f55a1", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-21T21:57:43.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-21T21:57:43.000Z", "max_issues_repo_path": "11_functionalequations.tex", "max_issues_repo_name": "ZhaoWanLong/maths-olympiad", "max_issues_repo_head_hexsha": "0dcacba8a6d1769bbccfedda89d08fa22c3f55a1", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "11_functionalequations.tex", "max_forks_repo_name": "ZhaoWanLong/maths-olympiad", "max_forks_repo_head_hexsha": "0dcacba8a6d1769bbccfedda89d08fa22c3f55a1", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-08T07:04:43.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-08T07:04:43.000Z", "avg_line_length": 47.8454545455, "max_line_length": 236, "alphanum_fraction": 0.6631198936, "num_tokens": 1864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.884039278690883, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.7078431736797522}}
{"text": "\\lab{Solitons}{Solitons}\n\\label{lab:solitons}\n\n\\objective{\nWe study traveling wave solutions of the Korteweg-de Vries (KdV) equation, using a pseudospectral discretization in space and a Runge-Kutta integration scheme in time.  }\n\nHere we consider soliton solutions of the Korteweg-de Vries (KdV) equation. This equation is given by \n\\[  \\frac{\\partial u }{\\partial t} + u \\frac{\\partial u}{\\partial x} + \\frac{\\partial^3 u}{\\partial x^3} = 0.\n\\]\nThe KdV equation is a canonical equation that describes shallow water waves. \n\nThe KdV equation possesses traveling wave solutions called solitons.  \nThese traveling waves have the form \n\\[ u(x,t) = 3s \\sech^2\\left(\\frac{\\sqrt{s}}{2}(x - st - a)\\right),\n\\]\nwhere $s$ is the speed of the wave. \nSolitons were first studied by John Scott Russell in 1834, in the Union Canal in Scotland. \nWhen a canal boat suddenly stopped, the water piled up in front of the boat continued moving down the canal in the shape of a pulse.  \n\nNote that there is a soliton solution for each wave speed $s$, and that the amplitude of the soliton depends on the speed of the wave. \nSolitons are traveling waves in the shape of a pulse, they are nonlinearly stable (bumped waves return to their previous shape), and they maintain their energy as they travel. \nThey also enjoy an additional stability property: they play well with others. \nTwo interacting solitons will maintain their shape after crossing paths. \n\n\\section*{Numerical solution}\nConsider the KdV equation on $[-\\pi,\\pi]$, together with an appropriate initial condition: \n\\begin{align*}\n\t &{ }u_t = -\\left(\\frac{u^2}{2} \\right)_x - u_{xxx},\\\\\n     &{ }u(x,0) = u_0(x).\n\\end{align*}\nWe will use initial data that is zero at the endpoints.\nThis will allow us to use a pseudospectral method for periodic initial data to find a numerical approximation for the solution $u(x,t)$. \n\nIf we use $N$ subintervals in space, we then obtain the spatial step $h = 2\\pi/N$ and the grid points $\\{x_j\\}_{j=1} = \\{-\\pi,-\\pi + h,\\ldots,\\pi-h\\}$.  \nLet $\\mathcal{F}(u)(t) = \\hat{u}(t)$ denote the Fourier transform of $u(x,t)$ (in space), so that \n\\[\n\\mathcal{F}(u) = \\hat{u}(k,t), \\quad k=-N/2+1, \\ldots, N/2.\n\\]\nSimilarly we let $\\mathcal{F}^{-1}$ represent the discrete inverse Fourier transform.\nRecall that $k$ represents the wave numbers in Fourier space; our code defines it by \n\\begin{lstlisting}\n# Array of wave numbers.  This array is reordered in Python to \n# accomodate the ordering inside the fft function in scipy.\nk = np.concatenate(( np.arange(0,N/2) ,\n\t\t\t\t\t np.array([0])\t,\n\t\t\t\t\t np.arange(-N/2+1,0,1)\t)).reshape(N,)\n\\end{lstlisting}\n\nWe now apply the Fourier transform to the KdV equation.\nIn Fourier space, we obtain \n\\begin{align*}\n\t\\mathcal{F}(u)_t &= -\\frac{ik}{2}\\mathcal{F}(u^2)- (ik)^3\\mathcal{F}(u).\n\\end{align*}\nLet $U(t)$ be the vector valued function given by $U(t) = (u(x_j,t))_{j=1}^N$.\nLet $\\mathcal{F}(U)(t)$ denote the discrete Fourier transform of $u(x,t)$ (in space), so that \n\\[\n\\mathcal{F}(U)(t) = (\\mathcal{F}(u)(k,t))_{k=-N/2+1}^{N/2}.\n\\]\nSimilarly we let $\\mathcal{F}^{-1}$ represent the discrete inverse Fourier transform.\nUsing the pseudospectral approximation in space leads to the system of ODEs\n\\begin{align}\n\t\\mathcal{F}(U)_t =  -\\frac{i}{2} \\vec{k}\\mathcal{F}\\left( \\mathcal{F}^{-1}(\\mathcal{F}(U))^2\\right) + i\\vec{k}^3\\mathcal{F}(U)\n\\end{align}\nwhere $\\vec{k}$ is a vector, and multiplication is done element-wise. In terms of $Y = \\mathcal{F}(U)$, this simplifies to \n\\begin{align}\n\tY_t =  -\\frac{i}{2} \\vec{k}\\mathcal{F}\\left( \\mathcal{F}^{-1}(Y)^2\\right) + i\\vec{k}^3Y\n\t\\label{lab:solitons:pseudospectral}\n\\end{align}\nand is implemented below.\n\\begin{lstlisting}\n# Defines the left hand side of the ODE y' = G(t,y)\n# defined above.\nik3 = 1j*k**3.\ndef G_unscaled(t,y):\n\tout = -.5*1j*k*fft(ifft(y,axis=0)**2.,axis=0)  + ik3*y        \n\treturn out\n\\end{lstlisting}\n\nEquation \\eqref{lab:solitons:pseudospectral} is solved below, using a soliton as initial data for the KdV equation. \nNote that the Fourier transform must be applied to the soliton before solving, and that the final numerical solution must be transformed back from Fourier space before plotting. \n\\begin{lstlisting}\nN = 256\nx = (2.*np.pi/N)*np.arange(-N/2,N/2).reshape(N,1)   # Space discretization\ns, shift = 25.**2., 2.  \t\t\t\t\t\t\t# Initial data is a soliton\ny0 = (3.*s*np.cosh(.5*(sqrt(s)*(x+shift)))**(-2.)).reshape(N,) \n\n# Solves the ODE.\nmax_t = .0075\ndt = .2*N**(-2.)\nmax_tsteps = int(round(max_t/dt))\ny0 = fft(y0,axis=0)\nT,Y = RK4(G_unscaled, y0, t0=0, t1=max_t, n=max_tsteps)\n\n# Using the variable stride, we step through the data, \n# applying the inverse fourier transform to obtain u.\n# These values will be plotted.\nstride = int(np.floor((max_t/25.)/dt))\nuvalues, tvalues = np.real(ifft(y0,axis=0)).reshape(N,1), np.array(0.).reshape(1,1)\nfor n in range(1,max_tsteps+1):\n\tif np.mod(n,stride) == 0:\n\t\tt = n*dt\n\t\tu = np.real( ifft(Y[n], axis=0) ).reshape(N,1)\n\t\tuvalues = np.concatenate((uvalues,np.nan_to_num(u)),axis=1)\n\t\ttvalues = np.concatenate((tvalues,np.array(t).reshape(1,1)),axis=1)\n\nfig = plt.figure()\nax = fig.gca(projection='3d')\nax.view_init(elev=45., azim=150)\ntv, xv = np.meshgrid(tvalues,x,indexing='ij')\nsurf = ax.plot_surface(tv,xv, uvalues.T, rstride=1, cstride=1, cmap=cm.coolwarm,\n\t\t\t\t\t\tlinewidth=0, antialiased=False)\ntvalues = tvalues[0]; ax.set_xlim(tvalues[0], tvalues[-1])\nax.set_ylim(-pi, pi); ax.invert_yaxis()\nax.set_zlim(0., 4000.)\nax.set_xlabel('T'); ax.set_ylabel('X'); ax.set_zlabel('Z')\nplt.show()\n\\end{lstlisting}\n\nThe method we have used requires the use of an algorithm for (ODE) initial value problems, such as the RK4 algorithm.\nThe RK4 method is implemented below.\n\\begin{lstlisting}\ndef initialize_all(y0, t0, t1, n):\n\t\"\"\" An initialization routine for the different ODE solving\n\tmethods in the lab. This initializes Y, T, and h. \"\"\"\n\t\n\tif isinstance(y0, np.ndarray):\n\t\tY = np.empty((n, y0.size),dtype=complex).squeeze()\n\telse:\n\t\tY = np.empty(n,dtype=complex)\n\tY[0] = y0\n\tT = np.linspace(t0, t1, n)\n\th = float(t1 - t0) / (n - 1)\n\treturn Y, T, h\n\ndef RK4(f, y0, t0, t1, n):\n\t\"\"\" Use the RK4 method to compute an approximate solution\n\tto the ODE y' = f(t, y) at n equispaced parameter values from t0 to t\n\twith initial conditions y(t0) = y0.\n\t\n\t'y0' is assumed to be either a constant or a one-dimensional numpy array.\n\t't0' and 't1' are assumed to be constants.\n\t'f' is assumed to accept two arguments.\n\tThe first is a constant giving the current value of t.\n\tThe second is a one-dimensional numpy array of the same size as y.\n\t\n\tThis function returns an array Y of shape (n,) if\n\ty is a constant or an array of size 1.\n\tIt returns an array of shape (n, y.size) otherwise.\n\tIn either case, Y[i] is the approximate value of y at\n\tthe i'th value of np.linspace(t0, t, n).\n\t\"\"\"\n\tY, T, h = initialize_all(y0, t0, t1, n)\n\tfor i in xrange(1, n):\n\t\tK1 = f(T[i-1], Y[i-1])\n\t\ttplus = (T[i] + T[i-1]) * .5\n\t\tK2 = f(tplus, Y[i-1] + .5 * h * K1)\n\t\tK3 = f(tplus, Y[i-1] + .5 * h * K2)\n\t\tK4 = f(T[i], Y[i-1] + h * K3)\n\t\tY[i] = Y[i-1] + (h / 6.) * (K1 + 2 * K2 + 2 * K3 + K4)\n\treturn T, Y\n\\end{lstlisting}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{soliton.png}\n\\caption{The solution to Problem \\ref{problem:solitons:single}.}\n\\label{fig:solitons:single}\n\\end{figure}\n\n\\begin{problem}\nRun the code above to numerically solve the KdV equation on $[-\\pi,\\pi]$ with initial conditions \n\\[\nu(x,t=0) = 3s\\sech^2\\left(\\frac{\\sqrt{s}}{2}(x+a)\\right),\n\\]\nwhere $s = 25^2,$ $a = 2$. Solve on the time domain $[0,.0075]$.\nThe solution is shown in Figure \\ref{fig:solitons:single}.\n\\label{problem:solitons:single}\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{interacting_solitons.png}\n\\caption{The solution to Problem \\ref{problem:solitons:interacting}.}\n\\label{fig:solitons:interacting}\n\\end{figure}\n\n\\begin{problem}\nNumerically solve the KdV equation on $[-\\pi,\\pi]$.\nThis time we define the initial condition \nto be the superposition of two solitons,\n\\[\nu(x,t=0) = 3s_1\\sech^2\\left(\\frac{\\sqrt{s_1}}{2}(x+a_1)\\right) + 3s_2\\sech^2\\left(\\frac{\\sqrt{s_2}}{2}(x+a_2)\\right),\n\\]\nwhere $s_1 = 25^2,$ $a_1 = 2$, and $s_2 = 16^2,$ $a_1 = 1$.\\footnote{This problem is solved in \\textit{Spectral Methods in MATLAB}, by Trefethen.}\nSolve on the time domain $[0,.0075]$.\nThe solution is shown in Figure \\ref{fig:solitons:interacting}.\n\\label{problem:solitons:interacting}\n\\end{problem}\n\n\\begin{problem}\nConsider again equation \\eqref{lab:solitons:pseudospectral}.\nThe linear term in this equation is $i\\vec{k}^3Y$.\nThis term contributes much of the exponential growth in the ODE, and responsible for how short the time step must be to ensure numerical stability.\nMake the substitution $Z = e^{-ik^3t}Y$ and find a similar ODE for $Z$.\nThis essentially allows the exponential growth to be scaled out (it's solved for analytically).\nUse the resulting equation to solve the previous problem.\n\\end{problem}", "meta": {"hexsha": "5b2e2ad69b98767c9c62d499e3171710519938da", "size": 8947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume4/Solitons/Solitons.tex", "max_stars_repo_name": "DM561/dm561.github.io", "max_stars_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-13T13:22:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-13T13:22:41.000Z", "max_issues_repo_path": "acme-material/Labs/Volume4/Solitons/Solitons.tex", "max_issues_repo_name": "DM561/dm561.github.io", "max_issues_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-10-18T19:57:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-31T19:00:36.000Z", "max_forks_repo_path": "acme-material/Labs/Volume4/Solitons/Solitons.tex", "max_forks_repo_name": "DM561/dm561.github.io", "max_forks_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.2222222222, "max_line_length": 178, "alphanum_fraction": 0.6948697888, "num_tokens": 2944, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694178, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7078414211197069}}
{"text": "\\section*{Problem 1 Solution}\n\n\\begin{enumerate}[a)]\n\n\\item \n\nA macroscopic cross section for a homogeneous mixture of materials can be found by summing the cross sections of those components, weighted by their volume fractions: \n\\begin{equation}\n\\label{gentotmacroXS}\n\\Sigma = \\sum_{i} \\frac{V_i}{V_t}\\Sigma_i\n\\end{equation}\nwhere $\\Sigma_i$ is the macroscopic cross section of the $i^{\\text{th}}$ material, $V_i$ is the volume of the $i^{\\text{th}}$ material, and $V_t$ is the total volume. For this problem, we are told that the fraction $\\frac{V_{\\text{UO2}}}{V_t} = 0.15$ and $\\frac{V_{\\text{H2O}}}{V_t} = 0.85$. Using these in equation (\\ref{gentotmacroXS}) the total macroscopic cross section of our reactor can be expressed just in terms of the macroscopic cross sections of UO$_2$ and H$_2$O.\n\\begin{equation}\n\\label{totmacroXS}\n\\Sigma = 0.15\\Sigma_{\\text{UO2}} + 0.85\\Sigma_{\\text{H2O}}\n\\end{equation}\nCalculating these two macroscopic cross sections requires knowledge of each of the individual microscopic cross sections of the compounds, since the macroscopic cross section is defined as\n\\begin{equation}\n\\label{macroXSi}\n\\Sigma_i = n_i\\sigma_i ,\n\\end{equation}\nwhere $n_i$ and $\\sigma_i$ are respectively the number density and total microscopic cross sections of the compounds. While neither of these quantities are given explicitly, we can calculate each from the information provided. \n\\-\\\\\n\nWe can find a compound's number density by dividing the weight density by the mass of one molecule of the compound. \n$$ n_i = \\frac{\\rho_i}{m_i} $$\nThe densities for UO$_2$ and H$_2$O are provided, and we can find the mass of a molecule by dividing the molar mass of the material by Avogadro's number, $N_A = 6.022\\times10^{23}\\text{ molecules/mol}$.\n$$ m_i = \\frac{M_i}{N_A}, $$\nand so\n$$ n_i = \\frac{\\rho_i N_A}{M_i} .$$\nFor our two compounds, UO$_2$ and H$_2$O these number densities are\n$$ n_{\\text{UO}_2} = \\frac{\\rho_{\\text{UO}_2} N_A}{M_{\\text{UO}_2}} \\qquad\\text{and}\\qquad n_{\\text{H}_2\\text{O}} = \\frac{\\rho_{\\text{H}_2\\text{O}} N_A}{M_{\\text{H}_2\\text{O}}} .$$\nBefore moving on to finding the microscopic cross sections, we can note that the molar mass of the compounds can be broken into the sum of the molar masses of their constituents according to their fraction in the compound.\n$$ n_{\\text{UO}_2} = \\frac{\\rho_{\\text{UO}_2} N_A}{f_{\\text{U}5}M_{\\text{U235}} + f_{\\text{U}8}M_{\\text{U238}} + 2M_{\\text{O}}} \\qquad\\text{and}\\qquad n_{\\text{H}_2\\text{O}} = \\frac{\\rho_{\\text{H}_2\\text{O}} N_A}{2M_{\\text{H}} + M_{\\text{O}}} .$$\n\\-\\\\\n\nNext, we look at microscopic cross sections. The microscopic cross section of a compound is given by the sum of the microscopic cross sections of it's elemental components. The complete microscopic cross section for water can be found using this fact.\n$$ \\sigma_{\\text{H2O}} = 2\\sigma_{\\text{H}} + \\sigma_{\\text{O}} $$\nThe microscopic cross section for UO$_2$ can be found similarly, however the calculation is slightly more complicated due to its enrichment in $^{235}$U. First, we find the average microscopic cross section for uranium by weighting the cross sections of $^{235}$U and $^{238}$U by their abundance.\n$$ \\sigma_{\\text{U}} = f_{\\text{U}5} \\sigma_{\\text{U}5} + f_{\\text{U}8} \\sigma_{\\text{U}8} $$\nwhere $f_{i}$ is the atomic fraction of material $i$ in the compound (for uranium in this case, this fraction is just the enrichment in atom \\%). Then, we can complete the process exactly as we did for H$_2$O,\n\\begin{align*}\n\\sigma_{\\text{UO}_2}\t&= \\sigma_{\\text{U}} + 2\\sigma_{\\text{O}} \\\\\n\t\t\t\t\t\t&= f_{\\text{U}5} \\sigma_{\\text{U}5} + f_{\\text{U}8} \\sigma_{\\text{U}8}  + 2\\sigma_{\\text{O}}. \n\\end{align*}\n\\-\\\\\n\nCombining these number densities and macroscopic cross sections, we can expand and rewrite the macroscopic cross sections described by equation (\\ref{macroXSi}) as\n%$$ \\Sigma_{\\text{UO}_2} = \\frac{\\rho_{\\text{UO}_2} \\left( f_{\\text{U}5} \\sigma_{\\text{U}5} + f_{\\text{U}8} \\sigma_{\\text{U}8}  + 2\\sigma_{\\text{O}}\\right) N_A}{f_{\\text{U}5}M_{\\text{U235}} + f_{\\text{U}8}M_{\\text{U238}} + 2M_{\\text{O}}} \\qquad\\text{and}\\qquad \\Sigma_{\\text{H}_2\\text{O}} = \\frac{\\rho_{\\text{H}_2\\text{O}} \\left(2\\sigma_{\\text{H}} + \\sigma_{\\text{O}}\\right) N_A}{2M_{\\text{H}} + M_\\text{O}} $$\nNow we can substitute the given values. \n$$ \\Sigma_{\\text{UO}_2} = \\frac{\\left(10.4\\text{ g/cm}^3\\right) \\left(0.05(607.5\\text{ b}) + 0.95(11.8\\text{ b})  + 2(3.5\\text{ b})\\right)\\left(6.022\\times10^{23}\\text{ mol}^{-1}\\right)}{0.05(235.044\\text{ g/mol}) + 0.95(238.050\\text{ g/mol}) + 2(15.995\\text{ g/mol})} $$\n$$ \\Sigma_{\\text{UO}_2} = 112.7\\text{ m}^{-1} $$\n\n$$ \\Sigma_{\\text{H}_2\\text{O}} = \\frac{\\left(1.0\\text{ g/cm}^3\\right) \\left(2(20.8\\text{ b}) + 3.5\\text{ b}\\right) \\left(6.022\\times10^{23}\\text{ mol}^{-1}\\right)}{2(1.008\\text{ g/mol}) + 15.995\\text{ g/mol}} $$\n$$ \\Sigma_{\\text{H}_2\\text{O}} = 150.8\\text{ m}^{-1} $$\n\nand plug these into equation (\\ref{totmacroXS}) for the total cross section of the core.\n$$ \\Sigma = 0.15(112.7\\text{ m}^{-1}) + 0.85(150.8\\text{ m}^{-1})\n $$\n$$\\boxed{ \\Sigma = 145.085\\text{ m}^{-1} }$$\n\n\\item \n\nNeutron attentuation follows a decaying exponential according to the equation\n$$ N = N(0) \\, e^{-\\Sigma x} $$\nwhere $N$ is the number of neutrons (you may be more familiar with this equation in terms of intensity; we have just eliminated the area and rate components from both sides).\n\nWe let $N(0)$ be our initial number of incident particles, $10^{15}$, $\\Sigma$ be the macroscopic cross section calculated in part (a), and $x$ be the distance traveled by the neutrons, 4 m.  \n$$ N = 10^{15} e^{(-145.085\\text{ m}^{-1})(4\\text{ m})} $$\nThis works out to be about $9.153\\times10^{-238}$, or \\underline{zero particles}.\n$$ N = 0 $$\nNote that this number only indicates the quantity of particles which make it through the core uncollided. Since many of these interactions are scattering collisions, and not absorptive events, it is quite possible that some neutrons will eventually make it through the reactor. A more complicated derivation would be required in that case.\n\\end{enumerate}\n\n", "meta": {"hexsha": "79cc51695a5a84d57f63a0105bda0b6a1eb38f99", "size": 6088, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc04/disc04_solution01.tex", "max_stars_repo_name": "mitchnegus/NE150-discussion", "max_stars_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/drafts/disc04/disc04_solution01.tex", "max_issues_repo_name": "mitchnegus/NE150-discussion", "max_issues_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/drafts/disc04/disc04_solution01.tex", "max_forks_repo_name": "mitchnegus/NE150-discussion", "max_forks_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 81.1733333333, "max_line_length": 475, "alphanum_fraction": 0.6954664915, "num_tokens": 2093, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694178, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7078414193154118}}
{"text": "\\chapter{Resampling methods: Bias, Variance, and their trade-off}\nWe have defined various smoothers and nonparametric estimation\ntechniques. In classical statistical theory we usually assume that the\nunderlying model generating the data is in the family of models we\nare considering. For nonparametrics this assumptions is relaxed and\nasymptotic and finite sample bias and variance \nestimates are not always easy to find in closed form. In this Chapter\nwe discuss some resampling methods that are commonly used to get\napproximations of bias, variance, confidence intervals, etc... \n\nIn particular we will look at the problem of choosing smoothing\nparameters. Remember how most of the smoothers we have defined have\nsome parameter that controls the smoothness of the final smooth or\ncurve estimate. For kernel smoothers we defined the scale parameter, for\nlocal regression we defined the span or bandwidth, and for smoothing\nsplines we had the penalty term. We will call all of these {\\it\nthe  smoothing parameter} and denote it with $\\lambda$. It should be\nclear from the context which of the specific smoothing parameters we\nare referring to.\n\n\n\\input{section-05-01.tex}\n\\input{section-05-02.tex}\n\\input{section-05-03.tex}", "meta": {"hexsha": "a3f924cbfc14fbaf7e2273273114e1f843514211", "size": 1223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-05.tex", "max_stars_repo_name": "igrabski/rafalab.github.io", "max_stars_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2016-08-17T23:04:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T19:21:02.000Z", "max_issues_repo_path": "pages/754/section-05.tex", "max_issues_repo_name": "igrabski/rafalab.github.io", "max_issues_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-18T00:41:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-21T22:35:40.000Z", "max_forks_repo_path": "pages/754/section-05.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 50.9583333333, "max_line_length": 72, "alphanum_fraction": 0.8103025348, "num_tokens": 271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.828938799869521, "lm_q1q2_score": 0.7078414187885783}}
{"text": "\\subsection{The Single-Vector Lanczos Algorithm}\n\nWe are armed now with all the required tools to present the main\nalgorithm that is used for SVD, in the context of LSI (at least in the\nserial form). As mentioned on the introductory section of this\nchapter, the algorithm exists thanks to Berry\n(\\cite{berry92},\\cite{berry95}); we should probably present our\nrespects to Berry in this moment, as he worked for more than a decade\naround the particular problem of solving efficiently the SVD/LSI\nproblem (and in essence, today's applications still use his\ncontributions). \\\\\n\nThe \\cref{alg:lasvd} we present below is not the final one, as there are more\npractical considerations to cover at the end of this subsection; but it is\neasier to present this simplified version, as it has all the main\ningredients. We can see in particular, how it combines Lanczos\nTridiagonalization Step (\\cref{alg:lanczos-step}) (which implicitly\nuses the Power Method \\cref{alg:power-method}), with the Rayleigh-Ritz\nMethod (\\cref{alg:ritz}). \\\\\n\nWe also take the opportunity to come back to our original context,\nwhere $A$ is a large and sparse matrix coming from an LSI problem. The\npseudocode is based on \\cite{berry92}, filling additional details\nfrom the C code of the implemented routine (LAS2) \\footnote{Originally\nthe routine was coded in Fortran77, but we found more comfortable to\ncheck the C port instead; both made by Berry, by the way.}.\n\n\\begin{algorithm}\n  \\label{alg:lasvd}\n  \\caption{The Single-Vector Lanczos Algorithm}\n%\n  \\setstretch{1}\n  \\SetKwInOut{Input}{Input}\n  \\SetKwInOut{Output}{Output}\n  \\DontPrintSemicolon\n%\n    \\Input{A matrix $A^{m \\times n}$ and a truncation factor\n    $k$}\n    \\BlankLine\n%\n    \\Output{The $k$ singular values and its associated right singular\n      vectors of $A$ \\footnote{The eigenvectors of matrix $\\trans{A}A$ are called\n        right singular vectors of $A$, while those of $A\\trans{A}$ are the\n        left singular vectors.} (which are the first $k$ eigenpairs of\n      symmetric matrix $\\trans{A}A$). Both are numeric approximations. } \n    \\BlankLine\n    \\BlankLine\n%\n    Use Lanczos Tridiagonalization step \\cref{alg:lanczos-step} to\n    generate a family of symmetric tridiagonal matrices, $\\{ T_j \\} (j\n    = 1,2, \\dots, c) \\suchthat c > k$. Note that these matrices\n    approximate the eigenvalues of symmetric matrix\n    $\\trans{A}A$\\ (which happen to be the singular values of $A$). \\;\n    \\BlankLine\n    \\BlankLine\n%\n    \\strut Compute the eigenvalues and eigenvectors of $T_k$ using the\n    (implicit) QL Method. \\;\n    \\BlankLine\n    \\BlankLine\n%   \n    For each computed eigenvalue $\\lambda_i$ of $T_k$ (hence of gramian matrix\n    $\\trans{A}A$), calculate the associated unit eigenvector $\\vec{z_i}$\n    such that $T_k\\vec{z_i} = \\lambda_i\\vec{z_i}$. \\;\n    \\BlankLine\n    \\BlankLine\n% \n    For each calculated eigenvector $\\vec{z_i}$ of $T_k$, compute the Ritz\n    vectors $v_i = Q_c\\vec{z_i}$ as an approximation to the\n    $i$-th eigenvector of $\\trans{A}A$ (hence, to the right singular\n    vectors of $A$). Note that the matrix $Q_c$ is a side product of\n    the first step. \\; \n    \\BlankLine\n    \\BlankLine\n%\n    return $(\\{\\lambda_1,\\lambda_2,\\cdots,\\lambda_k\\},\n            \\{\\vec{v_1},\\vec{v_2},\\cdots,\\vec{v_k}\\})$\n\\end{algorithm}\n\\hfill\n\nAlthough complete in appearance, \\cref{alg:lasvd} still has a serious\nnumerical issue: the potential loss of orthogonality in the vectors of\nmatrix $Q_c$. To solve that problem, we could reorthogonalize all\nvectors at every execution of \\cref{alg:lanczos-step}; but that would\nbe kind of brute force, and eliminate the advantages of the whole\nproposal. A clever approach, selective reorthogonalization, was\nselected by Berry in order to complete his master-piece: the LASVD/LAS2\nroutine \\footnote{Berry actually proposed four different methods of\n  calculating SVD, for the LSI problem; LAS2 (descendant of LASVD)\n  routine is just one of them. But it seems the fastest, and it was the\n  only one ported to the new skin of Berry's SVDPACKC,\n  which is SVDLIBC \\cite{svdlibc}. Interestingly though, Berry\n  mentions in \\cite{berry91} that LASVD is suitable only for low to\n  medium precision in the singular values. A pending task then, is to\n  confirm of modern incarnations still have such limitation.}. \\\\\n\nThe selective reorthogonalization approach, as explained by Golub in\n\\cite{golub13}, is inspired on the error analysis made by Paige\n  \\cite{paige71}. Peige shows that the most recently computed vector\n  \\vec{\\tilde{q_{k+1}}}, tends to have a non trivial and unwanted\n  component in the direction of the already converged Ritz vectors\n  \\footnote{Recall that the Ritz vectors approximate the eigenvectors\n    of the gramian matrix of $A$, hence the singular vectors of\n    $A$}. Therefore, we do not need to re-orthogonalize against all\n  the previously calculated vectors, rather use only the already\n  converged ones. \\\\\n\nSuch adjustment is done during the Lanczos step\n(\\cref{alg:lanczos-step}), using a criteria devised by Parlett et al\n\\cite{parlett79}, which allows one to: know when a Ritz vector is\nconverged. \\\\\n\nBerry does not include a final pseudocode of his LASVD\nroutine (inspired on the LANSOS routine from Parlett, Simon et\nal). The routine eventually got renamed as LAS2 and made its way into\nthe famous SVDPACK (Fortran77) and SVDPACKC libraries; and more\nrecently in the modern version called SVDLIBC. It is the latest, which\nis currently used by several LSI applications. \n\n\n\n", "meta": {"hexsha": "937c4df890762aa3de0131e69c26e899a8589a7c", "size": 5506, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-lanczos-serial-alg.tex", "max_stars_repo_name": "rzavalet/svd-lsi-project-master", "max_stars_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "svd-lanczos-serial-alg.tex", "max_issues_repo_name": "rzavalet/svd-lsi-project-master", "max_issues_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "svd-lanczos-serial-alg.tex", "max_forks_repo_name": "rzavalet/svd-lsi-project-master", "max_forks_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.131147541, "max_line_length": 81, "alphanum_fraction": 0.7422811478, "num_tokens": 1524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339909, "lm_q2_score": 0.8289388083214155, "lm_q1q2_score": 0.7078414167604881}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\n\\section{Mean-square limit} \\label{app:mslim}\nSuppose that we have a probability space $\\Omega$, and a sequence of random variables $X_n$ defined on $\\Omega$. We say that $X_n$ converges to $X$ in the mean-square sense if\n\\begin{equation}\n\t\\lim_{n\\rightarrow \\infty} \\esp{(X_n-X)^2} = 0,\n\\end{equation}\nand we note\n\\begin{equation}\n\t\\mslim_{n\\rightarrow \\infty} X_n = X.\n\\end{equation}", "meta": {"hexsha": "c02b9d225b6cf3e22fd02b58d9a2e96c96babf4a", "size": 443, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/appendix/mslim.tex", "max_stars_repo_name": "dufaysr/tfe", "max_stars_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inputs/appendix/mslim.tex", "max_issues_repo_name": "dufaysr/tfe", "max_issues_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inputs/appendix/mslim.tex", "max_forks_repo_name": "dufaysr/tfe", "max_forks_repo_head_hexsha": "75c6191e1533da84233d4a38dea3cc3f3884a286", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.3, "max_line_length": 175, "alphanum_fraction": 0.7246049661, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582612793112, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.7077536887796076}}
{"text": "\\section{Lines \\& Planes as VVFs}\r\n\\noindent\r\nVVFs are parametric equations that take one input value and return one or more output values as a vector. We can draw curves in space by defining the tail of the output of the VVF be at the origin and have the tip trace out the curve. We will look at some simple VVFs that you need to be able to recognize.\\\\\r\n\\input{./vectorValuedFunctions/lines}\r\n\\input{./vectorValuedFunctions/planes}", "meta": {"hexsha": "dd35c1828d6f97612807a56cda4ac6588449345b", "size": 433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorValuedFunctions/LinesPlanesAsVVFs.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorValuedFunctions/LinesPlanesAsVVFs.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorValuedFunctions/LinesPlanesAsVVFs.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 86.6, "max_line_length": 309, "alphanum_fraction": 0.7782909931, "num_tokens": 111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765140114859, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.7077186510094372}}
{"text": "\\section*{Latent: Missing Data}\n\\subsection*{Mixture modeling}\nModel each cluster as probability distr. $P(x|\\theta_j)$\\\\\n%Assuming data iid, likelihood is\ndata iid, likelih.: $P(D|\\theta) = \\prod_{i=1}^n \\sum_{j=1}^k w_j P(x_i|\\theta_j)$\\\\\n%Choose parameters to minimize negative log l.\\\\\n$\\underset{min}{argmin}L(D;\\theta) = \\underset{min}{argmin} - \\sum_i log \\sum_j w_j P(x_i| \\theta_j)$\n\n\\subsection*{Gaussian-Mixture Bayes classifiers}\nEstimate class prior $P(y)$; Est. cond. distr. for each class:\n$P(x|y) = \\sum_{j=1}^{k_y} w_j^{(y)} \\mathcal{N}(x; \\mu_j^{(y)}, \\Sigma_j^{(y)})$\\\\\n$P(y|x) = \\frac{1}{P(x)} p(y) \\sum_{j=1}^{k_y} w_j^{(y)} \\mathcal{N}(x; \\mu_j^{(y)}, \\Sigma_j^{(y)})$\n\n\\subsection*{Hard-EM}\nInitialize parameters $\\theta^{(0)}$; For $t=1,2,..$ (predict most likely class for each data point):\\\\\n$z_i^{(t)} = \\underset{z}{\\operatorname{argmax}} P(z|x_i, \\theta^{(t-1)})\\\\\n= \\underset{z}{\\operatorname{argmax}} P(z|\\theta^{(t-1)}) P(x_i|z,\\theta^{(t-1)})$;\\\\\nCompute the MLE (see Gauss Bayes Classifier):\\\\\n$\\theta^{(t)} = \\underset{\\theta}{\\operatorname{argmax}} P(D^{(t)}|\\theta)$\n\n\\subsection*{Soft-EM: \"While not converged repeat\"}\nE-step: For each i and j calculate $\\gamma_j^{(t)}(x_i)$\\\\\nM-step: Fit clusters to weighted data points:\\\\\n\n$w_j^{(t)} \\leftarrow \\frac{1}{n} \\sum_{i=1}^n \\gamma_j^{(t)} (x_i)$;  %\\text{|semi-supervised}\\\\\n$\\mu_j^{(t)} \\leftarrow \\frac{\\sum_{i=1}^n \\gamma_j^{(t)} (x_i) x_i}{\\sum_{i=1}^n \\gamma_j^{(t)} (x_i)}\\\\ %\\text{|learning with GMMs } ^t = ^*\\\\\n\\Sigma_j^{(t)} \\leftarrow \\frac{\\sum_{i=1}^n \\gamma_j^{(t)}(x_i) (x_i - \\mu_j^{(t)}) (x_i - \\mu_j^{(t)})^T}{\\sum_{i=1}^n \\gamma_j^{(t)}(x_i)}$\\\\ %\\text{|}\\gamma^{(t) = \\gamma}$\nEM for semi-supervised learning with GMMs:\\\\\n%unlabeled points\nunl. p.: $\\gamma_j^{(t)}(x_i) = P(Z=j|x_i, \\mu^{(t-1)}, \\Sigma^{(t-1)}, w^{(t-1)})$\\\\\nlabeled points $y_i$: $\\gamma_j^{(t)}(x_i) = [j = y_i]$\n\n%If enough space put this on summary.\n%\\subsection*{Log-likelihood}\n%$l(\\theta) = log P(\\mathcal{D})$\\\\\n%$=\\sum_{\\overset{i=1}{y_i=\\times}}^n log P(x_i;\\theta) + \\sum_{\\overset{i=1}{y_i\\not=\\times}}^n log P(x_i,y_i;\\theta)$\\\\\n%$=\\sum_{\\overset{i=1}{y_i=\\times}}^n log \\sum_{j=1}^m P(x_i, Y=j;\\theta) +$\\\\\n%$ \\sum_{\\overset{i=1}{y_i\\not=\\times}}^n log P(x_i,y_i;\\theta)$\\\\\n%$=\\sum_{\\overset{i=1}{y_i=\\times}}^n log \\sum_{j=1}^m P(x_i|Y=j;\\theta)P(Y=j;\\theta) +$\\\\\n%$ \\sum_{\\overset{i=1}{y_i\\not=\\times}}^n log P(x_i,y_i;\\theta)$\n\n%Only until here.\n\\iffalse\n\\subsection*{Log-likelihood}\n$l(\\theta) = log P(\\mathcal{D})$ \\\\\n$=\\sum_{\\overset{i=1}{y_i=\\times}}^n log P(x_i;\\theta) + \\sum_{\\overset{i=1}{y_i\\not=\\times}}^n log P(x_i,y_i;\\theta)$\\\\\n$=\\sum_{\\overset{i=1}{y_i=\\times}}^n log \\sum_{i=1}^m P(x_i, Y=j;\\theta) +$\\\\\n$ \\sum_{\\overset{i=1}{y_i\\not=\\times}}^n log P(x_i,y_i;\\theta)$\\\\\n$=\\sum_{\\overset{i=1}{y_i=\\times}}^n log \\sum_{i=1}^m P(x_i|Y=j;\\theta)P(Y=j|\\theta) +$\\\\\n$ \\sum_{\\overset{i=1}{y_i\\not=\\times}}^n log P(x_i,y_i;\\theta)$\n\n\\subsection*{Latent variable}\nWe denote the latent variable indicating the component the point is sampled from by Z, which takes on values in $\\{1,...,k\\}$.\n\n\\subsection*{E-step: Posterior probabilities}\n$\\gamma_j^t(x_i) = P(Z=j|x_i, \\theta_t) = \\frac{P(x_i|Z=j, \\theta_t) P(Z=j|\\theta_t)}{P(x_i;\\theta_t)}$\n\n\\subsection*{M-step: maximizing expected log likelihood}\n$\\mathbb{E}_{\\gamma^t}[\\log P(\\mathcal{D;\\theta})] = \n\\mathbb{E}_{\\gamma^t}[\\log \\Pi_{i=1}^nP(x_i,z_i;\\theta)] = $ \\\\\n$\\sum_{i=1}^n \\mathbb{E}_{\\gamma^t}[\\log P(x_i,z_i;\\theta)] = $ \\\\\n$\\sum_{i=1}^n \\sum_{j=1}^k \\gamma_j^t(x_i) \\log (P(x_i|z_i=j;\\theta) P(z_i=j;\\theta))$ \\\\\n$\\theta_{t+1} = \\underset{\\theta}{\\operatorname{argmax}} \\mathbb{E}_{\\gamma^t}[\\log P(\\mathcal{D;\\theta})]$\n\\fi", "meta": {"hexsha": "44f9f39cb1b835e4d336edb51605ce9fb162afcc", "size": 3684, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/Latent.tex", "max_stars_repo_name": "meck93/intro_ml_ethz", "max_stars_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-04-24T14:58:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-19T14:02:08.000Z", "max_issues_repo_path": "source/Latent.tex", "max_issues_repo_name": "meck93/intro_ml_ethz", "max_issues_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/Latent.tex", "max_forks_repo_name": "meck93/intro_ml_ethz", "max_forks_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.5625, "max_line_length": 176, "alphanum_fraction": 0.6153637351, "num_tokens": 1570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7076947653183195}}
{"text": "\n\\newpage\n\n \\section{Linear neural networks}\n \n\\subsection{Linear NN experiments}\nOur main goal of this experiment is to test if deeper linear neural network can converge faster. we use linear MNIST with totally 60000 data points as our dataset. The first experiment randomly split this dataset into training set with 48000 training data points and 12000 test data points. The second experiment we use the full data as our training set.\\\\\nGenerally, we use a linear neural network model.  A linear NN with $H$ hidden layers can be modeled as\n\\begin{equation}\n\t\\bm f(x,\\bm\\theta) = W_{H+1}(W_H(\\cdots(W_1 x + b_1)\\cdots)+b_H)+b_{H+1}\n\\end{equation}\nwhere $W_1\\in \\mathbb{R}^{d_1\\times d_x}$, $b_1 \\in \\mathbb{R}^{d_1}$, $W_i\\in \\mathbb{R}^{d_{i}\\times d_{i-1}}$, $b_i \\in \\mathbb{R}^{d_i}$, $i = 2,\\cdots,H$, $W_{H+1}\\in \\mathbb{R}^{d_y\\times d_{H+1}}$, $b_{H+1} \\in \\mathbb{R}^{d_y}$. Notice that $d_x$ represents the input size which is 500 in this experiment, while $d_y$ represents the output size , namely, the number of classes, which is 10 in this experiment. So from now on, we may only  use an array $(d_x,d_1,\\cdots,d_H,d_y)$ to represent our model.\\\\\nWe use cross-entropy with $L_2$ regularization as our loss function.\n\\begin{equation}\n\tL(\\bm\\theta,D) = \\frac{1}{|D|} \\sum_{i = 1}^k \\sum_{x\\in D_i} (\\log ({\\bm 1}^T e^{\\bm f(x,\\bm\\theta)}) - f_i(x,\\bm\\theta)) + \\lambda \\sum_{j = 0}^{p+1} (\\|W_j\\|_F^2 + \\|b_j\\|_2^2)\n\\end{equation}\n\n\\begin{itemize}\n\t\\item Model.\\\\\n    \\begin{itemize}\n    \t\\item Net0 (500,10).\n    \t\\item Net1 (500,100,10)\n    \t\\item Net2 (500,200,100,10)\n    \t\\item Net3 (500,400,200,100,10)\n    \t\\item Net4 (500,800,200,100,10)\n    \\end{itemize}\n    \\item Training algorithm.\n    \\begin{itemize}\n    \t\\item Full gradient descent(GD).\n    \t    \\begin{equation}\n    \t    \t\\bm\\theta = \\bm\\theta - lr \\frac{\\partial L}{\\partial \\bm\\theta}\n    \t    \\end{equation} \n    \t\\item Coordinate descent(CD).\n    \t\\begin{align}\n    \t\t&\\bm\\theta_1^+ = \\bm\\theta_1 - lr \\frac{\\partial L}{\\partial \\bm\\theta_1}(\\bm\\theta_1,\\bm\\theta_2,\\cdots,\\bm,\\bm\\theta_p,\\theta_{p+1}),\\\\\n    \t\t&\\bm\\theta_2^+ = \\bm\\theta_2 - lr \\frac{\\partial L}{\\partial \\bm\\theta_2}(\\bm\\theta_1^+,\\bm\\theta_2,\\cdots,\\bm\\theta_p,\\bm\\theta_{p+1}),\\\\\n    \t\t&\\bm\\theta_3^+ = \\bm\\theta_3 - lr \\frac{\\partial L}{\\partial \\bm\\theta_3}(\\bm\\theta_1^+, \\bm\\theta_2^+,\\cdots,\\bm\\theta_p,\\bm\\theta_{p+1}),\\\\\n    \t\t&\\cdots,\\\\\n    \t\t&\\bm\\theta_{p+1}^+ = \\bm\\theta_{p+1} - lr \\frac{\\partial L}{\\partial \\bm\\theta_{p+1}}(\\bm\\theta_1^+, \\bm\\theta_2^+,\\cdots,\\bm\\theta_p^+,\\bm\\theta_{p+1})\n    \t\\end{align}\n    \twhere $\\bm\\theta_j = (W_j,b_j), j = 1,2,\\cdots,p+1$.\n    \\end{itemize}\n    \\item Stopping criterion.\\\\\n    We stop iteration when training accuracy first obtain 100\\%.\n\\end{itemize}\n\n\n\\begin{enumerate}\n\t\\item Training Net0-4 using gradient descent.\\\\\n\tWe set $\\lambda = 10^{-5}$, learning rate $= 0.1$.\n\t\\begin{itemize}\n\t\t\\item Experiment 1: Using ranomly chosen 48000 data points from linear MNIST as training set.\\\\\n\t\t\\begin{table}[H]\n\t\t\t\\centering\n\t\t\t\\caption{Randomly chosen 80\\% full dataset as training set}\n\t\t\t\\label{tab:1}      \n\t\t\t\\begin{tabular}{lllllll}\n\t\t\t\t\\hline\\noalign{\\smallskip}\n\t\t\t\tModel &  Optim & Iterations & Time  & TrainL  & TestL & TestA \\\\\n\t\t\t\t\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\n\t\t\t\t\n\t\t\t\tNet0 & GD & 3190 & 3743 & 0.0062 & 0.0077 & 99.94   \\\\\n\t\t\t\t\n\t\t\t\tNet1 & GD & 2009 & 2475 & 0.0046 & 0.0063 & 99.95 \\\\\n\t\t\t\t\n\t\t\t\tNet2 & GD & 2322 & 3245 & 0.0034 & 0.0049 & 99.94 \\\\\n\t\t\t\t\n\t\t\t\tNet3 & GD & 1767 & 2705 & 0.0048 & 0.0066 & 99.93 \\\\\n\t\t\t\t\n\t\t\t\tNet4 & GD & 1805 & 3346 &0.0059 & 0.0075 & 99.93 \\\\\n\t\t\t\t\n\t\t\t\t\\noalign{\\smallskip}\\hline\n\t\t\t\t\n\t\t\t\\end{tabular}\n\t\t\\end{table}\n\t\t\n%\t\t\\begin{figure}[H]\n%\t\t\t\\centering\n%\t\t\t\\includegraphics[width=3in]{logGDtrainL.png}   \n%\t\t\t\\caption{log(Train Loss)}\n%\t\t\\end{figure}\n\n\t\n\t\n\t\n\t\t\\item Experiment 2: Using whole linear MNIST dataset as training set.\n\t\t\\begin{table}[H]\n\t\t\t\\centering\n\t\t\t\\caption{Full dataset}\n\t\t\t\\label{tab:2}      \n\t\t\t\\begin{tabular}{lllll}\n\t\t\t\t\\hline\\noalign{\\smallskip}\n\t\t\t\tModel &  Optim & Iterations & Time  & TrainL \\\\\n\t\t\t\t\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\n\t\t\t\t\n\t\t\t\tNet0 & GD & 4218 & 6168 & 0.0051  \\\\\n\t\t\t\t\n\t\t\t\tNet1 & GD & 2546 & 3937 & 0.0038  \\\\\n\t\t\t\t\n\t\t\t\tNet2 & GD & 2269 & 4010 & 0.0035  \\\\\n\t\t\t\t\n\t\t\t\tNet3 & GD & 2099 & 4046 & 0.0044  \\\\\n\t\t\t\t\n\t\t\t\tNet4 & GD & 1578 & 3815 &0.0065  \\\\\n\t\t\t\t\n\t\t\t\t\\noalign{\\smallskip}\\hline\n\t\t\t\t\n\t\t\t\\end{tabular}\n\t\t\\end{table}\n\t\t\n\t\t\n%\t\t\\begin{figure}[H]\n%\t\t\t\\centering\n%\t\t\t\\includegraphics[width=3in]{logGDfullL.png}   \n%\t\t\t\\caption{log(Train Loss) for full dataset}\n%\t\t\\end{figure}\n\t\tWe can see very clearly in the two figures that the loss of Net0 always decrease slower than other deeper linear NN. Or we can see in the table that Net0 use most iterations to reach 100\\% training accuracy. \n\t\n\t    \\item Experiment 3: Training '0' and '1' data in MNIST.\\\\\n\t     First I use Adam algorithm to verify that '0' and '1' are linearly separable in the training set of MNIST. Then I use full GD to iterate 50 epoches for each model and record their loss history. \n%\t    \\begin{figure}[H]\n%\t\t  \\centering\n%\t\t  \\includegraphics[width=3in]{log_MNIST_50.png}   \n%\t\t  \\caption{log(Train Loss) for MNIST dataset}\n%\t      \\end{figure}\n\t\t\\end{itemize}\n\t\\end{enumerate}\n", "meta": {"hexsha": "1fe4024e315ba7cd591d50548edab7ab4f00b87a", "size": 5267, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/linearNN_experiment.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/linearNN_experiment.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/linearNN_experiment.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.1484375, "max_line_length": 512, "alphanum_fraction": 0.6333776343, "num_tokens": 1998, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7076947551982088}}
{"text": "%\n% 125\n%\n\\chapter{The Expansion of Functions in Infinite Series}\n\n\\Section{7}{1}{A formula due to Darboux*TODO.  Journal de Math. (3), ii. (1876), p. 271.}\n\nLet $f(z)$ be analytic at all points of the straight line joining $a$\nto $z$, and let $\\phi(t)$ be any polynomial of degree $n$ in $t$.\n\nThen if $0 \\leq t \\leq 1$, we have by differentiation\n\\begin{align*}\n  \\frac{\\dd }{\\dd t}\n  \\sum_{m=1}^{n} (-)^{m} (z-a)^{m} \\phi^{(n-m)}(t) f^{(m)}(a + t(z-a))\n  \\\\\n  =\n  -(z-a) \\phi^{(n)}(t) f'(a + t(z-a))\n  +\n  (-)^{n} (z-a)^{n+1} \\phi(t) f^{(n+1)}(a + t (z-a)).\n\\end{align*}\n\nNoting that $\\phi^{(n)}(t)$ is constant $= \\phi^{(n)}(0)$, and integrating\nbetween the limits $0$ and $1$ of $t$, we get\n\\begin{align*}\n  \\phi^{(n)}(0) \\thebrace{ f(z) - f(a) }\n  \\\\\n  =&\n  \\sum_{m=1}^{n} (-)^{m-1} (z-a)^{m}\n  \\thebrace{\n    \\phi^{(n-m)}(1) f^{(m)}(z) - \\phi^{(n-m)}(0) f^{(m)}(a)\n  }\n  \\\\\n  &\n  + (-)^{n} (z-a)^{n+1}\n  \\int_{0}^{1} \\phi(t) f^{(n+1)}(a + t(z-a)) \\dmeasure t,\n\\end{align*}\nwhich is the formula in question.\n\nTaylor's series may be obtained as a special case of this by writing\n$\\phi(t) = (t-1)^{n}$ and making $n\\rightarrow\\infty$.\n\n%\\begin{smalltext}\nExample. By substituting $2n$ for $n$ in the formula of Darboux, and\ntaking $\\phi(t) = t^{n} (t-1)^{n}$, obtain the expansion (supposed convergent)\n$$\nf(z) - f(a)\n=\n\\sum_{n=1}^{\\infty}\n\\frac{ (-)^{n-1} (z-a)^{n} }{2^{n} n!}\n\\thebrace{ f^{(n)}(z) + (-)^{n-1} f^{(n)}(a) },\n$$\nand find the expression for the remainder after $n$ terms in this\nseries.\n%\\end{smalltext}\n\\Section{7}{2}{The \\Bernoulli an numbers and the \\Bernoulli an polynomials.}\n\nThe function $\\half z \\cot \\half z$ is analytic when $\\absval{z} <\n2\\pi$,\nand, since it is an even function of $z$, it can be expanded into a\nMaclaurin series, thus\n$$\n\\half z \\cot \\half z\n=\n1\n- B_{1} \\frac{z^{2}}{2!}\n- B_{2} \\frac{z^{4}}{4!}\n- B_{3} \\frac{z^{6}}{6!}\n\\cdots\n;\n$$\nthen $B_{n}$ is called the $n$th \\emph{\\Bernoulli an\n  number}\\footnote{TODO These numbers were introduced by Jakob BernouUi in bis Ars\nConjectandi, p. 97 (published posthumously, 1713).}.\nIt is found that\\footnote{TODO Tables of the first sixty-two \\Bernoulli an numbers have been given by\nAdams, Brit. A.is. ReiJorts, 1877.}\n$$\nB_{1} = \\frac{1}{6},\n\\quad\nB_{2} = \\frac{1}{30},\n\\quad\nB_{3} = \\frac{1}{42},\n\\quad\nB_{4} = \\frac{1}{30},\n\\quad\nB_{5} = \\frac{5}{66},\n\\quad\n\\ldots.\n$$\n\n%\n% 126\n%\nThese numbers can be expressed as definite integrals as follows:\n\nWe have, by example TODO:2 (p. TODO:122) of Chapter TODO:VI,\n\\begin{align*}\n  \\int_{0}^{\\infty}\n  \\frac{\\sin px \\dmeasure x}{e^{\\pi x} - 1}\n  =&\n  -\\frac{1}{2p} + \\frac{i}{2} \\cot ip\n  \\\\\n  =&\n  -\\frac{1}{2p}\n  +\n  \\frac{1}{2p} \\thebrace{\n    1\n    + B_{1} \\frac{(2p)^{2}}{2!}\n    - B_{2} \\frac{(2p)^{4}}{4!}\n    + \\cdots\n    }.\n\\end{align*}\n\nSince\n$$\n\\int_{0}^{\\infty}\n\\frac{x^{n} \\sin \\theparen{px + \\half n \\pi}}{e^{\\pi x} - 1}\n\\dmeasure x\n$$\nconverges uniformly (by de la Vall\\'ee Poussin's test) near\n$p=0$ we\nmay, by \\hardsubsectionref{4}{4}{4} corollary, differentiate both\nsides of this equation any number of times and then put $p = 0$; doing\nso and writing $2t$ for $x$, we obtain\n$$\nB_{n}\n=\n4n\n\\int_{0}^{\\infty}\n\\frac{t^{2n-1} \\dmeasure t}{e^{2\\pi t} - 1}.\n$$\n%\\begin{remark}\nA proof of this result, depending on contour integration, is given by\nCarda, Monatshefte fur Math, v.nd Phys. v. (1894), pp. 321-4.\n%\\end{remark}\n\nTODO:fixexample\nExample. Shew that\n$$\nB_{n}\n=\n\\frac{2n}{\\pi^{2n} (2^{2n}-1)}\n\\int_{0}^{\\infty}\n\\frac{x^{2n-1} \\dmeasure x}{\\sinh x}\n> 0.\n$$\n\nNow consider the function $t \\frac{e^{zt}-1}{e^{t}-1}$, which may be\nexpanded into a\nMaclaurin series in powers of $t$ valid when $\\absval{t} < 2\\pi$.\n\n\\emph{The \\Bernoulli an polynomial\\footnote{TODO The name was given by\n    Raabe, Journal filr Math. xlii. (1851), p.348.} of order $n$} is\ndefined to be the coefficient of $\\frac{t^{n}}{n!}$\nin this expansion. It is denoted by $\\phi_{n}(z)$, so that\n$$\nt \\frac{e^{zt}-1}{e^{t}-1}\n=\n\\sum_{n=1}^{\\infty}\n\\frac{\\phi\n_{n}(z) t^{n}}{n!}.\n$$\n\nThis polynomial possesses several important properties. Writing $z+1$\nfor $z$ in the preceding equation and subtracting, we find that\n$$\nt e^{zt}\n=\n\\sum_{n=1}^{\\infty}\n\\thebrace{\n  \\phi_{n}(z+1) - \\phi_{n}(z)\n}\n\\frac{t^{n}}{n!}.\n$$\n\nOn equating coefficients of $t^{n}$ on both\nsides of this equation we obtain\n$$\nn z^{n-1}\n=\n\\phi_{n}(z+1) - \\phi_{n}(z),\n$$\nwhich is a difference-equation satisfied by the function $\\phi_{n}(z)$.\n\n%\n% 127\n%\n\nAn explicit expression for the \\Bernoulli an polynomials can be obtained\nas follows. We have\n$$\ne^{zt} - 1\n=\nzt\n+ \\frac{z^{2}t^{2}}{2!}\n+ \\frac{z^{3}t^{3}}{3!}\n+ \\cdots,\n$$\nand\n$$\n\\frac{t}{e^{t}-1}\n=\n\\frac{t}{2i} \\cot \\frac{t}{2i} - \\frac{t}{2}\n=\n1\n- \\frac{t}{2}\n+ \\frac{B_{1} t^{2}}{2!}\n- \\frac{B_{2} t^{4}}{4!}\n+ \\cdots.\n$$\n\nHence\n$$\n\\sum_{n=1}^{\\infty}\n\\frac{\\phi_{n}(z) t^{n}}{n!}\n=\n\\thebrace{\n  zt\n  + \\frac{z^{2} t^{2}}{2!}\n  + \\frac{z^{3} t^{3}}{3!}\n  + \\cdots\n}\n\\thebrace{\n  1\n  - \\frac{t}{2}\n  + \\frac{B_{1} t^{2}}{2!}\n  - \\frac{B_{2} t^{4}}{4!}\n  + \\cdots\n}.\n$$\n\nFrom this, by equating coefficients of $t^{n}$\n(\\hardsubsectionref{3}{7}{3}), we have\n$$\n\\phi_{n}(z)\n=\nz^{n}\n- \\half n z^{n-1}\n+ \\binomialcoeff{n}{2} B_{1} z^{n-2}\n- \\binomialcoeff{n}{4} B_{2} z^{n-4}\n+ \\binomialcoeff{n}{6} B_{3} z^{n-6}\n- \\cdots,\n$$\nthe last term being that in $z$ or $z^{2}$ and\n$\\binomialcoeff{n}{2}, \\binomialcoeff{n}{4},\\ldots$  being the\nbinomial coefficients; this is the Maclaurin series for the $n$th\n\\Bernoulli an polynomial.\n%\\begin{Remark}\nWhen $z$ is an integer, it may be seen from the difference-equation that\n$$\n\\phi_{n}(z)/n\n=\n1^{n-1}\n+ 2^{n-1}\n+ \\cdots + (z-1)^{n-1}.\n$$\n\nThe Maclaurin series for the\nexpression on the right was given by \\Bernoulli.\n\n%\\begin{Remark}\n\\begin{wandwexample}\n  Shew that, when $n > 1$,\n  $$\n  \\phi_{n}(z) = (-)^{n} \\phi_{n}(1-z).\n  $$\n\\end{wandwexample}\n%\\end{Remark}\n\\Subsection{7}{2}{1}{The Euler-Maclaurin expansion.}\n\nIn the formula of Darboux \\hardsectionref{7}{1}) write $\\phi_{n}(t)$\nfor $\\phi(t)$, where $\\phi_{n}(t)$ is the $n$th \\Bernoulli an polynomial.\n\nDifferentiating the equation\n$$\n\\phi_{n}(t+1) - \\phi_{n}(t) = n t^{n-1}\n$$\n$n - k$ times, we have\n$$\n\\phi_{n}^{(n-k)}(t+1) - \\phi_{n}^{(n-k)}(t)\n=\nn (n-t) \\cdots k t^{k-1}\n$$\nPutting $t=0$ in this, we have\n$\\phi_{n}^{(n-k)}(1) = \\phi_{n}^{(n-k)}(0).$\n\nNow, from the Maclaurin\nseries for $\\phi_{n}(z)$, we have if $k > 0$\n\\begin{align*}\n  \\phi_{n}^{(n-2k-1)}(0) = 0,\n  &\n  \\quad\n  \\phi_{n}^{(n-2k)}(0) = \\frac{n!}{(2k)!} (-)^{k-1} B_{k},\n  \\\\\n  \\phi_{n}^{(n-1)}(0) = -\\half n!,\n  &\n  \\quad\n  \\phi_{n}^{(n)}(0) = n!.\n\\end{align*}\n\nSubstituting these values of $\\phi_{n}^{(n-k)}(1)$ and\n$\\phi_{n}^{(n-k)}(0)$ in Darboux's\nresult, we obtain the Euler-Maclaurin sum\nformula\\footnote{TODO A history of the formula is given by Barnes, Proc. London Math. Soc.\n(2), iii. (1905), p. 253. It was discovered by Euler (1732), but was\nnot published at the time. Euler communicated it (June 9, 1736) to\nStirling who replied (April 16, 1738) that it included his own theorem\n(see \\hardsubsectionref{12}{3}{3}) as a particular case, and also that the more general\ntheorem had been discovered by Maclaurin; and Euler, in a lengthy\nreply, waived his claims to priority. The theorem was published by\nEuler, Comm. Acad. Imp. Petrop. vi. (1732), [Published 1738], pp.\n68-97, and by Maclaurin in 1742, Treatise on Fluxions, p. 672. For\ninformation concerning the correspondence between Euler and Stirling,\nwe are indebted to Mr C. Tweedie.},\n\n%\n% 128\n%\n\\begin{align*}\n(z-a) f'(a)\n=&\nf(z) - f(a)\n- \\frac{z-a}{2} \\thebrace{ f'(z) - f'(a) }\n\\\\\n&\n+ \\sum_{m=1}^{n-1} \\frac{ (-)^{m-1} B_{m} (z-a)^{2m}}{(2m)!}\n\\thebrace{f^{(2m)}(z) - f^{(2m)}(a)}\n\\\\\n&\n-\\frac{(z-a)^{2n+1}}{(2n)!}\n\\int_{0}^{1} \\phi_{2n}(t) f^{(2n+1)}\\thebrace{ a + (z-a) t }\n\\dmeasure t.\n\\end{align*}\n\nIn certain cases the last term tends to zero as\n$n \\rightarrow \\infty$, and we can\nthus obtain an infinite series for $f(z) - f(a)$.\n\nIf we write $\\omega$ for $z - a$ and $F(x)$ for $f'(x)$, the last formula becomes\n\\begin{align*}\n  \\int_{a}^{a+\\omega} F(x) \\dmeasure x\n  =\n  &\n  \\half \\omega \\thebrace{ F(a) + F(a + \\omega) }\n  \\\\\n  &\n  + \\sum_{m=1}^{n-1}\n  \\frac{(-)^{m} B_{m} \\omega^{2m}}{(2m)!}\n  \\thebrace{F^{(2m-1)}(a+\\omega) - F^{(2m-1)}(a)}\n  \\\\\n  &\n  + \\frac{\\omega^{2n+1}}{(2n)!}\n  \\int_{0}^{1} \\phi_{2n}(t) F^{(2n)}(a + \\omega t) \\dmeasure t.\n\\end{align*}\n\nWriting $a + \\omega, a + 2\\omega, \\ldots, a + (r-1) \\omega$\nfor $a$ in this result and adding up, we get\n\\begin{align*}\n\\int_{a}^{a + r\\omega} F(x) \\dmeasure x\n=\n\\omega\n &\n\\thebrace{\n  \\half F(a) + F(a+\\omega) + F(a+2\\omega)\n  + \\cdots + \\half F(a + r\\omega)\n}\n\\\\\n&\n+ \\sum_{m=1}^{n-1}\n\\frac{(-)^{m} B_{m} \\omega^{2m}}{(2m)!}\n\\thebrace{\n  F^{(2m-1)}(a + r\\omega)\n  -\n  F^{(2m-1)}(a)\n}\n+ R_{n},\n\\end{align*}\nwhere\n$$\nR_{n}\n=\n\\frac{\\omega^{2n+1}}{(2n)!}\n\\int_{0}^{1} \\phi_{2n}(t)\n\\thebrace{ \\sum_{m=0}^{r-1} F^{(2n)}(a + m\\omega + \\omega t)}\n\\dmeasure t.\n$$\n\nThis last formula is of the utmost importance in connexion with the\nnumerical evaluation of definite integrals. It is valid if $F(x)$ is\nanalytic at all points of the straight line joining\n$a$ to $a + r \\omega$.\n\n%\\begin{Remark}\n\\begin{wandwexample}\n  If $f(z)$ be an odd function of $z$, shew that\n  $$\n  z f'(z)\n  =\n  f(z)\n  +\n  \\sum_{m=2}^{n}\n  (-)^{m}\n  \\frac{B_{m-1} (2z)^{2m-2}}{(2m-2)!}\n  f^{(2m-2)}(z)\n  -\n  \\frac{2^{2n} z^{2n+1}}{(2n)!}\n  \\int_{0}^{1}\n  \\phi_{2n}(t)\n  f^{(2n+1)}(-z + 2zt)\n  \\dmeasure t.\n  $$\n\\end{wandwexample}\n\\begin{wandwexample}\n  Shew, by integrating by parts, that the remainder after $n$\n  terms of the expansion of $\\half z \\cot \\half z$ may be written in the form\n  $$\n  \\frac{ (-)^{n+1} z^{2n+1} }{ (2n)! \\sin z }\n  \\int_{0}^{1} \\phi_{2n}(t) \\cos (zt) \\dmeasure t.\n  $$\n\\addexamplecitation{Math. Trip. 1904.}\n\\end{wandwexample}\n%\\end{Remark}\n\\Section{7}{3}{\\Burmann's theorem*TODO * Memoires de VInstitut, ii. (1799), p. 13. See also Dixon, Proc.\nLondon Math. Soc. xxxiv. (1902), pp. 151-153..}\n\nWe shall next consider several theorems which have for their object\n\\emph{the expansion of one function in powers of another function.}\n\n%\n% 129\n%\n\nLet $\\phi(z)$ be a function of $z$ which is analytic in a closed\nregion $S$ of which $a$ is an interior point; and let\n$$\n\\phi(a) = b.\n$$\n\nSuppose also that $\\phi'(a) \\neq 0$. Then Taylor's theorem furnishes the\nexpansion\n$$\n\\phi(z) - b\n=\n\\phi'(a) (z-a)\n+ \\half \\phi''(a) (z-a)^{2}\n+ \\cdots,\n$$\nand if it is legitimate to revert this series we obtain\n$$\nz - a\n=\n\\frac{1}{\\phi'(a)}\n\\thebrace{ \\phi(z) - b }\n-\n\\half \\frac{\\phi''(a)}{\\thebrace{\\phi'(a)}^{3}}\n\\thebrace{ \\phi(z) - b }^{2}\n+ \\cdots,\n$$\nwhich expresses $z$ as an analytic function of the variable\n$\\thebrace{ \\phi(z) - b }$,\nfor sufficiently small values of $\\absval{z-a}$. If then $f(z)$ be\nanalytic near $z = a$, it follows that $f(z)$ is an analytic function\nof $\\thebrace{ \\phi(z) - b }$\nwhen $\\absval{z - a}$ is sufficiently small, and so there will be an\nexpansion of the form\n$$\nf(z)\n=\nf(a)\n+ a_{1} \\thebrace{ \\phi(z) - b }\n+ \\frac{a_{2}}{2!} \\thebrace{ \\phi(z) - b }^{2}\n+ \\frac{a_{3}}{3!} \\thebrace{ \\phi(z) - b }^{3}\n+ \\cdots.\n$$\n\nThe actual coefficients in the expansion are given by the following\ntheorem, which is generally known as \\emph{\\Burmann's theorem}.\n\n\\emph{Let $\\psi(z)$ be a function of $z$ defined by the equation\n$$\n\\psi(z) = \\frac{z-a}{ \\phi(z) - b };\n$$\nthen an analytic function $f(z)$ can, in a certain domain of values of\n$z$, be expanded in the form\n$$\nf(z)\n=\nf(a)\n+\n\\sum_{m=1}^{n-1}\n\\frac{ \\thebrace{\\phi(z)-b}^{m} }{m!}\n\\frac{\\dd^{m-1}}{\\dd a^{m-1}}\n\\thebracket{\n  f'(a) \\thebrace{\\psi(a)}^{m}\n}\n+\nR_{n},\n$$\nwhere\n$$\nR_{n}\n=\n\\frac{1}{2 \\pi i}\n\\int_{a}^{z}\n\\int_{\\gamma}\n\\thebracket{\n  \\frac{\\phi(z) - b}{\\phi(t) - b}\n}^{n-1}\n\\frac{ f'(t) \\phi'(z) }{\\phi(t) - \\phi(z)}\n\\dmeasure t \\dmeasure z,\n$$\nand $\\gamma$ is a contour in the $t$-plane, enclosing the points $a$\nand $z$ and such that, if $\\zeta$ be any point inside it, the equation\n$\\phi(t) = \\phi(\\zeta)$ has no roots on or inside the contour\nexcept\\footnote{It is assumed that such a contour can be chosen if\n  $\\absval{z - a}$ be sufficiently small;\n  see \\hardsubsectionref{7}{3}{1}.} a simple root $t=\\zeta$.\n}\n\nTo prove this, we have\n\\begin{align*}\n  f(z) - f(a)\n  = &\n  \\int_{a}^{z} f'(\\zeta) \\dmeasure \\zeta\n  = \\frac{1}{2 \\pi i} \\int_{a}^{z} \\int_{\\gamma} TODO\n\\end{align*}\n\n%\n% 130\n%\n\nBut, by \\hardsectionref{4}{3},\n\\begin{align*}\n  &\n  \\frac{1}{1 \\pi i}\n  \\int_{a}^{z} \\int_{\\gamma}\n  \\thebracket{ \\frac{\\phi(\\zeta) - b}{\\phi(t) - b} }^{m}\n  \\frac{f'(t)\\phi'(\\zeta)}{\\phi(t) - b}\n  \\dmeasure t \\dmeasure \\zeta\n  \\\\\n  &=\n  \\frac{ [\\phi(z) - b]^{m+1} }{2 \\pi i (m+1)}\n  \\int_{\\gamma} \\frac{f'(t)}{[\\phi(t) - b]^{m+1}} \\dmeasure t\n  \\\\\n  &=\n  \\frac{ [\\phi(z) - b]^{m+1} }{2 \\pi i (m+1)}\n  \\int_{\\gamma}\n  \\frac{ f'(t) \\thebrace{\\psi(t)}^{m+1} }{ (t-a)^{m+1} }\n  \\dmeasure t\n  \\\\\n  &=\n  \\frac{ [\\phi(z) - b ]^{m+1} }{ (m+1)! }\n  \\frac{ \\dd^{m} }{ \\dd a^{m} }\n  \\thebracket{ f'(a) \\thebrace{\\psi(a)}^{m+1} }.\n\\end{align*}\nTherefore, writing\n$m - 1$ for $m$,\n\\begin{align*}\n  f(z) = f(a) +\n  &\n  \\sum_{m=1}^{n-1}\n  \\frac{ [\\phi(z) - b]^{m} }{m!}\n  \\frac{\\dd^{m-1}}{\\dd a^{m-1}}\n  [ f'(a) \\thebrace{ \\psi(a) }^{m} ]\n  \\\\\n  &\n + \\frac{1}{2 \\pi i}\n  \\int_{a}^{z} \\int_{\\gamma}\n  \\thebracket{\n    \\frac{\\phi(\\zeta) - b}{\\phi(t) - b}\n  }^{n-1}\n  \\frac{f'(t) \\phi'(\\zeta)}{\\phi(t) - \\phi(\\zeta)}\n  \\dmeasure t \\dmeasure \\zeta.\n\\end{align*}\n\nIf the last integral tends to zero as $n \\rightarrow \\infty$, we may write the\nright-hand side of this equation as an infinite series.\n\\begin{wandwexample}\nProve that\n$$\nz\n=\na\n+ \\sum_{n=1}^{\\infty}\n\\frac{(-)^{n-1} C_{n} (z-a)^{n} e^{n (z^{2} - a^{2})}}{n!},\n$$\nwhere\n$$\nC_{n}\n=\n(2na)^{n-1}\n- \\frac{n(n-1)(n-2)}{1!} (2na)^{n-3}\n+ \\frac{n^{2}(n-1)(n-2)(n-3)(n-4)}{2!} (2na)^{n-5}\n- \\cdots.\n$$\nTo obtain this expansion, write\n$$\nf(z) = z,\n\\quad\n\\phi(z) - b = (z-a) e^{z^{2} - a^{2}},\n\\quad\n\\psi(z) = e^{a^{2} - z^{2}}\n$$\nin the above expression\nof \\Burmann's theorem; we thus have\n$$\nz\n=\na\n+ \\sum_{n=1}^{\\infty}\n\\frac{1}{n!}\n(z-a)^{n}\ne^{n(z^{2} - a^{2})}\n\\thebrace{\n  \\frac{\\dd^{n-1}}{\\dd z^{n-1}}\n  e^{n(a^{2} - z^{2})}\n}_{z=a}.\n$$\n\nBut, putting $z = a + t$,\n\\begin{align*}\n  \\thebrace{\n    \\frac{\\dd^{n-1}}{\\dd z^{n-1}}\n    e^{n(a^{2} - z^{2})}\n  }_{z=a}\n  =&\n  \\thebrace{\n    \\frac{\\dd^{n-1}}{\\dd t^{n-1}}\n    e^{-n(2at + t^{2})}\n  }_{t=0}\n  \\\\\n  =&\n  TOOD\n\\end{align*}\nThe highest value of $r$ which gives a term in the summation is\n$r = n-1$.\nArranging therefore the summation in descending indices $r$,\nbeginning with $r = n-1$, we have\n\\begin{align*}\n  \\thebrace{\n    \\frac{\\dd^{n-1}}{\\dd z^{n-1}}\n    e^{n(a^{2} - z^{2})}\n  }_{z=a}\n  =&\n  TODO\n  \\\\\n  =& (-)^{n-1} C_{n},\n\\end{align*}\nwhich gives the required result.\n\\end{wandwexample}\n\\begin{wandwexample}\n  Obtain the expansion\n  $$\n  z^{2}\n  =\n  \\sin^{2} z\n  + \\frac{2}{3} \\half \\sin^{4} z\n  + \\frac{2 \\cdot 4}{3 \\cdot 5} \\frac{1}{3} \\sin^{6} z\n  + \\cdots.\n  $$\n\\end{wandwexample}\n%\n% 131\n%\n\\begin{wandwexample}\nLet a line $p$ be drawn through the origin in the $z$-plane,\nperpendicular to the line which joins the origin to any point $a$. If\n$z$ be any point on the $z$-plane which is on the same side of the line\n$p$ as the point $a$ is, shew that\n$$\n\\log z\n=\n\\log a\n+ 2 \\sum_{m=1}^{\\infty}\n\\frac{1}{2m+1} \\theparen{\\frac{z-a}{z+a}}^{2m+1}.\n$$\n\\end{wandwexample}\n\\Subsection{7}{3}{1}{\\Teixeira's extended form of \\Burmann's theorem.}\n\nIn the last section we have not investigated closely the conditions of\nconvergence of \\Burmann's series, for the reason that a much more\ngeneral form of the theorem will next be stated; this generalisation\nbears the same relation to the theorem just given that Laurent's\ntheorem bears to Taylor's theorem: viz., in the last paragraph we\nwere concerned only with the expansion of a function in \\emph{positive}\npowers of another function, whereas we shall now discuss the expansion\nof a function in \\emph{positive and negative} powers of the second\nfunction.\n\nThe general statement of the theorem is due to\n\\Teixeira\\footnote{TODO Journal f\\\"ur Math, cxxii. (1900), pp.\n  97-123.}, whose exposition we shall follow in this section.\n\nSuppose (i) that $f(z)$ is a function of $z$ analytic in a ring-shaped\nregion $A$, bounded by an outer curve $C$ and an inner curve $c$;\n(ii) that $\\theta(z)$ is a function analytic on and inside $C$,\nand has only one zero a\nwithin this contour, the zero being a simple one;\n(iii) that $x$ is a given point within $A$;\n(iv) that for all points $z$ of $C$ we have\n$$\n\\absval{\\theta(x)} < \\absval{\\theta(z)},\n$$\nand for all points $z$ of $c$ we have\n$$\n\\absval{\\theta(x)} > \\absval{\\theta(z)}.\n$$\n\nThe equation\n$$\n\\theta(z) - \\theta(x) = 0\n$$\nhas, in this case, a single root $z = x$ in the interior of $C$, as is\nseen from the equation\\footnote{The expansion is justified\n  by \\hardsectionref{4}{7}, since\n  $\\sum_{n=1}^{\\infty} \\thebrace{\\theta(x)/\\theta(z)}^{n}$\n  converges uniformly when $z$\n  is on $C$.}\n\\begin{align*}\n  \\frac{1}{2 \\pi i}\n  \\int_{C} \\frac{\\theta'(z)}{\\theta(z) - \\theta(x)} \\dmeasure z\n  =&\n  \\frac{1}{2 \\pi i}\n  \\thebracket{\n    \\int_{C} \\frac{\\theta'(z)}{\\theta(z)} \\dmeasure z\n    +\n    \\theta(x)\n    \\int_{C} \\frac{\\theta'(z)}{ \\thebrace{\\theta(z)}^{2}}\n    \\dmeasure z\n    + \\cdots\n  }\n  \\\\\n  =&\n  \\frac{1}{2 \\pi i}\n  \\int_{C} \\frac{\\theta'(z)}{\\theta(z)} \\dmeasure z\n\\end{align*}\nof which the left-hand and right-hand members represent respectively\nthe number of roots of the equation considered\n(\\hardsubsectionref{6}{3}{1}) and the\nnumber of the roots of the equation $\\theta(z) = 0$ contained within\n$C$.\n\nCauchy's theorem therefore gives\n$$\nf(x)\n=\n\\frac{1}{2 \\pi i}\n\\thebracket{\n  \\int_{C} \\frac{f(z) \\theta'(z)}{\\theta(z) - \\theta(x)} \\dmeasure z\n  -\n  \\int_{c} \\frac{f(z) \\theta'(z)}{\\theta(z) - \\theta(x)} \\dmeasure z\n}.\n$$\n\n%\n% 132\n%\nThe integrals in this formula can be expanded, as in Laurent's\ntheorem, in powers of $\\theta(x)$, by the formulae\n\\begin{align*}\n  TODO\n\\end{align*}\n\nWe thus have the formula\n$$\nTODO\n$$\nwhere\n$$\nTODO\n$$\n\nIntegrating by parts, we get, if $n \\neq 0$,\n$$\nTODO\n$$\n\nThis gives a development of $f(x)$ in positive and negative powers of\n$\\theta(x)$, valid for all points $x$; within the ring-shaped space $A$.\n\nIf the zeros and poles of $f(z)$ and $\\theta(z)$ inside $C$ are known,\n$A_{n}$ and $B_{n}$ can be evaluated by \\hardsubsectionref{5}{2}{2} or\nby \\hardsectionref{6}{1}.\n\n\\begin{wandwexample}\n  Shew that, if $\\absval{x} < 1$, then\n  $$\n  x\n  =\n  \\half \\theparen{ \\frac{2x}{1+x^{2}} }\n  +\n  \\frac{1}{2 \\cdot 4} \\theparen{ \\frac{2x}{1+x^{2}} }^{3}\n  +\n  \\frac{1\\cdot 3}{2 \\cdot 4 \\cdot 6} \\theparen{ \\frac{2x}{1+x^{2}} }^{5}\n  +\n  \\cdots.\n  $$\n\n  Shew that, when $\\absval{x} > 1$, the second member represents $x^{-1}$.\n\\end{wandwexample}\n\\begin{wandwexample}\nIf $S^{(m)}_{2n}$ denote the sum of all combinations of the numbers\n$$\n2^{2}, 4^{2}, 6^{2}, \\ldots, (2n-2)^{2},\n$$\ntaken $m$ at a time, shew that\n$$\n\\frac{1}{z}\n=\n\\frac{1}{\\sin z}\n+\n\\sum_{n=0}^{\\infty}\n\\frac{(-)^{n+1}}{ (2n+2)! }\n\\theparen{\n  \\frac{1}{2n+3}\n  - \\frac{S^{(1)}_{2(n+1)}}{2n+1}\n  + \\cdots\n  + \\frac{ (-)^{n} S^{(n)}_{2(n+1)}}{3}\n}\n(\\sin z)^{2n+1}\n$$\nthe expansion being valid for all values of $z$ represented by points\nwithin the oval whose equation is $\\absval{\\sin z} = 1$ and which contains the\npoint $z = 0$. \\addexamplecitation{\\Teixeira.}\n\\end{wandwexample}\n\n\\Subsection{7}{3}{2}{Lagrange's theorem.}\n\nSuppose now that the function $f(z)$ of \\hardsubsectionref{7}{3}{1}\nis analytic at all points in the interior of $C$, and let\n$\\theta(x) = (x - a) \\theta_{1}(x)$. Then $\\theta_{1}(x)$ is\nanalytic and not zero on or inside $C$ and the contour $c$ can be\ndispensed with; therefore the formulae which give $A_{n}$ and\n$B_{n}$ now become, by \\hardsubsectionref{5}{2}{2} and \\hardsectionref{6}{1},\n\\begin{align*} % TODO: multiline?\n  A_{n}\n  =&\n  \\frac{1}{2\\pi in} \\!\n  \\int_{C} \\frac{f'(z)}{(z-a)^{n} \\theta_{1}^{n}(z)} \\dmeasure z\n  = \\frac{1}{n!} \\frac{\\dd^{n-1}}{\\dd a^{n-1}}\n  \\thebrace{\n    \\frac{f'(a)}{\\theta_{1}^{n}(a)\n    }\n  }\n  \\quad (n \\geq 1),\n  \\\\\n  A_{0}\n  =&\n  \\frac{1}{2\\pi i} \\!\n  \\int_{C} \\frac{f(z) \\theta'(z)}{\\theta_{1}(z)}\n  \\frac{\\dmeasure z}{z-a}\n  =\n  f(a),\n  \\\\\n  B_{n}\n  =&\n  0.\n\\end{align*}\n\n%\n% 133\n%\n\nThe theorem of the last section accordingly takes the following form,\nif we write $\\theta_{1}(z) = 1 / \\phi(z)$:\n\n\\emph{Let $f(z)$ and $\\phi(z)$ be functions of $z$ analytic on and inside a\ncontour $C$ surrounding a point $a$, and let $t$ be such that the inequality\n$$\n\\absval{t \\phi(z) } < \\absval{z - a}\n$$\nis satisfied at all points $z$ on the perimeter of $C$;\nthen the equation\n$$\n\\zeta = a + t \\phi(\\zeta),\n$$\nregarded as an equation in $\\zeta$, has one root in the interior\nof $C$; and further any function of $\\zeta$ analytic on and inside\n$C$ can be expanded as a power series in $t$ by the formula\n$$\nf(\\zeta)\n=\nf(a)\n+\n\\sum_{n=1}^{\\infty}\n\\frac{t^{n}}{n!}\n\\frac{\\dd^{n-1}}{\\dd a^{n-1}}\n\\thebracket{\n  f'(a) \\phi^{n}(a)\n}.\n$$\n}\nThis result was published by Lagrange\\footnote{TODO Mem. de VAcad. de Berlin, xxiv.; Oeuvres, iii. p. 25.} in 1770.\n\\begin{wandwexample}\nWithin the contour surrounding $a$ defined by the inequality\n$\\absval{z (z - a)} > \\absval{a}$, where\n$\\absval{a} < \\half \\absval{ a }$, %TODO: verify\nthe equation\n$$\nz - a - \\frac{a}{z} = 0\n$$\nhas one root $\\zeta$, the expansion of which is given by Lagrange's theorem\nin the form\n$$\n\\zeta\n=\na\n+\n\\sum_{n=1}^{\\infty}\n\\frac{(-)^{n-1} (2n-2)!}{n! (n-1)! a^{2n-1}} a^{n}\n%TODO: verify\n$$\n\nNow, from the elementary theory of quadratic equations, we know that\nthe equation\n$$\nz - a - \\frac{a}{z} = 0\n%TODO: verify\n$$\nhas two roots, namely $TODO$ and $TODO$; and our\nexpansion\n\\emph{represents the former\\footnote{The latter is outside the given\n    contour.} of these only}---an example of the need for\ncare in the discussion of these series.\n\\end{wandwexample}\n\\begin{wandwexample}\n  If $y$ be that one of the roots of the equation\n  $$\n  TODO\n  $$\n  which tends to $1$ when $z \\rightarrow 0$, shew that\n  $$\n  TODO\n  $$\n  so long as $\\absval{z} < \\frac{1}{4}$.\n\\end{wandwexample}\n\\begin{wandwexample}\nIf $x$ be that one of the roots of the equation\n$$\nx = 1 + y x^{a}\n$$\nwhich tends to $1$ when $y \\rightarrow 0$, shew that\n$$\nTODO\n$$\nthe expansion being valid so long as\n$$\n\\absval{y}\n<\n\\absval{\n  (a-1)^{a-1} a^{-a}\n}.\n$$\n\\addexamplecitation{McClintock.}\n\\end{wandwexample}\n\n%\n% 134\n%\n\n\\Section{7}{4}{The expansion of a class of functions in rational fractions*'.}\nConsider a function $f(z)$, whose only singularities in the finite\npart of the plane are simple poles $a_{1},a_{2},a_{3},\\ldots$, where\n$\\absval{a_{1}} \\leq \\absval{a_{2}} \\leq \\absval{a_{3}} \\leq \\cdots$;\nlet $b_{1},b_{2},b_{3},\\ldots$, be the residues at these\npoles, and let it be possible to choose a sequence of circles $C_{m}$ (the\nradius of $C_{m}$ being $R_{m}$) with centre at $O$, not passing through any\npoles, such that $\\absval{f(z)}$ is bounded on $C_{m}$. (The function\n$\\cosec z$ may\nbe cited as an example of the class of functions considered, and we\ntake $R_{m} = (m + \\half)\\pi$.) Suppose further that\n$R_{m} \\rightarrow \\infty$ as $m \\rightarrow \\infty$ and that\nthe upper bound\\footnote{Which is a function of $m$.}\nof $\\absval{f(z)}$ on $C_{m}$ is itself bounded\nas\\footnote{Of course $R_{m}$ need not (and frequently must not) tend to infinity\n  continuously; e.g. in the example taken\n  $R_{m} = (m+\\half)z$, where $m$ assumes only integer values.}\n$m\\rightarrow\\infty$; so\nthat, for all points on the circle $C_{m}$, $\\absval{f(z)} < M$, where $M$ is\nindependent of $m$.\n\nThen, if $x$ be not a pole of $f(z)$, since the only poles of the\nintegrand are the poles of $f(z)$ and the point $z = x$, we have, by \\hardsectionref{6}{1},\n$$\n\\frac{1}{2 \\pi i} \\int_{C_{m}} \\frac{f(z)}{z-x} \\dmeasure z\n=\nf(x) + \\sum_{r} \\frac{b_{r}}{a_{r}-x}.\n$$\nwhere the summation extends over all poles in the interior of $C_{m}$.\n\nBut\n\\begin{align*}\n  \\frac{1}{2 \\pi i}\n  \\int_{C_{m}} \\frac{f(z)}{z-x} \\dmeasure z\n  =&\n  \\frac{1}{2 \\pi i}\n  \\int_{C_{m}} \\frac{f(z)}{z} \\dmeasure z\n  +\n  \\frac{x}{2 \\pi i}\n  \\int_{C_{m}} \\frac{f(x)}{z(z-x)} \\dmeasure z\n  \\\\\n  =&\n  f(0) + \\sum_{r} \\frac{b_{r}}{a_{r}}\n  +\n  \\frac{x}{2 \\pi i}\n  \\int_{C_{m}} \\frac{f(z)}{z(z-x)} \\dmeasure z,\n\\end{align*}\nif we suppose the function $f(z)$ to be analytic at the origin.\n\nNow as $m \\rightarrow \\infty$,\n$\\int_{C_{m}} \\frac{f(z)}{z(z-x)} \\dmeasure z$ is\n$\\bigo(R_{m}^{-1})$, and so tends to zero as\n$m$ tends to infinity.\n\nTherefore, making $m \\rightarrow \\infty$, we have\n$$\n0\n=\nf(x) - f(0)\n+\n\\sum_{n=1}^{\\infty}\nb_{n} \\theparen{\n  \\frac{1}{a_{n}-x} - \\frac{1}{a_{n}}\n}\n-\n\\lim_{m\\rightarrow\\infty}\n\\frac{x}{2 \\pi i}\n\\int_{C_{m}} \\frac{f(z)}{z(z-x)} \\dmeasure x,\n$$\n\\ie\n$$\nf(x) = f(0)\n+\n\\sum_{n=1}^{\\infty}\nb_{n}\n\\thebrace{\n  \\frac{1}{x-a_{n}} + \\frac{1}{a_{n}}\n  %TODO:consistent with above?\n}\n$$\nwhich is an expansion of $f(x)$ in rational fractions of $x$; and the\nsummation extends over \\emph{all} the poles of $f(x)$.\n\n%\\begin{smalltext}\nIf $\\absval{a_{n}} < \\absval{a_{n+1}}$ this series converges uniformly\nthroughout the region given by $\\absval{x} < a$, where $a$ is any constant\n(except near the points $a_{n}$).\nFor if $R_{m}$ be the radius of the circle which encloses the points\n$\\absval{a_{1}}, \\ldots, \\absval{a_{n}}$,\nthe modulus of the remainder of the terms of the series after the first $n$ is\n$$\n\\absval{ \\frac{x}{2 \\pi i}\n  \\int_{C_{m}} \\frac{f(z)}{z(z-x)} \\dmeasure z\n}\n< \\frac{Ma}{R_{m}-a},\n$$\nby \\hardsubsectionref{4}{6}{2}; and, given\n$\\eps$, we can choose $n$ \\emph{independent} of $x$\nsuch that $Ma/(R_{m}-a) < \\eps$.\n\n* Mittag-Leffler, Acta Soc. Scient. Fennicae, xi. (1880), pp. 273-293.\nSee also Acta Math. iv. (1884), pp. 1-79.\n\n%\n% 135\n%\n\nThe convergence is obviously still uniform even if\n$\\absval{a_{n}} \\leq \\absval{a_{n+1}}$\nprovided the terms of the series are grouped so as to combine the\nterms corresponding to poles of equal moduli.\n\nIf, instead of the condition $\\absval{f(z)} < M$, we have the\ncondition $\\absval{ z^{-p} f(z) } < M$,\nwhere $M$ is independent of $m$ when $z$ is on $C_{m}$, and $p$ is\na positive integer, then we should have to\nexpand $\\int_{C} \\frac{f(z)}{z-x} \\dmeasure z$ by writing\n$$\n\\frac{1}{z-x}\n=\n\\frac{1}{z}\n+ \\frac{x}{z^{2}}\n+ \\cdots\n+ \\frac{x^{p+1}}{z^{p+1}(z-x)},\n$$\nand should obtain a similar but somewhat more complicated expansion.\n\\begin{wandwexample}\nProve that\n$$\n\\cosec z\n=\n\\frac{1}{z}\n+\n\\sum (-)^{n}\n\\theparen{\\frac{1}{z-n\\pi} + \\frac{1}{n\\pi}}\n$$\nthe summation extending to all positive and negative values of $n$.\n\nTo obtain this result, let $\\cosec z - \\frac{1}{z} = f(z)$.\nThe singularities of this function are at the\npoints $z=n\\pi$, where $n$ is any positive or negative integer.\n\nThe residue of $f(z)$ at the singularity $n\\pi$ is therefore\n$(-)^{n}$, and the reader will easily see that $\\absval{f(z)}$ is\nbounded on the circle $\\absval{z} = (n + \\half) \\pi$ as\n$n \\rightarrow \\infty$.\n\nApplying now the general theorem\n$$\nf(z)\n=\nf(0)\n+\n\\sum c_{n} \\thebracket{ \\frac{1}{z-a_{n}} + \\frac{1}{a_{n}}  },\n$$\nwhere $c_{n}$ is the residue at the singularity $a_{n}$, we have\n$$\nf(z)\n=\nf(0)\n+\n\\sum (-)^{n} \\thebrace{ \\frac{1}{z-n\\pi} + \\frac{1}{n\\pi}  }.\n$$\n\nBut\n$$\nf(0)\n=\n\\lim_{z \\rightarrow 0} \\frac{z - \\sin z}{z \\sin z} = 0.\n$$\n\nTherefore\n$$\n\\cosec z\n=\n\\frac{1}{z}\n+\n\\sum (-)^{n} \\thebracket{ \\frac{1}{z-n\\pi} + \\frac{1}{n\\pi}  },\n$$\nwhich is the required result.\n\\end{wandwexample}\n\\begin{wandwexample}\nIf $0<a<1$, shew that\n$$\n\\frac{e^{az}}{e^{z}-1}\n=\n\\frac{1}{z}\n+\n\\sum_{n=1}^{\\infty}\n\\frac{2z \\cos 2na\\pi - 4n\\pi \\sin 2na\\pi}{z^{2}+4n^{2}\\pi^{2}}.\n$$\n\\end{wandwexample}\n\\begin{wandwexample}\nProve that\n$$\n\\frac{1}{2 \\pi x^{2} (\\cosh x - \\cos x)}\n=\n\\frac{1}{2 \\pi x^{4}}\n-\n\\frac{1}{e^{\\pi}-e^{-\\pi}}\n\\frac{1}{\\pi^{4} + \\frac{1}{4} x^{4}}\n+\n\\frac{2}{e^{2 \\pi}-e^{-2 \\pi}}\n\\frac{1}{(2 \\pi)^{4} + \\frac{1}{4} x^{4}}\n-\n\\frac{3}{e^{3 \\pi}-e^{-3 \\pi}}\n\\frac{1}{(3 \\pi)^{4} + \\frac{1}{4} x^{4}}\n+\n\\cdots.\n$$\n\nThe general term of the series on the right is\n$$\n\\frac{(-)^{r} r}{(e^{r \\pi}-e^{-r \\pi})\n  \\thebrace{(r \\pi)^{4} + \\frac{1}{4} x^{4}}},\n$$\nwhich is the residue at each of the four singularities\n$r, -r, ri, -ri$ of the function\n$$\n\\frac{\\pi z}{(\\pi^{4}z^{4} + \\frac{1}{4} x^{4}) (e^{\\pi z} - e^{-\\pi\n    z}) \\sin \\pi z}.\n$$\n\n%\n% 136\n%\n\nThe singularities of this latter function which are not of the type\n$r, -r, ri, -ri$ are at the five points\n$$\n0,\n\\frac{(\\pm 1 \\pm i) x}{2 \\pi}.\n$$\nAt $z=0$ the residue is\n$$\n\\frac{2}{\\pi x^{4}};\n$$\nat each of the four points\n$\\frac{(\\pm 1 \\pm i) x}{2 \\pi}$, the residue is\n$$\n\\thebrace{\n  2 \\pi x^{2} (\\cos x - \\cosh x)\n}^{-1}\n$$\n\nTherefore\n\\begin{align*}\n  4\n  \\sum_{r=1}^{\\infty}\n  \\frac{(-)^{r} r}{e^{r\\pi} - e^{-r\\pi}}\n  \\frac{1}{(r\\pi)^{4} + \\frac{1}{4} x^{4}}\n  +\n  \\frac{2}{\\pi x^{4}}\n  -&\n  \\frac{2}{ \\pi x^{2} (\\cosh x - \\cos x)}\n  \\\\\n  &\n  =\n  \\frac{1}{2 \\pi i}\n  \\lim_{n \\rightarrow \\infty}\n  \\int_{C}\n  \\frac{\\pi z}{\n    (\\pi^{4}z^{4} + \\frac{1}{x^{4}})\n    (e^{\\pi z}-e^{-\\pi z})\n    \\sin \\pi z\n  }\n  \\dmeasure z,\n\\end{align*}\nwhere $C$ is the circle whose radius is $n + \\half$, ($n$ an integer),\nand whose centre is the origin. But, at points on $C$, this integrand is\n$\\bigo( \\absval{z}^{-3} )$; the limit of the integral round $C$ is\ntherefore zero.\n\nFrom the last equation the required result is now obvious.\n\\end{wandwexample}\n\\begin{wandwexample}\n  Prove that\n  $$\n  \\sec x\n  =\n  4 \\pi\n  \\theparen{\n    \\frac{1}{\\pi^{2} - 4 x^{2}}\n    -\n    \\frac{3}{9 \\pi^{2} - 4 x^{2}}\n    +\n    \\frac{5}{25 \\pi^{2} - 4 x^{2}}\n    -\n    \\cdots\n  }.\n  $$\n\\end{wandwexample}\n\\begin{wandwexample}\n  Prove that\n  $$\n  \\cosech x\n  =\n  \\frac{1}{x}\n  -\n  2x\n  \\theparen{\n    \\frac{1}{\\pi^{2} + x^{2}}\n    -\n    \\frac{1}{4\\pi^{2} + x^{2}}\n    +\n    \\frac{1}{9 \\pi^{2} + x^{2}}\n    -\n    \\cdots\n  }.\n  $$\n\\end{wandwexample}\n\\begin{wandwexample}\n  Prove that\n  $$\n  \\sec x\n  =\n  4 \\pi\n  \\theparen{\n    \\frac{1}{\\pi^{2} + 4 x^{2}}\n    -\n    \\frac{3}{9\\pi^{2} + 4 x^{2}}\n    +\n    \\frac{5}{25 \\pi^{2} + 4 x^{2}}\n    -\n    \\cdots\n  }.\n  $$\n\\end{wandwexample}\n\\begin{wandwexample}\n  Prove that\n  $$\n  \\coth x\n  =\n  \\frac{1}{x}\n  +\n  2x\n  \\theparen{\n    \\frac{1}{\\pi^{2} + x^{2}}\n    +\n    \\frac{1}{4 \\pi^{2} + x^{2}}\n    +\n    \\frac{1}{9 \\pi^{2} + x^{2}}\n    +\n    \\cdots\n  }.\n  $$\n\\end{wandwexample}\n\\begin{wandwexample}\n  Prove that\n  $$\n  \\sum_{m=-\\infty}^{\\infty}\n  \\sum_{n=-\\infty}^{\\infty}\n  \\frac{1}{ (m^{2}+a^{2}) (n^{2}+b^{2}) }\n  =\n  \\frac{\\pi^{2}}{ab} \\coth \\pi a \\coth \\pi b.\n  $$\n\\addexamplecitation{Math. Trip. 1899.}\n\\end{wandwexample}\n\\Section{7}{5}{The expansion of a class of functions as\ninfinite products.}\n\nThe theorem of the last article can be applied to the expansion of a\ncertain class of functions as infinite products.\n\nFor let $f(z)$ be a function which has simple zeros at the\npoints\\footnote{These being the only zeros of $f(z)$; and $a_{n} \\neq 0$.}\n$a_{1}, a_{2}, a_{3}, \\ldots$, where\n$\\lim_{n \\rightarrow \\infty} \\absval{a_{n}}$ is infinite; and let\n$f(z)$ be analytic for all values of $z$.\n\nThen $f'(z)$ is analytic for all values of $z$\n(\\hardsubsectionref{5}{2}{2}), and so $\\frac{f'(z)}{f(z)}$ can have\nsingularities only at the points $a_{1}, a_{2}, a_{3}, \\ldots$.\n\nConsequently, by Taylor's theorem,\n$$\nf(z)\n=\n(z-a_{r}) f'(a_{r})\n+\n\\frac{ (z-a_{r})^{2} }{2} f''(a_{r})\n+\n\\cdots\n$$\nand\n$$\nf'(z)\n=\nf'(a_{r})\n+\n(z-a_{r}) f''(a_{r})\n+\n\\cdots.\n$$\n\n/ /\n%\n% 137\n%\nIt follows immediately that at each of the points $a_{r}$, the\nfunction\n$\\frac{f'(z)}{f(z)}$ has a simple pole, with residue $+1$.\n\nIf then we can find a sequence of circles $C_{m}$ of the nature described\nin \\hardsectionref{7}{4}, such that $\\frac{f'(z)}{f(z)}$ is bounded on\n$C_{m}$ as $m \\rightarrow \\infty$, it follows, from the\nexpansion given in \\hardsectionref{7}{4}, that\n$$\n\\frac{f'(z)}{f(z)}\n=\n\\frac{f'(0)}{f(0)}\n+\n\\sum_{n=1}^{\\infty}\n\\thebrace{\n  \\frac{1}{z-a_{n}}\n  -\n  \\frac{1}{a_{n}}\n}.\n$$\n\nSince this series converges uniformly when the terms are suitably\ngrouped (\\hardsectionref{7}{4}), we may integrate term-by-term\n(\\hardsectionref{4}{7}). Doing so, and taking the exponential of each\nside, we get\n$$\nf(z)\n=\nc\ne^{ z \\frac{f'(0)}{f(0)} }\n\\prod_{n=1}^{\\infty}\n\\thebrace{\n  \\theparen{ 1 - \\frac{z}{a_{n}} }\n  e^{ \\frac{z}{a_{n}} }\n},\n$$\nwhere $c$ is independent of $z$.\n\nPutting $z = 0$, we see that $f(0) = c$, and thus the general result\nbecomes\n$$\nf(z)\n=\nf(0)\ne^{ z \\frac{f'(0)}{f(0)} }\n\\prod_{n=1}^{\\infty}\n\\thebrace{\n  \\theparen{ 1 - \\frac{z}{a_{n}} }\n  e^{ \\frac{z}{a_{n}} }\n}.\n$$\n\nThis furnishes the expansion, in the form of an infinite product, of\nany function $f(z)$ which fulfils the conditions stated.\n\\begin{wandwexample}\n  Consider the function\n  $f(z) = \\frac{\\sin z}{z}$, which has simple zeros at\n  the points $r \\pi$, where $r$ is any positive or negative integer.\n\n  In this case we have\n  $$\n  f(0) = 1,\n  \\quad\n  f'(0) = 0,\n  $$\n  and so the theorem gives immediately\n  $$\n  \\frac{\\sin z}{z}\n  =\n  \\prod_{n=1}^{\\infty}\n  \\thebrace{\n    \\theparen{1 - \\frac{z}{n \\pi}}\n    e^{ \\frac{z}{n \\pi} }\n  }\n  \\thebrace{\n    \\theparen{1 + \\frac{z}{n \\pi}}\n    e^{ -\\frac{z}{n \\pi} }\n  };\n  $$\n  for it is easily seen that the condition concerning the behaviour of\n  $\\frac{f'(z)}{f(z)}$ as $\\absval{z} \\rightarrow \\infty$ is fulfilled.\n\\end{wandwexample}\n\\begin{wandwexample}\n  Prove that\n  \\begin{align*}\n  \\thebrace{\n    1 + \\theparen{ \\frac{k}{x}  }^{2}\n  }\n  \\thebrace{\n    1 + \\theparen{ \\frac{k}{2\\pi - x}  }^{2}\n  }\n  &\n  \\thebrace{\n    1 + \\theparen{ \\frac{k}{2\\pi + x}  }^{2}\n  }\n  \\thebrace{\n    1 + \\theparen{ \\frac{k}{4\\pi - x}  }^{2}\n  }\n  \\thebrace{\n    1 + \\theparen{ \\frac{k}{4\\pi + x}  }^{2}\n  } \\cdots\n  \\\\\n  =&\n  \\frac{\\cosh x - \\cos x}{1-\\cos x}.\n  \\end{align*}\n\\addexamplecitation{Trinity, 1899.}\n\\end{wandwexample}\n\\Section{7}{6}{The factor theorem of Weierstrass*.}\n\nThe theorem of \\hardsectionref{7}{5} is very similar to a more general theorem in\nwhich the character of the function $f(z)$, as\n$\\absval{z} \\rightarrow \\infty$, is not so\nnarrowly restricted.\n\n* Berliner Alh. (1876), pp. 11-60; Math. Werke, 11. (1895), pp.\n77-124.\n%\n% 138\n%\nLet $f(z)$ be a function of $z$ with no essential singularities (except at\n`the point infinity'); and let the zeros and poles of $f(z)$ be at\n$a_{1}, a_{2}, a_{3}, \\ldots$, where\n$0 < \\absval{a_{1}} \\leq \\absval{a_{2}} \\leq \\absval{a_{3}} \\ldots$.\nLet the zero\\footnote{We here regard a pole as being a zero of\n  negative order.} at $a_{n}$ be of (integer) order $m_{n}$.\n\nIf the number of zeros and poles is unlimited, it is necessary that\n$\\absval{a_{n}} \\rightarrow \\infty$, as $n \\rightarrow \\infty$;\nfor, if not, the points $a_{n}$ would have a limit\npoint\\footnote{From the two-dimensional analogue\n  of \\hardsubsectionref{2}{2}{1}.},\nwhich would be an essential singularity of $f(z)$.\n\nWe proceed to shew first of all that it is possible to find\npolynomials $g(z)$ such that\n$$\n\\prod_{n=1}^{\\infty}\n\\thebracket{\n  \\thebrace{\n    \\theparen{\n      1\n      -\n      \\frac{z}{a_{n}}\n    }\n    e^{g_{n}(z)}\n  }^{m_{n}}\n}\n$$\nconverges for all\\footnote{Provided that $z$ is not at one of the points $a_{m}$\n  for which $m$ is negative.} finite values of $z$.\n\nLet $K$ be any constant, and let $\\absval{z} < K$; then, since\n$\\absval{a_{n}} \\rightarrow \\infty$, we can\nfind $N$ such that, when $n > N$, $\\absval{a_{n}} > 2K$.\n\nThe first $N$ factors of the product do not affect its\nconvergence\\footnote{Provided that $z$ is not at one of the points $a_{m}$\n  for which $m$ is negative.}; % TODO:duplicated-footnote\nconsider any value of $n$ greater than $N$, and let\n$$\ng_{n}(z)\n=\n\\frac{z}{a_{n}}\n+\n\\half \\theparen{ \\frac{z}{a_{n}} }^{2}\n+\n\\cdots\n+\n\\frac{1}{k_{n}-1}\n\\theparen{ \\frac{z}{a_{n}} }^{k_{n} - 1}.\n$$\nThen\n\\begin{align*}\n  \\absval{\n    -\n    \\sum_{m=1}^{\\infty}\n    \\frac{1}{m}\n    \\theparen{\n      \\frac{z}{a_{n}}\n    }^{m}\n    +\n    g_{n}\n  }\n  =&\n  \\absval{\n    \\sum_{m=k_{n}}^{\\infty}\n    \\frac{1}{m}\n    \\theparen{\n      \\frac{z}{a_{n}}\n    }^{m}\n  }\n  \\\\\n  <&\n  \\absval{ \\frac{z}{a_{n}} }^{k_{n}}\n  \\sum_{m=0}^{\\infty}\n  \\absval{ \\frac{z}{a_{n}} }^{m}\n  \\\\\n  <&\n  2\n  \\absval{ (K a_{n}^{-1})^{k_{n}}  },\n\\end{align*}\nsince\n$ \\absval{ z_{n} a_{n}^{-1} } < \\half$.\n\nHence\n$$\n\\thebrace{\n  \\theparen{\n    1\n    -\n    \\frac{z}{a_{n}}\n  }\n  e^{g_{n}(z)}\n}^{m_{n}}\n=\ne^{u_{n}(z)},\n$$\nwhere\n$$\n\\absval{ u_{n}(z) }\n\\leq\n2\n\\absval{\n  m_{n}\n  (K a_{n}^{-1})^{k_{n}}\n}.\n$$\n\nNow $m_{n}$ and $a_{n}$ are given, but $k_{n}$ is at our disposal;\nsince $K a_{n}^{-1} < \\half$, we\nchoose $k_{n}$ to be the smallest number such that\n$2 \\absval{m_{n} (K a_{n}^{-1})^{k_{n}}} < b_{n}$,\nwhere\n$\\sum_{n=1}^{\\infty} b_{n}$ is any convergent series\\footnote{E.g. we\n  might take $b_{n} = 2^{-n}$.} of positive terms.\n\nHence\n$$\n\\prod_{n = N+1}^{\\infty}\n\\thebracket{\n  \\thebrace{\n    \\theparen{\n      1\n      -\n      \\frac{z}{a_{n}}\n    }\n    e^{g_{n}(z)}\n  }^{m_{n}}\n}\n=\n\\prod_{n = N+1}^{\\infty}\ne^{u_{n}(z)},\n$$\nwhere\n$ \\absval{ u_{n}(z) } < b_{n} $;\nand therefore, since $b_{n}$ is independent of $z$, the\nproduct converges absolutely and uniformly when\n$\\absval{z} < K$, except near the points $a_{n}$.\n%\n% 139\n%\n\nNow let\n$$\nF(z)\n=\n\\prod_{n=1}^{\\infty}\n\\thebracket{\n  \\thebrace{\n    \\theparen{\n      1\n      -\n      \\frac{z}{a_{n}}\n    }\n    e^{g_{n}(z)}\n  }^{m_{n}}\n}.\n$$\n\nThen, if $f(z) \\div F(z) = G_{1}(z)$, $G_{1}(z)$ is an integral\nfunction (\\hardsubsectionref{5}{6}{4}) of $z$ and has no zeros.\n\nIt follows that\n$\\frac{1}{G_{1}(z)} \\frac{\\dd}{\\dd z} G_{1}(z)$\nis analytic for all finite values of $z$; and so, by Taylor's theorem,\nthis function can be expressed as a series $\\sum_{n=1}^{\\infty} n\nb_{n} z^{n-1}$ converging everywhere; integrating, it follows that\n$$\nG_{1}(z) = c e^{G(z)},\n$$\nwhere $G(z) = \\sum_{n=1}^{\\infty} b_{n} z^{n}$ and $c$ is a constant;\nthis series converges everywhere, and so $G(z)$ is an integral\nfunction.\n\nTherefore, finally,\n$$\nf(z)\n=\nf(0)\ne^{G(z)}\n\\prod_{n=1}^{\\infty}\n\\thebracket{\n  \\thebrace{\n    \\theparen{\n      1\n      -\n      \\frac{z}{a_{n}}\n    }\n    e^{g_{n}(z)}\n  }^{m_{n}}\n},\n$$\nwhere $G(z)$ is some integral function such that $G(0) = 0$.\n%\\begin{smalltext}\n[Note. The presence of the arbitrary element $G(z)$ which occurs in\nthis formula for $f(z)$ is due to the lack of conditions as to the\nbehaviour of $f(z)$ as $\\absval{z} \\rightarrow \\infty$.]\n\n\\corollary. If $m_{n} =1$, it is\nsufficient to take $k_{n} = n$, by \\hardsubsectionref{2}{3}{6}.\n%\\end{smalltext}\n\\Section{7}{7}{The expansion of a class of periodic functions in a series of\ncotangents.}\n\nLet $f(z)$ be a periodic function of $z$, analytic except at a certain\nnumber of simple poles; for convenience, let $\\pi$ be the period of\n$f(z)$ so that $f(z) = f(z + \\pi)$.\n\nLet $z = x + iy$ and let $f(z) \\rightarrow l$ uniformly with respect\nto $x$ as $y \\rightarrow +\\infty$,\nwhen $0 \\leq x \\leq \\pi$; similarly let $f(z) \\rightarrow l'$\nuniformly as $y \\rightarrow -\\infty$.\n\nLet the poles of $f(z)$ in the strip $0 < x \\leq \\pi$ be at\n$a_{1}, a_{2}, \\ldots, a_{n}$; and\nlet the residues at them be $c_{1}, c_{2}, \\ldots, c_{n}$.\n\nFurther, let $ABCD$ be a rectangle whose corners are\\footnote{If any\n  of the poles are on $x = \\pi$, shift the rectangle slightly to\n  the right; $\\rho, \\rho'$ are to be taken so large that\n  $a_{1}, a_{2}, \\ldots, a_{n}$ are\n  inside the rectangle.}\n$-i\\rho$, $\\pi - i\\rho$, $\\pi + i\\rho'$, and $i\\rho'$ in order.\n\nConsider\n$$\n\\frac{1}{2 \\pi i}\n\\int f(t) \\cot (t-z) \\dmeasure t\n$$\ntaken round this rectangle; the residue of the integrand at $a_{r}$ is\n$c_{r} \\cot (a_{r}-z)$, and the residue at $z$ is $f(z)$.\n\nAlso the integrals along $DA$ and $CB$ cancel on account of the\nperiodicity of the integrand; and as $\\rho \\rightarrow \\infty$,\nthe integrand on $AB$ tends\nuniformly to $l' i$, while as $\\rho' \\rightarrow \\infty$\nthe integrand on $CD$ tends uniformly\nto $-li$; therefore\n$$\n\\half (l' + l)\n=\nf(z)\n+\n\\sum_{r=1}^{n}\nc_{r}\n\\cot (a_{r} - z).\n$$\n%\n% 140\n%\n\nThat is to say, we have the expansion\n$$\nf(z)\n=\n\\half (l' + l)\n+\n\\sum_{r=1}^{n}\nc_{r}\n\\cot (z - a_{r}).\n$$\n\\begin{wandwexample}\n  \\begin{align*}\n    \\cot (x - a_{1})\n    \\cot (x - a_{2})\n    \\cdots\n    \\cot (x - a_{n})\n    =&\n    \\sum_{r=1}^{n}\n    \\cot (a_{r} - a_{1})\n    \\cdots\n    *\n    \\cdots\n    \\cot (a_{r} - a_{n})\n    \\cot (x - a_{r})\n    +\n    (-)^{\\half n},\n    \\\\\n    \\textrm{or}\n    =&\n    \\sum_{r=1}^{n}\n    \\cot (a_{r} - a_{1})\n    \\cdots\n    *\n    \\cdots\n    \\cot (a_{r} - a_{n})\n    \\cot (x - a_{r}),\n  \\end{align*}\naccording as $n$ is even or odd; the `$*$' means that the factor\n$\\cot (a_{r} - a_{r})$ is omitted.\n\\end{wandwexample}\n\\begin{wandwexample}\nProve that\n\\begin{align*}\n  \\frac{\n    \\sin (x - b_{1})\n    \\sin (x - b_{2})\n    \\cdots\n    \\sin (x - b_{n})\n  }{\n    \\sin (x - a_{1})\n    \\sin (x - a_{2})\n    \\cdots\n    \\sin (x - a_{n})\n  }\n  =&\n  \\frac{\n    \\sin (a_{1} - b_{1})\n    \\cdots\n    \\sin (a_{1} - b_{n})\n  }{\n    \\sin (a_{1} - a_{2})\n    \\cdots\n    \\sin (a_{1} - a_{n})\n  }\n  \\cot (x - a_{1})\n  \\\\\n  &\n  +\n  \\frac{\n    \\sin (a_{2} - b_{1})\n    \\cdots\n    \\sin (a_{2} - b_{n})\n  }{\n    \\sin (a_{2} - a_{1})\n    \\cdots\n    \\sin (a_{2} - a_{n})\n  }\n  \\cot (x - a_{2})\n  \\\\\n  &\n  +\n  \\cdots\n  \\\\\n  &\n  +\n  \\cos (a_{1} + a_{2} + \\cdots + a_{n}\n  - b_{1} - b_{2} - \\cdots - b_{n}).\n\\end{align*}\n\\end{wandwexample}\n\\Section{7}{8}{Borel's theorem.}\n\\footnote{TODO Lemons sur les series divergentes (1901), p. 94. See also the\nmemoirs there cited.}\n\nLet $f(z) = \\sum_{n=0}^{\\infty} a_{n} z^{n}$ be analytic when\n$\\absval{z} \\leq r$, so that, by\n\\hardsubsectionref{5}{2}{3},\n$\\absval{ a_{n} r^{n} } < M$\nwhere $M$ is independent of $n$.\n\nHence, if\n$\\phi(z) = \\sum_{n=0}^{\\infty} \\frac{a_{n} z^{n}}{n!}$,\n$\\phi(z)$ is an integral function, and\n$$\n\\absval{ \\phi(z) }\n<\n\\sum_{n=0}^{\\infty} \\frac{M \\absval{z^{n}} }{ r^{n} \\cdot n!}\n=\nM e^{\\absval{z}/r},\n$$\nand similarly\n$\\absval{ \\phi^{(n)}(z) } < M e^{\\absval{z}/r}/r^{n}$.\n\nNow consider\n$f_{1}(z) = \\int_{0}^{\\infty} e^{-t} \\phi(zt) \\dmeasure t$;\nthis integral is an analytic function\nof $z$ when $\\absval{z} < r$, by \\hardsubsectionref{5}{3}{2}.\n\nAlso, if we integrate by parts,\n\\begin{align*}\n  f_{1}(z)\n  =&\n  \\thebracket{- e^{-t} \\phi(zt) }_{0}^{\\infty}\n  +\n  z \\int_{0}^{\\infty} e^{-t} \\phi'(zt) \\dmeasure t\n  \\\\\n  =&\n  \\sum_{m=0}^{n}\n  z^{m}\n  \\thebracket{ - e^{-t} \\phi^{(m)}(zt) }_{0}^{\\infty}\n  +\n  z^{n+1}\n  \\int_{0}^{\\infty}\n  e^{-t} \\phi^{(n+1)}(zt) \\dmeasure t.\n\\end{align*}\n\nBut $\\lim_{t \\rightarrow 0} e^{-t} \\phi^{(m)}(zt) = a_{m}$; and,\nwhen $\\absval{z} < r$,\n$\\lim_{t \\rightarrow \\infty} e^{-t} \\phi^{(m)}(zt) = 0$.\n\nTherefore\n$$\nf_{1}(z) = \\sum_{m=0}^{n} a_{m} z^{m} + R_{n},\n$$\n%\n% 141\n%\nwhere\n\\begin{align*}\n  TODO\n\\end{align*}\n\nConsequently, when $\\absval{z} < r$,\n$$\nf_{1}(z) = \\sum_{m=0}^{\\infty} a_{m} z^{m} = f(z);\n$$\nand so\n$$\nf(z) = \\int_{0}^{\\infty} e^{-t} \\phi(zt) \\dmeasure t,\n$$\nwhere\n$\n\\phi(z) = \\sum_{n=0}^{\\infty} \\frac{a_{n} z^{n}}{n!};\n$\nis called \\emph{Borel's function} associated with\n$\\sum_{n=0}^{\\infty} a_{n} z^{n}$.\n\nIf\n$S = \\sum_{n=0}^{\\infty} a_{n}$\nand\n$\\phi(z) = \\sum_{n=0}^{\\infty} \\frac{a_{n} z^{n}}{n!}$\nand if we can establish the relation\n$S = \\int_{0}^{\\infty} e^{-t} \\phi(t) \\dmeasure t$,\nthe series $S$ is said \\hardsubsectionref{8}{4}{1}) to be\n'\\emph{summable (B)}; so that the\ntheorem just proved shews that a Taylor's series representing an\nanalytic function is summable (B).\n\n\\Subsection{7}{8}{1}{Borel's integral and analytic continuation.}\nWe next obtain Borel's result that his integral represents an analytic\nfunction in a more extended region than the interior of the circle\n$\\absval{z} = r$.\n\nTODO:figure\n\nThis extended region is obtained as follows: take the singularities\n$a,b,c,\\ldots$ of $f(z)$ and through each of them draw a line perpendicular\nto the line joining that singularity to the origin. The lines so drawn\nwill divide the plane into regions of which one is a polygon with the\norigin inside it.\n\n\\emph{Then Borel's integral represents an analytic function}\n(which, by \\hardsectionref{5}{5}\nand \\hardsectionref{7}{8}, is obviously that defined by $f(z)$\nand its continuations)\n\\emph{throughout the interior of this polygon.} The reader will observe that\nthis is the first actual formula obtained for the analytic\ncontinuation of a function, except the trivial one of\n\\hardsectionref{5}{5}, example.\n\nFor, take any point $P$ with affix $\\zeta$ inside the polygon; then\nthe circle on $OP$ as diameter has no singularity on or inside\nit\\footnote{The reader will see this from the figure; for if there were such a\nsingularity the corresponding side of the polygon would pass between\n$O$ and $P$; \\ie,\n $P$ would be outside the polygon.}; and\nconsequently we can draw a slightly\n%\n% 142\n%\nlarger concentric circle\\footnote{The differeuce of the radii of the\n  circles being, say, $\\delta$.} $C$ with no singularity on or inside\nit. Then, by \\hardsectionref{5}{4},\n$$\na_{n}\n=\n\\frac{1}{2 \\pi i}\n\\int_{C} \\frac{f(z)}{z^{n+1}} \\dmeasure z,\n$$\nand so\n$$\n\\phi(\\zeta t)\n=\n\\frac{1}{2 \\pi i}\n\\sum_{n=0}^{\\infty}\n\\frac{\\zeta^{n} t^{n}}{n!}\n\\int_{C} \\frac{f(z)}{z^{n+1}} \\dmeasure z;\n$$\nbut\n$\\sum_{n=0}^{\\infty} \\frac{\\zeta^{n} t^{n}}{n!} \\frac{f(z)}{z^{n+1}}$\nconverges uniformly (\\hardsubsectionref{3}{3}{4}) on $C$ since\n$f(z)$ is bounded and $\\absval{z} \\geq \\delta > 0$, where\n$\\delta$ is independent of $z$; therefore, by \\hardsectionref{4}{7},\n$$\n\\phi(\\zeta t)\n=\n\\frac{1}{2 \\pi i}\n\\int_{C} z^{-1} f(z) \\exp(\\zeta t z^{-1}) \\dmeasure z,\n$$\nand so, when $t$ is real,\n$\\absval{\\phi(\\zeta t)} < F(\\zeta) e^{\\lambda t}$,\nwhere $F(\\zeta)$ is bounded in any closed region lying wholly\n\\emph{inside} the polygon and is independent of $t$;\nand $\\lambda$ is the greatest value of the real part of\n$\\zeta / z$ on $C$.\n\nIf we draw the circle traced out by the point $z/\\zeta$, we see that\nthe real part of $\\zeta/z$ is greatest when $z$ is at the extremity of the\ndiameter through $\\zeta$, and so the value of $\\lambda$ is\n$ \\absval{\\zeta} \\cdot \\thebrace{\\absval{\\zeta} + \\delta}^{-1} < 1$.\n\nWe can get a similar inequality for $\\phi'(\\zeta t)$ and hence,\nby \\hardsubsectionref{5}{3}{2},\n$\\int_{0}^{\\infty} e^{-t} \\phi(\\zeta t) \\dmeasure t$\nis analytic at $\\zeta$ and is obviously a one-valued function of\n$\\zeta$.\n\nThis is the result stated above.\n\n\\Subsection{7}{8}{2}{Expansions in series of inverse factorials.}\n\nA mode of development of functions, which, after being used by\nNicole\\footnote{TODO Mem de VAcad. des Sci. (Paris, 1717); see Tweedie, Proc. Edin. Math.\n  Soc. xxxvi. (1918).}\nand\nStirling\\footnote{TODO Methodus Dijferentialis (Londou, 1730).}\nin the eighteenth century, was systematically\ninvestigated by\n\\Schlomilch\\footnote{TODO Compendium der h'dheren AnalysU. More recent investigations are due\nto Kluyver, Nielsen and Pincherle. See Comptes liendiis, cxxxiii.\n(1901), cxxxiv. (1902), Annales de I'Ecole norm, sup. (3), XIX.,\nXIII., xxiii., JRendiconti del Lincei, (5), xi. (1902), and Palermo\nRendiconti, xxxiv. (1912). Properties of functions defined by series\nof inverse factorials have been studied in an important memoir by\nNorlund, Acta Math, xxxvii. (1914), pp. 327-H87.}\nin 1863, is that of expansion in a series\nof inverse factorials.\n\nTo obtain such an expansion of a function analytic when\n$\\absval{z} > r$, we let\nthe function be\n$f(z) = \\sum_{n=0}^{\\infty} a_{n} z^{-n}$, and use the formula\n$f(z) = \\int_{0}^{\\infty} z e^{-tz} \\phi(t) \\dmeasure t$,\nwhere $\\phi(t) = \\sum_{n=0}^{\\infty} a_{n} t^{n} / n!$;\nthis result may be obtained in the same way as\nthat of \\hardsectionref{7}{8}.\nModify this by writing\n$e^{-t} = 1 - \\xi$, $\\phi(t) = F(\\xi)$;\nthen\n$$\nf(z)\n=\n\\int_{0}^{1}\nz (1 - \\xi)^{z-1} F(\\xi) \\dmeasure \\xi.\n$$\n\nNow if $t = u + iv$ and if $t$ be confined to the strip\n$-\\pi < v < \\pi$, $t$ is a\none-valued function of $\\xi$ and $F(\\xi)$ is an analytic function of\n$\\xi$; and $\\xi$ is\nrestricted so that $-\\pi < \\arg (1-\\xi) < \\pi$. Also the interior of the\ncircle $\\absval{\\xi} = 1$ corresponds\n%\n% 143\n%\nto the interior of the curve traced out by the point\n$t = - \\log \\theparen{2 \\cos \\half \\theta} + \\half i \\theta$,\n(writing $\\xi= \\exp \\thebrace{i (\\theta + \\pi) }$ ); and inside this curve\n$$\n\\absval{t} - \\Re(t)\n\\leq\n\\sqrt{ \\thebrace{\\Re(t)}^{2} + \\pi^{2} }\n-\n\\Re(t)\n\\rightarrow\n0,\n$$\nas $\\Re(t) \\rightarrow \\infty$.\n\nIt follows that, when $\\absval{\\xi} \\leq 1$,\n$\\absval{F(\\xi)} < M e^{r\\absval{t}} < M_{1} \\absval{e^{rt}}$,\nwhere $M_{1}$ is independent of $t$; and so\n$F(\\xi) < M_{1} \\absval{(1-\\xi)^{-r}}$.\n\nNow suppose that $0 \\leq \\xi < 1$; then, by\n\\hardsubsectionref{5}{2}{3},\n$\\absval{F^{(n)}(\\xi)} < M_{2} n! \\rho^{-n}$\nwhere $M_{2}$ is the upper bound of\n$\\absval{F(z)}$ on a circle with centre $\\xi$ and\nradius $\\rho < 1 - \\xi$.\n\nTaking $\\rho = \\frac{n}{n+1} (1-\\xi)$ and observing\nthat\\footnote{ $(1 + x^{-1})^{x}$ increases with $x$;\n  for $\\frac{1}{1-y} > e^{y}$, when $y < 1$, and so\n  $\\log \\theparen{\\frac{1}{1-y}} > y$. That is to\n  say, putting $y^{-1} = 1+x$,\n  $\n  \\frac{\\dd}{\\dd x} x \\log (1 + x^{-1})\n  =\n  \\log (1 + x^{-1})\n  -\n  \\frac{1}{1+x}\n  >\n  0\n  $.\n}\n$(1 + n^{-1})^{n} < e$\nwe find that\n\\begin{align*}\n  \\absval{F^{(n)}(\\xi)}\n  <&\n  M_{1}\n  \\thebracket{\n    1\n    -\n    \\thebrace{\n      \\xi\n      +\n      \\frac{n}{n+1} \\xi\n    }\n  }^{-r}\n  \\cdot\n  n!\n  \\thebrace{\n    \\frac{n (1-\\xi)}{n+1}\n  }^{-n}\n  \\\\\n  <&\n  M_{1} e (n+1)^{r} n! (1-\\xi)^{-r-n}.\n\\end{align*}\n\nRemembering that, by \\hardsectionref{4}{5}, $\\int_{0}^{1}$ means\n$\\lim_{\\epsilon \\rightarrow +0} \\int_{0}^{1-\\epsilon}$, we\nhave, by repeated integrations by parts,\n\\begin{align*}\n  f(z)\n  =&\n  \\lim_{\\epsilon \\rightarrow +0}\n  \\thebracket{\n    -(1 - \\xi)^{z} F(\\xi)\n  }_{0}^{1-\\epsilon}\n  +\n  \\int_{0}^{1 - \\epsilon}\n  (1 - \\xi)^{z} F'(\\xi) \\dmeasure \\xi\n  \\\\\n  =&\n  \\lim_{\\epsilon \\rightarrow +0}\n  \\thebracket{\n    -(1 - \\xi)^{z} F(\\xi)\n  }_{0}^{1 - \\epsilon}\n  +\n  \\frac{1}{z + 1}\n  \\thebracket{\n    -(1 - \\xi)^{z+1} F'(\\xi)\n  }_{0}^{1 - \\epsilon}\n  \\\\\n  &\n  \\quad\n  \\quad\n  +\n  \\frac{1}{z + 1}\n  \\int_{0}^{1 - \\epsilon}\n  (1 - \\xi)^{z+1} F''(\\xi) \\dmeasure \\xi\n  \\\\\n  =&\n  \\cdots\n  \\\\\n  =&\n  b_{0}\n  +\n  \\frac{b_{1}}{z+1}\n  +\n  \\frac{b_{2}}{(z+1)(z+2)}\n  +\n  \\cdots\n  +\n  \\frac{b_{n}}{(z+1)(z+2)\\cdots(z+n)}\n  +\n  R_{n},\n\\end{align*}\nwhere\n\\begin{align*}\n  b_{n}\n  =&\n  \\lim_{\\epsilon \\rightarrow 0}\n  \\thebracket{\n    -(1-\\xi)^{z+n} F^{(n)}(\\xi)\n  }_{0}^{1 - \\epsilon}\n  \\\\\n  =&\n  F^{(n)}(0),\n\\end{align*}\nif the real part of $z+n-r-n>0$, \\ie if $\\Re(z) > r$;\nfurther\n\\begin{align*}\n  \\absval{R_{n}}\n  \\leq &\n  \\frac{1}{ \\absval{ (z+1)(z+2)\\cdots(z+n)  }}\n  \\lim_{\\epsilon \\rightarrow 0}\n  \\int_{0}^{1 - \\epsilon}\n  \\absval{ (1-\\xi)^{z+n} F^{(n+1)}(\\xi) }\n  \\dmeasure \\xi\n  \\\\\n  <&\n  \\frac{ M_{1} e (n+2)^{r} n!}{\n    \\absval{(z+1)(z+2)\\cdots(z+n)} \\Re(z-r)}\n  \\\\\n  <&\n  \\frac{ M_{1} e (n+2)^{r} n!}{\n    \\absval{ (r+1+\\delta)(r+2+\\delta) \\cdots (r+n+\\delta) \\delta }\n    },\n\\end{align*}\nwhere $\\delta = \\Re(z - r)$.\n%\n% 144\n%\n\nNow\n$$\n\\prod_{m=1}^{n}\n\\thebrace{\n  \\theparen{\n    1\n    +\n    \\frac{r + \\delta}{m}\n  }\n  e^{-\\frac{r+\\delta}{m}}\n}\n$$\ntends to a limit \\hardsubsectionref{2}{7}{1}) as\n$n \\rightarrow \\infty$, and so $\\absval{R_{n}} \\rightarrow 0$\nif\n$ (n+2)^{r} e^{-(r+\\delta) \\sum_{1}^{n} 1/m} $\ntends to zero; but\n$$\n\\sum_{m=1}^{n} 1/m\n>\n\\int_{1}^{n+1} \\frac{\\dmeasure x}{x}\n=\n\\log(n+1),\n$$\nby \\hardsubsectionref{4}{4}{3} (II), % TODO:insertref\nand $(n + 2)^{r} (n+1)^{-r-\\delta} \\rightarrow 0$ when\n$\\delta > 0$; therefore $R_{n} \\rightarrow 0$ as\n$n \\rightarrow \\infty$, and so, when $\\Re(z) > r$,\nwe have the convergent expansion\n$$\nf(z)\n=\nb_{0}\n+\n\\frac{b_{1}}{z+1}\n+\n\\frac{b_{2}}{(z+1)(z+2)}\n+\n\\cdots +\n\\frac{b_{n}}{(z+1)(z+2)\\cdots(z+n)}\n+\n\\cdots.\n$$\n\\begin{wandwexample}\nObtain the same expansion by using the results\n$$\n\\frac{1}{(z+1)(z+2)\\cdots(z+n+1)}\n=\n\\frac{1}{n!}\n\\int_{0}^{1} u^{n} (1-u)^{z} \\dmeasure u,\n$$\n$$\n\\int_{C}\n\\frac{ f(t) \\dmeasure t }{z - t}\n=\n\\int_{C} \\dmeasure t\n\\int_{0}^{1}\nf(t) (1-u)^{z-t-1} \\dmeasure u.\n$$\n\\end{wandwexample}\n\\begin{wandwexample}\nObtain the expansion\n$$\n\\log\\theparen{1 + \\frac{1}{z}}\n=\n\\frac{1}{z}\n-\n\\frac{a_{1}}{z(z+1)}\n-\n\\frac{a_{2}}{z(z+1)(z+2)}\n-\n\\cdots,\n$$\nwhere\n$$\na_{n}\n=\n\\int_{0}^{1}\nt (1-t) (2-t) \\cdots (n-1-t) \\dmeasure t,\n$$\nand discuss the region in which it converges.\n\\addexamplecitation{Schlomilch.}\n\\end{wandwexample}\n\n%TODO\nREFERENCES. E. Goursat, Cours d' Analyse (Paris, 1911), Chs. xv, xvi.\nE. BoREL, Lecons sur les series divergentes (Paris, 1901). T. J. I'a.\nBromwich\\footnote{The expansions considered by Eromwich are obtained by elementary\nmethods, i.e. without the use of Cauchy's theorem.} Theory of Infinite\nSeries (1908), Chs. viii, x, xi. 0.\nSchlomilch, Compendium der hoheren Analysis, ii. (Dresden, 1874).\n\n\\begin{wandwmiscexamples}\n  \\begin{wandwmiscexample}\n    If $y - x - \\phi(y) = 0$, where $\\phi$ is a given function of\n    its argument, obtain the expansion\n    $$\n    f(y)\n    =\n    f(x)\n    +\n    \\sum_{m=1}^{\\infty}\n    \\frac{1}{m!}\n    \\thebrace{\\phi(x)}^{m}\n    \\theparen{\n      \\frac{1}{1-\\phi'(x)}\n      \\frac{\\dd}{\\dd x}\n    }^{m}\n    f(x),\n    $$\n    where $f$ denotes any analytic function of its argument, and discuss\n    the range of its validity.\n    \\addexamplecitation{TODO:Levi-Civitk, Bertd. dei Lincei, (5), xvl\n      (1907), p. 3.}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    Obtain (from the formula of Darboux or otherwise) the expansion\n    $$\n    f(z) - f(a)\n    =\n    \\sum_{n=1}^{\\infty}\n    \\frac{(-)^{n-1} (z-a)^{n}}{n! (1-r)^{n}}\n    \\thebrace{\n      f^{(n)}(z) - r^{n} f^{(n)}(a)\n    };\n    $$\n    find the remainder after $n$ terms, and discuss the\n    convergence of the series.\n  \\end{wandwmiscexample}\n  % 145\n  %\n  \\begin{wandwmiscexample}\n    Shew that\n    \\begin{align*}\n      f(x+h) - f(x)\n      =&\n      \\sum_{m=1}^{n}\n      (-)^{m-1}\n      \\frac{1 \\cdot 3 \\cdot 5 \\cdots (2m-1)}{(m!)^{2}}\n      \\frac{h^{m}}{2^{m}}\n      \\thebrace{\n        f^{(m)}(x+h)\n        -\n        (-)^{m} f^{(m)}(x)\n      }\n      \\\\\n      & \\quad\n      +\n      (-)^{n} h^{n+1}\n      \\int_{0}^{1}\n      \\gamma_{n}(t)\n      f^{(n+1)}(x + ht) \\dmeasure t,\n    \\end{align*}\n    where\n    $$\n    \\gamma_{n}(t)\n    =\n    \\frac{x^{n+\\half} (1-x)^{n + \\half}}{(n!)^{2}}\n    \\frac{\\dd^{n}}{\\dd x^{n}}\n    \\thebrace{\n      x^{-\\half} (1-x)^{-\\half}\n    }\n    =\n    \\frac{1}{\\pi n!}\n    \\int_{0}^{1}\n    (x-z)^{n}\n    z^{-\\half}\n    (1-z)^{-\\half}\n    \\dmeasure z,\n    $$\n    and shew that $\\gamma_{n}(x)$ is the coefficient of\n    $n! t^{n}$ in the expansion of\n    $\\thebrace{ (1-tx)(1+t-tx) }^{-\\half}$\n    in ascending powers of $t$.\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    By taking\n    $$\n    \\phi(x+1)\n    =\n    \\frac{1}{n!}\n    \\thebracket{\n      \\frac{\\dd^{n}}{\\dd u^{n}}\n      \\thebrace{\n        \\frac{(1-r)e^{xu}}{1 - r e^{-u}}\n      }\n    }_{n=0}\n    $$\n    in the formula of Darboux, shew that\n    \\begin{align*}\n      f(x+h) - f(x)\n      =&\n      -\n      \\sum_{m=1}^{n}\n      a_{m}\n      \\frac{h^{m}}{m!}\n      \\thebrace{\n        f^{(m)}(x+h) - \\frac{1}{r} f^{(m)}(x)\n      }\n      \\\\\n      & \\quad\n      +\n      (-)^{n} h^{n+1}\n      \\int_{0}^{1}\n      \\phi(t) f^{(n+1)}(x+ht) \\dmeasure t,\n    \\end{align*}\n    where\n    $$\n    \\frac{1-r}{1 - r e^{-u}}\n    =\n    1\n    -\n    a_{1} \\frac{u}{1!}\n    +\n    a_{2} \\frac{u^{2}}{2!}\n    -\n    a_{3} \\frac{u^{3}}{3!}\n    +\n    \\cdots.\n    $$\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    Shew that\n    \\begin{align*}\n      f(z) - f(a)\n      =&\n      \\sum_{m=1}^{n}\n      (-)^{m-1}\n      \\frac{2 B_{m} (2^{2n} - 1)(z-a)^{2m-1}}{2m!}\n      \\thebrace{\n        f^{(2m-1)}(a)\n        +\n        f^{(2m-1)}(z)\n      }\n      \\\\\n      &\n      \\hfill +\n      \\frac{(z-a)^{2n+1}}{2n!}\n      \\int_{0}^{1}\n      \\psi_{2n}(t)\n      f^{(2n+1)}\\thebrace{\n        a + t(z-a)\n      }\n      \\dmeasure t,\n    \\end{align*}\n    where\n    $$\n    \\psi_{n}(t)\n    =\n    \\frac{2}{n+1}\n    \\thebracket{\n      \\frac{\\dd^{n+1}}{\\dd u^{n+1}}\n      \\theparen{\n        \\frac{u e^{tu}}{e^{u} + 1}\n      }\n    }_{u=0}.\n    $$\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    Prove that\n    \\begin{align*}\n      &\n      f(z_{2}) - f(z_{1})\n      =\n      C_{1} (z_{2} - z_{1}) f'(z_{2})\n      +\n      C_{2} (z_{2} - z_{1})^{2} f''(z_{1})\n      -\n      C_{3} (z_{2} - z_{1})^{3} f'''(z_{2})\n      \\\\\n      &\n      -C_{4} (z_{2}-z_{1})^{4} f^{\\textrm{iv}}(z_{1})\n      +\n      \\cdots\n      +\n      (-)^{n} (z_{2} - z_{1})^{n+1}\n      \\int_{0}^{1}\n      \\thebrace{\n        \\frac{\\dd^{n}}{\\dd u^{n}}\n        \\theparen{\n          e^{tu} \\sech u\n        }\n      }_{u=0}\n      f^{(n+1)}(z_{1} + t z_{2} - t z_{1})\n      \\dmeasure t;\n    \\end{align*}\n    in the series plus signs and minus signs occur in pairs, and the last\n    term before the integral is that involving\n    $(z_{2}-z_{1})^{n}$, also $C_{n}$ is the\n    coefficient of $z^{n}$ in the expansion of\n    $\\cot\\theparen{\\frac{\\pi}{4} - \\frac{z}{2}}$\n    in ascending powers of $z$. \\addexamplecitation{Trinity, 1899.}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    If $x_{1}$ and $x_{2}$ are integers, and $\\phi(z)$ is a function\n    which is analytic and bounded for all values of $z$ such that\n    $x_{1} \\leq \\Re(z) \\leq x_{2}$, shew (by integrating\n    $$\n    \\int \\frac{\\phi(z) \\dmeasure z}{ e^{\\pm 2 \\pi i z} - 1 }\n    $$\n    round indented rectangles whose corners are\n    $x_{1}$, $x_{2}$, $x_{2} \\pm \\infty i$, $x_{1} \\pm \\infty i$)\n    that\n    \\begin{align*}\n      &\n      \\half \\phi(x_{1})\n      + \\phi(x_{1} + 1)\n      + \\phi(x_{1} + 2)\n      + \\cdots\n      + \\phi(x_{2} - 1)\n      + \\half \\phi(x_{2})\n      \\hfill\n      \\\\\n      &\n      \\hfill =\n      \\int_{x_{1}}^{x_{2}} \\phi(z) \\dmeasure z\n      +\n      \\frac{1}{i}\n      \\int_{0}^{\\infty}\n      \\frac{ \\phi(x_{2}+iy) - \\phi(x_{1}+iy)\n        - \\phi(x_{2}-iy) + \\phi(x_{1}-iy)}{ e^{2 \\pi y} - 1 }\n      \\dmeasure y.\n    \\end{align*}\n    Hence, by applying the theorem\n    $$\n    4n\n    \\int_{0}^{\\infty}\n    \\frac{y^{2n-1}}{e^{2 \\pi y} - 1}\n    \\dmeasure y\n    =\n    B_{n},\n    $$\n    %\n    % 146\n    %\n    where $B_{1}, B_{2}, \\ldots$ are \\Bernoulli's numbers, shew that\n    $$\n    \\phi(1) + \\phi(2) + \\cdots + \\phi(n)\n    =\n    C\n    + \\half \\phi(n)\n    + \\int^{n} \\phi(z) \\dmeasure z\n    +\n    \\sum_{r=1}^{\\infty}\n    \\frac{(-)^{r-1} B_{r}}{2r!} \\phi^{(2r-1)}(n),\n    $$\n    (where $C$ is a constant not involving $n$), provided that the\n    last series converges.\n\n    (This important formula is due to TODO Plana, Mem. della R, Accad. di\n    Torino, xxv. (1820), pp. 403-418; a proof by means of contour\n    integration was published by Kronecker, Journal fur Math. cv. (1889),\n    pp. 345-348. For a detailed history, see Lindelof, Le Calcul des\n    Residus. Some applications of the formula are given in Chapter xii.)\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    Obtain the expansion\n    $$\n    u\n    =\n    \\frac{x}{2}\n    +\n    \\sum_{n=2}^{\\infty}\n    (-)^{n-1}\n    \\frac{1 \\cdot 3 \\cdots (2n-3)}{n!}\n    \\frac{x^{n}}{2^{n}}\n    $$\n    for one root of the equation\n    $x = 2u + u^{2}$ and shew that it converges so\n    long as $\\absval{x} < 1$.\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    If $S^{(m)}_{2n+1}$ denote the sum of all combinations of the numbers\n    $$\n    1^{2}, 3^{2}, 5^{2}, \\ldots (2n-1)^{2},\n    $$\n    taken $m$ at a time, shew that\n    $$\n    \\frac{\\cos z}{z}\n    =\n    \\frac{1}{\\sin z}\n    +\n    \\sum_{n=0}^{\\infty}\n    \\frac{(-)^{n+1}}{(2n+2)!}\n    \\thebrace{\n      \\frac{2^{2(n+1)}}{2n+3}\n      -\n      S^{(1)}_{2(n+1)}\n      \\frac{2^{2n}}{2n+1}\n      +\n      \\cdots\n      +\n      (-)^{n}\n      S^{(n)}_{2(n+1)}\n      \\frac{2^{2}}{3}\n    }\n    \\sin^{2n+1} z.\n    $$\n    \\addexamplecitation{Teixeira.}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    If the function $f(z)$ is analytic in the interior of that one of\n    the ovals whose equation is $\\absval{\\sin z} = C$\n    (where $C \\leq 1$), which includes the origin, shew that $f(z)$\n    can, for all points $z$ within this oval, be\n    expanded in the form\n    \\begin{align*}\n      f(z)\n      =&\n      f(0)\n      +\n      \\sum_{n=1}^{\\infty}\n      \\frac{ f^{(2n)}(0)\n        + S^{(1)}_{2n} f^{(2n-2)}(0)\n        + \\cdots\n        S^{(n-1)}_{2n} f''(0)\n      }{2n!}\n      \\sin^{2n} z\n      \\\\\n      &\n      \\quad +\n      \\sum_{n=0}^{\\infty}\n      \\frac{\n        f^{(2n+1)}(0)\n        + S^{(1)}_{2n+1} f^{(2n-1)}(0)\n        + \\cdots\n        + S^{(n)}_{2n+1} f'(0)\n      }{(2n+1)!}\n      \\sin^{2n+1} z,\n    \\end{align*}\n    where $S^{(m)}_{2n}$ is the sum of all combinations of the numbers\n    $$\n    2^{2}, 4^{2}, 6^{2}, \\ldots, (2n-2)^{2},\n    $$\n    taken $m$ at a time, and $S^{(m)}_{2n+1}$ denotes the\n    sum of all combinations of the numbers\n    $$\n    1^{2}, 3^{2}, 5^{2}, \\ldots, (2n-1)^{2},\n    $$\n    taken $m$ at a time.\n    \\addexamplecitation{Teixeira.}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    Shew that the two series\n    $$\n    2z\n    + \\frac{2 z^{3}}{3^{2}}\n    + \\frac{2 z^{5}}{5^{2}}\n    + \\cdots\n    $$\n    and\n    $$\n    \\frac{2z}{1 - z^{2}}\n    -\n    \\frac{2}{1 \\cdot 3^{2}}\n    \\theparen{\n      \\frac{2z}{1 - z^{2}}\n    }^{3}\n    +\n    \\frac{2 \\cdot 4}{3 \\cdot 5^{2}}\n    \\theparen{\n      \\frac{2z}{1 - z^{2}}\n    }^{5}\n    -\n    \\cdots\n    $$\n    represent the same function in a certain region of the $z$ plane,\n    and can be transformed into each other by \\Burmann's theorem.\n\n    \\addexamplecitation{TODO Kapteyn, Nieuw Archief, (2), iii. (1897), p. 225.}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    If a function $f(z)$ is periodic, of period $2 \\pi$, and is\n    analytic at all points in the infinite strip of the plane,\n    included between the two branches of the curve\n    $\\absval{\\sin z} = C$ (where $C > 1$),\n    shew that at all points in the strip it can be expanded in\n    an infinite series of the form\n    \\begin{align*}\n      f(z)\n      =&\n      A_{0} + A_{1} \\sin z + \\cdots + A_{n} \\sin^{n} z + \\cdots\n      \\\\\n      &\n      \\hfill\n      + \\cos z\n      ( B_{1} + B_{2} \\sin z + \\cdots + B_{n} \\sin^{n-1} z + \\cdots );\n    \\end{align*}\n    and find the coefficients\n    $A_{n}$ and $B_{n}$.\n  \\end{wandwmiscexample}\n  %\n  % 147\n  %\n  \\begin{wandwmiscexample}\n    If $\\phi$ and $f$ are connected by the equation\n    $$\n    \\phi(x) + \\lambda f(x) = 0,\n    $$\n    of which one root is $a$,\n    shew that\n    $$\n    TODO\n    $$\n    the general term being\n    $\n    (-)^{m}\n    \\frac{\\lambda^{m}}{1! 2! \\cdots m! (\\phi')^{\\half m(m+1)}}\n    $\n    multiplied by a determinant in which\n    the elements of the first row are\n    $\\phi', (\\phi^{2})', (\\phi^{3})', \\ldots, (\\phi^{m-1})', (f^{m} F')$\n    and each row is the differential coefficient of the preceding\n    one with respect to $a$; and\n    $F, f, F', \\ldots$ denote\n    $F(a), f(a), F'(a), \\ldots$.\n\n    (TODOWronski, Philosophie de la Technie, Section ii. p. 381. For proofs of\n    the theorem see Cayley, Quarterly Journal, xil. (1873), Transon, Nouv.\n    Ann. de Math. xill. (1874j, and C Lagrange, Brux. Mem. Couronnes, 4\",\n    xlvii. (1886), no. 2.)\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    If the function $W(a, b, x)$ be defined by the series\n    $$\n    W(a,b,x)\n    =\n    x\n    + \\frac{a-b}{2!} x^{2}\n    + \\frac{(a-b)(a-2b)}{3!} x^{3}\n    + \\cdots,\n    $$\n    which converges so long as\n    $$\n    \\absval{x} < \\frac{1}{\\absval{b}},\n    $$\n    shew that\n    $$\n    \\frac{\\dd}{\\dd x} W(a,b,x)\n    =\n    1\n    +\n    (a-b) W(a-b,b,x);\n    $$\n    and shew that if\n    $$\n    y = W(a,b,x),\n    $$\n    then\n    $$\n    x = W(b,a,y).\n    $$\n\n    Examples of this function are\n    \\begin{align*}\n      W(1,0,x) =& e^{x} - 1, \\\\\n      W(0,1,x) =& \\log (1+x), \\\\\n      W(a,1,x) =& \\frac{(1+x)^{a} - 1}{a}.\n    \\end{align*}\n    \\addexamplecitation{\\Jezek}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    Prove that\n    $$\n    \\frac{1}{ \\sum_{n=0}^{\\infty} a_{n} x^{n}}\n    =\n    \\frac{1}{a_{0}}\n    +\n    \\sum_{1}^{\\infty}\n    \\frac{ (-)^{n} x^{n} }{ n! a_{0}^{n+1} } G_{n},\n    $$\n    where\n    $$\n    TODO\n    $$\n    and obtain a similar expression for\n    $$\n    \\thebrace{\n      \\sum_{n=0}^{\\infty} a_{n} x^{n}\n    }^{\\half}.\n    $$\n    \\addexamplecitation{TODO Mangeot, Ann. de VEcole norm. sup. (3), xiv.}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    Shew that\n    $$\n    \\frac{1}{ \\sum_{r=0}^{n} a_{r} x^{r} }\n    =\n    -\n    \\sum_{r=0}^{\\infty}\n    \\frac{1}{r+1}\n    \\frac{\\partial S_{r+1}}{\\partial a_{1}} x^{r},\n    $$\n    %\n    % 148\n    %\n    where $S_{r}$ is the sum of the $r$-th powers of the reciprocals of\n    the roots of the equation\n    $$\n    \\sum_{r=0}^{n} a_{r} x^{r} = 0.\n    $$\n    \\addexamplecitation{TODO Gambioli, Bologna Memorie, 1892.}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    If $f_{n}(z)$ denote the $n$th derivate of $f(z)$, and if\n    $f_{-n}(z)$ denote that one of the $n$th integrals of\n    $f(z)$ which has an $n$-ple zero at $z=0$,\n    shew that if the series\n    $$\n    \\sum_{n=-\\infty}^{\\infty} f_{n}(z) g_{-n}(x)\n    $$\n    is convergent it represents a function of $z + x$;\n    and if the domain of convergence includes the origin in the\n    $x$-plane, the series is equal to\n    $$\n    \\sum_{n=0}^{\\infty} f_{-n}(z+x) g_{n}(0).\n    $$\n    Obtain Taylor's series from this result, by putting $g(z) = 1$.\n    \\addexamplecitation{Guichard.}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    Shew that, if $x$ be not an integer,\n    $$\n    TODO\n    $$\n    as $\\nu \\rightarrow \\infty$, provided that all terms for which\n    $m = n$ are omitted from the summation.\n    \\addexamplecitation{Math. Trip. 1895.}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    Sum the series\n    $$\n    \\sum_{n=-q}^{p}\n    \\theparen{\n      \\frac{1}{(-)^{n} x-a-n}\n      +\n      \\frac{1}{n}\n    },\n    $$\n    where the value $n = 0$ is omitted, and $p,q$ are\n    positive integers to be increased without\n    limit.\n    \\addexamplecitation{Math. Trip. 1896.}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    If\n    $\n    F(x)\n    =\n    e^{\\int_{0}^{x} x \\pi \\cot (x \\pi) \\dmeasure x}\n    $, shew that\n    $$\n    F(x)\n    =\n    e^{x}\n    \\frac{\n      \\prod\\limits_{n=1}^{\\infty} \\thebrace{\n        \\theparen{1 - \\frac{x}{n}}^{n}\n        e^{x + \\half \\frac{x^{2}}{n}}\n      }\n    }{\n    \\prod\\limits_{n=1}^{\\infty} \\thebrace{\n      \\theparen{1 + \\frac{x}{n}}^{n}\n      e^{-x + \\half \\frac{x^{2}}{n}}\n      }\n    },\n    $$\n    and that the function thus defined satisfies the relations\n    $$\n    F(-x) = \\frac{1}{F(x)},\n    \\quad\n    F(x) F(1-x) = 2 \\sin x \\pi.\n    $$\n    Further, if\n    $$\n    \\psi(z)\n    =\n    z\n    + \\frac{z^{2}}{2^{2}}\n    + \\frac{z^{3}}{3^{2}}\n    + \\cdots\n    =\n    - \\int_{0}^{z} \\log (1-t) \\frac{\\dmeasure t}{t},\n    $$\n    shew that\n    $$\n    F(x)\n    =\n    e^{\\half \\pi i x^{2}\n      -\n      \\frac{1}{2 \\pi i}\n      \\psi( 1 - e^{-2 \\pi i x} )\n    }\n    $$\n    when\n    $$\n    \\absval{ 1 - e^{-2 \\pi i x} } < 1.\n    $$\n    \\addexamplecitation{Trinity, 1898.}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    Shew that\n    \\begin{align*}\n      &\n      \\thebracket{\n        1 + \\theparen{\\frac{k}{x}}^{n}\n      }\n      \\thebracket{\n        1 + \\theparen{\\frac{k}{2 \\pi - x}}^{n}\n      }\n      \\thebracket{\n        1 + \\theparen{\\frac{k}{2 \\pi + x}}^{n}\n      }\n      \\thebracket{\n        1 + \\theparen{\\frac{k}{4 \\pi - x}}^{n}\n      }\n      \\thebracket{\n        1 + \\theparen{\\frac{k}{4 \\pi + x}}^{n}\n      } \\cdots\n      \\\\\n      &\n      \\hfill =\n      \\frac{\n        \\prod_{g=1}^{\\leq \\half n}\n        \\sqrt{1 - 2 e^{-\\alpha_{g}} \\cos(x + \\beta_{g}) + e^{-2\\alpha_{g}}}\n        \\sqrt{1 - 2 e^{-\\alpha_{g}} \\cos(x - \\beta_{g}) + e^{-2\\alpha_{g}}}\n      }{\n        2^{\\half n}\n        (1 - \\cos x)^{\\half n}\n        e^{-k \\cos \\pi / n}\n      },\n    \\end{align*}\n    where\n    $$\n    \\alpha_{g} = k \\sin \\frac{2g-1}{n} \\pi,\n    \\quad\n    \\beta_{g} = k \\cos \\frac{2g-1}{n} \\pi,\n    $$\n    and\n    $$\n    0 < x < 2 \\pi.\n    $$\n    \\addexamplecitation{Mildner.}\n  \\end{wandwmiscexample}\n  %\n  % 149\n  %\n  \\begin{wandwmiscexample}\n    If $\\absval{x} < 1$ and $a$ is not a positive integer, shew that\n    $$\n    \\sum_{n=1}^{\\infty}\n    \\frac{x^{n}}{n - a}\n    =\n    \\frac{2 \\pi i x^{a}}{1 - e^{2 a \\pi i}}\n    +\n    \\frac{x}{1 - e^{2 a \\pi i}}\n    \\int_{C} \\frac{t^{a-1} - x^{a-1}}{t - x} \\dmeasure t,\n    $$\n    where $C$ is a contour in the plane enclosing the points $0,x$.\n    \\addexamplecitation{TODO Lerch, Casopis, xxi. (1892), pp. 65-68.}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    If $\\phi_{1}(z), \\phi_{2}(z), \\ldots$ are any polynomials in $z$,\n    and if $F(z)$ be any integrable function, and if\n    $\\psi_{1}(z), \\psi_{2}(z), \\ldots$ be polynomials\n    defined by the equations\n    \\begin{align*}\n      &\n      \\int_{a}^{b}\n      F(x) \\frac{ \\phi_{1}(z) - \\phi_{TODO}(x) }{z - x}\n      \\dmeasure x\n      =\n      \\psi_{1}(z),\n      \\\\\n      &\n      \\int_{a}^{b}\n      F(x) \\phi_{1}(x)\n      \\frac{ \\phi_{2}(z) - \\phi_{2}(x) }{z - x}\n      \\dmeasure x\n      =\n      \\psi_{2}(z),\n      \\\\\n      &\n      \\int_{a}^{b}\n      F(x)\n      \\phi_{1}(x) \\phi_{2}(x) \\cdots \\phi_{m-1}(x)\n      \\frac{\\phi_{m}(z) - \\phi_{m}(x)}{z-x}\n      \\dmeasure x\n      =\n      \\psi_{m}(z),\n    \\end{align*}\n    Shew that\n    \\begin{align*}\n      &\n      \\hfill\n      \\int_{a}^{b}\n      \\frac{F(x) \\dmeasure x}{z - x}\n      =\n      \\frac{\\psi_{1}(z)}{\\phi_{1}(z)}\n      +\n      \\frac{\\psi_{2}(z)}{\\phi_{1}(z) \\phi_{2}(z)}\n      +\n      \\frac{\\psi_{3}(z)}{\\phi_{1}(z) \\phi_{2}(z) \\phi_{3}(z)}\n      +\n      \\cdots\n      \\hfill\n      \\\\\n      &\n      +\n      \\frac{\\psi_{m}(z)}{\\phi_{1}(z) \\phi_{2}(z) \\cdots \\phi_{m}(z)}\n      +\n      \\frac{1}{\\phi_{1}(z) \\phi_{2}(z) \\cdots \\phi_{m}(z)}\n      \\int_{a}^{b}\n      F(x) \\phi_{1}(x) \\phi_{2}(x) \\cdots \\phi_{m}(x)\n      \\frac{ \\dmeasure x }{z - x}.\n    \\end{align*}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    A system of functions $p_{0}(z), p_{1}(z), p_{2}(z), \\ldots$\n    is defined by the equations\n    $$\n    p_{0}(z) = 1,\n    \\quad\n    p_{n+1}(z) = (z^{2} + a_{n} z + b_{n}) p_{n}(z),\n    $$\n    where $a_{n}$ and $b_{n}$ are given functions of $n$, which tend\n    respectively to the limits $0$ and $-1$ as $n \\rightarrow \\infty$.\n\n    Shew that the region of convergence of a series of the form\n    $\\sum e_{n} p_{n}(z)$ where\n    $e_{1}, e_{2}, \\ldots$ are independent of $z$, is a Cassini's oval\n    with the foci $+1, -1$.\n\n    Shew that every function $f(z)$, which is analytic on and inside the\n    oval, can, for points inside the oval, be expanded in a series\n    $$\n    f(z) = \\sum (c_{n} + z c'_{n}) p_{n}(z) % TODO: verify\n    $$\n    where\n    $$\n    c_{n}\n    =\n    \\frac{1}{2 \\pi i} \\int (a_{n}+z) q_{n}(z) f(x) \\dmeasure z,\n    \\quad\n    c'_{n}\n    =\n    \\frac{1}{2 \\pi i} \\int q_{n}(z) f(z) \\dmeasure z,\n    $$\n    the integrals being taken round the boundary of the region, and the\n    functions $q_{n}(z)$ being defined by the equations\n    $$\n    q_{0} = \\frac{1}{z^{2} + a_{0} z + b_{0}},\n    \\quad\n    q_{n+1}(z)\n    =\n    \\frac{1}{z^{2} + a_{n+1} z + b_{n+1}}\n    q_{n}(z).\n    $$\n    \\addexamplecitation{TODO Pincherle, Rend, dei Lincei, (4), v. (1889), p. 8.}\n  \\end{wandwmiscexample}\n  \\begin{wandwmiscexample}\n    Let $C$ be a contour enclosing the point $a$, and let $\\phi(z)$ and\n    $f(z)$ be analytic when $z$ is on or inside $C$. Let $\\absval{t}$ be so small that\n    $$\n    \\absval{ t \\phi(z) } < \\absval{ z - a }\n    $$\n    when $z$ is on the periphery of $C$. By expanding\n    $$\n    \\frac{1}{2 \\pi i}\n    \\int_{C}\n    f(z)\n    \\frac{1 - t \\phi'(z)}{z - a - t \\phi(z)}\n    \\dmeasure z\n    $$\n    in ascending powers of $t$, shew that it is equal to\n    $$\n    f(a)\n    +\n    \\sum_{n=1}^{\\infty}\n    \\frac{ t^{n} }{n!}\n    \\frac{ \\dd^{n-1} }{ \\dd a^{n-1} }\n    \\thebracket{ f'(a) \\thebrace{\\phi(a)}^{n}\n    }.\n    $$\n    Hence, by using \\hardsectionref{6}{3}, \\hardsubsectionref{6}{3}{1}, obtain Lagrange's theorem.\n  \\end{wandwmiscexample}\n\\end{wandwmiscexamples}", "meta": {"hexsha": "40ef4e96eb9de6e901709ebcf845c3b4de40bf32", "size": 71704, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch07.tex", "max_stars_repo_name": "CdLbB/Whittaker-and-Watson", "max_stars_repo_head_hexsha": "5fefdd2c36b4e48cc078a88afc77df289e680a73", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/tex/wandw-ch07.tex", "max_issues_repo_name": "CdLbB/Whittaker-and-Watson", "max_issues_repo_head_hexsha": "5fefdd2c36b4e48cc078a88afc77df289e680a73", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tex/wandw-ch07.tex", "max_forks_repo_name": "CdLbB/Whittaker-and-Watson", "max_forks_repo_head_hexsha": "5fefdd2c36b4e48cc078a88afc77df289e680a73", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.3411458333, "max_line_length": 115, "alphanum_fraction": 0.5605126632, "num_tokens": 29183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.7076947540067133}}
{"text": "\\chapter{Binary Logic}\n\nThe basic idea of binary logic is that a particular statement or questions has one of two possible values assigned to it. It is called binary because the two possibilities form a pair, like a pair of wheels on a bicycle. However, a statement can only be assigned one value at a time: It is either \\textcolor{blue}{true}, or it is \\textcolor{red}{false}. As a flowchart, this allows a branching of a program based on the truth value.\\\\\n\n\\begin{center} \\imagegraphic[0.3]{flowchart_true.png}\\end{center}\n\nWe will also use what is called a Venn diagram to understand when certain combinations of statements are true or false. In the following diagram there is only one statement. The circle is colored blue because inside the circle represents when the questions \"Is A true?\" is a true statement. Outside the circle represents when the answer to that question is false.\\\\\n\n\\begin{center} \\imagegraphic[0.5]{A_venn.png}\\end{center}\n\n\\section{Logical Operators}\n\nThe logical operators (AND, OR, NOT) are ways of combining truth values of multiple statements, resulting in a new truth value. You can think of them kind of like arithmetic operations, except for boolean values (true or false) instead of numbers.\\\\\n\n\\section{The OR Operator}\n\nTo illustrate how they work, imagine someone is trying to get into a locked room full of gold. The room has some set of doors that leads to the room, and each door requires a key to open. In this first scenario, the room has two doors either one of which will let the person in. If they have at least one of the keys, they can get in. This is like the OR operation.\\\\\n\n\\begin{center} \\imagegraphic[1.0]{OR.png}\\end{center}\n\nNow to put this in more mathematical terms, the truth values of A and B are referring to whether that person has the key for that door. And the resulting truth value is whether they are able to get the gold. So, if I say \\(A=true\\), then I am saying they have the key for door A. \\(A=false\\) would mean that they don't have that key. And \\(B=true\\) means they have the key for door B, etc.\\\\\n\nWhen I say \\(A\\: OR \\: B\\), the result is true if they have either key, even if they have both keys at the same time. The result is false only if they have neither key. There are two keys, and there are two truth values for each one (do they have it or not). \\(2 \\times 2 = 4\\) possible combinations. If it helps you, every possible result can be listed in a table\\\\\n\n\\begin{center}\n\t\\begin{tabular}{c | c | c}\n\t\thas key A & has key B & A OR B = gets the gold\\\\ \\hline\n\t\t\\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{red}{false}\\\\ \\hline\n\t\t\\textcolor{blue}{true} & \\textcolor{red}{false} & \\textcolor{blue}{true} \\\\ \\hline\n\t\t\\textcolor{red}{false} & \\textcolor{blue}{true} & \\textcolor{blue}{true} \\\\ \\hline\n\t\t\\textcolor{blue}{true} & \\textcolor{blue}{true} &\\textcolor{blue} {true} \\\\ \\hline\n\t\\end{tabular}\n\\end{center}\n\nWe can also view the OR operations as the result of a flowchart. You can see below why there is only one way of getting a false result with the OR operation: both A and B have to be false to get false. But there is more than one way to get true.\n\n\\begin{center} \\imagegraphic[0.5]{flowchart_OR.png}\\end{center}\n\nYet another way of visualizing an OR operation is in a Venn diagram. The idea of a Venn diagram is to look at all the ways a statement is true. The points inside the A circle represents when A is true, and the points outside of that circle are when A is false. The same is true for the B circle and the truth of B. The combination of both circles is a collection of points representing when either A is true or B is true, which is the same as the statement A OR B.\n\n\\begin{center} \\imagegraphic[0.5]{OR_venn.png}\\end{center}\n\n\\section{The AND Operator}\n\nIn the next scenario, the one door is behind the other door. If the person has key A, but not key B, they cannot get in. If they have key B but not key A, they still cannot get in. \\\\\n\n\\begin{center} \\imagegraphic[1.0]{AND.png}\\end{center}\n\nSo, the result of A AND B is only true if they have both keys; that is, both A and B are true. If either A or B are false, or both, then the result is false.\n\n\\begin{center}\n\t\\begin{tabular}{c | c | c}\n\t\thas key A & has key B & A AND B = gets the gold \\\\ \\hline\n\t\t\\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{red}{false}\\\\ \\hline\n\t\t\\textcolor{blue}{true} & \\textcolor{red}{false} & \\textcolor{red}{false} \\\\ \\hline\n\t\t\\textcolor{red}{false} & \\textcolor{blue}{true} & \\textcolor{red}{false} \\\\ \\hline\n\t\t\\textcolor{blue}{true} & \\textcolor{blue}{true} & \\textcolor{blue}{true} \\\\ \\hline\n\t\\end{tabular}\n\\end{center}\n\nWe can also view the AND operation as the result of a flowchart, and why there is only one way of getting a true result from an AND operation; both A and B have to be true. But there is more than one way to get false.\n\n\\begin{center} \\imagegraphic[0.3]{flowchart_AND.png}\\end{center}\n\n\nAs a Venn diagram, the AND operation selects only the area that is common to both A and B.\n\n\\begin{center} \\imagegraphic[0.5]{AND_venn.png}\\end{center}\n\n\n\\section{Order of Operations}\n\nLogical operators can be combined just like arithmetic operators can. Parenthesis can be used to specify the order of the operations. In this example, the operation A or B is performed first. The result of that is then used with the AND operation. To get into the first room, they only need one key: either A OR B. But to get into the gold room, they also need key C no matter what.\\\\\n\n\\begin{center} \\imagegraphic[1.0]{AorBandC.png}\\end{center}\n\nThis time there are 8 total possible outcomes because there are three keys, each with two possible states (has it or doesn't have it): \\(2 \\times 2 \\times 2 = 8 \\). But since they can only get in if they also have key C, then only those times can they get the gold.\n\n\\begin{center}\n\t\\begin{tabular}{c | c | c | c | c}\n\t\tA & B & C & A OR B & (A OR B) AND C = gets the gold\\\\ \\hline\n\t\t\\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{red}{false}\\\\ \\hline\n\t\t\\textcolor{red}{false} & \\textcolor{blue}{true} & \\textcolor{red}{false} & \\textcolor{blue}{true} & \\textcolor{red}{false}\\\\ \\hline\n\t\t\\textcolor{blue}{true} & \\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{blue}{true} & \\textcolor{red}{false}\\\\ \\hline\n\t\t\\textcolor{blue}{true} & \\textcolor{blue}{true} & \\textcolor{red}{false} & \\textcolor{blue}{true} & \\textcolor{red}{false}\\\\ \\hline\n\n\t\t\\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{blue}{true} & \\textcolor{red}{false} & \\textcolor{red}{false}\\\\ \\hline\n\t\t\\textcolor{red}{false} & \\textcolor{blue}{true} & \\textcolor{blue}{true} & \\textcolor{blue}{true} & \\textcolor{blue}{true}\\\\ \\hline\n\t\t\\textcolor{blue}{true} & \\textcolor{red}{false} & \\textcolor{blue}{true} & \\textcolor{blue}{true} & \\textcolor{blue}{true}\\\\ \\hline\n\t\t\\textcolor{blue}{true} & \\textcolor{blue}{true} & \\textcolor{blue}{true} & \\textcolor{blue}{true} & \\textcolor{blue}{true}\\\\ \\hline\n\t\\end{tabular}\n\\end{center}\n\nAs a flowchart, I simply added an AND using the result of the OR operation.\n\n\\begin{center} \\imagegraphic[0.5]{flowchart_ORAND.png}\\end{center}\n\n\n\nLogical operations can usually be thought of in different ways. We could have also thought about the above problem as having two different ways of getting into the gold room. Either having keys A AND C, or having keys B AND C. So, we could write the same result as:\\\\\n\n\\begin{center}\n\t(A AND C) OR (B AND C) = (A OR B) AND C\n\\end{center}\n\n\\begin{center} \\imagegraphic[0.5]{ORAND_venn.png}\\end{center}\n\nIn the following scenario the AND operation is done first, however, so that means that even if they don't have either key B or key C, they can still get in if they have key A. But if they don't have key A, then they have to have both keys B and C to get in.\\\\\n\n\\begin{center} \\imagegraphic[1.0]{AorBandC2.png}\\end{center}\n\n\\begin{center}\n\t\\begin{tabular}{c | c | c | c | c}\n\t\tA & B & C & B AND C & A OR (B AND C) = gets the gold\\\\ \\hline\n\t\t\\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{red}{false}\\\\ \\hline\n\t\t\\textcolor{red}{false} & \\textcolor{blue}{true} & \\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{red}{false}\\\\ \\hline\n\t\t\\textcolor{blue}{true} & \\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{blue}{true}\\\\ \\hline\n\t\t\\textcolor{blue}{true} & \\textcolor{blue}{true} & \\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{blue}{true}\\\\ \\hline\n\n\t\t\\textcolor{red}{false} & \\textcolor{red}{false} & \\textcolor{blue}{true} & \\textcolor{red}{false} & \\textcolor{red}{false}\\\\ \\hline\n\t\t\\textcolor{red}{false} & \\textcolor{blue}{true} & \\textcolor{blue}{true} & \\textcolor{blue}{true} & \\textcolor{blue}{true}\\\\ \\hline\n\t\t\\textcolor{blue}{true} & \\textcolor{red}{false} & \\textcolor{blue}{true} & \\textcolor{red}{false} & \\textcolor{blue}{true}\\\\ \\hline\n\t\t\\textcolor{blue}{true} & \\textcolor{blue}{true} & \\textcolor{blue}{true} & \\textcolor{blue}{true} & \\textcolor{blue}{true}\\\\ \\hline\n\t\\end{tabular}\n\\end{center}\n\nNow that the AND is performed first, and OR is second, it causes a minor difference in the flowchart. See if you can spot the difference, and why that means there are more ways for it to result in true than when the OR was done first.\n\n\\begin{center} \\imagegraphic[0.5]{flowchart_ANDOR.png}\\end{center}\n\n\nIf there are no parenthesis, then AND is done first. So:\n\n\\begin{center}A OR B AND C = A OR (B AND C)\\end{center}\n\t\nsince AND gets higher precedence anyway. However, always using parenthesis has the added benefit of always making you think about want you \\textit{intend} to do, which helps prevent mistakes.\n\n\\begin{center} \\imagegraphic[0.5]{ANDOR_venn.png}\\end{center}\n\n\\section{The NOT Operator}\n\nThe NOT operation simply takes a truth value, and gives whatever the opposite value would be. For example, if A = false (they don't have key A), then that means that NOT A = true. It is just like saying \"they don't have key A\" (which is true if A = false). If A = true, then NOT A = false, since \"they don't have key A\" is a false statement in that case.\\\\\n\nWe can also view the NOT operation as the result of a flowchart.\n\n\\begin{center} \\imagegraphic[0.3]{flowchart_NOT.png}\\end{center}\n\nThis leads to several important identities. Take the first example where we have A OR B. So, lets say A OR B = G, where G is true when they can get the gold. But say we want to know when NOT G, when do they not get the gold? Well logically they don't get the gold if they don't have either key: NOT G = (NOT A) AND (NOT B). But if we replace the G with the original thing we get the following identity:\n\n\\begin{center}\n\tNOT (A OR B) = (NOT A) AND (NOT B)\n\\end{center}\n\nIn the view of the flowchart, it is as simple as flipping the results. True becomes false, and false becomes true. \n\n\\begin{center} \\imagegraphic[0.5]{flowchart_NOTOR.png}\\end{center}\n\nBut then where does AND factor in on the right hand side? It's there because it's doing an AND on the 'no' branches now, instead of the 'yes'. I'll rearrange it a little by flipping the no/yes branches coming out of each condition so you can see it really does mean AND.\n\n\\begin{center} \\imagegraphic[0.3]{flowchart_NOTOR2.png}\\end{center}\n\nNow lets do the same thing for the second case where G = A AND B. Logically, they won't get the gold if they don't have one of the keys. So, NOT G = (NOT A) OR (NOT B). Now replacing G with A AND B we get:\n\n\\begin{center}\n\tNOT (A AND B) = (NOT A) OR (NOT B)\n\\end{center}\n\n\\begin{center} \\imagegraphic[0.3]{flowchart_NOTAND.png}\\imagegraphic[0.47]{flowchart_NOTAND2.png}\\end{center}\n\nYou may notice a pattern here. When you negate an OR, you negate both sides of the OR and then switch the OR to an AND. Also, when you negate an AND, you negate both sides and switch it to an OR.\\\\\n\nTo negate more complicated expressions, like (A OR B) AND C, you could do one of two things. One, you cold look at the problem and figure out the case where they don't get the gold. Here they can't get it if they're missing both the A key and the B key, or they're missing the C key. So:\n\n\\begin{center}\n\tNOT((A OR B) AND C) = ((NOT A) AND (NOT B)) OR (NOT C)\n\\end{center}\n\nIf you notice though, once you have the identities for AND and OR by themselves, you can apply the NOT starting from the 'outside' and working in. For the case G = A OR (B AND C), the last operation to be done is the OR. So, negate the OR first, which causes B AND C to be negated, so you can use the other identity to negate that one.\n\n\\begin{center}\n\tNOT(A OR (B AND C)) = (NOT A) AND (NOT (B AND C))\\\\\n\t\n\tNOT(A OR (B AND C)) = (NOT A) AND ((NOT B) OR (NOT C))\n\\end{center}\n\nSo, for the case of G = A OR (B AND C), we can see they don't get the gold if don't have key A, and they also don't have just one of key B or key C.\\\\", "meta": {"hexsha": "0c38f16ec69b6db4ffcab8172a3830189845047d", "size": 12914, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TeX_files/LogicBinary.tex", "max_stars_repo_name": "kcdodd/ecsp-book", "max_stars_repo_head_hexsha": "371e0e07140bc2fa5a8e3d424510900f368f885a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-07-27T18:34:02.000Z", "max_stars_repo_stars_event_max_datetime": "2015-07-27T18:34:02.000Z", "max_issues_repo_path": "TeX_files/LogicBinary.tex", "max_issues_repo_name": "kcdodd/ecsp-book", "max_issues_repo_head_hexsha": "371e0e07140bc2fa5a8e3d424510900f368f885a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TeX_files/LogicBinary.tex", "max_forks_repo_name": "kcdodd/ecsp-book", "max_forks_repo_head_hexsha": "371e0e07140bc2fa5a8e3d424510900f368f885a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.4301075269, "max_line_length": 464, "alphanum_fraction": 0.7205358526, "num_tokens": 3800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7076947400753366}}
{"text": "\\documentclass[oneside]{book}\r\n\\usepackage[utf8]{inputenc}\r\n\\usepackage{authblk}\r\n\\usepackage{setspace} \r\n\\usepackage{amsmath}\r\n\\usepackage{textcomp}\r\n\\usepackage{amssymb}\r\n\\usepackage{geometry}\r\n\\usepackage{amsthm}\r\n\\usepackage{runic}\r\n\\usepackage{mathtools}\r\n\\usepackage{graphicx}\r\n\\usepackage{mathrsfs}\r\n\\usepackage[breaklinks=true,a4paper=true,pagebackref=true]{hyperref}\r\n\\graphicspath{ {figures/} }\r\n\\geometry{\r\n a4paper,\r\n total={170mm,257mm},\r\n left=20mm,\r\n top=20mm,\r\n}\r\n\\hypersetup{\r\n    colorlinks=true,\r\n    linktoc=true,\r\n    linkcolor=blue,\r\n}\r\n\\title{Libraria Calculosis}\r\n\\author{Liam Gardner}\r\n\\date{\\today}\r\n%\\doublespacing\r\n\\newcommand\\tab[1][1cm]{\\hspace*{#1}}\r\n\\newcommand\\nextline{\\newline\\tab}\r\n\\newcommand\\nextquestion{\\newline\\newline}\r\n\\newcommand\\soln{$\\text{sol}^\\text{n}\\text{ }$}\r\n\\newcommand\\fs{\\mbox{\\large $\\mathrlap{f}s\\,$}\\,}\r\n\\newcommand\\thm[2]{\\section*{Theorem: #1}\\label{sec:#2}\\addcontentsline{toc}{section}{Theorem: #1}}\r\n\\newcommand\\propn[2]{\\section*{Proposition: #1}\\label{sec:#2}\\addcontentsline{toc}{section}{Proposition: #1}}\r\n\\newcommand\\ddx[1]{\\frac{\\text{d}}{\\text{dx}}\\left[#1\\right]}\r\n\\newcommand\\dydx{\\frac{\\text{dy}}{\\text{dx}}}\r\n\\newcommand{\\Lim}[1]{\\raisebox{0.5ex}{\\scalebox{0.8}{$\\displaystyle \\lim_{#1}\\;$}}}\r\n\\newcommand{\\dfdx}{\\frac{\\text{df}}{\\text{dx}}}\r\n\\newcommand \\interval[1]{\\,^a_b\\mathcal{I}_{#1}}\r\n\\begin{document}\r\n\\DeclarePairedDelimiter\\abs{\\lvert}{\\rvert}\r\n\r\n\\maketitle\r\n\\tableofcontents\r\n\\chapter{Approximating $\\sqrt{95}$ Using Newton's Method}\r\n\\tab\r\nLet $f(x)=x^2-95$, then $f^\\prime(x) = 2x$. Newton's Update Function then produces\r\n$$x-\\frac{f(x)}{f^\\prime(x)}$$\r\n$$=x\\frac{x^2-95}{2x}$$\r\n$$=\\frac{2x^2}{2x} - \\frac{x^2-95}{2x}$$\r\n$$=\\frac{x^2+95}{2x}$$\r\n\\tab\r\nThus, we can define a recursive sequence $x_{n+1} = \\frac{x_n^2 + 95}{2x_n}$. Using a starting point of $x_0=10$, since $\\sqrt{95}$ is close to $\\sqrt{100}=10$. we get the following\r\n\\nextline\r\n\\begin{center}\r\n\\begin{tabular}{|c|c|}\r\n\\hline\r\n$x_0$ & 10 \\\\\r\n$x_1$ & 9.75 \\\\\r\n$x_2$ & 9.764764 \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\tab\r\nNotice that even for $x_2$, we get an approximation correct to 6 digits.\r\n\\subsection{If Newton's method converges, does it always converge to a root?}\r\n\\tab\r\nAnother way of phrasing this is if $\\{x_n\\}\\rightarrow L$, is $f(L)=0$?.\r\n\\nextline\r\nSince the sequence is convergent, we can replace $x_{n+1}$ and $x_n$ with L, and solve $L=L-\\frac{f(L)}{f^\\prime(L)}$ which implies that $f(L)=0$. Therefore, if Newton's Method converges, we're guaranteed that it converges to a root.\t\r\n\\chapter{Derivatives of Inverse Functions}\r\n\\tab\r\nWe still haven't seen $\\ddx{\\ln(x)}$. Our goal is to relate the derivative of a function with the derivative of its inverse.\r\nGiven a function $f(x)$, we can define the linearization at a point $a$ as $\\mathcal{L}_a^{f}$. Then, if we invert the linearization function, we get $\\left(\\mathcal{L}_a^{f}\\right)^{-1} = a+\\frac{1}{f^\\prime(a)}(x-f(a))$. If we take a point $f(a)=b$, then we get that $a= f^{-1}(b)$. Thus $\\left(\\mathcal{L}_a^f\\right)^{-1} = f^{-1}(b) + \\frac{x-b}{f^\\prime\\left(f^{-1}(b)\\right)}$. Therefore, we know that the inverse linearization of $f(x)$ at a point $x=a$, is the same as $\\mathcal{L}_b^{f^{-1}}$. That is to say, the inverse linearization of a function at a point $a$ is the same as the linearization of the inverse function at a point $f(a)$. Thus, $\\mathcal{L}_b^{f^{-1}} = f^{-1}(b) + \\ddx{f^{-1}}\\lvert_{x=b} \\cdot (x-b)$. Thus, by equality we know that $\\ddx{f^{-1}}\\lvert_{x=b} = \\frac{1}{f^\\prime(f^{-1}(b))}$\r\n\\thm{Inverse Function Theorem}{ift}\r\n\\tab\r\nIf $f$ is an invertible function on $[c,d]$, differentiable on $(c,d)$, and that $f^\\prime(a)\\neq0$, then $f^{-1}$ is differentiable at $x=f(a)$ with the derivative $\\ddx{f^{-1}}\\lvert_{x=b} = \\frac{1}{f^\\prime(f^{-1}(b))}$. Along with that $\\left(\\mathcal{L}_a^f\\right)^{-1} = \\mathcal{L}_{f(a)}^{f^{-1}}$\r\n\\subsection{Proof sketch}\r\n\\tab\r\nIf $f$ is an invertible function, then $f(f^{-1}(x)) = x$. Thus, since they're equal $\\ddx{f(f^{-1}(x))} = \\ddx{x}$\r\n$$\\ddx{f(f^{-1}(x))} = f^\\prime(f^{-1}(x))\\cdot \\ddx{f^{-1}(x)} = 1$$\r\n$$\\ddx{f^{-1}(x)} = \\frac{1}{f^\\prime(f^{-1}(x))}$$\r\n\\newline\r\n\\null\\hfill$\\mathcal{QED}$\r\n\\subsection{Testing Inverse Function Theorem}\r\n\\tab Let $f(x)=x^5$, then $f^{-1}(x)=\\sqrt[5]{x}=x^{\\frac{1}{5}}$. Thus, we know that $\\ddx{f^{-1}(x)} = \\frac{1}{5}x^{-4}{5} = \\frac{1}{5\\cdot\\sqrt[5]{x^4}}$.\r\n\\nextline\r\nUsing IFT, we get that the derivative is $\\frac{1}{f^\\prime(f^{-1}(x))} = \\frac{1}{5(f^{-1}(x))^4}  = \\frac{1}{5(x)^\\frac{4}{5}}$\r\n\\subsection{Derivative of $\\ln(x)$}\r\nUsing IFT, we can now calculate the derivative of $\\ln(x)$.\r\n$$\\ddx{\\ln(x)} = \\frac{1}{f^\\prime(f^{-1}(x))} = \\frac{1}{e^{\\ln(x)}} = \\frac{1}{x}$$\r\n\\nextline\r\nFurthermore, we can generalize this to know that $\\ddx{\\log_a(x)} = \\frac{1}{x\\ln(a)}$\r\n\\subsection{Derivative of Inverse Trig Functions}\r\n\\tab\r\nWe know that $\\ddx{\\sin(x)} = \\cos(x)$. \r\n$$\\ddx{\\arcsin{x}}=\\frac{1}{\\cos(\\arcsin(x))}$$\r\nLet $\\theta=\\arcsin(x)$, then $\\sin(\\theta)=x$. Using a triangle with a hypotenuse of $1$ and an opposite side to $\\theta$ of $x$. Then by the pythagorean theorem, we know the final side $a$ can be found as $a=\\sqrt{1-x^2}$. Thus, $\\cos(\\arcsin(x)) = \\cos(\\theta) = \\sqrt{1-x^2}$\r\n\\nextline\r\nTherefore, the derivative of the $\\arcsin(x)$ function is $\\frac{1}{\\sqrt{1-x^2}}$. Similarly, $\\ddx{\\arccos(x)} = \\frac{-1}{\\sqrt{1-x^2}}$ and $\\ddx{\\arctan(x)}=\\frac{1}{x^2+1}$.\r\n\\chapter{Implicit Differentiation}\r\n\\tab\r\nWe understand how to take the derivative of explicitly defined functions, as in $y=f(x)$. However, there are ways to differentiate implicitly defined functions, such as $x^2+y^2=1$. That expression implicitly defines two functions. An implicit function is an equation where $y$ is a function of $x$, thus we can (poorly) rewrite the equation for the unit circle as $x^2+f(x)^2 = 1$.\r\n\\nextline\r\nTo take the derivative of an implicit function, we take the derivative of both sides\r\n$$\\ddx{x^2+y^2=1}$$\r\n$$\\implies \\ddx{x^2+y^2} = \\ddx{1}$$\r\n$$\\implies \\ddx{x^2}+\\ddx{y^2} = 0$$\r\n$$\\implies 2x + 2y\\dydx = 0$$\r\n$$\\implies \\dydx=\\frac{-x}{y}$$\r\n\\tab\r\nOften with implicitly defined functions, the result of differentiation will also be implicit.\r\n\\nextline\r\nIf we wanted to know the slope(s) of the unit circle when $x=\\frac{1}{2}$, we can that the two points we get are\r\n$$\\left(\\frac{1}{2}\\right)^2 + y^2 = 1$$\r\n$$\\implies y^2 = \\frac{3}{4}$$\r\n$$\\implies y=\\sqrt{\\frac{3}{4}}=\\frac{\\pm\\sqrt{3}}{2}$$\r\n\\tab\r\nFrom this, we can use the implicit derivative on both points to get\r\n$$\\dydx=\\frac{\\frac{1}{2}}{\\frac{\\sqrt{3}}{2}} = \\frac{-1}{\\sqrt{3}}$$\r\n$$\\dydx=\\frac{\\frac{1}{2}}{\\frac{-\\sqrt{3}}{2}} = \\frac{1}{\\sqrt{3}}$$\r\n\\tab\r\nThus, we see that the two slopes of the unit circle at $x=\\frac{1}{2}$ are $\\frac{\\pm1}{\\sqrt{3}}$.\r\n\\newline\r\n\\begin{figure}[h]\r\n\\centering\r\n\\includegraphics[width=0.35\\textwidth]{l24f0}\r\n\\caption{Slopes of the unit circle at $x=\\frac{1}{2}$}\r\n\\end{figure}\r\n\\newpage\r\nTrying this again using $x^2+y^2=-1$, we see that the implicit derivative is the same as $x^2+y^2=1$, however, the derivative doesn't actually make sense, as the sum of two squares is always nonnegative. Thus, $x^2+y^2=-1$ does not define a function in $\\mathbb{R}^2$, as there are no pairs of real numbers $(x,y)$ that satisfy $x^2+y^2=-1$.\r\n\\nextline\r\nSimilarly, the relation $2x=x$ defines a point rather than a function, and thus differentiating doesn't yield anything reasonable, as the result is $2=1$. \r\n\\section{Example}\r\n\\tab\r\nFind $\\dydx$ if $x^3y^5+3x=8y^3+1$\r\n$$\\ddx{x^3y^5+3x=8y^3+1}$$\r\n$$\\implies \\ddx{x^3y^5+3x} = 24y^2\\dydx$$\r\n$$\\implies \\ddx{x^3y^5} + 3 = 24y^2\\dydx$$\r\n$$\\implies 3x^2y^5 + 5y^4x^3\\dydx + 3 = 24y^2\\dydx$$\r\n$$\\implies \\dydx\\left(5x^3y^4-24y^2\\right)=-3x^2y^5-3$$\r\n$$\\implies \\dydx=\\frac{-3x^2y^5-3}{5x^3y^4-24y^2}$$\r\n\\chapter{Logarithmic Differentiation}\r\n\\tab\r\nLogarithmic Differentiation is a trick in which you take the natural logarithm of both sides before implicit differentiation.\r\n\\nextline\r\nDifferentiation with a logarithm gives means of dealing with things like $y=f(x)^{g(x)}$. Along with that, since $\\ln(ab)=\\ln(a)+\\ln(b)$, using logarithmic differentiation allows us to skip using the product rule.\r\n\\subsection{Example 1}\r\nFind $\\dydx$ for $y=x^x$\r\n\\nextline\r\n$$y=x^x$$\r\n$$\\implies \\ln(y)=\\ln(x^x)$$\r\n$$\\implies \\ln(y)=x\\ln(x)$$\r\n$$\\implies \\ddx{\\ln(y)=x\\ln(x)}$$\r\n$$\\implies \\ddx{\\ln(y)}=\\ddx{x\\ln(x)}$$\r\n$$\\implies \\frac{1}{y}\\dydx = \\ln(x)+1$$\r\n$$\\implies \\dydx=y\\left(\\ln(x)+1\\right)$$\r\n\\tab\r\nSince the original function was defined explicitly, the derivative should be explicitly defined as well, thus we substitute $y=x^x$ to get\r\n$$\\dydx=x^x\\left(\\ln(x)+1\\right)$$\r\n\\subsection{Example 2}\r\nFind $\\dydx$ for $y=\\frac{\\sin(x)e^xx^3}{\\ln(x)}$\r\n$$y=\\frac{sin(x)e^xx^3}{\\ln(x)}$$\r\n$$\\ln(y)=\\ln\\left(\\frac{\\sin(x)e^xx^3}{\\ln(x)}\\right)$$\r\n$$\\implies \\ln(y)=\\ln(\\sin(x))+\\ln(e^x)+\\ln(x^3)-\\ln(\\ln(x))$$\r\n$$\\implies \\ln(y)=\\ln(\\sin(x))+3\\ln(x)-\\ln(\\ln(x)) + x$$\r\n$$\\implies \\ddx{\\ln(y)=\\ln(\\sin(x))+3\\ln(x)-\\ln(\\ln(x)) + x}$$\r\n$$\\implies \\frac{1}{y}\\dydx = \\frac{\\cos(x)}{\\sin(x)} + \\frac{3}{x} + 1 - \\frac{1}{x\\ln(x)}$$\r\n$$\\implies \\dydx=y\\left(\\frac{\\cos(x)}{\\sin(x)} + \\frac{3}{x} + 1 - \\frac{1}{x\\ln(x)}\\right)$$\r\n\\chapter{Extrema}\r\n$\\mathbf{\\text{def}^{\\text{n}}}$: A point $c$ is a local maximum of a function $f$ if there exists an open interval $\\mathcal{I}$ containing the point $c$ such that $f(x)\\leq f(c) \\forall x \\in \\mathcal{I}$. Similarly, $c$ is a local minimum if $f(x)\\geq f(c) \\forall x\\in\\mathcal{I}$. If $f:\\mathbb{R}\\rightarrow\\mathcal{I}$ then $c$ is a global extrema. Thus, all global extrema are also local extrema. It is also true that many local extrema can exist \r\n\\begin{figure}[h]\r\n\\centering\r\n\\includegraphics[width=0.5\\textwidth]{l25f0}\r\n\\caption{Examples of local and global extrema}\r\n\\end{figure}\r\n\r\n\\thm{Local Extrema Theorem}{LET}\r\n\\tab\r\nIf $c$ is a local extrema and $f^\\prime(c)$ exists, then we know $f^\\prime(c)=0$.\r\n\\subsection{proof}\r\n\\tab\r\nNotice that if $c$ is a local min of $f$, we can define a new function $g(x)=-f(x)$ and thus $c$ is a local max of $g$. Now, suppose WLOG suppose $c$ is a local max of $f$. Therefore, there exists an open interval $\\mathcal{I}=(a,b)$ containing $c$, such that $f(x)\\leq f(c)\\forall x\\in\\mathcal{I}$. Furthermore, suppose that $f^\\prime(c)$ exists. Therefore, the following is true:\r\n$$f(c)=\\lim_{h\\rightarrow0^+}\\frac{f(c+h)-f(c)}{h}=\\lim_{h\\rightarrow0^-}\\frac{f(c+h)-f(c)}{h}$$\r\n\\tab\r\nIf $h>0$ but is small enough that $a<c+h<b$ then we know that $f(c+h)\\leq f(c)$ because $c$ is a max of $f$ in the interval $\\mathcal{I}$. Therefore, we get that$\\frac{f(c+h)-f(x)}{h}\\leq 0$ and thus $f^\\prime(c)\\leq0$\r\n\\nextline\r\nIf $h<0$ but small ehough that $a<c+h<b$ then we know that $\\frac{f(c+h)-f(c)}{h}\\geq 0$ since division by a negative flips the inequality sign. Therefore, we get that $f^\\prime(c)\\geq0$\\nextline\r\nTherefore, since $f^\\prime(c)\\leq0$ and $f^\\prime(c)\\geq0$ we get that $f^\\prime(c)=0$\r\n\\newline\r\n\\null\\hfill$\\mathcal{QED}$\r\n\\subsection{Converse}\r\n\\tab Consider $f(x)=x^3$. Notice now that $f^\\prime(x)=3x^2$ and thus $f^\\prime(0)=0$, and $f(0)$ isn't a local extrema. Therefore, the converse isn't true. If we also look at $f(x)=\\abs{x}$, we know that $f(0)$ is a global min, however the derivative at $x=0$ doesn't exist, and thus the theorem doesn't apply.\r\n\\section{Finding Global Extrema}\r\n$\\mathbf{\\text{def}^{\\text{n}}}$: A point $c$ is a critical point of $f^\\prime(c)=0$ or $f^\\prime(c)$ doesn't exist.\\nextline\r\nLet's say that all max/mins occur at critical points. Combining this with the extreme value theorem gives us an algorithm for finding extrema. \\nextline\r\nConsider a differentiable function $f$ on the closed interval $[a,b]$. To find all global extrema, we do the following:\r\n\\begin{enumerate}\r\n\\item find all critical points of $f$ on $[a,b]$, let $\\mathcal{C}$ be the set of all $x$-values of critical points.\r\n\\item Evaluate $f(a)$, $f(b)$ and $f(c) \\forall c\\in\\mathcal{C}$.\r\n\\item Choose the biggest and smallest values of $f(a)$, $f(b)$ and $f(c) \\forall c\\in\\mathcal{C}$ \\\\\r\nThe biggest is the global max, and the smallest is the global min.\r\n\\end{enumerate}\r\n\\subsection{Example}\r\nFind the max/min of $f(x)=e^{x^3-2x^2-7x}$ on $[0,4]$\r\n\\nextline\r\nFinding critical points: We know that $\\dfdx$ is defined everywhere, and thus there will be no places on the interval where the derivative is undefined.\r\n\\nextline\r\nBy the chain rule we know $\\dfdx=e^{x^3-2x^2-7x}(3x^2-4x-7)$. Since $e^{p(x)}$ will never be zero, we know that $\\dfdx$ will be zero only when the quadratic term is 0. Since the quadratic factors to $(x+1)(3x-7)$, and since we know that $-1\\not\\in[0,4]$, we know that the only critical point will be $\\frac{7}{3}$.\r\n\\nextline\r\n$\\left\\{f(0), f(4), f\\left(\\frac{7}{3}\\right) \\right\\} = \\left\\{1, e^4, e^\\frac{-392}{27} \\right\\}$\r\n\\nextline\r\nFrom here, we can see that the global max and min are given by the points $(4,e^4)$, $\\left(\\frac{7}{3}, e^\\frac{-392}{27}\\right)$. Therefore, the global max is $4$ and the global min is $\\frac{7}{3}$.\t\r\n\\nextline\r\nThis topic will be revisited upon the genesis of the curve sketching unit.\r\n\\chapter{The Mean Value Theorem}\r\n\\thm{Rolle's Theorem}{RT}\r\n\\tab\r\nIf $f$ is a continuous function on $[a,b]$ and differentiable on $(a,b)$, and if $0=f(a)=f(b)$, then $\\exists c\\in (a,b)$ such that $f^\\prime(c)=0$.\r\n\\subsection{Proof}\r\n\\tab\r\nSuppose that $f$ is continuous on $[a,b]$ and differentiable on $(a,b)$ with $f(a)=f(b)=0$.\r\n\\subsection*{Case 1}\r\n\\tab $\\exists x_0\\in(a_b)$ with $f(x_0)>0$. The Extreme Value Theorem, shows that $f(x)$ achieves a max value on $[a,b]$. We know that the maximum point $c\\in (a,b)$  is thus not at the endpoints. Hence, since $f^\\prime(c)$ exists, by the \\hyperref[sec:LET]{Local Extrema Theorem} we know that $f^\\prime(c)=0$.\r\n\\subsection*{Case 2}\r\n\\tab $\\exists x_0\\in(a,b)$ with $f(x_0)<0$. The Extreme Value Theorem shows that $f(x)$ achieves a min value on $[a,b]$. We know that the minimum point $c\\in(a,b)$ is thus not at the endpoints. Hence, since $f^\\prime(c)$ exists, by the \\hyperref[sec:LET]{Local Extrema Theorem} we know that $f^\\prime(c)=0$.\r\n\\subsection*{Case 3}\r\n\\tab $f:[a,b]\\rightarrow 0$, hence $f^\\prime:(a,b)\\rightarrow 0$ and thus there are lots of choices for $c$.\r\n\\thm{The Mean Value Theorem}{MVT}\r\n\\tab\r\nSuppose $f$ is continuous on $[a,b]$ and differentiable on $(a,b)$. Then, $\\exists c\\in(a,b)$ such that $f^\\prime(c)=\\frac{f(b)-f(a)}{b-a}$. Rolle's Theorem is a special case of Mean Value Theorem.\r\n\\subsection{Proof}\r\n\\tab Let $h(x)=f(x)-f(a)-\\left(\\frac{f(b)-f(a)}{b-a}\\right)(x-a)$. Notice that $h(a)=h(b)=0$. Since $h$ is continuous on $[a,b]$ and differentiable on $(a,b)$. Thus, since the conditions of Rolle's Theorem are met, we know that $\\exists c\\in(a,b)$ such that $h^\\prime(c)=0$.\\nextline\r\n$$\\ddx{h^\\prime(x)}\\lvert_{x=c}=f^\\prime(c)-\\frac{f(b)-f(a)}{b-a}=0$$\r\n\\tab\r\nTherefore, we get that $f^\\prime(c)=\\frac{f(b)-f(a)}{b-a}$.\r\n\\subsection{Examples}\r\n\\tab\\textit{Find all points $c$ that satisfy the mean value theorem for} $f(x)=x^3+2x^2-x$ on $[-1,2]$\\nextline\r\nBy MVT we know that $f^\\prime(c)=\\frac{f(2)-f(-1)}{2-(-1)} = \\frac{14-2}{3} = 4$. Therefore, there is a point $c$ where the derivative is equal to 4. $f^\\prime(x)=3x^2+4x-1$\r\n$$f^\\prime(x)=3x^2+4x-1=c$$\r\n$$x=\\frac{-4\\pm\\sqrt{76}}{6}$$\r\n\\tab Since $\\frac{-4-\\sqrt{76}}{6}\\not\\in [-1,2]$, we know that it is not a proper value of $c$. Therefore, the only value of $c$ for this interval is $c=\\frac{\\sqrt{76}-4}{6}$\r\n\\newline\r\n\\nextline\r\n\\textit{Suppose that a function $f$ is continuous and differentiable everywhere. Furthermore, suppose $f$ has two roots. Then show $f^\\prime$ has at least one root}\r\n\\nextline\r\nLet $a,b$ be distinct roots of $f$, then $f(a)=f(b)=0$. Thus, by Rolle's Theorem, we know that $\\exists c\\in(a,b)$ such that $f^\\prime(c)=\\frac{f(b)-f(a)}{b-a}=0$ and thus there is at least one root of $f^\\prime$.\r\n\\section{Applications of MVT}\r\n\\tab\r\n$\\text{Def}^{\\text{n}}$: A function $F$ is called an antiderivative of $f$ is $F^\\prime(x)=f(x) \\forall x\\in\\mathbb{R}$\r\n\\nextline\r\n$F(x)=\\frac{x^2}{2}$ is an antiderivative of $f(x)$, since $F^\\prime(x)=\\frac{2x}{2}=x=f(x)$\r\n\r\n\\thm{The Constant Function Theorem}{CFT}\r\n\\tab\r\nIf $f^\\prime(x)=0$ $\\forall x\\in\\mathcal{I}$ then $f(x)=c$ $\\forall x\\in\\mathcal{I}$.\r\n\\subsection{Proof}\r\n\\tab\r\nLet $\\mathcal{I}$ be some interval, then suppose $f^\\prime(x)=0$ $\\forall x\\in\\mathcal{I}$. Note that $f$ is continuous on $\\mathcal{I}$. Let $x_1, x_2\\in \\mathcal{I}$ where $x_1\\neq x_2$. Then, let $f(x_1)=k$. By the Mean Value Theorem, $\\exists c\\in(x_1,x_2)$ such that $f^\\prime(c)=\\frac{f(x_2)-f(x_1)}{x_2-x_1}$. Since $(x_1,x_2)\\subseteq \\mathcal{I}$, we know that $f^\\prime(c)=0$ and thus $\\frac{f(x_2)-f(x_1)}{x_2-x_1}=0\\implies f(x_2)-f(x_1)=0\\implies f(x_2)=f(x_1)=k$.\r\n\\nextline\r\nSince both $x_1$ and $x_2$ were arbitrary, we conclude that $f(x)=k$ $\\forall x\\in\\mathcal{I}$\r\n\\thm{Uniqueness of Antiderivatives}{UA}\r\n\\tab\r\nAntiderivatives are not unique, since if we take $F(x)=h(x)+c$ and $f(x)=h^\\prime(x)$ then $F^\\prime(x)=h^\\prime(x)=f(x) \\forall c\\in\\mathbb{R}$. However, outside of adding constants, antiderivatives are unique (although it is not straightforward). This can be shown using the Mean Value Theorem.\r\n\\nextline\r\nIf $f^\\prime(x)=g^\\prime(x)$ $\\forall x\\in\\mathcal{I}$, and thus $f(x)$ and $g(x)$ are antiderivatives of the same function, then $\\exists k\\in\\mathbb{R}$ such that $f(x)=g(x)+k$ $\\forall x\\in\\mathcal{I}$.\r\n\\subsection{Proof}\r\nLet $h(x)=f(x)-g(x)$ and thus $h^\\prime(x)=f^\\prime(x)-g^\\prime(x)=0$ $\\forall x\\in\\mathcal{I}$. Hence, by \\hyperref[sec:CFT]{The Constant Function Theorem}, $\\exists k\\in\\mathbb{R}$ such that $h(x)=k$ $\\forall x\\in\\mathcal{I}$. Therefore, $h(x)=f(x)-g(x)=k$ $\\forall k\\in\\mathcal{I}\\implies f(x)=g(x)+k$ $\\forall x\\in\\mathcal{I}$.\r\n\\subsection{Notation}\r\nThe family of antiderivatives for a function $f(x)$ is denoted as follows, where $f(x)$ is referred to as the ``integrand'' and the dx is referred to as the ``variable of integration''.\r\n$$F(x)=\\int f(x)\\text{ dx}$$\r\n\\tab As an example, $\\int x^2\\text{ dx} = \\frac{x^2}{2}$\r\n\\thm{Increasing/Decreasing Function Theorem}{IncFT}\r\n\\tab\r\nLet $\\mathcal{I}$ be some interval with $x_1,x_2\\in\\mathcal{I}$ where $x_1< x_2$.\r\n\\begin{enumerate}\r\n\\item If $f^\\prime(x)>0 \\,\\forall x\\in\\mathcal{I}$ then, $f(x_2)>f(x_1)$ and we say $f$ is \\textit{increasing} on $\\mathcal{I}$\r\n\\item If $f^\\prime(x)\\geq0 \\,\\forall x\\in\\mathcal{I}$ then, $f(x_2)\\geq f(x_1)$ and we say $f$ is \\textit{non-decreasing} on $\\mathcal{I}$\r\n\\item If $f^\\prime(x)<0 \\,\\forall x\\in\\mathcal{I}$ then, $f(x_2)<f(x_1)$ then we say $f$ is \\textit{decreasing} on $\\mathcal{I}$\r\n\\item If $f^\\prime(x)\\leq0 \\,\\forall x\\in\\mathcal{I}$ then, $f(x_2)\\leq f(x_1)$ and we say $f$ is \\textit{non-increasing} on $\\mathcal{I}$\r\n\\end{enumerate}\r\n\\subsection{Proof of (1)}\r\n\\tab\r\nLet $\\mathcal{I}$ be an interval such that $x_1<x_2 \\in\\mathcal{I}$. Suppose that $f^\\prime(x)>0\\,\\forall x\\in\\mathcal{I}$. Since $f^\\prime$ exists, we know that $f$ is continuous $\\forall x\\in\\mathcal{I}$. We can thus apply \\hyperref[sec:MVT]{The Mean Value Theorem} to $[x_1, x_2]$.\\nextline\r\n$\\exists c\\in(x_1,x_2)$ such that $\\frac{f(x_2)-f(x_1)}{x_2-x_1} = f^\\prime(c)$. Since we know $f^\\prime(c)>0$ and $x_2-x_1>0$, we know that $f(x_2)-f(x_1)>0$. Thus, $f$ is increasing over $\\mathcal{I}$.\r\n\\subsection{Converses}\r\n\\tab\r\nThe converse of (2) and (4) are true (if $f(x)$ is non-increasing/non-decreasing on $\\mathcal{I}$ then $f^\\prime(x) >0 \\,\\forall x\\in\\mathcal{I}$).\r\n\\nextline\r\nThe converse of (1) and (3) are false. Consider $f(x)=x^3$. Where $f(x_2)>f(x_1) \\forall x_2>x_1$ However, $f^\\prime(0)=0$.\r\n\\section{Functions with Bounded Derivatives}\r\nWhat information can we derive from a function $f$ if we know the bounds of $\\dfdx$?\r\n\\nextline\r\nSuppose $m\\leq \\dfdx \\leq M$ $\\forall x\\in(a,b)$. If $f$ is continuous on $[a,b]$ then we can use \\hyperref[sec:MVT]{Mean Value Theorem}.\r\n\\nextline\r\nLet $x\\in(a,b)$. Applying MVT we get $\\exists c\\in(a,x)$ with $f^\\prime(c) = \\frac{f(x)-f(a)}{x-a}$.\r\n$$m \\leq f^\\prime(c) =\\frac{f(x)-f(a)}{x-a} \\leq M$$\r\n$$m(x-a) \\leq f(x)-f(a) \\leq M(x-a)$$\r\n$$f(a) + m(x-a) \\leq f(x) \\leq f(a) + M(x-a)$$\r\n\\tab\r\nThis implies that $f(x)$ is bounded between two lines.\r\n\\thm{Bounded Derivative Theorem}{BDT}\r\n\\tab\r\nIf a function $f$ is continuous on $\\interval{o}$ and differentiable on $\\interval{c}$ with $m\\leq f^\\prime(x)\\leq M$ $\\forall x\\in\\interval{o}$ then $f(a)+m(x-a)\\leq f(x)\\leq f(a)+M(x-a)$ $\\forall x \\in\\interval{c}$.\r\n\\subsection{Example}\r\nShow that $\\ln(3)\\in\\left[\\frac{7-e}{4}, \\frac{3}{e}\\right]$\\nextline\r\nLet $f(x)=\\ln(x)$. Hence, $f^\\prime(x)=\\frac{1}{x}$. We need to bound $f^\\prime(x)$ to use the theorem. Thus, we need some interval $\\interval{c}$ with $a<3<b$. We also need $f(a)$ to be easily computable. If we take $a=e$ then $\\ln(a)=1$. and $1<3$. Since we don't need $f(b)$ to be easily computable, we can take $b=4$.\r\n\\nextline\r\nNote that $\\ddx{\\frac{1}{x}} = \\frac{-1}{x^2}$. Thus, from the \\hyperref[sec:IncFT]{Increasing Function Theorem} we know that $f^\\prime(x)$ is decreasing. Thus, $f^\\prime(4) \\leq f^\\prime(x) \\leq f^\\prime(e)$. Since the derivative can be bound between $\\frac{1}{4}$ and $\\frac{1}{e}$, the natural choice for a range would be $f^\\prime(x)\\in\\left[\\frac{1}{4}, \\frac{1}{e}\\right]$.\r\n\\nextline\r\n$$f(a) + m(x-a) \\leq f(x) \\leq f(a)+M(x-a)$$\r\n$$1 + \\frac{1}{4}(x-e) \\leq f(x) \\leq f(a)+\\frac{1}{e}(x-a)$$\r\n$$1 + \\frac{1}{4}(3-e) \\leq f(x) \\leq 1 + \\frac{1}{e}(x-e)$$\r\n$$\\frac{7-e}{4} \\leq f(x) \\leq \\frac{3}{e}$$\r\n\\newline\r\n\\null\\hfill$\\mathcal{QED}$\r\n\\nextline\r\nCheck out the example in the textbook that uses Bounded Derivative Theorem to show the following;\r\n$$\\lim_{n\\rightarrow\\infty} \\left(1+\\frac{1}{n}\\right)^n = e$$\r\n\\section{Comparing Functions Using Derivatives}\r\nSuppose $f$ and $g$ are continuous at $x=a$ and $f(a)=g(a)$\r\n\\begin{enumerate}\r\n\\item If $f^\\prime(x) < g^\\prime(x)$ $\\forall x>a$ then $f(x)<g(x)$ $\\forall x>a$\r\n\\item If $f^\\prime(x) > g^\\prime(x)$ $\\forall x>a$ then $f(x)>g(x)$ $\\forall x>a$\r\n\\item If $f^\\prime(x) \\leq g^\\prime(x)$ $\\forall x>a$ then $f(x)\\leq g(x)$ $\\forall x>a$\r\n\\item If $f^\\prime(x) \\geq g^\\prime(x)$ $\\forall x>a$ then $f(x)\\geq g(x)$ $\\forall x>a$\r\n\\end{enumerate}\r\n\\subsection{Proof of (3)}\r\n\\tab\r\nSuppose $f$ and $g$ are continuous at $x=a$ with $f(a)=g(a)$ and $f^\\prime(x) \\leq g^\\prime(x)$ $\\forall x>a$.\r\n\\nextline\r\nLet $h(x)=f(x)-g(x)$. Then $h(a)=f(a)-g(a)=0$. Let $x>a$, $h^\\prime(x)=f^\\prime(x)-g^\\prime(x)$. By the hypothesis, we know that when $x>a$ that $f^\\prime(x)\\leq g^\\prime(x)$, thus, by the \\hyperref[sec:IncFT]{Decreasing Function Theorem}. Hence, $h(x)\\leq 0\\implies f(x)-g(x)\\leq 0\\implies f(x)\\leq g(x)$ $\\forall x>a$.\r\n\\end{document}", "meta": {"hexsha": "b566c6e3bf15028ccea2fe39733fd4d7363458c0", "size": 22896, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Libraria Calculosis/Libraria Calculosis.tex", "max_stars_repo_name": "GardnerLiam/Libraria-Mathematica", "max_stars_repo_head_hexsha": "bfc2b3734230e883e439ea9bfec3b6c4103a01ed", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-23T20:16:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-23T20:16:39.000Z", "max_issues_repo_path": "Libraria Calculosis/Libraria Calculosis.tex", "max_issues_repo_name": "GardnerLiam/Libraria-Mathematica", "max_issues_repo_head_hexsha": "bfc2b3734230e883e439ea9bfec3b6c4103a01ed", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-11-17T06:21:41.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-17T06:21:41.000Z", "max_forks_repo_path": "Libraria Calculosis/Libraria Calculosis.tex", "max_forks_repo_name": "GardnerLiam/Libraria-Mathematica", "max_forks_repo_head_hexsha": "bfc2b3734230e883e439ea9bfec3b6c4103a01ed", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.1428571429, "max_line_length": 823, "alphanum_fraction": 0.6478424179, "num_tokens": 8579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080671950640465, "lm_q2_score": 0.8757869867849167, "lm_q1q2_score": 0.7076947338848808}}
{"text": "\\lab{Introduction to Wavelets}{Intro to Wavelets}\n\n\\objective{Learn the basics of Wavelet Analysis\nand explore the wavelet-based FBI fingerprint compression standard.}\n\nRecall that in the context of Fourier analysis, one seeks to represent a\nfunction as a sum of sinusoids.\nA drawback to this approach is that the\nFourier transform only captures global frequency information, and local\ninformation is lost; we can know which frequencies are the\nmost prevalent, but not when or where they occur.\nThe Wavelet transform provides an alternative approach that avoids this shortcoming\nand is often a superior analysis technique for many types of signals and images.\n\n\\subsection*{The Discrete Wavelet Transform}\nIn wavelet analysis, we seek to analyze a function by considering its \\emph{wavelet decomposition}.\nThe wavelet decomposition of a function is a way of expressing the function as a linear combination\nof a particular family of basis functions.\nIn this way, we can represent a function by the sequence of coefficients (called\n\\emph{wavelet coefficients}) defining this linear combination.\nThe mapping from a function to its sequence of wavelet coefficients is called the \\emph{discrete\nwavelet transform}.\n\nThis situation is entirely analogous to the discrete Fourier transform. Instead of using trigonometric functions\nas our basis, we use a different family\nof basis functions. In Wavelet analysis, we determine the family of basis functions by first starting\noff with a function $\\psi$ called the \\emph{wavelet} and a function $\\phi$ called the \\emph{scaling function}\n(these functions are also called the mother and father wavelets, respectively). We then generate\ncountably many basis functions (sometimes called baby wavelets) from these two functions:\n\\begin{equation*}\n\\psi_{m,k}(x) = \\psi(2^mx - k)\n\\end{equation*}\n\\begin{equation*}\n\\phi_{m,k}(x) = \\phi(2^mx - k),\n\\end{equation*}\nwhere $m,k \\in \\mathbb{Z}$.\nThe historically first, and most basic, wavelet is called the \\emph{Haar Wavelet},\ngiven by\n\\[\n\\psi(x) =\n \\begin{cases}\n  1 & \\text{if } 0 \\leq x < \\frac{1}{2} \\\\\n  -1 & \\text{if } \\frac{1}{2} \\leq x < 1 \\\\\n  0 & \\text{otherwise.}\n \\end{cases}\n\\]\n% It might be nice to plot this function and include the image in the lab.\nThe associated scaling function is given by\n\\[\n\\phi(x) =\n \\begin{cases}\n 1 & \\text{if } 0 \\leq x < 1 \\\\\n 0 & \\text{otherwise.}\n \\end{cases}\n\\]\n\nIn the case of finitely-sampled signals and images, only finitely many wavelet coefficients are nonzero.\nDepending on the application, we are often only interested in the coefficients corresponding to a subset of the basis functions.\nSince a given family of wavelets forms an orthogonal set, we can compute the wavelet coefficients\nby taking inner products (i.e. by integrating). This direct approach is not particularly efficient,\nhowever. Just as there are fast algorithms for computing the fourier transform (e.g. the FFT),\nwe can efficiently calculate wavelet coefficients using techniques from signal processing.\nIn particular, we will use an \\emph{iterative filterbank} to compute the transform.\n% mathematical derivation?\n\nLet's launch into an implementation of the one-dimensional discrete wavelet transform.\nThe key operations in the algorithm are the discrete convolution ($*$) and down-sampling ($DS$).\nThe inputs to the algorithm are a one-dimensional array $X$ (the signal that we want to transform), a one-dimensional\narray $L$ (called the \\emph{low-pass filter}), a one-dimensional array $H$ (the \\emph{high-pass filter}), and a positive\ninteger $n$ (controlling to what degree we wish to transform the signal, i.e. how many wavelet coefficients we wish to compute).\nThe low-pass and high-pass filters can be derived from the wavelet and scaling function.\nThe low-pass filter extracts low frequency information, which gives us an approximation of the signal.\nThis approximation highlights the overall (slower-moving) pattern\nwithout paying too much attention to the high frequency details, which to the eye (or ear) may be unhelpful noise.\nHowever, we also need to extract the high-frequency details with the high-pass filter. While they may sometimes be\nnothing more than unhelpful noise, there are applications where they are the most important part of the signal; for example,\ndetails are very important if we are sharpening a blurry image or increasing contrast.\n\nFor the Haar Wavelet, our filters are given by\n\\begin{align*}\nL &= \\begin{bmatrix}\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}}\\end{bmatrix}\\\\\nH &= \\begin{bmatrix}-\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}}\\end{bmatrix}.\n\\end{align*}\nSee Algorithm \\ref{alg:1d_wavelet} and Figure \\ref{fig:filterbank} for the specifications.\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{dwt}{$X, L, H, n$}\n\t\\State $i \\gets 0$\t\t\t\t\t\t\\Comment{Some initialization steps}\n    \\State $A_i \\gets X$\n    \\While{$i < n$}\n        \\State $D_{i+1} \\gets \\,\\,DS(A_i * H)$ \\Comment{High-pass filtering}\n        \\State $A_{i+1} \\gets \\,\\,DS(A_i * L)$ \\Comment{Low-pass filtering}\n        \\State $i \\gets i + 1$\n    \\EndWhile\n    \\State \\pseudoli{return} $A_n,D_n, D_{n-1},\\ldots, D_1$.\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The one-dimensional discrete wavelet transform.}\n\\label{alg:1d_wavelet}\n\\end{algorithm}\n\\begin{figure}[H]\n\\centering\n\\begin{tikzpicture}[auto, node distance=1.5cm, thick, main node/.style={circle, draw}, LoHi/.style={rectangle, draw}, minimum size=.75cm]\n    \\node[draw=none](Aj){A$_j$};\n    \\node[draw=none](j1)[right of=Aj]{};\n    \\node[LoHi](Lo)[above right of=j1]{Lo};\n    \\node[LoHi](Hi)[below right of=j1]{Hi};\n    \\node[main node](1)[right of=Lo]{};\n    \\node[main node](2)[right of=Hi]{};\n    \\node[draw=none](Aj+1)[right of=1]{A$_{j+1}$};\n    \\node[draw=none](Dj+1)[right of=2]{D$_{j+1}$};\n\n\\foreach \\s/\\t in {Aj/j1.center, 1/Aj+1, 2/Dj+1}{\n    \\draw[->] (\\s) -- (\\t);}\n\\foreach \\s/\\t in {j1.center/Lo, j1.center/Hi}{\n    \\draw[](\\s) |- (\\t);}\n\\foreach \\s/\\t in {Lo/1, Hi/2}{\n    \\draw[](\\s) -- (\\t);}\n\\foreach \\s in {1, 2}{\n    \\draw[->, shorten >=.2cm, shorten <=.2cm] (\\s.north) -- (\\s.south);}\n\\end{tikzpicture}\n\n\\vspace{1cm}\n\n\\begin{center}\n\\begin{tikzpicture}\n% Key\n    \\node[draw=none, node distance=2.5cm](K)[below of=Aj]{Key:};\n    \\node[rectangle, draw, minimum size=.5cm, node distance=1cm](rect)[right of=K]{};\n    \\node[draw=none, node distance=1.3cm](conv)[right of=rect]{= convolve};\n    \\node[circle, draw, minimum size=.5cm, node distance=1cm](circ)[below of=rect]{};\n    \\node[draw=none, node distance=1.5cm](conv)[right of=circ]{= downsample};\n    \\draw[->, shorten >=.1cm, shorten <=.1cm] (circ.north) -- (circ.south);\n\\end{tikzpicture}\n\\end{center}\n\\caption{The one-dimensional discrete wavelet transform\nimplemented as a filter bank.}\n\\label{fig:filterbank}\n\\end{figure}\nAt each stage of the algorithm, we filter the signal into an approximation and its details.\nNote that the algorithm returns a sequence of one dimensional arrays\n\\[A_n, D_n, D_{n-1}, \\ldots, D_1.\\]\nIf the input signal $X$ has length $2^m$ for\nsome $m \\geq n$ and we are using the Haar wavelet, then $A_n$ has length $2^{m-n}$, and $D_i$ has length $2^{m-i}$\nfor $i=1,\\ldots,n$. The arrays $D_i$ are outputs of the high-pass filter, and thus represent high-frequency\ndetails.\nHence, these arrays are known as \\emph{details}.\nThe array $A_n$ is computed by recursively passing the signal through the low-pass filter, and hence it\nrepresents the low-frequency structure in the signal.\nIn fact, $A_n$ can be seen as a smoothed approximation of the original signal, and is called the \\emph{approximation}.\n\nAs noted earlier, the key mathematical operations are convolution and down-sampling.\nTo accomplish the convolution, we simply use a function in SciPy.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy.signal import fftconvolve\n>>> # initialize the filters\n>>> L = np.ones(2)/np.sqrt(2)\n>>> H = np.array([-1,1])/np.sqrt(2)\n>>> # initialize a signal X\n>>> X = np.sin(np.linspace(0,2*np.pi,16))\n>>> # convolve X with L\n>>> fftconvolve(X,L)\n[ -1.84945741e-16   2.87606238e-01   8.13088984e-01   1.19798126e+00\n   1.37573169e+00   1.31560561e+00   1.02799937e+00   5.62642704e-01\n   7.87132986e-16  -5.62642704e-01  -1.02799937e+00  -1.31560561e+00\n  -1.37573169e+00  -1.19798126e+00  -8.13088984e-01  -2.87606238e-01\n  -1.84945741e-16]\n\\end{lstlisting}\nThe convolution operation alone gives us redundant information, so we down-sample to keep only what we need.\nIn particular, we will down-sample by a factor\nof two, which means keeping only every other entry:\n\\begin{lstlisting}\n>>> # down-sample an array X\n>>> sampled = X[1::2]\n\\end{lstlisting}\nPutting these two operations together, we can obtain the approximation coefficients in one\nline of code:\n\\begin{lstlisting}\n>>> A = fft.convolve(X,L)[1::2]\n\\end{lstlisting}\nComputing the detail coefficients is done in exactly the same way, replacing $L$ with $H$.\n\\begin{problem}\nWrite a function that calculates the discrete wavelet transform as described above.\nThe output should be a list of one-dimensional NumPy arrays in the\nfollowing form: $[A_n, D_n, \\ldots, D_1]$.\n\nThe main body of your function should be a loop in which you calculate two arrays: the $i$-th approximation\nand detail coefficients. Append the detail coefficients array to your list, and feed the approximation array\nback into the loop. When the loop is finished, append the approximation array. Finally, reverse the order of your list\nto adhere to the required return format.\n\\end{problem}\nTest your function by calculating the Haar wavelet coefficients of a noisy sine signal for $n=4$:\n\\begin{lstlisting}\n>>> domain = np.linspace(0,4*np.pi, 1024)\n>>> noise =  np.random.randn(1024)*.1\n>>> noisysin = np.sin(domain) + noise\n>>> coeffs = dwt(noisysin, L, H, 4)\n\\end{lstlisting}\nPlot your results and verify that they match the plots in Figure \\ref{fig:dwt1D}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width = 0.5\\textwidth]{dwt1D}\n\\caption{A level 4 wavelet decomposition of a signal. The top panel is the original signal,\nthe next panel down is the approximation, and the remaining panels are the detail coefficients.\nNotice how the approximation resembles a smoothed version of the original signal, while the\ndetails capture the high-frequency oscillations and noise.}\n\\label{fig:dwt1D}\n\\end{figure}\n\nWe can now transform a one-dimensional signal into its wavelet coefficients,\nbut the reverse transformation is just as important.\nLuckily, we can reconstruct a signal from the approximation and detail coefficients.\nWe reverse the effects of the filterbank, using slightly modified filters, essentially adding the details back into the\nsignal at each stage until we reach the original.\nThe Haar wavelet filters for the inverse transformation are\n\\begin{align*}\nL &= \\begin{bmatrix}\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}}\\end{bmatrix}\\\\\nH &= \\begin{bmatrix}\\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}}\\end{bmatrix}.\n\\end{align*}\n\nSuppose we have the wavelet coefficients $A_n$ and $D_n$. Consulting Figure \\ref{fig:filterbank},\nwe can recreate $A_{n-1}$ by tracing the schematic backwards: $A_n$ and $D_n$ are first\n\\emph{up-sampled}, then they are convolved with $L$ and $H$, respectively, and finally\nadded together to obtain $A_{n-1}$. Up-sampling means doubling the length of an array\nby inserting a 0 at every other position. In Python, this whole process looks like:\n\\begin{lstlisting}\n>>> # up-sample the coefficient arrays A, D\n>>> up_A = np.zeros(2*A.size)\n>>> up_A[::2] = A\n>>> up_D = np.zeros(2*D.size)\n>>> up_D[::2] = D\n>>> # now convolve and add, but discard last entry\n>>> A = fftconvolve(up_A,L)[:-1] + fftconvolve(up_D,H)[:-1]\n\\end{lstlisting}\nNow that we have $A_{n-1}$, we repeat the process with $A_{n-1}$ and $D_{n-1}$ to obtain\n$A_{n-2}$. Proceed for a total of $n$ steps (one for each $D_n, D_{n-1},\\ldots ,D_1$) until we have obtained $A_0$.\nSince $A_0$ is defined to be the original\nsignal, we have finished the inverse transformation.\n% proof that this works, perhaps in an appendix...\n\\begin{problem}\nWrite a function that calculates the inverse wavelet transform as described above.\nThe inputs should be a list of arrays (of the same form as the output of your discrete\nwavelet transform function), the low-pass filter, and the high-pass filter.\nThe output should be a single array, the recovered signal.\n\nNote that the input list of arrays has length $n+1$ (consisting of $A_n$ together with\n$D_n, D_{n-1}, \\ldots, D_1$), so your code should perform the process given above $n$ times.\n\nIn order to check your work, compute\nthe discrete wavelet transform of a random array for different values of $n$, then compute the inverse\ntransform.\nCompare the original signal with the recovered signal using \\li{np.allclose}.\n\\end{problem}\n\\section*{The PyWavelets Module}\nHaving implemented our own version of the basic 1-dimensional wavelet transform, we now turn to\nPyWavelets, a Python library for Wavelet Analysis.\nIt provides convenient and efficient methods to calculate the one- and two-dimensional discrete Wavelet\ntransform, as well as much more.\nAssuming that the package has been installed on your machine, type the following to get started:\n\\begin{lstlisting}\n>>> import pywt\n\\end{lstlisting}\nPerforming the discrete Wavelet transform is very simple.\nBelow, we compute the one-dimensional transform for a sinusoidal signal.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> f = np.sin(np.linspace(0,8*np.pi, 256)) # build the sine wave\n>>> fw = pywt.wavedec(f, 'haar') # compute the wavelet coefficients of f\n\\end{lstlisting}\nThe variable \\li{fw} is now a list of arrays, starting with the final approximation\nframe, followed by the various levels of detail coefficients, just like the output\nof the wavelet transform function that you already coded.\nPlot the level 2 detail and verify that it resembles a blocky sinusoid.\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n>>> plt.plot(fw[-2], linestyle='steps')\n>>> plt.show()\n\\end{lstlisting}\nTo reconstruct the signal, we simply call the function \\li{waverec}:\n\\begin{lstlisting}\n>>> f_prime = pywt.waverec(fw, 'haar') # reconstruct the signal\n>>> np.allclose(f_prime, f) # compare with the original\nTrue\n\\end{lstlisting}\nThe second positional argument, as you will notice, is a string that gives the name of the wavelet to be used.\nWe first used the Haar wavelet, with which you are already familiar.\nPyWavelets supports a number of different Wavelets, however, which you can list by executing the following code:\n\\begin{lstlisting}\n>>> # list the available Wavelet families\n>>> print pywt.families()\n['haar', 'db', 'sym', 'coif', 'bior', 'rbio', 'dmey']\n>>> # list the available wavelets in the coif family\n>>> print pywt.wavelist('coif')\n['coif1', 'coif2', 'coif3', 'coif4', 'coif5']\n\\end{lstlisting}\nDifferent wavelets have different properties; the most suitable wavelet is dependent on the specific application.\nSee Figure \\ref{fig:more_wavelets} for the plots of a couple of additional wavelets.\n\\begin{figure}[H]\n\\begin{subfigure}[b]{0.45\\textwidth}\n    \\includegraphics[width=\\textwidth]{mexicanHat}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.45\\textwidth}\n    \\includegraphics[width=\\textwidth]{db5_3}\n\\end{subfigure}\n\\caption{Examples of different mother wavelets.}\n\\label{fig:more_wavelets}\n\\end{figure}\n\n\\section*{The 2-dimensional Wavelet Transform}\nWe can generalize the wavelet transform for two dimensions much as we generalized the fourier transform.\nThis allows us to perform wavelet analysis on, for example, digital images.\nIn particular, we can calculate the wavelet transform of a two-dimensional\narray  by first transforming the rows, and then the columns of the array.\n\nWhen implemented as an iterative filterbank, each pass through the filterbank yields an approximation plus three sets of detail coefficients\nrather than just one.\nMore specifically, if the two-dimensional array $X$ is the input to the filterbank, we obtain arrays $LL$, $LH$, $HL$, and $HH$,\nwhere $LL$ is a smoothed approximation of $X$ and the other three arrays contain wavelet coefficients capturing high-frequency\noscillations in vertical, horizontal, and diagonal directions.\nIn the parlance of signal processing, the arrays $LL$, $LH$, $HL$, and $HH$ are called \\emph{subbands}.\nBy recursively feeding any or all of the subbands back into the filterbank, we can decompose an input array into a collection\nof many subbands.\nThis decomposition can be represented schematically by a dyadic partition of a rectangle, called a \\emph{subband pattern}.\nThe subband pattern for one pass of the filterbank is shown in Figure \\ref{fig:2dsubbands}, with a concrete example given in Figure \\ref{fig:dwt2D}.\n\\begin{figure}\n\\begin{tikzpicture}\n%\\node[draw, thick, minimum size=4cm](-2,-2) square (2,2) []{$A_k$};\n\\draw[thick] (-2,-2) rectangle (2,2);\n\\draw[step=2cm,thick,draw](4,-2) grid (8,2);\n\\draw[thick] (4,-2) -- (8,-2);\n\n\\node[draw=none]()at(0,0){$X$};\n\\node[draw=none]()at(5,1){$LL$};\n\\node[draw=none]()at(7,1){$LH$};\n\\node[draw=none]()at(5,-1){$HL$};\n\\node[draw=none]()at(7,-1){$HH$};\n\\draw[->, >=stealth', thick, shorten <=.2cm, shorten >=.2cm]\n\t(2,0)--(4,0);\n\\end{tikzpicture}\n\\caption{The subband pattern for one step in the 2-dimensional wavelet transform.}\n\\label{fig:2dsubbands}\n\\end{figure}\n\\begin{figure}\n% the Mandrill image used to compute these images is found at http://homepages.cae.wisc.edu/~ece533/images/ (baboon.png)\n\\centering\n        \\begin{subfigure}{0.4\\textwidth}\\centering\n                    \\includegraphics[width=\\linewidth]{mandrill1.png}\n       \\end{subfigure}%\n%    \\hfill\n        \\begin{subfigure}{0.4\\textwidth}\\centering\n                    \\includegraphics[width=\\linewidth]{mandrill2.png}\n       \\end{subfigure}%\n    \\hfill\n        \\begin{subfigure}{0.4\\textwidth}\\centering\n                    \\includegraphics[width=\\linewidth]{mandrill3.png}\n       \\end{subfigure}%\n %   \\hfill\n        \\begin{subfigure}{0.4\\textwidth}\\centering\n                    \\includegraphics[width=\\linewidth]{mandrill4.png}\n       \\end{subfigure}\n    \\caption{Subbands for the Mandrill image after one pass through the filterbank.\n    Note how the upper left subband ($LL$) is an approximation of the original Mandrill image, while the other\n    three subbands highlight the stark vertical, horizontal, and diagonal changes in the image.\\\\\n    Original image source: \\url{http://sipi.usc.edu/database/}.}\n    \\label{fig:dwt2D}\n\\end{figure}\nThe wavelet coefficients that we obtain from a two-dimensional wavelet transform are very useful in a variety of image processing tasks.\nThey allow us to analyze and manipulate images in terms of both their\nfrequency and spatial properties, and at differing levels of resolution.\nFurthermore, wavelet bases often have the remarkable ability to represent\nimages in a very \\textit{sparse} manner -- that is, most of the image\ninformation is captured by a small subset of the wavelet coefficients.\nThis is the key fact for wavelet-based image compression.\n\nPyWavelets provides a simple way to calculate the subbands resulting from one pass through the filterbank.\n\\begin{lstlisting}\n>>> from scipy.misc import imread\n>>> fingerprint = imread('finger.pgm')\n>>> # use the db4 wavelet with periodic extension\n>>> lw = pywt.dwt2(fingerprint, 'db4', mode='per')\n\\end{lstlisting}\nNote that the \\li{mode} keyword argument determines the type of extension mode (required for the convolution\noperation).\nThe variable \\li{lw} is a list. The first entry of the list is the $LL$, or approximation, subband.\nThe second entry of the list is a tuple containing the remaining subbands, $LH$, $HL$, and $HH$ (in that order).\nPlot these subbands as follows:\n\\begin{lstlisting}\n>>> plt.subplot(221)\n>>> plt.imshow(np.abs(lw[0]), cmap=plt.cm.Greys_r, interpolation='none')\n>>> plt.subplot(222)\n>>> plt.imshow(np.abs(lw[1][0]), cmap=plt.cm.Greys_r, interpolation='none')\n>>> plt.subplot(223)\n>>> plt.imshow(np.abs(lw[1][1]), cmap=plt.cm.Greys_r, interpolation='none')\n>>> plt.subplot(224)\n>>> plt.imshow(np.abs(lw[1][2]), cmap=plt.cm.Greys_r, interpolation='none')\n>>> plt.show()\n\\end{lstlisting}\nCompare this with the subbands (of a different image) shown in Figure \\ref{fig:dwt2D}.\n\n\\section*{Image Compression}\nWe now turn to the topic of image compression.\nNumerous image compression techniques\nhave been developed over the years to reduce the cost of storing large quantities of images.\nTransform methods based on Fourier and Wavelet analysis\nhave long played an important role in these techniques;\nfor example, the popular JPEG image compression standard is based on\nthe discrete cosine transform.\nThe JPEG2000 compression standard and the FBI Fingerprint Image database, along with other systems,\ntake the wavelet approach.\n\nThe general framework for compression is fairly straightforward. First,\nthe image to be compressed undergoes some form of preprocessing,\ndepending on the particular application.\nNext, the discrete wavelet transform is used to calculate\nthe wavelet coefficients, and these are then \\textit{quantized},\ni.e. mapped to a set of discrete values (for example, rounding to the nearest integer).\nThe quantized coefficients are\nthen passed through an entropy encoder (such as Huffman Encoding), which reduces\nthe number of bits required to store the coefficients.\nWhat remains is a compact stream of bits\nthat can then be saved or transmitted much more efficiently than the\noriginal image. All of the above steps are invertible, allowing us to\nreconstruct the image from the compressed bitstream. See Diagram\n\\ref{tikz:wsqscheme}.\n\n\\begin{figure}\n\\centering\n\\begin{tikzpicture}[rect/.style= {draw=none, node distance = 3cm},\n\trect2/.style = {draw, thick, minimum width=3cm, minimum\n\theight=1cm}, >=stealth', shorten >=2pt]\n\n\\node[rect] (IM) [] {Image};\n\\node[rect2, node distance=3cm] (PR) [right of = IM]\n\t{Pre-Processing};\n\\node[rect2, node distance=4.5cm] (WD)[right of= PR]\n\t{Wavelet Decomposition};\n\\node[rect2, node distance=1.75cm](Q) [below=of PR.west, anchor=west]\n\t{Quantization};\n\\node[rect2, node distance = 1.75cm](EC)[below=of WD.west, anchor=west]\n\t{Entropy Coding};\n\\node[rect, node distance= 3.5cm](BS)[right of=EC]\n\t{Bit Stream};\n\n\\foreach \\s/\\t in {IM/PR, PR/WD, Q/EC, EC/BS}\n\t{\\path[->, thick](\\s) edge (\\t);}\n\\draw[|-,-|,->, thick](WD.south) |-+(0,-1em)-| (Q.north);\n\n\n\\end{tikzpicture}\n\\caption{Wavelet Image Compression Schematic}\n\\label{tikz:wsqscheme}\n\\end{figure}\n\n\\subsection*{WSQ: The FBI Fingerprint Image Compression Algorithm}\nThe Wavelet Scalar Quantization (WSQ) algorithm is among the first successful wavelet-based image compression algorithms.\nIt solves the problem of storing millions of fingerprint scans efficiently while meeting the law enforcement requirements for high image quality.\nThis algorithm is capable of achieving compression ratios in excess of 10-to-1 while retaining excellent image quality;\nsee Figure \\ref{fig:finger_compression}.\nWe will implement a basic version of this algorithm by writing a Python class that performs both the compression and decompression.\n\\begin{problem}\nBegin your implementation by defining the class \\li{WSQ} and adding an initialization method and the \\li{compress}\nmethod, as follows:\n\\begin{lstlisting}\nclass WSQ:\n    \"\"\"\n    Perform compression using the Wavelet Scalar Quantization algorithm.\n    All class attributes are set to None in __init__, but their values\n    are initialized in the compress method.\n\n    Attributes\n    ----------\n    _pixels : int, number of pixels in source image\n    _s : float, scale parameter for image preprocessing\n    _m : float, shift parameter for image preprocessing\n    _Q : numpy array, quantization parameters q for each subband\n    _Z : numpy array, quantization parameters z for each subband\n    _bitstrings : list of 3 BitArrays, giving bit encodings for each group.\n    _tvals : tuple of 3 lists of bools, indicating which subbands in each\n             groups were encoded\n    _shapes : tuple of 3 lists of tuples, giving shapes of each subband in each group\n    _huff_maps : list of 3 dicts, mapping huffman index to bit pattern\n    \"\"\"\n    def __init__(self):\n        self._pixels = None\n        self._s = None\n        self._m = None\n        self._Q = None\n        self._Z = None\n        self._bitstrings = None\n        self._tvals = None\n        self._shapes= None\n        self._huff_maps = None\n\n    def compress(self, img, r, gamma=2.5):\n        \"\"\"\n        The main compression routine. It computes and stores bitstring representation\n        of compressed image, along with other values needed for decompression.\n\n        Parameters\n        ----------\n        img : numpy array containing 8-bit integer pixel values\n        r : float, the closer to zero, the higher compression ratio\n        gamma : float, a parameter used in quantization\n        \"\"\"\n        pass\n\\end{lstlisting}\nAs we go through each step of the compression process throughout the remainder of the lab,\nyou will be adding methods and attributes to the class as directed.\nYou will also be implementing the \\li{compress} method along the way.\nAs a first step in the \\li{compress} method, calculate the number of pixels\nin the input image, and store this number in the class attribute \\li{_pixels}.\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}{.32\\textwidth}\n  \\centering\n  \\includegraphics[width=.7\\linewidth]{uncompressed_finger.png}\n  \\caption{Uncompressed}\n  \\label{fig:sub1}\n\\end{subfigure}%\n\\begin{subfigure}{.32\\textwidth}\n  \\centering\n  \\includegraphics[width=.7\\linewidth]{compressed_finger(30comp).png}\n  \\caption{12:1 compressed}\n  \\label{fig:sub1}\n\\end{subfigure}%\n\\begin{subfigure}{.32\\textwidth}\n  \\centering\n  \\includegraphics[width=.7\\linewidth]{compressed_finger(60comp).png}\n  \\caption{26:1 compressed}\n  \\label{fig:sub2}\n\\end{subfigure}\n\\caption{Fingerprint scan at different levels of compression.\\\\\nOriginal image source: \\url{http://www.nist.gov/itl/iad/ig/wsq.cfm}.\n}\n\\label{fig:finger_compression}\n\\end{figure}\n\n\\subsection*{WSQ: Preprocessing}\nThe input to the algorithm is a matrix of nonnegative 8-bit integer values giving\nthe grayscale pixel values for the fingerprint image. We process the image\nby the following formula:\n\\[\nM' = \\frac{M-m}{s},\n\\]\nwhere $M$ is the original image matrix, $M'$ is the processed image,\n$m$ is the mean pixel value, and $s = \\max\\{\\max(M) - m, m - \\min(M)\\}/128$\n(here $\\max(M)$ and $\\min(M)$ refer to the maximum and minimum pixel values\nin the matrix). This preprocessing serves to ensure that roughly half of the\nnew pixel values are negative, while the other half are positive, and all fall\nin the range $[-128,\\,128]$.\n\nTo get the mean, min, and max of an array, and the max of two elements,\nwe use the following commands:\n\\begin{lstlisting}\n>>> # assume we have an array M, numerical values a and b\n>>> M.mean()\n>>> M.max()\n>>> M.min()\n>>> max(a,b)\n\\end{lstlisting}\n\\begin{problem}\nImplement the preprocessing step, as well as its inverse by adding the class methods\n\\li{_preProcess} and \\li{_postProcess}.\nThese methods should accept a NumPy array (the image) and return the processed image.\nIn the \\li{_preProcess} method, you will calculate the values of $m$ and $s$ given above.\nThese values are needed later on for decompression, so store them in the class attributes \\li{_m} and \\li{_s}.\nRemember to avoid integer division!\n\nHaving done this, execute the preprocessing step in \\li{compress} method by calling \\li{_preProcess}.\n\\end{problem}\n\n\\subsection*{WSQ: Calculating the Wavelet Coefficients}\nThe official standard for the WSQ algorithm uses a slight modification of the\ndiscrete wavelet transform that we have studied in this lab. The differences\nare somewhat technical and do not affect performance drastically, so we will\nstick with the PyWavelets implementation. We use the \\li{'coif1'} wavelet.\n\\begin{figure}\n\\centering\n\\begin{tikzpicture}[scale=.65]\n\\draw [draw, step=1cm, thick] (0,8) grid (4,12);\n\\draw[draw, thick, step=1cm] (0,12) grid (8,16);\n\\draw[step=4cm, thick, draw](0,0) grid (16,16);\n\\draw[draw, step=.5,thick](0,15)grid(1,16);\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y))] in {0, 1}{\n\n\\node[draw=none]()at(.25+.5*\\x,15.75-.5*\\y){\\r};\n\t};\n\t};\n\n\\node[draw=none]()at(1.5, 15.5){4};\n\\node[draw=none]()at(.5,14.5){5};\n\\node[draw=none]()at(1.5,14.5){6};\n\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 7)] in {0, 1}{\n\n\\node[draw=none]()at(2.5+1*\\x,15.5-1*\\y){\\r};\n\t};\n\t};\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 7)] in {0, 1}{\n\n\\node[draw=none]()at(2.5+1*\\x,15.5-1*\\y){\\r};\n\t};\n\t};\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 11)] in {0, 1}{\n\n\\node[draw=none]()at(.5+1*\\x,13.5-1*\\y){\\r};\n\t};\n\t};\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 15)] in {0, 1}{\n\n\\node[draw=none]()at(2.5+1*\\x,13.5-1*\\y){\\r};\n\t};\n\t};\n\n\n\n\\foreach \\j in {0, 1} {\n\\foreach \\k in {0, 1} {\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 4*(\\j) + 8*(\\k)+ 19)] in {0, 1}{\n\n\\node[draw=none]()at(4.5+2*\\j+1*\\x,15.5-2*\\k-1*\\y){\\r};\n\t};\n\t};\n    };\n    };\n\n\\foreach \\j in {0, 1} {\n\\foreach \\k in {0, 1} {\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 4*(\\j) + 8*(\\k)+ 35)] in {0, 1}{\n\n\\node[draw=none]()at(.5+2*\\j+1*\\x,11.5-2*\\k-1*\\y){\\r};\n\t};\n\t};\n    };\n    };\n\n\\node[draw=none]()at(6,10){51};\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 60)] in {0, 1}{\n\n\\node[draw=none]()at(10+4*\\x,6-4*\\y){\\r};\n\t};\n\t};\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 56)] in {0, 1}{\n\n\\node[draw=none]()at(2+4*\\x,6-4*\\y){\\r};\n\t};\n\t};\n\n\\foreach \\x in {0, 1} {\n\\foreach \\y [evaluate=\\y as \\r using int((\\x)+2*(\\y) + 52)] in {0, 1}{\n\n\\node[draw=none]()at(10+4*\\x,14-4*\\y){\\r};\n\t};\n\t};\n\n\\end{tikzpicture}\n\\caption{Subband Pattern for WSQ.}\n\\label{fig:subbands}\n\\end{figure}\nWe need to calculate the subband pattern found in Figure \\ref{fig:subbands}.\nThis subband pattern is somewhat arbitrary, but is used because of its empirically good results in compression.\nWhile the pattern may appear complicated at first, we can obtain the\nrequired subband coefficients rather easily.\nTo start, decompose the image\ninto 16 subbands, first by using the \\li{dwt2} function to split the\nimage into four subbands, and then applying the function again to each of the\nfour subbands.\nWe give a reference implementation of a function that accomplishes just this task, together with its inverse, below:\n\\begin{lstlisting}\ndef _decompose16(self, image, wavelet):\n    \"\"\"\n    Decompose an array into 16 subbands.\n\n    Parameters\n    ----------\n    image : numpy array to be decomposed.\n    wavelet : string, giving the pywavelets name of the wavelet to use\n\n    Returns\n    -------\n    subbands : list of 16 numpy arrays giving the subbands\n    \"\"\"\n    subbands = []\n    LL, HVD = pywt.dwt2(image, wavelet, mode='per')\n    dec = pywt.dwt2(LL, wavelet, mode='per')\n    subbands.append(dec[0])\n    subbands.extend(dec[1])\n    for i in xrange(3):\n        dec = pywt.dwt2(HVD[i], wavelet, mode='per')\n        subbands.append(dec[0])\n        subbands.extend(dec[1])\n    return subbands\ndef _recreate16(self, subbands, wavelet):\n    \"\"\"\n    Recreate the original from the 16 subbands.\n\n    Parameters\n    ----------\n    subbands : list of 16 numpy arrays giving the subbands\n    wavelet : string, giving the pywavelets name of the wavelet to use\n\n    Returns\n    -------\n    img : numpy array, inverting the effect of _decompose16\n    \"\"\"\n    LL = pywt.idwt2((subbands[0], tuple(subbands[1:4])), wavelet, mode='per')\n    details = []\n    for i in xrange(1,4):\n        details.append(pywt.idwt2((subbands[4*i], tuple(subbands[4*i+1:4*i+4])), wavelet, mode='per'))\n    return pywt.idwt2((LL, tuple(details)), wavelet, mode='per')\n\\end{lstlisting}\n\nUsing the function \\li{_decompose16} on the fingerprint image,\nyou should now have a grid of 16 subbands.\nNext, split each of the three subbands found in the top left corner of the subband\ngrid into 16 additional subbands, in the same way as before. You now have a grid\nof $13 + 3(16) = 61$ subbands.\n\nFinally, take the very top left subband, and split this into four additional subbands.\nYou should have 64 subbands. Place them into a list in the order indicated by\nthe numbers in Figure \\ref{fig:subbands}.\n\n\\begin{problem}\nImplement the subband decomposition as described above by adding a class method \\li{_decompose}.\nWe give an implementation below. Insert comments to demonstrate your understanding of the code.\n\\begin{lstlisting}\ndef _decompose(self, img):\n    \"\"\"\n    Decompose an image into the WSQ subband pattern.\n\n    Parameters\n    ----------\n    img : numpy array holding the image to be decomposed\n\n    Returns\n    -------\n    subbands : list of 64 numpy arrays containing the WSQ subbands in order\n    \"\"\"\n    wavelet='coif1'\n    subbands = []\n    # insert comment\n    temp1 = self._decompose16(img, wavelet)\n\n    # insert comment\n    temp2 = []\n    for i in xrange(3):\n        temp2.append(self._decompose16(temp1[i], wavelet))\n\n    # insert comment\n    ll, hvd = pywt.dwt2(temp2[0][0], wavelet, mode='per')\n\n    # insert comment\n    subbands.append(ll)\n    subbands.extend(hvd)\n    subbands.extend(temp2[0][1:])\n    subbands.extend(temp2[1])\n    subbands.extend(temp2[2])\n    subbands.extend(temp1[3:])\n    return subbands\n\\end{lstlisting}\n\nImplement the inverse of this decomposition as well, i.e. write code that will take\na list of the 64 subbands and reproduce the original image.\nBelow we give an implementation.\nAgain, insert comments.\n\\begin{lstlisting}\ndef _recreate(self, subbands):\n    \"\"\"\n    Recreate an image from the 64 WSQ subbands.\n\n    Parameters\n    ----------\n    subbands : list of 64 numpy arrays containing the WSQ subbands in order\n\n    Returns\n    -------\n    img : numpy array, the recreated image\n    \"\"\"\n    wavelet='coif1'\n    # insert comment\n    ll = pywt.idwt2((subbands[0], tuple(subbands[1:4])), wavelet, mode='per')\n    temp1 = []\n    temp2 = []\n    temp2.append(ll)\n    temp2.extend(subbands[4:19])\n    # insert comment\n    temp1.append(self._recreate16(temp2, wavelet))\n    temp1.append(self._recreate16(subbands[19:35], wavelet))\n    temp1.append(self._recreate16(subbands[35:51], wavelet))\n    temp1.extend(subbands[51:])\n    # insert comment\n    img = self._recreate16(temp1, wavelet)\n    return img\n\\end{lstlisting}\n\nImplement the next step in the \\li{compress} method by calculating the wavelet subbands using \\li{_decompose}.\n\\end{problem}\n\n\\subsection*{WSQ: Quantization}\nQuantization is the process of mapping each wavelet coefficient to an\ninteger value, and is the main source of compression in the algorithm.\nBy mapping\nthe wavelet coefficients to a relatively small set of integer values, we reduce\nthe complexity of the data, which will allow us to efficiently encode the information\nin a bit string. Further, a large portion of the wavelet coefficients will be mapped to 0\nand discarded completely.\nThe fact that fingerprint images tend to be very nearly sparse in the wavelet domain\nmeans that we don't lose too much information from quantization.\nWe must take care, however, to perform this quantization in a\nmanner that achieves good compression without discarding so much information that we\nare unable to reconstruct the image accurately.\n\nGiven a wavelet coefficient $a$ in subband $k$, the corresponding quantized\ncoefficient $p$ is given by\n\\[\np =\n\\begin{cases}\n   \\left\\lfloor\\frac{a-Z_k/2}{Q_k}\\right\\rfloor + 1, & a> Z_k/2 \\\\\n   0,       & -Z_k/2 \\leq a \\leq Z_k/2\\\\\n   \\left\\lceil\\frac{a + Z_k/2}{Q_k}\\right\\rceil - 1, & a < -Z_k/2\n  \\end{cases}\n\\]\nThe values $Z_k$ and $Q_k$ are dependent on the subband, and determine how much\ncompression is achieved.\nIf $Q_k=0$, we simply map the coefficient to 0.\n\nSelecting appropriate values for these parameters is a tricky problem in itself, and relies on heuristics\nbased on the statistical properties of the wavelet coefficients.\nTherefore, we provide you with a method to come up with these values.\nThe method accepts the list of subbands as well as the parameters \\li{r} and \\li{gamma}\nthat were passed to the \\li{compress} method, and returns arrays $Q$ and $Z$,\nwhich give $Q_k$ and $Z_k$ for subbands $k=0,\\ldots,63$.\n\\begin{lstlisting}\ndef _getBins(self, subbands, r, gamma):\n    \"\"\"Calculate quantization bin widths for each subband.\"\"\"\n    subband_vars = np.zeros(64)\n    fracs = np.zeros(64)\n    for i in xrange(len(subbands)): # compute subband variances\n        X,Y = subbands[i].shape\n        fracs[i]=(X*Y)/(np.float(finger.shape[0]*finger.shape[1]))\n        x = np.floor(X/8.)\n        y = np.floor(9*Y/32.)\n        Xp = np.floor(3*X/4.)\n        Yp = np.floor(7*Y/16.)\n        mu = subbands[i].mean()\n        sigsq = (Xp*Yp-1.)**(-1)*((subbands[i][x:x+Xp, y:y+Yp]-mu)**2).sum()\n        subband_vars[i] = sigsq\n\n    A = np.ones(64)\n    A[52], A[56] = [1.32]*2\n    A[53], A[58], A[55], A[59] = [1.08]*4\n    A[54], A[57] = [1.42]*2\n\n    Qprime = np.zeros(64)\n    mask = subband_vars >= 1.01\n    Qprime[mask] = 10./(A[mask]*np.log(subband_vars[mask]))\n    Qprime[:4] = 1\n    Qprime[60:] = 0\n\n    K = []\n    for i in xrange(60):\n        if subband_vars[i] >= 1.01:\n            K.append(i)\n\n    while True:\n        S = fracs[K].sum()\n        P = ((np.sqrt(subband_vars[K])/Qprime[K])**fracs[K]).prod()\n        q = (gamma**(-1))*(2**(r/S-1))*(P**(-1./S))\n        E = []\n        for i in K:\n            if Qprime[i]/q >= 2*gamma*np.sqrt(subband_vars[i]):\n                E.append(i)\n        if len(E) > 0:\n            for i in E:\n                K.remove(i)\n            continue\n        break\n\n    Q = np.zeros(64) # final bin widths\n    for i in K:\n        Q[i] = Qprime[i]/q\n    Z = 1.2*Q\n\n    return Q, Z\n\\end{lstlisting}\n\nQuantization is not a perfectly invertible process. Once we have quantized\nthe wavelet coefficients, some information is permanently lost. However, we can\nroughly reconstruct the wavelet coefficients $\\hat{a}_k$ in subband $k$ from the quantized coefficients\n$p$ using the following formula.\nThis process is called \\emph{dequantization}.\n\\[\n\\hat{a}_k =\n\\begin{cases}\n(p-C)Q_k + Z_k/2, & p> 0\\\\\n0, & p = 0\\\\\n(p + C)Q_k - Z_k/2, & p < 0\n\\end{cases}\n\\]\nFor our purposes, take $C = 0.44$. Again, if $Q_k = 0$, just return $\\hat{a}_k = 0$.\n\\begin{problem}\nImplement the quantization step by adding the following method to your class:\n\\begin{lstlisting}\ndef _quantize(self, coeffs, Q, Z):\n    \"\"\"\n    Implement a uniform quantizer.\n\n    Parameters\n    ----------\n    coeffs : numpy array containing the floating-point values to be quantized.\n    Q : the step size of the quantization, a nonnegative float\n    Z : the null-zone width (of the center/0 quantization bin) nonnegative float\n\n    Returns\n    -------\n    out : numpy array of same shape as coeffs holding the quantized values\n    \"\"\"\n    pass\n\\end{lstlisting}\nWherever possible, operate on the vectors as a whole rather than writing for-loops.\nYou may wish to make use of the array slicing techniques demonstrated below:\n\\begin{lstlisting}\n>>> # assume X, Y are numpy arrays of same shape\n>>> m = X < -2 # create mask for entries less than -2\n>>> Y[m] = np.ceil(X[m]) + 2 # set corresponding entries of Y\n\\end{lstlisting}\n\nImplement the dequantization step as well.\n\\begin{lstlisting}\ndef _dequantize(self, coeffs, Q, Z, C=0.44):\n    \"\"\"\n    Reverse the quantization effect (approximately).\n\n    Parameters\n    ----------\n    coeffs : numpy array of quantized coefficients\n    Q : see doc for quantize\n    Z : see doc for quantize\n    C : centering parameter\n\n    Returns\n    -------\n    out : array of dequantized coefficients, same shape as coeffs\n    \"\"\"\n    pass\n\\end{lstlisting}\nRemember to consider the case where $Q=0$!\n\nObserve that both quantization and dequantization require $Q_k$ and $Z_k$ for each subband $k$.\nThus, once you obtain these values in the \\li{compress} method using \\li{_getBins}, store them in the class attributes\n\\li{_Q} and \\li{_Z}.\nThen, calculate the 64 compressed subbands.\nFor example, if \\li{subbands} is a list containing the 64 wavelet subbands, the following\ncode will produce a list of the quantized subbands:\n\\begin{lstlisting}\n>>> # get the quantization parameters, store\n>>> self._Q, self._Z = self._getBins(subbands, r, gamma)\n>>> # now create a list of all quantized subbands\n>>> q_subbands = [self._quantize(subbands[i],self._Q[i],self._Z[i]) for i in xrange(64)]\n\\end{lstlisting}\n\\end{problem}\n\\subsection*{WSQ: Grouping}\nAt this point in the algorithm, we have a list of 64 arrays, where the $k$-th\nentry is a matrix containing the quantized wavelet coefficients for the $k$-th subband.\nThe remaining steps in the algorithm focus on entropy coding these quantized\ncoefficients to further increase compression.\nAs such, we have finished with the wavelet analysis portion.\n\nWe will segment the list of quantized subbands into three groups.\nThis gives three lists of quantized coefficients, each having a high degree of homogeneity.\nThis is important for the entropy coding, since we can achieve better compression by separately encoding groups of similar coefficients.\n\nGroup quantized subbands $0$ through $18$ together, $19$ through $51$ together, and finally $52$ through $63$ together.\nYou may understand the logic of these groupings when glancing back at Figure \\ref{fig:subbands}.\nWhen grouping subbands together, flatten each subband and concatenate their entries together, so that you obtain a simple list of integer values.\nSince we are flattening and then concatenating the subbands, we need to save the shape of the original subbands, so that we can later\nreconstruct the subbands from the groups of coefficients.\nFinally, we will not include subbands that consist entirely of zeros, as these contain no information and thus don't need to be stored.\nTherefore, while looping through the subbands and creating the lists of coefficients, include a check for nonzero entries in the subband,\nand also create a list of boolean values for each group whose $i$-th entry indicates whether the $i$-th subband in the group was included.\n\nBelow is sample code for producing the first group.\nUse a similar approach for the other two groups.\n\\begin{lstlisting}\n>>> # assume subbands is my list of the 64 quantized subbands\n>>> g1 = []     # this will hold the group 1 coefficients\n>>> s1 = []     # keep track of the subband dimensions in group 1\n>>> t1 = []     # keep track of which subbands were included\n>>> for i in xrange(19):\n>>>     s1.append(subbands[i].shape)\n>>>     if subbands[i].any(): # True if any nonzero entry\n>>>         g1.extend(subbands[i].ravel())\n>>>         t1.append(True)\n>>>     else: # the subband was not transmitted\n>>>         t1.append(False)\n\\end{lstlisting}\n\nTo reconstruct the subbands from \\li{g1}, \\li{s1}, and \\li{t1}, we have the following code:\n\\begin{lstlisting}\n>>> # reconstruct the subbands in group 1\n>>> subbands1 = []     # the reconstructed subbands in group 1\n>>> i = 0\n>>> for j, shape in enumerate(s1):\n>>>     if t1[j]: # if the j-th subband was included\n>>>         l = shape[0]*shape[1] # number of entries in the subband\n>>>         subbands1.append(np.array(g1[i:i+l]).reshape(shape))\n>>>         i += l\n>>>     else: # the j-th subband wasn't included, so all zeros\n>>>         subbands1.append(np.zeros(shape))\n\\end{lstlisting}\n\\begin{problem}\nCarry out the grouping procedure and its inverse as described above by implementing\nthe following class methods:\n\\begin{lstlisting}\ndef _group(self, subbands):\n    \"\"\"\n    Split the quantized subbands into 3 groups.\n\n    Parameters\n    ----------\n    subbands : list of 64 numpy arrays containing quantized coefficients\n\n    Returns\n    -------\n    gs : tuple (g1,g2,g3)\n         each gi a list of quantized coeffs for groups i\n    ss : tuple (s1,s2,s3)\n         each si a list of tuples, the shapes of the subbands in group i\n    ts : tuple (t1,t2,t3)\n         each ti a list of bools indicating which subbands included\n    \"\"\"\n    pass\n\ndef _ungroup(self, gs, ss, ts):\n    \"\"\"\n    Re-create the subband list structure from the three groups.\n\n    Parameters\n    ----------\n    gs : tuple of form (g1, g2, g3)\n    ss : tuple of form (s1, s2, s3)\n    ts : tuple of form (t1, t2, t3)\n    See the docstring for _group.\n\n    Returns\n    -------\n    subbands : list of 64 numpy arrays\n    \"\"\"\n    pass\n\\end{lstlisting}\n\nNote that we need the shapes and the boolean lists indicating which subbands were included\nfor the un-grouping step.\nThus, in the \\li{compress} method, once we computed these tuples of lists, we store them in the class attributes \\li{_shapes}\nand \\li{_tvals}, respectively.\n\\begin{lstlisting}\n>>> groups, self._shapes, self._tvals = self._group(q_subbands)\n\\end{lstlisting}\n\\end{problem}\n\n\\subsection*{WSQ: From Quantized Coefficients to Huffman Indices}\nWe now have three groups of integer-valued quantized coefficients.\nIt remains to encode each of these three groups using Huffman coding.\n\nNote that each group is likely to contain many consecutive zeros, since we have rounded all of the smallest\nwavelet coefficients to zero.\nThere will also be a few quantized coefficients of high magnitude.\nThe remaining nonzero coefficients will have values between $-73$ and $74$.\nWith this in mind, we can represent these groups of coefficients even more tersely by\nmapping them to a set of discrete values (integers from $0$ to $253$), which we call \\emph{Huffman Indices}.\nThe mapping between Huffman indices and quantized coefficients is given in Table \\ref{table:huffIndex}.\n\\begin{table}\n\\begin{tabular}{|c|c|}\n\\hline\n\\textbf{Huffman Index} & \\textbf{Quantized Coefficient}\\\\\\hline\n0 & zero run length 1\\\\\\hline\n1 & zero run length 2\\\\\\hline\n\\vdots & \\vdots\\\\\\hline\n99 & zero run length 100\\\\\\hline\n100 & $75\\leq q \\leq 255$\\\\\\hline\n101 & $-255 \\leq q \\leq -74$\\\\\\hline\n102 & $256 \\leq q \\leq 65535$\\\\\\hline\n103 & $-65535 \\leq q \\leq -256$\\\\\\hline\n104 & zero run of length $101\\leq n \\leq 255$\\\\\\hline\n105 & zero run of length $255\\leq n \\leq 65535$\\\\\\hline\n106 & -73\\\\\\hline\n107 & -72\\\\\\hline\n108 & -71\\\\\\hline\n\\vdots & \\vdots\\\\\\hline\n179 & 0 \\emph{(use index 0)}\\\\\\hline\n\\vdots & \\vdots \\\\\\hline\n252 & 73\\\\\\hline\n253 & 74\\\\\\hline\n\\end{tabular}\n\\caption{The mapping between Huffman indices and quantized coefficients.}\n\\label{table:huffIndex}\n\\end{table}\n\nTo see how this mapping works, suppose that we have the following list of quantized coefficients:\n\\[\n[0, 0, 0, 0, -45, 13, 103, -269, 0]\n\\]\nThe list starts off with a zero run of length $4$, so the first Huffman index is $3$\n(each zero run of length $n$ where $n\\leq 100$ get a Huffman index of $n-1$).\nThe next coefficient is $-45$, so we infer from the Table that its Huffman index\nis $-45 + (106+73) = 134$.\nThe next coefficient is $13$, so as before, its Huffman index is $13 + 179 = 192$.\nThe final three indices are $100$, $103$, and $0$.\n\nNote that this mapping is not one-to-one when dealing with zero runs of lengths greater than $100$,\nor with coefficients of sufficiently large magnitudes (the Huffman indices for these cases\nare 100 through 105).\nWe refer to these cases as \\emph{exceptional cases}.\nWhen we encounter exceptional cases, we need to\nstore the length of the zero run or the magnitude of the coefficient, so that we can perfectly\nreconstruct the quantized coefficients at the decompression stage.\nHence, while generating a list of the Huffman indices for each group, we also generate a list\nof extra values for the exceptional cases.\n\nFinally, as we generate the list of Huffman indices from the quantized coefficients, we also tabulate\nthe frequency of each index, as this is necessary when building a Huffman Encoder.\n\nBelow we give code to calculate the Huffman indices, frequencies, and extra values given a list of\nquantized coefficients.\n\\begin{lstlisting}\ndef _huffmanIndices(self, coeffs):\n    \"\"\"\n    Calculate the Huffman indices from the quantized coefficients.\n\n    Parameters\n    ----------\n    coeffs : list of integer values\n\n    Returns\n    -------\n    inds : list of Huffman indices\n    freqs : numpy array whose i-th entry gives frequency of index i\n    extra : list of zero run lengths or coefficient magnitudes for exceptional cases\n    \"\"\"\n    N = len(coeffs)\n    i = 0\n    inds = []\n    extra = []\n    freqs = np.zeros(254)\n\n    # sweep through the quantized coefficients\n    while i < N:\n        # first handle zero runs\n        zero_count = 0\n        while coeffs[i] == 0:\n            zero_count += 1\n            i += 1\n            if i >= N:\n                break\n        if zero_count > 0 and zero_count < 101:\n            inds.append(zero_count - 1)\n            freqs[zero_count - 1] += 1\n        elif zero_count >= 101 and zero_count < 256: # 8 bit zero run\n            inds.append(104)\n            freqs[104] += 1\n            extra.append(zero_count)\n        elif zero_count >= 256: # 16 bit zero run\n            inds.append(105)\n            freqs[105] += 1\n            extra.append(zero_count)\n        if i >= N:\n            break\n        # now handle nonzero coefficients\n        if coeffs[i] > 74 and coeffs[i] < 256: # 8 bit pos coeff\n            inds.append(100)\n            freqs[100] += 1\n            extra.append(coeffs[i])\n        elif coeffs[i] >= 256: # 16 bit pos coeff\n            inds.append(102)\n            freqs[102] += 1\n            extra.append(coeffs[i])\n        elif coeffs[i] < -73 and coeffs[i] > -256: # 8 bit neg coeff\n            inds.append(101)\n            freqs[101] += 1\n            extra.append(abs(coeffs[i]))\n        elif coeffs[i] <= -256: # 16 bit neg coeff\n            inds.append(103)\n            freqs[103] += 1\n            extra.append(abs(coeffs[i]))\n        else: # current value is a nonzero coefficient in the range [-73, 74]\n            inds.append(179 + coeffs[i])\n            freqs[179 + coeffs[i]] += 1\n        i += 1\n    return inds, freqs, extra\n\\end{lstlisting}\n\\begin{problem}\nExamine the code for \\li{_huffmanIndices} to make sure you understand it, and add it to your class.\n\\end{problem}\n\nIn the decompression stage, we need to recover the quantized coefficients from the Huffman Indices.\nAs noted before, the mapping is not one-to-one for the exceptional cases, so we need both the list\nof indices and the extra values.\nGiven these two lists, it is not difficult to recover the coefficients.\n\\begin{lstlisting}\ndef _indicesToCoeffs(self, indices, extra):\n    \"\"\"\n    Calculate the coefficients from the Huffman indices plus extra values.\n\n    Parameters\n    ----------\n    indices : list of integer values (Huffman indices)\n    extra : list of indices corresponding to values with exceptional indices\n\n    Returns\n    -------\n    coeffs : list of quantized coefficients recovered from the indices.\n    \"\"\"\n    coeffs = []\n    j = 0 # index for extra array\n    for s in indices:\n        if s < 100: # zero count of 100 or less\n            coeffs.extend(np.zeros(s+1))\n        elif s == 104 or s == 105: # zero count of 8 or 16 bits\n            coeffs.extend(np.zeros(extra[j]))\n            j += 1\n        elif s in [100, 102]: # 8 or 16 bit pos coefficient\n            coeffs.append(extra[j]) # get the coefficient from the extra list\n            j += 1\n        elif s in [101, 103]: # 8 or 16 bit neg coefficient\n            coeffs.append(-extra[j]) # get the coefficient from the extra list\n            j += 1\n        else: # coefficient from -73 to +74\n            coeffs.append(s-179)\n    return coeffs\n\\end{lstlisting}\n\\begin{problem}\nExamine the code for \\li{_indicesToCoeffs} for understanding, and then add the method to your class.\n\\end{problem}\n\\subsection*{Reading and Writing Bits with bitstring}\nIn the final stage of the algorithm, we take our lists of Huffman indices and map them to bit patterns.\nPure Python is not equipped to manipulate data\nat the bit level, so we will use the Python package \\li{bitstring} to facilitate the process.\nIn this section we present the functions required for the WSQ algorithm.\n\nOnce you have installed the package, type the import command:\n\\begin{lstlisting}\n>>> import bitstring as bs\n\\end{lstlisting}\nIn order to build a string of bits, we initialize a \\li{BitArray} object, and then add the\ndesired bit patterns.\n\\begin{lstlisting}\n>>> bits = bs.BitArray()\n>>> # add bit patters 1101 and 01\n>>> bits.append('0b1101')\n>>> bits.append('0b01')\n\\end{lstlisting}\nNote that the string containing the bit pattern must begin with \\li{'0b'}.\n\nWe can add an 8- or 16-bit representations of an integer as follows:\n\\begin{lstlisting}\n>>> # add the 8-bit integer 212, and then the 16-bit integer 1047\n>>> bits.append('uint:8=212')\n>>> bits.append('uint:16=1047')\n\\end{lstlisting}\nTo view the bits contained in the \\li{BitArray}, we can print the \\li{bin} attribute.\n\\begin{lstlisting}\n>>> # view the entire bit string\n>>> print bits.bin\n110101110101000000010000010111\n\\end{lstlisting}\n\nWhen reading the data from a bit stream, we use a \\li{bs.ConstBitStream} object, and call its \\li{read} method, giving it an input string\nthat specifies the way to interpret the bits, and the number of bits to read.\nTo read the next 3 bits as binary, the input string would be \\li{'bin:3'}, whereas to read the next 16 bits as an unsigned integer\nyou would provide the input string \\li{'uint:16'}.\nLet's read the first 6 bits of \\li{bits}, one at a time:\n\\begin{lstlisting}\n>>> bitreader = bs.ConstBitStream(bits)\n>>> for i in xrange(6):\n>>>     print bitreader.read('bin:1')\n1\n1\n0\n1\n0\n1\n\\end{lstlisting}\nWe know that the next 8 bits should be interpreted as an unsigned integer, and likewise for the\nfollowing 16 bits. Thus, we read these bits as follows:\n\\begin{lstlisting}\n>>> print bitreader.read('uint:8')\n212\n>>> print bitreader.read('uint:16')\n1047\n\\end{lstlisting}\n\nYou now have all the tools necessary to read and write the compressed image bit stream.\n\n\\subsection*{WSQ: Huffman Coding}\nHuffman coding is a technique for assigning binary codes to a collection of symbols in such a way\nthat minimizes the total number of bits needed to encode the symbols.\nMore frequent symbols will be assigned shorter binary codes, while rare symbols will have\nlonger codes.\nOne simple way to implement Huffman Coding is to build a binary tree, whose leaves correspond\nto the different symbols to be encoded.\nWe then traverse the tree from the root down to each leaf node to generate the binary codes\n(left corresponds to 0, right corresponds to 1).\nBelow we give a reference implementation.\n\\begin{lstlisting}\nimport Queue\nclass huffmanLeaf():\n    \"\"\"Leaf node for Huffman tree.\"\"\"\n    def __init__(self, symbol):\n        self.symbol = symbol\n    def makeMap(self, huff_map, path):\n        huff_map[self.symbol] = path\n\nclass huffmanNode():\n    \"\"\"Internal node for Huffman tree.\"\"\"\n    def __init__(self, left, right):\n        self.left = left\n        self.right = right\n    def makeMap(self, huff_map, path):\n        \"\"\"\n        Traverse the huffman tree to build the encoding map.\n        \"\"\"\n        self.left.makeMap(huff_map, path + '0')\n        self.right.makeMap(huff_map, path + '1')\n\ndef huffman(freqs):\n    \"\"\"\n    Generate the huffman tree for the given symbol frequencies.\n    Return the map from symbol to bit pattern.\n    \"\"\"\n    q = Queue.PriorityQueue()\n    for i in xrange(len(freqs)):\n        leaf = huffmanLeaf(i)\n        q.put((freqs[i], leaf))\n    while q.qsize() > 1:\n        l1 = q.get()\n        l2 = q.get()\n        weight = l1[0] + l2[0]\n        node = huffmanNode(l1[1], l2[1])\n        q.put((weight,node))\n    root = q.get()[1]\n    huff_map = dict()\n    root.makeMap(huff_map, '')\n    return huff_map\n\\end{lstlisting}\nWhen we pass a list of Huffman indices to the function \\li{huffman}, we obtain\nobtain a dictionary (called the Huffman map) whose keys are the integers 0 through 253 (the Huffman indices)\nand whose values are the bit pattern assigned to each Huffman index.\nThis Huffman map, together with the list of Huffman indices and extra values,\nallows us to encode the quantized coefficients as a bit string.\nMake sure you understand the implementation of the encoding process given below:\n\\begin{lstlisting}\ndef _encode(self, indices, extra, huff_map):\n    \"\"\"\n    Encode the indices using the Huffman map, return the resulting bitstring.\n\n    Parameters\n    ----------\n    indices : list of integer values, the Huffman Indices\n    extra : list of integer coefficients corresponding to exceptional indices\n    huff_map : dict that maps Huffman index to bit pattern\n\n    Returns\n    -------\n    bits : BitArray object containing bit representation of the Huffman indices\n    \"\"\"\n    bits = bs.BitArray()\n    j = 0 # index for extra array\n    for s in indices: # encode each huffman index\n        bits.append('0b' + huff_map[s])\n\n        # encode extra values for exceptional cases\n        if s in [104, 100, 101]: # encode as 8-bit ints\n            bits.append('uint:8={}'.format(int(extra[j])))\n            j += 1\n        elif s in [102, 103, 105]: # encode as 16-bit ints\n            bits.append('uint:16={}'.format(int(extra[j])))\n            j += 1\n    return bits\n\\end{lstlisting}\n\n\\begin{problem}\nAdd the \\li{_encode} method to your class.\nImplement the Huffman coding step in the \\li{compress} method by calculating\nthe Huffman indices, Huffman map, and bit string for each group of quantized coefficients separately.\nStore the resulting three bit strings and Huffman maps in the class attributes \\li{_bitstrings}\nand \\li{_huff_maps}.\nUse the following code block as a guide.\n\\begin{lstlisting}\n>>> # assume groups is a list of the three groups of coefficients\n>>> # for each group, get huffman indices, create huffman tree, and encode\n>>> huff_maps = []\n>>> bitstrings = []\n>>> for i in xrange(3):\n>>>     inds, freqs, extra = self._huffmanIndices(groups[i])\n>>>     huff_map = huffman(freqs)\n>>>     huff_maps.append(huff_map)\n>>>     bitstrings.append(self._encode(inds, extra, huff_map))\n>>>\n>>> # store the bitstrings and the huffman maps\n>>> self._bitstrings = bitstrings\n>>> self._huff_maps = huff_maps\n\\end{lstlisting}\nYou have now fully implemented the compression algorithm!\n\\end{problem}\n\nFor decompression, we need to decode the bit strings back to Huffman indices.\nThis is straight-forward enough using the Huffman maps.\nEssentially, we read the bit string one bit at a time, check to see if we have a bit pattern\nfound in the Huffman map, and if so, store the corresponding Huffman index in the list of Huffman indices.\nIf the Huffman index is an exceptional case, we read the next 8 or 16 bits from\nthe bit string (depending on the exact value of the index), and store the resulting\nvalue in the list of extra values.\nExamine the implementation below for understanding:\n\\begin{lstlisting}\ndef _decode(self, bits, huff_map):\n    \"\"\"\n    Decode the bits using the given huffman map, return the resulting indices.\n\n    Parameters\n    ----------\n    bits : BitArray object containing the bit-encoded indices\n    huff_map : dict that maps huffman index to bit pattern\n\n    Returns\n    -------\n    indices : list of decoded huffman indices\n    extra : list of decoded values corresponding to exceptional indices\n    \"\"\"\n    indices = []\n    extra = []\n\n    # reverse the huffman map to get the decoding map\n    dec_map = {v:k for k, v in huff_map.items()}\n\n    # wrap the bits in an object better suited to reading\n    bits = bs.ConstBitStream(bits)\n\n    # read each bit at a time, decoding as we go\n    i = 0 # the index of current bit\n    pattern = '' # the current bit pattern\n    while i < bits.length:\n        pattern += bits.read('bin:1') # read in another bit\n        i += 1\n\n        # check if current pattern is in the decoding map\n        if dec_map.has_key(pattern):\n            indices.append(dec_map[pattern]) # insert huffman index\n\n            # if an exceptional index, read next bits for extra value\n            if dec_map[pattern] in (100, 101, 104): # 8-bit int or 8-bit zero run length\n                extra.append(bits.read('uint:8'))\n                i += 8\n            elif dec_map[pattern] in (102, 103, 105): # 16-bit int or 16-bit zero run length\n                extra.append(bits.read('uint:16'))\n                i += 16\n            pattern = '' # reset the bit pattern\n    return indices, extra\n\\end{lstlisting}\n\n\\begin{problem}\nAdd the \\li{_decode} method to your class.\n\\end{problem}\n\n\\subsection*{WSQ: Decompression}\nDecompression refers to recovering the original image from the bit encodings of the quantized wavelet coefficients.\nYou already have all of the methods required for decompression; what remains is to put them together.\nMake sure you understand what's going on in the following implementation.\n\\begin{lstlisting}\ndef decompress(self):\n    \"\"\"\n    Return the uncompressed image recovered from the compressed bistring representation.\n\n    Returns\n    -------\n    img : numpy array giving the recovered uncompressed image.\n    \"\"\"\n    # for each group, decode the bits, map from indices to coefficients\n    groups = []\n    for i in xrange(3):\n        indices, extras = self._decode(self._bitstrings[i], self._huff_maps[i])\n        groups.append(self._indicesToCoeffs(indices, extras))\n\n    # recover the subbands from the groups of coefficients\n    q_subbands = self._ungroup(groups, self._shapes, self._tvals)\n\n    # dequantize the subbands\n    subbands = [self._dequantize(q_subbands[i], self._Q[i], self._Z[i]) for i in xrange(64)]\n\n    # recreate the image\n    img = self._recreate(subbands)\n\n    # post-process, return the image\n    return self._postProcess(img)\n\\end{lstlisting}\n\\begin{problem}\nAdd the \\li{decompress} method to your class.\n\\end{problem}\n\n\\subsection*{WSQ: Calculating the Compression Ratio}\nThe compression ratio is the ratio of the number of bits in the original image to the number of bits in the encoding.\nAssuming that each pixel of the input image is an 8-bit integer, the number of bits in the image is just 8 times the number of pixels\n(recall that the number of pixels in the original source image is stored in the class attribute \\li{_pixels}).\nWe can calculate the number of bits in the encoding by adding up the lengths of each of the three bit strings stored\nin the class attribute \\li{_bitstrings}.\n\\begin{problem}\nAdd the method \\li{getRatio} to your class by implementing the following:\n\\begin{lstlisting}\ndef getRatio(self):\n    \"\"\"\n    Calculate the compression ratio achieved.\n\n    Returns\n    -------\n    ratio : float, the ratio of number of bytes in original image to number of bytes contained\n            in the three bitstrings combined.\n    \"\"\"\n    pass\n\\end{lstlisting}\nWatch out for integer division!\n\\end{problem}\n\nWe now have a fully functional implementation of the Wavelet Scalar Quantization algorithm for image compression.\nTest out your code by compressing the fingerprint image finger.pgm for different values of $r$ (say in the range\n0.1 to 0.9).\nCalculate the compression ratio, and plot the original image and compressed image together, as follows:\n\\begin{lstlisting}\n>>> # instantiate a value for r\n>>> finger = imread('finger.pgm')\n>>> wsq = WSQ()\n>>> wsq.compress(finger, r)\n>>> print wsq.getRatio()\n>>> new_finger = wsq.decompress()\n>>> plt.subplot(211)\n>>> plt.imshow(finger, cmap=plt.cm.Greys_r)\n>>> plt.subplot(212)\n>>> plt.imshow(new_finger.clip(finger.min(), finger.max()), cmap=plt.cm.Greys_r)\n>>> plt.show()\n\\end{lstlisting}\n\n\n\n\\begin{comment}\nWe don't need a lot of this expository content in the lab.\n\\subsection*{The Haar Wavelet}\n\nAs noted earlier, the Fourier transform is based on the complex exponential\nfunction. Let us alter the situation and consider instead the following\nfunction, known as the \\emph{Haar wavelet}:\n\\begin{equation*}\n\\psi(x) =\n \\begin{cases}\n  1 & \\text{if } 0 \\leq x < \\frac{1}{2} \\\\\n  -1 & \\text{if } \\frac{1}{2} \\leq x < 1 \\\\\n  0 & \\text{otherwise.}\n \\end{cases}\n\\end{equation*}\n\n% It might be nice to plot this function and include the image in the lab.\n\nAlong with this wavelet, we introduce the associated \\emph{scaling function}:\n\\begin{equation*}\n\\phi(x) =\n \\begin{cases}\n 1 & \\text{if } 0 \\leq x < 1 \\\\\n 0 & \\text{otherwise.}\n \\end{cases}\n\\end{equation*}\n\nFrom the wavelet and scaling function, we can generate two countable families\nof dyadic dilates and translates given by\n\\begin{equation*}\n\\psi_{m,k}(x) = \\psi(2^mx - k)\n\\end{equation*}\n\\begin{equation*}\n\\phi_{m,k}(x) = \\phi(2^mx - k),\n\\end{equation*}\nwhere $m,k \\in \\mathbb{Z}$.\n\nLet us focus for the moment on that second family of functions, $\\{\\phi_{m,k}\\}$.\nIf we fix $m$ and let $k$ vary over the integers, we have a countable collection of\nsimple functions. The support of a typical function $\\phi_{m,k}$ is the interval\n$[k2^{-m}, (k+1)2^{-m}]$, and for any $m \\in \\mathbb{Z}$ we have\n\\begin{equation*}\n\\mathbb{R} = \\displaystyle\\biguplus_k\\,[k2^{-m}, (k+1)2^{-m}],\n\\end{equation*}\nwhere $\\uplus$ denotes a union over disjoint sets. Thus, the supports can be viewed as\na discretization of the real line, and we can use this collection of simple functions\nto approximate any $f \\in L^2(\\mathbb{R})$ in the following sense:\n\\begin{equation*}\nf(x) \\approx f_m(x) := \\displaystyle\\sum_{k \\in \\mathbb{Z}}\\alpha_{m,k}\\phi_{m,k}(x),\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\alpha_{m,k} := 2^m \\displaystyle \\int_{k2^{-m}}^{(k+1)2^{-m}}f(x) dx\n\\end{equation*}\n($\\alpha_{m,k}$ is simply the average value of $f$ on $[k2^{-m},(k+1)2^{-m}]$). As you\nwould probably expect, the point-wise error between $f$ and its approximation $f_m$\n(called a \\emph{frame}) goes to zero as $m \\to \\infty$.\n\nThese frames are not quite good enough, however. Each coefficient $\\alpha_{m,k}$\ncertainly captures local information about $f$ -- namely its average value on\na certain interval -- but it fails to tell us anything about how $f$ changes\non that interval. We need more information than is provided by $f_m$ in order\nto know about discontinuities or high-frequency oscillations of $f$. To this end,\nwe now consider the wavelet function $\\psi$.\nNotice that the Haar wavelet is oscillatory in nature, and is thus better suited\nto capture local information on how a function changes at a given point. For\nany given $m$, we define a function $d_m$, called a \\emph{detail}, as follows:\n\\begin{equation*}\nd_m(x) := \\displaystyle\\sum_{k \\in \\mathbb{Z}}\\beta_{m,k}\\psi_{m,k}(x),\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\beta_{m,k} := 2^m \\displaystyle \\int_{-\\infty}^{\\infty}f(x) \\psi_{m,k}(x) dx.\n\\end{equation*}\nEach coefficient $\\beta_{m,k}$ gives information about how $f$ changes on the\nthe interval $[k2^{-m}, (k+1)2^{-m}]$, and larger coefficients correspond\nto larger spikes of width $2^{-m}$. Thus, as $m$ increases, the\ndetail function $d_m$ gives information about the higher-frequency oscillations\nof the function. The details and approximation frames interact in the following way:\n\\begin{equation*}\nf_{m+1} = f_m + d_m.\n\\end{equation*}\nAs a result of this fortuitous relationship, one can prove the decomposition\n\\begin{equation*}\nL^2(R) = V_0 \\oplus W_0 \\oplus W_1 \\oplus \\cdots,\n\\end{equation*}\nwhere $V_j := \\text{span}\\{\\phi_{j,k}\\}_{k \\in \\mathbb{Z}}$ and\n$W_j := \\text{span}\\{\\psi_{j,k}\\}_{k \\in \\mathbb{Z}}$. This fact justifies\nour hope to approximate and analyze functions using wavelets.\n\\begin{figure}[t]\n\\minipage{0.32\\textwidth}\n    \\includegraphics[width=\\linewidth]{sinecurve}\n    \\caption{$f(x) = \\sin (x)$}\n\\endminipage\\hfill\n\\minipage{0.32\\textwidth}\n    \\includegraphics[width=\\linewidth]{discreteSineCurve.pdf}\n    \\caption{$f_4$}\n\\endminipage\\hfill\n\\minipage{0.32\\textwidth}\n    \\includegraphics[width=\\linewidth]{sineCurveDetail}\n    \\caption{$d_4$}\n\\endminipage\n\\end{figure}\n\\begin{problem}\nCalculate and plot the approximation frames for $f(x) = \\sin(x)$ on the interval $[0,2\\pi]$\nfor $m = 4, 6, 8$. Note that because we are working on a finite interval,\nwe only need to calculate certain coefficients $\\alpha_{m,k}$. In\nparticular, we only need the coefficients for $k = 0$ up to the first integer\n$n$ such that $(n+1)2^{-m} > 2 \\pi$ (why?). Furthermore, to plot the frame,\nall we need is an array containing the relevant coefficients. Then simply plot\nthe coefficients against \\li{linspace} with appropriate arguments\nand set \\li{drawstyle='steps'} in the \\li{plt.plot} function.\n\\end{problem}\n\n\\begin{problem}\nNow calculate the details for $f(x) = \\sin(x)$ on the same interval and for the\nsame $m$ values given above. Use previous results to compute the coefficients\nfor $f_5$, $f_7$, and $f_9$ and plot them.\n\\end{problem}\n\nWhat purpose do these details and approximation frames serve? According to the\nproperties discussed above, we can approximate $L^2$ functions as follows:\n\\begin{align*}\nf \\approx f_{J+1} &= f_J + d_J \\\\\n&= f_{J-1} + d_{J-1} + d_J \\\\\n& \\ldots\\\\\n&= f_{I} + d_{I} + d_{I+1} + \\cdots + d_J,\n\\end{align*}\nwhere $1 \\leq I \\leq J$. If $f$ has compact support (as in the case of a finite-time signal,\nfor example), only finitely many of the coefficients in the frame and the details are\nnonzero, thus enabling us to represent $f$ to a reasonable degree of accuracy in a very\nefficient manner. The calculation of these detail coefficients is called the \\emph{discrete\nwavelet transform}. In the context of signals processing, one can imagine calculating these\ncoefficients, transmitting them, and then reproducing the approximated signal on the\nreceiving end. Furthermore, the coefficients of the details reflect the local properties\nof the original function $f$ at the particular level of detail and resolution! This means\nthat we can discard many of the coefficients if we are only interested in reproducing a certain\npart of the signal, or in recovering the entire signal to only a limited resolution. We can\nalso study just those frequencies of the signal that fall within a certain range (called a\nsub-band) by examining the detail coefficients at a particular level. These\nproperties make the discrete wavelet transform an attractive alternative to the Fourier\ntransform in many applications. See Figure \\ref{fig:dwt1D} for an example of the discrete Wavelet transform.\n\nIn practice, we are often interested in analyzing discrete signals with compact support (that is,\nfinite-time signals that we have sampled at a finite number of points). If wavelet analysis is\nto be of any use, we first need an efficient way to calculate the discrete wavelet transform.\nThe process described in the first section, while intuitive and illustrative of the mathematical\nprinciples\nbehind wavelet analysis, is not the best approach to calculating the wavelet coefficients. It\nturns out that the discrete wavelet transform can be implemented as an iterated low-pass/high-pass\nfilter bank, one iteration of which is shown graphically in the figure. We present the\nalgorithm without getting into the details of why it works.\n\n\nThe algorithm goes as follows.\nGiven an input matrix of size $2^n \\times 2^n$, first operate on the rows as you would\nin the one-dimensional Wavelet transform (i.e. convolve each row with the filters, then\ndownsample).\nWe then have two matrices of size $2^n \\times 2^{n-1}$,\nsince each row has been downsampled by a factor of 2. Then for each of these two\nintermediate matrices, operate on each column, yielding a total of four matrices of\nsize $2^{n-1} \\times 2^{n-1}$. Figure \\ref{fig:2dwt}\ngives a graphical depiction of one iteration of the algorithm.\n\nWe initialize $LL_0$ to be the\noriginal image matrix, and we terminate once the length of the rows or columns\nis less than the length of the filters. We end up with a list of wavelet\ncoefficients, starting with the final approximation frame $LL_n$ followed by\ncollections of detail coefficients $(LH_n,HL_n,HH_n)$, $(LH_{n-1},HL_{n-1},HH_{n-1})$,\n$\\ldots$, $(LH_1,HL_1,HH_1)$. Note that at each iteration we operate first on the\nrows (convolve with the filter, then downsample), and the we operate on the columns\nof the resulting matrices (\\emph{not} the original matrix). The size of the output\nmatrices have been reduced by a factor of two in both dimensions. As with the\none-dimensional algorithm, to reconstruct the image from the coefficients, we simply\nreverse the process by upsampling, convolving, and adding (first the columns, then\nthe rows). We provide sample code for one iteration of the transform and the inverse.\n\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy.signal import fftconvolve\n\n# given the current approximation frame image, and the filters lo_d and hi_d\n# initialize empty arrays\ntemp = np.zeros([image.shape[0], image.shape[1]/2])\nLL = np.zeros([image.shape[0]/2, image.shape[1]/2])\nLH = np.zeros([image.shape[0]/2, image.shape[1]/2])\nHL = np.zeros([image.shape[0]/2, image.shape[1]/2])\nHH = np.zeros([image.shape[0]/2, image.shape[1]/2])\n\n# low-pass filtering along the rows\nfor i in xrange(image.shape[0]):\n\ttemp[i] = fftconvolve(image[i], lo_d, mode='full')[1::2]\n\n# low and hi-pass filtering along the columns\nfor i in xrange(image.shape[1]/2):\n\tLL[:,i] = fftconvolve(temp[:,i],lo_d,mode='full')[1::2]\n    LH[:,i] = fftconvolve(temp[:,i],hi_d,mode='full')[1::2]\n\n# hi-pass filtering along the rows\nfor i in xrange(image.shape[0]):\n\ttemp[i] = fftconvolve(image[i], hi_d, mode='full')[1::2]\n\n# low and hi-pass filtering along the columns\nfor i in xrange(image.shape[1]/2):\n\tHL[:,i] = fftconvolve(temp[:,i],lo_d,mode='full')[1::2]\n    HH[:,i] = fftconvolve(temp[:,i],hi_d,mode='full')[1::2]\n\\end{lstlisting}\nAt this point, the variables \\li{LL, LH, HL, HH} contain the current level of wavelet coefficients.\nYou would then store \\li{(LH, HL, HH)} in a list, and feed \\li{LL} back into the same\nblock of code (with \\li{LL} replacing \\li{image}) to obtain the next level of coefficients.\n\nNow, given a current level of wavelet coefficients, here is the code to recover the previous\napproximation frame, which is the crucial step in the inverse transform.\n\\begin{lstlisting}\n# given current coefficients LL, LH, HL, HH\n# initialize temporary arrays\nn = LL.shape[0]\ntemp1 = np.zeros([2*n,n])\ntemp2 = np.zeros([2*n,n])\nup1 = np.zeros(2*n)\nup2 = np.zeros(2*n)\n\n# upsample and filter the columns of the coefficient arrays\nfor i in xrange(n):\n\tup1[1::2] = HH[:,i]\n\tup2[1::2] = HL[:,i]\n\ttemp1[:,i] = fftconvolve(up1, hi_r)[1:] + fftconvolve(up2, lo_r)[1:]\n\tup1[1::2] = LH[:,i]\n\tup2[1::2] = LL[:,i]\t\t\n\ttemp2[:,i] = fftconvolve(up1, hi_r)[1:] + fftconvolve(up2, lo_r)[1:]\n\n# upsample and filter the rows, then add results together\nresult = sp.zeros([2*n,2*n])\nfor i in xrange(2*n):\n\tup1[1::2] = temp1[i]\n\tup2[1::2] = temp2[i]\n\tresult[i] = fftconvolve(up1, hi_r)[1:] + fftconvolve(up2, lo_r)[1:]\n\\end{lstlisting}\n\n\\begin{problem}\nBuild off of the sample code to fully implement the two-dimensional discrete\nwavelet transform as described above.\nAs before, the input to your function should consist of\nthree arrays: the input image, the low-pass filter, and the high-pass filter.\nYou should return a list of the following form: $$[LL_n,(LH_n,HL_n,HH_n), \\ldots\n,(LH_1,HL_1,HH_1)].$$\n\nThe inverse wavelet transform function should take as input a list\nof that same form, as well as the reconstruction low-pass and high-pass filters,\nand should return the reconstructed image.\n\\end{problem}\n\\end{comment}\n\n\\begin{comment}\nThis section could be cool, but it's not hashed out very well yet.\n\\section*{Edge Detection}\nIt is often useful to identify the edges of objects and figures\nrepresented in images. The edge information can be used to classify images\nand group them with other similar images (this is part of a field called\n\\textit{computer vision}), to segment the image into component parts, to\nsharpen blurry images, to filter out unnecessary details of the image,\nand so forth. Of course, our human eyes are very adept at recognizing edges,\nbut enabling a computer to do the same is much more difficult. An edge can\nbe thought of as a discontinuity in the image or a region of high contrast\nin either color or brightness. We can therefore leverage the high-frequency\ndetail coefficients of the wavelet transform to detect the edges. Execute the\nfollowing code:\n\\begin{lstlisting}\n>>> # calculate one level of wavelet coefficients\n>>> coeffs = pywt.wavedec2(lena,'haar', level=1)\n\\end{lstlisting}\n\nNote that the approximation coefficients are very close to the original\nimage, while the detail coefficients are much more sparse, and roughly\ncapture the edges in the image. In particular, the upper right coefficients\nemphasize the vertical edges, the lower left coefficients emphasize the\nhorizontal edges, and the lower right coefficients emphasize the diagonal\nedges.\n\n\\begin{problem}\nNow zero out the approximation coefficients and use your inverse DWT\nfunction to recreate the image. Plot its absolute value. This image is\na fairly good representation of the edges. If we add this to the original\nimage, we can increase the contrast at the edges (that is, make the dark\nside darker, and the light side lighter). Do this, and plot the original\nimage side-by-side with the sharpened image. What do you notice? There\nare many image-sharpening techniques, and those based on wavelets\nare more sophisticated than what we have done here, but this gives the\nbasic idea.\n\\end{problem}\nthe above section needs work, or maybe should be taken out completely.\n\\end{comment}\n\n\\begin{comment}\nThis section is good, but there's just not room for it in this lab if we\nwant a fairly complete section on image compression.\n\\section*{Noise Removal}\nNoise in an image can be defined as unwanted visual artifacts that\nobscure the true image. Images can acquire noise from a variety of\nsources, including the camera, transmission, and image processing\nalgorithms. Noise can be completely random and incoherent (as in\nFigure \\ref{fig:incoherent}), or it can be coherent and display\nvisual patterns (Figure \\ref{fig:coherent}). In this section, we will\nfocus on reducing a particular type of random noise in images, called\n\\textit{Gaussian white noise}.\n\n\\begin{figure}[t]\n\\minipage{0.49\\textwidth}\n    \\includegraphics[width=\\linewidth]{phantom_random.pdf}\n    \\caption{The Phantom image with incoherent noise}\n    \\label{fig:incoherent}\n\\endminipage\\hfill\n\\minipage{0.49\\textwidth}\n    \\includegraphics[width=\\linewidth]{phantom_coherent.pdf}\n    \\caption{The Phantom image with coherent noise}\n    \\label{fig:coherent}\n\\endminipage\n\\end{figure}\n\nAn image that is distorted by Gaussian white noise is one in which\nevery pixel has been perturbed by a small amount, such that the\nperturbations are normally distributed. We can easily add such noise\nto an image using the \\li{np.random.normal} function.\n\n\\begin{lstlisting}\n>>> noisyLena = lena + np.random.normal(scale=20, size=lena.shape)\n>>> plt.imshow(noisyLena, cmap=plt.cm.Greys_r)\n>>> plt.show()\n\\end{lstlisting}\n\nGiven an image with Gaussian white noise, how do we go about reducing\nthe noise level? Our approach will be based on the idea of thresholding.\nIt turns out that images are often sparse in the wavelet basis,\nparticularly in the high-frequency details. The Gaussian noise, however,\nis very high frequency, and thus its wavelet transform will be\nconcentrated in high-frequency wavelet coefficients (of magnitude\nroughly proportional to the variance of the noise). We can therefore\nreduce the noise while preserving the true image by shrinking the\ndetail coefficients via hard or soft thresholding.\n\nGiven a positive threshold value $\\tau$, hard thresholding sets\nevery wavelet coefficient whose magnitude is less than $\\tau$ to\nzero, while leaving the remaining coefficients untouched. Soft\nthresholding also zeros out all coefficients of magnitude less than\n$\\tau$, but in addition maps every other coefficient $\\beta$ to\n$\\beta - \\tau$ if $\\beta > 0$ or $\\beta + \\tau$ if $\\beta < 0$.\n\nImplementing these simple thresholding algorithms in Python is\nstraight-forward, but PyWavelets already provides this functionality.\nThe following code gives an example.\n\n\\begin{lstlisting}\n>>> A = np.arange(-4,5).reshape(3,3)\n>>> A\narray([[-4, -3, -2],\n       [-1,  0,  1],\n       [ 2,  3,  4]])\n>>> pywt.thresholding.hard(A,1.5)\narray([[-4, -3, -2],\n       [ 0,  0,  0],\n       [ 2,  3,  4]])\n>>> pywt.thresholding.soft(A,1.5)\narray([[-2.5, -1.5, -0.5],\n       [ 0. ,  0. ,  0. ],\n       [ 0.5,  1.5,  2.5]])\n\\end{lstlisting}\n\nOnce the coefficients have been thresholded, we take the inverse\nwavelet transform to recover the denoised image. This can be done\nby calling the \\li{waverec2} function, providing the list of Wavelet\ncoefficients as well as the name of the desired Wavelet as arguments.\nThe threshold value is generally a function of the variance of the noise,\nand in real situations, we do not know what this variance is. In fact,\nnoise variance estimation in images is a research area in its own\nright, but this goes beyond the scope of this lab, and so we will\nassume that we already have a decent estimate of the variance.\n\n\\begin{figure}[t]\n    \\includegraphics[width=\\linewidth]{denoise.pdf}\n    \\caption{Noisy Lena (left), denoised using hard thresholding (center),\n    and denoised using soft thresholding (right).}\n    \\label{fig:denoise}\n\\end{figure}\n\n\\begin{problem}\nWrite functions that implement the hard and soft thresholding\ntechniques. The inputs should be a list of wavelet coefficients\nin the usual form, as well as the threshold value. The output\nshould be the thresholded wavelet coefficients (also in\nthe usual form). Remember that we only want to threshold the\ndetail coefficients, and not the approximation coefficients.\nYou should therefore leave the first entry of the input\ncoefficient list unchanged.\n\\end{problem}\n\n\\begin{problem}\nCreate a noisy version of the Lena image by adding Gaussian\nwhite noise of mean 0 and standard deviation $\\sigma = 20$ (i.e. \\li{scale=20}).\nCompute four levels of the wavelet coefficients using the Daubechies 4 Wavelet,\nand input these into your\nthresholding functions (with $\\tau = 3\\sigma$ for the hard threshold,\nand $\\tau = 3\\sigma/2$ for the soft threshold). Reconstruct the\ntwo denoised images, and then plot these together alongside the\nnoisy image. Your output should match Figure \\ref{fig:denoise}.\n\nWhat do you notice? How does lowering or raising the\nthreshold affect the reconstructed images? What happens if you use\na different Wavelet?\n\\end{problem}\n\\end{comment}", "meta": {"hexsha": "9dbca621a639508861cfe72c3123d580de51f453", "size": 82345, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/Wavelets/Haar.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Labs/Wavelets/Haar.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/Wavelets/Haar.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 41.7782851344, "max_line_length": 148, "alphanum_fraction": 0.712927318, "num_tokens": 22639, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.8705972566572503, "lm_q1q2_score": 0.7076800648291756}}
{"text": "\\lab{Application}{Nearest Neighbor Search}{Nearest Neighbor Search}\n\\label{Ch:NNS}\n\n\\objective{This section teaches about branch and bound and the curse of dimensionality using the nearest neighor search problem.}\n\n\\section*{The Nearest Neighbor Search Problem}\n\nYou move into a city that has several post offices. You want to know which one is the closest. This problem is  known as the nearest neighbor search problem or the post-office problem. The general case is you have data and then you a new point and you want to know which of the data the new point is closest to.\n\nThis has many applications. Some include computer vision, pattern recognition, internet markerting and data compression.\n\nThe naive way to solve this problem is to check the distance of all the data against the point.\n\n\\begin{problem}\nWrite a function that solves the nearest neighbor search problem by exuastively checking all the distances. The function should take in the set of points that is the data and a single point. The output should be the distance to the closest data point and the index of that point. Your function should be able to take in data in an arbitrary dimension.\n\\end{problem}\n\nThe complexity of this algorthim is $O(kn)$. Where  is the $k$ number of dimensions and $n$ is the number of data points.\n\n\\section*{K-D Trees}\n\nA faster way to solve this problem is to build a k-d tree and search the k-d tree for the nearest neighbor. \n\nA k-d tree is a binary tree where the nodes to the left of parent node have a lower value in the i-th dimension and the nodes to the right of the parent node have a greater value in the i-th dimension. Which dimension you split the nodes alternates at different levels. In the $3$ dimensional case the root node is divided in the $x$ dimension, children in the $y$ dimension, grandchildren in the $z$ dimension, and the great-grandchildren in the $x$ dimension and so on. Each node stores its location, left child and right child. This requires sorting at each level so the complexity is $O(nlog^2(n))$ But we only need to build the k-d tree once and after that we can query it as many times as we want.\n\nIncluded is a function that takes in a set of data and builds k-d tree. The leaf nodes' children are  python's ``None\" object.\n\nThe search of the tree is done recuersively. We will call the node that we are on the parent node. We first see if the distance between the parent node at the less is current best. If so, we update it. We then compare the values in the i-th dimension of the point and the parent. If it is point's value is less than the parent we recursively go down the left child, greater, the right child. Then we have to check if the hypersphere around the point with radius being the current best distance crosses the dividing hyperplane created by the parent. If the point's value is less than the parent, we do this by checking to see if the value in the i-th dimension plus the current best distance is greater than the parent's value in the i-th dimension. If the point's value is greater than the parent, we do this by checking to see if the value n the i-th dimension minus the current best distance is less than the parent's value in the i-th dimension. If this be the case, we recursively go down the other child as well.\n\n\\begin{problem}\nWrite a function that solves the nearest neighbor search problem by searching through a k-d tree. The function should take in k-d tree and a single point. The output should be the distance to the closest data point and the coordinates of that point. \n\\end{problem}\n\n\\begin{problem}\nTime both algorithms you have created with the number of data points being $10,000-100,000$ every mutiple of $10,000$ with $4$ dimensions. TIme only the searching of the k-d tree not the building of it. Plot both times on the same plot. How do the two algorithms compare?\n\\end{problem}\n\nThe complexity of this algorthim is $O(klog(n))$ in optimal time. Its worst case is $O(k*n^{1-\\frac{1}{k}})$ for reasons we will discuss in the next section.\n\n\\section*{Curse of Dimensionality}\n\nAs you increase the number of dimensions the number of times that you have to go down both branchs increases. You get to the point where you eliminate very few points by using a k-d tree.\n\n\\begin{problem}\nTime both algorithms for the number of data points being $10,000-100,000$ every mutiple of $10,000$ with $20$ dimension. Plot both times on the same plot. Now how do the two algorithms compare?\n\\end{problem}\n\n\\begin{problem}\nTime scipy built function for searching a k-d tree for the number of dimensions points being $2-50$ with $20,000$ data points. Plot the time. What do you notice? ``from scipy.spatial import KDTree\" will import the built in k-d tree. Create the tree by ``tree = KDTree(data)\" and search it by ``tree.query(point)\".\n\\end{problem}\n\n\n", "meta": {"hexsha": "299b3f5973a3020fd1ae908ed315c21cb2fe4d5d", "size": 4825, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/NearestNeighbor/NearestNeighbor.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/NearestNeighbor/NearestNeighbor.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/NearestNeighbor/NearestNeighbor.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 91.0377358491, "max_line_length": 1017, "alphanum_fraction": 0.7743005181, "num_tokens": 1117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673133042216, "lm_q2_score": 0.870597270087091, "lm_q1q2_score": 0.7076800639056834}}
{"text": "\\section{Simplicial sets}\nIn order to discuss the simplicial model for classifying spaces of $G$-bundles,\nwe will embark on a long digression on simplicial sets (which will last for\nthree sections). We begin with a brief review of some of the theory of\nsimplicial objects (see also Part \\ref{905}).\n\\subsection{Review}\nWe denote by $[n]$ the set $\\{0,1,\\cdots,n\\}$, viewed as a totally ordered set.\nDefine a category $\\Deltab$ whose objects are the sets $[n]$ for $n\\geq 0$,\nwith morphisms order preserving maps. There are maps $d^i:[n]\\to [n+1]$ given\nby omitting $i$ (called coface maps) and codegeneracy maps $s^i:[n]\\to[n-1]$\nthat's the surjection which repeats $i$. As discussed in Exercise\n\\ref{simplicialidentities}, any order-preserving map can be written as the\ncomposite of these maps, and there are famous relations that these things\nsatisfy. They generate the category $\\Deltab$.\n\nThere is a functor $\\Delta:\\Deltab\\to\\Top$ defined by sending\n$[n]\\mapsto\\Delta^n$, the standard $n$-simplex. To see that this is a functor,\nwe need to show that maps $\\phi:[n]\\to [m]$ induce maps $\\Delta^n\\to \\Delta^m$.\nThe vertices of $\\Delta^n$ are indexed by elements of $[n]$, so we may just\nextend $\\phi$ as an affine map to a map $\\Delta^n\\to\\Delta^m$.\n\nLet $X$ be a space. The set of singular $n$-simplices $\\Top(\\Delta^n,X)$\ndefines the singular simplicial set $\\Sin:\\Deltab^{op}\\to\\Set$.\n\\begin{definition}\n    Let $\\cc$ be a category. Denote by $s\\cc$ the category of simplicial\n    objects in $\\cc$, i.e., the category $\\Fun(\\Deltab^{op},\\cc)$. We write\n    $X_n = X([n])$, called the $n$-simplices.\n\\end{definition}\nExplicitly, this gives an object $X_n\\in\\cc$ for every $n\\geq 0$, as well as\nmaps $d_i:X_{n+1}\\to X_n$ and $s_i:X_{n-1}\\to X_n$ given by the face and\ndegeneracy maps.\n\\begin{example}\n    Suppose $\\cc$ is a small category, for instance, a group. Notice that $[n]$\n    is a small category, with:\n    $$[n](i,j) = \\begin{cases}\n\t\\{\\leq\\} & \\text{if }i\\leq j\\\\\n\t\\emptyset & \\text{else}.\n    \\end{cases}$$\n    We are therefore entitled to think about $\\Fun([n],\\cc)$. This begets a\n    simplicial set $N\\cc$, called the \\emph{nerve of $\\cc$}, whose\n    $n$-simplices are $(N\\cc)_n = \\Fun([n],\\cc)$. Explicitly, an $n$-simplex in\n    the nerve is $(n+1)$-objects in $\\cc$ (possibly with repetitions) and a\n    chain of $n$ composable morphisms. The face maps are given by composition\n    (or truncation, at the end of the chain of morphisms). The degeneracy maps\n    just compose with the identity at that vertex.\n    \n    For example, if $G$ is a group regarded as a category, then $(NG)_n = G^n$.\n\\end{example}\n\\subsection{Realization}\nThe functor $\\Sin$ transported us from spaces to simplicial sets. Milnor described a way to go the other way. \n\nLet $X$ be a simplicial set. We define the realization $|X|$ as follows:\n$$|X| = \\left(\\coprod_{n\\geq 0}\\Delta^n\\times X_n\\right)/\\sim,$$\nwhere $\\sim$ is the equivalence relation defined as:\n$$\n\\Delta^m\\times X_m\\ni (v,\\phi^\\ast x)\\sim (\\phi_\\ast v, x)\\in \\Delta^n\\times X\n$$\nfor all maps $\\phi:[m]\\to [n]$ where $v\\in \\Delta^m$ and $x\\in X_n$.\n\\begin{example}\n    The equivalence relation is telling us to glue together simplices as\n    dictated by the simplicial structure on $X$. To see this in action, let us\n    look at $\\phi^\\ast = d_i:X_{n+1}\\to X_n$ and $\\phi_\\ast = d^i:\\Delta^n\\to\n    \\Delta^{n+1}$. In this case, the equivalence relation then says that\n    $(v,d_ix)\\in \\Delta^n\\times X_n$ is equivalent to $(d^i v, x)\\in\n    \\Delta^{n+1}\\times X_{n+1}$. In other words: the $n$-simplex indexed by\n    $d_i x$ is identified with the $i$th face of the $(n+1)$-simplex indexed by\n    $x$.\n\\end{example}\nThere's a similar picture for the degeneracies $s^i$, where the equivalence\nrelation dictates that every element of the form $(v,s_ix)$ is already\nrepresented by a simplex of lower dimension.\n\\begin{example}\n    Let $n\\geq 0$, and consider the simplicial set $\\Hom_{\\Deltab}(-,[n])$.\n    This is called the ``simplicial $n$-simplex'', and is commonly denoted\n    $\\Deltab^n$ for good reason: we have a homeomorphism $|\\Deltab^n| \\simeq\n    \\Delta^n$. It is a good exercise to prove this using the explicit\n    definition.\n%    $$\n%    |\\Deltab^n| = \\coprod_{\\text{nondegenerate $k$-simplices in\n    %    }\\Deltab^n}\\Delta^k/\\sim\n%    $$\n%    Suppose $n=3$; what are the injective maps $[k]\\to [n]$? First $k\\leq 3$. I have the identity.\n%    Injective maps $[2]\\to [3]$ just omit one vertex, so I can put in a face. There are four of them.\n%    We can do the same thing with $1$-simplices.\n%    Those are the edges, and same thing for $0$-simplices.\n\\end{example}\nFor any simplicial set $X$, the realization $|X|$ is naturally a CW-complex,\nwith\n$$\\mathrm{sk}_n|X| = \\left(\\coprod_{k\\leq n}\\Delta^k\\times X_k\\right)/\\sim.$$\nThe face maps give the attaching maps; for more details, see \\cite[Proposition\nI.2.3]{goerss-jardine}. This is a very combinatorial way to produce\nCW-complexes.\n\nThe geometric realization functor and the singular simplicial set give two\nfunctors going back and forth between spaces and simplicial sets. It is natural\nto ask: do they form an adjoint pair? The answer is yes:\n$$\n\\begin{tikzcd}\n    s\\Set\\ar[r,bend left,\"|-|\",\"\"{name=A, below}] & \\Top\\ar[l,bend\n    left,\"\\Sin\",\"\"{name=B,above}] \\ar[from=A, to=B, symbol=\\dashv]\n\\end{tikzcd}\n$$\nFor instance, let $X$ be a space. There is a continuous map\n$\\Delta^n\\times\\Sin_n(X)\\to X$ given by $(v,\\sigma)\\mapsto \\sigma(v)$. The\nequivalence relation defining $|\\Sin(X)|$ says that the map factors through the\ndotted map in the following diagram:\n\\begin{equation*}\n    \\xymatrix{\n\t|\\Sin(X)|\\ar@{-->}[r] & X\\\\\n\t\\coprod\\Delta^n\\times\\Sin_n(X)\\ar[ur]\\ar@{->>}[u] &\n    }\n\\end{equation*}\nThe resulting map is the counit of the adjunction.\n\nLikewise, we can write down the unit of the adjunction: if $K\\in s\\Set$, the\nmap $K\\to\\Sin|K|$ sends $x\\in K_n$ to the map $\\Delta^n\\to |K|$ defined via\n$v\\mapsto [(v,x)]$.\n\nThis is the beginning of a long philosophy in semi-classical homotopy theory,\nof taking any homotopy-theoretic question and reformulating it in simplicial\nsets. For instance, one can define homotopy groups in simplicial sets. For more\ndetails, see \\cite{goerss-jardine}.\n\nWe will close this section with a definition that we will discuss in the next\nsection. Let $\\cc$ be a category. From our discussion above, we conclude that\nthe realization $|N\\cc|$ of its nerve is a CW-complex, called the\n\\emph{classifying space} $B\\cc$ of $\\cc$; the relation to the notion of\nclassifying space introduced in \\S \\ref{grassmannmodel} will be elucidated upon\nin a later section.\n%That's one thing to say.\n%The other thing to leave you with is this.\n%This construction of realization -- exactly the same formula makes sense more generally, even if I was considering simplicial \\emph{spaces}.\n%When I take the product, I really mean the product of spaces (in compactly generated spaces).\n", "meta": {"hexsha": "2b56932a27b439cffd9fe4d33b868998a0d36c0e", "size": 6932, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-56-ssets.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "906/lec-56-ssets.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "906/lec-56-ssets.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 51.7313432836, "max_line_length": 141, "alphanum_fraction": 0.6984997115, "num_tokens": 2205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511579973932, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7075422517665254}}
{"text": "% !TEX root = ../main.tex\n% chktex-file 21\n% chktex-file 46\n\\vspace{-0.5em}%\n\\section{Graph Coarsening}%\n\\label{sec:coarse}\n\\vspace{-0.5em}%\n\nNext we will see how the size of a graph $G$ can be reduced via \\textit{graph coarsening}.\nThe resulting coarsened graph $G_c$ should ideally be structurally similar to $G$, i.e.\\  it should have a similar spectrum.\nIn this section we will first define the class of coarsening operators $C$ and give an intuition on how they change the shape of a graph.\nThen we will describe a randomized algorithm to compute such a coarsening.\n\n\\subsection{Definition of the Coarsening Operator}%\n\\label{sec:coarse:formal}\n\nThe core idea of graph coarsening is to replace clusters of vertices in the original graph $G$ by single vertices in the coarsened graph $G_c$.\nFormally this means that the original vertices $\\mathcal{V} = \\{ v_1, \\dots, v_N \\}$ are mapped to a smaller vertex set $\\mathcal{V}_c = \\{ v'_1, \\dots, v'_n \\}$ via a surjective mapping $\\varphi: \\mathcal{V} \\to \\mathcal{V}_c$.\nThe original edges $(v_i, v_j) \\in \\mathcal{E}$ are mapped to $(\\varphi(v_i), \\varphi(v_j))$, resulting in a reduced edge set $\\mathcal{E}_c$ that contains every edge for which $\\varphi(v_i) \\neq \\varphi(v_j)$.\n\\Cref{fig:coarse:example:original,fig:coarse:example:coarsened} show an exemplary graph coarsening.\nTo reverse the coarsening mapping, we define $\\varphi^{-1}: \\mathcal{V}_c \\to \\mathcal{P}(\\mathcal{V})$ as the mapping from a coarsened vertex to the set of original vertices it represents.\n\\begin{figure}[ht]\n\t\\centering\n\t\\begin{subfigure}{0.33\\textwidth}\n\t\t\\includegraphics[width=0.9\\linewidth]{gfx/coarse/example/original.pdf}\n\t\t\\caption{Original $G$}\\label{fig:coarse:example:original}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{0.33\\textwidth}\n\t\t\\includegraphics[width=0.9\\linewidth]{gfx/coarse/example/coarsened.pdf}\n\t\t\\caption{Coarsened $G_c$}\\label{fig:coarse:example:coarsened}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{0.33\\textwidth}\n\t\t\\includegraphics[width=0.9\\linewidth]{gfx/coarse/example/reexpanded.pdf}\n\t\t\\caption{Approximated $\\widetilde{G}$}\\label{fig:coarse:example:reexpanded}\n\t\\end{subfigure}\n\t\\caption{%\n\t\tExample showing the effect of coarsening $G$ when merging the blue vertices into a single vertex.\n\t\tThe graph $\\widetilde{G}$ on the right shows the result of re-expanding $G_c$.\n\t}\\label{fig:coarse:example}\n\\end{figure}\n\nIn the last section we saw how graphs can be described via their Laplacian $L$.\nSince our goal is to analyze the effects of coarsening on the overall characteristics of a graph, we will describe a coarsening $\\varphi$ as an operation that acts directly on $L$ in the rest of this paper.\nThe so called \\textit{coarsening matrix} $C \\in \\mathbb{R}^{n \\times N}$ is essentially a matrix representing $\\varphi$:\n\\begin{align}\n\t\\varphi(v_i) = v'_j \\Leftrightarrow C b_i = n_j b'_j\\quad\n\t& \\text{with the standard basis vectors } b_i \\in \\mathbb{R}^N,\\, b'_j \\in \\mathbb{R}^n\\\\\n\t& \\text{and normalization factor\\footnotemark\\ } n_j := {\\left|\\varphi^{-1}(v'_j)\\right|}^{-\\frac{1}{2}} \\nonumber\n\\end{align}\n\\footnotetext{%\n\t$n_j$ is required for technical reasons.\n\tIt normalizes $\\Pi = C^{\\top} C$ so that it is a projector, i.e.\\  so it has eigenvalues in $\\{ 0, 1 \\}$.\n\tThis ensures that $G$ and $\\widetilde{G}$ have the same total weight.\n}%\nAnalogous to $\\varphi$, the coarsening matrix $C$ maps vertex basis vectors of $G$ to vertex basis vectors of $G_c$.\nBy linearity any signal $x \\in \\mathbb{R}^N$ on $G$ can thus be downsampled to a signal $x_c := C x \\in \\mathbb{R}^n$ on the coarsened graph $G_c$;\nthe signal strengths of merged vertices will simply be added up.\nSimilarly a downsampled signal $x_c$ can be upsampled again to an approximation $\\widetilde{x} \\in \\mathbb{R}^N$ of the original signal $x$.\nUpsampling uniformly distributes the signal strength of each $v'_j \\in \\mathcal{V}_c$ among $\\varphi^{-1}(v'_i)$, where the inverse $\\varphi^{-1}$ can be represented by $C^{\\top}$:\n\\begin{align*}\n\t\\widetilde{x} := C^{\\top} x_c = C^{\\top} C x = \\Pi x\\quad\\text{with the projector } \\Pi := C^{\\top} C\n\\end{align*}\n\nSince both the coarsening matrix $C$ and the Laplacian $L$ are operators acting on signals, we can combine them to define the \\textit{coarsened Laplacian} $L_c$ and also the \\textit{approximate Laplacian} $\\widetilde{L}$:\n\\begin{align*}\n\tL_c := C L C^{\\top}\\quad\\text{and}\\quad\\widetilde{L} := C^{\\top} L_c C = \\Pi L \\Pi\n\\end{align*}\n$L_c$ represents the Laplacian of the coarsened graph $G_c$\\footnote{%\n\t$L_c$ is actually not a proper combinatorial Laplacian, i.e.\\  its rows do not generally add up to $0$.\n\tTo fix this, $L_c$ could be normalized, which is however not necessary for our analysis.\n\tWe refer to \\citet[Sec.~2.1]{Loukas2018} for the details.\n}.\n$\\widetilde{L}$ represents the Laplacian of the graph $\\widetilde{G}$, which is the result of re-expanding the coarsened graph $G_c$.\nDuring re-expansion, every vertex $v'_i \\in \\mathcal{V}_c$ is replaced by the complete graph on the vertex set $\\varphi^{-1}(v'_i)$.\nThe neighbors of each replaced $v'_i$ are connected to the vertices that replace it.\n\\Cref{fig:coarse:example:reexpanded} shows how a graph might look like after such a re-expansion.\n\n\\vspace{-0.5em}%\n\\subsection{The Randomized Edge Contraction Algorithm}%\n\\label{sec:coarse:rec}\n\\vspace{-0.5em}%\n\nNow that we have defined the coarsening operator, we will look at a simple randomized algorithm which finds a coarsened graph $G_c$ that is spectrally similar to some given graph $G$.\nThe so called \\textit{Randomized Edge Contraction}~(REC)~\\cite{Loukas2018} algorithm is a variant of the well-known greedy algorithm for maximal matching generation.\nIt contracts random edges until the vertex count has been reduced by a ratio $r$ or until there are no more neighboring pairs of unmerged vertices.\nThe contracted edges are chosen with a probability proportional to their weight.\n\\begin{figure}[H]\n\t\\setlength{\\intextsep}{0pt}\n\t\\begin{minipage}{0.6\\linewidth}\n\t\t\\begin{algorithm}[H]\n\t\t\t\\caption{Randomized Edge Contraction}\\label{algo:coarse:rec}\n\t\t\t\\begin{algorithmic}[1]\n\t\t\t\t\\Function{REC}{$G = (\\mathcal{V}, \\mathcal{E}, W), r \\in [0, \\frac{1}{2}]$}\n\t\t\t\t\t\\State{$\\mathcal{C} \\leftarrow \\mathcal{E}$, $G_c \\leftarrow G$}\n\t\t\t\t\t\\State{$Z \\leftarrow \\sum_{e_{i j} \\in \\mathcal{E}} w_{i j}$}\n\t\t\t\t\t\\While{$|\\mathcal{C}| > 0$ and $\\frac{|\\mathcal{V}_c|}{|\\mathcal{V}|} > 1 - r$}\n\t\t\t\t\t\t\\State{Select some $e_{i j} \\in \\mathcal{C}$ with prob.\\  $p_{i j} = \\frac{w_{i j}}{Z}$.}\n\t\t\t\t\t\t\\State{$\\mathcal{C} \\leftarrow \\mathcal{C} \\setminus \\mathcal{N}_{i j}$}\n\t\t\t\t\t\t\\State{$Z \\leftarrow \\sum_{e_{i j} \\in \\mathcal{C}} w_{i j}$}\n\t\t\t\t\t\t\\State{$G_c \\leftarrow \\mathit{contract}(G_c, e_{i j})$}\n\t\t\t\t\t\\EndWhile{}\n\t\t\t\t\t\\State{\\Return{$G_c$}}\n\t\t\t\t\\EndFunction{}\n\t\t\t\\end{algorithmic}\n\t\t\\end{algorithm}\n\t\\end{minipage}%\n\t\\begin{minipage}{0.4\\linewidth}\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.75\\linewidth]{gfx/coarse/rec.pdf}\n\t\t\t\\caption{$\\mathit{contract}(G_c, e_{i j})$.}\\label{fig:coarse:rec}\n\t\t\\end{figure}\n\t\\end{minipage}\n\\end{figure}\n\nWe define the neighborhood $\\mathcal{N}_{i j}$ as the set of incident edges of $e_{i j}$, including $e_{i j}$ itself;\nthis is shown as the red and blue edges in \\cref{fig:coarse:rec}.\nREC only merges vertices that have not been merged with some other vertex yet.\nThus the reduction ratio $r = \\frac{N - n}{N}$ is at most $\\frac{1}{2}$, i.e.\\  $|\\mathcal{V}_c| \\geq \\frac{1}{2} |\\mathcal{V}|$.\nIf the node count needs to be further reduced, REC has to be applied multiple times.\n", "meta": {"hexsha": "81a68662b721ad90cb3d8cb73eb605d0b733f68a", "size": 7546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/content/chapter-coarsening.tex", "max_stars_repo_name": "Cortys/ml-seminar", "max_stars_repo_head_hexsha": "cfd3a0cb73ca54d90619159df058f021ac9c7101", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/content/chapter-coarsening.tex", "max_issues_repo_name": "Cortys/ml-seminar", "max_issues_repo_head_hexsha": "cfd3a0cb73ca54d90619159df058f021ac9c7101", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/content/chapter-coarsening.tex", "max_forks_repo_name": "Cortys/ml-seminar", "max_forks_repo_head_hexsha": "cfd3a0cb73ca54d90619159df058f021ac9c7101", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.3636363636, "max_line_length": 228, "alphanum_fraction": 0.7150808375, "num_tokens": 2476, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511579973932, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7075422499395131}}
{"text": "\\section{Small imprecisions can break algorithms}\nIn this section, we explore ways in which small imprecisions can modify the behavior of an algorithm in ways other than just causing further imprecisions.\n\n\\subsection{When making binary decisions}\nThe first scenario we will explore is when we have to make clear-cut decisions, such as deciding if two objects touch.\n\n{\n    \\newcommand{\\eCutoff}{\\epsilon_{\\mathrm{cutoff}}}\n    \\newcommand{\\eError}{\\epsilon_{\\mathrm{error}}}\n    \\newcommand{\\eChance}{\\epsilon_{\\mathrm{chance}}}\n    Let's say we have a line $l$ and a point $P$ computed imprecisely, and we want to figure out if the point lies on the line. Obviously, we cannot simply check if the point we have computed lies on the line, as it might be just slightly off due to imprecision. So the usual approach is to compute the distance from $P$ to $l$ and then figure out if that distance is less than some small value like $\\eCutoff=10^{-9}$.\n\n    While this approach tends to works pretty well in practice, to be sure that this solution works in every case and choose $\\eCutoff$ properly,\\footnote{And motivated problem setters \\emph{do} tend to find the worst cases.} we need to know two things. First, we need to know $\\eError$, the biggest imprecision that we might make while computing the distance. Secondly, and more critically, we need to know $\\eChance$, the smallest distance that point $P$ might be from $l$ while not being on it, in other words, the closest distance that it might be from $l$ ``by coincidence''.\n\n    Only once we have found those two values, and made sure that $\\eError < \\eChance$, can we then choose the value of $\\eCutoff$ within $[\\eError,\\eChance)$.\\footnote{In practice you should try to choose $\\eCutoff$ so that there is a factor of safety on both sides, in case you made mistakes while computing $\\eError$ or $\\eChance$.} Indeed, if $\\eCutoff < \\eError$, there is a risk that $P$ is on $l$ but we say it is not, while if $\\eCutoff \\geq \\eChance$ there is a risk that $P$ is not on $l$ but we say it is.\n\n    Even though $\\eError$ can be easily found with some basic knowledge of floating-point arithmetic and a few multiplications (see next section), finding $\\eChance$ is often very difficult. It depends directly on which geometric operations were done to find $P$ (intersections, tangents, etc.), and in most cases where $\\eChance$ can be estimated, it is in fact possible to make the comparison entirely with integers, which is of course the preferred solution.\n}\n\n\n\\subsection{By violating basic assumptions}\nMany algorithms rely on basic geometric axioms in order to provide their results, even though those assumptions are not always easy to track down. This is especially the case for incremental algorithms, like algorithms for building convex hulls. And when those assumptions are violated by using floating-point numbers, this can make algorithms break down in big ways.\n\nProblems of this type typically happen in situation when points are very close together, or are nearly collinear/coplanar. The ways to solve the problem depend a lot on what the algorithm, but tricks like eliminating points that are too close together, or adding random noise to the coordinates to avoid collinearity/coplanarity can be very useful.\n\nFor concrete examples of robustness problems and a look into the weird small-scale behavior of some geometric functions, see \\cite{classroom-robustness}.\n", "meta": {"hexsha": "7877ce88cc31c62eb67e12ac5f3eeaf0e8040902", "size": 3433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/precision/small-break.tex", "max_stars_repo_name": "cbarnson/UVa", "max_stars_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_stars_repo_licenses": ["Unlicense", "MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-07T17:00:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-05T02:08:35.000Z", "max_issues_repo_path": "archives/codelibraries/cp-geo-master/precision/small-break.tex", "max_issues_repo_name": "cbarnson/UVa", "max_issues_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_issues_repo_licenses": ["Unlicense", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "archives/codelibraries/cp-geo-master/precision/small-break.tex", "max_forks_repo_name": "cbarnson/UVa", "max_forks_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_forks_repo_licenses": ["Unlicense", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 127.1481481481, "max_line_length": 580, "alphanum_fraction": 0.7719196038, "num_tokens": 798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.8558511506439707, "lm_q1q2_score": 0.7075422475143766}}
{"text": "\t%to make section start on odd page\n\t\\newpage\n\t\\thispagestyle{empty}\n\t\\mbox{}\n\t\\section{Numerical Methods/Analysis}\n\t\n\t\\lettrine[lines=4]{\\color{BrickRed}T}he numerical analysis is a mathematical discipline. It is interested in both theoretical foundations as the implementation methods to resolve by purely numerical calculations and empirical approach, mathematical analysis problems.\\\\\n\t\n\\textbf{Definition (\\#\\mydef):} \"\\NewTerm{Numerical Methods/Analysis}\\index{Numerical Methods/Analysis}\" is the study of algorithms or empirical scientific methods for solving or analysing mathematical continuous or discrete problems. This means that it mainly deals to respond numerically to real or complex variables questions like numerical linear algebra over the real or complex fields, looking for numerical solutions of differential equations and other problems occurring in the physical sciences or financial/statistical engineering.\n\nSome continuous mathematical problems can be solved exactly by an algorithm. These algorithms are then named \"\\NewTerm{direct methods}\\index{direct methods}\". Examples are the elimination of Gauss-Jordan for solving a system of linear equations or the simplex algorithm of linear programming (see further below). However, for some problems no direct method are known (and is even proved that for a class of problems known as \"NP complete\" - see further below - there is no direct calculation with finished algorithm in a polynomial time). In such cases, it is sometimes possible to use an iterative method to attempt to determine an approximation of the solution. Such a method starts from a guessed value or roughly estimated one and finds successive approximations that should converge to the solution under certain conditions. Even when a direct method exists, however, an iterative method may be preferable because it is often more effective and often more stable (in particular it allows most often to correct minor errors in intermediate calculations).\n\n\tThe use of numerical analysis has been greatly facilitated by modern computers. The Increasing availability and power of computers since the second half of the 20th century allowed the application of numerical methods in many scientific, technical and economic, often with revolutionary, accurate and significant effects.\n\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\fbox{\\includegraphics[scale=0.75]{img/computing/meaning_life.eps}}\n\t\\end{figure}\n\nIn numerical simulations of physical systems (multi-physics), the initial conditions are very important in solving differential equations (see the various sections of this book where chaotic effects appears). The fact that we can not know them exactly implies that the results of calculations can never be perfectly accurate (we know this fact very well for the weather forecasting which is the most glaring example known). This effect is a consequence of the results of fundamental physics (based on pure mathematics) which demonstrates that we can not perfectly know a system by performing measurements since it directly disrupts it (Heisenberg uncertainty principle as see in the section of Quantum Wave Theory) and these disturbances are the subject of Chaos Theory (classical or quantum).\n\nWith new computer tools available in the early 21st century, it became practical and exciting to know the numerical methods to have fun with some softwares or programming languages (OpenGL, 3D Studio Max, Blender, Maple, MATLAB™, Mathematica, Comsol, R, C++, Python, etc.) to simulate 2D or 3D physical systems graphically.\n\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\\textbf{R1.} Many numerical methods used in computer science are based on arguments which we have already been studied in other sections of this books. We won't come back on this methods.\\\\\n\t\n\t\\textbf{R2.} This section being on the boundary between engineering and Applied Mathematics, we decided to give some application examples of developed tools with various programming languages or software.\\\\\n\t\n\t\\textbf{R3.} Many of the techniques presented below are available as complete code in the C++ book \\cite{oliveira2015practical} that we strongly recommend to the reader.\n\t\\end{tcolorbox}\t\n\t\n\t\\textbf{Definitions (\\#\\mydef):}\n\t\\begin{enumerate}\n\t\t\\item[D1.]  An \"\\NewTerm{algorithm}\\index{algorithm}\" is a finite sequence of rules to be applied in a specific order in a finite number of data to arrive in a finite number of steps (including the amount, or conversely the execution time is defined by the term \"\\NewTerm{cost}\\index{algorithm cost}\") to a certain result, independently of the data type.\n\t\t\n\t\t\\item[D2.] The algorithms are integrated into computers through \"\\NewTerm{programs}\\index{programs}\" (including stuff like \"functions\", \"objects\", \"classes\", \"methods\", \"properties\", \"pointers\", etc. but this is more related to a programming language course) that are the realization (implementation) of an algorithm using a given language (on a given architecture). This is the implementation of the principle.\n\t\\end{enumerate}\n\t\n\tAxioms of programming (anecdotal):\n\n\t\\begin{enumerate}\n\t\t\\item[A1.] More we write code, more errors we will produce.\n\t\t\n\t\t\\item[A2.] There are no programs without possible errors (due to the program itself, to the underlying electronics or most often to the user himself).\n\t\\end{enumerate}\n\t\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\nBasically there a minimum steps to follow when developing an algorithm and its corresponding code. A very good process to follow is the one proposed by the ISO/CEI 9126 norm.\n\t\\end{tcolorbox}\t\n\n\tWhen developing a scientific algorithm, it may be interesting, rigorous and even an obligation in very high level cases to analyze the \"complexity\" of the algorithm. Without going too far, let's see what it is exactly:\n\t\n\t\\subsection{Computer Representation of Numbers}\n\t\n\tIn a Computer numbers are represented by binary digits 0 and 1.\n\tComputers employ binary arithmetic for performing operations on\n\tnumbers. Since it gets cumbersome to display large numbers in\n\tbinary form computers usually display them in hexadecimal or octal\n\tor decimal system. All of these number systems are positional\n\tsystems. In a positional system a number is represented by a set\n\tof symbols. Each of these symbols denote a particular value\n\tdepending on its position. The number of symbols  used in a\n\tpositional system depends on its 'base'. Let us now discuss about\n\tvarious positional number systems:\n\t\n\t\\subsubsection{Decimal System}\n\t\n\tThe decimal system uses 10 as its base value and employs ten\n\tsymbols 0 to 9 in representing numbers. Let us consider a decimal\n\tnumber 7402 consisting of four symbols 7,4,0,2. In terms of base\n\t10 it can be expressed as follows.\n\t$$7402=7\\times10^{3}+4\\times10^{2}+0\\times10^{1}+2\\times10^{0}$$\n\t\n\tSo each of the symbols from a set of symbols denoting a number is\n\tmultiplied with power of the base (10) depending on its position\n\tcounted from the right. The count always begins with 0.\n\t\n\tIn general a decimal number $d_{m}d_{m-1}...d_{1}d_{0}$ consisting\n\tof $(m+1)$ symbols can be expressed as:\n\t$$\n\td_{m}\\times10^{m}+d_{m-1}\\times10^{m-1}+....+d_{1}\\times10^{1}+d_{0}\\times10^{0}=\\sum\\limits_{i=0}^{m}\n\td_{i}10^{i}\n\t$$\n\twhere $0\\leq d_{i}\\leq 9$ with $i=0,1,\\ldots, m$\n\t\n\tSimilarly, a fractional part of a decimal number can be expressed\n\tas $\\sum\\limits_{i=1}^{m}d_{i}10^{-i}$\n\t\n\t\\subsubsection{Binary system} \n\tBinary system is the positional system \tconsisting of two symbols i.e. 0,1 and '2' as its base. Any binary number $d_{m}d_{m-1}...d_{1}d_{0}$ actually represents a decimal value given by\n\t$$\n\td_{m}2^{m}+d_{m-1}2^{m-1}+...+d_{0}2^{0}=\\sum\\limits_{i=0}^{m}\n\td_{i}2^{i}\n\t$$\n\twhere $d_{i}=0\\quad or\\quad 1, \\quad i=0,1,..m. $\n\t\n\tConsider the binary number 10101. The decimal equivalent of 10101\n\tis given by\n\t\\begin{eqnarray}\n\t(10101)_{2} & = & 1\\times 2^{4}+0\\times 2^{3}+1\\times\n\t2^{2}+0\\times 2^{1}+1\\times 2^{0} \\nonumber \\\\\n\t& = & 16+0+4+0+1=(21)_{10} \\nonumber\n\t\\end{eqnarray}\n\t\n\tHere are the representation of some integer positive values in binary notation:\n\t\\begin{alignat*}{6}\n\t1&\\qquad&1& \\qquad\\quad\\qquad&  13&\\qquad&1101&\\qquad\\quad\\qquad &25&\\quad&11001&\\\\\n\t2&&10&&  14&&1110&&   26&&11010&\\\\\n\t3&&11&&  15&&1111&&   27&&11011&\\\\\n\t4&&100&& 16&&10000&&   28&&11100&\\\\\n\t5&&101&& 17&&10001&&   29&&11101&\\\\\n\t6&&110&& 18&&10010&&   30&&11110&\\\\\n\t7&&111&& 19&&10011&&   31&&11111&\\\\\n\t8&&1000&&20&&10100&&  32&&100000&\\\\\n\t9&&1001&&21&&10101&&  33&&100001&\\\\\n\t10&&1010&&22&&10110&& 34&&100010&\\\\\n\t11&&1011&&23&&10111&& 35&&100011&\\\\\n\t12&&1100&&24&&11000&& 36&&100100&\n\t\\end{alignat*}\n\n\tNotice that:\n\t\\begin{itemize}\n\t\t\\item The  number of different values representable in $n$ bits is  $2^n$,\n\t\t\n\t\t\\item An $n$-bit binary number $X=x_{n-1}x_{n-2}\\cdots x_1 x_0$ can represent  any integer value in the range $0 \\le X \\le 2^n-1$ (e.g., if $n=3$,  then $0 \\le X \\le 7$). Note that $n+1$ bits are needed to represent the value $X=2^n$.\n\t\t\n\t\t\\item The highest (left-most) bit $x_{n-1}$ of an $n$-bit number is named the \\NewTerm{most significant bit MSB}\\index{most significant bit} and the lowest bit (right-most) $x_0$ the \\NewTerm{least significant bit LSB}\\index{least significant bit}\".\n\t\\end{itemize}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/arithmetics/binary_joke.jpg}\n\t\\end{figure}\n\t\n\t\\paragraph{Binary arithmetic}\\mbox{}\\\\\\\\\\\n\tHere are the addition facts that you need when additing numbers in binary notation:\n\t\n\t\n\tDoing binary addition is like doing decimal addition excepted that we work on a binary set. \n\t\\newcommand*{\\carry}[1][1]{\\overset{#1}}\n\t\\newcolumntype{B}[1]{r*{#1}{@{\\,}r}}\n\t\\begin{equation*}\n\t\t\\begin{array}{B3}\n\t\t    \\carry 0 & \\carry 1\\carry 1\\carry 0\\carry 0 & \\carry 1\\carry 0\\carry 01 \\\\\n\t\t      {} + 0 & 1111 & 1111 \\\\ \\hline\n\t\t           1 & 1100 & 1000 \\\\\n\t\t\\end{array}\n\t\\end{equation*}\n\tHere are the subtractions facts that you need when subtracting numbers in binary notation:\n\t\n\tThe fact that $10-1=1$ will lead to borrowing since you can not take $1$ from $0$ for a certain place value, and so you must borrow from the $1$ in the next place value, much like how you need to borrow in decimal notation:\n\t\\begin{equation*}\n\t\t\\begin{array}{B3}\n\t\t    \t\t\\carry 1 \\carry 0\\carry 01 \\\\\n\t\t      \t{} - 0110 \\\\ \\hline\n\t\t            0011 \\\\\n\t\t\\end{array}\n\t\\end{equation*}\n\tWe will come back more in details on binary arithmetic during our study of Boolean algebra in the section of Logical Systems.\n\t\n\t\\subsubsection{Hexadecimal System} \n\t\n\tThe Hexadecimal system is the \tpositional system consisting of sixteen symbols, $0$,$1$,$2$...$9$,$A$,$B$,$C$,$D$,$E$,$F$, and '$16$' as its base. Here the symbols $A$ denotes $10$, $B$ denotes $11$ and so on. The decimal equivalent of the \tgiven hexadecimal number $d_{m} d_{m-1}...d_{0}$ is given by:\n\t\n\t For example consider $(15ACB)_{16}$:\n\t\n\tWe can convert a binary number directly to a hexadecimal number by grouping the binary digits, starting from the right, into sets of four and converting each group to its equivalent hexadecimal digit. If in such a grouping the last set falls short of four binary digits then do the obvious thing of prefixing it with adequate number of binary digit '$0$'. For example let us find the \thexadecimal equivalent of $(111\\;011\\;0101\\;0010\\;1110)_{2}$:\n\t\n\tThe vice versa is also true.\n\t\n\t\\subsubsection{Octal System}  \n\tThe octal system is the positional\n\tsystem that uses 8 as its base and $\\{0,1,...7\\}$ as its symbol set of size 8. The decimal equivalent of an octal number $(d_{m}d_{m-1}...d_{0})_{8}$ is given by:\n\t\n\t For example consider $(6741)_{8}$:\n\t \n\t\n\tWe can get the octal equivalent of a binary number by grouping the binary digits, starting from the right, into sets of three binary digits and converting each of these sets to its octal equivalent.\n\t\n\tIf such a grouping results in a last set having less number of digits it may be prefixed with adequate number of binary digit 0.\n\t\n\tAs an example the octal equivalent of $(1010\\;110\\;111\\;001)_{2}$.\n\t\n\tSo we have:\n\t\n\t\n\t\\pagebreak\n\t\\subsubsection{Conversion of decimal system to non-decimal system:}\n\tTo convert a decimal number to a number of any other system we should consider the integer and fractional parts separately and follow the following procedure:\n\t\n\tConversion of integer part:\n\t\\begin{enumerate}\n\t\t\\item Consider the integer part of a given decimal number and divide it by the base $b$ of the new number system. The remainder will constitute the rightmost digit of the integer part of the new number.\n\n\t\t\\item Next divide the quotient again by the base $b$. The remainder will constitute second digit from the right in the new system\n\t\\end{enumerate}\n\t\n\tContinue this process until we end up with a zero-quotient. The last remainder is the leftmost digit of the new number.\n\t\n\tConversion of fractional part:\n\t\\begin{enumerate}\n\t\t\\item Consider the fractional part of the given decimal number and multiply it with the base $b$ of the new system. The integral part of the product constitutes the leftmost digit of the fractional part in the new system.\n\n\t\t\\item Now again multiply the fractional part resulting in step (a) by the base $b$ of the new system. The integral part of the resultant product is the second digit from the left in the new system.\n\t\\end{enumerate} \n\t\n\tRepeat the above step until we encounter a zero-fractional part or a duplicate fractional part. The integer part of this last product will be the rightmost digit of the fractional part of the new number.\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tWe want to convert $54.45$ into its binary equivalent.\\\\\n\t\n\t\\begin{enumerate}\n\t\t\\item Consider the integer part i.e. $54$ and apply the steps listed under conversion of integer part i.e.\n\n\t\t\\item conversion of fractional part:\n\t\t\\vskip 10pt\n\t\n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{ccccc}\n\t\t\t                  &   &  Product & integral part &\n\t\t\tBinary number \\\\ \\hline $0.45$ $\\times$ $2$   & = &  $0.90$    &   $0$ &\n\t\t\t$(.01\\overline{1100})_2$ \\\\\n\t\t\t0.9 $\\times$ 2   & = &  1.80    &    1 &  \\\\\n\t\t\t0.8 $\\times$ 2   & = &  1.6     &    1 &  \\\\\n\t\t\t0.6 $\\times$ 2   & = &  1.2     &    1 &  \\\\\n\t\t\t0.2 $\\times$ 2   & = &  0.4     &    0 &  \\\\\n\t\t\t0.4 $\\times$ 2   & = &  0.8     &    0 &  \\\\\n\t\t\t0.8 $\\times$ 2   & = &  1.6     &    1 &  \\\\\n\t\t\t0.6 $\\times$ 2   & = &  1.2     &    1 &  \\\\\n\t\t\t0.2 $\\times$ 2   & = &  0.4     &    0 &  \\\\\n\t\t\t0.4 $\\times$ 2   & = &  0.8     &    0 &  \\\\\n\t\t\t0.8 $\\times$ 2   & = &  1.6     &    1 &  \\\\\n\t\t\t$\\dots$          &   &  $\\dots$ &    $\\dots$ &  \\\\\n\t\t\t$\\dots$          &   &  $\\dots$ &    $\\dots$ &  \\\\\n\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\t\\end{enumerate} \n\tTherefore:\n\t\n\tand finally:\n\t\n\t\\end{tcolorbox}\n\t\n\tHere the overbar denotes the repetition of the binary digits.\n\t\n\tNote: Using binary system as an intermediate stage we can easily convert octal numbers to hexadecimal numbers and vice-versa.\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\t(a)$(423)_{8}=(100\\quad 010\\quad 011)_{2}$\n\t\n\t$\\qquad\\qquad\\qquad=(0001\\quad 0001\\quad 0011)_{2}=(113)_{16}$\n\t\n\t(b) $(93.Af)_{16}$\n\t\n\t$\\qquad\\qquad\\qquad=(1001\\quad0011.\\quad1010\\quad1111)_{2}$\n\t\n\t$\\qquad\\qquad\\qquad=(010\\quad010\\quad011.\\quad101\\quad011\\quad110)_{2}$\n\t\n\t$\\qquad\\qquad\\qquad=(223.536)_{8}$\n\t\\end{tcolorbox}\n\t\n\tIn the above two examples we have grouped the binary digits suitably either to quadruplets or triplets to convert octal to hexadecimal and hexadecimal to octal numbers respectively.\n\n\n\n\t\\pagebreak\t\n\t\\subsection{Algorithm Complexity }\n\n\\textbf{Definition (\\#\\mydef):} The \"\\NewTerm{complexity}\\index{complexity}\" of an algorithm is the measure of the number of fundamental operations it performs in the worst case on a dataset.\n\nMeasure the exact complexity is most of time irrelevant because often too complex given the size of the programs (too big algorithms). To avoid calculating in detail the complexity of an algorithm, we identify the fundamental operations. These basic operations can be: an assignment, a comparison between two variables, an arithmetic operation between two variables, etc.\n\nThus, the classical used hypothesis for the calculation of the complexity are:\n\n\t\\begin{enumerate}\n\t\t\\item[H1.] The four fundamental operations have the same time cost: $+ \\equiv - \\equiv \\times \\equiv \\div$\n\t\t\\item[H2.] A memory access has a cheaper time cost than an arithmetic operation.\n\t\t\\item[H3.] A comparison check has a cheaper time cost than an arithmetic operation.\n\t\t\\item[H4.] We work with only one single processor.\n\t\\end{enumerate}\n\t\n\\textbf{Definitions (\\#\\mydef):}\n\t\\begin{enumerate}\n\t\t\\item[D1.] We note $D_n$ the sets of data of size $n$ and $T(n)$ the cost (in time) of the algorithm on the data or the data set of size $n$.\n\t\t\\item[D2.] The \"\\NewTerm{complexity at the best}\\index{complexity at the best}\" is given by the function:\n\t\t\t\n\t\tThis is the smallest time that will need an algorithm to run on a data set (lines of code) of fixed size, here equal to $n$, that the cost (duration) execution is $C(d)$. This is a lower bound on the complexity of the algorithm on a data set of size $n$.\n\t\t\\item[D3.] The \"\\NewTerm{complexity at worst}\\index{complexity at worst}\" (the most interesting for the practitioner because it is the one to minimize!):\n\t\t\t\n\t\tThis is the biggest time that will need an algorithm to run on a data set (lines of code) of fixed size, here equal to $n$, that the cost (duration) execution is $C(d)$. This is a upper bound on the complexity of the algorithm on a data set of size $n$. The algorithm will always finish at this time or before but never after.\n\t\t\\item[D4.] The \"\\NewTerm{average complexity}\\index{average complexity}\":\n\t\t\t\nThis is the average of the complexities of the algorithm on the data sets of size n (strictly speaking, we must obviously take into account the probability of occurrence of each of the data sets). This average reflects the general behavior of the algorithm if extreme cases are rare or complexity varies slightly depending on the data. However, the complexity in practice on a particular data set may be significantly greater than the average complexity; in this case the average complexity does not give a good indication of the behavior of the algorithm.\t\t\n\t\t\\item[D5.] The \"\\NewTerm{order of complexity}\\index{order of complexity}\" is defined as the number worst complexity at worst of an algorithms that contains several terms (additions or subtractions) so that we only keep the term that is growing the fastest. Thus, an algorithm having a complexity of type:\n\t\t\t\nwill be said to have a complexity of order $\\mathcal{O}(n!)$\n\t\\end{enumerate}\n\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\\textbf{{\\Large \\ding{45}}Examples:}\\\\\\\\\nConsider $N$ as the size of the data. For a decimal number this is the numbers $N$ of digits. Consider two decimal numbers like $0.a_1a_2a_3...$ and $0.b_1b_2b_3...$\\\\\n\nE1. Addition has linear complexity because in developed way addition is expressed as (\\SeeChapter{see section Numbers}):\\\\\n\t\n\nE2. Multiplication has quadratic complexity because in developed way multiplication is expressed as:\\\\\n\t\n\t\\end{tcolorbox}\n\n\\textbf{Definition (\\#\\mydef):} An algorithm is said to be \"\\NewTerm{optimal algorithm}\\index{optimal algorithm}\" if its complexity has the minimal complexity among all other algorithms in its class.\n\nAs we made it understand implicitly earlier, we focus almost exclusively on the time complexity of the algorithms. Sometimes it is interesting to focus on other of their characteristics, such as space complexity (size of the memory used), the bandwidth required, etc.\n\nFor the result of the analysis of an algorithm to be relevant, we must have a model of a machine on which the algorithm will be implemented (as a program). We usually take as a reference, the \"random access machine (RAM)\" with a single processor where instructions are executed one after the other, without concurrent operations and without stochastic processes (in contrast to possible future quantum computers).\n\nMost common algorithms can be classified into a number of broad classes of complexity whose order $\\mathcal{O}$ varies somehow:\n\t\\begin{enumerate}\n\t\t\\item The algorithms with \"\\NewTerm{constant complexity $\\mathcal{O}(1)$}\\index{complexity!constant complexity}\" that just do a boolean control (comparison).\n\t\t\n\t\t\\item The algorithms with \"\\NewTerm{linear complexity $\\mathcal{O}(n)$}\\index{complexity!linear complexity}\" and those in complexity in $\\mathcal{O} (n log (n))$ that are considered as fast.\n\t\t\n\t\t\\item The algorithms with \"\\NewTerm{\"polynomial complexity in $\\mathcal{O}(n^k)$}\\index{complexity!polynomial complexity}\" (for $k>3$ are considered as slow).\n\t\t\n\t\t\\item The algorithms with \"\\NewTerm{sub-linear complexity}\\index{complexity!sub-linear complexity}\" whose complexity is usually of the order $\\mathcal{O}(\\log (n))$\n\t\t\n\t\t\\item The algorithms with \"\\NewTerm{factorial complexity}\\index{complexity!factorial complexity}\" whose complexity is usually of the order $\\mathcal{O}(n!)$\n\t\\end{enumerate}\nand so on... (we give here definition only for complexity for which we already have given a detailed example or will give examples further below).\n\nIt is important to see that (focusing only on complexities we have seen with examples or will see later below):\n\t\n\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\nIn practice a good complexity is considered as being of order $\\mathcal{O}(n^k)$ for $k>3$. Poor complexity is considered as being of type $\\mathcal{O}(e^n),\\mathcal{O}(n!)$ or equation.\n\t\\end{tcolorbox}\n\nWe already saw above an example with linear complexity (addition of scalars) and of polynomial (quadratic) complexity (with multiplication of scalars).\n\n\nLet us see some other very common examples. The first example use the results of the previous examples:\n\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tE1. Evaluation of a polynomial:\n\t\n\tThe direct estimate of the value of $P(x)$ leads to a complexity:\n\t\n\tE2. Another important example is the inversion matrix problem that is used a lot in supercomputer megaflops benchmark (sometimes named \"\\NewTerm{LINPACK test}\\index{LINPACK test}\". As you can see in the MATLAB companions book there is a division by $n^3$ as the matrix inversion of of complexity order of $n^3$. Indeed:\\\\\n\t\n\tAt the beginning, when the first row has length $n$, it takes $n$ \n   operations to zero out any entry in the first column (one division, \n   and $n-1$ multiply-subtracts to find the new entries along the row \n   containing that entry. To get the first column of zeroes therefore \n   takes $n(n-1)$ operations.\\\\\n   \n    In the next column, we need $(n-1)(n-2)$ operations to get the second \n   column zeroed out.\\\\\n\n   In the third column, we need $(n-2)(n-3)$ operations.\\\\\n   \n   The sum of all of these operations is:\n   \n\twhich goes as $\\mathcal{O}(n^3)$. \n\t\n\t\\end{tcolorbox}\n\tThanks to William George Horner we have a more efficient algorithm that uses a factorization of the polynomial in the form:\n\t\nWe can see almost easily that this factorization holds the same number of additions to $(n)$ but reduces the number of multiplications to $(n)$.\n\nThe resulting complexity is $\\mathcal{O} (n)$. The gain is unquestionably important. In addition, this  factorization avoids computing power.\n\nLet us see now another well know example that almost all students that have learn scripting a little bit have experiences:\n\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\\textbf{{\\Large \\ding{45}}Examples:}\\\\\\\\\nThe famous example of algorithmic complexity is the search for an  information in a sorted column (list). A simple algorithm named \"dichotomous search\" is to take the cell to mid-column and see if we find the desired value. Otherwise, research must continue on the same method in the top or bottom of the column (depending on the lexicographical order).\\\\\\\\\nThe algorithm is recursive and allows at each step, to divide by two the size of the search space.\\\\\\\\\nIf this size is initially of $n$ cells in the column, it is of size $\\dfrac{n}{2}$ in step 1, of size $\\dfrac{n}{2^2}$ in step 2, and more generally of size $\\dfrac{n}{2^k}$ in step $k$.\\\\\\\\\nAt worst, the search ends when there is only one cell in the column to explore, i.e. when $k$ is such that $n<2^k$.\\\\\\\\\nWe deduce the maximum number of steps: it is the smallest $k$ such that $n<2^k$, written in another way $\\log_2(n)<k$, i.e. the sub-linear complexity:\n\t\n\t\\end{tcolorbox}\nThe result of this last example is to compared with a sequential search (useful when sorting is too costly in resources). For example, in a column of 25,000 data the complexity is $\\mathcal{O}(n)$ thus 25,000 while with the dichotomous method, the sub-linear complexity gives $\\log_2(25,000)=15$. The gain is considerable (at the condition that data is sorted)!\n\nOther complexity that the reader must absolutely know are some elementary Linear Algebra calculations (see the section of the same name)! So without proof (because normally trivial given the previous examples) if we consider two square matrices $A$ and $B$ of dimensions $n$ the main operations have the following complexities:\n\t\\begin{itemize}\n\t\t\\item Read the components (nested loops): $\\mathcal{O}(n^2)$\n\t\t\\item Calculation of the trace: $\\text{tr}(A)=\\displaystyle\\sum_{i=1}^{n}a_{ii}\\rightarrow \\mathcal{O}(n)$ \n\t\t\\item Addition $A+B=C$ so that $c_{ij}=a_{ij}+b_{ij}\\rightarrow \\mathcal{O}(n^2)$\n\t\t\\item Product $A\\cdot B=c$ so that $c_{ij}=\\displaystyle\\sum_{k=1}^na_{ik}b_{kj}\\rightarrow \\mathcal{O}(n^3)$\n\t\t\\item Determinant (by the direct method of Cramer as detailed in the section of Linear Algebra). We can thus show that the complexity order of the determinant of a square matrix of dimensions $n$ is $n$ products, $n-1$ additions plus $n$ times the complexity of the determinant of a matrix of dimensions $n-1$ so that finally we have: $\\text{det(A)}=\\mathcal{O}(n\\cdot n!)$\n\t\\end{itemize}\nAssuming that the computer performs an elementary operation in equation seconds (which is already a good computer), we obtain the following calculations time for several values of $n$ for the determinant:\n\n\t\t\nhence the need to make sometimes a time complexity calculation before starting an algorithm (unless you are working exclusively for future generations, provided that there will still be future generations...).\n\n\\subsubsection{NP-Completude}\n\nWe will introduce now for the general culture the concept of \"\\NewTerm{NP-completeness}\\index{NP-completeness}\", that is to say that we will try to define without too much formalism (as usual in this book).\n\nFirst let us introduce two non-formal definitions of a Turing machine.\n\n\\textbf{Definitions (\\#\\mydef):}\n\n\\begin{enumerate}\n\t\\item[D1.] An algorithm is said to be a \"\\NewTerm{deterministic Turing machine}\\index{deterministic Turing machine}\" when the set of its rules prescribes at most one action to be performed for any given situation.\n\t\n\t\\item[D2.] A \"\\NewTerm{non-deterministic Turing machine}\\index{non-deterministic Turing machine}\" may have a set of rules that prescribes more than one action for a given situation. For example, a non-deterministic Turing machine may have both \"If you are in state 2 and you see an 'A', change it to a 'B' and move left\" and \"If you are in state 2 and you see an 'A', change it to a 'C' and move right\" in its rule set.\n\\end{enumerate}\n\nNow let us define what type of problems are frequently considered:\n\n\\textbf{Definitions (\\#\\mydef):}\n\n\\begin{enumerate}\n\t\\item[D1.] \"\\NewTerm{Logarithmic problems L}\\index{problem!Logarithmic problems L}\" contains all algorithms (problems) that can be solved by a deterministic Turing machine using a logarithmic amount of computation time.\n\t\n\t\\item[D2.] \"\\NewTerm{Polynomial problems P}\\index{problem!Polynomial problems P}\" contains all algorithms (problems) that can be \\underline{solved} by a deterministic Turing machine using a polynomial amount of computation time.\n\t\n\t\\item[D3.] \"\\NewTerm{Non-deterministic polynomial time problems NP}\\index{problem!Non-deterministic polynomial time problems NP}\" are the set algorithms (problems) where the result instances can be \\underline{controlled} in a polynomial time complexity by a non-deterministic Turing machine. \n\\end{enumerate}\n\nIt should be noted at this stage of the discussion that the class P is included in the NP class so that $\\text{P} \\subset \\text{NP} $. Indeed if we know a polynomial algorithm to solve a problem then we can at worst check the solution with a polynomial complexity algorithm also.\n\n\tBut a difficult question is the following reciprocal: if a problem is NP (known solution can be controlled in polynomial time) but it seems we can not found yet an algorithm in a polynomial time (or less) to find the solution, does it always exist a polynomial algorithm to find the solution so that $P=NP$ that thus bring us to write  $\\text{P} \\subseteq \\text{NP}$?\n\t\n\tIn other words: If the solution of a problem can be quickly verified as being the correct one, can the solution also be found quickly?\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Examples:}\\\\\\\\\n\tE1. The problem of finding a Hamiltonian cycle (cycle that passes once and only once by all the vertices of the graph - see section Graphs Theory) in a graph belongs to NP since, given a known cycle it is trivial to check in linear time $\\mathcal{O}(n)$ it contains a well and once each vertex but found the cycle is at worst a factorial complexity $\\mathcal{O}(n!)$.\\\\\n\t\n\tE2. Factoring an integer $n$ in product of prime factors (important in cryptography) is an NP problem. Indeed, given the prime factors $p_1,p_2,...,p_n$ it is trivial to control the solution $n=p_1,p_2,...,p_n$ as it is of order $\\mathcal{O}(n^2)$. But we do not know if it exist a polynomial algorithm to find the prime numbers (to found the solution). So we do not know if the problem of finding prime numbers of an integer is a P-problem.\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\nApparently (we were not able to find the proof of this result and neither had opportunity to do so) the complexity of the best factorization algorithm for prime numbers is in the year 2007 of the type:\n\t\ntherefore there is still work to do (if a reader could provide us with the details that led to this result, we are interested).\n\t\\end{tcolorbox}\n\nA problem $x$ that is in NP is also in NP-Complete if and only if every other problem in NP can be quickly (i.e.. in polynomial time) transformed into $x$.\n\nIn other words a problem $x$ is \"\\NewTerm{NP-Complete NPC}\\index{NP-Complete NPC}\" if:\n\t\\begin{enumerate}\n\t\t\\item $x$ is in NP\n\t\t\\item Every problem in NP is reducible to $x$\n\t\\end{enumerate}\nSo, what makes NP-Complete so interesting is that if any one of the NP-Complete problems was to be solved quickly, then all NP problems can be solved quickly.\n\nA NPC problem is complete in that it contains most of the complexity of problems belonging to NP, and a polynomial solution to this problem involves a polynomial solution to all NP type problems.\n\nIn other words: NPC problems have an exponential complexity and they all have the same complexity class (modulo polynomials).\n\nFinally, what is important to understand and retain about this idea is that if we find one day a polynomial algorithm for one of these really difficult problems that are the NPC problems, then in one stroke NP becomes equal to P and all difficults problems become easy such that \n\t\nIn other words: can we find in a polynomial time what can be proved (controlled) in polynomial time?\n\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\nThis issue is so important in computing science to reduce energy consumptions and time computations that it belongs (arbitrarily) to the 7 millennium problems, whose resolution is prized \\$1 million  by the Clay Mathematic Institute. \n\t\\end{tcolorbox}\n\t\nOk this definitions given let us now study of some typical applications of numerical methods which are very often used in the industry. We will go from simple to more complicated and not forgetting that many methods that are not in this section can sometimes be found in other sections of the book!\n\n\\subsection{Integer Part}\n\nThe biggest integer less than or equal to a real number x is expressed in this book by $[x]$, which will be read \"\\NewTerm{integer part of $x$}\\index{integer part}\" and according to the norm ISO 80000-2:2009 \\textit{Mathematical signs and symbols to be used in the natural sciences and technology} it should denoted as: $\\text{int} \\; x$.\n\nThe number $M$ is an integer if and only if $[M] = M$. Similarly, the natural number $A \\in \\mathbb{N}$ is divisible in the natural set by the natural number $B \\in \\mathbb{N}$ if and only if:\n\t\nWe also denote by $\\left\\lbrace x\\right\\rbrace $ the fractional part of $x$ such that:\n\t\nThat is to say:\n\t\nwith $\\mid \\left\\lbrace x\\right\\rbrace \\mid < 1$\nConsider $x,y \\in \\mathbb{R}$. Then we have the following properties (normally most of them don't need any proof):\n\t\\begin{enumerate}\n\t\t\\item[P1.] $[x]\\leq x <[x]+1\\Leftrightarrow 0\\leq x-[x] <1$\n\t\t\\item[P2.] $[x]=\\displaystyle\\sum_{n\\leq x} 1$ for $x \\geq 0$\n\t\t\\item[P3.] $[x+m]=[x]+m$ if $m \\in \\mathbb{Z}$\n\t\t\\item[P4.] $[x]+[y] \\leq [x+y] \\leq [x]+[y]+1$\n\t\t\\begin{dem}\n\t\t\tA reader asked for the proof of this property. So let us see how to proceed. First we write:\n\t\t\t\n\t\twhere $n,m \\in \\mathbb{Z}$ and where $0 \\leq \\theta < 1$ and $0 \\leq \\phi <1$. Thus:\n\t\t\t\n\t\t\tBy writing $x=n+\\theta$, where $0\\leq 0 <1$, we have:\n\t\t\t\n\t\t\twhere $0 < 1 -\\theta \\leq 1$.\n\t\t\tIt follows that:\n\t\t\t\n\t\t\tif $\\theta = 0$ and:\n\t\t\t\n\t\t\tif $0<\\theta<1$.\n\t\t\t\\begin{flushright}\n\t\t\t\t$\\square$  Q.E.D.\n\t\t\t\\end{flushright}\n\t\t\\end{dem}\n\t\t\\item[P5.] $[-x]=-[x]$ if $x \\in \\mathbb{Z}$ otherwise $[-x]=-[x]-1$ if $x \\not\\in \\mathbb{Z}$\n\t\t\t\\begin{dem}\n\t\t\t The proof is already given at the end of the proof of property P4.\n\t\t\t\\begin{flushright}\n\t\t\t\t$\\square$  Q.E.D.\n\t\t\t\\end{flushright}\t\t\n\t\t\t\\end{dem}\n\t\t\\item[P6.] $\\left[\\dfrac{[x]}{m}\\right]=\\left[\\dfrac{x}{m}\\right]$ if $m \\in \\mathbb{N}$ \n\t\t\t\\begin{dem}\n\t\t\t\tFor this proof we will write:\n\t\t\t\t\n\t\t\t\twhere $0 < \\theta <1$\n\t\t\t\tand:\n\t\t\t\t\n\t\t\twhere $0 \\leq r < m-1$ (\\SeeChapter{see section Number Theory}). So we get:\n\t\t\t\t\n\t\t\t\tbecause $0 \\leq r + \\theta \\leq m$. Besides :\n\t\t\t\t\n\t\t\t\tand thus we have the expected result.\n\t\t\t\t\\begin{flushright}\n\t\t\t\t\t$\\square$  Q.E.D.\n\t\t\t\t\\end{flushright}\n\t\t\t\\end{dem}\n\n\t\t\\item[P7.] If $a \\in \\mathbb{N}$ then $\\left[\\dfrac{x}{a} \\right]$ represents the number of integers less than or equal $x$ that are divisible by $a$.\n\t\t\t\\begin{dem}\n\t\t\t\tFor the last part, we observe that if $a, 2a,...,ma$ are all positive integers $\\leq x$ that are divisible by $a$, it suffices to prove that $\\left[\\dfrac{x}{a}\\right]=m$. \n\t\t\t\t\n\t\t\t\tSince $(m+1)a>x$, then:\n\t\t\t\t\t\n\t\t\t\tThat is to say:\n\t\t\t\t\t\n\t\t\t\tand thus we have the expected result.\t\t\t\t\t\n\t\t\t\t\\begin{flushright}\n\t\t\t\t\t$\\square$  Q.E.D.\n\t\t\t\t\\end{flushright}\t\t\t\n\t\t\t\\end{dem}\n\t\\end{enumerate}\n\t\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\nThe rounding method of real values will be given in the section on Economy.\n\t\\end{tcolorbox}\n\t\n\t\\subsection{Heron's Square Root Algorithm}\n\t\n\tOne of the first things that many people learn in an introduction to Computer Sciences course is the algorithm for calculating the square root of a number. \n\t\n\tThere is such a simple algorithm for this purpose named \"\\NewTerm{Heron's algorithm}\\index{Heron's algorithm}\" or \"\\NewTerm{algorithm of Heron of Alexandria}\\index{algorithm of Heron of Alexandria}\" which converge to the value of this square root.\n\t\n\tThus want to calculate the square root:\n\t\t\n\t\\begin{dem}\n\t\tHere is a pseudo-proof because historically the algorithm was built on purely intuitive considerations (since 100 BC algebra did not exist...). In high-school classes the result is given as a definition and just convergence is observed.\n\t\t\n\t\tSo for the demonstration, we will proceed as follows:\n\t\t\t\n\t\t\tAnd the trick is to write:\n\t\t\t\t\n\t\t\t\t\\begin{flushright}\n\t\t\t\t\t$\\square$  Q.E.D.\n\t\t\t\t\\end{flushright}\n\t\\end{dem}\n\t\n\t\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\nWe want to calculate:\n\t\n\tWe take $A=10$ and this gives us the following table of iterations:\n\t\n\t\t\t\n\t\\end{tcolorbox}\n\n\tIn the case of the cubic root, the proof is similar and we obtain:\n\t\n\t\n\tand so on...\n\t\n\tTo conclude it is perhaps interesting to know that the reader can find in the section of Number Theory the method used in the antiquity (at least an analogy) using continued fractions.\n\t\n\t\t\\pagebreak\n\t\t\\subsection{Archimedes Algorithm}\n\t\n\tThe calculation of the universal constant \"pi\" denoted by $\\pi$ is certainly the algorithm with the greatest interest since we found this constant almost everywhere in physics and mathematics (there are numerous books on the subject available on the market).\n\t\n\tWe recall that we did not give the value of $\\pi$ in the section on Geometry or in other sections of this book until now. So we will now tackle this task.\n\t\n\tWe define in geometry the number named \"pi\", independently of the metric used, as the ratio of half the circumference of a circle with its radius such that:\n\t\n\tIt seems that we own the first algorithm of the calculation of this constant by Archimedes (287-212 BC.) and whose proof is given below:\n\t\\begin{dem}\n\t\tConsider an $n$-polygon inscribed in a circle:\n\t\t\\begin{figure}[H]\n\t\t\t\\begin{center}\n\t\t\t\\includegraphics[scale=0.75]{img/computing/archimedes_algorithm.eps}\n\t\t\t\\end{center}\t\n\t\t\t\\caption{The illustrated principle of Archimedes algorithm}\n\t\t\\end{figure}\n\tThe principle of Archimedes algorithm is as follows:\n\t\n\tGiven the perimeter of a regular polygon of $n$ sides inscribed in a circle of radius $1/2$ we can see in the figure above that by induction (\\SeeChapter{see section Trigonometry}):\n\t\n\tWith have for the perimeter of an $n$-polygon:\n\t\n\tand:\n\t\n\tWith:\n\t\n\tTherefore:\n\t\n\tTherefore:\n\t\n\tWe then just need a computer and several iterations to evaluate with a good accuracy the value of $\\pi$. Obviously, we use the Heron algorithm to calculate the square root...\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThere are a large number of algorithms to compute $\\pi$. The one shown above, without being the most aesthetic, seems historically to be the first and most simple one.\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\subsection{Euler's Number $e$}\n\t\n\tIncluding the constant $\\pi$, there are many other important mathematical constant that we need to generate with a computer (nowadays most constant values are stored as is and are not recalculated automatically). Among them, is the \"\\NewTerm{Euler number}\\index{Euler number}\" denoted by $e$ (\\SeeChapter{see section Functional Analysis}). Let's see how to calculate this number.\n\t\n\tConsider the Taylor series (\\SeeChapter{see section on Sequences and Series}) for an infinitely differentiable function $f$ given by:\n\t\n\tAs (\\SeeChapter{see section Differential and Integral Calculus}):\n\t\n\tTherefore we have:\n\t\n\tSo finally:\n\t\n\tThis relation provides an easy algorithm to calculate the Euler number to a given order $n$ of precision.\n\n\t\\subsection{Stirling's factorial approximation}\n\tObviously, the factorial may be calculated with a simple iteration. However, this kind of method generates an exponential complexity algorithm which is not the best. Then there exists another method:\n\n\tIn mathematics, Stirling's approximation (or Stirling's formula) is an approximation for factorials. It is a very powerful approximation, leading to a very useful in Statistical Mechanics (see section of the same name). \n\n\tThere are various approach that lead to different results. We will focus here on the only one that we will use later in theoretical physics and that is the worst easiest approximation.\n\t\n\tEither the definition of the factorial:\n\t\n\t\n\tAnd according to the properties of logarithms:\n\t\n\t\n\tIf $n$ is very large (but very large) then the previous sum can be approximately written as an integral:\n\t\n\t\n\tSolving this integral we get (\\SeeChapter{see section Differential and Integral Calculus})\n\t\n\t\n\tWhen $n \\gg 1$, the lower limit is negligible and then (approximation that will be very useful in the section of Statistical Mechanics):\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.7]{img/computing/stirling_factorial_approximation.jpg}\n\t\t\\caption{Comparison of logarithmic formulations using Stirling formula}\n\t\\end{figure}\n\t\n\tAfter a small elementary simplification, we obtain:\n\t\n\t\n\tThe latter relation is useful of course only if we assumes that Euler's constant is a value stored in the machine...\n\t\n\tLet Consider the Gamma function (\\SeeChapter{see section Differential and Integral Calculus}):\n\t\n\tand recall that for integers $\\lambda$ we have:\n\t\n\tWe get:\n\t\n\tSubstituting $y=t/\\lambda$ and letting $g(x)=y-\\log (y)$ We get: \n\t\n\tNow we will use Laplace's method of integration (\\SeeChapter{see section Differential and Integral Calculus}) and for this we we differentiate twice and get:\n\t\n\tso that $y^*=1,g(y^*)=1$ and $g''(y^*)=1$. Laplace's method now\n\tyields to:\n\t\n\tThe relation:\n\t\n\twhich is known as \"\\NewTerm{Stirling's improved formula}\\index{Stirling's improved formula}\".\n\t\n\t\\pagebreak\n\t\\subsection{Linear System of Equations}\n\t\n\tThere are many methods for solving systems of linear equations. Most of them have been developed to address particular systems. We will here study for the moment only one named the \"\\NewTerm{Gauss reduction method}\\index{Gauss reduction method}\" or \"\\NewTerm{Gauss pivot}\\index{Gauss pivot}\" or \"\\NewTerm{Gauss reduction algorithm}\\index{Gauss reduction algorithm}\" which is well suited for solving small systems of linear equations (up to 50 unknown).\n\t\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\\textbf{R1.} The validity of some of the operations that we will perform here to solve linear systems is proved in the section on Linear Algebra. In fact, to be brief, the whole method use vector spaces whose columns are linearly independent vectors.\\\\\n\n\t\\textbf{R2}. Recall that linear systems admit a solution if and only if the rank of the augmented matrix is less than or equal to the number of equations (\\SeeChapter{see section Linear Algebra}).\n\t\\end{tcolorbox}\n\t\n\t\\subsubsection{One equation with on unknown}\n\t\n\tWe begin for sure with the easiest and smallest possible example... of one equation with one unknown:\n\t\n\tWhere $a$ and $b$ are the coefficients of the equation and $x$ is unknown. Solving this equation consists to determine $x$ is according to $a$ and $b$. If $a$ is not equal to $0$ then:\n\t\t\n\tis the solution of the equation. If $a$ is equal to zer0 and if $b$ is different from $0$ then the equation above admits no solution. If $a$ and $b$ are equal to zero, then the equation has infinitely many solutions.\n\t\n\t\\subsubsection{Two equations with two unknowns}\n\t\n\tA linear system of two equations with two unknowns can be written as we know:\n\t\t\n\t\tWhere $a_{11},a_{12},a_{21},a_{22}$ are the coefficients of the equations, $x_1$ and $x_2$ are the unknowns.\n\t\t\n\t\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\nThe above-used notations have nothing to do with the tensor calculus!\n\t\t\\end{tcolorbox}\t\n\t\t\n\t\tTo solve the system following the algorithm that interest us we proceed as follows:\n\t\t\n\t\tUsing elementary algebraic manipulations (addition or subtraction of the various equalities between themselves - operations authorized by the linear independence of vectors-lines) we transform the system into another with one unknown less for one of the both equations given by (for example):\n\t\t\n\t\tThe transformation between the two systems:\n\t\t\n\t\tis simply done by multiplying each coefficient of the first equality by $\\dfrac{a_{21}}{a_{11}}$ and subtracting the second line with the resulting equation. This procedure is named \"\\NewTerm{row reduction}\\index{row reduction}\" or \"\\NewTerm{Gaussian elimination}\\index{Gaussian elimination}\". \n\t\t\n\t\tIn our case, the element $a_{11}$ is named the \"\\NewTerm{pivot}\\index{pivot}\" or \"\\NewTerm{leading coefficient}\\index{leading coefficient}\". In others words, if the $L_i$ is the notation for the each line number of the system, what we made is:\n\t\t\n\t\tThen, we solve the equation with only one unknown:\n\t\t\n\t\tWe can therefore conclude with:\n\t\t\n\t\tBut this is not the real algorithm. The real one use the augmented form:\n\t\t\n\t\t Now we apply $L_2-\\dfrac{a_{21}}{a_{11}}L_1\\rightarrow L_2$ and $L_1-\\dfrac{a_{12}}{a_{22}}L_2 \\rightarrow L_1$ such that:\n\t\t\n\t\tAs you can see the matrix has been put in diagonal form!\n\t\tNow to continue, we write:\n\t\t\n\t\t\n\t\tNow we just apply $\\dfrac{1}{a_{11}^{'}}L_1 \\rightarrow L_1$ and  $\\dfrac{1}{a_{12}^{'}}L_2 \\rightarrow L_2$ such that:\n\t\t\n\t\tFinally:\n\t\t\n\t\t\n\t\t\\subsubsection{Three equations with three unknowns}\n\tNow consider the case of the linear systems of three equations with three unknowns:\n\t\t\n\tWe can subsequently by elementary operations (see section Linear Algebra and the previous case) reduce this linear system in the following echelon form system:\n\t\t\n\t\tAnd therefore we can trivially solve the last line:\n\t\t\n\t\tAnd afterwards the second line:\n\t\t\n\t\tAnd finally:\n\t\t\n\t\tLet us return to the systems transformations. It is carried out in two stages:\n\t\t\\begin{enumerate}\n\t\t\t\\item In the first line, we choose $a_{11}$ as the pivot and we eliminate the coefficients $a_{21}$ and $a_{31}$ as follows:\n\t\t\t\n\t\t\tWe have to multiply each coefficient of the first line by $\\dfrac{a_{21}}{a_{11}}$ and subtract this result of the second line and therefore $a_{21}$ disappears.\n\t\t\t\n\t\t\tSimilarly, by multiplying the coefficients of the first line by $\\dfrac{a_{31}}{a_{11}}$, and subtracting the result obtained from the third line, $a_{31}$ disappears.\n\t\t\t\n\t\t\tThe linear system of equations can therefore be written as:\n\t\t\t\n\t\t\t\\item The second step is to treat the linear system of two equations with two unknowns formed by the second and third lines of the previous system and that, in choosing $a_{22}^{'}$ as pivot. This method of resolution can seem complicated but it has the advantage of being generalized and be applied to solve linear systems of $n$ equations in $n$ unknowns.\n\t\t\\end{enumerate}\n\t\t\n\t\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\t\tLet us see an example taken on Wikipedia (helps to copy/paste boring \\LaTeX ...):\n\t\t\n\t\tNow we put:\n\t\t\n\t\tTherefore we get:\n\t\t\n\t\tNow we put:\n\t\t\n\t\tTherefore we get:\n\t\t\n\t\t\\end{tcolorbox}\n\t\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\tTo continue we put:\n\t\t\n\t\tTherefore we get:\n\t\t\n\t\tWe put:\n\t\t\n\t\tTherefore we get:\n\t\t\n\t\tAnd finally we put:\n\t\t\n\t\tTo get:\n\t\t\n\t\tSo this is again an application of the row reduction method (or Gaussian elimination).\n\t\\end{tcolorbox}\n\tFor sure when you know that such systems can be solved using just a matrix inversion with a vector multiplication (\\SeeChapter{see section Linear Algebra}) all that stuff will be almost useless for most employees working in non-maths jobs.\n\n\t\t\\pagebreak\n\t\t\\subsubsection{$n$ equations with $n$ unknowns}\n\t\n\t\tTo simplify the writing, the coefficients will always be noted $a_{ij}$ and not $a_{ij}^{'},a_{ij}^{''}$, etc. at each stage of the calculation.\n\t\t\n\t\tGiven the linear system (we could also represent it as an augmented matrix to simplify the notations):\n\t\t\nWe will choose $a_{11}$ as the pivot to to eliminate $a_{21},a_{31},...,a_{n1}$. Then, removing $a_{32},a_{42},...,a_{n2}$ is performed by taking $a_{22}$ as a pivot. Last pivot to consider is obviously $a_{n-1,n-1}$, it helps eliminate $a_{n,n-1}$. The system then takes the form:\n\t\t\n\t\tAnd we can therefore solve the last equation, then the fore last equation, and so on up to the first one.\n\t\t\n\t\tThis method must however be fine-tuned to avoid pivots with $0$ values. The trick is therefore to switch the order in which the equations are written to choose the pivot coefficient whose absolute value is the largest. Thus, in the first column, the better is pivot is the coefficient such that $a_{j1}$:\n\t\t\nIt is taken to $a_{11}$ by permutation of first lines and $j$-th lines. Removal of the rest of the first column can then be performed. Then, we begin again with the $n-1$ remaining equations.\n\n\t\\pagebreak\n\t\\subsection{Polynomials}\n\t\n\tThe basics polynomials with real coefficients has been studied in the section of Functional Analysis in detail. Here we will address only the digital aspect of some problems related to polynomials (that is to say elementary algorithms or formulas useful for some operations not included by default in most computer programming languages).\n\t\n\tApart from the addition and subtraction of polynomials which we assume as trivial (aside the optimization of the complexity aside as the Horner scheme), we will see how to multiply and divide two polynomials.\n\t\n\tLet's first see how to multiply two polynomials.\n\t\n\tLet:\n\t\n\tTherefore:\n\t\n\tWith for $k=0,1,2,...,n+m$:\n\t\n\tit was easy...\n\t\n\tThe second case of interests to us now is the Euclidean division of polynomials (\\SeeChapter{see section Calculus}).\n\t\n\tLet us take again:\n\t\n\tbut with the condition that $n \\geq m$ that is to say $\\text{deg}(f(x))<\\text{deg}(g(x))$.\n\t\n\tThe division can be written as we know (see the section of Number Theory or Calculus):\n\t\n\twith:\n\t\n\totherwise $r(x)=0$\n\tIt is normally known beforehand (since proved in the section Calcul of the chapter Algebra) that we have:\n\t\n\tand:\n\t\n\tWe have therefore by definition $q(x)$ that is the quotient of the division and $r(x)$ the remainder of the Euclidean division of $f(x)$ by $g (x)$.\n\t\n\tTherefore, nothing prevents us from writing in the most general possible way:\n\t\n\tTo prove the expression of different $q_i$, we have preferred for educational reasons to use a specific example (see below) whose result will be generalized.\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tLet:\n\t\n\tSo of what we have said before, we get (starting point):\n\t\n\tUsing the fact that (as a reminder):\n\t\n\tSo we have almost immediately:\n\t\n\tThen (still proceeding in the same way):\n\t\n\tAnd finally:\n\t\n\t\\end{tcolorbox}\n\tSo in general:\n\t\n\tAs:\n\t\n\tThe first remainder is then:\n\t\n\tAfter:\n\t\n\tThe second remainder is then:\n\t\n\tand so on... we continue until $\\deg(r_k(x))<m$.\t\n\t\n\t\\pagebreak\n\t\\subsection{Regression Techniques}\n\tRegressions are very useful and very important tools for statisticians, engineers, computer scientists, marketing analysts, physicists, physicians, economists wishing to establish a law of correlation between two (or more) variables, do a qualitative analysis, an extrapolation or even to separate signal form noise (as every point outside the regression will be considered as being noise).\n\t\n\tThere are many regression  methods: the simple solution of first degree equations (when only two points of measurement are known) to equations that permits to obtain from a large number of points information that are essential to the establishment of a linear regression, polynomial, logistic or other law (or function).\n\t\n\tLet us give a list of the most used regressions techniques used in business and administrations (whose mathematical models are not all shown in this section yet but will be when we will have more time):\n\t\\begin{enumerate}\n\t\t\\item Linear regression model to one or more variables based on the method of least squares with binary or continuous variables with response variable belonging to $\\mathbb{R}$. Presented in detail in this section of the book (implicitly this model contains the interactions between variables and also some non-linear models).\n\t\t\n\t\t\\item Gaussian linear regression model (statistical approach of linear regression based on the method of least squares) with binary or  continuous variables with response variable also belonging to $\\mathbb{R}$. Presented in detail in this section of the book.\n\t\t\n\t\t\\item Nonlinear regression models with binary or continuous variables with response variable in $\\mathbb{R}$. Presented in detail in this section of the if they can be reduced to linear case or not but then no interactions of explanatory variables. Otherwise based on quasi-Newton techniques type or Gauss-Newton presented also this section.\n\t\t\n\t\t\\item Polynomial regression model by the method of B-spline or of the collocation polynomial with response variable in $\\mathbb{R}$. Presented in detail in this section of the book.\n\t\t\n\t\t\\item Logistic regression model (binomial regression) with binary, nominal variables (categorical) or ordinal or continuous with response variable bounded between $0$ and $1$. Presented summarily and naively in this section of the book.\n\t\t\n\t\t\\item Logic regression model is a (generalized) regression methodology that is primarily applied when most of the covariates in the data to be analyzed are binary. The goal of logic regression is to find predictors that are Boolean (logical) combinations of the original predictors. \n\t\t\n\t\t\\item Counting Poisson regression (Poisson MLE, PMLE, GLM) or negative binomial (binomial MLE and QGPMLE) model with binary, nominal (categorical) or ordinal or continuous variables with positive integer answer in $\\mathbb{N}$.\n\t\t\n\t\t\\item Orthogonal linear regression model (or Deming regression) that is used as complement to the paired $t$-test to check the stability of the measuring instruments in laboratories. This is a case where the explanatory and dependent variables are tainted with uncertainty.\n\t\t\n\t\t\\item Quantile regression model (very useful in the medical and economic fields) based on the same idea as the regression by the method of least squares, but where we do not minimizes the sum of squared errors from the average, but the sum of absolute errors from a given quantile (median or other). It's also used sometimes to get rid of extreme values.\n\t\t\n\t\t\\item The Theil–Sen estimator method\\index{Theil–Sen estimator method} also named Sen's slope estimator\\index{Sen's slope estimator} or Slope selection method\\index{slope selection method} or Single median method\\index{single median method} or Kendall robust line-fit method\\index{Kendall robust line-fit method} or Kendall–Theil robust line\\index{Kendall–Theil robust line}... is a very simple method for robustly fitting a line to a set of points (simple linear regression) that chooses the median $a_M$ of the slopes of all lines through pairs of two-dimensional sample points. For the estimate of the intercepts the USGS recommends the following calculation $b=y_M-a_Mx_M$. That's all... it's quite simple in fact.\n\t\t\n\t\t\\item LAD (Least Absolute Deviation) regression model that use absolute values rather than square errors.  But absolute values are difficult to work with in mathematics (especially Calculus) as absolute values results in discontinuous derivatives that cannot be treated analytically\n\t\t\n\t\t\\item LOESS (LOcal regrESSion) and LOWESS (locally weighted scatterplot smoothing) are two strongly related non-parametric regression methods. These methods are purely numerical (does therefore not provide any unique formula) and are performed by fitting simple models to localized subsets (we speak then of \"segmented regression\"). In fact, one of the chief attractions of this method is that is is not required to specify a global function of any form to fit a model to the data, only to fit segments of the data.\n\t\t\n\t\t\\item Multivariate adaptive regression splines (MARS) (The term \"MARS\" is trademarked and licensed to Salford Systems. In order to avoid trademark infringements, many open source implementations of MARS are named \"Earth\"...) and as it names describes it well... is uses splines to interpolate and also extrapolate know data.\n\t\t\n\t\t\\item Bayesian linear regression model is an approach to linear regression in which the statistical analysis is undertaken within the context of Bayesian inference, that means we have some prior knowledge about the regression coefficients and the error term.\n\t\t\n\t\t\\item Ridge regression model that us a trick on the information matrix $X^TX$ (see further below) by adding a constant in it. But the constraints of usage are quite boring (no intercept and coefficients normalized) that make it quite difficult to interpret.\n\t\t\n\t\t\\item Bootstrap or Jacknife regression model using all previous models and the by resampling techniques (see further below) gives the possibility to have robust estimators that could in some situations hard to get analytically. \n\t\\end{enumerate}\n\t... and ... in a given number of these approaches we differentiate mathematical models taking into account the censored data and uncensored data. This makes a bunch of theories/models to study in final and this is why this subsection if one of the biggest of the whole book and that some models are given in some other sections of the book (especially the Statistics section).\n\t\n\tFinally, note that in the linear regression explanatory variables form a linear expression but that does not mean they are themselves linear. Thus, if we consider the two expressions below:\n\t\n\tthe first is linear in the parameters but the second is not!\n\t\n\tFinally, a word on a technique sometimes used for qualitative interpretation of the influential of explanatory variables trough their coefficients for simple or multivariate linear regressions:\n\t\n\tWhen the amplitudes of some explanatory variables (continuous!) have very different orders of magnitudes this raises a big problem of interpretation of the influence of each variable by reading their coefficient and also generates problems of calculations precision in algorithms because of differences in size order and thus also generates rounding errors!\n\t\n\tThe traditional idea is then to center-reduce all the values of explanatory variables which helps greatly to interpretation of the influence of these variables (but we must then leave out the interpretation of the numerical value of the response variable). But take care to a common trap!!! Once the theoretical model obtained from been normalized (center-reduce) variables, the new values to explain should be obtained by having previously centered-reduced the new explanatory values but by subtracting the old average and reducing by the old standard deviations of respectively each of the injected explanatory variable in the model!\n\t\n\t\\pagebreak\n\t\\subsubsection{Univariate linear regression model}\n\t\n\tWe will present here several algorithms (methods) useful and known in experimental science (we have already discussed about some of them during our study of statistics). The goal is to express the linear relation between two variables $x$ (explanatory variable) and $y$ (response variable) independently by a \"\\NewTerm{linear model LM}\\index{linear model}\" as simple as possible (otherwise it would take hundreds of pages to introduce the topic!).\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tWriting this book we have hesitated a long time to put regression techniques in the Statistics section. But because in practice the choice of the type of regression is empirical it has seem to us most convenient to put this subject here.\n\t\\end{tcolorbox}\t\n\t\n\t\\textbf{Definition (\\#\\mydef):} In univariate regression we have:\n\t\\begin{enumerate}\n\t\t\\item $x$ is the independent variable or \"\\NewTerm{explanatory variable}\\index{explanatory variable}\" also named \"\\NewTerm{covariate}\\index{covariate}\" or \"\\NewTerm{predictor}\\index{predictor}\" (in economics \"\\NewTerm{exogenous variable}\"...). The $x$ values are set by the experimenter and are assumed to be known without error.\n\t\t\n\t\t\\item $y$ is the dependent variable or \"\\NewTerm{explained variable}\\index{explained variable}\" (e.g. the answer of the analyzer) also named in economy \"\\NewTerm{endogenous variable}\\index{endogenous variable}\". $y$ values are most of time measured with an error (bias) of measurement. One goal of regression is to estimate precisely this error.\n\t\\end{enumerate}\n\tWe seek a relation of the form:\n\t\n\tThis is the equation of a straight line (affine function), hence the term \"\\NewTerm{linear regression}\\index{linear regression}\" where $a$ is named in the study framework of regression techniques: \"\\NewTerm{regression coefficient}\\index{regression coefficient}\" instead of \"slope\" as seen in previous sections.\n\t\n\tIn real life, linear relations are an exception because most phenomenon are nonlinear in reality and even non-continuous in certain situations... Furthermore, it is not because they are linear in a given interval of measurements that are still linear at a smaller-scale or larger scale (zoom bias)!\n\t\n\tHowever, in practice we make transformation to linearize functions either by elementary algebraic transformations like those used by spreadsheets softwares (e.g. Microsoft Excel) like for example the linearization of a logarithmic function by making a simple change of variables:\n\t\n\tor for power and exponential functions by also making a small algebraic manipulation with the properties of logarithms as proved in the section of Functional Analysis (under the assumption that $a$ is strictly positive):\n\t\n\tor by making Taylor series approximations (\\SeeChapter{see section Sequences and Series}).\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIf we seek to determine the value of $y$ for an unmeasured $x$ and lying beyond the original interval of measurement, then we speak of \"\\NewTerm{extrapolation}\\index{extrapolation}\" or in more complicated cases \"\\NewTerm{forecast with prediction interval for $x$}\\index{forecast with prediction interval}\". We will see that further below.\n\t\\end{tcolorbox}\t\n\t\n\t\\paragraph{Regression line}\\mbox{}\\\\\\\\\\\n\tIn the common way to make an univariate linear regression of the type:\n\t\n\tthere exist multiple methods.\n\t\n\tThis first and most simple method in our point of view relies on the properties of covariance and mean (\\SeeChapter{see section Statistics}) and is widely used among others in elementary finance (but in fact in any filed where there are some statistics).\n\t\n\tConsider $X, Y$ two variables, one of which depends on the other (often it is $y$ that depends on $x$). According to the covariance bi-linearity property (\\SeeChapter{see section Statistics}) we recall that we have:\n\t\n\tthe following relation:\n\t\n\tSo it comes to the regression coefficient (we will reuse this relation during our study of yield of a portfolio according to Sharpe model in the section Economy):\n\t\n\tEither in a most explicit form which that we will use later (using what explicit relation determined in the section Statistics):\n\t\n\tTo determine the intercept we use the properties of the expected mean as proved in the section Statistics:\n\t\n\tTherefore we have $b$ as:\n\t\n\t\n\t\\paragraph{Least Squares Method (LSM)}\\mbox{}\\\\\\\\\\\n\tDue to the error on $y$, the experimental points, of coordinates $(x_k,y_k)$ do not lie exactly on the theoretical line. We can therefore find the equation of the experimental  line passing closest to these points.\n\t\n\tThe \"\\NewTerm{least squares method LSM}\\index{least squares method}\" will be under the particular study we are interested in to look for the values of the parameters $a, b$ that minimize the sum of squares of residual $e_i$ (SSR: Sum of Squared Residuals) between the observed values $y_k$ and the theoretical calculated values $y_k^{'}$. We then speak sometimes about the \"\\NewTerm{least squares method of ordinate deviations}\\index{least squares method of ordinate deviations}\"...:\n\t\n\twhere $n$ is the number of measured points and the theoretical values given by:\n\t\n\tTherefore written explicitly:\n\t\n\tThis relation shows the sum of squared deviations as a function of the parameters $a, b$. When this function is minimal (extremal), the derivatives with respect to these parameters canceled:\n\t\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\nThis method of minimum research (optimization) is named \"\\NewTerm{method of Lagrange multipliers}\\index{method of Lagrange multipliers}\" in the world of Economy (we will detail this method further below). In our example SSR is the scalar value that will be used as Lagrange multiplier.\n\t\\end{tcolorbox}\t\n\t\n\tTherefore after simplification and rearrangement:\n\t\n\tThe above system is named \"\\NewTerm{normal equations}\\index{normal equations}\". This is a linear system of two equations with two unknowns. Let us write to simplify the notation:\n\t\n\tThe system becomes:\n\t\n\tFrom the second line we get without surprise:\n\t\n\tBy replacing in the first line, we get:\n\t\n\tFrom there we get from the second line:\n\t\n\tThus, the terms of the slope and intercept of the straight line equation are:\n\t\n\tThe last two relations are used by a majority of spreadsheet softwares such as in the English version of Microsoft Excel 11.8346 when using the \\texttt{REGRESSION( )} function. The term $b$ (the $y$-intercept) may be obtained directly with the \\texttt{INTERCEPT( )} function and $a$ with the SLOPE() function and the whole with the \\texttt{LINEST( )} function.\n\t\n\tHere for information an interesting little list of some very practical case with this spreadsheet software (because requested a lot):\n\t\\begin{itemize}\n\t\t\\item For a straight line:\\\\\n\t\t$a$: \\texttt{=SLOPE (y, x)}\\\\\n\t\t$b$: \\texttt{= INTERCEPT (y, x)}\n\t\t\\item For a logarithmic function (we see here again the change of variable given at the before):\\\\\n\t\t$a$: = \\texttt{INDEX (LINEST (y, LN (x)), 1)}\\\\\n\t\t$b$: = \\texttt{INDEX (LINEST (y, LN (x)), 1, 2)}\\\\\n\t\t\\item For a power function (once again wee see the change of variable given at the beginning):\\\\\n\t\t$a$: = \\texttt{EXP(INDEX(LINEST(LN(y),LN(x),,),1,2))}\\\\\n\t\t$b$: = \\texttt{INDEX(LINEST(LN(y),LN(x),,),1)}\\\\\n\t\t\\item For an exponential function (we also find the change of variable given at the beginning):\\\\\n\t\t$a$: = \\texttt{EXP(INDEX(LINEST(LN(y),x),1,2))}\\\\\n\t\t$b$: = \\texttt{INDEX(LINEST(LN(y),x),1)}\\\\\n\t\\end{itemize}\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\nWe must keep in mind that the line of least squares, which can best summarize the cloud of observations points by minimizing SSR, necessarily passes through the center of gravity of the cloud, that is to say, by an average point that corresponds rarely to an observation (mean average of abscissas and ordinates).\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\paragraph{Univariate Regression Variance Analysis}\\mbox{}\\\\\\\\\\\n\tBefore starting it is important that the reader abandons immediately the possible reflex that would be to try to bring by successive analogies the regression ANOVA we will see now to the categorical ANOVA we have study in the section Statistics!\n\t\n\teither in discrete form:\n\t\n\tas well as by the construction of the least square method we have the following relation:\n\t\n\tNow we assume that each measured value is attached by a residual error such that:\n\t\n\tEither by subtracting the last two relations:\n\t\n\tNow let us go through an intermediate result. Remember that we obtained earlier:\n\t\n\tAnd therefore:\n\t\n\tBy replacing $b$ by its value:\n\t\n\tWe therefore get:\n\t\n\tMultiplying the second line above by $\\bar{x}$ and by subtracting from the first we get:\n\t\n\tTherefore after rearrangement:\n\t\n\tNow we go back to:\n\t\n\tIf we put it all square and summing for all observations, we get:\n\t\n\tTherefore:\n\t\n\tBut we have shown just before the double product was equal to zero. Therefore:\n\t\n\tThis last relation is named \"\\NewTerm{ANOVA equation}\\index{ANOVA!ANOVA equation}\" or \"\\NewTerm{variance analysis equation}\\index{ANOVA!variance analysis equation}\". In fact, it is the sums of squares. We would need to divided it by $n$ to obtain biased variances.\n\t\n\tThis last relation is often written:\n\t\n\twhere SST is the \"\\NewTerm{total sum of squares}\\index{total sum of squares}\", SSE the \"\\NewTerm{sum of square errors}\\index{sum of square errors}\" and SSR \"\\NewTerm{sum of squares residuals}\\index{sum of squares residuals}\".\n\t\n\tLet us note now the estimated $y_k$ that minimize the errors such that the error is null in a different way and let us named that the \"\\NewTerm{a priori linear model}\\index{a priori linear model}\":\n\t\n\tHence the equality we will reuse several times (it is just previous relations without error term):\n\t\n\tIt is indeed important in practice to differentiate the a priori model that does not take into account the errors of the real model that does!\n\t\n\tBecause of the previous equality the relation:\n\t\n\tCan be written:\n\t\n\twhere the sum after the equality is often named \"\\NewTerm{lack of fit}\\index{lack of fit}\". More explicitly:\n\t\n\tThis last relation can be represented graphically as follows:\n\\begin{figure}[H]\n\\centering\n\\includegraphics{img/arithmetics/sst_sse_ssr.jpg}\n\\caption{Graphical representation of respectively SST, SSE, SSR}\n\\end{figure}\n\nThe last relation is sometimes denoted also in the literature in a most educational way as follows:\n\n\twhich is just another way to write the variance decomposition (implicit variance):\n\t\n\t\n\tand it then comes immediately the relation sometimes used in practice to calculate residues (knowing the calculated values and measured values):\n\t\n\tIt is important to remember that the above relation between SST, SSE and SSR are valid only in the case of a linear model!\n\t\n\tIt is also important to note that in this particularly variance decomposition we have:\n\t\n\tRemember now that we have proved in the section Statistics, we found that the correlation coefficient was given (defined) by:\n\t\n\tOr else since we have shown above that (remember that the indicated variance is an estimated variance in practice!):\n\t\n\tWe can therefore write the correlation coefficient in the form:\n\t\n\tSo we deduce from this using the relations established in the section of statistics:\n\t\n\tRemember that we proved above that:\n\t\n\tTherefore:\n\t\n\tthat is to say:\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\nThis formulation of the correlation coefficient is extremely useful because, unlike the statistical formulation, the latter generalizes immediately to the multiple linear regression we will see a further below.\n\t\\end{tcolorbox}\n\tand in the context of regression models here are some typical cases of the value of the linear correlation coefficient with the first two lines and non-linear for the third line:\n\\begin{figure}[H]\n\\centering\n\\includegraphics{img/arithmetics/correlation_coefficients.jpg}\n\\caption{Some values of the linear correlation coefficient (source: Wikipedia)}\n\\end{figure}\n\tFinally let us indicate that we also find very often the linear correlation coefficient as follows in softwares and literature:\n\t\n\tThe last form highlights better that if the sum of the squares of residues SSR  residues is zero, the measures are perfectly modelised by a linear relation in the range of study considered.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tSome softwares communicates the \"\\NewTerm{predicted R-squared}\\index{predicted R-squared}\" defined as:\n\t\n\t where PRESS is the \"\\NewTerm{predicted residual sum of squares}\\index{predicted residual sum of squares}\" is a form of cross-validation used in regression analysis to provide a summary measure of the fit of a model to a sample of observations that were not themselves used to estimate the model. It is calculated as the sums of squares of the prediction residuals for those observations:\n\t \n\tTherefore PRESS differs from the sum of squares of the residual error in that each fitted value, $\\hat{y}_k$, for PRESS is obtained from the remaining $n – 1$ observations.\n\t\n\tGiven this procedure, the PRESS statistic can be calculated for a number of candidate model structures for the same dataset, with the lowest values of PRESS indicating the best structures. Models that are over-parameterised (over-fitted) would tend to give small residuals for observations included in the model-fitting but large residuals for observations that are excluded.\n\t\\end{tcolorbox}\n\t\n\tFinally, note that the ordinate value is not involved in the value of the correlation coefficient since (bilinearity property of covariance as proved in the section Statistics):\n\t\n\t\n\t\\pagebreak\n\t\\paragraph{F-test for Regression (significance test for linear regression)}\\mbox{}\\\\\\\\\\\n\tNow comes a part that interests us mainly for practical scientific laboratories tests!!! \n\t\n\tIf your graduate statistical training was anything like mine, you learned ANOVA in one class and Linear Regression in another.  My professors would often say things like \"\\textit{ANOVA is just a special case of Regression}\" but give vague answers when pressed. Let us see why!\n\t\n\tLet us recall that in the section of Statistics we proved that for the one controlled factor ANOVA , the test of equality of means (through the use of the variances) was written (we just change the letter $x$ to $y$ to avoid confusion for the developments that will follow) is given by:\n\t\n\twhich is used to compare, for example, the means of the cash-flows of two supposed independant chosen months (ie with $k=2$) over $10$ years (obviously in the case $k=2$ we could use a Student test if the conditions are of course satisfied!) supposing that for every year for the given month the values are normally distributed:\n\t\n\tTherefore a simple ANOVA with one controlled factor will give according to the calculations proven in the section of Statistics and using a spreadsheet software like Microsoft Excel 14.0.7106 the following results:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/arithmetics/anova_one_factor_for_comparison_with_regression_anova_excel.jpg}\n\t\\end{figure}\n\tBut you might think: Why we go back on such an example ????\n\n\tWell simply because we can very well build a linear regression model of the cash-flows of these two months, which we had not mentioned in the Statistics section! Thus, when we have an ANOVA with a controlled factor, nothing avoid us from making a linear regression of the data with binary explanatory variables (and vice versa)! To do this, it is enough that we rewrite the table above in the following form (dummy coding):\n\t\n\tObviously we not always have in reality binary $(0,1)$ explanatory values but we can always normalize the control variables to fall back on such a situation!\n\t\n\tThis necessarily can be summarized to:\n\t\n\tTherefore the regression model associated with this ANOVA with $1$ control factor at $2$ levels can therefore be written:\n\t\n\tBut, with the preceding relation and the table summarized above, we have a system of two equations with three unknowns ... which is obviously insoluble for a least squares approach. Therefore, the idea consists in sacrificing one of the explanatory variables as(generalizable to more than two variables obviously):\n\t\n\tand therefore (special choice):\n\t\n\tand then we have indeed two equations with two unknowns:\n\t\n\tThis explains the reason why statistical softwares will always give the coefficient of one of the two binary explanatory variables as zero (which obviously can be problematic in some cases and therefore it is enough to force the ordinate at the origin to be zero to have the two non-zero coefficients since then we fall back on a system of two equations with two unknowns). In the case of $k$ binary (dichotomous) explanatory variables, there will be $k - 1$ whose coefficients are non-zero (since one can always be explained by all others).\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe use of ANOVA, you probably guess, is only feasible if the residues are almost normally distributed and homoscedastic ... This is why statistical softwares have outputs giving such analysis when running a F-test for regression. \n\t\\end{tcolorbox}\n\tFinally, all this to say that the ANOVA is only a special case (with binary explanatory variables rather than continuous one and let us recall that $\\mathbb{N}\\in\\mathbb{R}$ not the inverse!) of the linear regression.\n\n\tLet us notice then that we can write:\n\t\n\tand as they are either $0$ or $1$ (or normalized to be such as). Then there remain only the terms $x_{ij}\\hat{\\beta}_j$ where $x_{ij}\\neq 0$ in a quantity that for each $j$ we will denote by $n_j$. It comes then since we only keep the $x_{ij}=1$ (for the last equality if it is not obvious the reader can make an example on a sheet of paper with a simple numerical application!):\n\t\n \twith obviously\\footnote{In our above example $N=20$ and $n_1=n_2=10$} $\\sum_{j=1}^k n_j=N$.\n\n\tBy the method of the ordinary least squares and the values that can take the $x_{ij}$ we quickly see that the coefficients (parameters) of the regression will be given by (we can detail again on reader request):\n\t\n\tand therefore:\n\t\n\tand as in our case in comparison with the one fixed factor ANOVA we have the obvious correspondences:\n\t\n\tit follows, therefore, that there is a correspondence between the numerator of the Fisher test of ANOVA and the equivalent expression of the linear regression (and therefore with the same number of degrees of freedom) that brings us to write:\n\t\n\tBut it remains for us to find the equivalent also of the denominator for the regression. For this we will proceed by similarity. Let us call that in the one fixed factor ANOVA we have proved that:\n\t\n\tand let us recall that for the linear regression, we have proved earlier above (with the corresponding notations in usage):\n\t\n\tFrom what we have seen above we know that degrees of freedom of $\\sum_i (\\hat{y}_i-\\bar{y})^2$ are $k-1$. If follows immediately that for $\\sum_i (y_{i}-\\bar{y})^2$ the degrees of freedom are $N-1$. Then we can write:\n\t\n\tIt then follows that the degrees of freedom of the sum of the squares residuals is then of $N-k$ such that:\n\t\n\tSum of the squares of residues that it is customary to write (useful for later !!!):\n\t\n\tAs $Q_T$ doesn't appear in the Fisher test there is no a priori reason that the equivalent which is SST for regression appears there. By elimination, the correspondence is then immediate:\n\t\n\tThe Fisher test then becomes for the linear regression:\n\t\n\tIt follows than that as for the one-fixed factor ANOVA, with linear regression, we can also make a table of the ANOVA (\\SeeChapter{see section Statistics}) as we will see later with an example!\n\t\n\tNow, let us prove a common and important form of this last relation. We have proved earlier above that the correlation coefficient could also be written in the form:\n\t\n\tHowever, let us notice that:\n\t\n\tHowever, let us recall once again that:\n\t\n \tThus explicitly as we have just seen:\n\t\n\tTherefore we can write:\n\t\n\tWhat we usually can found in some textbooks in the following form:\n\t\n\tWe thus see that if the coefficient of determination $R^2$ is large (close to $1$) then the value of $F$ is large, the linear model will be considered as explaining significantly well the variable explained with respect to the explanatory variable (but this still doesn't mean that there is causality!).\n\t\n\tLet us come back to our companion example! A simple ordinary least squares regression with a spreadsheet software like Microsoft Excel of the below table:\n\t\n\tgives (we make the choice not to force the ordinate at the origin and to take January as an explanatory variable with coefficient not zero otherwise we will not find the value of the calculation of the classic ANOVA seen earlier above):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/anova_approach_univariate_regression_plot_ms_excel.jpg}\n\t\t\\caption{Graphical representation of an univariate regression with the ANOVA approach in Microsoft Excel 14.0.7177}\n\t\\end{figure}\n\tthat is to say:\n\t\n\tWe then have:\n\t\t\n\twith obviously:\n\t\n\tThe calculations of all the classical ANOVA terms of the regression then give still with the same version of Microsoft Excel (the reader can verify by hand using the relations proved earlier above that we find the values given by this spreadsheet software):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/anova_for_regression_in_ms_excel.jpg}\n\t\\end{figure}\n\tand running the one-fixed factor ANOVA we had already introduced a little earlier above we have for comparison:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/arithmetics/anova_one_factor_for_comparison_with_regression_anova_excel.jpg}\n\t\\end{figure}\n\tWe see then the obvious similarity that there  arewith the two approaches!!! This is whey some people say sometimes: \"\\textit{running a regression or an ANOVA are two equivalent thinks (assumed under some given conditions)}\" as in the ANOVA, the categorical variable is effect coded, which means that each category's mean is compared to the grand mean. In the regression, the categorical variable is dummy coded, which means that each category intercept is compared to the reference group intercept! Since the intercept is defined as the mean value when all other predictors $= 0$, and there are no other predictors, the three intercepts are just means.\n\t\n\tIndeed, we have:\n\t\n\t\n\t\\pagebreak\n\t\\subsubsection{Univariate linear regression Gaussian Model}\n\tWe will assume that for an individual $k$ picked randomly from the population, $x_k$ is known without error, and that $y_k$ is a realization of a random variable that we will now denote $Y_k$ and the theoretical least squares regression line will be written now:\n\t\n\twhere $\\varepsilon_k$ is assumed identically distributed and independent residue (no correlation) for each point $k$ according to a centered Normal distribution (zero mean and standard deviation $\\sigma$ for all $k$) such as $\\forall i\\neq j$:\n\\begin{equation}\n  \\addtolength{\\fboxsep}{5pt}\n   \\boxed{\n   \\begin{gathered}\n\t\t\\begin{aligned}\n\t\t\t\\varepsilon_k=\\mathcal{N}(0,\\sigma)\\\\\n\t\t\t\\text{cov}(\\varepsilon_i,\\varepsilon_j)=0\n\t\t\\end{aligned}\n   \\end{gathered}\n   }\n\\end{equation}\n\tSo in other words:\n\t\n\twhere  the residue is defined by the difference between the theoretical ordinates $Y_k$ (considered as random variable) and the measured (experimental) ordinates $y_k$:\n\t\n\tand since by hypothesis $\\varepsilon_k=\\mathcal{N}(0,\\sigma)$, it immediately comes by the stability of the Normal law (\\SeeChapter{see section Statistics}) that:\n\t\n\tThis is why the model is named \"Gaussian linear model\" .... Explicitly, we have:\n\t\n\tThis is why theoretical model is formally denoted: \n\t\n\t\n\tWe will choose the symbol $\\sim$ to say \"follows the law ...\" in what follows immediately in order to avoid any confusion:\n\t\n\tWhich graphically is equivalent to have (so normally the statistical analysis of the Gaussian regression occurs only if and only if we have taken several measures of the dependent variable for fixed and identical values of the independent variables!!!!!!!!):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/arithmetics/gaussian_regression.jpg}\n\t\t\\caption{Graphical representation of the idea behind the Gaussian linear regression}\n\t\\end{figure}\n\tCaution! Since the model is Gaussian, the variable to explain has its domain of definition which is unbounded (support of the Normal distribution). Some companies (especially auditing firms...) wish sometimes to create a simple linear model to model a  probability (that for reminder is bounded in [0,1]) typically for the probability of bankruptcy/default based on various factors (explanatory variables ). Therefore the measured probability must first be turn into $Z$ values (quantiles) of the Normal distribution to have again an infinite range. This type of approach is then named \"\\NewTerm{linear $Z$-score model}\\index{linear $Z$-score model}\".\n\n\tAlmost all statistical analysis software provide a pattern (figure) of residues according to the $x$ values. Thus, these type of figures help to accept or reject the use of a linear Gaussian model:\n\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/residuals.jpg}\n\t\t\\caption{Examples of \"plot\" of residuals}\n\t\\end{figure}\n\n\tIn the above figure, the graph on the top left is what we should expect to be able to apply statistical tests the Gaussian linear model. The graph on the top right shows that the residuals variance is not constant and therefore the violation of the assumption homoscedasticity. The graph at the bottom left shows that the variance is constant but that our model has missing endogenous variables that added could perhaps explain the shift that that grows up linearly. The graph at the bottom right indicates a constant variance, but the model look like to be more nonlinear than linear.\n\n\tPrevious assumptions about the moments of residues (mean, variance) are named \"\\NewTerm{Gauss-Markov assumptions}\\index{Gauss-Markov assumptions}\" and the particular hypothesis of equal variances is named as we saw it in the section Statistics \"\\NewTerm{homoscedasticity}\\index{homoscedasticity}\" (while the fact that the variances are not equal is named for reminder \"heteroskedasticity\").\n\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\\textbf{R1. }The majority of softwares (including Microsoft Excel 11.8346) propose a graph which shows the residuals in function of the ordinate values x. Obviously, it is better that the points representing the residues are not too divergent ... otherwise the homoscedasticity assumption will be not satisfied.\\\\\n\n\\textbf{R2.} Practitioners sometimes transform the endogenous and exogenous variables by a logarithmic or exponential function or other to try to stabilize the residuals as most as possible.\n\t\\end{tcolorbox}\t\n\t\n\t\\begin{theorem}\n\tWe have through the property of the mean (\\SeeChapter{see section Statistics}):\n\t\n\t\\end{theorem}\n\tThen under the above assumptions, we will show that $a$ and $b$ are unbiased estimators (see section Statistics) of $\\alpha$ and $\\beta$ and it is possible to estimate the standard deviation from the SSR which is an important result named \"\\NewTerm{Gauss-Markov theorem}\\index{Gauss-Markov theorem}\".\n\t\n\tBefore seeing the proof let us do a recall and give some definitions of the variables that we have already handled and the new one that we will handle (if the vocabulary seems technical to the reader then it should read or reread the sections of Probabilities and Statistics):\n\t\n\t\n\t\n\t\\begin{dem}\n\tAccording to the adopted model, $a$ must now be regarded as a realization of the random variable given by (shown above as the ratio of the covariance and variance):\n\t\n\tand $b$ as a realization of the random variable given by:\n\t\n\tSo we differentiate random and non-random coefficient values by passing the lowercase notation in uppercase (as it is the tradition in the field of Statistics).\n\t\n\tTaking into account that theoretical dependent (endogenous) variable is considered as the realization of a random variable is therefore given by:\n\t\n\twe can put $A$ in the form:\n\t\n\tTherefore:\n\t\n\t\n\tAnd for $B$:\n\t\n\tTherefore and using also the definitions:\n\t\n\twith the same conclusion.\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\tSo the expected mean of $A$ and $B$ are unbiased estimators (i.e.. with minimum variance as seen in the section of Statistics) of. As they are estimators, in the literature, they are often noted $\\hat{a},\\hat{}$ and therefore it comes the common alternative notation:\n\t\t\n\tFinally, we must also calculate the variances of $A$ and $B$ using its properties (\\SeeChapter{see section Statistics}) and the assumptions on the residuals, we have:\n\t\n\tAs by assumption we have all $\\text{V}(\\epsilon_k)$ are equal and there is no autocorrelation, we can write:\n\t\n\tAnd if $n$ is large enough we will write:\n\t\n\tBefore determining the variance of $B$, remember that by hypothesis:\n\t\n\ttherefore by the property of linearity of the Normal distribution, the random variables $A$ and $B$ also follow a Normal distribution.\n\t\n\tAfter the recall of this assumption, it follows immediately (\\SeeChapter{see section Statistics}):\n\t\n\tTherefore:\n\t\n\tRemember the Huygens theorem (\\SeeChapter{see section Statistics}):\n\t\n\tin the case of equitable probabilities (Normal Law estimator of the mean as prove in the section Statistics).\n\t\n\tFinally we have:\n\t\n\twhere obviously the notation of the variance in the denominator is very unfair (because $x$ is not a random variable in this model) but very convenient to condense the notation.\n\t\n\tThe problem now lies in determining $\\sigma_\\epsilon^2$. Obviously to do this we will be forced to go through a statistical estimator.\n\t\n\tWe know we can write according to what was seen in the section Statistics regarding to estimators:\n\t\n\tbecause the Normal distribution is centered for residuals and therefore $\\bar{\\epsilon}=0$... and the residue is implicitly dependent of two the sum of two random variable that are $A$ and $B$ this is why we have a $-2$ and the denominator of the first fraction (we have to take away two degrees of freedom).\n\t\n\tLet us also indicate that in practice we frequently note the last result by mixing the notations of the random and deterministic appearance (hence noting everything with lower case):\n\t\n\twhere SEE means \"\\NewTerm{Standard Error of Estimate}\\index{Standard Error of Estimate}\" or sometimes also named  the \"\\NewTerm{standard regression error}\\index{standard regression error}\" which is obtained with the English version of Microsoft Excel trough square of the function \\texttt{STEYX( )}.\n\t\n\tSo we have to summarize the unbiased estimators variances of $A$ and $B$:\n\t\n\trelations which are therefore only valid for a linear regression with one unique explanatory variable (and under the assumptions of the Gaussian linear model). Knowing that by construction of the initial hypothesis that $A$ and $B$ follow a Normal distribution of respective expected mean $\\alpha,\\beta$ and whose variance is given just above, so we know completely the distribution that characterizes them.\n\t\n\tWhat is nice knowing these variances is that we can also therefore easily estimate the variance of the dependent variable in our regression (using the properties of the variance proved in the section Statistics).\n\t\n\tIt would be interesting to make statistical inference on the mean of the parameters $A$ and $B$ (i.e. the slope and intercept) given their known empirical mean (i.e. average). For this, remember that we have proved in the section Statistics the following confidence interval:\n\t\n\tt follows by making a parallel like engineers and physicists like to d ... that as $A$ is an unbiased estimator of the average of the slope $a$ and that:\n\t\n\tis in fact the standard error of the mean $A$, then by analogy:\n\t\n\tand then (this is an reasoning to be take with caution an it is better to use the developments that will follow later):\n\t\n\twhich therefore gives the confidence interval of the slope of a linear Gaussian with one unique explanatory variable (that's what gives Microsoft Excel 11.8346 for each coefficient). The approach is the same for the intercept.\n\t\n\tWarning! If the explanatory variable is a random variable, then we use naively (the are more accurate and correct model that we will see later when the explanatory variable is a also a random variable):\n\t\n\t\n\tIn the case of a linear regression with several explanatory variables, therefore assimilate to the concept of \"\\NewTerm{degrees of freedom DoF}\\index{degrees of freedom}\", the idea is the same but the calculations are longer (we don't have yet the will to do the mathematical developments for this case).\n\t\n\tFinally, remember that we got for the empirical correlation coefficient:\n\t\n\tWe then verbatim get the famous confidence interval of the correlation coefficient:\n\t\n\tYou should know that as calculate the confidence interval for the slope or the correlation coefficient is equivalent, many softwares (Tanagra, Minitab, Excel, etc.) which give only the value of the Student's distribution at the critical value of this latter only for the slope and assume that the reader knows that it is the same for the correlation coefficient.\n\t\n\t\\paragraph{Pearson Correlation Coefficient Test}\\mbox{}\\\\\\\\\\\n\tThe calculation obtained above for the confidence interval of the correlation coefficient is a little difficult in practice. It is for this reason that many practitioners and statistical software implements a very simple alternative communicated only in the minimal form that is the $p$-value.\n\t\n\tTo see this approach, remember that we proved in the section of Statistics that (this time we will adopt the correct notation...):\n\t\n\tAnd we saw just above that:\n\t\n\tSimilarly, we have the Pearson correlation coefficient estimator which is (using here the various the possible notations that we can find in the literature...):\n\t\n\tand therefore:\n\t\n\tThe hypothesis test we want to do is therefore:\n\t\n\tand therefore equivalent to:\n\t\n\tthe null hypothesis obviously being that the Pearson correlation is statistically significantly different from zero. So this is a bilateral test!\n\t\n\tTo find a simple form of the test, remember that we obtained:\n\t\n\tand also:\n\t\n\twhich brings us mixing the two to have:\n\t\n\tTherefore:\n\t\n\tBut we remember that we have also proved that if $n$ is large enough:\n\t\n\tBuf if $n$ is small we fall back on:\n\t\n\tTherefore:\n\t\n\tand with the null hypothesis $a=0$, we get:\n\t\n\t\n\tBe careful with the use of this test often and logically named \"\\NewTerm{Student's t-test for univariate regression slope}\\index{Student's t-test for univariate regression slope}\" or \"\\NewTerm{t-test for coefficient slope}\\index{t-test for coefficient slope}\", depending if the Pearson correlation coefficient is negative or positive and don't forget that it is bilateral.\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Examples:}\\\\\\\\\n\tE1. We have calculated for a series of data a positive Pearson correlation coefficient $R$ of value $0.298$ and the explanatory variable has $7$ values. So we have with the English version Microsoft Excel 11.8346 the $p$-value that is given by (we find exactly the same value as with Minitab 15.1.1):\\\\\n\t\n\t\\texttt{=2*(1-T.DIST(0.298/SQRT((1-0.298\\string^2)/(7-2));7-2;1))\\\\=2*(1-0.741869)=0.51626}\\\\\n\t\n\tIn this case we sadly can't reject the null hypothesis as what the Pearson correlation coefficient is equal to zero at a threshold of $5\\%$.\\\\\n\n\tE2. We have calculated for a data set a positive Pearson correlation coefficient $R$ of  $-0.084$ and the explanatory variable contains $19$ values. So we have with the English version of Microsoft Excel 11.8346 the $p$-value that is equal to (we find exactly the same value as with Minitab 15.1.1):\\\\\n\t\n\t\\texttt{=2* T.DIST((-0.084)/SQRT((1-(-0.084)\\string^2)/(19-2));19-2;1)\\\\=2*(1-0.366)=0.74186}\\\\\n\t\n\tIn this case we also sadly can't reject the null hypothesis as what the Pearson correlation coefficient is equal to zero at a threshold of 5%.\n\t\\end{tcolorbox}\n\tThis small trap makes that finally we take the absolute value of the Pearson correlation coefficient and we therefore use the always the same calculation method.\n\t\n\t\\paragraph{Confidence interval of predicted values}\\mbox{}\\\\\\\\\\\n\tWe wish for each measured value of the dependent variable, know the confidence interval. In other words, we would like to know the statistical variance estimator of $Y$ (we do not write the subscripts anymore to save time):\n\t\n\tUnfortunately, we will go into the wall because the covariance is difficult to calculate ($A$ and $B$ are not independent as shown by the expressions we got previously).\n\t\n\tBy cons, being a good observer, we see that if we use the result seen above:\n\t\n\tThen:\n\t\n\tThe problem being circumvented, we now have using the propeties of variance:\n\t\n\tTherefore:\n\t\n\tThe we have finally:\n\t\n\tNow let us recall (\\SeeChapter{see section Statistics}) that:\n\t\n\tand as $Y$ is distributed according to a Normal distribution for whose the unbiased estimator of the mean and standard deviation are given by the prior-previous  relation it comes immediately:\n\t\n\tIn practice you must also check that this ration follows a Normal distribution in order to make the confidence intervals and statistical tests that follow.\n\t\n\tLet us recall now that we have proved in the section Statistics that:\n\t\n\tfollows a Student law of degrees of freedom $k$ and the variable $U$ follows a chi-square law of degree of freedom $k$.\n\t\n\tNow let us come back to the expression of the $Z$ obtained above and remember that:\n\t\n\tTherefore:\n\t\n\tBut as we have the assumption:\n\t\n\tTherefore:\n\t\n\tand obviously:\n\t\n\tcorresponds to a sum of squares of reduced centered Normal laws. And therefore according to what we proved in section Statistics it follows that:\n\t\n\tTherefore:\n\t\n\tThat is to say:\n\t\n\tThis is one reason why many statisticians note directly and without detours:\n\t\n\t\n\tWhich is not necessarily obvious at first glance. This is why, following the request of a reader, we have detailed a little bit exaggeration, the mechanism behind this involvement.\n\t\n\tThis done, we have finally:\n\t\n\tand we deduce from this immediately a bilateral confidence interval of a given threshold level $\\alpha$ for a fixed $x$ whose expression is:\n\t\n\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe same kind of development can be done for the slope and the intercept. This is why software like Microsoft Excel, SPSS, Minitab, Statistica, etc. give the value of the Student t-distribution as well as the confidence interval for a given threshold level $\\alpha$. But for this to be meaningful, you must never forget that all the assumptions of the model must be met.\n\t\\end{tcolorbox}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/regression_confidence_interval.jpg}\n\t\t\\caption{Print screen of a confidence interval obtained with Minitab 15}\n\t\\end{figure}\n\tThe reader will have noticed that:\n\t\\begin{itemize}\n\t\t\\item it is very boring to obtain without software or without coding the plot of the confidence interval for the ordinary least squares since we have to calculate it for each point...\n\t\t\n\t\t\\item the confidence interval is curved which is sometimes considered as common sense, at least in the temporal version of the regression: furthest is the forecast less accurate it will be\n\t\\end{itemize}\n\t\n\tThe true value of $Y$ is given by:\n\t\n\twith the variance:\n\t\n\twhich is independent of the estimator $Y$. Therefore, the difference between $Y$ and $y$ (therefore between estimator and real value) has for variance:\n\t\n\tTherefore it is customary to consider that the  \"\\NewTerm{prediction interval}\\index{prediction interval}\" (not to be confused with the confidence interval of the estimator) is taken as:\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe same kind of development can be done for the slope and the intercept. This is why software like Microsoft Excel, SPSS, Minitab, Statistica, etc. give the value of the Student t-distribution as well as the confidence interval for a given threshold level $\\alpha$. But for this to be meaningful, you must never forget that all the assumptions of the model must be met.\n\t\\end{tcolorbox}\n\tThis gives us the following type of chart with a software such as Minitab 15:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1.2]{img/computing/regression_prediction_interval.jpg}\n\t\t\\caption{Print screen of a prediction interval (PI) in green obtained with Minitab 15}\n\t\\end{figure}\n\tWhere we can see the prediction interval PI in green and the confidence interval CI in red and its is obvious to see by the property of the variance that CI<PI.\n\t\n\tSo what must be well understand by the reader so far, is that if we are dealing with univariate linear regression or any other type of regression and want to plot the following data that corresponds to a sample for each $x$-value:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.7]{img/computing/regression_excel_list_data_sample.jpg}\n\t\\end{figure}\n\tTherefore using a spreadsheet software to make a plot of that the average of each year as following (most common case see in Fortune 500 companies by top managers and also by auditing companies like KPM and EY):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/regression_excel_sample_plot.jpg}\n\t\\end{figure}\n\tusing a smooth chart is everything but scientific. Indeed:\n\t\\begin{enumerate}\n\t\t\\item No spreadhseet software is able to summary the data list above automatically in quick an efficient way (with Microsoft Excel even Pivot Charts cannot do smooth scatter charts of such a list of data...).\n\t\t\n\t\t\\item Smooth scatter plot in spreadsheet softwares use splines interpolation and these are not statistical models that can be used for samples! So reading such charts in a spreadhseet software introduce a huge deterministic bias in the mind of the board committee or any customer/supplier.\n\t\t\n\t\t\\item As the averages come from samples there is an implicit confidence interval THAT HAS TO BE SHOWN to the board committee or customer/supplier. Do not show a confidence interval on sample data is a high-school level error that is not acceptable when done by a senior manager or business analyst or even a consultant of a big $5$ auditing companies.\n\t\\end{enumerate}\n\tSo following the detailed steps given in our R companion book we get something truly scientific and robust that is:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.7]{img/computing/regression_r_sample_plot.jpg}\n\t\\end{figure}\n\t\n\t\\pagebreak\n\t\\subsubsection{Linear univariate regression forced through the origin}\n\tOne very common case and requested case in laboratories (and generally in other departments) of companies, is to force the linear regression through the origin.\n\t\n\tWe will see now (in the univariate case) that the approach is only a simplified variant of the method of the ordinary least squares.\n\t\n\tWe use as before:\n\t\n\twhere $n$ is the number of points. But this time, let us write:\n\t\n\tthen:\t\n\t\n\tThis relation make appears the sum of squared deviations as a function of the parameter $a$. When this function is minimal (extremal), the derivatives with respect to its parameters are canceled:\n\t\n\tAfter simplification:\n\t\n\tFinally:\n\t\n\tYou can also easily check with any spreadsheet software (Microsoft Excel for example) that the calculations corresponds well.\n\t\n\t\\pagebreak\n\t\\subsubsection{Deming regression (orthogonal regression)}\n\tAs we have already mention it, the \"\\NewTerm{orthogonal linear regression model}\" \\index{orthogonal linear regression} or \"\\NewTerm{Deming regression}\"\\index{Deming regression}  is used as complement to the paired $t$-test to check the stability of the measuring instruments in laboratories. This is a case where the explanatory and dependent variables are tainted with uncertainty.\n\t\n\tWe will see now the derivation of the maximum likelihood estimates related to the Deming regression model. It is based on the book \\textit{Models in regression and related topics} (chapter three), from 1969 by Peter Sprent, but with more detailed calculations included (big thanks to Anders Jensen for the \\LaTeX code of the proof!).\n\n\tThe mathematical model $\\eta=\\alpha+\\beta\\xi$ describes a linear\n\trelationship between two variables $\\xi$ and $\\eta$. Observations $x$\n\tand $y$ of two variables are usually described by a regression of $y$\n\ton $x$ where $x$ is assumed to be observed without error (or,\n\tequivalently using the conditional distribution of $y$ given $x$). In\n\tlinear regression with observations subject to additive random\n\tvariation on both $x$ and $y$ and observed values for individuals\n\t$(x_i,y_i), i=1,\\ldots,n$, a model may be written:\n\t\n\twhere $e_{xi}$ and $e_{y_i}$ denotes the random part of the model.\n\tThis is known as a functional relationship because the $\\xi_i$'s are\n\tassumed to be fixed parameters, as opposed to a structural\n\trelationship where some distribution for the $\\xi_i$'s is assumed. In\n\tthe following it is assumed that the $e_{xi}$s are iid with:\n\t\n\tand that the $e_{yi}$s are iid with:\n\t\n\tfor some $\\lambda>0$. Furthermore $e_{xi}$ is assumed to be independent of $e_{yi}$.\n\t\n\tThe aim of this document is to derive the maximum\n\tlikelihood estimates for $\\alpha, \\beta, \\xi_i$ and $\\sigma^2$ in the functional model stated above.\n\n\tThe likelihood function:\n\t\n\tdenoted $f$ is:\n\t\n\tand the loglikelihood, denoted $L$, is:\n\t\n\tIt follows that the likelihood function is not bounded from above when $\\sigma^2$ goes to $0$, so in the following it is assumed that $\\sigma^2>0$.\n\n\tLet us solve for $\\xi_i$ now! The differentiation of $L$ with respect to $\\xi_i$ gives:\n\t\n\tSetting $\\frac{\\partial L}{\\partial \\xi_i}$ equal to zero yields:\n\t\n\tSo to estimate $\\xi_i$, estimates for $\\beta$ and $\\alpha$ are needed. Therefore focus is turned to the derivation of $\\hat{\\alpha}$.\n\n\tLet us now solve for $\\alpha$. The differentiation of $L$ with respect to $\\alpha$ gives:\n\t\n\tand putting $\\frac{\\partial L}{\\partial \\alpha}$ equal to zero yields to:\n\t\n\tNow one can use:\n\t\n\tto dispense with $\\xi_i$\n\t\t\n\t\n\tHence the estimate for $\\alpha$ becomes\n\t\n\n\tSolving for $\\beta$ by differentiating  $L$ with respect to $\\beta$ gives\n\t\n\tSetting $\\frac{\\partial L}{\\partial \\beta}$ equal to zero yields\n\t\n\tand using again:\n\t\n\twe get:\n\t\n\tThis implies that:\n\t\n\tDividing with $\\lambda$ and using the fact that:\n\t\n\tit is seen that\n\t\n\tSplitting up the sums even more gives:\n\t\nFinally the terms are sorted and collected according to powers of $\\beta$:\n\t\n\tSince:\n\t\\begin{itemize}\n\t\t\\item\n\t\t$\\displaystyle\\sum_{i=1}^n\\overline{x}.^2\n\t\t-\\overline{x}.\\displaystyle\\sum_{i=1}^nx_i=0$\n\t\t\\item\n\t\t$\\overline{y}.\\displaystyle\\sum_{i=1}^nx_i\n\t\t-\\displaystyle\\sum_{i=1}^nx_iy_i\n\t\t-2\\displaystyle\\sum_{i=1}^n\\overline{y}.\\overline{x}.\n\t\t+2\\displaystyle\\sum_{i=1}^ny_i\\overline{x}.=-\\text{SPD}_{xy}$\n\t\t\\item\n\t\t$\\displaystyle\\sum_{i=1}^ny_i^2\n\t\t-\\lambda\\displaystyle\\sum_{i=1}^nx_i^2\n\t\t+\\displaystyle\\sum_{i=1}^n\\overline{y}.^2\n\t\t-2\\displaystyle\\sum_{i=1}^ny_i\\overline{y}.\n\t\t+\\lambda\\overline{x}.\\displaystyle\\sum_{i=1}^nx_i\n\t\t=\\text{SSD}_y-\\lambda\\text{SSD}_x$\n\t\t\\item\n\t\t$\\displaystyle\\sum_{i=1}^nx_iy_i\n\t\t-\\overline{y}.\\displaystyle\\sum_{i=1}^nx_i=\\text{SPD}_{xy}$\n\t\\end{itemize}\n\tit is clear that the derivation of $\\beta$ comes down to solve:\n\t\n\tFor $\\text{SPD}_{xy}\\neq 0$ this implies that:\n\t\n\tSince:\n\t\n\tthere is always a positive and a negative solution to (\\ref{equation}). The desired solution should always have the same sign as $\\text{SPD}_{xy}$, hence the solution with the positive numerator is selected. Therefore\n\t\n\n\tLet us solve for $\\xi_i$ - again... With estimates for $\\beta$ and $\\alpha$ it is now possible to estimate $\\xi_i$ using:\n\t\n\twe get:\n\t\n\n\tLet us now solving for $\\sigma^2$ by differentiating $L$ with respect to $\\sigma^2$ gives:\n\t\n\tand setting $\\frac{\\partial L}{\\partial \\sigma^2}$ equal to zero yields\n\t\n\tTo get a central estimate of $\\sigma^2$ one must divide by $n-2$\ninstead of $2n$ since there are $n+2$ parameters to be estimated,\nnamely $\\xi_1,\\xi_2,\\ldots,\\xi_n,\\alpha$ and $\\beta$. Hence the\ndegrees of freedom are $2n-(n+2)=n-2$. Therefore:\n\t\n\tFinally summing up:\n\t\n\tThese results are implemented in Minitab 16.1.2 and also in the \\texttt{Deming()} function in the MethComp package of R as the ready can see it in the corresponding companion books.\n\n\t\\subsubsection{Multiple linear regression Gaussian Model}\n\tOf course, in some situations, linear regression is too simple or just not suitable. The most typical case that will concern us now in what follows are the situations where we have several explanatory variables (multivariate case!).\n\t\n\tThe idea of multiple linear regression is relatively simple. We want to determine the dependent variable $y$ from $p-1$ independent variables (i.e. in the absence of \"colinearity\"!) - and therefore of $p$ parameters to determine - connected by a linear relation of the general form:\n\t\n\tIn a sample of $n$ individuals we measure $y_i,x_{i,1},...,x_{i,p-1}$ for $i=1..n$:\n\t\n\tIn fact, the to estimate the parameters $\\beta_0,...,\\beta_{p-1}$ (estimated values which we denote by $\\hat{\\beta}_0,...,\\hat{\\beta}_{p-1}$ to respect traditions) the approach is very simple because it is just a generalization of the method of least squares we saw earlier for the simple univariate linear regression.\n\t\n\tSo in the end we rewrite the relation of Sum of Squared Residuals seen above by modifying a little bit because we now have the multilinear stuff:\n\t\n\twith the estimated theoretical model:\n\t\n\tSo we have to minimize:\n\t\n\tThe above parentheses can be rewritten in the form (using what we learned in Vector Calculus and Linear Algebra sections):\n\t\n\tWhose condensed form is:\n\t\n\tWe then have the vector of residues that can be written:\n\t\n\tAs we know, the least squares method is to find the vector $\\vec{\\hat{\\beta}}$ that minimizes:\n\t\t\n\tTherefore explicitly:\n\t\n\tNotice that we have:\n\t\n\tand:\n\t\n\tas each of the elements of the multiplication is a simple vector!\n\t\n\tTherefore we have (caution! do not forget that some multiplications in the relation that will follow are dot products!!!) the quadratic multivariate function of coefficients of vectors:\n\t\n\tLet us derivate this latter \"object function $F$\" at the order of vector $\\hat{\\beta}$ (it is as internal derivative component by component). What we will write:\n\t\n\tNow let us rewrite this form a vector notation to a pure matrix notation:\n\t\n\tWe seek the $\\vec{\\hat{\\beta}}$ that cancel this derivative. Therefore we must solve the following equation:\n\t\n\tTherefore:\n\t\n\tRemember before we continue that:\n\t\n\tTherefore the prior-previous relation can be written:\n\t\n\tA Linear Algebra is associative, let us write without the parenthesis:\n\t\n\tWe can obviously not simplify right and left by $\\vec{u}^TX^T$ as it is not a squared matrix, this term is then by obligation not reversible. The only one thing we cam do is identify the elements such that:\n\t\n\tthis implies obviously:\n\t\n\tWe find then that if the squared matrix $X^TX$ est reversible then:\n\t\n\tThe matrix $X^TX$ that we wil see again in the field of multiple linear regression and in the field of design of experiments (\\SeeChapter{Industrial Engineering}) is named \"\\NewTerm{information matrix}\\index{information matrix}\" or \"\\NewTerm{dispersion matrix}\\index{dispersion matrix}\" for a reason that will be very obvious later.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tWe say that the regression is \"\\NewTerm{balanced and orthogonal}\\index{balanced and orthogonal}\" when the information matrix is diagonal. We say that the regression is \"\\NewTerm{orthogonal}\\index{orthogonal}\" when the sub-matrix of the information matrix excluding the first row and first columns is orthogonal. We say that the regression is just \"\\NewTerm{balanced}\\index{balanced}\" when all the values of the first row and of the first column excepted the one at the intersection are equal to zero.\n\t\\end{tcolorbox}\t\n\tTo show that this seem correct a priori, let us fall back on the results we get of the simple univariate regression:\n\t\n\tThen supposing 2 observations, we have therefore:\n\t\n\tUsing the relation proved in the section of Lienar Algebra to calculate in generality the inverse of a matrix $A(a_{ij})$ in $A^{-1}(b_{ij})$:\n\t\n\tWe have in our special case:\n\t\t\n\tTherefore we have:\n\t\n\tand since we have a square matrix of dimension $2$ only, the calculation of the four determinants is reduced to selecting the components of $X^TX$ (\\SeeChapter{see section Linear Algebra}):\n\t\n\tTherefore:\n\t\n\tSo to a change in notations for the indeces and experimental measurements, we fall back on the results that we obtained during our study of the simple linear univariate regression that was (for refresh...):\n\t\n\tNow, we need a quality indicator regarding our multilinear regression. Remember that in the context of our study of the univariate linear regression, we proved that the linear correlation coefficient can be written as:\n\t\n\tand in fact it also applies directly to the multiple linear regression, since it does not presuppose the number of explanatory variables!!\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe reader interested in the practical application of these results may, just as for simple univariate regression, refer to the server exercises on the companion website - Numerical Methods section - where there are practical examples with Microsoft Excel.\n\t\\end{tcolorbox}\t\n\tObviously with multiple linear regression, we can now, with a small tip, do linear regression ... of polynomials (we will see later how to apply directly the ordinary least squares method on a polynomial). Indeed, consider a polynomial of the form:\n\t\n\tThat we can consider as be rewrittent it as:\n\t\n\tSo in tabsheet softwares like Microsoft Excel, just use the Regression Analysis Tool with the input variable $x$ column, a second column that we will have taken care to create with inside the square of $x$ (i.e. $x^2$) and which will be considered as the explanatory variable $w$ and a third column we have also taken care to create as the cube of $x$ (i.e. $x^3$) and which will be considered as the explanatory variable $z$.\n\t\n\tWe can also directly obtain the polynomials coefficients with functions already presented earlier above with Microsoft Excel (but you will not have all the relevant results of the Analysis Tool). For example for a polynomial of second degree:\n\t\n\t\\texttt{a: =INDEX(LINEST(y,x\\string^{1,2}),1)\\\\\n\tb: =INDEX(LINEST(y,x\\string^{1,2}),1,2)\\\\\n\tc: =INDEX(LINEST(y,x\\string^{1,2}),1,3)\n\t}\n\t\n\tand for a third-degree polynomial:\n\t\n\t\\texttt{a: =INDEX(LINEST(y,x\\string^{1,2,3}),1)\\\\\n\tb: =INDEX(LINEST(y,x\\string^{1,2,3}),1,2)\\\\\n\tc: =INDEX(LINEST(y,x\\string^{1,2,3}),1,3)\\\\\n\td: =INDEX(LINEST(y,x\\string^{1,2,3}),1,4)}\n\t\n\tThis is this trick that allows us to understand why and how the linear correlation coefficient also applies to polynomials in most spreadsheets softwares and statistical softwares. However we can have a more direct approach that does not require this transformation but which therefore is a little longer.\n\t\n\tNow let us go back to the Gaussian linear model with a concept a little more rigorous and adapted to the multilinear case and in particular to highlight the distinction between estimators of the slope of the regression and exact values:\n\t\n\tBut under this notation convention we have:\n\t\n\tand written it in vector form:\n\t\n\tNow, we use the technique of maximum likelihood (\\SeeChapter{see section Statistics}) and we seek the coefficients that maximizes therefore:\n\t\n\tWhat we can write in matrix form:\n\t\n\tTaking as in the section of Statistics the log-likelihood to facilitate future calculations and using the property of the transposed matrices proved in section of Linear Algebra, we get:\n\t\n\tNow let us look to the expression of $\\vec{\\beta}$ that maximizes the log-likelihood. It comes then:\n\t\n\tLet us use the property of the transposed matrix proved in the section of Linear Algebra:\n\t\n\tTherefore we have:\n\t\n\tFor reasons which will appear evident a little further below we chose the second equivalence. Therefore, we have (and remembering that seeking for an optimum is equivalent to have partial derivative equal to zero):\n\t\n\tTherefore:\n\t\n\tThat is to say, after rearrangement:\n\t\n\tThat is to say exactly the same expressions that we got just a little earlier above with the least squares method in the multilinear case and that was for reminder:\n\t\n\tThis shows that the statistical of the linear model by the maximum likelihood can fall back into the multilinear case (and thus also the univariate case) on the results of the least squares method. This has something almost divine ...\n\t\n\tFinally, let us indicate that we find here the almost famous \"\\NewTerm{hat matrix}\\index{hat matrix}\" or \"\\NewTerm{influence matrix}\\index{influence matrix}\" $H$ that connects alone all information between the real and explained theoretical values (and depending only on $X$!) and therefore verbatim the error of the theoretical model:\n\t\n\tWe have then something interesting to observe:\n\t\n\tBy definition, the influence of the observation $i$ in the regression and named the  \"\\NewTerm{leverage}\\index{leverage}\" (or \"\\NewTerm{leverage score}\\index{leverage score}\") is defined by:\n\t\n\tIt is a qualitative method (available in many statistical softwares) to judge the influence of points that could be considered as outliers. The idea is to compare the values of leverage between them. A point that admit a leverage more than twice its average (three times for small samples) is suspect.\n\t\n\t\\paragraph{Variance Inflation Factor (multicolinearity)}\\mbox{}\\\\\\\\\n\tIn statistics, the \"\\NewTerm{variance inflation factor (VIF)} quantifies the severity of multicollinearity in an ordinary least squares regression analysis. It provides an index that measures how much the variance (the square of the estimate's standard deviation) of an estimated regression coefficient is increased because of collinearity.\n\n\tTo start, the reader must know that during our study of Principal Component Analyses (PCA) further below we will proved in a trivial way that the variance-covariance matrix is given by (yes ... the present text on the VIF is more recent than the one drafted on the PCA then not to rewrite the same ... we refer to reader to it):\n\t\n\tAnd as the matrix of correlations is given by (\\SeeChapter{see section Statistics}):\n\t\n\tThen we get:\n\t\n\tThe ideal would also be to be able to put the inverse of the standard deviations in a matrix form in order to have a totally matrix expression. After some trial and error we quickly find that we can write the correlation matrix in the form:\n\t\n\twhere $S^{-1}$ is the usual notation to say that it is the diagonal matrix containing the inverse of the $\\sigma_j$, or explicitly (so that it is clear to the reader!):\n\t\n\tSo for now, we have two relations (out of three ... waiting for the proof of the third one) that will be very useful to us (attention the components of the vectors of the explanatory variables are always centered henceforth what implies a forced linear regression by the origin!):\n\t\n\tNow let's start from:\n\t\n \tand let us rewrite this in a somewhat more explicit form:\n\t\n\tTherefore:\n\t\n\tWe understand now better why $(X_c^TX_c)^{-1}$ is often named \"\\NewTerm{dispersion matrix}\\index{dispersion matrix}\" as we already mentioned above.\n\n\tLet us now take the matrix of the covariance-variances matrix of the coefficients:\n\t\n \tUsing the following property of the transposed matrices proved in the section Linear Algebra:\n\t\n\twe then have using this property this property a first time:\n\t\n\tand using it a second time:\n\t\n\tUsing now the following property proven in the section Linear Algebra:\n\t\n\tWe then have:\n\t\n\tand reusing:\n\t\n\tit comes:\n\t\n\tUsing the associativity property of the matrix product, we will write:\n\t\n\tAnd by taking out the elements which are not random variables of the expected mean, it comes:\n\t\n\tIt is often traditional (in spite of the confusion) possible to write this last result in the following form which we will see (and use) in the section of Industrial Engineering during our study of the Box-Behnken experimental designs:\n\t\n\tThis last matrix contains in the diagonal the general expression in the general case of multilinear regression the \"\\NewTerm{Standard Error of Estimate (SSE)}\\index{standard error of estimate}\" or more commonly named the \"\\NewTerm{standard error of the regression}\\index{standard error of the regression}\" (relation that uses among other the spreadsheet software Microsoft Excel in the case of the multilinear regression for the column \"Standard error\" of the coefficients ... except that it takes the square root to have the standard deviation and not the variance!) . If the linear regression is not forced at the origin, it will obviously be necessary to use obviously:\n\t\n\twith for recall:\n\t\n\twhere $k$ is for recall the number of coefficients of the multiple linear model.\n\n\tWe have now three important relations:\n\t\n\tLet us take up the first relation and manipulate it a little bit:\n\t\n\tIt comes when:\n\t\n \tAnd using the property proved in the section Linear Algebra:\n\t\n\tThen we have:\n\t\n\tBy substituting the right-hand term for equality in the third of the equalities, we then have:\n\t\n\tIf we denote by $\\text{V}\\left(\\vec{\\hat{\\beta}}\\right)$ the $j$-th diagonal element of the covariance-variance matrix of the $\\vec{\\hat{\\beta}}$ and $\\text{VIF}_j$, ,the \"\\NewTerm{Variance Inflation Factor (VIF)}\\index{variance inflation factor}\", the $j$-th diagonal element of the matrix $R^{-1}$ then it trivially follows that:\n\t\n\tHowever, normally the components of the covariance-variance matrix are estimators and not the true values. So we have instead in practice:\n\t\n\tHowever, we must find the explicit formulation of the $\\text{VIF}_j$. For this, let us recall that $R$ is a positive definite symmetric matrix (\\SeeChapter{see section Linear Algebra}). Let us, for example, calculate the inverse of such a matrix of dimension $2\\times 2$ explicitly by using the relation proved in the section Linear Algebra that is for recall:\n\t\n\tIn the special case that interests us, we have then:\n\t\n\tand since the correlation matrix is symmetric and unit diagonal, we have:\n\t\n\tIt comes then that if we focus on the elements of the diagonal:\n\t\n\tAnd the reader can check that regardless of the size of the matrix, the $\\text{VIF}_j$ will always be of the form:\n\t\n\tIn the case of $2\\times 2$ correlation matrix there is therefore only one coefficient $\\text{VIF}_j$ for the simple and good reason that the associated linear regression has only one coefficient ... Caution! Too many textbooks give the following relation for the general case:\n\t\n\tBut this is false as far as I know because the actual expression is much more complex. \n\n\tMost statistical software simply uses the following relation:\n\t\n\tTherefore:\n\t\n\tEither in the case where the data are such that the regression is not forced at the origin:\n\t\n\tTherefore the version I prefer to use and to teach (especially for customers and students having only a spreadsheet software at their disposition is):\n\t\n \tand as all terms are known to us in practice, the calculation of the $\\text{VIF}_j$ doesn't make us problems anymore!\n\tA rule of thumb is that if $\\text{VIF}_j>10$ then multicollinearity is high.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tSome software instead calculates the tolerance which is just the reciprocal of the VIF. The choice of which to use is a matter of personal preference.\n\t\\end{tcolorbox}\n\tThe square root of the variance inflation factor finally indicates how much larger the standard error is, compared with what it would be if that variable were uncorrelated with the other predictor variables in the model.\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tIf the variance inflation factor of a predictor variable were $5.27$ ($\\sqrt{5.27} = 2.3$) this means that the standard error for the coefficient of that predictor variable is $2.3$ times as large as it would be if that predictor variable were uncorrelated with the other predictor variables.\n\t\\end{tcolorbox}\n\t\n\t\\subsubsection{Polynomial regression}\n\tWe will now see how to determine the for example of the best second degree polynomial that passes by any number of points, but without transforming the function contrary to what we have just done just before! As we like physics in this book, we'll take a classic case of the cinematic to join business with pleasure...\n\t\n\tSo consider that we are looking for a polynomial of the second degree of the form:\n\t\n\tknowing that the method is easily applicable to higher order polynomials (at least as far as we know).\n\t\n\tRelation that it is customary to write in the field of polynomial regression as follows:\n\t\n\twhere $i$ represents the number of points available to us.\n\t\n\tFor the rest, let us once again base our developments on the least squares method. In other words, we seek the coefficients $c_1,c_2,c_3$ that minimize the error:\n\t\n\tand we attack again with partial derivatives for each coefficient:\n\t\n\tTherefore after a small rearrangement and simplification:\n\t\n\tSimilarly:\n\t\n\tTherefore after a small rearrangement and simplification:\n\t\n\tAnd finally:\n\t\n\tTherefore after a small rearrangement and simplification:\n\t\n\tSo using the notation of linear algebra, we finally have to solve the following system:\n\t\n\tand so we just have to solve this simple linear system either by hand using the relations proved in the section of Linear Algebra, or with a simple spreadsheet software (like Microsoft Excel for example).\n\t\n\t\\pagebreak\n\t\\subsubsection{Logistic Regressions (LOGIT)}\n\tOften, statistics data are relative to the qualitative informations. However, as we shall see, the traditional inference methods do not allow to model and study this type of variables. Specific methods should be used taking into account for example the lack of continuity of the processed variables or absence of the natural order between the terms that can take the qualitative variable.  We will therefore see now the most simple of this method.\n\t\n\t\\paragraph{Binomial Logistic Regression}\\mbox{}\\\\\\\\\n\tAs we have seen above, the simple linear regression therefore aims to model the relation between a quantitative dependent variable (unbounded) and quantitative explanatory variable.\n\t\n\tWhen the \"\\NewTerm{class variable}\\index{class variable}\" to explain $Y$ is binary (yes-no, presence-absence, 0-1, etc.), the idea is to approach it at first by a probability function $P(Y=1)$ which gives at the oppositie the probability of belonging to the class $Y=0$ or $Y=1$, which we will name the \"\\NewTerm{logistic binomial regression}\\index{logistic binomial regression}\" or \"\\NewTerm{logit regression}\\index{logit regression}\" or simple \"\\NewTerm{binomial regression}\\index{binomial regression}\" (often used in the context of artificial neural networks that we will see later). Then, in a second step, we define a for a binary case a \"\\NewTerm{cutoff}\\index{cutoff}\" value. For example, if we take a cutoff of $0.5$ then the cases for which $P(Y=1)>0.5$ will belong to the class $1$ (and vice versa in the opposite case).\n\t\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\\textbf{R1.} In fact, logistic regression is a simple probability distribution law in our case (we will see another logistic regression in the section Economy during our study of time series and yet another one in the section of Populations Dynamics).\\\\\n\t\n\t\\textbf{R2.} It is obviously not possible to apply systematically logistic regression to any type of data sample! Sometimes we have to look elsewhere...\\\\\n\t\n\t\\textbf{R3.} When the number of modalities is equal to $2$, we talk about \"\\NewTerm{dummy variable}\\index{dummy variable}\" (yes-no) or a \"\\NewTerm{dichotomic model}\\index{dichotomic model}\" or even of \"\\NewTerm{indicator variable}\\index{indicator variable}\"; if it is greater than $2$, we talk about \"\\NewTerm{polytomous variables}\\index{polytomous variables}\" (polytomous logistic regression). Therefore the logit binomial model is a \"dichotomous model\".\n\t\\end{tcolorbox}\n\tFor example, consider the dichotomous variable: \"graduation\". This takes two forms: \"ongoing\", \"finished\". Age is a possible predictor of this variable and we seek to model the probability of completing studies as a function of age.\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tTo build the graph below, we calculated and shown on the ordinate, for youth of various ages $x$, the percentage of those who have left school.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/binomial_logistic_idea.jpg}\n\t\t\\caption{Part at school according to Age}\n\t\\end{figure}\n\tBut how do we obtain such a graph with a dichotomic (dummy) variable ??? In fact it's relatively simple ... Imagine a sample of $100$ individuals. For these $100$ individuals assume for a given age that $70\\%$ \"has finished\" and $30\\%$ are \"ongoing\". Well the curve is simply the ratio of the two classes for a given age $x$. It is sometimes given the size of classes with circles over the length of the horizontal asymptotes to mean that this is a dichotomous variable.\n\t\\end{tcolorbox}\n\tPoints are distributed according to an $S$-curve (\\NewTerm{\"sigmoid\"}\\index{sigmoid}): there are two horizontal asymptotes as the proportion is between $0$ and $1$. We see immediately that a linear model would be manifestly inadequate (especially as the dependent variable a linear model sweeps the whole real numbers $\\mathbb{R}$ and is not confined to the range $[0, 1]$).\n\t\n\tThis curve evokes for some, rightly, a cumulative curve representing a distribution function (of a Normal distribution for instance, but other continuous distributions have almost the same shape). Thus, to fit a curve to this representation, we could move towards the distribution function of a Normal distribution, and instead of estimating the parameters $a$ and $b$ of the linear regression, we could estimate the parameters $\\mu,\\sigma$ of the Normal law (which is very similar to the logistic as will be shown below). We then speak of a \"\\NewTerm{probit model}\\index{probit model}\" (probability-unit).\n\t\n\tThe law that will interest us, however, is the logistic law. Unlike the Normal distribution, we know how to evaluate the expression of its distribution function (cumulative probability) that is of the type (his first advantage!):\n\t\n\tfor a single predictor variable (predictor) $x$ where $P$ is obviously a probability between $0$ and $1$. We will see a little further the historical reason for this choice.\n\t\n\tWe immediately see that this last relation being the integral of a density function (see the proof a little bit further below) it is therefore indeed a cumulative function as:\n\t\n\tIf there are several predictor variables then we write:\n\t\n\tWhen we choose the logistic distribution function, we get the logistic regression model, or \"\\NewTerm{logit model}\\index{logit model}\" for the choice of the \"\\NewTerm{link function}\\index{link function}\" and this is its second advantage (the most important one in fact!): we can make statistics on binary variable as if we were doing a simple linear regression!\n\t\n\tThus, to come back on our previous example, we estimate the cumulative probability for an individual of age $x$ to have finish his studies (there are several ways to write the law following the traditions and the context) with the following logistic distribution function:\n\t\n\tIt therefore follows the distribution function:\n\t\n\tObviously, depending on the value of the probability we associate with the age $x$ the fact of not having finished his studies (state associated with the binary value: $0$) or have them finished (state associated with the binary value: $1$).\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tAfter a change of variables, we find fall bakc on the logistic law as defined on Wikipedia:\n\t\n\t\\end{tcolorbox}\t\n\tLet us indicate that if $a$ is set as unit, and $b$ as non null, then we have the \"\\NewTerm{standard logistic law}\\index{standard logistic law}\" given by:\n\t\n\tWe can also calculate the mean of the distribution of the function by applying what has already been study in the Statistics section but part of this integral can only be solved numerically (at least as far as we know)... if we put:\n\t\n\tas being the random variable then we can formally calculate the mean of the logistic law (the reader may have noticed that it is as if we posed as $a=1$ and $b=0$). Indeed, starting from:\n\t\n\tTherefore it comes:\n\t\n\tthat after a numerical integration gives $0$. We then also get the following result:\n\t\n\tLet us calculate the integral:\n\t\n\tThus we see that if we put:\n\t\n\tWe fall back on a distribution function with the same position and dispersion parameters of a Normal distribution centered reduced variable (zero mean and unit variance).\n\t\n\tThe distribution function:\n\t\n\tcan also be transformed in a very known and important form!:\n\t\n\tTherefore:\n\t\n\tIn fact this is where lies the historically the trick of the origin of logistic regression. We transform a variable $P$ taking values in the in the range $[0,1]$ thanks to the logarithm of the ratio $P / (1-P)$ in a variable taking its values on the set $\\mathbb{R}$ and therefore it is possible to associate to it a standard linear regression. Certainly it is empirical, but the idea was pretty good!\n\n\tWhat some also write...:\n\t\n\tThe result of the last transformation is named the \"\\NewTerm{logit}\\index{logit}\". It is equal to the logarithm of the \"\\NewTerm{odds}\\index{odds}\" (which will be discussed in more detail soon):\n\t\n\tSo this is just the ratio of a likelihood of an event on the probability of the complementary event (or opposite event if you prefer).\n\t\n\tSo when the coefficients $a$ and $b$ have been determined, the above expression is used to determine $P$ knowing $x$ easily (it comes to solve a linear equation) and vice versa! Moreover, since $x$ is a dichotomic (dummy) variable coefficients are easily interpretable.\n\t\n\t\\pagebreak\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe odds is also sometimes named the \"\\NewTerm{rating}\\index{rating}\" by analogy to the rating of horses to the triple forecast. For example, if a horse has $3$ chances on $4$ to be a winner (thus verbatim $1$ on $4$ chance of being non-winner) its rating is a $3$ against $1$ ratio, that is to say an odds equal to $3$. We can also introduced the concept of \"\\NewTerm{odds ratio O.R.}\\index{odds ratio}\" for the rating ratio which is a very widely used indicator in medicine. Thus, if the occurrence of an event in a group $A$ is $p$, and $q$ in the group $B$, the odds ratio is then simply given by:\n\t\n\tThe odds ratio is always by design greater than or equal to zero. If the odds ratio is close to $1$, the event is independent of the group, if it is greater than $1$, the event is more common in group $A$ than in group $B$, if it is less than $1$ the event is less frequent in group $A$ than in group $B$.\n\t\\end{tcolorbox}\n\tLet us come back over the odds because it is possible to introduce the concept of logistics function by doing the opposite approach from the one presented above (i.e. to start with the definition of odds to get to the logit) and this can sometimes be even more educational.\n\t\n\tLet us suppose we start from the size (height) of a person to predict whether this person is a man or a woman. So we can talk about probability of being a man or a woman. Suppose the probability of a man for a given height is $90\\%$. So the odds of being a man is:\n\t\n\tIn our example, the odds will be $0.90 / 0.10$ therefore equal to $9$. Now, the probability of being a woman will be $0.10 / 0.90$ therefore equal to $0.11$. This asymmetry of values is not talking because the odds of being a man should be the opposite of the odds of being a woman ideally. We solve precisely this asymmetry using the natural logarithm. Thus we have:\n\t\n\tIn this way the logit (logarithm of the odds) is exactly the opposite of this of being a woman by the property of the logarithm:\n\t\n\t\n\t\\pagebreak\n\t\tTo introduce this tool let us suppose a bank wants to make a scoring of its debtors. As it has several subsidiaries it (the bank) built the following data tables for some of them (all subsidiaries are then not presented):\n\t\\begin{enumerate}\n    \t\\item 1st Subsidiary:\n\t\t\n\t\t\\item 2nd Subsidiary:\n\t\t\t\n\t\t\\item 3rd Subsidiary:\n\t\t\n\t\\end{enumerate}\n\tWe can see that the total proportion of good debtors in the three subsidiaries is of $91/136 \\cong 0.67$.\n\t\n\tWhen the credit is less than $27,500$, the percentage of good debtors is of $2/27\\cong 0.07$. When the amount of credit is less than $28,000$ the proportion of good debtors is of $19/51\\cong 0.37$.\n\t\n\tWhen the amount of credit is less than $28,500$, the percentage of good debtors is of $64/108 \\cong 0.59$ and for amounts below $30,000$ the proportion is of $91/936\\cong 0.67$.\n\t\n\tWe will put for this logistic regression that $Y=1$ is a good credit risk and that $Y=0$ is a bad risk. Next, we create the following table that is a summary of data from all subsidiaries:\n\t\n\tWhich gives graphically in Kilo-francs:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/arithmetics/logistic_regression_debtors_percentage.jpg}\n\t\t\\caption{Cumulative percentage of good debtors based on credit}\n\t\\end{figure}\n\tOnce done, we use the logit transformation:\n\t\n\tWhich give:\n\t\n\tA linear regression by least squares method gives:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/arithmetics/logistic_regression_olg.jpg}\n\t\t\\caption{Logit of good debtors based on the credit amount}\n\t\\end{figure}\n\twith for equation:\n\t\n\tThe logistics function with its representation comes then immediately (the $x$ units are in thousands of francs)\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/arithmetics/logistic_cumulative_distribution.jpg}\n\t\\end{figure}\n\tThus, it is possible to say in this example, what is the proportion $P$ of good or bad debtors according to the credit value $X$ than or equal to a certain given value. Since $0$ is a bad credit risk, we see that the more is the credit, the lower the risk is big (in this hypothetical case...). Moreover, with software like Minitab (see companion book), the difference between the quick calculations carried out by hand and those made with the binary logistic regression tool  of the software is in the order of $10\\%$ (because of course ... Minitab uses the concept of maximum likelihood estimators seen in the Statistics section to determine the coefficients and the constant).\n\t\n\tA software like Minitab gives automatically a sympathetic output which is the \"\\NewTerm{confusion matrix}\\index{confusion matrix}\". It compares the model to reality with a traditional cut-off set at $50\\%$ (obviously if the model perfectly match to the sample, the following matrix is a diagonal one):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/arithmetics/confusion_matrix.jpg}\n\t\t\\caption{Confusion matrix example}\n\t\\end{figure}\n\twhere the good debtors have the value $1$ (no credit risk) and the bad one the value $0$ (credit risk). We will detail futher below how to get this matrix with a spreadsheet software. Finally let us indicate that in many Data Mining softwares, it is customary to define the \"\\NewTerm{score}\\index{score}\" of the model as (in the specific case of one unique explanatory variable but can easily be generalized to many):\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIn some statistical softwares, when you run a logistic regression, you can get sometimes a message of the type: \\textit{complete separation of data points}. Indeed, thake a lookt at the following data set consisting of ne response variable, $Y$, and one predictor variable, $X$:\n\t\n\tNot the key pattern... This data set can be simply described as follows: if $X\\leq 4$, then $Y=0$ without fail. Similarly, if $X>4$, then $Y=1$, again without fail. This is hat is knows as \"separation\". This perfect prediction of the response is what causes the estimates, and thus the model, to fail.\n\t\\end{tcolorbox}\n\t\n\t\\paragraph{ROC and Lift curves}\\mbox{}\\\\\\\\\n\tThe \"\\NewTerm{ROC curve}\\index{ROC curve}\" for \"\\NewTerm{Receiver Operating Characteristic curve}\\index{ROC curve}\") is a measure of the performance of a binary classifier, that is to say a system that aims to categorize entities in two distinct groups on the basis of one or more of their characteristics. \n\n\tGraphically, we often represents the ROC measurement  in the form of a curve which gives the true positive rate (sensitivity: fraction of positives that are correctly detected) according to the rate of false positive rate (proportion of negatives which are incorrectly detected) for the same group. ROC curves are often used in statistics to show the progress realized with a binary classifier when \"\\NewTerm{discrimination threshold}\\index{discrimination threshold}\" (cut-off) varies.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tWe present this tool because many statistical software return automatically a ROC curve as output but the interest of this tool is in my personnal opinion very questionable. However, we will show a more useful tool right after.\n\t\\end{tcolorbox}\n\tLet us see practical case by taking our previous example (the Bank and its subsidiaries) with the spreadsheet software Microsoft Excel 14.0.7106. First to build the ROC curve we must obtain the confusion matrix that we presented just a little higher with Minitab. For this with a spreadsheet software and without doing code, here is a simple solution (but this is not the more condensed solution for pedagogical reasons).\n\t\n\tThe goal will be first to build the following table (this is only a part of the table of the previous example since in reality there are 136 rows of data) whose columns $B$ and $C$ comes from the three small tables of Credits used just before, column $A$ is just the cumulative frequency of individuals $1/136$ ... $2/136$ ... $3/136$ ... and so on):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/roc_curve_excel_data.jpg}\n\t\t\\caption{List to obtain in Microsoft Excel to obtain for the ROC curve}\n\t\\end{figure}\n\tNow let us see what is in columns D, E and F and that are directly related to the result obtained above, which was for refresh:\n\t\n\tbut that we have refined with a specialized statistical software to obtain:\n\t\n\twhich then allows us to build the three previous mentioned columns (here we have only a few of the first lines because it is sufficient to just increment the formulas to the bottom of the list):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/roc_curve_excel_model_and_score.jpg}\n\t\t\\caption{Spreadsheet formulas for the probability of the model and the score}\n\t\\end{figure}\n\tThe formula in column F refers to the cell M3 which as we shall see a little further contains the empirical choice of the value of the cutoff we had mentioned during the presentation of the theoretical model of the logistics regression (by default we defined it at $50\\%$).\n\t\n\tThen we must build the columns of true positive, false positive, true negative, false negatives using basic spreadsheet formulas:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/roc_curve_excel_positive_and_negative.jpg}\n\t\t\\caption{Spreadsheet formulas for true / false positives and negatives}\n\t\\end{figure}\n\tOnce we have this data, we can rebuild the confusion matrix that was given to us by Minitab and we will need to develop the ROC curve:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/confusion_matrix_formulas.jpg}\n\t\t\\caption{Spreadsheet formulas to build the confusion matrix}\n\t\\end{figure}\n\twhich explicitly gives:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/confusion_matrix_values.jpg}\n\t\t\\caption{Corresponding values of the construction of the confusion matrix}\n\t\\end{figure}\n\tcompared with the confusion matrix that we gave and coming from Minitab:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/arithmetics/confusion_matrix.jpg}\n\t\t\\caption{Confusion matrix Minitab 16.1.1}\n\t\\end{figure}\n\tNow observe the ROC curve given by Minitab:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/minitab_roc_curve.jpg}\n\t\t\\caption{ROC curve given by Minitab 16.1.1}\n\t\\end{figure}\n\tWhy the abscissa-represents:\n\t\\begin{gather*}\n\t\t1-\\%\\text{false positives}\n\t\\end{gather*}\n\tyou will probably ask yourself when the interpretation would have been easier if we had just the:\n\t\\begin{gather*}\n\t\t\\%\\text{false positives}\n\t\\end{gather*}\n\tWell for two reasons: the first is that practitioners like strictly increasing functions... and the second reason, the most important, is that if the binary classifier is fully effective, the surface is then equal to 1$ $(that is to say, $100\\%$). Which admittedly is nicer than to say that a null surface corresponds to a $100\\%$ efficiency. Well that being said ... let us continue.\n\t\n\tBefore learning how to interpret this chart, how to get the same curve in a spreadsheet software? Well just simply observe our column D of our Microsoft Excel list. Logically we have there $5$ different cumulative probabilities (as there were only $5$ credits values) which are respectively:\n\t\\begin{gather*}\n\t\t\\begin{aligned}\n\t\t0.235214057\\\\\n\t\t0.481608302\\\\\n\t\t0.777818743\\\\\n\t\t0.813679766\\\\\n\t\t0.991760974\n\t\t\\end{aligned}\n\t\\end{gather*}\n\tTherefore the idea of the construction of the ROC curve is to take each of the accumulated probabilities as cutt-off values. This give respectively:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/confusion_matrix_cutoff1.jpg}\n\t\t\\includegraphics{img/computing/confusion_matrix_cutoff2.jpg}\n\t\t\\includegraphics{img/computing/confusion_matrix_cutoff3.jpg}\n\t\t\\includegraphics{img/computing/confusion_matrix_cutoff4.jpg}\n\t\t\\includegraphics{img/computing/confusion_matrix_cutoff5.jpg}\n\t\t\\caption{Values of the confusion matrix for various cut-off values}\n\t\\end{figure}\n\tSo we get each time the coordinates of points of the ROC curve in function of cut-off values. Well this done, now let us turn to the interpretation by taking the below manually completed graph:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/minitab_roc_curve_completed.jpg}\n\t\t\\caption{ROC curves (blue: average classifier, red: good classifier, green: perfect classifier, black: poor classifier)}\n\t\\end{figure}\n\tThen as shown in the graph above and the intuition, a perfect binary classifier is one whose true positive rate is constant and always $100\\%$. So the binary classifier in our example is moderately good.\n\t\n\tBut from my personal point of view a good binary classifier is one that for a given value of the cut-off maximizes the sum of the rate of true positives and true negatives. Thus, with a spreadsheet software such as Microsoft Excel in \"evolutionary mode\" it is very easy to find this cutoff value that maximizes this objective. But however be careful to the trap: the value may not be unique, it can also be an interval (which is the case in our example!).\n\t\n\tFinally, if we denote by TP the true positive, TN the true negative, FP the false positives or Type I error (in terms of decision theory or tests theory), and FN false negative or Type II error we can then define a set of indicators to judge the quality of our predictor/classifier (or rather of our score):\n\t\n\t\\begin{itemize}\n\t\t\\item $\\text{TPR} = \\dfrac{\\text{TP}}{\\text{P}} = \\dfrac{\\text{TP}}{\\text{TP+FN}}$ named \"\\NewTerm{sensitivity}\\index{classification!sensitivity}\", corresponding to the rate of true positives.\n\t\t\n\t\t\\item $\\text{RPF} = \\dfrac{\\text{FP}}{\\text{N}} = \\dfrac{\\text{FP}}{\\text{FP+TN}}$ corresponding to the rate of false positives.\n\t\t\n\t\t\\item $\\text{ACC} = \\dfrac{\\text{TP+TN}}{\\text{P+N}}$ named \"\\NewTerm{accuracy}\\index{classification!accuracy}\".\n\t\t\n\t\t \\item $\\text{SPC} = \\dfrac{\\text{TN}}{\\text{N}} = \\dfrac{\\text{TN}}{\\text{FP+TN}}=1-\\text{FPR}$ named \"\\NewTerm{specificity}\\index{classification!specificity}\" or true negative rate.\n\t\t \n\t\t \\item $\\text{PPV} = \\dfrac{\\text{TP}}{\\text{TP+TP}}$ the \"\\NewTerm{positive predictive value}\\index{classification!positive predictive value}\".\n\t\t \n\t\t \\item $\\text{NPV} = \\dfrac{\\text{TN}}{\\text{TN+FN}}$ the \"\\NewTerm{negative predictive value}\\index{classification!negative predictive value}\".\n\t\t \n\t\t \\item $\\text{FDR} = \\dfrac{\\text{FP}}{\\text{FP+TP}}$ corresponding to the  \"\\NewTerm{false discovery rate}\\index{classification!false discovery rate}\".\n\t\\end{itemize}\n\tHaving done this, let us move to the second curve.\n\t\n\tThe principle of the \"\\NewTerm{lift curve}\\index{lift curve}\" is very simple but is based on a questionable assumption (which fortunately has not however a great importance) that is that without the theoretical model (logistic model in this case) we will absolutely know nothing of the real behavior that will have the customers (debtors). The hypothesis is to consider that if we took $50\\%$ of the individuals in our sample, we would have $50\\%$ of true positives (real bad debtors), if we took $25\\%$ of our sample, we would have $25\\%$ of true positives (true bad debtors) and so on. This initial hypothesis (considered by practitioners as the worst case) will be represented graphically by the following straight line:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/lift_curve_at_worst.jpg}\n\t\t\\caption[]{Lift curve at worst (as assumption)}\n\t\\end{figure}\n\tBut that's just to have an empirical reference when working with a single model of statistical clustering. In fact, given the multiplicity of statistical modeling methods, where almost each has its own empirical indicators of quality, statisticians have sought general criteria for the performance of a model (this obviously in the idea to be able to compare different the accuracy of various models between them).\n\t\n\tThus, an empirical and intuitive enough choice is to say that a statistical method is better than another if for a given subset of the sample, its predictive power (the cumulative number of true positives for example) is better or no. This is the purpose of the lift curve.\n\t\n\tThe lift curve is therefore a variation of the ROC curve. The lift curve classify the individuals by descending score (again for reasons of simplification of interpretation of the surface under the curve and especially to have in first the target group of interest to monitor), by grouping them by percentiles for example, determining the percentage of events of interest in each percentile (normally the true positives) and then by plotting the cumulative curve of these percentages, so that a point of the coordinates $(n, m)$ on the curve means that the $n\\%$ of individuals with the highest score concentrate $m\\%$ of events. This is the way to build this curve which we makes we speak of predictive performance of \"targeted marketing\".\n\t\n\tLet's see how to build such a curve, always with the same spreadsheet software and always the same data. The start of construction is to take some columns that we had used for the ROC curve (first 31 records out of 136):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/lift_curve_basis_formula.jpg}\n\t\t\\caption[]{Formulas of the first columns in Microsoft Excel to get the lift curve}\n\t\\end{figure}\n\twhere the reader may have noticed that we have arbitrarily chosen to set the cut-off at $50\\%$ (thus in reality, and the reader must never forget it, the whole lift curve changes for each value of the cut- off !!!).\n\t\n\tWhich explicitly provides (remember that column A, that as for the ROC curve is trivial, as its simply represent the cumulative effective):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/lift_curve_values.jpg}\n\t\t\\caption[]{Explicit value in Microsoft Excel to obtain for the lift curve}\n\t\\end{figure}\n\tOne difference now compared to the ROC curve is that we want the events of interest first (the bad debtors). The we must sort the column Model (that is to say the: Score) in descending order. This will give:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/lift_curve_values_sorted.jpg}\n\t\t\\caption[]{Explicit sorted value in Microsoft Excel to obtain for the lift curve}\n\t\\end{figure}\n\tThen we add the column of \\%Cumulative of true positives:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/lift_curve_values_sorted_cumulated_formula.jpg}\n\t\t\\caption[]{Column of \\%Cumulatived of true positives for the lift curve}\n\t\\end{figure}\n\tWhat gives globally:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.7]{img/computing/lift_curve_global_values.jpg}\n\t\t\\caption{Overview of all constructed columns for the lift curve}\n\t\\end{figure}\n\tThe last step is now simply to build a graph of \\%cumulative number of true positive (column G) relative to the \\%cumulative of the sample size (Column A) to get:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/lift_curve.jpg}\n\t\t\\caption[]{Lift curve (in red at worst, in blue our model)}\n\t\\end{figure}\n\tSo obviously we can not do in this case make an interpretation of the predictive power in terms of \"lift\" in comparison to another statistical model. By cons we can compare the predictive power of the logistic model used in this case in terms of lift compared to the case considered at worst (the diagonal for reminder ...). So in this case, if we take the $20\\%$ of customers (debtors) having the highest score, that's what we have:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/lift_curve_completed.jpg}\n\t\t\\caption[]{Lift Analysis}\n\t\\end{figure}\n\tSo in this particular example, this means that if we focus our analysis / research / target marketing or other... than on the $20\\%$ of the sample being the best score (for example ... for cost reasons), we have an overperformance of $37\\% / 20\\% = 1.85$. Then we say that the model has a lift of $1.85$. The idea then when we compare several models is to keep the one with the greatest lift (leverage).\n\t\n\t\\pagebreak\n\t\\subsection{Interpolation Techniques}\n\tThe main difference between interpolation and regression, is the definition of the problem they solve.\n\n\tGiven $n$ data points, when you interpolate, you look for a function that is of some predefined form that has the values in that points exactly as specified. That means given pairs $(x_i,y_i)$ you look for $f$ of some predefined form that satisfies $f(x_i)=y_i$. Most commonly $f$ is chosen to be polynomial, spline (low degree polynomials on intervals between given points).\n\t\n\tWhen you do regression, you look for a function that minimizes some cost, usually su of square of errors, You don't require the function to have the exact values at given point, you just want a good approximation. In general, your found function $f$ might not satisfy $f(x_i)=y_i$ for any data point, but the cost function, i.e. $\\displaystyle\\sum_{i=1}^n(f(x_i)-y_i)^2$ will be the smallest possible of all the functions of given form.\n\t\n\tThere are numerous polynomials interpolation techniques more or less complex and sophisticated . We propose here to present some in ascending order of difficulty.\n\t\n\t\\subsubsection{Bezier Curves (B-Splines)}\n\tThe Russian engineer Pierre Bezier, at the beginnings of the Computer Aided Design (CAD), in the 60s, gave a way to define curves and surfaces from points. This allows direct manipulation, geometric, of curves without having to give a series of equation to the machine to describe a complex curve!!\n\t\n\tThe application field of Bezier curves is a multifaceted to, very rich, at the crossroads of many diverse mathematical areas: Analysis, Cinematic, Differential Geometry,  Affine Geometry, Projective Geometry, Fractal Geometry, Probabilities, Statistics, Finance (rates curve), etc.\n\t\n\tThe Bezier are also become essential in their concrete applications in industry, and computer graphics. Most non-engineer and non-scientific people know them through the usage of some drawing tools included in Adobe Illustrator, Adobe Photoshop, 3D Studio Max, Blender, Rhino, Adobe InDesign, Microsoft Office Visio and even Microsoft Office Word and Microsoft Office PowerPoint.\n\t\n\tLet us present and study in detail the mathematical approach of this technique:\n\t\n\tFirst, we know that the equation of a segment line which we will denote in this field of study $M$ (with respect for the tradition) joining two points $A(x_1,y_1),B(x_2,y_2)$ is:\n\t\n\tThis is right since when $t=0$ we are on $A$ and when $t=1$ we are on $B$. Therefore $t\\in[0,1]$ and the point $M$ describes the whole straight segment $[AB]$.\n\t\n\tBy definition, the straight segment denoted $[AB]$ is a \"\\NewTerm{Bezier curve of degree $1$}\\index{Bezier curve}\" with control points $A$ and $B$ and the polynomials on $t$ or on $t-1$ are the \"\\NewTerm{Bernstein polynomials of degree $1$}\\index{Bernstein polynomials}\".\n\t\n\tLet us now build a parametric curve by adding a second step to what we just see:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/b_splines_three_points.jpg}\n\t\t\\caption{Idea behind 2nd order Bézier curves}\n\t\\end{figure}\n\t\\begin{enumerate}\n\t\t\\item 1st step:\n\t\t\\begin{enumerate}\n\t\t\t\\item Given $M_1(t)$ the barycenter of $(A,1-t)$ and $(B,t)$ and where $M_1(t)$ describes the segment $[AB]$.\n\t\t\t\\item  Given $M_2(t)$ the barycenter of $(B,1-t)$ and $(C,t)$ and where $M_2(t)$ describes the segment $[BC]$.\n\t\t\\end{enumerate}\n\t\t\\item 2nd step:\n\t\tGiven $M(t)$ the barycenter of $(M_1(t),1-t),(M_2(t),t)$.\\\\\n\t\t\t\n\t\tBy construction $M (t)$ is therefore at the same proportion of the segment $[M_1(t),M_2(t)]$ relative to the segment $[AB]$ or to $M_2(t)$ compared to the segment $[BC]$.\\\\\n\t\t\t\n\t\tThe curve obtained is then the envelope of the segments $[M_1(t),M_2(t)]$: at any point $M(t)$, the tangent to the curve is therefore the segment $[M_1(t),M_2(t)]$.\n\t\\end{enumerate}\n\t$M (t)$ then describes a Bézier curve of order two, which, by construction starts at $A$ and ends at $C$, and has for tangents $[AB]$ on $A$ and $[CB]$ on $C$.\n\t\n\tThis is in fact a parabolic arc (that we denote logically by $[ABC]$ in this field of study):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/b_splines_three_points_result.jpg}\n\t\t\\caption[]{Result of 2nd order Bézier curve}\n\t\\end{figure}\n\tBy the same pattern, we can define a Bézier curve of $n$ points $P_i$ with $i=1...n$. This is what we name the \"\\NewTerm{Casteljau algorithm}\\index{Casteljau algorithm}\". Thus, given:\n\t\n\tWe get:\n\t\n\tThe recurrence ending for:\n\t\n\tThus, for $n=2$ we have:\n\t\n\tTherefore:\n\t\n\tThus, we have necessarily with two points the equation of a straight line.\n\t\n\tNow consider $M_3(t)$ the Bézier curve of order $3$, therefore we have the points always defined by:\n\t\n\tWe then have by the recurrence relation:\n\t\n\twhere we have eliminated the terms containing unspecified points.\n\t\n\tWe have therefore:\n\t\n\tTherefore it comes:\n\t\n\tor in vector form (more consistent with the usual mathematical notation and therefore we also better understand the meaning of \"\\NewTerm{vectorial drawing}\\index{vectorial drawing}\"):\n\t\n\tand in matrix form:\n\t\n\tBy the same reasoning, we get for for a Bézier curve of order $4$:\n\t\n\tor in vector form:\n\t\n\tWhich corresponds generically to:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/b_splines_order_4.jpg}\n\t\t\\caption{Example of Bézier curve of order $4$}\n\t\\end{figure}\n\t\\pagebreak\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tLet us plot now a Bézier curve of order $4$ with Maple 4.00b. For this purpose we will use the following commands:\\\\\n\t\n\t\\texttt{>restart:with(plots):\\\\\n\t>x[0]:=1: y[0]:=4:\\\\\n\t>x[1]:=6: y[1]:=6:\\\\\n\t>x[2]:=1: y[2]:=2:\\\\\n\t>x[3]:=8: y[3]:=2.5:\\\\\n\t>f:=t->x[0]*(1-t)\\string^3+3*x[1]*t*(1-t)\\string^2+3*x[2]*t\\string^2*(1-t)+x[3]*t\\string^3;\\\\\n\t>g:=t->y[0]*(1-t)\\string^3+3*y[1 ]*t*(1-t)\\string^2+3*y[2]*t\\string^2*(1-t)+y[3]*t\\string^3\\\\\n\t>G:=plot([f(t),g(t),t=0..1],thickness=2):\\\\\n\t>t0:=textplot([x[0],y[0],`P[0]`],align=ABOVE):\\\\\t\n\t>t1:=textplot([x[1],y[1],`P[1]`],align=RIGHT):\\\\\t\n\t>t2:=textplot([x[2],y[2],`P[2]`],align=RIGHT):\\\\\n\t>t3:=textplot([x[3],y[3],`P[3]`],align=ABOVE):\\\\\n\t>Or:=textplot([0,0,`Origin`],align=ABOVE):\\\\\n\t>pp:=pointplot({[x[0],y[0]],[x[1],y[1]],[x[2],y[2]],[x[3],y[3]]},\\\\\n\tsymbol=circle,color=navy):\\\\\n\t>display(G,t0,t1,t2,t3,pp,Or);\\\\}\n\t\n\tThis will give:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/b_splines_order_4_maple.jpg}\n\t\\end{figure}\n\t\\end{tcolorbox}\n\tNow let us take again the previous Bezier curve with a different notation:\n\t\n\tWe first notice easily the following proportionality:\n\t\n\tand if we look more closely at the coefficients, we note that we have also:\n\t\n\tIt is neither more nor less than the Pascal's triangle !! So the coefficients are simply the binomial coefficients (\\SeeChapter{see section Calculus}) given for the order $n$ in our example by:\n\t\n\tThus, \"\\NewTerm{Bernstein polynomials}\\index{Bernstein polynomials}\" are defined by:\n\t\n\tand finally the Bernstein curves of order $n$ are given by:\n\t\n\tIn fact, if we have noted previously the sum as follows:\n\t\n\tWe would then have the Bernstein polynomials that are given (which is more respectful of the traditions ...) by:\n\t\n\tThis is a very practical relation because it allows easily and quickly to calculate the polynomial corresponding to a sequence of Bezier curve of order $n$.\n\t\n\tThen we have:\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tA Bezier curve is completely changed as soon as at least on point is moved. Then we say that the method of Bezier is a \"global method\".\n\t\\end{tcolorbox}\t\n\tA well-known example of order Bézier curves of order $3$ is the Pen tool of Adobe Photoshop or Adobe Illustrator softwares. Indeed, these tools create a series of Bézier curves of order $3$ whose point $P_2$ is set afterwards with the mouse using handles named \"Handles\" in Adobe practitioners language... Here's an example taken from one of these programs done with a plot with the Pen tool with $5$ points (thus $4$ splines):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/adobe_spline.jpg}\n\t\t\\caption{Examples of splines with a drawing program}\n\t\\end{figure}\n\tAs the user does not move the points handles all points are aligned on the straight line. We then feel like to have a spline of order $2$.\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tA circle, drawn by a profesional drawing software is in practice composed of 4 Bezier arcs. To observe this particularity, simply draw a circle with Adobe Illustrator for example, and then select it to reveal the Bezier control points arcs that defines it.\\\\\n\t\n\tWe'll look at the best way to choose the control points of these arcs so that they look like circle quadrants, and then we will see the difference between the drawing produced (vector circle) and true (bitmap) circle:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/spline_vector_circle.jpg}\n\t\t\\caption{Example of constructing a circle with Bézier curves}\n\t\\end{figure}\n\tLet us take the first quadrant or radius $1$ centered at the origin:\n\t\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\tLet us take the first quadrant or radius $1$ centered at the origin:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/spline_vector_circle_first_quadrant.jpg}\n\t\\end{figure}\n\tIt is approached by a Bézier arc whose control points are $P_1,P_2,P_3,P_4$. The ends of the Bézier arc being $P_1$ and $P_4$, it is natural to choose $P_1(1,0)$ and $P_4(0,1)$.\\\\\n\t\n\tIntuition leads us to choose $P_2(1,k)$ and $P_3(k,1)$ and it remains to find a positive value of $k$ so that the Bezier curve looks like a circular arc.\\\\\n\t\n\tWe thus obtain the parametric equation of the Bézier curve:\n\t\n\tTherefore:\n\t\n\tWe can look for example the value of $k$ for which the arc passes through the point:\n\t\n\tin $t=0.5$. It then becomes very simple from the parametric equation to determine $k$. It is simply for $x$ (or $y$) of a simple equation of one unknown.\n\t\\end{tcolorbox}\n\t\n\t\\subsubsection{Euler Method}\n\tStrictly speaking the Euler Method is much more than an interpolation method. But it can be introduced first as a liner piece-wise interpolation technique. In fact it provides an approximation (in the broadest sense) of a function $f (x)$ whose first derivative is known.\n\t\n\tThe interpolated points are not necessarily equidistant as the interpolation is piece-wise but as soon we extrapolate the step is by tradition equidistant and denoted by $h$ and the distance between two points: $x_i=x_0+ih$. We denote by $f(x)$ the exact value and $y_i$ the approximate value.\n\t\n\tThe idea is quite simple. If in $\\mathbb{R}^2$ we know two points $(y_i,x_i)$ and $(y_{i+1},x_{i+1})$ we can calculate piece-wise the slope as:\n\t\n\tIn more complicate example and real application of the Euler methods we know the true derivative on $x_i$.\n\t\n\tThe previous relation can be written\n\t\n\tAnd therefore for small $h$ we can do a linear interpolation between two point.\n\t\n\tIf the derivative is know (and the derivative can be of non-linear function!) we have the more general relation:\n\t\n\tThat is traditionally written:\n\t\n\tnamed also the \"\\NewTerm{Euler difference difference equation}\\index{Euler difference difference equation}\".\n\n\tThe \"\\NewTerm{local truncation error LTE}\\index{local truncation error}\" of the Euler method is error made in a single step. It is the difference between the numerical solution after one step.\n\t\n\tTo calculate this error we can write first:\n\t\n\tFor the exact solution (considered as exact...), we use the Taylor expansion (\\SeeChapter{see section Sequences and Series}):\n\t\n\tThe local truncation error (one one step!!!) introduced by the Euler method is given by the difference between these equations:\n\t\n\tThis shows that for small $h$, the local truncation error is approximately proportional to $h^2$. This makes the Euler method less accurate (for small $h$) than other higher-order techniques such as Runge-Kutta methods that we will see later.\n\t\n\t\\pagebreak\n\t\\subsubsection{Polynomial of collocation}\n\tGiven $y=f(x)$ a known function in explicit form or in tabulated form, and suppose that a given number of values:\n\t\n\tare given. The known points $(x_i,f(x_i))$ are named \"\\NewTerm{support points}\\index{support points}\".\n\t\n\t\"\\NewTerm{Interpolate $f$}\\index{interpolate}\" in this context means to estimate the values of $f$ for the horizontal $x$ knows values located between $x_0$ and $x_n$, that is to say in the range of interpolation by an approximate function $y=p(x)$, which satisfies the \"collocations conditions\" (nothing to do with your roommate...!):\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/collocation_polynomial.jpg}\n\t\t\\caption{Illustration of the interpolation concept with the collocation technique}\n\t\\end{figure}\n\tThe function $P$ is named \"\\NewTerm{collocation function}\\index{collocation function}\" on the $x_i$. When $P$ is a polynomial, we speak of \"\\NewTerm{collocation polynomial}\\index{collocation polynomial}\" or of \"\\NewTerm{interpolation polynomial}\\index{interpolation polynomial}\".\n\t\n\t\"\\NewTerm{Extrapolate}\\index{extrapolate}\" a function means study the $f(x)$ by $p(x)$ for $x$-located \"outside\" of the interpolation interval.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIt goes without saying that the interpolation is a very important tool for all researchers, statisticians and others.\n\t\\end{tcolorbox}\t\n\tWhen we know a polynomial of degree $n$ on $n + 1$ points, we can know the by simple way (but not very fast - but there are several methods) this polynomial completely.\n\t\n\tTo determine the polynomial, we will use the results presented above in our study of systems of linear equations. The disadvantage of the method presented here is that you have to guess to what type of polynomial you are dealing with (the order at least) and know what are the good points to chose (when there is a choice...).\n\t\n\tA particular example should suffice for understanding this method, the generalization being quite simple (see further below).\n\t\n\tGiven the univariate second degree polynomial:\n\t\n\tand we know the following point (you will notice the ingenuity of the points selected by the authors of these lines ...):\n\t\n\tWe deduce therefore the following system of equations:\n\t\n\tSystem that once solved using the state of the art techniques (\\SeeChapter{see section Linear Algebra}) gives us:\n\t\n\tLet us see the general case:\n\t\\begin{theorem}\n\tGiven  $(x_i,f(x_i))$  support points, with $x_i\\neq x_j$ if $i\\neq j$. Then there exists a polynomial $P_n(x)$ of degree less than or equal to $n$, and only one, such as $P_n(x_i)=f_i$ for $i=0,1,...,n$.\n\t\\end{theorem}\n\t\\begin{dem}\n\tLet us write:\n\t\n\tThe collocation conditions:\n\t\n\tare thus written:\n\t\n\tThis is a system of $n + 1$ equations in $n + 1$ unknowns.\n\t\n\tIts determinant is written (\\SeeChapter{see section Linear Algebra}):\n\t\n\trelation that we name \"\\NewTerm{Vandermonde determinant}\\index{Vandermonde determinant}\". We know that if the system has a solution, the determinant of the system must be non-zero (\\SeeChapter{see section Linear Algebra}).\n\t\n\tLet us show by an example (by taking a polynomial of the same degree as the one we used above) that the determinant is calculated using the previous relation (the reader will generalize by induction):\n\t\n\tTherefore in the case $n=2$, we consider the determinant:\n\t\n\tthus corresponding to the system (for reminder):\n\t\n\tLet us calculate this determinant following the column $1$ (by making use of co-factors as proved in the section of Linear Algebra):\n\t\n\tThis polynomial can be written:\n\t\n\tWhich is written:\n\t\n\tAs the $x_9$ is in the statement of our problem are all different such that $x_i\\neq x_j$ then the system has a unique solution! This proves that there is always an interpolation polynomial.\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\t\n\t\\end{dem}\n\tIt should be noted however that it is not a method of polynomial regression. Indeed, with a method of polynomial regression, we might choose a higher degree for the polynomial as the number of points we have.\n\t\n\t\\pagebreak\n\t\\subsubsection{Lagrange polynomial interpolation method}\n\tThe interpolation  polynomial Lagrange method (used a lot in practice because the algorithm is very simple and therefore effective) consider that we initially have (know) $n + 1$ points such as:\n\t\n\tand that we are looking for a collocation polynomial that passes through all the points. The idea of polynomial interpolation of Lagrange is therefore simple and very clever (as always someone must have think to it first...). Let us observe the chart below where we have $5$ points by which we seek to pass a collocation polynomial:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/lagrange_polynomial.jpg}\n\t\t\\caption{Illustration of concept of Lagrange Interpolation (source: Wikipedia)}\n\t\\end{figure}\n\tTo find the collocation polynomial in red (we obviously suppose we don't know it initially), the idea is that for every $x_i$ we associate a different polynomial of degree $n$ and not null on $f(x_i)$ but null on all other points $(x_j)_{j\\neq i}$. For this, as we see in the graph above, it is necessary that for each $i$ we associate a polynomial that has $n$ roots as:\n\t\n\tSo we see that we have $5$ polynomials, each with $4$ roots (hence of order $4$) and which are respectively zero on all the points $x_j\\neq x_i$ (as you can see on the graph). The coefficients $A_i$ are constants to be determined.\n\t\n\tNow nothing avoid us to sum all polynomial together since we will always have the right value on $f(x_i)$ (since the other polynomials are zero on this same point). Either by generalization the notation, the sum becomes:\n\t\n\tBy injecting respectively $x_0,x_1,...,x_i,...,x_n$, we get in the general case:\n\t\n\tWe deduce then immediately in the general case:\n\t\n\tSubstituting the values of the constants in the initial expression of the sum, we get:\n\t\n\tWhich can be written in condensed form:\n\t\n\twhere the term:\n\t\n\tis named \"\\NewTerm{Lagrange polynomial interpolation coefficients}\\index{Lagrange polynomial interpolation coefficients}\".\n\t\n\t\\subsection{Roots search}\n\tMany equation encountered in practice or in theory cannot be solved by closed form or analytical methods. Consequently, only a numerical approach can be obtained in a finite number of operations.\n\n\tThe mathematician Évariste Galois has proved, in particular, that the polynomial equation $P_n(x)$ (\\SeeChapter{see section Calculus}) has no algebraic solution if $P_n(x)$ is of degree $n>4$.\n\n\tThere are numerous algorithms that gives the possibility to calculate the roots of equations of the type $f(x)=0$ with an almost arbitrary precision. We will see in this section only the main one.\n\n\tCaution! The implementation of such algorithms need always at least an approximate knowledge (randomly or deterministic) of the searched value and also the behavior (shape) of the function near the root. A table of the function values (\\SeeChapter{see section Functional Analysis}) or its graphical representation (see same section) can in simple cases help to acquire this prerequisites knowledge.\n\t\n\tIf the univariate equation to solve is under the form $g(x)=h(x)$, we plot the curves representing $g$ and $h$. The roots of the equation $g(x)=h(x)$ being given by the abscissa of the intersection points of the both curves.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tBefore solving by numerical methods the equation $f(x)=0$, we have to check that the function $f$ satisfy some constraints. For example, the function $f$ has to be at least strictly monotone near the root that we will denote here by $\\bar{x}$, when the Newton method is applied. It is many times useful, even absolutely necessary, to determine an interval $[a,b]$ such that:\n\t\\begin{itemize}\n\t\t\\item $f$ is continuous on $[a,b]$ of class $\\mathcal{C}^1$.\n\n\t\t\\item $f(a)f(b)<0$\n\t\t\n\t\t\\item $\\exists \\bar{x}$ unique, $\\bar{x}\\in [a,b],f(r)=0$\n\t\\end{itemize}\n\t\\end{tcolorbox}\n\n\t\\subsubsection{Proportional parts methods}\n\tThe implementation, on a computer, of this method is particularly simple. The conditions to be satisfied being only that in the interval $[a,b]$:\n\t\\begin{itemize}\n\t\t\\item $f$ must be continuous\n\n\t\t\\item $f$ must be monotone near the root $r$\n\t\t\n\t\t\\item $f(a)f(b)<0$ to sure that there is a root\n\t\\end{itemize}\n\tAs we already know, in a small interval, we can replace a curve by a straight line segment. There are several possible situations but here is a special one but that can be generalized easily to anything:\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/root_proportional_method.jpg}\n\t\t\\caption{Local approximation of a curve by a straight line segment}\n\t\\end{figure}\n\tIn this figure, we get by using the theorems of Thales (\\SeeChapter{see section Euclidean geometry}):\n\t\n\ttherefore:\n\t\n\tIf $|f(a)| \\ll |f(b)|$, we can neglect $f(a)$ at the denominator and it comes:\n\t\n\tThe algorithm consists therefore in performing the following steps:\n\t\\begin{enumerate}\n\t\t\\item We fix $\\varepsilon>0$ as upper bound of the admissible error tolerance.\t\t\n\t\t\n\t\t\\item Choose $a$ and $b$ with opposite signs, calculate $f(a)$ and $f(b)$\n\t\t\n\t\t\\item We calculate $x_1=a-(b-a)k$. If $|f(x_1)|$ is small enough, we stop the calculation and we display $x_1$ and $f(x_1)$.\n\n\t\t\\item Otherwise we proceed as following:\n\t\t\\begin{itemize}\n\t\t\t\\item We replace $b$ by $a$ and $f(b)$ by $f(a)$\n\t\t\t\\item We replace $a$ by $x_1$ and $f(a)$ by $f(x_1)$\n\t\t\\end{itemize} \n\t\tand we go back to point (2).\n\t\\end{enumerate}\n\tIn pseudo-code (non-unique and not optimized):\\\\\\\\\n\t\\begin{algorithm}[H]\n\t \\KwData{$a$,$ b$, $\\varepsilon$ expression of $f$ }\n\t \\KwResult{$x_1$}\n\t initialization\\;\n\t$f(a)$,$f(b)$\\;\n\t \\While{$|f(x_1)|>\\varepsilon$}{\n\t  $x_1=a-(b-a)\\displaystyle\\frac{f(a)}{f(b)}$\\;\n\t  \\If{$|f(x_1)|>\\varepsilon$}{\n\t   $b:=a$\\;\n\t   $f(b):=f(a)$\\;\n\t   $a:=x_1$\\;\n\t   $f(a):=f(x_1)$\\;\n\t   }\n\t  Display $x_1$\\;\n\t }\n\t \\caption{Proportional Parts pseudo-code algorithm}\n\t\\end{algorithm}\n\tObviously this is not the best algorithm especially if there is no root or if the computer is slow. Then a good advice is to take as input a number of limited iterations that have to be done (we will see a more elaborated way to handle such situations in the next algorithm).\n\t\n\t\\subsubsection{Bisection method}\n\tThe bisection method in mathematics is also root-finding method that repeatedly bisects an interval and then selects a subinterval in which a root must lie for further processing. It is a very simple and robust method, but it is also relatively slow. Because of this, it is often used to obtain a rough approximation to a solution which is then used as a starting point for more rapidly converging methods. The method is also named the \"\\NewTerm{interval halving method}\\index{interval halving method}\", the \"\\NewTerm{binary search method}\\index{binary search method}\", or the \"\\NewTerm{dichotomy method}\\index{dichotomy method}\".\n\t\n\tThe method is applicable for numerically solving the equation $f(x) = 0$ for the real variable $x$, where $f$ is a continuous function defined on an interval $[a, b]$ and where $f(a)$ and $f(b)$ have opposite signs such that $f(a)f(b)<0$. In this case $a$ and $b$ are also said to bracket a root since, by the intermediate value theorem, the continuous function f must have at least one root in the interval $[a, b]$.\n\n\tAt each step the method divides the interval in two by computing the midpoint $c = (a+b) / 2$ of the interval and the value of the function $f(c)$ at that point. Unless $c$ is itself a root (which is very unlikely, but possible) there are now only two possibilities: either $f(a)$ and $f(c)$ have opposite signs and bracket a root, or $f(c)$ and $f(b)$ have opposite signs and bracket a root. The method selects the subinterval that is guaranteed to be a bracket as the new interval to be used in the next step. In this way an interval that contains a zero of $f$ is reduced in width by $50\\%$ at each step. The process is continued until the interval is sufficiently small.\n\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/root_bissection_method.jpg}\n\t\t\\caption{Bisection method scheme}\n\t\\end{figure}\n\n\tExplicitly, if $f(a)$ and $f(c)$ have opposite signs, then the method sets $c$ as the new value for $b$, and if $f(b)$ and $f(c)$ have opposite signs then the method sets $c$ as the new $a$. (If $f(c)=0$ then $c$ may be taken as the solution and the process stops.) In both cases, the new $f(a)$ and $f(b)$ have opposite signs, so the method is applicable to this smaller interval.\n\t\n\tThe implementation, on a computer, of this method is particularly simple. The conditions to be satisfied being only that in the interval $[a,b]$:\n\t\\begin{itemize}\n\t\t\\item $f$ must be continuous\n\n\t\t\\item $f$ must be monotone near the root $\\bar{x}$\n\t\t\n\t\t\\item $f(a)f(b)<0$ to sure that there is a root\n\t\\end{itemize}\n\t\n\tThe algorithm consists therefore in performing the following steps:\n\t\\begin{enumerate}\n\t\t\\item We fix $\\varepsilon>0$ as upper bound of the admissible error tolerance.\n\t\t\n\t\t\\item We calculate $x=(a+b)/2$\n\n\t\t\\item We evaluation $f(x)$\n\t\t\n\t\t\\item If $|f(x)|<\\varepsilon$ then the job is done, we have to display $x$ and $f(x)$\n\t\n\t\t\\item Otherwise we proceed as following\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item we replace $a$ by $x$ if $f(x)f(a)>0$.\n\t\n\t\t\t\t\\item we replace $b$ by $x$ if $f(x)f(b)>0$ or $f(x)f(a)<0$.\n\t\t\t\t\n\t\t\t\t\\item we go back in (2)\n\t\t\t\\end{enumerate}\n\t\\end{enumerate}\n\tThe previous step (4) imposes the condition for stopping the calculations. Sometimes it is better to choose another criterion calculation ending. It requires the calculated solution to be contained in an interval of length equation containing the root $x^{*}$. This test is enunciate as follows:\n\t\\begin{enumerate}\n\t\t\\item[4'.] If $|b-a|<\\varepsilon$, the job is finished and $x=(a+b)/2$ is displayed. It is for sure obvious that $|x-x^{*}|<\\varepsilon/2$\n\t\\end{enumerate}\n\tIn pseudo-code (non-unique and not optimized):\\\\\\\\\n\t\\begin{algorithm}[H]\n\t \\KwData{$a$,$ b$, $\\varepsilon$ expression of $f$ }\n\t \\KwResult{$x^{*}$}\n\t initialization\\;\n\t$x=(a+b)/2$\\;\n\t\\While{$|f(x)|>\\varepsilon$}{\n\t    \\uIf{$f(x)f(a)>0$}{\n     \t\t$a:=x$\\;\n\t \t}\n\t\t\\uElseIf{$f(x)f(b)>0\\; \\vee \\; f(x)f(a)<0$}{\n\t\t\t$b:=x$\\;\n\t\t}\n\t\t$x=(a+b)/2$\\;\n\t }\n\t Display $x,f(x)$\\;\n\t \\caption{Proportional Parts bissection pseudo-code algorithm}\n\t\\end{algorithm}\n\tThe equivalent Maple 4.00b code is given by:\n\t\n\t\\texttt{>zero:=proc(f,a,b,pre)\n\tlocal M;\\\\\n\tM:=f((a+b)/2);\\\\\n\tif abs(M)<pre then \\\\\n\t     RETURN((a+b)/2)\\\\\n\telif M>0 then\\\\\n\t     zero(f,a,(a+b)/2,pre)\\\\\n\telse zero(f,(a+b)/2,b,pre)\\\\\n\t     fi\\\\\n\tend:}\n\t\n\t\\pagebreak\n\t\\subsubsection{Secant method (Regula Falsi or False Position)}\n\tThe \"\\NewTerm{secant method}\\index{secant method}\" also named or \"\\NewTerm{regula falsi}\\index{regula falsi}\" (for: regularly false) or also named \"\\NewTerm{false position method}\\index{fale position method}\" is still a root search algorithm to zero. To introduce it, consider the following figure:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/root_regula_falsi.jpg}\n\t\t\\caption{Regula falsi method scheme}\n\t\\end{figure}\n\tThe implementation, on a computer, of this method is particularly simple. The conditions to be satisfied being only that in the interval $[a,b]$:\n\t\\begin{itemize}\n\t\t\\item $f$ must be continuous\n\n\t\t\\item $f$ must be monotone near the root $x^{*}$\n\t\t\n\t\t\\item $f(a)f(b)<0$ to sure that there is a root\n\t\\end{itemize}\n\tIf $P_n$ is the point of coordinates $(x_n,0)$, then the points $(A,B,P_n)$ are aligned on the secant. The following proportion (application of Thales theorem) is then true:\n\t\n\thence we deduce that:\n\t\n\tThe algorithm consists therefore in performing the following steps:\n\t\\begin{enumerate}\n\t\t\\item We fix $\\varepsilon>0$ as upper bound of the admissible error tolerance.\n\t\n\t\t\\item Calculation of $x_n=\\dfrac{af(b)-bf(a)}{f(b)-f(a)}$\n\n\t\t\\item Evaluation of $f(x_n)$\n\n\t\t\\item If $|f(x_n)|<\\varepsilon$, the job is done. We have to display $x_n$\n\n\t\t\\item Otherwise we proceed as following:\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item we replace $a$ by $x_n$ if $f(x_n)f(a)>0$.\n\t\n\t\t\t\t\\item we replace $b$ by $x_n$ if $f(x_n)f(b)>0$ or $f(x_n)f(a)<0$.\n\t\t\t\t\n\t\t\t\t\\item we go back in (2)\n\t\t\t\\end{enumerate}\n \t\\end{enumerate}\n \tOnce again, the previous step (4) imposes the condition for stopping the calculations. Sometimes it is better to choose another criterion calculation ending. It requires the calculated solution to be contained in an interval of length equation containing the root $x^{*}$. This test is enunciate as follows:\n\t\\begin{enumerate}\n\t\t\\item[4'.] If $|b-a|<\\varepsilon$, the job is finished and $x_n=\\dfrac{af(b)-bf(a)}{f(b)-f(a)}$ is displayed. It is for sure obvious that $|x-\\bar{x}|<\\varepsilon/2$\n\t\\end{enumerate}\n \tIn pseudo-code (non-unique and not optimized):\\\\\\\\\n\t\\begin{algorithm}[H]\n\t \\KwData{$a$,$ b$, $\\varepsilon$ expression of $f$ }\n\t \\KwResult{$\\bar{x}$}\n\t initialization\\;\n\t$x_n=\\dfrac{af(b)-bf(a)}{f(b)-f(a)}$\\;\n\t\\While{$|f(x)|>\\varepsilon$}{\n\t    \\uIf{$f(x)f(a)>0$}{\n     \t\t$a:=x_n$\\;\n\t \t}\n\t\t\\uElseIf{$f(x_n)f(b)>0\\; \\vee \\; f(x_n)f(a)<0$}{\n\t\t\t$b:=x$\\;\n\t\t}\n\t\t$x_n=\\dfrac{af(b)-bf(a)}{f(b)-f(a)}$\\;\n\t }\n\t Display $x_n,f(x_n)$\\;\n\t \\caption{Regual-Falsi pseudo-code algorithm}\n\t\\end{algorithm}\n\tNotice that the initial above relation can also be rewritten:\n\t\n\tIf we change a little bit the notation we get:\n\t\n\tWe then use this new value of $x$ as $x_2$ and repeat the process using $x_1$ and $x_2$ instead of $x_0$ and $x_1$. We continue this process, solving for $x_3$, $x_4$, etc., until we reach a sufficiently high level of precision (a sufficiently small difference between $x_n$ and $x_n - 1$):\n\t\n\t\n\t\\pagebreak\n\t\\subsubsection{Newton's method}\n\tA few years after its discovery of the theory of gravitation, Newton developed a special technique to compute fast the solutions of any equation (very fast). This \"supernaturally\" fast convergence has been used to prove some of the most significant theoretical results of the 20th century: the Kolmogorov stability theorem, the isometric embedding theorem of Nash ... Alone, this technique transcends the distinction between pure mathematics and applied mathematics!!!\n\t\n\tTo study the \"\\NewTerm{Newton's method}\\index{Newton's method}\" (also named \"\\NewTerm{Newton-Raphson method}\\index{Newton-Raphson method}\" or \"\\NewTerm{Newton approximation scheme\"}\\index{Newton approximation scheme}) in the plane (hence in the univariate case), consider the following figure:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/root_newton_method.jpg}\n\t\t\\caption{Newton's method in the plane}\n\t\\end{figure}\n\tIf $x_0$ is an approximation of the root $\\bar{x}$, we notice that $x_1$ is as better one. The point $x_1$ is the intersection of the tangent to the curve $(x_0,f(x_0))$ with the $x$-axis. The point $x_2$ is even a better approximate of $\\bar{x}$, the point $x_2$ is obtained in the same manner as $x_1$ but from $(x_1,f(x_1))$.\n\t\n\tNewton's method consists in the formalization of this geometric fact.\n\t\n\tTo use this technique, remember that if we take a function $f$ that is differentiable on $x_0$, then we can rewrite it in the form (\\SeeChapter{see section Sequences and Series}):\n\t\n\twhere $f'(x_0)$ is the derivative of $f$ in $x_0$ and $\\mathcal{O}(x-x_0)$ is a function that tends to $0$ as $(x-x_0)^n$ when $n \\geq 2$ when $x$ tends to $x_0$ (this is as we know a corrective term for the superior orders of the Taylor series).\n\t\n\tApplying this result to solve $f(x)=0$, we get:\n\t\n\tThe function does not permit the resolution of this equation relatively to $\\bar{x}$. By neglecting this term we get obviously:\n\t\n\tThis is just the expression of the discrete derivative. Indeed:\n\t \n\tThe latter relation is easily resolved with respect to $\\bar{x}$. To see this, let us begin by putting $\\bar{x}=x_1$:\n\t\n\tBut $x_1$ does not satisfy, in general, the equality $f(x_1)=0$. But as we have already pointed it out, $|f(x_1)|$  is smaller than $|f(x_0)|$ if the function $f$ satisfies some conditions.\n\t\n\tNewton's method consists in replacing the relation:\n\t\n\tby:\n\t\n\tand to iteratively solve this relation.\n\t\n\tThe following conditions are sufficient to ensure the convergence of the method in an interval $[a, b]$ including $x_0$ and $\\bar{x}$:\n\t\\begin{enumerate}\n\t\t\\item The function is twice differentiable\n\n\t\t\\item The derivative $f'$ does not vanish (monotony)\n\t\t\\item The second derivative $f''$ is continuous and does not vanish (no inflection point)\n\t\\end{enumerate}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIt is often sufficient to check the conditions (1) and (2) for the process to converge.\n\t\\end{tcolorbox}\n\tThe condition (2) is obvious, indeed if $f'(x)=0$ the iteration can lead to a calculation overflow (singularity).\n\t\n\tThe third condition (3) is less obvious, but the following figure shows a case of non-convergence. In this case, the process loops calculating alternately $x_i$ and $x_j$:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/root_newton_method_non_convergence.jpg}\n\t\t\\caption{Non-convergence example of Newton method}\n\t\\end{figure}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tConsider the problem of finding the positive number $x$ with $\\cos(x) = x^3$. We can rephrase that as finding the zero of $f(x) = \\cos(x) - x^3$. We have $f'(x) = -s\\in(x) - 3x^2$. Since $\\cos(x) \\leq 1$ for all $x$ and $x^3 > 1$ for $x > 1$, we know that our solution lies between $0$ and $1$. We try a starting value of $x_0 = 0.5$. (Note that a starting value of $0$ will lead to an undefined result, showing the importance of using a starting point that is close to the solution!).\n\t\\begin{gather*}\n\t\t\\begin{matrix}\n  x_1 & = & x_0 - \\dfrac{f(x_0)}{f'(x_0)} & = & 0.5 - \\dfrac{\\cos(0.5) - (0.5)^3}{-\\sin(0.5) - 3(0.5)^2} & = & 1.112141637097 \\\\\n  x_2 & = & x_1 - \\dfrac{f(x_1)}{f'(x_1)} & = & \\vdots & = & \\underline{0.}909672693736 \\\\\n  x_3 & = & \\vdots & = & \\vdots & = & \\underline{0.86}7263818209 \\\\\n  x_4 & = & \\vdots & = & \\vdots & = & \\underline{0.86547}7135298 \\\\\n  x_5 & = & \\vdots & = & \\vdots & = & \\underline{0.8654740331}11 \\\\\n  x_6 & = & \\vdots &= & \\vdots & = & \\underline{0.865474033102}\n\t\\end{matrix}\t\n\t\\end{gather*}\n\tThe correct digits are underlined in the above example. In particular, $x_6$ is correct to the number of decimal places given. We see that the number of correct digits after the decimal point increases from $2$ (for $x_3$) to $5$ and $10$, illustrating the quadratic convergence.\n\t\\end{tcolorbox}\n\tIf the function $f$ is given analytically, its derivative can be determined analytically. But in many cases it is advisable or even necessary to replace $f'(x_n)$ by the differential quotient:\n\t\n\twhere $h$ should be chosen as small enough so that the difference:\n\t\n\tis also small enough.\n\n\tThe iteration is then written:\n\t\n\tIf the resolution method is converging, the gap between $x_{n+1}$ and $\\bar{x}$ decreases at each iteration. This is ensured, for example, if the interval $[a, b]$ containing $x_{n+1}$, sees its length decreasing at each step. \n\n\t\\begin{theorem}\n\tNewton's method is interesting because the convergence is quadratic:\n\t\n\twhile the convergence of other methods is linear such that:\n\t\n\tLet us consider, for example, the method of bisection seen previously. At each iteration the length of the interval $[a, b]$ is halved. This ensures us that the gap $|x_{n+1}-\\bar{x}|$ is halved at each step of the calculation:\n\t\n\t\\end{theorem}\n\t\\begin{dem}\n\tTo prove the quadratic convergence of the Newton method, we have to make use of the limited Taylor series of $f$ and $f'$ in the neighborhood of $\\bar{x}$:\n\t\n\tBut:\n\t\n\ttherefore:\n\t\n\tSubtracting $\\bar{x}$ left and right of the equality and putting the two terms of the second member to the same denominator, we get:\n\t\n\tand when $x_n-\\bar{x}$ is small enough, the denominator can be simplified.\n\t\n\twhich shows that convergence is quadratic.\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tLet us finally communicate that we will study the Newton's method with several variables during our study of nonlinear optimization. It is an educational choices that seemed to us the best choice.\n\t\\end{tcolorbox}\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tHere is an application with Maple 4.00b of this method:\\\\\n\t\n\t\\texttt{\n\t>with(plots): with(plottools):\\\\\n\t>f:=x->exp(x)*x\\string^2-36;\\\\\n\t>D(f)(x);\\\\\n\t>x[0]:=3;\\\\\n\t>n:=7;\\\\\n\t>g:=x->f(x[i-1])+D(f)(x[i-1])*(x-x[i-1]);\\\\\n\t>for i from 1 by 1 to n do;\\\\\n\t>x[i]:=evalf(solve(g(x)=0,x));\\\\\n\t>od;\\\\\n\t>lines:={}:\\\\\n\t>for i from 1 by 1 to n do;\\\\\n\t>lines:=lines union \\{line([x[i-1],0],[x[i-1],f(x[i-1])],color=green), line([x[i-1],f(x[i-1])],[x[i],0],color=green)\\};\\\\\n\t>od:\\\\\n\t>display({plot(f(x),x=2..3.01)} union lines);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/engineering/newton_method_with_maple4.jpg}\n\t\t\\caption{Maple 4.00b application of Newton's method}\n\t\\end{figure}\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\subsection{Numerical Differentiation}\n\tIn numerical analysis, numerical differentiation describes algorithms for estimating the derivative of a mathematical function or function subroutine using values of the function and perhaps other knowledge about the function.\n\t\n\tMany modeling techniques or numerical resolution technique that we will see further use derivatives as for example the search of optimums (see further below), the finite element methods (see also further below). For example, to name the most famous case, the solver of Microsoft Office Excel 2007 and earlier offers some of the most elementary numerical derivatives that we will study here and reuse further:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/excel_solver_derivatives.jpg}\n\t\t\\caption{Screenshot of Microsoft Excel 2003 Solver}\n\t\\end{figure}\n\tTo allow a computer processing, the various derivatives  present in many algorithms must be approximated numerically. To do this, we use in the most basic case the principle of centered finite difference which is based on the following Taylor series expansions (\\SeeChapter{see section Sequences and Series}):\n\t\n\tWe then based on the base of this principle the following development of the second order:\n\t\n\tIt comes then when neglecting the higher order terms and subtracting and simplifying the two series above:\n\t\n\tRelation that we name \"\\NewTerm{first centered derivative with tangent estimate}\\index{first centered derivative with tangent estimate}\" (because we neglect all non-linear terms) or also \"\\NewTerm{Symmetric difference quotient}\\index{Symmetric difference quotient}\". We also find often this latter relation in the following equivalent form:\n\t\n\tNow let us see what we name the \"\\NewTerm{right first derivative}\\index{right first derivative}\" also named \"\\NewTerm{forward derivatives}\\index{forward derivatives}\", which consist simply in the application of the following intuitive  algorithm:\n\t\n\tand incidentally we can also define the \"\\NewTerm{left first derivative}\\index{left first derivative}\" also named \"\\NewTerm{backward derivative}\\index{backward derivative}\":\n\t\n\tWe see therefore the central derivatives require more calculations but are also more accurate. This below figure gives a quite summary of the previous relations with a special case:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/forward_backward_derivative.jpg}\n\t\t\\caption{Forward/Backward derivatives illustration}\n\t\\end{figure}\n\tWe can also develop more elaborate relations through Taylor expansions with superior orders, do averages between different methods and so on... it's quite endless...\n\t\n\t\\pagebreak\n\t\\subsection{Numerical Integration}\n\tIn numerical analysis, \"\\NewTerm{numerical integration}\\index{numerical integration}\" constitutes a broad family of algorithms for calculating the numerical value of a definite integral, and by extension, the term is also sometimes used to describe the numerical solution of differential equations. This subsection focuses on calculation of definite integrals. \n\t\n\tThe basic problem in numerical integration is to compute an approximate solution to a definite integral:\n\t\n\tto a given degree of accuracy. If $f(x)$ is a smooth function integrated over a small number of dimensions, and the domain of integration is bounded, there are many methods for approximating the integral to the desired precision.\n\t\n\tLet us consider the following figure:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/numerical_integration_interval.jpg}\n\t\t\\caption{Illustration of an interval under a curve}\n\t\\end{figure}\n\tWe would like to calculate the area between the $x$ axis, the curve $f$ and the straight vertical lines of equations $x=a$ and $x=b$. We assume in this case that the function $f$ is with positive values:\n\t\n\tWe would like to calculate the area between the $x$ axis, the curve $f$ and the straight vertical lines of equations $x=a$ and $x=b$. We assume in this case that the function $f$ is with positive values:\n\t\n\tThis problem, in its generality, is difficult or impossible to solve analytically in the most general cases. Below we will see some numerical methods for the approximate calculation of this area in increasing complexity order (sometimes these methods are used in corporations by employees who have only spreadsheets softwares like Microsoft Excel or OpenOffice Calc to calculate integrals...).\n\t\n\t\\subsubsection{Rectangles method}\n\tThe \"\\NewTerm{rectangle method}\\index{rectangle method}\" (also named the \"midpoint\" or \"mid-ordinate rule\") computes an approximation to a definite integral, made by finding the area of a collection of rectangles whose heights are determined by the values of the function.\n\t\n\tWe divide the interval $[a,b]$ into $n$ subintervals which bounds are the $x_i$. The lengths of these subintervals are $h_i=x_{i+1}-x_i$. We build rectangles which sides are $h_i$ and $f(x_i)$.\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/numerical_integration_left_inferior_rectangle_method.jpg}\n\t\t\\caption{Approach of the area under a curve by lower left rectangles method}\n\t\\end{figure}\n\tThe area of these rectangles is:\n\t\n\tIf the $h_i$ are small enough, $A_G$ is a good approximation of the sought approached area by the left method.\n\n\tWe can start this exercise again by choosing $h_i$ and $f(x_{i+1})$ as sides of the rectangles (so the approach from the right). We then get:\n\t\n\tThe correspondent figure is therefore the following:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/numerical_integration_right_superior_rectangle_method.jpg}\n\t\t\\caption{Approach of the area under a curve by upper right rectangles method}\n\t\\end{figure}\n\tAgain, the area of these rectangles approaches the area searched. To simplify computer code, it is useful to choose identical length intervals:\n\t\n\tIf we have $n$ rectangles, $h$ is then equal to $(b-a)/n$. The areas $A_D$ and $A_G$ become:\n\t\n\t\t\n\t\n\t\\subsubsection{Trapezoidal method}\n\tIn the purpose to increase the accuracy, it is possible to calculate:\n\t\n\tIn the case where all the intervals are of equal length, $A_T$ is equal to:\n\t\n\tThat we often find in the academic literature, in the form:\n\t\n\tThere are many other methods for solving this type of problem (including the Monte Carlo method that we will see further below).\n\t\n\tIn the case where the function $f$ is not made of only positive values, we no longer speak anymore about \"area\" but of \"\\NewTerm{Riemann sum}\\index{Riemann sum}\". The sum to calculate are then:\n\t\n\tand:\n\t\n\t\n\t\\pagebreak\n\t\\subsection{Optimization}\n\tIn mathematics, computer science and operations research, mathematical optimization (alternatively \"\\NewTerm{mathematical programming}\\index{mathematical programming}\") is the selection of a best element (with regard to some criteria) from some set of available alternatives.\n\n\tIn the simplest case, an optimization problem consists of maximizing or minimizing a real function by systematically choosing input values from within an allowed set and computing the value of the function. The generalization of optimization theory and techniques to other formulations comprises a large area of applied mathematics. More generally, optimization includes finding best available values of some objective function given a defined domain (or a set of constraints), including a variety of different types of objective functions and different types of domains.\n\t\n\tIn mathematics, conventional optimization problems are usually stated in terms of minimization (or changed to be as!). A large number of algorithms proposed for solving optimization problems are not capable of making a distinction between local optimal solutions and rigorous optimal solutions. The branch of applied mathematics and numerical analysis that is concerned with the development of deterministic algorithms that are capable of guaranteeing convergence in finite time to the actual optimal solution is named \"\\NewTerm{global optimization}\\index{global optimization}\".\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tWe speak of \"\\NewTerm{convex optimization}\\index{convex optimization}\" when any local minimum must be a global minimum. In other word there is only one unique solution.\n\t\\end{tcolorbox}\n\tIn the context of problem solving which involved two variables and their products, we then speak logically \"\\NewTerm{quadratic programming (QP)}\\index{quadratic programming}\" or simply \"\\NewTerm{nonlinear programming}\\index{nonlinear programmin}\". This is typically the case in financial engineering in portfolios modeling  (\\SeeChapter{see section Economy}) or in forecasting. We will study in details also further below simplified and particular version of the corresponding models that are the: Newton's method, quasi-Newton method, conjugate gradient method and nonlinear GRG.\n\n\t\\pagebreak\n\t\\subsubsection{Linear programming (Linear Optimization)}\n\tThe objective of the linear programming (LP-programming) is to find the optimum value of a linear function subject to a system of equations consisting in inequalities constraints that are also linear. The objective function is named \"\\NewTerm{economic function}\\index{economic function}\" (because used a lot in Economy) and we solve this type of system using typically, among others, a method named \"\\NewTerm{simplex method}\\index{simplex method}\" (see below), the corresponding graph is a \"\\NewTerm{polygon constraints}\\index{polygon constraints}\" (when the number of variable is obviously equal to $2$).\n\t\n\tThe reader can remember the following diagram that we saw in the section Calculus:\t\n\t\\begin{center}\n\t\\begin{tikzpicture}[scale=2]\n    \\draw[gray!50, thin, step=0.5] (-1,-3) grid (5,4);\n    \\draw[very thick,->] (-1,0) -- (5.2,0) node[right] {$x_1$};\n    \\draw[very thick,->] (0,-3) -- (0,4.2) node[above] {$x_2$};\n\n    \\foreach \\x in {-1,...,5} \\draw (\\x,0.05) -- (\\x,-0.05) node[below] {\\tiny\\x};\n    \\foreach \\y in {-3,...,4} \\draw (-0.05,\\y) -- (0.05,\\y) node[right] {\\tiny\\y};\n\n    \\fill[blue!50!cyan,opacity=0.3] (8/3,1/3) -- (1,2) -- (13/3,11/3) -- cycle;\n\n    \\draw (-1,4) -- node[below,sloped] {\\tiny$x_1+x_2\\geq3$} (5,-2);\n    \\draw (1,-3) -- (3,1) -- node[below left,sloped] {\\tiny$2x_1-x_2\\leq5$} (4.5,4);\n    \\draw (-1,1) -- node[above,sloped] {\\tiny$-x_1+2x_2\\leq3$} (5,4);\n\n\t\\end{tikzpicture}\n\t\\end{center}\n\tCorresponding to the following system of inequalities:\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tLinear programming is widely used (to name only the most famous case) in Logistics (maximal flow problem also named \"\\NewTerm{transport problem}\\index{transport problem}\"), in corporate finance or also in decision theory when we solve a mixed strategy game (see the section of Game and Decision Theory  for a practical example). That's why Microsoft Excel 12.0 and earlier includes a tool named the \"solver\" in which there is an option named \"Assume Linear Model\" which then requires the use of the simplex model that we will study below:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/excel_solver_lp.jpg}\n\t\\end{figure}\n\tor since the 2010 version of the software (the user interface has completely changed):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/excel_solver_lp_2010.jpg}\n\t\\end{figure}\n\t\\end{tcolorbox}\n\tWe will focus in particular in the section on the most widely used algorithm for linear optimization named the \"\\NewTerm{simplex algorithm}\\index{simplex algorithm}\".\n\t\n\tWhen a problem can be modeled as an economic function to be maximized with respect to certain constraints that are purely additive, so are typically in the context of linear programming.\n\t\n\tSo an economic function $Z$ as:\n\t\n\twhere the $x_i$ are variables that affect the value of $Z$, and the $c_i$ the weights of these variables modeling the relative importance of each of them on the value of the economic function.\n\t\n\tThe constraints  related to the variables are expressed by the following linear system:\n\t\n\tUnder general and matrix form this problem is written as:\n\t\n\t\n\tTo see the different method of resolution let us use an example as theoretical introduction:\n\t\n\tA factory produces two types of pieces $P1$ and $P2$ machined in two workshops $A1$ and $A2$. Machining times are for $P1$ or $3$ hours in the workshop $A1$ and $6$ hours in the workshop $A2$ and of for $4$ hours for $P2$ in the workshop $A1$ and $3$ hours in the workshop $A2$.\n\t\n\tWeekly up-time of human resources (workers) of the $A1$ workshop is $160$ hours and that of the workshop $A2$ is $180$ hours.\n\t\n\tThe profit margin is of $1,200.-$ for the pieces $P1$ and $1,000.-$ for pieces $P2$.\n\n\tThe question is how much of each kind of piece should we make to maximize weekly margin?\n\t\n\tThis will be formalized as follows (canonical formulation):\n\t\n\t\n\t\\paragraph{Graphical LP resolution}\\mbox{}\\\\\\\\\n\tThe graphical method is will adapted for problem with $2$ or $3$ variables but not more as our perception of hypervolume is quite limited for humans.\n\t\t\n\tWhen translate our optimization problem into graphical form, we speak also of \"\\NewTerm{polygon of constraints}\\index{polygon of constraints}\". Indeed, the economical constraints are represented by half planes. The solutions, if they exists, belongs to the intersection set name \"\\NewTerm{set of admissible solutions}\\index{set of admissible solutions}\" and is quite trivially represented in our case by:\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/lp_graph.jpg}\n\t\t\\caption{Illustration of a simple operational research problem with are of feasible solutions}\n\t\\end{figure}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIn the general case, for those who love the language of mathematicians ..., the information of a linear constraint geometrically corresponds to a half a space of $n$-dimensional space ($n$ being the number of variables) . In the elementary case, all the points in space that satisfy all constraints is limited by convex portions of hyperplane (see the case wiht $2$ variables, easy to illustrated), that is why the this is named also \"\\NewTerm{convex optimization}\\index{convex optimization}\". If the cost function is linear, the extreme point is a vertices (easy to see). The basic algorithm simplex algorithm (see further below) strat from one vertices and goes to the next vertices which locally maximizes the cost, and restarts the procedure as long as necessary.\n\t\\end{tcolorbox}\t\n\tTo find the coordinates of the vertices, we can use the graph if the points are easy to determine.\n\n\tIt is therefore to seek inside this area (connex), the pair  $(x_1,x_2)$ maximizing the economic function.\n\n\tHowever, the equation $Z$ is represented by a constant line of constant slope ($-1.2$) which all points $(x_1,x_2)$ provide the same $Z$ value for the objective function.\n\t\n\tIn particular, the straight line $1200x_1+1000x_2$ pass trough the origin and it provides a zero value to the economic function. To increase the value of $Z$ and therefore of the economic function, we have to take away from the origin (in the quarter $x_1>geq 0,x_2\\geq 0$ that is to say in the \\texttt{I}st quadrant) the line of slope $-1.2$. Obviously then we see very quickly that the simplex method will not work if the constraints of the polygon does not contain the origin point!\n\t\n\tTo meet the constraints, this straight line will be moved until the limit where it will not have a point of intersection anymore in comme with the are of admissible solutions (eventually a segment).\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/lp_graph_detailed.jpg}\n\t\t\\caption{Finding solutions graphically with the economic function}\n\t\\end{figure}\n\tThe optimal solution is therefore necessarily located on the periphery of the region of admissible solutions and the parallel formed by translating the economic function are named \"\\NewTerm{isoquants lines}\\index{isoquants lines}\" or \"\\NewTerm{isocost lines}\\index{isocost lines}\"...\n\t\t\n\t\\paragraph{Algebraic LP resolution}\\mbox{}\\\\\\\\\t\n\tLet us now see how to solve this problem analytically before moving to the theoretical part.\n\t\n\tSo we have the \"\\NewTerm{canonical system}\\index{canonical system}\":\n\t\n\twith:\n\t\n\tWe first introduce the \"\\NewTerm{slack variables}\\index{slack variables}\" to transform the $2$ inequalities in equalities. The system of equations takes then \"\\NewTerm{standard form}\\index{standard form}\":\n\t\n\tTherefore, for $x_1,x_2\\geq 0$ fixed, the slack variable whose coefficients are always unit, measure the distance to travel to reach the vertices.\n\n\tIt goes without saying that the technique of slack variables may be used for linear (or nonlinear) systems. Therefore, an constraint optimization system with inequalities, can always be reduced to an optimization system with equalities.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tObviously there is as much slack variable as inequalities.\n\t\\end{tcolorbox}\n\tFor the remaining part, we have noticed, after a review of this section, that the technique using tables (that we will see later) often presented in books and websites finally brought nothing to a deep understanding of the resolution mechanism (even if to program the computational method that is most convenient). Since the purpose of this book is to always prove with a maximum detail the operating principle of things so it goes without saying that we will opt for a first purely algebraic approach. Let us see it by returning to the system with the slack variables and the economic function but slightly rearranged:\n\t\n\tThe $A1$ constraint then becomes:\n\t\n\tand the constraint $A2$ respectively becomes:\n\t\n\tTherefore, the problem consist to maximize $Z$ with the constraints:\n\t\n\tLet us start with an obvious feasible solution given the constraints that is trivially:\n\t\n\tTherefore with the system:\n\t\n\twe find immediately:\n\t\n\tThe parameters in the actual state can be summarized as:\n\t\n\tTo go forward, the goal will be to make $Z$ grow and for this purpose we will increase only one single variable, choosing the one with the largest coefficient (weight) in:\n\t\n\tthat is to say $x_1$ (because implicitly we think this is how the $Z$ will increase the faster). We speak then of $x_1$ as the \"\\NewTerm{pivot direction}\\index{pivot direction}\". We keep then $x_2=0$ and we increase $x_1$ with the system which then reduces to:\n\t\n\tTherefore with $x_2=0$ and to begin $x_1=1$, we have:\n\t\n\tand we see that the constraints $x_1,x_2,x_3,x_4\\geq 0$ are still respected, it is the same if $x_1$ is equal to $2$, $3$, $4$, $5$, ... and this until $31$, because after:\n\t\n\tand one of the slack variable has become negative, the constraints $x_1,x_2,x_3,x_4\\geq 0$ are not all met and therefore this solution is not feasible.\n\t\n\tThe question in the general case is to ask ourselves until what value (the most constraint value, verbatim the smallest) we can increase $x_1$ while maintaining the condition $x_1,x_2,x_3,x_4\\geq 0$ when $x_2=0$? And the answer is quite simple:\n\t\n\tand therefore it is:\n\t\n\tthen we speak sometimes of the \"\\NewTerm{pivot step}\\index{pivot step}\". We then have the actual solution:\n\t\n\tWhich gives:\n\t\n\tGraphically, this is what we have just do:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/lp_graph_detailed_with_pivot.jpg}\n\t\t\\caption[]{Direction of the pivot head and arrival at point $(30, 0)$}\n\t\\end{figure}\n\tTo continue to increase $Z$ such simply (by increasing only one variable), we need a new system of equations similar to the original system:\n\t\n\twhere we had expressed the variables that takes are non-zero value depending on others who take a zero value, that is to say $x_3,x_4$, in function of $x_1,x_2$ since we had for recall:\n\t\n\tFor the remaining part, we must express $x_1,x_3$ and also $Z$ in function of $x_2,x_4$ since we just get for reminder:\n\t\n\tBefore getting the new system reaction function, making some algebraic manipulations:\n\t\n\twhich gives after simplification:\n\t\n\tand therefore it comes:\n\t\n\twhich gives after simplification:\n\t\n\tand we have identically:\n\t\n\tSo finally the system is:\n\t\n\tfrom which we reiterate the process (we increase only one  variable in $Z$ keeping the other to $0$). When we can not increase $Z$ as all coefficients are negative, well it is that we are at a maximum (thank you convexity...). Let us see this...\n\t\n\tIn $Z$ the biggest coefficient is now $x_2$ and so it leads us to put $x_4=0$. The most constraint value of $x_2$ that allows to always respect the constraints $x_1,x_2,x_3,x_4\\geq 0$ is therefore:\n\t\n\tAnd for this value, we have:\n\t\n\tThe original economic function then takes the value:\n\t\n\twhich therefore corresponds graphically to:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/lp_graph_detailed_with_pivot_second_iteration.jpg}\n\t\t\\caption{Pivot direction with arrival point at $(16, 28)$ for the second iteratio}\n\t\\end{figure}\n\tSo we see above that we arrived at the optimum value visible on the graph given at the beginning of this example. But how do we know that we arrived at the final point if we do not have plots or if we work in higher dimensions?\n\t\n\tIn fact, the process is terminated either when all the coefficients of the economic function are negative or that the most constraignant value that respects the constraints is equal to zero !!! Let's see if this is the case! We therefore have in our example:\n\t\n\tSo we'll rewrite the system:\n\t\n\twith this time $x_1,x_2$ and $Z$ dependant to $x_3,x_4$. We then have first:\n\t\n\tand we have:\n\t\n\tTherefore for $Z$ we have (the coefficients are all negative so we guess what comes ...):\n\t\n\tWe then have the new system:\n\t\n\tAs all coefficients of $Z$ are now negative, we're blocked because we would go in the wrong direction if we continue. We must therefore stop here and we adopt finally the solution:\n\t\n\tThe method of resolution using tables that is often presented in the literature is only useful to write the coefficients of the variables of the system a table, but the changes that we made are exactly those we just made algebraically before (but a the opposite of the tables the method we used don't hide the logic of the method).\n\t\n\t\\paragraph{Simplex algorithm LP resolution}\\mbox{}\\\\\\\\\n\tTo implement the  simplex algorithm, we must write the problem in a \"standard\" form and introduce the concept of \"base program\" that is the algebraic expression corresponding to the notion of \"extreme point of the polyhedron of eligible programs\" presented earlier above. Indeed, we will see that the solution of a problem of the linear programming type it exists, can still be obtained with a base program. The simplex method will therefore be to find a first base program and to build a following base programs constantly improving the economic function and thus leading to the optimum (this is what we name \"dynamic programming\").\n\t\n\tAn LP problem is said to be placed in its \"\\NewTerm{standard form}\\index{standard form}\" if it involves the search for the minimum of the objective function, the latter being subject to constraints in the form of linear equations and conditions of non-negativity of the variables, that is, say we can write it in the form earlier before:\n\t\n\tThat is to say, using matrix notation:\n\t\n\twhere the matrices $C:n\\times 1, A:m\\times n,b:m \\times 1$ respectively correspond to the activity coefficients of objective function, to the technical coefficients of activities and to second members of the constraints.\n\n\tWe will now see how a LP general problem can always be reduced to a standard form. As we guess it the concept of \"slack variable\" will be essential to perform this \"reduction\".\n\n\tFind the maximum of a function $f (x)$ is equivalent to find the minimum of the opposite sign function $f (x)$. Moreover, a constraint which is presented as an inequality:\n\t\n\tcan be replaced by the system:\n\t\n\twhere as we already know $s_i$ is the slack variable constraint such that $s_i\\geq 0$.\n\t\n\tOf course, if the system is such that:\n\t\n\tcan be replaced by the system:\n\t\n\timplying again to add a slack variable  and always with the constraint that $e_i\\geq 0$.\n\n\tThis work of putting in standard form work us to find a system of linear equations to solve system (we saw previously at the beginning of this section how to solve this kind of system with the pivot algorithm).\n\n\tThe matrix $A$ representing the components of the system of equations can be, as we know, expressed in different ways depending on the chosen vector basis (\\SeeChapter{see section of Vector Calculus}). We will introduce now the concept of \"\\NewTerm{canonical associated usable form}\\index{canonical associated usable form}\" by choosing a special base and show that this reformulation of constraint system will enable us to move towards the optimum.\n\t\n\tThe matrix $A$ can, after introduction of the slack variables be decomposed into two sub-matrices $[D|B]$, one containing the initial variables $D$ and the other with the slack variables $B$ such that:\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe slack variables are variable and not constant!! In a system where the variables are in quantity $n$ and the equations in quantity $m$ to have as a system where one of the equation would be written:\n\t\n\tTo add a slack variable such that:\n\t\n\twhere $x_{n+1}=e_i$ on each row $m$, the added slack variable being different of all variables already existing in the system. This is why we can decompose the matrix in two submatrices..\n\t\\end{tcolorbox}\n\tThe columns of the matrix $B$ are obviously, by definition of the method, units columns, linearly independent. These columns form a basis of the vector space of columns of $m$ elements (or dimensions) - the number of  lines of the system. We name $B$ the \"\\NewTerm{base matrix}\\index{base matrix}\".\n\t\n\tRight now it can seem a little bit confusing. So let us continue the theorey with a companion example as we have for habit to do it in this book.\n\tThe text below describing the simplex algorithm has been taken to Marcel Oliver (April 12, 2012) and formalized by our own work.\n\t\\begin{enumerate}\n\t\\item Step 1: Write the linear programming problem in standard form\n\t\n\tTurning a problem into standard form involves the following steps.\n\t\\begin{enumerate}\n\t\t\\item Turn Maximization into minimization and write inequalities in\n\t\tstandard order.\n\t\t\n\t\tThis step is obvious.  Multiply expressions, where appropriate, by\n\t\t$-1$.\n\t\t\n\t\t\\item Introduce slack variables to turn inequality constraints\n\t\tinto equality constraints with nonnegative unknowns.\n\t\t\n\t\tAny inequality of the form\n\t\t\n\t\tcan be replaced by:\n\t\t  \n\t\twith $s \\geq 0$.\n\t\t\n\t\t\\item Replace variables which are not sign-constrained by differences.\n\t\t\n\t\tAny real number $x$ can be written as the difference of nonnegative\n\t\tnumbers $x=u-v$ with $u,v\\geq 0$.\n\t\\end{enumerate}\n\n\tConsider the following example.\n\t\n\tsubject to \n\t\n\tWritten in standard form, the problem becomes:\n\t\n\tsubject to \n\t\n\n\t\\item Step 2: Write the coefficients of the problem into a\n\t\"\\NewTerm{simplex tableau}\\index{simplex tableau}\".\n\t\n\tThe coefficients of the linear system are collected in an augmented\n\tmatrix as known from Gaussian elimination for systems of linear\n\tequations; the coefficients of the objective function are written in a\n\tseparate bottom row with a zero in the right hand column.\n\t\n\tFor our example, the initial tableau reads:\n\t\\newcolumntype{B}{%\n\t  >{\\columncolor[gray]{.8}[.5\\tabcolsep]}c}\n\t\\begin{center}\n\t\\begin{tabular}{BcccBBB|c}\n\t  $x_1$ & $x_2$ & $u$ & $v$ & $s_1$ & $s_2$ & $s_3$ \\\\\n\t  \\hline\n\t  $1$ & $1$ & $-1$ & $1$ & $0$ & $0$ & $0$ & $1$ \\\\\n\t  $2$ & $-1$ & $-2$ & $2$ & $1$ & $0$ & $0$ & $5$ \\\\\n\t  $1$ & $-1$ & $0$ & $0$ & $0$ & $1$ & $0$ & $4$ \\\\\n\t  $0$ & $1$ & $1$ & $-1$ & $0$ & $0$ & $1$ & $5$ \\\\\n\t  \\hline\n\t  $-1$ & $-2$ & $-3$ & $3$ & $0$ & $0$ & $0$ & $0$ \n\t\\end{tabular}\n\t\\end{center}\n\tSo following what we have above, we get for:\n\t\n\tthat:\n\t\n\tThe variables associated to the column components of the matrix $S$ will now be named \"\\NewTerm{bases variables}\\index{bases variables}\". In our case the bases variables are then essentially the slack variables that we will write now $x_{n+1},x_{n+2},\\ldots,x_{n+m}$. The variables associates to the column of the matrix $X$ are named \"\\NewTerm{off-base variables}\\index{off-base variables}\", these are the variables $x_1,x_2,\\ldots,x_n$.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tLet us recall that in the expression of the economic function, only the off-base variables appear.\n\t\\end{tcolorbox}\n\tIn the following steps, we will act on the tableau by the rules of Gaussian elimination, where the pivots are always chosen from the columns corresponding to the bases variables.\n\t\n\tBefore proceeding, we need to choose an initial set of basic variables\n\twhich corresponds to a point in the feasible region of the linear\n\tprogramming problem.  Such a choice may be non-obvious, but we shall\n\tdefer this discussion for now.  In our example, $x_1$ and $s_1, \\dots,\n\ts_3$ shall be chosen as the initial bases variables, indicated by gray\n\tcolumns in the tableau above.\n\t\n\t\\item Step 3: Gaussian elimination\n\n\tFor a given set of basic variables, we use Gaussian elimination (\\SeeChapter{see section Lineal Algebra}) to reduce the corresponding columns to a permutation of the identity matrix.  This amounts to solving $A\\vec{x}=\\vec{b}$ in such a way that the values of the nonbasic variables are zero and the values for the basic variables are explicitly given by the entries in the right hand column of the fully reduced matrix. In addition, we eliminate the \tcoefficients of the objective function below each pivot.\n\t\n\tOur initial tableau is thus reduced to:\n\t\\begin{center}\n\t\\begin{tabular}{BcccBBB|c}\n\t  $x_1$ & $x_2$ & $\\boldsymbol{u}$ & $v$ & $s_1$ & $s_2$ & $s_3$ \\\\\n\t  \\hline\n\t  $1$ & $1$ & $\\boldsymbol{-1}$ & $1$ & $0$ & $0$ & $0$ & $1$ \\\\\n\t  $0$ & $-3$ & $\\boldsymbol{0}$ & $0$ & $1$ & $0$ & $0$ & $3$ \\\\\n\t  $\\mathit 0$ & $\\mathit{-2}$ & $\\boldsymbol{\\mathit{1}}$ & \n\t    $\\mathit{-1}$ & $\\mathit 0$ & $\\mathit 1$ & $\\mathit 0$ & \n\t    $\\mathit{3}$ \\\\\n\t  $0$ & $1$ & $\\boldsymbol{1}$ & $-1$ & $0$ & $0$ & $1$ & $5$ \\\\\n\t  \\hline\n\t  $0$ & $-1$ & $\\boldsymbol{-4}$ & $4$ & $0$ & $0$ & $0$ & $1$ \n\t\\end{tabular}\n\t\\end{center}\n\tThe solution expressed by the tableau is only admissible if all basic\n\tvariables are non-negative, i.e., if the right hand column of the\n\treduced tableau is free of negative entries.  This is the case in this\n\texample.  At the initial stage, however, negative entries may come up;\n\tthis indicates that different initial basic variables should have been\n\tchosen.  At later stages in the process, the selection rules for the\n\tbasic variables will guarantee that an initially feasible tableau will\n\tremain feasible throughout the process.\n\n\t\\item Step 4: Choose new basic variables\n\n\tIf, at this stage, the objective function row has at least one negative entry, the cost can be lowered by making the corresponding variable basic.  This new basic variable is named the \"\\NewTerm{entering variable}\\index{entering variable}\". Correspondingly, one formerly basic variable has then to become nonbasic, this variable is named the \"\"\\NewTerm{leaving variable}\\index{leaving variable}\". We use the following standard selection rules.\n\n\t\\begin{enumerate}\n\t\\item The entering variable shall correspond to the column\n\twhich has the most negative entry in the cost function row.  If all\n\tcost function coefficients are non-negative, the cost cannot be\n\tlowered and we have reached an optimum.  The algorithm then\n\tterminates.\n\t\n\t\\item Once the entering variable is determined, the leaving\n\tvariable shall be chosen as follows.  Compute for each row the ratio\n\tof its right hand coefficient to the corresponding coefficient in the\n\tentering variable column.  Select the row with the smallest finite\n\tpositive ratio.  The leaving variable is then determined by the column\n\twhich currently owns the pivot in this row.  If all coefficients in\n\tthe entering variable column are non-positive, the cost can be lowered\n\tindefinitely, i.e., the linear programming problem does not have a\n\tfinite solution.  The algorithm then also terminates.\n\t\\end{enumerate}\n\tIf entering and leaving variable can be found, go to Step~3 and\n\titerate.\n\t\n\tNote that choosing the most negative coefficient in rule (i) is only a\n\theuristic for choosing a direction of fast decrease of the objective\n\tfunction.  Rule (ii) ensures that the new set of basic variables\n\tremains feasible.  \n\t\n\tLet us see how this applies to our problem.  The previous tableau\n\tholds the most negative cost function coefficient in column $3$,\n\tthus $u$ shall be the entering variable (marked in boldface).  The\n\tsmallest positive ratio of right hand column to entering variable\n\tcolumn is in row $3$, as $\\tfrac31<\\tfrac51$.  The pivot in this row\n\tpoints to $s_2$ as the leaving variable.  Thus, after going through\n\tthe Gaussian elimination once more, we arrive at\n\t\\begin{center}\n\t\\begin{tabular}{BcBcBcB|c}\n\t  $x_1$ & $\\boldsymbol{x_2}$ & $u$ & $v$ & $s_1$ & $s_2$ & $s_3$ \\\\\n\t  \\hline\n\t  $1$ & $\\boldsymbol{-1}$ & $0$ & $0$ & $0$ & $1$ & $0$ & $4$ \\\\\n\t  $0$ & $\\boldsymbol{-3}$ & $0$ & $0$ & $1$ & $0$ & $0$ & $3$ \\\\\n\t  $0$ & $\\boldsymbol{-2}$ & $1$ & $-1$ & $0$ & $1$ & $0$ & $3$ \\\\\n\t  $\\mathit{0}$ & $\\boldsymbol{\\mathit{3}}$ & $\\mathit 0$ & $\\mathit 0$ \n\t      & $\\mathit 0$ & $\\mathit{-1}$ & $\\mathit{1}$ & $\\mathit 2$ \\\\\n\t  \\hline\n\t  $0$ & $\\boldsymbol{-9}$ & $0$ & $0$ & $0$ & $4$ & $0$ & $13$ \n\t\\end{tabular}\n\t\\end{center}\n\tAt this point, the new entering variable is $x_2$ corresponding to the\n\tonly negative entry in the last row, the leaving variable is $s_3$.\n\tAfter Gaussian elimination, we find\n\t\\begin{center}\n\t\\begin{tabular}{BBBcBcc|c}\n\t  $x_1$ & $x_2$ & $u$ & $v$ & $s_1$ & $s_2$ & $s_3$ \\\\\n\t  \\hline\n\t  $1$ & $0$ & $0$ & $0$ & $0$ & $\\tfrac23$ & $\\tfrac13$ & $\\tfrac{14}3$ \\\\\n\t  $0$ & $0$ & $0$ & $0$ & $1$ & $-1$ & $1$ & $5$ \\\\\n\t  $0$ & $0$ & $1$ & $-1$ & $0$ & $\\tfrac13$ & $\\tfrac23$ & $\\tfrac{13}3$ \\\\\n\t  $0$ & $1$ & $0$ & $0$ & $0$ & $-\\tfrac13$ & $\\tfrac13$ & $\\tfrac23$ \\\\\n\t  \\hline\n\t  $0$ & $0$ & $0$ & $0$ & $0$ & $1$ & $3$ & $19$ \n\t\\end{tabular}\n\t\\end{center}\n\tSince there is no more negative entry in the last row, the cost cannot\n\tbe lowered by choosing a different set of basic variables; the\n\ttermination condition applies.\n\n\t\\item Step 5: Read off the solution\n\n\tThe solution represented by the final tableau has all nonbasic\n\tvariables set to zero, while the values for the basic variables can be\n\tcan be read off the right hand column.  The bottom right corner gives\n\tthe negative of the objective function.\n\t\n\tIn our example, the solution reads $x_1=\\tfrac{14}3$, $x_2=\\tfrac23$,\n\t$x_3=u=\\tfrac{13}3$, $s_1=5$, $v=s_2=s_3=0$, which corresponds to\n\t$\\zeta=-19$, which can be independently checked by plugging the\n\tsolution back into the objective function.\n\t\n\tAs a further check, we note that the solution must satisfy the initial equation and inequations.  This can obviously be checked by direct computation.\n\t\\end{enumerate}\n\tIn summary, any LP once put in standard form is such that:\n\t\\begin{itemize}\n\t\t\\item There is a square sub-matrix of matrix $A$, which is named the \"base matrix\" and is equal to the square unit matrix $\\mathds{1}$ of size $m$ (indeed there are as many slack variables that lines in the original equations - at the number of $m$ - and as many columns as each slack variable has a different index).\n\n\t\t\\item The basic variables involved does not appear in the expression of the economic function.\n\n\t\t\\item The second member of the constraints consists of non-negative values.\n\t\\end{itemize}\n\tWe say then that the problem is put under a \"a canonical form associated with the basis $B$, corresponding to the basis variables $x_{n+1},x_{n+2},\\ldots,x_{n+m}$\".\n\t\n\t\\subsubsection{Nonlinear programming (Nonlinear optimization)}\n\tNonlinear programming is the process of solving an optimization problem defined by a system of equalities and inequalities, collectively termed constraints, over a set of unknown real variables, along with an objective function to be maximized or minimized, where some of the constraints or the objective function are nonlinear. \n\t\n\tA nonlinear optimization program (NLOP) is a generalization of linear programming (simplex algorithm) but about nonlinear functions and can also include nonlinear constraints and nonlinear economic functions.\n\n\tThe purpose of what follows is to understand in outline but with an acceptable level of rigour the optimization tools that offer many spreadsheets softwares like the previous versions of Microsoft Excel to the version 2007 (since the version 2007 we cannot make a fine-tuning of these options anymore):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/excel_solver_nonlinear_optimization.jpg}\n\t\t\\caption{Microsoft Excel 2003 Solver Options}\n\t\\end{figure}\n\t We will especially see now in what consist the \\textit{Newton} Search (meaning implicitly: \"Gauss-Newton method\") with the \\textit{Tangent} and \\textit{Quadratic} estimates. After which we will study also the Conjugate Gradients Search also with the tangent and quadratic methods respectively.\n\t \\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tWe will stop at the study of the above cited models because there is an excessive quantity of empirical models such as for example the best known models (algorithms): substitution method, method of Lagrange multipliers, Nelder-Mead algorithm, Broyden-Fletcher-Goldfarb-Shanno (BFGS) algorithm, algorithm  of simultaneous annhiliation (SA), methods of interior points... and see Wikipedia for a more complete list (there are over a dozen of methods without taking into account the variations including empirical adjustments).\n\t\\end{tcolorbox}\n\tWe will see it further below, but we already guess that the choice \\textit{Tangent} use a linear approximation (tangent) of the function to be optimized at the point considered when at the opposite the \\textit{Quadratic} option will make an estimation of a function of the second degree at the considered point (typically a parabola). If at the considered point, the function is well modeled by a quadric, then the \\textit{Quadratic} option can save time by choosing a better starting point that will require fewer steps on each additional research. If you have no idea of the behavior of a priori function, then the  \\textit{Tangent} option is slower but safer.\n\t\n\tA well known example in the literature to introduce the search of optimums of nonlinear functions, before moving on to the part taking into account constraints on the system, is the \"humpback whale function\" of that consist to find the minimum of:\n\t\n\tWith the range constraints:\n\t\n\twhat we can indeed check visually:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/humpback_whale_function.jpg}\n\t\t\\caption{Plot of the humpback whale function with minima already visible}\n\t\\end{figure}\n\tEither with Maple 4.00b:\n\t\n\t\\texttt{>plot3d(x\\string^2*(4-2.1*x\\string^2+1/3*x\\string^4)+x*y+y\\string^2*(-4+4*y\\string^2),\\\\\n x=-2..2,y=-1..1,contours=20,style=patchcontour,axes=boxed);}\n\n\tThat gives:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.65]{img/computing/humpback_whale_function_maple.jpg}\n\t\\end{figure}\n\n\tAs we can see, this function is a great example of multiple local minimum but there is also a must more vicious one that we will refer to when we will study evolutionary algorithms, the \"Rastgrini's function\":\n\t\n\t\\texttt{>plot3d(20+x\\string^2+y\\string^2-10*(cos(2*Pi*x)+cos(2*Pi*y)),\\\\ \tx=-5..5,y=-5..5,contours=20,style=patch,axes=boxed,numpoints=10000);}\n\t\n\tThat gives:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.65]{img/computing/rastgrini_function_maple.jpg}\n\t\\end{figure}\n\t\n\t\\paragraph{Substitution Method}\\mbox{}\\\\\\\\\n\tThe least complex method for solving a non-linear programming problem is named the \"\\NewTerm{substitution method}\\index{substitution method}\".\n\n\tThis method is restricted to models containing a single constraint and must be in addition to the equality type.\n\n\tLet us consider a companion example by considering the following economic function to maximize:\n\t\n \twith the constraint (remember that it must be an equality !!!):\n\t\n \tThe first step is then to arbitrarily substitute:\n\t\n \tIn the economic function to get:\n\t\n \tThis therefore brings us back to a function to be maximized which is unconstrained, so we can differentiate it and put it as zero. Then it comes:\n\t\n\tthat gives:\n\t\n\tFrom this we can deduce immediately that\n\t\n \tBy injecting those two values in the economic function, we then have:\n\t\n\tWe see by this example very quickly the limitations of this technique. The first being that the economic function was not too complex, the final equation to solve was therefore not a problem, the second being that there were only two variables, the third being that the constraint must be an equality as we have already mentioned.\n\t\n\t\n\t\\paragraph{Lagrange Multipliers Method}\\mbox{}\\\\\\\\\t\n\tThe \"\\NewTerm{Lagrange multipliers method}\\index{Lagrange multipliers method}\" is a rather general technique for solving nonlinear programming problems with one or more constraints with linear or non linear economic function with inequalities (rather than strict equations only) and with more than two variables (for Other examples than those presented here the reader can go to the corresponding page of Wikipedia).\n\n\tWe will begin to present this technique by a simple case which consists simply of taking again the example used during our study of the method of substitution:\n\t\n\tThe first step is to write the constraint function in Lagrangian form as we do in Analytical Mechanics (\\SeeChapter{see section  Analytical Mechanics}) at the difference that there are no general variables depending on the time:\n\t\n\tFor this, we write first:\n\t\n\tThen the idea is that since this expression is null, nothing prevents us from summing it or subtracting it from the economic function with why not an empirical multiplier that we will denote $\\lambda$ and which we will name the \"\\NewTerm{Lagrange multiplier}\".\n\n\tIt comes then if we choose to subtract for example (in fact the choice of the subtraction is made by anticipation of an interpretation of the Lagrange multiplier that we will see immediately after):\n\t\n\tWhich gives us our Lagrangian function. In generic form the latter is often written as following:\n\t\n \tNow the idea is to determine the values of the variables where the partial derivatives of the Lagrangian with respect to the variables vanish at the same time (corresponding in Analytichal Mechanis as the sum of all the Lagrangians relatively to one variable to be equal to zero):\n\t\n \tWhat is generally written as:\n\t\n\tWe therefore have a system of three equations with three unknowns which we know trivially how to solve (\\SeeChapter{see section Linear Algebra}). We then get as solutions:\n\t\n \tNotice that if we had not taken into consideration $\\lambda$ and therefore that implicitly that latter had been equal to $1$ since the beginning, we would have had the following system of equations:\n\t\n\tand therefore we would not have obtained the results of the substitution method seen previously ... hence the multiplicative factor!\n\n\tThe final value of $Z$ is then the same as for the substitution method taking into account $\\lambda$!!!\n\n\tAlthough the Lagrange multiplier method is powerful, its increasing complexity with a large number of variables makes it a difficult tool to manipulate in practice.\n\n\tWe will now focus on the interpretation of $\\lambda$. As we shall see, the latter represents the local variation rate per unit of positive variation of the constant of the constraint function. Thus, if the constraint function becomes (we have changed the $40$ into a $41$):\n\t\n\tBy doing again the same calculations as before, we then get\n\t\n \tTherefore, by having increased of one unit the constant of the constrained function, we have:\n\t\n \tIn general, if the Lagrange multiplier is positive, then the economic function will increase if the constant of the constraint is also incremented positively and vice versa.\n\n\tLet us now consider a case much more elaborate a useful for our stud of Economics (especial Portfolio Optimization). We want to solve by the method of the Lagrange Multipliers the Markowitz portfolio problem (\\SeeChapter{see section Economy}):\n\t\n\twith for recall:\n\t\n\tTo facilitate the developments that will follow we will write this system with the following notation (for the details on the notations see the section Economy):\n\t\n\tThe Lagrangian function will therefore be written:\n\t \n\tTherefore:\n\t \n \tNow we calculate:\n\t \n\tThis gives us the system of three equations:\n\t  \n\tBy rearranging the first equation:\n\t \n \tWe have:\n\t \n \tLet us now take the two equations:\n\t\n\tThus in an equivalent way:\n\t\n\tBy injecting in it the explicit relation of the weights of the portfolio, we have:\n\t\n\tWe can put this system in matrix form:\n\t\n\tWhich gives us:\n\t\n\tTherefore:\n\t\n\tSo once we have the values of these two Lagrange multipliers, we just have to inject them into:\n\t\n \tTo have weights that minimize the portfolio variance:\n\t\n\tSo the reader will see during our study of Modern Portfolio management that getting the optimal weights is much more easy using the Lagrange multiplied method (and less time consuming) than using a software optimizer!\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tBy the way the attentive reader will perhapse have noticed that finally making all the developement with the factor $1/2$ is useless since during the final substitution, the latter is neutralized with itself since $2$ is multiplied by $1/2$.\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\paragraph{Newton-Raphson Method (Quadratic Newton)}\\mbox{}\\\\\\\\\n\tThe \"\\NewTerm{Newton-Raphson method}\\index{Newton-Raphson method}\" is a technique for searching the extremum of a function or also, as we will see it when we will compare with a special example the difference between the Gauss-Newton method with that of Newton, for nonlinear regression.\n\n\tThe Newton-Raphson, who in earlier versions to Microsoft Excel 2007 was activated in the solver by selecting Newton and Quadratic option uses the second order Taylor approximation (ie with second order derivatives) to have a quadratic function (parabola) which converges if the origin point of the research is close to the optimum. This approximation is repeated to each iteration.\n\n\tTo start the formal approach let us recall that we have proved in the section Sequences and Series that a Taylor expansion for a function of two variables could be written in quadratic approximation by:\n\t\n\twhere for recall $h$ and $k$ are variables and $x_0,y_0$ are fixed and where we have the Hessian matrix:\n\t\n\tthat American experts in the field have a habit (unfortunate in my opinion ...) Note:\n\t\n\tthe latter expression being the most common can be very misleading with the notation of the Laplacian.\n\n\tIn the field of numerical methods it is customary to write the Taylor series above with few notations changes by putting first:\n\t\n\tThis gives us a more condensed and technical form of the Taylor series around $\\vec{x}$:\n\t\n\tBy changing again a little bit the notations:\n\t\n\tWe thus fall back on the usual expression of a function of $\\mathbb{R}^2\\rightarrow \\mathbb{R}$ evaluated in Taylor series centered on $\\vec{x}$.\n\n\tBut if we seek for a local extrema (also sometimes named \"\\NewTerm{critical point}\\index{critical point}\"), we will need in first time that the derivative of the whole Taylor series be equal to zero. That is to say:\n\t\n\tand that the determinant of the Hessian matrix is positive (\\SeeChapter{see section Sequences and Series}). And to know if we are on a local maximum or local minimum, we must look at the sign of $\\partial_x^2 f(\\vec{x})$.\n\n\tLet us rewrite the above relation explicitly as we proved it in the section of Sequences and Series for pedagogical reasons:\n\t\n\tAnd let us recall that all terms $x_0,y_0$ are constants because it is either the function $f$ evaluated the particular point $(x_0,y_0)$, or the partial derivative evaluated at the same point, either the partial second derivative always evaluated at the same point, etc.\n\n\tSo finally the gradient will give:\n\tAnd let us recall that all terms $x_0,y_0$ are constants because it is either the function $f$ evaluated the particular point $(x_0,y_0)$, or the partial derivative evaluated at the same point, either the partial second derivative always evaluated at the same point, etc.\n\n\tSo finally the gradient will give:\n\t\n\tand returning traditional notations in the field of numerical methods, we have then:\n\t\n\tAnd so as the gradient has to be equal zere, we have:\n\t\n\tand after a first rearrangement:\n\t\n\tand a second rearrangement:\n\t\n\twhich often written:\n\t\n\tand by american specialists:\n\t\n\tFinally, before moving on to a concrete example it is important that the reader remembers the relation just seen above:\n\t\n\t\n\t\\pagebreak\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tWe are seeking a local extremum of the \"humpback whale\" function shown earlier above:\n\t\n\twith the starting point (arbitrary):\n\t\n\tTo do the search, we calculate the gradient:\n\t\n\tand the hessian matrix:\n\t\n\tWe then have:\n\t\n\tand:\n\t\n\tand:\n\t\n\tand therefore:\n\t\n\tand we start again (with less detail):\n\t\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\n\tand therefore:\n\t\n\tand once again (with again less details):\n\t\n\tand therefore:\n\t\n\tand again (with even less detail):\n\t\n\tand values will not move anymore. But if we look at the original graphic where we highlighted the convergence point by a red point:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.85]{img/computing/convergence_point_humpback_whale_example.jpg}\n\t\t\\caption[]{Highlight of the convergence point in the humpback whale function}\n\t\\end{figure}\n\twe see that this system does not search a a global extremum bu a local extremum as we already specified it. In fact, as the reader may test itself, convergence is very sensitive to initial starting point.\n\t\\end{tcolorbox}\n\t\n\t\\paragraph{Gauss-Newton Method (Tangent Newton)}\\mbox{}\\\\\\\\\n\tThe Gauss-Newton method is a powerful approximation without the derivatives of the second order of the Newton-Raphson method that in the prior versions of Microsoft Excel 2007 was activated in the solver by selecting the option \\textit{Newton} and \\textit{Tangent}.\n\n\tTo study this method, let us do use a companion concrete example. Suppose we obtained the following data:\n\t\n\tand we suppose \"a priori\" that the data follow the following theoretical model (we could also try any other function):\n\t \n\tWe look then for $x_1,x_2$ that minimize the sum of squares between the experimental and theoretical values such that:\n\t\n\twith therefore:\n\t\n\tLet us write following the traditition in this field:\n\t\n\tWe then have the following common notation:\n\t\n\tNow, imagine that we found a bipoint $(x_1,x_2)=(\\vec{x})$ that gives this minimum and let us write it $(\\vec{x}_{*})$ and without forgetting that it will remain a local minimum and with luck a global one...! \n\n\tLet us consider a special case that we will name \"\\NewTerm{compatible solution}\\index{compatible solution}\" and define by the fact the the bi-point that minimize the sum of squares of errors is also such that for all $i$ we have:\n\t\n\tTherefore it is immediate that:\n\t\n\tBefore going further, let us notice for example that for a component $j$ (which corresponds in our case to each variable of the a priori supposed theoretical function of our model):\n\t\n\twhere the last condensed equality is many times far to be obvious morever as it makes usage of the gradient of a vector field (\\SeeChapter{see section Vector Calculus}) that we see rarely in practice. The reader that should be destabilized can refer directly to the numerical example further below to makes thing more clear.\n\n\tSo to continue... we deduce that:\n\t\n\tand the \"compatible solution\" brings us obviously to:\n\t\n\tFollowing the same step, we have:\n\t\n\tSo finally we have the following tow relations:\n\t\n\tGiven that for the \"compatible solution\" we have:\n\t\n\tit follows that in this case the second relation becomes:\n\t\n\twhere $H$ is the hessian matrix (\\SeeChapter{see section Sequences and Series}) what American practitionners write simply:\n\t\n\tSo we can approximate in the case of the compatible solution, the hessian that contains derivatives of the second order by derivatives of the first order.\n\n\tSo we have finally in this special case the two relations that are the pillar of the Gauss-Newton method:\n\t\n\tNow let us recall the basic relation of the Newton-Raphson method obtained earlier above:\n\t\n\tand for information, any mathematical technique (because they are many of them!) that simplifies the Hessian matrix to the right of equality becomes part of the family named \"\\NewTerm{quasi-Newton methods}\\index{quasi-Newton methods}\".\n\t\n\tWell the Gauss-Newton method that interest us here and is therefore one of the techniques of the family of the \"quasi-Newton methods\" consists simply in a first step in getting rid of the second derivatives of the Hessian of the Newton-Raphson method at the right of the equality thanks to the previously established relations such that (attention to remember the abuse of writing!):\n\t\n\tand in a second time rewrite the gradient on the left ot the equality thanks thanks to also to the previously established relation. Which gives us:\n\t\n\tThe factor $2$ being not very aesthetic, almost all reference books optimize the problem with the following start relation:\n\t\n\tSo by simply multiplying by a factor $1/2$ (which does not change the result) we have then:\n\t\t\n\tLet us recall again that a spreadsheet software like Microsoft Excel can not determine the derivatives it will calculate them using the numerical methods of right or centered derivatives as we have presented a earlier above.\n\n\tNow let us come back to our example of the beginning! So we have:\n\t\n\tWe start with a bipoint that seems the closest to the desired solution:\n\t\n\tThen we have:\n\t\n\tand therefore we have:\n\t\n\tThen it comes:\n\t\n\tWhat we can therefore rewrite as:\n\t\n\tWe also have by extension:\n\t\n\tThen we apply the relation proved earlier above:\n\t\n\tTherefore:\n\t\n\tAfter a minor simplification:\n\t\n\tTherefore:\n\t\n\tand therefore the next bipoint for the iteration will be:\n\t\n\tWhich of corresponds well to the values of the first iteration:\n\t\n\tWe will not do again explicitly also the other iterations. So this is what we get in the end:\n\t\n\twith therefore for local solution at the 4th iteration:\n\t\n\tWith Maple 4.00b we get:\n\t\n\t\\texttt{>with(plots):}\\\\\n\t\\texttt{>points:=plot([[1,3.2939],[2,4.2699],[4,7.1749],[5,9.3008],[8,20.259] ],style=point,color=blue,symbol=circle):}\\\\\n\t\\texttt{>plot\\_GN:=plot(2.5411*exp(0.2595*x),x=0..8):}\\\\\t\n\t\\texttt{>display([pict1,pict2]);}\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/gauss_newton_example_plot.jpg}\n\t\t\\caption[]{Points and our interpolated Gauss-Newton function}\n\t\\end{figure}\n\t\t\n\tTo close this subject let us do a comparison with the Newton-Raphson method for the first iteration using the same starting bipoint. Let us recall again that for this latter method, the iterations are based on the relation:\n\t\n\tand we will write the function as following for the Newton-Raphson method:\n\t\n\tand:\n\t\n\tThen we have:\n\t\n\tthat becomes:\n\t\n\tThen we have:\n\t\n\tThat becomes:\n\t\n\tThus:\n\t\n\tTherefore:\n\tand therefore the next bipoint for the iteration will be:\n\t\n\twhich corresponds obviously to the values of the first iteration:\n\t\n\tWe will not do again explicitly also other iterations. So this is what it gives finally about our function to be minimized:\n\t\n\tSo the Newton-Raphson method converges in this case slower than that of Gauss-Newton.\n\t\n\t\\pagebreak\n\n\t\\subsection{Resampling statistics}\t\n\tResampling statistics refers to the use of the observed data or of a data generating mechanism (such as a die) to produce new hypothetical samples (resamples) that mimic the underlying population, the results of which can then be analyzed. With numerous cross-disciplinary applications especially in the sub-disciplines of the life science, resampling methods are widely used since they are options when parametric approaches are difficult to employ or otherwise do not apply. \n\t\n       Resampled data is derived using a manual mechanism to simulate many pseudo-trials. These approaches were difficult to utilize prior to 1980s since these methods require many repetitions. With the incorporation of computers, the trials can be simulated in a few minutes and is why these methods have become widely used.  The methods that will be discussed are used to make many statistical inferences about the underlying population. The most practical use of resampling methods is to derive confidence intervals and test hypotheses. This is accomplished by drawing simulated samples from the data themselves (resamples) or from a reference distribution based on the data; afterwards, you are able to observe how the statistic of interest in these resamples behaves. Resampling approaches can be used to substitute for traditional statistical (formulaic) approaches or when a traditional approach is difficult to apply. These methods are widely used because their ease of use. They generally require minimal mathematical formulas, needing a small amount of mathematical (algebraic) knowledge. These methods are easy to understand and stray away from choosing an incorrect formula in your diagnostics.\n      \\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.7]{img/computing/random_sampling.jpg}\n\t\t\\caption{Summary of resampling in different methods (source: ?)}\n\t\\end{figure}\n\t\n\t\\subsubsection{Monte Carlo Simulations}\n\tMonte Carlo methods (or Monte Carlo experiments) are a broad class of computational algorithms that rely on repeated random sampling to obtain numerical results. They are often used in physical and mathematical problems (finance, supply chain, decisioneering, quality, etc.) and are most useful as workaround when it is difficult or impossible to use other mathematical methods.\n\t\n\tIt finds applications in various fields including the following examples:\n\t\\begin{itemize}\n\t\t\\item Problems related to the neutron bomb (or any other problem of  the same family)\n\n\t\t\\item Calculations of integrals or various parameters of random variables (finance, insurance, risk, forecasting)\n\t\n\t\t\\item Resolution of elliptic or parabolic equations\n\n\t\t\\item Solving linear systems\n\n\t\t\\item Optimization Problem Solving (operations research, project management, supply chain)\n\n\t\t\\item Creation of statistical tests (Anderson-Darling, Kolmogorov, Levene, Brown-Forsythe, etc.)\n\t\\end{itemize}\n\tThus there are two types of problems that can be treated by the Monte Carlo probabilistic method:\n\t\\begin{enumerate}\n\t\t\\item  problems, which have a random behavior \n\n\t\t\\item deterministic problems, which do not have a random behavior\n\t\\end{enumerate}\n\t\n\tAbout the probabilistic case, the idea is to observe the behavior of a series of random numbers that simulates how the real problem behaves and derive statistical solutions/conclusions. We then speak of \"\\NewTerm{Monte Carlo estimation}\\index{Monte Carlo estimation}\".\n\n\tIn the deterministic case, the studied problem is completely defined and we cam in principle predict its evolution, but some parameters of the problem can be treated as if it were random variables (this is typically the case in \"vector regression\" technique in Economy). The deterministic problem them becomes probabilistic and still solvable numerically. We then speak of \"\\NewTerm{Monte Carlo elaborated estimation}\\index{Monte Carlo elaborated estimation}\".\n\t\n\tLet us begin with the most used one in business: generating draws from a probability distribution. For this purpose we need to introduce the Inverse transform sampling.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe name of \"Monte Carlo method\" date around 1944. Isolated researchers have used however long before similar statistical methods: for example, Edwin Herbert Hall for the experimental determination of the speed of light (1873), or Kelvin in a discussion of the Boltzmann equation (1901), but the real use of Monte Carlo methods began with research on the atomic bomb.\\\\\n\n\tDuring the immediate postwar period, John Von Neumann, Encrio Fermi and Stanislaw Ulam warned the scientific community of the applicability of the Monte Carlo methods (eg for the approximation of the eigenvalues of the Schrödinger equation). The systematic study was made by Harris and Herman Khan in 1948. After an eclipse caused by too intensive use during the 1950s, the Monte Carlo method is back since almost everybody can run complex management or business strategic simulations on office computers (with softwres like @Risk or CrystalBall).  in short, wherever it is profitable to use simulation processes.\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\paragraph{Inverse Transform Sampling}\\mbox{}\\\\\\\\\n\tInverse transform sampling (also known as inversion sampling,  inverse probability integral transform, inverse transformation method, Smirnov transform, golden rule,) is a basic method for pseudo-random number sampling, i.e. for generating sample numbers at random from any probability distribution given its cumulative distribution function.\n\t\n\tInverse transformation sampling takes uniform samples of a number $\\mathcal{U}$ between $0$ and $1$, interpreted as a probability, and then return the largest number $x$ from the domain of the distribution $P(X)$ such that $P(-\\infty < X < x) \\le \\mathcal{U}$. \n\t\n\tComputationally, this method involves computing the quantile function of the distribution — in other words, computing the cumulative distribution function (CDF) of the distribution (which maps a number in the domain to a probability between $0$ and $1$) and then inverting that function.\n\t\n\tTo use this we method we go through he \"\\NewTerm{probability integral transform}\\index{probability integral transform}\" that states that if $X$ is a continuous random variable with cumulative distribution function $F_X$, then the random variable $Y=F_X(X)$ has a uniform distribution on $[0, 1]$. The inverse probability integral transform is just the inverse of this: specifically, if $Y$ has a uniform distribution on $[0, 1]$ and if $X$ has a cumulative distribution $F_X$, then the random variable $F_X^{-1}(Y)$ has the same distribution as $X$.\n\t\\begin{theorem}\n\tSuppose that a random variable $X$ has a distribution for which the cumulative distribution function (CDF) is $F_X$. Then the random variable $Y$ defined as:\n\t\n\thas a uniform distribution.\n\t\\end{theorem}\n\t\\begin{dem}\n\tGiven any random variable $X$, define $Y = F_X (X)$. Then (it is not always easy to read this proof through the first time even if afterwards it is obvious):\n\t\n\t$F_Y$ is just the CDF of uniform random variable $\\mathcal{U}[0,1]$. Thus, $Y$ has a uniform distribution on the interval $[0, 1]$.\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\tThe problem that the inverse transform sampling method solves is as follows:\n\t\\begin{itemize}\n\t\t\\item Let $X$ be a random variable whose distribution can be described by the cumulative distribution function $F_X$.\n\t\t\\item We want to generate values of $X$ which are distributed according to this distribution.\n\t\\end{itemize}\nThe inverse transform sampling method works as follows:\n\t\\begin{enumerate}\n\t\t\\item Generate a random number $\\mathcal{U}$ from the standard uniform distribution in the interval $[0,1]$.\n\t\t\\item Compute the value $x$ such that $F_X(x) =\\mathcal{U}$ (using $F_X^{-1}(\\mathcal{U})$).\n\t\t\\item Take $x$ to be the random number drawn from the distribution described by $F_X$.\n\t\\end{enumerate}\nExpressed differently, given a continuous uniform variable $\\mathcal{U})$ in $[0, 1]$ and an invertible cumulative distribution function $F_X$, the random variable $X = F_X^{-1}(\\mathcal{U})$ has distribution $F_X$ (or, $X$ is distributed $F_X$).\n\n\t\\pagebreak\n\t\\paragraph{Random number generation}\\mbox{}\\\\\\\\\n\tThe best way to understand the method of Monte Carlo is to make examples (even small one should be enough). But for this, we must first have a good random number generator (which is quite difficult depending on the job). This is a very delicate and sensitive field for which an international standards is published (ISO 28640:2010 \\textit{Random variate generation methods}).\n\t\n\tA random-number generator (RNG) is a computational or physical device designed to generate a sequence of numbers or symbols that cannot be reasonably predicted better than by a random chance.\n\t\n\tSeveral computational methods for random-number generation exist. Many fall short of the goal of true randomness, although they may meet, with varying success, some of the statistical tests for randomness intended to measure how unpredictable their results are.\n\t\n\tThere are two principal methods used to generate random numbers. The first method measures some physical phenomenon that is expected to be random and then compensates for possible biases in the measurement process. Example sources include measuring atmospheric noise, thermal noise, and other external electromagnetic and quantum phenomena. For example, cosmic background radiation or radioactive decay as measured over short timescales represent sources of natural entropy.\n\t\n\tThe second method uses computational algorithms that can produce long sequences of apparently random results, which are in fact completely determined by a shorter initial value, known as a seed value or key. As a result, the entire seemingly random sequence can be reproduced if the seed value is known. This type of random number generator is often named a \"pseudorandom number generator\". This type of generator typically does not rely on sources of naturally occurring entropy, though it may be periodically seeded by natural sources. This generator type is non-blocking, so they are not rate-limited by an external event, making large bulk reads a possibility.\n\t\n\tLet us take, to begin, an example with the Maple 4.00b random generator:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/maple_random_generator.jpg}\n\t\t\\caption{Pseudo-random generator with Maple 4.00b}\n\t\\end{figure}\n\tand:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/maple_random_generator_restart.jpg}\n\t\t\\caption[]{Pseudo-random generator restart with Maple 4.00b}\n\t\\end{figure}\n\tSo we see that the default random number generator used by default in Maple 4.00b should be used with extreme caution since a system reset is enough to find... equal random values! This is therefore as we already said \"\\NewTerm{pseudo-random generator}\\index{pseudo-random generator}\" that gives possibilities to makes  sometimes named \"\\NewTerm{pseudo Monte Carlo method}\\index{pseudo Monte Carlo method}\".\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/maple_random_generator_special_library.jpg}\n\t\t\\caption[]{Pseudo-random library with Maple 4.00b}\n\t\\end{figure}\n\tThe \\texttt{RAND( )} and \\texttt{RANDBETWEEN( )} functions of the of Microsoft Excel 14.0.6123 are also pseudo-random generators which here is a sample of 100 simulations (of course in Microsoft Excel the chart below will change each time you press on the keyboard button: F9):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/random_generator_plot_excel.jpg}\n\t\t\\caption[]{Illustration of a sequence of pseudo-random numbers with Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\tUnfortunately, it may happen with pseudo-random numbers that the numbers generated are presented in bunches, that is to say by sets of numbers close to each other, which reduces the effectiveness of the Monte Carlo simulation .\n\n\tAn empirical technique is to use then sequences of numbers generated by algorithms that scan almost surely the range $[0,1]$. We speak then of \"\\NewTerm{quasi-random numbers}\\index{quasi-random numbers}\" to make simulations sometimes named \"\\NewTerm{quasi-Monte Carlo}\\index{quasi-Monte Carlo}\". In almost all Microsoft Excel, you can create a Visual Basic Application function that will replace the pseudo-random generators that are the \\texttt{RAND( )} or \\texttt{RANDBETWEEN( )}.\n\n\tHere is an example of such a V.B.A. function which generates quasi-random number named \"\\NewTerm{Fauré random number sequence}\\index{Fauré random number sequence}\":\n\t\n\t\\begin{lstlisting}[language={[Visual]Basic}, caption={VBA Fauré sequence code}]\n\t\tFunction SequenceFaure(n) As Double\n    \t\tDim f As Double, sb As Double\n    \t\tDim i As Integer, n1 As Integer, n2 As Integer\n    \n    \t\tn1 = n\n    \t\tsb = 1 / 2\n    \t\tDo While n1 > 0\n\t\t        n2 = Int(n1 / 2)\n\t\t        i = n1 - n2 * 2\n\t\t        f = f + sb * i\n\t\t        sb = sb / 2\n\t\t        n1 = n2\n\t\t    Loop\n\t\t    SequenceFaure = f\n\t\tEnd Function\n\t\\end{lstlisting}\n\tThis will gives the following sequence for a sample of $100$ simulations:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/faure_pseudo_random_sequence_excel.jpg}\n\t\t\\caption[]{Illustration of a Fauré sequence of pseudo-random numbers with Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\twhere we see well that the sequence covers well the whole area between $0$ and $1$ (we say then that: it covers faster the integration surface). This technique is sometimes preferred because it has the advantage of keeping the values off the simulation every time we restart the simulation (therefore in Microsoft Excel the chart above will not change when you press the keyboard button F9) .\n\n\tBy conse the sequence generators have a great weakness: they are only applicable (to my knowledge at least) for problems of simulations with a single random variable (typically pricing single option strategy following Black \\& Scholes model). Indeed if we have several random variables (and this is the most common case!), then the variables are artificially correlated (correlation coefficient = $1$) because they travel all the area between $0$ and $1$ in the same way! So a good simulation with several variables is a simulation including the treated variables have a correlation coefficient which approaches zero!!!!!!\n\n\tIn addition, sequence generators require algorithms that are very time consuming when there are many variables relatively to a pseudo-random generator, this is why in most situations we prefer the old methods.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tAs we already mention it, engineers should refer to the international standard ISO 28640: 2010 when they need to implement random number generators in their softwares.\n\t\\end{tcolorbox}\n\tOnce the pseudo-random or random generator created and tested, we can see some applicaton of the Monte Carlo method before continuing on performance tricks relatively to this method. Thus, in the calculation of integrals, this method is very useful and very fast in terms of convergence speed.\n\t\n\t\\pagebreak\n\t\\paragraph{Monte Carlo integration}\\mbox{}\\\\\\\\\n\tIn numerical integration, methods such as the Trapezoidal rule use a deterministic approach as we already know. Monte Carlo integration, on the other hand, employs a non-deterministic approaches: each realization provides a different outcome. In Monte Carlo, the final outcome is an approximation of the correct value with respective error bars, and the correct value is within those error bars.\n\t\n\tConsider for example the calculation of the following univariate defined integral of a function $f$ and positive over the interval $[a, b]$:\n\t\n\tGiven:\n\t\n\tthe maximal value of the function $f$ between the bounds $[a,b]$.\n\n\tWe consider the rectangle bounding function on the interval $[a, b]$ defined by vertices $\\{(a,0),(b,0),(b,m),(a,m)\\}$:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/monte_carlo_onedimensional_integration.jpg}\n\t\t\\caption{Basic principle of the univariate integral calculation with Monte Carlo}\n\t\\end{figure}\n\tWe draw a large number $N$ of random points in this rectangle. For each point, we test if it is below the blue curve. Given $P$ the proportion of points below this curve, we have:\n\t\n\tThe corresponding Maple 4.00b algorithm  is given by:\\\\\n\t\n\t\\texttt{>intmonte:=proc(f,a,b,N)}\\\\\n\t\\texttt{local i,al,bl,m,P,aleaabs,aleaord,isabove;}\\\\\n\t\\texttt{m:=round(max(a,b)*10\\string^4);}\\\\\n\t\\texttt{al:=round(a*10\\string^4);}\\\\\n\t\\texttt{bl:=round(b*10\\string^4);}\\\\\n\t\\texttt{aleaabs:=rand(al..bl);}\\\\\n\t\\texttt{aleaord:=rand(0..m);}\\\\\n\t\\texttt{P:=0;}\\\\\n\t\\texttt{for i from 1 to N do}\\\\\n\t\\texttt{     isabove:=(f(aleaabs()/10\\string^4)-aleaord()/10\\string^4)>=0;}\\\\\n\t\\texttt{     if isabove then}\\\\\n\t\\texttt{          P:=P+1;}\\\\\n\t\\texttt{     fi}\\\\\n\t\\texttt{od:}\\\\\n\t\\texttt{RETURN((b-a)*max(a,b)*P/N)}\\\\\n\t\\texttt{end:}\\\\\n\t\n\tTo call this procedure in Maple, just write \\texttt{>intmonte(f, a, b, N)} but replacing the first argument passed as a parameter with the expression of a function and the other arguments by numerical values (obviously!).\n\t\n\t\\paragraph{Monte Carlo Estimation of Pi}\\mbox{}\\\\\\\\\n\tFor the calculation of $\\pi$ the principle is the same and therefore consist to use the proportion of the number of points in a quarter of circle area (this simplifies the algorithm by restricting the calculations to strictly positive coordinates) inscribed in a square of side $1$ (so the radius of the circle is also equal to $1$ obviously) relatively to the total number of points (to test if a point is outside the circle, we obviously use the Pythagorean theorem) such that:\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/monte_carlo_pi.jpg}\n\t\t\\caption{Monte Carlo $pi$ estimate}\n\t\\end{figure}\n\tThe corresponding Maple 4.00b algorithm is given by:\\\\\n\n\t\\texttt{>isinside:=proc(x,y) x\\string^2+y\\string^2<1 end:}\\\\\n\t\\texttt{>calculatepi:=proc(N)}\\\\\n\t\\texttt{local i,P,abs,ord,alea;}\\\\\n\t\\texttt{alea:=rand(-10\\string^4..10\\string^4);}\\\\\n\t\\texttt{P:=0;}\\\\\n\t\\texttt{for i from 1 to N do}\\\\\n\t\\texttt{     abs:=alea()/10\\string^4;ord:=alea()/10\\string^4;}\\\\\n\t\\texttt{       if isinside(abs,ord) then}\\\\\n\t\\texttt{            P:=P+1;}\\\\\n\t\\texttt{       fi}\\\\\n\t\\texttt{od;}\\\\\n\t\\texttt{RETURN(4*P/N)}\\\\\n\t\\texttt{end:}\\\\\n\t\\texttt{>evalf(calculatepi(100));evalf(calculatepi(1000));\\\\evalf(calculatepi(10000));evalf(calculatepi(100000));}\\\\\n\t\n\t\n\t\n\tIn terms of convergence it looks typically as:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/monte_carlo_pi_convergence.jpg}\n\t\\end{figure}\n\t\n\t\\paragraph{Monte Carlo Modeling}\\mbox{}\\\\\\\\\n\tThe most common application of the Monte Carlo method in business and industry is certainly the study of random variables. Furthermore, this method is part of the ISO 31010 Risk Management standard under the name of \"\\NewTerm{Monte Carlo analysis}\\index{Monte Carlo analysis}\". Many cutting edge tech companies make Monte Carlo modeling with a spreadsheet softwares like Microsoft Excel (even multinationals!) and with a lesser extent with professional oriented softwares or add-ins such as @RISK, CrystalBall, TreeAge, Isograph or MATLAB.\n\t\n\tThe advantages of this method in modeling random variables are:\n\t\\begin{itemize}\n\t\t\\item We can integrate any distribution  including empirical one and not continuous one!\n\n\t\t\\item Models are very easy to implement and can be expanded as needed without too much effort.\n\n\t\t\\item All influences or relation occurring in reality (at least the identified one....) may be represented and implemented in the model.\n\n\t\t\\item Sensitivity analysis (\\SeeChapter{see section Quantitative Management Techniques}) can be applied.\n\n\t\t\\item The models are easily understable and provide a measure of the accuracy of the result.\n\n\t\t\\item Many inexpensive software are available (at least inexpensive in comparison to criticality of the business analyzed that is most of time in the order of the billion of dollars).\n\t\\end{itemize}\n\tLet us consider a simple but concrete case (widely used in business) that I like to use in my introduction training of a small project of two tasks denoted by $A$ and $B$ which follow each other without free margin (or free slack). Let us imagine that the duration of each task has been estimated in accordance with the recommendation of the Project Management Institute with a beta distribution (\\SeeChapter{see section Statistics}) as learn it all project managers in their training curriculum (\\SeeChapter{see section Quantitative Management Techniques}).\n\n\tFor this example, the task $A$ has an optimistic duration of $5$ days and a pessimistic duration of $8$ days. Task $B$ an optimistic duration of $1$ day and a pessimistic duration of $4$ days. We would like in the spreadsheet software Microsoft Excel using a pseudo Monte Carlo simulation (therefore necessarily based on a pseudo-random variable) introduce three traditional minimum information:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/monte_carlo_tasks.jpg}\n\t\\end{figure}\n\t\\begin{itemize}\n\t\t\\item A table with $3$ columns (duration of $A$, $B$ and sum of both) and $10,000$ simulations (rows)\n\t\n\t\t\\item The graphical distribution function of the sum of the two random variables \n\n\t\t\\item The convergence of the 95th percentile on the $100$ first simulations (useful for the subject further below).\n\t\\end{itemize}\n\tWe then construct the following table of $10,000$ row (the screenshot shows only the first rows...):\n\n\twhere all cells from row $2$ to row $10,000$ of column A contains the following function (Microsoft Excel 14.0.7166):\n\n\t\\begin{center}\n\t\\texttt{=BETA.INV(RAND(),3+SQRT(2),3-SQRT(2),5,8)}\n\t\\end{center}\n\n\tand for column B contains the following function:\n\n\t\\begin{center}\n\t\\texttt{=BETA.INV(RAND(),3+SQRT(2),3-SQRT(2),1,4)}\n\t\\end{center}\n\n\tand finally the cell C1 contains the following function that was pull down until cell C10000:\n\t\n\t\\begin{center}\n\t\\texttt{=A2+B}\n\t\\end{center}\n\t\n\tObviously the values in Microsoft Excel 14.0.6123 will change each time you press the \\texttt{F9} key on the keyboard.\n\n\tThen this gives us the histogram still made with the same software version (we will not detail how to building such a chart it is a basic subject of Microsoft Office knowledge and has nothing to do in a scientific book) where the $x$-axes are the number of days:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/monte_carlo_histogram_tasks.jpg}\n\t\\end{figure}\n\tand the convergence of the $95$th percentile of the first $100$ simulations (because as this example is simple, the system converges quickly enough so that we do not to need to take more than $100$ simulations as example) where the $y$-axes is the number of days:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/monte_carlo_convergence_tasks.jpg}\n\t\\end{figure}\n\tObviously by default, in Microsoft Excel 14.0.6123 the chart above will change each time you pres the \\texttt{F9} key on the keyboard.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIn the case of the simulations of random variables, we can in simple cases involving only sums or subtractions of random variables, as is the case for the example above, determine the mean and the standard deviation of the results analytically using the property of linearity of the mean and variance (because normally for the variance of two independent random variables, the covariance is zero). By analyzing the difference between the analytical value and that obtained by numerical simulation, the offset can be corrected certain other statistical indicators by simply adding or subtracting the differential. This is known as the technique of \"\\NewTerm{control variables}\\index{control variables}\" that we will detail further below.\n\t\\end{tcolorbox}\n\tThere are other variance reduction techniques (ie: the standard deviation) that control variables technique Carlo to reduce the variance of the Monte Carlo estimators in specific conditions:\n\n\t\\begin{itemize}\n\t\t\\item One of these techniques is the use of \"\\NewTerm{antithetic variables}\\index{antithetic variables}\" which consists very simply (programming this technique at the high school level as you can see in the MATLAB™ companion book) to decorrelate simulations to make the covariance between the variables negative  and so reduce the global variance (such as we have seen in the section Statistics, the variance of the sum of two random variables make appear a covariance term). Unfortunately, this technique works satisfactorily with symmetric distributions this is why to my knowledge it is not implemented in simulation software available on the market.\n\n\t\t\\item There are also the technique named \"\\NewTerm{stratified sampling}\\index{stratified sampling}\" that consist to cut the  pre-image space of the random variable in regular intervals (the programming of this technique is also at the high school level as you can see in the MATLAB™ companion book). This technique works very well when the number of simulations must be small but only in the case of a single variable. This also why, as far as we I know, it is not implemented in simulation softwares available on the market.\n\n\t\t\\item There exist is a generalization of stratified sampling (the programming of this technique is also at the high school level) for simulations with multiple variables and that is named \"\\NewTerm{Latin Hypercube}\\index{Latin Hypercube}\" (abbreviated as \"LHS\" for Latin Hypercube Stratification). This technique ensures that each $n$-tuple of random variables (corresponding to a space of $n$ dimensions) uses a unique pre-image at each iteration, hence the name of that technique (Latin: refers to magic squares where each value appears uniquely, Hypercube because is an $n$-dimensional generalization of a magic square). Some simulation software available on the market implement this technique (@RISK, CrystalBall).\n\t\\end{itemize}\n\tTo summarize, whether that its the technique of Faure sequence generators, of antithetic variables, of control variables, of stratified sampling or Latin Hypercube even if these techniques are all easy to program, the method using the pseudo-random variables is privileged because is the most suitable for the majority of common situations in the business and in non-cutting edge scientific applications.\n\t\n\t\\subsubsection{Bootstrapping}\n\tIn statistics, \"\\NewTerm{bootstrap techniques}\\index{bootstrap techniques}\" can refer to any test or metric that relies on random sampling with replacement of a population of data to run statistical inference on small samples. This methods is relatively intensive in computations still for expensive office computers at this beginning of the 21st century.  \n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/bootstrap_sampling.jpg}\n\t\\end{figure}\n\tThe goal of bootstrapping is to find some indication of a statistic: its estimate of course, but also its dispersion (variance, standard deviation), confidence intervals or hypothesis testing. This method is based on simulations, such as Monte Carlo methods, with the difference that the bootstrap does not require additional information than that that is available already in the initial sample. In general, it is based on new samples obtained by sampling with replacement from the original sample (then we speak also of \"\\NewTerm{resampling}\\index{resampling}\").\n\t\n\tWe distinguish generally two types of bootstrap:\n\t\\begin{enumerate}\n\t\t\\item The bootstraps which make no assumptions about the probability distribution of the data analyzed. We then speak then as in statistics of \"\\NewTerm{non-parametric bootstrap}\\index{non-parametric bootstrap}\".\n\n\t\t\\item The bootstraps replacing each data measured by those corresponding to the analytical expression of the law of probability distribution assumed. We speak then of \"\\NewTerm{parametric bootstrap}\\index{parametric bootstrap}\". Once all the original values replaced, the process is exactly that of the non-parametric bootstrap.\n\t\\end{enumerate}\n\tWe will illustrate the principle of the bootstrap on the example of the confidence interval of the mean $\\mu$ of a random variable. For this example, the confidence interval for the mean of a random variable is completely determined from the mean and the variance calculated on the sample (\\SeeChapter{see section Statistics}).\n\n\tWe consider a sample of the random variable composed of $10$ estimates:\n\t\n\tLa arithematic average of this sample is:\n\t\n\tand it standard deviation (maximum unbiased likelihood estimator of the standard deviation):\n\t \n\tAs we are in the situation of a known sample mean and a known sample variance, to do the calculation of a confidence interval, then we have proved in the section Statistics that we had to use:\n\t\n\twhere $S$ is for recall another traditional notation in some areas of statistics for the notation of the empirical standard deviation (\\SeeChapter{see section Statistics}). We then have for the confidence interval at $95\\%$ of the mean:\n\t\t\n\tTherefore:\n\t\t\n\tWhich gives:\n\t\n\tThe confidence interval can also be calculated by bootstrap (this is especially useful for complicate distribution that are not symmetric and when we focus on the median rather than on the mean). Then it is therefor obtained by the Following algorithm:\n\t\\begin{enumerate}\n\t\t\\item From the initial sample, we simulate new samples of the same size, named \"\\NewTerm{bootstrap replicates}\\index{bootstrap replicates}\" of size $n$, by random draws with replacement (see figure above). For example with the previous series, we could get the following replicate:\n\t\t\n\t\tin which, by definition, some of the original sample values do not appear, and where others appear several times (yes it's a sampling with replacement therefore...). Several samples are simulated in this way. Se e can form a number of replicas (arrangements with replacement) equal to (\\SeeChapter{see section Probabilities}):\n\t\t\n\t\tTherefore with $10$ values we have $10,000,000,000$ possibilities...\n\t\t\n\t\t\\item For each simulated sample, an average\\footnote{in fact the process is the same for any estimate of any statistical indicator $\\hat{\\theta}$} is calculated (so we will have several thousand of averages!). \n\t\n\t\t\\item The $95\\%$ confidence interval is the calculate on this set of averages (or any other estimator) by typically using the percentile calculation (through the functions of a spreadsheet software or a programming/scripting language). This grouping is named the \"\\NewTerm{bagging}\\index{bagging}\" that is the abbreviation for \"\\NewTerm{Bootstrap Aggregating}\\index{Bootstrap Aggregating}\".\n\t\\end{enumerate}\n\tObviously for each set of bootstrap, the percentiles themselves will not be the same so it is even possible to create a confidence interval for the percentiles themselves!\n\t\n\tIt is quite easy (just like the Monte Carlo methods) to create replicas with spreadsheet software like Microsoft Excel (at least for people that know a little bit how to use a spreadsheet software) without computer programming or scripting (see below an example with Microsoft Excel)! Furthermore, the bootstrap technique is very powerful because it does not use any assumptions about the underlying statistical distribution. \n\n\tThe most common field of application of bootstrapping in \"direct\" business (I don't mind about Data Mining for Marketing that is not what I mean about \"direct business\") that I know is in project management during meetings where a dozen people estimates the duration of a project task or project phase.\n\t\n\tBootstrapping can therefore be applied to any estimator other than the average, as the median, the correlation coefficient between two random variables or the principal eigenvalue of a variance-covariance matrix (for principal component analysis), or the slope and intercept of a regression and this is its great strength!!! Indeed, for these estimators, there is no general mathematical relations that defines the standard error or confidence interval. The only methods applicable are resampling methods to which bootstrapping belongs to and this is intensively used since almost any home or office computer at the beginning of the 21st century is powerful enough to bootstrap small databases.\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tAs example let us first use a spreadsheet software like Microsoft Excel table 14.0.6123 and taking the theoretical companion example above as practical software example (we prohibit ourselves of doing VBA programming). We then build a small table with the previous sample:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/boostrapping_excel_initial_dataset.jpg}\n\t\\end{figure}\n\tAt the opposite of the companion theoretical example  would be able to determine a confidence interval for the median instead as for the arithmetic mean (we purposely take a statistical indicator for which there is simple analytical confidence interval). For this, we calculate the median of several thousand of replications in the column F (random choice!), where each replication corresponds to a row :\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/boostrapping_excel_resampling_median.jpg}\n\t\\end{figure}\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\twith the following quite long forula for Microsoft Excel Next 14.0.6123 to put in cell F5 and then pull down to the end of the sheet:\\\\\n\t\n\t\\texttt{=MEDIAN(INDEX($A$5:$A$14,RANDBETWEEN(1,10),1),\\\\\nINDEX($A$5:$A$14,RANDBETWEEN(1,10),1),\\\\\nINDEX($A$5:$A$14,RANDBETWEEN(1,10),1),\\\\\nINDEX($A$5:$A$14,RANDBETWEEN(1,10),1),\\\\\nINDEX($A$5:$A$14,RANDBETWEEN(1,10),1),\\\\\nINDEX($A$5:$A$14,RANDBETWEEN(1,10),1),\\\\\nINDEX($A$5:$A$14,RANDBETWEEN(1,10),1),\\\\\nINDEX($A$5:$A$14,RANDBETWEEN(1,10),1),\\\\\nINDEX($A$5:$A$14,RANDBETWEEN(1,10),1),\\\\\nINDEX($A$5:$A$14,RANDBETWEEN(1,10),1))\n\t}\n\t\n\tSo we can not have more that 10 billion more... corresponding to the $\\bar{A}_n^n$ calculate above (Microsoft Excel 14.0.6123 and after is limited  to $17,179,869,184$ cells...).\\\\\n\t\n\tThen simply in a cell of your choice we write:\\\\\n\t\\begin{center}\n\t\\texttt{=PERCENTILE(F5:F2003,0.025)}\n\t\\end{center}\n\tand in another cell:\\\\\n\t\\begin{center}\n\t\\texttt{=PERCENTILE(F5:F2003,0.975)}\n\t\\end{center}\n\t\n\twhich will give will $2,000$ replication respectively $7$ and $29.5$.\\\\\n\n\tWith basic knowledge of a spreadsheet software, it is possible to graphically show the convergence of the median in function the number of replications (below we used only the first $100$ replications):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.7]{img/computing/boostrapping_excel_median_convergence.jpg}\n\t\t\\caption[]{Convergence of the median in function of the number of replications}\n\t\\end{figure}\n\tObviously, this chart will look different every time you restart the simulation in Microsoft Excel 14.0.6123 by pressing the F9 key.\n\t\\end{tcolorbox}\n\t\n\tFinally let us indicate that after having study earlier above many linear regression models this does avoid the fact that in many cases no theoretical model is adapted either to interpolate or verbatim to extrapolate some data. Therefore, if we have for each abscissa point (exogenous variable) a given quantity of values  of the output (endogenous) variable, we can therefore use the bootstrapping method which will give us the bootstrapped regression coefficients and also bootstrapped interpolated or extrapolated values! This is an extremely interesting technique  in practice of non-parametric regression! We can do such bootstrap regressions in softwares like SPSS (with additional module) or SAS but also in the free R software with the right packages (see the companion book on R).\n\t\n\t\\pagebreak\n\t\\subsubsection{Jackknifing (jacknife resampling)}\n\tThe Jackknife was proposed by M.H. Quenouille in 1949 and later refined and given its current name by John Tukey in 1956 (it predates other common resampling methods such as the bootstrap). M.H. Quenouille originally developed the method as a procedure for correcting bias. Later, Tukey described its use in constructing confidence limits for a large class of estimators. It is similar to the bootstrap in that it involves resampling, but instead of sampling with replacement, the method samples without replacement.\n\n\tSo In statistics, the jackknife is a resampling technique especially useful for variance and bias estimation these estimator converge quick enough (the number of resampling is much more limited with jacknifing than with bootstrapping). The jackknife estimator of a parameter is found by systematically leaving out each observation from a dataset and calculating the estimate and then finding the average of these calculations. Given a sample of size $N$, the jackknife estimate is found by aggregating the estimates of each $N-1$ estimate in the sample.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/jacknife_permutation.jpg}\n\t\\end{figure}\n\tThis method is especially useful when:\n\t\\begin{enumerate}\n\t\t\\item Computer is now powerful enough to run a bootstrap\n\t\t\\item When we don't trust the resampling method as not suited to do the situation\n\t\\end{enumerate}\n\t\\textbf{Definition (\\#\\mydef):} The \"\\NewTerm{delete-1 Jackknife Samples}\\index{delete-1 Jackknife Samples}\" are selected by taking the original data vector and deleting one observation from the set. Thus, there are n unique Jackknife samples, and the $i$th Jackknife sample vector is defined as:\n\n\tThis procedure is generalizable to $k$ deletions, which is discussed further below.\n\n\tThe $i$th Jackknife Replicate is defined as the value of the estimator $s(\\cdot)$ evaluated at the $i$th Jackknife sample.\n\t\n\tAs we will prove it further below, the jacknife standard error of the estimator is (given typically by the bootstrap package of R as you can see it in the companion book):\n\t\n\twhere $\\hat{\\theta}_{(\\cdot)}$ is the empirical average of the Jackknife replicates:\n\t\n\tFor the proof let us consider the special case where the the Jackknife estimator above is an unbiased estimator of the variance of the sample mean.\n\t\\begin{dem}\n\tSo to prove the previous relation with the sample mean with just need to prove that (\\SeeChapter{see section Statistics}):\n\t\n\tTo prove this we write craftily:\n   \n   Once the term is squared, the equation is complete, and is identically equal to the right hand term above. Thus, in the case of the sample mean, the Jackknife estimate of the standard error reduces to the regular, unbiased estimator commonly used.\\\\\n   \n   \tWe say sometimes then that $n-1$ is the \"\\NewTerm{standard error jacknife bias inflation factor}\\index{standard error jacknife bias inflation factor}\".\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\tAs practical business oriented example of the use of Jackknife let me give the example of a customer (Fortune 500 company) that has to analyze worldwide counterfeiting of its products by sampling and controlling completely each year a given area of a given city chosen randomly in various countries and calculating the sum by country of counterfact products as it has a major influence on the strategy of the company, national politics and borders controls (the counterfacting being manly done by the mafia). As the geographical sampling error cannot be calculated as it is not guarantee that the chosen city has the same heterogeneity overall cities of the country it is as far as we know impossible to calculate with a closed form equation a tolerance interval for the real total counterfact. So an easy way to get a tolerance interval is to make a Jackknife resampling as it is easily acceptable for the board committee to make an analysis of what will have be the sum if for example we remove $50\\%$ of the sampling (at the condition that the a posteriori power of the test is still big enough!).\n\t\n\t\\pagebreak\n\t\\subsection{Finite difference method (F.D.M.)}\n\tThe finite element method (FEM) is a numerical technique for finding approximate solutions to boundary value problems for partial differential equations. It is also referred to as finite element analysis (FEA). FEM subdivides a large problem into smaller, simpler, parts, named \"finite elements\". The simple equations that model these finite elements are then assembled into a larger system of equations that models the entire problem. FEM then uses variational methods from the calculus of variations to approximate a solution by minimizing an associated error function.\n\t\n\t\\subsubsection{One space dimension F.D.M.}\n\tLet us recall that we have proved in the section of Thermodynamics the following heat diffusion equation (we present here the equation reduced to only one spatial dimension):\n\t\n\tand let us notice that this equation is not very general ... (it is not relativistic and does not take into account the heat generated in the form of radiation by the concerned material concerned or many other factors ...).\n\n\tWe can consider (\\SeeChapter{see section Differential and Integral Calculus}) that:\n\t\n\tand:\n\t\n\tAlso:\n\t\n\tThen the heat equation becomes:\n\t\n\tAfter rearranging, we have\n\t\n\tIf we look at this relation more closely, we see that this is a simple recursion. We just need to know the initial distribution (initial conditions) $T(x,0)$ to determine the distribution then all other values as:\n\t\n\tand:\n\t\n\tetc.\n\tIt is possible to implement such a simulation with nothing but a small spreadsheet software and a little time as we will we see just after... (using a spreadhseet software to understand the mechanism is better than using a blackbox like Maple or MATLAB by my experience).\n\n\tFor information $h$ and $k$ are named then the \"\\NewTerm{mesh step}\\index{mesh step}\" or \"\\NewTerm{space step}\\index{space step}\" of the model.\n\t\n\tLet us see an application example with a spreadsheet software like Microsoft Excel as it is quite a good practical exercise to understand how to implement the method.\n\t\n\tSo let us consider the following worksheet\\footnote{source: \\url{http://excelcalculations.blogspot.co.at/2011/04/solving-1d-heat-equation-using-finite.html}} where we consider a bar that is initially at a temperature of $0$ [C]and that is heated on the left-hand side at a constant temperature of $100$ [C] and where we use the relation proved earlier above:\n\t\n\tSo this gives (first rows only of $1,000$ rows): \n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.62]{img/computing/heat_equation_1d_excel_calculations.jpg}\n\t\t\\caption{1D Heat Equation FDM calculations in Microsoft Excel 14.0.7172}\n\t\\end{figure}\n\tExplicitly fr only a few rows a and few columns:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.42]{img/computing/heat_equation_1d_excel_formulas.jpg}\n\t\t\\caption{1D Heat Equation FDM explicit formulas in Microsoft Excel 14.0.7172}\n\t\\end{figure}\n\tWe have above taken for boundary conditions:\n\t \n\t\n\tAll this with a chart view (famous figure that is painful to obtain in a spreadhseet software...):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.7]{img/computing/heat_equation_1d_excel_plot.jpg}\n\t\t\\caption{1D Heat Equation FDM plot in Microsoft Excel 14.0.7172}\n\t\\end{figure}\n\t\n\n\tFor readers wishing to practice with real values ... a longitudinal Iron bar of $1$ [kg] has a specific heat capacity of $450\\;[\\text{J}\\cdot\\text{kg}^{-1}\\cdot\\text{K}^{-1}]$, an density of almost $7.88\\;[\\text{kg}\\cdot \\text{m}^{-3}]$ and a thermal conductivity of $82\\;[\\text{J}\\cdot\\text{s}^{-1}\\cdot\\text{m}^{-1}\\cdot\\text{K}^{-1}]$.\n\t\n\tHowever with such a file a above the reader will see that the FDM is stable   after some trials and errors if and only if:\n\t\n\tThis is what we will study now:\n\t\n\t\\paragraph{von Neuman stability}\\mbox{}\\\\\\\\\n\tIn numerical analysis, \"\\NewTerm{von Neumann stability analysis}\\index{von Neumann stability analysis}\" (also known as \"\\NewTerm{Fourier stability analysis}\\index{Fourier stability analysis}\") is a procedure used to check the stability of finite difference schemes as applied to linear partial differential equations. The analysis is based on the Fourier decomposition of numerical error and was developed at Los Alamos National Laboratory after having been briefly described in a 1947 article by British researchers Crank and Nicolson. This method is an example of explicit time integration where the function that defines governing equation is evaluated at the current time. Later, the method was given a more rigorous treatment in an article co-authored by John von Neumann.\n\t\n\tThe stability of numerical schemes is closely associated with numerical error. A finite difference scheme is stable if the errors made at one time step of the calculation do not cause the errors to be magnified as the computations are continued. A neutrally stable scheme is one in which errors remain constant as the computations are carried forward. If the errors decay and eventually damp out, the numerical scheme is said to be stable. If, on the contrary, the errors grow with time the numerical scheme is said to be unstable. The stability of numerical schemes can be investigated by performing von Neumann stability analysis. For time-dependent problems, stability guarantees that the numerical method produces a bounded solution whenever the solution of the exact differential equation is bounded. Stability, in general, can be difficult to investigate, especially when the equation under consideration is nonlinear.\n\t \n\tThe von Neumann method is based on the decomposition of the errors into Fourier series. To illustrate the procedure, consider the one-dimensional heat equation:\n\t\n\tdefined on the spatial interval $L$, which can be discretized as we have just proved as (in a very condensed form):\n\t\n\twhere as we have just proved earlier:\n\t\n\tand the solution $T_j^n$ of the discrete equation approximates the analytical solution $T(x,t)$ of the PDE on the grid.\n\t\n\tLet us define the round-off error $\\varepsilon_j^n$ as:\n\t\n\twhere $T_j^n$ is the solution of the discretized PDE as we knot it that would be computed in the absence of round-off error, and $N_j^n$ is the numerical solution obtained in finite precision arithmetic. Since the exact solution $T_j^n$ must satisfy the discretized PDE exactly, the error $\\varepsilon_j^n$ must also satisfy the discretized equation (superposition principle). Here we assumed that $N_j^n$ satisfies the PDE, too (this is only true in machine precision). Thus:\n\t\n\tis a recurrence relation for the error. \n\n\tEquations:\n\t\n\tshow that both the error and the numerical solution have the same growth or decay behavior with respect to time. For linear differential equations with periodic boundary condition, the spatial variation of error may be expanded in a finite Fourier series, in the interval $L$, as:\n\tAs we have proved it in the section Thermodynamics the solution of the PDE for the errors can be written in a condensed way for a given teim:\n\t\n\tSince the difference equation for error is linear (the behavior of each term of the series is the same as series itself), it is enough to consider the growth of error of a typical term:\n\t\n\tand as the reader will see with the next development we can simplify already the constant such that it remains:\n\t\n\tThe stability characteristics can be studied using just this form for the error with no loss in generality. To find out how error varies in steps of time, substitute the relation above into:\n\t\n\tafter noting that:\n\t\n\tto yield (after simplification):\n\t\n\tUsing the identities (\\SeeChapter{see section Trigonometry}):\n\t\n\tThen the prior previous relation can the be written as:\n\t\n\tLet us now define the amplification factor:\n\t\n\tThe necessary and sufficient condition for the error to remain bounded is that $|G|<1$. However in our case:\n\t\n\tthis is the explicit condition for stability of the numerical scheme.\n\t\n\tNote that the term:\n\t\n\tis always positive. Thus, to satisfy the prior previous relation we have:\n\t\n\tFor the above condition to hold at all:\n\t\n\twe have:\n\t\n\tgives the stability requirement for the FTCS scheme as applied to one-dimensional heat equation. This is exactly the value we found when playing with the Microsoft Excel worksheet.\n\t\n\t\\subsubsection{Space-time F.D.M (finite-volume method)}\n\tThe finite-volume method (FVM) is a method for representing and evaluating partial differential equations in the form of algebraic equations]. Similar to the finite difference method or finite element method, values are calculated at discrete places on a meshed geometry. \n\t\n\t\"Finite volume\" refers to the small volume surrounding each node point on a mesh. In the finite volume method, volume integrals in a partial differential equation that contain a divergence term are converted to surface integrals, using the divergence theorem. These terms are then evaluated as fluxes at the surfaces of each finite volume. Because the flux entering a given volume is identical to that leaving the adjacent volume, these methods are conservative. Another advantage of the finite volume method is that it is easily formulated to allow for unstructured meshes. The method is used in many computational fluid dynamics compouting packages as illustrated below:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.95]{img/computing/fdm_car.jpg}\n\t\t\\caption{Space-time FDM for car $C_x$ study}\n\t\\end{figure}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/fdm_airplane_wing.jpg}\n\t\t\\caption{Space-time FDM for airplane wing profile study}\n\t\\end{figure}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/fdm_nasa_spaceshuttle_launch.jpg}\n\t\t\\caption{Space-time FDM for NASA space shuttle launch (source: NASA)}\n\t\\end{figure}\n\tThe F.D.M. is a therefore a veeeeery important numerical method in practice because it also gives the possibility to solves directly Maxwell's equations in the time domain and space (and also General Relativity situations). It is then the classified in the $3$D (three-dimensional quantification of space) and temporal computational methods and finds its main industrial applications in the fields of design (antennas and circuits), of electromagnetic compatibility, of the diffraction and of the propagation and electromagnetic dosimetry (living beings and waves interactions).\n\t\n\tWe will discuss now the basics of the concept in a special cas as in practice, programming the F.D.M. is a whole team job in itself (like the rest of this book obviously but sometimes it is useful to recall that). Indeed a loot of problems must be resolved when dealing with computer programs using F.D.M. (convergence criteria, meshing methods, boundary conditions, user input, programming language methods, etc.).\n\n\tIn a electrodynamics problem treated by F.D.M., the first necessary step is to define the volume $V$ of the space and the time interval $I = [0, T]$ for which the resolution is desired (it is unrealistic at this day to hope to solve Maxwell's equations for an infinite space and for an unlimited period of time!). The volume of calculation contains the object (antenna circuit, ...) that it is desired to characterize, in response to a given excitation. Secondly, the space (meshing of $V$) and time should be discretized to allow a numerical implementation of the resolution (and in reality the meshing is not uniform...). The problem then becomes the one of determining the field at any point of the the mesh for any discrete moment of the observation time interval. The spatial and temporal discretization will be specified in what will follow below and will naturally come from physics equations to solve. They obviously condition both the accuracy of the calculation results and the computing resources required to carry it out.\n\n\tThe structuring of the F.D.M. mesh and the resolution method directly result of the equations to solve.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.9]{img/computing/fdm_mesh_01.jpg}\n\t\t\\caption{Airplane typical FDM meshing}\n\t\\end{figure}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/fdm_mesh_02.jpg}\n\t\t\\caption{Mechanical element FDM meshing}\n\t\\end{figure}\n\tIn a linear, homogeneous, isotropic, non-dispersive and non-magnetic (...) material, the Maxwell equations will be written explicitly based on the third Maxwell's equation (\\SeeChapter{see section Electrodynamics}):\n\t\n\tEither explicitly with the negative sign put at the other side of the equality:\n\t\n\tAnd we will also use the fourth Maxwell equation without sources:\n\t\n\tThus explicitly and rearranged:\n\t\n\tThat is to say for summary:\n\tThat is to say for summary:\n\t\n\tIn what follows, we will only concerned with the first equation, the other leading to similar developments.\n\n\tTo allow a computer processing, the various derivatives present in the equation must be approximated numerically as we already know. To do this, we use the principle of centered finite difference which is based on the following Taylor series expansions for recall (\\SeeChapter{see section Sequences and Series}):\n\t\n\tWe then have on the basis of this principle:\n\t\n\tIf we neglect the terms of the second order, it comes by subtracting the two series:\n\t\n\twhere $\\varepsilon(\\mathrm{d}_x^2$ is an error or order $2$, neglected thereafter (we notice that this is the centering that, allowing compensation of second derivatives,minimizes the error in the approximation).\n\t\n\tApplying this principle to temporal and spatial derivatives of:\n\t\n\tit comes:\n\t\n\tor after rearrangement:\n\t\n\tThis relation shows that if we know the components $E_y,E_z$ of electric field at time $t$ and the component $B_x$ of the magnetic field at the earlier time $t-\\mathrm{d}_t/2$, it is possible to determine $B_x$ at the time $t+\\mathrm{d}_t/2$. Obviously the process is exactly the same for all other components and shows the same time lag. This result suggests using an iterative numerical solution, in which the electric and magnetic fields are evaluated alternately, respectively at the discrete time $n\\mathrm{d}_t$ and $(n+1/2)\\mathrm{d}_t$, $\\mathrm{d}_t$ being the time step (denoted $\\Delta t$ by the computer scientists). It is customary in the literature to denote by $B_x^{n+\\dfrac{1}{2}}$ the component of the magnetic field at the time $(n+1/2)\\mathrm{d}_t)$.\n\t\n\tThe same analysis applies for the spatial distribution of the field on the observed points. Thus, evaluating $B_x$ at the point $(x,y,z)$ is based on the knowledge of $E_y$ at the points $(x,y,z+\\mathrm{d}_z/2)$ and $(x,y,z-\\mathrm{d}_z/2)$  and of $E_z$ at the points $(x,y+\\mathrm{d}_y/2,z)$ and $(x,y-\\mathrm{d}_y/2,z)$.\n\n\tSo we can summarize this geometrically in the following figure named \"\\NewTerm{Yee cell}\\index{Yee cell}\":\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/yee_cell_generic.jpg}\n\t\t\\caption{Generic Yee cell in parallelepiped mesh element}\n\t\\end{figure}\n\tThe electric field components are evaluted at the centers of the edges of the mesh and the components of the magnetic field at the centers of the faces so as to ensure the alternation imposed by the equations (as mentioned previously we name \"Yee cell\" the unit cell with this distribution of points).\n\t\n\tIn the special case of a propagating electromagnetic wave, the $\\vec{E}$ and $\\vec{B}$ fields are always perpendicular (\\SeeChapter{see section Electrodynamics}) in a homogeneous, linear, anisotropic medium (this type of media includes many things like air, water, glass without stress or tempering) and when the engineers prefers to represent the \"real\" magnetic field $\\vec{H}$ instead of the magnetic excitation $\\vec{H}$ we can found in the literature the following parallelepiped Yee cell figure:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/yee_cell_special.jpg}\n\t\t\\caption{Yee cell in parallelepiped mesh element for EM wave propagating in vacuum}\n\t\\end{figure}\n\tSo globally in vacuum without the presence of any object we have a meshing of the space that can be represented as follows:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/yee_cell_meshing.jpg}\n\t\t\\caption{Typical simple meshing with multiple Yee cells}\n\t\\end{figure}\n\tObviously, we can perform the calculation routines with a value of the permittivity and permeability that are not necessarily equal in all the cells. Allowing in addition to model the propagation of electromagnetic waves in heterogeneous and non isotropic media.\n\t\n\tFinally, it is important to notice that the spatial and temporal mesh step must be configured by the user running such simulations. This for computing resources reasons as well as accuracy goals. Indeed, we do not do the same simulations for  a multiphysics system in the low frequency in  vacuum than for non-isotropic material at high frequency and, either on a desktop computer or on a supercomputer.\n\t\n\t\\pagebreak\n\t\\subsection{Data Mining}\n\tData Mining, also popularly referred to as \"knowledge discovery from data (KDD)\"  or \"statistical learning\", is just a term to group a family of techniques whose first levels of granularity are given by (we will come back on a more precise definition further below):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.7]{img/computing/data_mining_orgchart.jpg}\n\t\t\\caption{Data Mining exhaustive orgchart techniques}\n\t\\end{figure}\n\tDeeper level of granularity would give\\footnote{this list is strongly inspired by Wikipedia, SPSS, SAS, R, RapidMiner and Tanagra softwares options} (sorry it's quite long but \"data scientists\", managers and IT staff in my teachings ask me many times to have an exhaustive one-place list):\n\t\\begin{itemize}\n\t\t\\item \\textbf{Feature selection (FS)/Data reduction:}\n\t\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item Backword-logit\n\t\t\t\\item CFS filtering (Hall \\& Smith CFS)\n\t\t\t\\item FCBF filtering (Yiu \\& Liu fast correlation based filter)\n\t\t\t\\item Chi-2 feature ranking\n\t\t\t\\item Fisher filtering\n\t\t\t\\item Forward-logit\n\t\t\t\\item Battiti's MIFS feature filtering\n\t\t\t\\item MODTree (Multivalued Oblivious Dicision) filtering (Lallich \\& Rakotomalala MODTree)\n\t\t\t\\item Non-negative matrix factorization dimension reduction\n\t\t\t\\item ReliefF (Kira \\& Rendell)\n\t\t\t\\item Runs filtering\n\t\t\t\\item Stepdisc (Wilk's partial lambda)\n\t\t\t\\item Oracle Minimum Description Length (MDL)\n\t\t\t\\item PCA (Principal Component Analysis)\n\t\t\t\\item SVD (Principal Component Analysis)\n\t\t\t\\item Kernel PCA / SVD\n\t\t\t\\item Isomap\n\t\t\t\\item Locally linear embedding\n\t\t\t\\item Maximum variance unfolding\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\\end{multicols}\n\t\t\n\t\t\\item \\textbf{Statistical indicators:}\n\t\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item Mean (arithemtic, geometric, harmonic)\n\t\t\t\\item M-Estimators\n\t\t\t\\item Maximum, Mininum, Range\n\t\t\t\\item Median\n\t\t\t\\item Interquartile range\n\t\t\t\\item Mode\n\t\t\t\\item Variance, semi-variance, standard deviation (biased or unbiased)\n\t\t\t\\item Fluctuation interval\n\t\t\t\\item Skewness\n\t\t\t\\item Kurtosis\n\t\t\t\\item Pearson or Spearman correlation\n\t\t\t\\item $p$-value\n\t\t\t\\item $\\beta$ of a NHST (power of test)\n\t\t\t\\item Coefficient of variation\n\t\t\t\\item Effect size\n\t\t\t\\item Cohen's kappa\n\t\t\t\\item Yule coefficient\n\t\t\t\\item Gini impurity index\n\t\t\t\\item Intraclass correlation coefficient\n\t\t\t\\item Bangdiwala's B\n\t\t\t\\item Fleiss Kappa\n\t\t\t\\item Cramér'V ($\\phi_c$)\n\t\t\t\\item Tschuprow's T \n\t\t\t\\item Scott's $\\pi$\n\t\t\t\\item $\\phi$-coefficient (Matthews correlation coefficient)\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\\end{multicols}\n\t\t\n\t\t\\item \\textbf{Statistical tests\\footnote{some of these tests are proved in the section Statistics} (parametric and non-parametric):}\n\t\t\\begin{multicols}{3}\n\t\t\\begin{enumerate}\n\t\t\t\\item (Brown)-Mood's test\n\t\t\t\\item (Siegel)-Tukeys test\n\t\t\t\\item Adjacency test\n\t\t\t\\item Ajne's test\n\t\t\t\\item Anderson-Darling's adequation test\n\t\t\t\\item ANCOVA test\n\t\t\t\\item ANOVA/MANOVA tests (+Welch's ANOVA/Friedmann's ANOVA/Kruskal-Wallis ANOVA. Van der Waerden ANOVA)\n\t\t\t\\item Ansari-Bradley's test\n\t\t\t\\item Anscombe-Glynn test\n\t\t\t\\item Armitage–Hill's test\n\t\t\t\\item Bartlett-(Kendall) test for variances\n\t\t\t\\item Bartlett's test for sphericity\n\t\t\t\\item Binomial sign test\n\t\t\t\\item Binomial test \n\t\t\t\\item Bowker's test for symmetry\n\t\t\t\\item Box's test\n\t\t\t\\item Box's M test\n\t\t\t\\item Box–Pierce test\n\t\t\t\\item Breslow-Day test\n\t\t\t\\item Breusch-Pagan-Godfrey's test for homogeneity of variances\n\t\t\t\\item Brown–Forsythe's test\n\t\t\t\\item Chow's test\n\t\t\t\\item Clark-Evans' test\n\t\t\t\\item Cochran's C-test\n\t\t\t\\item Cochran's Q test\n\t\t\t\\item Cochran-Armitage's test\n\t\t\t\\item Cochran-Mantel-Haenszel's test\n\t\t\t\\item Conover's test\n\t\t\t\\item Correlation for categorical variables text\n\t\t\t\\item Cramer–von Mises' test\n\t\t\t\\item Craps' test\n\t\t\t\\item Cuzick's trend test\n\t\t\t\\item Davies–Quade's test\n\t\t\t\\item Dickey–Fuller's test \n\t\t\t\\item DIP test\n\t\t\t\\item Discriminant test \n\t\t\t\\item Dixon's test\n\t\t\t\\item Duckworth's test\n\t\t\t\\item Duncan's multiple comparison test\n\t\t\t\\item Dunn's test\n\t\t\t\\item Dunnett's test\n\t\t\t\\item Durbin-Watson test\n\t\t\t\\item Epstein's test\n\t\t\t\\item Fieller's test (A/B Test)\n\t\t\t\\item Fisher's Exact test\n\t\t\t\\item Fisher's periodicity test\n\t\t\t\\item Fisher's variance test\n\t\t\t\\item Fisher's cumulant test\n\t\t\t\\item Fligner(-Killeen)'s test for homogeneity of variances\n\t\t\t\\item Fligner–Wolfe's test\n\t\t\t\\item Flingner–Policello's test\n\t\t\t\\item Freeman–Tukey's test\n\t\t\t\\item Friedman correlation test\n\t\t\t\\item G test\n\t\t\t\\item Gabriel's pairwise test\n\t\t\t\\item Gehan's generalized Wilcoxon test\n\t\t\t\\item Glejser's test\n\t\t\t\\item Goldfield–Quandt's test but white's test preferred\n\t\t\t\\item Goodman-Kruskal's Gamma test\n\t\t\t\\item Goodman-Kruskal's Lambda test\n\t\t\t\\item Goodman-Kruskal's tau test\n\t\t\t\\item Grubbs' test\n\t\t\t\\item Harrington and Fleming's Gp tests\n\t\t\t\\item Hartley's test\n\t\t\t\\item Haugh's test\n\t\t\t\\item Hettmansperger–McKean test\n\t\t\t\\item Hochberg's GT2 pairwise test\n\t\t\t\\item Hoeffding test\n\t\t\t\\item Hollander test:\n\t\t\t\\item Hosmer–Lemeshow test\n\t\t\t\\item Hotelling's T2-test \n\t\t\t\\item Hsu's MCB test\n\t\t\t\\item Jarque-Bera Normality Test\n\t\t\t\\item Jonckheere-Terpstra test\n\t\t\t\\item Jonckheere's k-sample test\n\t\t\t\\item Kaiser-Meyer-Olkin test\n\t\t\t\\item Kendall rank correlation test\n\t\t\t\\item Kendall's Tau-b\n\t\t\t\\item Kendall's Tau-c\n\t\t\t\\item Kendall's concordance W\n\t\t\t\\item Kendall's tau\n\t\t\t\\item Kenward-Roger tests\n\t\t\t\\item Khi-2 test for adquation\n\t\t\t\\item Khi-2 test for indendance with/without Yates correction\n\t\t\t\\item Klotz scale test\n\t\t\t\\item Knox's tests\n\t\t\t\\item Kolmogorov-Smirnov test\n\t\t\t\\item Kuiper's test\n\t\t\t\\item Lepage test\n\t\t\t\\item Levene's test\n\t\t\t\\item Likelihood ratio test\n\t\t\t\\item Lim–Wolfe test\n\t\t\t\\item Link–Wallace test\n\t\t\t\\item Log-rank test\n\t\t\t\\item Mack–Wolfe's test\n\t\t\t\\item Mann-Withney's test\n\t\t\t\\item Mardia–Watson–Wheeler's test\n\t\t\t\\item Mathisen's test\n\t\t\t\\item Mauchly's test\n\t\t\t\\item McCabe–Tremayne's test\n\t\t\t\\item McNemar's test\n\t\t\t\\item Median test\n\t\t\t\\item Michael's test\n\t\t\t\\item Mood's runs test\n\t\t\t\\item Mood's scale test\n\t\t\t\\item Mojena's test\n\t\t\t\\item Moses test\n\t\t\t\\item Newman–Keuls test (contreversé, non-parametric)\n\t\t\t\\item O'Brien's test\n\t\t\t\\item O'Brien's two-sample tests\n\t\t\t\\item Orthogonal t-test \n\t\t\t\\item Page's test\n\t\t\t\\item Partial correlation test\n\t\t\t\\item Pearson correlation test\n\t\t\t\\item Partial Theil U\n\t\t\t\\item Poisson test\n\t\t\t\\item Potthoff and Whitlinghill's test\n\t\t\t\\item Potthoff test\n\t\t\t\\item P-test\n\t\t\t\\item Rayleigh's test\n\t\t\t\\item Rosenbaum's test\n\t\t\t\\item Rosner Outlier test\n\t\t\t\\item Royston's test\n\t\t\t\\item Runs test\n\t\t\t\\item Savage's test\n\t\t\t\\item Scheffe 's test\n\t\t\t\\item Schuster's test\n\t\t\t\\item Semi-partial correlation test\n\t\t\t\\item Sequential test\n\t\t\t\\item Serial correlation test\n\t\t\t\\item Shapiro-Wilk adequation test \n\t\t\t\\item Sommer's d \n\t\t\t\\item Steel test\n\t\t\t\\item Stuart–Maxwell test\n\t\t\t\\item Tarone's test\n\t\t\t\\item The w/s-test\n\t\t\t\\item Theil's test\n\t\t\t\\item Triples test\n\t\t\t\\item T-test for coefficient slope\n\t\t\t\\item T-test (heteroscedastic or homoscedastic version)\n\t\t\t\\item Tukey's quick test\n\t\t\t\\item Tukey's test for nonadditivity\n\t\t\t\\item Turning point test\n\t\t\t\\item Unit root test\n\t\t\t\\item V-test (modified Rayleigh)\n\t\t\t\\item Waerden Normal-Scores test\n\t\t\t\\item Wald Chi-square test\n\t\t\t\\item Wald–Wolfowitz test\n\t\t\t\\item Walker's test\n\t\t\t\\item Watson's A-test\n\t\t\t\\item Watson's U2-test\n\t\t\t\\item Watson–Williams test\n\t\t\t\\item Wei–Lachin test\n\t\t\t\\item WE-test\n\t\t\t\\item White test  for homogeneity of variances \n\t\t\t\\item Wilcoxon's rank sum test\n\t\t\t\\item Wilcoxon's signed rank test\n\t\t\t\\item Wilk's multivariate outlier test\n\t\t\t\\item Z-test\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\\end{multicols}\n\t\t\n\t\t\\item \\textbf{Regression techniques\\footnote{\\SeeChapter{see section Theoretical Computing}}:}\n\t\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item Linear regression model (LSM)\n\t\t\t\\item Stepwise regression\n\t\t\t\\item Gaussian linear regression model\t\t\n\t\t\t\\item Nonlinear regression models with binary or continuous variables \n\t\t\t\\item Polynomial regression model \n\t\t\t\\item B-spline or of collocation polynomial regression\t\t\n\t\t\t\\item Logistic regression models\n\t\t\t\\item Counting Poisson regression (Poisson MLE, PMLE, GLM) \n\t\t\t\\item Negative binomial (binomial MLE and QGPMLE) regression model\t\t\n\t\t\t\\item Orthogonal linear regression model (or Deming regression)\t\t\n\t\t\t\\item Quantile regression model\t\n\t\t\t\\item Partial least squares regression (PLS)\n\t\t\t\\item LAD (Least Absolute Deviation) regression \t\t\n\t\t\t\\item LOESS (LOcal regrESSion) and LOWESS (locally weighted scatterplot smoothing)\t\t\n\t\t\t\\item Multivariate adaptive regression splines (MARS)\t\t\n\t\t\t\\item Bayesian linear regression model\n\t\t\t\\item Logic regression\n\t\t\t\\item Ridge regression model \t\t\n\t\t\t\\item Bootstrap or Jacknife regression model\n\t\t\t\\item Backward elimination regressions\n\t\t\t\\item Forward entry regression\n\t\t\t\\item C-RT regression tree\n\t\t\t\\item DfBets\n\t\t\t\\item Epilon SVR (support vector regression)\n\t\t\t\\item Nu SVR\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\\end{multicols}\n\t\t\n\t\t\\item \\textbf{Factorial analysis (AF):}\n\t\t\\begin{enumerate}\n\t\t\t\\item AFDM (Mixed data  factorial analysis)\n\t\t\t\\item Bootstrap eigenvalues\n\t\t\t\\item Linear discriminant analysis (canonical LDA)\n\t\t\t\\item Correspondance analysis\n\t\t\t\\item Discriminant correspondance analysis\n\t\t\t\\item Principal Component Analysis with/without Factor rotation (VariMax)\n\t\t\t\\item Harris component analysis\n\t\t\t\\item Multiple correspondence analysis\n\t\t\t\\item NIPALS (Nonlinear Iterative Partial Least Squares)\n\t\t\t\\item Parallel analysis\n\t\t\t\\item Principal factor analysis\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\n\t\t\\item \\textbf{Clustering (unsupervised):}\n\t\t\\begin{enumerate}\n\t\t\t\\item CatVARCHA (categorical variable hierarchical agglomerative clustering)\n\t\t\t\\item Clustering Tree (CT) with/without post-prunning\n\t\t\t\\item Fuzzy clustering tree\n\t\t\t\\item Kernel Density estimation\n\t\t\t\\item Kernel PCA (Principal Component Analysis)\n\t\t\t\\item Singular Value Decomposition (SVD)\n\t\t\t\\item EM-Clustering (Expectration-Maximization)\n\t\t\t\\item HAC (Hierarchical Agglomerative Clustering)\n\t\t\t\\item $K$-Means, $K$-Medians or $K$-Medoids clustering, Fuzzy clustering\n\t\t\t\\item Mean shift clustering\n\t\t\t\\item Spectral clustering\n\t\t\t\\item Multidimensional scaling\n\t\t\t\\item Kohonen-SOM (Self Organization Map)\n\t\t\t\\item Kohonen-LVQ (Learning Vector Quantizer)\n\t\t\t\\item VARCLUS (top down approach)\n\t\t\t\\item VARHCA (clustering variables using Hierarchical Cluster Analysis)\n\t\t\t\\item VARKMeans (clustering variable using $K$-Means)\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\n\t\t\\item \\textbf{Supervised (Spv) Learning:}\n\t\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item Binary logistic regression\n\t\t\t\\item BVM (Ball Vector Machine)\n\t\t\t\\item C4.5 (Quinlan algorithm)\n\t\t\t\\item C-PLS (PLS for classification)\n\t\t\t\\item C-RT (Regression Tree for classification)\n\t\t\t\\item CS-CRT (Cost Sensitive Classification RT)\n\t\t\t\\item C-MC4 (M-Estimates based and Laplaced smoothed CS-CRT)\n\t\t\t\\item C-SVC (Continuous Supervised Classification)\n\t\t\t\\item CVM (Core Vector Machine)\n\t\t\t\\item Decision List (One-Rule, ZeroR, CN2)\n\t\t\t\\item ID3 (Quinla algorithm)\n\t\t\t\\item Gradient Boosting\n\t\t\t\\item Gaussian processes\n\t\t\t\\item K-NN (Nearest Neigbhors)\n\t\t\t\\item LDA (Linear Discriminant Analysis)\n\t\t\t\\item Log-Reg TRIRLS \n\t\t\t\\item Multilayer perceptron (MLP neural network)\n\t\t\t\\item Multinomial Logistric Regression\n\t\t\t\\item Naive bayes categorical variables classification\n\t\t\t\\item Naive bayes continuous variables classification\n\t\t\t\\item PLS-DA (PLS Discriminany Analysis)\n\t\t\t\\item PSL-LDS (PLS Linear DA)\n\t\t\t\\item Prototype-NN (Nearest Neighbors)\n\t\t\t\\item Radial basis function (RBF neural network)\n\t\t\t\\item Random Tree\n\t\t\t\\item Rule Induction, Fuzzy rule induction\n\t\t\t\\item Support Vector Machine\n\t\t\t\\item Genetic classification\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\\end{multicols}\n\t\t\n\t\t\\item \\textbf{Semi-Supervised learning:}\n\t\t\\begin{enumerate}\n\t\t\t\\item S3VM\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\\item \\textbf{Meta Supervised learning:}\n\t\t\\begin{enumerate}\n\t\t\t\\item Arcing (Arc-x4) bagging with weighted\n\t\t\t\\item Bagging with/without cost sensitivity\n\t\t\t\\item Boosting  with/without cost sensitivity\n\t\t\t\\item MultiCost sensitive supervised learning\n\t\t\t\\item Stacked generalization\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\\item \\textbf{\\text{Supervised learning assessment:}}\n\t\t\\begin{enumerate}\n\t\t\t\\item Bias-variance decomposition (Wolpert \\& Kohavi)\n\t\t\t\\item Bootstrap\n\t\t\t\\item Cross-validation\n\t\t\t\\item Leave-One-Out\n\t\t\t\\item Test set assessment\n\t\t\t\\item Learning/Train assessment test\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\\item \\textbf{Scoring:}\n\t\t\\begin{enumerate}\n\t\t\t\\item Lift curve\n\t\t\t\\item ROC curve\n\t\t\t\\item Precision-Recall curve\n\t\t\t\\item Reliability diagram\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\\item \\textbf{Association:}\n\t\t\\begin{enumerate}\n\t\t\t\\item A priori (MR version or not)\n\t\t\t\\item A prior PT (Borgelt's algorithm)\n\t\t\t\\item Assoc outlier (association rule mining principle)\n\t\t\t\\item Frequent itemsets (Borgelt's algorithm)\n\t\t\t\\item ECLAT (equivalence class transformation algorithm)\n\t\t\t\\item FP-growth (frequent pattern growth)\n\t\t\t\\item RElim (recursive elimination)\n\t\t\t\\item SaM (Split and Merge)\n\t\t\t\\item JIM (Jaccard Itemset Mining)\n\t\t\t\\item Spv association rule \n\t\t\t\\item Spv association tree\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\\item \\textbf{Anomaly detection:}\n\t\t\\begin{enumerate}\n\t\t\t\\item Cochran C test\n\t\t\t\\item Dixon's test\n\t\t\t\\item Control Charts\\footnote{see section Industrial Engineering for the details on control charts} (P, NP, C, U, R-R, X-R, etc.)\n\t\t\t\\item Markov modulated Poisson process\n(MMPP)\n\t\t\t\\item Local outlier factor (LOF)\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\\item \\textbf{Reinforcement learning:}\n\t\t\\begin{enumerate}\n\t\t\t\\item Markov Decisions Processes\n\t\t\t\\item Case-Based Reasoning \n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\\item \\textbf{Forecastings:}\n\t\t\\begin{enumerate}\n\t\t\t\\item Linear and polynomial regressions (see above)\n\t\t\t\\item Moving Average\n\t\t\t\\item Simple exponential smoothing\n\t\t\t\\item Double exponential smoothing (Brown)\n\t\t\t\\item Triple exponential smoothing (Holt \\& Winters)\n\t\t\t\\item Logistic forecasts\n\t\t\t\\item ARIMA processes (AR, ARMA, ARIMA, ARFIMA)\n\t\t\t\\item GARCH processes\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\\item \\textbf{Sequence mining:}\n\t\t\\begin{enumerate}\n\t\t\t\\item GSP (Generalized Sequential Patterns)\n\t\t\t\\item SPADE (Sequential Pattern Discovery)\n\t\t\t\\item FreeSpan\n\t\t\t\\item HMM (hidden Markov models)\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\t\\item \\textbf{Deep learning:}\n\t\t\\begin{enumerate}\n\t\t\t\\item Deep Boltzman Machine (DBM)\n\t\t\t\\item Deep Belief Networks (DBN)\n\t\t\t\\item Convolutional Neural Networks (CNN)\n\t\t\t\\item Fuzzy neural network (FNN)\n\t\t\t\\item Stacked Auto-Encoders\n\t\t\t\\item ...\n\t\t\\end{enumerate}\n\t\\end{itemize}\n\tThis was the scientist point of view of Data Mining... From the point of view of business Data Mining is more considered as the following data life cycle:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.7]{img/computing/data_mining_life_cycle.jpg}\n\t\t\\caption{Data Mining life cycle as seen by SAS™ (source: SlideShare SAS)}\n\t\\end{figure}\n\tad also let us introduce the 4V's of Data Mining/Machine Learning that resume quite well the most common cases of data to which the Data Scientist is faces to:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.9]{img/computing/four_v_data_mining.jpg}\n\t\t\\caption{Data Mining/Machine Learning 4V's (source: ?, author: ?)}\n\t\\end{figure}\n\tOK! This done let us now begin first with the basics of clustering methods! \n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\\textbf{R1.} The data scientist must take care of not becoming a \"Data Pusher\" and not to do just \"infotainement\" (almost no-sense statistics) in order to remain employed. This is ethically non-scientific and as the reader of this book already knows it, as going at the opposite of the Archimedes Oath!\\\\\n\t\n\t\\textbf{R2.} Corporations and Managers have to understand that a data steward cannot be a data analyst that cannot be a data scientist that is also most of time not a statistician. Think the opposite show an evident lack of technical and scientific knowledge especially when the data scientist is supposed alone to install Big Data Servers, clean data, develop new mathematical models, do programming for implementing the models and put them in production.\\\\\n\t\n\t\\textbf{R3.} Data is not a currency, most data is garbage. Actionable information is currency. Extracting information form modern big data sets requires the equivalent processing infrastructure and time of extracting a nugget of gold from a mountain of dirt.\n\t\\end{tcolorbox}\n\t\n\t\\subsubsection{Clustering}\n\tIn statistical data analysis, \"clustering\" describes empirical methods of data classification (hierarchical clustering method or data partitioning method).\n\n\tThese techniques typically enable the segmentation of all customers of a company based on their demography or buying patterns, to group documents for presentations, identify new animal or plant species, to group information by individuals or by interests.\n\n\tWe see in practice two major families of clustering techniques (careful even experts in the field are unable to agree on a common classification ...!):\n\t\\begin{enumerate}\n\t\t\\item The \"\\NewTerm{Non-hierarchical techniques}\\index{Non-hierarchical techniques}\": that is to say where the number of classes (groups) final is chosen in advance.\n\n\t\t\\item The \"\\NewTerm{hierarchical techniques}\\index{hierarchical techniques}\": that is to say where it leads to a classification by successive aggregations.\n\t\\end{enumerate}\n\tAmong these two families we distinguish two sub-families (this is the definition for THIS book - and that correspond almost to that of the SAS company - as they are no common accepted definition until now between specialists working in this field):\n\t\\begin{enumerate}\n\t\t\\item The techniques that make use of data whose nominal classification property is known in advance to train a prediction model: \"\\NewTerm{machine learning\\footnote{Oxford Dictionary definition: The capacity of a computer to learn from experience, i.e. to modify its processing on the basis of newly acquired information.}\\index{machine learning}}\" or \"\\NewTerm{supervised learning}\\index{supervised learning}\". We find in this category the binary logistic regression techniques, CRT, ID3, discriminant analysis, Bayesian networks, decision lists, k-NN, neural networks, etc. \n\n\t\tAs there are not today a consensus in the definitions, it is important that the reader also knows that \"supervised\" algorithms by are algorithms that have a correction mechanism of the model parameters based on generated errors.\n\t\n\t\t\\item The techniques that make use of data whose no nominal classification is known in advance to suggest a classification and seek a possible classification (which at the business level is often more interesting): \"\\NewTerm{data mining\\footnote{Oxford Dictionary definition: The practice of examining large pre-existing databases in order to generate new information.}\\index{data mining}}\" or \"\\NewTerm{unsupervised learning (self guided algorithm)\\index{unsupervised learning}}\" or more rarely \"\\NewTerm{data mining}\\index{data mining}\". We find in this category the, HAC, k-mean, kohonen maps, $K$-means, etc.\n\t\\end{enumerate}\n\tThese both families  quite well summarised by the followinf figure:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/supervised_vs_unsupervised_learning.jpg}\n\t\t\\caption{Supervised vs Unsupervised learning idea}\n\t\\end{figure}\n\tare themselves divided into two sub-families: kernel-based or non-kernel based... (that means for the latter we don't need to make any assumption on the statistical distribution shape of the variable of interest).\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.48]{img/computing/data_mining_vs_machine_learning_following_sas.jpg}\n\t\t\\caption{Data Mining as seen by SAS™ (source: SlideShare SAS)}\n\t\\end{figure}\n\tThe distinction between machine learning and data mining has become more and more blurred, and there is a great deal of \"cross-fertilization\".\n\t\n\tThe industrial or operational use of this knowledge in the professional world can solve very different problems, ranging from customer relationship management to preventive maintenance, through fraud detection and the optimization of websites, the supervision of financial markets, pro-active prospecting (customer consumption preferences), optimization of paths (analysis of road caps and left turns), or target selection (probability of acquiring a new given prospects) anticipate the identification of terrorists, pricing of products in comparison to equivalent one on the mark, etc.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tBe careful to not to confuse strictly speaking we the concepts of classification, segmentation and association. Although the first two are often confused (classification / segmentation) because many algorithms do both at once, classification is the prediction of one or more discrete variables based on the value of other fields in the data set as the segmentation divides the data into groups of items having the most identical properties as possible. About association it is clear that many segmentation algorithms shows what is associated with what but the idea strictly speaking of association is to quantified by a scalar the degree of association between two data sets.\n\t\\end{tcolorbox}\t\n\tWe will see here some trivial techniques that we will complete with time ...\n\t\n\t\\pagebreak\n\t\\subsubsection{Regression and classification trees}\n\tRegression and classification trees (CART: Classification and Regression Tree) are a set of heuristic algorithms widely used in advanced marketing or social science to discriminate (categorize) a very large population. Obviously, these algorithms (that are part of hierarchical techniques) will never do better than a human being (at least in this first decade of the 21st century)... but also ask an employee to create groups in a population of 5 million customers on the basis of ten explanatory variables. You will have to wait for the response a quite long time...\n\t\n\tWhile these automated  classification techniques are very useful in the above situations, they nevertheless have a major problem that makes we will not focus too much on this subject:\n\t\\begin{itemize}\n\t\t\\item These techniques are very sensitive to the analyzed population and give very different results.\n\n\t\t\\item The various existing  techniques of classifications give results that are completely different for the same population.\n\t\\end{itemize}\n\tIt is better to be cautious about the conclusions that we can draw from these models and compare the results of several methods depending on the return on experience choose the one that seems the best suited.\n\n\tFor companion example, let us consider a set of categorical variables $x_1,\\ldots,x_p$. The recursive partitioning has for purpose to divide the $p$ variables of the space into rectangles which do not overlap.\n\t\n\tFor example, consider the variable $x_i$ and a value $s_i$ of this variable, we find that the partitioning $x_i<s_i$ and $s_i<x_i$separates well the data into two disjoint sets. Then one of the parts is in turn divided by a value $x_i$ or by the value of another variable. We end then with three rectangles and so on...\n\t\n\tThe idea is to create $n$ rectangles such that all data contained in a rectangle are homogeneous (that is to say contains only one family of points).\n\n\tTo address this issue, consider the following practical case:\n\t\n\tA dealer would like for his city to find a way to classify the families that are able to buy a car (owners) and those that are not ready to buy a car (non-owners). A sample of $12$ owners (\"$1$\" in the figure below) and $12$ non-owners (\"$2$\" in the figure below) is selected. The two independent variables are $x_1$ (wage in kilo-dollars) and $x_2$ (area of their home).\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.9]{img/computing/cart_data_list_sample_excel.jpg}\n\t\t\\caption[]{Original data list of CART application with Microsoft Excel 14.0.7172}\n\t\\end{figure}\n\tWe see that we have as many owners than non-owners (assumed equal appearance frequency in the whole population). Therefore the probability of belonging to a class is $50\\%$.\n\n\tOr graphically:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/cart_data_list_sample_excel_chart_0_iteration.jpg}\n\t\t\\caption[]{Original  plot CART application with Microsoft Excel 14.0.7172}\n\t\\end{figure}\n\tIf we apply the CART algorithm on this data, we see that we must choose $x_2$ (Area) as the first choice of division with the division value of $19$ (we will justify why!). The space $(x_1,x_2)$ is now divided into two rectangles (it was easy to guess that discriminating step without even using mathematics):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/cart_data_list_sample_excel_chart_1_iteration.jpg}\n\t\t\\caption[]{First iteration of CART application with Microsoft Excel 14.0.7172}\n\t\\end{figure}\n\tNotice how the division into two rectangles created two zones (splits) which are more homogeneous than the original graph! The upper rectangle contains points which are more Owners while the lower rectangle contains more Non-owners.\n\n\tTo determine this division, the CART algorithm examined each variable and all possible values for each variable division in order to find the best division.\n\n\tThus, the possible points of division for $x_1$ are (notice that this is every time the average of the two related values in the table):\n\t\\begin{gather*}\n\t\tx_1:\\{38.1,45.3,50.1,\\ldots,109.5\\}\n\t\\end{gather*}\n\tand that for $x_2$ are:\n\t\\begin{gather*}\n\t\tx_2:\\{14.4,15.4,16.2,\\ldots,23\\}\n\t\\end{gather*}\n\tThese points are ordered by the algorithm according to the way they reduce \"impurity\" (heterogeneous of composition) in the rectangle that generates the \"split\".\n\n\tThere are a large number of empirical ways to measure the impurity. The most common so far is the use of an indicator inspired the Gini coefficient (\\SeeChapter{see section Quantitative Management Techniques}). Thus, if we denote the classes by $k=1,2,3,\\ldots,C$ where $C$ is the total number of classes to be predicted, the \"\\NewTerm{Gini impurity index}\\index{Gini impurity index}\" for the $A$ rectangle is defined by:\n\t\n\twhere $p_k$ is the fraction of observation in the rectangle $A$ which belong to the class $k$. \n\n\tIn our example, we always have only two classes: Owners / Non- Owners.\n\n\tNext, the global Gini index is defined as the weighted average of the Gini indices.\n\n\tSo in our example, we have two classes, therefore $C=2$. Before the separation, we have:\n\t\n\tThe separation found in $19$ (see the second figure) gives for example for the top rectangle of the first subdivision:\n\t\n\tFor the inferior part:\n\t\n\tBy the hazard of the choice of this example, the impurity is the same for both rectangles (top and bottom).\n\n\tThe overall Gini index is then given by:\n\t\n\tNotice before continuing that if the subdivision is perfect (only have one family of points in one of the boxes), then we have:\n\t\n\tSo the impurity is zero ... And if all the points appear in equal proportions in each of the rectangles (worst situation we could say), the value is then:\n\t\n\tIf we generalize to $C$ classes ($C$ spatial dimensions), it comes immediately:\n\t\n\twhich is the maximum impurity.\n\n\tSo the impurity is always defined by a value in the range:\n\t\n\tNow, to continue with our example, even without using a computer algorithm, without even calculating the impurity, it is relatively easy to guess which will be the next discrimination: it will be $x_1=84.75$ (Income). Which will give:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/cart_data_list_sample_excel_chart_2_iteration.jpg}\n\t\t\\caption[]{Second iteration of CART application with Microsoft Excel 14.0.7172}\n\t\\end{figure}\n\tWhat was also easy to guess even without using the calculations (try your friends, you will see that very often they can found the first two discrimination).\n\n\tThe impurity will be calculated in the new discriminated area by:\n\t\n\tThe overall Gini index is given by:\n\t\n\tWe continue, but be aware that the result is less easy to guess. \n\n\tThe majority of individuals interviewed are wrong without using the mathematical definition of impurity and intuitively wrong to propose one or more of the following discrimination:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/cart_data_list_sample_excel_chart_3_iteration.jpg}\n\t\t\\caption[]{Third iteration of CART application with Microsoft Excel 14.0.7172}\n\t\\end{figure}\n\twith (you can do the math) a total impurity of $0.2727$. When in reality, the optimum discrimination is:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/cart_data_list_sample_excel_chart_3_iteration_real.jpg}\n\t\t\\caption[]{Third real iteration of CART application with Microsoft Excel 14.0.7172}\n\t\\end{figure}\n\twith a total impurity of $0.2592$. Indeed:\n\t\n\tThe overall Gini index is:\n\t\n\tIn the next step, we have:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/cart_data_list_sample_excel_chart_4_iteration.jpg}\n\t\t\\caption[]{Fourth iteration of CART application with Microsoft Excel 14.0.7172}\n\t\\end{figure}\n\tAt the next step:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/cart_data_list_sample_excel_chart_4_iteration.jpg}\n\t\t\\caption[]{Fifth iteration of CART application with Microsoft Excel 14.0.7172}\n\t\\end{figure}\n\tetc. until the end:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/cart_data_list_sample_excel_chart_final_iteration.jpg}\n\t\t\\caption[]{Final iteration of CART application with Microsoft Excel 14.0.7172}\n\t\\end{figure}\n\twhere each rectangle is pure (only contains data that one of the two classes).\n\n\tThe reason why the method is named \"Classification And Regression Tree\" algorithm is that each division can be represented as the division of a node into two successor nodes. The first division is shown as a branch of the tree root node. Here, for example are the first six iterations of the algorithm (only the first six one as the page size is to small to get them all):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/cart.jpg}\n\t\t\\caption{CART Final result in the traditional tree form}\n\t\\end{figure}\n\tIf you follow the detailed steps given in our R companion book you will see the corresponding result that is:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.9]{img/computing/cart_r.jpg}\n\t\t\\caption[]{CART Final result in the traditional tree form with R 3.0.2}\n\t\\end{figure}\n\tAnd if you follow the detailed steps given in our MATLAB™ companion book you will see the corresponding result that is:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.85]{img/computing/cart_matlab.jpg}\n\t\t\\caption[]{CART Final result in the traditional tree form with MATLAB™ 2013a}\n\t\\end{figure}\n\tAnd as mentioned above, we will stop here about our study of CART because the study of the corresponding empirical variations techniques are a full time job as they are numerous (and almost none gives the same results...).\n\t\n\t\n\t\\subsubsection{$K$-Means}\n\tThe $K$-means algorithm or \"mobile centers\" , also sometimes named \"classification method with dynamic clouds\" is in statistics and machine learning (specifically unsupervised learning), a data partitioning algorithm, ie a method that aims to divide observations in $K$ clusters in which each observation belongs to the partition with the nearest average.\n\n\tThe basic steps of the algorithm are as follows:\n\t\\begin{enumerate}\n\t\t\\item We choose a partitioning into $K$ groups\n\n\t\t\\item We generate $K$ averages (centers $c_i$) randomly\n\n\t\t\\item  The data are assigned to the group whose center is closest to them\n\n\t\t\\item We calculated the average of each group using the affected data\n\n\t\t\\item We return to step 3\n\t\\end{enumerate}\t\n\tSo our problem is the same as minimizing the enlarged criterion:\n\t\n\tover bother clusterings $C$ and $c_1,\\ldots,c_K\\in\\mathbb{R}^p$.\n\t\n\tThe $K$-means algorithm (which therefore belongs to non-hierarchical clustering techniques) however does not necessarily converge to an optimal solution. Let us recall that a global optimization calculation is inconsistent with the data volumes used, regardless of the power of computers. Thus, the $K$-means will use iterative algorithms to reach a local optimum. They will by trial and error minimize the variance-covariance matrices withingroups. It is also an algorithm that will try to find the best $K$ initial points.\n\n\tSome software gives you the ability to set the initial values and this will affect the final quality of the typology, knowing that there is ONE no good initial choice. This varies depending on the configuration of data, on the return of experience (REX) and even the chance...\n\t\n\tThere are three common solutions:\n\t\\begin{enumerate}\n\t\t\\item The software determines the $K$ initial points randomly. It can perform a number of tests and he will choose the most conclusive one.\n\n\t\t\\item We use the expert opinion that suppose someone has a fairly good knowledge of the study population for attaching to each class an ideal type. This may or not be a real individual.\n\n\t\t\\item The software distribute the $K$ initial points not randomly but according to some empirical algorithms.\n\t\\end{enumerate}\n\n\tRather than represent the algorithm with mathematical equations (what is quite nice but useless as the mathematical techniques are just a cumulation of what we already know), it seemed to more instructive to show how to implement this technique in a spreadsheet software like Microsoft Excel 14.0.6123 using again a companion example since experience shows that it is much more meaningful and effective to students (but computer scientists students really have to learn the maths to implement the algorithm!).\n\t\n\tFor this, we will first consider the following structure for which the idea is to establish three centers (so it is a $3$-means):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.74]{img/computing/kmeans_initial_sheet_values_and_chart_excel.jpg}\n\t\t\\caption[]{Basic starting $K$-means in Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\twhere we have on the left data from a population-based on the characteristics $X$ and $Y$ with a small table that will display the coordinates of the three centroid. We create on the same sheet the following table:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.74]{img/computing/kmeans_initial_sheet_point_cluster_association_excel.jpg}\n\t\t\\caption[]{Initial points-centroids $K$-means association in Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\twith trivial formulas for the three columns \\texttt{N}, \\texttt{O}, \\texttt{P}, where we used the standard Euclidean distance:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.5]{img/computing/kmeans_initial_sheet_point_cluster_association_excel_explicit_formulas.jpg}\n\t\t\\caption[]{Initial points-centroids $K$-means association explicit formulas in Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\tThen we launch the Microsoft Excel 14.0.6123 Solver  with the following parameters being careful to take the Evolutionary algorithm option. Therefore we assume that at every run we could have a different results:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/kmeans_solver_settings_excel.jpg}\n\t\t\\caption[]{$K$-means solver settings in Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\tand therefore we get for results:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.57]{img/computing/kmeans_final_sheet_point_cluster_association_excel.jpg}\n\t\t\\caption[]{$K$-means final associations in Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\tA software like Minitab 15.1.1 gives us other values for the centroid. As the latter don't give any plots let us see how the associations looks like if we write manually the centroid values given by Minitab in our Microsoft Excel sheet:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.55]{img/computing/kmeans_final_point_cluster_association_minitab.jpg}\n\t\t\\caption[]{$K$-means final associations with Minitab 15.1.1 values}\n\t\\end{figure}\n\tThe huge difference between Microsoft Excel and any other Statistical software is quite simple to explain! Software such as Microsoft Excel 14.0.6123 minimizes the distance points to the centers but is unable simultaneously to maximize the distance between the centers. Against the statistical software have algorithms implemented for this purpose.\n\t\n\tOther possible comparison... with Tanagra 1.4.44 we get:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/kmeans_final_point_cluster_association_tanagra.jpg}\n\t\t\\caption[]{$K$-means final associations in Tanagra 1.4.44}\n\t\\end{figure}\n\tAnd using the detailed steps given in our R companion book we get:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/kmeans_final_point_cluster_association_plot1_r.jpg}\n\t\\end{figure}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/kmeans_final_point_cluster_association_plot2_r.jpg}\n\t\\end{figure}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/kmeans_final_point_cluster_association_plot3_r.jpg}\n\t\t\\caption[]{$K$-means final associations in R 3.0.2}\n\t\\end{figure}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIn some application we want each center to boe one of the point itself. This is where \"\\NewTerm{$K$-medoids}\\index{$K$-medoids}\" (Partition around medoids) comes in an algorithm similar to the $K$-means algorithm, except when fitting the centers $c_1,\\ldots,c_K$, we restrict our attention to the point themselves. Generally $K$-medoids obvious return a higher value of $K_{\\text{means}}$. There is also on example in our R companion book.\n\t\\end{tcolorbox}\n\t\n\t\\subsubsection{Hierarchical Ascendant Classification (HAC) Dendrograms}\n\tA dendrogram (from Greek dendro \"tree\" and gramma \"drawing\") is a tree diagram frequently used to illustrate the arrangement of the clusters produced by hierarchical clustering. Dendrograms are often used in computational biology to illustrate the clustering of genes or samples, sometimes on top of heatmaps.\n\t\n\tTo introduce this clustering technique let us consider the following companion example based on the following list of data in Microsoft Excel:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/dendrogram_excel_list.jpg}\n\t\t\\caption[]{List of data for our study of dendrograms in Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\tWe wish to have a hierarchical organization of likeness of individuals based on their income and their living space. \n\n\tOne possible technique is to define for this measurement a distance of similarity. For example, the Euclidean distance:\n\t\n\tis an special choice that will associate two individuals whose distance is minimal. We speak then in the area of clustering \"\\NewTerm{simple link}\\index{simple link}\".\n\n\tSo we can easily using a spreadsheet software like Microsoft Excel 14.0.6123 create a \"\\NewTerm{distance matrix}\\index{distance matrix}\" which is a symmetric matrix with zero in diagonal and that relatively to the list given above will give:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.5]{img/computing/dendrogram_excel_distance_matrix.jpg}\n\t\t\\caption[]{Dendrograms distance matrix in Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\twhere we put in the cell D4 the following Euclidean distance formula:\n\t\\begin{center}\n\t\t\\texttt{=SQRT(($B4-D$2)\\string^2+($C4-D$3)\\string^2)}\n\t\\end{center}\n\twe then drag this formula for the rest of the matrix to the cell AA27 .\n\n\tThen we use the bottom-up method (agglomeration) where we combine the groups until there is only one group (containing all data) and this is a very boring work to describe and to do manually in spreadsheet software (we will put the detailed screenshot only if requested by readers).\n\n\tThis work will give us in a tabular form following the detailed steps given in our Minitab 15.1.1.0 companion book (values are not rounded to hundredths unlike the small matrix given in the figure above):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/dendrogram_minitab_summary_list.jpg}\n\t\t\\caption[]{Dendrograms distance summary list in Minitab 15.1.1.0}\n\t\\end{figure}\n\twhere the level of similarity of the linked group $i,j$ is defined empirically by:\n\t\n\tThus, for the first row we have for example:\n\t\n\tThe preceding list is more pleasant to analyze if, as is customary, we represent is a \"dendrogram\" ag given by Minitab 15.1.1.0 below:\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/dendrogram_minitab_plot.jpg}\n\t\t\\caption{Dendrograms plot in Minitab 15.1.1.0}\n\t\\end{figure}\n\tIf you follow the detailed steps given in our MATLAB™ 2013a companion book you will get:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/dendrogram_matlab_plot.jpg}\n\t\t\\caption{Dendrograms plot in MATLAB™ 2013a }\n\t\\end{figure}\n\tIf you follow the detailed steps given in our R companion book you will get:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/dendrogram_r_plot.jpg}\n\t\t\\caption{Dendrograms plot in R 3.0.2}\n\t\\end{figure}\n\tand still with R (see companion book) for the same data:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.85]{img/computing/dendrogram_r_plot_heatmap.jpg}\n\t\t\\caption{Dendrograms heatmap plot in R 3.0.2}\n\t\\end{figure}\n\tDendrograms and HAC are also used in biostatistics as show below (still with R but not described in the companion book yet):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.65]{img/computing/dendrogram_r_plot_heatmap_microarray.jpg}\n\t\t\\caption{Dendrograms heatmap microarray plot in R 3.0.2}\n\t\\end{figure}\n\tOr in finances to group similar times series (still with R and detailed steps given in the companion book):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.65]{img/computing/dendrogram_r_plot_tsa.jpg}\n\t\t\\caption{Dendrograms TSA microarray plot in R 3.0.2}\n\t\\end{figure}\n\t\n\t\\pagebreak\n\t\\subsubsection{Neural networks}\n\tNeural networks made from artificial cell structures are an approach for addressing from a new angle of perspective the problems of perception, memory, learning and nonlinear reasoning (in other words ... artificial intelligence, abbreviated \"IA\") as well as genetic algorithms (see further below). They have also proved to very promising alternatives to bypass some of the limitations of conventional numerical methods (see autodriven cars, autodriven airplanes, automatic trading systems). Thanks to their parallel processing of information and inspired mechanisms inspired of nerve cells (neurons), they infer emergent properties to solve problems once referred to be as highly complex. Sometimes they result of artificial neurons is so bluffy that even best engineers have difficulties to explain how the neural network could arrive to a given observed performance (an typical non-business well know example is the Google Deep-learning dreaming machine).\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{subfigure}{.5\\textwidth}\n\t\t  \\centering\n\t\t  \\includegraphics[width=0.9\\linewidth]{img/computing/dream_machine_google_original.jpg}\n\t\t\\end{subfigure}%\n\t\t\\begin{subfigure}{.5\\textwidth}\n\t\t  \\centering\n\t\t  \\includegraphics[width=0.9\\linewidth]{img/computing/dream_machine_google_result.jpg}\n\t\t\\end{subfigure}\n\t\t\\caption{Google Dream Machine test obtained the 2016-09-27 T20:42GMT (source: http://psychic-vr-lab.com/deepdream)}\n\t\\end{figure}\n\n\tHowever, the major problem of artificial neurons (as far as we know...) is that they are not able to self-organize, nor to self-structured intelligently by themselves, they can only change weights and change some layer parameters in a range given previously by a human. So you need at this date to proceed heuristically to find the best neural network structure adapted to a problem and this is their large current actual weakness (either using brute force via a database containing millions of models or genetic algorithms that we will see a bit further below).\n\t\n\tWe will discuss here the main architectures of neural networks. The purpose is not to study them all because they are too many of them (see figure on the next page), but rather to understand the basic internal mechanisms and how and when to use them with a minimal companion example with a common spreadsheet software. We will also discuss some concepts on fuzzy sets and logic (\\SeeChapter{see section Logical Systems}) in the idea that these later are incorporated into some neural network architectures that we will study.\n\t\n\tThe human brain is said ton contains about $100$ billion neurons. These neurons enable us among others to read a text while maintaining regular breathing to oxygenate our blood, activating our heart which ensures efficient circulation of the blood to nourish our cells, etc. After a very long learning path and trial and errors they also enable us to read books, innovate, create, copy concepts and gentle with other people of the same species (but the learning path doesn't work for all human being for all humans machine as some reject respect of life and of differences...).\n\t\\begin{figure}[H]\n\t\t\\centering\n\t  \t\\includegraphics[scale=0.39]{img/computing/neural_networks.jpg}\n\t\t\\caption{Neural Networks complete chart (source: http://www.asimovinstitute.org, author: Fjodor van Veen)}\n\t\\end{figure}\n\tEach of these neurons is also quit complex. Essentially, it is living tissue and chemistry and application of physics law (as the rest of our body). Neuro-physicists are just beginning to understand some of their internal mechanisms and are also able to influence them since a few decades. We usually think that their different neuronal functions, including memory is stored at the connections (synapses) between neurons. It is this kind of theory that has inspired most of the artificial neural network architectures (say to be \"formal neural networks\"). Learning is then the process that consist either to establish new connections, or modify existing one by trial and error or by an external reference (we will focus especially on the latter option).\n\t\n\tThis brings us to a fundamental question, based on our current knowledge: can we build approximate mathematical models of neurons and make them to possibly perform useful tasks? Well, the short answer is: yes, even if the networks that we develop have only a tiny fraction of the power of the human brain actually (year 2003), and that is the goal here to show how we can do it formally (because technically it is obvious that more powerful are the computer, more impressive will be the results)!\n\t\n\tNeural networks are now used in all kinds of application in various fields. For example, there are neural networks developed for: aircraft autopilots, car autopilot, automotive control systems automatic reading of bank checks, automatic reading of postal addresses, signal processing, balistic missile autopilots, voice synthesis, personal assistant, computer vision systems, market predictions, financial risks assessments, various manufacturing processes, medical diagnosis, oil and gas exploration, robotics, telecommunications, management decisioneering systems, classification and many others. In short, neural networks today have a significant impact and there is a safe bet that their importance will continue to grow in the future.\n\t\n\t\\paragraph{Neuron model}\\mbox{}\\\\\\\\\n\tThe mathematical model of an artificial neuron, or \"\\NewTerm{perceptron}\\index{perceptron}\" is shown in the figure below. A neuron consists essentially of an \"integrator\" which performs the weighted sum of its inputs (such as statistical mean ponderated by the inverse number of items!). The result $n$ of that is then transformed by a transfer function $f$ that produces the output $a$ of the formal neuron.\n\n\tThe $R$ neuron inputs  correspond to vector correspond traditionally denoted:\n\t\n\twhile:\n\t\n\trepresents the neuron's vector weight (we distinguish them to prepare ourselves to the study of multiple layers formal neurons... also named \"deep learning\" systems):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/formal_neuron_network_one_layer.jpg}\n\t\t\\caption{Example of one-layer formal neuron with the input vector and scalar output}\n\t\\end{figure}\n\tThe output of the integrator is defined (as it is an engineering technique) by the following relation:\n\t\n\tthat we can also write in matrix form (it could also be written as tensor but ...):\n\t\n\tSuch that finally:\n\t\n\tThis output is obviously a weighted sum of the weights and inputs less what we name the \"\\NewTerm{bias $b$ of the neuron}\\index{bias of a neuron}\" (correction factor determined by trial and error and often null in practice). The weighted sum is named \"\\NewTerm{activation level of the neuron}\\index{activation level of the neuron}\". The bias $b$ is also named \"\\NewTerm{activation threshold of the neuron}\\index{activation threshold of the neuron}\". When the activation level reaches or exceeds the threshold $b$, then $n$, the argument of $g$ becomes zero or positive of course. Otherwise it is negative.\n\n\tWe can draw a parallel between this mathematical model and some information that we know (or think we know) about the biological neuron. That latter has three main components: the dendrites, the cell body and axon:\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/neuron.jpg}\n\t\t\\caption{Simplified representation of the vocabulary of human neurons}\n\t\\end{figure}\n\tThe dendrites form a network of nerve receptors that are used to route to the body of the neuron the electrical signals from other neurons. It acts as like an integrator, accumulating electric charges. When the neuron becomes sufficiently excited (when the accumulated charge exceeds a certain threshold), by an electrochemical process, it generates an electric potential that spreads through its axon to eventually excite other neurons. The point of contact between the axon of one neuron and the dendrite of another neuron is named the \"synapse\". It seems that this is the spatial arrangement of neurons and their axons and also their quantity ($86,000,000,000$ neurons and $1.5\\cdot 10^{14}$ synapses for the average human brain), and the quality of individual synaptic connections that determine the precise function of a biological neural network. This is based on this knowledge that the mathematical model described above has been defined (this is \"Biomimicry Engineering\" or \"Biomimestims Engineering\").\n\t\n\tA weight of an artificial neuron represents somehow the effectiveness of a synaptic connection. A negative weight inhibits in way the entrance, while a positive weight increase its effect. It is important to remember that this is a rough approximation of a real synapse resulting in fact of a quite complex chemical process and dependent on many external factors still unclear. We must understand that our artificial neuron is a pragmatic model which, as we shall see later, will help us ot accomplish interesting tasks and more neurons we have more the tasks can be complex. The biological plausibility of this model is not important to us. What counts is the result that this model will allow us to achieve.\n\t\n\tAnother limiting factor in the model we set ourselves is regarding its discreet nature. Indeed, in order to simulate a neural network, we will make the time discrete in our equations. In other words, we assume that all neurons are synchronous, that is to say that at each time $t$, they will simultaneously calculate the weighted sum and produce an output $a(t)=f(n(t))$. In biological networks, all neurons are actually asynchronous...\n\n\tSo let us come back to our model as formulated by the previous relation and by doing a change of notation $\\vec{w}^T$:\n\t\n\tThis equation leads us to introduce a new more formal scheme of our formal neural nework (FNW) or perceptron:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/neural_network_one_layer_vector_simplified_form.jpg}\n\t\t\\caption{Vector written example of one-layer formal neuron with the input vector and scalar output}\n\t\\end{figure}\n\tWe represent the $R$ inputs as a black rectangle (the number of entries is indicated below the rectangle). From this rectangle result a vector $\\vec{p}$ whose dimensions are $R\\times 1$ . This vector is multiplied by a vector $W$ that contains the weights (synaptic) neuron. In the case of a single neuron, this vector has dimension $1\\times R$. The result of the multiplication is the \"activation level\" (scalar) which is then compared to the threshold $b$ (a scalar) by subtraction. Finally, the output of the neuron is calculated by the function $f$. The output of a single neuron is then always a scalar in this special case.\n\n\tTo find the components of the matrix $\\vec{w}$ (neuron input weight), and the bias $b$ we use operational research techniques (simplex method, conjugate gradient method, evolutionary algorithms, etc.) on a sample of data sample of the company of size $n$ in order to \"train the model of the neuron\". The purpose will then be to found weights $\\vec{w}$ that minimize the quadratic error given by:\n\t\n\twhere $a_k$ is the model output for the vector $\\vec{r}_k$ and $y^k$ is a real value corresponding the $\\vec{r}_k$ .\n\t\n\tAfter we test the result on a sample test before  putting the neural network in production for not yet existing data (we will do a detailed example with Microsoft Excel just after the presentations of the transfer functions).\n\t\t\n\t\\pagebreak\n\t\\paragraph{Transfer functions}\\mbox{}\\\\\\\\\n\tSo far, we have not specified the nature of the activation function $a=f(n)$ of our model. It turns out that several possibilities exist and these are empirical and must adapt to different situations (and the adaptation is sometimes also dynamic). The most common and most cited in the literature are listed in the figure below:\n\t\n\tThe three most used in the field of engineering are the functions \"threshold\" (I) , \"linear\" (II) and \"sigmoid\" (III) as shown in details below:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/neural_network_transfer_functions.jpg}\n\t\t\\caption{Most used transfer functions for neural networks in the 20th century}\n\t\\end{figure}\n\tAs its name suggests it, the threshold function applies a threshold on its input. Specifically, a negative input does not pass the threshold, the function returns then a $0$ (false), while a positive or zero input exceeds the threshold, and the function returns then a $1$ (true). It is obvious that this kind of feature is to make binary decisions (this function can also be assimilated to the Heaviside function for those who know it...).\n\t\n\tThe linear function is itself very simple, it directly associate its input to an output according to the relation $a=f(n)=n$. It is then evident that the output of the neuron corresponds to its activation level for which the zero value (the ordinate at the origin) occurs when $\\vec{w}^T\\vec{p}=b$.\n\t\n\tThe sigmoid transfer function is itself defined by the mathematical relation:\n\t\n\tit looks like to threshold function, either the linear function, as we are far or near to $b$ respectively. The threshold function is very nonlinear because there is a discontinuity when $\\vec{w}^T\\vec{p}=b$. For its part, the linear function is entirely linear. It has no change in slope. The sigmoid is an interesting compromise between the two. Finally notice that the hyperbolic tangent function is a symmetric version of the sigmoid.\n\t\n\t\n\t\\paragraph{Network Architecture}\\mbox{}\\\\\\\\\n\tBy definition, a \"\\NewTerm{neural network}\\index{neural network}\" is a network of several neurons, usually organized in layers. To build a layer of neurons $S$, we simply need to assemble them as in the figure below:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/neural_network_one_layer_vector_form.jpg}\n\t\t\\caption{Example of one-layer formal neural network with the input vector and output vector}\n\t\\end{figure}\n\tThe $S$ neurons of a same layer are all connected to the $R$ inputs in the figure above. We then say that the layer is \"fully connected\". But this is a special case and not a generality. Often the inputs of a neuron are different from those of another neuron, etc.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIf a neural network that has for purpose to learn that can learn a probability distribution over its set of inputs has only one hidden layer of $S$ neurons not interconnected between them (as is the case in the figure above), that is to say independent, we speak then of \"\\NewTerm{restricted Boltzmann machine RBM} \\index{restricted Boltzmann machine}\".\n\t\\end{tcolorbox}\n\t\n\tA weight $w_{i,j}$ is associated with each connection. We will always denote the first index by $i$ and the second by $j$. The first index (row) always means the neuron number on the layer, while the second index (column) specifies the number of the input. Thus, $w_{i,j}$ denotes the weight of the connection that connects the neuron $i$ to its input $j$. All the weights of a neuron lays thus forms a matrix $W$ of dimension $S\\times R$:\n\t\n\tWe must of course take into account that dimensionally we have not necessarily $S=R$ in the general case (the numbers of neurons and inputs are independent). If we consider that the $S$ neurons neurons form a vector, then we can create the vectors:\n\t\n\tThis brings us to the simplified representation illustrated below:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/neural_network_one_layer_multiple_neurons_vector_simplified_form.jpg}\n\t\t\\caption{Vector written example of one-layer formal neural network with the input vector and output vector}\n\t\\end{figure}\n\tFinally, to build a neural network (or MLP for \"\\NewTerm{Multi-Layer Perceptron}\\index{Multi-Layer Perceptron}\"), it just sufficient to combine layers as below:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.6]{img/computing/neural_network_multiple_layer.jpg}\n\t\t\\caption{Principle of construction of a Multi-Layer Perceptron}\n\t\\end{figure}\n\tThis example includes $R$ inputs and three layers of neurons have respectively $S^1,S^2,S^3$ neurons. In the general case, again these numbers are not necessarily equal. Each layer also has its own weight matrix $W^k$, where $k$ is the layer index. In the context of vectors and matrices relatively to one a layer, we always will use an exponent to describe this index. Thus, the vectors $\\vec{b}^k$, $\\vec{n}^k$, $\\vec{a}^k$ are also associated with the layer $A$.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tA superposition of MLP is what is usually named a: DLN for \"\\NewTerm{Deep Beliefs Net}\\index{Deep Beliefs Net}\".\n\t\\end{tcolorbox}\n\tIt should be notices in this example that the layers that follows the first has as input the output of the previous layer. So we can put on as many layers as we want, at least in theory. We can set any number of neurons of each layer. In practice, we will see later however it is not desirable to use too many neurons. Note also that nothing prevents us from changing transfer function from one layer to another. Thus, in the general case we have not necessarily $f^1=f^2=f^3$.\n\t\n\tThe last layer is obviously named \"\\NewTerm{output layer}\\index{output layer}\". The layers preceding the output layer are named \"\\NewTerm{hidden layers}\\index{hidden layers}\".\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tMultilayer neural networks are more powerful than simple single layer neural networks of course. Using two layers, provided you use a sigmoid activation function on the hidden layer we can \"train\" a network to produce an approximation of most functions with arbitrary precision. Except in rare cases, artificial neural networks use two or three layers.\n\t\\end{tcolorbox}\n\t\"\\NewTerm{Train}\\index{train a neural network}\" a neural network means changing the value of its weight matrices and its so that he realizes the desired input/output function (I / O). We will study in detail various algorithms and methods of heuristics approach to achieve it in different contexts.\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.7]{img/computing/neural_information_processing.jpg}\n\t\t\\caption{Neural Information Processing (source: Purdue University image/e-Lab)}\n\t\\end{figure}\n\tLet us now see a easy companion example (originally developed by Joe Breedlove) as always in this book first done with a spreadsheet software like Microsoft Excel. Afterwards we will show the same output result with R and MATLAB for which you can found the detailed procedure in the corresponding companion books.\n\t\n\t\\pagebreak\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tA company has measured during $14$ weeks its actual sales (Column: \\textit{Value to predict}) in function of forecast sales of five of its branches (\\textit{Variable1}, \\textit{Variable2}, etc.) and has reproduced them in Microsoft Excel 14.0.6123:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/neural_network_list_training_set_microsoft_excel.jpg}\n\t\t\\caption[]{Training data list for our neural network in Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\tNotice that there is absolutely no formula in the list above! The return on experience (especially with Microsoft Excel...) tell us it would be better to do a network architecture with two neurons, first with branches $\\{1,2,3\\}$ based on a sigmoid and a second with branches $\\{4.5\\}$ also based on a sigmoid. In addition, all should have a single bias and the both neurons should have a specific weight in comparison with the one and the other.\n\n\tWe then prepare the following table:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/neural_network_initial_weight_bias_and_ponderations_microsoft_excel.jpg}\n\t\t\\caption[]{Weight bias and weights to determined for our neural network}\n\t\\end{figure}\n\tOnce the table of weights, bias and ponderations built, we write our two neurons network  with the sigmoid function, for example, right next to the training sample data (which will facilitate the comparison):\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.6]{img/computing/neural_network_list_training_set_with_neural_network_microsoft_excel.jpg}\n\t\t\\caption[]{List of sample training data with neural network cells}\n\t\\end{figure}\n\tOr with the explicit formulas for the last three columns of interest:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.6]{img/computing/neural_network_list_training_set_with_neural_network_formulas_microsoft_excel.jpg}\n\t\t\\caption[]{List of sample training data with neural network cells}\n\t\\end{figure}\n\tTo apply operational research techniques, we need to minimize or maximize something. Therefore, we will seek to minimize the sum of squared errors by creating the following column:\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/neural_network_list_training_set_error_minimization_microsoft_excel.jpg}\n\t\t\\caption[]{List of sample training data with neural network cells and and quadratic error minimization}\n\t\\end{figure}\n\tOr with the explicit formulas (we see well that this corresponds indeed to the square of the difference between the measurements and model):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/neural_network_list_training_set_error_minimization_formulas_microsoft_excel.jpg}\n\t\t\\caption[]{List of sample training data with neural network cells and and quadratic error minimization}\n\t\\end{figure}\n\tNow with the solver of Microsoft Excel 14.0.6123 we minimize the content of the cell L36:\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/neural_network_solver_excel.jpg}\n\t\t\\caption[]{Neural network solver quadratic error minimization in Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\twe should not be too focused about the accuracy of the constraints for this case and therefore we have to play a little with this setting to get a satisfactory result:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.65]{img/computing/neural_network_solver_settings_excel.jpg}\n\t\t\\caption[]{Neural network solver settings in Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\tTo get a satisfactory result, it will be necessary in this case to request an accuracy of $0.001$. Which will give after the execution of the search by the solver a total square error of $0.8479$ (cell L36) and for the parameters of the neural network:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/neural_network_solver_excel_solution.jpg}\n\t\t\\caption[]{Neural network solver solution in Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\tSpecialized software will do better with a total square error of $0.8405$ (still for cell L36) and for the parameters of the neural network:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/neural_network_optimal_values_external_software.jpg}\n\t\t\\caption[]{Neural network optimal values with specialized software}\n\t\\end{figure}\n\tWe can graphically compare the measurements used to train the neural network and the result of the neural network model itself. Then we have:\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.9]{img/computing/neural_network_measurements_vs_model_plot_excel.jpg}\n\t\t\\caption[]{Neural network model VS Measurements}\n\t\\end{figure}\n\tWhich seems not bad for a nonlinear model! But once the model trained, we must always see if it applies to other data (test sample). Therefore let us consider:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/neural_network_test_sample_excel.jpg}\n\t\t\\caption[]{Neural network test data sample}\n\t\\end{figure}\n\tAlways with the same formulas:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.6]{img/computing/neural_network_test_sample_formula_excel.jpg}\n\t\t\\caption[]{Neural network test data sample neural network formula in Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\tAnd if we also graphically compare the real data and the modeled data, we get:\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.9]{img/computing/neural_network_test_sample_plot_excel.jpg}\n\t\t\\caption[]{Neural network test data sample neural network formula in Microsoft Excel 14.0.6123}\n\t\\end{figure}\n\tand here we see that the model is significantly worse. But it is so! The predictive science is not an exact science but a heuristic...\\\\\n\t\n\tIn the MALTAB companion book, working with the same data and building a similar neural network:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.9]{img/computing/neural_network_matlab.jpg}\n\t\t\\caption{Neural network in MATLAB 2013a}\n\t\\end{figure}\n\twe get the following model fitting plot:\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.85]{img/computing/neural_network_measurements_vs_model_plot_matlab.jpg}\n\t\t\\caption[]{Neural network model VS Measurements in MATLAB  2013a}\n\t\\end{figure}\n\tand test sample plot(MATLAB performs better than Microsoft Excel solver in this special case):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.85]{img/computing/neural_network_test_sample_plot_matlab.jpg}\n\t\t\\caption[]{Neural network model test sample plot in MATLAB  2013a}\n\t\\end{figure}\n\t\\end{tcolorbox}\n\t\n\t\n\t\\subsubsection{Genetic Algorithms}\n\tGenetic algorithms (GAs) are iterated  stochastic optimization algorithms based on the mechanisms of natural selection and genetics belonging to the family of \"\\NewTerm{evolutionary algorithms}\\index{evolutionary algorithms}\". This is an optimization technique that has spread widely since the beginning of the 21st century through the version 14.0.6123 of Microsoft Excel wherein the solver incorporates an evolutionary algorithm by default as shown by in the screenshot below:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.85]{img/computing/evolutionary_solver.jpg}\n\t\t\\caption[]{Screenshot of the the evolutionary Microsoft Excel 14.0.6123 solver}\n\t\\end{figure}\n\twith the corresponding options:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.85]{img/computing/evolutionary_solver_options.jpg}\n\t\t\\caption[]{Screenshot of the the evolutionary Microsoft Excel 14.0.6123 solver options}\n\t\\end{figure}\n\tThe process of the genetic algorithm is quite simple:\n\t\\begin{enumerate}\n\t\t\\item We start with an initial population of potential solutions (chromosomes) arbitrarily selected \n\n\t\t\\item We evaluate their relative performance (fitness) \n\n\t\t\\item Based on this performance, we create a new population of potential solutions using simple evolutionary operators: selection, crossover and mutation\n\n\t\t\\item We start this cycle until we find a satisfactory solution\n\t\\end{enumerate}\n\tGAs were originally developed by John Holland (1975). This is the book of Goldberg (1989) that we own their popularization. Their fields of application are widespread. Besides the economy (portfolio risk minimization), they are used for optimization functions in  finance, in optimal control theory (operational research), in the theory of repeative and differentials games (namely: in evolutionary games and the prisoner's dilemma) and information retrieval (Google) and search for shortest path in graph theory (Internet routing or GPS). The reason for the large number of applications is clear: simplicity and efficiency. Of course, other stochastic exploration techniques exist, the Monte Carlo can be regarded as a similar concept.\n\t\n\tTo summarize, Lerman and Ngouenet (1995) identified four main properties that make the fundamental difference between these algorithms and other methods:\n\t\\begin{enumerate}\n\t\t\\item The genetic algorithms use a coding of the input parameters, not the parameters themselves\n\n\t\t\\item  Genetic algorithms work on a population of points, instead of a single point\n\n\t\t\\item Genetic algorithms use only the values of the function considered, not its derivative, or other auxiliary knowledge\n\n\t\t\\item  The algorithms use probabilistic transition rules, not deterministic one\n\t\\end{enumerate}\n\tThe simplicity of their mechanisms, their ease of implementation and efficiency even for complex problems led to a growing number of publication this recent years in the scientific community.\n\t\n\t\\textbf{Definitions (\\#\\mydef):}\n\t\\begin{enumerate}\n\t\t\\item[D1.] A \"\\NewTerm{genetic algorithm}\\index{genetic algorithm}\" is defined by an individual / chromosome / sequence and a potential solution to the given problem.\n\n\t\t\\item[D2.]  A \"\\NewTerm{population}\\index{population (algorithm)}\" is a set of chromosomes or points of the search space\n\n\t\t\\item[D3.]  The \"\\NewTerm{environment}\\index{environment}\" is assimilated with the search space\n\n\t\t\\item[D4.]  The function that we seek to maximize is named \"\\NewTerm{fitness function}\\index{fitness function}\"\n\t\\end{enumerate}\n\n\tBefore going further, we need to define more formally the above concepts but under the particular case of Binary coding!\n\t\n\tThe organisms in competition are are the \"individuals\". Given an alphabet $A=\\{a_1,a_2,\\ldots,a_n\\}$, we assume that each individual can be represented by a word of fixed-length $l$ caught in the in $A^{*}$. \n\n\tThe word associated with an individual of the population will be named a \"\\NewTerm{chromosome}\\index{chromosome}\" or \"\\NewTerm{sequence}\\index{sequence}\" (the term is not quite equivalent to its biological namesake, however, it is common practice to use the term here too ) and thus given by $A$ of the length $l(A)$ with $\\forall i\\in[1,l]: a_i\\in A=\\{0,1\\}$ (reason: assumption of binary coding).\n\n\tIf there is no risk of confusion, we will identify the terms of \"individual\" and \"chromosome\".\n\n\tThe individuals form a population $P$ of size $P$, denoted by:\n\t\n\twith $i=1\\ldots N$.\n\tWe will make another important statement, that is to say, there is a function $f$ from one sequence with positive values which we denote $f(A)$, named \"\\NewTerm{fitness function}\\index{fitness function}\" that to any $A_i$ associates real number such that for $i\\neq j$:\n\t\n\tif and only if $A_i$ is better suited to the environment than $A_j$\n\n\tNotice that the term \"appropriate\" is not defined. For this, we would characterize the environment in which the individuals evolve, what we will not do. In fact, since we assume the existence of such a function and we put it in equivalence to the degree of adaptation, it is automatically set by the definition of $f$.\n\n\tWe will name \"\\NewTerm{generation}\\index{generation (algorithm)}\" a population at time $t$, what must be put in relation with the notion of lifetime or age. However, we place ourselves here in the particular case where each individual has a life equal to $1$, so the generation $(t + 1)$ consists of different individuals from the generation$ $t, we name them them obviously the \"\\NewTerm{descendants}\\index{descendants}\". Conversely, individuals of generation $t$ are the \"\\NewTerm{ancestors}\\index{ancestors}\" of the individuals of the generation $(t + 1)$. We denote the generation at time $t$ by $P(t)$, thus the population at time $t$.\n\n\tThus, a chromosome is seen as a bit sequence in binary code known as \"\\NewTerm{bit string}\\index{bit string}\". In the case of a non-binary coding, such as the real number encoding for example, then the sequence A contains only one point, we have then $A=\\{a\\}$ with $a\\in\\mathbb{R}$. \n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe fitness (effectiveness) is given by a function with real positive values. In the case of binary encoding, we will often use a function of decoding $d$ that will gives the possibility to transform  a binary string to a real number:\n\t\n\tafterwards the fitness function is chosen such that it transforms this value into a positive value:\n\t\n\t\\end{tcolorbox}\t\n\tThe purpose of a genetic algorithm is then simply to find the string that maximizes this function $f$. Of course, each individual problem will require its own functions $d$ and $f$.\n\n\tGAs are then based roughly on the following phases:\n\t\\begin{enumerate}\n\t\t\\item Initialization: an initial population of $N$ chromosomes is randomly chosen\n\n\t\t\\item Evaluation: each chromosome is decoded and evaluated\n\n\t\t\\item Selection: creation of a new population of $N$ chromosomes based on previous step by using an appropriate method of selection.\n\n\t\t\\item Reproduction: possibility of crossover and mutation in the new population\n\n\t\t\\item Return to the Evaluation phase until the stop of the algorithm\n\t\\end{enumerate}\n\tOr for people that are more visual:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/genetic_algorithm_flowchart.jpg}\n\t\\end{figure}\n\t\n\t\\paragraph{Encoding and Initial population}\\mbox{}\\\\\\\\\n\tThere exist three main types of coding:\n\t\\begin{enumerate}\n\t\t\\item Binary\n\t\t\\item Gray\n\t\t\\item Real\n\t\\end{enumerate}\n\tWe can easily move from one encoding to another. Some authors do not hesitate, moreover, to draw parallels with biology, by speaking of \"genotype\" (\\SeeChapter{see section Population Dynamics}) regarding the binary representation of an individual, and \"phenotype\" (\\SeeChapter{see section Population Dynamics}) with respect to its corresponding real value in the search space.\n\n\tLet us recall that the simplest transformation (decoding function $d$) of a binary string $A$ into an integer $x$ is effected by the following rule (\\SeeChapter{see section Numbers}):\n\t\n\twhere $l$ is the number of digits of the string minus $1$.\t\n\t\n\tTherefore the chromosome $A=\\{1,0,1,1\\}$ has trivially for value:\n\t\n\tObviously, the function needs to be adapted (by trial and error!) depending on the problem. Thus, if we seek to maximize a function $f:[0,1]\\rightarrow [0,1]$ a possible method would be as follows (the size of the chromosome of course dependent on the desired accuracy):\n\t\n\t\n\tThis can be assimilated to a harmonic series (\\SeeChapter{see section Sequences and Series}). For accuracy to the fifth decimal place, we will put $l=17-1$ since:\n\t\n\tAgain Another way to do would be to choose $d$ such as:\n\t\n\tLet us give an explanation of this choice:\n\t\n\tLet us put $l=n-1$:\n\t\n\tSo, with $l=16$ we have $2^{17}-1=131071$ and:\n\t\n\tThis last rule can be generalized. Thus, suppose that we seek to maximize (\"normalize\" would be a more suited term perhaps...) $f$ according to a real variable $x$. Given $D=[x_{\\min},x_{\\max}]$, with $D\\subset \\mathbb{R}$, the allowed  search space with $x_{\\min}$ and $x_{\\max}$ the lower and upper bounds of this space. Given $\\mathrm{prec}$ the precision (decimal) with which we seek $x$. Given:\n\t\n\tthe length (range) of the interval $D$. We then have to divide this interval at worst in:\n\t\n\tequal sub-intervals to meet accuracy expectations. For example, given $D=[-1,2]$ so we have $R=3$, if we wanted a precision $\\mathrm{prec}=6$, then we must divide this interval in $n=3,000,000$ sub-intervals.\n\t\n\tLet $k$ denote the natural integer such that $2^k>n$, which in our example involves $k=22$ as:\n\t\n\tthe transformation of a binary string $A=\\{a_1,\\ldots,a_l\\}$ in a real number $x$ can then be run in three stages:\n\t\\begin{enumerate}\n\t\t\\item Conversion (base $2$ into base $10$):\n\t\t\n\n\t\t\\item Normalization:\n\t\t\n\n\t\t\\item Maximization:\n\t\t\n\t\\end{enumerate}\n\tOr what remains the same directly in one step by using:\n\t\n\tTherefore for $f:[0,1]\\rightarrow [0,1]$ and $\\forall i,a_i=1$ we fall back well on:\n\t\n\tAbout the initialization phase, the procedure is quite simple. It consists of a random selection of $N$ individuals in the space of allowed individuals. In binary coding, according to the size $l$ of the string, we do for a chromosom $l$ sampling in $\\{0,1\\}$ with equal probability.\n\t\n\t\\paragraph{Operators}\\mbox{}\\\\\\\\\n\tOperators play a key role in the possible success of a GA. We number three main one: \n\t\t\\begin{enumerate}\n\t\t\t\\item the selection operator\n\t\t\t\\item the crossover operator\n\t\t\t\\item the mutation operator\n\t\t\\end{enumerate}\n\tIf the principle of each of these operators is easy to understand, it is difficult to explain the isolated importance of each of these operators in the success of the AG. This is partly due to the fact that each of these operators acts according to various criteria that depends on its own characteristics (fitness of individuals, likelihood of activation of the operator, etc.).\n\t\t\n\t\\pagebreak\n\t\\subparagraph{Operator of selection}\\mbox{}\\\\\\\\\n\tThis operator may be the most important since it allows individuals in a population to survive, reproduce or die. Generally, the probability of survival of an individual will be directly connected to its relative effectiveness in the population.  The basic part of the selection process is to stochastically select from one generation to create the basis of the next generation. \n\n\tThere are several methods for reproduction.  The most known and used method is undoubtedly the biased Goldberg's (1989) lottery wheel (roulette wheel). According to this method, each chromosome is duplicated in a new population in proportion to its adaptive value. We perform in some way, as many sampling that there are individuals in the population. Thus, in the case of a binary coding, the fitness of a particular chromosome being $f (d (A))$, the probability with which it will be reintroduced into the new population of size $N$ is given by the relative fitness:\n\t\n\tIndividuals with high fitness value thus have more chance of being selected by the wheel. We speak then of \"\\NewTerm{proportional selection}\\index{proportional selection}\":\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/goldberg_wheel.jpg}\n\t\t\\caption{Example of Goldberg's wheel with five indivuals with their respective relative fitness}\n\t\\end{figure}\n\tObviously the number of times the roulette wheel is spun is equal to the size of the new population.\n\n\tEach time the wheel stops this gives the fitter individuals the greatest chance of being selected for the next generation and subsequent: \"\\NewTerm{mating pool}\\index{mating pool}\".\n\n\tThe major drawback of this method lies in the fact that an individual that is not the best may still dominate the selection (imagine the search for maxima of a function in $\\mathbb{R}^2$, there may be several of them - maxima - and therefore we could get a wrong selection ...), we will speak rightly then of \"\\NewTerm{premature convergence}\\index{premature convergence}\" and this is one of the most common problems when using genetic algorithms. It can therefore also result in a loss of diversity by the domination of a super-individual. Another drawback is its poor performance towards the end when all individuals are alike.\n\n\tOne solution to this problem lies not in the use of another method of selection but the use of a modified fitness function. So we can use a scaling to decrease or increase artificially the relative difference between the fitness of individuals.\n\n\tBriefly, there are other methods, the best known being that of the tournament (tournament selection) we draw two random individuals in the population and reproduce the best of both in the new population. We repeat this procedure until the new population $P$ is complete. This method gives good results. However, as important as the selection phase, it does not create new individuals in the population. This is the role of crossover and mutation operators.\n\t\n\t\\subparagraph{Crossover operator}\\mbox{}\\\\\\\\\n\tThe crossover operator allows the creation of new individuals in a very simple process. It allows the exchange of information between chromosomes (individuals). First, two individuals, which then form a couple, are sample in the new population issued from the selection (or reproduction). Then one (or potentially many) crossing site is randomly draw (number between $1$ and $l-1$). Finally, according to a probability $P_c$ that the crossing is done, the end segments (in the case of a single crossing site) of both parents are then exchanged around this site:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/crossover.jpg}\n\t\t\\caption{Illustrative example of crossover}\n\t\\end{figure}\n\tThis operator allows the creation of two new individuals. However, an individual selected in the reproduction (slection) is not necessarily subjected to a crossover. The latter is carried out with a certain probability $P_c$. The more this probability is high and the more the population will undergo a crossover modification.\n\n\tAnyway, it is possible that the joint action of reproduction and the crossing is insufficient to ensure the success of the GA. Thus, in the case of binary encoding we have chosen so far, some information (ie the characters of the alphabet) may disappear from the population. Thus if no individual of the initial population contains a $1$ in the last position of the string and that we know a priori that this $1$ in the last position is part of the optimal string to find, all possible crosses will never show this $1$ initially unknown. In real number coding, such a situation can happen when using a simple crossover operator, it was such that the initial population was between $0$ and $40$ and that the optimal value was $50$. All possible combinations of convex digits belonging to the range $[0,40]$ will never allow to reach a the number of $50$. This is to address, among others, this problem that the mutation operator is used.\n\t\n\tAs usually the crossover operation uses $2$ individuals. So, if you have $20$ individuals, we choose $10$ pairs to cross, and with a probability of $P_c=80\\%$, on average we're going to cross only $8$ pairs.\n\t\n\n\t\\subparagraph{Mutation operator}\\mbox{}\\\\\\\\\n\tThe purpose of this operator is to change randomly, with some probability., the value of a component of the individual. In the case of binary encoding, each bit $a_i\\in\\{0,1\\}$ is replaced following a probability $P_m$ by its inverse ${a'}_i=1-a_i$. This is what is shown in the figure below. Like many crossover positions may be possible, we can very well admit that a same string can undergo several mutations.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/mutation.jpg}\n\t\t\\caption{Illustrative example of mutation}\n\t\\end{figure}\n\tThe mutation is traditionally considered a marginal operator even if somehow it gives to genetic algorithms the ergodic property (ie all points of the search space can be achieved). However operator is of great importance. It performs a dual role: perform a local search and / or out a global search (remote search).\n\t\n\tThe operators of the genetic algorithm are guided by a number of parameters set in advance. The value of these parameters affect the success of failure of a genetic algorithm. These parameters are (the reader can compare this list with the parameters available in the Microsoft Excel solver screenshot given earlier above):\n\t\\begin{itemize}\n\t\t\\item The size of the initial population $N$, and the coding length $l$ of each individual (in the case of binary encoding). If $N$ is too large, the computation time of the algorithm can be very important, and if $N$ is too small, it may converge too quickly to the wrong chromosome.\n\n\t\t\\item The crossover probability $P_c$, that depends on the form of the fitness function. Its choice is general heuristic (just like $P_m$). The higher it is, the more the initial population obviously undergoes significant changes. The generally accepted values are between $0.5$ and $0.9$.\n\n\t\t\\item The probability of mutation $P_m$ is generally small since a high rate may lead to a suboptimal solution.\n\t\t\n\t\tRather than reducing $P_m$, another way to avoid the best individuals to be altered is to use explicit report of the elite individuals in a certain proportion. So often, the top $5\\%$, for example, of the population is directly reused directly, the operator of reproduction (selection) or mutation operating then only on the remaining $95\\%$. This is named an \"\\NewTerm{elitist strategy}\\index{elitist strategy}\".\n\t\\end{itemize}\n\tLet us now see an example of GA (example of Goldberg - 1989).\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tWe want to find the maximum of the function $(f)=x$ on the intervale $[0,31]$ where $x$ is an integer. The first step consist in coding the function. For example, we use a binary coding of $x$, the sequence (chromosome) containing a maximum of $5$ bits. Thus, we have $x=2\\rightarrow \\{0,0,0,1,0\\}$, and also $x=31\\rightarrow \\{1,1,1,1,1\\}$. We are therefore seeking maximum of a fitness function (we will choose $f(x)$ itself in this simple example) in a space of $2^5=32$ possible values of $x$.\n\t\\begin{enumerate}\n\t\t\\item Sampling and evaluation of the initial population\n\n\t\tWe set the size of the population to $N=4$. We draw randomly $4$ chromosomes knowing that a chromosome consists of $5$ bits, and each bit has a $50\\%$ probability of having a value of $0$ or $1$. The maximum, (randomly) $16$ is reached by the second sequence. Let us see how the algorithm will try to improve this result.\n\n\t\tFirst, we get the following table:\n\t\t\n\t\tWe turn again the Goldberg's wheel $4$ times to obtain the following sequence:\n\t\t\n\t\tWe see here well the risk that we would have to lose the Sequence N$^\\circ 2$ from the start... that's the problem with this method. It can converge more slowly than others. However, the reader will notice that we have lost the sequence N$^\\circ 3$.\n\n\t\tWe now turn to the crossover part: the ancestors are randomly selected. We randomly draw a crossover location (\"site\" or \"loci\") in the sequence. The crossing then operates at this location with a probability $P_c$. The table below shows the consequences of this operator assuming chromosomes $1$ and $3$, afterwards $2$ and $4$ are paired, and each time the crossing takes place (e.g. with $P_c=1$):\n\t\\end{enumerate}\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\n\tWe now turn to the mutation part: in this binary coding example, the mutation is the occasional random modification (low probability) of the value of a bit (bit reversal). We thus draw for each bit a random number between $0$ and $1$ and if this digit is less than $P_m$ then the mutation takes place. The table below with $P_m=0.05$ highlights this process:\n\t\n\tNow that the new population is fully created, we can evaluate it again:\n\t\n\tThe maximum is now $28$ (N$^\\circ 4$). So we went from $16$ to $28$ after a single generation. Of course, we must repeat the procedure from the selection stage until the overall maximum, $31$, is obtained, or until that a stop criterion has been satisfied.\n\t\\end{tcolorbox}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIt is possible to prove mathematically, what is remarkable !!!, that the portions of chromosomes that are found in the best individuals will tend to reproduce ...\n\t\\end{tcolorbox}\n\tThe reader interested can also take a look to the MATLAB companion book where we use GAs to found the optimum of the Rastriging function:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/rastriging_function.jpg}\n\t\t\\caption{Rastriging function in MATLAB 2013A}\n\t\\end{figure}\n\twhere it works quite well as show it the result below:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/rastriging_function_matlab_optimum.jpg}\n\t\\end{figure}\n\tand also for neural networks optimization.\n\t\n\t\\begin{flushright}\n\t\\begin{tabular}{l c}\n\t\\circled{60} & \\pbox{20cm}{\\score{3}{5} \\\\ {\\tiny 23 votes,  58.26\\%}} \n\t\\end{tabular} \n\t\\end{flushright}\n\n\n\t%to make section start on odd page\n\t\\newpage\n\t\\thispagestyle{empty}\n\t\\mbox{}\n\t\\section{Fractals}\n\t\\lettrine[lines=4]{\\color{BrickRed}F}ractals are figures invariant by scale change (we also talk about \"self-similar structures\") and are the graphic representation of contractant recurrent sequences (for IFS fractals that we will see later) or not divergent (for escape-time fractals as we we will see further below).\n\t\n\tThe basic idea - simple and great ... at the same time - often involves taking a starting point, to build its image through a particular mathematical function, to take the image of the image and so on. The goal is to study how the successive points are allocate in the global target set of the defined function, if they are approaching a limit or if they roam between different values that can we explain, if more points in part of the set than another?\n\t\n\tThe advantage of this type of questions concerns both the study of the evolution of biological populations than the future of the solar system, 3D computing (the origin being the generation of mountains for 3D landscapes) changes in stock prices or random number generation in particular fields, or even medical diagnostic (especially for brain or heart).\n\t\n\tSee below a simple example image by image:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/geometry/fractal_mountain_1.jpg}\n\t\\end{figure}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/geometry/fractal_mountain_2.jpg}\n\t\\end{figure}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/geometry/fractal_mountain_3.jpg}\n\t\\end{figure}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/geometry/fractal_mountain_4.jpg}\n\t\\end{figure}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/geometry/fractal_mountain_5.jpg}\n\t\t\\caption{Pseudo-mountains generation from a random fractal (probabilistic fractal)}\n\t\\end{figure}\n\tFor the average person, fractals are used to look pretty. But they have far more serious applications: for example we already saw in this book that some of these \"attractive\" images reproduced physical phenomena (population dynamics for the Feigenbaum's Fractal, turbulence in a fluid with the Lorentz attractor, distribution of galaxies, L-Fractals, clusters and supercluster of galaxies, ...). Fractals have also found applications in music (with software generating fractal music) and in film (3D to generate mountains, fire, grass). Finally, in the field of computer graphics, fractals are used to compress images very effectively, with consistent quality regardless of the zoom, they help to create realistic textures, and can afford to dither an image with good results. Fractals are also used to reduce the size of the receive antennas and to extend their effectiveness frequency spectrum (some of our cell phones of the early 21st century have fractal receptor of the type \"Sierpinski carpet\" - see below - because of all types of frequencies they need to manage!). In civil engineering fractals are used for building some sound absorbers walls. And many other things...\n\t\n\tThis fractal geometry differs from the Euclidean geometry first by its definition: the figures of Euclidean geometry are generally determined by algebraic relations, while the fractal curves are defined recursively as we have already mentioned. Fractals also have fractional dimensions (we have already discussed this topic in the section of Euclidean geometry when defining the concept of dimension). On the other hand, we must not neglect their autosimilar appearance: each part of a fractal can be observed at any scale: each part is (essentially) a copy of the whole.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe developments that follow could easily have been put in the section of Sequences and Series or even of Functional Analysis or seen as a special case of the section Topology reduces to the Euclidean space (this is why you will find here also many references to the topology section). Our choice is pedagogical as well as for the section of Cryptography, in the sense that it is much more interesting for a high-school student to see an application of abstract concepts of topology in a practical framework (and furthermore aesthetics) where they are absolutely necessary for a proper understanding of the subject rather than in a framework where we can escape them very well without too suffer. The reader will find here some developments and theorems proposed elsewhere in this book and this only in the order to avoid having too \"turn pages\" too much.\n\t\\end{tcolorbox}\t\n\t\n\tNatural fractals are named \"\\NewTerm{non-deterministic objects}\\index{non-deterministic objects}\" because the dynamic process that allows their creation itself varies with time randomly (see the section of Population Dynamics for an excellent example). Nevertheless, we can try to model dynamic systems that lead to fractal objects under a rigorous mathematical form (that is still a good example of the way in which the mathematicians manage to make a simple and intuitive concept into a concrete abstract mathematical model and somewhat confusing as for Knot Theory).\n\t\n\tIn this section, we will consider the study of two families of fractals that will be in order:\n\t\\begin{enumerate}\n\t\t\\item Deterministic fractals based on iterated function that are strictly self-similar. They are generated, as we shall see, by the recursive application of contracting functions on subsets of a metric space. The fixed point theorem will guarantee (as we shall also see!) the existence and uniqueness of a \"\\NewTerm{fixed subset}\\index{fixed subset}\" of the metric space, towards which every subset converge.\n\t\t\n\t\t\\item Escape-time fractals (also known as \"fractals by induction\") that are not strictly self-similar: They are generated as we shall see later by recurring non-divergent sequences. The fixed point theorem serving as guarantee for the non-divergence of the function with respect to the chosen starting points.\n\t\\end{enumerate}\n\t\n\t\\subsection{IFS Fractals}\n\tLet us start by looking at the first family of fractals discovered by Michael Barnsley in 1987: the \"\\NewTerm{deterministic iterated function systems IFS}\\index{deterministic iterated function systems}\".\n\t\n\tOf all fractals, figures only those built by iterated function systems usually shows the self-similarity property, meaning that their complexity is invariant under change of scale.\n\t\n\tLet us start by \"bounding\" the thing...\n\t\n\tWe take an initial geometry $E_0$ of space $E$, a function $f$ from $E$ to $E$ such that:\n\t\n\t(which requires that the initial object can not leave its own definition domain through the iteration of the function $f$) and we create the discrete dynamical system defined by:\n\t\n\tUnder certain conditions we will now see, the sequence of geometric objects $(E_0)$ \"tends\" to a limit, which is often a fractal object (we will see further below some famous examples).\n\t\n\tNaturally, there is a rigorous mathematical framework in which the mentioned conditions and the verb \"tends\" have a precise definition. In particular, the objects $E_n$ are all compacts of $E$, that is to say bounded subsets (that we can include in a segment if $E$ is a straight line, in a disk if $E$ is a plane or a ball if $E$ is the three-dimensional space) and closed (every convergent sequence of $E_n$ has its limit in $E$). We place ourselves then in the compact metric space, equipped with the Hausdorff distance (see below for definition) for which we will show that it is complete when we work with compact sets the plane and  of space, and we will check that $f$ is an \"\\NewTerm{Hutchinson operator}\\index{Hutchinson operator}\", i.e. a contraction application from the space of the compact in itself for that distance. It then will then just remain to apply the fixed point theorem.\n\t\n\tDynamic systems of this type are said to be \"deterministic\", and therefore named \"IFS\" (iterated function systems deteministic). Let us precise that the limit of the IFS is named the \"\\NewTerm{attractor of the IFS}\\index{attractor of the IFS}\". We can show that under the conditions mentioned above, this attractor does not depend on the shape of the original geometric object (we will see practical examples further below).\n\t\n\tInitially, we will limit our study to $\\mathbb{R}$ (the general case is given in section Topology) knowing anyway that a generalization to the two-dimensional Euclidean space does not require too big and intellectual work and that the whole complex is isomorphic to it.\n\t\n\t\\textbf{Definition (\\#\\mydef):}\n\tTo enable us to define the boundaries of our fractal functions let us consider $X \\subseteq \\mathbb{R}$. We say that $\\xi$ is the \"\\NewTerm{supremum}\\index{supremum}\" of $X$ and denote it by:\n\t\n\tif $\\xi$ is the smallest \"\\NewTerm{upper bound}\\index{upper bound}\" of $X$ (an upper bound of $X$ is a number $a$ that satisfies $\\forall x \\in X,x\\leq a$).\n\t\n\tSimilarly, we say that $\\xi$ is an \"\\NewTerm{infimum}\\index{infimum}\" $X$ and denote it by:\n\t\n\tif $\\xi$ is the biggest \"\\NewTerm{lower bound}\\index{lower bound}\" of $X$ (a lower bound of $X$ is a number $a$ that satisfies $\\forall x \\in X,a\\leq x$).\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tWe often use the following characterization of the supremum:\n\t\n\tif and only if:\n\t\n\twhich is almost obvious because we can approach as close as we want of $\\xi$ with elements of $X$ (think with small $\\varepsilon$). For information, we then also in the same idea:\n\t\n\tif and only if:\n\t\n\t\\end{tcolorbox}\t\n\tWe consider as intuitive that if $X \\subseteq \\mathbb{R}$ has an upper bound, that is to say if there exists $a \\in \\mathbb{R}$ as $\\forall x \\in X,x \\leq a$ (respectively lower bounded), then $X$ has a supremum (respectively infimum).\n\t\n\tWe will see later that it is this property that will give us the possibility to prove later $\\mathbb{R}$ a \"\\NewTerm{complete metric space}\\index{complete metric space}\"!\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tBy the way, let us underline the importance of taking $\\mathbb{R}$ as a definition for metric space for this property to be satisfied. We can in fact notice that it is not verified in the set $\\mathbb{Q}$of rational numbers with the following simple example:\n\t\n\twhich is majorated but has no supremum in $\\mathbb{Q}$ because this supremum is in $\\mathbb{R}$ as:\n\t\n\tTherefore:\n\t\n\tThis is what makes $\\mathbb{Q}$ is not \"complete\".\n\t\\end{tcolorbox}\n\t\n\t\\textbf{Definition (\\#\\mydef)}: We say that $X\\subseteq\\mathbb{R} $ is \"\\NewTerm{bounded}\\index{bounded}\" if $X$ is minorated and majorated.\n\t\n\tFrom the definition it follows immediately that $X$ is bounded if and only if there exists $a,b$ with such that $X\\subseteq [a,b]$.\n\t\n\tNow that the concept of bound is relatively well defined, let see how a sequence can behave near from it.\n\t\n\t\\textbf{Definition (\\#\\mydef):} We say that $(a_n)_{\\mathbb{N}}$ of $\\mathbb{R}$ is an \"\\NewTerm{increasing sequence}\\index{increasing sequence}\" (\"decreasing\" respectively) if:\n\t\n\trespectively:\n\t\n\tWe say the sequence $(a_n)_{\\mathbb{N}}$ is \"\\NewTerm{monotone}\\index{monotone}\" if it is increasing or decreasing as we have already seen in the section Sequences And Series.\n\t\n\t\\textbf{Definition (\\#\\mydef):} Given $T=\\left\\lbrace n_0,n_1,n_2,...\\right\\rbrace$ infinite subset of $\\mathbb{N}$ with $n_0<n_1<n_2<...$. We say the sequence $(a_{n_i})_{i\\in \\mathbb{N}}$  is a \"\\NewTerm{subsequence}\\index{subsequence}\" of the sequence $(a_n)_{\\mathbb{N}}$.\n\t\n\t\\begin{theorem}\n\tLet us now prove that every sequence in $\\mathbb{R}$ admits a monotone subsequence (it's a bit the idea of a fractal!)\n\t\\end{theorem}\n\t\\begin{dem}\n\tWe say that $a_m$ is a \"\\NewTerm{peak}\\index{peak}\" of the sequence if:\n\t\n\tConsider the set $P$ of peaks of the sequence $(a_n)_{\\mathbb{N}}$.\n\t\\begin{itemize}\n\t\t\\item If $P$ is infinite then the subsequence $(a_n)_{n\\in P}$ is monotone since decreasing.\n\t\t\n\t\t\\item If $P$ is finite or empty:\n\t\t\n\t\t(if $P=\\varnothing$ we choose any $m_1$). $a_{m_1}$ is therefore not by construction not a peak, so there exists $m_2\\geq m_1$ such as $a_{m_1}\\leq a_{m_2}$. In turn $a_{m_2}$ is not a peak, so there exist $m_3\\geq m_2$ such as $a_{m_2}\\leq a_{m_3}$ etc. We see that we define thus as an increasing subsequence.\n\t\t\n\t\t\\textbf{Definition (\\#\\mydef):} We say that the sequence $(a_n)_\\mathbb{N}$ \"\\NewTerm{converge}\\index{convergent sequence}\" into $a\\in \\mathbb{R}$ and we note this:\n\t\t\n\t\tif:\n\t\t\n\t\tIn this case we say that $a$ is the \"\\NewTerm{limit of the sequence}\\index{limit of the sequence}\" $(a_n)_\\mathbb{N}$.\n\t\\end{itemize}\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\n\t\\pagebreak\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tIn the example in figure below where the sequence seems to converge towards the value $1.13$ we observe that for a particular non-zero positive $\\varepsilon$, there exists a particular $n$ which we will denote $N$ (which value is $17$ in the below example) from which the sequence converges.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/convergence_sequence.jpg}\n\t\t\\caption{Illustration of the principle of convergence of a sequence}\n\t\\end{figure}\n\t\\end{tcolorbox}\n\t\tIf there is no $a$ (respectively $N$) for which the previous relation is true, then we say that the sequence \"\\NewTerm{diverge}\\index{divergent sequence}\".\n\t\\begin{theorem}\n\tLet us prove now that every increasing sequence $(a_n)_\\mathbb{N}$ (resp decreasing) and majorated (resp. minorated) converges.\n\t\n\tIn other words, we seek to prove that any monotonous and bounded sequence $(a_n)_\\mathbb{N}$ converges (obviously ... by construction).\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIf it does not converge, we could not easily find out what is its lower bound and upper bound ... hence the fact that the need of this theorem becomes trivial.\n\t\\end{tcolorbox}\n\t\\end{theorem}\n\t\\begin{dem}\n\tThis theorem is actually quite intuitive. Consider for this an increasing sequence. We suspect that:\n\t\n\tis the limit of this sequence. Note first of all that $a=\\sup\\left\\lbrace a_0,a_1,a_2,...\\right\\rbrace$ exists because $(a_n)_\\mathbb{N}$ is majorated (see theorem proved previously).\n\t\n\tGiven $\\varepsilon>0$. It exists an $a_N$ such tat $a-\\varepsilon\\leq a_N \\leq a$. But in this case as the sequence is increasing, we have $\\forall\\geq N,a-\\varepsilon\\leq a_n\\leq a$. That is to say $|a_n-a|\\leq \\varepsilon$. In the case where the sequence is decreasing by proceding in the same way we prove that $a=\\inf{a_0,a_1,a_2,...}$ is the limit of this sequence.\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\\begin{theorem}\n\tAnd now the important theorem to remember after all this: Every bounded sequence of real numbers has a convergent subsequence  (that is intuitive ... but again ... when formalized it becomes sometimes less intuitive...).\n\t\n\tThis is what mathematicians name the \"\\NewTerm{Bolzano-Weierstrass theorem}\\index{Bolzano-Weierstrass theorem}\" and it is extremely important in many areas of mathematics:\n\t\\end{theorem}\n\t\\begin{dem}\n\tGiven $(a_n)_\\mathbb{N}$ such a sequence. By a previous proposal we know there is a monotonic subsequence which we denote $(b_n)_\\mathbb{N}$. $(b_n)_\\mathbb{N}$ is therefore a monotone and bounded sequence and by the previous theorem, $(b_n)_\\mathbb{N}$ converges.\n\t\n\tSo if we are unable to determine whether the subsequence converges nor his exact limit (which in practice is often very difficult), we only need to know that the subsequence is monotone and bounded to ensure that it converges (which is most of time much easier).\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\\begin{theorem}\n\tRemember that we saw in the section of Sequences and Series that a Cauchy sequence is a sequence $(a_n)_\\mathbb{N}$ that verifies (we restrict ourselves to the special case of Euclidean distance):\n\t\n\tThe difference between the two terms of a Cauchy sequence can be made arbitrarily small provided that the indices of these terms are big enough.\n\t\n\tWe have also proved (again in the section of Sequences and Series) that in the case of a distance in the general topological sense any convergent sequence is a Cauchy sequence (by cons the reciprocal is not always true at the condition that do not complete the set... otherwise the reciprocal is always true). For example, a sequence of rational numbers that converges to a real number is not a Cauchy sequence, except if we complete the set of rationals to get the set of real numbers.\n\t\\end{theorem}\n\tLet us redo the proof restricted to Euclidean distance (the method is exactly the same as the reader will notice):\n\t\\begin{dem}\n\tGiven $\\varepsilon$, we must show that there is:\n\t\n\tBut $(a_n)_\\mathbb{N}$ tends to $a$ therefore it exists a $N\\in \\mathbb{N}$ such that $n\\geq N \\Rightarrow |a_n-a|\\leq \\varepsilon/2$. For $n,m\\geq N$ we therefore have:\n\t\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\\begin{theorem}\n\tLet us now prove that every Cauchy sequence is bounded (we never talked about this until now anywhere in this book therefore we need to do the proof). Since currently we have just proved that every convergent sequence is a Cauchy sequence...\n\t\\end{theorem}\n\t\\begin{dem}\n\tIf $(a_n)_\\mathbb{N}$ is a Cauchy sequence then particularly for $\\varepsilon=1$ (randomly) we know that there exist $N\\in \\mathbb{N}$ such that $n,m\\geq N\\Rightarrow |a_n-a_m|\\leq 1$. So if we fix $m$, we get:\n\t\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\tLet us see now the fundamental theorem (it is at this level that there is a huge impact on the understanding of what is actually a fractal!) that can be deduced from the previous  lines.\n\t\\begin{theorem}\n\tWe will show that every Cauchy sequence of real numbers is convergent (by construction ...). We say then that the metric space $\\mathbb{R}$ provided with the Euclidean distance (absolute value) is a \"\\NewTerm{complete space}\\index{complete space}\".\n\t\\end{theorem}\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\\textbf{R1.} The completeness property is related to the metric (hence this theorem could equally have its place in the section of Topology!): The same space can be complete for a given distance and incomplete for another one. It is therefore important to always specify the distance that we take when we speak of complete space.\\\\\n\t\n\t\\textbf{R2.} Intuitively, a space is complete if it has no holes. The set of rational numbers $\\mathbb{Q}$ is by example complete if the real numbers are added to it.\n\t\\end{tcolorbox}\n\t\\begin{theorem}\n\tConsider first $(a_n)_\\mathbb{N}$ a Cauchy sequence. We have seen juste before that  $(a_n)_\\mathbb{N}$ is bounded and then that by the Bolzano-Weierstrass theorem, there exists a convergent subsequence  $(a_{n_i})_{i\\in\\mathbb{N}}$. Let us denote by $a$ the limit of the subsequence $(a_{n_i})_{i\\in\\mathbb{N}}$. We will now prove that the sequence $(a_n)_\\mathbb{N}$ is convergent of limit $a$.\n\t\\end{theorem}\n\t\n\t\\begin{dem}\n\tGiven $\\varepsilon>0$, there exist a $N\\in \\mathbb{N}$ such as (application of the definition of convergence for a subsequence):\n\t\n\tFor this same $\\varepsilon$ it exists $M\\geq 0$ (application of the definition of convergence for a Cauchy sequence):\n\t\n\tGiven $C=N+M$. We choose $i\\geq C$. We then have $|a_{n_i}-a|\\leq \\varepsilon/2$ and for $n,i>C$:\n\t\n\tSo by the triangle inequality (\\SeeChapter{see section Vector Calculus}), for any $n\\geq C$:\n\t\n\tThis means precisely that $(a_n)_\\mathbb{N}$ converges to $a$.\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\tBasically it is an intuitive result but at the time when real numbers were not known or not rigorously defined it was a different story! In fact, it is simply enough complete any set by the real numbers to get a complete space. Moreover, some mathematicians define the set of real number saying that it is the set for which every Cauchy sequence converges...\n\t\n\t\\textbf{Definition (naive \\#\\mydef):} Ab \"\\NewTerm{accumulation point}\\index{accumulation point}\" or \"\\NewTerm{cluster point}\\index{cluster point}\" is a point which we can approach as much as we want thanks to elements of a given set $X$ (we will approach it for example with a sequence). However, this accumulation point can be both inside and outside of $X$ (all items within $X$ are obviously limit points). A good image is to see a series that approach this accumulation point and define circles around it that are becoming smaller and smaller containing elements of the sequence.\n\t\n\tWe can imagine as an example a sequence defined by the set $X$ of rational numbers $\\mathbb{Q}$ which tends to an irrational or to a transcendental number (these two points being elements not belonging to the set of rational $\\mathbb{Q}$). So in this case, the accumulation point is outside $X$ (the set of rational $\\mathbb{Q}$). By cons, any accumulation point that would be a rational number for a sequence of rational number will necessarily ... in $X$ (that is to say $\\mathbb{Q}$).\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tWith respect to the usual Euclidean topology, the sequence of rational numbers:\n\t\n\thas no limit (i.e. does not converge) when $n\\rightarrow \\pm \\infty$, but has two accumulation points (which are considered limit points here), that are $-1$ and $+1$:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.43]{img/computing/accumulation_point.jpg}\n\t\\end{figure}\n\t\\end{tcolorbox}\n\tTherefore, comes the following definition (for more details see the section Topology):\n\t\n\t\\textbf{Definition (formal \\#\\mydef):} Given $X \\subseteq \\mathbb{R}^n$. We say that $x\\in \\mathbb{R}^n$ is an \"\\NewTerm{accumulation point}\\index{accumulation point}\" to $X$ if for all ball $\\mathcal{B}(x,r)$ of radius $r$ center on $x$ we have (for more details see the section Topology):\n\t\n\tThe set of all accumulation points (of a sequence) to $X$ is the \"\\NewTerm{limit set}\\index{limit set}\" of $X$ and denoted by $\\bar{X}$. We have obviously (it suffice to conceptualize it in an abstract way for all possible ball) $X \\subseteq \\bar{X}$.\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tLet us consider the interval $]0,1]$ with the ball $B (0,1)$. The intersection between the ball and the interval is not zero, we can say that $0$ is an accumulation point! But now let us take a sequence $1 / n$ for example in the interval $]0,1]$. This sequence tends to zero but $0$ is not in interval. It is a good example of $X \\subseteq \\bar{X}$.\n\t\\end{tcolorbox}\n\tWe can therefore make the proposition:\n\t\\begin{theorem}\n\tLet us prove now that $x\\in \\mathbb{R}^n$ is adherent to $X$ if and only if there is a sequence $\\left(u_n\\right)_{\\mathbb{N}}$ in $X$ converging to $x$ (note that the previous example shows that $x$ is not necessarily in $X$).\n\t\n\tIn fact, we will instead prove (if we can say it is a proof..) that if we choose an accumulation point $x$ then we can always find a sequence in$ $X converging to $x$.\n\t\\end{theorem}\n\t\\begin{dem}\n\tIf $x\\in \\mathbb{R}^n$ is adherent to $X$ then let us consider the following concentric balls $B\\left(x,\\dfrac{1}{n}\\right)$ with $n\\geq 1$ such as:\n\t\n\tand then there are always elements $u_n$ that satisfy:\n\t\n\twith whom we can create a sequence by the infinity of existing sequences.\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\t\n\t\\textbf{Definition (\\#\\mydef):} We say that $X\\subseteq \\mathbb{R}^n$ is a \"closed space\" if $X=\\bar{X}$.\n\t\n\tFrom the previous proposals it follows that in any closed space $F$, a sequence $(x_n)_{\\mathbb{N}}$ that converges has its limit in $F$.\n\t\n\tWe consider as if trivial that if $(F_i)_I$ is a family of closed indexed spaces on any set $I$, then $\\bigcap_I F_i$ is closed.\n\t\n\t\\textbf{Definition (\\#\\mydef):} $X\\subseteq \\mathbb{R}^n$ is a \"\\NewTerm{compact space}\\index{compact space}\" if $X$ is closed and bounded.\n\t\n\tThe following theorem gives a characterization of the compact from the sequences:\n\t\n\t\\begin{theorem}\n\t$X\\subseteq \\mathbb{R}^n$ is compact if and only if any sequence $(x_n)_\\mathbb{N}$ of $X$ possess a sub-sequence that converges in $X$.\n\t\\end{theorem}\n\t\\begin{dem}\n\tFirst let us prove that X is closed:\n\t\n\tIf $X$ is compact and $(x_n)_\\mathbb{N}$ is a sequence of $X$ then by the Bolzano-Weierstrass theorem, $(x_n)_\\mathbb{N}$  has a convergent subsequence of limit $x\\in \\mathbb{R}^n$. But since $X$ is closed, we have $x\\in X$. Conversely, let us assume that any sequence $(x_n)_\\mathbb{N}$  of $X$ has a subsequence which converges in $X$. Then $X$ is closed because if $x\\in \\bar{X}$ there is a sequence $(x_n)_\\mathbb{N}$ of $X$ which tends to $x$. By assumption, $(x_n)_\\mathbb{N}$ has a subsequence that converges $y\\in X$. The sequence $(x_n)_\\mathbb{N}$ being convergent all the sub-sequences converge to the same value, therefore $x=y\\in X$ (is this not great?!!). Thus $X=\\bar{X}$ that is to say $X$ is closed!\n\t\n\tLet us now prove that $X$ is bounded:\n\t\n\tLet us suppose the opposite. So there exists a sequence $(x_n)_\\mathbb{N}$ of $X$ such that $||x_n||\\geq n$. But in this case, no subsequence of $(x_n)_\\mathbb{N}$ is convergent, which is a contradiction! So $X$ is bounded. Finally, $X$ is compact!!!\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\tA property of compacts is that if we consider $(A_n)_\\mathbb{N}$ a decreasing sequence of non-empty compacts, that is to say $A_{n+1}\\subseteq A_n$, then $\\bigcap_{\\in \\mathbb{N}} A_n$ is a non-empty compact. We will pass trough the proof that is relatively trivial by the definition of the concept of Adherence Set that oblige that compacts are by construction non-empty...!\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tWe obtain the Cantor set $C$ as follows:\n\tWe begin by considering the closed bounded interval $C_0=[0,1]$ of $\\mathbb{R}$ which is therefore a compact space (bounded and closed set ). We split $C_0$ into three equal parts and we remove the middle interval. This gives us all the set:\n\t\n\twhich can be also considered also as the application of a contracting scaling factor of $1/3$ on the closed bounded interval of departure of which we translate the center of homothety.\\\\\n\t\n\tWe start again with the two intervals $[0,1/3],[2/3,1]$ for:\n\t\n\tdisjoint union of $4$ intervals. And so on... So we get a decreasing sequence $C_n$ of compact. We define:\n\t\n\tThanks to the previous proposal, we know that $C$ is not empty and is compact which shows that the compacts are not all \"trivial\" as intervals. The Cantor set (because he had played by doing the drawing below starting from the bottom) is an example of  (compact) fractal:\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/cantor_set_maple.jpg}\n\t\t\\caption{Cantor set with Maple 4.00b}\n\t\\end{figure}\n\tthat is possible to get with the following Maple 4.00b code:\\\\\n\t\n\t\\texttt{\n\t>with(plots):\\\\\n\tline := proc(a:: list, b:: list)\\\\\n\tlocal plotoptionen, n;\\\\\n\tif nargs > 2 then\\\\\n\tplotoptionen := seq(args[n], n=3 .. nargs)\\\\\n\telse \\\\\n\tplotoptionen := NULL\\\\\n\tfi;\\\\\n\tplot([a, b], style=line, plotoptionen);\\\\\n\tend:\\\\\\\\\n\tcree\\_segment := (a,b,h) -> line([a,h],[b,h],color=black): \\\\\n\tf1:=x->x/3: f2:=x->(x+2)/3:\\\\\\\\\n\tf := s -> s union map(f1, s) union map(f2, s):\\\\\\\\\n\tsequence\\_de\\_segments := proc(l,h) \\\\\n\tlocal accu, i;\\\\\n\taccu := NULL;\\\\\n\tfor i to nops(l) by 2 do\\\\\n\taccu := accu,cree\\_segment(l[i], l[i+1], h) od;\\\\\n\taccu\\\\\n\tend:\n\t}\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\texttt{\n\t>Cantor:= proc(n) local s, i;\\\\\n\t>option remember;\\\\\n\t>s:=sequence\\_de\\_segments([0,1], 1);\\\\\n\t>for i from 1 to n do\\\\\n\t>s:=sequence\\_de\\_segments(sort([op((f@@i)({0,1}))]), (1-i/n)), \n\t>s;\\\\\n\t>od;\\\\\n\t>display({s}union{seq(textplot([[0,(i+1/2)/n, '0'], [1, (i+1/2)/n, '1']] \\\\\n\t), i=0 .. n)}, color=blue,axes=NONE,thickness=7)\\\\\n\t>end:\\\\\\\\\n\t>Cantor(7);\n\t}\\\\\n\t\n\tIt is very interesting to notice that we converges to the Cantor fractal (in terms of geometry but also in term of values!) whatever the chosen starting compact we start from (the closed bounded interval) and also ... whatever the chosen contractor factor!\\\\\n\t\n\tBenoît Mandelbrot also observed this type of self similar structure in the analysis of electrical signals transmitted at his (junior) time when working for IBM on copper cables (IBM had transmission information loss problems).\n\t\\end{tcolorbox}\n\tNow let us look for finish how behave compactis vis-à-vis continuous applications (we need this to prove how to determine the distance from a point to a set which we will need absolutely after to determine the properties of the Hausdorff distance).\n\t\n\tLet us recall (\\SeeChapter{see section Topology}) that an application $f:X \\mapsto \\mathbb{R}^m$ whatever $X \\subseteq \\mathbb{R}^n$  is continuous on a point $x\\in X$ if:\n\t\n\tThis reflects the fact that for $y$ close enough to $x$, $f (y)$ is arbitrarily close to $f (x)$. We also say that $f$ is continuous on $X$ if it is continuous at each point of $X$.\n\t\\begin{theorem}\n\tGiven $f:X\\mapsto \\mathbb{R}^m$ a continuous application on $x\\in X$ and $(x_n)_\\mathbb{N}$ a sequence of $X$ with:\n\t\n\tThen the sequence $f(x_n)$ converges and (this proposal is very important!):\n\t\n\tIn other words, if we use as a set of starting values of a convergent sequence, then the function that take as input the values of this sequence  will converge too!\n\t\\end{theorem}\n\t\\begin{dem}\n\tGiven $\\varepsilon >0$. $f$ is continuous on $x$, so there exists $\\delta>0$ such that:\n\t\n\tThe sequence $(x_n)_\\mathbb{N}$ tends to $x$ therefore it exists $N\\in \\mathbb{N}$ such that:\n\t\n\tIf follows that $n\\geq N$, we have:\n\t\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\tIf we now consider a compact $X\\subseteq \\mathbb{R}^n$ and $f:X\\mapsto \\mathbb{R}^n$ a continuous application. The application $f(X)$ is compact. In particular $\\sup (f)$ and $\\inf (f)$ will be reached by definition and  by construction of a compact (closed and bounded set) which is equal to its adherence.\n\t\\begin{theorem}\n\t\tIn other words, a continuous real-valued function on a compact always reaches its supremum or infimum.\n\t\\end{theorem}\n\t\\begin{dem}\n\t\\begin{itemize}\n\t\t\\item Let us prove that $f (X)$ is closed.\n\n\t\tIndeed, given $f(x_n)$ a sequence that tends to $y\\in \\overline{f(X)}$ (we take theadherence to hope to prove that it is equal to the set itself) then $X$ being compact, then $(x_n)_\\mathbb{N}$ has a convergent subsequence $(x_{n_i})_{i\\in \\mathbb{N}}$.\n\t\tLet us put:\n\t\t\n\t\tThe function $f$ is continuoous, therefore:\n\t\t\n\t\tBut as:\n\t\t\n\t\twe have:\n\t\t\n\t\tThis prove that:\n\t\t\n\t\tand therefore that $f(X)$ is closed.\n\t\n\t\\item Let us now prove that $f (X)$ is bounded.\n\n\t\tFor this let us suppose the contrary. There is therefore a sequence $f(x_n)$ such that:\n\t\t\n\t\tfor every natural integer $n$ (precisely because it is assumed unbounded). Given $(x_{n_i})_{i\\in \\mathbb{N}}$ a convergent subsequence of $(x_n)_\\mathbb{N}$ with:\n\t\t\n\t\tThen:\n\t\t\n\t\tand it follows:\n\t\t\n\t\tbut this is in contradiction with:\n\t\t\n\t\tTherefore $f(X)$ is bounded. Then $f(X)$ being closed is bounded and therefore is compact.\n\t\\end{itemize}\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\tNow let apply this result (because this is what interests us in fractal spaces) to calculate the distance from a point to a set:\n\t\\begin{theorem}\n\tGiven $x\\in \\mathbb{R}^n$, the application $f:\\mathbb{R}^n \\mapsto \\mathbb{R}$ defined by $f (y) = d (x, y)$ is continuous.\n\t\\end{theorem}\n\t\\begin{dem}\n\tFor $(y,z)\\in\\mathbb{R}^2$, the triangle inequality gives us:\n\t\n\tBy changing the roles of $y, z$ we get:\n\t\n\tand therefore:\n\t\n\tTherefore for a given $\\varepsilon >0$, $d(z,y)\\leq \\varepsilon$ implies:\n\t\n\tThat is to say:\n\t\n\tand $f$ is therefore continuous on $y$.\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\\textbf{Definition (\\#\\mydef):} For $x\\in \\mathbb{R}^n$ and $A\\subseteq \\mathbb{R}^n$ we define the distance $x$ to $A$ as being the value:\n\t\n\t\\begin{theorem}\n\tIf $x\\in A$ then $d(x,A)=0$ (should me almost trivial). The reciprocal is not true. Indeed in the case $x=0$ and $A=]0,1]$ we have indeed $d(x,A)=0$ but $x \\in A$. So we have the following important proposal:\n\t\n\t\\end{theorem}\n\t\\begin{dem}\n\tThe fact that $d(x,A)=0$ implies the existence of a sequence $(a_n)_{\\mathbb{N}}$ of elements of $A$ such that:\n\t\n\twhich means\n\t\n\ttherefore $x\\in \\bar{A}$ (see previous developments).\n\n\tConversely, if $x\\in \\bar{A}$ then for every $\\varepsilon>0$ there exists $a\\in A$ such as $d(x,a)\\leq \\varepsilon$. But $d(x,A)\\leq d(x,a)\\leq \\varepsilon$. Thus for any $\\varepsilon>0$, $d(x,A)\\leq \\varepsilon$. That is to say:\n\t\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\tIn general the distance from $x$ to $A$ is not reached. That is to say that there is no $a\\in A$ such that $d(x,A)=d(x,a)$. To check this, it is sufficient to consider the example $x=-1$ and $A=]0,1]$. We have in this example $d(x,A)=1$ but for any $a\\in A$, $d(x,a)>1$. If $A$ is compact, the situation is obviously different according to the following proposal (the most important for the Hausdorff distance in our point of view):\t\n\t\\begin{theorem}\n\t\tIf $A\\subseteq \\mathbb{R}^n$ is compact, there exist $a\\in A$ such that $d(x,A)=d(x,a)$. Therefore:\n\t\t\n\t\\end{theorem}\n\t\\begin{dem}\n\tThe application $f:A\\mapsto \\mathbb{R}$ defined by $f(a)=d(x,a)$ is continuous as previously proved. Therefore $f(A)$ is compact (see a previous proposal). Thus, $f$ reaches its bounds, that is to say, there is $a\\int A$ such that $f (a) =\\inf(f (A))$. Therefore:\n\t\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThis previous proposition does not say that $a$ is unique, in general in fact it is not!\n\t\\end{tcolorbox}\n\t\n\t\\subsubsection{Fractals Metric Space}\n\tFractals are often perceived by people as pretty drawings on paper, but when we look in detail the geometry of fractal, we need a particular space to study them, much like the biologist who puts small worms on a wafer to observe the worms in detail to the microscope. We will do the same for our fractals by placing them in a place they like...\n\t\n\tThis place is likely to be a subspace of $\\mathbb{R}^2$ or  $\\mathbb{R}^3$, since in the end it will produce drawings... And to illustrate this we often will place ourselves in  $\\mathbb{R}^2$ (with the Euclidean metric), and unless otherwise stated, we always consider the case where $(X,d)$ is a complete metric space.\n\t\n\tLet us collect different items in order to construct this space:\n\t\n\t\\textbf{Definition (\\#\\mydef):} We define $\\mathcal{H}(X)$ as the space whose points are the compacts subsets of $X$ other than than $X$ itself. From now, we will name \"\\NewTerm{fractal}\\index{fractal}\" any element of $\\mathcal{H}(X)$.\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tIt is immediate that if $x,y\\in\\mathcal{H}$, then $x\\cup y\\in \\mathcal{H}$ but $x\\cap y$ is not necessarily in $\\mathcal{H}$. It is sufficient to see the figure below with the two compact sets of $\\mathbb{R}^2$ (closed and bounded therefore) below. There are therefore two points of $\\mathcal{H}$.. Their unition is still a compact, and therefore:\n\t\n\n\tBy cons, if the sets are disjoint (as here), $x\\cap y=\\varnothing$ and therefore $x$, $y$ are not a point of $\\mathcal{H}(\\mathbb{R}^2)$ (see previous theory).\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/fractal_compact_space.jpg}\n\t\t\\caption{Source: IFS and L-System V. Rezzonico, C. Hebeisen}\n\t\\end{figure}\n\t\\end{tcolorbox}\n\tAnother example involves taking the fractal Cantor ...\n\t\n\t\\textbf{Definition (\\#\\mydef):} Given $x\\in X$ and $B\\in\\mathcal{H}(X)$, we define the distance $d(x,B)$ of a point $x$ to a set $B$  by:\n\t\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\\textbf{R1.} This definition is quite general and applies to any non-empty subset of $X$, by replacing $\\min$ by $\\inf$. But in our specific case, we are interested in taking precisely $\\mathcal{H}(X)$ as a subspace.\\\\\n\t\n\t\\textbf{R2.} This distance is well defined (is exists) as $B$ is non-empty and compact.\\\\\n\t\n\t\\textbf{R3.} It is trivial to see that if this distance is zero, then $x\\in\\bar{B}$.\n\t\\end{tcolorbox}\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tIllustration in the case where $X=\\mathbb{R}^2$:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/distance_point_subspace.jpg}\n\t\t\\caption{Source: IFS and L-System V. Rezzonico, C. Hebeisen}\n\t\\end{figure}\n\t\\end{tcolorbox}\n\t\\textbf{Definition (\\#\\mydef):} Given $A,B\\in\\mathcal{H}(X)$. We define and denote the distance from $A$ to $B$ by:\n\t\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\\textbf{R1.} This definition is quite general and applies to any non-empty subset of $X$, by replacing $\\min$ by $\\inf$. But in our specific case, we are interested in taking precisely $\\mathcal{H}(X)$ as a subspace.\\\\\n\t\n\t\\textbf{R2.} We notice that this distance does not provide a $\\mathcal{H}(X)$ metric: indeed, $d(A,B)\\neq d(B,A)$ in general (take for example the Cantor fractal where some compact we have $A\\subset B$ with $A\\neq B$, then we have $d(A, B) = 0$ but but $d(B,A)>0$).\n\t\\end{tcolorbox}\n\t\\textbf{Definition (\\#\\mydef):} Given $A,B\\in\\mathcal{H}(X)$. We define and denote \"\\NewTerm{Hausdorff distance}\\index{Hausdorff distance}\" between two sets $A,B\\in \\mathcal{H}(X)$ by:\n\t\n\tThis time, by this definition, we have well a metric on $\\mathcal{H}(X)$.\n\n\tIndeed, let us check that the five properties of a distance are satisifed (\\SeeChapter{see section Topology}):\n\t\n\tGiven $A,B,C\\in \\mathcal{H}(X)$. Clearly we have without proof\\footnote{But let us know as always if you want we put the proofs} (symmetry, nullity and separation on the diagonal):\n\t\n\tMoreover, since $A$ and $B$ are compact, $h(A,B)=d(A,B)$ (see on of the previous proposals) for a given $a\\in A$ and a given $b\\in B$. But, since $d(a,b)>0$ by definition, we have (property of positivity) finally $h(A,B)>0$ such that $a\\in A$,$A\\notin B$:\n\t\n\tas $B$ is closed.\n\t\n\tFinally, since $h(A,B)=d(a,b)$ (see the extension of one of previous proposals), the triangle inequality is necessarily respected and then:\n\t\n\tSo $h$ is indeed a metric of $\\mathcal{X}$, which makes $(\\mathcal{H}(X),h)$ a metric space. This is a first step in the desired direction, we now have the tools to compare two sets belonging to $\\mathcal{X}(X)$ by the Hausdorff distance between them. If the two are not \"too different\", so intuitively that distance should be fairly small.\n\t\n\tIf we choose a strictly contracting function $f:X\\mapsto X$ of constant $\\lambda$ (\\SeeChapter{see section Topology}). Then, the application:\n\t\n\tdefined by:\n\t\n\tis by onstruction also strictly contracting of constant $\\lambda$.\n\t\n\tGiven $f_i:\\mathbb{R}^2\\mapsto \\mathbb{R}^n$, $i\\leq i\\leq k$ strictly contracting applications of contraction constant  $0\\leq \\lambda_i<1$. Then, there exists a unique compact $A\\in\\mathcal{H}(\\mathbb{R}^n)$ such that:\n\t\n\t($A$ is the unique fixe point of $T_{\\lambda_1,\\ldots,\\lambda_k}$) and for any compact $B$, we have:\n\t\n\twhere $T_{\\lambda_1,\\ldots,\\lambda_k}^m(B)$ is the $m$-th iteration of $B$ by $T_{\\lambda_1,\\ldots,\\lambda_k}$.\n\t\n\tThis result derives from the fixed-point theorem (\\SeeChapter{see section Sequences and Series}) applied to the space $\\mathcal{H}(\\mathbb{R}^n)$ that is complete.\n\n\tWith the same notation, we say that $f_1,\\ldots,f_k$ is an IFS (Iterated Function Systems) coding of the compact $A$. Thus the functions $f_1,\\ldots,f_k$ define the compact $A$. What is surprising, as we will see in the following examples, is that the $f_1,\\ldots,f_k$ are usually quite simple (as homotheties of the plan) while the compact $A$ is in many cases relatively or very \"complicated\" visually speaking.\n\n\tIf case $k=1$ is without interest, we would have $A=(x)$ where $x$ is the fixed point of $f_1$. With $k=2$ we already obtain nontrivial results.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tWhen the iterative contracting functions are all homotheties we speak then of \"\\NewTerm{Sierpinski's fractal}\\index{Sierpinski's fractal}\". Thus, the Cantor fractal  belongs to the family of Sierpinski's fractals.\n\t\\end{tcolorbox}\n\tA frequently used method for to generate IFS fractals (as it will be the case below with Maple 4.00b\\footnote{But if some readers have reproduced all the example below in C++ they are welcome to share their code}) is to consider a point in the plane $(x_n,y_n)$ on which we can without conditions or constraints apply an affine transformation to get a new point such that:\n\t\n\twhere $a$, $b$, $c$, $d$, $e$ and $f$ are any constants, and $(x_0,y_0)$ is given (chosen).\n\t\n\tWe can therefore consider an application $T$ that describes our transformation, and in matrix form we can write the previous system as follows:\n\t\n\tor even:\n\t\n\tSo in general, the vector $\\vec{b}$ above simply describes a translation, and the matrix $A$ is the composition of a rotations and a scaling (\\SeeChapter{see section Euclidean Geometry}). Computer programs (as it will be the case in the examples below), thus often require that the knowledge of the six parameters $a$, $b$, $c$, $d$, $e$ and $f$ that can for majority be equal to zero.\n\t\n\t\\pagebreak\n\t\\subsection{Fractals Visualization}\n\t\n\t\\subsubsection{Cantor's Fractal (Cantor Set)}\n\tLet us come back now on Cantor's Fractal but see now from the point of view of the application of two iterative contracting functions $f_1,f_2$ (thus corresponding to $k = 2$).\n\n\tSo we start form the following closed bounded set (then a compacit as it is bounded):\n\t\n\tTherefore: \n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/cantor_set_01.jpg}\n\t\t\\caption[]{Start set of Cantor's Fractal}\n\t\\end{figure}\n\tSo now by definition we split in three equal parts and we remove the middle interval. This gives us the set:\n\t\n\tTherefore:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[]{img/computing/cantor_set_03.jpg}\n\t\t\\caption{First iteration of Cantor's Fractal}\n\t\\end{figure}\n\tWe can see that $[0,1/3]$ can be obtained by the following homothety (scaling) application of factor $1/3$ centered at $(0,0)$:\n\t\n\tand that $[2/3,1]$ can be obtained by the following homothety (scaling) of factor $1/3$ centered at $(1,0)$:\n\t\n\tand so on, and we get as we already know (see Maple 4.00b code already given above):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/cantor_set_02.jpg}\n\t\t\\caption{Cantor attractor after $6$ iterations}\n\t\\end{figure}\n\tWhich corresponds using the formalism seen earlier to:\n\t\n\tThis process is continued ad infinitum, where the $n$-th set is\n\t\n\twith obviously $C_{0}=[0,1]$.\n\t\n\tBut let us see that it works with any compact of $\\mathbb{R}$ as a square for example with the following Maple 4.00b code  (we always show all the details of Maple 4.00b, because nothing says that readers have the software or that the software will still exist in 50 years for reproductibility purposes...).\n\t\n\tCaution!!! If the copy / paste of the book code in Maple 4.00b does not work, simply rewrite it directly in the Maple console.\n\t\n\t\\texttt{>transforme\\textunderscore point := proc(t, p)}\\\\\n\t\\texttt{   [t[1]*p[1]+t[2]*p[2]+t[5], t[3]*p[1]+t[4]*p[2]+t[6]]}\\\\\n  \t\\texttt{end:}\\\\\n\n  \t\\texttt{>IFSS := proc(n, liste\\textunderscore de\\textunderscore transformations,col)}\\\\\n  \t\\texttt{local i, j, k, s, seq\\textunderscore square:}\\\\\n     \\texttt{seq\\textunderscore square :=[[0,0],[1,0],[1,1],[0,1]];} \\\\\n     \\texttt{for j to n do}\\\\\n     \\texttt{   s := NULL;}\\\\   \n     \\texttt{   for i to nops(liste\\textunderscore de\\textunderscore transformations) do}\\\\\n        \\texttt{       {} {} {} s := s,}\\\\\n        \\texttt{      {} {} {} seq(transform\\textunderscore square(liste\\textunderscore de\\textunderscore transformations[i],}\\\\\n        \\texttt{      {} {} {} op(k, [seq\\textunderscore square])),}\\\\\n        \\texttt{      {} {} {} k=1 .. nops([seq\\textunderscore square]))}\\\\\n      \\texttt{   od;}\\\\\n      \\texttt{   seq\\textunderscore square := s}\\\\\n    \\texttt{od;}\\\\\n    \\texttt{plots[polygonplot]([seq\\textunderscore square], axes=none, color=col, scaling=constrained)}\\\\\n    \\texttt{end:}\\\\\n    \n\t\\texttt{>cantor:=[[evalf(1/3),0,0,evalf(1/3),0,0],[evalf(1/3),0,0,evalf(1/3), evalf(2/3),0]]:}\\\\\n\t\n\t\\texttt{>IFSS(1, cantor,blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/cantor_set_square_01.jpg}\n\t\t\\caption[]{First iteration on the Cantor set with squares}\n\t\\end{figure}\n\t\\texttt{>IFSS(2, cantor,blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/cantor_set_square_02.jpg}\n\t\t\\caption[]{Second iteration on the Cantor set with squares}\n\t\\end{figure}\n\t\\texttt{>IFSS(3, cantor,blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/cantor_set_square_03.jpg}\n\t\t\\caption[]{Third iteration on the Cantor set with squares}\n\t\\end{figure}\n\tetc.\n\t\n\tSo, whatever the starting set, the sequence of compact obtained by successive application of these two plane homotheties always converge (in the sense of the Hausdorff distance) to the same compact/attractor (assimilated to the fixed of the Fixed point theorem...) named Cantor's fractal or Cantor set (thus belonging to the family of Serpienski fractals). The latest figure above is a good approximation of this set.\n\t\n\tThe Cantor set being self-similar, consisting\nof $N=2$ congruent subsets, each when magnified by a factor of $M = 3$ yields the original set. Hence the fractal dimension (\\SeeChapter{see section Euclidean Geometry}) of the Cantor set is:\n\t\n\t\n\t\\subsubsection{Triangle Sierpinski Fractal}\n\tTo build the Sierpinski fractal (which can be found as curiosity sometimes on the seashell Cymbiola innexa REEVE), based on three iterative contracting functions $f_1,f_2,f_3$ (thus corresponding to $k = 3$), we assume for example three following points of $\\mathbb{R}^2$:\n\t\n\tWhich gives with Maple 4.00b:\n\t\n\tThe Sierkpinski Triangle consists of $3^n$ subsets with magnification factor $2^n$. So the fractal dimension is:\n\t\n\t\n\t\\texttt{>plots[polygonplot]( [[0, 0], [1, 0], [0.5, 1]],axes=none,color=black, scaling=constrained);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_set_01.jpg}\n\t\t\\caption[]{Start set of triangle Sierpinski fractal}\n\t\\end{figure}\n\tThis is a triangle, but we could start from any shape and we always arrive at the same result as we will see later.\n\t\n\tWe apply on each set a contracting function of factor $0.5$, this gives the triangle:\n\t\n\tand we denote that this homothety (scaling) of factor $0.5$ and center $(0,0)$ on the original triangle by:\n\t\n\tWe do now on this triangle a translation of $0.5$ in the direction of the $x$-axis, which gives the triangle:\n\t\n\twhich corresponds to a scaling factor of $0.5$ and center $(1.0)$ on the original triangle:\n\t\n\tWe now translate $[[0,0], [0.5,0], [0.25,0.5]]$ of $0.25$ along the $x$-axis and of $0.5$ according to the $y$-axis to have:\n\t\n\twhich corresponds to a scaling factor of $0.5$ of center $(0.5,0.75)$ on the original triangle:\n\t\n\tWith Maple 4.00b it now gives for the three triangles:\n\t\n\t\\texttt{>plots[polygonplot]([[[0,0],[0.5,0],[0.25,0.5]],[[0.5,0],[1,0],[.75,0.5]], [[0.25,0.5],[0.75,0.5],[0.5,1]]], axes=none,color=black, scaling=constrained);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_set_02.jpg}\n\t\t\\caption[]{First iteration on the Sierpinksi triangle}\n\t\\end{figure}\n\tand so on...:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_set_03.jpg}\n\t\t\\caption[]{Second iteration on the Sierpinksi triangle}\n\t\\end{figure}\n\tand so on...:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_set_04.jpg}\n\t\t\\caption[]{Third iteration on the Sierpinksi triangle}\n\t\\end{figure}\n\tand so on...:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_set_05.jpg}\n\t\t\\caption[]{Fourth iteration on the Sierpinksi triangle}\n\t\\end{figure}\n\tand so on (the triangles begins to be quite small to see a difference without zoom)...:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_set_06.jpg}\n\t\t\\caption[]{Sixth iteration on the Sierpinksi triangle}\n\t\\end{figure}\n\tWhich corresponds by taking the formalism seen previously:\n\t\n\tWe can make the same remark as when we have study the Cantor's Fractal: whatever the starting set, the sequence of compact obtained by successive application of these three plane homotheties always converge (in the sense of the Hausdorff distance) to the same compact/attractor (assimilated to the fixed of the Fixed point theorem...) named Sierpinski fractal. The latest figure above is a good approximation of this set.\n\t\n\tLet's see this with a Maple 4.00b code (once again if the copy/paste from the book in Maple 4.00b does not work, simply rewrite the code in the Maple console):\n\t\n\t\\texttt{>transforme\\textunderscore triangle := proc(t, triangle)}\\\\\t\n    \\texttt{   local i;}\\\\\n    \\texttt{   [seq(transforme\\textunderscore point(t, triangle[i]), i=1 .. 3)]}    \n\t\\texttt{end:}\\\\\n\n\t\\texttt{>IFS := proc(n, liste\\textunderscore de\\textunderscore transformations,col)}\\\\\n     \\texttt{local i, j, k, s, sequence\\textunderscore de\\textunderscore triangles:}\\\\\n     \\texttt{options `Copyright by Alain Schauber, 1996`;}\\\\\n     \\texttt{sequence\\textunderscore de\\textunderscore triangles := [[0, 0], [1, 0], [0.5, 1]];}\\\\\n     \\texttt{for j to n do}\\\\\n     \\texttt{   s := NULL;}\\\\   \n     \\texttt{   for i to nops(liste\\textunderscore de\\textunderscore transformations) do}\\\\\n        \\texttt{   {} {} {} s:= s,}\\\\\n        \\texttt{   {} {} {} seq(transforme\\textunderscore triangle(liste\\textunderscore de\\textunderscore transformations[i],}\\\\\n        \\texttt{   {} {} {} op(k, [sequence\\textunderscore de\\textunderscore triangles])),}\\\\\n        \\texttt{   {} {} {} k=1 .. nops([sequence\\textunderscore de\\textunderscore triangles]))}\\\\\n       \\texttt{   {} {} {} od;}\\\\       \n      \\texttt{   {} {} {} sequence\\textunderscore de\\textunderscore triangles := s}\\\\\n    \\texttt{od;}\\\\\n    \\texttt{plots[polygonplot]([sequence\\textunderscore de\\textunderscore triangles], axes=none, color=col, scaling=constrained)}\\\\\n  \t\\texttt{end:}\n  \t\n\t\\texttt{>triangle\\textunderscore de\\textunderscore  Sierpinski:=[[0.5,0,0,0.5,0,0],[0.5,0,0,0.5,0.5,0], [0.5,0,0,0.5,0.25,0.5]]:}\n\n\t\\texttt{>IFS(6, triangle\\textunderscore de\\textunderscore Sierpinski,blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_maple.jpg}\n\t\t\\caption{Sierpinski triangle attractor}\n\t\\end{figure}\n\tAnd this time we don't start from a triangle but from a square (IFS Square) with the following Maple 4.00b code:\n\t\n\t\\texttt{>transforme\\textunderscore square := proc(t, square)}\\\\\t\n    \\texttt{   local i;}\\\\\n    \\texttt{   [seq(transforme\\textunderscore point(t, square[i]), i=1 .. 4)]}    \n\t\\texttt{end:}\\\\\n\n\t\\texttt{>IFS := proc(n, liste\\textunderscore de\\textunderscore transformations,col)}\\\\\n     \\texttt{local i, j, k, s, seq\\textunderscore  square:}\\\\\n     \\texttt{seq\\textunderscore square := [[0, 0], [1, 0], [1, 1],[0, 1]];}\\\\\n     \\texttt{for j to n do}\\\\\n     \\texttt{   s := NULL;}\\\\   \n     \\texttt{   for i to nops(liste\\textunderscore de\\textunderscore transformations) do}\\\\\n        \\texttt{   {} {} {} s:= s,}\\\\\n        \\texttt{   {} {} {} seq(transform\\textunderscore square(liste\\textunderscore de\\textunderscore transformations[i],}\\\\\n        \\texttt{   {} {} {} op(k, [seq\\textunderscore square])),}\\\\\n        \\texttt{   {} {} {} k=1 .. nops([seq\\textunderscore square]))}\\\\\n       \\texttt{   {} {} {} od;}\\\\       \n      \\texttt{   {} {} {} seq\\textunderscore square := s}\\\\\n    \\texttt{od;}\\\\\n    \\texttt{plots[polygonplot]([seq\\textunderscore square], axes=none, color=col, scaling=constrained)}\\\\\n  \t\\texttt{end:}\n  \t  \t\n\t\\texttt{>square\\textunderscore  Sierpinski:=[[0.5,0,0,0.5,0,0],[0.5,0,0,0.5,0.5,0], [0.5,0,0,0.5,0.25,0.5]]:}\n\n\t\\texttt{>IFS(1, square\\textunderscore  Sierpinski,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_square_set_01.jpg}\n\t\t\\caption[]{First iteration on the Sierpinksi square}\n\t\\end{figure}\n\t\\texttt{>IFS(2, square\\textunderscore  Sierpinski,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_square_set_02.jpg}\n\t\t\\caption[]{Second iteration on the Sierpinksi square}\n\t\\end{figure}\n\t\\texttt{>IFS(3, square\\textunderscore  Sierpinski,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_square_set_03.jpg}\n\t\t\\caption[]{Third iteration on the Sierpinksi square}\n\t\\end{figure}\n\tand so on until...:\n\t\n\t\\texttt{>IFS(6, square\\textunderscore  Sierpinski,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_square_set_04.jpg}\n\t\t\\caption[]{Sixth iteration on the Sierpinksi square}\n\t\\end{figure}\n\tBasically, the Sierpinski fractal can obviously be also seen as a triangle to which the middle of the triangle is removed and where for each of the remaining triangles, we restart the process!\n\t\n\t\\subsubsection{Sierpinski carpet fractal}\n\tThe Sierpinski carpet is the attractor of eight contracting iterative functions of homothety of ratio $1/3$ centered at the vertices and sides of a square in which can be any put any plane geometric shape.\n\n\tThis time in $\\mathbb{R}^2$ we consider the eight homotheties ($h$):\n\t\n\tand we start for example from the four following points:\n\t\n\tthat corresponds to a filled square (but we can choose anything else!):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_carpet_set_01.jpg}\n\t\t\\caption[]{Start set of Sierpinski carpet fractal}\n\t\\end{figure}\n\tAfter application of the eight homotheties functions (we leave to the reader to do the calculations manually in the same we have already do it for the triangle), we get the following form of eight squares:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_carpet_set_02.jpg}\n\t\t\\caption[]{Second iteration of Sierpinski carpet fractal}\n\t\\end{figure}\n\tand applying again the eight homotheties (fortunately there are computers...):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_carpet_set_03.jpg}\n\t\t\\caption[]{Third iteration of Sierpinski carpet fractal}\n\t\\end{figure}\n\tand again:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_carpet_set_04.jpg}\n\t\t\\caption[]{Fourth iteration of Sierpinski carpet fractal}\n\t\\end{figure}\n\tetc.\n\t\n\tThe resulting fixed point (attractor) is obviously named the \"\\NewTerm{Sierpinski carpet}\\index{Sierpinski carpet}\" and this is the shape of the receiving antenna of the majority of our cell phones in the early 21st century.\n\n\tThe above figures can be obtained successively with the following Maple 4.00b code (if the copy/paste form the book in in Maple 4.00b does not work, simply rewrite the code in the Maple console):\n\t\n\t\\texttt{>transforme\\textunderscore point := proc(t, p)}\\\\\n      \t\\texttt{[t[1]*p[1]+t[2]*p[2]+t[5], t[3]*p[1]+t[4]*p[2]+t[6]]}\\\\\n\t\t\\texttt{end:}\n\n\t\\texttt{>transform\\textunderscore square := proc(t, square) }\\\\\n      \t\\texttt{local i;}\\\\\n     \t\\texttt{[seq(transforme\\textunderscore point(t, square[i]), i=1 .. 4)]}\\\\\n\t\t\\texttt{end:}\n\n\t\t\\texttt{>IFSS := proc(n, liste\\textunderscore de \\textunderscore transformations,col)}\\\\\n      \t\\texttt{local i, j, k, s, seq\\textunderscore square:}\\\\\n      \t\\texttt{seq\\textunderscore square :=[[0,0],[1,0],[1,1],[0,1]];}\\\\\n      \t\\texttt{for j to n do}\\\\\n      \t\\texttt{s := NULL;}\\\\\n      \t\\texttt{for i to nops(liste\\textunderscore de\\textunderscore transformations) do}\\\\\n         \t\\texttt{s := s,}\\\\\n         \t\\texttt{seq(transform\\textunderscore square(liste\\textunderscore de \\textunderscore transformations[i],}\\\\\n         \t\\texttt{op(k, [seq\\textunderscore square])),}\\\\\n         \t\\texttt{k=1 .. nops([seq\\textunderscore square]))}\\\\\n       \t\\texttt{od;}\\\\\n       \t\\texttt{seq\\textunderscore square := s }\\\\\n     \t\\texttt{od;}\\\\\n     \t\\texttt{plots[polygonplot]([seq\\textunderscore square], axes=none, color=col, scaling=constrained)}\\\\\n   \t\\texttt{end:}\n\n\t\t\\texttt{> dywan:= [[evalf(1/3),0,0,evalf(1/3),0,0],[evalf(1/3),0,0,evalf(1/3), evalf(1/3),0],[evalf(1/3),0,0,evalf(1/3),evalf(2/3),0],  [evalf(1/3),0,0,evalf(1/3),0,evalf(2/3)], [evalf(1/3),0,0,evalf(1/3),evalf(1/3), evalf(2/3)],[evalf(1/3),0,0,evalf(1/3), evalf(2/3),evalf(2/3)],\t[evalf(1/3),0,0,evalf(1/3),0,evalf(1/3)], [evalf(1/3),0,0,evalf(1/3),evalf(2/3),evalf(1/3)]]:}\\\\\n\n\t\\texttt{>IFSS(0, dywan, blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_carpet_set_maple_01.jpg}\n\t\t\\caption[]{Start set of Sierpinski carpet fractal}\n\t\\end{figure}\n\t\\texttt{>IFSS(1, dywan, blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_carpet_set_maple_02.jpg}\n\t\t\\caption[]{First iteration of Sierpinski carpet fractal}\n\t\\end{figure}\n\t\\texttt{>IFSS(2, dywan, blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_carpet_set_maple_03.jpg}\n\t\t\\caption[]{Second iteration of Sierpinski carpet fractal}\n\t\\end{figure}\n\t\\texttt{>IFSS(3, dywan, blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_carpet_set_maple_04.jpg}\n\t\t\\caption[]{Third iteration of Sierpinski carpet fractal}\n\t\\end{figure}\n\t\\texttt{>IFSS(4, dywan, blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sierpinski_carpet_set_maple_05.jpg}\n\t\t\\caption[]{Fourth iteration of Sierpinski carpet fractal}\n\t\\end{figure}\n\t\n\t\\pagebreak\n\t\\subsubsection{Fractal spirals}\n\tWe just saw two fractals of the Sierpinski's fractal family therefore based solely on contracting homotheties. Let us now see a fractal that combines rotation and scaling Contracting.\n\t\n\tIn $\\mathbb{R}^2$ we consider the two applications of homotheties ($h$) and rotations ($R$) as follows:\n\t\n\tWith a triangle and always with Maple 4.00b, this gives us (if the copy/paste form the book in in Maple 4.00b does not work, simply rewrite the code in the Maple console):\n\t\n\t\\texttt{>transforme\\textunderscore triangle := proc(t, triangle)}\\\\\n     \\texttt{local i;}\\\\\n     \\texttt{[seq(transforme\\textunderscore point(t, triangle[i]), i=1 .. 3)]}\\\\\n\t\\texttt{end:}\\\\\n\n\t\\texttt{>IFS := proc(n, liste\\textunderscore de\\textunderscore transformations,col)}\\\\\n     \\texttt{local i, j, k, s, sequence\\textunderscore de\\textunderscore triangles:}\\\\\n     \\texttt{options `Copyright by Alain Schauber, 1996`;}\\\\\n     \\texttt{sequence\\textunderscore de\\textunderscore triangles := [[0, 0], [1, 0], [0.5, 1]];}\\\\\n     \\texttt{for j to n do}\\\\\n     \\texttt{ s := NULL;}\\\\\n     \\texttt{for i to nops(liste\\textunderscore de\\textunderscore transformations) do}\\\\\n        \\texttt{s := s,}\\\\\n        \\texttt{seq(transforme\\textunderscore triangle(liste\\textunderscore de\\textunderscore transformations[i],}\\\\\n        \\texttt{op(k, [sequence\\textunderscore de\\textunderscore triangles])),}\\\\\n        \\texttt{k=1 .. nops([sequence\\textunderscore de\\textunderscore triangles]))}\\\\\n       \\texttt{od;}\\\\\n      \\texttt{sequence\\textunderscore de\\textunderscore triangles := s}\\\\\n     \\texttt{od;}\\\\\n    \\texttt{plots[polygonplot]([sequence\\textunderscore de\\textunderscore triangles], axes=none, color=col, scaling=constrained)}\\\\\n  \\texttt{end:}\n\n  \\texttt{>a:=evalf(5*Pi/6);b:=evalf(Pi/6);}\\\\\n  \\texttt{>c1x:=0.25;c1y:=0.5;c2x:=0.5;c2y:=0.5;}\\\\\n  \\texttt{>h1:=0.2;h2:=0.95;}\\\\\n  \\texttt{>spirale:=[[h1*cos(a),-h1*sin(a),h1*sin(a),h1*cos(a),(1-h1*cos(a))*c1x}\\\\\n  \\texttt{+h1*sin(a)*c1y,-h1*sin(a)*c1x+(1-h1*cos(a))*c1y],[h2*cos(b),-h2*sin(b),h2*sin(b),}\\\\\n  \\texttt{h2*cos(b),(1-h2*cos(b))*c2x+h2*sin(b)*c2y,-h2*sin(b)*c2x+(1-h2*cos(b))*c2y]]:}\\\\\n\n \t\\texttt{>IFS(1,spirale,blue);}\\\\\n \t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/spiral_fractal_set_01.jpg}\n\t\t\\caption[]{First iteration of spiral fractal}\n\t\\end{figure}\n\tand as the convergence is very slow, we will give the results by step of  $5$ iterations.\t\n\t\\texttt{>IFS(6,spirale,blue);}\\\\\n \t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/spiral_fractal_set_02.jpg}\n\t\t\\caption[]{Sixth iteration of spiral fractal}\n\t\\end{figure}\n\t\\texttt{>IFS(11,spirale,blue);}\\\\\n \t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/spiral_fractal_set_03.jpg}\n\t\t\\caption[]{Eleventh iteration of spiral fractal}\n\t\\end{figure}\n\t\\texttt{>IFS(16,spirale,blue);}\\\\\n \t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/spiral_fractal_set_04.jpg}\n\t\t\\caption[]{Sixteenth iteration of spiral fractal}\n\t\\end{figure}\n\t\n\t\n\t\\subsubsection{Von Koch fractal (Koch snowflake)} \n\tStill, in fractal obtained by contracting homotethies ($h$) and rotation ($R$) but to which we add now a translation ($T$), the Von Koch curve is a well known fractal, it can be obtained by the following applications (we already met this fractal in the section of Euclidean Geometry when we have introduced the concept of fractal dimension):\t\n\t\n\tHere is the corresponding Maple 4.00b code (if the copy/paste form the book in in Maple 4.00b does not work, simply rewrite the code in the Maple console):\n\t\n\t\\texttt{>koch := proc(p:: numeric)}\\\\\n\t\\texttt{local m, n, k, l, s, h, x, y, pts, t, i;}\\\\\n     \\texttt{h := 3\\string^(-p);}\\\\\n     \\texttt{pts := table([]): \\# [0, 0];}\\\\\n     \\texttt{pts[0]:=[0,0];}\\\\\n     \\texttt{x := 0; y := 0;}\\\\\n     \\texttt{for n from 0 to (4\\string^p) do}\\\\\n        \\texttt{m := n;}\\\\\n        \\texttt{s := 0;}\\\\\n       \\texttt{ for l from 0 to p-1 do}\\\\\n           \\texttt{t := irem(m, 4);}\\\\\n           \\texttt{m := iquo(m, 4);}\\\\\n           \\texttt{s := s+irem((t+1), 3) - 1}\\\\\n        \\texttt{od;  \\# end of for l}\\\\\n        \\texttt{x := evalhf(x+cos(Pi*s/3)*h);}\\\\\n        \\texttt{y := evalhf(y+sin(Pi*s/3)*h);}\\\\\n        \\texttt{pts[n+1] := [x, y];}\\\\\n     \\texttt{od;}\\\\\n    \\texttt{[seq(pts[i], i=0 .. n-1)];}\\\\\n  \\texttt{end:}\\\\\n\n\t\\texttt{>plot(koch(0), scaling=constrained, style=LINE, axes=NONE, color=blue,thickness=2);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/von_koch_set_01.jpg}\n\t\t\\caption[]{Start set of Von Koch fractal}\n\t\\end{figure}\n\t\\texttt{>plot(koch(1), scaling=constrained, style=LINE, axes=NONE, color=blue,thickness=2);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/von_koch_set_02.jpg}\n\t\t\\caption[]{First iteration of Von Koch fractal}\n\t\\end{figure}\n\t\\texttt{>plot(koch(2), scaling=constrained, style=LINE, axes=NONE, color=blue,thickness=2);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/von_koch_set_03.jpg}\n\t\t\\caption[]{Second iteration of Von Koch fractal}\n\t\\end{figure}\n\t\\texttt{>plot(koch(3), scaling=constrained, style=LINE, axes=NONE, color=blue,thickness=2);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/von_koch_set_04.jpg}\n\t\t\\caption[]{Third iteration of Von Koch fractal}\n\t\\end{figure}\n\tetc. etc. Until the following attractor:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/von_koch_set_05.jpg}\n\t\t\\caption[]{Fourth iteration of Von Koch fractal}\n\t\\end{figure}\n\t\n\tThe Koch snowflake (see figure below) is a variant of the Von Koch line and thab can be constructed by starting with an equilateral triangle, then recursively altering each line segment as follows:\n\t\\begin{enumerate}\n\t\t\\item Divide the line segment into three segments of equal length.\n\t\t\\item Draw an equilateral triangle that has the middle segment from step 1 as its base and points outward.\n\t\t\\item Remove the line segment that is the base of the triangle from step 2.\n\t\\end{enumerate}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/von_kock_snowflake.jpg}\n\t\t\\caption[]{Von Koch snowflake (source: Wikipedia)}\n\t\\end{figure}\n\tAfter each iteration, the number of sides of the Koch snowflake increases by a factor of $4$, so the number of sides after n iterations is given by:\n\t\n\tIf the original equilateral triangle has sides of length $s$, the length of each side of the snowflake after $n$ iterations is:\n\t\n\tthe perimeter of the snowflake after $n$ iterations is therefore of:\n\t\n\tThe Koch curve has an infinite length because the total length of the curve increases by one third with each iteration. Thas is to say:\n\t\n\tThe funny thing is that the area is finite... when the perimeter is infinite...\n\t\n\tIndeed, in each iteration a new triangle is added on each side of the previous iteration, so the number of new triangles added in iteration $n$ is:\n\t\n\tThe area of each new equilateral triangle added in an iteration is one ninth of the area of each equilateral  triangle added in the previous iteration, so the area of each equilateral  triangle added in iteration $n$ is:\n\t\n\twhere $a_0$ is the area of the original equilateral  triangle. The total new area added in iteration $n$ is therefore:\n\t\n\tThe total area of the snowflake after $n$ iterations is then obviously:\n\t\n\tCollapsing the geometric sum of the type $\\sum x^n$ using (\\SeeChapter{see section Sequences and Series}):\n\t\n\twe get:\n\t\n\tThe limit of the area is then immediate:\n\t\n\tSo the area of the Koch snowflake is $8/5$ of the area of the original triangle. \n\t\n\tWhat is so disturbing with Von Koch fractal is that we start from a line of finite length, to arrive at the end to a line of infinite length if we reiterate infinitly structure but it has a finished surface ... it's a \"pathological\" curve as the mathematicians say sometimes.\n\t\n\tThe Koch curve is legendary because it was used to Mandelbrot to write an article about the problem of measuring the length of the coasts of sea coasts (because the most the basic unit of measurement taken was small, more the perimeter ot the coast was great). He proposed to consider the coasts as fractals for which it is impossible to measure the perimeter but \"fractal tree\" or in other words: the fractal dimension.\n\t\n\tThe Koch Curve consists of $4^n$ subsets with magnification factor $3^n$. So the fractal dimension is:\n\t\n\t\n\t\\paragraph{Coastline paradox}\\mbox{}\\\\\\\\\n\tIt is now the right moment in our point of view to speak about the \"\\NewTerm{coastline paradox}\\index{coastline paradox}\" that is the counterintuitive observation that the coastline of a landmass does not have a well-defined length. This results from the fractal-like properties of coastlines. The first recorded observation of this phenomenon was by Lewis Fry Richardson and it was expanded by Benoit Mandelbrot.\n\n\tMore concretely, the length of the coastline depends on the method used to measure it. Since a landmass has features at all scales, from hundreds of kilometers in size to tiny fractions of a millimeter and below, there is no obvious size of the smallest feature that should be measured around, and hence no single well-defined perimeter to the landmass. Various approximations exist when specific assumptions are made about minimum feature size.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/coastline_paradox.jpg}\n\t\t\\caption{Coastline paradox (source: Wikipedia)}\n\t\\end{figure}\n\tThe length of \"true fractal\" therefore always diverges to infinity, as if one were to measure a coastline with infinite, or near-infinite resolution, the length of the infinitely smaller bends of the coastline would add up to infinity. However, this figure relies on the assumption that space can be subdivided indefinitely. The truth value of this assumption - which underlies Euclidean geometry and serves as a useful model in everyday measurement - is a matter of philosophical speculation, and may or may not reflect the changing realities of 'space' and 'distance' on the atomic level (approximately the scale of a nanometer). The Planck length, many orders of magnitude smaller than an atom, is proposed as the smallest measurable unit possible in the universe.\n\n\tIn reality, permanent features of the coastline of order of size $1$ cm or less do not exist, because of erosion and other action of the sea. In most places the minimum size is much larger than this. Thus the concept of an infinite fractal is not applicable to the coastline.\nFor practical considerations, an appropriate choice of minimum feature size is on the order of the units being used to measure. If a coastline is measured in kilometers, then small variations much smaller than one kilometer are easily ignored.\n\n\t\n\t\n\t\\subsubsection{Natural fractals}\n\tBesides the purely mathematical aspect of fractals, we can find, via heuristics, contracting applications for fractal shapes similar to that we can find in nature. Let us see some examples with Maple 4.00b always taking first for common basis of all fractals that follow, the following procedures (if the copy/paste form the book in in Maple 4.00b does not work, simply rewrite the code in the Maple console):\n\t\n\t\\texttt{>transforme\\textunderscore point := proc(t, p)}\\\\\n    \\texttt{[t[1]*p[1]+t[2]*p[2]+t[5], t[3]*p[1]+t[4]*p[2]+t[6]]}\\\\\n\t\\texttt{end:}\n\n\t\\texttt{>transforme\\textunderscore triangle := proc(t, triangle)}\\\\\n    \\texttt{local i;}\\\\\n    \\texttt{[seq(transforme\\textunderscore point(t, triangle[i]), i=1 .. 3)]}\\\\\n  \t\\texttt{end:}\n\n  \t\\texttt{>transform\\textunderscore square := proc(t, square)}\\\\\n    \\texttt{local i;}\\\\\n    \\texttt{[seq(transforme\\textunderscore point(t, square[i]), i=1 .. 4)]}\\\\\n\t\\texttt{end:}\n\n\t\\texttt{>IFS := proc(n, liste\\textunderscore de\\textunderscore transformations,col)}\\\\\n     \\texttt{local i, j, k, s, sequence\\textunderscore de\\textunderscore triangles:}\\\\\n     \\texttt{options `Copyright by Alain Schauber, 1996`;}\\\\\n     \\texttt{sequence\\textunderscore de\\textunderscore triangles := [[0, 0], [1, 0], [0.5, 1]];}\\\\\n     \\texttt{for j to n do}\\\\\n     \\texttt{s := NULL;}\\\\\n     \\texttt{for i to nops(liste\\textunderscore de\\textunderscore transformations) do}\\\\\n        \\texttt{s := s,}\\\\\n        \\texttt{seq(transforme\\textunderscore triangle(liste\\textunderscore de\\textunderscore transformations[i],}\\\\\n        \\texttt{op(k, [sequence\\textunderscore de\\textunderscore triangles])),}\\\\\n        \\texttt{k=1 .. nops([sequence\\textunderscore de\\textunderscore triangles]))}\\\\\n       \\texttt{od;}\\\\\n      \\texttt{sequence\\textunderscore de\\textunderscore triangles := s}\\\\\n     \\texttt{od;}\\\\\n    \\texttt{plots[polygonplot]([sequence\\textunderscore de\\textunderscore triangles], axes=none, color=col, scaling=constrained)}\\\\\n  \\texttt{end:}\n\n\t\\texttt{>IFSS := proc(n, liste\\textunderscore de\\textunderscore transformations,col)}\\\\\n     \\texttt{local i, j, k, s, seq\\textunderscore square:}\\\\\n     \\texttt{seq\\textunderscore square :=[[0,0],[1,0],[1,1],[0,1]];}\\\\\n     \\texttt{for j to n do}\\\\\n     \\texttt{s := NULL;}\\\\\n     \\texttt{for i to nops(liste\\textunderscore de\\textunderscore transformations) do}\\\\\n        \\texttt{s := s,}\\\\\n        \\texttt{seq(transform\\textunderscore square(liste\\textunderscore de\\textunderscore transformations[i],}\\\\\n        \\texttt{op(k, [seq\\textunderscore square])),}\\\\\n        \\texttt{k=1 .. nops([seq\\textunderscore square]))}\\\\\n      \\texttt{od;}\\\\\n      \\texttt{seq\\textunderscore square := s }\\\\\n    \\texttt{od;}\\\\\n   \\texttt{plots[polygonplot]([seq\\textunderscore square], axes=none, color=col, scaling=constrained)}\\\\\n  \\texttt{end:}\\\\\n\t\n\t\\paragraph{Branch}\\mbox{}\\\\\\\\\n\tWe start from:\n\t\n\t\\texttt{>rameau:=[[.387,.430,.430,-.387,.2560,.5220], }\\\\\n\t\\texttt{[.441,-.091,-.009,-.322,.4219,.5059], [-.468,.020,-.113,.015,.4,.4]]:}\n\n\tAnd we get:\n\n\t\\texttt{> IFSS(0,rameau,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/branch_set_01.jpg}\n\t\t\\caption[]{Start set for generic branch fractal}\n\t\\end{figure}\n\t\\texttt{> IFSS(1,rameau,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/branch_set_02.jpg}\n\t\t\\caption[]{First iteration set for generic branch fractal}\n\t\\end{figure}\n\t\\texttt{> IFSS(2,rameau,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/branch_set_03.jpg}\n\t\t\\caption[]{Second iteration set for generic branch fractal}\n\t\\end{figure}\n\t\\texttt{> IFSS(3,rameau,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/branch_set_04.jpg}\n\t\t\\caption[]{Third iteration set for generic branch fractal}\n\t\\end{figure}\n\t\\texttt{> IFSS(4,rameau,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/branch_set_05.jpg}\n\t\t\\caption[]{Fourth iteration set for generic branch fractal}\n\t\\end{figure}\n\t\\texttt{> IFSS(5,rameau,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/branch_set_06.jpg}\n\t\t\\caption[]{Fifth iteration set for generic branch fractal}\n\t\\end{figure}\n\t\\texttt{> IFSS(6,rameau,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/branch_set_07.jpg}\n\t\t\\caption[]{Sixth iteration set for generic branch fractal}\n\t\\end{figure}\n\t\n\t\\paragraph{Snowflake}\\mbox{}\\\\\\\\\n\tWe start from:\n\t\n\t\\texttt{>cristal:=[[.255,0,0,.255,.3726,.6714],[.255,0,0,.255,.1146,.2232], }\n\t\\texttt{[.255,0,0,.255,.6306,.2232],[.37,-.642,.642,.37,.6356,-.0061]]:}\n\n\tAnd we get:\n\t\n\t\\texttt{>IFSS(0, cristal,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/snowflake_set_01.jpg}\n\t\t\\caption[]{Start set for snowflake fractal}\n\t\\end{figure}\n\t\\texttt{> IFSS(1, cristal,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/snowflake_set_02.jpg}\n\t\t\\caption[]{First iteration set for snowflake fractal}\n\t\\end{figure}\n\t\\texttt{> IFSS(2, cristal,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/snowflake_set_03.jpg}\n\t\t\\caption[]{Second iteration set for snowflake fractal}\n\t\\end{figure}\n\t\\texttt{> IFSS(3, cristal,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/snowflake_set_04.jpg}\n\t\t\\caption[]{Third iteration set for snowflake fractal}\n\t\\end{figure}\n\t\\texttt{> IFSS(4, cristal,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/snowflake_set_05.jpg}\n\t\t\\caption[]{Fourth iteration set for snowflake fractal}\n\t\\end{figure}\n\t\\texttt{> IFSS(5, cristal,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/snowflake_set_06.jpg}\n\t\t\\caption[]{Fifth iteration set for snowflake fractal}\n\t\\end{figure}\n\t\\texttt{> IFSS(6, cristal,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/snowflake_set_07.jpg}\n\t\t\\caption[]{Sixth iteration set for snowflake fractal}\n\t\\end{figure}\n\t\\texttt{> IFSS(7, cristal,green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/snowflake_set_08.jpg}\n\t\t\\caption[]{Seventh iteration set for snowflake fractal}\n\t\\end{figure}\n\t\n\t\\pagebreak\n\t\\paragraph{Tree}\\mbox{}\\\\\\\\\n\tWe start from:\n\t\n\t\\texttt{>tree := [[-0.04, 0, -0.23, -0.65, -0.08, 0.26], [0.61, 0, 0, 0.31, 0.07, 2.5],}\n\t\\texttt{[0.65, 0.29, -0.3, 0.48, 0.54, 0.39], [0.64, -0.3, 0.16, 0.56, -0.56, 0.4]]:}\n\n\tAnd we get:\n\t\n\t\\texttt{>IFS(0, tree, green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/tree_set_01.jpg}\n\t\t\\caption[]{Start set for tree fractal}\n\t\\end{figure}\n\t\\texttt{> IFS(1, tree, green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/tree_set_02.jpg}\n\t\t\\caption[]{First iteration set for tree fractal}\n\t\\end{figure}\n\t\\texttt{> IFS(2, tree, green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/tree_set_03.jpg}\n\t\t\\caption[]{Second iteration set for tree fractal}\n\t\\end{figure}\n\t\\texttt{> IFS(3, tree, green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/tree_set_04.jpg}\n\t\t\\caption[]{Third iteration set for tree fractal}\n\t\\end{figure}\n\t\\texttt{> IFS(4, tree, green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/tree_set_05.jpg}\n\t\t\\caption[]{Fourth iteration set for tree fractal}\n\t\\end{figure}\n\t\\texttt{> IFS(5, tree, green);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/tree_set_06.jpg}\n\t\t\\caption[]{Fifth iteration set for tree fractal}\n\t\\end{figure}\n\t\n\t\\pagebreak\n\t\\paragraph{Fern}\\mbox{}\\\\\\\\\n\tWe start from:\n\t\n\t\\texttt{>fougere:=[[0,0,0,0.16,0,0],[0.2,-0.26,0.23,0.22,0,1.6],}\n\t\\texttt{[-0.15,0.28,0.26,0.24,0,0.44],[0.85,0.04,-0.04,0.85,0,1.6]]:}\n\n\tAnd we get:\n\t\n\t\\texttt{>IFS(0, fougere, blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/fern_set_01.jpg}\n\t\t\\caption[]{Start set for fern fractal}\n\t\\end{figure}\n\t\\texttt{>IFS(1, fougere, blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/fern_set_02.jpg}\n\t\t\\caption[]{First iteration set for fern fractal}\n\t\\end{figure}\n\t\\texttt{>IFS(2, fougere, blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/fern_set_03.jpg}\n\t\t\\caption[]{Second iteration set for fern fractal}\n\t\\end{figure}\n\t\\texttt{>IFS(3, fougere, blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/fern_set_04.jpg}\n\t\t\\caption[]{Third iteration set for fern fractal}\n\t\\end{figure}\n\t\\texttt{>IFS(4, fougere, blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/fern_set_05.jpg}\n\t\t\\caption[]{Fourth iteration set for fern fractal}\n\t\\end{figure}\n\t\\texttt{>IFS(5, fougere, blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/fern_set_06.jpg}\n\t\t\\caption[]{Fifth iteration set for fern fractal}\n\t\\end{figure}\n\t\\texttt{>IFS(6, fougere, blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/fern_set_07.jpg}\n\t\t\\caption[]{Sixth iteration set for fern fractal}\n\t\\end{figure}\n\t\\texttt{>IFS(7, fougere, blue);}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/fern_set_08.jpg}\n\t\t\\caption[]{Eighth iteration set for fern fractal}\n\t\\end{figure}\n\tetc. Unitl we get:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/fern_set_09.jpg}\n\t\t\\caption[]{Attractor set for fern fractal}\n\t\\end{figure}\n\tand we will stop here because the examples of IFS and natural fractals are uncountable...\n\t\n\t\\pagebreak\n\t\\subsection{Escape Time Algorithm Fractals}\n\tSeveral methods have been proposed to construct fractal images as we mentioned at the beginning of this section. The are generally three way of generating fractals that are well known:\n\t\\begin{itemize}\n\t\t\\item Iterated function systems (seen previously)\n\t\t\\item Escape time fractals (we will see now)\n\t\t\\item Random fractals\n\t\\end{itemize}\n\tSo we will now focus on the methods named \"\\NewTerm{escape time methods}\\index{escape time methods}\".\n\t\n\tFor this, we place ourselves in the complex plane $\\mathbb{C}$ consisting of the points $M (x, y)$ of affix:\n\t\n\tAfterwards we consider a complex sequence defined by:\n\t\n\tand:\n\t\n\tthe function $f$ being a complex continuous function. We will assumed that $f$ is build in such a way that is has a fixed point $x_0$, that is to say that there exists $x_0$ such as:\n\t\n\tIt is therefore simply the application of fixed-point theorem already mentioned several times before. Under some conditions on f and equation, we find that the following points does not diverge (which means it is not interested in points that converge but to those who do not diverge!). This method is the basis for the construction of Mandelbrot and Julia sets.\n\t\n\tBuilding a fractal image from such a set of defined sequences, is equivalent to study for each pair $(x, y)$ of the plane the behavior of the sequence itself. We then associates a color to each result (that is to say, each pair $(x, y)$) representing the \"speed\" of divergence of the sequence.\n\t\n\tTo study the convergence of a series, we look at his first $n$ elements, if we detect that the divergence conditions are satisfied then we can say that this sequence diverges, otherwise this result is potentially convergent. We notice that more $n$ is big, the more accurate are the results (but the computing time will be great).\n\t\n\tThe simplest algorithm for generating a representation of an escape time fractal (set) consist in repeating a calculation performed for each $x$, $y$ point in the plot area and based on the behavior of that calculation, a color is chosen for that pixel.\n\n\tThe $x$ and $y$ locations of each point are used as starting values in a repeating, or iterating calculation (described in detail below). The result of each iteration is used as the starting values for the next. The values are checked during each iteration to see whether they have reached a critical \"escape\" condition. If that condition is reached, the calculation is stopped, the pixel is drawn, and the next $x$, $y$ point is examined. For some starting values, escape occurs quickly, after only a small number of iterations. For starting values very close to but not in the set, it may take hundreds or thousands of iterations to escape. For values within the Mandelbrot set, escape will never occur. The programmer or user must choose how much iteration, or \"depth\", they wish to examine. The higher the maximal number of iterations, the more detail and subtlety emerge in the final image, but the longer time it will take to calculate the fractal image.\n\n\tEscape conditions can be simple or complex. Because no complex number with a real or imaginary part greater than $2$ can be part of the set, a common bailout is to escape when either coefficient exceeds$ $2. A more computationally complex method that detects escapes sooner, is to compute distance from the origin using the Pythagorean theorem, i.e., to determine the absolute value, or modulus, of the complex number. If this value exceeds $2$, the point has reached escape. More computationally intensive rendering variations include the Buddhabrot method, which finds escaping points and plots their iterated coordinates.\n\n\tThe color of each point represents how quickly the values reached the escape point. Often black is used to show values that fail to escape before the iteration limit, and gradually brighter colors are used for points that escape. This gives a visual representation of how many cycles were required before reaching the escape condition.\n\n\tTo render such an image, the region of the complex plane we are considering is subdivided into a certain number of pixels. To color any such pixel, let $c$  be the midpoint of that pixel. We now iterate the critical point under the chosen function, checking at each step whether the orbit point has modulus larger than $R$ the convergence radius. When this is the case, we know that $c$  does not belong to the escape time fractal, and we color our pixel according to the number of iterations used to find out. Otherwise, we keep iterating up to a fixed number of steps, after which we decide that our parameter is \"probably\" in the escape time fractal, or at least very close to it, and color the pixel black.\n\n\tIn pseudocode, this algorithm would look as follows. The algorithm does not use complex numbers and manually simulates complex-number operations using two real numbers, for those who do not have a complex data type. The program may be simplified if the programming language includes complex-data-type operations.\n\t\n\t\\begin{algorithm}[H]\n\t\\KwData{I,R}\n\t\\For{\\text{each pixel} $(P_x,P_y)$ \\text{on the screen}}{\n        $x_0 =$ scaled $x$ coordinate of pixel \\;\n        $y_0 =$ scaled $y$ coordinate of pixel \\;\n\t\t$x=0.0$\\;\n\t\t$y=0.0$\\;\n\t\titeration$=0$\\;\n\t\tmax\\textunderscore iteration$=I$\\;\n\t\t\\While{$x^2 + y^2 < R^2$  AND  $i <$ max\\textunderscore iteration}{\n\t\t\t$x=\\Re(z(x,y))+x_0$\\;\n\t\t\t$y=\\Im(z(x,y))+y_0$\\;\n\t\t\t$i:=i+1$\\;\n\t\t}\n\t\tcolor := palette[iteration]\\;\n\t}\n\t plot $(P_x,P_y,\\text{colors})$\\;\n\t \\caption{Escape Time Fractal pseudo-code algorithm}\n\t\\end{algorithm}\n\t\n\t\\subsubsection{Mandelbrot set}\n\tWe construct the Mandelbrot set through iterations in the complex plane (this is named also \"\\NewTerm{holomorphic dynamics}\\index{holomorphic dynamics}\"). The function is of the form:\n\t\n\twhere $c$ a constant parameter such that $c\\in\\mathbb{C}$ (so we double the argument of the initial complex number we squared its norm!).\n\t\n\tThe first term of the sequence is zero. So we have the following defined by:\n\t\n\tWhy do we start with $z_0=0$?: Because zero is the critical point of $z^2+c$, that is to say the point satisfying the extremum:\n\t\n\tFor each point of affix $x + \\mathrm{i}y$ of the plane, we study the above sequence for $c=x+\\mathrm{i}y$. If the sequence diverges, we say that the tested point does not belong to the Mandelbrot set, if the sequence converges, we say that the point belongs to the Mandelbrot set defined then by (the definition and name is due to Adrien Douady, in tribute to Benoit Mandelbrot):\n\t\n\t\n\tTo reproduce a basic representation of the Mandelbrot fractal, we associate to $c$ complex values of the plane. It is generally considered the portion of the complex plane having as real part, values between $-2.5$ and $1.5$, and as imaginary part, values between $-1.5$ and $1.5$. This portion of the complex plane is divided so to form a grid whose elements will be associated with values of $c$. For each value of $c$, we get a result that modules can converge (bounded sequence) or diverge (non-bounded sequence).\n\t\n\tIn practice, it is considered that sequence of modules converges if the first $30$ modules are less than $2$ ($R=2$ in the previous pseudo-code), that is to say $|z_{30}|\\leq 30$. When the sequence of the modules converges (bounded sequence), we color in black the grid point. After considering all points of the grid, we get a set of blackened points named: \"Mandelbrot set\" or \"Mandelbrot fractal\" as we already know and denoted by $\\mathcal{M}$. What constitutes a remarkably curious result!\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/elementary_mandelbrot_set_reprsentation.jpg}\n\t\t\\caption{Bichromic Mandelbrot Fractal}\n\t\\end{figure}\n\tWe can also color the points outside the Mandelbrot set using colors that depend on the number of terms calculated before obtaining a module greater than or equal to $2$. The Module points of the same color can be interpreted as points away at the same speed of the Mandelbrot set.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe list of $z_i$ generated by the iteration is named the \"\\NewTerm{orbit}\\index{orbit (fractal)}\" of $z_0$.\n\t\\end{tcolorbox}\n\tWe can also discover the Mandelbrot fractal in-deep using the following Maple 4.00b code derived from the earlier pseudo-code (available usually in high-school). The reader just have to copy the program below on a Maple worksheet and indicate instead of -$2 .. 1 .. 1.5 -1.5$ of the last line, the range of the real and imaginary parts of $c$ he wants to discover:\\\\\n\t\n\t \\texttt{>restart: with(plots):\\\\\n\t>couleur:=proc(a,b)\\\\\n\tlocal x,y,xi,yi,n;\\\\\n\tx:=a;\\\\\n\ty:=b;\\\\\n\tfor n from 0 to 30 while evalf(x\\string ^2+y\\string ^2) < 4 do;\\\\\n\t   xi:=evalf(x\\string ^2-y\\string ^2+a);\\\\\n\t   yi:=evalf(2*x*y+b);\\\\\n\t   x:=xi;\\\\\n\t   y:=yi;\\\\\n\tod;\\\\\n\tn\\\\\n\tend:}\n\t\n\tYou will therefore get the following result (the equivalent code for MATLAB and R are given in the companion books about MATLAB and R):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/mandelbrot_fractal_maple.jpg}\n\t\t\\caption{Mandelbrot Fractal with Maple 4.00b}\n\t\\end{figure}\n\tThe Mandelbrot set is self-similar in the vicinity of points named \"\\NewTerm{Misiurewicz points}\\index{Misiurewicz points}\":\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/mandelbrot_fractal_auto_similarity.jpg}\n\t\t\\caption{Self-Similarity of Mandelbrot Fractal}\n\t\\end{figure}\n\tIt seem also that we can prove (we still search the proof...) that the Mandelbrot fractal real axes can be put in correspondence with the logistic bifurcation diagram that we have study in the section of Population Dynamics such that:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/mandelbrot_fractal_logistic_bifurcation.jpg}\n\t\t\\caption{Mandelbrot-Logistic bifurcation correspondence (source: Wikipedia)}\n\t\\end{figure}\n\tThe functions are obviously both quadratic. In fact, the Mandelbrot Set can be recoded into to form logistic map (and vice versa).\n\t\n\tIndeed, as the Mandelbrot Fractal is obtained by iteration:\n\t\n\tand that we know that the logistic bifurcation is obtained by the iteration of:\n\t\n\tSo let us put in Mandelbrot function the (anticipated) change of variable such that $z_n$ be dependent of $x_n$ and $r$ but $c$ must as constant must also be only dependent of the constant $r$:\n\t\n\tThen:\n\t\n\t\n\t\\subsubsection{Julia set}\n\tThe Julia set is builded almost in the same way that the Mandelbrot set (since the Julia set is actually a subset of it after investigation!). In the Mandelbrot set, $c$ scans the plane. For the Julia set, $c$ is fixed during the computation of the image. To each $c$ corresponds a particular set that will be denoted $J(c)$. What varies this time is $z_0$, which takes the value of the point to test. It is therefore $z_0$ that scans the plan.\n\t\n\tA point of initial coordinates $(x_0, y_0)$ and affix and $x + \\mathrm{i}y$ belongs to $J(c)$ if and only if the sequence defined by:\n\t\n\tconverge (is bounded).\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.6]{img/computing/julia_set_making_of.jpg}\n\t\t\\caption{Making of of a Julia set}\n\t\\end{figure}\n\tIn fact, the Mandelbrot set is the set of points $c$ such that the Julia set of parameter $c$ is connex to, that is to say we can always found a $c$ such that when starting with $z_0$ in the Mandelbrot set is equivalent after a few iterations as starting with a fixed $z_0\\neq 0$ and a given $c$ (thus the Mandelbrot set generalizes all the Julia sets !!!). So the figure of the Mandelbrot set contains figures all the Julia sets, which is remarkable (but logic ...!):\n\t\n\tIf again we adapt the algorithm pseudo-code given earlier, we obtain to a given scale factor given the fractal shown below (obtained through the small Maple 4.00b code below and already used earlier for the Mandelbrot fractal):\n\t\n\t\\texttt{>restart; with(plots):\\\\\n\t>julia:= proc(c,x, y)local z, m;\\\\\n\tz:= evalf(x+y*I);\\\\\n\tfor m from 0 to 30 while abs(z) < 3 do\\\\\n\t   z:= z\\string^2 + c\\\\\n\t   od;\\\\\n\t   m\\\\\n\tend:\\\\\\\\\n\t>J:= proc(d)\\\\\n\tglobal phonyvar;\\\\\n\tphonyvar:= d;\\\\\n\t(x, y) -> julia(phonyvar, x, y)\\\\\n\tend:\\\\\\\\\n\t>plot3d(0, -2..2, -1.3..1.3, style=patchnogrid,orientation=[-90,0], grid=[270, 270],scaling=constrained, color=J(-1.25));\\\\}\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/julia_fractal_maple.jpg}\n\t\t\\caption{Julia Fractal with Maple 4.00b}\n\t\\end{figure}\n\tand to show that the Mandelbrot set contains all the Julia sets we have qualitatively:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/mandelbrot_family.jpg}\n\t\t\\caption{Illustration of \"fatherhood\" ... of the Mandelbrot set}\n\t\\end{figure}\n\tSo we must be able to write a single algorithm (see below) that achieves all of Julia fractals by simply selecting a good starting point as shown in the following figures (we can see on top right the \"Douady's Rabbit Fractal\" also named \"dragon fractal\":\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/julia_sets.jpg}\n\t\\end{figure}\n\tThat we get with the following Maple 4.00b  code:\n\t\n\t\\texttt{>couleur:=proc(a,b)\\\\\n\tlocal x,y,xi,yi,n;\\\\\n\tglobal reel,imaginaire;\\\\\n\tx:=a;\\\\\n\ty:=b;\\\\\n\tfor n from 0 to 100 while evalf(x\\string^2+y\\string^2)<4 do;\\\\\n\txi:=evalf(x\\string^2-y\\string^2+reel);\\\\\n\tyi:=evalf(2*x*y+imaginaire);\\\\\n\tx:=xi;\\\\\n\ty:=yi;\\\\\n\tod;\\\\\n\tn;\\\\\n\tend:\\\\\\\\\n\t>reel:=-0.181;\\\\\n\t>imaginaire:=-0.667;\\\\\\\\\n\t>plot3d(0,(-13/10)..(13/10),(-13/10)..(13/10),orientation=[-90,0], style=patchnogrid,scaling=constrained,axes=framed,numpoints=20000\n\t,color=couleur);\\\\}\n\t\n\t\\subsubsection{Newton set}\n\tNewton sets are also so named because they arise from the resolution of the problem looking for zeros of a function by the method of Newton (\\SeeChapter{see section Numerical Methods}).\n\n\tGiven $f$ a function with values in $\\mathbb{C}$ and differentiable in $\\mathbb{C}$ , we take $z_0$ in $\\mathbb{C}$ such that:\n\t\n\tThere are then two ways to proceed:\n\t\\begin{enumerate}\n\t\t\\item Either we focus on $|z_0-z_i|$ and then we do same as before.\n\n\t\t\\item Either we wonder to which zero $r_k$ the sequence converges and we focus on $|z_i-z_k|$.\n\t\\end{enumerate}\n\tIf again we translate our pseudo-code algorithm, into Maple language we obtain to a given scale factor the fractal shown below obtained with Maple 4.00b:\n\t\n\t\\texttt{>restart:\\\\\n\t>newton:= proc(x, y)\\\\\n\tlocal z, m;\\\\\n\tz:= evalf(x+y*I);\\\\\n\tfor m from 0 to 50 while abs(z\\string^3-1) >= 0.001 \\\\\tdo\\\\\n\tz:= z - (z\\string^3-1)/(3*z\\string^2)\\\\\n\tod;\\\\\n\tm\\\\\n\tend:\\\\\\\\\n\t>plot3d(0,-2..2,-1.5..1.5,orientation=[-90,0],grid=[250, 250], \t\\\\ style=patchnogrid,scaling=constrained,color=newton);\\\\}\n\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/newton_fractal.jpg}\n\t\t\\caption{Newton set fractal with Maple 4.00b}\n\t\\end{figure}\n\t\n\t\\begin{flushright}\n\t\\begin{tabular}{l c}\n\t\\circled{70} & \\pbox{20cm}{\\score{3}{5} \\\\ {\\tiny 20 votes,  66.00\\%}} \n\t\\end{tabular} \n\t\\end{flushright}\n\n\t%to make section start on odd page\n\t\\newpage\n\t\\thispagestyle{empty}\n\t\\mbox{}\n\t\\section{Logical Systems}\n\t\\lettrine[lines=4]{\\color{BrickRed}T}he reader familiar with the purpose of this book should not expect to see here any schemes of buttons, switches, timing diagrams or MIL standard wiring diagrams. We will remain in a purely formal framework of logical systems and their tools.\n\t\n\t\\textbf{Definitions (\\#\\mydef):}\n\t\\begin{enumerate}\n\t\t\\item[D1.] We speak of \"\\NewTerm{asynchronous logic model}\\index{asynchronous logic model}\" (commonly named \"\\NewTerm{sequential logic model}\\index{sequential logic model}\") when the outputs of a system depends on the chronological order in which the entries will succeed.\n\t\t\n\t\t\\item[D2.] We speak of \"\\NewTerm{combinatorial logic model}\\index{combinatorial logic model}\" when the outputs of a system depend only on the combination of the input variables.\n\t\\end{enumerate}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tWe differentiate the \"\\NewTerm{strict logic}\\index{strict logic}\" of \"\\NewTerm{fuzzy logic}\\index{fuzzy logic}\" that will both  be defined in the details later.\n\t\\end{tcolorbox}\n\t\n\t\\subsection{Strict Logic}\n\tConsider first a set which we will denote by $\\mathcal{B}$ with two elements (more formally denoted by $\\bot,\\top$).\n\t\n\t\\textbf{Definitions (\\#\\mydef):}\n\t\\begin{enumerate}\n\t\t\\item[D1.] A \"\\NewTerm{strict logic variable}\\index{strict logic variable}\" or \"\\NewTerm{boolean variable}\\index{Boolean variable}\" is an element of $\\mathcal{B}$ that has only two states $0$ and $1$ (as opposed to a fuzzy variable whose value can be \\underline{between} $0$ and $1$). It is represented by Latin uppercase letters or lowercase Latin letters (depending on your choice).\n\t\t\n\t\t\\item[D2.] A multivariate \"\\NewTerm{logic function $F$}\\index{logic function}\" of $n$ variables applies $\\mathcal{B}^n$ in $\\mathcal{B}$ such that:\n\t\t\n\t\tIt combines to a $n$-tuple of logical variables $(b_0,b_1,...,b_{n-1})$ a value $F(b_0,b_1,...,b_{n-1})$.\n\t\t\n\t\t\\item[D3.] There are different ways of expressing a logic function (\"\\NewTerm{Boolean function}\\index{Boolean function}\"). A function of $n$ variables is fully described by stating the values of this function for the set (or the subset of definition) of the combinations of the $n$-tuple variables:\n\t\t\n\t\\end{enumerate}\n\tThis statement usually takes the form of a table with $n + 1$ columns and no more than $2^n$ lines, each line exposing a combination of variables and the corresponding value of the function. The following table gives the general form of a \"\\NewTerm{truth table}\\index{truth table}\" function of three variables completely defined through a function $F$ (we already saw some simple examples in the section of Proof Theory):\n\t\n\t\tThe elements of input of the systems will be considered as Boolean variables on which we can build a ring structure set, that by adding a particular axiom, we can bring to an algebra (in the computational sense and the set one!) commonly named \"\\NewTerm{Boolean algebra}\\index{Boolean algebra}\" as we will see now.\n\t\t\n\t\tSo Boolean algebra is an algebra on itself (with a ring structure as we will define it rigorously later) proposing to translate signals with a value of the type $0/1$ (assimilated to: True/False) in mathematical expressions. For this, we define each elementary signal by \"logical variables\" and their treatment by \"logical functions\". Methods (\"truth tables\") exists to define the operations that we want to achieve, and to transcribe the result into an algebraic expression. Thanks the rules we will see later, these expressions can be simplified. This will allow to represent with simple symbols a logic circuit capable of performing basic arithmetic operations, that is to say a circuit that design the core components (at logic level) regardless of the realization through transistors (physical level).\n\t\n\t\\subsubsection{Boolean Algebra}\n\tBoolean algebra (or \"Boolean ring\" to a given axiom...) is therefore a structure which is most often used in electronic (or microelectronics/optoelectronics) this is why some people name it sometimes \"\\NewTerm{Switching Algebra}\\index{Switching Algebra}\" or \"\\NewTerm{logic gates}\\index{logic gates}\". Therefore, a processor is composed of transistors for performing functions on digital signals. These transistors assembled together form components for performing simple functions. From these components it is possible to create circuits performing fairly complex operations. Boolean algebra (named after the English mathematician George Boole 1815-1864) is a means to create more or less easily such circuits.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIt would be better before you start reading this chapter, to read at least in diagonal the subsection about Logic in the section of Proof Theory and on algebraic structures in the section of Set Theory.\n\t\\end{tcolorbox}\n\tIt is necessary for a rigorous definition of a Boolean algebra to give it in terms of abstract algebra.\n\t\n\tReminder: A \"\\NewTerm{Boolean algebra}\\index{Boolean algebra}\" $(\\mathcal{B},\\vee,\\wedge)$ is a set containing two particular elements $\\bot,\\top$, (abstract forms the $0$ and $1$) and has two internal composition laws, $\\vee,\\wedge$ (AND and logical OR) and verifies the following axioms to form a ring structure such that $\\forall a,b,c\\in \\mathcal{B}$:\n\t\n\t\\begin{itemize}\n\t\t\\item[A1.] Associativity: $(a \\vee b)\\vee c=a \\vee (b \\vee c)$ and $(a \\wedge b)\\wedge c=a \\wedge (b\\wedge c)$\n\t\t\n\t\t\\item[A2.] Commutativity: $a \\vee b=b \\vee a$ and $a \\wedge b=b\\wedge a$\n\t\t\n\t\t\\item[A3.] Absorption: $a \\wedge (a \\vee b)=a$ and $a \\vee (a \\wedge b)=a$\n\t\t\n\t\t\\item[A4.] Distributivity: $(a \\vee b)\\wedge c=(a \\wedge c)\\vee b \\wedge c$ and $(a\\wedge b)\\vee c=(a \\vee c)\\wedge(b\\vee c)$\n\t\t\n\t\t\\item[A5.] Idempotence: $a \\vee a=a$ and $a\\wedge a=a$\n\t\t\n\t\t\\item[A6.] Completation (or inversion): $a$ has a complement (negation) denoted by $\\neg a$ or $\\bar{a}$ (NOT) such as: $a \\wedge \\neg a=\\top$ and $a \\vee \\neg a=\\bot$\n\t\\end{itemize}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe first four axioms establish a ring structure. The fifth axiom (idempotence) added to the first four defines the concept of \"Boolean algebra\".\n\t\\end{tcolorbox}\n\tStrictly speaking to form a Boolean algebra we required a symmetrical element (\\SeeChapter{see section Set Theory}) with one of the two fundamental operators and we cannot do this directly with the two previous operators previously defined. That is why the real operators of Boolean algebra are normally the $\\wedge$ (AND) and the $\\Delta$ (symmetric difference), denoted in Boolean algebra by the symbol $\\oplus$, the latter one being given by the logic operation:\n\t\n\tbut to simplify, in the early school grades, it is common that we do implicitly reference to it without going into details.\n\t\n\tIt follows that the binary set $(\\mathcal{B},0,1)$ is therefore relatively to the laws $\\vee,\\wedge$ an \"Abelian group\". (\\SeeChapter{see section Set Theory}) Therefore, $(\\mathcal{B},\\vee)$ being an Abelian group, the law  $\\wedge$  being associative and distributive with respect to $\\vee$, $(\\mathcal{B},\\vee,\\wedge)$ is therefore a \"commutative ring with unit\"  (\\SeeChapter{see section Set Theory}) since $\\mathcal{B}$ has a neutral element relatively to the law $\\vee$.\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\\textbf{R1.} Thus, the operations $\\vee,\\wedge$ admits each a neutral element such that the value $1$ is the neutral element of $\\wedge$ and $0$ the neutral element of $\\vee$.\\\\\n\t\n\t\\textbf{R2.} The two operations that we usually use to form a Boolean algebra are the \"inclusive OR\" rigorously denoted $\\vee$ but more frequently denoted by the addition sign \"$+$\" and and the \"inclusive AND\" rigorously denoted by $\\wedge$ but more frequently denotey by the multiplication sign \"$\\cdot$\".\n\t\\end{tcolorbox}\n\t\n\tThe preceding axioms may, however been proved from the \"\\NewTerm{axioms of the definition}\\index{axioms of the definition}\":\n\t\\begin{enumerate}\n\t\t\\item[A1.] Negation: $\\top\\neg\\bot$ and $\\bot\\neg \\top$\n\t\t\n\t\t\\item[A2.] Double complentation: $\\neg\\neg a=\\bar{\\bar{a}}=a$\n\t\t\n\t\t\\item[A3.] Neutral element 1: $\\top$ is the neutral element of $\\wedge$\n\t\t\\item[A4.] Neutral element 2: $\\perp$ is the neutral element of $\\vee$\n\t\t\n\t\t\\item[A5.] De Morgan theorem: $\\neg (a \\vee b)=\\neg a \\wedge \\neg b$ and $\\neg (a\\wedge b)=\\neg a \\vee \\neg b$\n\t\\end{enumerate}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tDe Morgan's theorem can be proved using a simple truth table or algebraically as we will see just a little further below.\n\t\\end{tcolorbox}\n\tIt thus follows the following dual expressions:\n\t\\begin{gather*}\n\t\\begin{rcases*}\n\t0\\cdot 0=0\\\\\n\t1+1=1\n\t\\end{rcases*} \\text{dual expression}\n\t\\end{gather*}\n\t\n\t\\begin{gather*}\n\t\\begin{rcases*}\n\t1\\cdot 0=0\\\\\n\t0+1=1\n\t\\end{rcases*} \\text{dual expression}\n\t\\end{gather*}\n\t\\begin{gather*}\n\t\\begin{rcases*}\n\t\\bar{0}=1\\\\\n\t\\bar{1}=0\n\t\\end{rcases*} \\text{dual expression}\n\t\\end{gather*}\n\tWe name these expressions \"\\NewTerm{dual expressions}\\index{dual expressions}\" because by replacing in one equation logic equation, the $0$ by the $1$, the $\\cdot$ by $+$ and inversely, by this same equation remains verified.\n\t\n\t\\begin{theorem}\n\tLet us see now what we call the \"\\NewTerm{constants theorem}\\index{constants theorem}\" that consists to prove that:\n\t\n\t\\end{theorem}\n\t\\begin{dem}\n\tThe proofis trivial (if necessary the reader can quickly do a truth table) as it comes from the same property of the concept of \"Boolean ring\" and the identity element $1$ relative to the $\\wedge$ and its neutral element $0$ relative to $\\vee$.\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\\begin{theorem}\n\tWe have:\n\t\n\t\\end{theorem}\n\t\\begin{dem}\n\tThe distributivity brings us to write:\n\t\n\tand applying the complementation:\n\t\n\tapplying commutativity:\n\t\n\tand finally by applying the theorem of constants:\n\t\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\tThis proof will allow us to prove  the famous \"\\NewTerm{consensus theorem}\\index{consensus theorem}\":\n\t\\begin{theorem}\n\tIn Boolean algebra, the consensus theorem or rule of consensus[1] is the identity:\n\t\n\t\\end{theorem}\n\t\\begin{dem}\n\tTo verify the concesus theorem relative to logical product:\n\t\n\twe can make use of a Venn diagram where we can see trivially that the therm term $ab$ is contained in the other two:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/consensus_theorem.jpg}\n\t\t\\caption{Venn diagram of the consensus theorem}\n\t\\end{figure}\n\tOr more formally with other notations:\n\t\n\tProceeding the request of a reader we can also build a truth table:\n\t\n\t\t\n\tProceeding also with a Venn diagram, the reader will see without problem that we also have:\n\t\n\t\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\\begin{theorem}\n\tAnd finally the very famous \"\\NewTerm{Shannon's theorem}\\index{Shannon's theorem}\" (not to be confused with the Shannon theorem in signal theory!):\n\t\n\t\\end{theorem}\n\t\\begin{dem}\n\tWe begin with the first relation:\n\t\n\tand for the second relation:\n\t\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\\begin{theorem}\n\tNow let us come back on the De Morgan theorems previously presented as axioms:\n\t\n\tThese two relations therefore express that the inverse (or opposite) of  product (or respectively the sum) of two variables is equal to the sum (respectively the product) of the inverse of these same variables.\n\t\\end{theorem}\n\t\\begin{dem}\n\tSuppose $\\overline{(a+b)}=\\bar{a}\\bar{b}$ is true. So under the relations $\\bar{a}+a=1$ and $\\bar{a}a=1$ (axiom of complementation) we must have:\n\t\n\tSo we need to prove that these relations are true:\n\t\n\tand:\n\t\n\tThe second De Morgan theorem can be proven in the same way (we can put the details on request).\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThese two theorems can be extended to as many variables as we want.\n\t\\end{tcolorbox}\n\t\\begin{corollary}\n\tAs immediate corollary we have:\n\t\\begin{itemize}\n\t\t\\item $ab=\\overline{\\bar{a}+\\bar{b}}$\n\t\t\\item $a+b=\\overline{\\bar{a}\\bar{b}}$\n\t\t\\item $ab=\\overline{\\overline{ab}}$\n\t\t\\item $a+b=\\overline{\\overline{a+b}}$\n\t\t\\item $\\overline{a+b+c+...}=\\bar{a}\\bar{b}\\bar{c}...$\n\t\t\\item $\\overline{abc+...}=\\bar{a}+\\bar{b}+\\bar{c}+...$\n\t\\end{itemize}\n\t\\end{corollary}\n\tThe logical expressions, as we have seen it until now thanks to the previous axioms, properties and theorems, can always be writtent into two different forms (by paling also with the negations $\\neg$):\n\t\\begin{enumerate}\n\t\t\\item Under the form of a sum of logical products, also named \"\\NewTerm{normal disjcontive form NDF}\\index{normal disjcontive form}\", such as for example:\n\t\t\n\t\tThe constitutive terms of this polynomial are in this example the monomials $\\bar{a}\\bar{c}d,\\bar{a}c\\bar{d}$. The variables or complementary variables of the monomials are the \"letters\": $\\bar{a},\\bar{c},d,c\\bar{d}$.\n\t\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\t\tIf each (all) of the product contains all the input variables in a direct or complementary form, then the form is named \"\\NewTerm{first canonical form}\\index{first canonical form}\" or \"\\NewTerm{disjonctive canonical form}\\index{disjonctive canonical form}\". Each of the product is therefore named the \"\\NewTerm{minterm}\\index{minterm}\".\\\\\n\t\t\n\t\tObviously if we consider that each term and its negation is equivalent to $0$ and $1$ if we have one variable, the first canonical form has two terms  ($2^1$), if we have two variables, the first canonical form has four terms ($2^n$) and if $n$ variables we have $2^n$ terms.\n\t\t\\end{tcolorbox}\n\t\t\n\t\t\\item In the form of a product of logical sum, also named \"\\NewTerm{normal conjunctive form NCF}\\index{normal conjunctive form}\":\n\t\t\n\t\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\t\tIf each (all) of the sums contains all the input variables in a direct or complementary form, the form is named \"\\NewTerm{second canonical form}\\index{second canonical form}\" or \"\\NewTerm{conjunctive canonical form}\\index{conjunctive canonical form}\". Each of the sum is therefore named the \"\\NewTerm{maxterm}\\index{maxterm}\".\\\\\n\t\t\n\t\tObviously if we consider that each term and it negation is equivalent to $0$ and $1$ if we have one variable, the second canonical form has two terms  ($2^1$), if we have two variables, the second canonical form has four terms ($2^n$) and if $n$ variables we have $2^n$ terms.\n\t\t\\end{tcolorbox}\n\t\tTherefore, in other words, a normal disjonctive form est either a litteral and its complementary (one letter) or a disjonction of formulas written as conjonction of litterals. A conjonctive form is either a litteral (one letter) and its complementary, or a conjonction of formulas written as disjonction of litterals.\n\t\\end{enumerate}\n\tThe simplification methods we will see later aim to minimize the number of letters of the expressions so as to reduce the number of inputs of our logic system logic and therefore also the number of its components.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe algebraic simplification of an expression is to transform it so as to minimize the number of letters by applying theorems proven previously.\n\t\\end{tcolorbox}\n\tTo simplify expressions (or identify them) a known technique is therefore to use the \"\\NewTerm{Karnaugh tables}\\index{Karnaugh tables}\" that we will see further below in details.\n\t\n\t\\subsubsection{Logical Functions}\n\tSo when we talk about Boolean algebra unless other indication, we refer to the three basic Boolean operations (AND, OR, NOT) and some other logic functions arising from them for which we have the following symbols as defined in circuit theory (MIL norm representation if no error...):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/engineering/logic_mil_gates.jpg}\n\t\t\\caption{Logic MIL Gates}\n\t\\end{figure}\n\tand their respective \"\\NewTerm{truth tables}\\index{truth tables}\":\n\t\n\t\n\t\n\tAll others known (common) \"logic functions\" can be composed of these two basic operators. Such that by definition (given with their standard definition in the first line and with their different algebraic forms under their respective truth table):\n\t\\begin{center}\n\t$\\neg (a \\wedge b)=\\overline{a\\cdot b}=\\bar{a}+\\bar{b}$\n\t\\end{center}\n\t\n\t\\begin{center}\n\t\t$\\neg (a \\vee b)=\\overline{a + b}=\\bar{a}\\cdot\\bar{b}$\n\t\\end{center}\n\t\n\t\\begin{center}\n\t\t$a\\oplus b=(a \\vee b)\\wedge \\neg(a \\wedge b)=(a+b)\\cdot \\overline{(a\\cdot b)}$\\\\\n\t\t$a\\oplus b=a\\wedge \\neg b+b\\wedge \\neg q=a\\cdot\\bar{b}+b\\cdot \\bar{a}$\\\\\n\t\t$a\\oplus b=\\neg(a\\wedge b+\\neg a\\wedge\\neg b)=\\overline{a\\cdot b+\\bar{a}\\cdot\\bar{b}}$\n\t\\end{center}\n\t\n\twhere $a$ and $b$ are, as you will have understood, variables (or \"bit\" of Binary Digit) that can arbitrarily take the binary values $0$ or $1$.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe $\\mathrm{XOR}$ logic function is often denoted in the literature by the operator $\\oplus$ and we will consider as obvious that the $\\mathrm{XOR}$ is also a group law and thus allows to construct an abelian commutative group. This property of the $\\mathrm{XOR}$ is particularly used in cryptography.\n\t\\end{tcolorbox}\n\tAll the tables above can be sum up in the following figure with the corresponding MIL circuit theory symbols:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.9]{img/computing/summary_boole_de_morgan.jpg}\n\t\t\\caption{Summary Boole Algebra}\n\t\\end{figure}\n\t\n\t\\pagebreak\n\t\\subsubsection{Karnaugh maps}\n\tThe \"\\NewTerm{Karnaugh map}\\index{Karnaugh map}\", also known as the \"\\NewTerm{K-map}\\index{K-map}\", is a method to simplify boolean algebra expressions. Maurice Karnaugh introduced it in 1953. The Karnaugh map reduces the need for extensive calculations by taking advantage of humans' pattern-recognition capability\\footnote{The reader can found easily on the Internet many K-map generators that simplifies expressions automatically!}. \n\t\n\tThe required boolean results are transferred from a truth table onto a two-dimensional grid where the cells are ordered in Gray code, and each cell position represents one combination of input conditions, while each cell value represents the corresponding output value. Optimal groups of $1$s or $0$s are identified, which represent the terms of a canonical form of the logic in the original truth table.[1] These terms can be used to write a minimal boolean expression representing the required logic.\n\t\n\tKarnaugh maps are used to simplify real-world logic requirements so that they can be implemented using a minimum number of physical logic gates. A sum-of-products expression can always be implemented using AND gates feeding into an OR gate, and a product-of-sums expression leads to OR gates feeding an AND gate. Karnaugh maps can also be used to simplify logic expressions in software design. Boolean conditions, as used for example in conditional statements, can get very complicated, which makes the code difficult to read and to maintain. Once minimized, canonical sum-of-products and product-of-sums expressions can be implemented directly using AND and OR logic operators.\n\t\n\tLet us consider for example the function:\n\t\n\t(in disjunctive normal form) and its respective truth table:\n\t\n\tThe Karnaugh map is defined by a representation like the one below following the \\texttt{karnaugh-map} package of \\LaTeX{} (as it does sadly not exist at this day any international norm on how to represent Karnaugh map):\n\t\n\t\\begin{center}\n\t\\begin{tikzpicture}[thick]\n\t\t\\karnaughmapcolorfield{2}{0}{teal!50}%\n\t\t\\karnaughmapcolorfield{2}{1}{violet!50}%\n\t\t\\karnaughmapcolorfield{2}{3}{red!50}%\n\t\t\\karnaughmap[omitnegated=false,binaryidx,omitzeros=false]{1011}\n\t\\end{tikzpicture}\n\t\\end{center}\n\t\n\tThe colored items are those that we need to keep. That is: $\\bar{a}\\bar{b}$, $\\bar{a}b$, $ab$.\n\t\n\tThe Karnaugh table of a logic function thus has as many cells as possible combinations of variables which compose it, ie four cells for a function with two variables, and $2^n$ cells for a function with $n$ variables. Each cell, which is at the intersection of a row and column of the Karnaugh table, has the state $0$ or $1$ that the function $z(a,b)$ takes for the corresponding logical product of the variables (minterms).\n\n\tIn the preceding example, however, we can see something interesting, the function $z(a,b)$, as we see very well, can be simplified in two ways:\n\t\n\tor also:\n\t\n\tThis possible simplification is always done with two adjacent minterms in the Karnaugh table such as for the first solution $z=b+\\bar{a}\\bar{b}$:\n\t\\begin{center}\n\t\\begin{tikzpicture}[thick]\n\t\t\\karnaughmapcolorfield{2}{0}{red!50}%\n\t\t\\karnaughmapcolorfield{2}{2}{red!50}%\n\t\t\\karnaughmap[omitnegated=false,binaryidx,omitzeros=false]{1011}\n\t\\end{tikzpicture}\n\t\\end{center}\n\t\n\tand for $z=ab+\\bar{a}$:\n\t\\begin{center}\n\t\\begin{tikzpicture}[thick]\n\t\t\\karnaughmapcolorfield{2}{2}{red!50}%\n\t\t\\karnaughmapcolorfield{2}{3}{red!50}%\n\t\t\\karnaughmap[omitnegated=false,binaryidx,omitzeros=false]{1011}\n\t\\end{tikzpicture}\n\t\\end{center}\n\t\n\tWe see that indeed the first grouping / simplification (horizontal) is done on the row $\\bar{a}$ and the second grouping / simplification (vertical) is done on column $b$ both results of the algebraic simplification of the function as following:\n\t\n\tand:\n\t\n\tSo we could make the hypothesize that the Karnaugh table has for properties:\n\t\\begin{enumerate}\n\t\t\\item[P1.] To give us the normal disjunctive form of a function.\n\n\t\t\\item[P2.] That all adjoining cells with a value of $1$ can be simplified in the respective symbol (letter) of their union\n\t\\end{enumerate}\n\tIt is therefore an extremely powerful tool (algorithm) for simplifying and determining logical functions.\n\n\tLet's look at an example with three variables!\n\t\n\tFirst we give the truth table that can help for a better understanding:\n\t\n\tand the corresponding Karnaugh map:\n\t\\begin{center}\n\t\\begin{tikzpicture}[thick]\n\t\t\\karnaughmap[omitnegated=false,binaryidx,omitzeros=false]{1111 0011}\n\t\\end{tikzpicture}\n\t\\end{center}\n\tThe normal disjonctive form is the given by all the celles that are equal to $1$:\n\t\n\tThis corresponds to the following colored Karnaugh map:\n\t\\begin{center}\n\t\\begin{tikzpicture}[thick]\n\t\t\\karnaughmapcolorfield{2}{0}{red!50}%\n\t\t\\karnaughmapcolorfield{2}{1}{red!50}%\n\t\t\\karnaughmapcolorfield{2}{2}{red!50}%\n\t\t\\karnaughmapcolorfield{2}{3}{red!50}%\n\t\t\\karnaughmapcolorfield{3}{6}{red!50}%\n\t\t\\karnaughmapcolorfield{3}{7}{red!50}%\n\t\t\\karnaughmap[omitnegated=false,binaryidx,omitzeros=false]{1111 0011}\n\t\\end{tikzpicture}\n\t\\end{center}\n\tWe see quickly that the previous normal disjonctive form can be simplified as:\n\t\n\tThat gives the following Karnaugh map:\n\t\\begin{center}\n\t\\begin{tikzpicture}[thick]\n\t\t\\karnaughmapcolorfield{2}{0}{teal!50}%\n\t\t\\karnaughmapcolorfield{2}{1}{teal!50}%\n\t\t\\karnaughmapcolorfield{2}{2}{teal!50}%\n\t\t\\karnaughmapcolorfield{2}{3}{teal!50}%\n\t\t\\karnaughmapcolorfield{3}{6}{violet!50}%\n\t\t\\karnaughmapcolorfield{3}{7}{violet!50}%\n\t\t\\karnaughmap[omitnegated=false,binaryidx,omitzeros=false]{1111 0011}\n\t\\end{tikzpicture}\n\t\\end{center}\n\t\n\tBut it is less obvious with a Karnaugh map to see that all previous relations can be simplified into (using binary addition rules):\n\t\n\tThat gives the following Karnaugh map:\n\t\\begin{center}\n\t\n\t\\end{center}\n\tAnd this latter result can be seen with the available Karnaugh map minimizer freeware that we can found nowadays on the Internet. For example the freeware Karnaugh Map Minimizer that give us for the previous example (we also see at the same time why it is boring - as always also in other field of engineering an science - that there are no ISO norm to standardize Karnaugh map representation):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/karnaugh_map_minimizer.jpg}\n\t\t\\caption{Karnaugh Map Minimizer 0.4}\n\t\\end{figure}\n\tA difficulty remains however sometimes with this technique: how to choose the best construction of the table (disposition of letters)?\n\n\tIn fact, there is a specific way of associating the Boolean algebra complement rule with what we named the \"Gray code\".\n\n\t\\textbf{Definition (\\#\\mydef):} The \"\\NewTerm{reflected binary code (RBC)}\\index{reflected binary code}\", also known as \"\\NewTerm{Gray code}\\index{Gray code}\" after Frank Gray, is a binary numeral system where two successive values differ in only one bit (binary digit). The reflected binary code was originally designed to prevent spurious output from electromechanical switches\\footnote{The problem with natural binary codes is that physical switches are not ideal: it is very unlikely that physical switches will change states exactly in synchrony. In the transition between the two states shown above, all three switches change state.} and is useful to optimally build Karnaugh maps.\n\n\tHere is an example of the Gray code for decimal $0$ to $15$ (the reader can notice that only one bit/switch at a time change at each row):\n\t\n\tUsing Gray code we can create optimal Karnaugh tables. The reason is simple, the Gray code changes only one bit at a time at each increment as we have just seen. In practice this means that for two consecutive values, $1$ and $2$ for example, one of the two variables will be the opposite of the other one.\n\t\n\tWe can see this very well with the following structures:\n\t\\begin{center}\n\t\\begin{tikzpicture}[thick]\n\t\t\\karnaughmap{4}\n\t\\end{tikzpicture}\n\t\\end{center}\n\tbut more especially with greater tables (the order of the cell is not obvious):\n\t\\begin{center}\n\t\\begin{tikzpicture}[thick]\n\t\t\\karnaughmap{8}\n\t\\end{tikzpicture}\n\t\\end{center}\n\tor:\n\t\\begin{center}\n\t\\begin{tikzpicture}[thick]\n\t\t\\karnaughmap{16}\n\t\\end{tikzpicture}\n\t\\end{center}\n\tor more explicitly for that latter (you can therefore compare with the above Gray code table with $4$ digits to understand from where the internal numbering comes from):\n\t\\begin{center}\n\t\\begin{tikzpicture}[thick]\n\t\t\\karnaughmap[defaultmap=16,binaryidx,omitnegated=false]{}\n\t\\end{tikzpicture}\n\t\\end{center}\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tGiven $01$ corresponding to $\\bar{b}a$ and $11$ corresponding to $ba$, the sum (disjunctive form) would give us:\n\t\n\t which is reduced by using the complementation rule directly to:\n\t\n\thence the advantage to represent them next to each other in a Karnaugh table.\n\t\\end{tcolorbox}\n\tAll this to say that when two formulas are found side by side in a Karnaugh map, we retain the similar elements only.\n\n\tThe rules are such that we can reduce therefore when (see previous concrete example):\n\t\\begin{itemize}\n\t\t\\item[R1.] Two $1$ are juxtaposed in the table (here the $\\bar{c}+c$ will be simplified in the disjunctive form):\n\t\t\\begin{center}\n\t\t\\begin{tikzpicture}[thick]\n\t\t\t\\karnaughmapcolorfield{2}{0}{red!50}%\n\t\t\t\\karnaughmapcolorfield{2}{1}{red!50}%\n\t\t\t\\karnaughmap[omitnegated=false,binaryidx,omitzeros=true]{1100 0001}\n\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\t\n\t\t\\item[R2.] When two $1$ are at the extremities of the table (here the $\\bar{b}+b$ will be simplified in the disjunctive form:\n\t\t\\begin{center}\n\t\t\\begin{tikzpicture}[thick]\n\t\t\t\\karnaughmapcolorfield{2}{0}{red!50}%\n\t\t\t\\karnaughmapcolorfield{3}{4}{red!50}%\n\t\t\t\\karnaughmap[omitnegated=false,binaryidx,omitzeros=true]{1000 1001}\n\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\t\n\t\t\\item[R3.] A whole row is full of $1$ (in this case the both variables $ab$ disappear from the disjonctive form):\n\t\t\\begin{center}\n\t\t\\begin{tikzpicture}[thick]\n\t\t\t\\karnaughmapcolorfield{2}{0}{red!50}%\n\t\t\t\\karnaughmapcolorfield{2}{2}{red!50}%\n\t\t\t\\karnaughmapcolorfield{3}{4}{red!50}%\n\t\t\t\\karnaughmapcolorfield{3}{6}{red!50}%\n\t\t\t\\karnaughmap[omitnegated=false,binaryidx,omitzeros=true]{1010 1010}\n\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\t\n\t\t\\item[R4.] A whole column is full of $1$ (in this case the both variables $cd$ disappear from the disjonctive form):\n\t\t\\begin{center}\n\t\t\\begin{tikzpicture}[thick]\n\t\t\t\\karnaughmapcolorfield{2}{2}{red!50}%\n\t\t\t\\karnaughmapcolorfield{3}{3}{red!50}%\n\t\t\t\\karnaughmapcolorfield{4}{4}{red!50}%\n\t\t\t\\karnaughmapcolorfield{4}{5}{red!50}%\n\t\t\t\\karnaughmap[omitnegated=false,binaryidx,omitzeros=true]{0000 1111 1000 0000}\n\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\t\n\t\t\\item[R5.] Four adjacents cells are full of $1$ (in this case $b$ and $d$ disappear):\n\t\t\\begin{center}\n\t\t\\begin{tikzpicture}[thick]\n\t\t\t\\karnaughmapcolorfield{4}{4}{red!50}%\n\t\t\t\\karnaughmapcolorfield{4}{5}{red!50}%\n\t\t\t\\karnaughmapcolorfield{4}{0}{red!50}%\n\t\t\t\\karnaughmapcolorfield{4}{1}{red!50}%\n\t\t\t\\karnaughmap[omitnegated=false,binaryidx,omitzeros=true]{1100 1100 0000 0000}\n\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\t\n\t\t\\item[R6.] The same cells can be used for two reductions:\n\t\t\\begin{center}\n\t\t\\begin{tikzpicture}[thick]\n\t\t\t\\karnaughmapcolorfield{4}{4}{red!50}%\n\t\t\t\\karnaughmapcolorfield{4}{5}{red!50}%\n\t\t\t\\karnaughmapcolorfield{4}{0}{red!50}%\n\t\t\t\\karnaughmapcolorfield{4}{1}{red!50}%\n\t\t\t\\karnaughmapcolorfield[outline,ultra thick]{4}{4}{violet}%\n\t\t\t\\karnaughmapcolorfield[outline,ultra thick]{4}{5}{violet}%\n\t\t\t\\karnaughmapcolorfield[outline,ultra thick]{4}{c}{violet}%\n\t\t\t\\karnaughmapcolorfield[outline,ultra thick]{4}{d}{violet}%\n\t\t\t\n\t\t\t\\karnaughmap[omitnegated=false,binaryidx,omitzeros=true]{1100 1100 0000 1100}\n\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\t\n\t\t\\item[R7.] The same box can be used for two reductions:\n\t\t\\begin{center}\n\t\t\\begin{tikzpicture}[thick]\n\t\t\t\\karnaughmapcolorfield{4}{0}{red!50}%\n\t\t\t\\karnaughmapcolorfield{4}{4}{red!50}%\n\t\t\t\\karnaughmapcolorfield[outline,ultra thick]{4}{4}{violet}%\n\t\t\t\\karnaughmapcolorfield[outline,ultra thick]{4}{c}{violet}%\n\t\t\t\n\t\t\t\\karnaughmap[omitnegated=false,omitzeros=true]{1000 1000 0000 1000}\n\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\\end{itemize}\n\tand without errors ... that's all but it's already not bad!\n\t\n\t\\pagebreak\n\t\\subsubsection{Arithmetic Boolean (binary) operations}\n\tUsing all the elements demonstrated and given previously, we are now able to rigorously determine the logic function allowing Boolean addition and subtraction. Let us also recall that this being done, we can construct multiplication and division using respectively addition and subtraction.\n\n\tHowever, we can not with formal digital systems build elements for integration and differentiation. For this we refer the reader to the section of Electrokinetics where it is shown how to use inductors and capacitors to perform such operations with signals.\n\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tWe will work on integers but the reader must remember that rational numbers can always be increased in power to be represented in an integral way (it remains to perform the inverse operation if necessary).\n\t\\end{tcolorbox}\n\tThe sum of two bytes will be denoted $S$, the retention $C_s$ (outgoing retention, also often denoted $C_\\text{out}$) and the deferred retention $C_e$ (inward retention, also often denoted $C_\\text{in}$).\n\n\tThe truth table will be build with the \"tip\" that the system inputs $(a,b,C_e)$ take all possible values on $3$ bits (three letters) thus $2^3=8$ rows that we have represented in the following table:\n\t\n\tAnd now the idea consists in adding the column constituted by the sum:\n\t\n\trow by row (without thinking to the outgoing retention $C_s$ that we will see a little bit further below):\n\t\n\tNow, row by row, we add the outgoing retention $C_s$ (which is none other than the value that is sent to the incoming retention of the next row) of the sum $S$:\n\t\n\tTherefore we have $4$ minterms (that is, the terms for which $S$ is non-zero in the rows $2$, $3$, $5$ and $8$) such that the normal disjonctive form is written:\n\t\n\tA possible simplification is:\n\t\n\tIt also comes for the outgoing retention the following minterms:\n\t\n\tSo finally we have:\n\t\n\tTo build physically with fundamental logic gates this addition, it is useful first to introduce an intermediary logic circuit (but it's not obliged, it's just for pedagogical reasons and by educational tradition!). \n\t\n\tLet us for this purpose consider the truth table of the addition without incoming retention, named a \"\\NewTerm{half adder}\\index{half adder}\", and represented by the following \"technical\" drawing:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/half_adder_schema.jpg}\n\t\t\\caption{Half adder logic diagram}\n\t\\end{figure}\n\t\n\tAnd now we can introduce the \"\\NewTerm{full adder}\\index{full adder}\" that adds binary numbers and accounts for values carried in as well as out following the relation proved earlier above and is made of two half-adder. So here is for recall the minterms and we introduce the corresponding logical circuit:\n\t\\begin{gather*}\n\t\t\\begin{aligned}\n\t\tS&=C_e\\oplus a\\oplus b\\\\\n\t\tC_s&=ab+C_ea\\oplus b\n\t\t\\end{aligned}\n\t\\end{gather*}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/full_adder_schema.jpg}\n\t\t\\caption{Full adder logic diagram}\n\t\\end{figure}\n\t\n\t\n\t\\pagebreak\n\tThe subtraction (difference) of two bytes will be denoted $D$, the borrowing $B_s$ (outgoing borrowing, also often denoted $B_\\text{out}$) and the reported borrowing $B_e$ (inbound borrowing, also often denoted $B_\\text{in}$). The truth table will first be build as for the addition. That is, the system inputs $(a,b,e_e)$ take all possible values on $3$-bit (three-letter) the $2^3=8$ rows. Therefore:\n\t\n\tBut we will a little subtlety. Rather than bore us to calculate $D=a-b-B_e$, we will calculate $D=a+(-b)+(-B_e)$ in the purpose to be able to work with the following truth table:\n\t\n\tand now the idea is to add the difference column $D=a+(-b)+(-B_e)$ row by row (without thinking about the borrowing $B_s$) which will be strictly identical to the truth table of the sum:\n\t\n\tNow, row by row, we add the outgoing borrowing $B_s$ of the difference $D=a+(-b)+(-B_e)$ which written so, then becomes a sum $S$:\n\t\n\tTherefore it comes $4$ minterms (that is, the terms for which $S(D)$ is non-zero at row $2$, $3$, $5$, $8$) such that the normal disjonctive form of the subtraction can be written:\n\t\n\tA trivial possible simplification is:\n\t\n\tIt also comes for the outgoing borrowing the following minterms:\n\t\n\tSo finally:\n\t\n\tTo build physically with fundamental logic gates this subtraction, it is useful first to introduce an intermediary logic circuit (but it's not obliged, it's just for pedagogical reasons and by educational tradition!). \n\t\n\tLet us for this purpose consider the truth table of the subtraction without incoming borrowing, named a \"\\NewTerm{half subtracter}\\index{half subtracter}\", and represented by the following \"technical\" drawing (don't forget that $b$ means in fact $-b$!):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/half_subtracter_schema.jpg}\n\t\t\\caption{Half subtracter logic diagram}\n\t\\end{figure}\n\t\n\tAnd now we can introduce the \"\\NewTerm{full subtracter}\\index{full subtracter}\" that substracts binary numbers and accounts for values carried in as well as out following the relation proved earlier above and is made of two half-adder. So here is for recall the minterms and we introduce the corresponding logical circuit:\n\t\\begin{gather*}\n\t\t\\begin{aligned}\n\t\tD&=B_e\\oplus a\\oplus b\\\\\n\t\tB_s&=\\bar{a}b+B_e(\\overline{a\\oplus b})\n\t\t\\end{aligned}\n\t\\end{gather*}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/half_subtractor_schema.jpg}\n\t\t\\caption{Full subtracter logic diagram}\n\t\\end{figure}\n\t\n\t\n\t\\pagebreak\n\t\\subsection{Fuzzy logic}\n\tClassical logic only permits conclusions which are either true or false. However, there are also propositions with variable answers, such as one might find when asking a group of people to identify a color. In such instances, the truth appears as the result of reasoning from inexact or partial knowledge in which the sampled answers are mapped on a spectrum.\n\t\n\tHumans and animals often operate using fuzzy evaluations in many everyday situations. In the case where someone is tossing an object into a container from a distance, the person does not compute exact values for the object weight, density, distance, direction, container height and width, and air resistance to determine the force and angle to toss the object. Instead the person instinctively applies quick \"fuzzy\" estimates, based upon previous experience, to determine what output values of force, direction and vertical angle to use to make the toss.\nBoth degrees of truth and probabilities range between 0 and 1 and hence may seem similar at first, but fuzzy logic uses degrees of truth as a mathematical model of vagueness, while probability is a mathematical model of ignorance.\n\n\tTake, for example, the concepts of \"empty\" and \"full\". The meaning of each of them can be represented by a certain fuzzy set. The concept of emptiness would be subjective and thus would depend on the observer or designer. A $100$ [ml] glass containing $30$ [ml] of water may be defined as being $0.7$ empty and $0.3$ full, but another designer might, equally well, design a set membership function where the glass would be considered full for all values down to $50$ [ml].\n\t\n\tMost of the problems encountered are certainly mathematically modelizable. But these models often require overly restrictive assumptions, making application to the real world tricky. The problems of this world must take into account imprecise, uncertain information. Let us take the example of air conditioning: if we want to obtain a cool temperature, we can ask ourselves what temperature range will be appropriate (the demand is imprecise); Furthermore the reliability of the sensors comes into play (the measurement of the ambient temperature is uncertain). We see the difficulty of interpreting the linguistic variables as fresh, hot, ... and the processing of these uncertainties.\n\t\n\tAn approach was developed from 1965 by Loft. A. Zadeh, a professor at the University of California at Berkeley, based on the theory of fuzzy sets, generalizing the theory of classical sets. In the new Zadeh theory, an element can more or less belong to a certain set. Inaccuracies and uncertainties can thus be modeled, and reasonings acquire a flexibility that is not allowed by classical logic: \"\\NewTerm{fuzzy logic}\\index{fuzzy logic}\" was born. Many applications have developed in various domains, where no deterministic model exists or is practically implementable, as well as in situations where data imprecision makes control by conventional methods impossible.\n\n\tIn the following, we will first develop the basics of the theory of fuzzy subsets, then we will clarify the reasoning in fuzzy logic, we will examine the methods of exploitation of the results obtained, and finally we will see an effective application (and if possible an application with MATLAB™ and/or R).\n\n\tBefore turning to the formal side of the thing (mathematically speaking), it may be preferable (since it is still a technique of the engineer mainly) to briefly present the concepts of fuzzy logic in a pictorial way.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe fuzzy logic is a technique used for real in fields as varied as automatism (ABS brakes), robotics (pattern recognition), road traffic management (red lights), air traffic control, environment (meteorology, climatology, seismology), medicine (diagnostic aid), psychology, data mining, machine learning, and many others.\n\t\\end{tcolorbox}\n\tConsider, for example, the speed of a vehicle on a national highway. The normal speed is $90\\;[\\text{km}\\cdot\\text{h}^{-1}]$. A speed can be considered as high above  $100\\;[\\text{km}\\cdot\\text{h}^{-1}]$, and as low below $80\\;[\\text{km}\\cdot\\text{h}^{-1}]$. Boolean logic would look at a thing like this:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_car_speed_example_01.jpg}\n\t\\end{figure}\n\tWe see above that therefore the speed is considered $100\\%$ as high starting from $100\\;[\\text{km}\\cdot\\text{h}^{-1}]$, and $0\\%$ below.\n\n\tFuzzy logic, on the other hand, allows degrees of verification of the condition \"Is speed high?\" according to:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_car_speed_example_02.jpg}\n\t\\end{figure}\n\tThe situation is better here as the speed is considered as not high at all  below $80\\;[\\text{km}\\cdot\\text{h}^{-1}]$. We can therefore say that below $80\\;[\\text{km}\\cdot\\text{h}^{-1}]$, the speed is high at $0\\%$. The speed is considered to be high above $100\\;[\\text{km}\\cdot\\text{h}^{-1}]$. The speed is therefore high at $100\\%$ above $100\\;[\\text{km}\\cdot\\text{h}^{-1}]$. The speed is thus high at $50\\%$ when at $90\\;[\\text{km}\\cdot\\text{h}^{-1}]$ and high at $25\\%$ at $85\\;[\\text{km}\\cdot\\text{h}^{-1}]$.\n\n\tSimilarly, the function \"Is the speed low?\" Will be addressed typically as following by most humans:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_car_speed_example_03.jpg}\n\t\\end{figure}\n\tTherefore following the above figure the speed is considered low under $80\\;[\\text{km}\\cdot\\text{h}^{-1}]$. It is therefore $100\\%$ low. The speed is considered not at all low above $100\\;[\\text{km}\\cdot\\text{h}^{-1}]$. It is therefore $0\\%$ low. The speed is thus a $50\\%$ (bit low) when at $90\\;[\\text{km}\\cdot\\text{h}^{-1}]$ and at $75\\%$ (quite low) when at $85\\;[\\text{km}\\cdot\\text{h}^{-1}]$.\n\t\n\tWe can also define a function \"Is the speed average?\" by:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_car_speed_example_04.jpg}\n\t\\end{figure}\n\tOnce the input value evaluated (\"Is the speed high?\"), a value can be determined for an output function. Consider the function \"If the fever is strong, then administer aspirin\". Such a function is named \"\\NewTerm{fuzzy control}\". It is composed of two parts:\n\t\\begin{enumerate}\n\t\t\\item An input: \"Is the fever strong?\". We consider that a fever is not strong below $38^\\circ$ [C], and that it is high above $40^\\circ$ [C].\n\t\t\n\t\t\\item An output: \"Administer a given number of aspirin tablets!\"\n\t\\end{enumerate}\n\tThese two parts are related. We can represent them together as below:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_car_speed_example_05.jpg}\n\t\\end{figure}\n\tThere are several empirical techniques for determining the output value (in the example: the number of aspirin tablets to be administered):\n\n\tAn example consists in taking the horizontal passing through the corresponding ordinate point on the starting curve at the abscissa of the value of the input and of looking at where this horizontal section intersects the output curve. The abscissa of this point of intersection is a possible output value as shown below:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_car_speed_example_06.jpg}\n\t\\end{figure}\n\tA second empirical possible choice consists in taking as output value of the center of gravity of the gray trapezoid delimited by the horizontal and the output curve as shown in the figure below:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_car_speed_example_07.jpg}\n\t\\end{figure}\n\tFrom these two non-software oriented examples, we see that we are at the frontier of pure science and engineering frontier since there is a technical and/or statistical choice to be made in the method to be chosen.\n\t\n\tLet us now a computer aided example as engineers in practice use such stool to speed up their research and development! The case below in inspired by a textbook and many softwares take it now as basis example named the \"Basic Tipping Problem\". \n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tGiven a number between $0$ and $10$ that represents the quality of service and food at a restaurant (where $10$ is excellent), what should the tip be? \\\\\n\t\n\tThis problem is based on tipping as it is typically practiced in the United States. An average tip for a meal in the U.S. is $15\\%$, though the actual amount may vary depending on the quality of the service provided. But because service and food is rated on a scale of $0$ to $10$, we might have the tip go linearly from $5\\%$ if the service is bad to $25\\%$ if the service is excellent.\\\\\n\t\n\tIf we denote $S$ for the service and $F$ for food quality, we will chose the tip as being given by:\n\t\n\tHere is a copy/paste of the MATLAB™ 2013a script for the original url\\footnote{https://ch.mathworks.com/help/fuzzy/an-introductory-example-fuzzy-versus-nonfuzzy-logic.html}:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_tip_matlab_01_script.jpg}\n\t\\end{figure}\n\t\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\tIn this case, the results look satisfactory, but when you look at them closely, they do not seem quite right:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.9]{img/computing/fuzzy_logic_tip_matlab_01_plot.jpg}\n\t\\end{figure}\n\tSuppose you want the service to be a more important factor than the food quality. Specify that service accounts for $80\\%$ of the overall tipping grade and the food makes up the other $20\\%$. Try this equation:\n\t\n\tThus in MATLAB™ 2013a:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_tip_matlab_02_script.jpg}\n\t\\end{figure}\n\tThe response is still some how too uniformly linear. Suppose you want more of a flat response in the middle, i.e., you want to give a $15\\%$ tip in general, but want to also specify a variation if the service is exceptionally good or bad. This factor, in turn, means that the previous linear mappings no longer apply. You can still use the linear calculation with a piecewise linear construction. Now, return to the one-dimensional problem of just considering the service. You can create a simple conditional tip assignment using logical indexing:\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_tip_matlab_03_script.jpg}\n\t\\end{figure}\n\tthat gives the following plot:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/fuzzy_logic_tip_matlab_02_plot.jpg}\n\t\\end{figure}\n\tSuppose you extend this to two dimensions, where we take food into account again:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_tip_matlab_04_script.jpg}\n\t\\end{figure}\n\tthat gives the following plot:\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_tip_matlab_03_plot.jpg}\n\t\\end{figure}\n\tThe plot looks good, but the function is surprisingly complicated. It was a little difficult to code this correctly, and it is definitely not easy to modify this code in the future. Moreover, it is even less apparent how the algorithm works to someone who did not see the original design process.\n\t\\end{tcolorbox}\n\tIn practice we don't use a fuzzy function like the one above as there are sharp angles (imagine a car having speed settings wit abrupt changes as above...).\n\t\n\tTherefore rather than using linear functions a input we can choose among a class of continuous and smooth functions. For example the \"\\NewTerm{Gaussian curve membership function}\" defined by:\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.5]{img/computing/fuzzy_gaussmf.jpg}\n\t\\end{figure}\n\tor the \"\\NewTerm{Trapezoidal-shaped membership function}\" defined by:\n\t\n\tThe parameters $a$ and $d$ locate the \"feet\" of the trapezoid and the parameters $b$ and $c$ locate the \"shoulders.\"\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.5]{img/computing/fuzzy_trapmf.jpg}\n\t\\end{figure}\n\tOr also the \"\\NewTerm{Triangular-shaped membership function}\" defined by:\n\t\n\tThe parameters $a$ and $c$ locate the \"feet\" of the triangle and the parameter $b$ locates the peak:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.5]{img/computing/fuzzy_trimf.jpg}\n\t\\end{figure}\n\tLet us see with R the tipper problem managed with the fuzzy functions above (for more details see the R companion book!).\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\tHere is a copy/paste of the R script  given in \\cite{wagner2011fuzzy} with detailed explanations.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/fuzzy_tipping_problem_r.jpg}\n\t\\end{figure}\n\tThat gives:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.5]{img/computing/fuzzy_tipping_problem_r_plot.jpg}\n\t\\end{figure}\n\t\\end{tcolorbox}\n\t\n\t\\subsubsection{Fuzzy set}\n\t\\textbf{Definition (\\#\\mydef):} Given $X$ a set. A \"\\NewTerm{fuzzy subset}\" $A$ of $X$ is defined by a belonging function $f_A$ on $X$ with values in the interval $[0,1]$.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe belonging function $f_A$ can be set arbitrarily. A practical application problem is for the engineer to define these functions (we usually use statistical data or the opinion of an expert to make the least worst choice...).\n\t\\end{tcolorbox}\n\tThe notion of fuzzy subset encompasses that of classical subset for which $f_A$ is the indicator function given for recall by:\n\t\n\t\\textbf{Definition (\\#\\mydef):} If $A$ and $B$ are two sets, such that $A$ is included in $B$ (ie $A\\subset B$), we name \"\\NewTerm{indicator function}\\index{indicator function}\" of $A$ (relatively to $B$), the function $1_A$ defined in $\\{0,1\\}$, and such that:\n\t\n\tThis is for a classical set. Obviously such indicator functions are often very practical technical intermediaries!\n\t\n\tBut for fuzzy logic we have scnerio such like this:\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tA possible characteristic function to define the fuzzy subset $A$ \"to be twenty years\" on the set $X$ of the real positive numbers:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_centered_linear_fuzzy_function_simple.jpg}\n\t\t\\caption{Centered linear fuzzy function}\n\t\\end{figure}\n\t\\end{tcolorbox}\n\tThe following concepts are characteristic of $A$ in the field of fuzzy sets:\n\t\n\t\\pagebreak\n\t\\textbf{Definitions (\\#\\mydef):}\n\t\\begin{enumerate}\n\t\t\\item[D1.] Support of $A$:\n\t\t\n\n\t\t\\item[D2.] Height of $A$:\n\t\t\n\n\t\t\\item[D3.] A is said to be normalized if $h(A)=1$\n\t\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\t\tA possible characteristic function to define the fuzzy subset $A$ \"to be twenty years\" on the set $X$ of the real positive numbers:\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_centered_linear_fuzzy_function.jpg}\n\t\t\t\\caption{Centered linear fuzzy function}\n\t\t\\end{figure}\n\t\t\\end{tcolorbox}\n\t\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\t\tThe fuzzy subsets considered will all be assumed normalized, in extenso of height equal to $1$.\n\t\t\\end{tcolorbox}\n\t\t\n\t\t\\item[D4.] The kernel of $A$:\n\t\t\n\t\n\t\t\\item[D5.] Cardinality of $A$:\n\t\t\n\t\t\n\t\t\\item[D6.] $A$ is \"more specific\" than $B$ if:\n\t\t\n\t\t\n\t\t\\item[D7.] $A$ is \"more precise\" than $B$ if:\n\t\t\n\t\t\n\t\t\\item[D8.] There is equality between two fuzzy subsets if and only if:\n\t\t\n\t\t\\item[D9.] There is equality between two fuzzy subsets if and only if:\n\t\t\n\t\t\n\t\t\\item[D10.] There is inclusion between two fuzzy subsets if and only if:\n\t\t\n\t\t\n\t\t\\item[D11.] The intersection $A\\cap B$ is defined by:\n\t\t\n\t\t\n\t\t\\item[D12.] The union $A\\cup B$ is defined by:\n\t\t\n\t\\end{enumerate}\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tLet us return to the case already envisaged. We consider the \"twenty-year-old\" people and those with \"being in age\" (ie, those who are in age to vote/drink alcohol) (dotted in the figure: we consider it as a non-fuzzy sub-set!):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_example_01.jpg}\n\t\\end{figure}\n\tAccording on the definitions of the intersection (\"logical AND\" or logical multiplication according to the Boolean algebra) and the union (\"logical OR\" or logical addition according to Boolean algebra), we can characterize the subsets (first figure below), as well as those \"being in their twenties or being in age\" (second figure below):\n\t\\end{tcolorbox}\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_example_02.jpg}\n\t\\end{figure}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/fuzzy_logic_example_03.jpg}\n\t\\end{figure}\n\t\\end{tcolorbox}\n\t\n\t\\begin{flushright}\n\t\\begin{tabular}{l c}\n\t\\circled{80} & \\pbox{20cm}{\\score{3}{5} \\\\ {\\tiny 10 votes,  66.00\\%}} \n\t\\end{tabular} \n\t\\end{flushright}\n\n\n\t%to make section start on odd page\n\t\\newpage\n\t\\thispagestyle{empty}\n\t\\mbox{}\n\t\\section{Error-Correcting Codes}\n\t\\lettrine[lines=4]{\\color{BrickRed}I}f the first half of the 20th century was that of the analog revolution by radio and television, the second half of this century is that of the digital revolution and the systematic use of algebra in the data transmission. It is also the emergence automated error handling, where an \"\\NewTerm{Error}\\index{error}\" is a condition when the output information does not match with the input information. During transmission, digital signals suffer from noise that can introduce errors in the binary bits traveling from one system to other. \\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/error_transmission.jpg}\n\t\\end{figure}\n\tThe \"\\NewTerm{error correction codes}\\index{error correction codes}\" (ECC) are used to add redundancy to the data to make it tolerant to the transmission errors (at least to a given degree). Basically, the idea is to encode one way or another an information sequence and add encoding the original data as a control data integrity. So even if some of the information is corrupted, but not too much... redundancy will identify the incorrect parts of the message.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tECC are not only used for data transmission but also to give unique identifiers to bills in some countries and also in some factories to build a nomenclature system (naming) of pieces and to control afterwards the input of employees in computer systems! For example, bar-codes and QR-codes contains ECC.\n\t\\end{tcolorbox}\n\t\n\tThus, after the appearance of audio CD in the early 1980s, we must take into account the development of broadcasting satellites  and new means of communication such as the fax, the Minitel, Internet or digital phone using any correcting codes errors (CCE). Even photography, radio and books are becoming digital (and will probably only be in this format in a hundred years).\n\t\n\tImage or sound reproduction techniques are related to the transmission and to the correct reading of many digital messages, also known as \"words\". A message consists of words themselves made up of symbols (a particular example being the \"bit\" which for reminder is contraction of \"BInary digiT\"), taken from an alphabet. If the alphabet is binary so each symbol will be a bit.\n\t\n\tLet us take the message $00101$ formed of $5$ bits each worth $0$ or $1$. If we send the message as is, a transmission error or of reading can take place and make the message unintelligible (or the bill/piece unique identifier). Let us decide to repeat the message three times and send it:\n\t\n\tIf the received message contains an error, this error can be corrected. If there are two errors, the receiver is able to detect that there was a mistake but can not always recover the original message. Finally, if it occurs more than two errors during transmission, the receiver can not detect them.\n\t\n\tWe have seen just now a first example of ECC, named \"\\NewTerm{repeatedly code}\\index{repeatedly code}\". This code, which corrects errors and detects two, was used in some Audio CD player having three heads. The signal $0$ or $1$ is read independently by each of these three heads to give a word of three digits, and a reading error can be sometimes corrected.\n\t\n\tNote that it is natural to extend a message to protect it. Let us consider the words of a language. They are usually very far from each other, two words differs according to their lengths and in the letters and syllables used. Thus it will be difficult to confound the words \"library\" and \"cabinet\" although these words are mispronounced or misheard and we will naturally reconstitute the message in a conversation even when some letters would be deleted or distorted. The military meanwhile spell some information by saying \"Alpha Zulu\" for \"AZ\" to avoid errors...\n\t\n\tA second example widely used in computing science of error detection is the addition of a \"\\NewTerm{parity bit}\\index{parity bit}\". Let $00101$ be the original message and add it a last bit obtained by adding five bits of departure modulo $2$. The message is $001010$ and we can therefore detect errors but can not correct it.... For this, we make the sum of all the bits to obtain $0$ if there is no error, and $1$ otherwise. This code named \"\\NewTerm{parity code}\\index{parity code}\" is used everywhere: in the social security numbers where we add a key, in those of bank accounts or in barcode of supermarkets where it is the 13th digit that is the control key (the space probe Voyager II is one of the many users of parity codes to communicate almost in a reliable way and also the $8$th bit in the ASCII system which is used as a parity bit).\n\t\n\tFor many years, the DRAM sockets managed words with one bit only; it was then necessary to put the $8$ memory card sockets for working with bytes ($8$ bits). But at this time many cards included not $8$ but $9$ sockets! The ninth socket was designed to store a parity bit at each start of a memory byte. When reading a byte, we checked, if between the time of writing and that of reading, parity had not been changed (due to a parasite, for example).\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/ecc_ram.jpg}\n\t\t\\caption{ECC RAM vs Non-ECC RAM}\n\t\\end{figure}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tWe would like to point out that ECC memory is considered server-grade. They are sold to a market which pays much closer attention to reliability than the consumer market. As a result, ECC RAM is usually subjected to much stricter testing and validation before shipping. This is a big factor in why ECC modules see much lower failure rates.\n\t\\end{tcolorbox}\n\tFinally, let us see a third example used on some computer servers that use  in RAID4 or RAID6 parallel disks, this latter using Hamming codes that we will see later.\n\t\n\tSuppose we have $3$ hard drives, and the content of the first byte of each disc is the following:\n\t\n\tSo it is sufficient take each column and count the number $p$ of $1$ in the column. The value of the parity bit is then $p$ modulo $2$. We have for the first column in the example above $p$ which is $2$. Therefore, the parity bit is equal to $0$, etc. Then we have on the control disc (CD):\n\t\n\tThese three examples are fundamental to the basic coding theory and show that we can control the appearance of error by deliberately lengthening the message before transmission or reading. More sophisticated algebraic techniques are then used to improve the performance of coding, thanks to:\n\t\n\t\\begin{enumerate}\n\t\t\\item Know if any errors occurred (detection problems)\n\t\t\n\t\t\\item find the initial correct message from the message received (correction of problem)\n\t\t\n\t\t\\item correct the most  possible mistakes while using the least possible additional bits (the problem of performance encoding)\n\t\\end{enumerate}\n\tFrom the mathematical point of view, one of the interests of coding theory is to show that algebra applies once again well in our everyday life when we listen to music, or we settle in front of our televisions, and that such abstract notions as those of vector spaces or polynomials over finite fields allow us to read messages, listen to music or watch movies in optimum conditions!\n\t\n\tWe distinguish the following two classes of ECC: \n\t\\begin{enumerate}\n\t\t\\item Block codes\n\t\t\\item Treillis codes\n\t\\end{enumerate}\n\tThe figure below provides a simple overview of the error correcting codes family\\footnote{For example \"Quantum Error Correction\" is not indicated}. In the first class (right in the figure), we have the most popular codes such as BCH codes, Reed-Solomon and Goppa, Golay and Hamming. The second class (left in the figure) is less rich in variety but has a lot more flexibility, especially in the choice of parameters and decoding algorithms available. Let us cite for example the binary systematic recursive convolutional codes widely used in coded modulation and the parallel concatenated codes (Turbo Codes).\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/error_correcting_codes.jpg}\n\t\t\\caption{Non-exhaustive orgchart of correcting codes}\n\t\\end{figure}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tTo introduce the foundations of the theory of error correcting codes, we recommend strongly the reader to have read through first the section of Set Theory, after this of  Statistical Mechanics (where the information theory is) after of Numerical Systems and finally of Topology.\n\t\\end{tcolorbox}\n\t\n\tWhen possible we will show the reader how to put quickly in practice ECC using native MATLAB™ Communication Toolbox functions.\n\t\n\t\\subsection{CheckSum}\n\tBefore starting the part of pure mathematics, we would make a small introduction to the \"checksum\" (control sum) that is a tool frequently used in the business when exchanging files over several Giga Bytes between two computers or when downloading on the Internet.\n\t\n\tThe checksum, also sometimes named \"fingerprint\" is a basic concept of coding theory used for correcting codes. It corresponds to a particular case of \"redundancy control code\". It is widely used in computer and digital telecommunications as already said.\n\t\n\tOne of basic technique (among a dozens more or less sophisticated) is to take the sum of a given length of bits (byte, word, or other ...) and calculate the modulo 255 (FF in hexadecimal). For example, if we take two words and we rely on their hexadecimal ASCII code (you can find ASCII tables almost everywhere on the internet):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.9]{img/computing/checksum.jpg}\n\t\t\\caption{Basic Checksum principle (source: Wikipedia)}\n\t\\end{figure}\n\tSome tools also use the MD5 algorithm (Message Digest 5) or SHA (Secure Hash Algorithm) to have an checksum of a message (\\SeeChapter{see section Cryptography}).\n\t\n\t\\subsubsection{Luhn algorithm}\n\tThe Luhn algorithm or Luhn formula, also known as the \"modulus 10\" or \"mod 10\" algorithm, is a simple checksum formula used to validate a variety of identification numbers, such as Credit card numbers, IMEI numbers, National Provider Identifier numbers in the US, and Canadian Social Insurance Numbers (see examples further below). It was created by IBM scientist Hans Peter Luhn and described in U.S. Patent No. 2,950,048, filed on January 6, 1954, and granted on August 23, 1960.\n\n\tThe algorithm is in the public domain and is in wide use today. It is specified in ISO/IEC 7812-1 and is completely described in the following figure:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.8]{img/computing/luhn_algorithm.jpg}\n\t\t\\caption{Luhn algorithm for checksum principle}\n\t\\end{figure}\n\tThe Luhn algorithm will detect any single-digit error, as well as almost all transpositions of adjacent digits. It will not, however, detect transposition of the two-digit sequence $09$ to $90$ (or vice versa). It will detect $7$ of the $10$ possible twin errors (it will not detect $22 \\leftrightarrow 55$, $33 \\leftrightarrow 66$ or $44 \\leftrightarrow 77$).\n\t\n\tA picture is worth a thousand words let us see how this apply to VISA cards:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.6]{img/computing/luhn_algorithm_visa.jpg}\n\t\\end{figure}\n\n\tOther, more complex check-digit algorithms (such as the Verhoeff algorithm and the Damm algorithm) can detect more transcription errors.\n\t\n\t\\pagebreak\n\t\\subsection{Check Digit}\n\tAlso before starting the part of pure mathematics, we would make a small introduction to some common check digits (in fact any professionally driven government or company should have all objects or individuals identifiers with at least one check digit). We will only focus on example that have been asked to me by my students or people that contacted me on the Internet (otherwise I can dedicate a whole book only for examples on check digits...)!\n\t\n\t\\textbf{Definition (\\#\\mydef):} A \"\\NewTerm{check digit}\\index{check digit}\" is a form of redundancy check used for error detection on identification numbers, such as bank account numbers, which are used in an application where they will at least sometimes be input manually. It is analogous to a binary parity bit used to check for errors in computer-generated data. It consists of one or more digits computed by an algorithm from the other digits (or letters) in the sequence input.\n\t\n\t\\subsubsection{European Article Numbering (EAN-13)}\n\tLet us see first the check digit of EAN-13 bar codes (Cyclic Redundancy Check\\footnote{type of checksum, specifically a position dependent checksum algorithm} (CRC) ECC type):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.6]{img/computing/ean_13_barcod.jpg}\n\t\t\\caption{EAN-13 bar-code example}\n\t\\end{figure}\n\tThere are various different errors that can occur when numbers are written, printed or transferred in any manner. Different methods of assigning check digits are better at detecting certain kinds of errors than others. The most common types of errors that occur in practice and their frequencies, according to one study, are as follows:\n\t\n\tAnother common type of error not mentioned here is accidental insertion or deletion of characters. In the cases we will consider, the number will have a fixed length, so insertions and deletions will be automatically detected.\n\t\n\tThe EAN-13 format uses a modulus $10$ scheme, with check digit ($a_ c$) defined by\n\t\n\tFor example, if we start with the number $1234567$ in the EAN-8 scheme, then our check digit is:\n\t\n\twhich makes the full bar code number $12345670$.\n\t\n\tWhen dealing we ECC must worry about how effective a scheme is in detecting errors!\n\t\n\tLet us consider only two cases:\n\t\\begin{enumerate}\n\t\t\\item Single error detection rate:\n\n\t\tIf a digit $d$ whose weight is $1$ is changed to $c$, the weighted sum will change by $d-c$. The error will go undetected only if $d-c=0 \\mod 10$. But this happens only when $d=c$, in which case there has not been an error after all, so all errors of this kind are caught.\n\n\t\tWhat if the weight were $3$? Then the error would be undetected if $3(d-c)=0 \\mod 10$. But again, this cannot happen unless $d=c$. Thus, this method has a $100\\%$ single error detection rate (SEDR).\n\n\t\t\\item Transposition of adjacent digits detection rate:\n\n\t\tSuppose two adjacent digits, $cd$, are transposed to $dc$. If $c$’s weight is $3$ (hence $d$’s weight is $1$), the weighted sum is changed by:\n\t\t\n\t\twhich will be detected unless $2(c-d)=0 \\mod 10$, which can happen only if $c$ and $d$ differ by $5$. The same would have applied if $c$ had been weighted by $1$ and $d$ by $3$.\n\n\t\tAs a result, the transpositions that will go undetected must involve $0 \\leftrightarrow 5, 1\\leftrightarrow 6, 2 \\leftrightarrow 7, 3 \\leftrightarrow 8$ and $4 \\leftrightarrow 9$. So, $10$ transpositions are undetectable.\n\n\t\tThere are 100 possibilities for each pairing, and the transposition of 90 of these would result in an error. Therefore the detection rate is $ 80/90 = 88.9\\% $ transposition error detection rate (TEDR).\n\t\\end{enumerate}\n\t\n\t\\subsubsection{Swiss Post Payment slip}\n\tAnother famous example for my country is the Swiss Post payment slip where numerous numbers have a check digit.\n\t\n\tHere is a sample preview of such a payment slip:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.5]{img/computing/swiss_payment_slip.jpg}\n\t\t\\caption{Swiss payment slip}\n\t\\end{figure}\n\tand here technical description of the bottom right number with in red the check digit on which we will focus here:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.6]{img/computing/swiss_payment_slip_check_digit.jpg}\n\t\t\\caption{Swiss payment slip check digit for Reference Number}\n\t\\end{figure}\n\tAll the digit check in this Swiss payment slip are based on a recursive modulo $10$ computation.\n\t\n\tLet us give a small example on how to calculate the check digit based on the Swiss method. For this let us consider first the following matrix:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.55]{img/computing/swiss_payment_slip_matrix.jpg}\n\t\\end{figure}\n\tSo what would be the check digit of the number 70004152 (it's a typical 8 digit Swiss Post account)?\n\t\n\tThe process to determine that latter is simply the following:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.74]{img/computing/swiss_payment_slip_check_digit_calculation_procedure.jpg}\n\t\\end{figure}\n\t\n\t\\subsubsection{International Bank Account Number (IBAN)}\n\tThe International Bank Account Number (IBAN) is an internationally agreed system of identifying bank accounts across national borders to facilitate the communication and processing of cross border transactions with a reduced risk of transcription errors. It was originally adopted by the European Committee for Banking Standards (ECBS), and later as an international standard under ISO 13616.\n\n\tThe IBAN consists of up to 34 alphanumeric characters comprising: a country code; two check digits; and a number that includes the domestic bank account number, branch identifier, and potential routing information. The check digits enable a sanity check of the bank account number to confirm its integrity before submitting a transaction.\n\n\tBefore IBAN errors of transcription were not detectable and it was not possible for a sending bank to validate the routing information prior to submitting the payment. Routing errors caused delayed payments and incurred extra costs to the sending and receiving banks and often to intermediate routing banks.\n\n\tThe IBAN should not contain spaces when transmitted electronically. When printed it is expressed in groups of four characters separated by a single space, the last group being of variable length. Here is an example of how typically Switzerland writhe IBAN numbers:\n\t\\begin{center}\n\t\t\\texttt{CH93 0076 2011 6238 5295 7}\n\t\\end{center}\n\tPermitted IBAN characters are the digits $0$ to $9$ and the $26$ upper-case Latin alphabetic characters $A$ to $Z$. This applies even in countries (e.g., Thailand) where these characters are not used in the national language.\n\t\n\tAn IBAN is validated by converting it into an integer and performing a basic modulo $97$ operation (as described in ISO 7064: \\textit{Security techniques -Check character systems}) on it. If the IBAN is valid, the remainder equals $1$.\n\n\tThe procedure is a follows:\n\t\\begin{itemize}\n\t\t\\item Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid;\n\n\t\t\\item Move the four initial characters to the end of the string;\n\n\t\t\\item Replace each letter in the string with two digits, thereby expanding the string, where A $= 10$, B $= 11$, ..., Z $= 35$;\n\t\n\t\t\\item Interpret the string as a decimal integer and compute the remainder of that number on division by $97$.\n\t\\end{itemize}\n\tIf the remainder is $1$, the check digit test is passed and the IBAN might be valid.\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tGiven a fictitious United Kingdom bank, sort code \\texttt{12-34-56}, account number \\texttt{98765432}. For the sanity check we follow the above procedure:\n\t\\begin{itemize}\n\t\t\\item The IBAN is therefore:\n\t\t\\begin{center}\n\t\t\t\\texttt{GB82 WEST12345698765432}\n\t\t\\end{center}\n\n\t\t\\item We rearrange:\n\t\t\\begin{center}\n\t\t\t\\texttt{WEST12345698765432GB82}\n\t\t\\end{center}\n\n\t\t\\item We convert to integer:\n\t\t\\begin{center}\n\t\t\t\\texttt{3214282912345698765432161182}\n\t\t\\end{center}\n\n\t\t\\item We compute the modulo $97$:\n\t\t\\begin{center}\n\t\t\t\\texttt{3214282912345698765432161182} $\\mod 97=1$\n\t\t\\end{center}\n\t\\end{itemize}\n\t\\end{tcolorbox}\n\t\n\t\\subsubsection{UIC wagon numbers}\n\tWagon numbers (or coach numbers) are key data for railway operations. They enable a railway wagon or coach to be positively identified and form a common language between railway operators, infrastructure companies and the state authorities. The system of wagon numbering has been laid down by the International Union of Railways (Union internationale des chemins de fer or UIC) and is similar to that used for the locomotives and multiple units.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{subfigure}{0.4\\textwidth}\n\t\t\t\\includegraphics[width=\\textwidth]{img/computing/uic_wagon_slovakia.jpg}\n\t\t\t\\caption{Slovak UIC wagon number}\n\t\t\\end{subfigure}\n\t\t\\begin{subfigure}{0.4\\textwidth}\n\t\t\t\\includegraphics[width=\\textwidth]{img/computing/uic_wagon_switzerland.jpg}\n\t\t\t\\caption{Swiss UIC wagon number}\n\t\t\\end{subfigure}\t\t\t\t\n\t\\end{figure}\n\tThe complete wagon number comprises 12 digits. The individual digits have the following meaning:\n\t\\begin{itemize}\n\t\t\\item Digit 1-2: Type of vehicle and indication of the interoperability capacity\n\n\t\t\\item Digit 3-4: Country Code (Switzerland (CH) = $85$)\n\n\t\t\\item Digit 5-8: Vehicle type information\n\n\t\t\\item Digit 9-11: Individual running number (serial number)\n\t\t\n\t\t\\item Digit 12: Self-check digit\n\t\\end{itemize}\n\tThe digits are multiplied individually from right to left alternately by $2$ and $1$, and digit summed. The difference between this sum and the next multiple of ten is the check digit, placed after the eleventh digit, separated by a dash.\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tGiven a fictitious Wagon UIC \\texttt{21-81-24 7121 7}. For the sanity check we follow the above procedure:\n\t\\begin{itemize}\n\t\t\\item The UIC is therefore:\n\t\t\\begin{center}\n\t\t\t \\texttt{2 1 8 1 2 4 7 1 2 1 7}\n\t\t\\end{center}\n\n\t\t\\item We multiply:\n\t\t\\begin{center}\n\t\t\t \\texttt{2} $\\cdot 2\\quad$ \\texttt{1}$\\cdot 1\\quad$ \\texttt{8}$\\cdot 2\\quad$ \\texttt{1}$\\cdot 1\\quad$ \\texttt{2}$\\cdot 2\\quad$ \\texttt{4}$\\cdot 1\\quad$ \\texttt{7}$\\cdot 2\\quad$ \\texttt{1}$\\cdot 1\\quad$ \\texttt{2}$\\cdot 2\\quad$ \\texttt{1}$\\cdot 1\\quad$ \\texttt{7}$\\cdot 2$\n\t\t\\end{center}\n\t\tIt gives:\n\t\t\\begin{center}\n\t\t\t$4 \\; 1\\; 16 \\; 1\\; 4\\; 4\\; 14\\; 1\\; 4\\; 1\\; 14$\n\t\t\\end{center}\n\n\t\t\\item We sum up the digits using:\n\t\t\n\t\t\n\t\t\\item We take the next multiple of $10$ that $40$ so the check digit is equal to three $3$.\n\t\t\n\t\t\\item Finally we get:\n\t\t\\begin{center}\n\t\t\t\\texttt{21-81-24 7121 7-3}\n\t\t\\end{center}\n\t\\end{itemize}\n\t\\end{tcolorbox}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe swiss \"Unternehmens-Identifikationsnummer\" (company identification number) also have a check digit and so on...\n\t\\end{tcolorbox}\n\t\n\t\n\t\\pagebreak\n\t\\subsection{Permutations}\n\tAlso before starting the part of pure mathematics, we would make a small introduction to the check digit using permutations in VISA card numbers.\n\t\n\tCredit cards use an error-detecting scheme that was developed by IBM. It uses the permutation:\n\t\n\tIn other words (for more details see the section of Set Algebra) $\\sigma (0)=0$, $\\sigma (1)=2$, $\\sigma (2)=4$, etc.\n\t\n\tNotice also that:\n\t\n\n\tIn a $16$ digit credit card number, the final digit is the check digit. Let the credit card number be $(a_1, a_2,\\ldots , a_{15}, a_{16})$, with $a_{16}$ being the check digit. Then\n\t\n\tNote that in this example the permutation was applied to $a_ i$ where $i$ is odd ($a_1, a_3$, etc), because there is an odd number of digits excluding the check digit. Had this scheme been used on a number with an even number of digits excluding the check digit, the permutation would have been applied to $a_ i$ where $i$ was even.\n\t\n\tAs we know form the previous example, dealing we ECC must worry about how effective a scheme is in detecting errors!\n\t\n\tLet us consider again only two cases:\n\t\\begin{enumerate}\n\t\t\\item Single error detection rate:\n\n\t\tThis scheme catch all single-digit errors ($100\\%$ SEDR). Indeed, for example if digit $a_ i$ is changed from $c$ to $d$, and $i$ is even, the remainder will change by $c-d$, which is non-zero (and is, of course, smaller than the modulus $N=10$). If $i$ is odd, it will change by $\\sigma (c)-\\sigma (d)$. This is again non-zero: $\\sigma (c)$ cannot be equal to $\\sigma (d)$ if $\\sigma $ is a permutation.\n\n\t\t\\item Transposition of adjacent digits detection rate:\n\t\t\n\t\tIf two adjacent digits $c$ and $d$ are transposed, one of them must have the permutation applied - say $c$. The remainder will be unchanged only if $\\sigma (c)+d = \\sigma (d)+c$. Since $\\sigma (x) = 2x \\mod 9$, this happens only when $c = d \\mod 9$, that is, only when $c$ and $d$ are $0$ and $9$ (in either order).\n\t\t\n\t\tTherefore, for each pair of adjacent digits, of the $90$ possible transposition errors, two will be undetectable. So the detection rate for transpositions is $88/90 = 97.8\\% $ (TEDR).\n\t\\end{enumerate}\n\t\n\t\\subsection{Encoders}\n\tGiven $Q$ a finite set of $q$ elements (bits, alphabets). Given $k$ and $n$ two  nonzero integers with $k\\leq n$. The set of messages will be a part of $E$ of $Q^k$ and we introduce a bijective application (at least that is the goal):\n\t\n\tnamed \"\\NewTerm{encoding application}\\index{encoding application}\" or \"\\NewTerm{encoder}\\index{encoder}\". The message or word is an element  of $E$ that is to say $Q^k$. It is modified to provide the word: \n\t\n\tIt is the word $c$ that will be transmitted and read by any system to give a message received $x=(x_1,...,x_n)$ possibly flawed.\n\t\n\tLet us now denote $C=f(E)$ the image of $f$. Since $f$ is subjective by definition it is also injective, $f$ realized a bijection of $E$ on $C$ and $C$ can be considered as the set of all possible error coding messages. $C$ is named the \"\\NewTerm{code of length $n$}\\index{lengths of code}\", and the elements of $C$ are named the \"\\NewTerm{words}\\index{words}\" of the code. The cardinal of the code is by definition that of $C$ that is to say $\\text{Card}(C)$. To measure the degree of difference between two words $x$ and $y$ of $Q^n$, we use the \"\\NewTerm{Hamming distance}\\index{Hamming distance}\" $d_H$ defined by:\n\t\n\t\n\t\\begin{theorem}\n\tOn any set $Q$, we therefore define the application $d:Q^n\\times Q^n \\rightarrow \\mathbb{R}$ by:\n\t\n\tIf we denote by $\\delta_x$ the characteristic function of $x$:\n\t\n\tthen:\n\t\n\tis a distance.\n\t\\end{theorem}\n\tLet us now prove that following the topological axioms of a distance (\\SeeChapter{see section Topology}) that this is really a distance:\n\t\\begin{dem}\n\tOk let us prove the five axioms of a distance:\n\t\\begin{enumerate}\n\t\t\\item We will suppose that for the reader:\n\t\t\n\t\tis obvious (if not send us a request).\n\t\t\n\t\t\\item We will also suppose that:\n\t\t\n\t\tis obvious (if not send us a request).\n\t\t\n\t\t\\item We will also suppose that:\n\t\t\n\t\tis obvious (if not send us a request).\n\t\t\n\t\t\\item We will also suppose that:\n\t\t\n\t\twhere $d_H(x,y)=0$ mean that $x_i=y_i$ for $i=1...n$ and therefore that $x=y$.\n\t\t\n\t\t\\item Finally:\n\t\t\n\t\tIndeed:\n\t\t\n\t\tbut as:\n\t\t\n\t\tas $(1-\\delta_{x_i}(z_i))$ is equal to $1$ if $x_i\\neq z_i$ and $0$ otherwise, then:\n\t\t\n\t\\end{enumerate}\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tThe Hamming distance between the word \"\\textbf{ramer}\" and \"\\textbf{cases}\" or between \"\\textbf{0100}\" and \"\\textbf{1001}\" is equal to $3$.\n\t\\end{tcolorbox}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tCaution!!! Vectors will be denoted without the arrow in respect for tradition for this study field.\n\t\\end{tcolorbox}\n\tThe Hamming distance $d_H$ is therefore well a metric (\\SeeChapter{see section Topology}) as we just proved above and then we name \"\\NewTerm{Hamming space}\\index{Hamming space}\" on $Q$ the set $Q^n$ equipped with the metric $d_H$.\n\t\t\n\t\\textbf{Definition (\\#\\mydef):} If $Q$ is a group, the \"\\NewTerm{Hamming weight}\\index{Hamming weight}\" $w_H(x)$ of a word $x\\in Q^n$ is the number of nonzero components:\n\t\n\twhere $0$ is the word (vector) of $Q^n$ with all its components equal to the neutral element of $Q$. Furthermore, we have the following trivial property:\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tWhen $Q=\\{0,1\\}$ we will talk about \"\\NewTerm{binary code}\\index{binary code}\" (we'll see soon later an another form of writing for this binary set) of dimension $n$ equal to $2$.\n\t\\end{tcolorbox}\n\tThe \"\\NewTerm{minimum distance}\\index{minimum distance}\" of the code $C$ is the minimum distance between two distinct words of this code. We denote that integer by $d(C)$ or simply $d$ and therefore:\n\t\n\tor using the property of Hamming weight $d_H(x,y)=w(x-y)=w(x)$:\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tLet us consider the following redundant code denoted $(5, 4)$ for $4$ coded words of length $5$:\n\t\n\tThe Hamming distance of each of the pairs of code are:\n\t\n\tThe smallest non-zero minimum weight is therefore $3$ and the smallest Hamming distance is $3$.\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\textbf{Definitions (\\#\\mydef):}\n\t\\begin{itemize}\n\t\t\\item[D1.] A code $C$ of length $n$, of cardinal $M$ and of minimum distance $d$ is named a \"\\NewTerm{$(n, M, d)$ code}\". The numbers $n$, $M$, $d$ are the \"code parameters\". Thus, the code $(7, 4, 3)$ is a code of length seven, that is to say that the receiver receives seven bits, of length four, that is to say that once decoded, the message contains four symbols (letters) and the minimum distance between each codeword is three.\n\n\t\t\\item[D2.] We name \"\\NewTerm{minimum weight}\" of a $C$ code the integer:\n\t\t\n\t\\end{itemize}\n\tThe parameter $d$ plays an important role because it is closely related to the number of errors that can be corrected. Suppose that the encoded message is $c=(c_1,\\ldots,c_n)$ and that there were at least $e$ errors of transmission or reading. The resulting message obtained $x=(x_1,\\ldots,x_n)$ satisfies $d(x,c)\\le e$. We can fall back on $c$ from $x$ if, and only if, there exists a single code word located at a distance of $x$ less than or equal to $e$ (ie the center-to-center distance between two balls is equal to $2e$). In other words, it is necessary and sufficient that the closed balls of radius $e$ and centered on the elements of the code $C$ are disjoint. A code will correct $e$ errors if this condition is true.\n\n\tTherefore, a code $C$ of minimum distance $d$ corrects at most:\n\t\n\twhere $[]$ represents the integer part of a real number.\n\n\tIndeed, if a message of the code is at $d/2$ we will not be able to know to which message of the code (center of ball) it belongs since being (in a pictorial way) at the tangent of two balls. This is the reason why we will take $\\dfrac{d-1}{2}$ which is then the \"\\NewTerm{safe distance}\\index{safe distance}\" to correct as much as possible an erroneous message of the code. Moreover, since the number of errors is an integer, it comes the previous notation with the square brackets.\n\t\n\tIt is clear that the code can detect at most $d-1$ errors. Indeed, however how to distinguish an incorrect code from a correct code (code = coded message)? Apart from the fact that each element of the code is different (injective application of the set of messages in the set of encoded messages), it is also necessary to be able to differentiate among them those which are erroneous codes from those which do not Are not. Hence the $d-1$!!!\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tLet us consider the following redundant code denoted $(5, 4)$ for $4$ coded words of length $5$ whose minimal distance was therefore $d=3$:\n\t\n\tThis code therefore allows and make it possible to detect at most:\n\t\n\terrors and to correct at most:\n\t\n\tof them.\n\t\\end{tcolorbox}\n\t\n\t\\subsubsection{Block code}\n\tIn coding theory, a block code is any member of the large and important family of error-correcting codes that encode data in blocks. There is a vast number of examples for block codes, many of which have a wide range of practical applications. Block codes are conceptually useful because they allow coding theorists, mathematicians, and computer scientists to study the limitations of all block codes in a unified way. Such limitations often take the form of bounds that relate different parameters of the block code to each other, such as its rate and its ability to detect and correct errors.\n\n\t\\textbf{Definition (\\#\\mydef):} A \"\\NewTerm{block code}\\index{block code}\" of size $M$ and length $n$ defined on an alphabet of $q$ symbols ($1$ and $0$ for the binary language for example) is a set of $M$ vectors named the \"\\NewTerm{code words}\\index{code word}\". The idea is that each information word composed of $k$ symbols is associated with a single codeword composed of $n$ symbols. The vectors are therefore of length $n\\ge k$ and their components are $q$-ary (thus \"$2$-ary\" in the case of the binary language).\n\t\n\tExamples of block codes are Reed–Solomon codes, Hamming codes, Hadamard codes, Expander codes, Golay codes, and Reed–Muller codes. These examples also belong to the class of linear codes, and hence they are named \"linear block codes\". More particularly, these codes are known as algebraic block codes, or cyclic block codes, because they can be generated using boolean polynomials.\n\t\n\t\\textbf{Definition (\\#\\mydef):} A \"\\NewTerm{linear coding}\\index{linear code}\" means a set of code in which any linear combination (modular 2 sum most of time) of two codes within the set results in a code which also belong to the original set. Let's assume that you have a set of codes as in the figure below:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/linear_code.jpg}\n\t\t\\caption{Principle of a Linear code}\n\t\\end{figure}\n\tTake out any two codes from the set and take modular $2$ sum of them. The result is also a member of the set as shown below. Take any other two codes and try yourself.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe linearity of the block codes also mean that the $n$ symbols of the code word are obtained by a linear combination of the $k$ symbols of the information word.\n\t\\end{tcolorbox}\n\tLet us see an example!\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tLet us start from the following $M$ vectors based on $q = 3$ binary symbols (hence $k = 2$). In this case, we have $M=q^k$:\n\t\n\tWe then choose $n$ as equal to $6$ and we define a bijective mapping such that:\n\t% Please add the following required packages to your document preamble:\n% \\usepackage[table,xcdraw]{xcolor}\n% If you use beamer only pass \"xcolor=table\" option, i.e. \\documentclass[xcolor=table]{beamer}\n\t\n\tAs shows this example, of the particular block code conventionally denoted $(n, k)_q = (6, 3)_2$, the code has no particular structure. The decoding operation involves making an exhaustive comparison of the word received at the output of the channel with all the code modes before determining the most likely code word. This simple and stupid approach explains why many times this error correcting code is faster than many others...\n\t\\end{tcolorbox}\n\tThus, according to the above definition, a block code $C$ is the result of a injective application which associates with each vector formed by $k$ $q$-ary symbols ($k$ information symbols), an image vector of length $n$ with components in the same alphabet ($n$ encoded symbols):\n\t\n\t The encoding adds to the initial information $n-k$ additional symbols. The quantity:\n\t\n\tis named the \"\\NewTerm{rate of $C$}\\index{rate of error correcting code}\", or \"\\NewTerm{coding rate}\\index{cording rate}\". The block encoding operation is \"without memory\", in extenso the blocks are coded independently without any correlation between two consecutive blocks.\n\t\n\tNow it is convenient go back a little on Boole's Algebras (\\SeeChapter{see section Logical Systems}). To the $5$ axioms which define a Boolean algebra let us add a sixth one which gives it a structure of a field:\n\t\\begin{enumerate}\n\t\t\\item[A6.] The Boolean algebra (extension of a unitary ring by an axiom) with the law $*$ (or $\\wedge$) is a field.\n\t\\end{enumerate}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tLet us recall that a field is a non-zero ring in which every non-zero element is invertible.\n\t\\end{tcolorbox}\n\tIf we take the Boolean algebra formed by the $q=2$ elementary elements $\\{0,1\\}$ forming a binary set (alphabet), we actually have $1$ which is invertible since there exists $x$ such that:\n\t\n\twhich is $1$ itself!\n\n\tThis field is denoted $\\mathbb{q}=\\mathbb{F}_2$. In the area of error correcting codes, we often work in $\\mathbb{F}_2$ (single field with two elements) where for recall the addition is defined by:\n\t\n\tThe multiplication being defined by:\n\t\n\t\n\tTo return to our theory of codes: the set of messages $E=\\mathbb{F}_q^k$ can be equipped with a vector space structure of dimension $k$ on $\\mathbb{F}_q$ (\\SeeChapter{see section Set Theory}). Indeed, it suffices for this that $(E, +)$ to an abelian group and $*$ an external law defined by $\\mathbb{F}_q^k\\times \\mathbb{F}_q\\mapsto \\mathbb{F}_q^k$. If we decide to use only encoders that are linear (applications), the code $C=f(\\mathbb{F}_q^k)$ becomes a vector subspace of $\\mathbb{F}_q^n$ (because even if the application is bijective, since the body of the coded messages is finite, we necessarily have vector subspace of the vector space of all possible encoded messages).\n\t\n\t\\textbf{Definition (\\#\\mydef):} A \"\\NewTerm{linear code}\\index{linear code}\" of dimension $k$ and length $n$ is a vector subspace of dimension $k$ of $\\mathbb{F}_q^n$ (it is the way this is said..). If the minimum distance of $C$ is $d$, we say that $C$ is a \"\\NewTerm{$[n, k, d]_q$ code}\" or more simply \"\\NewTerm{code $[n,k]$}\".\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tLinear codes are therefore a special case of block codes as shown in the hierarchical scheme at the beginning of this section.\n\t\\end{tcolorbox}\n\tThe addition of the linearity constraint could undermine the quality of the code sought, but fortunately the performance study shows that the linear codes are very close to the best Block codes. Thus, linearity facilitates the study of block codes and allows the use of very powerful algebraic tools without reducing the class of linear blocks to an inefficient class.\n\t\n\tLet us denote by $G$ the matrix of the linear application $f:\\mathbb{F}_q^k \\mapsto \\mathbb{F}_q^n$. $G$ is a matrix of obviously dimension $n\\times k$ type and every word $c$ of $C$ is obtained from every word $x$ of $E$ by:\n\t\n\twhere $c=(c_1,\\ldots,c_n)\\in\\mathbb{F}_q^n$ and $x=(x_1,\\ldots,x_k)\\in\\mathbb{F}_q^k$ are line vectors with always $n\\ge k$. Thus $f(\\mathbb{F}_q^k)=C$.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe bases of $\\mathbb{F}_2^k$, $\\mathbb{F}_2^n$ are the common canonical bases (those we have often used in the section of Vector Calculus).\n\t\\end{tcolorbox}\n\t\n\t\\textbf{Definition (\\#\\mydef):} Let $C$ be a linear code $[n, k]$ and given $\\{g_1,g_2,\\ldots,g_k\\}$ the basis of C. A \"\\NewTerm{generating matrix}\\index{generating matrix}\" $G$ of $C$ is therefore a matrix $n\\times k$ whose columns are formed by the vectors $g_i$ of the basis (see the example further below).\n\n\tGiven $u=(u_1,\\ldots,u_k)$ the information word, in extenso the vector containing the $k$ information symbols. Then we can write the matrix relation linking the code word $c$ and the information word $u$ by:\n\t\n\t\n\t\\textbf{Definition (\\#\\mydef):} Let $C$ be a block code $[n, k]$. This code is named \"\\NewTerm{systematic code}\\index{systematic code}\", if the set of code words contains the $k$ unmodified symbols of the original information (we will return on this type of code further below). The remaining $n-k$ symbols are named \"\\NewTerm{parity symbols}\\index{parity symbols}\".\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe \"Hamming Code\" is such a code! In addition, systematic codes are special cases of block codes and we will return to their study further below.\n\t\\end{tcolorbox}\n\t\n\t\\textbf{Definition (\\#\\mydef):} Let $H$ be an $(n-k)\\times n$ matrix with elements in $\\mathbb{F}_q$, which satisfies $Hc=0$ for every word $c$ of a linear code $C$ (in other words: whose kernel is $C$). Then, $H$ is named the \"\\NewTerm{control matrix}\\index{control matrix}\" of the code $C$. Conversely, $c$ belongs to the code if and only if $Hc=0$. Otherwise there is a mistake!\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIt is easy to find $H$ because it is \"orthogonal\" to $G$ since the above definition implies:\n\t\n\tof course we must not take $H = 0$ in practice...\n\t\\end{tcolorbox}\n\tLet's see a companion example of all this with the Hamming code which is a systematic block code (caution!! it seem that there exist several definitions of a \"Hamming code!\"):\n\n\tThis method consists of doubling the information, sending as many parity bits as data bits. A first matrix for this purpose is:\n\t\n\tThe coding matrix $G$ above is of dimension dimension $n\\times k$, where $n$ is the number of bits received per packet, and $k$ is the number of bits per message containing the information (here $n=8$ and $k=4$). It automatically generates the parity bits specific to a message. For example, in order to send the message $1101$, in order to respect the matrix multiplication rule, consider this quartet as a column vector:\n\t\n\tSo by multiplying, we get:\n\t\n\tWe will therefore send a byte $11010110$, whose the first four bits form the message $u$ and the last four bits the parity bits, which are used to check the veracity / integrity of the message.\n\n\tThe corresponding control matrix $H$ is:\n\t\n\tThus, when the receiver receives the byte $11000110$ instead of $11010110$, the decoding gives as \"syndrome\":\n\t\n\tThe resulting column vector is therefore not zero. So there is an error! With the control matrix, the theory (see proof below) makes it possible to assert that as the vector obtained is the same as that which is in fourth position in the decoding matrix, the error is due to the fourth bit. As we are in base $2$, it is enough to change the $0$ into a $1$. This coding of the information is expensive, because it occupies twice as much bandwidth. However this is one of the most effective ways to secure information.\n\n\t\\begin{theorem}\n\tThe syndrom $s$ of a Hamming code corresponds to one of the column of the control matrix $H$.\n\t\\end{theorem}\n\t\\begin{dem}\n\tTo show that the syndrome of a Hamming code corresponds to one of the columns of the control matrix, we denote by $e_i$ the vectors-columns of the canonical basis on $\\mathbb{F}_2^n$, $e_i=(0,\\ldots,1,0,1,\\ldots,0)$ with $1$ in the $i$-th place. Given $c$ a code word. We thus have by the definition of $H$: $Hc=0$. Let us suppose that the received word, which we will denote by $\\tilde{c}$, is tainted by a single error and that this error is on the $j$-th bit. Threfore we have:\n\t\n\tand:\n\t\n\tTherefore it comes that:\n\t\n\tbut $He_j$ is the $j$-th column vector of the matrix $H$.\n\t\n\tThis shows us that when we $\\tilde{c}$ and we compute $H\\tilde{c}$ we get the column vector of the matrix $H$ located exactly at the location of the error (in this case $j$).\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tA null syndrome does not mean the absence of error(s). There are therefore undetectable error configurations!!!\n\t\\end{tcolorbox}\n\tLet us now write:\n\t\n\tThen we will notice that the matrices $G$ and $H$ of our companion example above are formed by the blocks $\\mathds{1}_4$ and $A$ in the following way:\n\t\n\tnamed the \"\\NewTerm{(canonical) generator matrix of a linear $(n,k)$ code}\", and:\n\t\n\ttje \"\\NewTerm{parity-check matrix}\\index{parity-check matrix}\".\n\t\n\tTherefore:\n\t\n\tBecause $1 + 1 = 0$ in $\\mathbb{F}_2$.\n\n\tIn general, if we work with the alphabet $\\mathbb{F}_2$ and if $G=\\begin{pmatrix}\\mathds{1}_k\\\\ A\\end{pmatrix}$ where $A$ is $(n-k)\\times k$ matrix then $H=(A\\quad -\\mathds{1}_k$ is also a control matrix because again:\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIn $\\mathbb{F}_2$, we have $\\mathds{1}_k=-\\mathds{1}_k$, since $1=-1$ this is why we wrote $H=(A\\quad -\\mathds{1}_k)$ in the previous companion example.\n\t\\end{tcolorbox}\n\t\n\t\\subsubsection{Systematic codes}\n\tAs we have mention it earlier above, let us come back on \"systematic codes\" that we have already defined.\n\t\n\tConstructing a systematic code consists as we already know in adding to each word $x=(x_1,\\ldots,x_k)$ of the message $n-k$ symbols $(c_{k+1},\\ldots,c_{k+n})$ linearly depending of the $x_i$ to get the code word $c=f(x)$.\n\n\tWe know already that symbols are named \"\\NewTerm{control bits}\\index{control bits}\" and (we will see another example just below):\n\t\n\twhere, for recall, $(\\mathds{1}_k|A)$ denotes the matrix $n\\times k$ obtained by writing one below the other, the identity matrix $\\mathds{1}_k$ of size $k$ and any matrix $A$.\n\t\n\tWe will say that a code $C$ is \"systematic\" if it has a generating matrix of the form $G=(\\mathds{1}_k|A)$.\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tWe propose to construct a systematic linear code with $n = k = 3$ as example. We will denote by $a_1,a_2,a_3$ the information bits. The control bits $a_4,a_5,a_6$ will be defined by:\n\t\n\tThe generating matrix $G$ is such that its upper part is the identity matrix of dimension $3$ (we had the same thing for the Hamming code). The first line $(110)$ of the matrix $A$ corresponds to the expression of the control bit $a_4$:\n\t\n\tetc. For each control bit.\\\\\n\n\tThe generating matrix $G$ is then written:\n\t\n\tBy multiplying this matrix by the $2^3=8$ possible vectors (the words consisting of three bits of information), we get the following code words:\n\t\n\tWe thus find that the minimum weight of the code words is $3$. Therefore the code detects $3-1 = 2$ errors and can correct of them $\\left[\\dfrac{3-1}{2}\\right]=1$.\n\t\\end{tcolorbox}\n\tThe reader interested can refer to out MATLAB™ companion book to see how to handle or generate error correcting codes.\n\n\t\\begin{flushright}\n\t\\begin{tabular}{l c}\n\t\\circled{60} & \\pbox{20cm}{\\score{3}{5} \\\\ {\\tiny 11 votes,  58.18\\%}} \n\t\\end{tabular} \n\t\\end{flushright}\n\n\t%to make section start on odd page\n\t\\newpage\n\t\\thispagestyle{empty}\n\t\\mbox{}\n\t\\section{Automata Theory}\n\t\\lettrine[lines=4]{\\color{BrickRed}T}he purpose of this section is to study the theoretical aspect of the computer/machine concept. We are located here at the level of mathematics and logic, regardless of any reference to a rea l specific computer/machine (or software). We will look at how this theoretical machine will take make acquisition of digital data, of whatever nature, to do treatment on it or to solve a general problem. We will then be taken to see that, from this point of view, any theoretical machine is reducible in its operating principle, to an ideal machine. Thus, we can say that all computers, or all programs are equivalent to each other, as the purpose of computer, in its theoretical definition, is universal, that is to say the capacity to treat all actually treatable problems.\n\t\n\tModern computing is the result of research undertaken in the early 20th century by Bertrand Russell and Alfred North Whitehead to constitute a formal mathematical system where any proposal could be proved by a logical calculation (see section Proof Theory) . David Hilbert and Kurt Gödel accomplished decisive steps in the exploration of this program. In 1931 Gödel proved that (recall):\n\t\\begin{enumerate}\n\t\t\\item It may be that in some cases we can prove one thing and its opposite (inconsistency).\n\t\t\n\t\t\\item In any formal mathematical system there are mathematical truths that can not be proved (incompleteness)\n\t\\end{enumerate}\n\tGödel's theorem thus ruin the dream to make from mathematics a perfectly coherent deductive system, but from the intellectual activity around the Principia project of Russel and Whitehead will be released the founding ideas of computer science. This brings Alan Turing in 1936, after Gödel, to tackle the problem of decidability.\n\t\n\t\\textbf{Definition (\\#\\mydef):} A system is named \"\\NewTerm{decidable system}\\index{decidable system}\" if there is an effective procedure for distinguishing provable proposals of others. To define more rigorously the concept of effective procedure, Alan Turing developed the concept of \"automata\", hereinafter named \"\\NewTerm{Turing machine}\\index{Turing machine}\" (see example below), which allows him to clarify the concept of implementation of an \"\\NewTerm{algorithm}\\index{algorithm}\".\n\t\n\t\\textbf{Definition (\\#\\mydef):} A \"\\NewTerm{Turing Complete language}\\index{Turing Complete language}\" is a language with at least a conditional and a while-loop construct - such a language can be used to implement a Turing machine that is \"powerful\" enough to perform any realizable algorithm \n\t\n\tInventing effective procedures (algorithms) is to determine a sequence of elementary operations that perform the calculations/treatments necessary to solve problems for which there are computable solutions (there are unsolved problems and incalculable solutions as we have seen during our study of complexity in the section of Theoretical Computing). Turing also proved that its calculation model is universal, that is to say that all Turing machines are equivalent (we will prove this below). It makes the assumption that any algorithm can be computed by a Turing machine. These ideas underpin the theory of computer programming.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThis section would have normally be placed at the first position of this Chapter but it seemed wiser to do first hand on concrete examples of theoretical computer before moving to the abstract formalism of their executions. This is one of the reasons why we will return here briefly on the concepts of algorithms, complexity, formal logical systems, proof theory and information (see all sections with the corresponding name). Furthermore, for this section, an experience in the development of computer software is a big plus for understanding certain concepts (or to imagine practical applications).\n\t\\end{tcolorbox}\n\tBefore we begin, it should be useful for the reader to have a non-exhaustive overview of the applications of Language and Automata Theory: specification of programming languages, compilation, pattern matching (in a text, in a database on the web, in the genes .. .), text compression, program verification, electronic computers, encoding for transmission, encryption, decoding of the genome, language, cognitive science, etc.\n\t\n\tThe modern computing science (in the mathematical point of view only) was born from research undertaken in the early 20th century by Bertrand Russell and Alfred North Whitehead to constitute the mathematical formal system where any proposal could be proved by a logical calculation (\\SeeChapter{see section Proof Theory}) . David Hilbert and Kurt Gödel accomplished decisive steps in the exploration of this program. In 1931 Gödel proved that (recall):\n\t\\begin{enumerate}\n\t\t\\item It may be that in some cases we can prove one thing and its opposite (inconsistency).\n\t\n\t\t\\item In any formal mathematical system there are mathematical truths that can not be proven (incompleteness)\n\t\\end{enumerate}\n\tGödel's theorem then  ruin the dream of mathematicians to bring mathematics into a perfectly coherent deductive system, but the intellectual ferment around the \\textit{Principia} project of Russel and Whitehead will release the founding ideas of theoretical computing. That brings in 1936 Alan Turing, after Gödel, to tackle the problem of decidability.\n\t\n\t\\textbf{Definition (\\#\\mydef):} A system is named \"\\NewTerm{decidable system}\\index{decidable system}\" if there exist an effective procedure to distinguishing demonstrable proposals of the others. \n\n\tTo define more rigorously the notion of effective procedure, Turing developed the concept of \"\\NewTerm{Automata}\\index{Automata}\", hereinafter named \"\\NewTerm{Turing machine}\" (see example below), which allows him to clarify the concept of running an \"\\NewTerm{algorithm}\" (\\SeeChapter{see section Theoretical Computing}).\n\t\n\tInvent effective procedures (algorithms) consists to determine a sequence of elementary operations that perform the calculations necessary to solve problems for which there are computable solutions (there are unsolved problems and incalculable solutions as we seen during our study of complexity in the section of Theoretical Computing). Turing also proved that its calculation model is universal, that is to say, all Turing machines are equivalent (we will prove it later below). He made the assumption that any algorithm can be computed by a Turing machine. These ideas underlying the theory of computer programming and was one important factor of winning the second World War thanks to the machine developed by Turing to uncrypt the Nazi Enigma cypher machine (a romance movie has been made about this subject in 2015 with Alan Turing as major role).\n\n\t\\subsection{Von Neumann machine}\n\tWe due to John von Neumann to conceive in 1945 the general architecture of the concrete apparatuses which will carry out the calculations according to the Turing model, an architecture so efficient and elegant that the computers of today are still constructed on these principles.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIn a way, we can say that this decade between 1936 and 1945 (corresponding well to the Second Worl War) saw the birth of computer science, which went from the mathematical and logical intellectual construction stage to the application of these ideas to the realization of concrete physical systems.\n\t\\end{tcolorbox}\n\tHere is the diagram of the of a von Neumann architecture:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/von_neumann_machine.jpg}\n\t\t\\caption{Principle of the von Neumann machine}\n\t\\end{figure}\n\tThe Control Units, Arithmetic-Logic Unit (ALU), and Primary Memory constitue all three the \"Central Unit\", or \"Processor\", of the computer. The processor consists of electronic circuits that can perform actions. The set of actions wired in the processor constitutes the instruction set of the processor and determines the basic language of its use, named \"\\NewTerm{machine language}\".\n\n\tThe role of the Control Unit is to enable the desired action (instruction) to be triggered at the desired moment. This instruction can belong to the Arithmetic-Logic Unit, to the Memory Unit or to the Control Unit itself. An instruction can also consult the contents of the Primary Memory unit (the \"read\") or modify the contents of that memory (the \"write\"). In general, an action consists in either consulting or modifying the state of the memory or one of the registers (which are special memory elements incorporated in the central processing unit), or triggering an input-output operation (communication with the outside world and in particular a human user).\n\t\n\tThe memory is made up of elements that can take states. A basic element of the memory can take two distinct states and can be used to represent an elementary data item, or \"bit\" (\\SeeChapter{see section Logical Systems}). This representation of a data element by a memory element is named a \"\\NewTerm{code}\". A memory with many bits allows the coding of complex data, within the limit of the size of the memory.\n\n\tThe way in which the central unit, memory and I/O devices (input/output) communicate is generically named a \"\\NewTerm{bus}\" (it is, in a way, the highway where data flows from one point to another Using addresses). In a somewhat formal way, a bus is a complete connected graph (SeeChapter{see section Graphs Theory}), which means in common language that all the elements connected to the bus can communicate with one another.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe \"code\" makes bits and groups of symbols match together. The simplest symbols are numbers and letters. To represent complex data, you can define methods, rules for grouping symbols, and associate a data element with a symbol group constructed according to the rules.\n\t\\end{tcolorbox}\n\t\\textbf{Definition (\\#\\mydef):} We will name \"\\NewTerm{language}\\index{language}\" a set of symbols or groups of symbols, constructed according to certain rules, and which are the \"\\NewTerm{words}\\index{word}\" of that language. A \"\\NewTerm{language syntax}\\index{language syntax}\" is the set of construction rules for language words.\n\t\n\tThe memory of the computer (this is the basic idea of von Neumann) contains information of two types: Programs and data. The programs and the data are represented with the same symbols, only the semantics allows to interpret their respective texts. Moreover, the text of a program can sometimes be considered as data for another program, for example a program of translation from one language to another.\n\t\n\t\\subsection{Turing machine}\n\tIt is important to be convinced (it will perhaps not be done in one day...) that all the programs we can write in different languages are equivalent!!! The Turing machine is a model of an automata whose description is very low-level (before going on to a much more formal definition). The von Neumann architecture, designed to efficiently perform the processes described by a Turing machine, generates imperative languages (see definition in remarq R1 below). Any program, functional or imperative, intended to be executed, will be translated into an imperative language, the \"machine language\" of the computer used. The coherence of computer science and the semantic equivalence of programs written in various languages which ensure the validity of this operation are the result not of chance but of a common original theoretical conception. Gödel, Church, von Neumann and Turing were all in Princeton in 1936...!\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\\textbf{R1.} The first evolved languages that have appeared are so-named \"\\NewTerm{imperative languages}\", based on the notion of the state of memory (it is the \"\\NewTerm{assembly language}\\index{assembly}\" by the way!). These languages, inspired by John von Neumann's model, include, like machine language, instructions that produce changes in memory (assignment instruction). The writing of a program in imperative language consists in writing the sequence of instructions which will cause the successive states by which the memory will have to pass so that, starting from an initial state allowing the initialization of the program, it arrives in a state providing final results.\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.91]{img/computing/assembly_demo.jpg}\n\t\t\\caption{Assembly language \"Hello World\" demo}\n\t\\end{figure}\n\t\\textbf{R2.} In addition to \"computational languages\", we distinguish in computer science \"sequential languages\", \"interpreted languages\", \"description languages\" and \"compiled languages\".\n\t\\end{tcolorbox}\n\tA formal model for an effective procedure (to describe an algorithm) must possess certain properties. First, each procedure must receive a finite definition. Secondly, the procedure must consist of separate steps, each of which must be capable of being accomplished mechanically. In its simplicity, the Turing machine composed of the following elements answers to this program:\n\t\\begin{enumerate}\n\t\t\\item An infinite memory represented by a ribbon divided into boxes. Each square of the ribbon may be given a symbol of the alphabet defined for the machine;\n\t\n\t\t\\item A reading head capable of traversing the tape in both directions;\n\t\n\t\t\\item A finite set of states among which we distinguish an initial state and the other states, named \"\\NewTerm{accepting states}\"\n\t\n\t\t\\item A transition function which, for each state of the machine and each symbol under the read head, specifies: the next state, the character that will be written on the ribbon instead of the one that was under the head The direction of the next playback of the playback head.\n\t\\end{enumerate}\n\tOne can equip his Turing Machine with the finite alphabet of his choice. His ribbon can be infinite in either direction or in one. It may even have several ribbons. It is shown that these various machines are equivalent.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.7]{img/computing/turing_machine.jpg}\n\t\t\\caption{Turing Machine principle}\n\t\\end{figure}\n\tWe are then led to the following simplistic definition:\n\t\n\t\\textbf{Definition (\\#\\mydef):}\n\tA \"\\NewTerm{finite automate}\" is a mathematical model of systems having a finite number of states and that actions (external or internal) can move from one state to another. The external actions are represented by the symbols of an alphabet $\\mathcal{A}$; The internal actions (invisible, silent, or spontaneous) are represented by a symbol not belonging to the aforementioned alphabet.\n\n\tAn automate is represented by a graph (\\SeeChapter{see section Graph Theory}) whose vertices are states and with each arc is associated the recognition of one or more letters.\n\n\tFinite automata are used to model and control finite-state systems and to solve common problems: lexical analysis, search of patterns in text, genome analysis, etc.\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Examples:}\\\\\\\\\n\tE1. A finite and deterministic automate which recognizes all integers whose writing is normalized (regular language), that is to say not starting with $0$ (the numbers in the circles are just there to describe the order in which the controller performs the operation):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.91]{img/computing/finite_automate_example_01.jpg}\n\t\t\\caption{First example of a finite automata}\n\t\\end{figure}\n\tDescription: The automata receives an integer in input \\circledtext{1}, it looks at whether this number starts with a $0$ or it is a number between $1$ and $9$. If the number starts with zero, the controller exits and stop at \\circledtext{3}. Otherwise, the controller goes to \\circledtext{2} and analyzes the numbers one after the other until it reaches the end and then stops and goes out at \\circledtext{3}.\\\\\n\t\n\tE2. A finite and deterministic automata which recognizes a numerical input in a regular language spreadsheet (for example: $+12,3$ or $08$ or $-15$ or $5\\text{E}12$ or $14\\text{E}-3$):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.91]{img/computing/finite_automate_example_02.jpg}\n\t\t\\caption{Second example of a finite automata}\n\t\\end{figure}\n\tIn other words, it is enough to recognize a language of the form:\n\t\n\twhich is indeed regular, where $\\varepsilon$ is the empty word, $\\mathcal{A}$ is the alphabet $\\{0,1, \\ldots, 9\\}$ and equation the set of words (in extenso of numbers) that can be written with $\\mathcal{A}$.\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\tE3.  A finite and deterministic automata recognizing all the multiples of $3$, regular language type (in other words if such a multiple is found, the automata gives an output, otherwise nothing):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/finite_automate_example_03.jpg}\n\t\t\\caption{Third example of a finite automata}\n\t\\end{figure}\n\t\\end{tcolorbox}\n\tI strongly recommend any reader that want the be familiar with complete Turing Machines to practice the challenge that Google made with the Turing Doodle (it is probably \"complete\" but not sure):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/turing_doodle.jpg}\n\t\t\\caption{Turing Doodle (source: Google)}\n\t\\end{figure}\n\tavailable here:\n\t\\begin{center}\n\t\t\\url{http://www.sciences.ch/htmlen/turing_doodle/}\n\t\\end{center}\n\tThe purpose of that Doodle is to change the algorithm so that when it is executed and the machine stops the content of the tape is compared to the content of the display on the right top corner. When the comparison is successful the player will go to the next level with another algorithm to change... and so on...\n\t\n\tSome passionate of Turing Machines have build real life small and beautiful electronic Turing machines as the one visible in the picture below (perhaps they build as a hobby or sell it to schools for education purposes???):\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.7]{img/computing/turing_machine_photo.jpg}\n\t\t\\caption{Turing Machine (source: ?)}\n\t\\end{figure}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tRelative to a common question: Yes! Artificial intelligence are Turing Machines and so is also the Brain (at the difference that its memory is limited).\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\subsection{Chomsky hierarchy}\n\tThe \"\\NewTerm{Chomsky hierarchy}\\index{Chomsky hierarchy}\" is a classification of the languages described by the formal grammars proposed in 1956 by the linguist Noam Chomsky. It is widely used today in computing, especially for the design of interpreters or compilers, or for the analysis of natural languages.\n\t\n\tIt is necessary before to define certain concepts!\n\t\n\t\\subsubsection{Formal language}\n\t\\textbf{Definition (naive version \\#\\mydef):} In a broad range of contexts (scientific, legal, etc.) we designate naively by \"\\NewTerm{formal language $\\mathcal{L}$}\\index{formal language}\" a more formalized and more precise form of expression than the everyday natural language (the two do not necessarily go together).\n\t\n\tIn mathematics, logic and computer science, a formal language is formed by:\n\t\\begin{enumerate}\n\t \t\\item A set of words obeying to strict logical rules (formal grammar or syntax).\n\n\t\t\\item Possibly of an underlying semantics (the strength of formal languages is to be able to disregard such semantics, which makes theories reusable in several models).\n\t\\end{enumerate}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThus, while a particular payroll or inverse matrix calculation will always remain a payroll or inverse matrix calculation, a group theorem will apply both to the set of integers and to the transformations of the Rubik cube.\n\t\\end{tcolorbox}\n\tThe formal language of a scientific discipline is therefore actually a language obeying strict formal syntax and which will serve to expose statements precisely, if possible concisely and without ambiguity, and is in opposition to natural language.\n\n\tFormal language has the advantage of making easy the manipulation and transformations these statements. Indeed, we will generally have precise transformation rules (development of logical formulas, normal forms, contrapositions, commutativity, associativity, etc.) that can be applied without even knowing the meaning of the statements to be transformed or the meaning of the transformation. It is therefore a powerful exploration tool, and it is the only language that allows machines to \"do mathematics\".\n\n\tThe disadvantage is obvious: not knowing the meaning of the statement prevents us from knowing which are the relevant transformations and hurts the intuition of the reasoning. Thus, it is good to know how to quickly read a statement in formal language and to translate it just as quickly into one or more more natural language statements.\n\t\n\tThis is where the limit of what we call \"proof-aid software\" lies: of course, the computer has (for now...) no intuition. The skill of the designer of such a program is to find ways for the computer to understand.\n\n\tGiving relevant meaning to a programming language in order to run its programs is relatively easy, because these formal languages have been designed to mean sequences of elementary actions of the machine. To prove a program (to prove that the algorithm ends in a finite number of times) or a mathematical theorem (which is almost the same thing), there is, on the other hand, no infallible method, the correction of a program being an undecidable decision problem. Thus, the prover must simply apply certain heuristics (a technique consisting in learning little by little taking into account what has been done beforehand) and often calling for help to the human user (same as humans do in fact...!). However, thanks to its heuristics and computing power, the computer explores thousands of ways that the human user would not have been able to test in several years, thus accelerating the work of the mathematician, physicist or engineer.\n\t\n\t\\textbf{Definition (\\#\\mydef):} As an object of study, a \"\\NewTerm{formal language $\\mathcal{L}$}\\index{formal language}\" is defined as a set $\\mathcal{W}$ of finite-length words $w_i$ (ie strings) deduced from a certain finite alphabet $\\mathcal{A}$, that is to say a free monoid (the set of words formed on an alphabet, provided with the internal law of concatenation - which is a law of composition - is a monoid which we name \"free monoid\", which empty word is the neutral element) on this alphabet.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThus, while a particular payroll or inverse matrix calculation will always remain a payroll or inverse matrix calculation, a group theorem will apply both to the set of integers and to the transformations of the Rubik cube.\n\t\\end{tcolorbox}\n\t\n\t\\subsubsection{Syntax}\n\t\\textbf{Definition (\\#\\mydef):} The \"\\NewTerm{syntax}\\index{syntax}\" is the branch of linguistics that studies the way in which \"free morphemes\" (words) combine to form \"syntagmas\" (nominal or verbal) that can lead to propositions that can combine in turn to form statements.\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tThe syntagma (sentence): \\textit{a modest house of red bricks} is encompassed in the upper syntagma, that is, the complete sentence. But this same sentence \\textit{a modest house of red bricks} includes among its elements, the lower syntagma \\textit{of red bricks}, complement of the name house.\n\t\\end{tcolorbox}\n\t\n\t\\textbf{Definitions (\\#\\mydef):} \n\t\\begin{enumerate}\n\t\t\\item[D1.] In grammar school, a \"\\NewTerm{proposition}\\index{proposition}\" is a syntagma articulated around a verb. This notion is mainly used in language learning.\n\n\t\t\\item[D2.] A \"\\NewTerm{statement}\\index{statememt}\" in linguistics is everything that is pronounced by a speaker between two breaks. Syntactically, the statement can therefore extend from the simple word to the length of a sentence (even to a discourse), through the syntagma.\n\t\\end{enumerate}\n\tThe term \"syntax\" is also used in computer science, where its definition is similar, modulo a different terminology... Thus the syntax is the respect, or the non-respect, of the formal grammar of a computer language, that is to say of the rules of arrangement of the lexemes (which in computer science are only lexical entities) in more complex terms, often: \"programs\". In the theory of formal languages, what plays the role of lexeme is usually named \"\\NewTerm{letter}\\index{letter}\" or \"\\NewTerm{symbol}\\index{symbol}\", and the product terms are named \"\\NewTerm{words}\\index{words}\".\n\t\n\tFrom a purely grammatical point of view, the study of syntax concerns three kinds of units:\n\t\\begin{itemize}\n\t\t\\item The \"\\NewTerm{sentence}\\index{sentence}\", which is the upper limit of the syntax.\n\n\t\t\\item The \"\\NewTerm{word}\\index{word}\", which is its basic constituent, sometimes named \"\\NewTerm{terminal element}\\index{terminal elements}\"\n\n\t\t\\item The \"\\NewTerm{syntagma}\\index{syntagma}\", which is its intermediate unit\n\t\\end{itemize}\n\tThe syntactic relations between these different units can be of two kinds:\n\t\\begin{itemize}\n\t\t\\item The \"\\NewTerm{coordination}\" when the elements are of the same status\n\n\t\t\\item The \"\\NewTerm{subordination}\" in the opposite case (when there is subordination, the subordinate element fulfills a syntactic function determined with respect to the higher level unit)\n\t\\end{itemize}\n\tThe study of syntax will take into account, in particular, the nature (or category or species) of the words, their form (morphology) and their function. It is why we speak more generally of \"\\NewTerm{morphosyntactic relations}\".\n\t\n\t\\subsubsection{Grammar}\n\t\\textbf{Definition (naive version \\#\\mydef):} A \"\\NewTerm{formal grammar $\\mathcal{G}$}\\index{formal grammar}\" is a formalism used to define a syntax and therefore a formal language $\\mathcal{L}$, that is to say a set $\\mathcal{W}$ of words $w_i$ on a given alphabet $\\mathcal{A}$.\n\t\n\tThe concept of formal grammar is particularly used in the following fields:\n\t\\begin{itemize}\n\t\t\\item Programs compilation (syntactic analysis)\n\n\t\t\\item The analysis and processing of natural languages\n\n\t\t\\item Calculation models (automata, circuits, Turing machines, etc.)\n\t\\end{itemize}\n\tTo define a grammar, we need (see the example below to understand):\n\t\\begin{enumerate}\n\t\t\\item An alphabet of non-terminal items\n\n\t\t\\item An alphabet of terminals item;\n\n\t\t\\item An initial symbol (the axiom) taken among the non-terminals items;\n\n\t\t\\item A set of production rules.\n\t\\end{enumerate}\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Examples:}\\\\\\\\\n\tE1. We can define arithmetic expressions in the following way (writings that we often find in the Proof theory) where $|$ is the symbol commonly use for the logical \"OR\":\n\t\\begin{center}\n\t\t\\texttt{exp}$\\rightarrow$ \\texttt{exp+exp}$|$\\texttt{exp*exp}$|$\\texttt{(exp)}$|$\\texttt{num}\n\t\\end{center}\n\twhere \\texttt{exp} means \"expression\" or:\n\t\\begin{center}\n\t\t\\texttt{num}$\\rightarrow 0$\\texttt{num}$|1$\\texttt{num}$|2$\\texttt{num}$|\\ldots|9$\\texttt{num}$|1|2|\\ldots|9$\n\t\\end{center}\n\tThe non-terminals here are explicitly \\texttt{exp} and \\texttt{num}, the terminals are \\texttt{+}, \\texttt{*}, (\\texttt{,}) and the digits. The axiom is \\texttt{exp}.\n\t\n\tE2. The syntax of classical propositional logic can be defined in the following way (\\SeeChapter{see section Proof Theory}):\n\t\\begin{gather*}\n\t\t\\mathcal{F}=\\text{Atom}|F\\vee F|F\\wedge F|F\\rightarrow|F\\neg F|\\exists x F|\\forall xF\n\t\\end{gather*}\n\t\\end{tcolorbox}\n\tThe most commonly used types of grammars are:\n\t\\begin{enumerate}\n\t\t\\item Left linear grammars that produce the same languages as regular expressions (this is what we are interested to in in this section)\n\n\t\t\\item Context-free grammar (example above)\n\n\t\t\\item Contextual grammars (this type of grammar requires a mathematical formalism and can not be defined without it)\n\t\\end{enumerate}\n\tA language is therefore a set of words $\\mathcal{W}$, which are simply sequences of symbols chosen from a finite alphabe set $\\mathcal{A}$. The languages of the Chomsky's hierarchy consist of words that respect a particular formal grammar. What distinguishes them within the framework of classification is the nature of the grammar.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tMost often, the symbols that are considered are formed of several characters, so that they correspond rather to what \"words\" in the current language. When there is ambiguity, for example in lexical analysis (vocabulary) and syntactic analaysis (part of the grammar that deals with the function and the disposition of words and propositions in the sentence), we speak of \"characters\" for the symbols of the alphabet used to encode the information, and of \"lexemes\" for the symbols of the abstract alphabet, which are the basic units of the language. Similarly, the \"words\" of the language correspond rather to \"sentences\" or \"texts\".\n\t\\end{tcolorbox}\n\tThe Chomsky hierarchy consists of the following $4$ levels, from the most restrictive to the broadest one:\n\t\\begin{enumerate}\n\t\t\\item[L1.] The \"\\NewTerm{languages of type 3}\" or \"\\NewTerm{regular language}\\index{regular languages}\": these are the languages defined by a regular grammar or a regular expression, or the languages recognizable by a finite-state automata.\n\n\t\t\\item[L2.]  The \"\\NewTerm{languages of type 2}\" or \"\\NewTerm{algebraic languages}\\index{algebraic language}\" also named \"\\NewTerm{context-free languages}\\index{context-free languages}\": these are the languages defined by a context-free grammar, or the languages recognizable by a non-deterministic stack automata. In this category are for example the computer programming languages.\n\n\t\t\\item[L3.]  The \"\\NewTerm{languages of type 1}\"  or \"\\NewTerm{context sensitive languages}\\index{ontext sensitive languages}\": these are the languages defined by a contextual grammar, or the languages recognizable by a non-deterministic Turing machine with a length bounded by a fixed multiple of the word length's (these types of languages require a mathematical formalism and can not be defined without it).\n\n\t\t\\item[L4.]  The \"\\NewTerm{languages of type 0}\", or \"\\NewTerm{recursively enumerable languages}\\index{recursively enumerable languages}\": This set includes all languages defined by a formal grammar. It is also the set of languages acceptable by a Turing machine (which is allowed to loop on a word that is not of the language).\n\t\\end{enumerate}\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/chomsky_hierarchy.jpg}\n\t\t\\caption{Chomsky hierarchy}\n\t\\end{figure}\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\\textbf{R1.} In addition to the $4$ types of the Chomsky hierarchy, there are remarkable intermediate classes! For example between types $3$ and $2$: deterministic non-contextual languages, recognizable by a deterministic stack automata and languages between levels $1$ and $0$: recursive languages, that is to say, recognizable by a Turing machine (the latter must refuse words which are not in the language).\\\\\n\t\n\t\\textbf{R2.} The $4$ types of languages and $2$ of intermediate languages above are strictly included in each other.\n\t\\end{tcolorbox}\n\tA parser for a formal language is a computer program that decides whether a given input word belongs or not to the language, and possibly constructs a derivation of it.\n\n\tThere are systematic methods for writing type $2$ or $3$ language analysis programs (parsers). Interpreters or compilers almost always include a phase of lexical analysis, which consists of recognizing type $3$ languages, followed by a phase of syntactic analysis that is a in fact a type $2$ language analysis.\n\n\tWe can now finally in a vulgarize way (always with the aim of paving the way) define what an automata is in the Chomsky hierarchy.\n\t\n\t\\subsubsection{Associated automata}\n\t\\textbf{Definition (naive version \\#\\mydef):}  In the field of theoretical computing, an \"\\NewTerm{automata}\\index{automata}\" is a machine to process information by a formal model (a Turing machine) on a given language. So:\n\t\\begin{itemize}\n\t\t\\item On a \"\\NewTerm{finite language}\\index{finite language}\" (language containing a finite number of words), the associated automata is a machine comparing a text with that which is stored in a read-only memory. The grammar associated with a finite language is a list of the words of the language.\n\t\t\n\t\t\\item On a \"\\NewTerm{regular language}\\index{regular language}\" (language where the syntactic correction is verified by storing only a finite number of information), the associated automata is the \"deterministic finite automaton\" (that is, for each word entered, there is only one possible path of the graph) or the \"non-deterministic finite automata\". The grammar associated with a regular language is a left linear grammar.\n\t\t\n\t\t\\item On an \"\\NewTerm{algebraic language}\" (language where the main syntactic constraint are the parenthesis), the associated automata is the \"pushdown (stack) non-deterministic automata\". The associated grammar is the algebraic grammar.\n\t\t\n\t\t\\item On a \"\\NewTerm{bounded language}\" (description requiring a mathematical formalism), the associated automata is the  \"linearly bounded automata\". The associated grammar is the contextual grammar.\n\t\t\n\t\t\\item On a \"\\NewTerm{decidable language}\" (an intelligent being manages to find a process to know whether or not one he is in the language), the associated automata is a Turing machine that stops on all data. There is no grammar associated to it.\n\t\t\n\t\t\\item On a \"\\NewTerm{semi-decidable language}\" (an intelligent being manages to find a process to know whether or not one he is in the language), the associated  automata is the Turing machine (thus contains conditional structures and loops). The associated grammars are the \"semi-Turing grammar\", the \"de Vangarden grammar\" or the \"affixed grammars\".\n\t\\end{itemize}\n\t\n\t\\pagebreak\n\t\\subsection{Terminology}\n\tThe automata therefore work mainly on letters, words, sentences and languages. In order to construct rigorous and optimal analysis methods and treatment on the subject it is interesting to formalize the treated objects. This is what we will do initially by defining these latter and their mathematical properties (which are very intuitive).\n\t\n\t\\subsubsection{Words}\n\t\\textbf{Definitions (\\#\\mydef):}\n\t\\begin{enumerate}\n\t\t\\item[D1.] An \"\\NewTerm{alphabet $\\mathcal{A}$}\\index{alphabet}\" is a set whose elements are the \"\\NewTerm{letter $\\ell$}\". The alphabets are always supposed to be finished.\n\t\t\n\t\t\\item[D2.] A \"\\NewTerm{word $w_i$}\\index{word}\" is a finite sequence of \"letters\" which we denote by juxtaposition:\n\t\t\n\t\n\t\t\\item[D3.] The \"\\NewTerm{empty word}\", denoted $\\varepsilon$, is the only word composed of no letters.\n\t\n\t\t\\item[D4.] The \"\\NewTerm{length}\" of a word $w$ is the number of letters that compose it, and is denoted $|w|$ (the empty word $\\varepsilon$ is the only word of length $0$).\n\t\n\t\tThe \"\\NewTerm{concatenation product}\\index{concatenation product}\" of two words $w_1=a_1a_2\\ldots a_n$ and $w_i=b_1b_2\\ldots b_m$ is the word $w_1w_2$ obtained by juxtaposition (concatenation):\n\t\t\n\t\tOf course (trivial), we have:\n\t\t\n\t\tWe denote by $\\mathcal{A}^{*}$ the set of words on $\\mathcal{A}$.\n\t\t\n\t\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\t\tGenes are words on the ACGT alphabet, proteins are words on a $20$-letter alphabet. The natural integers, written in base $10$, are words on the alphabet of the decimal digits...\n\t\t\\end{tcolorbox}\n\t\tLet $\\mathcal{A}$ be an alphabet. Let $\\mathcal{B}$ be a subset of $\\mathcal{A}$ . For any word $w\\in \\mathcal{A}$, the length in  $\\mathcal{B}$ of $w$ is the number of occurrences of letters of $\\mathcal{B}$ in the word $w$. This number will be denoted $|w|_{\\mathcal{B}}$.\n\t\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\t\tIn particular, we have trivially $|w|=|w|_{\\mathcal{A}}$.\n\t\t\\end{tcolorbox}\n\t\tFor every letter $\\ell\\in\\mathcal{A}$, $|w|_{\\ell}$ is the number of occurrences of $\\ell$ in $w$. We have:\n\t\t\n\t\t\n\t\t\\item[D5.] Given $w=\\ell_1\\ell_2\\ldots\\ell_n$, with $\\ell_1\\ell_2\\ldots\\ell_n\\in\\mathcal{A}$. The \"\\NewTerm{mirror word}\\index{mirror word}\" of $w$ is the word denoted $\\widetilde{w}$ defined by:\n\t\t\n\t\tObviously:\n\t\t\n\t\t\n\t\t\\item[D6.] A word $u$ is a \"\\NewTerm{prefix}\" or \"\\NewTerm{left factor}\" of a word $v$ if there is a word $x$ such that $ux=v$. The word $u$ is moreover a \"\\NewTerm{strict prefix}\" or \"\\NewTerm{eigen-prefix}\" if $u\\neq v$. Symmetrically, $u$ is a \"\\NewTerm{suffix}\" or \"\\NewTerm{right factor}\" of $v$ if $xu=v$ a word $x$. If $u\\neq v$, then $u$ is \"\\NewTerm{strict suffix}\" or \"\\NewTerm{eigen-suffix}\". The number of prefixes of a non-empty word $v$ is $1+|v|$ (the empty word always being a prefix, we always have any non-empty word that has at least the empty word as a prefix).\n\t\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\t\tThe word $w=aabab$ on $\\mathcal{A}=\\{a,b\\}$ has $12$ different possible factors:\n\t\t\n\t\t\\end{tcolorbox}\n\t\\end{enumerate}\n\t\\begin{lemma}[Levy's lemma]\n\tGiven $x$, $y$, $z$, $t$ be words such as $xy=zt$. Then there exists a word $w$ such that:\n\t\n\twith obviously:\n\t\n\tor:\n\t\n\twith also by extension:\n\t\t\n\t\\end{lemma}\n\tIt results logically in particular that if $|x|=|y|$, the word $w$ is empty, and therefore $x=z$ and $y=t$. In other words:\n\t\\begin{theorem}\n\tA free monoid (see the reminder below) can be simplified on the left and on the right.\n\t\\end{theorem}\n\t\\begin{dem}\n\tLet us put:\n\t\n\twith $a_i\\in\\mathcal{A}$, similarly:\n\t\n\twith $b_i\\in\\mathcal{A}$.\n\t\n\tAs:\n\t\n\tWe have:\n\t\n\t(but not necessarily $n=p$) and:\n\t\n\tfor $i=1,\\ldots,m$ so that:\n\t\n\tIf $|z|=p\\le n=|x|$, let us put $w=x_{p+1}\\ldots x_n$. Therefore:\n\t\n\tIf $|z|>|x|$, let us put $w=x_{n+1}\\ldots x_p$. Therefore:\n\t\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\tLet us just do a recall of a parallel of the section of Set Theory... In the framework of the study automata a \"\\NewTerm{free monoid}\\index{free monoid}\" is a set $\\mathcal{A}$ (the alphabet), whose elements are the letters $\\ell_i$. Therefore for the composition law denoted $\\cdot$:\n\t\n\tIn the Set Theory section, we were simply talking about the concept of \"monoid\". The monoid $(\\mathcal{A},\\cdot)=(\\mathcal{A},\\text{concatenation})$.\n\t\n\t\\pagebreak\n\t\\subsubsection{Languages}\n\tThe subsets of $\\mathcal{A}$ are named \"\\NewTerm{formal languages}\\index{formal languages}\". For example, for $\\mathcal{A}=\\{a,b\\}$, the set $\\mathcal{A}^{+}=\\{a^nb^n|n\\ge 0\\}$ is a language.\n\n\tWe define on the languages several operations. The set operations are the union, intersection, complementarity and the resulting difference (\\SeeChapter{see section Set Theory}). If $X$ and $Y$ are two parts of $\\mathcal{A}^{*}$ then for recall each of this operation is defined by:\n\t\\begin{itemize}\n\t\t\\item Union:\n\t\t\n\n\t\t\\item Intersection:\n\t\t\n\n\t\t\\item Complementarity:\n\t\t\n\n\t\t\\item Difference:\n\t\t\n\t\\end{itemize}\n\tThe also have for operation the product (of concatenation) of two languages $X$ and $Y$ is the language:\n\t\n\tand we have for recall:\n\t\n\tand also the operation of left quotient of $Y$ by $X$:\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tLet us consider three languages:\n\t\n\tThen we have for the union:\n\t\n\tfor the concatenation:\n\t\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\tfor a given quotient:\n\t\n\tanother quotient:\n\t\n\tand a last quotient:\n\t\n\tand a stupid difference example:\n\t\n\tFollowing the request of a reader we will detail:\n\t\n\tby recalling the definition:\n\t\n\tWe then have explicitly:\n\t\n\tand in the concatenation product of the two languages $X$ and $Y$, the only words where we find the elements $\\{0,1\\}$ of the language $Z$ as a prefix are:\n\t\n\tand as by definition $Z^{-1}(XY)$ is the unique set of terms $w$ which follow the prefixes that constitute the terms of $Z$, then there remains only:\n\t\n\t\\end{tcolorbox}\n\tWe have the following properties:\n\t\\begin{enumerate}\n\t\t\\item[P1.] Obviously:\n\t\t\n\n\t\t\\item[P2.] Less obvious:\n\t\t\n\t\twhere the inclusion is generally strict. To conceptualize this property, we must not forget that $X$ is a set of words and that $Y$, $Z$ do not necessarily have words of the same length!\n\t\\end{enumerate}\t\n\tThe powers of $X$ are defined by\n\t\n\tfor $n\\geq 1$\n\n\tIn particular, if $\\mathcal{A}$ is an alphabet, $\\mathcal{A}^n$ is the set of words of length $n$.\n\t\n\t\\textbf{Definitions (\\#\\mydef):}\n\t\\begin{enumerate}\n\t\t\\item[D1.] The \"\\NewTerm{Kleene star}\\index{}\" (or \"\\NewTerm{Kleene operator}\" or \"\\NewTerm{Kleene closure}\") of $X$ is the set:\n\t\t\n\t\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\t\tGiven $X=\\{a,ba\\}$. The words of $X^{*}$, classified by length are:\n\t\t\n\t\t\\end{tcolorbox}\n\t\n\t\t\\item[D2.] The operator \"$+$\" is defined similarly:\n\t\t\n\t\\end{enumerate}\n\t\n\t\n\t\\subsubsection{Equations}\n\tFirst let us see a little something we will need later: given $u$ and $v$ two non-empty words. The three following conditions are equivalent (without proof because quite trivial):\n\t\\begin{enumerate}\n\t\t\\item[C1.] $uv=vu$\n\t\t\\item[C2.] $\\exists\\, n,m>1:\\quad u^n=v^m$\n\t\t\\item[C3.] $\\exists\\, w\\neq\\varepsilon, k,l\\ge 1:\\quad u=w^k,v=w^l$ \n\t\\end{enumerate}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tLet us recall again that we do not necessarily have $|u|=|v|$ but that we can very well have $|u|>|v|$.\n\t\\end{tcolorbox}\n\tLet us now turn to interesting things (some fuzzy points of the section of Proof Theory can be clarified here sometimes...)!\n\t\n\t\\textbf{Definitions (\\#\\mydef):}\n\t\\begin{enumerate}\n\t\t\\item[D1.] Let $\\mathcal{V}$ and $\\mathcal{A}$ be two disjoint alphabets (you can imagine them as the set of variables and respectively of the constants for example...). An \"\\NewTerm{equation in words}\" with constants on $\\mathcal{A}$ is a couple $e=(\\alpha,\\beta)$ of words $(\\mathcal{V}\\cup \\mathcal{A})^{*}$. Such an equation is represented by $\\alpha=\\beta$. It is therefore necessary to see the two chosen words as the left and right members respectively of an equation.\n\t\t\n\t\t\\item[D2.]  An equation is say to be \"\\NewTerm{non-trivial equation}\" if $\\alpha\\neq \\beta$.\n\t\t\n\t\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\t\tGiven $\\mathcal{V}=\\{x\\}$ and $\\mathcal{A}=\\{a\\}$ and let us define:\n\t\t\n\t\tthen we have the following equation in words:\n\t\t\n\t\t\\end{tcolorbox}\n\n\t\t\\item[D3.] An equation $e$ is say to be an \"\\NewTerm{equation without constant}\" if $\\alpha,\\beta\\in\\mathcal{V}^{*}$.\n\n\t\t\\item[D4.] A \"\\NewTerm{solution}\" of the equation $e$ is a monoid homomorphism (\\SeeChapter{see section Set Theory}):\n\t\t\n\t\tinvariant (because every letter on $\\mathcal{A}$ is sent on $\\mathcal{A}^{*}$ and therefore every word on $\\mathcal{A}$ is sent on $\\mathcal{A}$) on $\\mathcal{A}$ such that:\n\t\t\n\t\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\t\tLet us recall that the definition of the homomorphism is such that if $\\alpha=xy$ then:\n\t\t\n\t\t\\end{tcolorbox}\n\t\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\t\tGiven $\\mathcal{A}=\\{a,b\\}$ and $\\mathcal{V}=\\{x,y\\}$. Let us wow consider the following words:\n\t\t\n\t\tlet us define $h$ such that it sends $x$ on $b$, $y$ on $a$, $a$ on $a$, $b$ on $b$. Therefore we have well:\n\t\t\n\t\tand we will always have for every couple:\n\t\t\n\t\t\\end{tcolorbox}\n\t\t\n\t\t\\item[D5.] A solution $h$ is say to be a \"\\NewTerm{cyclic solution}\" if there exists a word $w$ (belonging to $\\mathcal{A}$) such that $h(x)\\in w^{E}$ (considering the word itself as an alphabet therefore) for any variable $x$.\n\t\\end{enumerate}\n\t\n\t\n\t\\subsubsection{Codes}\n\t\\textbf{Definition (\\#\\mydef):} We name \"\\NewTerm{code}\\index{code}\" any part $\\mathcal{C}$ of a free monoid $\\mathcal{A}^{*}$ that satisfies the following condition for any (word) $x_1,\\ldots,x_n,y_1,\\ldots,y_m\\in \\mathcal{C}$:\n\t\n\tIn other words, $\\mathcal{C}C$ is a code if every word of $\\mathcal{C}^{*}$ (word composed of words) \\underline{uniquely factorize} into a product words of $\\mathcal{C}$. When a set is not a code, general we see it quite easily.\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Examples:}\\\\\\\\\t\n\tE1. The set (language) $\\{a,ab,ba\\}$ is not a code since the word $aba$ can written both as product $a\\cdot ba$ and as product $ab\\cdot a$.\\\\\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe simplest codes are the \"\\NewTerm{uniform codes}\\index{uniform codes}\". These are sets whose all words have the same length (which means that since each word is different, the combination of words can hardly differ).\n\t\\end{tcolorbox}\n\t\\phantom \\\\\n\tE2. The set $\\mathcal{A}^{*}$ of the words of length $n$ is a code, if $n\\ge 1$. The ASCII code that associates to some characters binary words of length $7$ (see ASCII table) with some characters is an example of uniform code.\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\paragraph{Prefix codes}\\mbox{}\\\\\\\\\n\t\\textbf{Definition (\\#\\mydef):} A \"\\NewTerm{prefix code}\\index{prefix code}\" is a type of code system (typically a variable-length code) distinguished by its possession of the \"prefix property\", which requires that there is no whole code word in the system that is a prefix (initial segment) of any other code word in the system. \n\t\n\tPrefix codes are also known as \"\\NewTerm{prefix-free codes}\", \"\\NewTerm{prefix condition codes}\" and \"\\NewTerm{instantaneous codes}\". Although Huffman coding is just one of many algorithms for deriving prefix codes, prefix codes are also widely referred to as \"Huffman codes\" (see further below), even when the code was not produced by a Huffman algorithm. \n\t\n\tUsing prefix codes, a message can be transmitted as a sequence of concatenated code words, without any out-of-band markers or (alternatively) special markers between words to frame the words in the message. The recipient can decode the message unambiguously, by repeatedly finding and removing sequences that form valid code words. This is not generally possible with codes that lack the prefix property\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\\textbf{R1.} The variable-length Huffman codes, country calling codes, the country and publisher parts of ISBNs, the Secondary Synchronization Codes used in the UMTS W-CDMA 3G Wireless Standard, and the instruction sets (machine language) of most computer microarchitectures are prefix codes.\\\\\n\t\n\t\\textbf{R2.} Prefix codes are not error-correcting codes. In practice, a message might first be compressed with a prefix code, and then encoded again with channel coding (including error correction) before transmission.\n\t\\end{tcolorbox}\n\tThe Morse codes encodes the letter \\texttt{E}, the most frequent, with a '.' And the letter \\texttt{Y}, more rare, by '-.--': this is an example of a variable length code, which makes it possible to represent the most frequent letters or words by shorter words. \n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/morse_code.jpg}\n\t\t\\caption{'Hello World' in Morse code}\n\t\\end{figure}\n\tAn important property is the uniqueness of the decoding (injective application), a problem that does not arise for codes of constant length. It can be solved, but too costly, when a special symbol separates two successive words of the code (the \"blank\" in the case of the Morse code). We can therefore not use such a non-constant length code if no word is the prefix of another code word. And as the reader has probably understand it now, a code with this property is named a \"prefix code\".\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\t\n\tSuppose we decide on a variable-size code convention, which matches, among other things, the following values:\n\t\n\tLet us suppose that we have to decode the sequence: \n\t\\begin{center}\n\t\t$1101000111100$\n\t\\end{center}\n\n\tSeveral interpretations (factorization) are then possible:\n\t\\begin{center}\n\t\t$1101000111100 = 11\\; 0100\\; 0111100 = 0\\; 255\\; 127$\n\t\\end{center}\n\tor:\n\t\\begin{center}\n\t\t$1101000111100 = 11010\\; 00\\; 11\\; 11\\; 00 = 2\\; 12\\; 0\\; 0\\; 12$\n\t\\end{center}\n\tAnd now we are very embarrassed! With several equivalent possibilities between which one can not decide, one is incapable of retranscribing the initial code.\n\n\tThe problem that has arisen here is that some codes are the beginning of other codes. Here, \"$11$\" is the code of the number $0$, but it is also the beginning of \"$11010$\", code of the number $2$. Hence the ambiguity!\n\t\\end{tcolorbox}\n\tWe then better understand the purpose and the name of \"prefix codes\". Thus, in order for there to be no ambiguity at the time of the decoding, we must absolutely have a prefix code if the code is not of constant length.\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\t\n\tThe set:\n\t\\begin{gather*}\n\t\tX=\\{ab,ababa,baa\\}\n\t\\end{gather*}\n\tis a code. Here, knowledge of the beginning of a possible code $abababa$ does not yet make it possible to know whether the decomposition begins by $ab\\cdot ab\\cdot ab\\cdot a$ or by $ababa\\cdot ba$. It is only after reading the next letter (not indicated in this example) that we know if the decomposition starts with $ab$ (if the letter is $b$) or by $ababa$ (if the letter is $a$)\n\t\\end{tcolorbox}\n\t\n\t\\pagebreak\n\t\\textbf{Definition (\\#\\mydef):} A code is with \"\\NewTerm{finite decryption delay}\" if there exists an integer $d$ such that, whenever a message $w$ begins with $p=x_1x_2\\ldots x_{d+1}$ with $x_1,x_2,\\ldots, x_{d+1}\\in X$ then the complete factorization of $w$ begins with $x_d$. It is therefore after a \"delay\" of $d$ code words that we can affirm that the first word found is the right one (as in the example above that is a $8$ finite decryption delay code).\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Examples:}\\\\\\\\\t\n\tE1. The code:\n\t\n\thas therefore a delay $d=0$.\\\\\n\n\tE2. The code:\n\t\n\thas therefore a delay $d=2$.\n\t\\end{tcolorbox}\n\t\n\t\\subsection{Linguistic algorithms}\n\tLet us put into practice what has already been seen so far in order to support us a little on \"useful\" concrete stuff!\n\t\n\t\\subsubsection{Huffmann algorithm}\n\tLet us first recall that in computing, we decide to encode an integer that has a value between $0$ and $255$ by a sequence of $8$ binary digits (or \"bits\" in English, valued $0$ or $1$), also called byte (whose maximum value is equal to $2^8$).\n\t\n\tEven if there is a mathematical logic in the way of associating an $8$-bit binary number to an integer between $0$ and $255$ (\\SeeChapter{see section Theoretical Computing}) we can imagine any coding of the type:\n\t\n\tin fact the correspondence can be any one, dictated by our imagination, as long as each integer between $0$ and $255$ is assigned to a fixed length binary code and only one. Once a correspondence is fixed, it is enough to take it as a convention.\n\t\n\tThe byte defined according to this convention is the basic unit of data storage. Any computer file is a sequence of bytes arranged in a defined order. The size of the file is simply the number of bytes that constitute it. The kilobyte (KB) corresponds to $1024$ (not $1000$) bytes, the megabyte (MB) to $1024\\times 1024$ bytes.\n\n\tIt should be noticed that this representation in base $2$ is only a convention! Other conventions are possible, which would be equally appropriate if everyone agrees to use the same convention.\n\n\tThe problem we are asking ourselves is: would there be another way of coding the numbers, perhaps less logical but more judicious, in such a way that the size of the same file rewritten according to the new convention would be smaller?\n\n\tThe binary encoding convention is ultimately very democratic: whether you are a $0$ or a $255$, we allocate you $8$ bits anyway to be able to code you. In other words, each possible input (a number between $0$ and $255$) is encoded on $8$ bits. This is a fixed size encoding.\n\n\tFrom the point of view of our problem (data compression), it would not matter if each of the possible values ($0$...$255$) were represented as frequently as the others. But in general this is not the case.\n\n\tFor example, see below the parsing of Wordpad.exe file (see your Accessories folder in your Microsoft Windows operating system\\footnote{This plot date from 2001... so its rendering quality is very bad. We will do it again when we will have the time}...). In this plot, on the abscissa as on the ordinate are the possible values of a given octet (hence $0$ ... $255$). On the diagonal, at the abscissa and corresponding ordinate, the size of the circle is proportional to the number of bytes having this value in the file:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/wordpad_byte_parsing.jpg}\n\t\t\\caption[]{Analysis of the byte distribution of a the Wordpad.exe file}\n\t\\end{figure}\n\tWe see clearly that the values $0$, $128$ and $255$ are much more frequent than the others!\n\n\tAs an indication, here are some values:\n\t\n\tWe will now decide of a variable-sized coding convention, which represents a value that is frequent by a small number of bits, and an uncommon value by a large number of bits.\n\t\n\tWe will now decide on a variable-sized coding convention, which represents a value that is frequent by a small number of bits, and an uncommon value by a large number of bits.\n\n\tFor example, $0$ will now be represented by the sequence \"$11$\" (when before it was \"$00000000$\"), $128$ by \"$1011010$\" (when before it was \"$10000000$\"), $255$ by \"$0100$\" (when before it was \"$11111111$\"), etc.\n\n\tGiven that $0$ represents almost one third of the file, we have gained a considerable place by coding it on two bits instead of eight! And same for the other frequent values...\n\n\tTherefore \"\\NewTerm{Huffman algorithm}\\index{Huffman algorithm}\" is a recipe for generating a variable-length prefix code from the frequency table of a sequence of values. So, if you have followed the theory so far, it is a solution to our problem.\n\n\tSuppose that our file is extremely simple, consisting of a single french word (\\textit{unconstitutionally}):\n\t\\begin{center}\n\t\t\\texttt{anticonstitutionnellement}\n\t\\end{center}\n\tThere are $25$ characters in this file. Each character being encoded by an $8$-bit octet (ASCII encoding), this means $25$ bytes, or $200$ bits! Let's see what we can do with that.\n\n\tFirst let us render the table of frequencies:\n\t\n\tAll other bytes (strings) have a null frequency: they are not represented in the file.\n\n\tNow we create a \"terminal node\" for each entry of the array:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.9]{img/computing/huffman_step_0.jpg}\n\t\\end{figure}\n\tWhat makes for us now $11$ trees containing only one knot each.\n\n\tWe now start an iteration: each time we delete the two trees on the left and replace them with a \"sum tree\". The new tree is inserted in the list in ascending order, and is repeated until there is only one tree left. Therefore we get:\n\t\\begin{itemize}\n\t\t\\item First Iteration:\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[scale=1]{img/computing/huffman_step_1.jpg}\n\t\t\\end{figure}\n\t\t\n\t\t\\item Second iteration:\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[scale=0.9]{img/computing/huffman_step_2.jpg}\n\t\t\\end{figure}\n\t\t\n\t\t\\item Third iteration:\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[scale=1]{img/computing/huffman_step_3.jpg}\n\t\t\\end{figure}\n\t\t\n\t\t\\item ....\n\t\\end{itemize}\n\t...and the final tree is:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.75]{img/computing/huffman_step_final.jpg}\n\t\\end{figure}\n\tAnd that's it!\n\n\tNow, the associated code to each letter is none other than the path to the corresponding terminal node from the root, noting $0$ for each left branch and $1$ for each right branch.\n\n\tFinally:\n\t\n\tAnd here is now, transcribed with our new code, the starting word:\n\t\\begin{center}\n\t{\\small \\texttt{110000001100110011101001111100110001111111011001101000010111101110101111101010001}}\n\t\\end{center}\n\twhich makes $81$ bits, instead of $200$ at the beginning! This corresponds to a compression ratio of almost $60\\%$.\n\t\n\tThe fact of having generated code using a binary tree ensures that no code can be the prefix of another one. You can verify that using the encoding table, there is no ambiguity possible to decode our compressed word!\n\t\n\t\\subsubsection{Sardinas and Patterson algorithm}\n\tWhen we have to deal with long codes, the difficulity is to check whether the code is really one... In order to do this, we can use the Sardinas and Patterson algorithm (the proof of this algorithm will be done during the next update of this section of the book).\n\n\tIn coding theory, the Sardinas–Patterson algorithm is a classical algorithm for determining in polynomial time whether a given variable-length code is uniquely decodable, named after August Albert Sardinas and George W. Patterson, who published it in 1953.\n\n\tTo do this check, we construct a graph $G(X)=(P,U)$, where $P$ is the set of non-empty prefixes (according to the definition of \"prefixes\" given earlier above) of words of $X$, and $U$ the set of pairs $(u, v)$ such that one of the following possibilities is met:\n\t\\begin{enumerate}\n\t\t\\item[P1.] $uv\\in X$ (by eliminating duplicate pairs if necessary)\n\n\t\t\\item[P2.] $v\\notin X$ and it exist $x\\in X$ such that $ux=v$\n\t\\end{enumerate}\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\t\n\tFor $X=\\{a,bb,abbba,babab\\}$, the set $P$ contains, in addition to $X$ (which are prefixes of $\\varepsilon$), the words $\\{b,ab,abb,abbb,b,ba,bab,baba\\}$ (respectively prefixes of $\\{b,bba,ba,a,abab,bab,ab,b\\}$).\\\\\n\n\tFirst we see immediately that the set of $X=\\{a,bb,abbba,babab\\}$ is not a code because:\n\t\n\tNow the pairs of $U$ are for the first possibility P1:\n\t\n\tand for the second possibility P2:\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\n\tfor which the $x$ which is used to form the $v$ is respectively $bb$, $bb$, $a$, $a$.\\\\\n\t\n\tSardinas and Patterson will therefore be:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/sardinas_patterson_example_graph.jpg}\n\t\t\\caption{Sardinas and Patterson example graph}\n\t\\end{figure}\n\twhere the vertices corresponding to the words of $X$ are doubly circled. The label of each arc is a word of the set $X$. The \"crossed arcs\" are traced in dotted lines and the \"front arcs\" in solid lines. If the arc $(u,v)$ is crossed, then the label is $uv$, otherwise it is the word $x$ such that $ux = v$.\n\t\\end{tcolorbox}\n\tIn our example above, there is a path from $a$ to $a$. By virtue of the Sardinas and Patterson theorem (which we will proved in the next update of this section), the set $X$ is not a code (a single and unique path between any two vertices of $X$ is enough).\n\t\n\tThe set $X$ is a code if and only if there is no non trivial path in $G(x)$ of a vertex of $X$ to a vertex of $X$ (in other words, a set $X$ is a code if and only if there is only the one and only trivial path leading from one vertex of $X$ to another one - this vertex may be the same as in the previous example).\n\t\n\t\\begin{flushright}\n\t\\begin{tabular}{l c}\n\t\\circled{60} & \\pbox{20cm}{\\score{2}{5} \\\\ {\\tiny 10 votes,  46.00\\%}} \n\t\\end{tabular} \n\t\\end{flushright}\n\n\t%to make section start on odd page\n\t\\newpage\n\t\\thispagestyle{empty}\n\t\\mbox{}\n\t\\section{Cryptography}\n\t\\lettrine[lines=4]{\\color{BrickRed}C}ryptography is one of the disciplines of cryptology endeavoring to protect messages (ensuring confidentiality and / or authenticity) that two people wish to share through an insecure channel often thanks to secrets or keys.\\\\\n\t\n\tThe history of cryptography is already long and exciting (since it is a kind of \"game\"). We report its first use in Egypt 4,000 years ago. However, for centuries, the methods used were often remained very primitive. Moreover, its implementation was limited to the needs of the army and diplomacy. Thus, encryption methods and cryptanalysis (code breaking) experienced an important development during the Second World War and had a profound influence on the course of it.\n\t\n\tAt the end of the 20th century (especially!), with the proliferation of computers and electronic communications media, it became increasingly important to use secret codes for transmitting data between the military or private organizations. Thus, engineers have had to look at this same time solid numerical methods whose implementation and use was within reach of almost everyone (nation, enterprise and individual) while ensuring that external attacks required tools out of reach of an individual or group of individuals equipped with standard and high-performance IT tools (in computing power). Engineers and researchers then plunged into the mathematical tools to search for satisfying these specifications and the most known systems, mathematical theories which were adopted had over 200 years old (apart quantum cryptography).\n\t\n\tThe growth of cryptographic technology has raised a number of legal issues in the information age. Cryptography's potential for use as a tool for espionage and sedition has led many governments to classify it as a weapon and to limit or even prohibit its use and export. In some jurisdictions where the use of cryptography is legal, laws permit investigators to compel the disclosure of encryption keys for documents relevant to an investigation Cryptography also plays a major role in digital rights management and piracy of digital media.\n\t\n\tSteganography techniques (art of concealing a message in another one or in an image) however must be preserved because nothing tells us that computing power will still be available in times of war. It should be noted also that the steganography deployed wealth of imagination. Note for example: the permutations of letters, special and subtle formating of characters, use of synonyms, hidden messages in text or comma behind a stamp, inside shots chess (hence the fact that these games were banned by the USA for some years after the attack on Pearl Harbor), in pictures / drawings, musical scores, etc. All of these techniques make that during the Second World War, the office of censorship in the United States occupied 10,000 full-time employees that analyzed the mail of citizens, classified ads, radio text, etc.\n\t\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\\textbf{R1.} To address the foundations of the theory of cryptography, we advise the reader to have read at first and at least in diagonal the section on Number Theory, on Set Theory, on Numerical Methods (especially the subsection on computational complexity), on Numerical Systems , on Statistical Mechanics (where information theory can be found) and for the part about quantum cryptography: the section of on Quantum Computing.\\\\\n\t\n\t\\textbf{R2.} We must remain aware that cryptography is more an engineer science than physicist science (except with quantum cryptography) and we must then not be so surprised to see some algorithms like fallen just from nowhere and adopted by industry because they just work almost well... Furthermore, it is also certain that only a few years after writing this text it will already be considered as obsolete (that is the art of engineering ... planned obsolescence).\n\t\\end{tcolorbox}\n\t\n\t\\subsection{Cryptographic systems}\n\t\n\t\\textbf{Definitions (\\#\\mydef):}\n\t\n\tA \"\\NewTerm{cryptographic system}\\index{cryptographic system}\" is composed of:\n\t\\begin{enumerate}\n\t\t\\item[D1.] A finite set $P$ named \"\\NewTerm{space of clear texts}\\index{space of clear texts}\".\n\t\t\n\t\t\\item[D2.] A finite set $C$ named \"\\NewTerm{space of encrypted texts}\\index{space of encrypted texts}\".\n\t\t\n\t\t\\item[D3.] A finite set $K$ named  the \"\\NewTerm{space of keys}\\index{space of keys}\".\n\t\\end{enumerate}\n\tFor each key $k$, we seek an encryption function $e_k$:\n\t\n\tand a deciphering (decryption) function $d_k$:\n\t\n\tsuch as (\\SeeChapter{see section Set Theory}):\n\t\n\tIn other words, these two functions must be injective!\n\t\n\tTo achieve this, two types of cryptographic techniques are mailny distinguished, encompassing almost all known modern encryption methods of the 20th century (for mathematical details see below):\n\t\\begin{enumerate}\n\t\t\\item The first concern cryptosystems with \"\\NewTerm{symmetrical secret key}\\index{symmetrical secret key}\".\n\t\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\t\tPublic keys often refer to the DES protocol (see below) for: Data Encryption System.\n\t\t\\end{tcolorbox}\n\t\t\n\t\t\\item The second concerning encryption systems with \"\\NewTerm{asymmetric public key}\\index{asymmetric public key}\".\n\t\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\t\tThis type of key often refers for example to the RSA protocol, the names of those to whom we awarded the Development: Rivest, Shamir and Adleman. They are widely used thanks to their rapid time encryption and decryption as well as their high entropy (see definition below).\n\t\t\\end{tcolorbox}\n\t\\end{enumerate}\n\tBy nature, these two types of keys are very different. Let us try to understand the reasons:\n\t\t\n\t\tA symmetric encryption means a system where the key used in the encryption operation is that used in the deciphering operation. In this case, during a secure exchange (assumed to be as), both sides of the correspondence must share a same secret: the used key or \"\\NewTerm{session key}\\index{session key}\".\n\t\t\n\t\tAn asymmetric encryption designates an encryption system in which the key used for encryption (private key of the sender) differs from that used for decryption (recipient's private key). The only exchange that exists between members of the group is the public key, which allows each member to adjust its encryption based on the private key of the other members (among the many who have asymmetric systems been proposed, one of the most widespread in the early 21st century is the RSA).\n\t\t\n\t\tThe symmetric key ciphers are traditionally classified into two groups:  \"\\NewTerm{stream ciphers}\\index{stream ciphers}\" and \"\\NewTerm{block ciphers}\\index{block ciphers}\".\n\t\t\n\t\t\\textbf{Definitions (\\#\\mydef):}\n\t\t\\begin{enumerate}\n\t\t\t\\item[D1.] A \"\\NewTerm{block cipher}\\index{block cipher}\" is an encryption algorithm that encrypts a fixed size of $n$-bits of data - known as a block - at one time. The usual sizes of each block are $64$ bits, $128$ bits, and $256$ bits. So for example, a $64$-bit block cipher will take in $64$ bits of plaintext and encrypt it into $64$ bits of ciphertext. In cases where bits of plaintext is shorter than the block size, padding schemes are called into play. Majority of the symmetric ciphers used today are actually block ciphers. DES, Triple DES, AES, IDEA, and Blowfish are some of the commonly used encryption algorithms that fall under this group.  \n\t\n\t\t\t\t\\item[D2.] A \"\\NewTerm{stream cipher}\\index{stream cipher}\" is an encryption algorithm that encrypts $1$ bit or byte of plaintext at a time. It uses an infinite stream of pseudorandom bits as the key. For a stream cipher implementation to remain secure, its pseudorandom generator should be unpredictable and the key should never be reused. Stream ciphers are designed to approximate an idealized cipher, known as the One-Time Pad. RC4, which stands for Rivest Cipher 4, is the most widely used of all stream ciphers, particularly in software. The cypher Engima machine of the second World Was is also a famous application of stream cipher.\n\t\t\\end{enumerate}\n\t\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tWithout going in the mechanical and electrical description of Enignma, the reader hast just to know that second version of the Enigma cypher machine had first a box $5$ rotors with $26$ start positions! The user had to choose $3$ of theses $5$ rotors and put them in a given position (position order has an importance!) in the machine.\n\n\tSo we have:\n\t\n\tcombinations to put $3$ rotors in a given order choosing among $5$ rotors ($5$ rotors for the first  position, multiplied the $4$ remaining rotors for the second position and so on...).\n\t\n\tAfter the Enigma user had to choose among on of the $26$ position of each rotor. Then the number of starting positions possibilities is equal to:\n\t\n\tFinally the business and military version of the Enigma machine had something extra: plugboard.\n\t\n\tThis plug-board has $10$ wires that connect two letter together among 26 letters (there $2\\cdot 20$ letters combine together). The combination is therefore:\n\t\n\tIndeed, we have $26!$ combinations of letters, but as there are $10$ cables for therefore $20$ letters we don't care about the combinations of $6$ of them. Hence the division by $6!$. We divide by $10!$ as for all the remaining combination of letters we can use only $10!$ of them. Since we don't care about the direction of the cables (from $A$ to $B$ or $B$ to $C$) and that we have $10$ cables, we must divide $10$ times by $2$ and this is equivalent as dividing by $2^{10}$.\n\tSo finally the total is:\n\t\n\tThis is the total number of ways you can set the Enigma machine...\n\t\\end{tcolorbox}\n\t\t\n\t\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\t\\textbf{R1.} In 2001, Microsoft Internet Explorer (Microsoft's web browser in this time) worked with a 1024-bit asynchronous system certified by a synchronous system and Adobe Acrobat (PDF) in 2004 with an AES (Advanced Encryption System) of 128 bits for the low protection as well in the years 2010-2015 the iPhone 4S and 5.\\\\\n\t\t\n\t\t\\textbf{R2.} Microsoft Windows Enterprise and its E.F.S. system (Encrypting File System) uses a a symmetric key (to encrypt the file) named  \"File Encryption Key\" and asymmetric cryptography to encrypt the symmetric key in the file header as shown below (the key being updated regularly via Windows Update root certificates):\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics{img/computing/cryptography_FEK.jpg}\n\t\t\t\\caption{Principle of F.E.K.. in Microsoft Windows O.S. (source: Wikipedia)}\n\t\t\\end{figure}\n\t\tHowever, the cryptography keys for EFS are in practice protected by the user account password, and are therefore susceptible to most password attacks. In other words, encryption of files is only as strong as the password to unlock the decryption key.\n\t\t\\end{tcolorbox}\n\t\tThese methods are still decipherable, provided that the interceptor has enough time and paper/money (excepted at this date for quantum encryption).\n\t\t\n\t\tHere is a small summary table of broken keys and their respective size for both conventional systems:\n\t\t\n\t\n\t\\subsubsection{Kerckhoffs' principle}\n\tThe primary function of cryptography is therefore to ensure the confidentiality of information exchange. Two parts of a confidential exchange will first agree on a secret convention to write their messages, and if they have carefully chosen, no one else should be able to enter their exchange.\n\t\n\tIf the secrecy of such agreements is possible from a few isolated individuals for a limited period, it is inconceivable at  large scale and for a fairly long period. This is what Auguste Kerckhoffs understood when establishing the basic principles of practical cryptography which requires a fundamental principle encryption system \"that does not require secrecy, and which can conveniently fall into the hands the enemy\".\n\t\n\tThe six postulates of Kerchoffs are:\n\t\\begin{enumerate}\n\t\t\\item The system must be practically, if not mathematically, indecipherable;\n\t\t\\item It should not require secrecy, and it should not be a problem if it falls into enemy hands;\n\t\t\\item It must be possible to communicate and remember the key without using written notes, and correspondents must be able to change or modify it at will;\n\t\t\\item It must be applicable to telegraph communications;\n\t\t\\item It must be portable, and should not require several persons to handle or operate;\n\t\t\\item Lastly, given the circumstances in which it is to be used, the system must be easy to use and should not be stressful to use or require its users to know and comply with a long list of rules.\n\t\\end{enumerate}\n\tThe second postulate, known today as the \"\\NewTerm{Kerckhoffs principle}\\index{Kerckhoffs principle}\"  states that the security of an encryption system is not based on the secrecy of the procedure, but only on one parameter used when its implementated: the key. This key is the only secret of the Exchange Agreement.\n\t\n\tThis principle, however, was reformulated by Claude Shannon: \"the enemy knows the system\". This formulation is known as the \"Shannon's maxim\". This is the principle usually adopted by cryptologists, as opposed to the security through obscurity.\n\t\n\t\\subsection{Traps}\n\tSometimes there are what we call the \"trap doors\" in public and secret keys. This is because when generating the key, which hast to be done randomly within certain predefined theoretical constraints, the random generator may have an issue (the issue is sometimes voluntary on the part of the supplier of the material for spy purpose...).\n\t\n\tIn the secret keys, the traps are located at the level of the \"\\NewTerm{key's entropy}\\index{key's entropy}\" (\\SeeChapter{see section Statistical Mechanics}), directly linked to the entropy of the random generator. We can simplistically define the entropy of a key generator by the average optimal binary questions (that is to say giving rise to the type of answers Yes / No) that we need to ask someone knowing a key produced by this generator to determine it. More the entropy of a key generator is high, higher is the number of questions we need to determine the key. Conversely, the smaller is the entropy, the lower are the questions, so that the search of a key is facilitated.\n\t\n\tThe introduction of traps in the asymmetric key systems is much more difficult, since this type of key already has intrinsic mathematical structure: their construction is not due to chance but is the result of mathematical rules. Chance is here in the choice of large prime numbers used. The fact that asymmetric systems can be easily calculated, but they are difficult to reverse are sometimes named \"trapdoor functions\".\n\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tAn example of a simple mathematical trapdoor is \"$6895601$ is the product of two prime numbers. What are those numbers?\" A typical solution would be to try dividing $6895601$ by several prime numbers until finding the answer. However, if one is told that $1931$ is one of the numbers, one can find the answer by entering \"$6895601\\div 1931$\" into any calculator. This example is not a sturdy trapdoor function – modern computers can guess all of the possible answers within a second – but this sample problem could be improved by using the product of two much larger primes.\\\\\n\t\n\tTherefore if a random generator that generates prime numbers is biased (\\SeeChapter{see section Statistics}), this bias will facilitate the research of a trapdoor.\n\t\\end{tcolorbox}\n\t\n\t\\textbf{Definition (\\#\\mydef):} A \"\\NewTerm{trapdoor function}\\index{trapdoor function}\" is a function that is easy to compute in one direction, yet difficult to compute in the opposite direction (finding its inverse) without special information.\n\t\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\\textbf{R1.} Functions related to the hardness of the discrete logarithm problem (either modulo a prime or in a group defined over an elliptic curve) are not known to be trapdoor functions, because there is no known \"trapdoor\" information about the group that enables the efficient computation of discrete logarithms.\\\\\n\t\n\t\\textbf{R2.} Trapdoor must not to be confused with a \"\\NewTerm{backdoor}\\index{backdoor}\" as this latter is a deliberate mechanism that is added to a cryptographic algorithm or operating system, for example, that permits one or more unauthorized parties to bypass or subvert the security of the system in some fashion.\n\t\\end{tcolorbox}\n\t\n\t\\subsection{Secret-key encryption system}\n\t\\textbf{Definition (\\#\\mydef):} The \"\\NewTerm{single-use encryption}\\index{single-use encryption}\" is a secret key encryption algorithm proved unconditionally secure. Properly used (and that's an important point), it provides an unbreakable encryption in reasonable time.\n\t\n\tThe theoretical basis of this encryption system are:\n\t\n\tGiven a message $M$ in binary form to be transmitted between people $A$ (creator and originator of the message $M$) and $B$ (reader and receiver). We generate a large amount of bits if possible \"truly randomly\" forming a secret key $K$ of same size as the message to be transmitted (computer programs, deterministic by nature, can not generate truly random bits).\n\t\n\tThis key will be sent to $B$ by a channel supposedly safe ... A given time after the transmission of this key $A$ will encode his message into $C$ by performing the operation:\n\t\n\twhere $\\star$ is an operator that must satisfy to a group law (\\SeeChapter{see section Set Theory}) on a finite set (that contains a limited number of items or \"letters\").\n\t\n\tThe idea in computing science is to use the XOR law (exclusive OR) denoted $\\oplus$ for what will follow (\\SeeChapter{see section Logical Systems}) as it is enough as a group law (remember that a group is the smallest structure having an opposite - and is associative and having neutral element - that gives therefore the possibility to reverse the encoding process). Therefore:\n\t\n\tFinally, the sender $A$ transmits the encrypted version of his message $C$ by a route not necessarily secure. $B$ can read the original message $M$ by using the inverse operator $\\oplus^{-1}$ (the XOR operator is its own inverse as we have proved it thanks to its the truth table in the section of Logical Systems!!!!). So receiver $B$ will do the following:\n\t\n\tProvided that the $K$ has been generated totally randomly and that each bit of it has been used only once to encrypt the message, an interceptor gets no information about the clear message $M$ if he intercepts $C$. Indeed, in these conditions, we can not establish any correlation between $M$ and $C$ without the knowledge of $K$.\n\t\n\tEven with future ultra-powerful quantum computers, the problem is insoluble, because nothing connects the information which is available and the problem to solve. Consequently, the \"single-use encoding\" is an encryption algorithm \"unconditionally secure\". The proof of its security does not rely on unproven mathematical conjectures and decryption attempts of an interceptor with infinite computing power are futile.\n\t\n\tHowever, each stage of encryption is a source of possible errors. Indeed, the key $K$ may have been poorly developed. The slightest statistical deviation of $K$ compared to the \"real\" random provides information on the clear message $M$ from its encrypted version. This is why the $K$ bits are to be used only once if possible.\n\t\n\tIndeed, suppose that same key is used to encrypt messages of French language $M_1$ and $M_2$ an attacker manages to intercept the two corresponding encrypted messages. From $C_1$ and $C_2$ the interceptor and can easily obtain information about $K$ and this because of language peculiarities (same for English). Indeed, since:\n\t\n\tthen the interceptor knows a simple result that involves $M_1$ and $M_2$ without the key $K$:\n\t\n\tas:\n\t\n\t(if necessary make the truth table to be convinced of this relation). Now, if $M_1$ and $M_2$ are in the same language, we will know, usually due to language redundancies (e.g. the letter \"e\" often appears in French), found from $C_1\\oplus C_2$ each of the two original messages (the work is though laborious without statistical automated tools).\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tImagine that we want to send a little message $M$ binary coded by $1101$ and we generated a random key $K$ that gave $0101$.\\\\\n\t\n\tThen we have:\n\t\n\tand therefore:\n\t\n\t\\end{tcolorbox}\n\tObviously in this kind of small situations we can guess $M$ without much difficulty just by having $C$ if there such like here only a single encryption step. This is why there are encoding patterns as we shall see now.\n\t\n\tThe main problem with this technique is the creation of a key as random as possible. To overcome this, mathematicians do pass the key through a series of nested functions, the result after many iterations, becomes \"pseudo-random\".\n\t\n\tBuilding a pseudo-random iteration is one thing, building a pseudo-random bijection is yet another!!! Indeed, we need to decrypt the message later, which is why we absolutely need a bijective system (which has everything arrival element - encrypted message - matches a single starting element - decrypted message - and vice versa).\n\t\n\t\\subsubsection{Feistel Schemes}\n\tEven if encryption algorithms in this late 20th century and early 21st century consider sufficient with a key having a finite number of bits, the goal remains the development that from a message $M$ and a random sequence of digits, or at least that looks like, to build a key $K$ to send an encrypted message $C$ that can be decipher easily only by people knowing the key. Specifically, this target application is to construct or identify a function which, firstly, do correspond to each digit of $M$ a digit $C$ that seems to look random (but whose value depends in reality on the deterministic key) and, secondly, authorizing the reverse path (inverse function by the property of bijection), that is to say that from a digit $C$, we can uniquely trace back to the corresponding digit of $M$. We therefore would like to find a pseudo-random bijection function.\n\t\n\tIn the years 1950s, the mathematician Horst Feistel has shown that a pseudo-random function transformed itself, by a relatively simple method, in bijection function. Today, the \"\\NewTerm{Feistel cypher}\\index{Feistel cypher}\" is most commonly used in the secret key encryption systems and is also the basis of the DES (Data Encryption System). How does it work?\n\t\n\tHere is the principle:\n\t\n\tThe initial message to be encrypted has a size of $2n$ bits. The split the original message $M$ into two blocks (thus the Feistel Schemes belongs ton the family of \"\\NewTerm{block cipher}\\index{block cipher}\"), $G$ and $D$, of equal length ($G$ includes the first $n$ bits and $D$ the following) and we build the transformation $\\varphi$ that associates to $G$ and $D$ the numbers $T$ and $S$ such as:\n\t\n\twhere for reminder the $\\oplus$ still represents the bit by bit XOR operation and where $f_1$ is any function, non-necessarily bijective, from $n$ bits to $n$ bit using the secret key $K$.\n\t\n\tThe transformation $\\varphi(G,D)=(S,T)$ is indeed bijective, as we can go back in a univoque way starting form $S$ and $T$ to $G$ and $D$ by the operations:\n\t\n\tObviously we must not stop here, since the right side of the message, $D$, has not been crypted, it is simply passed to the left. However, as $\\varphi$ is bijective, we can repeat the process. A Feistel scheme where we apply $n$ times the function $\\varphi$ is named a \"\\NewTerm{$n$-step pattern}\\index{$n$-step pattern}\".\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tWe will encrypt by the a two-step Feistel cypher a message consisting of $4$ bits (thus $2^4=16$ possibilities of messages), what is equivalent to building a bijection from $4$ bits to $4$bits from two functions $f_1,f_2$ of two bits to two bits . The functions $f_1,f_2$ have in input both: the message to encrypt and the secret key. We will assume that for some input key, these functions are:\n\t\n\tLet us notice that neither $f_1$ nor $f_2$ are bijections ($f_1(00)=f_1(11)=01$,$f_2(01)=f_2(10)=00$). For example, encrypt the message 1101. $G$ designates the left part of the message to be encrypted, $D$ the right part:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/feistel_encryption_simple_example.jpg}\n\t\t\\caption{Encryption of $1101$ using the Feistel method}\n\t\\end{figure}\n\tThe result is $0010$. We will compute the image of the other $15$ other possible messages and verify that there is an univocal correspondence between each message and its image by the Feistel scheme: we have constructed a bijection from two functions that are not bijective.\n\t\\end{tcolorbox}\n\n\t\\pagebreak\n\tQuite complex theoretical results guarantee the cryptographic security of Feistel schemes starting from $4$ steps when $n$ is large enough and when the functions $f_i$ are indistinguishable from truly random functions. In practice, rather than using $4$ steps and functions $f_i$ that look like random, it is generally preferred to use more steps and more simple functions $f_i$. After a few steps, the obtained bijection often becomes very difficult to distinguish from random bijections. And for parameters well chosen, we no longer know at all how to distinguish them from truly random bijections!!!\n\n\tMost of the secret key encryption algorithms currently in this end of 20th century used in the civilian world are Feistel schemas. In particular, the DES (Data Encryption System) algorithm  which is a $16$-step Feistel scheme as shown in the figure below and the Triple DES (TDES) algorithm which is a $48$-step Feistal scheme and the Blowfish algorithm that will not be discussed here).\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tFor example, there are, in some bank cards (at least in the beginning of this 21st century...), a DES key (or TDES since October 2001) which provides proof of the legitimacy of the card between the bank's control center and the merchant's terminal in addition to Public part of an RSA key to make sure the user code is entered (control done by an internal chip on the card, which must then be manufactured in very secure premises).\n\t\\end{tcolorbox}\n\tRigorously the Feistel scheme is a bit different because it involves keys, which we did not use in the example presented before. Here is a more detailed figure in what this Feistel scheme consists of (see figures below).\n\n\tPrinciple of the diagram: A message to be encrypted is divided into blocks of $64$ bits, each of which is divided into two $32$-bit sub-blocks, the left block ($G$) and the right-hand block ($D$). At each iteration, the old right block becomes the new left block and the new right block results from the XOR operation of the old right block, whose bits are mixed by a confusion function, and of the previous left block. The iteration is repeated $16$ times.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/feistel_encryption_more_realistic.jpg}\n\t\t\\caption{Feistel's scheme a little more realistic (source: ?)}\n\t\\end{figure}\n\tThe confusion function (\\textbf{f}), which acts on the $32$-bit blocks, mixes the bits according to the following processes (see the figure below):\n\t\\begin{itemize}\n\t\t\\item First, it transforms the $32$-bit block into a $48$-bit block by duplicating certain bits (\"expansion\"). \n\n\t\t\\item Then, it adds to this block a $48$-bit (\"token key\") subkey extracted from the $56$-bit secret key \n\n\t\t\\item And then transforms each $6$-bit set into $4$ bits by local transformations (\\textbf{S} transform)\n\t\\end{itemize}\n\tThe result is a $32$-bit block which is finally mixed according to a fixed permutation.\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/feistel_confusion_function_diagram.jpg}\n\t\t\\caption{Feistel's scheme confusion function diagram (source: ?)}\n\t\\end{figure}\n\t\n\t\\pagebreak\n\t\\subsection{Public key encryption}\n\tIn 1975, W. Diffie and M. E. Hellman revolutionized the science of cryptography by proving the existence of a protocol that could not be deciphered by an interceptor unless the interceptor had large computer resources. The most fascinating in their method - the principle of which is still in use in this early 21st century - is that the code used does not require to hide the method used and can be used repeatedly without any modification (Kerckhoffs principle). At their time, they simply created the concept of \"public-key cryptography\", or \"asymmetric cryptography\" (which we mentioned earlier in this section), an invention that sparked the emergence of a dynamic academic and industrial community.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tContrary to what one might think, public key cryptography has not relegated secret key cryptography to oblivion, on the contrary: these two types of cryptography are most often used in hybrid cryptosystems where the authentication of published keys is performed by a \"certification authority\".\n\t\\end{tcolorbox}\n\tBefore describing the Diffie-Hellman protocol  in detail, let us recall that the protocol of exchange of the \"secret keys\" was not reliable at that time (and is still not today) as it was transiting between the interlocutors, the element making it possible to encrypt and therefore decrypt the messages. In addition, even if only one key were to travel, anyone with sufficient computing power could break the code. Hence the need to change (misfortune more!) Periodically the keys (cryptoperiod). At least two solution are therefore available to us:\n\t\\begin{enumerate}\n\t\t\\item Do not exchange any key (it is possible but it is quite long as we will see in the figure below)\n\n\t\t\\item Exchange a secret key using a non-invertible mathematical function or at least very difficult to inverse (this is the Diffie-Hellman protocol that we will also see in a figure below).\n\t\\end{enumerate}\n\tTherefore Public key cryptography systems often rely on cryptographic algorithms based on mathematical problems that currently admit no efficient solution—particularly those inherent in certain integer factorization, discrete logarithm, and elliptic curve relationships. Public key algorithms, unlike symmetric key algorithms, do not require a secure channel for the initial exchange of one (or more) secret keys between the parties.\n\n\tBecause of the computational complexity of asymmetric encryption, it is usually used only for small blocks of data, typically the transfer of a symmetric encryption key (e.g. a session key). This symmetric key is then used to encrypt the rest of the potentially long message sequence. The symmetric encryption/decryption is based on simpler algorithms and is much faster.\n\t\n\tLet us see what the first solution is and its blatant disadvantage:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/public_key_principle.jpg}\n\t\t\\caption{Principle of public key encryption (source: ?)}\n\t\\end{figure}\n\tExplanation: Alice and Bernard want to transmit a message on an unsecured line and without exchanging keys. To do this, Alice puts her letter in a chest that she closes with her key and sends it to Bernard. The latter returns the chest to Alice where he added his own padlock which he closed with his own key. When Alice receives the chest, she takes off her padlock and sends Bernard a chest that no longer includes Bernard's padlock closed with Bernard's key. The latter then only has to open the chest to read the letter. This operation is safe and does not require exchange of keys. On the other hand, it requires several paths (the process is represented by the first $4$ transactions of the figure above).\n\t\n\tThe principle of the public key must allow secure exchanges, without a secret key, in a single path. Bernard distributes widely copies of his public padlock. Alice gets one, but anyone could do the same. Alice places the message in the trunk and closes it with the Bernard code lock, then sends it the trunk (represented by the $5$ transaction in the figure above). On receiving the trunk, Bernard can open the trunk, since he alone holds the key that opens this lock. The transfer is safe in one trip. In cryptography, the public key is equivalent to the code lock, which is available for example in directories, while the key that opens this lock is the private key, owned solely by their owner and never disclosed. The private and public keys (the so-named \"key trousseau\") are constructed from a supposed \"one-way\" mathematical function.\n\n\tLet's now see the second solution making use of public key according to the Diffie-Hellman protocol:\n\t\n\t\\subsubsection{Diffie-Hellman protocol}\n\tAs the name implies, a one-way function gives easily a result, but the reverse operation is very difficult. Finding such functions in the mathematical world seemed very arduous to mathematicians. How to imagine a function that is one-way for everyone, except for its creator who can reverse it through the knowledge of a particular information. Thus, W. Diffie and Hellman were the first to publicly propose a one-way function to solve the problem of agreeing on a common secret. The basic idea is to calculate values of the type:\n\t\n\twhere $\\alpha$ and $a$ are imposed as being integers and $p$ is a prime number.\n\t\n\tMathematicians call this kind of operation a \"\\NewTerm{modular exponentiation}\\index{modular exponentiation}\" or \"\\NewTerm{discrete exponential}\" and it is customary to denote the finite field of integers modulo $p$ (where $p$ is a prime number) by $\\text{GF}(p)$ in honor of Évariste Galois.\n\t\n\tTo explicate such a calculation (as a reminder of what was seen in the section of Number Theory ...), we raise a number $\\alpha$ to the power of $a$, and then divide the result by a large prime number $p$ and we keep finally the remainder of this division (operation modulo $p$). If this remainder is denoted $r$ then we write this:\n\t\n\tModular exponentiation similar to the one described above are considered easy to compute, even when the numbers involved are enormous. On the other hand, computing the \"\\NewTerm{discrete logarithm}\\index{discrete logarithm}\" – that is, the task of finding the exponent $a$ when given $\\alpha$, $p$, and $r$ (ie $\\alpha^a \\mod p$) – is believed to be difficult. This one-way function behavior makes modular exponentiation a candidate for use in cryptographic algorithms! In addition, one-way functions such as the one above from the modular arithmetic behave very irregularly as is shown in the table with the particular example below:\n\t\n\tSo even if it is easy to compute a discrete exponential, it is almost impossible to find the starting number $a$ from the result, especially when this modular function is applied to very large primes $p$.\n\n\tThe reader can check this by playing with Maple 4.00b that can calculate the discrete logarithm as following:\n\t\n\t\\texttt{>with(numtheory):\\\\\n\t>mlog(r,alpha,p);}\n\t\n\tOk we know how to crypt message... But now how can we communicate messages to someone that should be able to uncrypt them? This is named the \"\\NewTerm{Diffie–Hellman key exchange}\\index{Diffie–Hellman key exchange}\" that is a specific method of securely exchanging cryptographic keys over a public channel and was one of the first public-key protocols as originally conceptualized by Ralph Merkle and named after Whitfield Diffie and Martin Hellman. D–H is one of the earliest practical examples of public key exchange implemented within the field of cryptography. Here is the idea of the protocol:\n\t\n\tThe security of this protocol is computational. It is based on the assumption that with limited computing power and time, an opponent (spy) can not reverse the modular exponential function (by making use of the properties of the logarithms with the exponential functions as we saw in the section of Functional Analysis) and therefore can not find the secret $a$ from the exchanged elements. This computational difficulty is due to the fact that the computation time necessary for the inversion of a one-way function does not have an algorithmic complexity (\\SeeChapter{see section of Numerical Methods}) polynomial but exponential with $p$.\n\t\n\tAlice and Bernard have calculated the same common secret: $493$. Then $493$ is used to encrypt the exchanged data (in practice, much larger numbers are used). The spy is supposed to be able to intervene only after the exchange of the common choice of $p$ and $\\alpha$ (no man-in-the-middle attack!).\n\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThis protocol is vulnerable to a \"man-in-the-middle attack\" that is an attack where the attacker secretly relays and possibly alters the communication between two parties who believe they are directly communicating with each other. One example of man-in-the-middle attacks is active eavesdropping, in which the attacker makes independent connections with the victims and relays messages between them to make them believe they are talking directly to each other over a private connection, when in fact the entire conversation is controlled by the attacker. The attacker must be able to intercept all relevant messages passing between the two victims and inject new ones.\n\t\\end{tcolorbox}\n\tThe key $K$ is obtained by the fact that the power operation is compatible with the relation of equivalence modulo $p$ (\\SeeChapter{see section Number Theory}) such that:\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tWe have:\n\t\n\twhen with $w=2$ we have:\n\t\n\tbut\n\t\n\tIf it is not clear let us write it differently:\n\t\n\tIndeed, for the first one: $5-2=3$ can be divided by $3$ and for the second one $25-4=21$ can be divided by $3$.\n\t\\end{tcolorbox}\n\tThus, since $x<p$, the second modulo below has no meaning, so we can write:\n\t\n\tidentically:\n\t\n\tand therefore:\n\t\n\tDiffie-Hellman is a cornerstone of modern cryptography used for VPNs, HTTPS websites, email, and many other protocols. Bad implementation choices combined with advances in number theory mean real-world users of Diffie-Hellman are likely vulnerable to state-level attackers. \n\t\n\tDespite these precautions, experts established a record at the beginning of the 21st century using a new algorithm, they succeeded in reversing the modular exponential function for a $p$-number of 120 digits (about $400$ bits), using a Computer with four $525$ [MHz] processors. This record shows that the security of the protocol depends greatly on the constant progress made in the field of algorithmic complexity. Researchers estimate that breaking a single, common $1024$-bit prime would allow NSA (USA National Security Agency) to passively decrypt connections to two-thirds of VPNs and a quarter of all SSH servers globally. Breaking a second 1024-bit prime would allow passive eavesdropping on connections to nearly $20\\%$ of the top million HTTPS websites. In other words, a one-time colossal investment in power-lifting computation would make it possible to eavesdrop on trillions of encrypted connections.\n\t\n\tThe clever schema of Diffie-Hellman remains a schema of principle. Its main disadvantage is that it does not make it possible to provide the traditional security services: authentication of the two interveners, control of the integrity of the key and anti-replay (verification that information already transmitted is not re-transmitted ). It follows that an attacker can, for example, impersonate Alice by replacing the public element of Alice with her own public element. To overcome this disadvantage, secure versions of this generic protocol have been published, for example a protocol named \"STS\" (Station To Station), which uses, in particular, the electronic signature to ensure the authentication of the interveners (see below). This policy is the basis of the secured Internet connection (IPSec).\n\t\n\tThe Diffie-Hellman protocol paved the way for a whole series of algorithms, that of \"public key encryption\" being the first. The idea was to break the symmetry of encryption and decryption by using one-way functions.\n\t\n\t\\pagebreak\n\t\\subsubsection{R.S.A system}\n\tCuriously, the first \"\\NewTerm{R.S.A. encryption system}\\index{RSA encryption system}\" is conceptually quite different from the Diffie-Hellman protocol: it does not use the discrete exponential, but the factorization of large numbers. This public key system was invented in 1977 by Ron Rivest, Adi Shamir, and Leonard Adleman (hence the abreviation \"R.S.A.\"). Having quickly become an international standard, the R.S.A. technique has been marketed by more than $400$ companies and we estimate that more than 400 million software use it. It is implemented in web browsers, such as Netscape Navigator, Microsoft Internet Explorer, or some bank smart cards, such as VISA cards.\n\n\tThe R.S.A. system is based on the difficulty of factorizing large numbers and the one-way function used is a \"power\" function. The R.S.A. encryption protocol is divided into three phases:\n\t\\begin{enumerate}\n\t\t\\item Creation of keys (public and private)\n\n\t\t\\item Encryption using the recipient's public key\n\n\t\t\\item Decryption using the private key\n\t\\end{enumerate}\n\tIts concept is based on a famous theorem named \"\\NewTerm{Euler's theorem}\\index{Euler's theorem}\" (nothing to do with the theorem of the same name seen in the section of Graph Theory or in the section of Geometric Shapes). Let's see what it is (be careful it is relatively long!).\n\t\n\t\\paragraph{Euler's theorem}\\mbox{}\\\\\\\\\n\tBefore we see what Euler's theorem consists of, we must define two elements that are included in it. Apart the concept of congruence which we have already studied in the section of Number Theory, there remains a special function named the \"\\NewTerm{Euler indicator}\\index{Euler indicator}\" or also named \"\\NewTerm{totient function}\\index{totient function}\" and defined in general by:\n\t\n\tIn other words, the function $\\phi$ of the integer $m$ results in a number $n$ strictly less than $m$, given by the number of elements between $1$ and $m$ whose greatest common divisor (\\SeeChapter{see section Set Theory}) with $m$ is $1$. We have already given a practical example of the utility of this indicator function in the section of Number Theory in the framework of the reduced systems of residues and which are at the center of the proof of Euler's theorem.\n\t\n\tThis can be formulated in the following form: the indicator $\\phi$ of the integer $m$ is defined as the number of positive integers less than or equal to $m$ and prime with $m$.\n\n\tThis function therefore has the remarkable property of counting the number of positive integers smaller than $m$ and \"relatively prime\" (ie, having greater common diviser equal to $1$) with $m$.\n\n\tHere are some values of $\\phi(m)$ for $m$ that range from $0$ to $19$:\n\t\n\tLet us now introduct two properties of $\\phi(m)$:\n\t\\begin{enumerate}\n\t\t\\item[P1.] We notice the (trivial) property of this function when we denote any prime number (remember that $1$ is not a prime number!) by the letter $p$ then:\n\t\t\n\t\tas it is highlighted by the table above.\n\t\n\t\t\\item[P2.] The Euler indicator can also be written in the following form if $p$ and $q$ are relatively prime (this is the padlock of the R.S.A system which is more complicated than the simple multiplication of $p$ and $q$):\n\t\t\n\t\tthis last relation can easily be verified (without proof) by taking some values from the preceding table (if we do it like Ramanujan...).\n\t\\end{enumerate}\n\t\\begin{theorem}\n\tThis done, given $(a,m)=1$ (the greatest commond divisor of $a$ and $m$, ie $a$ and $m$ are relatively prime), the \"\\NewTerm{Euler's theorem}\\index{Euler's theorem}\" says that if $m$ is a natural number and $a$ is relatively prime with $m$ then we have:\n\t\n\tin which we see the Euler indicator defined above. It is a rather surprising relation. Let's see if it works with $7$ and $2$ which are relatively prime between them:\n\t\n\tthe remainder being indeed therefore equal to $1$ when we compute $64$ modulo $7$.\n\t\\end{theorem}\n\t\\begin{dem}\n\tLet us first recall (\\SeeChapter{see section Number Theory}) that a reduced system of residuals modulo $m$ is a set of integers equation that satisfy the three properties:\n\t\\begin{enumerate}\n\t\t\\item[P1.] The remainder $r_i$ and $m$ are relatively prime, ie $(r_i,m)=1$\n\n\t\t\\item[P2.] $r_i$ is not congruate $r_j$ modulo $m$ when $i\\neq j$\n\n\t\t\\item[P3.] Each integer $x$ relatively prime with $m$ is congruent to some $r_i$ modulo $m$\n\t\\end{enumerate}\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tFor example, the set $\\{1,5\\}$ is a reduced system of residuals modulo $6$ or another example, $\\{1,2,3,4,5,6\\}$ is a reduced system of residuals modulo $7$. \\\\\n\n\tWe also check for the first example that $1$ is not congruent $5$ modulo $6$ (indeed, $6$ does not divide $(5-1)$) and that $5$ which is relatively prime to $6$ is congruent to itself.\\\\\n\n\tFor the second set, we notice that the cardinal of the set of residuals corresponds to the value of the Euler indicator for the number $7$.\n\t\\end{tcolorbox}\n\t\\begin{lemma}\n\tThus, given $\\{r_1,r_2,\\ldots,r_{\\phi(m)}\\}$ be a reduced system of residuals modulo $m$. We need for the proof of Euler's theorem, to prove beforehand the lemma that $\\{ar_1,ar_2,\\ldots,ar_{\\phi(m)}\\}$ is also a reduced system of residuals modulo $m$.\n\t\\end{lemma}\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tAs we have already mentioned in the previous example, you can observe that the cardinality of the set of residuals corresponds, for a given prime modulo $m$, to the result defined by the property P1 of the Euler indicator function $\\phi(m)$. This property is to this day only a \"conjecture\", that is to say, an assumption based on probabilities (because it seems it has not be proven so far!).\n\t\\end{tcolorbox}\n\tFor this, let us recall that by the property of a reduced system:\n\t\n\tand that by hypothesis:\n\t\n\tthen we want the lemma that:\n\t\n\tis also satisfied.\n\t\n\tLet us put for this $d=1$ (by tradition ...). We then have since $(r_i,m)=d$ that $d|r_i$ and $d|m$ and identically for $(a,m)=d$ that $d|a$ and $d|m$. Now if $d$ divides well $a$ or $r_i$ in this case we have $d|r_i(a)$ or (equivalently) $d|a(r_i)$. Therefore $d|ar_i$ and $d|m$ which allows us to write:\n\t\n\tLet us return to our Euler's theorem... if still follow ... We have just proved that there is bijection between the two sets of residues. That is to say that for each residue $r_i$ of the reduced system modulo $m$, we will have a residue $ar_i$ of the reduced system modulo $m$ according to the fundamental property of the congruence which we recall says that: we can multiply the two members of a congruence by the same integer number and it will remain congruent modulo $m$ and modulo $m$ multiplied by this integer number.\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tLet us take:\n\t\n\tindeed:\n\t\n\tbecause the remainder of the division of $30$ by $6$ is indeed equal to zero. If we take for example:\n\t\n\tthen we also:\n\t\n\tand the remainder is also zero...\n\t\\end{tcolorbox}\n\tLet us make a recall on bijection (\\SeeChapter{see section Set Theory}): We say that we have a bijection, if to each element of a starting set corresponds one and only one element in the arrival set (if there was for every man on Earth only one woman - in equal proportions therefore - there would be a bijection between the set of Men and Women).\n\n\tIn short, since there is bijection between the two sets of residues, we can write:\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tThe set $\\{1,5\\}$ is a reduced system of residuals modulo $6$ as we have already seen. So we have:\n\t\n\tWe then:\n\t\n\tIf we take an $a$ such that $(a,m)=1$, for example $a=7$ because indeed $(7,6)=1$, then:\n\t\n\tbecause $6|(35-5=30)$. Indeed, $6$ divides well $30$ with a remainder equal to $0$.\n\t\\end{tcolorbox}\n\tSo let us return to our bijection, which can be written by the elementary rules of algebra:\n\t\n\tSince:\n\t\n\t(you can verify, but this is the very definition of a set of residues!), we are then obliged to conclude that:\n\t\n\tand anyway, even if it does not seem obvious to you, you just need to multiply each of the members of the equality of the congruence by:\n\t\n\tas permit us one of the intrinsic properties of congruence previously proved.\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\tThis interlude theory being done, let us consider a number $N$ of which we wish to decide whether it is prime number or not.\n\n\tWe know from the Euler theorem and of the property P1 of the Euler indicator that if $N$ is a prime number and if $a\\in\\mathbb{N}$, where $a<N$, then:\n\t\n\twhich is named the \"\\NewTerm{Fermat's little theorem}\\index{Fermat's little theorem}\".\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThis relation follows from the properties we have presented in our proof of Euler's theorem:\n\t\n\tand of the property P1 of the function $\\phi(m)$ for a prime number p:\n\t\n\t\\end{tcolorbox}\n\tThe Fermat's little theorem is however, also valid for some numbers $N$ which are not prime. But the numbers which check this without being prime are rare, and it is worthwhile to look for a more sophisticated algorithm to know if $N$ is really prime or not (we say that in this case, $N$ is a good candidate for primality and is then named \"\\NewTerm{pseudo-prime number}\"). To test whether the number non-prime number $N$ is \"sufficiently prime\", we try with an algorithm to test the Fermat's little theorem a maximum number $a\\in\\mathbb{N}$ with $a<N$.\n\t\n\tAccording to the property of congruence (see above), we also have:\n\t\n\tWe can apply this last theorem to a number $N$ on which we would like to know at best whether it is prime or not.\n\n\tThere are a large number of other non-optimal methods for determining whether $N$ is prime; including preliminary division trials by $2$, $3$, $5$, $7$, $11$, $\\ldots$ and small prime numbers up to $p\\leq\\sqrt{N}$ according to the method of the Eratosthenes screening which is best known method in high schools.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tIn fact, with the help of a fairly powerful computer, we can decide whether a natural number of the order of $10^{300}$ ($10$ followed by $300$ zeros) is first or not within a few minutes or seconds. What is important to know is that, given a natural number $N$, one can decide in relatively short time whether it is prime or not, without knowing however its prime factors!!\n\t\\end{tcolorbox}\n\tHowever, according to the fundamental theorem of arithmetic we have that:\n\t\\begin{theorem}\n\tAny natural number $N$ can be written as a product of prime numbers, and this representation is unique, apart from the order in which the prime factors are arranged.\n\t\\end{theorem}\n\tThe proof is already in the section of Number Theory but exceptionally ew will reproduce it here as it is quite a short proof:\n\t\\begin{dem}\n\tThe proof uses Euclid's lemma (\\SeeChapter{see section Number Theory}): if a prime $p$ divides the product of two natural numbers $a$ and $b$, then either $p$ divides $a$ or $p$ divides $b$ (or both).\n\t\n\tIf $N$ is prime, and therefore product of a unique prime integer, namely itself, the result is true and the proof is complete (say that a prime number is product of itself is obviously a misnomer! ). Suppose that $n$ is not prime and therefore strictly greater than $1$ and consider the set:\n\t\n\tSo, $D\\subset \\mathbb{N}$ and since $N$ is composite, we have that $D\\neq \\varnothing$. According to the principle of good order, $D$ has a smaller element $p_1$ that is prime, otherwise the minimum choice of $p_1$ is contradicted. We can the write $N=p_1N_1$. If $n_1$ is prime, then the proof is complete. If $n_1$ is also composite, then we repeat the same argument as before and we deduce the existence of a prime number $p_2$ and of an integer $N_2<N_1$, such as $N=p_1p_2N_2$. By continuing we come inevitably to the conclusion that $N_k$ will be prime.\n\t\n\tSo finally we well show that any number can be decomposed into prime numbers factors with the principle of good order.\n\t\\begin{flushright}\n\t\t$\\square$  Q.E.D.\n\t\\end{flushright}\n\t\\end{dem}\n\tSo finally we have proved that any number is decomposable into prime factors using the principle of good order. There exist in the set of natural numbers $\\mathbb{N}$, some which can be expressed by (or only by) two prime factors traditionally denoted $p$ and $q$. These are the numbers we use in public key cryptography according to the R.S.A. protocol.\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tWe do not know to this day a law that makes it possible to easily and quickly calculate the $i$-th prime factor $p_i$ of a number. In fact, even with the most powerful computers we have now in year $2002$ when we write these lines, it would take several years to find the two prime factors $p$ and $q$ of a \"\\NewTerm{RAS number}\\index{RAS number}\" $N=pq$ where $p$ and $q$ are of the order of $10^{100}$ each. And it seems unlikely that we will discover in the near future an algorithm sufficiently effective to improve appreciably this computing time. Note that it is possible to determine in less than $5$ minutes (in year $2002$) whether a number of $200 $digits is prime or not. However, to factorize a number of $200$ digits into two prime numbers, it would take at least $100$ years. Wonderful thing: the theories that allow these exploits are very deep and were developed partly long ago in a very different setting.\\\\\n\t\n\tNow in year $2009$ a RSA number of $232$ digits (ie $768$ bit RSA number) was factorized ($7$ years after we wrote the lines above) in half a year one eighty 2.2 GHz AMD Opteron processors...\n\t\\end{tcolorbox}\n\tThe fact that it is much more difficult to find the prime factors of a number $N$ than to find out if $N$ is prime or compound is precisely what made it possible to develop this very ingenious method of encoding and decoding messages according to the RSA protocol.\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tLet us consider now a group of individuals who regularly transmit messages by e-mail and for which it is important that the messages are known only to the sender and the recipient. Then, the group member (here Alice) who wants to receive encrypted information, choose two very large prime numbers $p$ and $q$ of the order of $10^{100}$. To find such prime numbers, we randomly choose a number of $100$ digits and we check by one of the known algorithms whether it is prime or not and we repeat the experiment until we get a prime number. Once this is done with these two prime numbers, we compute the expression:\n\t\n\tnamed the \"\\NewTerm{modulus}\".\\\\\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\tThen, Alice (who is the only one in possession of the number $N$ for the moment) who wants to receive the encrypted informations chooses a positive integer $a$ such (p.g.c.d.) that:\n\t\n\tSo $a$ (often denoted $e$ in the literature) is a prime integer with $\\phi(N)$ sometimes named the \"\\NewTerm{generator}\".\\\\\n\t\n\tAnd as:\n\t\n\tSuppose a Alice wants to receive a message from Bob, one of her friends.\\\\\n\n\tAlice has therefore the \"\\NewTerm{public key}\\index{public RSA key}\", defined by the couple:\n\t\n\tto Bob.\\\\\n\t\n\tBob receives the public key and wishes to send the french message: \\textit{déclencher l'opération rouge}\\footnote{In English: \\textit{trigger the red operation}}. To do this, Bob first transforms the message into numbers by using the convention that each letter is replaced by its corresponding position in the alphabet starting counting from $01$ (the character \"space\" will be encrypted \"$27$\").\\\\\n\n\tThus the clear message denoted $M$ afterwards becomes:\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tFor technical reason, $M$ and $N$ must have no common divisor other than $1$ (otherwise, a possible spy could reduce the problem of two very large numbers difficult to manipulate to that of smaller numbers, easier to manipulate). Otherwise, at the end of $M$, we add numbers without value, such as $01$ (for example), to finally have $M$ and $N$ without common divisor other than $1$.\n\t\\end{tcolorbox}\n\tWe can also break $M$ into pieces $M_i$ whose number of digits does not exceed $99$ (remember that we set a lower limit of a power of $100$ for $p$ and $q$ and that it would therefore suffice that one of the two prime numbers to be $1$ and the other exactly a number with an exponent $100$ to be at the limit of the number $N$ then comprising at worst 100 digits, even if this extreme example is quite bad for technical reasons as more easy to crack), in which case one will always have:\n\t\n\t\\end{tcolorbox}\n\t\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\tWe cut $M$ into pieces, each being smaller than $N$:\n\t\n\tand we work successively with each piece $M_1,M_2,\\ldots,M_{12}$ of the message.\\\\\n\t\n\tWe consider the power $a$ of $M_1$, that is, $M_1â$. We replace $M_1$ by the number $\\bar{M}_1$, which is the remainder of the division by $N$ of the number $M_1^a$. The same procedure is followed for all other $M_i$ pieces such as:\n\t\n\tThen Bob then sends the encoded message to Alice:\n\t\n\tAn interceptor of the encoded message and of the public key, knowing the encryption algorithm, would therefore have to solve the problem of one equation with two unknowns (equation obtained simply from the mathematical expression of the encryption rule):\n\t\n\tObviously unspecified problem!\n\t\\end{tcolorbox}\n\tTo see how the receiver decrypts the message, we need an additional mathematical tool.\n\n\tLet us recall that the receiver chooses $a$ such that $(a,\\phi(N))=1$, which implies, according to the Bézout's theorem\\index{Bézout's theorem} (\\SeeChapter{see section Number Theory}), that if $a$ and $\\phi(N)$ are relatively prime (that is to say for recall that their greatest common divisor is $1$) there exist integers $x$ and $y$ such that (we can assume that $x>0$, in which case $y<0$):\n\t\n\tor otherwise written:\n\t\n\tThis is how we will determine the value of $x$ (we must use algorithms to find the solution $x$ to this equation).\n\t\n\tWhich means:\n\t\\begin{enumerate}\n\t\t\\item If $a$ is prime with $\\phi(N)$ then by the properties of congruence it is also prime with $p-1$ and $q-1$.\n\t\n\t\t\\item That $a$ is invertible modulo $\\phi(N)$\n\t\n\t\tIndeed, because:\n\t\t\n\t\tAnd according to the definition of congruence ($m|(a-b)$) we have:\n\t\t\n\t\tsince $\\phi(N)$ divides the right-hand side of $ax-1=\\phi(N)y$ and therefore by the equality, the left-hand member. Therefore:\n\t\t\n\t\\end{enumerate}\n\tOnly the receiver of the message, can easily calculate the number $x\\le a$ used above. In order to do this, it is necessary to be able to calculate the value of $\\phi(N)$ and thus know $p$ and $q$.\n\n\tIf $M_i$ is the original message (its numerical value) and $\\bar{M}_i$ is the received encoded message (its numeric value), then we have the following relation:\n\t\n\tThis is completely logical since the difference $M_i^a-\\bar{M}_i$, where for recall, $\\bar{M}_i$ is the remainder of the division of $M_i^a$ by $N$, can therefore only be divisible by $N$.\n\t\n\tAlice thus receives the coded message $\\bar{M}$ and raise to the power of $x$ the numbers $\\bar{M}_i$ and thus obtains the initial message.\n\n\tIndeed, she will apply for each $\\bar{M}_i$ the following mathematical property of congruence:\n\t\n\tThe \"\\NewTerm{private key}\\index{private RSA Key}\" (allowing to decrypt the message and which can be easily known only by the Alice) is thus defined by the couple:\n\t\n\tLet us give more indeed explanations about what we have stated just above! We have showed that:\n\t\n\tand from the property of symmetry of congruence (\\SeeChapter{see section Numbers}), we can write:\n\t\n\tNow we can write:\n\t\n\taccording to the second principal property of congruence, which says for recall that the two members of a congruence can be elevated to the same power! That latter relation can also be written (application of Bézout's theorem):\n\t\n\tRemains to prove that:\n\t\n\twhere we can write $M_i^{1-\\phi(N)y}$ under the form:\n\t\n\tNow, remember that we have proved Euler's theorem:\n\t\n\tand that one of the properties of congruence gives us the right to elevate to any power the two members of the congruence such as:\n\t\n\tBut as 1 raised to any power makes $1$, we have:\n\t\n\tThis last relation allows us to verify that we can authorize ourselves to write:\n\t\n\tsince the two left members are well modulos $N$. \n\t\n\tSo if we sum up all this, Alice receives a piece $\\bar{M}_i$ and raises it automatically to the power $x$ to obtain a number which according to her should be the true $M_i$. To be sure, it applies the verification:\n\t\n\tIt is easy to see that any interceptor can not decode and in addition verify if the decoding is indeed the right one, because for this it should know the value of $x$, which in turn depends on $\\phi(N)$, that it does not know either, because he does not know the prime factors of $N$ that are $p$ and $q$.\n\n\tIt is customary to say that the RSA system uses the numbers $p$, $q$ (secrets), $N$ (public), $a$ (public) and $x$ (secret). The whole being summed up by the triplet $\\{n, a, x\\}$ denoted sometimes in the literature $\\{n, e, d\\}$.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/arithmetics/rsa_detailed_cyphering.jpg}\n\t\t\\caption{Principle of RSA public key encryption}\n\t\\end{figure}\n\tAnd here is a small practical application with Maple 4.00b:\n\t\n\t\\texttt{> \\#Initialization of the Maple 4.00b random generator\\\\\n\t> randomize():\\\\\n\t> \\#definition of the desired size for N (this is an even number)\\\\\n\t> t:=30:\\\\\n\t> \\#Generation of two integers of t/2 bits size\\\\\n\t> x:=rand(2\\string^(t/2-1)..2\\string^(t/2))();\\\\\n\t> y:=rand(2\\string^(t/2-1)..2\\string^(t/2))();\\\\\n\t> \\#Calculation of the following prime numbers\\\\\n\t> p:=nextprime(x);\\\\\n\t> q:=nextprime(y);\\\\\n\t> \\#Generation of the RSA key\\\\\n\t> n:=p*q;\\\\\n\t> phi:=(p-1)*(q-1);\\\\\n\t> \\#We choose \"a\" empirically\\\\\n\t> a:=65537;\\\\\n\t> \\#We check that it is prime with phi\\\\\n\t> igcd(a,phi);\\\\\n\t> \\#we calculate the inverse of \"a\" modulo phi\\\\\n\t> x:=1/a mod phi;\\\\\n\t> \\#we choose a message a being \"1234\"\\\\\n\t> m:=1234;\\\\\n\t> \\#we cypher\\\\\n\t> c:=m\\&\\string^a mod n;\\\\\n\t> \\#we decode\\\\\n\t> c\\&\\string^x mod n;\\\\\n\t}\n\n\tFollowing the request of a reader here is a literal summary of what we have seen so far for the first steps of the algorithm above with practical value and a given message:\n\t\\begin{tcolorbox}[colframe=black,colback=white,sharp corners]\n\t\\textbf{{\\Large \\ding{45}}Example:}\\\\\\\\\n\tWe want to cypher the message $M=314158$.\n\n\t\\begin{enumerate} \n\t\t\\item We choose $p$ and $q$ prime and sufficiently large:\n\t\t\n\t\twe then have:\n\t\t\n\t\n\t\t\\item We compute the Euler indicator:\n\t\t\n\t\n\t\t\\item We choose the generator $a$ such that:\n\t\t\n\t\tand for this we will take $a=5$. The pair $(a,N)$ is the public key (can be distributed to everyone for a specified time).\n\t\n\t\t\\item Then we calculate:\n\t\t\n\t\tSo the pair $(x, a)$ is the private key (to be kept secret).\n\t\t\n\t\t\\item Now we cypher with:\n\t\t\n\t\tTherefore:\n\t\t\n\t\t\n\t\t\\item Now to decypher (the exponent calculation cannot be done with sample spreadsheet softwares or simple online scientific calculator):\n\t\t\n\t\\end{enumerate}\n\t\\end{tcolorbox}\n\tFor security reasons, public key cryptography is used in conjunction with secret key cryptography. For example, at the time of writing these lines, the SSL protocol for Internet pages uses the RSA to exchange a secret key (symmetric system) and then encrypts the data using a conventional symmetric algorithm.\n\n\tLet us conclude this brief presentation of the messages cyphering by informing the reader that the American government (and not only...!) closely monitors the activities of mathematicians who work on the factorization of large numbers. Indeed, if one of them could find an algorithm allowing to factorize in a short time a number of two hundred digits (greater than $524$ bits unsigned), this would jeopardize the secret nature of several communications of a military order. In fact, this surveillance has raised a protest by the scientists in the United States, who see their professional freedom undermined (Notices of American Mathematical Society, January 1983).\n\n\tFor technical information, the software PGP (Pretty Good Privacy) published my the MIT (Massachusetts Institute of Technology), uses an RSA encryption system.\n\t\n\t\\pagebreak\n\n\t\n\t\\pagebreak\n\t\\subsection{Hash functions}\n\tA \"\\NewTerm{hash function}\\index{hash function}\" is a function that associates to a big set a much smaller set (of the order of a few hundred bits) that is characteristic of the starting. This property makes it very used in computing, in particular for quick access to data thanks to \"hash tables\" or to check the result of huge data transmission (downloads). Indeed, a hash function makes it possible to associate a particular integer with a string. Thus, if we know the fingerprint of the stored character strings, we can quickly check whether a string is in this table (in $\\mathcal{O}(1)$ if the hash function is good enough). Hash functions are also extremely useful in cryptography to speed up encryption.\n\n\tThe two most commonly used condensation algorithms at the beginning of the 21st century are the \"Secure Hash Algorithm (SHA)\", which calculates a $160$-bit summary, and the MD5 (Message Digest 5 - Run Rivest 1992), which calculates a $128$-bit summary called \"Message Digest\".\n\t\n\t\\subsubsection{MD5 message digest condensation function}\n\tThis \"\\NewTerm{Message Digest MD5}\\index{message Digest MD5}\" algorithm is (was) used mainly for digital signatures (notion used, when validating certificates of authenticity as we will see later) but as it has been found to suffer from extensive vulnerabilities\\footnote{In 2004 it was shown that MD5 is not collision-resistant. As such, MD5 is not suitable for applications like SSL certificates or digital signatures that rely on this property for digital security.}. It can still be used as a checksum to verify data integrity, but only against unintentional corruption.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/md5.jpg}\n\t\t\\caption{Illustrated result of MD5 algorithm}\n\t\\end{figure}\n\tHere are the different stages of its operation:\n\t\\begin{enumerate}\n\t\t\\item Completion:\n\t\t\n\t\tThe message consists of $b$ bits. The message is completed with a $1$, and sufficiently enough $0$ for the extended message to have a multiple length of $512$ bits. After this initial processing, the input text is manipulated in blocks of $512$ bits divided into $16$ sub-blocks \\texttt{M[i]} of $32$ bits.\n\t\t\n\t\t\\item Initialization:\n\t\t\n\t\tWe define the $32$-bit \"chaining variables\" \\texttt{A}, \\texttt{B}, \\texttt{C} and \\texttt{D} initialized as follows (the digits are hexadecimal):\n\t\t\\begin{center}\n\t\t\t\\texttt{A=01234567}, \\texttt{B=89ABCDEF}, \\texttt{C=FEDCBA98}, \\texttt{D=76543210}\n\t\t\\end{center}\n\t\tWe also define four non-linear functions \\texttt{F}, \\texttt{G}, \\texttt{H} and \\texttt{I} which take arguments coded on $32$ bits, and return a value on $32$ bits, the operations taking place bit by bit.\n\t\n\t\t\\texttt{F(X,Y,Z) = (X AND Y) OR (NOT (X) AND Z)}\\\\\n\t\t\\texttt{G(X,Y,Z) = (X AND Z) OR (Y AND NOT (Z))}\\\\\n\t\t\\texttt{H(X,Y,Z) = X XOR Y XOR Z}\\\\\n\t\t\\texttt{I(X,Y,Z) = Y XOR (X OR NOT (Z))}\n\t\n\t\tWhat is important with these four functions is that if the bits of their arguments \\texttt{X}, \\texttt{Y} and \\texttt{Z} are independent, the resulting bits are also independent.\n\t\t\n\t\t\\item Iterative calculation:\n\t\t\n\t\tThe main loop has $4$ rounds (see figure below) which each use a different nonlinear function (hence the fact that there are $4$ rounds). Each round therefore consists of $16$ executions of an operation (because there are $16$ sub-blocks).\n\n\t\tEach operation calculates a non-linear function of three of the variables \\texttt{A}, \\texttt{B}, \\texttt{C} and \\texttt{D}, adds to it a sub-block $M[i]$ of the text to be encrypted, a predefined constant $s$ (encoded on $32$ bits) and to a circular shift on the left of a variable number of bits $n$. Here is the example for \\texttt{A}:\n\t\t\\begin{itemize}\n\t\t\t\\item \\texttt{A = B + A + F(B,C,D) + M[i] + s} circularly offseted from $n$ bits to the left\n\t\t\t\\item \\texttt{A = B + A + G(B,C,D) + M[i] + s} circularly offseted from $n$ bits to the left\n\t\t\t\\item \\texttt{A = B + A + H(B,C,D) + M[i] + s} circularly offseted from $n$ bits to the left\n\t\t\t\\item \\texttt{A = B + A + I(B,C,D) + M[i] + s} circularly offseted from $n$ bits to the left\n\t\t\\end{itemize}\n\t\tThis new value of \\texttt{A} is then summed with the old one.\n\t\t\n\t\t\\item Writing of the summary (fingerprint):\n\t\t\n\t\tThe $128$-bit summary is obtained by putting end-to-end the four $32$-bit chaining variables \\texttt{A}, \\texttt{B}, \\texttt{C}, \\texttt{D} obtained at the end of the iteration.\n\t\\end{enumerate}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/md5_algorithm_flow.jpg}\n\t\t\\caption{Illustrated MD5 algorithm flow (source: Wikipedia, author: Dake)}\n\t\\end{figure}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tNormally we would put the MD5 algorithm pseudocode but... as it is a pain in the a.. to write it in LaTeX with the \\texttt{algorithm2e} package we will for the moment not do it....\n\t\\end{tcolorbox}\n\tThe MD5 function as we have already mention it is not safe and not unique (two different inputs can give the same signature: we talk then of \"collision\"). However, the MD5 function is still widely used as a verification tool during downloads and the user can validate the integrity of the downloaded version thanks to the fingerprint. This can be done with a program for example named \\texttt{md5sum} for MD5 and \\texttt{sha1sum} for SHA-1 (see just below).\n\t\n\tHere is the figerprint (abusively sometimes named \"signature\") obtained on a sentence\\footnote{Made with the online tool \\url{http://www.md5hashgenerator.com}} (which we took without accents):\n\t\\begin{center}\n\tMD5(\"Wikipedia, the free encyclopedia\") = f8aa0d3b1dae3f41d67c200688723c1b\n\t\\end{center}\n\tBy modifying a character, this impression drastically changes:\n\t\\begin{center}\n\tMD5 (\"Wikipedia, the free encyclopediA\") = f9829ad9d4c2713140973520cad9206c\n\t\\end{center}\n\tSpecifically, the MD5 fingerprint or can be performed as follows: when downloading a program, we write (copy) the character set indicated on the download page. When this download is complete, we launch one of the aforementioned software on the downloaded file.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.87]{img/computing/md5_cisco_hash.jpg}\n\t\t\\caption{Illustrated MD5 downlaod hash from CISCO}\n\t\\end{figure}\n\tIt must also be noticed why that main reason why using symmetric (or asymmetric) encryption is not advisable for protecting passwords is: key management. When using encryption, you must protect the encryption key (or the entropies from which the key is derived). And protecting the key is a very difficult task to solve. Hashing (with SHA, MD5, or any other algorithm) solves the problem of key protection, because you don't need to keep any secret value (other than salt, but salt is significantly less sensitive than encryption key; you can store salt in plain text). So if you only keep passwords for authentication purposes (performed by your app), there is absolutely no reason to use encryption; hashing would do just fine. \n\t\n\t\\pagebreak\n\t\\subsubsection{SHA-1 Secure Hash Algorithm condensation function}\n\tThe \"\\NewTerm{SHA-1}\\index{SHA-1}\" or \"\\NewTerm{Secure Hash Algorithm-1}\\index{Secure Hash Algorithm-1}\" is used in competition with the MD5 for Digital Signature Algorithm as specified by the Digital Signature Standard (DSS). It was designed by the United States National Security Agency and is a U.S. Federal Information Processing Standard published by the United States NIST\n\n\tSHA-1 is no longer considered secure against well-funded opponents. In 2005, cryptanalysts found attacks on SHA-1 suggesting that the algorithm might not be secure enough for ongoing use, and since 2010 many organizations have recommended its replacement by SHA-2 or SHA-3. Microsoft, Google, Apple and Mozilla have all announced that their respective browsers will stop accepting SHA-1 SSL certificates by 2017.\n\n\tOn February 23, 2017 CWI Amsterdam and Google announced they had performed a collision attack against SHA-1, publishing two dissimilar PDF files which produce the same SHA-1 hash as proof of concept (\\url{https://shattered.io}).\n\n \tFor a message of length less than $2^{64}$, the SHA-1 generates a $160$-bit digest of the message named also \"hash\" or \"fingerprint\". Again, identically to the MD5, a tiny modification of the original message must have a big impact on the condensed message and there must not be an identical Message Digest for two messages of different origin.\n\n\tAs for the MD5, we work on messages whose length is a multiple of $512$ bits.\n\t\\begin{enumerate}\n\t\t\\item Completion:\n\t\t\n\t\tIf the message does not have a length of $512$ bits, we add as many $1$ as necessary at the end of the message. The last $64$ bits of the $512$-bit block are used to set the original length of the message. The $512$-bit block is then transformed into sub-blocks \\texttt{M[i]} of $32$ bits each expressed in hexadecimal ($0\\ge i\\ge 15$).\n\t\t\n\t\t\\item Initialization:\n\t\t\n\t\tAs for the MD5, this time we define $80$ chaining variables of $32$ bits $K[i]$ initialized as following (the digits are hexadecimal):\n\t\t\\begin{itemize}\n\t\t\t\\item \\texttt{K[t]=01234567} for $0\\ge t\\ge 19$\n\t\t\t\\item \\texttt{K[t]=89ABCDEF} for $20\\ge t\\ge 39$\n\t\t\t\\item \\texttt{K[t]=FEDCBA98} for $40\\ge t\\ge 59$\n\t\t\t\\item \\texttt{K[t]=76543210} for $60\\ge t\\ge 79$\n\t\t\\end{itemize}\n\t\tWe also define $80$ non-linear functions \\texttt{F[0]}, \\texttt{F[1]}, \\texttt{F[2]}, ..., \\texttt{F[79]} which take $32$-bit arguments and return a $32$-bit value, the operation being done bit by bit:\n\t\t\\begin{itemize}\n\t\t\t\\item \\texttt{F[t](X,Y,Z) = (X AND Y) OR (NOT(X) AND Z)} for $0\\ge t\\ge 19$\n\t\t\t\\item \\texttt{F[t](X,Y,Z) = (X XOR Y) XOR D } for $20\\ge t\\ge 39$\n\t\t\t\\item \\texttt{F[t](X,Y,Z) = (X AND Y) OR (X AND Z) OR (Y AND Z)} for $40\\ge t\\ge 59$\n\t\t\t\\item \\texttt{F[t](X,Y,Z) = X XOR Y XOR Z} for $60\\ge t\\ge 79$\n\t\t\\end{itemize}\n\t\tWhat is important with these $80$ functions is that if the bits of their arguments \\texttt{X}, \\texttt{Y} and \\texttt{Z} are independent, the bits of the result are also independent.\n\t\n\t\t\\item Iterative calculation:\n\t\t\n\t\tThe iteration uses two buffers, each consisting of the use of $5$ chaining variables. The chaining variables of the first buffer are denoted \\texttt{A}, \\texttt{B}, \\texttt{C}, \\texttt{D}, \\texttt{E}. The second buffer contains the chaining variables \\texttt{H[0]}, \\texttt{H[1]}, \\texttt{H[2]}, \\texttt{H[3]}, \\texttt{H[4]}.\n\t\\end{enumerate}\n\n\tMoreover, let \\texttt{S\\string^n} denote the circular shift of \\texttt{n} bits to the left, here is the SHA-1 algorithm (if we have the time in the future we will write it properly with the correct LaTeX package...):\n\t\n\t\\begin{verbatim}\n\tFor t = 16 to 79 Do\n     M[t] = S^1(M[t-16] XOR M[t-15] XOR M [t-14] XOR M [t-13]);\n\tEnd For\n\tA = H[0];\n\tB = H[1]; \n\tC = H[2];\n\tD = H[3]; \n\tE = H[4]\n\tFor t = 0 to 79 Do\n\t     TEMP = S^5(A) + F[t](B,C,D) + E + M[t] + K[t]\n\t     E = D; \n\t     D = C; \n\t     C = S^30(B); \n\t     B = A; \n\t     A = TEMP;\n\tEnd For\n\tH[0] = H[0] + A;\n\tH[1] = H[1] + B; \n\tH[2] = H[2] + C; \n\tH[3] = H[3] + D; \n\tH[4] = H[4] + E;\n\t\\end{verbatim}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tSince we have written this text on SHA-1, new versions, sometimes significantly different of SHA-1 have been released. The SHA-0 was realeased in 1998, the SHA-1 presented above is a minor correction of the SHA-0, the SHA-2 was realeased in 2001 and finally the SHA-3 in 2012.\n\t\\end{tcolorbox}\n\t\t\n\tTo sum up a bit, it msut be clear that MD5 (Message-Digest algorithm 5) is a cryptographic hash function, while Advanced Encryption Standard (AES) or RSA are symmetric-key encryption algorithms, so they are used for different purposes. A hash, like MD5 or SHA are used to verify passwords because they are hard to invert, that is, to obtain the password from the hash-string. An AES or RSA encryption, on the other hand, are invertible, the original message can be obtained if we know the key. \n\t\n\t\n\t\\subsection{Certificate based authentication}\n\tWe saw during our study of public key and secret key cryptography that there was an issue in the system of transmission of the keys at the beginning of the communication.\n\n\tThus, in both systems, the issue lies in the fact that a malicious person (\"man-in-the-middle\" attack) can replace the real interlocutor and send either a false secret key or a false public key (depending on the case).\n\n\tThus, a certificate of authenticity makes it possible to associate a key with an entity (a person, a machine, etc.) in order to ensure its validity (association with the \"real person\"). The certificate is in a way the identity card of the key or the \"\\NewTerm{digital signature}\\index{digital signature}\", issued by an organization named \"\\NewTerm{certification authority}\\index{certification authority}\".\n\n\tThe technologies using digital signatures are part of a larger set known as \"\\NewTerm{Public Key Infrastructure (PKI)}\\index{public key infrastructure}\". The whole takes place by means of certificates which you can obtain from a Certification Authority (see example below). When you request your certificate, your computer creates the key pair consisting of a private key (the yellow on the schema) and a public key (the black one). Your private key is secret and it is only you who have access to it while the public key is freely available for everyone. Your public key will be attached to your certificate that you will get from the certification authority to whom you have submitted your certificate request.\n\n\tThe PKI (on which the IPSec connection is based) essentially targets $4$ important points:\n\t\\begin{enumerate}\n\t\t\\item The authentication (the recipient of your email must be able to verify that it is you who sent the object and not another individual).\n\n\t\t\\item Integrity (ensure that the content has not been changed along the way).\n\n\t\t\\item Confidentiality (ensuring that the content is readable only by the recipient).\n\n\t\t\\item Non-repudiation (arising from the first 3 points)\n\t\\end{enumerate}\n\tThe certification authority is responsible for issuing the certificates, assigning them a validity date, and possibly revoking certificates before that date if the key is compromised.\n\t\n\tCertificates are small files divided into two parts:\n\t\\begin{itemize}\n\t\t\\item The part containing the information\n\t\t\n\t\t\\item The part containing the signature of the certification authority (see Microsoft Internet Explorer browser for an example)\n\t\\end{itemize}\n\n\tThe certificate structure is standardized by the International Telecommunication Unification (ITU) standard X.509, which defines the information contained in the certificate:\n\t\\begin{itemize}\n\t\t\\item The name of the certification authority (VeriSign for example)\n\n\t\t\\item The name of the owner of the certificate (the UBS bank for example)\n\n\t\t\\item The date of validity of the certificate ($X$ day from the current date)\n\n\t\t\\item The encryption algorithm used (MD5RSA)\n\n\t\t\\item The owner's public key\n\t\\end{itemize}\n\tHere is a quite good schematic example:\n\t\n\tTo sign the message you are sending (point \\circledtext{5} in the figurebelow), it is sufficient to apply a hash function (point \\circledtext{1}) which produces a summary (hash code) of the message (using MD5 or any version of SHA). The summary (fingepring) obtained is (almost...) specific to each message, like the image of a fingerprint we know that a hash algorithm ensures that if a single bit of the original text is modified and a new hash is made, the latter will with a very high probability radically different from the first one, and the hashed code can then be encrypted using your private key (\\circledtext{2} and \\circledtext{3}), this results constitutes the \"digital signature\". The recipient of the message (point \\circledtext{6}) can then verify that you are the sender by ecrypting the digital signature (point \\circledtext{7}), by means of your public key (point \\circledtext{8}), that you transmitted to it automatically with the mail (point \\circledtext{4}), to get the hashed code (point \\circledtext{9}). The recipient then applies the same hash function to the received message (point \\circledtext{10} in the diagram). If the two codes (points \\circledtext{11} and \\circledtext{12} on the schema) are identical, you are the sender of the message (authentication) and the message has not been altered (integrity).\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.9]{img/computing/principle_of_digital_signatures.jpg}\n\t\t\\caption{Principle of digital signatures}\n\t\\end{figure}\n\tAll this looks very complicated, but in practice, depending on the software, you just have to click on one or three buttons on the screen to start the whole process.\n\n\tOtherwise let's see another figure involving now a Certificate authority:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/certificate_authority.jpg}\n\t\t\\caption{Principle of certificate authority (source: Pour la Science)}\n\t\\end{figure}\n\tWhere we have:\n\t\\begin{enumerate}\n\t\t\\item Alice uses a private key ($a$) as well as a public key ($b$) received from a certificate authority that has typically transmitted the private and public keys to Alice in a smart card containing a digital certificate ($c$). This certificate also includes the signature of the certificate authority, which can be verified by any person (or software) who knows or has access to the public key of this organization.\n\t\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/quovadis_suisse_id.jpg}\n\t\t\\caption[]{Example of digital certificate smart card used by the author of this chapter}\n\t\\end{figure}\n\t\t\n\t\t\\item The public key ($d$) of the certificate authority is provided to those who need it, for example Bob. This key can be included in the web browsers programs and in other software used for secure computer communications.\n\t\t\n\t\t\\item Alice digitally signs the message she sends to Bob. First, she creates a digest of the message by applying a hash function to it. The digest thus created is then encrypted using the secret key of Alice which gives the digital signature of the message ($e$). This signature is sent to Bob at the same time as the encrypted message ($f$) and the public key.\n\t\t\n\t\t\\item Bob uses the public key of the certificate authority to verify that the official digital signature on the certificate is authentic and that the accompanying public key is that of Alice. He then uses this key to decrypt Alice's digital signature and gets the digest of the message. Finally, Bernard applies the hash function to the message sent by Alice and thus gets a digest of the message. If this digest is identical to that obtained by Alice's numerical encryption, Bob is sure that the message comes from Alice and has not been altered by a third person.\n\t\\end{enumerate}\n\t\n\t\\pagebreak\n\t\\subsection{Quantum cryptography}\n\t\"\\NewTerm{Quantum cryptography}\\index{uantum cryptography}\" is a marketing expression, but somewhat misleading: it is not a question of encrypting a message using quantum physics, but of using quantum physics to ensure that the transmission of the key has not been spied. Currently used popular public-key encryption and signature schemes (RSA) can be broken by quantum adversaries. The advantage of quantum cryptography lies in the fact that it allows the completion of various cryptographic tasks that are proven or conjectured to be impossible using only classical (i.e. non-quantum) communication (see below for examples). For example, it is impossible to copy data encoded in a quantum state and the very act of reading data encoded in a quantum state changes the state. This is used to detect eavesdropping in quantum key distribution.\n\n\tIndeed, as we have already explained it in the section of Quantum Computing, the transmission of a message, encrypted or not, can be done using the two orthogonal linear polarization states of a photon, for example $|x\\rangle$, $|y\\rangle$. We can decide to assign by convention the value $1$ to the polarization $|x\\rangle$ and the value $0$ to the polarization $|y\\rangle$: each photon therefore carries one bit of information. Any encrypted or unencrypted message can then be written in binary language, such as a sequence of $0$ and $1$, and the message $1001110$ will be encoded by Alice thanks to the sequence of photons $|x\\rangle |y\\rangle |y\\rangle |x\\rangle |x\\rangle |x\\rangle |y\\rangle$, which she will send to Bob for example by an optical fiber. Using a birefringent plate, Bob separates the photons with vertical and horizontal polarization and two detectors placed behind the slide allow him to decide whether the photon was polarized horizontally or vertically:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/photon_polarization_experiment.jpg}\n\t\t\\caption{Thought experiment for polarization measurement}\n\t\\end{figure}\n\t\n\tThe whole process and protocol can be summarized by the excellent following figure:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.65]{img/computing/quantum_cryptography.jpg}\n\t\t\\caption{Quantum key distribution}\n\t\\end{figure}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe protocol described above is named BB84, named after its inventors Bennett and Brassard.\n\t\\end{tcolorbox}\n\tLet us now turn to the formal part (we strongly recommand the reader to first take a look the section of Quantum Computing!).\n\n\tThe states of the quantum system are the states of polarization of a photon: the measurements (of the observable) will also have its polarization states. Possible measures will include:\n\t\n\twe will denote the corresponding states $|0\\rangle$ and $|1\\rangle$ (orthonormal basis of the space of the states of polarization): it is the base H/V (Horizontal/Vertical).\n\n\tLet us consider several cases:\n\t\\begin{enumerate}\n\t\t\\item[C1.] Given a photon in the state $|\\Psi\\rangle=|0\\rangle$ then as we have seen in the section Quantum Computing, we will have:\n\t\t\n\n\t\t\\item[C2.] Or a photon in the state:\n\t\t\n\t\\end{enumerate}\n\tAnd it customary to write the sequence of the key as following:\n\t\n\t\\begin{tcolorbox}[title=Remarks,colframe=black,arc=10pt]\n\t\\textbf{R1.} Let us recall that this (famous) value is chosen for normalization purposes such as that $\\langle \\Psi|\\Psi\\rangle$!!! Many people ask the question of where the square root comes from in Quantum Computing? The answer is simply for normalization as we have detailed it in the section of Quantum Computing\\\\\n\n\t\\textbf{R2.} Let us also recall that the photons $|\\Psi_{01}\\rangle$ and $|\\Psi_{11}\\rangle$ are not polarized in the direction \"$|0\\rangle+|1\\rangle$\" (ie in the oblique direction) but are in a quantum superposition of these two polarizations!\n\t\\end{tcolorbox}\n\tThen for example (we apply as we saw in the section of Quantum Computing, the test $|0\\rangle$ to the state $|\\Psi_{01}\\rangle$):\n\t\n\tand:\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tLet us recall that in this book, we write in Quantum Physics the module of a complex number and the norm, indistinctly by the symbol $||{}||$ therefore caution to the possible confusions!\n\t\\end{tcolorbox}\n\t\n\t\\subsection{Alternative cryptography}\n\tMathematicians sometimes venture out of the beaten path of Number Theory: they invent cryptosystems based on braids or networks (see the corresponding sections of Knot Theory or Graph Theory). Physicists are not left behind and offer methods of encryption that use the theory of chaos or quantum physics. The latter would provide a definitive solution to the delicate problem of key exchange and jeopardize cryptosystems based on factorization.\n\n\tMost of these methods are outside the scope of this book for the moment but we can give however a non-exhaustive list:\n\t\\begin{itemize}\n\t\t\\item The LLL algorithm based on the mesh structure of sets of numbers and based on the Minkowski theorem ensuring that the content of a disc of given radius at a point contains at least one other point of the network\n\n\t\t\\item The ultravariable cryptography in which the data pass through systems of superimposed quadratic equations.\n\n\t\t\\item Optical hyperchaos, obtained by the passage of a LASER in a IKEDA ring in which a nonlinear wavelength material is integrated.\n\n\t\t\\item ...\n\t\\end{itemize}\n\tThe future will tell us the rest!\n\t\n\t\n\t\n\n\n\t\n\n\t\\begin{flushright}\n\t\\begin{tabular}{l c}\n\t\\circled{50} & \\pbox{20cm}{\\score{2}{5} \\\\ {\\tiny 12 votes,  50.00\\%}} \n\t\\end{tabular} \n\t\\end{flushright}\n\n\t%to make section start on odd page\n\t\\newpage\n\t\\thispagestyle{empty}\n\t\\mbox{}\n\t\\section{Quantum Computing}\n\t\\lettrine[lines=4]{\\color{BrickRed}Q}uantum computing (we should rather speak of \"\\NewTerm{quantum calculation}\\index{quantum calculation}\" because we are currently very far from an input / output system) is a beautiful example of the use of specific theoretical models of quantum physics for treatment and the transmission of information.\\\\\n\t\n\tHowever it must also be remembered that the behavior of transistors etched on the chip in your computer could not be imagined in 1947 by Bardeen, Brattain and Shockley that from their knowledge of quantum physics. So all of our electronic devices already operating on the basis of semiconductors operate with developments achieved through quantum physics.\n\t\n\tThe big news, since the early 1980s, is the ability of physicists to manipulate and observe individual elementary quantum objects: photons, atoms, ions, etc. It is this ability to manipulate and observe basic quantum objects that is the cause of quantum information, where these elementary quantum objects will physically build the \"\\NewTerm{qubits}\\index{qubits}\" (for \"Quantum Bit\"). That said, no fundamentally new concept has been introduced since the 1930s and the founding fathers of quantum physics (Heisenberg, Schrödinger, Dirac, Planck, Einstein, etc.), if they revived today, would not be surprised by quantum computing, even if they would surely be surprised by the prowess of the experimenters who now realize experiences qualified in their era of \"gedanken experiment\" (imaginary experiment that was impossible to do in laboratory).\n\t\n\tIt is also interesting to notice that the increasing miniaturization of electronics will find its limits because of quantum effects, which will become essential below the nanometer. Thus, we believe that Moore's Law (which assumption that the computing power of machines doubles roughly every $18$ months) may not be correct anymore by the years 2015-2020.\n\t\n\tIt is likely that the trend of the study of quantum physics and its application to quantum information (and quantum electronics and quantum telecommunications) will explode in the coming decades (especially towards the end of the 21st century). Thus, engineering schools will integrate in all study field Quantum Physics in school curricula. What physicists studying for soon already almost 100 years in their curriculum.\n\t\n\tBefore moving to the formal side, we felt, however, interesting to make a small popularized passage because we noticed that it helps to understand the calculations that will be made thereafter.\n\t\n\tIn the 70 and 80, the first quantum computers are born from the minds of physicists such as Richard Feynman, Paul Benioff, David Deutsch and Charles Bennett. Feynman's idea was that instead of complaining that the simulation of quantum phenomena demand enormous powers to our to days computers today, that we use the power of quantum phenomena to make the computers faster than classic computers.\n\t\n\tDuring long time physicists doubted that quantum computers can be used, and even that we can do something viable if they existed. But:\n\t\\begin{itemize}\n\t\t\\item In 1994, Peter Shor, a scientist of AT\\&T shows it is possible to factor large numbers in a reasonable time using a quantum computer. This discovery unlocks suddenly credits for quantum computers reasearch.\n\t\t\n\t\t\\item In 1996, Lov Grover, invented an algorithm based on quantum computers to find an entry in an unsorted database.\n\t\t\n\t\t\\item In 1998, IBM was the first to present a $2$-qubit quantum calculator.\n\t\t\n\t\t\\item In 1999, the IBM R\\&D team used the Grover algorithm for fast quantum search on a database (quantum database search) on a calculator with $3$-qubits and beat their record the following year with a $5$-qubit computer.\n\t\t\n\t\t\\item In 2001, IBM created a quantum computer with $7$-qubits and factored the number $15$... thanks to the Shor algorithm (\\SeeChapter{see section Theoretical Computing}). Calculators with $7$-qubits are built around chloroform molecules and their useful life is no more than a few minutes.\n\t\t\n\t\t\\item In 2007, the Canadian company D-Wave during a demonstration presented a quantum computer with $16$-qubits.\n\t\t\n\t\t\\item In May 2013, Google announced that it was launching the Quantum Artificial Intelligence Lab, hosted by NASA's Ames Research Center, with a $512$-qubit D-Wave quantum computer. \n\t\t\n\t\t\\item In October 2015 researchers at University of New South Wales built a quantum logic gate in silicon for the first time.\n\t\\end{itemize}\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tAs a $1$ fermion spin qubit is equivalent to $2$ bits, we have then that $N$ fermion spin qubits are equal to $2^N$ classical bits. Therefore if one day we reach the $100$ fermion spin qubits computer we will have a potential memory of $2^{100}\\cong 1\\cdot 10^{15}$ Petabytes...\n\t\\end{tcolorbox}\n\tThe memory of a classical computer is made of bits (\\SeeChapter{see section Logical Systems}). Each bit carries either a $1$ or a $0$ (bipolar mode). The machine computes by manipulating those bits. A quantum computer is working on a set of qubits. A qubit can wear either a $1$ or a $0$, or a superposition of a $1$ and a $0$ (or, more accurately, he wears a phase distribution). The quantum computer computes by manipulating those distributions as discussed in detail below.\n\t\n\tQuery a qubit whose phase angle is not $0^{\\circ}$ or $90^{\\circ}$ ($\\pi/2$) is not very useful: we will get the answer $0$ with a given probability and $1$ with another probability and ... it is possible to construct random generators much cheaper! However, if we manage to create an algorithm that systematically leads it to a phase $0^{\\circ}$ or $90^{\\circ}$, we get a deterministic result. But is also necessary that it corresponds to a sought response.\n\t\n\tA quantum computer could be implemented from any particles that can have two states. It can be built from photons, or from any particle or atom/molecule having a spin.\n\t\n\tAs we know, a classical computer with two one bit can only store numbers with one digits composed of one or zeros(\\SeeChapter{see section Logic Systems}) for a total of $2^1=2$ states that it must treat separately. At one point, he could contain the bits $1$ for example.\n\t\n\tA quantum computer with one qubit can actually store $3$ as it can have a project state corresponding to $1$ or to $0$ and any superposition of the states $0$ and $1$ with a given probability (the third state!) before being observed (\\SeeChapter{see section Wave Quantum Physics}). When the calculator make the measurement the state superposition is canceled as we know and therefore the third state can only be used (at least as far as we know) for intermediate and temporary calculations (as they cannot be read with our actual knowledge). This is why today qubits are specialized for given algorithms and we have \"quantum calculators\" but not \"quantum computers\".\n\t\n\tBefore we study the mathematical aspects let us start by the study of one of the most famous cat in the world to better understand (we hope so):\t\n\t\n\t\\subsection{Schrödinger's Cat superposition}\n\tAs we have study it in details in the section of Quantum Sections, unlike in classical mechanics, essentially different states can mix in\nquantum mechanics at least until a specific property is measured!\n\n\tNow let us recall this famous thought experiment:\n\t\n\t\\begin{enumerate}\n\t\t\\item Put a (living) cat in box.\n\t\t\\item Add a container with deadly poison, that can be remotely released.\n\t\t\\item Close and seal the box.\n\t\t\\item Connect the remote to a quantum randomness source (e.g. nuclear decay).\n\t\\end{enumerate}\n\tIn what state\" is the cat? Is it alive or dead? Who knows?\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/schrodinger_cat_experiment.jpg}\n\t\t\\caption{Schrodinger Cat experiment (source: Wikipedia)}\n\t\\end{figure}\n\tAs long as no one checks (!!!), it a sensible way to think about this to\nconsider the cat being in an intermediate state:\n\t\n\tAs long as no one checks (!!!) the cat is in a superposition of two\nstates that are classically impossible to consider at the same time.\n\n\tNow let us start by understanding the underlying concepts of quantum theory and of quantum computing with the study of the polarization of the photon.\n\t\n\tNow if we open the box obviously, we will see (\"measure\") either a dead or alive cat.\n\t\n\tBy \"measuring\" the system, we put it back in a classical, pure state! Asw we knot it already: Measuring affects the system!\n\t\n\tThe Cat set of states will be written:\n\t\n\tTake a second cat, same arrangement and consider a 2-cat system:\n\t\n\tThat is to say with two cats:\n\t\n\tTherefore as we can see the central idea of quantum computing is manipulating the $N$-qubit system to change at the same time ALL $2^N$ pure states probabilities but when the $N$-qubit system will be measured,\nonly a single pure state will be picked out!\n\n\tA quantum algorithm must therefore modify the probability distribution of the quantum system, such that the correct \"result\" state has an (almost) $100\\% $ probability.\n\t\n\t\\subsection{Photon polarization}\n\tSince Albert Einstein, we know that light is composed of photons, or particles of light and it has a dual wave-particle appearance (\\SeeChapter{see section Wave Optics}). If we reduce the light intensity of a beam of photons, we should be able to study the polarization of individual photons, that we know perfectly how to detect using photomultipliers. Suppose that the experiment detects $N$ photons. When $N\\rightarrow +\\infty$, we must fall back on the results of wave optics (see section of the same name).\n\t\n\tLet us perform by example the following experience:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/photon_polarization_experiment.jpg}\n\t\t\\caption{Thought experiment for polarization measurement}\n\t\\end{figure}\n\tA birefringent plate separates a light beam whose polarization is makes an angle $\\theta$ with O$x$ in a subsequent beam polarized  following O$x$ and another polarized following O$y$, the intensities being respectively $I\\cos^2(\\theta)$ and $I\\sin^2(\\theta)$ (according to the proof of Malus Law made in the section of Wave Optics).\n\t\n\tLet us reduce the intensity so that the photons arrive one by one, and let us place two photodetectors $D_x,D_y$ behind the blade. The experiment shows that $D_x,D_y$ never click together at the same time (except in cases of \"dark count\" when a counter is triggered spontaneously because of background noise): a photon comes entirely either on $D_x$, either ön $D_y$, a photon therefore can not divide itself. On the other hand, the experiment shows that the probability $P_x$ (respectively $P_y$) of detecting a photon by $D_x$ (respectively $D_y$) is equal to $\\cos^2(\\theta)$ (respectively $\\sin^2(\\theta)$). So if the experiment detects $N$ photons, we will have $N_x$ (respectively $N_y$) photons detected by $D_x$ (respectively $D_y$):\n\t\n\twhere the $\\cong$ takes int account the statistical fluctuations. As the light intensity is proportional to the number of photons, we fall indeed back on the Malus law the limit $N\\rightarrow +\\infty$.\n\t\n\tHowever, we notice two problems:\n\t\\begin{enumerate}\n\t\t\\item Can we predict, for a given photon, it will trigger $D_x$ or $D_y$? The answer of quantum theory is: NO, statement has deeply shocked Albert Einstein (God does not play dice!). Some physicists (including Albert Einstein) have been tempted to assume that quantum theory was incomplete, and that there were \"hidden variables\" whose knowledge would provide the individual destiny of each photon. Under very reasonable assumptions on which we will come back, we now know that such hidden variables are excluded. The probabilities of quantum theory are, as we know (\\SeeChapter{see section Wave Quantum Physics}), intrinsic! They are not related to an imperfect knowledge of the physical situation, as is the case for example in the game of heads or tails.\n\n\t\t\\item If we combine the two beams of the first birefringent plate, using a second blade that is symmetrical to the first:\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics{img/computing/photon_polarization_experiment_recombining_photons.jpg}\n\t\t\t\\caption[]{Imaginary experience recombining the two beams}\n\t\t\\end{figure}\n\t\tand if we seek the probability that a photon passes through the analyzer, a photon can choose the path $x$ with a probability $\\cos(\\theta)^2$, then it has a probability $\\cos^2(\\alpha)$ to cross the analyzer thus a total probability of $\\cos^2(\\theta)\\cos^2(\\alpha)$. If it chooses the path $y$, they will have a probability $\\sin^2(\\theta)\\sin^2(\\alpha)$ to cross the analyzer. The total probability is thus obtained by summing the probabilities of the two possible options:\n\t\t\n\t\tThis result is FALSE! Indeed, classical optics tells us that the intensity $I\\cos^2(\\theta-\\alpha)$ (\\SeeChapter{see section Wave Optics}) and the correct result is confirmed by experience:\n\t\t\n\t\tWhich is not the same at all!\n\t\t\n\t\tIn fact, to fall back on the results of optics wave, it must be remembered that the probability in quantum physics is obtained through the norm to the square of the probability amplitude (\\SeeChapter{see section Wave Quantum Physics}). Therefore:\n\t\t\n\t\tand we must add the amplitudes for indistinguishable paths and using basic trigonometric relations, we get:\n\t\t\n\t\twhich gives well:\n\t\t\n\t\\end{enumerate}\n\tSuppose we have a way of knowing whether the photon takes the path $x$ or the path $y$ (impossible in our case, but analogue experiments answering to the question \"What path?\" were realized with atoms). We could then divide the photons into two classes, those who \"chose\" the path $x$ and those who \"chose\" the path $y$.\n\t\n\tFor photons having chosen the path $x$, we may block the path $y$ by a cache without changing anything, and vice versa for photons having chosen the path $y$ we could block the path $x$. Obviously, the result can then be onyle be ${P'}_\\text{tot}$. If we can discriminate between the paths, the result is not the same anymore, the paths are no longer indistinguishable. Under the experimental conditions where it is impossible in principle to distinguish between the paths, we can say either:\n\t\\begin{enumerate}\n\t\t\\item Either the photon use the both paths at once (...)\n\n\t\t\\item Or it make no sense to ask the question \"Which path?\", Since the experimental conditions do not allow to answer.\n\t\\end{enumerate}\n\tIt must be notice that if the experience allows to decide between two paths, the result is ${P'}_\\text{tot}$, even if we decide not to observe them. It is just enough that the experimental conditions allow, in principle, to distinguish between the two paths.\n\t\n\t\\subsection{Qubit}\n\tUltimately, the idea of quantum computing is therefore to connect\nquantum gates in a suitable fashion while protecting the superposition\nbetween the $N$ qubits from any external influence.\n\nWe can use the polarization of photons to transmit information, for example by an optical fiber. We decide quite arbitrarily, to assign the value of $1$ bit to a photon polarized along O$x$ and $0$ to a photon polarized along O$y$.\n\n\tTo investigate the theory, it has become traditional to imagine that the two people who exchange information are conventionally named Alice (A) and Bob (B)... Alice sends to Bob for example the following sequence of polarized photons:\n\t\n\tBob analyzes the polarization of these photons with a birefringent plate and derives the message from Alice:\n\t\n\tThis is obviously not a very efficient way to exchange messages, but it is the basis of quantum cryptography (\\SeeChapter{see section Cryptography}). However, the interesting question now is: what is the value of the bit that we can attribute for example to a photon polarized at $45^\\circ$...? According to the above results, a photon polarized at $45^\\circ$. is a linear superposition of photon polarized along O$x$ and a photon polarized along O$y$. A qubit is therefore an entity much richer than a regular bit, which cannot take in the strict sense only the values $0$ and $1$.\n\t\n\tIn a sense, a qubit can take all values between $0$ and $1$ and therefore contains an infinite amount of information! However, this optimistic statement was immediately denied when we realize that the measurement of qubit can give only the result $0$ or $1$, regardless of the chosen base. However, we can ask ourselves the question of this \"hidden information\" in the linear superposition and we will see that we can exploit it under certain conditions.\n\t\n\tTo take into account for the possibility of linear superposition, it is natural to introduce for the mathematical description of the polarization a complex vector space (cause: phasers) in two dimensions corresponding to the polarization plane as we saw it in the section of Wave Optics. We denote this vector space $\\mathcal{H}$ (we take again the notation of Hilbert spaces) and name the \"\\NewTerm{Hilbert space of polarization states}\\index{Hilbert space of polarization states}\".\n\n\tWe may well decompose the vector corresponding to linear polarizations O$x$ and O$y$ in two ket vectors equation and equation such that any polarization state (whether linear, circular, or other) may decompose according to this basis:\n\t\n\tThus, a linear polarization is described by real coefficients $\\lambda,\\mu$ but the description of a circular or elliptical polarization obviously require to use complex coefficients!\n\n\tThe probability amplitudes will correspond to a scalar product on this space. So given two vectors corresponding to two different polarizations:\n\t\n\tThe Hermitian dot product (\\SeeChapter{see section Vector Calculus}) will be:\n\t\n\tNow a linear polarization state (\\SeeChapter{see section Wave Optics}) following $\\theta$ will be given logically  by (if we restrict ourselves to the linear case so!):\n\t\n\twhere $|x\\rangle$, $|y\\rangle$ are vectors having unit norms. This is consistent with the mental representation:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics{img/computing/recall_of_field_decomposition.jpg}\n\t\t\\caption[]{Reminder of field decomposition principle}\n\t\\end{figure}\n\twhere the amplitude is normalized to the unit.\n\n\tThe probability amplitude for a polarized photon following $\\theta$ goes through an analyzer oriented following $\\alpha$ can now be written:\n\t\n\tand the probability of passing through the analyzer will always be given by the squared norm of this amplitude as we have prove it earlier above:\n\t\n\tIn general, we define probability amplitudes, where $|\\Phi\\rangle$, $|\\Psi\\rangle$ are polarization states:\n\t\n\tand the corresponding probability will be:\n\t\n\tWe are now ready to tackle the crucial issue of the measure as part of this quantum experiment. Let take again the polarizer / analyzer experiment, assuming that the analyzer is oriented along O$x$. If the polarizer is oriented along O$x$, an outgoing photon passes through the polarizer analyzer with a probability of $100\\%$; if the polarizer is oriented along O$y$, the probability is $0\\%$. The analyzer performs a (polarization) test, and the test result is $1$ or $0$. The test allow us to determine the polarization state of the photon.\n\n\tBut this is not the general case!\n\t\n\tLet us assume that the polarizer is oriented following the general direction $\\theta$ or the orthogonal direction $\\theta_{\\perp}$ (there is a rotation of $\\pi/2$). We then use the properties of the unitary trigonometric circle:\n\t\n\tand therefore if the polarizer prepares for example the photon in the state $|\\theta\\rangle$ and the analyzer is oriented along O$x$, the probability of success of the test will always be $\\cos^2(\\theta)$ whatever the type of polarization!! Let us recall that in this example, after the passing through the analyzer, the polarization state of the photon is no longer $|\\theta\\rangle$, but $|x\\rangle$. The measurement therefore changes the polarization state.\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tOf course, another way of seeing that the two vectors above are orthogonal is to make a scalar product and to see that the result is immediately equal to zero.\n\t\\end{tcolorbox}\n\tWe see a difference of principle between measurement in classical physics and measurement in quantum physics. In classical physics, the physical quantity to be measured predates the measurement: if a radar measures the speed of your car at $180$ [km$\\cdot$h$^{-1}$] on the highway, this speed pre-existed to its measure by the policeman. On the contrary, in the measurement of polarization of a photon $|\\theta\\rangle$ by an analyzer oriented along O$x$, the fact that the test gives a polarization according to O$x$ does not make it possible to conclude that the photon tested had previously its polarization following O$x$.\n\n\tSo we have a device preparing the quantum system in the state $|\\Phi\\rangle$ and a second one capable of \"preparing\" it in the state $|\\Psi\\rangle$ that we will use as an analyzer. After the test, the quantum system will therefore be in the state $|\\Psi\\rangle$, which means mathematically that we realize an orthogonal projection on $|\\Psi\\rangle$.\n\n\tLet $\\mathcal{P}_\\Psi$ this projector, then the vectorial orthogonal projection (\\SeeChapter{see section Vector Calculus}) is given by:\n\t\n\twhich consists (for recall) of a simple scalar product (scalar orthogonal projection) multiplied by the vector $|\\Psi\\rangle$. This is easily seen by judiciously placing the parentheses:\n\t\n\tand therefore:\n\t\n\tThe projection of the state vector is named, as we have already seen it (in the section of Wave Quantum Physics), in the Copenhagen interpretation of quantum physics \"state vector reduction\", or, for historical reasons, \"\\NewTerm{reduction of the wave packet}\\index{reduction of the wave packet}\". This reduction of the state vector is a convenient fiction of the Copenhagen interpretation, which avoids having to ask questions about the measurement process ...\n\n\tThe reader accustomed to Linear Algebra (see section of the same name) will have probably notice trivially that we can manipulate the notation convention of the projector as a matrix (linear mapping) such as in two simple particular cases (those of interest to us):\n\t\n\tA reader has asked us to explicit this matrix approach. Let us see how we arrive at this matrix aspect of the orthogonal projection with a particular example of two vectors in a real two-dimensional space. For this let us consider:\n\t\n\tand therefore (the procedure is the same for $y$):\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tThe matrix notation of the orthogonal projector is often presented as a definition of a mathematical tool named \"\\NewTerm{outer product}\\index{outer product}\".\n\t\\end{tcolorbox}\n\tSo finally, to get back to our previous subject, we have:\n\t\n\tand same for the other component.\n\t\n\tAs:\n\t\n\tWe then have:\n\t\n\tWe will notice that the identity operator can be written as the sum of the two projectors $\\mathcal{P}_x$,$\\mathcal{P}_y$:\n\t\n\trelation named \"\\NewTerm{closure relation}\", which can be generalized to an orthonormal basis of a Hilbert space $\\mathcal{H}$ of dimension $N$:\n\t\n\tMoreover, the projectors $\\mathcal{P}_x$,  $\\mathcal{P}_y$ commute (trivial verification):\n\t\n\tThus, the tests $|x\\rangle$, $|y\\rangle$ are compatible (whatever the direction of the measurement the result is independent). In contrast, the projectors $\\mathcal{P}_\\theta$, $\\mathcal{P}_{\\theta,\\perp}$:\n\t\n\twhich satisfy (trivial verification) to:\n\t\n\tas well as (trivial verification):\n\t\n\tDo not commute with $\\mathcal{P}_x$,$\\mathcal{P}_y$:\n\t\n\tand therefore the tests $|x\\rangle$ and $|\\theta\\rangle$ are incompatible.\n\n\tFor the next developments, it will be useful to notice that the knowledge of the probabilities of success of a $T$ test makes it possible to define an average value (expected mean):\n\t\n\tIn analogy with the context, we can read this as following: the expected mean of the test is equal to the representative value of the photon oriented according to O$x$ (corresponding arbitrarily  to the value $1$) multiplied by the probability of passing through the analyzer oriented also according to O$x$ (therefore test concluding at $100\\%$) summed with the representative value of the photon oriented according to O$y$ (corresponding arbitrarily to the value $0$) multiplied by the probability of passing through the analyzer always oriented along O$x$ (therefore $0\\%$ of the photons O$y$ will pass the O$x$ test) .\n\n\tFor example, if the test $T$ is represented by the procedure $|\\Phi\\rangle$ and we apply it to a state $|\\Phi\\rangle$ (containing as we have seen above the  representative values of the linearly or non-linearly polarized photon...) then the test corresponds to a scalar product:\n\t\n\t\n\tAnd as we have seen it in the section of Wave Quantum Quantum Physics, we know that in fact:\n\t\n\tis the mean value of an operator $M$ in the state $|\\Phi\\rangle$. Thus, to the test $T$ to which a procedure $|\\Psi\\rangle$ is associated, we can associate the projector $\\mathcal{P}_{\\Phi}$ whose mean value in the state $|\\Phi$ gives the probability of success of the test.\n\n\tThe generalization of this observation makes it possible to construct the physical properties of a quantum system. Let us give an example by returning to the case of polarization. Suppose that we construct (quite arbitrarily) a property $\\mathcal{M}$ of a photon as follows:\n\t\\begin{itemize}\n\t\t\\item $\\mathcal{M}$ is equal to $+1$ if the photon is polarized following O$x$\n\n\t\t\\item $\\mathcal{M}$ is equal to $-1$ if the photon is polarized according to O$y$\n\t\\end{itemize}\n\tWe can associate with the physical property $\\mathcal{M}$ the Hermitian operator:\n\t\n\tWhich satisfies (trivial) the relation between operator, eigenvalue and vector:\n\t\n\tThe mean value (expected mean) of $M$ then being (by definition):\n\t\n\tLet us assume the photon in the linear polarization state of angle $\\theta$, then the mean value $\\rangle M \\langle_\\theta$ in the state $|\\theta\\rangle$ is (trivial):\n\t\n\tBefore seeing, how can we construct such an operator $M$ with another object than the photon and with the same properties, let us introduce a mathematical tool generalizing the conditions and the configuration of any polarized wave:\n\t\n\t\\subsubsection{Bloch sphere}\n\tThe Bloch sphere is, as we will see, a geometrical representation of the pure states of the qubits (two-level quantum mechanical system) as points of the surface of a sphere, named after the physicist Felix Bloch\n\n\tA given number of elementary operations done in quantum computing can be carried out with this sphere under the choice of a suitable projector .\n\n\tWe will see that a state of an arbitrary qubit (vector in the complex plane) can be written:\n\t\n\twhere $\\gamma\\in\\mathbb{R}$ and $0\\le \\phi\\leq 2\\pi$, define a point on the three-dimensional Bloch sphere and where we have the two basic vectors:\n\t\n\tfor which sometimes the definition is reversed (but it does not matter as long as it forms an orthogonal basis!).\n\n\tThe qubits represented by arbitrary values $\\gamma$ (global gauge invariance according to $U(1)$ as seen in the section of Set Algebra) are all represented by the same point on the Bloch sphere because we will show that the factor has no observable effect and that we can then write without losing in generality:\n\t\n\t\n\twhich is represented as we will justify later by the figure below:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/bloch_sphere.jpg}\n\t\t\\caption{Bloch-sphere (two dimensional one)}\t\n\t\\end{figure}\n\tThe Bloch sphere is a generalization of the representation of a complex number $z$ (\\SeeChapter{see section Numbers}) with $|z|^2=1$ as point of the circle in the (Gauss-) plane.\n\n\tWe also saw in this same section that a complex number could be represented by a complex exponential such that:\n\t\n\tand if the circle were unitary:\n\t\n\tLet us notice that the constraint $|z|^2=1$ eliminates a degree of freedom.\n\n\tWe will now notice the decomposition of a state of polarization in the form:\n\t\n\tAnd this one in a more traditional form in quantum computing (logic when we see the bases ...):\n\t\n\twhere $\\alpha,\\beta\\in\\mathbb{C}$ (yes! indeed we are not anymore in the simple case of a wave linearly polarized now ...!) without forgetting the condition of normalization:\n\t\n\tWe can therefore write the qubit in the form:\n\t\n\t\\begin{tcolorbox}[title=Remark,colframe=black,arc=10pt]\n\tCaution! It is very important to have read the part dealing with the polarization of light in the section of Wave Optics to understand that it does comes from nowhere!!! With the difference that we do not work here with phasors because the solution of Schrödinger's equation of evolution involves complex exponentials as we saw in the context of the resolution of the latter for a eigen-mode of free particle.\n\t\\end{tcolorbox}\n\tAdding an overall phase factor should have no influence on the coefficients $\\alpha$, $\\beta$ because:\n\t\n\tand similarly for $|\\beta|^2$. Thus, we are free to multiply our polarized and standardized qubit:\n\t\n\tby the global phase $e^{-\\mathrm{i}\\phi_a}$ which gives:\n\t\n\tIn addition, we always have the condition of normalization $\\langle \\Psi' | \\Psi\\rangle$ to respect (impose).\n\t\n\tReturning to the Cartesian coordinates, we have:\n\t\n\tAnd the normalization constraint then gives:\n\t\n\twhat is the equation of a unit sphere in $\\mathbb{R}^2$ space with the Cartesian coordinates $(x,y,r_\\alpha)$. Hence the quantum origin of the Bloch sphere!\n\t\n\tWe know (\\SeeChapter{see section Vector Calculus}) that the cartesian coordinates are connected to the spherical coordinates by the relations:\n\t\n\ttherefore by putting $z:=r_\\alpha$ and remembering that $r=1$, we can write:\n\t\n\tWe now have only two useful parameters to know to define our point on the unit sphere (and always to the arbitrariness of phase).\n\t\n\tThe reader will notice that unlike the linearly polarized qubit, the general case above adds a complex term and that inversely by removing this additional term, we fall back on the relation of the linearly polarized wave seen at the beginning of this section. However, notice (for general culture) that if we add the same complex term to the first term, then we also have the very common following representation of the linearly polarized wave whose writing is named \"\\NewTerm{Jones vector}\\index{Jones vectors}\":\n\t\n\tBut we have not finished yet!\n\n\tLet us return to (we remove the apostrophe for the state of polarization):\n\t\n\tand notice that:\n\t\n\tand:\n\t\n\twithout forgetting that $\\phi\\in\\mathbb{R}$ and that in this case the exponential factor in front of the $|1\\rangle$ is a global phase change without influence.\n\n\tAll this suggests that $0\\le \\theta \\le \\pi/2 $ is sufficient to describe any state of polarization and hence all points of the Bloch sphere.\n\n\tOn the other hand, we can see that in the system $(r,\\theta,\\phi)$ the point of coordinates $(1,\\pi-\\theta,\\phi+\\pi)$ is the point opposite to that of coordinates $(1,\\theta,\\pi)$:\n\t\n\tWe also have (this is quite immediate but we can detail on request):\n\t\n\tand therefore opposite points on the Bloch's sphere correspond orthogonal qubits (states of polarization)!\n\n\tThus we can consider only the upper hemisphere of the Bloch sphere since the opposite points differ only from a phase factor $-1$ and are therefore equivalent in the representation of the Bloch sphere.\n\n\tThus, the relation:\n\t\n\tis sufficient to describe the whole Bloch sphere in a complex space of dimension $2$.\n\n\tBy construction, each point given by the previous relation of dimension $2$ contains a double representation of a rotation in the real space of dimension $3$.\n\n\tWe have also seen in the chapter of Spinor Calculus that a rotation could be written in the form:\n\t\n\tWith for recall the Pauli Matrices (\\SeeChapter{see section Relativistic Quantum Physics}):\n\t\n\tEither with the usual (traditional) writing of the field of Quantum Computing:\n\t\n\tEither after simplifying the last matrix:\n\t\n\tNow let us consider the rotation of our polarization state vector (due to a projector):\n\t\n\tTo get a coefficient of $|0\\rangle$ that is real (in order to have an observable in the projection of an axis), we multiply by a phase factor $e^{\\mathrm{i}\\alpha/2}$ giving:\n\t\n\tSo to get a rotation around the $z$-axis it enough to change $\\phi\\rightarrow \\phi+\\alpha$.\n\n\tSo if we come back to:\n\t\n\tit can be shown in the same way that in a general framework a unitary qubit operator can be written in the observable form:\n\t\n\tIt is then necessary to choose the angles and the axis of rotation to define the operator completely.\n\t\n\t\\paragraph{Qubit of polarization}\\mbox{}\\\\\\\\\n\tWe will come back here on the case of polarization of the photon but this time we will be able to generalize thanks to the formulation of the Bloch's sphere to any type of polarization.\n\n\tLet us consider for this a polarizer that only passes photons polarized vertically followed by a photodetector, which do a \"click\" if a photon is detected and nothing else. This device allows us to detect vertically polarized photons.\n\n\tLet us translate this in the language of quantum mechanics: The states of the system are therefore the states of polarization of a photon. The measurements of the observable will also have its states of polarization.\n\n\tThe possible measures are:\n\t\n\tWe will denote the corresponding states $|x\\rangle$, $|y\\rangle$. In our configuration, it is then obvious that the couple $(\\lambda_0,\\lambda_1)$ represents the eigenvalues and $|x\\rangle$, $|y\\rangle$ the eigenvectors of an operator (which we do not know for know) and that we will therefore denote $\\mathcal{P}$.\n\n\tAs we know, $|x\\rangle$, $|y\\rangle$ is an orthonormal basis of the space of states (of polarization). This is the base named \"H/V base\" for \"Horizontal/Vertical\" and is denoted normally:\n\t\n\tLet us now take several cases:\n\t\\begin{enumerate}\n\t\t\\item Given a photon in the sate:\n\t\t\n\t\tthen:\n\t\t\n\t\n\t\t\\item Let a photon be in the semi-vertical / horizontal state, that is to say oblique (which can be assimilated to the quantum superposition of its two polarizations):\n\t\t\n\t\twhere the root is just there to ensure the normalization condition:  $\\langle \\Psi|\\Psi\\rangle=1$. Indeed:\n\t\t\n\t\tThen since there is superposition (ie half of each in the total wave):\n\t\t\n\t\t\n\t\t\\item Let us now take any polarization (and this is what we did not have before!):\n\t\t\n\t\twhich is well-normalized as we know it. So:\n\t\t\n\t\tThe sum of the two probabilities giving indeed $1$!\n\t\\end{enumerate}\n\tNow, let's imagine that we turn the polarizer of $\\pi/4$. We will denote the new basis of this polarizer $|0'\\rangle$, $|1'\\rangle$ determined by a rotation of angle $\\pi/4$ with by construction:\n\t\n\twhere the first base therefore corresponds to the diagonal polarization and the second is named \"antidiagonal polarization\". It is therefore the \"\\NewTerm{D/A base}\" (Diagonal / Antidiagonal). In the form of the Jones vectors the last two relations are written:\n\t\n\tIf we imagine that we have two polarizers that follow one another. The first having the D/A base and the second the H/V base, the first will prepare the photon polarized generally in a particular state (polarization) which will be by construction be the oblique state for the base H/V. Thus our second polarizer will have only situations of the type:\n\t\n\tThus, this shows that any measure obviously disturbs the state of polarization of the photon and thus disrupts the state of the system. This last result is used in quantum cryptography!\n\n\tWe notice by the way that by using the spin operator introduced during our study of the chapter on Wave Quantum Physics we have:\n\t\n\twhich is of the same form as the following relation (relation linking eigenvector and eigenvalue) obtained in the in the section of Wave Quantum Physics:\n\t\n\tAnd that indicates indeed that the state:\n\t\n\tseems to be necessarily associated with a $1/2$ spin particle. We also notice that this state is an eigenvector of the operator $S_x$ associated with the eigenvalue $\\hbar/2$. Indeed:\n\t\n\tSince in the present case with the operator $S_x$ we have immediately the eigenvalue and the associated eigenvector without making any intermediate calculations, it comes that the probability of measuring this eigenvalue (refer for recall to the 4th postulate of Wave Quantum Physics which associates operator to a measurement through the eigenvalue) is easy to calculate because the eigenvector is equal to the state vector in this particular case. Therefore:\n\t\n\t\n\t\\paragraph{$1/2$ spin Qubit}\\mbox{}\\\\\\\\\n\tWe will see here how to build a qubit based on a particle with a $1/2$ spin.\n\n\tIn the study of the Bloch sphere, we have examined a qubit at a given instant and we have seen that in a Hilbert space $H$, this qubit is described (by choice) by a unit vector:\n\t\n\tdecomposed into an orthonormal basis $(|0\\rangle, |1\\rangle)$.\n\n\tLet us consider the most general and minimum initial state corresponding to an arbitrary orientation of a spin:\n\t\n\tWhich corresponds, as we know, to two opposite (and superposed) states on the Bloch sphere.\n\t\n\tLet us notice that we have indeed a normalized probability of the form:\n\t\n\tWe have also seen that the projection along $z$ by the operator $R_z(\\alpha)$ of the state $\\Psi$ is given to the phase arbitrariness by:\n\t\n\tNow let u recall our example:\n\t\n\twhere $M$ was a Hermitian operator. Now the Pauli matrices are simple Hermitian operators. Moreover, as we have demonstrated in the section of Spinor Calculus, the Hermitian operator $\\sigma_z$ (assimilated to $M$) has by chance the same eigenvalues and eigenvectors corresponding to the two relations above. But it is then written in a traditional way as we saw it in the section of Spinor Calculus:\n\t\n\tor even more condensed:\n\t\n\tMoreover, this operator also satisfies the relation:\n\t\n\tAnd what is the physical property associated with $\\sigma_z$? Well this is the spin (!) and we will come back to it a bit further below because that means we can use the spin $1/2$ as a qubit.\n\n\tNow let us introduce the evolution of the system on this projection because it is not static (but this would not change this particular case to consider it static).\n\n\tWe have seen in the section of Wave Quantum Physics that this operation consisted in a simple case (as here) of introducing a phase term dependent on time of the type:\n\t\n\tTherefore:\n\t\n\tWhat is written more soberly:\n\t\n\tLet us recall that the state of a $1/2$ spin particle is two-dimensional and described by the state matrix (\\SeeChapter{see section Relativistic Quantum Physics}):\n\t\n\twith:\n\t\n\tIf we want to calculate the expected mean of the observable (physical property) along each axis, then we use the $5$th postulate in the case of the $x$-axis:\n\t\n\tFollow the $y$-axis:\n\t\n\tand finally following the $z$-axis:\n\t\n\tFor thus fall back well for the component $z$ (because it is the only one that interests us here), the result which was imposed above in the form:\n\t\n\twith an angle difference which is a matter of substitution and an amplitude which makes it possible to match the particularity of the configuration of the system. We therefore have mathematical relations similar in all respects to the manipulation of qubits of oriented spins or qubits of polarized photons.\n\n\tThe question we can ask ourselves about the spin is how to prepare it in the state $|\\Psi\\rangle$ In fact, we can do this with a magnetic field by copying the Stern-Gerlach experiment, which allows us to separate a beam of spin $1/2$ particles into two distinct beam.\n\n\tSince we now know all the eigenvalues and eigenvectors of the spin operator $S$, we can then determine the general form of the spin operator in any orientation (!):\n\t\n\tWe have also:\n\t\n\tWe have the chosen $|\\Psi\\rangle$ which is, in addition to being a state vector, an eigenvector of $S_n$ with the eigenvalue $\\hbar/2$. Therefore the probability of measuring this particular state vector is equal to $1$.\n\n\tNow we know by using the $5$th postulate that the probability of finding the eigenvalue $\\hbar/2$(of the operator $S_n$), in a measurement of the property $S$ along the $z$-axis performed at time $t$ on the quantum system prepared in the state $\\Psi$, is given by the square of the module of the projection of the function or state vector $\\Psi$ on the vector or eigenvector $\\varphi$ associated with the eigenvalue $\\hbar/2$ (and its operator along this axis).\n\n\tBut the operator according to $z$ is:\n\t\n\tFor the same operator, we have seen in the section of Spinor Calculus that it had as eigenvectors:\n\t\n\tLet us take the first eigenvector oriented according to $z$-axis on the Bloch sphere. We have then:\n\t\n\tAnd the probability according to the other eigenvector would give the same expression but with a sinus. The sum of the two probabilities would then give us well $1$!\n\n\tWe thus notice that the relations are very similar between the photon and the spin in our case of study. This is normal since both are two-level systems, resulting in similar results.\n\t\n\t\\subsection{Quantum logic gates}\n\tIn quantum computing and specifically the quantum circuit model of computation, a quantum gate (or quantum logic gate) is a basic quantum circuit operating on a small number of qubits. They are the building blocks of quantum circuits, like classical logic gates are for conventional digital circuits.\n\t\n\tLet us recall that we have stated above that the construction of a quantum qubit was done on the vector basis:\n\t\n\to in extenso, by linearity (and this is all elementary trick!), any transformation that acts on these basic vectors, will therefore act on all qubit of the complex plane.\n\n\tLet us consider the particular case for this introduction the logic gate which modifies the state of the $1$-qubit, that is to say qubit which are collinear to one of the basis vectors, into the opposite state. That is to say:\n\t\n\tWe quickly guess that the matrix that satisfies this relation (caution! the reader will notice that it is not a special case of the rotation matrix in the plane as seen in the section of Eucidian Geometry!):\n\t\n\tAnd which is sometimes written by specialists:\n\t\n\tAnd we see that this logical gate of negation of the $1$-qubit is nothing else than the first matrix of Pauli. So we can also write:\n\t\n\tNegation which is sometimes named \"\\NewTerm{$X$-Pauli quantum gate}\" or \"\\NewTerm{NOT quatum gate}\\index{NOT quantum gate}\" and represented by the following symbol in \"\\NewTerm{quantum circuits}\\index{quantum circuits}\":\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/quantum_gate_not.jpg}\t\n\t\t\\caption{NOT Quantum gate}\n\t\\end{figure}\n\tNow let us look for the logic gate making the following orthogonal clockwise transformation:\n\t\n\tWe guess quite quick that the matrix which satisfies this relation (caution! the reader will notice that this time is a special case of the rotation matrix in the plane as seen in the section of Eucidian Geometry!):\n\t\n\tAnd which is sometimes written by specialists (in a somewhat unfortunate way):\n\t\n\t\n\tAnd we see that this logical transformation gate in the clockwise direction of the $1$-qubit involves the second Pauli matrix. So we can also write:\n\t\n\tNegation which is sometimes named \"\\NewTerm{$Y$-Pauli quantum gate}\\index{$Y$-Pauli gate}\" and which has no classical equivalent.\n\t\n\tNow let us seek for the logical gate making the following strictly counterclockwise orthogonal transformation:\n\t\n\tWe guess quite quick that the matrix that satisfies this relation (caution! the reader will notice that it is not a special case of the rotation matrix in the plane seen in the section of Euclidian Geometry!):\n\t\n\tAnd which is sometimes written by specialists (in a somewhat unfortunate way):\n\t\n\tAnd we see that this logical transformation gate in the clockwise direction of $1$-qubit involves the second Pauli matrix. So we can also write:\n\t\n\tNegation then we sometimes name \"\\NewTerm{$Z$-Pauli quantum gate}\\index{$Z$-Pauli quantum gate}\".\n\t\n\tWhen describing a quantum gate on an individual qubit, any dynamical operation, $G$, is a member of the unitary group $\\text{U}(2)$ (\\SeeChapter{Set Algebra}), which consists of all $2\\times 2$ matrices where $G^\\dagger=G^{-1}$. Up to a global (and unphysical) phase factor, any single qubit operation can be expressed as a linear combination of the generator of $\\text{SU}(2)$ that are the Pauli matrices!\n\t\n\tNow let us return to the following transformation which we have dealt with earlier:\n\t\n\tIn other words, it is the transformation (diagonal for recall):\n\t\n\tWe quickly notice that the corresponding matrix is then:\n\t\n\twhich is named \"\\NewTerm{Hadamard quantum gate}\\index{Hadamard quantum gate}\" and thus corresponds to an counterclockwise rotation of $\\pi/4$. This gate is represented by the following symbol in quantum circuits:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[scale=1]{img/computing/quantum_gate_hadamard.jpg}\t\n\t\t\\caption{Hadamard Quantum gate}\n\t\\end{figure}\n\tAnd we can continue like this for a long time to create empirical quantum logic gates ... so we will stop here.\n\n\n\t\\begin{flushright}\n\t\\begin{tabular}{l c}\n\t\\circled{60} & \\pbox{20cm}{\\score{2}{5} \\\\ {\\tiny 22 votes,  53.64\\%}} \n\t\\end{tabular} \n\t\\end{flushright}", "meta": {"hexsha": "e4115ecc5fb394d859470d6f87d881aad0af4486", "size": 779218, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter_Computing.tex", "max_stars_repo_name": "lefevred/Opera_Magistris_Francais_v3", "max_stars_repo_head_hexsha": "71a881b8dfdf0ac566c59442244e6ed5f9a2c413", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapter_Computing.tex", "max_issues_repo_name": "lefevred/Opera_Magistris_Francais_v3", "max_issues_repo_head_hexsha": "71a881b8dfdf0ac566c59442244e6ed5f9a2c413", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter_Computing.tex", "max_forks_repo_name": "lefevred/Opera_Magistris_Francais_v3", "max_forks_repo_head_hexsha": "71a881b8dfdf0ac566c59442244e6ed5f9a2c413", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.5047720988, "max_line_length": 1338, "alphanum_fraction": 0.7565957152, "num_tokens": 202156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117898012105, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7075422335127218}}
{"text": "\n\\subsection{Even and odd functions}\n\n\\subsubsection{Defining odd and even functions}\n\nAn even function is one where:\n\n\\(f(x)=f(-x)\\)\n\nAn odd function is one where:\n\n\\(f(x)=-f(-x)\\)\n\n\\subsubsection{Functions which are even and odd}\n\nIf a function is even and odd:\n\n\\(f(x)=f(-x)=-f(-x)\\)\n\n\\(f(x)=-f(x)\\)\n\nThen \\(f(x)=0\\).\n\\subsubsection{Scaling odd and even functions}\n\nScaling an even function provides an even function.\n\n\\(h(x)=c.f(x)\\)\n\n\\(h(-x)=c.f(-x)\\)\n\n\\(h(-x)=c.f(x)\\)\n\n\\(h(-x)=h(x)\\)\n\nScaling an odd function provides an odd function.\n\n\\(h(x)=c.f(x)\\)\n\n\\(-h(-x)=-c.f(-x)\\)\n\n\\(-h(-x)=c.f(x)\\)\n\n\\(-h(-x)=h(x)\\)\n\n\\subsubsection{Adding odd and even functions}\n\nNote than \\(2\\) even functions added together makes an even function.\n\n\\(h(x)=f(x)+g(x)\\)\n\n\\(h(x)=f(-x)+g(-x)\\)\n\n\\(h(-x)=f(x)+g(x)\\)\n\n\\(h(x)=h(-x)\\)\n\nAnd adding \\(2\\) odd functions together makes an odd function.\n\n\\(h(x)=f(x)+g(x)\\)\n\n\\(h(x)=-f(-x)-g(-x)\\)\n\n\\(-h(-x)=f(x)+g(x)\\)\n\n\\(-h(-x)=h(x)\\)\n\n\\subsubsection{Multiplying odd and even functions}\n\nMultiplying \\(2\\) even functions together makes an even function.\n\n\\(h(x)=f(x)g(x)\\)\n\n\\(h(-x)=f(-x)g(-x)\\)\n\n\\(h(-x)=f(x)g(x)\\)\n\n\\(h(-x)=h(x)\\)\n\nMultiplying \\(2\\) odd functions together makes an even function.\n\n\\(h(x)=f(x)g(x)\\)\n\n\\(h(-x)=f(-x)g(-x)\\)\n\n\\(h(-x)=(-1).(-1.)f(x)g(x)\\)\n\n\\(h(-x)=h(x)\\)\n\n", "meta": {"hexsha": "e452207cf3dda5436da62d26228e4aa4c9f1f90f", "size": 1309, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/propertiesFunctions/01-04-analysisEvenOdd.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/propertiesFunctions/01-04-analysisEvenOdd.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/propertiesFunctions/01-04-analysisEvenOdd.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.7078651685, "max_line_length": 69, "alphanum_fraction": 0.5660809778, "num_tokens": 478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604134, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7075422286624482}}
{"text": "\\section{The Beginning}\n\\subsection{The First Law of Thermodynamics and the Stefan-Boltzmann Equation}\nThe beginning of CLAuDE is based upon one of the most important laws of physics: \"Energy is neither created nor destroyed, only changed from one form to another.\" In otherwords, if energy goes into an object it must \nequal the outflowing energy plus the change of internal energy. This is captured in Stefan-Boltzmann's law (\\autoref{eq:stefan-boltzmann}) \\cite{stefan-boltzmann}. \n\nHere we assume that the planet is a black body, i.e. it absorbs all radiation (energy waves, some waves are visible like light, others are invisible like radio signals) on all wavelengths. \nIn \\autoref{eq:stefan-boltzmann} the symbols are:\n\n\\begin{itemize}\n    \\item $S$: The energy that reaches the top of the atmosphere, coming from the sun or a similar star, per meters squared $Jm^{-2}$. This is also called the insolation.\n    \\item $\\sigma$: The Stefan-Boltzmann constant, $5.670373 \\cdot 10^-8 \\ (Wm^{-2}K^{-4})$ \\cite{stefan-boltzmann}.\n    \\item $T$: The temperature of the planet ($K$).\n\\end{itemize}\n\nTechnically speaking \\autoref{eq:stefan-boltzmann} is incorrect, as there is a mismatch in units. However, that is corrected in \\autoref{eq:basis sphere final} so there is no need to worry about \nit just yet. The energy difference between the energu that reaches the atmosphere and the temperature of the planet must be equal to the change in temperature of the planet, which is written in \n\\autoref{eq:sb rewritten}. The symbols on the right hand side are:\n\n\\begin{itemize}\n    \\item $\\Delta U$: The change of internal energy ($J$) \\cite{thermo1}.\n    \\item $C$: The specific heat capacity of the object, i.e. how much energy is required to heat the object by one degree Kelvin ($\\frac{J}{K}$).\n    \\item $\\Delta T$: The change in temperature ($K$).\n\\end{itemize}\n\nWe want to know the change of temperature $\\Delta T$, so we rewrite the equation into \\autoref{eq:sb rewritten2}. Here we added the $\\delta t$ term to account for the time difference (or time step). This is needed as\nwe need an interval to calculate the difference in temperature over. Also we needed to make the units match, and by adding this time step the units all match up perfectly.\n\n\\begin{subequations}\n    \\begin{equation}\n        S = SB = \\sigma T^4\n        \\label{eq:stefan-boltzmann}\n    \\end{equation}\n    \\begin{equation}\n        S - \\sigma T^4 = \\Delta U = C \\Delta T\n        \\label{eq:sb rewritten}\n    \\end{equation}\n    \\begin{equation}\n        \\Delta T = \\frac{\\delta t(S - \\sigma T^4)}{C}\n        \\label{eq:sb rewritten2}\n    \\end{equation}\n    \\label{eq:basis}\n\\end{subequations}\n\nThe set of equations in \\autoref{eq:basis} form the basis of the temperature exchange of the planet. However two crucial aspects are missing. Only half of the planet will be receiving light from \nthe sun at once, and the planet is a sphere. So we need to account for both in our equation. We do that in \\autoref{eq:basis sphere correction}. We view the energy reacing the atmosphere as a \ncircular area of energy, with the equation for the are of a circle being \\autoref{eq:basis circle} \\cite{areaCircle}. The area of a sphere is in \\autoref{eq:basis sphere} \\cite{areaSphere}. In \nboth equations, $r$ is the radius of the circle/sphere. By using \\autoref{eq:basis circle} and \\autoref{eq:basis sphere} in \\autoref{eq:sb rewritten2} we get \\autoref{eq:basis sphere2} where \n$r$ is replaced by $R$. It is common in physics literature to use capitals for large objects like planets. However we are not done yet since we can divide some stuff out. We end up with \n\\autoref{eq:basis sphere final} as the final equation we are going to use.\n\n\\begin{subequations}\n    \\begin{equation}\n        \\pi r^2\n        \\label{eq:basis circle}\n    \\end{equation}\n    \\begin{equation}\n        4 \\pi r^2\n        \\label{eq:basis sphere}\n    \\end{equation}\n    \\begin{equation}\n        \\Delta T = \\frac{\\delta t (\\pi R^2S - 4\\pi R^2\\sigma T^4)}{4\\pi CR^2}\n        \\label{eq:basis sphere2}\n    \\end{equation}\n    \\begin{equation}\n        \\Delta T = \\frac{\\delta t (S - 4\\sigma T^4)}{4C}\n        \\label{eq:basis sphere final}\n    \\end{equation}\n    \\label{eq:basis sphere correction}\n\\end{subequations}\n\n\\subsection{Insolation}\n\nWith the current equation we calculate the global average surface temperature of the planet itself. However, this planet does not have an atmosphere just yet. Basically we modelled the \ntemperature of a rock floating in space, let's change that with \\autoref{eq:atmos}. Here we assume that the area of the atmosphere is equal to the area of the planet surface. Obviously\nthis assumption is false, as the atmosphere is a sphere that is larger in radius than the planet, however the difference is not significant enough to account for it. We also define the\natmosphere as a single layer. This is due to the accessibility of the model, we want to make it accessible, not university simulation grade. One thing to take into account for the \natmosphere is that it only partially absorbs energy. The sun (or a similar star) is relatively hot and sends out energy waves (radiation) with relatively low wavelengths. The planet is \nrelatively cold and sends out energy at long wavelengths. As a side note, all objects radiate energy. You can verify this by leaving something in the sun on a hot day for a while and \nalmost touch it later. You can feel the heat radiating from the object. The planet is no exception and radiates heat as well, though at a different wavelength than the sun. The \natmosphere absorbs longer wavelengths better than short wavelengths. For simplicity's sake we say that all of the sun's energy does not get absorbed by the atmosphere. The planet's \nradiation will be absorbed partially by the atmosphere. Some of the energy that the atmosphere absorbs is radiated into space and some of that energy is radiated back onto the planet's \nsurface. We need to adjust \\autoref{eq:basis sphere final} to account for the energy being radiated from the atmosphere back at the planet surface.\n\nSo let us denote the temperature of the planet surface as $T_p$ and the temperature of the atmosphere as $T_a$. Let us also write the specific heat capacity of the planet surface as $C_p$ \ninstead of $C$. We add the term in \\autoref{eq:atmos on surface improved} to \\autoref{eq:basis sphere final} in \\autoref{eq:surface change}. In \\autoref{eq:atmos on surface}, $\\epsilon$ is the \nabsorbtivity of the atmosphere, the fraction of energy that the atmosphere absorbs. We divided \\autoref{eq:atmos on surface} by $\\pi R^2$ as we did that with \\autoref{eq:basis sphere final} as \nwell, so we needed to make it match that division.\n\n\\begin{subequations}\n    \\begin{equation}\n        4\\pi R^2 \\epsilon \\sigma T_a^4\n        \\label{eq:atmos on surface}\n    \\end{equation}\n    \\begin{equation}\n        4\\epsilon \\sigma T_a^4\n        \\label{eq:atmos on surface improved}\n    \\end{equation}\n    \\begin{equation}\n        \\Delta T_p = \\frac{\\delta t (S + 4\\epsilon \\sigma T_a^4 - 4\\sigma T_p^4)}{4C_p}\n        \\label{eq:surface change}\n    \\end{equation}\n    \\label{eq:atmos}\n\\end{subequations}\n\nAs you probably expected, the atmosphere can change in temperature as well. This is modelled by \\autoref{eq:atmos change}, which is very similar to \\autoref{eq:surface change}. There are\nsome key differences though. Instead of subtracting the radiated heat of the atmosphere once we do it twice. This is because the atmosphere radiates heat into space and towards the \nsurface of the planet, which are two outgoing streams of energy instead of one for the planet (as the planet obviously cannot radiate energy anywhere else than into the atmosphere).\n$C_a$ is the specific heat capacity of the atmosphere.\n\n\\begin{equation}\n    \\Delta T_a = \\frac{\\delta t (\\sigma T_p^4 - 2\\epsilon\\sigma T_a^4)}{C_a}\n    \\label{eq:atmos change}\n\\end{equation}\n\n\\subsection{The Latitude Longitude Grid}\nWith the current model, we only calculate the global average temperature. To calculate the temperature change along the surface and atmosphere at different points, we are going to use a grid.\nFortunately the world has already defined such a grid for us, the latitude longitude grid \\cite{latlong}. The latitude is the coordinate running from the south pole to the north pole, with -90 \nbeing the south pole and 90 being the north pole. The longitude runs parallel to the equator and runs from 0 to 360 which is the amount of degrees that an angle can take when calculating the \nangle of a circle. So 0 degrees longitude is the same place as 360 degrees longitude. To do this however we need to move on from mathematical formulae to code (or in this case pseudocode).\n\nPseudocode is a representation of real code. It is meant to be an abstraction of code such that it does not matter how you present it, but every coder should be able to read it and implement \nit in their language of preference. This is usually easier to read than normal code, but more difficult to read than mathematical formulae. If you are unfamiliar with code or coding, look up \na tutorial online as there are numerous great ones.\n\nThe pseudocode in \\autoref{alg:stream1v1} defines the main loop of the model. All values are initialised beforehand, based on either estimations, trial and error or because they are what they \nare (like the Stefan-Boltzmann constant $\\sigma$). The total time $t$ starts at 0 and increases by $\\delta t$ after every update of the temperature. This is to account for the total time that \nthe model has simulated (and it is also used later). What you may notice is the $T_p[lan, lon]$ notation. This is to indicate that $T_p$ saves a value for each $lan$ and $lon$ combination.\nIt is initialised as all zeroes for each index pair, and the values is changed based on the calculations. You can view $T_p$ like the whole latitude longitude grid, where $T_p[lat, lon]$ is an \nindividual cell of that grid indexed by a specific latitude longitude combination.\n\n\\begin{algorithm}[hbt]\n    \\SetAlgoLined\n    $\\delta t \\leftarrow 60 \\cdot 5$ \\;\n    $\\sigma \\leftarrow 5.67 \\cdot 10^{-8}$ \\;\n    $\\epsilon \\leftarrow 0.75$ \\;\n    $C_p \\leftarrow 10^7$ \\;\n    $C_a \\leftarrow 10^6$ \\;\n    $S \\leftarrow 1370$ \\;\n    $R \\leftarrow 6.4 \\cdot 10^6$ \\;\n    $t \\leftarrow 0$ \\;\n\n    \\While{\\texttt{TRUE}}{\n        \\For{$lat \\in [-90, 90]$}{\n            \\For{$lon \\in [0, 360]$}{\n                $T_p[lat, lon] \\leftarrow T_p[lat, lon] + \\frac{\\delta t (S + 4\\epsilon \\sigma (T_a[lat, lon])^4 - 4\\sigma (T_p[lat, lon])^4)}{C_p}$ \\;\n                $T_a[lat, lon] \\leftarrow T_a[lat, lon] + \\frac{\\delta t (\\sigma (T_p[lat, lon])^4 - 2\\epsilon\\sigma (T_a[lat, lon])^4)}{C_a}$ \\;\n                $t \\leftarrow t + \\delta t$ \\;\n            }\n        }\n    }\n    \\caption{The main loop of the temperature calculations}\n    \\label{alg:stream1v1}\n\\end{algorithm}\n\n\\subsection{Day/Night Cycle}\nAs you can see, the amount of energy that reaches the atmopsphere is constant. However this varies based on the position of the sun relative to the planet. To fix this, we have to assign a function \nto $S$ that gives the correct amount of energy that lands on that part of the planet surface. This is done in \\autoref{alg:solar}. In this algorithm the term insolation is mentioned, which is $S$\nused in the previous formulae if you recall. We use the $\\cos$ function here to map the strength of the sun to a number between $0$ and $1$. The strength is dependent on the latitude, but since \nthat is in degrees and we need it in radians we transform it to radians by multiplying it by $\\frac{\\pi}{180}$. This function assumes the sun is at the equinox (center of the sun is directly \nabove the equator) \\cite{equinox} at at all times. The second $\\cos$ is needed to simulate the longitude that the sun has moved over the longitude of the equator. For that we need the difference \nbetween the longitude of the point we want to calculate the energy for, and the longitude of the sun. The longitude of the sun is of course linked to the current time (as the sun is in a different\\\nposition at 5:00 than at 15:00). So we need to map the current time in seconds to the interval $[0,$ seconds in a day$]$. Therefore we need the mod function. The mod function works like this:\n$x$ mod $y$ means subtract all multiples of $y$ from $x$ such that $0 \\leq x < y$. So to map the current time to a time within one day, we do $t$ mod $d$ where $t$ is the current time and $d$ is \nthe amount of seconds in a day. When we did the calculation specified in \\autoref{alg:solar} we return the final value (which means that the function call is \"replaced\" \\footnote{Replaced is not \nnecessarily the right word, it is more like a mathematical function $f(x)$ where $y = f(x)$. You give it an $x$ and the value that correpsonds to that $x$ is saved in $y$. So you can view the \nfunction call in pseudocode as a value that is calculated by a different function which is then used like a regular number.} by the value that the function calculates). If the final value is less \nthan 0, we need to return 0 as the sun cannot suck energy out of the planet (that it does not radiate itself, which would happen if a negative value is returned).\n\nIn the second stream, it was revealed that $t$ mod $d$ in \\autoref{alg:solar} should be $-t$ mod $d$ such that the sun moves in the right direction. In the first stream the sun would move to the \nright (west to east), however the sun moves to the left (east to west) and so the time must be flipped in order for the model to be correct.\n\n\\begin{algorithm}[hbt]\n    \\SetAlgoLined\n    \\SetKwInput{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{insolation $ins$, latitude $lat$, longitude $lon$, time $t$, time in a day $d$}\n    \\Output{Amount of energy $S$ that hits the planet surface at the given latitude-time combination.}\n    $longitude \\leftarrow 360 \\cdot \\frac{(-t \\text{ mod } d)}{d}$ \\;\n    $S \\leftarrow ins \\cdot \\cos(lat \\frac{\\pi}{180}) \\cos((lon - longitude) \\cdot \\frac{\\pi}{180})$ \\;\n    \\eIf{$S < 0$}{\n        \\Return{$0$}\n    }{\n        \\Return{$S$}\n    }\n    \\caption{Calculating the energy from the sun (or similar star) that reaches a part of the planet surface at a given latitude and time}\n    \\label{alg:solar}\n\\end{algorithm}\n\nBy implementing \\autoref{alg:solar}, \\autoref{alg:stream1v1} must be changed as well, as $S$ is no longer constant for the whole planet surface. So let us do that in \\autoref{alg:stream1v2}. Note \nthat $S$ is defined as the call to \\autoref{alg:solar} (as is showcased by the text \\texttt{solar}). In case you are unfamiliar with calls, defining a function is defining how it works and \ncalling a function is actually using it.\n\n\\begin{algorithm}[hbt]\n    \\SetAlgoLined\n    $\\delta t \\leftarrow 60 \\cdot 5$ \\;\n    $\\sigma \\leftarrow 5.67 \\cdot 10^{-8}$ \\;\n    $\\epsilon \\leftarrow 0.75$ \\;\n    $C_p \\leftarrow 10^7$ \\;\n    $C_a \\leftarrow 10^7$ \\;\n    $I \\leftarrow 1370$ \\;\n    $R \\leftarrow 6.4 \\cdot 10^6$ \\;\n    $t \\leftarrow 0$ \\;\n    $day \\leftarrow 60 \\cdot 60 \\cdot 24$ \\;\n    $S \\leftarrow$ \\texttt{solar($I$, $lat$, $lon$, $t$, $day$)} \\;\n    $nlat$ is the amount of latitude points in the interval $[0, 90]$, how you divide them is your own choice. \\;\n    $nlot$ is the amount of longitude points in the interval $[0, 360]$, how you divide them is your own choice. \\;\n\n    \\While{\\texttt{TRUE}}{\n        \\For{$lat \\in [-nlat, nlat]$}{\n            \\For{$lon \\in [0, nlot]$}{\n                $T_p[lat, lon] \\leftarrow T_p[lat, lon] + \\frac{\\delta t (S + 4\\epsilon \\sigma (T_a[lat, lon])^4 - 4\\sigma (T_p[lat, lon])^4)}{C_p}$ \\;\n                $T_a[lat, lon] \\leftarrow T_a[lat, lon] + \\frac{\\delta t (\\sigma (T_p[lat, lon])^4 - 2\\epsilon\\sigma (T_a[lat, lon])^4)}{C_a}$ \\;\n                $t \\leftarrow t + \\delta t$ \\;\n            }\n        }\n    }\n    \\caption{The main loop of the temperature calculations}\n    \\label{alg:stream1v2}\n\\end{algorithm}\n\n\\autoref{alg:stream1v2} calculates the values that are plotted (which is not discussed here as that is Python specific). Due to the \\texttt{WHILE(TRUE)} loop, this calculation never finishes and\nallows us to simulate days, weeks, months and even years of heat exchange all conveniently plotted in a graph. In Simon's implementation, the graphs update in realtime, meaning that whenever a \nround of calculations has finished, they are immediately processed to be displayed in the graph. \n\nHowever other forms of looking at the calculated data can be implemented, like writing a table to a txt file, saving the generated grpahs at a certain interval or spewing all the data into a csv \ndataset. The possibilities are endless, and the whole goal of the model is for it to be modular. Meaning that if you want to do something with it (like have a multi-layered atmosphere instead of \na single layer atmosphere) you can just write some lines of code and run the model and it should still work. Therefore you can write your own extensions of the model to fit it to your needs and \nrequirements.", "meta": {"hexsha": "e0d1a2aeff6ca2a81673415a580feea0ac619791", "size": 17044, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex-docs/streams/Stream1.tex", "max_stars_repo_name": "balintf/claude", "max_stars_repo_head_hexsha": "a3ebf0605ca26c4aadd0273f6b70813bdf931c9c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex-docs/streams/Stream1.tex", "max_issues_repo_name": "balintf/claude", "max_issues_repo_head_hexsha": "a3ebf0605ca26c4aadd0273f6b70813bdf931c9c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex-docs/streams/Stream1.tex", "max_forks_repo_name": "balintf/claude", "max_forks_repo_head_hexsha": "a3ebf0605ca26c4aadd0273f6b70813bdf931c9c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 74.7543859649, "max_line_length": 216, "alphanum_fraction": 0.7215442384, "num_tokens": 4625, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.7075422237795356}}
{"text": "\\documentclass[oneside]{tufte-handout}\n\\usepackage{amsmath}\n\n\\newcommand\\code[1]{\\texttt{#1}}\n\n\\title{STL Quadratic Interpolation \\\\ Implementation Notes}\n\n\\author{James A. Crotinger \\\\ email: \\href{mailto:jim.crotinger@servicenow.com}{\\tt jim.crotinger@servicenow.com}}\n\n\\begin{document}\n\n\\maketitle%\n\n\\section{Implementation}\n\n\\begin{fullwidth}\nThe algorithm used by \\code{stl-decomp-4j} assumes that the input data is regularly spaced with no missing values,\nallowing for a very efficient implementation of the underlying Loess smoother. Part of this formulation is explained here in order to extend the formulation to quadratic interpolation. \n\n\\section{Local Linear Interpolation}\n\nThe local (weighted) linear interpolation in \\code{LinearLoessInterpolator} is a straight port of the code in the original Ratfor function \\code{stl.r:est}. The input data is a sequence of data points $\\{x_i, y_i\\}$, where the $x_i$ are the regularly spaced grid points. The Loess interpolation of the data set at an arbitrary point $x$ can be expressed as\n\\begin{equation}\\label{eq:interp-def}\n  y(x) = \\sum_{i = 1}^m \\hat{w}_i(x) y_i\n\\end{equation}\ni.e. the interpolation can be re-cast as a linear operation on the input y-values. The weights $\\hat{w}_i(x)$ depend only on the original weights, $w_i$, and on geometric factors.\n\nFor linear interpolation, we desire coefficients $\\alpha$ and $\\beta$ such that the line\n\\begin{equation}\\label{eq:linear}\n\ty(x) = \\alpha + \\beta x\n\\end{equation}\nis the best fit to our set of points. The square error from a weighted least-squares fit of this curve to the training data is\n\\begin{equation}\\label{eq:mean-square-error}\nE = {\\frac{1}{2}} \\sum_{i=1}^m (y_i - \\alpha - \\beta x_i)^2 \\cdot w_i\n\\end{equation}\nwhere $\\sum w_i = 1$ are external weights (in Loess these come from the implementation of the locality window).\n\n\\subsection{Finding $\\alpha$}\n\nThe optimal choices of $\\alpha$ and $\\beta$ are found by differentiating Eq. (\\ref{eq:mean-square-error}) with respect to each of these, setting to zero and solving:\n\\begin{equation}\n\\frac{\\partial E}{\\partial \\alpha} = - \\sum_{i=1}^m w_i (y_i - \\alpha - \\beta x_i) = 0\n\\end{equation}\nThen\n\\begin{equation}\\label{eq:alpha1}\n\\sum w_i y_i - \\alpha \\sum w_i - \\beta \\sum w_i x_i = 0\n\\end{equation}\nFor a given sequence ${z_i}$ we define\n\\begin{equation}\\label{eq:avg-def}\n\t\\langle z \\rangle \\equiv \\sum_i w_i z_i\n\\end{equation}\nThen we can rewrite the Eq. (\\ref{eq:alpha1}) as\n\\begin{equation}\\label{eq:alpha}\n\\alpha = \\langle y \\rangle - \\beta \\langle x \\rangle\n\\end{equation}\n\n\\subsection{Finding $\\beta$}\n\nRepeating this exercise for $\\beta$, skipping the intermediate details, gives\n\\begin{equation}\\label{eq:beta}\n\\beta = \\frac{\\langle x y \\rangle - \\langle x \\rangle \\langle y \\rangle}{\\langle x^2 \\rangle - \\langle x \\rangle^2}\n\\end{equation}\n\n\\subsection{The Weight}\n\nGiven Eqs. (\\ref{eq:alpha}) and (\\ref{eq:beta}),  Eq. (\\ref{eq:linear}) becomes\n\\begin{align}\ny(x) &= \\alpha + \\beta x \\\\\n       &= \\langle y \\rangle + \\beta ( x - \\langle x \\rangle) \\\\\n       &= \\langle y \\rangle + \\frac{\\langle x y \\rangle - \\langle x \\rangle \\langle y \\rangle}{\\langle x^2 \\rangle - \\langle x \\rangle^2} (x - \\langle x \\rangle)\n\\end{align}\nWriting out the averages that involve $y$, we have:\n\\begin{align}\ny(x) &= \\sum_j w_j y_j + \\sum_j \\frac{x - \\langle x \\rangle}{\\langle x^2 \\rangle - \\langle x \\rangle^2} w_j (x_j - \\langle x \\rangle)y_j  \\\\\n       &= \\sum_j w_j \\left[1 + \\frac{x - \\langle x \\rangle}{\\langle x^2 \\rangle - \\langle x \\rangle^2}(x_j - \\langle x \\rangle) \\right] y_j \\\\\n       &= \\sum_j \\hat{w}_j(x) y_j\n\\end{align}\nwhere:\n\\begin{equation}\\label{eq:linear-weight}\n\\hat{w}_j(x) \\equiv w_j\\left[ 1 + \\frac{(x - \\langle x \\rangle)(x_j - \\langle x \\rangle)}{\\langle x^2 \\rangle - \\langle x \\rangle^2} \\right]\n\\end{equation}\n\nSo, given the point $x$ at which we want to perform the interpolation (or extrapolation - $x$ is not limited to being in the range of the set of grid points, $\\{x_i\\}$), we just calculate a geometric adjustment to the original weights, $w_i$. These various averages can be computed efficiently since the weights $w_i$ are non-zero only in the Loess window near the point $x$.\n\n\\section{Local Quadratic Interpolation}\nAs before, given data points $\\{x_i, y_i\\}, i = 1, ..., m$, and externally supplied weights $w_i, \\sum_i w_i = 1$, we want to find a set of modified weights $\\hat{w}_i$ such that the interpolation at a value $x$ can be written as\n\\begin{equation}\ny(x) = \\sum_{i=1}^m \\hat{w}_i(x) y_i\n\\end{equation}\nNow we model the data as a local quadratic:\n\\begin{equation}\\label{eq:quadratic}\ny(x) = a_0 + a_1 x + a_2 x^2\n\\end{equation}\n\n\\subsection{Finding $a_0$}\nThe square error in the local interpolation of the training data is:\n\\begin{equation}\\label{eq:quad-error}\nE = \\frac{1}{2} \\sum_i w_i (y_i - a_0 - a_1 x_i - a_2 x_i^2)\n\\end{equation}\nMinimizing with respect to $a_0$,\n\\begin{equation}\n\\frac{\\partial E}{\\partial a_0} = - \\sum_i w_i (y_i - a_0 - a_1 x_i - a_2 x_i^2) = 0\n\\end{equation}\nThis yields the obvious extension of the linear result:\n\\begin{equation}\\label{eq:a0}\na_0 = \\langle y \\rangle - a_1 \\langle x \\rangle - a_2 \\langle x^2 \\rangle\n\\end{equation}\nwhere the averages $\\langle \\cdot \\rangle$ are defined as before.\n\n\\subsection{Finding $a_1$}\nSimilarly, for $a_1$ we have\n\\begin{align}\n\\frac{\\partial E}{\\partial a_1} &= - \\sum_i w_i x_i (y_i - a_0 - a_1 x_i - a_2 x_i^2) = 0 \\\\\n                                &= - \\langle x y \\rangle + a_0 \\langle x \\rangle + a_1 \\langle x^2 \\rangle + a_2 \\langle x^3 \\rangle = 0\n\\end{align}\nSolving for $\\langle x y \\rangle$ and substituting $a_0$ from Eq. (\\ref{eq:a0}):\n\\begin{align}\n\\langle x y \\rangle &= \\left[\\langle y \\rangle - a_1 \\langle x \\rangle - a_2 \\langle x^2 \\rangle \\right] \\langle x \\rangle + a_1 \\langle x^2 \\rangle + a_2 \\langle x^3 \\rangle \\\\\n                    &= \\langle x \\rangle \\langle y \\rangle - a_1 \\langle x \\rangle^2 - a_2 \\langle x \\rangle \\langle x^2 \\rangle + a_1 \\langle x^2 \\rangle + a_2 \\langle x^3 \\rangle\n\\end{align}\nGathering terms\n\\begin{equation}\\label{eq:xymxy}\n\\langle x y \\rangle - \\langle x \\rangle \\langle y \\rangle = a_1 (\\langle x^2 \\rangle - \\langle x \\rangle^2) + a_2 (\\langle x^3 \\rangle - \\langle x^2 \\rangle \\langle x \\rangle)\n\\end{equation}\nWe define the following geometric factors $M_2$ and $M_3$, and a correlation factor $C_{xy}$:\n\\begin{align}\nM_2 &= \\langle x^2 \\rangle - \\langle x \\rangle^2 \\label{eq:m2} \\\\\nM_3 &= \\langle x^3 \\rangle - \\langle x^2 \\rangle \\langle x \\rangle  \\label{eq:m3} \\\\\nC_{xy} &= \\langle x y \\rangle - \\langle x \\rangle \\langle y \\rangle \\label{eq:cxy}\n\\end{align}\nThen Eq. (\\ref{eq:xymxy}) can be rewritten as\n\\begin{equation}\nC_{xy} = a_1 M_2 + a_2 M_3\n\\end{equation}\nSolving for $a_1$\n\\begin{equation}\\label{eq:a1}\na_1 = \\frac{C_{xy}}{M_2} - a_2 \\frac{M_3}{M_2}\n\\end{equation}\n\n\\subsection{Finding $a_2$}\n\nThe result of minimizing Eq. (\\ref{eq:quad-error}) with respect to $\\alpha_2$ results in an expression similar to Eq.~(\\ref{eq:xymxy}), just adding another $x$ in the appropriate averages, leading to\n\\begin{equation}\\label{eq:x2ymx2y}\n\\langle x^2 y \\rangle - \\langle x^2 \\rangle \\langle y \\rangle = a_1 (\\langle x^3 \\rangle - \\langle x^2 \\rangle \\langle x \\rangle) + a_2 (\\langle x^4 \\rangle - \\langle x^2 \\rangle^2)\n\\end{equation}\nWe define the following geometric and correlation factors:\n\\begin{align}\nM_4 &= \\langle x^4 \\rangle - \\langle x^2 \\rangle^2 \\label{eq:m4} \\\\\nC_{x^2y} &= \\langle x^2 y \\rangle - \\langle x^2 \\rangle \\langle y \\rangle \\label{eq:cx2y}\n\\end{align}\nUsing Eq. (\\ref{eq:m3}) and Eqs. (\\ref{eq:m4}-\\ref{eq:cx2y}), Eq. (\\ref{eq:x2ymx2y}) becomes\n\\begin{equation*}\nC_{x^2y} = a_1 M_3 + a_2 M_4\n\\end{equation*}\nSubstituting our expression for $a_1$ from Eq. (\\ref{eq:a1}),\n\\begin{align}\nC_{x^2y} &= \\left[\n     \\frac{C_{xy}}{M_2} - a_2 \\frac{M_3}{M_2}\n     \\right] M_3 + a_2 M_4 \\\\\n     &= \\frac{M_3}{M_2} C_{xy} + a_2 (M_4 - \\frac{M_3^2}{M_2})\n\\end{align}\nSolving for $a_2$ and simplifying\n\\begin{align}\na_2 &= \\frac{\n        C_{x^2y} - \\frac{M_3}{M_2} C_{xy}\n     }{\n        M_4 - \\frac{M_3^2}{M_2}\n     } \\\\\n     &= \\frac{\n        M_2 C_{x^2y} - M_3 C_{xy}\n     }{\n        M_2 M_4 - M_3^2\n     } \\label{eq:a2}\n\\end{align}\nSubstituting Eq. (\\ref{eq:a2}) back into Eq. (\\ref{eq:a1}) gives\n\\begin{align*}\na_1 &= \\frac{C_{xy}}{M_2} - \\frac{\n        M_2 C_{x^2y} - M_3 C_{xy}\n     }{\n        M_2 M_4 - M_3^2\n     } \\frac{M_3}{M_2} \\\\\n     &= \\frac{C_{xy}}{M_2} \n         - \\frac{M_2 C_{x^2y}}{M_2 M_4 - M_3^2} \\frac{M_3}{M_2} \n         + \\frac{M_3^2 }{M_2 M_4 - M_3^2} \\frac{C_{xy}}{M_2} \\\\\n     &= \\frac{C_{xy}}{M_2} \\frac{M_2 M_4 - M_3^2}{M_2 M_4 - M_3^2}\n         + \\frac{M_3^2 }{M_2 M_4 - M_3^2} \\frac{C_{xy}}{M_2} \n         - \\frac{M_3 C_{x^2y}}{M_2 M_4 - M_3^2}\n\\end{align*}\nSo our final expression for $a_1$ is\n\\begin{equation}\\label{eq:a1-final}\n\ta_1     =  \\frac{M_4 C_{xy} - M_3 C_{x^2y}}{M_2 M_4 - M_3^2}\n\\end{equation}\n\n\\subsection{The Weight}\nReturning to the interpolation expression, Eq. (\\ref{eq:quadratic}), we start by substituting back $a_0$:\n\\begin{align}\ny(x) &= a_0 + a_1 x + a_2 x^2 \\\\\n     &= \\langle y \\rangle - a_1 \\langle x \\rangle - a_2 \\langle x^2 \\rangle + a_1 x + a_2 x^2 \\\\\n     &= \\langle y \\rangle + a_1 (x - \\langle x \\rangle) + a_2 (x^2 - \\langle x^2 \\rangle) \\label{eq:ywa1a2}\n\\end{align}\nDefining the following geometric terms\n\\begin{align}\n\\beta_2 &= \\frac{M_4}{M_2 M_4 - M_3^2} \\\\\n\\beta_3 &= \\frac{M_3}{M_2 M_4 - M_3^2}\\\\\n\\beta_4 &= \\frac{M_2}{M_2 M_4 - M_3^2}\n\\end{align}\nWe can rewrite Eqs. (\\ref{eq:a2}) and (\\ref{eq:a1-final}) as\n\\begin{align}\na_1 &= \\beta_2 C_{xy} - \\beta_3 C_{x^2 y} \\\\\na_2 &= \\beta_4 C_{x^2y} - \\beta_3 C_{xy}\n\\end{align}\nThen Eq. (\\ref{eq:ywa1a2}) becomes\n\\begin{align}\ny(x) &= \\langle y \\rangle + (x - \\langle x \\rangle)(\\beta_2 C_{xy} - \\beta_3 C_{x^2 y}) \n       + (x^2 - \\langle x^2 \\rangle)(\\beta_4 C_{x^2y} - \\beta_3 C_{xy}) \\\\\n       &= \\langle y \\rangle  + [\\beta_2(x - \\langle x \\rangle) - \\beta_3 (x^2 - \\langle x^2 \\rangle)] C_{xy}\n       + [\\beta_4(x^2 - \\langle x^2 \\rangle) - \\beta_3 (x - \\langle x \\rangle)] C_{x^2y}\n\\end{align}\nDefining the following functions of $x$\n\\begin{align}\n\\hat{a}_1(x) &\\equiv \\beta_2(x - \\langle x \\rangle) - \\beta_3 (x^2 - \\langle x^2 \\rangle) \\\\\n\\hat{a}_2(x) &\\equiv \\beta_4(x^2 - \\langle x^2 \\rangle) - \\beta_3 (x - \\langle x \\rangle)\n\\end{align}\nwe can write, using the definitions of $C_{xy}$ and $C_{x^2y}$, Eqs. (\\ref{eq:cxy}) and (\\ref{eq:cx2y}):\n\\begin{align}\ny(x) &= \\langle y \\rangle + \\hat{a}_1(x) C_{xy} + \\hat{a}_2(x) C_{x^2y} \\\\\n     &= \\sum_i w_i y_i + \\hat{a}_1(x)  \\sum_i w_i (x_i - \\langle x \\rangle) y_i \n         + \\hat{a}_2(x) \\sum_i w_i (x_i^2 - \\langle x^2 \\rangle) y_i \\\\\n     &= \\sum_i w_i y_i \\left[1 + \\hat{a}_1(x) (x_i - \\langle x \\rangle) \n         + \\hat{a}_2(x) (x_i^2 - \\langle x^2 \\rangle)\\right]\n\\end{align}\nSo finally we arrive at our goal\n\\begin{equation}\ny(x)     = \\sum_i \\hat{w}_i(x) y_i\n\\end{equation}\nwhere\n\\begin{equation}\n    \\hat{w}_i(x) \\equiv w_i \\left[1 + \\hat{a}_1(x) (x_i - \\langle x \\rangle) \n         + \\hat{a}_2(x) (x_i^2 - \\langle x^2 \\rangle)\\right]\n\\end{equation}\nThe code in \\code{QuadraticLoessInterpolator.updateWeights} in \\code{LoessInterpolator.java} is very close to a literal transcription of the above math.\n\n\\end{fullwidth}\n\\end{document}\n", "meta": {"hexsha": "2b12fc5cdceceb3ecadaa88e4d06c71e7c84d047", "size": 11309, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "stl-decomp-4j/docs/ImplementationNotes.tex", "max_stars_repo_name": "shahgoshtasbi/stl-decomp-4j", "max_stars_repo_head_hexsha": "9e28dfcdeeae53023242890c0fca61766fb44613", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 148, "max_stars_repo_stars_event_min_datetime": "2017-04-20T01:43:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T09:17:37.000Z", "max_issues_repo_path": "stl-decomp-4j/docs/ImplementationNotes.tex", "max_issues_repo_name": "shahgoshtasbi/stl-decomp-4j", "max_issues_repo_head_hexsha": "9e28dfcdeeae53023242890c0fca61766fb44613", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2017-05-29T12:39:03.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-05T21:13:33.000Z", "max_forks_repo_path": "stl-decomp-4j/docs/ImplementationNotes.tex", "max_forks_repo_name": "shahgoshtasbi/stl-decomp-4j", "max_forks_repo_head_hexsha": "9e28dfcdeeae53023242890c0fca61766fb44613", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 42, "max_forks_repo_forks_event_min_datetime": "2017-05-15T22:07:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T08:05:15.000Z", "avg_line_length": 46.1591836735, "max_line_length": 375, "alphanum_fraction": 0.6573525511, "num_tokens": 4231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7074331216886407}}
{"text": "\\section{$n$-step TD Prediction}\n\\subsection{Exercise 7.1}\n\\subsubsection*{Q}\nIn Chapter 6 we noted that the Monte Carlo error can be written as the sum of TD errors (6.6) if the value estimates don’t change from step to step. Show that the $n$-step error used in (7.2) can also be written as a sum TD errors (again if the value estimates don’t change) generalizing the earlier result.\n\n\\subsubsection*{A}\nWrite\n\\[\n    G_{t:t+n} = \\sum_{i=1}^n \\gamma^{i-1}R_{t-i} + \\gamma^n V(S_{t+n}),\n\\]\nthen have the TD error\n\\[\n    \\delta_t \\doteq R_{t+1} + \\gamma V(S_{t+1}) - V(S_t).\n\\]\nSo the $n$-step error can be written as\n\\begin{align*}\n    G_{t:t+n} - V(S_t) &= R_{t+1} + \\gamma \\sum_{i=1}^{n-1} \\gamma^{i-1} R_{t+1+i} + \\gamma^n V(S_{t+n}) - V(S_t) \\\\\n                       &= \\delta_t + \\gamma \\left( G_{t+1:t+n} - V(S_{t+1}) \\right) \\\\\n                       &\\vdotswithin{=}\\\\\n                       &= \\sum_{k=t}^{t+n-1} \\gamma^{k-t} \\delta_k\n\\end{align*}\n\n\n\\subsection{Exercise 7.2 (programming)}\n\\subsubsection*{Q}\nWith an $n$-step method, the value estimates \\emph{do} change from step to step, so an algorithm that used the sum of TD errors (see previous exercise) in place of the error in (7.2) would actually be a slightly different algorithm. Would it be a better algorithm or a worse one? Devise and program a small experiment to answer this question empirically.\n\n\\subsubsection*{A}\n...\n\n\\subsection{Exercise 7.3}\n\\subsubsection*{Q}\nWhy do you think a larger random walk task (19 states instead of 5) was used in the examples of this chapter? Would a smaller walk have shifted the advantage to a different value of $n$? How about the change in left-side outcome from 0 to -1 made in the larger walk? Do you think that made any difference in the best value of $n$?\n\\subsubsection*{A}\n\\begin{itemize}\n    \\item Smaller walk would have shifted advantage to smaller $n$ because when $n \\geq \\frac{\\textrm{\\#states}-1}{2}$ (\\#states is odd) the algorithm updates all states visited by the terminal reward. This means that the algorithm only makes value changes of size $\\alpha$, since the values are no longer bootstrapped or backed up.\n    \\item The addition of the $-1$ reward on the left favours smaller values of $n$, because in longer episodes the larger values of $n$ will have to update many states by the terminal reward (now $-1$ rather than $0$) thus increasing variance\n\\end{itemize}\n\n\\subsection{Exercise 7.4}\n\\subsubsection*{Q}\nProve that the n-step return of Sarsa (7.4) can be written exactly in terms of a novel TD error, as\n\\[\n    G_{t:t+n} = Q_{t-1}(S_t, A_t) + \\sum_{k=t}^{\\textrm{min}(t+n, T) -1} \\gamma^{k-1}[R_{k+1} + \\gamma Q_k(S_{k+1}, A_{k+1}) - Q_{k-1}(S_k, A_k)].\n\\]\n\\subsubsection*{A}\nDenote\n\\[\n    G_{t:t+n} \\doteq \\sum_{i=1}^n \\gamma^{i-1}R_{t+i} + \\gamma^n Q_{t+n-1}(S_{t+n}, A_{t+n})\n\\]\nfor $n \\geq 1$ and $0 \\leq t < T-n$ and with $G_{t:t+n} = G_t$ if $t+n > T$.\\\\\n\nSet $\\tau = \\textrm{min}(t+n, T) - 1$ and observe that\n\\begin{align*}\n   & \\sum_{k=t}^{\\tau} \\gamma^{k-t} [R_{t+1} + \\gamma Q_k(S_{k+1}, A_{k+1}) - Q_{k-1}(S_k, A_k)] \\\\\n   &= \\sum_{k=t}^{\\tau} \\gamma^{k-t} R_{t+1} + \\gamma \\sum_{k=t}^{\\tau} \\gamma^{k-t} Q_k(S_{k+1}, A_{k+1}) - \\sum_{k=t}^{\\tau} \\gamma^{k-t} Q_{k-1}(S_k, A_k) \\\\\n   &= G_{t:t+n} - \\mathds{1}\\{t+n < T\\}\\gamma^n Q_{t+n-1}(S_{t+n}, A_{t+n}) + \\gamma^{\\tau} Q_{\\tau}(S_{\\tau}, A_{\\tau}) - Q_{t-1(S_t, A_t)} \\\\\n   &= G_{t:t+n} - Q_{t-1}(S_t, A_t).\n\\end{align*}\n\n\\subsection{Exercise 7.5}\n\\subsubsection*{Q}\nWrite the pseudocode for the off-policy state-value prediction algorithm described above.\n\\subsubsection*{A}\nThe update that we use is the same as the $n$-step TD update, only multiplied by the importance sampling ratio and with the control variate added. \n\\[\n    G_{t:h} \\doteq \\rho_t (R_{t+1} + \\gamma G_{t+1:h}) + (1 - \\rho_t) V_{h-1}(S_t)\n\\]\nThe algorithm is therefore the same, but with these steps replacing the old returns calculations, using the latest available value function.\\\\\n\nIf you take the recursion relation literally then we should get a control variate for each of the intermediary states $(t+1, \\dots, t+n)$, but I don't think that this is what is intended as this would just increase variance further.\n\n\\subsection{Exercise 7.6}\n\\subsubsection*{Q}\nProve that the control variate in the above equations does not change the expected value of the return.\n\\subsubsection*{A}\nIn (7.13) we have\n\\begin{align*}\n    \\E{}[(1-\\rho_t)V_{h-1}(S_t)] &= \\E{}_b[(1-\\rho_t)V_{h-1}(S_t)] \\\\\n                                 &= \\E{}_b[(1-\\rho_t)]\\E{}_b[V_{h-1}(S_t)] \\\\\n                                 &= 0.\n\\end{align*}\nIn the second case (7.14) we have \n\\begin{align*}\n    & \\E{}_b [\\bar{V}_{h-1}(S_{t+1}) - \\rho_{t+1}Q_{h-1}(S_{t+1}, A_{t+1}) \\vert S_{t+1}] \\\\\n    &= \\sum_a \\pi(a \\vert S_{t+1}) Q_{h-1}(S_{t+1}, a) - \\sum_a b(a \\vert S_{t+1}) \\frac{\\pi(a\\vert S_{t+1})}{b(a \\vert S_{t+1})} Q_{h-1}(S_{t+1}, a)\\\\\n                        &= 0 \n\\end{align*}\n\n\\subsection{*Exercise 7.7}\n\\subsubsection*{Q}\nWrite the pseudocode for the off-policy action-value prediction algorithm described immediately above. Pay particular attention to the termination conditions for the recursion upon hitting the horizon or the end of episode.\n\\subsubsection*{A}\n...\n\n\\subsection{Exercise 7.8}\n\\subsubsection*{Q}\nShow that the general (off-policy) version of the $n$-step return (7.13) can still be written exactly and compactly as the sum of state-based TD errors (6.5) if the approximate state value function does not change.\n\\subsubsection*{A}\nUpdate target is\n\\[\n    G_{t:h} = \\rho_t (R_{t+1} + \\gamma G_{t+1:h}) + (1 - \\rho_t) V_{h-1}(S_t).\n\\]\nAssume state-value function does not change and introduce the TD error\n\\[\n    \\delta_t \\doteq R_{t+1} + \\gamma V(S_{t+1}) - V(S_t).\n\\]\nThen\n\\begin{align*}\n    G_{t:h} - V(S_t) &= \\rho_t \\left( R_{t+1} + \\gamma G_{t+1:h} - V(S_t) \\right) \\\\\n                     &= \\rho_t \\left( R_{t+1} + \\gamma [G_{t+1:h} - V(S_{t+1})] + \\gamma V(S_{t+1})  - V(S_t) \\right) \\\\\n                     &= \\rho_t \\delta_t + \\rho_t \\gamma[G_{t+1:h} - V(S_{t+1})] \\\\\n                     &\\vdotswithin{=}\\\\\n                     &= \\sum_{i=t}^{\\textrm{min}(h, T)-1}\\rho_{t:i}\\gamma^{i-t}\\delta_i\n\\end{align*}\n\n\n\\subsection{Exercise 7.9}\n\\subsubsection*{Q}\nRepeat the above exercise for the action version of the off-policy n-step return (7.14) and the Expected Sarsa TD error (the quantity in brackets in Equation 6.9).\n\\subsubsection*{A}\nAction-value update is \n\\[\n    G_{t:h} = R_{t+1} + \\gamma \\rho_{t+1} \\left(G_{t+1:h} - Q_{h-1}(S_{t+1}, A_{t+1}\\right) - \\gamma \\bar{V}_{h-1}(S_h)\n\\]\nwhere\n\\[\n    \\bar{V}_h \\doteq \\sum_a \\pi(a \\vert S_h)Q(S_h, a)\n\\]\nand we assume that the action value function does not change between iterations. Define\n\\[\n    \\delta_t \\doteq R_{t+1} + \\gamma \\bar{V}(S_{t+1}) - Q(S_t, A_t).\n\\]\nThen\n\\begin{align*}\n    G_{t:h} - Q(S_t, A_t) &= \\delta_t + \\gamma \\rho_{t+1}(G_{t+1:h} - Q(S_{t+1}, A_{t+1})) \\\\\n                          &\\vdotswithin{=}\\\\\n                          &=\\sum_{i=t}^{\\textrm{min}(h, T)-1}\\gamma^{i-t}\\rho_{t+1:i}\\delta_i\n\\end{align*}\nwhere we enforce the convention that $\\rho_{a:b} = 1$ if $a > b$.\n\n\\subsection{Exercise 7.10 (programming)}\n\\subsubsection*{Q}\nDevise a small off-policy prediction problem and use it to show that the off-policy learning algorithm using (7.13) and (7.2) is more data efficient than the simpler algorithm using (7.1) and (7.9).\n\\subsubsection*{A}\n...\n\n\\subsection{Exercise 7.11}\n\\subsubsection*{Q}\nShow that if the approximate action values are unchanging, then the tree-backup return (7.16) can be written as a sum of expectation-based TD errors:\n\\[\n    G_{t:t+n} = Q(S_t, A_t) + \\sum_{k=t}^{\\textrm{min}(t+n, T)-1}\\delta_k \\prod_{i=t+1}^k \\gamma \\pi(A_i \\vert S_i),\n\\]\nwhere $\\delta_t \\doteq R_{t+1} + \\gamma \\bar{V}_t(S_{t+1}) - Q(S_t, A_t)$ and $\\bar{V}_t$ is given by (7.8).\n\n\\subsubsection*{A}\nAssume action-values unchanging. The recursion formula for tree backup is \n\\[\n    G_{t:t+n} = R_{t+1} + \\gamma \\sum_{a \\neq A_{t+1}} \\pi(a \\vert S_{t+1}) Q(S_{t+1}, a) + \\gamma \\pi(A_{t+1}, S_{t+1}) G_{t+1:t+n}.\n\\]\nDefine\n\\[\n    \\delta_t \\doteq R_{t+1} + \\gamma \\bar{V}(S_{t+1}) - Q(S_t, A_t)\n\\]\nwhere\n\\[\n    \\bar{V}_h \\doteq \\sum_a \\pi(a \\vert S_h)Q(S_h, a).\n\\]\nThen\n\\begin{align*}\n    G_{t:t+n} - Q(S_t, A_t) &= R_{t+1} + \\gamma \\bar{V}(S_{t+1}) - \\gamma \\pi(A_{t+1}, S_{t+1})Q(S_{t+1}, A_{t+1}) \\\\\n                            &\\quad - Q(S_t, A_t) + \\gamma \\pi(A_{t+1}, S_{t+1})G_{t+1:t+n} \\\\\n                            &= \\delta_t - \\gamma \\pi(A_{t+1}, S_{t+1}) [G_{t+1:t+n} - Q(S_{t+1}, A_{t+1})] \\\\\n                            &\\vdotswithin{=}\\\\\n                            &=\\sum_{i=1}^{\\textrm{min}(t+n, T)-1} \\delta_i \\prod_{j=t+1}^i \\gamma \\pi(A_j, S_j)\n\\end{align*}\nwhere we define the product operator to have the behaviour $\\prod_a^b[\\cdot] = 1$ for $a > b$.\n                                        \n\n\n\n", "meta": {"hexsha": "736594d06b4941086df132e7e6b0e832e8825ad4", "size": 8889, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/chapters/chapter7/chapter7_content.tex", "max_stars_repo_name": "ElliotMunro200/reinforcement_learning_an_introduction", "max_stars_repo_head_hexsha": "c4fccb46a4bb00955549be3505144ec49f0132e5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 234, "max_stars_repo_stars_event_min_datetime": "2018-09-01T00:26:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T03:55:50.000Z", "max_issues_repo_path": "exercises/chapters/chapter7/chapter7_content.tex", "max_issues_repo_name": "15779235038/reinforcement_learning_an_introduction", "max_issues_repo_head_hexsha": "a0ac9e5da6eaeae14d297a560c499d1a6e579c2a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2018-11-29T21:04:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-13T17:11:50.000Z", "max_forks_repo_path": "exercises/chapters/chapter7/chapter7_content.tex", "max_forks_repo_name": "15779235038/reinforcement_learning_an_introduction", "max_forks_repo_head_hexsha": "a0ac9e5da6eaeae14d297a560c499d1a6e579c2a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2018-07-31T04:53:21.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T04:03:43.000Z", "avg_line_length": 48.8406593407, "max_line_length": 354, "alphanum_fraction": 0.6144673192, "num_tokens": 3204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029117, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7073851346269759}}
{"text": "\\subsection{$k$-Nearest Neighbors}\n\nThe $k$-nearest neighbors algorithm ($k$-NN) is a nonparametric method commonly used for classification, where each object is classified by a vote among its $k$ nearest neighbors.\\cite{altman1992introduction} Since the algorithm is substantially a local method, it would be less likely to be influenced by global topology of the attribute space, which suggests an important advantage of applying $k$-NN here.\n\nHowever, it is also noteworthy that the $k$-NN algorithm suffers from severe curse of dimensionality. What makes it worse is that we have got only 2192 observations here but more than 10 attributes. Therefore some variable selection must be applied before launching the $k$-NN algorithm.\n\n\\begin{figure}[h]\n\\center\\includegraphics[width = .7\\textwidth]{knncv.png}\n\\caption{Cross Validation Error Rates of \\(k\\)-NN}\n\\label{knncv}\n\\end{figure}\n\n\\begin{table}[h]\n\\setlength{\\belowcaptionskip}{5pt}\n\\caption{Confusion Matrix and Error Rates of \\(k\\)-NN}\n\\label{errknn}\n\\centering\n\\renewcommand\\arraystretch{1.5}\n\\begin{tabular}{rrrrr}\n\\hline\n\\hline\n & & \\multicolumn{2}{c}{True Condition} & \\\\\n\\hline\n & & Non-Precipitation & Precipitation & \\\\\n\\cline{1-4}\n\\multirow{2}{*}{Prediction} & {Non-Precipitation} & 308 & 52 & \\\\\n\\cline{2-4}\n&Precipitation&58&241&\\\\\n\\hline\n&Error Rate & 0.1585 & 0.1775 & 0.1669\\\\\n\\cline{2-5}\n& & Type \\uppercase\\expandafter{\\romannumeral1} & Type \\uppercase\\expandafter{\\romannumeral2} & Overall\\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\nFortunately, the process of variable selection can be done with the result of the random forest which we have launched before. According to random forest, the most important attributes are PRCP, TDIF, and the four attributes regarding wind.\n\nThe data set can be even further reduced as we observe the strong correlation between WSF2 and WSF5 (their correlation turns out to be approximately $0.95$). Because of such stong colinearity, we would only keep 4 attributes, i.e. PRCP, TDIF, WSF5 and WDF5 in the $k$-NN algorithm. (Note that for wind vectors, the distances shall not be Euclidean as they are presented in polar coordinates.)\n\nThe cross validation error rates for different values of $k$ are shown above in Figure \\ref{knncv}, which suggests that $k=30$ would be the best to proceed with. Then the confusion matrix and the test errors are as follows in Table \\ref{errknn}.\n\nAs we can see, in general, SVM has the best performance, while $k$-NN the worse. It is also noteworthy that for all of the three methods here, there are always more Type \\uppercase\\expandafter{\\romannumeral2} error than Type \\uppercase\\expandafter{\\romannumeral1} error.\n\n", "meta": {"hexsha": "c45fab98dc1ebb8ef97ddd38df9d20d7dd66d62d", "size": 2657, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/knn.tex", "max_stars_repo_name": "shengchenHAO/Weather-Forecast-", "max_stars_repo_head_hexsha": "0c81dd5b8b3c4572464b0e0b841ca279ecb0d650", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Report/knn.tex", "max_issues_repo_name": "shengchenHAO/Weather-Forecast-", "max_issues_repo_head_hexsha": "0c81dd5b8b3c4572464b0e0b841ca279ecb0d650", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/knn.tex", "max_forks_repo_name": "shengchenHAO/Weather-Forecast-", "max_forks_repo_head_hexsha": "0c81dd5b8b3c4572464b0e0b841ca279ecb0d650", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.0444444444, "max_line_length": 408, "alphanum_fraction": 0.7662777569, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7073851337085899}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{amsmath,amsthm}\n\\usepackage[headings]{fullpage}\n\\usepackage[utopia]{mathdesign}\n\\usepackage{color}\n\n\\pagestyle{myheadings}\n\\markboth{MATH426/CISC410}{MATH426/CISC410}\n\n\\input{../../fncextra}\n\\begin{document}\n\n\\begin{center}\n  \\bf A fitting challenge\n\\end{center}\n\nSome phenomena, like the growth of tumors, can be predicted by theory to follow a \\textbf{Gompertz function},\n\\begin{equation}\n  \\label{g}\n  g(t) = A e^{-b e^{-ct}},\n\\end{equation}\nwhere $A,b,c$ are positive parameters. As $t$ varies over the real line, $g$ increases from 0 to $A$. \n\nSuppose you have data $(t_i,z_i)$, $i=1,\\dots,m$, that you believe follow a Gompertz curve with unknown parameters. Taking the log, we get\n\\begin{equation}\n  \\label{logdata}\n  \\log(z_i) \\approx (\\log A) - b e^{-c t_i}.\n\\end{equation}\nWe let $y_i=\\log z_i$ and let $a=\\log A$. Define a function $\\bff$ whose components are\n\\begin{equation}\n\t\\label{f}\n\tf_i(a,b,c) = a - b e^{-c t_i} - y_i.\n\\end{equation}\nIn order to fit the data, we seek to minimize $\\|\\bff\\|_2$ as a function of $a$, $b$, and $c$, which together we call the vector $\\bfx$. This is a nonlinear least squares problem that can be solved by the Levenberg iteration.\n\n\\subsection*{Preparation}\n\nRead section 4.7. \n\n\n\\subsection*{Goals}\n\nYou will find a nonlinear least squares fit to given data and use the result to predict the asymptotic value $g(\\infty)=A$. \n\n\\subsection*{Procedure}\n\nDownload the script template and the file \\texttt{gompertz\\_data}.\n\n\\begin{enumerate}\n    \\item Load the data file, which has two vectors \\texttt{t} and \\texttt{z}. Make a plot of $z$ versus $t$. \n     \n    \\item In a separate file, write a function \n\\begin{verbatim}\nfunction f = gomp(x,t,z)\n\\end{verbatim}\n    that returns the $m$-vector defined by~\\eqref{f}, given a value of $\\bfx=[a;b;c]$ and the vectors \\texttt{t} and \\texttt{z}.\n    \n    \\item In the script file, use \\texttt{levenberg} to find best fitting values for $a,b,c$. \n    \n    \\item Using the result of the fit, calculate the value of $\\lim_{t\\to\\infty} g(t)$. \n    \n    \\item On top of the data points, make a plot of the fitting function~\\eqref{g} over $0\\le t \\le 40$. (Remember that the function fits the log of the values, not the values themselves.)\n\\end{enumerate}\n\n\n\\end{document}\n\n", "meta": {"hexsha": "13190a659a8d08e8081a582c45426dc64ad26486", "size": 2301, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter04/Gompertz/Gompertz.tex", "max_stars_repo_name": "snowdj/fnc-extras", "max_stars_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 109, "max_stars_repo_stars_event_min_datetime": "2018-04-21T09:02:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T19:03:54.000Z", "max_issues_repo_path": "labs/chapter04/Gompertz/Gompertz.tex", "max_issues_repo_name": "snowdj/fnc-extras", "max_issues_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-12-04T22:17:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T21:04:47.000Z", "max_forks_repo_path": "labs/chapter04/Gompertz/Gompertz.tex", "max_forks_repo_name": "snowdj/fnc-extras", "max_forks_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 49, "max_forks_repo_forks_event_min_datetime": "2017-04-02T17:21:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T17:19:57.000Z", "avg_line_length": 33.347826087, "max_line_length": 225, "alphanum_fraction": 0.6992611908, "num_tokens": 714, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744806385542, "lm_q2_score": 0.8652240704135291, "lm_q1q2_score": 0.707385120004317}}
{"text": "\\section{Graphs}\r\n\r\n\\begin{frame}{Graphs}{Paths}\r\n  For a graph {\\color{MainA}$G = (V, E)$}:\r\n  \\begin{itemize}\r\n    \\item\r\n      A path of {\\color{MainA}$G$} is a sequence of edges\r\n      \\begin{math}\r\n        {\\color{MainA}u_1},\r\n        {\\color{MainA}u_2},\r\n        \\dots,\r\n        {\\color{MainA}u_i} \\in {\\color{MainA}V}\r\n      \\end{math}\r\n      with\r\n      \\begin{itemize}\r\n        \\item\r\n          Undirected graph:\r\n          \\begin{math}\r\n            \\{{\\color{MainA}u_1}, {\\color{MainA}u_2}\\},\r\n            \\{{\\color{MainA}u_2}, {\\color{MainA}u_3}\\},\r\n            \\dots,\r\n            \\{{\\color{MainA}u_{i-1}}, {\\color{MainA}u_i}\\} \\in\r\n            {\\color{MainA}E}\r\n          \\end{math}\r\n        \\item\r\n          Directed graph:\r\n          \\begin{math}\r\n            ({\\color{MainA}u_1}, {\\color{MainA}u_2}),\r\n            ({\\color{MainA}u_2}, {\\color{MainA}u_3}),\r\n            \\dots,\r\n            ({\\color{MainA}u_{i-1}}, {\\color{MainA}u_i}) \\in\r\n            {\\color{MainA}E}\r\n          \\end{math}\r\n      \\end{itemize}\r\n    \\item\r\n      The {\\color{MainA}length of a path} is\r\n      \\begin{itemize}\r\n        \\item\r\n          Without weights:\r\n          {\\color{MainA}number of edges} taken\r\n        \\item\r\n          With weights:\r\n          {\\color{MainA}sum of weigths of edges} taken\r\n      \\end{itemize}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Graphs}{Paths}\r\n  For a graph {\\color{MainA}$G = (V, E)$}:\r\n  \\begin{itemize}\r\n    \\item\r\n      The {\\color{MainA}shortest path} between two vertices\r\n      ${\\color{MainA}u}, {\\color{MainA}v}$ is the path\r\n      \\begin{math}\r\n      {\\color{MainA}P}\r\n      = ({\\color{MainA}u}, \\dots, {\\color{MainA}v})\r\n      \\end{math}\r\n      with the shortest length ${\\color{MainA}d(u,v)}$ or lowest costs\r\n    \\item\r\n      The {\\color{MainA}diameter} of a graph is the\r\n      {\\color{MainA}longest shortest path}\r\n  \\end{itemize}\r\n\\end{frame}\r\n", "meta": {"hexsha": "12afaa0fac194a8eaf180064c00b8acc97d91915", "size": 1978, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-13/Chapter/eng/010_Graphs.tex", "max_stars_repo_name": "TobiOnline/AlgoDat", "max_stars_repo_head_hexsha": "565a9f03a9ed7ef354cb4f143959df77df89b726", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2016-12-16T17:42:34.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-26T11:07:16.000Z", "max_issues_repo_path": "Lecture-13/Chapter/eng/010_Graphs.tex", "max_issues_repo_name": "TobiOnline/AlgoDat", "max_issues_repo_head_hexsha": "565a9f03a9ed7ef354cb4f143959df77df89b726", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2016-10-08T09:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-20T15:40:10.000Z", "max_forks_repo_path": "Lecture-13/Chapter/eng/010_Graphs.tex", "max_forks_repo_name": "TobiOnline/AlgoDat", "max_forks_repo_head_hexsha": "565a9f03a9ed7ef354cb4f143959df77df89b726", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2016-10-07T11:55:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-05T08:36:38.000Z", "avg_line_length": 29.9696969697, "max_line_length": 81, "alphanum_fraction": 0.4807886754, "num_tokens": 637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.707385112728748}}
{"text": "Given classifier $f : \\mathbb{R}^d \\to \\mathcal{Y}$, construct smoothed classifier $g$ as $\\displaystyle g(x) := \\argmax_{c \\in \\mathcal{Y}} \\P_\\epsilon \\left[f(x+\\epsilon) = c\\right]$ where $\\epsilon \\sim \\mathcal{N}(0, \\sigma^2 \\mathbf{1})$\n\n\\paragraph{Robustness}\nIf $\\displaystyle \\P[f(x+\\epsilon) = c_A] \\ge \\underline{p_A} \\ge \\overline{p_B} \\ge \\max_{c \\neq c_A} \\P[f(x+\\epsilon) = c]$, then $g(x+\\delta) = c_A$ for all $\\| \\delta \\|_2 < R := \\frac{\\sigma}{2} \\left( \\Phi^{-1}(\\underline{p_A}) - \\Phi^{-1}(\\overline{p_B}) \\right)$\n\n\\paragraph{Certification} $\\underline{p_A}$ approximate with sampling: if $\\underline{p_A} > 0.5$, return radius $\\sigma \\Phi^{-1}(\\underline{p_A})$, otherwise abstain. \n\n\\paragraph{Certified Accuracy}\nPick target radius $T$, count \\#points in test set with certified radius $R > T$ and where predicted label matches test set label (Standard accuracy: $T=0$)\n\n \\paragraph{Inference}\n Reject null hypothesis (true prob. of $f$ returning $\\hat{c_A}$ is $0.5$, i.e., classes are indistinguishable) if estimated $p$-value $\\le \\alpha$, else abstain. \n \n $\\rightarrow$ returns wrong class $\\hat{c_A} \\neq c_A$ with prob. $\\le \\alpha$\n \n \\paragraph{Generalized Smoothing} \n $g(x) = \\argmax_{c \\in \\mathcal{Y}} \\P_\\epsilon[f(\\psi_\\epsilon(x)) = c]$, $\\epsilon \\sim \\mathcal{N}(0, \\sigma^2\\mathbf{1})$, $\\psi_\\alpha(\\psi_\\beta) = \\psi_{\\alpha+\\beta}$ (e.g., instantiate $\\psi$ with geometric transformations). \n \n\\paragraph{Summary}\n\\begin{itemize}\n\\item Scales to large networks;\n\\item Relaxes deterministic guarantees into statistical guarantees on robustness;\n\\item May need many samples to obtain higher certified radius. Also requires sampling at inference time;\n\\item Generalizing smoothing to different properties is harder than convex methods.\n\\end{itemize}", "meta": {"hexsha": "3d980be17eb44b655efbe82106b7ebd66e025cc6", "size": 1796, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "randomized-smoothing.tex", "max_stars_repo_name": "cknabs/RIAI-summary-HS2020", "max_stars_repo_head_hexsha": "42a1ee3cc2e51c52188f842c78923792bd0f3edf", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-01-20T21:27:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-24T20:28:56.000Z", "max_issues_repo_path": "randomized-smoothing.tex", "max_issues_repo_name": "cknabs/RIAI-summary-HS2020", "max_issues_repo_head_hexsha": "42a1ee3cc2e51c52188f842c78923792bd0f3edf", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-25T09:29:16.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-25T10:50:09.000Z", "max_forks_repo_path": "randomized-smoothing.tex", "max_forks_repo_name": "cknabs/RIAI-summary-HS2020", "max_forks_repo_head_hexsha": "42a1ee3cc2e51c52188f842c78923792bd0f3edf", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 71.84, "max_line_length": 270, "alphanum_fraction": 0.6993318486, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.70735819954232}}
{"text": "\\subsection{Lagrange Multipliers}\r\n\\noindent\r\nLagrange multipliers are a method that allow us to find extrema of a function subject to domain constraints.\\\\\r\n\r\n\\input{./differentialMultivariableCalculus/toyExample}\r\n\r\n\\noindent\r\nIn the example above, $f_x = 1$, $g_x = 2x$, $f_y = 1$, and $g_y = 2y$ with constraint $x^2 + y^2 = 1$.\\\\ \r\nGiving us a system\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\t1 = \\lambda 2x \\\\ \r\n\t\t1 = \\lambda 2y \\\\ \r\n\t\tx^2 + y^2 = 1\r\n\t\\end{cases} \\implies x = y = \\pm \\frac{1}{\\sqrt{2}}\\text{ and } \\lambda = \\frac{1}{\\sqrt{2}}.\r\n\\end{equation*}\r\nThis means that the max value of $f$ constrained by $g$ is\r\n\\begin{equation*}\r\n\tf\\left(\\frac{1}{\\sqrt{2}},\\frac{1}{\\sqrt{2}}\\right) = \\sqrt{2}.\r\n\\end{equation*}\r\n\r\n\\input{./differentialMultivariableCalculus/methodLagrangeMultipliers}", "meta": {"hexsha": "be5494d73f7bf37b7b21c886cb0c91ee661591b3", "size": 799, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/lagrangeMultipliers.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/lagrangeMultipliers.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/lagrangeMultipliers.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 36.3181818182, "max_line_length": 111, "alphanum_fraction": 0.662077597, "num_tokens": 294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.7879312031126511, "lm_q1q2_score": 0.7073221380084057}}
{"text": "\n\\subsection{Scalar potential}\n\nGiven a vector field \\(\\mathbf F\\) we may be able to identify a scalar field \\(P\\) such that:\n\n\\(\\mathbf F=-\\nabla P\\)\n\n\\subsection{Non-uniqueness of scalar potentials}\n\nScalar potentials are not unique.\n\nIf \\(P\\) is a scalar potential of \\(\\mathbf F\\), then so is \\(P+c\\), where \\(c\\) is a constant.\n\n\\subsection{Conservative vector fields}\n\nNot all vector fields have scalar potentials. Those that do are conservative.\n\nFor example if a vector field is the gradient of a scalar height function, then the height is a scalar potential.\n\nIf a vector field is the rotation of water, there will not be a scalar potential.\n\n", "meta": {"hexsha": "2bca414beed22128a179af44a6c404da74a4c9ca", "size": 652, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/multiCalculus/02-01-scalarPotential.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/multiCalculus/02-01-scalarPotential.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/multiCalculus/02-01-scalarPotential.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.6363636364, "max_line_length": 113, "alphanum_fraction": 0.740797546, "num_tokens": 157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.7073221272255705}}
{"text": "\\subsection{Matrix Completion via Alternating Minimizations}\n\\label{matrix_completion}\n\n\\noindent{\\bf Description}\n\\smallskip\n\nLow-rank matrix completion is an effective technique for statistical data analysis widely used in the data mining and machine learning applications.\nMatrix completion is a variant of low-rank matrix factorization with the goal of recovering a partially observed and potentially noisy matrix from a subset of its revealed entries.\nPerhaps the most popular applications in which matrix completion has been successfully applied is in the context of collaborative filtering in recommender systems. \nIn this setting, the rows in the data matrix correspond to users, \nthe columns to items such as movies, and entries to feedback provided by users for items. \nThe goal is to predict missing entries of the rating matrix. \nThis implementation uses the alternating least-squares (ALS) technique for solving large-scale matrix completion problems.\\\\ \n\n\n\\smallskip\n\\noindent{\\bf Usage}\n\\smallskip\n\n{\\hangindent=\\parindent\\noindent\\it%\n\t{\\tt{}-f }path/\\/{\\tt{}ALS.dml}\n\t{\\tt{} -nvargs}\n\t{\\tt{} V=}path/file\n\t{\\tt{} L=}path/file\n\t{\\tt{} R=}path/file\n%\t{\\tt{} VO=}path/file\n\t{\\tt{} rank=}int\n\t{\\tt{} reg=}L2$\\mid$wL2%regularization\n\t{\\tt{} lambda=}double\n\t{\\tt{} fmt=}format\n\t\n}\n\n\n\\smallskip\n\\noindent{\\bf Arguments}\n\\begin{Description}\n\t\\item[{\\tt V}:]\n\tLocation (on HDFS) to read the input (user-item) matrix $V$ to be factorized\n\t\\item[{\\tt L}:]\n\tLocation (on HDFS) to write the left (user) factor matrix $L$\n\t\\item[{\\tt R}:]\n\tLocation (on HDFS) to write the right (item) factor matrix $R$\n%\t\\item[{\\tt VO}:]\n%\tLocation (on HDFS) to write the input matrix $VO$ with empty rows and columns removed (if there are any)\n\t\\item[{\\tt rank}:] (default:\\mbox{ }{\\tt 10})\n\tRank of the factorization\n\t\\item[{\\tt reg}] (default:\\mbox{ }{\\tt L2})\n\tRegularization:\\\\\n\t{\\tt L2} = L2 regularization;\\\\\n \t{\\tt wL2} = weighted L2 regularization;\\\\\n \tif {\\tt reg} is not provided no regularization will be performed. \n \t\\item[{\\tt lambda}:] (default:\\mbox{ }{\\tt 0.000001})\n \tRegularization parameter\n \t\\item[{\\tt maxi}:] (default:\\mbox{ }{\\tt 50})\n\t Maximum number of iterations\n\t\\item[{\\tt check}:] (default:\\mbox{ }{\\tt FALSE})\n\tCheck for convergence after every iteration, i.e., updating $L$ and $R$ once\n\t\\item[{\\tt thr}:] (default:\\mbox{ }{\\tt 0.0001})\n\tAssuming {\\tt check=TRUE}, the algorithm stops and convergence is declared \n\tif the decrease in loss in any two consecutive iterations falls below threshold {\\tt thr}; \n\tif {\\tt check=FALSE} parameter {\\tt thr} is ignored.\n\t\\item[{\\tt fmt}:] (default:\\mbox{ }{\\tt \"text\"})\n\tMatrix file output format, such as {\\tt text}, {\\tt mm}, or {\\tt csv}\n\\end{Description}\n \n \\smallskip\n \\noindent{\\bf Usage: ALS Prediction/Top-K Prediction}\n \\smallskip\n \n {\\hangindent=\\parindent\\noindent\\it%\n \t{\\tt{}-f }path/\\/{\\tt{}ALS\\_predict.dml}\n \t{\\tt{} -nvargs}\n \t{\\tt{} X=}path/file\n \t{\\tt{} Y=}path/file\n \t{\\tt{} L=}path/file\n \t{\\tt{} R=}path/file\n \t{\\tt{} Vrows=}int\n \t{\\tt{} Vcols=}int\n \t{\\tt{} fmt=}format\n \t\n }\\smallskip\n \n \n  \\smallskip  \n  {\\hangindent=\\parindent\\noindent\\it%\n  \t{\\tt{}-f }path/\\/{\\tt{}ALS\\_topk\\_predict.dml}\n  \t{\\tt{} -nvargs}\n  \t{\\tt{} X=}path/file\n  \t{\\tt{} Y=}path/file\n  \t{\\tt{} L=}path/file\n  \t{\\tt{} R=}path/file\n  \t{\\tt{} V=}path/file\n  \t{\\tt{} K=}int\n  \t{\\tt{} fmt=}format\n  \t\n  }\\smallskip\n \n%   \\noindent{\\bf Arguments --- Prediction}\n%   \\begin{Description}\n%   \t\\item[{\\tt X}:]\n%   \tLocation (on HDFS) to read the input matrix $X$ containing user-ids (first column) and item-ids (second column) \n%   \t\\item[{\\tt L}:]\n%   \tLocation (on HDFS) to read the left (user) factor matrix $L$\n%   \t\\item[{\\tt R}:]\n%   \tLocation (on HDFS) to read the right (item) factor matrix $R$\n%   \t\\item[{\\tt Y}:]\n%   \tLocation (on HDFS) to write the output matrix $Y$ containing user-ids (first column), item-ids (second column) and predicted ratings (third column)\n%   \t\\item[{\\tt Vrows}:] \n%   \tNumber of rows of the user-item matrix $V$\n%   \t\\item[{\\tt Vcols}] \n%   \tNumber of columns of the user-item matrix $V$ \n%   \t\\item[{\\tt fmt}:] (default:\\mbox{ }{\\tt \"text\"})\n%   \tMatrix file output format, such as {\\tt text}, {\\tt mm}, or {\\tt csv}\n%   \\end{Description}\n   \n\n  \\noindent{\\bf Arguments --- Prediction/Top-K Prediction}\n  \\begin{Description}\n  \t\\item[{\\tt V}:]\n  \tLocation (on HDFS) to read the user-item matrix $V$ \n  \t\\item[{\\tt X}:]\n  \tLocation (on HDFS) to read the input matrix $X$ with following format:\n  \t\\begin{itemize}\n  \t\t\\item for {ALS\\_predict.dml}: a 2-column matrix that contains the user-ids (first column) and the item-ids (second column),\n  \t\t\\item for {ALS\\_topk\\_predict.dml}: a 1-column matrix that contains the user-ids.\n  \t\\end{itemize} \n  \t\\item[{\\tt Y}:]\n  \tLocation (on HDFS) to write the output of prediction with the following format:\n  \t\\begin{itemize}\n  \t\t\\item for {ALS\\_predict.dml}: a 3-column matrix that contains the user-ids (first column), the item-ids (second column) and the predicted ratings (third column),\n  \t\t\\item for {ALS\\_topk\\_predict.dml}: a ($K+1$)-column matrix that contains the user-ids in the first column and the top-K item-ids in the remaining $K$ columns will be stored at {\\tt Y}.\n  \t\tAdditionally, a matrix with the same dimensions that contains the corresponding actual top-K ratings will be stored at {\\tt Y.ratings}; see below for details. \n  \t\\end{itemize}\n%  \tNote the following output format in predicting top-K items. \n%  \tFor a user with no available ratings in $V$ no \n%  \ttop-K items will be provided, i.e., the corresponding row in $Y$ will contains 0s.   \n%  \tMoreover, $K'<K$ items with highest predicted ratings will be provided for a user $i$ \n%  \tif the number of missing ratings $K'$ (i.e., those with 0 value in $V$) for $i$ is less than $K$.\n  \t\\item[{\\tt L}:]\n  \tLocation (on HDFS) to read the left (user) factor matrix $L$\n  \t\\item[{\\tt R}:]\n  \tLocation (on HDFS) to write the right (item) factor matrix $R$\n   \t\\item[{\\tt Vrows}:] \n   \tNumber of rows of $V$ (i.e., number of users)\n   \t\\item[{\\tt Vcols}] \n   \tNumber of columns of $V$ (i.e., number of items) \n  \t\\item[{\\tt K}:] (default:\\mbox{ }{\\tt 5})\n  \tNumber of top-K items for top-K prediction\n  \t\\item[{\\tt fmt}:] (default:\\mbox{ }{\\tt \"text\"})\n  \tMatrix file output format, such as {\\tt text}, {\\tt mm}, or {\\tt csv}\n  \\end{Description}\n  \n \\noindent{\\bf Details}\n \\smallskip\n \n Given an $m \\times n$ input matrix $V$ and a rank parameter $r \\ll \\min{(m,n)}$, low-rank matrix factorization seeks to find an $m \\times r$ matrix $L$ and an $r \\times n$ matrix $R$ such that $V \\approx LR$, i.e., we aim to approximate $V$ by the low-rank matrix $LR$.\n The quality of the approximation is determined by an application-dependent loss function $\\mathcal{L}$. We aim at finding the loss-minimizing factor matrices, i.e., \n \\begin{equation}\\label{eq:problem}\n (L^*, R^*) = \\textrm{argmin}_{L,R}{\\mathcal{L}(V,L,R)}.\n \\end{equation} \n In the context of collaborative filtering in the recommender systems it is often the case that the input matrix $V$ contains several missing entries. Such entries are coded with the 0 value and the loss function is computed only based on the nonzero entries in $V$, i.e.,\n \\begin{equation*} %\\label{eq:loss}\n \\mathcal{L}=\\sum_{(i,j)\\in\\Omega}l(V_{ij},L_{i*},R_{*j}),\n \\end{equation*} \n where $L_{i*}$ and $R_{*j}$, respectively, denote the $i$th row of $L$ and the $j$th column of $R$, $\\Omega=\\{\\omega_1,\\dots,\\omega_N\\}$ denotes the training set containing the observed (nonzero) entries in $V$, and $l$ is some local loss function.  \n %for some training set $\\Omega$ that contains the observed (nonzero) entries in $V$ and some local loss function $l$. In the above formula, \n \n ALS is an optimization technique that can be used to solve quadratic problems. \n For matrix completion, the algorithm repeatedly keeps one of the unknown matrices ($L$ or $R$) fixed and optimizes the other one. In particular, ALS alternates between recomputing the rows of $L$ in one step and the columns of $R$ in the subsequent step.  \n Our implementation of the ALS algorithm supports the loss functions summarized in Table~\\ref{tab:loss_functions} commonly used for matrix completion~\\cite{ZhouWSP08:als}. \n %\n \\begin{table}[t]\n \t\\centering\n \t\\label{tab:loss_functions}\n \t\\begin{tabular}{|ll|} \\hline\n \t\tLoss & Definition \\\\ \\hline\n% \t\t$\\mathcal{L}_\\text{Sl}$ & $\\sum_{i,j} (V_{ij} - [LR]_{ij})^2$ \\\\\n% \t\t$\\mathcal{L}_\\text{Sl+L2}$ & $\\mathcal{L}_\\text{Sl} + \\lambda \\Bigl( \\sum_{ik} L_{ik}^2 + \\sum_{kj} R_{kj}^2 \\Bigr)$ \\\\\n \t\t$\\mathcal{L}_\\text{Nzsl}$ & $\\sum_{i,j:V_{ij}\\neq 0} (V_{ij} - [LR]_{ij})^2$ \\\\\n \t\t$\\mathcal{L}_\\text{Nzsl+L2}$ & $\\mathcal{L}_\\text{Nzsl} + \\lambda \\Bigl( \\sum_{ik} L_{ik}^2 + \\sum_{kj} R_{kj}^2 \\Bigr)$ \\\\\n \t\t$\\mathcal{L}_\\text{Nzsl+wL2}$ & $\\mathcal{L}_\\text{Nzsl} + \\lambda \\Bigl(\\sum_{ik}N_{i*} L_{ik}^2 + \\sum_{kj}N_{*j} R_{kj}^2 \\Bigr)$ \\\\ \\hline \n \t\\end{tabular}\n \t\\caption{Popular loss functions supported by our ALS implementation; $N_{i*}$ and $N_{*j}$, respectively, denote the number of nonzero entries in row $i$ and column $j$ of $V$.}\n \\end{table}\n \n Note that the matrix completion problem as defined in (\\ref{eq:problem}) is a non-convex problem for all loss functions from Table~\\ref{tab:loss_functions}. \n However, when fixing one of the matrices $L$ or $R$, we get a least-squares problem with a globally optimal solution.  \n For example, for the case of $\\mathcal{L}_\\text{Nzsl+wL2}$ we have the following closed form solutions\n  \\begin{align*}\n  L^\\top_{n+1,i*} &\\leftarrow (R^{(i)}_n {[R^{(i)}_n]}^\\top + \\lambda N_2 I)^{-1} R_n V^\\top_{i*}, \\\\\n  R_{n+1,*j} &\\leftarrow ({[L^{(j)}_{n+1}]}^\\top L^{(j)}_{n+1} + \\lambda N_1 I)^{-1} L^\\top_{n+1} V_{*j}, \n  \\end{align*}\n where $L_{n+1,i*}$ (resp. $R_{n+1,*j}$) denotes the $i$th row of $L_{n+1}$ (resp. $j$th column of $R_{n+1}$), $\\lambda$ denotes \n the regularization parameter, $I$ is the identity matrix of appropriate dimensionality, \n $V_{i*}$ (resp. $V_{*j}$) denotes the revealed entries in row $i$ (column $j$), \n $R^{(i)}_n$ (resp. $L^{(j)}_{n+1}$) refers to the corresponding columns of $R_n$ (rows of $L_{n+1}$), \n and $N_1$ (resp. $N_2$) denotes a diagonal matrix that contains the number of nonzero entries in row $i$ (column $j$) of $V$.   \n \n% For example, for the case of $\\mathcal{L}_\\text{Sl-L2}$ we have the following closed form solutions\n% \\begin{align*}\n% L^\\top_{n+1,i*} &\\leftarrow (R_n {[R_n]}^\\top + \\lambda I)^{-1} R_n V^\\top_{i*}, \\\\\n% R_{n+1,*j} &\\leftarrow ({[L_{n+1}]}^\\top L_{n+1} + \\lambda I)^{-1} L^\\top_{n+1} V_{*j}, \n% \\end{align*}\n% where $L_{n+1,i*}$ (resp. $R_{n+1,*j}$) denotes the $i$th row of $L_{n+1}$ (resp. $j$th column of $R_{n+1}$), $\\lambda$ denotes \n% the regularization parameter and $I$ is the identity matrix of appropriate dimensionality. \n% For the case of $\\mathcal{L}_\\text{Nzsl}$ we need to remove the equation that correspond to zero entries of $V$ from the least-squares problems. \n% With wL2 we get the following equations\n% \\begin{align*}\n% L^\\top_{n+1,i*} &\\leftarrow (R^{(i)}_n {[R^{(i)}_n]}^\\top + \\lambda N_2 I)^{-1} R_n V^\\top_{i*}, \\\\\n% R_{n+1,*j} &\\leftarrow ({[L^{(j)}_{n+1}]}^\\top L^{(j)}_{n+1} + \\lambda N_1 I)^{-1} L^\\top_{n+1} V_{*j}, \n% \\end{align*}\n% where $V_{i*}$ (resp. $V_{*j}$) denotes the revealed entries in row $i$ (column $j$), \n% $R^{(i)}_n$ (resp. $L^{(j)}_{n+1}$) refers to the corresponding columns of $R_n$ (rows of $L_{n+1}$), \n% and $N_1$ (resp. $N_2$) denotes a diagonal matrix that contains the number of nonzero entries in row $i$ (column $j$) of $V$.\n \n \\textbf{Prediction.} \n Based on the factor matrices computed by ALS we provide two prediction scripts:   \n \\begin{Enumerate}\n \t\\item {\\tt ALS\\_predict.dml} computes the predicted ratings for a given list of users and items;\n \t\\item {\\tt ALS\\_topk\\_predict.dml} computes top-K item (where $K$ is given as input) with highest predicted ratings together with their corresponding ratings for a given list of users.\n \\end{Enumerate} \n  \n \\smallskip\n \\noindent{\\bf Returns}\n \\smallskip\n \n We output the factor matrices $L$ and $R$ after the algorithm has converged. The algorithm is declared as converged if one of the two criteria is meet: \n (1) the decrease in the value of loss function falls below {\\tt thr}\n given as an input parameter (if parameter {\\tt check=TRUE}), or (2) the maximum number of iterations (defined as parameter {\\tt maxi}) is reached. \n Note that for a given user $i$ prediction is possible only if user $i$ has rated at least one item, i.e., row $i$ in matrix $V$ has at least one nonzero entry. \n In case, some users have not rated any items the corresponding factor in $L$ will be all 0s.\n Similarly if some items have not been rated at all the corresponding factors in $R$  will contain only 0s. \n Our prediction scripts output the predicted ratings for a given list of users and items as well as the top-K items with highest predicted ratings together with the predicted ratings for a given list of users. Note that the predictions will only be provided for the users who have rated at least one item, i.e., the corresponding rows contain at least one nonzero entry. \n% Moreover in the case of top-K prediction, if the number of predicted ratings---i.e., missing entries--- for some user $i$ is less than the input parameter $K$, all the predicted ratings for user $i$ will be provided.\n\n \n\n \n \n  \n \\smallskip\n \\noindent{\\bf Examples}\n \\smallskip\n  \n% {\\hangindent=\\parindent\\noindent\\tt\n% \t\\hml -f ALS.dml -nvargs V=/user/biadmin/V L=/user/biadmin/L R=/user/biadmin/R rank=10 reg=\"L2\" lambda=0.0001 fmt=csv \n% \t\t\n% }\n  \n {\\hangindent=\\parindent\\noindent\\tt\n \t\\hml -f ALS.dml -nvargs V=/user/biadmin/V L=/user/biadmin/L R=/user/biadmin/R rank=10 reg=\"wL2\" lambda=0.0001 maxi=50 check=TRUE thr=0.001 fmt=csv\t\n \t\n }\n \n \\noindent To compute predicted ratings for a given list of users and items:\n \n {\\hangindent=\\parindent\\noindent\\tt\n  \t\\hml -f ALS-predict.dml -nvargs X=/user/biadmin/X Y=/user/biadmin/Y L=/user/biadmin/L R=/user/biadmin/R  Vrows=100000 Vcols=10000 fmt=csv\t\n  \t\n }\n  \n \\noindent To compute top-K items with highest predicted ratings together with the predicted ratings for a given list of users:\n \n {\\hangindent=\\parindent\\noindent\\tt\n   \t\\hml -f ALS-top-predict.dml -nvargs X=/user/biadmin/X Y=/user/biadmin/Y L=/user/biadmin/L R=/user/biadmin/R V=/user/biadmin/V K=10 fmt=csv\t\n   \t\n }\n\n\n%\n%\\begin{itemize}\n%\t\\item Y. Zhou, D. K. Wilkinson, R. Schreiber, and R. Pan. \\newblock{Large-scale parallel collaborative flitering for the Netflix prize}. In Proceedings of the International\n%\tConference on Algorithmic Aspects in Information and Management (AAIM), 2008, 337-348.\n%\\end{itemize}\n \n ", "meta": {"hexsha": "669af33f2678f0c17e535186a3f0a369a576a934", "size": 14700, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "system-ml/docs/Algorithms Reference/ALS.tex", "max_stars_repo_name": "alcedo/systemml", "max_stars_repo_head_hexsha": "4d371a6d6b52e5517b1411302af3fdd8cd3c156a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-03-17T18:03:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-25T08:17:09.000Z", "max_issues_repo_path": "system-ml/docs/Algorithms Reference/ALS.tex", "max_issues_repo_name": "alcedo/systemml", "max_issues_repo_head_hexsha": "4d371a6d6b52e5517b1411302af3fdd8cd3c156a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "system-ml/docs/Algorithms Reference/ALS.tex", "max_forks_repo_name": "alcedo/systemml", "max_forks_repo_head_hexsha": "4d371a6d6b52e5517b1411302af3fdd8cd3c156a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-11-26T00:43:09.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-02T06:29:30.000Z", "avg_line_length": 53.0685920578, "max_line_length": 371, "alphanum_fraction": 0.6800680272, "num_tokens": 4732, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7073221249903819}}
{"text": "\\section{Clustering Data Streams (20 points) }\n\n\\paragraph{Introduction.}\nIn this problem, we study an approach for clustering massive data streams. We will study a framework for turning an approximate clustering algorithm into one that can work on data streams, \\emph{i.e.}, one which needs a small amount of memory and a small number of (actually, just one) passes over the data. As the instance of the clustering problem, we will focus on the $k$-means problem.\n\n\\paragraph{Definitions.}\nBefore going into further details, we need some definitions:\n\\begin{itemize}\n\t\\item The function $d:\\mathbb{R}^{p}\\times \\mathbb{R}^{p} \\rightarrow \\mathbb{R}^{+}$ denotes the Euclidean distance:\n\t\\[\n\t\td(x,y) = ||x-y||_2.\n\t\\]\n\t\\item For any $x\\in \\mathbb{R}^p$ and $T\\subset \\mathbb{R}^p$, we define:\n\t\\[\n\t\td(x,T)=\\min_{z\\in T}\\{d(x,z)\\}.\n\t\\]\n\t\\item Having subsets $S,T\\subset \\mathbb{R}^{p}$, and a weight function $w:S\\rightarrow \\mathbb{R}^{+}$, we define:\n\t\\[\n\t\t\\mathrm{cost}_w(S,T)=\\sum_{x\\in S} w(x)d(x,T)^2.\n\t\\]\n\t\\item Finally, if for all $x\\in S$ we have $w(x)=1$, we simply denote $\\mathrm{cost}_w(S,T)$ by $\\mathrm{cost}(S,T)$.\n\\end{itemize}\n\n\\paragraph{Reminder: $k$-means clustering.}\nThe $k$-means clustering problem is as follows: given a subset $S\\subset \\mathbb{R}^p$, and an integer $k$, find the set $T$ (with $|T|=k$), which minimizes $\\mathrm{cost}(S,T)$. If a weight function $w$ is also given, the $k$-means objective would be to minimize $\\mathrm{cost}_w(S,T)$, and we call the problem the weighted $k$-means problem.\n\n\\paragraph{Strategy for clustering data streams.}\nWe assume we have an algorithm \\textsc{alg} which is an $\\alpha$-approximate weighted $k$-means clustering algorithm (for some $\\alpha>1$). In other words, given any $S\\subset \\mathbb{R}^p$, $k\\in\\mathbb{N}$, and a weight function $w$, \\textsc{alg} returns a set $T\\subset\n\\mathbb{R}^p$, $|T|=k$, such that:\n\\[\n\t\\mathrm{cost}_w(S,T)\\leq \\alpha \\min_{|T'|=k}\\{\\mathrm{cost}_w(S,T')\\}.\n\\]\n\\textbf{We will see how we can use {\\sc alg} as a building block to make an algorithm for the $k$-means problem on data streams.}\n\nThe basic idea here is that of divide and conquer: if $S$ is a huge set that does not fit into main memory, we can read a portion of it that does fit into memory, solve the problem on this subset (\\emph{i.e.}, do a clustering on this subset), record the result (\\emph{i.e.}, the cluster centers and some corresponding weights, as we will see), and then read a next portion of $S$ which is again small enough to fit into memory, solve the problem on this part, record the result, etc. At the end, we will have to combine the results of the partial problems to construct a solution for the main big problem (\\emph{i.e.}, clustering $S$).\n\nTo formalize this idea, we consider the following algorithm, which we denote as\n\\textsc{algstr}:\n\n\\begin{itemize}\n\t\\item Partition $S$ into $\\ell$ parts $S_1, \\ldots, S_{\\ell}$.\n  \\item For each $i=1$ to $\\ell$, run \\textsc{alg} on $S_i$ to get a set of $k$ centers\n  $T_i=\\{t_{i1}, t_{i2}, \\ldots, t_{ik}\\}$, and assume $\\{S_{i1},S_{i2}, \\ldots,\n  S_{ik}\\}$ is the corresponding clustering of $S_i$ (\\emph{i.e.}, $S_{ij} = \\{x\\in\n  S_i| \\, d(x,t_{ij}) < d(x,t_{ij'}) \\; \\forall j'\\neq j, 1\\leq j'\\leq k\\}$).\n  \\item Let $\\widehat{S}= \\bigcup_{i=1}^{\\ell}T_i$, and define weights $w(t_{ij}) =\n  |S_{ij}|$.\n  \\item Run \\textsc{alg} on $\\widehat{S}$ with weights $w$, to get $k$ centers $T$.\n  \\item Return $T$.\n\\end{itemize}\n\nNow, we analyze this algorithm. Assuming $T^{*}=\\{t^{*}_1, \\ldots, t^{*}_k\\}$ to\nbe the optimal $k$-means solution for $S$ (that is, $T^{*} =\n\\mathrm{argmin}_{|T'|=k}\\{\\mathrm{cost}(S,T')\\}$), we would like to compare\n$\\mathrm{cost}(S,T)$ (where $T$ is returned by \\textsc{algstr}) with\n$\\mathrm{cost}(S,T^{*})$.\n\nA small fact might be useful in the analysis below: for any ${(a,b) \\in \\mathbb{R}^+}$ we have: \\[{(a+b)^2 \\leq 2a^2 + 2b^2.}\\]\n\n\\subquestion{(a) [5pts]} First, we show that the cost of the final clustering can be bounded in terms of the total cost of the intermediate clusterings:\n\n\\task{Prove that: \\[\\mathrm{cost}(S,T) \\leq 2\\cdot \\mathrm{cost}_w(\\widehat{S},\nT) + 2\\sum_{i=1}^{\\ell} \\mathrm{cost}(S_i, T_i).\\]}\n\n\\hint{You might want to use Triangle Inequality for Euclidean distance $d$.}\n\n\n\\subquestion{(b) [5pts]} So, to bound the cost of the final clustering, we can\nbound the terms on the right hand side of the inequality in part (a).\nIntuitively speaking, we expect the second term to be small compared to\n$\\mathrm{cost}(S,T^{*})$, because $T^{*}$ only uses $k$ centers to represent the\ndata set ($S$), while the $T_i$'s, in total, use $k\\ell$ centers to represent\nthe same data set (and $k\\ell$ is potentially much bigger than $k$). We show this formally:\n\n\\task{Prove that: \\[{\\sum_{i=1}^{\\ell} \\mathrm{cost}(S_i, T_i) \\leq \\alpha \\cdot \\mathrm{cost}(S,T^{*})}.\\]}\n\n\n\\subquestion{(c) [10pt]} Prove that \\textsc{algstr} is a $(4\\alpha^2+6\\alpha)$-approximation algorithm for the $k$-means problem.\n\n\\task{\nProve that:  \n\\[{\\mathrm{cost}(S,T) \\leq (4\\alpha^2+6\\alpha)\n\\cdot \\mathrm{cost}(S,T^{*})}.\\]} \n\n\\textit{Hint: You might want to first prove two useful facts, which help bound the first term on the right hand side of the inequality in part (a):}\n\\[{\\mathrm{cost}_w(\\widehat{S}, T) \\leq \\alpha \\cdot \\mathrm{cost}_w(\\widehat{S},T^{*})}.\\]\n\\[{\\mathrm{cost}_w(\\widehat{S},\nT^{*}) \\leq 2\\sum_{i=1}^{\\ell} \\mathrm{cost}(S_i, T_i) + 2\\cdot \\mathrm{cost}(S,T^{*})}.\\]\n\n\n\\textbf{Additional notes:} We have shown above that \\textsc{algstr} is a $(4\\alpha^2+6\\alpha)$-approximation algorithm for the $k$-means problem. Clearly, $4\\alpha^2+6\\alpha > \\alpha$, so \\textsc{algstr} has a somewhat worse approximation guarantee than \\textsc{alg} (with which we started).  However, \\textsc{algstr} is better suited for the streaming application, as not only it takes just one pass over the data, but also it needs a much smaller amount of memory.\n\nAssuming that \\textsc{alg} needs $\\Theta(n)$ memory to work on an input set $S$ of size $n$  (note that just representing $S$ in memory will need $\\Omega(n)$ space), if we partitioning $S$ into $\\sqrt{n/k}$ equal parts, {\\sc algstr} can work with only ${O(\\sqrt{nk})}$ memory. (Like in the rest of the problem, $k$ represents the number of clusters per partition.)\n\nNote that for typical values of $n$ and $k$, assuming $k \\ll n$, we have $\\sqrt{nk} \\ll n$. For instance, with $n=10^6$, and $k=100$, we have $\\sqrt{nk} = 10^4$, which is $100$ times smaller than $n$.\n\n\\subsection*{What to submit}\n\\begin{enumerate}[(a)]\n\t\\item Proof that $\\mathrm{cost}(S,T) \\leq 2\\cdot\n\t\\mathrm{cost}_w(\\widehat{S}, T) + 2\\sum_{i=1}^{\\ell} \\mathrm{cost}(S_i, T_i)$.\n\t\\item Proof that $\\sum_{i=1}^{\\ell} \\mathrm{cost}(S_i, T_i) \\leq\n\\alpha \\cdot \\mathrm{cost}(S,T^{*})$.\n\t\\item Proof that $\\mathrm{cost}(S,T) \\leq (4\\alpha^2+6\\alpha)\n\\cdot \\mathrm{cost}(S,T^{*})$.\n\\end{enumerate}\n", "meta": {"hexsha": "944c48aeca094d0e97bbe92dd8e9a88ec2cb0483", "size": 6889, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw4-bundle/hw4-bundle/HW4 source/hw4_3.tex", "max_stars_repo_name": "x3pi/mining-massive-datasets", "max_stars_repo_head_hexsha": "36d1f8ab437ea75d7437fc3e28593c2bb907ddd9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-12-24T01:06:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T10:54:57.000Z", "max_issues_repo_path": "hw4-bundle/hw4-bundle/HW4 source/hw4_3.tex", "max_issues_repo_name": "x3pi/mining-massive-datasets", "max_issues_repo_head_hexsha": "36d1f8ab437ea75d7437fc3e28593c2bb907ddd9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hw4-bundle/hw4-bundle/HW4 source/hw4_3.tex", "max_forks_repo_name": "x3pi/mining-massive-datasets", "max_forks_repo_head_hexsha": "36d1f8ab437ea75d7437fc3e28593c2bb907ddd9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-09-11T17:31:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T20:33:33.000Z", "avg_line_length": 64.9905660377, "max_line_length": 635, "alphanum_fraction": 0.6768761794, "num_tokens": 2333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.8976952886860978, "lm_q1q2_score": 0.7073221221374306}}
{"text": "\\chapter{Falling Bodies}\n\nBecause of gravity, if you throw a hammer straight up in the air, from\nthe moment it leaves your hand until it hits the ground, it is\naccelerating toward the center of the earth at a constant rate.\n\n\\emph{Acceration} is the change in velocity. If the hammer leaves your\nhand with a velocity of 12 meters per second upward, one second later\nit will be rising, its velocity will have slowed to 2.2 meters per\nsecond. One second after that, the hammer will be falling at a rate of\n7.6 meters per second. Every second the hammer's velocity is changing by\n9.8 meters per second, and that change is always toward the center of\nthe earth. When the hammer is going up, gravity is slowing it down by\n9.8 meters per second each second.  When the hammer is coming down,\ngravity is speeding it up by 9.8 meters per second each second.\\index{acceleration}\n\nAcceleration due to gravity on earth is a constant negative 9.8 meters per second per second:\n\\begin{equation*}\na = -9.8   \n\\end{equation*}\n(Why is it negative? We are talking about height, which increases as\nyou go away from the center of the earth. Acceleration is changing the\nvelocity in the opposite direction.)\n\n\\section{Calculating the Velocity}\n\nGiven that the acceleration is constant, it makes sense that the\nvelocity is a straight line. Assuming once again that the hammer\nleaves your hand at 12 meters per second, then the upwards velocity at\ntime $t$ is given by:\n\\begin{equation*}\n  v = 12 - 9.8t\n\\end{equation*}\n\nNote that the velocity of the hammer is being given as a function. Here is its graph:\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-0.25,xmax=2.75,\n        ymin=-13,ymax=13,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$t$},\n        ylabel={$v$},\n        ]\n        \\addplot[no marks,sdkblue] expression[domain=0:2.25,samples=100]{x * (-9.8) + 12} node[left] {$12 - 9.8t$}; \n    \\end{axis}\n\\end{tikzpicture}\n\n\\begin{Exercise}[title={When is the apex of flight?}, label=vapex]\n  Given the hammer's velocity is given by $12 - 9.8t$, at what time (in seconds)\n  does it stop rising and begin to fall?\n\\end{Exercise}\n\\begin{Answer}[ref=vapex]\n  Solve for when the velocity is zero.\n\n  $t = \\frac{12}{9.8} = 1.22$ seconds after release.\n\\end{Answer}\n\nAt this point, we need to say something about air resistance. Gravity\nis not the only force on the hammer; as it travels through the air,\nthe air tries to slow it down. This force is called \\emph{air resistance},\nand for a large, fast moving object (like an airplane) it is very big force. For a\ndense object (like a hammer) moving at a slow speed (what you generate\nwith your hand), air resistance doesn't significantly affect acceleration.\n\n\\section{Calculating Position}\n\nIf you let go of the hammer when it is 2 meters\nabove the ground, the height of the hammer is given by:\n\\begin{equation*}\n  p = -\\frac{9.8}{2}t^2 + 12t + 2\n\\end{equation*}\n\nHere is a graph of this function:\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-1.2,xmax=3.5,\n        ymin=-13,ymax=13,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$t$},\n        ylabel={$p$},\n      ]\n      \\addplot[no marks,sdkblue,dashed,<-] expression [domain=-0.7:0,samples=100] {(-4.9)*(x^2) + 12 * x + 2};\n      \\addplot[no marks,sdkblue] expression [domain=0:2.58,samples=100] {(-4.9)*(x^2) + 12 * x + 2};\n      \\addplot[no marks,sdkblue,dashed,->] expression [domain=2.58:3,samples=100] {(-4.9)*(x^2) + 12 * x + 2};\n    \\end{axis}\n\\end{tikzpicture}\n\n\nHow did I figure this out? \\textbf{The change in position between time\n  $0$ and any time $t$ is equal to the area under the velocity graph\n  between $x = 0$ and $x = t$.}\n\nLet's use the velocity graph to figure out how much the position has\nchanged in the first second of the hammer's flight. Here's the\nvelocity graph with the area under the graph for the first second filled\nin:\n\n\\usepgfplotslibrary{fillbetween}\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-0.25,xmax=2.75,\n        ymin=-13,ymax=13,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$t$},\n        ylabel={$v$},\n      ]\n      \\addplot[no marks,sdkblue, name path=f] expression[domain=0:2.25,samples=100]{x * (-9.8) + 12} node[left] {$12 - 9.8t$};\n      \\path[name path=xaxis] (axis cs:0,0) -- (axis cs:1,0);\n      \\addplot[\n        thick,\n        color=sdkblue,\n        fill=sdkblue, \n        fill opacity=0.05\n    ]\n    fill between[\n        of=f and xaxis,\n        soft clip={domain=0:1},\n    ];\n    \\addplot[dashed,gray] coordinates {(0,12)(1,12)};\n    \\addplot[dashed,gray] coordinates {(1,12)(1,0)};\n    \\end{axis}\n\\end{tikzpicture}\n\nThe blue filled region is the area of the dashed rectangle minus that\nempty triangle in its upper left.  The height of the rectangle is\ntwelve and its width is the amount of time the hammer has been in\nflight ($t$).  The triangle is $t$ wide and and $9.8t$ tall. Thus, the\narea of the blue region is given by $12t - \\frac{1}{2}9.8 t^2$.\n\nThat's the change in position. Where was it originally? 2 meter off\nthe ground.  So the height is given by $p = 2 + 12t - \\frac{1}{2}9.8t^2$.\nWe usually write terms so that the exponent decreases, so:\n\n$$p = - \\frac{1}{2}9.8t^2 + 12t + 2$$\n\nFinding the area under the curve like this is called\n\\textit{integration}.  We say ``To find a function that gives the\nchange in position, we just integrate the velocity function.''  A lot\nof the study of calculus is learning to integrate different sorts of\nfunctions.\\index{integration}\n\nOne important note about integration: Any time the curve drops under\nthe $x$-axis, the area is considered negative. (Which makes sense,\nright? If the velocity is negative, the hammer's position is\ndecreasing.)\n\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-0.25,xmax=2.75,\n        ymin=-13,ymax=13,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$t$},\n        ylabel={$v$},\n      ]\n      \\addplot[no marks,sdkblue, name path=f] expression[domain=0:2.25,samples=100]{x * (-9.8) + 12} node[left] {$12 - 9.8t$};\n      \\path[name path=xaxis] (axis cs:0,0) -- (axis cs:2.25,0);\n      \\addplot[\n        thick,\n        color=sdkblue,\n        fill=sdkblue, \n        fill opacity=0.05\n      ]\n      fill between[\n        of=f and xaxis,\n        soft clip={domain=0:1.2245},\n      ];\n      \\addplot[\n        thick,\n        color=red,\n        fill=red, \n        fill opacity=0.07\n      ]\n      fill between[\n        of=f and xaxis,\n        soft clip={domain=1.2245:2.1},\n      ];\n    \\end{axis}\n\\end{tikzpicture}\n\n\n\\section{Quadratic functions}\n\nFunctions of the form $f(x) = a x^2 + b x + c$ are called \\newterm{quadratic functions}. \nIf $a > 0$, the ends go up.\nIf $a < 0$, the ends go down.\\index{quadratic functions}\n\n\n\\begin{tikzpicture}\n  \\begin{axis}[\n      xmin=-2.2,xmax=1.2,\n      ymin=-2,ymax=3,\n      axis x line=middle,\n      axis y line=middle,\n      axis line style=<->,\n    ]\n    \\addplot[no marks,sdkblue] expression [domain=-2:1,samples=100] {(2)*(x^2) + 2 * x - 1};\n  \\end{axis}\n  \\node[right] at (1,4) {$2x^2 + 2x - 1$};\n\\end{tikzpicture}\n\\hspace{4mm}\n\\begin{tikzpicture}\n  \\begin{axis}[\n    xmin=-1.5,xmax=1.5,\n    ymin=-2,ymax=1.5,\n    axis x line=middle,\n    axis y line=middle,\n    axis line style=<->,\n  ]\n  \\addplot[no marks,sdkblue] expression [domain=-1.5:1.5,samples=100] {(-1.2)*(x^2) + 0.5 * x + 1};\n\\end{axis}\n\\node[right] at (0.5,1) {$-1.2 x^2 + 0.5 x + 1$};\n\\end{tikzpicture}\n\nThe graph of a quadratic function is a \\newterm{parabola}.\n\n\\section{Simulating a falling body in Python}\n\nNow you are going to write some Python code that simulates the flying hammer. First, we are just going print out the position, speed, and acceleration of the hammer for every 1/100th of a second after it leaves your hand. (Later we will make a graph.)\n\nCreate a file called \\filename{falling.py} and type this into it:\n\n\\begin{Verbatim}\n# Acceleration on earth\nacceleration = -9.8 # m/s/s\n\n# Size of time step\ntime_step = 0.01 # seconds\n\n# Initial values\nspeed = 12  # m/s upward\nheight = 2  # m above the ground\ncurrent_time = 0.0  # seconds after release\n\n# Is the hammer still aloft?\nwhile height > 0.0:\n\n    # Show the values\n    print(f\"{current_time:.2f} s:\")\n    print(f\"\\tacceleration: {acceleration:.2f} m/s/s\")\n    print(f\"\\tspeed: {speed:.2f} m/s\")\n    print(f\"\\theight: {height:.2f} m\")\n\n    # Update height\n    height = height + time_step * speed\n\n    # Update speed\n    speed = speed + time_step * acceleration\n\n    # Update time\n    current_time = current_time + time_step\n\n\nprint(f\"Hit the ground: Complete\")\n\\end{Verbatim}\n\nWhen you run it, you will see something like this:\n\\begin{Verbatim}\n0.00 s:\n\tacceleration: -9.80 m/s/s\n\tspeed: 12.00 m/s\n\theight: 2.00 m\n0.01 s:\n\tacceleration: -9.80 m/s/s\n\tspeed: 11.90 m/s\n\theight: 2.12 m\n0.02 s:\n\tacceleration: -9.80 m/s/s\n\tspeed: 11.80 m/s\n\theight: 2.24 m\n0.03 s:\n\tacceleration: -9.80 m/s/s\n\tspeed: 11.71 m/s\n\theight: 2.36 m\n...\n2.60 s:\n\tacceleration: -9.80 m/s/s\n\tspeed: -13.48 m/s\n\theight: 0.20 m\n2.61 s:\n\tacceleration: -9.80 m/s/s\n\tspeed: -13.58 m/s\n\theight: 0.07 m\nHit the ground: Complete\n\\end{Verbatim}\n\nNote that the acceleration isn't changing at all, but it is changing\nthe speed and the speed is changing the height.\n\nWe can see that the hammer in our simulation hits the ground just\nafter 2.61 seconds.\n\n\\subsection{Graphs and Lists}\n\nNow, we are going to graph the acceleration, speed, and height using a\nlibrary called matplotlib. However, in order to make the graphs, we\nneed to gather all the data into lists.\\index{matplotlib}\n\nFor example, we will have a list of speeds, and the first three\nentries will be 12.0, 11.9, and 11.8.\\index{lists, python}\n\nWe create an empty list and assign it to a variable like this:\n\\begin{Verbatim}\nx = []\n\\end{Verbatim}\n\nThen we can add items like this:\n\\begin{Verbatim}\nx.append(3.14)\n\\end{Verbatim}\n\nTo get the first time back, we can ask for the object at index 0.\n\\begin{Verbatim}\ny = x[0]\n\\end{Verbatim}\nNote that the list starts at 0.  So if you have 32 items in the list,\nthe first item is at index 0. The last item is at index 31.\n\nDuplicate the file \\filename{falling.py} and name the new copy \\filename{falling\\_graph.py}\n\nWe are going to make a plot of the height over time. At the start of the program, you will import the\nmatplotlib library.  At the end of the program, you will create a plot and show it to the user.\n\nIn \\filename{falling\\_graph.py}, add the bold code:\n\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\textbf{import matplotlib.pyplot as plt}\n\n# Acceleration on earth\nacceleration = -9.8 # m/s/s\n\n# Size of time step\ntime_step = 0.01 # seconds\n\n# Initial values\nspeed = 12  # m/s upward\nheight = 2  # m above the ground\ncurrent_time = 0.0  # seconds after release\n\n\\textbf{# Create empty lists}\n\\textbf{accelerations = []}\n\\textbf{speeds = []}\n\\textbf{heights = []}\n\\textbf{times = []}\n\n# Is the hammer still aloft?\nwhile height > 0.0:\n\n    \\textbf{# Add the data to the lists}\n    \\textbf{times.append(current_time)}\n    \\textbf{accelerations.append(acceleration)}\n    \\textbf{speeds.append(speed)}\n    \\textbf{heights.append(height)}\n    \n    # Update height\n    height = height + time_step * speed\n\n    # Update speed\n    speed = speed + time_step * acceleration\n\n    # Update time\n    current_time = current_time + time_step\n\n\\textbf{# Make a plot}\n\\textbf{fig, ax = plt.subplots()}\nfig.suptitle(\"Falling Hammer\")\n\\textbf{ax.set_xlabel(\"Time (s)\")}\n\\textbf{ax.set_ylabel(\"Height (m)\")}\n\\textbf{ax.plot(times, heights)}\n\\textbf{plt.show()}\n\\end{Verbatim}\n\nWhen you run the program, you should see a graph of the height over time.\n\n\\includegraphics[width=0.7\\linewidth]{heightplot.png}\n\nIt is more interesting if we can see all three: acceleration, speed, and height. \nSo lets make three stacked plots.  Change the plotting code in \\filename{falling\\_graph.py} to:\\index{matplotlib!subplots}\n\n\\begin{Verbatim}\n# Make a plot with three subplots\nfig, ax = plt.subplots(3,1)\nfig.suptitle(\"Falling Hammer\")\n\n# The first subplot is acceleration\nax[0].set_ylabel(\"Acceleration (m/s/s)\")\nax[0].plot(times, accelerations)\n\n# Second subplot is speed\nax[1].set_ylabel(\"Speed (m/s)\")\nax[1].plot(times, speeds)\n\n# Third subplot is height\nax[2].set_xlabel(\"Time (s)\")\nax[2].set_ylabel(\"Height (m)\")\nax[2].plot(times, heights)\nplt.show()\n\\end{Verbatim}\n\nNow you will get plots of all three variables:\n\n\\includegraphics[width=0.8\\linewidth]{stackedplot.png}\n\nThis is what we expected, right?  The acceleration is a constant negative number.  The speed is a\nstraight line with a negative slope.  The height is a parabola.\n\nA natural question at this point is ``When exactly will the hammer hit the\nground?''  That is, when does $height = 0$? The values of $t$ where a function is zero are\nare known as its \\textit{roots}. Height is given by a quadratic function. In the next\nchapter, you will get the trick for finding the roots of any quadratic\nfunction.\n", "meta": {"hexsha": "dec826d31da3f17cb3098722ed0916dc7fc07d83", "size": 13052, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Functions/falling_bodies-en_US.tex", "max_stars_repo_name": "hillegass/sequence", "max_stars_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/Functions/falling_bodies-en_US.tex", "max_issues_repo_name": "hillegass/sequence", "max_issues_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/Functions/falling_bodies-en_US.tex", "max_forks_repo_name": "hillegass/sequence", "max_forks_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 30.8557919622, "max_line_length": 251, "alphanum_fraction": 0.6787465523, "num_tokens": 3981, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059609645724, "lm_q2_score": 0.8918110511888302, "lm_q1q2_score": 0.7073006607519426}}
{"text": "\\begin{cor}\n    \\label{cor_bin_exp_and_macaulay_conv}\n    (Generalization of Theorem~\\ref{thm_odd_power_by_macaulays_convolution} for Binomials.)\n    For every $m\\in\\mathbb{N}, \\; x,y\\in\\mathbb{R}$\n    \\begin{equation*}\n        \\sum_{r=0}^{m} \\coeffA{m}{r} \\convPower{n}{r}{x+y}\n        =\n        1 + \\sum_{r=0}^{2m+1} \\binom{2m+1}{r} x^{2m+1-r} y^r, \\quad n\\geq 0.\n    \\end{equation*}\n\\end{cor}\nFor example, given $m=0,1,2$ the Corollary~\\ref{cor_bin_exp_and_macaulay_conv} gives\n\\begin{equation*}\n    \\begin{split}\n        \\sum_{r=0}^{0} \\coeffA{0}{r} \\convPower{n}{r}{x+y}\n        &= 1 + x + y \\\\\n        \\sum_{r=0}^{1} \\coeffA{1}{r} \\convPower{n}{r}{x+y}\n        &= 1 + x + y - (x + y) (1 + x + y) (1 - 3 x - 3 y + 2 (x + y)) \\\\\n        &= 1 + x^3 + 3 x^2 y + 3 x y^2 + y^3\\\\\n        \\sum_{r=0}^{2} \\coeffA{2}{r} \\convPower{n}{r}{x+y}\n        &=1 + x + y + (x + y) (1 + x + y) \\left(-1 + x + 5 x^2 + y + 10 x y + 5 y^2\\right. \\\\\n        &-15 x (x + y) + 10 x^2 (x + y) - 15 y (x + y) + 20 x y (x + y) \\\\\n        &+ 10 y^2 (x + y) +9 (x + y)^2 - 15 x (x + y)^2 \\\\\n        &\\left.-15 y (x + y)^{2} + 6 {(x + y)}^{3}\\right) \\\\\n        &=x^5 + 5 x^4 y + 10 x^3 y^2 + 10 x^2 y^3 + 5 x y^4 + y^5 + 1\n    \\end{split}\n\\end{equation*}\nAbove example could be verified using using the commands\n\\begin{itemize}\n    \\item \\texttt{BinomialTheoremAndDiscreteConvolutionTest[0, x + y]}\n    \\item \\texttt{BinomialTheoremAndDiscreteConvolutionTest[1, x + y]}\n    \\item \\texttt{Expand[BinomialTheoremAndDiscreteConvolutionTest[1, x + y]]}\n    \\item \\texttt{BinomialTheoremAndDiscreteConvolutionTest[2, x + y]}\n    \\item \\texttt{Expand[BinomialTheoremAndDiscreteConvolutionTest[2, x + y]]}\n\\end{itemize}\ndefined in Mathematica package at~\\cite{PK22Source}.\n\\begin{cor}\n    \\label{cor_bin_exp_and_macaulay_conv_strict}\n    (Generalization of Theorem~\\ref{thm_odd_power_by_macaulays_convolution_strict} for Binomials.)\n    For every $m\\in\\mathbb{N}, \\; x,y\\in\\mathbb{R}$\n    \\begin{equation*}\n        \\sum_{r=0}^{m} \\coeffA{m}{r} \\convPower{n}{r}{x+y}\n        =\n        -1 + \\sum_{r=0}^{2m+1} \\binom{2m+1}{r} x^{2m+1-r} y^r, \\quad n > 0.\n    \\end{equation*}\n\\end{cor}\nFor example, given $m=0,1$ the Corollary~\\ref{cor_bin_exp_and_macaulay_conv_strict} gives\n\\begin{equation*}\n    \\begin{split}\n        \\sum_{r=0}^{0} \\coeffA{0}{r} \\convPower{n}{r}{x+y}\n        &= x + y - 1 \\\\\n        \\sum_{r=0}^{1} \\coeffA{1}{r} \\convPower{n}{r}{x+y}\n        &= -1 + x + y - (-1 + x + y) (x + y) (-1 - 3 x - 3 y + 2 (x + y)) \\\\\n        &= x^3 + 3 x^2 y + 3 x y^2 + y^3 - 1\n    \\end{split}\n\\end{equation*}\nAbove example could be verified using using the commands\n\\begin{itemize}\n    \\item \\texttt{BinomialTheoremAndDiscreteConvolutionStrictTest[0, x + y]}\n    \\item \\texttt{BinomialTheoremAndDiscreteConvolutionStrictTest[1, x + y]}\n    \\item \\texttt{Expand[BinomialTheoremAndDiscreteConvolutionStrictTest[1, x + y]]}\n\\end{itemize}\ndefined in Mathematica package at~\\cite{PK22Source}.\nFrom the other prospective, let be a function $f_r(t,k) = (t-k)^r, \\; t \\geq k$, then following identity holds\n\\begin{equation}\n(x-2a)\n    ^{2m+1} + 1 =\\sum_{r=0}^{m} \\coeffA{m}{r} (f_r(t,k) \\ast f_r(t,k))[x]\n    \\label{eq:parametric-identity}\n\\end{equation}\nLet be a function $g_r(t,k) = (t-k)^r, \\; t > k$, then\n\\begin{equation}\n(x-2a)\n    ^{2m+1} - 1 =\\sum_{r=0}^{m} \\coeffA{m}{r} (g_r(t,k) \\ast g_r(t,k))[x]\n    \\label{eq:parametric-identity-strict}\n\\end{equation}\n\n\\subsection{Generalization for Multinomials} \\label{subsec:generalization-for-multinomials}\nIn this subsection we generalize\nTheorems~\\ref{thm_odd_power_by_macaulays_convolution},~\\ref{thm_odd_power_by_macaulays_convolution_strict}\nfor multinomial cases.\n\\begin{cor}\n    \\label{cor_mult_exp_and_macaulay_conv}\n    (Generalization of Theorem~\\ref{thm_odd_power_by_macaulays_convolution} for Multinomials.)\n    For every $x_1, x_2, \\ldots, x_t\\in\\mathbb{R}, \\; m\\in\\mathbb{N}, \\; n\\geq1\\in\\mathbb{N}$\n    \\[\n        \\sum_{r=0}^{m} \\coeffA{m}{r} \\convPower{n}{r}{\\multifoldSum{t}} =\n        1 + \\sum_{\\multifoldSum[k]{t}=2m+1} \\binom{2m+1}{k_1, k_2,\\ldots, k_t} \\prod_{\\ell=1}^{t} x_\\ell^{k_\\ell}\n    \\]\n\\end{cor}\nFor instance, given $m=1$ the Corollary~\\ref{cor_mult_exp_and_macaulay_conv} gives\n\\begin{equation*}\n    \\begin{split}\n        &\\sum_{r=0}^{1} \\coeffA{1}{r} \\convPower{n}{r}{x+y+z} \\\\\n        &=1 + x + y + z - (x + y + z) (1 + x + y + z) (1 - 3 x - 3 y - 3 z + 2 (x + y + z)) \\\\\n        &=1 + x^3 + 3 x^2 y + 3 x y^2 + y^3 + 3 x^2 z + 6 x y z + 3 y^2 z + 3 x z^2 + 3 y z^2 + z^3.\n    \\end{split}\n\\end{equation*}\nAbove example could be verified using using the commands\n\\begin{itemize}\n    \\item \\texttt{BinomialTheoremAndDiscreteConvolutionTest[1, x + y + z]}\n    \\item \\texttt{Expand[BinomialTheoremAndDiscreteConvolutionTest[1, x + y + z]]}\n\\end{itemize}\ndefined in Mathematica package at~\\cite{PK22Source}.\n\\begin{cor}\n    \\label{cor_mult_exp_and_macaulay_conv_strict}\n    (Generalization of Theorem~\\ref{thm_odd_power_by_macaulays_convolution_strict} for Multinomials.)\n    For each $\\multifoldSum{t} \\geq 1, \\; x_1,x_2,\\ldots,x_t\\in\\mathbb{R}, \\; m\\in\\mathbb{N}, \\; n\\geq1\\in\\mathbb{N}$\n    \\[\n        \\sum_{r=0}^{m} \\coeffA{m}{r} \\convPower{n}{r}{\\multifoldSum{t}} =\n        -1 + \\sum_{\\multifoldSum[k]{t}=2m+1} \\binom{2m+1}{k_1, k_2,\\ldots, k_t} \\prod_{\\ell=1}^{t} x_\\ell^{k_\\ell}\n    \\]\n\\end{cor}\nFor example, given $m=1$ the Corollary~\\ref{cor_mult_exp_and_macaulay_conv_strict} gives\n\\begin{equation*}\n    \\begin{split}\n        &\\sum_{r=0}^{1} \\coeffA{1}{r} \\convPower{n}{r}{x+y+z} \\\\\n        &=-1 + x + y + z - (-1 + x + y + z) (x + y + z) (-1 - 3 x - 3 y - 3 z + 2 (x + y + z)) \\\\\n        &=-1 + x^3 + 3 x^2 y + 3 x y^2 + y^3 + 3 x^2 z + 6 x y z + 3 y^2 z + 3 x z^2 + 3 y z^2 + z^3.\n    \\end{split}\n\\end{equation*}\nAbove example could be verified using using the commands\n\\begin{itemize}\n    \\item \\texttt{BinomialTheoremAndDiscreteConvolutionStrictTest[1, x + y + z]}\n    \\item \\texttt{Expand[BinomialTheoremAndDiscreteConvolutionStrictTest[1, x + y + z]]}\n\\end{itemize}\ndefined in Mathematica package at~\\cite{PK22Source}.\n", "meta": {"hexsha": "0a6e538cb9639ebaf2c4e4b747ad4c4587920a71", "size": 6069, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/sections/relation-between-binomial-theorem-and-discrete-convolution.tex", "max_stars_repo_name": "kolosovpetro/OnTheBinomialTheoremAndDiscreteConvolution", "max_stars_repo_head_hexsha": "14a3facc4759e9b8452b15409e8dcfac4e9add26", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/sections/relation-between-binomial-theorem-and-discrete-convolution.tex", "max_issues_repo_name": "kolosovpetro/OnTheBinomialTheoremAndDiscreteConvolution", "max_issues_repo_head_hexsha": "14a3facc4759e9b8452b15409e8dcfac4e9add26", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/sections/relation-between-binomial-theorem-and-discrete-convolution.tex", "max_forks_repo_name": "kolosovpetro/OnTheBinomialTheoremAndDiscreteConvolution", "max_forks_repo_head_hexsha": "14a3facc4759e9b8452b15409e8dcfac4e9add26", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.1666666667, "max_line_length": 117, "alphanum_fraction": 0.609655627, "num_tokens": 2526, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7073006499489951}}
{"text": "\n\\section{Signal processing for vibration analysis}\nVibration data is vital for health assessment of a given system and carries out very useful information about its performance (refer to section \\ref{sec:data-acquisition} for details about data acquisition), yet these information are usually hard to observe in its raw waveform. Signal processing techniques are used to convert the raw waveform from time domain into frequency or time–frequnecy domains.\n\n\\section{Fourier analysis}\nFourier analysis, also called harmonic analysis, of a periodic signal $x(t)$ is the decomposition of the series into summation of sinusoidal components, where each sinusoid has a specific amplitude and phase.\n\nThe Fourier transform (FT) of a signal $x(t)$ can be mathematically given by equation \\ref{equation:fourier-transform}:\n\n\\begin{equation}\n    X(w) = \\int_{-\\infty}^{\\infty}x(n)e^{-jwt}dt\n    \\label{equation:fourier-transform}\n\\end{equation}\n\nIn practical applications of digital signal processing where signals are discrete in time rather than continuous (e.g. vibration analysis) a discretized version called discrete fourier transform (DFT) is used instead, it is expressed mathematically by equation \\ref{equation:discrete-fourier-transform}:\n\n\\begin{equation}\n    X(w) = \\sum_{-\\infty}^{\\infty}x(t)e^{-jwt}dt\n    \\label{equation:discrete-fourier-transform}\n\\end{equation}\n\nFast Fourier transform (FFT) is an effective algorithm used to implement DFT in computers. Figure \\ref{figure:fft} shows a signal in its waveform (or time domain) and its corresponding spectrum (frequency domain) obtained using FFT algorithm. The spectrum shows the frequency components present in the signal:\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics{figures/fft.pdf}\n    \\caption{Signal in the time domain and its fast Fourier transform}\n    \\label{figure:fft}\n\\end{figure}\n\n\\section{Wavelet transform}\nWavelet transform is also a spectral analysis tool, like Fourier transform. The main difference is that Fourier transform decomposes the signal into sinusoidal components, but wavelet transform decomposes it into a set of oscillatory functions called \\textbf{wavelets}. Unlike sinusoids, wavelets are localized in time, thus wavelet transform doesn't only provide information about the frequency present in a signal but also the time of their occurence. Wavelet transform is a much better solution than Fourier transform when studying non-linear non-stationary signals (i.e. its frequency components vary with time).\n\nFigure \\ref{fig:time-frequency-plane} shows the difference in time and frequency resolutions between different methods. In the waveform, the signal has absolute resolution in time and zero resolution in frequency. Fourier transform on the contrary transforms the signal totally into the frequency domain, therefore it has absolute resolution in frequency but no resolution in time. Short-time Fourier transform is calculated identically to fourier transform but it is performed on separate segments of the original signal to preserve some resolution in time. Wavelet transform on the other hand exhibits a high time resolution for high frequencies and high frequency resolution for low frequencies:\n\n\\begin{figure}[H]\n    \\centering\n    \\input{figures/time-frequency-resolution.tex}\n    \\caption{Time—frequency resolution plane}\n    \\label{fig:time-frequency-plane}\n\\end{figure}\n\nThere are a wide variety of wavelets that serve different purposes like Morlet wavelet, Daubechies wavelet and many others.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics{figures/wavelets.pdf}\n    \\caption{Different types of wavelets}\n    \\label{fig:wavelets}\n\\end{figure}\n\n\\subsection{Continuous wavelet transform}\nMathematically, continuous wavelet transform is defined by equation \\ref{equation:cwt}:\n\n\\begin{equation}\n    CWT_x^\\psi(\\tau, s)=\\frac{1}{\\sqrt{|s|}}\\int_{-\\infty}^{\\infty}x(t)\\psi^* \\left(\\frac{t-\\tau}{s}\\right)dt\n    \\label{equation:cwt}\n\\end{equation}\n\nWhere $x(t)$ is the original signal, $\\psi^*$ is a function called the \\textbf{mother wavelet}; $s$ and $\\tau$ are the \\textbf{scale} and \\textbf{translation} parameters respectively. The original signal is multiplied by the mother wavelet which is scaled using different scales then translated over the signal.\n\nThe output of \\acrshort{cwt} is a scaleogram like the one in figure \\ref{fig:scaleogram} which is a scaleogram (filled contour plot) of vibrations data snapshot of 25ms:\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics{figures/scaleogram.pdf}\n    \\caption{Scaleogram of vibration data snapshot}\n    \\label{fig:scaleogram}\n\\end{figure}\n\nThe x and y axes represent time and frequency respectively. Different colors indicate the power (i.e. amplitude) of each frequency (y-axis) during each instant of time (x-axis) which—unlike Fourier transform—provides information about the frequencies present in the signal and also the instances of time when these frequencies are present.\n\n\\subsection{Discrete wavelet transform}\nIn practical applicaions, discrete wavelet transform (DWT) is implemented as a filter bank where the signal is passed therough low- and high-pass filters to obtain \\textbf{approximation} and \\textbf{decomposition coefficients}. Figure \\ref{fig:dwt} shows a DWT with 2 levels of decomposition which yields 2nd order approximation and decomposition coefficients:\n\n\\begin{figure}[H]\n    \\centering\n    \\input{figures/dwt.tex}\n    \\caption{Discrete wavelet transform (DWT) as a filter bank}\n    \\label{fig:dwt}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics{figures/dwt_chirp.pdf}\n    \\caption{Level 3 signal decomposition using DWT}\n    \\label{fig:dwt-chirp-signal}\n\\end{figure}\n\nDWT returns two sets of coefficients: \\textbf{approximation coefficients} associated with the low pass filter and \\textbf{detail coefficients} associated with the high pass filter of the DWT. By applying DWT again on the approximation coefficients the next level of decomposition can be obtained. At each level the original signal is downsampled by a factor of 2, this fact imposes a limitation on the possible number of decomposition levels for a given signal.\n\n\\section{Conclusion}\nVibration data are discrete signals sampled at a certain frequency in time. Although they hold so many valuable information about equipment performance, these information are usually not directly observable in the time domain. Digital signal processing techniques offer a way to gain more insights from raw vibration data by converting it to frequency or time–frequency domains where unusual frequency components can indicate development of certain degradation pattern. This chapter introduced several of these techniques like Fourier and Wavelet transforms. A following chapter will present the use of these techniques for extracting features that serve as an input for a neural network that can estimate the remaining useful life.\n\\end{comment}\n\n", "meta": {"hexsha": "1f4eb65ec1db606ac137db0f46cc3548652dfa00", "size": 6934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter04_old.tex", "max_stars_repo_name": "ljalil/MasterThesis", "max_stars_repo_head_hexsha": "59f4ec6356f41647cc4ac9510bcdd0c8506919b8", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-06-25T16:28:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T19:53:37.000Z", "max_issues_repo_path": "chapters/chapter04_old.tex", "max_issues_repo_name": "ljalil/MasterThesis", "max_issues_repo_head_hexsha": "59f4ec6356f41647cc4ac9510bcdd0c8506919b8", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter04_old.tex", "max_forks_repo_name": "ljalil/MasterThesis", "max_forks_repo_head_hexsha": "59f4ec6356f41647cc4ac9510bcdd0c8506919b8", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-14T13:37:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-14T13:37:32.000Z", "avg_line_length": 72.2291666667, "max_line_length": 732, "alphanum_fraction": 0.7917507932, "num_tokens": 1562, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7073006471686777}}
{"text": "\\chapter{Theory}\n\n\\section{Strongly Correlated Systems}\n\\subsection{Exercise 1}\n\\paragraph*{(a)} Let $a_i^\\dagger$ be the creation operator on orbital $i$ and $a_i$ the annhilation operator. The canonical anticommutation relations are\n\\begin{align}\n    \\{a_i,\\, a_j\\} &= \\{a_i^\\dagger,\\, a_j^\\dagger\\} = 0 \\\\\n    \\{a_i,\\, a_j^\\dagger\\} &= \\delta_{i,\\, j} \\mathds{1}.\n\\end{align}\n\n\\paragraph*{(b)} One transformation is\n\\begin{align}\n    c_{i,0} &= a_i + a_i^\\dagger \\\\\n    c_{i,1} &= \\mathrm{i}(a_i - a_i^\\dagger),\n\\end{align}\nwhere $i$ is the orbital index.\n\n\\paragraph*{(c)} Majorana fermions satisfy the following anticommutation relation\n\\begin{equation}\n    \\{c_{i,\\alpha}c_{i,\\beta}\\} = \\delta_{i,j}\\delta_{\\alpha,\\beta} \\mathds{1}.\n\\end{equation}\n\n\n\\subsection{Exercise 2}\n\\paragraph*{(a)} Using the Jordan-Wigner transformation, a fermionic operator $a_j$ or $a_j^\\dagger$ becomes a $j$-local qubit operator, since it acts non trivially on $j$ sites.\n\n\\paragraph*{(b)} Thanks to the fact of storing only partial sums of qubits occupation, a fermionic operator translates into a $O(\\log(j))$-local qubit operator.", "meta": {"hexsha": "551742856b0d8f8d30ff0b71a87a1782fd46635f", "size": 1120, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/theory.tex", "max_stars_repo_name": "debrevitatevitae/aqa-project", "max_stars_repo_head_hexsha": "d300b577d3dd6f1e2d184b6897c4a06dc1e33f43", "max_stars_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/theory.tex", "max_issues_repo_name": "debrevitatevitae/aqa-project", "max_issues_repo_head_hexsha": "d300b577d3dd6f1e2d184b6897c4a06dc1e33f43", "max_issues_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/theory.tex", "max_forks_repo_name": "debrevitatevitae/aqa-project", "max_forks_repo_head_hexsha": "d300b577d3dd6f1e2d184b6897c4a06dc1e33f43", "max_forks_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.4814814815, "max_line_length": 178, "alphanum_fraction": 0.6928571429, "num_tokens": 366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425223682085, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.7072788939907189}}
{"text": "\n\\subsection{Introduction}\n\npage setting out linear stuff to come\n\nOLS, generalised linea rmodels etc are m-estimators, as are gmm\n\nh3 on parametric\n\nWith maximum likelihood estimation we maximise a function.\n\nWe could choose other functions to maximise or minimise.\n\n\\(\\sum_i f(x_i, \\theta )\\)\n\nIf \\(f(x_i, \\theta )\\) is differentiable wrt to \\(\\theta \\) this can be solved by finding the stationay point.\n\nThis is a \\(\\phi \\) type.\n\nOtherwise it is a \\(\\rho \\) type.\n\n \n\npage on influence funcitons there\n\nGeneralisation of MLE.\n\n\\(m_\\theta =m_\\theta (x, \\theta )\\)\n\nZ-estimator is where this is met, through diff\n\n\\(\\frac{\\delta }{\\delta \\theta }m_\\theta =z_\\theta (\\theta , x)=0\\)\n\nM-estimator for mean \n\n\\(m_\\theta (\\theta )=-(x-\\theta )^2\\)\n\n\\(z_\\theta (\\theta )=x-\\theta \\)\n", "meta": {"hexsha": "eae3640243e1c70f5076ec972fe5383d7cf11301", "size": 781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/M/01-01-M_estimation.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/M/01-01-M_estimation.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/M/01-01-M_estimation.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.0256410256, "max_line_length": 110, "alphanum_fraction": 0.6927016645, "num_tokens": 233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7072705970712843}}
{"text": "\\section{The Gram-Schmidt orthogonalization procedure}\n\\label{sec:gram-schmidt}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Use the Gram-Schmidt procedure to find an orthogonal basis\n    of a subspace of an inner product space.\n  \\item Find an orthonormal basis of a subspace.\n  \\end{enumerate}\n\\end{outcome}\n\nAlthough we have already seen some potential uses for orthogonal\nbases, we have not yet seen very many examples of such bases. In this\nsection, we will look at the Gram-Schmidt orthogonalization procedure,\na method for turning any basis into an orthogonal one.\n\nThe basic idea is very simple: if two vectors $\\vect{v}_1,\\vect{v}_2$\nare not orthogonal, then we can make them orthogonal by replacing\n$\\vect{v}_2$ by a vector of the form $\\vect{u}_2 = \\vect{v}_2 -\nt\\vect{v}_1$, for a suitable parameter $t$.\n\\begin{equation*}\n  \\begin{tikzpicture}[scale=1.25]\n    \\draw[thick,red] (1.5,0) -- (1.5,2) -- (0,2);\n    \\draw[thick,blue,->] (0,0) -- node[left]{$\\vect{v}_1$} (0,2.7);\n    \\draw[thick,blue,->] (0,0) -- node[left, pos=0.6]{$\\vect{v}_2$} (1.5,2);\n    \\draw[thick,green!50!black,->] (0,0) -- node[below right, pos=0.3]{$\\vect{u}_2 = \\vect{v}_2 - t\\vect{v}_1$} (1.5,0);\n  \\end{tikzpicture}\n\\end{equation*}\nBut what is the correct value of $t$? It turns out that this value is\nuniquely determined by the requirement that $\\vect{v}_1$ and\n$\\vect{u}_2$ must be orthogonal. We calculate\n\\begin{equation*}\n  \\iprod{\\vect{v}_1,\\vect{u}_2}\n  ~=~ \\iprod{\\vect{v}_1,\\vect{v}_2-t\\vect{v}_1}\n  ~=~ \\iprod{\\vect{v}_1,\\vect{v}_2}-t\\iprod{\\vect{v}_1,\\vect{v}_1}.\n\\end{equation*}\nSetting this equal to $0$ yields the unique solution\n\\begin{equation*}\n  t = \\frac{\\iprod{\\vect{v}_1,\\vect{v}_2}}{\\iprod{\\vect{v}_1,\\vect{v}_1}}\n\\end{equation*}\nNote that this is exactly the same thing as the Fourier coefficient of\n$\\vect{v}_2$ in the direction of $\\vect{v}_1$. The following\nproposition summarizes what we have found so far. For consistency with\nour later notation, we also rename the first basis vector $\\vect{v}_1$\nto $\\vect{u}_1$.\n\n\\begin{proposition}{Gram-Schmidt orthogonalization procedure for 2 vectors}{gram-schmidt-2}\n  Let $\\set{\\vect{v}_1,\\vect{v}_2}$ be a basis for some subspace $W$\n  of an inner product space $V$. Define vectors\n  $\\vect{u}_1,\\vect{u}_2$ as follows:\n  \\begin{eqnarray*}\n    \\vect{u}_1 &=& \\vect{v}_1, \\\\\n    \\vect{u}_2 &=& \\vect{v}_2 ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_2}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1.\n  \\end{eqnarray*}\n  Then $\\set{\\vect{u}_1,\\vect{u}_2}$ is an orthogonal basis of $W$.\n\\end{proposition}\n\n\\begin{example}{Gram-Schmidt orthogonalization procedure for 2 vectors}{gram-schmidt-2}\n  In $\\R^3$ with the usual dot product, find an orthogonal basis for\n  \\begin{equation*}\n    \\sspan\\set{\n      \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    }.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  Let $\\vect{v}_1 = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}$\n  and $\\vect{v}_2 = \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 1 \\end{mymatrix}$.\n  We calculate\n  \\begin{eqnarray*}\n    \\vect{u}_1\n    &=& \\vect{v}_1\n        ~=~ \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}, \\\\\n    \\vect{u}_2\n    &=& \\vect{v}_2 ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_2}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1\n        ~=~ \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    ~-~ \\frac{1}{2}\\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{c} -1/2 \\\\ 1/2 \\\\ 1 \\end{mymatrix}.\n  \\end{eqnarray*}\n  Therefore the desired orthogonal basis is\n  $\\set{\\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\end{mymatrix},\n    \\begin{mymatrix}{c} -1/2 \\\\ 1/2 \\\\ 1 \\end{mymatrix}}$.\n\\end{solution}\n\nThe procedure for finding an orthogonal basis of a $k$-dimensional\nspace is very similar. We adjust each basis vector $\\vect{v}_i$ by\nsubtracting a suitable linear combination of previous orthogonal basis\nvectors.\n\n\\begin{proposition}{Gram-Schmidt orthogonalization procedure for $k$ vectors}{gram-schmidt-k}\n  Let $\\set{\\vect{v}_1,\\ldots,\\vect{v}_k}$ be a basis for some subspace $W$\n  of an inner product space $V$.%\n  \\index{Gram-Schmidt procedure}%\n  \\index{orthogonalization}%\n  \\index{orthogonal basis!Gram-Schmidt procedure}\n  Define vectors\n  $\\vect{u}_1,\\ldots,\\vect{u}_k$ as follows:\n  \\begin{eqnarray*}\n    \\vect{u}_1\n    &=& \\vect{v}_1,\n    \\\\\n    \\vect{u}_2\n    &=& \\vect{v}_2\n        ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_2}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1,\n    \\\\\n    \\vect{u}_3\n    &=& \\vect{v}_3\n        ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_3}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1\n        ~-~ \\frac{\\iprod{\\vect{u}_2,\\vect{v}_3}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\vect{u}_2,\n    \\\\\n    &\\vdots&\n    \\\\\n    \\vect{u}_k\n    &=& \\vect{v}_k\n        ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_k}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1\n        ~-~ \\frac{\\iprod{\\vect{u}_2,\\vect{v}_k}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\vect{u}_2\n        ~-~ \\ldots\n        ~-~ \\frac{\\iprod{\\vect{u}_{k-1},\\vect{v}_k}}{\\iprod{\\vect{u}_{k-1},\\vect{u}_{k-1}}}\\vect{u}_{k-1}.\n  \\end{eqnarray*}\n  Then $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is an orthogonal basis of $W$.\n\\end{proposition}\n\n\\begin{proof}\n  First, it is clear that $\\set{\\vect{v}_1,\\ldots,\\vect{v}_k}$ and\n  $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ span the same subspace, as each\n  $\\vect{v}_i$ is a linear combination of\n  $\\vect{u}_1,\\ldots,\\vect{u}_i$ and conversely, each $\\vect{u}_i$ is\n  a linear combination of $\\vect{v}_1,\\ldots,\\vect{v}_i$. So the only\n  thing we must check is that $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is\n  an orthogonal set. In other words, we must show that\n  $\\iprod{\\vect{u}_j,\\vect{u}_i}=0$ for all $j<i$. We prove this by\n  induction on $i$, i.e., we assume it is already true for all pairs\n  of indices smaller than $i$. To show\n  $\\iprod{\\vect{u}_j,\\vect{u}_i}=0$, we calculate:\n  \\begin{eqnarray*}\n    \\iprod{\\vect{u}_j,\\vect{u}_i}\n    &=& \\textstyle\n        \\iprod{\\vect{u}_j, \\vect{v}_i\n        ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_i}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1\n        ~-~ \\ldots\n        ~-~ \\frac{\\iprod{\\vect{u}_j,\\vect{v}_i}}{\\iprod{\\vect{u}_j,\\vect{u}_j}}\\vect{u}_j\n        ~-~ \\ldots\n        ~-~ \\frac{\\iprod{\\vect{u}_{i-1},\\vect{v}_i}}{\\iprod{\\vect{u}_{i-1},\\vect{u}_{i-1}}}\\vect{u}_{i-1}}\n    \\\\\n    &=& \\textstyle\n        \\iprod{\\vect{u}_j, \\vect{v}_i}\n        ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_i}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\iprod{\\vect{u}_j,\\vect{u}_1}\n        ~-~ \\ldots\n        ~-~ \\frac{\\iprod{\\vect{u}_j,\\vect{v}_i}}{\\iprod{\\vect{u}_j,\\vect{u}_j}}\\iprod{\\vect{u}_j,\\vect{u}_j}\n        ~-~ \\ldots\n        ~-~ \\frac{\\iprod{\\vect{u}_{i-1},\\vect{v}_i}}{\\iprod{\\vect{u}_{i-1},\\vect{u}_{i-1}}}\\iprod{\\vect{u}_j,\\vect{u}_{i-1}}\n    \\\\\n    &=& \\textstyle\n        \\iprod{\\vect{u}_j, \\vect{v}_i}\n        ~-~ 0\n        ~-~ \\ldots\n        ~-~ \\frac{\\iprod{\\vect{u}_j,\\vect{v}_i}}{\\iprod{\\vect{u}_j,\\vect{u}_j}}\\iprod{\\vect{u}_j,\\vect{u}_j}\n        ~-~ \\ldots\n        ~-~ 0\n    \\\\\n    &=& \\iprod{\\vect{u}_j, \\vect{v}_i}\n        ~-~ \\iprod{\\vect{u}_j,\\vect{v}_i}\n    \\\\\n    &=& 0.\n  \\end{eqnarray*}\n  It follows that the set $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is\n  orthogonal, as desired.\n\\end{proof}\n\n\\begin{example}{Gram-Schmidt orthogonalization procedure}{gram-schmidt-r4}\n  In $\\R^4$, find an orthogonal basis for\n  \\begin{equation*}\n    \\sspan\\set{\n      \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 0 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    }.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  Let\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{v}_2 = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 0 \\end{mymatrix},\\quad\\mbox{and}\\quad\n    \\vect{v}_3 = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix}.\n  \\end{equation*}\n  We calculate\n  \\begin{eqnarray*}\n    \\vect{u}_1\n    &=& \\vect{v}_1\n        ~=~ \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix},\n    \\\\\n    \\vect{u}_2\n    &=& \\vect{v}_2 ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_2}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1\n    ~=~ \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    ~-~ \\frac{3}{4}\\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{c} 1/4 \\\\ 1/4 \\\\ 1/4 \\\\ -3/4 \\end{mymatrix},\n    \\\\\n    \\vect{u}_3\n    &=& \\vect{v}_3\n        ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_3}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1\n        ~-~ \\frac{\\iprod{\\vect{u}_2,\\vect{v}_3}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\vect{u}_2\n    \\\\\n    &=& \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    ~-~ \\frac{2}{4}\\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    ~-~ \\frac{1/2}{3/4}\\begin{mymatrix}{c} 1/4 \\\\ 1/4 \\\\ 1/4 \\\\ -3/4 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{c} 1/3 \\\\ 1/3 \\\\ -2/3 \\\\ 0 \\end{mymatrix}.\n  \\end{eqnarray*}\n  Therefore the orthogonal basis is\n  $\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3} = \\set{\n    \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix},~\n    \\begin{mymatrix}{c} 1/4 \\\\ 1/4 \\\\ 1/4 \\\\ -3/4 \\end{mymatrix},~\n    \\begin{mymatrix}{c} 1/3 \\\\ 1/3 \\\\ -2/3 \\\\ 0 \\end{mymatrix}\n  }$.\n\\end{solution}\n\nThe Gram-Schmidt procedure is sensitive to reordering the vectors. For\nexample, if we order the original basis vectors in\nExample~\\ref{exa:gram-schmidt-r4} in the opposite order, we end up\nwith a different orthogonal basis at the end. Sometimes this can\nsimplify the calculations, as the following example shows.\n\n\\begin{example}{Gram-Schmidt orthogonalization procedure: reordering the vectors}{gram-schmidt-r4-b}\n  In $\\R^4$, find an orthogonal basis for\n  \\begin{equation*}\n    \\sspan\\set{\n      \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 0 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    }.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  Note that these are the same basis vectors as in\n  Example~\\ref{exa:gram-schmidt-r4}, but listed in a different order.\n  Let\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix},\\quad\n    \\vect{v}_2 = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 0 \\end{mymatrix},\\quad\\mbox{and}\\quad\n    \\vect{v}_3 = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  We calculate\n  \\begin{eqnarray*}\n    \\vect{u}_1\n    &=& \\vect{v}_1\n        ~=~ \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix},\n    \\\\\n    \\vect{u}_2\n    &=& \\vect{v}_2 ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_2}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1\n    ~=~ \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    ~-~ \\frac{2}{2}\\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{mymatrix},\n    \\\\\n    \\vect{u}_3\n    &=& \\vect{v}_3\n        ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_3}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1\n        ~-~ \\frac{\\iprod{\\vect{u}_2,\\vect{v}_3}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\vect{u}_2\n    \\\\\n    &=& \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    ~-~ \\frac{2}{2}\\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    ~-~ \\frac{1}{1}\\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{mymatrix}.\n  \\end{eqnarray*}\n  This time, we end up with the orthogonal basis\n  $\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3} = \\set{\n    \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix},~\n    \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{mymatrix},~\n    \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{mymatrix}\n  }$.\n\\end{solution}\n\nIn the next example, we will consider $\\R^n$, but with a non-standard\ninner product.\n\n\\begin{example}{Gram-Schmidt orthogonalization procedure, non-standard inner product}{gram-schmidt-non-standard}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{ccc}\n      1 & 2 & -2 \\\\\n      2 & 6 & -1 \\\\\n      -2 & -1 & 9 \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  and consider the vector space $\\R^3$ with the inner product given by\n  $\\iprod{\\vect{v},\\vect{w}} = \\vect{v}^T A\\vect{w}$.\n  Let\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\end{mymatrix},\n    \\quad\n    \\vect{v}_2 = \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 0 \\end{mymatrix},\n    \\quad\\mbox{and}\\quad\n    \\vect{v}_3 = \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Apply the Gram-Schmidt procedure to\n  $\\vect{v}_1,\\vect{v}_2,\\vect{v}_3$ to find an orthogonal basis\n  $\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3}$ for $\\R^3$ with respect to\n  the above inner product.\n\\end{example}\n\n\\begin{solution}\n  As usual, we start with\n  \\begin{eqnarray*}\n    \\vect{u}_1 &=& \\vect{v}_1 = \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\end{mymatrix}.\n  \\end{eqnarray*}\n  Next, we calculate\n  \\begin{eqnarray*}\n    \\iprod{\\vect{u}_1,\\vect{v}_2} &=& \\vect{u}_1^TA\\vect{v}_2 = 2, \\\\\n    \\iprod{\\vect{u}_1,\\vect{u}_1} &=& \\vect{u}_1^TA\\vect{u}_1 = 1.\n  \\end{eqnarray*}\n  Therefore,\n  \\begin{eqnarray*}\n    \\vect{u}_2\n    &=& \\vect{v}_2\n        - \\frac{\\iprod{\\vect{u}_1,\\vect{v}_2}}{\\iprod{\\vect{u}_1,\\vect{u}_1}} \\vect{u}_1\n        = \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    - \\frac{2}{1} \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    = \\begin{mymatrix}{c} -2 \\\\ 1 \\\\ 0 \\end{mymatrix}.\n  \\end{eqnarray*}\n  Finally, we calculate\n  \\begin{eqnarray*}\n    \\iprod{\\vect{u}_1,\\vect{v}_3} &=& \\vect{u}_1^TA\\vect{v}_3 = -2, \\\\\n    \\iprod{\\vect{u}_2,\\vect{v}_3} &=& \\vect{u}_2^TA\\vect{v}_3 = 3, \\\\\n    \\iprod{\\vect{u}_2,\\vect{u}_2} &=& \\vect{u}_2^TA\\vect{u}_2 = 2.\n  \\end{eqnarray*}\n  Therefore,\n  \\begin{eqnarray*}\n    \\vect{u}_3\n    &=& \\vect{v}_3\n        - \\frac{\\iprod{\\vect{u}_1,\\vect{v}_3}}{\\iprod{\\vect{u}_1,\\vect{u}_1}} \\vect{u}_1\n        - \\frac{\\iprod{\\vect{u}_2,\\vect{v}_3}}{\\iprod{\\vect{u}_2,\\vect{u}_2}} \\vect{u}_2\n        = \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    - \\frac{-2}{1} \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    - \\frac{3}{2} \\begin{mymatrix}{c} -2 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 5 \\\\ -3/2 \\\\ 1 \\end{mymatrix}.\n  \\end{eqnarray*}\n  So the desired orthogonal basis is\n  \\begin{equation*}\n    \\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3}\n    = \\set{\n      \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{c} -2 \\\\ 1 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{c} 5 \\\\ -3/2 \\\\ 1 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  Note that it is not orthogonal with respect to the dot product, but\n  with respect to the inner product defined above.\n\\end{solution}\n\n\\begin{example}{Legendre polynomials}{legendre-polynomials}\n  Consider the vector space $\\Poly$ of polynomials, with the inner product\n  \\begin{equation*}\n    \\iprod{p,q} = \\int_{-1}^{1} p(x)q(x)\\,dx.\n  \\end{equation*}\n  Use the Gram-Schmidt procedure to find an orthogonal basis for\n  $\\sspan\\set{1,x,x^2,x^3}$.%\n  \\index{Legendre polynomial}%\n  \\index{polynomial!Legendre polynomial}\n\\end{example}\n\n\\begin{solution}\n  Let $\\vect{v}_1=1$, $\\vect{v}_2=x$, $\\vect{v}_3=x^2$, and\n  $\\vect{v}_4=x^3$. We follow the Gram-Schmidt procedure:\n  \\begin{eqnarray*}\n    \\vect{u}_1\n    &=& \\vect{v}_1\n        ~=~ 1.\n  \\end{eqnarray*}\n  Before we calculate $\\vect{u}_2$, we have to evaluate two integrals:\n  \\begin{eqnarray*}\n    \\iprod{\\vect{u}_1,\\vect{v}_2}\n    &=& \\int_{-1}^{1} 1\\cdot x\\,dx\n    ~=~ \\bigbracket{\\textstyle\\frac{1}{2}x^2}_{-1}^{1}\n    ~=~ 0,\n    \\\\\n    \\iprod{\\vect{u}_1,\\vect{u}_1}\n    &=& \\int_{-1}^{1} 1\\cdot 1\\,dx\n    ~=~ \\bigbracket{x}_{-1}^{1}\n    ~=~ 2.\n  \\end{eqnarray*}\n  Then\n  \\begin{eqnarray*}\n    \\vect{u}_2\n    &=& \\vect{v}_2 ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_2}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1\n    ~=~ x ~-~ \\frac{0}{2}\\cdot 1 ~=~ x.\n  \\end{eqnarray*}\n  To calculate $\\vect{u}_2$, we first evaluate three integrals:\n  \\begin{eqnarray*}\n    \\iprod{\\vect{u}_1,\\vect{v}_3}\n    &=& \\int_{-1}^{1} 1\\cdot x^2\\,dx\n    ~=~ \\bigbracket{\\textstyle\\frac{1}{3}x^3}_{-1}^{1}\n    ~=~ \\frac{2}{3},\n    \\\\\n    \\iprod{\\vect{u}_2,\\vect{v}_3}\n    &=& \\int_{-1}^{1} x\\cdot x^2\\,dx\n    ~=~ \\bigbracket{\\textstyle\\frac{1}{4}x^4}_{-1}^{1}\n    ~=~ 0,\n    \\\\\n    \\iprod{\\vect{u}_2,\\vect{u}_2}\n    &=& \\int_{-1}^{1} x\\cdot x\\,dx\n    ~=~ \\bigbracket{\\textstyle\\frac{1}{3}x^3}_{-1}^{1}\n    ~=~ \\frac{2}{3}.\n  \\end{eqnarray*}\n  Then\n  \\begin{eqnarray*}\n    \\vect{u}_3\n    &=& \\vect{v}_3\n        ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_3}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1\n        ~-~ \\frac{\\iprod{\\vect{u}_2,\\vect{v}_3}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\vect{u}_2\n        ~=~ x^2 ~-~ \\frac{2/3}{2}\\cdot 1 ~-~ 0\\cdot x\n        ~=~ x^2 - \\frac{1}{3}.\n  \\end{eqnarray*}\n  To calculate $\\vect{u}_3$, we first evaluate four integrals:\n  \\begin{eqnarray*}\n    \\iprod{\\vect{u}_1,\\vect{v}_4}\n    &=& \\int_{-1}^{1} 1\\cdot x^3\\,dx\n    ~=~ \\bigbracket{\\textstyle\\frac{1}{4}x^4}_{-1}^{1}\n    ~=~ 0,\n    \\\\\n    \\iprod{\\vect{u}_2,\\vect{v}_4}\n    &=& \\int_{-1}^{1} x\\cdot x^3\\,dx\n    ~=~ \\bigbracket{\\textstyle\\frac{1}{5}x^5}_{-1}^{1}\n    ~=~ \\frac{2}{5},\n    \\\\\n    \\iprod{\\vect{u}_3,\\vect{v}_4}\n    &=& \\int_{-1}^{1}\\textstyle (x^2-\\frac{1}{3})\\cdot x^3\\,dx\n    ~=~ \\bigbracket{\\textstyle\\frac{1}{6}x^6 - \\frac{1}{12}x^4}_{-1}^{1}\n    ~=~ 0,\n    \\\\\n    \\iprod{\\vect{u}_3,\\vect{u}_3}\n    &=& \\int_{-1}^{1}\\textstyle (x^2-\\frac{1}{3})^2\\,dx\n    ~=~ \\bigbracket{\\textstyle\\frac{1}{5}x^5-\\frac{2}{9}x^3+\\frac{1}{9}x}_{-1}^{1}\n    ~=~ \\frac{8}{45}.\n  \\end{eqnarray*}\n  Then\n  \\begin{eqnarray*}\n    \\vect{u}_4\n    &=& \\vect{v}_4\n        ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_4}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1\n        ~-~ \\frac{\\iprod{\\vect{u}_2,\\vect{v}_4}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\vect{u}_2\n        ~-~ \\frac{\\iprod{\\vect{u}_3,\\vect{v}_4}}{\\iprod{\\vect{u}_3,\\vect{u}_3}}\\vect{u}_3\n    \\\\\n    &=& x^3 ~-~ \\frac{0}{2}\\cdot 1 ~-~ \\frac{2/5}{2/3}\\cdot x ~-~ \\frac{0}{8/45}\\cdot(x^2-\\frac{1}{3})\n        ~=~ x^3 - \\frac{3}{5}x.\n  \\end{eqnarray*}\n  Thus, we obtain the orthogonal basis $\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3,\\vect{u}_4} =\n  \\set{1,~ x,~ x^2-\\frac{1}{3},~ x^3 - \\frac{3}{5}x}$.\n\\end{solution}\n\nThe orthogonal polynomials from Example~\\ref{exa:legendre-polynomials}\nare known (up to scalar multiples) as \\textbf{Legendre polynomials}%\n\\index{Legendre polynomial}%\n\\index{polynomial!Legendre polynomial}.  We can continue in the same\nfashion applying the Gram-Schmidt procedure to the polynomials\n$1, x, x^2, x^3, x^4, x^5, x^6, \\ldots$ to get an infinite sequence of\northogonal polynomials. The first few elements of this sequence are:\n\\begin{eqnarray*}\n  p_0(x) &=& 1, \\\\\n  p_1(x) &=& x, \\\\\n  p_2(x) &=& x^2 - \\frac{1}{3}, \\\\\n  p_3(x) &=& x^3 - \\frac{3}{5}x, \\\\\n  p_4(x) &=& x^4 - \\frac{6}{7}x^2 + \\frac{3}{35}, \\\\\n  p_5(x) &=& x^5 - \\frac{10}{9}x^3 + \\frac{5}{21}x, \\\\\n  p_6(x) &=& x^6 - \\frac{15}{11}x^4 + \\frac{5}{11}x^2 - \\frac{5}{231}, \\\\\n  p_7(x) &=& x^7 - \\frac{21}{13}x^5 + \\frac{105}{143}x^3 - \\frac{35}{429}x, \\\\\n  p_8(x) &=& x^8 - \\frac{28}{15}x^6 + \\frac{14}{13}x^4 - \\frac{28}{143}x^2 + \\frac{7}{1287}.\n\\end{eqnarray*}\n\\begin{center}\n  \\begin{tikzpicture}[domain=1:-1, scale=4]\n    \\draw[thick,color=fourier1,samples=50] plot (\\x,{abs(\\x^6)-15/11*abs(\\x^4)+5/11*abs(\\x^2)-5/231}) node[left=2ex,color=fourier1t] {$x^6 - \\frac{15}{11}x^4 + \\frac{5}{11}x^2 - \\frac{5}{231}$};\n    \\draw[thick,color=fourier2,samples=50] plot (\\x,{\\x^5 - 10/9*\\x^3+5/21*\\x}) node[left=2ex,color=fourier2t] {$x^5 - \\frac{10}{9}x^3 + \\frac{5}{21}x$};\n    \\draw[thick,color=fourier3,samples=50] plot (\\x,{abs(\\x^4)-6/7*abs(\\x^2)+3/35}) node[left=2ex,color=fourier3t] {$x^4 - \\frac{6}{7}x^2 + \\frac{3}{35}$};\n    \\draw[thick,color=fourier4,samples=50] plot (\\x,\\x^3-3/5*\\x) node[left=2ex,color=fourier4t] {$x^3 - \\frac{3}{5}x$};\n    \\draw[thick,color=fourier5,samples=50] plot (\\x,{abs(\\x^2)-1/3}) node[left=2ex,,color=fourier5t] {$x^2-\\frac{1}{3}$};\n    \\draw[thick,color=fourier6] plot (\\x,\\x) node[left=2ex,color=fourier6t] {$x$};\n    \\draw[thick,color=fourier7] plot (\\x,1) node[left=2ex,color=fourier7t] {$1$};\n    \\draw[->] (-1.2,0) -- (1.2,0) node[right] {$x$};\n    \\draw[->] (0,-1.2) -- (0,1.2) node[above] {$p(x)$};\n    \\draw (1,0) -- (1,-0.05) node[below] {$1$};\n    \\draw (-1,0) -- (-1,-0.05) node[below] {$-1$};\n  \\end{tikzpicture}\n\\end{center}\n\nThe Gram-Schmidt procedure yields an {\\em orthogonal} basis. If we\nwant to compute an {\\em orthonormal} basis, we also have to normalize\neach basis vector. Since normalization usually involves dividing by a\nsquare root, it is best to do this at the end, i.e., after the entire\nGram-Schmidt procedure is complete, rather than normalizing each\n$\\vect{u}_i$ immediately after it is found. Note that the Gram-Schmidt\nprocedure itself does not involve computing any square roots.\n\n\\begin{example}{Finding an orthonormal basis}{finding-orthonormal-basis-r4}\n  In $\\R^4$, find an orthogonal basis for\n  \\begin{equation*}\n    \\sspan\\set{\n      \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 0 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    }.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  In Example~\\ref{exa:gram-schmidt-r4}, we already found an orthogonal basis\n  \\begin{equation*}\n    \\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3} ~=~\n    \\set{\n      \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 1/4 \\\\ 1/4 \\\\ 1/4 \\\\ -3/4 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 1/3 \\\\ 1/3 \\\\ -2/3 \\\\ 0 \\end{mymatrix}\n    }\n  \\end{equation*}\n  for this space. So all that is left to do is to normalize each\n  vector. The orthonormal basis is\n  \\begin{equation*}\n    \\set{\n      \\frac{\\vect{u}_1}{\\norm{\\vect{u}_1}},\n      \\frac{\\vect{u}_2}{\\norm{\\vect{u}_2}},\n      \\frac{\\vect{u}_3}{\\norm{\\vect{u}_3}}\n    }\n    ~=~\n    \\set{\n      \\frac{1}{2}\\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix},~\n      \\frac{2}{\\sqrt{3}}\\begin{mymatrix}{c} 1/4 \\\\ 1/4 \\\\ 1/4 \\\\ -3/4 \\end{mymatrix},~\n      \\frac{\\sqrt{3}}{\\sqrt{2}}\\begin{mymatrix}{c} 1/3 \\\\ 1/3 \\\\ -2/3 \\\\ 0 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  Alternatively, we could have also normalized the orthogonal basis we\n  found in Example~\\ref{exa:gram-schmidt-r4-b}. In that case, we\n  obtain the orthonormal basis\n  \\begin{equation*}\n    \\set{\n      \\frac{1}{\\sqrt{2}}\n      \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    }.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Orthonormal basis of polynomials}{legendre-polynomials2}\n  Find an orthonormal basis for the space of\n  Example~\\ref{exa:legendre-polynomials}.\n\\end{example}\n\n\\begin{solution}\n  In Example~\\ref{exa:legendre-polynomials}, we found the orthogonal\n  basis\n  $\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3,\\vect{u}_4} = \\set{1,~ x,~\n    x^2-\\frac{1}{3},~ x^3 - \\frac{3}{5}x}$.  We also computed\n  \\begin{equation*}\n    \\iprod{\\vect{u}_1,\\vect{u}_1} = 2,\\quad\n    \\iprod{\\vect{u}_2,\\vect{u}_2} = \\frac{2}{3},\\quad\\mbox{and}\\quad\n    \\iprod{\\vect{u}_3,\\vect{u}_3} = \\frac{8}{45}.\n  \\end{equation*}\n  We also need to compute $\\iprod{\\vect{u}_4,\\vect{u}_4}$:\n  \\begin{equation*}\n    \\iprod{\\vect{u}_4,\\vect{u}_4}\n    ~=~ \\int_{-1}^{1}{\\textstyle (x^3 - \\frac{3}{5}x)^2}\\,dx\n    ~=~ \\int_{-1}^{1}{\\textstyle x^6 - \\frac{6}{5}x^4 + \\frac{9}{25}x^2}\\,dx\n    ~=~ \\bigbracket{\\textstyle\\frac{1}{7}x^7-\\frac{6}{25}x^5+\\frac{3}{25}x^3}_{-1}^{1}\n    ~=~ \\frac{8}{175}.\n  \\end{equation*}\n  Therefore, the orthonormal basis is:\n  \\begin{equation*}\n    \\set{\n      \\frac{\\vect{u}_1}{\\norm{\\vect{u}_1}},\n      \\frac{\\vect{u}_2}{\\norm{\\vect{u}_2}},\n      \\frac{\\vect{u}_3}{\\norm{\\vect{u}_3}},\n      \\frac{\\vect{u}_4}{\\norm{\\vect{u}_4}}\n    }\n    = \\set{\n      \\frac{1}{\\sqrt{2}},~\n      \\sqrt{\\frac{3}{2}} x,~\n      \\sqrt{\\frac{45}{8}} (x^2-\\frac{1}{3}),~\n      \\sqrt{\\frac{175}{8}} (x^3 - \\frac{3}{5}x)\n    }.\n  \\end{equation*}\n\\end{solution}\n\nWe finish this section by remarking that the formula\n\\begin{equation*}\n  \\frac{\\iprod{\\vect{u},\\vect{v}}}{\\iprod{\\vect{u},\\vect{u}}}\\vect{u}\n\\end{equation*}\nis exactly what we called the \\textbf{projection of $\\vect{v}$ onto\n  $\\vect{u}$}%\n\\index{vector!projection of}%\n\\index{projection!in inner product space}%\n\\index{projection!vector to vector} in Section~\\ref{ssec:projections},\nexcept that we have generalized this concept from $\\R^n$ to an\narbitrary inner product space. We can define\n\\begin{equation*}\n  \\proj_{\\vect{u}}(\\vect{v})\n  = \\frac{\\iprod{\\vect{u},\\vect{v}}}{\\iprod{\\vect{u},\\vect{u}}}\\vect{u}.\n\\end{equation*}\nWith this definition, the Gram-Schmidt procedure can also be expressed\nmore succinctly as follows.\n\\begin{equation*}\n  \\begin{array}{rcl}\n    \\vect{u}_1\n    &=& \\vect{v}_1,\n    \\\\\n    \\vect{u}_2\n    &=& \\vect{v}_2\n        ~-~ \\proj_{\\vect{u}_1}(\\vect{v}_2),\n    \\\\\n    \\vect{u}_3\n    &=& \\vect{v}_3\n        ~-~ \\proj_{\\vect{u}_1}(\\vect{v}_3)\n        ~-~ \\proj_{\\vect{u}_2}(\\vect{v}_3),\n    \\\\\n    &\\vdots&\n    \\\\\n    \\vect{u}_k\n    &=& \\vect{v}_k\n        ~-~ \\proj_{\\vect{u}_1}(\\vect{v}_k)\n        ~-~ \\proj_{\\vect{u}_2}(\\vect{v}_k)\n        ~-~ \\ldots\n        ~-~ \\proj_{\\vect{u}_{k-1}}(\\vect{v}_k).\n  \\end{array}\n\\end{equation*}\n\n", "meta": {"hexsha": "bfa31ee4848811e94d23aeb0c06c55f4af9625ee", "size": 25006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/InnerProductSpaces-GramSchmidt.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/InnerProductSpaces-GramSchmidt.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/InnerProductSpaces-GramSchmidt.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 39.945686901, "max_line_length": 194, "alphanum_fraction": 0.5835799408, "num_tokens": 10708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.9099070048165069, "lm_q1q2_score": 0.7072705885257498}}
{"text": "\\lab{Applications}{Voronoi Diagrams and Delaunay Triangulations}{Voronoi Diagrams and Delaunay Triangulations}\n\\label{lab:voronoi}\n\n\\objective{Introduce Voronoid Diagrams and Delaunay Triangulations and discuss their applications}\n\n\\section*{Voronoi Diagrams}\n\nIn this lab we will discuss some applications of Voronoi Diagrams.\nIn the abstract sense, a Voronoi diagram is a partition of a plane into regions that lie closest to different points.\nThe easiest way to understand this is to look at some examples.\nFigure \\ref{voronoi_ex_1} is a voronoi diagram generated from 100 random points with $x$ and $y$ values between 0 and 1.\nNotice how each point has a small  cell around it that is made up of the points that lie closest to it.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{voronoi_example_1.pdf}\n\\caption{A Voronoi diagram of the square $[0,1]\\times [0,1]$ for 100 randomly generated points.}\n\\label{voronoi_ex_1}\n\\end{figure}\n\nOne possible way to compute this sort of diagram would be by brute force, for example:\n\\begin{lstlisting}\nimport numpy as np\nfrom numpy.random import rand\nfrom matplotlib imort pyplot as plt\nnum = 10\nres = 201\npts = rand(num, 2)\nX = np.linspace(0, 1, res)\nY = X.copy()\nX, Y = np.meshgrid(X, Y)\nZ = np.empty_like(X)\nindices = np.zeros_like(X)\nfor i in xrange(res):\n    for j in xrange(res):\n        #note: we don't need to do the sqare root\n        #since we really just need to compare the distances\n        mn = (X[i,j] - pts[0,0])**2 + (Y[i,j] - pts[0,1])**2\n        for k in xrange(1,num):\n            dist = (X[i,j] - pts[k,0])**2 + (Y[i,j] - pts[k,1])**2\n            if dist < mn:\n                indices[i,j] = k\n                mn = dist\nplt.pcolormesh(X,Y,indices)\nplt.scatter(pts[:,0],pts[:,1])\nplt.xlim((0,1))\nplt.ylim((0,1))\nplt.show()\n\\end{lstlisting}\nThis algorithm is good because it can work regardless of the metric space we are using, but it is terribly slow.\nFigure \\ref{voronoi_1norm} shows a similar diagram using the 1-norm and figure \\ref{voronoi_supnorm} shows a diagram generated using the supremum norm.\nIt is linear in the number of points added and linear in the number of pixels used to represent the diagram.\nThis can be a terrible limitation, but if you are not working in a well behaved metric space, this may be the simplest approach.\n\\begin{figure}\n\\begin{minipage}[b]{0.45\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{voronoi_1norm.png}\n\\caption{Voronoi diagram in the 1-norm}\n\\label{voronoi_1norm}\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.45\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{voronoi_supnorm.png}\n\\caption{Voronoi diagram in the supremum norm}\n\\label{voronoi_supnorm}\n\\end{minipage}\n\\end{figure}\n\nIt is also possible to make voronoi diagrams based off of shapes and lines as well as points. \n\nThere are several data structures used in the field of computational geometry that can store the exact edges of diagrams like this.\nWe would prefer to not have to worry about sampling the domain in this way.\nThere are a variety of algorithms that can compute Voronoi diagrams in $\\mathcal{O}\\left( n \\log\\left(n\\right)\\right)$ time (where $n$ is the number of points).\nFortune's algorithm is a linesweep algorithm that can do this.\n\nThe Qhull library is commonly used to compute voronoi diagrams, and delaunay triangulations.\nSciPy includes a wrapper of the Qhull library in the \\li{scipy.spatial} module.\nIt currently only supports 2 dimensional voronoi diagrams under the Euclidean norm.\nIt allows you to generate a voronoi diagram from a set of points, add points to a voronoi diagram, find the nearest point to any given point, and plot a voronoi diagram.\n\nA plot similar to the one we just generated can be made using SciPy like this:\n\\begin{lstlisting}\nimport numpy as np\nfrom numpy.random import rand\nimport scipy.spatial as st\nfrom matplotlib import pyplot as plt\nG = rand(100,2)\nG = st.Voronoi(G)\nst.voronoi_plot_2d(G)\nplt.xlim((0, 1))\nplt.ylim((0, 1))\nplt.show()\n\\end{lstlisting}\nNotice how much clearer the plot is and how much faster it is generated.\nTry running the last bit of code for 1000 points.\nThough this is a little slower than it was for 10 points, this is a graph that would not display well if we had been using the brute force method.\n\nTable \\ref{voronoi_attributes} shows the different attributes of the \\li{Voronoi} object.\nFor more details, see \\url{http://docs.scipy.org/doc/scipy-dev/reference/spatial.html}\n\\begin{table}[h!]\n\\begin{center}\n\t\\begin{tabular}{|l|p{12cm}|}\n    \\hline\n\n    \\li{points} & coordinates of input points (centers of cells)\\\\\n\n    \\li{vertices} & vertices of graph\\\\\n\n    \\li{ridge_points} & indices of the input points between which each ridge on the diagram lies\\\\\n\n    \\li{ridge_vertices} & indices of the vertices at the end of each ridge\\\\\n\n    \\li{regions} & indices of the vertices corresponding to each voronoi cell\\\\\n\n    \\li{point_region} & indices of the regions corresponding to each input point\\\\\n\n    \\hline\n\n    \\end{tabular}\n\\end{center}\n\\caption{Various summarizing functions}\n\\label{voronoi_attributes}\n\\end{table}\n\nUnfortunately, the \\li{Voronoi} objects do not allow us to find out, given the coordinates of a new point, which of our original input points lies the closest to it.\nTo do something like that we would need to use a different algorithm or data structure.\nOne possible way of solving such a problem is to us a KD tree.\nKD trees will be discussed in further detail in Volume II.\nScipy includes built in KD trees in both Python and C.\nThe version in C is generally faster.\nYou can make a KD tree like this\n\\begin{lstlisting}\nimport numpy as np\nfrom numpy.random import rand\nimport scipy.spatial as st\nA = rand(1000,2)\nkd = st.cKDTree(A)\n\\end{lstlisting}\nIn this case we used the \\li{cKDTree} object.\nThat is a KDTree implemented in C.\n\\li{KDTree} is a Python-based version that is also included in scipy.\nTo find the nearest neighbor of a point \\li{pt} and how far away it is we can now use the following line of code:\n\\begin{lstlisting}\nkd.query(pt)\n\\end{lstlisting}\n\n\\section*{Applications of Voronoi Diagrams}\n\nThough the computation of a Voronoi Diagram does not provide a quick way to run nearest neighbor queries, there are still several applications for Voronoi Diagrams.\nThe first, and probably most obvious, is the representation of data.\nIf you want to look for visual patterns in data, a Voronoi Diagram can be very useful.\nOne historically significant example was the containment of the London Cholera outbreak of 1854.\nThe English Mathematician John Snow plotted where the cholera outbreaks had all happened and after some consideration, noticed that they were all relatively close to a certain water pump in that portion of the city.\nUpon noticing this, he plotted the voronoi cell of that particular water pump and proposed that the cholera outbreak was linked to contaminated water.\nHe recommended that the pump handle be removed so that people would have to use other pumps in the city.\nOnce the contaminated pump was shut down, the cholera outbreak was stopped.\n\nVoronoi diagrams can also be used to solve problems involving the points furthest from those already on the graph.\nExamples include determining where to drill next when searching for oil, or where to put a new branch of a major company.\n\nThe file \\li{edge_intersections.py} included with this lab includes a helper function, \\li{edge_intersections}, that will be helpful for the rest of the lab.\nIt takes a Voronoi diagram object as input as well as two tuples (xlims and ylims) representing the limits of a rectangle.\nIt returns an array containing the intersections of the edges of the voronoi diagram.\nIt also returns two lists of pairs of indices.\nIn the first list of indices, the first index in each pair corresponds to one of the vertices of the Voronoi diagram and the second index corresponds to one of the intersections found by this function.\nThe second list of indices accounts for the case that no endpoint of an edge intersecting the region lies within the region.\nIn the second list of indices, both indices of each pair correspond to intersections with the boundaries of the region.\n\n\\begin{problem}\n\\label{FurthestPoints}\nWrite a function that, given a list of points and a rectangular region of the plain and an integer $n$, finds the $n$ points in the region that lie farthest from all the points already given.\nUse the helper function given to test the intersections of the edges of the voronoi diagram with the intersections of the rectangular region.\n\\end{problem}\n\nAnother possible application is navegation through a field of obstacles.\n\n\\begin{problem}\nWrite a function that, given a list of points, forms the adjacency matrix corresponding to the connections between each node of the Voronoi diagram.\nHave this function take a threshold value to limit which ridges are included.\nDo not include a ridge in the adjacency matrix if the distance from the ridge to the center points of the Voronoi cells is less than the threshold.\nYou can find this distance by measuring the distance between each pair of points referenced in the \\li{ridge_points} attribute of the Voronoi object and then dividing by two.\nNote: the infinite ridges of the graph have $-1$ listed as one of the indices in the \\li{ridge_vertices} attribute.\nMake sure you do not include these ridges.\n\nUse your solution to Lab \\ref{lab:MarkovGraph} Problem \\ref{maze_prob} to find a path from any given node to any other node.\nWrite another function that plots the Voronoi diagram and the path between any two given nodes.\n\nNote: if you have a working implementation of Djikstra's algorithm, you may use it and use the graph weights corresponding to the distance between nodes instead.\nUsing a modified version of Djikstra's Algorithm you could maximize the distance from any node to the path, but we won't ask you to do that here.\nA fuller solution of this problem would also account for the bounds of the region.\nThat could be done with the helper function included with this lab.\n\\end{problem}\n\nAnother possible application of voronoi diagrams is in the estimation of total rainfall, size of ore deposits, or other similar problems.\nOne simple way to do this is to take a weighted average of all known measurements where each measurement is given the weight corresponding to the size of its voronoi cell.\n\n\\begin{comment}\n% This problem is cool, but it would probably make the lab too long\n% I'll leave it here in case we want to add it later\n\n\\begin{problem}\n\\label{AverageRainfall}\nWrite a function that, given a square region and measurement values at different nodes, computes the weighted average of the measurements over the region.\nWeight each measurement according to the area of the voronoi cell of each node.\n\nHint: You can find the area of each voroni cell by considering the triangles formed between its vertices and its center point. One way to compute the area of a triangle given the coordinates of its vertices is $A = \\sqrt{s\\left(s-a\\right) \\left(s-b\\right) \\left(s-c\\right)}$ where $s = \\frac{a+b+c}{2}$ and $a$, $b$, and $c$ are the lengths of the edges of the triangle.\nThis is known as Herron's Formula.\n\\end{problem}\n\n\\end{comment}\n\n\\section*{Delaunay Triangulation}\n\nA concept related to Voronoi diagrams is that of the Delaunay Triangulation.\nDelaunay Triangulations also have a wide variety of applications.\nOne such application is the automatic division of a region into triangles for use in finite element analysis for the numerical solution of partial differential equations.\nIn general, the delaunay triangulation divides the smallest convex region containing all the given points (the convex hull) into triangles that obey certain rules.\n\nYou can make a Delaunay Triangulation from a list of points and plot it like this:\n\\begin{lstlisting}\nA = rand(100, 2)\nD = st.Delaunay(A)\nplt.triplot(A[:,0] ,A[:,1], D.simplices)\nplt.show()\n\\end{lstlisting}\n\n\\begin{problem}\nUse a Delaunay triangulation to write a function that breaks up the unit square into right triangles.\nHave the only argument to your function be the number of nodes you want along each edge of the square.\nPlot your results.\n\\end{problem}\n\n%other possible applications:\n%Use Delaunay Triangulation to tesselate a 3d surface.\n%Use tesselation to rerun ore/rainfall problem and compare results.", "meta": {"hexsha": "ade42546d0c795770a9af3a016105e21e27abda9", "size": 12354, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/voronoi/voronoi.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/voronoi/voronoi.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/voronoi/voronoi.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.570212766, "max_line_length": 370, "alphanum_fraction": 0.7740003238, "num_tokens": 3043, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619306896955, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7071971509218784}}
{"text": "\\input{../../assignment-header}\n\n%========================================================================\n\\title{Assignment 2:  Simulation Basics}\n\\date{Assigned:  Jan. 23  ---  Due:  Feb. 1}\n\\author{Optimal Control For Robotics}\n%========================================================================\n\\begin{document}\n\\maketitle\n%=================================================\n\n\\section*{Introduction}\\\n\nIn this assignment you will implement Euler's method and\nuse it to simulate two simple dynamical systems.\nThe first system is an ideal passive pendulum,\none of the simplest non-linear systems that corresponds to a physical mechanism.\nThe second system is the Lorenz system,\nwhich is highly non-linear and generates the famous Lorenz Attractor.\n\n\\par This assignment includes a set of template files to guide you in writing the\nsimulation function, dynamics functions, and top-level code to generate the plots.\n\\vspace{-0.6em} \\begin{itemize}  \\setlength\\itemsep{0em}\n  \\item \\texttt{EulerMethodSimulate.m} --- simulate a dynamical system using Euler's method\n  \\item \\texttt{PendulumDynamics.m} --- compute the system dynamics for a simple pendulum\n  \\item \\texttt{LorenzDynamics.m} --- compute the system dynamics for the Lorenz system\n  \\item \\texttt{prob\\_03\\_studentName.m} --- run the simulation of the pendulum and make plots\n  \\item \\texttt{prob\\_04\\_studentName.m} --- run the simulation of the Lorenz system and make plots\n\\end{itemize}\n\nYou will need to complete each of these files by replacing the \\texttt{\\%\\%\\%\\% TODO} markings with\ncorrect implementations in each case. There are detailed comments throughout the template code\nto indicate what each section of the code should do. The template files are described in\ndetail at the end of this assignment, and included as stand-alone Matlab files as well.\n\n\\section*{Write-Up}\n\nYou will submit a single (short) write-up for this assignment:\n\\vspace{-0.0em} \\begin{itemize}  \\setlength\\itemsep{0em} \\setlength\\itemindent{18pt}\n  \\item Header: full name, studentName, date, assignment name and number\n  \\item List any other students that you worked with.\n  \\item How long did this assignment take you?\n\\end{itemize}\n\n\\section*{Deliverables}\n\\begin{itemize}\n  \\item Fully implement all five template files and submit them.\n  \\item Submit the plots that you generated for each simulation: \\\\\n        \\texttt{prob\\_03\\_studentName.pdf}   and   \\texttt{prob\\_04\\_studentName.pdf}\n  \\item Submit the write-up for the assignment:   \\texttt{hw\\_02\\_studentName.txt}\n  \\item All code should be clearly written and well documented. Figures should include labels and titles.\n  \\item All files should besubmitted through Tufts Trunk (as a single compressed file)\n\\end{itemize}\n\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\\pagebreak\n\\section*{\\texttt{EulerMethodSimulation.m}}\n\nThe key line that you will write in this file will implement Euler's Method for integration,\ngiven below, where $\\bm{z}_k$ is the state at the current time step, $\\bm{z}_{k+1}$ is the state\nat the next time step, $h$ is the duration of the time step, and $\\dot{\\bm{z}}_k$ is the time-derivative\nof the state at the current time step.\nNotice that this function is general-purpose: it can be used to simulate any dynamical system.\n\n\\begin{equation}\n  \\bm{z}_{k+1} = \\bm{z}_k + h \\dot{\\bm{z}}_k\n\\end{equation}\n\n\\lstinputlisting{EulerMethodSimulation.m}\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\\pagebreak\n\\section*{\\texttt{PendulumDynamics.m}}\n\nThe dynamics of a simple pendulum can be modeled as:\n\n\\begin{equation}\n  \\ddot{q} = -\\sin(q)\n\\end{equation}\n\nEuler's Method for simulation, like most simulation methods, requires the dynamical system to be\nin first-order form. To to this, we will introduce a new variable $\\omega = \\dot{q}$ to represent\nangular rate. This allows us to write a second-order equation as a system of two first-order equations:\n\n\\begin{align}\n  &  \\dot{q} = \\omega \\\\\n  &  \\dot{\\omega} = -\\sin(q)\n\\end{align}\n\nYou will notice a tilde (\\texttt{\\~}) in the argument list for this function.\nThis tells Matlab that our function does not use this argument\nand allows it the compiler to do some optimization to improve run-time speed.\nWe keep the argument here beause simulation functions\n(such as \\texttt{EulerMethodSimulate()} and \\texttt{ode45()})\noften require the first argument of the dynamics function to be time.\n\n\\lstinputlisting{PendulumDynamics.m}\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\\pagebreak\n\\section*{\\texttt{LorenzDynamics.m}}\n\nThis function implements the equations for the Lorenz system. For a special combination of\nparameters this system produces a famous fractal known as the Lorenz attractor.\nThe equations for this system are given below, where $x$, $y$, and $z$ are the state of the\nsystem, and $\\sigma=10$, $\\rho=29$, and $\\beta = 8/3$ are system parameters.\n\n\\begin{align}\n  &  \\dot{x} = \\sigma (y-x) \\\\\n  &  \\dot{y} = x (\\rho - z) - y \\\\\n  &  \\dot{z} = x y - \\beta z\n\\end{align}\n\n\\lstinputlisting{LorenzDynamics.m}\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\\pagebreak\n\\section*{\\texttt{prob\\_03\\_studentName.m}}\n\nThis function sets up and runs a simulation of the simple pendulum system and then generates a plot\nof the resulting simulation. Let's assume that the pendulum is using SI units.\nFollow the directions in the template code for simulation and plotting details.\nWhen you submit this file you should replace \\texttt{studentName} with your full name.\n\n\\lstinputlisting{prob_03_studentName.m}\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\\pagebreak\n\\section*{\\texttt{prob\\_04\\_studentName.m}}\n\nThis function sets up and runs a simulation of the Lorenz System and then generates a plot of the\nLorenz attractor. We will use dimensionless units.\nFollow the directions in the template code for simulation and plotting details.\n\n\\lstinputlisting{prob_04_studentName.m}\n\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%\n\\pagebreak\n\n%=================================================\n\\end{document}\n", "meta": {"hexsha": "db3017615b675235b88be14412b10aca79fe6dfb", "size": 6185, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "topics/02-simulation-basics/assignment/hw-02-simulation-basics.tex", "max_stars_repo_name": "ShaneRozenLevy/ME149_Spring2018", "max_stars_repo_head_hexsha": "0cd1960cd3699ef4f24f824c89b32a64c73b5b99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 45, "max_stars_repo_stars_event_min_datetime": "2018-01-10T15:55:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T22:54:58.000Z", "max_issues_repo_path": "topics/02-simulation-basics/assignment/hw-02-simulation-basics.tex", "max_issues_repo_name": "Boyang--Li/ME149_Spring2018", "max_issues_repo_head_hexsha": "333dcf4891ca05f007590f3a40f67ae46cf2cf6b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "topics/02-simulation-basics/assignment/hw-02-simulation-basics.tex", "max_forks_repo_name": "Boyang--Li/ME149_Spring2018", "max_forks_repo_head_hexsha": "333dcf4891ca05f007590f3a40f67ae46cf2cf6b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-02-24T00:15:06.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T14:08:38.000Z", "avg_line_length": 43.2517482517, "max_line_length": 105, "alphanum_fraction": 0.6719482619, "num_tokens": 1499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8244619263765706, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7071971487210654}}
{"text": "\\hypertarget{sorting-algorithms}{%\n\\section{Sorting Algorithms}\\label{sorting-algorithms}}\n\n\\begin{itemize}\n\\tightlist\n\\item\n  sorting can be \\textbf{comparison-based or non-comparison-based}\n\\item\n  the fundamental operation of comparison-based sorting is\n  compare-exchange\n\\item\n  the lower bound on any comparison-based sequential sorting of n\n  numbers is $\\mathcal{O}(n * log (n))$\n\\item\n  we focus here on comparison-based sorting algorithms\n\\end{itemize}\n\n\\hypertarget{compare-exchangesplit}{%\n\\subsection{Compare-Exchange/Split}\\label{compare-exchangesplit}}\n\n\\hypertarget{compare-exchange}{%\n\\subsubsection{Compare Exchange}\\label{compare-exchange}}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/compareExchange.png}\n\\caption{Compare Exchange process}\n\\end{figure}\n\n\\hypertarget{compare-split}{%\n\\subsubsection{Compare Split}\\label{compare-split}}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/comparesplit.png}\n\\caption{Compare Split process}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/comparesplitExample.png}\n\\caption{Compare Split example}\n\\end{figure}\n\n\\hypertarget{odd-even-transposition-sort}{%\n\\subsection{Odd-Even Transposition\nSort}\\label{odd-even-transposition-sort}}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.4\\textwidth]{figures/transpositionsort.png}\n\\caption{Odd-Even Transposition Sort}\n\\end{figure}\n\n\\hypertarget{parallel-shellsort}{%\n\\subsection{Parallel Shellsort}\\label{parallel-shellsort}}\n\n\\begin{itemize}\n\\tightlist\n\\item\n  let n be the number of elements to be sorted and p be the number of\n  processes\n\\item\n  during the first phase, processes that are far away from each other in\n  the array compare split their elements\n\\item\n  during the second phase, the algorithm switches to an odd-even\n  transposition sort with $2l \\leq p$ iterations\n\\end{itemize}\n\nIn phase 1:\n\n\\begin{itemize}\n\\tightlist\n\\item\n  initially, each process sorts its block of $n/p$ elements internally\n\\item\n  each process is now paired with its corresponding process in the\n  reverse order of the array: that is, process $P_i$ is paired with\n  process $P_{p-i-1}$, where $i < p/2$\n\\item\n  all pairs perform a compare-split operation\n\\item\n  the processes are split into two groups of size $p/2$ each and the phase\n  1 is repeated in each group until a group contains one process only\n\\end{itemize}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.35\\textwidth]{figures/parallelshellsort.png}\n\\caption{Parallel Shellsort}\n\\end{figure}\n\n\\begin{itemize}\n\\tightlist\n\\item\n  In the first phase, each process performs $d = log(p)$ compare-split\n  operations\n\\item\n  with $\\mathcal{O}(p)$ bisection width, each communication can be performed in time   $\\Theta(n/p)$ for a total time of $\\Theta ( \\frac{n * log (p)}{p})$\n\\item\n  in the second phase, l odd and l even iterations are performed, each\n  requiring time $\\Theta(n/p)$\n\\end{itemize}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.4\\textwidth]{figures/runtimeShellsort.png}\n\\caption{Parallel runtime of Shellsort}\n\\end{figure}\n\n\\clearpage\n\\hypertarget{sorting-networks}{%\n\\subsection{Sorting Networks}\\label{sorting-networks}}\n\n\\begin{itemize}\n\\tightlist\n\\item\n  a sorting network is a network of comparators designed specifically\n  for sorting\n\\item\n  a comparator is a device with\n\n  \\begin{itemize}\n  \\tightlist\n  \\item\n    2 inputs: $x$ and $y$\n  \\item\n    2 outputs: $x'$ and $y'$\n  \\end{itemize}\n\\item\n  an increasing comparator $\\oplus : x' = min\\{x,y\\} and y' = max\\{x,y\\}$\n\\item\n  a decreasing comparator $\\ominus : x' = max\\{x,y\\} and y' = min\\{x,y\\}$\n\\end{itemize}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.7\\textwidth]{figures/sortingNetwork.png}\n\\caption{Sorting Networks}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.7\\textwidth]{figures/sortingNetwork2.png}\n\\caption{Sorting Network Example}\n\\end{figure}\n\n\\clearpage\n\\hypertarget{bitonic-sort}{%\n\\subsection{Bitonic Sort}\\label{bitonic-sort}}\n\nA bitonic sequence has two tones (sequences), one increasing and one\ndecreasing or vice versa. Any cyclic rotation fo a bitonic sequence is\nalso bitonic (repeated sequence). E.g. \\{1,2,4,7,6,0\\} is bitonic or\n\\{8,9,2,1,0,4\\} is bitonic (because it's repeated).\n\nFor the bitonic sort, we\n\n\\begin{enumerate}\n\\def\\labelenumi{\\arabic{enumi}.}\n\\tightlist\n\\item\n  build a single bitonic sequence from the given unsorted sequence\n\\item\n  rearrange the bitonic sequence into a sorted sequence\n\\end{enumerate}\n\nParallel Runtime (p = n): a bitonic sorting network sorts n elements in\n$\\Theta(log^2 (n))$ time.\n\n\\hypertarget{bitonic-merge}{%\n\\subsubsection{Bitonic Merge}\\label{bitonic-merge}}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/bitonicSequenceTheory.png}\n\\caption{Theory Bitonic Merge}\n\\end{figure}\n\nIn other words: At the beginning, there is one big bitonic sequence. In\nsplitting this bitonic sequence into two, you have two new sequences\n(lower and upper sequence). If you repeate this splitting, you will have\na sorted sequence at the end.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/bitonic-merge.png}\n\\caption{Bitonic Merge}\n\\end{figure}\n\n\\clearpage\n\\hypertarget{building-a-bitonic-sequence}{%\n\\subsubsection{Building a Bitonic\nSequence}\\label{building-a-bitonic-sequence}}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.7\\textwidth]{figures/create-bitonic-sequence.png}\n\\caption{Creation of a bitonic sequence}\n\\end{figure}\n\n\\hypertarget{bitonic-sort-block-of-elements-per-process}{%\n\\subsubsection{Bitonic Sort: Block of Elements Per\nProcess}\\label{bitonic-sort-block-of-elements-per-process}}\n\nYou are also able to implement bitonic sort if there are less processes\nthan elements.\n\n\\begin{itemize}\n\\tightlist\n\\item\n  the first step is a local sort of the local block\n\\item\n  each subsequent compare-exchange operation is replaced by a\n  compare-split operation\n\\item\n  the bitonic network consists of $(1 + log (p))*\\frac{log (p)}{2} = \\mathcal{O}(log^2 (p))$\n  steps\n\\end{itemize}\n\n\\hypertarget{parallel-quicksort}{%\n\\subsection{Parallel Quicksort}\\label{parallel-quicksort}}\n\nThe following figure describes the serial sequence of the quick sort.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.7\\textwidth]{figures/quicksort-serial.png}\n\\caption{Quicksort in Serial}\n\\end{figure}\n\n\\clearpage\n\\hypertarget{recursive-decomposition}{%\n\\subsubsection{Recursive Decomposition}\\label{recursive-decomposition}}\n\n\\begin{itemize}\n\\tightlist\n\\item\n  the array is partitioned serially and each of the sub-problems is\n  handled by a different process\n\\item\n  the time for this algorithm is lower-bounded by $\\Omega(n)$, because of the serial partitioning\n\\end{itemize}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.7\\textwidth]{figures/quicksort-parallel.png}\n\\caption{Quicksort in parallel}\n\\end{figure}\n\n\\hypertarget{pram}{%\n\\subsubsection{PRAM}\\label{pram}}\n\nPRAM makes use of CRCW (concurrent read, concurrent write).\n\n\\begin{itemize}\n\\tightlist\n\\item\n  process $P_i$ is assigned element $A[i]$\n\\item\n  build binary tree\n\\item\n  traverse tree and count elements in left and right sub-trees and\n  compute correct element positions\n\\item\n  each process writes its element to the correct position in A\n\\end{itemize}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.4\\textwidth]{figures/quicksortPRAM.png}\n\\caption{Quicksort PRAM pseudo-code}\n\\end{figure}\n\n\\begin{itemize}\n\\tightlist\n\\item\n  The arbitrary choice of root (by concurrent write of all processes) is\n  the new pivot\n\\item\n  The root doesn't work anymore.\n\\item\n  All other processes save their value into the proper array of the\n  existing two halfs\n\\end{itemize}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.7\\textwidth]{figures/binarytreeQuicksortExample.png}\n\\caption{Quicksort Example Binary tree}\n\\end{figure}\n\n\\begin{itemize}\n\\tightlist\n\\item\n  As soon as the binary tree is created, the values need to be written\n  to the goal array\n\\item\n  Each node needs to know his final position in the goal array\n\\item\n  The position can be calculated from the left childs of the current\n  node\n\\item\n  The number of childs can be calculated recursively by asking his child\n  how many child it has (which asks his childs again\\ldots{})\n\\end{itemize}\n\n\\clearpage\n\\hypertarget{shared-address-space-sas-parallelizing-quicksort}{%\n\\subsubsection{Shared Address Space (SAS): Parallelizing\nQuicksort}\\label{shared-address-space-sas-parallelizing-quicksort}}\n\nConsider an array of size n equally divided across p processes.\n\n\\begin{itemize}\n\\tightlist\n\\item\n  Pivot Selection\n\n  \\begin{itemize}\n  \\tightlist\n  \\item\n    a pivot is selected by one of the processes and made known to all\n    processes\n  \\item\n    can be made local from one process\n  \\end{itemize}\n\\item\n  Local Rearrangement\n\n  \\begin{itemize}\n  \\tightlist\n  \\item\n    each process partitions its array block into two, say S\\_i and L\\_i\n    , based on the selected and communicated pivot\n  \\end{itemize}\n\\item\n  Global Rearrangement\n\n  \\begin{itemize}\n  \\tightlist\n  \\item\n    all of the S\\_i arrays are merged to S and all of the L\\_i arrays\n    are merged to L separately\n  \\end{itemize}\n\\item\n  Processor Partitioning\n\n  \\begin{itemize}\n  \\tightlist\n  \\item\n    the set of processes is partitioned into two (in proportion of the\n    size of arrays S and L)\n  \\end{itemize}\n\\item\n  the algorithm is recursively repeated for each process group and\n  sub-array, until a sub-array is assigned to a single process, in which\n  case it proceeds to sort it locally\n\\end{itemize}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/quicksortSASExample.png}\n\\caption{SAS Quicksort Example}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/sasQuicksortGlobalRearrangement.png}\n\\caption{SAS Quicksort Global Rearrangement}\n\\end{figure}\n\n\\hypertarget{bucket-sort}{%\n\\subsection{Bucket Sort}\\label{bucket-sort}}\n\nThe sequential bucket sort divides the values which need to be sorted\ninto different buckets. After that, one can sort the buckts itself.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/bucket-sort.png}\n\\caption{Bucketsort}\n\\end{figure}\n\n\\clearpage\n\\hypertarget{parallel-bucket-sort}{%\n\\subsubsection{Parallel Bucket Sort}\\label{parallel-bucket-sort}}\n\nThe pre-sorting into different buckets can also be done in parallel.\n\n\\begin{itemize}\n\\tightlist\n\\item\n  Input\n\n  \\begin{itemize}\n  \\tightlist\n  \\item\n    each process is assigned a block of $n/p$ elements\n  \\item\n    the number of buckets $m = p$\n  \\item\n    each process knows the range $[a, b]$\n  \\end{itemize}\n\\item\n  Algorithm\n\n  \\begin{itemize}\n  \\tightlist\n  \\item\n    each process partitions its block of $n/p$ elements into p sub-blocks, one for each of the $p$ buckets: $\\Theta(n/p)$\n  \\item\n    each process sends $p- 1$ sub-blocks to the appropriate processes\n    using a single all-to-all personalized communication: $\\Theta(p * n/p^2) = \\Theta(n/p)$\n  \\item\n    each process sorts all the elements it receives by using an optimal\n    sequential sorting algorithm: $\\Theta((n/p) * log (n/p))$\n  \\end{itemize}\n\\item\n  Parallel Runtime\n\n  \\begin{itemize}\n  \\tightlist\n  \\item\n    $T_P = \\Theta(n/p) + \\Theta(n/p) + \\Theta((n/p) *log (n/p)) = \\Theta((n/p) * log (n/p))$\n  \\end{itemize}\n\\end{itemize}\n\n\n\\clearpage\n\\hypertarget{sample-sort}{%\n\\subsection{Sample Sort}\\label{sample-sort}}\n\n\\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black]\nRandom Sampling: If I don't know the distribution of my data, I can take a random sequence of this data ond check the distribution of this sequence, with the assumption that it is the same as the rest of the data. \n\\end{tcolorbox}\n\n\\begin{itemize}\n\\tightlist\n\\item\n  Similar to Bucket Sort\n\n  \\begin{itemize}\n  \\tightlist\n  \\item\n    without the unrealistic assumption of uniformly distributed elements\n  \\item\n    a sample is selected from the n elements, and the range of the\n    buckets is determined by choosing m - 1 elements (splitters) from\n    the sample\n  \\end{itemize}\n\\item\n  Splitter Selection Method\n\n  \\begin{itemize}\n  \\tightlist\n  \\item\n    the n elements are divided into m blocks of size n/m each\n  \\item\n    each block is sorted by using an optimal sequential sorting\n    algorithm\n  \\item\n    from each sorted block m - 1 evenly spaced elements are chosen\n  \\item\n    the m(m - 1) elements selected from all the blocks represent the\n    sample used to determine the buckets\n  \\item\n    from the sorted sample choose m - 1 evenly spaced splitters\n  \\item\n    this scheme guarantees that the number of elements ending up in each\n    bucket is less than 2n/m if the elements don't contain duplicates\n  \\end{itemize}\n\\end{itemize}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/samplesort.png}\n\\caption{Samplesort}\n\\end{figure}\n\n\\clearpage\n\\hypertarget{parallel-sample-sort}{%\n\\subsubsection{Parallel Sample Sort}\\label{parallel-sample-sort}}\n\n\\begin{itemize}\n\\tightlist\n\\item\n  Parallelized Splitter Selection Scheme\n\n  \\begin{itemize}\n  \\tightlist\n  \\item\n    choose $m = p$\n  \\item\n    each processor generates the $p - 1$ local splitters in parallel\n  \\item\n    all processors share their splitters using a single all-to-all\n    broadcast operation\n  \\item\n    each processor sorts (merges) the same $p*(p- 1)$ sorted sample\n    elements it receives and selects the same $p - 1$ uniformly spaces\n    splitters from them\n  \\end{itemize}\n\\item\n  Parallel Algorithm\n\n  \\begin{itemize}\n  \\tightlist\n  \\item\n    each process partitions its block of $n/p$ elements into p sub-blocks\n    according to the $p - 1$ splitters, one for each of the p buckets\n  \\item\n    each process sends p sub-blocks to the appropriate processes (a\n    single all-to-all personalized communication is useful only if all\n    sub-blocks are of almost equal size)\n  \\item\n    each process merges all the received p sub-blocks\n  \\end{itemize}\n\\end{itemize}\n\n\\hypertarget{analysis-of-sample-sort}{%\n\\subsubsection{Analysis of Sample Sort}\\label{analysis-of-sample-sort}}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.85\\textwidth]{figures/analysis-samplesort.png}\n\\caption{Analysis of the sample-sort}\n\\end{figure}\n\n\\textbf{Total} $= \\mathcal{O}(\\frac{n}{p}*log(\\frac{n}{p}))+\\mathcal{O}(p^2 * log(p)) + \\mathcal{O}(p * log(\\frac{n}{p})) + \\mathcal{O}(\\frac{n}{p} * log(p))$ \\\\\n$= \\mathcal{O}(\\frac{n}{p}*log(n)) + \\mathcal{O}(p^2*log(p)) + \\mathcal{O}(p*log(\\frac{n}{p}))$\\\\ \\\\ \nDa gilt: $\\mathcal{O}(\\frac{n}{p}*log (\\frac{n}{p})) = \\mathcal{O}(\\frac{n}{p}*log(n) - \\frac{n}{p}*log(p))$", "meta": {"hexsha": "b0d0a34c0b267e9ca9cecea37d0061018b5aa351", "size": 14675, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TSM_ProgAlg/10_SortingAlgorithm.tex", "max_stars_repo_name": "nortismo/mse-documentations", "max_stars_repo_head_hexsha": "cc67637785237d630f077a863edcd5f49aa52b59", "max_stars_repo_licenses": ["Beerware"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "TSM_ProgAlg/10_SortingAlgorithm.tex", "max_issues_repo_name": "nortismo/mse-documentations", "max_issues_repo_head_hexsha": "cc67637785237d630f077a863edcd5f49aa52b59", "max_issues_repo_licenses": ["Beerware"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TSM_ProgAlg/10_SortingAlgorithm.tex", "max_forks_repo_name": "nortismo/mse-documentations", "max_forks_repo_head_hexsha": "cc67637785237d630f077a863edcd5f49aa52b59", "max_forks_repo_licenses": ["Beerware"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-15T07:10:24.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-15T07:10:24.000Z", "avg_line_length": 27.5328330206, "max_line_length": 214, "alphanum_fraction": 0.7448040886, "num_tokens": 4264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619091240701, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7071971339224207}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS622: Theory of Formal Languages\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 2}\n\nDefine the mapping $f:A^*\\rightarrow A^*$ by\n\n\\begin{equation}\\label{assum1}\nf(\\lambda)=\\lambda\n\\end{equation}\n\n\\begin{equation}\\label{assum2}\nf(ax)=xa\n\\end{equation}\n\nfor every $x \\in A^*$ and $a \\in A$.\nProve that $f$ is a \\textit{bijection}, that is, it is one-to-one and onto.\n\n\\subsection*{Solution}\n\nTo prove $f$ is a bijection, it is first proven that $f$ is one-to-one, using proof by contradiction.\nLet us assume that $f: A^* \\rightarrow A^*$ is not one-to-one, that is, there is at least an element $y$ in $A^*$ to which two different elements $u, v \\in A^*$, $u \\neq v$ are mapped by $f$.\nThat is following assumptions are made.\n\n\\begin{eqnarray}\nf(u) = y \\label{assum3} \\\\\nf(v) = y \\label{assum4} \\\\\nu \\neq v \\label{assum5}\n\\end{eqnarray}\n\nTwo possible cases on the nature of $y$ arise:\n\n\\begin{enumerate}[label=(\\alph*)]\n\n\\item\n$y = \\lambda$\n\nUsing assumption \\eqref{assum1},\n\n\\begin{equation}\\label{assum6}\ny=\\lambda=f(\\lambda)=f(y)\n\\end{equation}\n\nSubstituting \\eqref{assum6} in \\eqref{assum3} and \\eqref{assum4} gives\n\n\\begin{equation}\nf(u) = f(y) = f(v) \\Rightarrow u = v\n\\end{equation}\n\nwhich is in contrast to our assumption \\eqref{assum5}.\n\n\\item\n$y \\neq \\lambda$\n\nIn this case $y$ has at least one symbol and hence can be shown by $y=xa$ where $a \\in A$ and $x \\in A^*$.\n$u$ and $v$ must also have at least one symbol as, if otherwise, Based on \\eqref{assum1}, $f(\\lambda)$ would never be mapped to a symbol.\nThus $u$ and $v$ can be represented as $u = by$ and $v = cz$ where $\\{b,c\\}\\in A$ and $\\{y,z\\}\\in A^*$.\n\nFrom \\eqref{assum3} and \\eqref{assum4}:\n\\begin{eqnarray}\nf(u) = f(by) = y = xa \\label{2eq8}\\\\\nf(v) = f(cz) = y = xa \\label{2eq9}\n\\end{eqnarray}\n\nBased on \\eqref{assum2} following would also be true.\n\\begin{eqnarray}\nf(u) = f(by) = yb \\label{2eq10}\\\\\nf(v) = f(cz) = zc \\label{2eq11}\n\\end{eqnarray}\n\nFrom \\eqref{2eq8} and \\eqref{2eq10}\n\n\\begin{equation}\\label{2eq12}\nxa = yb\n\\end{equation}\n\nAnd from \\eqref{2eq9} and \\eqref{2eq11}\n\n\\begin{equation}\\label{2eq13}\nxa = zc\n\\end{equation}\n\nSince $a$, $b$ and $c$ are symbols, \\eqref{2eq12} and \\eqref{2eq13} can only happen if\n\n\\begin{eqnarray}\na = b = c & x = y = z\n\\end{eqnarray}\n\nThus\n\n\\begin{equation}\nby = cz \\Rightarrow u = v\n\\end{equation}\n\nwhich contradicts our earlier assumption \\eqref{assum5}.\n\n\\end{enumerate}\n\nBased on contradictions occurred in both possible cases, one-to-one property of $f:A^*\\rightarrow A^*$ holds true.\n\nA similar approach will be conducted to prove the onto property of $f:A^*\\rightarrow A^*$ mapping.\nBy proof of contradiction, it is assumed that $f$ is not onto; suggesting that there is at least one element $y$ in $A^*$ that is not mapped to by any element in $A^*$.\nTwo possible cases for $y$ would arise.\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item $y = \\lambda$\n\nBased on \\eqref{assum1}, there exists an element $\\lambda$ in $A^*$ that when mapped by $f$ is mapped to $y = \\lambda$.\n\\item $y \\neq \\lambda$\n\nIn this case $y$ has at least one symbol and hence can be shown by $y=xa$ where $a \\in A$ and $x \\in A^*$.\nBased on \\eqref{assum2} there is always an element $z \\in A^*$ where $z = ax$ and $f(z) = f(ax) = xa = y$.\n\n\\end{enumerate}\n\nAs both possible cases contradict with our earlier assumption that $y$ is not mapped to by any element in $A^*$, contradicted assumption is false and $f:A^*\\rightarrow A^*$ holds onto.\n", "meta": {"hexsha": "644cfe775775b35554c4edf05111633349926b6b", "size": 3725, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs622-2015f/src/tex/hw01/hw01q02.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs622-2015f/src/tex/hw01/hw01q02.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs622-2015f/src/tex/hw01/hw01q02.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 30.7851239669, "max_line_length": 191, "alphanum_fraction": 0.6595973154, "num_tokens": 1256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8887587839164801, "lm_q1q2_score": 0.7071481254254259}}
{"text": "\n\n\\subsection{Cournot model}\n\nWith competition, the elasticity of demand refers to the whole market, not just a single producer. Instead we have:\n\n\\(\\epsilon = \\dfrac{p}{Q}\\dfrac{\\delta Q}{\\delta p}\\)\n\n\\(Q=\\sum_j q_j\\)\n\nWe now get:\n\n\\(p[1+\\dfrac{q}{Q}\\dfrac{\\delta Q}{\\delta q}\\dfrac{Q}{p}\\dfrac{\\delta p}{\\delta Q}]=MC\\)\n\n\\(p[1+\\dfrac{\\mu }{\\epsilon }]=MC\\)\n\nUsing the firm's size elasticity: \\(\\mu = \\dfrac{q}{Q}\\dfrac{\\delta Q}{\\delta q}\\)\n\nWith monopoly this is:\n\n\\(\\mu = 1\\)\n\n\n\nIn this model this is:\n\n\\(\\dfrac{p-MC}{p}=-\\dfrac{\\mu}{\\epsilon }\\)\n\n", "meta": {"hexsha": "bb05b86ff1590b18eaab23073ada4cde71c3d5e5", "size": 552, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/econometricsAggregate/05-02-cournot.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/econometricsAggregate/05-02-cournot.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/econometricsAggregate/05-02-cournot.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.0344827586, "max_line_length": 115, "alphanum_fraction": 0.6286231884, "num_tokens": 198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7070932508202094}}
{"text": "\\section{Source Code}\n\n\nTo save pages, only codes that are relevant to the text are given below. I will upload all the codes to \\href{https://github.com/iChunyu/signal-process-demo}{my GitHub repository} after I get score of \\textsl{Digital Signal Processing} to avoid being judged cheating.\n\n\n\n\n\\subsection{LPSD Algorithm}\n\n\n{\\noindent \\bfseries Python Version}\n\n\n\\begin{lstlisting}[language=Python]\n'''\nPersonal fuction library in Python\nContents\n    (1) pxx,f = lpsd(data,fs,Jdes=1000)\n\nLast Update: 2021-02-10\n'''\n\n# %%\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n# %% function01: LPSD\n'''\nLPSD: Logarithmic frequency axis Power Spectral Density\npxx,f = lpsd(data,fs,Jdes=1000)\n   data --- Input data series, one dimension vector\n   fs   --- Sample frequency, unit: Hz\n   Jdes --- Desired frequency points, default: 1000\n   pxx  --- One-sided PSD, unit: *^2/Hz\n   f    --- Frequency points related to PSD points, unit: Hz\n   Default window function is hanning window.\n\nRef: Improved spectrum estimation from digitized timeseries on a logarithmic frequency axis\n     Article DOI: 10.1016/j.measurement.2005.10.010\n\nRemark: Unfamiliar with Python by now, the functiondoesn't support matrix data by now.\n    [MATLAB version supports matrix data.]\n\nXiaoCY 2021-02-10\n'''\n\n# subfuction\n# calculate frequency points\ndef getFreqs(N,fs,Jdes,Kdes,ksai):\n    fmin = fs/N\n    fmax = fs/2\n    r_avg = fs/N*(1+(1-ksai)*(Kdes-1))\n\n    g = (N/2)**(1/(Jdes-1))-1\n\n    f = np.zeros(Jdes)-1\n    L = np.copy(f)\n    m = np.copy(f)\n    j = 0\n    fj = fmin\n    while fj < fmax:\n        rj = fj*g\n        if rj < r_avg:\n            rj = np.sqrt(rj*r_avg)\n        if rj < fmin:\n            rj = fmin\n        \n        Lj = np.floor(fs/rj)\n        rj = fs/Lj\n        mj = fj/rj\n\n        f[j] = fj\n        L[j] = Lj\n        m[j] = mj\n\n        fj = fj+rj\n        j += 1\n    \n    idx = f<0\n    f = np.delete(f,idx)\n    L = np.delete(L,idx)\n    m = np.delete(m,idx)\n    return f,L,m\n\n# main\ndef lpsd(data,fs,Jdes=1000):\n    Kdes = 100\n    ksai = 0.5\n    N = len(data)\n\n    f,L,m = getFreqs(N,fs,Jdes,Kdes,ksai)\n\n    J = len(f)\n    pxx = np.zeros(J)\n    for j in range(J):\n        Dj = np.floor((1-ksai)*L[j])\n        Kj = np.floor((N-L[j])/Dj+1)\n        w = np.hanning(L[j])\n        C_PSD = 2/fs/np.dot(w,w)\n        l = np.arange(0,L[j])\n        W1 = np.cos(-2*np.pi*m[j]/L[j]*l)\n        W2 = np.sin(-2*np.pi*m[j]/L[j]*l)\n        A = 0.0\n        for k in range(int(Kj)):\n            G = data[int(k*Dj):int(k*Dj+L[j])].copy()\n            G = G-np.mean(G)\n            G = G*w\n            A += np.dot(G,W1)**2 + np.dot(G,W2)**2\n        pxx[j] = A/Kj*C_PSD\n\n    return pxx,f\n\nif __name__ =='__main__':\n    fs = 10\n    x = np.random.randn(1000)*np.sqrt(fs/2)\n    pxx,f = lpsd(x,fs)\n\n    plt.figure\n    plt.loglog(f,np.sqrt(pxx))\n    plt.grid()\n    plt.xlabel('Frequency (Hz)')\n    plt.ylabel(r'PSD ($\\rm*/\\sqrt{Hz}$)')\n\\end{lstlisting}\n\n\n{\\noindent \\bfseries MATLAB Version}\n\n\n\\begin{lstlisting}[language=Matlab]\n% Use LPSD mothod to plot power spectral density\n% [Pxx,f] = iLPSD(Data,fs,Jdes)\n%    Data --- Input data, processed by column\n%    fs   --- Sample frequency, unit: Hz\n%    Jdes --- Desired frequency points, default: 1000\n%    Pxx  --- One-sided PSD, unit: *^2/Hz\n%    f    --- Frequency points related to PSD points,unit: Hz\n%    Default window function is hanning window.\n% Demo:\n%    iLPSD(data,fs)\n%       Plot PSD using default settings.\n%    h = iLPSD(data,fs,Jdes)\n%       Plot PSD with desired points of 1000\n%    [Pxx,f] = iLPSD(data,fs)\n%       Return PSD points, not plot any figure\n\n% Ref: Improved spectrum estimation from digitizedtime series on a logarithmic frequency axis\n%      Article DOI: 10.1016/j.measurement.2005.10.010\n\n% XiaoCY 2020-04-21\n\n%% Main\nfunction varargout = iLPSD(varargin)\n    \n    nargoutchk(0,2);\n    narginchk(2,3);\n    \n    data = varargin{1};\n    fs = varargin{2};\n    if nargin == 3\n        Jdes = varargin{3};\n    else\n        Jdes = 1000;\n    end\n    \n    Kdes = 100;\n    ksai = 0.5;\n    \n    [N,nCol] = size(data);\n    if N==1 && nCol~=1\n       data = data';\n       N = nCol;\n       nCol = 1;\n    end\n    \n    [f,L,m] = getFreqs(N,fs,Jdes,Kdes,ksai);\n    \n    J = length(f);\n    P = zeros(J,nCol);\n    for j = 1:J\n        Dj = floor((1-ksai)*L(j));\n        Kj = floor((N-L(j))/Dj+1);\n        w = hann(L(j));\n        C_PSD = 2/fs/sum(w.^2);\n        l = (0:L(j)-1)';\n        W1 = cos(-2*pi*m(j)/L(j).*l);\n        W2 = sin(-2*pi*m(j)/L(j).*l);\n        A = zeros(1,nCol);\n        for k = 0:Kj-1\n            G = data(k*Dj+1:k*Dj+L(j),:);\n            G = G-mean(G);        % G = detrend(G);   \n            G = G.*w;\n            A = A + sum(G.*W1).^2+sum(G.*W2).^2;\n        end\n        P(j,:) = A/Kj*C_PSD;\n    end\n    \n    switch nargout\n        case 0\n            PlotPSD(P,f)\n        case 1\n            varargout{1} = PlotPSD(P,f);\n        case 2\n            varargout{1} = P;\n            varargout{2} = f;\n        otherwise\n            % Do Nothing\n    end\nend\n\n%% Subfunctions\n% get logarithmic frequency points\nfunction [f,L,m] = getFreqs(N,fs,Jdes,Kdes,ksai)\n    fmin = fs/N;\n    fmax = fs/2;\n    r_avg = fs/N*(1+(1-ksai)*(Kdes-1));\n    \n    g = (N/2)^(1/(Jdes-1))-1;\n    \n    f = zeros(Jdes,1)-1;\n    L = f;\n    m = f;\n    j = 1;\n    fj = fmin;\n    while fj < fmax\n        rj = fj*g;\n        if rj < r_avg\n            rj = sqrt(rj*r_avg);\n        end\n        if rj < fmin\n            rj = fmin;\n        end\n        \n        Lj = floor(fs/rj);\n        rj = fs/Lj;\n        mj = fj/rj;\n        \n        f(j) = fj;\n        L(j) = Lj;\n        m(j) = mj;\n        \n        fj = fj+rj;\n        j = j+1;\n    end\n    f(f<0) = [];\n    L(L<0) = [];\n    m(m<0) = [];\nend\n\n% plot PSD\nfunction varargout = PlotPSD(P,f)\n    hLine = loglog(f,sqrt(P));\n    grid on\n    xlabel('Frequency (Hz)')\n    ylabel('PSD ([Unit]/Hz^{1/2})')\n    \n    if nargout == 1\n        varargout{1} = hLine;\n    end\nend\n\\end{lstlisting}\n\n\n\n\n\n\\subsection{Main Code}\n\n\n{\\noindent \\bfseries Python Version}\n\n\n\\begin{lstlisting}[language=Python]\n'''\nMain code for DSP project\n(See ../DSP_Project_Reqirement&Guidance(2020 Fall).pdfProject-1 for detail.)\n\nXiaoCY 2021-02-18\n'''\n\n#%%\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport scipy.signal as signal\nimport springlib as sp\n\nsavepdf = False\nN = 1000\nfs = 1000.0\npi = np.pi\n\nt = np.arange(N)/fs\nx1 = np.cos(2*pi*50*t)\nx2 = 0.3*np.cos(2*pi*100*t + pi/3)\nx3 = 0.2*np.cos(2*pi*150*t - pi/3)\nx4 = 0.1*np.sin(2*pi*250*t)\nxn = 0.05*np.random.randn(N)\nx = x1+x2+x3+x4+xn\n\n#%% design IIR filter\nWp = 110./(fs/2)             # passband cornerfrequency (normalized)\nWs = 130./(fs/2)             # stopband cornerfrequency (normalized)\nRp = 1.                      # passband ripple (dB)\nRs = 60.                     # stopband attenuation(dB)\n\nNz,Wn = signal.cheb2ord(Wp,Ws,Rp,Rs)\nb,a = signal.cheby2(Nz,Rs,Wn)\n\nf = np.linspace(0,fs/2,500)\n_,g = signal.freqz(b,a,f,fs=fs)\ngdb = 20*np.log10(np.abs(g))\n\nplt.figure()\nplt.plot(f,gdb,label='Chebyshev Type II')\nplt.grid()\nplt.legend()\nplt.xlabel('Frequency (Hz)')\nplt.ylabel('Gain (dB)')\nplt.xlim(0,fs/2)\nif savepdf: \n    plt.savefig('prjFilter.pdf')\nplt.show()\n\n#%% filter data\ny = signal.filtfilt(b,a,x)\n\nplt.figure()\nplt.plot(t,x,label='original')\nplt.plot(t,y,label='filtered')\nplt.grid()\nplt.legend()\nplt.xlabel('Time (s)')\nplt.ylabel('Signal (A)')\nplt.xlim(0,0.2)\nif savepdf:\n    plt.savefig('prjSignal.pdf')\nplt.show()\n\n\npxx,fx = sp.lpsd(x,fs)\npyy,fy = sp.lpsd(y,fs)\n\nplt.figure()\nplt.semilogy(fx,np.sqrt(pxx),label='original')\nplt.semilogy(fy,np.sqrt(pyy),label='filtered')\nplt.grid()\nplt.legend()\nplt.xlabel('Frequency (Hz)')\nplt.ylabel(r'Signal ($\\rm A/\\sqrt{Hz}$)')\nplt.xlim(0,fs/2)\nif savepdf:\n    plt.savefig('prjPSD.pdf')\nplt.show()\n\\end{lstlisting}\n\n\n{\\noindent \\bfseries MATLAB Version}\n\n\n\\begin{lstlisting}[language=Matlab]\n% Main code for DSP project\n% (See ../DSP_Project_Reqirement&Guidance(2020 Fall).pdf Project-1 for detail.)\n\n% XiaoCY 2021-02-18\n\n%%\nclear;clc\n\nN = 1e3;\nfs = 1e3;\n\nt = (0:N-1)'/fs;\nx1 = cos(2*pi*50*t);\nx2 = 0.3*cos(2*pi*100*t + pi/3);\nx3 = 0.2*cos(2*pi*150*t - pi/3);\nx4 = 0.1*sin(2*pi*250*t);\nxn = 0.05*randn(N,1);\nx = x1+x2+x3+x4+xn;\n\n%%\nWp = 110/(fs/2);                % passband corner frequency (normalized)\nWs = 130/(fs/2);                % stopband corner frequency (normalized)\nRp = 1;                         % passband ripple (dB)\nRs = 60;                        % stopband attenuation (dB)\n\n[Nz,Wn] = cheb2ord(Wp,Ws,Rp,Rs);\n[b,a] = cheby2(Nz,Rs,Wn);\n\nf = linspace(0,fs/2,500);\ng = freqz(b,a,f,fs);\ngdb = 20*log10(abs(g));\n\nfigure('Name','filter')\nplot(f,gdb,'DisplayName','Chebyshev Type II')\ngrid on\nlegend\nxlabel('Frequency (Hz)')\nylabel('Gain (dB)')\n\n%%\ny = filtfilt(b,a,x);\n\nfigure('Name','time')\nplot(t,x,'DisplayName','original')\nhold on\ngrid on\nplot(t,y,'DisplayName','filtered')\nlegend\nxlabel('Time (s)')\nylabel('Signal (A)')\nxlim([0,0.1])\n\nfigure('Name','PSD')\n[pxx,f] = iLPSD([x,y],fs);\nsemilogy(f,sqrt(pxx))\ngrid on\nlegend('original','filtered')\nxlabel('Frequency (Hz)')\nylabel('PSD (A/Hz^{1/2})')\n\\end{lstlisting}", "meta": {"hexsha": "ec1a37c7da0c7b784a280da058a7df46f822d64a", "size": 9065, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "misc/homework/appendix.tex", "max_stars_repo_name": "iChunyu/signal-process-demo", "max_stars_repo_head_hexsha": "13cb094f0b4787df818dcac2bffbcb8928276f06", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-10-19T05:37:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T05:30:01.000Z", "max_issues_repo_path": "misc/homework/appendix.tex", "max_issues_repo_name": "iChunyu/signal-process-demo", "max_issues_repo_head_hexsha": "13cb094f0b4787df818dcac2bffbcb8928276f06", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-10-19T08:35:33.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-24T08:23:40.000Z", "max_forks_repo_path": "misc/homework/appendix.tex", "max_forks_repo_name": "iChunyu/signal-process-demo", "max_forks_repo_head_hexsha": "13cb094f0b4787df818dcac2bffbcb8928276f06", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.5833333333, "max_line_length": 267, "alphanum_fraction": 0.5627137341, "num_tokens": 3095, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7070191488211718}}
{"text": "\n\\subsection{Trend stationary}\n\nIf we can remove the trend as a function, eg linear or non-linear growth, and the rest is stationary, then the process is trend stationary\n\n", "meta": {"hexsha": "3766e5da2e37723335a5bfb87d4c20d25d7e699c", "size": 172, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/stochasticOrderIntegration/01-02-trendStationarity.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/stochasticOrderIntegration/01-02-trendStationarity.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/stochasticOrderIntegration/01-02-trendStationarity.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6666666667, "max_line_length": 138, "alphanum_fraction": 0.7848837209, "num_tokens": 37, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473746782092, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7070191442172524}}
{"text": "% !Mode:: \"TeX:UTF-8\"\n% !TEX program  = xelatex\n\\subsection{Computer Field}\nIn the field of computers, the summation formula for the geometric progression is quite important for reducing the computing complexity. For example, we can reduce the summation complexity of the arithmetic progression from $O(n)$ to $O(1)$, and the geometric progression from $O(n^2)$ to $O(n)$, which maximizes memory utilization. You may refer to appendix~\\ref{A:python-1} for more information. Here comes an example written in \\texttt{IPython}\\cite{PER-GRA:2007}:\n\\begin{pylist}{Comparison}\nbase = 2\nnumber = 1024\n\n%%timeit\ns = 0\nfor i in range(number):\n    s += base**i\n\n%%timeit\ns = sum(base**i for i in range(number))\n\n%%timeit\ns = base**number - 1\n\\end{pylist}\n\nThe running time of the first block is $656 \\mu s ± 10.4\\mu s$ per loop, the second block is $628 \\mu s ± 15.8 \\mu s$, and the third block is $765 ns ± 9.5 ns$ per loop. Obviously, the formula works efficiently.\n", "meta": {"hexsha": "bc8854f7fb0dd187b0c029024b250be4ff3589f6", "size": 958, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MA320/sections/2/3.tex", "max_stars_repo_name": "iydon/homework", "max_stars_repo_head_hexsha": "253d4746528ef62d33eba1de0b90dcb17ec587ed", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-10-20T08:18:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-11T12:14:56.000Z", "max_issues_repo_path": "MA320/sections/2/3.tex", "max_issues_repo_name": "AllenYZB/homework", "max_issues_repo_head_hexsha": "65bd3372df197bec5e152a37cdc1f6f5432b7f3e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2022-01-13T03:04:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T00:49:10.000Z", "max_forks_repo_path": "MA320/sections/2/3.tex", "max_forks_repo_name": "AllenYZB/homework", "max_forks_repo_head_hexsha": "65bd3372df197bec5e152a37cdc1f6f5432b7f3e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-11-02T05:46:01.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-12T23:11:28.000Z", "avg_line_length": 43.5454545455, "max_line_length": 467, "alphanum_fraction": 0.7202505219, "num_tokens": 286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7069235574519599}}
{"text": "\\section{The dot product}\n\\label{sec:dot-product}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Compute the dot product of vectors geometrically and\n    algebraically.\n  \\item Use properties of the dot product, including the\n    Cauchy-Schwarz inequality and the triangle inequality, to prove\n    further equalities and inequalities.\n  \\item Determine whether two vectors are orthogonal.\n  \\item Compute the scalar and vector projection of one vector onto\n    another.\n  \\item Decompose a vector into orthogonal components.\n  \\end{enumerate}\n\\end{outcome}\n\nThere are two ways of multiplying vectors that are useful in\napplications. The first of these is called the \\textbf{dot product},\nand the second is called the \\textbf{cross product}. We will consider\nthe dot product here, and the cross product in the next section.\n\n", "meta": {"hexsha": "6a7439d869f43e6a140e336030694b2a66db1329", "size": 822, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Vectors-DotProduct.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Vectors-DotProduct.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Vectors-DotProduct.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 35.7391304348, "max_line_length": 69, "alphanum_fraction": 0.7737226277, "num_tokens": 187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767906859265, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7069235497080167}}
{"text": "\\lab{Interior Point I}{Interior Point I}\n\\objective{Learn About Interior Point Methods for Linear Constrained Optimization.}\n\n\\section*{Interior Point Methods: Overview}\nAlthough the Simplex algorithm was long the only practically competitive method for linear programming, the past 30 years have seen the\ndiscovery and widespread adoption of a new family of algorithms that rival and in some cases outperform the Simplex algorithm, collectively\ncalled Interior Point methods. One of the major shortcomings of the Simplex algorithm is that the number of steps required to solve the\nproblem can grow exponentially in the size of the linear system. Thus, for certain large linear programs, the Simplex algorithm is simply\nnot viable. Interior Point methods offer and alternative approach and guarantee much better theoretical convergence properties.\n\nRecall that a linear program is a constrained optimization problem with a linear objective function and linear constraints.\nThe linear constraints define a set of allowable points called the \\emph{feasible region}, the boundary of which forms a geometric\nobject known as a \\emph{polytope}. The theory of convex optimization ensures that the optimal point for the objective function\ncan be found among the vertices of the feasible polytope. The Simplex Method tests a sequence of such vertices until it finds\nthe optimal point. Provided the linear program is neither unbounded nor infeasible, the algorithm is certain to produce the correct\nanswer after a finite number of steps, but it does not guarantee an efficient path along the polytope toward the minimizer. Interior\npoint methods do away with the feasible polytope and instead generate a sequence of points that cut through the interior (or\nexterior) of the feasible region and converge iteratively to the optimal point. Although it is computationally more expensive to\ncompute such interior points, each step results in significant progress toward the minimizer. See Figure \\ref{fig:intPath} for\na visualization of an Interior Point method. In general, the Simplex Method requires many more, albeit less expensive, computations.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{interiorPath.pdf}\n\\caption{A path traced by an Interior Point algorithm.}\n\\label{fig:intPath}\n\\end{figure}\n\n\\section*{Primal-Dual Interior Point Methods}\nSome of the most popular and successful types of Interior Point methods nowadays are known as Primal-Dual Interior Point methods. To\ndescribe this approach, let us consider the following linear program:\n\\begin{align*}\n\\text{minimize }\\qquad &c^Tx\\\\\n\\text{subject to }\\qquad &Ax = b\\\\\n&x \\geq 0.\n\\end{align*}\nHere, $x, c \\in \\mathbb{R}^n$, $b \\in \\mathbb{R}^m$, and $A$ is an $m \\times n$ matrix with full row rank. By $x \\geq 0$, we\nsimply mean that each coordinate of $x$ is nonnegative. Note that this formulation is quite general, as any linear program can be\nposed in this manner, after appropriate transformations. This is the primal problem, and its dual takes the form\n\\begin{align*}\n\\text{maximize }\\qquad &b^T\\lambda\\\\\n\\text{subject to }\\qquad &A^T\\lambda + s = c\\\\\n&s \\geq 0,\n\\end{align*}\nwhere $\\lambda \\in \\mathbb{R}^m$ and $s \\in \\mathbb{R}^n$.\n\nThe theory of convex optimization gives us necessary and sufficient\nconditions for the solutions to the primal and dual problems via the Karush-Kuhn-Tucker (KKT) conditions.\nThese conditions are derived as follows. First, we calculate the so-called \\emph{Lagrangian function} for our linear program.\nThe Lagrangian function for a general constrained optimization problem of the form\n\\begin{align*}\n\\text{minimize }\\qquad &f(x)\\\\\n\\text{subject to }\\qquad &c_i(x) = 0, \\quad i = 1,2,\\ldots,k,\\\\\n&d_i(x) \\geq 0, \\quad i = 1,2,\\ldots,j,\n\\end{align*}\nis defined to be\n\\[\n\\mathcal{L}(x, \\lambda, s) := f(x) - \\displaystyle\\sum_{i=1}^k\\lambda_ic_i(x) - \\displaystyle\\sum_{i=1}^js_id_i(x).\n\\]\nFrom here, the KKT conditions are\n\\begin{align*}\n\\nabla_x\\mathcal{L}(x,\\lambda,s) &= 0,\\\\\nc_i(x) &= 0,\\quad i = 1,2,\\ldots,k,\\\\\ns_id_i(x) &= 0,\\quad i=1,2,\\ldots,j,\\\\\nd_i(x) &\\geq 0,\\quad i=1,2,\\ldots,j,\\\\\ns_i &\\geq 0,\\quad i=1,2,\\ldots,j.\n\\end{align*}\nFor our linear program, $f(x) = c^Tx$, $c_i(x) = A_i^Tx - b_i$ (where $A_i$ denotes the $i$-th row of $A$), and\n$d_i(x) = x_i$. Hence, you can check that our Lagrangian function is\n\\[\n\\mathcal{L}(x,\\lambda,s) = c^Tx - \\lambda^T(Ax - b) - s^Tx.\n\\]\nWe then calculate\n\\[\n\\nabla_x\\mathcal{L}(x,\\lambda,s) = (c^T - \\lambda^TA - s^T)^T = c - A^T\\lambda - s.\n\\]\nThe KKT conditions can now be expressed as follows:\n\\begin{align*}\nA^T\\lambda + s &= c\\\\\nAx &= b\\\\\nx_is_i &= 0, \\quad i = 1,2,\\ldots,n,\\\\\nx, s &\\geq 0.\n\\end{align*}\nIn fact, it is convenient to write these conditions in a more compact manner, by defining an almost-linear function\n$F$ and setting it equal to zero:\n\\begin{align*}\nF(x,\\lambda,s) :=\n\\begin{bmatrix}\nA^T\\lambda + s - c\\\\\nAx - b\\\\\nXSe\\\\\n\\end{bmatrix}\n&= 0,\\\\\n(x,s) &\\geq 0,\n\\end{align*}\nwhere $X = \\text{diag}(x_1,x_2,\\ldots,x_n)$, $S = \\text{diag}(s_1,s_2,\\ldots,s_n)$, and $e = (1,1,\\ldots,1)^T$.\n\nA Primal-Dual Interior Point method is a line search method that starts with an initial guess $(x_0, \\lambda_0, s_0)$\nand produces a sequence of points that converge to $(x^*, \\lambda^*, s^*)$, the solution to the KKT equations and hence\nthe solution to the original linear program.\n\n\\subsection*{Search Direction and Step Length}\nWe now describe how to select the search direction and step length at each iteration of the algorithm. Because this is\na constrained problem, matters are more complicated than is usual in unconstrained line search methods.\n\nIn the spirit of\nNewton's Method, we can form a linear approximation of the system $F(x,\\lambda,s) = 0$ centered around our current\npoint $(x, \\lambda, s)$, and\ncalculate the direction $(\\triangle x, \\triangle \\lambda, \\triangle s)$ in which to step to set the linear approximation\nequal to 0. This equates to solving the linear system\n\\[\nJ(x,\\lambda,s)\n\\begin{bmatrix}\n\\triangle x\\\\\n\\triangle \\lambda\\\\\n\\triangle s\\\\\n\\end{bmatrix}\n= - F(x,\\lambda,s).\n\\]\nHere $J(x,\\lambda,s)$ denotes the Jacobian matrix of $F$. We can calculate this matrix block-wise by obtaining the\npartial derivatives of each block entry of $F(x,\\lambda, s)$ with respect to $x$, $\\lambda$, and $s$, respectively.\nFor example, consider the topmost block entry of $F(x,\\lambda,s)$, given by\n\\[\nA^T\\lambda + s - c.\n\\]\nWe calculate the partial derivatives of this expressions as follows:\n\\begin{align*}\n\\frac{\\partial}{\\partial x}[A^T\\lambda + s - c] &= 0,\\\\\n\\frac{\\partial}{\\partial \\lambda}[A^T\\lambda + s - c] &= A^T,\\\\\n\\frac{\\partial}{\\partial s}[A^T\\lambda + s - c] &= I.\\\\\n\\end{align*}\nHence, the topmost block row of $J(x,\\lambda,s)$ is given by\n\\[\n\\begin{bmatrix}\n0 \\quad A^T \\quad I\\\\\n\\end{bmatrix}.\n\\]\n\nContinuing in this manner, we can calculate the entire Jacobian, which leads us to the following linear system:\n\\begin{equation}\n\\begin{bmatrix}\n0 & A^T & I\\\\\nA & 0 & 0\\\\\nS & 0 & X\n\\end{bmatrix}\n\\begin{bmatrix}\n\\triangle x\\\\\n\\triangle \\lambda\\\\\n\\triangle s\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n-r_c\\\\\n-r_b\\\\\n-XSe\n\\end{bmatrix},\n\\label{eq:affine}\n\\end{equation}\nwhere $r_b = Ax - b$ and $r_c = A^T\\lambda + s - c$.\nThis Newton direction is too greedy, however, and even small steps in this direction may cause us to violate the nonnegativity\ncondition (the last line of the KKT conditions). We need to find a new search direction.\n\nChoosing an appropriate search direction is a tricky task, and various approaches exist. We will follow a popular strategy\nknown as the \\emph{Predictor-Corrector Algorithm}. The idea is to actually calculate two directions. We first calculate\nthe standard Newton direction described above; that is, we obtain the solution to Equation \\ref{eq:affine}. This is known as\nthe \\emph{predictor step}, since it gives us a direction in which the objective does indeed decrease, hence predicting our\nfinal search direction. Denote the solution to this system by $(\\triangle x^a, \\triangle \\lambda^a, \\triangle s^a)$.\nAs discussed, however, we must deviate from this direction somewhat, and so we additionally solve the\nfollowing linear system of equations:\n\\begin{equation}\n\\begin{bmatrix}\n0 & A^T & I\\\\\nA & 0 & 0\\\\\nS & 0 & X\n\\end{bmatrix}\n\\begin{bmatrix}\n\\triangle x\\\\\n\\triangle \\lambda\\\\\n\\triangle s\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n-r_c\\\\\n-r_b\\\\\n-XSe - \\triangle X^a\\triangle S^ae + \\sigma \\mu e\n\\end{bmatrix}.\n\\label{eq:centering}\n\\end{equation}\nThe solution to this system, which we denote by $(\\triangle x, \\triangle \\lambda, \\triangle s)$, is our final search direction.\n\nWe now describe the new pieces of Equation \\ref{eq:centering}.\nNote that\n\\begin{align*}\n\\triangle X^a &= \\text{diag}(\\triangle x_1^a,\\ldots,\\triangle x_n^a),\\\\\n\\triangle S^a &= \\text{diag}(\\triangle s_1^a,\\ldots,\\triangle s_n^a).\n\\end{align*}\nFurther,\ndefine $\\mu := x^Ts/n$. This quantity, called the \\emph{duality measure}, tells us roughly how close we are\nto the optimal solution, with values closer to 0 being more desirable. It is present in Equation \\ref{eq:centering}\nfor the purpose of obtaining a search direction that leads to a decrease towards 0 in the duality measure.\n\nThe formula for $\\sigma$ is somewhat more complicated, and\nis based on a heuristic approach. First, make the following calculations (which give the maximum allowable step lengths in\nthe Newton search direction for $x$ and $s$ before the nonnegativity condition is violated):\n\\begin{align*}\n\\alpha_a^p &:= \\min\\left(1, \\displaystyle\\min_{i : \\triangle x_i^a < 0}-\\frac{x_i}{\\triangle x_i^a}\\right)\\\\\n\\alpha_a^d &:= \\min\\left(1, \\displaystyle\\min_{i : \\triangle s_i^a < 0}-\\frac{s_i}{\\triangle s_i^a}\\right).\n\\end{align*}\nNext, define\n\\[\n\\mu_a := \\frac{1}{n}(x+\\alpha_a^p\\triangle x^a)^T(s+\\alpha_a^d\\triangle s^a),\n\\]\nwhich is simply the duality measure for the point obtained by taking a full step in the Newton direction.\nFinally, calculate $\\sigma$ by the formula\n\\[\n\\sigma = \\left(\\frac{\\mu_a}{\\mu}\\right)^3.\n\\]\n\nNow that we have our search direction, it remains to choose our step length. We wish to step nearly as far as possible without\nviolating the nonnegativity condition, thus remaining in the interior of the feasible region. First, make the following\ncalculations, which give the maximum allowable step lengths for $x$ and $s$, respectively:\n\\begin{align*}\n\\beta^p &:= \\displaystyle\\min_{i : \\triangle x_i < 0}-\\frac{x_i}{\\triangle x_i}\\\\\n\\beta^d &:= \\displaystyle\\min_{i : \\triangle s_i < 0}-\\frac{s_i}{\\triangle s_i}.\n\\end{align*}\nNext, we back off from these maximum step lengths slightly:\n\\begin{align*}\n\\alpha^p &:= \\min(1, 0.95\\beta^p)\\\\\n\\alpha^d &:= \\min(1, 0.95\\beta^d).\n\\end{align*}\nThese are our final step lengths. That is, our next point $(x', \\lambda', s')$ is given by\n\\begin{align*}\nx' &= x + \\alpha^p\\triangle x\\\\\n(\\lambda', s') &= (\\lambda, s) + \\alpha^d(\\triangle \\lambda, \\triangle s).\n\\end{align*}\nWe summarize the entire procedure in Algorithm \\ref{alg:predcorr}.\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Predictor-Corrector Algorithm}{}\n    \\State \\textrm{Choose initial point } $(x_0, \\lambda_0, s_0)$.\n    \\For{$k = 0, 1, 2, \\ldots$}\n        \\State \\textrm{Solve for } $(\\triangle x^a, \\triangle \\lambda^a, \\triangle s^a)$.\n        \\State \\textrm{Calculate } $\\alpha_a^p, \\alpha_a^d, \\mu_a$, \\textrm{and} $\\sigma$.\n        \\State \\textrm{Solve for } $(\\triangle x, \\triangle \\lambda, \\triangle s)$.\n        \\State \\textrm{Calculate the step lengths } $\\alpha^p, \\alpha^d$.\n        \\State $x_{k+1} = x_k + \\alpha^p\\triangle x$,\\\\\n        $\\qquad\\quad(\\lambda_{k+1}, s_{k+1}) = (\\lambda_k, s_k) + \\alpha^d(\\triangle \\lambda, \\triangle s)$.\n    \\EndFor\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Predictor-Corrector Algorithm}\n\\label{alg:predcorr}\n\\end{algorithm}\n\nA few notes on the implementation of this algorithm are in order.\nIn each iteration, by far the most expensive operations are solving Equations \\ref{eq:affine} and\n\\ref{eq:centering}. Fortunately, the only difference between the two equations is the right-hand side.\nThus, we can avoid repetitious calculation by first factorizing the block matrix\n\\[\n\\begin{bmatrix}\n0 & A^T & I\\\\\nA & 0 & 0\\\\\nS & 0 & X\n\\end{bmatrix}\n\\]\nonce at the beginning of the iteration, and then using the factorization twice to solve both equations.\nFor convenience, consider using the functions \\li{lu_factor} and \\li{lu_solve} in the \\li{scipy.linalg}\nmodule. It is possible to speed up these calculations further, but for simplicity we won't pursue the issue\nfurther.\n\nNext, as mentioned above, the duality measure $\\mu$ tells us in some sense how close our current point is to the minimizer.\nThe closer $\\mu$ is to 0, the closer we are to the optimal point. Thus, by printing the value of $\\mu$ at\neach iteration, you can track how your algorithm is progressing and detect when you have converged.\n\nAnother potentially tricky calculation that comes up in each iteration has the following form:\n\\[\n\\min\\left(1, \\displaystyle\\min_{i : u_i < 0}-\\frac{v_i}{u_i}\\right),\n\\]\nwhere $\\mathbf{u} = (u_1, \\ldots, u_n)^T$ and $\\mathbf{v} = (v_1, \\ldots, v_n)^T$ are vectors.\nThis can be done in a vectorized fashion in Python as follows (assuming that the arrays \\li{u} and \\li{v}\nhave already been initialized):\n\\begin{lstlisting}\n>>> mask = u < 0\n>>> if np.any(mask):\n>>>     myMin = min(1, (-v/u)[mask].min())\n>>> else:\n>>>     myMin = 1\n\\end{lstlisting}\nWe need the if-statement to deal with the case where no entry of $u$ is negative.\n\nFinally, the choice of initial point $(x_0, \\lambda_0, s_0)$ is an important, nontrivial one.\nA naively or randomly chosen initial point may cause the algorithm to fail to converge.\nWe provide code to calculate an appropriate initial point. You should include a call to this function in your algorithm to obtain the initial point.\n\n\\begin{lstlisting}\ndef startingPoint(A, b, c):\n    \"\"\"\n    Calculate an initial guess to the solution of the\n    linear program min c^T x, Ax = b, x>=0.\n    Inputs:\n        A -- array of shape (m,n) with linearly independent rows\n        b -- array of length m\n        c -- array of length n\n    Returns:\n        x -- array of length n\n        lam -- array of length m\n        s -- array of length n\n    Ref: Nocedal and Wright, p. 410\n    \"\"\"\n    # first calculate x, lam, s of minimal norm satisfying the primal and dual constraints\n    B = la.inv(A.dot(A.T))\n    x = A.T.dot(B.dot(b))\n    lam = B.dot(A.dot(c))\n    s = c - A.T.dot(lam)\n\n    # perturb x and s so they are nonnegative\n    dx = max((-3./2)*x.min(), 0)\n    ds = max((-3./2)*s.min(), 0)\n    x += dx*np.ones(x.shape)\n    s += ds*np.ones(s.shape)\n\n    # perturb x and s so they are not too close to zero, not too dissimilar\n    dx = .5*(x*s).sum()/s.sum()\n    ds = .5*(x*s).sum()/x.sum()\n    x += dx*np.ones(x.shape)\n    s += ds*np.ones(s.shape)\n\n    return x, lam, s\n\\end{lstlisting}\n\n\\begin{problem}\nWrite a function \\li{interiorPoint} that implements the interior point method described above.\nThe function should accept $A$, $b$, and $c$ as parameters, along with keyword arguments\n\\li{niter} that gives the number of iterations to perform, and \\li{verbose} that indicates\nwhether to print out the value of the objective function and $\\mu$ at each iteration.\nThe function should return the optimal point $x$ along with the value of the objective function at this\npoint.\n\\end{problem}\n\\section*{Least Absolute Deviations}\nWe now return to the familiar problem of fitting a line (or hyperplane) to a set of data. We have previously approached this\nproblem by minimizing the sum of the squares of the errors between the data points and the line, an approach known as \\emph{least\nsquares}. The least squares solution can be obtained analytically when fitting a linear function, or through a number of optimization\nmethods (such as Conjugate Gradient) when fitting a nonlinear function.\n\nThe method of least absolute deviations also seeks to find a best fit line to a set of data, but the error between the data and\nthe line is measured differently. In particular, suppose we have a set of data points $(y_1, \\mathbf{x}_1), (y_2, \\mathbf{x}_2), \\ldots,\n(y_m, \\mathbf{x}_m)$, where $y_i \\in \\mathbb{R}$, $\\mathbf{x}_i \\in \\mathbb{R}^n$ for $i = 1, 2, \\ldots, m$. Here, the $\\mathbf{x}_i$ vectors\nare the explanatory variables and the $y_i$ values are the response variables, and we assume the following linear model:\n\\[\ny_i = \\beta^T\\mathbf{x}_i + b, \\qquad i = 1, 2, \\ldots, m,\n\\]\nwhere $\\beta\\in\\mathbb{R}^n$ and $b \\in \\mathbb{R}$. The error between the data and the proposed linear model is given by\n\\[\n\\sum_{i=1}^n |\\beta^T\\mathbf{x}_i + b - y_i|,\n\\]\nand we seek to choose the parameters $\\beta, b$ so as to minimize this error.\n\nBefore we explore how to solve this problem, a discussion of the differences between least absolute deviations and least squares is in order.\nThe most prominent difference between these two approaches is how they respond to outliers in the data. Least absolute deviations is\nrobust in the presence of outliers, meaning that one (or a few) errant data points won't severely affect the fitted line. Indeed, in most cases,\nthe best fit line is guaranteed to pass through at least two of the data points.\nThis is a desirable property when the outliers may be ignored (perhaps because they are due to measurement error or corrupted data).\nLeast squares, on the other hand,\nis much more sensitive to outliers, and so is the better choice when outliers cannot be dismissed. See Figure \\ref{fig:leastAbsDev}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{leastAbsDev.pdf}\n\\caption{Fitted lines produced by least absolute deviations (top) and least squares (bottom). The presence of an outlier accounts for the\nstark difference between the two lines.}\n\\label{fig:leastAbsDev}\n\\end{figure}\n\nWhile least absolute deviations is robust with respect to outliers, small horizontal perturbations of the data points can lead to very different\nfitted lines. Hence, the least absolute deviations solution is less stable than the least squares solution. In some cases there are even infinitely\nmany lines that minimize the least absolute deviations error term. However, one can expect a unique solution in most cases.\n\nThe least absolute deviations solution arises naturally when we assume that the residual terms $\\beta^T\\mathbf{x}_i + b - y_i$ have a particular\nstatistical distribution (the Laplace distribution). Ultimately, however, the choice between least absolute deviations and least squares depends on the\nnature of the data at hand, as well as your own good judgment.\n\n\\subsection{Least Absolute Deviations as a Linear Program}\nWe can formulate the least absolute deviations problem as a linear program, and then solve it using our interior point method.\nFor $i = 1, 2, \\ldots, m$ we introduce the artificial variable $u_i$ to take the place of the error term $|\\beta^T\\mathbf{x}_i + b - y_i|$,\nand we require this variable to satisfy $u_i \\geq |\\beta^T\\mathbf{x}_i + b - y_i|$. This constraint is not yet linear, but we can split it into\nan equivalent set of two linear constraints:\n\\begin{align*}\nu_i &\\geq \\beta^T\\mathbf{x}_i + b - y_i,\\\\\nu_i &\\geq y_i - \\beta^T\\mathbf{x}_i - b.\n\\end{align*}\nClearly, the $u_i$ are implicitly constrained to be nonnegative.\n\nOur linear program can now be stated as follows:\n\\begin{align*}\n\\text{minimize }\\qquad &\\sum_{i=1}^m u_i\\\\\n\\text{subject to }\\qquad &u_i \\geq \\beta^T\\mathbf{x}_i + b - y_i,\\\\\n&u_i \\geq y_i - \\beta^T\\mathbf{x}_i - b.\n\\end{align*}\nThis is not yet in the form that we need in order to use our interior point method.\nFor each inequality constraint, we bring all variables ($u_i, \\beta, b$) to the left hand side and\nintroduce a nonnegative slack variable to transform the constraint into an equality:\n\\begin{align*}\nu_i  - \\beta^T\\mathbf{x}_i - b - s_{2i-1}&= -y_i,\\\\\nu_i +\\beta^T\\mathbf{x}_i + b - s_{2i}&= y_i,\\\\\ns_{2i-1}, s_{2i}&\\geq 0.\n\\end{align*}\n\nNotice that the variables $\\beta, b$ are not assumed to be nonnegative, but in our interior point method, all variables are assumed\nto be nonnegative. We can fix this situation by writing these variables as the difference of nonnegative variables:\n\\begin{align*}\n  \\beta &= \\beta_1 - \\beta_2,\\\\\n  b &= b_1 - b_2,\\\\\n  &\\beta_1, \\beta_2, b_1, b_2 \\geq 0.\n\\end{align*}\nSubstituting these values into our constraints, we have the following system of constraints:\n\\begin{align*}\nu_i  - \\beta_1^T\\mathbf{x}_i + \\beta_2^T\\mathbf{x}_i - b_1 + b_2 - s_{2i-1}&= -y_i,\\\\\nu_i + \\beta_1^T\\mathbf{x}_i - \\beta_2^T\\mathbf{x}_i + b_1 - b_2 - s_{2i}&= y_i,\\\\\nu_i, \\beta_1, \\beta_2, b_1, b_2, s_{2i-1}, s_{2i}&\\geq 0.\n\\end{align*}\nWriting $\\mathbf{y} = (-y_1, y_1, -y_2, y_2, \\ldots, -y_m, y_m)^T$ and $\\beta_i = (\\beta_{i,1}, \\ldots, \\beta_{i,n})^T$ for $i = 1, 2$,\nwe can aggregate all of our variables into one vector as follows:\n\\[\n\\mathbf{v} = (u_1,\\ldots, u_m, \\beta_{1,1},\\ldots, \\beta_{1,n}, \\beta_{2,1},\\ldots, \\beta_{2,n}, b_1, b_2, s_1,\\ldots,s_{2m})^T.\n\\]\nDefining $\\mathbf{c} = (1, 1, \\ldots, 1, 0, \\ldots, 0)^T$ (where only the first $m$ entries are equal to 1), we can write our\nobjective function as\n\\[\n\\sum_{i=1}^m u_i = \\mathbf{c}^T\\mathbf{v}.\n\\]\nHence, the final form of our linear program is\n\\begin{align*}\n  \\text{minimize }\\qquad &\\mathbf{c}^T\\mathbf{v}\\\\\n  \\text{subject to }\\qquad A\\mathbf{v} &= \\mathbf{y},\\\\\n  \\mathbf{v} &\\geq 0,\n\\end{align*}\nwhere $A$ is a matrix containing the coefficients of the constraints.\nOur constraints are now equalities, and the variables are all nonnegative, so we are ready to use our interior point method to obtain\nthe solution.\n\nLet's work through an example. We start with an array \\li{data}, each row of which consists of the values $y_i, x_{i,1},\\ldots,x_{i,n}$,\nwhere $\\mathbf{x}_i = (x_{i,1}, x_{i,2}, \\ldots, x_{i,n})^T$. We will have $3m + 2(n+1)$ variables in our linear program. Below, we initialize\nthe vectors $\\mathbf{c}$ and $\\mathbf{y}$.\n\\begin{lstlisting}\n>>> m = data.shape[0]\n>>> n = data.shape[1] - 1\n>>> c = np.zeros(3*m + 2*(n + 1))\n>>> c[:m] = 1\n>>> y = np.empty(2*m)\n>>> y[::2] = -data[:, 0]\n>>> y[1::2] = data[:, 0]\n>>> x = data[:, 1:]\n\\end{lstlisting}\n\nThe hardest part is initializing the constraint matrix correctly. It has $2m$ rows and $3m + 2(n+1)$ columns. Try writing out the\nconstraint matrix by hand for small $m, n$, and make sure you understand why the code below is correct.\n\\begin{lstlisting}\n>>> A = np.ones((2*m, 3*m + 2*(n + 1)))\n>>> A[::2, :m] = np.eye(m)\n>>> A[1::2, :m] = np.eye(m)\n>>> A[::2, m:m+n] = -x\n>>> A[1::2, m:m+n] = x\n>>> A[::2, m+n:m+2*n] = x\n>>> A[1::2, m+n:m+2*n] = -x\n>>> A[::2, m+2*n] = -1\n>>> A[1::2, m+2*n+1] = -1\n>>> A[:, m+2*n+2:] = -np.eye(2*m, 2*m)\n\\end{lstlisting}\n\nNow we can calculate the solution by calling our interior point function.\n\\begin{lstlisting}\n>>> sol = interiorPoint(A, y, c, niter=10, verbose=False)[0]\n\\end{lstlisting}\n\nThe variable \\li{sol}, however, holds the value for the vector\n\\[\n\\mathbf{v} = (u_1,\\ldots, u_m, \\beta_{1,1},\\ldots, \\beta_{1,n}, \\beta_{2,1},\\ldots, \\beta_{2,n}, b_1, b_2, s_1,\\ldots,s_{2m+1})^T.\n\\]\nWe want the values of $\\beta = \\beta_1-\\beta_2$ and $b = b_1 - b_2$, and we accomplish this by the\nfollowing code:\n\\begin{lstlisting}\n>>> beta = sol[m:m+n] - sol[m+n:m+2*n]\n>>> b = sol[m+2*n] - sol[m+2*n+1]\n\\end{lstlisting}\n\n\\begin{problem}\nThe file \\li{simdata.txt} contains two columns of data. The first gives the values of the response\nvariables, and the second column gives the values of the explanatory variables. Find the least absolute\ndeviations line for this data set, and plot it together with the data.\n\\end{problem} ", "meta": {"hexsha": "f875a4c610330d53da4553f11e4cac5d95f4a7bd", "size": 23618, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/InteriorPoint1/InteriorPoint1.tex", "max_stars_repo_name": "m4webb/numerical_computing", "max_stars_repo_head_hexsha": "d26e5ace9dbb91cd87440d84f0bd05d4a46e6781", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/InteriorPoint1/InteriorPoint1.tex", "max_issues_repo_name": "m4webb/numerical_computing", "max_issues_repo_head_hexsha": "d26e5ace9dbb91cd87440d84f0bd05d4a46e6781", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/InteriorPoint1/InteriorPoint1.tex", "max_forks_repo_name": "m4webb/numerical_computing", "max_forks_repo_head_hexsha": "d26e5ace9dbb91cd87440d84f0bd05d4a46e6781", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-12-08T01:19:23.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T01:19:23.000Z", "avg_line_length": 48.2, "max_line_length": 151, "alphanum_fraction": 0.7132271996, "num_tokens": 7201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7069235491741691}}
{"text": "\\subsection{Distance between Two Points and Midpoints}\\label{sec:DistanceAndMidpoints}\r\n\r\nAnother important concept in Geometry is the notion of length.  If we are going to unite Algebra and Geometry using the Cartesian Plane, then we need to develop an algebraic understanding of what distance in the plane means.\\\\\r\n\r\nGiven two points $(x_1,y_1)$ and $(x_2,y_2)$, recall that their\r\nhorizontal distance from one another is $\\Delta x=x_2-x_1$ and their\r\nvertical distance from one another is $\\Delta y=y_2-y_1$. Actually,\r\nthe word ``distance'' normally denotes ``positive distance''. $\\Delta\r\nx$ and $\\Delta y$ are {\\it signed\\/} distances, but this is clear from\r\ncontext. The (positive) distance from one point to the other\r\nis the length of the hypotenuse of a right triangle with legs $|\\Delta\r\nx|$ and $|\\Delta y|$, as shown in Figure~\\ref{fig:distance between\r\npoints}.  The Pythagorean Theorem states that the distance between\r\nthe two points is the square root of the sum of the squares of the\r\nhorizontal and vertical sides:\\\\\r\n$$| \\, \\Delta x \\,|^{2} + | \\, \\Delta y \\, |^{2} =  d^{2}$$ \\\\\r\n\r\n\r\n\r\n\\figure[!ht]\r\n\\centerline{\\vbox{\\beginpicture\r\n\\normalgraphs\r\n%\\ninepoint\r\n\\setcoordinatesystem units <0.5truein,0.5truein>\r\n\\setplotarea x from 0 to 3, y from 0 to 2\r\n\\putrule from 0 0 to 3 0\r\n\\putrule from 3 0 to 3 2\r\n\\plot 0 0 3 2 /\r\n\\put {$(x_1,y_1)$} [r] <-5pt,0pt> at 0 0\r\n\\put {$(x_2,y_2)$} [l] <5pt,0pt> at 3 2\r\n\\put {$\\Delta x$} [t] <0pt,-5pt> at 1.5 0\r\n\\put {$\\Delta y$} [l] <5pt,0pt> at 3 1\r\n\\endpicture}}\r\n\\caption{Distance between two points (here, $\\Delta x$ and $\\Delta y$ are positive). \\label{fig:distance between points}}\r\n\\endfigure\r\n\r\n\\begin{formulabox}[Distance Formula]\r\nThe distance between points $(x_1,y_1)$ and $(x_2,y_2)$ is\r\n$$\\hbox{distance}=\\sqrt{(\\Delta x)^2+(\\Delta y)^2}=\\sqrt{(x_2-x_1)^2+ (y_2-y_1)^2}$$\r\n\\end{formulabox}\r\n\r\n\\bigskip\r\n\r\n\\begin{example}{Distance Between Two Points}{DistanceExample}\r\nFind and simplify the distance between $P(-2,3)$ and $Q(1,-3)$.\r\n\\end{example}\r\n\\begin{solution}\t\r\nThe distance, $d$, between points $P(-2,3)$ and $Q(1,-3)$ is \\\\\r\n$$\\begin{array}{rcl}\r\nd & = & \\sqrt{ (x_2-x_1)^2+ (y_2-y_1)^2}\\\\\r\n & = & \\sqrt{(1-(-2))^2+(-3-(3))^2} \\\\\r\n & = & \\sqrt{9+36} \\\\\r\n & = & 3\\sqrt{5} \\\\\r\n \\end{array}$$\r\n So the distance  is $3\\sqrt{5}$.\r\n\\end{solution}\r\n\r\n\\begin{example}{Point on a Line}\r\n\tFFind all of the points with $x$-coordinate $1$ which are $4$ units from the point $(3,2)$. \r\n\\end{example}\r\n\\begin{solution}\r\n\tWe shall soon see that the points we wish to find are on the line $x=1$, but for now we'll just view them as points of the form $(1,y)$.  Visually,\\\\\r\n\t$$ \\includegraphics[scale=0.4]{images/distance-ex}$$\r\n\tWe require that the distance from $(3,2)$ to $(1,y)$ be $4$.  The Distance Formula yields\r\n\t\r\n\t\\[ \\begin{array}{rclr} \r\n\td &  = & \\sqrt{\\left(x_{\\mbox{\\tiny$2$}}-x_{\\mbox{\\tiny$1$}}\\right)^2+\\left(y_{\\mbox{\\tiny$2$}}-y_{\\mbox{\\tiny$1$}}\\right)^2}  & \\\\\r\n\t4 &  = & \\sqrt{(1-3)^2+(y-2)^2} & \\\\\r\n\t4  & = & \\sqrt{4+(y-2)^2} & \\\\ \r\n\t4^2 & = & \\left(\\sqrt{4+(y-2)^2}\\right)^2 &  \\mbox{squaring both sides} \\\\\r\n\t16 & = & 4+(y-2)^2 & \\\\\r\n\t12 & = & (y-2)^2 & \\\\\r\n\t(y-2)^2 & = & 12 &  \\\\\r\n\ty - 2 & = & \\pm \\sqrt{12} & \\mbox{extracting the square root} \\\\\r\n\ty-2 & = & \\pm 2 \\sqrt{3} & \\\\\r\n\ty & = & 2 \\pm 2 \\sqrt{3}  & \r\n\t\\end{array} \\]\r\n\tWe obtain two points:  $(1, 2 + 2 \\sqrt{3})$ and $(1, 2-2 \\sqrt{3}).$  \r\n\t\r\n\\end{solution}\t\t\r\n\r\nAs a special case of the distance formula, suppose we want to know the\r\ndistance of a point $(x,y)$ to the origin.  According to the distance\r\nformula, this is $$\\sqrt{(x-0)^2+(y-0)^2}=\\sqrt{x^2+y^2}.$$\r\nA point $(x,y)$ is at a distance $r$ from the origin if and only if\r\n$\\sqrt{x^2+y^2}=r$, or, if we square both sides: $x^2+y^2=r^2$.  As illustrated\r\nin the next section, this is the equation of the circle of radius, $r$, centered at the origin.\r\n\r\nFurthermore, given two points we can determine the \\dfont{midpoint} of the line segment joining the two points.\\\\\r\n\r\n\\begin{formulabox}[Midpoint Formula]\r\nThe midpoint of the line segment joining two points $(x_1,y_1)$ and \r\n$(x_2,y_2)$ is the point with coordinates:\r\n$$\\hbox{midpoint}=\\left(\\frac{x_1+x_2}{2},\\frac{y_1+y_2}{2}\\right).$$\r\n\\end{formulabox}\r\n\r\n\\bigskip\r\n\r\n\\begin{example}{Midpoint of a Line Segment}{Midpoint}\r\nFind the midpoint of the line segment joining the given points: $(1,0)$ and $(5,-2)$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nUsing the \\ifont{midpoint formula} on $(x_1,y_1)=(1,0)$ and $(x_2,y_2)=(5,-2)$ we get:\r\n$$\\left(\\frac{1+5}{2},\\frac{0+(-2)}{2}\\right)=(3,-1)$$\r\nThus, the midpoint of the line segment occurs at $(3,-1)$.\r\n\\end{solution}\r\n\r\n\r\nWe close with a more abstract application of the Midpoint Formula. \r\n\r\n\\begin{example}{Distance between points}\r\nIIf $a \\neq b$, prove that the line $y = x$ equally divides the line segment with endpoints $(a,b)$ and $(b,a)$.\r\n\\end{example}\t\r\n\\begin{solution}\t\r\nTo prove the claim, we use the Midpoint formula to find the midpoint  \r\n\t\r\n\t\\[ \\begin{array}{rcl}\r\n\t\r\n\tM & = & \\left( \\dfrac{a+b}{2},  \\dfrac{b+a}{2} \\right) \\\\\r\n\t& = & \\left( \\dfrac{a+b}{2},  \\dfrac{a+b}{2} \\right)  \\\\ \\end{array} \\]\r\n\t\r\n\tSince the $x$ and $y$ coordinates of this point are the same, we find that the midpoint lies on the line $y=x$, as required. \\\r\n\\end{solution}\r\n\t\r\n\r\n\r\n", "meta": {"hexsha": "0e3d7750c586cfcc2bc8a15f80fd43d0f93ecd98", "size": 5299, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1-review/1-2-2-distances-and-midpoints.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1-review/1-2-2-distances-and-midpoints.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1-review/1-2-2-distances-and-midpoints.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.3984375, "max_line_length": 227, "alphanum_fraction": 0.6363464805, "num_tokens": 1882, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7069235465928545}}
{"text": "\n\\subsection{Closed sets}\n\nThe complement of any open set is a closed set.\n\nA set can be open, closed, both or neither.\n\n", "meta": {"hexsha": "ba5b52968b4385f7cab7fd215ec589b63cbc5e16", "size": 121, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/topologyFinite/02-03-closed.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/topologyFinite/02-03-closed.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/topologyFinite/02-03-closed.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.125, "max_line_length": 47, "alphanum_fraction": 0.7355371901, "num_tokens": 30, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7069235440994631}}
{"text": "\\section{Synthesizing Functions for a Given Encoding} \\label{sec:synthesis}\n%\nAs a first step, we tackle the problem of synthesizing\nfunctions over a given encoding.\n%\nWe begin with an overview of the standard encoding for the\ndata types which we focused our development on.\n%\nWe then explore how to specify the behavior of functions for\ntheir synthesis.\n\n% The first step we took for synthesizing expressions was to synthesize\n%   individual functions given an encoding.\n\n\\subsection{Church Encodings}\n%\nWe tested and focused our development on three\ndifferent data types: \\emph{booleans}, \\emph{natural\nnumbers} and \\emph{pairs}.\n%\nWe give their standard encodings below.\n\n\\paragraph{Booleans}\n%\nThe standard encoding for the boolean values \\emph{true} and\n\\emph{false} is given by:\n%\n\\begin{align*}\n  \\text{\\true} &= \\lambda a . \\lambda b . a \\\\\n  \\text{\\false} &= \\lambda a . \\lambda b . b\n\\end{align*}\n%\nIntuitively, boolean logic is interpreted as a choice and\nboolean values are represented as functions of two\nparameters making this choice: \\true chooses its first\nparameter and \\false chooses its second parameter.\n\n\\paragraph{Natural numbers}\n%\nChurch numerals are the standard representation of natural\nnumbers in the lambda calculus.\n%\nIn this encoding the number $n$ is represented as a\nhigher-order function that maps a function $f$ to its\n$n$-fold composition.\n%\nThe value of the numeral is equivalent to the number of\ntimes the function gets applied: 0 does not apply the\nfunction at all, 1 applies the function once, 2 applies the\nfunction twice, \\emph{etc.}\n%\n\\begin{align*}\n  0 & = \\lambda f . \\lambda x . x \\\\\n  1 & = \\lambda f . \\lambda x . f\\,x \\\\\n  2 & = \\lambda f . \\lambda x . f\\,(f\\,x) \\\\\n  3 & = \\lambda f . \\lambda x . f\\,(f\\,(f\\,x)) \\\\\n  \\vdots & \\\\\n  n & = \\lambda f . \\lambda x . f^{\\circ n}\\,x\n\\end{align*}\n\n\\paragraph{Pairs}\n%\nA pair is represented as a function that takes two arguments\nand returns a higher-order function which when provided with\na function as argument applies it to the two components of\nthe pair.\n%\n\\begin{align*}\n  \\pair &= \\lambda x. \\lambda y. \\lambda f.f\\,x\\,y\n\\end{align*}\n\n\\subsection{Synthesis from Examples} \\label{sec:io}\n%\nWe now turn to the question of how the behavior of a\nfunction can be specified.\n%\nAs it has proven useful in many scenarios, we explore the\nidea of using input-output examples.\n\nConsider, for instance, the boolean function \\f{and}.\nWe can specify its behavior extensionally as follows:\n%\n\\begin{align*}\n\\f{?and}\\,\\true\\,\\true    &\\equiv \\true \\\\\n\\f{?and}\\,\\true\\,\\false   &\\equiv \\false \\\\\n\\f{?and}\\,\\false\\,\\true   &\\equiv \\false \\\\\n\\f{?and}\\,\\false\\, \\false &\\equiv \\false \\\\\n\\end{align*}\n%\nBy convention, we prefix the functions we wish to synthesize\nwith \\f{?} and by convenience we refer to the boolean values\n\\true and \\false by name, but they should be understood as\nif their definition was expanded.\n%\nWith this specification our tool can successfully find the\nstandard definition of \\f{and} for church booleans:\n%\n\\begin{align}\n  \\label{eq:and-def}\n  \\f{and} &= \\lambda p. \\lambda q. p\\,q\\,p\n\\end{align}\n\nSimilarly, we can apply this idea to numerals to specify the\nbehavior of the \\f{plus} function.\n%\nIn this case, however, we cannot specify the behavior on all\npossible inputs but we can select a representative set.\n%\n\\begin{align*}\n  \\f{?plus}\\; 0\\; 1 &\\equiv 1\\\\\n  \\f{?plus}\\; 1\\; 0 &\\equiv 1\\\\\n  \\f{?plus}\\; 1\\; 2 &\\equiv 3\\\\\n  \\f{?plus}\\; 2\\; 2 &\\equiv 4\\\\\n\\end{align*}\n%\nThe above specification is sufficient for our tool to find\nthe definition:\n%\n\\begin{align}\n  \\label{eq:plus-def}\n  \\f{plus} &= \\lambda m. \\lambda n. \\lambda f. \\lambda x. m\\,f\\,(n\\,f\\,x)\n\\end{align}\n\n\n\n\\subsection{Beyond Extensionality}\n%\nThe specifications presented in the previous section only\nspell out the extensional behavior of functions.\n%\nWe found that it is also often useful to constraint the way\nfunctions evaluate.\n%\nThe ability to do so proved to be important for the\nspecification of encodings as we will see in\n\\cref{sec:co-synthesis}.\n\nRecall the resulting encoding for \\f{and} given in\n\\labelcref{eq:and-def}.\n%\nThis definition uses the first argument as the test.\n%\nUnder normal order evaluation, this corresponds to the usual\nshort-circuit evaluation where the second argument is only\nevaluated when the first one is known to be false.\n%\nThe purely extensional specification given in \\cref{sec:io}\ncannot distinguish this from a function that first\nevaluates the second argument:\n%\n\\begin{align}\n  \\label{eq:and-def2}\n  \\f{and} &= \\lambda p. \\lambda q. q\\,p\\,q\n\\end{align}\n%\nOne of our main insights is that this sort of evaluation\nbehavior can be specified using free variables.\n%\nFor example, the function \\f{and} could be specified as:\n%\n\\begin{align*}\n  \\f{?and}\\,\\true\\,x &\\equiv x \\\\\n  \\f{?and}\\,\\false\\,x &\\equiv \\false \\\\\n\\end{align*}\n%\nHere, the variable $x$ is meant to remain free as opposed to\n\\true and \\false which should be expanded to their\ndefinition.\n%\nThis specification effectively rule out\n\\labelcref{eq:and-def2} from the possible results.\n\nSimilarly, the specification for \\f{plus} in the previous\nsection cannot distinguish the definition in\n\\labelcref{eq:plus-def} from:\n%\n\\begin{align}\n  \\label{eq:plus-def2}\n  \\f{plus} &= \\lambda m.\\lambda n.\\lambda f.\\lambda x.n\\,f\\,(m\\,f\\,x)\n\\end{align}\n%\nThey differ in the order in which the arguments $m$ and $n$\nare applied to get the final result.\n%\nIn this case, we can give an alternative specification based\non the evaluation of \\f{plus} seen as a recursively-defined\nfunction:\n%\n\\begin{align*}\n  \\f{?plus}\\;0\\;y &\\equiv y \\\\\n  \\f{?plus}\\;(\\f{succ}\\;x)\\;y &\\equiv \\f{succ}\\;(\\f{?plus}\\;x\\;y)\n\\end{align*}\n%\nwhere \\f{succ} is the successor function defined as:\n%\n\\begin{align*}\n  \\f{succ} = \\lambda n. \\lambda f. \\lambda x. f\\,(n\\,f\\,x)\n\\end{align*}\n\nThis specification does not just fix the order in which $m$\nand $n$ are evaluated but also rule out various spurious\nresults which satisfy the incomplete specification given in\n\\cref{sec:io}.\n%\nHowever, checking conformance with this sort of\nspecifications is in general more challenging because it\nrequires $\\eta$-conversion.\n%\nTo see why consider the evaluation of the term in the first\nequivalence when we expand \\f{plus} with the definition in\n\\labelcref{eq:plus-def}.\n%\nUnder normal order, $\\f{plus}\\;0\\;y$ evaluates to $\\lambda\nf.\\lambda x. y\\,f\\,x$ which is only $\\eta$-equivalent to\n$y$.\n\n% We will be using input-output examples as our specification, so the\n%   behavioral constraints of our synthesis problem are simply the\n%   evaluation of our examples for a given term or function.\n% For instance, the input-output examples to synthesize \\textit{and}\n%   will look like $?and \\, true \\, true = true$,\n%   $?and \\, false \\, true = false$,\n%   $?and \\, true \\, false = false$, and\n%   $?and \\, false \\, false = false$, where the $?$ before \\texttt{and}\n%   signifies the function we are synthesizing.\n% Note that because there is no structural difference in untyped lambda\n%   calculus between functions and terms, there is no need to differentiate\n%   the two in our synthesizer.\n% Additionally, we are using a bottom-up search strategy with some\n%   special limitations on the form which are described in detail in\n%   section \\ref{sec:optimizations}.\n% We will generate terms from the untyped lambda calculus grammar, with\n%   the additional constraint that they must be in normal form.\n% Additionally, we will be generating terms using De Bruijn indices rather\n%   than with explicit variables names, in order to make evaluation of the\n%   terms easier (largely so we don't have to worry about alpha-renaming).\n", "meta": {"hexsha": "7086833f6436d1b05183e47676f50655ae2b3443", "size": 7643, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/synthesis.tex", "max_stars_repo_name": "DavidThien/elsa", "max_stars_repo_head_hexsha": "2bf97839d1fc210d12dac919b34ec4e0143f80e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/synthesis.tex", "max_issues_repo_name": "DavidThien/elsa", "max_issues_repo_head_hexsha": "2bf97839d1fc210d12dac919b34ec4e0143f80e6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/synthesis.tex", "max_forks_repo_name": "DavidThien/elsa", "max_forks_repo_head_hexsha": "2bf97839d1fc210d12dac919b34ec4e0143f80e6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2489451477, "max_line_length": 75, "alphanum_fraction": 0.7215752977, "num_tokens": 2160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515684, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7069095976076348}}
{"text": "\\lab{Applications}{Filtering and Convolution}{Filtering and Convolution}\n\\objective{This lesson demonstrates the use of the Fourier Transform for cleaning up noisy signals and finding convolutions of signals.}\n\n\\section*{Cleaning up a noisy signal}\n\nListen to \\texttt{Noisysignal1.wav} (see Figure \\ref{noisysignal}). This is a mono recording of a (probably familar) voice with some annoying noise over it. Fortunately for us, this noise is ``colored\", i.e. it only occurs over a limited range of frequencies. This makes it possible for us to remove it fairly easily without unduly damaging the underlying signal.\n\\begin{figure}[ht]\\caption{Noisy signal}\\label{noisysignal}\\centering\\includegraphics[width=\\textwidth]{noisy}\\end{figure}\nHow do we begin? First we examine the DFT of the signal in order to identify which frequencies make up the noise (see Figure \\ref{noisyspec}).\n\\begin{figure}[ht]\\caption{Spectrum of noisy signal}\\label{noisyspec}\\centering\\includegraphics[width=\\textwidth]{noisyspec}\\end{figure}\nWe notice a large band from 10000 to 20000 units which seems to be intruding in the spectrum. This is our noise. (The fact that it begins and ends so abruptly in the spectrum, instead of tapering off gradually, should be a clue that this noise was produced artificially, by the author of this lab, rather than arising in a natural way in the recording or transmission process.) To remove the noise, we simply zero out this part of the DFT and then take the inverse DFT (using the function \\texttt{spfft.ifft}) to get our cleaned-up signal. But we must remember to zero out the corresponding part in the right half of the DFT as well, in order to ensure that the inverse DFT of the result is a real-valued signal.\n\nIt is critical that the values zeroed in the right half of the DFT be precisely the mirror images of the zeroed in the left half: i.e., assuming the DFT of the signal is stored in the vector \\texttt{fsig}, if we set \\texttt{fsig[j]} to zero then we should also set \\texttt{fsig[-j]} to zero. If we are off on the index even just by one, then the result will not be a real valued signal and thus will not be playable.\n\nSo, we do the whole thing in Python like this:\n\\begin{lstlisting}\nrate,data = wavfile.read('Noisysignal1.wav')\nfsig = sp.fft(data,axis = 0)\nfor j in xrange(10000,20000):\n    fsig[j]=0\n    fsig[-j]=0\n\nnewsig=sp.ifft(fsig)\nnewsig = sp.real(newsig)\nnewsig = sp.int16(newsig/sp.absolute(newsig).max() * 32767)\n\\end{lstlisting}\n\nNow we can either save the resulting cleaned-up signal \\texttt{newsig} to a \\texttt{.wav} file using \\texttt{wavwrite}. If we plot it, the individual syllables are now visible in the waveform (see Figure \\ref{cleansignal}).\n\n\\begin{figure}[ht]\\caption{Cleaned-up \\texttt{Noisysignal1.wav} }\\label{cleansignal}\\centering\\includegraphics[width=\\textwidth]{Cleanedsignal}\\end{figure}\n\n\\begin{problem}\nListen to \\texttt{Noisysignal2.wav}. You will probably just hear noise. However, there is a signal behind it. Remove the noise using the technique described above. In order to make the cleaned-up signal audible. What does the voice say? Who is the speaker? (If you don't know the answer to this last question, try a quick Google search.)\n\\end{problem}\n\n\n\\section*{Filtering and Convolution}\n\nWe have already seen how the DFT can be used to filter out certain bands of frequencies from a signal. In this section we will look at how the DFT can be used to carry out another type of filtering effect. To begin, suppose we have a recording of musical piece played in, say, a small carpeted room with essentially no acoustics, and suppose we would like to apply an effect to make it sound as if the piece were played in a large concert hall (or some other room). How could we do that?\n\nThe first thing we need is a recording of the so-called \\emph{impulse response} of the room whose acoustics we are trying to imitate. This is a recording of how the room responds to a short pulse of sound. Effective ways of producing a loud sound approximating a pulse include firing a (blank) gunshot, popping a balloon, or, if neither of those are available, clapping the hands one time. You have probably noticed (or can imagine) that if you pop a balloon in large room, although the sound of the actual pop only lasts a few milliseconds, you can hear the sound echoing about the room for up to several seconds. This echoing sound is called the impulse response of the room. Actually, it is somewhat imprecise to refer to \\emph{the} impulse response of the room, since the recorded response can significantly depend both on the location of device producing the pulse and on location of the listener (or recording device) in the room.\n\nNow, the idea is that if we know how the room responds to a pulse, then we can reconstruct how the room will respond to any sound. This is because any sound can be considered to be a series of pulses of varying amplitudes and polarity (i.e., they may be positive or negative). Each sample of sound can be considered as a pulse, even though the ear will not perceive it that way, because the pulses are so close together. Now, we make the assumption that the room's response is linear, meaning that a pulse of $k$ times the amplitude will produce a response of $k$ times the amplitude but otherwise identical; such an assumption is generally reasonably accurate, assuming the pulse is not extremely loud. To calculate how the room responds to a complex sound consisting of millions of samples, we simply add up its response to each sample of the sound, each such response simply being a scaled copy of the impulse response which we recorded.\n\nThus, in our simulation, each sample of our sound (of which there are usually 44100 per second) triggers a new scaled copy of the room's impulse response. If the impulse response is several seconds long, that means there may be a hundred thousand or more scaled copies of the impulse response sounding at once, which must all be mixed together to produce the final sound. This may be starting to seem computationally infeasible or at least very difficult. The key is to recognize that this process can be described as a convolution: namely, the final sound is simply the convolution of the our original sound with the impulse response. We can calculate convolutions quickly using the convolution theorem which says\n\n\\[\\mathcal{F}(f \\ast g) = (\\mathcal{F} f) (\\mathcal{F} g)\\]\n\nwhere $\\mathcal{F}$ is the Fourier Transform and $\\ast$ is convolution.\n\nThus we calculate the convolution of two arrays by simply taking the fourier transform of each, multiplying them pointwise, and then taking the inverse transform.\n\n\\begin{problem}\n\\emph{This Problem is optional.  If the instructor does not require it then students may use the provided \\texttt{balloon.wav} file which contains the sound of a balloon pop in a large room.}\n\nFind a large room or area with good acoustics, and record (an approximation to) its impulse response using a balloon pop. To record the sound, you will want to use at least a decent microphone. You may want to record it using the program Audacity \\footnote{Audacity is free software and may be downloaded at http://audacity.sourceforge.net} and a laptop. If you use a unidirectional microphone, be sure the microphone is pointing at the balloon when you pop it, so that the direct sound from the pop is picked up. (If you don't, the result will still be okay. It's just that after we do the convolution, it will probably sound somewhat distant, as if we are at the back of the room, where we can't hear the music directly, only through the reverberation of the room.)\nIf you've chosen a good room, the response should be audible for at least a full second.\n\nInclude a plot of both the waveform and spectrum of the impulse response you recorded.\n\\end{problem}\n\n\n\\begin{problem}\\label{convolution_problem}\nDownload and listen to the file \\texttt{chopinw.wav}. You will hear a piano being played in a dead room with little or no acoustics. Using the Convolution Theorem, take the convolution of this signal with the impulse response recorded in the previous problem. Describe the resulting sound.\n\nIn doing this problem, keep in mind that the Convolution Theorem requires both signals to have the same length; therefore you will need to pad the smaller of your two signals (namely, the impulse response signal) with zeros at the end in order to make it the same size as the other signal. But the convolution of the Convolution Theorem is a circular convolution, which will mean that the room's response to a sound near the end of the signal will wrap around back to the beginning of the signal in the result. In order to avoid this undesired effect, you will want to also pad the signals with additional zeros (at least as many zeros as one less than the size of the impulse response signal).\n\\end{problem}\n\nIn doing the preceding problem, keep in mind that the Convolution Theorem requires both signals to have the same length; therefore you will need to pad the smaller of your two signals (namely, the impulse response signal) with zeros at the end in order to make it the same size as the other signal. But the convolution of the Convolution Theorem is a circular convolution, which will mean that the room's response to a sound near the end of the signal will wrap around back to the beginning of the signal in the result. In order to avoid this undesired effect, you will want to also pad the signals with additional zeros (at least as many zeros as one less than the size of the impulse response signal).\n\nIn some instances, a circular convolution is actually desirable. For instance, an interesting effect is achieved by taking the circular convolution of a long segment of white noise with some other (shorter) sound. We can create white noise using scipy's \\texttt{rand} function:\n\\begin{lstlisting}\n#samplerate = 22050\n#noise = sp.int16(sp.random.randint(-32767,32767,samplerate*10)) # Create 10 seconds of mono white noise\n\\end{lstlisting}\n\n\\begin{problem}\nCreate white noise in this way this and listen to the resulting sound (CAUTION: Turn your volume way down.  It may be very very loud).  This kind of noise is called ``white\" because it contains all frequencies (below the Nyquist frequency) with the same strength, or rather, with the same expected strength (since the amplitude of a specific frequency is a matter of chance). In order to see this, plot the spectrum of the noise.\n\\end{problem}\n\nNow we are going to take the circular convolution of this noise with some other sound. For instance, let's use \\texttt{Tada.wav}. The result is in \\texttt{tada-conv.wav}. We notice that the original short sound has been sustained to an indefinite length. The result is not a set of static tones, but rather a rich sound which preserves not only the tones, but the texture, of the original sound; you can hear different tones fluctuating randomly in amplitude over time. If you were to play this \\texttt{tada-conv.wav} on repeat, you would find that, because we used a circular convolution, the sound loops seamlessly from the end back to the beginning; however, most sound players are not capable of doing this properly, so you will probably hear a break in the sound. To demonstrate the ``seamlessness\", we can paste together three copies of the sound consecutively:\n\n\\begin{lstlisting}\nrate, sig = wavfile.read('tada-conv.wav')\nsig = sp.append(sig,sig)\nsig = sp.append(sig,sig)\n\\end{lstlisting}\n\nListen to the resulting sound, and notice that we are not able to identify where the sound loops back to the beginning, because there is no break or click.\n\n\\begin{problem}\nRecord yourself singing a few notes (or, feel free to produce some other sound another way). Take the circular convolution of white noise with this recording. Now do it again using stereo white noise, which you can create, e.g., by doing \\texttt{noise = sp.float16(sp.random.randint(-32767,32767,(samplerate*10,2)))}. It's no problem that your original recording will probably be mono; just make the left and right channels duplicate in the recording (but: be sure to use different left and right channels for the white noise). Can you hear any difference between the mono and stereo versions of the result?\n\\end{problem}\n\nFeel free to play around with this. The file \\texttt{guitar-conv.mp3} is a collage of sounds created using this technique (mostly using guitar samples). You could probably think of other lots of other things you can do with this.\n\n\n%\\begin{problem}\n%Using the algorithm described in the lecture notes, implement your own Inverse Fast Fourier Transform (IFFT) in MATLAB from scratch. You may assume that $N$ is a power of 2. Test it on several random vectors and make sure the results match those of MATLAB's \\texttt{ifft}. It should have $O(N\\log N)$ running time. Now, by adjusting your IFFT, implement the FFT, and redo Problem \\ref{convolution_problem} using the FFT and IFFT which you have implemented. Use \\texttt{tic} and \\texttt{toc} to measure how long it takes to finish, against how long it took using MATLAB's \\texttt{fft} and \\texttt{ifft}.\n%\\end{problem}\n%\n%It is possible to implement your \\texttt{fft} and \\texttt{ifft} using vector operations, which will speed things up; however, one could hardly expect to beat MATLAB's \\texttt{fft} and \\texttt{ifft}, which are implemented by calling the extremely well-optimized FFTW library (Fastest Fourier Transform in the West).\n\n\n\n", "meta": {"hexsha": "1ae02d7d044ab683554208a7a1f64b93a40f6666", "size": 13449, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/FFT/Filtering_and_Convolution.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/FFT/Filtering_and_Convolution.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/FFT/Filtering_and_Convolution.tex", "max_forks_repo_name": "lcbendall/numerical_computing", "max_forks_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 128.0857142857, "max_line_length": 940, "alphanum_fraction": 0.7846680051, "num_tokens": 3122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733963661418, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7069095858122253}}
{"text": "\\documentclass{article}\n\n\\usepackage[letterpaper, margin=1.3cm]{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage{siunitx}\n\\usepackage{mathtools}\n\\usepackage{multicol}\n\n\\title{ECE 240 Assignment 8}\n\\author{Michael Kwok}\n\\begin{document}\n\n\\maketitle\n\\begin{multicols}{2}\n\\section*{1}\n\\begin{align*}\nF(s) &= \\int_{0^-}^\\infty f(t)e^{-st}dt\\\\\n&= \\int_{0^-}^\\infty \\left(e^{2t} -2e^{-t}\\right)e^{-st} u(t)dt\\\\\n&= \\int_{0}^\\infty e^{-(s-2)t}dt - 2\\int_{0}^\\infty e^{-(1+s)t}dt\\\\\n&= \\left[\\frac{1}{s-2}e^{-(s-2)t}\\right]^\\infty_0 + \\left[ \\frac{1}{1+s}e^{-(s+1)t}\\right]^\\infty_0\n\\end{align*}\n\nThe first expression is only convergent when $s-2 > 0$. Since $s = \\sigma + j\\omega$, the region of convergence will be calculated by the following:\n \n\\begin{align*}\n    \\sigma -2 &> 0\\\\\n    \\sigma &> 2\n\\end{align*}\n\nSo assuming $\\sigma > 2$,\n\n\\begin{align*}\n    F(s) &= \\frac{1}{s-2} \\lim_{t \\to \\infty} \\left( e^{-(s-2)t} -1 \\right)\\\\\n    &+ \\frac{2}{s+1} \\lim_{t \\to \\infty} \\left( e^{-(s+1)t} -1 \\right)\\\\\n    &= \\boxed{\\frac{1}{s-2} - \\frac{2}{s+1}}\n\\end{align*}\n\\section*{2}\n\\begin{align*}\n    f(t) &= \\int_0^1 te^{-t}dt + \\int_1^\\infty e^{-t}dt\\\\\n    &= e^{-1}\\left(\\frac{1}{2} - 0\\right) + \\lim_{t\\to\\infty}\\left(-e^{-t} + e^{-1}\\right)\\\\\n    &= \\frac{1}{2} e^{-1} + e^{-1}\\\\\n    &= \\boxed{\\frac{3}{2}e^{-1}}\n\\end{align*}\n\\section*{3}\n\\subsection*{a}\n\\begin{align*}\n    f_1(t) &= \\sin\\left[\\omega_0(t-\\tau)\\right]u(t-\\tau)\\\\\n    F_1(s) &= \\boxed{\\frac{\\omega_0}{s^2 + \\omega_0^2} e^{-s\\tau}}\n\\end{align*}\n\\subsection*{b}\n\\begin{align*}\n    f_1(t) &= \\sin\\left[\\omega_0(t-\\tau)+\\omega_0\\tau\\right]u(t-\\tau)\\\\\n    &= \\sin\\left[\\omega_0(t-\\tau)\\right]\\cos(\\omega_0\\tau)u(t-\\tau)\\\\\n    &+ \\cos\\left[\\omega_0(t-\\tau)\\right]\\sin(\\omega_0\\tau)u(t-\\tau)\\\\\n    F_1(s) &= \\cos(\\omega_0\\tau)\\frac{\\omega_0}{s^2 + \\omega_0^2} e^{-s\\tau}\\\\\n    &+ \\boxed{\\sin(\\omega_0\\tau)\\frac{s}{s^2 + \\omega_0^2} e^{-s\\tau} }\n\\end{align*}\n\\section*{4}\n\\begin{align*}\n    g(t) &= f(t) + f(t-T_0) + f(t-2T_0) + \\ldots\\\\\n    G(s) &= F(s) + F(s)e^{-sT_0} + F(s)e^{-s2T_0} + \\ldots\\\\\n\\end{align*}\nLet $x = e^{-sT_0}$\n\\begin{align*}\n    G(s) &= F(s)\\left(1+x+x^2+x^3+\\ldots\\right)\\\\\n    &= \\frac{F(s)}{1+x}\\\\\n    &= \\boxed{\\frac{F(s)}{1+e^{-sT_0}}}\n\\end{align*}\n\\section*{5}\n\\begin{align*}\n    f(t) &= t\\left[ u(t) - u(t-2) \\right] + \\left( -2t+6 \\right)\\left[ u(t-2) - u(t-3) \\right]\\\\\n    f(0^{-}) &= 0\\\\\n    f'(t)&= u(t)-u(t-2)-2u(t-2)+2u(t-3)\\\\\n    &+6\\delta(t-2)-6\\delta(t-3)\\\\\n    \\mathcal{L}\\{ f'(t)\\} &= sF(s)-f(0^-)\\\\\n    sF(s) &= \\frac{1}{s} - \\frac{1}{s} e^{-2s} - \\frac{2}{s} e^{-2s} + \\frac{2}{s} e^{-3s} +6e^{-2s} -6e^{-3s}\\\\\n    F(s) &= \\boxed{\\frac{1}{s^2}-\\frac{3}{s^2}e^{-2s}+\\frac{2}{s^2}e^{-3s} + \\frac{6}{s}e^{-2s} - \\frac{6}{s}e^{-3s}}\n\\end{align*}\n\\end{multicols}\n\\end{document}\n", "meta": {"hexsha": "1adf8a34418b97960f4f0551a7747c40951cf0bb", "size": 2765, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/ECE240/ECE240As8.tex", "max_stars_repo_name": "n30phyte/SchoolDocuments", "max_stars_repo_head_hexsha": "79652ec7e3345d67e67f0cffe3bea468708622bd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Assignments/ECE240/ECE240As8.tex", "max_issues_repo_name": "n30phyte/SchoolDocuments", "max_issues_repo_head_hexsha": "79652ec7e3345d67e67f0cffe3bea468708622bd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Assignments/ECE240/ECE240As8.tex", "max_forks_repo_name": "n30phyte/SchoolDocuments", "max_forks_repo_head_hexsha": "79652ec7e3345d67e67f0cffe3bea468708622bd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.1358024691, "max_line_length": 148, "alphanum_fraction": 0.5345388788, "num_tokens": 1331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7069095823476792}}
{"text": "\\section{Finite Sets}\n\n\\begin{definition}\n  A set is said to be \\textbf{finite} if there is a bijective correspondence of\n  $A$ with some section of the positive integers. That is, $A$ is finite if it\n  is empty or if there is a bijection\n  \\begin{equation}\n    f:A \\to \\pbrac{1, \\dots, n}\n  \\end{equation}\n  for some positive integer $n$. In the former case, we say that $A$ as\n  \\textbf{cardinality 0}, and in the latter case, we say that $A$ has\n  \\textbf{cardinality $n$}.\n\\end{definition}\n\n\\section*{Exercises}\n\n\\bx{\n  \\ea{\n    \\item There are $4 \\times 3 \\times 2 = 24$ injective mappings,\n    \\begin{align*}\n      (1, 1), (2, 2), (3, 3)\\\\\n      (1, 1), (2, 2), (3, 4)\\\\\n      (1, 1), (2, 3), (3, 2)\\\\\n      (1, 1), (2, 3), (3, 4)\\\\\n      (1, 1), (2, 4), (3, 2)\\\\\n      (1, 1), (2, 4), (3, 3)\\\\\n      (1, 2), (2, 1), (3, 3)\\\\\n      (1, 2), (2, 1), (3, 4)\\\\\n      (1, 2), (2, 3), (3, 1)\\\\\n      (1, 2), (2, 3), (3, 4)\\\\\n      (1, 2), (2, 4), (3, 1)\\\\\n      (1, 2), (2, 4), (3, 3)\\\\\n      (1, 3), (2, 1), (3, 2)\\\\\n      (1, 3), (2, 1), (3, 4)\\\\\n      (1, 3), (2, 2), (3, 1)\\\\\n      (1, 3), (2, 2), (3, 4)\\\\\n      (1, 3), (2, 4), (3, 1)\\\\\n      (1, 3), (2, 4), (3, 2)\\\\\n      (1, 4), (2, 1), (3, 2)\\\\\n      (1, 4), (2, 1), (3, 3)\\\\\n      (1, 4), (2, 2), (3, 1)\\\\\n      (1, 4), (2, 2), (3, 3)\\\\\n      (1, 4), (2, 3), (3, 1)\\\\\n      (1, 4), (2, 3), (3, 2)\n    \\end{align*}\n    \\item $10 \\cdot 9 \\cdot \\dots \\cdot 3 = 1814400$ \\dots, you can tell this is not a fun time.\n  }\n}\n\n\\bx{\n  AFSOC $A$ is finite. Then $B$ must be finite since it is a subset of $A$, but this is a contradiction since $b$ is not finite by assumption.\n}\n\n\\bx{\n  Let the propr subset be $X^\\omega - {0, 0, \\dots}$.\n  Let the bijection be\n  \\begin{align*}\n    f(000000\\dots) &= 1000000\\dots\\\\\n    f(100000\\dots) &= 0100000\\dots\\\\\n    f(110000\\dots) &= 0010000\\dots\\\\\n    &\\cdots\n  \\end{align*}\n  It’s just binary written in R to L significant digits, + 1 to shift for the missing $000\\dots$.\n}\n\n\\bx{\n  \\ea{\n    \\item Induction from empty set as base case. Adding an element gives you two\n    cases, either the new element is the largest, or the existing largest\n    element remains the largest.\n    \\item \\TODO: What is an order type? I think the idea here is map $A$ into $\\mathbb{Z}$ in the order that the elements are in $A$, and then they will have the order type of the $\\Zp$.\n  }\n}\n\n\\bx{\n  No. $A = \\emptyset$ and $B$ could be infinite.\n}\n\n\\bx{\n  \\ea{\n    \\item $X^n$ is basically an $n$-tuple showing whether or not an element of A is included in the set, so you can make that bijection to $\\mathcal{P}(A)$.\n    \\item $\\mathcal{P}(A)$ has a bijection with $X^n$, which is finite, so $\\mathcal{P}(A)$ is finite as well.\n  }\n\n  \\label{chap1:sec6:prob6}\n}\n\n\\bx{\n  Consider $C = A \\times B$. Any function $f$ is some subset of $C$. Then the\n  set of all functions is a subset of $\\mathcal{P}(C)$, which from \\ref{chap1:sec6:prob6}\n  we know is finite since $C$ is finite.\n}\n", "meta": {"hexsha": "86ceadf119a3bbbde2801d6d2a8d3bde16e592c3", "size": 2949, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter1/chapter1-6.tex", "max_stars_repo_name": "mikinty/Topology-Munkres-Solutions", "max_stars_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2021-07-02T05:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T04:11:03.000Z", "max_issues_repo_path": "chapters/chapter1/chapter1-6.tex", "max_issues_repo_name": "mikinty/Topology-Munkres-Solutions", "max_issues_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter1/chapter1-6.tex", "max_forks_repo_name": "mikinty/Topology-Munkres-Solutions", "max_forks_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7096774194, "max_line_length": 186, "alphanum_fraction": 0.5422177009, "num_tokens": 1235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505964, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7069095791034671}}
{"text": "\n\\subsection{Robust principal component analysis}\n\n\\subsubsection{Robust PCA}\n\nRobust PCA can be used to deal with corrupted data, such as corrupted image data.\n\nRather than data \\(X\\) we have \\(M=L_0+S_0\\) where \\(L_0\\) is what we want to recover (and is low rank), and \\(S_0\\) is noise (and sparce).\t\n\nIn video footage, \\(L_0\\) can correspond to the background, while \\(S_0\\) corresponds to movement.\n\n", "meta": {"hexsha": "d877f016920002c95af1bc29f2f42379f76df5b7", "size": 404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/dimensionality/01-02-robust.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/dimensionality/01-02-robust.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/dimensionality/01-02-robust.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.6666666667, "max_line_length": 140, "alphanum_fraction": 0.7277227723, "num_tokens": 110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8397339516289535, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7069095723506423}}
{"text": "\\chapter[Residues]{Evaluating Contour Integrals Using Residues}\n\\section{Motivation}\nLet $\\mathcal{C}$ be a simple, closed anticlockwise contour.  In the previous section we saw how certain integrals of the form\n\\[\n\\int_{\\mathcal{C}} f\n\\]\nmay be calculated using Cauchy's Integral Formula, when $f$ is a function holomorphic on region $\\mathcal{R} \\backslash \\set{z_0}$ with $z_0$ a point enclosed by $\\mathcal{C}$.  However, this does not always work, as the following example illustrates.\n\\begin{example}\n\\label{e:gdef}\nCauchy's Integral Formula does not allow us to compute $\\int_{\\cont} f$, where $\\mathcal{C}$ is the anticlockwise unit circle and $f$ is the function defined by\n\\[\nf(z) = \\frac{1}{z^2+\\frac{1}{4}} = \\frac{1}{(z+\\frac{i}{2})(z-\\frac{i}{2})},\n\\]\nas there are two points enclosed by $\\cont$ at which $f$ is not holomorphic. \n\\begin{blankbox}\n\\begin{center}\n\\altgraphics[scale=1]{ch6_shrink1_full}{ch6_shrink1}\n\\end{center}\nDraw the line $L=[-1,1]$ to get two new closed anticlockwise contours $\\mathcal{C}_1$ and $\\mathcal{C}_2$, with $\\mathcal{C}_1$ enclosing $i/4$ and $\\mathcal{C}_2$ enclosing $-i/4$.  Then\n\\[\n\\int_{\\mathcal{C}} f = \\int_{\\mathcal{C}_1} f + \\int_{\\mathcal{C}_2} f,\n\\]\nsince the integral along $L$ in $\\mathcal{C}_1$ and the integral along $\\tilde{L}$ in $\\mathcal{C}_2$ cancel.  We can then use Cauchy's Integral Formula to evaluate each of $\\displaystyle \\int_{\\mathcal{C}_1} f$ and $\\displaystyle \\int_{\\mathcal{C}_2} f$ separately.\n\\end{blankbox} \n\\end{example}\nWe will assume without proof that the method we have just described will extend to the case when there is any finite number of points enclosed by $\\mathcal{C}$ at which $f$ is not holomorphic:\n\n\n\n\n\n\\begin{theorem}[Generalised Shrinking Contour/ Deformation Theorem; proof non-examinable]\n\\label{t:gdef}\nLet $\\mathcal{R}$ be a simply connected region, $\\mathcal{C}$ a simple, closed anticlockwise contour in $\\mathcal{R}$, and $z_1,z_2,\\ldots,z_n$ a finite collection of points that are enclosed by $\\mathcal{C}$.  If $f$ is holomorphic on $\\mathcal{R} \\backslash \\set{z_1,\\ldots,z_n}$, then \n\\[\n\\int_{\\mathcal{C}} f = \\int_{\\mathcal{C}_1}f+ \\ldots + \\int_{\\mathcal{C}_n} f,\n\\]\nwhere each $\\mathcal{C}_j$ is a closed simple anticlockwise circular contour enclosing $z_j$ and no other $z_k$.\n\\end{theorem}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{ch6_residues2}\n\\caption{A contour $\\mathcal{C}$ enclosing points $z_1,z_2,z_3$ and $z_4$ at which $f$ is not holomorphic.  The integral of $f$ along $\\mathcal{C}$ is determined by the integrals along the circular contours enclosing these points.}\n\\end{figure}\n\n Theorem~\\ref{t:gdef} allows us, as least in principle, to evaluate each $\\int_{\\mathcal{C}_j} f$ separately to obtain $\\int_{\\mathcal{C}} f$.  Thus we have essentially reduced the problem to that of evaluating integrals where there is one point enclosed by the given contour at which $f$ is not holomorphic.  \n \n This approach will not always work, however. \n  \n\\begin{example}\nLet $f: \\C \\backslash \\set{0} \\to \\C$ be defined by\n\\[\nf(z) = \\frac{\\sin(z)}{z^2},\n\\]\nand let $\\mathcal{C}$ be any anticlockwise closed circular contour centred at $0$.\nWe cannot write\n\\[\n\\frac{\\sin (z)}{z^2} = \\frac{g(z)}{(z-z_0)}\n\\]\nfor any $z_0$ enclosed by $\\mathcal{C}$ and $g$ holomorphic on a simply connected region containing $\\mathcal{C}$.  Indeed the obvious choice would be to take $z_0=0$, but then we would have to define $g(z) = \\dfrac{\\sin(z)}{z}$, which still fails to be holomorphic on a suitable region.\n\\end{example}\n\n\n\n\\section{Singulairities of complex functions}\nTheorem~\\ref{t:gdef} shows that when calculating the integral of $f$ along a simple, anticlockwise, closed contour $\\mathcal{C}$, the value $\\int_{\\mathcal{C}} f$ is in some sense depends only on those points at which $f$ is not holomorphic.  Therefore, we shall study these points in more detail.\n\n\\begin{definition}\nA function $f$ has an \\emph{isolated singularity} at the point $z_0$ if for some $r>0$, $f$ is holomorphic on a punctured disc $D'(z_0,r)$ but not on the (unpunctured) open disc $D(z_0,r)$.\n\\end{definition}\nNote that if $f$ has an isolated singularity at $z_0$, it may be the case that $f$ is not defined at $z_0$, or $f$ is defined at $z_0$ but not differentiable there.\n\n\\begin{example}\nThe function $f$ defined by\n\\[\nf(z) = \\frac{1}{z^4+1}\n\\]\nhas isolated singularities at the points $e^{i\\pi/4},\\ e^{3i\\pi/4},\\ e^{5i\\pi/4},\\ e^{7i\\pi/4}$; in each case, take $r = \\frac{1}{4}$ for example.\n\\begin{center}\n\\includegraphics[scale=1]{ch6_poles1}\n\\end{center}\n%\\vspace*{2cm}\n\n\\end{example}\n\\begin{example}\nThe function $f$ defined by\n\\[\nf(z) = \\frac{\\sin (z)}{z^2}\n\\]\nhas an isolated singularity at $0$.\n\\end{example}\n\\begin{example}\nThe Principal Logarithm function $\\Log : \\C \\backslash \\set{0}$ defined by\n\\[\n\\Log (z) = \\log(\\abs{z}) + i \\Arg (z),\n\\]\nis not holomorphic at any point on the negative real axis.  No such point is an isolated singularity of $\\Log$\n\\end{example}\n\\begin{blankbox}\n\\begin{center}\n\\includegraphics[scale=0.5]{ch6_non_iso_full}\n\\end{center}\nIndeed, if $t \\leq 0$ is a point on the negative real axis and $r>0$, then $D'(t,r)$ contains points at which $\\Log$ is not holomorphic; $z=t-\\frac{r}{2}$ for example.\n%\\vspace*{3cm}\n\\end{blankbox}\n\\begin{definition}  \nLet $f$ be continuous on $\\mathcal{R} \\backslash \\set{z_0}$. We say that $\\displaystyle \\lim_{z \\to z_0} f(z) = \\infty$ if given any $M>0$ there is some $r>0$ such that\n\\[\n\\abs{f(z)}>M \\text{ for all } z \\in D'(z_0,r).\n\\]\n\\end{definition}\n\\begin{example}\n\nConsider the function\n\\[\nf(z) = \\frac{1}{(z-2i)^3}\n\\]\nwhich has an isolated singularity at $2i$.  We will show that $\\displaystyle \\lim_{z \\to 2i} f(z) = \\infty$.\n\\end{example}\n\\begin{solution}\n\nIndeed, given $M>0$, let $r=M^{-1/3}$.  Then \n\\begin{align*}\n0 < \\abs{z-2i} < r \\Rightarrow \\abs{f(z)} &= \\abs{\\frac{1}{(z-2i)^3}}\\\\\n& = \\frac{1}{\\abs{z-2i}^3} \\\\\n& > \\frac{1}{(M^{-1/3})^3} = M.\n\\end{align*}\n\\end{solution}\nIn most of the examples that we consider, $\\displaystyle \\lim_{z \\to z_0} f(z) = \\infty$ will occur whenever evaluating $f$ at $z_0$ would involve division by $0$ (except when $\\frac{0}{0}$ would appear).  We shall make this more precise shortly.\n\n\\begin{definition}\nA function $f$ with an isolated singularity $z_0$ is said to have a \\emph{pole at $z_0$} if\n\\[\n\\lim_{z \\to z_0} f(z) = \\infty.\n\\]\nMoreover, for $n \\geq 1$, $f$ is said to have a \\emph{pole of order $n$} at $z_0$ if for some $r>0$, $f$ can be represented in the form\n\\[\nf(z) = \\frac{g(z)}{(z-z_0)^n}\\quad\\text{ for all } z \\in D'(z_0,r)\n\\]\nwhere $g$ is holomorphic on $D(z_0,r)$ and $g(z_0) \\neq 0$.\n\\end{definition}\nNote that the representation\n\\[\nf(z) = \\frac{g(z)}{(z-z_0)^n}\n\\]\nneed not be valid everywhere on the domain of $f$, only inside the `small' disc $D(z_0,r)$.  The function $g$, unlike $f$, is both defined and differentiable at $z_0$.\n\n\\begin{example}\nLet us return to the example of\n\\[\nf(z) = \\frac{1}{1+z^4}\n\\]\nand investigate the pole $z_1 = e^{i\\pi/4}$ of $f$.\n\\end{example}\n\\begin{solution}\nDenote by $z_2,z_3$ and $z_4$ the other complex $4^{th}$ roots of $-1$, and let $g$ be the function defined by\n\\[\ng(z) = \\frac{1}{(z-z_2)(z-z_3)(z-z_4)}.\n\\]\nThen $g$ is holomorphic on $\\C \\backslash \\set{z_2,z_3,z_4}$, and in particular, holomorphic on $D(z_1,\\frac{1}{2})$ for example (the precise value of $r>0$ is not important).\n\\begin{center}\n\\includegraphics[scale=1]{ch6_poles2}\n\\end{center}\nMoreover, $g(z_1) \\neq 0$ and\n\\[\nf(z) = \\frac{g(z)}{z-z_1} \\quad \\text{ for all }\\quad z \\in D'(z_1,\\tfrac{1}{2}).\n\\]\nThis shows that $f$ has a pole of order $1$ at $z_1$.\n\\end{solution}\n\n\n\n\n\n%\\vspace*{5cm}\n\n\n\n\\begin{example}\n\\label{e:poles2}\nLet us investigate the poles of  the function\n\\[\nf(z) = \\frac{1}{(z^2+9)^2}.\n\\]\n\\end{example}\n\\begin{solution}\n%\\vspace*{12cm}\nUsing the factorisation\n\\[\nz^2+9 = (z+3i)(z-3i)\n\\]\nwe have\n\\[\nf(z)= \\frac{1}{(z+3i)^2(z-3i)^2}\n\\]\nso that $f$ has isolated singularities at $\\pm 3i$.\n\nIf we define the function $g_1$ by\n\\[\ng_1(z) = \\frac{1}{(z+3i)^2}\n\\]\nthen $g_1$ is holomorphic on $\\C \\backslash \\set{-3i}$ and in particular, holomorphic at $3i$ (that is, holomorphic on some open disc centred at $3i$, for example, $D(3i,1)$).  Since\n\\[\ng_1(3i) = - \\frac{1}{36} \\neq 0 \\quad\\text{ and }\\quad f(z) = \\frac{g_1(z)}{(z-3i)^2} \\quad\\text{ for } z \\in D'(3i,1)\n\\]\nwe see that $f$ has a pole of order $2$ at $z=3i$.\n\nSimilarly, by considering the function $g_2$ defined by\n\\[\ng_2(z) = \\frac{1}{(z-3i)^2}\n\\]\nwe see that $g_2$ is holomorphic and nonzero at $z=-3i$ and\n\\[\nf(z) = \\frac{g_2(z)}{(z+3i)^2}\\quad\\text{ for }\\quad z \\in D'(-3i,1)\n\\]\nso that $f$ has a pole of order $2$ at $z=-3i$ also.\n\\end{solution}\n\n%\\newpage\n\\section{The Residue Theorem}\n\n\\begin{definition}\nLet $f$ have an isolated singularity at $z_0$, then we define the \\emph{residue of $f$ at $z_0$}, denoted by $\\Res (f;z_0)$, to be\n\\[\n\\Res (f;z_0) = \\frac{1}{2\\pi i} \\int_{\\mathcal{C}} f\n\\]\nwhere $\\mathcal{C}$ is an anticlockwise simple closed contour which contains $z_0$ and no other singularities of $f$, and lies inside a region in which $f$ is holomorphic.\n\\end{definition}\nIf $f$ has an isolated singularity at $z_0$, then such a contour $\\mathcal{C}$ can always be found.  Indeed, we know that $f$ is holomorphic on the punctured disc $D'(z_0,r)$ for some $r>0$.  Thus we may take $\\mathcal{C}$ to be the anticlockwise circle with centre $z_0$ and radius $r/2$.\n\n\nFor example, we have seen before that with $\\mathcal{C}$ the anticlockwise unit circle,\n\\[\n\\int_{\\mathcal{C}} \\frac{1}{z}\\ dz=2\\pi i \\quad \\text{ and} \\quad \\int_{\\mathcal{C}} \\frac{1}{z^2}\\ dz = 0.\n\\]\nThus for the functions $f$ and $g$ defined by $f(z)=\\dfrac{1}{z}$ and $g(z) = \\dfrac{1}{z^2}$ we have\n\\[\n\\Res (f;0)=1 \\quad \\text{ and } \\quad \\Res (g;0) = 0.\n\\]\n%\\vspace*{7cm}\n\n\nTheorem~\\ref{t:residue} is essentially a reformulation of the Generalised Deformation Theorem (Theorem~\\ref{t:gdef}), and generalises Cauchy's Integral Formula.\n\\begin{theorem}[The Residue Theorem]\n\\label{t:residue}\nLet $\\mathcal{R}$ be a simply connected region and let $f$ be a function that is holomorphic on the region $\\mathcal{R} \\backslash \\set{ z_1,z_2,\\ldots , z_n}$ and has isolated singularities at the points $z_1,z_2,\\ldots,z_n$. If $\\mathcal{C}$ is an anticlockwise simple closed contour that lies in $\\mathcal{R}\\backslash \\set{z_1,z_2,\\ldots,z_n}$ and encloses the points $z_1,z_2,\\ldots,z_n$, then\n\\[\n\\int_{\\mathcal{C}} f = 2 \\pi i \\left( \\Res (f;z_1)+\\Res (f;z_2) + \\ldots + \\Res (f;z_n ) \\right).\n\\]\n\\end{theorem}\nIn other words\n\\[\n\\int_{\\mathcal{C}} f = 2\\pi i \\left( \\text{ sum of residues of $f$ at isolated singularities enclosed by $\\mathcal{C}$ } \\right)\n\\]\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{ch6_residues2}\n\\caption{At each singularity $z_j$, the residue of $f$ at $z_j$ is given by the the integral of $f$ along the small circular contour surrounding $z_j$ (divided by $2\\pi i$).  The integral of $f$ along $\\mathcal{C}$ is then determined by these residues.}\n\\end{figure}\n\nWe want to use the Residue Theorem to evaluate contour integrals.  The theorem may not look particularly useful yet, since residues themselves are defined to be integrals along circular contours.  However, the following two theorems show us that certain residues may be calculated without performing any integration.\n\n\n\n\nWe will need the following Lemma, the proof of which is omitted.\n\\begin{lemma}[Proof non-examinable]\n\\label{l:goverh}\nSuppose that $z_0 \\in \\C$, $h$ is holomorphic at the point $z_0$ with $h(z_0)=0$ and $h'(z_0) \\neq 0$.  Then there is some $\\delta>0$ and a holomophic function $k:D(z_0,\\delta) \\to \\C$ with $k(z) \\neq 0$ and $h(z)=(z-z_0)k(z)$ for all $z \\in D(z_0,\\delta)$.\n\\end{lemma}\n\\begin{theorem}[The $g/h$ rule]\n\\label{t:goverh}\nLet $z_0 \\in \\C,\\ r>0$ and let $f$ be holomorphic on $D'(z_0,r)$. Suppose that $f$ can be represented by\n\\[\nf(z) = \\frac{g(z)}{h(z)}\\quad \\text{ for } z \\in D'(z_0,r)\n\\]\nwhere $g$ and $h$ are holomorphic on $D(z_0,r)$, and $g(z_0) \\neq 0$, $h(z_0)=0$ and $h'(z_0) \\neq 0$. Then\n\\begin{enumerate}\n\\item[(i)] The function $f$ has an isolated singularity, and in particular, a  pole of order one at $z_0$.\n\\item[(iii)] The residue of $f$ at $z_0$ is given by\n\\[\n\\Res (f,z_0) = \\frac{g(z_0)}{h'(z_0)}.\n\\]\n\\end{enumerate}\n\\end{theorem}\n\\begin{proof}\nBy Lemma~\\ref{l:goverh} we obtain $\\delta>0$ (making $\\delta<r$ if necessary) and $k:D(z_0,\\delta)\\to \\C$, with $k$ holomorphic and nonzero on $D(z_0,\\delta)$ and\n\\[\nf(z)= \\frac{g(z)}{k(z)}\\cdot \\frac{1}{(z-z_0)} \\quad \\text{ for all } z \\in D'(z_0,\\delta).\n\\]\nSince $k(z) \\neq 0$ for all $z \\in D(z_0,\\delta)$ the function $z \\mapsto \\frac{g(z)}{k(z)}$ is holomorphic on $D(z_0,\\delta)$, and since $g(z_0) \\neq 0$, $f$ has a pole of order $1$ at $z_0$.\n\nIf $\\mathcal{C}$ is the anticlockwise circle with centre $z_0$ and radius $r/2$, then Cauchy's Integral Formula gives\n\\[\n\\Res (f;z_0) = \\frac{1}{2\\pi i} \\int_{\\mathcal{C}} f = \\frac{1}{2\\pi i} \\int_{\\mathcal{C}} \\frac{g(z)}{k(z)} \\cdot \\frac{1}{z-z_0}\\ dz = \\frac{g(z_0)}{k(z_0)}.\n\\]\nBut then by the product rule, $h'(z) = k(z)+(z-z_0)k'(z)$ for all $z \\in D(z_0,\\delta)$, so that $h'(z_0) = k(z_0)$, thus\n\\[\n\\Res (f;z_0) = \\frac{g(z_0)}{h'(z_0)}.\n\\]\n\\end{proof}\n\n\n\n\\begin{example}\nLet us calculate the residues at the poles of the function $f$ defined by\n\\[\nf(z) = \\frac{1}{1+z^2}.\n\\]\n\\end{example}\n\\begin{solution}\n%\\vspace*{12cm}\nWith $g(z)=1$ and $h(z)=1+z^2$, we have $h(z)=0$ at $z=\\pm i$, and $h'(z)=2z \\neq 0$ at these points.\nHence $f$ has poles of order $1$ at $z=\\pm 1$, with residues\n\\begin{align*}\n\\Res (f;i ) & = \\frac{g(i)}{h'(i)} = \\frac{1}{2i} = - \\frac{i}{2} \\\\\n\\Res (f;-i) & = \\frac{g(-i)}{h'(-i)} = \\frac{1}{-2i} = \\frac{i}{2}.\n\\end{align*}\n\nConsider the simple, closed anticlockwise contours $\\mathcal{C}_1,\\mathcal{C}_2$ and $\\mathcal{C}_3$ shown below.\n\\begin{center}\n\\begin{tabular}{ccc}\n\\includegraphics[scale=0.45]{ch6_res1full} & \\includegraphics[scale=0.45]{ch6_res2full} & \\includegraphics[scale=0.45]{ch6_res3full}\n\\end{tabular}\n\\end{center}\nBy the Residue Theorem, we have\n\\begin{align*}\n\\int_{\\mathcal{C}_1} f &= 2\\pi i \\left[ \\Res (f;i) \\right] = 2\\pi i \\left[ \\frac{-i}{2} \\right] = \\pi \\\\\n\\int_{\\mathcal{C}_2} f &= 2\\pi i \\left[ \\Res (f;-i) \\right] =2\\pi i \\left[ \\frac{i}{2} \\right] = -\\pi\\\\\n\\int_{\\mathcal{C}_3} f &= 2\\pi i \\left[ \\Res (f;i)+\\Res(f;-i) \\right] = 2\\pi i \\left[ -\\frac{i}{2} + \\frac{i}{2} \\right] = 0,\n\\end{align*}\nsince $\\mathcal{C}_1$ encloses the singularity $z=i$ and no others, $\\mathcal{C}_2$ encloses the singularity $z=-i$ and no others, and $\\mathcal{C}_3$ encloses the singularities $z=i$ and $z=-i$.\n\\end{solution}\n\\begin{example}\nLet us do the same for the function\n\\[\nf(z) = \\frac{-i}{6z^2+13z+6}\n\\]\n\\end{example}\n\\begin{solution}\nLet $g(z)=-i$ and \n\\[\nh(z) = 6z^2+13z+6 = (3z+2)(2z+3)\n\\]\nand note that $h(z)=0$ for $z=-\\frac{2}{3},-\\frac{3}{2}$.  Since $h'(z)=12z+13$, we have\n\\[\nh'(-2/3)  = 5 \\quad\\text{ and}\\quad h'(-3/2) = -5,\n\\]\nboth of which are nonzero, so that $f$ has poles of order $1$ at $-\\frac{2}{3}$ and $-\\frac{3}{2}$ by Theorem~\\ref{t:goverh}.  Moreover, by the same result,\n\\begin{align*}\n\\Res(f;-2/3) & = \\frac{g(-2/3)}{h'(-2/3)} = - \\frac{i}{5} \\\\\n\\Res (f;-3/2) & = \\frac{g(-3/2)}{h'(-3/2)} = \\frac{i}{5}.\n\\end{align*}\n\\end{solution}\n%\\vspace*{20cm}\n%\\begin{absolutelynopagebreak}\n\\begin{theorem}[The Residue at a pole of order $n$]\n\\label{t:polen}\nLet $f$ have an isolated singularity at $z_0$ which is a pole of order $n$, so that for some $r>0$\n\\[\nf(z) = \\frac{g(z)}{(z-z_0)^n} \\quad \\text{ for } z \\in D'(z_0,r),\n\\]\nwith $g$ holomorphic on $D(z_0,r)$ and $g(z_0) \\neq 0$.  Then\n\\[\n\\Res (f,z_0) = \\frac{g^{(n-1)}(z_0)}{(n-1)!}.\n\\]\n\\end{theorem}\n%\\end{absolutelynopagebreak}\n%\\noindent\\textit{Proof:}\n\\begin{proof}\nBy definition,\n\\[\n\\Res (f;z_0) = \\frac{1}{2\\pi i} \\int_{\\mathcal{C}} \\frac{g(z)}{(z-z_0)^n}\\ dz,\n\\]\nwhere $\\mathcal{C}$ is the anticlockwise circle with centre $z_0$ and radius $r/2$.  By Theorem~\\ref{t:cauchyd} (Cauchy's Integral Formula for Derivatives),\n\\[\ng^{(n-1)} (z_0) = \\frac{(n-1)!}{2\\pi i} \\int_{\\mathcal{C}} \\frac{g(z)}{(z-z_0)^n}\\ dz,\n\\]\nso that\n\\[\ng^{(n-1)} (z_0) = (n-1)!\\ \\Res (f;z_0),\n\\]\nor in other words,\n\\[\n\\Res (f;z_0) = \\frac{g^{(n-1)}(z_0)}{(n-1)!}.\n\\]\n\\end{proof}\n%\\vspace*{10cm}\n\n\n\n\\begin{example}\n\\label{e:res3}\n%\\begin{absolutelynopagebreak}\nLet us consider the function $f$ defined by\n\\[\nf(z) = \\frac{1}{(z^2+9)^2}.\n\\]\nand calculate the residues at the poles of $f$.\n\\end{example}\n\\begin{solution}\n%\\end{absolutelynopagebreak}\nFollowing Example~\\ref{e:poles2}, we define $g_1$ and $g_2$ by\n\\[\ng_1(z) = \\frac{1}{(z+3i)^2} \\quad\\text{ and }\\quad g_2(z) = \\frac{1}{(z-3i)^2}\n\\]\nso that\n\\[\nf(z) = \\frac{g_1(z)}{(z-3i)^2} = \\frac{g_2(z)}{(z+3i)^2},\n\\]\nand $g_1$ is holomorphic and nonzero at $z=3i$, $g_2$ is holomorphic and nonzero at $z=-3i$.  \n\nSince the poles at $z=\\pm 3i$ both have order $2$, Theorem~\\ref{t:polen} tells us that\n\\[\n\\Res (f;3i) =\\frac{g_1'(3i)}{1!} \\quad\\text{ and } \\Res (f;-3i) = \\frac{g_2'(-3i)}{1!}.\n\\]\nThe required derivatives are\n\\begin{align*}\ng_1'(z) = -2(z+3i)^{-3} & \\Rightarrow g_1'(3i) = -2(3i+3i)^{-3} = - \\frac{i}{108} \\\\\ng_2'(z) = -2(z-3i)^{-3} & \\Rightarrow g_2'(-3i) = -2(-3i-3i)^{-3} = \\frac{i}{108},\n\\end{align*}\nHence\n\\[\n\\Res (f;3i) = \\frac{-i/108}{1!} = - \\frac{i}{108} \\quad\\text{ and }\\quad \\Res (f;-3i) = \\frac{i/108}{1!}= \\frac{i}{108}.\n\\]\n%\\vspace*{15cm}\n\n\\end{solution}\n\n\\begin{example}\n%\\begin{absolutelynopagebreak}\nFor the function $f$ defined by\n\\[\nf(z) = \\frac{\\exp(\\pi z)}{(z-i)^3}\n\\]\nfind $\\Res (f,i)$.  Hence evaluate\n\\[\n\\int_{\\mathcal{C}} \\frac{\\exp( \\pi z)}{(z-i)^3}\\ dz,\n\\]\nwhere $\\mathcal{C}$ is the anticlockwise triangular contour with vertices $2$, $2i$ and $-2$.\n\\end{example}\n%\\end{absolutelynopagebreak}\n%\\vspace*{15cm}\n\\begin{solution}\nThe only pole of $f$ is a pole of order $3$ at $z=i$.  With $g$ the holomorphic function defined by $g(z) = \\exp(\\pi z )$, we have $g'(z) = \\pi \\exp(\\pi z)$ and $g''(z) = \\pi^2 \\exp(\\pi z)$.  By Theorem~\\ref{t:polen},\n\\[\n\\Res(f;i) = \\frac{g''(i)}{2!} = \\frac{\\pi^2 \\exp(\\pi i)}{2!} = \\frac{\\pi^2(-1)}{2} = - \\frac{\\pi^2}{2}.\n\\]\nSince $\\mathcal{C}$ is a simple, closed anticlcokwise contour, and $i$ is the only pole of $f$ enclosed by $\\mathcal{C}$, the Residue Theorem gives\n\\[\n\\int_{\\mathcal{C}} f = 2\\pi i \\Res (f;i) = 2\\pi i \\left( -\\frac{\\pi^2}{2} \\right) = -i \\pi^3.\n\\]\n\\end{solution}\n\n%\\newpage\n\\section{Evaluating Real Integrals using Contour Integration, part 2}\nRecall how we used contour integration to evaluate\n\\[\n\\int_{-\\infty}^{+\\infty} \\frac{1}{1+x^2}\\ dx.\n\\]\nWe first considered the complex function $f$ where $f(z)=\\dfrac{1}{1+z^2}$, and computed the integral of $f$ along the path $\\cont_R = L_R+S_R$ consisting of the line segment $[-R,R]$ and the upper semicircle with centre $0$ and radius $R$, from $R$ to $-R$ via $iR$ (where $R>1$).\n\nWe did this using Cauchy's Integral Formula, though we could equally have used the Residue Theorem.  We then showed that\n\\[\n\\lim_{R \\to \\infty} \\int_{S_R} f = 0\n\\]\nusing The Estimation Lemma.  From this we deduced that\n\\[\n\\int_{-\\infty}^{+\\infty} \\frac{1}{1+x^2}\\ dx  = \\lim_{R \\to \\infty} \\int_{L_R} f = \\lim_{R \\to \\infty} \\left( \\int_{L_R}f + \\int_{S_R} f \\right)\n= \\int_{\\cont_R} f. \n\\]\nIn fact, the exact same method can be used to evaluate many integrals of the form\n\\[\n\\int_{-\\infty}^{+\\infty} f(x)\\ dx,\\quad\\text{ for example}\\quad \\int_{-\\infty}^{+\\infty} \\frac{p(x)}{q(x)}\\ dx\n\\]\nwith $p$ and $q$ real polynomials, where $q$ has no real roots and the degree of $q$ is at least the degree of $p$ plus 2.\n\\begin{example}\n\\label{e:realint2}\nLet us evaluate\n\\[\n\\int_{-\\infty}^{+\\infty} \\frac{1}{(x^2+9)^2}\\ dx\n\\]\nusing contour integration.\n\\end{example}\n\\begin{solution}\n\nWe shall follow the approach used in Example~\\ref{e:realint1}, by considering the complex function $f$ defined via\n\\[\nf(z) = \\frac{1}{(z^2+9)^2}\n\\]\nand the contour $\\mathcal{C}_R=L_R+S_R$, where $R>3$, $L_R=[-R,R]$ and $S_R$ is the upper semicircle with centre $0$ and radius $R$ from $R$ to $-R$ via $iR$.\n\nUsing the result of Example~\\ref{e:res3}, the only singularity of $f$ enclosed by $\\mathcal{C}_R$ is at $z=3i$, hence by the Residue Theorem\n\\[\n\\int_{\\mathcal{C}_R} f = 2\\pi i \\Res (f;3i) = 2\\pi i \\left( -\\frac{i}{108} \\right) = \\frac{\\pi}{54}\n\\]\nfor all $R>3$.\n\nIf $z \\in S_R$, then $\\abs{z}=R$ and hence by the reverse triangle inequality\n\\[\n\\abs{z^2+9} \\geq \\abs{\\abs{z^2}-9} = \\abs{\\abs{z}^2-9} = R^2-9,\n\\]\nso that for all such $z$ we have $\\abs{z^2+9}^2 \\geq \\left( R^2-9 \\right)^2$.  Thus for all $z \\in S_R$,\n\\[\n\\abs{\\frac{1}{(z^2+9)^2}} = \\frac{1}{\\abs{z^2+9}^2} \\leq \\frac{1}{\\left(R^2-9 \\right)^2}.\n\\]\nThe Estimation Lemma gives\n\\[\n\\abs{ \\int_{\\mathcal{C}_R} \\frac{1}{(z^2+9)^2}\\ dz } \\leq \\frac{1}{\\left(R^2-9 \\right)^2} \\cdot \\pi R,\n\\]\nhence $\\displaystyle \\int_{\\mathcal{C}_R} f \\to 0$ as $R \\to \\infty$ as before.\n\nParameterising $L_R$ using $\\gamma:[-R,R] \\to \\C$, $\\gamma(t)=t$ we have $\\gamma'(t)=1$ and so\n\\[\n\\int_{L_R} f = \\int_{-R}^{R} \\frac{1}{(t^2+9)^2}\\ dt.\n\\]\nHence\n\\begin{align*}\n\\frac{\\pi}{54} & = \\int_{\\mathcal{C}_R} f  && (\\forall\\ R>3) \\\\\n& = \\lim_{R \\to \\infty} \\int_{\\mathcal{C}_R} f && \\\\\n& = \\lim_{R \\to \\infty} \\left( \\int_{L_R} f \\right) + \\lim_{R \\to \\infty} \\left( \\int_{S_R} f \\right) && \\\\\n& = \\lim_{R \\to \\infty} \\int_{-R}^{+R} \\frac{1}{(t^2+9)^2}\\ dt\\ +0&& \\\\\n &= \\int_{-\\infty}^{+\\infty} \\frac{1}{(t^2+9)^2}\\ dt. &&\n\\end{align*}\n(Note that it does not matter whether we call the variable of integration $x$ or $t$).\n\\end{solution}\n\\begin{example}\nUse Example~\\ref{e:realint2} to deduce the value of\n\\[\n\\int_0^{\\infty} \\frac{1}{(x^2+9)^2}\\ dx.\n\\]\n\\end{example}\n\\begin{solution}\nSince $\\displaystyle f(x) = \\frac{1}{x^2+9}$ is an even function (i.e. $f(-x)=f(x)$) it follows that\n\\[\n\\int_0^{\\infty} \\frac{1}{(x^2+9)^2}\\ dx  = \\frac{1}{2} \\int_{-\\infty}^{\\infty} \\frac{1}{(x^2+9)^2}\\ dx = \\frac{\\pi}{108}.\n\\]\n\\end{solution}\n\n\nWe showed in example~\\ref{e:trig2} that for a rational function $R$ of two real variables\n\\[\n\\int_0^{2\\pi} R ( \\cos(t), \\sin(t))\\ dt = \\int_{\\mathcal{C}} R \\left( \\frac{z+z^{-1}}{2} , \\frac{z-z^{-1}}{2i} \\right) \\cdot \\frac{1}{iz}\\ dz\n\\]\nwhere $\\mathcal{C}$ is the anticlockwise circle $\\set{z \\in \\C: \\abs{z}=1}$.\n\n\\begin{example}\nEvaluate\n\\[\n\\int_0^{2\\pi} \\frac{\\sin (t)}{5-4\\sin(t)}\\ dt\n\\]\nusing contour integration.\n\\end{example}\n\\begin{solution}\nFor $z = \\exp (it) \\in \\mathcal{C}$, define $f$ via \n\\begin{align*}\nf(z) = R \\left( (z+z^{-1})/2,(z-z^{-1})/(2i) \\right) \\cdot \\frac{1}{iz}\\ & = \\frac{[z-z^{-1}]/(2i)}{5-4[z-z^{-1}]/(2i)}\\cdot \\frac{1}{iz} \\\\\n& = \\frac{z-z^{-1}}{10i-4z+4z^{-1}} \\cdot \\frac{1}{iz} \\\\\n& =  \\frac{z^2-1}{-4z^2+10iz+4} \\cdot \\frac{1}{iz} \\\\\n& =  \\frac{i(z^2-1)}{z(4z^2-10iz-4)}\\\\\n& = \\frac{1}{2} \\cdot \\frac{i(z^2-1)}{z(z-2i)(2z-i)}\n\\end{align*}\nso that\n\\[\n\\int_0^{2\\pi} \\frac{\\sin (t)}{5-4\\cos(t)}\\ dt = \\int_{\\mathcal{C}}  f dz.\n\\]\nThe function $f$ has simple poles at $0, i/2$ and $2i$, and  the first two of these are enclosed by $\\mathcal{C}$.  Writing\n\\[\ng(z)=i(z^2-1) \\quad \\text{ and } h(z) = 4z^3-10iz^2-4z\n\\]\nwe have $f=g/h$ and $h'(z)=12z^2-20iz-4$, hence by the $g/h$ rule\n\\begin{align*}\n\\mathrm{Res} (f;0) & = \\frac{g(0)}{h'(0)} = \\frac{-i}{-4} = \\frac{i}{4} \\\\\n\\mathrm{Res} (f;i/2) & = \\frac{g(i/2)}{h'(i/2)} = \\frac{i((\\tfrac{i}{2})^2-1)}{12(\\tfrac{i}{2})^2-20i(\\tfrac{i}{2})-4} =\\frac{-5i}{12}.\n\\end{align*}\nThe Residue Theorem gives \n\\[\n\\int_{\\mathcal{C}}  \\frac{(z^2-1)}{2z(z-2i)(2z-i)}\\ dz =  2 \\pi i \\left( \\frac{i}{4} - \\frac{5i}{12} \\right) =2\\pi i \\left(\\frac{-i}{6} \\right) = \\frac{\\pi}{3}. \n\\]\nHence\n\\[\n\\int_0^{2\\pi} \\frac{\\sin (t)}{5-4\\sin(t)}\\ dt =\\frac{\\pi}{3}.\n\\]\n\\end{solution}\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "28958ac03ecffa635f7174f136b85e867696b680", "size": 23668, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2003/LectureNotes/Chapter_6.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2003/LectureNotes/Chapter_6.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2003/LectureNotes/Chapter_6.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 39.7781512605, "max_line_length": 398, "alphanum_fraction": 0.6388372486, "num_tokens": 9483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.8856314828740729, "lm_q1q2_score": 0.7068993480833146}}
{"text": "\\section{Differentiation}\n\n\\subsection{Exercise 1}\nWe have that\n\\begin{align*}\n        \\abs{f(x) - f(y)} &\\leq (x - y)^2 = \\abs{x - y}^2 \\\\\n        \\frac{\\abs{f(x) - f(y)}}{\\abs{x - y}} &\\leq \\abs{x - y} \\\\\n                                              &\\implies f'(x) = 0 \\: \\forall x\n\\end{align*}\nSince we can write $\\frac{f(t) - f(x)}{t - x} = f'(x) + u(t)$ with $\\lim_{t \\to x} u(t) \\to 0$, we have that\n\\begin{align*}\n        f(t) - f(x) = (t - x) u(t), &\\quad f(t) - f(y) = (t - y) v(t) \\\\\n        f(y) - f(x) = (y - x) u(y), &\\quad f(x) - f(y) = (x - y) v(x) \\implies u(y) = v(x) \\: \\forall x, y \\\\\n        f(y) - f(x) &= 0 \\implies f(x) = f(y) \\: \\forall x, y\n\\end{align*}\nWhoops, I did this before reading the mean value theorem section - this problem follows immediately\nfrom applying the mean value theorem after showing $f'(x) = 0$.\n\n\\subsection{Exercise 2}\nTake $x, t \\in (a, b)$ with $t > x$. Applying the mean value theorem to $f$ on $[x, t]$, we get\n$f(t) - f(x) = (t - x) f'(y)$ for some $y \\in (x, t)$. Since $f'(y) > 0 \\implies f(t) - f(x) > 0$,\n$f$ is strictly increasing on $(a, b)$. We can prove $g = f^{-1}$ is differentiable directly\n\\begin{align*}\n        \\lim_{t \\to x} \\frac{g(f(t)) - g(f(x))}{f(t) - f(x)} &= \\lim_{t \\to x} \\frac{t - x}{f(t) - f(x)} \\\\\n                                                             &= \\frac{1}{f'(x)}\n\\end{align*}\n\n\\subsection{Exercise 3}\nSuppose (WLOG) that $x_2 > x_1$ but $f(x_2) = f(x_1)$. Then we have that\n\\begin{align*}\n        x_2 + \\epsilon g(x_2) &= x_1 + \\epsilon g(x_1) \\\\\n        (x_2 - x_1) + \\epsilon (g(x_2) - g(x_1)) &= 0 \\\\\n        1 + \\epsilon g'(x) &= 0 \\quad x \\in (x_1, x_2) \\\\\n        1 + \\epsilon g'(x) &\\geq 1 - \\epsilon \\abs{g'(x)} \\\\\n                           &> 0 \\quad \\forall \\epsilon < \\frac{1}{M}\n\\end{align*}\nWhere the penultimate step follows from the mean value theorem.\nThus, we can choose an $\\epsilon$ such that $f(x_2) \\neq f(x_1)$, which means we can make $f$ injective.\n\n\\subsection{Exercise 4}\nLet $f(x) = C_0 + C_1 x + ... + C_n x^n$ and $g(x) = C_0 x + \\frac{C_1}{2} x^2 + ... + \\frac{C_n}{n+1}x^{n+1}$.\nThen $g'(x) = f(x)$. Applying the mean value theorem to $g(x)$ on $[0, 1]$ yields that there is an $x$ \nsuch that $g'(x) = f(x) = g(1) - g(0) = 0$, so $f$ has a root in $(0, 1)$.\n\n\\subsection{Exercise 5}\nIt looks like the mean value theorem is this chapter's ratio test; you can guess how this will go.\nBy the mean value theorem, $f'(y) = f(x + 1) - f(x)$ for $y \\in [x, x+1]$. Thus we have\n$\\lim_{x \\to \\infty} g(x) = \\lim_{y \\to \\infty} f'(y) = 0$.\n\n\\subsection{Exercise 6}\nConsider $x > y > 0$. By the mean value theorem (surprise), we have that\n\\begin{align*}\n        f(x) - f(y) &= f'(a) (x - y) \\quad a \\in (x, y) \\\\\n                    &< f'(x) (x - y) \\\\\n        \\lim_{y \\to 0} \\frac{f(x) - f(y)}{x - y} &< \\lim_{y \\to 0} f'(x) \\\\\n        \\frac{f(x)}{x} &< f'(x)\n\\end{align*}\nDifferentiating $g$, we get\n\\begin{align*}\n        g'(x) &= \\frac{xf'(x) - f(x)}{x^2} \\\\\n        f'(x) > \\frac{f(x)}{x} &\\implies g'(x) > 0\n\\end{align*}\nSo $g$ is monotonically increasing.\n\n\\subsection{Exercise 7}\nIf $f$ and $g$ are real, then the result follows immediately from L'Hopital's, since the existence of \n$f'(x), g'(x)$ imply that $f$ and $g$ are continuous (so the requirement that $f(x) \\to 0$ and $g(x) \\to 0$ \nis satisfied). More generally, for complex functions, we have\n\\begin{align*}\n        \\lim_{t \\to x} \\frac{f(t)}{g(t)} &= \\lim_{t \\to x} \\frac{f_1(t) + f_2(t) i}{g_1(t) + g_2(t) i} \\\\\n                                         &= \\lim_{t \\to x} \\frac{\\frac{f_1(t) + f_2(t)i}{t - x}}{\\frac{g_1(t) + g_2(t)i}{t - x}} \\\\\n                                         &= \\frac{f'(x)}{g'(x)}\n\\end{align*}\n\n\\subsection{Exercise 8}\nExercise 7 was a brief detour, but we are now back to hammering away with the mean value theorem. We have\n\\begin{align*}\n        \\abs{\\frac{f(t) - f(x)}{t - x} - f'(x)} &< \\epsilon \\\\\n        \\abs{f'(y) - f'(x)} &< \\epsilon \n\\end{align*}\nWhere $y \\in (x, t)$ or $y \\in (t, x)$. Since $f'$ is continuous, we can choose $\\delta$ such that\n$\\abs{y - x} < \\delta$ implies the above inequality, which means we can take $\\abs{t - x} < \\delta$ to\nget the desired result.\n\nThis does not seem to have to hold for vector-valued functions, since in that case we only have\n$\\abs{f(t) - f(x)} \\leq (t - x) \\abs{f'(y)}$.\n\n\\subsection{Exercise 9}\nYes, since we can apply L'Hopital's to $(0, +\\infty)$ and $(-\\infty, 0)$\n\\begin{align*}\n        f'(0) &= \\lim_{t \\to 0} \\frac{f(t) - f(0)}{t} \\\\\n              &= \\lim_{t \\to 0} f'(t) = 3\n\\end{align*}\n\n\\subsection{Exercise 10}\nWe proceed exactly as directed by Rudin\n\\begin{align*}\n        \\lim_{x \\to 0} \\frac{f(x)}{g(x)} &= \\lim_{x \\to 0} \\bigg(\\frac{f(x)}{x} - A\\bigg) \\frac{x}{g(x)} + \\frac{Ax}{g(x)} \\\\\n                                         &= \\frac{\\lim_{x \\to 0} \\frac{f(x) - Ax}{x}}{\\lim_{x \\to 0} \\frac{g(x)}{x}} + \\frac{A}{\\lim_{x \\to 0} \\frac{g(x)}{x}} \\\\\n                                         &= 0 + \\frac{A}{B}\n\\end{align*}\nWhere the final step follows from breaking up $f, g, A$ into their real and imaginary components and applying\nL'Hopital's ($\\Re f'(x) - \\Re A$ and $\\Im f'(x) - \\Im A$ both go to 0).\n\n\\subsection{Exercise 11}\nDouble application of L'Hopital's\n\\begin{align*}\n        \\lim_{h \\to 0} \\frac{f(x + h) + f(x - h) - 2f(x)}{h^2} &= \\lim_{h \\to 0} \\frac{f'(x + h) - f'(x - h)}{2h} \\\\\n                                                               &= \\lim_{h \\to 0} \\frac{f''(x + h) + f''(x - h)}{2} \\\\\n                                                               &= f''(x)\n\\end{align*}\nIf we let $f(x) = x \\sin \\frac{1}{\\abs{x}}$ when $x \\neq 0$ and $f(0) = 0$, then $f''(0)$ does not exist. \nHowever, plugging $f$ into the above limit and setting $x = 0$, we see that the limit is 0.\n\n\\subsection{Exercise 12}\n\\begin{align*}\n        &f(x) = \\abs{x}^3 = \n        \\begin{cases}\n                -x^3 & x < 0 \\\\\n                0 & x = 0 \\\\\n                x^3 & x > 0\n        \\end{cases} \\implies \n        f'(x) = \n        \\begin{cases}\n                -3x^2 & x < 0 \\\\\n                0 & x = 0 \\\\\n                3x^2 & x > 0\n        \\end{cases} \\\\\n        &\\implies f''(x) =\n        \\begin{cases}\n                -6x & x < 0 \\\\\n                0 & x = 0 \\\\\n                6x & x > 0\n        \\end{cases} \\implies \n        f^{(3)}(x) =\n        \\begin{cases}\n                -6 & x < 0 \\\\\n                0 & x = 0 \\\\\n                6 & x > 0 \n        \\end{cases}\n\\end{align*}\nSo the left and right limits of $f^{(3)}(0)$ do not equal one another.\n\n\\subsection{Exercise 14}\nSuppose $f$ is a convex differentiable function. Then\n\\begin{align*}\n        f(\\lambda x + (1 - \\lambda) y) &\\leq \\lambda f(x) + (1 - \\lambda) f(y) \\\\\n        f(\\lambda x + (1 - \\lambda) y) - f(y) &\\leq \\lambda (f(x) - f(y)) \\\\\n        \\frac{f(y) - f(\\lambda x + (1 - \\lambda) y)}{\\lambda (y - x)} &\\geq \\frac{f(y) - f(x)}{y - x} \\\\\n        \\frac{f(y) - f(\\lambda x + (1 - \\lambda) y)}{y - (\\lambda x + (1 - \\lambda)y)} &\\geq \\frac{f(y) - f(x)}{y - x} \n\\end{align*}\nSince $x$ was arbitrary, the last inequality implies that $f'$ is monotonically increasing (because we can \nconsider a new interval whose left endpoint is $\\lambda x + (1 - \\lambda) y$).\n\nFor the other direction, we can modify the convexity condition until we get something that we can apply\nthe mean value theorem to. Letting $z = \\lambda x + (1 - \\lambda) y$, we have\n\\begin{align*}\n        f(z) &\\leq \\lambda f(x) + (1 - \\lambda) f(y) \\\\ \n        \\lambda (f(z) - f(x)) &\\leq (1 - \\lambda) (f(y) - f(z)) \\\\\n        \\frac{f(z) - f(x)}{z - x} &\\leq \\frac{(1 - \\lambda) (f(y) - f(z))}{\\lambda (z - x)} \\\\\n                                  &\\leq \\frac{f(y) - f(z)}{y - z}\n\\end{align*}\nThe final inequality is true by monotonicity of $f'$ and applying the mean value theorem \nto $(x, z)$ and $(z, y)$. The final step follows from the fact that $\\lambda (z - x) = (1 - \\lambda) (y - z)$.\n\n\\subsection{Exercise 15}\nProceeding as directed by the hint, we have\n\\begin{align*}\n        f(x + 2h) &= f(x) + 2hf'(x) + 2h^2 f''(c) \\\\\n        f'(x) &= \\frac{1}{2h} (f(x + 2h) - f(x)) - hf''(c) \\\\\n        M_1 &\\leq \\frac{1}{2h} (\\abs{f(x + 2h)} + \\abs{f(x)}) + h\\abs{f''(c)} \\\\\n            &\\leq \\frac{M_0}{h} + h M_2 \\\\\n        M_1^2 &\\leq \\frac{M_0^2}{h^2} + 2 M_0 M_2 + h^2 M_2^2 \\\\\n              &\\leq 4 M_0 M_2 \\quad \\quad h = \\sqrt{\\frac{M_0}{M_2}}\n\\end{align*}\n\n\\subsection{Exercise 18}\nDifferentiating $f(t) - f(\\beta) = (t - \\beta) Q(t)$ and evaluating at $\\alpha$, we have\n\\begin{align*}\n        f^{(k)}(\\alpha) &= (\\alpha - \\beta) Q^{(k)} (\\alpha) - k Q^{(k - 1)} (\\alpha) \\\\\n        \\frac{f^{(k)}(\\alpha)}{k!} (\\beta - \\alpha)^k &= -\\frac{Q^{(k)}(\\alpha)}{k!}(\\beta - \\alpha)^{k+1} + \n        \\frac{Q^{(k - 1)}(\\alpha)}{(k - 1)!} (\\beta - \\alpha)^{k} \\\\\n        \\sum_{k = 1}^{n - 1}\\frac{f^{(k)}(\\alpha)}{k!} (\\beta - \\alpha)^k &=  -\\frac{Q^{(n - 1)}(\\alpha)}{(n - 1)!}(\\beta - \\alpha)^{n} + (f(\\beta) - f(\\alpha)) \\\\\n        P(\\beta) + \\frac{Q^{(n - 1)}(\\alpha)}{(n - 1)!}(\\beta - \\alpha)^{n} &= f(\\beta)\n\\end{align*}\n\n", "meta": {"hexsha": "cbc1fac439eed2aae69e4c3d2182369e33b38c34", "size": 9061, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Principles_of_Mathematical_Analysis_Rudin/chapter_5.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "Principles_of_Mathematical_Analysis_Rudin/chapter_5.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Principles_of_Mathematical_Analysis_Rudin/chapter_5.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.4545454545, "max_line_length": 163, "alphanum_fraction": 0.4918883125, "num_tokens": 3491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619963333289, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.7068633914359428}}
{"text": "\\section{Artificial Neural Networks}\nArtificial neural networks are a computing system inspired by biological neurons. Neural networks are comprised of neurons which are capable of taking any number of numerical inputs and outputs a numerical value.\n\n\\input{figures/background/neural-net}\n\nMathematically, a single neuron is a function.\nThe function of a neuron $j$ receiving input $x_j$ and producing output $y_j$ is composed of the activation $a_j$, an activation function $f_a$ which returns the activation, and an output function $f_{o}$.\nThe activation $a_j$ can also be considered the neuron's state.\nThe activation function $f_a$ calculates $a_j$ given the network input $x_j$ and can be defined as:\n\\begin{align}\n\ta_j &= f_a\\left(x_j\\right)\n\\end{align}\nThe output function $f_o$ computes $y_j$ based on $a_j$ and is defined as:\n\\begin{align}\n\ty_j &= f_o\\left(a_j\\right)\n\\end{align}\nMany activation functions exists and are used including the identity function and the rectified linear unit (ReLU), defined as:\n\\begin{align}\n\tf_a(x) &= \n\t\\begin{cases}\n\t\t0\t& \\text{for } x \\leq 0\\\\\n\t\tx\t& \\text{for } x > 0\n\t\\end{cases}\n\\end{align}\n\nBetween each neuron in the network are connections which transfer the output of neuron $i$ to neuron $j$. Each of these connections are assigned a weight $w_{ij}$, which is computed by the learning algorithm.\nEach neuron also has a bias $w_{0j}$.\nThese parameters are used to provide a neuron its input $x_j$. This is defined as:\n\\begin{align}\n\tx_j &= \\sum_{i}y_iw_{ij} + w_{0j}\n\\end{align}\n\n\\figref{fig:background-neuralnet} shows a visualization of the interactions between multiple neurons.\n\nLearning occurs by using an algorithm known as backpropagation to modify the parameters of the neural network.\nFurther discussion on backpropagation can be found in Section \\ref{section:background-backpropagation}.\n\nDeep neural networks are so called deep due to having multiple \"hidden\" layers between the input and output which are not accessed directly.\n\n\\subsection{Convolutional Neural Networks}\\label{section:background-cnn}\nConvolutional Neural Networks (CNNs) are a specific class of deep neural networks and have been found to perform exceptionally well for image analysis, such as image classification and segmentation.\nThe inspiration for CNNs come from biological processes to simulate the organization of the visual cortex in animals~\\cite{cnnbiology}.\nConvolutional layers are the core building blocks of CNNs.\nThese convolutional layers consist of a set of learnable filters which are convolved across the entire input and compute the dot products between the different entries of the filter.\n\n\\input{figures/background/convolution}\n\nBy using multiple convolutional layers, higher level features can be extracted, generating a feature map.\nThe module responsible for extracting the feature map is commonly known as the encoder.\n\nThe convolutional layers that make up the CNN are called the feature encoder.\nThe output of these convolutional layers are then fed into a module with one or more fully convolutional layers to produce a classification of each pixel in a scene.\nThese convolutional layers work by taking the deep feature maps produced by the encoder and using deconvolutional or upsampling layers to produce a log-likelihood vector for each pixel.\nThis module is known as the decoder.\nThe resulting vector produced is a probability of each pixel being a certain class.\nApplying an argmax operation on this vector produces a segmentation of the input image.\n\nA bottleneck structure may also be used to increase performance.\nA bottleneck structure in a convolutional neural network reduces the number of features by performing a $1 \\times 1$ convolution on a tensor before performing a convolution operation.\nA final $1 \\times 1$ convolution is then performed to expand the tensor to contain a meaningful combination features.\nAs the input features are correlated, redundancy can be removed by performing the first $1 \\times 1$ convolution.\n\nFor example, performing a $3 \\times 3$ convolution on a $256 \\times 256$ input tensor requires more than 589,000 operations.\nA bottleneck structure can be used to reduce the dimensionality of the input tensor to only 64 dimensions using a $1 \\times 1$ convolution.\nThe $3 \\times 3$ convolution is then performed on this tensor.\nFinally, the resulting tensor is re-expanded back to the original 256 dimensions using another $1 \\times 1$ convolution.\nThis would result in slightly over 69,000 operations, significantly less than without the bottleneck structure.\n\nThis reduces both the number of operations required as well as the number of parameters in the network.", "meta": {"hexsha": "753012fa97c6476f19d8f0c2c4305885afc09670", "size": 4664, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/3_1-neural-networks.tex", "max_stars_repo_name": "yvan674/bachelor-thesis", "max_stars_repo_head_hexsha": "00121f35245c20ddf77bd5d0ca9467460849902c", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/3_1-neural-networks.tex", "max_issues_repo_name": "yvan674/bachelor-thesis", "max_issues_repo_head_hexsha": "00121f35245c20ddf77bd5d0ca9467460849902c", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/3_1-neural-networks.tex", "max_forks_repo_name": "yvan674/bachelor-thesis", "max_forks_repo_head_hexsha": "00121f35245c20ddf77bd5d0ca9467460849902c", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.5942028986, "max_line_length": 212, "alphanum_fraction": 0.7973842196, "num_tokens": 1031, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422241476944, "lm_q2_score": 0.7431679972357831, "lm_q1q2_score": 0.7068584618062304}}
{"text": "\\section{Two-Stage Least Squares and its Limitations}\n\n\\subsection{Basic Model}\nThroughout the paper, unless stated otherwise, we consider the following basic model with two equations, following the notation of \\cite{angrist1999jackknife}:\n\\begin{align*}\nY_i &= X_i\\beta + \\varepsilon_i \\\\\nX_i &= Z_i\\pi + \\eta_i\n\\end{align*}\n$Y_i$ is scalar. $X_i$ is $1\\times L$ row vector of potentially endogenous regressors. \n$Z_i$ is $1\\times K$ row vector, with $K\\geq L$. \n$K-L$ is the number of over-identifying restrictions. In matrix notation:\\\\\n\\begin{align}\n\\underset{(N\\times 1)}{\\mathbf{Y}} = \\underset{(N\\times L)}{\\mathbf{X}}\\beta + \\underset{(N\\times 1)}{\\varepsilon} \\\\\n\\underset{(N\\times L)}{\\mathbf{X}} =  \\underset{(N\\times K)}{\\mathbf{Z}}\\pi + \\underset{(N\\times L)}{\\eta}\n\\end{align}\nwhere (2.1) denotes the structural equation, (2.2) is the first stage. $\\mathbf{Y}$ and $\\varepsilon$ are $N \\times 1$ vectors. \n$\\mathbf{X}$ and $\\eta$ are $N \\times L$ matrices, and $\\mathbf{Z}$ is $N \\times K$ matrix. If the vectors of regressors and that of instruments have $M$ common elements, then $M$ columns of the $N \\times L$ matrix $\\eta$ have their elements as zero.\n\\par The following assumptions hold for our model:\n\\begin{enumerate}\n\\item Conditional on instruments $Z_i$, the error term $\\varepsilon_i$ has expectation zero ($E[\\varepsilon_i|Z_i]=0$) and variance $\\sigma^2$.\n\\item $E[\\eta|\\mathbf Z]=0$ and $E[\\eta_i^\\prime\\eta_i|\\mathbf Z]=\\Sigma_\\eta$, with rank $L-M$.\n\\item $E[\\varepsilon_i\\eta_i^\\prime|\\mathbf Z]=\\sigma_{\\varepsilon\\eta}$, where $\\sigma_{\\varepsilon\\eta}$ is an L-dimensional column vector.\n\\item All observations of ($Y_i, X_i, Z_i$) are independent and identically distributed.\n\\end{enumerate}\n\n\\subsection{Concentration Parameter}\nThe Concentration Parameter $\\mu^2$, given by:\n        \\begin{equation}\n  \\mu^2 = \\frac{\\pi' Z' Z \\pi}{\\sigma_{\\eta}^2}\n        \\end{equation}\nmeasures the strength of the instruments. It is unitless. An important question to be addressed at this point is that since $\\pi$, and thus $\\mu^2$, is unknown, how is the researcher supposed to know whether $\\mu^2$ value is low enough for the instrument under study to be weak? This is addressed by the fact that the concentration parameter can be interpreted in terms of the first stage F statistic, discussed in Section 3. If the sample size is large, $E(F) \\cong \\mu^2/K + 1$, and thus $F-1$ can be treated as an estimator of $\\mu^2 /K$, which gives us a convenient way to test for weak instruments. \n\n\n\\par The concept of $\\mu^2$ is essentially the starting point for understanding the weak instruments literature. \\cite{rothenberg1984approximating} showed that the concentration parameter plays the role we commonly associate with the sample size or number of observations: as $\\mu^2$ becomes large, the normal distribution becomes a good approximation for the 2SLS distribution. Likewise a small concentration parameter leads to a non-normal distribution of 2SLS, and the estimator becomes biased. Thus $\\mu^2$ can be interpreted as the effective sample size.\n\n\n\\subsection{Two-Stage Least Squares Estimator}\n\nIt is helpful to characterize the 2SLS and (later on the jackknife estimator as well), as a feasible version of the ideal but infeasible instrumental variables estimator. Adhering to the notation defined in section 2.1, we derive the formula for the 2SLS estimator using this characterization. The derivation is adopted, with modifications to the notation, from \\cite{brucehansen2019} and \\cite{angrist1999jackknife}. \n\\par First, we estimate the ideal estimator $\\hat\\beta_{OPT}$ using the optimal instrument $Z\\pi$, by ordinary least-squares:\n\\begin{equation}\n\\hat\\beta_{OPT}= ((\\mathbf{Z}\\pi)'\\mathbf{X})^{-1}((\\mathbf{Z}\\pi)'\\mathbf{Y})\n\\end{equation}\n$\\pi$ is unknown however, and so the optimal estimator $\\hat\\beta_{OPT}$ is infeasible.\n\nWe use an estimate of $\\pi$ instead, and denote it  by $\\hat\\pi$. $\\hat\\pi$ is estimated from the reduced form regression which yields $\\hat\\pi = (\\mathbf{Z}'\\mathbf{Z})^{-1}(\\mathbf{Z}'\\mathbf{X})$. Substituting $\\hat\\pi$ into (2.4),\n\\begin{equation}\n\\hat\\beta_{2SLS}= ((\\mathbf{Z}\\hat\\pi)'(\\mathbf{Z}\\hat\\pi))^{-1}((\\mathbf{Z}\\hat\\pi)'\\mathbf{Y})\n\\end{equation}\n\\begin{equation}\n\\hat\\beta_{2SLS}= ((\\mathbf{Z}(\\mathbf{Z}'\\mathbf{Z})^{-1}(\\mathbf{Z}'\\mathbf{X}))'(\\mathbf{Z}(\\mathbf{Z}'\\mathbf{Z})^{-1}(\\mathbf{Z}'\\mathbf{X}))^{-1}((\\mathbf{Z}(\\mathbf{Z}'\\mathbf{Z})^{-1}(\\mathbf{Z}'\\mathbf{X}))'\\mathbf{Y})\n\\end{equation}\n\\begin{equation}\n\\hat\\beta_{2SLS}= ((\\mathbf{X}'\\mathbf{Z})(\\mathbf Z'\\mathbf Z)^{-1}\\mathbf Z'\\mathbf X)^{-1}\\mathbf X'\\mathbf Z(\\mathbf Z'\\mathbf Z)^{-1}\\mathbf Z'\\mathbf Y\n\\end{equation}\nThis is the two-stage least squares estimator.\n$\\hat\\beta_{2SLS}$ can be thought of as an estimator with the constructed instrument $(\\mathbf{Z}\\hat\\pi)$ where $\\hat\\pi = (\\mathbf{Z}'\\mathbf{Z})^{-1}(\\mathbf{Z}'\\mathbf{X})$.\n\\par\nRepresenting (2.7) in terms of the projection matrix  $P_{Z}=\\mathbf Z(\\mathbf Z'\\mathbf Z)^{-1}\\mathbf Z'$:\n\\begin{equation}\n\\hat{\\beta }_{2SLS}=((\\mathbf X'P_{Z}\\mathbf X)^{-1}\\mathbf X'P_{Z}\\mathbf Y)\n\\end{equation}\nThe two-stage least squares is by far the most widely used estimator for instrumental variables estimation, however, as we briefly discussed in chapter 1, it has certain concerning limitations, which we expand upon in the next section.\n\n\\subsection{Limitations of 2SLS: Bias}\nIn the weak instruments case, the 2SLS estimator fails to provide unbiased, reliable estimates. As shown in Section 2.3, we arrived at the 2SLS estimator using an estimate of $\\pi$ since the true value of the first-stage coefficients is unknown, which implies a certain amount of\nover-fitting of the first-stage equation, leading to bias in the\ndirection of the expectation of the OLS estimator of $\\beta$.\n\n\n\\par There is considerable  theoretical research noting the poor finite-sample properties of instrumental variables estimator. Results on the magnitude of this bias have been provided by \\cite{nagar1959bias}, \\cite{richardson1968exact}, \\cite{sawa1969exact} and \\cite{buse1992bias}. Further, as shown by noteworthy results of \\cite{bound1995problems}, with weak instruments particularly, the finite sample behavior worsens and the estimator can become biased as well as inconsistent.\n\n\n\\subsubsection{Bias in Single Instrument case}\nTo visualize the problem intuitively, first let us consider the simple case of a single (weak) instrument and endogenous regressor:\n\n        $$Y_i = X_i\\beta + \\varepsilon_i$$\n$$X_i = Z_i\\pi_1 + \\eta_i$$\n\nIn this case, the 2SLS estimator is simply given by the ratio of the two covariances: \n\\begin{equation}\n    \\hat\\beta_{2SLS}=\\frac{\\sigma_{Y_iZ_i}}{\\sigma_{X_iZ_i}}\n\\end{equation}\nHowever, given the fact that our instrument is very weak,\n$\\sigma_{X_iZ_i}=0.$ \nHence, $\\hat\\beta_{2SLS}$ does not exist.\n\\par In the simplest case, the 2SLS estimator is just the ratio of two covariances, and with weak instruments, the 2SLS or general instrumental variables estimator does not exist.\n    \n\n\n\\subsubsection{Approximate Expression of Bias in Multiple-Instruments case}\nIn this section we provide two different expressions approximating the bias of the two-stage least squares estimator in the general case and show how it centers around ordinary least squares. \n\\par Defining the `relative bias' of 2SLS to be its bias relative to the\ninconsistency of OLS, \\cite{buse1992bias} derived an expression for the approximate bias of $\\hat\\beta_{2SLS}$ using power series approximations. This result holds even when the errors are not normally distributed: \n\\begin{equation}\n  \\frac{\\sigma_{\\varepsilon\\eta }(K-2)}{\\pi'\\mathbf Z'\\mathbf Z\\pi}  \n\\end{equation}\n\nwhere N is the sample size and K is the number of excluded instruments.\nThis expression is approximately inversely proportional to $\\mu^2/(K-2)$, as shown:\n\n\\begin{equation}\n\\frac{\\sigma_{\\varepsilon\\eta}{\\sigma_\\eta^2}(K-2)}{{\\sigma_\\eta^2}\\pi'\\mathbf Z'\\mathbf Z\\pi} = \\frac{\\sigma_{\\varepsilon\\eta}(K-2)}{{\\sigma_\\eta^2}{\\mu^2}}  \n\\end{equation}\nwhere $\\mu^2$ denotes the concentration parameter (measure of the strength of the instrument as discussed in Section 1.). Note that in the above equation, the term $\\frac{\\sigma_{\\varepsilon\\eta }}{\\sigma_{\\eta }^{2}}$ approximately equals the asymptotic bias of the OLS estimator when the instrument explains little of the variation of $\\mathbf X$. Hence, from equation (2.10) it is clearly seen that for $K>2$, the bias of the 2SLS estimator relative to OLS is inversely proportional to the concentration parameter, hence, weaker the instrument(s), lower is the concentration parameter, and higher is the bias of 2SLS towards the OLS estimate.\n\n\\par It can be seen from the above formulation that increasing the number of instruments with the explanatory power remaining constant, causes the relative bias of the 2SLS to only increase.\n\n\\par Before moving on to the second expression, it is important to briefly introduce alternate asymptotic representations that are generally used for the weak instruments case.\nAs discussed by \\cite{stock2002survey}, for weak instruments, conventional asymptotic approximations to finite-sample distributions are quite poor. Two alternate asymptotic methods commonly employed are \\textbf {weak-instrument asymptotics} (involving a sequence of models chosen to keep $\\mu^2/K$ constant as sample size $N \\rightarrow \\infty$) pioneered by \\cite{staiger1997stock} and \\textbf {many-instrument or group asymptotics} (involving sequence of models with fixed instruments and normal errors, where $K$ is proportional to $N$ and $\\mu^2/K$ converges to a constant finite limit), first proposed by \\cite{bekker1994alternative}. In the 1995 working paper version of \\cite{angrist1999jackknife}, it was referred to as group asymptotics.\n\n\\par We present an expression for the approximate bias of the 2SLS estimator using group asymptotics, wherein we let\nthe number of instruments grow proportional to rate of the sample size.\nThis keeps the instruments weak. The detailed derivation of this expression is provided in the appendix A.1.\n\\begin{equation}\n    E[\\hat{\\beta }_{2SLS}-\\beta]\\approx \\frac{\\sigma_{\\varepsilon\\eta }}{\\sigma_{\\eta }^{2}}\\frac{1}{F+1}\n\\end{equation}\nwhere F is the population analog of the F-statistic for the joint significance of the instruments in the first-stage regression. $\\frac{\\sigma_{\\varepsilon\\eta }}{\\sigma_{\\eta }^{2}}$ approximately equals the asymptotic bias of the OLS estimator. Given a weak first-stage (weak instruments case), $F\\rightarrow0$, and we can see that the bias approaches $ \\frac{\\sigma_{\\varepsilon\\eta }}{\\sigma_{\\eta }^{2}}$. With a strong first-stage, $F\\rightarrow \\infty$ and then the 2SLS bias goes to 0. \n \n\n\n\\subsubsection{Inconsistency of the 2SLS estimator}\nIn this section we relate the two conditions for instrumental variables estimation to the consistency property of the 2SLS estimator. If the weak correlation (between the instrument(s) and the endogenous variable) is coupled together with even a small violation of the second condition of instrumental variables estimation (which is the instrument exogeneity condition) then we have an inconsistent estimator. This insight was first discussed by \\cite{bound1995problems}.\n\n\n\nTo represent the problem discussed above, let us consider the probability limit of the 2SLS estimator:\n\n\\begin{equation}\nplim \\hat{\\beta} _{2SLS}=\\beta + \\frac{\\sigma _{\\mathbf {\\hat X},\\varepsilon }}{\\sigma _{\\mathbf {\\hat X}}^{2}}\n\\end{equation}\n\nwhere $\\mathbf {\\hat X}$ is the projection of $\\mathbf X$ onto $\\mathbf Z$, and ${\\sigma _{\\mathbf {\\hat X},\\varepsilon }}$ is the covariance between $\\mathbf {\\hat X}$ and $\\varepsilon$.\n\nFrom equation (2.13) we can intuitively understand that if $\\sigma _{\\mathbf {\\hat X}}^{2}$ is small, which implies that we have a weak instrument, then as long as ${\\sigma _{\\mathbf {\\hat X},\\varepsilon }}$ is zero the estimator will be consistent. However, suppose we have a weak instrument  and also, ${\\sigma _{\\mathbf {\\hat X},\\varepsilon }}$ is small but non-zero, then even that small correlation between $\\mathbf Z$ (and thus, $\\mathbf {\\hat X}$) and the structural error term $\\varepsilon$ can lead to a large inconsistency.\n\nHence, with weak instruments, even moderate correlation between instrument and structural error term can magnify the inconsistency of IV estimator. ", "meta": {"hexsha": "3bc2d281b9972d79a97b51d730ed0b867b314d5d", "size": 12403, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch02.tex", "max_stars_repo_name": "mchandra12/research_module_econometrics", "max_stars_repo_head_hexsha": "2e65411b69d6924495c5e321857b64d06f1ce7ff", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ch02.tex", "max_issues_repo_name": "mchandra12/research_module_econometrics", "max_issues_repo_head_hexsha": "2e65411b69d6924495c5e321857b64d06f1ce7ff", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch02.tex", "max_forks_repo_name": "mchandra12/research_module_econometrics", "max_forks_repo_head_hexsha": "2e65411b69d6924495c5e321857b64d06f1ce7ff", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 90.5328467153, "max_line_length": 746, "alphanum_fraction": 0.7509473514, "num_tokens": 3449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.7068357359166684}}
{"text": "%\n%% Author: Jeffrey Leung\n%% Last edited: 2015-07-05\n%%\n%% This document contains section 1 (encoding) of a course overview of CMPT 150.\n%\n\n\\section{Encoding}\n\n\\subsection{Introduction}\n\\begin{easylist}[itemize]\n\n& \\emph{Alphabet:} Finite set of symbols\n\t&& E.g. $\\{0, 1\\}, \\{T, F\\}, \\{0, 1, 2, ... , 9\\}, \\{A, B, C, ... , Z\\}$\n\t\t\n& \\emph{Message:} Meaningful sequence of symbols from an alphabet\n\t&& E.g. \"CMPT 150\", \"XYZ-AB2\", 0110101 (a binary sequence)\n\t\t\n& \\emph{Encoding:} Representation of the symbols of one alphabet by sequences of symbols from a second alphabet\n\t&& \\emph{Codeword:} Meaningful sequence of symbols which translates into a sequence of symbols of another alphabet\n\t\t&&& \\emph{Uniquely decipherable:} Each codeword has only one meaning\n\t\t&&& \\emph{Fixed-length:} Each codeword has the same length\n\t\t\t&&&& Number of different codewords of length $k$ where there are $j$ elements in the alphabet is $j^k$ (e.g. 4-bit binary has $2^4 = 16$ different possibilities)\n\n\\end{easylist}\n\\subsection{Binary, Hexadecimal, and BCD}\n\\begin{easylist}[itemize]\n\n& Codewords: See \\hyperref[bin_hex_encoding_scheme]{Table~\\ref*{bin_hex_encoding_scheme}}\n\n& Binary:\n\t&& Computers interpret voltage levels of cells as 0 or 1\n\t&& \\emph{Little Endian notation:} The rightmost bit is numbered as the least significant bit (0) and the leftmost bit is numbered as the most significant bit (n-1 where n = length of sequence)\n\t&& Integer field: Digits to the left of the decimal point\n\t&& Fractional field: Digits to the right of the decimal point\n& Hexadecimal:\n\t&& Add additional leading 0s if necessary for conversion\n\n\t&& E.g. Base 2 to base 16:\n\t\\Deactivate\n\t\\begin{center}\n\t\t$001 1111 0010 1011_{2} = x_{16}$\n\t\n\t\t\\bigskip\n\t\t\\centering\n\t\t\\begin{tabular}{ c | c | c | c }\n\t\t\t0001 & 1111 & 0010 & 1011 \\\\\n\t\t\t1 & F & 2 & B \\\\\n\t\t\\end{tabular}\n\t\t\\bigskip \\\\\n\t\t$001 1111 0010 1011_{2} =$ 1F2B$_{16}$\n\t\\end{center}\n\t\\Activate\n\n\\pagebreak\n\n\\Deactivate\n\\begin{table}[!htp]\n\t\\caption{Binary/Decimal/Hexadecimal encoding scheme}\n\t\\label{bin_hex_encoding_scheme}\n\t\\centering\n\t\\begin{tabular}{ c | c | c }\n\t\tBinary: & Decimal: & Hexadecimal: \\\\\n\t\t\\hline\n\t\t0000 &  0 & 0 \\\\\n\t\t0001 &  1 & 1 \\\\\n\t\t0010 &  2 & 2 \\\\\n\t\t0011 &  3 & 3 \\\\\n\t\t0100 &  4 & 4 \\\\\n\t\t0101 &  5 & 5 \\\\\n\t\t0110 &  6 & 6 \\\\\n\t\t0111 &  7 & 7 \\\\\n\t\t1000 &  8 & 8 \\\\\n\t\t1001 &  9 & 9 \\\\\n\t\t1010 & 10 & A \\\\\n\t\t1011 & 11 & B \\\\\n\t\t1100 & 12 & C \\\\\n\t\t1101 & 13 & D \\\\\n\t\t1110 & 14 & E \\\\\n\t\t1111 & 15 & F \\\\\n\t\\end{tabular}\n\\end{table}\n\\Activate\n\n\\bigskip\n& \\emph{Binary Coded Decimal (BCD):} Encoding scheme where each decimal digit is encoded as 4 binary bits\n%&& Codewords: See \\hyperref[bcd_encoding_scheme]{Table~\\ref*{bcd_encoding_scheme}}\n\n\\Deactivate\n\\begin{table}[!htb]\n\t\\caption{BCD encoding scheme}\n\t\\label{bcd_encoding_scheme}\n\t\\centering\n\t\\begin{tabular}{ c | c }\n\t\tDecimal: & BCD: \\\\\n\t\t\\hline\n\t\t0 & 0000 \\\\\n\t\t1 & 0001 \\\\\n\t\t2 & 0010 \\\\\n\t\t3 & 0011 \\\\\n\t\t4 & 0100 \\\\\n\t\t5 & 0101 \\\\\n\t\t6 & 0110 \\\\\n\t\t7 & 0111 \\\\\n\t\t8 & 1000 \\\\\n\t\t9 & 1001 \\\\\n\t\\end{tabular}\n\\end{table}\n\\Activate\n\n\\pagebreak\n\n\t&& E.g. BCD encoding:\n\t\\Deactivate\n\t\\begin{center}\n\t\t$169_{10} = x_{BCD}$\n\t\t\\begin{table}[!htb]\n\t\t\t\\centering\n\t\t\t\\begin{tabular}{ c | c | c }\n\t\t\t\t1 & 6 & 9 \\\\\n\t\t\t\t0001 & 0110 & 1001 \\\\\n\t\t\t\\end{tabular}\n\t\t\\end{table}\n\t\t\n\t\t$169_{10} = 0001 \\ 0110 \\ 1001_{BCD}$\n\t\\end{center}\n\t\\Activate\n\n\t&& E.g. BCD decoding:\n\t\\Deactivate\n\t\\begin{center}\n\t\t$1010 \\ 0001 \\ 0110_{BCD} = x_{10}$\n\t\t\\begin{table}[!htb]\n\t\t\t\\centering\n\t\t\t\\begin{tabular}{ c | c | c }\n\t\t\t\t1010 & 0001 & 0110 \\\\\n\t\t\t\t? & 1 & 6 \\\\\n\t\t\t\\end{tabular}\n\t\t\\end{table}\n\t\t\n\t\t$1010 \\ 0001 \\ 0110_{BCD}$ is meaningless.\n\t\\end{center}\n\t\\Activate\n\n\\end{easylist}\n\\subsection{Positional Number System Conversions}\n\\subsubsection{Base 10 to Base X}\n\\begin{easylist}[itemize]\n\n& Integer: Divide the base 10 number by $x$ and write the remainder to the right. The number in base $x$ is the sequence of remainders from bottom to top.\n\n\t&& E.g. Base 10 to base 2:\n\t\\Deactivate % Deactivates easylist; allows usage of &\n\t\\begin{center}\n\t\t$13_{10} = x_{2}$\n\t\n\t\t\\begin{table}[!hb]\n\t\t\t\\centering\n\t\t\t\\begin{tabular}{ r | r l }\n\t\t\t\t            2 & 13 &   \\\\\n\t\t\t\t\\cline{2-2} 2 &  6 & 1 \\\\\n\t\t\t\t\\cline{2-2} 2 &  3 & 0 \\\\\n\t\t\t\t\\cline{2-2} 2 &  1 & 1 \\\\\n\t\t\t\t\\cline{2-2} \\multicolumn{2}{r}{0} & 1 \\\\\n\t\t\t\\end{tabular}\n\t\t\\end{table}\n\t\t\n\t\t$13_{10} = 1101_{2}$\n\t\\end{center}\n\t\\Activate\n\t\n\t&& E.g. Base 10 to base 16:\n\t\\Deactivate\n\t\\begin{center}\n\t\t$38_{10} = x_{16}$\n\t\n\t\t\\begin{table}[!hb]\n\t\t\t\\centering\n\t\t\t\\begin{tabular}{ r | r l }\n\t\t\t\t            16 & 38 &   \\\\\n\t\t\t\t\\cline{2-2} 16 &  2 & 6 \\\\\n\t\t\t\t\\cline{2-2} \\multicolumn{2}{r}{0} & 2 \\\\\n\t\t\t\\end{tabular}\n\t\t\\end{table}\n\t\n\t\t$38_{10} = 26_{16}$\n\t\\end{center}\n\t\\Activate\n\n& Fractional: Draw a line down from the decimal point. While the right side is greater than 0, multiply the right side by 2 and write the result below. The fraction in binary is the sequence of 0s and 1s on the left side from top to bottom.\n\n\t&& E.g. Base 10 to base 2:\n\t\\Deactivate\n\t\\begin{center}\n\t\t$0.625_{10} = x_{2}$\n\t\t\n\t\t\\begin{table}[!htb]\n\t\t\t\\centering\n\t\t\t\\begin{tabular}{ r : l } % ':' creates a dashed vertical line (from package arydshln)\n\t\t\t\t. & 625 \\\\\n\t\t\t\t1 & 25 \\\\\n\t\t\t\t0 & 5 \\\\\n\t\t\t\t1 & 0 \\\\\n\t\t\t\\end{tabular}\n\t\t\\end{table}\n\t\t\n\t\t$0.625_{10} = 0.101_{2}$\n\t\\end{center}\n\t\\Activate\n\n& E.g. Base 10 to base 2:\n\\Deactivate\n\\begin{center}\n\t$18.375_{10} = x_{2}$\n\t\n\t\\begin{table}[!htb]\n\t\t\\begin{minipage}{.5\\linewidth}\n\t\t\t\\centering\n\t\t\t\\begin{tabular}{ r | r l }\n\t\t\t\t            2 & 18 &   \\\\\n\t\t\t\t\\cline{2-2} 2 &  9 & 0 \\\\\n\t\t\t\t\\cline{2-2} 2 &  4 & 1 \\\\\n\t\t\t\t\\cline{2-2} 2 &  2 & 0 \\\\\n\t\t\t\t\\cline{2-2} 2 &  1 & 0 \\\\\n\t\t\t\t\\cline{2-2} \\multicolumn{2}{r}{0} & 2 \\\\\n\t\t\t\\end{tabular}\n\t\t\\end{minipage}%\n\t\t\\begin{minipage}{.5\\linewidth}\n\t\t\t\\centering\n\t\t\t\\begin{tabular}{ r : l }\n\t\t\t\t. & 375 \\\\\n\t\t\t\t0 & 75 \\\\\n\t\t\t\t1 & 5 \\\\\n\t\t\t\t1 & 0 \\\\\n\t\t\t\\end{tabular}\n\t\t\\end{minipage} \n\t\\end{table}\n\n\t$18.375_{10} = 1 \\ 0010.011_{2}$\n\\end{center}\n\\Activate\n\n\\end{easylist}\n\\subsubsection{Base X to Base 10}\n\\begin{easylist}[itemize]\n\n& Write the position values underneath each digit, then add the position values of all digits with 1s.\n\n& E.g. Base 2 to base 10:\n\\Deactivate\n\\begin{center}\n\t$10 \\ 1010 \\ 0111_{2} = x_{10}$\n\t\n\t\\begin{table}[!htb]\n\t\t\\centering\n\t\t\\begin{tabular}{ c | c | c | c | c | c | c | c | c | c }\n\t\t\t   1  &    0  &    1  &    0  &    1  &    0  &    0  &    1  &    1  &    1  \\\\\n\t\t\t$2^9$ & $2^8$ & $2^7$ & $2^6$ & $2^5$ & $2^4$ & $2^3$ & $2^2$ & $2^1$ & $2^0$ \\\\\n\t\t\\end{tabular}\n\t\\end{table}\n\n\t$2^9 + 2^7 + 2^5 + 2^2 + 2^1 + 2^0 = 679$ \\\\\n\t\\medskip\n\t$10 \\ 1010 \\ 0111_{2} = 679_{10}$\n\\end{center}\n\\Activate\n\n\\pagebreak\n\n& E.g. Base 16 to base 10:\n\\Deactivate\n\\begin{center}\n\t$26_{16} = x_{10}$\n\t\n\t\\begin{table}[!htb]\n\t\t\\centering\n\t\t\\begin{tabular}{ c | c }\n\t\t\t    2  &     6  \\\\\n\t\t\t$16^1$ & $16^0$ \\\\\n\t\t\\end{tabular}\n\t\\end{table}\n\n\t$(2 \\times 16^1) + (6 \\times 16^0) = 32 + 6 = 38$ \\\\\n\t\\medskip\n\t$26_{16} = 38_{10}$\n\\end{center}\n\\Activate\n\n& E.g. Base 2 to base 10:\n\\Deactivate\n\\begin{center}\n\t$0.101_{2} = x_{10}$\n\t\n\t\\begin{table}[!htb]\n\t\t\\centering\n\t\t\\begin{tabular}{ c c c | c | c }\n\t\t\t   0  & . &       1  &       0  &      1  \\\\\n\t\t\t$2^0$ &   & $2^{-1}$ & $2^{-2}$ & $2^{-3}$ \\\\\n\t\t\\end{tabular}\n\t\\end{table}\n\t\n\t$2^{-1} + 2^{-3} = 0.5 + 0.125 + 0.625$ \\\\\n\t\\medskip\n\t$0.101_{2} = 0.625_{10}$\n\\end{center}\n\\Activate\n\n\\subsection{Signed Arithmetic}\n\n& \\emph{Signed arithmetic:} Binary encoding which represents both positive and negative numbers\n\t&& Codewords: See \\hyperref[binary_representations]{Table~\\ref*{binary_representations}}\n\t&& Rules:\n\t\t&&& 0 is always represented\n\t\t&&& For any positive number which is represented, its corresponding negative number must also be represented\n\t&& $2^{k}-1$ codewords where $k$ is the number of bits\n\t\t&&& Greatest number which can be represented: $\\frac{2^{k} - 1}{2} = 2^{k-1}-1$\n\t\t&&& Least number which can be represented: $-2^{k-1}-1$\n\t\t&&& E.g. 4 bits can represent:\n\t\t\t&&&& In signed magnitude encoding: \\\\ $\\{-7, -6, \\dots , -1, 0, 1, \\dots , 6, 7\\}$ = 15 numbers\n\t\t\t&&&& In 2's complement encoding: \\\\ $\\{-8, -7, -6, \\dots , -1, 0, 1, \\dots , 6, 7\\}$ = 16 numbers\n\n\\Deactivate\n\\begin{table}[!hbp]\n\t\\caption{Binary representations}\n\t\\label{binary_representations}\n\t\\centering\n\t\\begin{tabular}{ | c | c | c | }\n\t\t\\hline\n\t\tCodeword & Sign-magnitude decoding & 2's complement decoding \\\\\n\t\t\\hline\n\t\t0000 &  0 &  0 \\\\\n\t\t0001 &  1 &  1 \\\\\n\t\t0010 &  2 &  2 \\\\\n\t\t0011 &  3 &  3 \\\\\n\t\t0100 &  4 &  4 \\\\\n\t\t0101 &  5 &  5 \\\\\n\t\t0110 &  6 &  6 \\\\\n\t\t0111 &  7 &  7 \\\\\n\t\t\\hline\n\t\t1000 & -0 & -8 \\\\\n\t\t1001 & -1 & -7 \\\\\n\t\t1010 & -2 & -6 \\\\\n\t\t1011 & -3 & -5 \\\\\n\t\t1100 & -4 & -4 \\\\\n\t\t1101 & -5 & -3 \\\\\n\t\t1110 & -6 & -2 \\\\\n\t\t1111 & -7 & -1 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\\Activate\n\n\\pagebreak\n\n& \\emph{Signed magnitude:} Binary encoding where the most significant bit represents whether the number is positive/negative (0 for positive, 1 for negative) and the other bits represent the value\n\t&& Conversion: Interpret the sign and value separately, then combine them\n\t\t&&& E.g. $-13_{10} = x_{2\\ \\text{(signed magnitude)}}$\n\t\t\\medskip \\\\\n\t\tSign = - = 1 \\\\\n\t\tMagnitude = $13_{10} = 1101_{2}$\n\t\t\\medskip \\\\\n\t\t$\\therefore -13_{10} = 1\\ 1101_{2\\ \\text{(signed magnitude)}}$\n\t\t\n\t\t\\bigskip\n\t\t\n\t\t&&& E.g. $100\\ 1001_{2\\ \\text{(signed magnitude)}} = x_{10}$\n\t\t\\medskip \\\\\n\t\tSign = 1 = - \\\\\n\t\tMagnitude = $1001_{2} = 9_{10}$\n\t\t\\medskip \\\\\n\t\t$\\therefore 100\\ 1001_{2\\ \\text{(signed magnitude)}} = -9_{10}$\n\t\t\n\t\t\\bigskip\n\t\t\n\t\t&&& E.g. $1000_{2\\ \\text{(signed magnitude)}} = x_{10}$\n\t\t\\medskip \\\\\n\t\tSign = 1 = - \\\\\n\t\tMagnitude = $0$\n\t\t\\medskip \\\\\n\t\t$\\therefore 1000_{2\\ \\text{(signed magnitude)}} = -0_{10}$\n\t\t\n%TODO CMPT 150 lecture notes, page 5\n\n\n\\end{easylist}", "meta": {"hexsha": "a8c72708ddc32c1d479dc9ddb34c2df2dcaa0c0a", "size": 9671, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cmpt-150-introduction-to-computer-design_partial/tex/section_1.tex", "max_stars_repo_name": "AmirNaghibi/notes", "max_stars_repo_head_hexsha": "c4640bbcb65c94b8756ccc3e4c1bbc7d5c3f8e92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2019-08-11T08:45:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T02:37:39.000Z", "max_issues_repo_path": "cmpt-150-introduction-to-computer-design_partial/tex/section_1.tex", "max_issues_repo_name": "AmirNaghibi/notes", "max_issues_repo_head_hexsha": "c4640bbcb65c94b8756ccc3e4c1bbc7d5c3f8e92", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cmpt-150-introduction-to-computer-design_partial/tex/section_1.tex", "max_forks_repo_name": "AmirNaghibi/notes", "max_forks_repo_head_hexsha": "c4640bbcb65c94b8756ccc3e4c1bbc7d5c3f8e92", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-18T09:17:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-27T21:44:56.000Z", "avg_line_length": 25.1194805195, "max_line_length": 240, "alphanum_fraction": 0.5859786992, "num_tokens": 3988, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324983301568, "lm_q2_score": 0.8670357615200474, "lm_q1q2_score": 0.7068357300055782}}
{"text": "\\section{The Field of Complex Numbers}\r\n\\subsection{Basic Definitions}\r\nWe construct the complex numbers in the following way:\r\n\\begin{definition}\r\n    Consider the plane $\\mathbb R^2$, we equip it with the \\textit{complex multiplication} $\\cdot:\\mathbb R^2\\times\\mathbb R^2\\to\\mathbb R^2$ in a way that:\r\n    $$(a,b)\\cdot(c,d)=(ac-bd,ad+bc)$$\r\n    If we denote $(x,y)$ by $x+iy$, the resulting field $(\\mathbb R^2, +, \\cdot, 1, 0)$ is called the complex numebrs, and is denotes by $\\mathbb C$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    $\\mathbb C$ is indeed a field.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nNote that $i^2=-1$\r\n\\begin{definition}\r\n    The conjugate $\\bar z$ or $z^*$ of $z=x+iy\\in\\mathbb C$ is defined as $x-iy$.\r\n    The modulus $|z|$ of $z$ is defined as $\\sqrt{z\\bar z}=\\sqrt{x^2+y^2}$.\r\n    The argument $\\arg z$ of $z$ is the angle $\\theta$ such that $z=|z|(\\cos\\theta+i\\sin\\theta)$, taken mod $2\\pi$.\r\n\\end{definition}\r\nThe last expression is called the polar form of a complex number.\r\nIt is obvious that $|zw|=|z||w|$ and that $|z|=|\\bar z|$.\r\n\\begin{claim}\r\n    The argument of any complex number $z$ is defined.\r\n\\end{claim}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nIt is worth to note that $\\tan\\theta = y/x$.\r\nAlthough there are infinitely many angles that can make the equality in the polar form, we often take the principal value, i.e. within $(-\\pi,\\pi]$.\r\nBut it is the most convenient to take it as a value in $\\mathbb R/2\\pi\\mathbb Z$.\\\\\r\nOf course, the complex numbers inherits the geometrical meanings of the plane $\\mathbb R^2$. The geometric representation of it is called the Argand diagram.\r\nOn the Argand diagram, the argument is essentially the (anticlockwise) angle between the vector representating the complex number and the positive real axis.\r\nThe modulus, at the same time, is the length of that vector.\r\nThe addition and substraction of the complex numbers are the same as what we did it with 2D vectors (i.e. parallelogram law).\\\\\r\nThere is an important theorem associated with the polynomial in the complex numbers.\r\n\\begin{theorem}[Fundamental Theorem of Algebra]\r\n    Any nonconstant polynomial in $\\mathbb C$ has a root.\r\n\\end{theorem}\r\nOne should note easily that it is equivalent to say that a nonconstant complex polynomial of order $n$ has exactly $n$ roots.\r\nThe theorem means that the process of field extensions ends at $\\mathbb C$.\r\n\\begin{proof}\r\n    Later.\r\n\\end{proof}\r\n\\begin{proposition}[Triangle Inequality]\r\n    $|z+w|\\le |z|+|w|$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Since both sides are positive, it is equivalent to its squared form:\r\n    $$(z+w)(\\bar z+\\bar w)\\le z\\bar z+w\\bar w+2|z||w|\\iff \\frac{1}{2}(z\\bar w+\\bar zw)\\le |z\\bar w|$$\r\n    But this is just to say that $\\Re (z\\bar w)\\le |z\\bar w|$, which is true.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Replacing $w$ by $w-z$ gives $|w-z|\\ge |w|-|z|$.\r\n    By symmetry $|w-z|\\ge |z|-|w|$, so we have the general form\r\n    $$|w-z|\\ge||z|-|w||$$\r\n\\end{corollary}\r\n\\begin{proposition}\r\n    Let $z_1=r_1(\\cos \\theta_1+i\\sin\\theta_1)$ and $z_2=r_2(\\cos\\theta_2+i\\sin\\theta_2)$, then\r\n    $$z_1z_2=r_1r_2(\\cos(\\theta_1+\\theta_2)+i\\sin(\\theta_1+\\theta_2))$$\r\n    That is, $\\arg z_1+\\arg z_2=\\arg z_1z_2\\pmod{2\\pi}$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Just compound angle formula suffices.\r\n    It is known to be the De Movrie's Theorem.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    $(\\cos\\theta+i\\sin\\theta)^n=\\cos(n\\theta)+i\\sin(n\\theta)$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Induction shows the case $n\\in\\mathbb N$, for negative $n=-m$, we have\r\n    $$\\text{LHS}=(\\cos(m\\theta)+i\\sin(m\\theta))^{-1}=\\cos(m\\theta)-i\\sin(m\\theta)=\\text{RHS}$$\r\n    That establishes it\r\n\\end{proof}\r\n\\subsection{Exponential and Trigonometric Functions}\r\n\\begin{definition}\r\n    $$e^z:=\\sum_{n=0}^\\infty \\frac{z^n}{n!}$$\r\n\\end{definition}\r\nThe series converges for all $z$ since it absolutely converges.\r\nAlso due to absolute convergence, we can multiply and arrange the series, which gives\r\n$$e^ze^w=e^{z+w}$$\r\nNote as well that $e^0=1$ and $(e^z)^n=e^{nz}$ for $n\\in\\mathbb Z$.\r\n\\begin{definition}\r\n    $\\cos(z)=(e^{iz}+e^{-iz})/2$, which gives the series\r\n    $$\\sum_{n=0}^\\infty(-1)^n\\frac{z^{2n}}{(2n)!}$$\r\n    Similarly $\\sin(z)=(e^{iz}-e^{-iz})/(2i)$, so its series expansion is\r\n    $$\\sum_{n=0}^\\infty(-1)^n\\frac{z^{2n+1}}{(2n+1)!}$$\r\n\\end{definition}\r\nBy differentiating the series term by term,\r\n$$(\\sin z)^\\prime=\\cos z, (\\cos z)^\\prime =-\\sin z, (e^z)^\\prime=e^z$$\r\n\\begin{theorem}\r\n    $$e^{iz}=\\cos z+i\\sin z$$\r\n\\end{theorem}\r\nNote that $\\cos z$ is not necessarily real, same for $\\sin z$.\r\nBut if $z$ is real, they are.\r\n\\begin{lemma}\r\n    $e^z=1\\iff z=2in\\pi$ for some $n\\in\\mathbb Z$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Write $z=x+iy$, then we have\r\n    $$e^{x+iy}=e^xe^{iy}=e^x(\\cos y+i\\sin y),x,y\\in\\mathbb R$$\r\n    So $e^x\\cos y=1$ and $e^x\\sin y=0$.\r\n    Solving it gives $x=0, y=0\\pmod{2\\pi i}$\r\n\\end{proof}\r\nWe have the following general form of complex number\r\n$$z=|z|e^{i\\arg z}$$\r\n\\subsection{Roots of Unity}\r\n\\begin{definition}\r\n    $z\\in\\mathbb C$ is called an $n^{th}$ root of unity if $z^n=1$\r\n\\end{definition}\r\nTo find all solutions to $z^n=1$, we write\r\n$$z=re^{i\\theta}$$\r\nso $r^n=1$ and $iN\\theta=2\\pi in$ for some $n\\in\\mathbb Z$.\r\nThis gives $n$ distinct solutions:\r\n$$z=e^{2\\pi in/N}$$\r\nwhere $n\\in \\{0,1,2,\\ldots ,n-1\\}$\r\nThe roots of unity lie on the unit circle on the Argand diagram.\r\nThey are the vertices of a regular $n$-gon.\r\n\\subsection{Logarithms and Complex Powers}\r\n\\begin{definition}\r\n    Define $w=\\log z$ by $e^w=z$ since we want $\\log$ to be the inverse of $\\exp$, which is not injective.\r\n    So $\\log$ is multi-valued.\r\n    $$\\log z=\\log|z|+i\\arg z\\pmod{2\\pi i}$$\r\n    We can, of course, make it single-valued by restricting $\\arg z$ to the principal branch $(-\\pi,\\pi]$ or $[0,2\\pi)$.\r\n    But in this case, we do not have $\\log(ab)=\\log a+\\log b$\r\n\\end{definition}\r\nIn fact, one can prove that it is impossible to choose a $\\log$ in the complex plane that lives up to every one of our expectations.\r\n\\begin{example}\r\n    If $z=-1$, then $\\log z=i\\pi\\pmod{2\\pi i}$.\r\n\\end{example}\r\n\\begin{definition}\r\n    We define $z^\\alpha=e^{\\alpha\\log z}$ for any $\\alpha, z\\in\\mathbb C$ where $z\\neq 0$.\r\n    Note that since $\\log$ is multi-valued, the complex powers are multi-valued in general.\r\n    They differ by a multiplicative factor in the form $e^{2n\\pi i\\alpha},n\\in\\mathbb Z$.\r\n\\end{definition}\r\nIf $\\alpha\\in\\mathbb Z$, then the power is single-valued.\r\nIf $\\alpha\\in\\mathbb Q$, it is finite-valued.\r\nBut in general, a complex power admits infinitely many values.\r\n\\begin{example}\r\n    1. We want to calculate $i^i$. $\\log i=\\pi/2+2\\pi ni$, so\r\n    $$i^i=e^{i\\log i}=e^{-\\pi/2+2\\pi n}$$\r\n    where $n\\in\\mathbb Z$.\\\\\r\n    2. We want to calculate $(1+i)^{1/2}$, so it equals\r\n    $$e^{1/2\\log\\sqrt 2+i(\\pi/4+2n\\pi i)}=2^{1/4}e^{i\\pi/8}/2$$\r\n\\end{example}\r\n\\subsection{Lines and Circles}\r\nFor a fixed $w\\in\\mathbb C$ such that $w\\neq 0$, the set of points $z=\\lambda w$ is a line through the origin in the direction of $w$.\\\\\r\nBy shifting $z=z_0+\\lambda w$ is a line parallel to $z=\\lambda w$ though $z_0$.\\\\\r\nTo write this in the form without the real parameter $\\lambda$, we take the conjugate\r\n$$\\bar z=\\bar z_0+\\lambda\\bar w$$\r\nConbining the two equations and eleminate $\\lambda$, we have $\\bar wz-w\\bar z=\\bar wz_0-w\\bar z_0$.\r\nThis is one standard form of the equation of a line (there are others though).\\\\\r\nThe equation of a circle centered at $c\\in\\mathbb C$ with radius $\\rho$ is given by $|z-c|=\\rho$, which is to say\r\n$$(z-c)(\\bar z-\\bar c)=\\rho^2\\iff z\\bar z-c\\bar z-\\bar cz=\\rho^2-c\\bar c$$\r\nThe general form of a point on the circle is $c+\\rho e^{i\\theta}$ where $\\theta$ is a real parameter.\\\\\r\nNote that in the geometrical viewpoint of $\\mathbb C$, $z\\mapsto z+z_0$ is a translation, $z\\mapsto\\lambda z$ where $\\lambda\\in\\mathbb R$ is a scaling, $z\\mapsto ze^{i\\theta}$ where $\\theta\\in\\mathbb R$ is a rotation, $z\\mapsto\\bar z$ is a translation, $z\\mapsto 1/z$ is an inversion.\r\nComparing with groups, translation, rotation, scaling, inversion generates the Mobius group which normally acts on $\\mathbb C_\\infty=\\mathbb C\\cup\\{\\infty\\}\\cong S^2$ by stereographic projection.\r\nOn $\\mathbb C_\\infty$, lines in $\\mathbb C$ are circles.", "meta": {"hexsha": "3031910b65c35d6dd7f87ce8fed8ad29ddd77256", "size": 8325, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/complex.tex", "max_stars_repo_name": "david-bai-notes/IA-Vectors-and-Matrices", "max_stars_repo_head_hexsha": "7fc43486ec5276262d4058c9daaea12affdb6bac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1/complex.tex", "max_issues_repo_name": "david-bai-notes/IA-Vectors-and-Matrices", "max_issues_repo_head_hexsha": "7fc43486ec5276262d4058c9daaea12affdb6bac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1/complex.tex", "max_forks_repo_name": "david-bai-notes/IA-Vectors-and-Matrices", "max_forks_repo_head_hexsha": "7fc43486ec5276262d4058c9daaea12affdb6bac", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.6898734177, "max_line_length": 285, "alphanum_fraction": 0.6616216216, "num_tokens": 2842, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664175, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7068357121815013}}
{"text": "\\section{Deterministic Capital Budgeting}\n\\label{sec:DeterministicCapitalBudgeting}\n\nWe consider a capital budgeting problem for a nuclear generation station, with possible extension to\na larger fleet of plants.\nDue to limited resources, we can only select a subset from a list of\nseveral candidate capital projects.\nOur goal is to maximize overall NPV associated with the\nselected subset.\nIn doing so, we must respect resource limits and capture key structural and\nstochastic dependencies of the system, although in this section we start with the simpler\ndeterministic case, ignoring randomness.\nExample projects include upgrading a steam turbine,\nrefurbishing or replacing a set of reactor coolant pumps, and replacing a set of feed-water heaters.\n\n\\[\n\\begin{array}{ll}\n%%%%%%%%%%%%%% INDICES AND SET %%%%%%%%%%%%%%%%\n\\multicolumn{2}{l}{\\mbox{\\em Indexes and sets:} } \\\\\nt \\in T  & \\mbox{time periods (years)} \\\\\ni \\in I  & \\mbox{investment candidate projects} \\\\\nj \\in J_{i}\t& \\mbox{options for selecting project $i$} \\\\%, e.g., initiate project $i$ in year $t$ or $t+2$ and in a standard (three year) or in an expedited (two year) manner} \\\\\n% i^{'},j^{'} \\in IJ_{ij} & \\mbox{piggybacking situations} \\\\%, i.e., option $j^{'}$ for project $i^{'}$ can be selected only if option $j$ is selected for project $i$} \\\\\nk \\in K\t& \\mbox{types of resources} \\\\%, e.g., capital funds, O\\&M funds, labor-hours, time during outage} \\\\\n\\\\\n%%%%%%%%%%%%%% DATA %%%%%%%%%%%%%%%%\n\\multicolumn{2}{l}{\\mbox{\\em Data:}} \\\\\na_{ij} & \\mbox{reward (revenue minus financial cost) of selecting project $i$ via option $j$}  \\\\\nb_{kt} & \\mbox{available budget for a resource of type $k$ in year $t$}\\\\\nc_{ijkt}  & \\mbox{consumption of resource of type $k$ in year $t$ if project $i$ is performed via option $j$} \\\\\n\\\\\n%%%%%%%%%%%%%% DECISION VARS %%%%%%%%%%%%%%%%\n\\multicolumn{2}{l}{\\mbox{\\em Decision variables:}}  \\\\\nx_{ij} & \\mbox{1 if project $i$ is selected via option $j$; 0 otherwise} \\hspace*{4.0in}\\\\\n\\end{array}\n\\]\n\n\\vst \\noi {\\em Formulation:}\n\\begin{subequations}\\label{model-deter}\n\\begin{eqnarray}\n&\\dst \\max_{x} &  \\dst \\sum_{i \\in I, j \\in J_{i}} a_{ij} x_{ij} \\label{obj_deter} \\\\\n& s. t.  & \\sum_{j \\in J_{i}} x_{ij} = 1,   i \\in I \\\\\n& & \\sum_{i \\in I, j \\in J_{i}} c_{ijkt} x_{ij} \\leq b_{kt}, k \\in K, t \\in T \\\\\n& & x_{ij} \\in \\{0,1\\}, j \\in J_{i}, i \\in I.\n\\end{eqnarray}\n\\end{subequations}\n\nThe decision variables, $x_{ij}$, indicate whether we choose to do project i by means j. Restated,\nif $x_{ij}=1$, then we recommend doing project $i$ via option $j$; taken together, these decision\nvariables produce both a portfolio of selected projects and a schedule for performing those projects\nover time.  The set of available options, $j \\in J_i$, can explicitly include the “do-nothing” option,\nand the first constraint ensures that we choose exactly one option from the available set for each\nproject, including the possibility of selecting the do-nothing option. Even if we select the\ndo-nothing option for a project, it induces an NPV, $a_{ij}$, which may be negative, representing\ngrowing O\\&M costs, losses in plant efficiency, etc. The second structural constraint ensures that\nthe budget of each resource $k$ is respected in each year $t$. The objective function\nincludes the NPV for each project-option pair, $a_{ij}$, and the correct NPV is selected by\nthe $0-1$ decision variable, $x_{ij}$.\n\n% The third structural constraint\n% captures piggybacking situations in which option $j^{'}$ for project $i^{'}$ (which may have cheaper\n% costs) may be selected only if project-option pair $(i,j)$ is also selected.\n\nWe note that certain projects must be done (e.g., for safety and or regulatory\nreasons). This can be handled within the mathematical formulation just given, without introducing\nadditional constructs. The set $J_i$ typically includes a do-nothing option for each project,\nbut when project $i$ must be done, we simply do not include the do-nothing option. Mathematically,\none alternative is to disclude an explicit do-nothing option, replace the first structural\nconstraint with an inequality, and add an additional set of must-do projects with an equality\nconstraint. Both options are mathematically equivalent and simply represent a choice to be made by\nthe analyst. In LOGOS, we use \\xmlNode{mandatory} and \\xmlNode{nonSelection} to\nhandle these conditions. \\xmlNode{mandatory} is used to specify the must-do projects,\nwhile \\xmlNode{nonSelection} is used to activate the do-nothing option.\n\n\\nb If a project is listed under \\xmlNode{mandatory}, the do-nothing option is not allowed\nfor this project. In addition, handling the do-nothing option implicitly leads to the NPV being\ncalculated relative to that of the do-nothing option.\n\nThe objective of capital budgeting is to find the right combination of binary decisions for\nevery investment so that overall profit is maximized. The output is a\ncollection of projects to be carried out, and we refer to this selected collection of projects\nas a ``project portfolio''. However, as is frequently the case for capital budgeting with\nNPP applications, in practice, several optional constraints, such as resources/liabilities,\ndependencies/synergies, options, time windows for every investment, etc., have to be\nfulfilled. This leads to a various variations of the knapsack problem.\nIn the following subsection, we will present several different variants of the above\ncapital budgeting problem (i.e., variants of the knapsack problem).\n\n\\subsection{Single Knapsack Problem Optimization}\n\\label{subsec:skp}\n\n\\subsubsection{Simple Knapsack Problem}\nThe simple knapsack problem (KP) for capital budgeting can be defined as follows:\nwe are given an instance of the capital budgeting problem with investment set $I$,\nconsisting of $I$ investments $i$ with profit $a_i$ (e.g. NPV), cost $c_i$,\nand available budget $b$. The objective is to select a subset of $I$ such\nthat the total profit of the selected investments is maximized and the total cost does\nnot exceed $b$. Alternatively, KP can be formulated as a solution of the following\nlinear integer programming formulation:\n\n\\begin{subequations}\\label{simpleKP}\n\\begin{eqnarray}\n&\\dst \\max_{x} &  \\dst \\sum_{i \\in I} a_{i} x_{i} \\\\\n& s. t. & \\sum_{i \\in I} c_{i} x_{i} \\leq b\\\\\n& & x_{i} \\in \\{0,1\\}, i \\in I.\n\\end{eqnarray}\n\\end{subequations}\n\nExample LOGOS input XML:\n\\begin{lstlisting}[style=XML]\n<Logos>\n  <Sets>\n    <investments>\n      1,2,3,4,5,6,7,8,9,10\n    </investments>\n  </Sets>\n\n  <Parameters>\n    <net_present_values index=\"investments\">\n      18,20,17,19,25,21,27,23,25,24\n    </net_present_values>\n    <costs index=\"investments\">\n      1,3,7,4,8,9,6,10,2,5\n    </costs>\n    <available_capitals>\n      15\n    </available_capitals>\n  </Parameters>\n\n  <Settings>\n    <solver>cbc</solver>\n    <sense>maximize</sense>\n  </Settings>\n</Logos>\n\\end{lstlisting}\n\nWhen running this case, LOGOS would generate a CSV (comma separated values) file\ncontaining solutions for the optimization problem (i.e. values of decision variables\nand maximum profit [MaxNPV is used to describe the maximum profit]). The header of\nthis CSV file contains the indices listed under \\xmlNode{investments}\nused as indices for decision variables and the objective variable \\textbf{MaxNPV}.\nThe data provides the values for both decision variables and the objective variable.\n\nExample LOGOS output CSV:\n\\begin{lstlisting}[language=python]\n1,2,3,4,5,6,7,8,9,10,MaxNPV\n1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,106.0\n\\end{lstlisting}\n\nIn this case, projects \\textbf{1, 2, 4, 9, and 10} are selected with a maximum\nprofit of 106.0.\n\n\\subsubsection{Bounded Knapsack Problem}\nIn the capital budgeting problem described above, it may be the case that not all\ninvestments/projects are different from each other. For example, in practice,\nthere may be given a number ($n_i$) of identical pumps/valves to be replaced. In this\ncase, the number of decision variables is equal to the number of different\ninvestments, rather than the total number of investments. The constraint for the\ndecision variables becomes:\n\\begin{equation}\n0\\leq x_i \\leq n_i, i\\in N\n\\end{equation}\nThe resulting problem is called the bounded knapsack problem (BKP) and is formally defined as:\n\n\\begin{subequations}\\label{boundedKP}\n\\begin{eqnarray}\n&\\dst \\max_{x} &  \\dst \\sum_{i \\in I} a_{i} x_{i} \\\\\n& s. t. & \\sum_{i \\in I} c_{i} x_{i} \\leq b\\\\\n& & x_{i} \\in \\{0,n_i\\}, i \\in I.\n\\end{eqnarray}\n\\end{subequations}\n\nExample LOGOS input XML:\n\\begin{lstlisting}[style=XML]\n<Logos>\n  <Sets>\n    <investments>\n      1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,\n      14, 15, 16, 17, 18, 19, 20, 21, 22\n    </investments>\n  </Sets>\n\n  <Parameters>\n    <net_present_values index=\"investments\">\n      150,35,200,60,60,45,60,40,30,10,70,\n      30,15,10,40,70,75,80,20,12,50,10\n    </net_present_values>\n    <costs index=\"investments\">\n      9,13,153,50,15,68,27,39,23,52,11,32,\n      24,48,73,42,43,22,7,18,4,30\n    </costs>\n    <available_capitals>\n      400\n    </available_capitals>\n  </Parameters>\n\n  <Settings>\n    <lowerBounds>\n      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\n    </lowerBounds>\n    <upperBounds>\n      1,1,2,2,2,3,3,3,1,3,1,\n      1,2,2,1,1,1,1,1,2,1,2\n    </upperBounds>\n    <solver>glpk</solver>\n    <sense>maximize</sense>\n  </Settings>\n</Logos>\n\\end{lstlisting}\n\nExample LOGOS output CSV:\n\\begin{lstlisting}[language=python]\n1,2,...,21,22,MaxNPV\n1.0,1.0,...,1.0,0.0,1010.0\n\\end{lstlisting}\n\n\\subsubsection{Multi-Dimensional Knapsack Problem: DKP}\nMoving in a different direction, we now take into account not only the cost constraint, but also\nthe limited commitment of critical resources, including: (i) capital cost, (ii) O\\&M\ncosts, (iii) time and labor-hours during a planned outage, and (iv) personnel,\ninstallation and maintenance equipment, workspaces, etc.. Denoting the cost of every\ninvestment by $c_{ik}$ for each resource $k$ and introducing the corresponding limited resource\n$b_k$, we can formulate the capital budgeting problem as a multi-dimensional\nor D-dimensional knapsack problem formally defined by:\n\n\\begin{subequations}\\label{boundedKP}\n\\begin{eqnarray}\n&\\dst \\max_{x} &  \\dst \\sum_{i \\in I} a_{i} x_{i} \\\\\n& s. t. & \\sum_{i \\in I} c_{ik} x_{i} \\leq b_k, k\\in K\\\\\n& & x_{i} \\in \\{0,1\\}, i \\in I.\n\\end{eqnarray}\n\\end{subequations}\n\nWhere the limited resources set is denoted by $K$, consisting of $k$ “colors” of money\nwithin capital costs, O\\&M costs, personnel availability, etc.\nAnother example is provided if the plant has multi-year investments. Consider a DKP problem in\nwhich the costs of each investment and the available capitals vary according to time\nperiod $t$. By defining $c_{it}$ as the cost of investment $i$ at time period $i$,\nand $b_t$ as the available capital at time period $t$, we get:\n\n\\begin{subequations}\\label{DKP}\n\\begin{eqnarray}\n&\\dst \\max_{x} &  \\dst \\sum_{i \\in I} a_{i} x_{i} \\\\\n& s. t. & \\sum_{i \\in I} c_{it} x_{i} \\leq b_t, t\\in T\\\\\n& & x_{i} \\in \\{0,1\\}, i \\in I.\n\\end{eqnarray}\n\\end{subequations}\n\nExample LOGOS input XML:\n\\begin{lstlisting}[style=XML]\n<Logos>\n  <Sets>\n    <investments>\n      1,2,3,4,5,6,7,8,9\n    </investments>\n    <time_periods>\n      1,2,3,4,5\n    </time_periods>\n  </Sets>\n\n  <Parameters>\n    <net_present_values index=\"investments\">\n      2.315,0.824,22.459,60.589,0.667,5.173,4.003,0.582,0.122\n    </net_present_values>\n    <costs index=\"investments, time_periods\">\n      0.219,0.257,0.085,0.0,0.0,\n      0.0,0.0,0.122,0.103,0.013,\n      5.044,1.839,0.0,0.0,0.0,\n      6.74,6.134,10.442,0.0,0.0,\n      0.425,0.0,0.0,0.0,0.0,\n      2.125,2.122,0.0,0.0,0.0,\n      2.387,0.19,0.012,2.383,0.192,\n      0.0,0.95,0.0,0.0,0.0,\n      0.03,0.03,0.688,0.0,0.0\n    </costs>\n    <available_capitals index=\"time_periods\">\n      0.665,4.712,9.642,3.458,1.683\n    </available_capitals>\n  </Parameters>\n\n  <Settings>\n    <solver>glpk</solver>\n    <sense>maximize</sense>\n  </Settings>\n</Logos>\n\\end{lstlisting}\n\nExample LOGOS output CSV:\n\\begin{lstlisting}[language=python]\n1,2,3,4,5,6,7,8,9,MaxNPV\n1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,4.388\n\\end{lstlisting}\n\n\n\\subsection{Multiple Knapsack Problem Optimization}\n\\label{subsec:mkp}\nAnother interesting variant of the capital budgeting problem arises if we consider\nmaintenance for multiple units in a NPP in parallel, i.e. it has to be decided whether\nto accept a particular replacement and, in the positive case, in which unit to conduct\nthe corresponding replacement. This can be formulated by\nintroducing a binary decision variable for every maintenance-unit combination.\nIf there are $I$ investments (investment set $I$) on the list of maintenance requests and $m$\nunits (unit set $M$) available, we use binary variables:\n\n\\begin{equation}\nx_{im} \\in \\{0,1\\}, i\\in I, m\\in M\n\\end{equation}\nThe resulting problem is called the multiple knapsack problem (MKP),\nand the mathematical formulation is given by:\n\n\\begin{subequations}\\label{MKP}\n\\begin{eqnarray}\n&\\dst \\max_{x} &  \\dst \\sum_{m \\in M} \\sum_{i \\in I} a_{i} x_{im} \\\\\n& s. t. & \\sum_{i \\in I} c_{i} x_{im} \\leq b_m, m \\in M\\\\\n& & \\sum_{m \\in M} x_{im} \\leq 1 \\\\\n& & x_{im} \\in \\{0,1\\}, i \\in I, m \\in M.\n\\end{eqnarray}\n\\end{subequations}\n\nExample LOGOS input XML:\n\\begin{lstlisting}[style=XML]\n<Logos>\n  <Sets>\n    <investments>\n      1,2,3,4,5,6,7,8,9,10\n    </investments>\n    <capitals>\n      unit_1, unit_2\n    </capitals>\n  </Sets>\n\n  <Parameters>\n    <net_present_values index=\"investments\">\n      78, 35, 89, 36, 94, 75, 74, 79, 80, 16\n    </net_present_values>\n    <costs index=\"investments\">\n      18, 9, 23, 20, 59, 61, 70, 75, 76, 30\n    </costs>\n    <available_capitals index=\"capitals\">\n      103, 156\n    </available_capitals>\n  </Parameters>\n\n  <Settings>\n    <solver>cbc</solver>\n    <sense>maximize</sense>\n    <problem_type>MultipleKnapsack</problem_type>\n  </Settings>\n</Logos>\n\\end{lstlisting}\n\nExample LOGOS output CSV:\n\\begin{lstlisting}[language=python]\n1,2,3,4,5,6,7,8,9,10,capitals,MaxNPV\n0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,unit_1,452.0\n1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,unit_2,452.0\n\\end{lstlisting}\n\n\n\\subsection{Multiple-Choice Multi-Dimensional Knapsack Problem Optimization}\n\\label{subsec:mckp}\nAnother quite different variant of the capital budgeting problem appears if there may\nbe multiple ways to carry out each investment/project. Each investment $i$, however, exists\nin a number of options in which the j-th option has cost $c_{ij}$ and profit\nvalue $a_{ij}$. This problem can be expressed as the multiple-choice knapsack problem\n(MCKP). Assume $J_i$ is the set of different options for investment $i$. Using the\ndecision variables $x_{ij}$ to denote whether option $j$ was chosen from the set $J_i$,\nthe mathematical formulation of MCKP is given by:\n\n\\begin{subequations}\\label{MKP}\n\\begin{eqnarray}\n&\\dst \\max_{x} &  \\dst \\sum_{i \\in I, j \\in J_{i}} a_{ij} x_{ij} \\\\\n& s. t.  & \\sum_{j \\in J_{i}} x_{ij} = 1,   i \\in I \\\\\n& & \\sum_{i \\in I, j \\in J_{i}} c_{ij} x_{ij} \\leq b \\\\\n& & x_{ij} \\in \\{0,1\\}, j \\in J_{i}, i \\in I.\n\\end{eqnarray}\n\\end{subequations}\n\nConsidering the limited resources and multi-year investments, the MCKP may be extended\nto a D-dimensional MCKP problem (D-MCKP). For example, a project may be performed over\na three-year period--say, years `$t$, $t+1$, $t+2$'--or the start of the project could\ninstead be two years hence, changing the equation to `$t+2$, $t+3$, $t+4$'.\nAlternatively, at increased cost and benefit, it may be possible to complete\nthe project in two years: `$t$, $t+1$', or `$t+2$, $t+3$'. When selecting a project to\nuprate plant capacity, we may have the options of increasing it by 3\\% or 6\\%.\nIn these cases, the problem can be expressed as the D-MCKP.\nThis problem is formally defined as follows:\n\n\\begin{subequations}\\label{model-deter}\n\\begin{eqnarray}\n&\\dst \\max_{x} &  \\dst \\sum_{i \\in I, j \\in J_{i}} a_{ij} x_{ij} \\label{obj_deter} \\\\\n& s. t.  & \\sum_{j \\in J_{i}} x_{ij} = 1,   i \\in I \\\\\n& & \\sum_{i \\in I, j \\in J_{i}} c_{ijt} x_{ij} \\leq b_{t}, t \\in T \\\\\n& & x_{ij} \\in \\{0,1\\}, j \\in J_{i}, i \\in I.\n\\end{eqnarray}\n\\end{subequations}\n\nor in the same as the problem described at the beginning of this chapter\n(see Section~\\ref{sec:DeterministicCapitalBudgeting}):\n\n\\begin{subequations}\\label{model-deter}\n\\begin{eqnarray}\n&\\dst \\max_{x} &  \\dst \\sum_{i \\in I, j \\in J_{i}} a_{ij} x_{ij} \\label{obj_deter} \\\\\n& s. t.  & \\sum_{j \\in J_{i}} x_{ij} = 1,   i \\in I \\\\\n& & \\sum_{i \\in I, j \\in J_{i}} c_{ijkt} x_{ij} \\leq b_{kt}, k \\in K, t \\in T \\\\\n& & x_{ij} \\in \\{0,1\\}, j \\in J_{i}, i \\in I.\n\\end{eqnarray}\n\\end{subequations}\n\nExample LOGOS input XML:\n\\begin{lstlisting}[style=XML]\n<Logos>\n  <Sets>\n    <investments>\n      1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17\n    </investments>\n    <options index='investments'>\n      1;\n      1;\n      1;\n      1,2,3;\n      1,2,3,4;\n      1,2,3,4,5,6,7;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1;\n      1\n    </options>\n  </Sets>\n\n  <Parameters>\n    <net_present_values index='options'>\n      2.046 2.679 2.489 2.61 2.313 1.02 3.013 2.55 3.351 3.423 3.781 2.525\n      2.169 2.267 2.747 4.309 6.452 2.849 7.945 2.538 1.761 3.002 3.449\n      2.865 3.999 2.283 0.9 8.608\n    </net_present_values>\n    <costs index='options'>\n      36538462\n      83849038\n      4615385\n      2788461538\n      2692307692\n      5480769231\n      1634615385\n      2981730768\n      7211538462\n      9038461538\n      649038462\n      650000000\n      216346154\n      212500000\n      3076923077\n      3942307692\n      1144230769\n      675721154\n      1442307692\n      99711538\n      4807692\n      123076923\n      138461538\n      86538462\n      108653846\n      75092404\n      6413462\n      147932692\n    </costs>\n    <available_capitals>\n      15E9\n    </available_capitals>\n  </Parameters>\n\n  <Settings>\n    <solver>cbc</solver>\n    <sense>maximize</sense>\n    <problem_type>mckp</problem_type>\n  </Settings>\n</Logos>\n\\end{lstlisting}\n\nExample LOGOS output CSV:\n\\begin{lstlisting}[language=python]\n1__1,2__1,3__1,4__1,4__2,4__3,...,17__1,MaxNPV\n1.0,1.0,1.0,1.0,0.0,0.0,...,1.0,59.82600000000001\n\\end{lstlisting}\n\nIn the output file, the names \\textbf{``investmentsIndex\"\\_\\_``optionsIndex\"} are used to\nspecify the decision variable. For example, \\textbf{1\\_\\_1} indicates that investment \\textbf{1}\nwith option \\textbf{1} is selected.\n", "meta": {"hexsha": "15e74363847b6454f840f605e4c7a2f7fcd6c424", "size": 18393, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/user_manual/include/DeterministicCapitalBudgeting.tex", "max_stars_repo_name": "dgarrett622/LOGOS", "max_stars_repo_head_hexsha": "7234b8b5e80bc79526b4cbced7efd5ae482f7c44", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-05-04T08:42:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-03T13:14:12.000Z", "max_issues_repo_path": "doc/user_manual/include/DeterministicCapitalBudgeting.tex", "max_issues_repo_name": "albernsrya/LOGOS", "max_issues_repo_head_hexsha": "535a25ccd3a83259b615acd569257d751fe00439", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 28, "max_issues_repo_issues_event_min_datetime": "2021-01-12T17:41:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-03T18:20:16.000Z", "max_forks_repo_path": "doc/user_manual/include/DeterministicCapitalBudgeting.tex", "max_forks_repo_name": "albernsrya/LOGOS", "max_forks_repo_head_hexsha": "535a25ccd3a83259b615acd569257d751fe00439", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-02-05T17:18:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T14:36:42.000Z", "avg_line_length": 37.0080482897, "max_line_length": 179, "alphanum_fraction": 0.6850975915, "num_tokens": 6288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7068357113266593}}
{"text": "\\subsection{Orthogonal matrices}\n\nRecall that the process to find the inverse of a matrix was often cumbersome.\nIn contrast, it was very easy to take the transpose of a matrix. Luckily for some special\nmatrices, the transpose equals the inverse. When an $n \\times n$-matrix has all real\nentries and its transpose equals its inverse, the matrix is called an \\textbf{orthogonal matrix}.\n\nThe precise definition is as follows.\n\n\\begin{definition}{Orthogonal matrices}{orthogonal-matrices}\nA real $n\\times n$-matrix $U$ is called an\n\\index{matrix!orthogonal} \\textbf{orthogonal} matrix if $UU^{T}=U^{T}U=I$.\n\\end{definition}\n\nNote since $U$ is assumed to be a square matrix, it suffices to verify\nonly one of these equalities $UU^{T}=I$ or $U^{T}U=I$ holds to\nguarantee that $U^T$ is the inverse of $U$.\n\nConsider the following example.\n\n\\begin{example}{Orthogonal matrix}{}\nShow the matrix\n\\begin{equation*}\nU=\\begin{mymatrix}{rr}\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}}\n\\end{mymatrix}\n\\end{equation*}\nis orthogonal.\n\\end{example}\n\n\\begin{solution}\nAll we need to do is verify (one of the equations from) the requirements of Definition~\\ref{def:orthogonal-matrices}.\n\n\\begin{equation*}\nUU^{T}=\\begin{mymatrix}{rr}\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}}\n\\end{mymatrix} \\begin{mymatrix}{rr}\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}}\n\\end{mymatrix} =\\allowbreak \\begin{mymatrix}{cc}\n1 & 0 \\\\\n0 & 1\n\\end{mymatrix}\n\\end{equation*}\n\nSince $UU^{T} = I$, this matrix is orthogonal.\n\\end{solution}\n\nHere is another example.\n\n\\begin{example}{Orthogonal matrix}{}\nLet $U=\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 0 & -1 \\\\\n0 & -1 & 0\n\\end{mymatrix}$. Is $U$ orthogonal?\n\\end{example}\n\n\\begin{solution}\nAgain the answer is yes and this can be verified simply by showing that $U^{T}U=I$:\n\n\\begin{eqnarray*}\nU^{T}U&=&\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 0 & -1 \\\\\n0 & -1 & 0\n\\end{mymatrix} ^{T}\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 0 & -1 \\\\\n0 & -1 & 0\n\\end{mymatrix} \\\\\n&=&\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 0 & -1 \\\\\n0 & -1 & 0\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 0 & -1 \\\\\n0 & -1 & 0\n\\end{mymatrix} \\\\\n&=&\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{mymatrix}\n\\end{eqnarray*}\n\\end{solution}\n\nWhen we say that $U$ is orthogonal, we are saying that $UU^T=I$, meaning that\n\\begin{equation*}\n\\sum_{j}u_{ij}u_{jk}^{T}=\\sum_{j}u_{ij}u_{kj}=\\delta _{ik}\n\\end{equation*}\nwhere $\\delta _{ij}$ is the \\textbf{Kronecker symbol}\ndefined\n\\index{Kronecker symbol} by\n\\begin{equation*}\n\\delta _{ij}=\\left\\{\n\\begin{array}{c}\n1\n\\text{ if }i=j \\\\\n0\\text{ if }i\\neq j\n\\end{array}\n\\right.\n\\end{equation*}\n\nIn words, the product of the $i\\th$ row of $U$ with the $k\\th$ row\ngives $1$ if $i=k$ and $0$ if $i\\neq k$. The same is true of the columns because\n$U^{T}U=I$ also. Therefore,\n\\begin{equation*}\n\\sum_{j}u_{ij}^{T}u_{jk}=\\sum_{j}u_{ji}u_{jk}=\\delta _{ik}\n\\end{equation*}\nwhich says that the product of one column with another column gives $1$ if the two\ncolumns are the same and $0$ if the two columns are different.\n\nMore succinctly, this states that if $\\vect{u}_{1},\\ldots,\\vect{u}_{n}$\nare the columns of $U$, an orthogonal matrix, then\n\\[\n\\vect{u}_{i}\\dotprod \\vect{u}_{j}=\\delta _{ij} = \\left\\{\n\\begin{array}{c}\n1\\text{ if }i=j \\\\\n0\\text{ if }i\\neq j\n\\end{array}\n\\right.\n\\]\n\nWe will say that the columns form an orthonormal set of vectors, and similarly for the rows. Thus a matrix is \\textbf{orthogonal} if its rows (or columns) form an\n\\textbf{orthonormal} set of vectors. Notice that the convention is to call such a matrix orthogonal rather than orthonormal (although this may make more sense!).\n\n\\begin{proposition}{Orthonormal basis}{orthonormal-basis}\nThe rows of an $n \\times n$ orthogonal matrix form an orthonormal\nbasis of $\\R^n$. Further, any orthonormal basis of\n$\\R^n$ can be used to construct an $n \\times n$ orthogonal\nmatrix.\n\\end{proposition}\n\n\\begin{proof}\nRecall from Theorem~\\ref{thm:orthonormal-basis} that an orthonormal set is\nlinearly independent and forms a basis for its span. Since the rows of\nan $n \\times n$ orthogonal matrix form an orthonormal set, they must\nbe linearly independent. Now we have $n$ linearly independent vectors,\nand it follows that their span equals $\\R^n$. Therefore these\nvectors form an orthonormal basis for $\\R^n$.\n\nSuppose now that we have an orthonormal basis for $\\R^n$. Since the\nbasis will contain $n$ vectors, these can be used to construct an $n\n\\times n$-matrix, with each vector becoming a row. Therefore the\nmatrix is composed of orthonormal rows, which by our above discussion,\nmeans that the matrix is orthogonal. Note we could also have construct\na matrix with each vector becoming a column instead, and this would\nagain be an orthogonal matrix. In fact this is simply the transpose of\nthe previous matrix.\n\\end{proof}\n\nConsider the following proposition.\n\n\\begin{proposition}{Determinant of orthogonal matrices}{orthogonal-determinant}\nSuppose $U$ is an orthogonal matrix. Then $\\det (U) = \\pm 1$.\n\\end{proposition}\n\n\\begin{proof}\nThis result follows from the properties of determinants. Recall that\nfor any matrix $A$, $\\det(A)^T = \\det(A)$. Now if $U$ is orthogonal, then:\n\\begin{equation*}\n(\\det (U)) ^{2}=\\det (U^{T}) \\det (U)\n=\\det (U^{T}U) =\\det (I) =1\n\\end{equation*}\n\nTherefore $(\\det (U))^2 = 1$ and it follows that $\\det (U) = \\pm 1$.\n\\end{proof}\n\nOrthogonal matrices are divided into two classes, proper and improper.\n\\index{matrix!proper}\\index{matrix!improper}\nThe proper orthogonal matrices are those whose determinant equals 1\nand the improper ones are those whose determinant equals $-1$. The\nreason for the distinction is that the improper orthogonal matrices\nare sometimes considered to have no physical significance. These\nmatrices cause a change in orientation which would correspond to\nmaterial passing through itself in a non-physical manner. Thus in\nconsidering which coordinate systems must be considered in certain\napplications, you only need to consider those which are related by a\nproper orthogonal transformation. Geometrically, the linear\ntransformations determined by the proper orthogonal matrices\ncorrespond to the composition of rotations.\n\nWe conclude this section with two useful properties of orthogonal matrices.\n\n\\begin{example}{Product and inverse of orthogonal matrices}{product-inverse-orthogonal}\nSuppose $A$ and $B$ are orthogonal matrices. Then $AB$ and $A^{-1}$ both exist and are orthogonal.\n\\end{example}\n\n\\begin{solution}\nFirst we examine the product $AB$.\n\\[ (AB)(B^TA^T)=A(BB^T)A^T =AA^T=I \\]\nSince $AB$ is square, $B^TA^T=(AB)^T$ is the inverse of\n$AB$, so $AB$ is invertible, and $(AB)^{-1}=(AB)^T$\nTherefore, $AB$ is orthogonal.\n\nNext we show that $A^{-1}=A^T$ is also orthogonal.\n\\[ (A^{-1})^{-1} = A = (A^T)^{T}\n=(A^{-1})^{T} \\]\nTherefore $A^{-1}$ is also orthogonal.\n\\end{solution}\n", "meta": {"hexsha": "2123e7ceb0a869227aa0e6e32c932dc794d71cbd", "size": 7045, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/RnVectorsOrthogonalityMatrices.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/RnVectorsOrthogonalityMatrices.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/RnVectorsOrthogonalityMatrices.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 34.3658536585, "max_line_length": 162, "alphanum_fraction": 0.7071682044, "num_tokens": 2301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.754914997895581, "lm_q2_score": 0.9362850048591, "lm_q1q2_score": 0.7068155924728716}}
{"text": "\\documentclass[a4paper,10pt]{article}\n\n%\\usepackage[landscape]{geometry}\n\n\\usepackage{mathtools}\n\\usepackage{booktabs}\n\\usepackage{tabularx}\n\n\\title{\\vspace*{-2cm}Big \\(\\bigO\\)-notation for A\\&W algorithms}\n\\date{}\n\n\\pagenumbering{gobble}\n\n\\newcommand{\\bigO}{\\mathcal{O}}\n\n\\begin{document}\n    \\maketitle\n    \\renewcommand{\\arraystretch}{1.25}\n    \\subsection*{Definitions}\n    \\begin{center}\n        \\begin{tabularx}{\\textwidth}{l >{\\raggedleft\\arraybackslash}X}\n            \\toprule\n            Number of vertices in a graph & \\(n\\) \\\\\n            Number of edges in a graph & \\(m\\) \\\\\n            Highest capacity in network & \\(U\\) \\\\\n            Number of vertices at the edge of a convex hull & \\(h\\) \\\\\n            Variable chosen for desired accuracy of Monte-Carlo algorithms & \\(\\lambda\\) \\\\\n            \\bottomrule\n        \\end{tabularx}\n    \\end{center}\n\n    \\subsection*{Overview of algorithms}\n\n    Some of the algorithms are randomized. They thus have their average runtime noted.\n    \\begin{center}\n    \\begin{tabular}{lr}\n        \\toprule\n        Maximal flow (Ford-Fulkerson) & \\(\\bigO(mnU)\\)\\\\\n        Maximal flow (Capacity Scaling) & \\(\\bigO(mn(1 + \\log U))\\) \\\\\n        Maximal flow (Dynamic Trees) & \\(\\bigO(mn\\log n)\\) \\\\\n        Smallest enclosing disc (naive) & \\(\\bigO(n^4)\\) \\\\\n        Eulerian path in connected graph & \\(\\bigO(m)\\) \\\\\n        Count Hamiltonian cycles in graph & \\(\\bigO(n^{2.81}\\log n \\cdot 2^n)\\) \\\\\n        2-approximation of Metric TSP & \\(\\bigO(n^2)\\) \\\\\n        1.5-approximation of Metric TSP & \\(\\bigO(n^3)\\) \\\\\n        Maximal matching & \\(\\bigO(m)\\) \\\\\n        Maximum matching in bipartite graph (Hopcroft-Karp) & \\(\\bigO(\\sqrt{n}(n+m))\\) \\\\\n        Perfect matching in \\(2^k\\)-regular bipartite graph & \\(\\bigO(m)\\) \\\\\n        Greedy coloring & \\(\\bigO(m)\\) \\\\\n        \\(\\bigO(\\sqrt{n})\\)-coloring for 3-colorable graphs & \\(\\bigO(m)\\) \\\\\n        Convex hull (Jarvis-Wrap) & \\(\\bigO(nh)\\) \\\\\n        Convex hull with \\textit{sorted} points (LocalRepair) & \\(\\bigO(n)\\) \\\\\n        QuickSelect & \\(\\bigO(n)\\) \\\\\n        Miller-Rabin prime test & \\(\\bigO(\\ln n)\\) \\\\\n        Colorful-Path with length \\(\\log n\\) & \\(\\bigO(mn \\log n)\\) \\\\\n        Minimal cut (naive) & \\(\\bigO(\\lambda n^4)\\) \\\\\n        Minimal cut (single bootstrapping) & \\(\\bigO(\\lambda n^3)\\) \\\\\n        Minimal cut (repeated bootstrapping) & \\(\\bigO(n^2\\text{poly}(\\log n))\\) \\\\\n        Smallest enclosing disc (clever randomized) & \\(\\bigO(n \\log n)\\) \\\\\n        \\bottomrule\n    \\end{tabular}\n    \\end{center}\n\\end{document}", "meta": {"hexsha": "c9605eafcbe4aa09d82fb7ab46b98aac9d9ba8fc", "size": 2550, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "anw-runtime/anw-runtime.tex", "max_stars_repo_name": "XYQuadrat/eth-cheatsheets", "max_stars_repo_head_hexsha": "d25d20190246c1444208fa0337d875d794bd6f8f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-11-29T21:28:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-21T00:48:40.000Z", "max_issues_repo_path": "anw-runtime/anw-runtime.tex", "max_issues_repo_name": "XYQuadrat/eth-cheatsheets", "max_issues_repo_head_hexsha": "d25d20190246c1444208fa0337d875d794bd6f8f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-08-02T15:39:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-09T18:24:51.000Z", "max_forks_repo_path": "anw-runtime/anw-runtime.tex", "max_forks_repo_name": "XYQuadrat/eth-cheatsheets", "max_forks_repo_head_hexsha": "d25d20190246c1444208fa0337d875d794bd6f8f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-08-02T14:07:26.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-09T18:01:08.000Z", "avg_line_length": 40.4761904762, "max_line_length": 91, "alphanum_fraction": 0.5803921569, "num_tokens": 786, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.70680620310344}}
{"text": "\\section{Linear and Higher Order Approximations}\\label{sec:Approx}\r\nWhen we define the derivative $f^{\\prime\r\n}\\left( x\\right) $ as the rate of change of $f\\left( x\\right) $ with respect\r\nto $x,$ we notice that in relation to the graph of $f,$ the derivative is\r\nthe slope of the tangent line, which (loosely speaking) is the line that just\r\ngrazes the graph. But what precisely do we mean by this? In short,\r\n\\textbf{the tangent line approximates the graph near the point of contact}. The\r\ndefinition of the derivative $f^{\\prime }\\left( a\\right) $ guarantees this\r\nwhen it exists: By taking $x$ sufficiently close to $a$ but not equal to $a,$%\r\n\\begin{equation*}\r\n\\frac{f\\left( x\\right) -f\\left( a\\right) }{x-a}\\approx f^{\\prime }\\left(\r\na\\right) ,\r\n\\end{equation*}%\r\nand consequently,%\r\n\\begin{equation*}\r\nf\\left( x\\right) \\approx f^{\\prime }\\left( a\\right) \\left( x-a\\right)\r\n+f\\left( a\\right) .\r\n\\end{equation*}%\r\nThe left hand side gives us the $y$-value of the function $y=f\\left(\r\nx\\right) $ and the right hand side gives us the $y$-value $y=f^{\\prime\r\n}\\left( a\\right) \\left( x-a\\right) +f\\left( a\\right) $ for the tangent line\r\nto the graph of $f$ at the point $\\left( a,f\\left( a\\right) \\right) .$\r\n\r\nIn this section we will explore how to apply this idea to approximate some\r\nvalues of $f$, some changes in the values of $f$, and also the roots of $f.$\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n% Subsections to include\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\input{5-applications-of-derivatives/5-4-1-linear-approximations}\r\n\\input{5-applications-of-derivatives/5-4-2-differentials}\r\n\\input{5-applications-of-derivatives/5-4-3-taylor-polynomials}\r\n\\input{5-applications-of-derivatives/5-4-4-newtons-method}\r\n\r\n% Exercises for each subsection are in the separate files", "meta": {"hexsha": "ad7fa27d82c22e48dc7e5471c7912c31339f6d75", "size": 1795, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-4-0-approximations.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5-applications-of-derivatives/5-4-0-approximations.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5-applications-of-derivatives/5-4-0-approximations.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.2857142857, "max_line_length": 80, "alphanum_fraction": 0.6763231198, "num_tokens": 530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.706806179647843}}
{"text": "\\subsection{The macroelement technique}\n\n\\begin{intro}\n  The arguments of the previous section can be extended to the case\n  where instead of individual mesh cell $\\cell$ we condider small\n  groups of such cells, called\n  \\putindex{macroelement}s~\\cite{Stenberg84}. This will give us some\n  more freedom for testing the inf-sup condition locally, but possibly\n  not on each cell separately. In order to get uniform estimates, we\n  introduce a generalization of the concept of shape regularity.\n\\end{intro}\n\n\\begin{Definition}{macro-equivalence}\n  A \\define{macroelement} $M\\subset \\T_h$ is a union of cell\n  $\\cell_i\\in\\T_h$. Given the mappings $\\Phi_\\cell\\colon \\widehat\\cell \\to\n  \\cell$, there is a reference macroelement $\\widehat M$ and a mapping\n  $\\Phi_M\\colon \\widehat M\\to M$ such that $\\Phi_M(\\widehat M) = M$. We say\n  that $M$ is equivalent to $\\widehat M$.\n\\end{Definition}\n\n\\begin{Definition}{macro-spaces}\n  For a \\putindex{macroelement} $M$, we introduce the spaces\n  \\begin{align}\n    \\label{eq:macroelement:27}\n    V_M &= \\bigl\\{ u\\in H^1_0(M;\\R^d) \\big\\vert\n            \\;\\exists v_h\\in V_h\\colon u=v_{h|M}\\bigr\\},\n    \\\\\n    \\label{eq:macroelement:28}\n    Q_M &= \\bigl\\{ p\\in L^2_0(M) \\big\\vert\n            \\;\\exists q_h\\in Q_h\\colon p=q_{h|M}\\bigr\\},\n  \\end{align}\n  the kernel of the discrete, local gradient operator\n  \\begin{gather}\n    \\label{eq:macroelement:29}\n    \\ker{B^\\transpose_M} = \\bigl\\{q\\in Q_M \\big\\vert \n    \\;\\forall v\\in V_M\\colon \\form(\\div v,q) = 0\\bigr\\}.\n  \\end{gather}\n  For a mesh $\\mesh_h$ which is subdivided into a nonoverlapping set\n  of macros $M_j$, we define the space of pressure functions\n  $Q_M^0\\subset Q$ which are constant on each macro with the\n  $L^2$-projection $\\Pi_M\\colon Q_h\\to Q_M^0$.\n\\end{Definition}\n\n\\begin{Lemma}{macro-local}\n  Let $\\{M\\}$ with $M\\subset \\mesh_h$ be a set of macroelements\n  equivalent to the same reference macroelement $\\widehat M$. Let the\n  family $\\{\\mesh_h\\}$ be shape regular and assume\n  $\\ker{B^\\transpose_{M}} = \\{0\\}$. Then, there is a constant\n  $\\beta_M>0$ independent of $h$ such that for all $M$ there holds\n  \\begin{gather}\n    \\label{eq:macroelement:31}\n    \\inf_{p\\in Q_M} \\sup_{v\\in V_M}\n    \\frac{\\form(\\div v,q)_M}{\\norm{v}_{1,M}\\norm{q}_{0,M}}\n    \\ge \\beta_{\\widehat M}.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  For each $M$, the existence of such a constant $\\beta_{M}$ is\n  equivalent to the fact that the smallest nonzero singular value is\n  strictly greater than zero in finite dimensional spaces. Next, we\n  observe that $\\nabla \\Phi_{M}$ is bounded by the\n  $\\nabla\\Phi_{\\cell_i}$, which in turn is uniformly bounded by the\n  shape regularity. Therefore, by a cell-wise scaling argument and the\n  fact that $\\widehat M$ has only finitely many cells we have\n  \\begin{gather}\n    \\beta_{\\widehat M} = \\min_M \\beta_M > 0.\n  \\end{gather}\n\\end{proof}\n\n\\begin{remark}\n  Depending on the technique of proof being used, we also may decide\n  to impose~\\eqref{eq:macroelement:31} directly for each macroelement.\n\\end{remark}\n\n\\begin{Lemma}{macro-projection}\n  Let $\\mesh_h$ be subdivided into a nonoverlapping set of\n  macroelements $M$ such that there is a finite set of reference macro\n  elements $\\widehat M$, and let $\\ker{B^\\transpose_M} = \\{0\\}$. Then, there is\n  a constant $c_1>0$ such that for all $q_h\\in Q_h$ exists $v_h\\in V_h$\n  satisfying\n  \\begin{gather}\n    \\label{eq:macroelement:32}\n    \\begin{split}\n      \\form(\\div v_h, q_h) = \\form(\\div v_h,{(\\identity-\\Pi_M)} q_h)\n      &\\ge c_1 \\norm{(\\identity-\\Pi_M) q_h}_0^2\\\\\n      \\norm{v_h}_2 & \\le \\norm{(\\identity-\\Pi_M) q_h}_0.\n    \\end{split}\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  For any $q_h\\in Q_h$, we have $(\\identity-\\Pi_M) q_h\\in Q_M$ for each\n  macroelement $M$. Applying \\slideref{Lemma}{macro-local}, for each\n  $M$ there exists $v_M\\in V_M$ such that\n  \\begin{gather}\n    \\form(\\div v_M, {(\\identity-\\Pi_M)} q_h)_M\n    \\ge c_1 \\norm{v_M}_{1,M}\\norm{(\\identity-\\Pi_M) q_h}_{0,M},\n  \\end{gather}\n  with $c=\\min \\beta_{\\widehat M}$. Let now $v_M$ such that\n  $\\norm{v_M}_{1,M} = \\norm{(\\identity-\\Pi_M) q_h}_{0,M}$ and $v$ such that\n  $v_{|M} = v_M$. Since $v_M$ is zero on $\\d M$, we have $v\\in\n  V_h$. By construction,~\\eqref{eq:macroelement:32} holds.\n\\end{proof}\n\n\\begin{Lemma}{macro-constant}\n  Let $\\{M_j\\}$ be a covering of $\\mesh_h$ with macroelements. For any\n  two macros $M_i$ and $M_j$ let $T_{ij}$ be their common\n  boundary. Then, if every $T_{ij}$ of codimension one contains at\n  least one degree of freedom controlling $u\\cdot\\n$, there is a\n  constant $c_2>0$ such that for every $q_h\\in Q_h$ exists $w_h\\in\n  V_h$ such that\n  \\begin{gather}\n    \\label{eq:macroelement:33}\n    \\begin{split}\n      \\form(\\div w_h, \\Pi_M q_h) &\\ge c_2 \\norm{\\Pi_M q_h}^2_0\\\\\n      \\norm{w_h}_1 &\\le \\norm{\\Pi_M q_h}_0.\n    \\end{split}\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Problem}\n  Prove \\slideref{Lemma}{macro-constant}\n\\end{Problem}\n\n\\begin{Theorem}{macroelement}\n  Let the assumptions of \\slideref{Lemma}{macro-projection}\n  hold. Then, the pair $V_h\\times Q_h$ is inf-sup stable.\n\\end{Theorem}\n\n\\begin{proof}\n  Let $q_h\\in Q_h$. Then, applying \\slideref{Lemma}{macro-projection}\n  and \\slideref{Lemma}{macro-constant}, we obtain functions $v_h$ and\n  $w_h$ such that for $u_h = v_h+ \\delta w_h$ for any $\\delta>0$ there\n  holds\n  \\begin{align}\n    \\form(\\div u_h, q_h)\n    &= \\form(\\div v_h, q_h) + \\form(\\div w_h, q_h) \\\\\n    &\\ge c_1 \\norm{(\\identity-\\Pi_M) q_h}_0^2\n      + \\delta c_2 \\norm{\\Pi_M q_h}_0^2\n      - \\delta \\norm{w_h}_1 \\norm{(\\identity-\\Pi_M) q_h}_0 \\\\\n    & = (c_1 - \\delta) \\norm{(\\identity-\\Pi_M) q_h}_0^2\n      + \\delta c_2 \\norm{\\Pi_M q_h}_0^2.\n  \\end{align}\n  Choosing $\\delta = c_1/(1+c_2)$, we obtain\n  \\begin{gather}\n    \\label{eq:macroelement:34}\n    \\begin{split}\n      \\form(\\div u_h, q_h) &\\ge \\frac{c_1c_2}{1+c_2} \\norm{q}_0^2 \\\\\n      \\norm{u}_1 &\\le \\norm{q}_0.\n    \\end{split}\n  \\end{gather}\n\\end{proof}\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "4ab0e09e3f1e5649cb1d95ebfc9a8162f0ca3236", "size": 6004, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mixed/macroelement84.tex", "max_stars_repo_name": "arimiftari/notes", "max_stars_repo_head_hexsha": "737b95ed6a4163bd1d395c0379410513dcb03ef1", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mixed/macroelement84.tex", "max_issues_repo_name": "arimiftari/notes", "max_issues_repo_head_hexsha": "737b95ed6a4163bd1d395c0379410513dcb03ef1", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-05-24T07:31:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-31T12:58:14.000Z", "max_forks_repo_path": "mixed/macroelement84.tex", "max_forks_repo_name": "arimiftari/notes", "max_forks_repo_head_hexsha": "737b95ed6a4163bd1d395c0379410513dcb03ef1", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-05-15T19:28:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-05T19:07:29.000Z", "avg_line_length": 37.525, "max_line_length": 79, "alphanum_fraction": 0.666389074, "num_tokens": 2109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.835483553488848, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7067709887020667}}
{"text": "\\section{Brownian Motion}\n\n\\begin{frame}{Brownian motion}\nBrownian motion can be constructed as a limit of random walks.\n\\begin{eqnarray*}\n P(Y_i=\\Delta x)=\\frac{1}{2} \\\\\n P(Y_i=-\\Delta x)=\\frac{1}{2}\n\\end{eqnarray*}\n\\pause\n\n\\begin{center}\nWhat is the distribution of \n\\begin{equation*}\nX_n=Y_1+Y_2+...+Y_n\n\\end{equation*}\nif $Y_1,Y_2,...,Y_n$ are i.i.d.? \n\\end{center}\n\\end{frame}\n\n\n\\begin{frame}\n\\begin{eqnarray*}\nX_n&= &Y_1+Y_2+...+Y_n\\\\ \\\\\n\\pause\n\\ln (M_{X_n})(\\lambda)&\\approx &\\frac{(\\Delta x)^2}{\\Delta t} \\left(\\frac{\\lambda ^2 T}{2}+\\frac{\\lambda ^4 \\Delta x ^2 T}{4}+... \\right)\\\\\n\\end{eqnarray*}\n\\pause\nIf we assume that $\\frac{(\\Delta x)^2}{\\Delta t}=k$ then,\n\\begin{equation*}\n\\lim_{\\Delta x \\to 0}{M_{X_n}(\\lambda)}=\\exp\\left(\\frac{kT\\lambda ^2}{2}\\right)\n\\end{equation*}\nwhich means $X_n \\sim N(0,kT)$\n\\end{frame}\n\n\\begin{frame}\n\\begin{block}{Standard Brownian Motion}\nA random variable $B(t)$ that depends continuously on $t \\in [0,T]$ and satisfies: \n\\begin{itemize}\n\\item $B(0)=0$\n\\item For $0 \\leq s<t\\leq T$: $B(t)-B(s)\\sim N(0, t-s)$\n\\item For $0 \\leq s<t<u<v\\leq T$ the increments $B(t)-B(s)$ and $B(v)-B(u)$ are independent.\n\\end{itemize}\n\\end{block}\n\\end{frame}\n\n\\begin{frame}{Computational Purposes}\n\\pause\nDiscretized Brownian motion: $B(t)$ is specified at discrete t values.\n\\begin{eqnarray*}\n&& W(0)=0\\\\\n&& W(j)=W(j-1)+dW(j)\n\\end{eqnarray*}\n$dW(j)$ is an independent random variable of the form $N(0,\\Delta t)$\\cite{doi:10.1137/S0036144500378302}.\n\\end{frame}\n\n\\begin{frame}\n\\begin{center}\n\\includegraphics[scale=0.5]{r_w_3.png}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}\n\\begin{center}\n\\includegraphics[scale=0.5]{r_w_4.png}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}\n\\begin{center}\n\\includegraphics[scale=0.5]{hist.png}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}\n\\begin{center}\n\\includegraphics[scale=0.5]{qqplot.png}\n\\end{center}\n\\end{frame}\n\n\n\\section{Stochastic Integrals}\n\n\\begin{frame}{Stochastic Differential Equations}\n\\pause\nWe'll take an ordinary differential equation that contains a deterministic part and add an additional stochastic term:\n\\begin{eqnarray*}\ndx=fdt+gdB\n\\end{eqnarray*}\n\\end{frame}\n\n\\begin{frame}{Stochastic Integrals}\n\\pause\n\\begin{center}\nWhat does $\\int_{a}^{b} f(t)dB$ mean? \\bigskip \\pause  $\\int_{a}^{b} B(t)dB$?\\pause \\\\\n\n\\begin{equation*}\n\\sum_{i=1}^{n}B(t_{j-1})\\left( B(t_{j})-B(t_{j-1})\\right) ?\n\\end{equation*}\n\\pause\n\\bigskip\n\nIn $[0,1]$ with $\\Delta t=1/500$:\\\\ \nLeft hand side=-0.42765\\\\ \nMid-Point=0.088892\n\\end{center}\n\\end{frame}\n\n\n\\begin{frame}\n\\begin{block}{Definition}\nGiven f(t) a continuous function with bounded variation. Let $a_i=f(t_{i-1})$, then \\textbf{the Wiener integral} is:\n\\begin{equation*}\nI(f):=\\lim_{n \\to \\infty}\\sum_{i=1}^{n}a_i(B(t_i)-B(t_{i-1}))\n\\end{equation*}\n\\pause\n\\begin{itemize}\n\\item $E[I(f)]=0$\n\\item $Var[I(f)]=\\int_{a}^{b}f^2(t)dt$\n\\end{itemize}\n\\end{block}\n\\end{frame}\n", "meta": {"hexsha": "98e9ab12dacdf16eda2062d26dcdb8003cd68383", "size": 2870, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Presentations/Midterm/HighamPaper.tex", "max_stars_repo_name": "SUNY-SDE-2015/REU15", "max_stars_repo_head_hexsha": "a54ace642d8696250c7fa0bf574b16a931ec91c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Presentations/Midterm/HighamPaper.tex", "max_issues_repo_name": "SUNY-SDE-2015/REU15", "max_issues_repo_head_hexsha": "a54ace642d8696250c7fa0bf574b16a931ec91c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-06-04T17:55:32.000Z", "max_issues_repo_issues_event_max_datetime": "2015-07-09T15:38:17.000Z", "max_forks_repo_path": "Presentations/Midterm/HighamPaper.tex", "max_forks_repo_name": "SUNY-SDE-2015/REU15", "max_forks_repo_head_hexsha": "a54ace642d8696250c7fa0bf574b16a931ec91c9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5245901639, "max_line_length": 139, "alphanum_fraction": 0.6735191638, "num_tokens": 1117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245618, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.7067709833939989}}
{"text": "\\section{Areas in Polar Coordinates}\\label{sec:Areas in polar coordinates}\nWe can use the equation of a curve in polar coordinates to compute\nsome areas bounded by such curves.\nThe basic approach is the same as with any application of integration:\nFind an approximation that approaches the true value. For areas in\nrectangular coordinates, we approximated the region using rectangles;\nin polar coordinates, we use sectors of circles, as depicted in\nFigure~\\ref{fig:approximating area with sectors}. Recall that the\narea of a sector of a circle is $\\ds \\alpha r^2/2$, where $\\alpha$ is the\nangle subtended by the sector. If the curve is given by $r=f(\\theta)$,\nand the angle subtended by a small sector is $\\Delta\\theta$, \nthe area is $\\ds (\\Delta\\theta)(f(\\theta))^2/2$.\nThus we approximate the total area as\n$$\\sum_{i=0}^{n-1} {1\\over 2} f(\\theta_i)^2\\;\\Delta\\theta.$$\nAs a limit, this will give rise to:\n$$\\int_a^b {1\\over 2} f(\\theta)^2\\;d\\theta.$$\n\n\\begin{example}{Area inside a Cardioid}{cardioidarea}\nFind the area inside the cardioid $r=1+\\cos\\theta$.\n\\end{example}\n\n\\begin{solution}\n$$\\int_0^{2\\pi}{1\\over 2} (1+\\cos\\theta)^2\\;d\\theta=\n\\ds{1\\over 2}\\int_0^{2\\pi} 1+2\\cos\\theta+\\cos^2\\theta\\;d\\theta=\n\\ds{1\\over 2}\\left(\\theta +2\\sin\\theta+\n\\ds{\\theta\\over2}+\\ds{\\sin2\\theta\\over4}\\middle)\\right|_0^{2\\pi}={3\\pi\\over2}.$$\n\\end{solution}\n\nAs in the example above, if a function is defined over the complete region $[0,2\\pi]$, then the bounds for the integral are $a=0$, $b=2\\pi$. However, sometimes we need to be careful!\n\n\\begin{example}{Area inside a Loop}{areainloop}\nFind the area inside the loop $r=\\sqrt{\\cos\\theta}$.\n\\end{example}\n\\begin{solution}\nWe look for points of intersection.\n\\begin{align*}\n0&=\\sqrt{\\cos\\theta}\t\\\\\n0&=\\cos\\theta\n\\end{align*}\nThis has solutions $\\theta=\\pi/2$ and $3\\pi/2$, but we must select our bounds for integration correctly. Since $\\cos\\theta$ is negative on $(\\pi/2,3\\pi/3)$, $\\sqrt{\\cos\\theta}$ is undefined. Note that one full revolution is $2\\pi$; that is, the function is $2\\pi$ periodic. If we were to integrate on $[3\\pi/2,\\pi/2]$ we would get the same answer, and can avoid a scenario in which $\\sqrt{\\cos\\theta}$ is undefined. Equivalently, we can integrate on $[-\\pi/2,\\pi/2]$.\n\\[\\ds \\int_a^b\\frac{1}{2} f(\\theta)^2\\,d\\theta=\\int_{-\\pi/2}^{\\pi/2}\\frac{1}{2}\\left(\\sqrt{\\cos\\theta}\\right)^2\\,d\\theta=\\frac{1}{2}\\int_{-\\pi/2}^{\\pi/2}\\cos\\theta\\,d\\theta=\\frac{1}{2}\\Big(\\sin\\theta\\Big)\\Big|_{-\\pi/2}^{\\pi/2}=1\\]\n\\end{solution}\n\n\\figure[H]\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <20truemm,20truemm>\n\\setplotarea x from 0 to 2.5, y from 0  to 1.5\n\\axis left shiftedto x=0 /\n\\axis bottom shiftedto y=0 /\n\\setquadratic\n\\plot 1.941 0.393 1.900 0.506 1.850 0.613 1.791 0.715 1.723 0.811\n1.648 0.900 1.565 0.981 1.476 1.054 1.382 1.118 1.284 1.172\n1.182 1.217 1.078 1.252 0.973 1.278 0.867 1.293 0.762 1.299\n0.659 1.295 0.559 1.283 0.462 1.262 0.369 1.233 0.281 1.196\n0.199 1.153 /\n\\setlinear\n\\plot 0 0 0.75 1.299 /\n\\circulararc -15 degrees from 0.75 1.299 center at 0 0 \n\\plot 0 0 1.207 1.207 /\n\\circulararc -15 degrees from 1.207 1.207 center at 0 0\n\\plot 0 0 1.616 0.933 / \n\\circulararc -15 degrees from 1.616 0.933 center at 0 0\n\\plot 0 0 1.9 0.51 /\n\\endpicture}}\n\\caption{{Approximating area by sectors of circles.} \\label{fig:approximating area with sectors}}\n\\endfigure\n\n\\begin{example}{Area Between Circles}{areabetweencircles}\nFind the area between the circles $r=2$ and\n$r=4\\sin\\theta$, as shown in figure~\\ref{fig:polar area between curves}.\n\\end{example}\n\n\\begin{solution}\nThe two curves intersect where $2=4\\sin\\theta$, or $\\sin\\theta=1/2$,\nso $\\theta=\\pi/6$ or $5\\pi/6$. The area we want is then\n$$\n  {1\\over2}\\int_{\\pi/6}^{5\\pi/6}\n  16\\sin^2\\theta-4\\;d\\theta={4\\over3}\\pi + 2\\sqrt{3}.\n$$\n\\end{solution}\n\n%\\figure[!ht]\n%\\centerline{\n%\\hbox{\\hfill\\tikzpicture[domain=-2:2,x=6mm,y=6mm]\n%\\draw[->] (-2.1,0) -- (2.1,0) ;\n%\\draw[->] (0,-2.1) -- (0,4.1) ;\n%\\gpad\n%\\draw[color=black] plot[parametric,id=\\the\\gpnum,domain=0:2*3.1416,samples=50] \n%function{2*cos(t),2*sin(t)};\n%\\gpad\n%\\draw[color=black] plot[parametric,id=\\the\\gpnum,domain=0:3.1416,samples=50] \n%function{4*sin(t)*cos(t),4*sin(t)*sin(t)};\n%\\gpad\n%\\fill[opacity=0.5,fill=red!20] \n%plot[parametric,id=\\the\\gpnum,domain=0.5236:2.618]\n%function{4*sin(t)*cos(t),4*sin(t)*sin(t)} node {\\gpad}\n%plot[parametric,id=\\the\\gpnum,domain=0.5236:2.618]\n%function{2*cos(3.1416-t),2*sin(3.1416-t)} -- cycle;\n%\\endtikzpicture\\hfill}}\n%\\caption{{An area between curves.} \\label{fig:polar area between curves}}\n%\\endfigure\n\n\\figure[H]\n\\[\n\\includegraphics[width=1.75in]{images/7-area-circles} \n\\] \n\\caption{{An area between curves.} \\label{fig:polar area between curves}}\n\\endfigure\n\nThis first example makes the process appear more straightforward than it\nis. Since points have many different representations in polar\ncoordinates, it is not always so easy to identify points of\nintersection. \n\n\\begin{example}{Shaded Area}{shadedarea}\nFind the shaded area in the first graph of\nfigure~\\ref{fig:harder area between polar curves} as the difference\nof the other two shaded areas. The cardioid is $r=1+\\sin\\theta$ and\nthe circle is $r=3\\sin\\theta$. \n\\end{example}\n\n\\begin{solution}\nWe attempt to find points of intersection:\n\\begin{eqnarray*}\n  1+\\sin\\theta&=3\\sin\\theta\\cr\n  1&=2\\sin\\theta\\cr\n  1/2&=\\sin\\theta.\\cr\n\\end{eqnarray*}\nThis has solutions $\\theta=\\pi/6$ and $5\\pi/6$; $\\pi/6$ corresponds to\nthe intersection in the first quadrant that we need.  Note that no\nsolution of this equation corresponds to the intersection point at the\norigin, but fortunately that one is obvious. The cardioid goes through\nthe origin when $\\theta=-\\pi/2$; the circle goes through the origin at\nmultiples of $\\pi$, starting with $0$.\n\nNow the larger region has area\n$$\n  {1\\over2}\\int_{-\\pi/2}^{\\pi/6} (1+\\sin\\theta)^2\\;d\\theta=\n  {\\pi\\over2}-{9\\over16}\\sqrt{3},\n$$\nand the smaller has area\n$$\n  {1\\over2}\\int_{0}^{\\pi/6} (3\\sin\\theta)^2\\;d\\theta=\n  {3\\pi\\over8} - {9\\over16}\\sqrt{3},\n$$\nso the difference is the area we seek, which is $\\pi/8$.\n\\end{solution}\n\n\n\n%\\figure[!ht]\n%\\centerline{\n%\\hbox to \\hsize{\\hfill\\tikzpicture[domain=-2:2,x=9mm,y=9mm]\n%\\draw[->] (-1.6,0) -- (1.6,0) ;\n%\\draw[->] (0,-1) -- (0,3.1) ;\n%\\gpad\n%\\draw[color=black] plot[parametric,id=\\the\\gpnum,domain=0:2*pi,samples=50] \n%function{(1+sin(t))*cos(t),(1+sin(t))*sin(t)};\n%\\gpad\n%\\draw[color=black] plot[parametric,id=\\the\\gpnum,domain=0:pi,samples=50] \n%function{3*sin(t)*cos(t),3*sin(t)*sin(t)};\n%\\gpad\n%\\fill[opacity=0.5,fill=red!20] \n%plot[parametric,id=\\the\\gpnum,domain=-pi/2:pi/6]\n%function{(1+sin(t))*cos(t),(1+sin(t))*sin(t)} node {\\gpad}\n%plot[parametric,id=\\the\\gpnum,domain=0:pi/6] \n%function{3*sin(pi/6-t)*cos(pi/6-t),3*sin(pi/6-t)*sin(pi/6-t)}; \n%\\endtikzpicture\n%\\quad\n%\\tikzpicture[domain=-2:2,x=9mm,y=9mm]\n%\\draw[->] (-1.6,0) -- (1.6,0) ;\n%\\draw[->] (0,-1) -- (0,3.1) ;\n%\\gpad\n%\\draw[color=black] plot[parametric,id=\\the\\gpnum,domain=0:2*pi,samples=50] \n%function{(1+sin(t))*cos(t),(1+sin(t))*sin(t)};\n%\\gpad\n%\\draw[color=black] plot[parametric,id=\\the\\gpnum,domain=0:pi,samples=50] \n%function{3*sin(t)*cos(t),3*sin(t)*sin(t)};\n%\\gpad\n%\\fill[opacity=0.5,fill=red!20] \n%plot[parametric,id=\\the\\gpnum,domain=-pi/2:pi/6]\n%function{(1+sin(t))*cos(t),(1+sin(t))*sin(t)}; \n%\\endtikzpicture\n%\\quad\n%\\tikzpicture[domain=-2:2,x=9mm,y=9mm]\n%\\draw[->] (-1.6,0) -- (1.6,0) ;\n%\\draw[->] (0,-1) -- (0,3.1) ;\n%\\gpad\n%\\draw[color=black] plot[parametric,id=\\the\\gpnum,domain=0:2*pi,samples=50] \n%function{(1+sin(t))*cos(t),(1+sin(t))*sin(t)};\n%\\gpad\n%\\draw[color=black] plot[parametric,id=\\the\\gpnum,domain=0:pi,samples=50] \n%function{3*sin(t)*cos(t),3*sin(t)*sin(t)};\n%\\gpad\n%\\fill[opacity=0.5,fill=red!20] \n%plot[parametric,id=\\the\\gpnum,domain=0:pi/6] \n%function{3*sin(t)*cos(t),3*sin(t)*sin(t)}; \n%\\endtikzpicture\n%\\hfill}}\n%\\caption{{An area between curves.} \\label{fig:harder area between polar curves}}\n%\\endfigure\n\\figure[H]\n\\[\n\\includegraphics[width=4.5in]{images/7-area-between} \n\\] \n\\caption{{An area between curves.} \\label{fig:harder area between polar curves}}\n\\endfigure\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Areas in polar coordinates}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex}\nFind the area enclosed by the curve.\n\\begin{multicols}{2}\n\\begin{enumerate}\n\t\\item\t$\\ds r=\\sqrt{\\sin\\theta}$\n\t\\item\t$\\ds r=2+\\cos\\theta$\n\t\\item\t$\\ds r=\\sec\\theta, \\pi/6\\le\\theta\\le\\pi/3$\n\t\\item\t$\\ds r=\\cos\\theta, 0\\le\\theta\\le\\pi/3$\n\t\\item\t$\\ds r=2a\\cos\\theta, a>0$\n\t\\item\t$\\ds r=4+3\\sin\\theta$\n\\end{enumerate}\n\\end{multicols}\n\\begin{sol}\n\\begin{multicols}{2}\n\\begin{enumerate}\n\t\\item\t$1$\n\t\\item\t$9\\pi/2$\n\t\\item\t$\\ds \\sqrt3/3$\n\t\\item\t$\\ds \\pi/12+\\sqrt3/16$\n\t\\item\t$\\ds \\pi a^2/4$\n\t\\item\t$41\\pi/2$\n\\end{enumerate}\n\\end{multicols}\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the area inside the loop formed by\n$\\ds r=\\tan(\\theta/2)$.\n\\begin{sol}\n $2-\\pi/2$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the area inside one loop of $\\ds r=\\cos(3\\theta)$.\n\\begin{sol}\n $\\pi/12$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the area inside one loop of $\\ds r=\\sin^2\\theta$.\n\\begin{sol}\n $3\\pi/16$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the area inside the small loop of $\\ds r=(1/2)+\\cos\\theta$.\n\\begin{sol}\n $\\ds \\pi/4-3\\sqrt3/8$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the area inside $\\ds r=(1/2)+\\cos\\theta$, including the\narea inside the small loop.\n\\begin{sol}\n $\\ds \\pi/2+3\\sqrt3/8$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the area inside one loop of $\\ds r^2=\\cos(2\\theta)$.\n\\begin{sol}\n $1$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the area enclosed by $r=\\tan\\theta$ and \n$\\ds r={\\csc\\theta\\over\\sqrt2}$.\n\\begin{sol}\n $3/2-\\pi/4$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the area inside $r=2\\cos\\theta$ and outside\n$r=1$.\n\\begin{sol}\n $\\ds \\pi/3+\\sqrt3/2$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the area inside $r=2\\sin\\theta$ and above\nthe line $r=(3/2)\\csc\\theta$.\n\\begin{sol}\n $\\ds \\pi/3-\\sqrt3/4$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the area inside $r=\\theta$, $0\\le\\theta\\le2\\pi$.\n\\begin{sol}\n $\\ds 4\\pi^3/3$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the area inside $\\ds r=\\sqrt{\\theta}$, $0\\le\\theta\\le2\\pi$.\n\\begin{sol}\n $\\ds \\pi^2$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the area inside both $\\ds r=\\sqrt3\\cos\\theta$ and\n$r=\\sin\\theta$.\n\\begin{sol}\n $\\ds 5\\pi/24-\\sqrt3/4$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the area inside both $r=1-\\cos\\theta$\nand $r=\\cos\\theta$.\n\\begin{sol}\n $\\ds 7\\pi/12-\\sqrt3$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n The center of a circle of radius 1 is on the \ncircumference of a circle of radius 2. Find the area \nof the region inside both circles.\n\\begin{sol}\n $\\ds 4\\pi-\\sqrt{15}/2-7\\arccos(1/4)$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the shaded area in figure~\\ref{fig:area inside spiral}. \nThe curve is $r=\\theta$, $0\\le\\theta\\le3\\pi$.\n\\begin{sol}\n $\\ds 3\\pi^3$\n\\end{sol}\n\\end{ex}\n\n\n%\\figure[!ht]\n%\\centerline{\n%\\hbox to \\hsize{\\hfill\n%\\tikzpicture[domain=-2:2,x=4mm,y=4mm]\n%\\draw[->] (-10,0) -- (7,0) ;\n%\\draw[->] (0,-5.2) -- (0,8.5) ;\n%\\gpad\n%\\draw[color=black] plot[parametric,id=\\the\\gpnum,domain=0:3*pi,samples=100] \n%function{(t)*cos(t),(t)*sin(t)};\n%\\gpad\n%\\fill[opacity=0.5,fill=red!20] (0,0) -- (2*pi,0)\n%plot[parametric,id=\\the\\gpnum,domain=2*pi:3*pi]\n%function{(t)*cos(t),(t)*sin(t)} node {\\gpad} -- (-pi,0)\n%plot[parametric,id=\\the\\gpnum,domain=0:pi] \n%function{(pi-t)*cos(pi-t),(pi-t)*sin(pi-t)}; \n%\\endtikzpicture\n%\\hfill}}\n%\\caption{{An area bounded by the spiral of Archimedes.} \\label{fig:area inside spiral}}\n%\\endfigure\n\\figure[H]\n\\[\n\\includegraphics[width=2.75in]{images/7-arch} \n\\] \n\\caption{{An area bounded by the spiral of Archimedes.} \\label{fig:area inside spiral}}\n\\endfigure\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "2d850f9205b7da1cbd7e0a77a67178a66d9351e5", "size": 11868, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11-polar-coord-parametric-eq/11-3-areas.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "11-polar-coord-parametric-eq/11-3-areas.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "11-polar-coord-parametric-eq/11-3-areas.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5223880597, "max_line_length": 467, "alphanum_fraction": 0.6606841928, "num_tokens": 4592, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835330070839, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7067709811106091}}
{"text": "\n\\subsection{The Expectation-Maximisation algorithm}\n\n\\subsubsection{Expectation-Maximisation algorithm}\n\nThis is used to learn the parameters for a Gaussian Mixture Model\n\nWe cannot simply maximise the likelihood function, because this cannot be specified for a latent model.\n\nThe log likelihood function normally is:\n\n\\(L(\\theta ; X)=p(X|\\theta )\\)\n\nWith hidden variables it is:\n\n\\(L(\\theta ; X, Z)=p(X|\\theta )=\\int p(X, Z|\\theta)dZ\\)\n\n\\subsubsection{1: Expectation step}\n\nWe consider the expected log likelihood. We call this \n\n\\(E[\\log L(\\theta ; X, Z)]\\)\n\n\\subsubsection{2: Maximisation step}\n\n\n", "meta": {"hexsha": "0bed582da5a5de441d7908cd1774aef0599c83ee", "size": 601, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/latent/03-01-GMMEM.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/latent/03-01-GMMEM.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/latent/03-01-GMMEM.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2592592593, "max_line_length": 103, "alphanum_fraction": 0.7387687188, "num_tokens": 156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7066656381746186}}
{"text": "\\section{Motivation of Group}\r\nGroups are the mathematical notion of symmetries.\r\nIndeed, if we go further into this topic, we will find that the symmetries of anything give a group, and any group is actually the symmetry of something.\r\nThen why study symmetries in this way?\r\nWhy do we not just desribing the symmetries one by one instead?\\\\\r\nConsider a tetrahedron.\r\nThere are $12$ rotational symmetries of it: $1$ doing nothing, $8$ rotations on an axis joining one of the vertices and the centre of the tetrahedron, and $3$ rotations on the axis joining the midpoints of opposite sides.\r\nThe interesting thing is, if you composite two of the rotations that are listed above, you get another rotation.\r\nFor example, if we label the vertices as $1,2,3,4$, then one of the rotations on the axis passing though vertex $1$ may send the vertices like\r\n$$1\\to 1, 2\\to 4, 3\\to 2, 4\\to 3$$\r\nand the rotation on the axis joining midpoints of opposite segments would permute them by\r\n$$1\\to 3, 2\\to 4, 3\\to 1, 4\\to 2$$\r\nWe let $R$ be the former rotation and $S$ be the latter, then we could find $S\\circ R$, the rotation given by doing $R$ first then $S$ next.\r\nIndeed, this is the permutation\r\n$$1\\to 3, 2\\to 2, 3\\to 4, 4\\to 1$$\r\nwhich is one of the rotations on the axis passing though $2$.\r\nHere is an interesting thing: we can do $R\\circ S$ as well, but it is, as one can check, a rotation on the axis passing though $4$!\r\nSo $RS\\neq SR$, as in the order of the composition of two rotations matters.\r\nThis is kind of the point of group theory.\\\\\r\nNow we can look at the rotational symmetries of another soli: an isocagonal cone.\r\nThis time it is quite obvious: the rotational symmetries are precisely the rotations on the central axis of degree $n\\pi/6$ where $n=0,1,2,\\ldots, 11$.\r\nNow this set of rotations has order $12$ as well.\r\nBut are the two sets of rotational symmetries, one on a tetrahedron and another on a isocagonal cone, the same?\r\nNo, our intuition said. But why?\r\n\\begin{proposition}\r\n    The groups of rotational symmetries of a tetrahedron and a isocagonal cone are different.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Note that every rotation in the tetrahedron group is the same as doing nothing after repeating itself 2 or 3 (so, 6) times. \r\n    But the rotation of $\\pi/6$ degrees of the isocagonal cone does not have this property.\r\n    Therefore the two groups are different.\r\n\\end{proof}\r\nThere is another way of doing it,\r\n\\begin{proof}[Alternative proof]\r\n    In our previous example, we have found two rotations $S$ $R$ such that they do not commute, i.e. $RS\\neq SR$.\r\n    However, every two rotations in the isocagonal cone group commmutes.\r\n    Therefore they are different.\r\n\\end{proof}\r\nNote that in the second proof, there is an important property of groups that was used: commutativity.\r\nThis notion, expressed in several contexts, is essential to group theory.\r\nBut to see that, you have to dive into the world of groups.\r\n", "meta": {"hexsha": "5abcc2a95fb12f6321c6c38287ce3fe1d0fcbcb5", "size": 2954, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "0/mot.tex", "max_stars_repo_name": "david-bai-notes/IA-Groups", "max_stars_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "0/mot.tex", "max_issues_repo_name": "david-bai-notes/IA-Groups", "max_issues_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "0/mot.tex", "max_forks_repo_name": "david-bai-notes/IA-Groups", "max_forks_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 70.3333333333, "max_line_length": 222, "alphanum_fraction": 0.7450914015, "num_tokens": 803, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907933, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7066324009105109}}
{"text": "% !TEX root = main.tex\n\n%------------------------------------------------\n\\chapter{Conservative Equations}\n\\begin{definition}\nA conservative equation is an equation of the form $$\\frac{d^2x}{dt^2} +V'(x) = 0.$$\n\\end{definition}\n\\begin{remark}\nThis means that we can consider any equation $$\\frac{d^2x}{dt^2} + F(x) = 0$$ in which we can find an indefinite integral of $F.$\n\\end{remark}\n\\subsection*{Trick for Conservative Equation}\nMultiply the equation by $\\frac{dx}{dt}$ to obtain $$\\frac{dx}{dt}\\frac{d^2x}{dt^2}+V'(x)\\frac{dx}{dt} = 0$$ or by the chain rule, $$\\frac{d}{dt}\\bigg[\\frac{1}{2}\\bigg(\\frac{dx}{dt}\\bigg)^2+V(x)\\bigg] = 0.$$ Hence $$\\frac{1}{2}\\bigg(\\frac{dx}{dt}\\bigg)^2+V(x) = E$$ where $E$ is a constant. We could rearrange this as $$\\frac{dx}{dt} = \\pm \\sqrt[]{2E-2V(x)}.$$ This is an infinite family  (parametrized by E) of separable first order equations. Unfortunately this usually does not help.\n\\begin{example}\nConsider a pendulum of length $l$ with all the concentrated at the end. The equation governing the motion of the pendulum is $$\\frac{d^2\\theta}{dt^2} +\\frac{g}{l}\\sin(\\theta) = 0$$ where $g$ is the acceleration due to gravity. Prove that there exisits $T>0$ such that $\\theta (t+T) = \\theta(t)$ for all $t.$ The least such $T$ is called the period of $\\theta.$ So $$V'(\\theta) = \\frac{g}{l}\\sin(\\theta)$$ and without loss of generality we take $$V(\\theta) = \\frac{-g}{l}\\cos(\\theta)$$ and the energy conservation equation becomes $$\\frac{1}{2}\\bigg(\\frac{dx}{dt}\\bigg)^2- \\frac{g}{l}\\cos(\\theta) = E.$$ In the special case where $E = \\frac{g}{l}$ we get $$\\frac{1}{2}\\bigg(\\frac{dx}{dt}\\bigg)^2 = \\frac{g}{l}(1+\\cos(\\theta) = \\frac{2g}{l}\\cos^2\\bigg(\\frac{\\theta}{2}\\bigg).$$ However this is the only cases where an explicit solution is possible. For the other cases we shall plot the curves in $\\mathbb{R}^2$ given by $t \\mapsto(\\theta(t), \\frac{d\\theta}{dt}).$\n\\end{example}\n\\begin{definition}\nConsider a conservative equation $$\\frac{d^2x}{dt^2} + V'(x) = 0.$$ The phase diagram for this equation is the set of parametric curves $$t \\rightarrow(x(t),x'(t))$$ where $x$ solves the differential equation.\n\\end{definition}\n\\begin{example} [Linearized Pendulum]\nFrom the previous example $$\\frac{d^2x}{dt^2}+\\frac{g}{l}x = 0$$ has an auxiliary quadratic $$\\lambda^2 + \\frac{g}{l} = 0$$ with roots $$\\lambda = \\pm i \\omega, \\hspace{15pt} \\omega = \\sqrt[]{\\frac{g}{l}}.$$ The general solution is $x(t) = A\\sin(\\omega t) + B\\cos(\\omega t)$ where $A$, $B$ are constants. We can also write this as $x(t) = R\\cos(\\omega t - \\delta).$ Then $$R\\cos(\\omega t - \\delta) = R\\cos(\\omega t )\\cos(\\delta)+R\\sin(\\omega t)sin(\\delta)$$ and thus $$R\\cos(\\delta) = B, \\hspace{15pt} R\\sin(\\delta) = A.$$ Hence $$x'(t) = -\\omega R \\sin(\\omega t -\\delta)$$ and so $$(x(t),x'(t) = (R\\cos(\\omega t - \\delta), -\\omega R\\sin(\\omega t -delta)).$$ These are ellipses because $$\\bigg(\\frac{x(t)}{R}\\bigg)^2+\\bigg(\\frac{x'(t)}{\\omega R}\\bigg)^2 = 1$$ The fact that the solutions are periodic is revealed by the fact that the curves in the phase diagram are closed.\n\\end{example}\n\\begin{example}[Pendulum Phase Diagram]\nFor the lineraized pendulum $$\\frac{d^2x}{dt^2}+\\frac{g}{l}x=0.$$ We have $$V'(x)=\\frac{g}{l}x = \\omega^2x.$$ We can take $$V(x) = \\frac{1}{2}\\omega^2x^2$$ and the energy conservation equation is $$\\frac{1}{2}(x'(t))^2+V(x) = E$$ where $E$ is a constant i.e $$\\frac{1}{2}\\omega ^\"(x(t))^2+\\frac{1}{2}(x'(t))^2 = E.$$ Then by multiplying with 2 and dividing by $2E$ to get $$\\bigg(\\frac{x(t)\\omega}{\\sqrt[]{2E}}\\bigg)^2+\\bigg(\\frac{x'(t)}{\\sqrt[]{2E}}\\bigg)^2 = 1$$ which is the same as the previous example with $$R =\\frac{\\sqrt[]{2E}}{\\omega}.$$ For the full pendulum equation $$V'(x) = \\frac{g}{l}\\sin(x) = \\omega^2\\sin(x)$$ and we take $$V(x) = \\omega^2 - \\omega^2 \\cos(x).$$ The phase curves are $$\\frac{1}{2}(x'(t))^2+\\omega^2(1-\\cos(x))=E.$$\n We want to plot the curves, and we already have the case $$V(x) = \\frac{1}{2}x^2$$ or generally $$V(x) = kx^2 \\hspace{25pt} k>0$$ when the phase curves are ellipses. In both of these examples, $V(x)  \\geq 0$ everywhere so we need $E\\leq 0$. When $E=0$ we need both $y=0$ and $v(x) = 0$. For the case $V(x) = \\frac{g}{l}(1-\\cos(x))$ this gives the points $(2n\\pi,0), n\\in \\mathbb{Z}.$ For the case $V(x) = kx^2$ we just get (0,0) when $E>0$ is small. Thus we draw a line at height $E$ across the graph $V(x).$ \n \\smallskip\n For the pendulum equation when $E\\geq \\frac{2g}{l}$ then $E\\geq V(x)$ for all $x$. \n \n \\bigskip \n \n Suppose we now wish to approximate the phase curves, either for the pendulum equation or any other, in a small neighborhood of a point $(x_0,0)$ at which $V$ has a local maximum e.g $x_0 = \\pi$ for the pendulum equation with $V(x) = \\frac{g}{l}(1-\\cos(x))$. We use the Taylor expansion $$V(x) = V(x_0) +(x-x_0)+V'(x_0)+\\frac{1}{2!}(x-x_0)^2V''(x_0)+....$$ Since $V$ has a local maximum at $x_0$ $$V'(x_0) = 0$$ $$V''(x_0) \\leq 0.$$ Assume $V''(x_0) <0$ and so the energy conservation equation is $$E=\\frac{1}{2}(x')^2+V(x) = \\frac{1}{2}(x')^2+V(x_0) + \\frac{1}{2|}(x-x_0)^2V''(x_0) +.....$$ $$\\approx \\frac{1}{2}(x')^2-\\frac{1}{2}\\omega^2(x-x_0)^2$$ where $\\omega^2 = -V''(x_0)>0.$ The curves $\\frac{1}{2}y^2-\\frac{1}{2}\\omega^2(x-x_0)^2 = E$ are hyperbola.\n\\end{example}\n\\begin{example}\nDraw the phase diagram for the equation $$\\frac{d^2x}{dt^2}+2x-3x^2 = 0$$ show that there exists periodic solutions and obtain an integral expression for their periods.\n\\begin{solution}\nHere $V'(x) = 2x-3x^2$ so $V(x) = x^2-x^3$ is a suitable choice for $v$. The energy equation is $$\\frac{1}{2}(x')^2+x^2+x^3 = E$$ \n\\end{solution}\n\\end{example}\n\\subsection*{Integral Expression for the Period of a Periodic Solution}\nObserve that since $\\frac{1}{2}(x')^2+V(x)$ is a constant and since $x'=0$ when $x=\\alpha$ and $x=\\beta$ we have $$V(\\alpha)=v(\\beta).$$ The period of the solution is the time it takes from $\\alpha$ to $\\beta$ plus the time to return. By symmetry these times are equal so the period is twice the transit from $\\alpha$ to $\\beta.$ Thus the period is $$T= \\int_0^T dt = 2\\int_\\alpha^\\beta\\frac{dt}{dx}dx = 2\\int_\\alpha^\\beta \\frac{dx}{x'}$$ Now $$\\frac{1}{2}(x')^2 +V(x) = V(\\alpha)=v(\\beta)$$ giving $$x' = \\pm \\sqrt[]{2(V(\\beta)-V(x))}.$$ From $\\alpha$ to $\\beta$, $x$ increases so $$x' = \\sqrt[]{2(V(\\beta)-V(x))}.$$ Thus $$T = \\sqrt[]{2}\\int_\\alpha^\\beta\\frac{dx}{\\sqrt[]{V(\\beta)-V(x)}}.$$\n\n\n%------------------------------------------------\n\\endinput\n", "meta": {"hexsha": "0ff7850deb1df23982e55b9fa49d753f0c08ad82", "size": 6457, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L4/MA1001/Conservative_Equations.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L4/MA1001/Conservative_Equations.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L4/MA1001/Conservative_Equations.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 146.75, "max_line_length": 962, "alphanum_fraction": 0.6281554902, "num_tokens": 2369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619634, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7066323972462587}}
{"text": "\\section{Introduction}\n\nIn this lab, our goal is to study the phenomenon of simple harmonic oscillation,\nfind the spring constant and effective mass of a spring,\nand how to use the air track. We will analyze the relationship between the\noscillation period and the mass of the oscillator, check whether the oscillation\nperiod depends on the the amplitude, and examine the relationship between the\nmaximum speed and the amplitude. \n\nThere are various kinds of periodic motion in nature, among which the simplest\nand the most fundamental one is the simple harmonic motion, where the restoring\nforce is proportional to the displacement from the equilibrium position and as a\nresult, the position of a particle depends on time as the sine (or cosine)\nfunction. Discussion of the simple harmonic motion is a basis for studying more\ncomplex situations. \n\n\\subsubsection{Hooke's Law}\nWithin the elastic limit of deformation, the force Fx needed to be applied in\norder to stretch or compress a spring by the distance x is proportional to that\ndistance, i.e.\n\n\\begin{equation}\n\\label{hookeslaw}\nF_x=kx,\n\\end{equation}\n\nwhere $k$ is a the spring constant that characterizing how easy it is to deform a\nspring.\nThis constant will be found in the present exercise using a measurement device\ncalled the Jolly balance. \nThe linear relation  between the force and the deformation, is known as the\nHooke’s Law.\nAccording to Newton's third law of dynamics, the spring exerts a reaction force\n(called the elastic force) of the same magnitude but opposite direction. \n\n\\subsection{Equation of Motion of the Simple Harmonic Oscillator}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=12cm]{fig/i1}\n\\caption{Mass-spring system}\n\\label{mss}\n\\end{figure}\n\nAs shown in Figure~\\ref{mss}, the mass with two springs is placed on an\nair track, which aims at eliminating the frictional forces. Assuming that the\nrestoring force is the only force acting on mass M, the equation of motion od\nmass M is \n\n\\begin{equation}\n\\label{M1}\nM\\frac{d^2x}{dt^2}+(k_1+k_2)x=0.\n\\end{equation}\n\nHence the general solution to Eq. \\ref{M1} is\n\n\\begin{equation}\nx(t)=Acos(\\omega_0t+\\phi_0),\n\\end{equation}\n\nwhere $\\omega_0=\\sqrt{(k_1+k_2)/M}$ is the natural angular frequency of the\noscillations (determined by the parameters of the system), A is the amplitude,\nand $\\phi_0$ is the initial phase (determined by initial conditions). The\nnatural period of oscillation is \n\n\\begin{equation}\nT=\\frac{2\\pi}{\\omega_0}=2\\pi\\sqrt{\\frac{M}{k_1+k_2}}.\n\\end{equation}\n    \nIn this exercise, the relationship mentioned above will be studied.\n    \n\\subsection{Mass of the Spring}\n\nWe take into the mass of the springs in terms of the so-called\neffective mass, which is the sum of the mass of the object $M$ and\nthe effective mass of springs $m_0$.\nThe angular frequency can be expressed as\n\n\\begin{equation}\n  \\label{omega1}\n\\omega_0=\\sqrt{\\frac{k_1+k_2}{M+m_0}}\n\\end{equation}\n\nwhere $m_0$ is 1/3 of the actual mass of the spring.\n\n\\subsection{Mechanical Energy in Harmonic Motion}\n\nThe elastic potential energy for a spring-mass system is $U=kx^2/2$ and the\nkinetic energy of an oscillating mass is $K=mv^2/2$.\nAt the equilibrium position ($x=0$), the speed of the mass is maximum\n$v=v_{\\max}$. \nAt this point the total mechanical energy is equal to maximum kinetic energy\n$K_{\\max}$ . \nOn the other hand, at maximum displacement ($x=\\pm A$) the mass is\ninstantaneously at rest, and the contribution to the total mechanical energy is\ndue to the potential energy only, which is at its maximum $U_{\\max}$. \nIn the absence of non-conservative forces (such as frictional forces or drag\nforces), the total mechanical energy is conserved and $K_{\\max}=U_{\\max}$, which\nimplies  \n\n\\begin{equation}\nk=\\frac{m (v_{max})^2}{A^2}\n\\label{kmv2_A2}\n\\end{equation}\n\n", "meta": {"hexsha": "f3d7ab7743c9b81c880b43b1635120cffe38c567", "size": 3795, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "E3/part/1i.tex", "max_stars_repo_name": "iamwrm/VP141", "max_stars_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-24T11:28:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T11:28:04.000Z", "max_issues_repo_path": "E3/part/1i.tex", "max_issues_repo_name": "iamwrm/VP141", "max_issues_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "E3/part/1i.tex", "max_forks_repo_name": "iamwrm/VP141", "max_forks_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.1428571429, "max_line_length": 81, "alphanum_fraction": 0.7683794466, "num_tokens": 1016, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245911726382, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7066323807752444}}
{"text": "\\subsection*{Models}\n\\label{sec:methods_models}\n\nWe modeled the data by considering only the carbon chain length of the molecules composing each stimulus.  \nThe computation of the animal's response probability to each test stimulus was given by first computing: \n\\begin{equation}\nf(S+_i,test_j) = f_1(S+_i) * f_2(S+_i,test_j)\n\\end{equation}\nwith each function argument the carbon chain length of an $S+$ component $i$ or a test stimulus component $j$, where:\n\\begin{equation}\nf_1(x_i) = exp(-a*x_i) \\\\\nf_2(x_i,x_j) = exp(-b*|x_i-x_j|)\n\\end{equation}\nwith $a$ and $b$ free parameters, obtained by maximum likelihood estimation (see below).  \n$f_1$ represents the salience of an $S+$ component, and the functional form of $f_1$ is inspired by the vapor pressure dependence of carbon chain length, which is one component of perceived intensity.  $f_2$ represents the generalization gradient across carbon chain length.  \n\nWe then considered 3 classes of models, varying in computational complexity, i.e. the number of computations of $f$ across stimulus components.  \n\\begin{itemize}\n\\item \\textit{Scalar}: Each stimulus was represented by the mean carbon chain length of its components.  The probability of response ($p_r$) was a function of the difference between the mean carbon chain length of the $S+$ and that of the test stimulus, i.e.:\n\\begin{equation}\np_r = p_{r0} * f(S+_{mean},test_{mean})\n\\end{equation}\n\\item \\textit{All-to-All}: Each stimulus was represented by an array of length N containing the carbon chain lengths of the components, e.g. an array of length 2 for a binary mixture. $p_r$ was a function of the difference between each element of the $S+$ array and each element of the test stimulus array, i.e. the difference in carbon chain lengths between each $S+$ component and each test stimulus component.  \n\\begin{equation}\np_r = p_{r0} * \\frac{1}{N^2}\\sum_{i=1}^{N}\\sum_{j=1}^{N}f(S+_i,test_j)\n\\end{equation}\n\\item \\textit{Nearest Neighbor}: Each stimulus was represented as in \\textit{All-to-All}, but $p_r$ was a function only of the difference between each element $i$ of the $S+$ array and the single nearest (most similar in carbon chain length) element of the test stimulus array, with index $i'$.  \n\\begin{equation}\np_r = p_{r0} * \\frac{1}{N}\\sum_{i=1}^{N}f(S+_i,test_{i'})\n\\end{equation}\n\\end{itemize}\n\nEach model was fit to the pooled data, expressed as response probabilities for each test stimulus in each experiment, using maximum likelihood estimation to obtain the parameters $a$, $b$, and $p_{r0}$, which applied universally to all experiments.  In an alternative fit, we allows $p_{r0}$ to vary according to the experiment type (although it was still fixed for all animals, strains, and stimuli within each experiment), to account for variable baseline response motivation across experiments.  Goodness-of-fit is reported as the mean-squared error between the model fit and the observed response probabilities, and is fundamentally bounded at the low end due to binomial variability.  \n\nAll code and analysis is available at \\url{http://github.com/quolf/nearest-neighbor}.  ", "meta": {"hexsha": "31abe74fc0ecbf8a13c1082ded9a449da998e547", "size": 3112, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Methods:Models.tex", "max_stars_repo_name": "quolf/nearest-neighbor", "max_stars_repo_head_hexsha": "3629ec9f8cded836f20d0e216f3cbb89dd0b49f6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Methods:Models.tex", "max_issues_repo_name": "quolf/nearest-neighbor", "max_issues_repo_head_hexsha": "3629ec9f8cded836f20d0e216f3cbb89dd0b49f6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Methods:Models.tex", "max_forks_repo_name": "quolf/nearest-neighbor", "max_forks_repo_head_hexsha": "3629ec9f8cded836f20d0e216f3cbb89dd0b49f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 88.9142857143, "max_line_length": 690, "alphanum_fraction": 0.7606041131, "num_tokens": 805, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.7066078762869326}}
{"text": "\\documentclass[../research.tex]{subfile}\n\n\\subsection{Sequences}\n\\label{sec:1.1}\n\n  We denote set of positive integers as $\\N$.\n\n  \\begin{prop}\n    Let $a_i = (a_i^1,\\dots,a_i^n)\\in\\R^n$ be a sequence,  $\\forall n\\in\\N$. Then \n    $a_i\\to a:=(a^1,\\dots,a^n)\\in\\R^n$, as $i\\to\\infty$ iff $a_i^k\\to a^k$ as $i\\to\\infty$, \n    $\\forall k\\in\\{1,\\dots,n\\}$.\n  \\end{prop}\n\n  \\begin{proof}\n    We know that \n    $$\\max_{k=1,\\dots,n}{|a^k|}\\leq\\|a\\|\\leq\\sqrt{n}\\max_{k=1,\\dots,n}{|a^k|}.$$\n\n    To show this, observe that:\n    $$\\sqrt{\\max_k{((a^k)}^2)}\\leq\\sqrt{(a^1)^2+\\dots+(a^n)^2}\\leq\\sqrt{n\\max_k{((a^k)^2})}$$\n    $$\\Rightarrow \\sqrt{(\\max_k{|a^k|})^2}\\leq\\|x\\|\\leq\\sqrt{n(\\max_k{|a^k|})^2}$$\n    $$\\Rightarrow \\max_k{|a^k|}\\leq\\|x\\|\\leq\\sqrt{n}\\max_k{|a^k|}$$\n    \n    First assume that $a_i\\to a$ as $i\\to\\infty$. Then $\\forall\\epsilon>0$ $\\exists N\\in\\N$ such \n    that $\\|a_i-a\\|<\\epsilon$ whenever $i\\geq N$.\n\n    Then $\\forall k=1\\dots n$, $|a^k_i-a^k|\\leq\\max_k{|a^k_i-a^k|}\\leq\\|a_i-a\\|<\\epsilon$ whenever \n    $i\\geq N$, so $a^k_i\\to a^k$ as $i\\to\\infty$.\n\n    Conversely, assume that $a_i^k\\to a^k$ as $i\\to\\infty$, $\\forall k\\in\\{1,\\dots,n\\}$.\n    Then $\\forall\\epsilon>0$, $\\exists N^k\\in\\N$ such that $|a_i^k-a^k|\\leq\\frac{\\epsilon}{\\sqrt{n}}$ \n    whenever $i\\geq N^k$, $\\forall k=1,\\dots,n$. Let \n    $$N=\\max_{k=1,\\dots,n}{N^k}.$$\n\n    Then $\\max_k{|a^k_i-a^k|}<\\frac{\\epsilon}{\\sqrt{n}}$ whenever $i\\geq N$, so \n    $\\|a_i-a\\|\\leq\\sqrt{n}\\max_k{|a^k_i-a^k|}<\\epsilon$.\n  \\end{proof}\n\n  \\begin{prop}\n    The limit of a sequence in $\\R^n$ is unique.\n  \\end{prop}\n\n  \\begin{proof}\n    Let $(x_i)_{i\\in\\N}$ be a sequence with $x_i\\in\\R^n$. \n    Suppose for a contradiction that $x_i\\to a$ and $x_i\\to b$ as $i\\to\\infty$, with $a\\neq b$.\n\n    Then $\\forall\\epsilon>0$, $\\exists N_a,N_b\\in\\N$ such that $\\|x_i-a\\|<\\frac{\\epsilon}{2}$ whenever \n    $i\\geq N_a$, and $\\|x_i-b\\|<\\frac{\\epsilon}{2}$ whenever $i\\geq N_b$. Let\n    $$N=\\max{\\{N_a,N_b\\}}.$$\n    Then whenever $i\\geq N$, we have:\n    \\begin{align*}\n    \\|a-b\\|&=\\|a-x_i+x_i-b\\|\\\\\n           &\\leq\\|a-x_i\\|+\\|x_i-b\\|\\\\\n           &<\\frac{\\epsilon}{2}+\\frac{\\epsilon}{2}=\\epsilon,\n    \\end{align*}\n    And since $\\epsilon$ can be made arbitrarily small, we find that $a=b$, which is a contradiction.\n  \\end{proof}\n\n  \\begin{theorem}[Monotone convergence]\n    An increasing and bounded above sequence is convergent. Likewise, a decreasing and bounded below \n    sequence is convergent.\n  \\end{theorem}\n\n  \\begin{proof}\n    Suppose $(a_i)$ is bounded above and increasing. Then the set $A=\\{a_i:i\\in\\N\\}$ has a supremum, \n    say $a=\\sup{A}$. I claim that $a_i\\to a$ as $i\\to\\infty$. \\\\\n\n    \\textit{Proof of claim.}\n      Fix $\\eps$. Then $\\exists a_N$, with $N\\in\\N$ such that \n      $$a-\\epsilon<a_N\\leq a<a+\\epsilon.$$\n      Since $(a_i)$ is increasing, $a_i\\geq a_N$ when $i\\geq N$, and since it is also bounded above \n      by $a$, we have \n      $$a-\\epsilon<a_N\\leq a\\leq a_i<a+\\epsilon,$$\n      and so \n      $$|a-a_i|<\\epsilon.$$\n    So $a_i\\to a$ as $i\\to\\infty$. Simililary, we can show that if $(a_i)$ is bounded below and \n    decreasing, $a_i\\to \\inf{\\{a_i:i\\in\\N\\}}$ as $i\\to\\infty$.\n  \\end{proof}\n\n  \\begin{lemma}\n    Let $(a_n)_{n\\in\\N}$ be a bounded sequence of real numbers. Then $(a_n)_{n\\in\\N}$ has a convergent \n    subsequence.\n  \\end{lemma}\n%\n%  \\begin{proof}\n%    We say $x_i$ is a peak point of $(a_n)$ if $a_n\\leq x_i, \\forall n>i$.\\\\\n%\n%    Then either we have infinitely many peak points, or finitely many.\n%    In the first case, we have an infinite subsequence, $(x_{i_j})_{j\\in\\mathbb{N}}$, of peak points \n%    which is non-increasing, since $a_{i_n}\\leq x_{i_j}$ whenever $n>j$. Then since $(a_i)$ is \n%    bounded, so is $(x_{i_j})$, so it is convergent.\\\\\n%\n%    Now consider the case of finitely many peak points, say $x_1,\\dots x_k$. Choose \n%    $n_1>\\text{max}\\{1,\\dots,k\\}$. Since $a_{n_1}$ is not a peak point, $\\exists n_2 > n_1$ such \n%    that $a_{n_2}>a_{n_1}$. Since $a_{n_2}$ is not a peak point, $\\exists n_3 > n_2$ such that \n%    $a_{n_3}>a_{n_2}$. Continuing inductively, with $a_{n_i}>a_{n_{i-1}}$, we obtain a decreasing \n%    subsequence $(a_{n_j})_{j\\in\\N}$. Then since $(a_{n_j})_{j\\in\\N}$ is bounded, it converges.\n%  \\end{proof}\n%\n%  We now present another proof.\n%\n  \\begin{proof}\n    Since $(a_i)$ is bounded, $\\exists K\\geq0$ such that $a_i\\in I_0:=[-K,K]\\,\\forall i\\in\\N$.\n    Then one of $[-K,0]$, $[0,K]$ contains infinitely many elements of $(a_i)$. Choose the \n    leftmost one, and call it $I_1$. Repeat this inductively, such that $I_j:=[c_j,d_j]$ \n    contains infinitely many elements of $(a_i)$. We then inductively define \n    $$i_j=\\min_{i>i_{j-1}}{i:a_i\\in I_j}.$$\n    In other words, $a_{i_j}$ is the first element of $(a_i)$ which lies in $I_j$. Now, since \n    $$I_j\\subset I_{j-1}\\subset\\dots\\subset I_1\\subset I_0,$$\n    The sequences $(c_j)$ and $(d_j)$ are monotically increasing and decreasing, respectively, \n    and since they are bounded, they both converge, so say that \n    $$c_j\\to c\\in[-K,K]\\text{ as }j\\to\\infty,$$\n    $$d_j\\to d\\in[-K,K]\\text{ as }j\\to\\infty.$$\n    Since $d_j-c_j=\\text{length}(I_j)=2^{1-j}K\\to0$ as $j\\to\\infty$, we have that $c=d$, and \n    since $c_j\\leq a_{i_j}\\leq d_j$, we also have that $a_{i_j}\\to c=d$ as $j\\to\\infty$.   \n  \\end{proof}\n\n  \\begin{cor}\n    Let $(a_i)_{i\\in\\N}$ be a bounded sequence in $\\R^n$. Then $(a_i)$ has a \n    convergent subsequence.\n  \\end{cor}\n  \\begin{proof}\n    Since $(a_i)$ is bounded, and the component sequences $(a_i^k)$ are bounded $\\forall k=1,\\dots,n$.\n\n    Then by the previous lemma, $(a_i^1),\\dots,(a_i^n)$ have subsequences $(a_{i_{j_1}}^1), \\dots, \n    (a_{i_{j_n}}^n)$ converging to $a^1,\\dots,a^n$ respectively. Let \n    \\begin{align*}\n      J_1&=\\{j_{1_1},j_{1_2},\\dots\\},\\\\\n      J_2&=\\{j_{2_1},j_{2_2},\\dots\\},\\\\\n         &\\vdots \\\\\n      J_n&=\\{j_{n_1},j_{n_2},\\dots\\},\n    \\end{align*}\n    and $J=J_1\\cap\\dots\\cap J_n$.\\\\\n\n    Then each component subsequence $(a_j^k)_{j\\in J}$ converges to $a^k$, so $(a_j)_{j\\in J}$ \n    converges to $a$.\n  \\end{proof}\n\n  \\begin{theorem}[Bolzano-Weierstrass]\n    Let $E\\subset\\R^n$ be compact and $(a_i)_{i\\in\\N}$ a sequence in $E$. Then $(a_i)$ has a \n    subsequence converging to a point in $E$.\n  \\end{theorem}\n\n  \\begin{proof}\n    Since $(a_i)$ is bounded, it has a subsequence $(a_{i_j})\\to a$ as $j\\to\\infty$.\n\n    And since $E$ is closed, and $a$ a limit point of $E$, $a\\in E$.\n  \\end{proof}\n\n\\subsection{Continuous Functions}\n\\label{sec:1.2}\n\n  \\begin{definition}[Continuity]\n    Let $A\\subset\\R^n$ be open. We say $f:A\\to\\R^m$ is \\textit{continuous} on $A$ if, \n    $\\forall a\\in A$, $\\forall\\epsilon>0$ $\\exists\\delta>0$ such that \n    $\\|f(x)-f(a)\\|<\\epsilon$, whenever $\\|x-a\\|<\\delta$.\n  \\end{definition}\n\n  Generally, we can think of continuous functions are those for which points that are `near' are mapped to \n  by points that are also `near', and so showing that a function is continuous amounts to finding a positive\n  relationship between the definition of `nearness' in the domain and the definition of `nearness' in \n  the range (these are not generally the same). In this \n  case, points $x,y\\in\\R^n$ are near if the distance between them, $\\|x-y\\|$, is small.\n  \n  In a more general topological sense, we say that two points are near, in a certain capacity, \n  if they are both elements of the same open set. Thus, very vaguely, the more open sets the points \n  are both elements of, the nearer they are. In Euclidean space, open sets are defined as arbitary \n  unions of open balls $B_\\epsilon(x)$, for $x\\in\\R^n$ and $\\epsilon>0$. Thus, $x=y$ precisely when \n  $y\\in B_\\epsilon(x)$ (and $x\\in B_\\epsilon(y)$) $\\forall\\epsilon>0$. \n  \n  This is the Euclidean case of \n  a general property called non-seperatedness, which we use to describe \n  points that both lie in every open set. Since they share every open set in common, their nearness \n  is maximal, and so we can think of them as essentially being indistinguishable - i.e. the same point. \n  We will revist this later, when we discuss seperatedness conditions.\n\n  \\begin{prop}\n    For $f:A\\to\\R^m$, we write $f(x)=(f_1(x),\\dots,f_m(x))$.\n\n    Then $f$ is continuous if and only if each of the component functions \n    $f_i:A\\to\\R$ are continuous.\n  \\end{prop}\n\n  \\begin{proof}\n    First assume $f$ is continuous at $a\\in A$. Then $\\forall\\epsilon>0$ \n    $\\exists\\delta>0$ such that $\\|f(x)-f(a)\\|<\\epsilon$ whenever $\\|x-a\\|<\\delta$. Then \n    \\begin{align*}\n      |f_i(x)-f_i(a)|&\\leq\\max_i{|f_i(x)-f_i(a)|}\\\\\n                     &\\leq\\|f(x)-f(a)\\|\\\\\n                     &<\\epsilon\\quad\\forall i=1,\\dots,m.\n    \\end{align*}\n\n    Hence each $f_i$ is continuous at $a$. Now assume that each $f_i$ is continuous at $a\\in A$.\n\n    Then $\\forall\\epsilon>0$, $\\exists\\delta_i>0$ such that $|f_i(x)-f_i(a)|<\\frac{\\epsilon}{m\\sqrt{m}}$\n    whenever $\\|x-a\\|<\\delta_i$, $\\forall i=1,\\dots,m$. Now let $\\delta=\\min{\\{\\delta_1,\\dots,\\delta_m\\}}$\n\n    Then when $\\|x-a\\|<\\delta$, $\\|x-a\\|<\\delta_i$, so $|f_i(x)-f_i(a)|<\\frac{\\epsilon}{m\\sqrt{m}}$ \n    $\\forall i=1,\\dots,m$. Then\n    \\begin{align*}\n    \\|f_i(x)-f_i(a)\\|&\\leq\\sqrt{m}\\max_i{|f_i(x)-f_i(a)|}\\\\\n                     &\\leq\\sqrt{m}\\sum_{i=1}^m{|f_i(x)-f_i(a)|}\\\\\n                     &<\\epsilon\n    \\end{align*}    \n  \\end{proof}\n\n  \\begin{example}\n    Every linear function is continuous.\n  \\end{example}\n\n  \\begin{prop}\n    Let $A\\subset\\R^n$ be open. Then $f:A\\to\\R^m$ is continuous at $x\\in A$ if and only if \n    $f(x_i)\\to f(x)$ as $i\\to\\infty$ for any sequence $(x_i)$ converging to $x$.\n  \\end{prop}\n\n  \\begin{proof}\n    Let $(x_i)$ be a sequence in $A$ converging to $x\\in A$, and assume $f:A\\to\\R^m$ to be continuous \n    at $x$. Then $\\forall\\epsilon>0$, $\\exists\\delta>0$ such that $\\|f(x)-f(y)\\|<\\epsilon$ \n    whenever $0<\\|x-y\\|<\\delta$.\\\\\n\n    Since $x_i\\to x$, $\\nat$ such that $\\|x_i-x\\|<\\delta$ whenever $i\\geq N$, and hence $\\|f(x_i)-f(x)\\|<\\epsilon$, \n    so we have that $f(x_i)\\to f(x)$ as $i\\to\\infty$.\\\\\n\n    Now assume the converse holds, and for a contradiction that $f$ is not continuous. Then \n    $\\exists\\epsilon>0$ such that $\\forall\\delta>0$ $\\|f(x)-f(x_i)\\|\\geq\\epsilon$ whenever \n    $0<\\|x-x_i\\|<\\delta$, and in particular whenever $0<\\|x-x_i\\|<\\frac{1}{i}$, $\\forall i\\in\\N$.\n\n    Then the sequence $(x_i)$ converges to $x$, so by assumption the image sequence $(f(x_i))$ \n    converges to $f(x)$.\\\\\n\n    Thus $\\exists N\\in\\N$ such that $\\|f(x_i)-f(x)\\|<\\epsilon$ whenever $i\\geq N$, which is a \n    contradiction. Hence, $f$ is continuous at $x$.\n  \\end{proof}\n\n  \\begin{theorem}[Extreme Value Theorem]\n    Let $E\\subset\\R^n$ be compact and non-empty. Let $f:E\\to\\R$ be continuous.\n    Then $f$ achieves its maximum and minimum values on $E$.\n  \\end{theorem}\n\n  \\begin{proof}\n    We prove that $f$ reaches its maximum on $E$. First suppose for a contradiction that \n    $f$ is unbounded above on $E$. Then $\\forall M\\geq 0$, and in particular \n    $\\forall i\\in\\N$, $\\exists x_i\\in E$ such that $f(x_i)>i$. \n    In other words, $f(x_i)\\to\\infty$ as $i\\to\\infty$.\n\n    Then since $E$ is compact, it is bounded, so the sequence $(x_i)_{i\\in\\N}$ is bounded. \n    Then by the Bolzano-Weierstrass theorem it has a subsequence $(x_{i_j})_{j\\in\\N}$ convergent to $x\\in E$.\n\n    Now since $f$ is continuous on $E$, it is continuous at $x$, so $f(x_{i_j})\\to f(x)$ as $j\\to\\infty$.\n    Since $E$ is compact, it is closed, so $f(x)\\in E$, and therefore $f(x)$ is finite. This is a contraction since \n    $f$ was assumed to diverge to infinity for any subsequence of $(x_i)$, including $(x_{i_j})$.\n\n    So $f$ is bounded above on $E$. Now by completeness of $\\R$, $f(E)$ has a supremum, say \n    $$M=\\sup_{x\\in E}{f(x)}.$$ \n    We show that that $f$ reaches its maximum on $E$, i.e. that $M\\in f(E)$, or \n    that $\\exists p_+\\in E$ such that $f(p_+)=M$. Now $\\forall i\\in\\N$, $\\exists x_i\\in E$ such that \n    $$M-\\frac{1}{i}<f(x_i)\\leq M.$$\n    Then clearly $f(x_i)\\to M$ as $i\\to\\infty$, so by the Bolzano-Weierstrass theorem $(x_i)_{i\\in\\N}$ has \n    a subsequence $(x_{i_j})_{j\\in\\N}$ convergent in to some $p_+\\in E$. Since $f$ is continuous at $p_+$, \n    $f(x_{i_j})\\to f(p_+)$ as $j\\to\\infty$. Hence $f(p_+)=M$, so $f$ achieves its maximum on $E$.\n\n    Now in a similar fashion we prove that $f$ reaches its minimum on $E$. Suppose that \n    $f$ is unbounded below on $E$. Then $\\forall i\\in\\N$, $\\exists x_i\\in E$ such that $f(x_i)<-i$. \n    So $f(x_i)\\to-\\infty$ as $i\\to\\infty$.\n\n    Now, the sequence $(x_i)_{i\\in\\N}$ is bounded. Then by the Bolzano-Weierstrass theorem it has a \n    subsequence $(x_{i_j})_{j\\in\\N}$ convergent to $x\\in E$. Since $f$ is continuous at \n    $x$, $f(x_{i_j})\\to f(x)$ as $j\\to\\infty$, and so $f(x)\\in E$ (so $f(x)$ is finite). This is a contraction since \n    $f$ was assumed to diverge to negative infinity for any subsequence of $(x_i)$, including $(x_{i_j})$.\n\n    So $f$ is bounded below on $E$. Now by completeness of $\\R$, $f(E)$ has an infimum, say \n    $$m=\\inf_{x\\in E}{f(x)}.$$ \n    We show that that $f$ reaches its minimum on $E$, i.e. that $m\\in f(E)$, or \n    that $\\exists p_-\\in E$ such that $f(p_-)=m$. Now $\\forall i\\in\\N$, $\\exists x_i\\in E$ such that \n    $$m\\leq f(x_i)<m+\\frac{1}{i}.$$\n    Then clearly $f(x_i)\\to m$ as $i\\to\\infty$, so by the Bolzano-Weierstrass theorem $(x_i)_{i\\in\\N}$ has \n    a subsequence $(x_{i_j})_{j\\in\\N}$ convergent in to some $p_-\\in E$. Since $f$ is continuous at $p_-$, \n    $f(x_{i_j})\\to f(p_-)$ as $j\\to\\infty$. Hence $f(p_-)=m$, so $f$ achieves its minimum on $E$.\n  \\end{proof}\n\n\\subsection{Uniform Continuity and Convergence}\n\\label{sec:1.3}\n\n  \\begin{definition}[Uniformly Continuous]\n    Let $A\\subset\\R^n$ be open. We say $f:A\\to\\R^m$ is \\textit{uniformly continuous} on $A$ if, \n    $\\forall\\epsilon>0$ $\\exists\\delta>0$ such that $\\forall x,y\\in A$,\n    $\\|f(x)-f(y)\\|<\\epsilon$ whenever $\\|x-y\\|<\\delta$.\n  \\end{definition}\n\n  \\textbf{Remark:} Clearly uniform continuity implies continuity.\n\n  \\begin{prop}\n    Let $f:\\R\\to\\R$ be differentiable with bounded derivative. Then $f$ is uniformly continuous.\n  \\end{prop}\n\n  \\begin{proof}\n    Fix $\\eps$. Then $\\forall x,y\\in\\R$ with $x<y$, by the Mean Value Theorem \n    $\\exists c\\in(x,y)$ such that $f'(c)=\\frac{f(y)-f(x)}{y-x}$. By assumption \n    $\\exists M\\geq 0$ such that $|f'(c)|=\\frac{|f(y)-f(x)|}{|y-x|}\\leq M$.\n\n    Set $\\delta = \\frac{\\epsilon}{M+1}$. Then \n    \\begin{align*}\n      |f(y)-f(x)|&\\leq M|y-x|\\\\\n                 &<\\frac{M\\epsilon}{M+1}\\\\\n                 &<\\frac{M\\epsilon}{M}\\\\\n                 &=\\epsilon\n    \\end{align*}\n  \\end{proof}\n\n  \\begin{prop}\n    A continuous function on a compact subset $E\\subset\\R^n$ is uniformly continuous.\n  \\end{prop}\n\n  \\begin{proof}\n    Let $E\\subset\\R^n$ be compact, and $f:E\\to\\R^m$ continuous. We assume for a contradiction that \n    $f$ is not uniformly continuous. Then $\\exists\\epsilon>0$ such that $\\forall i\\in\\N$ \n    $\\exists x_i,y_i\\in E$ with $\\|x_i-y_i\\|<\\frac{1}{i}$ such that $\\|f(x_i)-f(y_i)\\|\\geq\\epsilon$.\n\n    Then by the Bolzano-Weierstrass theorem, the sequence $(x_i)_{i\\in\\N}$ has a\n    subsequences $(x_{i_j})_{j\\in\\N}$ converging to some $x\\in E$.  Furthermore, the sequence $(y_i)_{i\\in\\N}$ \n    has a convergent subsequence $(y_{i_j})_{j\\in\\N}$. We now show that $y_{i_j}\\to x$ as $j\\to\\infty$.\n\n    Choose $\\epsilon'>0$. Then $\\exists N\\in\\N$ such that $\\|x_{i_j}-x\\|<\\frac{\\epsilon'}{2}$ whenever $i_j\\geq N$.\n    \\begin{align*}\n    \\|x-y_{i_j}\\|&=\\|x-x_{i_j}+x_{i_j}-y_{i_j}\\|\\\\\n                 &\\leq\\|x-x_{i_j}\\|+\\|x_{i_j}-y_{i_j}\\|\\\\\n                 &<\\frac{\\epsilon'}{2}+\\frac{1}{i_j}\\\\\n                 &\\leq\\frac{\\epsilon'}{2}+\\frac{1}{j}\\\\\n                 &<\\frac{\\epsilon'}{2}+\\frac{\\epsilon'}{2}\\\\\n                 &=\\epsilon'\n    \\end{align*}\n  \\end{proof}\n\n  \\begin{theorem}[Heine-Borel]\n    Let $A\\subset\\R^n$ be closed and bounded. Then $A$ is compact.\n  \\end{theorem}\n\n  \\begin{definition}[Uniform convergence]\n    Let $A\\subset\\R^n$ and $(f_i)_{i\\in\\N}$ be a sequence of functions $f_i:A\\to\\R^m.$\n\n    We say $f_i\\to f$ \\textit{uniformly} to $f:A\\to\\R^m$ if and only if $\\forall\\epsilon>0$, \n    $\\exists N\\in\\N$ such that $\\|f_i(x)-f(x)\\|<\\epsilon$ whenever $i\\geq N$ and $x\\in A$.\n  \\end{definition}\n\n  \\begin{theorem}\n    Let $A\\subset\\R^n$ and $(f_i)_{i\\in\\N}$ be a sequence of functions $f_i:A\\to\\R^m$ which \n    converges uniformly to $f:A\\to\\R^m$ uniformly.\n    \n    Then if $f_i$ is uniformly continuous $\\forall i\\in\\N$, $f$ is uniformly continuous.\n  \\end{theorem}\n\n  \\begin{proof}\n    Fix $\\epsilon>0$. Then since $f_i\\to f$ uniformly, $\\exists N\\in\\N$ such that \n    $\\|f_i(x)-f(x)\\|<\\epsilon/3$ whenever $i\\geq N$ and $x\\in A$.\n\n    Also since each $f_i$ is uniformly continuous, $\\exists\\delta>0$ such that $\\|f_i(x)-f_i(y)\\|$ \n    $\\forall x,y\\in A$. Then using the triangle inequality:\n    \\begin{align*}\n      \\|f(x)-f(y)\\| &\\leq\\|f(x)-f_i(x)\\|+\\|f_i(x)-f(y)\\| \\\\\n                    &<\\epsilon/3+\\|f_i(x)-f_i(y)\\|+\\|f_i(y)-f(y)\\| \\\\\n                    &<\\epsilon/3+\\epsilon/3+\\epsilon/3 \\\\\n                    &=\\epsilon\n    \\end{align*}\n    $\\forall x,y\\in A$ such that $\\|x-y\\|<\\delta$. Hence, $f$ is uniformly continuous.\n  \\end{proof}\n\n  \\begin{cor}\n    Now assume that each $f_i$ is just continuous instead. Then $f$ is continuous.\n  \\end{cor}\n\n  \\begin{proof}\n    Fix $a\\in A$, and $\\epsilon>0$. Then since $f_i\\to f$ uniformly, $\\exists N\\in\\N$ such that \n    $\\|f_i(x)-f(x)\\|<\\epsilon/3$ whenever $i\\geq N$ and $x\\in A$.\n\n    Also since each $f_i$ is continuous, $\\exists\\delta>0$ such that $\\|f_i(x)-f_i(a)\\|<\\epsilon/3$ \n    $\\forall x\\in A$. Then using the triangle inequality:\n    \\begin{align*}\n      \\|f(x)-f(a)\\| &\\leq\\|f(x)-f_i(x)\\|+\\|f_i(x)-f(a)\\| \\\\\n                    &<\\epsilon/3+\\|f_i(x)-f_i(a)\\|+\\|f_i(a)-f(a)\\| \\\\\n                    &<\\epsilon/3+\\epsilon/3+\\epsilon/3 \\\\\n                    &=\\epsilon\n    \\end{align*}\n    $\\forall x\\in A$ such that $\\|x-a\\|<\\delta$. Hence, $f$ is continuous.\n  \\end{proof}\n\n\\subsection{Integration}\n\\label{sec:1.4}\n\n  \\begin{definition}[Partitions]\n    Let $[a,b]\\subset\\R$. We define a \\textit{partition}, $\\mathcal{P}$, of $[a,b]$ by an ordered tuple\n    $$\\mathcal{P}=(x_0,x_1,\\dots,x_{k-1},x_k),$$\n    such that $a=x_0<x_1<\\dots<x_{k-1}<x_k=b$.\n\n    We call any interval of the form $[x_j,x_{j+1}]$ a \\textit{subinterval} of the partition $\\mathcal{P}$. \n    The length of this subinterval is $\\Delta x_j=x_{j+1}-x_j$, and we define \n    $$\\text{mesh}(\\mathcal{P}):=\\max_{j=0,\\dots,k-1}{\\Delta x_j}.$$\n\n    Finally, for any two partitions $\\mathcal{P}$ and $\\mathcal{Q}$, we say $\\mathcal{Q}$ \\textit{refines} \n    $\\mathcal{P}$ iff every point in $\\mathcal{P}$ lies in $\\mathcal{Q}$.\n  \\end{definition}\n\n  \\begin{definition}[Darboux sums]\n    Let $f:[a,b]\\to\\R$ be bounded, and fix a partition $\\mathcal{P}$ of $[a,b]$. Then we define the \n    \\textit{upper} and \\textit{lower Darboux sums} by\n    $$U(f,\\mathcal{P})=\\sum_{j=0}^{k-1}M_j\\Delta x_j,$$\n    where $M_j=\\sup_{x\\in[x_j,x_{j+1}]}{f(x)}$, and\n    $$L(f,\\mathcal{P})=\\sum_{j=0}^{k-1}m_j\\Delta x_j,$$\n    where $m_j=\\inf_{x\\in[x_j,x_{j+1}]}{f(x)}$.  \n  \\end{definition}\n\n  \\begin{lemma}\n    Let $\\mathcal{P}$ and $\\mathcal{Q}$ be partitions of $[a,b]$, with $\\mathcal{Q}$ a refinement of \n    $\\mathcal{P}$. Then\n    $$L(f,\\mathcal{P})\\leq L(f,\\mathcal{Q})\\leq U(f,\\mathcal{Q})\\leq U(f,\\mathcal{P}).$$\n  \\end{lemma}\n\n  \\begin{proof}\n    Let $\\mathcal{Q}=(x_0=a,x_1,\\dots,x_k=b)$. Let $I_j$ be the subinterval of $\\mathcal{P}$ \n    containing $[x_j,x_{j+1}]$, for $j=0,\\dots,k-1$. Then \n    $$\\inf_{x\\in I_j}{f(x)}\\leq\\inf_{x\\in [x_j,x_{j+1}]}{f(x)}\\leq\\sup_{x\\in [x_j,x_{j+1}]}{f(x)}\n    \\leq\\sup_{x\\in I_j}{f(x)}.$$\n    Then by multiplying by $\\Delta x_j$ and summing over $j$, we get\n    $$\\sum_{j=0}^{k-1}{\\Delta x_j\\inf_{x\\in I_j}{f(x)}}\\leq\\sum_{j=0}^{k-1}{\\Delta x_j m_j}\n    \\leq\\sum_{j=0}^{k-1}{\\Delta x_j M_j}\\leq\\sum_{j=0}^{k-1}{\\Delta x_j\\sup_{x\\in I_j}{f(x)}}.$$\n    We can rewrite the two outer sums as \n    $$\\sum_{j=0}^{k-1}{\\Delta x_j\\inf_{x\\in I_j}{f(x)}}=\\sum_{\\text{subints. of }\\mathcal{P}\n    \\text{, }I}{\\bigg[\\inf_{x\\in I}{f(x)}}\\sum_{j\\text{ s.t. }I=I_j}{\\Delta x_j}\\bigg]=L(f,\\mathcal{P}),$$\n    $$\\sum_{j=0}^{k-1}{\\Delta x_j\\sup_{x\\in I_j}{f(x)}}=\\sum_{\\text{subints. of }\\mathcal{P}\n    \\text{, }I}{\\bigg[\\sup_{x\\in I}{f(x)}}\\sum_{j\\text{ s.t. }I=I_j}{\\Delta x_j}\\bigg]=U(f,\\mathcal{P}).$$\n    Hence,\n    $$L(f,\\mathcal{P})\\leq L(f,\\mathcal{Q})\\leq U(f,\\mathcal{Q})\\leq U(f,\\mathcal{P}).$$\n  \\end{proof}\n\n  \\begin{cor}\n    $$L(f,\\mathcal{P})\\leq U(f,\\mathcal{P'})$$\n    for any two partitions $\\mathcal{P}$ and $\\mathcal{P'}$.\n  \\end{cor}\n\n  \\begin{proof}\n    Let $\\mathcal{Q}$ be a common refinement of $\\mathcal{P}$ and $\\mathcal{P'}$. Then \n    $$L(f,\\mathcal{P})\\leq L(f,\\mathcal{Q})\\leq U(f,\\mathcal{Q})\\leq U(f,\\mathcal{P'}).$$    \n  \\end{proof}\n\n  \\begin{definition}[Darboux integrals]\n    We define the following sets:\n    \\begin{align*}\n      U_f&=\\{U(f,\\mathcal{P'}):\\mathcal{P'}\\text{ is a partition of }[a,b]\\}, \\\\\n      \\text{and }L_f&=\\{L(f,\\mathcal{P}):\\mathcal{P}\\text{ is a partition of }[a,b]\\}.\n    \\end{align*}\n    Let $\\mathcal{Q}$ be any parition of $[a,b]$. Then $U_f$ is bounded below by $L(f,\\mathcal{Q})$ and $L_f$ is \n    bounded above by $U(f,\\mathcal{Q})$. Thus we can define \\textit{upper} and \\textit{lower Darboux \n    integrals} by:\n    $$\\overline{\\int_a^b}f(x)\\text{d}x=\\inf{U_f},$$\n    $$\\underline{\\int_a^b}f(x)\\text{d}x=\\sup{L_f}.$$\n    If these two are equal, then we say $f$ is \\textit{integrable}, and we let \n    $$\\int_a^bf(x)\\text{d}x=\\overline{\\int_a^b}f(x)\\text{d}x=\\underline{\\int_a^b}f(x)\\text{d}x.$$\n  \\end{definition}\n\n  \\begin{prop}\n    A bounded function $f:[a,b]\\to\\R$ is integrable if and only if $\\eps$ there exists a partition \n    $\\calP$ of $[a,b]$ such that\n    $$U(f,\\calP)-L(f,\\calP)<\\epsilon.$$\n  \\end{prop}\n\n  \\begin{proof}\n    We assume that $\\eps$ there exists a partition $\\calP$ of $[a,b]$ such that $U(f,\\calP)-\n    L(f,\\calP)<\\epsilon.$ Then\n    $$L(f,\\calP)\\leq\\underline{\\int_a^b}f(x)\\text{d}x\\leq\\overline{\\int_a^b}f(x)\\text{d}x\\leq U(f,\\calP),$$\n    so \n    $$\\overline{\\int_a^b}f(x)\\text{d}x-\\underline{\\int_a^b}f(x)\\text{d}x\\leq U(f,\\calP)-L(f,\\calP)<\\epsilon,$$\n    and so \n    $$\\overline{\\int_a^b}f(x)\\text{d}x=\\underline{\\int_a^b}f(x)\\text{d}x$$\n    so $f$ is integrable. \n\n    Conversely, assume that $f$ is integrable. Fix $\\eps$. Then since $\\lowint=\\sup{L_f}$ and \n    $\\upint=\\inf{U_f}$, $\\exists\\calP,\\calP'$ as parititions of $[a,b]$, such that \n    $$\\lowint\\geq L(f,\\calP)>\\lowint-\\frac{\\epsilon}{2},$$\n    $$\\upint\\leq U(f,\\calP')<\\upint+\\frac{\\epsilon}{2}.$$\n    Since $f$ is integrable, this simplifies to\n    $$L(f,\\calP)+\\frac{\\epsilon}{2}>0,$$\n    $$U(f,\\calP')-\\frac{\\epsilon}{2}<0.$$\n    We let $\\calQ$ be the common refinement of $\\calP$ and $\\calP'$. Then\n    $$U(f,\\calQ)-L(f,\\calQ)\\leq U(f,\\calP')-L(f,\\calP)<\\frac{\\epsilon}{2}+\\frac{\\epsilon}{2}\n    =\\epsilon.$$    \n  \\end{proof}\n\n  \\begin{prop}\n    Every continuous function is integrable.\n  \\end{prop}\n\n  \\begin{proof}\n    Suppose $f:[a,b]\\to\\R$ is continuous. Since $[a,b]$ is compact, $f$ is uniformly continuous, so \n    $\\forall x,y\\in[a,b]$, $\\eps\\del$ such that $|f(x)=f(y)|<\\epsilon/{b-a}$ when $|x-y|<\\delta$.\n    Now fix $\\eps$, let $calP$ be a partition of $[a,b]$ with $k+1$ uniformly spaced points, and \n    such that $\\text{mesh}(\\calP)<\\delta$.\n\n    Then $\\forall x,y\\in[x_j,x_{j+1}]$, we have $|f(x)-f(y)|<\\epsilon/{b-a}$, for $j=0,1,\\dots,k-1$. \n    In particular $M_j-m_j<\\epsilon/{b-a}$, so $\\Delta x_j(M_j-m_j)<\\Delta x_j\\epsilon/{b-a}$. We \n    then sum over $j$, noting that $\\Delta x_j=b-a/k$\n\n    \\begin{align*}\n      \\sum_{j=0}^{k-1}\\Delta x_j(M_j-m_j)&<\\sum_{j=0}^{k-1}\\frac{\\epsilon(b-a)}{k(b-a)} \\\\\n      \\sum_{j=0}^{k-1}\\Delta x_j M_j-\\sum_{j=0}^{k-1}\\Delta x_j m_j&<\\frac{k\\epsilon}{k} \\\\\n      U(f,\\calP)-L(f,\\calP) &<\\epsilon\n    \\end{align*}\n    And so $f$ is integrable by the previous proposition.\n  \\end{proof}\n\n  \\begin{prop}[Linearity of the integral]\n    Let $f:[a,b]\\to\\R$ and $g:[a,b]\\to\\R$ be integrable functions, and $\\lambda\\in\\R$. Then $f+\n    \\lambda g$ is inetgrable, and\n    $$\\int_a^bf(x)+\\lambda g(x)\\text{d}x=\\int_a^bf(x)\\text{d}x+\\lambda\\int_a^bg(x)\\text{d}x.$$\n  \\end{prop}\n\n  \\begin{proof}\n\n  \\end{proof}\n\n  \\begin{prop}[Additivity of the integral]\n    Let $f:[a,b]\\to\\R$ be bounded, and let $c\\in[a,b]$. Then $f$ is integrable on $[a,b]$ if and \n    only if $f$ is integrable on both $[a,c]$ and $[c,b]$. Moreover\n    $$\\int_a^bf(x)\\text{d}x=\\int_a^cf(x)\\text{d}x+\\int_c^bf(x)\\text{d}x.$$\n  \\end{prop}\n\n  \\begin{proof}\n    Assume $f$ is integrable on $[a,b]$. Fix $\\eps$. Then we can choose a partition $\\calP=\n    (x_0=a,x_1,\\dots,x_{k-1},x_k=b)$ such that $U(f,\\calP)-L(f,\\calP)<\\epsilon$. We let $\\calQ$ be a \n    refinement of $\\calP$ containing $c$, say $\\calQ=(x_0=a,\\dots,x_{l-1},x_l=c,x_{l+1},\\dots,x_k=b)$.\n    Clearly $U(f,\\calQ)-L(f,\\calQ)<\\epsilon$.\n\n    We now `split' $\\calQ$ into two partitions $\\calQ_1=(a,x_1,\\dots,c)$ and $\\calQ_2=(c,x_{l+1},\\dots,b)$.\n    Then $U(f,\\calQ)=U(f,\\calQ_1)+U(f,\\calQ_2)$, and $L(f,\\calQ)=L(f,\\calQ_1)+L(f,\\calQ_2)$, so \n    $$U(f,\\calQ_1)-L(f,\\calQ_1)+U(f,\\calQ_2)-L(f,\\calQ_2)<\\epsilon,$$\n    and so \n    $$U(f,\\calQ_1)-L(f,\\calQ_1)<\\epsilon,$$\n    $$U(f,\\calQ_2)-L(f,\\calQ_2)<\\epsilon.$$\n    Hence, $f$ is integrable on $[a,c]$ and $[c,b]$.\n\n    Conversely, assume that $f$ is integrable on $[a,c]$ and $[c,b]$. Fix $\\eps$. Then there exists \n    partitions $\\calP_1:=(a,x_1,\\dots,c)$ and $\\calP_2:=(c,\\dots,x_{k-1},b)$ of $[a,c]$ and $[c,b]$ respectively such that \n    $$U(f,\\calP_1)-L(f,\\calP_1)<\\frac{\\epsilon}{2},$$\n    $$U(f,\\calP_2)-L(f,\\calP_2)<\\frac{\\epsilon}{2}.$$\n    Then \n    $$U(f,\\calP_1)+U(f,\\calP_2)-L(f,\\calP_1)-L(f,\\calP_2)<\\epsilon.$$\n    We now `join' $\\calP_1$ and $\\calP_2$ at $c$ to create a partition of $[a,b]$, $\\calQ:=\n    (a,\\dots,x_{l-1},c,x_{l+1},\\dots,b)$. Then \n    $$U(f,\\calQ)=U(f,\\calP_1)+U(f,\\calP_2),$$\n    $$L(f,\\calQ)=L(f,\\calP_1)+L(f,\\calP_2),$$\n    so \n    $$U(f,\\calQ)-L(f,\\calQ)=U(f,\\calP_1)-L(f,\\calP_1)+U(f,\\calP_2)-L(f,\\calP_2)<\\frac{\\epsilon}{2}\n    +\\frac{\\epsilon}{2}=\\epsilon.$$\n    And hence, $f$ is integrable on $[a,b]$.\n    \n    Finally, since $\\int_a^bf(x)\\text{d}x=\\inf{U_f}=\\sup{L_f}$, for all $\\epsilon>0$ there exists a partition $\\calP$ of \n    $[a,b]$ such that when we split it into two partitions $\\calQ_1$ and $\\calQ_2$ of $[a,c]$ and \n    $[c,b]$ respectively, as illustrated above, we get \n    \\begin{align*}\n      \\int_a^bf(x)\\text{d}x &\\leq U(f,\\calP) \\\\\n                            &=U(f,\\calQ_1)+U(f,\\calQ_2) \\\\\n                            &<\\int_a^cf(x)\\text{d}x+\\frac{\\epsilon}{2}+\\int_c^bf(x)\\text{d}x\n                                                                      +\\frac{\\epsilon}{2} \\\\\n                            &=\\int_a^cf(x)\\text{d}x+\\int_c^bf(x)\\text{d}x+\\epsilon.\n    \\end{align*}\n    Similarly, \n    \\begin{align*}\n      \\int_a^bf(x)\\text{d}x &\\geq L(f,\\calP) \\\\\n                            &=L(f,\\calQ_1)+L(f,\\calQ_2) \\\\\n                            &>\\int_a^cf(x)\\text{d}x-\\frac{\\epsilon}{2}+\\int_c^bf(x)\\text{d}x\n                                                                      -\\frac{\\epsilon}{2} \\\\\n                            &=\\int_a^cf(x)\\text{d}x+\\int_c^bf(x)\\text{d}x-\\epsilon,\n    \\end{align*}\n    and hence,\n    $$\\bigg|\\int_a^bf(x)\\text{d}x-\\bigg(\\int_a^cf(x)\\text{d}x+\\int_c^bf(x)\\text{d}x\\bigg)\\bigg|\n                                                                                    <\\epsilon,$$\n    so                                                                               \n    $$\\int_a^bf(x)\\text{d}x=\\int_a^cf(x)\\text{d}x+\\int_c^bf(x)\\text{d}x.$$\n  \\end{proof}\n\n  \\begin{lemma}\n    Let $A\\subset\\R^n$ and $f,g:A\\to\\R$ be bounded. Then \n    \\begin{enumerate}\n      \\item $\\sup_{x\\in A}{-f(x)}=-\\inf_{x\\in A}{f(x)}$\n      \\item $\\inf_{x\\in A}{-f(x)}=-\\sup_{x\\in A}{f(x)}$\n      \\item $|\\sup_{x\\in A}f(x)|\\leq\\sup_{x\\in A}|f(x)|$\n      \\item $|\\inf_{x\\in A}f(x)|\\leq\\inf_{x\\in A}|f(x)|$\n      \\item $\\sup_{x\\in A}{f(x)+g(x)}\\leq\\sup_{x\\in A}{f(x)}+\\sup_{x\\in A}{g(x)}$\n      \\item $\\inf_{x\\in A}{f(x)+g(x)}\\geq\\inf_{x\\in A}{f(x)}+\\inf_{x\\in A}{g(x)}$\n    \\end{enumerate}\n  \\end{lemma}\n\n  \\begin{lemma}\n    Let $A\\subset\\R^n$, and $f:A\\to\\R$ be bounded. Then\n    $$\\sup_{x\\in A}{|f(x)|}-\\inf_{x\\in A}{|f(x)|}\\leq\\sup_{x\\in A}{f(x)}-\\inf_{x\\in A}{f(x)}.$$\n  \\end{lemma}\n\n  %\\begin{proof}\n  %  \\verb%% \n%\n  %  \\textit{Case 1.} $$\\sup_{x\\in A}f(x)\\leq0.$$\n  %    Then $f(x)\\leq0\\,\\forall x\\in A$, so $f(x)=-|f(x)|$. \n  %    \n  %    So $\\sup_{x\\in A}{f(x)}-\\inf_{x\\in A}{f(x)}\n  %    =\\sup_{x\\in A}{-|f(x)|}-\\inf_{x\\in A}{-|f(x)|}=-\\inf_{x\\in A}{|f(x)|}+\\sup_{x\\in A}{|f(x)|}$, \n  %    and hence we have equality.\n%\n  %  \\textit{Case 2.} $$\\sup_{x\\in A}f(x)\\geq0,\\,\\inf_{x\\in A}f(x)\\geq0.$$\n  %    Then again we have equality trivially. \n%\n  %  \\textit{Case 3.} $$\\sup_{x\\in A}f(x)>0,\\,\\inf_{x\\in A}f(x)<0.$$\n  %    Then $\\sup_{x\\in A}f(x)=|\\sup_{x\\in A}f(x)|\\leq\\sup_{x\\in A}|f(x)|$, \n  %    $\\inf_{x\\in A}f(x)=-|\\inf_{x\\in A}f(x)|\\geq-\\inf_{x\\in A}{|f(x)|}$.\n  %\\end{proof}\n\n  \\begin{lemma}\n    Let $f:[a,b]\\to\\R$ be an integrable function. Then $\\eps,\\del$ such that \n    $U(f,\\calP)-L(f,\\calP)<\\epsilon$ whenever $\\text{mesh}(\\calP)<\\delta$.\n  \\end{lemma}\n\n  %\\begin{proof}\n  %  Fix $\\epsilon>0$. Then, since $f$ is integrable, it is bounded, so $\\exists M\\geq0$ such that \n  %  $|f(x)|\\leq M,\\,\\forall x\\in[a,b]$. Also, $\\exists$ partition $\\calQ:=(x_0=a,x_1,\\dots,x_{k-1},x_k=b)$ \n  %  such that \n  %  $$U(f,\\calQ)-L(f,\\calQ)<\\frac{\\epsilon}{2}.$$\n%\n  %  Let $\\calP:=(x_0=a,x_1,\\dots,x_{l-1},x_l=b)$ be a partition of $[a,b]$ with $\\text{mesh}(\\calP)\n  %  <\\delta:=\\frac{\\epsilon}{5kM}$.\n%\n  %  Then $\\forall j=0,\\dots,k-1$, we define the sets \n  %  $$A_j:=\\{0\\leq i\\leq l-1:[x_i]\\}$$\n  %\\end{proof} \n\n  \\begin{definition}[Riemann sum]\n    Given an integrable function $f:[a,b]\\to\\R$ and a \\textit{tagged partition}, \n    $(\\calP,\\tau)$ where \n    $$\\calP=(x_0,\\dots,x_k),$$\n    $$\\tau=(t_0,\\dots,t_{k-1})$$ with \n    $t_j\\in[x_j,x_{j+1}]\\,\\forall j\\in\\{0,\\dots,k-1\\}$, of $[a,b]$, we define a \\textit{Riemann sum} by \n    $$R(f,\\calP,\\tau)=\\sum_{j=0}^{k-1}{f(t_j)\\Delta x_j}.$$\n  \\end{definition}\n\n  \\begin{theorem}\n    Let $f:[a,b]\\to\\R$ be an integrable function, and $\\big((\\calP_i,\\tau_i)\\big)_{i\\in\\N}$ be sequence of \n    tagged partitions of $[a,b]$ such that $\\text{mesh}(\\calP_i)\\to 0$ as $i\\to\\infty$. Then \n    $$R(f,\\calP_i,\\tau_i)\\to\\int_a^bf(x)\\text{d}x,$$\n    as $i\\to\\infty$.\n  \\end{theorem}\n\n  \\begin{proof}\n    Fix $\\varepsilon>0$. Then $\\del$ such that $U(f,\\calQ)-L(f,\\calQ)<\\varepsilon$ whenever \n    $\\text{mesh}(\\calQ)<\\delta$. Since $\\text{mesh}(\\calP_i)\\to 0$ as $i\\to\\infty$, $\\exists N\\in\\N$ \n    such that $|\\text{mesh}(\\calP_i)|<\\delta$ whenever $i\\geq N$. So \n    $$U(f,\\calP_i)-L(f,\\calP_i)<\\varepsilon\\quad\\forall i\\geq N.$$\n    Note that since $(m_j)_i\\leq (f(t_j))_i\\leq (M_j)_i$, we have $L(f,\\calP_i)\\leq R(f,\\calP_i,\\tau_i)\\leq U(f,\\calP_i)$, \n    and in particular \n    $$L(f,\\calP_i)-\\varepsilon<R(f,\\calP_i,\\tau_i)<U(f,\\calP_i)+\\varepsilon.$$\n    Then since \n    $$L(f,\\calP_i)\\leq\\int_a^bf(x)\\text{d}x\\leq  U(f,\\calP_i),$$\n    we have \n    $$-\\varepsilon<R(f,\\calP_i,\\tau_i)-\\int_a^bf(x)\\text{d}x<\\varepsilon.$$\n    Hence\n    $$\\bigg|R(f,\\calP_i,\\tau_i)-\\int_a^bf(x)\\text{d}x\\bigg|<\\varepsilon.$$\n  \\end{proof}\n\n  \\begin{theorem}[Fundamental theorem of Calculus]\n    Let $f:[a,b]\\to\\R$ be continuous. We define $F:[a,b]\\to\\R$ by \n    $$F(x)=\\int_a^xf(t)\\text{d}t.$$\n    Then $F$ is differentiable on $(a,b)$, and $F'(x)=f(x)$ $\\forall x,y\\in[a,b]$.\n  \\end{theorem}\n\n  \\begin{proof}\n    Fix $\\varepsilon>0$. Then since $f$ is continuous on $[a,b]$, it is uniformly continuous so \n    $\\exists\\delta>0$ such that $|f(y)-f(z)|<\\varepsilon$ whenever $|y-z|<\\delta$. Now fix \n    $x\\in(a,b)$. Then $\\forall y\\in[a,b]$ such that $0<|y-x|<\\delta$, we have:\n    \\begin{align*}\n      \\bigg|\\frac{F(y)-F(x)}{y-x}-f(x)\\bigg|&=\\bigg|\\frac{1}{y-x}\\bigg(\\int_a^yf(t)\\text{d}t-\n      \\int_a^xf(t)\\text{d}t\\bigg)-f(x)\\bigg| \\\\\n                                            &=\\bigg|\\frac{1}{y-x}\\int_x^yf(t)\\text{d}t-f(x)\\bigg| \\\\\n                                            &=\\bigg|\\frac{1}{y-x}\\int_x^yf(t)-f(x)\\text{d}t\\bigg| \\\\\n                                            &=\\frac{1}{|y-x|}\\bigg|\\int_x^yf(t)-f(x)\\text{d}t\\bigg| \\\\\n                                            &\\leq\\sup_{t\\in[x,y]}|f(t)-f(x)| \\\\\n                                            &=\\max_{t\\in[x,y]}|f(t)-f(x)|\\text{ by the extreme value theorem } \\\\\n                                            &<\\varepsilon, \n    \\end{align*}\n    Since $|t-x|<\\delta$.\n  \\end{proof}\n\n\n\\subsection{Differentiation}\n\\label{sec:1.5}\n", "meta": {"hexsha": "55685d6cafe090f129f47fb3d0c1e0205dd778c4", "size": 32861, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01-analysis.tex", "max_stars_repo_name": "Jerrycaster/maths", "max_stars_repo_head_hexsha": "29706561f90442846e67348a75094e840a8124b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "01-analysis.tex", "max_issues_repo_name": "Jerrycaster/maths", "max_issues_repo_head_hexsha": "29706561f90442846e67348a75094e840a8124b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01-analysis.tex", "max_forks_repo_name": "Jerrycaster/maths", "max_forks_repo_head_hexsha": "29706561f90442846e67348a75094e840a8124b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.6937590711, "max_line_length": 123, "alphanum_fraction": 0.5743890935, "num_tokens": 12853, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.7064476303690798}}
{"text": "\\section[Sequences and Series of Functions]{\\hyperlink{toc}{Sequences and Series of Functions}}\n\n\\subsection{Motivating Examples}\n\\begin{nexample}{}{}\n    For $m, n \\in \\NN$, let $p_{n, m} = \\frac{m}{n}$. Then, \n    \\begin{align*}\n        \\lim_{m\\rightarrow \\infty} p_{m, n} = \\infty, \\quad \\linf p_{m, n} = 0\n    \\end{align*}\n    In particular,\n    \\begin{align*}\n        \\lim_{m \\rightarrow \\infty}\\linf p_{m, n} = 0, \\quad \\linf\\lim_{m \\rightarrow \\infty} p_{m, n} = \\infty.\n    \\end{align*}\n    Which demonstrates that the order of which limits are taken in can affect the value.\n\\end{nexample}\n\n\\begin{nexample}{}{}\n    Define the sequence of functions:\n    \\begin{align*}\n        f_n(x) = \\begin{cases}\n            1 & x \\geq 0\n            \\\\ 1 + nx & -\\frac{1}{n} < x < 0\n            \\\\ 0 & x \\leq -\\frac{1}{n}\n        \\end{cases}\n    \\end{align*}\n    Since $f_n$ is piecewise linear, it is continuous. However, looking at the $n \\rightarrow \\infty$ limit, we have:\n    \\begin{align*}\n        \\linf f_n(x) = \\begin{cases}\n            1 & x \\geq 0\n            \\\\ 0 & x < 0\n        \\end{cases}\n    \\end{align*}\n    Which is the right continuous step function, which is evidently discontinuous at $x = 0$. Hence, the limit of continuous functions can be discontinuous. Another way of viewing this problem is:\n    \\begin{align*}\n        \\linf \\lim_{x \\rightarrow 0} f_n(x) = 0, \\quad \\lim_{x \\rightarrow 0} \\linf f_n(x) = \\text{D.N.E.}\n    \\end{align*}\n    so again we see the order of taking our limits can be important.\n\\end{nexample}\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale=1.5]\n        \\draw[latex-latex, very thick] (-2, 0) -- (2, 0);\n        \\draw[-latex , very thick] (0, 0) -- (0, 2);\n        \\draw[<-, thick, blue] (-1.5, 0) -- (-0.5, 0);\n        \\draw[thick, blue] (-0.5, 0) -- (0, 1);\n        \\draw[->, thick, blue] (0,1) -- (1.5, 1);\n        \\draw[] (-0.5, 0) -- (-0.5, -0.15);\n        \\node[below] at (-0.5, -0.15) {$-\\frac{1}{n}$};\n    \\end{tikzpicture}\n    \n    \n    \\caption{Plot of $f_n$ in the above example.}\n    \\label{fig37}\n\\end{figure}\n\n\\setcounter{rudin}{3}\n\n\\begin{example}{}{7.4}\n    For $m \\in \\NN$ and $x \\in \\RR$, let $f_m(x) = \\lim_{n \\rightarrow \\infty} \\left[\\cos(m!\\pi x)\\right]^{2n}$. Since $\\abs{\\cos(k\\pi)} = 1$ if $k \\in \\ZZ$, we see that $f_m(x) = 1$ when $m! x \\in \\ZZ$. Conversely, since $\\abs{\\cos(k\\pi)} < 1$ if $k \\neq \\ZZ$, $f_m(x) = 0$ when $m! x \\notin \\ZZ$. Some plots of $f_m(x)$ on $[0, 1]$ for $m = 1, 2, 3$ are below as a visualization. We now define $f(x) = \\lim_{m \\rightarrow \\infty} f_m(x)$. If $x = \\frac{p}{q} \\in \\QQ$, then $m! x = \\frac{m! p}{q} \\in \\ZZ$ for $m$ large enough (for $m \\geq q$, as the denominator cancells). Therefore, we have that $f(x) = 1$ for $x \\in \\QQ$. Conversely, if $x \\notin \\QQ$, then $m! x \\notin \\ZZ$ for all $m \\in \\NN$. So, $f_m(x) = 0$ for all $m$, and $f(x) = 0$. Therefore, we have that:\n    \\begin{align*}\n        f(x) = \\lim_{m \\rightarrow \\infty} f_m(x) = \\begin{cases}\n            1 & x \\in \\QQ\n            \\\\ 0 & x \\notin \\QQ\n        \\end{cases}.\n    \\end{align*}\n    In other words, $f$ is the Dirchlet function. The interesting part is that each of the $f_m(x)$ are Riemann integrable on $[0, 1]$ by Theorem \\ref{thm:6.10} (as $f$ has finitely many discontinuities for any $m \\in \\NN$). However, the limit is not Riemann integrable, as we prove below. Hence, the limit of Riemann integrable functions is not necessarily Riemann integrable.\n\\end{example}\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale = 1.5]\n        \\draw[-latex, very thick] (0, 0) -- (0, 2);\n        \\draw[-latex, very thick] (0, 0) -- (2, 0);\n        \\draw[-latex, very thick] (2.5, 0) -- (2.5, 2);\n        \\draw[-latex, very thick] (2.5, 0) -- (4.5, 0);\n        \\draw[-latex, very thick] (5, 0) -- (5, 2);\n        \\draw[-latex, very thick] (5, 0) -- (7, 0);\n        \\filldraw[blue] (0, 1) circle (1.5pt);\n        \\filldraw[blue] (1.5, 1) circle (1.5pt);\n        \\draw[thick, blue] (0, 0) -- (1.5, 0);\n        \\draw[blue, fill = white] (0, 0) circle (1.5pt);\n        \\draw[blue, fill = white] (1.5, 0) circle (1.5pt);\n        \\node[text = blue] at (0.75, 0.5) {$f_1(x)$};\n\n        \\filldraw[blue] (2.5, 1) circle (1.5pt);\n        \\filldraw[blue] (3.25, 1) circle (1.5pt);\n        \\filldraw[blue] (4, 1) circle (1.5pt);\n        \\draw[thick, blue] (2.5, 0) -- (4, 0);\n        \\draw[blue, fill = white] (2.5, 0) circle (1.5pt);\n        \\draw[blue, fill = white] (3.25, 0) circle (1.5pt);\n        \\draw[blue, fill = white] (4, 0) circle (1.5pt);\n        \\node[text = blue] at (3.25, 0.5) {$f_2(x)$};\n\n        \\filldraw[blue] (5, 1) circle (1.5pt);\n        \\filldraw[blue] (5.25, 1) circle (1.5pt);\n        \\filldraw[blue] (5.5, 1) circle (1.5pt);\n        \\filldraw[blue] (5.75, 1) circle (1.5pt);\n        \\filldraw[blue] (6, 1) circle (1.5pt);\n        \\filldraw[blue] (6.25, 1) circle (1.5pt);\n        \\filldraw[blue] (6.5, 1) circle (1.5pt);\n        \\draw[thick, blue] (5, 0) -- (6.5, 0);\n        \\draw[blue, fill = white] (5, 0) circle (1.5pt);\n        \\draw[blue, fill = white] (5.25, 0) circle (1.5pt);\n        \\draw[blue, fill = white] (5.5, 0) circle (1.5pt);\n        \\draw[blue, fill = white] (5.75, 0) circle (1.5pt);\n        \\draw[blue, fill = white] (6, 0) circle (1.5pt);\n        \\draw[blue, fill = white] (6.25, 0) circle (1.5pt);\n        \\draw[blue, fill = white] (6.5, 0) circle (1.5pt);\n        \\node[text = blue] at (5.75, 0.5) {$f_3(x)$};\n    \\end{tikzpicture}\n    \\caption{Plot of $f_m(x)$ over the interval $[0, 1]$ for $m = 1, 2, 3$. For $m = 1$, only $x = 0, 1$ satisfy $m! x = x \\in \\ZZ$. For $m = 2$, we have that $x = 0, \\frac{1}{2}, 1$ satisfy $m!x = 2x \\in \\ZZ$. Finally, for $m = 3$, we have that $x = 0, \\frac{1}{6}, \\frac{2}{6}, \\frac{3}{6}, \\frac{4}{6}, \\frac{5}{6}, 1$ satisfy $m!x = 6x \\in \\ZZ$.}\n    \\label{fig38}\n\\end{figure}\n\n\\noindent We now show that $f$ defined in the above example is not Riemann integrable on $[0, 1]$.\n\n\\begin{proof}\n    Consider any partition $P$ of $[0, 1]$. Due to the density of rational and irrational numbers in $\\RR$ (Theorem \\ref{thm:1.20}) we have that $M_i = \\sup{f(x): x \\in [x_{i-1}, x_i]} = 1$ and $m_i = \\inf{f(x): x \\in [x_{i-1}, x_i]} = 0$ for all $i$. Therefore, we have that $U(P, f) = \\sum_{i=1}^N M_i \\Delta x_i = 1$ and $L(P, f) = \\sum_{i=1}^N m_i \\Delta x_i = 0$ for all partitions $P$. Therefore, $\\sup_P U(P, f) = 1$ and $\\inf_P L(P, f) = 0$, and we conclude that $f$ is not Riemann integrable on $[0, 1]$.\n\\end{proof}\n\n\n\\begin{nexample}{}{}\n    Define $f_n$ such that:\n    \\begin{align*}\n        f_n(x) = \\begin{cases}\n            0 & \\abs{x} \\geq \\frac{1}{n}\n            \\\\ n(nx+1) & -\\frac{1}{n} < x < 0\n            \\\\ -n(nx+1) & 0 < x < \\frac{1}{n}\n            \\\\ 0 & x = 0\n        \\end{cases}\n    \\end{align*}\n    Then, we have that $f(x) = \\linf f_n(x) = 0$ for all $x$.  Furthermore, we have that $\\int_{-1}^1 f_n(x)dx = 1$ for all $n$, but $\\int_{-1}^1 f(x)dx = 0$. Hence, we have that:\n    \\begin{align*}\n        \\linf \\int_{-1}^1 f_n(x)dx = 1 \\neq 0 = \\int_{-1}^1 \\linf f_n(x) dx\n    \\end{align*}\n    showing that problems can arise when we interchange the order of an integral with a limit.\n\\end{nexample}\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale=1.5]\n        \\draw[latex-latex, very thick] (-2, 0) -- (2, 0);\n        \\draw[-latex , very thick] (0, 0) -- (0, 2);\n        \\draw[<-, thick, blue] (-1.5, 0) -- (-0.5, 0);\n        \\draw[thick, blue] (-0.5, 0) -- (0, 1);\n        \\draw[thick, blue] (0, 1) -- (0.5, 0);\n        \\draw[->, thick, blue] (0.5, 0) -- (1.5, 0);\n        \\filldraw[blue] (0, 0) circle (1.5pt);\n        \\draw[blue, fill = white] (0, 1) circle (1.5pt);\n        \\node[right] at (0, 1) {$n$};\n        \\draw[] (-0.5, 0) -- (-0.5, -0.15);\n        \\node[below] at (-0.5, -0.15) {$-\\frac{1}{n}$};\n        \\draw[] (0.5, 0) -- (0.5, -0.15);\n        \\node[below] at (0.5, -0.15) {$\\frac{1}{n}$};\n    \\end{tikzpicture}\n    \n    \\caption{Plot of $f_n$ in the above example.}\n    \\label{fig39}\n\\end{figure}\n\n\\begin{example}{}{7.5}\n    Let $f_n(x) = \\frac{\\sin nx}{\\sqrt{n}}$ for $n \\in \\NN, x \\in \\RR$. Then, let $f(x) = \\linf f_n(x) = 0$ for all $x \\in \\RR$, so $f'(x) = 0$. However, $f'_n(x) = \\frac{1}{\\sqrt{n}}n \\cos n x = \\sqrt{n} \\cos n x$ and $\\linf \\sqrt{n} \\cos n x$ does not exist. For example, $f_n'(\\pi) = \\sqrt{n}(-1)^n$ which is a divergent sequence. So:\n    \\begin{align*}\n        f'(\\pi) = \\left(\\linf f_n\\right)'(\\pi) = 0 \\neq \\linf f_n'(\\pi)\n    \\end{align*}\n    whcih shows us that problems can arise when interchanging a derivative (which is just a type of limit) with a limit.\n\\end{example}\n\\noindent With the above five examples, we have seen examples of bad behaviour that can occur under interchange of limits. Namely:\n\\begin{enumerate}[1.]\n    \\item An interchange of the order of limits can change the limiting value for a double sequence.\n    \\item The limit of a sequence of continuous functions is not necessarily continuous.\n    \\item The limit of a sequence of Riemann integrable functions is not necessarily Riemann integrable.\n    \\item The limit of a sequence of Riemann integrals can differ from the Riemann integral of the limit of a sequence.\n    \\item The limit of a sequence of derivatives can differ from the derivative of a limit of a sequence.\n\\end{enumerate}\n\n\\noindent The good news is that in all of these examples, the sequences we looked at had a ``weak'' form of convergence, where we fix $x$ and then take the $n \\rightarrow \\infty$ limit. We will now proceed to look at a stronger version of convergence, which looks at ``all $x$ at once'', ensuring that this bad behaviour does not (for the most part) occur.\n\n\\subsection{Uniform Convergence}\n\n\\setcounter{rudin}{6}\n\\begin{definition}{Uniform Convergence}{7.7}\n    Let $E$ be any set and $f_n: E \\mapsto \\RR$ or $f_n: E \\mapsto \\CC$ for $n \\in \\NN$. Then, $f_n$ \\textbf{converges uniformly} to $f$ on $E$ if for all $\\e > 0$, there exists $N$ such that $n \\geq N$ implies that $\\abs{f_n(x) - f(x)} < \\e$ for all $x \\in E$. \n\\end{definition}\n\\noindent Note the lack of $x$ dependence in the above definition. We give a useful visual intuition of uniform convergence below:\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale=2]\n        \\draw[-latex, very thick] (0, 0) -- (2, 0);\n        \\draw[-latex, very thick] (0, 0) -- (0, 2);\n        \\node[] at (0.5, 0) {$[$};\n        \\node[] at (1.5, 0) {$]$};\n        \\node[below] at (1, 0) {$E$};\n        \\draw[red] (1, 1.5) parabola (0.5, 0.5);\n        \\draw[red] (1, 1.5) parabola (1.5, 0.5);\n        \\draw[red, dotted, yshift = 10pt] (1, 1.5) parabola (0.5, 0.5);\n        \\draw[red, dotted, yshift = 10pt] (1, 1.5) parabola (1.5, 0.5);\n        \\draw[red, dotted, yshift = -10pt] (1, 1.5) parabola (0.5, 0.5);\n        \\draw[red, dotted, yshift = -10pt] (1, 1.5) parabola (1.5, 0.5);\n        \\draw[<->] (1, 1.5) -- (1, 1.15);\n        \\node[left] at (1, 1.3) {$\\e$};\n        \\draw[<->] (1, 1.5) -- (1, 1.85);\n        \\node[left] at (1, 1.625) {$\\e$};\n        \\node[right, text = red] at (1.5, 0.5) {$f$};\n    \\end{tikzpicture}\n    \n    \\caption{Visualization of the intuition behind uniform convergence. If $f_n \\rightarrow f$, uniformly, for any $\\e > 0$, we can find $N$ such that for $n \\geq N$, $f_n(x)$ lies in the $\\e$-tube (pictured above) around $f$.}\n    \\label{fig40}\n\\end{figure}\n\n\\begin{nexample}{}{}\n    Let us return to Example \\ref{exam:7.5}. We have that:\n    \\begin{align*}\n        \\abs{f_n(x) - f(x)} = \\abs{\\frac{\\sin n x}{\\sqrt{n}} - 0} \\leq \\frac{1}{\\sqrt{n}}\n    \\end{align*}\n    So taking $n$ large enough such that $\\frac{1}{\\sqrt{n}} < \\e$, we can see that $f_n(x)$ converges uniformly to $f(x) = 0$. Note that this example does show that uniform convergence is \\textit{not} sufficient for:\n    \\begin{align*}\n        \\lim_{n \\rightarrow \\infty} f_n' = \\left(\\lim_{n \\rightarrow \\infty} f_n \\right)'\n    \\end{align*}\n    to hold. We will return to the relation of uniform convergence and differentiation in a later theorem.\n\\end{nexample}\n\n\\begin{nexample}{}{}\n    Let us return to our second example from our section on motivating examples. Recall we had:\n    \\begin{align*}\n        f_n(x) = \\begin{cases}\n            1 & x \\geq 0\n            \\\\ 1 + nx & -\\frac{1}{n} < x < 0\n            \\\\ 0 & x \\leq -\\frac{1}{n}\n        \\end{cases} \\quad f(x) = \\begin{cases}\n            1 & x \\geq 0\n            \\\\ 0 & x < 0\n        \\end{cases}\n    \\end{align*}\n    We then have that:\n    \\begin{align*}\n        f_n(x) - f(x) = \\begin{cases}\n            1 + nx & -\\frac{1}{n} < x < 0\n            \\\\ 0 & \\text{otherwise}\n        \\end{cases}\n    \\end{align*}\n    So for $x = -\\frac{1}{2n}$, we have that:\n    \\begin{align*}\n        f_n\\left(-\\frac{1}{2n}\\right) - f\\left(-\\frac{1}{2n}\\right) = 1 + n\\left(-\\frac{1}{2n}\\right) - 0 = \\frac{1}{2}\n    \\end{align*}\n    Which will never be less than $\\e$ for $\\e < \\frac{1}{2}$. Hence, we conclude that $f_n$ does not converge uniformly to $f$ on $\\RR$. \n\\end{nexample}\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale=1.5]\n        \\draw[latex-latex, very thick] (-2, 0) -- (2, 0);\n        \\draw[-latex , very thick] (0, 0) -- (0, 2);\n        \\draw[<-, thick, blue] (-1.5, 0) -- (-0.5, 0);\n        \\draw[thick, blue] (-0.5, 0) -- (0, 1);\n        \\draw[->, thick, blue] (0,1) -- (1.5, 1);\n        \\draw[] (-0.5, 0) -- (-0.5, -0.15);\n        \\node[below] at (-0.5, -0.15) {$-\\frac{1}{n}$};\n        \\draw[->, red] (0, 1) -- (1.5, 1);\n        \\draw[<-, red] (-1.5, 0) -- (0, 0);\n        \\draw[red, fill = red] (0, 1) circle (1pt);\n        \\draw[red, fill = white] (0, 0) circle (1pt);\n        \\node[left, text = blue] at (-0.25, 0.5) {$f_n$};\n        \\node[right, text = red] at (1.5, 1) {$f$};\n        \\draw[dotted, red] (-1.5, 0.1) -- (0, 0.1);\n        \\draw[dotted, red] (-1.5, -0.1) -- (0, -0.1);\n        \\draw[dotted, red] (0, 1.1) -- (1.5, 1.1);\n        \\draw[dotted, red] (0, 0.9) -- (1.5, 0.9);\n    \\end{tikzpicture}\n    \n    \\caption{Visualization of why the convergence of $f_n \\rightarrow f$ in the above example is not uniform. We can see that if we draw a small enough $\\e$ tube (i.e. $\\e \\leq 1$), there is no way to choose $n$ large enough to make all of $f_n(x)$ lie in the tube.}\n    \\label{fig41}\n\\end{figure}\n\\begin{theorem}{Cauchy Criterion for Uniform Convergence}{7.8}\n    $f_n$ converges uniformly on $E$ if and only if for all $\\e > 0$, thre exists $N$ such that if $m, n \\geq N$, then $\\abs{f_m(x) - f_n(x)} < \\e$ for all $x \\in E$. \n\\end{theorem}\n\\noindent Again, note the lack of $x$ dependence in the above theorem.\n\\begin{nproof}\n    $\\boxed{\\implies}$ Suppose $f_n \\rightarrow f$ uniformly on $E$. Then, there exists some $N$ such that for $m, n \\geq N$:\n    \\begin{align*}\n        \\abs{f_m(x) - f(x)} < \\frac{\\e}{2}, \\quad \\abs{f_n(x) - f(x)} < \\frac{\\e}{2}\n    \\end{align*}\n    for all $x \\in E$. Therefore by the triangle inequality, we have that:\n    \\begin{align*}\n        \\abs{f_m(x) - f_n(x)} \\leq \\abs{f_m(x) - f(x)} + \\abs{f(x) - f_n(x)} < \\frac{\\e}{2} + \\frac{\\e}{2} = \\e\n    \\end{align*}\n    Hence $\\abs{f_m(x) - f_n(x)} < \\e$ for all $x \\in E$. \n\n    $\\boxed{\\impliedby}$ Let $x \\in E$. By assumption, $\\set{f_n(x)}_{n \\in \\NN}$ is a Cauchy sequence, and hence has a limit $f(x)$ (as both $\\RR$ and $\\CC$, the possible codomains of $f$, are complete). We then let $f(x) = \\linf f_n(x)$, so we have pointwise convergence. To see that the convergence is uniform, let $\\e > 0$. We know that $\\abs{f_m(x) - f_n(x)} < \\e$ for $m, n \\geq N$ and for all $x$. Then, let $m \\rightarrow \\infty$. Then, $\\abs{f(x) - f_n(x)} \\leq \\e$. for all $n \\geq N$ and all $x \\in E$, so the convergence is uniform. \\qed\n\\end{nproof}\n\n\\begin{theorem}{}{7.9}\n    Suppose $\\linf f_n(x) = f(x)$ for $x \\in E$, and let:\n    \\begin{align*}\n        M_n = \\sup_{x \\in E}\\abs{f_n(x) - f(x)}\n    \\end{align*}\n    Then, $f_n \\rightarrow f$ uniformly on $E$ if and only if $M_n \\rightarrow 0$ as $n \\rightarrow \\infty$.\n\\end{theorem}\n\\begin{nproof}\n    $\\boxed{\\implies}$ suppose $f_n \\rightarrow f$ uniformly. Then, for any $\\e > 0$, there exists some $N \\in \\NN$ such that for all $n \\geq N$ and all $x \\in E$:\n    \\begin{align*}\n        \\abs{f_n(x) - f(x)} < \\e\n    \\end{align*}\n    Since this holds for all $x \\in E$, taking the supremum of $\\abs{f_n(x) - f(x)}$ we have that:\n    \\begin{align*}\n        \\sup_{x \\in E}\\abs{f_n(x) - f(x)} = M_n \\leq \\e\n    \\end{align*}\n    We then have that $M_n \\leq \\e$ for $n \\geq N$ for some $N$, and hence $M_n \\rightarrow 0$.\n    \n    $\\boxed{\\impliedby}$ Suppose that $M_n \\rightarrow 0$. Then, for any $\\e > 0$, there exists some $N \\in \\NN$ such that for all $n \\geq N$:\n    \\begin{align*}\n        \\sup_{x \\in E}\\abs{f_n(x) - f(x)} = M_n < \\e\n    \\end{align*}\n    We then have that for any $x \\in E$:\n    \\begin{align*}\n        \\abs{f_n(x) - f(x)} \\leq \\sup_{x \\in E}\\abs{f_n(x) - f(x)} < \\e\n    \\end{align*}\n    so we conclude that $f_n \\rightarrow f$ uniformly. \\qed\n\\end{nproof}\n\n\\begin{ndef}{: Uniform Convergence of Series}{}\n    We say that $\\sum_{n = 1}^\\infty f_n(x)$ \\textbf{converges uniformly} on $E$ if $S_n(x) = \\sum_{i=1}^n f_i(x)$ is a uniformly convergent sequence of functions.\n\\end{ndef}\n\n\\begin{theorem}{Weierstrauss M-Test}{7.10}\n    Suppose $\\abs{f_n(x)} < M_n$ for all $n \\geq N_0$ and for all $x \\in E$. Suppose also that $\\sum_{n = N_0}^\\infty M_n < \\infty$. Then, $\\sum_{n=1}^\\infty f_n(x)$ converges uniformly on $E$. \n\\end{theorem}\n\\begin{nproof}\n    Let $S_n(x) = \\sum_{i=1}^n f_i(x)$. For $n > m \\geq N_0$, we have that:\n    \\begin{align*}\n        \\abs{S_n(x) - S_m(x)} = \\abs{\\sum_{i=m+1}^n f_i(x)} \\leq \\sum_{i=m+1}^n \\abs{f_i(x)} \\leq \\sum_{i=m+1}^n M_i\n    \\end{align*}\n    Let $\\e > 0$. Choose $N \\geq N_0$ such that $\\sum_{i = N+1}^\\infty M_i < \\e$ (which we can choose as the series converges by assumption). We then have that $\\abs{S_n(x) - S_m(x)} < \\e$ for all $n > m \\geq N$ for all $x \\in E$. Hence, $S_n(x)$ converges uniformly on $E$. \\qed\n\\end{nproof}\n\n\\begin{theorem}{}{7.11}\n    Let $E \\subset X$ and $f_n: E \\mapsto \\RR \\text{ or } \\CC$, $n \\in \\NN$. Suppose $f_n \\rightarrow f$ uniformly on $E$, and let $x \\in E$ (where $x$ is a limit point of $E$). Suppose $\\lim_{t \\rightarrow x} f_n(t) = A_n$ exists for each $n \\in \\NN$. Then, $A_n \\rightarrow A$ for some $A$ And $\\lim_{t \\rightarrow x} f(t) = A$. In other words:\n    \\begin{align*}\n        \\lim_{t \\rightarrow x}\\linf f_n(t) = \\linf \\lim_{t \\rightarrow x} f_n(t)\n    \\end{align*}\n    showing that the interchange of limits is valid when we have uniform convergence.\n\\end{theorem}\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale=2]\n        \\draw[-latex, very thick] (0, 0) -- (2, 0);\n        \\draw[-latex, very thick] (0, 0) -- (0, 2);\n        \\draw[red] (0, 1) to [ curve through ={(0.5, 1.2)..(1,0.7)..(1.5,1.2)}] (1.7, 1.1);\n        \\draw[red, dotted, yshift = 5pt] (0, 1) to [ curve through ={(0.5, 1.2)..(1,0.7)..(1.5,1.2)}] (1.7, 1.1);\n        \\draw[red, dotted, yshift = -5pt] (0, 1) to [ curve through ={(0.5, 1.2)..(1,0.7)..(1.5,1.2)}] (1.7, 1.1);\n        \\draw[blue] (0, 1.15) to [curve through = {(0.5, 1.1)..(1, 0.8)..(1.5,1.1)}] (1.7, 1);\n        \\draw[blue, fill = white] (0, 1.15) circle (1pt);\n        \\node[left, text = blue] at (0, 1.15) {$A_n$};\n        \\draw[red, fill = white] (0, 1) circle (1pt);\n        \\node[left, text = red] at (0, 1) {$A$};\n        \\node[right, text = red] at (1.7, 1.15) {$f$};\n        \\node[right, text = blue] at (1.7, 0.95) {$f_n$};\n    \\end{tikzpicture}\n    \n    \\caption{Visualization of Theorem \\ref{thm:7.11}, with $E = (0, \\infty)$ and $x = 0$. Eventually, the graph of $f_n$ lies in the $\\e$ tube around $f$ (no matter how skinny the tube is). But, $A_n$ is being determined by $f_n$ near $0$, so there is nowhere for $A_n$ to go except to the limiting value. That is, $A_n \\rightarrow A$ as the $\\e$ tube gets compressed.}\n    \\label{fig42}\n\\end{figure}\n\n\\begin{nproof}\n    We first show that $A_n \\rightarrow A$ for some $A$. Since $\\RR, \\CC$ are complete metric spaces, it suffices to show that $\\set{A_n}$ is Cauchy. Given $\\e > 0$, choose $N$ such that for $m, n \\geq N$, $\\abs{f_n(t) - f_m(t)} < \\e$ for all $t$ (such an $N$ exists by Theorem \\ref{thm:7.8}). Letting $t \\rightarrow x$, we therefore obtain that $\\abs{A_n - A_m} \\leq \\e$ for all $m, n \\geq N$, showing that $\\set{A_n}$ is Cauchy. Hence, the sequence converges to some limit $A$. \n\n    Now, we show that $\\lim_{t \\rightarrow x}f(t) = A$. We show this by the common ``$\\e/3$ argument''. For all $t \\in E$ and $n \\in \\NN$, we have by the triangle inequality that:\n    \\begin{align*}\n        \\abs{f(t) - A} \\leq \\abs{f(t) - f_n(t)} + \\abs{f_n(t) - A_n} + \\abs{A_n - A} (*)\n    \\end{align*} \n    Which is a good move, as we know that we can make each of the three terms on the RHS arbitrarily small (they are ``close''). Let $\\e > 0$. Since $f_n \\rightarrow f$ uniformly, there exists $N_1$ such that $\\abs{f(t) - f_n(t)} < \\frac{\\e}{3}$ for all $n \\geq N_1$ and all $t \\in E$. Since $A_n \\rightarrow A$, there exists some $N_2$ such that $\\abs{A_n - A} < \\frac{\\e}{3}$ for all $n \\geq N_2$. Letting $N = \\max\\set{N_1, N_2}$ and taking $n = N$ in $(*)$, we have that:\n    \\begin{align*}\n        \\abs{f(t) - A} < \\frac{\\e}{3} + \\abs{f_N(t) - A_N} + \\frac{\\e}{3} \n    \\end{align*}\n    Since $\\lim_{t \\rightarrow x} f_N(t) = A_N$, we can choose $\\delta > 0$ such that $t \\in N_{\\delta}(x)$ implies $\\abs{f_N(t) - A_N} < \\frac{\\e}{3}$ (Note a subtle point here that this choice of $\\delta$ depends on $N$!). Therefore, if $t \\in N_{\\delta}(x)$, we have that:\n    \\begin{align*}\n        \\abs{f(t) - A} < \\frac{\\e}{3} + \\frac{\\e}{3} + \\frac{\\e}{3} = \\e\n    \\end{align*}\n    Hence, as $t \\rightarrow x$, $f(t) \\rightarrow A$. \\qed\n\\end{nproof}\n\n\\begin{theorem}{}{7.12}\n    Suppose $f_n$ is continuous on $E$ for all $n \\in \\NN$, and $f_n \\rightarrow f$ uniformly on $E$. Then, $f$ is continuous.\n\\end{theorem}\n\\begin{nproof}\n    Every $f_n$ is continuous at isolated points of $E$, so it suffices to consider limit points $x \\in E' \\cap E$. For these points, we have that:\n    \\begin{align*}\n        f(x) = \\lim_{n \\rightarrow \\infty}f_n(x) = \\linf\\lim_{t \\rightarrow x} f_n(t) = \\lim_{t \\rightarrow x} \\linf f_n(t) = \\lim_{t \\rightarrow x} f(t)\n    \\end{align*}\n    Where the third equality (the interchange of the two limits) follows from Theorem \\ref{thm:7.11}. We conclude that $f$ is continuous by Theorem \\ref{thm:4.6} (as $f(x) = \\lim_{t \\rightarrow x} f(t)$). \\qed\n\\end{nproof}\n\n\\begin{theorem}{}{7.13}\n    Suppose $K$ is compact, and:\n    \\begin{enumerate}\n        \\item $f_n$ is continuous on $K$ for each $n \\in \\NN$\n        \\item $f_n \\rightarrow f$ pointwise (that is, for each $x \\in K$, $f_n(x) \\rightarrow f(x)$) and $f$ is continuous\n        \\item $f_n(x) \\geq f_{n+1}(x)$ for all $x \\in K$ and all $n \\in \\NN$ (note that the opposite inequality also works, just multiply by $-1$).\n    \\end{enumerate}\n    Then, $f_n \\rightarrow f$ uniformly on $K$. \n\\end{theorem}\n\\noindent Note that this theorem is not super useful, being that it requires so many specific assumptions; however, we will find that it does have an interesting proof. Before we move to that, let us show some counterexamples for when the assumptions do not hold.\n\n\\begin{nexample}{}{}\n    Let $K = [-1, 0)$, and define:\n    \\begin{align*}\n        f_n(x) = \\begin{cases}\n            0 & -1 \\leq x \\leq -\\frac{1}{n}\n            \\\\ 1 + nx & -\\frac{1}{n} < x < 0\n        \\end{cases}\n    \\end{align*}\n    We then have that $f_n$ is continuous on $K$, that $f_n \\rightarrow 0$ pointwise on $K$, that $f$ is continuous (the zero function), and $f_n$ is decreasing with $n$. However, we note that $f_n$ does not converge uniformly to $f$ on $K$, with points close to zero being problem points (for example, take $x = -\\frac{1}{2n}$, and then $f_n(x) - f(x) = \\frac{1}{2}$ for all $n$). We note that $K$ is \\textit{not} compact, showing the importance of compactness of the domain in the above Theorem.\n\\end{nexample}\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale=1.5]\n        \\draw[latex-latex, very thick] (-2, 0) -- (2, 0);\n        \\draw[-latex , very thick] (0, 0) -- (0, 2);\n        \\draw[thick, blue] (-1.5, 0) -- (-0.5, 0);\n        \\draw[thick, blue] (-0.5, 0) -- (0, 1);\n        \\draw[blue, fill = white] (0, 1) circle (1pt);\n        \\draw[] (-1.5, 0) -- (-1.5, -0.15);\n        \\draw[blue, fill = blue] (-1.5, 0) circle (1pt);\n        \\draw[] (-0.5, 0) -- (-0.5, -0.15);\n        \\node[below] at (-0.5, -0.15) {$-\\frac{1}{n}$};\n        \\node[below] at (-1.5, -0.15) {$-1$};\n        \\node[right] at (0, 1) {$1$};\n    \\end{tikzpicture}\n    \n    \\caption{Plot of $f_n$ on $K = [-1, 0)$ from the above example.}\n    \\label{fig43}\n\\end{figure}\n\n\\begin{nexample}{}{}\n    Let $K = [0, 1]$, and define:\n    \\begin{align*}\n        f_n(x) = \\begin{cases}\n            2nx & 0 \\leq x < \\frac{1}{2n}\n            \\\\ 2 - 2nx & \\frac{1}{n} \\leq x \\leq \\frac{1}{n}\n            \\\\ 0 & \\frac{1}{n} < x \\leq 1\n        \\end{cases}\n    \\end{align*}\n    We then have that $f_n$ is continuous, $f_n \\rightarrow f = 0$ pointwise (which is continuous), and $K$ is compact. However, $f_n$ does not converge to $f$ uniformly. In this case, condition (c) of the above Theorem fails; $f_n$ is not monotonic in $n$.\n\\end{nexample}\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale=2]\n        \\draw[-latex, very thick] (0, 0) -- (2, 0);\n        \\draw[-latex, very thick] (0, 0) -- (0, 2);\n        \\draw[] (1, 0) -- (1, -0.15);\n        \\draw[blue, thick] (0, 0) -- (0.5, 1);\n        \\draw[blue, thick] (0.5, 1) -- (1, 0);\n        \\draw[blue, thick] (1, 0) -- (1.5, 0);\n        \\draw[] (1.5, 0) -- (1.5, -0.15);\n        \\draw[blue, fill = blue] (1.5, 0) circle (1pt);\n        \\draw[blue, fill = blue] (0, 0) circle (1pt);\n        \\draw[] (0, 1) -- (-0.15, 1);\n        \\node[left] at (-0.15, 1) {$1$};\n        \\node[below] at (1.5, -0.15) {$1$};\n        \\draw[] (0.5, 0) -- (0.5, -0.15);\n        \\node[below] at (0.5, -0.15) {$\\frac{1}{2n}$};\n        \\node[below] at (1, -0.15) {$\\frac{1}{n}$};\n    \\end{tikzpicture}\n    \n    \\caption{Plot of $f_n$ on $K = [0, 1]$ from the above example.}\n    \\label{fig44}\n\\end{figure}\n\n\\begin{nproof}\n    Let $g_n = f_n - f$. We can then see that:\n    \\begin{enumerate}\n        \\item $g_n$ is continuous (the difference of two continuous functions is continuous by Theorem \\ref{thm:4.9})\n        \\item $g_n \\rightarrow 0$ pointwise for all $x \\in K$\n        \\item $g_n \\geq g_{n+1} \\geq 0$ for all $x \\in K$.\n    \\end{enumerate}\n    The goal will be to show that $g_n \\rightarrow 0$ uniformly on $K$. We will use the finite intersection property of compact sets to show this. Let $\\e > 0$. We will show that there exists $N$ such that $0 \\leq g_n(x) < \\e$ for all $n \\geq N$ and for all $x \\in K$. Note that it suffices to show that $g_N(x) < \\e$ for some $N$, as $g$ is monotone decreasing in $n$. Define $K_n = g_{n}^{-1}([\\e, \\infty))$ (i.e. the set of ``bad $x$s''). We are done if we are able to show that there exists a $N$ with $K_N = \\emptyset$. Since $g_n$ is conitnuous, $K_n$ is closed as $[\\e, \\infty)$ is closed. Since $K_n \\subset K$, $K$ is therefore compact as a closed subset of a compact set (Theorem \\ref{thm:2.35}). Additionally, we have that $K_{n+1} \\subset K_n$, as $g_{n+1} \\geq \\e$ implies that $g_n \\geq \\e$. Since $g_n \\rightarrow 0$ pointwise, given $x \\in K$, there exsits $N_x$ such that $x \\notin K_n$ for all $n \\geq N_x$ (as $g_n(x) < \\e$ for large enough $n$). We therefore have that $x \\notin \\bigcap_n K_n$ for all $x \\in K$. Then, applying the corollary to Theorem \\ref{thm:2.36}, we obtain that $K_N$ is empty. This means that for this $N$, $g_N^{-1}([\\e, \\infty)) = \\emptyset$, and hence $g_N^{-1}([0, \\e]) = K$, which is to say that $0 \\leq g_n(x) < \\e$ for all $x \\in K$. \\qed\n\\end{nproof}\n\n\\begin{definition}{$\\C(X)$ and the Supremum Norm}{7.14}\n    For a metric space $X$, define:\n    \\begin{align*}\n        \\C(X) = \\set{f: X \\mapsto \\CC \\text{ such that $f$ is bounded and continuous.}}\n    \\end{align*}\n    The \\textbf{supremum norm} of $f \\in \\C(X)$ is then defined as $\\norm{f} = \\sup_{x \\in X}\\abs{f(x)}$. We claim that $\\norm{f - g}$ defines a metric on $\\C(X)$, and we prove this assertion below. Thus, we have that:\n    \\begin{align*}\n        f_n \\rightarrow f \\text{ uniformly} &\\iff \\forall \\e > 0, \\exists N \\text{ such that } \\abs{f_n(x) - f(x)} < \\e \\; \\forall n \\geq N \\text{ and } \\forall x \\in X\n        \\\\ &\\iff \\forall \\e > 0, \\exists N \\text{ such that } \\norm{f_n(x) - f(x)} < \\e \\; \\forall n \\geq N\n        \\\\ &\\iff f_n \\rightarrow f \\text{ in the metric space $\\C(X)$}\n    \\end{align*}\n    We have hence ``metrized'' uniform convergence.\n\\end{definition}\n\\begin{ntheorem}{}{}\n    $\\norm{f - g}$ defines a metric on $\\C(X)$.\n\\end{ntheorem}\n\\begin{nproof}\n    We recall the three properties of a metric as per Definition \\ref{def:2.15}:\n    \\begin{enumerate}\n        \\item $d(f, g) = 0 \\iff f = g$\n        \\item $d(f, g) = d(g, f)$\n        \\item $d(f, g) \\leq d(f, h) + d(h, g)$\n    \\end{enumerate}\n    We now show that $\\norm{f - g}$ satisfies these three properties.\n    \\begin{enumerate}\n        \\item $\\norm{f - g} = 0$ means that $0 = \\sup_{x \\in X}\\abs{f(x) - g(x)} \\implies \\abs{f(x) - g(x)} = 0$ for all $x$, hence $f(x) = g(x)$. \n        \\item $\\norm{f - g} = \\sup_{x \\in X}\\abs{f(x) - g(x)} = \\sup_{x \\in X}\\abs{g(x) - f(x)} = \\norm{g - f}$\n        \\item We have that $\\abs{f(x) - g(x)} \\leq \\abs{f(x) - h(x)} + \\abs{h(x) - g(x)}$ for all $x \\in X$, so $\\norm{f - g} \\leq \\norm{f - h} + \\norm{h - g}$. \\qed\n    \\end{enumerate}\n\\end{nproof}\n\n\\noindent Note that sometimes $\\norm{f}$ is written as $\\norm{f}_\\infty$ as it is the $n \\rightarrow \\infty$ limit of the $L_p$ norm. See HW3Q3 for the proof that the supremum norm is the limit of the $L_p$ norm. \n\n\\begin{theorem}{}{7.15}\n    $\\C(X)$ is a complete metric space (every Cauchy sequence in $\\C(X)$ has a limit in $\\C(X)$).\n\\end{theorem}\n\\begin{nproof}\n    Let $\\set{f_n}$ be a Cauchy sequence in $\\C(X)$. Then, given $\\e > 0$, $\\exists N$ such that $m, n \\geq N$ implies $\\norm{f_m - f_n} = \\sup_{x \\in X}\\abs{f_m(x) - f_n(x)} < \\e$. By the Cauchy criterion (Theorem \\ref{thm:7.8}), $f_n \\rightarrow f$ for some $f$. What is left to show is that $f \\in \\C(X)$. $f$ is continuous as it is the uniform limit of continuous functions (Theorem \\ref{thm:7.12}). Additionally, $f$ is bounded as there exists $N_0$ such that $\\abs{f(x) - f_{N_{0}}(x)} < 1$ for all $x$, and hence $\\abs{f(x)} \\leq \\abs{f_{N_0}(x)} + \\abs{f(x) - f_{N_0}(x)} \\leq M_0 + 1$ for all $x$ where $M_0$ is the bound on $f_{N_0}(x)$ that exists as $f_{N_0} \\in \\C(X)$. As $f$ is continuous and bounded, we conclude that $f \\in \\C(X)$. \\qed\n\\end{nproof}\n\n\\subsection{Uniform Convergence and Integration}\n\\begin{theorem}{}{7.16}\n    Suppose $f_n \\in \\R_{\\alpha}[a, b]$ for all $n \\in \\NN$ and that $f_n \\rightarrow f$ uniformly on $[a, b]$. Then, $f \\in \\R_{\\alpha}[a, b]$, and:\n    \\begin{align*}\n        \\linf \\int_{a}^b f_n d\\alpha = \\int_a^b f d\\alpha\n    \\end{align*}\n\\end{theorem}\n\n\\newpage\n\\noindent In other words, the above Theorem tells us that we can interchange the integral with the limit if the sequence is uniformly convergent. Compare this to our earlier example with pointwise convergence, where such an interchange was not possible (as it yielded different values).\n\n\\begin{nproof}\n    First, we show that $f \\in \\R_{\\alpha}[a, b]$. Let $\\e > 0$. Since $f_n \\rightarrow f$ uniformly, there exists $N$ such that $\\abs{f_n(X) - f(x)} < \\e$ if $n \\geq N$ for all $x \\in [a, b]$. So, $f_n(x) - \\e < f(x) < f_n(x) + \\e$. Hence,\n    \\begin{align*}\n        \\lint{a}{b}(f_n - \\e)d\\alpha \\leq \\lint{a}{b}fd\\alpha \\leq \\uint{a}{b} fd\\alpha \\leq \\uint{a}{b}(f_n + \\e)d\\alpha \n    \\end{align*}\n    Since $f_n \\pm \\e \\in \\R_{\\alpha}[a, b]$, we have that:\n    \\begin{align*}\n        \\int_{a}^b (f_n - \\e)d\\alpha \\leq \\lint{a}{b}fd\\alpha \\leq \\uint{a}{b} fd\\alpha \\leq \\int_a^b(f_n + \\e)d\\alpha \n    \\end{align*}\n    Therefore:\n    \\begin{align*}\n        0 \\leq \\uint{a}{b} fd\\alpha - \\lint{a}{b} fd\\alpha \\leq \\int_a^b 2\\e d\\alpha \\implies \\uint{a}{b} fd\\alpha - \\lint{a}{b} fd\\alpha \\leq 2\\e(\\alpha(b) - \\alpha(a))\n    \\end{align*}\n    Since $\\e$ is arbitrary, we have that $\\uint{a}{b} fd\\alpha = \\lint{a}{b} fd\\alpha$ and hence $f \\in \\R_\\alpha[a, b]$.\n\n    Next, we show that $\\linf \\int_{a}^b f_n d\\alpha = \\int_a^b f d\\alpha$. To do this, we show that $\\abs{\\int_a^b fd\\alpha - \\int_a^bf_nd\\alpha}$ goes to 0 as $n \\rightarrow \\infty$. We have that:\n    \\begin{align*}\n        \\abs{\\int_a^b fd\\alpha - \\int_a^bf_nd\\alpha} = \\abs{\\int_a^b (f - f_n)d\\alpha} \\leq \\int_a^b\\abs{f - f_n}d\\alpha \\leq \\int_a^b \\e d\\alpha = \\e(\\alpha(b) - \\alpha(a))\n    \\end{align*}\n    Where in the first equality we use Linearity (Theorem \\ref{thm:6.12}), the first inequality we apply Theorem \\ref{thm:6.13}, and in the second inequality, we use that for any $\\e > 0$, there exists $N$ such that $\\abs{f - f_n} < \\e$ for $n \\geq N$. Since $\\e$ is arbitrary, we conclude that $\\linf \\int_{a}^b f_n d\\alpha = \\int_a^b f d\\alpha$. \\qed\n\\end{nproof}\n\n\\begin{ncorollary}{}{}\n    If $f_n \\in \\R_\\alpha[a, b]$ and $f(x) = \\sum_{n=1}^\\infty f_n(x)$ converges uniformly on $[a, b]$, then $\\int_a^b fd\\alpha = \\sum_{n=1}^\\infty \\int_a^b f_n d\\alpha$. That is to say, the infinite series and the integral can be interchanged.\n\\end{ncorollary}\n\n\\begin{nproof}\n    Let $S_n(x) = \\sum_{i=1}^n f_i(x)$. Then, $S_n(x) \\rightarrow f(x)$ uniformly by assumption, so:\n    \\begin{align*}\n        \\int_a^b fd\\alpha = \\linf \\int_a^b s_n d\\alpha = \\linf \\sum_{i=1}^n \\int_a^b f_i d\\alpha = \\sum_{i=1}^\\infty \\int_a^b f_i d\\alpha\n    \\end{align*}\n    Where the first equality follows from the previous theorem, and the second equality follows from the fact that a finite sum and integral can be interchanged by Linearity. \\qed\n\\end{nproof}\n\n\\subsection{Uniform Convergence and Differentiation}\nRecall Example \\ref{exam:7.5}, where we looked at the sequence of functions $f_n(x) = \\frac{\\sin n x}{\\sqrt{n}}$. We showed that $f_n \\rightarrow 0$ uniformly on $\\RR$, but we found in the example that $f_n'(x)$ does \\emph{not} converge. We are therefore motivated to find a condition that if a function converges and is differentiable, then $f_n'$ converges.\n\nAs a point of notation, note that for $a < b$ we denote $\\int_b^a f d\\alpha = -\\int_a^b fd\\alpha$. \n\n\\begin{theorem}{}{7.17}\n    Suppose:\n    \\begin{enumerate}\n        \\item $f_n$ is differentiable on $[a, b]$;\n        \\item $\\exists x_0 \\in [a, b]$ such that $f_n(x_0)$ converges as $n \\rightarrow \\infty$;\n        \\item $f_n'$ converges uniformly on $[a, b]$. \n    \\end{enumerate}\n    Then, there exists $f$ such that $f_n \\rightarrow f$ uniformly on $[a, b]$, and:\n    \\begin{align*}\n        \\linf f_n'(x) = f'(x) \\; \\forall x \\in [a, b]\n    \\end{align*}\n\\end{theorem}\n\\noindent A couple remarks before we move to the proof. First, we note that hypothesis (b) seems strange; why would we require convergence $f_n$ at a single point? This has to do with the fact that in differentiating, we lost our constants. For example, let $f_n(x) = n$ as the simplest example. In this case, we have that $f_n$ is differentiable everywhere (with derivative zero everywhere on $[a, b]$) and that $gfn'$ uniformly converges (it is just the sequence of the zero function). However, $f_n$ does not even converge!\n\nNote that we can and will assume that $f_n(x_0) \\rightarrow 0$ at the specified $x_0$; if this is not true, we can simply replace $f_n(x)$ by $f_n(x) - f_n(x_0)$.\n\n\\begin{nproof}\n    The proof of the above theorem is not so trivial. We will therefore prove a weaker theorem. Namely, we add a fourth hypothesis (d) that $f_n'$ is continuous on $[a, b]$. The proof of the stronger/original theorem can be found in Rudin.\n    \n    First, by (c) there exists a $g$ such that $f_n' \\rightarrow g$ uniformly on $[a, b]$ (and also on any subinterval of $[a, b]$). Furthermore, by (d) and Theorem \\ref{thm:7.12}, $g$ is continuous. \n    \n    Next, applying Theorem \\ref{thm:7.16} (to either $[x_0, x]$ or $[x, x_0]$) we have that:\n    \\begin{align*}\n        \\int_{x_0}^x f_n'(t) \\rightarrow \\int_{x_0}^x g(t) dt = f(x)\n    \\end{align*}\n    Then applying the Fundamental theorem of calculus (Theorem \\ref{thm:6.21}), we have $f_n(x) - f_n(x_0) \\rightarrow f(x) \\text{ and } f'(x) = g(x)$. But we also assume that $f_n(x_0) \\rightarrow 0$, so $f_n(x) \\rightarrow f(x)$ and $f_n'(x) \\rightarrow g(x) = f'(x)$. So, we have shown pointwise convergence of $f_n$ to $f$! We have obtained that $\\linf f_n'(x) = f'(x)$ for all $x \\in [a, b]$. Finally, we show $f_n \\rightarrow f$ uniformly on $[a, b]$. We have that:\n    \\begin{align*}\n        \\abs{f(x) - f_n(x)} = \\abs{\\int_{x_0}^x g(t)dt - \\int_{x_0}^x f_n'(t) dt + f_n(x_0)} &\\leq \\int_{x_0}^x \\abs{g(t) - f_n'(t)}dt + \\abs{f_n(x_0)}\n        \\\\ &< \\int_{x_0}^x \\frac{\\e}{2(b-a)}dt + \\frac{\\e}{2} \\leq \\frac{\\e}{2(b-a)}(b-a) + \\frac{\\e}{2} = \\e\n    \\end{align*}\n    Where we apply Theorem \\ref{thm:6.13} for the first inequality, the fact that $f_n'(t) \\rightarrow g$ and $f_n(x_0) \\rightarrow 0$ in the second last inequality, and Theorem \\ref{thm:6.12}(d) in the last inequality. \\qed\n\\end{nproof}\n\n\\begin{theorem}{}{7.18}\n    There exists a continuous function $f: \\RR \\mapsto \\RR$ such that $f'(x)$ does not exist for any $x \\in \\RR$.\n\\end{theorem}\n\n\\noindent The proof of the above theorem will follow by the construction of an ``infinitely spiky'' real function. Though this might seem like a very pathological counterexample, there are actually many examples of non-differentiable phenomena in mathematics. Looking at the field of probability, we find that brownian motion, brownian maps, and discrete exploration processes (to name a few) all have this property. A visualization of the brownian map, as well as other beautiful probability pictures can be found here \\url{https://secure.math.ubc.ca/Links/Probability/pages/pic_gallery.html}.\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale=1.5]\n        \\draw[-latex, very thick] (0, 0) -- (0, 2);\n        \\draw[latex-latex, very thick] (-2.5, 0) -- (2.5, 0);\n        \\draw[blue] (-2, 0) -- (-1.5, 1) -- (-1, 0) -- (-0.5, 1) -- (0, 0) -- (0.5, 1) -- (1, 0) -- (1.5, 1) -- (2, 0);\n        \\draw[] (0, 1) -- (0.15, 1);\n        \\draw[right] node at (0.1, 1) {$1$};\n        \\draw[below] node at (0, 0) {$0$};\n        \\draw[below] node at (1, 0) {$1$};\n        \\draw[below] node at (-1, 0) {$-1$};\n\n\n    \\end{tikzpicture}\n    \\caption{Plot of the $\\phi$ function defined in the proof of Theorem \\ref{thm:7.18}.}\n    \\label{fig45}\n\\end{figure}\n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[scale=0.25]{Images/7-18-graph.png}\n    \n    \\caption{Desmos visualization of the nowhere-differentiable $f$ constructed in the proof of Theorem \\ref{thm:7.18}. Note that a partial sum $(N = 10)$ of the series that $f$ is defined to be is shown, as the infinite series is impossible to plot. Readers can play around the function with themselves at \\url{https://www.desmos.com/calculator/onhkmblgo6}. There is a notion that $f$ is ``infinitely spiky'', no matter how much one is to zoom into the above graph.}\n    \\label{fig46}\n\\end{figure}\n\n\\begin{nproof}\n    Define $\\phi: \\RR \\mapsto \\RR$ by $\\phi(x) = \\abs{x}$ for $-1 \\leq x \\leq 1$ and $\\phi(x + 2) = \\phi(x)$ for all $x \\in \\RR$. (See figure \\ref{fig45} above). Then, $\\phi$ is continuous; moreover, it is Lipschiz continuous, with $\\abs{\\phi(s) - \\phi(t)} \\leq \\abs{s - t}$ for all $s, t \\in \\RR$ (with equality where there are no integers between $s, t$). Define $f(x) = \\sum_{n=0}^\\infty \\left(\\frac{3}{4}\\right)^n \\phi(4^nx)$. The series converges uniformly on $\\RR$ by Theorem \\ref{thm:7.10}, since $0 \\leq \\left(\\frac{3}{4}\\right)^n \\phi(4^nx) \\left(\\frac{3}{4}\\right)^n$ and $\\sum_n\\left(\\frac{3}{4}\\right)^n$ converges (it is a geometric series with $r < 1$). Hence, $f$ is continuous as it is a uniform limit of a continuous function (Theorem \\ref{thm:7.12}). We now prove that $f'(x)$ does not exists for any $x \\in \\RR$; let us then fix $x$. It suffices to find $\\delta_m \\rightarrow 0$ such that:\n    \\begin{align*}\n        \\abs{\\frac{f(x + \\delta_m) - f(x)}{\\delta_m}} \\rightarrow \\infty \\text{ as } m \\rightarrow \\infty.\n    \\end{align*}\n    We then choose $\\delta_m = \\pm \\frac{1}{2}\\frac{1}{4^m}$. We choose the sign of $\\delta_m$ depending on the choice of $x$ as follows. At most one of $(4^m x - \\frac{1}{2}, 4^mx)$ and $(4^mx, 4^mx + \\frac{1}{2})$ contains an integer. We choose the sign such that no integer lies between $4^m x$ and $4^m(x + \\delta_m)$. Note that we may choose a differnet sign for each $m$. \n    \n    Next, we make the observation that $\\abs{\\phi(4^m(x + \\delta_m)) - \\phi(4^mx)} = 4^mx$; this holds as for the difference between two $\\phi(x)$ values at two points without an integer between them is just the difference between the $x$ values. Looking back at our definition of $\\delta_m$, we then see that $\\abs{\\phi(4^m(x + \\delta_m)) - \\phi(4^mx)} = \\frac{1}{2}$.\n\n    Furthermore, we see that if $n > m$, we have that $\\phi(4^n(x + \\delta_m)) - \\phi(4^nx \\pm \\frac{1}{2}4^{n-m}) = \\phi(4^nx)$ as $\\frac{1}{2}4^{n-m}$ is an even integer and $\\phi$ is 2-periodic. This leads us to conclude that $\\phi(4^n(x + \\delta_m)) - \\delta(4^nx) = 0$ if $n > m$. Given $m$, then define:\n    \\begin{align*}\n        \\gamma_n = \\frac{\\phi(4^n(x + \\delta_m)) - \\delta(4^nx)}{\\delta_m}\n    \\end{align*}\n    Then, $\\gamma_n = 0$ if $n > m$, $\\abs{\\gamma_m} = \\abs{\\frac{4^m\\delta_m}{\\delta_m}} = \\abs{4^m} =4^m$, and if $0 \\leq n < m$, $\\abs{\\gamma_n} \\leq \\frac{1}{\\delta_m}\\abs{4^n(x + \\delta_m) - 4^nx} = \\frac{1}{\\abs{\\delta_m}}\\abs{4^n\\delta_m} = 4^n$. Finally, we have that:\n    \\begin{align*}\n        \\abs{\\frac{f(x + \\delta_m) - f(x)}{\\delta_m}} = \\abs{\\sum_{n=0}^\\infty \\left(\\frac{3}{4}\\right)^n\\gamma_m} = \\abs{\\sum_{n=0}^m \\left(\\frac{3}{4}\\right)^n\\gamma_m} &\\geq \\left(\\frac{3}{4}\\right)^m\\abs{\\gamma_m} - \\sum_{n=0}^{m-1}\\left(\\frac{3}{4}\\right)^n\\abs{\\gamma_n}\n        \\\\ &\\geq \\left(\\frac{3}{4}\\right)^m4^m - \\sum_{n=0}^{m-1}\\left(\\frac{3}{4}\\right)^n4^n\n        \\\\ &= 3^m - \\sum_{n=1}^{m-1}3^n\n        \\\\ &= 3^m - \\frac{3^m - 1}{3 - 1}\n        \\\\ &= \\frac{1}{2}(3^m + 1)\n    \\end{align*}\n    Where the second equality follows as all terms $n > m$ are zero, the first inequality follows by the reverse triangle inequality, the second inequality follows by the bounds on $\\abs{\\gamma_n}$, and the third-to-last equality is the geometric sum formula. As $m \\rightarrow \\infty$, the difference quotient goes to infinity, and we therefore conclude that $f$ is differentiable nowhere. \\qed\n\\end{nproof}\n\n\\subsection{Equicontinuous Families of Functions}\n\\setcounter{rudin}{21}\n\\begin{definition}{Equicontinuity}{7.22}\n    A family $\\mathcal{F}$ of functions on $E$ (that is, a possibly finite, countable, or uncountable set of functions on $E$) is \\textbf{equicontinuous} on $E$ if for every $\\e > 0$, there exists $\\delta > 0$ such that if $f \\in \\mathcal{F}$ and $x, y \\in E$ with $d(x, y) < \\delta$, then $\\abs{f(x) - f(y)} < \\e$. Note that the functions $f \\in \\mathcal{F}$ are either real or complex valued.\n\\end{definition}\n\\noindent The above definition of equicontinuity is essentially an even stronger version of uniform continuity; the $\\delta$ works not just for all $x$ and $y$ for a single $f$, but for all $x$ and $y$ for all of the $f$s in $\\mathcal{F}$. If $\\mathcal{F} = \\set{f}$, then this is just uniform continuity.\n\n\\begin{ntheorem}{}{}\n    \\begin{enumerate}\n        \\item If a family $\\mathcal{F}$ of functions on $E$ is equicontinuous, then every $f \\in \\mathcal{F}$ is uniformly continuous on $E$.\n        \\item Any finite family $\\mathcal{F} = \\set{f_1, \\ldots f_n}$ of uniformly continuous functions on $E$ is equicontinuous.\n    \\end{enumerate}\n\\end{ntheorem}\n\\begin{nproof}\n    \\begin{enumerate}\n        \\item The claim follows immediately from the definition.\n        \\item Let $\\e > 0$. Then, by the uniform continuity of each $f_i \\in \\mathcal{F}$, there exists $\\delta_i$ such that if $d(x, y) < \\delta_i$, then $\\abs{f_i(x) - f_i(y)} < \\e$. Taking $\\delta = \\min{\\delta_1, \\ldots, \\delta_n}$, we have that for any $f \\in \\mathcal{F}$, if $d(x, y) < \\delta$ then $\\abs{f(x) - f(y)} < \\e$. Hence $\\mathcal{F}$ is equicontinuous. \\qed\n    \\end{enumerate}\n\\end{nproof}\n\n\\begin{nexample}{}{}\n    Let $\\mathcal{F} = \\set{f_1, f_2, \\ldots}$ with $f_n(x) = \\frac{\\sin (nx)}{\\sqrt{n}}$ for $x \\in [0, 1] \\in E$. Then, $\\mathcal{F}$ is equicontinuous.\n\\end{nexample}\n\\begin{nproof}\n    We have that $\\abs{f_n(x) - f_n(y)} = \\frac{1}{\\sqrt{n}}\\abs{\\sin(nx) - \\sin(ny)} \\leq \\frac{2}{\\sqrt{n}}$ for all $x, y \\in E$. Let $\\e > 0$. Choose $N$ such that $\\frac{2}{\\sqrt{n}} < \\e$ if $n > N$. Since the remaining $f_n$ (i.e. $\\set{f_1, \\ldots, f_{n}}$) are a finite collection of uniformly continuous functions (they are uniformly continuous by Theorem \\ref{thm:4.19}, as they continuous functions on a closed and bounded interval), by the above theorem, $\\set{f_1, \\ldots f_{n}}$ is equicontinuous. So, there exists a $\\delta$ such that for $n \\geq N$ and $\\abs{x - y} < \\delta$, $\\abs{f_n(x) - f_n(y)} < \\e$. We then have that for any $n \\in \\NN$ and for any $x, y \\in E$ with $\\abs{x - y} < \\delta$, then $\\abs{f_n(x) - f_n(y)} < \\e$. We conclude that $\\mathcal{F}$ is equicontinuous. \\qed\n\\end{nproof}\n\n\\begin{ntheorem}{ (Problem 7.16)}{}\n    Let $\\set{f_n}$ be an equicontinuous sequnece of functions such that $f_n: K \\mapsto \\CC$ with $K$ compact. Suppose there is a pointwise limit $f(x) = \\linf f_n(x)$ that exists for all $x \\in K$. Then, $f_n \\rightarrow f$ uniformly on $K$.\n\\end{ntheorem}\n\\begin{nproof}\n    We use an ``$\\frac{\\e}{3}$ argument''. Let $\\e > 0$. Then, choose $\\delta > 0$ such that $\\abs{f_n(x) - f_n(y)} < \\frac{\\e}{3}$ for all $n$ and for all $x, y$ such that $d(x, y) < \\delta$ (such a choice is possible by the equicontinuity of the sequence). Take an open cover of $K$ by considering the set of neighbourhoods of radius $\\delta$ around every point $x \\in K$. Since $K$ is compact, the open cover $\\set{N_{\\delta}(x): x \\in K}$ has a finite subcover $\\set{N_\\delta(x_1), \\ldots, N_\\delta(x_k)}$. Thus, given $x \\in K$, there exists $x_j$ such that $x \\in N_\\delta(x_j)$ and hence $d(x_j, x) < \\delta$. Therefore by the triangle inequality:\n    \\begin{align*}\n        \\abs{f_n(x) - f_m(x)} &\\leq \\abs{f_n(x) - f_n(x_j)} + \\abs{f_n(x_j) - f_m(x_j)} + \\abs{f_m(x_j) - f_m(x)}\n        \\\\ &< \\frac{\\e}{3} + \\abs{f_n(x_j) - f_m(x_j)} + \\frac{\\e}{3}\n    \\end{align*}\n    where the last inequality follows from the equicontinuity. For each $i \\in \\set{1, \\ldots k}$, we know that $\\set{f_n(x_j)}$ is a convergent sequence as $f_n$ converges pointwise by assumption. Hence, it is a Cauchy sequence. Therefore, there exists a $N_i$ such that $m, n \\geq N_i$ implies $\\abs{f_n(x_i) - f_m(x_i)} < \\frac{\\e}{3}$. Take $N = \\max{N_1, \\ldots, N_k}$. Then, we have that $m, n \\geq N$ implies:\n    \\begin{align*}\n        \\abs{f_n(x) - f_m(x)} < \\frac{\\e}{3} + \\frac{\\e}{3} + \\frac{\\e}{3} = \\e.\n    \\end{align*}\n    So, $f_n$ satisfies the Cauchy criterion for uniform convergence, and hence $\\set{f_n}$ converges uniformly on $K$. \\qed\n\\end{nproof}\n\n\\setcounter{rudin}{23}\n\n\\begin{theorem}{}{7.24}\n    If $f_n: K \\mapsto \\CC$ is continuous, $K$ is compact, and $f_n \\mapsto f$ uniformly on $K$, then $\\set{f_n}$ is equicontinuous.\n\\end{theorem}\n\\begin{nproof}\n    We again use an ``$\\frac{\\e}{3}$ argument''. Let $\\e > 0$. Since $f_n \\rightarrow f$ uniformly, we have that there exists $N$ such that $m, n \\geq N$ implies $\\abs{f_n(x) - f_m(x)} < \\frac{\\e}{3}$ for all $x \\in K$. Also, since $K$ is compact, each $f_i$ is unformly continuous, so $\\set{f_1, \\ldots f_N}$ is equicontinuous for any $N \\in \\NN$ (as it is a finite set of uniformly continuous functions). Hence, there exists $\\delta > 0$ such that $\\abs{f_i(x) - f_i(y)} < \\frac{\\e}{3}$ if $d(x, y) < \\delta$ and $i \\leq N$. Finally, for $n > N$, we habe that:\n    \\begin{align*}\n        \\abs{f_n(x) - f_n(y)} \\leq \\abs{f_n(x) - f_N(x)} + \\abs{f_N(x) - f_N(y)} + \\abs{f_N(y) - f_n(y)} < \\frac{\\e}{3} + \\frac{\\e}{3} + \\frac{\\e}{3} = \\e\n    \\end{align*}\n    where the first/third $\\frac{\\e}{3}$s come from uniform convergence and the second from the equicontinuity. We conclude that $\\set{f_n}$ is equicontinuous. \\qed\n\\end{nproof}\n\n\\begin{nexample}{}{}\n    We here discuss a set of functions which is not equicontinuous, by returning to a prior example. Let $K = [0, 1]$, and define:\n    \\begin{align*}\n        f_n(x) = \\begin{cases}\n            2nx & 0 \\leq x < \\frac{1}{2n}\n            \\\\ 2 - 2nx & \\frac{1}{n} \\leq x \\leq \\frac{1}{n}\n            \\\\ 0 & \\frac{1}{n} < x \\leq 1\n        \\end{cases}.\n    \\end{align*}\n    See Figure \\ref{fig44} for a visualization. We have that $\\set{f_n}$ obeys $\\abs{f_n(x)} \\leq 1$ for all $x \\in [0, 1]$, but that $\\set{f_n}$ is not equicontinuous, as $\\abs{f_n(\\frac{1}{2^n} - f_n(0)} = 1 - 0 = 1$ for all $n$. We can get as close as we like to $0$, but the difference will remain large. Also, there is no subsequence of $\\set{f_n}$ that can be uniformly convergent on $[0, 1]$, as $f_n(x) \\rightarrow 0$ for all $x \\in [0, 1]$ pointwise but $f_n(\\frac{1}{2n}) = 1$ for all $n$. $f_n(x)$ ``stays far'' from the limit. The takeaway message is that a sequence that converges pointwise but is not equicontinuous is not guaranteed to have a uniformly convergent subsequence. This is motivation for the later Theorem \\ref{thm:7.25}, which gives crtieria for a sequence of functions having a uniformly convergent subsequence.\n\\end{nexample}\n\n\\setcounter{rudin}{18}\n\n\\begin{definition}{Pointwise/Uniform Bounded Functions}{7.19}\n    $\\set{f_n}$ is \\textbf{pointwise bounded} on $E$ if there exists a $\\phi: E \\mapsto \\RR$ such that $\\abs{f_n(x)} < \\phi(x)$ for all $x \\in E$ and for all $n \\in \\NN$. $\\set{f_n}$ is \\textbf{uniformly bounded} on $E$ if there exists $M$ such that $\\abs{f_n(x)} \\leq M$ for all $x \\in E$ and all $n \\in \\NN$.\n\\end{definition}\n\n\\begin{nexample}{}{}\n    Let $f_n(x) = \\frac{1}{x} + \\frac{1}{n}$. Then, $\\set{f_n}$ is pointwise bounded, by (for example) $\\phi(x) = \\frac{1}{x} + 2$. But, it is not uniformly bounded, as $\\frac{1}{x}$ grows arbitrarily large as $x \\rightarrow 0$. \n\\end{nexample}\n\n\\setcounter{rudin}{22}\n\\begin{theorem}{Selection Theorem}{7.23}\n    Suppose $f_n : E \\mapsto \\CC$ is pointwise bounded on a countable set $E$. Then, some subsequence $\\set{f_{n_k}}$ of $\\set{f_n}$ is pointwise convergent on $E$; that is to say, $\\lim_{k \\rightarrow \\infty} f_{n_k}(x)$ exists for all $x \\in E$. \n\\end{theorem}\n\\noindent Note that the above theorem plays a large role in probability!\n\n\\begin{nproof}\n    We invoke a ``diagonal argument''. Let $E = \\set{x_1, x_2, \\ldots}$. Consider the sequence $\\set{f_n(x_1)}$. We have that it is pointwise bounded by hypothesis, so there exists a subsequence $\\set{f_{1_k}}$ such that $\\linf f_{1_n}(x_1)$ converges. (Theorem \\ref{thm:2.42}). We can apply the same logic for $x_2, x_3, \\ldots$ in term, such that the proceeding sequence is a subsequence of the former. In other words, we form the array:\n    \\begin{align*}\n        \\begin{array}{ccccc}\n            S_1: & f_{1_1} & f_{1_2} & f_{1_3} & \\ldots \\\\\n            S_2: & f_{2_1} & f_{2_2} & f_{2_3} & \\ldots \\\\\n            S_3: & f_{3_1} & f_{3_2} & f_{3_3} & \\ldots \\\\\n            & & \\vdots & &\n        \\end{array}\n    \\end{align*}\n    In doing so, we have that $S_1$ converges on $x_1$, $S_2$ is a subsequence of $S_1$ that converges on $x_1$ and $x_2$, $S_3$ is a subsequence of $S_2$ that converges on $x_1$ and $x_2$ and $x_3$ and so on. Then, we consider the sequence formed by the diagonal of the above array, with $S: f_{1_1}, f_{2_2}, f_{3_3}, \\ldots$. This is a subsequence of our original sequence $f_n$. If we fix some $N$, then this subsequence is a subsequence of $S_n$ for $n \\geq N$ (as $S$ is eventually a subsequence of each $S_n$), so it converges on the same points that $S_n$ does, namely, $x_1, \\ldots, x_n$. But this is true for every $n \\in \\NN$, so the subsequence $S$ converges for $x_i \\in E$ for every $i \\in \\NN$. \\qed\n\\end{nproof}\n\n\\begin{nlemma}{ (Problem 2.25)}{}\n    If $K$ is compact, then $K$ has a countable dense subset $E \\subset K$ (i.e. $\\overline{E} = E \\cup E' = K$). Alternatively, for all $x \\in K$, there exists $r > 0$ such that there exists $p \\in E$ such that $d(p, x) < r$. In other words, $K$ is separable. \n\\end{nlemma}\n\n\\begin{nproof}\n    For $n \\in \\NN$, $\\set{N_{1/n}(p)}_{p \\in K}$ is an open cover. So, it has a finite subcover $\\set{N_{1/n}(p)}_{p \\in E_n}$ where $E_n \\subset K$ is finite. Let $E = \\bigcup_{n=1}^\\infty E_n$, then $E$ is at most countable (Theorem \\ref{thm:2.12}). To see that it is dense, let $x \\in K$, and $r > 0$. Then, choose $n_0$ such that $\\frac{1}{n_0} < r$. We can then find $p_0 \\in E_{n_0} \\subset E$ such that $x \\in N_{1/n_0}(p_0)$ as $E_{n_0}$ is an open cover of $K$. Then, $d(x, p_0) < \\frac{1}{n_0} < r$. Hence, $E$ is dense. \\qed\n\\end{nproof}\n\n\\setcounter{rudin}{24}\n\\begin{theorem}{Arzela-Ascoli}{7.25}\n    Suppose $K$ is compact, and that $\\mathcal{F} = \\set{f_n} \\subset \\C(K)$ is equicontinuous and pointwise bounded. Then,\n    \\begin{enumerate}\n        \\item $\\set{f_n}$ is uniformly bounded.\n        \\item $\\set{f_n}$ has a uniformly convergent subsequence (i.e. a subsequence that converges in $\\C(K)$).\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{nproof}\n    \\begin{enumerate}\n        \\item The goal is to find $M$ such that $\\abs{f_n(x)} \\leq M$ for all $n \\in \\NN$ and for all $x \\in K$. Let $\\e > 0$ (though we can take $\\e = 0$ for this proof of part (a)). Since $\\mathcal{F}$ is equicontinuous, we have that there exists $\\delta > 0$ such that $d(x, y) < \\delta$ implies $\\abs{f_n(x) - f_n(y)} < \\e$ for all $n$. $K$ is compact, we can cover $K$ with balls of radius $\\delta$ around each point in $K$ and then take a finite subcover; i.e. there exists a finite set $\\set{p_1, \\ldots, p_r} \\in K$ such that $\\set{N_\\delta(p_i)}_{i = 1, \\ldots, r}$ covers $K$. For each $i$, $\\set{f_n(p_i)}_n$ is bounded, that is, $\\abs{f_n(p_i)} \\leq M_i$ for all $n$. Let $M_0 = \\max{M_1, \\ldots, M_n}$. Given $x \\in K$, choose $p_i$ such that $x \\in N_\\delta(p_i)$. Then:\n        \\begin{align*}\n            \\abs{f_n(x)} \\leq \\abs{f_n(p_i)} + \\abs{f_n(x) - f_n(p_i)} < M_i + \\e \\leq M_0 + \\e\n        \\end{align*} \n        letting $M = M_0 + \\e$, we see that $\\set{f_n}$ is a uniformly bounded.\n        \\item Our goal is to construct a uniformly convergent subsequence. We do this in three steps. First, we construct a subsequence (we will show it is uniformly convergent afterwards!). By the above Lemma, $K$ has a countable dense subset $E$. By Theorem \\ref{thm:7.23}, there exists a subsequence $\\set{f_{n_i}}$ such that $\\lim_{i \\rightarrow \\infty} f_{n_i}(x)$ exists for all $x \\in E$. Write $g_i = f_{n_i}$.\n        \n        Secondly, we set up the argument to show uniform convergence of the subsequence constructed in the first step. Let $\\e > 0$. By the equicontinuity assumption, there exists $\\delta > 0$ such that $d(x, y) < \\delta$ implies $\\abs{g_i(x) - g_i(y)} < \\frac{\\e}{3}$ for all $i$. Consider $\\set{N_\\delta(p)}_{p \\in E}$, which covers $K$ since $E$ is dense. By the compactness of $K$, there exists a finite subset $\\set{N_{\\delta}(x_1), \\ldots, N_\\delta(x_m)}$ with $x_i \\in E$. Hence, given $x \\in K$, there exists $x_s$ such that $d(x, x_s) < \\delta$. \n\n        For the third step, we complete the proof with an ``$\\frac{\\e}{3}$ argument''. Using the triangle inequality, we have that:\n        \\begin{align*}\n            \\abs{g_i(x) - g_j(x)} &\\leq \\abs{g_i(x) - g_i(x_s)} + \\abs{g_i(x_s) - g_j(x_s)} + \\abs{g_j(x_s) - g_j(x)}\n            \\\\ &< \\frac{\\e}{3} + \\abs{g_i(x_s) - g_j(x_s)} + \\frac{\\e}{3}\n        \\end{align*}\n        where the last inequality follows from the arguments in step 2. For the second term, we consider that for $s = 1, \\ldots, m$, we can choose $N_s$ such that $\\abs{g_j(x_s) - g_i(x_s)} < \\frac{\\e}{3}$ for $i, j \\geq N_s$ (this choice of $N_s$ is possible as $\\set{g_n(x_s)})$ converges. There are finitely many $N_s$s, so let $N = \\max{N_1, \\ldots, N_m}$. Then, we have that:\n        \\begin{align*}\n            \\abs{g_i(x) - g_j(x)} < \\frac{\\e}{3} + \\frac{\\e}{3} + \\frac{\\e}{3} = \\e    \n        \\end{align*}\n        for $i, j \\geq N$ and for all $x \\in K$. Hence, $\\set{g_i}$ converges uniformly on $K$. \\qed\n    \\end{enumerate}\n\\end{nproof}\n\n\\subsection{The Stone-Weierstrass Theorem}\n\n\\begin{theorem}{Weierstrass}{7.26}\n    Let $f: [a, b] \\mapsto \\RR$ be continuous. Then, there exists polynomials $P_n$ such that $P_n \\rightarrow f$ uniformly on $[a, b]$.\n\\end{theorem}\n\\noindent Note that it will suffice to consider the case where $[a, b] = [0, 1]$; we can get to arbitrary $[a, b]$ to $[0, 1]$ by a change of variable, and the composition of apolynomial with a change of variable is still a polynomial.\n\n\\noindent Note that our proof will take a different angle from Rudin's proof of the theorem; we shall be exploring the proof by Bernstein. However, before we begin the proof, we will need to establish some basic background in probability.\n\n\\begin{ndef}{: Bernoulli Trials}{}\n    A \\textbf{Bernoulli trial} is a random experiment with a success outcome of probablity $p$ and a failure outcome with probability $1 - p$ (here, $p \\in [0, 1]$ is fixed). Consider $n$ independent Bernoulli trials (where each experiment does not affect any of the others) and let $S_n$ be the number of successes. Then, we have that:\n    \\begin{align*}\n        p_m = P(S_n = m) = \\binom{n}{m}p^m(1-p)^{n-m} \\quad (m = 0, 1, \\ldots, n).\n    \\end{align*}\n    Also note that:\n    \\begin{align*}\n        \\sum_{m=0}^np_m = [p+(1-p)]^n = 1^n = 1\n    \\end{align*}\n\\end{ndef}\n\n\\begin{ndef}{: Random Variables}{}\n    A \\textbf{random variable} is a function $X: \\set{0, 1, \\ldots n} \\mapsto \\RR$. \n\\end{ndef}\n\\noindent For example, $S_n$ is the identity function, with $X(m) = S_n(m) = m$. \n\n\\begin{ndef}{: Expectation}{}\n    The \\textbf{expectation} of a random variable $X$, denoted $EX$, is defined as:\n    \\begin{align*}\n        EX = \\sum_{m=0}^n X(m)p_m\n    \\end{align*}\n\\end{ndef}\n\\noindent We can interpret the expectation of $X$ as the sum over the values of $X$, weighted by the likelihoods. As an example, we have that:\n\\begin{align*}\n    ES_n = \\sum_{m=0}^n S_n(m)p_m = \\sum_{m=0}^n mp_m = \\sum_{m=0}^n m\\binom{n}{m}p^m(1-p)^{n-m} = \\ldots = np\n\\end{align*}\n\n\\begin{ndef}{: Variance \\& Standard Deviation}{}\n    The \\textbf{variance} of a random variable $X$, denoted $\\text{Var}(X)$, is defined as:\n    \\begin{align*}\n        \\text{Var}(X) = E[(X - EX)^2] = E(X^2) - (EX)^2.\n    \\end{align*}\n    The \\textbf{standard deviation}of $X$, denoted by $\\sigma_x$, is then defined as $\\sigma_x = \\sqrt{\\text{Var}(X)}$.\n\\end{ndef}\n\\noindent For example, $\\text{Var}(S_n) = E(S_n^2) - (ES_n)^2 = np(1-p)$, and $\\sigma_{S_n} = \\sqrt{np(1-p)}$. \n\n\\begin{ndef}{: Proportion of Successes}{}\n    Define $X_n$ to be the \\textbf{proportion of successes} in $n$ independent Bernoulli trials, with $X_n = \\frac{1}{n}S_n$. Then, we have that $EX_n = \\frac{1}{n}np = p$, $\\text{Var}(X_n) = \\text{Var}(\\frac{1}{n}S_n) = \\frac{1}{n^2}\\text{Var}(S_n)= \\frac{1}{n}p(1-p)$. We then have that $\\sigma_{X_n} = \\sqrt{\\frac{p(1-p)}{n}}$.\n\\end{ndef}\n\\noindent Analyzing the standard deviation $\\sigma_{X_n}$, we see that as we do more trials ($n$ increases), the fluctuation of the proportion of successes gets smaller. This phenomena is known as the \\emph{Law of large numbers}, which states that the proportion of successes should converge to the probability of success in a single trial. $\\sigma_{X_n} \\rightarrow 0$ as $n \\rightarrow \\infty$ tells us this fact. \n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale=1.5]\n        \\draw[blue, thick, smooth, samples = 100, domain=0:2, variable = \\x] plot(\\x, {exp(-((\\x)-1)*((\\x)-1)*5)});\n        \\draw[-latex, very thick] (0, 0) -- (2, 0);\n        \\draw[-latex, very thick] (0, 0) -- (0, 2);\n        \\node[left] at (-0.15, 1.9) {$P(X_n = \\frac{m}{n})$};\n        \\node[below] at (1.9, -0.15) {$X_n = \\frac{m}{n}$};\n        \\draw[] (1, 0) -- (1, -0.15);\n        \\node[below] at (1, -0.15) {$p$};\n        \\draw[<->] (1, 0.65) -- (1.3, 0.65);\n        \\draw[<->] (1, 0.65) -- (0.7, 0.65);\n        \\node[below] at (1.2, 0.65) {$\\sigma_{X_n}$};\n        \\node[below] at (0.85, 0.65) {$\\sigma_{X_n}$};\n    \\end{tikzpicture}\n    \n    \\caption{Visualization of how $P(X_n)$. Since $\\sigma_{X_n}$ (the width of the distribution) scales as $\\frac{1}{\\sqrt{n}}$, as $n$ grows, the distribution becomes more sharply peaked around $p$.}\n    \\label{fig47}\n\\end{figure}\n\n\\begin{ntheorem}{: Chebychev's Inequality}{}\n    $P(\\abs{X_n - p} > \\delta) \\leq \\frac{1}{\\sigma^2}p(1-p)\\frac{1}{n}$. Note that this inequality can be generalized to random variables in general, but here it suffices to consider the inequality just for the case of $X_n$.\n\\end{ntheorem}\n\\begin{nproof}\n    We have that:\n    \\begin{align*}\n        P(\\abs{X_n - p} > \\delta) = \\sum_{m: \\abs{\\frac{m}{n} - p} > \\sigma}p_m \\leq \\sum_{m=0}^n \\abs{\\frac{\\frac{m}{n} - p}{\\sigma}}^2p_m = \\frac{1}{\\sigma^2}\\sum_{m=0}^n \\left(\\frac{m}{n} - p\\right)^2p_m &= \\frac{1}{\\sigma^2}\\text{Var}(X_n) \n        \\\\ &= \\frac{1}{\\sigma^2}p(1-p)\\frac{1}{n}.\n    \\end{align*}\n    where in the first inequality we use the fact that $\\abs{\\frac{\\frac{m}{n} - p}{\\sigma}}^2 \\geq 1$ and we hence add non-negative terms to the sum, and in the second to last equality we invoke the definition of the variance. \\qed\n\\end{nproof}\n\\noindent With the machinery of basic probability established, we move to the proof of the Weierstrass theorem.\n\n\\begin{nproof}\n    Take $p = x \\in [0, 1]$. We then have that $p_m = \\binom{n}{m}x^m(1-x)^{n-m}$. Let $P_n(x) = Ef(x_n) = \\sum_{m=0}^n f(\\frac{m}{n})p_m$ (why? as we take $n$ large, we have that $x_n \\rightarrow x$, so $f(x_n) \\rightarrow f(x)$, showing that $P_n(x)$ approximates $f(x)$ well). We note that $\\sum_{m=0}^n f(\\frac{m}{n})p_m$ is a polynomial in $x$ of degree $n$. This is our candidate for a uniformly convergent polynomial. We then have that:\n    \\begin{align*}\n        f(x) - P_n(x) = \\sum_{n=0}\\left(f(x) - f\\left(\\frac{m}{n}\\right)\\right)p_m\n    \\end{align*}\n    We will show that this is small by dividing it into two parts. For $\\sigma > 0$, we have that:\n    \\begin{align*}\n        \\abs{f(x) - P_n(x)} &\\leq \\sum_{m: \\abs{\\frac{m}{n} - x} \\leq \\sigma} \\abs{f(x) - f\\left(\\frac{m}{n}\n        \\right)}p_m + \\sum_{m: \\abs{\\frac{m}{n} - x} > \\sigma}\\abs{f(x) - f\\left(\\frac{m}{n}\\right)}p_m\n        \\\\ &\\leq \\sum_{m: \\abs{\\frac{m}{n} - x} \\leq \\sigma} \\abs{f(x) - f\\left(\\frac{m}{n}\n        \\right)}p_m + \\sum_{m: \\abs{\\frac{m}{n} - x} > \\sigma}2Mp_m\n    \\end{align*}\n    where $M = \\sup\\set{f(x): x \\in [0, 1]}$. Let $\\e > 0$. we choose $\\delta > 0$ such that $\\abs{x - y} < \\delta$ implies $\\abs{f(x) - f(y)} < \\frac{\\e}{2}$. This choice is possible by the uniform continuity of $f$ (it is a continuous (polynomial) function on a compact set ($[0, 1]$)). Then, for the first term above we have that:\n    \\begin{align*}\n        \\sum_{m: \\abs{\\frac{m}{n} - x} \\leq \\sigma} \\abs{f(x) - f\\left(\\frac{m}{n}\n        \\right)}p_m \\leq \\frac{\\e}{2}\\sum_{m=0}^n p_m = \\frac{\\e}{2}.\n    \\end{align*}\n    For the second term, we apply Chebychev's inequality to get:\n    \\begin{align*}\n        \\sum_{m: \\abs{\\frac{m}{n} - x} > \\sigma}2Mp_m \\leq 2M\\frac{1}{\\delta^2}\\frac{x(1-x)}{n}.\n    \\end{align*}\n    Since $x(1-x) \\leq \\frac{1}{4}$ for $x \\in [0, 1]$ we have:\n    \\begin{align*}\n        \\sum_{m: \\abs{\\frac{m}{n} - x} > \\sigma}2Mp_m \\leq 2M\\frac{1}{\\delta^2}\\frac{x(1-x)}{n} \\leq \\frac{M}{2\\delta^2}\\frac{1}{n}.\n    \\end{align*}\n    Now, choose $n$ such that $n > N \\geq \\frac{4\\delta^2}{M\\e}$. We then have that:\n    \\begin{align*}\n        \\frac{M}{2\\delta^2}\\frac{1}{n} < \\frac{\\e}{2}\n    \\end{align*}\n    Then, we have that:\n    \\begin{align*}\n        \\abs{f(x) - P_n(x)} \\leq \\frac{\\e}{2} + \\frac{\\e}{2} = \\e\n    \\end{align*}\n    which proves the claim. \\qed\n\\end{nproof}\n\\noindent Our conclusion is that $P_n(x)$ is very close to $f(x)$. In the above proof, we split up the sum into two parts, and used different methods to obtain nice estimates/bounds on each. The next topic we will look at is generalizing this theorem; we will be building up to Rudin 7.32 (Stone-Weierstrass).\n\n\\setcounter{rudin}{27}\n\n\\begin{definition}{Algebras}{7.28a}\n    Let $\\A$ be a set of functions $f: E \\mapsto \\CC$ (or $\\RR$). Then, $\\A$ is an \\textbf{algebra} if for all $f, g \\in \\A$ and for all $c \\in \\CC$, $f + g \\in \\A$, $fg \\in \\A$, and $cf \\in \\A$. \n\\end{definition}\n\n\\begin{nexample}{}{}\n    Let $E = [0, 1]$ and let $\\A = \\mathbb{P}$ be the set of polynomials on $[0, 1]$. Then, $\\A$ is an algebra as the sum and product of two polynomials is also a polynomial, and a constant times a polynomial is a polynomial.\n\\end{nexample}\n\n\\setcounter{rudin}{27}\n\n\\begin{definition}{Uniformly Closed Algebras and Uniform Closure}{7.28b}\n    We say that an algebra $\\A$ is \\textbf{uniformly closed} if $f_n \\in \\A$ and if $f_n \\rightarrow f$ uniformly on $E$, then $f \\in A$. In other words, the uniform limit of sequences of functions in the algebra is contained in the algebra. The \\textbf{uniform closure} of $\\A$ is then defined as $\\mathcal{B} = \\set{f: E \\mapsto \\CC: \\exists f_n \\in \\A \\text{ such that } f_n \\rightarrow f \\text{ uniformly}}$. \n\\end{definition}\n\n\\begin{nexample}{}{}\n    $\\mathbb{P}$ in the above example is not closed, as the uniform limit of a polynomial is not necessarily a polynomial. $\\C([0, 1])$ is uniformly closed as the limit of uniform and continuous functions are closed and bounded. $\\C([0, 1])$ is also the uniform closure of $\\mathbb{P}$ by the Weierstrass theorem (Theorem \\ref{thm:7.26}). \n\\end{nexample}\n\n\\begin{theorem}{}{7.29}\n    The uniform closure $\\mathcal{B}$ (sometimes denoted $\\overline{\\A}$) of an algebra $\\A$  of bounded functions is a uniformly closed algebra. Note that $\\A$ has a metric $d(f, g) = \\sup_{x \\in E}\\abs{f(x) - g(x)} = \\norm{f - g}$ and uniform convergence is equivalent to convergence in this metric.\n\\end{theorem}\n\n\\begin{nproof}\n    Suppose $f, g \\in \\mathcal{B}$ and $c \\in \\CC$. Then, there exsits $\\set{f_n}, \\set{g_n} \\subset \\A$ such that $f_n \\rightarrow f$ uniformly and $g_n \\rightarrow g$ uniformly (that is, $\\norm{f - f_n} \\rightarrow 0$ and $\\norm{g - g_n} \\rightarrow 0$). We then have that:\n    \\begin{align*}\n        f_n + g_n &\\rightarrow f + g \\text{ uniformly,}\n        \\\\ fng_n &\\rightarrow fg \\text{ uniformly,}\n        \\\\ cf_n &\\rightarrow cf \\text{ uniformly.}\n    \\end{align*}\n    Note that the first two lines above correspond to Rudin problems 7.2 and 7.3 respectively (these are left as exercises to the reader). We conclude that $f+g, fg, cg \\in \\mathcal{B}$ and hence $\\mathcal{B}$ is an algebra. Furthermore, it is uniformly closed as it consists of $\\A$ and all limit points of $\\A$ (hence $\\mathcal{B} = \\overline{\\A}$). \\qed\n\\end{nproof}\n\n\\begin{definition}{Separating Points and Vanishing at No Point}{7.30}\n    A set $\\A$ consisting of functions $f: E \\mapsto \\CC$ \\textbf{separates points} on $E$ if for all $x_1, x_2$ in $E$ with $x_1 \\neq x_2$, there exists $f \\in \\A$ such that $f(x_1) \\neq f(x_2)$. In other words, there are enough functions in the set such that whatever pair of points we choose, we can always find distinct function values at these points. We say that $\\A$ \\textbf{vanishes at no point} in $E$ if for all $x \\in E$, there exists $f \\in \\A$ such that $f(x) \\neq 0$.\n\\end{definition}\n\n\\begin{nexample}{}{}\n    \\begin{enumerate}\n        \\item The set of polynomials $\\mathbb{P}$ on $[-1, 1]$ separates points and vanishes at no point.\n        \\item The set of even polynomials on $[-1, 1]$ vanishes at no point but does not separate points (as for any $x \\in (0, 1]$ and even polynomial $f$, $f(x) = f(-x)$).\n        \\item The set of odd polynomials on $[-1, 1]$ separates points, but all odd polynomials vanish at zero.\n    \\end{enumerate}\n\\end{nexample}\n\n\\setcounter{rudin}{31}\n\n\\begin{theorem}{Stone-Weierstrass}{7.32}\n    The uniform closure of any algebra $\\A$ of real continuous functions on a compact set $K$ which separates points and vanishes at no point is $\\C(K)$ (i.e. the set of all continuous functions on $K$).\n\\end{theorem}\n\\noindent In other words, the above theorem tells us that given $\\A$ that separates points and vanishes at no point on compact $K$, we can generate a sequence that uniformly converges to any continuous function on $K$. Note that the above theorem gives the Weierstrass theorem as a special case. Take $[a, b]$ and $\\A = \\mathbb{P}$ to be the polynomials on $[a, b]$. Then, $\\mathbb{P}$ separates points and vanishes at no point, so according to the theorem, the uniform closure of $\\mathbb{P}$ is all continuous functions on $[a, b]$. \n\n\\begin{theorem}{Complex Stone-Weierstrass}{7.33}\n    Let $\\A$ be a set of real complex functions on a compact set $K$ which separates points and vanishes at no point. Furthermore, suppose that $\\A$ is self adjoint, that is, if $f \\in \\A$, then $\\overline{f} \\in \\A$ (where $\\overline{f}(x) = \\overline{f(x)}$). Then, the uniform closure of $\\A$ is $\\C(K)$. \n\\end{theorem}\n\n\\noindent We establish three ingridients necessary for our proof of the Stone-Weierstrass theorem.\n\n\\begin{nlemma}{ 1}\n    Let $\\A$ be an algebra of real, continuous functions on a compact set $K$. Then, if $f \\in \\overline{\\A}$, then $\\abs{f} \\in \\overline{\\A}$. \n\\end{nlemma}\n\n\\begin{nproof}\n    Let $f \\in \\overline{\\A}$ and $M = \\sup_{x \\in K}\\abs{f(x)}$. This $M$ is finite. Let $\\e > 0$. By Theorem \\ref{thm:7.26}, there exists a polynomial $\\tilde{P}_n$ duch that:\n    \\begin{align*}\n        \\sup_{\\abs{y} \\leq M}\\abs{\\tilde{P}_n(y) - \\abs{y}} < \\frac{\\e}{2}.\n    \\end{align*}\n    Then, let $P_n(y) = \\tilde{P}_n(y) - \\tilde{P}_n(0) = \\sum_{j=1}^n c_jy^j$. We then have that:\n    \\begin{align*}\n        \\abs{P_n(y) - \\abs{y}} \\leq \\abs{\\tilde{P}_n(0) - \\abs{0}} + \\abs{\\tilde{P}_n(y) - \\abs{y}} < \\frac{\\e}{2} + \\frac{\\e}{2} = \\e\n    \\end{align*}\n    Also, $P_n(f) = \\sum_{j=1}^n c_jf^j \\in \\overline{\\A}$ as $f \\in \\overline{\\A}$ and hence sums/products of $f$ will be in the algebra. Note that the constant function may or may not be in the algebra, which is the reason why we define $P_n$ with the constant term left out (by subtracting $\\tilde{P}_n(0)$ from $\\tilde{P}_n(y)$). Moreover, we have that $\\sup_{x \\in K}\\abs{P_n(f)(x) - \\abs{f(x)}} < \\e$ as $\\abs{P_n(y) - \\abs{y}} < \\e$ for any $\\abs{y} \\leq M$ (since $\\abs{f(x)} \\leq M$ for all $x \\in K$). Hence, $\\abs{f} \\in \\overline{\\A}$. \\qed\n\\end{nproof}\n\n\\begin{nlemma}{ 2}\n    For $\\overline{\\A}$ as in the previous Lemma (where $\\overline{\\A}$ is the uniform closure of a set of real, continuous functions on compact $K$), if $f_1, \\ldots, f_n \\in \\overline{\\A}$, then $\\max\\set{f_1, \\ldots, f_n} \\in \\overline{\\A}$ and $\\min\\set{f_1, \\ldots, f_n} \\in \\overline{\\A}$. \n\\end{nlemma}\n\n\\begin{nproof}\n    It suffices to consider the case where $n = 2$. For this we use that:\n    \\begin{align*}\n        \\max\\set{f_1, f_2} &= \\frac{1}{2}(f_1 + f_2) + \\frac{1}{2}\\abs{f_1 - f_2}\n        \\\\ \\min\\set{f_1, f_2} &= \\frac{1}{2}(f_1 + f_2) - \\frac{1}{2}\\abs{f_1 - f_2}\n    \\end{align*}\n    Then, as $\\overline{\\A}$ is an algebra, we have that $\\frac{1}{2}(f_1 + f_2) \\pm \\frac{1}{2}\\abs{f_1 - f_2} \\in \\overline{\\A}$ by Lemma 1. \\qed\n\\end{nproof}\n\\noindent As a quick verification of the above formulas for the max/min over $\\set{f_1, f_2}$, we can WLOG consider the case where $f_1 \\geq f_2$:\n\\begin{align*}\n    \\frac{1}{2}(f_1 + f_2) + \\frac{1}{2}\\abs{f_1 - f_2} = &\\frac{1}{2}(f_1 + f_2) + \\frac{1}{2}(f_1 - f_2) = f_1 = \\max\\set{f_1, f_2}\n    \\\\ \\frac{1}{2}(f_1 + f_2) - \\frac{1}{2}\\abs{f_1 - f_2} = &\\frac{1}{2}(f_1 + f_2) - \\frac{1}{2}(f_1 - f_2) = f_2 = \\min\\set{f_1, f_2}\n\\end{align*}\n\n\\setcounter{rudin}{30}\n\n\\begin{theorem}{}{7.31}\n    If an algebra $\\A$ of functions on $E$ separates points and vanishes at no point, then given any $x_1, x_2 \\in E$ with $x_1 \\neq x_2$ and constants $c_1, c_2$, there exists $f \\in \\A$ such that $f(x_1) = c_1$ and $f(x_2) = c_2$. \n\\end{theorem}\n\n\\begin{nproof}\n    By hypothesis, there exists $g \\in A$ such that $g(x_1) \\neq g(x_2)$ (as $\\A$ separates points). Furthermore, there exists $h, k \\in \\A$ such that $h(x_1) \\neq 0$ and $k(x_2) \\neq 0$ as $\\A$ vanishes at no point. Let:\n    \\begin{align*}\n        u(x) &= (g(x) - g(x_1))k(x)\n        \\\\ v(x) &= (g(x) - g(x_2))h(x)\n    \\end{align*}\n    Then, $u(x_1) = 0$ and $u(x_2) \\neq 0$, and $v(x_1) \\neq 0$ and $v(x_2) = 0$. Note that the $k, h$s are necessary to include in the above definitions of $u, v$ to ensure that $u, v$ lie in our algebra; $g(x) - g(x_i)$ may not be in $\\A$ if the constant functions are not in $\\A$. Now, let:\n    \\begin{align*}\n        f(x) = c_1\\frac{v(x)}{v(x_1)} + c_2\\frac{u(x)}{u(x_2)}\n    \\end{align*}\n    which is a meaningful definition as $v(x_1) \\neq 0$ and $u(x_2) \\neq 0$. Since $\\A$ is an algebra, $f \\in \\A$. Furthermore, we have that:\n    \\begin{align*}\n        f(x_1) = c_1\\frac{v(x_1)}{v(x_1)} + c_2\\frac{u(x_1)}{v(x_2)} = c_1 + 0 = c_1\n    \\end{align*}\n    and identically $f(x_2) = c_2$, proving the claim. \\qed\n\\end{nproof}\n\n\\noindent We now proceed into the proof of Theorem \\ref{thm:7.32}. As a brief refresher, we have an algebra $\\A$ of continuous real functions on a compact set $K$, which vanishes points and separates at no point. We wish to show that for all continuous functions $f: K \\mapsto \\RR$ and for all $\\e > 0$, there exists $h \\in \\mathcal{B} = \\overline{\\A}$ such that $\\norm{h - f} < \\e$. \n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[scale=2]\n        \\draw[-latex, very thick] (0, 0) -- (2, 0);\n        \\draw[-latex, very thick] (0, 0) -- (0, 2);\n        \\node[] at (0.5, 0) {$[$};\n        \\node[] at (1.5, 0) {$]$};\n        \\node[below] at (1, 0) {$K$};\n        \\draw[red] (1, 1.5) parabola (0.5, 0.5);\n        \\draw[red] (1, 1.5) parabola (1.5, 0.5);\n        \\draw[red, dotted, yshift = 10pt] (1, 1.5) parabola (0.5, 0.5);\n        \\draw[red, dotted, yshift = 10pt] (1, 1.5) parabola (1.5, 0.5);\n        \\draw[red, dotted, yshift = -10pt] (1, 1.5) parabola (0.5, 0.5);\n        \\draw[red, dotted, yshift = -10pt] (1, 1.5) parabola (1.5, 0.5);\n        \\draw[blue] (0.5, 1.5) to [ curve through ={(0.75, 1.3)..(1,1.17)..(1.2,1.3)...(1.3,1.2)...(1.4,1.4)}] (1.5, 1.5);\n        \\node[right, text = blue] at (1.5, 1.5) {$g_x(t)$};\n        \\draw[] (0.77, 0) -- (0.77, -0.15);\n        \\node[below] at (0.77, -0.15) {$x$};\n        \\filldraw[] (0.77, 1.28) circle (0.5pt);\n        %\\draw[<->] (1, 1.5) -- (1, 1.15);\n        %\\node[left] at (1, 1.3) {$\\e$};\n        %\\draw[<->] (1, 1.5) -- (1, 1.85);\n        %\\node[left] at (1, 1.625) {$\\e$};\n        \\node[right, text = red] at (1.5, 0.5) {$f(t)$};\n    \\end{tikzpicture}\n    \n    \\caption{Visualization of Claim 1 in the below proof of the Stone-Weierstrass theorem. We have that $g_x(x) = f(x)$, and that $g_x(t)$ lies above the bottom of the $\\e$-tube around $f$. As we will see in the proof, this $g_x$ is obtained by considering $h_y$s that satisfy $h_y(t) - f(t) > -\\e$ for $t$ in some neighbourhood of $y$. By the compactness of $K$, we can consider a finite subcover of these neighbourhoods, and defining $g_x$ to be the maximum of some finite number of $h_{y_i}$s. \n    }\n    \\label{fig48}\n\\end{figure}\n\n\\begin{nproof}\n    \\textbf{Claim 1:} Let $f: K \\mapsto \\RR$ be continuous, $x \\in K$, and $\\e > 0$. Then, $\\exists g_x \\in \\mathcal{B}$ such that $g_x(x) = f(x)$ and $g_x(t) - f(t) > -\\e$ for all $t \\in K$.\n\n    We now prove the claim. Fix $x \\in K$. Given $y \\in K$ with $y \\neq x$, by Theorem \\ref{thm:7.31} there exists $h_y \\in \\A$ such that $h_y(x) = f(x)$ and $h_y(y) = f(y)$. $h_y - f$ is continuous, and $h_y(y) - f(y) = 0$, so by continuity there exists an open set $J_y \\subset K$ such that $y \\in J_y$ and $h_y(t) - f(t) > -\\e$ for all $t \\in J_y$. We can form an open cover of $K$ from considering the set of $J_y$s around each $y \\in K$. By the compactness of $K$, there exists a finite subcover $\\set{J_{y_1}, \\ldots J_{y_n}}$. Let $g_x = \\max\\set{h_{y_1}, \\ldots h_{y_n}}$ (a maximum can be taken over a finite set). Each of the $h_{y_i}$s are continuous and in $\\A$, so $g_x \\in \\mathcal{B}$ by Lemma 2. Also, we have that:\n    \\begin{align*}\n        g_x(x) = \\max{h_{y_1}(x), \\ldots, h_{y_n}(x)} = \\max{f(x), \\ldots, f(x)} = f(x)\n    \\end{align*}\n    as well as that $g_x(t) - f(t) \\geq h_{y_i}(t) - f(t) > -\\e$ where we choose $i$ such that $t \\in J_{y_i}$. This proves the claim.\n\n    \\textbf{Claim 2:} Let $f: K \\mapsto \\RR$ be continuous, and let $\\e > 0$. Then, there exists $h \\in \\mathcal{B}$ such that $\\sup_{x \\in K}\\abs{h(x) - f(x)} < \\e$. This claim implies the Stone-Weierstrass theorem. We will be ``fixing'' the function from claim 1 such that the function does not lie above the $\\e$ tube. \n\n    Let us move onto the proof of the claim. Since $g_x - f$ is continuous and $g_x(x) - f(x) = 0$, we ahve that there exists an open set $V_x \\in K$ such that $\\abs{g_x(t) - f(t)} < \\e$ for $t \\in V_x$. Since $K$ is compact, we have that $K \\subset V_{x_1} \\cup \\ldots \\cup V_{x_n}$ for some $x_1, \\ldots, x_n \\in K$. Let $h = \\min\\set{g_{x_1}, \\ldots, g_{x_n}}$. By Lemma 2, $h \\in \\mathcal{B}$. Then, take any $t \\in K$. We then have that:\n    \\begin{align*}\n        h(t) - f(t) = g_{x_i} - f(t) > -\\e\n    \\end{align*}\n    where we pick $i$ to give the minimum, and the lower bound of $-\\e$ follows by Claim 1. We also have that:\n    \\begin{align*}\n        h(t) - f(t) \\leq g_{x_{i'}}(t) - f(t) < \\e\n    \\end{align*}\n    where we pick a new $i'$ such that $t \\in V_{x_{i'}}$. We conclude that $\\norm{h - f} < \\e$, proving the claim. \\qed\n\\end{nproof}\n\n\\noindent Having proven the real case of the Stone-Weierstrass theorem, we now move to the proof of the complex generalization (Theorem \\ref{thm:7.33}). Recall that we add the hypothesis that $\\A$ is self-adjoint in this generalization (if $f \\in \\A$, then $\\overline{f} \\in \\A$). As a recap of the statement of the theorem, we suppose that $\\A$ is a self-adjoint algebra of complex continuous functions on a compact set $K$ that separates points and vanishes at no point. Then, $\\mathcal{B} = \\overline{\\A} = \\C(K)$. In other words, for any $f \\in \\C(K)$ we can find an element in $\\overline{\\A}$ such that the difference is arbitrarily small. \n\n\\begin{nproof}\n    Let $\\A_\\RR$ be the algebra of real-valued continuous functions contained in $\\A$. If $f = u + iv \\in \\A$, then $u = \\frac{1}{2}(f + \\overline{f}) \\in \\A_\\RR$ and $v = \\frac{1}{2}(f - \\overline{f}) \\in \\A_\\RR$. We have that $\\A_\\RR$ separates points; to see this, let $x_1, x_2 \\in K$ with $x_1 \\neq x_2$. By Theorem \\ref{thm:7.31} (applied to $\\A$) there exists $f \\in \\A$ such that $f(x_1) = 1$ and $f(x_2) = 0$. Writing $f = u + iv$, we have that $u(x_1) = 1 \\neq u(x_2) = 0$ and $u \\in \\A_\\RR$. Furthermore, $\\A_\\RR$ vanishes at no point. For all $x \\in K$, by assumption there exists $f \\in \\A$ such that $f(x) \\neq 0$, and hence $u(x) \\neq 0$ (or $v(x) \\neq 0$). Hence by Theorem \\ref{thm:7.32}, we have that $\\A_\\RR = \\C_\\RR(K)$ (that is, the real values continuous functions on $K$). Let $f = u + iv \\in \\C_\\CC(K)$ and let $\\e > 0$. There exist $\\tilde{u}, \\tilde{v}$ such that $\\norm{u - \\tilde{u}} < \\frac{\\e}{2}$ and $\\norm{v - \\tilde{v}} < \\frac{\\e}{2}$, so it follows that $\\norm{f - (\\tilde{u} + i\\tilde{v})} \\leq \\norm{u - \\tilde{u}} + \\norm{v - \\tilde{v}} < \\e$. \\qed\n\\end{nproof}", "meta": {"hexsha": "9fa131654cfd30076be4ef8ce2d1022a2381d581", "size": 79785, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/ch7.tex", "max_stars_repo_name": "RioWeil/MATH320-321-Notes", "max_stars_repo_head_hexsha": "532c4bf12a8e4ea80a58a83508de05e1f121a79a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/ch7.tex", "max_issues_repo_name": "RioWeil/MATH320-321-Notes", "max_issues_repo_head_hexsha": "532c4bf12a8e4ea80a58a83508de05e1f121a79a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-10T23:18:29.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-25T17:05:30.000Z", "max_forks_repo_path": "Chapters/ch7.tex", "max_forks_repo_name": "RioWeil/MATH320-321-notes", "max_forks_repo_head_hexsha": "532c4bf12a8e4ea80a58a83508de05e1f121a79a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.1972477064, "max_line_length": 1288, "alphanum_fraction": 0.6038729084, "num_tokens": 29782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.9184802456988518, "lm_q1q2_score": 0.7063850051068535}}
{"text": "\\input{../common/common.tex}\n\n\\title{Math notes - Points on circle}\n\\author{Uwe Hoffmann}\n\\hypersetup{colorlinks, pdftitle={Math notes - Points on circle}}\n\n\\begin{document}\n\n\\setcounter{chapter}{1}\n\\section*{Points on circle}\n\n\\vspace{10 mm}\n\\begin{problem}\n$N$ distinct points, numbered from $0$ onwards, are located on a circle (in the rest of this problem all point numbers are taken $\\mathbf{mod} N$). Point $i + 1$ is the clockwise neighbor of point $i$. An integer array, $dist[0 \\ldots N)$, is given such that $dist.i$ is the distance (along the circle) between points $i$ and  $i + 1$. Derive a program to determine whether four of these points form a rectangle.\n\\end{problem}\n\nWe adopt the same notation used in \\textit{Programming in the 1990s} \\cite{Cohen90} and \\textit{Programming, The Derivation of Algorithms}\\cite{Kaldewaij90}: The notation of function application is the \"dot\" notation with name of function, followed by arguments, each separated by a dot. The notation of quantified expressions has the operator followed by the bounded variables, then a colon followed by the range for the bounded variables and ended with a colon and the actual expression. So\n\n\\begin{equation*}\t \n\t(\\sum k : i \\leq k < j : x_k)\n\\end{equation*}\n\n\\noindent corresponds to the more classical mathematical notation $\\sum_{k = i}^{ j - 1}x_k$. \n\n\\noindent For our derivation steps in predicate calculus we will use the following notation:\n\n\\begin{equation*}\n\\begin{array}{lcl}\n\t\t&&A \\\\\n\t      &=& \\{  \\mbox{reason why A equals B} \\} \\\\      \n                  &&B \\\\\n                &\\leq& \\{ \\mbox{reason why B is less than C} \\} \\\\\n                  && C  \n   \\end{array}\n\\end{equation*}\n\n\\noindent We are asked to solve $S$ in \\medskip\n\n$\\|[$\n\n\\verb|    | \\textbf{con} $N:\\ int;\\ \\{N \\geq 4\\}$\n\n\\verb|        | $dist(i: 0 \\leq i < N):\\ int;\\ \\{\\forall i: 0 \\leq i < N: dist.i > 0\\}$\n\n\\verb|    | \\textbf{var} $r: bool$;\n\n\\verb|        | S\n\n\\verb|    | $\\{r: r \\equiv (\\exists\\ 4\\  \\text{points that form a rectangle}) \\}$\n\n$]\\|$\n\n\\medskip\n\n\\noindent Let's first develop a more manageable postcondition. Evidently four points that form a rectangle is equivalent to two pairs of diametral opposing points. We introduce a function for the set of all indices from point $x$ to point $y$ in clockwise direction along the circle:\n\n\\begin{equation*}\n\\begin{array}{ll}\n& I: [0, \\ldots, N) \\rightarrow [0, \\ldots, N) \\rightarrow 2^{[0, \\ldots, N)} \\\\\n& I.x.y :=\n\\begin{cases}\n[x, \\ldots, y)\\qquad,\\  x \\leq y \\\\\n[x, \\ldots, N) \\bigcup\\  [0, \\ldots, y) \\quad,\\ x > y\n \\end{cases}\n \\end{array}\n\\end{equation*}\n\n\\noindent Let $C$ be the circumference of the circle.\n\\noindent We define function\n\\begin{equation*}\n\\begin{array}{ll}\n   & f : [0, \\ldots, N) \\rightarrow [0, \\ldots, N) \\rightarrow int \\\\\n   & f.x.y := C - 2 (\\sum i: i \\in I.x.y : dist.i)\n\\end{array}\n\\end{equation*}\n\n\\noindent We want to find the number of diametral opposing pairs of points:\\medskip\n\n$\\|[$\n\n\\verb|    | \\textbf{con} $N:\\ int;\\ \\{N \\geq 2\\}$\n\n\\verb|        | $dist(i: 0 \\leq i < N):\\ int;\\ \\{\\forall i: 0 \\leq i < N: dist.i > 0\\}$\n\n\\verb|    | \\textbf{var} $r: int$;\n\n\\verb|        | S\n\n\\verb|    | $\\{r: r = (\\#\\ x, y: 0 \\leq x < N,\\  0 \\leq y < N: f.x.y = 0) \\}$\n\n$]\\|$\n\n\\medskip\n\n\\begin{lem}\\label{slope}\nThe function $f$ is increasing in its first argument and decreasing in its second argument.\n\\end{lem}\n\n\\begin{proof}\n$f$ is increasing in its first argument:\n\\begin{equation*}\n\\begin{array}{lcl}\n\t\t&& f.(x + 1).y \\\\\n\t      &=& \\{ \\mbox{definition of $f$} \\} \\\\      \n                  && C - 2 (\\sum i: i \\in I.(x + 1).y : dist.i) \\\\\n                &=& \\{  I.(x + 1).y = I.x.y \\setminus \\{x\\} \\} \\\\\n                  &&  C - 2((\\sum i: i \\in I.x.y : dist.i) - dist.x)  \\\\\n                 &=& \\{ \\mbox{definition of $f$} \\} \\\\\n                 && f.x.y + 2 dist.x \\\\\n                 &>& \\{ dist.x > 0 \\} \\\\\n                && f.x.y\n   \\end{array}\n\\end{equation*}\n\n$f$ is decreasing in its second argument:\n\\begin{equation*}\n\\begin{array}{lcl}\n\t\t&& f.x.(y + 1) \\\\\n\t      &=& \\{ \\mbox{definition of $f$} \\} \\\\      \n                  && C - 2 (\\sum i: i \\in I.x .(y + 1) : dist.i) \\\\\n                &=& \\{  I.x.(y + 1) = I.x.y\\ \\bigcup\\  \\{y\\} \\} \\\\\n                  &&  C - 2((\\sum i: i \\in I.x.y : dist.i) + dist.y)  \\\\\n                 &=& \\{ \\mbox{definition of $f$} \\} \\\\\n                 && f.x.y - 2 dist.y \\\\\n                 &<& \\{ dist.y > 0 \\} \\\\\n                && f.x.y\n   \\end{array}\n\\end{equation*}\n\\end{proof}\n\n\\noindent Looking at the postcondition \n\\begin{equation*}\n\\{r: r = (\\#\\ x, y: 0 \\leq x < N,\\  0 \\leq y < N: f.x.y = 0) \\}\n\\end{equation*}\n we define the function\n \\begin{equation*}\n G.a.b = (\\#\\ x, y: a \\leq x < N,\\  b \\leq y < N: f.x.y = 0)\n\\end{equation*}\nand we will maintain the invariants:\n\\begin{equation*}\n\\begin{array}{lcl}\n     P_0 &:& G.0.0 = r + G.a.b \\\\      \n     P_1 &:& 0 \\leq a \\leq N\\\\\n     P_2 &:& 0 \\leq b \\leq N\n   \\end{array}\n\\end{equation*}\n\n\\noindent The initial values $r, a, b := 0, 0, 0$ satisfy  the invariants and\n\\begin{equation*}\na = N \\vee b = N \\Rightarrow G.a.b = 0 \\Rightarrow r = G.0.0\n\\end{equation*}\nestablishes the postcondition, so we can stop when $a = N \\vee b = N$.\n\n\\noindent So far we have\\medskip\n\n$\\|[$\n\n\\verb|    | \\textbf{con} $N:\\ int;\\ \\{N \\geq 4\\}$\n\n\\verb|        | $dist(i: 0 \\leq i < N):\\ int;\\ \\{\\forall i: 0 \\leq i < N: dist.i > 0\\}$\n\n\\verb|    | \\textbf{var} $a, b, r: int$;\n\n\\verb|    | $a, b, r := 0, 0, 0$;\n\n\\verb|    | \\textbf{do} $a \\neq N \\wedge b \\neq N$\n\n\\verb|       | S\n\n\\verb|    | \\textbf{od}\n\n\\verb|    | $\\{r: r = G.0.0 \\}$\n\n$]\\|$\n\n\\medskip\n\n\\noindent We need to increment $a, b$ and maintain the invariants:\n\\begin{equation*}\n\\begin{array}{lcl}\n\t\t&& G.a.b \\\\\n\t      &=& \\{ \\mbox{definition of $G$} \\} \\\\      \n                  && (\\#\\ x, y: a \\leq x < N,\\  b \\leq y < N: f.x.y = 0) \\\\\n                &=& \\{  \\text{range split } x = a \\} \\\\\n                  &&  G.(a + 1).b + (\\# y: b \\leq y < N:f.a.y = 0)  \\\\\n                 &=& \\{ \\mbox{$f$ is decreasing in second argument (\\ref{slope}), and assume } f.a.b < 0 \\} \\\\\n                 && G.(a + 1).b \n   \\end{array}\n\\end{equation*}\nso $f.a.b < 0 \\Rightarrow G.a.b = G.(a + 1).b$. Similarly\n\\begin{equation*}\n\\begin{array}{lcl}\n\t\t&& G.a.b \\\\\n\t      &=& \\{ \\mbox{definition of $G$} \\} \\\\      \n                  && (\\#\\ x, y: a \\leq x < N,\\  b \\leq y < N: f.x.y = 0) \\\\\n                &=& \\{  \\text{range split } y = b \\} \\\\\n                  &&  G.a.(b + 1) + (\\# x: a \\leq y < N:f.x.b = 0)  \\\\\n                 &=& \\{ \\mbox{$f$ is increasing in second argument (\\ref{slope}), and assume } f.a.b > 0 \\} \\\\\n                 && G.a.(b + 1) \n   \\end{array}\n\\end{equation*}\nso $f.a.b > 0 \\Rightarrow G.a.b = G.a.(b + 1)$. Also for the case $f.a.b = 0$ we have\n\\begin{equation*}\n\\begin{array}{lcl}\n\t\t&& r + G.a.b \\\\\n\t      &=& \\{ \\mbox{definition of $G$} \\} \\\\      \n                  && r + (\\#\\ x, y: a \\leq x < N,\\  b \\leq y < N: f.x.y = 0) \\\\\n                &=& \\{  \\text{range split } x = a \\} \\\\\n                  &&  r + G.(a + 1).b + (\\# y: b \\leq y < N:f.a.y = 0)  \\\\\n                 &=& \\{ \\mbox{$f$ is decreasing in second argument (\\ref{slope}), and assume } f.a.b = 0 \\} \\\\\n                 && (r + 1) +  G.(a + 1).b \n \\end{array}\n\\end{equation*} \n\nOur program becomes\\medskip\n\n$\\|[$\n\n\\verb|    | \\textbf{con} $N:\\ int;\\ \\{N \\geq 4\\}$\n\n\\verb|        | $dist(i: 0 \\leq i < N):\\ int;\\ \\{\\forall i: 0 \\leq i < N: dist.i > 0\\}$\n\n\\verb|    | \\textbf{var} $a, b, r: int$;\n\n\\verb|    | $a, b, r := 0, 0, 0$;\n\n\\verb|    | \\textbf{do} $a \\neq N \\wedge b \\neq N$\n\n\\verb|       | \\textbf{if}\n\n\\verb|       | $\\square\\  f.a.b > 0 \\rightarrow b := b + 1$\n\n\\verb|       |  $\\square\\  f.a.b < 0 \\rightarrow a := a + 1$ \n\n\\verb|       |  $\\square\\  f.a.b = 0 \\rightarrow a, r := a + 1, r + 1$ \n\n\\verb|       | \\textbf{fi}\n\n\\verb|    | \\textbf{od}\n\n\\verb|    | $\\{r: r = G.0.0 \\}$\n\n$]\\|$\n\n\\medskip\n\n\\noindent We cannot have $f$ in the program text so the last thing we have to do is eliminate $f$. We do this by introducing a new variable $c: int$ and maintaining the additional invariant $P_3: c = f.a.b$. Lemma \\ref{slope} already showed us the expressions for $f$ when the first or the second argument increase, so our final program looks like this\\footnote{The program is bound by the function $2 N - a - b$ so it is $O(N)$. The solution is an example of the slope search technique.}\\medskip\n\n$\\|[$\n\n\\verb|    | \\textbf{con} $N:\\ int;\\ \\{N \\geq 4\\}$\n\n\\verb|        | $dist(i: 0 \\leq i < N):\\ int;\\ \\{\\forall i: 0 \\leq i < N: dist.i > 0\\}$\n\n\\verb|    | \\textbf{var} $a, b, c, r: int$;\n\n\\verb|    | $a, b, c, r := 0, 0, C, 0$;\n\n\\verb|    | \\textbf{do} $a \\neq N \\wedge b \\neq N$\n\n\\verb|       | \\textbf{if}\n\n\\verb|       | $\\square\\  c > 0 \\rightarrow b, c := b + 1, c - 2 dist.b$\n\n\\verb|       |  $\\square\\  c < 0 \\rightarrow a, c := a + 1, c + 2 dist.a$ \n\n\\verb|       |  $\\square\\  c = 0 \\rightarrow a, c, r := a + 1, 2 dist.a, r + 1$ \n\n\\verb|       | \\textbf{fi}\n\n\\verb|    | \\textbf{od}\n\n\\verb|    | $\\{r: r = G.0.0 \\}$\n\n$]\\|$\n\n\\bibliographystyle{plainnat}\n\\bibliography{../common/math}\n\n\\end{document}\n\n", "meta": {"hexsha": "2b4a44e1a42c8760be869467c2ffdba69d604e41", "size": 9138, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pointsoncircle/pointsoncircle.tex", "max_stars_repo_name": "uwedeportivo/math_notes", "max_stars_repo_head_hexsha": "e0120bb53fad9043637ce964b186194888ba0c49", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pointsoncircle/pointsoncircle.tex", "max_issues_repo_name": "uwedeportivo/math_notes", "max_issues_repo_head_hexsha": "e0120bb53fad9043637ce964b186194888ba0c49", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pointsoncircle/pointsoncircle.tex", "max_forks_repo_name": "uwedeportivo/math_notes", "max_forks_repo_head_hexsha": "e0120bb53fad9043637ce964b186194888ba0c49", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.4042553191, "max_line_length": 496, "alphanum_fraction": 0.5221054935, "num_tokens": 3403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.7063694250304839}}
{"text": "%!TEX root = ../main.tex\n\n%=======================================================================  hyperbola\n\\section{Hyperbola}\n\\label{sec:hyperbola}\n\n\tThe \\emphindexdef{hyperbola} is another fundamental shape of nature.\n\t\n\n\t\\subsection{The conic sections}\n\n\t\tThere is a deep connection between the geometric shapes of the circle,\n\t\tthe ellipse, the parabola, and the hyperbola.\n\t\tThese seemingly different shapes can be obtained, geometrically speaking,\n\t\tfrom a single object: the cone.\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\index{cone}\n\t\tWe can obtain the four curves by slicing the cone at different angles,\n\t\tas illustrated in Figure~\\ref{fig:conic_sections_four-shapes}.\n\n\t\t\\begin{figure}[htb]\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.8\\textwidth]{figures/math/conic_sections_four-shapes.pdf}\n\t\t\t\\vspace{-2mm}\n\t\t\t\\caption{\tTaking slices through a cone at different angles produces different geometric shapes:\n\t\t\t\t\ta circle, an ellipse, a parabola, or a hyperbola.}\n\t\t\t\\label{fig:conic_sections_four-shapes}\n\t\t\\end{figure}\n\t\n\n\t\\subsection{Conic sections in polar coordinates}\n\n\t\tAll four conic sections can be described by the same function in polar coordinates:\t\t\t\t\t\\index{polar coordinates}\n\t\t\\[\n\t\t  r(\\theta) = \\frac{q(1+\\varepsilon)}{1 + \\varepsilon\\cos(\\theta)}\\,,\n\t\t\\]\n\t\twhere $q$ is the curve's closest distance to a focal point\n\t\tand $\\varepsilon$ is the curve's eccentricity.\t\t\t\t\t\t\t\t\t\t\t\t\\index{eccentricity}\n\t\tFor a circle, $q=R$ (the radius) and the eccentricity parameter is $\\varepsilon=0$.\n\t\tFor an ellipse, $q=a(1-\\varepsilon)$ and the eccentricity parameter varies between $0$ and $1$ ($0\\leq \\varepsilon < 1$).\n\t\tNote we include the case $\\varepsilon=0$ since a circle is a special case of an ellipse.\n\t\tFor a parabola, $q=f$ (the focal length) and the eccentricity is $\\varepsilon=1$.\n\t\tFor a hyperbola, $q = a(\\varepsilon-1)$ and the eccentricity is $\\varepsilon>1$.\n\n\t\tWe can use the eccentricity parameter $\\varepsilon$ to classify all four curves.\n\t\tDepending on the value of $\\varepsilon$,\n\t\tthe equation $r(\\theta)$ defines either a circle, an ellipse, a parabola, or a hyperbola.\t\\index{circle}\\index{ellipse}\\index{hyperbola}\\index{parabola}\n\t\tTable~\\ref{table:conics} summarizes all our observations regarding conic sections.\n\n\n\t\t\\begin{table}[htb]\n\t\t{ \\small\n\n\t\t\\centering \n\t\t\\begin{longtable}{@{}lllll@{}} \n\t\t\\toprule\n\t\tConic section \t\\! \t&  Equation  \t\\!\\!\t\t\t\t\t\n\t\t& Polar function\t\n\t\t&\tEccentricity \\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!\t\t\t\t\\\\\n\t\t\\midrule\n\t\tCircle\t\t\t\t& $x^2+y^2=R^2$ \\; \t\t\t\t\t& $r(\\theta)=R$\t\t\t& $\\varepsilon = 0$\t\t\t\t\t\t\t\t\\\\[1mm]\n\t\tEllipse\t\t\t\t& $\\frac{x^2}{a^2}+\\frac{y^2}{b^2}=1$\t& $r(\\theta)=\\frac{a(1-\\varepsilon^2)}{1 + \\varepsilon\\cos(\\theta)}$ &\t$\\varepsilon\\!=\\!\\sqrt{1\\!-\\!\\frac{b^2}{a^2}}\\,, \\; 0\\!\\leq\\!\\varepsilon\\!<\\!1$\\!\\!\t\\\\[2mm]\n\t\tParabola\t\t\t\t& $y^2=4fx$\t\t\t\t\t\t& $r(\\theta)=\\frac{2f}{1 + \\cos(\\theta)}$ &\t$\\varepsilon=1$\t\t\t \t\t\t\t\t\t\\\\[1mm]\n\t\tHyperbola\t\t\t& $\\frac{x^2}{a^2}-\\frac{y^2}{b^2}=1$\t& $r(\\theta)=\\frac{a(\\varepsilon^2-1)}{1 + \\varepsilon\\cos(\\theta)}$ &\t$\\varepsilon\\!=\\!\\sqrt{1\\!+\\!\\frac{b^2}{a^2}}\\,, \\; 1\\!<\\!\\varepsilon\\!<\\!\\infty$ \\\\[1mm]\n\t\t\\bottomrule\n\t\t\\end{longtable}\n\n\t\t}\n\t\t\\vspace{4mm}\n\t\t\\caption{The four conic sections and their eccentricity parameters. }\n\t\t\\label{table:conics}\n\t\t\\end{table}\n\n\n\t\tThe motion of the planets is explained by Newton's law of gravitation.\n\t\tThe gravitational interaction between two bodies always leads one of the two bodies to follow a trajectory described by one of the conic sections\n\t\tfor which the other body is the focal point.\n", "meta": {"hexsha": "29d2307753204bbf6dd78b215be46d4101a95bec", "size": 3510, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sources/original/01_math/22.hyperbola.tex", "max_stars_repo_name": "minireference/sample-book", "max_stars_repo_head_hexsha": "83e827d7e0c3f5fea1d08815810f0b08bef503e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2020-10-19T21:21:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T16:42:13.000Z", "max_issues_repo_path": "sources/original/01_math/22.hyperbola.tex", "max_issues_repo_name": "minireference/sample-book", "max_issues_repo_head_hexsha": "83e827d7e0c3f5fea1d08815810f0b08bef503e3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sources/original/01_math/22.hyperbola.tex", "max_forks_repo_name": "minireference/sample-book", "max_forks_repo_head_hexsha": "83e827d7e0c3f5fea1d08815810f0b08bef503e3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-12T19:03:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-12T19:03:04.000Z", "avg_line_length": 46.1842105263, "max_line_length": 213, "alphanum_fraction": 0.6581196581, "num_tokens": 1193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672181749422, "lm_q2_score": 0.874077230244524, "lm_q1q2_score": 0.706313155913751}}
{"text": "\\chapter{Solutions for Burgers' Equation in the Deterministic Version}\n\\label{Chapter_3} \n\t\n\tThis chapter is one of the most important, since we will begin with the development of the main objective of this work. We will construct two spectral methods known as Fourier-Galerkin and Fourier-Collocation using the projection and interpolation operators respectively, considering an initial value problem that will be defined using our objective equation presented in (\\ref{Burgers_Equation}). \\\\\n\t\n\tFor this, to illustrate what we have studied in the Chapter (\\ref{Chapter_2}), we will consider the function space $H^q_p [0, 2 \\pi]$ with the norm defined in (\\ref{sobolev_norm}) for some $q$ that will be specified later. We will assume that the problems have solutions $u(x, t) \\in H^q_p [\\mathcal{D}]$ for every $t \\in I$, where $\\mathcal{D} = [x_L, x_R]$ for some fixed reals $ x_L $, $ x_R $ and $I = [0, T]$ with $T> 0$. So, given some real $\\alpha \\geq 0$ and an initial condition function $u_0 (x) \\in H^q_p [\\mathcal{D}]$, our initial value problem is as follows\n\t\\begin{align}\n\t\\label{IVP_Burgers}\n\t\t\\left \\lbrace \\begin{array}{ll}\n\t\t\t\\frac{\\partial u}{\\partial t} + \\frac{1}{2} (u^2)_x = \\alpha \\frac{\\partial^2 u}{\\partial x}, \\hspace{2mm} 0 < t \\leq T, \\hspace{2mm} x \\in I \\\\\n\t\t\t\\\\\n\t\t\tu(x, 0) = u_0(x), \\hspace{2mm} x \\in I\n\t\t\\end{array}  \\right .\n\t\\end{align}\n\t\n\tThe analytical solution of the previous problem was given in (\\ref{Exact_Solution}), and we observe that it is not easy to evaluate it directly. Therefore, it is necessary to choose a suitable method of numerical integration to calculate the integrals involved, since they have exponential behavior that is noticeably affected when the parameter $\\alpha$ is very small. However, precision problems can also arise because arithmetic operations can generate considerable errors if they are not performed correctly, and therefore this equation is not a good choice for finding solutions to the problem. \\\\\n\t\n\tIn the next section, we will present the aforementioned spectral methods considering the linear problem obtained by using the transformation given by (\\ref{Hopf_tranform}), And this will allow us to approximate the solutions of the problem (\\ref{IVP_Burgers}) More easily and with excellent precision. In addition, this will give us the advantage of having solutions that can be considered exact and use them to compare them with those that will be obtained in the numerical experiments that we will describe in the second section when implementing these methods for the nonlinear problem (\\ref{IVP_Burgers}), Since we will observe that the precision will be much less because we will need to use numerical methods to solve in the variable $t$, decreasing with respect to the parameter $\\alpha$.\n    \n\t\\input{burgers_equation/deterministic/methods/Fourier_Methods}\n\t\\input{burgers_equation/deterministic/numerical_experiments/Numerical_Results}\n\t", "meta": {"hexsha": "ab86ae76da03ae2f9478b8b8d289d82d47931cf1", "size": 2927, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/burgers_equation/deterministic/Deterministic.tex", "max_stars_repo_name": "alanmatzumiya/Maestria", "max_stars_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-12-29T10:44:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T11:18:45.000Z", "max_issues_repo_path": "docs/burgers_equation/deterministic/Deterministic.tex", "max_issues_repo_name": "alanmatzumiya/spectral-methods", "max_issues_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/burgers_equation/deterministic/Deterministic.tex", "max_forks_repo_name": "alanmatzumiya/spectral-methods", "max_forks_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T13:29:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T13:29:56.000Z", "avg_line_length": 133.0454545455, "max_line_length": 796, "alphanum_fraction": 0.7642637513, "num_tokens": 738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527631, "lm_q2_score": 0.8740772286044095, "lm_q1q2_score": 0.7063131505482867}}
{"text": "\\section{Drop out and nonlinear G-S method}\n\nHere we are going to talk about the Dropout method for training DL model. This is a kind of training algorithm but also a kind of parameter regularilization method in some sense. \n\nRecall the traditional Mini-Batch SGD training algorithm, for every step, we update the parameters $\\Theta$ by:\n\\begin{equation}\n\\Theta^{t+1} = \\Theta^t + \\eta_t \\sum_{i \\in B_t} \\mathcal{L}_i(\\Theta),\n\\end{equation} \nwhere \n\\begin{equation}\n \\mathcal{L}_i(\\Theta) = \\frac{1}{N} L(f(x_i ;\\Theta) ,y_i),\n\\end{equation}\nwith $L(\\cdot, \\cdot)$ is the loss function like $L^2$ normal or cross-entropy.\n\nSo the dropout means that you need to change our model just in this step, and get:\n\\begin{equation}\n\\tilde{f}^{j} = \\theta^j \\circ P^j \\circ g^j \\circ \\tilde f^{j-1},\n\\end{equation}\nwith $P^j$ is a diagonal matrix for \n\\begin{equation}\nP^j_{ii} \\simeq P,\n\\end{equation}\nwith\n\\begin{equation}\nP\\{x = 0 \\} = p, \\quad P\\{x = 1 \\} = 1-p.\n\\end{equation}\nand then get the update\n\\begin{equation}\n\\Theta^{t+1} = \\theta^{t} - \\eta \\nabla_{\\Theta} \\sum_{i \\in B_t} L(\\tilde f^J(x_i, \\Theta), y_i).\n\\end{equation}\n\nNow we may note \n\\begin{equation}\n\\Theta \\mathcal{P}  = \\{\\theta^0, \\theta^1 P^1, \\cdots, \\theta^{J}P^J\\}.\n\\end{equation}\nThen drop-out method can be think as:\n\\begin{equation}\n\\Theta^{t+1} = \\theta^{t} - \\eta \\nabla_{\\Theta} \\sum_{i \\in B_t} L(f^J(x_i, \\Theta), y_i) |_{\\Theta = \\Theta^t \\mathcal{P}}.\n\\end{equation}\n\n\n\\subsection{GS and Dropout}\nSuppose $\\mathcal D_\\gamma(\\mathbf A)$ is dropout function with prevent probability $\\gamma$. $\\mathbf x$ is input data. $f^j(x;\\theta^j)=\\sigma(W^jx+b^j)$ , $\\theta^j=(W^j,b^j)$, $f=f^j\\circ f^{j-1}\\circ \\cdots \\circ f^1$ is the neural network function.\n\\subsection{Training}\n\\begin{itemize}\n\t\\item [GS:] A general form of GS iteration can write as $$g_{\\text{GS}}=D_\\gamma(\\nabla_{\\Theta} (f^j\\circ f^{j-1}\\circ \\cdots \\circ f^1(\\mathbf x)))$$\n\t\\item [Dropout:] $g_{\\text{Dropout}}=\\nabla( D_{\\gamma_j}\\circ f^j\\circ D_{\\gamma_{j-1}}\\circ f^{j-1} \\circ \\cdots \\circ D_{\\gamma_1}\\circ f^1 )$, we usually set $$\\gamma_1,...,\\gamma_{j-2},\\gamma_j = 0.$$ So we have $$g_{\\text{Dropout}}=\\nabla_\\Theta(  f^j\\circ D_{\\gamma_{j-1}}\\circ f^{j-1} \\circ \\cdots \\circ f^1(\\mathbf x) )$$\n\t\n\\end{itemize}\n\\subsection{Prediction}\n\tAfter training, the weight of each layer should be scaling to make the expectation be same as dropout.\n\t\n\tSo when predicting, the neural network function is\n\t$$\n\tf= (\\gamma_j f^j)\\circ (\\gamma_{j-1} f^{j-1})\\circ \\cdots \\circ( \\gamma_1 f^1 )$$\n", "meta": {"hexsha": "7a3403f044a4b7f82489709a65cc14b5ed97c67d", "size": 2541, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/dropout-old.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/dropout-old.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/dropout-old.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.375, "max_line_length": 331, "alphanum_fraction": 0.6717827627, "num_tokens": 954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7062685527654318}}
{"text": "\\chapter{}\n\n\\begin{ex}\n    Let \\(X_{1}, \\ldots, X_{n} \\stackrel{i.i.d.}{\\sim} f(x \\mid \\eta)\\), where \\(\\{f(x \\mid \\eta)\\}_{\\eta \\in \\mathcal{E}}\\) is a full rank, \\(k\\)-parameter exponential family. Show that\n    \\begin{enumerate}[(a)]\n        \\item \\(\\{f(\\mathbf{x} \\mid \\eta)\\}_{\\eta \\in \\mathcal{E}}\\) is a full rank, \\(k\\)-parameter exponential family; \n        \\item \\(\\sum_{i=1}^{n} T\\left(X_{i}\\right)\\) is minimal sufficient for \\(\\eta\\). \n        \\item Conclude that, under i.i.d. measurements, the dimension of the minimal sufficient statistic is independent of the sample size \\(n\\). In other words, canonical exponential families display a strong dimension reduction property. \n    \\end{enumerate}\n    \\rmk{1} One question of interest is: what other families of distributions permit dimension reduction in the sense described in part (c) of this problem? The Darmois-Koopman-Pitman theorem, stated below without proof, answers this question. Under certain regularity assumptions, only exponential families have this property!\n    \n    \\thm{1} (Darmois-Koopman-Pitman theorem; Theorem 1.6.18 in Lehmann and Casella (1998), p.40). Suppose that the following assumptions hold.\n    \\begin{enumerate}[(a)]\n        \\item \\(X_{1}, \\ldots, X_{n} \\stackrel{i.i.d. }{\\sim} f\\left(x_{1} \\mid \\theta\\right)\\), where \\(f\\left(x_{1} \\mid \\theta\\right)\\) is a.c.; \n        \\item \\(\\operatorname{supp}_{\\theta} f\\left(x_{1} \\mid \\theta\\right)\\) is an interval; \n        \\item for \\(f(\\boldsymbol{x} \\mid \\theta)=\\prod_{i=1}^{n} f\\left(x_{i} \\mid \\theta\\right)\\), there exists a continuous \\(k\\)-dimensional sufficient statistic, where \\(k<n\\). \n    \\end{enumerate}\n    Then,\n    \\begin{enumerate}[(i)]\n        \\item if \\(k=1\\), then there are functions \\(\\eta_{1}(\\cdot), B(\\cdot), h(\\cdot)\\) such that\n        \\[\n        f(\\boldsymbol{x} \\mid \\theta)=h(\\boldsymbol{x}) \\exp \\left\\{\\eta_{1}(\\theta) T_{1}(\\boldsymbol{x})-B(\\theta)\\right\\}. \n        \\]\n        \\item if \\(k \\geq 2\\) and \\(f\\left(x_{1} \\mid \\theta\\right)\\) has continuous partial derivatives with respect to \\(x_{1}\\), then there exist functions \\(\\eta_{i}(\\cdot), B(\\cdot), h(\\cdot)\\) such that\n        \\[\n        f(\\boldsymbol{x} \\mid \\theta)=h(\\boldsymbol{x}) \\exp \\left\\{\\sum_{i=1}^{s} \\eta_{i}(\\theta) T_{i}(\\boldsymbol{x})-B(\\theta)\\right\\}, \\quad s \\leq k .\n        \\]\n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item Knowing that \n        \\[\n            f(x_i|\\eta)=h(x_i)\\exp\\left(\\eta^T T(x_i)-A(\\eta)\\right). \n        \\]\n        And the space for $\\eta$ is $k$-dimension. So, \\[\n            f(x|\\eta)=\\prod_{i=1}^n h(x_i)\\cdot\\exp\\left(\\eta^T\\sum_{i=1}^nT(x_i)-nA(\\eta)\\right). \n        \\]\n        Its parameter space is also $k$-dimension. So, $f(x|\\eta)$ is full rank. \n        \\item For $x\\neq y$, \n        \\[\n            \\frac{f(x|\\eta)}{f(y|\\eta)}=\\exp\\left(\\eta^T\\left(\\sum_{i=1}^nT(x_i)-\\sum_{i=1}^nT(y_i)\\right)\\right). \n        \\]\n        So, $\\sum_{i=1}^nT(x_i)$ is minimal sufficient. \n        \\item Because the parameter space is $k$-dimension, the dimension for minimal sufficient statistic $\\sum_{i=1}^nx_i$ is at most $k$-dimension, which is independent with $n$. \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Let \\(Z_{1}, \\ldots, Z_{n} \\stackrel{i.i.d. }{\\sim} F(z)\\), where \\(F(z)\\) is a c.d.f. that is continuous at zero. Let \\(X_{i}=\\sigma Z_{i}\\), \\(i=1, \\ldots, n\\). Show that \\(\\left(X_{1} / X_{n}, \\ldots, X_{n-1} / X_{n}\\right)^{T}\\) is ancillary for \\(\\sigma\\).\n\\end{ex}\n\n\\begin{solution}\n    \\[\n        \\frac{X_i}{X_n}=\\frac{Z_i}{Z_n}\n    \\]\n    it doesn't depend on $\\sigma$. So, \\(\\left(X_{1} / X_{n}, \\ldots, X_{n-1} / X_{n}\\right)^{T}\\) is ancillary for \\(\\sigma\\). \n\\end{solution}\n\n\\begin{ex}\n    Let \\(X_{1}, \\ldots, X_{n} \\stackrel{i.i.d. }{\\sim} U[\\theta, \\theta+1]\\), \\(\\theta \\in \\mathbb{R}\\) (i.e., the location family generated by a \\(U[0,1]\\) distribution). \n    \\begin{enumerate}\n        \\item Show that the vector and univariate statistics\n        \\[\n        T(\\mathbf{X})=\\left(X_{(n)}-X_{(1)}, \\frac{X_{(1)}+X_{(n)}}{2}\\right)^{T}, \\quad V(\\mathbf{X})=X_{(n)}-X_{(1)}\n        \\]\n        are, respectively, minimal sufficient and ancillary for \\(\\theta\\). \n        \\item Conclude that \\(T(\\mathbf{X})\\) and \\(V(\\mathbf{X})\\) are dependent (a paradoxical conclusion!). \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}\n        \\item $p(x_i|\\theta)=\\mathbf{1}_{\\theta\\leqslant x_i\\leqslant \\theta+1}$, \n        \\[\n            p(x)=\\prod_{i=1}^n\\mathbf{1}_{\\theta\\leqslant x_i\\leqslant \\theta+1}=\\mathbf{1}_{\\theta\\leqslant x_{(1)}, x_{(n)}\\leqslant \\theta+1}. \n        \\]\n        \n        Let $R=X_{(n)}-X_{(1)}$, $M=\\frac{X_{(1)}+X_{(n)}}{2}$. Then $X_{(1)}=\\frac{2M-R}{2}$, $X_{(n)}=\\frac{2M+R}{2}$. The joint density function for $X_{(1)}$ and $X_{(n)}$ is \n        \\[\n            g(x_{(1)}, x_{(n)})=n(n-1)(x_{(n)}-x_{(1)})^{n-2}. \n        \\]\n        Replace $X_{(1)}, X_{(n)}$ with $M$ and $R$. We can get \n        \\[\n            g(M,R)=n(n-1)(R)^{n-2}. \n        \\]\n        So, \\[\n            g(M)=n, \\qquad g(R)=n(n-1)R^{n-2}(1-R). \n        \\]\n        Both of them are independent with $\\theta$. So, they are ancillary. \n\n        \\item Obviously, $g(M)\\cdot g(R)\\neq g(M,R)$. \n    \\end{enumerate}\n    \n\\end{solution}\n\n\\begin{ex}\n    Let \\(X_{1}, \\ldots, X_{n} \\stackrel{i.i.d. }{\\sim} \\mathcal{N}\\left(\\sigma, \\sigma^{2}\\right), \\sigma>0, n \\geq 2\\). As seen in class,\n\\[\nT(\\mathbf{X})=\\left(\\sum_{i=1}^{n} X_{i}^{2}, \\sum_{i=1}^{n} X_{i}\\right)^{T}\n\\]\nis minimal sufficient. We now show that \\(T(\\mathbf{X})\\) is not complete. \n    \\begin{enumerate}[(a)]\n        \\item Let \\(\\delta_{1}(\\mathbf{X})=\\bar{X}\\). Show that \\(\\mathbb{E}\\left(\\delta_{1}(\\mathbf{X}) \\mid \\sigma\\right)=\\sigma\\). \n        \\item Let\n        \\[\n        \\delta_{2}(\\mathbf{X})=\\sqrt{\\frac{n-1}{2}} \\frac{\\Gamma((n-1) / 2)}{\\Gamma(n / 2)} \\sqrt{S^{2}}\n        \\]\n        Show that \\(\\mathbb{E}\\left(\\delta_{2}(\\mathbf{X}) \\mid \\sigma\\right)=\\sigma\\). \n        \\item Set \\(g\\left(t_{1}, t_{2}\\right)=t_{1}-t_{2}\\) and conclude that \\(T(\\mathbf{X})\\) is not complete. \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item From the Large Number Theorem, we know that $\\bar{X}\\sim N(\\sigma, \\sigma^2/n)$. So, \n        \\[\n            \\mathbf{E}(\\bar{X})=\\sigma. \n        \\]\n        \\item \\[S^2=\\frac{1}{n-1}\\sum_{i=1}^n(X_i-\\bar{X})^2\\]\n        \\[\n            \\frac{(n-1)S^2}{\\sigma^2}=\\sum_{i=1}^n(\\frac{X-\\bar{X}}{\\sigma})^2\\sim\\chi_n^2. \n        \\]\n        So, $\\mathbf{E}(S)=\\sigma\\sqrt{\\frac{2}{n-1}}\\cdot \\frac{\\Gamma(n/2)}{\\Gamma((n-1)/2)}$. Then, we have\n        \\[\n            \\mathbf{E}(\\delta_2(X)|\\sigma)=\\sigma. \n        \\]\n        \\item $\\mathbf{E}(\\delta_1(X)-\\delta_2(X))=0$, but $\\Pr(\\delta_1(X)-\\delta_2(X))=\\Pr(\\bar{X}-\\delta_2(X))\\neq 1$. \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Let \\(Y_{1}, \\ldots, Y_{n}\\) be independent random variables, each with distribution \\(Y_{i} \\sim B\\left(n_{i}, p_{i}\\right)\\), \\(i=1, \\ldots, n\\). To fix ideas, make the additional assumptions\n    \\begin{itemize}\n        \\item \\(n=2, n_{1}=2, n_{2}=1 ;\\)\n        \\item \\(p_{i}=p_{i}\\left(x_{i}\\right)=1-e^{-\\theta x_{i}} \\in[0,1), \\theta>0, x_{i} \\geq 0, i=1,2\\) (example: \\(x_{i}\\) represents the chosen level of a medication, \\(p_{i}\\left(x_{i}\\right)\\) is the probability a patient recovers and \\(Y_{i}\\) is the number of patients who recover); \n        \\item \\(x_{1}:=1<2=: x_{2}\\).\n    \\end{itemize}\n    \\begin{enumerate}[(a)]\n        \\item Express \\(\\eta_{2}(\\theta)\\) as a function of \\(\\eta_{1}(\\theta)\\) and conclude that the model forms a curved exponential family. \n        \\item Show that \\(\\mathbf{Y}=\\left(Y_{1}, Y_{2}\\right)^{T}\\) is minimal sufficient for \\(\\theta\\). \n        \\item Use the statistic \\(1_{\\left\\{Y_{1}=0\\right\\}}-1_{\\left\\{Y_{2}=0\\right\\}}\\) to conclude that \\(\\mathbf{Y}\\) is not complete. \n        \\item Please solve the following conundrum. The technical condition used in part (b) implies the minimal sufficiency of \\(T(\\mathbf{Y})=\\mathbf{Y}\\) and also that \\(\\mathcal{E}\\) is not contained in a unidimensional hyperplane. Therefore, by Problem set \\#1, \\(\\operatorname{int}(\\mathcal{E}) \\neq \\emptyset\\), which, in turn, implies the completeness of \\(T(\\mathbf{Y})=\\mathbf{Y}\\). What is going on? \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item \\[f(y_1=k_1)=\\binom{2}{k_1}p_1^{k_1}(1-p_1)^{2-k_1}, \\]\n        \\[f(y_2=k_2)=\\binom{1}{k_2}p_2^{k_2}(1-p_2)^{1-k_2}=p_2^{k_2}(1-p_2)^{1-k_2}. \\]\n        \\item \\[\n            \\begin{aligned}\n                &\\quad\\, f(y_1=k_1, y_2=k_2)\\\\\n                &=f(y_1=k_1)f(y_2=k_2)\\\\\n                &=\\binom{2}{k_1}\\exp\\left(k_1\\left(\\ln\\left(1-e^{-\\theta}\\right)+\\theta\\right)+k_2\\left(\\ln\\left(1-e^{-2\\theta}\\right)+2\\theta\\right)-4\\theta\\right). \n            \\end{aligned}\n        \\]\n        \\[\n            \\begin{aligned}\n                &\\frac{f(y_1=k_1, y_2=k_2)}{f(y_1=m_1, y_2=m_2)}\\\\\n                ={}&{}\\frac{\\binom{2}{k_1}}{\\binom{2}{m_1}}\\exp\\left((k_1-m_1)\\left(\\ln\\left(1-e^{-\\theta}\\right)+\\theta\\right)+(k_2-m_2)\\left(\\ln\\left(1-e^{-2\\theta}\\right)+2\\theta\\right)\\right), \n            \\end{aligned}\n        \\]\n        If we want this ratio doesn't depend on $\\theta$, then $k_1=m_1$, $k_2=m_2$. $Y=(Y_1,Y_2)$ is minimal statistic. \n        \\item \\[\n            \\mathbf{E}(1_{Y_1=0})=\\Pr(Y_1=0)=(1-p_1)^2=e^{-2\\theta}. \n        \\]\n        \\[\n            \\mathbf{E}(1_{Y_2=0})=\\Pr(Y_2=0)=(1-p_2)^2=e^{-2\\theta}. \n        \\]\n        So, $\\mathbf{E}(1_{Y_1=0}-1_{Y_2=0})=\\mathbf{E}(f(Y))=0$. But $\\Pr(1_{Y_1=0}-1_{Y_2=0})\\neq 1$. \n        \\item I think the $\\mathcal{E}$ is the parameter space of canonical form, and because it is curved, int$(\\mathcal{E})=\\emptyset$. \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Let \\(X_{1}, \\ldots, X_{n} \\stackrel{i.i.d. }{\\sim} \\operatorname{Poi}(\\lambda)\\), \\(\\lambda>0\\). Prove directly - i.e., without resorting to exponential families - that the statistic \\(T(\\mathbf{X})=\\sum_{i=1}^{n} X_{i}\\) is complete for \\(\\lambda\\). \n\\end{ex}\n\n\\begin{solution}\n    Knowing that  \n    \\[\n        \\bar{X}\\sim N\\left(\\lambda, \\frac{\\lambda}{n}\\right), \\qquad T=\\sum_{i=1}^nX_i\\sim N\\left(n\\lambda, n\\lambda\\right). \n    \\]\n    For some function $f(T)$, \n    \\[\n        \\mathbf{E}(f(T))=\\sum f(t)\\frac{1}{\\sqrt{2\\pi n\\lambda}}e^\\frac{-(t-n\\lambda)^2}{2n\\lambda}=0. \n    \\]\n    Because $\\frac{1}{\\sqrt{2\\pi n\\lambda}}e^\\frac{-(t-n\\lambda)^2}{2n\\lambda}>0$. So, $f(t)=0$, i.e. $\\Pr(f(t)=0)=1$, a.s. \n\\end{solution}\n\n\\begin{ex}\n    Let \\(Y_{1}, \\ldots, Y_{n} \\stackrel{i.i.d. }{\\sim} E(\\eta, 1), \\eta \\in \\mathbb{R}\\), namely, a shifted exponential distribution, which has density\n    \\[\n    f_{Y_{1}}(y)=e^{-(y-\\eta)} 1_{(\\eta, \\infty)}(y), \\quad y \\in \\mathbb{R} .\n    \\]\n    Let \\(X_{i}=e^{-Y_{i}}, i=1, \\ldots, n\\), and \\(\\theta=e^{-\\eta}\\)\n    \\begin{enumerate}\n        \\item Show that \\(X_{1}, \\ldots, X_{n} \\stackrel{i.i.d. }{\\sim} U[0, \\theta], \\theta>0\\). \n        \\item Conclude that \\(X_{(n)}\\) is complete for \\(\\theta\\) or \\(\\eta\\). \n        \\item Now consider \\(Y_{(1)}=-\\log X_{(n)}\\). Show that \\(Y_{(1)}\\) is complete for \\(\\eta\\). \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}\n        \\item \\[\n            F(y\\leqslant Y)=\\int_\\eta^ye^{-t+\\eta}\\der t= 1-e^{-y+\\eta}. \n        \\]\n        \\[\n            \\begin{aligned}\n                \\Pr(x_i\\leqslant X_i)&=\\Pr(e^{-y_i}\\leqslant X_i)\\\\\n                &=\\Pr(y_i\\geqslant -\\ln(X_i))\\\\\n                &=e^{\\ln(X_i)+\\eta}=\\frac{1}{\\theta}X_i. \n            \\end{aligned}\n        \\]\n        So, we can know that \\(f(x_i)=\\frac{1}{\\theta}\\). \n        \\item $f_{X_{(n)}}(x)=nx^{n-1}\\theta^{-n}$, $0<x<\\theta$. If for some function $g(T)$, $\\mathbf{E}(g(T))=0$, then \n        \\[\n            \\begin{aligned}\n                0 &=\\frac{\\der}{\\der  \\theta} \\mathbf{E} g(T) \\\\\n                &=\\frac{\\der}{\\der  \\theta} \\int_{0}^{\\theta} g(t) n t^{n-1} \\theta^{-n} \\der  t \\\\\n                &=\\left(\\theta^{-n}\\right) \\frac{\\der}{\\der  \\theta} \\int_{0}^{\\theta} n g(t) t^{n-1} \\der  t+\\left(\\frac{\\der}{\\der  \\theta} \\theta^{-n}\\right) \\int_{0}^{\\theta} n g(t) t^{n-1} \\der  t\\\\\n                &=\\frac{ng(\\theta)}{\\theta}. \n            \\end{aligned}\n        \\]\n        And because $\\theta>0$, $n>0$. So, $g(\\theta)=0$. Then, $T$ is complete. \n        \\item They are equivalent, and $Y_{(1)}$ is complete for $\\eta$. \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Let \\(\\mathcal{P}\\) be a family of probability measures. If \\(T\\) is complete for \\(\\mathcal{P}\\) and \\(U\\) is equivalent to \\(T\\), show that \\(U\\) is complete for \\(\\mathcal{P}\\). \n\\end{ex}\n\n\\begin{solution}\n    Let $f(t)$ be the distribution of $T$ and $T=m(U)$. Then $f^*(u)=f(m(U))m'(U)$. For $T$, if it is complete, then for any function $g(T)$, \n    \\[\n        \\int g(t)f(t)\\der t=0 \\Rightarrow \\Pr(g(t)=0)=1. \n    \\]\n    Substitute $t$ with $m(u)$. Then, \n    \\[\n        \\begin{aligned}\n            &\\quad\\,\\int g(m(u))f(m(u))\\der (m(u))\\\\\n            &=\\int g(m(u))f(m(u))m'(u)\\der u\\\\\n            &=\\int g(m(u))f^*(u)\\der u=0\\Rightarrow \\Pr(g(m(u))=0)=1. \n        \\end{aligned}\n    \\]\n    And because the arbitrary of $g$, $g(m(u))$ can be taken as any function of $u$. So, $U$ is also complete. \n\\end{solution}\n\n\\begin{ex}\n    Let \\(X_{1}, \\ldots, X_{n} \\stackrel{i.i.d. }{\\sim} \\mathcal{N}\\left(\\mu, \\sigma^{2}\\right)\\), \\(\\mu \\in \\mathbb{R}, \\sigma^{2}>0 .\\) Show that \\(\\bar{X}\\) and \\(S^{2}\\) are independent. \n    \n    (\\rmk{2}: this classical result can be shown by means of characteristic functions. However, in the context of our course, a much shorter proof can be provided). \n\\end{ex}\n\n\\begin{solution}\n    We know that $(\\bar{X}, S^2)$ are sufficient. And $\\bar{X}\\sim N(\\mu,\\sigma^2/n)$. So, $\\bar{X}$ is complete for $\\mu$ (Because $N(\\mu,\\sigma^2/n)$ is full rank exponential family). \n        \n    And $S^2$ only depends on $\\sigma^2$ (Because $\\frac{(n-1)S^2}{\\sigma^2}=\\sum_{i=1}^n(\\frac{X-\\bar{X}}{\\sigma})^2\\sim\\chi_n^2$), it is an ancillary statistic. So, from Basu's theorem, they are independent. \n\\end{solution}\n", "meta": {"hexsha": "6e4f033371b8f46ed024a49d088e52f78536d21e", "size": 14162, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Statistics/Problem Set/set3.tex", "max_stars_repo_name": "Addasecond86/MS-Stat-Tulane", "max_stars_repo_head_hexsha": "3af55f890c0dedfed7a4614665730002b4c3a370", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Mathematical Statistics/Problem Set/set3.tex", "max_issues_repo_name": "Addasecond86/MS-Stat-Tulane", "max_issues_repo_head_hexsha": "3af55f890c0dedfed7a4614665730002b4c3a370", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mathematical Statistics/Problem Set/set3.tex", "max_forks_repo_name": "Addasecond86/MS-Stat-Tulane", "max_forks_repo_head_hexsha": "3af55f890c0dedfed7a4614665730002b4c3a370", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.6439393939, "max_line_length": 411, "alphanum_fraction": 0.5495692699, "num_tokens": 5345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346599, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7062408979657798}}
{"text": "\\subsection{Semirings}\\label{subsec:semirings}\n\nWe will start by defining semirings, and to do that we will first motivate distributivity.\n\n\\begin{proposition}\\label{thm:monoid_distributivity}\n  Fix an \\hyperref[rem:additive_magma/multiplication]{additive} \\hyperref[def:monoid]{monoid} \\( (R, +, \\cdot) \\), where \\( +: R \\times R \\to R \\) is the monoid operation and \\( \\cdot: \\BbbN \\times R \\to R \\) is defined via \\eqref{eq:rem:additive_magma/multiplication}.\n\n  We have the following property, which we call \\term{distributivity} of \\( \\cdot \\) over \\( + \\):\n  \\begin{equation}\\label{eq:thm:monoid_distributivity}\n    n \\cdot (x + y) = n \\cdot x + n \\cdot y.\n  \\end{equation}\n\\end{proposition}\n\\begin{proof}\n  We use induction on \\( n \\). The case \\( n = 0 \\) is trivial. Suppose that \\eqref{eq:thm:monoid_distributivity} holds. Then\n  \\begin{equation*}\n    (n + 1) \\cdot (x + y)\n    \\reloset {\\eqref{eq:def:magma/exponentiation}} =\n    n \\cdot (x + y) + (x + y)\n    \\reloset {\\T{ind.}} =\n    n \\cdot x + n \\cdot y + (x + y)\n    \\reloset {\\eqref{eq:def:magma/exponentiation}} =\n    (n + 1) \\cdot x + (n + 1) \\cdot y.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:semiring}\\mcite[1]{Golan2010}\n  A \\term{semiring} is a \\hyperref[def:magma/commutative]{commutative} \\hyperref[def:monoid]{monoid} \\( (R, +) \\) with a second \\hyperref[def:magma/associative]{associative} operation \\( \\cdot: R \\times R \\to R \\) called \\term{multiplication}, which extends multiplication with natural numbers. The precise compatibility axioms are listed in \\fullref{def:semiring/theory} because they fit nicely into first-order logic (unlike the \\hyperref[def:semimodule/theory]{theory of semimodules}, for example, for which we prefer expressing these conditions in the metalogic).\n\n  Although not strictly necessary, it will be convenient for us to assume that multiplication has an identity. If a multiplicative identity does not exist, we call \\( (R, +, \\cdot) \\) a \\term{nonunital semiring}. A canonical example of a nonunital semiring is a \\hyperref[def:semiring_ideal]{semiring ideal}. We will not use nonunital semirings, but it is important to acknowledge their existence. In this context, if an identity exists, we will sometimes call \\( (R, + \\cdot) \\) a \\term{unital semiring}.\n\n  We call \\( (R, +) \\) the \\term{additive monoid} and \\( (R, \\cdot) \\) the \\term{multiplicative monoid} of the semiring. We also consider the \\term{additive group} and the \\term{multiplicative group} as the subsets of \\hyperref[def:monoid_inverse]{invertible} elements. Both are instances of \\fullref{thm:invertible_submonoid_is_group}. The multiplicative group is denoted by \\( R^\\times \\); it is discussed further in \\hyperref[def:divisibility/unit]{units}.\n\n  Semirings have the following metamathematical properties:\n  \\begin{thmenum}\n    \\thmitem{def:semiring/theory} The \\hyperref[def:first_order_theory]{first-order theory} for semirings extends the \\hyperref[def:monoid/theory]{theory of monoids}.\n\n    First, we add another \\hyperref[rem:first_order_formula_conventions/infix]{infix} binary functional symbol \\( \\cdot \\) and a constant \\( 1 \\). The notation for the constant is justified by \\fullref{thm:semiring_characteristic_homomorphism}.\n\n    We then extend the theory of monoids with \\hyperref[def:magma/commutative]{commutativity} for \\( + \\), \\hyperref[def:magma/associative]{associativity} for \\( \\cdot \\), and the following axioms:\n    \\begin{thmenum}\n      \\thmitem{def:semiring/left_distributivity} Multiplication on the left distributes over addition:\n      \\begin{equation}\\label{eq:def:semiring/left_distributivity}\n        \\xi \\cdot (\\eta + \\zeta) \\doteq \\xi \\cdot \\eta + \\xi \\cdot \\zeta.\n      \\end{equation}\n\n      \\thmitem{def:semiring/right_distributivity} Multiplication on the right also distributes over addition:\n      \\begin{equation}\\label{eq:def:semiring/right_distributivity}\n        (\\xi + \\eta) \\cdot \\zeta \\doteq \\xi \\cdot \\zeta + \\eta \\cdot \\zeta.\n      \\end{equation}\n\n      If multiplication is commutative, right distributivity follows from left distributivity.\n\n      \\thmitem{def:semiring/absorption} Zero is an absorbing element:\n      \\begin{equation}\\label{eq:def:semiring/absorption}\n        \\xi \\cdot 0 \\doteq 0 \\wedge 0 \\cdot \\xi \\doteq 0.\n      \\end{equation}\n\n      \\thmitem{def:semiring/identity} We also restate the identity axiom \\eqref{eq:def:monoid/theory/identity} for the multiplicative unit \\( 1 \\) to highlight its connection with \\eqref{eq:def:semiring/absorption}:\n      \\begin{equation}\\label{eq:def:semiring/identity}\n        \\xi \\cdot 1 \\doteq \\xi \\wedge 1 \\cdot \\xi \\doteq \\xi.\n      \\end{equation}\n    \\end{thmenum}\n\n    \\thmitem{def:semiring/homomorphism} A \\hyperref[def:first_order_homomorphism]{first-order homomorphism} from the semiring \\( R \\) to \\( T \\) is a function \\( \\varphi: R \\to T \\) that is a \\hyperref[def:monoid/homomorphism]{monoid homomorphism} both for their additive monoids also for their multiplicative monoids.\n\n    \\thmitem{def:semiring/submodel} The set \\( A \\subseteq R \\) is a \\hyperref[thm:substructure_is_model]{submodel} of \\( R \\) if it is a both \\hyperref[def:monoid/submodel]{submonoid} of the additive monoid and also of the multiplicative monoid. We call \\( A \\) a \\term{sub-semiring}.\n\n    As a consequence of \\fullref{thm:positive_formulas_preserved_under_homomorphism}, the \\hyperref[def:multi_valued_function/image]{image} of a homomorphism \\( \\varphi: R \\to T \\) is a sub-semiring of \\( A \\).\n\n    For an arbitrary set \\( A \\), we denote the \\hyperref[def:first_order_generated_substructure]{generated submodel} by \\( \\braket{ A } \\).\n\n    \\thmitem{def:semiring/trivial} The \\hyperref[thm:substructures_form_complete_lattice/bottom]{trivial} semiring is the \\hyperref[def:pointed_set/trivial]{trivial pointed set} \\( \\set{ 0 } \\).\n\n    See \\fullref{ex:def:semiring/trivial} for some properties of the trivial semiring.\n\n    \\thmitem{def:semiring/exponentiation} As we shall see in \\fullref{thm:semiring_characteristic_homomorphism}, multiplication in \\( \\cdot \\) extends left multiplication with natural numbers in the monoid \\( (R, +) \\). We do have a third operation, however --- \\hyperref[def:monoid/exponentiation]{monoid exponentiation} in \\( (R, \\cdot) \\).\n\n    For any integer \\( n \\), we have the fundamental property \\( 1^n = 1 \\).\n\n    \\thmitem{def:semiring/commutative} If multiplication is commutative, we call the semiring itself \\term{commutative}. Unless multiplication corresponds to function composition, most semirings we will encounter will be commutative.\n\n    Notable exceptions to this rule are \\hyperref[def:ordinal]{ordinals}. A \\hyperref[def:successor_and_limit_ordinal]{limit ordinal} \\( \\alpha \\), regarded as the set of all smaller ordinals, is a semiring. It is not commutative, however, as shown in \\fullref{ex:ordinal_addition}.\n\n    \\thmitem{def:semiring/power_set} Similarly to power set magmas defined in \\fullref{def:magma/power_set}, the power set \\( \\pow(R) \\) of a semiring is also a semiring with the operations\n    \\begin{align*}\n      A \\oplus B &\\coloneqq \\set{ x + y \\given x \\in A \\T{and} y \\in B } \\\\\n      A \\odot B  &\\coloneqq \\set{ x \\cdot y \\given x \\in A \\T{and} y \\in B }\n    \\end{align*}\n\n    \\thmitem{def:semiring/category} The corresponding \\hyperref[def:category_of_small_first_order_models]{category of \\( \\mscrU \\)-small models} \\( \\ucat{SRing} \\) is \\hyperref[def:concrete_category]{concrete} over \\hyperref[def:monoid]{\\( \\ucat{CMon} \\)} with the forgetful functor taking the additive monoids. We denote the category of commutative semirings by \\( \\cat{CSRing} \\).\n\n    \\thmitem{def:semiring/opposite}\\mcite[555]{Knapp2016BasicAlgebra} The \\term{opposite semiring} of \\( (R, +, \\cdot) \\) is the semiring \\( (R, +, \\star) \\), with multiplication defined as \\( x \\star y = y \\cdot x \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{remark}\\label{rem:semiring_etymology}\n  In \\fullref{def:semiring}, we require semirings to have both an additive identity and a multiplicative identity. This is not consistent with semigroups defined in \\fullref{def:magma/associative}, which in general do not have identities.\n\n  \\cite[ch. 3]{GondranMinoux1984Graphs} suggest using \\enquote{dioid} (short for \\enquote{double monoid}) instead of \\enquote{semiring}. \\cite[xi]{Golan2010} describes how the term \\enquote{dioid} may refer to semirings with idempotent addition, i.e. a general form of the tropical semirings defined in \\fullref{def:tropical_semiring}.\n\n  We thus prefer using the term \\enquote{semiring} as we have defined it in \\fullref{def:semiring}.\n\\end{remark}\n\n\\begin{example}\\label{ex:def:semiring}\n  We list several examples of \\hyperref[def:semiring]{semirings} that are not \\hyperref[def:ring]{rings}.\n\n  \\begin{thmenum}\n    \\thmitem{ex:def:semiring/trivial} A \\hyperref[def:semiring/homomorphism]{semiring} is trivial if and only if \\( 0_R = 1_R \\). This follows from \\eqref{eq:def:semiring/absorption} and \\eqref{eq:def:semiring/identity}.\n\n    As a consequence, if \\( \\varphi: \\set{ 0 } \\to R \\) is a \\hyperref[def:semiring/homomorphism]{semiring} homomorphism, \\( R \\) is a trivial semiring. This is further strengthened by \\fullref{thm:semiring_embedding_preserves_characterstic}.\n\n    \\thmitem{ex:def:semiring/natural_numbers} The \\hyperref[def:set_of_natural_numbers]{natural numbers} are the quintessential example of a semiring. We prove in \\fullref{thm:natural_number_multiplication_properties} that they are a semiring.\n\n    \\thmitem{ex:def:semiring/ordinals} Every \\hyperref[def:successor_and_limit_ordinal]{limit ordinal} is a monoid under addition, as discussed in \\fullref{ex:def:semiring/ordinals}, however it is not commutative.\n\n    \\hyperref[def:cardinal_arithmetic/addition]{Cardinal addition} is commutative, however, and hence for every \\hyperref[def:successor_and_limit_cardinal/weak_limit]{limit cardinal} \\( \\kappa \\), the set of all cardinals smaller than \\( \\kappa \\) are a semiring.\n\n    \\thmitem{ex:def:semiring/lattice} We discussed in \\fullref{ex:def:monoid/semilattice} that in a \\hyperref[def:semilattice/bounded]{bounded lattice} \\( (X, \\vee, \\wedge, \\top, \\bot) \\), both \\( (X, \\vee, \\bot) \\) and \\( (X, \\wedge, \\top) \\) are monoids.\n\n    As a consequence of \\fullref{thm:bounded_lattice_absorbing}, \\( \\bot \\) is absorbing with respect to \\( \\wedge \\) and \\( \\top \\) with respect to \\( \\vee \\). Therefore, if the lattice is \\hyperref[def:semilattice/distributive_lattice]{distributive}, as a consequence of \\fullref{thm:bounded_lattice_absorbing}, both \\( (X, \\vee, \\wedge) \\) and \\( (X, \\wedge, \\vee) \\) are semirings.\n\n    We refer to these semirings are the positive and negative semiring of the lattice. This terminology comes from \\fullref{ex:def:ordered_semiring/lattice}.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{definition}\\label{def:tropical_semiring}\\mcite[exmpl. 1.12]{Golan2010}\n  Consider the additive monoid \\( (\\BbbN, +) \\) of natural numbers or, more generally, an \\hyperref[def:ordered_magma]{ordered} \\hyperref[def:magma/commutative]{commutative} \\hyperref[def:monoid]{monoid} \\( (M, +, \\leq) \\).\n\n  We adjoin a \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{top element} \\( \\infty \\) to \\( M \\) that is absorbing with respect to addition. That is, \\( x + \\infty = \\infty \\) for every \\( x \\in M \\).\n\n  The \\( \\min \\)-plus semiring over \\( M \\) is the triple \\( (M \\cup \\set{ \\infty }, \\min, +) \\). The \\hyperref[def:partially_ordered_set_extremal_points/maximum_and_minimum]{minimum} as a binary operation plays the role of semiring addition, with \\( \\infty \\) as the zero element. The usual addition in \\( M \\) extended with \\( \\infty \\) plays the role of semiring multiplication, with \\( 0 \\) as the multiplicative identity.\n\n  We analogously define the \\( \\max \\)-plus semiring, adjoining a \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bottom element} \\( -\\infty \\) rather than a top element \\( \\infty \\).\n\n  We will sometimes use \\enquote{tropical semiring} to refer to either type of semirings. See \\fullref{rem:tropical_semiring_etymology}.\n\\end{definition}\n\\begin{defproof}\n  We will only show \\hyperref[def:semiring/left_distributivity]{distributivity}. If \\( x \\leq y \\), since \\( \\leq \\) is compatible with \\( + \\), we have\n  \\begin{equation*}\n    \\underbrace{\\min\\set{ x, y }}_{x} + z = x + z \\leq y + z.\n  \\end{equation*}\n\n  Therefore,\n  \\begin{equation*}\n    \\min\\set{ x, y } + z = \\min\\set{ x + z , y + z }.\n  \\end{equation*}\n\\end{defproof}\n\n\\begin{remark}\\label{rem:tropical_semiring_etymology}\n  \\hyperref[def:tropical_semiring]{\\( \\min \\)-plus} and \\( \\max \\)-plus semirings are sometimes referred to as the \\term{tropical semirings}. This term is ambiguous, unfortunately, but it gives rise to the terms \\enquote{tropical geometry} and \\enquote{tropical optimization}.\n\n  According to \\cite{Pin1994}, the name \\enquote{tropical semiring} is a dedication to the Brazilian-born Imre Simon. The paper also introduces the terms \\enquote{tropical integers}, \\enquote{tropical reals}, etc. \\cite[3]{Golan2010} refers to the more general notion of additively-idempotent semirings. Both reserve the term \\enquote{tropical semiring} for the case where \\( M = \\BbbN \\). \\cite[ch. 3]{GondranMinoux1984Graphs} does not explicitly use the word \\enquote{tropical}, but instead refers to semirings as \\enquote{dioids}, and the latter term sometimes refers to additively-idempotent semirings.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:semiring_characteristic_homomorphism}\n  For every \\hyperref[def:semiring/identity]{semiring}, multiplication extends the abelian group multiplication.\n\n  More precisely, denote the additive identity by \\( 0_R \\) and the multiplicative identity by \\( 1_R \\). Define the following semiring homomorphism:\n  \\begin{equation}\\label{eq:thm:semiring_characteristic_homomorphism}\n    \\begin{aligned}\n      &\\iota: \\BbbN \\to R \\\\\n      &\\iota(n) \\coloneqq \\begin{cases}\n        0_R                &n = 0, \\\\\n        \\iota(n - 1) + 1_R &n > 0.\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation}\n\n  This is the unique homomorphism from \\( \\BbbN \\) to \\( R \\). Furthermore, we have the following analogue to \\eqref{eq:def:magma/exponentiation}:\n  \\begin{equation}\\label{eq:thm:semiring_characteristic_homomorphism/multiplication}\n    \\iota(n) \\cdot x \\coloneqq \\begin{cases}\n      0_R,                      &n = 0, \\\\\n      \\iota(n - 1) \\cdot x + x, &n > 1.\n    \\end{cases}\n  \\end{equation}\n\\end{proposition}\n\\begin{proof}\n  First note that \\eqref{eq:thm:semiring_characteristic_homomorphism/multiplication} follows from \\eqref{eq:thm:semiring_characteristic_homomorphism} via \\hyperref[def:semiring/right_distributivity]{right distributivity}.\n\n  It remains to show that \\( \\iota \\) is a monoid homomorphism, and that it is unique. Clearly \\( \\iota(0) = 0_R \\) and \\( \\iota(1) = 1_R \\). Proving \\( \\iota(n + m) = \\iota(n) + \\iota(m) \\) and \\( \\iota(nm) = \\iota(n) \\cdot \\iota(m) \\) can be done via nested induction.\n\n  Now suppose \\( \\varphi: \\BbbN \\to R \\) is a homomorphism. It is clear that \\( \\varphi(0) = 0_R \\) and \\( \\varphi(1) = 1_R \\), and also\n  \\begin{equation*}\n    \\varphi(n + 1) = \\varphi(n) + \\varphi(1) = \\varphi(n) + 1_R.\n  \\end{equation*}\n\n  This implies \\( \\iota = \\varphi \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:category_of_semirings_properties}\n  The \\hyperref[def:semiring/category]{category of semirings} has the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:category_of_semirings_properties/initial} The \\hyperref[def:set_of_integers]{ring of integers} \\( \\BbbZ \\) is an \\hyperref[def:universal_objects/initial]{initial object}.\n\n    \\thmitem{thm:category_of_semirings_properties/terminal} The trivial semiring \\( \\set{ 0 } \\) is an \\hyperref[def:universal_objects/terminal]{terminal object}.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:category_of_semirings_properties/initial} Follows from \\fullref{thm:semiring_characteristic_homomorphism}.\n  \\SubProofOf{thm:category_of_semirings_properties/terminal} Follows from \\fullref{ex:def:semiring/trivial}.\n\\end{proof}\n\n\\begin{definition}\\label{def:ordered_semiring}\\mcite[224]{Golan2010}\n  An \\term{ordered semiring} is a \\hyperref[def:magma/commutative]{commutative} semiring \\( R \\) with a \\hyperref[def:partially_ordered_set]{partial order} \\( \\leq \\) such that \\( (R, +) \\) is an \\hyperref[def:ordered_magma]{ordered magma} and, additionally, \\( x \\leq y \\) and \\( 0 \\leq z \\) imply \\( xz \\leq yz \\).\n\n  As in \\fullref{def:ordered_magma}, the commutativity condition can be avoided, but then we would need to also require \\( zx \\leq zy \\).\n\n  If the semiring is \\hyperref[def:totally_ordered_set]{totally ordered}, we can use the usual terminology that is conventional for real numbers:\n  \\begin{itemize}\n    \\item \\( x \\) is \\term{positive} if \\( x > 0 \\).\n    \\item \\( x \\) is \\term{nonnegative} if \\( x \\geq 0 \\).\n    \\item \\( x \\) is \\term{negative} if \\( x < 0 \\).\n    \\item \\( x \\) is \\term{nonpositive} if \\( x \\leq 0 \\).\n  \\end{itemize}\n\\end{definition}\n\n\\begin{example}\\label{ex:def:ordered_semiring}\n  We list several examples of \\hyperref[def:ordered_semirings]{ordered semirings}.\n\n  \\begin{thmenum}\n    \\thmitem{ex:def:ordered_semiring/natural_numbers} The \\hyperref[def:set_of_natural_numbers]{natural numbers} form an ordered semiring as shown in \\fullref{thm:natural_numbers_are_well_ordered}.\n\n    \\thmitem{ex:def:ordered_semiring/lattice} We discussed in \\fullref{ex:def:semiring/lattice} that a \\hyperref[def:semilattice/bounded]{bounded} \\hyperref[def:semilattice/distributive_lattice]{distributive} \\hyperref[def:semilattice/lattice]{lattice} \\( (X, \\vee, \\wedge) \\) can be regarded as a semiring, and so can its opposite lattice.\n\n    We discussed in \\fullref{ex:def:ordered_magma/semilattice} that both \\( (X, \\vee) \\) and \\( (X, \\wedge) \\) are \\hyperref[def:ordered_magma]{ordered magmas}. Both \\( (X, \\vee, \\wedge) \\) and \\( (X, \\wedge, \\vee) \\) vacuously satisfy the condition from \\fullref{def:ordered_semiring}, which makes them ordered semirings.\n\n    All elements of the ordered semiring \\( (X, \\vee, \\wedge) \\) are nonnegative and all elements of \\( (X, \\wedge, \\vee) \\) are nonpositive. With a slight abuse of notation, we refer to them as the \\term{positive} and \\term{negative} semirings of the lattice.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{definition}\\label{def:divisibility}\\mimprovised\n  Fix an arbitrary element \\( x \\) in a \\hyperref[def:semiring]{semiring}. If there exist elements \\( l \\) and \\( r \\) such that \\( x = lr \\), we say that \\( l \\) is a \\term{left divisor} of \\( x \\), and that \\( r \\) is a \\term{right divisor}.\n\n  In a \\hyperref[def:semiring/commutative]{commutative semiring}, the two notions coincide, and we simply use the term \\enquote{divisor}. If \\( x \\) is a divisor of \\( y \\), we write \\( x \\mid y \\) and say that \\( y \\) is a \\term{multiple} of \\( x \\). Most rings we will encounter will be commutative, but it is useful to have the weaker notions of left and right divisors.\n\n  \\begin{thmenum}\n    \\thmitem{def:divisibility/zero}\\mcite[4]{Golan2010} Divisors of \\( 0 \\) are called \\term{zero divisors}. Due to \\hyperref[def:semiring/absorption]{absorption}, every semiring element is a zero divisor. If \\( lr = 0 \\) for nonzero \\( l \\) and \\( r \\), we say that \\( l \\) (resp. \\( r \\)) is a \\term{nontrivial} left (resp. right) zero divisor.\n\n    \\thmitem{def:divisibility/unit} Divisors of \\( 1 \\) are called \\term{invertible}, since they are precisely the \\hyperref[def:monoid_inverse]{monoid inverses} under multiplication. They are also sometimes called \\term{units}.\n\n    The set of all two-sided units of \\( R \\) is precisely the \\hyperref[def:semiring]{multiplicative group} \\( R^\\times \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:def:divisibility}\n  \\hfill\n  \\begin{thmenum}\n    \\thmitem{ex:def:divisibility/integers} The positive integers are commutative and their left and right divisors coincide. They have no \\hyperref[def:divisibility/zero]{nontrivial zero divisors} as a consequence of \\fullref{thm:natural_number_multiplication_properties}.\n\n    \\thmitem{ex:def:divisibility/matrix_zero_divisors} A simple example of nontrivial zero divisors is given by the \\hyperref[def:matrix_algebra]{matrix algebra} \\( \\BbbZ^{2 \\times 2} \\). We have\n    \\begin{equation*}\n      \\underbrace\n      {\n        \\begin{pmatrix}\n          0 & 1 \\\\\n          0 & 0\n        \\end{pmatrix}\n      }_{L}\n      \\underbrace\n      {\n        \\begin{pmatrix}\n          0 & 0 \\\\\n          0 & 1\n        \\end{pmatrix}\n      }_{R}\n      =\n      \\begin{pmatrix}\n        0 & 0 \\\\\n        0 & 0\n      \\end{pmatrix}.\n    \\end{equation*}\n\n    Therefore, \\( L \\) is a left zero divisor and \\( R \\) is a right zero divisor. The two do not commute because\n    \\begin{equation*}\n      \\underbrace\n      {\n        \\begin{pmatrix}\n          0 & 0 \\\\\n          0 & 1\n        \\end{pmatrix}\n      }_{R}\n      \\underbrace\n      {\n        \\begin{pmatrix}\n          0 & 1 \\\\\n          0 & 0\n        \\end{pmatrix}\n      }_{L}\n      =\n      \\begin{pmatrix}\n        0 & 0 \\\\\n        1 & 0\n      \\end{pmatrix}.\n    \\end{equation*}\n\n    Nevertheless, \\( RLRL \\) is the zero matrix, so \\( R \\) is a left zero divisor and \\( L \\) is a right zero divisor.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{proposition}\\label{thm:divisibility_and_isomorphisms}\n  Suppose that \\( R \\) and \\( S \\) are \\hyperref[def:semiring/commutative]{commutative semirings}.\n\n  \\begin{thmenum}\n    \\thmitem{thm:divisibility_and_isomorphisms/divisibility} If \\( \\varphi: R \\to S \\) is any homomorphism, then \\( x \\mid y \\) implies \\( \\varphi(x) \\mid \\varphi(y) \\). The converse holds of \\( \\varphi \\) is an isomorphism.\n\n    \\thmitem{thm:divisibility_and_isomorphisms/zero} If \\( R \\) and \\( S \\) are isomorphic, the \\hyperref[def:divisibility/zero]{zero divisors} of \\( R \\) are precisely the zero divisors of \\( S \\).\n\n    \\thmitem{thm:divisibility_and_isomorphisms/unit} If \\( R \\) and \\( S \\) are isomorphic, the \\hyperref[def:divisibility/unit]{units} of \\( R \\) are precisely the units of \\( S \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:divisibility_and_isomorphisms/divisibility} If \\( x \\mid y \\), then \\( xr = y \\) for some \\( r \\in R \\). Then \\( \\varphi(x) \\varphi(r) = \\varphi(y) \\), hence \\( \\varphi(x) \\mid \\varphi(y) \\). If \\( \\varphi \\) is an isomorphism, the converse follows by using \\( \\varphi^{-1}: S \\to R \\).\n\n  \\SubProofOf{thm:divisibility_and_isomorphisms/zero} Follows from \\fullref{thm:divisibility_and_isomorphisms/divisibility} by noting that homomorphisms preserve zeros.\n\n  \\SubProofOf{thm:divisibility_and_isomorphisms/unit} Follows from \\fullref{thm:divisibility_and_isomorphisms/divisibility} by noting that homomorphisms preserve ones.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:semiring_cancellative_iff_no_zero_divisors}\n  An element of a \\hyperref[def:semiring/commutative]{commutative semiring} is cancellable if and only if it is not a \\hyperref[def:divisibility]{zero divisor}. That is, \\( x \\mid 0 \\) if and only if \\( xy = xz \\) does not imply \\( y = z \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( x \\) be a nonzero element.\n\n  \\SufficiencySubProof Suppose that \\( x \\) is a zero divisor and let \\( y \\) be such that \\( xy = 0 \\). For any element \\( z \\), we have\n  \\begin{equation*}\n    xy = 0 = x(yz).\n  \\end{equation*}\n\n  But \\( y \\neq yz \\) unless \\( z = 1 \\). Thus, \\( x \\) is not cancellable.\n\n  \\NecessitySubProof Suppose that \\( x \\) is cancellable.\n\n  Suppose also that \\( xy = 0 \\) for some nonzero \\( y \\). Then \\( xy = x0 \\), which implies \\( y = 0 \\). But this contradicts out choice of \\( y \\).\n\n  Thus, \\( x \\) is not a zero divisor.\n\\end{proof}\n\n\\begin{definition}\\label{def:entire_semiring}\n  We say that the \\hyperref[def:semiring]{semiring} \\( R \\) is \\term{entire} if any of the following equivalent conditions hold:\n  \\begin{thmenum}\n    \\thmitem{def:entire_semiring/zero_divisors}\\mcite[4]{Golan2010} \\( R \\) has no \\hyperref[def:divisibility/zero]{nontrivial zero divisors}.\n    \\thmitem{def:entire_semiring/cancellation} \\( R \\setminus \\set{ 0_R } \\) is a \\hyperref[def:magma/cancellative]{cancellative} \\hyperref[def:monoid]{monoid} with respect to multiplication.\n  \\end{thmenum}\n\\end{definition}\n\\begin{defproof}\n  The equivalence follows from \\fullref{thm:semiring_cancellative_iff_no_zero_divisors}.\n\\end{defproof}\n\n\\begin{proposition}\\label{thm:semiring_divisibility_order}\n  In an \\hyperref[def:entire_semiring]{entire} \\hyperref[def:semiring/commutative]{commutative semiring}, the \\hyperref[def:divisibility]{divisibility} relation is a \\hyperref[def:preordered_set]{preorder}.\n\n  It is not a partial order in general. To avoid the nonuniqueness problems described in \\fullref{ex:preorder_nonuniqueness}, we instead prefer working with ideals. See \\fullref{rem:lattice_of_principal_ideals} and \\fullref{rem:lattice_of_principal_ideals} for the general approach.\n\\end{proposition}\n\\begin{proof}\n  Fix a semiring \\( R \\).\n\n  \\SubProofOf[def:binary_relation/reflexive]{reflexivity} Clearly every element of \\( R \\) divides itself.\n\n  \\SubProofOf[def:binary_relation/transitive]{transitivity} Let \\( x \\mid y \\mid z \\). Then there exist elements \\( a \\) and \\( b \\) such that \\( y = a x \\) and \\( z = b y \\). Hence, \\( z = (ba) x \\) and \\( x \\mid z \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:zerosumfree}\\mcite[4]{Golan2010}\n  We say that an \\hyperref[rem:additive_magma]{additive} \\hyperref[def:monoid]{monoid} is \\term{zerosumfree} if the \\hyperref[thm:invertible_submonoid_is_group]{additive group} is trivial. That is, if \\( x + y = 0 \\) implies \\( x = y = 0 \\).\n\\end{definition}\n\n\\begin{example}\\label{ex:def:zerosumfree}\n  We list several examples of \\hyperref[def:zerosumfree]{zerosumfree} semirings:\n  \\begin{thmenum}\n    \\thmitem{ex:def:zerosumfree/natural_numbers} By \\fullref{thm:natural_number_addition_properties}, the natural numbers are zerosumfree.\n\n    \\thmitem{ex:def:zerosumfree/lattice} We discussed in \\fullref{ex:def:semiring/lattice} that every bounded distributive lattice \\( (X, \\vee, \\wedge) \\) has two associated semirings.\n\n    We will show that the positive semiring \\( (X, \\vee, \\wedge) \\) is zerosumfree. The proof only relies on \\( \\vee \\) being idempotent. Suppose that \\( x \\vee y = \\bot \\). Then\n    \\begin{equation*}\n      \\bot\n      =\n      x \\vee y\n      \\reloset {\\eqref{eq:def:magma/idempotent}} =\n      (x \\vee x) \\vee y\n      \\reloset {\\eqref{eq:def:magma/associative}} =\n      x \\vee (x \\vee y)\n      =\n      x \\vee \\bot\n      \\reloset {\\eqref{eq:thm:binary_lattice_operations/identity/join}} =\n      x.\n    \\end{equation*}\n\n    Therefore, \\( x = \\bot \\). But \\( \\bot \\vee y = y \\), hence \\( x \\vee y = \\bot \\) implies \\( y = \\bot \\).\n\n    This demonstrates that the positive semiring is zerosumfree.\n\n    \\thmitem{ex:def:zerosumfree/tropical} The \\hyperref[def:tropical_semiring]{\\( \\min \\)-plus semiring} \\( (\\BbbN \\cup \\set{ \\infty }, \\min, +) \\) discussed in \\fullref{def:tropical_semiring} is also zerosumfree. Indeed, \\( \\min \\) is idempotent, and the proof is analogous to the one for lattices in \\fullref{ex:def:zerosumfree/lattice}.\n  \\end{thmenum}\n\\end{example}\n", "meta": {"hexsha": "cf077421fa1eea643df8b1425149891398a68944", "size": 27232, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/semirings.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/semirings.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/semirings.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.7676767677, "max_line_length": 606, "alphanum_fraction": 0.7072194477, "num_tokens": 8598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.828938825225204, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.7062167610428011}}
{"text": "\\section{Homework \\# 05}\n\nGiven a spring mass damper system as shown below, obtain a function $x(t)$ to describe the movement of the object.\n\nConsider \n\n\\begin{equation}\nF(t) = \\begin{cases} \n      t &  0 \\leq t < 2  \\\\\n      2 & 2 \\leq t < 4 \\\\\n      2(5-t) & 4 \\leq t < 5 \\\\\n      0 & \\text{for all other cases}\n   \\end{cases}\n\\end{equation}\n\nFriction follows the following behaviour\n\n\\begin{equation}\nF_f (t) = \\begin{cases} \n      t &  0 \\leq t < \\mu N  \\\\\n      \\mu N & \\mu N \\leq t < t_x \\\\\n      -\\mu N & t_x \\leq t < 5 \\\\\n      0 & \\text{for all other cases}\n   \\end{cases}\n\\end{equation}\n\n\\begin{equation*}   \nN = m*g\n\\end{equation*}\n\n\nThe values for the constants are as follows:\n\n\\begin{itemize}\n \\item Spring coefficient $k = 1$\n \\item Damper coefficient $b = 2$\n \\item Mass $m = 0.5$\n \\item Friction coefficient $\\mu = 0.1$\n \\item Gravity $g = 9.81$\n\\end{itemize}\n\n\\subsection{Solution}\n \n\\begin{itemize}\n \\item Split the analysis of the system in different time intervals, taking into account the change in values for both $F(t)$ and $F_f (t)$.\n \\item Obtain the homogeneous and particular solutions at each time interval, and determine the coefficients associated for each of them.\n \\item  Find the value for $t_x$. Recall $\\dot{x}(t_x)=0$.\n\\end{itemize}\n\n\nThe sum of forces at any point in time is \n\n$\\sum F = F(t) - F_f (t) - F_b - F_k$ \n\n$F_k = k x(t)$\n\n$F_b = b \\dot{x}(t)$\n\nRecall that $\\sum F = m \\ddot{x}(t)$ and rewrite the equation as follows\n\n$ m \\ddot{x}(t) = F(t) - F_f (t) - b \\ddot{x}(t) - k x(t)$\n\nReorder the terms to express the equation as an ODE\n\n$ m \\ddot{x}(t) + b \\ddot{x}(t) + k x(t) = F(t) - F_f (t)$\n\nDivide all terms by $m$\n\n$  \\ddot{x}(t) + \\dfrac{b}{m} \\ddot{x}(t) + \\dfrac{k}{m} x(t) = \\dfrac{F(t) - F_f (t)}{m}$\n\nEvaluate the known constants\n\n$  \\ddot{x}(t) + 4 \\ddot{x}(t) + 2 x(t) = 2 F(t) - 2 F_f (t)$\n\n\nThe general solution to this ODE will have the following form\n\n$x(t) = x_h (t) + x_p (t)$\n\nThe homogeneous solution is obtained by replacing the values on the right hand side of the equation with 0 and solving the ODE.\n\n$\\ddot{x}(t) + 4 \\ddot{x}(t) + 2 x(t) = 0$\n\n$\\lambda^2 + 4 \\lambda +2 = 0$\n\n$\\lambda = \\dfrac{-4\\pm \\sqrt{4^2 - 4 (1) (2)}}{2}$\n\n$\\lambda = \\dfrac{-4\\pm \\sqrt{8}}{2}$\n\n$\\lambda = -2\\pm \\sqrt{2}$\n\n$\\lambda_1 = -2 + \\sqrt{2}$\n\n$\\lambda_2 = -2 - \\sqrt{2}$\n\nThe homogeneous solution is the following\n\n$x_h (t) = c_1 \\exp{(\\lambda_1 t)} + c_2 \\exp{(\\lambda_2 t)}$\n\n$\\dot{x}_h (t) = c_1 \\lambda_1 \\exp{(\\lambda_1 t)} + c_2 \\lambda_2 \\exp{(\\lambda_2 t)}$\n\nThe particulara solution is different at each time interval. See in the following sections for the process of obtaining it at each time interval.\n\nThe coefficients $c_1$ and $c_2$ are obtained at each time interval based on the initial conditions for each of them ($x(\\tau)$, $\\dot{x}(\\tau)$).\n\nA general solution is presented below\n\nLet $t=\\tau$ and evaluate for $x(t)$ and $\\dot{x}(t)$\n\n$x(\\tau) = x_\\tau$\n\n$\\dot{x}(\\tau) = \\dot{x}_\\tau$\n\nSolve for $c_2$ in $x_\\tau$\n\n$x_{\\tau} = c_1 \\exp{(\\lambda_1 \\tau)} + c_2 \\exp{(\\lambda_2 \\tau)} + x_p (\\tau)$\n\n$x_{\\tau} - x_p (\\tau) = c_1 \\exp{(\\lambda_1 \\tau)} + c_2 \\exp{(\\lambda_2 \\tau)} $\n\n$x_{\\tau} - x_p (\\tau) - c_1 \\exp{(\\lambda_1 \\tau)} = c_2 \\exp{(\\lambda_2 \\tau)} $\n\n$c_2   = \\dfrac{x_{\\tau} - x_p (\\tau) - c_1 \\exp{(\\lambda_1 \\tau)}}{\\exp{(\\lambda_2 \\tau)}} $\n\nNow evaluate $c_2$ in $\\dot{x}_\\tau$ and solve for $c_1$. Recall that the first derivative is written as follows\n\n$\\dot{x}(t) = c_1 \\lambda_1 \\exp{(\\lambda_1 t)} + c_2 \\lambda_2 \\exp{(\\lambda_2 t)} +  \\dot{x}_p (t) $\n\nSubstituting $c_2$\n\n$\\dot{x}_{\\tau} = c_1 \\lambda_1 \\exp{(\\lambda_1 t)} + (\\dfrac{x_{\\tau} - x_p (\\tau) - c_1 \\exp{(\\lambda_1 \\tau)}}{\\exp{(\\lambda_2 \\tau)}}) \\lambda_2 \\exp{(\\lambda_2 \\tau)} +  \\dot{x}_p (\\tau) $\n\nFactorise $c_1$ and simplify.\n\n$\\dot{x}_{\\tau} = c_1 \\lambda_1 \\exp{(\\lambda_1 t)} + (x_{\\tau} - x_p (\\tau) - c_1 \\exp{(\\lambda_1 \\tau)}) \\lambda_2  +  \\dot{x}_p (\\tau) $\n\n$\\dot{x}_{\\tau} = c_1 (\\lambda_1 \\exp{(\\lambda_1 t)} - \\lambda_2 \\exp{(\\lambda_1 \\tau)} )  + \\lambda_2 x_{\\tau} - \\lambda_2 x_p (\\tau)  +  \\dot{x}_p (\\tau) $\n\nSolve for $c_1$\n\n$c_1 = \\dfrac{\\dot{x}_{\\tau} - \\lambda_2 x_{\\tau} + \\lambda_2 x_p (\\tau)  -  \\dot{x}_p (\\tau)}{ \\lambda_1 \\exp{(\\lambda_1 \\tau)} - \\lambda_2 \\exp{(\\lambda_1 \\tau)}  }  $\n", "meta": {"hexsha": "364f553a860bd933bf6a7bdc647c1b24cb7b9bd0", "size": 4288, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/tex/hw_05.tex", "max_stars_repo_name": "der-coder/Cinvestav-Dynamic-Systems-2019", "max_stars_repo_head_hexsha": "e30ded5312a2734eb542368de69c40a9d3af9989", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Notes/tex/hw_05.tex", "max_issues_repo_name": "der-coder/Cinvestav-Dynamic-Systems-2019", "max_issues_repo_head_hexsha": "e30ded5312a2734eb542368de69c40a9d3af9989", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/tex/hw_05.tex", "max_forks_repo_name": "der-coder/Cinvestav-Dynamic-Systems-2019", "max_forks_repo_head_hexsha": "e30ded5312a2734eb542368de69c40a9d3af9989", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.4113475177, "max_line_length": 193, "alphanum_fraction": 0.6079757463, "num_tokens": 1664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388040954683, "lm_q2_score": 0.8519528094861981, "lm_q1q2_score": 0.7062167430412634}}
{"text": "%\n%==> Section: Plotting functions\n%\n\\section{\n  Plotting functions\n}\n%\n%==> Plotting user-defined functions\n%\n\\begin{frame}[fragile]\n  \\frametitle{\n    Plotting user-defined functions\n  }\n\n  Ti$k$Z also has a math engine which enables you to plot functions:\n\n  \\lstinputlisting{./tex/src/plot_function.tex}\n\n  gives you\n\n  \\begin{center}\n    \\input{./tex/src/plot_function.tex}\n  \\end{center}\n\n  The domain instruction shows the range of $x$ which is plotted. In this case we are plotting the function $0.025+x+x^2.$ Note the braces around the function that we plot in\n\n  \\begin{lstlisting}\n    plot (\\x, {function});\n  \\end{lstlisting}\n  \n\\end{frame}\n\n%\n%==> Built-in math functions\n%\n\\begin{frame}[fragile]\n  \\frametitle{\n    Built-in math functions\n}\n\n  \\begin{itemize}\n  \\item\n    Many mathematical functions are possible; you will probably have enough with\n\n    \\begin{lstlisting}\n      factorial(\\x), sqrt(\\x), exp(\\x), ln(\\x)\n      log2(\\x), log10(\\x), abs(\\x)\n    \\end{lstlisting}\n\n  \\item\n    \n    \\begin{lstlisting}\n      pow(\\x,y), mod(\\x, y)\n    \\end{lstlisting}\n\n    which gives $x^y$ and $x$ modulo $y.$\n\n  \\item\n    \n    \\begin{lstlisting}\n      round(\\x), floor(\\x), ceil(\\x)\n    \\end{lstlisting}\n       \n    rounds $x$ to the nearest integer, the largest integer smaller than $x$, the smallest integer larger than $x$.\n  \\end{itemize}\n\\end{frame}\n\n\n%\n%==> Built-in math functions (continued)\n%\n\\begin{frame}[fragile]\n  \\frametitle{\n    Built-in math functions (continued)\n}\n\n  \\begin{itemize}\n  \\item\n    \\begin{lstlisting}\n      sin(\\x)\n    \\end{lstlisting}\n\n    it assumes that $x$ is in degrees; if $x$ is expressed in radians use\n\n    \\begin{lstlisting}\n      sin(\\x r)\n    \\end{lstlisting}\n\n    In a similar fashion,\n    \n    \\begin{lstlisting}\n      cos(\\x), cos(\\x r), tan(\\x), tan(\\x r)\n    \\end{lstlisting}\n\n    We also have\n\n    \\begin{lstlisting}\n      min(\\x,y), max(\\x,y).\n    \\end{lstlisting}\n    \n  \\item \n    In mathematical expressions the two following \\textcolor{violet}{\\bf rational} variables can be useful:\n\n    \\begin{lstlisting}\n      e\n    \\end{lstlisting}\n    \n    which is equal to \\textcolor{violet}{2.718281828}, and\n\n    \\begin{lstlisting}\n      pi\n    \\end{lstlisting}\n\n    which is equal to \\textcolor{violet}{3.141592654}.\n\n  \\end{itemize}\n\\end{frame}\n\n%\n%==> Plot trig functions\n%\n\\begin{frame}[fragile]\n  \n  You can mix functions to compute more complicated expressions (see above for the reason for the {\\tt r} parameter in the argument of $\\sin$ and $\\cos$ and note the use of \\textcolor{violet}{\\tt pi} to define the domains):\n  \\lstinputlisting{./tex/src/plot_trig_functions.tex}\n\n  which gives you\n\n  \\begin{center}\n    \\input{./tex/src/plot_trig_functions.tex}\n  \\end{center}\n\n\\end{frame}\n", "meta": {"hexsha": "b9375596dab4bb08a31ff3cd9f4a38d0f0a38db4", "size": 2748, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/sections/plotting_functions.tex", "max_stars_repo_name": "jlokimlin/tikz_crash_course", "max_stars_repo_head_hexsha": "0b4011d1d57be271d9b67a4ceb44e8448f31c0c8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2016-04-24T18:36:57.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-03T20:09:31.000Z", "max_issues_repo_path": "tex/sections/plotting_functions.tex", "max_issues_repo_name": "jlokimlin/tikz_crash_course", "max_issues_repo_head_hexsha": "0b4011d1d57be271d9b67a4ceb44e8448f31c0c8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/sections/plotting_functions.tex", "max_forks_repo_name": "jlokimlin/tikz_crash_course", "max_forks_repo_head_hexsha": "0b4011d1d57be271d9b67a4ceb44e8448f31c0c8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.5074626866, "max_line_length": 223, "alphanum_fraction": 0.6473799127, "num_tokens": 814, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.706188169479923}}
{"text": "\\chapter{Transforming Functions}\n\nLet's say I gave you the graph of a function $f$, like this:\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-2.2,xmax=2.2,\n        ymin=-1,ymax=5,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$x$},\n        ylabel={$y$},\n      ]\n      \\addplot[no marks,sdkblue] expression[domain=-2:2,samples=100]{x^2} node[below, yshift=-6mm] {$f(x)$};\n    \\end{axis}\\end{tikzpicture}\n\nAnd then I tell you that the function $g(x) = f(x) + 1.5$.  Can you guess what the graph of $g$ would look like? It is the same graph, just translated up 1.5:\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-2.2,xmax=2.2,\n        ymin=-1,ymax=5,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$x$},\n        ylabel={$y$},\n      ]\n      \\addplot[dashed,sdkblue] expression[domain=-2:2,samples=100]{x^2} node[below, yshift=-6mm] {$f(x)$};\n      \\addplot[no marks,sdkblue] expression[domain=-2:2,samples=100]{x^2 + 1.5} node[below, yshift=-6mm] {$g(x)$};\n    \\end{axis}\\end{tikzpicture}\n\nThere are four kinds of transformations that we do all the time:\n\\begin{itemize}\n\\item Translation up and down in the direction of $y$ axis (the one you just saw)\n\\item Translation left and right in the direciton of the $x$ axis\n\\item Scaling up and down along the $y$ axis\n\\item Scaling up and down along the $x$ axis\n\\end{itemize}\n\nNow I will demonstrate each of the four using the graph of $\\sin(x)$.\n\n\\section{Translation up and down}\n\nWhen you add a positive constant to a function, you translate the\nwhole graph up that much. A negative constant translates it down.\n\nHere is the graph of $\\sin(x) - 0.5$:\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels\n    fill=white, inner sep=1pt, font=\\scriptsize,\n            },                        ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5235, ystep=0.5] (-6.6,-1.7) grid (6.6,1.2);\n\n% y tick label\n\\foreach \\y in {-1, -1/2, 1/2, 1}{\\node[tl,left=1mm] at (0,\\y) {$\\y$};}\n% x tick label\n\\foreach \\x [count=\\xx from -4] in \n       {-2\\pi,\n        -\\frac{3\\pi}{2},\n        -\\pi,           \n        -\\frac{\\pi}{2}, \n        { },\n         \\frac{\\pi}{2},\n         \\pi, \n         \\frac{3\\pi}{2}, \n         2\\pi\n        }{\\node[tl,below=1mm] at (3*0.5235*\\xx,0) {$\\x$};}\n% axes\n    \\draw[->,thick] (-6.5,0) -- (6.5,0) node[right] {$x$};\n    \\draw[->,thick] (0,-1.25) -- (0, 1.25) node[above] {$y$};\n% curve\n\\draw[<->,dashed,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{sin(deg{\\x})});\n\\draw[<->,thick,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{sin(deg{\\x}) - 0.5});\n\\end{tikzpicture}\n\n\\section{Translation left and right}\n\nWhen you add a positive number to $x$ before running it through $f$,\nyou translate the graph to the left that much. Adding a negative\nnumber translates the graph to the right.\n\nHere is the graph of $\\sin(x - \\pi/6)$:\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels\n    fill=white, inner sep=1pt, font=\\scriptsize,\n            },                        ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5236, ystep=0.5] (-6.6,-1.2) grid (6.6,1.2);\n\n% y tick label\n\\foreach \\y in {-1, -1/2, 1/2, 1}{\\node[tl,left=1mm] at (0,\\y) {$\\y$};}\n% x tick label\n\\foreach \\x [count=\\xx from -4] in \n       {-2\\pi,\n        -\\frac{3\\pi}{2},\n        -\\pi,           \n        -\\frac{\\pi}{2}, \n        { },\n         \\frac{\\pi}{2},\n         \\pi, \n         \\frac{3\\pi}{2}, \n         2\\pi\n        }{\\node[tl,below=1mm] at (3*0.5235*\\xx,0) {$\\x$};}\n% axes\n    \\draw[->,thick] (-6.5,0) -- (6.5,0) node[right] {$x$};\n    \\draw[->,thick] (0,-1.25) -- (0, 1.25) node[above] {$y$};\n% curve\n\\draw[<->,dashed,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{sin(deg{\\x})});\n\\draw[<->,thick,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{sin(deg{\\x} - 30)});\n\\end{tikzpicture}\n\nNotice the sign:\n\\begin{itemize}\n\\item Add to $x$ before processing with the function translates the graph to the \\emph{left}.\n\\item Subtract from $x$ before processing with the function translates the graph to the \\emph{right}\n\\end{itemize}\n\n\\section{Scaling up and down in the $y$ direction}\n\nTo scale the function up and down, you multiply the result of the\nfunction by a constant.  If the constant is larger than 1, it\nstretches the function up and down.\n\nHere is $y = 2\\sin(x)$:\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels\n    fill=white, inner sep=1pt, font=\\scriptsize,\n            },                        ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5236, ystep=0.5] (-6.6,-2.2) grid (6.6,2.2);\n\n% y tick label\n\\foreach \\y in {-1, -1/2, 1/2, 1}{\\node[tl,left=1mm] at (0,\\y) {$\\y$};}\n% x tick label\n\\foreach \\x [count=\\xx from -4] in \n       {-2\\pi,\n        -\\frac{3\\pi}{2},\n        -\\pi,           \n        -\\frac{\\pi}{2}, \n        { },\n         \\frac{\\pi}{2},\n         \\pi, \n         \\frac{3\\pi}{2}, \n         2\\pi\n        }{\\node[tl,below=1mm] at (3*0.5235*\\xx,0) {$\\x$};}\n% axes\n    \\draw[->,thick] (-6.5,0) -- (6.5,0) node[right] {$x$};\n    \\draw[->,thick] (0,-1.25) -- (0, 1.25) node[above] {$y$};\n% curve\n\\draw[<->,dashed,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{sin(deg{\\x})});\n\\draw[<->,thick,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{sin(deg{\\x}) * 2.0});\n\\end{tikzpicture}\n\nWith a wave like this, we speak of its \\newterm{Amplitude}, which you\ncan think of as its height. The baseline that this wave oscillates\naround is zero. The maximum distance that it gets from that baseline\nis its amplitude.  Thus, the amplitude here has been increased from 1\nto 2.\n\nIf you multiply by a negative number, the function gets flipped.  Here is $y = -0.5 \\sin(x)$\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels\n    fill=white, inner sep=1pt, font=\\scriptsize,\n            },                        ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5236, ystep=0.5] (-6.6,-1.2) grid (6.6,1.2);\n\n% y tick label\n\\foreach \\y in {-1, -1/2, 1/2, 1}{\\node[tl,left=1mm] at (0,\\y) {$\\y$};}\n% x tick label\n\\foreach \\x [count=\\xx from -4] in \n       {-2\\pi,\n        -\\frac{3\\pi}{2},\n        -\\pi,           \n        -\\frac{\\pi}{2}, \n        { },\n         \\frac{\\pi}{2},\n         \\pi, \n         \\frac{3\\pi}{2}, \n         2\\pi\n        }{\\node[tl,below=1mm] at (3*0.5235*\\xx,0) {$\\x$};}\n% axes\n    \\draw[->,thick] (-6.5,0) -- (6.5,0) node[right] {$x$};\n    \\draw[->,thick] (0,-1.25) -- (0, 1.25) node[above] {$y$};\n% curve\n\\draw[<->,dashed,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{sin(deg{\\x})});\n\\draw[<->,thick,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{sin(deg{\\x}) * -0.5});\n\\end{tikzpicture}\n\nAmplitude is never negative.  Thus, the amplitude of this wave is 0.5.\n\n\\section{Scaling up and down in the $x$ direction}\n\nIf you multiply $x$ by a number larger than 1 before running it\nthrough the function, the graph gets compressed toward zero.\n\nHere is $y = \\sin(3x)$:\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels\n    fill=white, inner sep=1pt, font=\\scriptsize,\n            },                        ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5236, ystep=0.5] (-6.6,-1.2) grid (6.6,1.2);\n\n% y tick label\n\\foreach \\y in {-1, -1/2, 1/2, 1}{\\node[tl,left=1mm] at (0,\\y) {$\\y$};}\n% x tick label\n\\foreach \\x [count=\\xx from -4] in \n       {-2\\pi,\n        -\\frac{3\\pi}{2},\n        -\\pi,           \n        -\\frac{\\pi}{2}, \n        { },\n         \\frac{\\pi}{2},\n         \\pi, \n         \\frac{3\\pi}{2}, \n         2\\pi\n        }{\\node[tl,below=1mm] at (3*0.5235*\\xx,0) {$\\x$};}\n% axes\n    \\draw[->,thick] (-6.5,0) -- (6.5,0) node[right] {$x$};\n    \\draw[->,thick] (0,-1.25) -- (0, 1.25) node[above] {$y$};\n% curve\n\\draw[<->,dashed,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{sin(deg{\\x})});\n\\draw[<->,thick,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{sin(deg{\\x} * 3)});\n\\end{tikzpicture}\n\nThe distance between two peaks of a wave is known as its\n\\newterm{wavelength}.  The original wave had a wavelength of $2\\pi$.\nThe compressed wave has a wavelength of $2\\pi/3$.\n\nIf you multiply $x$ by a number smaller than 1, it will stretch the function out, away from the $y$ axis.\n\nIf you multiply $x$ by a negative number, it will flip the function around the $y$ axis.\n\nHere is $y = 2^{(-0.5x)}$. Notice that it has flipped around the $y$ axis and is stretched out along the $x$ axis.\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-3.1,xmax=3.1,\n        ymin=-0.5,ymax=8,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$x$},\n        ylabel={$y$},\n      ]\n      \\addplot[dashed,sdkblue] expression[domain=-3.0:3.0,samples=100]{2^x} node[left, xshift=-1mm,yshift=-6mm] {$2^x$};\n      \\addplot[no marks,sdkblue] expression[domain=-3.0:3.0,samples=100]{2^(-0.5 * x)}\n      node[above, xshift=-6mm] {$2^{-0.5x}$};\n    \\end{axis}\\end{tikzpicture}\n\n\\section{Order is important!}\n\nWe can combine these transformations. This allows us, for example, to\ntranslate a function up 2 and then scale along the $y$ axis by 3.\n\nHere is $y = 2.0 (\\sin(x) + 1)$:\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels\n    fill=white, inner sep=1pt, font=\\scriptsize,\n            },                        ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5236, ystep=0.5] (-6.6,-1.2) grid (6.6,4.2);\n\n% y tick label\n\\foreach \\y in {-1, -1/2, 1/2, 1, 2, 3, 4}{\\node[tl,left=1mm] at (0,\\y) {$\\y$};}\n% x tick label\n\\foreach \\x [count=\\xx from -4] in \n       {-2\\pi,\n        -\\frac{3\\pi}{2},\n        -\\pi,           \n        -\\frac{\\pi}{2}, \n        { },\n         \\frac{\\pi}{2},\n         \\pi, \n         \\frac{3\\pi}{2}, \n         2\\pi\n        }{\\node[tl,below=1mm] at (3*0.5235*\\xx,0) {$\\x$};}\n% axes\n    \\draw[->,thick] (-6.5,0) -- (6.5,0) node[right] {$x$};\n    \\draw[->,thick] (0,-1.25) -- (0, 4.25) node[above] {$y$};\n% curve\n\\draw[<->,dashed,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{sin(deg{\\x})});\n\\draw[<->,thick,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{2.0 * (sin(deg{\\x}) + 1)});\n\\end{tikzpicture}\n\nA function is often a series of steps. Here are the steps in $f(x) = 2(\\sin(x) + 1)$:\n\\begin{enumerate}\n\\item Take the sine of $x$\n\\item Add 1 to that\n\\item Multiply that by 2\n\\end{enumerate}\n\nWhat if we change the order? Here are the steps in $g(x) = 2\\sin(x) + 1$:\n\\begin{enumerate}\n\\item Take the sine of $x$\n\\item Multiply that by 2\n\\item Add 1 to that\n\\end{enumerate}\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels\n    fill=white, inner sep=1pt, font=\\scriptsize,\n            },                        ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5236, ystep=0.5] (-6.6,-2.2) grid (6.6,4.2);\n\n% y tick label\n\\foreach \\y in {-2, -1, -1/2, 1/2, 1, 2, 3, 4}{\\node[tl,left=1mm] at (0,\\y) {$\\y$};}\n% x tick label\n\\foreach \\x [count=\\xx from -4] in \n       {-2\\pi,\n        -\\frac{3\\pi}{2},\n        -\\pi,           \n        -\\frac{\\pi}{2}, \n        { },\n         \\frac{\\pi}{2},\n         \\pi, \n         \\frac{3\\pi}{2}, \n         2\\pi\n        }{\\node[tl,below=1mm] at (3*0.5235*\\xx,0) {$\\x$};}\n% axes\n    \\draw[->,thick] (-6.5,0) -- (6.5,0) node[right] {$x$};\n    \\draw[->,thick] (0,-2.25) -- (0, 4.25) node[above] {$y$};\n% curve\n\\draw[<->,dashed,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \nplot (\\x,{2.0 * (sin(deg{\\x}) + 1)});\n\\draw (4, 3) node{$2(\\sin(x) + 1)$};\n\\draw[<->,thick,draw=black,\n      domain=-6.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{2.0 * sin(deg{\\x} + 1)});\n\\draw (2.5, -1.5) node{$2\\sin(x) + 1$};\n\\end{tikzpicture}\n\nThe moral: You can do multiple transformations of your function, but\nthe order in which you do them is important.\n\n\\begin{Exercise}[title={Transforms}, label=sine_transform]\n\nFind a function that creates a sine wave such that the top of the first crest is\nat the point $(\\frac{\\pi}{2}, 5)$ and the bottom of the trough that follows is at $(\\pi, 1)$.\n\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels\n    fill=white, inner sep=1pt, font=\\scriptsize,\n            },                        ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5236, ystep=0.5] (-1,-0.6) grid (6.6,5.2);\n\n% y tick label\n\\foreach \\y in {1/2, 1, 2, 3, 4, 5}{\\node[tl,left=1mm] at (0,\\y) {$\\y$};}\n% axes\n    \\draw[->,thick] (-0.9,0) -- (6.5,0) node[right] {$x$};\n    \\draw[->,thick] (0,-0.25) -- (0, 5.25) node[above] {$y$};\n    % curve\n    \\filldraw[black] (1.570796326794897, 5)  circle(3pt) node [right, yshift=1mm]{$(\\pi/2,5)$};\n    \\filldraw[black] (3.141592653589793, 1)  circle(3pt) node[below]{$(\\pi,1)$};\n    \\draw[<->,thick,draw=black,\n      domain=-0.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{2.0 * sin(deg{2*\\x} - 90) + 3});\n\\end{tikzpicture}\n\n  \n\\end{Exercise}\n\\begin{Answer}[ref=sine_transform]\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels\n    fill=white, inner sep=1pt, font=\\scriptsize,\n            },                        ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5236, ystep=0.5] (-1,-0.6) grid (6.6,5.2);\n\n% y tick label\n\\foreach \\y in {1/2, 1, 2, 3, 4, 5}{\\node[tl,left=1mm] at (0,\\y) {$\\y$};}\n% axes\n    \\draw[->,thick] (-0.9,0) -- (6.5,0) node[right] {$x$};\n    \\draw[->,thick] (0,-0.25) -- (0, 5.25) node[above] {$y$};\n    % curvet\n    \\filldraw[black] (0.785398163397448, 3)  circle(3pt) node[right, yshift=1mm]{$(\\pi/4, 3)$};\n    \\filldraw[black] (1.570796326794897, 5)  circle(3pt) node [right, yshift=1mm]{$(\\pi/2, 5)$};\n    \\filldraw[black] (3.141592653589793, 1)  circle(3pt) node[below]{$(\\pi, 1)$};\n    \\filldraw[black] (4.71238898038469, 5)  circle(3pt) node[right, yshift=1mm]{$(3\\pi/2, 5)$};\n    \\draw[<->,thick,draw=black,\n      domain=-0.5:6.5,samples=300,variable=\\x] \n      plot (\\x,{2.0 * sin(deg{2*\\x} - 90) + 3});\n    \\draw[dashed,thick, draw=black] (0,3) -- (6,3);\n\\end{tikzpicture}\n\nThis wave has an amplitude of 2.  Its baseline has been translated up to 3.\n\nThis wave has wavelength of $\\pi$. A sine wave usually has a\nwavelength of $2\\pi$, so we need to compress the $x$ axis by a factor of 2.\n\nThe wave first crosses its baseline at $pi/4$.  The sine wave starts\nby crossing its baseline, so we need to translate the curve right by\n$\\pi/4$.\n\n$$f(x) = 2 \\sin(2x - \\frac{\\pi}{4}) + 3$$\n\n\\end{Answer}\n\n", "meta": {"hexsha": "9f6c83d38ae060e6562aaf6600ccae6d0ceeb8c8", "size": 14299, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Oscillations/transforms-en_US.tex", "max_stars_repo_name": "hillegass/sequence", "max_stars_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/Oscillations/transforms-en_US.tex", "max_issues_repo_name": "hillegass/sequence", "max_issues_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/Oscillations/transforms-en_US.tex", "max_forks_repo_name": "hillegass/sequence", "max_forks_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 32.6461187215, "max_line_length": 158, "alphanum_fraction": 0.559269879, "num_tokens": 5457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.8962513634345444, "lm_q1q2_score": 0.7061844083875551}}
{"text": "\n\\subsection{Terms and predicates}\n\n\\subsubsection{Predicates}\n\nZero-order logic adds predicates. Like propositional variables, these have truth values. Unlike propositional variable, predicates take terms as inputs.\n\nFor example using propositional logic we can write the statement \"you are 25\" as \\(\\theta \\).\n\nWith preterites we can write this as \\(P(you, 25)\\).\n\nA propositional variable can be considered a special case of a predicate variable, where the number of inputs is \\(0\\).\n\n", "meta": {"hexsha": "3bdc2f390bd6827d1b31c598aa610431b0cbd0ef", "size": 488, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/preteriteLogic/01-01-zeroWriting.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/preteriteLogic/01-01-zeroWriting.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/preteriteLogic/01-01-zeroWriting.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.8571428571, "max_line_length": 152, "alphanum_fraction": 0.7766393443, "num_tokens": 108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.7061844050161121}}
{"text": "\\section{Basis and dimension}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find a basis of a given vector space.\n  \\item Determine the dimension of a vector space.\n  \\item Extend a linearly independent set of vectors to a basis.\n  \\item Shrink a spanning set of vectors to a basis.\n  \\end{enumerate}\n\\end{outcome}\n\n\\begin{definition}{Basis}{basis-vector-space}\n  Let $V$ be a vector space. A set $B$ of vectors is called a\n  \\textbf{basis}%\n  \\index{basis}%\n  \\index{basis!of a vector space}%\n  \\index{vector space!basis} of $V$ if\n  \\begin{enumerate}\n  \\item $B$ is a spanning set for $V$, and\n  \\item $B$ is linearly independent.\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{example}{Bases of $\\Poly_2$}{basis-p2}\n  Consider the vector space $\\Poly_2$ of polynomials of degree at most\n  2 with coefficients in a field $K$.%\n  \\index{P2@$\\Poly_2$!basis of}\n  \\begin{itemize}\n  \\item $\\set{1,~ x,~ x^2}$ is a basis of $\\Poly_2$.\n  \\item $\\set{x^2,~ (x+1)^2,~ (x+2)^2}$ is a basis of $\\Poly_2$.\n  \\item $\\set{1,~ x-1,~ (x-1)^2}$ is a basis of $\\Poly_2$.\n  \\end{itemize}\n  Unlike $\\R^n$, a vector space like $\\Poly_2$ does not\n  necessarily have a ``standard'' basis. One basis might be useful for\n  one application, and another basis for a different application.\n\\end{example}\n\n\\begin{proof}\n  It is easy to verify that each set of vectors is linearly\n  independent and spanning. See Examples~\\ref{exa:spanning-set},\n  {\\ref{exa:linear-independence-polynomial}}, and\n  {\\ref{exa:polynomials-increasing-degree}} for similar calculations.\n\\end{proof}\n\n\\begin{example}{An infinite basis}{basis-p}\n  Consider the vector space $\\Poly$ of all polynomials with\n  coefficients in a field $K$. The following is a basis for $\\Poly$%\n  \\index{P@$\\Poly$!basis of}:\n  \\begin{equation*}\n    \\set{1,~ x,~ x^2,~ x^3,~ x^4,~ \\ldots}.\n  \\end{equation*}\n  Note that this basis is infinite.\n\\end{example}\n\n\\begin{proof}\n  The polynomials $1$, $x$, $x^2$, $x^3$, $x^4$, $\\ldots$ are linearly\n  independent by Proposition~\\ref{prop:linear-dependence-redundant}.\n  Namely, if they were linearly dependent, then one of the polynomials\n  could be written as a linear combination of earlier ones. However,\n  this is not possible because a polynomial of degree $n$ cannot be a\n  linear combination of polynomials of degree less than $n$.\n\n  To show that the polynomials $1$, $x$, $x^2$, $x^3$, $x^4$, $\\ldots$\n  are a spanning set, consider an arbitrary element $p(x)$ of $\\Poly$.\n  Then by definition, $p(x)$ is of the form\n  \\begin{equation*}\n    p(x) = a_nx^n + a_{n-1}x^{n-1} + \\ldots + a_1x + a_0,\n  \\end{equation*}\n  for some $n\\geq 0$ and $a_0,\\ldots,a_n\\in K$. But then $p(x)$ is a\n  linear combination of $1,\\ldots,x^n$, i.e., it is in the span of\n  $\\set{1,~ x,~ x^2,~ x^3,~ x^4,~ \\ldots}$.\n\\end{proof}\n\n\\begin{example}{Not a basis}{not-a-basis}\n  Consider the vector space $\\Seq_K$ of infinite sequences. As before,\n  let $e^k$ be the sequence whose $k\\th$ element is $1$ and that is\n  $0$ everywhere else, i.e.,\n    \\begin{equation*}\n    \\begin{array}{l}\n      e^0 = (1,0,0,0,0,\\ldots), \\\\\n      e^1 = (0,1,0,0,0,\\ldots), \\\\\n      e^2 = (0,0,1,0,0,\\ldots), \\\\\n    \\end{array}\n  \\end{equation*}\n  and so on. Then the set\n  \\begin{equation*}\n    \\set{e^0,~ e^1,~ e^2,~ \\ldots}\n  \\end{equation*}\n  is \\textit{not} a basis of $\\Seq_K$. Indeed, although we saw in\n  Example~\\ref{exa:linear-independence-sequences} that the sequences\n  $e^0$, $e^1$, $e^2$, $\\ldots$ are linearly independent,\n  Example~\\ref{exa:spans-sequences} shows that they are not spanning.\n  Indeed,\n  \\begin{equation*}\n    W = \\sspan\\set{e^0,~ e^1,~ e^2,~ \\ldots}\n  \\end{equation*}\n  is a subspace of $\\Seq_K$, consisting exactly of the\n  \\textbf{finitely supported}%\n  \\index{finitely supported sequence}%\n  \\index{sequence!finitely supported} sequences, i.e., those sequences\n  that have only finitely many non-zero components. Thus, $\\set{e^0,~ e^1,~\n    e^2,~ \\ldots}$ is a basis of $W$.\n\\end{example}\n\nThe following theorem ensures that every vector space has a basis.  We\nwill not prove this theorem, because when the spaces are\ninfinite-dimensional, the proof uses mathematics that is beyond the\nscope of this book. The proof uses a reasoning principle called the\n\\textbf{axiom of choice}%\n\\index{axiom of choice}%\n\\index{choice!axiom of}, which allows us to prove the existence of a\nbasis even in cases where we cannot find an actual concrete example of\na basis.  For example, it is not possible to give a specific example\nof a basis for the space $\\Seq_K$, even though the following theorem\nguarantees that such a basis exists.\n\n\\begin{theorem}{Existence of bases}{basis-existence}\n  Every vector space has a basis.\n\\end{theorem}\n\nThe Exchange Lemma, which we proved in the context of $\\R^n$ in\nSection~\\ref{sec:basis-and-dimension}, is true in general vector\nspaces.\n\n\\begin{lemma}{Exchange Lemma}{exchange-lemma-vector-space}\n  \\index{exchange lemma!in a vector space}%\n  Let $V$ be a vector space over a field $K$. Suppose\n  $\\vect{u}_1,\\ldots,\\vect{u}_r$ are linearly independent elements\n  of $\\sspan\\set{\\vect{v}_1,\\ldots,\\vect{v}_s}$. Then $r\\leq s$.\n\\end{lemma}\n\nThe proof is exactly the same as that of\nLemma~\\ref{lem:exchange-lemma}, so we do not repeat it here.  As in\nSection~\\ref{sec:basis-and-dimension}, an important consequence of the\nExchange Lemma is that any two bases of a vector space have the same\nsize.\n\n\\begin{theorem}{Bases are of the same size}{basis-same-size-vector-space}\n  \\index{basis!size of}%\n  Let $V$ be a vector space over some field $K$, and let $B_1$ and\n  $B_2$ be bases of $V$. Then either $B_1$ and $B_2$ are both finite\n  and have the same number of elements, or else $B_1$ and $B_2$ are\n  both infinite.\n\\end{theorem}\n\n\\begin{proof}\n  We first show that $B_1$ and $B_2$ are either both finite or both\n  infinite. Assume one of them, say $B_1$, is finite and contains $s$\n  vectors. Since $B_1$ is spanning and $B_2$ is linearly independent,\n  it follows from the Exchange Lemma that $B_2$ cannot contain more\n  than $s$ vectors, and in particular, $B_2$ must be finite.  So the\n  sets are either both finite or both infinite. If they are both\n  finite, say of size $s$ and $r$, then by the Exchange Lemma, we have\n  $s\\leq r$ and $r\\leq s$, hence $r=s$.\n\\end{proof}\n\nThis allows us to define the dimension of a vector space.\n\n\\begin{definition}{Dimension}{dimension-vector-space}\n  Let $V$ be a vector space over a field $K$. If $V$ has a basis\n  consisting of $n$ vectors, we say that $V$ has \\textbf{dimension}%\n  \\index{dimension!of vector space}%\n  \\index{vector space!dimension} $n$, and we write $\\dim(V)=n$. In\n  this case we also say that $V$ is \\textbf{finite-dimensional}%\n  \\index{finite-dimensional space}%\n  \\index{vector space!finite-dimensional}. If $V$ has an infinite\n  basis, we say that $V$ is \\textbf{infinite-dimensional}%\n  \\index{infinite-dimensional space}%\n  \\index{vector space!infinite-dimensional}, and we write\n  $\\dim(V) = \\infty$.\n\\end{definition}\n\nNote that the dimension is well-defined by Theorems\n{\\ref{thm:basis-existence}} and\n{\\ref{thm:basis-same-size-vector-space}}, since these theorems ensure\nthat every vector space has a basis (and therefore a dimension), and\nthat any two bases are of the same size (and therefore a vector space\ncannot have more than one dimension).\n\nWe now calculate the dimensions of some vector spaces we encountered in\nSections~\\ref{sec:definition-vector-spaces} and\n{\\ref{sec:vector-space-subspaces}}.\n\n\\begin{itemize}\n\\item The space $\\R^n$ has dimension $n$.\n\\item The space $\\Poly_2$ has dimension $3$. We found several bases\n  for this space in Example~\\ref{exa:basis-p2}.\n\\item The space $\\Mat_{m,n}$ has dimension $mn$. A possible basis\n  consists of all the matrices that contain a single $1$ and zeros\n  everywhere else.\n\\item The space $\\Func_{X,K}$ is infinite-dimensional if $X$ is an\n  infinite set. If $X$ is a finite set of $n$ elements, then this\n  space is $n$-dimensional. In that case, a basis is given by the set\n  of functions whose value is $1$ for one input and $0$ for all other\n  inputs.\n\\item The space $\\Seq_K$ is infinite-dimensional. We found an infinite\n  linearly independent set in\n  Example~\\ref{exa:linear-independence-sequences}, showing that the\n  space cannot be finite-dimensional.\n\\item The space $\\Poly$ is infinite-dimensional. We found a basis for\n  this space in Example~\\ref{exa:basis-p}.\n\\item The subspace of $\\Func_{\\R,\\R}$ consisting of the continuous\n  functions is infinite-dimensional. For example, the functions\n  $\\set{1,x,x^2,x^3,\\ldots}$ form an infinite, linearly independent\n  set of continuous functions.\n\\item The subspace of $\\Func_{\\R,\\R}$ consisting of the differentiable\n  functions is infinite-dimensional. Again, the set\n  $\\set{1,x,x^2,x^3,\\ldots}$ is an infinite linearly independent set\n  in this space.\n\\end{itemize}\n\n\\begin{example}{Space of sequences satisfying a linear recurrence}{subspace-recurrence-dimension}\n  In Example~\\ref{exa:subspace-recurrence}, we considered the space\n  $W$ of sequences of real numbers that satisfy the recurrence%\n  \\index{recurrence!as a subspace}\n  $a_{n+2}=a_n+a_{n+1}$. What is the dimension of this space?\n\\end{example}\n\n\\begin{solution}\n  The space is $2$-dimensional. The easiest way to see this is to\n  observe that a sequence $a\\in W$ is determined by its first two\n  elements. We can say that the first two elements of the sequence are\n  parameters, and all the other elements are then computed by the\n  recurrence relation. Specifically, suppose $a_0=x$ and\n  $a_1=y$. Using the recurrence relation to compute the remaining\n  elements, we have\n  \\begin{eqnarray*}\n    a &=& (x,~y,~x+y,~x+2y,~2x+3y,~3x+5y,~\\ldots) \\\\\n      &=& x(1,0,1,1,2,3,\\ldots) + y(0,1,1,2,3,5,\\ldots).\n  \\end{eqnarray*}\n  Since this is the general form of the elements of $W$, and since the\n  two sequences starting with 1,0 and 0,1 are clearly linearly\n  independent, it follows that\n  \\begin{equation*}\n    \\set{(1,0,1,1,2,3,\\ldots),~ (0,1,1,2,3,5,\\ldots)}\n  \\end{equation*}\n  is a basis of $W$.\n\\end{solution}\n\n\\begin{example}{Solution space of a linear differential equation}{dimension-differential-equation}\n  In Example~\\ref{exa:subspace-differential-equation}, we considered\n  the space of solutions of the differential equation $f''=-f$. What\n  is the dimension of this space?\n\\end{example}\n\n\\begin{solution}\n  From calculus, we know that the general solution of the differential\n  equation $f''=-f$ is\n  \\begin{equation*}\n    f(x) = A\\sin x + B\\cos x,\n  \\end{equation*}\n  where $A,B$ are constants. We also know, from\n  Example~\\ref{exa:linearly-independent-functions}, that $\\sin x$ and\n  $\\cos x$ are linearly independent. It follows that\n  $\\set{\\sin x, \\cos x}$ is a basis for the solution space. The\n  solution space is therefore $2$-dimensional.\n\\end{solution}\n\nWe conclude this section by stating two properties of bases that\ngeneralize Theorem~\\ref{thm:linearly-independent-subset} and\nLemma~\\ref{lem:extend-to-basis}: every linearly independent set can be\nextended to a basis by adding 0 or more vectors, and every spanning\nset can be reduced to a basis by removing 0 or more vectors.\n\n\\begin{proposition}{Extending a linearly independent set to a basis}{basis-from-linear-independent}\n  Let $V$ be a vector space, and let $S\\subseteq V$ be a linearly\n  independent set of vectors. Then $S$ can be extended to a basis of\n  $V$, i.e., there exists a basis $B$ of $V$ such that $S\\subseteq\n  B$.%\n  \\index{linear independence!extending to basis}%\n  \\index{basis!by extending linearly independent set}\n\\end{proposition}\n\n\\begin{proposition}{Shrinking a spanning set to a basis}{basis-from-spanning}\n  \\index{spanning set!shrink to basis}%\n  \\index{basis!by shrinking spanning set}%\n  Let $V$ be a vector space, and let $S\\subseteq V$ be a spanning set\n  of $V$. Then $S$ can be shrunk to a basis, i.e., there exists a\n  basis $B$ of $V$ such that $B\\subseteq S$.\n\\end{proposition}\n\n\\begin{example}{Extending a linearly independent set to a basis}{adding-linear-independent-basis}\n  Let $S \\subseteq M_{22}$ be the linearly independent set given by\n  \\begin{equation*}\n    S  = \\set{\n      \\begin{mymatrix}{rr}\n        1 & 0 \\\\\n        0 & 0\n      \\end{mymatrix},~\n      \\begin{mymatrix}{rr}\n        0 & 1 \\\\\n        0 & 0\n      \\end{mymatrix}\n    }\n  \\end{equation*}\n  Enlarge $S$ to a basis of $M_{22}$.\n\\end{example}\n\n\\begin{solution}\n  We can obtain a basis of $M_{22}$ by adding two more linearly\n  independent matrices\n  \\begin{equation*}\n    \\begin{mymatrix}{rr}\n      0 & 0 \\\\\n      1 & 0\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\begin{mymatrix}{rr}\n      0 & 0 \\\\\n      0 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n  The resulting basis is\n  \\begin{equation*}\n    B = \\set{\n      \\begin{mymatrix}{rr}\n        1 & 0 \\\\\n        0 & 0\n      \\end{mymatrix},~\n      \\begin{mymatrix}{rr}\n        0 & 1 \\\\\n        0 & 0\n      \\end{mymatrix},~\n      \\begin{mymatrix}{rr}\n        0 & 0 \\\\\n        1 & 0\n      \\end{mymatrix},~\n      \\begin{mymatrix}{rr}\n        0 & 0 \\\\\n        0 & 1\n      \\end{mymatrix}\n    }.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Shrinking a spanning set to a basis}{shrink-spanning}\n  Consider the spanning set $S \\subseteq \\Poly_2$ given by\n  \\begin{equation*}\n    S = \\set{1,~ x,~ 2x+1,~ x^2+1,~ x^2+2}\n  \\end{equation*}\n  Shrink $S$ to a basis of $\\Poly_2$.\n\\end{example}\n\n\\begin{solution}\n  We use a version of the casting-out method. We examine each element\n  $S$ from left to right and cast out the elements that are linear\n  combinations of previous elements. Clearly the first two elements,\n  $1$ and $x$, are linearly independent. The next element, $2x+1$, is\n  redundant because it is a linear combination of $1$ and $x$. The\n  next element $x^2+1$ is linearly independent of $1$ and $x$. The\n  final element $x^2+2$ is redundant because it is a linear\n  combination of $1$ and $x^2+1$. Therefore, the following subset of\n  $S$ is a basis of $\\Poly_2$:\n  \\begin{equation*}\n    B = \\set{1,~ x,~ x^2+1}.\n  \\end{equation*}\n\\end{solution}\n", "meta": {"hexsha": "bfb708f325d151fe7a5b08c562cb0cd669c11d05", "size": 14051, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/VectorSpaces-Basis.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/VectorSpaces-Basis.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/VectorSpaces-Basis.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 39.248603352, "max_line_length": 99, "alphanum_fraction": 0.6915522027, "num_tokens": 4482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.9149009457116781, "lm_q1q2_score": 0.7061603461143791}}
{"text": "\\section{The field equations of gravity}\nThe field equations of gravity are \\cite{Einstein:1915ca}\n\\begin{equation}\n\tR_{\\mu\\nu}-\\frac{1}{2}g_{\\mu\\nu}R + \\Lambda g_{\\mu\\nu}= \\frac{8\\pi \\symup{G}}{\\symup{c}^4} T_{\\mu\\nu}.\n\\end{equation}\n\n\\subsection{Solutions}\nThe \\emph{Schwarzschild} solution is:\n\\begin{equation}\n\t\\dif s^2 = \\l( 1 - \\frac{r_{\\symup{s}}}{r} \\r) \\symup{c}^2 \\,\\dif t^2 - \\l(1-\\frac{r_{\\symup{s}}}{r}\\r)^{-1} \\,\\dif r^2 - r^2 \\l(\\dif \\Theta^2+\\sin^2\\Theta \\dif \\varphi^2\\r).\n\\end{equation}\nThis is a vacuum solution ($T_{\\mu\\nu}=0$).\n", "meta": {"hexsha": "c8881736fd50fcef860b50a6efbd117390723c87", "size": 549, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/gravity.tex", "max_stars_repo_name": "The-Ludwig/latex-template", "max_stars_repo_head_hexsha": "d5b279b2ac62d4fff019baecb0444ce391f1c686", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "content/gravity.tex", "max_issues_repo_name": "The-Ludwig/latex-template", "max_issues_repo_head_hexsha": "d5b279b2ac62d4fff019baecb0444ce391f1c686", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "content/gravity.tex", "max_forks_repo_name": "The-Ludwig/latex-template", "max_forks_repo_head_hexsha": "d5b279b2ac62d4fff019baecb0444ce391f1c686", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.2307692308, "max_line_length": 175, "alphanum_fraction": 0.635701275, "num_tokens": 243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067260443809, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.7060197367544714}}
{"text": "%!TEX root = index.tex\n\n\\section{The Discriminant}\n\\epigraph{In mathematics you don't understand things. You just get used to them.}{John von Neumann}\n\nWe'll start by analyzing polynomials using good old calculus. There is an algebraic invariant, called the \\emph{discriminant}, that has a geometric interpretation coming from calculus on one hand and an algebraic interpretation coming from the properties of the roots of the polynomials on the other.\\\\\n\nThe \\textbf{discriminant of a polynomial} is a number which can be computed using only the coefficients of the polynomial and which is 0 precisely when the polynomial has repeated roots. There is no reason, a priori, to expect that such an number should exist but it does, and you've encountered it already for the quadratic equation.\n\n\n\n\n\n\n\\subsection{Quadratic}\n\t\nLet us start with the simplest case. Consider the quadratic polynomial $ x^2 + bx + c$ with roots $ \\alpha_1$ and $ \\alpha_2$.\n\\begin{questions}\n  \\item Express $ b, c$ in terms of $ \\alpha_1, \\alpha_2$.\n\\end{questions}\n\\begin{questions}[resume]\n\t\\item What are the conditions on the coefficients $ b,c$ under which\n\t\\begin{enumerate}\n\t\t\\item $ \\alpha_1 = \\alpha_2$,\n\t\t\\item $ \\alpha_1, \\alpha_2$ are both real,\n\t\t\\item $ \\alpha_1, \\alpha_2$ are both non-real.\n\t\\end{enumerate}\n\tIs it possible for exactly one of $ \\alpha_1$ and $ \\alpha_2$ to be real?\n\\end{questions}\nNote that the answers to these questions depend on a single number. This number, denoted $ \\Delta$ (delta), is called the \\textbf{discriminant} of the quadratic polynomial. \n\t\\begin{questions}[resume]\n\t\t  \\item Express the discriminant $ \\Delta$ in terms of $ \\alpha_1, \\alpha_2$.\t\t\n\t\\end{questions}\n\n\\newpage\n\\subsection{Cubic}\nMoving on to the next degree, consider the following cubic with roots $ \\beta_1, \\beta_2, \\beta_3$.\n\\begin{align*}\n\tP(x) = x^3 + a_2 x^2 + a_1 x + a_0\n\\end{align*}\n\\begin{questions}\n\t\\item Express $ a_2, a_1, a_0$ explicitly in terms of $ \\beta_1, \\beta_2, \\beta_3$.\n\\end{questions}\nWe'll first get rid of the coefficient on $ x^2$ to simplify our computations.\n\\begin{questions}[resume]\n\t\\item \\begin{enumerate}\n\t\t\\item Find the coefficients of the polynomial $ P_k(x)$ whose roots are $$ \\beta_1 + k, \\beta_2 + k, \\beta_3 + k$$ where $ k$ is a constant, in terms of the coefficients of $ P(x)$.\n\t\t\\item Find the value of $ k$ for which the coefficient of $ x^2$ in $ P_k(x)$ is 0.\n\t\\end{enumerate}\n\tThe value of $ k$ only depends on the coefficients of $ P(x)$ and hence we can simplify our polynomial \\textbf{without knowing the roots}.\n\t\\begin{enumerate}[resume]\n\t\t\\item For the polynomial $ P(x) = x^3 + 3x^2 + 1$ use find the polynomial $ P_k(x)$ whose $ x^2$ coefficient is 0. What is the relationship between the roots of $ P(x)$ and $ P_k(x)$?\n\t\t\\item Repeat the same exercise for the polynomial $ x^3 - 3x^2 + 3x - 1$.\n\t\\end{enumerate}\n\\end{questions}\n\n\n\n\n\n\\newpage\n\\subsection{Graphing the cubic}\nFrom now on we'll assume that our cubic is of the form:\n\\begin{align}\n\tP(x) = x^3 + px + q\n\\end{align}\nWe'll further assume $ p < 0$ for simplicity. Such a cubic is sadly called a \\textbf{depressed cubic}. With roots $ \\beta_1, \\beta_2, \\beta_3$ we've the relations\n\\begin{align*}\n\t0  & = \\beta_1 + \\beta_2 + \\beta_3                    \\\\\n\tp  & = \\beta_1 \\beta_2 + \\beta_2 \\beta_3 + \\beta_3\\beta_1 \\\\\n\t-q & = \\beta_1 \\beta_2 \\beta_3                        \n\\end{align*}  \nThere are four possible cases for the roots.\n\\begin{center}\n\t\\begin{tabular}{rl}\n\t\t\\textbf{Case 0} & all three roots equal                     \\\\\n\t\t\\textbf{Case 1} & all three roots distinct and real                   \\\\\n\t\t\\textbf{Case 2} & one repeated real root  \\\\\n\t\t\\textbf{Case 3} & two complex roots\n\t\\end{tabular}\n\\end{center}\n\n\\begin{questions}[resume]\n\t\\item \\begin{enumerate}\n\t\t\\item Convince yourselves that these cases are mutually exclusive and that are no other possibilities. Can $ P(x)$ have no real root? Can $ P(x)$ have a repeated complex root? all three roots complex (not real)?\n\t\t\\item Case 0 is trivial, what are the roots in this case? What are $ p,q$ in this case?\n\t\\end{enumerate}\n\\end{questions}\n\\begin{questions}[resume]\n\t\\item Draw the (qualitatively correct) graphs of $ P(x)$ in each of the four cases.\n\\end{questions}\n\\begin{questions}[resume]\n\t\\item By analyzing the graph of $ P(x)$, determine the relationship between the roots of $P(x)$ and $ P'(x)$ for each of the three cases: Case 1 (distinct real), Case 2 (repeated real), Case 3 (complex).\n\\end{questions}\n\nEach of these cases are in fact completely determined by the coefficients $ p,q$. This is because $ P'(x)$ is a friendly quadratic equation whose roots are easy to find.\n\\begin{questions}[resume]\n  \\item \\begin{enumerate}\n  \t\\item Find the roots of $ P'(x)$.\n\t\t\\item Use your answers to the previous questions to determine the conditions on the coefficients $ p,q$ corresponding to the three cases.\n  \\end{enumerate}\n\\end{questions}\n\nAssuming you did the calculations correctly you should get conditions of the following form for some number $ \\Delta$.\n\\begin{align*}\n\t\\Delta > 0 & \\implies P(x) \\mbox{ has three real roots} \\\\\n\t\\Delta = 0 & \\implies P(x) \\mbox{ has a repeated root}   \\\\\n\t\\Delta < 0 & \\implies P(x) \\mbox{ has exactly one real root}   \n\\end{align*}\nThese are exactly the relations we had for a quadratic! \n\n\n\\newpage\n\\subsection{The Discriminant of the Cubic}\nBy the previous section the roots of our polynomial are distinct real, repeated or complex according to whether the value of the polynomial is -ve, 0 or +ve at the roots of it's derivative $ \\sqrt {{-p}/{3}}$, or the opposite for $ -\\sqrt {{-p}/{3}}$.\n\n\\begin{questions}[resume]\n  \\item Simplify the condition $$P \\left(\\sqrt {{-p}/{3}}\\right)= 0$$ to the form $ -4p^3 - 27q^2 = 0$. Similar simplifications are possible for the conditions $P (\\sqrt {{-p}/{3}}) < 0$ and $> 0$.\n\\end{questions}\n\nUsing the other root $ -\\sqrt {{-p}/{3}}$ we surprisingly get the \\emph{exact} same conditions. Thus we've (almost) proved the following theorem.\n\\begin{thm}\n\tThe cubic $ P(x) = x^3 + px + q$ has distinct real, repeated, or complex roots, according to whether the \\textbf{discriminant} of $ P(x)$ $$ \\Delta = -4p^3 - 27q^2$$ is positive, 0 or negative. \n\\end{thm}\n\n\n\\begin{questions}[resume]\n  \\item Determine whether the following polynomials have distinct real, repeated or complex roots. \n\t\\begin{enumerate}\n\t\t\\item $ x^3 + 1$\n\t\t\\item $ x^3 - 1$\n\t\t\\item $ x^3 - 3x + 2 $\n\t\t\\item $ x^3 - 3x + 1 $\n\t\t\\item (optional) $x^3 + 3x^2 + 1$\n\t\\end{enumerate}\n\\end{questions}\n\n\\begin{questions}[resume]\n\t\\item \\begin{enumerate}\n\t\t\\item What is the value of $ q$ for which $ x^3 -3x + q$ has distinct real roots, repeated roots, and complex roots respectively.\n\t\t\\item In the case when $ x^3 - 3x + q$ has repeated roots, find the roots.\n\t\\end{enumerate}\n\\end{questions}\n\n\n\n\n\n\n\\newpage\n\\subsection{The Roots \\& the Discriminant}\nAs in the case of a quadratic $\\left( b^2 - 4c = (\\alpha_1 - \\alpha_2)^2 \\right)$ there is a surprising relation between $ \\Delta$ and the roots $ \\beta_1, \\beta_2, \\beta_3$. \n\n\\begin{thm}\n\\label{thm:discriminant}\n\t\\begin{align*}\n\t\t-4p^3 - 27q^2 = (\\beta_1 - \\beta_2)^2(\\beta_2 - \\beta_3)^2(\\beta_3 - \\beta_1)^2 \n\t\\end{align*}\n\\end{thm}\n\nThe proof of this theorem is very cumbersome, we'll only verify it for some cases.\n\\begin{questions}[resume]\n\t\\item \n\t\\begin{enumerate}\n\t\t\\item Argue directly that\n\t\t\\begin{align*}\n\t\t\tP(x) \\mbox{ has distinct real roots} & \\Rightarrow  (\\beta_1 - \\beta_2)^2(\\beta_2 - \\beta_3)^2(\\beta_3 - \\beta_1)^2 > 0\\\\\n\t\t\t P(x) \\mbox{ has a repeated root}  & \\Rightarrow  (\\beta_1 - \\beta_2)^2(\\beta_2 - \\beta_3)^2(\\beta_3 - \\beta_1)^2 = 0\n\t\t\\end{align*}\n\t\\item For the complex roots case, assume that $ \\beta_1$ is real and, $ \\beta_2 $ and $ \\beta_3$ are complex. Show that \n\t\t\\begin{align*}\n\t\t\t\\beta_2 = -\\beta_1/2 + i \\beta' \\mbox{ and } \\beta_2 = -\\beta_1/2 - i \\beta'\n\t\t\\end{align*}\n\t\tfor some real number $ \\beta'$. Prove that in this case\n\t\t\\begin{align*}\n\t\t  (\\beta_1 - \\beta_2)^2(\\beta_2 - \\beta_3)^2(\\beta_3 - \\beta_1)^2 < 0\n\t\t\\end{align*}\t\n\t\\end{enumerate}\n\\end{questions}\n\n\n\n\\begin{questions}[resume]\n\t\\item For $ \\beta_1 = 0$, $\\beta_2 = 1$, $\\beta_3 = -1$,\n\t\\begin{enumerate}\n\t\t\\item Compute $(\\beta_1 - \\beta_2)^2(\\beta_2 - \\beta_3)^2(\\beta_3 - \\beta_1)^2$.\n\t\t\\item Compute the coefficients $ p,q$ of the polynomial $ P(x) = (x - \\beta_1)(x - \\beta_2)(x - \\beta_3)$. \n\t\t\\item Compute $-4p^3 - 27q^2$.\n\t\\end{enumerate}\n\\end{questions}\n\n\\begin{questions}[resume]\n  \\item (optional) If you're feeling ambitious prove Proposition \\ref{thm:discriminant} by expanding and simplifying the left and the right hand sides.\n\\end{questions}\n\n\n\n\n\n\n\\newpage\n\\subsection{Symmetries \\& the Discriminant}\n\nThere are generalizations of \\ref{thm:discriminant} for all degrees i.e. we can always express ``the product of the squares of pairwise differences of roots'' as a polynomial in the coefficients. \n\nThe coefficients satisfy the equations \n\\begin{align*}\n\t0  & = \\beta_1 + \\beta_2 + \\beta_3                    \\\\\n\tp  & = \\beta_1 \\beta_2 + \\beta_2 \\beta_3 + \\beta_3\\beta_1 \\\\\n\t-q & = \\beta_1 \\beta_2 \\beta_3                        \n\\end{align*}  \nThe right hand sides of these equations are called \\textbf{elementary symmetric polynomials} (a symmetric polynomial is a multivariable polynomial which remains unchanged if we permute the $\\beta_i$'s). They are called \\emph{elementary} because of the following theorem.\n\n\\begin{thm}[Fundamental Theorem of Symmetric Polynomials]\n\tEvery symmetric polynomial can be expressed uniquely as a polynomial in the elementary symmetric ones.\n\\end{thm}\n\nThis theorem is surprisingly easy to prove once you know your induction well. Try the next problem to get an idea of how the proof of this theorem goes in general.\n\\begin{questions}[resume]\n\t\\item \n\t\\begin{enumerate}\n\t\t\\item Express $ \\beta_1^2 + \\beta_2^2 + \\beta_3^2$ in terms of $ p,q$. \\hint{Expand $(\\beta_1 + \\beta_2 + \\beta_3)^2$.}\n\t\t\n\t\t\\item Why is the expression $ \\beta_1^2 \\beta_2 + \\beta_2^2 \\beta_3  + \\beta_3^2 \\beta_1 $ not symmetric? What terms can you add to it to make it symmetric. Express the resulting polynomial in terms of $ p,q$. \\hint{Expand $(\\beta_1 + \\beta_2 + \\beta_3)(\\beta_1 \\beta_2 + \\beta_2 \\beta_3 + \\beta_3\\beta_1)$}\n\t\\end{enumerate}\n\\end{questions}\n\n\nThe discriminant $(\\beta_1 - \\beta_2)^2(\\beta_2 - \\beta_3)^2(\\beta_3 - \\beta_1)^2$ is also symmetric in $ \\beta_1, \\beta_2, \\beta_3$ (do you see why?) and hence can be written as a polynomial in the elementary symmetric ones, which turns out to be $-4p^3 - 27q^2$.\\\\\n\n This is the simplest connection between symmetries and polynomials. Galois' insight involved studying polynomials with \\emph{fewer} symmetries.\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "5a8de176cbf103badd566c8928610d40dba2e2e6", "size": 10719, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Discriminant.tex", "max_stars_repo_name": "apurvnakade/jhu2018-symmetries-and-polynomials", "max_stars_repo_head_hexsha": "1c3e17b80baddd2e5758110ecbc0b63a9e4ef9d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Discriminant.tex", "max_issues_repo_name": "apurvnakade/jhu2018-symmetries-and-polynomials", "max_issues_repo_head_hexsha": "1c3e17b80baddd2e5758110ecbc0b63a9e4ef9d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Discriminant.tex", "max_forks_repo_name": "apurvnakade/jhu2018-symmetries-and-polynomials", "max_forks_repo_head_hexsha": "1c3e17b80baddd2e5758110ecbc0b63a9e4ef9d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.2933884298, "max_line_length": 334, "alphanum_fraction": 0.6921354604, "num_tokens": 3398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7059397497272899}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{titletoc}\n\\usepackage{titlesec}\n\\usepackage{geometry} \n\\usepackage{fontspec, xunicode, xltxtra}\n\\usepackage{float}\n\\usepackage{cite}\n\\usepackage{amsmath}\n\\usepackage{listings}\n\\usepackage{titletoc}\n\\usepackage{booktabs}\n\n\\geometry{left=3cm,right=3cm,top=3cm,bottom=3cm}\n\\DeclareMathOperator*{\\argmin}{argmin}\n\\DeclareMathOperator*{\\argmax}{argmax}\n\\DeclareMathOperator*{\\logit}{logit}\n\\DeclareMathOperator*{\\var}{var}\n\\DeclareMathOperator*{\\cov}{cov}\n\\DeclareMathOperator*{\\expec}{E}\n\\DeclareMathOperator*{\\deriv}{d}\n\\DeclareMathOperator*{\\const}{constant}\n\n\\begin{document}\n\\title{\\textsf{Homework 8 for Bayesian Data Analysis}}\n\\author{Fan JIN\\quad (2015011506)}\n\\maketitle\n\n\\section*{Question 11.3}\n{\n    \\subsection*{Separate model and Pooled model:}\n    {\n        With the noninformative prior distribution, uniform for $(\\theta, \\log{\\sigma})$,\n        $$y_j | \\theta, \\sigma^2 \\sim \\mathrm{N}(\\theta, \\sigma^2),$$\n        $$p(\\theta, \\sigma^2) \\propto \\sigma^{-2}.$$\n\n        The conditional distributions are\n        $$p(\\theta | \\sigma^2) \\propto 1,$$\n        $$p(\\sigma^2 | \\theta) \\propto \\sigma^{-2}.$$\n\n        It follows that \n        $$p(\\theta | \\sigma^2, y) \\propto 1 \\cdot \\mathrm{N}(\\bar{y}, \\sigma^2/n) \\propto \\exp{\\left( -\\frac{n}{2\\sigma^2} (\\bar{y}-\\theta)^2 \\right)},$$\n        $$p(\\sigma^2 | \\theta, y) \\propto \\sigma^{-2-n} \\cdot \\exp{\\left( -\\frac{1}{2\\sigma^2} \\left[ (n-1)s^2 + n(\\bar{y}-\\theta)^2 \\right] \\right)}.$$\n\n        \\begin{itemize}\n\n        \\item For the separate model, plug in $y$ for the sixth machine only. \n        We can calculate the posterior distribution $\\theta | y$ by simulation, using Metropolis-within-Gibbs on the two conditional distributions above. \n        \\\\ But we have no idea about the seventh machine, for each machine has its separate parameters. \n        Therefore, we cannot obtain the predictive distributions or the posterior mean for the seventh machine.\n\n        \\item For the pooled model, plug in $y$ for all the six machines. \n        We can calculate the posterior distribution $\\theta | y$ by simulation, using Metropolis-within-Gibbs on the two conditional distributions above. \n        \\\\ And we use this posterior distribution to predict the seventh machine, for the machines have pooled parameters. \n\n        \\end{itemize}\n    }\n\n    \\subsection*{Hierarchical model:}\n    {\n        The four conditional distributions are given on p.289 of textbook:\n\n        \\begin{itemize}\n\n        \\item $$\\theta_j | \\mu, \\sigma, \\tau, y \\sim \\mathrm{N}(\\hat{\\theta}_j, V_{\\theta_j}),$$ where\n        $$\\hat{\\theta}_j = \\frac{ \\frac{1}{\\tau^2}\\mu + \\frac{n_j}{\\sigma^2}\\bar{y}_{.j} }{ \\frac{1}{\\tau^2} + \\frac{n_j}{\\sigma^2} },$$\n        $$V_{\\theta_j} = \\frac{1}{ \\frac{1}{\\tau^2} + \\frac{n_j}{\\sigma^2} }.$$\n\n        \\item $$\\mu | \\theta, \\sigma, \\tau, y \\sim \\mathrm{N}(\\hat{\\mu}, \\tau^2/J),$$ where\n        $$\\hat{\\mu} = \\frac{1}{J} \\sum_{j=1}^{J} \\theta_j.$$\n\n        \\item $$\\sigma^2 | \\theta, \\mu, \\tau, y \\sim \\mathrm{Inv-}\\chi^2 (n, \\hat{\\sigma}^2),$$ where\n        $$n = \\sum_{j=1}^{J} n_j,$$\n        $$\\hat{\\sigma}^2 = \\frac{1}{n} \\sum_{j=1}^{J} \\sum_{i=1}^{n_j} (y_{ij} - \\theta_j)^2.$$\n\n        \\item $$\\tau^2 | \\theta, \\mu, \\sigma, y \\sim \\mathrm{Inv-}\\chi^2 (J-1, \\hat{\\tau}^2),$$ where\n        $$\\hat{\\tau}^2 = \\frac{1}{J-1} \\sum_{j=1}^{J} (\\theta_j - \\mu)^2.$$\n\n        \\end{itemize}\n\n        Use Metropolis-within-Gibbs on the four conditional distributions above, we can draw $\\theta_j$, $\\mu$, $\\sigma^2$, $\\tau^2$ by simulation.\n        The posterior distribution $\\theta_j | y$ can be obtained immediately. \n        Then, we obtain $\\mu | y$ and $\\tau^2 | y$, which then give $\\theta_7 | y$. \n        Finally, the posterior distribution $y_{i7} | y$ can be estimated, given $\\sigma^2 | y$ obtained.\n    }\n\n    \\subsection*{Reports}\n    {\n        Source code: ``src1.R''\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.8\\linewidth]{posterior_mean_separate.png}\n            \\caption{}\n        \\end{figure}\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.8\\linewidth]{posterior_mean_pooled.png}\n            \\caption{}\n        \\end{figure}\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.8\\linewidth]{posterior_mean_hierarchical.png}\n            \\caption{}\n        \\end{figure}\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.8\\linewidth]{posterior_predictive_pooled.png}\n            \\caption{}\n        \\end{figure}\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.8\\linewidth]{posterior_predictive_hierarchical.png}\n            \\caption{}\n        \\end{figure}\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.8\\linewidth]{posterior_predictive_mean_pooled.png}\n            \\caption{}\n        \\end{figure}\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.8\\linewidth]{posterior_predictive_mean_hierarchical.png}\n            \\caption{}\n        \\end{figure}\n    }\n}\n\n\\section*{Random-walk Metroplis}\n{\n    Source code: ``src2.R''\n\n    To make the adaptive tune of $\\alpha$ and $\\beta$ at each iteration, according to the empirical formula. For the first 20 iterations, we do not change the hyperparamters.\n\n    \\begin{lstlisting}[language=R]\n    # Adapt\n    if (i > 20) {\n      tune$alpha = 2.4^2 * var(alpha_keep[1:i]) / 2\n      tune$beta = 2.4^2 * var(beta_keep[1:i]) / 2\n    }\n    \\end{lstlisting}\n\n    The adaptived hyperparamters converge to $\\alpha=0.04629154$ and $\\beta=1.906087$.\n    \\begin{lstlisting}[language=R]\n        $alpha\n        [1] 0.04629154\n\n        $beta\n        [1] 1.906087\n    \\end{lstlisting}\n}\n\n\\clearpage\n\\end{document}\n", "meta": {"hexsha": "143ae0d5f2a6ffb869fc293d03cc706234e28a62", "size": 5864, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW8/Homework8.tex", "max_stars_repo_name": "goldsail/BayesianHomework", "max_stars_repo_head_hexsha": "d5506faccbf4d0b7b696c7c2bcb42d020bb0d357", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-07-07T18:55:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-07T18:55:43.000Z", "max_issues_repo_path": "HW8/Homework8.tex", "max_issues_repo_name": "kingium/BayesianHomework", "max_issues_repo_head_hexsha": "d5506faccbf4d0b7b696c7c2bcb42d020bb0d357", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW8/Homework8.tex", "max_forks_repo_name": "kingium/BayesianHomework", "max_forks_repo_head_hexsha": "d5506faccbf4d0b7b696c7c2bcb42d020bb0d357", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.8322580645, "max_line_length": 174, "alphanum_fraction": 0.6067530696, "num_tokens": 1830, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117898012105, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7059397449369986}}
{"text": "\\chapter{Investigating results on the limiting distribution}\n\\section{Playing with the (original) sequence of maxima}\n\\paragraph{}\nHere, we will generate finite size sequences (N = 10000) of independent identically distributed random variables following respectively :\n\\begin{itemize}\n\t\\item a standard Normal Distribution $\\mathcal{N}(0,1)$\n\t\\item a Cauchy Distribution \\textit{Cauchy(0,1)}\n\t\\item an Exponential Distribution \\textit{Exp(1)}\n\\end{itemize}\nWe will compute the sequence of maxima, neither centred nor normalised, and draw the scatter plot as well as the plot of the maxima  $M_n$ as a function of the time steps $n$.\nWe will also draw the $1 - \\frac{1}{n}$-quantiles of the distributions (distributions of the sample, not of the maxima), which we will denote by $q_n$, as a function of the time steps $n$. This will lead us to make an interesting observation.\n\\section{Sample following a Normal distribution}\n\\paragraph{Computing the quantiles}\nThe Normal distribution is a particular case because, unlike in the cases of the Cauchy and the Exponential distribution, there is no explicit form to the cumulative distribution function. We will thus use a \"well-known\"\\footnote{Many textbooks mention it, though it is not necessarily what springs to the mind when thinking about the properties of Gaussian RVs.} inequality, holding $\\forall t > 0$ :\n\\begin{equation}\n(\\frac{1}{t} - \\frac{1}{t^3} ) \\frac{\\exp(-\\frac{t^2}{2})}{\\sqrt{2 \\pi}} < 1 - \\Phi(t) < \\frac{1}{t} \\frac{\\exp(-\\frac{t^2}{2})}{\\sqrt{2 \\pi}}\n\\end{equation}\nFrom there, it is easy to see that the following holds :\n\\begin{equation}\n1 - \\Phi(t) \\sim_{t \\rightarrow +\\infty} \\frac{1}{t} \\frac{\\exp(-\\frac{t^2}{2})}{\\sqrt{2 \\pi}} \\\\\n\\end{equation}\nWhen $n$ grows large, the $1 - \\frac{1}{n}$-quantile grows very large so it is valid to replace $1 - \\Phi(t) $ by its equivalent in the equation satisfied by the quantiles : \\\\\n\\begin{equation}\n\\begin{alignat*}{2}\n&\\textcolor{white}{\\iff} & F_X(q_n) &= 1 - \\frac{1}{n} \\\\ \n&\\iff &  \\frac{1}{q_n} \\frac{\\exp(-\\frac{q_n^2}{2})}{\\sqrt{2 \\pi}}  &= \\frac{1}{n} \\\\\n&\\iff & \\log(q_n) + \\log(\\exp(-\\frac{q_n^2}{2})) + \\log(\\sqrt{2 \\pi}) &= \\log(n)\\\\\n\\end{alignat*}\n\\end{equation}\nThis equation cannot be solved analytically, we will resolve it iteratively. The starting point is $\\log(n) = \\frac{t_0^2}{2}$, which gives us $t_0 = \\sqrt{(2 \\log(n))}$. If we then run the Newton-Raphson algorithm, we see that the corrections to $t_0$ from the next iterations are small enough that we can keep $t_0$ as solution.\\footnote{See the fourth of the figures below}.\n\\begin{figure}[h!]\n\t\\centering\n\t\\caption{Below, a realisation of the sequence of maxima for i.i.d. standard unit Gaussian RVs}\\label{fig:toyingLimitGaussian}\n\\end{figure}\n\\begin{figure}[h!]\n\t\\centering\n\t\\begin{minipage}[b]{0.4\\textwidth}\n        \\centering\n        \\includegraphics[scale =0.4]{/Users/kimartin/Desktop/PDM_thesis_report/latex_template5_57/main/R_Files_1/gaussianScatterMaxima.jpeg}\n        \\caption{Scatter Plot of the \\\\Maxima, n = 10000}\n        \\label{fig:toyingLimitGaussianScatter}\n\t\\end{minipage}\n\t\\begin{minipage}[b]{0.4\\textwidth}\n\t\t        \\centering\n\t\t        \\includegraphics[scale = 0.4]{/Users/kimartin/Desktop/PDM_thesis_report/latex_template5_57/main/R_Files_1/gaussianMaximaAgainstSteps.jpeg}\n\t\t        \\caption{Maxima against the time steps}\n\t\t        \\label{fig:toyingLimitGaussianAgainst}\n\t\\end{minipage}\n \\end{figure}\n \\begin{figure}[h!]\n       \\centering\n       \\includegraphics[scale = 0.4]{/Users/kimartin/Desktop/PDM_thesis_report/latex_template5_57/main/R_Files_1/gaussianFitting.jpeg}\n       \\caption{Maxima against the time steps and function $n \\rightarrow \\sqrt{2 \\log(n)}$}\n       \\label{fig:toyingLimitGaussianFitting}\n\\end{figure}\n \\begin{figure}[h!]\n \t\\centering\n \t\\includegraphics[scale = 0.4]{/Users/kimartin/Desktop/PDM_thesis_report/latex_template5_57/main/R_Files_3/corrApproxQuantileGaussian.jpeg}\n \t\\caption{The correction becomes negligible compared to the starting term as n grows large}\n \t\\label{fig:toyingLimitGaussianCorr}\n \\end{figure}\n\\section{Sample following a Cauchy distribution}\n\\paragraph{Computing the quantiles}\n\\newline\nLet $X_1, \\cdots, X_n $ be i.i.d. RVs $\\sim$ \\textit{Cauchy(0,1)}. The distribution function is $F_X(t) = \\frac{1}{\\pi} \\arctan(x) - \\frac{1}{2}$. The $1 - \\frac{1}{n}$-quantiles satisfy the equation : \n\\newline\n\\begin{equation}\n\\begin{alignat*}{2}\n&\\textcolor{white}{\\iff} & F_X(q_n) &= 1 - \\frac{1}{n} \\\\ \n&\\iff &  \\frac{\\arctan(q_n)}{\\pi} + \\frac{1}{2} &= 1 - \\frac{1}{n} \\\\\n&\\iff & \\frac{\\arctan(q_n)}{\\pi} &= \\frac{2-n}{n} \\\\\n&\\iff & q_n &= \\tan(\\frac{\\pi}{2} \\frac{2-n}{n})\n\\end{alignat*}\n\\end{equation}\n\\begin{figure}[h!]\n\t\t\\caption{Below, a realisation of the sequence of maxima for i.i.d. \\textit{Cauchy(0,1)} RVs}\\label{fig:toyingLimitCauchy}\n\\end{figure}\n\\begin{figure}[h!]\n\t\\centering\n\t\\begin{minipage}[b]{0.4\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[scale =0.4]{/Users/kimartin/Desktop/PDM_thesis_report/latex_template5_57/main/R_Files_1/cauchyScatterMaxima.jpeg}\n\t\t\\caption{Scatter Plot of the \\\\Maxima, n = 10000}\n\t\t\\label{fig:toyingLimitCauchyScatter}\n\t\\end{minipage}\n\t\\begin{minipage}[b]{0.4\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[scale = 0.4]{/Users/kimartin/Desktop/PDM_thesis_report/latex_template5_57/main/R_Files_1/cauchyMaximaAgainstSteps.jpeg}\n\t\t\\caption{Maxima against the time steps}\n\t\t\\label{fig:toyingLimitCauchyAgainst}\n\t\\end{minipage}\n\\end{figure}\n \\begin{figure}[h!]\n \t\\centering\n \t\\includegraphics[scale = 0.4]{/Users/kimartin/Desktop/PDM_thesis_report/latex_template5_57/main/R_Files_1/cauchyFitting.jpeg}\n    \\caption{Maxima against the time steps and function $n \\rightarrow \\tan(\\pi \\frac{2-n}{2 n})}$}\n    \\label{fig:toyingLimitCauchyFitting}\n \\end{figure}\n\\newpage\n \\paragraph{}\n$n \\rightarrow \\tan(\\pi \\frac{2-n}{2 n})}$ is roughly linear in $n$. We know that if $\\lvert x \\rvert < \\frac{\\pi}{2}$, $\\tan(x) = x + \\frac{x^3}{3} + \\frac{2 x^5}{15} + \\cdots$ so if we take the first order approximation, we get $\\tan(x) \\approx x$ which confirms what the plot seems to suggest.\\footnote{Of course the expansion is valid as for a number of observations $n$ greater than $1$, $ -1 < \\frac{2}{n} - 1 < 1$ and thus $\\lvert \\frac{\\pi}{2} \\frac{2 - n}{n} \\rvert = \\vert \\frac{\\pi}{2} (\\frac{2}{n} - 1) \\rvert < \\frac{\\pi}{2}$.}\n\\section{Sample following an Exponential Distribution}\n\\paragraph{Computing the quantiles}\n\\newline\nLet $X_1, \\cdots, X_n $ be i.i.d. RVs $\\sim$ \\textit{Exponential($\\lambda$)}. The distribution function is $F_X(t) = 1 - \\exp(-\\lambda t)$. The $1 - \\frac{1}{n}$-quantiles satisfy the equation : \n\\newline\n\\begin{equation}\n\\begin{alignat*}{2}\n&\\textcolor{white}{\\iff} & F_X(q_n) &= 1 - \\frac{1}{n} \\\\ \n&\\iff & 1 - \\exp(-\\lambda q_n) &= 1 - \\frac{1}{n} \\\\\n&\\iff & q_n &= \\frac{1}{\\lambda} \\log(n)\n\\end{alignat*}\n\\end{equation}\n\\begin{figure}[h!]\n\t\t\\caption{Below, a realisation of the sequence of maxima for i.i.d. \\textit{Exp(1)} RVs}\\label{fig:toyingLimitExponential}\n\\end{figure}\n\\begin{figure}[h!]\n\t\\centering\n\t\\begin{minipage}[b]{0.4\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[scale =0.4]{/Users/kimartin/Desktop/PDM_thesis_report/latex_template5_57/main/R_Files_1/exponentialScatterMaxima.jpeg}\n\t\t\\caption{Scatter Plot of the Maxima, n = 10000}\n\t\t\\label{fig:toyingLimitExponentialScatter}\n\t\\end{minipage}\n\t\\begin{minipage}[b]{0.4\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[scale = 0.4]{/Users/kimartin/Desktop/PDM_thesis_report/latex_template5_57/main/R_Files_1/exponentialMaximaAgainstSteps.jpeg}\n\t\t\\caption{Maxima against the time steps}\n\t\t\\label{fig:toyingLimitExponentialAgainst}\n\t\\end{minipage}\n\\end{figure}\n\\begin{figure}[h!]\n\t\t\\centering\n\t\t\\includegraphics[scale = 0.4]{/Users/kimartin/Desktop/PDM_thesis_report/latex_template5_57/main/R_Files_1/exponentialFitting.jpeg}\n\t\t\\caption{Maxima against the time steps and function $n \\rightarrow \\log(n)}$}\n\t\\label{fig:toyingLimitExponentialFitting}\n\\end{figure}\n\\newpage\n\\section{Why does this work ?}\n\\paragraph{(The underlying idea)}\nWhy have we made a link between the $\\frac{1}{n}$-quantiles of the common distribution of the $X_i$ and the sequence of the $M_n$ ? Actually, the link is that if the sample is made up of independent realizations, then $M_n$ is an estimate of the $1 - \\frac{1}{n}$ quantile. \\newline\nThe idea behind this is as follows, that the maxima will get closer to the upper end-point of the distribution of the $X_i$, $F_{X_i}$. That is also the case for the $1 - \\frac{1}{n}$-quantiles of $F_{X_i}$. Of course, it is only an intuition !\n\\section{What are the limiting distributions in theses cases ?}\n\\paragraph{Preliminary remark}\nIn what follows we are using theoretical results exposed in the next chapter, chapter 3, concerning the three possible limiting distributions as well as Von Mises' theorem.\n\\paragraph{Fr\\'{e}chet limiting distribution}\nLet us assume that a random variable $X$ follows a $Cauchy(0,1)$ distribution, $x^+ = + \\infty$. The limiting distribution can only be either a Gumbel or a Fréchet-type distribution.\n\\begin{equation}\n\\begin{alignat*}{2}\nf_X(x) = \\frac{1}{\\pi} \\frac{1}{1 + x^2}\n\\end{alignat*}\n\\end{equation}\n\\begin{equation}\n\\begin{alignat*}{2}\nF_X(x) = \\frac{1}{\\pi} \\arctan(x) + \\frac{1}{2}\n\\end{alignat*}\n\\end{equation}\n\\begin{equation}\n\\begin{alignat*}{2}\nr(x) &= \\frac{f_X(x)}{1 - F_X(x)} \\\\\n&= \\frac{\\frac{1}{1 + x^2}}{\\frac{\\pi}{2} - \\arctan(x)} \\\\\n&= \\frac{\\frac{1}{1 + x^2}}{\\frac{\\pi}{2} - (\\frac{\\pi}{2} - \\arctan(\\frac{1}{x}))}\\\\\n&= \\frac{1}{(1 + x^2) \\arctan(\\frac{1}{x})}\\\\\n&= \\frac{1}{(1 + x^2) (\\frac{1}{x} + o(\\frac{1}{x^2}))}\\\\\n&= \\frac{1}{\\frac{1 + x^2}{x} + o(1)}\\\\\n\\implies x r(x) &= \\frac{x^2}{x^2 + 1 + o(1)} \\\\\n\\implies x r(x) &\\xrightarrow[x \\rightarrow + \\infty]{} 1\n\\end{alignat*}\n\\end{equation}\nFinally, by Von Mises' theorem, we can conclude that the limiting distribution for the standardized maxima of a $Cauchy(0,1)$ sample is a Fréchet distribution.\n%\\paragraph{Fréchet distribution} \n%Let $X_1, \\cdots, X_n $ be i.i.d. RVs $\\sim$ \\textit{Exponential($\\lambda$)}. Let us remember from the previous section the form of the $\\frac{1}{n}$-quantile $q_n = \\frac{1}{\\lambda}\\log(n)$. Let us evaluate $F_{M_n}$ in $q_\\frac{1}{n}-t$ : \\\\\n%\\begin{equation}\n%\\begin{alignat*}{2}\n%F_{M_n}(q_\\frac{1}{n}-t) &= (1 - \\exp(-\\lambda(q_\\frac{1}{n}-t)))^n\\\\ \n%&= (1 - \\exp(\\lambda t)\\exp(-\\lambda q_\\frac{1}{n}))^n\\\\ \n%&= (1 - \\frac{\\exp(\\lambda t)}{n})^n \\\\\n%&\\longrightarrow_{n \\rightarrow +\\infty} \\exp(-\\exp(\\lambda t)) \\\\\n%\\end{alignat*}\n%\\end{equation}\n\\paragraph{Gumbel limiting distribution}\nLet us assume that a random variable $X$ follows a $Exp(1)$ distribution, $x^+ = + \\infty$. The limiting distribution here again can only be either a Gumbel or a Fréchet-type distribution.\n\\begin{equation}\n\\begin{alignat*}{2}\nf_X(x) = \\lambda \\exp(- \\lambda x)\n\\end{alignat*}\n\\end{equation}\n\\begin{equation}\n\\begin{alignat*}{2}\nF_X(x) =  1 - \\exp(- \\lambda x)\n\\end{alignat*}\n\\end{equation}\n\\begin{equation}\n\\begin{alignat*}{2}\nr(x) &= \\frac{f_X(x)}{1 - F_X(x)} \\\\\n&= \\frac{\\lambda \\exp(- \\lambda x)}{1 - (1 - \\exp(- \\lambda x))} \\\\\n&= \\frac{\\lambda \\exp(- \\lambda x)}{\\exp(- \\lambda x)} \\\\\n&= \\lambda \\\\\n\\implies \\frac{\\mathrm{d}r}{\\mathrm{d}x}(x) &= 0\n\\end{alignat*}\n\\end{equation}\nFinally, by Von Mises' theorem, we can conclude that the limiting distribution for the standardized maxima of an $Exp(1)$ sample is a Gumbel distribution.\n\\paragraph{Gumbel limiting distribution - bis}\nLet us assume that a random variable $X$ follows a $\\mathcal{N}(0,1)$ distribution, $x^+ = + \\infty$. The limiting distribution here again can only be either a Gumbel or a Fréchet-type distribution. It turns out that in that case, the limiting distribution is a Gumbel-type distribution. The computation is slightly more involved than previously, as shown below :\n\\end{equation}\n\\begin{equation}\n\\begin{alignat*}{2}\n\\frac{\\mathrm{d}r}{\\mathrm{d}x}(x) &= \\frac{\\frac{\\mathrm{d}f}{\\mathrm{d}x}(x) (1 - F_X(x)) - f(x) (-f(x))}{(1 - F_X(x))^2} \\\\\n&= \\frac{f(x)^2 + \\frac{\\mathrm{d}f}{\\mathrm{d}x}(x) (1 - F_X(x)) }{(1 - F_X(x))^2}\n\\end{alignat*}\n\\end{equation}\nIt yields an indeterminate form. The key to solve the issue here is to use an expansion of the cumulative distribution function of a standard Gaussian random variable : \\newline\n$\\Phi(x) \\approx \\frac{1}{2} + \\frac{1}{\\sqrt{2 \\pi}} \\exp(\\frac{-x^2}{2}) (x + \\frac{x^3}{3} + \\frac{x^5}{15})$ \\newline\n\\begin{equation}\n\\begin{alignat*}{2}\n\\frac{\\mathrm{d}r}{\\mathrm{d}x}(x) &= \\frac{\n\t\\frac{\\exp(- x^2)}{2 \\pi} - \\frac{x}{2 \\sqrt{2 \\pi}} \\exp(\\frac{-x^2}{2}) + \\frac{x \\exp(- x^2)}{2 \\pi} (x + \\frac{x^3}{3} + \\frac{x^5}{15})\n\t}{\n\t(\\frac{1}{2} - \\frac{1}{\\sqrt{2 \\pi}} \\exp(\\frac{-x^2}{2}) (x + \\frac{x^3}{3} + \\frac{x^5}{15}))^2\n\t} \\\\\n\t&=  \\frac{\n\t\t\\frac{\\exp(- x^2)}{2 \\pi} - \\frac{x}{2 \\sqrt{2 \\pi}} \\exp(\\frac{-x^2}{2}) + \\frac{x \\exp(- x^2)}{2 \\pi} (x + \\frac{x^3}{3} + \\frac{x^5}{15})\n\t}{\n\t\\frac{1}{4} - \\frac{\\exp(\\frac{-x^2}{2})}{\\sqrt{2 \\pi}} (x + \\frac{x^3}{3} + \\frac{x^5}{15}) + \\frac{\\exp(-x^2)}{2 \\pi} (x + \\frac{x^3}{3} + \\frac{x^5}{15})^2 \n} \\\\\n\\end{alignat*}\n\\end{equation}\nNow we can see that if we take the limit when $x$ goes to $+ \\infty$, we get a $0$. By Von Mises' theorem, we can conclude that the limiting distribution for the standardized maxima of a $\\mathcal{N}(0,1)$ sample is a Gumbel distribution.\n\\paragraph{Weibull limiting distribution}\nCauchy, Normal and Exponential distributions all have an infinite upper end-point, thus we cannot get a Weibull distribution as limiting distribution. Let us assume that a random variable $X$ follows a $Unif([0,1])$ distribution, $x^+ = 1 < + \\infty$. \n\\begin{equation}\n\\begin{alignat*}{2}\nf_X(x) = 1\n\\end{alignat*}\n\\end{equation}\n\\begin{equation}\n\\begin{alignat*}{2}\nF_X(x) =  x\n\\end{alignat*}\n\\end{equation}\n\\begin{equation}\n\\begin{alignat*}{2}\nr(x) &= \\frac{f_X(x)}{1 - F_X(x)} \\\\\n&= \\frac{1}{1 - x} \\\\\n\\implies (x^+ - x) r(x) &= (x^+ - x) \\frac{1}{1 - x} \\\\\n\\implies (1 - x) r(x) &= (1 - x) \\frac{1}{1 - x} = 1 \\\\\n\\implies (x^+ - x) r(x) &\\xrightarrow[x \\rightarrow x^+]{} 1 > 0\n\\end{alignat*}\n\\end{equation}\nFinally, by Von Mises' theorem, we can conclude that the limiting distribution for the standardized maxima of a $Unif([0,1])$ sample is a Weibull distribution.", "meta": {"hexsha": "c19108a5474c4dd0773ed4c3f9d4cdd61d6a299b", "size": 14248, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/main/ch4_investigatingLimitingDistributions.tex", "max_stars_repo_name": "CillianMH/pdmExtremeValueTheory", "max_stars_repo_head_hexsha": "f7a7504c2eca0c6be665bcfc3d98dfee6c02de41", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/main/ch4_investigatingLimitingDistributions.tex", "max_issues_repo_name": "CillianMH/pdmExtremeValueTheory", "max_issues_repo_head_hexsha": "f7a7504c2eca0c6be665bcfc3d98dfee6c02de41", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/main/ch4_investigatingLimitingDistributions.tex", "max_forks_repo_name": "CillianMH/pdmExtremeValueTheory", "max_forks_repo_head_hexsha": "f7a7504c2eca0c6be665bcfc3d98dfee6c02de41", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.992, "max_line_length": 540, "alphanum_fraction": 0.683745087, "num_tokens": 5061, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7059397382177721}}
{"text": "%!TEX root = ../notes.tex\n\\section{February 28, 2022}\n\\subsection{Miller-Rabin Primality Test}\nRecall \\cref{prop:aq-1-mod-p} from last class.\n\\begin{proposition*}\n    Let $p$ be an odd prime. Write\n    \\[p-1 = 2^k\\cdot q\\quad\\text{with $q$-odd}\\]\n    Then either\n    \\[a^{q}\\equiv 1\\mod p\\]\n    or one of $a^q, a^{2q}, a^{4q},\\dots, a^{2^{k-1}q}$ is $\\equiv -1\\mod p$.\n\\end{proposition*}\n\nFor $561$, we write $561 = 2^4\\cdot 35$.\n\\begin{align*}\n    2^{35}  & \\equiv 263 \\pmod{561} \\\\\n    2^{70}  & \\equiv 166 \\pmod{561} \\\\\n    2^{140} & \\equiv 67 \\pmod{561}  \\\\\n    2^{280} & \\equiv 1 \\pmod{561}\n\\end{align*}\nusing the following code\\dots\n\\begin{lstlisting}[language=Python]\nfrom crypto import pow_mod\n\npow_mod(2, 35) # 263\n263 ** 2 % 561 # 166\n166 ** 2 % 561 # 67\n67 ** 2 % 561 # 1\n\\end{lstlisting}\n\n\\begin{definition}[Miller-Rabin Witness]\n    $a$ is a \\ul{Miller-Rabin witness} if $a$ does not satisfy above proposition.\n\\end{definition}\n\n\\begin{theorem}\n    If $n$ is composite, then at at least $75\\%$ of $a\\in(\\ZZ/n\\ZZ)$ are Miller-Rabin witnesses.\n\\end{theorem}\n\\begin{proof}\n    Given on faith.\n\\end{proof}\n\n\\begin{algorithm}[Miller-Rabin Probabilistic Primality Test]\n    ~\\begin{lstlisting}[numbers=none,language=Python,escapeinside={(*}{*)}]\nfrom random import randrange\nfrom crypto import pow_mod\n\ndef miller_rabin(n, a):\n    \"\"\"\n    Miller-Rabin primality test on number n and base a\n    \"\"\"\n    q, k = n - 1, 0\n    # Write (*$n-1 = 2^k\\cdot q$*)\n    while q % 2 == 0:\n        k = k + 1\n        q = q // 2\n    a = pow_mod(a, q, n)\n    if a == 1 or a == n - 1:\n        return False\n    for _ in range(k - 1):\n        a = a ** 2 % n\n        if a == n - 1:\n            return False\n    return True\n\ndef is_prime(n):\n    for _ in range(50):\n        if miller_rabin(n, randrange(1, n)):\n            return False\n    return True\n\\end{lstlisting}\n\\end{algorithm}\n\nUsing this, we can find large prime numbers using\n\\begin{lstlisting}[language=Python]\nfrom crypto import miller_rabin, is_prime\ndef next_prime(n):\n    while not is_prime(n):\n        n = n + 1\n    return n\n\\end{lstlisting}\n\n\\begin{theorem}[Prime Number Theorem]\n    Probability that $n$ is prime is about\n    \\[\\frac{1}{\\log(n)}\\]\n    More formally,\n    \\[\\lim_{x\\to \\infty}\\frac{\\text{\\# of primes $\\leq x$}}{x/\\log x} = 1\\]\n\\end{theorem}\n\nSo the Miller-Rabin test lets us efficiently find (large) prime numbers.", "meta": {"hexsha": "6ce6afc1c10a75609c32e6ca9c9c30dc7cf143d2", "size": 2382, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-02-28.tex", "max_stars_repo_name": "jchen/math1580-notes", "max_stars_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-14T15:03:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T15:03:38.000Z", "max_issues_repo_path": "lectures/2022-02-28.tex", "max_issues_repo_name": "jchen/math1580-notes", "max_issues_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_issues_repo_licenses": ["BSL-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures/2022-02-28.tex", "max_forks_repo_name": "jchen/math1580-notes", "max_forks_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_forks_repo_licenses": ["BSL-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0681818182, "max_line_length": 96, "alphanum_fraction": 0.6112510495, "num_tokens": 842, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7059397323569526}}
{"text": "\\subsection{The Hahn-Banach theorem}\\label{subsec:hahn_banach}\n\nThe Hahn-Banach theorem is an important result that can be stated differently and in different levels of generality.\n\n\\begin{theorem}[Geometric Hahn-Banach theorem/Mazur's theorem]\\label{thm:geometric_hahn_banach}\\mcite[24]{ИоффеТихомиров1974}\n  Fix a \\hyperref[def:topological_vector_space]{topological vector space} \\( X \\). Let \\( A \\subseteq X \\) be an open \\hyperref[def:convex_set]{convex} set and \\( L \\subseteq X \\) be a subspace that is disjoint from \\( A \\). Then there exists a continuous linear functional \\( x^* \\in X^* \\) such that\n  \\begin{equation*}\n    \\begin{array}{l}\n      \\real \\inprod{x^*} x > 0, x \\in A \\\\\n      \\real \\inprod{x^*} x = 0, x \\in L\n    \\end{array}\n  \\end{equation*}\n\n  See \\fullref{rem:linear_functionals_over_c} for a justification of only considering the real part of \\( x^* \\).\n\\end{theorem}\n\n\\begin{corollary}\\label{thm:hahn_banach_implies_functionals_vanish_nowhere}\\mcite[24]{ИоффеТихомиров1974}\n  The \\hyperref[def:dual_vector_space]{dual} of a Hausdorff \\hyperref[def:locally_convex_space]{locally convex space} \\( X \\) does not \\hyperref[def:functions_vanish_nowhere]{vanish} at the nonzero vectors of \\( X \\).\n\\end{corollary}\n\\begin{proof}\n  Fix a nonzero point \\( x \\in X \\). The result follows from \\fullref{thm:geometric_hahn_banach} with \\( L \\coloneqq \\{ 0 \\} \\) and \\( A \\) --- any convex set containing \\( x \\) and not containing zero. Such a set \\( A \\) exists because the topology is Hausdorff and \\( x \\) has a neighborhood disjoint from any point in \\( L \\).\n\\end{proof}\n\n\\begin{corollary}\\label{thm:hahn_banach_implies_annihilator_nontrivial}\\mcite[25]{ИоффеТихомиров1974}\n  The \\hyperref[def:vector_space_annihilator]{annihilator} of any proper subspace of a Hausdorff \\hyperref[def:locally_convex_space]{locally convex space} contains nonzero elements.\n\\end{corollary}\n\\begin{proof}\n  Denote the proper subspace by \\( L \\subsetneq X \\). Fix \\( x \\in X \\setminus L \\) and let \\( A \\) be a convex neighborhood of \\( x \\) that is disjoint from \\( L \\). The result follows from \\fullref{thm:geometric_hahn_banach}.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:hahn_banach_implies_duality_mapping_nonempty}\\mcite[25]{ИоффеТихомиров1974}\n  In a \\hyperref[def:norm]{normed} space \\( X \\), for any nonzero vector \\( x \\in X \\) there exists a continuous functional \\( x^* \\in S_{X^*} \\) such that \\( \\inprod {x^*} x = \\norm x \\). In other words, the duality \\hyperref[def:duality_mapping]{mapping} is nonempty for any point.\n\\end{corollary}\n\\begin{proof}\n  This follows from \\fullref{thm:hahn_banach_implies_annihilator_nontrivial} by taking \\( A \\coloneqq B(x, \\abs{x}) \\) and \\( L \\coloneqq \\{ 0 \\} \\) and then scaling the obtained functional.\n\\end{proof}\n\n\\begin{theorem}[Hahn-Banach hyperplane separation theorem]\\label{thm:hahn_banach_hyperplane_separation}\\mcite[25]{ИоффеТихомиров1974}\n  Fix a \\hyperref[def:topological_vector_space]{topological vector space} \\( X \\). Let \\( A, B \\subseteq X \\) be disjoint \\hyperref[def:convex_set]{convex} sets. If \\( \\int{A} \\neq \\varnothing \\), there exists a continuous linear functional \\hyperref[def:hyperplane_separation]{separating} \\( A \\) and \\( B \\).\n\\end{theorem}\n", "meta": {"hexsha": "38d2568e70604ed594b1aab5e914142609ea6102", "size": 3231, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/hahn_banach.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/hahn_banach.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/hahn_banach.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 78.8048780488, "max_line_length": 329, "alphanum_fraction": 0.7313525224, "num_tokens": 1054, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523148, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7059115231066775}}
{"text": "\\lab{Algorithms}{Building Matrices, Sparse Matrices and Algorithmic Complexity}{Matrices and Complexity, cont.}\n\n\\objective{This section explains how to create specific types of large matrices. It also introduces the concept of temporal complexity. Finally, it explores SciPy's special methods for working with sparse matrices.}\n\n\\section*{Temporal Complexity}\n\n%{\\bf The next two paragraphs are an alternate description of Big O, designed as a more intuitive approach, to help with Vol I (a more technical explanation would be in Vol II). Let me know what you think...}\n\n%I am not sure that this is clear or precise enough.  I think that the previously written stuff with some easier problems may be better...\n\nOne of the most important questions in scientific computing is: How long will this operation take?  The concept of temporal complexity attempts to answer this question by determining how much time a function needs to operate on a given size of input.  For example suppose calculating the inverse of a matrix of size $n$ requires the following number of calculations.\n%For this reason we often discuss algorithms in terms of their temporal complexity, which describes how long an operation takes in terms of the size of the input. For example, suppose calculating the inverse of a matrix of size $n$ requires the following number of calculations:\n\\[\nf(n) = \\frac{3n^3}{2} + 75n^2 + 250n + 30\n\\]\nWhat is the most important part of this expression? When our input gets very large the only relevant term in this equation is $n^3$. For this reason we say that $f(n) \\in O(n^3)$, or more commonly that $f(n)$ is $O(n^3)$ (spoken ``Big O of n cubed'' or ``Order of n cubed\"). This notation is borrowed from analysis. This notation captures the salient behavior of our temporal complexity, or more precisely the growth rate we can expect of the execution time of our algorithm. We will discuss this concept later, but this is a simple introduction to the notion of complexity and Big O. Spatial complexity is the amount of memory an algorithm uses, and is defined similarly. \n\n\\begin{comment}\n\nNow that we have begun to study some more complex MATLAB expressions, it is prudent to have a basic notion of the complexity of the operations we are interested in executing.  Complexity theory is the study of the difficulty of computational problems.  What makes computing the sum of two integers easy, and what makes computing the inverse of a large matrix so difficult?  There is an entire field dedicated to answering such questions; in this work we only do a cursory examination to communicate the basic ideas and vocabulary.\n\t\n\tTo begin, we use an example to illustrate what we are trying to accomplish.  There are occasions when one is willing to sacrifice precision in order to focus on more important features of the object of study.  For example, $f(x) = x^3 + \\frac{sin(20x)}{10}$ produces a cubic function with a slight wobble.  In some applications that wobble may be a crucial detail, but in many cases the wobble will be irrelevant and only serves to distract from the salient features of the function.  We extend this example to algorithms.\n\n\tAn algorithm is an ordered set of instructions.  Something simple like a recipe to bake a cake is an algorithm, but the only algorithms you will be dealing with here are MATLAB operations and programs.  To describe the complexity of an algorithm we use asymptotic notation called ``Big O.''  Big O makes us focus on salient features of the complexity of an algorithm while at the same time suppressing unnecessary details, much like we ignored the sine wobble in the previous example.  It has been said that using Big O is ``the art of knowing where to be sloppy and where to be precise.''\n\t\n\tWith that introduction, we define Big O:\n\t\n\\begin{theorem}\n\t$f(x) = O(g(x))$ if and only if $\\exists$ M $\\in \\mathbb{N}, x_0 \\in dom(f)$ such that $|f(x)| \\le M|g(x)|$ $\\forall x > x_0$\n \\end{theorem}\n \n This is an abuse of notation, we really should be saying that $f(x) \\in O(g(x))$ since $O(g(x))$ is not a function but an equivalence class of functions.  Lamentably, using $=$ has become embedded into the culture, so there is not much to be done except make a note of the correct notation and move along.\n \n \\begin{example}\n $x^2 = O(x^3)$ since $x^2 < x^3$ when $x > 1$\n \\end{example}\n \n \\begin{example}\n $x^3 + 3x^2 + x + 4 = O(x^3)$ since $x^3 + 3x^2 + x + 4 < 10x^3$ when $x > 1$\n \\end{example}\n \n  \\begin{example}\n $x^2 + 10000x = O(x^2)$ since $x^2 + 10000x < 100000x^2$ for all x.\n \\end{example}\n \nYou can see that when we talk about Big O of polynomials, we are simply dropping off lower order terms and ignoring coefficients.\n% \n% (These problems may be too challenging)\n% \\begin{problem}\n% Show that $O(\\log{x}) \\subset O(x) \\subset O(x\\log{x})$\n% \\end{problem}\n% \n% \\begin{problem}\n% Show that $O(x^k) \\subset O(x^{k+1})$\n% \\end{problem}\n% \n% \\begin{problem}\n% Show that $O(x^p) \\subset O(2^x)$ for all $p \\in \\mathbb{N}$\n% \\end{problem}\n% \n\tWhat does this have to do with computer programs?  Every algorithm executed on a computer corresponds to a function that returns the number of steps taken (and therefore the time) given an input of size n.  Certain problems can be solved with fewer steps, whilst others require many more.  For example, given two matrices of size n, it only takes about n steps to add the entries together and thus matrix addition is $O(n)$.  On the other hand, given a matrix of size $n$, it takes about $n^3$ steps to calculate its inverse, and thus inverting a matrix is $O(n^3)$.  There is something inherently more difficult about inverting a matrix; there is complexity that simply isn't there with the straightforward operation of addition.\n%\t\n%\tWe will return to complexity analysis after we know a little bit more about writing our own scripts and functions.\n\\end{comment}\t\n\t\n\\section*{Advanced Matrix Tools}\n\nWe now introduce a few different ways to build matrices. Two important methods available for building matrices are \\li{zeros()} and \\li{ones()}. These commands allow us to build matrices populated entirely with zeros or ones, respectively. For example, to build a 3-vector filled with zeros we enter the following command:\n\n\\begin{lstlisting}[style=python]\n: import scipy as sp\n: sp.zeros((3,1))\narray([[ 0.],\n       [ 0.],\n       [ 0.]])\n\\end{lstlisting}\n\nTo find additional options for these methods, you can use the help system.\n\n%Better explanation and an example or two should go here.\n\nOne important use of the \\li{zeros()} method is to allow us to pre-allocate memory. Pre-allocation is simply the practice of reserving a chunk of memory for later use. We can always add more space to a matrix using the methods we learned in lab 1, but this requires many extra internal operations because of way arrays are stored in memory. Thus, it is generally faster to allocate a matrix with its final size and modify its values rather than building an array as you go.\n\n%Problem here comparing pre-allocation vs. no pre-allocation.  There should be several orders of magnitude difference.\n\n% Perhaps more of a segue here?\n\nTable 1.3 gives a few commands that allow us to build types of useful matrices.\n\n\\begin{table}[h!]\n\n\\begin{center}\n\n    \\begin{tabular}{|l|p{4cm}|l|}\n\n    \\hline\n\n    Function & Description & Usage \\\\\n\n    \\hline\n\n    \\li{eye()} & Identity matrix & sp.eye(m, n)\\\\\n\n    \\li{zeros()} & Zero matrix & sp.zeros((m, n))\\\\\n\n    \\li{ones()} & One matrix & sp.ones((m, n))\\\\\n\n    \\li{diag()} & Building (or retrieving) along a diagonal&\\\\\n\n    \\li{linalg.toeplitz()} & Matrix with constant diagonals & la.toeplitz()\\\\\n\n    \\li{linalg.triu()} & Upper triangular&\\\\\n    \n    \\li{linalg.tril()} & Lower triangular&\\\\\n    \n    \\li{rand} & Psuedo-random matrix, uniformily distributed&\\\\\n\n   \\li{randn} & Psuedo-random matrix, normally distributed&\\\\\n\n   \\li{random.randint()} & Psuedo-random matrix, uniformily distributed integers & sp.random.randint()\\\\\n    \n    \\li{tile()} & Copy across a given dimension & sp.tile(A, reps)\\\\\n\n    \\hline\n\n    \\end{tabular}\n\t\\caption{Special matrix creation commands}\n\n\\end{center}\n\\end{table}\n\nFor example, suppose that we want to create a matrix with $-2$ on the diagonal, and ones on the super and sub diagonal. We can do this by using the following command:\n\n\\begin{lstlisting}[style=python]\n: from scipy import linalg as la\n: la.toeplitz([-2,1,0])\narray([[-2,  1,  0],\n       [ 1, -2,  1],\n       [ 0,  1, -2]])\n\\end{lstlisting}\n\nThis matrix is useful because it numerically approximates the second derivative of a function. We investigate some properties of this matrix in Problem 6 of this lab, and explain more about this matrix later.\n\n\\begin{problem}\nUse the \\li{diagflat()} method to create the following matrices. All of these matrices should be easily scaleable (ie only minor modification would be required to change the size).\n\\[\n\\begin{pmatrix}\n1&2&3&4&5\\\\\n0&1&2&3&4\\\\\n0&0&1&2&3 \\\\\n0&0&0&1&2 \\\\\n0&0&0&0&1 \\\\\n\\end{pmatrix}\n\\hspace{8mm}\n\\begin{pmatrix}\n1&1/2&1/3 & 1/4 &1/5\\\\\n1/2&1&1/2&1/3&1/4\\\\\n1/3&1/2&1&1/2&1/3 \\\\\n1/4&1/3&1/2&1&1/2 \\\\\n1/5&1/4&1/3&1/2&1 \\\\\n\\end{pmatrix}\n\\]\n\\end{problem}\n\n\\begin{problem}\nCreate the matrices from Problem 1 using the methods \\li{linalg.toeplitz()} or \\li{linalg.triu()}. Which method is easier? Now use whichever command is easiest to create the matrix:\n\\[\n\\begin{pmatrix}\n1&0&0&0&0\\\\\n0&2&0&0&0\\\\\n0&0&3&0&0 \\\\\n0&0&0&4&0 \\\\\n0&0&0&0&5 \\\\\n\\end{pmatrix}\n\\]\n\\end{problem}\n \n\\begin{problem}\nWrite a function that will create a matrix of size $n$ that has ones on the diagonal and has normally-distributed random entries in the last two columns and the last two rows.\n%Do this in one line using the commands from this section and matrix building techniques from Lab 1.1.\n\\end{problem}\n\n\\section*{Sparse Matrices}\nIn this section we discuss how sparse matrices are used and constructed. A sparse matrix is a matrix that has few non-zero entries (where few is generally relative to the number of entries in the matrix).  SciPy has several different ways of storing sparse matrices.  Each way has it pros and cons (the reader is encouraged to read the help for way).\n\n\\begin{table}[h!]\n\n\\begin{center}\n\n    \\begin{tabular}{|c|c|}\n\n    \\hline\n\n    Function & Description \\\\\n\n    \\hline\n\n    \\li{sparse.bsr()} & Compressed Block Sparse Row\\\\\n    \n    \\li{sparse.coo()} & Coordinate\\\\\n    \n    \\li{sparse.csc()} & Compressed Sparse Column\\\\\n    \n    \\li{sparse.csr()} & Compress Sparse Row\\\\\n    \n    \\li{sparse.dia()} & Sparse Diagonal\\\\\n    \n    \\li{sparse.dok()} & Dictionary of Keys\\\\\n    \n    \\li{sparse.lil()} & Linked List\\\\\n\n    \n    \\hline\n\n    \\end{tabular}\n        \\caption{Sparse matrix representations in SciPy}\n\\end{center}\n\\end{table}\n\nType the following into IPython.\n\\begin{lstlisting}[style=python]\n: from scipy import sparse as spar\n: A = sp.diagflat([2,3,4])\n: B = spar.csc_matrix(A)\n: C = B.todense()\n\\end{lstlisting}\n\nNotice that the matrix $A$ has only three non-zero entries, and so we can consider it sparse. In memory, an array stores a bit of data (be it an integer, float, or complex number) each entry, meaning that a $3 \\times 3$ matrix requires a total 9 blocks of memory. However, if we leverage the sparsity of $A$ we realize that we only need to store 3 numbers. The \\li{sparse} methods do exactly this: they store only the non-zero entries and their locations in the matrix. No longer are we working with array.  SciPy has many methods for performing operations on sparse arrays.  To convert back to a dense matrix, we use the \\li{.todense()} property of the sparse matrix.  We can also convert between the different types sparse arrays.\n\nWe remark that if you want to make a sparse diagonal matrix, the\nbest way to do it isn't to use \\li{diagflat()} followed by \\li{sparse},\nit's actually better to use the \\li{sparse.spdiags()} method:\n\\begin{lstlisting}[style=python]\n: spar.spdiags([2,3,4],0,3,3)\n\\end{lstlisting}\n\nThis is because oftentimes when we are using sparse matrices we are dealing with matrices that are too large to be handled efficiently by python when represented in full form.\n\n\\section*{Banded Matrices}\nA banded matrix is one whose only non-zero entries are diagonal\nstrips.  For example, the matrix\n\\[\nA = \\begin{pmatrix} 1&2&0&0\\\\3&4&5&0\\\\0&6&7&8\\\\0&0&9&10\n\\end{pmatrix}\n\\]\nis banded because there are three nonzero diagonals.  This\nparticular type of banded matrix is called a tri-diagonal matrix.\n\nYou can easily create banded matrices using the \\li{diagflat()} method.  For example, the matrix $A$ above can be created by\nentering\n\\begin{lstlisting}[style=python]\n: sp.diagflat([3,6,9],-1) + sp.diagflat([1,4,7,10],0) + sp.diagflat([2,5,8],1)\n\\end{lstlisting}\n\nOften a better way to create a tri-diagonal is it use the \\li{spar.spdiags()} method. This is because many diagonal matrices are sparse. For example, we create the same matrix in Python (while designating that it is sparse) using the command:\n\\begin{lstlisting}[style=python]\n: Z = sp.array([[3, 1, 0],[6, 4, 2],[9, 7, 5],[0,10,8]]).T\n: spar.spdiags(Z,[-1,0,1],4,4)\n\\end{lstlisting}\n\nFor more information, check the documentation by typing \\li{spar.spdiags?}. For example we create a tri-diagonal array with uniformily distributed random entries.  This example also demonstartes the efficiency of using sparse arrays.\n\\begin{lstlisting}[style=python]\n: B = sp.rand(3,10000)\n: A = spar.spdiags(B,range(-1,2),10000,10000)\n: denseA = A.todense()  #only do this step if you have _lots_ of memory!\n: A.data.nbytes\n240000          #about 0.24MB of memory\n: denseA.nbytes\n800000000       #about 762.9MB of memory!\n\\end{lstlisting}\n\n\nWe can't use the \\li{full} command in this case because the computer will almost certainly run out of memory (the matrix is $10,\\!000 \\times 10,\\!000$). However, we can still visualize this matrix using the \\li{plt.spy()} command from matplotlib, which essentially shows the location of non-zero entries in a matrix. The output of \\li{plt.spy(A)} in this case is shown in Figure 1.2:\n\n%change to plt figure\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[scale = .5]{./Figures/spy}\n\\end{center}\n\\caption{The output of the \\li{spy} command.}\n\\end{figure}\n\n\\section*{Using Sparse Matrices}\n\nConsider the linear system $A x = b$, where $A$ is a\n $100,\\!000\\times 100,\\!000$ tri-diagonal matrix.  To store a full\nmatrix of that size in your computer, it would normally require 10\nbillion double-precision floating-point numbers.  Since it takes 8\nbytes to store a double, it would take roughly 80GB to store the\nfull matrix.  For most desktop computers, that fact alone makes the\nsystem numerically prohibitive to solve. The temporal complexity of the problem is even more problematic. Methods for directly solving an arbitrary linear system are usually $O(n^3)$.  As\na result, even if the computer could store an 80GB matrix in RAM, it\nwould still take several weeks to solve the system.  However, since\nwe don't have computers with that much available RAM, most of the\nmatrix would have to be stored on the hard drive, so the computation\nwould probably take between $6$ months to a year.\n\nThe point is that even the next generation of computers will\nstruggle with solving arbitrary linear systems of this size in a\nreasonable period of time.  However, if we take advantage of the\nsparse structure of the tri-diagonal matrix, we can solve the linear\nsystem, even with a modest modern computer.  This is because all of\nthose zeros don't need to be stored and we don't need to do as many\noperations to row reduce the tri-diagonal system.\n\nLet's first compute the spatial complexity of the above system when\nconsidered as a sparse matrix.  There are three diagonals that have\nroughly $100,\\!000$ non-zero entries.  That's $300,\\!000$\ndouble-precision floating point numbers, which is about 2.4 MB (Less\nstorage than your favorite song).  As a result, it will easily\nfit into the computer's RAM.  Furthermore, the temporal complexity for solving\na tri-diagonal matrix is $O(n)$. Let's see how long it takes to\nsolve the system for random data:\n\n\\begin{lstlisting}[style=python]\n: from scipy.sparse import linalg as sparla\n: from timer import timer\n: D = sp.rand(3, 100000)\n: b = sp.rand(1, 100000)\n: A = spar.spdiags(D,[-1,0,1],100000,100000)\n: def solSys():\n....: return sparla.spsolve(A,b)\n: with timer() as t:\n....: t.time(solSys)\n....: t.printTimes()\n\\end{lstlisting}\n\n\\begin{problem}\nWrite a function that returns a full $n\\times n$\ntri-diagonal array with $2$'s along the diagonal and $-1$'s along\nthe two sub-diagonals above and below the diagonal. Hint: Use the \\li{la.toeplitz()} method. Note that this is the second derivative matrix that we discussed at the beginning of this lab.\n\\end{problem}\n\n\\begin{problem}\nWrite another function that builds the same array as above, but as a sparse array. You must build this as a sparse matrix from the beginning. Hint: Use the \\li{spar.spdiags()} method.\n\\end{problem}\n\n\\begin{problem}\nSolve the linear system $Ax = b$ where $A$ is the $n\\times n$\ntri-diagonal array from the above two problems and $b$ is randomly\ngenerated.  How high can you go for each method?  Make a table for\nseveral different values of $n$ and the time it took to solve for\neach run.  What conclusions can you draw?\n\\end{problem}\n\n\\begin{problem}\nUsing the sparse array above and the method \\li{la.eigs()}, calculate the smallest eigenvalue $\\lambda$ of the array as the array's size goes to infinity. What value does $\\lambda n^2$ approach?  Hint: It's the square of an important number. This is related to operator theory: the second derivative operator has this eigenvalue in certain cases.\n\\end{problem}\n\n\\section*{Other Sparse Commands}\n\nOne important method of sparse array objects is the \\li{nonzero()} method, which is related to the number of nonzero entries in an array.  This number is important because it is an indicator of the amount of time and space that is required to operate on the sparse array. You should be aware that there is some overhead to using and storing the sparse array data structure. Sparsely represented arrays are very beneficial when the number of nonzero entries is relatively small compared to the total number of entries. When the array has many nonzero entries, a sparse representation becomes disadvantageous. To see this, create and execute a script with the following code:\n\\begin{lstlisting}[style=python]\n: A = sp.rand(600,600); B = spar.csc_matrix(A)\n: def square(A): return sp.power(A, 2)\n: with timer() as t:\n....: t.time(square, A)\n....: t.time(square, B)\n\\end{lstlisting}\n\nRun the script and note the two different runtimes. Notice that it takes much longer to square the sparse array. This is because the sparse array data structure is optimized for arrays that are actually sparse. The array $A$ is entirely nonzero. Thus, you incur the overhead of the sparse array representation without any benefits since there are no entries you are not required to store or compute. To summarize, only use a sparse array when your array is in fact sparse. Using sparse arrays for mostly nonzero arrays will negatively impact performance and memory requirements.\n\n\nJust as with dense arrays, we can pre-allocate sparse arrays. Sometimes it is necessary to create sparse matrices that do not have a nice banded pattern.  We initialize a sparse array just like any other array.  The most efficient sparse array for pre-allocation is LIL.  Once you are done constructing you sparse array and wish to perform calculations, you should convert to a more efficient sparse array (CSR or CSC).\n\\begin{lstlisting}[style=python]\n: Z = spar.lil_matrix((400,300))\n<400x300 sparse matrix of type '<type 'numpy.float64'>'\n        with 0 stored elements in LInked List format>\n: Z[1,34] = 23\n: Z[23,32] = 56\n: Z[2,:] = 13.2\n\\end{lstlisting}\n\nThis code snippet creates a $400 \\times 300$ LIL sparse array.  We can then work with the sparse array as though it were a dense array.  When the array is initialized all of the entries\nare assumed to be zero.", "meta": {"hexsha": "f97cae0e6beab2935923be265c9c6c872de747fb", "size": 20034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/Matrices/Matrices2.tex", "max_stars_repo_name": "jasongrout/numerical_computing", "max_stars_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/Matrices/Matrices2.tex", "max_issues_repo_name": "jasongrout/numerical_computing", "max_issues_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/Matrices/Matrices2.tex", "max_forks_repo_name": "jasongrout/numerical_computing", "max_forks_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-21T23:06:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-21T23:06:27.000Z", "avg_line_length": 53.424, "max_line_length": 732, "alphanum_fraction": 0.7381451532, "num_tokens": 5323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581049086031, "lm_q2_score": 0.8872045877523147, "lm_q1q2_score": 0.7059115209572252}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[top=1in, bottom=1in, left=0.6in, right=0.6in]{geometry}\n\\usepackage{lipsum}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage[hidelinks]{hyperref}\n\\usepackage{graphicx}\n\\usepackage[\nbackend=biber,\nstyle=numeric,\ndoi=false,\nurl=false,\nmaxbibnames=9\n]{biblatex}\n\\addbibresource{sysbio2018_blackboard.bib}\n\n%\\newcommand{\\mymatrix}[1]{{\\boldsymbol{#1}}}\n\\newcommand{\\mymatrix}[1]{#1}\n\\newcommand{\\myvector}[1]{{\\boldsymbol{#1}}}\n\\newcommand{\\fluxcone}{\\mathcal{C}}\n\\newcommand{\\stoichmat}{\\mymatrix{S}}\n\\newcommand{\\stoichmatint}{\\mymatrix{S}_{\\mathsf{int}}}\n\n\\date{March 2, 2018}\n\\title{\\textbf{SysBio 2018}\\\\Innsbruck, Austria}\n\\author{Elad Noor}\n\\begin{document}\n\\maketitle\n\\tableofcontents\n\n\\section{Blackboard session: Metabolic Engineering}\n\n\\subsection{Introduction}\n\\subsubsection{Linear Programming (LP)}\nEvery Linear Programming problem can be converted to a canonical form that is:\n\\begin{eqnarray}\n\t\\textsf{\\textbf{Primal}}&&\\nonumber\\\\\n\t&\\textsf{maximize}&\\myvector{c}^\\top\\myvector{x}\\nonumber\\\\\n\t&\\textsf{subject to}&\\mymatrix{A}\\myvector{x} \\leq \\myvector{b}\\nonumber\\\\\n\t&\\textsf{and}&\\myvector{x}\\geq \\myvector{0}\\,.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\end{eqnarray}\n\nThe dual is a symmetrical linear problem described by the following constraints\n\\begin{eqnarray}\n\t\\textsf{\\textbf{Dual}}&&\\nonumber\\\\\n\t&\\textsf{minimize}&\\myvector{b}^\\top\\myvector{y}\\nonumber\\\\\n\t&\\textsf{subject to}&\\mymatrix{A}^\\top\\myvector{y} \\geq \\myvector{c}\\nonumber\\\\\n\t&\\textsf{and}&\\myvector{y}\\geq 0\\,.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\end{eqnarray}\n\nIf the primal has an optimal solution ($\\myvector{x}^*$), then the dual will also have an optimal solution ($\\myvector{y}^*$) and their values will be equal:\n\\begin{eqnarray}\n\t\\textsf{\\textbf{Strong duality theorem}}&&\\nonumber\\\\\n\t&&\\myvector{c}^\\top\\myvector{x}^* = \\myvector{b}^\\top\\myvector{y}^*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\end{eqnarray}\n\nLinear Programming problems can be solved very efficiently using established algorithms such as Simplex. Many good solvers exist for LP, including open source options such as glpk, CLP, and the internal R-project solver.\n\n\\subsubsection{Mixed-Integer Linear Programming (MILP)}\nIf a LP contains variables that can only have integer values (or in a more specific case, boolean values), the problem cannot be solved using the standard methods. In fate, MILP problems in general are NP-complete, i.e. computationally hard. The free solvers are typically not good enough for solving MILPs. Nevertheless, advanced commercial solvers such as CPLEX and Gurobi are quite efficient in solving even large MILPs in reasonable time, and provide free licenses for academics.\n\n\\subsection{Convex analysis of a metabolic flux cone}\nThe basic idea underlying most metabolic constraint-based models, is mass-balance combined with the steady-state assumption. Formally, given a stoichiometric matrix $\\mymatrix{S}$, where rows represent metabolites and column represent reactions, and given a flux vector $\\myvector{v}$, the rate of change in metabolite levels ($\\myvector{c}$) is given by the equation.\n\\begin{eqnarray}\\label{eq:dynamic-mass-balance}\n\t&\\textsf{\\textbf{Dynamic mass-balance}} &\\nonumber\\\\\n    &&\\frac{d\\myvector{c}}{dt} = \\stoichmat \\myvector{v}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\end{eqnarray}\nFor the subset of rows in $\\stoichmat$ that represent internal metabolites (e.g. intracellular metabolites) which is denoted $\\stoichmatint$, the pseudo steady-state assumption states that their concentrations do not change over time.\n\\begin{eqnarray}\\label{eq:pseudo-steady-state}\n\t&\\textsf{\\textbf{Pseudo steady-state}} &\\nonumber\\\\\n\t&&\\stoichmatint \\myvector{v} = 0~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\end{eqnarray}\nNote that external metabolites are not constrained in this way. For example, the concentration of extracellular glucose in the medium decreases gradually while cells are growing at steady-state. Therefore, pseudo steady-state flux solutions are contained within the null-space (or kernel) of $\\stoichmatint$, i.e. $\\myvector{v} \\in \\ker(\\stoichmatint)$.\n\n\\subsubsection{The flux cone}\nTypically, many of the reactions in our model will be considered irreversible, due to thermodynamic constraints (and we will elaborate on this topic in section \\ref{sec:thermodynamics}). Therefore, a subset of the fluxes will be constrained to be positive:\n\\begin{eqnarray}\\label{eq:irreversible}\n\\forall i \\in I_{irr} ~~ v_i \\geq 0\n\\end{eqnarray}\n\nTherefore, the set of possible flux solutions would be all fluxes that satisfy both equation \\ref{eq:pseudo-steady-state} and \\ref{eq:irreversible}. Explicitly, it would be the intersection of all the hyperplanes that represent rows in $\\stoichmatint$ described by $S_{j*}\\cdot \\myvector{v} = 0$ and all half-spaces corresponding to irreversible reactions $\\myvector{e_i} \\cdot \\myvector{v} \\geq 0$ (where $\\myvector{e_i}$ is the unit vector corresponding to reaction $i$). This intersection is an unbound convex polyhedron denoted the steady-state \\emph{flux cone} or $\\fluxcone$ \\cite{marashi_analysis_2012}.\n\t\nIt is important to note, that the flux cone is unbounded in some directions, i.e. it can extend to infinity. Therefore, we typically ignore the absolute values of the fluxes (represented, for example, by $||\\myvector{v}||$) and consider only the relative values -- i.e. the direction towards which the vector is pointing. It is often easier to only consider normalized vectors, such as ones whose biomass rate is set to 1.\n\t\n\\begin{eqnarray}\\label{eq:fluxcone}\n\t&\\textsf{\\textbf{Flux cone}} &\\nonumber\\\\\n\t&&\\fluxcone = \\{\\myvector{v} \\in \\mathbb{R}^n~|~\\stoichmatint\\myvector{v} = 0 ~\\wedge ~ v_i \\geq 0~~\\forall i \\in I_{irr}\\}~~~~~~~~~~~~~~~~~\n\\end{eqnarray}\n\n\\subsubsection{Elementary Flux Modes}\nElementary Flux Modes (EFMs) are defined as the set of all non-decomposable vectors in the flux cone. A non-decomposable vector is one whose \\textit{support} (the set of reactions with non-zero flux) is minimal -- i.e. the flux cone does not contain any vectors whose support is a proper subset of it. EFMs also form a convex basis for the flux cone \\cite{schilling_theory_2000}:\n\\begin{eqnarray}\n\\forall \\myvector{v} \\in \\fluxcone:~ \\exists \\lambda_j \\geq 0 ~~\\text{s.t.}~~ \\myvector{v} = \\sum_j \\lambda_j~\\myvector{e}^j\n\\end{eqnarray}\nwhere $\\{\\myvector{e}^j\\}_j$ is the set of all EFMs. Figure \\ref{fig:toy1} illustrates a model with 10 reactions and 9 EFMs.\n\\begin{figure}[ht!]\n\t\\begin{center}\n\t\\includegraphics[width=0.8\\textwidth]{toy1}\n\t\\caption{A toy example with 6 internal reactions and 4 exchange reactions. The flux cone is spanned by 9 EFMs.}\\label{fig:toy1}\n\t\\end{center}\n\\end{figure}\n\nEFMs are closely related to Extreme Pathways (EPs) and distinguishing them requires more subtle definitions. For further reading you can refer to \\cite{klamt_two_2003}.\n\n\\subsubsection{Classification of EFMs}\nEven in our small toy example in Figure \\ref{fig:toy1}, we already encounter a common problem that arises when dealing with EFMs -- i.e. cycles. In this example, it's quite obvious that the two EFMs that consist of combining two opposing reactions is futile and should be ignored. Larger networks, however, might have much larger cycles that are harder to identify and get rid of.\n\nFirst, we need to distinguish between \\textit{primary exchange} and \\textit{currency exchange} reactions. The former are the standard reactions that exchange nutrients between the cell/compartment and its environment (sugar import, CO$_2$ export, etc.). \\textit{Currency exchange} reactions do not, in fact, exchange material between compartments, but are rather abstract representations of energy dissipation. A canonical example would be the ATP maintenance reaction that is present in most metabolic models: ATP + H$_2$O $\\rightharpoonup$ ADP + P$_i$.\n\nNow, we can define the three types of EFMs (\\cite{price_extreme_2002}, see Figure \\ref{fig:efm_types}):\n\\begin{description}\n\t\\item[I] -- \\textit{Primary systemic EFMs} have at least one active primary exchange flux.\n\t\\item[II] -- \\textit{Futile cycles} have no active primary exchange fluxes, and at least one active currency exchange flux.\n\t\\item[III] -- \\textit{Internal cycles} have no active exchange fluxes (neither primary nor currency). \n\\end{description}\n\n\\begin{figure}[ht!]\n\t\\begin{center}\t\\includegraphics[width=0.7\\textwidth]{extreme_pathway_types}\n\t\\caption{The three types of Elementary Flux Modes.}\\label{fig:efm_types}\n\t\\end{center}\n\\end{figure}\n\nTo illustrate the three types of pathways, we present another toy model with one currency exchange reaction and two primary exchange reactions (Figure \\ref{fig:toy2}). This model contains all the three types of EFMs.\n\\begin{figure}[ht!]\n\t\\begin{center}\n\t\\includegraphics[width=0.5\\textwidth]{toy2}\n\t\\caption{A small toy model with 8 internal reactions, 2 primary exchange reactions, and one currency exchange reaction. In this simple network, one can identify all three types of extreme pathways. The Type I pathway (green) is typically the type of solution that most constrain-based models are seeking. The Type II pathway ($A \\rightarrow B \\rightarrow C \\rightarrow A$, blue) is a typical futile cycle, since it does not involve any primary exchange reactions, but does \\emph{waste} ATP. The Type III pathway ($A \\rightarrow C \\rightarrow D \\rightarrow A$, red) is called internal since none of its reactions are exchange reactions. An internal cycle will never be thermodynamically feasible.\n\t}\\label{fig:toy2}\n\t\\end{center}\n\\end{figure}\n\nIn the next section, we will see how this three type classification is useful to separate thermodynamically feasible pathways from infeasible ones.\n\n\\subsection{Thermodynamics}\\label{sec:thermodynamics}\nA fundamental principle in enzymatic catalysis is the notion that enzymes can accelerate the rate of a reaction, but not change its thermodynamic equilibrium, therefore they have no effect on the \\textit{direction} of flux.\n\n\\subsubsection{The Gibbs free energy of reaction}\n\nThe second law of thermodynamics states that entropy can never decrease over time in an isolated system. In living cells, which are open systems in constant pressure, temperature, and pH, entropy can be replaced by the concept of transformed Gibbs free energy of reaction \\cite{alberty_biochemical_2006-1}, denoted $\\Delta_r G'$. Then, for a chemical reaction to be feasible, it must impose a negative change in $\\Delta_r G'$:\n\\begin{eqnarray}\n\\Delta_r G' < 0\n\\end{eqnarray}\nFor the purpose of constraint-based modeling, it is enough to understand how each $\\Delta_r G'$ is affected by its reactant concentration. We typically use the assumption that biochemical reactions occur in dilute aqueous solutions (i.e. the activity coefficient of uncharged species is unity). In this case, the transformed Gibbs free energy of reaction $j$ is given by:\n\\begin{eqnarray}\\label{eq:thermo1}\n\\Delta_r G'_j &=& \\Delta_r G'^\\circ_j + R\\,T\\cdot\\ln(Q'_j) \\\\\nQ'_j &=& \\prod_i c_i^{S_{ij}}\n\\end{eqnarray}\nwhere $R$ is the gas constant, $T$ is the temperature (in Kalvin), $Q'$ is the biochemical reaction quotient, $c_i$ is the molar concentration of a reactant (substrate of product) and $S_{ij}$ are the corresponding stoichiometric coefficients (i.e. a row in $\\stoichmatint$). $\\Delta_r G'^\\circ_j$ represents that $\\Delta_r G'_j$ in standard conditions, which is typically defined as 1 M for each one of the reactants. One way to measure $\\Delta_r G'^\\circ_j$, is to let the reaction run until it reaches equilibrium, and measure the concentrations of all reactants. The value of $Q'$ in equilibrium is called the \\textit{equilibrium constant} and is denoted $K'$. Also, since know that at equilibrium $\\Delta_r G'_j = 0$, we can solve for $\\Delta_r G'^\\circ_j$ and get:\n\\begin{eqnarray}\n\\Delta_r G'^\\circ_j &=& -R\\,T\\cdot\\ln(K'_j)\n\\end{eqnarray}\nFor further reading on thermodynamics of biochemical reactions, see \\cite{alberty_recommendations_2011, noor_note_2013}.\n\n\nFinally, we would like to rewrite equations \\ref{eq:thermo1} in a more convenient way that corresponds well with our linear algebra notation. First, one can notice that taking the log from $Q'$ makes it a linear function of the log-concentration values: $\\ln(Q'_j) = \\sum_i S_{ij} \\cdot \\ln(c_i)$. In addition, from now on we will use a matrix notation for calculating the vector of all reaction Gibbs energies ($\\myvector{\\Delta_r G'}$):\n\\begin{eqnarray}\n\\myvector{\\Delta_r G'} = \\myvector{\\Delta_r G'^\\circ} + R\\,T\\cdot\\stoichmat^\\top \\myvector{x}\n\\end{eqnarray}\nwhere we define $\\myvector{x}$ as the vector of log-concentrations, i.e. $x_i = \\ln(c_i)$.\n\n\\subsubsection{Irreversibility is an approximation}\nIn pure physics terms, every chemical reaction should be reversible. There are cases, where the equilibrium is so far from unity, which makes it impossible for the reaction to reach equilibrium in practice. In these cases, it is sometimes convenient to assume that the reaction is irreversible and complete ignore the reverse direction. In defining the flux cone, this assumption can significantly reduce the solution space and number of EFMs.\n\nMost thermodynamics-aware models, however, cannot make this assumption. Every reaction must have a defined equilibrium constant, no matter how extreme it might be. Therefore, from now on, we assume $\\Delta_r G'^\\circ_j$ has a finite value, even for reactions that are defined as irreversible in our model. There is no universal threshold for $\\Delta_r G'^\\circ_j$ which make a reaction irreversible. It is context dependent and a topic of much debate \\cite{mavrovouniotis_identification_1993-1, henry_thermodynamics-based_2007, noor_integrated_2012}. \n\nBeyond $\\Delta_r G'^\\circ_j$, probably the most important parameters for determining the reversibility are the range of concentrations allowed for each of the reactants. Basically, a reversible reaction should have both positive and negative values to its $\\Delta_r G'_j$, depending on the chosen reactant concentrations within their predefined ranges. If we denote the vectors of lower and upper bounds as $\\myvector{b}^L$ and $\\myvector{b}^U$, respectively, the constraint on $\\myvector{x}$ would be:\n\\begin{eqnarray}\n\\ln(\\myvector{b}^L) \\leq \\myvector{x} \\leq \\ln(\\myvector{b}^U)\n\\end{eqnarray}\nIt is easy to see, that the lowest value for $\\Delta_r G'_j$ is achieved when all substrate concentrations are set to their value in $\\myvector{b}^U$, and all product concentrations to $\\myvector{b}^L$. The highest value of $\\Delta_r G'_j$ occurs in the opposite extreme. Then, it become straightforward to check if a reaction is, by itself, reversible or not.\n\n\\subsubsection{Thermodynamic Feasibility of EFMs}\nGiven a specific elementary flux mode $\\myvector{e}^j$ (or any flux vector $\\myvector{v}$, for that matter), we would like to know whether it is thermodynamically feasible according to the second law. First, every one of the support reactions must be feasible in the direction defined by $\\myvector{e}^j$. However, the same metabolite can be a substrate for one reaction, and a product for another and therefore there is inter-dependence between the $\\Delta_r G'_j$ values of these reactions. Sometimes, even though a series of reactions can be individually feasible, their combination is infeasible. This has been termed a \\textit{distributed bottleneck} by \\textcite{mavrovouniotis_identification_1993-1} in 1993.\n\nUsing Linear Programming, it is relatively simple to test thermodynamic feasibility:\n\\begin{eqnarray}\\label{eq:feasible_lp}\n\\textsf{Find}&\\myvector{x}&\\nonumber\\\\\n\\textsf{such that}&&\\nonumber\\\\\n\\myvector{\\Delta_r G'} &\\equiv& \\myvector{\\Delta_r G'^\\circ} + RT \\cdot \\stoichmat^\\top \\myvector{x} \\nonumber\\\\\n\\myvector{\\Delta_r G'} &<& 0\\nonumber\\\\\n\\ln(\\myvector{b}^L) &\\leq& \\myvector{x} ~\\leq~ \\ln(\\myvector{b}^U) \n\\end{eqnarray}\n\n\\subsubsection{Max-min Driving Force}\nIn order to provide a more quantitative measure for the thermodynamic feasibility of a given pathway, the Max-min Driving Force (MDF) method provides a relatively simple measure. We adjust the Linear Program in Equation \\ref{eq:feasible_lp}, by adding a margin variable ($B$) and maximizing its value:\n\\begin{eqnarray}\n\\textsf{MDF} &\\equiv& \\max_{B,\\myvector{x}}{B} \\nonumber\\\\\n\\textsf{such that}&&\\nonumber\\\\\n\\myvector{\\Delta_r G'} &\\equiv& \\myvector{\\Delta_r G'^\\circ} + RT \\cdot \\stoichmat^\\top \\myvector{x} \\nonumber\\\\\n\\myvector{\\Delta_r G'} &<& -B\\nonumber\\\\\n\\ln(\\myvector{b}^L) &\\leq& \\myvector{x} ~\\leq~ \\ln(\\myvector{b}^U) \n\\end{eqnarray}\nIf the MDF is positive, then there exists a set of concentrations $\\myvector{x}$ (inside the allowed range) such that $\\myvector{\\Delta_r G'} \\leq -B < 0$, i.e. this pathway is thermodynamically feasible. The larger $B$ is, the ``more feasible'' it is, since we can keep all reactions farther away from equilibrium. From non-equilibrium thermodynamic theory, we know that reactions that are far from equilibrium tend to be more efficient (as described by the flux-force relationship \\cite{beard_relationship_2007-1}). An example for MDF calculation is given in Figure \\ref{fig:mdf}.\n\nAn online interface for running MDF analysis can be found here: \\url{http://equilibrator.weizmann.ac.il/pathway/}.\n\n\\begin{figure}[ht!]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.8\\textwidth]{mdf}\n\t\t\\caption{(left) Schematic comparison between two pathways. Each pathway starts and ends with the same compounds, employs five enzymes and carries the same net flux. The kinetic parameters of all enzymes in both pathways, as well as enzyme and metabolite concentrations, are assumed to be identical. (right) Energetic profile of Embden-Meyerhof-Parnas glycolysis. Dashed black line corresponds to $\\Delta_r G'^\\circ$ values (metabolite concentrations of 1M) of pathway reactions at pH 7.5. Red line corresponds to $\\Delta_r G'$ values of pathway reactions after an optimization procedure that maximizes the driving force of the thermodynamic bottleneck reactions. Figure is from \\textcite{noor_pathway_2014}.\n\t\t}\\label{fig:mdf}\n\t\\end{center}\n\\end{figure}\n\n\\subsubsection{Thermodynamic Flux Balance Analysis (TFBA)}\n\nThermodynamic FBA (also known as Thermo\\-dynamic-based Metabolic Flux Analysis \\cite{henry_thermodynamics-based_2007}) was designed to deal with thermodynamically infeasible flux solutions within the framework of FBA:\n\\begin{eqnarray}\n\\textsf{\\textbf{FBA}} && \\nonumber\\\\\n\\myvector{v^*} &=& \\mathrm{arg\\max_v} {~\\myvector{c}^\\top\\myvector{v}}\\nonumber\\\\\n\\textsf{such that:} && \\nonumber\\\\\n\\stoichmatint \\myvector{v} &=& \\myvector{0}  \\label{eq:fba1} \\\\\n\\myvector{v}_{LB} &\\leq& \\myvector{v} ~\\leq~ \\myvector{v}_{UB} \\label{eq:fba2}\n\\end{eqnarray}\nwhere $\\myvector{c} \\in \\mathbb{R}^r$ is the objective function, and the constants are the internal stoichiometric matrix $\\stoichmatint \\in \\mathbb{R}^{m \\times r}$. $\\myvector{v}_{LB}$ and $\\myvector{v}_{UB}$ are the lower and upper bounds on the fluxes, typically relevant only for exchange fluxes.\n\nTFBA adds another two sets of variables -- the boolean flux indicators ($\\myvector{y} \\in \\{0, 1\\}^r$), and the log-concentrations ($\\myvector{x} \\in \\mathbb{R}^r$). Then, the following constraints are added to the Linear Problem (which is now actually a Mixed-Integer Linear Problem -- MILP):\n\\begin{eqnarray}\n\\textsf{\\textbf{TFBA}} && \\nonumber\\\\\n\\myvector{v^*} &=& \\mathrm{arg\\max_v} {~\\myvector{c}^\\top\\myvector{v}}\\nonumber\\\\\n\\textsf{such that:} && \\nonumber\\\\\n\\stoichmatint \\myvector{v} &=& \\myvector{0} \\nonumber\\\\\n\\myvector{v}_{LB} &\\leq& \\myvector{v} ~\\leq~ \\myvector{v}_{UB} \\nonumber\\\\\n0 &\\leq& M \\myvector{y} - \\myvector{v} ~\\leq~ M  \\label{eq:tfba1}\\\\\n0 &<& M \\myvector{y} + \\myvector{\\Delta_r G'} ~<~ M \\label{eq:tfba2} \\\\\n\\myvector{\\Delta_r G'} &=& \\myvector{\\Delta_r G'^\\circ} + RT \\cdot \\stoichmat^\\top \\myvector{x} \\label{eq:tfba3}\\\\\n\\ln(\\myvector{b}^L) &\\leq& \\myvector{x} ~\\leq~ \\ln(\\myvector{b}^U) \\label{eq:tfba4}\n\\end{eqnarray}\nThe new constants are the vector of standard Gibbs energies of reaction $\\myvector{\\Delta_r G'^\\circ}$ (in units of kJ/mol), the gas constant $R$ = 8.31 J/mol/K and temperature $T$ = 300 K. $M$ which is a very large number (larger than any of the possible flux and Gibbs free energy). Note also the difference between the internal stoichiometric matrix ($\\stoichmatint$) used for the pseudo steady-state assumption, versus the full stoichiometric matrix ($\\stoichmat$) used in the Gibbs free energy calculation.\n\nEquations \\ref{eq:tfba3}-\\ref{eq:tfba4} should be familiar, and are exactly the same as in previous sections. To understand how the other two constraints (\\ref{eq:tfba1}-\\ref{eq:tfba2}) enforce thermodynamic feasibility, we consider three possible cases for each reaction $j$ separately:\n\\begin{enumerate}\n\t\\item $v_j > 0$ : the only possible value that $y_j$ can have is 1, otherwise, $My_j - v_j$ would be negative and violate constraint \\ref{eq:tfba1}. Therefore, constraint \\ref{eq:tfba2} becomes $0 < M + \\Delta_r G'_j < M$, which means that $\\Delta_r G'_j < 0$.\n\t\\item $v_j < 0$ : the only possible value that $y_j$ can have is 0, otherwise, $My_j - v_j$ would be larger than $M$ and violate constraint \\ref{eq:tfba1}. Therefore, constraint \\ref{eq:tfba2} becomes $0 < \\Delta_r G'_j < M$, which means that $\\Delta_r G'_j > 0$.\n\t\\item $v_j = 0$ : both $0$ and $1$ are possible solutions for $y_j$. Therefore, there are no constraints on $\\Delta_r G'_j$.\n\\end{enumerate}\nSummarizing these 3 cases, one can concisely write:\n\\begin{eqnarray}\n\\forall j:v_j = 0~\\vee~\\text{sign}(v_j) = -\\text{sign}(\\Delta_r G'_j)\\,,\n\\end{eqnarray}\nwhich is exactly the second law of thermodynamics.\n\n\\subsubsection{Loopless Flux Balance Analysis (ll-FBA)}\nThe loopless algorithm \\cite{schellenberger_elimination_2011} is very similar to TFBA, except that there are no actual thermodynamic values. This way, thermodynamically infeasible internal (Type III) cycles are eliminated, while all other pathways are kept \\cite{noor_proof_2012}. The set of equations describing ll-FBA are:\n\\begin{eqnarray}\n\\textsf{\\textbf{ll-FBA}} && \\nonumber\\\\\n\\myvector{v^*} &=& \\mathrm{arg\\max_v} {~\\myvector{c}^\\top\\myvector{v}}\\nonumber\\\\\n\\textsf{such that:} && \\nonumber\\\\\n\\stoichmatint \\myvector{v} &=& \\myvector{0} \\label{eq:llfba1} \\\\\n\\myvector{v}_{LB} &\\leq& \\myvector{v} ~\\leq~ \\myvector{v}_{UB} \\\\\n0 &\\leq& M \\myvector{y} - \\myvector{v} ~\\leq~ M\n\\label{eq:llfba2} \\\\\n0 &<& M \\myvector{y} + \\myvector{\\Delta_r G'} ~<~ M \\label{eq:llfba3} \\\\\n\\myvector{\\Delta_r G'} &\\in& \\ker{(\\stoichmat)}^\\perp \\label{eq:llfba5}\n\\end{eqnarray}\nhere, $\\myvector{\\Delta_r G'}$ is not constrained by the $\\myvector{\\Delta_r G'}^\\circ$ and the metabolite concentrations, but is only required to be orthogonal to the null-space of $\\stoichmat$ (or, equivalently, to be in $\\mathrm{image}(\\stoichmat^\\top)$).\n\nWhy does ll-FBA not eliminate type II cycles from the set of flux solutions? These futile cycles ``waste'' resources such as ATP, but are thermodynamically feasible. They are only considered ``cycles'' because we chose to give co-factors a special status (namely, they are external metabolites that do not need to be kept at steady-state). In other words, type II EFMs are in the null-space of $\\stoichmatint$, but not in the null-space of $\\stoichmat$ (just like type I EFMs). Therefore, it is possible to assign negative $\\Delta_r G'$ values to all reactions in a type II EFMs.\n\nInterestingly, this argument can be applied also to the reverse of such futile cycle. Running a futile cycle in reverse is sometimes called an Energy Generating Cycle (EGC), and is obviously unrealistic. Furthermore, unlike type III cycles that do not affect the biomass rate in standard FBA, EGCs have the potential to increase the maximal biomass yield and pose a more serious problem in FBA models \\cite{fritzemeier_erroneous_2017-2}. This is one of the cases where TFBA differs from ll-FBA, as it prevents the use of EGCs completely, while ll-FBA doesn't.\n\n\\subsection{Metabolic engineering algorithms}\n\n\\subsubsection{Phenotypic Phase Plane (PPP)}\nThis useful concept derived from FBA, is a term for 2D projections on the flux polytope. Typically, one chooses specific reaction (e.g. exchange of succinate) for the y-axis and the FBA objective (i.e. biomass rate) for the x-axis. The projection of the flux polytope onto this plane creates a convex polygon shape and helps to visualize how important a certain flux is for creating biomass. Often for cases where the selected flux is a fermentation product, the PPP is referred to as a \\textit{production envelope}. It is standard practice to present strain-design results by overlaying two or more PPPs, e.g. a knockout strain versus the wild-type (Figure \\ref{fig:ppp}). Using such comparisons, it is easy to see if the knockout is useful for forcing a cell to produce the desired chemical byproduct, by coupling its production to the biomass rate.\n\n\\begin{figure}[ht!]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.7\\textwidth]{ppp}\n\t\t\\caption{Phenotypic phase planes for anaerobic succinate production from glucose based on the \\textit{E. coli} core model. (a) wild-type strain (light gray) vs. triple-deletion mutant (ACKr, ATPS4r, FUM) resulting in a design without growth-coupling (purple). (b) wild-type strain vs. triple-deletion mutant (ACALD, PYK, ME2) resulting in a partially growth-coupled design. (c) wild-type strain vs. double-deletion mutant (ACALD, LDH\\_D) resulting in a fully growth-coupled design. Figure is from \\textcite{machado_co-evolution_2015}.}\\label{fig:ppp}\n\t\\end{center}\n\\end{figure}\n\n\\subsubsection{OptKnock and its derivatives}\n\\textcite{burgard_optknock_2003-1} phrased the OptKnock optimization problem first as a bi-level mixed-integer linear optimization problem. The inner problem is standard FBA, maximizing an objective function $\\myvector{c}_\\textsf{in}^\\top \\myvector{v}$. This encodes the assumption that each knockout strain we consider for the outer problem, evolves to maximize the objective (which is typically set to be the biomass function). Then, we choose the one knockout that maximizes the outer objective $\\myvector{c}_\\textsf{out}^\\top \\myvector{v}$ -- typically the secretion rate of the desired product (e.g. succinate).\n\\begin{eqnarray}\n\\textsf{\\textbf{OptKnock}} && \\nonumber\\\\\n\\max_{\\myvector{y}}~~\\myvector{c}_{\\textsf{out}}^\\top \\myvector{v}&&\\nonumber\\\\\n\\textsf{subject to}&&\\nonumber\\\\\n&\\max_{\\myvector{v}}~\\myvector{c}_{\\textsf{in}}^\\top \\myvector{v}&\\nonumber\\\\\n&\\textsf{subject to}&\\nonumber\\\\\n&&\\stoichmatint \\myvector{v} = \\myvector{0} \\nonumber\\\\\n&&v_{\\textsf{LB},\\,j} \\cdot y_j \\leq v_j \\leq y_j \\cdot v_{\\textsf{UB},\\,j} \\nonumber\\\\\n&\\myvector{y} \\in \\{0, 1\\}^r \\nonumber\\\\\n&\\sum_j{(1-y_j)} \\leq K & \\label{eq:optknock}\n\\end{eqnarray}\nwhere, $K$ is the maximum number of allowed knockouts. The inner LP is a standard FBA optimization problem, except that a few of the reactions are ``knockout out'' -- when a reaction indicator is set to 0 by the external LP it forces the corresponding flux to zero, i.e. $y_j = 0 \\rightarrow v_j = 0$. In addition, we set $v_{\\textsf{LB},\\,biomass} > 0$ and $y_{biomass} = 1$, since we only want to consider mutants that show at least some minimal growth. Finally, the external LP places an upper bound on the total number of knockouts, which is useful for two reasons: (1) making sure we don't have too many knockouts that would make the genetic manipulation impractical, and (2) to reduce the computational load required to solve the MILP. Nevertheless, even for small $K$, solving the bi-level MILP  directly is not tractable for large networks (such as the genome-scale \\textit{E. coli} model). Fortunately, \\textcite{burgard_optknock_2003-1} provided a solution, by converting into a single-level MILP using duality theory.\n\nThe dual of the inner optimization problem in \\ref{eq:optknock} is:\n\\begin{eqnarray}\n\\min_{\\myvector{\\lambda},\\myvector{\\mu},\\myvector{\\omega}} ~\\sum_j y_j (v_{\\textsf{UB},\\,j} \\cdot \\mu_j - v_{\\textsf{LB},\\,j} \\cdot \\omega_j)&\\nonumber\\\\\n\\textsf{subject to}&\\nonumber\\\\\n&\\stoichmatint^\\top \\myvector{\\lambda} + \\myvector{\\mu} - \\myvector{\\omega} \\geq \\myvector{c}_\\textsf{in} \\nonumber\\\\\n&\\myvector{\\mu}, \\myvector{\\omega} \\geq 0\\,.\n\\end{eqnarray}\nSince duality theory states if the optimums solutions of the primal and dual problems are bounded, their objective function values must be equal to one another, so ensuring optimality can be achieved by equating the two objectives: $\\myvector{c}_\\textsf{in}^\\top \\myvector{v} = \\sum_j y_j (v_{\\textsf{UB},\\,j} \\cdot \\mu_j - v_{\\textsf{LB},\\,j} \\cdot \\omega_j)$. However, using this equation as a constraint in the outer optimization problem would make it non-linear, since it contains products of two variables ($y_j \\cdot \\mu_j$ and $y_j \\cdot \\omega_j$). We can, however, use the fact that $y_j$ are binary in order to cast this expression into a linear form.\n\nFirst, we introduce a new set of auxiliary variables $\\myvector{m} \\in \\mathbb{R}^r$, and constrain them to be $m_j = y_j \\cdot \\mu_j$ by adding the following:\n\\begin{eqnarray}\n\t0 \\leq &m_j& \\leq y_j \\cdot M \\nonumber\\\\\n\t\\mu_j - (1 - y_j) \\cdot M \\leq &m_j& \\leq \\mu_j\\,.\n\\end{eqnarray}\nAs before, $M$ is a constant larger than any possible value of $\\mu_j$. Considering the two cases for $y_j$, one can easily see that $y_j = 0 ~\\rightarrow~ m_j = 0$ and $y_j = 1 ~\\rightarrow~ m_j = \\mu_j$, which is what we wanted to achieve. We do exactly the same for $\\myvector{\\omega}$ and another set of variables $\\myvector{u} \\in \\mathbb{R}^r$. Then we can rewrite the dual objective as: $\\sum_j y_j (v_{\\textsf{UB},\\,j} \\mu_j - v_{\\textsf{LB},\\,j} \\omega_j) = \\myvector{v}_\\textsf{UB}^\\top \\myvector{m} - \\myvector{v}_\\textsf{LB}^\\top\\myvector{u}$.\n\nUsing this notion, we get a single-level MILP problem for OptKnock:\n\\begin{eqnarray}\\label{eq:optknock2}\n\\textsf{\\textbf{OptKnock}} & \\nonumber\\\\\n\\max_{\\myvector{y},\\myvector{v},\\myvector{\\lambda},\\myvector{\\mu},\\myvector{\\omega},\\myvector{m},\\myvector{u}}~~\\myvector{c}_\\textsf{out}^\\top \\myvector{v}&\\nonumber\\\\\n\\textsf{subject to}&\\nonumber\\\\\n&\\stoichmatint \\myvector{v} = \\myvector{0} \\nonumber\\\\\n&v_{\\textsf{LB},\\,j} \\cdot y_j \\leq v_j \\leq y_j \\cdot v_{\\textsf{UB},\\,j} \\nonumber\\\\\n&\\myvector{c}_\\textsf{in}^\\top \\myvector{v} = \\myvector{v}_\\textsf{UB}^\\top \\myvector{m} - \\myvector{v}_\\textsf{LB}^\\top\\myvector{u} \\nonumber\\\\\n&\\myvector{c}_\\textsf{in} \\leq \\stoichmatint^\\top \\myvector{\\lambda} + \\myvector{\\mu} - \\myvector{\\omega} \\nonumber\\\\\n&0 \\leq \\myvector{\\mu}, \\myvector{\\omega} \\nonumber\\\\\n&0 \\leq \\myvector{m} \\leq \\myvector{y} \\cdot M \\nonumber\\\\\n&\\myvector{\\mu} - (1 - \\myvector{y}) \\cdot M \\leq \\myvector{m} \\leq \\myvector{\\mu} \\nonumber\\\\\n&0 \\leq \\myvector{u} \\leq \\myvector{y} \\cdot M \\nonumber\\\\\n&\\myvector{\\omega} - (1 - \\myvector{y}) \\cdot M \\leq \\myvector{u} \\leq \\myvector{\\omega} \\nonumber\\\\\n&\\sum_j{(1-y_j)} \\leq K  \n\\end{eqnarray}\n\n\\subsubsection{Derivatives of OptKnock}\n\nA comprehensive review by \\textcite{machado_co-evolution_2015} lists the many published algorithms for \\textit{in silico} strain design that followed after OptKnock (see Figure \\ref{fig:optknock_derivatives}).\n\\begin{figure}[ht!]\\label{fig:optknock_derivatives}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.75\\textwidth]{optknock_derivatives.png}\n\t\\end{center}\n\t\\caption{A timeline of all constraint-based strain design methods that followed OptKnock (figure is from \\cite{machado_co-evolution_2015}).}\n\\end{figure}\n\nRobust\\-Knock is an improvement for Opt\\-Knock, introduced by \\textcite{tepper_predicting_2010-1} in 2010, which accounts for competing pathways that might reduce the chemical production rates. One common issue with standard Opt\\-Knock, is that it only looks at the maximal rate of the chemical production rate: $\\max \\myvector{c}_\\textsf{out}^\\top \\myvector{v}$. However, as visualized by the production envelope in Figure \\ref{fig:ppp}a, there might be redundancy in the solution space, where the same biomass rate can be achieved without any production of the desired chemical. Robust\\-Knock addresses this problem by performing a max-min optimization, i.e. maximizing the lowest value of $\\myvector{c}_\\textsf{out}^\\top \\myvector{v}$ over all $\\myvector{v}$ that satisfy the inner LP. This method yields solutions like in Figure \\ref{fig:ppp}b-c.\n\n\\printbibliography\n\n\\end{document}\n\n", "meta": {"hexsha": "8c86b78e6d0773709dc31e9f5160e1164e66737a", "size": 32413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "blackboard_elad.tex", "max_stars_repo_name": "eladnoor/sysbio2018", "max_stars_repo_head_hexsha": "5f15e573a4bab5c9beac81ed30f608f2baf37013", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "blackboard_elad.tex", "max_issues_repo_name": "eladnoor/sysbio2018", "max_issues_repo_head_hexsha": "5f15e573a4bab5c9beac81ed30f608f2baf37013", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "blackboard_elad.tex", "max_forks_repo_name": "eladnoor/sysbio2018", "max_forks_repo_head_hexsha": "5f15e573a4bab5c9beac81ed30f608f2baf37013", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 95.3323529412, "max_line_length": 1028, "alphanum_fraction": 0.7506247493, "num_tokens": 9469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.7059115166583206}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS622: Theory of Formal Languages\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 1}\n\nLet $A = \\{a,b\\}$.\nConstruct the minimal deterministic finite automaton that is able to accept the language $aA^*b$.\n\n\\subsection*{Solution}\n\nBased on Hopcraft's Algorithm \\cite{hopcroft1971n}, we start by $Q_0 = L = \\{aA^*b\\}$ and apply symbols $\\{a,b\\}\\in A$ to go to $a^{-1}L$ and $b^{-1}L$ respectively.\nWe take advantage of the following property of prefixes.\n\n\\begin{equation}\\label{eq1}\na^{-1}LK = (a^{-1}L)K \\cup (L \\cap \\{\\lambda\\})a^{-1}K\n\\end{equation}\n\nLet $L$ and $K$ be defined as $aA^*$ and $b$, respectively.\nUsing Eq. \\ref{eq1}, we'll have\n\n\\begin{equation}\\label{eq2}\n\\begin{aligned}\na^{-1}aA^*b &= (a^{-1}aA^*)b \\cup (aA^* \\cap \\{\\lambda\\})a^{-1}b\\\\\n&= A^*b \\cup \\emptyset \\emptyset\\\\\n&= A^*b\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\\label{eq3}\n\\begin{aligned}\nb^{-1}aA^*b &= (b^{-1}aA^*)b \\cup (aA^* \\cap \\{\\lambda\\})b^{-1}b\\\\\n&= \\emptyset \\cup \\emptyset \\lambda\\\\\n&= \\emptyset\n\\end{aligned}\n\\end{equation}\n\nTherefore, $Q_1 = \\{aA^*b, A^*b, \\emptyset\\}$.\nIn a similar fashion,\n\n\\begin{equation}\n\\begin{aligned}\na^{-1}A^*b &= (a^{-1}A^*)b \\cup (A^* \\cap \\{\\lambda\\})a^{-1}b\\\\\n&= A^*b\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\nb^{-1}A^*b &= (b^{-1}A^*)b \\cup (A^* \\cap \\{\\lambda\\})b^{-1}b\\\\\n&= A^*b \\cup \\{\\lambda\\}\n\\end{aligned}\n\\end{equation}\n\nand evidently, $a^{-1}\\emptyset = b^{-1}\\emptyset = \\emptyset$.\nTherefore, $Q_2 = Q_1 \\cup \\{A^*b \\cup \\{\\lambda\\}\\}$.\n\n\\begin{equation}\n\\begin{aligned}\na^{-1}(A^*b\\cup\\{\\lambda \\}) &= a^{-1}A^*b \\cup a^{-1}\\lambda\\\\\n&= A^*b\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\nb^{-1}(A^*b\\cup\\{\\lambda \\}) &= b^{-1}A^*b \\cup b^{-1}\\lambda\\\\\n&= A^*b \\cup \\{\\lambda \\}\n\\end{aligned}\n\\end{equation}\n\nThus, $Q_3 = Q_2 = Q_L = \\{aA^*b, \\emptyset, A^*b, A^*b\\cup\\{\\lambda \\} \\}$.\n$Q_L$ would be set of states of the machine $\\mathcal{M}_L$ that can recognize the language $aA^*b$.\nThe automaton $\\mathcal{M}_L$ is defined by Table \\ref{tab1}.\nAlso, Figure \\ref{fig1} depicts graph of $\\mathcal{M}_L$ where $q_0$, $q_1$, $q_2$ and $q_3$ represent $\\emptyset$, $aA^*b$, $A^*b$ and $A^*b\\cup\\{\\lambda \\}$, respectively.\n\n\\begin{table}\\centering\n\t\\begin{tabular}[H!]{|c||c|c|c|c|}\n\t\t\\hline\n\t\tInput & $aA^*b$ & $A^*b$ & $\\emptyset$ & $A^*\\cup \\{\\lambda \\}$\\\\\n\t\t\\hline\n\t\ta & $A^*b$ & $A^*b$& $\\emptyset$& $A^*b$\\\\\n\t\tb & $\\emptyset$ & $A^*b\\cup \\{\\lambda \\}$& $\\emptyset$ & $A^*b \\cup \\{\\lambda \\}$\\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{Directed graph of the automaton $\\mathcal{M}_L$}\\label{tab1}\n\\end{table}\n\n\\begin{figure}\\centering\n\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,semithick]\n\t\t\\tikzstyle{final}=[circle,thick,draw=black,fill=gray!40,text=black]\n\t\t\\node[state,initial]\t(1) \t\t\t\t\t{$q_1$};\n\t\t\\node[state]\t\t\t(0) [left of = 1]\t\t{$q_0$};\n\t\t\\node[state]\t\t\t(2) [right of = 1]\t\t{$q_2$};\n\t\t\\node[state, final]\t\t(3) [right of = 2]\t\t{$q_3$};\n\t\t\\path\n\t\t\t(0) edge [loop left]\tnode {a,b}\t (0)\n\t\t\t(1) edge [bend left]\tnode {b}\t (0)\n\t\t\t\tedge [bend left]\tnode {a}\t (2)\n\t\t\t(2) edge [bend left]\tnode {b}\t (3)\n\t\t\t\tedge [loop above]\tnode {a}\t (2)\n\t\t\t(3) edge [loop right]\tnode {b}\t (3)\n\t\t\t\tedge [bend left]\tnode {a}\t (2);\n\t\\end{tikzpicture}\n\t\\caption{Directed graph of the automaton $\\mathcal{M}_L$}\\label{fig1}\n\\end{figure}\n", "meta": {"hexsha": "da4fc4e68648639e3184a32ac44552b0b2041a29", "size": 3615, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs622-2015f/src/tex/hw03/hw03q01.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs622-2015f/src/tex/hw03/hw03q01.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs622-2015f/src/tex/hw03/hw03q01.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 32.8636363636, "max_line_length": 173, "alphanum_fraction": 0.5825726141, "num_tokens": 1505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732855, "lm_q2_score": 0.8633916064587, "lm_q1q2_score": 0.7058869557512537}}
{"text": "\\documentclass[twocolumn]{article}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{outlines}\n\\usepackage{amsmath}\n\\usepackage{gensymb}\n\\title{Ch. 22 Notes}\n\\author{John Yang}\n\\setcounter{section}{+20}\n\n\\begin{document}\n\\maketitle\n\\section{Sinusoidal AC Circuit Analysis}\n\\subsection{Representations of a complex variable}\n\\begin{outline}\n\\1 Rectangular, Polar, Exponential \\[z=x+iy=r\\angle\\theta=re^{i\\theta}\\] where \\[x=r\\cos\\theta\\]\\[y=r\\sin\\theta\\]\\[\\tan\\theta=\\dfrac{\\text{Im}}{\\text{Re}}=\\dfrac{y}{x}\\]\\[z=r\\angle\\theta=r\\cos\\theta+ir\\sin\\theta=re^{i\\theta}\\]\n\n\\end{outline}\n\\subsection{Arithmetic Operations with Complex Variables}\n\\begin{outline}\n\\1 Adding and subtracting: Add real and add imaginary separately\n\\1 Multiplication: \\[z_1z_2=r_1r_2e^{i(\\theta_1+\\theta_2)}\\]\\[z_1z_2=(r_1\\angle\\theta_1)(r_2\\angle\\theta_2)=r_1r_2\\angle(\\theta_1+\\theta_2)\\]\\[z_1z_2=(x_1+iy_1)(x_2+iy_2)\\]\\[=(x_1x_2-y_1y_2)+i(x_1y_2+x_2y_1)\\]\n\\1 Division: \\[\\dfrac{z_1}{z_2}=\\dfrac{r_1e^{i\\theta_1}}{r_2e^{i\\theta_2}}=\\dfrac{r_1}{r_2}\\angle(\\theta_1-\\theta_2)\\]\\[\\dfrac{z_1}{z_2}=\\dfrac{r_1\\angle\\theta_1}{r_2\\angle\\theta_2}=\\dfrac{r_1}{r_2}\\angle(\\theta_1-\\theta_2)\\]\n\\1 Complex conjugates: \\[z=x+iy\\]\\[z^*=x-iy\\]\n\\end{outline}\n\\subsection{Complex potential differences and currents: Phasors} \n\\begin{outline}\n\\1 Sinusoidally oscillating potential differences and currents: \\[V(t)=V_0\\cos(\\omega t+\\theta)\\]\\[I(t)=I_0\\cos(\\omega t+\\phi)\\]\n\\end{outline}\n\\subsection{The Potential difference and current Phasors for resistors, Inductors, and Capacitors}\n\\begin{outline}\n\\1 Resistor: \\[V=IR\\]\\[V(t)=RI(t)\\]\n\\1 Inductor: \\[V=L\\dfrac{dI}{dt}\\]\n\\1 Capacitor: \\[C=\\dfrac{Q}{V}\\]\\[I=C\\dfrac{dV}{dt}\\]\n\\1 Impedances: \\[V=IZ\\]\n    \\2 Resistor: \\[Z_R=R\\]\n    \\2 Inductor: \\[Z_L=i\\omega L\\]\n    \\2 Capacitor: \\[Z_C=\\dfrac{1}{i\\omega C}\\]\n\\1 Impedance is measured in Ohms. Impedances for capacitors and inductors are imaginary numbers. Impedance is not a phasor. \n\\end{outline}\n\\subsection{Series and parallel combinations of impedances}\n\\begin{outline}\n\\1 Impedances in series combine like resistors in series\n\\1 Impedances in parallel combine like resistors in parallel\n\\end{outline}\n\\subsection{Complex independent AC voltage sources}\n\\begin{outline}\n\\1 Complex voltage sources: \\[V_{\\text{source}}(t)=V_0\\cos(\\omega t)+iV_0\\sin(\\omega t)\\]\\[V_{\\text{source}}(t)=V_0e^{i(\\omega t)}\\]\\[V_{\\text{source}}(t)=V_0\\angle(\\omega t)\\]\n\\end{outline}\n\\subsection{Power absorbed by circuit elements in AC Circuits}\n\\begin{outline}\n\\1 Average power absorbed by a circuit element: \\[\\langle P\\rangle=\\dfrac{1}{2}V_0I_0\\cos\\beta\\]where\\[\\beta=\\theta-\\phi\\]\n\\1 $\\cos\\beta$ is the power factor. \n\\1 Peak values divided by $\\sqrt 2$ are known as effective values of potential difference and current, also known as rms values. \\[V_{\\text{rms}}=\\dfrac{V_0}{\\sqrt 2}\\]\\[I_{\\text{rms}}=\\dfrac{I_0}{\\sqrt 2}\\]\\[\\langle P\\rangle=V_{\\text{rms}}I_{\\text{rms}}\\cos\\beta\\]\n\\1 Multimeters read rms values and not peak values\n\\1 For resistors, $\\cos\\beta=1$\n\\1 For capacitors, the average power is 0 because \\(\\beta=-\\dfrac{\\pi}{2}\\)\n\\1 For inductors, the average power is 0 because \\(\\beta=\\dfrac{\\pi}{2}\\)\n\\end{outline}\n\\subsection{A Filter circuit}\n\\begin{outline}\n\\1 Filter circuits let certain frequencies pass relatively unimpeded and filter out or eliminate one or another range of frequencies. \n\\end{outline}\n\\subsection{A Series RLC Circuit}\n\\begin{outline}\n\\1 For fixed $L$ and $C$, the numerical value of the resistance affects the shape of the graph of $\\langle P\\rangle$ vs. $\\omega$. The smaller the resistance $R$, the more sharply peaked the curve. \n\\end{outline}\n\n\n\\end{document}", "meta": {"hexsha": "e4a3ea725f997feaa801b3f94672ae7d4e2fb38d", "size": 3643, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch 22/ch 22 notes.tex", "max_stars_repo_name": "CookiePie1/PhysicsC", "max_stars_repo_head_hexsha": "80d1d884f2ef2560f2c30345acf6c10cc326b4cb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ch 22/ch 22 notes.tex", "max_issues_repo_name": "CookiePie1/PhysicsC", "max_issues_repo_head_hexsha": "80d1d884f2ef2560f2c30345acf6c10cc326b4cb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch 22/ch 22 notes.tex", "max_forks_repo_name": "CookiePie1/PhysicsC", "max_forks_repo_head_hexsha": "80d1d884f2ef2560f2c30345acf6c10cc326b4cb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.7971014493, "max_line_length": 265, "alphanum_fraction": 0.7227559704, "num_tokens": 1316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7058869490219808}}
{"text": "\\documentclass{stdlocal}\n\\begin{document}\n\\section{Mathematical Proofs} % (fold)\n\\label{sec:proofs}\n  \\begin{lemma*}[Monte Carlo Integration Estimates Value of Integral]\n    Choose the same setting as in the above definition \\ref{definition:monte-carlo-integration}.\n    In this case for all $n\\in\\setNatural$, the Monte Carlo integration $\\mathrm{MCI}_n(f)$ is a Monte Carlo method and the following statements for the expectation value and standard deviation are fulfilled.\n    \\[\n      \\expect \\mathrm{MCI}_n(f) = \\integral{U}{}{f}{λ}\n      \\separate\n      \\stddev\\boxBrackets{\\mathrm{MCI}_n(f)} \\leq \\sqrt{\\frac{λ(U)}{n} \\integral{U}{}{f^2}{λ}}\n    \\]\n  \\end{lemma*}\n  \\begin{proof}[Lemma \\ref{lemma:monte-carlo-integration} on page \\pageref{lemma:monte-carlo-integration}]\n    Let $p$ be the probability density of $X_n$.\n    Because the random variables are uniformly distributed on $U$, we can express it as follows.\n    \\[\n      \\function{p}{U}{[0,\\infty)}\n      \\separate\n      p(x) \\define \\frac{1}{λ(U)}\n    \\]\n    By using substitution and chaining from propositions \\ref{proposition:substitution} and \\ref{proposition:chaining}, the expectation value can be directly computed.\n    \\[\n      \\begin{aligned}[t]\n        \\expect \\mathrm{MCI}_n(f)\n        &= \\expect \\boxBrackets{ \\frac{λ(U)}{n} \\sum_{k=1}^n f\\circ X_k }\n        = \\frac{λ(U)}{n} \\sum_{k=1}^n \\expect(f\\circ X_k) \\\\\n        &= λ(U) \\integral{U}{}{f(x) p(x)}{λ(x)}\n        = \\integral{U}{}{f}{λ}\n      \\end{aligned}\n    \\]\n    For the standard deviation, first the variance will be observed.\n    Since the sequence of random variables is stochastically independent, the sum can be taken out of the argument.\n    Afterwards, we again apply substitution and chaining.\n    \\[\n      \\begin{aligned}\n        \\var \\mathrm{MCI}_n(f) &= \\var\\boxBrackets{ \\frac{λ(U)}{n} \\sum_{k=1}^n f\\circ X_k } = \\frac{λ(U)^2}{n^2} \\sum_{k=1}^n \\var\\roundBrackets{f\\circ X_k} \\\\\n        &= \\frac{λ(U)^2}{n^2} \\sum_{k=1}^n \\expect\\roundBrackets{f\\circ X_k}^2 - \\boxBrackets{\\expect\\roundBrackets{f\\circ X_k}}^2 \\\\\n        &\\leq \\frac{λ(U)^2}{n^2} \\sum_{k=1}^n \\expect\\roundBrackets{f\\circ X_k}^2 = \\frac{λ(U)^2}{n} \\integral{U}{}{f^2(x) p(x)}{λ(x)} \\\\\n        &= \\frac{λ(U)}{n} \\integral{U}{}{f^2}{λ}\n      \\end{aligned}\n    \\]\n    The inequality is now inferred by the definition of the standard deviation which proofs the lemma.\n    \\[\n      \\stddev\\boxBrackets{\\mathrm{MCI}_n(f)} = \\sqrt{\\var \\mathrm{MCI}_n(f)} \\leq \\sqrt{\\frac{λ(U)}{n} \\integral{U}{}{f^2}{λ}}\n    \\]\n  \\end{proof}\n\n  \\begin{lemma*}[Pseudorandom Sequences are Ultimately Periodic]\n    Let $\\mathscr{G}\\define (S,T,U,G)$ be a PRNG and $s_0\\in S$ its initial state.\n    Then the respective pseudorandom sequence $(u_n)_{n\\in\\setNatural}$ is ultimately periodic.\n    In this case, for the period ρ and the transient τ the following holds.\n    \\[\n      1 \\leq ρ + τ - 1 \\leq \\# S\n    \\]\n    In particular, if $T$ is bijective $(u_n)$ will be periodic.\n  \\end{lemma*}\n  \\begin{proof}[Lemma~\\ref{lemma:pseudorandom-sequences-periodicity} on page \\pageref{lemma:pseudorandom-sequences-periodicity}]\n    Let $(s_n)_{n\\in\\setNatural}$ be the respective sequence of states and $N\\define \\# S$ the number of different states.\n    $T$ maps all elements of $S$ to at most $N$ other elements of $S$.\n    Therefore at least the element $s_N$ has to be mapped to an element $s_k$ for $k\\in\\setNatural$ with $k\\leq N$ which was already reached.\n    % Hence, there exist $n,k\\in\\setNatural$ with $k\\leq n\\leq N$ such that $T(s_n) = s_k$.\n    Hence, we conclude the following.\n    \\[\n      \\exists n,k\\in\\setNatural, k\\leq n\\leq N: \\quad T(s_n) = s_k\n    \\]\n    % Assume $T$ maps $s_n$ to a state $s_k$ with $k\\in\\setNatural$ and $k < n$.\n    We choose $n$ and $k$ appropriately and define the following values.\n    \\[\n      ρ \\define n - k + 1\n      \\separate\n      τ \\define k\n    \\]\n    Now let $i\\in\\setNatural_0$ be arbitrary and apply the definition.\n    We get the following chain of equations which show that $(u_n)$ is ultimately periodic.\n    \\[\n      \\begin{aligned}\n        u_{τ+i+ρ} &= u_{n+1+i} = G \\circ T^{n+1+i}(s_0) = G \\circ T^i\\circ T^{n+1}(s_0) \\\\\n        &= G \\circ T^i(s_k) = G \\circ T^i \\circ T^k(s_0) = G \\circ T^{i+k}(s_0) = u_{k+i} = u_{τ+i}\n      \\end{aligned}\n    \\]\n    The inequality can be shown by directly inserting the values into the definition.\n    \\[\n      1 \\leq ρ + τ - 1 = n \\leq N = \\# S\n    \\]\n    This proofs the given lemma.\n  \\end{proof}\n\n  \\begin{lemma*}[Equidistributed Pseudorandom Sequences]\n    Let $\\mathscr{G}\\define (S,T,U,G)$ be a PRNG with $s_0\\in S$ as its seed value and $(u_n)_{n\\in\\setNatural}$ the respective pseudorandom sequence with transient τ and period ρ.\n    Furthermore, let μ be a probability measure on $(U,\\mathscr{P}(U))$.\n    Then the following statements are equivalent.\n    \\begin{enumerate}[label=(\\roman*)]\n      \\item $(u_n)$ is equidistributed with respect to μ.\n      \\item For all $u\\in U$ the following is true.\n        \\[\n          \\frac{1}{ρ} \\cdot \\#\\set{n\\in\\setNatural}{τ\\leq n < ρ+τ, u_n = u} = μ(\\set{u}{})\n        \\]\n    \\end{enumerate}\n  \\end{lemma*}\n  \\begin{proof}[Lemma~\\ref{lemma:equidistribution} on page \\pageref{lemma:equidistribution}]\n    Because $U$ is a finite set, every measurable function $\\function{X}{U}{\\setReal}$ can be described as a linear combination of characteristic functions with respect to some real coefficients $α_u$ for all $u \\in U$ in the following way.\n    \\[\n      X = \\sum_{u\\in U} α_u \\mathds{1}_{\\set{u}{}}\n    \\]\n    Hence, without loss of generality, it suffices to take only characteristic functions into account.\n    Let $u\\in U$ be arbitrary.\n    The right-hand side of the definition will then result in the following.\n    \\[\n      \\integral{U}{}{\\mathds{1}_{\\set{u}{}}}{μ} = μ(\\set{u}{})\n    \\]\n    Applying the characteristic function together with the properties of a periodic sequence to the left-hand side of the definition, looks as follows.\n    \\[\n      \\begin{aligned}\n        \\lim_{n\\to\\infty} \\frac{1}{n} \\sum_{k=1}^n \\mathds{1}_{\\set{u}{}}(u_k)\n        &= \\lim_{n\\to\\infty} \\frac{1}{n} \\sum_{k=1}^{τ-1} \\mathds{1}_{\\set{u}{}}(u_k) + \\lim_{n\\to\\infty} \\frac{1}{n}\\sum_{k=τ}^{τ+n-1} \\mathds{1}_{\\set{u}{}}(u_k) \\\\\n        &= \\frac{1}{ρ} \\sum_{k=τ}^{τ+ρ-1} \\mathds{1}_{\\set{u}{}}(u_k) \\\\\n        &= \\frac{1}{ρ} \\cdot \\#\\set{n\\in\\setNatural}{τ\\leq n < ρ+τ, u_n = u}\n      \\end{aligned}\n    \\]\n    This shows the desired equivalence and proofs the lemma.\n  \\end{proof}\n\n  \\begin{lemma*}[Corresponding Vector Sequences are Ultimately Periodic]\n    Let $U$ be a non-empty set of values and $(u_n)_{n\\in\\setNatural}$ be an ultimately periodic sequence in $U$ with period ρ and transient τ.\n    In this case, every corresponding $k$-dimensional vector sequence $(v_n)_{n\\in\\setNatural}$ with translation $t$ is ultimately periodic with period $ρ'$ and transient $τ'$ defined as follows.\n    \\[\n      ρ' \\define \\frac{ρ}{\\mathrm{gcd}(ρ,k)}\n      \\separate\n      τ' \\define \\ceilBrackets{\\frac{\\max(0,τ-1-t)}{k}} + 1\n    \\]\n  \\end{lemma*}\n  \\begin{proof}[Lemma \\ref{lemma:vector-sequences-periodicity} on page \\pageref{lemma:vector-sequences-periodicity}]\n    Choose $n\\in\\setNatural_0$ and $i\\in\\setNatural$ with $i\\leq k$ to be arbitrary.\n    We denote with $v^{(i)}_n$ the $i$.~coordinate of the $n$.~vector.\n    By definition the following equality holds.\n    \\[\n      v^{(i)}_{τ' + n + ρ'} = u_{t + (τ'+n+ρ'-1)k + i}\n    \\]\n    Observing the index, we separate it into three parts.\n    One for the index, one for the transient one for the period.\n    \\[\n      t+(τ' + n + ρ' - 1)k + i = \\underbrace{(t + τ'k - k + 1)}_{\\reverseDefine \\tilde{τ}} + \\underbrace{(nk + i - 1)}_{\\reverseDefine \\tilde{n}}  + \\underbrace{ρ'k}_{\\reverseDefine \\tilde{ρ}}\n    \\]\n    The period part has to be a multiple of the period ρ of $(u_n)$ as can be seen in the following.\n    Hence, $\\tilde{ρ}$ has the property of a period.\n    \\[\n      \\tilde{ρ} = ρ'k = \\frac{ρk}{\\mathrm{gcd}(ρ,k)} = ρ \\frac{k}{\\mathrm{gcd}(ρ,k)}\n    \\]\n    To apply the periodicity of $(u_n)$, the transient part has to be bigger or equal to the transient τ of $(u_n)$.\n    \\[\n      \\tilde{τ} = t + τ'k - k + 1 = 1 + t + k \\ceilBrackets{\\frac{\\max(0,τ-1-t)}{k}} \\geq τ\n    \\]\n    Inserting the results and applying the periodicity of $(u_n)$, we can conclude that the corresponding vector sequence has to be ultimately periodic as well.\n    \\[\n      v^{(i)}_{τ' + n + ρ'} = u_{\\tilde{τ} + \\tilde{n} + \\tilde{ρ}} = u_{\\tilde{τ} + \\tilde{n}} = u_{t + (τ' + n - 1)k + i} = v^{(i)}_{τ' + n}\n    \\]\n    Due to the shown statements, $ρ'$ and $τ'$ are indeed the smallest possible values such that this equation holds and can therefore be denoted as period and transient of $(v_n)$ respectively.\n  \\end{proof}\n% section proofs (end)\n\\end{document}", "meta": {"hexsha": "d385f0f0e44ef617feb48bf864eb4849fc47d8d3", "size": 8835, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/thesis/sections/proofs.tex", "max_stars_repo_name": "lyrahgames/random-number-generators", "max_stars_repo_head_hexsha": "c78931c1a5c0a85a1ad36d7d8979567b0853be52", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-03-28T15:12:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-20T00:07:23.000Z", "max_issues_repo_path": "docs/thesis/sections/proofs.tex", "max_issues_repo_name": "lyrahgames/random-number-generators", "max_issues_repo_head_hexsha": "c78931c1a5c0a85a1ad36d7d8979567b0853be52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/thesis/sections/proofs.tex", "max_forks_repo_name": "lyrahgames/random-number-generators", "max_forks_repo_head_hexsha": "c78931c1a5c0a85a1ad36d7d8979567b0853be52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.8757763975, "max_line_length": 240, "alphanum_fraction": 0.6303338993, "num_tokens": 3001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7058869375266196}}
{"text": "\n\n%%%%%%%%%%%%%%%% arm kinematics %%%%%%%%%%%%%%\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.7\\columnwidth]{chapters/img/robot_arm.png}\n    \\caption{Placeholder image for the robotic arm?.}\n    \\label{fig:robotic_manipulator_general}\n\\end{figure}\n\n\n\\section*{Manipulator Kinematics} %Niklas\nKinematics is what describes the motion of rigid bodies and points in space. \n\n\\subsection*{Backgroud}\n\\subsection*{Rigid body transformation}\nIn general any position can be described by translation along three axes and rotation along these same axes. These translations/rotations can be described by a matrix\n\\begin{equation}\n    T = \n    \\begin{bmatrix}\n        R & d \\\\\n        \\bf{0} & 1\n    \\end{bmatrix}\n\\end{equation}\nwhere \\(R\\) is a 3 x 3 rotation matrix and \\(d\\) a 3 x 1 translation matrix. This implies that any transformation could be characterized by six parameters, three for the translation and three for the rotation. \\cite{spong}\n\n\n\\subsection*{Denavit-Hartenberg Convention}\nA common approach for selecting the coordinate frames of reference for each joint in a robotic arm is the Denavit-Hartenberg convention. This allows the transformation matrix for each joint to be expressed as\n\\begin{equation}\n    A_i = Rot_{z}(\\theta_i) \\cdot Trans_{z}(d_i) \\cdot Trans_{x}(a_i) \\cdot Rot_{z}(\\alpha_i)\n    \\label{eqn:DH-transformation}\n\\end{equation}\nthat consists of the four basic transformations\n\\begin{equation}\n    Rot_z(\\theta_i) = \n    \\begin{bmatrix}\n        cos(\\theta_i) & -sin(\\theta_i) & 0 & 0 \\\\\n        sin(\\theta_i) & cos(\\theta_i) & 0 & 0 \\\\\n        0 & 0 & 1 & 0 \\\\\n        0 & 0 & 0 & 1\n    \\end{bmatrix}\n\\end{equation}\n\\begin{equation}\n    Trans_z(d_i) = \n    \\begin{bmatrix}\n        1 & 0 & 0 & 0 \\\\\n        0 & 1 & 0 & 0 \\\\\n        0 & 0 & 1 & d_i \\\\\n        0 & 0 & 0 & 1\n    \\end{bmatrix}\n\\end{equation}\n\\begin{equation}\n    Trans_x(\\alpha_i) = \n    \\begin{bmatrix}\n        1 & 0 & 0 & \\alpha_i \\\\\n        0 & 1 & 0 & 0 \\\\\n        0 & 0 & 1 & 0 \\\\\n        0 & 0 & 0 & 1\n    \\end{bmatrix}\n\\end{equation}\n\\begin{equation}\n    Rot_z(\\theta_i) = \n    \\begin{bmatrix}\n        1 & 0 & 0 & 0 \\\\\n        0 & cos(\\alpha_i) & -sin(\\alpha_i) & 0 \\\\\n        0 & sin(\\alpha_i) & cos(\\alpha_i) & 0 \\\\\n        0 & 0 & 0 & 1\n    \\end{bmatrix}.\n\\end{equation}\n\n\nWhere the parameters \\(\\theta_i\\), \\(a_i\\), \\(d_i\\) and \\(\\alpha_i\\), known as DH-parameters, characterize each joint. To allow the transformation for each joint to be represented by only four parameters, compared to the six parameters that is required in general, there are some restrictions on how the coordinate frames can be chosen. To comply with the DH-convention, the following must be satisfied.\n\\begin{itemize}\n    \\item The axis \\(x_{1}\\) is perpendicular to the axis \\(z_0\\)\n    \\item The axis \\(x_{1}\\) intersects the axis \\(z_0\\)\n\\end{itemize}\nwhere it is assumed that two frames are given, frame 0 and frame 1, and the transformation from equation \\ref{eqn:DH-transformation} transforms a coordinate from frame 1 into a coordinate in frame 0.\\cite{spong}\n\n\n\n\\subsection*{Kinematic Chain} %A1*A2*...\nA robotic manipulator can be described by a set of joints with links between them where a homogeneous transformation matrix \\(A_i\\) that describes the transformation with respect to the previous joint exists for each joint. This means that a transformation that describes the position and orientation of joint \\(j\\) with respect to a joint \\(i\\) to a can be found by a transformation matrix \\cite{spong}\n\\begin{equation}\n    \\begin{cases}\n        T_j^i = A_{i+1}A_{i+2}...A_{j-1}A_{j}, \\text{  if \\(i < j\\) } \\\\\n        T_j^i = I, \\text{  if \\(i = j\\) } \\\\\n        T_j^i = (T_i^j)^{-1}, \\text{  if \\(i > j\\) }\n    \\end{cases}\n    \\label{eqn:Kinematic_chain_spong}\n\\end{equation}\n\n\n\n\\subsection*{Forward Kinematics}\nForward kinematics is the problem of finding the position and orientation of the end effector.\n\nSince a manipulator can be seen as a kinematic chain the problem of finding the position and orientation of the end effector can be solved by finding the transformation matrices in equation \\ref{eqn:Kinematic_chain_spong}.\n\n\n\n\\subsection*{Inverse Kinematics}\nThe problem of finding the joint states required for achieving a desired pose is called inverse kinematics. For some simple kinematic chains an analytical solution exists, but in general a numerical approach might be required. \n\n%we have for joints, three needed for position. geometric approach for finding the position. then joint for is used to control the pitch of the EOF\n\n\n\n\n\n\\subsection*{Workspace}\nA robotic manipulator will not be able to reach all points in space since it has a fixed size. It will not even be able to reach all mathematically reachable points since each joint (usually) have some restrictions on how it can rotate/translate. The physically reachable space is defined as the workspace of the manipulator. %source might be needed here\n\\\\\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%% Kinematics Implementation %%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Implementation}\n\n\\subsection*{Denavit-Hartenberg Convention}\nIn table \\ref{tab:DH-table} the DH-parameters that was used for the robotic manipulator, seen in figure \\ref{fig:robotic_manipulator_general}, are listed.\n\\begin{table}[H]\n    \\centering\n    \\caption{The Denavit-Hartenberg parameters used for the robotic manipulator.}\n    \\begin{tabular}{c | c c c c c}\n        \\(i\\) & \\(\\theta_i\\) [rad] & \\(d_i\\) [mm] & \\(a_i\\) [mm] & \\(\\alpha_i\\) [rad] \\\\\n        \\hline\n        \\(1\\) & \\(\\theta_1\\) & \\(75\\) & \\(0\\) & \\(\\pi / 2\\) \\\\\n        \\(2\\) & \\(\\theta_2\\) & \\(0\\) & \\(67.5\\) & \\(0\\) \\\\\n        \\(3\\) & \\(\\theta_3\\) & \\(0\\) & \\(67.5\\) & \\(0\\) \\\\\n        \\(4\\) & \\(\\theta_4\\) & \\(0\\) & \\(65\\) & \\(0\\) \\\\\n    \\end{tabular}\n    \\label{tab:DH-table}\n\\end{table}\n\n\n\n\\subsection*{Forward Kinematics}\nThe transformation matrices from equation \\ref{eqn:DH-transformation} for each joint can be multiplied together\n\\begin{equation}\n    T_{end} = A_1 \\cdot A_2 \\cdot A_3 \\cdot A_4\n\\end{equation}\nwhere \\(A_1\\) - \\(A_4\\) are calculated from equation \\ref{eqn:DH-transformation} to find the pose \\(T_{end}\\) of the end effector and thereby solving the forward kinematic problem.\n\n\n\\subsection*{Inverse Kinematics}\nTo solve the inverse kinematics for the position of a three joint manipulator a geometric method can be used to find an analytical solution. The required angles to achieve a desired position \\((x_d, y_d, z_d)\\) in an elbow-up configuration are \\cite{Lec14_mit_Manipulation}\n\n\\begin{equation}\n    \\begin{cases}\n        \\theta_1 = Atan(x, y) \\\\\n        \\theta_3 = Atan(D, +\\sqrt{1 - D^2}) \\\\\n        \\theta_2 = Atan(\\sqrt{x_d^2 + y_d^2}, z_d - d_1) \\\\- Atan(a_2 + a_3 \\cdot D, a_3 \\cdot \\sqrt{1 - D^2}) %fix\n    \\end{cases}\n\\end{equation}\nwhere \\(Atan(x, y)\\) is the two argument arctangent function \\cite{inverse_tangent_wolfram} and \n\n\\begin{equation}\n    D = \\frac{x_d^2 + y_d^2 + (z_d - d_1)^2 - a_2^2 - a_3^2}{2 a_2 a_3}\n\\end{equation}\nand \\(a_2\\), \\(a_3\\), and \\(d_1\\)   are the corresponding DH-parameters.\n\n\n\n\\subsection*{Workspace}\nThe robotic manipulator seen in figure \\ref{fig:robotic_manipulator_general} has the following limitations for the first three joints\n\\begin{equation}\n    \\begin{cases}\n        -100^\\circ < \\theta_1 < 100^\\circ \\\\\n        -14^\\circ < \\theta_2 < -194^\\circ \\\\\n        -104^\\circ < \\theta_3 < 104^\\circ \n    \\end{cases}\n    \\label{eqn:workspace_limits_angles}\n\\end{equation}\ndue to limitations on how much each joint can rotate and limitations such as cables and safety concerns. A simulated 2D slice of the workspace can be seen in figure \\ref{fig:workspace_simulated}. The full workspace can be formed by rotating this 2D slice around the z-axis according to the limitations on \\(\\theta_1\\) from equation \\ref{eqn:workspace_limits_angles}.\n\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.7\\columnwidth]{chapters/img/workspace.eps}\n    \\caption{A simulated 2D slice of the workspace for the three jointed manipulator.}\n    \\label{fig:workspace_simulated}\n\\end{figure}\n%chapters/img/workspace.eps\n\n\n\n\n%%%%%%%%%%%%%%%% arm kinematics end %%%%%%%%%%%%%%\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\section*{Base}\n\nThe motors will be connected to tracks on the robot and can therefore be modelled as two wheels connected with a rod, as seen in figure \\ref{fig:base_math_model}.\\\\ \nDeriving a mathematical model is straight forward if we can read the encoders from the motors. From the encoders we would be able to get both the length the robot has traveled and more importantly the individual speed each motor rotates with. The speed for the individual motor is given by: \n\n\\begin{equation}\n    v_m=\\frac{2\\pi r_{wh}/N_{enc}}{\\Delta t}\n    \\label{eq:base_system_eq1}\n\\end{equation}\n\n\\noindent Where $N_{enc}$ is the number of encoders on the motor, $r_{wh}$ is the radius of the driving wheel and thickness of the track and $\\Delta t$ is the time between the previous encoder reading and the most recent one. By doing this for both the left and right motor we can find how fast the robot is moving along the line by:\n\n\\begin{equation}\n    \\overline{v}= \\frac{v_L+v_R}{2}(-\\cos \\theta \\hat{i}+ \\sin \\theta \\Hat{j})\n\\end{equation}\n\n\\noindent Where the $y$-axis parallel to the line. In a similar fashion the angular velocity can be calculated using:\n\n\\begin{equation}\n    \\Dot{\\theta} = \\frac{v_R-v_L}{2r_{b}}\n    \\label{eq:base_system_eq2}\n\\end{equation}\n\n\\noindent Where $r_{b}$ is the distance from the center of the base to the wheels. From this and figure \\ref{fig:base_math_model} it's easy to see that the change of angle then becomes:\n\n\\begin{equation}\n    \\theta = sin^{-1}\\left(\\frac{V_L-V_R}{2r_{b}}t\\right)\n\\end{equation}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.7\\columnwidth]{chapters/img/base_math_model.eps}\n    \\caption{Modelling of the base as two wheels connected with a rod, where $\\theta$ is the angle to the line}\n    \\label{fig:base_math_model}\n\\end{figure}\n%base_math_model.eps\n\nGiven the use of small-angles approximation\\footnote{Which will be assumed since the robot will be operating on a grid with hard coded functions for turning at QR-codes}, the angular velocity can be written as:\n\n\\begin{equation}\n    \\theta = \\frac{V_L-V_R}{2r_{b}}t\n\\end{equation}\n\n\n\\noindent Using equations \\eqref{eq:base_system_eq1}-\\eqref{eq:base_system_eq2} a system can be built for simulations in matlab, using rate of change and max/min value limiters for simulations of the motors physical restrictions.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\\section*{Camera vision and calibration}\nIn this section it is outlined the theory behind the camera vision system. \nHow points in a 3D-space are projected on a 2D-plane, calibration and distortion correction. \n\\subsection*{Camera model}\n\\subsection*{Distortion}\n", "meta": {"hexsha": "2ce6b251dae0e1e2651b17e82f2f4558456b2996", "size": 10911, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/finished/chapters/modeling.tex", "max_stars_repo_name": "kottz/D7039E", "max_stars_repo_head_hexsha": "d86848a037a07e97122c92e3c80c980c58c41d52", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/finished/chapters/modeling.tex", "max_issues_repo_name": "kottz/D7039E", "max_issues_repo_head_hexsha": "d86848a037a07e97122c92e3c80c980c58c41d52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 72, "max_issues_repo_issues_event_min_datetime": "2020-09-15T13:32:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-01T08:06:16.000Z", "max_forks_repo_path": "report/finished/chapters/modeling.tex", "max_forks_repo_name": "kottz/D7039E", "max_forks_repo_head_hexsha": "d86848a037a07e97122c92e3c80c980c58c41d52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-16T16:06:15.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-16T16:06:15.000Z", "avg_line_length": 41.8045977011, "max_line_length": 403, "alphanum_fraction": 0.6838053341, "num_tokens": 3091, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391599428538, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7058869365716285}}
{"text": "\\section{Introduction}\nA \\textbf{cryptosystem} consists of a family of \\textit{enciphering transformations} $f$, each corresponding to a choice of parameters $p$, from a set $P$ of all possible plaintext message units to a set $C$ of all possible ciphertext message units. The transformation requires:\n\\begin{itemize}\n\t\\item An algorithm, which is the same for the whole family and supposedly publicly known;\n\t\\item An enciphering key $K_E$, the value of parameters $p$;\n\t\\item A deciphering key $K_D$.\n\\end{itemize}\nThe deciphering key is needed in order to compute $f^{-1}$, i.e.\\ decipher the message. The transformation uses the same algorithm as encrypting, except with a different key. \n\nA \\textbf{public key} or \\textbf{asymmetric cryptosystem}, by definition, has the property that someone who knows only to encipher cannot use the encipher key to find the deciphering key without a prohibitively lengthy computation: the function $f : P \\rightarrow C$ is easy to compute once $K_E$ is known, but it is very hard in practice to compute the inverse function $f^{-1} : C \\rightarrow P$.\n\nIn mathematical terms, the inverse computation should be \\textbf{infeasible}, namely so computationally intensive that it is impossible to evaluate it in any reasonable time period. \n\nThis implies that $f$ is not invertible without some additional information, therefore $f$ is an \\textit{one-way function}. Most public key algorithms are in fact based on number-theoretic functions, whose goal is usually not to have a compact mathematical description between input and output.\n\nA public key cryptosystem, therefore, involves not only one key but a pair: one is public and can be publicly shared, and the other is private and its discover by a third part would compromise the security of the system.\n\nThe main point of this scheme is that it is not necessary that the key possessed by the person who encrypts the message is secret. Receivers can only decrypt using their secret key.\n\nInformation needed to send secret messages, therefore, can be made public without anyone being able to read the content. This makes communication possible within two parts which have never interacted before, an useful feature among modern systems with huge workloads. \n\n\\subsection{Cyclic groups and generators}\n\\textbf{Cyclic groups} are a way to generalize public key algorithms within groups not necessarily constrained by a prime number. They have a key role in cryptography, since they allow many useful one-way functions which can be used to encrypt information: in fact, cryptographic functions which are hard to break should be defined within finite groups.\n\nA \\textbf{group} is a set of elements $G$ together with an operation $\\circ$ which combines two elements of $G$. A group has the following properties:\n\\begin{enumerate}\n\t\\item The group operation $\\circ$ is \\textit{closed}: for all $a, b \\in G$, it holds that $a \\circ b = c \\in G$;\n\t\\item The group operation is \\textit{associative}: $a \\circ (b \\circ c) = (a \\circ b) \\circ c$ for all $a, b, c \\in G$;\n\t\\item There is an element $1 \\in G$ called the \\textit{neutral element} (identity) such that $a \\circ 1 = 1 \\circ a = a$ for all $a \\in G$;\n\t\\item For each $a \\in G$ there exists an element $a^{-1}$ called the \\textit{inverse}, such that $a \\circ a^{-1} = a^{-1} \\circ a = 1$;\n\t\\item A group $G$ is \\textit{abelian} (or \\textit{commutative}) if, furthermore, $a \\circ b = b \\circ a$ for all $a, b \\in G$.\n\\end{enumerate}\nCryptography majorly relies on \\textit{multiplicative groups}, where the operation $\\circ$ denotes multiplication.\n\nAlgorithms related to discrete logarithm problem, for example, concern the group $\\mathbb{Z}^*_n$, consisting in the set of all integers $i = 0, 1, \\dots, n - 1$ for which $\\gcd(i, n) = 1$. $\\mathbb{Z}^*_n$ forms an abelian group under multiplication modulo $n$, where the identity element is $e = 1$.\n\nSince cryptography concerns finite structures, groups also have to respect the property to have a finite number of elements, defining the \\textit{cardinality} or \\textit{order} of the group $G$ by $|G|$. \n\nEvery element of a group $G$ has also an order, which is the smallest positive integer $k$ such that:\n$$a^k = a \\circ a \\circ \\dots \\circ a = 1$$\nThe $\\circ$ operation is applied $k$ times, obtaining the identity element of $G$.\n\nExample: the order of the element $a = 3$ in the group $\\mathbb{Z}^*_{11}$ is 5, since $a^5 = 1 \\mod 11$. \n\nThe powers of $a$ run through the same finite sequence of remainders indefinitely, adopting a cyclic behavior. This allows to introduce cyclic groups.\n\nA group $G$ which contains an element $\\alpha$ with maximum order $|G|$ is said to be \\textbf{cyclic}. Elements with maximum order are called primitive or \\textbf{generators}, since every element $a$ of $G$ can be written as a power $\\alpha^i = a$ of this element for some $i$, so that $\\alpha$ generates the entire group.\n\nFor every prime $p$, $(\\mathbb{Z}^*_p, \\cdot)$ is an abelian finite cyclic group.\n\nHaving a finite cyclic group $G$, some interesting properties hold:\n\\begin{enumerate}\n\t\\item For every $a \\in G$, it holds that:\n\t\\begin{enumerate}\n\t\t\\item $a^{|G|} = 1$;\n\t\t\\item The order of $a$ divides $|G|$;\n\t\\end{enumerate}\n\t\\item The number of primitive elements of $G$ is $\\phi(G)$, where $\\phi$ defines the Euler function (number of positive integers up to $G$ which are coprime to it);\n\t\\item if $|G|$ is prime, then all elements $a \\neq 1$ are primitive.\n\\end{enumerate}\nThose concepts have relevancy in cryptography: prime fields are widely used for building discrete logarithm cryptosystems, using the fact that in a cyclic group \\textit{only element orders which divide the group cardinality} exist. \n\n\\subsubsection{Subgroups}\n\\textbf{Subgroups} are subsets of cyclic groups which are groups themselves, therefore respect all the previously stated properties. \n\nLet $(G, \\circ)$ be a cyclic group. Then, every element $a \\in G$ with $ord(a) = s$ is the primitive element of a cyclic subgroup with $s$ elements.\n\nAs previously stated, the generator can be non-unique. An important special case are subgroups of prime order: with cardinality $q$, all elements $e \\neq 1$ have order $q$ as well.\n\nIf $H$ is a subgroup of $G$, then $|H|$ divides $|G|$. \n\nTo obtain a construction method for subgroups from a given finite cyclic group, only the cardinality $n$ and a primitive element are needed: then, $\\alpha^{n/k}$ is computed to obtain a generator $\\alpha$ of the subgroups with $k$ elements.\n\nThis follows knowing that every integer $k$ which divides the cardinality $n$ there exists exactly one cyclic subgroup $H$ of $G$ of order $k$, consisting in the elements $a \\in G$ satisfying $a^k = 1$. \n\n\n", "meta": {"hexsha": "ab1b33d2f909db2ff35439aca51118c660959b2e", "size": 6706, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Seminar - Algebraic Methods and Algorithms in Cryptology  /chapters/introduction.tex", "max_stars_repo_name": "mrahtapot/TUM", "max_stars_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 225, "max_stars_repo_stars_event_min_datetime": "2019-10-02T10:49:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T22:25:38.000Z", "max_issues_repo_path": "Seminar - Algebraic Methods and Algorithms in Cryptology  /chapters/introduction.tex", "max_issues_repo_name": "mrahtapot/TUM", "max_issues_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-02-16T12:22:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-31T19:35:57.000Z", "max_forks_repo_path": "Seminar - Algebraic Methods and Algorithms in Cryptology  /chapters/introduction.tex", "max_forks_repo_name": "mrahtapot/TUM", "max_forks_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 69, "max_forks_repo_forks_event_min_datetime": "2019-10-02T21:46:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T19:27:50.000Z", "avg_line_length": 87.0909090909, "max_line_length": 398, "alphanum_fraction": 0.7467939159, "num_tokens": 1743, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.7057846557487817}}
{"text": "\n\\subsection{Unary operators}\n\nA unary operator takes one input and returns another.\n\nOnly negation, \\(\\neg \\) is of interest.\n\nThe following statements are equivalent:\n\n\\begin{itemize}\n\\item \\(T\\)\n\\item \\(\\neg F\\)\n\\end{itemize}\n\n\n", "meta": {"hexsha": "762212301e5bdba622f433f8520137ea74606b37", "size": 231, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogic/02-01-unary.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/propositionalLogic/02-01-unary.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/propositionalLogic/02-01-unary.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.4375, "max_line_length": 53, "alphanum_fraction": 0.7142857143, "num_tokens": 62, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.798186787341014, "lm_q1q2_score": 0.7056284741801239}}
{"text": "\\chapter{Applications Beyond Analysis and Resynthesis}\n\n\n\n\\subsection{Discussion of the Stop Function}\\label{section:audioEffects:stopFunction}\nIn this section, the stop function of the detection stage is revisted.\n\n    \\subsubsection{Residual Power Threshold}\n    Perhaps the most striaghtforward stop function is checking power of the residual signal, $x_r$. Given a threshold $t$:\n    \\begin{align}\\label{eq:audioEffects:stopFunction:powerThreshold}\n        s(y, t) =\n            \\begin{cases}\n                0, & \\text{if } t \\geq \\sum_{N = 0}^{N-1} y[n]^2 \\\\\n                1, & \\text{otherwise}\n            \\end{cases}\n    \\end{align}\n    When the periodicity transform is performed short-time on a signal, that is, in frames, it is typically best to set $t$ equal to some fractional amount of the input vector $x$ so as to allow the threshold for frame $i$, $t_i$, to be dynamic:\n    \\begin{align*}\n        t_i = t \\sum_{N = 0}^{N-1} x[n]^2\n    \\end{align*}\n    where $0 \\leq t < 1$. There are of course many variations of the above thresholding formulation in Equation \\eqref{eq:audioEffects:stopFunction:powerThreshold} such as $||x||_p$.\n\n    If one uses the simple threshold stop function, it is important to recognize that it is possible to continue finding periodic data in a residual that carries no meaningful information as to the ``essence'' of the input signal (refer to the paragraph beginning this section). Although these ``phantom'' periodicities may help the convex program to better minimize the reconstruction error, they often add no value and can often distort the useful periodicities already detected.\n\n        As an example, let $x$ be the combination of three sinusoids with periods 17, 21, and 50, plus zero-mean Gaussian noise with a SNR of -18 dB:\n        \\begin{figure}[h]\n            \\centering\n            % \\includegraphics[width=0.75\\textwidth]{PATH/TO/MY/FIG}\n            \\caption{[A signal $x$ that is the sum of three equal-amplitude sinusoids with $p = \\{17, 21, 50\\}$ plus zero-mean Gaussain noise.]A signal $x$ that is the sum of three equal-amplitude sinusoids with $p = \\{17, 21, 50\\}$ plus zero-mean Gaussain noise.}\n            \\label{fig:audioEffects:stopFunction:residual:sinesPlusNoise}\n        \\end{figure}\n        where $N$ is the length of the signal and is equal to 1000, and $G(n)$ is the Gaussian noise at sample $n$. What periods are found at various values of $t$? Below is the output of the convex program using the projection in Equation \\eqref{eq:intro:sethares} and different values of $t$. We also set $t$ directly to simplify:\n        \\begin{figure}[h]\n            \\centering\n            % \\includegraphics[width=0.75\\textwidth]{PATH/TO/MY/FIG}\n            \\caption[A figure showing the effect of different threshold values for the stop function.\\index{Values of $t$}]{Results of period detection using various values of $t$. \\emph{Top Panel:} $t = 0.2$. Note that not enough data is captured and only two periods are found. \\emph{Middle Panel:} $t = 0.1$ Since $t$ is exactly equal to the SNR of the signal, we find that the three periods we expect are found before the algorithm terminates. \\emph{Bottom Panel:} $t = 0.05$ Although we find the three periods we expect, the algorithm also finds periods in the residual noise. This has the further effect of distorting the already detected periodic waveforms as one will see in Section \\ref{ch3:recoveringWaveforms}}\n            \\label{fig:audioEffects:stopFunction:thresholdEffect}\n        \\end{figure}\n        Notice that in the bottom panel, $t$ is set too low and we therefore see many periods which, while they do ``exist'', do not necessarly add information but are rather imparted by the projection process and numerical happenstance.\n\n        In a close-to-ideal world (one in which we admit noise), one would simply set $t$ to be the level of the noise floor in the signal. In this way, one would only capture the periodic components while leaving the noise (relatively) untouched. This, of course, is not possible in real data and is especially prone to error when non-integer periods are present. See Section \\ref{ch3:nonintegerPeriods} for a longer discussion.\n\n\n    \\subsubsection{Sum of the Power of the Periodic Components}\n    A novel way to approch the problem and one that keeps in mind the qualitative criteria of ``listenability'' is to check whether or not the sum of the powers of the detected periodic waveforms exceeds the power of the original signal. For convenience, we define the power to be $E(x) \\equiv \\sum_{n = 0}^{N - 1} |x[n]|^2$:\n    \\begin{align}\n        s(x, X_Q) = \\begin{cases}\n            0, & \\text{if } E(x) \\leq \\sum_{x_q \\in X_Q} E(x_q) \\\\\n            1, & \\text{otherwise}\n        \\end{cases}\n    \\end{align}\n    where $X_Q$ is the set of projections of the best periods acquired through projection of $x_r$ onto $P_p$. Note that these projections are also of length $N$. This often results in a less-than-perfect reconstruction from a residual minimization standpoint but in practice has shown better listenability of the components themselves.\n\n    \\subsubsection{Decrease in the Total Power of Periodic Components}\n    An interesting phenomenon was observed in processing real data, often data that contains noise and/or non-integer periodicities whereby the sums of the derived periodic components \\emph{decreases} as more iterations are performed.\n\n    \\subsubsection{Lack of Significant Periods}\n    If the input to the ML estimator is $x = \\mathcal{N}(0, \\sigma^2)$, the resulting powers of the periods, normalized as Equation \\eqref{eq:intro:sethares:periodicNormGamma}, we see that there are no significant peaks in the periodogram:\n    \\begin{figure}[h]\n        \\centering\n        % \\includegraphics[width=0.75\\textwidth]{PATH/TO/MY/FIG}\n        \\caption[Periodogram of zero-mean Gaussian noise for $2 \\leq p \\leq 500$ for $N = 1000$]\n        {Periodogram of zero-mean Gaussian noise for $2 \\leq p \\leq 500$ for $N = 1000$. Notice the conspicuous lack of significant periods for the ML estimator to choose from.}\n        \\label{fig:audioEffects:gaussianPeriodogram}\n    \\end{figure}\n\n    We can measure this by defining the ``flatness'' of the periodogram to be:\n    \\begin{align} \\label{eq:audioEffects:flatness}\n        P_{\\text{flatness}}(P) &= \\frac\n            {\n                % e^{\\big( \\frac{1}{N} \\sum_{n=0}^{N-1} \\ln P[n] \\big)}\n                \\sqrt[N]{\\Pi_{n=0}^{N-1} P_n}\n                % \\big( \\Pi_{n=0}^{N-1} P_n \\big)^{\\frac{1}{N}}\n            }\n            {\n                \\frac{1}{N} \\sum_{n=0}^{N-1} P_n\n            }\n    \\end{align}\n    where $N$ is the number of periods we search for (i.e. $N = P_{max} - P_{min}$) and $t$ is again a threshold, all typically converted to decibels. Notice that this is identical to the spectral flatness measure that is common in measuring the Fourier Transform of a discrete time signal. It proves useful in this regard as well, as a simple but effective measure of determining whether or not there remain any more significant periods in the data.\n\n    Suppose $x = S_1 + \\mathcal{N}(0, \\sigma^2)$ and $||S_1||_2 \\ll ||\\mathcal{N}(0, \\sigma^2)||_2$. The resulting periodogram will be very similar to that of pure zero-mean Gaussain noise yet we know there is a periodic signal in $x$. What ought to be the interpretation in this case? In practice, it was found that in this case, the periodic signal $S_1$ is so insignificant so as to have no meaningful value as to the constitution of $x$. In other words, in such a case nothing of value is lost by disregarding $S_1$ given its overall weakness in the signal.\n\n\n\\subsection{Time Stretching}\n\n\\subsection{Monaural Source Separation}\n", "meta": {"hexsha": "93677a1021ae3f78584f93118f5884b340a50a62", "size": 7716, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/audioEffects/audioEffects.tex", "max_stars_repo_name": "woolgathering/ucsdDissertation", "max_stars_repo_head_hexsha": "a0a08d98f6cf0962c7518de6e79ce2750eb2a751", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/audioEffects/audioEffects.tex", "max_issues_repo_name": "woolgathering/ucsdDissertation", "max_issues_repo_head_hexsha": "a0a08d98f6cf0962c7518de6e79ce2750eb2a751", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/audioEffects/audioEffects.tex", "max_forks_repo_name": "woolgathering/ucsdDissertation", "max_forks_repo_head_hexsha": "a0a08d98f6cf0962c7518de6e79ce2750eb2a751", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 88.6896551724, "max_line_length": 721, "alphanum_fraction": 0.7052877138, "num_tokens": 2020, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7056284586929521}}
{"text": "\\chapter{Unit 4}\n\\section{First Fundamental Theorem of Calculus}\nLet $f$ be a function defined $\\forall x\\in[a,b]$. Let $F$ be the antiderivative\nof $f$ on $[a,b]$. It can be said that:\n\\begin{equation}\n  \\int_{a}^{b} f(x) dx = F(b) - F(a)\n\\end{equation}\n\n\\subsection{The Mean Value Theorem}\nIf $f$ is continuous on the closed interval $[a,b]$, then there exists a number\n$x=c$ such that:\n\\begin{equation}\n  \\int_{a}^{b} f(x)dx = f(c)(b-a)\n\\end{equation}\n\n\\section{Second Fundamental Theorem of Calculus}\n\\begin{equation}\n  \\frac{d}{dx}\\left[\\int_a^x f(t) dt\\right]=f(x)\n\\end{equation}\n\n\\begin{equation}\n  \\frac{d}{dx}\\left[ \\int_a^{u(x)} f(t) dt\\right] = f(u(x))\\frac{du}{dx}\n\\end{equation}\n\n\\section{Sigma Limit Process}\nLet $c_i = a+i(\\Delta{x})$, and $\\Delta{x}=\\frac{b-a}{n}$.\n\n\\begin{equation}\n  \\int_a^b f(x) dx = \\lim_{\\Delta x\\to 0} \\sum_{i=1}^{n}f(c_i)\\Delta{x_i}\n\\end{equation}\n\n\\section{Logarithmic \\& Exponential Functions}\n\\begin{equation}\n  \\int \\frac{du}{u} = \\ln|u| + C\n\\end{equation}\n\n\\begin{equation}\n  \\int e^u dx = du * e^u + C\n\\end{equation}\n\n\\section{Differential Equations}\n\\begin{equation}\n  y=Ce^{kt}\n\\end{equation}\n\n\\section{Inverse Trigonometric Functions}\n\\begin{align}\n  \\int \\frac{1}{a^2+u^2} du = \\frac{1}{a}\\arctan{\\frac{u}{a}} + C \\\\\n  \\int \\frac{1}{\\sqrt{a^2-u^2}} du = \\arcsin{\\frac{u}{a}} + C &&\n  \\int \\frac{1}{u\\sqrt{u^2-a^2}} du = \\frac{1}{a}\\arcsec{\\frac{|u|}{a}} + C\n\\end{align}\n", "meta": {"hexsha": "ad24822309bf37b77953b6d011c8d63722c638da", "size": 1421, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016/bc_calculus/units/unit_4.tex", "max_stars_repo_name": "ttaylorr/midterms", "max_stars_repo_head_hexsha": "fdde0fd1a66eb5242d0dfa04a5201c3ab6d6b7eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-01-06T06:55:26.000Z", "max_stars_repo_stars_event_max_datetime": "2015-01-06T06:55:26.000Z", "max_issues_repo_path": "2016/bc_calculus/units/unit_4.tex", "max_issues_repo_name": "ttaylorr/midterms", "max_issues_repo_head_hexsha": "fdde0fd1a66eb5242d0dfa04a5201c3ab6d6b7eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2016/bc_calculus/units/unit_4.tex", "max_forks_repo_name": "ttaylorr/midterms", "max_forks_repo_head_hexsha": "fdde0fd1a66eb5242d0dfa04a5201c3ab6d6b7eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.3269230769, "max_line_length": 80, "alphanum_fraction": 0.6354679803, "num_tokens": 574, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.705620993200981}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Power Series and Convergence}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises relating to power series and their convergence properties.\n\\end{abstract}\n\\maketitle\n\n\\begin{exercise}\nCompute the radius of convergence of the power series below.\n\\[ \\sum_{n = 1}^\\infty \\frac{(x-3)^n}{2^n + 1} \\]\n\\[ R = \\answer{2} \\]\n\\begin{hint}\nWhen computing a limit like\n\\[ \\lim_{n \\rightarrow \\infty} \\frac{2^{n} + 1}{2^{n+1} + 1}, \\]\nremember the effect of orders of growth: $1 <\\!\\!< 2^n$, and so from the perspective of the limit, the $+1$'s in both the numerator and denominator are both negligible.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nCompute the radius of convergence of the power series below.\n\\[ \\sum_{n = 1}^\\infty \\frac{(-3)^n (\\ln n) (x-3)^n}{4^n} \\]\n\\[ R = \\answer{\\frac{4}{3}} \\]\n\\begin{hint}\nWhen computing a limit like\n\\[ \\lim_{n \\rightarrow \\infty} (\\ln n)^{1/n}, \\]\nremember that we already know $n^{1/n} \\rightarrow 1$ and that $\\ln n <\\!\\!<n$ as well, so we expect $(\\ln n)^{1/n} \\rightarrow 1$ as well.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nCompute the radius of convergence of the power series below.\n\\[ \\sum_{n = 1}^\\infty \\frac{(-2)^n n! (x-3)^n}{3^n+n^2} \\]\n\\[ R = \\answer{0} \\]\n\\end{exercise}\n\n\\begin{exercise}\nCompute the interval of convergence for the power series below.\n\\[ \\sum_{n=1}^\\infty \\frac{(-2)^n (x-3)^n}{\\ln n} \\]\nThe left endpoint of the interval is $\\answer{5/2}$; it \\wordChoice{\\choice{is}\\choice[correct]{is not}} included in the interval of convergence.\nThe right endpoint of the interval is $\\answer{7/2}$; it is \\wordChoice{\\choice[correct]{is}\\choice{is not}} included in the interval of convergence.\n\\end{exercise}\n\n\\begin{exercise}\nReindex the series below:\n\\[ \\sum_{n=1}^\\infty \\frac{x^{2n+1}}{n + 2} = \\sum_{n = 0} \\frac{x^{\\answer{2n+3}}}{\\answer{n+3}} \\]\n\\end{exercise}\n\n\\begin{exercise}\nDifferentiate the series below term-by-term:\n\\[ \\frac{d}{dx} \\sum_{n=0}^\\infty \\frac{n}{n+1} x^n = \\sum_{n=1} \\answer{\\frac{n^2}{n+1}} x^{\\answer{n-1}}. \\]\n(Note that the $n=0$ term goes away because the derivative of a constant is zero.)\n\\end{exercise}\n\n\\begin{exercise}\nIntegrate the series below term-by-term:\n\\[ \\int_0^x \\left[ \\sum_{n=0}^\\infty \\frac{x^n}{(2n+3)^2} \\right]  = \\sum_{n=0} \\answer{\\frac{1}{(n+1)(2n+3)^2}} x^{\\answer{n+1}}. \\]\n\\end{exercise}\n\n\\begin{exercise}\nFor each step below, apply a term-by-term operation, a multiplication by a monomial, or a substitution to derive a new series formula from a known formula.\n\\begin{itemize}\n\\item Use the formula \\[ \\frac{1}{1-x} = \\sum_{n=0}^\\infty x^n \\]\nto derive a summation formula for $1/(1+x^2)$, i.e.,\n\\[ \\frac{1}{1+x^2} = \\sum_{n=0}^\\infty \\answer{(-1)^n} x^{\\answer{2n}}. \\]\n\\item Use the formula you derived above to develop a power series expansion for arctangent:\n\\[ \\arctan x = \\sum_{n=0}^\\infty \\answer{\\frac{(-1)^n}{(2n+1)}} x^{\\answer{2n+1}}. \\]\n\\item The radius of convergence of this last series is $R = \\answer{1}$.\n\\end{itemize}\n\\end{exercise}\n\n\\begin{exercise}\nFor each step below, apply a term-by-term operation, a multiplication by a monomial, or a substitution to derive a new series formula from a known formula.\n\\begin{itemize}\n\\item Use the formula \\[ \\frac{1}{1-x}   = \\sum_{n=0}^\\infty x^n \\] to determine the sum of the series below for $-1 < x < 1$:\n\\[ \\sum_{n = 0}^\\infty \\frac{x^{n+1}}{n+1} = \\answer{- \\ln |1-x|}. \\]\n(Don't forget absolute values if you need them.)\n\\item Use the formula you just derived to determine the sum of the series\n\\[ \\sum_{n=0}^\\infty \\frac{x^{2n+3}}{n+1} = \\answer{- x \\ln |1-x^2|.} \\]\n\\item Use the formula you just derived to determine the sum of the series\n\\[ \\sum_{n=0}^\\infty \\frac{2^{2n} x^{2n+3}}{n+1} = \\answer{- \\frac{1}{4} x \\ln |1-4x^2|.} \\]\n\\end{itemize}\n\\end{exercise}\n\n\n\\section*{Sample Quiz Questions}\n\\begin{question}%%%%%[PowerSerInterval001]\n\nFind the full interval of convergence for the power series \\[\\sum_{m=2}^{\\infty} \\frac{(-3)^mm^2(x - 5)^m }{\\ln m}.\\]\n(Hints will not be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice[correct]{\\(\\displaystyle \\left(\\frac{14}{3},\\frac{16}{3}\\right)\\)}\n\\choice{\\(\\displaystyle \\left[\\frac{14}{3},\\frac{16}{3}\\right)\\)}\n\\choice{\\(\\displaystyle \\left(2,8\\right]\\)}\n\\choice{\\(\\displaystyle \\left[2,8\\right]\\)}\n\\choice{\\(\\displaystyle \\left(-\\infty,\\infty\\right)\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nFirst observe that \n\\[\\begin{aligned}\n\\frac{1}{R} & = \\lim_{m\\rightarrow \\infty} \\left| \\frac{\\frac{(-3)^{(m+1)}{(m+1)}^2 }{\\ln {(m+1)}} }{\\frac{(-3)^mm^2 }{\\ln m}} \\right| \\\\\n& = \\lim_{m\\rightarrow \\infty} \\left| \\frac{-3{(m+1)}^2\\ln m }{m^2\\ln {(m+1)} } \\right| \\\\\n& = 3\n\\end{aligned}\\]\nbecause \\[\\lim_{m \\rightarrow \\infty} \\frac{(m+1)^2 \\ln m}{m^2 \\ln (m+1)} = \\lim_{m \\rightarrow \\infty} \\frac{(m+1)^2}{m^2} \\lim_{m \\rightarrow \\infty} \\frac{\\ln m}{\\ln (m+1)} = 1\\] by virtue of l'Hospital's rule applied to both limits on the right-hand side.\n\\begin{hint}\nThis means that the radius equals \\(1/3\\). At the endpoint \\(x=14/3\\), the series equals \\[\\sum_{m=2}^{\\infty} \\frac{m^2 }{\\ln m },\\] which diverges by the \\(n\\)-th term divergence test because \\(\\lim_{m \\rightarrow \\infty} m^{2} / \\ln m = \\infty \\neq 0\\). At the endpoint \\(x=16/3\\), the series equals \\[\\sum_{m=2}^{\\infty} (-1)^m\\frac{m^2 }{\\ln m },\\] which diverges for the same reason as the other endpoint, i.e., the terms do not go to zero.\n\\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[PowerSerInterval003]\n\nFind the full interval of convergence for the power series \\[\\sum_{m=2}^{\\infty} \\frac{(-4)^m(\\ln m)(x - 1)^m }{(-2)^mm}.\\]\n(Hints will not be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\left(\\frac{1}{2},\\frac{3}{2}\\right)\\)}\n\\choice[correct]{\\(\\displaystyle \\left[\\frac{1}{2},\\frac{3}{2}\\right)\\)}\n\\choice{\\(\\displaystyle \\left(-1,3\\right]\\)}\n\\choice{\\(\\displaystyle \\left[-1,3\\right]\\)}\n\\choice{\\(\\displaystyle \\left(-\\infty,\\infty\\right)\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nFirst observe that \n\\[\\begin{aligned}\n\\frac{1}{R} & = \\lim_{m\\rightarrow \\infty} \\left| \\frac{\\frac{(-4)^{(m+1)}(\\ln {(m+1)}) }{(-2)^{(m+1)}{(m+1)}} }{\\frac{(-4)^m(\\ln m) }{(-2)^mm}} \\right| \\\\\n& = \\lim_{m\\rightarrow \\infty} \\left| \\frac{-4(\\ln {(m+1)})m }{-2(\\ln m){(m+1)} } \\right| \\\\\n& = 2\n\\end{aligned}\\]\nbecause \\[\\lim_{m \\rightarrow \\infty} \\frac{m\\ln (m+1)}{(m+1) \\ln m} = \\lim_{m \\rightarrow \\infty} \\frac{m}{m+1} \\lim_{m \\rightarrow \\infty} \\frac{\\ln (m+1)}{\\ln m} = 1\\] by virtue of l'Hospital's rule applied to both limits on the right-hand side. \\begin{hint}\nThis means that the radius equals \\(1/2\\). At the endpoint \\(x=3/2\\), the series equals \\[\\sum_{m=2}^{\\infty} \\frac{(\\ln m) }{m },\\] which diverges by direct comparison to the harmonic series, i.e., the \\(p\\)-series with \\(p = 1\\). At the endpoint \\(x=1/2\\), the series equals \\[\\sum_{m=2}^{\\infty} (-1)^m\\frac{(\\ln m) }{m },\\] which converges by the alternating series test because the sign of the terms alternates and \\(\\ln m / m\\) decreases to zero as \\(m \\rightarrow \\infty\\). \\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[PowerSerInterval004]\n\nFind the full interval of convergence for the power series \\[\\sum_{m=2}^{\\infty} \\frac{(-2)^m(\\ln m)(x + 4)^m }{6^mm}.\\]\n(Hints will not be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\left(-\\frac{13}{3},-\\frac{11}{3}\\right)\\)}\n\\choice{\\(\\displaystyle \\left[-\\frac{13}{3},-\\frac{11}{3}\\right)\\)}\n\\choice[correct]{\\(\\displaystyle \\left(-7,-1\\right]\\)}\n\\choice{\\(\\displaystyle \\left[-7,-1\\right]\\)}\n\\choice{\\(\\displaystyle \\left(-\\infty,\\infty\\right)\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nFirst observe that \n\\[\\begin{aligned}\n\\frac{1}{R} & = \\lim_{m\\rightarrow \\infty} \\left| \\frac{\\frac{(-2)^{(m+1)}(\\ln {(m+1)}) }{6^{(m+1)}{(m+1)}} }{\\frac{(-2)^m(\\ln m) }{6^mm}} \\right| \\\\\n& = \\lim_{m\\rightarrow \\infty} \\left| \\frac{-2(\\ln {(m+1)})m }{6(\\ln m){(m+1)} } \\right| \\\\\n& = \\frac{1}{3}\n\\end{aligned}\\]\nbecause \\[\\lim_{m \\rightarrow \\infty} \\frac{m\\ln (m+1)}{(m+1) \\ln m} = \\lim_{m \\rightarrow \\infty} \\frac{m}{m+1} \\lim_{m \\rightarrow \\infty} \\frac{\\ln (m+1)}{\\ln m} = 1\\] by virtue of l'Hospital's rule applied to both limits on the right-hand side. \\begin{hint}\nThis means that the radius equals \\(3\\). At the endpoint \\(x=-7\\), the series equals \\[\\sum_{m=2}^{\\infty} \\frac{(\\ln m) }{m },\\] which diverges by direct comparison to the harmonic series, i.e., the \\(p\\)-series with \\(p = 1\\). At the endpoint \\(x=-1\\), the series equals \\[\\sum_{m=2}^{\\infty} (-1)^m\\frac{(\\ln m) }{m },\\] which converges by the alternating series test because the sign of the terms alternates and \\(\\ln m / m\\) decreases to zero as \\(m \\rightarrow \\infty\\). \\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[PowerSerInterval005]\n\nFind the full interval of convergence for the power series \\[\\sum_{m=1}^{\\infty} \\frac{\\sqrt[3]{m}(x - 2)^m }{m!}.\\]\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\left(1,3\\right)\\)}\n\\choice{\\(\\displaystyle \\left[1,3\\right)\\)}\n\\choice{\\(\\displaystyle \\left(1,3\\right]\\)}\n\\choice{\\(\\displaystyle \\left[1,3\\right]\\)}\n\\choice[correct]{\\(\\displaystyle \\left(-\\infty,\\infty\\right)\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nFirst observe that \n\\[\\begin{aligned}\n\\frac{1}{R} & = \\lim_{m\\rightarrow \\infty} \\left| \\frac{\\frac{\\sqrt[3]{{(m+1)}} }{{(m+1)}!} }{\\frac{\\sqrt[3]{m} }{m!}} \\right| \\\\\n& = \\lim_{m\\rightarrow \\infty} \\left| \\frac{\\sqrt[3]{{(m+1)}} }{(m+1)\\sqrt[3]{m} } \\right| \\\\\n& = 0\n\\end{aligned}\\]\nbecause \\(m+1\\) in the denominator tends to \\(\\infty\\) and \\[\\lim_{m \\rightarrow \\infty} \\frac{\\sqrt[3]{m+1}}{\\sqrt[3]{m}} = \\lim_{m \\rightarrow \\infty} \\left( 1 + m^{-1} \\right)^{1/3} = \\left( 1 + \\lim_{m \\rightarrow \\infty} m^{-1} \\right)^{1/3} = 1.\\]\nThis means that the radius is infinite and the interval of convergence is \\((-\\infty,\\infty)\\).\n\\end{feedback}\n\n\\end{question}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%%%%%[2015C.03]\n\nFor which values of \\(x\\) does the series \\(\\displaystyle \\sum_{n=1}^\\infty \\frac{(-1)^{n+1}(x-1)^n}{n 4^n}\\) converge?\n\\begin{multiplechoice}\n\\choice{\\(-3 < x < 5\\)}\n\\choice{\\(-3 \\leq x < 5\\)}\n\\choice[correct]{\\(-3 < x \\leq 5\\)}\n\\choice{\\(-5 < x \\leq 3\\)}\n\\choice{\\(-5 \\leq x < 3\\)}\n\\choice{\\(-5 \\leq x \\leq 3\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2016C.11]\n\nFind the interval of convergence of the power series below.\n\\[ \\sum_{n=1}^\\infty \\frac{(4x-1)^n}{n^\\frac{3}{4} (n^2+2)} \\]\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\left( 0 , \\frac{1}{2} \\right]\\)}\n\\choice[correct]{\\(\\displaystyle \\left[ 0 , \\frac{1}{2} \\right]\\)}\n\\choice{\\(\\displaystyle \\left( 0 , \\frac{1}{2} \\right)\\)}\n\\choice{\\(\\displaystyle \\left[ 0 , \\frac{1}{2} \\right)\\)}\n\\choice{\\(\\displaystyle \\left( -\\frac{1}{2} , 0\\right]\\)}\n\\choice{\\(\\left( - \\infty, \\infty \\right)\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2017C.13]\n\nFind the interval of convergence of the power series \\(\\displaystyle \\sum_{n=2}^\\infty \\frac{2^n (x+5)^n}{\\sqrt[3]{n}}\\).\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\left[ -\\frac{11}{2}, -\\frac{9}{2} \\right]\\)}\n\\choice[correct]{\\(\\displaystyle \\left[ -\\frac{11}{2}, -\\frac{9}{2} \\right)\\)}\n\\choice{\\(\\displaystyle \\left( -\\frac{11}{2}, -\\frac{9}{2} \\right)\\)}\n\\choice{\\(\\displaystyle \\left[ \\frac{9}{2}, \\frac{11}{2} \\right)\\)}\n\\choice{\\(\\displaystyle \\left( \\frac{9}{2}, \\frac{11}{2} \\right)\\)}\n\\choice{\\(\\displaystyle \\left[ \\frac{9}{2}, \\frac{11}{2} \\right]\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "0937e5cede91c1e9a96e46e5a111c0aeac939678", "size": 11603, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "powerseries/25powerseriespractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "powerseries/25powerseriespractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "powerseries/25powerseriespractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.5854700855, "max_line_length": 491, "alphanum_fraction": 0.6379384642, "num_tokens": 4289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138366, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7056166829489999}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\\begin{document}\n\\subsection{Generic greedy algorithm}\nThe greedy algorithm is an algorithmic paradigm. It does not always provide a solution in general, not least an optimal solution. As such the greedy algorithm is a description of a problem solving heuristic.  It says that when trying to solve a problem we should choose the local optimum at each iteration in the hope of finding a global optimum. In this section, we will introduce the generic procedure that makes the greedy algorithm and showing how it can be modified in a variety of ways, including for compatibility with matroids.\n\n\\begin{algorithm}[H]\n\\caption{Greedy algorithm\\cite{jungnickel}}\\label{greedy}\nLet $(E,\\mathcal{S})$ be an independence system and $\\omega:E \\longrightarrow \\mathbb{R^+}$\n\\begin{algorithmic}[1]\n\\Procedure{GREEDY}{$E, \\mathcal{S}, \\omega,T$}\n\\State order the elements of $E$ according to their weight\n\\State $E = \\{ e_1,...,e_m\\}$ with $\\omega(e_1) \\geq \\omega(e_2) \\geq ... \\geq \\omega(e_m)$\n\\State $T\\gets \\emptyset$\n\\For{$k=1$ to $m$}\n\t\\If{$T \\cup \\{e_k\\} \\in \\mathcal{S}$}\n\t \t\\State append $e_k$ to $T$\n\t\\EndIf\n\\EndFor\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\nWe can see in the above pseudocode (taken from \\cite{jungnickel}) that this is a sequential iterative algorithm. Our data is kept in a list sorted by weight: heaviest to lightest. We then select the heaviest entry in our list at each iteration and append it to our initial empty variable $T.$ By the end of the process we should have joined a certain number of the elements to our variable $T.$ Where $T$ at the time of termination is the greedy algorithm solution.\\\\ This is how the algorithm looks in the most abstract sense, later we will see it used as a way of solving the \\textit{minimal spanning tree} problem mentioned in \\textit{definition 3.11}.\n\\subsection{Modified greedy for Matroids}\nHere, we will see how this algorithm corresponds to matroids. The greedy algorithm above, constructed a maximal weight element from our list called $T.$ Depending on the structure of our system and the termination clause this element's cardinality can differ. It is our hope to show that when the greedy algorithm is applied to a matroid we get an optimal solution, meaning that we generate a base of the matroid. However, for now it is enough to show that the greedy algorithm always produces a solution in general. This is illustrated by the below pseudocode, which was adapted from Oxley's\\cite{ox_book} description.\n\n\\begin{algorithm}[H]\n\\caption{Matroid greedy algorithm}\\label{matroid_ver}\nThe \\textit{greedy algorithm} for the pair $(\\mathcal{I}, \\omega)$ is as follows:\n\\begin{algorithmic}[1]\n\\Procedure{GREEDY}{$E, \\mathcal{I}, \\omega$}\n\\State Set $T \\gets \\emptyset$ and $E = \\{e_1,...,e_m\\}$\n\\While{$\\exists e \\in E \\setminus T$ such that $T \\cup \\{e\\} \\in \\mathcal{I}$}\n\\State Choose such an element $e_{max}$ of maximum weight,\n\\State let $T = T \\cup \\{e_{max}\\}$\n\\EndWhile\n\\State\\Return $T$\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\nThe procedure described above is as follows: Initialise the solution variable $T$ as the emptyset (the empty set is always independent). We want to build the base of the matroid: $B_G.$ At each iteration select the heaviest weighted element possible that is not already contained in $T$ such that $T \\cup \\{e\\} \\in \\mathcal{I}$ where $e$ is the selected element, we want to repeat this procedure as many times as possible until there are no such elements left to choose. Then we return $T,$ as $T$ is now equal to the solution of the greedy algorithm, i.e $B_G$ (the base generated by the greedy algorithm). \n\n\\begin{rem}\nIt is interesting to note that in this way we should find a maximal member $B_{max}$ of $\\mathcal{B}$ (the collection of bases of a matroid) and we will prove that this is certainly the case later in \\textit{theorem 5.2}. But if we negate this process in the following way we can use this exact procedure to find a minimal member $B_{min}$ of $\\mathcal{B}.$ This works as follows:\\\\\nLet $\\omega : E \\longrightarrow \\mathbb{R^{-}}$ be the weight function, we want to find an independent set $A$ whose weight is maximal, where\n\\begin{equation}\n\\omega(A) := \\sum_{e \\in A} |\\omega (e)|\n\\end{equation}\nDue to the fact that our weights are now negative real numbers, finding the maximal element at each iteration corresponds to finding the value with the minimal absolute value. And so through completing the greedy algorithm process we should successfully find our minimal element $B_{min}$ of $\\mathcal{B}.$\n\\end{rem}\n\\end{document}", "meta": {"hexsha": "395f3e81b87a4e9b15792bda6c7f6d3f12cb70c8", "size": 4604, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeXPdfs/sections/algo1.tex", "max_stars_repo_name": "emcd123/Matroids", "max_stars_repo_head_hexsha": "f1ab7a5164a60b753ba429ef7ba9ce36517d4439", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "LaTeXPdfs/sections/algo1.tex", "max_issues_repo_name": "emcd123/Matroids", "max_issues_repo_head_hexsha": "f1ab7a5164a60b753ba429ef7ba9ce36517d4439", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LaTeXPdfs/sections/algo1.tex", "max_forks_repo_name": "emcd123/Matroids", "max_forks_repo_head_hexsha": "f1ab7a5164a60b753ba429ef7ba9ce36517d4439", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-21T18:03:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T18:03:07.000Z", "avg_line_length": 88.5384615385, "max_line_length": 655, "alphanum_fraction": 0.7539096438, "num_tokens": 1216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503206, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7056166733904754}}
{"text": "\\chapter[Finite elements for parabolic problems]{Finite elements for \\\\\nparabolic problems in 1D}\n\nWe now consider a more general parabolic PDE with mixed boundary conditions,\n\\begin{equation}\\label{eq: parabolic ivp 1d}\n\\begin{aligned}\nu_t+\\mathcal{L}u&=f(x,t)&&\\text{for $0<x<L$ and $0<t<T$,}\\\\\nu&=\\gamma_0(t)&&\\text{at $x=0$, for $0<t<T$,}\\\\\nau'&=\\gamma_L(t)&&\\text{at $x=L$, for $0<t<T$,}\\\\\nu&=u_0(x)&&\\text{for $0<x<L$ when $t=0$,}\n\\end{aligned}\n\\end{equation}\nwhere $\\mathcal{L}u=-\\bigl(a(x)u'\\bigr)'+c(x)u$ as before \nin~\\eqref{eq: L self-adjoint}.  The identity~\\eqref{eq: Lu v by parts} implies \nthat, for any test function~$v(x)$,\n\\begin{equation}\\label{eq: parabolic 1d weak}\n\\int_0^Lu_tv\\,dx+\\int_0^L\\bigl(a(x)u_xv_x+c(x)uv\\bigr)\\,dx\n\t=\\gamma_L(t)v(L)+\\int_0^Lf(x,t)v\\,dx\n\\quad\\text{provided $v(0)=0$.}\n\\end{equation}\nWe will use this relation to formulate a semidiscrete finite element \nsolution~$u_h(x,t)\\approx u(x,t)$ and then apply finite difference \napproximations in time to derive some fully-discrete schemes.\n\n\\section{Semidiscrete method}\\label{sec: semidiscrete parabolic FEM}\nLet $V_h$ denote the space of continuous, piecewise-linear functions for a \ngiven mesh~\\eqref{eq: 1d nodes} on the spatial interval~$[0,L]$.  We define the \nsolution set (now dependent on~$t$) and test space by\n\\[\nS_h(t)=\\{\\,v\\in V_h:v(0)=\\gamma_0(t)\\,\\}\n\\quad\\text{and}\\quad\nT_h=\\{\\,v\\in V_h:v(0)=0\\,\\}.\n\\]\nWe also choose $u_{0h}\\in V_h$ such that $u_0\\approx u_{0h}$; the simplest \nchoice would be the interpolant $u_{0h}=\\mathcal{Q}_1u_0$. The semidiscrete\nfinite element solution~$u_h(x,t)$ is then defined for~$0\\le t\\le T$ by \nrequiring that $u_h(\\cdot,t)\\in S_h(t)$ and\n\\begin{equation}\\label{eq: semidiscrete fem 1d}\n\\int_0^L(u_h)_tv\\,dx+\\int_0^L\\bigl(a(x)(u_h)_xv_x+c(x)u_hv\\bigr)\\,dx\n    =\\gamma_L(t)v(L)+\\int_0^Lf(x,t)v\\,dx\n\\quad\\text{for all $v\\in T_h$,}\n\\end{equation}\nwith $u_h(0)=u_{0h}$. The stiffness matrix~$\\boldsymbol{A}$ and mass \nmatrix~$\\boldsymbol{C}$ are the same as in the stationary problem \n(section~\\ref{sec: self-adjoint 1d}), but the nodal \nvalues of the solution are now time-dependent, with\n\\[\nu_h(x,t)=\\sum_{q=0}^P U_q(t)\\chi_q(x)\\quad\\text{for $0\\le x\\le L$,}\\quad\n\\text{where $U_q(t)=u_h(x_q,t)$.}\n\\]\nLikewise, the load vector is time-dependent in general, since \n\\[\nf_p(t)=\\int_0^Lf(x,t)\\chi_p(x)\\,dx.\n\\]\nNoting \n\\[\n\\int_0^L(u_h)_t\\chi_p\\,dx=\\int_0^L\\sum_{q=0}^P\n    \\frac{dU_q}{dt}\\,\\chi_q(x)\\chi_p(x)\\,dx=\\sum_{q=0}^P m_{pq}\\,\\frac{dU_q}{dt}\n    \\quad\\text{where $m_{pq}=\\int_0^L\\chi_q\\chi_p\\,dx$,}\n\\]\nwe see by choosing $v=\\chi_p$ in~\\eqref{eq: semidiscrete fem 1d} that\n\\[\n\\sum_{q=0}^P\\biggl(m_{pq}\\,\\frac{dU_q}{dt}+a_{pq}U_q+c_{pq}U_q\\biggr)\n    =\\gamma_L(t)\\chi_p(L)+f_p(t),\n\\]\nwith $U_q(0)=u_{0h}(x_q)$.  Since $U_0(t)=u_h(x_0,t)=\\gamma_0(t)$,\n\\[\n\\sum_{q=1}^P\\biggl(m_{pq}\\,\\frac{dU_q}{dt}+a_{pq}U_k+c_{pq}U_q\\biggr)\n    =f_p(t)+g_p(t)\n\\]\nwhere\n\\[\ng_p(t)=\\gamma_L(t)\\delta_{pP}-m_{p0}\\gamma_0'(t)-(a_{p0}+c_{p0})\\gamma_0(t),\n\\]\nand so the nodal values satisfy the $P\\times P$ system of linear ODEs,\n\\begin{equation}\\label{eq: semidiscrete fem 1d ODE}\n\\boldsymbol{M}\\,\\frac{d\\boldsymbol{U}}{dt}\n+(\\boldsymbol{A}+\\boldsymbol{C})\\boldsymbol{U}=\\boldsymbol{f}(t)\n    +\\boldsymbol{g}(t)\\quad\\text{for $0\\le t\\le T$,}\n    \\quad\\text{with $\\boldsymbol{U}(0)=\\boldsymbol{U}_0$,}\n\\end{equation}\nwhere \n\\[\n\\boldsymbol{M}=[m_{pq}]_{p,q=1}^P,\\qquad \n\\boldsymbol{A}=[a_{pq}]_{p,q=1}^P,\\qquad\n\\boldsymbol{C}=[c_{pq}]_{p,q=1}^P,\n\\]\nand\n\\[\n\\boldsymbol{f}(t)=[f_p(t)]_{p=1}^P,\\qquad\n\\boldsymbol{g}(t)=[g_p(t)]_{p=1}^P,\\qquad\n\\boldsymbol{U}_0=[u_{0h}(x_p)]_{p=1}^P.\n\\]\nBy using an energy argument, we can show that $u_h$ is stable.\n\n\\begin{theorem}\nAssume that $c(x)\\ge0$.  Then, the semidiscrete finite element \nmethod~\\eqref{eq: semidiscrete fem 1d} has a unique \nsolution~$u_h(\\cdot,t)\\in S_h(t)$ for~$0\\le t\\le T$.  Furthermore, the\nmethod is stable in the sense that\n\\[\n\\|(u_h-\\eta)(\\cdot,t)\\|\\le\\|(u-\\eta)(\\cdot,0)\\|\n\t+2\\int_0^t\\|(f-\\eta_s-\\mathcal{L}\\eta)(\\cdot,s)\\|\\,ds\n\t\\quad\\text{for $0\\le t\\le T$,}\n\\]\nwhere $\\eta$ is any function satisfying\n\\[\n\\eta(\\cdot,t)\\in S_h(t),\\qquad \\eta(0,t)=\\gamma_0(t),\\qquad\n\ta(L)\\eta_x(L,t)=\\gamma_L(t).\n\\]  \nFor example, we my choose\n\\[\n\\eta(x,t)=\\gamma_0(t)+\\frac{\\gamma_L(t)}{a(L)}\\,x.\n\\]\n\\end{theorem}\n\\begin{proof}\nThe existence and uniqueness of $u_h$ follows from a standard result for\nsystems of ODEs.  To establish the stability estimate, we first\nuse the energy inner product~\\eqref{eq: energy iprod} to write\n\\eqref{eq: semidiscrete fem 1d} as\n\\[\n\\iprod{(u_h)_t,v}+\\iprod{u_h,v}_{\\mathcal{L}}=\\gamma_L(t)v(L)\n\t+\\iprod{f(\\cdot,t),v}\\quad\\text{for all $v\\in T_h$.}\n\\]\nThus, the difference \n\\[\nw(x,t)=u_h(x,t)-\\eta(x,t)\n\\]\nsatisfies \n\\[\nw(\\cdot,t)\\in S_h(t)\\quad\\text{and}\\quad\nw(0,t)=u_h(0,t)-\\gamma_0(t)=0,\n\\]\nimplying that $w(\\cdot,t)\\in T_h$ for each~$t\\in[0,T]$, and we see by\nchoosing $v(x)=w(x,t)$ that\n\\[\n\\iprod{(u_h)_t,w(\\cdot,t)}+\\iprod{u_h,w(\\cdot,t)}_{\\mathcal{L}}\n\t=\\gamma_L(t)w(L,t)+\\iprod{f(\\cdot,t),w(\\cdot,t)}.\n\\]\nSince $u_h=w+\\eta$,\n\\[\n\\iprod{w_t+\\eta_t,w}+\\iprod{w+\\eta,w}_{\\mathcal{L}}\n\t=\\gamma_L(t)w(L,t)+\\iprod{f,w},\n\\]\nand integration by parts gives\n\\[\n\\iprod{\\eta,w}_{\\mathcal{L}}=[a\\eta_xw]_0^L+\\iprod{\\mathcal{L}\\eta,w}\n\t=\\gamma_L(t)w(L,t)+\\iprod{\\mathcal{L}\\eta,w}.\n\\]\nTherefore,\n\\[\n\\iprod{w_t,w}+\\|w\\|_{\\mathcal{L}}^2=\\iprod{g,w}\n\\quad\\text{where}\\quad g(x,t)=f(x,t)-\\eta_t(x,t)-(\\mathcal{L}\\eta)(x,t).\n\\]\nObserve that\n\\[\n\\iprod{w_t,w}=\\frac{1}{2}\\,\\frac{d}{dt}\\|w(\\cdot,t)\\|^2,\n\\]\nso after integrating in time to arrive at the estimate\n\\[\n\\|w(\\cdot,t)\\|^2+2\\int_0^t\\|w(\\cdot,s)\\|_{\\mathcal{L}}^2\\,ds\n\\le\\|w_0\\|^2+2\\int_0^t\\iprod{g(\\cdot,s),w(\\cdot,s)}\\,ds\n\\quad\\text{for $0\\le t\\le T$,}\n\\]\nwhere \n\\[\nw_0(x)=w(x,0)=(u-\\eta)(x,0).\n\\]\nSince $\\|w(\\cdot,t)\\|$ is a continuous function of~$t$, there is a \n$t^*\\in[0,t]$ such that \n\\[\n\\|w(\\cdot,t^*)\\|=\\max_{0\\le s\\le t}\\|w(\\cdot,s)\\|. \n\\]\nTherefore, using the Cauchy--Schwarz inequality,\n\\begin{multline*}\n\\|w(\\cdot,t)\\|^2\\le\\|w(\\cdot,t)\\|^2+2\\int_0^t\\|w(\\cdot,s)\\|_{\\mathcal{L}}^2\\,ds\n\\le\\|w(\\cdot,t^*)\\|^2+2\\int_0^{t^*}\\|w(\\cdot,s)\\|_{\\mathcal{L}}^2\\,ds\\\\\n\\le\\|w_0\\|^2+2\\int_0^{t^*}\\|g(\\cdot,s)\\|\\|w(\\cdot,s)\\|\\,ds\n\\le\\|w(\\cdot,t^*)\\|\\biggl(\\|w_0\\|+2\\int_0^t\\|g(\\cdot,s)\\|\\,ds\\biggr),\n\\end{multline*}\nso\n\\[\n\\|w(\\cdot,t)\\|\\le\\|w_0\\|+2\\int_0^t\\|g(\\cdot,s)\\|\\,ds,\n\\]\nwhich gives the desired estimate.\n\\end{proof}\n\\begin{corollary}\n\\begin{multline*}\n\\|u_h(\\cdot,t)\\|\\le\\|u_{0h}\\|+2\\int_0^t\\|f(\\cdot,s)\\|\\,ds\\\\\n\t+C\\biggl(|\\gamma_0(t)|+|\\gamma_L(t)|\n\t+\\int_0^t\\bigl(|\\gamma_0(s)|+|\\gamma_0'(s)|\n\t+|\\gamma_L(s)|+|\\gamma_L'(s)|\\bigr)\\,ds\\biggr).\n\\end{multline*}\n\\end{corollary}\n\n\\section{Time stepping}\\label{sec: time stepping}\nWe can use finite differences for the time integration, putting\n\\begin{equation}\\label{eq: uniform tn}\nt_n=n\\,\\Delta t\\quad\\text{for $0\\le n\\le N$,}\n    \\quad\\text{where $\\Delta t=\\frac{T}{N}$,}\n\\end{equation}\nand seeking $U^n_p\\approx u_h(x_p,t_n)\\approx u(x_p,t_n)$.\n\n\\begin{example}\nThe \\emph{forward Euler method} based on~\\eqref{eq: semidiscrete fem 1d ODE} is\n\\[\n\\boldsymbol{M}\\,\\frac{\\boldsymbol{U}^{n+1}-\\boldsymbol{U}^n}{\\Delta t}\n+(\\boldsymbol{A}+\\boldsymbol{C})\\boldsymbol{U}^n=\\boldsymbol{f}^n\n    +\\boldsymbol{g}^n\\quad\\text{for $0\\le n\\le N-1$,}\n    \\quad\\text{with $\\boldsymbol{U}^0=\\boldsymbol{U}_0$,}\n\\]\nwhere $\\boldsymbol{U}^n=[U^n_p]_{p=1}^P$, \n$\\boldsymbol{f}^n=\\boldsymbol{f}(t_n)$~and \n$\\boldsymbol{g}^n=\\boldsymbol{g}(t_n)$.  Notice that this method is not \nactually explicit, due to the presence of the matrix~$\\boldsymbol{M}$: at the \n$n$th time step we have to solve the linear system\n\\[\n\\boldsymbol{M}\\boldsymbol{U}^{n+1}=\\bigl(\\boldsymbol{M}\n-\\Delta t\\,(\\boldsymbol{A}+\\boldsymbol{C})\\bigr)\\boldsymbol{U}^n\n    +\\Delta t\\,\\bigl(\\boldsymbol{f}^n+\\boldsymbol{g}^n\\bigr).\n\\]\n\\end{example}\n\n\\begin{example}\nThe \\emph{backward Euler method} based on~\\eqref{eq: semidiscrete fem 1d ODE} is\n\\[\n\\boldsymbol{M}\\,\\frac{\\boldsymbol{U}^{n}-\\boldsymbol{U}^{n-1}}{\\Delta t}\n+(\\boldsymbol{A}+\\boldsymbol{C})\\boldsymbol{U}^n=\\boldsymbol{f}^n\n    +\\boldsymbol{g}^n\\quad\\text{for $1\\le n\\le N$,}\n    \\quad\\text{with $\\boldsymbol{U}^0=\\boldsymbol{U}_0$,}\n\\]\nwhich requires that we solve the linear systems\n\\[\n\\bigl(\\boldsymbol{M}+\\Delta t\\,(\\boldsymbol{A}+\\boldsymbol{C})\\bigr) \n    \\boldsymbol{U}^n=\\boldsymbol{M}\\boldsymbol{U}^{n-1}\n    +\\Delta t\\,\\bigl(\\boldsymbol{f}^n+\\boldsymbol{g}^n\\bigr).\n\\]\n\\end{example}\n\n\\begin{example}\nThe \\emph{Crank--Nicolson method} based on~\\eqref{eq: semidiscrete fem 1d ODE} \nis\n\\[\n\\boldsymbol{M}\\,\\frac{\\boldsymbol{U}^{n}-\\boldsymbol{U}^{n-1}}{\\Delta t}\n+(\\boldsymbol{A}+\\boldsymbol{C})\\boldsymbol{U}^{n-1/2}=\\boldsymbol{f}^{n-1/2}\n    +\\boldsymbol{g}^{n-1/2}\\quad\\text{for $1\\le n\\le N$,}\n    \\quad\\text{with $\\boldsymbol{U}^0=\\boldsymbol{U}_0$,}\n\\]\nwhich requires that we solve the linear systems\n\\[\n\\bigl(\\boldsymbol{M}+\\tfrac12\\Delta t\\,(\\boldsymbol{A}+\\boldsymbol{C})\\bigr) \n    \\boldsymbol{U}^n\n=\\bigl(\\boldsymbol{M}-\\tfrac12\\Delta t\\,(\\boldsymbol{A}+\\boldsymbol{C})\\bigr) \n    \\boldsymbol{U}^{n-1}\n    +\\Delta t\\,\\bigl(\\boldsymbol{f}^{n-1/2}+\\boldsymbol{g}^{n-1/2}\\bigr).\n\\]\n\\end{example}\n\n\\section{Discrete separation of variables}\\label{sec: discrete separation}\nConsider the special case when $f(x,t)\\equiv0$, $\\gamma_0(t)\\equiv0$~and \n$\\gamma_L(t)\\equiv0$.  Let $(\\phi_k,\\lambda_k)$ be the $k$th eigenpair for the \noperator $\\mathcal{L}$, so that\n\\[\n\\mathcal{L}\\phi_k=\\lambda_k\\phi_k\\quad\\text{for $0<x<L$,}\\quad\n\\text{with $\\phi_k(0)=0=a\\phi_k'(L)$.}\n\\]\nFor the special choice of initial condition\n\\[\nu_0(x)=\\phi_k(x),\n\\]\nthe solution of the continuous problem $u_t+\\mathcal{L}u=0$ is simply\n\\begin{equation}\\label{eq: u0 eigenfunction}\nu(x,t)=e^{-\\lambda_kt}\\phi_k(x).\n\\end{equation}\nWe shall assume that $c(x)\\ge0$ for $0<x<L$, which ensures that $\\lambda_k>0$ \nfor all~$k$; see exercise~\\ref{ex: quadratic form}.  Thus, the \nfactor~$e^{-\\lambda_kt}$ decreases monotonically to zero as~$t\\to\\infty$.\n\nEach of the matrices $\\boldsymbol{A}$, $\\boldsymbol{C}$~and $\\boldsymbol{M}$ is \nreal and symmetric, and in addition $\\boldsymbol{M}$ is positive-definite, so \nthere exist \\emph{generalised eigenpairs} $(\\boldsymbol{\\Phi}_k,\\Lambda_k)$ \nsuch that \n\\[\n(\\boldsymbol{A}+\\boldsymbol{C})\\boldsymbol{\\Phi}_k\n    =\\Lambda_k\\boldsymbol{M}\\boldsymbol{\\Phi}_k,\\qquad\n\\boldsymbol{\\Phi}_j^T(\\boldsymbol{A}+\\boldsymbol{C})\\boldsymbol{\\Phi}_k\n    =\\Lambda_k\\delta_{jk},\\qquad\n\\boldsymbol{\\Phi}_j^T\\boldsymbol{M}\\boldsymbol{\\Phi}_k=\\delta_{jk}\n\\]\nfor $j$, $k\\in\\{1,2,\\ldots,P\\}$.  Our assumptions ensure that \n$\\boldsymbol{A}+\\boldsymbol{C}$ is positive-definite, so $\\Lambda_k>0$ \nfor~$1\\le k\\le2P$.\n\nSuppose we choose discrete initial data\n\\[\n\\boldsymbol{U}_0=\\boldsymbol{\\Phi}_k.\n\\]\nFor moderate values of~$k$, we expect \n$\\boldsymbol{\\Phi_k}\\approx[\\phi_k(x_p)]_{p=1}^P$, assuming we label the \n$\\lambda_k$~and $\\Lambda_k$ so that\n\\[\n0<\\lambda_1\\le\\lambda_2\\le\\lambda_3\\le\\cdots\n\\quad\\text{and}\\quad\n0<\\Lambda_1\\le\\Lambda_2\\le\\cdots\\le\\Lambda_P,\n\\]\nand make appropriate choices for the corresponding eigenfunctions and \neigenvectors. In our special case, the semidiscrete initial-value \nproblem~\\eqref{eq: semidiscrete fem 1d ODE} simplifies to\n\\[\n\\boldsymbol{M}\\,\\frac{d\\boldsymbol{U}}{dt}\n+(\\boldsymbol{A}+\\boldsymbol{C})\\boldsymbol{U}=\\boldsymbol{0}\n    \\quad\\text{for $0\\le t\\le T$,}\n    \\quad\\text{with $\\boldsymbol{U}(0)=\\boldsymbol{\\Phi}_k$,}\n\\]\nwhich has the solution\n\\begin{equation}\n\\boldsymbol{U}(t)=e^{-\\Lambda_kt}\\boldsymbol{\\Phi}_k,\n\\end{equation}\nwhich again decreases monotonically to zero as~$t\\to\\infty$.\n\nLet us compare theses continuous-time solutions with the discrete-time \nsolutions for the three time-stepping schemes described in \nsection~\\ref{sec: time stepping}.  \n\n\\begin{example}\nThe forward Euler method in this special case is\n\\[\n\\boldsymbol{M}\\boldsymbol{U}^{n+1}=\\bigl(\\boldsymbol{M}\n-\\Delta t\\,(\\boldsymbol{A}+\\boldsymbol{C})\\bigr)\\boldsymbol{U}^n,\n\\]\nand since\n\\[\n\\bigl(\\boldsymbol{M} \n-\\Delta t\\,(\\boldsymbol{A}+\\boldsymbol{C})\\bigr)\\boldsymbol{\\Phi}_k\n    =\\boldsymbol{M}\\Phi_k-\\Delta t\\,\\Lambda_k\\boldsymbol{M}\\boldsymbol{\\Phi}_k\n    =\\boldsymbol{M}(1-\\Delta t\\,\\Lambda_k)\\boldsymbol{\\Phi}_k\n\\]\nwe see by induction on $n$ that\n\\[\n\\boldsymbol{U}^n=(1-\\Delta t\\,\\Lambda_k)^n\\boldsymbol{\\Phi}_k.\n\\]\nIf $\\Delta t\\,\\Lambda_k<1$ then the factor~$(1-\\Delta t\\,\\Lambda_k)^n$ \ndecreases monotonically to zero as~$t_n\\to\\infty$, so we have the correct \nqualitative behaviour of the solution, and furthermore\n\\[\ne^{-\\Lambda_kt_n}=e^{-\\Lambda_k n\\,\\Delta t}\n    =\\bigl(e^{-\\Delta t\\Lambda_k}\\bigr)^n\\approx(1-\\Delta t\\,\\Lambda_k)^n\n    \\quad\\text{if $\\Delta t\\,\\Lambda_k$ is small, for $n$ fixed.}\n\\]\nIf $1<\\Delta t\\,\\Lambda_k<2$ then $(1-\\Delta t\\,\\Lambda_k)^n$ tends to zero, \nbut with an oscillating sign, as $t_n\\to\\infty$, which is the wrong qualitative \nbehaviour. If $\\Delta t\\,\\Lambda_k>2$, then $(1-\\Delta t\\,\\Lambda_k)^n$ not \nonly oscillates but is also unbounded.\n\\end{example}\n\n\\begin{example}\nThe \\emph{backward Euler method} in this special case is\n\\[\n\\bigl(\\boldsymbol{M}+\\Delta t\\,(\\boldsymbol{A}+\\boldsymbol{C})\\bigr) \n    \\boldsymbol{U}^n=\\boldsymbol{M}\\boldsymbol{U}^{n-1},\n\\]\nand since\n\\[\n\\bigl(\\boldsymbol{M} +\\Delta t\\,(\\boldsymbol{A}+\\boldsymbol{C})\\bigr)^{-1}\n\\boldsymbol{M}\\boldsymbol{\\Phi}_k\n    =(1+\\Delta t\\,\\Lambda_k)^{-1}\\boldsymbol{\\Phi_k}\n\\]\nwe see by induction on $n$ that\n\\[\n\\boldsymbol{U}^n=(1+\\Delta t\\,\\Lambda_k)^{-n}\\boldsymbol{\\Phi}_k.\n\\]\nThe factor~$(1+\\Delta t\\,\\Lambda_k)^{-n}$ always decreases monotonically to \nzero as~$t_n\\to\\infty$, so we have the correct qualitative behaviour no matter \nhow large $\\Delta t$.  Furthermore,\n\\[\ne^{-\\Lambda_kt_n}=\\bigl(e^{-\\Delta t\\Lambda_k}\\bigr)^n\n    \\approx(1+\\Delta t\\,\\Lambda_k)^{-n}\n    \\quad\\text{if $\\Delta t\\,\\Lambda_k$ is small, for $n$ fixed.}\n\\]\n\\end{example}\n\n\\begin{example}\nThe \\emph{Crank--Nicolson method} in this special case is\n\\[\n\\bigl(\\boldsymbol{M}+\\tfrac12\\Delta t\\,(\\boldsymbol{A}+\\boldsymbol{C})\\bigr) \n    \\boldsymbol{U}^n\n=\\bigl(\\boldsymbol{M}-\\tfrac12\\Delta t\\,(\\boldsymbol{A}+\\boldsymbol{C})\\bigr) \n    \\boldsymbol{U}^{n-1},\n\\]\nand since\n\\[\n\\bigl(\\boldsymbol{M}+\\tfrac12\\Delta t\\,\n    (\\boldsymbol{A}+\\boldsymbol{C})\\bigr)^{-1}\n\\bigl(\\boldsymbol{M}-\\tfrac12\\Delta t\\,(\\boldsymbol{A}+\\boldsymbol{C})\\bigr) \n    \\boldsymbol{\\Phi_k}\n    =\\frac{(1-\\tfrac12\\Delta t\\,\\Lambda_k)^{-1}}%\n{(1+\\tfrac12\\Delta t\\,\\Lambda_k)^{-1}}\\,\\boldsymbol{\\Phi_k},\n\\]\nwe see by induction on $n$ that\n\\[\n\\boldsymbol{U}^n=\\biggl(\n    \\frac{1-\\tfrac12\\Delta t\\,\\Lambda_k}{1+\\tfrac12\\Delta t\\,\\Lambda_k}\\biggr)^n\n    \\boldsymbol{\\Phi}_k.\n\\]\nThus, the correct qualitative behaviour occurs when $\\Delta t\\,\\Lambda_k<2$.\nIf $\\Delta t\\,\\Lambda_k>2$, then $\\boldsymbol{U}^n$ still tends to zero \nas~$t_n\\to\\infty$, but with a sign oscillation.  Also, rate of decay becomes \nslower and slower with increasing values of~$\\Delta t\\,\\Lambda_k$.\n\\end{example}\n\nFor general initial data~$u_0$, we know from section~\\ref{sec: separation} \nthat the continuous solution is\n\\[\nu(x,t)=e^{-t\\mathcal{L}}u_0(x)\n    =\\sum_{k=1}^\\infty\\widehat{(u_0)}_k e^{-\\lambda_kt}\\phi_k(x)\n\\quad\\text{where}\\quad\n\\widehat{(u_0)}_k=\\frac{\\langle u_0,\\phi_k\\rangle}{\\|\\phi_k\\|^2}.\n\\]\nSimilarly, we claim that for a general discrete\ndata~$\\boldsymbol{U}_0$, the semidiscrete finite element solution has the form\n\\begin{equation}\\label{eq: semidiscrete FEM Fourier}\n\\boldsymbol{U}(t)=e^{-t\\boldsymbol{M}^{-1}(\\boldsymbol{A}+\\boldsymbol{C})}\n    \\boldsymbol{U}_0\n    =\\sum_{k=1}^P\\widehat{(\\boldsymbol{U}_0)}_k e^{-\\Lambda_kt}\n    \\boldsymbol{\\Phi}_k\n\\quad\\text{where}\\quad\n\\widehat{(\\boldsymbol{U}_0)}_k\n=\\frac{\\langle\\boldsymbol{U}_0,\\boldsymbol{\\Phi}_k\\rangle_{\\boldsymbol{M}}}%\n{\\|\\boldsymbol{\\Phi_k}\\|_{\\boldsymbol{M}}^2}.\n\\end{equation}\nHere, $\\langle\\boldsymbol{V},\\boldsymbol{W}\\rangle_{\\boldsymbol{M}}\n=\\boldsymbol{V}^T\\boldsymbol{M}\\boldsymbol{W}$ and \n$\\|\\boldsymbol{V}\\|_{\\boldsymbol{M}}\n=\\sqrt{\\boldsymbol{V}^T\\boldsymbol{M}\\boldsymbol{V}}$ are the inner product and \nnorm induced by the positive-definite matrix~$\\boldsymbol{M}$.  Indeed, \n$\\boldsymbol{U}(t)=e^{-t\\boldsymbol{M}^{-1}(\\boldsymbol{A}+\\boldsymbol{C})}\n\\boldsymbol{U}_0$ because\n\\[\n\\frac{d\\boldsymbol{U}}{dt}+\\boldsymbol{M}^{-1}(\\boldsymbol{A}+\\boldsymbol{C})\n\\boldsymbol{U}=\\boldmath{0},\n\\]\nand we have\n\\[\n\\boldsymbol{U}_0=\\sum_{k=1}^P\\widehat{(\\boldsymbol{U}_0)}_k\\boldsymbol{\\Phi}_k,\n\\]\nbecause the eigenvectors~$\\boldsymbol{\\Phi}_k$ form an \n$\\boldsymbol{M}$-orthogonal basis for~$\\mathbb{R}^P$.  The \nrepresentation~\\eqref{eq: semidiscrete FEM Fourier} then follows because\n$\\boldsymbol{M}^{-1}(\\boldsymbol{A}+\\boldsymbol{C})\\boldsymbol{\\Phi}_k\n=\\Lambda_k\\boldsymbol{\\Phi}_k$.\n\n\\begin{example}\\label{example: forward Euler FEM}\nFor general discrete initial data~$\\boldsymbol{U}_0$, the forward Euler method \ngives\n\\[\n\\boldsymbol{U}^n=\\sum_{k=1}^P\\widehat{(\\boldsymbol{U}_0)}_k \n    (1-\\Delta t\\,\\Lambda_k)^n\\Phi_k,\n\\]\nand therefore\n\\[\n\\|\\boldsymbol{U}^n\\|_{\\boldsymbol{M}}^2\n    =\\sum_{k=1}^P\\bigl|\\widehat{(\\boldsymbol{U}_0)}_k\\bigr|^2\n    |1-\\Delta t\\,\\Lambda_k|^{2n}\\|\\Phi_k\\|_{\\boldsymbol{M}}^2.\n\\]\nSince\n\\[\n\\|\\boldsymbol{U}_0\\|_{\\boldsymbol{M}}^2\n    =\\sum_{k=1}^P\\bigl|\\widehat{(\\boldsymbol{U}_0)}_k\\bigr|^2\n    \\|\\Phi_k\\|_{\\boldsymbol{M}}^2,\n\\]\nit follows that\n\\[\n\\|\\boldsymbol{U}^n\\|_{\\boldsymbol{M}}\n    \\le\\Bigl(\\max_{1\\le k\\le P}|1-\\Delta t\\,\\Lambda_k|^n\\Bigr)\n    \\|\\boldsymbol{U}_0\\|_{\\boldsymbol{M}}\n\t=(|1-\\Delta t\\,\\Lambda_P)^n\\|\\boldsymbol{U}_0\\|_{\\boldsymbol{M}}.\n\\]\nHence, if $\\Delta t\\le 1/\\Lambda_P$ then $\\|\\boldsymbol{U}^n\\|_{\\boldsymbol{M}}\n\\le\\|\\boldsymbol{U}_0\\|_{\\boldsymbol{M}}$ and the forward Euler method is \nstable in the $\\boldsymbol{M}$-norm.\n\\end{example}\n\n\\begin{example}\nA similar argument shows that the backward Euler method gives\n\\[\n\\|\\boldsymbol{U}^n\\|_{\\boldsymbol{M}}\n    \\le\\Bigl(\\max_{1\\le k\\le P}(1+\\Delta t\\,\\Lambda_k)^{-n}\\Bigr)\n    \\|\\boldsymbol{U}_0\\|_{\\boldsymbol{M}}\n\t=(1+\\Delta t\\,\\Lambda_1)^{-n}\\|\\boldsymbol{U}_0\\|_{\\boldsymbol{M}},\n\\]\nand hence we have stability in the $\\boldsymbol{M}$-norm for any~$\\Delta t$.\n\\end{example}\n\n\\begin{example}\nFor the Crank--Nicolson method,\n\\[\n\\|\\boldsymbol{U}^n\\|_{\\boldsymbol{M}}\n    \\le\\biggl(\\max_{1\\le k\\le P}\\biggl|\n    \\frac{1-\\tfrac12\\Delta t\\,\\Lambda_k}{1+\\tfrac12\\Delta t\\,\\Lambda_k}\n    \\biggr|^n\\biggr)\\|\\boldsymbol{U}_0\\|_{\\boldsymbol{M}}\n=\\biggl|\\frac{1-\\tfrac12\\Delta t\\,\\Lambda_1}{1+\\tfrac12\\Delta t\\,\\Lambda_1}\n\t\\biggr|^n\\|\\boldsymbol{U}_0\\|_{\\boldsymbol{M}},\n\\]\nand we again have stability in the $\\boldsymbol{M}$-norm for any~$\\Delta t$.\n\\end{example}\n\n\\begin{Exercises}\n\n\\exercise\\label{ex: quadratic form}\nSuppose that $\\boldsymbol{A}\\in\\mathbb{R}^{N\\times N}$ is symmetric and \npositive-semidefinite, and let \n$\\|\\boldsymbol{v}\\|=\\sqrt{\\boldsymbol{v}^T\\boldsymbol{v}}$ denote the \nEuclidean norm in~$\\boldsymbol{R}^N$.  \n\\begin{description}\n\\item{(i)}\nShow that the minimum eigenvalue of~$\\boldsymbol{A}$ equals the minimum value \nof the \\emph{Rayleigh quotient}:\n\\[\n\\lambda_{\\min}(\\boldsymbol{A})\n    =\\min_{\\boldsymbol{0}\\ne\\boldsymbol{v}\\in\\mathbb{R}^N}\n    \\frac{\\boldsymbol{v}^T\\boldsymbol{A}\\boldsymbol{v}}{\\|\\boldsymbol{v}\\|^2}.\n\\]\nHint: choose an orthonormal basis for~$\\mathbb{R}^N$ consisting of eigenvectors \nof~$\\boldsymbol{A}$.\n\\item{(ii)} Show likewise for the maximum eigenvalue that\n\\[\n\\lambda_{\\max}(\\boldsymbol{A})\n    =\\max_{\\boldsymbol{0}\\ne\\boldsymbol{v}\\in\\mathbb{R}^N}\n    \\frac{\\boldsymbol{v}^T\\boldsymbol{A}\\boldsymbol{v}}{\\|\\boldsymbol{v}\\|^2}.\n\\]\n\\item{(iii)} How does this result generalise if we replace the Euclidean norm \nwith the norm~$\\|\\boldsymbol{v}\\|_{\\boldsymbol{M}}=\\sqrt{\\boldsymbol{v}^T\n\\boldsymbol{M}\\boldsymbol{v}}$ induced by a symmetric and strictly \npositive-definite matrix~$\\boldsymbol{M}\\in\\mathbb{R}^{N\\times N}$?\n\\end{description}\n\n\\exercise\\label{ex: polynomial derivative}\nLet $f(\\xi)=a_1+a_2\\xi+a_3\\xi^2+\\cdots+a_{r+1}\\xi^r$ be any real polynomial of \ndegree at most~$r$, and form the associated (column) vector of coefficients\n$\\boldsymbol{a}=[a_i]_{i=1}^{r+1}$.\n\\begin{description}\n\\item{(i)} Find the matrix~$\\boldsymbol{B}$ such that \n$\\int_0^1|f(\\xi)|^2\\,d\\xi=\\boldsymbol{a}^T\\boldsymbol{B}\\boldsymbol{a}$. \n\\item{(ii)} Prove that $\\boldsymbol{B}$ is symmetric and (strictly) \npositive-definite.\n\\item{(iii)} Find the matrix~$\\boldsymbol{D}$ such that\n$\\int_0^1|f'(\\xi)|^2\\,d\\xi=\\boldsymbol{a}^T\\boldsymbol{D}\\boldsymbol{a}$. \n\\item{(iv)} Prove that $\\boldsymbol{D}$ is symmetric and positive-semidefinite.\n\\item{(v)} With the help of exercise~\\ref{ex: quadratic form}, find a \nconstant~$C_r$ (depending only on~$r$) such that\n\\[\n\\int_0^1|f'(\\xi)|^2\\,d\\xi\\le C_r\\int_0^1|f(\\xi)|^2\\,d\\xi.\n\\]\n\\item{(vi)} Compute the numerical value of $C_r$ for $r\\in\\{0,1,2,3\\}$.\n\\end{description}\n\\begin{ans}\n(i) $\\boldsymbol{B}=[b_{ij}]_{i,j=1}^{r+1}$ where $b_{ij}=1/(i+j-1)$\\quad\n(iii) $\\boldsymbol{D}=[d_{ij}]_{i,j=1}^{r+1}$ where \n\\[\nd_{ij}=\\begin{cases}\n    0&\\text{if $i=1$ or $j=1$,}\\\\\n    (i-1)(j-1)/(i+j-3)&\\text{otherwise.}\n\\end{cases}\n\\]\n(iv) $C_r=\\lambda_{\\max}(\\boldsymbol{D})=\\max_{\\boldsymbol{a}\\ne\\boldsymbol{0}}\n\\boldsymbol{a}^T\\boldsymbol{D}\\boldsymbol{a}/\n\\boldsymbol{a}^T\\boldsymbol{B}\\boldsymbol{a}$ \n(vi)\n\\begin{center}\n\\renewcommand{\\arraystretch}{1.25}\n\\begin{tabular}{r|r}\n$r$&$C_r$\\\\\n\\hline\n   0&     0.00\\\\\n   1&    12.00\\\\\n   2&    60.00\\\\\n   3&   170.12\n\\end{tabular}\n\\end{center}\n\\end{ans}\n\n\\exercise\nLet $C_r$ be the constant from part (v) of \nexercise~\\ref{ex: polynomial derivative}, and recall the notation used in \nsection~\\ref{sec: accuracy of interpolation}.\n\\begin{description}\n\\item{(i)} Show that \n\\[\n\\int_{x_{p-1}}^{x_p}|f(x)|^2\\,dx=h_p\\int_0^1|\\hat f(\\xi)|^2\\,d\\xi\n\\quad\\text{and}\\quad\n\\int_{x_{p-1}}^{x_p}|f'(x)|^2\\,dx=h_p^{-1}\\int_0^1|\\hat f'(\\xi)|^2\\,d\\xi.\n\\]\n\\item{(ii)} Deduce that if $f\\in\\mathbb{P}_r$ then\n\\[\n\\int_{x_{p-1}}^{x_p}|f'(x)|^2\\,dx\n    \\le C_rh_p^{-2}\\int_{x_{p-1}}^{x_p}|f(x)|^2\\,dx.\n\\]\n\\item{(iii)} Hence prove the \\emph{inverse inequality}: if $v$ is a continuous \npiecewise polynomial of degree at most~$r$, then\n\\[\n\\int_0^L|v'(x)|^2\\,dx\\le C_rh_{\\min}^{-2}\\int_0^L|v(x)|^2\\,dx\n\\quad\\text{where $h_{\\min}=\\min_{1\\le p\\le P}h_p$.}\n\\]\n\\end{description}\n\n\\exercise\nRecall the notation from sections \n\\ref{sec: semidiscrete parabolic FEM}--\\ref{sec: discrete separation}.\n\\begin{description}\n\\item{(i)}\nShow that for any $v$, $w\\in T_h$,\n\\[\n\\int_0^L\\bigl(a(x)v'w'+c(x)vw\\bigr)\\,dx\n    =\\boldsymbol{W}^\\top(\\boldsymbol{A}+\\boldsymbol{C})\\boldsymbol{V}\n\\quad\\text{and}\\quad\n\\int_0^Lv(x)w(x)\\,dx=\\boldsymbol{W}^T\\boldsymbol{M}\\boldsymbol{V},\n\\]\nwhere $V_p=v(x_p)$~and $W_p=w(x_p)$.  \n\\item{(ii)}\nHence prove that\n\\[\n\\Lambda_{\\max}\\le C_1h_{\\min}^{-2}a_{\\max}+c_{\\max}\\quad\\text{where}\\quad\na_{\\max}=\\max_{0\\le x\\le L}a(x)\\quad\\text{and}\\quad\nc_{\\max}=\\max_{0\\le x\\le L}c(x).\n\\]\n\\item{(iii)}\nWhat does the upper bound in part~(ii) imply about the stability of the forward \nEuler method?\n\\end{description}\n\\begin{ans}\n(iii) We saw in example~\\ref{example: forward Euler FEM} that if $\\Delta \nt>1/\\Lambda_P$ then the forward Euler method has at least one unstable mode.  \nSince $\\Lambda_P=O(h_{\\min}^{-2})$, to ensure stability we must expect to need \n$\\Delta t$ of order~$h_{\\min}^2$.  This conclusion is consistent with the \nstability condition of Theorem~\\ref{thm: explicit Euler stability} for the \nfinite difference case.\n\\end{ans}\n\n\\end{Exercises}\n\n\n\n", "meta": {"hexsha": "d3d71b8f9e443b0d1c8de6e93f4e6b1537dd1204", "size": 23340, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "texsrc/chap4.tex", "max_stars_repo_name": "billmclean/ComputationalMathsNotes", "max_stars_repo_head_hexsha": "9d521fdf7ec407cca287997885d81c3150973415", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-30T21:30:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-30T21:30:20.000Z", "max_issues_repo_path": "texsrc/chap4.tex", "max_issues_repo_name": "billmclean/ComputationalMathsNotes", "max_issues_repo_head_hexsha": "9d521fdf7ec407cca287997885d81c3150973415", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "texsrc/chap4.tex", "max_forks_repo_name": "billmclean/ComputationalMathsNotes", "max_forks_repo_head_hexsha": "9d521fdf7ec407cca287997885d81c3150973415", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.298600311, "max_line_length": 80, "alphanum_fraction": 0.6655955441, "num_tokens": 9433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851135937125, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7056166706892089}}
{"text": "\\section{Limits}\n\n\\subsection{Delta-Epsilon Definition on R}\n\nThe limit of $f$ as $x$ approaches $a$ is $L$ if given a positive real number\n$\\epsilon$, there exists a corresponding $\\delta$ so that numbers selected with distance from $a$\nless than $\\delta$ and $>0$ it is guaranteed that outputs under $f$ are within distance $\\epsilon$ from $L$.\n\n\\begin{mybox}{Formal definition}\n    $\\lim_{x\\to a}f(x)=L$ if $\\forall \\epsilon >0$, $\\exists\\delta > 0$ such that $0< |x-a| < \\delta \\implies |f(x)-L|<\\epsilon$\n\\end{mybox}\n\n\\begin{center}\n    \\includegraphics[scale=0.5]{figures/Screen Shot 2021-05-12 at 3.29.55 PM.png}\n\\end{center}\n\n\\subsection{Definition of Limit on R2}\n\nIf $f:\\R^2\\to \\R$ and $P_0=(x_0,y_0)$, then $\\lim _{(x, y) \\rightarrow\\left(x_{0}, y_{0}\\right)} f(x, y)=L$ \nif given any small positive number $\\epsilon$, $\\delta>0$ is guaranteed so when there is a point $C\\neq P_0$ within circle of radius $\\delta$ about $P_0$, $f(x,y)$ lies within $\\epsilon$ of $L$.\n\n\\begin{mybox}{Formal definition}\n\\[\\lim _{(x, y) \\rightarrow\\left(x_{0}, y_{0}\\right)} f(x, y)=\\lim _{\\tb{x} \\rightarrow P_{0}} f(x, y)=L \\text { if } \\forall \\varepsilon>0 \\;\\exists \\delta>0\\]\nsuch that\n\\[0<\\sqrt{\\left(x-x_{0}\\right)^{2}+\\left(y-y_{0}\\right)^{2}}<\\delta \\Longrightarrow|f(x, y)-L|<\\varepsilon\\]\n\\end{mybox}\n\n\\begin{mybox}{Continuous functions}\n    \\begin{itemize}\n        \\item Polynomials: $f(x,y)=x^2y+xy^2$\n        \\item Exponentials: $f(x,y)=e^{xy}$\n        \\item Trigonometric: $f(x,y)=\\sin(x+y)$\n        \\item Compositions of any continuous functions: $f(x,y)=\\cos(e^{x^2y-xy^2})$\n        \\item Sums, differences, products of continuous functions: $f(x, y)=x^{2} y-x y^{2}+e^{x y} \\sin (x y)$\n        \\item Quotients of continuous functions (domain of quotient does not include zeros of denominator): $f(x, y)=\\frac{x^{2 y}-x y^{2}}{\\sin (x y)}$\n    \\end{itemize}\n\\end{mybox}\n\n\\subsection{Computational Techniques}\n\nCan use continuity to find limit (plug in point). Can also use conjugate multiplication to simplify and compute. Cancelling terms works because a limit approaches a value instead of equaling it.\nCan also squeeze a function between 2 continuous ones to find limit.\n\nLet $\\lim _{(x, y) \\rightarrow(0,0)} \\frac{x^{2}}{\\sqrt{x^{2}+y^{2}}}$ exist.\nKnow that $0\\leq \\lim _{(x, y) \\rightarrow(0,0)} \\frac{x^{2}}{\\sqrt{x^{2}+y^{2}}}$.\nBecause $y^2>0$, $\\frac{x^{2}}{\\sqrt{x^{2}+y^{2}}} \\leq \\frac{x^{2}+y^{2}}{\\sqrt{x^{2}+y^{2}}}$.\nThus, $\\lim _{(x, y) \\rightarrow(0,0)} 0 \\leq \\lim _{(x, y) \\rightarrow(0,0)} \\frac{x^{2}}{\\sqrt{x^{2}+y^{2}}} \\leq \\lim _{(x, y) \\rightarrow(0,0)}\\left(x^{2}+y^{2}\\right)^{1 / 2}$\nso the limit is 0.\n\nOther strategies: If a term $k(x,y)\\geq 0\\;\\forall\\; (x,y)\\in \\R^2$, then can simply perform $\\pm 1$ to denominator for squeeze theorem proofs.\n\n\\begin{mybox}{Common inequalities}\n\\begin{itemize}\n    \\item AM-GM inequality: $\\frac{x+y}{2}\\geq \\sqrt{xy}\\implies (x-y)^2\\geq 0$\n    \\item Triangle inequality: $|x+y|\\leq |x|+|y|$ and $|x-y|\\geq |x|-|y|$\n    \\item $|e^x-1|\\leq |x|e^{|x|}$\n    \\item $(x\\pm y)^2\\geq 0$\n\\end{itemize}\n\\end{mybox}\n\nProof that $\\frac{\\sin x}{x}=1$:\n\n\\begin{center}\n    \\includegraphics[scale=0.4]{figures/Screen Shot 2021-04-21 at 10.59.12 AM.png}\n\\end{center}\n\nIt is evident that:\n\\begin{gather}\n    \\frac{1}{2}\\sin x\\leq \\frac{1}{2}x\\leq \\frac{1}{2}\\tan x\\\\\n    \\sin x\\leq x \\leq \\tan x\\\\\n    1\\leq \\frac{x}{\\sin x}\\leq \\frac{1}{\\cos x}\\\\\n    1\\geq \\frac{\\sin x}{x}\\geq \\cos x\n\\end{gather}\n\nApplying the squeeze theorem to 4:\n\n\\begin{gather*}\n    \\lim_{x\\to 0}1\\geq \\lim_{x\\to 0}\\frac{\\sin x}{x}\\geq \\lim_{x\\to 0} \\cos x\\\\\n    1\\geq \\frac{\\sin x}{x}\\geq 1\n\\end{gather*}\n\nThus, $\\lim_{x\\to 0}\\frac{\\sin x}{x}=1$.\n\n\\section{Derivatives}\n\n\\subsection{Limit Definition}\n\nA function $f:\\R^m \\to \\R^n$ is differentiable at $P_0$ if there is a linear transformation from $n\\times m$ matrix $Df(P_0)$ satisfying\n\n\\[\\lim_{\\tb{x}\\to P_0}\\frac{\\big\\vert \\big\\vert f \\big( \\tb{x} \\big)-\\big(f(P_0)+\\mathrm{D}f(P_0)(\\tb{x}-P_0) \\big) \\big\\vert \\big\\vert}{\\vert \\vert \\tb{x}-P_0 \\vert \\vert}=0\\]\n\nIf the function is differentiable at this point, then $Df(P_0)$ is the derivative of $f$ at $P_0$. Called Jacobian matrix of $f$ at $P_0$.\n\nCan adapt this to single-variable calculus:\n\n\\[\\displaystyle \\lim_{x\\to a} \\frac{\\vert f(x)-\\big(f(a)+(m_a)(x-a)\\big) \\vert}{\\vert x-a \\vert}=0\\]\n\nSimplifying and reconfiguring to limit definition of a derivative:\n\n\\begin{align*}\n    \\lim_{x\\to a} \\frac{\\vert f(x)-\\big(f(a)+(m_a)(x-a)\\big) \\vert}{\\vert x-a \\vert}&=0\\\\\n    \\lim_{x\\to a}\\left\\vert \\frac{f(x)-\\big(f(a)+(m_a)(x-a)\\big)}{x-a} \\right\\vert&=0\\\\\n    \\left \\vert \\lim_{x\\to a} \\frac{f(x)-\\big(f(a)+(m_a)(x-a)\\big)}{x-a} \\right \\vert&=0\\\\\n    \\lim_{x\\to a} \\frac{f(x)-\\big(f(a)+(m_a)(x-a)\\big)}{x-a}&=0 \\, \\mbox{since}\\, \\vert 0 \\vert=0\\\\ \n    \\lim_{x\\to a} \\left( \\frac{f(x)-f(a)}{x-a}-m_a\\right)&=0\\\\\n    \\lim_{x\\to a}\\frac{f(x)-f(a)}{x-a}&=m_a\n\\end{align*}\n\nEquivalent to the case of a $1\\times 1$ matrix $Df(P_0)$ where the single entry is $f'(a)$.\nAlso $m_a=f'(a)\\implies f(x)=f(a)+f'(a)(x-a)$ is the linear approximation. \n\nAs $x$-values approach $a$, $f(x)-(f(a)+f'(a)(x-a))$ approaches 0 faster. Thus, $\\frac{f(x)-\\big(f(a)+f'(a)(x-a)\\big)}{x-a}$ approaches 0.\n\n\\subsection{Multivariable Application}\n\nApproximating plane of some $f:\\R^2\\to \\R$ is $L_{P_0}(x,y)=f(a,b)+f_x(a,b)(x-a)+f_y(a,b)(y-b)$, i.e. the plane spanned by\n$\\langle 1,0,f_x(a,b)\\rangle$ and $\\langle 0,1,f_y(a,b)\\rangle$ passing through $(a,b,f(a,b))$.\n\nIs identical to $\\begin{bmatrix}f_x(P_0)&f_y(P_0)\\end{bmatrix}\\begin{bmatrix}x-a\\\\y-b\\end{bmatrix}$. The matrix is the matrix of partial derivatives.\n\nSuch a function is differentiable if:\n\n\\[\\displaystyle \\lim_{(x,y)\\to(a,b)}\\frac{f(x,y)-\\left(f(a,b)+\\Big(\\begin{matrix} f_x(a,b)&f_y(a,b) \\end{matrix} \\Big)\\left(\\begin{matrix}x-a\\\\y-b\\\\ \\end{matrix} \\right) \\right)}{\\sqrt{(x-a)^2+(y-b)^2}}=0\\]\n\nNumerator is linear approximation and denominator is distance to point $(a,b)$. Thus:\n\n\\begin{mybox}{Differentiability}\n\\[f(x,y) \\mbox{ is differentiable at the point }P_0\\mbox{ if}\\displaystyle \\lim_{(x,y)\\to P_0}\\frac{|f(x,y)-L_{P_0}(x,y)|}{||(x,y)-P_0||}=0\\]\n\\end{mybox}\n\nGeometrically, if a circle about $P_0$ is drawn and radius is collapsed, distance between $f$ and approximating plane will become 0 much faster, so fraction becomes 0.\n\nIf there is a radius $\\delta > 0$ on the disk of radius $\\delta$ centered at $P_0$, $f_x(x,y)$ and $f_y(x,y)$ are continuous at every point on the disk, then $f(x,y)$ is continuous at every point on the disk.\nDifferentiability can not be established by the existence of partial derivatives at a point, it is sufficient to demonstrate continuous partials\nat a point.\n\nThe criteria for differentiability are that $f_x,f_y$ exist and $f$ is locally linear at $P_0$. The tangent plane exists here. However,\nit is sufficient to demonstrate differentiability by showing that both $f_x$ and $f_y$ are continuous on an open disk $D$ to conclude that $f(x,y)$\nis differentiable on $D$. Alternatively, the above limit definition can be used.\n\nIf a function $f:\\R^m\\to \\R^n$ exists, then it is made up of $n$ component functions on $\\R^m$. The Jacobian matrix is as follows:\n\n\\[Df\\left( x_1,\\ldots x_m\\right) =\\begin{bmatrix} \\nabla f_{1}\\left(x_1,\\ldots x_m\\right) \\\\ \\vdots \\\\ \\nabla f_{n}\\left(x_1,\\ldots x_m\\right) \\end{bmatrix}\\]\n\nThe number of rows $n$ depends on components (codomain) of the output space whereas the domain determines columns ($m$). Thus, linear approximation to a function $f:\\R^m\\to \\R^n$ at $P_0$ is\n\n\\[L_{P_0}(\\tb{x})=f(P_0)+\\Big(\\mbox{matrix of partial derivatives at}\\,P_0\\Big)(\\tb{x}-P_0)\\]\n\nIn parametric equations (paths), let $\\tb{c}(t)=\\big(x(t), y(t), z(t) \\big)$ have continuous partials.\nThus, the matrix of partials $D\\tb c(t)=\\begin{bmatrix}x'(t)\\\\y'(t)\\\\z'(t)\\end{bmatrix}$. Is the vertical velocity vector.\nIf the approximation $L_{t_0}(t)$ is found, it yields:\n\n\\begin{align*}\n    L_{t_0}(t)&=\\tb c(t_0)+\n    \\left(\n    \\begin{matrix}\n    x'(t_0)\\\\\n    y'(t_0)\\\\\n    z'(t_0)\\\\\n    \\end{matrix}\n    \\right)\n    (t-t_0)\\\\\n    &=\\tb{c} (t_0)+(t-t_0)\\tb c\\,'(t_0)\n\\end{align*}\n\nAlso, note that matrix of partials for a scalar valued function $f:\\R^n\\to \\R$ is simply the gradient; there is 1 row and $n$ columns in the gradient vector.\n\n\\section{Derivative Rules}\n\n\\begin{mybox}{General rules}\nIf $f,g:\\R^m\\to \\R^n$ are differentiable at $P_0\\in \\R^m$ for $c\\in \\R$:\n\\begin{itemize}\n    \\item $h(\\tb{x})=cf(\\tb{x})\\implies \\mathrm{D}h(P_0)=cDf(P_0)$\n    \\item $h(\\tb{x})=f(\\tb{x})+g(\\tb{x})\\implies \\mathrm{D}h(P_0)=\\mathrm{D}f(P_0)+\\mathrm{D}g(P_0)$ (domain = codomain; sum of two $n\\times m$ matrices)\n\\end{itemize}\n\nIf $f,g:\\R^n\\to \\R$ are differentiable at $P_0\\in \\R^n$:\n\\begin{itemize}\n    \\item $h(\\tb{x})=f(\\tb{x})g(\\tb{x})\\implies \\mathrm{D}h(P_0)=f(P_0)\\mathrm{D}g(P_0)+g(P_0)\\mathrm{D}f(P_0)$ (no commutativity as matrix times scalar DNE)\n\\end{itemize}\n\nIf $f,g:\\R^n\\to \\R$ are both differentiable at $P_0\\in \\R^n$ and $g(P_0)\\neq 0$:\n\\begin{itemize}\n    \\item $\\mathrm{D}\\left(\\frac{f}{g}\\right)(P_0)=\\frac{g(P_0)\\mathrm{D}f(P_0)-f(P_0)\\mathrm{D}g(P_0)}{g(P_0)^2}$\n\\end{itemize}\n\\end{mybox}\n\n\\subsection{Chain Rule}\n\n\\begin{mybox}{Chain rule}\nIf $g:\\R^m\\to \\R^p$ and $f:\\R^p\\to \\R^n$ and $g$ is differentiable at $P_0\\in \\R^m$ and the same for $f$ at $g(P_0)$:\n\\begin{itemize}\n    \\item $\\mathrm{D}\\Big(f\\circ g\\Big)(P_0)=\\mathrm{D}f\\big(g(P_0)\\big)\\mathrm{D}g(P_0)$\n\\end{itemize}\n\\end{mybox}\n\nThus, derivative of composites is a matrix product. $\\mathrm{D}f(g(P_0))\\to n\\times p$ and $\\mathrm{D}g(P_0)\\to p\\times m$\nso $\\mathrm{D}(f\\circ g)(P_0)\\to n\\times m$.\n\nIf $\\tb{c}:\\R\\to \\R^n$ is a path differentiable at $t_0\\in \\R$ and $f:\\R^n\\to \\R$ is differentiable at $\\tb{c}(t_0)$, then:\n\n\\[\\frac{d}{dt}f(\\tb{c}(t_0))=\\mathrm{D}f(\\tb{c}(t_0))D\\tb{c}(t_0)=\\left[ \\nabla f\\left( x_{1},x_{2},\\ldots x_{n}\\right) \\right]\\begin{bmatrix} \\vdots \\\\ \\tb{c}\\,'(t_0) \\\\ \\vdots \\end{bmatrix}=\\nabla f(\\tb{c}\\,'(t_0))\\cdot \\tb{c}\\,'(t_0)\\]\n\nThus, derivative of scalar valued function and path is dot product of gradient and velocity.\n\n\\section{Gradient}\n\n\\subsection{Directional Derivative}\n\nDirectional derivative of a scalar function $f:\\R^n\\to \\R$ at some $P_0\\in\\R^n$ in the direction of $\\tb{v}\\in\\R^n$ is given by\n\n\\[\\boxed{f_{\\tb{v}}\\left(P_{0}\\right)=\\nabla f\\left(P_{0}\\right) \\cdot \\frac{\\tb{v}}{\\|\\tb{v}\\|}}\\]\n\nMaximizing the directional derivative involves the dot product. Let $f:\\R^n\\to \\R$ and $P_0\\in\\R^n$ where $\\nabla f(P_0)$ is defined.\nAlso, let $\\tb{u}$ be a unit vector such that $f_{\\tb{u}}(P_0)$ is maximized. The directional derivative is\n\n\\[f_{\\tb u}(P_0)=\\nabla f(P_0)\\cdot \\tb u=\\|\\nabla f(P_0)\\|\\cos \\theta\\]\n\nSince $\\cos\\theta \\in [-1,1]$, the directional derivative is maximized at $\\cos\\theta = 1\\implies \\tb{u}||\\nabla f(P_0)||$.\n\n\\begin{mybox}{Gradient fact}\nThe gradient of a function at $P_0$ points in the direction of steepest ascent.\n\\end{mybox}\n\nFor a more general case given $f:\\R^n\\to \\R$ and $P_0\\in\\R^n$ where $\\nabla f_{\\tb{v}}(P_0)$ is maximized and $\\nabla f(P_0)$ exists:\n\\begin{align*}\n    \\nabla f_{\\tb{v}}(P_0)&=\\nabla f(P_0) \\cdot \\frac{\\tb{v}}{||\\tb{v}||}\\\\\n    &=\\nabla f(P_0) \\cdot \\frac{\\nabla f(P_0)}{||\\nabla f(P_0)||}\\\\\n    &=\\frac{\\nabla f(P_0)\\cdot \\nabla f(P_0)}{||\\nabla f(P_0)||}\\\\\n    &=||\\nabla f(P_0)||\n\\end{align*}\n\nThus, the length of the gradient vector tells how steep the ascent is in the direction of the steepest ascent.\n\n\\subsection{Gradient Fields}\n\nA image in the codomain $\\R^n$ where arrows originating at each point point in the steepest direction $\\forall\\; P\\in \\R^n$ where the partials exist.\nAre always perpendicular to level curves of $f$.\n\nLet $f:\\R^n\\to \\R$ and $P\\in \\R^n$ a point where partials of $f$ exist. Considering the level set $f(\\tb{x})=f(P)$,\nall values map to same codomain value as $P$. Also, let $\\tb{c}:\\R^n\\to \\R$ have an image entirely within this level set $f(\\tb{x})=f(P)$\nand $\\tb{c}(t_0)=P$. Then, the proof must show that $\\nabla f(P)\\cdot \\tb c\\,'(t_0)=0$.\n\nNote that since $h(t)=f(\\tb{c}(t))$, $h'(t_0)=\\nabla f \\Big(\\tb c (t_0) \\Big)\\cdot \\tb c\\,'(t_0)=\\nabla f (P)\\cdot  \\tb c\\,'(t_0)$.\nSince the image of $\\tb{c}(t)$ lies within $f(\\tb{x})=f(P)$, $f$ is constant on the image of $\\tb{c}$ (every point on $\\tb{c}$ maps to $f(P)$ under $f$).\nThus, $h(t)=f(\\tb{c}(t))\\implies h'(t)=0\\;\\forall\\;t$.\n\n\\subsection{Sphere}\n\nSphere is not a function as a point $P=(x,y)$ correspond to multiple $z$ values.\nCan be viewed as a level surface in $\\R^3$ for some $f:\\R^3\\to \\R$. The function is $f(x,y,z)=x^2+y^2+z^2$\nand the level surface sphere is $x^2+y^2+z^2=R^2$ where $R$ is the radius.\nGiven the point $(0,0,R)$, the gradient is upward along the $z$-axis. All curves passing through this point\nhave a tangent vector perpendicular to $\\nabla f(0,0,R)$ since gradients are perpendicular to level sets.\nIt can be said that any vector perpendicular to $\\nabla f(0,0,R)$ is a tangent to at least 1 curve in the sphere passing through $(0,0,R)$.\nThus, the perpendicular space to $\\nabla f(0,0,R)$ forms a plane of tangent vectors at $(0,0,R)$ and is a tangent plane.\nAn expression for the tangent plane is \n\n\\begin{align*}\n    \\nabla f (0,0,R)\\cdot(x-0, y-0, z-R)&=0\\\\\n    f_x(0,0,R)x+f_y(0,0,R)y+f_z(0,0,R)&=0\\\\\n    2(0)x+2(0)y+2(R)(z-R)&=0\\\\\n    2Rz-2R^2&=0\\\\\n    z&=R\\\\\n\\end{align*}\n\nExpression for the tangent plane to a level set of some $f:\\R^3\\to \\R$:\n\n\\begin{align*}\n    \\nabla f (P_0)\\cdot(x-x_0, y-y_0,z- z_0)&=0\\\\\n    f_x(P_0)(x-x_0)+f_y(P_0)(y-y_0)+f_z(P_0)(z-z_0)&=0\\\\\n    f_x(P_0)x+f_y(P_0)y+f_z(P_0)z&=\\nabla f(P_0)\\cdot P_0\\\\\n\\end{align*}\n$$\\boxed{f_x(P_0)x+f_y(P_0)y+f_z(P_0)z=\\nabla f(P_0)\\cdot P_0}$$\n\n\\section{Implicit Function Theorem}\n\n\\subsection{Single variable}\n\nIs the explanation behind single-variable implicit differentiation.\nIf $F:\\R^2\\to \\R$ is of class $C^1$ and there is a point $\\tb{x}_0=(a,b)\\in\\R^2$ such that \n$F(a,b)=0$ and $F_y(a,b)\\neq 0$, then it is guaranteed that\n\\begin{itemize}\n    \\item There is some small $\\delta>0$ and some small $\\epsilon>0$ so that for $(x,y)\\in\\R^2$ with $|x-a|<\\delta$ and $|y-b|<\\epsilon$ there is a unique function $g:\\R\\to\\R$ satisfying\n    $F(x,g(x))=0$ and any point on the level set $F(x,y)=0$ satisfying these 2 conditions on coordinates will have property $y=g(x)$. To summarize, near the point $(a,b)$ points on $F(x,y)=0$ lie on the graph of a unique function $y=g(x)$.\n    \\item $g$ is of class $C^1$; differentiable so $g'(x)$ is continuous and $g'(x)=-\\frac{F_x}{F_y}$\n\\end{itemize}\n\n\\begin{center}\n    \\includegraphics[scale=0.4]{figures/Screen Shot 2021-05-10 at 7.08.59 AM.png}\n\\end{center}\n\n\\begin{mybox}{Special case} \n    Given that $F:\\R^{n+1}\\to \\R$ has continuous partials, let $(\\tb x, z)$ denote the points in $\\R^{n+1}$\n    where $\\tb x\\in \\R^n$ and $z\\in \\R$. Assume that $(\\tb x_0,z_0)$ satisfies\n\n    \\[F(\\tb x_0,z)=0\\;\\text{and}\\;\\frac{\\partial F}{\\partial z}(\\tb x_0,z)\\neq 0\\]\n\n    Then, $\\tb x_0$ and $z_0$ are contained in a neighborhood such that there exists a unique $z=g(\\tb x)$ defined for $\\tb x$ and $z$ in these neighborhoods such that\n\n    \\[F(\\tb x, g(\\tb x))=0\\]\n\n    It can also be said that $z=g(\\tb x)$ is continuously differentiable with derivative \n\n    \\[\\mathbf{D} g(\\mathbf{x})=-\\left.\\frac{1}{\\frac{\\partial F}{\\partial z}(\\mathbf{x}, z)} \\mathbf{D}_{\\mathbf{x}} F(\\mathbf{x}, z)\\right|_{z=g(\\mathbf{x})}\\]\n\n    $\\tb D_{\\tb x}F$ denotes the partial of $F$ with respect to $\\tb x$ so that $\\mathbf{D}_{\\mathbf{x}} F=\\left[\\partial F / \\partial x_{1}, \\ldots, \\partial F / \\partial x_{n}\\right]$.\n    Thus, \n\n    \\[\\frac{\\partial g}{\\partial x_{i}}=-\\frac{\\partial F / \\partial x_{i}}{\\partial F / \\partial z}, \\quad i=1, \\ldots, n\\]\n\\end{mybox}\n\n\\subsection{Multivariable definition}\n\nIf $F:\\R^3\\to \\R$ is of class $C^1$ and there exists $\\tb{x}_0=(a,b,c)\\in\\R^3$ such that\n$F(a,b,c)=0$ and $F_z(a,b,c)\\neq 0$ then is is guaranteed that\n\\begin{itemize}\n    \\item There is some small $\\delta > 0$ and $\\epsilon > 0$ so that for $(x,y,z)\\in\\R^3$ with $\\sqrt{(x-a)^2+(y-b)^2}<\\delta$ and $|z-c|<\\epsilon$ there is a unique function $g:\\R^2\\to\\R$\n    that satisfies $F(x,y,g(x,y))=0$ and any point satisfying these inequalities on $x,y,z$-coordinates that lies on $F(x,y,z)=0$ will have the property $z=g(x,y)$, so near the point $(a,b,c)$ on the level set $F(x,y,z)=0$ points can be seen as lying on $z=g(x,y)$.\n    \\item $g$ is of class $C^1$ so it is differentiable and both partials exist and are continuous, and $g_x(x,y)=-\\frac{F_x}{F_z},g_y(x,y)=-\\frac{F_y}{F_z}$.\n\\end{itemize}\n\nThe IFT can justify the existence of a tangent plane to a surface.\n\nLet $F:\\R^3\\to \\R$ be of class $C^1$ and the surface $S=\\{(x,y,z)\\in\\R\\;|\\;F(x,y,z)=c\\}$ for some $c\\in\\R$ be the level set of $F$.\nThe tangent plane is given by $F_x(P)x+F_y(P)y+F_z(P)z=\\nabla F(P)\\cdot \\tb P$ for $P=(x_0,y_0,z_0)$. The plane is not defined when\n$\\nabla F(P)=\\tb 0$. \n\nApplying the IFT, this plane is tangent to $S$. If $\\nabla F(P)\\neq \\tb 0$ then at least one of $F_x,F_y,F_z\\neq 0$ at $P$.\nWithout loss of generality, let $F_z\\neq 0$. Then, let $f(x,y,z)=F(x,y,z)-c$. Since $f_z(P)=F_z(P)\\neq 0$, applying the IFT to $f$ makes the conclusion that \nnear $P$ $z$ is a differentiable function of $x,y$ so that there is a unique function $g:\\R^2\\to \\R$ such that $z=g(x,y)$. The tangent plane to $g$ at $P$ is \n\\begin{align*}\n    z &=g\\left(x_{0}, y_{0}\\right)+g_{x}\\left(x_{0}, y_{0}\\right)\\left(x-x_{0}\\right)+g_{y}\\left(x_{0}, y_{0}\\right)\\left(y-y_{0}\\right) \\\\\n    &=z_{0}+g_{x}\\left(x_{0}, y_{0}\\right)\\left(x-x_{0}\\right)+g_{v}\\left(x_{0}, y_{0}\\right)\\left(y-y_{0}\\right)\n\\end{align*}\n\nIt can then be shown that this plane is the same as given by the gradient approximation:\n\nIt follows that $f_x(P)=F_x(P)$ and $f_y(P)=F_y(P)$. Then,\n\n\\begin{align*}\n    z&=z_0+g_x(x_0,y_0)(x-x_0)+g_y(x_0,y_0)(y-y_0)\\\\\n    z&=z_0-\\frac{F_x(P)}{F_z(P)}(x-x_0)-\\frac{F_y(P)}{F_z(P)}(y-y_0)\\\\\n    F_z(P)z&=F_z(P)z_0-F_x(P)x+F_x(P)x_0-F_y(P)y+F_yy_0\\\\\n    F_x(P)x+F_y(P)y+F_z(P)z&=F_z(P)z_0+F_x(P)x_0+F_y(P)y_0\\\\\n    F_x(P)x+F_y(P)y+F_z(P)z&=\\nabla F(P)\\cdot P\n\\end{align*}\n\n\\begin{mybox}{General implicit theorem}\n    If $\\mathrm{det}(A)\\neq 0$ where $A$ is the $m\\times m$ matrix \n\n    \\[\n        \\left[\\begin{array}{ccc}\n            \\frac{\\partial F_{1}}{\\partial z_{1}} & \\cdots & \\frac{\\partial F_{1}}{\\partial z_{m}} \\\\\n            \\vdots & \\vdots \\\\\n            \\frac{\\partial F_{m}}{\\partial z_{1}} & \\cdots & \\frac{\\partial F_{m}}{\\partial z_{m}}\n        \\end{array}\\right]\n    \\]\n\n    then near the point $(\\tb x_0,\\tb z_0)$, the following system \n\n    \\[\\begin{array}{c}\n        F_{1}\\left(x_{1}, \\ldots, x_{n}, z_{1}, \\ldots, z_{m}\\right)=0 \\\\\n        F_{2}\\left(x_{1}, \\ldots, x_{n}, z_{1}, \\ldots, z_{m}\\right)=0 \\\\\n        \\vdots \\\\\n        F_{m}\\left(x_{1}, \\ldots, x_{n}, z_{1}, \\ldots, z_{m}\\right)=0 .\n    \\end{array}\\]\n\n    defines smooth and unique functions such that \n\n    \\[z_{i}=k_{i}\\left(x_{1}, \\ldots, x_{n}\\right) \\quad(i=1, \\ldots, m)\\]\n\n    where the derivatives are calculared with implicit differentiation.\n\\end{mybox}\n\n\\subsection{IFT for vector-valued functions}\n\nLet $F:\\R^{m+n}\\to \\R^n$ be of class $C^1$, then \n\\[F(x_1, x_2, x_3,...,x_m, z_1, z_2, ..., z_n)=\\Big(F_1(\\mbox{input vector}), F_2(\\mbox{input vector}), F_3(\\mbox{input vector}),...,F_n(\\mbox{input vector})\\Big)\\]\n\nThe inputs to $F$ are the $m$-dimensional vector $\\tb x_0=(x_1,x_2,\\ldots,x_m)$ and the $n$-dimensional vector $\\tb z_0=(z_1,z_2,\\ldots, z_n)$.\nThe conditions for IFT are met when\n\\begin{itemize}\n    \\item $F(\\tb x_0,\\tb z_0)=\\tb 0$\n    \\item $\\mbox{Det}\\left(\n        \\begin{matrix}\n        \\frac{\\partial F_1}{\\partial z_1}&\\dots&\\frac{\\partial F_1}{\\partial z_n}\\\\\n        \\vdots&\\ddots&\\vdots\\\\\n        \\frac{\\partial F_n}{\\partial z_1}&\\dots&\\frac{\\partial F_n}{\\partial z_n}\n        \\end{matrix}\n        \\right)\\neq 0$\n\\end{itemize}\n\nThen there is a unique $C^1$ function $g:\\R^m\\to \\R^n$ such that for all points satisfying $F(\\tb v)=\\tb 0$ that are sufficiently near $P=(\\tb x_0,\\tb z_0)$ we can conclude $\\tb z=g(\\tb x)$.\n\n\\begin{mybox}{Inverse function theorem}\n    This case is in the attempt to solve the system \n\n    \\[\\left.\\begin{array}{c}\n        f_{1}\\left(x_{1}, \\ldots, x_{n}\\right)=y_{1} \\\\\n        \\ldots \\\\\n        f_{n}\\left(x_{1}, \\ldots, x_{n}\\right)=y_{n}\n    \\end{array}\\right\\}\\]\n\n    Solving this is the same as inverting the equations of this system.\n    The condition is that in a neighborhood of some $\\tb x_0$, $\\mathrm{det}(A)\\neq 0$\n    where $A$ is the determinant of $\\tb Df(\\tb x_0)$ and $f=(f_1,\\ldots,f_n)$. $\\mathrm{det}(A)$\n    (the Jacobian determinant) is given by \n\n    \\[\\left.\\frac{\\partial\\left(f_{1}, \\ldots, f_{n}\\right)}{\\partial\\left(x_{1}, \\ldots, x_{n}\\right)}\\right|_{\\mathbf{x}=\\mathbf{x}_{0}}=J(f)\\left(\\mathbf{x}_{0}\\right)=\\left|\\begin{array}{ccc}\n        \\frac{\\partial f_{1}}{\\partial x_{1}}\\left(\\mathbf{x}_{0}\\right) & \\cdots & \\frac{\\partial f_{1}}{\\partial x_{n}}\\left(\\mathbf{x}_{0}\\right) \\\\\n        \\vdots & & \\vdots \\\\\n        \\frac{\\partial f_{n}}{\\partial x_{1}}\\left(\\mathbf{x}_{0}\\right) & \\cdots & \\frac{\\partial f_{n}}{\\partial x_{n}}\\left(\\mathbf{x}_{0}\\right)\n    \\end{array}\\right|\\]\n\n    If this determinant is not 0, then the system can be solved for $\\tb x=g(\\tb y)$ for $\\tb x$ near $\\tb x_0$ and $\\tb y$ near $\\tb y_0$ and $g$ has continuous partials.\n\\end{mybox}\n\nThis is reasonable because a linear approximation acts in an invertible way locally, so both the derivative and function can be said to be invertible.\n\n\\subsection{Example problem}\n\nGiven a nonlinear system of equations:\n\\begin{align*}\n    xu+yvu^2&=2\\\\\n    xu^3+y^2v^4&=2\\\\\n\\end{align*}\n\nImplicit differentiation is done by treating $u$ and $v$ as functions of $x,y$. In this case,\ncan find how a small change in $x$ affects $u$ when all variables are 1 (i.e. $(x,y,u,v)=(1,1,1,1)$)).\nFirst equation differentiation gives \n\\begin{align*}\n    \\frac{\\partial }{\\partial x}\\Big(xu+yvu^2\\Big)&=\\frac{\\partial }{\\partial x}\n    \\Big(2\\Big)\\\\\n    u+x\\frac{\\partial u}{\\partial x}+yv\\left(2u\\frac{\\partial u}{\\partial x}\\right)+yu^2\\frac{\\partial v}{\\partial x}&=0\\\\\n    (x+2uvy)\\frac{\\partial u}{\\partial x}+yu^2\\frac{\\partial v}{\\partial x}&=-u\n\\end{align*}\n\nSecond equation gives \n\\begin{align*}\n    \\frac{\\partial }{\\partial x}\\Big(xu^3+y^2v^4\\Big)&=\\frac{\\partial}{\\partial x}(2)\\\\\n    x\\Big(3u^2\\frac{\\partial u}{\\partial x}\\Big)+u^3+y^24v^3\\frac{\\partial v}{\\partial x}&=0\\\\\n    3xu^2\\frac{\\partial u}{\\partial x}+y^24v^3\\frac{\\partial v}{\\partial x}&=-u^3\\\\\n\\end{align*}\n\nPlugging in $(1,1,1,1)$ gives \n\\begin{align*}\n    3u_x+v_x&=-1\\\\\n    3u_x+4v_x&=-1\\\\\n\\end{align*}\n\nThus, $u_x=-\\frac{1}{3}$. In this problem, $F$ is defined as $F(x,y,u,v)=(xu+yvu^2-2,xu^3+y^2v^4-2)$. Or,\n\\begin{align*}\n    F_1(x,y,u,v)&=xu+yvu^2-2\\\\\n    F_2(x,y,u,v)&=xu^3+y^2v^4-2\n\\end{align*}\n\nThe matrix to be checked for the condition is \n\\[\n    \\begin{bmatrix}\n    \\frac{\\partial F_1}{\\partial u}&\\frac{\\partial F_1}{\\partial v}\\\\\n    \\frac{\\partial F_2}{\\partial u}&\\frac{\\partial F_2}{\\partial v}\\\\\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n    x+2yvu&yu^2\\\\\n    3xu^2&4y^2v^3\\\\\n    \\end{bmatrix}\n    \\implies \n    \\begin{bmatrix}\n        3&1\\\\\n        3&4\n    \\end{bmatrix}\n\\]\n\nSince the determinant is 9, the IFT application is valid.", "meta": {"hexsha": "4dceea4f69c0ef0f9b3ed6cdf06b0f9d3e89d544", "size": 23320, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multivariable-calculus/tex/unit-3.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multivariable-calculus/tex/unit-3.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multivariable-calculus/tex/unit-3.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.9915966387, "max_line_length": 265, "alphanum_fraction": 0.6348627787, "num_tokens": 9017, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8705972734445508, "lm_q1q2_score": 0.7056007280726979}}
{"text": "\\chapter{Matrix Group}\r\n\\section{Linear Groups}\r\n\r\n\\begin{defn}[normal subgroup]\r\nA \\textbf{normal subgroup} $N$ of a given group $G$ is a subgroup which left and right cosets $gN$ and $Ng$ are the same: $gN = Ng$, i.e., $$gNg^{-1} = N$$ for every $g\\in G.$ We denote it as $N \\triangleleft G$.\r\n\\end{defn}\r\n\\begin{prop}[why normal?] The quotient group $G/N$ (read $G$ mod $N$) is well-defined if and only if $N$ is normal of G.\r\n\\end{prop}\r\n\\begin{proof}\r\nWhatever we take, the equivalence class must be the same. If $N$ is normal and letting $x\\sim \\tilde x$, i.e., $x^{-1}\\tilde x \\in N$, $$\\tilde xN \\subseteq (xN)N = xN$$ and \\textit{vice versa}. If $\\bar x = \\bar{\\tilde x} $ if $x\\sim \\tilde x$ and $\\overline{xy} = \\bar x \\bar y,$ we have $$gN = (1g)N = NgN = hNgN = (hg)N$$ for every $h\\in N$, hence $N = g^{-1} hgN$ so that $N$ is normal: letting $n = g^{-1}hg\\tilde{n}$, we have $g^{-1}hg=n\\tilde{n}^{-1}\\in N$ for every $h\\in N$ whence $g^{-1}Ng \\subseteq N.$\r\n\\end{proof}\r\n\\begin{defn}[general linear group and special linear group] The \\textbf{general linear group} of a given vector space $V$ is a (multiplicative) group of automorphism on $V$; that is, $\\operatorname{GL}(V) = \\mathfrak L(V,V)^\\times.$ And the \\textbf{special linear group} of $V$ is the subgroup of $\\operatorname{GL}(V)$ which is consisted by linear transformations whose determinant are all 1.\r\n\r\nWe denote $\\operatorname{GL}(n, F) = \\operatorname{GL}(F^n),$ and $\\operatorname{SL}(n, F) = \\operatorname{SL}(F^n).$\r\n\\end{defn}\r\n\\begin{theorem}[first isomorphism theorem]\r\nFor any homomorphism $\\varphi:~G\\to H$ for two groups $G$ and $H$, $$G/\\ker \\varphi \\approx \\operatorname{im} \\varphi.$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n\\hfill\r\n\\begin{center}\r\n\\leavevmode\r\n\\xy\r\n\\xymatrix {\r\nG \\ar@{->}[rr]^{\\varphi} \\ar@{->}[dr] &&\\operatorname{im}\\varphi\\\\ & G/\\operatorname{ker}\\varphi \\ar@{->}[ur]_{\\approx} &\\\\\r\n}\r\n\\endxy\r\n\\end{center}\r\n\\end{proof}\r\n\\begin{prop}[GL and SL] $$\\operatorname{GL}(V)/\\operatorname{SL}(V) \\approx F^\\times.$$\r\n\\end{prop}\r\n\r\n\\begin{defn}[center] The \\textbf{center} $Z(G)$ of a group $G$ is the subgroup of elements which satisfy the `commutative law', i.e., $$Z(G) = \\{z\\in G: \\quad zg = gz \\textrm{ for every }g\\in G\\}.$$ $Z$ for \\textit{zentrum}, which means `center' in German.\r\n\\end{defn}\r\n\\begin{prop}[normality of the center]\r\n$$Z(G)\\triangleleft G.$$\r\n\\end{prop}\r\n\\begin{proof}\r\nTrivially, $$gZ(G) = \\{gz:~z\\in Z(G)\\} = \\{zg:~z \\in Z(G)\\} = Z(G)g.$$\r\n\\end{proof}\r\n\\begin{ex}\r\nWhat are the centers of (a) $\\operatorname{GL}(n, F)$ and (b) $\\operatorname{SL}(n, F)$?\r\n\r\nAnswer: (a) $0\\ne cI$'s, (b) $\\alpha I$'s where $\\alpha^n = 1.$\r\n\\end{ex}\r\n\\begin{proof}\r\n(a) is just all. Let $AZ = ZA$ for all invertible $A.$ Then, especially, for all \\textit{elementary matrices}, $EZ = ZE.$ Note that multiplying $E$ left is the same with elementary \\textit{row} operating, while multiplying right is for elementary \\textit{column} operating. (Especially, for $E_{i + cj}$'s.) Hence we obtain that $Z$ is diagonal. Instead a more detailed explanation, we see an example: $$\r\n\\begin{pmatrix}\r\n1 & 3 \\\\\r\n0 & 1\r\n\\end{pmatrix}\r\n\\begin{pmatrix}\r\na & *_1 \\\\\r\n*_2 & b\r\n\\end{pmatrix}\r\n=\r\n\\begin{pmatrix}\r\na + 3*_2 & *_1 + 3b \\\\\r\n*_2 & b\r\n\\end{pmatrix},$$\r\n$$\\begin{pmatrix}\r\na & *_1 \\\\\r\n*_2 & b\r\n\\end{pmatrix}\r\n\\begin{pmatrix}\r\n1 & 3 \\\\\r\n0 & 1\r\n\\end{pmatrix}\r\n=\r\n\\begin{pmatrix}\r\na  & *_1 + 3a \\\\\r\n*_2 & b + 3*_2\r\n\\end{pmatrix},$$\r\nhence $*_1$ and $*_2$ are zero. Similar details says that $Z$ must be diagonal, for bigger matrices.\r\n\r\nNow, the proof is done: since $E_{i\\leftrightarrow j}$ is an elementary matrix, $Z_{ii} = Z_{jj}$, for every $i$ and $j$ pair. Therefore $Z$ is a `nonzero'(since $Z$ is invertible!) multiple of $I.$\r\n\r\nNot so surprisingly, the proof works on any \\textit{ring} with 1; if we modify `nonzero' to `invertible', that is, $c\\in R^{\\times}.$\r\n\\end{proof}\r\n\\begin{add}[divide by center?] Dividing by center means to ignore the difference due to the elements of $Z.$ Since $$Z(G) = \\{z\\in G:\\quad z = gzg^{-1}\\textrm{ for every }g\\in G\\},$$ we have some `morphisms' $\\varphi_g:~a \\mapsto b = gzg^{-1}$ and \\textit{their group} $$\\operatorname{Inn}(G) = \\{ \\varphi_g:\\quad g \\in G\\}.$$ We call this group the \\textbf{inner automorphism group} of $G$.\r\n\r\nWe want to show that $G/Z(G) \\approx \\operatorname{Inn}(G).$ The idea is easy: use the homomorphism $\\varphi_\\bullet$ above: $$\\varphi_\\bullet:\\quad G \\to \\operatorname{Inn}(G).$$ The kernel of this homomorphism is just the center of $G$, since the (multiplicational) identity of $\\operatorname{Inn}(G)$ is the identity function $\\operatorname{id}_G$ and, from $$\\varphi_z = z\\bullet z^{-1} = \\operatorname{id}_G, \\qquad \\forall g\\in G,$$i.e., $$\\varphi_z (g) = zgz^{-1} = g, \\qquad \\forall g\\in G,$$ we get $zg = gz$ whence $z \\in Z(G).$ Therefore $\\ker (\\varphi_\\bullet) = Z(G)$, and by the first isomorphism theorem, we obtain $$G/Z(G) \\approx \\operatorname{Inn}(G).$$\r\n\\end{add}\r\n\r\n\\begin{defn}[PGL and PSL]\r\nThe \\textbf{projective general linear group} is defined by $$\\operatorname{PGL}(V) = \\operatorname{GL}(V)/Z(\\operatorname{GL}(V)).$$\r\nThe \\textbf{projective special linear group} is defined by $$\\operatorname{PSL}(V) = \\operatorname{SL}(V)/Z(\\operatorname{SL}(V)).$$\r\n\\end{defn}\r\n\r\nProjective geometry is difficult...\r\n\r\n\\section{Orthogonal group}\r\n\\begin{defn}[orthogonal transformation]\r\nFor an \\textit{inner product space} $(V,~\\langle \\bullet , \\bullet \\rangle)$ (or even just a quadratic space with non-degenerate symmetric bilinear form), an \\textbf{orthogonal transformation} of $V$ is an invertible linear transformation which preserves the given inner product, that is, such $A\\in \\operatorname{GL}(V)$: $$\\langle v, ~w \\rangle = \\langle Av,~ Aw \\rangle.$$ The group of such transformations is called the \\textbf{orthogonal group} $\\operatorname{O}(V)$ of $V$, and also denote $\\operatorname{O}(n, F) = \\operatorname{O}(F^n)$ and $\\mathrm O(n) = \\mathrm O(n, \\mathbb R)$. $F^n$ is considered with \\textit{dot product.}\r\n\r\nSimilarly, $\\operatorname{SO}(V) = \\{T\\in \\operatorname{O}(V):~ \\operatorname{det}T = 1\\}$, and analogous definitions for $\\operatorname{SO}(n,F)$ and $\\operatorname{SO}(n).$ Obviously, it is called the \\textbf{special orthogonal group} of $V$.\r\n\\end{defn}\r\n\\begin{defn}[unitary group]\r\nIf we give a \\textit{hermitian form} $(V, ~ \\langle \\bullet, \\bullet \\rangle )$ rather than an inner product, where the given field is `trivially' the field $\\mathbb C$ of complex number, we define analogously \\textbf{unitary group} $\\operatorname{U}(n)$ as we defined the orthogonal group:$$\\langle v, ~w \\rangle = \\langle Av,~ Aw \\rangle, \\qquad A \\in \\operatorname{GL}(n,~\\mathbb C).$$ We \\textit{already know} what is $\\operatorname{SU}(n)$ and how to call it \\textsf{:D}.\r\n\\end{defn}\r\n\r\n\\begin{prop}\r\n\\hfill\r\n\\begin{itemize}\r\n    \\item $\\operatorname{SO}(V) \\triangleleft\\operatorname{O}(V) \\triangleleft \\operatorname{GL}(V);$\r\n    \\item $\\operatorname{SO}(V) \\triangleleft\\operatorname{SL}(V) \\triangleleft \\operatorname{GL}(V);$\r\n    \\item $\\operatorname{O}(n, F) = \\{ A\\in \\mathfrak M_{n,n}(F)^\\times:~ A^{-1}=A^\\mathsf T\\},$ if the inner product is a standard one, so-called \\textit{dot product}. (\\textit{Canonically isomorphic!})\r\n\\end{itemize}\r\nAlso the followings hold: for $\\operatorname{O}(n, F)$,  every element is a matrix with pairwise orthonormal columns (or rows).\r\n\\end{prop}\r\nGood, well, why it is called `orthogonal'? It is because these preserves the `angle' of two vectors, especially the \\textit{orthogonality}. Then, \\textit{what} is orthogonal? Which matrices are orthogonal?\r\n\\begin{prop}\r\n\\hfill\r\n\r\nIn $\\mathbb R^2$, $\\operatorname{O}(2)$ consists of rotations and reflections. And the group of rotations is just $\\operatorname{SO}(2).$\r\n\\begin{proof}From\r\n$$A=\\begin{pmatrix}a&b\\\\c&d\\end{pmatrix}, \\qquad AA^\\mathsf T = \\begin{pmatrix}a&b\\\\c&d\\end{pmatrix}\\begin{pmatrix}a&c\\\\b&d\\end{pmatrix} = \\begin{pmatrix}a^2+b^2&ac+bd\\\\ac+bd&c^2+d^2\\end{pmatrix} = I,$$\r\nwe obtain $a^2 + b^2 = 1 = c^2 + d^2$ and $ac+bd = 0$. Solutions for the first equality are just sines and cosines, namely: $$a = \\cos x, ~~b = \\sin x, \\quad c = \\cos y,~~d = \\sin y.$$ (Orders of sine and cosine do not have to consider; since there is an inversion $\\theta~\\mapsto~\\frac \\pi 2 - \\theta$.) Evaluating to another equality, $$\\cos x \\cos y + \\sin x \\sin y = \\cos(y-x) = 0,\\qquad y-x = \\frac{2k-1}{2}\\pi.$$ Hence $y = x + \\frac{2k-1}{2}\\pi.$ Substituting it, we get $$c = - \\sin x \\sin \\left(\\frac{2k-1}{2}\\pi\\right) = \\mp \\sin x,\\qquad d = \\cos x \\sin \\left(\\frac{2k-1}{2}\\pi\\right) = \\pm \\cos x.$$ Due to a \\textit{custom} in math and other sciences, we use $\\theta = -x$ and finally get $$A=\\begin{pmatrix}\\cos \\theta &-\\sin \\theta \\\\ \\pm \\sin \\theta & \\pm \\cos \\theta \\end{pmatrix}.$$\r\n\r\nIf the signa of second row are pluses, $$A_+ = \\begin{pmatrix}\\cos \\theta &-\\sin \\theta \\\\\\sin \\theta & \\cos \\theta \\end{pmatrix} = R_\\theta,$$ where $R_\\theta$ is the \\textbf{rotation matrix} of angle $\\theta$. Since $ \\operatorname{det}R_\\theta = 1$, $R_\\theta \\in \\operatorname{SO}(2).$\r\n\r\nIf the signa of second row are minuses, $$A_- = \\begin{pmatrix}\\cos \\theta &-\\sin \\theta \\\\-\\sin \\theta & -\\cos \\theta \\end{pmatrix}  = \\begin{pmatrix}1&0\\\\0&-1\\end{pmatrix} \\begin{pmatrix}\\cos \\theta &-\\sin \\theta \\\\\\sin \\theta & \\cos \\theta \\end{pmatrix} =\\begin{pmatrix}1&0\\\\0&-1\\end{pmatrix} R_\\theta = S_{-\\theta/2},$$ where $S_\\varphi$ is a \\textbf{reflection matrix} w.r.t. a line $\\theta = \\varphi$ in polar coordinate system. (Draw it $\\sim \\!.$) Note that $\\operatorname{det}S_\\varphi = -1$.\r\n\\end{proof}\r\n\\end{prop}\r\n\r\nHow about 3-dimensional space? We consider a rotation on a line, the \\textit{axis}. For example, there are `basic' three rotations: $$\\displaystyle {\\begin{alignedat}{1}R_{x}(\\theta )&={\\begin{pmatrix}1&0&0\\\\0&\\cos \\theta &-\\sin \\theta \\\\[3pt]0&\\sin \\theta &\\cos \\theta \\\\[3pt]\\end{pmatrix},}\\\\[6pt]R_{y}(\\theta )&={\\begin{pmatrix}\\cos \\theta &0&\\sin \\theta \\\\[3pt]0&1&0\\\\[3pt]-\\sin \\theta &0&\\cos \\theta \\\\\\end{pmatrix},}\\\\[6pt]R_{z}(\\theta )&={\\begin{pmatrix}\\cos \\theta &-\\sin \\theta &0\\\\[3pt]\\sin \\theta &\\cos \\theta &0\\\\[3pt]0&0&1\\\\\\end{pmatrix}.}\\end{alignedat}}$$ Surprisingly, they are almost \\textit{all}, i.e., the following holds. (Details are omitted.)\r\n\r\n\\begin{theorem}[decomposition of rotation]\r\nFor every `rotation' $R\\in\\operatorname{SO}(3)$,\r\n$$R=R_{z}(\\alpha )\\,R_{y}(\\beta )\\,R_{x}(\\gamma )\\,$$\r\n where \\textit{Tait-Bryan angles} of $R$ are $\\alpha$, $\\beta$, $\\gamma$, about axes $z$, $y$, $x$ respectively.\r\n\\end{theorem}\r\n\r\nFollowing our knowledge, there efinition for \\textit{arbitrary rotation} is quite obvious, and only acceptable:\r\n\r\n\\begin{defn}[rotation] \\textbf{Rotation} is an element of SO.\\end{defn}\r\n\r\nWe must figure out the following definitions.\r\n\\begin{defn}[PGO, PSO, PGU, PSU]Projective (general) orthogonal group $\\operatorname{PGO}(V)$ and projective special orthogonal group $\\operatorname{PSO}(V).$ Similarly for U's...\r\n\\end{defn}\r\n\\begin{ex}\r\nCalculate them! What is $Z(\\operatorname{O}(V))$ and $Z(\\operatorname{SO}(V))$?\r\n\\end{ex}\r\n\\begin{proof}\r\nSame with \\textbf{Example 1.1.} A difference is that $\\det Z = \\pm 1$ in $\\operatorname{O}(V).$ Another one is for $\\operatorname{SO}$: for odd-dimensional $V$, $Z(\\operatorname{SO}(V))=\\{I\\}$ (a trivial group) since $\\operatorname{det}\\pm I = \\pm 1$; while $Z(\\operatorname{SO}(V))=\\{\\pm I\\}$ for even-dimensional $V$ since $\\operatorname{det}\\pm I = 1.$\r\n\\end{proof}\r\n\\begin{coro}\r\n\\emph{PSO $\\approx$ SO} for odd-dimensional vector space $V$.\r\n\\end{coro}\r\n\\begin{prop}\r\n$$\\operatorname{PSU}(2)\\approx \\operatorname{SO}(3), \\qquad \\operatorname{SU}(2) \\dhxrightarrow{\\text{double}} \\operatorname{SO}(3),$$ where $\\dhxrightarrow{\\text{double}}$ means that there is a double covering.\r\n\\end{prop}\r\n\r\n``The shortest path between two truths in the real domain passes through the complex domain.'' ---Jacques Hadamard.\r\n\r\n\\begin{proof}\r\n$Z(\\operatorname{SU}(2)) = \\{\\pm I\\}$? Trivial. Then it suffices to show that $\\operatorname{PSU}(2)\\approx \\operatorname{SO}(3)$. A transformation $A$ of $\\operatorname{PSU}(2)$ satisfies \\textsf{(U)} $AA^\\dagger = I$ by the definition. Use same method as \\textbf{Proposition 1.5.}: let $$A=\\begin{pmatrix}a&b\\\\c&d\\end{pmatrix},$$ then $$AA^\\dagger = \\begin{pmatrix}a&b\\\\c&d\\end{pmatrix}\\begin{pmatrix}\\bar a&\\bar c\\\\\\bar b&\\bar d\\end{pmatrix} = \\begin{pmatrix}a\\bar a+b\\bar b&a\\bar c+b\\bar d\\\\\\bar a c+\\bar b d&c\\bar c + d\\bar d\\end{pmatrix}=I$$ whence $$|a|^2 + |b|^2 = 1 = |c|^2 + |d|^2, \\qquad a\\bar c + b\\bar d = 0.$$ The first equality gives us $$a = e^{i\\varphi_1}\\cos x,~~b = e^{i\\varphi_2}\\sin x,~~c = e^{i\\varphi_3}\\cos y,~~d = e^{i\\varphi_4}\\sin y,$$ and the second equality gives $$\\cos x \\cos y + e^{i(-\\varphi_1+\\varphi_2+\\varphi_3-\\varphi_4)}\\sin x \\sin y = 0,$$ since $\\overline{e^{i\\theta}} = e^{-i\\theta}$ for real $\\theta$. If $-\\varphi_1+\\varphi_2+\\varphi_3-\\varphi_4 \\ne 0,$ the equality must not hold unless $b=d=0$, which leads to a contradiction. Also, since \\textsf{(S)} $\\operatorname{det}A = 1$, $$ad-bc = e^{i(\\varphi_1 + \\varphi_4)}(\\cos x \\sin y - \\sin x \\cos y) = e^{i(\\varphi_1 + \\varphi_4)} \\sin(y-x) = 1$$ whence $\\varphi_1 + \\varphi_4 =\\varphi_2 + \\varphi_3 = k\\pi$ and $y-x = \\frac{2k-1}{2} \\pi.$ Therefore $$A = \\begin{pmatrix}e^{i\\varphi_1}\\cos x&e^{i\\varphi_2}\\sin x \\\\ \\mp e^{- i\\varphi_2}\\sin x&\\pm e^{-i\\varphi_1}\\cos x \\end{pmatrix}.$$ Finally, \\textsf{(P)} ignore one signum of them, then we have $$A = \\begin{pmatrix}e^{i\\varphi_1}\\cos \\theta & - e^{i\\varphi_2}\\sin \\theta \\\\  e^{- i\\varphi_2}\\sin \\theta& e^{-i\\varphi_1}\\cos \\theta \\end{pmatrix}.$$ Hence, for example, there is an `isomorphism' $$\\begin{pmatrix}e^{i\\varphi_1}\\cos \\theta & - e^{i\\varphi_2}\\sin \\theta \\\\  e^{- i\\varphi_2}\\sin \\theta& e^{-i\\varphi_1}\\cos \\theta \\end{pmatrix} \\leftrightarrow (\\theta, \\varphi_1, \\varphi_2) \\leftrightarrow R_z(\\theta)R_y(\\varphi_1)R_x(\\varphi_2),$$ since $R_\\bullet (\\alpha + \\beta) = R_\\bullet (\\alpha)R_\\bullet (\\beta).$ Therefore $\\operatorname{PSU}(2)\\approx \\operatorname{SO}(3).$\r\n\\end{proof}\r\n\\section{SO(1,1)}\r\n\\begin{defn}[indefinite orthogonal group] Consider the Euclidean space only, i.e.,   $F=\\mathbb R$.\r\nThe \\textbf{indefinite orthogonal group} $\\operatorname{O}(p, q)$ is something like O, but the inner product is not provided while the following bilinear form is given: $$\\langle v, w\\rangle = v^\\mathsf T \\operatorname{diag}(\\underbrace{1, \\cdots, 1}_{p}, \\underbrace{-1, \\cdots, -1}_{q}) w,$$\r\n for $(p+q)$-dimensional vectors $v$ and $w$. For instance, $\\operatorname{O}(n) = \\operatorname{O}(n,0) = \\operatorname{O}(0,n).$\r\nAnd SO$(p,q)$ is ...\r\n\\end{defn}\r\nWe are interested in O(1,1) and O(1,3) in particular.\r\n\\begin{prop}\r\n$\\operatorname{SO}(1,1)$ can be represented by a hyperbolae $x^2 - y^2 = 1$, hence 2 connected curves. $\\operatorname{SO}^+$ is the `connected' component of this group which contains the identity $I$, $$\\operatorname{SO}^+ = \\left\\{ \\begin{pmatrix}\\cosh \\theta & \\sinh \\theta \\\\ \\sinh \\theta & \\cosh \\theta\\end{pmatrix}:~~ \\theta\\in\\mathbb R \\right\\}.$$ In fact, we call the connected component of a given `topological' group that contains the identity element the \\textbf{identity component} of given group.\r\n\\end{prop}\r\n\\begin{center}\r\n\r\n\\begin{tikzpicture}\r\n\\draw[->] (-3,0) -- (3,0) node[right] {$x$};\r\n\\draw[->] (0,-3) -- (0,3) node[above] {$y$};\r\n\\draw[dashed] (-3,-3) -- (3,3);\r\n\\draw[dashed] (3,-3) -- (-3,3);\r\n\\draw[scale=1,domain=-3:3,smooth,variable=\\y,blue,thick] plot ({(\\y*\\y + 1)^(1/2)},{\\y});\r\n\\node at (2.3,1.5) {$\\operatorname{SO}^{+}$};\r\n\\draw[scale=1,domain=-3:3,smooth,variable=\\y,blue,thick] plot ({-(\\y*\\y + 1)^(1/2)},{\\y});\r\n\\node at (-2.5,1.5) {$-\\operatorname{SO}^{+}$};\r\n\\node at (0.2,-0.5) {O};\r\n\\end{tikzpicture}\r\n\\end{center}\r\n\\begin{proof}\r\nCompletely same process. Note that if $A\\in\\operatorname{SO}(1,1)$, $$v^\\mathsf T \\begin{pmatrix}1&0\\\\0&-1\\end{pmatrix}w = \\langle v,w\\rangle = \\langle Av,Aw\\rangle =v^\\mathsf T A^\\mathsf T \\begin{pmatrix}1&0\\\\0&-1\\end{pmatrix}Aw,$$ hence $$\\begin{pmatrix}1&0\\\\0&-1\\end{pmatrix} = A^\\mathsf T \\begin{pmatrix}1&0\\\\0&-1\\end{pmatrix} A.$$ Then we have $$\\operatorname{SO}(1,1) = \\left\\{ \\pm \\begin{pmatrix}\\cosh \\theta & \\sinh \\theta \\\\ \\sinh \\theta & \\cosh \\theta\\end{pmatrix}:~~ \\theta\\in\\mathbb R \\right\\}.$$ We \\textit{can(?)} represent it as a parametrized hyperbola: $$\\pm \\begin{pmatrix}\\cosh \\theta & \\sinh \\theta \\\\ \\sinh \\theta & \\cosh \\theta\\end{pmatrix} \\longleftrightarrow \\pm\\begin{pmatrix}\\cosh \\theta\\\\ \\sinh \\theta\\end{pmatrix},$$ then $\\operatorname{SO}^+$ and $-\\operatorname{SO}^+$ are connected components of $\\operatorname{SO}(1,1).$\r\n\\end{proof}\r\nWhat does `connected' means? Detail definition is in \\textit{topology}: it cannot separated by some open sets.\r\n\r\nWe will stop our work here about groups for the time being. If we learn \\textit{topology} or \\textit{Lie group theory}, it will continue...\r\n", "meta": {"hexsha": "71a95eed3e40da658ec9c211854632313ea31744", "size": 16946, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matrix_group.tex", "max_stars_repo_name": "utophii/LinAlg", "max_stars_repo_head_hexsha": "3d11ab2382a1b7aaeea5c6703ee3f1e860b18f46", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "matrix_group.tex", "max_issues_repo_name": "utophii/LinAlg", "max_issues_repo_head_hexsha": "3d11ab2382a1b7aaeea5c6703ee3f1e860b18f46", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "matrix_group.tex", "max_forks_repo_name": "utophii/LinAlg", "max_forks_repo_head_hexsha": "3d11ab2382a1b7aaeea5c6703ee3f1e860b18f46", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 89.6613756614, "max_line_length": 2132, "alphanum_fraction": 0.6605688658, "num_tokens": 6106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.870597270087091, "lm_q1q2_score": 0.7056007253515475}}
{"text": "\n\\subsection{Structural supply and demand functions}\n\nSupply:\n\n\\(Q_s=\\alpha_1 + \\beta_1P+\\gamma_1I + \\epsilon_1\\)\n\nDemand:\n\n\\(Q_d=\\alpha_2 + \\beta_2P+\\gamma_2I + \\epsilon_2\\)\n\nCan't estimate because the equations are simulataneous.\n\n\nTo estimate, \\(cov(P, \\epsilon_1)\\) needs to be \\(0\\), but what is it?\n\n\\(cov(P, \\epsilon_1)= E[(P-E[P])(\\epsilon_1-E[\\epsilon_1])]\\)\n\\(cov(P, \\epsilon_1)= E[(P-E[P])(\\epsilon_1-E[\\epsilon_1])]\\)\n\n", "meta": {"hexsha": "219a9d1574e16f3d29d63dc34921acf9d3ac7063", "size": 431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/econometricsAggregate/01-01-problem.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/econometricsAggregate/01-01-problem.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/econometricsAggregate/01-01-problem.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.55, "max_line_length": 70, "alphanum_fraction": 0.6658932715, "num_tokens": 155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.7054810544818362}}
{"text": "\\chapter{Theoretical Framework}\n\\section{Relativistic Electrons}\nIn a (linear) particle accelerator, charged particles, such as electrons, are accelerated to increase their total energy over their energy at rest.\n\nCompared to heavier particles, such as protons ($m_p=\\SI{938.27}{\\mega\\eV\\per c\\squared}$), electrons are light particles ($m_e=\\SI{0.511}{\\mega\\eV\\per c\\squared}$). They are typically accelerated to speeds comparable to the speed of light to achieve kinetic energies usable for scientific experiments. For this reason, relativistic mechanics are needed to describe their movements.\\footnote{As relativistic mechanics are a super set of classical mechanics, the equations also apply for slower particles.} \\cite{Hinterberger1997}\n\nWith the speed of light $c=\\SI{2.99792458e8}{\\m\\per\\s}$ and the particle velocity $v$, it is common to define \\cite{Wangler2008}:\n\\begin{align}\\label{eq:theoreticalFramework_gammabeta}\n\\text{(normalized velocity)}\\qquad\\beta &= \\frac{v}{c}\\\\\n\\text{(relativistic mass factor)}\\qquad\\gamma &= \\frac{1}{\\sqrt{1-\\beta^2}} \\\\\n\\text{(relativistic momentum)}\\qquad p &= \\gamma m v \n\\end{align}\n\nThe total energy of a particle is \\cite{Hinterberger1997}\n\\begin{equation}\nW=\\sqrt{(mc^2)^2+(pc)^2},\n\\end{equation}\nwith the rest energy $mc^2$ and the kinetic energy is\n\\begin{equation}\nT=W-mc^2.\n\\end{equation}\n\nWith electrons (mass $m_e$) leaving the \\gls{flute} electron gun with a momentum of $p=\\SI{7}{\\MeV\\per c}$, this is equivalent to\n\\begin{align}\nW=\\sqrt{(m_ec^2)^2+(pc)^2} &= \\SI{7.0186}{\\MeV}\\\\\n\\gamma = \\frac{W}{m_ec^2} &= \\num{13.7351}\\\\\n\\beta = \\sqrt{1-\\gamma^{-2}} &= 0.9973\n\\end{align}\n\nThe force exerted on an electron (charge $q$) by an electric field $E$ and a magnetic flux density $B$ is given by the Lorentz force \\cite[p.~19]{Hinterberger1997}\n\\begin{equation}\\label{eq:fl}\nF_L = q\\left(E+v\\times B\\right).\n\\end{equation}\nAs the force due to the magnetic field is scaled with the velocity $v$, it is technically more viable to steer and focus a relativistic electron with magnets instead of electric fields. This is mainly because strong magnetic fields are easier to create and work with than high electric fields, which are difficult to handle. \\cite[p.~27]{Krieger2013}\n\n\\autoref{eq:fl} also motivates the use need for stable electron energies. Since the velocity depends on the energy, the force on the electrons is also a function of their energy. The magnetic fluxes of electromagnets can only be changed slowly compared to the repetition rate of an accelerator, so corrections to $B$ are not possible, which is why $v$/$E$ needs to be stable for a stable trajectory/focusing.\n\n\n\n\n\\section{Signal Analysis}\n\\subsection{Auto- and Cross-Covariance}\nThe \\textit{cross covariance} between two stochastic processes $x[n]$ and $y[n]$ is a measure of the similarity between $x[n]$ at index $n_1$ and $y[n]$ at index $n_2$ and is defined as\n\\begin{equation}\\label{eq:crosscovariance}\nr_{xy}[n_1,n_2] = \\text{E}\\left\\{(x[n_1]-\\mu_x[n_1])(y[n_2]-\\mu_y[n_2])^\\ast\\right\\}.\n\\end{equation}\n\nFor the special case of $y[n]:=x[n]$, $r_{xx}[n_1,n_2]$ is called \\textit{auto covariance} and is a measure of self similarity of $x[n]$. \\cite[p.~172]{Park2017}\n\nThe processes $x[n]$ and $y[n]$ are called \\textit{\\gls{wss}} if the following two properties hold. \\cite[p.~167]{Park2017}\nFirst, their means $\\mu_{\\xi}[n]$ are constant, i.e. they do not depend on the sample index:\n\\begin{align}\\label{eq:wss}\n\\mu_{x}[n] &= \\mu_x\\\\\n\\mu_{y}[n] &= \\mu_y\n\\end{align}\nAlso, the auto covariance does not depend on the absolute sample indices $n_1$ and $n_2$, but merely on the difference between them:\n\\begin{equation}\nr_{xy}[n_1,n_2] = r_{xy}[m],\\qquad \\text{with: } m:=n_2-n_1\n\\end{equation}\n\nIf both processes in \\autoref{eq:crosscovariance} are \\gls{wss}, \\autoref{eq:crosscovariance} simplifies to\n\\begin{equation}\nr_{xy}[m] = \\text{E}\\left\\{(x[n]-\\mu_x)(y[n-m]-\\mu_y)^\\ast\\right\\}.\n\\end{equation}\n\nFor the auto covariance both means are identical and can be moved outside the expectation operator:\n\\begin{equation}\nr_{xx}[m] = \\text{E}\\left\\{(x[n])(x[n-m])^\\ast\\right\\}-\\mu_{x}^2.\n\\end{equation}\n\nWhen analyzing signals, the stochastic processes are often unknown and only one realization $x[n]$ is known. But if the process generating $x[n]$ is \\textit{(weakly) ergodic}, then one realization is enough to determine the auto covariance of the process. \\cite[p.~252]{Puente2019}\nThen the auto covariance can be estimated with\n\\begin{equation}\\label{eq:autocovarianveEstimation}\n\\hat{r}[m] = \\frac{1}{N} \\sum_{n=m+1}^{N} x[n]\\,x^\\ast[n-m]\\qquad m \\in [0,\\,N-1].\n\\end{equation} \n\n\n\\subsection{Estimating the Spectrum of a Stochastic Process}\nFor a deterministic, time-discrete signal $x[n] \\in \\mathcal{L}_1$, the \\gls{dft} exists (see \\cite{Lapidoth2019}) and is defined as\n\\begin{equation}\nX[k] = \\sum_{n=0}^{N-1} x[n]\\,\\text{e}^{-j\\frac{2\\pi}{N}k\\,n}\\qquad k,n \\in [0,\\,N-1],\n\\end{equation}\nusing $k=\\frac{N}{2\\pi}\\,\\omega = N\\,f$ as the independent, discrete frequency variable. \nFrom the complex sequence $X[k]$, often only the magnitude (or energy) is of greater interest while the phase information are neglected. \nTherefore, $S_{xx}$ is defined as\n\\begin{equation}\nS_{xx} = \\left|X[k]\\right|^2,\n\\end{equation}\ncalled the \\textit{\\gls{esd}}.\n\nIf $x[n]$ is the realization of a stochastic process, then it is of random nature rather than deterministic.\nBecause realizations of physical processes do not posses finite energy, they are not in the $\\mathcal{L}_1$ set and their \\gls{dft} is not defined. \\cite[p.~5]{Stoica1997}\n\nIn this case instead of an energy spectral density, the spectrum of the average power of the process, called the \\textit{\\gls{psd}}, can be used instead.\nTo compute the \\gls{psd}, there are two possibilities:\n\\begin{align}\n\\Phi_{xx}[k] &= \\sum_{m=-\\infty}^{\\infty} r[m]\\,\\text{e}^{-j\\frac{2\\pi}{N}k\\,m} \\label{eq:phixx1}\\\\\n\\Phi_{xx}[k] &= \\lim_{N\\rightarrow\\infty} \\text{E}\\left\\{\\frac{1}{N}\\left|\\sum_{n=0}^{N-1} x[n]\\,\\text{e}^{-j\\frac{2\\pi}{N}k\\,n}\\right|^2 \\right\\} \\label{eq:phixx2}\n\\end{align}\nWhen assuming $r[m]$ decays ``fast enough'', i.e.\n\\begin{equation}\n\\lim_{N\\rightarrow\\infty} \\frac{1}{N} \\sum_{m=-N}^{N} |m|\\,\\left|r[m]\\right| = 0\n\\end{equation}\nthen \\autoref{eq:phixx1} and \\autoref{eq:phixx2} are equal. \\cite[p.~7]{Stoica1997}\n\nFor measured data however neither equations can be used directly.\nFor \\autoref{eq:phixx1} the auto covariance sequence $r[m]$ is unknown.\nBut it could be estimated with \\autoref{eq:autocovarianveEstimation}. In case of \\autoref{eq:phixx2} it is not possible to evaluate the limit, because only finite length data can be sampled and also the expectation can not be computed since in general there is only one realization available. Both operations can be neglected when doing an estimation.\n\nWith these practical changes in place, \\autoref{eq:phixx1} and \\autoref{eq:phixx2} become\n\\begin{align}\n\\hat{\\Phi}_{c,\\,xx}[k] &= \\sum_{m=-(N-1)}^{N-1} \\hat{r}[m]\\,\\text{e}^{-j\\frac{2\\pi}{N}k\\,m} \\label{eq:phiCxx1}\\qquad\\text{(Correlogram)}\\\\\n\\hat{\\Phi}_{p,\\,xx}[k] &= \\frac{1}{N} \\left| \\sum_{n=0}^{N-1} x[n]\\,\\text{e}^{-j\\frac{2\\pi}{N}k\\,n}\\right|^2\\qquad\\text{(Periodogram)}\\label{eq:periodogram}.\n\\end{align}\n\nBoth methods yield equal results, if $r[m]$ is estimated with the biased estimator $\\hat{r}[m]$ in \\autoref{eq:autocovarianveEstimation} in contrast to the unbiased estimator (compare \\cite[p.~24]{Stoica1997})\n\\begin{equation}\n\\hat{r}_{\\text{unbiased}}[m] = \\frac{1}{N-m} \\sum_{n=m+1}^{N} x[n]\\,x^\\ast[n-m]\\qquad m \\in [0,\\,N-1].\n\\end{equation}\n\n\\cite{Rowell2008} shows one key weakness of the unmodified periodogram method in \\autoref{eq:periodogram}: The variance does not decrease significantly with more samples $N$. Instead. the variance of the periodogram for each frequency approaches the square of the actual \\gls{psd}:\n\\begin{equation}\n\\lim_{N\\rightarrow\\infty} \\text{Var}\\left\\{\\hat{\\Phi}_{p,\\,xx}[k]\\right\\} = \\Phi_{xx}^2[k]\n\\end{equation}\nFurthermore, the periodogram/correlogram suffer from the smearing and leakage effects because the limited length of the data samples always causes an implicit windowing, thus reducing frequency resolution.\\\\\n\nThere are several popular methods that improve on the periodogram/correlogram concepts:\n\n\\textbf{Blackman-Tukey:} Because of the poor accuracy of $\\hat{r}[m]$ for $k\\approx N$ in the definition of $\\hat{\\Phi}_{c,\\,xx}[k]$ and the bigger the $N$, the more small errors in $\\hat{r}[m]$ sum up, truncating/windowing of $\\hat{r}[m]$ with $w[k]$ (length $M$) can be beneficial for the accuracy of the estimation.\n\\begin{equation}\n\\hat{\\Phi}_{BT,\\,xx}[k] = \\sum_{m=-(M-1)}^{M-1} w[k]\\hat{r}[m]\\,\\text{e}^{-j\\frac{2\\pi}{N}k\\,m}\n\\end{equation}\nThe choice of the window $w[k]$ trades frequency resolution for variance and smearing for leakage reduction. \\cite[p.~41]{Stoica1997}\n\n\\textbf{Barlett:} The Barlett method reduces the variance of the periodogram by splitting the $N$ data samples in $Q=\\nicefrac{N}{M}$ blocks and averaging together the sub-periodograms:\n\\begin{align}\n\\hat{\\Phi}_{q,\\,xx}[k] &= \\frac{1}{M} \\left| \\sum_{n=0}^{M-1} x_q[n]\\,\\text{e}^{-j\\frac{2\\pi}{M}k\\,n}\\right|^2\\\\\n\\hat{\\Phi}_{B,\\,xx}[k] &= \\frac{1}{Q} \\sum_{q=1}^{Q} \\hat{\\Phi}_{q,\\,xx}[k]\n\\end{align}\nThe variance of the estimation scales with $Q$ (see \\cite[p.~6]{Rowell2008}):\n\\begin{equation}\n\\text{Var}\\left\\{\\hat{\\Phi}_{B,\\,xx}[k]\\right\\} = \\frac{1}{Q}\\Phi_{xx}^2[k]\n\\end{equation}\n\n\\textbf{Welch:} The Welch method combines splitting the data into $Q$ segments with windowing each segment and allowing the segments to overlap. With $P = \\nicefrac{1}{M} \\sum_{n=0}^{M-1} |w[n]|^2$ being the ``power'' of the window, the Welch method is computed as\n\\begin{align}\n\\hat{\\Phi}_{s,\\,xx}[k] &= \\frac{1}{M P} \\left| \\sum_{n=0}^{M-1} x_s[n]\\,\\text{e}^{-j\\frac{2\\pi}{M}k\\,n}\\right|^2\\\\\n\\hat{\\Phi}_{W,\\,xx}[k] &= \\frac{1}{Q} \\sum_{s=1}^{Q} \\hat{\\Phi}_{s,\\,xx}[k].\n\\end{align}\nCompared to the Barlett method, the overlapping of up to \\SI{50}{\\percent} (see \\cite{Welch1967}) allows increasing $Q$, thus reducing the variance.\n\\begin{equation}\\label{eq:varWelch}\n\\text{Var}\\left\\{\\hat{\\Phi}_{W,\\,xx}[k]\\right\\} = \\frac{1}{Q}\\Phi_{xx}^2[k]\n\\end{equation}\n\n\n\\paragraph{Spectogram}\nIf a stochastic process or a signal as a realization of that process $x[n]$ is not \\gls{wss}, one possibility to analyze and display the spectral content is the use of the \\gls{stft} and the spectrogram, which is a two dimensional power spectral density function mapping frequency and time to a third coordinate like height, intensity or color.\n\nTo calculate the spectrogram, the signal is split into segments with the sliding window $w[n-m]$ for which duration the signal is assumed to be stationary. For each segment at time index $m$, the periodogram is calculated according to\n\\begin{equation}\n\\hat{\\Phi}_{xx}[k,m] = \\frac{1}{N} \\left| \\sum_{n=0}^{N-1} w[n-m] x[n]\\,\\text{e}^{-j\\frac{2\\pi}{N}k\\,n}\\right|^2.\n\\end{equation}\n\n\n\n\n\n\n\n\n\n\\section{Feedback Control Systems}\\label{sec:feedbackcontrol}\nFeedback control systems are used to control a dynamic system (also called a plant) in such a way that its output $y(t)$ follows a certain input $x(t)$ and disturbances on the output $d(t)$ are rejected. The general structure of a closed-loop control system is shown in \\autoref{fig:theoreticalFramework-feedback-architecture}. To achieve sufficient tracking of the input and stabilization of the output, a controller $G(s)$ uses the error $e(t)$ to control the plant $P(s)$ accordingly.\nThe error is defined as\n\\begin{equation}\ne(t)=x(t)-r(t) = x(t)-[y(t)\\ast h(t)]\n\\end{equation}\nwith $h(t)$ being the inverse Laplace transform of the filters transfer function $H(s)$. The signal $r(t)$ is the output of the measurement filter $h(t)$ or $H(s)$. It is most commonly a lowpass filter used to reject high-frequency noise on the system output $y(t)$.\n\nFeedback control systems, or closed-loop systems, are to be differentiated from open-loop systems, in which there is no return path, so they cannot compensate for \\textit{un}known disturbances. If $d(t)$ is known $\\forall t$, then an open loop system would be possible and any errors could simply be compensated. But for real world application this approach is only usable for crude control tasks or if the system is very well understood or isolated from its surroundings.\n\n\\begin{figure}[tbh]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{chap/TheoreticalFramework/img/feedbackControl/architecture.tikz}\n\t\\caption[Control system structure]{General structure of a time-continuous feedback control system}\n\t\\label{fig:theoreticalFramework-feedback-architecture}\n\\end{figure}\n\n\\subsection{Disturbance Rejection and Input Tracking}\\label{sec:drandtrack}\nDisturbance rejection and input tracking are two important characteristics to evaluate a stable controller. To calculate them, the block diagram in \\autoref{fig:theoreticalFramework-feedback-architecture} and the Laplace transform of the inputs/outputs are used.\\footnote{The Laplace transform of a function in time $f(t)$ is written as $F(s)=\\mathcal{L}\\left\\{f(t)\\right\\}$.} \n\nTo calculate how the output $y(t)$ depends on the input $x(t)$, the input tracking transfer function can be used. \\cite[p.~88]{Foellinger2016}\nIt is calculated as the transfer function $F_T=\\nicefrac{Y(s)}{X(s)}$ by setting $d(t)=0$:\n\\begin{align}\\label{eq:inputTracking}\nY(s)&=G(s)P(s)E(s)\\quad\\text{with:}\\quad E(s)=X(s)-H(s)Y(s)\\\\\n\\Leftrightarrow Y(s)\\left[1+G(s)P(s)H(s)\\right]&=G(s)P(s)X(s)\\\\\n\\Leftrightarrow F_T:=\\frac{Y(s)}{X(s)} &= \\frac{G(s)P(s)}{1+G(s)P(s)H(s)}.\n\\end{align}\n\nOn the other hand, the transfer function $F_{DR}=\\nicefrac{Y(s)}{D(s)}$ can be used to describe the systems response to a disturbance. \\cite[p.~88]{Foellinger2016} It is defined by setting $x(t)=0$ and calculating\n\\begin{align}\\label{eq:disturbanceRejection}\nY(s)&=G(s)P(s)E(s)+D(s)\\quad\\text{with:}\\quad E(s)=-H(s)Y(s)\\\\\n\\Leftrightarrow Y(s)\\left[1+G(s)P(s)H(s)\\right]&=D(s)\\\\\n\\Leftrightarrow F_{DR}:=\\frac{Y(s)}{D(s)}&=\\frac{1}{1+G(s)P(s)H(s)}.\n\\end{align}\n\n\\subsection{Control System Stability}\nThe application of a controller to a system is only useful if the resulting system has a stable behavior.\nOne possible definition of stability is the \\gls{bibo} criterion (see \\cite[p.~82]{Foellinger2016}):\n\\begin{definition}\\label{def:bibo}\n(\\textit{BIBO stability}) A \\gls{lti} system is said to be \\gls{bibo} stable if for some $M,N \\in \\mathbb{R}^+$, the response to a bounded input $|u(t)| \\le M$ results in a bounded output $|y(t)| \\le N$.\n\\end{definition}\n\nFor a given control system, one way to analyze its stability is to plot the locus $z=F_o(s=j2\\pi f)$ of the open loop frequency response\n\\begin{equation}\nF_o(s) = G(s)P(s)H(s)\n\\end{equation}\nfrom $f=0$ to $f=\\infty$ and using the Nyquist stability criterion.\nFor the special case of a stable open loop $F_o(s)$ \\footnote{The stability of $F_o(s)$ can often easily be determined from the block diagram.} the Nyquist stability criterion can be stated as (see \\cite[p.~111]{Foellinger2016})\n\\begin{definition}\\label{def:Nyquist}\n(\\textit{Nyquist stability criterion}) If the open loop $F_o(s)$ is stable, then the closed loop is stable if $z=F_o(s=j2\\pi f)$ does not go through or encircles $z=(-1,0j)$.\n\\end{definition}\n\n\\newpage\n\\section{Metrics to Quantify the Stability of a Signal}\\label{sec:metrics}\n``Stability'' can have different meanings depending on the context. In case of signal processing, a signal is usually said to be \\textit{stable} if it has only little variation around its mean or some target value, i.e. the mean has to be constant and the variance stays below some threshold. \nStability is not to be confused with stationarity, which requires the mean, the variance and the autocorrelation to stay constant over time. \\cite{Guthrie2020} \nTo express stability as a single numerical value, there are several possibilities, some are described in the following.\n\n\\paragraph{Relative Standard Deviation}\nThis measures the stability as the standard deviation but related to the mean value to make it comparable to other quantities with different scaling or units.\n\nThe relative, or percentual, standard deviation of the stationary stoachastic process $X$ is defined using the mean $\\mu_X$ and the standard deviation $\\sigma_X$ as\n\\begin{equation}\n\\op{\\%STD_X} := \\frac{\\sigma_X}{\\mu_X}.\n\\end{equation}\nIn general, especially if $X$ is non-stationary (see \\autoref{eq:wss}), $\\op{\\%STD_X}$ depends on the absolute time $t$ and the window size $T$ for which the process is assumed to be stationary:\n\\begin{equation}\n\\op{\\%STD_X} = \\op{\\%STD_X}(t,T)\n\\end{equation}\nIn that case, for a fixed window size $T=T_0$, a mean percentual standard deviation can be computed with \n\\begin{equation}\\label{eq:stdp}\n\\op{\\%STD_X}(T=T_0) = \\frac{1}{N} \\sum_{n=0}^{N-1} \\op{\\%STD_X}(t_n,T_0).\n\\end{equation}\nThis assumes discrete time steps $t_n$, $n\\in[0,N-1]$.\n\n\\paragraph{Mean Squared Error}\nA similar measure to the percentual standard deviation is the \\gls{mse}, if, instead of the mean $\\mu_X$, a fixed target $x_t$ is used.\n\nThe mean squared error sums up the squared errors $\\left(x[n] - x_t[n]\\right)^2$ of $x[n]$ from a set value $x_t$. To remove the effect of the length of the data sequence, the sum is devided by the length of the sequence $N$:\n\\begin{equation}\n\\op{MSE}_x := \\frac{1}{N} \\sum_{n=0}^{N-1} \\left(x[n] - x_t\\right)^2\n\\end{equation}\n\n\\paragraph{Relative Power of Most Prominent Noise}\nThis novel approach compares the power of the most prominent noise power source $P_\\text{noise, max}$ of the signal $x$ with the total power $P_x$:\n\\begin{equation}\\label{eq:mpn}\n\\op{MPN}_x := \\frac{P_\\text{noise, max}}{P_x}\n\\end{equation}\n\nCompared to the relative standard deviation $\\op{\\%STD}(t,T)$, this method has the advantage of being time-independent and keeping periodic noise structures:\\\\\n\n\\paragraph{Comparison}\nTo make $\\op{\\%STD}(t,T)$ independent of time, it could be tempting to choose $T=T_\\text{total}$ with $T_\\text{total}$ being the time span of the data set. But because of the averaging effect of the standard deviation estimator, this washes out the maxima and thus could lead to an under-estimation of $\\op{\\%STD}$, so an over-estimation of the stability.\n\nThe $\\op{MSE}$ uses the whole data set, but due to normalizing maxima can also be hidden.\n\nPeriodogram-based method have the advantage that for a fixed target value $x_t$, they are very easy to interpret: All power, that is not in the $f=0$ frequency bin, is definitely noise. Integrating over these noise bins yields the error power comparable to the $\\op{MSE}$.\nThe described $\\op{MPN}$ metric has the advantage of showing the largest contributor to the noise and allows for an easy validation of a controllers success on this noise component.\n\n", "meta": {"hexsha": "302572acade66049dd782ab5d8fd95fef86de983", "size": 18789, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap/TheoreticalFramework/theoretical-framework.tex", "max_stars_repo_name": "youcann/thesisvorlage-latex", "max_stars_repo_head_hexsha": "34e58b00e6df11f79a38a3e6c394892bed687be2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chap/TheoreticalFramework/theoretical-framework.tex", "max_issues_repo_name": "youcann/thesisvorlage-latex", "max_issues_repo_head_hexsha": "34e58b00e6df11f79a38a3e6c394892bed687be2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chap/TheoreticalFramework/theoretical-framework.tex", "max_forks_repo_name": "youcann/thesisvorlage-latex", "max_forks_repo_head_hexsha": "34e58b00e6df11f79a38a3e6c394892bed687be2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.332103321, "max_line_length": 529, "alphanum_fraction": 0.7271275746, "num_tokens": 5840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.7054793552322758}}
{"text": "\n\\subsection{Functionals of probabilities}\n\n\\(\\phi (P)\\in \\mathbb{R} \\) is a functional on \\(P(X)\\).\n\nExamples include the expectation and variance.\n\nWe can define derivatives on these functionals.\n\n\\(\\phi (P)\\approx \\phi (P^0)+D_\\phi (P-P^0)\\)\n\nWhere \\(D_\\phi \\) is linear.\n\n", "meta": {"hexsha": "36133b172164a4eb4e46aa5e2800b8d3afa21271", "size": 276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityMoments/01-01-functional.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/probabilityMoments/01-01-functional.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/probabilityMoments/01-01-functional.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.7142857143, "max_line_length": 56, "alphanum_fraction": 0.6775362319, "num_tokens": 83, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.7054793434223847}}
{"text": "\\section{Dynamic Programming}\n  \\subsection{Dynamic Convex Hull Trick}\n    \\code{dp/dynamic-ch-trick.cpp}\n  \\subsection{Divide and Conquer Optimization}\n    For DP problems of the form $$dp(i,j) = min_{k \\leq j} \\{dp(i-1,k)+C(k,j)\\}$$ where $C(k,j)$ is some cost function.\n    \\code{dp/divide-conquer-opt.cpp}\n", "meta": {"hexsha": "f7d2e41d6e34917f22e5920060fc851818ccbe0c", "size": 310, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebook/tex/dp.tex", "max_stars_repo_name": "bullybutcher/progvar-library", "max_stars_repo_head_hexsha": "4d4b351c8a2540c522d00138e1bcf0edc528b540", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-10-16T13:22:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-29T22:03:44.000Z", "max_issues_repo_path": "notebook/tex/dp.tex", "max_issues_repo_name": "bullybutcher/progvar-library", "max_issues_repo_head_hexsha": "4d4b351c8a2540c522d00138e1bcf0edc528b540", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2021-11-27T14:40:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:14:59.000Z", "max_forks_repo_path": "notebook/tex/dp.tex", "max_forks_repo_name": "bullybutcher/progvar-library", "max_forks_repo_head_hexsha": "4d4b351c8a2540c522d00138e1bcf0edc528b540", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2022-03-11T20:53:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T07:08:46.000Z", "avg_line_length": 44.2857142857, "max_line_length": 119, "alphanum_fraction": 0.6838709677, "num_tokens": 97, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.7053889039482094}}
{"text": "\\Lecture{Jayalal Sarma}{Oct 19, 2020}{18}{Introduction to Ramsey Numbers}{Shivlal Gangesh}{$\\alpha$}{JS}\n\\section{Introduction}\nTill now we have seen advanced versions of the discrete mathematics topics we already know. Now we are going to get into Extremal combinatorics. Here we are interested in questions of the form \n\\begin{itemize}\n\\item \\textit{If this structure appears, then what is the minimum/maximum size of the object?}\n\\item \\textit{If the size is at least this much , then what kind of structures appear in the object?}\n\\item \\textit{What is the minimum size of the collection such that it is guaranteed to have certain property?}\n\\end{itemize}\nIn general we are interested in the extreme behaviors in combinatorics. The classic example we start with is an extension to an example that we have done in the beginning of the course as an Application of Pigeon Hole Principle.\n\\section{Starting Point} \\label{R(3,3)}\n\\begin{theorem}\nSix people meet in a party. Then either there exist three people who are friends with each other or there exist three people who are strangers with each other.(Note : Any two people can either be friends or strangers)\n\\end{theorem}\nWe are interested in proving the above statement. Lets look into two different approaches\n\\subsection{Model 1 (Using Cliques and Independent Sets)}\n\\begin{description}\n   \\item[Model] Let us represent the problem as a $6$ vertex graph $G(V,E) $with each person corresponding to a vertex. $(u,v) \\in E$ if and only if person $u$ is a friend of person $v$.\nIn this Model the original statement can be reformulated as\n\\item[Statement]\n\\textit{Any graph on $6$ vertices must either have a clique on $3$ vertices or an independent set on $3$ vertices.\n\\item}\n\\begin{proof}\n Consider any vertex $v$ in the graph G, without loss of generality we can assume that the degree of $v$ is greater than or equal to $3$  because suppose it is not the case then consider $\\overline{G}$ ; as $\\textrm{Cliques in }G \\leftrightarrow \\textrm{Independent Sets in } \\overline{G} $.\\\\\n Let the $3$ neighbours of $v$ be $a$, $b$ and $c$. Consider the two exhaustive cases :\n \\begin{description}\n    \\item[Case 1 : There are no edges among $a$, $b$ and $c$]\n    $ $ \\newline\n    Here we have $\\{a, b, c\\}$ as the 3-Independent Set\n    \\item[Case 2 : There is at least one edge among $a$, $b$ and $c$ ]\n    $ $ \\newline\n    Let $(a,b) \\in E$ be that edge, then we have $\\{v, a, b\\}$ as the 3-clique\n \\end{description}\nTherefore the given statement holds true.\n\\end{proof}\n\\item[Proof for tightness]\nTo prove that this is tight we need to show there is a graph with $5$ vertices such that it does not have 3-clique and 3-Independent Set. Given below is one such  example\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.2\\linewidth]{images/r33counter_example.png}\n    \\caption{5-vertex graph with no 3-clique and no 3-Independent Set}\n\\end{figure}\n\\end{description}\n\\subsection{Model 2 (Using Graph Edge colouring)}\n\\begin{description}\n   \\item[Model]\n   Let us represent the problem as 2-edge coloring of a $K_6$ graph with each vertex corresponding to a person. Color the edge $(u,v)$ with \\textit{red} if $u$ and $v$ are friends, color it with \\textit{blue} if $u$ and $v$ are strangers.\nIn this Model the original statement can be reformulated as\n\\item[Statement]\n\\textit{For any 2-edge colouring of $K_6$, there must exist either  a red $K_3$  or a blue $K_3$ }\n\\item\n\\begin{proof}\n Consider any Red,Blue-edge coloring of $K_6$. Consider any vertex $v$, the degree of $v$ is $5$ as the graph is a complete graph. By Pigeon Hole Principle , $v$ must have either $3$ red edges incident on it or $3$ blue edges incident on it. Consider the case when $v$ is incident on with $3$ red edges. Let the 3 neighbours of $v$ be $a$, $b$ and $c$.  Now there are 2 cases :\n \\begin{description}\n    \\item[Case 1 : There is no red colored edge among $(a,b)$, $(b,c)$ and $(c,a)$ ]\n    $ $ \\newline\n    Then all the three edges $(a,b)$, $(b,c)$ and $(c,a)$ are colored blue. Therefore $\\{a, b, c\\}$ forms a blue $K_3$\n    \\item[Case 2 : There is at least one red colored edge among $(a,b)$, $(b,c)$ and $(c,a)$ ]\n    $ $ \\newline\n    Let $(a,b)$ be the red colored edge, then $\\{v, a, b\\}$ forms a red $K_3$\n \\end{description}\n Therefore the given statement holds true.\n\\end{proof}\n\\item[Proof for tightness]\nTo prove that this is tight we need to show there is a 2-edge coloring of $K_5$ Such that it does not have red $K_3$ and blue $K_3$. Given below is one such  example\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=0.2\\linewidth]{images/k5counter_example.png}\n    \\caption{2-edge coloring of $K_5$ with no red $K_3$ and no blue $K_3$}\n\\end{figure}\n\\end{description}\n\nGeneralizing the above problem with arbitrary red $k_p$ and blue $k_q$ has been extensively studied by Ramsey and has led to the definition of Ramsey numbers.\n\\section{Ramsey numbers}\n\\begin{definition}[Ramsey number]\nThe Ramsey number denoted by $R(p,q)$ is the minimum number of vertices say $n$ such that any 2-edge coloring of $K_n$ must have either a red $K_p$ or a blue $K_q$.\\\\\n(\\textbf{Or equivalently as})\\\\\nThe minimum number of vertices ($n$) such that any graph on $n$ vertices must either have a clique on $p$ vertices or an independent set on $q$ vertices.\n\\end{definition}\n\n\\subsection{Some Observations}\n\\begin{property}\n$R(3,3)=6$\n\\end{property}\nThis is the direct formulation of the example we have done previously in \\ref{R(3,3)}\n\\begin{property}\n$R(p,q) = R(q,p)$\n\\end{property}\nThe colors \\textit{red} and \\textit{blue} are just placeholders for two colors, thus swapping the colors will still preserve the Ramsey number property. Therefore $R(p,q) = R(q,p)$.\n\\begin{property}\n$\\forall l \\geq 1 \\quad R(l,1) = 1$\n\\end{property}\nThe existence of a blue $K_1$ is nothing but the presence of single vertex and any graph with a single vertex satisfies this property. Therefore $R(l,1) = 1$\n\n\n\\section{Existence of R(p,q)}\nThe Proof for the existence of $R(p,q)$ is due to Erdős–Szekeres. The existence was proved by providing an upper bound as a recurrence relation as follows :\n\\begin{theorem}\n$$\\forall p,q \\geq 2 \\quad R(p,q) \\; \\leq \\; R(p,q-1) + R(p-1,q) $$\n\\end{theorem}\n\\begin{proof}\n Let us prove this by mathematical induction on $n$ where $n=p+q$.\n \\begin{description}\n    \\item[Idea] To show the upper bound for $R(p,q) \\leq n$ , we must argue that for any 2-edge coloring of $K_n$ there exist a red $K_p$ or blue $K_q$\n\n   \\item[Base case] $p=q=2$\n$$R(2,2) \\leq  R(2,1) + R(1,2)  $$\n$$2 \\leq 1+1$$\nHence it holds true for the base case.\n   \\item[Induction Hypothesis]\nAssume the recurrence relation is true for $n<l$. Then we need to prove it for $n=l$. Let $n=R(p-1,q)+R(p,q-1)$. Let $w$ be any vertex in $G$ ($K_n$) and consider any $2$ -edge coloring of $G$. Let $H_1$ be the subgraph of $G$ formed from the vertices sharing a red-edge with $v$ and $H_2$ be the the subgraph of $G$ formed from the vertices sharing a blue-edge with $v$.\n\\begin{description}\n   \\item[Case 1 : There are at least $R(p-1,q)$ many red edges incident on vertex $w$]\n   $ $ \\newline\n   $H_1$ is a complete graph on $R(p-1,q)$ vertices with 2-edge coloring. By definition and Induction Hypothesis we have that there exist a red $K_{p-1}$ or blue $K_q$ in $H_1$. So in graph $G$ (along with vertex $w$) there exist a red $K_p$ or blue $K_q$\n   \\item[Case 2 : There are at least $R(p,q-1)$ blue edges incident on vertex $w$]\n      $ $ \\newline\n      $H_2$ is a complete graph on $R(p,q-1)$ vertices with 2-edge coloring. By definition and Induction Hypothesis we have that there exist a red $K_p$ or blue  $K_{q-1}$ in $H_2$. So in graph $G$ (along with vertex $w$) there exist a red $K_p$ or blue $K_q$.\n\\end{description}\n   \\end{description}\n   \n\\end{proof} \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n", "meta": {"hexsha": "4ccd0ca2d6487e9e9706106057e7bacce564ba20", "size": 7904, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week07L1.tex", "max_stars_repo_name": "pot8ohead/theory-toolkit", "max_stars_repo_head_hexsha": "177249454691f7e264d9ee7d5a354e180a54e095", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week07L1.tex", "max_issues_repo_name": "pot8ohead/theory-toolkit", "max_issues_repo_head_hexsha": "177249454691f7e264d9ee7d5a354e180a54e095", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week07L1.tex", "max_forks_repo_name": "pot8ohead/theory-toolkit", "max_forks_repo_head_hexsha": "177249454691f7e264d9ee7d5a354e180a54e095", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.1369863014, "max_line_length": 377, "alphanum_fraction": 0.7021761134, "num_tokens": 2370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324938410784, "lm_q2_score": 0.8652240860523328, "lm_q1q2_score": 0.7053587894038111}}
{"text": "\\section{Sample algorithm}\n\\begin{algorithm}\n\t\\caption{Kruskal's Algorithm}\\label{alg:kruskal}\n\t\\begin{algorithmic}[1]\n\t\t\\Procedure{MakeSet}{$v$}\n\t\t\t\\State Create new set containing $v$\n\t\t\\EndProcedure \\\\\n\t\t\n\t\t\\Function{FindSet}{$v$} \n\t\t\t\\State\\Return a set containing $v$\n\t\t\\EndFunction \\\\\n\t\t\n\t\t\\Procedure{Union}{$u$,$v$}\n\t\t\t\\State Unites the set that contain $u$ and $v$ into a new set\n\t\t\\EndProcedure \\\\\n\t\t\n\t\t\\Function{Kruskal}{$V,E,w$}\n\t\t\t\\State $A \\gets \\{\\}$\n\t\t\t\\For {each vertex $v$ in $V$}\n\t\t\t\t\\State MakeSet($v$)\n\t\t\t\\EndFor\n\t\t\t\\State Arrange $E$ in increasing costs, ordered by $w$\n\t\t\t\\For {each ($u$,$v$) taken from the sorted list}\n\t\t\t\t\\If {FindSet($u$) $\\neq$ FindSet($v$)}\n\t\t\t\t\t\\State $A \\gets A \\cup \\{(u,v)\\}$\n\t\t\t\t\t\\State Union($u,v$)\n\t\t\t\t\\EndIf\n\t\t\t\\EndFor\n\t\t\t\\State \\Return A\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\newpage\n\\section{Sample Python code}\n\\begin{lstlisting}[language=Python]\nimport numpy as np\n\ndef incmatrix(genl1,genl2):\n\tm = len(genl1)\n\tn = len(genl2)\n\tM = None #to become the incidence matrix\n\tVT = np.zeros((n*m,1), int)  #dummy variable\n\n\t#compute the bitwise xor matrix\n\tM1 = bitxormatrix(genl1)\n\tM2 = np.triu(bitxormatrix(genl2),1) \n\n\tfor i in range(m-1):\n\t\tfor j in range(i+1, m):\n\t\t\t[r,c] = np.where(M2 == M1[i,j])\n\t\t\tfor k in range(len(r)):\n\t\t\t\tVT[(i)*n + r[k]] = 1;\n\t\t\t\tVT[(i)*n + c[k]] = 1;\n\t\t\t\tVT[(j)*n + r[k]] = 1;\n\t\t\t\tVT[(j)*n + c[k]] = 1;\n\n\tif M is None:\n\t\tM = np.copy(VT)\n\telse:\n\t\tM = np.concatenate((M, VT), 1)\n\n\tVT = np.zeros((n*m,1), int)\n\n\treturn M\n\\end{lstlisting}\n\n\\newpage\n\\section{Sample Matlab code}\n\\lstinputlisting[language=Octave]{codes/sample-code.m}", "meta": {"hexsha": "10e606736a0f6488dcb499e1c342cd6ace6ef2f1", "size": 1623, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main/contents/appendix/appendix.tex", "max_stars_repo_name": "yasirroni/thesisdtetiugm", "max_stars_repo_head_hexsha": "637e76c0114f02bd44b407c00e5146e18ce76850", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "main/contents/appendix/appendix.tex", "max_issues_repo_name": "yasirroni/thesisdtetiugm", "max_issues_repo_head_hexsha": "637e76c0114f02bd44b407c00e5146e18ce76850", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "main/contents/appendix/appendix.tex", "max_forks_repo_name": "yasirroni/thesisdtetiugm", "max_forks_repo_head_hexsha": "637e76c0114f02bd44b407c00e5146e18ce76850", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.1857142857, "max_line_length": 64, "alphanum_fraction": 0.6142945163, "num_tokens": 614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264639, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7053587770202452}}
{"text": "\\subsection{Method of Undetermined Coefficients}\r\n\\noindent\r\nThe rules for undetermined coefficients are very similar for systems and single equations. Let's say we have a heterogeneous system of the form\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\tx_1' = a_{11}x_1 + \\ldots + a_{1n}x_n + f_1(t) \\\\\r\n\t\t\\vdots \\\\\r\n\t\tx_n' = a_{n1}x_n + \\ldots + a_{nn}x_n + f_n(t)\r\n\t\\end{cases}\r\n\\end{equation*}\r\nwritten in a matrix form,\r\n\\begin{equation*}\r\n\t\\begin{bmatrix}\r\n\t\tx_1' \\\\\r\n\t\t\\vdots \\\\\r\n\t\tx_n'\r\n\t\\end{bmatrix} = \\begin{bmatrix}\r\n\t\ta_{11} & \\ldots & a_{1n} \\\\\r\n\t\t\\vdots & \\ddots & \\vdots \\\\\r\n\t\ta_{n1} & \\ldots & a_{nn}\r\n\t\\end{bmatrix} \\begin{bmatrix}\r\n\t\tx_1 \\\\\r\n\t\t\\vdots \\\\\r\n\t\tx_n\r\n\t\\end{bmatrix} + \\begin{bmatrix}\r\n\t\tf_1(t) \\\\\r\n\t\t\\vdots \\\\\r\n\t\tf_n(t)\r\n\t\\end{bmatrix}\r\n\\end{equation*}\r\nor more compactly as\r\n\\begin{equation*}\r\n\t\\vec{x}' = A\\vec{x} + \\vec{f}\r\n\\end{equation*}\r\nAll we need to do is look at each $f_i(t)$ and write in the $i^{th}$ blank the corresponding guess. This is like doing undetermined coefficients on each equation in the system.\\\\\r\n\r\n\\noindent\r\nThis is especially nice when all the $f_i(t)$'s have a similar form because we can write our guess as\r\n\\begin{equation*}\r\n\t\\vec{g}(t) = f_c(t)\\vec{v}\r\n\\end{equation*}\r\nwhere $f_c(t)$ is the guess corresponding to $f$ and $\\vec{c}$ is a vector of undetermined scalars.\r\n\r\n\\ifodd\\includeLinearSystemsExamples\\input{./linearSystems/heterogeneousSystems/undeterminedCoefficients_example.tex}\\fi", "meta": {"hexsha": "c384b1e632725812c4fa0f4605b8ea68a78e2fdb", "size": 1446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/heterogeneousSystems/undeterminedCoefficients.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/linearSystems/heterogeneousSystems/undeterminedCoefficients.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/linearSystems/heterogeneousSystems/undeterminedCoefficients.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.8636363636, "max_line_length": 179, "alphanum_fraction": 0.6694329184, "num_tokens": 511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7053587713539068}}
{"text": "%!TEX root =  ../main.tex\n\n\\objective{Solve arbitrary equations involving rational powers.}\n\n\nFractional exponents are nothing too special.  It is simply important to remember that in the\nfraction, the numerator is what we've been thinking of as powers ($\\frac{5}{1}=5$) and the\ndenominators are roots, i.e. $2^{\\frac{1}{2}}=\\sqrt{2}$.  As we will see next section, this isn't \na watertight definition, but it will do for now.\n\n\\subsection{Multiplying}\\index{Exponents!rules of}\nIn situations where exponents abound, it may become confusing when one can and cannot\nmultiply, and what to do with exponents.  What do we mean when we write $5^2\\cdot5^3$? \nIs that $5^5$ or $5^6$?  Expanding the notation should help clear it up.  $5^2$ means \n``multiply by five twice'', i.e. $5\\cdot 5$.  $5^3$ means ``multiply by five three times'', $5\\cdot\n5\\cdot 5$.  So we can see that $5^2\\cdot5^3=5\\cdot 5\\cdot 5\\cdot 5\\cdot 5=5^5$.\n\n\n\n\\begin{derivation}{Multiplying with the Same Base}\n$b^m\\cdot b^n=b^{m+n}$.  Notice that $b$ must be consistent.\n\\end{derivation}\n\n\nStudents sometimes want to combine in impossible ways.  $2\\cdot5^3$ becomes $10^3$ \nsomehow, in their minds.  When we consider what the notation means, the contradiction\nbecomes clear.  $2\\cdot5^3$ means ``two times this: five-times-five-times-five'', which is in no\nway the same as ``ten times ten times ten''.\n\n\\subsection{Dividing}\nIf the exponents can be added when multiplying powers of the same base, what would you\nexpect when dividing?  Yes, it is subtraction.\n\n\n\\begin{derivation}{Dividing with the Same Base}\n$\\cfrac{b^m}{b^n}=b^{m-n}$.  Notice that $b$ must be consistent.\n\\end{derivation}\n\n\nThis is a good explanation for negative exponents.  For example, $\\cfrac{2^3}{2^8}=2^{-5}$.\nThere are more two's in the denominator than the numerator.  This is the same as $\\frac{1}{2^5}$,\nwhich is a far more useful way to write the fraction.  When cancelling and simplifying are done,\nit is conventional to expand the exponent, in this case writing $\\frac{1}{32}$.\n\nThis also explains the origin of $b^0=1$, unless $b=0$.  Zero exponent arrises when there\nare as many of the base in the denominator as there are in the numerator.  Anything\ndivided by itself is 1.\n\n\\subsection{Exponents}\nWhat happens when there is an exponent on an exponent?  Easier than a dream within a\ndream, the exponents continue to mean what they have always meant: ``have this many\nof this bases be multiplied against themselves''.  For example, $(2^3)^4$ means ``four\ngroups of two-times-two-times-two'', or $2^12$.\n\n\\begin{derivation}{Distribution of Exponents over Multiplication}\n$(b^m\\cdot c^n)^p=b^{m\\cdot p}\\cdot c^{n\\cdot p}$ and so for, on each element under\nthe power\n\\end{derivation}\n\n\n\\begin{example}\n\\exProblem\nSolve $x^{\\frac{3}{2}}=27$.\n\n\\exSolution\nTo get $x$ to have a simple exponent of 1, raise both sides to the two-third.\\\\\n$\\left(x^\\frac{3}{2}\\right)^{\\frac{2}{3}}=27^{\\frac{2}{3}}$\n$x=\\left(\\sqrt[3]{27}\\right)^2$\\\\\n$x=3^2=9$\n\\end{example}\n\nNotice too, there is no distributive property of exponents over addition.  $\\sqrt{x^2+1}$\nis irreducible, not $x+1$.  We would need to know what $x$ was to be able to proceed.\n\n\\subsection{Rational Exponents}\\index{exponents!rational}\nFractional exponents must be the same as roots.  For example, we know from\nthe multiplication property that $4^\\frac{1}{2}\\cdot 4^\\frac{1}{2}$ must equal $4^1$.\nThat must mean we are looking for a number times itself to equal 4, so $4^\\frac{1}{2}$\nmust equal 2.  This means $\\sqrt{4}=4^\\frac{1}{2}$.  By the same logic, we would \nfind that $4^\\frac{1}{3}=\\sqrt[3]{4}$, $4^\\frac{1}{4}=\\sqrt[4]{4}$, etc.  By the power\nrule above, $4^\\frac{3}{2}$ must be the same as $(4^\\frac{1}{2})^3$.  This could also\nbe written as $4^{1.5}$.\n\nWe must be careful with even rational exponents, because they can hide the sign of the base.\nFor example, $((-5)^2)^\\frac{1}{2}=5$.  The safe answer then to $\\sqrt[n]{x^n}$ for any\neven $n$ is $|x|$.\n", "meta": {"hexsha": "fa9a6aad61a85b5401fcc187ae77e59652ddef28", "size": 3962, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch05/0502.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch05/0502.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch05/0502.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.5402298851, "max_line_length": 99, "alphanum_fraction": 0.7097425543, "num_tokens": 1236, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324713956854, "lm_q2_score": 0.8652240773641087, "lm_q1q2_score": 0.7053587629005941}}
{"text": "\\documentclass{article} \r\n\r\n\\usepackage[utf8]{inputenc}\r\n\\usepackage{amssymb,amsmath}\r\n\r\n\\usepackage{graphicx}\r\n\r\n\\usepackage[top=3cm, bottom=3cm, left=3cm, right=3cm, includefoot]{geometry}\r\n\r\n\\usepackage{amsthm}\r\n\\theoremstyle{definition}\r\n\\newtheorem{definition}{Definition}\r\n\r\n\\begin{document}\r\n\r\n\\begin{definition}\r\n\\emph{Convex polytope} $\\mathbf{S}$ is the set of all convex combinations of a finite point set $ \\mathcal{S}$, i.e.\r\n\\begin{displaymath}\r\n \\mathbf{S} :=\r\n \\left\\lbrace \r\n v \\in \\mathbb{R}^n: v := \\sum\\limits_{i=1}^{\\vert \\mathcal{S} \\vert} \\alpha_i v_i; \r\n\t\\forall i = 1,\\dots,\\vert \\mathcal{S} \\vert: \\alpha_i \\geq 0, v_i \\in \\mathcal{S}, \r\n\t\\sum\\limits_{i=1}^{\\vert \\mathcal{S} \\vert} \\alpha_i = 1 \r\n \\right\\rbrace.\r\n\\end{displaymath}\r\n\\end{definition}\r\n\r\nLet us consider two convex polytopes $\\mathbf{P}, \\mathbf{Q}$ in $\\mathbb{R}^d$ defined by the boundary point sets\r\n\\begin{displaymath}\r\n \\begin{array}{rcll}\r\n  \\mathcal{P} & := & \\lbrace p_1, \\dots, p_{n_p} \\rbrace \\subset \\mathbb{R}^d ~\\mathrm{,} \\\\\r\n  \\mathcal{Q} & := & \\lbrace q_1, \\dots, q_{n_q} \\rbrace \\subset \\mathbb{R}^d ~\\mathrm{.}\r\n \\end{array}\r\n\\end{displaymath}\r\nThe problem is to find the shortest distance between these two objects\r\n\\begin{equation}\r\n \\label{eq:polytope_problem1}\r\n \\min\\limits_{p \\in \\mathcal{P}, q \\in \\mathcal{Q}} \\Vert p - q \\Vert ~\\mathrm{.}\r\n\\end{equation}\r\nEvery interior point of the convex polytope can be expressed as a convex linear combination of given points in sets $\\mathcal{P}$ and $\\mathcal{Q}$\r\n\\begin{equation}\r\n \\label{eq:polytope_linear_comb}\r\n \\begin{array}{l}\r\n  \\forall p \\in \\mathbf{P} ~ \\exists \\alpha_1, \\dots, \\alpha_{n_p} \\in \\mathbb{R}: p = \\sum\\limits_{i = 1}^{n_p} \\alpha_{i} p_i ~\\mathcal{,} \\\\\r\n\t~~~~~~~~~~~~~~~~~~~~~~~ \\mathrm{where} ~ \\sum\\limits_{i = 1}^{n_p} \\alpha_i = 1 ~ \\mathrm{and} ~ 0 \\leq \\alpha_i \\leq 1 ~\\forall i = 1,\\dots,n_p ~\\mathrm{,} \\\\\r\n  \\forall q \\in \\mathbf{Q} ~ \\exists \\beta_1, \\dots, \\beta_{n_q} \\in \\mathbb{R}: q = \\sum\\limits_{i = 1}^{n_q} \\beta_{i} q_i ~\\mathcal{,} \\\\\r\n\t~~~~~~~~~~~~~~~~~~~~~~~ \\mathrm{where} ~ \\sum\\limits_{i = 1}^{n_q} \\beta_i = 1 ~ \\mathrm{and} ~ 0 \\leq \\beta_i \\leq 1 ~\\forall i = 1,\\dots,n_q ~\\mathrm{.}\r\n \\end{array}\r\n\\end{equation} \r\nWe denote\r\n\\begin{displaymath}\r\n \\begin{array}{rcl}\r\n  y & := & [\\alpha_1, \\dots, \\alpha_{n_p}, \\beta_1, \\dots, \\beta_{n_q}]^T \\in \\mathbb{R}^{n_p + n_q} ~\\mathrm{,} \\\\\r\n  C & := & [p_1, \\dots, p_{n_p}, -q_1, \\dots, -q_{n_q}] \\in \\mathbb{R}^{d, n_p + n_q} ~\\mathrm{,} \\\\\r\n  B & := & \r\n  \\left[\r\n   \\begin{array}{cccccc}\r\n    1 & \\dots & 1 & 0 & \\dots & 0 \\\\\r\n    0 & \\dots & 0 & 1 & \\dots & 1 \r\n   \\end{array}   \r\n  \\right] \\in \\mathbb{R}^{2, n_p + n_q}  ~\\mathrm{,} \\\\\r\n  c & := & [1,1]^T \\in \\mathbb{R}^{2} \\mathrm{.}\r\n \\end{array}  \r\n\\end{displaymath}\r\nAfterwards, the cost function can be reformulated\r\n\\begin{displaymath}\r\n \\Vert p - q \\Vert  = \\left\\Vert \\sum\\limits_{i = 1}^{n_p} \\alpha_{i} p_i - \\sum\\limits_{i = 1}^{n_q} \\beta_{i} q_i \\right\\Vert = \\Vert Cy \\Vert\r\n\\end{displaymath} \r\nand the feasible set conditions have the form\r\n\\begin{displaymath}\r\n By = c ~~~ \\wedge ~~~ y \\geq 0 ~\\mathrm{.}\r\n\\end{displaymath}\r\nAfter these notations, the problem \\eqref{eq:polytope_problem1} can be reformulated as\r\n\\begin{equation}\r\n \\label{eq:polytope_problem2}\r\n \\begin{array}{rcl}\r\n  \\bar{y} & := & \\arg \\min\\limits_{y \\in \\Omega_E \\cap \\Omega_I} y^T C^T C y ~\\mathrm{,} \\\\\r\n  \\Omega_E & := & \\left\\lbrace y \\in \\mathbb{R}^{n_p + n_q}: By = c \\right\\rbrace ~\\mathrm{,} \\\\\r\n  \\Omega_I & := & \\left\\lbrace y \\in \\mathbb{R}^{n_p + n_q}: y \\geq 0 \\right\\rbrace ~\\mathrm{.}\r\n \\end{array}\r\n\\end{equation}\r\nThe next step consists of homogenization and orthogonalization. We introduce a substitution\r\n\\begin{equation}\r\n \\label{eq:polytope_subs}\r\n x := y - y_{\\mathrm{in}} ~~ \\Rightarrow ~~ y = x + y_{\\mathrm{in}} ~\\mathrm{,}\r\n\\end{equation}\r\nwhere $y_{in}$ is arbitrary point from $\\Omega_E$. We can choose\r\n\\begin{displaymath}\r\n y_{\\mathrm{in}} := \\left[ \\frac{1}{n_p}, \\dots, \\frac{1}{n_p}, \\frac{1}{n_q}, \\dots, \\frac{1}{n_q} \\right] \\in \\mathbb{R}^{n_p + n_q} ~\\mathrm{.} \r\n\\end{displaymath}\r\nAfterwards, the cost function and conditions have the form\r\n\\begin{displaymath}\r\n \\begin{array}{l}\r\n  f(x) := \\frac{1}{2} \\Vert C(x + y_{\\mathrm{in}}) \\Vert^2 = \\frac{1}{2} x^T \\overbrace{C^T C}^{=: A} x + x^T \\overbrace{C^T C y_{\\mathrm{in}}}^{=: - b} + ~c, ~~~ c =: \\frac{1}{2} y_{\\mathrm{in}}^T C^T C y_{\\mathrm{in}} = ~\\mathrm{const.} ~\\mathrm{,}\\\\\r\n  B(x + y_{\\mathrm{in}}) = Bx + B y_{\\mathrm{in}} = Bx + c ~~~ \\Rightarrow ~~~ ( By = c ~ \\Leftrightarrow ~ Bx = 0) ~\\mathrm{,} \\\\\r\n  y \\geq 0 ~~ \\Leftrightarrow ~~ x \\geq - y_{\\mathrm{in}}  ~\\mathrm{.}\r\n \\end{array}\r\n\\end{displaymath}\r\nMoreover, the matrix $B$ can be orthonormalized using simple process\r\n\\begin{displaymath}\r\n \\hat{B} := \r\n \\left[\r\n  \\begin{array}{cc}\r\n   \\frac{1}{\\sqrt{n_p}} & 0 \\\\\r\n   0 & \\frac{1}{\\sqrt{n_q}}\r\n  \\end{array}\r\n \\right] \r\n B  ~\\mathrm{.}\r\n\\end{displaymath}\r\nWe obtained QP with homogeneous orthogonal linear equality constraints and bound inequality constraints\r\n\\begin{equation}\r\n \\label{eq:polytope_problem3}\r\n \\begin{array}{rcl}\r\n  \\bar{x} & := & \\arg \\min\\limits_{x \\in \\Omega_E \\cap \\Omega_I} \\frac{1}{2} x^T A x - b^T x ~\\mathrm{,} \\\\\r\n  \\Omega_E & := & \\left\\lbrace x \\in \\mathbb{R}^{n_p + n_q}: \\hat{B}x = 0 \\right\\rbrace ~\\mathrm{,} \\\\\r\n  \\Omega_I & := & \\left\\lbrace x \\in \\mathbb{R}^{n_p + n_q}: x \\geq -y_{\\mathrm{in}} \\right\\rbrace ~\\mathrm{.}\r\n \\end{array}\r\n\\end{equation}\r\nAfter solving this problem, the original solution can be obtained using back substitution \\eqref{eq:polytope_subs} to obtain $y$, i.e. the coeficients of linear combinations \\eqref{eq:polytope_linear_comb} of the nearest points from each polytope.\r\n\r\n%\\newpage\r\n\r\n\\paragraph{Numerical example}\r\n\r\nWe consider two circles discretized by parameter $m \\geq 3$, whose boundary points are defined by $P, Q \\in \\mathbb{R}^{2,m}$\r\nwith columns\r\n\\begin{displaymath}\r\n P_{\\ast,i} = \r\n \\left[\r\n  \\begin{array}{c}\r\n   \\cos (2i\\pi / m ) - 2  \\\\\r\n   \\sin (2i\\pi / m ) \r\n  \\end{array}\r\n \\right]\r\n , ~~~\r\n Q_{\\ast,i} = \r\n \\left[\r\n  \\begin{array}{c}\r\n   \\cos (\\pi - 2i\\pi / m ) + 2 \\\\\r\n   \\sin (\\pi - 2i\\pi / m ) \r\n  \\end{array}\r\n \\right], ~~~\r\n i = 0,\\dots,m-1 ~\\mathrm{.} \r\n\\end{displaymath}\r\nExamples for $m = 5$ and $m=7$ can be found in Fig. \\ref{fig:polytope1}.\r\n\r\n\\begin{figure}[h!]\r\n\\begin{center}\r\n\\includegraphics[width=0.45\\textwidth]{polytope_n5.eps}\r\n\\includegraphics[width=0.45\\textwidth]{polytope_n7.eps}\r\n\\caption[Polytope distance: testing benchmark]{Testing benchmark for polytopes distance with discretization parameter $m = 5$ \\emph{(left)} and $m = 7$ \\emph{(right)}.}\r\n\\label{fig:polytope1}\r\n\\end{center}\r\n\\end{figure}\r\n\r\nThe solution of the problem for any $m$ is given by\r\n\\begin{displaymath}\r\n \\bar{y} =\r\n \\left[\r\n  \\alpha_1, \\dots, \\alpha_m, \\beta_1, \\dots, \\beta_m\r\n \\right]^T = \r\n [\\underbrace{1 , 0, \\dots, 0}_{\\in \\mathbb{R}^m}, \\underbrace{1 , 0, \\dots, 0}_{\\in \\mathbb{R}^m}]^T ~\\mathrm{.}  \r\n\\end{displaymath}\r\n\r\nIn this problem, we can directly compute the regular condition number of Hessian matrix \r\n\\begin{displaymath}\r\n \\kappa (A) = \\kappa (C^T C) = \\kappa (CC^T) = \\kappa\r\n \\left( \\left[\r\n  \\begin{array}{cc}\r\n   \\sum\\limits_{i = 1}^{n_p} P_{i,1}^2 + \\sum\\limits_{i = 1}^{n_q} Q_{i,1}^2 & \\sum\\limits_{i = 1}^{n_p} P_{i,1} P_{i,2} + \\sum\\limits_{i = 1}^{n_q} Q_{i,1} Q_{i,2} \\\\\r\n   \\sum\\limits_{i = 1}^{n_p} P_{i,2} P_{i,1} + \\sum\\limits_{i = 1}^{n_q} Q_{i,2} Q_{i,1} & \\sum\\limits_{i = 1}^{n_p} P_{i,2}^2 + \\sum\\limits_{i = 1}^{n_q} Q_{i,2}^2\r\n  \\end{array}\r\n \\right] \\right) ~\\mathrm{.}\r\n\\end{displaymath}\r\nMoreover, it holds\r\n\\begin{displaymath}\r\n \\begin{array}{rcl}\r\n \\sum\\limits_{i = 1}^{n_p} P_{i,2} P_{i,1} + \\sum\\limits_{i = 1}^{n_q} Q_{i,2} Q_{i,1} & = &\r\n\t\\sum\\limits_{i = 0}^{m-1} \r\n\t\t\\left( \\cos \\left( \\frac{2i\\pi}{m} \\right) - 2 \\right)\r\n\t\t\\sin \\left( \\frac{2i\\pi}{m} \\right) \\\\\r\n  & & ~~~~~ + \r\n \\sum\\limits_{i = 0}^{m-1} \r\n  \\left( \\cos \\left( \\pi - \\frac{2i\\pi}{m} \\right) + 2 \\right)\r\n  \\sin \\left( \\pi - \\frac{2i\\pi}{m} \\right)\r\n = 0~\\mathrm{,}\r\n \\end{array} \r\n\\end{displaymath}\r\nso\r\n\\begin{displaymath}\r\n \\kappa (A) = \\kappa\r\n \\left( \\left[\r\n  \\begin{array}{cc}\r\n   \\sum\\limits_{i = 1}^{n_p} P_{i,1}^2 + \\sum\\limits_{i = 1}^{n_q} Q_{i,1}^2 & 0 \\\\\r\n   0 & \\sum\\limits_{i = 1}^{n_p} P_{i,2}^2 + \\sum\\limits_{i = 1}^{n_q} Q_{i,2}^2\r\n  \\end{array}\r\n \\right] \\right) ~\\mathrm{.}\r\n\\end{displaymath}\r\nAfterwards, the condition number can be expressed\r\n\\begin{displaymath}\r\n\\kappa (A) = \\frac{\\sum\\limits_{i = 1}^{n_p} P_{i,1}^2 + \\sum\\limits_{i = 1}^{n_q} Q_{i,1}^2}{\\sum\\limits_{i = 1}^{n_p} P_{i,2}^2 + \\sum\\limits_{i = 1}^{n_q} Q_{i,2}^2} =\r\n\\frac{\\sum\\limits_{i=0}^{m-1} \\left( \\cos \\left( \\frac{2i\\pi}{m} \\right) - 2 \\right)^2}{\\sum\\limits_{i=0}^{m-1} \\sin^2 \\left( \\frac{2i\\pi}{m} \\right)} ~~~~ \\forall m \\geq 3 ~\\mathrm{.}\r\n\\end{displaymath}\r\n\r\n\\noindent Let us consider $\\alpha \\in \\mathbb{R}$ and let us present a complex number $z \\in \\mathbb{C}$ by prescription\r\n\\begin{displaymath}\r\n z := \\cos \\alpha + \\mathbf{i} \\sin \\alpha ~\\mathrm{,}\r\n\\end{displaymath}\r\nwhere $\\mathbf{i}$ is imaginary unit. Then by De Moivre's formula we can write\r\n\\begin{displaymath}\r\n \\sum\\limits_{i=0}^{m-1} \\left( \\cos ( i\\alpha) + \\mathbf{i} \\sin ( i \\alpha) \\right) =\r\n \\sum\\limits_{i=0}^{m-1} z^i =\r\n \\frac{z^m - 1}{z - 1} =\r\n \\frac{\\cos (m\\alpha) + \\mathbf{i} \\sin (m\\alpha) - 1}{z-1} ~\\mathrm{.}\r\n\\end{displaymath}\r\nIf we choose specific $\\alpha$ in previous equality, we obtain next\r\n\\begin{equation}\r\n \\label{eq:polytope_ne_pom}\r\n  \\begin{array}{ccccc}\r\n   \\alpha := \\frac{2 \\pi}{m}& ~ \\Rightarrow ~ & \\sum\\limits_{i=0}^{m-1} \\left( \\cos \\left( \\frac{2i\\pi}{m} \\right) + \\mathbf{i} \\sin \\left( \\frac{2i\\pi}{m} \\right) \\right) = 0 & ~ \\Rightarrow ~ & \\sum\\limits_{i=0}^{m-1} \\cos \\left( \\frac{2i\\pi}{m} \\right) = 0\\mathrm{,}\\\\ \r\n   \\alpha := \\frac{4 \\pi}{m}& ~ \\Rightarrow ~ & \\sum\\limits_{i=0}^{m-1} \\left( \\cos \\left( \\frac{4i\\pi}{m} \\right) + \\mathbf{i} \\sin \\left( \\frac{4i\\pi}{m} \\right) \\right) = 0 & ~ \\Rightarrow ~ & \\sum\\limits_{i=0}^{m-1} \\cos \\left( \\frac{4i\\pi}{m} \\right) = 0\\mathrm{.}\r\n  \\end{array}\r\n\\end{equation}\r\nNow, we return back to regular condition number and $\\forall m \\geq 3$ we can write (using \\eqref{eq:polytope_ne_pom})\r\n\\begin{displaymath} \r\n \\begin{array}{rl}\r\n   \\kappa (A) = & \\frac{\\sum\\limits_{i=0}^{m-1} \\left( \\cos \\left( \\frac{2i\\pi}{m} \\right) - 2 \\right)^2}{\\sum\\limits_{i=0}^{m-1} \\sin^2 \\left( \\frac{2i\\pi}{m} \\right)} \r\n= \\frac{\\sum\\limits_{i=0}^{m-1} \\cos^2 \\left( \\frac{2i\\pi}{m} \\right) - 4 \\cos \\left( \\frac{2i\\pi}{m} \\right) + 4}{\\sum\\limits_{i=0}^{m-1} \\sin^2 \\left( \\frac{2i\\pi}{m} \\right)} \\\\\r\n & = \\frac{\\sum\\limits_{i=0}^{m-1} \\left( \\frac{1 + \\cos \\left( \\frac{4i\\pi}{m} \\right)}{2} - 4 \\cos \\left( \\frac{2i\\pi}{m} \\right) + 4 \\right)}{\\sum\\limits_{i=0}^{m-1} \r\n  \\frac{1 - \\cos \\left( \\frac{4i\\pi}{m} \\right)}{2}} \r\n =  \\frac{ \\frac{1}{2} \\sum\\limits_{i=0}^{m-1} \\cos \\left( \\frac{4i\\pi}{m} \\right) - 4 \\sum\\limits_{i=0}^{m-1} \\cos \\left( \\frac{2i\\pi}{m} \\right) + \\sum\\limits_{i=0}^{m-1} \\frac{9}{2}   }{-\\frac{1}{2}\\sum\\limits_{i=0}^{m-1} \\cos \\left( \\frac{4i\\pi}{m} \\right) + \\sum\\limits_{i=0}^{m-1} \\frac{1}{2} } = 9 ~\\mathrm{.}\r\n \\end{array} \r\n\\end{displaymath}\r\n\r\n\r\n\\end{document}\r\n\r\n", "meta": {"hexsha": "9caec2e4414258e3342926e7e1f07f1b576da553", "size": 11282, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/test_03/polytope.tex", "max_stars_repo_name": "lukaspospisil/permon_examples", "max_stars_repo_head_hexsha": "5a47cdfcdf24fa55bb0ffca23a8aabaea8a4b629", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/test_03/polytope.tex", "max_issues_repo_name": "lukaspospisil/permon_examples", "max_issues_repo_head_hexsha": "5a47cdfcdf24fa55bb0ffca23a8aabaea8a4b629", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/test_03/polytope.tex", "max_forks_repo_name": "lukaspospisil/permon_examples", "max_forks_repo_head_hexsha": "5a47cdfcdf24fa55bb0ffca23a8aabaea8a4b629", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.4033613445, "max_line_length": 317, "alphanum_fraction": 0.6023754653, "num_tokens": 4711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7052476101896413}}
{"text": "\\section{Introduction}\n\nThe objective of this exercise is to study damped and driven oscillations in\nmechanical systems using the Pohl resonator. For driven oscillations, we will\nalso observe and quantify the mechanical resonance phenomenon. \n    \nIf a periodically varying external force is applied to a damped harmonic\noscillator, the resulting motion is called forced (or driven) oscillations, and\nthe external force is called the driving force. Assuming that the driving force\nis of the form \n    \\[\n        F=F_0(sin\\omega t+\\delta),\n    \\]\nwith the amplitude F 0 and angular frequency ω, the resulting steady-state\nforced oscillations will be simple harmonic with the angular frequency equal to\nthat of the driving force. The amplitude of these steady-state oscillations\nturns out to depend on the angular frequency of the the driving force, in\nparticular on how far it is from the natural angular frequency, and the damping\ncoefficient. The amplitude may become quite large, and this phenomenon is known\nas the mechanical resonance. \n\nAnother interesting property of driven steady-state oscillations is the fact\nthat there is a phase lag between the driving force and the displacement from\nthe equilibrium position of the oscillating particle. This phase lag reaches\n$\\pi/2$ (a quarter of the cycle) when the system is driven at the natural\nangular frequency.\n    \nIn this experiment, forced oscillation of a balance wheel will be studied. The\ncorresponding quantities (such as the force and the position) will be replaced\nby their angular counterparts. \n\nThe driving torque $\\tau_{dr}=\\tau_0cos\\omega t$ and a damping torque\n$\\tau_f=-b\\frac{d\\theta}{dt}$, Also, we know the restoring torque\n$\\tau=-k\\theta$, its equation od motion is of the form \n\n\\begin{equation}\n\\label{1}\nI\\frac{d^2\\theta}{dt^2}=-k\\theta-b\\frac{d\\theta}{dt}+\\tau_0cos\\omega t,\n\\end{equation}\n\nwhere I is the moment of inertia of the balance wheel, $\\tau_0$ is the amplitude\nof the driving torque, and $\\omega$ is the angular frequency of the driving\ntorque. Introducing the symbols \n\n\\[\n\\omega_0=\\frac{k}{I},\\quad 2\\beta=\\frac{b}{I}, \\quad \\mu=\\frac{\\tau_0}{I}, \n\\]\n\nEq. \\ref{1} can be rewitten as\n\\begin{equation}\n\\label{2}\n\\frac{d^2\\theta}{dt^2}+2\\beta\\frac{d\\theta}{dt}+\\omega_0^2\\theta\n=\\mu cos\\omega t.\n\\end{equation}\n\nThw solution to Eq \\ref{2} is\n\\[\n\\theta(t)=\\theta_{tr}(t)+\\theta_{st}cos(\\omega t+\\varphi),\n\\]\nwhere the former term $\\theta_{tr}$ denotes the transient solution that vanished\nexponentially as $t\\rightarrow \\infty$. The steady-state  oscillation is with\nthe amplitude \n\\[\n\\theta_{st}=\\frac{\\mu}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}}\n\\]\nFor small values of the damping coefficient $\\beta$, the resonance angular\nfrequency is close to the the natural angular frequency, and the amplitude of\nsteady-state oscillations becomes large. The dependence of both the amplitude\nand the phase shift on the driving angular frequency are shown in the left and\nright Figure 1, respectively, for different values of the damping coefficient.", "meta": {"hexsha": "1d3659098667f3bb45355767cdfc117a035ec570", "size": 3037, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "E5/part/1i.tex", "max_stars_repo_name": "iamwrm/VP141", "max_stars_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-24T11:28:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T11:28:04.000Z", "max_issues_repo_path": "E5/part/1i.tex", "max_issues_repo_name": "iamwrm/VP141", "max_issues_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "E5/part/1i.tex", "max_forks_repo_name": "iamwrm/VP141", "max_forks_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.3857142857, "max_line_length": 80, "alphanum_fraction": 0.7655581166, "num_tokens": 797, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8577681013541611, "lm_q1q2_score": 0.705247609441842}}
{"text": "\\section{Basics of Reinforcement Learning}\n\\label{sec:basics_reinforcement_learning}\n\n\\emph{Reinforcement Learning} (RL) is a general class of algorithms in the field of \\emph{Machine Learning} (ML) that allows an agent to learn how to behave in a stochastic and possibly unknown environment, where the only feedback consists of a scalar reward signal \\cite{sutton1998introduction}. The goal of the agent is to learn by trial-and-error which actions maximize his long-run rewards. However, since the environment evolves stochastically and may be influenced by the actions chosen, the agent must balance his desire to obtain a large immediate reward by acting greedily and the opportunities that will be available in the future. Thus, RL algorithms can be seen as computational methods to solve sequential decision problems by directly interacting with the environment.\\\\\n\n\\subsection{Markov Decision Processes}\n\\label{sec:markov_decision_processes}\nSequential decision problems are typically formalized using \\emph{Markov Decision Processes} (MDP). An MDP is a stochastic dynamical system specified by the tuple $<\\S, \\A, \\calP, \\calR, \\gamma>$, where $(\\S, \\calS)$ is a measurable state space, $(\\A, \\calA)$ is a measurable action space, $\\calP: \\S \\times \\A \\times \\calS \\to \\R$ is a Markov transition kernel, $\\calR: \\S \\times \\A \\to \\R$ is a reward function and $0 < \\gamma < 1$ is the discount factor. Suppose that at time $t$ the system is in state $S_t = s$ and that the agent takes action $A_t = a$, then, regardless of the previous history of the system, the probability to find the system in a state belonging to $B\\in\\calS$ at time $t+1$ is given by \n\\begin{equation}\n\t\\calP(s, a, B) = \\P{S_{t+1} \\in B | S_t = s, A_t = a}\n\\end{equation}\nFollowing this random transition, the agent receives a stochastic reward\n$R_{t+1}$. The reward function $\\calR(s, a)$ gives the expected reward\nobtained when action $a$ is taken in state $s$, i.e. \n\\begin{equation}\n\t\\calR(s, a) = \\E{R_{t+1} | S_t = s, A_t = a}\n\\end{equation}\nThis feedback mechanism between the environment and the agent is illustrated in Figure \\ref{fig:sequential_decision_problem}. At any time step, the agent selects his actions according to a certain policy $\\pi: \\S \\times \\calA \\to \\R$ such that for every $s \\in \\S$, $C \\mapsto \\pi(s,C)$ is a probability distribution over $(\\A, \\calA)$. Hence, a policy $\\pi$ and an initial state $s_0 \\in \\S$ determine a random state-action-reward sequence ${\\{(S_t, A_t, R_{t+1})\\}}_{t\\geq 0}$ with values on $\\S \\times \\A \\times \\R$.\n\\begin{figure}[t]\n\t\\centering\n\t\\begin{tikzpicture}[node distance = 6em, auto, thick]\n\t\t\\node [block] (Agent) {Agent};\n\t\t\\node [block, below of=Agent] (Environment) {Environment};\t\t    \n\t\t\\path [line] (Agent.0) --++ (4em,0em) |- node [near start]{Action $a_t$} (Environment.0);\n\t\t\\path [line] (Environment.190) --++ (-6em,0em) |- node [near start]{State  $s_{t}$} (Agent.170);\n\t\t\\path [line] (Environment.170) --++ (-4.25em,0em) |- node [near start, right] {Reward $r_{t+1}$} (Agent.190);\n\t\\end{tikzpicture}\n\t\\caption{Agent-environment interaction in sequential decision problems.}\n\t\\label{fig:sequential_decision_problem}\n\\end{figure}\nIn an infinite horizon task, the agent's performance is typically measured as the total discounted reward obtained following a specific policy\n\\begin{equation}\n\tG_t = \\sum^{\\infty}_{t=0} \\gamma^t R_{t+k+1} \n\\end{equation}\nSince this gain is stochastic, the agent considers its expected value, which is typically called \\emph{state-value function}\n\\begin{equation}\n\tV_\\pi(s) = \\E[\\pi]{G_t|S_t = s}\n\\end{equation}\nwhere the subscript in $\\mathbb{E}_{\\pi}$ indicates that all the actions are selected according to policy $\\pi$. The state-value function measures how good it is for the agent to be in a given state and follow a certain policy. Similarly, we introduce the \\emph{action-value function}\n\\begin{equation}\n\tQ_\\pi(s,a) = \\E[\\pi]{G_t|S_t = s, A_t = a}\n\\end{equation}\nWe have the following relationship between $V_\\pi$ and $Q_\\pi$\n\\begin{equation}\n\tV_\\pi(s) = \\int_\\A \\pi(s,a) Q_\\pi(s,a) da\n\\end{equation}\nAlmost all reinforcement learning algorithms are designed to estimate these \nvalue functions and are typically based on the Bellman equations.\n\\begin{equation}\n\tV_\\pi(s) = \\calR_\\pi(s) + \\gamma T_\\pi V_\\pi(s)\t\n\t\\label{eq:bellman_expectation_eq_V}\n\\end{equation}\n\\begin{equation}\n\t\tQ_\\pi(s,a) = \\calR(s,a) + \\gamma T_a V_\\pi(s)\n\t\t\\label{eq:bellman_expectation_eq_Q}\n\\end{equation}\nwhere we denoted by $T_a$ (resp. $T_\\pi$) the transition operator for action \n$a$ (resp. for policy $\\pi$)\n\\begin{equation}\n\tT_a F(s) = \\E{F(S_{t+1})|S_t = s, A_t = a} = \\int_\\S \\calP(s, a, s') F(s') ds'\n\\end{equation}\n\\begin{equation}\n\tT_\\pi F(s) = \\E[\\pi]{F(S_{t+1})|S_t = s} = \\int_\\A \\pi(s,a) \\int_\\S \\calP(s,a,s') F(s') ds'\tda\n\\end{equation}\nThese equations can be rewritten as fixed-point equations which, under some formal assumptions on the reward functions, admit a unique solution by the contraction mapping theorem. The agent's goal is to select a policy $\\pi_*$ that maximizes his expected return in all possible states. Such a policy is called \\emph{optimal} and the corrisponding value functions are called \\emph{Optimal State-Value Function}\n\\begin{equation}\n\tV_*(s) = \\sup_\\pi V_\\pi(s)\n\\end{equation}\nand \\emph{Optimal Action-Value Function}\n\\begin{equation}\n\tQ_*(s,a) = \\sup_\\pi Q_\\pi(s,a)\n\\end{equation}\nThe optimal value functions satisfy the following Bellman equations.\n\\begin{equation}\n\tV_*(s) = \\sup_a Q_*(s,a) = \\sup_a \\left\\{\\calR(s,a) + \\gamma T_a V_*(s)\\right\\}\n\\end{equation}\n\\begin{equation}\n\t\\begin{split}\n\t\tQ_*(s,a) &= \\calR(s,a) + \\gamma T_a V_*(s)\\\\\n\t\t\t &= \\calR(s,a) + \\gamma \\int_\\S \\calP(s,a,s') \\sup_{a'} Q_*(s', a') ds'\n\t\\end{split}\n\\end{equation}\nAgain, these are fixed-point equations for which the existence and uniqueness of a solution is guaranteed by the contraction mapping theorem. Given the optimal action-value function $Q_*$, an optimal policy is obtained by selecting in each state the action with maximizes $Q_*$\n\\begin{equation}\n\ta_* = \\argsup_a Q_*(s,a)\n\\end{equation}\nThis greedy policy is deterministic and only depends on the current state of the system.\n\n\\subsection{Policy Gradient Methods}\nThe standard way to solve MDPs is through dynamic programming, which simply consists in solving the Bellman fixed-point equations discussed in the previous chapter. Following this approach, the problem of finding the optimal policy is transformed into the problem of finding the optimal value function. However, apart from the simplest cases where the MDP has a limited number of states and actions, dynamic programming becomes computationally infeasible. Moreover, this approach requires complete knowledge of the Markov transition kernel and of the reward function, which in many real-world applications might be unknown or too complex to use. \\emph{Reinforcement Learning} (RL) is a subfield of Machine Learning which aims to turn the infeasible dynamic programming methods into practical algorithms that can be applied to large-scale problems. RL algorithms are based on two key ideas: the first is to use samples to compactly represent the unknown dynamics of the controlled system. The second idea is to use powerful function approximation methods to compactly estimate value functions and policies in high-dimensional state and action spaces. In this section we will only focus on a particular class of algorithms called \\emph{Policy Gradient Methods}, which have proved successful in many applications. For a more complete introduction to RL, the reader may consult \\cite{sutton1998introduction}, \\cite{szepesvari2010algorithms} or \\cite{wiering2012reinforcement}.\\\\\nIn \\emph{policy gradient methods} \\cite{peters2008reinforcement}, the optimal policy is approximated using a parametrized policy $\\pi: \\S \\times \\calA \\times \\Theta \\to \\R$ such that, given a parameter vector $\\theta \\in \\Theta \\subseteq \\R^{D_\\theta}$, $\\pi(s, B; \\theta) = \\pi_\\theta(s, B)$ gives the probability of selecting an action in $B \\in \\calA$ when the system is in state $s \\in \\S$.\nThe general goal of policy optimization in reinforcement learning is to\noptimize the policy parameters $\\theta \\in \\Theta$ so as to maximize a certain\nobjective function $J: \\Theta \\to \\R$\n\\begin{equation}\n\t\\theta^* = \\argmax_{\\theta \\in \\Theta} J(\\theta)\n\\end{equation}\nIn the following, we will focus on gradient-based and model-free methods that exploit\nthe sequential structure of the the reinforcement learning problem. The idea of\npolicy gradient algorithms is to update the policy parameters using the gradient ascent direction of the objective function\n\\begin{equation}\n\t\\theta_{k+1} = \\theta_k + \\alpha_k \\nabla_\\theta J\\left(\\theta_k\\right)\n\\end{equation}\nwhere $\\{\\alpha_k\\}_{k\\geq 0}$ is a sequence of learning rates. Typically, the\ngradient of the objective function is not known and its approximation is the key component of every policy gradient algorithm. It is a well-know result from stochastic optimization \\cite{kushner2003stochastic} that, if the gradient estimate is unbiased and the learning rates satisfy the \\emph{Robbins-Monro conditions}\n\\begin{equation}\n\t\\sum_{k=0}^\\infty \\alpha_k = \\infty \\;\\;\\;\\;\\;\\; \\sum^{\\infty}_{k=0}\n\t\\alpha_k^2 < \\infty \n\\end{equation}\nthe learning process is guaranteed to converge at least to a local optimum of\nthe objective function. In an episodic environment where the system always starts from an initial state $s_0$, the typical objective function is the start value.\n\\begin{equation}\n\tJ_{\\text{start}}(\\theta) = V_{\\pi_\\theta}(s_0) = \\E[\\pi_\\theta]{G_0 |\n S_0 = s_0}\n\\end{equation}\nIn a continuing environment, where no terminal state exists and the task might go on forever, it is common to use either the average value \n\\begin{equation}\n\tJ_{\\text{avV}}(\\theta) = \\E[S \\sim d^{\\theta}]{V_{\\pi_\\theta}(S)} = \\int_\\S\n\td^{\\theta}(s) V_{\\pi_\\theta}(s) ds\n\\end{equation}\nwhere $d^\\theta$ is the stationary distribution of the Markov chain induced by $\\pi_\\theta$. Alternatively, one may use the average reward per time step\n\\begin{equation}\n\tJ_{\\text{avR}}(\\theta) = \\rho(\\theta) = \\E[\\substack{S \\sim d^{\\theta}\\\\A \\sim \\pi_\\theta}]{\\calR(S,A)} \n\t= \\int_\\S d^{\\theta}(s) \\int_\\A \\pi_\\theta(s,a) \\calR(s,a) da ds\n\\end{equation}\nLuckily, the same methods apply with minor changes to the three objective functions. \n\n\\subsubsection{Policy Gradient Theorem}\nThe \\emph{policy gradient theorem} \\cite{sutton1999policy} shows that the gradient can be rewritten in a form suitable for estimation from experience aided by an approximate action-value or advantage function.\n\\begin{theorem}[Policy Gradient]\n\\label{thm:risk_neutral_policy_gradient}\n\tLet $\\pi_\\theta$ be a differentiable policy. The policy gradient for the average reward formulation is given by\n\t\\begin{equation}\n\t\t\\nabla_\\theta \\rho(\\theta) =\n\t\t\\E[\\substack{S \\sim d^\\theta\\\\A \\sim \\pi_\\theta}]{\\nabla_\\theta\\log\n\t\t\\pi_\\theta(S,A) Q_{\\theta}(S, A)}\n\t\\end{equation}\n\twhere $d^\\theta$ is the stationary distribution of the Markov chain induced by $\\pi_\\theta$. The policy gradient for the start value formulation is given by\n\t\\begin{equation}\n\t\t\\nabla_\\theta J_{\\text{start}}(\\theta) =\n\t\t\\E[\\substack{S \\sim d_\\gamma^\\theta(s_0, \\cdot)\\\\A \\sim \\pi_\\theta}]{\\nabla_\\theta\\log\n\t\t\\pi_\\theta(S,A) Q_{\\theta}(S, A)}\n\t\\end{equation}\n\twhere $d_\\gamma^\\theta(s_0, \\cdot)$ is the $\\gamma$-discounted visiting distribution over states starting from the initial state $s_0$ and following policy $\\pi_\\theta$\n\t\t\\begin{equation}\n\t\t\td_\\gamma^\\theta(s, x) = \\sum_{k=0}^{\\infty} \\gamma^k \\calP_\\theta^{(k)}(s, x)\n\t\t\\end{equation}\n\\end{theorem}\nLet us notice that we can subtract a state-dependent baseline from the action-value function without changing the value of the expectation, indeed\n\\begin{equation*}\n\t\\begin{split}\n\t\\E[\\substack{S \\sim d^\\theta\\\\A \\sim \\pi_\\theta}]{\\nabla_\\theta\\log\n\t\t\t\\pi_\\theta(S,A) B_\\theta(S)} \n\t&= \\int_\\S d^\\theta(s) \\int_\\A \\pi_\\theta(s,a) \\nabla_\\theta\\log\n\t\t\t\t\\pi_\\theta(s,a) B_\\theta(s) da ds\\\\\n\t&= \\int_\\S d^\\theta(s)  B_\\theta(s) \\int_\\A \\nabla_\\theta \\pi_\\theta(s,a) da ds\\\\\n\t&= \\int_\\S d^\\theta(s)  B_\\theta(s)  \\nabla_\\theta  \\underbrace{\\int_\\A  \\pi_\\theta(s,a) da}_{= 1} ds = 0\n\t\\end{split}\n\\end{equation*}\nHence, the policy gradient theorem can be rewritten as \n\\begin{equation}\n\\label{eq:pg_theorem_baseline}\n\t\\nabla_\\theta \\rho(\\theta) =\n\t\\E[\\substack{S \\sim d^\\theta\\\\A \\sim \\pi_\\theta}]{\\nabla_\\theta\\log\n\t\\pi_\\theta(S,A) \\left(Q_{\\pi_\\theta}(S, A) - B_\\theta(S)\\right)}\n\\end{equation}\nThe baseline can be chosen so as to minimize the variance of the gradient estimate which can prove beneficial for the algorithm convergence \\cite{peters2008reinforcement}. This result can be used as the starting point to derive several policy gradient methods that use different approximation of the action-value function, which is typically unknown. For instance, in an episodic MDP the action-value function can be estimated with the total return obtained on a sample trajectory\n\\begin{equation}\n\tQ_\\theta(s_0,a_0) \\approx \\sum_{t=0}^{T^{(m)}} \\gamma^t r_{t+1}^{(m)}\n\\end{equation}\nCombining this remark with a Monte Carlo approximation of Eq. (\\ref{eq:pg_theorem_baseline}), we obtain the \\emph{Monte Carlo Policy Gradient} algorithm \\cite{baxter2001infinite} (also known as GPOMDP) for which the pseudocode is reported in Algorithm \\ref{algo:GPOMDP}.\n\\begin{algorithm}[t]\n\t\\caption{GPOMDP}\n\t\\label{algo:GPOMDP}\n\t\\begin{algorithmic}[0]\n\t\t\\Require{\\\\\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item Initial policy parameters $\\theta_0 = (\\theta_0^1, \\ldots, \\theta_0^{D_\\theta})^T$\n\t\t\t\t\\item Learning rate $\\{\\alpha_k\\}$\n\t\t\t\t\\item Number of trajectories $M$\n\t\t\t\\end{itemize}\n\t\t} \n\t\t\\Ensure Approximation of the optimal policy $\\pi_{\\theta^*} \\approx \\pi_*$\n\t\t\\begin{algorithmic}[1]\n\t\t\\State Initialize $k = 0$\n\t\t\\Repeat\n\t\t\t\\State Sample $M$ trajectories $h^{(m)} = \\{(s_t^{(m)}, a_t^{(m)}, r_{t+1}^{(m)}\\}_{t = 0}^{T^{(m)}}$ of the MDP under policy $\\pi_{\\theta_k}$\n\t\t\t\\State Compute the optimal baseline \n\t\t\t\\begin{equation}\n\t\t\t\t\\widehat{b}_k^n = \\frac{\\sum^{M}_{m=1} \\left[ \\sum_{i=0}^{T^{(m)}} \n\t\t\t\t\t\t\t\t\t\\partial_{\\theta_k} \\log \\pi_\\theta\\left(s_i^{(m)}, a_i^{(m)}\\right) \\right]^2 \n\t\t\t\t\t\t\t\t\t\\sum^{T^{(m)}}_{j=0} \\gamma^j r_{j+1}^{(m)}}{\\sum^{M}_{m=1} \\left[ \\sum_{i=0}^{T^{(m)}} \\partial_{\\theta_k} \\log \\pi_\\theta\\left(s_i^{(m)}, a_i^{(m)}\\right) \\right]^2}\n\t\t\t\\end{equation}\n\t\t\t\\State Approximate policy gradient\n\t\t\t\\begin{equation}\n\t\t\t\t\\frac{\\partial}{\\partial\\theta^n} J_{\\text{start}}(\\theta_k) \\approx \\widehat{g}_k^n = \\frac{1}{M} \\sum^{M}_{m=1} \\sum_{i=0}^{T^{(m)}} \n\t\t\t\t\t\\frac{\\partial}{\\partial\\theta^n} \\log \\pi_{\\theta_k}\\left(s_i^{(m)}, a_i^{(m)}\\right) \\left( \n\t\t\t\t\t\\sum^{T^{(m)}}_{j=i} \\gamma^j r_{j+1}^{(m)} - \\widehat{b}_k^n \\right)\n\t\t\t\\end{equation}\n\t\t\t\\State Update actor parameters $\\theta_{k+1} = \\theta_k + \\alpha_k \\widehat{g}_k $. \n\t\t\t\n\t\t\t\\State $k \\leftarrow k + 1$\n\t\t\\Until{converged}\n\t\t\\end{algorithmic}\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\subsubsection{Parameter-Based Policy Gradient Methods}\nIn Monte Carlo Policy Gradient, trajectories are generated by sampling at each\ntime step an action according to a stochastic policy $\\pi_\\theta$ and the\nobjective function gradient is estimated by differentiating the policy with\nrespect to the parameters. However, sampling an action from the policy at each\ntime step leads to a large variance in the sampled histories and therefore in \nthe gradient estimate, which can in turn slow down the convergence of the\nlearning process. To address this issue, the \\emph{policy gradient with parameter-based exploration} (PGPE) method \\cite{sehnke2008policy} replaces the search in the policy space with a direct search in the model parameter space. Given an episodic MDP, PGPE considers a deterministic controller $F: \\S \\times \\Theta \\to \\A$ that, given a set of parameters $\\theta \\in \\Theta \\subseteq \\R^{D_\\theta}$, maps a state $s \\in \\S$ to an action $a = F(s; \\theta) = F_\\theta(s) \\in \\A$. The policy parameters are drawn from a probability distribution $p_\\xi$, with hyper-parameters $\\xi \\in \\Xi \\subseteq \\R^{D_\\xi}$. Combining these two hypotheses, the agent follows a stochastic policy $\\pi_\\xi$ defined by\n\\begin{equation}\n\t\\forall B \\in \\calA ,\\ \\pi_\\xi(s,B) = \\pi(s, B; \\xi) = \\int_\\Theta p_\\xi(\\theta) \n\t\\ind{F_{\\theta}(s)\\in B} d\\theta\n\\end{equation}\nIn this setting, the policy gradient theorem can be reformulated in the following way \n\\begin{theorem}[Parameter-Based Policy Gradient]\n\tLet $p_\\xi$ be differentiable with respect to $\\xi$, then the gradient of the average reward is given by\n\t\\begin{equation}\n\t\t\\nabla_\\xi J(\\xi) = \\E[\\substack{S \\sim d^\\xi\\\\\\theta \\sim p_\\xi}]{\\nabla_\\xi \\log p_\\xi(\\theta) Q_{\\pi_\\xi}(S, \\theta)}\n\t\\end{equation}\n\twhere we denoted $Q_\\xi(S, \\theta) = Q_\\xi(S, F_\\theta(S))$.\n\\end{theorem}\nThis expression is very similar to the original policy gradient theorem, but\nthe expectation is taken over the controller parameters instead of the action space and we have the likelihood score of the controller parameters distribution instead of that of the stochastic policy. Thus, we might interpret this result as if the agent directly selected the parameters $\\theta$ according to a policy $p_\\xi$, which then lead to an action through the deterministic mapping $F_\\theta$. Therefore, it is as if the agent's policy was in the parameters space and not in the control space. As in the standard policy gradient methods, we can subtract a state-dependent baseline $B_\\xi(S)$ to the gradient without increasing the bias\n\\begin{equation}\n\t\\nabla_\\xi J(\\xi) = \\E{\\nabla_\\xi \\log p_\\xi(\\theta) \\left(Q_{\\pi_\\xi}(S,\n\t\t\t\t\t\t\\theta) - B_\\xi(S)\\right)}\n\\end{equation}\nThe PGPE algorithm, which is outlined in Algorithm \\ref{algo:PGPE}, employs a Monte Carlo approximation of this gradient, where the action-value function is estimated using the returns on a sampled trajectory of the MDP. The benefit of this approach is that the controller is deterministic and therefore the actions do not need to be sampled at each time step, with a consequent reduction of the gradient estimate variance. Indeed, It is sufficient to sample the parameters $\\theta$ once at the beginning of the episode and then generate an entire trajectory following the deterministic policy $F_\\theta$. As an additional benefit, the parameter gradient is\nestimated by direct parameter perturbations, without having to backpropagate\nany derivatives, which allows to use non-differentiable controllers. Again the baseline can be chosen so as to minimize the gradient estimate variance \\cite{zhao2011analysis}.\n\\begin{algorithm}[t!]\n\t\\caption{Episodic PGPE algorithm}\n\t\\label{algo:PGPE}\n\t\\begin{algorithmic}[0]\n\t\t\\Require{\\\\\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item Initial hyper-parameters $\\xi_0 = (\\xi_0^1, \\ldots, \\xi_0^{D_\\xi})^T$\n\t\t\t\t\\item Learning rate $\\{\\alpha_k\\}$\n\t\t\t\t\\item Number of trajectories $M$\n\t\t\t\\end{itemize}\n\t\t} \n\t\t\\Ensure Approximation of the optimal policy $F_{\\xi^*} \\approx \\pi_*$\n\t\t\\begin{algorithmic}[1]\n\t\t\t\\State Initialize $k = 0$\n\t\t\t\\Repeat\n\t\t\t\t\\For {$m = 1, \\ldots, M$}\n\t\t\t\t\t\\State Sample controller parameters $\\theta^{(m)} \\sim p_{\\xi_k}$ \n\t\t\t\t\t\\State Sample trajectory $h^{(m)} = \\{(s_t^{(m)}, a_t^{(m)}, r_{t+1}^{(m)}\\}_{t = 0}^{T^{(m)}}$ under policy $F_{\\theta^{(m)}}$\n\t\t\t\t\\EndFor\n\t\t\t\t\\State Compute optimal baseline \n\t\t\t\t\\begin{equation}\n\t\t\t\t\t\\widehat{b}_k^n = \\frac{\\sum^{M}_{m=1} \\left[\\partial_{\\xi^n} \\log p_{\\xi_k} \\left(\\theta^{(m)}\\right)\\right]^2 \\sum^{T^{(m)}}_{j=0} \\gamma^j r_{j+1}^{(m)}}{\\sum^{M}_{m=1} \\left[\\partial_{\\xi^n} \\log p_{\\xi_k} \\left(\\theta^{(m)}\\right)\\right]^2}\n\t\t\t\t\\end{equation}\n\t\t\t\t\\State Approximate policy gradient\n\t\t\t\t\\begin{equation}\n\t\t\t\t\t\\frac{\\partial}{\\partial\\xi^n} J_{\\text{start}}(\\xi_k) \\approx \\widehat{g}_k^n = \\frac{1}{M} \\sum^{M}_{m=1}\n\t\t\t\t\t\t\\frac{\\partial}{\\partial\\xi^n} \\log p_{\\xi_k}\\left(\\theta^{(m)}\\right) \\left( \n\t\t\t\t\t\t\\sum^{T^{(m)}}_{j=i} \\gamma^j r_{j+1}^{(m)} - \\widehat{b}_k^n \\right)\n\t\t\t\t\\end{equation}\n\t\t\t\t\\State Update hyperparameters using gradient ascent $\\xi_{k+1} = \\xi_k + \\alpha_k \\widehat{g}_k^n$\n\t\t\t\t\\State $k \\leftarrow k + 1$\n\t\t\t\\Until{converged}\n\t\t\\end{algorithmic}\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\n", "meta": {"hexsha": "2abd4e0a385437c6698f556c3230cec8e305ebb2", "size": 20181, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Pacs/Report/Sections/2_basics_of_reinforcement_learning.tex", "max_stars_repo_name": "AmineAboussalah/Thesis", "max_stars_repo_head_hexsha": "1a3ae97023acff1ee5e2d197a446734117a6fb99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 80, "max_stars_repo_stars_event_min_datetime": "2016-06-13T15:20:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T23:47:13.000Z", "max_issues_repo_path": "Pacs/Report/Sections/2_basics_of_reinforcement_learning.tex", "max_issues_repo_name": "pnecchi/Thesis", "max_issues_repo_head_hexsha": "1a3ae97023acff1ee5e2d197a446734117a6fb99", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Pacs/Report/Sections/2_basics_of_reinforcement_learning.tex", "max_forks_repo_name": "pnecchi/Thesis", "max_forks_repo_head_hexsha": "1a3ae97023acff1ee5e2d197a446734117a6fb99", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 34, "max_forks_repo_forks_event_min_datetime": "2017-05-15T07:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-21T21:48:53.000Z", "avg_line_length": 73.6532846715, "max_line_length": 1474, "alphanum_fraction": 0.7224617214, "num_tokens": 6147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797065461671, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.7052471720683309}}
{"text": "\\subsection{Example: Four-bar linkage Mechanism}\n\n\\begin{frame}\n\t\\begin{block}{Example 2: Four-bar linkage Mechanism}\n\t\t\\begin{table}\n\t\t\t\\begin{minipage}{0.5\\linewidth}\n\t\t\t\t\\begin{tabular}{l|l}\n\t\t\t\t\t& $l_{AB}=l_1=0.15m$\\\\\n\t\t\t\t\t& $l_{BC}=l_2=0.35m$\\\\\n\t\t\t\t\t& $l_{CD}=l_3=0.3m$\\\\\n\t\t\t\t\tGiven & $l_{CE}=l_4=0.15m$\\\\\n\t\t\t\t\t& $x_D=0.3m$\\\\\n\t\t\t\t\t& $y_D=0.3m$\\\\\n\t\t\t\t\t& $\\theta_1=45^ {\\circ}$\\\\ \\hline\n\t\t\t\t\tFind & $\\vb{r}{B}$, $\\vb{r}{C}$, $\\vb{r}{E}$\\\\\n\t\t\t\t\\end{tabular}\t\n\t\t\t\\end{minipage}\\hfill\n\t\t\t\\begin{minipage}{0.5\\linewidth}\n\t\t\t\t\\begin{figure}\n\t\t\t\t\t\\includegraphics[width=50mm]{images/R-RRR.png}\n\t\t\t\t\\end{figure}\n\t\t\t\\end{minipage}\n\t\t\\end{table}\n\t\\end{block}\n\\end{frame}\n\n\\begin{frame}\n\\emph{Solution}\\vskip .25cm\nPosition of joint $B$:  $\\displaystyle \\vb{r}{B} = x_B\\ih + y_B\\jh = l_1\\cos{\\theta_1}\\ih + l_1\\sin{\\theta_1}\\jh$\\\\\nPosition of joint $C$:  $\\displaystyle \\vb{r}{C} = x_C\\ih + y_C\\jh = 0.1\\jh$\\\\\nPosition of joint $D$: $\\displaystyle \\vb{r}{D} = x_D\\ih + y_D\\jh$\\\\\nPosition of joint $E$: $\\displaystyle \\vb{r}{E} = x_E\\ih + y_E\\jh$\\\\\n\\[\n\\Rightarrow\\begin{cases}\n(x_B-x_C)^2+(y_B-y_C)^2=l_1^2\\\\\n(x_D-x_C)^2+(y_D-y_C)^2=l_3^ 2\n\\end{cases}\n\\]\nSolving the system of equations yields $x_{C_1}$ and $x_{C_2}$. Notice that in the mechanism, $0>x_C$ is the condition to obtain correct solution.\n\\[\n\\Rightarrow \\begin{cases}\n(x_C-x_E)^2 + (y_C-y_E)^2 = l_4^2\\\\\n\\displaystyle \\frac{y_C-y_E}{x_C-x_E}=\\frac{y_D-y_E}{x_D-x_E}\n\\end{cases}\n\\]\nSolving the system of equations yields $x_{E_1}$ and $x_{E_2}$. Notice that in the mechanism, $x_C>x_E$ is the condition to obtain correct solution.\n\\end{frame}\n\n\n\\begin{frame}{MATLAB R2019a code}\n\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/RRRR-position1.m}\n\\end{frame}\n\\begin{frame}\n\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/RRRR-position2.m}\n\\end{frame}\n\\begin{frame}{Plotting using MATLAB R2019a}\n\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/RRRR-plot.m}\n\\end{frame}\n\\begin{frame}{Output figure}\n\\centering\n\\includegraphics[width=100mm]{images/RRRR-plot.png}\n\\end{frame}\n\\begin{frame}{Trajectory plotting using MATLAB R2019a}\n\\lstinputlisting[style=Matlab-editor, basicstyle=\\mlttfamily]{codes/RRRR-trajectory.m}\n\\end{frame}\n\\begin{frame}{Output figure}\n\\centering\n\\includegraphics[width=100mm]{images/RRRR-trajectory.png}\n\\end{frame}", "meta": {"hexsha": "71fbda4db23f0d1215f217ff5267a0bd161c058b", "size": 2347, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Finished/position_analysis_pdf/Sections/Examples/RRRR.tex", "max_stars_repo_name": "HungNguyenDang/literate-meme", "max_stars_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Finished/position_analysis_pdf/Sections/Examples/RRRR.tex", "max_issues_repo_name": "HungNguyenDang/literate-meme", "max_issues_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Finished/position_analysis_pdf/Sections/Examples/RRRR.tex", "max_forks_repo_name": "HungNguyenDang/literate-meme", "max_forks_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.0144927536, "max_line_length": 148, "alphanum_fraction": 0.677460588, "num_tokens": 931, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7052471707955621}}
{"text": "%! TEX root = master.tex\n\n\\lecture{5}{Wed 03 Nov 2021 10:45}{Determinants}\n\n\\subsection*{Definitions}\n\nLet \\matri{A} be a square matrix. The scalar $\\det(A)$ or $\\mod{A}$  is called the \\textbf{determinant} of \\matri{A}.\n\nFor a  $2 \\times 2$ square matrix, the determinant is given by $a_{11}a_{22} - a_{12}a_{21}$. The plot thickens very quickly as we try to determine the determinant of larger $n \\times n$ matrices.\\\\\n\nThe process of evaluating the determinant of an $n \\times n$ matrix is described by the following steps:\n\\begin{enumerate}\n  \\item The \\textbf{minor} $\\matr{M_{jk}}$ is the matrix obtained from a square matrix when omitting the $j^{th}$ row and the $k^{th}$ column.\n  \\item The scalar quantity referred to as the \\textbf{cofactor} $\\alpha_{jk} = (-1)^{j+k} \\det(\\matr{M}_{jk})$\n\\end{enumerate}\nThe determinant of an $n \\times n$ matrix \\matri{A}, when choosing the first row as the starting point is therefore given by \n    \\begin{align*}\n  \\det(\\matr{A}) &= a_{11}\\matr A_{11} + a_{12}\\matr A_{12} + \\cdots + a_{1n}\\matr A_{1n} \\\\\n                 &= \\sum_{i=1}^n a_{1r}\\matr A_{1r}\n\\end{align*}\nThe same value of the determinant is obtained if the first point of reference is chosen to be any other row or column. To minimize computation complexity, the row or column with the most entries equal to 0 should be chosen with the result of reducing the maximum number of terms in the sequence to 0.\n\n\\subsection*{Properties of Determinants}\n\n\\begin{enumerate}\n  \\item [P1.] $\\det(\\matr{A}) = \\det(\\matr{A}^T)$\n  \\item [P2.] If \\matri{A} is an $n \\times n$ triangular matrix, then $\\det(\\matr{A}) = a_{11}a_{22}\\cdots a_{nn}$.\n  \\item [P3.] The interchanging of any two consecutive rows only alters the sign of of the determinant without affecting its magnitude.\n  \\item [P4.] If any two rows consecutive rows or columns of an $n \\times n$ matrix \\matri{A} are equal, then $\\det(\\matr{A}) = 0$.  \n\\end{enumerate}\n\\newpage\n  \\begin{theorem}\\label{thm:scalar-out}\n    If all elements of one row are multiplied by a constant $k$, then the value of the determinant is also multiplied by k.\n  \\end{theorem}\n\n\\begin{proof}\n    Let \\matri{K} be the general $n \\times n$ matrix \\matri{A} but with all entries in the first row multiplied by $k$. Then,\n    \\begin{align*}\n      \\mod{K} &=\n    \\begin{vmatrix} \n      ka_{11} & ka_{12} & \\cdots & ka_{1n}\\\\\n      a_{21} & a_{22} & \\cdots & a_{2n}\\\\\n      \\vdots & \\vdots & \\ddots & \\vdots\\\\\n      a_{n1} & a_{n2} & \\cdots & a_{nn}\n    \\end{vmatrix}\\\\\n              &= ka_{11}A_{11} + ka_{12}A_{12} + \\cdots + ka_{1n}A_{1n}\\\\\n              &= k(a_{11}A_{11} + a_{12}A_{12} + \\cdots + a_{1n}A_{1n})\\\\\n              &= k\\mod{A}\n    \\end{align*}\n\\end{proof}\n\n\\corollary{If any two rows of an $n \\times n$ matrix \\matri A are multiples of the other (\\emph{are linearlly dependent}), then the $\\mod{A} = 0$.}\n\\corollary{If \\matri{A} is an $n \\times n$ matrix, then $\\det{(k\\matr A)} = k^n \\det(\\matr A)$.}\n\\vspace{2em}\n\\begin{theorem}\n If a distinct scalar $\\alpha_{ij}$ is added to all the entries of a row of an $n \\times n$ matrix \\matri{A}, then $\\det(\\matr A)$ is equal to \n \\[  \\begin{vmatrix}\n      a_{11} & a_{12} & \\cdots & a_{1n}\\\\\n      a_{21} & a_{22} & \\cdots & a_{2n}\\\\\n      \\vdots & \\vdots & \\ddots & \\ldots\\\\\n      a_{n_1} & a_{n_2} & \\cdots & a_{nn}\\\\ \n    \\end{vmatrix} \n    + \n    \\begin{vmatrix}\n      \\alpha_{11} & \\alpha_{12} & \\cdots & \\alpha_{1n}\\\\\n      a_{21} & a_{22} & \\cdots & a_{2n}\\\\\n      \\vdots & \\vdots & \\ddots & \\vdots\\\\\n      a_{n_1} & a_{n_2} &\\cdots& a_{nn}\n      \\end{vmatrix}.\\] \n\\end{theorem}\n\\begin{proof}\n  \\[\n    \\text{Consider\\ \\ \\ }\n    \\begin{vmatrix}\n      a_{11}+\\alpha_{11} & a_{12}+\\alpha_{12} & \\cdots & a_{1n}+\\alpha_{1n}\\\\\n      a_{21} & a_{22} & \\cdots & a_{2n}\\\\\n      \\vdots & \\vdots & \\ddots & \\ldots\\\\\n      a_{n_1} & a_{n_2} & \\cdots & a_{nn}\\\\ \n    \\end{vmatrix}\\\\\n  \\]\n  \\begin{align*}\n    &= \\left(a_{11} + \\alpha_{11}\\right)\\matr A_{11} + \\left(a_{12} + \\alpha_{12}\\right)A_{12} + \\cdots + \\left( a_{1n} + \\alpha_{1n} \\right)\\matr A_{1n}\\\\\n    &= (a_{11}\\matr A_{11} + a_{12}\\matr A_{12} + \\cdots + a_{1n}\\matr A_{1n}) + \\left(\\alpha_{11}\\matr A_{11} + \\alpha_{12}\\matr A_{12} + \\cdots + \\alpha_{1n}\\matr A_{1n}\\right)\\\\\n  \\end{align*}\n\\end{proof}\n\\newpage\n\\begin{theorem}\\label{thm:row-distr}\n  The value of a determinant is unchanged if we add to the entries of any row the same multiple of the corresponding entries of another row.\n\n\\begin{center}\n  If $\\mod{A} =\n  \\begin{vmatrix}\n    a_{11} & a_{12} & \\cdots & a_{1n}\\\\\n    a_{21} & a_{22} & \\cdots & a_{2n}\\\\\n    \\vdots & \\vdots & \\ddots & \\vdots\\\\\n    a_{n1} & a_{n2} & \\cdots & a_{nn}\n  \\end{vmatrix}$, then $\n  \\begin{vmatrix}\n    a_{11} + ka_{21} & a_{12}+ka_{22} & \\cdots & a_{1n} + ka_{2n}\\\\\n    a_{21} & a_{22} & \\cdots & a_{2n}\\\\\n    \\vdots & \\vdots & \\ddots & \\vdots\\\\\n    a_{n1} & a_{n2} & \\cdots & a_{nn}\n  \\end{vmatrix} = \\mod{A}$\n\\end{center}  \n\n\\end{theorem}\n\\begin{proof}\nLet  $\\matr K =\\begin{vmatrix}\n    a_{11} + ka_{21} & a_{12}+ka_{22} & \\cdots & a_{1n} + ka_{2n}\\\\\n    a_{21} & a_{22} & \\cdots & a_{2n}\\\\\n    \\vdots & \\vdots & \\ddots & \\vdots\\\\\n    a_{n1} & a_{n2} & \\cdots & a_{nn}\n  \\end{vmatrix}$. Then, by Theorem ~\\ref{thm:row-distr}, \\[\\mod{K} = \\mod{A} + \n\\begin{vmatrix}\n    ka_{21} & ka_{22} & \\cdots & ka_{2n}\\\\\n    a_{21} & a_{22} & \\cdots & a_{2n}\\\\\n    \\vdots & \\vdots & \\ddots & \\vdots\\\\\n    a_{n1} & a_{n2} & \\cdots & a_{nn}\n  \\end{vmatrix}.\\]\n  Then, by Theorem \\ref{thm:scalar-out} and P4, \n$ \n  \\begin{vmatrix}\n    ka_{21} & ka_{22} & \\cdots & ka_{2n}\\\\\n    a_{21} & a_{22} & \\cdots & a_{2n}\\\\\n    \\vdots & \\vdots & \\ddots & \\vdots\\\\\n    a_{n1} & a_{n2} & \\cdots & a_{nn}\n  \\end{vmatrix} \n  =\n  k\\begin{vmatrix}\n    a_{21} & a_{22} & \\cdots & a_{2n}\\\\\n    a_{21} & a_{22} & \\cdots & a_{2n}\\\\\n    \\vdots & \\vdots & \\ddots & \\vdots\\\\\n    a_{n1} & a_{n2} & \\cdots & a_{nn}\n  \\end{vmatrix}\n  = 0\n$\n~\\\\~\\\\~\\\\Therefore, $\\mod{K} = \\mod{A}$.\n\\end{proof}\n\\begin{theorem}\\label{thm:det-distr}\n  The determinant of the product of two matrices is equal to the product of the two determinants.\n  $$\\det(\\matr{AB}) = \\det(\\matr A) \\det(\\matr B)$$\n\\end{theorem}\n\\begin{proof}\n  This proof is left as an exercise to the reader for the $2 \\times 2$ matrix case.\n\\end{proof}\n\n\\begin{theorem}\n  If $\\matr A \\inverse$ is invertible, then $\\mod{A \\inverse} = \\frac{1}{\\det{(\\matr A)}}$ \n\\end{theorem}\n\n\\begin{proof}\n  \\matri A is invertible. Thus \n  \\begin{align*}\n    \\exists\\ \\matr B \\text{ s.t. } \\matr{AB} &= I\\\\\n    \\det{(\\matr{AB})} &= \\det{(I)}\\\\\n    \\det(\\matr A) \\cdot \\det(\\matr B) &= 1\\\\\n    \\det(\\matr B) &= \\frac{1}{\\det(\\matr A)}\n \\end{align*}\n\\end{proof}\n\\remark{An $n \\times n$ matrix is invertible $\\Leftrightarrow \\det(\\matr A) \\neq 0$}\n", "meta": {"hexsha": "025434c6285cf3be946c4f3d976f998e79b39b64", "size": 6748, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bachelor-1/semester-1/mathematical-methods/lec_05.tex", "max_stars_repo_name": "girogio/university-notes", "max_stars_repo_head_hexsha": "52c6db020148fa3636c01f1e343d2172b424cd13", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "bachelor-1/semester-1/mathematical-methods/lec_05.tex", "max_issues_repo_name": "girogio/university-notes", "max_issues_repo_head_hexsha": "52c6db020148fa3636c01f1e343d2172b424cd13", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bachelor-1/semester-1/mathematical-methods/lec_05.tex", "max_forks_repo_name": "girogio/university-notes", "max_forks_repo_head_hexsha": "52c6db020148fa3636c01f1e343d2172b424cd13", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.9130434783, "max_line_length": 300, "alphanum_fraction": 0.5945465323, "num_tokens": 2664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006919925839876, "lm_q2_score": 0.8807970685907242, "lm_q1q2_score": 0.7052471599120421}}
{"text": "\\section{(Linear) Regression \\quad\n{\\normalfont\\sffamily model: $\\color{section-text-color} \\hat{\\mathbf y} = \\bm X \\beta$}}\n\n% ===\n\nAssuming $\\bm X^\\top \\bm X$ non-singular. %$\\hat\\beta\\ped{Linear}$ has smallest variance among linear \\underline{unbiased} estimates.\n\nBayesian view:\\;\n$(Y \\mid X,\\beta) \\sim \\Gauss{\\bm x^\\top \\beta, \\sigma^2 \\mathbb I}$\n\nDistrib. of estimator\n$\\hat\\beta\\ped{LS} \\sim \\Gauss{\\beta, (\\bm X^\\top \\bm X)^{-1} \\sigma^2}$\n\n\n\\emph{Ridge:}\n$\\epsilon\\ped{RSS}(\\beta,{\\color{OrangeRed}{\\lambda}}) = \\paren{\\bm y - \\bm X^\\top \\!\\beta}^\\top \\paren{\\bm y - \\bm X^\\top \\!\\beta} \\color{OrangeRed} {+} \\lambda \\beta^\\top \\!\\beta$\n\\\\\n$\\hat\\beta = (\\bm X^\\top \\bm X \\begingroup \\color{OrangeRed} + \\lambda \\mathbb I \\endgroup)^{-1} \\bm X^\\top \\bm y$,\n\\quad prior: $\\beta \\sim \\Gauss{0, \\frac{\\sigma^2}{\\lambda} \\mathbb I}$\n\n\\emph{(Ridge) Shrinkage:}\nDecompose $\\bm X = \\bm{UDV}^\\top$\\\\\n$\\bm X \\hat\\beta = \\bm{UD} (\\bm D^2 {+} \\begingroup \\color{OrangeRed} \\lambda \\mathbb I \\endgroup)^{-1} \\bm{DU}^\\top \\bm y = \\sum\\limits_{j\\leq d} \\bm u_j \\frac{d_j^2}{d_j^2 \\begingroup \\color{OrangeRed} + \\lambda \\endgroup} \\bm u_j^\\top \\bm y$\n\n\\emph{Lasso:}\n%$\\epsilon\\ped{RSS}(\\beta,\\lambda) = \\sum_{i\\leq n} (y_i - x_i^\\top \\beta)^2 + \\lambda \\norm{\\beta}_1$\n$\\hat\\beta = \\arg\\min_\\beta \\sum_{i\\leq n} (y_i - x_i^\\top \\beta)^2 \\color{OrangeRed} + \\lambda \\norm{\\beta}_1$\n\\\\\n\\textit{(no closed form)},\n\\hfill prior: $p(\\beta_i) {=} \\frac{\\lambda}{4\\sigma^2} \\exp(-\\abs{\\beta_i} \\frac{\\lambda}{2\\sigma^2})$\n\n\n\\emph{Bias-variance:}\n$\\E[D]{ \\E[Y\\mid X=x]{ (\\hat f(x) - Y)^2 } }$\n{\\small ${=} \\E[D]{ (\\hat f(x) {-} \\E[D]{\\hat f(x)})^2 } + \\paren*{ \\E[D]{\\hat f(x)} {-} \\E{Y\\vert X=x} }^2$}\n$+ \\E{ (Y - \\E{Y\\vert X=x})^2 }$\n$= variance + bias^2 + noise$\n\n\n\\emph{Gauss-Markov Theorem:}\\\\\nFor any linear estimator $\\widetilde\\theta = c\\!^\\top \\bm y = a\\!^\\top (\\hat\\beta {+} \\bm{Dy})$ that is unbiased for $a^\\top \\beta$, it holds: $\\V{a^\\top \\hat\\beta} \\leq \\V{c^\\top \\bm y}$.\n\nAmong all linear \\textbf{u}-estimators, $\\hat\\beta\\ped{LS}$ minimises the gen. error!\n\\enskip\nWhat about \\textbf{biased} estimators? We \\rotatebox[origin=c]{45}{$\\to$} bias a bit in the hope that the variance \\rotatebox[origin=c]{-45}{$\\to$}.\n\n\\emph{Combining Regressors:} $\\hat f(x) \\coloneqq \\frac1B \\sum_{i\\leq B} \\hat f_i(x)$\\\\\n$\\mathrm{bias} [\\hat f(x)] = \\frac1B \\sum \\mathrm{bias} [\\hat f_i(x)]$\\\\\n$\\V{\\hat f} = \\frac{1}{B^2} \\sum \\V[D]{\\hat f_i} + \\frac{1}{B^2} {\\sum\\sum}_{i\\neq j} \\Cov{\\hat f_i, \\hat f_j} \\approx \\frac{\\sigma^2}{B}$\n\n% ===\n", "meta": {"hexsha": "290463cdec2fa90c96d061e30cef0121eca42a5e", "size": 2528, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/AML20/sections/03_regression.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/AML20/sections/03_regression.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/AML20/sections/03_regression.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.6153846154, "max_line_length": 244, "alphanum_fraction": 0.6048259494, "num_tokens": 1052, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.705215295129718}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Zeros}\n\n\\objective{Graph, read, and produce rational functions}\n\n\nA rational function is one defined by $\\frac{f(x)}{g(x)}$ where $f(x)$ and $g(x)$ are both\npolynomials.  Rational functions exhibit some common behaviors with polynomials, \nsuch as $x$-intercepts and one $y$-intercept.  But they also tend to have vertical and\nhorizontal asymptotes.  The most basic rational function --- $\\frac{1}{x}$ --- is, in fact,\na hyperbola, with two branches.  But rational functions can have many more than two\nbranches, or even just have one.\n\n\nThere are three things one could consider with regard to 0 and a given rational function.\nFirst, the entire quotient could be 0, which would make $x$-intercepts.  Fortunately,\na quotient is only equation to zero when the numerator is equal to zero, meaning\nwe only need to find when top equation's zeros to find the whole equation's.\n\nWhen the denominator is equal to zero, much more bizarre behavior emerges.  A vertical\nasymptote will occur, though it is not immediately clear if the left and right limits will be\nto opposite infinities, or to the same one.  Factoring will make it clear: if the term\nhas an even multiplicity, the asymptote will be followed to the same infinity.  Otherwise,\none sided-limit will be $\\infty$ and the other $-\\infty$.\n\nLastly, we should consider what happens when we make the argument 0.  A $y$-intercept\nis always a coordinate with the appearance $(0,y_0)$, so plugging in 0 is an efficient way\nto find it.\n\nEach of these three techniques for various ``zero's'', assumes that it is not occurring when\nfunction is in an indeterminate form.  Holes and asymptotes can prevent intercepts from \nactually occurring, and obfuscate one another\n\n\\subsection{Horizontal Asymptotes}\nIf a rational function looks like a fraction, a ratio, a quotient, that's because it is!  Just as\na polynomial looks more and more like an integer power function the further out one zooms,\nso too a rational function will look more like the results if one simply divides the numerator\nby the denominator.\n\nConsider the function $r(x) = \\dfrac{2x^2-4x-6}{x^2+x-2}$.  In the big picture, \nit is a simple division problem.  Ultimately, we want to know $lim_{x\\rightarrow\\infty} \nr(x)$:\n\n\\polylongdiv{2x^2-4x-6}{x^2+x-2}\n\nand so the question becomes equivalent to \n\n$$\n\\lim_{x\\rightarrow\\infty} 2-\\frac{6x+2}{x^2+x-2}\n$$\n\nwhich is two.\n\nWe might have spared ourselves the work of polynomial long division by contrasting the degree\nof the numerator and denominator beforehand.  Which has greater degree?\n\\begin{itemize}\n\\item[\\textbf{denom.}] the long term behavior can be modeled by a horizontal asymptote at $y=0$\n\\item[\\textbf{neither}] the long tern behavior will still be a horizontal asymptote at $y=\\frac{a}{b}$, where $a$ and $b$ are the leading terms of the numerator and denominator respectively\n\\item[\\textbf{numer.}] polynomial division cannot be avoided, and the long-run behavior trends towards an asymptote at $y=$ the quotient, ignoring the remainder\n\\end{itemize}\n\n\\subsection{Signs}\nRational functions are among the hardest for graphers to correctly display.  \nEven large computers can display misleading results if the window is not correctly \npre-programmed.  If it is necessary to map out the sign of the function beforehand,\na tabular approach can be very helpful.  We will combine a number line and a table\ninto a new kind of grid, using the following function as an example:\n\n$$Y_1=\\frac{x+1}{(10x-1)^2}$$\n\n\\begin{figure}[h]\n\\begin{centering}\n\\begin{tikzpicture}\n\n\\matrix (m) [matrix of math nodes, \n             column sep=0cm, row sep=0pt,\n     nodes={text width=15mm, align=center, \n            text height=3ex, text depth=1.5ex}]\n{\n(x+1)       &   -   &   +   &   +   \\\\\n(10x-1)^2    &   +   &   +   &   +   \\\\\n\\textbf{Q}        &   \\textbf{-}  &  \\textbf{+}    &  \\textbf{+}    \\\\\n};\n\\draw  (m-1-1.north west) -- (m-1-4.north east);\n\\draw (m-2-1.north west) -- (m-2-4.north east);\n\\draw (m-3-1.north west) -- (m-3-4.north east);\n\\draw (m-3-1.south west) -- (m-3-4.south east);\n\n\\draw  (m-1-1.north east) -- (m-3-1.south east);\n\\draw (m-1-2.north east) -- (m-3-2.south east);\n\\draw (m-1-3.north east) -- (m-3-3.south east);\n\\draw (m-1-4.north east) -- (m-3-4.south east);\n\n\\node[above] at (m-1-2.north east) {$-1$};\n\\node[above] at (m-1-3.north east) {$0.1$};\n\n\\node at (m-1-2.east) {$0$};\n\\node at (m-2-2.east) {$+$};\n\\node at (m-3-2.east) {\\textbf{0}};\n\n\\node at (m-1-3.east) {$+$};\n\\node at (m-2-3.east) {$0$};\n\\node at (m-3-3.east) {\\textbf{$\\infty$}};\n\\end{tikzpicture}\n\\caption{A sign table and number-line combination}\n\\end{centering}\n\\end{figure}\n\nThe table is made by writing the factors of the numerator and denominator down the\nleft.  The bottom row is the function itself, which is the quotient of the rest.  Across \nthe top, you will need a division for each of the zeros of the factors and room\nfor all the spaces in-between and around.  On the lines, write the zero's if the factor\nis zero there, or just the sign.  To complete the bottom, simply remember the\nrules of  signs:\n\n\\begin{enumerate}\n\\item a positive multiplied or divided by a positive is a positive\n\\item a negative multiplied or divided by a negative is a negative\n\\item a negative multiplied or divided by a negative is positive\n\\end{enumerate}\n\nThe zero's require only a little more thought.  A zero in the numerator\nmakes the entire quotient zero.  If a zero in the numerator is surrounded by\nlike signs, then either side of the vertical asymptote will go to that sign infinity.\nIf the signs disagree, then both infinities will be approached, each from the\nside matching their sign.\n\n\\begin{figure}\n\\begin{centering}\n\\includegraphics[scale=0.3]{\\chapdir/pics/verticalasymptote}\n\\caption{An appropriately zoomed in graph of $\\frac{x+1}{(10x-1)^2}$}\n\\end{centering}\n\\end{figure}\n\nWith this much more appropriate window, we can see that there is a local minimum,\nperhaps in the vicinity of $x=-2$.  If it indeed occurs at a rational number, there is no\nreason to find the derivative by hand with the TI-8* will do it for us!\n\n\\index{TI-8*!graph derivatives}\nSet $Y_2$ to be \\texttt{nDeriv(Y$_1$(X),X,X)} or $\\left.\\frac{d}{dx}(Y_1(X))\\right|_{X=X}$, \ndepending upon your model of TI-8*.  (nDerive is choice 8 under \n\\Touche[style=function,principal=math].)  It seems have a\nzero near 2.  The function is clearly concave and derivative is increasing, so it should be\na local minimum.  Using ZERO (under \n\\Touche[style=function,principal=trace,fontsize=7pt,position=0.9]\n), we find it to be exactly -2.1.  Plugging\nback into the original equation, we get $\\frac{-1.1}{484}$, which $\\triangleright$FRAC\nconverts to $-\\frac{1}{440}$.\n", "meta": {"hexsha": "cd5e26ad15d1cb0562abea165f7f200fae279cf2", "size": 6715, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch06/0604.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch06/0604.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch06/0604.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.7666666667, "max_line_length": 189, "alphanum_fraction": 0.7231571109, "num_tokens": 1976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7051531347785497}}
{"text": "\\chapter{Trigonometric Functions}\n\\section{Radians}\nA radian is a measure of the central angle $\\theta$ such that the arc $s$\nintercepted by the angle is equal to the length of the radius, $r$.\n\nOne radian is the measure of a central angle $\\theta$ that intercepts an arc $s$\nequal to the length of the radis $r$ of the circle: ($\\theta$ is measured in\nradians)\n\\begin{equation}\n  \\theta=\\frac{s}{r}\n\\end{equation}\n\nThere are a few key terms that are used when describing angles inside of a\ncircle:\n\\begin{description}\n  \\item[Initial side]{The starting position of the ray}\n  \\item[Terminal side]{The other side of the ray}\n  \\item[Vertex]{The intersection of the initial and terminal side}\n\\end{description}\n\n\\subsection{Converting beteen radians and degrees}\n\\begin{enumerate}\n  \\item{To convert degrees to radians, simply multiply degrees by\n    $\\frac{\\pi\\text{rad}}{180}$}\n  \\item{To convert radians to degrees, multiply radians by\n    $\\frac{180}{\\pi\\text{rad}}$}\n\\end{enumerate}\n\n\\subsection{Linear and Angular Speed}\nArc legth is defined for a length $s$ as the quantity of the length of the\nradius, $r$ and the central angle that $s$ is intercepted by, $\\theta$:\n\\begin{equation}\n  s=r\\theta\n\\end{equation}\n\nTherefore, linear speed is defined as the quotient of the arc-length and the\ntime that has passed:\n\\begin{equation}\n  \\text{linear speed}=\\frac{\\text{arc length}}{\\text{time}}=\\frac{s}{t}\n\\end{equation}\n\nAnd as follows, angular speed is the same formula, except we are looking at\nradians per second, as in the following equation:\n\\begin{equation}\n  \\text{angular speed}=\\frac{\\text{central angle}}{\\text{time}}=\\frac{\\theta}{t}\n\\end{equation}\n\n\\section{Unit Circle Trigonometry}\nConsider a unit circle (a circle of radius $1$ centered around $(0,0)$) defined\nby the following equation: $x^2+y^2=1$.\n\nFor any point \\textit{on} the circle, the coordinate pair that will intersect\nthe edge of the circle is defined as $P(\\theta)=(cos(\\theta),sin(\\theta))$.\n\n\\begin{itemize}\n  \\item{$sin(t)=y$}\n  \\item{$cos(t)=x$}\n  \\item{$tan(t)=\\frac{y}{x}$}\n  \\item{$csc(t)=\\frac{1}{y}$}\n  \\item{$sec(t)=\\frac{1}{x}$}\n  \\item{$cot(t)=\\frac{x}{y}$}\n\\end{itemize}\n\n\\subsection{Even and Odd Trigonometric Functions}\n\\begin{itemize}\n  \\item{Even:}\n    \\begin{itemize}\n      \\item{$cos(-t)=cos(t)$}\n      \\item{$sec(-t)=sec(t)$}\n    \\end{itemize}\n  \\item{Odd:}\n    \\begin{itemize}\n      \\item{$sin(-t)=-sin(t)$}\n      \\item{$csc(-t)=-csc(t)$}\n      \\item{$tan(-t)=-tan(t)$}\n      \\item{$cot(-t)=-cot(t)$}\n    \\end{itemize}\n\\end{itemize}\n\n\\section{Right Triangle Trigonmetry}\nConsider a right triangle.  A geometric figure with three sides, two of which\nmeet at a $90\\deg$ angle.  The other side is reffered to as the hypoteneuse, and\nthe length of that side is equal to $\\sqrt{a^2+b^2}$.\n\nThere are six trigonometric functions that we will study that relate to right\ntriangles.  They are defined as follows:\n\\begin{itemize}\n  \\item{$sin(\\theta)=\\frac{\\text{opp}}{\\text{hyp}}$}\n  \\item{$cos(\\theta)=\\frac{\\text{adj}}{\\text{hyp}}$}\n  \\item{$tan(\\theta)=\\frac{\\text{opp}}{\\text{adj}}$}\n  \\item{$csc(\\theta)=\\frac{1}{sin(\\theta)}$}\n  \\item{$sec(\\theta)=\\frac{1}{cos(\\theta)}$}\n  \\item{$cot(\\theta)=\\frac{1}{tan(\\theta)}$}\n\\end{itemize}\n\n\\subsection{Trigonometric Identities}\n\n\\subsubsection{Reciprocal Identities}\nThis set of identities defines the relationships between pairs of trigonometric\nfunctions as inverses of each other.\n\n\\begin{itemize}\n  \\item{$sin(\\theta)=\\frac{1}{csc(\\theta)}$}\n  \\item{$cos(\\theta)=\\frac{1}{sec(\\theta)}$}\n  \\item{$tan(\\theta)=\\frac{1}{cot(\\theta)}$}\n  \\item{$csc(\\theta)=\\frac{1}{sin(\\theta)}$}\n  \\item{$sec(\\theta)=\\frac{1}{cos(\\theta)}$}\n  \\item{$cot(\\theta)=\\frac{1}{tan(\\theta)}$}\n\\end{itemize}\n\n\\subsubsection{Quotient Identites}\nThis set of identnties defines two trigonometric functions as quotients of other\npairs of trigonometric functions.\n\n\\begin{itemize}\n  \\item{$tan(\\theta)=\\frac{sin(\\theta)}{cos(\\theta)}$}\n  \\item{$cot(\\theta)=\\frac{cos(\\theta)}{sin(\\theta)}$}\n\\end{itemize}\n\n\\section{Graphs of Sine and Cosine Functions}\nThe sine function is defined for all $x\\in(-\\infty,\\infty)$, and has a range of\n$[-1,1]$.  It has a period of $2\\pi$ and has $x$-intercepts at $(n\\pi, 0)$ and\n$y$-intercepts at the origin.  It is an odd-function with original symmetry.\n\nOn the other hand, the cosine is also defined for all $x\\in(-\\infty,\\infty)$,\nand has a range of $[-1,1]$.  It has a period of $2\\pi$ and has $x$-intercepts\nat $(\\frac{\\pi}{2}+n\\pi,0)$.  It has a $y$-intercept at $(1,0)$ and is an even\nfunction with $y$-axis symmetry.\n\n\\subsection{Amplitude}\nThe amplitude of a function is defined as one half of the distance between its\nrelative minimum and maximum points.  For any trigonmetric function of the form\n$y=a\\text{sin}(x)$ or $y=a\\text{cos}(x)$, the amplitude is $|a|$.\n\n\\subsection{Period}\nThe period of a function is the time it takes the function to repeat itself, for\nany point.  The period itself is not a function, it is a constant value for all\npoints \\textit{across} a function.  For any function that is defined by the\npattern: $y=a\\text{sin}(x)$ or $y=a\\text{cos}(x)$, the period is defined by the\nfollowing equation:\n\\begin{equation}\n  \\text{Period}=\\frac{2\\pi}{b}\n\\end{equation}\n\n\\section{Graphs of other Trigonometric Functions}\n\n\\subsection{The Tangent and its Inverse}\nThe graph of the tangent function is defined for all real numbers $x$, such that\n$x\\neq\\frac{\\pi}{2}+n\\pi$.  Its range is defined for all\n$x\\in(-\\infty,\\infty)$ and has $x$-intercepts at $(n\\pi,0)$, and a\n$y$-intercept at the origin.  It has vertical asymptotes at\n$x=\\frac{\\pi}{2}+n\\pi$ and is an odd function with origianl symmetry.\n\nThe function $f(x)=cot(x)$ is exactly the $tan(x)$ function, but shifted\n$\\frac{\\pi}{2}$ units to the right.  That is to say that\n$f(x)=cot(x)=tan(x)+\\frac{\\pi}{2}$.\n\n\\subsection{The Cosecant and Secant Functions}\nThese functions are very easy to reason about.  Take their inverse functions,\nand draw plot them on a graph.  Define vertical asymptotes when the origianl\nfunction is $f(x)=0$, and draw points at the relative minimum and maximum across\nthe original function.  Stretch those points to the asymptotes through\ncontinuous curves, and you have the function that you are trying to sketch.\n\nThe same rules apply when applying transformations to these functions.\n\n\\section{Inverse Trignonometric Functions}\nThe inverse sine function, or $f(x)=arcsin(x)$ is defined over the interval\n$[-\\frac{\\pi}{2},\\frac{\\pi}{2}]$.  Simply take the sine function at those two\nendpoints and plot the inverse function.  Apply transformations as normal.\n\n\\subsection{Characteristics of Inverse Trigonometric Functions}\n\\begin{description}\n  \\item[$f(x)=arcsin(x)$]{Defined over all $x\\in[-1,1]$; $-\\frac{\\pi}{2} \\leq\n    f(x) \\leq \\frac{pi}{2}$}\n  \\item[$f(x)=arccos(x)$]{Defined over all $x\\in[-1,1]$; $0 \\leq f(x) \\leq \\pi$}\n  \\item[$f(x)=arctan(x)$]{Defined over all $x\\in(-\\infty,\\infty)$;\n    $-\\frac{\\pi}{2} \\leq f(x) \\leq \\frac{\\pi}{2}$}\n\\end{description}\n", "meta": {"hexsha": "633896e7b7bc3200ac977fc43435e67b14a41bfd", "size": 7019, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pre_calculus_h/chapters/4_trigonometric_functions.tex", "max_stars_repo_name": "ttaylorr/finals", "max_stars_repo_head_hexsha": "41f6a03e4a082768c10b9a77a0e042cfce2a6d7f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pre_calculus_h/chapters/4_trigonometric_functions.tex", "max_issues_repo_name": "ttaylorr/finals", "max_issues_repo_head_hexsha": "41f6a03e4a082768c10b9a77a0e042cfce2a6d7f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pre_calculus_h/chapters/4_trigonometric_functions.tex", "max_forks_repo_name": "ttaylorr/finals", "max_forks_repo_head_hexsha": "41f6a03e4a082768c10b9a77a0e042cfce2a6d7f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9944444444, "max_line_length": 80, "alphanum_fraction": 0.6993873771, "num_tokens": 2219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7051531246744811}}
{"text": "\\chapter{Elliptic curve cryptography}\n\\label{chpr:ecc}\nIn this chapter we will analyse the cryptographic primitives and assumptions that will allow in the next chapter to introduce the digital signature schemes that are the core of the present work. The first argument will be the specialization of elliptic curves to finite fields, the mathematical structure underpinning the whole elliptic curve cryptography.\n\n\\bigskip\n\n\\section{Elliptic curves over finite fields}\n\\label{ecoverff}\nUp to now we considered the field over which the curve is defined to be the set of real numbers: this is not at all the unique possibility. The typical choice in cryptography is $K = \\mathbb{F}_p$, where $\\mathbb{F}_p$ is the finite field with $p$ elements. \n\\\\\nSince there are only finitely many pairs $(x, y)$ with $x, y \\in \\mathbb{F}_p$, the group $E(\\mathbb{F}_p)$ is finite.\nIn practice we consider: \n$$\\{(x, y) \\in \\mathbb{F}_p^2 \\ | \\ y^2 \\equiv x^3 + ax + b \\ (\\text{mod} \\ p), \\ 4a^3 + 27b^2 \\not\\equiv 0 \\ (\\text{mod} \\ p)\\} \\cup \\{\\infty\\}.$$\nIt can be shown that the formulas for point addition are the same derived in Section \\ref{grouplaw}, but where the calculations are done modulo $p$\\footnote{Notice that reduction modulo $p$ can be executed much faster if the prime $p$ is a Mersenne or a pseudo-Mersenne prime, i.e. if $p = 2^d - 1$ for some $d$ in the first case or if $p \\simeq 2^d$ in the second one.}.\n\\\\\n\\begin{center}\n\t\\includegraphics[width=0.9\\linewidth]{Images/ec_over_ff.eps}\n\t\\captionof{figure}{The curve $y^2 = x^3 - x$ over $\\mathbb{F}_{61}$.}\n\t\\label{fig:figure4}\n\t\\source{\\url{https://en.wikipedia.org/wiki/Elliptic_curve\\#Elliptic_curves_over_finite_fields}.}\n\\end{center}\nIn Figure \\ref{fig:figure4} the typical shape of an elliptic curve over a finite field is represented: we can see that we are not anymore dealing with a smooth curve, but with a finite set of points scattered along the plane. We can notice a certain degree of symmetry with respect to the line $y = \\frac{p}{2}$, with the exception of the points with $y$ coordinate equal to zero, that correspond to the roots of the cubic $x^3 + ax + b$ in $\\mathbb{F}_p$.\n\\\\\nIt is still possible to define a geometric method for point addition: the general idea is that we draw the line passing through the points considered. Since we are working in modular arithmetic, this line ``repeats\" itself along the plane. Once the line intersects a third point, we take the opposite one to be the result of the addition. The approach is presented in Figure \\ref{fig:figure5}, however the method can be somewhat counterintuitive, especially when dealing with point doubling, so we stick with the algebraic notation.\n\n\\bigskip\n\\noindent\nThe number of points on an EC over $\\mathbb{F}_q$ plays a central role in the cryptographic applications, so we state here a useful theorem that allows to give an estimate:\n\\begin{thm} [{\\bf Hasse's theorem}] Let $\\mathbb{F}_q$ be a finite field and let $E$ be an elliptic curve defined over $\\mathbb{F}_q$. Then the order of $E(\\mathbb{F}_q)$ (i.e. the number of points) satisfies: $$|q + 1 - \\#E(\\mathbb{F}_q)| \\leq 2\\sqrt{q}.$$\n\\end{thm}\n\\begin{center}\n\t\\includegraphics[width=0.9\\linewidth]{Images/sum_ec_over_ff.eps}\n\t\\captionof{figure}{Geometric representation for the addition of points on the elliptic curve $y^2 = x^3 - x + 3$ over $\\mathbb{F}_{127}$.}\n\t\\label{fig:figure5}\n\t\\source{\\cite{RefWork:4}.}\n\\end{center}\n\\noindent\nLoosely speaking, Hasse's theorem tells us that the number of points over $E(\\mathbb{F}_q)$ increases linearly with the order of the field.\n\\\\\nAnother observation we want to do is that if $\\#E(\\mathbb{F}_p)$ is a prime number, then $E(\\mathbb{F}_p)$ is a cyclic group: this is a direct consequence of Lagrange's theorem. Since the order of each subgroup is a divisor of the order of the group, we have that, if the order of the group is a prime number, there is no subgroup (with the exception of the trivial one, comprising only the point at infinity). This means that it has to exist a generator of the whole group. Suppose this is not the case, i.e. $\\nexists G \\in E(\\mathbb{F}_p) \\ | \\ \\forall Q \\in E(\\mathbb{F}_p) \\ \\exists q \\in [1, ..., \\#E(\\mathbb{F}_p)] \\ \\text{s.t.} \\ Q = qG$: thus, $\\forall G \\in E(\\mathbb{F}_p)$, there exists at least a $Q$ for which the relation $Q = qG$ does not hold. Fix $G$ and start adding it repeatedly to itself. Of course we would reach different points in $E(\\mathbb{F}_p)$ due to the closure of the addition. However we won't be able to reach $Q$, by definition. But eventually we would reach the point at infinity (when $q$ gets equal to the order of $G$): then we would start again, meaning that we would have found a cyclic subgroup. But this is in contrast with Lagrange's theorem, so that we can conclude that the whole set of elliptic curve's points form a cyclic group if $\\#E(\\mathbb{F}_p)$ is a prime number.\n\n\\bigskip\n\n\\subsection{Elliptic curve domain parameters}\n\\label{ecparam}\nIn order to rely on ECC, the parties involved in a scheme need to agree on a set of parameters called elliptic curve domain parameters. A typical choice is to rely on standardized curves (e.g. those defined in \\cite{RefWork:3}); however, it is still possible to choose other parameters, but this has to be done carefully, as we will explain in this section. We start defining EC parameters, following closely \\cite{RefWork:2}.\n\\\\\n\\\\\nElliptic curve parameters are defined as a sextuple $T = (p, a, b, G, n, h)$, where:\n\\begin{itemize}\n\t\\item The integer $p$ specifies the prime finite field $\\mathbb{F}_p$;\n\t\\item The two elements $a, b \\in \\mathbb{F}_p$ specifies the elliptic curve $E(\\mathbb{F}_p)$ through the Weierstrass equation;\n\t\\item $G$ is a point on $E(\\mathbb{F}_p)$;\n\t\\item $n$ is the order of $G$, i.e. the number of elements of the cyclic subgroup generated by $G$ (that can coincide with the whole $E(\\mathbb{F}_p)$);\n\t\\item $h = \\frac{\\#E(\\mathbb{F}_p)}{n}$ is an integer\\footnote{We can deduce that $h$ is an integer directly from Lagrange's theorem.} called the cofactor. \n\\end{itemize}\nThere are different ways in which we can choose these parameters. For example, they can be generated at random or not. Random generation is a conservative choice, since it offers a guarantee against future special purpose attacks. In this case it could be better to use verifiable random parameters, meaning that $(a, b)$ and/or $G$ are obtained as output from a secure hash function\\footnote{An hash function in general is a function that takes as input strings of arbitrary length and outputs in a fixed length sequence of bytes. For a discussion on the security properties of an hash function we refer to the appendix of \\cite{RefWork:2}.}, applied to some seed $S$. When choosing verifiable random parameters, the sextuple $T$ should be coupled with the seed value $S$ to allow parameters' validation. However, non random curves are typically built in particular ways to ensure efficient computations. Standardized curves, that comprises both types of EC, have the advantage of underpinning interoperability, plus an high degree of reliability, having been heavily tested.\n\\\\\nNow that we have explained what they are and how they can be chosen, we will show some constraints and the validation process for the sextuple $T$.\n\n\\bigskip\n\\bigskip\n\\bigskip\n\\bigskip\n\\bigskip\n\\noindent\n{\\bf Parameters' selection}: \n\\begin{enumerate}\n\t\\item Select the approximate security level in bits, $t$\\footnote{The security level should be chosen such that solving the Elliptic Curve Discrete Logarithm Problem (ECDLP, Section \\ref{dlp}) requires $2^t$ curve's operations. The SEC standard that we are following restricts to $t \\in \\{80, 112, 128, 192, 256\\}$.};\n\t\\item Choose a prime $p$ such that $\\lceil log_2p\\rceil = 2t$ if $80 < t < 256$, such that $\\lceil log_2p\\rceil = 521$ if $t = 256$ and such that $\\lceil log_2p\\rceil = 192$ if $t = 80$;\n\t\\item Select $a$ and $b$ in $\\mathbb{F}_p$ such that:\n\t\\begin{itemize}\n\t\t\\item $4a^3 + 27b^2 \\neq 0 \\ (\\text{mod} \\ p)$;\n\t\t\\item $\\#E(\\mathbb{F}_p) \\neq p$;\n\t\\end{itemize} \n\t\\item Select $G \\in E(\\mathbb{F}_p)$ such that:\n\t\\begin{itemize}\n\t\t\\item $p^B \\neq 1 \\ (\\text{mod} \\ n), \\ \\forall 1 \\leq B < 100$;\n\t\t\\item $h \\leq 2^{\\frac{t}{8}}$;\n\t\t\\item $n - 1$ and $n + 1$ should each have a large prime factor $r$, which is large in the sense that $log_nr > \\frac{19}{20}$.\n\t\\end{itemize}\n\\end{enumerate}\nThese requirements may look strange, but are all needed in order to avoid special attacks. In particular, the two requirements at point 3 are needed in order for the curve to be non singular and to avoid Smart's attack\\footnote{The points on the curve are mapped to the elements of the additive group of $\\mathbb{F}_p$, so that the discrete logarithm problem is solvable in polynomial time through the {\\bf Extended Euclidean Algorithm}.}, respectively.\n\\\\\nThe three requirements at point 4 instead are needed to ensure that the curve is robust against MOV and Cheon's attack\\footnote{These attacks are complex and their explanation is out of the scope of the present work; we refer the interested reader to the appendix of \\cite{RefWork:2} for an overview and for further bibliography.}, and to ensure that the order of $G$ is sufficiently high.\n\\\\\nNotice however that the choice of the parameters does not secure against all possible attacks. Indeed other kind of attacks may be possible, such as side channel attacks: timing and power analysis are an example. They exploit the differences in the point addition and doubling operations, that lead to different timings or power consumptions. Possible solutions are a change of coordinates or the use of Edwards curves, a special family of elliptic curves for which addition and doubling can be done with the same operation.\n\n\\bigskip\n\\noindent\n{\\bf Parameters' validation}: Given $T = (p, a, b, G, n, h)$ and $t$, the parameters are deemed valid if:\n\\begin{enumerate}\n\t\\item $p$ is a prime such that $\\lceil log_2p\\rceil = 2t$ if $80 < t < 256$, or such that $\\lceil log_2p\\rceil = 521$ if $t = 256$, or such that $\\lceil log_2p\\rceil = 192$ if $t = 80$;\n\t\\item $a, b, x_G$ and $y_G$ are integers in $[0, ..., p - 1]$;\n\t\\item $4a^3 + 27b^2 \\neq 0 \\ (\\text{mod} \\ p)$;\n\t\\item $y_G^2 = x_G^3 + ax_G + b \\ (\\text{mod} \\ p)$;\n\t\\item $n$ is a prime number;\n\t\\item $h \\leq 2^{\\frac{t}{8}}$ and $h = \\lfloor (\\sqrt{p} + 1)^2 / n \\rfloor$;\n\t\\item $nG = \\infty$;\n\t\\item $p^B \\neq 1 \\ (\\text{mod} \\ n), \\ \\forall 1 \\leq B < 100$ and $n \\neq p$. \n\\end{enumerate}\nIf the parameters are verifiably random, it should also be checked that $(a, b)$ and/or $G$ have been correctly derived from the seed $S$.\n\\\\\nThese checks are needed to verify that: the curve has the required difficulty level, it is defined over $\\mathbb{F}_p$, it is non singular, $G$ is a point of the curve, the Discrete Logarithm (DL, Section \\ref{dlp}) is difficult, $h$ is effectively the cofactor of $G$, $G$ has order $n$ and neither MOV nor Smart's attacks are possible.\n\n\\bigskip\n\n\\subsection{Elliptic curve key pairs}\n\\label{keypairs}\nIn this section we would like to briefly analyse the core of the public key cryptography based on elliptic curves: the concept of elliptic curve key pair. Shortly, public key cryptography is a cryptographic system that relies on pairs of keys, a public and a private key, with different roles. The asymmetry of the keys is the reason behind the fact that public key cryptography is sometimes called also asymmetric cryptography. We talk about asymmetry since public keys can be published, while private keys must be kept secret, as the names suggest. This accomplishes two functions: authentication, since everybody with the public key can verify that the holder of the paired private key sent a signed message, and encryption, where the public key is used for encryption, but only the owner of the private counterpart can decrypt.\n\n\\bigskip\n\\noindent\nGiven some elliptic curve domain parameters $T = (p, a, b, G, n, h)$, an elliptic curve key pair $\\{\\textcolor{red}{q}, \\textcolor{green}{Q}\\}$ associated with $T$ consists of an elliptic curve secret key $\\textcolor{red}{q}$, which is an integer in $[1, n - 1]$, and an elliptic curve public key $\\textcolor{green}{Q} = (x_Q, y_Q)$, which is the point $\\textcolor{green}{Q} = \\textcolor{red}{q}G$.\n\\\\\nThe choice of the colours is intended to make clear what is secret and what can be made public.\n\\\\\nTo detect transmission errors or to prevent the deliberate submit of an invalid key, it is desirable to validate the public key of the counterparties. This can be achieved following these steps:\n\\begin{enumerate}\n\t\\item Check that $Q \\neq \\infty$;\n\t\\item Check that $x_Q$ and $y_Q$ are integers in $[0, p - 1]$ and that $y_Q^2 = x_Q^3 + ax_Q + b \\ (\\text{mod} \\ p)$;\n\t\\item Check that $nQ = \\infty$.\n\\end{enumerate}\nThrough this algorithm we are checking that $Q$ is effectively a point on the curve different from the point at infinity and that it belongs to the cyclic subgroups generated by $G$. Indeed, if the relation $Q = qG$ holds we have that $nQ = n(qG) = q(nG) = q\\infty = \\infty$. If this would not be the case, the third check would fail.\n\n\\bigskip\n\n\\subsection{Jacobian coordinates}\n\\label{jac}\nWe have already written that for EC over finite fields the same formulas previously seen hold, with the calculations done modulo $p$. What we have not dealt with is that this comes with a downside: in particular we have now to deal with modular inversion, an operation that, although can be done efficiently, is up to two orders of magnitude slower than field's multiplication.\n\\\\\nIn the next chapter we will deal with digital signatures and we will see that ECDSA requires modular inversion. This traduces in poor performances when it comes to a system like Bitcoin in which signatures are (potentially) verified by each participant in the network to validate transactions. Therefore, it is sometimes advantageous to avoid modular inversion, either in the formulas for point addition or in the signature scheme. The first case can be solved through a change of coordinates: the approach consists in writing all the points as points in a projective space, the key idea being to defer the divisions by multiplying them into a denominator, represented then as a new coordinate, instead of performing every division immediately. Only at the very end we perform a single division to convert from projective coordinates back to affine coordinates. \n\n\\bigskip\n\\noindent\nJacobian coordinates are a modification of projective coordinates, typically used since they lead to a faster doubling procedure. In affine form, each elliptic curve point has two coordinates $(x, y)$. In projective form, each point will have three coordinates $(X : Y : Z)$, with the restriction that $Z$ is never zero for points different from the point at infinity\\footnote{A projective point is denoted by $(X : Y : Z)$ since, in general, the two dimensional projective space \\textbf{P}$_K^2$ over a field $K$ is given by equivalence classes of triples $(X, Y, Z)$, with $X, Y, Z \\in K$ and at least one element different from zero. Here equivalence between $(X_1, Y_1, Z_1)$ and $(X_2, Y_2, Z_2)$ means that $\\exists \\lambda \\in K \\ | \\ (X_1, Y_1, Z_1) = \\lambda(X_2, Y_2, Z_2)$. Thus, the equivalence classes only depend on the ratios of $X$ to $Y$ to $Z$, from which the notation.}. The forward mapping is given by $(x, y) \\mapsto (xz^2, yz^3, z)$, for any non zero $z$ (usually chosen to be 1 for convenience). The reverse mapping is given by $(X : Y : Z) \\mapsto (X/Z^2, Y/Z^3)$, as long as $Z$ is non zero.\n\\\\\nThe elliptic curve $y^2 = x^3 + ax + b$ becomes:\n$$Y^2 = X^3 + aXZ^4 + bZ^6.$$\nThe point at infinity now has the coordinates $(1 : 1 : 0)$: indeed, substituting $Z = 0$ in the equation defining the curve we get $Y^2 = X^3$; then we simply normalize.\n\\\\\nLet $Q_i = (X_i : Y_i : Z_i), \\ i = 1, 2$, be points on the elliptic curve $Y^2 = X^3 + aXZ^4 + bZ^6$. Then:\n$$(X_3 : Y_3 : Z_3) = (X_1 : Y_1 : Z_1) + (X_2 : Y_2 : Z_2),$$\nwhere $X_3,Y_3$ and $Z_3$ are computed as follows:\n\\begin{itemize}\n\t\\item $Q_1 \\neq \\pm Q_2$: we have the affine test $x_1 = x_2$, that in jacobian coordinates correspond to the check $X_1/Z_1^2 = X_2/Z_2^2 \\ \\Longrightarrow \\ X_1Z_2^2 = X_2Z_1^2$. \n\t\\\\\n\tWe start again from the slope of the line passing through $Q_1$ and $Q_2$.\n\t$$m = \\frac{y_2 - y_1}{x_2 - x_1} = \\frac{Y_2/Z_2^3 - Y_1/Z_1^3}{X_2/Z_2^2 - X_1/Z_1^2} = \\frac{Y_2/Z_2^3 - Y_1/Z_1^3}{X_2/Z_2^2 - X_1/Z_1^2} \\cdot \\frac{Z_1^3Z_2^3}{Z_1^3Z_2^3} =$$ $$= \\frac{Y_2Z_1^3 - Y_1Z_2^3}{X_2Z_1^3Z_2 - X_1Z_1Z_2^3}.$$\n\tDefining $T = Y_1Z_2^3$, $U = Y_2Z_1^3$, $W = U - T$, $R = X_1Z_2^2$, $S = X_2Z_1^2$ and $V = S - R$ we can write:\n\t$$m = \\frac{U - T}{SZ_1Z_2 - RZ_1Z_2} = \\frac{W}{VZ_1Z_2}.$$\n\tNow consider:\n\t$$x_3 = m^2 - x_1 - x_2 = \\frac{W^2}{V^2Z_1^2Z_2^2} - \\frac{X_1}{Z_1^2} - \\frac{X_2}{Z_2^2} = \\frac{W^2}{V^2Z_1^2Z_2^2} - \\frac{X_1}{Z_1^2}\\cdot\\frac{V^2Z_2^2}{V^2Z_2^2} - \\frac{X_2}{Z_2^2}\\cdot\\frac{V^2Z_1^2}{V^2Z_1^2} = $$ $$= \\frac{W^2 - V^2X_1Z_2^2 - V^2X_2Z_1^2}{V^2Z_1^2Z_2^2} = \\frac{W^2 - V^2R - V^2S}{V^2Z_1^2Z_2^2} = \\frac{W^2 - V^2(S + R)}{V^2Z_1^2Z_2^2} = $$ $$= \\frac{W^2 - V^2(S - R + 2R)}{V^2Z_1^2Z_2^2} = \\frac{W^2 - V^3 - 2RV^2}{V^2Z_1^2Z_2^2},$$\n\t$$y_3 = m(x_1 - x_3) - y_1 = \\frac{W}{VZ_1Z_2}\\left(\\frac{X_1}{Z_1^2} - \\frac{W^2 - V^3 - 2RV^2}{V^2Z_1^2Z_2^2}\\right) - \\frac{Y_1}{Z_1^3} = $$ $$= \\frac{W}{VZ_1Z_2}\\left(\\frac{V^2X_1Z_2^2 - W^2 + V^3 + 2RV^2}{V^2Z_1^2Z_2^2}\\right) - \\frac{Y_1}{Z_1^3} = $$ $$= \\frac{W(RV^2 - [W^2 - V^3 - 2RV^2]) - V^3Y_1Z_2^3}{V^3Z_1^3Z_2^3} = $$ $$\\frac{W(RV^2 - [W^2 - V^3 - 2RV^2]) - TV^3}{V^3Z_1^3Z_2^3}.$$\n\tThus, we can write:\n\t$$X_3 = W^2 - V^3 - 2RV^2, \\ Y_3 = W(RV^2 - X_3) - TV^3, \\ Z_3 = VZ_1Z_2,$$\n\twhere\n\t$$T = Y_1Z_2^3, \\ U = Y_2Z_1^3, \\ R = X_1Z_2^2, \\ S = X_2Z_1^2, \\ V = S - R, \\ W = U - T.$$\n\t\\item $Q_1 = Q_2$:  now we have to check if $y = 0$. This is equivalent to check whether  $Y / Z^3 = 0 \\ \\Longrightarrow \\ Y = 0$, since $Z \\neq 0$.\n\t$$m = \\frac{3x^2 + a}{2y} = \\frac{3(X/Z^2)^2 + a}{2Y/Z^3} = \\frac{3X^2/Z^4 + a}{2Y/Z^3} \\cdot \\frac{Z^4}{Z^4} = \\frac{3X^2 + aZ^4}{2YZ} = \\frac{W}{2YZ},$$\n\tif we define $W = 3X^2 + aZ^4$.\n\t$$x_3 = m^2 - 2x = \\frac{W^2}{4Y^2Z^2} - 2\\frac{X}{Z^2} = \\frac{W^2 - 8XY^2}{4Y^2Z^2} = \\frac{W^2 - 2V}{4Y^2Z^2},$$ once we define $V = 4XY^2$. Moreover:\n\t$$y_3 = m(x - x_3) - y = \\frac{W}{2YZ}\\left(\\frac{X}{Z^2} - \\frac{W^2 - 2V}{4Y^2Z^2}\\right) - \\frac{Y}{Z^3} = $$ $$= \\frac{W(4XY^2 - [W^2 - 2V])}{8Y^3Z^3} - \\frac{Y}{Z^3} = \\frac{W(4XY^2 - [W^2 - 2V]) - 8Y^4}{8Y^3Z^3} =$$ $$= \\frac{W(V - [W^2 - 2V]) - 8Y^4}{8Y^3Z^3}.$$\n\tFinally we can write:\n\t$$X_3 = W^2 - 2V, \\ Y_3 = W(V - X_3) - 8Y^4, \\ Z_3 = 2YZ,$$\n\twhere\n\t$$W = 3X^2 + aZ^4, \\ V = 4XY^2.$$\n\t\\item Once again we can consider jointly the separate cases $Q_1 = Q_2 \\wedge y = 0$ and $Q_1 = -Q_2$: indeed, by definition, we have $Q_1 + Q_2 = \\infty$.\n\\end{itemize}\nLooking at the formulas we can see that no inversion is involved in the calculations. Moreover, a further speed up is possible when doubling if we set $a = -3$\\footnote{This is the reason why some standardized curves make this choice for the parameter $a$.}: we have $W = 3X^2 -3Z^4 = 3(X^2 - Z^4) = 3(X + Z^2)(X - Z^2)$, which can be computed via one squaring and one multiplication rather than via three squarings.\n\n\\bigskip\n\\noindent\nWe implemented this approach in the library that can be found at \\url{https://github.com/dginst/BitcoinBlockchainTechnology} to improve the efficiency of the curve's operations. The speed up checks have been performed considering the curves secp192k1, secp192r1, secp224k1, secp224r1, secp256k1, secp256r1, secp384r1 and secp521r1 as described in \\cite{RefWork:3}, resulting in a scalar multiplication that is from six to seven times faster in all the cases.\n\n\\bigskip\n\n\\subsection{The Bitcoin curve: secp256k1}\n\\label{btccurve}\nSince this work is mainly focused on applications that can be deployed in Bitcoin, we would like to present the elliptic curve over a finite field used there. This could also suggest the shape of the curves used in practice.\n\\\\\n\\\\\nThe curve is named secp256k1: the naming is not casual, and its analysis could help a better understanding of the curve's properties. It begins with {\\bf sec} to denote \"Standards for Efficient Cryptography\", the documentation from which it is taken; then it follows a {\\bf p}, denoting the use of parameters over a prime field $\\mathbb{F}_p$, in contrast with the so called binary fields $\\mathbb{F}_{2^m}$, denoted by the letter {\\bf t}; the {\\bf p} is followed by a number, 256, denoting the length in bits of the field size $p$, that suggests the difficulty of solving the DL on the curve; then it comes a {\\bf k} to denote parameters associated with a Koblitz curve\\footnote{The name Koblitz curve used here refers to the definition given in \\cite{RefWork:3}.}, to be distinguished from an {\\bf r}, that would denote the use of verifiably random parameters; at last we find the sequence number {\\bf 1}, meaning that this curve is the first, actually the unique, with all these characteristics.\n\\\\\nWe have already discussed the benefits of using a random curve; however, secp256k1 was constructed in a special non random way to ensure efficient computations.\n\\\\\nHere follows the sextuple $T$ defining the secp256k1 curve:\n\\begin{itemize}\n\t\\item The finite field $\\mathbb{F}_p$ is defined by the pseudo-Mersenne prime number: \n\t$$p = \\text{FFFFFFFF} \\ \\ \\text{FFFFFFFF} \\ \\ \\text{FFFFFFFF} \\ \\ \\text{FFFFFFFF} \\ \\ \\text{FFFFFFFF}$$ \n\t$\\text{FFFFFFFF} \\ \\text{FFFFFFFE} \\ \\text{FFFFFC2F} =$\n\t\\\\\n\t\\\\\n\t$= 2^{256} - 2^{32} - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1.$\n\t\\item The defining equation $E$: $y^2 = x^3 + ax + b$ is determined by:\n\t$$a = \\text{00000000} \\ \\ \\text{00000000} \\ \\ \\text{00000000} \\ \\ \\text{00000000} \\ \\ \\text{00000000} \\ \\ \\text{00000000} \\ \\ \\text{00000000}$$\n\t$ \\text{00000000} =$\n\t\\\\\n\t\\\\\n\t$= 0;$\n\t$$b = \\text{00000000} \\ \\ \\text{00000000} \\ \\ \\text{00000000} \\ \\ \\text{00000000} \\ \\ \\text{00000000} \\ \\ \\text{00000000} \\ \\ \\text{00000000}$$\n\t$ \\text{00000007} =$\n\t\\\\\n\t\\\\\n\t$= 7.$\n\t\\\\\n\t\\\\\n\tHence $E$:\t$y^2 = x^3 + 7$.\n\t\\item The point $G$ in compressed form is\\footnote{The starting bytes 0x02 and 0x04 mean exactly that the first expression of $G$ is in compressed form, while the second one is uncompressed. For what concerns the compressed form we need to have informations about the $y$ coordinate. 0x02 is used when it is even, while 0x03 is used when it is odd: if $y$ is a square root in $\\mathbb{F}_p$, we know that also $-y \\ (\\text{mod} \\ p) = p - y$ is a square root. Since $p$ is an odd prime, we are sure that one of the roots is odd while the other is even.}:\n\t$$G = \\text{02} \\ \\ \\text{79BE667E} \\ \\ \\text{F9DCBBAC} \\ \\ \\text{55A06295} \\ \\ \\text{CE870B07} \\ \\ \\text{029BFCDB}$$ \n\t$\\text{2DCE28D9} \\ \\ \\text{59F2815B} \\ \\ \\text{16F81798},$\n\t\\\\\n\t\\\\\n\tand in uncompressed form:\n\t$$G = \\text{04} \\ \\ \\text{79BE667E} \\ \\ \\text{F9DCBBAC} \\ \\ \\text{55A06295} \\ \\ \\text{CE870B07} \\ \\ \\text{029BFCDB}$$ \n\t$\\text{2DCE28D9} \\ \\ \\text{59F2815B} \\ \\ \\text{16F81798} \\ \\ \\text{483ADA77} \\ \\ \\text{26A3C465} \\ \\ \\text{5DA4FBFC}$\n\t\\\\\n\t\\\\\n\t$\\text{0E1108A8} \\ \\ \\text{FD17B448} \\ \\ \\text{A6855419} \\ \\ \\text{9C47D08F} \\ \\ \\text{FB10D4B8}$.\n\t\\item Finally, the order $n$ of $G$ and the cofactor are:\n\t$$n = \\text{FFFFFFFF} \\ \\ \\text{FFFFFFFF} \\ \\ \\text{FFFFFFFF} \\ \\ \\text{FFFFFFFE} \\ \\ \\text{BAAEDCE6}$$\n\t$\\text{AF48A03B} \\ \\ \\text{BFD25E8C} \\ \\ \\text{D0364141},$\n\t\\\\\n\t\\\\\n\t$h = \\text{01}$.\n\\end{itemize}\n\n\\bigskip\n\n\\bigskip\n\n\\section{The discrete logarithm problem}\n\\label{dlp}\nIn this section we will deal more in depth with the obscure concept of Discrete Logarithm Problem (DLP).\n\\\\\nIn general the DLP is defined over a group $\\mathbb{G}$. For the moment write $\\mathbb{G}$ in multiplicative notation and consider $x, y \\in \\mathbb{G}$ such that $y$ is in the cyclic subgroup generated by $x$. The DLP is the problem of determining an integer $k \\geq 1$ such that $x^k = y$: this notation justifies the name, since it would mean to find $k = log_xy$.\n\\\\\nTypically, the cryptosystems whose security is based on ECC, depend on the difficulty of solving the DLP defined over the EC (ECDLP). One way of attacking the DLP is simple brute force: try all possible values of $k$ until one works. This is impractical when the answer $k$ is an integer of several hundred digits, which is a typical size used in cryptography (indeed this approach is fully exponential in the number of bits representing $k$\\footnote{Assume for example to work with secp256k1, the Bitcoin curve. This means that $p \\simeq 2^{256}$, and the same holds true for $n$. By brute force we try all possible values of $k$, that ranges from $1$ to $n-1$. Trying all possible $k$ would lead to a number of steps of the order $O(2^{256})$, exponential in the number of bits representing the order of the group.}). Therefore, better techniques are needed.\n\\\\\nMore formally, the DLP can be defined as follows:\n\\begin{mydef}\n\tLet $\\mathbb{G}$ be a cyclic group of order $n$ and let $g$ be a generator. An algorithm $\\mathcal{A}$ is said to $(t, \\epsilon)$-solve the DLP in $\\mathbb{G}$ if on input a random $h \\in \\mathbb{G}$, it runs in time at most $t$ and returns $k \\in \\{0, ..., n - 1\\}$ such that $h = g^k$ with probability at least $\\epsilon$.\n\\end{mydef}\n\\noindent\nThe most general algorithms that works in any group has a time upper bound of $O(|\\mathbb{G}|^{\\frac{1}{2}})$, where with $|\\mathbb{G}|$ we denote the cardinality of the set $\\mathbb{G}$. But it turns out that the DLP is significantly easier in some groups than it is in others. In order of difficulty:\n\\begin{enumerate}\n\t\\item The additive group of $\\mathbb{F}_q$: the problem here can be stated as finding $k$ such that $kx = y$, i.e. we only need to find the inverse of $x$, and we have already stated that this can be done efficiently through the extended euclidean algorithm (in particular this requires $O(log_2(q))$ elementary operations, meaning that the problem can be solved in polynomial time);\n\t\\item The multiplicative group $\\mathbb{F}_q^{\\times}$: the problem here is finding $k$ such that $x^k = y$. It can be shown that there exist some algorithms that work in sub-exponential time (the so called index calculus methods);\n\t\\item Elliptic curves over finite fields: the fastest known procedure to solve the ECDLP on general curves are collision algorithms. Those algorithms are fully exponential: this explains the widespread adoption of ECC in recent years\n\\end{enumerate}\n\\noindent\nThe last point is linked to the primary benefit of ECC, that is a smaller key size: since the problem is harder, in order to have the same level of security we can rely on smaller keys, reducing storage and transmission requirements.\n\n\\bigskip\n\\noindent\nThe two most general algorithms are known as {\\bf Baby Step, Gian Step Algorithm} and as the {\\bf Pollard's $\\rho$ Method} with its variants\\footnote{For a detailed but still easily understandable presentation of the algorithms we refer to \\cite{RefWork:4}.}: as explained above both runs in time $O(|\\mathbb{G}|^{\\frac{1}{2}})$, but the first is exponential also in the memory required to run, making it absolutely impractical. But let's focus on the run time of the algorithms on the Bitcoin's curve: assuming that the scalar multiplication requires constant time on the order of milliseconds, solving the ECDLP would require time proportional to $10^{-3} * 2^{128} \\simeq 10^{35}$ seconds or around $10^{28}$ years. It is easy to see that even relying on optimizations, super computers or parallelization, nowadays it is computationally infeasible to solve the ECDLP. \n", "meta": {"hexsha": "a2f8aa77cfd2df02caa21f5f99438527ef5b2013", "size": 27699, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/ECC.tex", "max_stars_repo_name": "gionasoldati/thesis", "max_stars_repo_head_hexsha": "e8b3b3828f4ccb0a35e26381b361425e09a51b11", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/ECC.tex", "max_issues_repo_name": "gionasoldati/thesis", "max_issues_repo_head_hexsha": "e8b3b3828f4ccb0a35e26381b361425e09a51b11", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapters/ECC.tex", "max_forks_repo_name": "gionasoldati/thesis", "max_forks_repo_head_hexsha": "e8b3b3828f4ccb0a35e26381b361425e09a51b11", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-06T23:47:52.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-06T23:47:52.000Z", "avg_line_length": 107.7782101167, "max_line_length": 1318, "alphanum_fraction": 0.7118668544, "num_tokens": 8940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7051299642831634}}
{"text": "\\documentclass[11pt, a4paper]{article}\n\n\\usepackage{tikz}\n\\usetikzlibrary{arrows,automata, shapes, petri}\n\\usepackage{amsmath}\n\n\\begin{document}\n\n\\title{BACKPROPAGATION}\n\\date{}\n\\maketitle\n\nBackpropagation is a computer algorithm used for supervised training of Artificial Neural Networks. It is based on two ideas - the Chain Rule of derivatives in Calculus and Dynamic Programming.\n\n\\section{Notation}\n\n\\begin{center}\n\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,\n\t\tsemithick]\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\node[state] (I1)                    {$\\ \\ a^1_1$};\n\t\t\\node[state] (I2) [below of=I1, node distance=5em] {$\\ \\ a^1_2$};\n\t\t\\node[state] (I3) [below of=I2, node distance=5em] {$\\ \\ a^1_3$};\n\t\t\t\t\t\t\n\t\t\\node[state] (J1) [above right of=I1, node distance=8em]  {$z^2_1|a^2_1$};\n\t\t\\node[state] (J2) [below of=J1, node distance=7em] {$z^2_2|a^2_2$};\n\t\t\\node[state] (J3) [below of=J2, node distance=7em] {$z^2_3|a^2_3$};\n\t\t\\node[state] (J4) [below of=J3, node distance=7em] {$z^2_4|a^2_4$};\t\n\t\t\t\t\t\t\n\t\t\\node[state] (K1) [below right of=J1, node distance=10em]  {$z^3_1|a^3_1$};\n\t\t\\node[state] (K2) [below of=K1, node distance=7em] {$z^3_2|a^3_2$};\t\n\t\t\t\t\t\t\n\t\t\\node [rectangle, node distance=2cm] (I) [above of=I1] {1};\n\t\t\\node [rectangle, node distance=2cm] (J) [above of=J1] {2};\n\t\t\\node [rectangle, node distance=2cm] (K) [above of=K1] {3};\t\n\t\t\t\t\t\t\n\t\t\\path (I2) edge  node {$w^2_{32}$} (J3);\t\n\t\t\\path (J4) edge  node {$w^3_{24}$} (K2);\t\t\n\t\t\t\t\t\t                   \n\t\\end{tikzpicture}\n\\end{center}\n\nThe layers are of the Neural Network are denoted by positive integers with input layer denoted by $1$, the first hidden layer by $2$ and so on till the output layer. The inputs in the input layer are denoted by $a^1_{i}$ as shown above. For all the other neurons in other layers, $z^l_i$ denotes the weighted sum of the neuron activations in the previous layer and $a^l_i$ denotes that neuron's activation. The weights are superscripted by the index of the layer of the neuron at the end, and subscripted first by the layer index of the end neuron and then by that of the start neuron.\n\n\\section{Forward Pass}\n\nFor any layer $l$ which is apart from the input layer, it can be written,\n\n\\begin{align*}\n\tz^l_i = \\left( \\sum_j w^l_{ij}a^{l-1}_j \\right)  + b^l_i \n\\end{align*} \n\nTaking examples from the figure,\n\n\\begin{align*}\n\tz^2_1 = (w^2_{11}a^1_1  + w^2_{12}a^1_2  +  w^2_{13}a^1_3) + b^2_1 \\\\ \n\tz^2_2 = (w^2_{21}a^1_1  + w^2_{22}a^1_2  +  w^2_{23}a^1_3) + b^2_2 \\\\\n\tz^2_3 = (w^2_{31}a^1_1  + w^2_{32}a^1_2  +  w^2_{33}a^1_3) + b^2_3 \\\\\n\tz^2_4 = (w^2_{41}a^1_1  + w^2_{42}a^1_2  +  w^2_{43}a^1_3) + b^2_4 \n\\end{align*}\n\nThese equations can be rewritten in matrix form as follows,\n\n\\begin{align*}\n\t\\begin{pmatrix} z^2_1 \\\\ z^2_2 \\\\ z^2_3 \\\\z^2_4 \\end{pmatrix} = \\begin{pmatrix}  w^2_{11} & w^2_{12} & w^2_{13} \\\\ w^2_{21} & w^2_{22} & w^2_{23} \\\\ w^2_{31} & w^2_{32} & w^2_{33} \\\\w^2_{41} & w^2_{42} & w^2_{43}  \\end{pmatrix} \\begin{pmatrix} a^1_1 \\\\ a^1_2 \\\\ a^1_3 \\\\ \\end{pmatrix} + \\begin{pmatrix} b^2_1 \\\\ b^2_2 \\\\ b^2_3 \\\\b^2_4 \\end{pmatrix}\t\n\\end{align*}\n\nor \n\n\\begin{align*}\n\t\\boldsymbol{Z}^2 = \\boldsymbol{W}^2 \\boldsymbol{A}^1 + \\boldsymbol{B}^2 \n\\end{align*}\n\nGeneralizing for all layers,\n\n\\begin{align}\n\t\\boldsymbol{Z}^l = \\boldsymbol{W}^l \\boldsymbol{A}^{l-1} + \\boldsymbol{B}^l \n\\end{align}\n\nActivation function $\\sigma$ is applied to $z^l_i$ to yield $a^l_i$.\n\n\\begin{align*}\n\ta^2_1 = \\sigma(z^2_1) \\\\\n\ta^2_2 = \\sigma(z^2_2) \\\\\n\ta^2_3 = \\sigma(z^2_3) \\\\\n\ta^2_4 = \\sigma(z^2_4) \\\\\n\\end{align*} \n\nwhich can be written in matrix form as,\n\n\\begin{align*}\n\t\\boldsymbol{Z}^2 = \\sigma(\\boldsymbol{A}^2) \n\\end{align*}\n\nor more generally as,\n\n\\begin{align}\n\t\\boldsymbol{Z}^l = \\sigma(\\boldsymbol{A}^l) \n\\end{align}\n\nGiven $\\boldsymbol{A}^1$, any $\\boldsymbol{Z}^l$ or $\\boldsymbol{A}^l$ can be calculated using the two equations (1) and (2). This completes the analysis of the forward pass of backpropagation algorithm.\n\n\\section{Backward Pass}\n\nImagine a point in time where the weights and biases of a neural network are fixed. Now, one training example is taken and its inputs are fed into the neural network. Using the the forward pass equations, the neural network's output is computed. Usually, this output is different from the training example's expected output and thus the goal of backpropagation is to calucate the partial derivates of the cost function w.r.t. each weight and bias for them to be tweaked optimally.\n\n\\subsection{Cost Function}\n\nThe notion of the difference between the expected output of a training example and the actual output from neural network is formalized as follows,\n\n\\begin{align*}\n\tC & = \\frac{1}{2} ||\\boldsymbol{Y} - \\boldsymbol{A}^L||^2 \\\\\n\t  & = \\frac{1}{2}\\sum_j (y_j - a^L_j)^2                   \n\\end{align*}\n\n\\subsection {Backpropagation}\n\n\\begin{align*}\n\t\\frac{\\partial C}{\\partial z^L_j} & = (a^L_j - y_j) \\frac{\\partial a^L_j}{\\partial z^L_j} \\\\\n\t                                  & = (a^L_j - y_j) \\times \\sigma^{'} (z^L_j)             \n\\end{align*}\n\nDenoting $\\frac{\\partial C}{\\partial z^L_j}$ by $\\delta^L_j$ and $(\\delta^L_1, \\delta^L_2, .. )^T$ by $\\boldsymbol{\\Delta^L}$, it can be written\n\n\\begin{align}\n\t\\boldsymbol{\\Delta^L} = (\\boldsymbol{A^L} - \\boldsymbol{Y}) \\odot \\sigma^{'}(\\boldsymbol{Z^L}) \n\\end{align}\n\nwhere $\\odot$ denotes element-wise matrix product.\n\nCan $\\boldsymbol{\\Delta^L}$ somehow be related to $\\boldsymbol{\\Delta^{L-1}}$?\n\n\\begin{align*}\n\t\\delta^{L-1}_j & = \\frac{\\partial C}{\\partial z^{L-1}_j}                                                                                              \\\\\n\t               & = \\frac{\\partial C}{\\partial a^{L-1}_j} \\frac{\\partial a^{L-1}_j}{\\partial z^{L-1}_j}                                                \\\\\n\t               & = \\frac{\\partial C}{\\partial a^{L-1}_j} \\times \\sigma^{'}(z^{L-1}_j)                                                                 \\\\\n\t               & = \\left( \\sum_i \\frac{\\partial z^{L}_i}{\\partial a^{L-1}_j} \\frac{\\partial C}{\\partial z^{L}_i} \\right) \\times \\sigma^{'}(z^{L-1}_j) \\\\\n\t               & = \\left( \\sum_i w^L_{ij} \\delta^L_i \\right) \\times \\sigma^{'}(z^{L-1}_j)                                                             \\\\\n\\end{align*}\n\nFor the above example, the equations become\n\n\\begin{align*}\n\t\\begin{pmatrix} \\delta^{L-1}_1 \\\\ \\delta^{L-1}_2 \\\\ \\delta^{L-1}_3 \\\\ \\delta^{L-1}_4 \\end{pmatrix} &= \\begin{pmatrix}  w^L_{11} & w^L_{21} \\\\ w^L_{12} & w^L_{22} \\\\ w^L_{13} & w^L_{23} \\\\w^L_{14} & w^L_{24}  \\end{pmatrix} \\begin{pmatrix} \\delta^L_1 \\\\ \\delta^L_2 \\end{pmatrix} \\odot \\begin{pmatrix} \\sigma^{'}(z^{L-1}_1) \\\\ \\sigma^{'}(z^{L-1}_2) \\\\ \\sigma^{'}(z^{L-1}_3) \\\\ \\sigma^{'}(z^{L-1}_4) \\end{pmatrix} \\\\\t\t\n\t\\boldsymbol{\\Delta^{L-1}} &= \\boldsymbol{W^L}^T \\boldsymbol{\\Delta^L} \\odot \\sigma^{'}(\\boldsymbol{Z^{L-1}})\n\\end{align*}\n\nThe equation can be generalized to,\n\n\\begin{align}\n\t\\boldsymbol{\\Delta^{l}} & = \\boldsymbol{W^{l+1}}^T \\boldsymbol{\\Delta^{l+1}} \\odot \\sigma^{'}(\\boldsymbol{Z^{l}}) \n\\end{align}\n\nUsing equation (3) and (4) $\\boldsymbol{\\Delta^{l}}$ can be calculated for any $l$.\n\n\\begin{align}\n\t\\frac{\\partial C}{\\partial w^l_{jk}} & = \\frac{\\partial z^l_{j}}{\\partial w^l_{jk}} \\frac{\\partial C}{\\partial z^l_{j}}             \n\t= a^{l-1}_k \\delta^l_j \\\\\n\t\\frac{\\partial C}{\\partial b^l_{j}}  & = \\frac{\\partial z^l_{j}}{\\partial b^l_{j}} \\frac{\\partial C}{\\partial z^l_{j}} = \\delta^l_j \n\\end{align}\n\nHence, equations (3) and (4) ``propagate\" the error backwards and then with help of equations (5) and (6), partial derivative of the error w.r.t. any neural network weight or bias can be calculated.\n\n\\section{Conclusion}\n\nBackpropagation is famous because it can quickly calculate partial derivatives to optimally adjust the parameters of a neural network. In the description above, backpropagation calculates the derivatives w.r.t only one training example. In practice training examples are bunched into mini-batches and partials calculated for each example in a mini batch are averaged for network parameter adjustment.\n\n\\end{document}", "meta": {"hexsha": "f6076da24fe2cade9b257f3ad696c1922ce65829", "size": 8025, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Backpropagation/Backpropagation.tex", "max_stars_repo_name": "singaurav/machine-learning-notes", "max_stars_repo_head_hexsha": "4fdd5b839156bcbf8f95a36275b8cd10f93e4c9d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-26T11:33:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-26T11:33:39.000Z", "max_issues_repo_path": "Backpropagation/Backpropagation.tex", "max_issues_repo_name": "singaurav/machine-learning-notes", "max_issues_repo_head_hexsha": "4fdd5b839156bcbf8f95a36275b8cd10f93e4c9d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Backpropagation/Backpropagation.tex", "max_forks_repo_name": "singaurav/machine-learning-notes", "max_forks_repo_head_hexsha": "4fdd5b839156bcbf8f95a36275b8cd10f93e4c9d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-22T18:56:20.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-22T18:56:20.000Z", "avg_line_length": 47.7678571429, "max_line_length": 585, "alphanum_fraction": 0.6235514019, "num_tokens": 2908, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199511728004, "lm_q2_score": 0.8418256393148982, "lm_q1q2_score": 0.7051299508989565}}
{"text": "\\section{Class List}\nHere are the classes, structs, unions and interfaces with brief descriptions\\+:\\begin{DoxyCompactList}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1add}{numpp\\+::differentiation\\+::symbolic\\+::add$<$ Left, Right $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1add}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1matrix_1_1sparse_1_1block}{numpp\\+::matrix\\+::sparse\\+::block$<$ T, Rows, Columns $>$} \\\\*Block version of sparse matrix }{\\pageref{classnumpp_1_1matrix_1_1sparse_1_1block}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1constant}{numpp\\+::differentiation\\+::symbolic\\+::constant$<$ Value $>$} \\\\*Class representing constant integer number }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1constant}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1cosinus}{numpp\\+::differentiation\\+::symbolic\\+::cosinus$<$ T $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1cosinus}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1matrix_1_1dense}{numpp\\+::matrix\\+::dense$<$ T, Rows, Columns $>$} }{\\pageref{classnumpp_1_1matrix_1_1dense}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate}{numpp\\+::differentiation\\+::symbolic\\+::differentiate$<$ Function, Order $>$} \\\\*Allows differentiation of N-\\/th order }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate_3_01Function_00_011_01_4}{numpp\\+::differentiation\\+::symbolic\\+::differentiate$<$ Function, 1 $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate_3_01Function_00_011_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1divide}{numpp\\+::differentiation\\+::symbolic\\+::divide$<$ Left, Right $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1divide}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1exponential}{numpp\\+::differentiation\\+::symbolic\\+::exponential$<$ T $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1exponential}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\\+::differentiation\\+::automatic\\+::forward$<$ T $>$} }{\\pageref{classnumpp_1_1differentiation_1_1automatic_1_1forward}}{}\n\\item\\contentsline{section}{\\hyperlink{structnumpp_1_1matrix_1_1sparse_1_1impl_1_1inner__block}{numpp\\+::matrix\\+::sparse\\+::impl\\+::inner\\+\\_\\+block$<$ T $>$} }{\\pageref{structnumpp_1_1matrix_1_1sparse_1_1impl_1_1inner__block}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1logarithm}{numpp\\+::differentiation\\+::symbolic\\+::logarithm$<$ T $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1logarithm}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1minus}{numpp\\+::differentiation\\+::symbolic\\+::minus$<$ T $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1minus}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1multiply}{numpp\\+::differentiation\\+::symbolic\\+::multiply$<$ Left, Right $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1multiply}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1matrix_1_1sparse_1_1nested}{numpp\\+::matrix\\+::sparse\\+::nested$<$ T, Rows, Columns $>$} \\\\*Block nested version of sparse matrix }{\\pageref{classnumpp_1_1matrix_1_1sparse_1_1nested}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1power}{numpp\\+::differentiation\\+::symbolic\\+::power$<$ Left, Exp $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1power}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+addition$<$ Left, Right $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01add_3_01constant_3_0a2e8fcb21917ecf6b67a5c4cb33302f3}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+addition$<$ add$<$ constant$<$ left\\+\\_\\+value $>$, Right $>$, constant$<$ right\\+\\_\\+value $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01add_3_01constant_3_0a2e8fcb21917ecf6b67a5c4cb33302f3}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01add_3_01Left_00_01co9800d9c084c22272aa6400ee9a366a08}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+addition$<$ add$<$ Left, constant$<$ left\\+\\_\\+value $>$ $>$, constant$<$ right\\+\\_\\+value $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01add_3_01Left_00_01co9800d9c084c22272aa6400ee9a366a08}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_010_01_4_00_01constant_3_010_01_4_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+addition$<$ constant$<$ 0 $>$, constant$<$ 0 $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_010_01_4_00_01constant_3_010_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_010_01_4_00_01minus_3_01Right_01_4_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+addition$<$ constant$<$ 0 $>$, minus$<$ Right $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_010_01_4_00_01minus_3_01Right_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_010_01_4_00_01Right_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+addition$<$ constant$<$ 0 $>$, Right $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_010_01_4_00_01Right_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_01left__vfa025c621c0342a297dcef4b571ae845}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+addition$<$ constant$<$ left\\+\\_\\+value $>$, add$<$ constant$<$ right\\+\\_\\+value $>$, Right $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_01left__vfa025c621c0342a297dcef4b571ae845}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_01left__v2b04d4fb76b2adc8e73af8cc3aa482e4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+addition$<$ constant$<$ left\\+\\_\\+value $>$, add$<$ Left, constant$<$ right\\+\\_\\+value $>$ $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_01left__v2b04d4fb76b2adc8e73af8cc3aa482e4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01Left_00_01constant_3_010_01_4_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+addition$<$ Left, constant$<$ 0 $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01Left_00_01constant_3_010_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01Left_00_01minus_3_01Right_01_4_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+addition$<$ Left, minus$<$ Right $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01Left_00_01minus_3_01Right_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01minus_3_01Left_01_4_00_01constant_3_010_01_4_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+addition$<$ minus$<$ Left $>$, constant$<$ 0 $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01minus_3_01Left_01_4_00_01constant_3_010_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01minus_3_01Left_01_4_00_01Right_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+addition$<$ minus$<$ Left $>$, Right $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01minus_3_01Left_01_4_00_01Right_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+division$<$ Upper, Lower $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01constant_3_010_01_4_00_01T_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+division$<$ constant$<$ 0 $>$, T $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01constant_3_010_01_4_00_01T_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01constant_3_011_01_4_b4d4ff9717ee8780cd1da6b85e108a8c}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+division$<$ constant$<$ 1 $>$, divide$<$ First, Second $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01constant_3_011_01_4_b4d4ff9717ee8780cd1da6b85e108a8c}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01First_00_01multiply_3_01First_00_01Second_01_4_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+division$<$ First, multiply$<$ First, Second $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01First_00_01multiply_3_01First_00_01Second_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01multiply_3_01First_009a599186e504c392075b7a47787417d}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+division$<$ multiply$<$ First, Second $>$, multiply$<$ Second, Third $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01multiply_3_01First_009a599186e504c392075b7a47787417d}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01multiply_3_01First_0c33d7e82a36da3303a0a365fc4a46997}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+division$<$ multiply$<$ First, Second $>$, Second $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01multiply_3_01First_0c33d7e82a36da3303a0a365fc4a46997}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01T_00_01constant_3_011_01_4_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+division$<$ T, constant$<$ 1 $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01T_00_01constant_3_011_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01T_00_01T_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+division$<$ T, T $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01T_00_01T_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+minus$<$ T $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus_3_01minus_3_01constant_3_010_01_4_01_4_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+minus$<$ minus$<$ constant$<$ 0 $>$ $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus_3_01minus_3_01constant_3_010_01_4_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus_3_01minus_3_01subtract_3_01Left_00_01Right_01_4_01_4_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+minus$<$ minus$<$ subtract$<$ Left, Right $>$ $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus_3_01minus_3_01subtract_3_01Left_00_01Right_01_4_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus_3_01minus_3_01T_01_4_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+minus$<$ minus$<$ T $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus_3_01minus_3_01T_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+multiplication$<$ Left, Right $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01constant_3_010_01_4_00_01Right_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+multiplication$<$ constant$<$ 0 $>$, Right $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01constant_3_010_01_4_00_01Right_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01constant_3_011_01_4_00_01Right_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+multiplication$<$ constant$<$ 1 $>$, Right $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01constant_3_011_01_4_00_01Right_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01constant_3_01ld8b2feb223452c4aaaf6eb83932601c0}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+multiplication$<$ constant$<$ left\\+\\_\\+value $>$, multiply$<$ T, constant$<$ right\\+\\_\\+value $>$ $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01constant_3_01ld8b2feb223452c4aaaf6eb83932601c0}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01First_00_01dive5d11c87e98ba09157b84506291511c8}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+multiplication$<$ First, divide$<$ constant$<$ 1 $>$, Second $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01First_00_01dive5d11c87e98ba09157b84506291511c8}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01Left_00_01constant_3_010_01_4_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+multiplication$<$ Left, constant$<$ 0 $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01Left_00_01constant_3_010_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01Left_00_01constant_3_011_01_4_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+multiplication$<$ Left, constant$<$ 1 $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01Left_00_01constant_3_011_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01minus_3_01Firsc21300ab659abf99cc3eaf6c7230201c}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+multiplication$<$ minus$<$ First $>$, minus$<$ Second $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01minus_3_01Firsc21300ab659abf99cc3eaf6c7230201c}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01multiply_3_01Te3834a073b1fa2b6ff55d54d5efcdc27}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+multiplication$<$ multiply$<$ T, constant$<$ left\\+\\_\\+value $>$ $>$, constant$<$ right\\+\\_\\+value $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01multiply_3_01Te3834a073b1fa2b6ff55d54d5efcdc27}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__subtraction}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+subtraction$<$ Left, Right $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__subtraction}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__subtraction_3_01Left_00_01minus_3_01Right_01_4_01_4}{numpp\\+::differentiation\\+::symbolic\\+::impl\\+::simplify\\+\\_\\+subtraction$<$ Left, minus$<$ Right $>$ $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__subtraction_3_01Left_00_01minus_3_01Right_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1sinus}{numpp\\+::differentiation\\+::symbolic\\+::sinus$<$ T $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1sinus}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1subtract}{numpp\\+::differentiation\\+::symbolic\\+::subtract$<$ Left, Right $>$} }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1subtract}}{}\n\\item\\contentsline{section}{\\hyperlink{classtuple__element}{tuple\\+\\_\\+element} \\\\*Tuple\\+\\_\\+element specialization for \\hyperlink{classnumpp_1_1vector}{numpp\\+::vector} }{\\pageref{classtuple__element}}{}\n\\item\\contentsline{section}{\\hyperlink{classtuple__element}{tuple\\+\\_\\+element} \\\\*Tuple\\+\\_\\+element specialization for \\hyperlink{classnumpp_1_1matrix_1_1dense}{numpp\\+::matrix\\+::dense} }{\\pageref{classtuple__element}}{}\n\\item\\contentsline{section}{\\hyperlink{classstd_1_1tuple__element_3_01Index_00_01numpp_1_1matrix_1_1dense_3_01T_00_01Rows_00_01Columns_01_4_01_4}{std\\+::tuple\\+\\_\\+element$<$ Index, numpp\\+::matrix\\+::dense$<$ T, Rows, Columns $>$ $>$} }{\\pageref{classstd_1_1tuple__element_3_01Index_00_01numpp_1_1matrix_1_1dense_3_01T_00_01Rows_00_01Columns_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classstd_1_1tuple__element_3_01Index_00_01numpp_1_1vector_3_01T_00_01Size_00_01Transposition_01_4_01_4}{std\\+::tuple\\+\\_\\+element$<$ Index, numpp\\+::vector$<$ T, Size, Transposition $>$ $>$} }{\\pageref{classstd_1_1tuple__element_3_01Index_00_01numpp_1_1vector_3_01T_00_01Size_00_01Transposition_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classtuple__size}{tuple\\+\\_\\+size} \\\\*Tuple\\+\\_\\+size specialization for \\hyperlink{classnumpp_1_1matrix_1_1dense}{numpp\\+::matrix\\+::dense} }{\\pageref{classtuple__size}}{}\n\\item\\contentsline{section}{\\hyperlink{classtuple__size}{tuple\\+\\_\\+size} \\\\*Tuple\\+\\_\\+size specialization for \\hyperlink{classnumpp_1_1vector}{numpp\\+::vector} }{\\pageref{classtuple__size}}{}\n\\item\\contentsline{section}{\\hyperlink{classstd_1_1tuple__size_3_01numpp_1_1matrix_1_1dense_3_01T_00_01Rows_00_01Columns_01_4_01_4}{std\\+::tuple\\+\\_\\+size$<$ numpp\\+::matrix\\+::dense$<$ T, Rows, Columns $>$ $>$} }{\\pageref{classstd_1_1tuple__size_3_01numpp_1_1matrix_1_1dense_3_01T_00_01Rows_00_01Columns_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classstd_1_1tuple__size_3_01numpp_1_1vector_3_01T_00_01Size_00_01Tranposition_01_4_01_4}{std\\+::tuple\\+\\_\\+size$<$ numpp\\+::vector$<$ T, Size, Tranposition $>$ $>$} }{\\pageref{classstd_1_1tuple__size_3_01numpp_1_1vector_3_01T_00_01Size_00_01Tranposition_01_4_01_4}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1variable}{numpp\\+::differentiation\\+::symbolic\\+::variable$<$ T, Number $>$} \\\\*Class representing variable of any type }{\\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1variable}}{}\n\\item\\contentsline{section}{\\hyperlink{classnumpp_1_1vector}{numpp\\+::vector$<$ T, Size, Transposition $>$} }{\\pageref{classnumpp_1_1vector}}{}\n\\end{DoxyCompactList}\n", "meta": {"hexsha": "7a4cca1799378acf227f5c6910f071028b3570f3", "size": 20868, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/annotated.tex", "max_stars_repo_name": "szymonmaszke/numpp", "max_stars_repo_head_hexsha": "9149c9d81f70a6ce833fdd1d2f0f2b584e2ac4d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2018-06-06T01:51:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-02T15:17:00.000Z", "max_issues_repo_path": "docs/annotated.tex", "max_issues_repo_name": "vyzyv/numpp", "max_issues_repo_head_hexsha": "9149c9d81f70a6ce833fdd1d2f0f2b584e2ac4d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-11-28T12:15:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-16T00:03:38.000Z", "max_forks_repo_path": "docs/annotated.tex", "max_forks_repo_name": "szymonmaszke/numpp", "max_forks_repo_head_hexsha": "9149c9d81f70a6ce833fdd1d2f0f2b584e2ac4d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-08-06T13:58:27.000Z", "max_forks_repo_forks_event_max_datetime": "2018-04-06T06:45:22.000Z", "avg_line_length": 311.4626865672, "max_line_length": 482, "alphanum_fraction": 0.8283975465, "num_tokens": 8480, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951143326726, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7050604802523088}}
{"text": "\\chapter{Uncountable Sets}\n\nIn the previous chapter we proved that many sets are countable; moreover, we\nproved that standard operations such as union, intersection, and product of\ncountable sets is also countable. This chapter shows that we know at least one\nuncountable set. Moreover, this chapter gives tools to compare cardinalities of\nsets.\n\n\\section{Cardinality of Reals}\n\\begin{theorem}[Cantor]\n\\label{theorem:reals-are-uncountable}\n  The set of real number $\\R$ is uncountable.\n\\end{theorem}\n\nTo prove this theorem we need the following two lemmas.\n\\begin{lemma}\n\\label{lemma:segment-is-uncountable}\n  The set $\\set[0 < x < 1]{x \\in \\R}$ of real numbers between $0$ and $1$ is\n  uncountable.\n\\end{lemma}\n\n\\begin{lemma}\n\\label{lemma:segment-equipotent-to-reals}\n  The set $\\R$ is equipotent to $\\set[0 < x < 1]{x \\in \\R}$.\n\\end{lemma}\n\n\\begin{proof}[Proof of \\Cref{theorem:reals-are-uncountable}]\n  Assume that $\\R$ is denumerable. Then by\n  \\Cref{remark:denumerable-equipotent-to-denumerable,lemma:segment-equipotent-to-reals},\n  $\\set[0 \\le x \\le 1]{x \\in \\R}$ is also denumerable, which contradicts\n  \\Cref{lemma:segment-is-uncountable}.\n\\end{proof}\n\nTo complete the proof of \\Cref{theorem:reals-are-uncountable} we need to prove\nthese two lemmas.\n\\begin{proof}[Proof of \\Cref{lemma:segment-is-uncountable}]\n  Assume $\\set[0 < x < 1]{x \\in \\R}$ is countable; this implies that \n  $S = \\set[0 \\le x \\le 1]{x \\in \\R}$ is also countable. \n\n  Note that each number $x \\in S$ can be represented as an infinite decimal \n  \\[\n    x = 0.a_1 a_2 a_3 \\dots\n  \\]\n  where $0 \\le a_i \\le 9$ for all $i \\in \\N$ (the number $1$ can be represented\n  as $0.\\dot{9}$).\n\n  Let $f : \\N \\to S$ be a bijection, and let $f(n) = .a_{n, 1} a_{n, 2} \\dots$.\n  Consider the sequence $b_1$, $b_2$, \\dots such that \n  \\[\n    b_i = \n    \\begin{cases}\n      0 & \\text{if } a_{i, i} \\neq 0 \\\\\n      1 & \\text{otherwise}\n    \\end{cases}.\n  \\]\n  Let $y = 0.b_1 b_2 \\dots$ and let $m \\in \\N$ be an integer such that $f(m) =\n  y$. Note that \n  \\[\n    .a_{m, 1} a_{m, 2} \\dots = f(m) =  0.b_1 b_2 \\dots\n  \\]\n  However, $a_{m, m} \\neq b_m$ which is a contradiction.\n\\end{proof}\n\n\\begin{proof}[Proof of \\Cref{lemma:segment-equipotent-to-reals}]\n  To prove this lemma we start from proving that $\\R$ is equipotent to \n  $\\set[-\\pi / 2 < x < \\pi / 2]{x \\in \\R}$; indeed, we may consider the tangent\n  function which is a bijection between these two sets.\n\n  The next step is to note that the sets $\\set[-\\pi / 2 < x < \\pi / 2]{x \\in \\R}$ and \n  $\\set[0 < x < 1]{x \\in \\R}$ are also equipotent. Consider the function \n  $f : \\set[0 < x < 1]{x \\in \\R} \\to \\set[-\\pi / 2 < x < \\pi / 2]{x \\in \\R}$\n  such that $f(x) = \\pi (x - 1 / 2)$. It is clear that $f$ is a bijection, which\n  finishes the proof.\n\\end{proof}\n\n\\begin{exercise}\n  Show that $(\\set[0 < x < 1]{x \\in \\R})^2$ and $\\set[0 < x < 1]{x \\in \\R}$ are equipotent.\n\\end{exercise}\n\n\\section{Inequalities Between Cardinalities}\nSince $\\N \\subseteq \\R$ the statement that $\\R$ is uncountable can be\ninterpreted as `the set of reals is larger than the set of integers (or the set\nof rationals)'. The following definition allows to make this reformulation\nprecise.\n\\begin{definition}\n  Let $X$ and $Y$ be two sets. \n  \\begin{itemize}\n    \\item We say that $X$ and $Y$ have the same cardinality if they are\n      equipotent; i.e., if $\\cardinality{X} = \\cardinality{Y}$.\n    \\item We write that $\\cardinality{X} \\ge \\cardinality{Y}$ and say that the\n      cardinality of $X$ is at most the cardinality of $Y$ if there is an\n      injection from $X$ to $Y$.\n    \\item We also write $\\cardinality{X} < \\cardinality{Y}$ and say that the\n      cardinality of $X$ is less than the cardinality of $Y$ if \n      $\\cardinality{X} \\neq \\cardinality{Y}$ and $\\cardinality{X} \\le\n      \\cardinality{Y}$.\n  \\end{itemize}\n\\end{definition}\nCantor's theorem says that $\\cardinality{\\R} > \\cardinality{\\N}$ or\n$\\cardinality{\\R} > \\aleph_0$.\\footnote{%\n  A quesiotn that immidiately come in mind after lookin at this reformulation is\n  whether exists something in between; i.e., whether exists a set $S$ such that\n  $\\aleph_0 < \\cardinality{S} < \\cardinality{\\R}$. The hypothesis that such a\n  set exists is called \\emph{the continuum hypothesis}. In 1963, Paul Cohen\n  proved that it is not possible to prove or disprove thus hypothesis starting\n  from axioms of the set theory.\n}\n\nMoreover, Cantor proved that there are even bigger sets\n\\begin{theorem}\n  For any set $X$, $\\cardinality{\\subsets{X}} > \\cardinality{X}$.\n\\end{theorem}\n\\begin{proof}\n  The idea of this proof is simialr to the proof of Cantor's theorem\n  (\\Cref{theorem:reals-are-uncountable}). \n  \n  Firs of all we may notice that $\\cardinality{\\subsets{X}} \\ge \\cardinality{X}$\n  since $f : X \\to \\subsets{X}$ such that $f(x) = \\set{x}$ is an injection.\n  \n  It is also clear that the set $\\subsets{X}$ is equipotent to the set\n  $\\functions{X}{\\set{0, 1}}$ (this can be proven similarly to\n  \\Cref{corollary:power-set-and-set-of-binary-strings}).\n\n  Let us now prove that $\\cardinality{\\functions{X}{\\set{0, 1}}} \\neq\n  \\cardinality{X}$. Assume this is not true and\n  there is a bijection $F : X \\to \\functions{X}{\\set{0, 1}}$. Let $f_x = F(x)$.\n  Consider $g : X \\to \\set{0, 1}$ such that \n  \\[\n    g(x) = \n    \\begin{cases}\n      0 & \\text{if } f_x(x) = 1 \\\\\n      1 & \\text{if } f_x(x) = 0 \\\\\n    \\end{cases}\n  \\]\n  (note that for any $x$, $g(x) \\neq f_x(x)$). It is clear that\n  $g \\in \\functions{X}{\\set{0, 1}}$; however, if $g = F(y) = f_y$, then $g(y) =\n  f_y(y) \\neq f_y(y)$, which is a contradiction. Therefore $F$ is not a bijection.\n\\end{proof}\n\nWe devoted the whole chapter to the pigeonhole principle, unsurprisengly one may\nprove a similar theorem for infinite sets.\\footnote{%\n  This theorem is often called Schr\\\"{o}der--Bernstein theorem since Schr\\\"{o}der\n  and Bernstein published independently proofs of this theorem in 1898. Cantor\n  is often added because he first stated the result in 1887, while\n  Schr\\\"{o}der's name is often omitted because his proof turned out to be\n  flawed. Howerver, the name of Dedekind, who first proved it is not mentioned\n  at all.\n}\n\\begin{theorem}[Schr\\\"{o}der--Bernstein]\n  Let $X$ and $Y$ be two nonempty sets such that $\\cardinality{X} >\n  \\cardinality{Y}$. Then any function $f : X \\to Y$ is not an injection; i.e.,\n  there are $x_1, x_2 \\in X$ such that $f(x_1) = f(x_2)$.\n\\end{theorem}\n\n\nWe are not going to prove this theorem; however, let us formulate a very\nimportant corollary of this theorem.\n\\begin{corollary}\n\\label{corollary:schroder-bernstein}\n  Let $X$ and $Y$ be two nonempty sets. If $\\cardinality{X} \\le \\cardinality{Y}$\n  and $\\cardinality{Y} \\ge \\cardinality{X}$, then $\\cardinality{X} =\n  \\cardinality{Y}$.\n\\end{corollary}\n\nUsing this theorem we may prove that \n\\[\n  \\cardinality{\\set[x, y \\in \\R, x^2 + y^2 = 1]{(x, y)}} = \n  \\cardinality{\\set[-1 \\le x \\le 1]{x \\in \\R}}.\n\\]\nFirst of all note that \n\\[\n  \\set[x, y \\in \\R, x^2 + y^2 = 1]{(x, y)}\n  \\subseteq \\set[-1 \\le x \\le 1]{x \\in \\R};\n\\]\nhence\n\\[\n  \\cardinality{\\set[x, y \\in \\R, x^2 + y^2 = 1]{(x, y)}} \\le \n  \\cardinality{\\set[-1 \\le x \\le 1]{x \\in \\R}}.\n\\]\nIn addition, one may prove using scaling and shift that\n\\[\n  \\cardinality{\\set[-1 \\le x \\le 1]{x \\in \\R}} = \n  \\cardinality{\\set[-\\frac{1}{\\sqrt{2}} \\le x \\le \\frac{1}{\\sqrt{2}}]{x \\in \\R}}.\n\\]\nFinally, \n\\[\n  \\set[-\\frac{1}{\\sqrt{2}} \\le x \\le \\frac{1}{\\sqrt{2}}]{x \\in \\R}\n  \\subseteq \n  \\set[x, y \\in \\R, x^2 + y^2 = 1]{(x, y)}\n\\]\nhence\n\\[\n  \\cardinality{\n    \\set[-\\frac{1}{\\sqrt{2}} \\le x \\le \\frac{1}{\\sqrt{2}}]{x \\in \\R}\n  }\n  \\le\n  \\cardinality{\n    \\set[x, y \\in \\R, x^2 + y^2 = 1]{(x, y)}\n  }.\n\\]\nCombining all this together we can obtain that\n\\begin{gather*}\n  \\cardinality{\n    \\set[x, y \\in \\R, x^2 + y^2 = 1]{(x, y)}\n  } \\le \n  \\cardinality{\\set[-1 \\le x \\le 1]{x \\in \\R}} \\\\\n  \\text{and}\\\\\n  \\cardinality{\\set[-1 \\le x \\le 1]{x \\in \\R}} \\le\n  \\cardinality{\n    \\set[x, y \\in \\R, x^2 + y^2 = 1]{(x, y)}\n  }.\n\\end{gather*}\nHence, using the Schr\\\"{o}der–Bernstein theorem we can prove the equality.\n\n\\begin{chapterendexercises}\n    \\exercise[recommended] Prove that $\\cardinality{\\functions{X}{\\set{0, 1}}} =\n      \\cardinality{2^X}$ for any set $X$.\n    \\exercise[recommended] Prove \\Cref{corollary:schroder-bernstein}\n    \\exercise Show that $\\functions{\\N}{\\set{0, 1}}$ is equipotent to\n      $\\functions{\\N}{\\set{0, 1, 2}}$.\n      \\begin{solution}\n        We are going to prove it using Cantor-Bernstein theorem.\n        Hence, the proof consists of two parts.\n        \\begin{enumerate}\n          \\item In the first part we prove that\n            $\\cardinality{\\functions{\\N}{\\set{0, 1}}} \\le\n            \\cardinality{\\functions{\\N}{\\set{0, 1, 2}}}$. To prove this we need to show that\n            there is an injection from $\\functions{\\N}{\\set{0, 1}}$ to\n            $\\functions{\\N}{\\set{0, 1, 2}}$ and it is clear that\n            $F :  \\functions{\\N}{\\set{0, 1}} \\to \\functions{\\N}{\\set{0, 1, 2}}$\n            such that $F(f) = f$ is an injection.\n          \\item In the second part we prove that \n            $\\cardinality{\\functions{\\N}{\\set{0, 1, 2}}} \\le\n            \\cardinality{\\functions{\\N}{\\set{0, 1}}}$.\n            To prove this we need to show that there is an\n            injection from $\\functions{\\N}{\\set{0, 1, 2}}$ to $\\functions{\\N}{\\set{0, 1}}$.\n            Let us consider\n            $G : \\functions{\\N}{\\set{0, 1, 2}} \\to \\functions{\\N}{\\set{0, 1}}$\n            such that $G(f) = f'$, where\n            \\begin{gather*}\n              h'(2n - 1) =\n              \\begin{cases}\n                0 & \\text{ if } h(n) \\neq 2 \\\\\n                1 & \\text{otherwise}\n              \\end{cases} \\\\\n              \\text{and} \\\\\n              h'(2n) =\n              \\begin{cases}\n                0 & \\text{ if } h(n) \\neq 1 \\\\\n                1 & \\text{otherwise}.\n              \\end{cases}\n            \\end{gather*}\n            We need to prove that this is an injection. Assume the opposite\n            i.e. that $G(h_1) = G(h_2)$ but $h_1 \\neq h_2$.\n            There is $n$ such that $h_1(n) \\neq h_2(n)$ since $h_1 \\neq h_2$.\n            Without loss of generality, it is enough to consider the following\n            cases.\n            \\begin{itemize}\n              \\item If $h_1(n) = 0$ and $h_2(n) = 1$, then $G(h_1)(2n) = 0$\n                and $G(h_2)(2n) = 1$ which is a contradiction.\n              \\item If $h_1(n) = 0$ and $h_2(n) = 2$, then\n                $G(h_1)(2n - 1) = 0$ and $\\mathcal{G}(h_2)(2n - 1) = 1$ which\n                is a contradiction.\n              \\item If $h_1(n) = 1$ and $h_2(n) = 2$, then $G(h_1)(2n - 1) =\n              0$ and $G(h_2)(2n - 1) = 1$ which is a contradiction.\n            \\end{itemize}\n        \\end{enumerate}\n      \\end{solution}\n    \\exercise Show that if a set $A \\subseteq \\R^2$ contains a line, then $A$\n      and $\\R$ are equipotent.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "5dac5ba3b9391385f5ff7c256674ae2b3768ff7d", "size": 10905, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_5/chapter_26_uncountable.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_5/chapter_26_uncountable.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_5/chapter_26_uncountable.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 40.0919117647, "max_line_length": 92, "alphanum_fraction": 0.6081613939, "num_tokens": 3861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.8947894632969137, "lm_q1q2_score": 0.7050325316642012}}
{"text": "\\section{Group Actions}\r\n\\begin{definition}\r\n    Let $(G,\\cdot,e)$ be a group and $S$ be a set.\r\n    The action of $G$ on $S$ is a function $\\star:G\\times S\\to S$ satisfying\\\\\r\n    A1. $\\forall x\\in S,e\\star x=x$.\\\\\r\n    A2. $\\forall g_1,g_2\\in G, \\forall x\\in S, (g_1\\cdot g_2)\\star x=g_1\\star(g_2\\star x)$.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. $\\forall g\\in G, x\\in S, g\\star x=x$ always defines a group action.\\\\\r\n    2. A group $G$ acts on the set $S=G$ by left multiplication.\r\n    That is, via $g\\star g'=g\\cdot g'$.\r\n    This is called the \\textit{left regular action}.\\\\\r\n    3. Consider $\\operatorname{Sym}S$, it acts on $S$ by applying the permutation.\\\\\r\n    4. The symmetries of a solid $X$ acts on the set of points of $X$ (or a special subset like the set of vertices).\r\n    Note that the dihedral group $D_{2n}$ acts on an $n$-gon in this way.\r\n\\end{example}\r\n\\begin{definition}\r\n    The orbit of $x\\in S$ is the set\r\n    $$G\\star x=\\{y\\in X:\\exists g\\in G,y=g\\star x\\}$$\r\n    If this set is equal to $X$, then this action is called transitive.\r\n    The stabiliser of $x\\in S$ is the set\r\n    $$G_x=\\{g\\in G:g\\star x=x\\}$$\r\n    The kernel is defined as\r\n    $$\\{g\\in G:\\forall x\\in S,g\\star x=x\\}=\\bigcap_{x\\in S}G_x$$\r\n    An action is faithful if its kernel is $\\{e\\}$.\r\n\\end{definition}\r\n\\begin{theorem}\r\n    An action is the same as a homomorphism $\\rho:G\\to\\operatorname{Sym}S$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    The function $t_g:x\\mapsto g\\star x$ is a permutation of $X$ for any $g\\in G$.\r\n    Indeed, we can find an inverse of it which is exactly $t_{g^{-1}}$.\r\n    Now we shall show that the map $\\rho:g\\mapsto t_g$ is an homomorphism.\r\n    We can evaluate $\\rho(gh)=t_{gh}$, but $t_{gh}(x)=(gh)\\star x=g\\star(h\\star x)=t_g\\circ t_h(x)$, therefore\r\n    $$\\rho(gh)=t_g\\circ t_h=\\rho(g)\\rho(h)$$\r\n    Conversely, let $\\rho$ be an homomorphism, then consider the function $\\star$ defined by $g\\star x=(\\rho(g))(x)$ is an action.\r\n\\end{proof}\r\nNote that the same actions are corrsponded to the same homomorphism.\r\n\\begin{theorem}[Cayley's Theorem]\r\n    Any group is isomorphic to a subgroup of some symmetric group.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Consider the left regular action of the group $G$ on the set $G$.\r\n    There is then a homomorphism $\\rho:G\\to \\operatorname{Sym}G$.\r\n    Now this action is faithful.\r\n    Indeed, $\\rho(g)=e\\iff\\forall x\\in G, gx=x\\iff g=e$ (Or simply we can write $g=ge=e$).\\\\\r\n    Therefore this homomorphism is injective, hence $G\\cong\\operatorname{Im}\\rho\\le\\operatorname{Sym}G$.\r\n\\end{proof}\r\nWe now want to dive deeper into orbits and stabiliser.\r\nLet $G$ act on $X$.\r\n\\begin{theorem}\r\n    For each $x\\in X$, $G_x\\le G$, and the collection of all orbits $G\\star x$ for every $x\\in X$ partitions $X$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Note that $e\\in G_x$ for each $x$ so $G_x$ is nonempty.\r\n    If $a,b\\in G_x$, then $x=e\\star x=(b^{-1}b)\\star x=b^{-1}\\star (b\\star x)=b^{-1}\\star x\\implies b^{-1}\\in G_x$.\r\n    Therefore $(ab^{-1})\\star x=a\\star(b^{-1}\\star x)=a\\star x=x\\implies ab^{-1}\\in G_x$, so $G_x\\le G$.\\\\\r\n    Now the union of orbits contains each $x\\in X$ since $x\\in G\\star x$.\r\n    Now if $G\\star x\\cap G\\star y\\neq\\varnothing$, there is some $g,h\\in G$ such that $g\\star x=h\\star y$.\r\n    Therefore for any $z\\in G\\star x$, then $z=k\\star x$ for some $k\\in G$, then $z=k\\star((g^{-1})\\star(h\\star y))=(kg^{-1}h)\\star y\\implies z\\in G\\star y$.\r\n    So $G\\star x\\subseteq G\\star y$ and $G\\star y\\subseteq G\\star x$, so $G\\star x=G\\star y$.\r\n    Hence the orbits form a parition of $X$.\r\n\\end{proof}\r\nWhat we have discussed so far is called the left action.\r\nThe right action $\\diamond:X\\times G\\to X$ is defined analogously.\r\nSo $x\\diamond e=x$ and $(x\\diamond g)\\diamond h=x\\diamond (gh)$.\r\n\\begin{proposition}\r\n    If $\\diamond$ is a right action, then we can define a left action $\\star$ by $g\\star x=x\\diamond g^{-1}$.\r\n    We can also have the other way around.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nSo we can only use left actions during the scope of our study.\r\n\\begin{definition}\r\n    If $G$ has a left action on $X$, the set of orbits is called $G\\backslash X=\\{G\\star x:x\\in X\\}$.\r\n    If $G$ has a right action on $X$, the set of orbits is called $X/G=\\{x\\diamond G:x\\in X\\}$\r\n\\end{definition}\r\n\\begin{example}\r\n    The dihedral group $D_{2n}$ acts on the regular $n$-gon $X$ in the obvious way.\\\\\r\n    The orbit of a vertex is then all vertices.\r\n    The stabiliser of a vertex is the identity and the reflection across the axis which is the diagonal through the vertex.\r\n    Note here that the size of the orbit times the size of stabiliser is the size of the dihedral group.\\\\\r\n    Now consider a point in the interior of a side of the square.\r\n    Then the orbit of this point would consist of $8$ points, and nothing stabilises it, so we also get that the product of the sizes of the orbit and the stabiliser is $8$, the size of the dihedral group.\\\\\r\n    Let us now look at the symmetries of the tetrahedron with vertices $1,2,3,4$.\r\n    Suppose the rotation across midpoints of opposite sides be $S$ and the rotation across the central axis through a vertex $R$.\\\\\r\n    Let $V$ be the set of vertices and let this group act on it.\r\n    Then it is obvious that this action is transitive, and the stabiliser of a vertex are the rotations with respect to the axis through that vertex.\\\\\r\n    So again the sizes of the orbit and stabiliser give a product of $12$, the size of the group.\\\\\r\n    Now we act on the set of edges $E$.\r\n    Pick one of the edge $X$, then the action of the group on it is yet again transitive, and the stabilisers are the identity and the rotation $R$ on the midpoint of $E$ and its opposite edge.\r\n    Again they give a product of $6\\times 2=12$, the size of the group.\r\n\\end{example}\r\nThe preceding observation triggers the following theorem.\r\n\\begin{theorem}[Orbit-Stabiliser Theorem on finite groups]\\label{ost_finite}\r\n    $|G_x||G\\star x|=|G|$\r\n\\end{theorem}\r\nTo prove it, we need some preparation.\r\n\\begin{proposition}\r\n    If $H\\le G$, the left regular action of $H$ on $G$ is the left multiplication of element in $H$ on $G$, i.e. $h\\star g=hg$.\r\n    The right regular action then is $g\\diamond h=gh$\r\n\\end{proposition}\r\n\\begin{definition}\r\n    A left coset of $H$ in $G$ is an orbit of the right regular action.\r\n    Write $G/H$ to denote the collection of these cosets.\\\\\r\n    We can define the right coset the other way around which are collected as $H\\backslash G$.\r\n\\end{definition}\r\nSo each left coset is in the form $gH=\\{gh:h\\in H\\}$, and the right coset in the form $Hg=\\{hg:h\\in H\\}$.\r\nNote that it is not always true that a left coset is equal to the right coset.\\\\\r\nAlso $G/H=\\{S\\subseteq G:\\exists g\\in G,S=gH\\}$ and we can find $H\\backslash G$ similarly.\r\n\\footnote{Some authors use $G:H$ for the collection of left cosets.}\\\\\r\nNote that $gH=g'H\\iff g'^{-1}g\\in H$, and for right cosets $Hg=Hg'\\iff g'g^{-1}\\in H$ but again these two conditions may or may not be equivalent.\r\n\\begin{example}\r\n    The (left and right) cosets of $2\\mathbb Z$ are $2\\mathbb Z$ and $2\\mathbb Z+1=1+2\\mathbb Z$.\\\\\r\n    The (left and right) cosets of $n\\mathbb Z$ are $k+n\\mathbb Z, k\\in\\{0,1,\\ldots n-1\\}$.\\\\\r\n    Consider $D_6$, $R=\\{e,r,r^2\\}, S=\\{e,s\\}$ are subgroups.\r\n    The (left and right) coset of $R$ are $R$ and $sR=Rs$\r\n    And the left cosets of $S$ are $S$, $rS$ and $r^2S$ and the right ones are $S$, $Sr$, $Sr^2$, but in this case the left and right cosets are not equal.\r\n\\end{example}\r\n\\begin{theorem}\r\n    If $H\\subset G$ and $g\\in G$, then there is a bijection $H\\to gH$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    $h\\mapsto gh$ is the bijection.\r\n\\end{proof}\r\n\\begin{corollary}[Lagrange's Theorem]\\label{lagrange}\r\n    If $G$ is finite and $H\\le G$, then we have $|H||G/H|=G$.\r\n    In particular $|H|$ divides $|G|$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    The cosets are orbits thus parition $G$ and they are of the same cardinality due to the preceding theorem.\r\n\\end{proof}\r\nWe can repeat the same argument to see that the same also applies to right cosets.\r\n\\begin{definition}\r\n    Let $G$ be a group, and $H\\le G$, then the index of $H$ is the order of $G/H$ given that it is finite, otherwise we say the index is infinite.\r\n\\end{definition}\r\nEquivalently, the index is $|G|/|H|$ (given that $H$ is finite).\r\n\\begin{corollary}\r\n    If $G$ is finite and $g\\in G$, then $g^{|G|}=e$, that is, $\\operatorname{ord}g||G|$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Consider the subgroup $\\langle g\\rangle\\le G$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $G$ is finite $|G|$ is prime, then $G\\cong C_p$ and it is generated by any identity element.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    $G$ contains some non-identity element since $|G|=p>1$.\r\n    Choose any $g\\in G$ such that $g\\neq e$.\r\n    Then $1<\\operatorname{ord}g||G|=p$, so since $p$ is prime, then $\\operatorname{ord}g=p$.\r\n    Thus since $\\langle g\\rangle\\le G$ and they are both finite and of the same order, $C_p\\cong \\langle g\\rangle=G$.\r\n\\end{proof}\r\nThere is a corollary of this in number theory.\r\nWe consider the collection of all (equivalent classes) of integers $k\\in\\mathbb Z_n$ such that $(k,n)=1$.\r\nSince $(k,n)=1$, $k$ is invertible in $\\mathbb Z_n$ for any such $k$ in the collection.\r\nConversely, if $k$ cannot be invertible in $\\mathbb Z_n$ if $(k,n)\\neq 1$.\\\\\r\nSo this collection is a group $\\mathbb Z_n^{\\times}$ under multiplication modulo $n$.\r\nAlso, this group has order $\\phi(n)$ which is the number of positive integers less than $n$ that are coprime to it.\r\n\\begin{corollary}[Fermat-Euler Theorem]\r\n    If $(k,n)=1$, then\r\n    $$k^{\\phi(n)}\\equiv 1\\pmod{n}$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Apply the preceding corollary to $\\mathbb Z_n^\\times$.\r\n\\end{proof}\r\nAfter these warm-ups, we shall prove the Orbit-Stabiliser Theorem (in a stronger form).\r\n\\begin{theorem}[Orbit-Stabiliser Theorem]\r\n    Suppose a group $G$ acts on a set $X$ and $x\\in X$, then there is a bijection $G/G_x\\to G\\star x$ by $\\phi:gG_x\\mapsto g\\star x$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    To see $\\phi$ is well defined, observe that $\\forall h\\in G_x, g\\star x=g\\star (h\\star x)=(gh)\\star x$.\r\n    It is obviously surjective by the definition of orbit.\r\n    It is injective since if $\\phi(gH)=\\phi(g'H)$, then $(g^{-1}g')\\star x=x\\implies g^{-1}g'\\in H\\implies gH=g'H$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Theorem \\ref{ost_finite}.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Due to the existence of this bijection, if $G$ is finite, then $|G|/|G_x|=|G/G_x|=|G\\star x|\\implies |G\\star x||G_x|=|G|$.\r\n\\end{proof}\r\nOne of the most important application of this theorem is to work out the order of some finite group.\r\n\\begin{example}\r\n    We look at the rotational symmetries of a cube.\r\n    Collect the symmetries as the group $G$ and consider its action on the eight vertices $X$.\r\n    Now this action is transitive, obviously, so fixing any $x\\in X$, $|G\\star x|=8$.\r\n    Also, any member of the stabiliser of $x$ must be rotations though the axis through $x$ and the centre of the centre of the group since it fixes that.\r\n    There are three rotations of this form, so $|G|=|G_x||G\\star x|=24$.\r\n\\end{example}\r\n\\begin{theorem}[Cauchy's Theorem]\\label{cauchy}\r\n    Let $G$ be a finite group and suppose $p$ is a prime dividing its order, then $G$ contains an element of order $p$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Consider a subset $X\\subseteq G^p$ defined by $X=\\{(g_1,g_2,\\ldots, g_p)\\in G^p:g_1g_2\\cdots g_p=e\\}$.\r\n    Since $|G^p|=|G|^p$, and $|X|=|G|^{p-1}$.\r\n    Let $H=C_p=\\langle\\xi\\rangle$, consider the action of $H$ on $X$ by\r\n    $$\\xi\\star (g_1,g_2,\\ldots,g_p)=(g_2,g_3,\\ldots,g_p,g_1)$$\r\n    This is an action, indeed, if $g_1g_2\\cdots g_p=e$, then $g_2g_3\\cdots g_pg_1=g_1^{-1}eg_1=e$.\r\n    For any element $x\\in X$, by Theorem \\ref{ost_finite}, $p=|H|=|H_x||H\\star x|$.\r\n    But $p$ is prime, so every orbit has to have either size $1$ or size $p$, also the ordrs of the orbits sum to $|X|=|G|^{p-1}$ which is divisible by $p$.\r\n    So the number of size $1$ orbits must be divisible by $p$, thus at least $2$.\r\n    But all such orbits must be in the form $(g,g,\\ldots, p)$, but since there are $2$ of them, there is some $g\\neq e$ such that this tuple is in $X$, thus $g^p=e$ and $g\\neq e$, therefore $g$ has order $p$.\r\n\\end{proof}\r\nIn fact, we have shown that the number of elements of order $p$ is congruent to $p-1\\pmod{p}$.\r\n\\begin{definition}\r\n    Fix a group $G$.\r\n    $a,b\\in G$ are conjugates of each other if $\\exists g\\in G, a=gbg^{-1}$.\\\\\r\n    The conjugation action is an action of a group $g$ on itself by $g\\star h=ghg^{-1}$.\r\n\\end{definition}\r\nOne can check that the conjugation is indeed an action.\r\n\\begin{definition}\r\n    The orbits of the conjugation are called the conjugacy classes of $G$.\r\n    The stabiliser of the conjugation of an element $h$ is called the centraliser $C_G(h)$ of $h$.\r\n    The kernel of the conjugation action is called the centre $Z(G)$ of $G$.\r\n\\end{definition}\r\nWe can extend the conjugation action to the subgroups of $G$.\r\n\\begin{definition}\r\n    If $H\\le G$, then the conjugate of $H$ by $g$ is the subgroup $\\{ghg^{-1}:h\\in H\\}$.\r\n\\end{definition}\r\nIt is trivial that the conjugate of a subgroup is indeed a subgroup.\r\n", "meta": {"hexsha": "de937a42abbd9b6e87d6b1d0cdd7ca80b3e0272e", "size": 13292, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/action.tex", "max_stars_repo_name": "david-bai-notes/IA-Groups", "max_stars_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/action.tex", "max_issues_repo_name": "david-bai-notes/IA-Groups", "max_issues_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/action.tex", "max_forks_repo_name": "david-bai-notes/IA-Groups", "max_forks_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.1447963801, "max_line_length": 209, "alphanum_fraction": 0.6658892567, "num_tokens": 4378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.89181104831338, "lm_q1q2_score": 0.705003672216313}}
{"text": "\\section*{Discrete Choice (Threshold) Problems}\\label{SecDiscrChoice}\n\nOne powerful application of dynamic programming that illustrates its versatility as a dynamic solution method is to models that have both continuous and discrete state variables. These models are sometimes referred to as discrete choice problems or optimal stopping problems.  Examples include models of employment that involve both the choice of whether to work and how much to work, models of firm entry and exit that involve the choice of both whether to produce and how much to produce, and models of marriage that involve the choice of whether to date (get married or keep dating) and how much to date.\n\nIn this problem set, we follow a simple version of a standard job search model.  Assume that workers are infinitely lived. Let the value of entering a period with most recent wage $w$, current job offer wage $w'$, and employment status $s$ be given by the following value function,\n\\begin{equation}\\label{EqV}\n   V(w,w',s) = \\begin{cases}\n                  V^E(w)    \\quad&\\text{if}\\quad s = E \\\\\n                  V^U(w,w') \\quad&\\text{if}\\quad s = U \\\\\n               \\end{cases}\n\\end{equation}\nwhere employment status is a binary variable $s=\\{E,U\\}$; a person can be either employed or unemployed.\n\nIf an individual's job status is employed ($s = E$) in a given period, then expected utility is the utility of consumption in the current period plus the discounted expected value of the entering the next period with wage $w$, job offer wage $w''$, and employment status $s'$.\n\\begin{equation}\\label{EqVe1}\n   V^E(w) = u(w) + \\beta E_{w'',s'}V(w,w'',s')\n\\end{equation}\nHere we assume that individuals spend all of their earnings each period so that utility from the consumption in the current period is $u(w)$.  The discount factor is $\\beta$.  The next periods wage, $w''$, and job offer, $s'$, are unknown and we consider them as random variables.  Consequently, the expectations operator $E_{w'',s'}$ is over the job offer wage, and employment status in the next period, and next period's value function is simply \\eqref{EqV} with the future value of employment status $s'$.\n\nThe joint probability distribution over $w''$ and $s'$ is characterized in the following simple way. If the worker stays employed in the next period $s' = E$, then next period's wage equals the current period's wage. If the worker becomes unemployed in the next period $s' = U$, then the worker's unemployment benefits will be a percentage of his current wage $\\alpha w$. Any worker who is unemployed will receive one wage offer per period $w'$, which that worker will receive in the following period, drawn from the cumulative density function $F(w')$ or probability density function $f(w')$, which is independent of the worker's previous wage (for simplicity). Lastly, let $\\gamma$ represent the probability that an employed worker becomes unemployed in the next period. So \\eqref{EqVe1} can be rewritten in the following way.\n\\begin{equation}\\label{EqVe2}\n   V^E(w) = u(w) + \\beta \\Bigl[(1-\\gamma)V^E(w) + \\gamma E_{w''}V^U(w,w'')\\Bigr]\n\\end{equation}\n\nThe value of being unemployed in a given period is a function of both the wage at the most recent job $w$ as well as the wage of the current job offer $w'$,\n\\begin{equation}\\label{EqVu}\n   V^U(w,w') = u(\\alpha w) + \\beta\\max_{s'\\in\\{E,U\\}}\\Bigl\\{V^E(w'),E_{w''}\\left[V^U(w,w'')\\right]\\Bigr\\}\n\\end{equation}\nwhere $\\alpha\\in(0,1)$ is the fraction of the worker's previous wage paid in unemployment insurance benefits. The maximization in \\eqref{EqVu} reflects the decision of whether to accept the current job offer or remain unemployed for another period.  It is only in the unemployed state $s=U$ in which the worker makes a decision. Once the job offer ($w'$) is received, the worker can choose whether to accept or reject the offer. The expectation in \\eqref{EqVu} is, therefore, not over $w'$ but over the possible job offers in the following period, $w''$; if the worker chooses to reject the current job offer, then $s' = U$.\n\nThe policy function for the decision of the unemployed worker whether to accept a job $s'=E$ or whether to reject a job $s'=U$ will be a function of both the amount of the most recent wage $w$ and the amount of the current job offer: $s' = \\psi(w,w')$. These discrete choice problems are often called threshold problems because the policy choice depends on whether the state variable is greater than or less than some threshold level. That is, an unemployed worker will accept a job if and only if the offer wage is above some set amount. In the labor search model, the threshold level is called the ``reservation wage'' $w_R'$. The reservation wage $w_R'$ is defined as the wage offer such that the worker is indifferent between accepting the job $s' = E$ and staying unemployed $s' = U$.\n\\begin{equation}\\label{EqWR}\n   w_R' \\equiv w': V^E(w') = E_{w''}\\left[V^U(w,w'')\\right]\n\\end{equation}\nNote that the reservation wage $w_R'$ is a function of the wage at the most recent job $w$ (if you have higher unemployment benefits you will wait for a higher job offer). The policy function will then take the form of accepting the job if $w' \\geq w_R'$ or rejecting the job offer and stay unemployed if $w' < w_R'$.\n\\begin{equation}\\label{EqSprime}\n   s' = \\psi(w,w') = \\begin{cases}\n                      E \\quad\\text{if}\\quad w' \\geq w_R' \\\\\n                      U \\quad\\text{if}\\quad w' < w_R'\n                   \\end{cases}\n\\end{equation}\n\nIn summary, the labor search discrete choice problem is characterized by the value functions \\eqref{EqV}, \\eqref{EqVe2}, and \\eqref{EqVu}, the reservation wage \\eqref{EqWR}, and the policy function \\eqref{EqSprime}. Because wage offers are distributed according to the cdf $F(w')$ and because the policy function takes the form of \\eqref{EqSprime}, the probability that the unemployed worker receives a wage offer that he will reject is $F(w_R')$ and the probability that he receives a wage offer that he will accept is $1 - F(w_R')$. Just like the continuous choice cake eating problems, this problem can be solved by value function, policy function, or modified policy function iteration.\n\nThe value function iteration solution method for the equilibrium in the labor search problem is analogous to the value function iteration from the previous labs. The only difference is that two value functions ($V^E$ and $V^U$) must converge to a fixed point in this problem instead of just one value function converging in the previous problems.  Although there are two value functions to consider, there is only one policy function since decisions are only made in the unemployed state.  Thus there is only one policy function to iterate on in the case of policy or modified policy iteration.\n\nAssume that the probability of becoming unemployed in a given period is $\\gamma = 0.10$, the fraction of wages paid in unemployment benefits is $\\alpha = 0.5$, and the discount factor is $\\beta = 0.9$. Assume that the log of wage offers are distributed normally.  We then say that offers are distributed lognormally and write $w'\\sim \\text{LogN}(\\mu,\\sigma)$.  We let $m=20$ be the mean wage, $v=400$ be the variance of the wage.  Often lognormal distributions are reported with the mean and variance of $\\log(w')$ which is distributed normally, but for simplicity you will not have to deal with that here. This is a convenient choice for the distribution of wage offers.  Among other things, it guarantees that wage offers will be positive.  Denote the cdf of the lognormal distribution as $F(w')$ and the pdf of the distribution as $f(w')$.\n\n\\vspace{5mm}\n\n\\begin{problem}\n\\begin{enumerate}\n\n   \\item Approximate the support of $w\\in(0,\\infty)$ by generating a column vector of possible values for $w$. Let the maximum value be $w_{max} = 100$, let the minimum value be $w_{min} = 0$, and let the number of equally spaced points in the vector be $N = 500$. Let the wage of a job offer in any period be lognormally distributed with mean job offer of $m=20$ and variance $v =200$.  Generate the discrete approximation of the lognormal probability density function $f(w')$ using the function defined in discretelognorm.py which is provided.  As arguments, it takes the points where the approximation is needed (w), along with the mean and variance so that it can be called as\n\n\\begin{lstlisting}[style=python]\nf = discretelognorm(w,m,v)\n\\end{lstlisting}\n\n    Then the $n$th entry of $f$ represents the probability that the job offer in the next period equals the $n$th entry of $w$, $\\text{Pr}(w' = w_n)$.\n\n   \\item Solve for the equilibrium optimal policy function $s' = \\psi(w,w')$ by value function iteration.  In this case we iterate on both value functions $V^E$ and $V^U$ each time through the loop.  In order to compute the expected value of $V^U$, just matrix multiply $V^U$ and $f$. Remember, the policy function $\\psi(w,w')$ gives the choice of whether to accept the job offer if unemployed with a given previous wage and current job offer.  Thus it will be a vector of length $N$ of zeros and ones.  Again, use a tolerance level of $10^{-9}$ and require that both value functions must converge (compute a delta for each and iterate until both are less than $10^{-9}$).\n\n   \\item Compute the reservation wage $w_R'$ as a function of the current wage $w$.  The reservation wage is the value of $w$ where the policy function changes from zeros to ones (the optimal choice changes from remaining unemployed to accepting the job offer).  If psi is an $N\\times N$ matrix representing the policy function, the reservation wage wr could be computed as follows\n   \\begin{lstlisting}[style = python]\n    wr_ind = sp.argmin(sp.diff(psi), axis = 1)\n    wr = w[wr_ind]\n   \\end{lstlisting}\n\twhere the rows of psi correspond to values of $w$ and the columns correspond to values of $w'$.\n\n   \\item Plot the equilibrium reservation wage $w_R'$ of the converged problem as a function of the current wage $w$ with the current wage on the $x$-axis and the reservation wage $w_R'$ on the $y$-axis. This is the most common way to plot discrete choice policy functions. The reservation wage represents the wage that makes the unemployed worker indifferent between taking a job offer and rejecting it. So any wage above the reservation wage line represents $s' = E$ and any wage below the reservation wage line represents $s' = U$.\n\n\\end{enumerate}\n\\end{problem}\n\nIn the previous problem, it was necessary to iterate on two value functions.  Consequently the convergence is relatively slow.  Thus the gains by using modified policy function iteration are considerable.\n\n\\begin{problem}\nSolve the same problem, this time using modified policy function iteration with $m=15$ value function iterations within each policy iteration.  Roughly, you can structure your code as follows:\n\n\\begin{enumerate}\n\t\\item Initialize $w$,$u(\\alpha w)$, $f$, $\\gamma$, and $\\beta$.  This should be the same as the previous problem.\n\t\n\t\\item\tInitialize $V^E$, $V^U$, and $E[V^U]$ to zeros.  Then begin the while loop.\n\t\n\t\\item Inside the while loop update the policy function.  It is determined as\n\t\\begin{equation}\n\t\t\\psi (w,w') = \\text{argmax} \\left\\{ V^E(w'), E_{w''}[V^U(w,w'')]\\right\\}\n\t\\end{equation}\n\t\n\t\\item Begin a for loop to iterate on the value functions.  Unlike in the previous algorithms lab, there is no $Q$ matrix in this case.  Given the previous iteration's value functions, updating $V^E$ should be simple because it does not depend directly on the policy function.\n\t\n\tTo iterate on $V^U$, we need to compute $V^U$ given the current policy.  The policy determines the maximization in equation \\eqref{EqVu}.  One way to compute the max is to use $\\psi$ as a mask.  $V^U$ could be computed as follows:\n\t\n\t\\begin{lstlisting}[style = python]\n\targ1 = sp.repeat(sp.transpose(VE),N,0)*(1-psi)\n    arg2 = sp.repeat(EVU,N,1)*psi\n    arg = arg1+arg2\n    VUprime = alpha_util_grid + beta*arg\n\t\\end{lstlisting}\t\n\\newpage\n\twhere the ordering is such that $1$ corresponds to the state $E$ and $0$ corresponds to the state $U$.\n\t\n\t\\item Compute the $\\delta$'s.\n\t\n\t\\item After the while loop you should compute the reservation wage and plot it.\n\\end{enumerate}\n\\end{problem}\n\n\\begin{problem}\nHow many iterations did value function iteration take?\nHow many iterations did modified policy function iteration take?\nWhich was faster?\n\\end{problem} ", "meta": {"hexsha": "ff1d6580c7cc7457978c1859e1f755fc2d0d5edd", "size": 12394, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/Dynamic_Programming/Job_Search.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/Dynamic_Programming/Job_Search.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/Dynamic_Programming/Job_Search.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 108.7192982456, "max_line_length": 842, "alphanum_fraction": 0.7407616589, "num_tokens": 3116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7050036608506589}}
{"text": "\\chapter[Quadrature]{Numerical Quadrature}\n\n\\section{Introduction}\n\nThere are many circumstances in mathematical modelling when we need to\nevaluate an integral, like\n%\n\\begin{equation}\n \\mint{a}{b}{f(x)}{x} .\\label{Qua:eq:1}\n\\end{equation}\n%\nHowever, the integrals that can be evaluated analytically are few and\nmany integrals of great interest in engineering, like, for example,\nthe error function,\n%\n\\begin{equation}\n \\mbox{Erf}(x) = \\mint{-\\infty}{x}{e^{-\\xi^2}}{\\xi} \\label{Qua:eq:2}\n\\end{equation}\n%\ncan only be evaluated numerically.\n\nWe discuss two major techniques to evaluate integrals\n(\\textit{quadrature}): the first is based on \\textit{interpolation},\nthe second on \\textit{Gaussian quadrature}.\n\n\\section{Polynomial interpolation}\n\nIf we want to work with any function $f(x)$ numerically we must expect\nto represent it using a finite amount of information. Typically this\nis done by assuming that we know only the value of the function at a\nfinite set of points, call \\textit{nodes}, $\\{x_j\\}$, with\n$j=0,\\ldots,N$. We denote the function values $f_j \\equiv f(x_j)$.\n\nOne standard approach is to approximate the function $f$ by another\nfunction $g(x)$ which is easy to manipulate and \\textit{interpolates}\n$f$ at the nodes, i.e.\n%\n\\begin{equation}\n  g(x_j) = f_j = f(x_j), \\quad j = 0, \\ldots, N.\n\\end{equation}\n%\nWe then use $g$ in place of $f$ wherever necessary, as we shall see\nbelow.\n\nOne standard, simple choice of \\textit{interpolating function} $g(x)$\nis a polynomial. Given the $N+1$ values $f_j$ at the nodes $x_j$ there\nis a \\emph{unique} polynomial $g$ of order $N$ that interpolates $f$\n(as should be clear, as a polynomial of order $N$ has $N+1$\ncoefficients to be fixed). There are two standard forms of writing\nthis polynomial explicitly. Here we just show the Lagrange form to\nshow the explicit construction is possible. Often the Newton form is\nused in numerical calculations instead.\n\nFirst, given the nodes $x_j$, define the \\textit{fundamental\n  polynomials} $\\ell_j(x)$ by\n%\n\\begin{equation}\n  \\ell_j(x) = \\prod_{\\substack{i = 0\\\\i \\ne j}}^N \\frac{x - x_i}{x_j -\n    x_i}, \\quad j = 0, 1, \\dots, N.\n\\end{equation}\n%\nThese have the property that $\\ell_j(x_j) = 1$ and $\\ell_j(x_k) = 0, j\n\\ne k$. It follows that\n%\n\\begin{equation}\n  g(x) = \\sum_{j=0}^N f(x_j) \\ell_j(x)\n\\end{equation}\n%\nis the polynomial of degree $N$ that interpolates the function $f(x)$\nat the nodes $x_j$.\n\nIn what follows we shall see methods for solving quadrature and\ndifferential equations based on polynomial interpolation. For these\nthe defining features are the locations of the nodes and the order of\nthe interpolating polynomial. In many cases the formulas will simplify\ngreatly from the general Lagrange form above, so each case is treated\nseparately.\n\n\\section[Using polynomial interpolation]{Numerical integration based on polynomial interpolation}\n\n\\subsection{Introduction}\n\nWe assume that we can evaluate the function at a finite set of points,\ncalled \\textit{nodes}, $\\{x_j\\}$, with $j=0,\\ldots, N$ in the interval\n$[a,b]$ and we want to estimate~(\\ref{Qua:eq:1}).  The idea behind all\nthe methods based on polynomial interpolation is that we can replace\nthe function $f(x)$ with a simpler function $g(x)$, i.e.\\ a function\nwhose integral we can evaluate analytically.  We require that the\nfunction $g(x)$ \\textit{interpolates} the function $f(x)$, i.e.\\ that\nit has the same value as $f(x)$ at the nodes:\n%\n\\begin{equation}\n  g(x_j) = f(x_j) , \\qquad j = 0,1,\\ldots,N. \\label{Qua:eq:3}\n\\end{equation}\n%\nThe simplest choice of class of functions $g(x)$ are polynomials and\nthe different quadrature interpolation methods are differentiated by\nthe order of the polynomial interpolation.  Formulae based on\npolynomial interpolation with equally spaced nodes go under the\ngeneric name of \\textit{Newton-Cotes formulae}.\n\n\\subsection{Trapezoidal rule}\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=135mm]{figures/trapez}}\n  \\caption{\\label{fig:trapez} \\it The trapezoidal rule is based on the\n    approximation of the given function $f(x)$ with an order one\n    polynomial (left).  In general one uses a composite trapezoidal\n    rule: the integration range is divided in intervals of length $h$\n    and the function is approximated by a different polynomial on each\n    interval (right).}\n\\end{figure}\n\nThe simplest case results if we choose an interpolating polynomial of\norder one, i.e.\\ we replace the function with a straight line that\ninterpolates the function at the end points of the integration range\n(see left panel of Figure~\\ref{fig:trapez}).   The area under the line\nis given by\n%\n\\begin{equation}\n  A = \\frac{1}{2} (b-a) [f(a) + f(b)]\n  \\label{Qua:eq:32}\n\\end{equation}\n%\nand this is the approximate value of~(\\ref{Qua:eq:1}) according to the\n\\textit{trapezoidal rule}.  It is clear that unless the range $[a,b]$\nis very small the error in the estimate obtained using the trapezoidal\nrule is very large.  The standard procedure is to make use of the\n\\textit{composite trapezoidal rule}: the integration range is divided\ninto $N$ intervals of length $h$ and the function $f(x)$ is\napproximated on each interval by a straight line that interpolates the\nfunction at the nodes (see right panel of Figure~\\ref{fig:trapez}).\nThe area under each segment of the piecewise linear curve is\n%\n\\begin{equation}\n  A_j = \\frac{1}{2} (x_{j}-x_{j-1}) [f(x_{j})+f(x_{j-1})] , \\quad\n  j = 1,2, \\ldots, N.\n  \\label{Qua:eq:4}\n\\end{equation}\n%\nBy summing all the areas we obtain the composite trapezoidal rule:\n%\n\\begin{equation}\n  \\mint{a}{b}{f(x)}{x} = \\sum_{j=1}^{N} A_j =\n  \\frac{1}{2} \\sum_{j=1}^{N} (x_{j}-x_{j-1}) [f(x_{j})+f(x_{j-1})]\n  \\label{Qua:eq:5}\n\\end{equation}\n%\nIf the nodes are equally spaced, i.e.\\ if $(x_{j}-x_{j-1}) = h$ for all\n$j=1, \\ldots, N$, this formula reduces to:\n%\n\\begin{equation}\n \\mint{a}{b}{f(x)}{x} =\n  \\frac{h}{2} \\sum_{j=1}^{N} [f(x_{j})+f(x_{j-1})] =\n  \\frac{h}{2} ( f_0 + 2 f_1 + 2 f_2 + \\ldots + 2 f_{N-1} + f_N ) ,\n\\label{Qua:eq:12}\n\\end{equation}\n%\nwhere $f_j \\equiv f(x_j)$.  The error in the approximation is given by\n%\n\\begin{equation}\n  \\text{Error} \\le \\frac{1}{12} h^3 N M_2 =\n  \\frac{(b-a) h^2}{12} M_2 , \\qquad\n  M_2 = \\max_{x\\in[a,b]} |f''(x)| .\n  \\label{Qua:eq:6}\n\\end{equation}\n\n\\subsection{Simpson's rule}\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=135mm]{figures/simpson}}\n  \\caption{\\label{fig:simpson} \\it Simpson's rule is based on the\n    approximation of the given function $f(x)$ with an order two\n    polynomial (left).  In general one uses a composite Simpson's\n    rule: the integration range is divided in intervals of length $2\n    h$ and the function is approximated by different parabolas on each\n    interval.}\n\\end{figure}\n\nIn this case the function is approximated with a polynomial of order\ntwo (a parabola, see left panel of Figure~\\ref{fig:simpson}).  We can\nobtain the formula for the quadrature by writing the interpolating\npolynomial and integrating it.  It turns out that the area under the\nparabola is given by\n%\n\\begin{equation}\n  A = \\frac{b-a}{6}\n  \\left [ f(a) + 4 f\\left(\\frac{a+b}{2}\\right) + f(b) \\right ],\n  \\label{Qua:eq:33}\n\\end{equation}\n%\nand this is the approximate value of~(\\ref{Qua:eq:1}) according to\n\\textit{Simpson's rule}.  It is clear that unless the range $[a,b]$ is\nvery small the error in the estimate obtained using the trapezoidal\nrule is very large.  The standard procedure is to make use of the\n\\textit{composite Simpson's rule}: the integration range is divided\ninto $N/2$ intervals of length $2 h$, with $N$ an even number. The\nfunction $f(x)$ is approximated on each interval by a parabola that\ninterpolates the function at the nodes (see right panel of\nFigure~\\ref{fig:simpson}).  For simplicity we assume that the\ninterpolation points $\\{x_j\\}$, $j=0,1,2,\\ldots,N$ are all equally\nspaced so that we can write:\n%\n\\begin{equation*}\n  x_j = x_0 + j h .\n\\end{equation*}\n%\nThe area under the parabola joining the nodes $x_{j-1}$, $x_{j}$ and\n$x_{j+1}$ is\n%\n\\begin{equation}\n  A_j = \\frac{h}{3} \\left[f(x_{j-1})+4f(x_{j})+f(x_{j+1})\\right]\n  \\label{Qua:eq:9}\n\\end{equation}\n%\nwhere $j=1,3,5,\\ldots, N-1$.  This result is known as\n\\textit{Simpson's rule}.  If we apply it to all the sub-intervals in\n$[a,b]$ we obtain the composite Simpson rule:\n%\n\\begin{equation}\n  \\mint{a}{b}{f(x)}{x} = \\sum_{k=1}^{N/2} A_{2k-1} =\n  \\frac{h}{3} \\left[ f(a) +\n    2 \\sum_{j=1}^{N/2-1} f(x_{2j}) +\n    4 \\sum_{j=1}^{N/2} f(x_{2j-1}) + f(b) \\right] + R,\n  \\label{Qua:eq:10}\n\\end{equation}\n%\nwhere the estimate for the error is given by\n%\n\\begin{equation}\n  |R|\\le \\frac{M_4}{180}(b-a)h^4,\\label{Qua:eq:11}\n\\end{equation}\n%\nwhere $M_4=\\max|f^{(4)}(x)|$ with $a \\le x \\le b$.  Note that\nSimpson's rule is exact for any cubic polynomial as $f^{(4)}(x) \\equiv\n0$ for all polynomials of order three.\n\nWe can obtain an estimate of the error by proceeding as follows.  We\ncompare the Taylor expansion of Simpson's rule for the integral in the\nrange $[x_{j-1},x_{j+1}]$, given by equation~(\\ref{Qua:eq:9}), to the\nTaylor expansion of the exact integral.  The error is the first term\nin the difference of the two Taylor expansions.  We start with the\nTaylor expansion of the Simpson's rule estimate of\n%\n\\begin{equation}\n  \\mint{x_{j-1}}{x_{j+1}}{f(x)}{x} \\simeq A_j =\n  \\frac{h}{3} [ f(x_{j-1}) + 4 f(x_{j}) + f(x_{j+1}) ] ,\n  \\label{Qua:eq:19}\n\\end{equation}\n%\nwhere, to simplify the notation, we use the notation $f_j=f(x_j)$,\n$f'_j=f'(x_j)$, and, in general, $f^{(n)}_j$ for the $n$-th derivative\nof $f(x)$ evaluated at $x=x_j$.  Using Taylor's theorem to expand\n$f(x)$ at $x=x_j$ we can write\n%\n\\begin{equation}\n  A_j = 2 h f_j + \\frac{h^3}{3} f_j'' + \\frac{h^5}{36} f_j^{(4)} + \\order{h^6}\n  \\label{Qua:eq:20}\n\\end{equation}\n%\nWe now need to compute the Taylor expansion in powers of $h$ of the\nexact result.  In order to do this we introduce the function\n%\n\\begin{equation}\n  F(t) = \\mint{x_j-t}{x_j+t}{f(x)}{x} .\n  \\label{Qua:eq:21}\n\\end{equation}\n%\nNote that with this notation\n%\n\\begin{equation}\n  \\mint{x_{j-1}}{x_{j+1}}{f(x)}{x} = F(h).\n  \\label{Qua:eq:14}\n\\end{equation}\n%\nTherefore, in order to compute the Taylor expansion in powers of $h$\nof the exact result of the integral in equation~(\\ref{Qua:eq:14}), we\nneed to expand $F(t)$ in Taylor series around $t=0$:\n%\n\\begin{equation}\n  F(h) = F(0) +\n  h \\eval{\\dv{F}{t}}_{t=0}  +\n  \\frac{h^2}{2} \\, \\eval{\\dv[2]{F}{t}}_{t=0}  +\n  \\ldots +\n  \\frac{h^5}{5!} \\, \\eval{\\dv[5]{F}{t}}_{t=0} +\n  \\order{h^6}\n  \\label{Qua:eq:15}\n\\end{equation}\n%\nWe note that $F(0)=0$.  Moreover, by the fundamental theorem of\ncalculus (with a little help from the chain rule)\n%\n\\begin{equation*}\n  \\dv{F}{t} = f(x_j+t) + f(x_j-t) \\implies\n  \\dv[n]{F}{d} = f^{(n-1)}(x_j+t) +\n  (-1)^{n+1} f^{(n-1)}(x_j-t) .\n\\end{equation*}\n%\nNote that all the even derivatives of $F(t)$ are zero at $t=0$ so that\nthe Taylor expansion of~(\\ref{Qua:eq:15}) becomes\n%\n\\begin{equation}\n  2 h f_j + \\frac{h^3}{3} f_j'' + \\frac{h^5}{60} f_j^{(4)} + \\order{h^6}.\n  \\label{Qua:eq:30}\n\\end{equation}\n%\nCombining these two expansions, we have that the local error in the\ninterval $[x_{j-1},x_{j+1}]$ is, up to order $h^6$,\n%\n\\begin{equation}\n  E_j \\equiv F(h) - A_j = - \\frac{1}{90} h^5 f_j^{(4)} \\implies\n  \\abs{E_j} \\le \\frac{1}{90} h^5 M_4 ,\n  \\label{Qua:eq:31}\n\\end{equation}\n%\nwhere $M_4$ is the same as in equation~(\\ref{Qua:eq:11}).  Summing the\nlocal errors over all the intervals used in the composite Simpson's\nrule gives the total error, $R$,\n%\n\\begin{equation}\n  \\abs{R} = \\abs{\\sum_{k=1}^{N/2} E_{2k-1}} \\le\n  \\sum_{k=1}^{N/2} \\abs{ E_{2k-1} } \\le\n  \\sum_{k=1}^{N/2} \\frac{1}{90} h^5 M_4 = \\frac{M_4}{180}(b-a)h^4.\n\\end{equation}\n\n\\subsection{Richardson extrapolation}\n\nThis is a very general technique that uses the information on the rate\nof decrease of the error to get a better estimate of the numerical\nresult required.  As such it can be applied to many different\nalgorithms, not just quadratures.  However, here we illustrate it in\nthe context of Simpson's rule.\n\nEquation~(\\ref{Qua:eq:11}) tells us that the error on the estimate of\nthe integral decreases with the fourth power of the integration step,\n$h$.  However, in order to estimate the error using this formula we\nwould also need the value of the coefficient $M_4$.  We can get round\nthis problem by using the following procedure.  Indicate with $I_n$\nthe estimate of the integral using $n$ intervals and with $I$ the\nexact value of the integral.  From~(\\ref{Qua:eq:11}) we have that\n%\n\\begin{equation}\n  I - I_{2n} \\simeq C (2n)^{-4} =\n  2^{-4} \\left ( C n^{-4} \\right ) \\simeq 2^{-4} (I - I_n) .\n  \\label{Qua:eq:16}\n\\end{equation}\n%\nIn this last step we have assumed that the constant $C$ is the same\nwhether we use $n$ or $2n$ intervals to estimate the integral.  This\nnot strictly true, but it is a reasonable approximation if the\nintegration range is small enough.  From~(\\ref{Qua:eq:16}) we have\nthat the exact value of the integral is approximately\n%\n\\begin{equation*}\n  I \\simeq \\frac{2^4 I_{2 n} - I_n}{2^4 -1}\n\\end{equation*}\n%\nand we use this as the new estimate of the integral\n(\\textit{Richardson extrapolated value}):\n%\n\\begin{equation}\n  R_{2 n} = \\frac{2^4 I_{2 n} - I_n}{2^4 -1} .\n  \\label{Qua:eq:22}\n\\end{equation}\n%\nThe error in the approximation is roughly\n%\n\\begin{equation}\n  E_{2n} \\equiv \\abs{ R_{2 n} - I_{2 n} } = \\frac{\\abs{I_n - I_{2 n}}}{2^4 -1} .\n  \\label{Qua:eq:17}\n\\end{equation}\n%\nThis quantity is called the \\textit{computable estimate of the error}.\n\n\\subsection{Adaptive quadrature}\n\nAdaptive quadrature methods are intended to compute definite integrals\nto a given precision by automatically choosing a set of nodes that\ntakes into account the behaviour of the integrand by being denser\nwhere the integrand varies more rapidly. Ideally, the user supplies\nonly the integrand $f$, the interval $[a,b]$, and the accuracy\n$\\epsilon$ desired for computing the integral\n%\n\\begin{equation}\n  \\mint{a}{b}{f(x)}{x} . \\label{Qua:eq:23}\n\\end{equation}\n%\nThe program then divides the interval into sub-intervals of varying\nlength so that numerical integration on these sub-intervals will\nproduce results of acceptable precision. The main idea is that if\nSimpson's rule on a given sub-interval is not sufficiently accurate,\nthat interval will be divided into two equal parts, and Simpson's rule\nwill be used on each half. This procedure will be repeated in an\neffort to obtain an approximation to the integral with the same\naccuracy over all the sub-intervals involved.  A rough algorithm is as\nfollows:\n\n\\begin{enumerate}\n  %\n\\item Compute the integral~(\\ref{Qua:eq:23}) using $3$ points and\n  estimate the global error.  If the error is smaller than the\n  tolerance stop.\n  %\n\\item Divide the interval into two equal parts.  Consider each part in\n  turn.\n  %\n\\item Compute the integral on the sub-interval using $3$ points,\n  i.e.\\ using a finer grid.\n%\n\\item Estimate the error on the evaluation of the integral over the\n  sub-interval.  If it is larger than the maximum acceptable local\n  error then divide the sub-interval in two and start again from point\n  (2).  Otherwise go to point (3) and work on the next sub-interval if\n  there are any left.\n%\n\\end{enumerate}\n\nIn order to apply this idea we need to firstly to estimate the\n\\textit{local error}: we can do this using Richardson's extrapolation\nand equation~(\\ref{Qua:eq:17}).  Secondly, we need to estimate the\n\\textit{global error} on the integration over the entire interval\n$[a,b]$ as a function of the local errors.\n\n\\smallskip\n\n\\noindent\nWe indicate with $e_i$ the local error on the integration over the\nsegment $[x_{i-1},x_i]$. If\n%\n\\begin{equation}\n  \\abs{e_i} \\le \\epsilon (x_i-x_{i-1})/(b-a),\n  \\label{Qua:eq:25}\n\\end{equation}\n%\nthen the total error will be bounded by\n%\n\\begin{equation}\n  \\abs{ \\sum_{i=1}^n e_i} \\le \\sum_{i=1}^n \\abs{e_i} \\le\n  \\frac{\\epsilon}{b-a} \\sum_{i=1}^n (x_i-x_{i-1}) = \\epsilon.\n  \\label{Qua:eq:26}\n\\end{equation}\n%\nTherefore in the adaptive quadrature algorithm outlined above we have\nto ensure that the local error satisfies~(\\ref{Qua:eq:25}).\n\n\\section{Gaussian Quadrature}\n\nThe aim of all quadrature techniques is to create formulae of the type\n%\n\\begin{equation}\n  \\mint{a}{b}{f(x)}{x} \\simeq \\sum_{i=1}^n w_i f(x_i) .\n \\label{Qua:eq:18}\n\\end{equation}\n%\nIn the trapezoidal and Simpson's rule the points where the function is\nevaluated, $x_i$, are fixed \\textit{a priori} and we obtain\nthat~(\\ref{Qua:eq:18}) is exact for all polynomial of degree less than\nor equal to $n$.  In the case of the trapezoidal rule we have $n=2$\nand the rule is exact for all linear functions.  In the case of\nSimpson's rule we have $n=3$ and we would expect the formula to be\nexact for all quadratic polynomials.  As a matter of fact, it is exact\nfor polynomials of order three, but this is due to a happy\ncancellation.\n\nHowever, there is no obligation to fix the nodes.  As a matter of fact\nwe could fix the coefficients (called \\textit{weights}) $w_i$, for\nexample set them all to one, or we could not fix anything.  The\ngeneral criterion to find nodes and weights is to require that\nequation~(\\ref{Qua:eq:18}) is as accurate as possible, i.e.\\ that it is\nexact for polynomials of degree as high as possible.  In other words,\nwe require that the nodes and weights are such that\n%\n\\begin{equation}\n  \\mint{a}{b}{x^s}{x} = \\sum_{i=1}^n w_i x_i^s, \\quad s=0,1,...,N,\n  \\label{Qua:eq:27}\n\\end{equation}\n%\nwith $N$ as large as possible.\n\nAs above, we define the \\textit{fundamental polynomials}\n$\\ell_i(x)$ given by\n%\n\\begin{equation}\n  \\ell_i(x) = \\prod_{\\substack{j = 0\\\\j \\ne i}}^N \\frac{x - x_j}{x_i -\n    x_j}, \\quad i = 0, 1, \\dots, N,\n\\end{equation}\n%\nhave the property that $\\ell_i(x_i) = 1$ and $\\ell_i(x_k) = 0, i \\ne\nk$. It follows that\n%\n\\begin{equation}\n  p(x) = \\sum_{i=0}^N f(x_i) \\ell_i(x)\n\\end{equation}\n%\nis the polynomial of degree $N$ that interpolates the arbitrary\nfunction $f(x)$ at the given nodes $x_i$. If the nodes are known or\nfixed we can therefore immediately compute the weights as\n%\n\\begin{equation}\n  w_i = \\mint{a}{b}{\\ell_i(x)}{x}.\n\\end{equation}\n%\n\nIf neither the nodes nor the weights are fixed we have $N$ nonlinear\nequations for $2n$ unknowns $x_1,...,x_n$ and $w_1,...,w_n$.  One can\nshow that this problem has a unique solution if $N=2n-1$, i.e.\\ that it\nis possible to compute exactly the integrals of polynomials of degree\nup to $2 n - 1$.  The resulting algorithm is called a {\\bf Gaussian\n  quadrature}.  There are many formulae for Gaussian quadrature that\ndepend mainly on the choice of integration interval and on the type of\nthe integral.  A generic Gauss quadrature formula is\n%\n\\begin{equation}\n  \\mint{a}{b}{W(x) f(x)}{x} = \\sum_{i=1}^n w_i f(x_i)\n\\end{equation}\n%\nand the different formulae are summarised in the following table:\n\n\\begin{center}\n \\begin{tabular}{lll} \\hline\n  $(a,b)$ & $W(x)$ & Gauss- \\\\ \\hline\n  $(-1,1)$ & 1 & Legendre \\\\\n  $(-1,1)$ & $(1-x^2)^{-1/2}$ & Chebychev \\\\\n  $(0,\\infty)$ & $x^c e^{-x}$ & Laguerre $c=0,1,\\ldots$ \\\\\n  $(-\\infty,+\\infty)$ & $e^{-x^2}$ & Hermite \\\\ \\hline\n \\end{tabular}\n\\end{center}\n\n\\section*{Further reading}\n\nTopics covered here are also covered in\n\\begin{itemize}\n\\item Chapter 6 of Linz \\& Wang, \\textit{Exploring Numerical\n    Methods} (QA297 LIN),\n\\item Chapter 7 of Kincaid \\& Cheney, \\textit{Numerical Analysis}\n  (QA297 KIN),\n\\item Chapters 7 and 10 of S{\\\"u}li \\& Mayers, \\textit{An Introduction\n    to Numerical Analysis} (not in library).\n\\end{itemize}\n\nThe issue of representing an arbitrary function by an interpolating\nfunction, which will recur in later chapters, is covered in\nconsiderable detail elsewhere; for example\\begin{itemize}\n\\item Chapters 4 and 5 of Linz \\& Wang, \\textit{Exploring Numerical\n    Methods} (QA297 LIN),\n\\item Chapter 6 of Kincaid \\& Cheney, \\textit{Numerical Analysis}\n  (QA297 KIN),\n\\item Chapters 6, 8, 9 and 11 of S{\\\"u}li \\& Mayers, \\textit{An Introduction\n    to Numerical Analysis} (not in library).\n\\end{itemize}\n", "meta": {"hexsha": "7dcae94676a28865d156fe62060c2b757b6fbd60", "size": 19969, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/tex/Quadrature.tex", "max_stars_repo_name": "josh-gree/NumericalMethods", "max_stars_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 76, "max_stars_repo_stars_event_min_datetime": "2015-02-12T19:51:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T15:34:11.000Z", "max_issues_repo_path": "Notes/tex/Quadrature.tex", "max_issues_repo_name": "josh-gree/NumericalMethods", "max_issues_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-05-24T19:49:52.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-23T21:40:42.000Z", "max_forks_repo_path": "Notes/tex/Quadrature.tex", "max_forks_repo_name": "josh-gree/NumericalMethods", "max_forks_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2015-01-05T13:30:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-15T09:59:39.000Z", "avg_line_length": 36.2413793103, "max_line_length": 97, "alphanum_fraction": 0.7013370725, "num_tokens": 6595, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996142, "lm_q2_score": 0.8918110353738529, "lm_q1q2_score": 0.7050036531849956}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 7}\n\nShow how to implement a queue using two stacks.\nAnalyze the running time of the queue operations and argue about their amortized cost.\n\n\\subsection*{Solution}\n\nTo implement a standard queue with \\textsc{Enqueue} and \\textsc{Dequeue} operations, using two stacks with pop and push operations, Algorithms \\ref{alg61} and \\ref{alg62} are respectively proposed, in which number of elements in stack $S$ is noted with $S.length$.\n\n\\begin{algorithm}[H]\n\\caption{\\textsc{Enqueue($x$)}}\\label{alg61}\n\\begin{algorithmic}[1]\n\\State \\textsc{Push($S_1$, $x$)}\n\\State $S_1.length \\leftarrow S_1.length + 1$\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{algorithm}[H]\n\\caption{\\textsc{Dequeue()}}\\label{alg62}\n\\begin{algorithmic}[1]\n\\If {$S_2.length == 0$}\n\\For {$i \\leftarrow S_1.length$ down to $1$}\n\\State $q \\leftarrow$ \\textsc{Pop}($S_1$)\n\\State \\textsc{Push}($S_2$, $q$)\n\\EndFor\n\\EndIf\n\\State \\Return \\textsc{Pop}($S2$)\n\\end{algorithmic}\n\\end{algorithm}\n\nIt is trivial to show that the runtime for \\textsc{Enqueue}$(x)$ using Algorithm \\ref{alg61} is $\\mathcal{O}(1)$ since each \\textsc{Push} operation for an stack takes a constant time $C$.\n\nWhen stack $S_2$ is not empty, \\textsc{Dequeue} operation takes a constant time as well, simply because there is only one \\textsc{Pop} operation with cost $C$.\n\nIn the worst-case however, when stack $S_2$ is empty and there are $n$ elements in stack $S_1$, the for loop will iterate $n$ times, leading to a run-time of $\\mathcal{O}(n)$.\nThus the \\textsc{Dequeue} algorithm is linear in number of elements in queue.\n\nAn amortize analysis, however, reveal both \\textsc{Enqueue} and \\textsc{Dequeue} algorithms only take constant time $C$ per item.\nThis is trivial for \\textsc{Enqueue} since each element is \\textsc{Push}ed only once.\n\nTo prove this statement for \\textsc{Dequeue}, suppose a stack $S_1$ of $m$ elements.\nIt suffices to prove that it takes a multiple of $m$ constant-time cost to dequeue all $m$ elements, thus leading to a $\\mathcal{O}(1)$ cost per element.\n\nTo dequeue the first element, all $m$ elements are \\textsc{Pop}ed from stack $S_1$ and \\textsc{Push}ed to stack $S_2$.\nOnce in $S_2$, they await their turn to be \\textsc{Pop}ed again in later \\textsc{Dequeue} operations.\nThis means each individual element of queue is \\textsc{Pop}ed, \\textsc{Push}ed and \\textsc{Pop}ed only once, and since both two operations have constant-time cost, a \\textsc{Dequeue} will have an amortized cost of 3, i.e. $\\mathcal{O}(1)$.\n", "meta": {"hexsha": "dd8dc2c759d9d5cfd226ea7dd5159c8b9f86e8fc", "size": 2844, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw04/hw04q07.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw04/hw04q07.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw04/hw04q07.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 52.6666666667, "max_line_length": 264, "alphanum_fraction": 0.7063994374, "num_tokens": 840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.897695292107347, "lm_q1q2_score": 0.7049678249356371}}
{"text": "\\documentclass{article}\r\n\\title{ALO for LASSO with Intercept through Generalized LASSO}\r\n\\author{Yuze Zhou}\r\n\\usepackage{amsmath}\r\n\\usepackage{amsfonts}\r\n\\usepackage{graphicx}\r\n\\usepackage{algorithm}\r\n\\usepackage{subfigure}\r\n\\begin{document}\r\n\\maketitle\r\n\\section{The Dual of LASSO with intercept}\r\n\\paragraph{}For the generalized LASSO problem $\\min\\limits_{\\beta}\\frac{1}{2}||y-X\\beta||+\\lambda||D\\beta||_{1}$, the dual problem is derived as:\r\n\\begin{center}\r\n$\\min\\limits_{u}\\frac{1}{2}||y-\\theta||_{2}^{2}$\\\\\r\n$\\theta \\in \\{X^{\\tau}\\theta = D^{\\tau}u, ||u||_{\\infty} \\leq \\lambda\\}$\r\n\\end{center}\r\n\\paragraph{}The dual problem could be written in a proximal approach such that:\r\n\\begin{center}\r\n$\\hat{u} = \\textbf{prox}_{R}(y)$\\\\\r\n$R(u) = \\left\\{\r\n\\begin{aligned}\r\n0 \\quad \\if \\theta \\in \\{X^{\\tau}\\theta = D^{\\tau}u, ||u||_{\\infty} \\leq \\lambda\\}\\\\\r\n+\\infty \\quad otherwise\r\n\\end{aligned}\r\n\\right.\r\n$\r\n\\end{center}\r\n\\paragraph{}Denote $J$ as the jacobian of the proximal operator at the full data problem $y$, then the ALO estimator could be obtained as:\r\n\\begin{center}\r\n$y^{/i} = y_{i} - \\frac{\\hat{u}_{i}}{J_{ii}}$\r\n\\end{center}\r\n\\paragraph{}For the case of LASSO with an intercept, we could expand the $X$ with a column of ones in the first column, expand $\\beta$ with another dimension and choose $D = [\\textbf{0}, I ]$.\r\n\\paragraph{}Denote $E := \\{j: |X_{i}^{\\tau}\\theta| = \\lambda \\}$ to be the active set. Then the Jacobian is locally given as the projection onto the orthogonal complement of the span of $X_{E}$ and the ones vector. Further denote $\\tilde{X}_{E} = [\\textbf{1}, X_{E}]$, then the Jacobian is given as $I - \\tilde{X_{E}}(\\tilde{X_{E}}^{\\tau}\\tilde{X_{E}})\\tilde{X_{E}}^{\\tau}$.\r\n\\end{document}", "meta": {"hexsha": "5f1d1516d41d5379ee20ac06f250c0f5214a9b8c", "size": 1722, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lassointgl.tex", "max_stars_repo_name": "Geophagus96/Summer-ALO", "max_stars_repo_head_hexsha": "a290326a917461dc6b0e516dfc762ce04ed3679a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-07-25T20:32:11.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-25T20:32:11.000Z", "max_issues_repo_path": "lassointgl.tex", "max_issues_repo_name": "Geophagus96/Summer-ALO", "max_issues_repo_head_hexsha": "a290326a917461dc6b0e516dfc762ce04ed3679a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lassointgl.tex", "max_forks_repo_name": "Geophagus96/Summer-ALO", "max_forks_repo_head_hexsha": "a290326a917461dc6b0e516dfc762ce04ed3679a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.6470588235, "max_line_length": 375, "alphanum_fraction": 0.6707317073, "num_tokens": 588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7049678114038443}}
{"text": "\n\n\\chapter{Expression of Angular Eigenstates of Harmonic Oscillators} \\label{appA}\n\nIn this appendix, we derive some results on harmonic oscillators which are useful to show the abilities of entanglement detection of the SRPT criterion.\n\n\\section{Two Dimensional Harmonic Oscillator}\n\nIn two dimensions, the Hamiltonian describing a particle of mass $m$ subject to an isotropic harmonic potential is\n\n\\[ H =  \\frac{p_x^2}{2m}+\\frac{p_y^2}{2m} + \\frac 1 2 m \\omega^2 \\left( x^2 + y^2 \\right),\\]\nwith $x_i, p_i$ the position and momentum of the particle in the directions $i=x,y$ and $\\omega$ a constant. Since $H$ is the sum of two  oscillators Hamiltonians along the directions $x$ and $y$, it is clear that the eigenvalues of the hamiltonian will be written as\n\\[ \\ket{n_x, n_y} \\equiv \\ket{n_x} \\otimes \\ket{n_y}, \\]\nwhen the $\\ket{n_i}$ are the eigenstates of the two one dimensional Hamiltonians. We may define the annihilation operators:\n\\begin{eqnarray}\n    a_x &=& \\frac{1}{\\sqrt 2} \\left( \\sqrt{\\frac{m\\omega}{\\hbar}} x + \\frac{i}{\\sqrt{m \\hbar \\omega}} p_x \\right), \\\\\n    a_y &=& \\frac{1}{\\sqrt 2} \\left( \\sqrt{\\frac{m\\omega}{\\hbar}} y +\\frac{i}{\\sqrt{m \\hbar \\omega}} p_y \\right).\n\\end{eqnarray}\nThe creation operators $a^\\dagger_i$ are the hermitian conjugates of the above operators. We have\n\\[ [a_x,a^\\dagger_x]= [a_y,a^\\dagger_y]=1, \\]\nwhile all other commutators between the four operators are zero. Let us finally define the number operators\n\\begin{eqnarray}\n    N_x &=&a_x^\\dagger a_x, \\\\\n    N_y &=& a_y^\\dagger a_y,\n\\end{eqnarray}\nwhich allow us to write $H$ as\n\\[ H = (N_x + N_y +1) \\hbar \\omega. \\]\n\nThe eigenstates have the properties\n\\begin{eqnarray}\n    a_i \\ket{n_i} &=& \\sqrt{n_i} \\ket{n_i-1},\\\\\n    a_i^\\dagger \\ket{n_i} &=& \\sqrt{n_i+1} \\ket{n_i+1},\\\\\n    N_i \\ket{n_i} &=& n_i \\ket{n_i},\n\\end{eqnarray}\nand therefore, we have\n\\[  \\ket{n_x,n_y} = \\frac{1}{\\sqrt{n_x! n_y!}} \\left( a_x^\\dagger \\right)^{n_x}  \\left( a_y^\\dagger \\right)^{n_y} \\ket{0,0}, \\]\nwith $\\ket{0,0}$ the ground state of the oscillator.\n\nWe can also prove that\n\\[ H \\ket{n_x,n_y} = (n_x + n_y +1) \\hbar \\omega \\ket{n_x,n_y}.\\]\n\nIf we define the total quantum number\n\\[ n = n_x + n_y, \\]\nwe note that one particular value of $n$ corresponds to the $n+1$ orthogonal eigenstates\n\\[ \\ket{n,0}, \\; \\ket{n-1,1}, \\ldots, \\; \\ket{0,n}, \\]\nwhich shows that the measure of the energy alone does not allow us to pinpoint one proper state. The discrimination between all these states could be achieved by measuring the energy separately in the $x$ and $y$ direction, but there is another method that takes advantage of the angular momentum $L_z$. That operator is defined by\n\\[ L_z = x p_y - y p_x,\\]\nor in other terms\n\\[ L_z= i\\hbar(a_x a_y^\\dagger-a_x^\\dagger a_y), \\]\nand it is clear that the $\\ket{n_x,n_y}$ states are not eigenstates of $L_z$.\n\nHowever, it is possible to show that\n\\[ [H,L_z]=0, \\]\nwhich indicates there must be a common eigenstate basis for the two operators. That basis is made of the $\\ket{\\psi_{k,M}}$ eigenvectors which has the following properties:\n\\begin{eqnarray}\n    H \\ket{\\psi_{k,M}} &=& \\hbar \\omega(2k+|M|+1) \\ket{\\psi_{k,M}},\\\\\n    L_z \\ket{\\psi_{k,M}} &=& \\hbar M \\ket{\\psi_{k,M}}.\n\\end{eqnarray}\n\nWe wish to express any $\\ket{\\psi_{k,M}}$ state in function of the $\\ket{n_x,n_y}$ states. It is quite clear that $n=n_x+n_y=2k+|M|$ and therefore for given $k$ and $M$ we have in general\n\\[ \\ket{\\psi_{k,M}} = \\sum_{i=0}^n c_i \\ket{n_x=n-i, n_y=i}. \\label{eq-2Dsum}\\]\n\nTo find the analytical expression of the $c_i$ coefficients, we need to define an intermediate basis as follow\n\\begin{eqnarray}\n    a_r &=& \\frac{1}{\\sqrt 2} \\left(a_x-ia_y \\right), \\\\\n    a_l &=& \\frac{1}{\\sqrt 2} \\left(a_x+ia_y \\right),\n\\end{eqnarray}\nwhere $r$ and $l$ stand for right and left, as those operators can be interpreted as annihilators of right and left  ``circular quanta''. They are very similar to $a_x$ and $a_y$, they follow the commutation rules\n\\[ [a_r,a^\\dagger_r]= [a_l,a^\\dagger_l]=1, \\]\nand all other combinations are zero. It is possible to express the regular ladder operators in function of the circular one and we find that\n\\begin{eqnarray}\n    H&=&(N_r + N_l +1) \\hbar \\omega,\\\\\n    L_z &=& \\hbar (N_r- N_l) ,\n\\end{eqnarray}\nwith $N_r=a^\\dagger_r a_r$ and $N_l=a^\\dagger_l a_l$ the new number operators. We see that there is a $\\ket{\\varphi_{n_r,n_l}}$ basis in which both $H$ and $L_z$ are diagonal and which behaves exactly like the $\\ket{n_x,n_y}$ basis. We also find\n\\begin{eqnarray}\n    n &=& n_r + n_l = 2k+ |M|, \\\\\n    M &=& n_r - n_l,\n\\end{eqnarray}\n\nThis result does allow to associate a definite $\\ket{\\psi_{k,M}}$ state to a single state $\\ket{\\varphi_{n_r,n_l}}$. There are two cases depending on the sign of $M$; if $M>0$, it means $n_r>n_l$ and $|M|=n_r-n_l$ and $k=n_l$, if $M<0$, then $|M|=n_l-n_r$ and $k=n_r$. Globally,\n\\begin{eqnarray}\n    \\ket{\\psi_{k,M}} &=& \\ket{\\varphi_{n_r=k+|M|,n_l=k}} \\:\\: \\textrm{if } M>0, \\\\\n    \\ket{\\psi_{k,M}} &=& \\ket{\\varphi_{n_r=k,n_l=k+|M|}} \\:\\: \\textrm{if } M<0.\n\\end{eqnarray}\n\nWe see that a state with a positive helicity $M$ has more ``right'' quanta than ``left'' quanta and inversely for $M<0$. Now, to express a $\\ket{\\varphi_{n_r,n_l}}$ into a combination of $\\ket{n_x,n_y}$ we have\n\\begin{eqnarray}\n    \\ket{\\varphi_{n_r,n_l}}&=& \\frac{1}{\\sqrt{n_r! n_l!}} \\left( a_r^\\dagger \\right)^{n_r}  \\left( a_l^\\dagger \\right)^{n_l} \\ket{\\varphi_{0,0}}, \\\\\n    &=&   \\frac{1}{\\sqrt{2^n n_r! n_l!}} \\left( a_x^\\dagger +ia_y^\\dagger \\right)^{n_r}  \\left( a_x^\\dagger -ia_y^\\dagger\\right)^{n_l} \\ket{0,0}, \\label{eq-2D2}\\\\\n    &=&   \\frac{1}{\\sqrt{2^n n_r! n_l!}} \\sum_{k=0}^{n_r} \\sum_{l=0}^{n_l}  \\binom{n_r}{k} \\binom{n_l}{l} \\left( a_x^\\dagger \\right)^{n-k-l}  \\left(a_y^\\dagger \\right)^{j+k} (i)^{k-l} \\ket{0,0}, \\label{eq-2D3}\\\\\n    &=&   \\frac{1}{\\sqrt{2^n n_r! n_l!}} \\sum_{i=0}^{n} \\sum_{j}^{\\{-i,-i+2,\\cdots, i\\}}  \\binom{n_r}{\\frac{i-j}{2}} \\binom{n_l}{\\frac{i+j}{2}} \\left( a_x^\\dagger \\right)^{n-i}  \\left(a_y^\\dagger \\right)^i (i)^{j} \\ket{0,0}, \\label{eq-2D4}\\\\\n    &=&   \\frac{1}{\\sqrt{2^n n_r! n_l!}} \\sum_{i=0}^{n} \\sum_{j=0}^{i}  \\binom{n_r}{j} \\binom{n_l}{i-j} \\left( a_x^\\dagger \\right)^{n-i}  \\left(a_y^\\dagger \\right)^i (i)^{2j-i} \\ket{0,0},\\label{eq-2D5} \\\\\n    &=&   \\sum_{i=0}^{n}(-i)^i  \\sqrt{ \\frac{(n-i)! i!}{2^n n_r! n_l!}}    \\sum_{j=0}^{i} (-1)^j \\binom{n_r}{j} \\binom{n_l}{i-j}  \\ket{n-i,i},\\label{eq-2D6} \\\\\n    &=&   \\sum_{i=0}^{n}(-i)^i  \\sqrt{\\frac{\\binom{n}{n_r} }{2^n \\binom{n}{i}}}    \\sum_{j=0}^{i}(-1)^j \\binom{n_r}{j} \\binom{n_l}{i-j}  \\ket{n-i,i}, \\label{eq-2D7}\n\\end{eqnarray}\nwhere on line (\\ref{eq-2D2}) we simply used the definition of $a_r$ and $a_l$ and noted the ground state is the same in both basis, in (\\ref{eq-2D3}) we used the binomial formula twice and in (\\ref{eq-2D4}) we applied the change of variables $i=k+l$ and $j=k-l$. In order to span all values of $(k,l)$ only once, we span all ``antidiagonal'' lines with $k+l=i$ $(i=0,1,\\ldots,n)$ and along those lines we consider the elements $(k=\\frac{i+j}{2},l=\\frac{i-j}{2})$ $(j=-i, -i+2,\\ldots, i-2,i)$. The values of $j$ should actually only go from $\\max\\{-i,i-2 n_l\\}$ to  $\\min\\{i,2 n_r -i\\}$ in order not to go beyond $k=n_r$ and $l=n_l$ but we can simplify it since the binomial coefficients will yield zero if $k>n_r$ or $l>n_l$. In line (\\ref{eq-2D5}) we applied yet another change of variable as $j'=\\frac{i+j}{2}$ $(j=0, 1, \\ldots, i)$ and renamed $j'$ as $j$, in (\\ref{eq-2D6}) we applied the creation operators to the ground state and in (\\ref{eq-2D7}) we multiplied the numerator and denominator in the root term by $n!$ and simplified the expression. The final sum on $j$ may be expressed differently as we find that\n\\[  \\sum_{j=0}^{i}(-1)^j \\binom{n_r}{j} \\binom{n_l}{i-j} = \\binom{n_l}{i} {}_2F_1(-i,-n_r; n_l -i+1;-1), \\]\nwith ${}_2F_1$ the hypergeometric function, but we choose to keep the sum as it is for its implementation simplicity.\n\nNow,  we need to express directly the $\\ket{\\psi_{k,n}}$ state in the $\\ket{n_x, n_y}$ basis. Depending on the sign of $M$, we need to consider the state $\\ket{\\varphi_{k+|M|, k}}$ or $\\ket{\\varphi_{k,k+|M|}}$. The easiest way to see the effect of a swap of $n_r$ and $n_l$ is in line (\\ref{eq-2D3}) where the only difference is $i^{k-l}$  becoming $i^{l-k}=(-i)^{k-l}$. With that consideration, we finally have the $c_i$ coefficients we wanted in (\\ref{eq-2Dsum}) up to an overall phase:\n\\[ c_i =  \\left(- \\textrm{sign}(M) i \\right)^i  \\sqrt{\\frac{\\binom{n}{k} }{2^n \\binom{n}{i}}}    \\sum_{j=0}^{i}(-1)^j \\binom{k+|M|}{j} \\binom{k}{i-j}.\\]\n\nThe last property we want to investigate is the relation\n\\[ c_i = i^n (-1)^{n_l-i} c_{n-i} . \\]\nOn the left hand side, we have\n\\begin{eqnarray}\n    c_i&=& (-i)^i  \\sqrt{\\frac{\\binom{n}{n_r} }{2^n \\binom{n}{i}}}  \\sum_{j=0}^{i}(-1)^j \\binom{n_r}{j} \\binom{n_l}{i-j} ,\n\\end{eqnarray}\nand on the right hand side\n\\begin{eqnarray}\n    c_{n-i}&=&  (-i)^{n-i} \\sqrt{\\frac{\\binom{n}{n_r} }{2^n \\binom{n}{n-i}}}    \\sum_{j=0}^{n-i}(-1)^j \\binom{n_r}{j} \\binom{n_l}{n-i-j} , \\\\\n    &=&  (-i)^{n-i}  \\sqrt{\\frac{\\binom{n}{n_r} }{2^n \\binom{n}{i}}}    \\sum_{j=n_l-i}^{n_r}(-1)^{n_r-j} \\binom{n_r}{n_r-j} \\binom{n_l}{n-i+j-n_r} , \\\\\n    &=&  (-i)^{n-i} (-1)^{n_r}  \\sqrt{\\frac{\\binom{n}{n_r} }{2^n \\binom{n}{i}}}    \\sum_{j=n_l-i}^{n_r}(-1)^{j} \\binom{n_r}{j} \\binom{n_l}{i-j} ,\n\\end{eqnarray}\nwhere in the second step we used the variable change $j'=n_r-j$ and in the last step simplified the expression. Aside from the phase, the only remaining difference is the borns of the sum but thanks to the binomial coefficients, that difference vanishes. Indeed, for both sums, the condition of having non zero terms is $\\max\\{ 0, i- n_l\\} \\le j \\le \\min\\{ i,n_r \\} $, so that all terms considered outside those limits are zero. Of course, we have $|c_i|=|c_{n-i}|$.\n\n\n\\section{Three Dimensional Harmonic Oscillator}\n\nIn three dimensions, the Hamiltonian describing a particle of mass $m$ subject to an isotropic harmonic potential is\n\n\\[ H =  \\frac{p_x^2}{2m}+\\frac{p_y^2}{2m} + \\frac{p_z^2}{2m}+ \\frac 1 2 m \\omega^2 \\left( x^2 + y^2 +z^2\\right),\\]\nwith $x_i, p_i$ the position and momentum of the particle in the directions $i=x,y,z$ and $\\omega$ a constant. Once again, since $H$ is the sum of three oscillators Hamiltonians, the eigenvalues of the hamiltonian will be written as\n\\[ \\ket{n_x, n_y,n_z} \\equiv \\ket{n_x} \\otimes \\ket{n_y} \\otimes \\ket{n_z}, \\]\nwhen the $\\ket{n_i}$ are the eigenstates of the three one dimensional Hamiltonians. We may define the third annihilation operator:\n\\[ a_z = \\frac{1}{\\sqrt 2} \\left( \\sqrt{\\frac{m\\omega}{\\hbar}} z + \\frac{i}{\\sqrt{m \\hbar \\omega}} p_z \\right),\\]\nwhich behaves exactly as the others. We also define its number operator\n\\[ N_z = a_z^\\dagger a_z, \\]\nwhich allow us to write $H$ as\n\\[ H = \\left(N_x + N_y + N_z +\\frac 3 2 \\right) \\hbar \\omega. \\]\n\nThe eigenstates are of the form\n\\[  \\ket{n_x,n_y,n_z} = \\frac{1}{\\sqrt{n_x! n_y!n_z!}} \\left( a_x^\\dagger \\right)^{n_x}  \\left( a_y^\\dagger \\right)^{n_y} \\left( a_z^\\dagger \\right)^{n_z} \\ket{0,0,0}, \\]\nwith $\\ket{0,0,0}$ the ground state of the oscillator. This time for a definite energy $n=n_x+n_y+n_z$ there is a degree of degenerescence $g_n$ of\n\\[ g_n = \\sum_{i=0}^n (i+1) = \\frac{n(n+1)}{2} + (n+1) = \\frac 1 2 (n+1)(n+2). \\]\nJust as we introduced $L_z$ in the two dimensional harmonic oscillator, we introduce the additional observable\n\\[ \\mathbf{L}^2 = \\frac 1 2 (L_+ L_- + L_- L_+) + L_z^2, \\]\nwith\n\\begin{eqnarray}\n    L_+ &=& \\hbar \\sqrt 2 (a^\\dagger_z a_l - a^\\dagger_r a_z), \\\\\n    L_- &=& \\hbar \\sqrt 2 (a^\\dagger_l a_z - a^\\dagger_z a_r).\n\\end{eqnarray}\n\nIt can be checked that $[H,\\mathbf{L}^2]=0$ and $[L_z,\\mathbf{L}^2]=0$ which implies there must be a common set of eigenstates for $H$, $L_z$ and $\\mathbf{L}^2$ . Those eigenstates are the $\\ket{\\psi_{k,l,m}}$ states and have the following properties\n\\begin{eqnarray}\n    H \\ket{\\psi_{k,l,m}} &=& \\hbar \\omega(2k+l+\\frac 3 2) \\ket{\\psi_{k,l,m}},\\\\\n    L_z \\ket{\\psi_{k,l,m}} &=& \\hbar m \\ket{\\psi_{k,l,m}},\\\\\n    \\mathbf{L}^2 \\ket{\\psi_{k,l,m}} &=& \\hbar^2 l(l+1) \\ket{\\psi_{k,l,m}}, \\\\\n    L_\\pm \\ket{\\psi_{k,l,m}} &=& \\hbar \\sqrt{l(l+1)-m(m\\pm1)} \\ket{\\psi_{k,l,m\\pm1}}.\\\\\n\\end{eqnarray}\n\nThe last relation implies that $m$ can take any integer value from $-l$ to $l$. So by repeatedly applying the $L_-$ operator on a $\\ket{\\psi_{k,l,l}}$ state, we should be able to generate all states down to $\\ket{\\psi_{k,l,-l}}$. The first step is to find the expression of the $\\ket{\\psi_{k,l,l}}$ in the $\\ket{\\varphi_{n_r,n_l,n_z}}$ basis using the particular property $L_+ \\ket{\\psi_{k,l,l}} = 0$. By identifying the quantum numbers we find\n\\begin{eqnarray}\n    n&=& n_r + n_l + n_z = 2k+ l, \\\\\n    m &=& n_r - n_l.\n\\end{eqnarray}\n\nSince $n_r-n_l=m$ we can always write $n_r = K+m$, $n_r=K$ with $K$ a positive integer and therefore we must have $n_z=n-m-2K$, which cannot be negative hence we have $K \\le \\frac{n-m}{2}$.  We are now able to write\n\\[ \\ket{\\psi_{k,l,l}} = \\sum_{K=0}^k c_K \\ket{\\varphi_{n_r=K+l, n_l=K, n_z = 2k-2K}}, \\]\nsince $\\frac{n-l}{2} = k$ and with normalized coefficient $c_K$. The effect of $L_+$ on such a decomposition is\n\\bea\nL_+ \\ket{\\psi_{k,l,l}} &=& \\sum_{K=0}^k c_K \\sqrt 2 \\hbar \\left( \\sqrt{K} \\sqrt{2k-2K+1} \\ket{\\varphi_{K+l, K-1,2k-2K+1}} \\right. \\nonumber \\\\\n&& \\ - \\left. \\sqrt{K+l+1}\\sqrt{2k-2K} \\ket{\\varphi_{K+l+1, K,2k-2K-1}} \\right),\n\\eea\nwhich is zero if\n\\[ c_K  \\sqrt{K+l+1}\\sqrt{2k-2K} = c_{K+1} \\sqrt{K+1} \\sqrt{2k-2K-1}. \\]\n\nFrom that relation, we can express all $c_K$ in function of $c_0$ and then normalize all coefficient. We have\n\\bea\nc_K^2 &=& c_0^2 \\prod_{j=0}^{K-1} \\frac{(j+l+1)(2k-2j)}{(j+1)(2k-2j-1)} ,\\\\\n&=& c_0^2 \\frac{(l+1)(l+2)\\ldots(l+K)(2k)(2k-2)\\ldots(2k-2K+2)}{(1)(2)\\ldots K (2k-1)(2k-3)\\ldots(2k-2K+1)} ,\\\\\n&=& c_0^2 \\frac{(l+K)!}{l!K! } \\frac{(2k)!!}{(2k-2K)!!} \\frac{(2k-2K-1)!!}{(2k-1)!!}, \\\\\n&=& c_0^2 \\binom{l+K}{K} \\frac{2^k k! }{2^{k-K}(k-K)! }\\frac{(2k-2K)!}{2^{k-K}(k-K)! }\\frac{2^{k}(k)! }{(2k)!}, \\\\\n&=& c_0^2 \\,2^{2K}\\,\\frac{ \\binom{l+K}{K} \\binom{2k-2K}{k-K}  }{ \\binom{2k}{k} },\n\\eea\nwhere $k!!$ is the double factorial of $k$ which has the property\n\\bea\n(2k)!! &=&(2k)(2k-2)\\ldots2 = k! 2^{k}, \\\\\n(2k+1)!! &=&(2k+1)(2k-1)\\ldots1 = \\frac{(2k)!}{k! 2^{k}},\n\\eea\nthat we used in the process.\n\nWith that expression, we are now able to calculate the value of $c_0$ by normalizing the expression. We have\n\\bea\n\\sum_{K=0}^k c_K^2 &=& c_0^2 \\sum_{K=0}^k \\,2^{2K}\\,\\frac{ \\binom{l+K}{K} \\binom{2k-2K}{k-K}  }{ \\binom{2k}{k} }, \\\\\n&=& c_0^2 \\frac{ \\binom{2(k+l+1)}{2k}}{ \\binom{k+l+1}{k} },\n\\eea\nSince that expression must be 1, we have he value of $c_0$. Finally, we get up to a global phase\n\\[ \\ket{\\psi_{k,l,l}} = \\sum_{K=0}^k\\,2^{K}\\, \\sqrt{ \\frac{ \\binom{l+K}{K} \\binom{2k-2K}{k-K} \\binom{k+l+1}{k} }{ \\binom{2k}{k}  \\binom{2(k+l+1)}{2k} }} \\ket{\\varphi_{K+l, K, 2k-2K}}. \\]\n\n%From that state we can get any other  $\\ket{\\psi_{k,l,m}}$ by applying $L_-$ the right number of time. Indeed, we have\n%\\[ \\ket{\\psi_{k,l,m}}=\\frac{(L_-/\\hbar)^{l-m}}{\\prod_{j=m+1}^l \\sqrt{l(l+1)-j(j-1)}} \\ket{\\psi_{k,l,l}}. \\]\n%\n%First, we simplify the product at the denominator\n%\\bea\n%\\prod_{j=m+1}^l \\sqrt{l(l+1)-j(j-1)} &=& \\prod_{j=m+1}^l \\sqrt{l+j}\\sqrt{l-j+1}, \\\\\n%&=& \\sqrt{\\frac{(2l)!}{(l+m)!}}\\sqrt{(l-m)!}=\\sqrt{\\binom{2l}{l+m}} (l-m)!.\n%\\eea\n%We also have\n%\\[ \\left(\\frac{L_-}{\\hbar}\\right)^{l-m} = 2^{\\frac{l-m}{2}} (a^\\dagger_l a_z - a^\\dagger_z a_r)^{l-m} = 2^{\\frac{l-m}{2}} \\sum_{j=0}^{l-m} (-1)^j \\binom{l-m}{j} (a^\\dagger_l a_z)^{l-m-j} (a^\\dagger_z a_r)^j, \\]\n%and by noting that\n%\\bea \n%a^{k} \\ket{n} &=& \\sqrt\\frac{n!}{(n-k)!} \\ket{n-k}, \\\\ \n%(a^\\dagger)^{k} \\ket{n} &=& \\sqrt\\frac{(n+k)!}{n!} \\ket{n+k}, \n%\\eea\n%we see that\n%\\bea \n%(a^\\dagger_l a_z)^{l-m-j} (a^\\dagger_z a_r)^j  \\ket{\\varphi_{K+l, K, 2k-2K}} &=&   \\sqrt\\frac{(K+l)!}{(K+l-j)!} \\sqrt\\frac{(K+l-m-j)!}{K!} \\nonumber \\\\\n%&& \\ \\sqrt\\frac{(2k-2K+j)!}{(2k-2K-l+m+2j)!} \\sqrt\\frac{(2k-2K+j)!}{(2k-2K)!} \\nonumber \\\\\n%&& \\ \\ket{\\varphi_{K+l-j, K+l-m-j, 2k-2K-l+m+2j}},\n%\\eea\n%and if we apply the variable change $j'=K+l-j$ ($j'=K+m,\\ldots, K+l$)\n%\\[ (a^\\dagger_l a_z)^{l-m-j} (a^\\dagger_z a_r)^j  \\ket{\\varphi_{K+l, K, 2k-2K}} =   \\sqrt\\frac{(K+l)!(j-m)!(n-K-j)!^2}{j!K!(n+m-2j)!(2k-2K)!} \\ket{\\varphi_{j, j-m, n+m-2j}}.\\]\n%\n%The expression became\n%\\[ \\ket{\\psi_{k,l,m}}=\\sum_{K=0}^k   \\sum_{j=K+m}^{K+l}  (-1)^j  c_{K,j}\\ket{\\varphi_{j, j-m, n+m-2j}},\\]\n%with\n%\\bea\n%c_{K,j}&=&  \\sqrt{ \\frac{  \\binom{l-m}{K+l-j}^2  \\binom{l+K}{K} \\binom{2k-2K}{k-K} \\binom{k+l+1}{k} }{2^{l-m-2K} \\binom{2k}{k}  \\binom{2(k+l+1)}{2k} \\binom{2l}{l+m}}}  \\sqrt\\frac{(K+l)!(j-m)!(n-K-j)!^2}{(l-m)!^2j!K!(n+m-2j)!(2k-2K)!} \n%\\eea\n", "meta": {"hexsha": "5af4d45dcf73396b4ddcebe4309130f1ee830d80", "size": 16689, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Examples/MainText/appendixA.tex", "max_stars_repo_name": "oist/Thesis-LaTeX-template", "max_stars_repo_head_hexsha": "bac95aefb568fb28782927cb179a758e1f90477c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-01-18T12:08:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T04:05:24.000Z", "max_issues_repo_path": "Examples/MainText/appendixA.tex", "max_issues_repo_name": "oist/Thesis-LaTeX-template", "max_issues_repo_head_hexsha": "bac95aefb568fb28782927cb179a758e1f90477c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Examples/MainText/appendixA.tex", "max_forks_repo_name": "oist/Thesis-LaTeX-template", "max_forks_repo_head_hexsha": "bac95aefb568fb28782927cb179a758e1f90477c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 75.1756756757, "max_line_length": 1119, "alphanum_fraction": 0.6219665648, "num_tokens": 6832, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.704944658089}}
{"text": "\\chapter{Reconstructing  CT Signals}\n\nIn the previous lecture we focused on sampling of CT signals to produce a DT signal $x[n] = x(nT)$ with sample index $n$ and sample time $T$. In this lecture we consider \\emph{reconstruction}, converting from a DT signal $x[n]$ to a CT signal $x(t)$ using a sample time $T$ as the spacing between samples. Ideally a conversion from $x(t)$ to $x[n]$ and back again would result in identical signal. \n\n\\section{Reconstruction Theory}\nGiven a DT signal $x[n]$ and a sample spacing $T$, we can define a corresponding CT signal as \n\\[\nx_p(t) = \\sum\\limits_{n = -\\infty}^{\\infty} x[n] \\, \\delta(t-nT)\n\\]\nthe impulse train with each impulse weighted by the DT signal.\n\nCT signal reconstruction can be viewed from two different (but equivalent) perspectives. In the time domain perspective, the CT signal $x(t)$ corresponding to a DT signal $x[n]$ can be viewed as \\emph{interpolation}, where the values of the CT signal are equal to the DT signal at intervals of the sample time, i.e. $x(nT) = x[n]$, and in between the value of $x(t)$ is interpolated. If the interpolation is of zero-order, the value at $x(nT)$ is held constant until $x(nT+T)$. This is called a \\emph{zero-order hold}, and can mathematically modeled as convolution of the weighted impulse train with a pulse $p(t) = u(t) - u(t-T)$ whose width is the sample time, called the interpolation function.\n\\[\ny(t) = p(t)*x_p(t)\n\\]\nThis is illustrated below\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/zero-order-hold-interp.pdf}\n\\end{center}\n\nThe zero-order hold is not a very accurate representation of a band-limited signal. So, what interpolation function is optimal?\n\nTo answer this question we can turn to the alternative perspective on reconstruction, that of the frequency domain. Recall the sampled signal $x(nT)$ in the frequency domain can be viewed as the summation of the Fourier transform of $x(t)$, $X(j\\omega)$, and periodic replicas or images centered at multiples of the sampling frequency. If we assume the original signal was band-limited and sampled appropriately (using the Nyquist criteria), then if we ideal low-pass filter the sampled signal we will preserve the central portion of the Fourier spectrum that corresponds to the original signal, and chop off the images. For this reason the reconstruction filter is also called an anti-imaging filter.\n\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/bandlimitedreconstructed1.pdf}\n\\end{center}\n\nRecall filtering is multiplication the frequency domain and convolution in the time domain, so the optimal interpolation function corresponds to the impulse response of the ideal low-pass filter with cutoff frequency $\\omega_c = 2\\pi B$, a sinc function.\n\n\\[\nh(t) = \\mathcal{F}^{-1} \\left\\{ H(j\\omega) \\right\\} = \\frac{1}{2\\pi} \\int\\limits_{\\-\\omega_c}^{\\omega_c} e^{j\\omega t} \\; d\\omega = \\frac{1}{\\pi t}\\sin(\\omega_c t) \n\\]\n\nThus the ideal ideal interpolation function is the sinc function, and reconstruction is low-pass filtering of the weighted impulse train $x_p(t)$ \\footnote{As an aside this also gives an intuitive view of convolution with an impulse train, as interpolation}.\n\n\\section{Practical Reconstruction}\n\nAs we have seen before we cannot physically represent the impulse train nor the ideal low-pass filter. Thus practical reconstruction uses an approximation of the ideal reconstruction filter by a digital-to-analog converter (DAC), followed by a causal (and thus physically possible) low-pass filter.\n\n\\subsection{Zero-order hold using an R-2R ladder}\n\nA zero-order hold DAC can be implemented by a circuit called a resistor ladder. Consider a digital output with $N$ bits and a reference voltage $V_{ref}$ (for example an 8-bit output port on a micro-controller using CMOS 3.3v logic).\n\nIf this port is connected to a resistor network consisting of resistor values $R$ and $2R$ as follows\n\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/resistor-ladder.pdf}\n\\end{center}\n\n\nthen depending on the bit pattern at the output port $V$, the output of the buffer op-amp will be\n\\[\nV_o = V_{ref}\\frac{V}{2^N}\n\\]\n\nIf the port value is changed every sample time $T$, then the resister ladder and buffer op-amp combine to implement a zero-order hold circuit.\n\n\\subsection{Reconstruction(anti-imaging) filter}\n\nThe zero-order hold is followed by the reconstruction (anti-imaging) filter which low-pass filters the output and smooths-out the jumps from value to value.\n\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/sinc-interp.pdf}\n\\end{center}\n\nIn general the reconstruction filter is of a similar, or identical form to the anti-aliasing filter.\n", "meta": {"hexsha": "71c8d39ffb1bbfd1481d8ca3021f7df46eda607e", "size": 4641, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "24-recon.tex", "max_stars_repo_name": "clwyatt/notes-2714", "max_stars_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "24-recon.tex", "max_issues_repo_name": "clwyatt/notes-2714", "max_issues_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "24-recon.tex", "max_forks_repo_name": "clwyatt/notes-2714", "max_forks_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.25, "max_line_length": 701, "alphanum_fraction": 0.7629821159, "num_tokens": 1137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603726, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.704944645435483}}
{"text": "%!TEX root=ClassNotes.tex\n\n\\section{Applications of Integrals}\n\n\\subsection{Improper Integrals}\nImproper integrals compute areas of unbounded regions. These integrals are a source of several false paradoxes. As we'll see below, counter-intuitive as it may seem, unbounded regions {\\it can} have finite areas.\\\\\n\nWe'll study two types of improper integrals: depending on whether the corresponding region is unbounded along the $x$-axis or along the $y$-axis.\nThe idea is to {\\it view an unbounded region as a limit of bounded regions}.\n\n\\begin{definition}\n  {\\bf Improper integrals} (of the first kind) are integrals where one (or both) of the bounds is $\\pm \\infty$.\\footnote{Note that $\\infty$ is not a number here either, but represents a limit.}\n  Let $f$ be a continuous function.\n  Define,\n\t\\begin{align*}\n\t\t\\int \\limits_a^{\\infty} f(t) \\: dt\n\t\t & =\n\t\t\\lim \\limits_{x \\rightarrow \\infty}\\int \\limits_a^{x} f(t) \\: dt \\\\\n\t\t\\int \\limits_{-\\infty}^a f(t) \\: dt\n\t\t & =\n\t\t\\lim \\limits_{x \\rightarrow -\\infty}\\int \\limits_{x}^{a} f(t) \\: dt \\\\\n\t\t\\int \\limits_{-\\infty}^{\\infty} f(t) \\: dt\n\t\t & =\n\t\t\\lim \\limits_{x \\rightarrow \\infty}\\int \\limits_0^{x} f(t) \\: dt\n    +\n    \\lim \\limits_{x \\rightarrow -\\infty}\\int \\limits_{x}^{0} f(t) \\: dt\n\t\\end{align*}\n  where $a$ is a real number.\n\\end{definition}\n\n\\begin{exercise}\n\tFor the following problems, draw the region whose area the integral is computing (you can use a calculator for graphing) and compute the integral.\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $\\int \\limits_1^{\\infty} \\dfrac{1}{t} \\: dt$\n\t\t\t\\item $\\int \\limits_1^{\\infty} \\dfrac{1}{t^2} \\: dt$\n\t\t\t\\item $\\int \\limits_0^{\\infty} \\sin t \\: dt$\n\t\t\t\\item $\\int \\limits_0^{\\infty} 2t e^{-t^2} \\: dt$\n\t\t\t\\item $\\int \\limits_{1}^{\\infty} \\dfrac{9}{(1 - 3t)^4} \\: dt$\n\t\t\t\\item $\\int \\limits_{-\\infty}^{\\infty} \\dfrac{6 t^3}{(t^4 + 1)^2} \\: dt$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\n\\begin{exercise}\n  \\begin{enumerate}\n    \\item The choice of the number 0 in the definition of $\\int_{-\\infty}^{\\infty}$ is not important. We can replace 0 with any real number and the answer would not change.\n    Compute\n    \\begin{align*}\n      \\lim \\limits_{x \\rightarrow \\infty}\\int \\limits_1^{x} \\dfrac{6 t^3}{(t^4 + 1)^2} \\: dt\n      +\n      \\lim \\limits_{x \\rightarrow -\\infty}\\int \\limits_{x}^1 \\dfrac{6 t^3}{(t^4 + 1)^2} \\: dt\n    \\end{align*}\n    and compare it with Problem 6 of the previous exercise. Why does the answer not change?\n\n    \\item On the other hand, consider the following change.\n    Compute\n    \\begin{enumerate}\n      \\item $\\lim \\limits_{x \\rightarrow \\infty}\\int \\limits_{-x}^{x} \\sin t \\: dt$, and\n      \\item $\\lim \\limits_{x \\rightarrow \\infty}\\int \\limits_0^{x} \\sin t \\: dt\n      +\n      \\lim \\limits_{x \\rightarrow -\\infty}\\int \\limits_{x}^{0} \\sin t \\: dt$\n    \\end{enumerate}\n    Why are the two answers different?\n  \\end{enumerate}\n  Thus, when limits are involved, our intuition does not always provide us with the correct answer.\n\\end{exercise}\n\n\\begin{definition}\n  {\\bf Improper integrals} (of the second kind) are integrals where the function being integrated has a discontinuity in the interval of integration.\n  Let $[a,b]$ be an interval and let $c \\in [a, b]$ be a point such that $f(x)$ is discontinuous at $c$ but continuous on the rest of interval. Define,\n\t\\begin{align*}\n    \\mbox{if } a < c < b, &&\n    \\int \\limits_a^b f(t) \\: dt\n\t\t & =\n\t\t\\lim \\limits_{x \\rightarrow c^{-}}\\int \\limits_a^{x} f(t) \\: dt\n    +\n    \\lim \\limits_{x \\rightarrow c^{+}}\\int \\limits_{x}^{b} f(t) \\: dt \\\\\n    \\mbox{if } c = a, &&\n    \\int \\limits_c^b f(t) \\: dt\n\t\t & =\n    \\lim \\limits_{x \\rightarrow c^{+}}\\int \\limits_{x}^{b} f(t) \\: dt \\\\\n    \\mbox{if } c = b, &&\n    \\int \\limits_a^c f(t) \\: dt\n\t\t & =\n\t\t\\lim \\limits_{x \\rightarrow c^{-}}\\int \\limits_a^{x} f(t) \\: dt\n\t\\end{align*}\n\\end{definition}\n\n\n\\begin{exercise}\n\tFor the following problems, draw the region whose area the integral is computing (you can use a calculator for graphing if you like) and compute the integral.\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $\\int \\limits_0^{3} \\dfrac{1}{\\sqrt{3 - t}} \\: dt$\n\t\t\t\\item $\\int \\limits_{2}^{3} \\dfrac{4t}{\\sqrt[3]{t^2 - 4}} \\: dt$\n\t\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\nIt is possible to compute integrals of more general unbounded regions using the same ideas.\n\n\\subsection{Arc Length}\nRecall that the integral $\\int_a^b f(t) \\: dt$ is defined as the limit of the Riemann sum\n\\begin{align*}\n  \\sum_{i = 0}^{n-1} m_i (x_{i+1} - x_{i})\n\\end{align*}\nwhere $x_i$'s form a partition of the interval $[a,b]$ and $m_i$ is the min (inf) of the $f(x)$ values in the interval $[x_i, x_{i+1}]$. One way to {\\it represent} this sum is as the sum of several quantities of the form\n\\begin{align*}\n  y \\: \\Delta x\n\\end{align*}\nwhere $\\Delta x$ stands for the length of the interval $x_{i+1} - x_i$ which can be thought of as {\\bf the change in $x$}, and $y$ stands for {\\bf the minimum value of $f(x)$} for $x \\in[x_i, x_{i+1}]$. So that\n\\begin{align}\n  \\label{eq:sum_limit}\n  \\lim \\limits_{\\Delta x \\rightarrow 0} \\left(\\sum y \\: \\Delta x \\right) = \\int y \\: dx\n\\end{align}\nThe reason for doing this, is that this allows us to interpret several {\\it naturally occurring} quantities as integrals (which is why the Riemann sum formulation of integral is much more useful than the area formulation). One such example is an {\\bf arc length}.\\\\\n\n\n{\\bf Arc length} is just a fancy name for the length of a curve. For example, the arc length of a circle of radius $r$ is $2 \\pi r$. We are interested in computing the arc length of the graph of a function $y=f(x)$.\n\\begin{figure}[H]\n  \\centering\n  \\includegraphics[width=0.5\\textwidth]{ArcLength.png}\n  \\caption*{Approximating the graph $y=f(x)$ by line segments}\n\\end{figure}\nWe do this by partitioning the interval $[a,b]$ and approximating the graph $ y = f(x)$ over each partition by a straight line. The length of each small straight line segment equals\n\\begin{align*}\n  \\sqrt{\\Delta x^2 + \\Delta y^2}\n\\end{align*}\nand hence the arc length equals\n\\begin{align*}\n  \\lim \\limits_{\\Delta x \\rightarrow 0}  \\left(\\sum \\sqrt{\\Delta x^2 + \\Delta y^2}\\right)\n\\end{align*}\nThis looks very close to \\eqref{eq:sum_limit}. Next we need to separate a $\\Delta x$ term.\n\\begin{align*}\n  \\lim \\limits_{\\Delta x \\rightarrow 0} \\left(\\sum \\sqrt{1 + \\left(\\dfrac{\\Delta y}{\\Delta x}\\right)^2} \\Delta x \\right)\n\\end{align*}\nThis looks exactly like \\eqref{eq:sum_limit} with $y$ replaced with $\\sqrt{1 + \\left(\\frac{\\Delta y}{\\Delta x}\\right)^2}$. Finally we notice that\n\\begin{align*}\n  \\lim \\limits_{\\Delta x \\rightarrow 0} \\dfrac{\\Delta y}{\\Delta x} = \\dfrac{dy}{dx}\n\\end{align*}\nwhich gives us the formula for the arc length.\n\\begin{theorem}\n  \\label{thm:arclength}\n  Let $f$ be a differentiable function on the interval $[a,b]$. The arc length of the graph $y = f(x)$ over the interval $[a,b]$ is given by the integral\n  \\begin{align*}\n    \\int \\limits_a^b \\sqrt{1 + \\left(\\dfrac{dy}{dx} \\right)^2}  \\: dx\n  \\end{align*}\n\\end{theorem}\nWhile the above derivation is not a {\\it proof}, it can be converted into a proof using $\\sup$'s and $\\inf$'s, using the same method we used to prove the Fundamental Theorem of Calculus.\n\n\\begin{exercise}\n  Using the arc length formula in Theorem \\ref{thm:arclength} compute the following:\n  \\begin{enumerate}\n    \\item Circumference of a circle of radius r.\n    \\item Arc length of the parabola $y = x^2$ from 0 to 1.\n    \\item Arc length of line segment $y = m x$ from $a$ to $b$, where $m$, $a$, $b$ are real numbers. Explain the result geometrically.\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n  Here we encounter the first example of a {\\it naturally occurring} unsolvable integral.\n  Find the expression for the arc length of the sine curve $y = \\sin x$ from 0 to $a$.\n  This integral, called an {\\bf elliptic integral}, cannot be algebraically computed.\\footnote{Even though elliptic integrals cannot be simplified algebraically, they have deep connections to number theory.\n  The impossibility of algebraically evaluating elliptic integrals presents the first obstacle towards a complete understanding of prime numbers!\\\\\n  See: \\url{https://en.wikipedia.org/wiki/Elliptic_function}}\n\\end{exercise}\n\n\\begin{exercise}{\\bf (Optional)}\n  In this problem, you'll need to use the fact that the (curved) surface area of a cylinder is $2 \\pi r h$ and the volume is $\\pi r^2 h$, where $r$ is the radius and $h$ is the height of the cylinder.\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{SurfaceOfRevolution.png}\n  \\end{figure}\n  \\end{exercise}\n  \\begin{enumerate}\n    \\item Derive the formula for the area of the surface obtained by revolving the curve $y = f(x)$ over the interval $[a,b]$ about the $x$-axis.\n   Such a surface is called a {\\bf surface of revolution}.\n    \\item Derive the formula for the volume of the solid obtained by revolving the region under the curve $y = f(x)$ over the interval $[a,b]$ about the $x$-axis.\n    Such a solid is called a {\\bf solid of revolution}.\n  \\end{enumerate}\nWe can do both of these constructions by revolving the curve about the $y$-axis instead of the $x$-axis. In this case, we simply switch $x$ and $y$ and use the function $x=f^{-1}(y)$ instead of $y = f(x)$.\\\\\n\n\n\\subsection{Differential Equations}\nIt would be remiss to not mention differential equations while studying applications of calculus.\nCalculus was invented by Newton to find solutions to his laws of motion, which are a set of differential equations.\n\nA {\\bf differential equation} is any equation involving derivatives $\\frac{dy}{dx}$, $\\frac{d^2y}{dx^2}$ etc.\nSolving a differential equation means finding a function $y = f(x)$ that satisfies the equation.\n\nWe've already encountered one very simple differential equation.\nThe Fundamental Theorem of Calculus is essentially a statement about the solution of a differential equation.\nWe can rephrase it as saying:\\\\ {\\it The solution to the differential equation\n\\begin{align*}\n  \\dfrac{dy}{dx} = g(x)\n\\end{align*}\nis given by\n\\begin{align*}\n  y = \\int g(x) \\: dx.\n\\end{align*}\n}\n\nIn this section, we'll see some examples of differential equations without going into any details.\nIt is not possible to {\\it solve} this differential equation in the same way that we solve algebraic equations. Instead, we {\\it guess} a solution and verify it.\n\n\\begin{exercise}\n  A {\\bf separable} differential equation is of the form\n  \\begin{align*}\n    \\dfrac{dy}{dx} = f(x) \\cdot g(y)\n  \\end{align*}\n  for some functions $f$ and $g$. The solution of this differential equation is given by\n  \\begin{align*}\n    \\int \\dfrac{1}{g(y)} \\: dy  = \\int f(x) \\: dx\n  \\end{align*}\n  It is called separable because the variables $x$ and $y$ can be ``separated'' i.e. all the terms involving $y$ are on the left hand side and all the terms involving $x$ are on the right hand side. A non-example is $\\frac{dy}{dx} = x + y$.\n\n  Find solutions for the following separable differential equations and verify that your solution satisfies the differential equation.\n  \\begin{multicols}{2}\n    \\begin{enumerate}\n      \\item $\\dfrac{dy}{dx} = 2y$\n      \\item $\\dfrac{dy}{dx} = xy$\n      \\item $\\dfrac{dy}{dx} = \\dfrac{3x^2}{\\cos y}$\n      \\item $\\dfrac{dy}{dx} = - \\dfrac{y}{x}$\n      \\item $\\dfrac{dy}{dx} = - \\dfrac{x}{y}$\n      \\item $\\dfrac{dy}{dx} = e^{-y}(2x - 4) $\n    \\end{enumerate}\n  \\end{multicols}\n\\end{exercise}\n\n\\newpage\n\\begin{exercise}\n  The following differential equation is called a {\\bf damped harmonic oscillator},\n  \\begin{align*}\n    m \\dfrac{d^2y}{dx^2} + c \\dfrac{dy}{dx} + k y = 0\n  \\end{align*}\n  where $m$, $k$, and $c$ are constants.\n  This differential equation is used to model simple oscillatory systems.\n  \\begin{enumerate}\n    \\item Find a number(s) $r$ such that $y=e^{rx}$ solves the differential equation\n    \\begin{align*}\n       \\dfrac{d^2y}{dx^2} - 4 y = 0\n    \\end{align*}\n    \\item Find a number(s) $r$ such that $y=e^{rx}$ solves the differential equation\n    \\begin{align*}\n       \\dfrac{d^2y}{dx^2} + 4 y = 0\n    \\end{align*}\n    \\item Find a number(s) $r$ such that $y=e^{rx}$ solves the differential equation\n    \\begin{align*}\n       \\dfrac{d^2y}{dx^2} - 2 \\dfrac{dy}{dx} + y = 0\n    \\end{align*}\n    For this $r$, verify that $y = x e^{rx}$ is also a solution.\n    \\item Notice that the three equations have very different kinds of solutions.\n    How would you describe the difference between the three equations?\n  \\end{enumerate}\n\\end{exercise}\n\nDifferential equations in general are very very difficult to solve. Finding solutions to differential equations has been a guiding question for much of modern mathematics. It is still not known whether a solution exists to the differential equation that describes fluid motion.\\footnote{See \\url{https://en.wikipedia.org/wiki/Navier-Stokes_equations}.} Nevertheless a lot of techniques now exist for solving a variety of differential equations either exactly or numerically.\nDifferential equations is one of the most active areas of mathematical research today.\n", "meta": {"hexsha": "cbca0bb62029980fdbceba60b7acba0438650874", "size": 13064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2018/10ApplicationIntegrals.tex", "max_stars_repo_name": "apurvnakade/jhu2017-18-honors-single-variable-calculus", "max_stars_repo_head_hexsha": "5b6cb3dde364990abe868ce155a697dce78302fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2018/10ApplicationIntegrals.tex", "max_issues_repo_name": "apurvnakade/jhu2017-18-honors-single-variable-calculus", "max_issues_repo_head_hexsha": "5b6cb3dde364990abe868ce155a697dce78302fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2018/10ApplicationIntegrals.tex", "max_forks_repo_name": "apurvnakade/jhu2017-18-honors-single-variable-calculus", "max_forks_repo_head_hexsha": "5b6cb3dde364990abe868ce155a697dce78302fa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.2461538462, "max_line_length": 474, "alphanum_fraction": 0.6847826087, "num_tokens": 4058, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245911726382, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7049446324891097}}
{"text": "\\chapter{Linear Regression}\n\\label{chp:linreg}\n\n%Linear regression is an approach in supervised learning. It is used for predicting a quantitative response and it is widely used for statistical learning methods. It may seem that it is a bit simple compared to some of the more modern statistical learning approaches, but it serves as a good base as newer approaches can be seen as a generalization or extension of the linear regression. \n%This chapter presents the key ideas of a linear regression model and it will describe the least squares approach\n%which is the most commonly used to fit this model\\\\\n\nThis chapter presents Linear regression which is an approach in supervised learning that can be used for predicting a quantitative response. Furthermore the least squares approach is explained as the most commonly used method for fitting a linear regression model.\n\n\\section{Simple Linear Regression}\n\nSimple linear regression is used for predicting a quantitative response, often denoted Y, based on a single predictor, often denoted X.\nThe relationship between X and Y can be expressed as:\n\n\\begin{equation}\nY \\approx \\beta_0 + \\beta_1X\n\\end{equation}\n\nIn equation (2.1) $\\beta_0$ represents the intercept and $\\beta_1$ which is multiplied with X represents the slope.\n%This means that Y is approximately modeled as X or in other words Y is regressing on X. \n%$\\beta_0$ and $\\beta_1$ are two unknown constants that represent the intercept and slope in the linear model. They are also known as model coefficients or parameters. \nIn linear regression training data containing observations of X and Y is used to estimate $\\hat{\\beta_0}$ and $\\hat{\\beta_1}$. \nThis can be mathematically expressed as:\n\n\\begin{equation}\n\\hat{y} = \\hat{\\beta_0} + \\hat{\\beta_1}x\n\\end{equation}\n\n%$\\hat{y}$ is the prediction of Y based on X = x. The \\textit{hat} %symbol is used to denote the estimated value for an unknown parameter or coefficient or to predict a value of the response.\n\n%When estimating the coefficients \n%$\\hat{\\beta_0}$ and  $\\hat{\\beta_1}$ are in practice unknown. So %in order to use (2.1) to make predictions, $\\hat{\\beta_0}$ and  %$\\hat{\\beta_1}$ needs to be estimated so the data can be used. \n\n%First Let \n%\\begin{equation}\n%(x_1, y_1), (x_2, y_2),..., (x_n, y_n)\n%\\end{equation}\n\n%represent n observation pairs where each of them have a measurement of X and a measurement of Y. n can represent lots of thing. can be the number of different markets, or different cities. It depends on the data.\n\n$\\hat{\\beta_0}$ and  $\\hat{\\beta_1}$ must be estimated to fit all the observations as good as possible. This can be ensured by using the least squared approach.\n%In other words $\\hat{\\beta_0}$ is the intercept and  $\\hat{\\beta_1}$ is a slope, so the resulting line is as close as possible to n\\{th} data points\n\n%First the prediction for Y will be written as $\\hat{y_i} = \\hat{\\beta_0} + \\hat{\\beta_1} x_i$ based on the \\emph{i}th value of X.\n%Then $e_i = y_i - \\hat{y_i}$ will represent the \\emph{i}th residual, which is the difference between the \\emph{i}th observed response value and the \\emph{i}th response value that is predicted by the linear model.\n\nLeast squared approach determines the $\\hat{\\beta_0}$ and  $\\hat{\\beta_1}$ to minimize the residual sum of squares.\nThe residual is defined as the difference between the predicted and the true response value: $y-\\hat{y}$. $\\hat{y}$ can be replaced with $\\hat{\\beta_0} + \\hat{\\beta_1}x$ and the residual sum of squares can then be defined as:\n\n\\begin{equation}\nRSS = (y_1 - (\\hat{\\beta_0} + \\hat{\\beta_1}X_1))^2 + (y_2 - (\\hat{\\beta_0} + \\hat{\\beta_1}X_2))^2 + ... + (y_n - (\\hat{\\beta_0} + \\hat{\\beta_1}X_n))^2\n\\end{equation}\n\n%The least squares approach can then be used to choose $\\hat{\\beta_0}$ and $\\hat{\\beta_1}$ to minimize the RSS (2.5).\n%The minimization is written as:\n\nThe least squares coefficients can then be estimated from the minimizers of RSS defined in equation in (2.4) and (2.5).\n\\begin{equation}\n\\hat{\\beta_1} = \\dfrac{\\sum\\limits_{i=1}^n(x_i - \\bar{x})(y_i - \\bar{y})}{\\sum\\limits_{i=1}^n(x_i - \\bar{x})^2}\n\\end{equation}\n\n\\begin{equation}\n\\hat{\\beta_0} = \\bar{y} -\\hat{\\beta_1}\\bar{x}\n\\end{equation}\n\n%n (3.4) $\\hat{y} \\equiv \\dfrac{1}{n}\\sum\\limits_{i=1}^ny_i$ and %$\\hat{x}\\equiv \\dfrac{1}{n}\\sum\\limits_{i=1}^nx_i$ are the ample eans and the function is used to define the least squares coefficient estimates for a simple linear regression \n\n\n\\subsection{Lab 3.6.2 - Simple Linear Regression}\n\nIn Lab 3.6.2 the data set \\emph{Boston} is given. It consists of records from about 506 neighborhoods around Boston. The task is to predict \\emph{medv} (median house value) via the predictor \\emph{lstat} (percent of households with low socioeconomic status).\n\nThe data is initially prepared before the linear regression can be performed. This is shown in listing \\ref{lst:lin_reg_prep}. The data is loaded and then the \\emph{lstat} data is added to \\emph{boston\\_X\\_train} and the \\emph{medv} data is added to \\emph{boston\\_Y\\_train}.\n\n\\begin{lstlisting}[caption={Data preparation for linear regression}, label=lst:lin_reg_prep, mathescape=true]\nboston = datasets.load_boston()\n\n#Extract 'lstat'-\nboston_X_train = boston.data[:, np.newaxis, 12]\n\n#Extract 'medv'\nboston_Y_train = boston.target\n\\end{lstlisting}\n\nTo perform the linear regression the library sklearn is used in python. In listing \\ref{lst:lin_reg} it is shown how a linear regression model is fitted to the training data \\emph{boston\\_X\\_train} and the \\emph{boston\\_Y\\_train}.\n\n\\begin{lstlisting}[caption={Python linear regression function}, label=lst:lin_reg, mathescape=true]\nlm = linear_model.LinearRegression()\nlm.fit(boston_X_train, boston_Y_train)\n\\end{lstlisting}\n\n\\FloatBarrier\n\nThe code in listing \\ref{lst:lin_reg_plot} is used to plot \\emph{medv} and \\emph{lstat} along with the least squares regression line. In line 1 the test data is plotted to see how it corresponds to the least squares regression line. To plot the least squares regression line the command 'plot' is used. This is seen in line 2 where 'boston\\_X\\_test' is the test data which consist of the \\emph{lstat} data. The result is plotted in Figure \\ref{fig:lin_reg_plot}. The plots shows that the relation between \\emph{lstat} and \\emph{medv} is somewhat non-linear. \n\n\\begin{lstlisting}[caption={Python plotting of linear regression function}, label=lst:lin_reg_plot, mathescape=true]\nplt.scatter(boston_X_test, boston_Y_test,  color='black')\nplt.plot(boston_X_test, lm.predict(boston_X_test), color='blue',\nlinewidth=3)\n\nplt.xticks(())\nplt.yticks(())\n\nplt.show()\n\\end{lstlisting}\n\n\\myFigure{lin_reg_plot.PNG}{Linear regression of \\emph{medv} and \\emph{lstat}}{fig:lin_reg_plot}{0.5}\n\n\\section{Multiple Linear Regression}\n\nWhen using simple linear regression only one predictor is used. But often more than one predictor is available. Instead multiple linear regression uses two or more predictors to predict the response variable Y. The relationship between the predictor variable and response variable with simple linear regression can be described as a one-to-one, while multiple linear regression is a many-to-one relationship, as illustrated in Figure \\ref{fig:relation}.\n\n\\myFigure{relation.PNG}{Relationship between predictor variables \"P.V\" and response variables \"R.V\" in Simple- and Multiple Linear Regression}{fig:relation}{0.8}\n\n\\FloatBarrier\nAs specified in Lab 3.6.2, the predictors are called X, while Y is the response. This means for multiple linear regression, that the relationship between X and Y is expressed as:\n\n\\begin{equation}\nY \\approx \\beta_0 + \\beta_1 * X_1 + \\beta_2 * X_2 + … + \\beta_k * X_k\n\\end{equation}\n\nSimilar to simple linear regression, the regression coefficients are estimated using the least squares approach so that $\\beta_0$, $\\beta_1$,...$\\beta_p$ is chosen to minimize the RSS.\n\n\\subsection{Lab 3.6.3 - Multiple Linear Regression}\n\nIn this exercise multiple linear regression is used. In Listing \\ref{lst:mul_lin_reg} all 13 predictors in the Boston data set is used for performing multiple linear regression.\n\n\\begin{lstlisting}[caption={Linear regression of multiple predictors}, label=lst:mul_lin_reg, mathescape=true]\nboston_X_train = boston.data\nboston_Y_train = boston.target\n\nlm = linear_model.LinearRegression()\nlm.fit(boston_X_train, boston_Y_train)\n\\end{lstlisting}\n\n%In listing \\ref{lst:print} the calculated coefficients, intercept and variance for the linear regression model is printed.\n\n%\\begin{lstlisting}[caption={Printing regression overview}, label=lst:print, mathescape=true]\n%print(\"Coefficients:\")\n%print(lm.coef_)\n%print(\"Intercept: \")\n%print(lm.intercept_)\n%print(\"Variance score: %.2f\" % lm.score(boston_X_test, boston_Y_test))\n%\\end{lstlisting}\n\nThe printed output is shown in figure \\ref{fig:multiOutput}. The output first shows the estimated coefficients for the linear regression model. The first value -0.1072 is $\\beta_1$ and is multiplied with the predictor \\emph{crim}. The next value 0.0464 is $\\beta_2$ and is multiplied with the predictors \\emph{zn}. In total there are 13 coefficients, one for each predictor.\n\nFurthermore the intercept value $\\beta_0$ is printed. This is the value of the interception with the y-axis. Lastly multiple $R^2$ is printed. The $R^2$ of the simple linear regression was only calculated to 0.544, while for the multiple linear regression model including all 13 predictors the $R^2$ coefficient was improved to 0.74. This indicates that the model is improved using multiple linear regression.\n\n\\myFigure{MultiLinRegOutput.PNG}{Resulting coefficients, intercept value and multiple $R^2$ for the multiple linear regression model}{fig:multiOutput}{0.8}\n\n\n", "meta": {"hexsha": "fa1303aea20f52202d8723aff470d05ff7889c34", "size": 9690, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/chapter/linear_regression.tex", "max_stars_repo_name": "Rotvig/F17Q4---Decision-Support-Systems", "max_stars_repo_head_hexsha": "62c3bb41a8fb4df75f4f038dea7af521cddafa4a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Report/chapter/linear_regression.tex", "max_issues_repo_name": "Rotvig/F17Q4---Decision-Support-Systems", "max_issues_repo_head_hexsha": "62c3bb41a8fb4df75f4f038dea7af521cddafa4a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/chapter/linear_regression.tex", "max_forks_repo_name": "Rotvig/F17Q4---Decision-Support-Systems", "max_forks_repo_head_hexsha": "62c3bb41a8fb4df75f4f038dea7af521cddafa4a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.3333333333, "max_line_length": 558, "alphanum_fraction": 0.7628482972, "num_tokens": 2577, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7049153136376246}}
{"text": "\\documentclass{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\n\\title{Solution to the Monty Hall Problem with the Bayesian Theorem}\n\\date{\\today}\n\\author{Lukas Prokop}\n\n\\newcommand{\\Pc}[2]{P(#1\\,|\\,#2)}\n\n\\begin{document}\n\\maketitle\n\n\\section{The problem}\n%\nIn a quizshow, the candidate has to select one of three doors.\nBehind two doors there is a goat (an undesirable prize).\nBehind the one door there is a car.\nAt the beginning the candidate tries to guess the door with the car.\nAfterwards the moderator Monty Hall opens one of the doors with a goat which is not the candidate's door.\nSo two doors are left where one of them is the one, the candidate has chosen.\nMonty asks the candidate whether he would like to change his mind; he is\nfree to select the other door.\n\nIn general, is it better to change the mind, stick to the first selection\nor doesn't it matter?\n\n\\section{Bayesian approach}\n%\nAssumption (one of three cases): The candidate selects door \\#1.\n\\begin{center}\n  \\begin{tabular}{cc}\n    $D_1$ & Car behind door \\#1 \\\\\n    $D_2$ & Car behind door \\#2 \\\\\n    $D_3$ & Car behind door \\#3\n  \\end{tabular}\n\\end{center}\n\n\\noindent\nWe define the corresponding probabilities:\n\\[\n    P(D_1) = \\frac13  \\qquad\n    P(D_2) = \\frac13  \\qquad\n    P(D_3) = \\frac13\n\\]\n\nWe somehow have to model the behavior of the moderator.\nTherefore we introduce a hypothesis $H$ that he opens door \\#3.\nThe probability that he selects door \\#3 in favor of door \\#2\nis $\\frac12$, because \\#1 is already taken by the candidate:\n\\[\n    P(H) = \\frac12\n\\]\n\n\\noindent\nFurthermore,\n\\[\n    \\Pc{H}{D_1} = \\frac12  \\qquad\n    \\Pc{H}{D_2} = 1        \\qquad\n    \\Pc{H}{D_3} = 0\n\\]\n\nSo the probability that he opens door \\#3 under the condition that door \\#1\ncontains the car is $\\frac12$ (moderator will select door \\#2 or door \\#1\nbecause \\#1 is candidate's door). The probability is $1$ if the car is in\ndoor \\#2 (door \\#1 is candidate's door and \\#2 contains the car).\nAnd if the car is in door \\#3, the moderator will never show door \\#3.\n\nWe can spot some asymmetry here. This point is evidently responsible why\nan intuition like ``it does not matter'' might be wrong.\n\nSo we will use the Bayes' Theorem:\n\\[\n    \\underbrace{\\Pc{A}{B}}_{\\text{posterior probability}} =\n      \\frac{\\overbrace{\\Pc{B}{A}}^{\\text{Likelihood}} \\cdot\n        \\overbrace{P(A)}^{\\text{priori probability}}\n      }{\n        \\underbrace{P(B)}_{\\text{expectedness}}\n      }\n\\]\n\nThe important question is: Under the assumption that we have selected door \\#1\n(our first assumption) and Monty opens door \\#3 (our hypothesis or\n``expectedness''), what is the probability that the car is behind door \\#1\ncompared to door \\#2?\n\\[\n    \\Pc{D_1}{H} = \\frac{\\Pc{H}{D_1} \\cdot P(D_1)}{P(H)}\n        = \\frac{\\frac12 \\cdot \\frac13}{\\frac12} = \\frac13\n\\] \\[\n    \\Pc{D_2}{H} = \\frac{1 \\cdot \\frac13}{\\frac12} = \\frac23\n\\]\n\nSo apparently, the probability that door \\#2 contains the car is higher than\nfor door \\#1. Or in other words: in this case the candidate should prefer\nto change his mind.\n\nNow we have to evaluate this for other hypotheses (moderator opens door \\#2)\nand other candidate selections (door \\#2 and door \\#3). The approach is the\nsame and not carried out here. But the conclusion keeps the same in all cases:\nBeing open to change your mind will make you probabilistically win the car.\n\n\\end{document}\n", "meta": {"hexsha": "7055123be69eaf3834d0a4075bdf6831df471095", "size": 3369, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pub/bayes_monty_hall.tex", "max_stars_repo_name": "meisterluk/tug_lp", "max_stars_repo_head_hexsha": "eaf7e0a9bfaa91400248f7231c6891531ee71275", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pub/bayes_monty_hall.tex", "max_issues_repo_name": "meisterluk/tug_lp", "max_issues_repo_head_hexsha": "eaf7e0a9bfaa91400248f7231c6891531ee71275", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pub/bayes_monty_hall.tex", "max_forks_repo_name": "meisterluk/tug_lp", "max_forks_repo_head_hexsha": "eaf7e0a9bfaa91400248f7231c6891531ee71275", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3942307692, "max_line_length": 105, "alphanum_fraction": 0.697239537, "num_tokens": 1014, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.7049153109654185}}
{"text": "\\documentclass[11pt, oneside]{article}\n\n\\usepackage{../../shared/preamble}\n\\addbibresource{../../shared/references.bib}\n\n\\usepackage{../sets/sets}\n\\usepackage{../groups/groups}\n\\usepackage{../topological-spaces/topological-spaces}\n\\usepackage{../real-numbers/real-numbers}\n\\usepackage{vector-spaces}\n\n\\title{Vector Spaces}\n\\author{Arthur Ryman, {\\tt arthur.ryman@gmail.com}}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\nThis article contains Z Notation type declarations for vector spaces and some related objects.\nIt has been type checked by \\fuzz.\n\\end{abstract}\n\n\\section{Real Vector Spaces}\n\nReal vector spaces are multidimensional generalizations of real numbers.\nThey are the objects studied in linear algebra and are foundational to differential geometry.\n\nIn the following let $\\genT$ denote a set of elements which we'll refer to as {\\em vectors}\nand let $A$ denote an Abelian group over the vectors in which the binary operation is denoted as addition.\nLet $v$ and $w$ denote vectors and\nand let $x$ and $y$ denote real numbers.\n\n\\subsection{Notation for Vector Addition, Zero, and Negative: \\zcmd{addV}, \\zcmd{zeroV}, and \\zcmd{negV}}\n\nLet $v \\addV w$ denote vector addition,\nlet $\\zeroV$ denote the zero vector,\nand let $\\negV v$ denote the negative vector.\n\n\\subsection{Real Scalar Multiplication: \\zcmd{mulS}, \\zcmd{timesS}, and $RealScalarMultiplication$}\n\nA {\\em real scalar multiplication} operation on the vectors is an operation $smul$ \nthat maps the pair $(x, v)$ to another vector, typically denoted $x \\mulS v$ or $x \\timesS y$,\nsuch that\nmultiplication by 0 maps all vectors to the group identity element,\nmultiplication by 1 maps each vector to itself,\nmultiplication preserves group addition, \nand multiplication distributes over both real and group addition.\n\nLet $RealScalarMultiplication$ denote this situation.\n\n\\begin{schema}{RealScalarMultiplication}[\\genT]\nA: \\abgroup \\genT \\\\\nsmul: \\R \\cross \\genT \\fun \\genT\n\\where\n\\LET (\\_ \\addV \\_) == A; \\\\\n\\t1\t\\zeroV == identity\\_element~A; \\\\\n\\t1\t(\\_ \\mulS \\_) == smul @ \\\\\n\\t2\t\t\\forall x, y: \\R; v, w: \\genT @ \\\\\n\\t3\t\t\t\\zeroR \\mulS v = \\zeroV \\land \\\\\n\\t3\t\t\t\\oneR \\mulS v = v \\land \\\\\n\\t3\t\t\t(x \\mulR y) \\mulS v = x \\mulS (y \\mulS v) \\land \\\\\n\\t3\t\t\t(x \\addR y) \\mulS v = x \\mulS v \\addV y \\mulS v \\land \\\\\n\\t3\t\t\tx \\mulS (v \\addV w) = x \\mulS v \\addV x \\mulS w\n\\end{schema}\n\n\\begin{itemize}\n\t\\item Multiplying by $\\zeroR$ gives the zero vector.\n\t\\item Multiplying by $\\oneR$ gives the same vector.\n\t\\item Scalar multiplication is associative.\n\t\\item Scalar addition distributes over scalar multiplication.\n\t\\item Vector addition distributes over scalar multiplication.\n\\end{itemize}\n\n\\subsection{The Set of All Real Vector Spaces: \\zcmd{vecR}}\n\nA {\\em real vector space} is a pair $(A, smul)$ where $A$ is an Abelian group and $smul$\nis a real scalar multiplication on the elements of $A$.\nThe elements of $A$ are referred to as \\textit{vectors}.\n\nLet $\\vecR \\genT$ denote the set of all real vector spaces over $\\genT$,\n\n\\begin{zed}\n\\vecR \\genT == \\{~ RealScalarMultiplication[\\genT] @ (A, smul) ~\\}\n\\end{zed}\n\n\\subsection{Real Linear Transformations: $RealLinearTransformation$}\n\nLet $V_1$ and $V_2$ be real vector spaces and let $f$ be a homomorphism of the underlying\nAbelian groups.\nThe map $f$ is said to be a {\\em linear transformation} if $f$ maps scalar multiples of vectors to the\nscalar multiple of the mapped vectors.\n\nLet $RealLinearTransformation$ denote this situation.\n\n\\begin{schema}{RealLinearTransformation}[\\genT, \\genU]\nf: \\genT \\fun \\genU \\\\\nV_1: \\vecR \\genT \\\\\nV_2: \\vecR \\genU\n\\where\n\\LET A_1 == first~V_1; (\\_ \\mulS \\_) == second~V_1; \\\\\n\\t1\tA_2 == first~V_2; (\\_ \\timesS \\_) == second~V_2 @ \\\\\n\\t2\t\tf \\in \\homGroup(A_1, A_2) \\land \\\\\n\\t2\t\t(\\forall x: \\R; v: \\genT @ \\\\\n\\t3\t\t\tf(x \\mulS v) = x \\timesS(f~v))\n\\end{schema}\n\n\\begin{itemize}\n\\item The vector space $V_1$ has Abelian group $A_1$ and scalar multiplication $(\\_ \\mulS \\_)$.\n\\item The vector space $V_2$ has Abelian group $A_2$ and scalar multiplication $(\\_ \\timesS \\_)$.\n\\item The map $f$ is a homomorphism of the underlying Abelian groups.\n\\item The map $f$ maps scalar multiples of vectors in $\\genT$ to scalar multiples of the mapped vectors in $\\genU$.\n\\end{itemize}\n\n\\subsection{The Set of All Real Linear Transformations: \\zcmd{homVecR}}\n\nLet $V_1$ and $V_2$ be real vector spaces.\nLet $\\homVecR(V_1, V_2)$ denote the set of all linear transformations from $V_1$ to $V_2$.\nA linear transformation is also referred to as a \\textit{homomorphism} of vector spaces.\n\n\\begin{zed}\n\\homVecR[\\genT, \\genU] == \\\\\n\\t1\t(\\lambda V_1: \\vecR \\genT; V_2: \\vecR \\genU @ \\\\\n\\t2\t\t\\{~ f: \\genT \\fun \\genU | \\\\\n\\t3\t\t\tRealLinearTransformation[\\genT, \\genU] ~\\})\n\\end{zed}\n\n\\section{Real $n$-tuples}\n\nThe preceding section described real vector spaces abstractly.\nIn this section we define a family of finite-dimensional real vector spaces\nwhose elements are finite sequences of real numbers, also referred to as \\textit{real tuples}.\n\n\\subsection{The Set of All Finite Sequences of Real Numbers: \\zcmd{Rinf}}\n\nLet $n$ be a natural number.\nA finite sequence of $n$ real numbers is called a {\\it real $n$-tuple}.\nLet $\\Rinf$ denote the set of all real $n$-tuples for any $n$.\n\n\\begin{zed}\n\t\\Rinf == \\seq \\R\n\\end{zed}\n\n\\subsection{The Component Projection Function: \\zcmd{piRinf}}\n\nThe real numbers that comprise an $n$-tuple are called its \\textit{components}.\nLet $v$ be a real $n$-tuple and let $i$ be an integer where $1 \\le i \\le n$.\nThe real number $v(i)$ is the $i$-th component of $v$.\nLet $\\piRinf(i)$ be the projection function that maps an $n$-tuple $v$ to its $i$-th component $v(i)$.\n\n\\begin{axdef}\n\t\\piRinf: \\nat_1 \\fun \\Rinf \\pfun \\R\n\\where\n\t\\forall i: \\nat_1 @ \\\\\n\t\\t1\t\\piRinf(i) = (\\lambda v: \\Rinf | i \\in \\dom v @ v(i))\n\\end{axdef}\n\n\\subsection{The Set of All Well-Dimensioned Subsets of $\\Rinf$: \\zcmd{DeltaRinf}}\n\nA non-empty subset of $\\Rinf$ is said to be \\textit{well-dimensioned} if each of its elements has the same number\nof components.\nLet $\\DeltaRinf$ denote the family of all well-dimensioned subsets of $\\Rinf$ .\n\n\\begin{axdef}\n\t\\DeltaRinf: \\family~\\Rinf\n\\where\n\t\\DeltaRinf = \\{~ S: \\power_1 \\Rinf | \\forall v, w: S @ \\# v = \\# w ~\\}\n\\end{axdef}\n\n\\subsection{The Dimension of a Well-Dimensioned Set of Tuples: \\zcmd{dimRinf}}\n\nLet $S \\in \\DeltaRinf$ be a well-dimensioned set of tuples.\nThe number of components of each tuple in $S$ is called its \\textit{dimension}.\nLet $\\dimRinf(S)$ denote the dimension of $S$.\n\n\\begin{axdef}\n\\dimRinf: \\DeltaRinf \\fun \\nat\n\\where\n%\t\\forall n: \\nat @ \\forall U: \\power(\\Rtup(n)) @ \\\\\n%\t\\t1\t\\dimRinf(U) = n\n\\forall S: \\DeltaRinf @ \\\\\n\\t1\t\\dimRinf S = (\\mu v: S @ \\# v)\n\\end{axdef}\n\n\\subsection{The Set of All Compatible Pairs of Tuples: \\zcmd{RinfDelta}}\n\nThe pair of real tuples $(v, w)$ is said to be \\textit{compatible} if each member has the same number of components.\nLet $\\RinfDelta$ denote the set of all compatible pairs of real tuples.\nIf the pair $(v, w)$ is compatible then $v$ and $w$ are said to be compatible with each other.\n\n\\begin{axdef}\n\t\\RinfDelta: \\Rinf \\rel \\Rinf\n\\where\n\t\\RinfDelta = \\{~ v, w: \\Rinf | \\# v = \\# w ~\\}\n\\end{axdef}\n\n\\subsection{Addition of Compatible Tuples: \\zcmd{addRinf}}\n\nLet $v$ and $w$ be $n$-tuples.\nVector addition of $v$ and $w$ is the $n$-tuple $v \\addRinf w$ defined by component-wise addition.\n\n\\begin{axdef}\n\t\\_ \\addRinf \\_: \\RinfDelta \\fun \\Rinf\n\\where\n\t\\langle \\rangle \\addRinf \\langle \\rangle = \\langle \\rangle\n\\also\n\\forall n: \\nat_1; v, w: \\Rinf | n = \\#v = \\# w @ \\\\\n\\t1\tv \\addRinf w = (\\lambda i: 1 \\upto n @ v~i \\addR w~i)\n\\end{axdef}\n\n\\subsection{Subtraction of Compatible Tuples: \\zcmd{subRinf}}\n\nVector subtraction is defined similarly.\n\n\\begin{axdef}\n\t\\_ \\subRinf \\_: \\RinfDelta \\fun \\Rinf\n\\where\n\t\\langle \\rangle \\subRinf \\langle \\rangle = \\langle \\rangle\n\\also\n\\forall n: \\nat_1; v, w: \\Rinf | n = \\#v = \\# w @ \\\\\n\\t1\tv \\subRinf w = (\\lambda i: 1 \\upto n @ v~i \\subR w~i)\n\\end{axdef}\n\n\\subsection{The Negative of a Tuple: \\zcmd{negRinf}}\n\nLet $\\negRinf v$ denote the negative of $v$.\n\n\\begin{axdef}\n\\negRinf: \\Rinf \\fun \\Rinf\n\\where\n\\negRinf \\langle \\rangle = \\langle \\rangle\n\\also\n\\forall n: \\nat_1; v: \\Rinf | n = \\# v @ \\\\\n\\t1\t\\negRinf v = (\\lambda i: 1 \\upto n @ \\negR(v~i))\n\\end{axdef}\n\n\\subsection{Scalar Multiplication of a Tuple: \\zcmd{smulRinf}}\n\nLet $v$ be an $n$-tuple and let $c$ be a real number.\nScalar multiplication of $v$ by $c$ is the $n$-tuple $c \\smulRinf v$ defined by component-wise multiplication.\n\n\\begin{axdef}\n\\_ \\smulRinf \\_ : \\R \\cross \\Rinf \\fun \\Rinf \n\\where\n\\forall c: \\R @ \\\\\n\\t1\tc \\smulRinf \\langle \\rangle = \\langle \\rangle\n\\also\n\\forall c: \\R; n: \\nat_1; v: \\Rinf | n = \\# v @ \\\\\n\\t1\tc \\smulRinf v = (\\lambda i: 1 \\upto n @ c \\mulR (v~i))\n\\end{axdef}\n\n\\begin{remark}\nScalar multiplication is associative in the sense that $(a \\mulR b) \\smulRinf v = a \\smulRinf (b \\smulRinf v)$\n\n\\begin{zed}\n\t\\forall a, b: \\R; v: \\Rinf @ \\\\\n\t\\t1\t(a \\mulR b) \\smulRinf v = a \\smulRinf (b \\smulRinf v)\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{The Set of All Real $n$-tuples: \\zcmd{Rtup}}\n\nLet $\\Rtup(n)$ denote $\\R^n$, the set of all $n$-tuples for some given $n$.\n\\begin{axdef}\n\t\\Rtup: \\nat \\fun \\power \\Rinf\n\\where\n\t\\forall n: \\nat @ \\\\\n\t\\t1\t\\Rtup(n) = \\{~ v: \\Rinf | \\# v = n ~\\}\n\\end{axdef}\n\n\\begin{remark}\n\n\\begin{zed}\n\t\\Rinf = \\bigcup \\{~ n: \\nat @ \\Rtup(n) ~\\}\n\\end{zed}\n\n\\end{remark}\n\n\\begin{remark}\nThe subset $\\Rtup(n)$ is well-dimensioned.\n\n\\begin{zed}\n\t\\forall n: \\nat @ \\\\\n\t\\t1\t\\Rtup(n) \\in \\DeltaRinf\n\\end{zed}\n\n\\end{remark}\n\n\\begin{remark}\nThe dimension of $\\Rtup(n)$ is $n$.\n\n\\begin{zed}\n\t\\forall n: \\nat @ \\\\\n\t\\t1\t\\dimRinf(\\Rtup(n)) = n\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{Addition of $n$-tuples: $addRtup$}\n\nLet $addRtup(n)$ denote the restriction of addition to $\\Rtup(n)$.\n\n\\begin{zed}\naddRtup == \\\\\n\\t1\t(\\lambda n: \\nat @ \\\\\n\\t2\t\t(\\lambda v, w: \\Rtup(n) @ v \\addRinf w))\n\\end{zed}\n\n\\begin{example}\nThe binary operation $addRtup(n)$ defines an Abelian group over $\\Rtup(n)$.\n\n\\begin{zed}\n\\forall n: \\nat @ \\\\\n\\t1\taddRtup(n) \\in \\abgroup(\\Rtup(n))\n\\end{zed}\n\n\\end{example}\n\n\\subsection{Subtraction of $n$-tuples: $subRtup$}\n\nLet $subRtup(n)$ denote the restriction of subtraction to $\\Rtup(n)$.\n\n\\begin{zed}\nsubRtup == \\\\\n\\t1\t(\\lambda n: \\nat @ \\\\\n\\t2\t\t(\\lambda v, w: \\Rtup(n) @ v \\subRinf w))\n\\end{zed}\n\n\\subsection{The Negative of an $n$-tuple: $negRtup$}\n\nLet $negRtup(n)$ denote the restriction of the negative operation to $\\Rtup(n)$.\n\n\\begin{zed}\nnegRtup == \\\\\n\\t1\t(\\lambda n: \\nat @ \\\\\n\\t2\t\t(\\lambda v: \\Rtup(n) @ \\negRinf v))\n\\end{zed}\n\n\\begin{remark}\nThe operation $negRtup(n)$ is the inverse operation of the Abelian group $addRtup(n)$.\n\n\\begin{zed}\n\\forall n: \\nat @ \\\\\n\\t1\tnegRtup(n) = inverse\\_operation(addRtup(n))\n\\end{zed}\n\n\\end{remark}\n\n\n\\subsection{The Zero Real $n$-tuple: \\zcmd{zeroRtup}}\n\nLet $\\zeroRtup(n)$ denote the $n$-tuple consisting of all zeroes.\n\n\\begin{axdef}\n\t\\zeroRtup: \\nat \\fun \\Rinf\n\\where\n\t\\zeroRtup(0) = \\langle \\rangle\n\\also\n\t\\forall n: \\nat_1 @ \\\\\n\t\\t1\t\\zeroRtup(n) = (\\lambda i: 1 \\upto n @ \\zeroR)\n\\end{axdef}\n\n\\begin{remark}\nEvery component of $\\zeroRtup(n)$ is $\\zeroR$.\n\n\\begin{zed}\n\\forall n: \\nat @ \\\\\n\\t1\t\\forall i: 1 \\upto n @ \\\\\n\\t2\t(\\piRinf i)(\\zeroRtup n) = \\zeroR\n\\end{zed}\n\n\\end{remark}\n\n\\begin{remark}\nThe tuple $\\zeroRtup(n)$ is in $\\Rtup(n)$.\n\n\\begin{zed}\n\\forall n: \\nat @ \\\\\n\\t1\t\\zeroRtup(n) \\in \\Rtup(n)\n\\end{zed}\n\n\\end{remark}\n\n\\begin{remark}\nThe tuple $\\zeroRtup(n)$ is the identity element of the Abelian group $addRtup(n)$.\n\n\\begin{zed}\n\\forall n: \\nat @ \\\\\n\\t1\t\\zeroRtup(n) = identity\\_element(addRtup(n))\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{Scalar Multiplication of an $n$-tuple: $smulRtup$}\n\nLet $smulRtup(n)$ denote scalar multiplication restricted to $\\Rtup(n)$.\n\n\\begin{zed}\nsmulRtup == \\\\\n\\t1\t(\\lambda n: \\nat @ \\\\\n\\t2\t\t(\\lambda c: \\R; v: \\Rtup(n) @ c \\smulRinf v))\n\\end{zed}\n\n\\subsection{The Real Vector Space of $n$-tuples: $vecRtup$}\n\nLet $vecRtup(n)$ denote the real vector space of $n$-tuples.\n\n\\begin{zed}\nvecRtup == \\\\\n\\t1\t(\\lambda n: \\nat @ (addRtup(n), smulRtup(n)))\n\\end{zed}\n\n\\begin{remark}\nThe pair $vecRtup(n)$ defines a vector space over $\\Rtup(n)$.\n\n\\begin{zed}\n\\forall n: \\nat @ \\\\\n\\t1\tvecRtup(n) \\in \\vecR(\\Rtup(n))\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{Linear Transformations of $n$-tuples: \\zcmd{linRtup}}\n\nDefine $\\linRtup(n,m)$ to be the set of all linear transformations from $\\R^n$ to $\\R^m$.\n\\begin{axdef}\n\t\\linRtup: \\nat \\cross \\nat \\fun \\power(\\Rinf \\pfun \\Rinf)\n\\where\n\t\\forall n,m: \\nat @ \\\\\n\t\\t1\t\\linRtup(n,m) = \\homVecR(vecRtup(n), vecRtup(m))\n\\end{axdef}\n\n\\subsection{The Identity Transformation of $n$-tuples: \\zcmd{idRtup}}\n\nLet $\\idRtup(n)$ denote the identity function on $\\Rtup(n)$.\n\n\\begin{axdef}\n\t\\idRtup: \\nat \\fun \\Rinf \\pfun \\Rinf\n\\where\n\t\\forall n: \\nat @ \\\\\n\t\\t1\t\\idRtup(n) = \\id(\\Rtup(n))\n\\end{axdef}\n\n\\begin{remark}\nThe function $\\idRtup(n)$ is a linear transformation.\n\n\\begin{zed}\n\t\\forall n: \\nat @ \\\\\n\t\\t1\t\\idRtup(n) \\in \\linRtup(n, n)\n\\end{zed}\n\n\\end{remark}\n\n\\section{The Metric Topology on Real $n$-tuples}\n\n\\subsection{The Dot Product of Tuples: \\zcmd{dotRinf}}\n\nThe {\\it inner} or {\\it dot} product of $n$-tuples $v$ and $w$ is the real number $v \\dotRinf w$ \ndefined by the sum of the component-wise products.\n\n\\begin{axdef}\n\t\\_ \\dotRinf \\_ : \\RinfDelta \\fun \\R\n\\where\n\t\\langle \\rangle \\dotRinf \\langle \\rangle = \\zeroR\n\\also\n\t\\forall x, y: \\R; v, w: \\Rinf | \\# v = \\# w @ \\\\\n\t\\t1\t(\\langle x \\rangle \\cat v) \\dotRinf (\\langle y \\rangle \\cat w) = x \\mulR y \\addR v \\dotRinf w\n\\end{axdef}\n\nEach $\\Rtup(n)$ is a real inner product space under the operation of dot product defined above.\n\n\\subsection{The Norm of a Tuple: \\zcmd{normRinf}}\n\nThe norm $\\norm{v}$ of the $n$-tuple $v$ is the positive square root of its dot product with itself.\n$$\n\t\\norm{v} = \\sqrt{v \\dotRinf v}\n$$\n\nDefine $\\normRinf(v)$ to be $\\norm{v}$.\n\\begin{axdef}\n\t\\normRinf: \\Rinf \\fun \\R\n\\where\n\t\\forall v: \\Rinf @ \\\\\n\t\\t1\t\\normRinf(v) = \\sqrtR(v \\dotRinf v)\n\\end{axdef}\n\nThe concepts of continuity, limits, and differentiability extend to functions between normed vector spaces such as $\\R^n$.\n\n\\subsection{The Open Ball at a Tuple: \\zcmd{ballRinf}}\n\nLet $\\ballRinf(v,r)$ denote the \\textit{open ball} in $\\Rtup(n)$ of radius $r  \\in \\Rpos$ centred at $v \\in \\Rtup(n)$.\n\n\\begin{axdef}\n\\ballRinf: \\Rinf \\cross \\Rpos \\fun \\power \\Rinf\n\\where\n\\forall v: \\Rinf; r: \\Rpos @ \\\\\n\\t1\t\\LET n == \\# v @ \\\\\n\\t2\t\t\\ballRinf(v, r) = \\{~ w: \\Rtup(n) | \\normRinf(v \\subRinf w) \\ltR r ~\\}\n\\end{axdef}\n\n\\subsection{The Set of All Open Balls at an $n$-tuple: \\zcmd{ballsRtup}}\n\nLet $\\ballsRtup(n)$ denote the family of all open balls in $\\Rtup(n)$.\n\n\\begin{axdef}\n\t\\ballsRtup: \\nat \\fun \\family~\\Rinf\n\\where\n\t\\forall n: \\nat @ \\\\\n\t\\t1\t\\ballsRtup(n) =  \\{~ v: \\Rtup(n); r: \\Rpos @ \\ballRinf(v,r) ~\\}\n\\end{axdef}\n\n\\begin{remark}\nThe set of all open balls in $\\Rtup(n)$ is a family of sets in $\\Rtup(n)$.\n\n\\begin{zed}\n\\forall n: \\nat @ \\\\\n\\t1\t\\ballsRtup(n) \\in \\family(\\Rtup(n))\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{The Usual Topology on $n$-tuples: \\zcmd{tauRtup}}\n\nThe \\textit{usual topology} on $\\Rtup(n)$ is the topology generated by the open balls in $\\Rtup(n)$.\nLet $\\tauRtup(n)$ denote the usual topology on $\\Rtup(n)$.\n\n\\begin{axdef}\n\t\\tauRtup: \\nat \\fun \\family~\\Rinf\n\\where\n\t\\forall n: \\nat @ \\\\\n\t\\t1\t\\tauRtup(n) = topGen[\\Rtup(n)] (\\ballsRtup(n))\n\\end{axdef}\n\n\\begin{remark}\n\nIf $n \\in \\nat$ then $\\tauRtup(n)$ is a topology on $\\Rtup(n)$.\n\n\\begin{zed}\n\t\\forall n: \\nat @ \\tauRtup(n) \\in top[\\Rtup(n)]\n\\end{zed}\n\\end{remark}\n\n\\subsection{The Set of All Neighbourhoods of a Tuple: \\zcmd{neighRinf}}\n\nLet $v \\in \\Rtup(n)$. \nAn open set $U$ in the usual topology $\\tauRtup(n)$ that contains $v$\nis called a \\textit{neighbourhood} of $v$.\nLet $\\neighRinf(v)$ denote the set of all neighbourhoods of $x$.\n\n\\begin{axdef}\n\\neighRinf: \\Rinf \\fun \\family~\\Rinf\n\\where\n\\forall n: \\nat; v: \\Rinf | n = \\#v @ \\\\\n\\t1\t\\neighRinf(v) = \\{~ U: \\tauRtup(n) | v \\in U ~\\}\n\\end{axdef}\n\n\\begin{remark}\n\nThe set of all neighbourhoods of $v \\in \\Rtup(n)$ is a family of sets in $\\Rtup(n)$.\n\n\\begin{zed}\n\\forall n: \\nat; v: \\Rinf | n = \\#v @ \\\\\n\\t1\t\\neighRinf(v) \\in \\family(\\Rtup(n))\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{The Topological Space of $n$-tuples: \\zcmd{tsRtup}}\n\nLet $\\tsRtup(n)$ denote the topological space defined by the usual topology on $\\Rtup(n)$.\n\n\\begin{axdef}\n\t\\tsRtup: \\nat \\fun topSpaces[\\Rinf]\n\\where\n\t\\forall n: \\nat @ \\\\\n\t\\t1\t\\tsRtup(n) = (\\Rtup(n), \\tauRtup(n))\n\\end{axdef}\n\n\\section{Continuity}\n\n\\subsection{Real-Valued Functions That Are Continuous on the Set of All $n$-tuples: \\zcmd{CzeroRtup}}\n\nA function $f \\in \\R^n \\fun \\R$ is said to be \\textit{continuous} if it is continuous with respect to the usual topologies\non $\\R^n$ and $\\R$.\nLet $\\CzeroRtup(n)$ denote the set of these continuous functions.\n\n\\begin{axdef}\n\t\\CzeroRtup: \\nat \\fun \\power(\\Rinf \\pfun \\R)\n\\where\n\t\\forall n: \\nat @ \\\\\n\t\\t1\t\\CzeroRtup(n) = \\CzeroTT(\\tsRtup(n), \\Rtau)\n\\end{axdef}\n\n\\subsection{Real-Valued Functions That Are Continuous on a Subset of $n$-tuples: \\zcmd{CzeroSubsetRtup}}\n\nLet $U$ be a subset of $\\R^n$.\nA function $f \\in U \\fun \\R$ is said to be \\textit{continuous on} $U$\nif it is continuous with respect to the topology induced on $U$.\nLet $\\CzeroSubsetRtup(U)$ denote the set of these continuous functions.\n\n\\begin{axdef}\n\t\\CzeroSubsetRtup: \\DeltaRinf \\fun \\power(\\Rinf \\pfun \\R)\n\\where\n\t\\forall U: \\DeltaRinf @ \\\\\n\t\\t1\t\\LET n == \\dimRinf U @ \\\\\n\t\\t2\t\t\\CzeroSubsetRtup(U) = \\CzeroTT(\\tsRtup(n) \\inducedTopSp U, \\Rtau)\n\\end{axdef}\n\n\\subsection{Real-Valued Functions That Are Continuous at an $n$-tuple: \\zcmd{CzeroPointRtup}}\n\nA partial function $f$ from $\\R^n$ to $\\R$ is said to be \\textit{continuous at} $x \\in \\R^n$ if its domain contains a neighbourhood $U$ of $x$\nsuch that its restriction to $U$ is continuous on $U$.\nLet $\\CzeroPointRtup(x)$ denote the set of such functions.\n\n\\begin{axdef}\n\t\\CzeroPointRtup: \\Rinf \\fun \\power(\\Rinf \\pfun \\R)\n\\where\n\t\\forall x: \\Rinf @ \\\\\n\t\\t1\t\\LET n == \\# x @ \\\\\n\t\\t2\t\t\\CzeroPointRtup(x) = \\{~ f: \\Rtup(n) \\pfun \\R | \\exists U: \\neighRinf(x) | U \\subseteq \\dom f @ U \\dres f \\in \\CzeroSubsetRtup(U) ~\\}\n\\end{axdef}\n\n\\subsection{$m$-tuple-Valued Functions That Are Continuous on the Set of All $n$-tuples: \\zcmd{CzeroRtupRtup}}\n\nA mapping $f$ from $\\Rtup(n)$ to $\\Rtup(m)$ is said to be continuous if it is continuous with respect to the usual topologies.\nLet $\\CzeroRtupRtup(n,m)$ denote the set of these continuous mappings.\n\n\\begin{axdef}\n\t\\CzeroRtupRtup: \\nat \\cross \\nat \\fun \\power(\\Rinf \\pfun \\Rinf)\n\\where\n\t\\forall n, m: \\nat @ \\\\\n\t\\t1\t\\CzeroRtupRtup(n,m) = \\CzeroTT(\\tsRtup(n), \\tsRtup(m))\n\\end{axdef}\n\n\\begin{example}\nThe function $\\idRtup(n)$ is continuous.\n\n\\begin{zed}\n\t\\forall n: \\nat @ \\\\\n\t\\t1\t\\idRtup(n) \\in \\CzeroRtupRtup(n,n)\n\\end{zed}\n\n\\begin{theorem}\nLinear functions are continuous.\n\n\\begin{zed}\n\t\\forall n, m: \\nat@ \\\\\n\t\\t1\t\\linRtup(n, m) \\subseteq \\CzeroRtupRtup(n,m)\n\\end{zed}\n\n\\end{theorem}\n\n\\end{example}\n\n\\subsection{$m$-tuple-Valued Functions That Are Continuous on a Subset of $n$-tuples: \\zcmd{CzeroSubsetRtupRtup}}\n\nLet $U$ be any subset of $\\Rtup(n)$.\nLet $\\CzeroSubsetRtupRtup(U,m)$ denote the set of continuous mappings from the topology induced by $\\tsRtup(n)$ on $U$ to $\\tsRtup(m)$.\n\n\\begin{axdef}\n\t\\CzeroSubsetRtupRtup: \\DeltaRinf \\cross \\nat \\fun \\power (\\Rinf \\pfun \\Rinf)\n\\where\n\t\\forall n, m: \\nat @ \\\\\n\t\\t1\t\\forall U: \\DeltaRinf | \\dimRinf(U) = n @ \\\\\n\t\\t2\t\t\\CzeroSubsetRtupRtup(U, m) = \\CzeroTT(\\tsRtup(n) \\inducedTopSp U, \\tsRtup(m))\n\\end{axdef}\n\n\\begin{remark}\n\n\\begin{zed}\n\t\\forall n, m: \\nat @ \\\\\n\t\\t1\t\\CzeroSubsetRtupRtup(\\Rtup(n),m) = \\CzeroRtupRtup(n,m)\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{$m$-tuple-Valued Functions That Are Continuous at an $n$-tuple: \n$VectorConinuous$, \\zcmd{CzeroPointRtupRtup}}\n\nLet $x \\in \\Rtup(n)$ and let $f$ be a partial function from $\\Rtup(n)$ to $\\Rtup(m)$\nwhose domain includes some neighbourhood $U$ of $x$ such that $f$ restricted to $U$ is continuous.\nIn this case $f$ is said to be {\\it continuous at $x$}.\n\n\\begin{schema}{VectorContinuous}\n\tn, m: \\nat \\\\\n\tf: \\Rinf \\pfun \\Rinf \\\\\n\tx: \\Rinf\n\\where\n\tf \\in \\Rtup(n) \\pfun \\Rtup(m)\n\\also\n\t\\exists U: \\neighRinf(x) | \\\\\n\t\\t1\tU \\subseteq \\dom f @ \\\\\n\t\\t2\t\tU \\dres f \\in \\CzeroSubsetRtupRtup(U,m)\n\\end{schema}\n\nLet $\\CzeroPointRtupRtup(x,m)$ denote the set of all partial functions $f$ from $\\Rtup(n)$ to $\\Rtup(m)$\nthat are continuous at $x$.\n\n\\begin{axdef}\n\t\\CzeroPointRtupRtup: \\Rinf \\cross \\nat \\fun \\power (\\Rinf \\pfun \\Rinf)\n\\where\n\t\\forall n, m: \\nat @ \\forall x: \\Rtup(n)  @ \\\\\n\t\\t1\t\\CzeroPointRtupRtup(x, m) = \\\\\n\t\\t2\t\t\\{~ f: \\Rtup(n) \\pfun \\Rtup(m) | VectorContinuous ~\\}\n\\end{axdef}\n\n\\begin{example}\nThe function $\\idRtup(n)$ is continuous at every point $x \\in \\Rtup(n)$.\n\n\\begin{zed}\n\t\\forall n: \\nat @ \\forall x: \\Rtup(n) @ \\\\\n\t\\t1\t\\idRtup(n) \\in \\CzeroPointRtupRtup(x, n)\n\\end{zed}\n\n\\end{example}\n\n\\begin{theorem}\nLinear functions are continuous everywhere.\n\n\\begin{zed}\n\t\\forall n, m: \\nat @ \\\\\n\t\\t1\t\\forall x: \\Rtup(n); L: \\linRtup(n,m) @ \\\\\n\t\\t2\t\tL \\in \\CzeroPointRtupRtup(x, m)\n\\end{zed}\n\n\\end{theorem}\n\n\n\\section{Differentiability}\n\nLet $x \\in \\R^n$ and let $f: \\R^n \\pfun \\R^m$ be continuous at $x$.\nThen $f$ is said to be {\\it differentiable at $x$} if there exists a linear transformation $L: \\R^n \\fun \\R^m$\nsuch that $f(x + h) - f(x)$ is approximately linear in $h$ for very small $h$.\n$$\nf(x + h) - f(x) \\approx  L(h) + O(h^2) \\quad \\text{when} \\quad \\norm{h} \\approx 0\n$$\n\nThis condition can be written as a limit.\n$$\n\\lim_{h \\to 0} \\frac{\\norm{f(x+h) - f(x) - L(h)}}{\\norm{h}} = 0\n$$\n\n\\subsection{The Difference Quotient: $DifferenceQuotient$ and $diffQuot$}\n\nThe limit exists when the following difference quotient function $q: \\R^n \\pfun \\R$ is continuous at $0$.\n$$\nq(h) = \n\\begin{cases}\n\t\\frac{\\norm{f(x+h) - f(x) - L(h)}}{\\norm{h}}\t&\t\\text{if } h \\neq 0\\\\\n\t0\t\t\t\t\t\t\t\t&\t\\text{otherwise}\n\\end{cases}\n$$\n\nGiven a function $f$ that is continuous at $x$, and a linear transformation $L$,\nwe can define the difference quotient $q$.\nClearly $q$ is uniquely determined by $f$, $x$, and $L$.\nLet $DifferenceQuotient$ denote this situation.\n\n\\begin{schema}{DifferenceQuotient}\n\tVectorContinuous \\\\\n\tL: \\Rinf \\pfun \\Rinf \\\\\n\tq: \\Rinf \\pfun \\R\n\\where\n\tL \\in \\linRtup(n, m)\n\\also\n\t\\dom q = \\{~ h: \\Rtup(n) | x \\addRinf h \\in \\dom f ~\\}\n\\also\n\t\\forall h: \\dom q | h \\neq \\zeroRtup(n) @ \\\\\n\t\\t1\tq(h) = \\normRinf(f(x \\addRinf h) \\subRinf f(x) \\subRinf L(h)) \\divR \\normRinf(h)\n\\also\n\tq(\\zeroRtup(n)) = \\zeroR\n\\end{schema}\n\n\\begin{itemize}\n\\item $L$ is a linear transformation from $\\Rtup(n)$ to $\\Rtup(m)$.\n\\item The difference quotient $q$ is defined on a subset of $\\Rtup(n)$ that contains $\\zeroRtup(n)$.\n\\item $q(h)$ is defined as the quotient when $h$ is non-zero.\n\\item $q(0)$ is defined as zero.\n\\end{itemize}\n\nLet $diffQuot(f,x,L)$ denote the difference quotient $q$.\n\n\\begin{zed}\ndiffQuot == \\{~ DifferenceQuotient @ (f, x, L) \\mapsto q ~\\}\n\\end{zed}\n\n\\subsection{The Derivative of a Continuous $m$-tuple-Valued Function: $VectorDifferentiable$}\n\nThe continuous function $f$ is \\textit{differentiable at} $x$ when there exists a linear transformation $L$ \nsuch that the difference quotient $q$ is continuous at $0$.\nIn this case $L$ is unique and is referred to as the \\textit{derivative at} $x$.\n\n\\begin{schema}{VectorDifferentiable}\nVectorContinuous \\\\\nL: \\Rinf \\pfun \\Rinf\n\\where\n\\LET q == diffQuot(f, x, L) @ \\\\\n\\t1\tq \\in \\CzeroPointRtup(\\zeroRtup(n))\n\\end{schema}\n\n\\begin{itemize}\n\\item The continuous function $f$ is differentiable at $x$ with derivative $L$ if the resulting\ndifference quotient $q$ is continuous at $\\zeroRtup(n)$.\n\\end{itemize}\n\n\\begin{remark}\nIf $L$ exists then it is unique.\n\\end{remark}\n\n\nLet $\\smoothRnm(x,m)$ denote the set of all functions $f \\in \\Rtup(n) \\pfun \\Rtup(m)$ that are smooth at $x \\in \\Rtup(n)$.\n\n\\printbibliography\n\n\\end{document}", "meta": {"hexsha": "925bab7ec04e3eb2fa26986caba33c1d21879c8d", "size": 23875, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "articles/vector-spaces/vector-spaces.tex", "max_stars_repo_name": "agryman/mathz", "max_stars_repo_head_hexsha": "a516a20936e1ed7b9f07c546eee7aacf1831de65", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-30T08:06:17.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-30T08:06:17.000Z", "max_issues_repo_path": "articles/vector-spaces/vector-spaces.tex", "max_issues_repo_name": "agryman/mathz", "max_issues_repo_head_hexsha": "a516a20936e1ed7b9f07c546eee7aacf1831de65", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "articles/vector-spaces/vector-spaces.tex", "max_forks_repo_name": "agryman/mathz", "max_forks_repo_head_hexsha": "a516a20936e1ed7b9f07c546eee7aacf1831de65", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2227662179, "max_line_length": 142, "alphanum_fraction": 0.6692774869, "num_tokens": 8804, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220787, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7049153002289205}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{amssymb,amsmath}\n\\usepackage{breqn}\n\\usepackage{fancyhdr}\n\\pagestyle{fancyplain}\n\\rhead{Prepared by Adam Beardsley on \\today}\n\n\\begin{document}\n\n\\section{Image to PS Notes}\n\nWe start with an image of the sky, $I_{Jy}(\\theta_x,\\theta_y,f)$, in units of Jy / str. We can convert to temperature units using the Rayleigh-Jeans law.\n\\begin{equation}\nI_T(\\theta_x,\\theta_y,f) = 10^{-23}\\frac{c^2 \\;\\text{str}}{2 f^2 k_B} I_{Jy}(\\theta_x,\\theta_y,f)\n\\end{equation}\n$A_b$ is the array beam in steradians. The factor of $10^{-23}$ in front is for the conversion from Jy to SI units ($10^{-26}$), and from K to mK ($10^{3}$). In this space we can easily convert angles and frequency to physical space (Mpc) using the following transformations (Morales and Hewitt, 2004).\n\\begin{subequations}\\label{eq:transformations}\n\\begin{align}\nr_x & = D_M(z) \\theta_x \\\\\nr_y & = D_M(z) \\theta_y \\\\\nr_z & = \\frac{c(1+z)^2}{H_0 f_{21} E(z)} \\Delta f\n\\end{align}\n\\end{subequations}\nWhere $r_z$ is measured relative to the closest distance line-of-sight of the observation, and $\\Delta f$ is the channel frequency relative to the top of the observing band.\n\nThe next step is to Fourier transform the image to $k-$space. This is done in practice with a two dimensional discrete transform in the perpendicular direction and a FFT in the parallel direction. Mathematically all three steps can be written with a sum over all three dimensions of $\\mathbf{r}$, where the indices $i,j$ indicate that $\\mathbf{r}$ and $\\mathbf{k}$ are discrete.\n\\begin{equation}\n\\tilde{I}(\\mathbf{k}_j) = \\sum_{\\mathbf{r}_i} I(\\mathbf{r}_i)e^{-i \\mathbf{k}_j \\cdot \\mathbf{r}_i} \\Delta r_x \\Delta r_y \\Delta r_z\n\\end{equation}\nThis expression has units of mK Mpc$^3$. I will drop the indices to simplify notation.\n\nNext we square and relate to the power spectrum (e.g. Morales and Wyithe, 2010).\n\\begin{equation}\n\\left<\\left|\\tilde{I}(\\mathbf{k})\\right|^2\\right> = \\frac{1}{(2\\pi)^3}\\int P(\\mathbf{k}')\\left|W(\\mathbf{k}-\\mathbf{k}')\\right|^2 d^3\\mathbf{k}'\n\\end{equation}\nNote in previous versions of this memo, the $2\\pi$'s were omitted. Correspondence with Matt McQuinn confirmed they should be there.\nThe window function is compact and sharply peaked in $k-$space, so we approximate the power spectrum to be constant over the integral (e.g. Bowman, 2006). We then arrive at our estimate of $P(\\mathbf{k})$.\n\\begin{equation}\\label{eq:PS}\n\\hat{P}(\\mathbf{k}) = \\frac{\\left<\\left|\\tilde{I}(\\mathbf{k}\\right|^2\\right> }{ \\frac{1}{(2\\pi)^3}\\int \\left|\\widetilde{W}(\\mathbf{k}-\\mathbf{k}')\\right|^2 d^3\\mathbf{k}'}\n\\end{equation}\n\nThe integral of the window function is determined by the bandwidth and field of view of the instrument (See e.g. Morales, 2005; Morales and Hewitt, 2004; and Bowman, 2006). In our units system this is given by\n\\begin{equation}\n\\frac{1}{(2\\pi)^3} \\int \\left|\\widetilde{W}(\\mathbf{k}-\\mathbf{k}')\\right|^2 d^3\\mathbf{k}' = \\int \\left|W(\\mathbf{r}-\\mathbf{r}')\\right|^2 d^3 \\mathbf{r}' \\approx D_M(z)^2 \\Omega \\Delta D\n\\end{equation}\nwhere $\\Omega$ is the solid angle of the observation, and $\\Delta D$ is the extent of the observation in the line-of-sight direction. This integral has units of Mpc$^3$. Thus our units for the power spectrum in Eq. \\ref{eq:PS} are mK$^2$ Mpc$^3$ as expected.\n\n\\section{Detailed Window Function Calculation}\nWe can calculate the integrated window function for zenith pointing analytically using a MWA beam model. We treat a tile as a set of short dipoles sitting above a ground plane. The dipoles will have relative phases with respect to one another based on the direction of some source. We will calculate the response for an individual dipole at location $(x_i,y_i,h)$ relative to the center of the tile. The vertical component, $h$, is the height of the dipole, and we will assume it is the same for all dipoles on a single tile.\n\nThe phase difference for the dipole is found using simple geometry.\n\\begin{equation}\n\\Delta\\phi_i = \\frac{2\\pi}{\\lambda} (x_i \\sin\\theta_x+y_i \\sin\\theta_y)\n\\end{equation}\n\nIn addition to the phase differences, the ground plane also serves as an amplitude modulation. If the reflected wave is in phase with the incoming wave, the dipole will have twice the response as if the plane was not there. On the other hand, if the reflection is completely out of phase, the dipole will have zero response. We can derive the form of the amplitude modulation using geometry again. This time we find the phase difference between the incident wave and the reflected wave. The reflected part can be found by modeling the path difference between the true dipole above the plane and a virtual dipole below the plane.\n\n\\begin{equation}\n\\Delta D = 2 h \\cos\\theta_z\n\\end{equation}\nHere $\\theta_z$ is the zenith angle. The phase will be given by this path difference as well as a $\\pi$ flip at the ground plane interface.\n\\begin{equation}\n\\Delta\\phi_{r,i} = \\pi + \\frac{2 \\pi}{\\lambda} (2h \\cos\\theta_z)\n\\end{equation}\n\nBecause this phase is independent of dipole (assumed $h$ is the same for all dipoles), we can solve for the amplitude of the incident plus reflected wave.\n\\begin{subequations}\n\\begin{align}\nA & = \\left|1 + e^{i \\Delta \\phi_r} \\right| \\\\\n& = \\left( (1 + \\cos(\\Delta \\phi_r))^2 + (\\sin(\\Delta \\phi_r))^2\\right)^{1/2} \\\\\n& = \\left(1 + 2\\cos(\\Delta \\phi_r) + \\cos^2(\\Delta\\phi_r) + \\sin^2(\\Delta\\phi_r) \\right)^{1/2} \\\\\n& = \\left(2(1+\\cos(\\Delta \\phi_r))\\right)^{1/2} \\\\\n& = 2 \\left|\\cos(\\Delta \\phi_r/2)\\right| \\\\\n& = 2 \\left|\\cos\\left(\\pi/2 + \\frac{2 \\pi}{\\lambda}h \\cos\\theta_z\\right))\\right| \\\\\n& = 2 \\sin\\left(\\frac{2 \\pi}{\\lambda}h \\cos\\theta_z\\right)\n\\end{align}\n\\end{subequations}\n\nThe dipole will be sensitive only to radiation with polarization aligned along its axis. Due to the orthogonality between direction of propagation and polarization, a non polarized source will appear polarized to the instrument if it is off zenith. For a dipole with single polarization, the amplitude attenuation is given by\n\\begin{equation}\nP = 1-\\sin(\\theta_z)\\cos(\\theta_{az}),\n\\end{equation}\nwhere $\\theta_{az}$ is the azimuth angle.\n\nThe response for the dipole is then given by\n\\begin{subequations}\n\\begin{align}\nR_i &= APe^{i \\Delta \\phi_i} \\\\\n& = 2 \\sin\\left(\\frac{2\\pi}{\\lambda}h\\cos\\theta_z\\right) \\mathrm{exp}\\left[\\frac{2\\pi i}{\\lambda}(x_i \\sin\\theta_x + y_i cos\\theta_y)\\right]\\left(1-\\sin(\\theta_z)\\cos(\\theta_{az})\\right)\n\\end{align}\n\\end{subequations}\n\nNext we construct the response for the full tile by summing over the dipoles. We can leverage the symmetry of the tile by defining a horizontal space, $\\delta_x$, which we will assume to be uniform.\n\\begin{subequations}\n\\begin{align}\nR_{tile} &= \\sum_i R_i \\\\\n& = \\sum_i 2 \\sin\\left(\\frac{2\\pi}{\\lambda}h\\cos\\theta_z\\right) \\mathrm{exp}\\left[\\frac{2\\pi i}{\\lambda}(x_i \\sin\\theta_x + y_i cos\\theta_y)\\right]\\left(1-\\sin(\\theta_z)\\cos(\\theta_{az})\\right) \\\\\n& = 2 \\sin\\left(\\frac{2\\pi}{\\lambda}h\\cos\\theta_z\\right) \\sum_j \\sum_k  \\mathrm{exp}\\left[\\frac{2\\pi i}{\\lambda}(j \\delta_x \\sin\\theta_x + k \\delta_x cos\\theta_y)\\right]\\left(1-\\sin(\\theta_z)\\cos(\\theta_{az})\\right)\n \\end{align}\n\\end{subequations}\nThe $j$ and $k$ sums are over the half integers -3/2, -1/2, 1/2, and 3/2.\n\nIn the approximation that the tiles are identical (and thus have the same $R_{tile}$), the window function is simply the magnitude squared of the response. We also normalize the window so that at phase center it is equal to unity. Further, the window function in general is a function of the frequency, but we will assume it is constant within a channel.\n\\begin{equation}\nW(\\theta_x,\\theta_y,f) = \\frac{\\left|R_{tile}(\\theta_x,\\theta_y)\\right|^2}{\\left|R_{tile}(0,0)\\right|^2}\n\\end{equation}\n\nNext we can use the transformations from Eq. \\ref{eq:transformations} to rewrite the window function in terms of cosmological axes ($\\mathbf{r}$). With some simplification we arrive at the following for the window function squared.\n\\begin{dmath}\n\\left| W(\\mathbf{r})\\right|^2 = \\frac{1}{256 \\left|\\sin\\left(\\frac{2\\pi h}{\\lambda}\\right)\\right|^4} \\left| \\sin\\left(\\frac{2\\pi h \\cos(\\frac{\\sqrt{r_x^2+r_y^2}}{D_m})}{\\lambda}\\right) \\times \\\\ \\\\ \n\\left(\\cos\\left(\\frac{\\pi \\delta_x \\sin(r_x/D_m)}{\\lambda}\\right)+\\cos\\left(\\frac{3\\pi \\delta_x \\sin(r_x/D_m)}{\\lambda}\\right) \\right) \\times \\\\ \\\\\n\\left(\\cos\\left(\\frac{\\pi \\delta_x \\sin(r_y/D_m)}{\\lambda}\\right)+\\cos\\left(\\frac{3\\pi \\delta_x \\sin(r_y/D_m)}{\\lambda}\\right) \\right)\\right|^4 \\times \\\\ \\\\\n\\left(1-\\sin\\left(\\frac{\\sqrt{r_x^2+r_y^2}}{D_m}\\right)\\frac{r_y}{\\sqrt{r_x^2+r_y^2}}\\right)^4\n\\end{dmath}\n\nThis can then be integrated (probably numerically) to arrive at our estimate of the integrated window function (with the assumptions of identical tiles phased at zenith). As an example I compute this integral for observing parameters shown in Table \\ref{tbl:obs_params}, and find\n\\begin{equation}\n\\int |W(\\mathbf{r})|^2d^3 \\mathbf{r} \\approx 7.0 \\times 10^8 \\text{ Mpc}^3\n\\end{equation}\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{l c c}\n\\hline\nParameter & Symbol & Value \\\\\n\\hline\nRedshift & $z$ & 8 \\\\\nWavelength & $\\lambda$ & 1.90 m \\\\\nDipole spacing & $\\delta_x$ & 1.1 m \\\\\nDipole height & $h$ & 0.35 m \\\\\nBandwidth & $B$ & 8 MHz\n\\end{tabular}\n\\caption{Observing and instrument parameters for example calculation}\n\\label{tbl:obs_params}\n\\end{center}\n\\end{table}\n\n\\section{Calculating Window Function from Ian's Data Cubes}\n\nWe now aim to calculate the above integral from the data cubes that Ian produces with FHD. In particular, these are cubes of the weights and the variance of each pixel (in image space). Let the symbols for these cubes be $w$ and $\\sigma^2$ respectively. I will continue to use a capital $W$ for the window function.\n\nThe first step is to Fourier transform the weights and variances to $(k_x,k_y,r_z)$ space. This is the space in which the weights and variances are non-covariant and easiest to manipulate.\n\nWe begin by relating the weights cube $w$ to the sampled window function. There may be a normalization difference, which we will solve for, and the weights account for all the gridded visibilities ($N_{\\text{vis}}$) rather than a single beam. The same factors come into the variance cube. So we can write,\n\\begin{subequations} \\label{eq:relate_w_to_W}\n\\begin{align}\n\\sum_{\\text{beam}} W(k_{\\perp},r_z) & = \\frac{1}{N_{\\text{vis}}} \\sum_{\\text{cube}} W_0 w(k_{\\perp},r_z) \\\\\n\\sum_{\\text{beam}} |W(k_{\\perp},r_z)|^2 & = \\frac{1}{N_{\\text{vis}}} \\sum_{\\text{cube}} |W_0|^2 \\sigma^2(k_{\\perp},r_z)\n\\end{align}\n\\end{subequations}\nwhere $W_0$ is the normalization constant.\n\nNext we solve for $W_0$ by forcing $W(r_x=0,r_y=0,r_z) = 1$ (as in the previous section). The window function is $\\mathbf{r}$ space is related to the window function in $(k_{\\perp},r_z)$ space by a two dimensional inverse Fourier transform. Our convention for the Fourier transform did not have $2\\pi$ in going from $k$ to $r$, so now we must include it.\n\\begin{equation}\nW(\\mathbf{r}) = \\frac{1}{(2\\pi)^2} \\int W(k_{\\perp},r_z) e^{i \\mathbf{k}_{\\perp} \\cdot \\mathbf{r}_{\\perp}} d^2 k_{\\perp}\n\\end{equation}\nWe can then evaluate when $r_{\\perp}=0$ and apply our normalization.\n\\begin{equation}\nW(r_{\\perp}=0,r_z) =  \\frac{1}{(2\\pi)^2} \\int W(k_{\\perp},r_z) d^2 k_{\\perp} = 1\n\\end{equation}\nThis integral can be approximated with a sum and related to the weights using Eq. \\ref{eq:relate_w_to_W} to solve for $W_0$.\n\\begin{subequations} \\label{eq:solve_W0}\n\\begin{align}\n1 & = \\frac{1}{(2\\pi)^2} \\int W(k_{\\perp},r_z) d^2 k_{\\perp} \\\\\n& \\approx  \\frac{1}{(2\\pi)^2} \\sum_{\\text{beam}} W(k_{\\perp},r_z) (\\Delta k_{\\perp})^2 \\\\\n& =  \\frac{(\\Delta k_{\\perp})^2}{N_{\\text{vis}}(2\\pi)^2} \\sum_{\\text{cube}} W_0  w(k_{\\perp},r_z) \\\\\n\\rightarrow W_0 & = \\frac{N_{\\text{vis}}(2\\pi)^2}{(\\Delta k_{\\perp})^2} \\frac{1}{\\sum_{\\text{cube}} w(k_{\\perp},r_z)} \n\\end{align}\n\\end{subequations}\nNote that this result is dependent on our normalization choice which is only true at zenith pointing and phase center. So the sum over the weights should be done for that particular case, and used for other pointings and phase centers in the following work.\n\nArmed with a solution for $W_0$ we now seek to solve the integral in question.\n\\begin{subequations}\n\\begin{align}\n\\int |W(\\mathbf{r})|^2 d^3 \\mathbf{r} & = \\frac{1}{(2\\pi)^2} \\int |W(k_{\\perp},r_z)|^2 d^2k_{\\perp}d r_z \\\\\n& \\approx \\frac{\\Delta D}{(2\\pi)^2} \\sum_{\\text{beam}} |W(k_{\\perp},r_z)|^2 (\\Delta k_{\\perp})^2 \\\\\n& = \\frac{\\Delta D (\\Delta k_{\\perp})^2}{(2\\pi)^2} \\frac{1}{N_{\\text{vis}}} \\sum_{\\text{cube}} |W_0|^2 \\sigma^2(k_{\\perp},r_z) \\\\\n& = \\frac{\\Delta D (\\Delta k_{\\perp})^2}{(2\\pi)^2 N_{\\text{vis}}} \\frac{N_{\\text{vis}}^2(2\\pi)^4}{(\\Delta k_{\\perp})^4} \\frac{\\sum_{\\text{cube}} \\sigma^2(k_{\\perp},r_z)}{\\left|\\sum_{\\text{cube}} w(k_{\\perp},r_z)\\right|^2}  \\\\\n& = \\frac{(2\\pi)^2 \\Delta D N_{\\text{vis}}}{(\\Delta k_{\\perp})^2} \\frac{\\sum_{\\text{cube}} \\sigma^2(k_{\\perp},r_z)}{\\left|\\sum_{\\text{cube}} w(k_{\\perp},r_z)\\right|^2}\n\\end{align}\n\\end{subequations}\nIn the first step we used Parseval's theorem to relate the integral of the function squared in one space to the integral of the Fourier transform squared. The second step is approximating the integral as a sum, and doing the trivial integral over $r_z$ (the window is assumed to be constant over the band). Next we make use of Eq. \\ref{eq:relate_w_to_W} to replace the sum over the window function. The fourth step is using the result of Eq. \\ref{eq:solve_W0} to plug in for $W_0$. Finally we simplify in the last step. It is worth noting that the units of our final expression are Mpc$^3$, as expected.\n\nThis result should allow for a check on the data pipeline by comparing this calculation to that of the previous section. There are still a few outstanding questions (in my mind anyway):\n\\begin{itemize}\n  \\item Is the normalization correct? I believe there are assumptions in the noise calculations that require the window function to be normalized to the collecting area. How exactly is that done? \\\\ \\\\\n { \\bf Answer:} The normalization is fixed by how we do our calibration. By saying that our apparent flux of a source on phase center is equal to the true flux of that source, we have set the normalization of the window function to be unity at phase center. So the assumption above is correct.\n  \\item In what space should the integral be computed? In the past we have said it doesn't matter if the integral is done in $r$ or $k$ space because of Parseval's theorem. However, there are $2\\pi$'s relating the two spaces, and it is important to use the correct version.\n  \\item There are probably more\\ldots will add when I think of them.\n\\end{itemize}\n\n\\section{A couple notes on W-projection}\nFor computational reasons, we seek to estimate the effect W-projection has on our longest baselines. Let us consider a single baseline, projected onto a plane perpendicular to the line of pointing.\n\\begin{figure}[h!]\n\\includegraphics[width=\\columnwidth]{W_projection.png}\n\\caption{A projected baseline with non zero pointing.}\n\\label{fig:proj_base}\n\\end{figure}\nLet $b$ represent the longest baseline, and $b'$ represent the projected baseline. We wish to find the ratio $b'/b$.\n\nBy inspection we can see that the projected baseline length can be determined from a pure geometric projection combined with the diffraction opening angle, $\\alpha$. Mathematically,\n\\begin{equation}\nb' = b\\cos(\\theta) + x = b\\cos(\\theta) + b\\sin(\\theta)\\tan(\\alpha).\n\\end{equation}\nAlpha is approximately half of the primary beam width. So our ratio becomes\n\\begin{equation} \\label{eq:bprimeb}\n\\frac{b'}{b} = \\cos(\\theta) + \\sin(\\theta)\\tan(\\mathrm{FoV}/2)\n\\end{equation}\nWe can plot this ratio as a function of $\\theta$ for a conservative field of view of 40$^{\\circ}$ (Fig. \\ref{fig:bprimeb}).\n\\begin{figure}[h!] \n\\includegraphics[width=\\columnwidth]{bprimeb.png}\n\\caption{Projected baseline ratio as a function of pointing angle.}\n\\label{fig:bprimeb}\n\\end{figure}\n\nWe are mostly interested in the maximum of this ratio. We set the derivative with respect to theta equal to zero and solve.\n\\begin{subequations}\n\\begin{align}\n\\frac{\\partial}{\\partial\\theta}(b'/b)  = -\\sin(\\theta) + \\cos(\\theta)\\tan(\\mathrm{FoV}/2) &= 0 \\\\\n \\tan(\\theta_{max}) & = \\tan(\\mathrm{FoV}/2) \\\\\n \\rightarrow \\theta_{max} &= \\mathrm{FoV}/2\n\\end{align}\n\\end{subequations}\nPlugging this result back into Eq. \\ref{eq:bprimeb}, we have the maximum ratio for a given field of view.\n\\begin{subequations}\n\\begin{align}\n\\left.\\frac{b'}{b}\\right\\vert_{\\theta_{max}} & = \\cos(\\mathrm{FoV}/2) + \\sin(\\mathrm{FoV}/2)\\tan(\\mathrm{FoV}/2) \\\\\n& = \\sec(\\mathrm{FoV}/2)\n\\end{align}\n\\end{subequations}\n\n\n\\end{document}", "meta": {"hexsha": "4952dc69d6fe6ba7abc1fe527fb942595916cfe3", "size": 16666, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "006_Image_to_PS_Notes/image_to_PS_notes.tex", "max_stars_repo_name": "EoRImaging/Memos", "max_stars_repo_head_hexsha": "216dbda634c1686be25cda25bb258664067a3aad", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-05T08:38:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-05T08:38:01.000Z", "max_issues_repo_path": "006_Image_to_PS_Notes/image_to_PS_notes.tex", "max_issues_repo_name": "EoRImaging/Memos", "max_issues_repo_head_hexsha": "216dbda634c1686be25cda25bb258664067a3aad", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2019-03-07T22:45:46.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-20T20:19:43.000Z", "max_forks_repo_path": "006_Image_to_PS_Notes/image_to_PS_notes.tex", "max_forks_repo_name": "EoRImaging/Memos", "max_forks_repo_head_hexsha": "216dbda634c1686be25cda25bb258664067a3aad", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-03-07T01:12:56.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-07T01:12:56.000Z", "avg_line_length": 71.2222222222, "max_line_length": 628, "alphanum_fraction": 0.7179887195, "num_tokens": 5307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782736, "lm_q2_score": 0.793105953629227, "lm_q1q2_score": 0.7048798998065976}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage{enumitem}\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{1em}\n\n\\begin{document}\n\n\\section{Functions in number theory}\n\\subsection{Rules}\n\\begin{enumerate}\n\\item\n\\textbf{Fermat's little theorem.} \\\\\nFor prime $p$ and integer $a$\n$$a^p \\equiv a \\mod p$$\n\n\\item\n\\textbf{Wilson's theorem.} \\\\\n$$(p-1)! \\equiv -1 \\mod p$$\nif and only if when $p$ is prime number.\n\n\\item \n\\textbf{Number of factors} \\\\\nThe number of positive factors of $n=p_1^{\\alpha_1} \\dots p_k^{a_k}$\n$$d(n)= (\\alpha_1+1)(\\alpha_2+1)\\dots (\\alpha_k+1)$$\t\n\\item \n\\textbf{Sum of factors} \\\\\nThe sum of positive factors of $n=p_1^{\\alpha_1} \\dots p_k^{a_k}$\n\n$$\\sigma(n)= \\frac{p_1^{\\alpha_1+1}-1}{p_1-1} \\dots  \\frac{p_k^{\\alpha_k+1}-1}{p_k-1}$$\n\n\\item \n\\textbf{Euler's function} \\\\\nEuler’s function or totient function $\\varphi(n)$ is defined for $n=p_1^{\\alpha_1} \\dots p_k^{a_k}$ as the number\nof positive integers less than $n$ and coprime to $n$. Then\n$$\\varphi(n) = n \\left(1-\\frac{1}{p_1}\\right) \\dots  \\left(1-\\frac{1}{p_k}\\right)$$\n\n\n\\item \n\\textbf{Euler's theorem}  (Generalisation of Fermat's theorem)\\\\\nLet $n$ be a natural number and $a$ an integer such that $\\gcd(a,n)=1$. Then\n$$a^{\\varphi(n)} \\equiv 1 \\mod n $$\n\n\\end{enumerate}\n\n\\subsection{Problems}\n\\begin{enumerate}\n\n\\item \nFind all primes $p$, for which the sum of all positive factors of $p^4$ is a perfect square.\n\n\\item \nProve that for positive integer $n$ \n$$\\sum_{d|n} \\varphi (d) =n $$\n\n\\item \nProve that for positive integers $a$ and $b$ \n$$ \\varphi(ab) = \\varphi (a)\\varphi(b)\\frac{\\gcd(a,b)}{\\varphi(\\gcd(a,b))} $$\n\n\\item % https://artofproblemsolving.com/wiki/index.php?title=Fermat%27s_Little_Theorem#Problems\nOne of Euler's conjectures was disproved in the 1960s by three American mathematicians when they showed there was a positive integer such that $133^5+110^5+84^5+27^5=n^5$. Find the value of ${n}$. \n\n\\item  %p46 http://s3.amazonaws.com/aops-cdn.artofproblemsolving.com/resources/articles/olympiad-number-theory.pdf\nHow many prime numbers $p$ are there, such that $29^p+1$ is a multiple of $p$?\n\n\\item \nProve that if $\\gcd(a,n)=1$, then\n$$a^b \\equiv a^{b \\mod \\varphi(n)}  \\mod n$$\n\n\\item % http://s3.amazonaws.com/aops-cdn.artofproblemsolving.com/resources/articles/olympiad-number-theory.pdf\nFind the last three digits of $2008^{2007^{2006^{\\dots^{^{}2^{1}}}}}$.\n\n\\item \nProve that there exists no positive integer for which $n! + 19^{93}$ is a perfect square.\n\n\\item \nFind all pairs of positive prime numbers $(p_1,p_2)$ for which the equation $$\\phi(n^2) = n + p_1p_2$$\nhas a solution for $n$ in positive integers. \n\n\\item % http://www.math.olympiaadid.ut.ee/eng/archive/bw/bw05sol.pdf\n\nLet $p$ be a prime number and let $n$ be a positive integer. Let $q$ be a positive divisor of $(n+1)^p-n^p$. Show that $q-1$ is divisible by $p$.\n\n\\end{enumerate}\n\n\n\\end{document}", "meta": {"hexsha": "78443ee292b966e3b8feccd97088455d64db66db", "size": 2953, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "07_functions-in-number-theory.tex", "max_stars_repo_name": "ZhaoWanLong/maths-olympiad", "max_stars_repo_head_hexsha": "0dcacba8a6d1769bbccfedda89d08fa22c3f55a1", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-21T21:57:43.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-21T21:57:43.000Z", "max_issues_repo_path": "07_functions-in-number-theory.tex", "max_issues_repo_name": "ZhaoWanLong/maths-olympiad", "max_issues_repo_head_hexsha": "0dcacba8a6d1769bbccfedda89d08fa22c3f55a1", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "07_functions-in-number-theory.tex", "max_forks_repo_name": "ZhaoWanLong/maths-olympiad", "max_forks_repo_head_hexsha": "0dcacba8a6d1769bbccfedda89d08fa22c3f55a1", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-08T07:04:43.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-08T07:04:43.000Z", "avg_line_length": 32.8111111111, "max_line_length": 197, "alphanum_fraction": 0.6921774467, "num_tokens": 1033, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782737, "lm_q2_score": 0.7931059414036511, "lm_q1q2_score": 0.7048798889410095}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Indeterminate Forms}\n\n\\objective{Classify difficult limits problems and solve via certain techniques}\n\n\nJust as we used limits to define the derive six chapters ago, now they return the favor\nand derivatives themselves allow us to find certain limits.  We have seen how removable\ndiscontinuities take the form $\\frac{0}{0}$, but what are we to do if a derivative\nproduce that form?  In fact, there are many forms which mathematicians classify\nas \\textbf{indeterminate}\n\n$$\n\\frac{0}{0} , \\frac{\\infty}{\\infty} , 0\\times\\infty , \\infty-\\infty , 0^0 , ^\\infty \\text{, and } \\infty^0 \n$$\n\nThese are all indicative of a variety of answers, some finite, some infinite.  There is\nno way to know what answer will predominate in the end without more work.\nConsider this limit\n\\begin{equation}\n\\lim_{x\\rightarrow0}\\frac{5x}{\\ln(x+1)}\n\\end{equation}\nObviously, if we attempt a direct evaluation, we get a meaningless answer.  But\nconsider what we know about this quotient function.  Every ``nudge'' in the $x$\ndirection (dx) will produce a small change in the top half of the fraction: 5dx, to\nbe precise.  Similarly, the change in the denominator (it's implicit differential)\nis $\\frac{1}{x+1}$dx.  As a fraction, this is $\\cfrac{5dx}{\\frac{1}{x+1}dx}$ or \n$5(x+1)$.  Notice this is not like the maneuvering we did with removable \ndiscontinuities; we have not constructed an identical but hole-less version\nof the equation.  Our new equation is useful because it goes through the hole.\n\n\nThis technique for solving limits at indeterminate value is call \\textbf{L'Hopital's}\nRule (LO-pee-talz), even though it was found by L'Hopital's collegue Bernoulli.\n\n\\personfeature[0in]{\\chapdir/pics/Leopold_Kronecker_1865}{Leopold Kronecker}{1823 -\n1891}{was a German mathematician who worked on number theory, algebra and logic. \nHe criticized Cantor's work on set theory, and said, ``God made the integers, \nall else is the work of man.''  He studied elliptic functions and conjectured his \n``dearest dream of youth\", a generalization that was later put forward by \nHilbert in a modified form as his twelfth problem. \n\\href{https://en.wikipedia.org/wiki/Leopold_Kronecker}{Wikipedia}}\n\n\\subsection{Infinite Forms}\nNot every form with a zero in the denominator or an infinity in it is indeterminate.\nThe following forms resolve in other ways, and cannot be solved with L'Hopital's\nRule:\n$$\n\\frac{1}{0} , \\frac{\\infty}{1} , \\frac{\\infty}{0} , \\infty + \\infty , \\infty \\times\\infty\n$$\n\nSome other fractions you should recognize from algebra and/or experience as zero:\n$$\n\\frac{0}{1} = \\frac{1}{\\infty} = \\frac{0}{\\infty}\n$$\n\nTo return to our earlier equation of $\\frac{5x}{\\ln(x+1)}$, what is the limit as $x$ \napproaches infinity?  Logarithmic graphs \\emph{seem} to taper off, and direct \nevaluation is useless (plugging in infinity for $x$) because we get $\\frac{\\infty}{\\infty}$.\nBut L'Hopital's Rule works here too, because that is an indeterminate form.\nOur limit will be the same as \n\\begin{equation}\n\\lim_{x\\rightarrow0}5(x+1)\n\\end{equation}\nwhich is infinite.", "meta": {"hexsha": "c45ae7034358dd66cd3e769d7ce4be6bddf6da70", "size": 3085, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch08/0804.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch08/0804.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch08/0804.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.7424242424, "max_line_length": 107, "alphanum_fraction": 0.7474878444, "num_tokens": 880, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7048325938525609}}
{"text": "\n\n\\section{Previous work}\n\\label{sec:previous:work}\n\nFirst of all, we recall some modular arithmetic fundamentals. Let\n$a,b\\in\\mathbb{Z}$ and $n\\in\\mathbb{N}$, \\textit{$a$ is congruent to $b$ modulo\n$n$}, written as $a \\equiv_{n} b$, if $a \\mod n = b \\mod n$; from this, follows\nthat $n \\left| (a-b)\\right.$ and $a - b = nk$, for some $k\\in\\mathbb{Z}$, are\nequivalent definitions.\n\n%\\subsection{Lucas theorem exposed}\n\nIn \\cite{fine:1947}, Fine exposes the following theorem which is a fundamental\nresult for our work, \n\n\\begin{theorem}[Lucas] Let $p$ be a prime and $m,n\\in\\mathbb{N}$, then\n    \\begin{displaymath}\n        {{m}\\choose{n}} \\equiv_{p} \n            {{m_{0}}\\choose{n_{0}}} \n            {{m_{1}}\\choose{n_{1}}} \n            \\cdots \n            {{m_{k}}\\choose{n_{k}}} \n    \\end{displaymath}\n    representing $m=\\left(m_{0},m_{1},\\ldots,m_{k}\\right)_{p}$ and\n    $n=\\left(n_{0},n_{1},\\ldots,n_{k}\\right)_{p}$ in base $p$, for some $k\\in\\mathbb{N}$.\n    \\iffalse\n    So both $m_{j}$ and $n_{j}$ are in $\\lbrace 0,\\ldots, p-1 \\rbrace$, for\n    $j\\in\\lbrace 0,\\ldots,k\\rbrace$.\n    \\fi\n    \\label{thm:lucas:theorem}\n\\end{theorem}\n\n\\iffalse\n\\begin{proof}\n    Consider the sequence\n    $\\vect{\\alpha}_{m}=\\left({{m}\\choose{n}}\\right)_{n\\in\\mathbb{N}}$ of\n    binomial coefficients which count the number of $n$-elements subsets out of\n    a set composed by $m$ elements. We use $\\vect{\\alpha}_{m}$ to\n    define a formal power series on the indeterminate variable $t$ and its generating\n    function\n    \\begin{displaymath}\n        %\\begin{split}\n            \\sum_{n=0}^{m}{{{m}\\choose{n}}\\,t^{n}} %&\n                = \\left(1+t\\right)^{m}\n                = \\left(1+t\\right)^{m_{0}+m_{1}p+\\cdots+m_{k}p^{k}}%\\\\\n                %&\n                = \\prod_{r=0}^{k}{{\\left(1+t\\right)^{m_{r}p^{r}}}}\n                = \\prod_{r=0}^{k}{\\left(\\left(1+t\\right)^{p^{r}}\\right)^{m_{r}}}\n        %\\end{split}\n    \\end{displaymath} \n    where $m=\\left(m_{0},m_{1},\\ldots,m_{k}\\right)_{p}$ is represented in \n    base $p$. The expansion of $\\left(1+t\\right)^{p^{r}}$ yields\n    \\begin{displaymath}\n            \\left(1+t\\right)^{p^{r}} = \\sum_{s=0}^{p^{r}}{{{p^{r}}\\choose{s}}\\,t^{s}}\n                = 1+\\sum_{s=1}^{p^{r}-1}{{{p^{r}}\\choose{s}}\\,t^{s}}+t^{p^{r}}\n    \\end{displaymath}\n    and the application of the congruence relation $\\equiv_{p}$ makes the last sum\n    vanish because $\\displaystyle p\\left|{{p^{r}}\\choose{s}}\\right.$, therefore\n    $\\left(1+t\\right)^{p^{r}} \\equiv_{p} 1+t^{p^{r}}$ holds and it allows us to rewrite\n    the products as\n    \\begin{displaymath}\n            \\prod_{r=0}^{k}{\\left(\\left(1+t\\right)^{p^{r}}\\right)^{m_{r}}}\n                \\equiv_{p} \\prod_{r=0}^{k}{\\left(1+t^{p^{r}}\\right)^{m_{r}}}\n                \\equiv_{p} \\prod_{r=0}^{k}{\\sum_{s_{r}=0}^{m_{r}}{{{m_{r}}\\choose{s_{r}}}t^{s_{r}p^{r}}}}.\n    \\end{displaymath}\n    there is a product of $k+1$ formal power series, properly shifted according to \n    $p_{0},p_{1},\\ldots,p_{k}$: such product yields a new formal power series which satisfies\n    \\begin{displaymath}\n        \\sum_{n=0}^{m}{{{m}\\choose{n}}\\,t^{n}} \n        \\equiv_{p}\n        \\sum_{n=0}^{m}{\\left(\\sum_{\\vect{\\omega}\\in\\Omega_{n}}{\\prod_{i=0}^{k}{{{m_{i}}\\choose{\\omega_{i}}}}}\\right)\\,t^{n}}\n    \\end{displaymath}\n    where $\\Omega_{n}=\\left\\lbrace\\vect{\\omega}=\\left(\\omega_{0},\\ldots,\\omega_{k}\\right):\n        \\sum_{j=0}^{k}{\\omega_{j}p^{j}}=n\\right\\rbrace$.\n    There exists a \\emph{unique} set of coefficients\n    $\\lbrace n_{0},n_{1},\\ldots,n_{k}\\rbrace$ such that $n=\\sum_{j=0}^{k}{n_{j}p^{j}}$, therefore\n    each set $\\Omega_{n}$ contains only one element, namely $\\vect{\\omega}=(n_{0},\\ldots,n_{k})$, so\n    \\begin{displaymath}\n        \\sum_{n=0}^{m}{{{m}\\choose{n}}\\,t^{n}} \n        \\equiv_{p} \\sum_{n=0}^{m}{\\left({\\prod_{i=0}^{k}{{{m_{i}}\\choose{n_{i}}}}}\\right)\\,t^{n}}\n    \\end{displaymath}\n    holds and the argument follows by equating coefficients attached to $t^{n}$, \n    %for $n\\in\\lbrace0,\\ldots,m\\rbrace$, \n    as required.\n\n\\end{proof}\n\\fi\n\n%\\subsection{Divisibility -- with visibility}\n\nIn \\cite{sved:1988}, Marta Sved gives solid bases to understand\n\\textit{divisibility properties} of some \\emph{counting numbers}, namely\ncoefficients occurring in combinatorics such as binomials and Stirling numbers,\nthat shows divisibility structures of remarkable design. \n\nShe starts working on the Pascal triangle $\\mathcal{P}$, whose coefficients\nare defined by the recurrence\n\\begin{equation}\n    {{n}\\choose{k}}={{n-1}\\choose{k-1}}+{{n-1}\\choose{k}},\n    \\label{eq:binomial:recurrence}\n\\end{equation}\nand studies a new triangle $\\mathcal{P}_{\\equiv_{p}}$ obtained from\n$\\mathcal{P}$ where each coefficient is taken modulo $p$, for some small prime\nnumber $p$. Besides, she introduces a little language that allows her to\ncharacterize these \"modular\" triangles and we readly adopt it as well.\n\nLet $\\mathcal{M}=\\left(m_{n,k}\\right)_{n,k\\in\\mathbb{N}}$ be an infinite, lower\ntriangular array so that $m_{n,k}=0$ if $n<k$. Choose a prime $p$, then the\narray $\\displaystyle\\mathcal{M}_{\\equiv_{p}} = \\left(m_{n,k}\\mod p :\nm_{n,k} \\in \\mathcal{M}\\right)_{n,k\\in\\mathbb{N}}$ contains the following regions\n\\begin{itemize}\n\n\\item a \\emph{principal cell} $\\mathcal{M}_{\\equiv_{p}}^{\\bigtriangleup} = \n        \\left(m_{n,k}\\in \\mathcal{M}_{\\equiv_{p}}\\right)_{n,k\\in\\lbrace 0,\\ldots,p-1\\rbrace}$;\n\n\\item a \\emph{cell} $c_{p,\\beta}=\\left( \\beta\\,m_{n,k}\\mod p:m_{n,k}\\in\n\\mathcal{M}_{\\equiv_{p}}^{\\bigtriangleup}\\right)_{n,k\\in\\mathbb{N}}$ which is a\ncopy of the \\emph{principal cell} with each entry multiplied by the same\nconstant $\\beta\\in\\mathbb{N}$;\n\n\\item a \\emph{principal cluster} $\\mathcal{M}_{\\equiv_{p}}^{(\\alpha)} =\n\\left(m_{n,k}\\in \\mathcal{M}_{\\equiv_{p}}\\right)_{n,k\\in\\lbrace\n0,\\ldots,p^{\\alpha}-1\\rbrace}$ of order $\\alpha\\in\\mathbb{N}$, so that for\n$\\alpha=1$ it denotes the \\emph{principal cell};\n\n\\item a \\emph{cluster} $\\mathcal{C}_{p,\\beta}^{(\\alpha)}=\\left(\n\\beta\\,m_{n,k}\\mod p:m_{n,k}\\in\n\\mathcal{M}_{\\equiv_{p}}^{(\\alpha)}\\right)_{n,k\\in\\mathbb{N}}$ of order\n$\\alpha\\in\\mathbb{N}$ which is a copy of the \\emph{principal cluster} of order\n$\\alpha$ with each entry multiplied by the same constant $\\beta\\in\\mathbb{N}$;\n\n\\item finally, a \\emph{zero-hole} of order $\\alpha\\in\\mathbb{N}$ which is an\n\\emph{upside-down} triangular array of coefficients where each one is a\nmultiple of $p$, from here the name, distributed according to the scheme\n(i)~$p^{\\alpha}-1$ coefficients lie on the first row, (ii)~$p^{\\alpha}-2$\ncoefficients lie on the second row down to (iii)~a single coefficient that lies\non the $(p^{\\alpha}-1)$-th row, eventually.  Observe that a \\emph{zero-hole} of\norder $\\alpha$ has $p^{\\alpha}-1$ rows, one less than a \\emph{principal\ncluster} of the same order.\n\n\\end{itemize}\n\n\nAlthough a formal proof can be stated by induction using\n\\autoref{eq:binomial:recurrence}, Marta shows that the following  theorem  has\nan easier formulation using the proposed language.\n\n\\begin{theorem}[Sved]\n    Let $p$ be a prime and $\\mathcal{P}_{\\equiv_{p}}$ be the \n    modular Pascal array. The principal cluster $\\mathcal{P}_{\\equiv_{p}}^{(\\alpha+1)}$\n    of order $\\alpha + 1$ consists of $p$ layers of clusters of order $\\alpha$ alternating\n    with zero-holes of order $\\alpha$, while the first layer contains the principal\n    cluster of order $\\alpha$ only.\n\\end{theorem}\n", "meta": {"hexsha": "25f7ff83a6471c1e9a62d8984fff07ded80075d1", "size": 7370, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modular-article/previous-work.tex", "max_stars_repo_name": "massimo-nocentini/master-thesis", "max_stars_repo_head_hexsha": "0d82bfcc82c92512d0795f286256a19f39b9b1f9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "modular-article/previous-work.tex", "max_issues_repo_name": "massimo-nocentini/master-thesis", "max_issues_repo_head_hexsha": "0d82bfcc82c92512d0795f286256a19f39b9b1f9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "modular-article/previous-work.tex", "max_forks_repo_name": "massimo-nocentini/master-thesis", "max_forks_repo_head_hexsha": "0d82bfcc82c92512d0795f286256a19f39b9b1f9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.2435897436, "max_line_length": 124, "alphanum_fraction": 0.6314789688, "num_tokens": 2591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893335913536, "lm_q2_score": 0.8596637559030337, "lm_q1q2_score": 0.7048325845912979}}
{"text": "%================================\n\\section{Continuous Maps}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\tLet $(X, \\mathcal T_X)$ and $(Y, \\mathcal T_Y)$ be topological spaces. A function $f: X \\to Y$ is \\textit{continuous} iff\n\t$$\n\t\\forall U \\in \\mathcal T_Y, \\quad f^{-1}[U] \\in \\mathcal T_X.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note} \\\n\t\\begin{enumerate}\n\t\t\\item Let $(X, \\mathcal T)$ and $(X, \\mathcal T')$ be topological spaces, let identity map $i:(X, \\rho) \\to (X, \\rho')$ be surjective. By definition, $i$ is continuous over $X$ iff $\\mathcal T \\supseteq \\mathcal T'$.\n\t\t\\item Let $(X, \\mathcal T_X)$ and $(Y, \\mathcal T_Y)$ be topological spaces if $\\mathcal T_X$ is the discrete topology, then any function $f: X \\to Y$ is continuous over $X$, because any sets in $X$ is open. Naturally, for any $U \\in \\mathcal T_Y$, $f^{-1}[U]$.\n\t\t\\item By the previous conditions, if $\\mathcal T_X$ is indiscrete topology but $\\mathcal T_Y$ is not, then no function $f: X \\to Y$ is continuous. (Check again!)\n\t\t\\item TO DO: Find valued example by point sets, for example let $\\mathcal T = \\{a, b, c, d, e\\}$.\n\t\\end{enumerate}\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{lemma}\n\tLet $(X, \\mathcal T_X)$ and $(Y, \\mathcal T_X)$ be topological space. A function: $f:X\\to Y$ is continuous iff for any closed subset $V$ of $Y$, the preimage $f^{-1}[V]$ is closed in $X$.\n\\end{lemma}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proof}\n\tIf $V$ is closed in $Y$, then there is a $U \\in \\mathcal T_Y$, such that $V = Y \\setminus U$.\n\t$$\n\tf^{-1}[V] = f^{-1}[Y \\setminus U] = X \\setminus f^{-1}[U] \\in \\mathcal T_Y.\n\t$$\n\\end{proof}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{lemma}\n\tContinuous maps preserve convergence of sequence..\n\\end{lemma}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tThis is not vise versa, i.e., there exists discontinuous map preserve convergence of sequence either.\n\t\n\tFor example, let $(X, \\mathcal T)$ and $(X, \\mathcal T')$ be topological space. Let $\\mathcal T'$ be discrete topology, and let\n\t$$\n\t\\mathcal T = \\{ \\text{monotones of $X$} \\} \\cup \\{ \\emptyset, X \\}.\n\t$$\n\tThen any $\\{x_n\\} \\subseteq X$ converges iff it is in the form of\n\t$$\n\tx, x, x, \\ldots\n\t$$\n\tClearly, for all $f:(X, \\mathcal T) \\to (X, \\mathcal T')$, for any $\\{x_n\\}$ converges to $x \\in (X, \\mathcal T)$, $\\{f(x_n)\\}$ also converges to $f(x) \\in (X, \\mathcal T')$. It is in the form of\n\t$$\n\tf(x), f(x), f(x), \\ldots\n\t$$\n\tBut, $f$ is not continuous over $(X, \\mathcal T)$. (For any $U \\subsetneq X$ with $|U|>1$, $f^{-1}[U] \\notin \\mathcal T$).\n\\end{note}\n%--------------------------------\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n%", "meta": {"hexsha": "4c910d3e2f43fe785e415989b4330a9b0fd7d9e9", "size": 2859, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-by-tom-leinster/c1_topological-space/s4_continuous-maps.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-by-tom-leinster/c1_topological-space/s4_continuous-maps.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-by-tom-leinster/c1_topological-space/s4_continuous-maps.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0947368421, "max_line_length": 263, "alphanum_fraction": 0.5222105631, "num_tokens": 903, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145053, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.704832575330035}}
{"text": "\\documentclass{pset_template}\n\n\\title{Boolean Algebra}\n\\date{February 1, 2019}\n\\editorOne{Alexander Sun}\n\\editorTwo{Sanjit Bhat}\n\\lectureNum{1}\n\\contestMonth{February}\n\n\\begin{document}\n\\maketitle\n\n\\section{Introduction}\nBoolean algebra is the branch of algebra in which the variables store truth value. All variables are true(1) or false(0).\nThere are 3 main operations that create the base for boolean algebra: $\\textbf{AND(conjunction)}$, $\\textbf{OR(disjunction)}$, and $\\textbf{NOT(negation)}$.\n\n\\bigskip\n\\noindent\n\\section{Basic Operations}\n\\textbf{AND}, denoted x $\\land$ y or x AND y or x $\\cdot$ y, satisfies x $\\land$ y = 1 if x = y = 1 , else x $\\land$ y = 0\n\n\\noindent\n\\textbf{OR}, denoted x $\\lor$ y or x OR y or x + y, satisfies x $\\lor$ y = 0 if x = y = 0 , else x $\\lor$ y = 1\n\n\\noindent\n\\textbf{NOT}, denoted $\\neg$x or NOT x or $\\sim$x or $\\bar{x}$, satisfies $\\neg$x = 0 if x = 1 and $\\neg$x = 1 if x = 0, reverses truth values of operation\n\n\\begin{center}\n\\begin{tabular}{ |c|c|c|c| }\n \\hline\n x & y & x$\\land$y & x$\\lor$y \\\\\n \\hline\n  0 & 0 & 0 & 0 \\\\\n \\hline\n 1 & 0 & 0 & 1 \\\\\n \\hline\n 0 & 1 & 0 & 1 \\\\\n \\hline\n 1 & 1 & 1 & 1 \\\\\n \\hline\n\\end{tabular}\n\\end{center}\n\n\\begin{center}\n\\begin{tabular}{ |c|c| }\n \\hline\n x & $\\neg$x \\\\\n \\hline\n  0 & 1  \\\\\n \\hline\n 1 & 0 \\\\\n \\hline\n\\end{tabular}\n\\end{center}\n\n\\section{Secondary Operations}\n\n\\textbf{Material Implication}, denoted  x $\\rightarrow$ y = $\\neg$x$\\lor$y, if x = 1, then x $\\rightarrow$ y = y, if x = 0, then x $\\rightarrow$ y = 1\n\n\\noindent\n\\textbf{Exclusive Or}, denoted x $\\oplus$ y or x XOR y, x $\\oplus$ y = 1 if x = 1 $\\&$ y = 0 or x = 0 $\\&$ y = 1, else x $\\oplus$ y = 0, true when values are different\n\n\\noindent\n\\textbf{Equivalence}, denoted x $\\equiv$ y, x $\\equiv$ y = 1 if x =1 $\\&$ y =1, or if x = 0 $\\&$ y = 0, complement of XOR, true when values are the same\n\\noindent\n\\textbf{Dual}, the dual is found by replacing all OR's with AND's and all AND's with OR's, and all 1's with 0's and all 0's with 1's\n\n\\noindent\n\\textbf{Complement}, found by negating each individual value and replaving all OR's with AND's and all AND's with OR's and all 1's with 0's and all 0's with 1's\n\\bigskip\n\n\\noindent\nMemorizing boolean algebra laws is extremely beneficial to being able to solve problems quickly and efficiently. Here is a link to page with almost every law. Most are derivable, but should still be memorized.  http://www.uiltexas.org/files/academics/UILCS-BooleanIdentities.pdf\n\nDemorgan's Rule is crucial to simplifying boolean algebra problems. It states: $$ \\bar{A} + \\bar{B} = \\overline{AB}$$ or $$ \\bar{A} * \\bar{B} = \\overline{A+B}$$\n\n\\bigskip\n\n\\noindent\nWith these basic rules memorized, all boolean algebra problems should be simple to work through\n\n\\section{Exercises}\n\\begin{enumerate}\n\\item Simplify completely:(ACSL 2001-2002)\n$( A + B )\\oplus A B$\n\n\\item Simplify the following expression: F = BC + $\\overline{BC}$ + BA\n\n\\item Simplify the Boolean expression (A+B+C)$\\overline{(D+E)}$ + (A+B+C)(D+E):\n\\end{enumerate}\n\nFor more practice resources on boolean algebra, read through\n\\href{http://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra}{the ACSL Wiki page}.\n\\end{document}\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "50614d3526cca0ce331806f20d0a10dc6b910ca3", "size": 3200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "boolean-algebra.tex", "max_stars_repo_name": "sanjit-bhat/AB-ACSL", "max_stars_repo_head_hexsha": "ab9bf7e5526cc5863c0173ab518138dada2dc1ef", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-12T03:01:29.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-12T03:01:29.000Z", "max_issues_repo_path": "boolean-algebra.tex", "max_issues_repo_name": "sanjit-bhat/AB-ACSL", "max_issues_repo_head_hexsha": "ab9bf7e5526cc5863c0173ab518138dada2dc1ef", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "boolean-algebra.tex", "max_forks_repo_name": "sanjit-bhat/AB-ACSL", "max_forks_repo_head_hexsha": "ab9bf7e5526cc5863c0173ab518138dada2dc1ef", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.4761904762, "max_line_length": 278, "alphanum_fraction": 0.675625, "num_tokens": 1095, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933315126792, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7048325719644796}}
{"text": "%\n% Copyright 2018 Parakram Majumdar\n%\n% Licensed under the Apache License, Version 2.0 (the \"License\");\n% you may not use this file except in compliance with the License.\n% You may obtain a copy of the License at\n%\n%     http://www.apache.org/licenses/LICENSE-2.0\n%\n% Unless required by applicable law or agreed to in writing, software\n% distributed under the License is distributed on an \"AS IS\" BASIS,\n% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n% See the License for the specific language governing permissions and\n% limitations under the License.\n%\n\n\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{tikz}\n\\usetikzlibrary{shapes.geometric, arrows,positioning}\n\\title{Multi Layered Perceptron}\n\\author{Parakram Majumdar}\n\n\\begin{document}\n  \\maketitle\n\n\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\Prob}[2]{\\mathbb{#1}\\left[ #2 \\right]}\n\\newcommand{\\sigmoid}[1]{\\text{sigmoid}\\left(#1\\right)}\n\\newcommand{\\map}[2]{\\text{map}\\left(#1,#2\\right)}\n  \n\\section{Introduction}\n  We are given a training set $T$ of $t$ points in $\\R^d$,\n  a set $L$ of $l$ labels,\n  and a \\emph{classification} $C: T \\rightarrow L$.\n  \n  Machine learning is interested in learning classifiers of the form\n  $f: \\R^d \\rightarrow L$ that can closely approximate $C$.\n\n\\section{Single Perceptron, Single Point, Single Label}\n  Having truly one label is an uninteresting case,\n  as basically all points would have the same label,\n  and there is nothing to ``learn''.\n  Instead we assume two labels, $L_1$ and $L_2$.\n  We then train a classifier for $L_1$,\n  and assign to $L_2$ whatever is not in $L_1$.\n  \n  Given a single point $p \\in \\R^d$,\n  a single perceptron $c$ \n  with \\emph{weight} vector $w_c \\in \\R^d$, \n  and a \\emph{bias} $b_c \\in \\R$,\n  for classifying a single Label $L_1$,\n  accepts $p$ with the probability\n  \\[ \\hat y_{p,L_1} = \\Prob{\\hat P}{p \\in L_1} =  \\sigmoid{w_c \\cdot p + b_c}\\]\n  where\n  \\[ \\sigmoid{x} = \\frac{e^x}{e^{x} + 1} \\]\n  If the actual classification of the training point \n  is given by $y_{p,L_1} = \\Prob{I}{p \\in L_1}$\n  then training criterion is to minimize \n  the cross entropy:\n  \\begin{eqnarray*} \n    \\mathbb{H} & = & \\Prob{H}{\\mathbb{P}, \\mathbb{\\hat P}} \\\\\n               & = & \\Prob{E}{\\log{ \\frac{1}{\\hat y}}} \\\\\n               & = & \\sum_{L_i \\in L}{\\Prob{H}{y_{p, L_i}, \\hat y_{p, L_i}}}\\\\\n               & = & -\\sum_{L_i \\in L}{y_{p, L_i}\\log{\\hat y_{p, L_i}}}\\\\\n               & = & -y_{p,L_1}\\log(\\hat y_{p,L_1}) - (1 - y_{p,L_1})\\log(1 - \\hat y_{p,L_1})\n   \\end{eqnarray*}\n\n\\section{Multiple Points}\n  Given a set of $t$ points\n  represented as a 2 dimensional tensor $T \\in \\R^{t\\times d}$, \n  the perceptron $c$ can then be \\emph{applied}\n  to all the points in $T$ to get\n  \\[ \\hat y_{T,c} = \\map{T \\cdot w_c + b_c\\overrightarrow{u_t}}{\\sigmoid \\cdot} \\]\n  where \n  \\begin{itemize}\n    \\item $\\map{\\overrightarrow x}{f}$ is\n            the element-wise application of $f$ on $\\overrightarrow x$\n    \\item $\\overrightarrow{u_n} = [1, 1, 1, ... n \\text{ times}]$\n  \\end{itemize}\n  The $i^{th}$ element of $\\hat y_{T, c}$ then gives us\n  the probability of the $i^{th}$ point being in $L_1$.\n  \\[ \\hat y_{T, c}[i] = \\Prob{\\hat P}{T[i] \\in L_1} = \\hat y_{T[i], c}\\]\n  And therefore, if the actual classification \n  of all training points is given by \n  \\[ y_{T,c} = \\map{T}{\\Prob{I}{\\cdot \\in L_1}} \\]\n  then the training criterion is to minimize the cross entropy\n  \\begin{eqnarray*}\n    \\mathbb{H} & = & \\sum_{i=1}^t \\Prob{H}{y_{T, c}[i], \\hat y_{T, c}[i]} \\\\\n               & = & \\text{sum}(\\text{map}(y_{T, c}, \n                                            \\hat y_{T, c}, \n                                            \\Prob{H}{\\cdot, \\cdot}\n                                           )\n                               )\n  \\end{eqnarray*}\n  where\n  \\begin{itemize}\n    \\item $\\text{sum}(x)$ gives the sum of all the elements \n          in the tensor $x$\n    \\item $\\text{map}(x, y, f(\\cdot, \\cdot))$\n          is the element-wise application of\n          the binary function $f$ to the elements of $x$ and $y$.\n          In other words,\n          \\[ \\text{map}(x, y, f(\\cdot, \\cdot))[i] = f(x[i], y[i]) \\]\n  \\end{itemize}\n  \n\\section{Multiple Labels}\n  Classifying a point across multiple labels may be achieved\n  using multiple perceptrons.\n  However, if we simply use the multiple perceptrons independently,\n  we end up with unconstrained probabilities\n  for a point belonging to each label.\n  Instead, we would ideally want the probabilities to add up to 1,\n  since a point can only belong to one label.\n  \n  Suppose we have $l$ labels, and corresponding $l$ perceptrons.\n  Each perceptron produces an output $x_i \\in \\R^t$,\n  where $t$ is the number of points.\n  Then the probability of point $T_j$ \n  belonging to label $L_k$\n  is\n  \\[ \\hat y_{T_j, L_k} = \n        \\frac{e^{x_k[j]}}\n             {\\sum_{m = 1}^{l} e^{x_m[j]} }\n  \\]\n  \n  To simplify this notation, we introduce the softmax function:\n  \\begin{eqnarray*}\n    \\text{softmax}(\\overrightarrow z)\n      & = & \\text{softmax}(z_1, z_2, ... z_n)\n    \\\\\n      & = & \\left[ \\frac{e^{z_1}}{\\sum_{i=1}^n e^{z_i}},\n                   \\frac{e^{z_2}}{\\sum_{i=1}^n e^{z_i}},\n                   ...,\n                   \\frac{e^{z_n}}{\\sum_{i=1}^n e^{z_i}}\n            \\right]\n    \\\\\n    \\text{softmax}(\\overrightarrow z; j)\n      & = & \\frac{e^{z_j}}{\\sum_{i=1}^n e^{z_i}}\n  \\end{eqnarray*}\n  \n  And concisely represent\n  all the probabilities as:\n  \\[\\hat y_{T, L} = \\text{map}(x_1, x_2, ..., x_l, \\text{softmax})\\]\n  \n  Therefore, the training criteria is to minimize the cross-entropy:\n  \\[ \\mathbb{H}(\\hat y_{T, L}, y_{T, L})\n       = \\sum_{T_i \\in T, L_j \\in L} \\mathbb{H}(\\hat y_{T_i, L_j},\n                                                y_{T_i, L_j})\n  \\]\n  \n\\section{Multiple Layers of Perceptrons}\n  Multiple layers of perceptrons,\n  with non-linear activation functions, are necessary\n  for classifying data that is not linearly separable.\n  An activation function is applied to the output of a neuron\n  before feeding it to the next layer.\n  \n\\section{Sample 2-Layer Perceptron}\n  Let the input data be organized\n  into a 2-dimensional structure\n  $T \\in \\R^{t \\times d}$,\n  where $t$ is the number of points\n  and $d$ is the dimensionality of each point.\n  \n  We feed these points to the first layer\n  consisting of, say, $m$ perceptrons.\n  Thus, we have $m$ weight vectors:\n  \\[ w_{1, 1}, w_{1, 2}, ..., w_{1, m} \\in \\R^d \\]\n  and $m$ biases:\n  \\[ b_{1, 1}, b_{1, 2}, ..., b_{1, m} \\in \\R \\]\n  to give the unactivated output \n  $p_{1, i} \\in \\R^{t}$ \n  of the $i^{th}$ perceptron:\n  \\[ p_{1, i} = T \\cdot w_{1, i} + b_{1, i}\\overrightarrow u_{t} \\]\n  \n  These unactivated outputs $p_{1, \\cdot}$ are passed \n  through a sigmoid activation function\n  to get the final activated outputs\n  $z_{1, \\cdot} \\in R^{t}$ \n  of this layer:\n  \\[ z_{1, i} = \\text{map}(p_{1, i}, \\sigmoid{\\cdot})\n  \\]\n  \n  These outputs $z_{1, \\cdot}$ then become \n  the inputs for the next and final layer.\n  For convenience, we define\n  $z_1 \\in \\R^{t \\times m}$\n  as the output vector of the first layer,\n  created by concatenating all the individual outputs.\n  \n  Since se have $l$ labels for classification,\n  the final layer should have $l$ perceptrons.\n  Thus, we have $l$ weight vectors:\n  \\[ w_{2, 1}, w_{2, 2}, ..., w_{2, l} \\in R^m \\]\n  and $l$ biases:\n  \\[ b_{2, 1}, b_{2, 2}, ..., b_{2, l} \\in R \\]\n  to give the unactivated outputs $p_{2, \\cdot} \\in \\R^t$:\n  \\[ p_{2, i} = z_1 \\cdot w_{2, i} + b_{2, i} \\overrightarrow u_{t} \\]\n  \n  We leave the outputs unactivated for this final layer,\n  and concatenate the outputs to get $p_2 \\in {R^{t \\times l}}$\n  Thus, the probabilities $\\hat y \\in \\R^{t \\times l}$\n  of the points belonging to classes is given by:\n  \\[ \\hat y = \\text{map}(p_2, \\text{softmax}(\\cdot)) \\]\n  \n  If the real probabilities are given by $y \\in R^{t \\times l}$\n  then the training criterion is to minimize the cross entropy:\n  \\[\n    \\mathbb{H}\n    = \\Prob{H}{\\hat y, y}\n    = \\sum_{i \\in T, j \\in L} \\Prob{H}{\\hat y_{i, j}, y_{i, j}}\n  \\]\n  \n  \\tikzstyle{io} = [circle, \n                    text centered,\n                    draw=black]\n  \\tikzstyle{perceptron} = [rectangle,\n                            text centered,\n                            draw=black,\n                            minimum width=1.5cm,\n                            minimum height=.8cm,\n                            fill=blue!20]\n  \\tikzstyle{weight} = [rectangle,\n                        text centered,\n                        draw=black,\n                        fill=yellow!30,\n                        rounded corners]\n  \\tikzstyle{arrow} = [thick,->,>=stealth]\n                            \n  \\begin{tikzpicture}[node distance=2cm]\n  \\node (input) [io, fill=green!20] {$T$};\n  \\node (inputlabel) [above of=input] {Input};\n  \n  \\node (p12) [perceptron, right=1cm of input] {$z_{12}$};\n  \\node (p11) [perceptron, above=2cm of p12] {$z_{11}$};\n  \\node (p13) [perceptron, below=2cm of p12] {$z_{13}$};\n  \\node (w11) [weight, below=.5cm of p11] {$w_{11}, b_{11}$};\n  \\node (w12) [weight, below=.5cm of p12] {$w_{12}, b_{12}$};\n  \\node (w13) [weight, below=.5cm of p13] {$w_{13}, b_{13}$};\n  \\node (p1label) [above=0.2cm of p11] {Layer 1};\n  \n  \\node (p22) [perceptron, right=1cm of p12] {$p_{22}$};\n  \\node (p21) [perceptron, above=2cm of p22] {$p_{21}$};\n  \\node (p23) [perceptron, below=2cm of p22] {$p_{23}$};\n  \\node (w21) [weight, below=.5cm of p21] {$w_{21}, b_{21}$};\n  \\node (w22) [weight, below=.5cm of p22] {$w_{22}, b_{22}$};\n  \\node (w23) [weight, below=.5cm of p23] {$w_{23}, b_{23}$};\n  \\node (p2label) [above=0.2cm of p21] {Layer 2};\n  \n  \\node (output) [perceptron, right=1cm of p22] {$\\hat y$};\n  \\node (softmaxlabel) [above of=output] {Prediction};\n  \n  \\node (error) [io, right=1cm of output, fill=red!20] {$\\mathbb{H}$};\n  \\node (errorlabel) [above of=error] {Error};\n  \\node (y) [io, below=.5cm of error, fill=green!20] {$y$};\n  \n  \\draw [arrow] (input) -- (p11.west);\n  \\draw [arrow] (input) -- (p12.west);\n  \\draw [arrow] (input) -- (p13.west);\n  \n  \\draw [arrow] (p11.east) -- (p21.west);\n  \\draw [arrow] (p11.east) -- (p22.west);\n  \\draw [arrow] (p11.east) -- (p23.west);\n  \n  \\draw [arrow] (p12.east) -- (p21.west);\n  \\draw [arrow] (p12.east) -- (p22.west);\n  \\draw [arrow] (p12.east) -- (p23.west);\n  \n  \\draw [arrow] (p13.east) -- (p21.west);\n  \\draw [arrow] (p13.east) -- (p22.west);\n  \\draw [arrow] (p13.east) -- (p23.west);\n  \n  \\draw [arrow] (p21.east) -- (output);\n  \\draw [arrow] (p22.east) -- (output);\n  \\draw [arrow] (p23.east) -- (output);\n  \n  \\draw [arrow] (w11) -- (p11);\n  \\draw [arrow] (w12) -- (p12);\n  \\draw [arrow] (w13) -- (p13);\n  \\draw [arrow] (w21) -- (p21);\n  \\draw [arrow] (w22) -- (p22);\n  \\draw [arrow] (w23) -- (p23);\n  \n  \\draw [arrow] (output) -- (error);\n  \\draw [arrow] (y) -- (error);\n  \\end{tikzpicture}\n\n\\end{document}\n", "meta": {"hexsha": "4184190dd7ab78a8ebeb83db2de393bbb5eb6e69", "size": 10904, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tex/MultiLayerPerceptron.tex", "max_stars_repo_name": "appu226/ParaGraph", "max_stars_repo_head_hexsha": "82604a286b50d414515f22521882115980f2ee80", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-17T08:52:06.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-17T08:52:06.000Z", "max_issues_repo_path": "doc/tex/MultiLayerPerceptron.tex", "max_issues_repo_name": "appu226/ParaGraph", "max_issues_repo_head_hexsha": "82604a286b50d414515f22521882115980f2ee80", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2018-03-31T17:26:01.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-04T15:17:48.000Z", "max_forks_repo_path": "doc/tex/MultiLayerPerceptron.tex", "max_forks_repo_name": "appu226/ParaGraph", "max_forks_repo_head_hexsha": "82604a286b50d414515f22521882115980f2ee80", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.470790378, "max_line_length": 93, "alphanum_fraction": 0.582355099, "num_tokens": 3800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.7048108818149662}}
{"text": "\\subsection{Geometric description of the cross product}\n\nThe following is the geometric description of the cross\nproduct. Recall that the dot product of two vectors results in a\nscalar. In contrast, the cross product results in a vector, as the\ncross product gives a direction as well as a magnitude.%\n\\index{cross product!geometric description}\n\n\\begin{definition}{Geometric definition of cross product}{cross-product-geometric}\n  Let\\/ $\\vect{u}$ and $\\vect{v}$ be two vectors in $\\R^3$. Their\n  \\textbf{cross product}%\n  \\index{cross product}, written $\\vect{u}\\times \\vect{v}$, is the\n  vector defined by the following three rules.%\n  \\index{cross product!geometric description}\n\n  \\begin{enumerate}\n  \\item Its length is $\\norm{\\vect{u}\\times \\vect{v}} =\\norm{\\vect{u}} \\norm{\n      \\vect{v}} \\sin \\theta$,\n    where $\\theta$ is the included angle between $\\vect{u}$ and $\\vect{v}$.\n\n  \\item It is orthogonal to both $\\vect{u}$ and $\\vect{v}$.\n\n  \\item The vectors $\\vect{u}$, $\\vect{v}$, and $\\vect{u}\\times\n    \\vect{v}$, in that order, form a right-handed system.\n  \\end{enumerate}\n\\end{definition}\n\nWe note that the length of the cross product,\n$\\norm{\\vect{u}\\times\\vect{v}}$, given by the formula\n$\\norm{\\vect{u}}\\norm{\\vect{v}}\\sin\\theta$, is the area of the\nparallelogram determined by $\\vect{u}$ and $\\vect{v}$, as shown in the\nfollowing picture.%\n\\index{cross product!area of parallelogram}%\n\\index{area!of parallelogram}%\n\\index{parallelogram!area of}%\n\\begin{center}\n  \\begin{tikzpicture}[scale=1.3]\n    \\filldraw[fill=green!20,draw=green!50!black] (0,0) -- (0:8mm) arc (0:45:8mm) -- cycle;\n    \\draw[->,thick,red] (0,0) -- node[left] {$\\vect{v}$} (2,2);\n    \\draw[->,thick,blue] (0,0) -- node[below] {$\\vect{u}$} (3,0);\n    \\draw[thick] (2,2)--(5,2);\n    \\draw[thick] (3,0)--(5,2);\n    \\draw[dashed] (2,2)--(2,0);\n    \\node[green!30!black] at (22.5:5.5mm) {$\\theta$};\n    \\node[right] at (2,1){$\\norm{\\vect{v}} \\sin(\\theta)$};\n  \\end{tikzpicture}\n\\end{center}\n", "meta": {"hexsha": "fc1b43431a8d55a78050eb5c197d30c7d652f9db", "size": 1978, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Vectors-CrossProduct-Geometric.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Vectors-CrossProduct-Geometric.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Vectors-CrossProduct-Geometric.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 41.2083333333, "max_line_length": 90, "alphanum_fraction": 0.6648129424, "num_tokens": 669, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.9005297867852854, "lm_q1q2_score": 0.7048108752963317}}
{"text": "\\section{Function extensionality}\n\\label{chap:funext}\n\n\\subsection{Equivalent forms of function extensionality}\n\n\\begin{axiom}[Function Extensionality]\\label{axiom:funext}\n  \\index{function extensionality}\\index{identity type!of a Pi-type@{of a $\\Pi$-type}}\\index{extensionality principle!for functions}%\n  For any type family $B$ over $A$, and any two dependent functions $f,g:\\prd{x:A}B(x)$, the canonical map\\index{htpy-eq@{$\\htpyeq$}}\\index{htpy-eq@{$\\htpyeq$}!is an equivalence}\\index{is an equivalence!htpy-eq@{$\\htpyeq$}}\n  \\begin{equation*}\n    \\htpyeq:(f=g)\\to (f\\htpy g)\n  \\end{equation*}\n  that sends $\\refl{f}$ to $\\reflhtpy_{f}$ is an equivalence. We will write $\\eqhtpy$\\index{eq-htpy@{$\\eqhtpy$}} for its inverse.\n\\end{axiom}\n\nIn other words, the axiom of function extensionality asserts that for any two dependent functions $f,g:\\prd{x:A}B(x)$, the type of identifications $f=g$ is equivalent to the type of homotopies $f\\htpy g$ from $f$ to $g$. By the fundamental theorem of identity types (\\cref{thm:id_fundamental})\\index{fundamental theorem of identity types} there are three equivalent ways of asserting function extensionality. In the following theorem we state one further equivalent condition.\n\n\\begin{thm}\\label{thm:funext_wkfunext}\nThe following are equivalent:\\index{function extensionality}\n\\begin{enumerate}\n\\item The axiom of function extensionality.\n\\item For any type family $B$ over $A$ and any dependent function $f:\\prd{x:A}B(x)$, the total space\n  \\begin{equation*}\n    \\sm{g:\\prd{x:A}B(x)}f\\htpy g\n  \\end{equation*}\n  is contractible.\n\\item\n  The principle of \\define{homotopy induction}\\index{homotopy induction}\\index{induction principle!for homotopies}:\n  for any type family $B$ over $A$, any dependent function $f:\\prd{x:A}B(x)$, and any family of types $P(g,H)$ indexed by $g:\\prd{x:A}B(x)$ and $H:f\\htpy g$, the evaluation function\n\\begin{equation*}\n\\Big(\\prd{g:\\prd{x:A}B(x)}{H:f\\htpy g}P(g,H)\\Big)\\to P(f,\\reflhtpy_f)\n\\end{equation*}\ngiven by $s\\mapsto s(f,\\reflhtpy_f)$ has a section.\n\\item The \\define{weak function extensionality principle}\\index{weak function extensionality} holds: For every type family $B$ over $A$ one has\\index{contractible!weak function extensionality}\n\\begin{equation*}\n\\Big(\\prd{x:A}\\iscontr(B(x))\\Big)\\to\\iscontr\\Big(\\prd{x:A}B(x)\\Big).\n\\end{equation*}\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nThe fact that function extensionality is equivalent to (ii) and (iii) follows directly from \\cref{thm:id_fundamental}.\n\nTo show that function extensionality implies weak function extensionality, suppose that each $B(a)$ is contractible with center of contraction $c(a)$ and contraction $C_a:\\prd{y:B(a)}c(a)=y$. Then we take $c\\defeq \\lam{a}c(a)$ to be the center of contraction of $\\prd{x:A}B(x)$. To construct the contraction we have to define a term of type\n\\begin{equation*}\n\\prd{f:\\prd{x:A}B(x)}c=f.\n\\end{equation*}\nLet $f:\\prd{x:A}B(x)$. By function extensionality we have a map $(c\\htpy f)\\to (c=f)$, so it suffices to construct a term of type $c\\htpy f$. Here we take $\\lam{a}C_a(f(a))$. This completes the proof that function extensionality implies weak function extensionality.\n\nIn the remaining part of the proof, we will show that weak function extensionality implies that the type\n\\begin{equation*}\n\\sm{g:\\prd{x:A}B(x)}f\\htpy g\n\\end{equation*}\nis contractible for any $f:\\prd{x:A}B(x)$. In order to do this, we first note that we have a section-retraction pair\n\\begin{equation*}\n  \\begin{tikzcd}[column sep=small]\n    \\Big(\\sm{g:\\prd{x:A}B(x)}f\\htpy g\\Big) \\arrow[r,\"i\"] & \\Big(\\prd{x:A}\\sm{b:B(x)}f(x)=b\\Big) \\arrow[r,\"r\"] & \\Big(\\sm{g:\\prd{x:A}B(x)}f\\htpy g\\Big).\n  \\end{tikzcd}\n\\end{equation*}\nHere we have the functions\n\\begin{align*}\ni & \\defeq \\lam{(g,H)}{x}(g(x),H(x)) \\\\\nr & \\defeq \\lam{p}\\pairr{\\lam{x}\\proj 1(p(x)),\\lam{x}\\proj 2(p(x))}.\n\\end{align*}\nTheir composite is homotopic to the identity function by the computation rule for $\\Sigma$-types and the $\\eta$-rule for $\\Pi$-types:\n\\begin{align*}\nr(i(g,H)) & \\jdeq r(\\lam{x}\\pairr{g(x),H(x)}) \\\\\n& \\jdeq \\pairr{\\lam{x}g(x),\\lam{x}H(x)} \\\\\n& \\jdeq \\pairr{g,H}.\n\\end{align*}\nNow we observe that the type $\\prd{x:A}\\sm{b:B(x)}f(x)=b$ is a product of contractible types, so it is contractible by our assumption of the weak function extensionality principle. The claim therefore follows, since retracts of contractible types are contractible by \\cref{ex:contr_retr}\\index{contractible!retract of}.\n\\end{proof}\n\nFor the remainder of this chapter we will assume that the function extensionality axiom holds\\index{axiom!function extensionality}. In \\cref{thm:funext-univalence} we will derive function extensionality from the univalence axiom. \n\nAs a first application of the function extensionality axiom we generalize the weak function extensionality axiom to $k$-types.\n\n\\begin{thm}\\label{thm:trunc_pi}\\index{k-type@{$k$-type}}\nFor any type family $B$ over $A$ one has\\index{truncated type!closed under Pi@{closed under $\\Pi$}}\n\\begin{equation*}\n\\Big(\\prd{x:A}\\istrunc{k}(B(x))\\Big)\\to \\istrunc{k}\\Big(\\prd{x:A}B(x)\\Big).\n\\end{equation*}\n\\end{thm}\n\n\\begin{proof}\nThe theorem is proven by induction on $k\\geq -2$. The base case is just the weak function extensionality principle\\index{weak function extensionality}, which was shown to follow from function extensionality in \\cref{thm:funext_wkfunext}.\n\nFor the inductive hypothesis, assume that the $k$-types are closed under dependent function types. Assume that $B$ is a family of $(k+1)$-types. By function extensionality, the type $f=g$ is equivalent to $f\\htpy g$ for any two dependent functions $f,g:\\prd{x:A}B(x)$. Now observe that $f\\htpy g$ is a dependent product of $k$-types, and therefore it is an $k$-type by our inductive hypotheses. Therefore, it follows by \\cref{thm:ktype_eqv} that $f=g$ is an $k$-type, and hence that $\\prd{x:A}B(x)$ is an $(k+1)$-type.\n\\end{proof}\n\n\\begin{cor}\\label{cor:funtype_trunc}\\index{truncated type!closed under exponentials}\nSuppose $B$ is a $k$-type. Then $A\\to B$ is also a $k$-type, for any type $A$.\n\\end{cor}\n\n\\subsection{The type theoretic principle of choice}\n\nThe type theoretic principle of choice\\index{type theoretic choice} asserts that $\\Pi$ distributes over $\\Sigma$\\index{distributivity!of Pi over Sigma@{of $\\Pi$ over $\\Sigma$}}. More precisely, it asserts that the canonical map\\index{choice@{$\\choice$}}\n\\begin{equation*}\n  \\choice:\\Big(\\prd{x:A}\\sm{y:B(x)}C(x,y)\\Big)\\to \\Big(\\sm{f:\\prd{x:A}B(x)}\\prd{x:A}C(x,f(x))\\Big)\n\\end{equation*}\ngiven by $\\lam{h}(\\proj 1(h(x)),\\proj 2(h(x)))$, is an equivalence. In order to see this as a principle of choice, one can view the left hand side as the type of functions $h$ that pick for every $x:A$ a term $y:B(x)$ equipped with a term of type $C(x,y)$. The function $\\choice$ then constructs a dependent function $f:\\prd{x:A}B(x)$ equipped with a term of type $\\prd{x:A}C(x,f(x))$. In this section we show that the map $\\choice$ is an equivalence, and we use this to characterize the identity of any dependent function type $\\prd{x:A}B(x)$ in terms of any characterization of the identity types of the individual types $B(x)$.\n\n\\begin{thm}\\label{thm:choice}\nConsider a family of types $C(x,y)$ indexed by $x:A$ and $y:B(x)$. Then the map\n\\begin{equation*}\n  \\choice:\\Big(\\prd{x:A}\\sm{y:B(x)}C(x,y)\\Big)\\to \\Big(\\sm{f:\\prd{x:A}B(x)}\\prd{x:A}C(x,f(x))\\Big)\n\\end{equation*}\ngiven by $\\lam{h}(\\proj 1(h(x)),\\proj 2(h(x)))$ is an equivalence.\n\\end{thm}\n\n\\begin{proof}\n  We define the map\\index{choice-1@{$\\choice^{-1}$}}\n  \\begin{equation*}\n    \\choice^{-1}:\\Big(\\sm{f:\\prd{x:A}B(x)}\\prd{x:A}C(x,f(x))\\Big)\\to\\Big(\\prd{x:A}\\sm{y:B(x)}C(x,y)\\Big)\n  \\end{equation*}\n  by $\\lam{(f,g)}{x}(f(x),g(x))$. Then we have to construct homotopies\n  \\begin{equation*}\n    \\choice\\circ\\choice^{-1}\\htpy\\idfunc,\\qquad\\text{and}\\qquad\n    \\choice^{-1}\\circ\\choice\\htpy\\idfunc.\n  \\end{equation*}\n  For the first homotopy it suffices to construct an identification\n  \\begin{equation*}\n    \\choice(\\choice^{-1}(f,g))=(f,g)\n  \\end{equation*}\n  for any $f:\\prd{x:A}B(x)$ and any $g:\\prd{x:A}C(x,f(x))$. We compute the left-hand side as follows:\n  \\begin{align*}\n    \\choice(\\choice^{-1}(f,g))\n    & \\jdeq \\choice(\\lam{x}(f(x),g(x))) \\\\\n    & \\jdeq (\\lam{x}f(x),\\lam{x}g(x)).\n  \\end{align*}\n  By the $\\eta$-rule it follows that $f\\jdeq \\lam{x}f(x)$ and $g\\jdeq\\lam{x}g(x)$. Therefore we have the identification\n  \\begin{equation*}\n    \\refl{(f,g)}:\\choice(\\choice^{-1}(f,g))=(f,g).\n  \\end{equation*}\n  This completes the construction of the first homotopy.\n\n  For the second homotopy we have to construct an identification\n  \\begin{equation*}\n    \\choice^{-1}(\\choice(h))=h\n  \\end{equation*}\n  for any $h:\\prd{x:A}\\sm{y:B(x)}C(x,y)$. We compute the left-hand side as follows:\n  \\begin{align*}\n    \\choice^{-1}(\\choice(h))\n    & \\jdeq \\choice^{-1}(\\lam{x}\\proj 1(h(x)),(\\lam{x}\\proj 2(h(x)))) \\\\\n    & \\jdeq \\lam{x}(\\proj 1(h(x)),\\proj 2(h(x)))\n  \\end{align*}\n  However, it is \\emph{not} the case that $(\\proj 1(h(x)),\\proj 2(h(x)))\\jdeq h(x)$ for any $h:\\prd{x:A}\\sm{y:B(x)}C(x,y)$. Nevertheless, we have the identification\n  \\begin{equation*}\n    \\eqpair(\\refl{},\\refl{}):(\\proj 1(h(x)),\\proj 2(h(x)))= h(x).\n  \\end{equation*}\n  Therefore we obtain the required homotopy by function extensionality:\n  \\begin{equation*}\n    \\lam{h}\\eqhtpy(\\lam{x}\\eqpair(\\refl{\\proj 1(h(x))},\\refl{\\proj 2(h(x))})):\\choice^{-1}\\circ\\choice\\htpy\\idfunc.\\qedhere\n  \\end{equation*}\n\\end{proof}\n\n\\begin{cor}\nFor type $A$ and any type family $C$ over $B$, the map\n\\begin{equation*}\n\\Big(\\sm{f:A\\to B} \\prd{x:A}C(f(x))\\Big)\\to\\Big(A\\to\\sm{y:B}C(x)\\Big)\n\\end{equation*}\ngiven by $\\lam{(f,g)}{x}(f(x),g(x))$ is an equivalence.\n\\end{cor}\n\n\\begin{rmk}\n  The type theoretic choice principle can be used to derive the binomial theorem\\index{binomial theorem}. We give an informal argument of how this goes. Recall that the binomial theorem asserts that\n  \\begin{equation*}\n    (n+m)^k=\\sum_{l=0}^k\\binom{k}{l}n^l m^{k-l}\n  \\end{equation*}\n  for any three natural numbers $k,m,n$.\n\n  Consider the types $A\\defeq\\Fin(k)$\\index{Fin@{$\\Fin$}}, $B\\defeq\\Fin(n)$ and $C\\defeq\\Fin(m)$. Then we can define the type family $P:\\bool\\to\\UU$ given by\n  \\begin{align*}\n    P(\\btrue) & \\defeq B \\\\\n    P(\\bfalse) & \\defeq C.\n  \\end{align*}\n  Now, the type theoretic principle of choice gives us an equivalence\n  \\begin{equation*}\n    \\Big(\\prd{x:A}\\sm{t:\\bool}P(t)\\Big)\\simeq \\Big(\\sm{f:A\\to\\bool}\\prd{x:A}P(f(x))\\Big).\n  \\end{equation*}\n  Now we note that the type $(f(x)=1)+(f(x)=0)$ is contractible for any $f:A\\to\\bool$ and $x:A$. Therefore we have equivalences\n  \\begin{align*}\n    \\sm{f:A\\to\\bool}\\prd{x:A}P(f(x)) & \\simeq\n    \\sm{f:A\\to\\bool}\\prd{x:A}{t:(f(x)=1)+(f(x)=0)}P(f(x)) \\\\\n    & \\simeq \\sm{f:A\\to\\bool}(\\fib{f}{1}\\to B)\\times (\\fib{f}{0}\\to C)\n  \\end{align*}\n  Now we note that, because there are $\\binom{k}{l}$\\index{binomial coefficient} ways to choose a subset of $l$ elements of $A$, there are\n  \\begin{equation*}\n    \\sum_{l=0}^k\\binom{k}{l}n^l m^{k-l}\n  \\end{equation*}\n  elements in the above type.\n\\end{rmk}\n\n\\subsection{Universal properties}\nThe function extensionality principle allows us to prove \\emph{universal properties}. Universal properties are characterizations of all maps out of or into a given type, so they are very important. Among other applications, universal properties characterize a type up to equivalence. In the following theorem we prove the universal property of dependent pair types.\n\n\\begin{thm}\\index{universal property!Sigma-types@{$\\Sigma$-types}}\\index{Sigma-type@{$\\Sigma$-type}!universal property}\nLet $B$ be a type family over $A$, and let $X$ be a type. Then the map\\index{ev-pair@{$\\evpair$}}\n\\begin{equation*}\n\\evpair:\\Big(\\Big(\\sm{x:A}B(x)\\Big)\\to X\\Big)\\to \\Big(\\prd{x:A}(B(x)\\to X)\\Big)\n\\end{equation*}\ngiven by $f\\mapsto\\lam{a}{b}f(a,b)$ is an equivalence.\n\\end{thm}\n\n\\begin{proof}\nThe map in the converse direction is simply\n\\begin{equation*}\n\\ind{\\Sigma} : \\Big(\\prd{x:A}(B(x)\\to X)\\Big)\\to \\Big(\\Big(\\sm{x:A}B(x)\\Big)\\to X\\Big).\n\\end{equation*}\nBy the computation rules for $\\Sigma$-types we have\n\\begin{equation*}\n\\lam{f}\\refl{f}:\\evpair\\circ\\ind{\\Sigma}\\htpy\\idfunc\n\\end{equation*}\n\nTo show that $\\ind{\\Sigma}\\circ\\evpair\\htpy\\idfunc$ we will also apply function extensionality. Thus, it suffices to show that $\\ind{\\Sigma}(\\lam{x}{y}f((x,y)))=f$. We apply function extensionality again, so it suffices to show that\n\\begin{equation*}\n\\prd{t:\\sm{x:A}B(x)}\\ind{\\Sigma}\\big(\\lam{x}{y}f((x,y))\\big)(t)=f(t).\n\\end{equation*}\nWe obtain this homotopy by another application of $\\Sigma$-induction. \n\\end{proof}\n\n\\begin{cor}\\label{cor:times_up_out}\\index{universal property!cartesian product}\\index{cartesian product!universal property}\nLet $A$, $B$, and $X$ be types. Then the map\\index{ev-pair@{$\\evpair$}}\n\\begin{equation*}\n\\evpair: (A\\times B \\to X)\\to (A\\to (B\\to X))\n\\end{equation*}\ngiven by $f\\mapsto\\lam{a}{b}f((a,b))$ is an equivalence.\n\\end{cor}\n\nThe universal property of identity types is sometimes called the \\emph{type theoretical Yoneda lemma}\\index{Yoneda lemma (type theoretical)}: families of maps out of the identity type are uniquely determined by their action on the reflexivity identification.\n\n\\begin{thm}\\label{thm:yoneda}\\index{universal property!identity type}\\index{identity type!universal property}\nLet $B$ be a type family over $A$, and let $a:A$. Then the map\\index{ev-refl@{$\\evrefl$}}\n\\begin{equation*}\n\\evrefl:\\Big(\\prd{x:A} (a=x)\\to B(x)\\Big)\\to B(a)\n\\end{equation*}\ngiven by $\\lam{f} f(a,\\refl{a})$ is an equivalence. \n\\end{thm}\n\n\\begin{proof}\nThe inverse $\\varphi$ is defined by path induction, taking $b:B(a)$ to the function $f$ satisfying $f(a,\\refl{a})\\jdeq b$. It is immediate that $\\evrefl\\circ\\varphi\\htpy \\idfunc$.\n\nTo see that $\\varphi\\circ \\evrefl\\htpy\\idfunc$, let $f:\\prd{x:A}(a=x)\\to B(x)$. To show that $\\varphi(f(a,\\refl{a}))=f$ we use function extensionality (twice), so it suffices to show that\n\\begin{equation*}\n\\prd{x:A}{p:a=x} \\varphi(f(a,\\refl{a}),x,p)=f(x,p).\n\\end{equation*}\nThis follows by path induction on $p$, since $\\varphi(f(a,\\refl{a}),a,\\refl{a})\\jdeq f(a,\\refl{a})$.\n\\end{proof}\n\n\\subsection{Composing with equivalences}\n\nWe show in this section that a map $f:A\\to B$ is an equivalence if and only if for any type $X$ the precomposition map\\index{precomposition map}\n\\begin{equation*}\n\\blank\\circ f: (B\\to X)\\to (A\\to X)\n\\end{equation*}\nis an equivalence. Moreover, we will show in \\cref{ex:equiv_precomp} that the `dependent version' of this statement also holds: a map $f:A\\to B$ is an equivalence if and only if for any type family $P$ over $B$, the precomposition map\n\\begin{equation*}\n\\blank\\circ f: \\Big(\\prd{y:B}P(y)\\Big)\\to\\Big(\\prd{x:A}P(f(x))\\Big)\n\\end{equation*}\nis an equivalence.\n\n\\begin{thm}\\label{ex:equiv_precomp}\\index{equivalence!precomposition}\nFor any map $f:A\\to B$, the following are equivalent:\n\\begin{enumerate}\n\\item $f$ is an equivalence.\n\\item For any type family $P$ over $B$ the map\n\\begin{equation*}\n\\Big(\\prd{y:B}P(y)\\Big)\\to\\Big(\\prd{x:A}P(f(x))\\Big)\n\\end{equation*}\ngiven by $h\\mapsto h\\circ f$ is an equivalence.\n\\item For any type $X$ the map\n\\begin{equation*}\n(B\\to X)\\to (A\\to X)\n\\end{equation*}\ngiven by $g\\mapsto g\\circ f$ is an equivalence. \n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nTo show that (i) implies (ii), we first recall from \\cref{lem:coherently-invertible} that any equivalence is also coherently invertible\\index{coherently invertible}. Therefore $f$ comes equipped with\n\\begin{align*}\ng & : B \\to A\\\\\nG & : f\\circ g \\htpy \\idfunc[B] \\\\\nH & : g\\circ f \\htpy \\idfunc[A] \\\\\nK & : G\\cdot f \\htpy f\\cdot H.\n\\end{align*}\nThen we define the inverse of $\\blank\\circ f$ to be the map\n\\begin{equation*}\n\\varphi:\\Big(\\prd{x:A}P(f(x))\\Big)\\to\\Big(\\prd{y:B}P(y)\\Big)\n\\end{equation*}\ngiven by $h\\mapsto \\lam{y}\\tr_P(G(y),h(g(y)))$. \n\nTo see that $\\varphi$ is a section of $\\blank\\circ f$, let $h:\\prd{x:A}P(f(x))$. By function extensionality it suffices to construct a homotopy $\\varphi(h)\\circ f\\htpy h$. In other words, we have to show that\n\\begin{equation*}\n\\tr_P(G(f(x)),h(g(f(x)))=h(x)\n\\end{equation*}\nfor any $x:A$. Now we use the additional homotopy $K$ from our assumption that $f$ is coherently invertible. Since we have $K(x):G(f(x))=\\ap{f}{H(x)}$ it suffices to show that\n\\begin{equation*}\n\\tr_P(\\ap{f}{H(x)},hgf(x))=h(x).\n\\end{equation*}\nA simple path-induction argument yields that\n\\begin{equation*}\n\\tr_P(\\ap{f}{p})\\htpy \\tr_{P\\circ f}(p)\n\\end{equation*}\nfor any path $p:x=y$ in $A$, so it suffices to construct an identification\n\\begin{equation*}\n\\tr_{P\\circ f}(H(x),hgf(x))=h(x).\n\\end{equation*}\nWe have such an identification by $\\apd{h}{H(x)}$.\n\nTo see that $\\varphi$ is a retraction of $\\blank\\circ f$, let $h:\\prd{y:B}P(y)$. By function extensionality it suffices to construct a homotopy $\\varphi(h\\circ f)\\htpy h$. In other words, we have to show that\n\\begin{equation*}\n\\tr_P(G(y),hfg(y))=h(y)\n\\end{equation*}\nfor any $y:B$. We have such an identification by $\\apd{h}{G(y)}$. This completes the proof that (i) implies (ii).\n\nNote that (iii) is an immediate consequence of (ii), since we can just choose $P$ to be the constant family $X$.\n\nIt remains to show that (iii) implies (i). Suppose that\n\\begin{equation*}\n\\blank\\circ f:(B\\to X)\\to (A\\to X)\n\\end{equation*}\nis an equivalence for every type $X$. Then its fibers are contractible by \\cref{thm:contr_equiv}. In particular, choosing $X\\jdeq A$ we see that the fiber\n\\begin{equation*}\n\\fib{\\blank\\circ f}{\\idfunc[A]}\\jdeq \\sm{h:B\\to A}h\\circ f=\\idfunc[A]\n\\end{equation*}\nis contractible. Thus we obtain a function $h:B\\to A$ and a homotopy $H:h\\circ f\\htpy\\idfunc[A]$ showing that $h$ is a retraction of $f$. We will show that $h$ is also a section of $f$. To see this, we use that the fiber\n\\begin{equation*}\n\\fib{\\blank\\circ f}{f}\\jdeq \\sm{i:B\\to B} i\\circ f=f\n\\end{equation*}\nis contractible (choosing $X\\jdeq B$). \nOf course we have $(\\idfunc[B],\\refl{f})$ in this fiber. However we claim that there also is an identification $p:(f\\circ h)\\circ f=f$, showing that $(f\\circ h,p)$ is in this fiber, because\n\\begin{align*}\n(f\\circ h)\\circ f & \\jdeq f\\circ (h\\circ f) \\\\\n& = f\\circ \\idfunc[A] \\\\\n& \\jdeq f\n\\end{align*}\nNow we conclude by the contractibility of the fiber that $(\\idfunc[B],\\refl{f})=(f\\circ h,p)$. In particular we obtain that $\\idfunc[B]=f\\circ h$, showing that $h$ is a section of $f$.\n\\end{proof}\n\n\\begin{exercises}\n\\exercise Show that the functions\\index{inv-htpy@{$\\invhtpy$}!is an equivalence}\\index{concat-htpy@{$\\concathtpy$}!is a family of equivalences}\\index{concat-htpy'@{$\\concathtpy'$}!is a family of equivalences}\\index{is an equivalence!inv-htpy@{$\\invhtpy$}}\\index{is an equivalence!concat-htpy(H)@{$\\concathtpy(H)$}}\\index{is an equivalence!concat-htpy'(K)@{$\\concathtpy'(K)$}}\n\\begin{align*}\n\\invhtpy & : (f \\htpy g) \\to (g \\htpy f) \\\\\n\\concathtpy(H) & : (g \\htpy h) \\to (f \\htpy h) \\\\\n\\concathtpy'(K) & : (f \\htpy g) \\to (f \\htpy h)\n\\end{align*}\nare equivalences for every $f,g,h : \\prd{x:A}B(x)$. Here, $\\concathtpy'(K)$ is the function defined by $H\\mapsto \\ct{H}{K}$.\n\\exercise \\label{ex:isprop_istrunc}\n\\begin{subexenum}\n\\item Show that for any type $A$ the type $\\iscontr(A)$ is a proposition\\index{is-cont(A)r@{$\\iscontr(A)$}!is a proposition}\\index{is contractible!is a property}. %There's an easy proof using double singleton induction. This is a nice application of weak funext.\n\\item Show that for any type $A$ and any $k\\geq-2$, the type $\\istrunc{k}(A)$ is a proposition.\\index{istrunc@{$\\istrunc{k}$}!is a proposition}\n\\end{subexenum}\n\\exercise \\label{lem:postcomp_equiv}\nLet $f:X\\to Y$ be a map. Show that the following are equivalent:\n\\begin{enumerate}\n\\item $f$ is an equivalence.\\index{equivalence!postcomposition}\n\\item The map $f\\circ\\blank : X^A\\to Y^A$ is an equivalence for every type $A$.\n\\end{enumerate}\n\\exercise \\label{ex:isprop_isequiv}Let $f:A\\to B$ be a function.\n\\begin{subexenum}\n\\item Show that if $f$ is an equivalence, then the type $\\sm{g:B\\to A}f\\circ g\\htpy \\idfunc$ of sections of $f$ is contractible.\n\\item Show that if $f$ is an equivalence, then the type $\\sm{h:B\\to A}h\\circ f\\htpy \\idfunc$ of retractions of $f$ is contractible.\n\\item Show that $\\isequiv(f)$ is a proposition.\\index{is-equiv(f)@{$\\isequiv(f)$}!is a proposition}\n\\item Use \\cref{ex:prop_equiv,ex:isprop_istrunc} to show that $\\isequiv(f)\\eqvsym \\iscontr(f)$.\\index{is-equiv(f)@{$\\isequiv(f)$}!is-equiv(f) is-contr(f)@{$\\isequiv(f)\\eqvsym\\iscontr(f)$}}\n\\end{subexenum}\nConclude that $\\eqv{A}{B}$ is a subtype of $A\\to B$, and in particular that the map $\\proj 1 : (\\eqv{A}{B})\\to (A\\to B)$ is an embedding.\n\\exercise \\label{ex:prop_equiv}\n\\begin{subexenum}\n\\item \\label{ex:equiv-bi-implication}Let $P$ and $Q$ be propositions. Show that\\index{bi-implication}\n\\begin{equation*}\n\\eqv{(P\\leftrightarrow Q)}{(\\eqv{P}{Q})}.\n\\end{equation*}\n\\item Show that $P$ is a proposition if and only if $P\\to P$ is contractible.\n\\end{subexenum}\n\\exercise Show that $\\pathsplit(f)$\\index{path-split!is a proposition} and $\\iscohinvertible(f)$\\index{coherently invertible!is a proposition} are propositions for any map $f:A\\to B$. Conclude that we have equivalences\\index{is-equiv(f)@{$\\isequiv(f)$}!is-equiv(f) path-split(f)@{$\\isequiv(f)\\eqvsym\\pathsplit(f)$}}\\index{is-equiv(f)@{$\\isequiv(f)$}!is-equiv(f) is-coh-invertible(f)@{$\\isequiv(f)\\eqvsym\\iscohinvertible(f)$}}\n  \\begin{equation*}\n    \\isequiv(f) \\eqvsym \\pathsplit(f) \\eqvsym \\iscohinvertible(f).\n  \\end{equation*}\n%\\item Let $B$ and $C$ be type families over $A$, suppose that $p:\\id{a}{a'}$ in $A$, and consider two functions $f:B(a)\\to C(a)$ and $g:B(a')\\to C(a')$.\n%\\begin{subexenum}\n%\\item Show that the square\n%\\begin{equation*}\n%\\begin{tikzcd}\n%B(a) \\arrow[r,\"f\"] \\arrow[d,swap,\"\\tr_B(p)\"] & C(a) \\arrow[d,\"\\tr_C(p)\"] \\\\\n%B(a') \\arrow[r,swap,\"g\"] & C(a')\n%\\end{tikzcd}\n%\\end{equation*}\n%commutes for every homotopy $H:\\tr_{B(x)\\to C(x)}(p,f)\\htpy g$. In other words, construct a function of type\n%\\begin{equation*} \n%\\Big(\\tr_{B(x)\\to C(x)}(p,f)\\htpy g\\Big)\\to \\Big(\\tr_C(p)\\circ f\\htpy g\\circ \\tr_B(p)\\Big)\n%\\end{equation*}\n%\\item Show that this map is an equivalence.\n%\\end{subexenum}\n\\exercise \\label{ex:idfunc_autohtpy}Construct for any type $A$ an equivalence\\index{has-inverse(f)@{$\\hasinverse(f)$}!has-inverse(id) id htpy id@{$\\hasinverse(\\idfunc)\\simeq (\\idfunc\\htpy\\idfunc)$}}\n\\begin{equation*}\n\\eqv{\\hasinverse(\\idfunc[A])}{\\Big(\\idfunc[A]\\htpy\\idfunc[A]\\Big)}.\n\\end{equation*}\nNote: We will use this fact in \\cref{ex:is_invertible_id_S1} to show that there\nare types for which $\\isinvertible(\\idfunc[A])\\not\\eqvsym\\isequiv(\\idfunc[A])$.\n\\exercise\n\\begin{subexenum}\n\\item Show that the type\\index{universal property!empty type}\\index{empty type!universal property}\n\\begin{equation*}\n\\prd{t:\\emptyt}P(t)\n\\end{equation*}\nis contractible for any $P:\\emptyt\\to \\UU$.\n\\item Show that for any type $X$ the following are equivalent:\n  \\begin{enumerate}\n  \\item the unique map $\\emptyt \\to X$ is an equivalence.\n  \\item The type $Y^X$ is contractible for any type $Y$.\n  \\end{enumerate}\n\\end{subexenum}\n\\exercise Consider two types $A$ and $B$.\\index{universal property!coproduct}\\index{coproduct!universal property}\n\\begin{subexenum}\n\\item Show that the map\\index{ev-inl-inr@{$\\evinlinr$}}\n\\begin{equation*}\n  \\evinlinr: \\Big(\\prd{t:A+B}P(t)\\Big) \\to\n  \\Big(\\prd{x:A}P(\\inl(x))\\Big)\\times\\Big(\\prd{y:B}P(\\inr(y))\\Big)\n\\end{equation*}\ngiven by $f\\mapsto (f\\circ\\inl,f\\circ\\inr)$ is an equivalence.\n\\item Show that the following are equivalent for any type $X$ equipped with maps $i:A\\to X$ and $j:B\\to X$:\n  \\begin{enumerate}\n  \\item The map $\\indcoprod(i,j) :A+B\\to X$ is an equivalence.\n  \\item For any type $Y$, the map\n    \\begin{equation*}\n      \\lam{f}(f\\circ i,f\\circ j):(X\\to Y)\\to (A\\to Y)\\times (B \\to Y)\n    \\end{equation*}\n    is an equivalence.\n  \\end{enumerate}\n\\end{subexenum}\n\\exercise \n\\begin{subexenum}\n\\item Show that the map\\index{universal property!unit type}\\index{unit type!universal property}\\index{ev-pt@{$\\evpt$}}\n\\begin{equation*}\n\\Big(\\prd{t:\\unit}P(t)\\Big)\\to P(\\ttt)\n\\end{equation*}\ngiven by $\\lam{f}f(\\ttt)$ is an equivalence. \n\\item Consider a type $X$ equipped with a point $x:X$. Show that the following are equivalent: \n\\begin{enumerate}\n\\item The map $\\indunit(x):\\unit\\to X$ is an equivalence (i.e., $X$ is contractible).\n\\item For any type $Y$ the map\n\\begin{equation*}\n\\lam{f}f(x) : (X\\to Y)\\to Y\n\\end{equation*}\nis an equivalence.\n\\end{enumerate}\n\\end{subexenum}\n\\exercise \\label{ex:sec_retr}Consider a commuting triangle \n\\begin{equation*}\n\\begin{tikzcd}[column sep=tiny]\nA \\arrow[rr,\"h\"] \\arrow[dr,swap,\"f\"] & & B \\arrow[dl,\"g\"] \\\\\n& X\n\\end{tikzcd}\n\\end{equation*}\nwith $H:f\\htpy g\\circ h$.\n\\begin{subexenum}\n\\item Show that if $h$ has a section, then $\\sections(g)$ is a retract of $\\sections(f)$.\n\\item Show that if $g$ has a retraction, then $\\retractions(h)$ is a retract of $\\sections(f)$.\n\\end{subexenum}\n\\exercise \\label{ex:equiv_pi} Consider a family $f_i:A_i\\to B_i$ of $k$-truncated maps, indexed by $i:I$. Show that the map\n  \\begin{equation*}\n    \\lam{h}{i}f_i(h(i)):\\Big(\\prd{i:I}A_i\\Big)\\to\\Big(\\prd{i:I}B_i\\Big)\n  \\end{equation*}\n  is again $k$-truncated. Conclude that if each $f_i$ is an equivalence, then so is the above map.\n  \\exercise Consider a map $f:X\\to Y$. Show that the following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ is $k$-truncated.\n  \\item For every type $A$, the postcomposition function\n    \\begin{equation*}\n      f\\circ\\blank : (A\\to X)\\to (A\\to Y)\n    \\end{equation*}\n    is $k$-truncated.\n  \\end{enumerate}\n  In particular it follows that $f$ is an embedding if and only if $f\\circ\\blank$ is an embedding.\n\n  Hint: Show that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=huge]\n      (f=g) \\arrow[r,\"\\apfunc{m}\"] \\arrow[d,swap,\"\\htpyeq\"] & (m\\circ f=m\\circ g) \\arrow[d,\"\\htpyeq\"] \\\\\n      (f\\htpy g) \\arrow[r,swap,\"H\\mapsto m\\cdot H\"] & (m\\circ f\\htpy m\\circ g)\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes, and apply \\cref{ex:equiv_pi}.\n  \\exercise \\label{ex:pi-fib}Consider a function $f:A\\to B$, and let $P$ be a family of types over $B$. Show that the map\n  \\begin{equation*}\n    \\Big(\\prd{b:B}\\fib{f}{b}\\to P(b)\\Big)\\to\\Big(\\prd{a:A}P(f(a))\\Big)\n  \\end{equation*}\n  given by $h\\mapsto h_{f(a)}(a,\\refl{f(a)})$ is an equivalence.\n  \\exercise \\label{ex:triangle_fib}Consider a diagram of the form\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      A \\arrow[dr,swap,\"f\"] & & B \\arrow[dl,\"g\"] \\\\\n      & X\n    \\end{tikzcd}\n  \\end{equation*}\n  \\begin{subexenum}\n  \\item Show that the type $\\sm{h:A\\to B} f\\htpy g\\circ h$ is equivalent to the type of families of maps\n    \\begin{equation*}\n      \\prd{x:X}\\fib{f}{x}\\to\\fib{g}{x}.\n    \\end{equation*}\n  \\item Show that the type $\\sm{h:\\eqv{A}{B}} f\\htpy g\\circ h$ is equivalent to the type of families of equivalences\n    \\begin{equation*}\n      \\prd{x:X}\\fib{f}{x}\\eqvsym\\fib{g}{x}.\n    \\end{equation*}\n  \\end{subexenum}\n  \\exercise \\label{ex:sq_fib}Consider a diagram of the form\n  \\begin{equation*}\n    \\begin{tikzcd}\n      A \\arrow[d,swap,\"f\"] & B \\arrow[d,\"g\"] \\\\\n      X \\arrow[r,swap,\"h\"] & Y.\n    \\end{tikzcd}\n  \\end{equation*}\n  Show that the type $\\sm{i:A\\to B}h\\circ f\\htpy g\\circ i$ is equivalent to the type of families of maps\n  \\begin{equation*}\n    \\prd{x:X}\\fib{f}{x}\\to\\fib{g}{h(x)}.\n  \\end{equation*}\n  % Note: In \\cref{thm:pb_fibequiv_complete} we will characterize the type of families of equivalences $\\prd{x:X}\\fib{f}{x}\\simeq\\fib{g}{x}$.\n  % \\item Show that the type $\\sm{i:\\eqv{A}{B}}h\\circ f\\htpy g\\circ i$ is equivalent to the type of families of equivalences\n  %   \\begin{equation*}\n  %     \\prd{x:X}\\fib{f}{x}\\eqvsym\\fib{g}{h(x)}.\n  %   \\end{equation*}\n  \\exercise \\label{ex:iso_equiv}Let $A$ and $B$ be sets. Show that type type $\\eqv{A}{B}$ of equivalences from $A$ to $B$ is equivalent to the type $A\\cong B$ of \\define{isomorphisms}\\index{isomorphism}\\index{set!isomorphism} from $A$ to $B$, i.e., the type of quadruples $(f,g,H,K)$ consisting of\n  \\begin{align*}\n    f & : A\\to B \\\\\n    g & : B\\to A \\\\\n    H & : f\\circ g = \\idfunc[B] \\\\\n    K & : g\\circ f = \\idfunc[A].\n  \\end{align*}\n  \\exercise \\label{ex:pi_sec}Let $B$ be a type family over $A$, and consider the postcomposition function\n  \\begin{equation*}\n    \\proj1 \\circ \\blank : \\Big(\\sm{x:A} B(x)\\Big)^A \\to A^A.\n  \\end{equation*}\n  Construct equivalences\n  \\begin{equation*}\n    \\Big(\\prd{x:A}B(x)\\Big) \\eqvsym \\sections(\\proj 1) \\eqvsym \\fib{\\proj 1 \\circ\\blank}{\\idfunc[A]}.\n  \\end{equation*}\n  \\exercise Construct equivalences\n  \\begin{align*}\n    \\Fin(n^m) & \\simeq (\\Fin(m)\\to\\Fin(n)) \\\\\n    \\Fin(n!) & \\simeq (\\Fin(n)\\simeq\\Fin(n)).\n  \\end{align*}\n\\end{exercises}\n", "meta": {"hexsha": "528d9f42955cf4440dd8814d69e39e9114ce79e4", "size": 28698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/funext.tex", "max_stars_repo_name": "hemangandhi/HoTT-Intro", "max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 333, "max_stars_repo_stars_event_min_datetime": "2018-09-26T08:33:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:50:15.000Z", "max_issues_repo_path": "Book/funext.tex", "max_issues_repo_name": "hemangandhi/HoTT-Intro", "max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-06-18T04:16:04.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-16T15:27:01.000Z", "max_forks_repo_path": "Book/funext.tex", "max_forks_repo_name": "hemangandhi/HoTT-Intro", "max_forks_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2018-09-26T09:08:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T00:33:50.000Z", "avg_line_length": 52.8508287293, "max_line_length": 630, "alphanum_fraction": 0.6831834971, "num_tokens": 10116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7047988603166042}}
{"text": "\\section*{Exercises}\n\n\\begin{ex} Find the determinants of the following matrices.\n  \\begin{equation*}\n    (a)~\\begin{mymatrix}{rr}\n      1 & 3 \\\\\n      0 & 2\n    \\end{mymatrix}\n    \\quad\n    (b)~\\begin{mymatrix}{rr}\n      0 & 3 \\\\\n      0 & 2\n    \\end{mymatrix}\n    \\quad\n    (c)~\\begin{mymatrix}{rr}\n      4 & 3 \\\\\n      6 & 2\n    \\end{mymatrix}\n    \\quad\n    (d)~\\begin{mymatrix}{rr}\n      -3 & 4 \\\\\n      -1 & 2\n    \\end{mymatrix}\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Find the following determinants.\n  \\begin{equation*}\n    (a)~\\begin{absmatrix}{rrr}\n      1 & 2 & 3 \\\\\n      4 & 5 & 6 \\\\\n      7 & 8 & 9 \\\\\n    \\end{absmatrix}\n    \\quad\n    (b)~\\begin{absmatrix}{rrr}\n      1  & 0 & 2 \\\\\n      2  & 5 & 3 \\\\\n      -1 & 0 & 0 \\\\\n    \\end{absmatrix}\n    \\quad\n    (c)~\\begin{absmatrix}{rrr}\n      3 &  4 & 1 \\\\\n      0 & -1 & 1 \\\\\n      1 &  2 & 1 \\\\\n    \\end{absmatrix}\n    \\quad\n    (d)~\\begin{absmatrix}{rrr}\n      0  & -2 &  1 \\\\\n      4  & 1  & -3 \\\\\n      -1 & 3  &  1 \\\\\n    \\end{absmatrix}\n  \\end{equation*}\n\\end{ex}\n\n", "meta": {"hexsha": "f4f6569ef75f2605dd5cf30a06719e185473a9db", "size": 1033, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Determinants-TwoAndThree.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Determinants-TwoAndThree.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Determinants-TwoAndThree.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 18.4464285714, "max_line_length": 59, "alphanum_fraction": 0.4462729913, "num_tokens": 457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7047988508547488}}
{"text": "%% Magic command to compile root document\n% !TEX root = ../../thesis.tex\n\n%% Reset glossary to show long gls names\n\\glsresetall\n\n%% Set path to look for the images\n\\graphicspath{{./Sections/Basics/Resources/}}\n\nSo far we have explained how \\glspl{ann} works assuming that we feed them with vectors of fixed length. Even though we could take a multichannel image and transform it into a vector, in practice this would be computationally very expensive. For instance, assuming that we have a 3 channel image of size 224 by 224, this would result into an input vector of length $3 \\cdot 224 \\cdot 224=150'528$. Then, if the first layer of our network has 100 units, this would mean more than 15 millions of parameters only for the first layer. Furthermore, the transformation of our image into a vector would mean a loss of spatial information. This means that the \\gls{ann} would not be able to capture or use the spatial relationship between pixels and shapes within the image.\n\nA \\gls{cnn} is a type of \\gls{ann} widely used to analyze data in the form of images. The intuition behind a \\gls{cnn} is that instead of just looking at an image and trying to predict the target value directly, first learn some \\hl{features} within the image, and then make the predict base on this features.\nTo achieve this, \\glspl{cnn} mainly use \\hl{convolution} and \\hl{pooling} layers.\n\n\\subsubsection{Convolution layer}\n\nThe only difference a\n\nA convolution layer is very similar to a regular layer described in section \\ref{sec:basics:ANN}. Basically, they only differ in the way the layer input is multiplied by the the layer weights.\nRecall that in a regular layer, the input of a unit is the dot product between the layer input and its corresponding weight vector (i.e., $z=\\bs{w}^T\\bs{x}$).\nThis means that for each element in the input vector $\\bs{x}$, there is a corresponding element in the weight vector $\\bs{w}$. However, for a convolution layer this is not the case.\nConvolution layers are based on the shared-weight architecture of the convolution \\hl{kernels} or \\hl{filters} that slide along the input and returns a translation known as \\hl{feature maps} \\cite{zhang1988shift}. This means that the \\hl{kernels} weights will be used for multiple elements of the layer input. Figure \\ref{fig:basics:conv_layer} shows the convolution process with a 2 by 2 kernel over a RGB image (3 channels) of size 4 by 4. Each entrance of the returned feature map $z_i$ is the dot product between the kernel weights $\\bs{w}$ and the $\\bs{x}_i-th$ chunk of the image.\n\n\\begin{figure}[!ht]\n  \\centering\n  \\includegraphics[width=\\linewidth]{Diagrams/Conv_layer.png}\n  \\caption{Convolution process steps. In red, green and blue the input image, in orange the convolution kernel (size 2 by 2 and stride of 1) and in gray the convolution output (feature map).}\n  \\label{fig:basics:conv_layer}\n\\end{figure}\n\nMathematically this looks as follow\n\n\\begin{equation}\n  z_i = \\bs{w}^T \\bs{x}_i + b\n\\end{equation}\n\nwhere $\\bs{w}\\in\\mathbb{R}^{2 \\times 2 \\times 3}$, $\\bs{x_i}\\in\\mathbb{R}^{2 \\times 2 \\times 3}$ and $b\\in\\mathbb{R}$ is the bias (not shown in the images).\n\nLike the kernel size, the number of pixels we shift the kernel each time along side the input (\\hl{Stride}) is also a hyperparameter of convolution layers. IN figure \\ref{fig:basics:conv_layer}, the stride size is 1.\n\nFigure \\ref{fig:basics:conv_layer} also shows that size (width and height) of the returned feature map is smaller than the input image. If we want to keep the input and output size the same (\\hl{Same convolution}), then we must add zeros at the edges of the input features (zero-padding). This is shown on figure \\ref{fig:basics:conv_layer_pad}.\n\n\\begin{figure}[!ht]\n  \\centering\n  \\includegraphics[width=0.7\\linewidth]{Diagrams/Conv_layer_pad.png}\n  \\caption{Convolution with padding. In blue a single-channel input features, in orange the convolution kernel (size 3 by 3 and stride of 1) and in gray the convolution output (feature map).}\n  \\label{fig:basics:conv_layer_pad}\n\\end{figure}\n\nSo far we have seen that a convolution projects a multi-channel input feature (image) into a single-channel feature map. Therefore, if we want our output feature map to have $n$ channels, then our convolution must have $n$ different kernels.\n\nNormally, a non-linear activation function is applied to the output of convolution layers (and normally also after batch normalization) to enable the \\gls{cnn} to learn non-linear relations.\n\n\\subsubsection{Pooling layer}\n\nUnlike convolution layers, the goal of Pooling layers is to reduce the feature image (height and width, but not depth) rather than learn features.\nHowever, Pooling layers work in a similar way to convolution layers in the way that they also slide a kernel along the input. However, in this case the kernel works independently on each feature map (that is, each channel) and has no weights to learn.\nThis means that the pooling layers maintain the same number of input and output channels.\nThere are several ways to do this downsampling, but the most common are Max Polling and Average Polling. As the name suggests, Average pooling shrinks the feature image by averaging sections of it, while Max pooling takes the maximum value. Figure \\ref{fig:basics:pooling} shows an example of a max and average pooling layer on a single-channel feature image using a 2 by 2 kernel and a stride of 2.\n\n\\begin{figure}[!ht]\n  \\centering\n  \\includegraphics[width=0.7\\linewidth]{Diagrams/Pooling.png}\n  \\caption{Max and average pooling with a 2 by 2 kernel and stride 2. The color denotes the kernel position.}\n  \\label{fig:basics:pooling}\n\\end{figure}\n\nNormally, Pooling layers are applied over the output of the activation functions.\n\n\\subsubsection{Global Average Pooling layer}\n\nAs we mentioned at the beginning of this section, the idea of a \\gls{cnn} is to first learn the features within the input images and then make a prediction based on these features. To do this, the \\hl{Global Average Pooling layer} transforms the channels of the last feature map into a vector (by averaging each of its channels), so that this can be used as input in a regular \\gls{ann} to make the final prediction. Figure \\ref{fig:basics:global_avg_pool} shows an example of this, when it is applied into a feature map with 7 channels.\n\n\\begin{figure}[!ht]\n  \\centering\n  \\includegraphics[width=0.7\\linewidth]{Diagrams/Global_avg_pooling.png}\n  \\caption{Global Average Pooling layer.}\n  \\label{fig:basics:global_avg_pool}\n\\end{figure}\n\n\\subsubsection{Inception module}\n\nRecall that a convolution layer is meant to learn features from a 3D object with 2 spatial dimensions (width and height) and a channel dimension. This means that each kernel in the convolution needs to learn simultaneously cross-channel and spatial correlations.\nThe intuition behind the \\hl{Inception module} is to improve this process by separating this two tasks, so that the cross-channel correlations and the spatial correlations can be learned separately and independently \\cite{chollet2017xception}.\n\nA normal inception model looks at the cross-channel correlations first through a set of 3 or 4 \\hl{pointwise convolutions}\\footnote{A \\hl{pointwise convolution} is a convolution with 1 by 1 kernels and stride 1.}, and then learns the spacial information in the downsampled feature image (in depth, not height and width), by means of regular convolution (usually with 3 by 3 or 5 by 5 kernels). Figure \\ref{fig:basics:inception_module} shows a diagram of an Inveption V3 module.\n\n\\begin{figure}[!ht]\n  \\centering\n  \\includegraphics[width=0.6\\linewidth]{Inception_module.png}\n  \\caption{A regular Inception module (Inveption V3). Image source \\cite{chollet2017xception}.}\n  \\label{fig:basics:inception_module}\n\\end{figure}\n\nFrançois Chollet \\cite{chollet2017xception}, used the inception module as reference to propose the \\hl{depthwise separable convolution}, which is something between a normal convolution and a normal convolution combined/followed by a pointwise convolution.\nFigure \\ref{fig:basics:extreme_inception_module} shows an \\hl{extreme} version of the inception module shown in figure \\ref{fig:basics:inception_module}. The \\hl{depthwise separable convolution} is very similar to the one shown in figure \\ref{fig:basics:extreme_inception_module}, the only difference is that the pointwise convolution is applied before the 3 by 3 convolutions instead of after.\n\n\\begin{figure}[!ht]\n  \\centering\n  \\includegraphics[width=0.6\\linewidth]{Extreme_Inception_module.png}\n  \\caption{An extreme version of our Inception module. Image source \\cite{chollet2017xception}.}\n  \\label{fig:basics:extreme_inception_module}\n\\end{figure}\n\nEven though the \\hl{depthwise separable convolution} is a simplified version of the inception module, the idea and motivation behind it is the same. The \\hl{depthwise separable convolution}, and the residual block, are the main components of the \\hl{Xception} architecture \\cite{chollet2017xception}.\n", "meta": {"hexsha": "bbcac3f19d4813923fa3f40bfd6af4db60b7c3b6", "size": 8999, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Manuscript/Sections/Basics/Convolutional_Neural_Networks.tex", "max_stars_repo_name": "andresbecker/master_thesis", "max_stars_repo_head_hexsha": "c67b8309b524ccfd02448573f2352ce57b5531cc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Manuscript/Sections/Basics/Convolutional_Neural_Networks.tex", "max_issues_repo_name": "andresbecker/master_thesis", "max_issues_repo_head_hexsha": "c67b8309b524ccfd02448573f2352ce57b5531cc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Manuscript/Sections/Basics/Convolutional_Neural_Networks.tex", "max_forks_repo_name": "andresbecker/master_thesis", "max_forks_repo_head_hexsha": "c67b8309b524ccfd02448573f2352ce57b5531cc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.8962264151, "max_line_length": 765, "alphanum_fraction": 0.7820868985, "num_tokens": 2263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035763237924, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7047850353324646}}
{"text": "\\section{Robust PCA}\n\\begin{compactitem}\n\t\\item Idea: Approximate $\\mathbf{X}$ with $\\mathbf{L} + \\mathbf{S}$, $\\mathbf{L}$ is low-rank, $\\mathbf{S}$ is sparse.\n\t\\item $\\min_{\\mathbf{L},\\mathbf{S}}\\mathsf{rank}(\\mathbf{L}) + \\mu \\lVert \\mathbf{S}\\rVert_0$, s. t. $\\mathbf{L} + \\mathbf{S} = \\mathbf{X}$. As non-convex, change to $\\min_{\\mathbf{L},\\mathbf{S}} \\|\\mathbf{L}\\|_\\star + \\lambda \\lVert\\mathbf{S}\\rVert_1$ (\\emph{not} the same in general) Deal w/ missing values: subj. to $L_{ij} + S_{ij} = X_{ij}, \\forall(i,j) \\in \\Omega_{observed}$\n\t\\item Perfect reconstruction is \\emph{not} possible if $\\mathbf{S}$ is low-rank, $\\mathbf{L}$ is sparse, or $\\mathbf{X}$ is low-rank \\textit{and} sparse. Formally coherence: $\\|\\mathbf{U}^\\top \\mathbf{e}_i\\|^2 \\leq \\frac{\\nu r}{n}$, $\\|\\mathbf{V}^\\top \\mathbf{e}_i\\|^2 \\leq \\frac{\\nu r}{n}$, $\\|\\mathbf{UV}^\\top\\|^2_{ij} \\leq \\frac{\\nu r}{n^2}$ : $\\mathbf{L}=\\mathbf{U}\\mathbf{D}\\mathbf{V}^\\top$\n\\end{compactitem}\n\n\\subsection*{Dual Ascent (Gradient Method for Dual Problem)}\n$\\boldsymbol{\\lambda}^{t+1} = \\boldsymbol{\\lambda}^{t} + \\eta \\nabla D(\\boldsymbol{\\lambda}^t)$,\n$ \\nabla D (\\boldsymbol{\\lambda}) = \\mathbf{A}\\mathbf{x}^*-\\mathbf{b}$ for $\\mathbf{x}^* \\in \\arg\\min_\\mathbf{x} \\mathcal{L}(\\mathbf{x},\\boldsymbol{\\lambda})$\n\\textbf{Dual Decomposition for Dual Ascent}:\n\\\\$\\mathbf{x}_i^{t+1} := \\arg\\min_{\\mathbf{x}_i} \\mathcal{L}_i(\\mathbf{x}_i,\\lambda^t)$;\n$\\boldsymbol{\\lambda}^{t+1} := \\boldsymbol{\\lambda}^t + \\eta^t \\left( \\sum_{i=1}^{N} \\mathbf{A}_i \\mathbf{x}_i^{t+1} -\\mathbf{b} \\right) $\n\n\\subsection*{Alternating Direction Method of Multipliers (ADMM)}\n$\\min_{\\mathbf{x}_1, \\mathbf{x}_2} f_1(\\mathbf{x}_1) + f_2(\\mathbf{x}_2)$ s. t. $\\mathbf{A}_1 \\mathbf{x}_1 + \\mathbf{A}_2 \\mathbf{x}_2 = \\mathbf{b}$, $f_1, f_2$ convex\n\\begin{inparaitem}[\\color{red}\\textbullet]\n\t\\item Augmented Lagrangian: $L_p(\\mathbf{x}_1, \\mathbf{x}_2, \\boldsymbol{\\nu}) = f_1(\\mathbf{x}_1) + f_2(\\mathbf{x}_2) + \\boldsymbol{\\nu}^\\top (\\mathbf{A}_1 \\mathbf{x}_1 + \\mathbf{A}_2 \\mathbf{x}_2 - \\mathbf{b}) + \\frac{p}{2}\\| \\mathbf{A}_1 \\mathbf{x}_1 + \\mathbf{A}_2 \\mathbf{x}_2 - \\mathbf{b} \\|_2^2$\n\t\\item ADMM: $\\mathbf{x}_1^{(t+1)} := \\argmin_{\\mathbf{x}_1} L_p(\\mathbf{x}_1, \\mathbf{x}_2^{(t)}, \\boldsymbol{\\nu}^{(t)})$, $\\mathbf{x}_2^{(t+1)} := \\argmin_{\\mathbf{x}_2} L_p(\\mathbf{x}_1^{(t+1)}, \\mathbf{x}_2, \\boldsymbol{\\nu}^{(t)})$, $\\boldsymbol{\\nu}^{(t+1)} := \\boldsymbol{\\nu}^{(t)} + p(\\mathbf{A}_1 \\mathbf{x}_1^{(t+1)} + \\mathbf{A}_2 \\mathbf{x}_2^{(t+1)} - \\mathbf{b})$\n  \\item ADMM for RPCA: $f_1(\\mathbf{L}) = \\|\\mathbf{L}\\|_\\star$, $f_2(\\mathbf{S}) = \\lambda \\| \\mathbf{S} \\|_1$, $\\mathbf{A}_1 \\mathbf{x}_1 + \\mathbf{A}_2 \\mathbf{x}_2 = \\mathbf{b} \\text{ becomes } \\mathbf{L} + \\mathbf{S} = \\mathbf{X}$, therefore $L_p(\\mathbf{L}, \\mathbf{S}, \\boldsymbol{\\nu}) = \\|\\mathbf{L}\\|_* + \\nu \\|\\mathbf{S}\\|_1 + \\left< \\nu, \\mathrm{vec}(\\mathbf{L}+\\mathbf{S}-\\mathbf{X}) \\right> + \\frac{P}{2} \\| \\mathbf{L}+ \\mathbf{S} - \\mathbf{X} \\|_F^2$\n  %updates: $\\mathbf{L}^{t+1} = \\mathcal{D}_{\\rho^{-1}}(X-S-\\rho^{-1}\\text{mat}(\\lambda))$\n\\end{inparaitem}", "meta": {"hexsha": "b4e122e1a8aa94ad4d0cafc1ed5497bfb82e607b", "size": 3084, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "RobustPCA.tex", "max_stars_repo_name": "vscherer/eth-cil-exam-cheatsheet", "max_stars_repo_head_hexsha": "9ae156bcf5e2797e65b5495ff520649b43860cdd", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-09-24T20:33:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-21T15:52:46.000Z", "max_issues_repo_path": "RobustPCA.tex", "max_issues_repo_name": "vscherer/eth-cil-exam-cheatsheet", "max_issues_repo_head_hexsha": "9ae156bcf5e2797e65b5495ff520649b43860cdd", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "RobustPCA.tex", "max_forks_repo_name": "vscherer/eth-cil-exam-cheatsheet", "max_forks_repo_head_hexsha": "9ae156bcf5e2797e65b5495ff520649b43860cdd", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-01-14T16:21:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-18T17:17:10.000Z", "avg_line_length": 140.1818181818, "max_line_length": 465, "alphanum_fraction": 0.6157587549, "num_tokens": 1386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035763237924, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7047850314018865}}
{"text": "\\section{MAP Operator}\nThe operator MAP applies a uniform evaluation pattern\nto all members of a composite structure: a matrix, a list or the arguments\nof an operator expression. The evaluation pattern can be a\nunary procedure, an operator, or an algebraic expression with\none free variable. MAP is used with the syntax:\n\\begin{verbatim}\n  MAP(EXPRN1:algebraic,EXPRN2:expression)\n\\end{verbatim}\n{\\tt EXPRN2} is a list, a matrix or an operator expression.\n\n{\\tt EXPRN1} is\n\\begin{itemize}\n\\item the name of an operator for a single argument: the operator\n is evaluated once with each element of {\\tt EXPRN1} as its single argument,\n\\item an algebraic expression with exactly one free variable, that is\na variable preceded by the tilde symbol: the expression\n is evaluated for each element of {\\tt EXPRN1} where the element is\n substituted for the free variable,\n\\item a replacement rule of the form\n\\begin{verbatim}\n  VAR => EXPRN3\n\\end{verbatim} \n  where {\\tt VAR} is a variable and {\\tt EXPRN3} is an expression\n  which contains {\\tt VAR}.\n  Here {\\tt EXPRN3} is evaluated for each element of {\\tt EXPRN1} where \n  the element is substituted for  {\\tt VAR}. {\\tt VAR} may be \n  optionally preceded by a tilde.\n\\end{itemize}\nThe rule form for {\\tt EXPRN2} is needed when more than\none free variable occurs.\n\n{\\it Examples:}\n\\begin{verbatim}\n     % collect absolute values\n   map(abs,{1,-2,a,-a});\n               \n                      ->\n\n   {1,2,abs(a),abs(a)}\n\n     % integrate a matrix\n   map(int(~w,x), mat((x^2,x^5),(x^4,x^5)));\n\n                      ->\n \n        [  3     6 ]\n        [ x     x  ]\n        [----  ----]\n        [ 3     6  ]\n        [          ]\n        [  5     6 ]\n        [ x     x  ]\n        [----  ----]\n        [ 5     6  ]\n\n     % multiply an equation\n   map(~w*6 , x^2/3 = y^3/2 -1);\n   \n                      ->\n\n         2     3\n      2*x =3*(y  - 2)\n\n    \n\\end{verbatim}\n{\\tt MAP} can be applied in nested mode:\n\\begin{verbatim}\n   map(sub(x=y,~q)-sub(x=0,~q),map(mat(int(~w,x),(x^2-y,x^3))));\n                      ->\n\n       [  2             4 ]\n       [ y *(y - 3)    y  ]\n       [------------  ----]\n       [     3         4  ]\n\n    % The following example needs the rule form because there are two\n    % free variables in the rightmost expression.\n \n   map(~w=>map(int(~r,x),w),{mat((x^2,x^4)),mat((x^3,x^5))});\n\n                      ->\n       {\n\n        [  3     5 ]\n        [ x     x  ] \n        [----  ----]\n        [ 3     5  ]\n\n        ,\n\n        [  4     6 ]\n        [ x     x  ]\n        [----  ----]\n        [ 4     6  ]\n\n        }\n\\end{verbatim}\n\n\n\n\\section{SELECT Operator}\nThe operator SELECT extracts from a list \nor from the arguments of an n--ary operator elements corresponding\nto a boolean predicate. The predicate pattern can be a\nunary procedure, an operator or an algebraic expression with\none free variable. SELECT is used with the syntax:\n\\begin{verbatim}\n  SELECT(EXPRN1:expression,EXPRN2:list)\n\\end{verbatim}\n\n{\\tt EXPRN1} is\n\\begin{itemize}\n\\item the name of an operator for a single argument: the operator\n is evaluated once with each element of {\\tt EXPRN2} as its single argument,\n\\item an algebraic expression with exactly one free variable, that is\na variable preceded by the tilde symbol at least once: the expression\n is evaluated for each element of {\\tt EXPRN2} where the element is\n substituted for the free variable,\n\\item a replacement rule of the form\n\\begin{verbatim}\n  VAR => EXPRN3\n\\end{verbatim} \n  where {\\tt VAR} is a variable and {\\tt EXPRN3} is an expression\n  which contains {\\tt VAR}.\n  Here {\\tt EXPRN3} is evaluated for each element of {\\tt EXPRN2} where \n  the element is substituted for  {\\tt VAR}. {\\tt VAR} may be \n  optionally preceded by a tilde.\n\\end{itemize}\nThe rule form for {\\tt EXPRN1} is needed when more than\none free variable occurs. The result of the operation is built\nfrom those elements of {\\tt EXPRN2} which let {\\tt EXPRN1} evaluate\nto a value different from {\\tt 0} or {\\tt nil}, using the\nleading operator of  {\\tt EXPRN2}.\n\n\nExamples:\n\n\\begin{verbatim}\n  select( ~w>0, {1,-1,2,-3,3})\n                      ->\n                    {1,2,3}\n\n   % select the tersm with even powers of y \n  select(evenp deg(~w,y), part((x+y)^5,0):=list);\n\n                      -> \n          5     3  2      4\n        {x ,10*x *y ,5*x*y }\n\n   % select elements of a sum directly\n  select(evenp deg(~w,x), 2x^2+3x^3+4x^4);\n\n                      ->\n          2    4\n        2x  +4x    \n\\end{verbatim}\n\n", "meta": {"hexsha": "895ee7abf82635b605ecaf7f27252c06d33528d0", "size": 4489, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "atomic_Decomp/Redlog/reduce.doc/map.tex", "max_stars_repo_name": "Korosensei42/AtomicDecomposition", "max_stars_repo_head_hexsha": "ca10f97c2cef1a258a4e9fade0a3133d1389d08e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "atomic_Decomp/Redlog/reduce.doc/map.tex", "max_issues_repo_name": "Korosensei42/AtomicDecomposition", "max_issues_repo_head_hexsha": "ca10f97c2cef1a258a4e9fade0a3133d1389d08e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "atomic_Decomp/Redlog/reduce.doc/map.tex", "max_forks_repo_name": "Korosensei42/AtomicDecomposition", "max_forks_repo_head_hexsha": "ca10f97c2cef1a258a4e9fade0a3133d1389d08e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2327044025, "max_line_length": 76, "alphanum_fraction": 0.5894408554, "num_tokens": 1308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591569, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7047850272642732}}
{"text": "\\section{The univalence axiom}\n\n\\subsection{Equivalent forms of the univalence axiom}\n\nThe univalence axiom characterizes the identity type of the universe. Roughly speaking, it asserts that equivalent types are equal. It is considered to be an \\emph{extensionality principle}\\index{extensionality principle!for types} for types.\n\n\\begin{axiom}[Univalence]\\label{axiom:univalence}\n  The \\define{univalence axiom}\\index{univalence axiom} on a universe $\\UU$ is the statement that for any $A:\\UU$ the family of maps\\index{equiv-eq@{$\\equiveq$}}\n\\begin{equation*}\n\\equiveq : \\prd{B:\\UU} (\\id{A}{B})\\to(\\eqv{A}{B}).\n\\end{equation*}\nthat sends $\\refl{A}$ to the identity equivalence $\\idfunc:\\eqv{A}{A}$ is a family of equivalences.\\index{identity type!of a universe} A universe satisfying the univalence axiom is referred to as a \\define{univalent universe}\\index{univalent universe}. If $\\UU$ is a univalent universe we will write\n$\\eqequiv$\\index{eq-equiv@{$\\eqequiv$}}\nfor the inverse of $\\equiveq$.\n\\end{axiom}\n\nThe following theorem is a special case of the fundamental theorem of identity types (\\cref{thm:id_fundamental})\\index{fundamental theorem of identity types}. Subsequently we will assume that any type is contained in a univalent universe.\\index{axiom!univalence}\n\n\\begin{thm}\\label{thm:univalence}\nThe following are equivalent:\n\\begin{enumerate}\n\\item The univalence axiom holds.\n\\item The type\n\\begin{equation*}\n\\sm{B:\\UU}\\eqv{A}{B}\n\\end{equation*}\nis contractible for each $A:\\UU$.\n\\item The principle of \\define{equivalence induction}\\index{equivalence induction}\\index{induction principle!for equivalences} holds: for every $A:\\UU$ and for every type family\n\\begin{equation*}\nP:\\prd{B:\\UU} (\\eqv{A}{B})\\to \\UU,\n\\end{equation*}\nthe map\n\\begin{equation*}\n\\Big(\\prd{B:\\UU}{e:\\eqv{A}{B}}P(B,e)\\Big)\\to P(A,\\idfunc[A])\n\\end{equation*}\ngiven by $f\\mapsto f(A,\\idfunc[A])$ has a section.\n\\end{enumerate}\n\\end{thm}\n\n\\subsection{Univalence implies function extensionality}\nOne of the first applications of the univalence axiom was Voevodsky's theorem that the univalence axiom on a universe $\\UU$ implies function extensionality for types in $\\UU$. The proof uses the fact that weak function extensionality implies function extensionality.\n\nWe will also make use of the following lemma. Note that this statement was also part of \\cref{lem:postcomp_equiv}. That exercise is solved using function extensionality. Since our present goal is to derive function extensionality from the univalence axiom, we cannot make use of that exercise.\n\n\\begin{lem}\\label{lem:postcomp-equiv}\n  For any equivalence $e:\\eqv{X}{Y}$ in a univalent universe $\\UU$, and any type $A$, the post-composition map\n  \\begin{equation*}\n    e\\circ\\blank : (A \\to X) \\to (A\\to Y)\n  \\end{equation*}\n  is an equivalence.\n\\end{lem}\n\n\\begin{proof}\n  The statement is obvious for the identity equivalence $\\idfunc : \\eqv{X}{X}$. Therefore the claim follows by equivalence induction, which is by \\cref{thm:univalence} one of the equivalent forms of the univalence axiom.\n\\end{proof}\n\n\\begin{thm}\\label{thm:funext-univalence}\\index{univalence axiom!implies function extensionality}\n  For any universe $\\UU$, the univalence axiom on $\\UU$ implies function extensionality on $\\UU$.\n\\end{thm}\n\n\\begin{proof}\n  Note that by \\cref{thm:funext_wkfunext}\\index{weak function extensionality} it suffices to show that univalence implies weak function extensionality, where we note that \\cref{thm:funext_wkfunext} also holds when it is restricted to small types.\n  \nSuppose that $B:A\\to \\UU$ is a family of contractible types. Our goal is to show that the product $\\prd{x:A}B(x)$ is contractible.\nSince each $B(x)$ is contractible, the projection map $\\proj 1:\\big(\\sm{x:A}B(x)\\big)\\to A$ is an equivalence by \\cref{ex:proj_fiber}.\n\nNow it follows by \\cref{lem:postcomp-equiv} that $\\proj1\\circ\\blank$ is an equivalence. Consequently, it follows from \\cref{thm:contr_equiv} that the fibers of\n\\begin{equation*}\n\\proj 1\\circ\\blank : \\Big(A\\to \\sm{x:A}B(x)\\Big)\\to (A\\to A)\n\\end{equation*}\nare contractible. In particular, the fiber at $\\idfunc[A]$ is contractible. Therefore it suffices to show that $\\prd{x:A}B(x)$ is a retract of $\\sm{f:A\\to\\sm{x:A}B(x)}\\proj 1\\circ f=\\idfunc[A]$. In other words, we will construct\n\\begin{equation*}\n\\begin{tikzcd}\n\\Big(\\prd{x:A}B(x)\\Big) \\arrow[r,\"i\"] & \\Big(\\sm{f:A\\to\\sm{x:A}B(x)}\\proj 1\\circ f=\\idfunc[A]\\Big) \\arrow[r,\"r\"] & \\Big(\\prd{x:A}B(x)\\Big),\n\\end{tikzcd}\n\\end{equation*}\nand a homotopy $r\\circ i\\htpy \\idfunc$.\n\nWe define the function $i$ by\n\\begin{equation*}\n  i(f) \\defeq (\\lam{x}(x,f(x)),\\refl{\\idfunc}).\n\\end{equation*}\nTo see that this definition is correct, we need to know that\n\\begin{equation*}\n  \\lam{x}\\proj 1(x,f(x))\\jdeq \\idfunc.\n\\end{equation*}\nThis is indeed the case, by the $\\eta$-rule\\index{eta-rule@{$\\eta$-rule}} for $\\Pi$-types.\n\nNext, we define the function $r$. Let $h:A\\to \\sm{x:A}B(x)$, and let $p:\\proj 1 \\circ h = \\idfunc$. Then we have the homotopy $H\\defeq\\htpyeq(p):\\proj 1 \\circ h \\htpy \\idfunc$. Then we have $\\proj 2(h(x)):B(\\proj 1(h(x)))$ and we have the identification $H(x):\\proj 1(h(x))=x$. Therefore we define $r$ by\n\\begin{equation*}\n  r((h,p),x)\\defeq \\tr_B(H(x),\\proj 2(h(x))).\n\\end{equation*}\n\nWe note that if $p\\jdeq \\refl{\\idfunc}$, then $H(x)\\jdeq\\refl{x}$. In this case we have the judgmental equality $r((h,\\refl{}),x)\\jdeq\\proj 2 (h(x))$. Thus we see that $r\\circ i\\jdeq \\idfunc$ by another application of the $\\eta$-rule for $\\Pi$-types.\n\\end{proof}\n\n\\subsection{Propositional extensionality and posets}\n\n\\begin{thm}\\label{thm:propositional-extensionality}\n  Propositions satisfy \\define{propositional extensionality}\\index{propositional extensionality}\\index{extensionality principle!for propositions}:\n  for any two propositions $P$ and $Q$, the canonical map\\index{bi-implication}\\index{iff-eq@{$\\iffeq$}}\n  \\begin{equation*}\n    \\iffeq:(P=Q)\\to (P\\leftrightarrow Q)\n  \\end{equation*}\n  that sends $\\refl{P}$ to $(\\idfunc,\\idfunc)$ is an equivalence. It follows that the type $\\prop$ of propositions in $\\UU$ is a set.\\index{Prop@{$\\prop$}!is a set}\n\\end{thm}\n\nNote that for any $P:\\prop$, we usually also write $P$ for the underlying type of the proposition $P$. If we would be more formal about it we would have to write $\\proj 1(P)$ for the underlying type, since $\\prop$ is the $\\Sigma$-type $\\sm{X:\\UU}\\isprop(X)$. In the following proof it is clearer if we use the more formal notation $\\proj 1(P)$ for the underlying type of a proposition $P$.\n\n\\begin{proof}\n  We note that the identity type $P=Q$ is an identity type in $\\prop$. However, since $\\isprop(X)$ is a proposition for any type $X$, it follows that the map\n  \\begin{equation*}\n    \\apfunc{\\proj 1} : (P = Q) \\to (\\proj 1(P) = \\proj 1(Q))\n  \\end{equation*}\n  is an equivalence. Now we observe that we have a commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=huge]\n      (P=Q) \\arrow[d,swap,\"\\apfunc{\\proj 1}\"] \\arrow[r] & (P\\leftrightarrow Q) \\\\\n      (\\proj 1(P)=\\proj 1(Q)) \\arrow[r,swap,\"\\equiveq\"] & (\\proj 1(P)\\simeq\\proj 1(Q)) \\arrow[u,swap,\"\\simeq\"]\n    \\end{tikzcd}\n  \\end{equation*}\n  Since the left, bottom, and right map are equivalences, it follows that the top map is an equivalence.\n\\end{proof}\n\n\\begin{defn}\n  A \\define{partially ordered set (poset)}\\index{partially ordered set|see poset}\\index{poset} is a set $P$ equipped with a relation\n  \\begin{equation*}\n    \\blank\\leq\\blank : P \\to (P \\to \\prop)\n  \\end{equation*}\n  that is \\define{reflexive}\\index{reflexive!poset} (for every $x:P$ we have $x\\leq x$), \\define{transitive}\\index{transitive!poset} (for every $x,y,z:P$ such that $x\\leq y$ and $y\\leq z$ we have $x\\leq z$), and \\define{anti-symmetric}\\index{anti-symmetric!poset} (for every $x,y:P$ such that $x\\leq y$ and $y\\leq x$ we have $x=y$).\n\\end{defn}\n\n\\begin{rmk}\n  The condition that $X$ is a set can be omitted from the definition of a poset. Indeed, if $X$ is any type that comes equipped with a $\\prop$-valued ordering relation $\\leq$ that is reflexive and anti-symmetric, then $X$ is a set by \\cref{lem:prop_to_id}.\n\\end{rmk}\n\n\\begin{eg}\n  The type $\\prop$ is a poset\\index{Prop@{$\\prop$}!is a poset}, where the ordering relation is given by implication: $P$ is less than $Q$ if $P\\to Q$. The fact that $P\\to Q$ is a proposition is a special case of \\cref{cor:funtype_trunc}. The relation $P\\to Q$ is reflexive by the identity function, and transitive by function composition. Moreover, the relation $P\\to Q$ is anti-symmetric by \\cref{thm:propositional-extensionality}\\index{propositional extensionality}.\n\\end{eg}\n\n\\begin{eg}\n  The type of natural numbers\\index{natural numbers!is a poset with leq@{is a poset with $\\leq$}}\\index{natural numbers!is a poset with divisibility}\\index{poset!N with leq@{$\\N$ with $\\leq$}}\\index{poset!N with divisibility@{$\\N$ with divisibility}} comes equipped with at least two important poset structures. The first is given by the usual ordering relation $\\leq$, and the second is given by the relation $d\\mid n$ that $d$ divides $n$.\n\\end{eg}\n\n\\begin{thm}\n  For any poset $P$ and any type $X$, the set $P^X$ is a poset.\\index{poset!closed under exponentials} In particular the type of subtypes of any type is a poset.\\index{poset!type of subtypes}\\index{subtype!poset}\n\\end{thm}\n\n\\begin{proof}\n  Let $P$ be a poset with ordering $\\leq$, and let $X$ be a type. Then $P^X$ is a set by \\cref{cor:funtype_trunc}. For any $f,g:X\\to P$ we define\n  \\begin{equation*}\n    (f\\leq g) \\defeq \\prd{x:X}f(x)\\leq g(x).\n  \\end{equation*}\n  Reflexivity and transitivity follow immediately from reflexivity and transitivity of the original relation. Moreover, by the anti-symmetry of the original relation it follows that\n  \\begin{equation*}\n    (f\\leq g)\\times (g\\leq f) \\to (f\\htpy g). \n  \\end{equation*}\n  Therefore we obtain an identification $f=g$ by function extensionality. The last claim follows immediately from the fact that a subtype of $X$ is a map $X\\to\\prop$, and the fact that $\\prop$ is a poset.\n\\end{proof}\n\n\\begin{exercises}\n\\exercise \\label{ex:istrunc_UUtrunc}\n\\begin{subexenum}\n\\item Use the univalence axiom to show that the type $\\sm{A:\\UU}\\iscontr(A)$ of all contractible types in $\\UU$ is contractible.\\index{universe!of contractible types}\n\\item Use \\cref{cor:emb_into_ktype,cor:funtype_trunc,ex:isprop_isequiv} to show that if $A$ and $B$ are $(k+1)$-types, then the type $\\eqv{A}{B}$ is also a $(k+1)$-type.\\index{A simeq B@{$\\eqv{A}{B}$}!truncatedness}\n\\item Use univalence to show that the universe of $k$-types\\index{universe!of k-types@{of $k$-types}}\\index{U leq k@{$\\UU^{\\leq k}$}}\\index{k-type@{$k$-type}!universe of k-types@{universe of $k$-types}}\\index{truncated type!universe of k-types@{universe of $k$-types}}\n\\begin{equation*}\n\\UU^{\\leq k}\\defeq \\sm{X:\\UU}\\istrunc{k}(X)\n\\end{equation*}\nis a $(k+1)$-type, for any $k\\geq -2$.\n\\item Show that $\\UU^{\\leq-1}$ is not a proposition.\\index{universe!of propositions}\n\\item Show that $\\eqv{(\\eqv{\\bool}{\\bool})}{\\bool}$, and conclude by the univalence axiom that the universe of sets\\index{universe!of sets} $\\UU^{\\leq 0}$ is not a set. \n\\end{subexenum}\n\\exercise Use the univalence axiom to show that the type $\\sm{P:\\prop}P$ is contractible.\n\\exercise Let $A$ and $B$ be small types. \n\\begin{subexenum}\n\\item Construct an equivalence\n\\begin{equation*}\n\\eqv{(A\\to (B\\to\\UU))}{\\Big(\\sm{S:\\UU} (S\\to A)\\times (S\\to B)\\Big)}\n\\end{equation*}\n\\item We say that a relation $R:A\\to (B\\to\\UU)$ is \\define{functional}\\index{relation!functional} if it comes equipped with a term of type\\index{is-function(R)@{$\\isfunction(R)$}}\n\\begin{equation*}\n\\isfunction(R) \\defeq \\prd{x:A}\\iscontr\\Big(\\sm{y:B}R(x,y)\\Big)\n\\end{equation*}\nFor any function $f:A\\to B$, show that the \\define{graph}\\index{graph!of a function} of $f$ \n\\begin{equation*}\n\\graph_f:A\\to (B\\to \\UU)\n\\end{equation*}\ngiven by $\\graph_f(a,b)\\defeq (f(a)=b)$ is a functional relation from $A$ to $B$.\n\\item Construct an equivalence\n\\begin{equation*}\n\\eqv{\\Big(\\sm{R:A\\to (B\\to\\UU)}\\isfunction(R)\\Big)}{(A\\to B)}\n\\end{equation*}\n\\item Given a relation $R:A\\to (B\\to \\UU)$ we define the \\define{opposite relation}\\index{relation!opposite relation}\\index{opposite relation}\\index{op R@{$\\opp{R}$}}\n\\begin{equation*}\n\\opp{R} : B\\to (A\\to\\UU)\n\\end{equation*}\nby $\\opp{R}(y,x)\\defeq R(x,y)$. Construct an equivalence\\index{A simeq B@{$\\eqv{A}{B}$}!as relation}\n\\begin{equation*}\n\\eqv{\\Big(\\sm{R:A\\to (B\\to \\UU)}\\isfunction(R)\\times\\isfunction(\\opp{R})\\Big)}{(\\eqv{A}{B})}.\n\\end{equation*}\n\\end{subexenum}\n\\exercise\n  \\begin{subexenum}\n  \\item Show that $\\isdecidable(P)$ is a proposition\\index{is-decidable@{$\\isdecidable$}!is a proposition}, for any proposition $P$.\n  \\item Show that $\\classicalprop$%\n    \\index{classical-Prop@{$\\classicalprop$}!classical-Prop bool@{$\\classicalprop\\eqvsym\\bool$}} is equivalent to $\\bool$.\n  \\end{subexenum}\n\\exercise Recall that $\\UU_\\ast$ is the universe of pointed types\\index{UU*@{$\\UU_\\ast$}}.\n  \\begin{subexenum}\n  \\item For any $(A,a)$ and $(B,b)$ in $\\UU_\\ast$, write $(A,a)\\simeq_\\ast(B,b)$ for the type of \\define{pointed equivalences}\\index{pointed equivalence}\\index{equivalence!pointed equivalence} from $A$ to $B$, i.e.,\n    \\begin{equation*}\n      (A,a)\\simeq_\\ast (B,b)\\defeq \\sm{e:A\\simeq B}e(a)=b.\n    \\end{equation*}\n    Show that the canonical map\\index{UU*@{$\\UU_\\ast$}!identity type}\\index{identity type!of UU*@{of $\\UU_\\ast$}}\n    \\begin{equation*}\n      \\big((A,a)=(B,b)\\big)\\to \\Big((A,a)\\simeq (B,b)\\Big)\n    \\end{equation*}\n    sending $\\refl{(A,a)}$ to the pair $(\\idfunc,\\refl{a})$, is an equivalence.\n  \\item Construct for any pointed type $(X,x_0)$ an equivalence\n    \\begin{equation*}\n      \\Big(\\sm{P:X\\to \\UU}P(x_0)\\Big)\\simeq \\sm{(A,a_0):\\UU_\\ast}(A,a_0)\\to_\\ast(X,x_0).\n    \\end{equation*}\n  \\end{subexenum}\n\\exercise Show that any subuniverse\\index{subuniverse!closed under equivalences} is closed under equivalences, i.e., show that there is a map\n  \\begin{equation*}\n    (X\\simeq Y) \\to (P(X)\\to P(Y))\n  \\end{equation*}\n  for any subuniverse $P:\\UU\\to\\prop$, and any $X,Y:\\UU$.\n  \\exercise Show that the universe inclusions\n  \\begin{equation*}\n    \\UU \\to \\UU^+\\qquad\\text{and}\\qquad \\UU\\to \\UU\\sqcup\\VV\n  \\end{equation*}\n  defined in \\cref{rmk:universe-constructions}, are embeddings.\n\\end{exercises}\n", "meta": {"hexsha": "8ba51a687df6007c718f4315d12ad609bbb604c6", "size": 14299, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/univalence.tex", "max_stars_repo_name": "hemangandhi/HoTT-Intro", "max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 333, "max_stars_repo_stars_event_min_datetime": "2018-09-26T08:33:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:50:15.000Z", "max_issues_repo_path": "Book/univalence.tex", "max_issues_repo_name": "hemangandhi/HoTT-Intro", "max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-06-18T04:16:04.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-16T15:27:01.000Z", "max_forks_repo_path": "Book/univalence.tex", "max_forks_repo_name": "hemangandhi/HoTT-Intro", "max_forks_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2018-09-26T09:08:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T00:33:50.000Z", "avg_line_length": 60.5889830508, "max_line_length": 468, "alphanum_fraction": 0.7071123855, "num_tokens": 4806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778257, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7047825054103819}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n\\usepackage{graphicx}\n\n\\begin{document}\n\n\\title{Discretization of Common Filters}\n\\author{K. Loux}\n\\date{\\today}\n\\maketitle\n\n\\section{Introduction}\nThis document contains difference equation implementations for transfer functions of common filters. Continuous-time transfer functions can be discretized using the relationship $z = e^{sT}$, where $T$ is the sampling period, $s$ is imaginary frequency and $z$ is discretized imaginary frequency.\n\nIn order for this relationship to be helpful, we need to solve for $s$, then replace all instances of $s$ in our continuous-time transfer functions with the result.  Solving for $s$, however, results in a relationship involving a natural logarithm.  We make a first-order approximation of the logarithm instead.\n\n\\begin{equation}\ns = \\frac{1}{T} \\ln \\left( z \\right) \\approx \\frac{2}{T} \\frac{1 - z^{-1}}{1 + z^{-1}}\n\\end{equation}\n\nTo go from a discrete-time transfer function to a difference equation, variables that are multiplied by $z^{-n}$ are replaced with the values of those variables from $n$ time steps in the past.\n\nWe use the variable $u$ to represent input and $y$ to represent output from the filters.  We give all coefficients in the form of $a_0$ through $a_n$ and $b_0$ through $b_m$ where $a$ coefficients are applied to input quantities and $b$ coefficients are applied to output quantities.  All coefficients can be scaled by $1 / b_0$, so then $b_0 = 1$ and the first $b$ coefficient required to be stored will be $b_1$.  These can be used in a difference equation as shown below.\n\n\\begin{equation}\ny_k = \\frac{a_0 u_k + a_1 u_{k - 1} + ... + a_n u_{k - n} - b_1 y_{k - 1} - ... - b_m y_{k - m}}{b_0}\n\\end{equation}\n\n\\section{First Order Low-Pass Filter}\n\nContinuous-time transfer function:\n\n\\begin{equation}\n\\frac{Y}{U} = \\frac{\\omega}{s + \\omega}\n\\end{equation}\n\nDifference equation coefficients:\n\n\\begin{align*}\na_0 &= \\omega T \\\\\na_1 &= a_0 \\\\\nb_0 &= \\omega T + 2 \\\\\nb_1 &= \\omega T - 2\n\\end{align*}\n\n\\section{Second Order Low-Pass Filter}\n\nContinuous-time transfer function:\n\n\\begin{equation}\n\\frac{Y}{U} = \\frac{\\omega^2}{s^2 + 2 \\zeta \\omega s + \\omega^2}\n\\end{equation}\n\nDifference equation coefficients:\n\n\\begin{align*}\na_0 &= \\omega^2 T^2 \\\\\na_1 &= 2 a_0 \\\\\na_2 &= a_0 \\\\\nb_0 &= \\omega^2 T^2 + 4 + 4 \\zeta \\omega T \\\\\nb_1 &= 2 \\omega^2 T^2 - 8 \\\\\nb_2 &= \\omega^2 T^2 + 4 - 4 \\zeta \\omega T\n\\end{align*}\n\n\\section{First Order High-Pass Filter}\n\nContinuous-time transfer function:\n\n\\begin{equation}\n\\frac{Y}{U} = \\frac{s}{s + \\omega}\n\\end{equation}\n\nDifference equation coefficients:\n\n\\begin{align*}\na_0 &= 2 \\\\\na_1 &= -2 \\\\\nb_0 &= \\omega T + 2 \\\\\nb_1 &= \\omega T - 2\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "cf11f9a180df475214d0151026f83ad206d81317", "size": 2784, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/filters.tex", "max_stars_repo_name": "KerryL/Filters", "max_stars_repo_head_hexsha": "1fd5f7b8072be6416c989e2cc3c6bac9653f251d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/filters.tex", "max_issues_repo_name": "KerryL/Filters", "max_issues_repo_head_hexsha": "1fd5f7b8072be6416c989e2cc3c6bac9653f251d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/filters.tex", "max_forks_repo_name": "KerryL/Filters", "max_forks_repo_head_hexsha": "1fd5f7b8072be6416c989e2cc3c6bac9653f251d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3720930233, "max_line_length": 474, "alphanum_fraction": 0.7036637931, "num_tokens": 873, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936879, "lm_q2_score": 0.8311430415844385, "lm_q1q2_score": 0.7047824954770666}}
{"text": "\\section{Determinants and row operations}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine the effect of a row operation on the determinant of\n    a matrix.\n  \\item Use row operations to calculate a determinant.\n  \\end{enumerate}\n\\end{outcome}\n\nRecall that there are three kinds of elementary row operations%\n\\index{matrix!row operation}%\n\\index{matrix!elementary row operation}%\n\\index{row operation}%\n\\index{elementary row operation} on matrices:\n\\begin{enumerate}\n\\item Switch two rows.\n\\item Multiply a row by a non-zero number.\n\\item Add a multiple of one row to another row.\n\\end{enumerate}\nThe following theorem examines the effect of these row operations on\nthe determinant of a matrix.\n\n\\begin{theorem}{Effect of row operations on the determinant}{determinant-row-operations}\n  Let $A$ be an $n\\times n$-matrix.\n  \\begin{enumerate}\n  \\item If $B$ is obtained from $A$ by switching two rows, then\n    \\begin{equation*}\n      \\det(B) = -\\det(A).\n    \\end{equation*}\n  \\item If $B$ is obtained from $A$ by multiplying one row by a\n    non-zero scalar $k$, then\n    \\begin{equation*}\n      \\det(B) = k\\det(A).\n    \\end{equation*}\n  \\item If $B$ is obtained from $A$ by adding a multiple of one row to\n    another row, then\n    \\begin{equation*}\n      \\det(B) = \\det(A).\n    \\end{equation*}\n  \\end{enumerate}\n\\end{theorem}\n\nNotice that the second part of this theorem is true when we multiply\n{\\em one} row of the matrix by $k$.  If we were to multiply {\\em two}\nrows of $A$ by $k$ to obtain $B$, we would have\n$\\det(B) = k^2 \\det(A)$.\n\n\\begin{example}{Using row operations to calculate a determinant}{determinant-row-operations1}\n  Use row operations to calculate the following determinant:\n  \\begin{equation*}\n    \\begin{absmatrix}{rrr}\n      1 & 5 & 5 \\\\\n      0 & 0 & -3 \\\\\n      0 & 2 & 7 \\\\\n    \\end{absmatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  If we switch the second and third rows, we obtain a triangular\n  matrix, of which the determinant is easy to compute. By\n  Theorem~\\ref{thm:determinant-row-operations}, switching two rows\n  negates the determinant. We therefore have:\n  \\begin{equation*}\n    \\begin{absmatrix}{rrr}\n      1 & 5 & 5 \\\\\n      0 & 0 & -3 \\\\\n      0 & 2 & 7 \\\\\n    \\end{absmatrix}\n    ~=~\n    -\\begin{absmatrix}{rrr}\n      1 & 5 & 5 \\\\\n      0 & 2 & 7 \\\\\n      0 & 0 & -3 \\\\\n    \\end{absmatrix}\n    ~=~ -(1\\cdot 2\\cdot(-3)) ~=~ 6.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Using row operations to calculate a determinant}{determinant-row-operations2}\n  Use row operations to calculate the following determinant:\n  \\begin{equation*}\n    \\begin{absmatrix}{rrr}\n      1 & 4 & -2 \\\\\n      1 & 8 & 1 \\\\\n      2 & 4 & -9 \\\\\n    \\end{absmatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We can use elementary row operations to reduce this matrix to\n  triangular form:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 4 & -2 \\\\\n      1 & 8 & 1 \\\\\n      2 & 4 & -9 \\\\\n    \\end{mymatrix}\n    \\stackrel{R_2\\rowop R_2-R_1}{\\roweq}\n    \\begin{mymatrix}{rrr}\n      1 & 4 & -2 \\\\\n      0 & 4 & 3 \\\\\n      2 & 4 & -9 \\\\\n    \\end{mymatrix}\n    \\stackrel{R_3\\rowop R_3-2R_1}{\\roweq}\n    \\begin{mymatrix}{rrr}\n      1 & 4 & -2 \\\\\n      0 & 4 & 3 \\\\\n      0 & -4 & -5 \\\\\n    \\end{mymatrix}\n    \\stackrel{R_3\\rowop R_3+R_2}{\\roweq}\n    \\begin{mymatrix}{rrr}\n      1 & 4 & -2 \\\\\n      0 & 4 & 3 \\\\\n      0 & 0 & -2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Each of the row operations is of the form ``add a multiple of one\n  row to another row'', and therefore does not change the\n  determinant. We therefore have:\n  \\begin{equation*}\n    \\begin{absmatrix}{rrr}\n      1 & 4 & -2 \\\\\n      1 & 8 & 1 \\\\\n      2 & 4 & -9 \\\\\n    \\end{absmatrix}\n    ~=~\n    \\begin{absmatrix}{rrr}\n      1 & 4 & -2 \\\\\n      0 & 4 & 3 \\\\\n      2 & 4 & -9 \\\\\n    \\end{absmatrix}\n    ~=~\n    \\begin{absmatrix}{rrr}\n      1 & 4 & -2 \\\\\n      0 & 4 & 3 \\\\\n      0 & -4 & -5 \\\\\n    \\end{absmatrix}\n    ~=~\n    \\begin{absmatrix}{rrr}\n      1 & 4 & -2 \\\\\n      0 & 4 & 3 \\\\\n      0 & 0 & -2 \\\\\n    \\end{absmatrix}\n    ~=~ 1\\cdot 4\\cdot(-2) = -8.\n  \\end{equation*}\n\\end{solution}\n\nIn general, we can convert any square matrix to triangular form using\nelementary row operations. In fact, it is always possible to do so\nusing only elementary operations of the first and third kind (swap two\nrows or add a multiple of one row to another). This gives us a very\nefficient way to compute determinants. If the matrices are large, this\nmethod is much more efficient than the cofactor method.\n\n\\begin{example}{Using row operations to calculate a determinant}{determinant-row-operations3}\n  Use elementary row operations of the first and third kind to calculate the\n  following determinant:\n  \\begin{equation*}\n    \\begin{absmatrix}{rrrr}\n      0 & 2 & 1 & 4 \\\\\n      2 & 2 & -4 & -1 \\\\\n      1 & 1 & -2 & -1 \\\\\n      1 & 3 & 2 & 5 \\\\\n    \\end{absmatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We use elementary row operations to reduce the matrix to triangular\n  form:\n  \\begin{equation*}\n    \\begin{array}{ccccc}\n      \\begin{mymatrix}{rrrr}\n        0 & 2 & 1 & 4 \\\\\n        2 & 2 & -4 & -1 \\\\\n        1 & 1 & -2 & -1 \\\\\n        1 & 3 & 2 & 5 \\\\\n      \\end{mymatrix}\n      &\\stackrel{R_1\\rowswap R_3}{\\roweq}&\n      \\begin{mymatrix}{rrrr}\n        1 & 1 & -2 & -1 \\\\\n        2 & 2 & -4 & -1 \\\\\n        0 & 2 & 1 & 4 \\\\\n        1 & 3 & 2 & 5 \\\\\n      \\end{mymatrix}\n      &\\stackrel{R_2\\rowop R_2-2R_1}{\\roweq}&\n      \\begin{mymatrix}{rrrr}\n        1 & 1 & -2 & -1 \\\\\n        0 & 0 & 0 & 1 \\\\\n        0 & 2 & 1 & 4 \\\\\n        1 & 3 & 2 & 5 \\\\\n      \\end{mymatrix}\n      \\\\\\\\[-1ex]\n      &\\stackrel{R_4\\rowop R_4-R_1}{\\roweq}&\n      \\begin{mymatrix}{rrrr}\n        1 & 1 & -2 & -1 \\\\\n        0 & 0 & 0 & 1 \\\\\n        0 & 2 & 1 & 4 \\\\\n        0 & 2 & 4 & 6 \\\\\n      \\end{mymatrix}\n      &\\stackrel{R_4\\rowop R_4-R_3}{\\roweq}&\n      \\begin{mymatrix}{rrrr}\n        1 & 1 & -2 & -1 \\\\\n        0 & 0 & 0 & 1 \\\\\n        0 & 2 & 1 & 4 \\\\\n        0 & 0 & 3 & 2 \\\\\n      \\end{mymatrix}\n      \\\\\\\\[-1ex]\n      &\\stackrel{R_2\\rowswap R_3}{\\roweq}&\n      \\begin{mymatrix}{rrrr}\n        1 & 1 & -2 & -1 \\\\\n        0 & 2 & 1 & 4 \\\\\n        0 & 0 & 0 & 1 \\\\\n        0 & 0 & 3 & 2 \\\\\n      \\end{mymatrix}\n      &\\stackrel{R_3\\rowswap R_4}{\\roweq}&\n      \\begin{mymatrix}{rrrr}\n        1 & 1 & -2 & -1 \\\\\n        0 & 2 & 1 & 4 \\\\\n        0 & 0 & 3 & 2 \\\\\n        0 & 0 & 0 & 1 \\\\\n      \\end{mymatrix}\n    \\end{array}\n  \\end{equation*}\n  By Theorem~\\ref{thm:determinant-row-operations}, the determinant\n  changes signs each time we swap two rows. The determinant is\n  unchanged when we add a multiple of one row to another. Therefore,\n  we have\n  \\begin{equation*}\n    \\begin{array}{ccccccc}\n      \\begin{absmatrix}{rrrr}\n        0 & 2 & 1 & 4 \\\\\n        2 & 2 & -4 & -1 \\\\\n        1 & 1 & -2 & -1 \\\\\n        1 & 3 & 2 & 5 \\\\\n      \\end{absmatrix}\n      &=&\n      - \\begin{absmatrix}{rrrr}\n        1 & 1 & -2 & -1 \\\\\n        2 & 2 & -4 & -1 \\\\\n        0 & 2 & 1 & 4 \\\\\n        1 & 3 & 2 & 5 \\\\\n      \\end{absmatrix}\n      &=&\n      - \\begin{absmatrix}{rrrr}\n        1 & 1 & -2 & -1 \\\\\n        0 & 0 & 0 & 1 \\\\\n        0 & 2 & 1 & 4 \\\\\n        1 & 3 & 2 & 5 \\\\\n      \\end{absmatrix}\n      \\\\\\\\[-1ex]\n      &=&\n      - \\begin{absmatrix}{rrrr}\n        1 & 1 & -2 & -1 \\\\\n        0 & 0 & 0 & 1 \\\\\n        0 & 2 & 1 & 4 \\\\\n        0 & 2 & 4 & 6 \\\\\n      \\end{absmatrix}\n      &=&\n      - \\begin{absmatrix}{rrrr}\n        1 & 1 & -2 & -1 \\\\\n        0 & 0 & 0 & 1 \\\\\n        0 & 2 & 1 & 4 \\\\\n        0 & 0 & 3 & 2 \\\\\n      \\end{absmatrix}\n      \\\\\\\\[-1ex]\n      &=&\n      + \\begin{absmatrix}{rrrr}\n        1 & 1 & -2 & -1 \\\\\n        0 & 2 & 1 & 4 \\\\\n        0 & 0 & 0 & 1 \\\\\n        0 & 0 & 3 & 2 \\\\\n      \\end{absmatrix}\n      &=&\n      - \\begin{absmatrix}{rrrr}\n        1 & 1 & -2 & -1 \\\\\n        0 & 2 & 1 & 4 \\\\\n        0 & 0 & 3 & 2 \\\\\n        0 & 0 & 0 & 1 \\\\\n      \\end{absmatrix}\n      &=& -6.\n    \\end{array}\n  \\end{equation*}\n  In practice, the last calculation could have been done in a single\n  step. All we had to do is count the number of swap operations we\n  performed during the row operations. If there is an odd number of\n  swap operations, the sign of the determinant changes; otherwise, it\n  stays the same.\n\\end{solution}\n\n", "meta": {"hexsha": "d58dc199bdb911fd9936ec7451cd4779d33f019f", "size": 8252, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Determinants-RowOperations.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Determinants-RowOperations.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Determinants-RowOperations.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 28.0680272109, "max_line_length": 93, "alphanum_fraction": 0.5304168686, "num_tokens": 3021, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.831143031127974, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7047824882069764}}
{"text": "\\section{Common Vector-Valued Functions}\r\n\\input{./vectorValuedFunctions/circles}\r\n\\input{./vectorValuedFunctions/helices}\r\n\r\n\\noindent\r\nSince VVFs are essentially multiple single-input single-output functions packaged together, the domain of a VVF is the domain on which all components are defined.\\\\\r\n\r\n\\noindent\r\nFor example, if $\\vec{r}(t) = \\langle \\tan{t},6t,\\ln{\\left(16-t^2\\right)} \\rangle$,\r\n\\begin{itemize}\r\n\t\\item $\\tan{t}$ is defined for all real numbers not equivalent to $\\pm\\pi/2$ radians.\r\n\t\\item $6t$ is defined for all real numbers.\r\n\t\\item $\\ln{\\left(16-t^2\\right)}$ is defined for $t\\in\\left(-4,4\\right)$.\r\n\\end{itemize}\r\nThe intersection of these domains is $\\left(-4, -\\pi/2\\right) \\cup \\left(-\\pi/2, \\pi/2\\right) \\cup \\left(\\pi/2, 4\\right)$, which is the domain of $\\vec{r}(t)$.", "meta": {"hexsha": "d10b319d23a407a728358ab0b107127223fcfb75", "size": 801, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorValuedFunctions/CommonVVFs.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorValuedFunctions/CommonVVFs.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorValuedFunctions/CommonVVFs.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 53.4, "max_line_length": 165, "alphanum_fraction": 0.7016229713, "num_tokens": 260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.704766355402936}}
{"text": "\\documentclass[notitlepage]{problem-solving}\n\n\\author{Matt McCarthy}\n\\title{Fibonacci Generating Function}\n\\date{June 2016}\n\n\\addbibresource{fibonacci.bib}\n\\nocite{*}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{problem*}\n\tLet $(F_n)_{n\\in\\NN}$ denote the sequence of Fibonacci numbers.\n\tFind the closed form of $F_n$.\n\\end{problem*}\n\n\\section{Background}\n\nLets begin with the definition of the Fibonacci numbers.\n\\begin{definition}\n\tThe Fibonacci numbers $(F_n)_{n\\in\\NN}$ are defined by $F_1=F_2=1$, and $F_{n+2}=F_{n+1}+F_n$.\n\\end{definition}\n\nFrom the Fibonacci numbers we get the golden ratio, $\\varphi$, and its conjugate, $\\overline{\\varphi}$ where\n\\[\n\t\\varphi = \\frac{1+\\sqrt{5}}{2} \\text{ and } \\overline{\\varphi} = \\frac{1-\\sqrt{5}}{2}.\n\\]\n\nWhile the Fibonacci recurrence is simple, its difficult to tell from the definition what the $n$th Fibonacci number is without computing all of the terms before it.\nSince the Fibonacci's are defined recursively, we can use \\textit{generating functions} to extract a closed form for $F_n$ relatively easily.\n\n\\begin{definition}\n\tLet $(a_n)_{n\\in\\NN}$ be a $\\RR$-valued sequence.\n\tThen the generating function for $a_n$ is the power series\n\t\\[\n\t\tG(x) = \\sum_{n\\in\\NN} a_nx^n.\n\t\\]\n\\end{definition}\n\nAfter we create the generating function, we generally want to find its closed form (that is, a representation without using limits).\nThen, we use that new representation to find a closed form for the terms of the sequence (in this case, a non-recursive representation).\n\n\\section{Solution}\n\n\\begin{problem*}\n\tLet $(F_n)_{n\\in\\NN}$ denote the sequence of Fibonacci numbers.\n\tFind the closed form of $F_n$.\n\\end{problem*}\n\nWe begin by setting up a generating function, $F(x)$, for $F_n$.\n\\[\n\tF(x) := \\sum_{n=1}^\\infty F_n x^n.\n\\]\nThe next step is to use the recurrence, however $F_1$ and $F_2$ need to be handled separately since they are not defined recursively.\nThus,\n\\[\n\tF(x) = F_1 x + F_2 x^2 + \\sum_{n=3}^\\infty F_n x^n.\n\\]\nNow we apply the definition of the Fibonacci numbers yielding,\n\\[\n\tF(x) = x + x^2 + \\sum_{n=3}^\\infty (F_{n-1} + F_{n-2}) x^n.\n\\]\nBy rearranging we get,\n\\[\n\tF(x) = x + x^2 +\\paren{\\sum_{n=3}^\\infty F_{n-1} x^n} + \\paren{\\sum_{n=3}^\\infty F_{n-2} x^n}.\n\\]\nNow, we factor out some power of $x$ from each sum, yielding\n\\[\n\tF(x) = x + x^2 +x\\paren{\\sum_{n=3}^\\infty F_{n-1} x^{n-1}} + x^2\\paren{\\sum_{n=3}^\\infty F_{n-2} x^{n-2}}.\n\\]\nWe now reindex the sums and do some manipulation so that we get the following.\n\\[\n\tF(x) = x + x^2 +x\\paren{F_1x-F_1x+\\sum_{n=2}^\\infty F_{n} x^n} + x^2\\paren{\\sum_{n=1}^\\infty F_{n} x^n}\n\\]\nSome more manipulation yields,\n\\[\n\tF(x) = x + x^2 -x^2 +x\\paren{\\sum_{n=1}^\\infty F_n x^n} + x^2 \\paren{\\sum_{n=1}^\\infty F_n x^n}.\n\\]\nNote, that we see the original definition of $F(x)$ in this new form, therefore\n\\[\n\tF(x) = x + xF(x) + x^2 F(x).\n\\]\nSolving for $F(x)$ yields,\n\\[\n\tF(x) = \\frac{x}{1-x-x^2} = \\frac{x}{-(x^2+x-1)}.\n\\]\n\nThe next step is to find the closed form of $F_n$.\nWe know that $-\\varphi$ and $-\\overline{\\varphi}$ are roots of  the polynomial in the denominator, therefore\n\\[\n\tF(x) = \\frac{x}{-(x+\\varphi)(x+\\overline{\\varphi})}.\n\\]\nUsing $\\varphi\\overline{\\varphi} = -1$ yields,\n\\[\n\tF(x)=\\frac{x}{(1-\\varphi x)(1-\\overline{\\varphi}x)}.\n\\]\nNext, we perform partial fraction decomposition of $F(x)$, which gives us\n\\[\n\tF(x) = \\frac{1}{\\sqrt{5}} \\paren{\\frac{1}{1-\\varphi x}-\\frac{1}{1-\\overline{\\varphi}x}}.\n\\]\nUsing the formula for the power series for $(1-x)^{-1}$ yields,\n\\[\n\tF(x) = \\sum_{k=1}^\\infty \\frac{\\varphi^n-\\overline{\\varphi}^n}{\\sqrt{5}} x^n = \\sum_{k=1}^\\infty F_n x^n.\n\\]\nBy uniqueness of power series, we deduce that\n\\[\n\tF_n = \\frac{\\varphi^n-\\overline{\\varphi}^n}{\\sqrt{5}}.\n\\]\n\n\\printbibliography\n\n\\end{document}\n", "meta": {"hexsha": "924559c5c5298680f2ad4a8f689fb4ad05120e18", "size": 3740, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016-summer/fibonacci/fibonacci.tex", "max_stars_repo_name": "matt-mccarthy/problem-solving", "max_stars_repo_head_hexsha": "8014f517e5290f2904cfb49f3831f05e484d59ec", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2016-summer/fibonacci/fibonacci.tex", "max_issues_repo_name": "matt-mccarthy/problem-solving", "max_issues_repo_head_hexsha": "8014f517e5290f2904cfb49f3831f05e484d59ec", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2016-summer/fibonacci/fibonacci.tex", "max_forks_repo_name": "matt-mccarthy/problem-solving", "max_forks_repo_head_hexsha": "8014f517e5290f2904cfb49f3831f05e484d59ec", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.5217391304, "max_line_length": 164, "alphanum_fraction": 0.6665775401, "num_tokens": 1332, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.7956581073313276, "lm_q1q2_score": 0.7046598646530295}}
{"text": "%TODOS FOR THIS LAB\n%1.  Maybe merge mst and ImgSegMST\n\n\\lab{Algorithm}{Kruskal's and Prim's Algorithm}{Kruskal's and Prim's Algorithm}\n\\label{Ch:Kruskal}\n\n\\objective{Find a minimum spanning tree for a connected, weighted graph using Kruskal's Algorithm and Prim's Algorithm.}\n\n\\section*{Weighted Graphs and Spanning trees}\n\nRemember that a graph is composed of two sets: a set of nodes and a set of edges that connect the nodes.\n\n\\begin{figure}[H]\n\\includegraphics[width = .4\\textwidth]{graph1.pdf}\n\\caption{An example of an undirected graph}\n\\label{mst:graph1}\n\\end{figure}\n\nA graph is directed if connections are uni-directional.\nA graph is undirected if connections are bi-directional.\nFigure 7.1 shows an example of an undirected graph.\nA weighted graph is a graph where each edge has a value associated with it.\nUsually these values represent some sort of cost or distance.\nA connected graph is a graph where there is a path, or a set of edges, that connects every two nodes together.\nWe can write a matrix that describes this type of graph.\nEach row of our matrix represents a starting point and each column represents a destination.\nIf an edge from one node to another exists, we put the weight of the edge.\nIf there is no edge, we put a 0.\nFor the above graph in Figure 7.1 we generate the following matrix:\n\n\\[\nA = \\begin{pmatrix}\n0 & 1 & 0 & 0 & 0 & 0\\\\\n1 & 0 & 1 & 0 & 0 & 1\\\\\n0 & 1 & 0 & 1 & 1 & 1\\\\\n0 & 0 & 1 & 0 & 1 & 0\\\\\n0 & 0 & 1 & 1 & 0 & 1\\\\\n0 & 1 & 1 & 0 & 1 & 0\\\\\n\\end{pmatrix}\n\\]\n\nThis matrix is called an adjacency matrix.\nNote that since the graph is undirected, then this matrix is symmetric.\nNow consider the graph in Figure 7.4.  This graph is the same as the graph in Figure 7.1, except now there is a weight attached to each edge.  The matrix for this graph is\n\\[\nA = \\begin{pmatrix}\n0 & 3 & 0 & 0 & 0 & 6\\\\\n3 & 0 & 5 & 0 & 0 & 4\\\\\n0 & 5 & 0 & 1 & 1 & 5\\\\\n0 & 0 & 1 & 0 & 2 & 0\\\\\n0 & 0 & 1 & 2 & 0 & 4\\\\\n6 & 4 & 5 & 0 & 4 & 0\\\\\n\\end{pmatrix}\n\\]\n\nAnother way to store the information from a graph is to make a list of the edges with their corresponding weights.\nFor an unweighted, undirected graph, this would just mean making a list of the pairs of nodes that correspond to each edge.\nFor a weighted, undirected graph, a third value could be added to the end of each edge representing the corresponding weight of that edge.\nA list like this for the graph in Figure 7.1 would look like this:\n\n\\begin{align*}\n[('A', 'B'),\n ('B', 'C'),\n ('B', 'F'),\n ('C', 'D'),\\\\\n ('C', 'E'),\n ('C', 'F'),\n ('D', 'E'),\n ('E', 'F')]\n\\end{align*}\n\nFor this lab, we will be focusing on undirected, weighted graphs.\n\nA spanning tree of a connected, undirected graph $G$ is an undirected graph that contains all the nodes of $G$, a subset of the edges, and no cycles.\nA cycle, for undirected graphs, is a path where you start and end on the same node without crossing any edge more than once.\nThe red in Figure 7.2 is an example of a cycle in an undirected graph.\n\n\\begin{figure}[H]\n\\includegraphics[width = .4\\textwidth]{graph3.pdf}\n\\caption{A cycle in an undirected graph}\n\\label{mst:graph3}\n\\end{figure}\n\nThe minimum spanning tree (MST) of a weighted, undirected graph is a spanning tree where the total weight is less than or equal to the total weight of every other spanning tree.\nBoth Kruskal's and Prim's Algorithms are methods that find the minimum spanning tree of a weighted, undirected graph.\nFigure 7.3 shows a spanning tree of the graph shown in Figure 7.1.\nFigure 8.5 shows a minimum spanning tree of the graph shown in Figure 7.4.\n\n\\begin{figure}[H]\n\\includegraphics[width = .4\\textwidth]{graph2.pdf}\n\\caption{A spanning tree with no cycles for the graph in Figure 7.1.}\n\\label{mst:graph2}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width = .4\\textwidth]{graph4.pdf}\n\\caption{A weighted, undirected graph}\n\\label{mst:graph4}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width = .4\\textwidth]{graph5.pdf}\n\\caption{The MST of the graph in Figure 7.4.}\n\\end{figure}\n\n\\section*{Kruskal's algorithm}\n\nGiven a weighted, directed graph G with $n$ nodes, Kruskal's algorithm finds a minimum spanning tree by first sorting the edges from smallest to largest.\nThen starting with the smallest, the algorithm adds edges to the tree as long as the addition of each new edge does not create a cycle.\nWhen $n-1$ edges have been added, the algorithm stops.\n\nIn order to avoid creating cycles while building the tree, it is necessary to keep track of which portions of the tree currently lie in connected groups.\nThis can be done by creating a dictionary where, when the algorithm starts, each node points to itself as the \"root\" of its own tree.\nAs you add edges to the tree you will change which nodes are the \"root\" nodes. This tracks which nodes are currently connected.\nDoing this allows us to run the algorithm by iterating over the edges by weight in ascending order, and adding them to the tree if they connect nodes which are not already connected by the current tree.\n\nConsider the graph in Figure 7.4 and apply Kruskal's algorithm.\nFirst, we initialize our tree to be an empty list: \\li{[]}.\nTo track the root nodes of each tree, we will also initialize a dictionary where each node points to itself.\nIt will look like this: \\li{\\{A:A, B:B, C:C, D:D, E:E, F:F\\}}.\nSince there are 6 nodes in the graph, we will continue until we have 5 edges in the tree.\nNext, sort the edges by weight.\nThe result is something like the list \\li{[(C, D, 1), (C, E, 1), (D, E, 2), (A, B, 3), (B, F, 4), (E, F, 4), (B, C, 5), (C, F, 5), (A, F, 6)]}.\n\nNow we begin iterating through the edges to build the tree.\nThe first edge in the list is \\li{(C,D,1)}.\nThe root for \\li{C} is \\li{C} and the root for \\li{D} is \\li{D}, so we add this edge to the tree.\nThe tree becomes \\li{[(C, D, 1)]}.\nWe then change the root node of \\li{D} to be \\li{C}.\nThe dictionary of root nodes now looks like \\li{\\{A:A, B:B, C:C, D:C, E:E, F:F\\}}.\n\nNow we process the next edge, \\li{(C, E, 1)}.\nThe root node of \\li{C} is \\li{C}, and the root node of \\li{E} is \\li{E}, so adding this edge does not create a cycle.\nWe add this edge into the tree, so the tree is now \\li{[(C, D, 1), (C, E, 1)]}.\nThen we change the root of \\li{E} so that it is \\li{C}, so the dictionary is \\li{\\{A:A, B:B, C:C, D:C, E:C, F:F\\}}.\n\nThe next edge is \\li{(D, E, 2)}.\nThe root node of the tree containing \\li{D} is \\li{C} and the root node of the tree containing \\li{E} is \\li{C}, so these nodes are already connected, so we do not add this edge to the tree.\n\nThe next edge is \\li{(A, B, 3)}.\nThe root node for \\li{A} is \\li{A}, and the root node for \\li{B} is \\li{B}, so we add the edge to the tree and update the dictionary.\nThe dictionary becomes \\li{\\{A:A, B:A, C:C, D:C, E:C, F:F\\}}\n\nThe next edge is \\li{(B, F, 4)}.\nThe root node for \\li{B} is \\li{A} and the root node for \\li{F} is \\li{F}, so we add the edge to the tree and change the root node of \\li{F} to be \\li{A}.\nThe dictionary becomes \\li{\\{A:A, B:A, C:C, D:C, E:C, F:A\\}}\n\nThe next edge is \\li{(E, F, 4)}.\nThe root node for \\li{E} is \\li{C} and the root node for \\li{F} is \\li{A}.\nWe add the edge to the tree and end the algorithm since there are now 5 edges in the tree.\n(If we were to continue the algorithm, we would update the root node of \\li{A} to be \\li{C}.)\n\nNotice how we updated the root of the root node to one of the nodes in the edge added.\nWe manage the root nodes in this manner in order to find the root node by tracing back through the dictionary until we find a node that points to itself.\nFor example, to find the root node of \\li{F} we first need to get the value for \\li{F} from the dictionary.  This is \\li{A}.\nThen we get the value for \\li{A} from the dictionary which is \\li{C}.\nSince the value of \\li{C} in the dictionary is itself, the \\li{C} is the root node of the graph containing \\li{F}.\nIt is necessary to trace through the dictionary in this manner each time because we avoid iterating over all of the nodes and updating their root values everytime.\n\nBelow is the pseudocode for the algorithm as we have described it above:\n\n\\begin{itemize}\n\n% Note: The comments in the solutions match the pseudocode.\n% When making changes, please keep that in mind.\n\n\\item Initialize an empty list of edges for the minimum spanning tree.\n\n\\item Make a dictionary that points each node toward its root (not always directly to it).\nStart with each node pointing to itself.\n\n\\item Initialize the number of nodes that still need to be processed to the number of nodes minus 1.\n\n\\item Define a helper function that, given a node, traces through the dictionary to find the root of its tree.\nThis can be done like this:\n\n\t\\begin{itemize}\n\n\t\\item Initialize a temporary variable to be the node for which we are finding the root.\n\n\t\\item While the temporary node does not point to itself in the dictionary:\n\n\t\t\\begin{itemize}\n\n\t\t\\item Update the temporary node to be the node it currently points to in the dictionary.\n\n\t\t\\end{itemize}\n\n\t\\item Return the temporary node.\n\n\t\\end{itemize}\n\n\\item Iterate over the edges by ascending weight.\nUse a \\li{for} loop for this and return the tree when it is big enough which breaks the loop for you.\n\n\t\\begin{itemize}\n\n\t\\item Trace through the dictionary to find the root node of each of the nodes in the edge you are processing.\n\n\t\\item If the roots are not the same (i.e. if adding the edge doesn't form a cycle):\n\n\t\t\\begin{itemize}\n\n\t\t\\item Add the edge to the tree.\n\n\t\t\\item Lower the number of edges remaining by one.\n\n\t\t\\item If the number of edges remaining is 0, return the tree (which also breaks the loop).\n\n\t\t\\item Update the root of the root of the second node in the edge to be the root of the first node in the edge.\n\t\t\tThis lets us record that the two subtrees are now connected.\n\n\t\t\\end{itemize}\n\n\t\\end{itemize}\n\n\\end{itemize}\nNote on implementation: You can iterate over a sorted copy of a list using the built in \\li{sorted} function.\nYou can sort by the third value in each tuple using the \\li{itemgetter} function that is part of the \\li{operator} library included with Python.\nFor example:\n\\begin{lstlisting}\nfrom operator import itemgetter\n...\nfor n1, n2, weight in sorted(edges, key=itemgetter(2)):\n    ...\n\\end{lstlisting}\n\n\\begin{problem}\nImplement Kruskal's algorithm.\nTest your algorithm on random symmetric arrays.\nYou can generate a random symmetric array by multiplying a random array by its transpose.\nUse the data from MSTdata.npy to test your tree.\nUse np.load(\"MSTdata.npy\") to get it.\nUse the \\li{formChanger} function below to put it in the right form.\n\\begin{lstlisting}\ndef formChanger(oldData):\n    newData=[]\n    for i in oldData: newData.append((i[0],i[1],int(i[2])))\n    return newData\n\\end{lstlisting}\n\\end{problem}\n\\section*{Prim's algorithm}\n\nPrim's is a similar algorithm for finding minimum spanning trees.\nWhile it is much slower than Kruskal's algorithm for sparse graphs, it is much faster for dense graphs because Prim's algorithm avoids sorting the edges.\n\nAgain, consider the example shown in Figure 7.4.\nWe first initialize a dictionary with all the nodes as keys in order to track which nodes have not been processed.\nAt the beginning it will be \\li{\\{A:False, B:False, C:False, D:False, E:False, F:False\\}}.\nWe then form the dictionary that maps each node to the edges that contain it.\nSince we will already know one node of each edge while we use the dictionary, we only need to store the node that is not being looked up.\nIt should end up looking like \\li{\\{A:[(B, 3), (F, 6)], B:[(A, 3), (C, 5), (F, 4)], C:[(B, 5), (D, 1), (E, 1), (F, 5)], D:[(C, 1), (E, 2)], E:[(C, 1), (D, 2), (F, 4)], F:[(A, 6), (B, 4), (C, 5), (E, 4)]\\}}.\nWe will also initialize an empty dictionary to track the shortest edges that run between nodes we have processed and nodes that we haven't.\nAs we iterated over the edges in our initialization step, we are also able to find the shortest edge.\nIn this case, it is \\li{(D, C, 1)}.\nLet's start with \\li{(D, C, 1)} and initialize our tree as the list \\li{[(D, C, 1)]}.\nNext, we mark \\li{D} and \\li{C} as processed in the dictionary that tracks which nodes have been processed.\nWe now start to build our dictionary of nodes that are one edge away from our processed nodes.\nIn this case, after adding the shortest edges between processed and unprocessed nodes to the dictionary, the dictionary becomes \\li{\\{B:(C, B, 5), E:(C, E, 1), F:(C, F, 5)\\}}.\nNotice we did not include \\li{E:(D, E, 2)} because there is a shorter edge to \\li{E} from \\li{C}.\n\nOf the edges in the dictionary of edges that can be processed next, the shortest is \\li{(C, E, 1)}, so we add that edge to the tree and mark \\li{E} as processed.\nWith \\li{E} being processed, we can now reach \\li{F} at a cost of 4.\nAfter making this change, the dictionary of edges to process becomes \\li{\\{B:(C, B, 5), E:(C, E, 1), F:(E, F, 4)\\}}.\nSince \\li{E} no longer needs to be processed, we can remove it from consideration.\nSo this dictionary now becomes \\li{\\{B:(C, B, 5), F:(E, F, 4)\\}}.\n\nOf the edges to be processed next, \\li{(E, F, 4)} is the shortest, so we add it to the tree and mark \\li{F} as processed.\nAfter performing the appropriate modifications to the dictionary of edges to be processed next, it becomes \\li{\\{B:(F, B, 4), A:(F, A, 6)\\}}.\n\nOf the edges to be processed next, \\li{(F, B, 4)} is the shortest, so we add it to the tree and mark \\li{B} as processed.\nAfter performing the appropriate modifications to the dictionary of edges to be processed next, it becomes \\li{\\{A:(B, A, 3)\\}}.\n\nThe only edge to be considered is \\li{(B, A, 3)}, so we add it to the tree.\nThe tree is long enough that it it spans the nodes, so the algorithm is finished.\n\nHere's pseudocode for a version of Prim's algorithm.\nWhile it is not a perfectly optimized version, it is pretty good.\n\n\\begin{itemize}\n\n% Note: The comments in the solutions match the pseudocode.\n% When making changes, pleas keep that in mind.\n\n\\item Initialize a dictionary to track which nodes have been processed.\n\n\\item Initialize an empty dictionary of lists to track the edges containing each node.\n\n\\item Fill the edge list.\n\tBe sure to add each edge to the list corresponding to both of its nodes.\n\n\\item Get the first edge to add (The shortest edge from any given node is a good pick).\n\n\\item Mark the nodes in the first edge as processed.\n\n\\item Initialize the tree to be the list containing the first edge.\n\n\\item Initialize an empty dictionary that will be used to contain the edges that can be processed next.\n\n\\item Define a helper function to insert an edge into the dictionary (if that insertion is needed).\n\tThis can be done as follows:\n\n\t\\begin{itemize}\n\n\t\\item Get the value of the node that is reached by the edge.\n\n\t\\item If that node isn't in the dictionary, set its value to be the edge passed to the functions.\n\n\t\\item If it is in the dictionary already, set its value to be the shorter of the edges being processed and the edges already in the dictionary.\n\n\t\\end{itemize}\n\n\\item Use the helper function to insert the edges reached by the first two processed nodes into the dictionary of edges to be processed.\n\n\\item Until the tree contains enough edges to span all the nodes:\n\n\t\\begin{itemize}\n\n\t\\item Find the shortest edge in the dictionary of edges to be processed.\n\n\t\\item Remove the shortest edge from the dictionary.\n\n\t\\item Add it to the tree.\n\n\t\\item Mark the node reached by the new edge as processed.\n\n\t\\item Use the helper function to insert the edges reached by the newly processed node into the dictionary of edges to be processed.\n\n\t\\end{itemize}\n\n\\item Return the completed tree.\n\n\\end{itemize}\n\n\\begin{problem}\nWrite a Python function that uses Prim's algorithm to find the minimum spanning tree of a graph.\nTest your implementation with the same data as the previous problem.\nCompare the speed of Prim's algorithm with the speed of Kruskal's algorithm.\nCreate a function which prints these two times.\n\\end{problem}\n\nMany graph packages have functions for finding the minimal spanning tree. One of these is NetworkX. You begin as follows\n\\begin{lstlisting}\nimport networkx as nx\nG=nx.Graph()\n\\end{lstlisting}\nYou can add a node $x$ with \\li{G.add_node(x)} and add a edge from $x$ to $y$ with weight n with \\li{G.add_edge(x,y,weight=n)}. Then \\li{nx.minimum_spanning_tree(G)} returns the minimal spanning tree using Kruskals algorithm.\n\n\\begin{problem}\nUse NetworkX to find the minimal spanning tree of the data in MSTdata.npy.\nCompare the output with that of your algorithm.\nCreate a function which prints your comparison.\n\\end{problem}\n\n%Add specifications\n\n\\section*{Image Segmentation}\n\n%Lab \\ref{MSTImgSeg}\n\nOne application of Minimal Spanning Trees (MSTs) is image segmentation.\nKruskal's algorithm is especially good at this.\nYou can convert an image into graph. Each pixel is a vertex and you define weights between the nodes. You then build the minimal spanning tree. If you take away the edge with the greatest weight you will get two forests (removing an edge from any graph with no cycles will create two forests). Then you can continue doing this to each forest to split up those forests. Each forest corresponds to a segment of the image.\nLet $k$ be the number of divisions that is wanted and $n$ be the number of nodes.\nKruskal's algorithm is performed until $n-(k+1)$ edges are added which is the same as taking out the $k$ edges with greatest weights.\n\nThere are many different ways to turn an image into a graph and weight the edges.\nA simple, yet effective, version is to make every pixel a node and the edges are the difference in intensities in the four cardinal directions.\n\n\nThis means that there are less than $4n$ edges.\nOther image segmentation algorithms have to use $n^2$ space.\nThis gives the MST algorithm a critical advantage over other image segmentation algorithms.\n\n\\begin{problem}\nWrite a function that takes a black and white image as input and outputs a list of the edges and a list of nodes.\nStore the edges using the form \\li{(node,node,weight)}.\n\\end{problem}\n\nThe provided Kruskal's algorithm takes as inputs the list of nodes, the list of edges and the number of divisions desired.\nThe number of divisions often has to be higher than the actual number that is needed because sometimes one or two pixels form a division because the difference between them and the pixels around them is so great.\nYou will have to adjust the number of divisions until the desired result is found.  See Figure 9.1.\n\n\\begin{problem}\nPerform the image segmentation algorithm on the image, then graph the original image and the three largest divisions.\n(Use the Counter class from collections to find the number of pixels in each division.)\n\\end{problem}\n\n\\begin{problem}\nMake a division of the image a different color.\n\\end{problem}\n\n\n\\vfill\n\\begin{figure}[ht]\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{MSTseg1.jpg}\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{MSTseg2.jpg}\n\\end{minipage}\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{MSTseg3.jpg}\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{MSTseg4.jpg}\n\\end{minipage}\n\\caption{The original image is in the top left hand corner. The three larges segments are shown in the other corners. The original image was 498x498 and 50000 divisions were used.}\n\\end{figure}\n\\vfill \n", "meta": {"hexsha": "fd81a2b2e99f5b8a30ebdae27addd1c6759fceb6", "size": 19467, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/MST/mst.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/MST/mst.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/MST/mst.tex", "max_forks_repo_name": "lcbendall/numerical_computing", "max_forks_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.6834532374, "max_line_length": 419, "alphanum_fraction": 0.733805928, "num_tokens": 5370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.8856314738181875, "lm_q1q2_score": 0.7046598643968742}}
{"text": "\\section{Yuyan}\n\nPlease present main results on manifold ...\n\n\\subsection{Manifold Learning}\nSuppose there a dataset $\\mathbf X =(\\mathbf x_1,...,\\mathbf x_n)$ and each $\\mathbf x_i\\in \\mathbb R^d$. In many  practical problem, the $\\mathbf x_i$ locates on a low dimension manifold $\\mathcal M$ in $\\mathbb R^d$. The goal of Manifold Learning is to find the parameter coordinate of $\\mathcal M$, so we can present the points $\\mathbf x_1,...,\\mathbf x_n$ in a essential form.\n\\subsubsection{Isomap}\nThe main idea of isomap is to keep the geodesic distance of $\\mathcal M$ during dimensionality reduction.\n\n\nThe Figure \\ref{fig:isomapmnist} is the effect of Isomap for MNist, it shows different digit in the MNist dataset is separable.\n%\\begin{figure}\n\t%\\centering\n\t%\\includegraphics[width=0.7\\linewidth]{../figures/IsomapMnist}\n\t%\\caption{The effect of Isomap for MNist}\n\t%\\label{fig:isomapmnist}\n%\\end{figure}\n", "meta": {"hexsha": "8fe4450eeeb8bbc1902b5b402a89c201e4f6d88b", "size": 910, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/yuyan.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/yuyan.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/yuyan.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.5555555556, "max_line_length": 381, "alphanum_fraction": 0.7494505495, "num_tokens": 262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7046598493773868}}
{"text": "\\section{Generic Time Triggered Cyclic Executive Scheduler}\nLet $f$ denote the frame length, $P$ the full period, $D(k)$ the relative deadline of task $k$,\n$C(k)$ its execution time, and $p(k)$ the period of task $k$ (how often it occurs).\nThen the following conditions have to be satisfied:\n\\begin{itemize}\n\t\\item $\\forall k . f \\leq p(k)$ (at most one execution within a frame)\n\t\\item $P = \\lcm_k\\left(p(k)\\right)$\n\t\\item $\\forall k . f \\geq C(k)$ (processes start and complete within single frame)\n\t\\item $\\forall k . 2f - \\gcd\\left(p(k),f\\right) \\leq D(k)$ (between release time and deadline of every task there is at least one frame boundary)\n\\end{itemize}\n", "meta": {"hexsha": "f846dbee15f5e01f8a5223c443dd145f89cf1a14", "size": 662, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "embedded systems/sections/time_triggered_cyclic_executive_scheduler.tex", "max_stars_repo_name": "ntruessel/eth-summaries", "max_stars_repo_head_hexsha": "dbfa4c206b441868a6ab55331c42daa96abd42bf", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "embedded systems/sections/time_triggered_cyclic_executive_scheduler.tex", "max_issues_repo_name": "ntruessel/eth-summaries", "max_issues_repo_head_hexsha": "dbfa4c206b441868a6ab55331c42daa96abd42bf", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "embedded systems/sections/time_triggered_cyclic_executive_scheduler.tex", "max_forks_repo_name": "ntruessel/eth-summaries", "max_forks_repo_head_hexsha": "dbfa4c206b441868a6ab55331c42daa96abd42bf", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.1818181818, "max_line_length": 146, "alphanum_fraction": 0.7054380665, "num_tokens": 198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.967899295134923, "lm_q2_score": 0.727975460709318, "lm_q1q2_score": 0.7046069352960697}}
{"text": "\\lab{Image Segmentation}{Image Segmentation}\n\n\\objective{Understand some basic applications of eigenvalues to graph theory.  Learn how to calculate the Laplacian matrix of a graph.  Apply the Laplacian matrix to determine connectivity of a graph and segment an image.}\n\\label{lab:ImgSeg_eigenvalues}\n\n\\section*{Graph Theory}\n\\begin{figure}\n\n \\begin{tikzpicture}[auto,node distance=1.5cm,\n thick,main node/.style={circle,draw}]\n\n  \\node[main node] (5) [] {6};\n  \\node[main node] (2) [below right of=5] {3};\n  \\node[main node] (3) [above right of=5] {4};\n  \\node[main node] (4) [right of=3] {5};\n  \\node[main node] (1) [right of=2] {2};\n  \\node[main node] (0) [below right of=4] {1};\n\n  \\foreach \\s/\\t in {5/3, 3/4, 4/0, 0/1, 1/2, 2/3, 1/4, 5/0} {\n   \\path[draw] (\\s) edge (\\t);}\n\\end{tikzpicture}\n\\caption{An undirected graph that is connected.}\n\\label{fig:example_graph}\n\\end{figure}\n\n\\begin{figure}\n\n \\begin{tikzpicture}[auto,node distance=2cm,\n thick,main node/.style={circle,draw}]\n\n  \\node[main node] (0) [] {1};\n  \\node[main node] (1) [below of=0] {2};\n  \\node[main node] (2) [right of=0] {3};\n  \\node[main node] (3) [below of=2] {4};\n  \\node[main node] (4) [right of=2] {5};\n  \\node[main node] (5) [right of=3] {6};\n\n   \\path[draw] (0) edge node [left] {3} (1);\n   \\path[draw] (2) edge node [left] {1} (3);\n   \\path[draw] (4) edge node{-1} (5);\n   \\path[draw] (3) edge node{2} (4);\n   \\path[draw] (3) edge node [below]{.5} (5);\n\\end{tikzpicture}\n\\caption{A weighted undirected graph that is not connected.}\n\\label{fig:example_graph2}\n\\end{figure}\n\n% \\begin{tikzpicture}[auto,node distance=1.5cm,\n% thick,main node/.style={circle,draw}]\n%\n%  \\node[main node] (2) [] {2};\n%  \\node[main node] (1) [below left of=2] {1};\n%  \\node[main node] (0) [below right of=2] {0};\n%\n%  \\foreach \\s/\\t in {1/1, 1/2, 1/3, 2/3} {\n%   \\path[draw] (\\s) edge (\\t);}\n%\\end{tikzpicture}\n%\\caption{An undirected graph that is not simple.}\n%\\label{fig:example_graph}\n%\\end{figure}\n\n\n%\\begin{figure}\n% \\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=1.5cm,\n% thick,main node/.style={circle,draw}]\n%\n%  \\node[main node] (A) [] {A};\n%  \\node[main node] (B) [below of=A] {B};\n%  \\node[main node] (C) [right of=A] {C};\n%  \\node[main node] (D) [below of=C] {D};\n%  \\node[main node] (E) [right of=C] {E};\n%  \\node[main node] (F) [right of=D] {F};\n%\n%  \\foreach \\s/\\t in {A/C, B/A, B/D, C/E, C/F, D/C} {\n%   \\path[draw] (\\s) edge (\\t);}\n%\\end{tikzpicture}\n%\\caption{A simple directed graph}\n%\\end{figure}\n\n\n\nGraph theory is a branch of mathematics dealing with mathematical structures called graphs.  Graphs represent relationships between objects.\n%For example, the transition diagram in Figure \\ref{fig:markov1} in Lab \\ref{lab:EigSolve} shows the relationship between states in a Markov chain.\nAn \\emph{undirected graph} is a set of nodes (or vertices) and edges, where each edge connects exactly two nodes (see Figure \\ref{fig:example_graph}).\nIn a \\emph{directed graph}, edges are directional. Each edge only goes one way, usually visualized as an arrow pointing from one node to another.\nIn this lab, we will only consider undirected graphs, which we will simply call graphs (unless we wish to emphasize the fact that they are undirected).\n\n%A graph is \\emph{simple} if no edge connects a node to itself. \n%The graph in Figure [TODO!] is simple, but the graph in Figure [TODO!] is not.\n\nA \\emph{weighted} graph is a graph with a weight attached to each edge.\nFor example, a weighted graph could represent a collection of cities with roads connecting them.\nThe vertices would be cities, the edges would be roads, and weight of an edge would be the length of a road.\nSuch a graph is depicted in Figure \\ref{fig:example_graph2}.\n\nAny unweighted graph can be thought of as a weighted graph by assigning a weight of 1 to each edge.\n\n\\subsection*{Adjacency, Degree, and Laplacian Matrices}\nWe will now introduce three matrices associated with a graph. \nThroughout this section, assume we are working with a weighted undirected graph with $N$ nodes, and that $w_{ij}$ is the weight attached to the edge connecting node $i$ and node $j$.\nWe first define the adjacency matrix.\n\n\\begin{definition} The \\emph{adjacency matrix} is an $N \\times N$ matrix whose $(i,j)$-th entry is\n\\begin{center}\n\t$ \\begin{cases}  w_{ij} & \\mbox{if an edge connects node i and node j} \\\\ 0 & \\mbox{otherwise.} \\end{cases}$\n\\end{center}\n% If the graph is not simple, there are differing conventions for how to define the diagonal of the adjacency matrix.\n\\end{definition}\n\nFor example, the graph in Figure \\ref{fig:example_graph} has the adjacency matrix $A_1$ and the graph in Figure \\ref{fig:example_graph2} has the adjacency matrix $A_2$, where\n\\[\nA_1 = \\begin{pmatrix}\n0 & 1 & 0 & 0 & 1 & 1\\\\\n1 & 0 & 1 & 0 & 1 & 0\\\\\n0 & 1 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 1 & 0 & 1 & 1\\\\\n1 & 1 & 0 & 1 & 0 & 0\\\\\n1 & 0 & 0 & 1 & 0 & 0\n\\end{pmatrix} \\qquad A_2 = \n \\begin{pmatrix}\n0 & 3 & 0 & 0 & 0 & 0\\\\\n3 & 0 & 0 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 1 & 0 & 2 & .5\\\\\n0 & 0 & 0 & 2 & 0 & -1\\\\\n0 & 0 & 0 & .5 & -1 & 0\n\\end{pmatrix}.\n\\]\nNotice that these adjacency matrices are symmetric. This will always be the case for undirected graphs.\n\n\\begin{comment}\nRaising the adjacency matrix to a power yields some very interesting information.\nWe can discover the number of paths of length $n$ between two nodes by raising a graph's adjacency matrix to the $n$th power.\nFor example, by squaring $A$, we can find the number of paths of length two between every pair of nodes.\n\\begin{lstlisting}\n>>> A = np.array([[0,1,0,0,1,0],[1,0,1,0,1,0],\n                  [0,1,0,1,0,0],[0,0,1,0,1,1],\n                  [1,1,0,1,0,0],[0,0,0,1,0,0]])\n\n>>> np.linalg.matrix_power(A,2)\narray([[2, 1, 1, 1, 1, 0],\n       [1, 3, 0, 2, 1, 0],\n       [1, 0, 2, 0, 2, 1],\n       [1, 2, 0, 3, 0, 0],\n       [1, 1, 2, 0, 3, 1],\n       [0, 0, 1, 0, 1, 1]])\n\\end{lstlisting}\nWe can see that no paths of length two exist between node 0 and node 5 because $A^2_{0,5} = 0$.\nBy calculating $A^6$ we can find the number of paths of length six from node 3 to itself.\n\\begin{lstlisting}\n>>> np.linalg.matrix_power(A, 6)\narray([[45, 54, 38, 45, 54, 16],\n       [54, 86, 29, 77, 51, 11],\n       [38, 29, 55, 15, 70, 27],\n       [45, 77, 15, 75, 31,  4],\n       [54, 51, 70, 31, 93, 34],\n       [16, 11, 27,  4, 34, 14]])\n\\end{lstlisting}\nWe see that there are 75 unique paths of length six from node 3 to itself.\nImagine trying to count all of those paths by hand!\nIt would be very easy to count incorrectly.\nThis method makes it very simple to count paths without mistakes.\n\nAdjacency matrices can also be composed of \\li{True} and \\li{False} values.\nIn this case, the $n$th power of such a matrix (using boolean arithmetic)\nis again a matrix of\nboolean values which simply indicate whether there exists a path of length $n$ between the given pair of nodes, rather than indicating the number of such\npaths.\n\n\\begin{problem}\nLet the following matrix represent a directed graph\n\\[\n\\begin{pmatrix}\n0 & 0 & 1 & 0 & 1 & 0 & 1 \\\\\n1 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n0 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n1 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\n0 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n0 & 0 & 1 & 0 & 0 & 0 & 1 \\\\\n0 & 1 & 0 & 0 & 0 & 0 & 0\n\\end{pmatrix}\n\\]\nBetween which pair of nodes does there exist the greatest number of paths\nof length five?\nFrom which node to which node is there no path of length seven?\n\\end{problem}\n\\end{comment}\n\nThe second matrix is the degree matrix. \n\\begin{definition} The \\emph{degree matrix} is an $N \\times N$ diagonal matrix whose $(i,i)$-th entry is\n\\[ \n\\sum_{j=1}^N w_{ij}.\n\\]\nThis quantity is the sum of the weight of each edge leaving node $i$.\n\\end{definition}\n%For a directed graph, each node has an \\emph{out-degree} (the number of edges directed away from a node) and an \\emph{in-degree} (the number edges directed toward a node).\nWe call the $(i, i)$-th entry of the degree matrix the \\emph{degree} of node $i$. As an example, the degree matrices of the graphs in Figures \\ref{fig:example_graph} and \\ref{fig:example_graph2} are $D_1$ and $D_2$, respectively.\n\n\\[\nD_1 = \\begin{pmatrix}\n3 & 0 & 0 & 0 & 0 & 0\\\\\n0 & 3 & 0 & 0 & 0 & 0\\\\\n0 & 0 & 2 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 3 & 0 & 0\\\\\n0 & 0 & 0 & 0 & 3 & 0\\\\\n0 & 0 & 0 & 0 & 0 & 2\n\\end{pmatrix}. \\qquad D_2 = \n \\begin{pmatrix}\n3 & 0 & 0 & 0 & 0 & 0\\\\\n0 & 3 & 0 & 0 & 0 & 0\\\\\n0 & 0 & 1 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 3.5 & 0 & 0\\\\\n0 & 0 & 0 & 0 & 1 & 0\\\\\n0 & 0 & 0 & 0 & 0 & -.5\n\\end{pmatrix}\n\\]\n\nFinally, we can combine the degree matrix and the adjacency matrix to get the Laplacian matrix.\n% Wikipedia defines the Laplacian of a simple graph only. I don't know why.\n% The graph in our application is NOT simple. \n% However, the non-simple parts cancel out, meaning that the Laplacian of the graph is the same as if you removed all self edges and then computed the Laplacian.\n% So I just define the Laplacian this way and don't talk about simple graphs.\n\\begin{definition}\nThe \\emph{Laplacian matrix} of a graph is \n\\[D - A \\]\nwhere $D$ is the degree matrix and $A$ is the adjacency matrix of the graph.\n\\end{definition}\n\nFor example, the Laplacian matrix of the graphs in Figures \\ref{fig:example_graph} and \\ref{fig:example_graph2} are $L_1$ and $L_2$, respectively, where\n\n\\[\nL_1 = \\begin{pmatrix}\n3 & -1 & 0 & 0 & -1 & -1\\\\\n-1 & 3 & -1 & 0 & -1 & 0\\\\\n0 & -1 & 2 & -1 & 0 & 0\\\\\n0 & 0 & -1 & 3 & -1 & -1\\\\\n-1 & -1 & 0 & -1 & 3& 0\\\\\n-1 & 0 & 0 & -1 & 0 & 2\n\\end{pmatrix}. \\qquad L_2 = \n \\begin{pmatrix}\n3 & -3 & 0 & 0 & 0 & 0\\\\\n-3 & 3 & 0 & 0 & 0 & 0\\\\\n0 & 0 & 1 & -1 & 0 & 0\\\\\n0 & 0 & -1 & 3.5 & -2 & -.5\\\\\n0 & 0 & 0 & -2 & 1 & 1\\\\\n0 & 0 & 0 &- .5 & 1 & -.5\n\\end{pmatrix}\n\\]\n\nIn this lab we will learn about graphs by studying their Laplacian matrices.\nWhile the Laplacian matrix seems simple, we can learn surprising things from its eigenvalues.\n\n\n\\begin{problem}\nWrite a function that accepts the adjacency matrix of a graph as an argument and returns the Laplacian matrix. \nTest your function on the graphs in Figures \\ref{fig:example_graph} and \\ref{fig:example_graph2}.\n\nHint: You can compute the diagonal of the degree matrix in one line by summing over an axis (see Lab \\ref{lab:NumpyIntro}).\n\\label{prob:laplacian}\n\\end{problem}\n\n\n\n\\subsection*{Connectivity: First Application of Laplacians}\n\nA \\emph{connected graph} is a graph where every vertex is connected to every other vertex by at least one path.\nThe graph in Figure \\ref{fig:example_graph} is connected, whereas the graph in Figure \\ref{fig:example_graph2} is not.\nIt is often important to know if a graph is connected.\nA naive approach to determine connectivity of a graph is to search every possible path from each vertex.\nWhile this works for very small graphs, most interesting graphs will have thousands of vertices, and for such graphs this approach is not feasible.\n\nInstead of the naive approach, we can use an interesting result from algebraic graph theory. \nThis result relates the connectivity of a graph to its Laplacian.\n\nThe Laplacian of any graph always has at least one zero eigenvalue.\nWhy is this true?  If $L$ is the Laplacian matrix of a graph, then the rows of $L$ must sum to 0.\n(Think about how L was created.)\nSince this is true, L cannot have full rank, so $\\lambda = 0$ must be an eigenvalue of $L$. \n\nFurthermore, if $L$ represents a graph that is \\textit{not} connected, more than one of the eigenvalues of $L$ will be zero. \nTo see this, let $J \\subset \\{1 \\dots N\\}$ such that the vertices $\\{v_j\\}_{j \\in J}$ form a connected component of the graph. \nDefine a vector $\\x$ such that\n \\[\n    \\x_j = \\begin{cases}\n        1, & j \\in J \\\\\n        0, & j \\not\\in J\n        \\end{cases}\n  \\]\n\nThen $\\x$ is an eigenvector of $L$ corresponding to the eigenvalue $\\lambda = 0$. \n(Look at the Laplacian matrix in Figure \\ref{fig:example_graph2} and consider the product $L_2 \\x$.) \nIn other words, for each connected component, 0 appears at least once as an eigenvalue.\n\nIn fact, it can be rigorously proven that the number of zero eigenvalues of the Laplacian exactly \\textit{equals} the number of connected components. \nIf we can solve for the eigenvalues of $L$, this makes it simple to calculate how many connected components are in the graph.\n\n$L$ is always a positive semi-definite matrix, so all of its eigenvalues are greater than or equal to 0.\nThe second smallest eigenvalue of $L$ is known as the \\textit{algebraic connectivity} of the graph.\nIt is clearly 0 for non-connected graphs.\nFor connected graphs, the algebraic connectivity can give us useful information about the sparsity or ``connectedness'' of a graph.\nA higher algebraic connectivity indicates that the graph is more strongly connected.\n\n\\begin{comment}\nThus, it will have real eigenvalues. \nSurprisingly, a graph is connected if the second smallest eigenvalue of its Laplacian matrix is positive.  By second smallest, we mean the second eigenvalue when they are ordered smallest to largest.  The eigenvalues of the Laplacian matrix are never negative; thus, if the second one is not zero, the graph is connected.\nIn many applications, the Laplacian matrix is sparse, so by taking advantage of this sparsity, we can cheaply determine if a graph is connected.\n\\end{comment}\n\n\\begin{problem}\n\\leavevmode\nCompute the number of connected components in a graph.\nWrite a function that accepts the adjacency matrix of a graph and returns two arguments: the number of connected components, and the algebraic connectivity of the graph (second smallest eigenvalue of the Laplacian).\n\nUse the \\li{scipy.linalg} package to compute the eigenvalues.\nNote that this package will return complex eigenvalues (with negligible imaginary parts). Keep only the real parts.\nYour function should also accept a tolerance value, such that all eigenvalues less than this value are assumed to be zero.\nThis should default to \\li{tol=1e-8}.\n\n\\begin{comment}\n%Old part of problem, removed because no great way to evaluate it\nHere is a function that creates a random symmetric matrix of Boolean values with sparsity determined by the input \\li{c}.\n\\begin{lstlisting}\ndef sparse_generator(n, c):\n    ''' Return a symmetric nxn matrix with sparsity determined by c.\n    Inputs:\n        n (int): dimension of matrix\n        c (float): a float in [0,1]. Larger values of c will produce\n             matrices with more entries equal to zero.\n    '''\n    A = np.random.rand(n**2).reshape((n, n))\n    A = ( A > c**(.5) )\n    return A.T.dot(A)\n\\end{lstlisting}\n\nTest your function on matrices created by \\li{sparse_generator} with inputs $n = 10, 100$ and $c = .25, .5, .95$. \nWhat do you notice about the likelihood that a random graph is connected?\n\\end{comment}\n\n\\end{problem}\n\n\n\\section*{Image Segmentation: Second Application of Laplacians}\n\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}{0.31\\textwidth}\n        \\includegraphics[width=\\textwidth]{RegMon.png}\n    \\end{subfigure}\n   \\hspace*{\\fill}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\includegraphics[width=\\textwidth]{NegMon.png}\n    \\end{subfigure}\n    \\hspace*{\\fill}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\includegraphics[width=\\textwidth]{PosMon.png}\n    \\end{subfigure}\n    \n\\caption{An image and its segments.}\n\\label{fig:monument}\n\\end{figure}\nImage segmentation is the process of finding natural boundaries in an image (see Figure \\ref{fig:monument}).\nThis is a simple task for humans, who can easily pick out portions of an image that ``belong together.''\nIn this lab, you will learn one way for a computer to segment images using graph theory.\n\nThe algorithm we will present comes from a paper by Jianbo Shi and Jitendra Malik in 2000 (\\cite{Shi2000}).\nThey segment an image using the following steps.\n\\begin{enumerate}\n\t\\item \\textbf{Represent the image as a weighted graph of pixels.} \nAn image is made up of individual pixels, each having a brightness and a location.\n(Here, \\emph{brightness} is equivalent to the grayscale value of the pixel.)\nTo define a graph representing the image, we let each pixel be a vertex.\n%We say that two pixels are connected in the graph if they are close together, i.e. within some distance $r$ of each other, in the image.\nThe weight of the edges between two pixels is determined by their distance apart and their similarity in brightness.\nWe define the graph so that two similar pixels (i.e., with similar brightness and location) will be connected by a strong edge.\n\t\\item \\textbf{Calculate the Laplacian.} \nWe calculate the adjacency and degree matrices of the graph representing the image, and use these to obtain the Laplacian.\n\t\\item \\textbf{Choose the best cut.} \nThe graph we have created is connected, but not all edges have the same weight.\nDissimilar pixels will be connected by edges that have a low weight.\nWe can split the graph into two connected components by ``cutting\" it along the low-weight edges.\nThese components are the image segments we are looking for.\n(We can also cut an image multiple times to segment it into more than two pieces.)\nAs we will see later, Shi and Malik's algorithm uses spectral information (eigenvectors) of the Laplacian to minimize the weight of the cut edges.\n\\end{enumerate}\n\n\\begin{comment}\n% Previous explanation which was refactored into the list form above\nTheir idea is to represent an image as a weighted graph as follows. \nTo a computer, an \\emph{image} is a collection of \\emph{pixels}. \nEach pixel has a brightness and coordinates describing its location in the image.\nTo define a graph representing this image, we let every pixel be a vertex.\nTwo pixels are connected if the distance between their coordinates is small (less than $r$).\nThe weight of the edge connecting two pixels is related to their similarity in brightness, where a low weight means they are very different.\n\nAfter defining this graph, we will segment the image by ``cutting'' (or removing) edges with low weights, which represent lines of high contrast in the image. \nThe ``cut'' is the total weight of the edges removed. Thus, to segment an image, we wish to minimize the ``cut.''\nWe can ``cut'' an image multiple times to segment an image into more than two pieces.\n\\end{comment}\n\n\n\\subsection*{Defining the Graph and Adjacency Matrix}\n\n%New\nWe now define the graph that represents an image. In our $M \\times N$ image, the associated graph will have $MN$ nodes, one representing each pixel. We let $w_{ij}$ be the weight of the edge connecting pixels $i$ and $j$, and define\n\n \\begin{equation}\n \\label{eq:adjacency}\nw_{ij} = \\begin{cases} \\exp(-\\frac{|I(i) - I(j)|}{\\sigma_I^2}-\\frac{d(i,j)}{\\sigma_d^2}) & \\mbox{ for $d(i,j) < r$} \\\\ 0 & \\mbox{ otherwise,} \\end{cases}\n\\end{equation}\nwhere\n\\begin{itemize}\n\t\\item$d(i,j)$ is the Euclidean distance between pixel $i$ and pixel $j$\n\t\\item $|I(i) - I(j)|$ is the difference in brightness of pixels $i$ and $j$\n\t\\item $r$, $\\sigma_I$ and $\\sigma_d$ are constants that we choose\n\\end{itemize}\n\nWith this definition, pixels that are farther apart than radius $r$ will never be connected. \nPixels within $r$ will be strongly connected if they are similar in brightness ($|I(i) - I(j)|$ is small) and close together ($d(i,j)$ is small).\nHighly contrasting pixels ($|I(i) - I(j)|$ is large) will be weakly connected. \nThis gives us a graph with the properties that we intuitively want.\n\nThe adjacency matrix $W$ is $(MN) \\times (MN)$ and has $w_{ij}$ as its $ij$th entry. \n$W$ will be sparse as long as $r$ is small. \nFigure \\ref{fig:adjacency} shows a visualization of the adjacency matrix for a $4 \\times 4$ image when $r=1.2$.\n\n\\begin{comment}\nNow let us define the adjacency matrix of the graph associated to an image. \nSince an $M \\times N$ image has $M \\times N$ pixels, the adjacency matrix will be $(M \\times N) \\times (M \\times N)$.\nAfter choosing a radius $r$ and some scaling factors $\\sigma_I$ and $\\sigma_d$, we define the adjacency matrix to be $W = (w_{ij})$, where\n\n\\begin{equation}\n\\label{eq:adjacency}\nw_{ij} = \\begin{cases} \\exp(-\\frac{|I(i) - I(j)|}{\\sigma_I^2}-\\frac{d(i,j)}{\\sigma_d^2}) & \\mbox{ for $d(i,j) < r$} \\\\ 0 & \\mbox{ otherwise,} \\end{cases}\n\\end{equation}\nwhere\n\\begin{itemize}\n\t\\item$d(i,j)$ is the Euclidean distance between pixel $i$ and pixel $j$.\n\t\\item $|I(i) - I(j)|$ is the difference in brightness of pixels $i$ and $j$.\n\\end{itemize}\n\n$W$ will be sparse as long as $r$ is small. \nFigure \\ref{fig:adjacency} shows what the adjacency matrix looks like for a $4x4$ image when $r=1.2$.\n\\end{comment}\n\n\\begin{figure}\n\\begin{tikzpicture}[dot/.style={circle,fill=black,minimum \n\tsize=4pt,inner sep=0pt,outer sep=-1pt}, >=stealth]\n%scale=.85, transform shape,\n\n\n%image\n\\draw[step=.75,thick](2.999,0)grid(6,3);\n%numbers 1-16\n\\foreach \\x in {1,2,3,4}\n\t\\foreach \\y in {4}\n\t\t\\node[draw=none, anchor=south west]at(\\x*.75+2.6, \\y-1.4){\\x};\n\\foreach \\x [evaluate=\\x as \\r using int(\\x+4)]in {1,2,3,4}\n\t\\foreach \\y in {3}\n\t\t\\node[draw=none, anchor=south west]at(\\x*.75+2.6, \\y-1.2){\\r};\n\\foreach \\x [evaluate=\\x as \\r using int(\\x+8)] in {1,2,3,4}\n\t\\foreach \\y in {2}\n\t\t\\node[draw=none, anchor=south west]at(\\x*.75+2.5, \\y-.95){\\r};\n\\foreach \\x [evaluate=\\x as \\r using int(\\x+12)] in {1,2,3,4}\n\t\\foreach \\y in {1}\n\t\t\\node[draw=none, anchor=south west]at(\\x*.75+2.5, \\y-.7){\\r};\n\n\\node[draw=none](image)at(4.5, -.5){$image$};\n\\node[draw=none](flattened)at(7.25,-3){\\textit{flattened image}};\n\\node[draw=none](adjacency)at(12,-3){\\textit{adjacency matrix}};\n\n%dots within grid\n\\foreach \\x in {1,2,3,4}\n\t\\foreach \\y in {1,2,3,4}\n\t\t\\node[draw, dot]at(\\x*.75+2.6,\\y*.75-.4){};\n\n%color fill\n\\foreach \\x/\\y in {2/3.75, 1.25/3, 2/3, 2.75/3, 2/2.25} {\\node[draw, minimum \n\tsize=.75cm, fill=green!30!black, fill opacity=.25]at(\\x+2.118,\\y-1.118){};}\n\n%circle in image\n\\node[draw, circle, minimum size=2cm,thick](circle)at(4.13,1.86){};\n\n%flattened image\n\\draw[step=.5, thick](6.999,-2.5)grid(7.5,5.5);\n\\foreach \\x in {7}\n\t\\foreach \\y in {1,...,16}\n\t\t\\node[draw=none]at(\\x+.25,\\y*-.5+5.75){\\y};\n\n\\draw[->,thick](6.1, 1.5)--(6.9,1.5);\n\n%adjancey matrix\n\\draw[step=.5](7.9999,-2.5)grid(16,5.5);\n%\\draw[step=2,thick](7.999,-2.5)grid(16,5.5);\n\n%outside labels\n\\foreach \\x in {1,5,9,13} {\\node[draw=none]at(\\x*.5+7.75,5.8){\\x};}\n\\foreach \\y in {1,5,9,13}{\\node[draw=none]at(16.3,\\y*-.5+5.8){\\y};}\n\n%shading of boxes\n\\foreach \\x/\\y in {8.5/5.5, 9/5.5, 8.5/5, 9/5, 9.5/5,9/4.5,9.5/4.5,10/4.5, \n\t9.5/4, 10/4, 10.5/5.5, 11/5,11.5/4.5, 12/4, 12.5/3.5, \n\t13.5/2.5, 14/2, 14.5/1.5, 15/1, 15.5/.5,16/0, 10.5/3.5, 11/3.5, 11/2.5, \n\t11.5/2.5,12/2.5, 11.5/2,12/2, 12.5/1.5, 13/1.5, 12.5/1, 13/1,\n\t13.5/1,13/.5,13.5/.5,14/.5, 13.5/0,14/0, 14.5/-.5,15/-.5,14.5/-1,\n\t15/-1,15.5/-1, 15/-1.5, 15.5/-1.5, 16/-1.5, 15.5/-2, 16/-2, 8.5/3.5,\n\t9.5/2.5,10/2,10.5/1.5,11/1,11.5/.5,12/0, 12.5/-.5, 13/-1, 13.5/-1.5, 14/-2} \n\t{\\node[draw, minimum size=.5cm, fill=black, fill opacity=.25]\n\tat(\\x-.25,\\y-.25){};}\n\n%green shaded boxes\n\\foreach \\x/\\y in {9/3,11/3, 11.5/3, 10.5/3, 13/3} {\\node\n\t[draw, minimum size=.5cm, fill=shadecolor]\n\tat(\\x-.25,\\y-.25){};}\n\n\\node[draw=none]at(8.75,2.75){2};\n\\node[draw=none]at(10.25,2.75){5};\n\\node[draw=none]at(10.75,2.75){6};\n\\node[draw=none]at(11.25,2.75){7};\n\\node[draw=none]at(12.75,2.75){10};\n\n\\end{tikzpicture}\n\n\\caption{The grid on the left represents a $4\\times4$ (or $M \\times N$) image with 16 pixels. \nAt right is the corresponding $16 \\times 16$ (or $(MN) \\times (MN)$) adjacency matrix with all nonzero entries shaded.\nFor example, in the $6^{th}$ row, entries 2, 5, 6, 7, and 10 are nonzero because those pixels are within radius $r$ of pixel 6 (here $r = 1.2$).}\n%For example, the $6^{th}$ row corresponds to the $6^{th}$ pixel. \n%Within that row, entries are nonzero if they correspond to pixels that are within radius $r$ of pixel 6 ($r = 1.2$ was used here).}\n\\label{fig:adjacency}\n\\end{figure}\n\n\n\\subsection*{Computing the Adjacency Matrix}\nWe will now write a function to compute the adjacency matrix for a given image.\n%The function will also accept constants \\li{radius}, \\li{sigma_I}, and \\li{sigma_d} to use in \\ref{eq:adjacency}. \nThe function will accept a filename and constants \\li{radius}, \\li{sigma_I}, and \\li{sigma_d}, and return the adjacency matrix and the diagonal of the corresponding degree matrix. \n\nThe basic approach is straightforward. \nFor each pixel in the image, compare it to every other pixel, use (\\ref{eq:adjacency}) to calculate the weight of the edge between them, and fill in the weight in the adjacency matrix.\nThis section will discuss how to implement this efficiently in Python.\n\nFirst, load an image and convert it to grayscale. \nThe included function \\li{getImage} helps handle color images.\nIt accepts a filename and returns a 2-D grayscale image.\n\nIt will be useful to flatten the $M \\times N$ image.\nThis converts it into a 1-D array of pixels of length $MN$, essentially giving each pixel an index. \nWe can use \\li{img.flatten} to flatten the array \\li{img}.\n\\begin{lstlisting}\n>>> A = np.array([[1,2],[3,4]])\n>>> A.flatten()                \narray([1,2,3,4])\n\\end{lstlisting}\n\nNext, initialize empty adjacency and degree matrices to fill in. \nAs in Figure \\ref{fig:adjacency}, the adjacency matrix will be sparse, so initialize it as a sparse matrix \\li{W}. \nUse the sparse matrix type \\li{lil_matrix}, which is optimized for filling in a matrix one entry at a time. \nSince we only need to store the diagonal of the degree matrix, initialize this diagonal as a regular 1-dimensional NumPy array \\li{D}.\n\nWe now fill in \\li{W} according to our definition in Equation \\ref{eq:adjacency}.\nEach pixel in the image corresponds to one row in \\li{W}.\nFor each pixel:\n\\begin{itemize}\n\\item Find its neighbors (the pixels in the image that are within distance $r$ of it)\n\\item Use \\ref{eq:adjacency} to calculate the weights connecting the pixel to each of its neighbors\n\\item Fill in these weights in \\li{W}, leaving the rest of the values in the row as zeros. \\footnote{Note that \\li{W} will be a symmetric matrix. We could potentially speed up this algorithm by taking advantage of this fact.}\n\\end{itemize} \nThe sum of the entries of a row in \\li{W} will be the corresponding entry in \\li{D}. \n\nYou may choose to use the provided helper function \\li{getNeighbors} to find the neighbors of a given pixel.\nThe function accepts the index of a pixel in the flattened image, along with a value for $r$ and the original image dimensions. \nIt returns two flat arrays: \\li{indices} and \\li{distances}. \nThe array \\li{indices} contains the indices of the neighbor pixels within distance $r$ of the input pixel. \nThe array \\li{distances} contains the corresponding distances of those pixels from the input pixel.\n%According to (\\ref{eq:adjacency}), the array \\li{indices} contains exactly the indices of the nonzero entries of the current row of \\li{W}.  \nUsing Figure \\ref{fig:adjacency} as an example, with the inputs 6, 1.2, 4, and 4 the outputs would be \\li{indices = array([2,5,6,7,10])} and \\li{distances = array([1,1,0,1,1])}. \nTry running the function with different inputs to build intuition about what it does.\n\nFinally, convert \\li{W} to the sparse matrix type \\li{csc_matrix}, which is faster for computations. Then return \\li{W} and \\li{D}.\n\n\\begin{problem}\nWrite the function \\li{adjacency} described in this section.\nAccept an image a filename and constants \\li{radius}, \\li{sigma_I}, and \\li{sigma_d}.\nReturn the corresponding sparse adjacency matrix \\li{W} and the diagonal of the degree matrix \\li{D}.\nUse (\\ref{eq:adjacency}) to compute the weights in the adjacency matrix.\nFor speed, try to compute an entire row of \\li{W} at once, instead of filling in \\li{W} entry by entry.\n\n\n%Notice that for each pixel you can save time by only checking the pixels $r$ rows and columns away.\n%For that you'll have to handle the pixels on the edges and corners of the image carefully.\n%I gave them new helper code, which abstracts away the edge cases.\n\\label{prob:adjacency_dream}\n\\end{problem}\n\n\\subsection*{Minimizing the `Cut'}\nAs stated earlier, the goal is to split the image into two segments, while minimizing the weight of the edges that are `cut' in the corresponding graph.\nLet $L$ be the Laplacian of the adjacency matrix defined in \\ref{eq:adjacency} and let $D$ be the degree matrix.\nShi and Malik proved that using the second smallest eigenvalue of $D^{-1/2}LD^{-1/2}$, we can minimize the `cut' .\nBoth $D$ and $L$ will be symmetric matrices, so all eigenvalues of $D^{-1/2}LD^{-1/2}$ will be real, therefore the second smallest one is well-defined.\n(Note that $D^{-1/2}$ refers not to matrix, but element-wise, exponentiation.)\n\nThe eigenvector associated to the second smallest eigenvalue is the key to segmenting the image. \nThis eigenvector will have $MN$ entries.\nShi and Malik proved that the indices of its \\emph{positive} entries are the indices of the pixels in the flattened image which belong in one segment.\nLikewise, the indices of its \\emph{negative} entries are the indices of the pixels which belong in the other segment.\n\nTo compute the segments, reshape this eigenvector as an $M \\times N$ array, and set the positive entries to True and the negative entries to False.\nWe can multiply this True-False mask entry-wise by the image. \nThis zeros out the pixels in the image corresponding to the \\li{False} entries in the mask, without affecting the pixels corresponding to \\li{True} entries. \nWe can negate the mask using the tilde operator, which lets us compute the other segment of the image. \nFinally we return the two segments.\n\n\\begin{comment}\nHere is the definition of a function that will segment an image.\n\\begin{lstlisting}\n1. def segment(img):\n\\end{lstlisting}\n\nUse the function \\li{adjacency} from Problem \\ref{prob:adjacency_dream} to compute the adjacency matrix and the diagonal of the degree matrices of the image.\n\\begin{lstlisting}\n2.     W, D = adjacency(img)\n\\end{lstlisting}\n\nNext we create sparse matrices corresponding to $D$ and $D^{-1/2}$ in Shi and Malik's algorithm. Remember that the sparse matrix type \\li{csc_matrix} is best for computations.\n\\begin{lstlisting}\n3.     Dsq = # calculate the square root of D\n4.     D_matrix = spar.spdiags(D, 0, D.shape[1], D.shape[1], format = 'csc')\n5.     Dsq_matrix = # create a sparse matrix with diagonal Dsq\n\\end{lstlisting}\nNow it is simple to compute $D^{-1/2}LD^{-1/2}$. We call this matrix \\li{P}.\n\\begin{lstlisting}\n6.     L = # compute the Laplacian\n7.     P = # compute D^{-1/2}*L*D^{-1/2} as in Shi and Malik's algorithm\n\\end{lstlisting}\nAccording to Shi and Malik, we need the eigenvector corresponding to the second smallest eigenvalue of \\li{P}. We compute this with the \\li{eigs()} method of the \\li{scipy.sparse.linalg} module. We set the parameter \\li{which='SR'} in the function call in order to compute the eigenvalues with Smallest Real part and their corresponding eigenvectors. The parameter \\li{k} in the function call can be used to specify how many eigenvalues the method computes.\n\\begin{lstlisting}\n8.     e = # compute the two smallest eigenvalues of P and their eigenvectors\n9.     eigvec = # eigenvector of the second smallest eigenvalue\n\\end{lstlisting}\n\nNext we create a mask that is \\li{True} wherever \\li{eigvec} is positive and reshape it to be the size of \\li{img}. \n\\begin{lstlisting}\n10.    mask = # create mask\n\\end{lstlisting}\n\n\\begin{lstlisting}\n11.    pos = # compute positive segment\n12.    neg = # compute negative segment\n13.    return pos, neg\n\\end{lstlisting}\n\n\\end{comment}\n\n\\begin{problem} Write the function \\li{segment} to segment an image.\nThe function should accept an image filename and return both of the segments.\nYou should call the code you wrote in Problem \\ref{prob:adjacency_dream}.\nUse sparse matrices where possible.\n\n\nTest on the image \\li{dream.png}.\nYour segments should look like the segments in Figure \\ref{fig:dream_solution} (the original image is on the left). \n\nHints:\n\\begin{enumerate}\n\\item After defining $D^{-1/2}$, convert $D$ and $D^{-1/2}$ into sparse matrices using \\li{scipy.sparse.spdiags}.\n\\item Since are now dealing with sparse instead of dense matrices, you shouldn't use your solution to Problem \\ref{prob:laplacian} to calculate the Laplacian. \n\n\\item Multiply sparse matrices with \\li{A.dot(B)}.\n\n\\item Use \\li{scipy.sparse.eigsh} to calculate the eigenvector. This is a sparse eigenvalue solver optimized for symmetric matrices.\nSet the keyword \\li{which = \"SM\"} to return the smallest eigenvalues.\n\n\\item The provided function \\li{displayPosNeg} can be used to plot your images. \n\n\\end{enumerate}\n\n\\end{problem}\n\n\\begin{figure}\n\\centering\n    \\centering\n    \\begin{subfigure}{0.31\\textwidth}\n        \\includegraphics[width=\\textwidth]{RegDream.png}\n    \\end{subfigure}\n    \\hspace*{\\fill}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\includegraphics[width=\\textwidth]{NegDream.png}\n    \\end{subfigure}\n    \\hspace*{\\fill}\n    \\begin{subfigure}{0.31\\textwidth}\n        \\includegraphics[width=\\textwidth]{PosDream.png}\n    \\end{subfigure}\n\\caption{Segments of \\li{dream.png}}\n\\label{fig:dream_solution}\n\\end{figure}\n\n\\begin{comment} %Old stuff from middle of lab\nHere is the function definition, which includes some default values for the constants.\n\\begin{lstlisting}\n1.\tdef adjacency(img, radius=5.0, sigma_I = .15, sigma_d = 1.7):\n\\end{lstlisting}\n\\begin{lstlisting}\n4.     W = spar.lil_matrix((flat_img.size, flat_img.size), dtype=float)\n5.     D = np.zeros((1, flat_img.size))\n\\end{lstlisting}\n\nLater, our function will iterate through the rows of the adjacency matrix, initializing one row at a time. Each row corresponds to a pixel of the original image. Thus, we begin by flattening the image (see Figure \\ref{fig:adjacency}). We also store the dimensions of \\li{img} for later.\n\\begin{lstlisting}\n2.     flat_img = img.flatten()\n3.     height, width = img.shape\n\\end{lstlisting}\n\n\\begin{lstlisting}\n6.     for pixel in xrange(flat_img.size):\n7.         indices, distances = getNeighbors(pixel, radius, height, width)\n8.         weights = # weights[j] should be W[pixel, indices[j]]\n9.         W[pixel, indices] = weights\n10.        D[0,pixel] = weights.sum()\n\\end{lstlisting}\n\\end{comment}\n\n\\begin{comment}\n\\begin{lstlisting}\n11.    W = W.tocsc()\n12.    return W, D\n\\end{lstlisting}\n\\end{comment}\n\n\\begin{comment}\n\\section*{Appendix: helper code for Problem \\ref{prob:adjacency_dream}}\nHere is the function \\li{getNeighbors} which you can use to compute the adjacency matrix of an image, as in Problem \\ref{prob:adjacency_dream}.\n\n\\lstinputlisting[style=fromfile]{getNeighbors.py}\n\\end{comment}", "meta": {"hexsha": "ca9e165cd84fa7acc005539ab274c83008d7fe5a", "size": 34447, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol1A/ImageSegmentation/ImageSegmentation.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol1A/ImageSegmentation/ImageSegmentation.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol1A/ImageSegmentation/ImageSegmentation.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 46.9945429741, "max_line_length": 457, "alphanum_fraction": 0.7026156124, "num_tokens": 10849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214155, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7045740966074395}}
{"text": "\\section{Operational Laws}\n\\label{sec:Operational-Laws}\n\nOperational laws are laws that hold for any open/closed system \\footnote{they often are most powerful when applied to closed ones.} or part of it.\nThey are distribution independent and depends only on mean quantities.\nOperational laws can be put together to prove asymptotic bounds on closed networks behavior.\nThese asymptotic bounds are useful to answer what-if questions.\nThey are fundamental for the modification analysis.\n\nIn the following sections, we present the following operational laws: \n\\textit{Little's Law},\n\\textit{Utilization Law},\n\\textit{Forced Flow Law}, and \n\\textit{Bottleneck Law}.\n\n\n\n\n\\subsection{Little's Law}\n\\label{sec:Little-Law}\n\nThe Little's Law \\cite{little1961proof} is the most important operational law. It relates mean number of system jobs to the mean response time.\n\n\\begin{theorem}[Little's Law for open systems]\n\\label{thm:Little-Law-Open-Systems}\t\n\tFor any ergodic open system, we have that\n\t\n\t\\begin{equation}\n\t\\label{eqn:Little-Law-Open-Systems}\n\t\\expected{N} = \\lambda \\cdot \\expected{T}\n\t\\end{equation}\n\t\n\twhere $\\expected{N}$ is the expected number of jobs in the system, $\\lambda$ is the average arrival rate into the system, and $\\expected{T}$ is the mean time jobs spend in the system.\n\\end{theorem}\n\n\\begin{theorem}[Little's Law for closed systems]\n\\label{thm:Little-Law-Closed-Systems}\t\n\tFor any ergodic closed system, we have that\n\t\n\t\\begin{equation}\n\t\\label{eqn:Little-Law-Closed-Systems}\n\tN = X \\cdot \\expected{T}\n\t\\end{equation}\n\t\n\twhere $N$ is the multiprogramming level, $X$ is the throughput, and $\\expected{T}$ is the mean time jobs spend in the system.\n\\end{theorem}\n\nIt is important to note that Little's Law makes no assumption on arrival process, service process, network topology or anything else. It only requires the system to be in steady state with finite $\\expected{N}$ and $\\expected{T}$.\n\nThe Little's Law holds for higher moments only under very restrictive conditions (e.g. it requires FCFS \\cite{bertsimas1995distributional,brumelle1972generalization}).\n\nThe Little's Law take into account the \\textit{effective arrival rate}. Be aware to consider the three quantities in Little's Law on the same request flow.\n\nThe following is an alternative expression of the Little's Law for closed systems.\n\n\\begin{corollary}\n\\label{cor:Response-Time-Law-Closed-Systems}\n\t\n\tFor every ergodic closed system, we have that\n\t\n\t\\begin{equation}\n\t\\label{eqn:Response-Time-Law-Closed-Systems}\n\t\\expected{R} = \\frac{N}{X} - \\expected{Z}\n\t\\end{equation}\n\t\n\twhere \n\t$\\expected{R}$ is the expected response time,\n\t$N$ is the multiprogramming level,\n\t$X$ is the system throughput, and\n\t$\\expected{Z}$ is the expected think time.\n\t\n\t\\begin{proof}\n\t\tThe corollary directly follows from the Little's Law.\n\t\t\\begin{equation*}\n\t\t\\begin{split}\n\t\tN & = X \\cdot \\expected{T} \\\\\n\t\t& = X \\cdot (\\expected{R} + \\expected{Z}) \n\t\t\\end{split}\n\t\t\\end{equation*}\n\t\tSo we have\n\t\t\\begin{equation*}\n\t\t\\expected{R} = \\frac{N}{X} - \\expected{Z}\n\t\t\\end{equation*}\n\t\\end{proof}\n\\end{corollary}\n\n\n\n\n\\subsection{Utilization-Law}\n\\label{sec:Utilization-Law}\n\n\\begin{theorem}[Utilization Law]\n\\label{thm:Utilization-Law-2}\t\n\tFor every stable queue node we have that\n\t\n\t\\begin{equation}\n\t\\varrho = \\frac{\\lambda}{\\mu}\n\t\\end{equation}\n\t\n\twhere $\\varrho$ is the long-run fraction of time that the server is busy.\n\t\n\t\\begin{proof}\n\t\tLet us consider only the server of the queue node, without the associated queue. The number of jobs in the node is 1 with probability $\\varrho$ and 0 with probability $(1-\\varrho)$. Hence the the expected number of jobs in the node is $\\varrho$.\n\t\tSo, applying Little's Law, we have\n\t\t\\begin{equation*}\n\t\t\t\\begin{split}\n\t\t\t\\varrho & = \\expected{N} \\\\\n\t\t\t\t\t& = \\lambda \\cdot \\expected{T} \\\\\n\t\t\t\t\t& = \\lambda \\cdot \\expected{S} \\\\\n\t\t\t\t\t& = \\lambda \\cdot \\frac{1}{\\mu}\n\t\t\t\\end{split}\n\t\t\\end{equation*}\n\t\\end{proof}\n\\end{theorem}\n\nNotice that\n\n\\begin{equation}\n\\varrho_{i} = \\probability{server \\; i \\; busy} = \\expected{requests \\; to \\; server \\; i}\n\\end{equation}\nThat is, the utilization is the probability to have the server busy and the expected number of requests being served.\n\n\n\n\n\\subsection{Forced Flow Law}\n\\label{sec:Forced-Flow-Law}\n\n\\begin{theorem}[Forced Flow Law]\n\\label{thm:Forced-Flow-Law}\t\n\tFor every stable network of queues, we have that\n\t\n\t\\begin{equation}\n\t\\label{eqn-Forced-Flow-Law}\n\tX_{i} = \\expected{V_{i}} \\cdot X\n\t\\end{equation}\n\t\n\twhere \n\t$X$ is the system throughput,\n\t$X_{i}$ is the throughput at the \\textit{i}-th server, and\n\t$V_{i}$ is the visit ratio for the \\textit{i}-th server, that is the number of visits per job to the \\textit{i}-th server.\n\t\n\t\\begin{proof}\n\t\tLet us first consider a intuitive demonstration.\n\t\tFor every system completion, there are on average $\\expected{V_{i}}$ completions at the \\textit{i}-th server. Hence the rate of completions at the \\textit{i}-th server is $\\expected{V_{i}}$ times the rate of system completions.\n\t\t\n\t\tLet us now consider a more formal demonstration.\n\t\tLet $C(t)$ denote the system completions during time $t$, $C_{i}(t)$ denote the completions at the \\textit{i}-th server during time $t$, and $V_{i}^{(i)}$ denote the number of visits the the \\textit{j}-th job makes to the \\textit{i}-th server. Then,\n\t\t\\begin{equation*}\n\t\t\t\\begin{split}\n\t\t\t\tC_{i}(t) & = \\sum_{j \\in C(t))}V_{i}^{(j)} \\\\\n\t\t\t\t\\frac{C_{i}(t)}{t} & = \\frac{\\sum_{j \\in C(t))}V_{i}^{(j)} }{C(t)} \\cdot \\frac{C(t)}{t} \\\\\n\t\t\t\t\\lim_{t \\to \\infty} \\frac{C_{i}(t)}{t} & = \\lim_{t \\to \\infty} \\frac{\\sum_{j \\in C(t))}V_{i}^{(j)} }{C(t)} \\cdot \\lim_{t \\to \\infty} \\frac{C(t)}{t} \\\\\n\t\t\t\tX_{i} & = \\expected{V_{i}} \\cdot X\n\t\t\t\\end{split}\n\t\t\\end{equation*}\n\t\\end{proof}\n\\end{theorem}\n\n\n\n\n\\subsection{Bottleneck Law}\n\\label{sec:Bottleneck-Law}\n\nWe define $D_{i}$ to be the total service demand on the \\textit{i}-th server\n\n\\begin{equation}\nD_{i} = \\sum_{j=1}^{V_{i}}S_{i}^{(j)}\n\\end{equation}\n\nSince $V_{i}$ and $S_{i}^{(j)}$ are independent, we have that\n\n\\begin{equation}\n\\label{eqn:Service-Demand}\n\\expected{D_{i}} = \\expected{V_{i}} \\cdot \\expected{S_{i}}\n\\end{equation}\n\nIn practice, we measure $\\expected{D_{i}}$ as follows\n\n\\begin{equation}\n\\expected{D_{i}} = \\frac{B_{i}}{C} \n\\end{equation}\n\nwhere\n$B_{i}$ is the busy time for the \\textit{i}-th server, and\n$C$ is the system completions.\n\nLet $m$ be the number of servers in our system. Let\n\n\\begin{equation}\n\\label{eqn:Total-Demand}\nD = \\sum_{i=1}^{m}\\expected{D_{i}}\n\\end{equation}\n\nand\n\n\\begin{equation}\n\\label{eqn:Maximum-Demand}\nD_{max} = \\max\\{\\expected{D_{i}}\\}\n\\end{equation}\n\nPrevious definitions will be useful when discussing \\textit{Bottleneck Law}, \\textit{asymptotic bounds} and \\textit{modification analysis}.\n\n\\begin{theorem}[Bottleneck Law]\n\\label{thm:Bottleneck-Law}\t\n\tFor every stable network of queues, we have that\n\t\n\t\\begin{equation}\n\t\\label{eqn:Bottleneck-Law}\n\t\\varrho_{i} = X \\cdot \\expected{D_{i}}\n\t\\end{equation}\n\t\n\twhere \n\t$\\varrho_{i}$ is the utilization of the \\textit{i}-th server, \n\t$X$ is the system throughput, and\n\t$\\expected{D_{i}}$ is the expected service demand on the \\textit{i}-th server for all visits of a single job.\n\t\n\t\\begin{proof}\n\t\tLet us first consider an intuitive demonstration.\n\t\tLet $X$ denote the job/sec arrival rate to the whole system and let each arrival contribute $\\expected{D_{i}}$ seconds of work for the \\textit{i}-th server. We have that the \\textit{i}-th server is busy for $X \\cdot \\expected{D_{i}}$ seconds out of every second.\n\t\tThus $X \\cdot \\expected{D_{i}}$ represents the utilization of the \\textit{i}-th server.\n\t\t\n\t\tLet us now consider a more formal demonstration.\n\t\tLet us consider \n\t\tthe Utilization Law ($\\varrho = X \\cdot \\expected{S}$),\n\t\tthe Forced Flow Law ($X_{i} = \\expected{V_{i}} \\cdot X$), and\n\t\tthe demand definition ($D_{i} = \\sum_{j=1}^{V_{i}}S_{i}^{(j)} \\Rightarrow \\expected{D_{i}} = \\expected{V_{i}} \\cdot \\expected{S_{i}}$).\n\t\tWe have that\n\t\t\\begin{equation*}\n\t\t\t\\begin{split}\n\t\t\t\t\\varrho_{i} & = X_{i} \\cdot \\expected{S_{i}} \\\\\n\t\t\t\t\t\t\t& = X \\cdot \\expected{V_{i}} \\cdot \\expected{S_{i}} \\\\\n\t\t\t\t\t\t\t& = X \\cdot \\expected{D_{i}}\n\t\t\t\\end{split}\n\t\t\\end{equation*}\n\t\\end{proof}\n\\end{theorem}", "meta": {"hexsha": "9c71a2d0ba88af089e5de2b966ba37905aa646bb", "size": 8177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/operational-laws.tex", "max_stars_repo_name": "gmarciani/research", "max_stars_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-07-27T13:31:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-20T12:54:12.000Z", "max_issues_repo_path": "performance-modeling/sec/operational-laws.tex", "max_issues_repo_name": "gmarciani/research", "max_issues_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "performance-modeling/sec/operational-laws.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 34.2133891213, "max_line_length": 264, "alphanum_fraction": 0.7001345237, "num_tokens": 2621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.704574095915564}}
{"text": "\\subsection{Integral domains}\\label{subsec:integral_domains}\n\n\\begin{definition}\\label{def:integral_domain}\n  An \\term{integral domain} is an \\hyperref[def:entire_semiring]{entire} \\hyperref[def:ring/commutative]{commutative (unital) ring}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:integral_domain}\n  \\hyperref[def:integral_domain]{Integral domains} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:integral_domain/subring} Any \\hyperref[def:ring/submodel]{subring} of an integral domain is also an integral domain.\n\n    \\thmitem{thm:def:integral_domain/polynomial_ring} A commutative ring \\( R \\) is an integral domain if and only if its \\hyperref[def:polynomial_algebra]{polynomial ring} \\( R[X] \\) is.\n\n    \\thmitem{thm:def:integral_domain/root_limit} In an integral domain, the \\hyperref[def:polynomial_root]{multiset of roots} of a univariate nonzero polynomial of \\hyperref[def:polynomial_degree]{degree} \\( n \\) has \\hyperref[def:weighted_set/multiset]{multiset cardinality} at most \\( n \\).\n\n    In other words, a polynomial of degree cannot have more that \\( n \\) roots, counting multiple roots.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:integral_domain/subring} Trivial.\n\n  \\SubProofOf{thm:def:integral_domain/polynomial_ring}\n\n  \\NecessitySubProof* If \\( R[X] \\) is an integral domain, by \\fullref{thm:def:integral_domain/subring}, so is \\( R \\).\n\n  \\SufficiencySubProof* It is sufficient to prove the statement for one indeterminate. If \\( p(X) \\) and \\( q(X) \\) are nonzero polynomials, then so is \\( p(X) q(X) \\) by \\fullref{thm:def:polynomial_degree/product}.\n\n  \\SubProofOf{thm:def:integral_domain/root_limit} We will use induction on the degree. Zero-degree polynomials clearly have zero roots. Suppose that the statement holds for polynomials of degree \\( n - 1 \\), and let \\( p(X) \\) have degree \\( n \\).\n\n  If \\( p(X) \\) has a root \\( u \\), by the equivalence in \\fullref{def:polynomial_root}, \\( (X - u) \\) divides \\( p(X) \\). Then \\( \\ifrac {p(X)} {(X - u)} \\) has degree \\( n - 1 \\) by \\fullref{thm:def:polynomial_degree/product}. Let \\( M \\) be the multiset of roots of \\( \\ifrac {p(X)} {(X - u)} \\). After adding \\( u \\) to \\( M \\), we have incremented its total cardinality by \\( 1 \\), thus making it at most \\( n \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:quotient_by_prime_ideal}\n  The ideal \\( P \\) of the \\hyperref[def:ring/commutative]{commutative ring} \\( R \\) is \\hyperref[def:semiring_ideal/prime]{prime} if and only if the \\hyperref[def:ring/quotient]{quotient ring} \\( R / P \\) is an \\hyperref[def:integral_domain]{integral domain}.\n\n  See \\fullref{thm:quotient_by_maximal_ideal} for the corresponding statement for \\hyperref[def:semiring_ideal/maximal]{maximal ideals} in possibly noncommutative rings.\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Suppose that \\( P \\) is a prime ideal. Clearly \\( R / P \\) is a commutative ring. Since \\( P \\) is a proper ideal, \\( R / P \\) must be nontrivial. We will show that it is an \\hyperref[def:entire_semiring]{entire ring}.\n\n  Let \\( [x] [y] = [0] = P \\) (where \\( [x] = x + P \\) is the coset of \\( x \\) in \\( R / P \\)). By definition,\n  \\begin{equation*}\n    [x] [y] = (x + P) (y + P) = (xy + P),\n  \\end{equation*}\n  which implies \\( xy + P = P \\) and hence \\( xy \\in P \\). Since \\( P \\) is prime, by \\fullref{thm:def:semiring_ideal/prime_pointwise}, we have \\( x \\in P \\) or \\( y \\in P \\).\n\n  Therefore, \\( [x] = [0] \\) or \\( [y] = [0] \\). Generalizing on \\( x \\) and \\( y \\), we can conclude that \\( R / P \\) is entire, and thus an integral domain.\n\n  \\NecessitySubProof Suppose that \\( R / P \\) is an integral domain. Since \\( R / P \\) is nontrivial, \\( P \\) must be a proper ideal. We will show that it satisfies \\fullref{thm:def:semiring_ideal/prime_pointwise}.\n\n  Let \\( xy \\in P \\). We have\n  \\begin{equation*}\n    P = [0] = [xy] = [x] [y],\n  \\end{equation*}\n  hence \\( [x] \\) and \\( [y] \\) are zero divisors in \\( R / P \\). But \\( R / P \\) is entire, hence either \\( [x] \\) or \\( [y] \\) must be zero. That is, either \\( x \\in P \\) or \\( y \\in P \\).\n\n  Generalizing on \\( x \\) and \\( y \\), we can conclude that \\( P \\) is a prime ideal.\n\\end{proof}\n\n\\begin{definition}\\label{def:domain_divisibility}\\mimprovised\n  We will introduce several notions related to \\hyperref[def:divisibility]{divisibility} in \\hyperref[def:integral_domain]{integral domains}.\n\n  \\begin{thmenum}\n    \\thmitem{def:domain_divisibility/associates} We say that \\( x \\) and \\( y \\) are \\term{associates} if any of the following conditions hold:\n    \\begin{thmenum}\n      \\thmitem{def:domain_divisibility/associates/direct} Both \\( x \\mid y \\) and \\( y \\mid x \\).\n      \\thmitem{def:domain_divisibility/associates/unit} There exists a \\hyperref[def:divisibility/unit]{unit} \\( u \\) such that \\( x = uy \\).\n      \\thmitem{def:domain_divisibility/associates/ideals} The \\hyperref[def:semiring_ideal/principal]{principal ideals} \\( \\braket{ x } \\) and \\( \\braket{ y } \\) are equal.\n    \\end{thmenum}\n\n    \\thmitem{def:domain_divisibility/irreducible} We say that the nonzero nonunit element \\( x \\) is \\term{irreducible} if any of the following conditions hold:\n    \\begin{thmenum}\n      \\thmitem{def:domain_divisibility/irreducible/direct} Whenever \\( x = yz \\), then \\( y \\) or \\( z \\) is a unit.\n      \\thmitem{def:domain_divisibility/irreducible/ideals} \\( \\braket{ x } \\) is maximal among all proper principal ideals. Maximality means that, if \\( \\braket{ x } \\subseteq \\braket{ y } \\) for some nonzero nonunit \\( y \\), then \\( \\braket{ x } = \\braket{ y } \\).\n    \\end{thmenum}\n\n    \\thmitem{def:domain_divisibility/prime} We say that the nonzero element \\( x \\) is \\term{prime} if any of the following equivalent conditions hold:\n    \\begin{thmenum}\n      \\thmitem{def:domain_divisibility/prime/direct} If \\( x \\mid yz \\), then \\( x \\mid y \\) or \\( x \\mid z \\).\n      \\thmitem{def:domain_divisibility/prime/ideals} The ideal \\( \\braket{ x } \\) is \\hyperref[def:semiring_ideal/prime]{prime}.\n    \\end{thmenum}\n\n    This definition is motivated by \\fullref{thm:euclids_lemma}.\n  \\end{thmenum}\n\\end{definition}\n\\begin{defproof}\n  \\SubProofOf{def:domain_divisibility/associates}\n  \\ImplicationSubProof*{def:domain_divisibility/associates/direct}{def:domain_divisibility/associates/unit} If \\( x \\mid y \\) and \\( y \\mid x \\), then there exist \\( a \\) and \\( b \\) such that \\( x = ay \\) and \\( y = bx \\). Hence, \\( x = abx \\). Since we are working in an integral domain, we can cancel \\( x \\) to obtain \\( ab = 1_R \\). Therefore, both \\( a \\) and \\( b \\) are \\hyperref[def:divisibility/unit]{units}.\n\n  \\ImplicationSubProof*{def:domain_divisibility/associates/unit}{def:domain_divisibility/associates/ideals} Suppose that \\( x = uy \\) for some unit \\( u \\). If \\( z \\braket{ x } \\), then \\( x = uy \\) divides \\( z \\) and hence \\( y \\) also divides \\( z \\), implying that \\( \\braket{ x } \\subseteq \\braket{ y } \\). We obtain the converse inclusion by noting that \\( y = u^{-1} x \\).\n\n  \\ImplicationSubProof*{def:domain_divisibility/associates/ideals}{def:domain_divisibility/associates/direct} If \\( \\braket{ x } = \\braket{ y } \\), then, by \\fullref{thm:def:semiring_ideal/division}, \\( x \\mid y \\) and \\( y \\mid x \\).\n\n  \\SubProofOf{def:domain_divisibility/irreducible}\n  \\ImplicationSubProof*{def:domain_divisibility/irreducible/direct}{def:domain_divisibility/irreducible/ideals} Suppose that \\( x \\) is not a unit and that \\( x = yz \\) implies that \\( y \\) or \\( z \\) is a unit. Since we are working in an integral domain, \\( x \\) is necessarily nonzero.\n\n  Let \\( \\braket{ x } \\subseteq \\braket{ w } \\) for some nonunit \\( w \\). By \\fullref{thm:def:semiring_ideal/division}, \\( w \\mid x \\). Then there exists some element \\( a \\) such that \\( x = aw \\). Since \\( w \\) is not a unit by assumption, \\( a \\) must be a unit. By the equivalent definitions of associates in a domain, \\( \\braket{ x } = \\braket{ w } \\).\n\n  \\ImplicationSubProof*{def:domain_divisibility/irreducible/ideals}{def:domain_divisibility/irreducible/direct} Suppose that \\( \\braket{ x } \\) is maximal among nonzero proper principal ideals.\n\n  Let \\( x = yz \\). If, without loss of generality, \\( \\braket{ x } \\subseteq \\braket{ y } \\), then \\( \\braket{ x } = \\braket{ y } \\) and, again by the equivalent conditions for associates, there exists some unit \\( u \\) such that \\( x = uy \\). Cancelling \\( y \\) in \\( yu = yz \\), we obtain \\( u = z \\). Hence, \\( z \\) is a unit.\n\n  \\SubProofOf{def:domain_divisibility/prime} Trivial.\n\\end{defproof}\n\n\\begin{proposition}\\label{thm:def:domain_divisibility}\n  The notions from \\fullref{def:domain_divisibility} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:domain_divisibility/prime_is_irreducible} Every \\hyperref[def:domain_divisibility/prime]{prime element} is \\hyperref[def:domain_divisibility/irreducible]{irreducible}.\n\n    \\thmitem{thm:def:domain_divisibility/irreducible_in_polynomial_ring} An element of the domain \\( D \\) is \\hyperref[def:domain_divisibility/irreducible]{irreducible} in \\( D \\) if and only if it is irreducible in \\( D[X] \\).\n\n    \\thmitem{thm:def:domain_divisibility/associates_and_isomorphisms} If \\( \\varphi: D \\to E \\) is an isomorphism, then \\( x \\) and \\( y \\) are \\hyperref[def:domain_divisibility/associates]{associates} in \\( D \\) if and only if \\( \\varphi(x) \\) and \\( \\varphi(y) \\) are associates in \\( E \\).\n\n    \\thmitem{thm:def:domain_divisibility/primes_and_isomorphisms} If \\( \\varphi: D \\to E \\) is an isomorphism, then \\( x \\) is \\hyperref[def:domain_divisibility/prime]{prime} (resp. \\hyperref[def:domain_divisibility/irreducible]{irreducible}) in \\( D \\) if and only if \\( \\varphi(x) \\) is prime (resp. irreducible) in \\( E \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:domain_divisibility/prime_is_irreducible} Let \\( x \\) be a prime element and suppose that \\( x = yz \\). Then \\( x \\) divides \\( y \\) or \\( z \\). If, without loss of generality, \\( x \\) divides \\( y \\), then \\( x \\) and \\( y \\) are \\hyperref[def:divisibility/associates]{associates}, and, by the equivalence of conditions in \\fullref{def:domain_divisibility/associates}, \\( z \\) must be a unit.\n\n  \\SubProofOf{thm:def:domain_divisibility/irreducible_in_polynomial_ring}\n\n  \\SufficiencySubProof* Suppose that \\( x \\) is irreducible in \\( D \\) and let \\( x = y(X) z(X) \\). By \\fullref{thm:def:polynomial_degree/product}, both \\( y(X) \\) and \\( z(X) \\) must be constant polynomials. Therefore, they are scalars, and since \\( x \\) is irreducible, \\( y \\) or \\( z \\) is a unit. By \\fullref{thm:def:polynomial_algebra/units}, if \\( y \\) is a unit in \\( D \\), it is a unit in \\( D[X] \\).\n\n  Generalizing on \\( x \\), it follows that every irreducible element in \\( D \\) is also irreducible in \\( D[X] \\).\n\n  \\NecessitySubProof* Suppose that \\( x \\) is irreducible in \\( D[X] \\) and let \\( x = yz \\). Then \\( y \\) or \\( z \\) is a unit of \\( D[X] \\), and thus again by \\fullref{thm:def:polynomial_algebra/units}, it is a unit of \\( D \\).\n\n  Generalizing on \\( x \\), it follows that every element of \\( D \\) that is irreducible in \\( D[X] \\) is also irreducible in \\( D \\).\n\n  \\SubProofOf{thm:def:domain_divisibility/associates_and_isomorphisms} Follows from \\fullref{thm:divisibility_and_isomorphisms}.\n\n  \\SubProofOf{thm:def:domain_divisibility/primes_and_isomorphisms} Follows from \\fullref{thm:divisibility_and_isomorphisms}.\n\\end{proof}\n\n\\begin{example}\\label{ex:def:domain_divisibility}\n  We list some examples of the notions from \\fullref{def:domain_divisibility}:\n  \\begin{thmenum}\n    \\thmitem{ex:def:domain_divisibility/integers} \\hyperref[def:prime_number]{Prime numbers} are irreducible integers by their definition. By \\fullref{thm:euclids_lemma}, they are also prime.\n\n    The inverse \\( -p \\) of the prime number \\( p \\) is also irreducible and prime in \\( \\BbbZ \\), but convention requires \\enquote{prime numbers} to be positive.\n\n    \\thmitem{ex:def:domain_divisibility/irreducible_not_prime} Consider the ring of univariate \\hyperref[def:polynomial_algebra]{polynomials} over \\( \\BbbR \\) whose constant coefficient is rational.\n\n    The polynomial \\( X \\) is irreducible. Indeed, if \\( X = p(X) q(X) \\), by \\fullref{thm:def:polynomial_degree/product}, one of \\( p(X) \\) or \\( q(X) \\) must be a constant polynomial, i.e. a unit.\n\n    The polynomial \\( X \\) is not prime, however. We have \\( X \\mid (\\sqrt 2 X)^2 \\), but \\( X \\not\\mid \\sqrt 2 X \\) because that would imply that \\( \\sqrt 2 \\) is a polynomial in our ring, and it is not a rational number.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{remark}\\label{rem:choice_of_associates}\n  If \\( x \\) and \\( y \\) are \\hyperref[def:domain_divisibility/associates]{associates}, we generally have no reason to prefer \\( x \\) to \\( y \\). This leads to a non-uniqueness in certain contexts, e.g. choosing a \\hyperref[def:gcd_and_lcm]{greatest common divisor} or, more generally, a generator for a principal ideal. In such cases, we often prefer working with ideals.\n\n  Fortunately, in the majority of cases, we have good candidates for uniqueness:\n  \\begin{itemize}\n    \\item In the domain \\( \\BbbZ \\) of integers, there are two units, \\( 1 \\) and \\( -1 \\). It is conventional to choose the positive greatest common divisor.\n\n    \\item In a polynomial ring over the integers \\( \\BbbZ \\), by \\fullref{thm:def:polynomial_algebra/units}, the units are again \\( 1 \\) and \\( -1 \\), and we can choose the leading coefficient to be positive.\n\n    \\item If \\( \\BbbK \\) is any \\hyperref[def:field]{field}, any polynomial is associated with a unique \\hyperref[def:monic_polynomial]{monic polynomial}.\n  \\end{itemize}\n\\end{remark}\n\n\\begin{remark}\\label{rem:lattice_of_principal_ideals}\n  The lattice of ideals described in \\fullref{thm:semiring_of_ideals/lattice} is sometimes too general for our needs. Rather than stating definitions and theorems \\enquote{up to a multiplication by a unit}, it is often more convenient to state them in terms of principal ideals. For this reason, we sometimes restrict ourselves to a lattice consisting only of principal ideals.\n\n  Unfortunately, as demonstrated in \\fullref{ex:def:irreducible_factorization/nonunique}, there may not be a least upper bound of principal ideals, and thus set of all principal ideals may fail to be lattice. Whether the principal ideals form a lattice is intimately related to the existence of \\hyperref[def:gcd_and_lcm]{greatest common divisors}. This motivates introducing the concept of greatest common divisor domains defined in \\fullref{def:gcd_domain}.\n\n  The extreme case are \\hyperref[def:principal_ideal_domain]{principal ideal domains}, in which this lattice is the same as the general lattice of ideals.\n\\end{remark}\n\n\\begin{definition}\\label{def:gcd_domain}\n  We say that an \\hyperref[def:integral_domain]{integral domain} is a \\term{greatest common divisor domain} if the subset of all principal ideals forms a lattice. By \\fullref{thm:gcd_and_lcm}, it is sufficient for only joins or meets to exist.\n\n  This definition is discussed in \\fullref{rem:lattice_of_principal_ideals} and its relation to the usual concept of a greatest common divisor is given in \\fullref{def:gcd_and_lcm}.\n\\end{definition}\n\n\\begin{definition}\\label{def:gcd_and_lcm}\\mimprovised\n  Fix arbitrary elements \\( x \\) and \\( y \\) of a \\hyperref[def:gcd_domain]{GCD domain}.\n\n  Their \\term{greatest common divisor ideal} is the supremum of the principal ideals \\( \\braket{ x } \\) and \\( \\braket{ y } \\) in the \\hyperref[rem:lattice_of_principal_ideals]{lattice of principal ideals}. As discussed in \\fullref{rem:choice_of_associates}, we can often choose a canonical representative from this ideal, which we call \\enquote{the} greatest common divisor and denote by \\( \\gcd(x, y) \\). Even without making a choice, we may denote the ideal itself by \\( \\braket{ \\gcd(x, y) } \\).\n\n  \\hyperref[def:semilattice/duality]{Dually}, the infimum of this lattice is generated by \\enquote{the} \\term{least common multiple} \\( \\braket{ \\lcm(x, y) } \\).\n\n  Due to \\fullref{thm:def:gcd_domain/join}, we can extend GCDs and LCMs to finitely many elements rather than only two.\n\\end{definition}\n\n\\begin{remark}\\label{rem:gcd_of_zeros}\n  The greatest common divisor \\( \\gcd(0, 0) \\) is often left undefined, but we see no problem with defining it as \\( 0 \\). We have \\( \\braket{ 0 } + \\braket{ 0 } = \\braket{ 0 } \\), and hence the result is consistent with \\fullref{def:gcd_and_lcm}.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:gcd_and_lcm}\n  The \\hyperref[def:gcd_and_lcm]{greatest common divisors} and \\hyperref[def:gcd_and_lcm]{least common multiples} of \\( x \\) and \\( y \\) (have representative that) are related as follows:\n  \\begin{equation}\\label{eq:thm:gcd_and_lcm}\n    xy = \\gcd(x, y) \\lcm(x, y).\n  \\end{equation}\n\n  Furthermore, if in some integral domain only one of them exists, the other one exists too.\n\\end{proposition}\n\\begin{proof}\n  Let \\( d \\) be any common divisor of \\( x \\) and \\( y \\). Then \\( d \\) also divides the product \\( xy \\). Let \\( m \\), \\( a \\) and \\( b \\) be elements satisfying\n  \\begin{align*}\n    xy &= d m, \\\\\n     x &= d a, \\\\\n     y &= d b.\n  \\end{align*}\n\n  We have\n  \\begin{equation*}\n    x (db) = d m.\n  \\end{equation*}\n\n  Cancelling \\( d \\), we obtain that \\( x \\) divides \\( m \\). We similarly obtain that \\( y \\) divides \\( m \\).\n\n  Now suppose that \\( d \\) is the least common divisor. Let \\( m' \\) be a common multiple. We have \\( xy = m' d' \\) for some \\( d' \\). By \\hyperref[def:preordered_set/duality]{duality} to what we have just proved, \\( d' \\) must be a common divisor. We have \\( d' \\mid d \\), which in turn implies \\( m \\mid m' \\).\n\n  Therefore, \\( m \\) is a least common multiple.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:def:gcd_domain}\n  \\hyperref[def:gcd_domain]{Greatest common divisor domains} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:gcd_domain/join} A a lattice join, GCD is \\hyperref[def:magma/associative]{associative}, \\hyperref[def:magma/commutative]{commutative} and \\hyperref[def:magma/idempotent]{idempotent} when considered as a binary operation.\n\n    \\thmitem{thm:def:gcd_domain/polynomial_ring} If the \\hyperref[def:polynomial_algebra]{polynomial ring} \\( R[X] \\) over a commutative ring \\( R \\) is a greatest common divisor domain, then \\( R \\) also is.\n\n    The converse to this is true, but it is more difficult to prove. See \\fullref{thm:polynomial_ring_over_gcd_domain}.\n\n    \\thmitem{thm:def:gcd_domain/irreducible_is_prime} Every \\hyperref[def:domain_divisibility/irreducible]{irreducible element} is \\hyperref[def:domain_divisibility/prime]{prime}.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:gcd_domain/join} Follows from \\fullref{thm:binary_lattice_operations/semilattices}.\n\n  \\SubProofOf{thm:def:gcd_domain/polynomial_ring} By \\fullref{thm:def:integral_domain/subring}, \\( R \\) is an integral domain.\n\n  Given elements \\( x \\) and \\( y \\) from \\( D \\), \\( \\gcd(x, y) \\) is a polynomial in \\( R[X] \\) that divides each of the elements. Hence, by \\fullref{thm:def:polynomial_degree/product}, the GCD is a constant polynomial. We may thus regard it as an element of \\( R \\).\n\n  Therefore, \\( R \\) is also a greatest common divisor domain.\n\n  \\SubProofOf{thm:def:gcd_domain/irreducible_is_prime} Suppose that \\( x \\) is an irreducible element and let \\( x \\mid yz \\). If \\( x \\) is a unit, it divides both \\( y \\) and \\( z \\), and hence it is prime.\n\n  Suppose that \\( x \\) is not a unit. Putting \\( d \\coloneqq \\gcd(y, z) \\), we obtain\n  \\begin{equation*}\n    x \\mid x y = d \\cdot \\frac y d \\cdot \\frac z d,\n  \\end{equation*}\n  where \\( d \\), \\( \\tfrac y d \\) and \\( \\tfrac z d \\) are coprime. Hence, \\( x \\) divides exactly one of the three.\n\n  By transitivity of divisibility, \\( x \\) necessarily divides \\( y \\), \\( z \\) or both.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:bezouts_identity_converse}\n  In a \\hyperref[def:gcd_domain]{GCD domain}, if \\( d \\) divides both \\( x \\) and \\( y \\), and if there exist elements \\( a \\) and \\( b \\) such that \\( ax + by = d \\), then \\( d \\) is a \\hyperref[def:gcd_and_lcm]{greatest common divisor} of \\( x \\) and \\( y \\).\n\\end{proposition}\n\\begin{proof}\n  Suppose that \\( e \\) is a common divisor of \\( x \\) and \\( y \\). Then \\( e \\) divides both \\( ax \\) and \\( by \\), hence also \\( ax + by = d \\). Therefore, \\( e \\) divides \\( d \\), implying that \\( d \\) is the greatest common divisor of \\( x \\) and \\( y \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:coprime_elements}\n  We say that the nonzero elements \\( x \\) and \\( y \\) in a \\hyperref[def:gcd_domain]{GCD domain} are \\term{coprime} if any the \\hyperref[def:gcd_and_lcm]{greatest common divisor} of \\( x \\) and \\( y \\) is a unit.\n\n  In this form, the definition is unfortunately inconsistent with \\hyperref[def:semiring_ideal/coprime]{coprime ideals}. See \\fullref{thm:def:principal_ideal_domain/coprime}.\n\\end{definition}\n\n\\begin{definition}\\label{def:irreducible_factorization}\\mimprovised\n  An \\term{irreducible factorization} or simply \\term{factorization} of a nonzero element \\( x \\) in an arbitrary \\hyperref[def:integral_domain]{integral domain} is a finite sequence \\( p_1, \\ldots, p_n \\) of \\hyperref[def:domain_divisibility/irreducible]{irreducible elements} such that, for some \\hyperref[def:divisibility/unit]{unit} \\( u \\),\n  \\begin{equation*}\n    x = u p_1 \\cdots p_n.\n  \\end{equation*}\n\n  By cancellation of multiplication, the unit \\( u \\) is uniquely determined by the irreducible factors. If \\( x \\) is itself a unit, then it is its own factorization (i.e. \\( n = 0 \\)) because \\( p \\mid x \\) for an irreducible \\( p \\) would imply that \\( p \\) is a unit and hence not irreducible.\n\n  We say that two factorizations\n  \\begin{equation*}\n    x = u p_1 \\cdots p_n = v q_1 \\cdots q_m\n  \\end{equation*}\n  are equivalent if \\( n = m \\) and if there exists a \\hyperref[def:symmetric_group/permutation]{permutation} \\( \\pi \\in S_n \\) such that \\( q_{\\pi(k)} \\) and \\( p_k \\) are \\hyperref[def:domain_divisibility/associates]{associated} for every \\( k = 1, \\ldots, n \\).\n\n  Finally, if any two factorizations of \\( x \\) are unique, we say that \\( x \\) \\term{factors uniquely} into a product of irreducible factors.\n\\end{definition}\n\n\\begin{example}\\label{ex:def:irreducible_factorization}\n  We list some examples of \\hyperref[def:irreducible_factorization]{irreducible factorization}:\n  \\begin{thmenum}\n    \\thmitem{ex:def:irreducible_factorization/integers} By \\fullref{def:irreducible_factorization}, every integer has a unique factorization.\n\n    \\thmitem{ex:def:irreducible_factorization/nonunique} Consider the ring of real polynomials with a rational constant term discussed in \\fullref{ex:def:domain_divisibility/irreducible_not_prime}.\n\n    We have\n    \\begin{equation*}\n      2X^2 = (\\sqrt 2 X) \\cdot (\\sqrt 2 X) = 2 \\cdot X \\cdot X.\n    \\end{equation*}\n\n    We have shown in \\fullref{ex:def:domain_divisibility/irreducible_not_prime} that \\( X \\) is irreducible, and we can similarly show that \\( \\sqrt 2 X \\) is irreducible. Thus, the above are two irreducible factorizations. They are not equivalent, however, since \\( X \\not\\mid \\sqrt 2 X \\).\n\n    As a consequence, both \\( X \\) and \\( \\sqrt 2 X \\) are maximal divisors of \\( 2X^2 \\), but they are not \\hyperref[def:domain_divisibility/associates]{associates}.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{proposition}\\label{thm:def:irreducible_factorization}\n  \\hyperref[def:irreducible_factorization]{Irreducible factorizations} in integral domains have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:irreducible_factorization/existence} If every ascending chain of \\hi{principal} ideals stabilizes in the sense of \\fullref{def:noetherian_semimodule/acc}, then every element has at least one irreducible factorization.\n\n    This condition is sometimes abbreviated as ACCP (ascending chain condition on principal ideals).\n\n    \\thmitem{thm:def:irreducible_factorization/uniqueness} If every \\hyperref[def:domain_divisibility/irreducible]{irreducible element} is \\hyperref[def:domain_divisibility/prime]{prime}, then all factorizations of an element are equivalent (but there may be elements without a factorization).\n\n    \\thmitem{thm:def:irreducible_factorization/polynomial_ring} For any domain \\( D \\), \\( x = u p_1 \\cdots p_n \\) is an irreducible factorization in \\( D \\) if and only if it is an irreducible factorization of \\( x \\) in \\( D[X] \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:irreducible_factorization/existence} Suppose that every ascending chain of principal ideals stabilizes.\n\n  Let \\( x \\) be an arbitrary element, and suppose that it does not have an irreducible factorization. In particular, \\( x \\) is not a unit and is not irreducible. Then there exist elements \\( a_1 \\) and \\( b_1 \\), which are not both irreducible and not both units, such that \\( x = a_1 b_1 \\). Via \\hyperref[rem:natural_number_recursion]{natural number recursion}, we can build a sequence \\( a_1, a_2, \\ldots \\) such that\n  \\begin{equation*}\n    \\cdots \\mid a_2 \\mid a_1 \\mid x\n  \\end{equation*}\n  and no two elements are associates. By \\fullref{thm:def:semiring_ideal/division}, this implies\n  \\begin{equation*}\n    \\braket{ x } \\subsetneq \\braket{ a_1 } \\subsetneq \\braket{ a_2 } \\cdots.\n  \\end{equation*}\n\n  The existence of such a sequence contradicts the ACCP. Therefore, \\( x \\) must have at least one irreducible factorization.\n\n  \\SubProofOf{thm:def:irreducible_factorization/uniqueness} Suppose that every irreducible element is prime.\n\n  We will prove by induction that, if \\( x \\) has a factorization of length \\( n \\), then any other factorization is equivalent to it.\n\n  If \\( n = 0 \\), then \\( x = u \\) is a unit, and hence \\( m = 0 \\) and \\( x = u = v \\).\n\n  Otherwise, suppose that factorizations of length \\( n - 1 \\) are unique and that we are given the factorizations\n  \\begin{equation}\\label{eq:def:irreducible_factorization/uniqueness/proof/assumption}\n    x = u p_1 \\cdots p_n = v q_1 \\cdots q_m.\n  \\end{equation}\n\n  Since \\( p_1 \\) is prime, \\( p_1 \\) divides \\( q_{k_0} \\) for some \\( k_0 = 1, \\ldots, m \\). Thus, \\( p_1 = w q_k \\) for some unit \\( w \\). We can thus cancel \\( p_1 \\) to obtain\n  \\begin{equation*}\n    u p_2 \\cdots p_n = (vw) q_1 \\cdots q_{k_0-1} q_{k_0+1} \\cdots q_m.\n  \\end{equation*}\n\n  By the inductive hypothesis, this factorization is unique. Hence, \\( n = m \\), and there exists a permutation \\( \\pi \\in S_n \\) such that \\( p_k = q_{\\pi(k)} \\) for \\( k = 2, \\ldots, n \\). Then\n  \\begin{equation*}\n    \\widehat{\\pi}(k) \\coloneqq \\begin{cases}\n      k_0,    & k = 1 \\\\\n      \\pi(i), & k > 1\n    \\end{cases}\n  \\end{equation*}\n  is a permutation witnessing the equivalence of the factorizations \\eqref{eq:def:irreducible_factorization/uniqueness/proof/assumption}.\n\n  \\SubProofOf{thm:def:irreducible_factorization/polynomial_ring}\n\n  \\SufficiencySubProof* Suppose that\n  \\begin{equation}\\label{eq:thm:def:irreducible_factorization/polynomial_ring/sufficiency_assumption}\n    x = u(X) p_1(X) \\cdots p_n(X)\n  \\end{equation}\n  be an irreducible factorization of \\( x \\in D \\) in \\( D[X] \\). By \\fullref{thm:def:polynomial_degree/product}, all polynomials in this factorization are constants. By \\fullref{thm:def:domain_divisibility/irreducible_in_polynomial_ring}, since they are irreducible in \\( D[X] \\), they are also irreducible in \\( D \\).\n\n  Therefore, \\eqref{eq:thm:def:irreducible_factorization/polynomial_ring/sufficiency_assumption} is an irreducible factorization of \\( x \\) in \\( D \\).\n\n  \\NecessitySubProof* Due to \\fullref{thm:def:polynomial_algebra/units} and \\fullref{thm:def:domain_divisibility/irreducible_in_polynomial_ring}, irreducible elements and units in \\( D \\) are also irreducibles and units in \\( D[X] \\). Hence, every irreducible factorization in \\( D \\) is also an irreducible factorization in \\( D[X] \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:unique_factorization_domain}\n  We say that an \\hyperref[def:integral_domain]{integral domain} is a \\term{unique factorization domain} if any of the following equivalent conditions hold:\n  \\begin{thmenum}\n    \\thmitem{def:unique_factorization_domain/factorization} Every element \\hyperref[def:irreducible_factorization]{factors uniquely} into a product of irreducible elements.\n\n    \\thmitem{def:unique_factorization_domain/primes_and_ideals} Every ascending chain of principal ideals stabilizes and every irreducible element is prime.\n  \\end{thmenum}\n\\end{definition}\n\\begin{defproof}\n  \\ImplicationSubProof{def:unique_factorization_domain/factorization}{def:unique_factorization_domain/primes_and_ideals}\n\n  \\SubProof*{Proof that irreducibles are prime} holds, hence we only need to prove that an irreducible element is prime.\n\n  Let \\( x \\) be an irreducible element. Suppose that \\( x \\mid yz \\), so that there exists some element \\( a \\) satisfying \\( ax = yz \\).\n  Let \\( y = u p_1 \\cdots p_n \\) and \\( z = v q_1 \\cdots q_m \\) be irreducible factorizations. Then\n  \\begin{equation*}\n    ax = (uv) p_1 \\cdots p_n q_1 \\cdots q_m.\n  \\end{equation*}\n\n  The factorizations are equivalent, hence \\( x \\) must divide one of the other irreducible elements. If \\( x \\mid p_k \\) for some \\( k = 1, \\ldots, n \\), then \\( x \\mid y \\). If \\( x \\mid q_k \\) for some \\( k = 1, \\ldots, m \\), then \\( x \\mid z \\).\n\n  \\SubProof*{Proof of ascending chain condition} Suppose that every element has a unique factorization.\n\n  Fix an ascending sequence of principal ideals\n  \\begin{equation*}\n    \\braket{ x_1 } \\subseteq \\braket{ x_2 } \\subseteq \\braket{ x_3 } \\cdots.\n  \\end{equation*}\n\n  By \\fullref{thm:def:semiring_ideal/division}, this implies that \\( x_{k+1} \\) divides \\( x_k \\) for \\( k = 1, 2, \\ldots \\).\n\n  Let \\( x_1 = y x_2 \\) and fix \\hyperref[def:irreducible_factorization]{irreducible factorizations}\n  \\begin{align*}\n    x_1 &= u p_1 \\cdots p_n \\\\\n    x_2 &= v q_1 \\cdots q_m \\\\\n    y   &= w r_1 \\cdots r_k.\n  \\end{align*}\n\n  Since the factorizations are unique, we have \\( n = m + k \\). If \\( k = 0 \\), then \\( x_1 \\) and \\( x_2 \\) are associated and \\( \\braket{ x_1 } = \\braket{ x_2 } \\). If \\( k > 0 \\), then \\( \\braket{ x_1 } \\subsetneq \\braket{ x_2 } \\), and \\( x_2 \\) has a strictly shorter irreducible factorization.\n\n  Proceeding by induction on the length of the factorization, we conclude that there are at most \\( n \\) strict inclusions in the sequence of ideals.\n\n  \\ImplicationSubProof{def:unique_factorization_domain/primes_and_ideals}{def:unique_factorization_domain/factorization} Follows from \\fullref{thm:def:irreducible_factorization/existence} and \\fullref{thm:def:irreducible_factorization/uniqueness}.\n\\end{defproof}\n\n\\begin{proposition}\\label{thm:def:unique_factorization_domain}\n  \\hyperref[def:unique_factorization_domain]{Unique factorization domains} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:unique_factorization_domain/polynomial_ring} If the \\hyperref[def:polynomial_algebra]{polynomial ring} \\( R[X] \\) over a commutative ring \\( R \\) is a unique factorization domain, then \\( R \\) also is.\n\n    The converse to this is true, but it is more difficult to prove. See \\fullref{thm:polynomial_ring_over_ufd}.\n\n    \\thmitem{thm:def:unique_factorization_domain/gcd} Every unique factorization domain is a \\hyperref[def:gcd_domain]{GCD domain}.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:unique_factorization_domain/polynomial_ring} Suppose that \\( D[X] \\) is a unique factorization. By \\fullref{thm:def:irreducible_factorization/polynomial_ring}, every irreducible factorization of \\( x \\in D \\) in \\( D[X] \\) is also an irreducible factorization in \\( D[X] \\). This implies both existence and uniqueness.\n\n  \\SubProofOf{thm:def:unique_factorization_domain/gcd} Fix arbitrary elements \\( x \\) and \\( y \\). We will show that they have a greatest common divisor.\n\n  Suppose that we have the decompositions\n  \\begin{align*}\n    x &= u p_1 \\cdots p_n \\\\\n    y &= v q_1 \\cdots q_m.\n  \\end{align*}\n\n  Otherwise, let \\( r_1, \\ldots, r_k \\) be a well-ordering on the set \\( \\set{ p_1, \\ldots, p_n, q_1, \\ldots, q_m } \\). For every \\( i = 1, \\ldots, k \\), let \\( s_i \\) be the minimum of the number of elements from \\( p_1, \\ldots, p_n \\) associated with \\( r_i \\) and the number of elements of \\( q_1, \\ldots, q_m \\) associated with \\( r_i \\). Finally, define\n  \\begin{equation*}\n    r \\coloneqq r_1^{s_1} \\cdots r_k^{s_k}.\n  \\end{equation*}\n\n  We can use nested induction on \\( k \\) and \\( s_k \\) to show that \\( r \\) is, up to a unit, the greatest common divisor of \\( x \\) and \\( y \\). Indeed, \\( k = 0 \\) implies that \\( x \\) and \\( y \\) have no common divisors. For the inductive step, note that dividing both \\( x \\) and \\( y \\) by \\( r_k^{s_k} \\) allows us to use the inductive hypothesis with \\( r_1^{s_1} \\cdots r_{k-1}^{s_{k-1}} \\), and that multiplying back by \\( r_k^{s_k} \\) makes \\( r \\) the GCD of \\( x \\) and \\( y \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:principal_ideal_domain}\n  We say that an \\hyperref[def:integral_domain]{integral domain} is a \\term{principal ideal domain} if every \\hyperref[def:semiring_ideal]{ideal} is \\hyperref[def:semiring_ideal/principal]{principal}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:principal_ideal_domain}\n  \\hyperref[def:principal_ideal_domain]{Principal ideal domains} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:principal_ideal_domain/noetherian} Every principal ideal domain is \\hyperref[def:noetherian_semiring]{noetherian}.\n\n    \\thmitem{thm:def:principal_ideal_domain/ufd} Every principal ideal domain is a \\hyperref[def:unique_factorization_domain]{unique factorization domain}.\n\n    \\Fullref{ex:ufd_but_not_pid} demonstrates that the converse is not true.\n\n    \\thmitem{thm:def:principal_ideal_domain/prime_ideal_is_maximal} \\hyperref[def:semiring_ideal/prime]{Prime ideals} in a principal ideal domains are \\hyperref[def:semiring_ideal/maximal]{maximal}.\n\n    \\thmitem{thm:def:principal_ideal_domain/gcd} For the \\hyperref[def:gcd_and_lcm]{greatest common divisor}, we have\n    \\begin{equation*}\n      \\braket{ \\gcd(x, y) } = \\braket{ x } + \\braket{ y } = \\braket{ x, y }\n    \\end{equation*}\n    and for the \\hyperref[def:gcd_and_lcm]{least common multiple},\n    \\begin{equation*}\n      \\braket{ \\lcm(x, y) } = \\braket{ x } \\cap \\braket{ y }.\n    \\end{equation*}\n\n    \\thmitem{thm:def:principal_ideal_domain/coprime} \\( x \\) and \\( y \\) are \\hyperref[def:coprime_elements]{coprime elements} if and only if \\( \\braket{ x } \\) and \\( \\braket{ y } \\) are \\hyperref[def:coprime ideal]{coprime ideals}.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:principal_ideal_domain/noetherian} In a principal ideal domain every ideal is generated by a single element, hence the domain satisfies \\fullref{def:noetherian_semiring/generated}. Thus, it is noetherian.\n\n  \\SubProofOf{thm:def:principal_ideal_domain/ufd} Suppose that \\( x \\) is an irreducible element of a principal ideal domain. Then \\( x \\) satisfies \\fullref{def:domain_divisibility/irreducible/ideals}, and hence \\( \\braket{ x } \\) is a maximal ideal. By \\fullref{thm:def:semiring_ideal/maximal_is_prime}, maximal ideals are prime, and hence \\( x \\) is a prime element.\n\n  Therefore, every irreducible element is prime. Combined with \\fullref{thm:def:principal_ideal_domain/noetherian}, this implies that the domain satisfies \\fullref{def:unique_factorization_domain/primes_and_ideals}, and is hence a unique factorization domain.\n\n  \\SubProofOf{thm:def:principal_ideal_domain/prime_ideal_is_maximal} Let \\( P \\) be a prime ideal in a principal ideal domain. Then \\( P = \\braket{ p } \\) for some prime element \\( p \\). By \\fullref{thm:def:domain_divisibility/prime_is_irreducible}, \\( p \\) is irreducible, and hence \\( \\braket{ p } \\) is a maximal ideal.\n\n  \\SubProofOf{thm:def:principal_ideal_domain/gcd} Follows from \\fullref{thm:semiring_of_ideals/lattice} by nothing that every ideal is principal.\n\n  \\SubProofOf{thm:def:principal_ideal_domain/coprime} Follows from \\fullref{thm:def:principal_ideal_domain/gcd}.\n\\end{proof}\n\n\\begin{theorem}[Bezout's identity]\\label{thm:bezouts_identity}\n  In a \\hyperref[def:principal_ideal_domain]{principal ideal domain}, for every pair of elements \\( x \\) and \\( y \\), there exist some elements \\( a \\) and \\( b \\) such that\n  \\begin{equation}\\label{eq:thm:bezouts_identity}\n    ax + by = \\gcd(x, y).\n  \\end{equation}\n\n  \\Fullref{alg:extended_euclidean_algorithm} gives us an explicit construction for \\( a \\) and \\( b \\).\n\n  The converse, \\fullref{thm:bezouts_identity_converse}, holds more generally.\n\\end{theorem}\n\\begin{proof}\n  Clearly \\( \\ifrac x {\\gcd(x, y)} \\) and \\( \\ifrac y {\\gcd(x, y)} \\) are \\hyperref[def:coprime_elements]{coprime elements}. By \\fullref{thm:def:principal_ideal_domain/coprime}, there exist elements \\( a \\) and \\( b \\) such that\n  \\begin{equation*}\n    a \\frac x {\\gcd(x, y)} + b \\frac y {\\gcd(x, y)} = 1.\n  \\end{equation*}\n\n  Multiplying by \\( \\gcd(x, y) \\), we obtain \\eqref{eq:thm:bezouts_identity}.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:multiplicative_group_of_integers_modulo}\n  The \\hyperref[def:semiring]{multiplicative group} \\( \\BbbZ_n^\\times \\) of the ring \\hyperref[thm:ring_of_integers_modulo]{\\( \\BbbZ_n \\)} of integers modulo \\( n > 1 \\) is the set of all positive integers \\hyperref[def:coprime_elements]{coprime} to \\( n \\).\n\n  In particular, \\( \\BbbZ_p \\) is a \\hyperref[def:field]{field} if and only if \\( p \\) is a \\hyperref[def:prime_number]{prime number}.\n\\end{corollary}\n\\begin{proof}\n  Note that \\( x < n \\) is invertible modulo \\( n \\) if and only if there exists an integer \\( a \\) such that \\( ax = 1 \\pmod n \\). That is, if there exist integers \\( a \\) and \\( b \\) such that \\( ax + bn = 1 \\).\n\n  The rest of the theorem follows from \\fullref{thm:bezouts_identity} in one direction and \\fullref{thm:bezouts_identity_converse} in the other direction.\n\\end{proof}\n\n\\begin{example}\\label{ex:ufd_but_not_pid}\\mcite{ProofWiki:polynomials_in_integers_is_not_principal_ideal_domain}\n  The \\hyperref[def:unique_factorization_domain]{unique factorization domain} \\( \\BbbZ[X] \\) is not a \\hyperref[def:principal_ideal_domain]{principal ideal domain}.\n\n  Note that \\( \\BbbZ[X] \\) is a unique factorization domain by \\fullref{thm:def:unique_factorization_domain/polynomial_ring}.\n\n  Consider the ideal \\( I \\) of polynomials with an even constant term. Assume that \\( I \\) is generated by the polynomial \\( p(X) \\in \\BbbZ[X] \\). Since \\( 2 \\in I \\), then \\( p(X) \\) divides \\( 2 \\), so \\( p(X) \\in \\set{ -2, -1, 1, 2 } \\). But then \\( p(X) \\) is a unit, and hence, \\( I = \\braket{p(X)} = \\BbbZ[X] \\), which contradicts the definition of \\( I \\).\n\n  The obtained contradiction proves that \\( \\BbbZ[X] \\) is not a principal ideal domain.\n\\end{example}\n\n\\begin{definition}\\label{def:euclidean_domain}\\mcite{nLab:euclidean_domain}\n  An \\term{Euclidean domain} is an \\hyperref[def:integral_domain]{integral domain} \\( D \\) endowed with a function \\( \\delta: D \\to \\BbbZ_{\\geq 0} \\), which we call the \\term{Euclidean degree}, such that for every pair \\( x \\) and \\( y \\) of elements of \\( D \\) with \\( y \\neq 0_D \\), there exists a pair \\( q \\) and \\( r \\) such that\n  \\begin{equation}\\label{eq:def:euclidean_domain/division}\n    x = yq + r\n  \\end{equation}\n  holds and either \\( r = 0_D \\) or \\( \\delta(r) < \\delta(q) \\).\n\n  We say that \\( y \\) \\term{divides} \\( x \\) with \\term{quotient} \\( q \\) and \\term{remainder} \\( r \\).\n\n  If the quotient and remainder are unique, as they usually are, we use the special notation\n  \\begin{align*}\n    \\quot(x, y) \\coloneqq q, \\\\\n    \\rem(x, y) \\coloneqq r = x - y \\quot(x, y).\n  \\end{align*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:euclidean_domain}\n  \\hyperref[def:euclidean_domain]{Euclidean domains} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:euclidean_domain/pid} Every Euclidean domain is a \\hyperref[def:principal_ideal_domain]{principal ideal domain}.\n\n    Counterexamples to the converse are discussed in \\cite{Anderson1988}.\n\n    \\thmitem{thm:def:euclidean_domain/field} Every field is a \\hyperref[def:euclidean_domain]{Euclidean domain}.\n\n    \\thmitem{thm:def:euclidean_domain/field_polynomials} A commutative ring \\( R \\) is a field if and only if its \\hyperref[def:polynomial_algebra]{polynomial ring} \\( R[X] \\) is a \\hyperref[def:principal_ideal_domain]{principal ideal domain}.\n\n    Furthermore, if \\( R \\) is a field, the \\hyperref[def:polynomial_degree]{polynomial degree} function \\( \\deg: R[X] \\setminus \\set{ 0 } \\to \\BbbZ_{\\geq 0} \\) makes \\( R \\) an \\hyperref[def:euclidean_domain]{Euclidean domain}.\n\n    We are free to define \\( \\deg \\) to take any value for the zero polynomial.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:euclidean_domain/pid} Fix an ideal \\( I \\) of the Euclidean domain \\( D \\). By \\fullref{thm:natural_numbers_are_well_ordered}, the set \\( \\delta(I) \\) has a minimum. Choose an element \\( m \\in I \\) such that \\( \\delta(m) = \\min \\delta(I) \\). Obviously \\( \\braket{m} \\subseteq I \\). We will prove that \\( I \\subseteq m \\).\n\n  Let \\( x \\in I \\). We divide it by \\( m \\) to obtain\n  \\begin{equation*}\n    x = mq + r,\n  \\end{equation*}\n  such that either \\( r \\) is zero or \\( \\delta(r) < \\delta(m) \\). Since both \\( x \\) and \\( m \\) are in \\( I \\), we have \\( r = mq - x \\in I \\). But \\( m \\) minimizes \\( \\delta \\) over \\( I \\), thus \\( \\delta(m) \\leq \\delta(r) \\), which contradicts \\( \\delta(r) < \\delta(m) \\).\n\n  Therefore, \\( r \\) is zero and\n  \\begin{equation*}\n    x = mq,\n  \\end{equation*}\n  which implies that \\( x \\in \\braket m \\). This proves \\( I \\subseteq \\braket m \\).\n\n  We have now obtained \\( \\braket m = I \\). Since \\( I \\) was an arbitrary ideal, we conclude that every ideal in the domain is principal.\n\n  \\SubProofOf{thm:def:euclidean_domain/field} By \\fullref{thm:division_ring_is_entire}, a field is necessarily an integral domain. Since every element of \\( \\BbbK \\) is divisible (without remainder), the Euclidean function can be arbitrary; for definiteness, we take it to be canonically zero.\n\n  \\SubProofOf{thm:def:euclidean_domain/field_polynomials}\n  \\SufficiencySubProof* Suppose that \\( R[X] \\) is a principal ideal domain.\n\n  By \\fullref{thm:def:integral_domain/subring}, \\( R \\) is an integral domain. By \\fullref{thm:quotient_algebra_universal_property}, \\( R[X] / \\braket{ X } \\cong R \\). By \\fullref{thm:quotient_by_prime_ideal}, \\( \\braket{ X } \\) is a prime ideal in \\( R[X] \\). By \\fullref{thm:def:principal_ideal_domain/prime_ideal_is_maximal}, \\( \\braket{ X } \\) is a maximal ideal. By \\fullref{thm:quotient_by_maximal_ideal}, \\( R[X] / \\braket{ X } \\cong R \\) is a field.\n\n  \\NecessitySubProof* Suppose that \\( R \\) is a field. By \\fullref{thm:def:integral_domain/polynomial_ring}, \\( R[X] \\) is a domain. By \\fullref{alg:euclidean_division_of_polynomials}, we can divide two polynomials \\( f(X) \\) and \\( g(X) \\), where \\( g(X) \\) is monic, in a way that satisfies the definition of an Euclidean domain.\n\n  Thus, for any \\( f(X) \\) and a nonzero \\( g(X) \\) with leading coefficients \\( b_m \\), \\fullref{alg:euclidean_division_of_polynomials} gives us\n  \\begin{equation*}\n    f(X) = \\frac {g(X)} {b_m} q(X) + r(X).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{algorithm}[Euclidean algorithm]\\label{alg:euclidean_algorithm}\n  In an \\hyperref[def:euclidean_domain]{Euclidean domain}, we can explicitly construct the \\hyperref[def:gcd_and_lcm]{greatest common divisor} of arbitrary elements \\( x \\) and \\( y \\) as follows:\n  \\begin{thmenum}\n    \\thmitem{alg:euclidean_algorithm/guard} If \\( y \\) is zero, halt the algorithm with \\( \\gcd(x, y) \\coloneqq x \\).\n    \\thmitem{alg:euclidean_algorithm/initialization} Define \\( r_{-1} \\coloneqq x \\) and \\( r_0 \\coloneqq y \\).\n    \\thmitem{alg:euclidean_algorithm/step} Starting with \\( k = 1 \\), obtain a quotient \\( q_k \\) and remainder \\( r_k \\) so that\n    \\begin{equation*}\n      r_{k-2} = r_{k-1} q_k + r_k.\n    \\end{equation*}\n\n    If \\( r_k \\) is not zero, repeat \\fullref{alg:euclidean_algorithm/step} with \\( k + 1 \\).\n\n    Otherwise, halt the algorithm with \\( \\gcd(x, y) \\coloneqq r_{k-1} \\).\n  \\end{thmenum}\n\\end{algorithm}\n\\begin{defproof}\n  If \\( y \\) is zero, then \\( \\braket{ x, y } = \\braket{ x } \\), and hence the result is consistent with \\fullref{def:gcd_and_lcm}.\n\n  Otherwise, Euclidean division ensures that \\( \\delta(r_k) < \\delta(r_{k-1}) \\) on the \\( k \\)-th step. Thus, the algorithm halts. Denote by \\( n \\) the last step where \\( r_n \\) is not zero.\n\n  We show by induction on \\( k < n \\) that \\( r_n \\) divides \\( r_{n-k} \\). The base case \\( k = 0 \\) is obvious since \\( r_n \\) divides itself.\n\n  Assume that \\( r_n \\) divides \\( r_{n-i} \\) for \\( 0 \\leq i < k \\). Now, since\n  \\begin{equation*}\n    r_{n-k} = r_{n-(k-1)} q_{n-(k-2)} + r_{n-(k-2)}\n  \\end{equation*}\n  and both of the terms on the right-hand side are multiples of \\( r_n \\), the left-hand side \\( r_{n-k} \\) is also a multiple.\n\n  So, we conclude that \\( r_n \\) divides both \\( r_{n-(n-1)} = r_1 = y \\) and \\( r_{n-n} = r_0 = x \\).\n\n  Finally, we must show that \\( r_n \\) is the greatest among all common divisors of \\( x \\) and \\( y \\). Let \\( d \\) be a common divisor. Then \\( d \\mid r_0 \\) and \\( d \\mid r_1 \\). Suppose that \\( d \\mid r_{k-1} \\) and \\( d \\mid r_{k-2} \\), for some \\( k < n \\). Then\n  \\begin{equation*}\n    r_{k-2} = r_{k-1} q_k + r_k,\n  \\end{equation*}\n  implying that \\( d \\) also divides \\( r_k \\). Hence, we obtain \\( d \\mid r_n \\). Since our choice of common divisor \\( d \\) was arbitrary, we conclude that \\( r_n \\) is the greatest common divisor.\n\\end{defproof}\n\n\\begin{algorithm}[Extended Euclidean algorithm]\\label{alg:extended_euclidean_algorithm}\n  In an \\hyperref[euclidean_domain]{Euclidean domain}, for \\( x \\) and \\( y \\) we can explicitly construct elements \\( a \\) and \\( b \\) so that \\fullref{thm:bezouts_identity} holds, i.e.\n  \\begin{equation*}\n    ax + by = \\gcd(x, y).\n  \\end{equation*}\n\n  \\begin{thmenum}\n    \\thmitem{alg:extended_euclidean_algorithm/guard} If \\( y \\) is zero, then halt the algorithm with \\( a = 1 \\), \\( b = 0 \\).\n\n    \\thmitem{alg:extended_euclidean_algorithm/algorithm} Let \\( r_{-1}, r_0, r_1, \\ldots, r_n \\) and \\( q_1, q_2, \\ldots, q_n \\) be the sequences of quotients and remainders from \\fullref{alg:euclidean_algorithm}. The \\term{extended Euclidean algorithm} proceeds as follows:\n\n    Define\n    \\begin{equation*}\n      a_k \\coloneqq \\begin{cases}\n        1,                     &k = 1, \\\\\n        a_{k-2} - a_{k-1} q_k, &k > 1,\n      \\end{cases}\n    \\end{equation*}\n    and\n    \\begin{equation*}\n      b_k \\coloneqq \\begin{cases}\n        -q_1,                  &k = 1, \\\\\n        b_{k-2} - b_{k-1} q_k, &k > 1.\n      \\end{cases}\n    \\end{equation*}\n\n    Halt the algorithm with \\( a \\coloneqq a_n \\) and \\( b \\coloneqq b_n \\).\n  \\end{thmenum}\n\\end{algorithm}\n\\begin{defproof}\n  Suppose that \\( y \\) is not zero. We will prove with induction on \\( k < n \\) that\n  \\begin{equation*}\n    r_k = a x_k + b y_k.\n  \\end{equation*}\n\n  For the base case \\( k = 1 \\), we have\n  \\begin{align*}\n    r_{-1}    &= r_0 q_1 + r_1, \\\\\n    x         &= y q_1 + r_1,   \\\\\n    x - y q_1 &= r_1,\n  \\end{align*}\n  hence \\( r_1 = x + (-q_1) y = a_1 x + b_1 y \\).\n\n  For \\( k > 1 \\), we have\n  \\begin{align*}\n    r_{k-2}                                               &= r_{k-1} q_k + r_k,                 \\\\\n    x a_{k-2} + y b_{k-2}                                 &= (x a_{k-1} + y b_{k-1}) q_k + r_k, \\\\\n    x (a_{k-2} - a_{k-1} q_k) + y (b_{k-2} - b_{k-1} q_k) &= r_k.\n  \\end{align*}\n\n  This completes the induction.\n\n  Finally, since \\( r_n = \\gcd(x, y) \\), we conclude that\n  \\begin{equation*}\n    \\gcd(x, y) = a_n x + b_n y.\n  \\end{equation*}\n\\end{defproof}\n\n\\begin{proposition}\\label{thm:polynomial_ring_over_gcd_domain}\n  If the \\hyperref[def:integral_domain]{integral domain} \\( D \\) is a \\hyperref[def:greatest_factorization_domain]{greatest common divisor domain}, so is \\( D[X] \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( D \\) be a GCD domain and let \\( \\BbbK \\) be its \\hyperref[thm:field_of_fractions]{field of fractions}.\n\n  Let \\( p(X) \\) and \\( q(X) \\) be arbitrary polynomials in \\( D[X] \\). We will show that they have a greatest common divisor.\n\n  By \\fullref{thm:def:euclidean_domain/field_polynomials}, \\( \\BbbK[X] \\) is an Euclidean domain, and thus \\( p(X) \\) and \\( q(X) \\) have a GCD in \\( \\BbbK[X] \\), which is unique up to multiplication by a unit in \\( \\BbbK[X] \\). Thus, taking an arbitrary GCD\n  \\begin{equation*}\n    r(X) = \\sum_{k=0}^n \\frac {a_k} {b_k} X^k,\n  \\end{equation*}\n  the polynomial \\( b_0 \\cdots b_n r(X) \\) is also a GCD. Furthermore, the latter is actually a polynomial in \\( D[X] \\).\n\n  Therefore, \\( p(X) \\) and \\( q(X) \\) have a GCD in \\( D[X] \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:polynomial_content}\\mcite[def. V.4.6]{Aluffi2009}\n  The \\term{content} of a univariate polynomial over a \\hyperref[def:gcd_domain]{GCD domain} is the \\hyperref[def:gcd_and_lcm]{GCD} of its coefficients.\n\n  Dividing \\( p(X) \\) by its content, we obtain another polynomial, which we call the \\term{primitive part} of \\( p(X) \\). Polynomials whose content is a unit are called \\term{primitive} in the context of \\fullref{thm:gauss_lemma}, although this clashes with the unrelated concept of primitive polynomials in \\hyperref[thm:finite_fields]{finite fields}.\n\\end{definition}\n\n\\begin{lemma}[Gauss' lemma]\\label{thm:gauss_lemma}\n  If \\( p(X) \\) and \\( q(X) \\) are \\hyperref[def:polynomial_content]{primitive polynomials}, then \\( p(X) q(X) \\) is also primitive.\n\\end{lemma}\n\\begin{proof}\n  Fix two primitive polynomials\n  \\begin{align*}\n    p(X) = \\sum_{k=0}^n a_k X^k,\n    &&\n    q(X) = \\sum_{k=0}^m b_k X^k.\n  \\end{align*}\n\n  Let \\( d \\) be the content of \\( p(X) q(X) \\). It divides every coefficient\n  \\begin{equation*}\n    \\sum_{i+j=k} a_i b_j\n  \\end{equation*}\n  of \\( p(X) q(X) \\), and hence also \\( a_i b_j \\) for every particular pair of indices \\( i < n \\) and \\( j < m \\).\n\n  For any fixed \\( i < n \\), \\( d \\) divides \\( a_i b_j \\) for every \\( j < m \\). Since \\( q(X) \\) is primitive, \\( d \\) cannot divide \\( b_j \\) for every \\( j < m \\) unless \\( d \\) is a unit. Hence, \\( d \\) necessarily divides \\( a_i \\). Our choice of \\( i \\) was arbitrary, hence \\( d \\) divides \\( a_i \\) for every \\( i < n \\). But \\( p(X) \\) is also primitive. Therefore, \\( d \\) can only be a unit.\n\\end{proof}\n\n\\begin{lemma}\\label{thm:irreducible_primitive_polynomial_in_field_of_fractions}\n  Let \\( D \\) be a \\hyperref[def:gcd_domain]{GCD domain} and let \\( \\BbbK \\) be its \\hyperref[thm:field_of_fractions]{field of fractions}. If a \\hyperref[def:polynomial_content]{primitive polynomial} \\( p(X) \\) is \\hyperref[def:domain_divisibility/irreducible]{irreducible} in the polynomial ring \\( \\BbbK[X] \\), then it is irreducible in \\( D[X] \\).\n\\end{lemma}\n\\begin{proof}\n  Suppose that \\( p(X) \\) is primitive and irreducible in \\( \\BbbK[X] \\). Let\n  \\begin{equation*}\n    p(X) = q(X) r(X),\n  \\end{equation*}\n  where \\( q(X) \\) and \\( r(X) \\) are polynomials from \\( D[X] \\). Then \\( q(X) \\) or \\( r(X) \\) is a unit in \\( \\BbbK[X] \\), hence it is a nonzero constant polynomial. Suppose that \\( q(X) = q_0 \\).\n\n  Then \\( q_0 \\) is an element of \\( D \\) that divides all coefficients of \\( p(X) \\). By assumption, the coefficients of \\( p(X) \\) are coprime. It follows that \\( q_0 \\) is a unit in \\( D \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:polynomial_ring_over_ufd}\n  If the \\hyperref[def:integral_domain]{integral domain} \\( D \\) is a \\hyperref[def:unique_factorization_domain]{unique factorization domain}, so is \\( D[X] \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( D \\) be a unique factorization domain and let \\( \\BbbK \\) be its \\hyperref[thm:field_of_fractions]{field of fractions}.\n\n  By \\fullref{thm:polynomial_ring_over_gcd_domain}, \\( D[X] \\) is a GCD domain. Then \\fullref{thm:def:gcd_domain/irreducible_is_prime} is satisfied, with by \\fullref{thm:def:irreducible_factorization/uniqueness} implies that if an element has at least one \\hyperref[def:irreducible_factorizaion]{irreducible factorization}, all others are equivalent to it.\n\n  We will now show existence of irreducible factorizations.\n\n  Let \\( p(X) \\) be a polynomial in \\( D[X] \\). By \\fullref{thm:def:euclidean_domain/field_polynomials}, \\( p(X) \\) has an irreducible factorization\n  \\begin{equation*}\n    p(X) = u q_1(X) \\cdots q_n(X),\n  \\end{equation*}\n  where \\( q_1(X), \\ldots, q_n(X) \\) belong to \\( \\BbbK[X] \\).\n\n  For a fixed index \\( i = 1, \\ldots, n \\), if the polynomial \\( q_i(X) \\) has the form\n  \\begin{equation*}\n    q_i(X) = \\sum_{k=0}^n \\frac {a_k} {b_k} X^k,\n  \\end{equation*}\n  then \\( b_1 \\cdots b_n q_i(X) \\) is a polynomial in \\( D[X] \\). Denote by \\( r_i(X) \\) the \\hyperref[def:polynomial_content]{primitive part} this polynomial in \\( D[X] \\). Since every scalar from \\( D \\) is simply a unit in \\( \\BbbK[X] \\), it follows that \\( r_i(X) \\) is also irreducible in \\( \\BbbK[X] \\).\n\n  Hence, for the appropriate scalar \\( v \\in \\BbbK \\),\n  \\begin{equation*}\n    p(X) = v r_1(X) \\cdots r_n(X)\n  \\end{equation*}\n  is an irreducible factorization in \\( \\BbbK[X] \\).\n\n  By \\fullref{thm:irreducible_primitive_polynomial_in_field_of_fractions}, \\( r_1(X), \\ldots, r_n(X) \\) are irreducible elements of \\( D[X] \\). Thus, if \\( v = \\tfrac c d \\) with \\( c \\) and \\( d \\) coprime, then\n  \\begin{equation*}\n    d p(X) = c r_1(X) \\cdots r_n(X)\n  \\end{equation*}\n  is an irreducible factorization in \\( D[X] \\).\n\n  By \\fullref{thm:gauss_lemma}, the product \\( r_1(X) \\cdots r_n(X) \\) is a primitive polynomial in \\( D[X] \\). Hence, \\( d \\) cannot divide neither \\( c \\) nor \\( r_1(X) \\cdots r_n(X) \\), implying that \\( d \\) is a unit. Therefore,\n  \\begin{equation*}\n    p(X) = c r_1(X) \\cdots r_n(X)\n  \\end{equation*}\n  is an irreducible factorization of \\( p(X) \\) in \\( D[X] \\).\n\\end{proof}\n", "meta": {"hexsha": "38d877cd979a3c034e6da3eddda0b5654d500d92", "size": 54014, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/integral_domains.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/integral_domains.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/integral_domains.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.8758085382, "max_line_length": 499, "alphanum_fraction": 0.687618025, "num_tokens": 17180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7045740790599879}}
{"text": "\n\\section{Dynamic Programming}\n\nThe term Dynamic Programming (DP) refers to a collection of algorithms that can be used to compute optimal policies given perfect model of the environment as a Markov Decision Process (MDP). DP methods tend to be computationally expensive and we often don't have a perfect model of the environment, so they aren't used in practice. However, they provide useful theoretical basis for the rest of reinforcement learning. \\\\\n\nUnless stated otherwise, will assume that the environment is a finite MDP. If the state or action space is continuous, then we will generally discretise it and apply finite MDP methods to the approximated problem.\\\\\n\nThe key idea of DP, and of reinforcement learning generally, is the use of value functions to organize and structure the search for good policies. We use DP and the Bellman equations to find optimal value functions. \n\n\\subsection{Policy Evaluation (Prediction)}\nWe can use the Bellman equation for the state-value function $v_\\pi$ to construct an iterative updating procedure.\n\n\\subsubsection*{Iterative Policy Evaluation}\nConsider a sequence of approximate value functions $v_0, v_1, v_2, \\dots$ each mapping $\\mathcal{S}^{+}$ to $\\mathbb{R}$. The initial approximation, $v_0$, is chosen arbitrarily (except that the terminal state, if any, must be given value $0$), and each successive approximation is obtained by using the Bellman equation for $v_\\pi$ as an update rule:\n\n\\begin{align}\n    v_{k+1} &\\doteq \\Epi [R_{t+1} + \\gamma v_{k}(S_{t+1}) | S_t = s] \\\\\n            &= \\sum_a \\pi(s|a) \\sum_{s', r} p(s', r| s, a) \\left[r + \\gamma v_k(s')\\right]\n\\end{align}\n\nClearly, $v_k = v_\\pi$ is a fixed point. The sequence $\\{v_k\\}$ can be shown in general to converge to $v_\\pi$ as $k \\to \\infty$ under the same conditions that guarantee the existence of $v_\\pi$. This algorithm is called \\emph{iterative policy evaluation}. This update rule is an instance of an \\emph{expected update} because it performs the updates by taking an expectation over all possible next states rather than by taking a sample next state.\\\\\n\n\\subsection{Policy Improvement}\n\\subsubsection*{Policy Improvement Theorem}\n\nLet $\\pi$, $\\pi'$ be any pair of deterministic policies, such that\n\\begin{equation}\n    q_\\pi(s, \\pi'(s)) \\geq v_\\pi(s) \\quad \\forall s \\in \\mathcal{S}.\n\\end{equation}\nThat is, $\\pi'$ is as least as good as $\\pi$. Then we have (shown below)\n\\begin{equation}\n    v_{\\pi'}(s) \\geq v_\\pi(s) \\quad \\forall s \\in \\mathcal{S}\n\\end{equation}\nso $\\pi'$ gives at least as good (expected) return as $\\pi$.\\\\\n\nThe argument below also shows that if $q_\\pi(s, \\pi'(s)) > v_\\pi(s)$ at any $s$, then there is at least one $s$ for which $v_{\\pi'}(s) > v_\\pi(s)$.\n\\subsubsection*{proof:}\n\\begin{align*}\n    v_\\pi(s) & \\leq q_\\pi(s, \\pi'(s)) \\\\\n             & = \\E{}[R_{t+1} + \\gamma v_\\pi(S_{t+1}) | S_t=s, A_t=\\pi'(s)] \\\\\n             & = \\E{}_{\\pi'} [R_{t+1} + \\gamma v_\\pi(S_{t+1}) | S_t=s] \\\\\n             & \\leq \\E{}_{\\pi'} [R_{t+1} + \\gamma R_{t+2} + \\gamma^2 R_{t+3} + \\dots| S_t=s] \\\\\n             & = v_{\\pi'}(s)\n\\end{align*}\n\n\\subsubsection*{Policy Improvement Algorithm}\nNow consider a policy that is greedy with respect to $q_\\pi(s, a)$. Define \n\\begin{align}\n    \\pi'(s) &= \\argmax_a q_\\pi(s, a) \\\\ \n            &= \\argmax_a \\E{} [R_{t+1} + \\gamma v_\\pi(S_{t+1}) | S_t=s, A_t=a] \\\\\n            &= \\argmax_a \\sum_{s', r} p(s', r|s, a)[ r + \\gamma v_\\pi(s')].\n\\end{align}\nNow we can use $v_\\pi$ to get $\\pi' \\geq \\pi$, then use $v_{\\pi'}$ to get \\emph{another} policy. (In the above, ties are broken arbitrarily when the policy is deterministic. If the policy is stochastic, we accept any policy that assigns zero probability to sub-optimal actions.)\\\\\n\nNote that by construction\n\\[\n    q_\\pi(s, \\pi'(s)) \\geq v_\\pi(s)\n\\]\ntherefore\n\\[\n    v_{\\pi'} \\geq v_\\pi\n\\]\nso we get from this process a monotonically increasing sequence of policies.\\\\\n\nNote also that if $\\pi'$ is as good as $\\pi$ then $v_{\\pi'} = v_\\pi$ and $\\forall s \\in \\mathcal{S}$\n\\begin{align*}\n    v_\\pi &= \\max_a \\E{}[R_{t+1} + \\gamma v_{\\pi'(S_{t+1})}| S_t=s, A_t=a]\\\\\n          &= \\max_a \\sum_{s', r} p(s', r|s, a)(r + \\gamma v_{\\pi'}(s'))\n\\end{align*}\nwhich is the Bellman optimality condition for $v_*$, so both $\\pi$ and $\\pi'$ are optimal. This means that policy improvement gives a strictly better policy unless the policy is already optimal. \\\\\n\nThe policy improvement theorem holds for stochastic policies too, but we don't go into that here.\n          \n\n\\subsection{Policy Iteration}\nWe can exploit policy improvement iteratively to get the policy iteration algorithm.\n\n\\includegraphics[width=\\textwidth]{\\ProjectDir/data/notes_images/policy_iteration_algorithm.png}\n\\mbox{}\\\\\nA finite MDP has only a finite number of policies (as long as they are deterministic, of course) so this process is guaranteed to converge.\n\n\\subsection{Value Iteration}\nPolicy iteration can be slow because each iteration involves running the entire policy evaluation until convergence. \\\\\n\nIt turns out that one can truncate the policy evaluation step of policy iteration in many ways without losing convergence guarantees. One special case of this is \\emph{value iteration}, where we truncate policy evaluation after only one update of each state. This algorithm converges to $v_*$ under the same conditions that guarantee the existence of $v_*$. \n\n\\includegraphics[width=\\textwidth]{\\ProjectDir/data/notes_images/value_iteration_algorithm.png}\n\\mbox{}\\\\\n\nNote the $\\max_a$ in the assignment of $V(s)$, since we only one sweep of the state space and then choose the greedy policy.\\\\\n\nIt may be more efficient to interpose multiple policy evaluation steps in between policy improvement iterations, all of these algorithms converge to an optimal policy for discounted finite MDPs. \n\n\\subsection{Asynchronous Dynamic Programming}\nThe DP methods that we have described so far all involve a full sweep of the state space on each iteration. This is potentially a very costly procedure. \\\\\n\n\\emph{Asynchronous} DP algorithms update the values in-place and cover states in any order whatsoever. The values of some states may be updated several times before the values of others are updated once. To converge correctly, however, an asynchronous algorithm must continue to update the values of all the states: it can’t ignore any state after some point in the computation.\\\\\n\nAsynchronous DPs give a great increase in flexibility, meaning that we can choose the updates we want to make (even stochastically) based on the interaction of the agent with the environment. This procedure might not reduce computation time in total if the algorithm is run to convergence, but it could allow for a better rate of progress for the agent.\n\n\\subsection{Generalised Policy Iteration}\nWe use the term \\emph{generalised policy iteration} (GPI) to refer to the general idea of letting policy evaluation and policy improvement processes interact, independent of the granularity and other details of the two processes. Almost all reinforcement learning methods are well described as GPI, including the policy iteration algorithms we have discussed in this section. GPI works via the competing but complementary nature of the two processes. In some cases it can be guaranteed to converge. \n\n\\subsection{Efficiency of Dynamic Programming}\nIf we ignore a few technical details, then the (worst case) time DP methods take to find an optimal policy is polynomial in the number of states and actions. Compare this to the searching the states directly, which is exponential.", "meta": {"hexsha": "1eed394c48b9e21005c4495198d70a06e2dcb873", "size": 7555, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/chapter4/chapter4_content.tex", "max_stars_repo_name": "ElliotMunro200/reinforcement_learning_an_introduction", "max_stars_repo_head_hexsha": "c4fccb46a4bb00955549be3505144ec49f0132e5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 234, "max_stars_repo_stars_event_min_datetime": "2018-09-01T00:26:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T03:55:50.000Z", "max_issues_repo_path": "notes/chapters/chapter4/chapter4_content.tex", "max_issues_repo_name": "15779235038/reinforcement_learning_an_introduction", "max_issues_repo_head_hexsha": "a0ac9e5da6eaeae14d297a560c499d1a6e579c2a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2018-11-29T21:04:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-13T17:11:50.000Z", "max_forks_repo_path": "notes/chapters/chapter4/chapter4_content.tex", "max_forks_repo_name": "15779235038/reinforcement_learning_an_introduction", "max_forks_repo_head_hexsha": "a0ac9e5da6eaeae14d297a560c499d1a6e579c2a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2018-07-31T04:53:21.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T04:03:43.000Z", "avg_line_length": 71.9523809524, "max_line_length": 499, "alphanum_fraction": 0.7295830576, "num_tokens": 1984, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964035, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7043716647603117}}
{"text": "\\chapter{Random Variables}\n\n\\begin{ex}\n  Note that\n  \\begin{align*}\n    F(x^+)-F(x^-)\n     & =F(x)-\\lim_{\\substack{y\\to x    \\\\ y < x}}F(y) & & \\text{(by Theorem 2.8)} \\\\\n     & =\\lim_{\\substack{y\\to x         \\\\ y < x}}F(x)-F(y) \\\\\n     & =\\lim_{\\substack{y\\to x         \\\\ y < x}}\\P{X\\leq x}-\\P{X\\leq y} \\\\\n     & =\\lim_{\\substack{y\\to x         \\\\ y < x}}\\P{X\\in (-\\infty, x]}-\\P{X\\in (-\\infty, y]} \\\\\n     & =\\lim_{\\substack{y\\to x         \\\\ y < x}}\\P{X\\in (-\\infty, y]\\cup(y, x]}-\\P{X\\in (-\\infty, y]} \\\\\n     & =\\lim_{\\substack{y\\to x         \\\\ y < x}}\\P{X\\in (y, x]} \\\\\n     & =\\P{\\bigcap_{i=1}^n (x-1/n, x]} \\\\\n     & =\\P{X=x}.\n  \\end{align*}\n\\end{ex}\n\n\\begin{ex}~\n  \\inputminted{python}{../code/02-02.py}\n\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.98]{../images/02-02}\n    \\caption{Plot of the CDF $F$.}\n  \\end{figure}\n\n  Note that\n  \\[\n    \\P{2< X\\leq 4.8}\n    =\\P{X\\leq 4.8}-\\P{X\\leq 2}\n    =\\frac{2}{10}-\\frac{1}{10}\n    =\\frac{1}{10},\n  \\]\n  while\n  \\[\n    \\P{2\\leq X\\leq 4.8}=\\P{X\\leq 4.8}-\\P{X< 2}=\\frac{2}{10}-0=\\frac{2}{10}.\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  \\begin{enumerate}[1.]\n    \\item[]\n    \\item We already proved this claim as part of our solution to Exercise 1.\n    \\item Note that\n          \\begin{align*}\n            F(y) - F(x)\n             & = \\P{X\\in (-\\infty, y]} - \\P{X\\in (-\\infty, x]}           \\\\\n             & = \\P{X\\in (-\\infty, x]\\cup(x, y]} - \\P{X\\in (-\\infty, x]} \\\\\n             & = \\P{X\\in (x, y]}                                         \\\\\n             & = \\P{x < X\\leq y}.\n          \\end{align*}\n    \\item We have\n          \\begin{align*}\n            \\P{X>x}\n             & = \\P{X\\in (x, \\infty)}      \\\\\n             & = \\P{X\\in (-\\infty, x]^c}   \\\\\n             & = 1 - \\P{X\\in (-\\infty, x]} \\\\\n             & = 1 - F(x).\n          \\end{align*}\n    \\item Note that by Part 2, $F(b)-F(a)=\\P{a<X\\leq b}$. Moreover, note that\n          since $X$ is continuous, $\\P{\\{a\\}}=\\P{\\{b\\}}=0$, and hence we can\n          freely add or remove the endpoints of the interval on the right-hand\n          side without changing the value of the probability.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  \\begin{enumerate}[(a)]\n    \\item []\n    \\item We have\n          \\[\n            F_X(x)=\\begin{cases}\n              0                                & x \\leq 0,        \\\\\n              \\frac{1}{4}x                     & 0 < x < 1,       \\\\\n              \\frac{1}{4}                      & 1 \\leq x \\leq 3, \\\\\n              \\frac{1}{4} + \\frac{3}{8}(x - 3) & 3 < x < 5,       \\\\\n              1                                & x \\geq 5.\n            \\end{cases}\n          \\]\n    \\item Let $Y=1/X$. Note that\n          \\[\n            \\P{Y\\leq y}\n            =\\P{\\frac{1}{X}\\leq y}\n            =\\P{X\\geq \\frac{1}{y}}\n            =1-F_X(y^{-1}),\n          \\]\n          and that therefore\n          \\[\n            F_Y(y)=\\begin{cases}\n              0                         & y\\leq\\frac{1}{5},          \\\\\n              \\frac{15}{8}-\\frac{3}{8y} & \\frac{1}{5}<y<\\frac{1}{3}, \\\\\n              \\frac{3}{4}               & \\frac{1}{3}\\leq y\\leq 1,   \\\\\n              1 - \\frac{1}{4y}          & y>1,\n            \\end{cases}\n          \\]\n          and\n          \\[\n            f_Y(y)=\\begin{cases}\n              0              & y\\leq\\frac{1}{5},          \\\\\n              \\frac{3}{8y^2} & \\frac{1}{5}<y<\\frac{1}{3}, \\\\\n              0              & \\frac{1}{3}\\leq y\\leq 1,   \\\\\n              \\frac{1}{4y^2} & y>1.\n            \\end{cases}\n          \\]\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Let X and Y be independent discrete random variables. Then, for any\n  $x,y\\in\\R$,\n  \\begin{align*}\n    f_{X,Y}(x,y)\n     & =\\P{(X, Y)=(x, y)}            \\\\\n     & =\\P{(X, Y)\\in \\{(x, y)\\}}     \\\\\n     & =\\P{X\\in \\{x\\}, Y\\in \\{y\\}}   \\\\\n     & =\\P{X\\in \\{x\\}}\\P{Y\\in \\{y\\}} \\\\\n     & =\\P{X=x}\\P{Y=y}               \\\\\n     & =f_X(x)f_Y(y).\n  \\end{align*}\n\n  Conversely, suppose that $f_{X,Y}(x,y)=f_X(x)f_Y(y)$ for all $x$ and $y$.\n  Then for any $A$ and $B$,\n  \\begin{align*}\n    \\P{X\\in A, Y\\in B}\n     & =\\P{(X, Y)\\in A\\times B}                          \\\\\n     & =\\sum_{\\substack{(a,b)\\in A\\times B}}f_{X,Y}(a,b) \\\\\n     & =\\sum_{a\\in A}\\sum_{b\\in B}f_{X,Y}(a,b)           \\\\\n     & =\\sum_{a\\in A}\\sum_{b\\in B}f_{X}(a)f_{Y}(b)       \\\\\n     & =\\sum_{a\\in A}f_X(a)\\sum_{b\\in B}f_{Y}(b)         \\\\\n     & =\\P{X\\in A}\\P{Y\\in B}.\n  \\end{align*}\n\\end{ex}\n\n\\begin{ex}\n  Note that $Y$ is a discrete random variable with outcomes $0$ or $1$. In\n  particular,\n  \\[\n    \\P{Y=1}=\\E{I_A(X)}=\\int_A\\! f(x)\\,\\d{x},\n  \\]\n  and therefore\n  \\[\n    f_Y(x)=\\begin{cases}\n      1-\\int_A\\! f(t)\\,\\d{t} & x=0, \\\\\n      \\int_A\\! f(t)\\,\\d{t}   & x=1.\n    \\end{cases}\n  \\]\n  Hence,\n  \\[\n    F_Y(x)=\\begin{cases}\n      0                      & x < 0,       \\\\\n      1-\\int_A\\! f(t)\\,\\d{t} & 0\\leq x < 1, \\\\\n      1                      & x\\geq 1.\n    \\end{cases}\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  Consider\n  \\begin{align*}\n    \\P{Z>z}\n     & =\\P{X>z}\\P{Y>z}                                       \\\\\n     & =(1-\\P{X \\leq z})(1-\\P{Y \\leq z})                     \\\\\n     & =1-\\P{X \\leq z}-\\P{Y \\leq z}+\\P{X \\leq z}\\P{Y \\leq z} \\\\\n     & =\\begin{cases}\n      1        & z< 0,       \\\\\n      1-2z+z^2 & 0\\leq z< 1, \\\\\n      0        & z\\geq 1,\n    \\end{cases}\n  \\end{align*}\n  and hence\n  \\[\n    f_Z(z)\n    =\\frac{\\d}{\\d{z}} F_Z(z)\n    =\\frac{\\d}{\\d{z}} (1 - \\P{Z>z})\n    =\\begin{cases}\n      2-2z & 0\\leq z< 1,       \\\\\n      0    & \\text{otherwise}.\n    \\end{cases}\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  Note that $X^+$ is not supported on negative values and that therefore\n  $\\P{X^+\\leq x}=0$ for $x<0$. Note that $X^+=0$ whenever $X\\leq 0$ and\n  therefore $\\P{X^+=0}=\\P{X<0}$. Finally, for $x>0$,\n  \\[\n    \\P{X^+\\leq x}\n    =\\P{X^+<0}+\\P{X^+=0}+\\P{0<X\\leq x}\n    =F(0)+F(x)-F(0)=F(x).\n  \\]\n  Hence,\n  \\[\n    F_{X^+}(x)=\\begin{cases}\n      0    & x < 0,    \\\\\n      F(x) & x \\geq 0.\n    \\end{cases}\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  Suppose $X\\sim \\text{Exp}(\\beta)$. Then\n  \\begin{align*}\n    F(x)\n     & =\\int_{0}^x\\!\\beta e^{-\\beta t}\\,\\d{t}                   \\\\\n     & =-\\int_{0}^{-\\beta x}\\!e^{u}\\,\\d{u}    &  & (u=-\\beta t) \\\\\n     & =1-e^{-\\beta x}.\n  \\end{align*}\n  Now, suppose that $q=1-e^{-\\beta x}$. Then\n  \\[\n    e^{-\\beta x}= 1 - q,\n  \\]\n  or,\n  \\[\n    F^{-1}(q) = -\\frac{\\ln(1 - q)}{\\beta}.\n  \\]\n\\end{ex}\n\n% 10\n\\begin{ex}\n  Let $A,B\\subset \\R$. Note that\n  \\begin{align*}\n    \\P{g(X)\\in A, h(Y)\\in B}\n     & =\\P{X\\in g^{-1}(A), Y\\in h^{-1}(B)}   \\\\\n     & =\\P{X\\in g^{-1}(A)}\\P{Y\\in h^{-1}(B)} \\\\\n     & =\\P{g(X)\\in A}\\P{h(Y)\\in B}.\n  \\end{align*}\n  Since $A$ and $B$ were arbitrary, it follows that $g(X)$ and $h(Y)$ are\n  independent.\n\\end{ex}\n\n\\begin{ex}\n  \\begin{enumerate}[(a)]\n    \\item[]\n    \\item Note that $\\P{X=1}=\\P{Y=1}=1/2$, but $\\P{(X,Y)=(1,1)}=0$, instead of\n          1/4 as we would have expected if $X$ and $Y$ were independent.\n    \\item We have\n          \\begin{align*}\n            f_{N,X,Y}(n,x,y)\n             & =f_{N}(n)f_{X|N}(x|n)f_{Y|X,N}(y|x,n)                                      \\\\\n             & =\\frac{\\lambda^n e^{-\\lambda}}{n!}\\binom{n}{x}p^x(1-p)^{n-x}\\delta(x+y-n),\n          \\end{align*}\n          and therefore\n          \\begin{align*}\n            f_{X,Y}(x,y)\n             & =\\sum_{n=0}^\\infty\\frac{\\lambda^n e^{-\\lambda}}{n!}\\binom{n}{x}p^x(1-p)^{n-x}\\delta(x+y-n) \\\\\n             & =\\frac{\\lambda^{x+y} e^{-\\lambda}}{(x+y)!}\\binom{x+y}{x}p^x(1-p)^y                         \\\\\n             & =e^{-\\lambda}\\frac{\\lambda^x p^x}{x!} \\frac{\\lambda^y (1-p)^y}{y!}                         \\\\\n             & =\\frac{(\\lambda p)^xe^{-\\lambda p}}{x!} \\frac{(\\lambda(1-p))^ye^{-\\lambda (1-p)}}{y!}      \\\\\n             & = f_X(x)f_Y(y).\n          \\end{align*}\n          Hence, by Problem 2.5, it follows that $X\\amalg Y$.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Let $I_1\\times I_2$ be the range of $X$ and $Y$ where $I_1$ and $I_2$ are\n  (possibly unbounded) intervals. Then\n  \\begin{align*}\n    f_X(x)\n     & =\\int_{I_2}\\!f(x, y)\\,\\d{y}  \\\\\n     & =\\int_{I_2}\\!g(x)h(y)\\,\\d{y} \\\\\n     & =g(x)\\int_{I_2}\\!h(y)\\,\\d{y} \\\\\n     & =h_0g(x),\n  \\end{align*}\n  where the integral is known to be finite by Fubini's theorem since\n  $\\int_{I_1\\times I_2}f(x,y)\\,\\d{(x,y)}=1$.\n\n  Likewise,\n  \\[\n    f_Y(y)\n    =\\int_{I_1}\\!g(x)h(y)\\,\\d{y}\n    =g_0h(y).\n  \\]\n\n  Therefore,\n  \\[\n    \\int_{I_1}\\!f_X(x)f_Y(y)\\,\\d{x}\n    =h_0g_0\\int_{I_1}\\!g(x)h(y)\\,\\d{x}\n    =h_0g_0\\int_{I_1}\\!f(x,y)\\,\\d{x},\n  \\]\n  or, taking the leftmost and rightmost integrals,\n  \\[\n    f_Y(y)=h_0g_0f_Y(y).\n  \\]\n  Hence, $h_0g_0=1$, and so\n  \\[\n    f_X(x)f_Y(y)=h_0g_0 g(x)h(y)=g(x)h(y)=f(x,y).\n  \\]\n  Thus, $X$ and $Y$ are independent by Theorem 2.30.\n\\end{ex}\n\n\\begin{ex}\n  \\begin{itemize}[(a)]\n    \\item\n          Note that\n          \\[\n            F(y)\n            =\\P{Y\\leq y}\n            =\\P{e^X \\leq y}\n            =\\P{X \\leq \\ln {y}},\n          \\]\n          and therefore\n          \\[\n            f(y)\n            =\\frac{\\d}{\\d{y}}\\Phi(\\ln {y})\n            =\\frac{1}{y\\sqrt{2\\pi}}e^{-\\frac{1}{2}(\\ln{y})^2}.\n          \\]\n\n          \\inputminted{python}{../code/02-13a.py}\n          \\begin{figure}[H]\n            \\centering\n            \\includegraphics[scale=0.98]{../images/02-13a}\n            \\caption{Graph of PDF for $Y=e^X$.}\n          \\end{figure}\n\n    \\item[(b)]\n          \\inputminted{python}{../code/02-13b.py}\n\n          \\begin{figure}[H]\n            \\centering\n            \\includegraphics[scale=0.98]{../images/02-13b}\n            \\caption{Histogram of 10,000 samples from $Y=e^X$.}\n          \\end{figure}\n  \\end{itemize}\n\\end{ex}\n\n\\begin{ex}\n  Note that since $(X,Y)$ is uniformly distributed, the probability that\n  $\\P{R\\leq r}$ for $0\\leq r<1$ is going to be proportional to the area of the\n  disc of radius $r$. Therefore,\n  \\[\n    F_R(r)=\\begin{cases}\n      0   & r < 0,          \\\\\n      r^2 & 0\\leq r \\leq 1, \\\\\n      1   & r > 1,\n    \\end{cases}\n  \\]\n  and\n  \\[\n    f_R(r)=\\begin{cases}\n      2r & 0\\leq r \\leq 1,   \\\\\n      0  & \\text{otherwise}.\n    \\end{cases}\n  \\]\n\\end{ex}\n\n% 15\n\\begin{ex}\n  We have\n  \\[\n    F_X(x)\n    =\\P{X\\leq x}         \\\\\n    =\\P{F^{-1}(U)\\leq x} \\\\\n    =\\P{U\\leq F(x)}\n    =F(x),\n  \\]\n  and therefore $X\\sim F$.\n\n  \\inputminted{python}{../code/02-15.py}\n\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=1]{../images/02-15}\n    \\caption{A histogram of samples drawn from a uniform distribution and then\n      transformed under the inverse of the CDF of an $\\text{Exponential}(1)$\n      distribution.}\n  \\end{figure}\n\\end{ex}\n\n\\begin{ex}\n  We have\n  \\begin{align*}\n    \\cP{X=x}{X+Y=n}\n     & =\\frac{\\P{X=x,X+Y=n}}{\\P{X+Y=n}}                                                                               \\\\\n     & =\\frac{\\P{X=x,Y=n-x}}{\\P{X+Y=n}}                                                                               \\\\\n     & =\\frac{\\P{X=x}\\P{Y=n-x}}{\\P{X+Y=n}}                                                                            \\\\\n     & =\\frac{\\lambda^x e^{-\\lambda}}{x!}\\frac{\\mu^{n-x} e^{-\\mu}}{(n-x)!}\\frac{n!}{(\\lambda +\\mu)^ne^{-\\lambda-\\mu}} \\\\\n     & =\\binom{n}{x}\\left(\\frac{\\lambda}{\\lambda+\\mu}\\right)^x\\left(\\frac{\\mu}{\\lambda+\\mu} \\right)^{n-x}             \\\\\n     & =\\binom{n}{x}\\left(\\frac{\\lambda}{\\lambda+\\mu}\\right)^x\\left(1-\\frac{\\lambda}{\\lambda+\\mu} \\right)^{n-x},\n  \\end{align*}\n  but this is precisely the probability mass function of a\n  $\\text{Binomial}(n, \\lambda/(\\lambda+\\mu))$.\n\\end{ex}\n\n\\begin{ex}\n  We begin by obtaining the marginal distribution for $Y$:\n  \\[\n    \\int_0^1\\! c(x+y^2)\\,\\d{x}\n    =c\\left[\\frac{x^2}{2}+xy^2\\right]_{x=0}^1\n    =c\\left(\\frac{1}{2}+y^2\\right),\n  \\]\n  and therefore\n  \\[\n    f_Y(y)=c\\left(\\frac{1}{2}+y^2\\right)I_{[0,1]}(y).\n  \\]\n\n  Using the definition of conditional probability, we get\n  \\[\n    f_{X|Y}(x\\,|\\,y)\n    =\\frac{f_{X,Y}(x,y)}{f_Y(y)}\n    =\\frac{(x+y^2)}{\\left(\\frac{1}{2}+y^2\\right)}I_{[0,1]^2}(x,y).\n  \\]\n  Therefore,\n  \\[\n    \\cP{X<\\frac{1}{2}}{Y=\\frac{1}{2}}\n    =\\int_0^{1/2}\\!\\frac{x+\\frac{1}{4}}{\\frac{1}{2}+\\frac{1}{4}}\\,\\d{x}\n    =\\frac{4}{3}\\int_0^{1/2}\\!\\left(x+\\frac{1}{4}\\right)\\,\\d{x}\n    =\\frac{1}{3}.\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  \\begin{enumerate}[(a)]\n    \\item[]\n    \\item\n          \\begin{align*}\n            \\P{X<7}\n            =\\P{Z<\\frac{7 - 3}{4}}\n            =\\P{Z<1}\n            \\approx 0.8413.\n          \\end{align*}\n    \\item\n          \\begin{align*}\n            \\P{X>-2}\n            =1-\\P{Z<\\frac{-2 - 3}{4}}\n            =1 - \\P{Z<-1.25}\n            \\approx 0.8944.\n          \\end{align*}\n    \\item\n          \\begin{align*}\n            .05\n            =\\P{X>x}\n            =1-\\P{Z<\\frac{x-3}{4}}\n          \\end{align*}\n          Therefore\n          \\begin{align*}\n            1.64485\\approx \\Phi^{-1}(0.95)=\\frac{x-3}{4},\n          \\end{align*}\n          and so\n          \\begin{align*}\n            x\\approx 9.5794.\n          \\end{align*}\n\n    \\item\n          \\begin{align*}\n            \\P{0\\leq X < 4}\n             & =\\P{X<4}-\\P{X < 0}          \\\\\n             & =\\P{Z < 0.25}-\\P{Z < -0.75} \\\\\n             & \\approx 0.3702.\n          \\end{align*}\n    \\item\n          \\begin{align*}\n            .05\n             & =\\P{|X|>|x|}                                 \\\\\n             & =\\P{X>x}+\\P{X<-x}                            \\\\\n             & =1-\\P{X<x}+\\P{X<-x}                          \\\\\n             & =1-\\P{Z<\\frac{x-3}{4}}+\\P{Z<\\frac{-x-3}{4}}.\n          \\end{align*}\n\n          We use the following Python code to learn that $x$ is\n          approximately $9.61098387$.\n\n          \\inputminted{python}{../code/02-18.py}\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Suppose that $r$ is strictly monotone increasing with an inverse $s=r^{-1}$.\n  Let $X$ be a random variable and let $Y=r(X)$.\n  Then, since the inverse of a strictly monotone increasing function is also\n  strictly monotone increasing,\n  \\[\n    A_y\n    =\\{x \\mid r(x) \\leq y \\}\n    =\\{x \\mid x \\leq s(y) \\},\n  \\]\n  and hence\n  \\[\n    F_Y(y) = F_X(s(y)).\n  \\]\n  Thus, by the Chain Rule,\n  \\[\n    f_Y(y)=\\frac{\\d}{\\d{y}}F_X(s(y))=f_X(s(y))\\frac{\\d{s(y)}}{\\d{y}}.\n  \\]\n\n  Next, suppose that $r$ is strictly monotone decreasing. Then, since the\n  inverse of a strictly monotone decreasing function is also\n  strictly monotone decreasing,\n  \\[\n    A_y\n    =\\{x \\mid r(x) \\leq y \\}\n    =\\{x \\mid x \\geq s(y) \\}\n  \\]\n  and hence\n  \\[\n    F_Y(y) = 1-F_X(s(y)),\n  \\]\n  and\n  \\[\n    f_Y(y)=\\frac{\\d}{\\d{y}}\\left(1-F_X(s(y))\\right)=-f_X(s(y))\\frac{\\d{s(y)}}{\\d{y}}.\n  \\]\n\n  Finally, note that in the strictly monotone increasing case,\n  $\\frac{\\d{s(y)}}{\\d{y}}>0$, and therefore we can replace it with\n  $\\left|\\frac{\\d{s(y)}}{\\d{y}}\\right|$, while in the strictly monotone\n  decreasing case $\\frac{\\d{s(y)}}{\\d{y}}<0$, and therefore we can replace\n  $-\\frac{\\d{s(y)}}{\\d{y}}$ with $\\left|\\frac{\\d{s(y)}}{\\d{y}}\\right|$.\n  Hence, in both cases\n  \\[\n    f_Y(y)=f_X(s(y))\\left|\\frac{\\d{s(y)}}{\\d{y}}\\right|.\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  Let $Z=X-Y$ and note that if $0<z\\leq 1$,\n  \\[\n    A_z=\\{(x,y)\\mid x-y\\leq z\\}\n  \\]\n  is the unit square minus the triangle with vertices $(z,0)$, $(1,1)$ and\n  $(1,1-z)$, while if $-1<z\\leq 0$, $A_z$ is the triangle with vertices\n  $(0, -z)$, $(0, 1)$ and $(1+z,1)$. Hence,\n  \\[\n    F_Z(z)=\\begin{cases}\n      0                   & z\\leq -1,         \\\\\n      \\frac{(1+z)^2}{2}   & -1<z\\leq 0,       \\\\\n      1-\\frac{(1-z)^2}{2} & 0<z\\leq 1,        \\\\\n      1                   & \\text{otherwise},\n    \\end{cases}\n  \\]\n  and\n  \\[\n    f_Z(z)=\\begin{cases}\n      1+z & -1<z\\leq 0,       \\\\\n      1-z & 0<z\\leq 1,        \\\\\n      0   & \\text{otherwise}.\n    \\end{cases}\n  \\]\n\n  Next, let $U=X/Y$, and note that then\n  \\[\n    A_u=\\{(x,y)\\mid x/y\\leq u\\}\n  \\]\n  is the area in the unit square above the graph of the line $y=\\frac{1}{u}x$.\n  If $0<u\\leq 1$, this is the triangle with vertices $(0,0)$, $(0, 1)$ and\n  $(u, 1)$, while if $u>1$, this is the entire unit square except the triangle\n  with vertices $(0, 0)$, $(1, 0)$ and $\\left(1, \\frac{1}{u}\\right)$. Therefore,\n  \\[\n    F_U(u)=\\begin{cases}\n      0              & u\\leq 0,   \\\\\n      \\frac{u}{2}    & 0<u\\leq 1, \\\\\n      1-\\frac{1}{2u} & u> 1,\n    \\end{cases}\n  \\]\n  and\n  \\[\n    f_U(u)=\\begin{cases}\n      \\frac{1}{2}    & 0<u\\leq 1,        \\\\\n      \\frac{1}{2u^2} & u>1,              \\\\\n      0              & \\text{otherwise}.\n    \\end{cases}\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  Note that\n  \\begin{align*}\n    F_Y(y)\n     & =\\P{Y\\leq y}                                                                                   \\\\\n     & =\\P{X_1\\leq y, X_2\\leq y, \\cdots, X_n\\leq y}                                                   \\\\\n     & =\\P{X_1\\leq y}\\P{X_2\\leq y}\\cdots\\P{X_n\\leq y} &  & \\text{(independence of $X_i$'s)}           \\\\\n     & =\\P{X_1\\leq y}^n                               &  & \\text{(identical distribution of $X_i$'s)} \\\\\n     & =(1-e^{-\\beta y})^n,\n  \\end{align*}\n  and therefore,\n  \\[\n    f_Y(y)\n    =\\frac{\\d}{\\d{y}} (1-e^{-\\beta y})^n\n    =n\\beta e^{-\\beta y}(1-e^{-\\beta y})^{n-1}.\n  \\]\n\\end{ex}", "meta": {"hexsha": "082bb2d7794c4856718f1ba8fc19a5e2bfccedf1", "size": 16930, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/ch02.tex", "max_stars_repo_name": "dtrifuno/all-of-stats-solutions", "max_stars_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/tex/ch02.tex", "max_issues_repo_name": "dtrifuno/all-of-stats-solutions", "max_issues_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tex/ch02.tex", "max_forks_repo_name": "dtrifuno/all-of-stats-solutions", "max_forks_repo_head_hexsha": "0572cdae22b128e71c1c6c7ead2bf3b259875bc9", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.1896551724, "max_line_length": 120, "alphanum_fraction": 0.4200826934, "num_tokens": 6748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.704371650365353}}
{"text": "\n\\subsection{Anti-derivative}\n\n\nTaking the derivative of a function provides another function. The anti-derivative of a function is a function which, when differentiated, provides the original function.\n\nAs this function can include any additive constant, there are an infinite number of anti-derivatives for any function.\n\n\n", "meta": {"hexsha": "cb5504c2d3f582d22e9466946b318ec8ecd6ef73", "size": 325, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/integration/04-01-diffAnti.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/integration/04-01-diffAnti.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/integration/04-01-diffAnti.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.5, "max_line_length": 170, "alphanum_fraction": 0.8123076923, "num_tokens": 63, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8615382094310355, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.704371644552198}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{latexsym}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{graphicx}\n\\usepackage{wrapfig}\n\\usepackage{pseudocode}\n\\usepackage{url}\n\\usepackage[backref, colorlinks=true, citecolor=red, urlcolor=blue, pdfauthor={Jyh-Ming Lien}]{hyperref}\n\n\n\\newcommand{\\handout}[5]{\n  \\noindent\n  \\begin{center}\n  \\framebox{\n    \\vbox{\n      \\hbox to 5.78in { {\\bf CS 633 Computational Geometry} \\hfill #2 }\n      \\vspace{4mm}\n      \\hbox to 5.78in { {\\Large \\hfill #5  \\hfill} }\n      \\vspace{2mm}\n      \\hbox to 5.78in { {\\em #3 \\hfill #4} }\n    }\n  }\n  \\end{center}\n  \\vspace*{4mm}\n}\n\n\\newcommand{\\lecture}[4]{\\handout{#1}{#2}{#3}{}{#1}}\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{corollary}[theorem]{Corollary}\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem{observation}[theorem]{Observation}\n\\newtheorem{proposition}[theorem]{Proposition}\n\\newtheorem{definition}[theorem]{Definition}\n\\newtheorem{claim}[theorem]{Claim}\n\\newtheorem{fact}[theorem]{Fact}\n\\newtheorem{assumption}[theorem]{Assumption}\n\n% 1-inch margins, from fullpage.sty by H.Partl, Version 2, Dec. 15, 1988.\n\\topmargin 0pt\n\\advance \\topmargin by -\\headheight\n\\advance \\topmargin by -\\headsep\n\\textheight 8.9in\n\\oddsidemargin 0pt\n\\evensidemargin \\oddsidemargin\n\\marginparwidth 0.5in\n\\textwidth 6.5in\n\n\\parindent 0in\n\\parskip 1.5ex\n%\\renewcommand{\\baselinestretch}{1.25}\n\n\\begin{document}\n\n\\lecture{Voronoi Stippling}{Fall 2019}{Prof.\\ Jyh-Ming Lien}{---}\n\n\nThe goal of this assignment is to deepen your understanding on various implementations of 2-d Voronoi Diagram. \nYou are given an implementation of 2-d Voronoi Diagram using well-known image-based wave propagation method. You task is to (1) understand the implementations and (2) improve the provided implementation.\n\n\\textbf{What to submit}: You  need to turn in a report in \\LaTeX\\ (see the template in report folder).  Your report should include two main sections: a summary of what the code does, \nand your improvement. In the second section, you should include\nall the example outputs (visual and/or statistical results). In the last section you should report known bugs, and known limitations.\n\n\\textbf{How to submit}:\nZip your entire folder including code and example input and output in a single file called ``your\\_net\\_id\\_PA02.zip\". For example, my GMU net id is jmlien,  so my submission will be jmlien\\_PA02.zip.\n\n\\textbf{Due: Oct 30, 2019. At 11:59 pm.}\n\n\\section{Part 1: Understand the implementations (40 pts)}\n\n\n\\subsection{What should  you do?}\n\nYour goal is to get a full grasp of what the code does. \nYour summary should provide algorithms for computing Voronoi diagram, Centroidal Voronoi tessellation (CVT), \nand stippling methods. \n%Your summary should provide a discussion on what parameters are used to control their outputs. \n\n{\\sc Hint 1}: The implementation is based on the paper by Secord, Adrian. ``Weighted voronoi stippling.\" Proceedings of the 2nd international symposium on Non-photorealistic animation and rendering. ACM, 2002. It is highly recommend that you read the paper first.\n\n{\\sc Hint 2}: To compile hedcuter code, please use cmake or the solution file in folder {\\em hedcuter/code/vc\\_files}.\nThis code requires OpenCV 4.0. Installing OpenCV is straight forward on OSX and Linux. \nBy default, it requires 64 bits installation of OpenCV on Windows. \nThe solution file also uses two environment variables called ``OPENCV\\_INCLUDEDIR'' and ``OPENCVX64\\_LIBRARYDIR'' the point to \nthe include and library folders on the system. Therefore, make sure that you have those variable defined before you compile. You can  consult OpenCV documents\n(\\href{docs.opencv.org}{\\it docs.opencv.org})  or (\\href{https://www.learnopencv.com/install-opencv-4-on-windows/}{\\it https://www.learnopencv.com/install-opencv-4-on-windows/}\nif you encounter problems. \n\n\n\\section{Part 2: Improve  ``hedcuter'' code (60 pts)}\n\n\n\\subsection{What should  you do?}\n\nProvide at least three improvements (each will worth 20 points) to the hedcuter code. Below are some possible improvements that \nyou can do. In your report, you should show the improvement either visually or/and statistically for timing/performance results\nusing images of your own, i.e. do not use the images in hedcuter/images. \nExtra bonus of 20 points will be given for an additional improvement beyond the 3rd improvement.\n\\begin{enumerate}\n\n\\item Improve the distribution of the disks to avoid unnatural clustering of the disks. One idea is to use higher\nimage resolution (using subpixels) for computing the centroids of Voronoi cells. \n\n\\item Improve the computation efficiency. One way of doing this is via  the implementation of Fortune's algorithm. Another way is GPU. You can try the method by Hoff III, Kenneth E., et al. ``Fast computation of generalized Voronoi diagrams using graphics hardware.\" Proceedings of the 26th annual conference on Computer graphics and interactive techniques, 1999. The implementation should be pretty simple if you know OpenGL.\n\n\\item Add functionality to generate colorful disks. For example, you can implement functions that are not available in hedcuter code but provided in the voronoi code.\n\n\\item Using feature extraction, such as lines, to get better looking results.\n\n\\end{enumerate}\n\n\n\\bibliographystyle{plain}\n\\bibliography{shape-assignment}\n\n\\end{document}\n\n\n", "meta": {"hexsha": "ad3a0fca436291c7216e8b53f98ed4a2dfd08d14", "size": 5364, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment/assignment.tex", "max_stars_repo_name": "william-r-austin/hedcut", "max_stars_repo_head_hexsha": "58c6e452439a4abaf2bf09e09393e9a267fe2fe4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-04-14T18:41:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-17T10:12:56.000Z", "max_issues_repo_path": "assignment/assignment.tex", "max_issues_repo_name": "william-r-austin/hedcut", "max_issues_repo_head_hexsha": "58c6e452439a4abaf2bf09e09393e9a267fe2fe4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment/assignment.tex", "max_forks_repo_name": "william-r-austin/hedcut", "max_forks_repo_head_hexsha": "58c6e452439a4abaf2bf09e09393e9a267fe2fe4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-11-03T18:56:31.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-16T21:23:13.000Z", "avg_line_length": 43.6097560976, "max_line_length": 426, "alphanum_fraction": 0.7673378076, "num_tokens": 1444, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396211, "lm_q2_score": 0.8824278788223265, "lm_q1q2_score": 0.7043422651848017}}
{"text": "%!TEX root=ClassNotes.tex\n\n\\section{Inequalities}\nIn this section we'll learn how to solve inequalities and in the process figure out how to write proofs of statements involving inequalities.\n\n\nThe biggest different between equalities and inequalities is that, unlike equalities, there are usually infinitely many (if any) solutions to inequalities. When we we're trying to solve an inequality we're not looking for the best solution, we're not even looking for a good solution, we're simply looking for {\\bf one} solution. For example, both $x = 1.001$ and $x = 10^{100}$ are equally valid solutions to the inequality $x > 1$.\n\n\\begin{exercise}\n\tFind a positive real solution to each of the following inequalities.\n\t\\begin{enumerate}\n\t\t\\item $x ^ 3 + x < 1$\n\t\t\\item $(1 + x)^2 - 1 < 1$\n\t\t\\item $1 - (1 - x)^2 < 1$\n\t\t\\item $x ^ 3 + 2x < 1 + x^2$\n\t\t\\item $x^{10} + x > 10 $\n\t\t\\item $x^3 - x > 1$\n\t\\end{enumerate}\n\\end{exercise}\n\nWhen we try to solve equalities we try to simply the equation until it becomes easy to solve. The same thing is true for inequalities, however, the ways to simplify an inequality are much more subtle.\n\n\\begin{example}\n\tIf we're trying to solve $P(x) > \\epsilon$, where $P$ is some complicated expression that cannot be simplified, then we try to find some simpler $Q(x)$, such that $P(x) > Q(x)$ and try to solve for $Q(x) > \\epsilon$ instead. Similarly, if we're trying to solve $P(x) < \\epsilon$, then we try to find some simpler $Q(x)$, such that $P(x) < Q(x)$ and try to solve for $Q(x) < \\epsilon$ instead.\n\n\t There is no {\\it canonical way} in which an inequality can be solved. We somehow simplify the inequality and hope that we get a solution.\n\\end{example}\n\nFor solving complicated inequalities, we need a systematic approach towards estimating functions. There are different tricks and identities for estimating different kinds of functions. For now, we'll focus mainly on estimating polynomials.\n\n\\begin{exercise}$ $\n\t\\label{q:inequality_1}\n\tProve the following extremely useful set of inequalities\n\t\\begin{center}\n\t\t\\begin{tabular}{ll}\n\t\t\tif $1 \\ge x > 0$ &then $ 1 \\ge x \\ge x^2 \\ge x^3 \\ge \\dots$ \\\\\n\t\t\tif $1 \\le x$ &then $1 \\le x \\le x^2 \\le x^3 \\le \\dots$.\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{exercise}\n\n\n\\noindent {\\bf Word of Caution: } You should be very careful when negative numbers are involved. Multiplying an inequality by a negative number changes it's sign, for example, $2 < 3$ but $-2 > -3$. So,\n\\begin{center}\n\t\\begin{tabular}{ll}\n\t\tif $1 \\ge x > 0$ &then $ -1 \\le -x \\le -x^2 \\le -x^3 \\le \\dots$ \\\\\n\t\tif $1 \\le x$ &then $-1 \\ge -x \\ge -x^2 \\ge -x^3 \\ge \\dots$.\n\t\\end{tabular}\n\\end{center}\n\n\n\\subsection{Proofs involving Inequalities}\nWe'll encounter several statements in this class like: {\\it For every $\\epsilon> 0$ there exists a positive real number $x$ such that $x^3 + 3x < \\epsilon$.} When we want to prove such a statement, we are essentially trying to solve $x^3 + 3x < \\epsilon$. (Why?) For example,\\\\\n\\begin{q}\n\t\\label{q:sample_problem_inequality_1}\n\tProve that for every $\\epsilon > 0$ there exists a positive real number $x$ such that $x^3 + 3x < \\epsilon$.\n\\end{q}\n\\noindent We're asking for a solution to the equation $x^3 + 3x < \\epsilon$ for an arbitrary positive real number $\\epsilon$.\n\\begin{enumerate}\n\t\\item The terms $x^3$ and $x$ have different degrees. We can try to use the inequalities in Exercise \\ref{q:inequality_1} to simplify their sum, for this we need to know if $x \\ge 1$ or $x \\le 1$.\n\t\\item We're probably looking for a small  $x$ so we could assume $x \\le 1$. If this does not work we'll come back try something else. (Remember that we're trying to find {\\bf one} solution.)\n\t\\item As $x \\le 1$, $x^3 \\le x$ so that\n\t\t$x^3 + 3x \\le x + 3x= 4x$.\n\t\\item\tAs $x^3 + 3x \\le 4x$ and we want to find a solution to $x^3 + 3x < \\epsilon$, it suffices to solve $4x < \\epsilon$. As $\\epsilon$ is positive, \\textbf{one} solution for this is $x = \\epsilon / 5$.\n\t\\item We still need to check if this solution actually works. We can do this by trying to write down a direct proof and making sure that all the implications are logically sound.\n\t\\item We required the condition $x \\le 1$ for this solution to work. To ensure this we'll set $x = \\min \\{ 1, {\\epsilon}/{5}\\}$.\n\\end{enumerate}\n\nNow we know what the solution is, but we still need to write down a proof for the original statement. A proof should always start with some assumptions and logically derive the required conclusion. For us the assumption will be $\\epsilon > 0$ and $x = \\min \\{ 1, {\\epsilon}/{5}\\}$ and the expected conclusion is $x^3 + 3x < \\epsilon$.\n\n\\begin{proof}[Proof of Q. \\ref{q:sample_problem_inequality_1}]\n\tLet $\\epsilon > 0$ and let $x = \\min \\{ 1, {\\epsilon}/{5}\\}$. Note that $x \\le 1$ and hence $x^3 \\le x$. Then,\n\t\\begin{align*}\n\t\tx^3 + 3x\n\t\t&\\le x + 3x \\\\\n\t\t&= 4x \\\\\n\t\t&= 4 \\min  \\{ 1, {\\epsilon}/{5}\\} \\\\\n\t\t&\\le 4 \\epsilon /5 \\\\\n\t\t&< \\epsilon & \\mbox{ as $\\epsilon$ is positive}\n\t\\end{align*}\n\tHence, $x= \\min \\{ 1, {\\epsilon}/{5}\\}$ is a solution of $x^3 + 3x < \\epsilon$, which proves the proposition.\n\\end{proof}\nFirst we had to solve the inequality then reverse the steps: start with the solution and write a {\\it direct proof} for the proposition. This is how proofs are usually discovered. You make an ``educated guess'' and hope that it works. Sometimes it doesn't, so you go back to finding another ``educated guess''.\n\n\n\\begin{remark}[A note on quantifiers]\n\t For proving the statement {\\it``prove that for every $\\epsilon > 0$ there exists a positive real number $x$ such that $x^3 + 3x < \\epsilon$''} we had to start with the statement {\\it ``let $\\epsilon > 0$ and $x = \\min \\{ 1, {\\epsilon}/{5}\\}$''}.\n\t The variable $x$ depends on the variable $\\epsilon$.\n\t This is fine because of the order of quantifiers: {\\it``\\dots for every $\\epsilon > 0$ there exists a positive real number $x$ \\dots''}; the quantifier for $\\epsilon$ comes before the quantifier for $x$ and hence the variable $x$ can depend on the variable $\\epsilon$.\n\n\tIf instead, suppose we were trying to prove {\\it ``there exists a positive real number $x$ such that for every $\\epsilon > 0$, $x^3 + 3x < \\epsilon$''}.\n\tWe're still trying to solve the equation $x^3 + 3x < \\epsilon$ but now the quantifier for $x$ comes before the quantifier for $\\epsilon$ and hence $x$ cannot depend on the variable $\\epsilon$ but instead should be a constant that universally solves the equation $x^3 + 3x < \\epsilon$ for every $\\epsilon > 0$.\n\tNo such $x$ exists (why?) and hence the statement {\\it ``there exists a positive real number $x$ such that for every $\\epsilon > 0$, $x^3 + 3x < \\epsilon$''} is false.\n\\end{remark}\n\n\\begin{exercise}\n\tProve that for every $\\epsilon > 0$ there exists a positive real number $x$ such that \\dots\n\t\t\\begin{enumerate}\n\t\t\t\\item  $x ^ 3 + x < \\epsilon$.\n\t\t\t\\item  $(1 + x)^2 - 1 < \\epsilon$.\n\t\t\t\\item $1 - (1 - x)^2 < \\epsilon$.\n\t\t\t\\item  $x ^ 3 + 2x < \\epsilon + x^2$.\n\t\t\t\\item  $x^{10} + x > \\epsilon $.\n\t\t\t\\item  $x^3 - x > \\epsilon $.\n\t\t\t\t\t\t\\hint{Break $x^3$ as $\\frac{x^3}{2} + \\frac{x^3}{2}$ and find the conditions on $x$ for which $\\left(\\frac{x^3}{2} - x\\right) > 0$.}\\\\\n\t\t\\end{enumerate}\n\\end{exercise}\n\nFinally, we are sometimes required to find not one solution but a range of solutions. We try to come up an ``educated guess'' by the same method, and many a times this gives us the required range for free with a few changes in the final proof.\n\n\\begin{q}\n\t\\label{q:sample_problem_inequality_2}\n\tProve that for every $\\epsilon > 0$, there exists a positive real number $\\delta$ such that, for all $x$, if $0 < x < \\delta$ then $x^3 + 3x < \\epsilon$.\n\\end{q}\n\\begin{proof}\n\tLet $\\epsilon > 0$, let $\\delta = \\min \\{ 1, \\epsilon/5\\}$ and let $ 0 < x < \\delta$. Because $\\delta \\le 1$, we have $x < 1$ and hence $x^3 < x$. As before,\n\t\\begin{align*}\n\t\tx^3 + 3x\n\t\t&\\le x + 3x \\\\\n\t\t&= 4x \\\\\n\t\t&< 4 \\delta \\\\\n\t\t&= 4 \\min  \\{ 1, {\\epsilon}/{5}\\} \\\\\n\t\t&\\le 4 \\epsilon /5 \\\\\n\t\t&< \\epsilon& \\mbox{ as $\\epsilon$ is positive}\n\t\\end{align*}\n\tHence, every $0 < x <  \\min \\{ 1, \\epsilon/5\\}$ is a solution of $x^3 + 3x < \\epsilon$, which proves the proposition.\n\\end{proof}\n\n\n\\begin{exercise}\n\tProve that for every $\\epsilon > 0$, there exists a positive real number $\\delta$ such that, for all $x$, if $ 0 < x < \\delta$ then \\dots\n\t\t\\begin{enumerate}\n\t\t\t\\item  $x ^ 3 + x < \\epsilon$.\n\t\t\t\\item  $(1 + x)^2 - 1 < \\epsilon$.\n\t\t\t\\item $1 - (1 - x)^2 < \\epsilon$.\n\t\t\t\\item  $x ^ 3 + 2x < \\epsilon + x^2$.\n\t\t\\end{enumerate}\n\t\t\\noindent Prove that for every $\\epsilon > 0$, there exists a positive real number $\\delta$ such that, for all $x$, if $ x > \\delta$ then\n\t\t\\begin{enumerate}\n\t\t\t\\item $x^{10} + x > \\epsilon $.\n\t\t\t\\item $x^3 - x > \\epsilon$.\n\t\t\\end{enumerate}\n\\end{exercise}\n\n\\subsubsection*{Optional Problems}\n\\begin{exercise}\n\t\\begin{enumerate}\n\t\t\\item Prove that for every $\\epsilon > 0$, for every real number $x > 0$, there exists a $\\delta > 0$ such that, for all real numbers $y > 0$, if $ 0 < y - x < \\delta$ then $y^2 - x^2 < \\epsilon$.\n\t\t\\item Prove that the following statement is false: For every $\\epsilon > 0$, there exists a $\\delta > 0$ such that, for every real number $x > 0$, for all real numbers $y > 0$, if $ 0 < y - x < \\delta$ then $y^2 - x^2 < \\epsilon$.\n\t\\end{enumerate}\n\\end{exercise}\n", "meta": {"hexsha": "396a0ca882c0b857cca10e0227cc08253b64d901", "size": 9286, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2018/02Inequalities.tex", "max_stars_repo_name": "apurvnakade/jhu2017-18-honors-single-variable-calculus", "max_stars_repo_head_hexsha": "5b6cb3dde364990abe868ce155a697dce78302fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2018/02Inequalities.tex", "max_issues_repo_name": "apurvnakade/jhu2017-18-honors-single-variable-calculus", "max_issues_repo_head_hexsha": "5b6cb3dde364990abe868ce155a697dce78302fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2018/02Inequalities.tex", "max_forks_repo_name": "apurvnakade/jhu2017-18-honors-single-variable-calculus", "max_forks_repo_head_hexsha": "5b6cb3dde364990abe868ce155a697dce78302fa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.0921052632, "max_line_length": 433, "alphanum_fraction": 0.666702563, "num_tokens": 3008, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8824278587245935, "lm_q1q2_score": 0.704342249143057}}
{"text": "\n\n\\section*{Solutions to selected problems - 1}\n\n  \\begin{proof}[Solution to Q.4]\n    A line $L$ not passing through the origin can be written as\n    \\begin{align*}\n      L = \\{ \\vec{v} + c \\vec{w} : c \\in \\bbr\\}\n    \\end{align*}\n    \\begin{figure}[H]\n      \\centering\n      \\begin{tikzpicture}[scale=0.75]\n        \\clip(-1,-1) rectangle (10,5);\n\n        \\draw [thick, ->] (0,0)--(3,1);\n        \\node [below left] at (0,0) {$\\vec{0}$};\n          \\node [right] at (3,1) {$\\vec{v}$};\n        \\draw [thick, ->] (0,0)--(1,2);\n          \\node [above] at (1,2) {$\\vec{w}$};\n        \\draw [dashed] (1,2)--(4,3);\n\n        \\draw [thick, ->] (6,7)--(1,-3);\n          \\node [right] at (4,3) {$L = \\{ \\vec{v} + c \\vec{w} : c \\in \\bbr\\}$};\n      \\end{tikzpicture}\n    \\end{figure}\n\n    Similarly, a plane in $\\bbr^3$ that does not pass through the origin is given by $$\\{  \\vec{v} + c_1 \\vec{w}_1 + c_2 \\vec{w}_2\\}.$$\n  \\end{proof}\n\n\n\n\n\n  \\begin{proof}[Solution to Q.6]\n    \\textbf{Claim: }Every subspace of $\\bbr^1$ is either $\\{ \\vec{0} \\}$ or $\\bbr^1$.\\\\\n    \\textbf{Proof: }\n    Let $V$ be a subspace of $\\bbr^1$.\n    We have already shown that $V$ contains the vector $\\vec{0}$.\n    We will show that if $V \\neq \\{ \\vec{0}\\}$ then $V = \\bbr^1$.\n\n    Suppose $V$ contains a non-zero vector $\\vec{v} = [a]$ where $a \\neq 0$.\n    Because $V$ is closed under scalar multiplication $c \\vec{v} = c[a] = [ca]$ is also in $V$ for every real number $c$.\n    But $c$ can be any real number, so every vector $[b]$ is in $V$ which implies that $V = \\bbr^1$.\n  \\end{proof}\n\n  \\begin{proof}[Solution to Q.7]\n    A line in $\\bbr^2$ (or $\\bbr^3$) is a subspace of $\\bbr^2$ (or $\\bbr^3$) if and only if it passes through the origin.\n  \\end{proof}\n\n  \\begin{proof}[Solution to Q.8]\n    A plane in $\\bbr^3$ is a subspace of $\\bbr^3$ if and only if it passes through the origin.\n  \\end{proof}\n\n  \\begin{proof}[Solution Q.10 Part 2]\n    The union of two subspaces is not always a subspace.\n    Consider the following subspaces of $\\bbr^2$. Let $V$ be the $x$-axis and let $W$ be the $y$-axis.\n    Then $V \\cup W$ is the union of $x$ and $y$ axes. But this is not a subspace as it is not closed under addition.\n  \\end{proof}\n\n  \\begin{proof}[Solution to Q.12 Part 6]\n    For $\\cals = \\{ \\vec{e}_1 - \\vec{e}_2, \\vec{e}_2 - \\vec{e}_3, \\vec{e}_3 - \\vec{e}_1\\}$.\n    Notice the following identity:\n    \\begin{align*}\n      \\vec{e}_3 - \\vec{e}_1 = -(\\vec{e}_1 - \\vec{e}_2) - (\\vec{e}_2 - \\vec{e}_3)\n    \\end{align*}\n    \\begin{figure}[H]\n      \\centering\n      \\begin{tikzpicture}[scale=3]\n        \\node [below right] at (0,0) {$\\vec{0}$};\n\n        \\draw [thick, ->] (0,0)--(1,0);\n        \\node [below left] at (1,0) {$\\vec{e}_1 - \\vec{e}_2$};\n\n        \\draw [thick, ->] (0,0)--(-0.5,0.866);\n        \\node [below left] at (-0.5,0.866) {$\\vec{e}_2 - \\vec{e}_3$};\n\n        \\draw [thick, ->] (0,0)--(-0.5,-0.866);\n        \\node [left] at (-0.5,-0.866) {$\\vec{e}_3 - \\vec{e}_1$};\n\n      \\end{tikzpicture}\n    \\end{figure}\n\n    So that we can describe a vector in $\\spn(\\cals)$ as\n    \\begin{align*}\n      \\spn(\\cals) \\ni \\vec{v}\n      &=c_1(\\vec{e}_1 - \\vec{e}_2) + c_2 (\\vec{e}_2 - \\vec{e}_3) + c_3 (\\vec{e}_3 - \\vec{e}_1) \\\\\n      &= c_1(\\vec{e}_1 - \\vec{e}_2) + c_2 (\\vec{e}_2 - \\vec{e}_3) + c_3 \\left(-(\\vec{e}_1 - \\vec{e}_2) - (\\vec{e}_2 - \\vec{e}_3)\\right) \\\\\n      &= (c_1-c_3)(\\vec{e}_1 - \\vec{e}_2) + (c_2-c_3) (\\vec{e}_2 - \\vec{e}_3) \\\\\n      &= c_1'(\\vec{e}_1 - \\vec{e}_2) + c_2'(\\vec{e}_2 - \\vec{e}_3)\n      \\in \\spn\\left((\\vec{e}_1 - \\vec{e}_2),(\\vec{e}_2 - \\vec{e}_3)\\right).\n    \\end{align*}\n    So $\\vec{v}$ is in $\\spn\\left((\\vec{e}_1 - \\vec{e}_2),(\\vec{e}_2 - \\vec{e}_3)\\right)$.\n\n    \\emph{Answer:} $\\spn(\\cals)$ is a plane spanned by the vectors $\\vec{e}_1 - \\vec{e}_2$ and $\\vec{e}_2 - \\vec{e}_3$.\n  \\end{proof}\n", "meta": {"hexsha": "6694dd3280fa10c7281fbf90dc27776a23399c2a", "size": 3794, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "solutions1.tex", "max_stars_repo_name": "apurvnakade/mc2019-linear-algebra", "max_stars_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "solutions1.tex", "max_issues_repo_name": "apurvnakade/mc2019-linear-algebra", "max_issues_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "solutions1.tex", "max_forks_repo_name": "apurvnakade/mc2019-linear-algebra", "max_forks_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.5208333333, "max_line_length": 138, "alphanum_fraction": 0.5342646284, "num_tokens": 1589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.7043194205502156}}
{"text": "\\chapter{$\\mathcal{N} = 4$ SYM}\n\nConsider the action of a $d$-dimensional Yang-Mills (YM) theory \nwith a massless spin-$\\frac{1}{2}$ field $\\Psi$ in the adjoint representation of the gauge group $U(N)$:\n% (we will consider $SU(N)$)\n\\begin{equation}\n S = - \\dfrac{1}{g_{YM}^2} \\int d^d x \\, \\text{tr}\n     \\left(\n         \\dfrac{1}{2}F_{M N}F^{M N}\n       - \\bar{\\Psi} \\Gamma^M D_M \\Psi \n     \\right),    \n\\end{equation}\nwhere $F_{M N} =\\sum_{a=1}^{N^2} F_{M N}^a T^a_{ij}$, so that the trace is over the matrix indices $i, j=1, \\ldots, N$. \n$T^a$ are the generators of the gauge group.\nMore explicitly, the field-strength and the covariant derivative are\n\\begin{eqnarray}\n F_{MN} &=& \\partial_M A_N - \\partial_N A_M + [A_M, A_N],\\\\\n D_M &=& \\partial_M  + [A_M, \\cdot].\n\\end{eqnarray}\n\n% \\begin{eqnarray}\n%  F_{MN}^a &=& \\partial_M A_N^a - \\partial_N A_M^a + f_{abc} A_M^b A_N^c,\\\\\n%  D_M \\Psi^a &=& \\partial_M \\Psi^a + f_{abc} A_M^b \\Psi^c,\n% \\end{eqnarray}\n% where the structure constants $f_{abc}$ are defined by the commutation relation $[T^a, T^b]=f_{abc} T^c$.\n\n\nIn Minkowski spacetime $\\mathbb{R}^{9,1}$, \nthis action turns out to be invariant under the supersymmetry transformation:\n\\begin{eqnarray}\n \\delta_\\epsilon A_M  & = & \\epsilon \\Gamma_M \\Psi,\\\\\n \\delta_\\epsilon \\Psi & = & \\dfrac{1}{2} F_{M N} \\Gamma^{M N} \\epsilon,\n\\end{eqnarray}\nwhere $\\epsilon$ is a constant Majorana-Weyl spinor that parametrizes the transformation.\n% The bosonic and the fermionic degrees of freedom indeed match,\n% \\begin{itemize}\n%  \\item Bosonic: $D-2 = 8$\n%  \\item Fermionic: $2^{D/2}/2/2 = 8$\n% \\end{itemize}\n% which is a necessary condition for supersymmetry. \n\n \nLower dimensional supersymmetric theories can actually be obtained by \ndimensional reduction from the above theory \\cite{Brink:1976bc}. \nLet us review how we can derive the action for the maximally supersymmetric\n$\\mathcal{N}=4$ SYM on $\\mathbb{R}^{4}$.\n\n\\section{Action on $\\mathbb{R}^{4}$}\nThe dimensional reduction consists of restricting the dependence of the fields only to 4 dimensions: $(x_1, \\ldots, x_4)$.\nThe original Lorentz symmetry group $Spin(9,1)$ is then broken to $Spin(4) \\times Spin(5,1)^R$,\nthat is the Lorentz group in 4d and an internal symmetry group called R-symmetry (hence the superindex $R$).\nThese groups are isomorphic to:\n\\begin{eqnarray}\nSpin(4)      &=& SU(2)_L \\times SU(2)_R \\\\\nSpin(5, 1)^R &=& Spin(4)^R \\times SO(1,1)^R \\\\\n\t     &=& SU(2)^R_L \\times SU(2)^R_R \\times SO(1,1)^R.\n\\end{eqnarray}\n% where the subindexes $L, R$ refers to left and right. \n\nThe gauge field $A_M$ is reduced to the 4d gauge field and scalars:\n\\begin{eqnarray}\n Spin(4):     & \\,& A_\\mu, \\quad \\mu = 1, 2, 3, 4 \\\\\n%  Spin(5,1)^R: & \\,& \\Phi_I, \\quad I = 0, 5, 6, 7, 8, 9\n Spin(4)^R: & \\,& \\Phi_I, \\quad I = 5, 6, 7, 8 \\\\\n SO(1,1)^R: & \\,& \\Phi_I, \\quad I = 0, 9 \n\\end{eqnarray}\nwhere we wrote down the group they transform under.\n\nThe fermionic field, which is a Majorana-Weyl spinor, \ncan be decomposed to 4 Majorana spinors (each having 2 degrees of freedom):\n\\begin{equation}\n \\Psi=\\begin{bmatrix}\n       \\psi_L\\\\\n       \\chi_R\\\\\n       \\psi_R\\\\\n       \\chi_L\n      \\end{bmatrix}\n\\end{equation}\nwhere the spinors with the subindex $L$ (or $R$) transform in the spin-$\\frac{1}{2}$ representation of\n$SU(2)_L$ (or $SU(2)_R$).\nAlso, spinors with the name $\\psi$ and $\\chi$ transform in the spin-$\\frac{1}{2}$ representation of\n$SU(2)_L^R$ and $SU(2)_R^R$ from the R-symmetry subgroup, respectively.\n\n\n\n\nThe $\\mathcal{N}=4$ SYM action explicitly written in terms of the 4d bosonic fields is:\n\\begin{equation}\\label{SR4}\n  \\begin{split}\n    S_{\\mathbb{R}^4} = - \\dfrac{1}{g_{YM}^2} \\int d^4 x \\, \\text{tr}\n    (\n         \\dfrac{1}{2}F_{\\mu \\nu}F^{\\mu \\nu}\n       + D_\\mu \\Phi_I D^\\mu \\Phi^I\n       + \\dfrac{1}{2} [\\Phi_I, \\Phi_J]\\, [\\Phi^I, \\Phi^J]       \n    \\\\\n       \\qquad\n       - \\bar{\\Psi} \\Gamma^\\mu D_\\mu \\Psi \n       - \\bar{\\Psi} \\Gamma^I [ \\Phi_I, \\Psi ]\n    ),\n   \\end{split}\n\\end{equation}\nwhere we decomposed the 10d gamma matrices as $\\Gamma^M=\\Gamma^\\mu \\otimes \\Gamma^I$.\n\n\nThe action has no mass scale, and it is in fact conformal invariant even at quantum level \\cite{MANDELSTAM1983149, BRINK1983323}.\nThe conformal group extends the Poincar\\'e group (translation, rotations and boosts) \nto include scaling (dilatation),\nand special conformal transformation, which is a composition of inversion, translation and inversion.\nThe conformal symmetry, the four copies of supersymmetry and the internal R-symmetry\nare part of the larger $\\mathcal{N}=4$ superconformal group $PSU(2,2|4)$.\nIts Lie algebra is generated by the generators of the conformal algebra, \n16 supercharges (that commute with momentum generators),\nand 16 superconformal charges (that commute with special conformal generators). \nDetails of the algebra can be found for example in \\cite{Minahan:2010js}.\n\n\n\\section{Action on $S^4$}\nIn order to apply supersymmetric localization to $\\mathcal{N}=4$ SYM, \nwe shall put this theory on a hypersphere $S^4$.\n% , which can be done using conformal invariance.\nConformal invariance implies an additional conformal coupling of the scalars to the scalar curvature $\\mathcal{R}$, \nnamely,\n\\begin{equation}\\label{conformalCoupling}\n \\dfrac{\\mathcal{R}}{6} \\Phi^I \\Phi_I, \\quad I=0,5,6,7,8,9\n\\end{equation}\nwhere for $S^d$ with radius $R$, the scalar curvature is $\\mathcal{R} = d(d-1)/R^2 $.\nThen, there will be also a metric factor $\\sqrt{g}$ coming from the curved background.\nThe action on $S^4$ is hence\n\\begin{equation}\\label{SS4}\n  \\begin{split}\n    S_{S^4} = - \\dfrac{1}{g_{YM}^2} \\int d^4 x \\, \\sqrt{g} \\text{tr}\n    \\left(\n        \\dfrac{1}{2}F_{\\mu \\nu}F^{\\mu \\nu}\n       + D_\\mu \\Phi_I D^\\mu \\Phi^I\n       + \\dfrac{1}{2} [\\Phi_I, \\Phi_J]\\, [\\Phi^I, \\Phi^J]       \n    \\right. \\\\\n    \\left. \n       \\qquad\n       - \\bar{\\Psi} \\Gamma^\\mu D_\\mu \\Psi \n       - \\bar{\\Psi} \\Gamma^I [ \\Phi_I, \\Psi ]\n       + \\dfrac{2}{R^2} \\Phi^I \\Phi_I\n    \\right).\n   \\end{split}\n\\end{equation}\nLocalization also requires the existence of an off-shell supersymmetry.\nTo fulfill this condition, additional auxiliary field terms are added to the above action, see \\cite{Pestun:2007rz, Festuccia:2011ws}.\nThen, on the localization locus, the action will effectively be $3/2$ times the conformal coupling \\eqref{conformalCoupling}, \nsee also \\cite{Russo:2013qaa}.\nNaturally, at the decompactification limit $R \\rightarrow \\infty$, we recover the flat space version.\n% We shall see this limit is important for many of our results.\n\n\n\n\n\n\n\n\\chapter{$\\mathcal{N} = 2^*$ SYM}\n\nThe fields of $\\mathcal{N}=4$ SYM form a $\\mathcal{N}=4$ vector (or gauge) multiplet, \nbut the latter can be decomposed into two $\\mathcal{N}=2$ massless supermultiplets, namely\n\\begin{eqnarray}\n \\text{Vector multiplet:} & & \\{A_1, A_2, A_3, A_4, \\Phi_0, \\Phi_9, \\psi_L, \\psi_R\\},  \\\\\n \\text{Matter hypermultiplet:} & &\\{\\Phi_5, \\Phi_6, \\Phi_7, \\Phi_8, \\chi_L, \\chi_R\\}.\n\\end{eqnarray}\t\n\n$\\mathcal{N}=2^*$ SYM is the unique massive deformation of $\\mathcal{N}=4$ SYM that breaks half of its supersymmetries.\nThis is achieved by giving mass to the matter hypermultiplet, \neither via the $\\mathcal{N}=1$ superpotential \\cite{Buchel:2000cn, Bobev:2013cja}, \nor using Scherk-Schwarz reduction of $\\mathcal{N}=1$ SYM \\cite{Pestun:2007rz, Scherk:1979zr}.\nThe latter prescribes the following replacement rules in the action \\eqref{SR4}:\n\\begin{eqnarray}\nD_0 \\Phi_i &\\rightarrow & D_0 \\Phi_i + M_{ij} \\Phi_j, \\quad i,j =5,\\ldots 8 \\\\\nD_0 \\chi &\\rightarrow & D_0 \\chi + \\dfrac{1}{4}\\Gamma_{ij} M_{ij} \\chi,\n\\end{eqnarray}\nwhere $M_{ij}$, a $4 \\times 4$ matrix, is a generator of $SU(2)^R_R$,\nand is normalized as $M_{ij} M^{ij} = 4 M^2$, where $M$ is the mass scale. All the repeated indices are summed over.\nThese replacements will give the standard mass term to the bosons and the fermions, \nand a cubic coupling term for the scalars. \nIn its infinite-mass limit, the matter hypermultiplet can be integrated out, \nand the resulting theory is the pure $\\mathcal{N}=2$ SYM.\n\n\n% The full mass term to be added to the massless theory is:\n% \\begin{equation}\n%  S_\\text{mass} = \\dfrac{1}{2 g_{YM}^2} \\int d^4 x \\, \\sqrt{g} \n%  \\text{tr} \\left( m^2 \\Phi_i \\Phi^i + m (\\chi_1 \\chi_1 + \\chi_2 \\chi_2 + h.c.) \n%            -\\dfrac{1}{4 r} R_{ki} M_{kj} \\Phi^i \\Phi^j\n%            \\right)\n% \\end{equation}\nIn order to apply the localization method to the partition function of $\\mathcal{N}=2^*$ SYM,\nwe need to put it on $S^4$.\nSince the theory is no longer conformal due to the hypermultiplet mass scale,\nan additional curvature correction term to the mass is required in order to preserve supersymmetry, \nbesides the conformal coupling discussed in \\eqref{SS4}.\n% Moreover, localization requires off-shell supersymmetry, and that is fixed by an auxiliary field term to the action.\nThe full action can be found in \\cite{Pestun:2007rz}, with the details of the localization procedure therein.\nWe are interested in the final localized result, that we will discuss next.\n\n% In the limit of infinitely heavy hypermultiplet, these fields possess no dynamic degrees of freedom,\n% hence we can integrate them out and then the resulting theory is the pure $\\mathcal{N}=2$ SYM. \n\n\n\n\\input{Chapters/PartitionFunctions.tex}\n\n% \\section{Action }\n\n% Let us first review how to obtain the actions of our theories. \n% We will start with the action of $\\mathcal{N}=4$ SYM on $\\mathbb{R}^{3,1}$. \n% It is convenient to use the language of $\\mathcal{N}=1$ SYM in $\\mathbb{R}^{9,1}$, \n% from which all supersymmetric actions for lower dimensional Yang-Mills theory can be obtained from (cite someone).\n% \n% The action is \n% \\begin{equation}\n%  S = \\int d^4 x\\, \\sqrt{g} \\mathcal{L}.\n% \\end{equation}\n% \n% The Lagrangian density for $\\mathcal{N}=4$ SYM on $S^4$:\n% \\begin{equation}\n%  \\mathcal{L}_{$\\mathcal{N}=4$} = -\\dfrac{1}{g_{YM}^2} \n%     \\text{tr}\\left(\n%       \\frac{1}{2}F_{MN}F^{MN} - \\Psi \\Gamma^M D_M \\Psi  + \\dfrac{2}{r^2} \\Phi_A \\Phi^A\n%     \\right).  \n% \\end{equation}\n% For $\\mathcal{N}=2^*$ SYM, we add mass to the hypermultiplet (in the covariant derivatives),\n% \\begin{equation}\n%  \\mathcal{L}_{$\\mathcal{N}=2$^*} = \n% \t\t     -\\dfrac{1}{g_{YM}^2} \n% \t\t\t   \\text{tr} \\left(\n% \t\t\t      \\frac{1}{2}F_{MN}F^{MN} - \\Psi \\Gamma^M D_M \\Psi  + \\dfrac{2}{r^2} \\Phi_A \\Phi^A\n% \t\t\t      -\\dfrac{1}{4 r} R_{ki} M_{kj} \\Phi^i \\Phi^j - K_i K^i\n% \t\t\t    \\right). \n% \\end{equation}\n% where the last term is added in order to have an off-shell susy so that the localization can be applied.", "meta": {"hexsha": "2247d681b6f53bbe61ce97f08dbb06c5714afd0b", "size": 10501, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/SYM.tex", "max_stars_repo_name": "yixinyi/PhDThesis", "max_stars_repo_head_hexsha": "fa5e6d89bf6e7658cebae8bab8a3d22fe4e53e29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/SYM.tex", "max_issues_repo_name": "yixinyi/PhDThesis", "max_issues_repo_head_hexsha": "fa5e6d89bf6e7658cebae8bab8a3d22fe4e53e29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapters/SYM.tex", "max_forks_repo_name": "yixinyi/PhDThesis", "max_forks_repo_head_hexsha": "fa5e6d89bf6e7658cebae8bab8a3d22fe4e53e29", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.685106383, "max_line_length": 134, "alphanum_fraction": 0.6741262737, "num_tokens": 3655, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834278, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7042257616097218}}
{"text": "\\documentclass[letterpaper]{article}\n\n\\usepackage{fullpage}\n\\usepackage{nopageno}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage[utf8]{inputenc}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\title{Notes}\n\\date{September 22, 2014}\n\\maketitle\n\\section*{cont'd example from last time}\n$a_{n+1}=1+\\frac{1}{a_n}$ and is fibanocci sequence. terms are back and forth but converging. it is clear that $a_n>1\\forall n$.\n\\begin{align*}\n  \\left\\lvert a_{n+1}-a_n\\right\\rvert&=\\left\\lvert 1+\\frac{1}{a_n}-\\left(1+\\frac{1}{a_{n-1}}\\right)\\right\\rvert\\\\\n  &=\\left\\lvert\\frac{1}{a_n}-\\frac{1}{a_{n-1}}\\right\\rvert\\\\\n  &=\\frac{\\left\\lvert a_n-a_{n-1}\\right\\rvert}{a_n\\cdot a_{n-1}}\\text{with $a_n>1$ so}\\\\\n  \\left\\lvert a_{n+1}-a_n\\right\\rvert&<\\left\\lvert a_{n}-a_{n-1}\\right\\rvert\\\\\n\\end{align*}\ndoes this mean we have a limit?\ncontractive sequence has the property\n$|a_{n+1}-a_n|<r|a_n-a_{n-1}|$ wher $r\\in(0,1)$\n\nno, it is possible in principle that $\\lim|a_{n+1}-a_n|=b>0$ and that would mean that $\\{a_n\\}$ is not convergent\n\n\\begin{align*}\n  a_na_{n+1}&=a_n(1+\\frac{1}{a_n}=a_n+1>2\\\\\n  \\left\\lvert a_{n+1}-a_n\\right\\rvert&<\\frac{1}{2}\\left\\lvert a_{n}-a_{n-1}\\right\\rvert\\\\\n\\end{align*}\nso it is convergent because $\\frac{1}{2}\\in(0,1)$\n\n\\section*{2.8.D}\npick a sequence of $\\varepsilon$, $\\varepsilon_n=\\{\\frac{1}{2^n}\\}$. given $\\varepsilon_1=\\frac{1}{2}$ there exists $N+1\\in\\mathbb{N}$ such that $|a_m-a_n<\\varepsilon_1$ if $m,n\\ge N_1$, $\\varepsilon_2=\\frac{1}{4}, \\exists N_2$ st $\\left\\lvert a_m-a_n\\right\\rvert<\\varepsilon_2$ and so on.\n\nso $|a_{\\mathbb{N}_{n+1}}-a_{N_{n}}|<\\frac{1}{2^n}$ and so the sum is less than 1 and we win.\n\\section*{convergent series}\ngiven $(a_n)$ we consider the series $\\sum\\limits_{n=1}^\\infty{a_n}$ let $s_n=\\sum\\limits_{k=1}^n{a_k}$ be the $n$th partial sum of the series. if $\\lim s_n$ exists, we say that the series $\\sum\\limits_{k=1}^\\infty{a_k}$is convergent\n\nthe following are equivalent\n\\begin{itemize}\n\\item\n$\\sum a_n$ is convergent\n\\item\n$\\forall\\varepsilon>0\\exists N$ st if $n\\ge N, \\left\\lvert\\sum\\limits_{k=n+1}^\\infty{a_k}\\right\\rvert<\\varepsilon$\n\\item\n$\\forall\\varepsilon>0\\exists N$ st if $m,n\\ge N, \\left\\lvert\\sum\\limits_{k=n+1}^m{a_k}\\right\\rvert<\\varepsilon$\n\\end{itemize}\nproofs are in the book\n\n\\section*{note}\nif $\\sum a_k<\\infty$ then $\\lim a_k=0$ but the converse is false, as shown by the harmonic series.\n\ntelescoping and geometric series are basically the only ones where we know how to find the sums\n\n\\section*{3.1.c}\nif $\\sum t_k$ is a convergent series of positive terms and $p>1$ show that $\\sum t_k^p$ is convergent\n\nthe necessary condition is that $\\lim t_k=0$. by the necessary condition $\\exists N$ st $0\\le t_k\\le1\\forall k\\ge N$. Therefore $\\sum\\limits_{k=N}^\\infty{t_k^p}\\le\\sum\\limits_{k=N}^\\infty{t_k}<\\infty$ \n\\section*{3.1.d}\nif $\\lim |a_n|=0$ then there exists $\\sum a_{n_k}<\\infty$\n\nexample argument: harmonic series\n\\end{document}\n\n", "meta": {"hexsha": "2a6ab6cb2f8382e4d0f8f1b5058e83f21e4b2d5e", "size": 2960, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "real analysis/analysis-notes-2014-09-22.tex", "max_stars_repo_name": "ylixir/school", "max_stars_repo_head_hexsha": "66d433f2090b6396c8dd2a53a733c25dbe7bc90f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "real analysis/analysis-notes-2014-09-22.tex", "max_issues_repo_name": "ylixir/school", "max_issues_repo_head_hexsha": "66d433f2090b6396c8dd2a53a733c25dbe7bc90f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "real analysis/analysis-notes-2014-09-22.tex", "max_forks_repo_name": "ylixir/school", "max_forks_repo_head_hexsha": "66d433f2090b6396c8dd2a53a733c25dbe7bc90f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.8985507246, "max_line_length": 289, "alphanum_fraction": 0.6939189189, "num_tokens": 1177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8740772253241803, "lm_q1q2_score": 0.7041847483765813}}
{"text": "\\section{Introduction to Functions}\\label{sec:Functions}\r\nA \\dfont{function} $y=f(x)$ is a rule for determining\r\n$y$ when we're given a value of $x$.  For example, the rule\r\n$y=f(x)=2x+1$ is a function.  Any line $y=mx+b$ is called a \\dfont{linear} \r\nfunction.  The graph of a function looks like a curve \r\nabove (or below) the $x$-axis, where for any value\r\nof $x$ the rule $y=f(x)$ tells us how far to go above (or below) the\r\n$x$-axis to reach the curve.\r\n\r\n\\begin{definition}{FUNCTION}\r\n\tAA {\\bf{function}} is a relation between a set of inputs and a set of permissible outputs with the property that each input is related to exactly one output. That is, a function $f$ assigns to each element $x$ in a set $D$ exactly one element, called $f(x)$ in a set $E$.\r\n\\end{definition}\t\r\n\r\nA function $f$ is defined by its set of inputs, called the {\\bf{domain}} of $f$. The inputs are also referred to as the {\\bf{independent variable}} of the function. The set of permissible outputs is called the {\\bf{range}} of $f$ (or image of the function). Since outputs depend on the inputs, the output is referred to as the {\\bf{dependent variable}}. For a function written in the form, $\\displaystyle{f(x)}$, $x$ is also referred to as the {\\bf{argument}} of the function. Thus, for $g(4+h)$ the input $4+h$ is the argument for the function $g$.  \\\\\r\n\r\n\r\n\\begin{figure}[H]\r\n\t$$\\includegraphics[width=4.5in]{images/Domain1}$$\r\n\t\\caption{Arrow diagrams showing (a) function and (b) non-function. \\label{fig:arrowDiagrams}} \r\n\\end{figure}\t\r\n\r\nThe diagram in Figure~\\xrefn{fig:arrowDiagrams} (a) represents a function with domain $\\{1, 2, 3\\}$ and set of ordered pairs $\\{(1,D), \\,\\,(2,C), \\,\\,(3,C)\\}$. The range of $f$ is $\\{C, \\,\\,D\\}$. However, this second diagram (Figure~\\xrefn{fig:arrowDiagrams} (b)) does not represent a function. One reason is that $x=2$ corresponds to two values of $y$, $y=B$ and $y=C$.  \\\\\r\n\r\nA useful way to visualize a function is by sketching its graph. If $f$ is a function with domain $D$, then its graph is the set of ordered pairs $\\ds{(x,f(x))}$. Since the y-coordinate of ant point $(x,y)$ on the graph is $y=f(x)$, we can read the value of $f(x)$ from the graph as being the height of the graph corresponding to $x$. The graph of $f$ also allows us to see visualize the domain and range of the function. \\\\\r\n\r\n\r\n\r\n\r\nFunctions can be defined in various ways: by an algebraic formula or several\r\nalgebraic formulas, by a graph, or by an experimentally determined \r\ntable of values. In the latter case, the table gives a bunch of \r\npoints in the plane, which we might then\r\ninterpolate with a smooth curve, if that makes sense.\r\n\r\n\\vspace{3mm} \r\nGiven a value of $x$, a function must give\r\nat most one value of $y$.  Thus, vertical lines are not functions.  \r\n%For example, the line $x=1$ has infinitely many values of $y$ if $x=1$. It\r\n%is also true that \r\n%if $x$ is any number (not 1) there is no $y$ which corresponds to $x$,\r\n%but that is not a problem---only multiple $y$ values is a problem.\r\n\r\nOne test to identify whether or not a curve in the $(x,y)$ coordinate \r\nsystem is a function is the following.\r\n\r\n\\begin{theorem}{The Vertical Line Test}{Vertical Line Test}\r\n\t\\label{VertLineTest}\r\nA curve in the $(x,y)$ coordinate system represents a function if and only if no vertical line intersects the curve more than once.\r\n\\end{theorem}\r\n\r\n\\begin{figure}[H]\r\n\t$$\\includegraphics[width=5in]{images/VerticalLines1}$$\r\n\t\r\n\t\\caption{(a) Vertical line intersects curve once for all $x$, therefore the curve represents a function. (b) Vertical Line intersects curve more than once for $x$, therefore this curve does not represent a function. }\r\n\\end{figure}\r\n\r\n\\begin{example}{Identifying Functions}{IDFunctions}\r\n\tDetermine which equations represent $y$ as a function of $x$.  \\\\\r\n\t\r\n\\hspace{4mm} (a) \\hspace{2mm} $x^3 + y^2 = 1$ \\hspace{1.5cm} (b) \\hspace{2mm} $x^2 + y^3 = 1$\r\n\t\\hspace{1.5cm} (c) \\hspace{2mm} $x^2y = 1 - 3y$\r\n\\end{example}\r\n\\begin{solution}\t\r\nFor each of these equations, we solve for $y$ and determine whether each choice of $x$ will determine only one corresponding value of $y$.\r\n\t\r\n(a) \t\t\r\n \\[ \\begin{array}{rclr} \r\n\t\tx^3 + y^2 & = & 1 & \\\\\r\n\t\ty^2 & = & 1 - x^3 & \\\\\r\n\t\t\\sqrt{y^2} & = & \\sqrt{1 - x^3} & \\mbox{extract square roots} \\\\\r\n\t\ty & = & \\pm \\sqrt{1 - x^3} & \\\\ \r\n\t\t\\end{array} \\]\r\n\t\t\r\nIf we substitute $x=0$ into our equation for $y$, we get  $y = \\pm \\sqrt{1 - 0^3} = \\pm 1$, so that $(0,1)$ and $(0,-1)$ are on the graph of this equation. Hence, this equation does not represent $y$ as a function of $x$. As predicted, the graph of $x^3+y^2=1$, shown in Figure~\\xrefn{fig:graphFT}(a), clearly fails the Vertical Line Test (Theorem \\ref{VertLineTest}), so the equation does not represent $y$ as a function of $x$.\\\\   \r\n\r\n\\vspace{3mm}\r\n\t\t\r\n(b)\r\n  \\[ \\begin{array}{rclr} \r\n\t\tx^2 + y^3 & = & 1 & \\\\\r\n\t\ty^3 & = & 1 - x^2 & \\\\\r\n\t\t\\sqrt[3]{y^3} & = & \\sqrt[3]{1 - x^2} & \\\\\r\n\t\ty & = & \\sqrt[3]{1 - x^2} & \\\\ \r\n\t\t\\end{array} \\]\r\n\t\t\r\nFor every choice of $x$, the equation $y =  \\sqrt[3]{1 - x^2}$ returns only \\textbf{one} value of $y$.  Hence, this equation describes $y$ as a function of $x$. As predicted, the graph of $x^2+y^3=1$, shown in Figure~\\xrefn{fig:graphFT}(b), clearly passes the Vertical Line Test (Theorem \\ref{VertLineTest}), so the equation does represent $y$ as a function of $x$.\\\\   \r\n\t\t\r\n(c) \r\n  \\[ \\begin{array}{rclr} \r\n\t\tx^2y & = & 1 - 3y & \\\\\r\n\t\tx^2y + 3y & = & 1 & \\\\\r\n\t\ty \\left(x^2 + 3\\right) & = & 1 & \\mbox{factor} \\\\\r\n\t\ty & = & \\dfrac{1}{x^2 + 3} & \\\\ \r\n\t\t\\end{array} \\]\r\n     For each choice of $x$, there is only one value for $y$, so this equation describes $y$ as a function of~$x$. \t\t\r\n     As predicted, the graph of $x^2y=1-3y$, shown in Figure~\\xrefn{fig:graphFT}(c), clearly passes the Vertical Line Test (Theorem \\ref{VertLineTest}), so the equation does represent $y$ as a function of $x$.\\\\   \r\n\r\n\\begin{figure}[H]\t\r\n$$\\includegraphics[scale=0.38]{images/TestFunction-ex1}$$\r\n\\caption{\\label{fig:graphFT}} \r\n\\end{figure}\r\n\\end{solution}\r\n\r\n\r\n\\subsection{Function Notation and Domain}\r\n\r\n In this section, we focus more on the \\textbf{process} \\index{function ! as a process} by which the $x$ is matched with the $y$.  If we think of the domain of a function as a set of \\textbf{inputs} and the range as a set of \\textbf{outputs}, we can think of a function $f$ as a process by which each input $x$ is matched with only one output $y$.  Since the output is completely determined by the input $x$ and the process $f$, we symbolize the output with \\index{function ! notation} \\textbf{function notation}: `$f(x)$', read `$f$ \\textbf{of} $x$.' In other words, $f(x)$ is the output which results by applying the process $f$ to the input $x$.  In this case, the parentheses here do not indicate multiplication, as they do elsewhere in Algebra.  This can cause confusion if the context is not clear, so you must read carefully. \\\\\r\n \r\n The value of $y$ is completely dependent on the choice of $x$.  For this reason,  $x$ is often called the \\index{variable ! independent} \\index{independent variable} \\index{function ! independent variable of} \\textbf{independent variable}, or \\index{function ! argument} \\index{argument ! of a function} \\textbf{argument} of $f$, whereas $y$ is often called the \\index{variable ! dependent} \\index{dependent variable} \\index{function ! dependent variable of} \\textbf{dependent variable}. \r\n \r\n \\medskip\r\n \r\n As we shall see, the process of a function $f$ is usually described using an algebraic formula. For example, suppose a function $f$ takes a real number and performs the following two steps, in sequence\r\n \r\n \\begin{enumerate}\r\n \t\r\n \t\\item  multiply by 3\r\n \t\r\n \t\\item  add 4\r\n \t\r\n \\end{enumerate}\r\n \r\n If we choose $5$ as our input,  in step 1 we multiply by $3$ to get $(5)(3) = 15$.  In step 2, we add 4 to our result from step 1 which yields $15 + 4 = 19$.  Using function notation, we would write  $f(5) = 19$ to indicate that the result of applying the process $f$ to the input $5$ gives the output $19$.  In general, if we use $x$ for the input, applying step 1 produces $3x$.  Following with step 2 produces $3x+4$ as our final output.  Hence for an input $x$, we get the output $f(x) = 3x + 4$.  Notice that to check our formula for the case $x=5$, we replace the occurrence of $x$ in the formula for $f(x)$ with $5$ to get $f(5) = 3(5) + 4 = 15 + 4 = 19$, as required.\r\n\r\n\r\n\\begin{minipage}{0.4\\textwidth}\r\nIn addition to lines, another familiar example of a  \r\nfunction is the parabola $f(x)=x^2$.  We can draw the graph of this\r\nfunction by taking various values of $x$ (say, at regular intervals) and\r\nplotting the points $(x,f(x))=(x,x^2)$.  Then connect the points with a\r\nsmooth curve.  (See Figure~\\xrefn{fig:graphx2}.)\\\\\r\n\\end{minipage} \r\n\\begin{minipage}{0.3\\textwidth}\r\n\t$$\\begin{array}{r|r}\r\n\t\tx & y=x^{2}\\\\ \\hline\r\n\t\\vdots & \\vdots \\\\\t\r\n\t-3 & (-3)^{2} = 9 \\\\\r\n\t-2 & (-2)^{2} = 4 \\\\\r\n\t-1 & (-1)^{2} = 1 \\\\\r\n\t0 & (0)^{2} = 0 \\\\\r\n\t1 & (1)^{2} = 1 \\\\\r\n\t2 & (2)^{2} = 4 \\\\\r\n\t3 & (3)^{2} = 9 \\\\\r\n\t\\vdots & \\vdots \\\\\r\n\\end{array} $$\t\r\n\\end{minipage}\r\n\\begin{minipage}{0.3\\textwidth}\r\n\t\\begin{figure}[H]\r\n\t$$\\includegraphics[scale=0.25]{images/Plotx2}$$\r\n\t\\caption{ \\label{fig:graphx2}}\r\n\t\\end{figure} \r\n\\end{minipage}\r\n\t\r\n\r\nThe two examples $f(x)=2x+1$ and $f(x)=x^2$ are both functions which\r\ncan be evaluated at {\\it any} value of $x$ from negative infinity to\r\npositive infinity.  For many functions, however, it only makes sense to\r\ntake $x$ in some interval or outside of some ``forbidden'' region.  The\r\ninterval of $x$-values at which we're allowed to evaluate the function is\r\ncalled the \\dfont{domain} of the function.\r\n\r\n\\begin{minipage}{0.6\\textwidth}\r\n\t\\begin{example}{Graph of a function}{GraphFunction}\r\n\t\tGiven the graph of $f$ shown in Figure~\\xrefn{fig:graphF}\\\\\r\n\t\t(a)  Find the values of $f(-2)\\, , \\,\\, f(3) \\, , \\,$ and $\\, f(5)$. \\\\\r\n\t\t(b) What are the domain and range of $f$?\\\\\r\n\t\\end{example}\r\n\t\\vspace{2.5cm}\r\n\\end{minipage}\r\n\\begin{minipage}{0.4\\textwidth}\r\n\t\\begin{figure}[H]\r\n\t\t$$\\includegraphics[width=2.2in]{images/graphFunction1}$$\r\n\t\t\\caption{ \\label{fig:graphF}} \r\n\t\\end{figure}\r\n\\end{minipage}\r\n\r\n\\vspace{-2.5cm}\r\n\\begin{minipage}{0.6\\textwidth}\r\n\t\\begin{solution}\r\n\t\t(a) We see from the Figure  that the point $(-2, \\,-3)$ lies on the graph of $f$, so the value of $f$ at $x=-2$ is $f(-2)=-3$. From the graph, when $x=3$, $f(3)=-1$ and when $x=5$, $f(5)=4$. \\\\\r\n\t\t(b) The graph of $f(x)$ is defined for $\\displaystyle{-6 \\leq x \\leq 6}$, so the domain of $f$ is the closed interval $[-6, \\, 6]$. The range of $f$ is the set of all $y$ -values obtained from evaluating the function on its domain. Therefore, the range of $f$ is the  closed interval from $[-3, \\, 6]$. \r\n\t\\end{solution}\r\n\\end{minipage}\t\r\n\r\n\\begin{example}{Evaluating a function}\r\n\tIIf $\\,\\,\\displaystyle{f(x)=x^{2}-3x+5}$, \\hspace{2mm} find  $\\displaystyle{f(-1)} \\,$ , \\hspace{2mm}  $\\displaystyle{f(0)} \\, $ , \\hspace{2mm}  $\\displaystyle{f(11)}$\r\n\\end{example}\r\n\\begin{solution}\r\n\tWe first evaluate $f(-1)$ by replacing $x$ with the argument $-1$ in the expression \\\\ $\\displaystyle{f(x)=x^{2}-3x+5}$. This yields \\hspace{2mm} $\\displaystyle{f(-1)=(-1)^{2}-3(-1)+5= 9}$. \\\\\r\n\t\r\n\tSimilarily,   \\hspace{2mm} $\\displaystyle{f(0)=(0)^{2}-3(0)+5= 5}$ \\hspace{2mm} and  \\hspace{2mm}  $\\displaystyle{f(11)=(11)^{2}-3(11)+5= 9}$ \\\\\r\n\\end{solution}\r\n\r\n\\begin{example}{Evaluating a function}{EvalFn}\r\n\tFind and simplify the following.\r\n\t\r\n\t\\begin{enumerate}\r\n\t\t\r\n\t\t\\item $f(-1)$, $f(0)$, $f(2)$\r\n\t\t\r\n\t\t\\item  $f(2x)$, $2 f(x)$\r\n\t\t\r\n\t\t\\item $f(x+2)$, $f(x)+2$, $f(x) + f(2)$\r\n\t\t\r\n\t\\end{enumerate}\r\n\\end{example}\r\n\\begin{solution}\r\n\t\r\n\t \\begin{enumerate} \\item  To find $f(-1)$, we replace every occurrence of $x$ in the expression $f(x)$ with $-1$\r\n\t\t\t\r\n\t\t\t\\[ \\begin{array}{rclr}  \r\n\t\t\tf(-1) & = & -(-1)^2 + 3(-1) + 4 & \\\\\r\n\t\t\t& = & -(1) + (-3) + 4 & \\\\ \r\n\t\t\t& = & 0 & \\\\ \r\n\t\t\t\\end{array} \\]\r\n\t\t\t\r\n\t\t\t\r\n\t\t\tSimilarly, $f(0) = -(0)^2 + 3(0) + 4 = 4$, \\\\\r\n\t\t\t\r\n\t\t\tand \\hspace{9mm} $f(2) = -(2)^2 + 3(2) + 4 = -4+6+4 = 6$.\r\n\t\t\t\r\n\t\t\t\\item To find $f(2x)$, we replace every occurrence of $x$ with the quantity $2x$\r\n\t\t\t\r\n\t\t\t\\[ \\begin{array}{rclr}  \r\n\t\t\tf(2x) & = & -(2x)^2 + 3(2x) + 4 & \\\\\r\n\t\t\t& = & -(4x^2) + (6x) + 4 & \\\\\r\n\t\t\t& = & -4x^2+6x+4 & \\\\ \r\n\t\t\t\\end{array} \\]\r\n\t\t\t\r\n\t\t\tThe expression $2f(x)$ means we multiply the expression $f(x)$ by $2$\r\n\t\t\t\r\n\t\t\t\\[ \\begin{array}{rclr}  \r\n\t\t\t2f(x) & = & 2\\left(-x^2 + 3x + 4\\right) & \\\\\r\n\t\t\t& = & -2x^2 + 6x + 8 \\\\ \r\n\t\t\t\\end{array} \\]\r\n\t\t\t\r\n\t\t\t\r\n\t\t\t\\item  To find $f(x+2)$, we replace every occurrence of $x$ with the quantity $x+2$\r\n\t\t\t\r\n\t\t\t\\[ \\begin{array}{rclr}  \r\n\t\t\tf(x+2) & = & -(x+2)^2 + 3(x+2) + 4 & \\\\\r\n\t\t\t& = & -\\left(x^2 + 4x + 4\\right) + (3x+6) + 4 & \\\\\r\n\t\t\t& = & -x^2-4x-4+3x+6+4 &  \\\\\r\n\t\t\t& = & -x^2-x+6 & \r\n\t\t\t\\end{array} \\]\r\n\t\t\t\r\n\t\t\tTo find $f(x)+2$, we add $2$ to the expression for $f(x)$\r\n\t\t\t\r\n\t\t\t\\[ \\begin{array}{rclr}  \r\n\t\t\tf(x) + 2 & = & \\left(-x^2 + 3x + 4\\right) + 2  & \\\\\r\n\t\t\t& = & -x^2 + 3x + 6 \\\\ \r\n\t\t\t\\end{array} \\]\r\n\t\t\t\r\n\t\t\tFrom our work above, we see $f(2) = 6$ so that\r\n\t\t\t\r\n\t\t\t\\[ \\begin{array}{rclr}  \r\n\t\t\tf(x) + f(2) & = & \\left(-x^2 + 3x + 4\\right) + 6  & \\\\\r\n\t\t\t& = & -x^2 + 3x + 10 \\\\ \r\n\t\t\t\\end{array} \\]\r\n\t\t\t\r\n\t\t\\end{enumerate}\r\n\t\t\r\n\r\nA few notes about the previous example are in order.  First note the difference between the answers for $f(2x)$ and $2f(x)$.  For $f(2x)$, we are multiplying the \\textit{input} by $2$;  for $2 f(x)$, we are multiplying the \\textit{output} by $2$.  As we see, we get entirely different results.  Along these lines, note that $f(x+2)$, $f(x) + 2$ and $f(x) + f(2)$ are three \\textit{different} expressions as well.  Even though function notation uses parentheses, as does multiplication, there is \\textit{no} general `distributive property' of function notation. Finally, note the practice of using parentheses when substituting one algebraic expression into another;  we highly recommend this practice as it will reduce careless errors. \r\n\\end{solution}\r\n\r\n\r\n\\begin{example}{Evaluating a function}\r\n\tIIf $\\,\\,\\displaystyle{f(x)=\\sqrt{x^{2}+1}-\\frac{3}{5-x}}$, \\hspace{2mm} evaluate $f(-x)\\,$  \\hspace{2mm} and  \\hspace{2mm}  $f(a+h)$.\r\n\\end{example}\r\n\\begin{solution}\r\n\t\r\n\t$$\\begin{array}{rclrcl }\r\n\tf(-x) & = & \\displaystyle{\\sqrt{(-x)^{2}+1}-\\frac{3}{5-(-x)}}  & \\hspace{1.5cm} f(a+h) & = & \\displaystyle{\\sqrt{(a+h)^{2}+1}-\\frac{3}{5-(a+h)}} \\\\\r\n\t&&&&& \\\\\r\n\t& = & \\displaystyle{\\sqrt{x^{2}+1}-\\frac{3}{5+x}}         && = & \\displaystyle{\\sqrt{a^{2}+2ah+h^{2}+1}-\\frac{3}{5-a-h}} \\\\\r\n\t\\end{array}$$\r\n\\end{solution}                    \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n%\\begin{figure}[h]\r\n%%\\centerline{\r\n%\\hbox to \\hsize{\\vbox{\\beginpicture\r\n%\\normalgraphs\r\n%%\\ninepoint\r\n%\\setcoordinatesystem units <0.7truecm,0.7truecm>\r\n%\\setplotarea x from -3 to 3, y from -3 to 3\r\n%\\axis left shiftedto x=0 /\r\n%\\axis bottom shiftedto y=0 /\r\n%\\setquadratic\r\n%\\plot -2.5 3 0 0 2.5 3 /\r\n%\\put {$f(x)=x^2$} [t] <0pt,-5pt> at 0 -3\r\n%\\endpicture }\\hfill\r\n%\\vbox{\\beginpicture\r\n%\\normalgraphs\r\n%%\\ninepoint\r\n%\\setcoordinatesystem units <0.7truecm,0.7truecm>\r\n%\\setplotarea x from -3 to 3, y from -3 to 3\r\n%\\axis left shiftedto x=0 /\r\n%\\axis bottom shiftedto y=0 /\r\n%\\setquadratic\r\n%\\plot 0 0 1 1 3 1.732 /\r\n%\\put {$f(x)=\\sqrt{x}$} [t] <0pt,-5pt> at 0 -3\r\n%\\endpicture }\\hfill\r\n%\\vbox{\\beginpicture \r\n%\\normalgraphs\r\n%%\\ninepoint\r\n%\\setcoordinatesystem units <0.7truecm,0.7truecm>\r\n%\\setplotarea x from -3 to 3, y from -3 to 3\r\n%\\axis left shiftedto x=0 /\r\n%\\axis bottom shiftedto y=0 /\r\n%\\setquadratic\r\n%\\plot -3.000 -0.333 -2.867 -0.349 -2.733 -0.366 -2.600 -0.385 -2.467 -0.405 \r\n%-2.333 -0.429 -2.200 -0.455 -2.067 -0.484 -1.933 -0.517 -1.800 -0.556 \r\n%-1.667 -0.600 -1.533 -0.652 -1.400 -0.714 -1.267 -0.789 -1.133 -0.882 \r\n%-1.000 -1.000 -0.867 -1.154 -0.733 -1.364 -0.600 -1.667 -0.467 -2.143 \r\n%-0.333 -3.000 /\r\n%\\plot 0.333 3.000 0.467 2.143 0.600 1.667 0.733 1.364 0.867 1.154 \r\n%1.000 1.000 1.133 0.882 1.267 0.789 1.400 0.714 1.533 0.652 \r\n%1.667 0.600 1.800 0.556 1.933 0.517 2.067 0.484 2.200 0.455 \r\n%2.333 0.429 2.467 0.405 2.600 0.385 2.733 0.366 2.867 0.349 \r\n%3.000 0.333 /\r\n%\\put {$f(x)=1/x$} [t] <0pt,-5pt> at 0 -3\r\n%\\endpicture}}\r\n%%}\r\n%\\caption{Some graphs. \\label{fig:some graphs}}\r\n%\r\n%\\end{figure} \r\n\r\n\\begin{example}{Domain of an a quadratic function}{FindDomain}\r\n\tFind the domain and range of $\\ds{f(x)=x^{2}}$.\r\n\\end{example}\r\n\r\n\\begin{minipage}{0.6\\textwidth}\r\n\t\\begin{solution} \t\r\n\t\tThe domain of $\\ds{f(x)=x^{2}}$ is the set of all real numbers, $\\ds{\\R }$, where the graph of $f$ consists of all pairs of real numbers $\\ds{(x, \\,x^{2})}$. The graph of $f$ represents a parabola. The range of $f$ consists of all values of $f(x)=x^{2}$, or more precisely, the set of non-negative real numbers. So the range of $f$ is $\\ds{\\{y \\in \\mathbb{R} \\, \\ssep \\, y \\geq 0 \\} = [0,\\infty)}$.   \\\\\r\n\t\\end{solution}\r\n\\end{minipage}\r\n\\begin{minipage}{0.4\\textwidth}\r\n\t$$\\includegraphics[width=1.5in]{images/x2}$$\r\n\\end{minipage}\r\n\r\n\\begin{example}{Domain of the Square-Root Function}{DomainofSquare-RootFunction}\r\n\tFind the domain of $\\ds{f(x)=\\sqrt{x}}$. \r\n\\end{example}\r\n\r\n\\begin{solution}\r\nThe square-root function $(x)=\\sqrt{x}$ is the rule\r\nwhich says, given an $x$-value, take the non-negative number whose\r\nsquare is $x$.  This rule only makes sense if $x\\ge 0$. % is positive or zero.\r\nWe say that the domain of this function is $x\\ge 0$, or more formally\r\n$\\left\\{x\\in\\mathbb{R}\\, \\ssep \\,x\\ge 0\\right\\}$.  Alternately, we\r\ncan use interval notation, and write that the domain is $[0,\\infty)$.\r\nThe fact that the domain of $y=\\sqrt{x}$ is $[0,\\infty)$ means that in the\r\ngraph of this function (see Table~\\ref{tab:elemfns})\r\nwe have points $(x,y)$ only above $x$-values on the right side of the\r\n$x$-axis.\r\n\\end{solution}\r\n\r\n\\begin{example}{Domain of the Identity Function}{DomainofSquare-RootFunction}\r\n\tFind the domain of $\\ds{f(x)=\\frac{1}{x} }$. \r\n\\end{example}\r\n\r\n\\begin{solution}\r\nAnother example of a function whose domain is not the entire $x$-axis\r\nis: $f(x)=1/x$, the reciprocal function. (See Table~\\ref{tab:elemfns}.)  We cannot substitute $x=0$\r\nin this formula.  The function makes sense, however, for any nonzero\r\n$x$, so we take the domain to be: $\\{x\\in\\mathbb{R}\\, \\ssep \\,x\\ne 0\\}$.  The graph\r\nof this function does not have any point $(x,y)$ with $x=0$.  As $x$\r\ngets close to 0 from either side, the graph goes off toward $\\pm$ infinity.\r\nWe call the vertical line $x=0$ an \\dfont{asymptote}.\r\n\\end{solution}\r\n\r\n\r\nTo summarize, two reasons why certain $x$-values are excluded from the\r\ndomain of a function are the following.\r\n\r\n\\begin{formulabox}[Restrictions for the Domain of a Function]\r\n\r\n1.  Division by zero is not allowed. That is, if $\\ds{\\,\\,f(x)=\\frac{P(x)}{Q(x)}\\,\\,}$ then $\\ds{\\,\\, Q(x) \\neq 0}$. \\\\\r\n2.  Real square roots of a negative number do not exist. That is, if $\\ds{\\,\\, f(x) = \\sqrt{D(x)} \\,\\,}$ \\\\\r\nthen $\\ds{\\,\\, D(x) \\geq 0}$.  \\\\\r\n\\\\\r\nWe will encounter some other ways in which functions might be undefined later.\r\n\\end{formulabox}\r\n\r\n\\begin{example}{Finding domain of a rational function with a square root}{domain}\r\n\tFind the domain of \r\n\t$$f(x)={\\frac{1}{\\sqrt{4x-x^2}}}$$\r\n\t\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\n\\begin{solution} \r\n\tTo answer this question, we must rule out the $x\\,$-values that make\r\n\t$4x-x^2$ negative (because we cannot take the square root of a\r\n\tnegative number)\r\n\tand also the $x\\,$-values that make $4x-x^2$ zero (because if $4x-x^2=0$, then\r\n\twhen we take the square root we get 0, and we cannot divide by 0).\r\n\tIn other words, the domain consists of all $x$ for which $4x-x^2$ is\r\n\tstrictly positive.  That is, \\\\\r\n\t$$\\begin{array}{rcl}\r\n\t4x-x^{2} & > & 0 \\\\\r\n\tx (4-x) & > & 0 \\hspace{5mm} \\longrightarrow \\,\\,0 < x < 4 \\\\\r\n\t\\end{array}$$\r\n\t\r\n\tIn interval notation, the domain is the interval $(0,4)$.\r\n\\end{solution}\r\n\r\n\r\n\r\n\\subsection{Modeling with Functions}\\label{sec:ModelingFn}\r\n\r\nThe importance of Mathematics to our society lies in its value to approximate, or \\textbf{model}\\index{mathematical model}\\index{model ! mathematical} real-world phenomenon.  Whether it be used to predict the high temperature on a given day, determine the hours of daylight on a given day, or predict population trends of various and sundry real and mythical beasts, Mathematics is second only to literacy in the importance humanity's development.\r\n\r\n\\medskip\r\n\r\nIt is important to keep in mind that anytime Mathematics is used to approximate reality, there are always limitations to the model.  For example, suppose grapes are on sale at the local market for $\\$1.50$ per pound. Then one pound of grapes costs $\\$1.50$, two pounds of grapes cost $\\$3.00$, and so forth.  Suppose we want to develop a formula which relates the cost of buying grapes to the amount of grapes being purchased.  Since these two quantities vary from situation to situation, we assign them variables.  Let $c$ denote the cost of the grapes and let $g$ denote the amount of grapes purchased. To find the cost $c$ of the grapes, we multiply the amount of grapes $g$ by the price $\\$1.50$ dollars per pound to get \\[c = 1.5 g\\]  In order for the units to be correct in the formula, $g$ must be measured in \\textit{pounds} of grapes in which case the computed value of $c$ is measured in \\textit{dollars}.  Since we're interested in finding the cost $c$ given an amount $g$, we think of $g$ as the independent variable and $c$ as the dependent variable.  Using the language of function notation, we write \\[c(g) = 1.5 g\\] where $g$ is the amount of grapes purchased (in pounds) and $c(g)$ is the cost (in dollars).  For example, $c(5)$ represents the cost, in dollars, to purchase $5$ pounds of grapes. In this case, $c(5) = 1.5(5) = 7.5$, so it would cost $\\$ 7.50$. If, on the other hand, we wanted to find the \\textit{amount} of grapes we can purchase for $\\$5$, we would need to set $c(g) = 5$ and solve for $g$.  In this case, $c(g)=1.5g$, so solving  $c(g) = 5$ is equivalent to solving $1.5g = 5$  Doing so gives $g = \\frac{5}{1.5} = 3.\\overline{3}$. This means we can purchase exactly $3.\\overline{3}$ pounds of grapes for $\\$5$.  Of course, you would be hard-pressed to buy exactly $3.\\overline{3}$ pounds of grapes, and this leads us to our next topic of discussion, the \\index{domain ! applied}\\index{applied domain of a function}\\textbf{applied domain} of a function.\r\n\r\n\\medskip\r\n\r\nEven though, mathematically, $c(g) = 1.5g$ has no domain restrictions (there are no denominators and no even-indexed radicals), there are certain values of $g$ that don't make any physical sense.  For example, $g = -1$ corresponds to `purchasing' $-1$ pounds of grapes. Also, unless the `local market' mentioned is the State of California (or some other exporter of grapes), it also doesn't make much sense for $g = 500,000,000$, either. So the reality of the situation limits what $g$ can be, and these limits determine the applied domain of $g$.  Typically, an applied domain is stated explicitly.  In this case, it would be common to see something like $c(g) = 1.5g$, $0 \\leq g \\leq 100$, meaning the number of pounds of grapes purchased is limited from $0$ up to $100$. The upper bound here, $100$ may represent the inventory of the market, or some other limit as set by local policy or law.  Even with this restriction, our model has its limitations.  As we saw above, it is virtually impossible to buy exactly  $3.\\overline{3}$ pounds of grapes so that our cost is exactly $\\$5$.  In this case, being sensible shoppers, we would most likely `round down' and purchase $3$ pounds of grapes or however close the market scale can read to $3.\\overline{3}$ without being over.  It is time for a more sophisticated example.\r\n\r\n\\begin{example}{Application}{Application}\r\n\tThe height $h$ in feet of a model rocket above the ground $t$ seconds after lift-off is given by \\[ h(t) = \\left\\{ \\begin{array}{rcl} -5t^2 + 100t, & \\mbox{if} & 0 \\leq t \\leq 20 \\\\ 0, & \\mbox{if} & t > 20 \\\\ \\end{array} \\right.\\]\r\n\t\\begin{enumerate}\r\n\t\t\r\n\t\t\\item Find and interpret $h(10)$ and $h(60)$.\r\n\t\t\r\n\t\t\\item Solve $h(t) = 375$ and interpret your answers.\r\n\t\\end{enumerate}\r\n\\end{example}\r\n\\begin{solution}\r\n\t\\begin{enumerate} \r\n\\item We first note that the independent variable here is $t$, chosen because it represents time.  Secondly, the function is broken up into two rules:  one formula for values of $t$ between $0$ and $20$ inclusive, and another for values of $t$ greater than 20. Since $t=10$ satisfies the inequality $0 \\leq t \\leq 20$,  we use the first formula listed,  $h(t) = -5t^2 + 100t$, to find $h(10)$.  We get $h(10) = -5(10)^2 + 100(10) = 500$.  Since $t$ represents the number of seconds since lift-off and $h(t)$ is the height above the ground in feet, the equation $h(10) = 500$ means that $10$ seconds after lift-off, the model rocket is $500$ feet above the ground. To find $h(60)$, we note that $t=60$ satisfies $t > 20$, so we use the rule $h(t) = 0$.  This function returns a value of $0$ regardless of what value is substituted in for $t$, so $h(60) = 0$.  This means that $60$ seconds after lift-off, the rocket is $0$ feet above the ground;  in other words, a minute after lift-off, the rocket has already returned to Earth.\r\n\r\n\\item Since the function $h$ is defined in pieces, we need to solve $h(t) = 375$ in pieces.  For $0 \\leq t \\leq 20$, $h(t) =  -5t^2 + 100t$, so for these values of $t$, we solve $-5t^2 + 100t = 375$.  Rearranging terms, we get $5t^2 - 100t + 375 = 0$, and factoring gives $5(t-5)(t-15) = 0$. Our answers are  $t=5$ and $t=15$, and since both of these values of $t$ lie between $0$ and $20$, we keep both solutions.  For $t>20$, $h(t) = 0$, and in this case, there are no solutions to $0=375$.  In terms of the model rocket,  solving $h(t) = 375$ corresponds to finding when, if ever, the rocket reaches $375$ feet above the ground. Our two answers, $t=5$ and $t=15$ correspond to the rocket reaching this altitude \\textit{twice} -- once $5$ seconds after launch, and again $15$ seconds after launch.\r\n\\end{enumerate}\r\n\\end{solution}\t\r\n\r\nThe type of function in the previous example is called a \\textbf{piecewise-defined} function, or `piecewise' function for short.  Many real-world phenomena (e.g. postal rates, income tax formulas are modeled by such functions.  \r\n\r\nHere is another example where the domain of a function is restricted. For example, if $y$ is the area of a\r\nsquare of side $x$, then we can write $f(x)=x^2$.  In a purely\r\nmathematical context the domain of the function $y=x^2$ is all of\r\n$\\mathbb{R}$. However, in the story-problem context of finding areas of squares,\r\nwe restrict the domain to positive values of $x$, because a square\r\nwith negative or zero side makes no sense.\r\n\r\nIn pure mathematics, we usually take the domain to be all\r\nvalues of $x$ at which the formulas can be evaluated. However, in\r\na physical application problem there might be further restrictions on the domain\r\nbecause only certain values of $x$ are of interest or make practical\r\nphysical sense. For example, the volume $V$ of a sphere is given by the formula $V(r)=\\frac{4}{3}\\pi r^3$ where $r$ is the radius of the sphere. The domain of $V$ is all $r \\geq 0$, since it makes no sense to have a negative radius.\\\\ \r\n\r\n\r\n%Also, letters different from $f$ may be used.  For example, if $y$ is\r\n%the velocity of something at time $t$, we may write $y=v(t)$ with\r\n%the letter $v$ (instead of $f$) standing for the velocity function (and\r\n%$t$ playing the role of $x$).\r\n%\r\n%The letter playing the role of $x$ is called the \\dfont{independent\r\n%variable}, and the letter playing the role of $y$ is called the\r\n%\\dfont{dependent variable} (because its\r\n%value ``depends on'' the value of the independent\r\n%variable).  In story problems, when one has to translate from English \r\n%into mathematics, a crucial step is to\r\n%determine what letters stand for variables.  If only words and no\r\n%letters are given, then we have to decide which letters to use.  Some\r\n%letters are traditional.  For example, almost always, $t$ stands for\r\n%time.\r\n%\r\n\\begin{example}{Open Box}{openbox} \r\nAn open-top box is made from an $a\\times b$ rectangular piece of\r\ncardboard by cutting out a square of side $x$ from each of the four\r\ncorners, and then folding the sides up and sealing them with duct\r\ntape.  Find a formula for the volume $V$ of the box as a function of\r\n$x$, and find the domain of this function.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\n\t\r\n\\begin{wrapfigure}{r}{0.4\\textwidth}\r\n\t\\begin{center}\r\n\t\t\\includegraphics[width=0.38\\textwidth]{images/openbox}\r\n\t\\end{center}\r\n\t\\caption{}\r\n\\end{wrapfigure}\t\r\n\t\r\nThe box we get will have height $x$ and rectangular base of\r\ndimensions $a-2x$ by $b-2x$.  Thus, \r\n$$V(x)=x(a-2x)(b-2x)$$\r\nHere $a$ and $b$ are constants, and $V$ is the variable that depends\r\non $x$, i.e., $V$ is playing the role of $y$.  \r\n\r\nThis formula makes mathematical sense for any $x$, but in the physical\r\nproblem the domain is much less.  In the first place, $x$ must be\r\npositive.  In the second place, it must be less than half the length\r\nof either of the sides of the cardboard.  Thus, the domain is\r\n$$\\left\\{x\\in\\mathbb{R}\\,\\ssep\\,0<x<{\\frac{1}{2}}(\\hbox{minimum~of~$a$~and~$b$})\\right\\}.$$\r\nIn interval notation we write: the domain is the interval\r\n$(0,\\min(a,b)/2)$. You might think about whether we could allow 0 or \r\n(the minimum~of~$a$~and~$b$) to be in the domain. They make a certain\r\nphysical sense, though we normally would not call the result a box. If we\r\nwere to allow these values, what would be the corresponding volumes?\r\nDoes that volume make sense?\r\n\r\n\r\n\r\n\\end{solution}\r\n\r\n\r\n\r\n\\begin{example}{Circles and function}{circle}\r\n\tCan a circle of radius $r$ centered at the origin be expressed as a function? \r\n\t\r\n\\end{example}\r\n\r\n\\begin{solution} \r\n\tThe equation of a circle of radius $r$ centered at the origin is usually given in the form\r\n\t$x^2+y^2=r^2$.  To write the equation in the form $y=f(x)$ we solve\r\n\tfor $y$, obtaining $y=\\pm\\sqrt{r^2-x^2}$.  But {\\it this is not a\r\n\t\tfunction}, because when we substitute a value in $(-r,r)$ for $x$\r\n\tthere are two corresponding values of $y$.  To get a function, we must\r\n\tchoose one of the two signs in front of the square root.  If we choose\r\n\tthe positive sign, for example, we get the upper semicircle\r\n\t$f(x)=\\sqrt{r^2- x^2}$ (see Figure~\\ref{fig:upper semicircle}).  The\r\n\tdomain of this function is the interval $[-r,r]$, i.e., $x$ must be\r\n\tbetween $-r$ and $r$ (including the endpoints). \r\n\tIf $x$ is outside of\r\n\tthat interval, then $r^2-x^2$ is negative, and we cannot take the\r\n\tsquare root.  In terms of the graph, this just means that there are no\r\n\tpoints on the curve whose $x$-coordinate is greater than $r$ or less\r\n\tthan $-r$.\r\n\t\r\n\t\\figure[!ht]\r\n\t\\centerline{\\vbox{\\beginpicture\r\n\t\t\t\\normalgraphs\r\n\t\t\t%\\ninepoint\r\n\t\t\t\\setcoordinatesystem units <0.5truein,0.5truein>\r\n\t\t\t\\setplotarea x from -3.1 to 3.1, y from 0 to 3.1\r\n\t\t\t\\axis bottom ticks withvalues {$-r$} {$r$} / at -3 3 / /\r\n\t\t\t\\axis left shiftedto x=0 /\r\n\t\t\t\\circulararc 180 degrees from 3 0 center at 0 0\r\n\t\t\t\\endpicture}}\r\n\t\\caption{Upper semicircle $f(x)=\\sqrt{r^2- x^2}$. \\label{fig:upper semicircle}}\r\n\t\\endfigure\r\n\t\r\n\\end{solution}\r\n\r\n\r\nA function does not always have to be given by a single formula as the next example demonstrates.\r\n\r\n\\begin{example}{Piecewise Velocity}{PiecewiseVelocityExample}\r\nSuppose that $v(t)$ is the velocity function for a car\r\nwhich starts out from rest (zero velocity) at time $t=0$; then\r\nincreases its speed steadily to 20 m/sec, taking 10 seconds to do\r\nthis; then travels at constant speed 20 m/sec for 15 seconds; and\r\nfinally applies the brakes to decrease speed steadily to 0, taking 5\r\nseconds to do this. Express the velocity of the car as a function of time $t$.  \r\n\\end{example}\r\n\r\n\\begin{solution}\r\n\tThe formula for $v(t)$ is different in each of\r\n\tthe three time intervals.  \\\\\r\n\t\r\n\\begin{minipage}{0.3\\textwidth}\r\n\tFor $0 \\leq t \\leq 10$: \\\\\r\n\t\r\n\t\\vspace{-4mm}\r\n\\hspace{1cm} \t$\\begin{array}{c|c} \r\n\t\tt & v \\\\ \\hline\r\n\t\t0 & 0 \\\\\r\n\t\t10 & 20 \\\\\r\n\\end{array}$\r\n\r\nrepresented by $v(t)=2t$ \r\n\\end{minipage}\r\n\\begin{minipage}{0.3\\textwidth}\r\nFor $10 \\leq t \\leq 25$: \\\\\r\n\r\n\\vspace{-4mm}\r\n\\hspace{1cm} $\\begin{array}{c|c} \r\nt & v \\\\ \\hline\r\n10 & 20 \\\\\r\n25 & 20 \\\\\r\n\\end{array}$\r\n\r\nrepresented by $v(t)=20$ \r\n\\end{minipage}\r\n\\begin{minipage}{0.35\\textwidth}\r\n\tFor $25 \\leq t \\leq 30$: \\\\\r\n\t\r\n\t\\vspace{-4mm} \r\n\\hspace{1cm}\t$\\begin{array}{c|c} \r\n\tt & v \\\\ \\hline\r\n\t25 & 20 \\\\\r\n\t30 & 0 \\\\\r\n\t\\end{array}$\r\n\t\r\nrepresented by $v(t)=-4t+120$\r\n\t\\end{minipage}\t\r\n\t\r\n\t\r\n\\vspace{2mm} \t\r\n The velocity of the car  can be expressed as the following piecewise function \r\n\r\n\\vspace{-0.5cm}\r\n\\begin{minipage}{0.5\\textwidth}\t\r\n\\hspace{1cm} $\\displaystyle{ v(t) = \\left\\{ \\begin{array}{cl}\r\n\t2t, & 0 \\leq t \\leq 10 \\\\\r\n\t20, & 10 \\leq t \\leq 25 \\\\\r\n\t-4t+120, & 25 \\leq t \\leq 30 \\\\\r\n\t\\end{array} \\right.}$\t\\\\\r\n\t\r\nThe graph of this function is shown in Figure~\\ref{fig:piecewise velocity}.\r\n\r\n\\vspace{5mm}\r\n\\end{minipage}\r\n\\begin{minipage}{0.5\\textwidth}\t\r\n\t\r\n\\begin{figure}[H]\r\n\t$$\\includegraphics[scale=0.3]{images/Velocity}$$\r\n\t\\caption{ \\label{fig:piecewise velocity} } \r\n\\end{figure} \t\t\r\n\r\n%\\figure[!h]\r\n%\\centerline{\\vbox{\\beginpicture\r\n%\\normalgraphs\r\n%%\\ninepoint\r\n%\\setcoordinatesystem units <4truemm,2truemm>\r\n%\\setplotarea x from 0 to 31, y from 0 to 22\r\n%\\axis bottom ticks withvalues {$10$} {$25$} {$30$} / at 10 25 30 / /\r\n%\\axis left ticks numbered from 0 to 20 by 10 /\r\n%\\plot 0 0 10 20 25 20 30 0 /\r\n%\\put {$t$} [l] <3pt,0pt> at 31 0\r\n%\\put {$v$} [b] <0pt,3pt> at 0 22\r\n%\\endpicture}}\r\n%\\caption{A velocity function. \\label{fig:piecewise velocity}}\r\n%\\endfigure\r\n\r\n\\end{minipage} \r\n\r\n\\end{solution}\r\n\t\r\n\\pagebreak\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for \\ref{sec:Functions}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n\\begin{multicols}{2}\r\n%%%%%%%%%\r\n\\begin{ex}\r\nDetermine whether each curve represents a function. \\\\\r\n\r\n\\vspace{-1.3cm}\r\n$$\\includegraphics[scale=0.25]{images/ExFN3}$$\t\r\n\r\n\\begin{sol}\r\n\tUsing the Vertical Line Test,\r\n\t(A) function, \\hspace{3mm} (B) not a function, \\hspace{3mm} (C) not a function, \\hspace{3mm} (D) function, \\hspace{3mm} (E) function, \\hspace{3mm} (F) not a function. \t\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nDetermine whether or not the equation represents $y$ as a function of $x$.\\\\\r\n\r\n\\begin{multicols}{2}\r\n\t\\begin{enumerate}\r\n\t\t\\item $y = x^{3} - x$ \r\n\t\t\\item $y = \\sqrt{x - 2}$\r\n\t\t\\item $x^{3}y = -4$ \r\n\t\t\\item $x^{2} - y^{2} = 1$\r\n\t\t\\item $y = \\dfrac{x}{x^{2} - 9}$\r\n\t\t\\item $x = -6$\r\n\t\t\\item  $x = y^2 + 4$\r\n\t\t\\item $y = x^2 + 4$\r\n\t\t\\item $x^2 + y^2 = 4$\r\n\t\t\\item $y = \\sqrt{4-x^2}$\r\n\t\t\\item $x^2 - y^2 = 4$\r\n\t\t\\item $x^3 + y^3 = 4$\r\n\t\t\\item $2x + 3y = 4$\r\n\t\t\\item $2xy = 4$\r\n\t\t\\item $x^2 = y^2$ \r\n\t\t\\end{enumerate} \r\n\\end{multicols}\r\n\\begin{sol}\r\n\\begin{multicols}{2}\r\n\t\\begin{enumerate}\r\n\t\t\\item $y = x^{3} - x$  function\r\n\t\t\\item $y = \\sqrt{x - 2}$ function\r\n\t\t\\item $x^{3}y = -4$  function\r\n\t\t\\item $x^{2} - y^{2} = 1$ not a function\r\n\t\t\\item $y = \\dfrac{x}{x^{2} - 9}$ function\r\n\t\t\\item $x = -6$ not a function\r\n\t\t\\item  $x = y^2 + 4$ not a function\r\n\t\t\\item $y = x^2 + 4$ function\r\n\t\t\\item $x^2 + y^2 = 4$ not a function\r\n\t\t\\item $y = \\sqrt{4-x^2}$ function\r\n\t\t\\item $x^2 - y^2 = 4$not a function\r\n\t\t\\item $x^3 + y^3 = 4$ function\r\n\t\t\\item $2x + 3y = 4$ function\r\n\t\t\\item $2xy = 4$ function \r\n\t\t\\item $x^2 = y^2$ not a function \r\n\t\\end{enumerate} \r\n\\end{multicols} \t\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\t\r\n\t\r\n\t\r\n%%%%%%%%%%%%%%%\r\n\\begin{ex}\r\nIf $\\,\\, f(x) = \\sqrt{x-4}-3x \\,\\,$, find \\\\\r\n$f(-4)\\, , \\,\\, f(4) \\, , \\, \\text{and} \\,\\, f(8)$. \r\n\r\n\\begin{sol}\r\n\t$f(-4)$ is undefined, \\hspace{3mm} $f(4)=-12$, \\hspace{3mm} $f(8)=-22$\r\n\\end{sol} \t\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nIf $\\displaystyle{f(x)=2x^{2}-3x+2}$, find the following. \\\\\r\n\r\n\\begin{tabular}{lll}\r\n(a) $f(2)$ & \\hspace{2mm} (b) $f(-2)$ & \\hspace{2mm} (c) $f(a)$  \\\\\r\n&& \\\\ \r\n(d)  $f(-a)$ & \\hspace{2mm} (e) $f(a+1)$ & \\hspace{2mm} (f) $f(2a)$ \\\\\r\n&& \\\\ \r\n(g) $2f(a)$ & \\hspace{2mm} (h) $\\displaystyle{\\left[ f(a) \\right]^{2}}$ & \\hspace{2mm} (i) $f(a+h)$ \\\\\r\n\\end{tabular}\r\n\r\n\\begin{sol}\r\n\\begin{tabular}{ll}\r\n(a) $f(2)=6$ & (b) $f(-2)=16$ \\\\\r\n(c) $f(a)=2a^{2}-3a+2$  & (d)  $f(-a)=2a^{2}+3a+2$ \\\\\r\n(e) $f(a+1)=2a^{2}+a+1$ & (f) $f(2a)=8a^{2}-6x+2$ \\\\\r\n(g) $2f(a)=4x^{2}-6x+4$ & (h) $\\displaystyle{\\left[ f(a) \\right]^{2}=4x^{4}-12x^{3}+17x^{2}-12x+4}$ \\\\\r\n(i) $f(a+h)=2a^{2}+4ah+2h^{2}-3a-3h+2$ & \\\\\r\n\\end{tabular} \r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\begin{ex}\r\nUse the given function $f$ to find and simplify the following:\\\\\r\n \\begin{multicols}{3}\r\n\t\\begin{itemize}\r\n\t\t\\item  $f(2)$\r\n\t\t\\item  $f(-2)$\r\n\t\t\\item  $f(2a)$\r\n\t\t\\item  $2 f(a)$\r\n\t\t\\item $f(a+2)$\r\n\t\t\\item  $\\displaystyle{f \\left( \\frac{2}{a} \\right)}$\r\n\t\t\\item $\\displaystyle{\\frac{f(a)}{2}}$\r\n\t\t\\item  $f(a + h)$\r\n\t\t\\item $\\displaystyle{f(a) + f(2)}$\r\n\t\\end{itemize}\r\n\\end{multicols}\r\n\r\n\\begin{multicols}{2}\r\n\t(a) \\hspace{2mm}  $f(x) = 2x-5$ \\\\\r\n\t\\\\\r\n    (b) \\hspace{2mm} $f(x) = 5-2x$\t\\\\\r\n    \\\\\r\n    (c) \\hspace{2mm} $f(x) = 2x^2 - 1$\\\\\r\n    \\\\\r\n    (d) \\hspace{2mm} $f(x) = \\dfrac{2}{x}$ \\\\\r\n    \\\\ \r\n\t(e) \\hspace{2mm} $\\displaystyle{f(x) = 3x^2+3x-2}$\\\\\r\n\t\\\\\r\n\t(f) \\hspace{2mm}  $f(x) = \\sqrt{2x+1}$\\\\\r\n\t\\\\\r\n\t(g) \\hspace{2mm} $f(x) = -7$\\\\\r\n\t\\\\\r\n\t(h) \\hspace{2mm}  $f(x) = \\dfrac{x}{2}$\\\\\r\n\\end{multicols}\r\n\\begin{sol}\r\n(a) \\hspace{2mm} For $f(x) = 2x-5$ \\\\\r\n$f(2) = -1$\\\\\r\n$f(-2) = -9$\\\\\r\n$f(2a) = 4a-5$\t\\\\\r\n$2 f(a) = 4a-10$\\\\\r\n$f(a+2) = 2a-1$\\\\\r\n$f(a) + f(2) = 2a-6$\\\\\t\r\n$f \\left( \\frac{2}{a} \\right) = \\frac{4}{a} - 5$ \\\\\r\n$\\hphantom{f \\left( \\frac{2}{a} \\right)} = \\frac{4-5a}{a}$\\\\\r\n$\\frac{f(a)}{2} =\\frac{2a-5}{2}$\\\\\r\n$f(a + h) = 2a + 2h - 5$\\\\\r\n\t\t\r\n\\vspace{3mm}\t\r\n\r\n(b) \\space{2mm} For $f(x) = 5-2x$\\\\\r\n$f(2) = 1$\\\\\r\n$f(-2) = 9$\\\\\r\n$f(2a) = 5-4a$\t\\\\\r\n$2 f(a) = 10-4a$\\\\\r\n$f(a+2) = 1-2a$\\\\\r\n$f(a) + f(2) = 6-2a$\\\\\r\n$f \\left( \\frac{2}{a} \\right) = 5 - \\frac{4}{a}$ \\\\\r\n$\\hphantom{f \\left( \\frac{2}{a} \\right)} = \\frac{5a-4}{a}$\\\\\r\n$\\frac{f(a)}{2} = \\frac{5-2a}{2}$\\\\\r\n$f(a + h) = 5-2a-2h$\\\\\r\n\r\n\\vspace{3mm} \r\n\r\n(c) \\hspace{2mm} For $f(x) = 2x^2-1$\\\\\r\n$f(2) = 7$\\\\\r\n$f(-2) = 7$\\\\\r\n$2 f(a) = 4a^2-2$\\\\\r\n$f(a+2) = 2a^2+8a+7$\\\\\r\n$f(a) + f(2) = 2a^2+6$\\\\\r\n$f \\left( \\frac{2}{a} \\right) = \\frac{8}{a^2} - 1$ \\\\\r\n$\\hphantom{f \\left( \\frac{2}{a} \\right)} = \\frac{8-a^2}{a^2}$\\\\\r\n$\\frac{f(a)}{2} =  \\frac{2a^2-1}{2}$\\\\\r\n$f(a + h) = 2a^2+4ah+2h^2-1$\\\\\r\n\t\t\r\n\\vspace{2mm}\r\n\r\n(d) \\hspace{2mm} For $f(x) = 3x^2+3x-2$\\\\\r\n$f(2) = 16$\\\\\r\n$f(-2) = 4$\\\\\r\n$f(2a) = 12a^2+6a-2$\\\\\r\n$2 f(a) = 6a^2+6a-4$\\\\\r\n$f(a+2) = 3a^2+15a+16$\\\\\r\n\\small $f(a) + f(2) = 3a^2+3a+14$ \\normalsize\\\\\r\n$f \\left( \\frac{2}{a} \\right) = \\frac{12}{a^2} + \\frac{6}{a} - 2$ \\\\\r\n$\\hphantom{f \\left( \\frac{2}{a} \\right)} = \\frac{12+6a-2a^2}{a^2}$\\\\\r\n$\\frac{f(a)}{2} =  \\frac{3a^2+3a-2}{2}$\\\\\r\n$f(a + h) = 3a^2 + 6ah + 3h^2+3a+3h-2$\\\\\r\n\t\t\r\n\\vspace{3mm}\t\r\n\r\n(e) \\hspace{2mm} For $f(x) = \\sqrt{2x+1}$\\\\\r\n$f(2) = \\sqrt{5}$\\\\\r\n$f(-2)$ is not real \\\\\r\n$f(2a) = \\sqrt{4a+1}$\\\\\r\n$2 f(a) = 2\\sqrt{2a+1}$\\\\\r\n$f(a+2) = \\sqrt{2a+5}$\\\\\r\n\\small $f(a) + f(2) =\\sqrt{2a+1} + \\sqrt{5}$ \\normalsize\\\\\r\n$f \\left( \\frac{2}{a} \\right) = \\sqrt{\\frac{4}{a} + 1}$ \\\\\r\n$\\hphantom{f \\left( \\frac{2}{a} \\right)} = \\sqrt{\\frac{a+4}{a}}$\\\\\r\n$\\frac{f(a)}{2} = \\frac{\\sqrt{2a+1}}{2}$\\\\\r\n$f(a + h) = \\sqrt{2a+2h+1}$\\\\\r\n\r\n\\vspace{3mm} \r\n\t\r\n(f) \\hspace{2mm}  For $f(x) = -7$\\\\\r\n$f(2) = -7$\\\\\r\n$f(-2) = -7$\\\\\r\n$f(2a) = -7$\\\\\r\n$2 f(a) = -14$\\\\\r\n$f(a+2) = -7$\\\\\r\n$f(a) + f(2) = -14$\\\\\r\n$f \\left( \\frac{2}{a} \\right) = -7$ \\\\\r\n$\\frac{f(a)}{2} = \\frac{-7}{2}$\\\\\r\n$f(a + h) = -7$\\\\\r\n\r\n\\vspace{3mm}\r\n\r\nFor $f(x) = \\frac{x}{2}$\\\\\r\n$f(2) = 1$\\\\\r\n$f(-2) = -1$\\\\\r\n$f(2a) = a$\\\\\r\n$2 f(a) = a$\\\\\r\n$f(a+2) = \\frac{a+2}{2}$\\\\\r\n$f(a) + f(2) = \\frac{a}{2}+ 1$ \\\\\r\n$\\hphantom{f(a) + f(2)} = \\frac{a+2}{2}$\\\\\r\n$f \\left( \\frac{2}{a} \\right) = \\frac{1}{a}$\\\\\r\n$\\frac{f(a)}{2} =  \\frac{a}{4}$\\\\\r\n$f(a + h) = \\frac{a+h}{2}$\\\\\r\n\t\t\r\n\\vspace{3mm}\t\r\n\r\n(g) For $f(x) = \\frac{2}{x}$\\\\\r\n$f(2) = 1$\\\\\r\n$f(-2) = -1$\\\\\r\n$f(2a) = \\frac{1}{a}$\\\\\r\n$2 f(a) = \\frac{4}{a}$\\\\\r\n$f(a+2) = \\frac{2}{a+2}$\\\\\r\n$f(a) + f(2) = \\frac{2}{a}+1$ \\\\\r\n$\\hphantom{f(a)+f(2)}=\\frac{a+2}{2}$\\\\\r\n$f \\left( \\frac{2}{a} \\right) = a$\\\\\r\n$\\frac{f(a)}{2} =  \\frac{1}{a}$\\\\\r\n$f(a + h) = \\frac{2}{a+h}$\\\\\r\n\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\r\n\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%\r\n\\begin{ex}\r\nAn on-line comic book retailer charges shipping costs according to the following formula \\[{\\displaystyle S(n) = \\left\\{ \\begin{array}{rcl}  1.5 n + 2.,5 &  & 1 \\leq n \\leq 14  \\\\\r\n\t0,  & & n \\geq 15\r\n\t\\end{array} \\right. }\\]\r\n\r\nwhere $n$ is the number of  comic books purchased and $S(n)$ is the shipping cost in dollars.\r\n\r\n\\begin{enumerate}\r\n\t\r\n\t\\item  What is the cost to ship 10 comic books?  %  Ans:  $S(10) = 17.5$, $\\$ 17.50$.\r\n\t\r\n\t\\item  What is the significance of the formula $S(n) = 0$ for $n \\geq 15$?   % Ans:  There is free shipping on orders of $15$ or more comic books. \r\n\\end{enumerate} \t\t\r\n\t\t\r\n\\begin{sol}\r\n(a) \\hspace{2mm} $S(10) = 17.5$, so it costs $\\$ 17.50$ to ship 10 comic books. \\\\\r\n(b) \\hspace{2mm} There is free shipping on orders of $15$ or more comic books. \\\\\r\n\t\t\t\r\n\\end{sol}\t\r\n\\end{ex}\r\n\t\r\n\t\r\n%%%%%%%%%%%%%%%%%%%%%%%\r\n\\begin{ex}\r\nThe cost $C$ (in dollars) to talk $m$ minutes a month on a mobile phone plan is modeled by   \\[{\\displaystyle C(m) = \\left\\{ \\begin{array}{rcl} 25, & & 0 \\leq m \\leq 1000 \\\\\r\n\t25+0.1(m-1000), &  & m > 1000\r\n\t\\end{array} \\right. }\\]\r\n\r\n\\begin{enumerate}\r\n\t\r\n\t\\item  How much does it cost to talk $750$ minutes per month with this plan?  % Ans:  $C(750) = 25$, $\\$ 25$.\r\n\t\r\n\t\\item  How much does it cost to talk $20$ hours a month with this plan?  % Ans:  $C(1200) = 45$, $\\$ 45$. \r\n\t\r\n\t\\item  Explain the terms of the plan verbally.  % Ans:  It costs $\\$25$ for up to $1000$ minutes and $10$ cents per minute for each minute over $1000$ minutes.\r\n\t\r\n\\end{enumerate}\t\r\n\\begin{sol}\r\n\t\r\n(a) \\hspace{2mm} $C(750) = 25$, so it costs $\\$ 25$ to talk 750 minutes per month with this plan. \\\\\r\n\r\n(b) \\hspace{2mm} Since $20 \\, \\text{hours} = 1200 \\, \\text{minutes}$, we substitute $m = 1200$ and get  $C(1200) = 45$.  It costs $\\$ 45$ to talk 20 hours per month with this plan. \\\\ \r\n\r\n(c) \\hspace{2mm}  It costs $\\$25$ for up to $1000$ minutes and $10$ cents per minute for each minute over $1000$ minutes.\r\n\r\n\t\r\n\\end{sol}\t\t\r\n\\end{ex}\r\n\t\t\r\n\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\begin{ex}\r\nFind the domain of each of the following functions:\r\n\r\n\\begin{tabular}{ll}\r\n\t(a)\t$\\ds f(x)=x^2+1$ & (b)\t$\\ds f(x)=\\sqrt{2x-3}$ \\\\\r\n\t& \\\\ [0em]\r\n\t(c) $\\ds g(x)=\\frac{1}{x+1}$ & (d) $\\ds y=\\frac{1}{x^2-1}$ \\\\\r\n\t& \\\\ [0em]\r\n\t(e) $\\ds f(x)=\\sqrt{\\frac{-1}{x}}$ & (f) $\\ds g(t)={\\root 3 \\of t}$ \\\\\r\n\t& \\\\ [0em]\r\n\t(g) $\\ds f(x)=\\frac{x+4}{x^{2}-9}$ & (h) $\\ds y=\\sqrt{1-x^2}$ \\\\\r\n\t& \\\\ [0em]\r\n\t(i) $\\ds y=\\sqrt{1-\\frac{1}{x} }$ & (j) $\\ds h(x)=\\frac{1}{\\sqrt{1-(3x)^2}}$ \\\\\r\n\t& \\\\ [0em]\r\n\t(k) $\\ds f(s)=\\sqrt{s}+\\frac{1}{s-1}$ & (l) $\\ds f(x)=\\frac{1}{\\sqrt{x}-1}$ \\\\\r\n\t& \\\\ [0em]\r\n\t(m) $\\ds y=\\frac{\\sqrt{2x-1}}{x^{2}-x}$ & (n)  $\\ds y=\\frac{\\sin x}{\\sqrt{2x-1}}$\r\n\\end{tabular}\r\n\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\t\\item\t$\\ds \\{x\\mid x\\in \\R\\}$, i.e., all $x$\r\n\t\\item\t$\\ds \\{x\\mid x\\ge 3/2\\}$\r\n\t\\item\t$\\ds \\{x\\mid x\\not=-1\\}$\r\n\t\\item\t$\\ds \\{x\\mid x\\not=1 \\hbox{ and } x\\not=-1\\}$\r\n\t\\item\t$\\ds \\{x\\mid x<0\\}$\r\n\t\\item\t$\\ds \\{t\\mid t\\in \\R\\}$, i.e., all $t$\r\n\t\\item\t$\\ds \\{x\\mid x\\not \\pm 3\\}$\r\n\t\\item\t$\\ds \\{x\\mid -1\\le x\\le 1\\}$\r\n\t\\item\t$\\ds \\{x\\mid x\\ge 1\\}$\r\n\t\\item\t$\\ds \\{x\\mid -1/3< x< 1/3\\}$\r\n\t\\item\t$\\ds \\{s\\mid s\\ge0  \\hbox{ and } s\\not=1\\}$\r\n\t\\item\t$\\ds \\{x\\mid x\\ge0  \\hbox{ and } x\\not=1\\}$\r\n\t\\item  $\\ds \\{x\\mid x\\not=0,\\, 1\\}$\r\n\t\\item  $\\ds \\{x\\mid x> 1/2\\}$\r\n\\end{enumerate}\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%\r\n\\begin{ex}\r\nFind the (implied) domain of the function.\r\n\r\n\r\n%\\begin{multicols}{2}\r\n(a) \\hspace{2mm}  $f(x) = x^{4} - 13x^{3}  - 19$ \\\\\r\n\\\\\r\n(b) \\hspace{2mm}  $f(x) = x^2 + 4$\\\\\r\n\t\\\\\t\r\n(c) \\hspace{2mm}\t$f(x) = \\dfrac{x-2}{x+1}$\\\\\r\n\\\\\r\n(d) \\hspace{2mm} $f(x) = \\dfrac{3x}{x^2+x-2}$\\\\\r\n\\\\\r\n(e) \\hspace{2mm}  $f(x) = \\dfrac{2x}{x^2+3}$\\\\\r\n\\\\\r\n(f) \\hspace{2mm} $f(x) = \\dfrac{2x}{x^2-3}$\\\\\r\n\\\\\r\n(g) \\hspace{2mm}  $f(x) = \\dfrac{x+4}{x^2 - 36}$\\\\\r\n\\\\\r\n(h) \\hspace{2mm} $f(x) = \\dfrac{x-2}{x-2}$  \\\\\r\n\\\\\r\n(i) \\hspace{2mm}  $f(x) = \\sqrt{3-x}$\\\\\r\n\\\\\r\n(j) \\hspace{2mm} $f(x) = \\sqrt{2x+5}$  \\\\\r\n\\\\\r\n(k) \\hspace{2mm} $f(x) = 9x\\sqrt{x+3}$\\\\\r\n\\\\\r\n(l) \\hspace{2mm} $f(x) = \\dfrac{\\sqrt{7-x}}{x^2+1}$  \\\\\r\n\\\\\r\n(m) \\hspace{2mm} $f(x) = \\sqrt{6x-2}$\\\\\r\n\\\\\r\n(n) \\hspace{2mm} $f(x) = \\dfrac{6}{\\sqrt{6x-2}}$\\\\\r\n\\\\\r\n(o) \\hspace{2mm}  $f(x) = \\sqrt[3]{6x-2}$\\\\\r\n\\\\\r\n(p) \\hspace{2mm} $f(x) = \\dfrac{6}{4 - \\sqrt{6x-2}}$\\\\\r\n\\\\\r\n(q) \\hspace{2mm}  $f(x) = \\dfrac{\\sqrt{6x-2}}{x^2-36}$\\\\\r\n\\\\\r\n(r) \\hspace{2mm} $f(x) = \\dfrac{\\sqrt[3]{6x-2}}{x^2+36}$\\\\\r\n\\\\\r\n(s) \\hspace{2mm}  $s(t) = \\dfrac{t}{t - 8}$\\\\\r\n\\\\\r\n(t) \\hspace{2mm} $Q(r) = \\dfrac{\\sqrt{r}}{r - 8}$\\\\\r\n\\\\\r\n(u) \\hspace{2mm}  $b(\\theta) = \\dfrac{\\theta}{\\sqrt{\\theta - 8}}$\\\\\r\n\\\\\r\n(v) \\hspace{2mm} $A(x) = \\sqrt{x - 7} + \\sqrt{9 - x}$\\\\\r\n\\\\\r\n(w) \\hspace{2mm} $\\alpha(y) = \\sqrt[3]{\\dfrac{y}{y - 8}}$\\\\\r\n\\\\\r\n(x) \\hspace{2mm} $g(v) = \\dfrac{1}{4 - \\dfrac{1}{v^{2}}}$\\\\\r\n\\\\\r\n(y) \\hspace{2mm}  $T(t) = \\dfrac{\\sqrt{t} - 8}{5-t}$ \\\\\r\n\\\\\r\n(z) \\hspace{2mm} $u(w) = \\dfrac{w - 8}{5 - \\sqrt{w}}$ \\\\\r\n%\\end{multicols} \t\r\n\\begin{sol}\r\n\\begin{multicols}{2}\r\n\t\\begin{enumerate}\r\n\t\t\\item $(-\\infty, \\infty)$\r\n\t\t\\item  $(-\\infty, \\infty)$\r\n\t\t\\item $(-\\infty, -1) \\cup (-1, \\infty)$\r\n\t\t\\item  $(-\\infty,-2) \\cup (-2,1) \\cup (1, \\infty)$\r\n\t\t\\item $(-\\infty, \\infty)$\r\n\t\t\\item  $(-\\infty, -\\sqrt{3}) \\cup (-\\sqrt{3}, \\sqrt{3}) \\cup (\\sqrt{3}, \\infty)$\r\n\t\t\\item  $(-\\infty, -6) \\cup (-6,6) \\cup (6, \\infty)$\r\n\t\t\\item $(-\\infty, 2) \\cup (2, \\infty)$\r\n\t\t\\item  $(-\\infty, 3]$\r\n\t\t\\item $\\left[-\\frac{5}{2}, \\infty \\right)$  \r\n\t\t\\item  $[-3, \\infty)$\r\n\t\t\\item $(-\\infty, 7]$  \r\n\t\t\\item    $\\left[ \\frac{1}{3}, \\infty \\right)$\r\n\t\t\\item   $\\left( \\frac{1}{3}, \\infty \\right)$\t\r\n\t\t\\item   $(-\\infty, \\infty)$\t\r\n\t\t\\item   $\\left[ \\frac{1}{3}, 3 \\right) \\cup (3, \\infty)$\r\n\t\t\\item  $\\left[ \\frac{1}{3}, 6 \\right) \\cup (6, \\infty)$\r\n\t\t\\item   $(-\\infty, \\infty)$\r\n\t\t\\item $(-\\infty, 8) \\cup (8, \\infty)$\r\n\t\t\\item $[0, 8) \\cup (8, \\infty)$\r\n\t\t\\item $(8, \\infty)$\r\n\t\t\\item $[7, 9]$\r\n\t\t\\item $(-\\infty, 8) \\cup (8, \\infty)$\r\n\t\t\\item $\\left( -\\infty, -\\frac{1}{2} \\right) \\cup \\left( -\\frac{1}{2}, 0 \\right) \\cup \\left(0, \\frac{1}{2}$ \r\n\t\t\\item $[0, 5) \\cup (5,\\infty)$\r\n\t\t\\item $[0, 25) \\cup (25, \\infty)$\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\r\n\\end{sol}\t\r\n\\end{ex}\r\n\t\r\n\t\r\n\r\n\r\n\r\n\r\n\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nA farmer wants to build a fence along a river.  He has\r\n500 feet of fencing and wants to enclose a rectangular pen on three\r\nsides (with the river providing the fourth side).  If $x$ is the\r\nlength of the side perpendicular to the river, determine the area of\r\nthe pen as a function of $x$.  What is the domain of this function?\r\n\\begin{sol}\r\n$A=x(500-2x)$, $\\ds \\{x\\mid 0\\le x\\le 250\\}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%\r\n\\begin{ex}\r\nA can in the shape of a cylinder is to be made with a total\r\nof 100 square centimeters of material in the side, top, and bottom;\r\nthe manufacturer wants the can to hold the maximum possible\r\nvolume. Write the volume as a function of the radius $r$ of the can;\r\nfind the domain of the function.\r\n\\begin{sol}\r\n$\\ds V=r(50-\\pi r^2)$, $\\ds \\{r\\mid 0< r\\le \\sqrt{50/\\pi}\\}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%\r\n\\begin{ex}\r\nA can in the shape of a cylinder is to be made to hold a\r\nvolume of one liter (1000 cubic centimeters). The manufacturer wants\r\nto use the least possible material for the can. Write the surface area\r\nof the can (total of the top, bottom, and side) as a function of the\r\nradius $r$ of the can; find the domain of the function.\r\n\\begin{sol}\r\n$\\ds A=2\\pi r^2+2000/r$, $\\ds \\{r\\mid 0<r<\\infty\\}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nSuppose that it cost $\\displaystyle{5 \\cents \\,}$ per minute to park at the airport with the rate dropping to $\\displaystyle{3 \\cents \\,}$ after $9$ $\\textsc{P.M.}$ Find and graph the cost function $c(t)$ for values of $t$ satisfying $0 \\leq t \\leq 120$. Assume that $t$ is the number of minutes after $8 \\, \\textsc{P.M.}$. \t\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nThe Canadian Federal tax rates for 2017 are shown in the following Table. \\\\\r\n\r\n(a) Write a piecewise definition for the tax due $T(x)$ on an income of $x$ dollars. \t\\\\\r\n(b) Find the tax due on a taxable income of $\\$100,000$. \\\\\r\n\r\n\\vspace{-1cm}\r\n$$\\includegraphics[scale=0.45]{images/piecwiseTaxBracket}$$\r\n\\end{ex}\r\n\r\n\r\n\\end{multicols}\r\n\r\n\\end{enumialphparenastyle}\r\n\r\n\\pagebreak\r\n", "meta": {"hexsha": "9e91f7bfd05775b99c4eee021cb759c193e833bc", "size": 48476, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2-functions/2-1-functions.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2-functions/2-1-functions.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2-functions/2-1-functions.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.1164205039, "max_line_length": 1990, "alphanum_fraction": 0.6096831422, "num_tokens": 18304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.8688267711434708, "lm_q1q2_score": 0.7041657812544142}}
{"text": "\\subsection{Average Precision}\n\\label{chp:fundamentals:sec:metrics:subsec:average_precision}\n\nDue to the previously mentioned trade-off between recall and precision both of those metrics should be considered when optimizing a model for a task.\nOne metric which considers recall as well as precision is \\ac{AP}.\n\n\\subsubsection{Definition}\n\\label{chp:fundamentals:sec:metrics:subsec:average_precision:definition}\n\n\\Textcite{Zhu:2004} defines it as the following:\n\n\\begin{equation}\\label{eq:average_precision}\n    AP = \\sum_{i=1}^n {p(i)\\Delta r(i)}\n\\end{equation}\n\nWhere $p(i)$ is the precision taking into account the first $i$ elements and $\\Delta r(i)$ indicates the the recall change from the $i-1$th to the $i$th item.\nWith this metric the order of the sequence is crucial.\nAn algorithm which manages to sort a sequence of elements in a way that all relevant items are listed first achieves higher AP than an algorithm which performs poorly on the sorting task.\n\nLet us consider the following example.\nAn algorithm was trained to return all relevant items from a dataset.\nGiven an unseen dataset of five items the model returns the following sorted sequence given in \\cref{fig:metrics:average_precision:sample}.\nThe sequence is sorted in descending order, meaning the elements which the algorithm classifies as relevant with most confidence, are inserted first.\nConsequently, in the example below the algorithm falsely classifies the second and fifth item as relevant.\n\n\\begin{figure}[htpb]\n    \\centering\n    \\def\\svgwidth{\\columnwidth}\n    \\input{figures/metrics/Average_Precision.pdf_tex}\n    \\caption[Example Sequence]{A sorted example sequence returned by some algorithm.}\\label{fig:metrics:average_precision:sample}\n\\end{figure}\n\nThe sequence shown in \\cref{fig:metrics:average_precision:sample} contains a total of three relevant items.\nFollowing \\textcite{Zhu:2004}, this yields a recall change $\\Delta r(i)=\\frac{1}{3}$ for a relevant item $i$ and $\\Delta r(i)=0$ for an irrelevant one.\nNow we can calculate the \\ac{AP} according to \\cref{eq:average_precision}:\n\\begin{equation}\n    \\begin{aligned}\n        AP &= \\sum_{i=1}^n {p(i)\\Delta r(i)}\\\\\n        &= \\frac{1}{1} \\cdot \\frac{1}{3} + \\frac{1}{2} \\cdot 0 + \\frac{2}{3} \\cdot \\frac{1}{3} + \\frac{3}{4} \\cdot \\frac{1}{3} + \\frac{3}{5} \\cdot 0\\\\\n        &=  (\\frac{1}{1} + \\frac{2}{3}  + \\frac{3}{4}) \\cdot \\frac{1}{3}\\\\\n        &\\approx 0.81\n    \\end{aligned}\n\\end{equation}\n\n\\subsubsection{Interpretation}\n\\label{chp:fundamentals:sec:metrics:subsec:average_precision:interpretation}\nThe overall interpretation of \\ac{AP} is intuitive: The more relevant items are ranked at the top of the returned sequence the higher is the \\ac{AP} value.\nHowever, in contrast to precision and recall, it is more difficult to judge whether the retrieved value for \\ac{AP} is \"good\" or \"bad\".\nShould we consider a system which yields $\\ac{AP}=0.66$ as good?\nIn this part we want to address this issue and provide a tangible interpretation of the \\ac{AP} value.\n\nFirst we want to take a look at different example sequences and their corresponding \\ac{AP} values.\nWe then derive an intuitive explanation for these example sequences which helps to judge \\ac{AP} in general.\nLet us consider two example sequences \\textit{sequence 1} and \\textit{sequence 2} shown in \\cref{fig:metrics:average_precision:interpreation:sample}.\n\n\\begin{figure}[htpb]\n    \\centering\n    \\def\\svgwidth{\\columnwidth}\n    \\input{figures/metrics/Average_Precision_Example.pdf_tex}\n    \\caption[Two Example Sequences]{Two example sequences taken from \\textcite{Tapaswi:2012}.}\\label{fig:metrics:average_precision:interpreation:sample}\n\\end{figure}\n\nFor the first sequence we observe that \\textit{every third} top ranked item is relevant whereas in the second sequence \\textit{every second} item is.\nWe can now calculate the \\ac{AP} for both sequences according to \\cref{eq:average_precision} which yields $\\ac{AP}_1= \\frac{1}{3}$ for the first sequence and $\\ac{AP}_2= \\frac{1}{2}$ for the second one.\nWith the sequences above and their corresponding \\acp{AP} $\\ac{AP}_1$ and $\\ac{AP}_2$ we can now conclude that an $\\ac{AP}=\\frac{1}{j}$ indicates that every $j$th item is relevant \\parencite{Tapaswi:2012}.\nWith this in mind an $\\ac{AP}=0.66$ is rather good, because approximately every $1.5$th item of the top ranked ones is relevant, whereas with an example $\\ac{AP}=0.2$ only every fifth item is relevant.\n", "meta": {"hexsha": "0bdc2afc8e172e32beb275a3d6fb4fc028770d48", "size": 4428, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/02_fundamentals/sections/metrics/subsections/average_precision.tex", "max_stars_repo_name": "HaaLeo/vague-requirements-thesis", "max_stars_repo_head_hexsha": "f9bb53c6f17c2cd1731531ad2a68dd53d72e52e9", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/02_fundamentals/sections/metrics/subsections/average_precision.tex", "max_issues_repo_name": "HaaLeo/vague-requirements-thesis", "max_issues_repo_head_hexsha": "f9bb53c6f17c2cd1731531ad2a68dd53d72e52e9", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/02_fundamentals/sections/metrics/subsections/average_precision.tex", "max_forks_repo_name": "HaaLeo/vague-requirements-thesis", "max_forks_repo_head_hexsha": "f9bb53c6f17c2cd1731531ad2a68dd53d72e52e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.0895522388, "max_line_length": 205, "alphanum_fraction": 0.7533875339, "num_tokens": 1200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7040185547886394}}
{"text": "\\section{Application: Perspective rendering}\n\nAs an application of linear transformations, we consider the problem\nof perspective rendering. Imagine some object has been described by\ncoordinates in 3-dimensional space, and we wish to make an image of\nthe object as it would be seen by a human eye or by a camera. The\nprocess of computing such an image is known as \\textbf{rendering}%\n\\index{rendering}.\n\nConceptually, the rendering process makes use of a \\textbf{camera}%\n\\index{camera}, which we will assume is located at the origin of a\n3-dimensional coordinate system called the \\textbf{camera coordinate\n  system}%\n\\index{camera coordinates}%\n\\index{coordinate system!camera coordinates}, and an \\textbf{image\n  plane}%\n\\index{image plane}%\n\\index{plane!image plane}, which we will assume is the plane $z=1$ in\ncamera coordinates. The 3-dimensional space also contains one or more\nobjects that we wish to render. We can consider the object to be\ndescribed by a set of points. For each point $\\vect{p}$ on the object,\nwe draw a straight line from $\\vect{p}$ to the camera, and let\n$\\vect{p}'$ be the point where this line intersects the image\nplane. The point $\\vect{p}$ of the object is rendered as the point\n$\\vect{p}'$ in the image. This process is illustrated in the following\nfigure:\n\\begin{equation*}\n  \\includegraphics[width=0.6\\textwidth]{figures/perspective-chair}\n\\end{equation*}\n\n% ----------------------------------------------------------------------\n\\subsection*{Object coordinates}\n\nIt is convenient to describe each object in its own coordinate system,\ncalled the \\textbf{object coordinate system}%\n\\index{object coordinates}%\n\\index{coordinate system!object coordinates}. To illustrate this\nconcept, we will consider a cube of side length 2, centered at the\norigin. The 8 corners of this cube have the following coordinates in\nthe object coordinate system:\n\\begin{equation*}\n  \\begin{mymatrix}{r}  1 \\\\ 1 \\\\ 1 \\end{mymatrix},~\n  \\begin{mymatrix}{r}  1 \\\\ 1 \\\\ -1 \\end{mymatrix},~\n  \\begin{mymatrix}{r}  1 \\\\ -1 \\\\ 1 \\end{mymatrix},~\n  \\begin{mymatrix}{r}  1 \\\\ -1 \\\\ -1 \\end{mymatrix},~\n  \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 1 \\end{mymatrix},~\n  \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ -1 \\end{mymatrix},~\n  \\begin{mymatrix}{r} -1 \\\\ -1 \\\\ 1 \\end{mymatrix},~\n  \\begin{mymatrix}{r} -1 \\\\ -1 \\\\ -1 \\end{mymatrix}.\n\\end{equation*}\nFor later reference, let us call this the \\textbf{standard cube}%\n\\index{standard cube}. The following picture shows the standard cube\nwithin its object coordinate system:\n\\begin{equation*}\n  \\begin{tikzpicture}[x={(0.8cm,-0.45cm)},y={(1cm,0.3cm)},z={(0cm,1.1cm)},scale=0.7]\n    \\draw[->] (-3,0,0) -- (3,0,0) node[right]{$y$};\n    \\draw[->] (0,3,0) -- (0,-3,0) node[left]{$x$};\n    \\draw[->] (0,0,-2.5) -- (0,0,2.5) node[right]{$z$};\n    \\begin{scope}\n      \\clip (1,1,1) -- (1,1,-1) -- (1,-1,-1) -- (-1,-1,-1)\n      -- (-1,-1,1) -- (-1,1,1) -- cycle;\n      \\fill[blue!3] (1,1,1) -- (1,1,-1) -- (1,-1,-1) -- (-1,-1,-1)\n      -- (-1,-1,1) -- (-1,1,1) -- cycle;\n      \\draw[black!30,->] (-3,0,0) -- (3,0,0);\n      \\draw[black!30,->] (0,-3,0) -- (0,3,0);\n      \\draw[black!30,->] (0,0,-2.5) -- (0,0,2.5);\n    \\end{scope}\n    \\draw[thick] ( 1, 1, 1) -- ( 1, 1,-1) -- ( 1,-1,-1) -- ( 1,-1, 1) -- cycle;\n    \\draw[thick] ( 1,-1, 1) -- (-1,-1, 1) -- (-1,-1,-1) -- ( 1,-1,-1) -- cycle;\n    \\draw[thick] ( 1, 1, 1) -- ( 1,-1, 1) -- (-1,-1, 1) -- (-1, 1, 1) -- cycle;\n    \\draw (1,0,0) -- (3,0,0);\n    \\draw (0,-3,0) -- (0,-1,0);\n    \\draw (0,0,1) -- (0,0,2.5);\n  \\end{tikzpicture}\n\\end{equation*}\n\n% ----------------------------------------------------------------------\n\\subsection*{Conversion to camera coordinates}\n\nBefore we render an object, we need to place it in some appropriate\nlocation relative to the camera. We do this by specifying four vectors\n$\\vect{q}$, $\\vect{a}_x$, $\\vect{a}_y$, and $\\vect{a}_z$ in\n$\\R^3$. Here, $\\vect{q}$ is the origin of the object coordinate\nsystem, relative to the camera coordinate system. The vectors\n$\\vect{a}_x$, $\\vect{a}_y$, and $\\vect{a}_z$ are the axes of the\nobject coordinate system, relative to the camera coordinate system, as\nshown in the following illustration:\n\\begin{equation*}\n  \\begin{tikzpicture}\n    \\fill (0,0) circle (0.1) node[below] {Camera};\n    \\begin{scope}[x={(-0.8cm,0.45cm)},z={(1cm,0.3cm)},y={(0cm,1.1cm)}]\n      \\draw[->] (0,0,0) -- (2,0,0) node[left]{$x$};\n      \\draw[->] (0,0,0) -- (0,2,0) node[left]{$y$};\n      \\draw[->] (0,0,0) -- (0,0,5) node[right]{$z$};\n    \\end{scope}\n    \\begin{scope}[shift={(4,3)}]\n      \\begin{scope}[x={(-1cm,-0.14cm)},y={(1.1cm,-0.35cm)},z={(0.2cm,1.3cm)},scale=0.7]\n        \\begin{scope}\n          \\clip (1,-1,1) -- (1,-1,-1) -- (1,1,-1) -- (-1,1,-1)\n          -- (-1,1,1) -- (-1,-1,1) -- cycle;\n          \\fill[blue!3] (1,-1,1) -- (1,-1,-1) -- (1,1,-1) -- (-1,1,-1)\n          -- (-1,1,1) -- (-1,-1,1) -- cycle;\n        \\end{scope}\n        \\draw[thick] ( 1, 1, 1) -- ( 1, 1,-1) -- ( 1,-1,-1) -- ( 1,-1, 1) -- cycle;\n        \\draw[thick] ( 1, 1, 1) -- (-1, 1, 1) -- (-1, 1,-1) -- ( 1, 1,-1) -- cycle;\n        \\draw[thick] ( 1, 1, 1) -- ( 1,-1, 1) -- (-1,-1, 1) -- (-1, 1, 1) -- cycle;\n        \\draw[thick,blue,->] (0,0,0) -- (1,0,0) node[left]{$\\vect{a}_x$};\n        \\draw[thick,blue,->] (0,0,0) -- (0,1,0) node[right]{$\\vect{a}_y$};\n        \\draw[thick,blue,->] (0,0,0) -- (0,0,1) node[right]{$\\vect{a}_z$};\n      \\end{scope}\n    \\end{scope}\n    \\draw[thick,blue,->] (0,0) -- node[above=1ex]{$\\vect{q}$}(4,3);\n  \\end{tikzpicture}\n\\end{equation*}\nThus, given a point with object coordinates\n$\\vect{v}=\\begin{mymatrix}{c}x\\\\y\\\\z\\end{mymatrix}$, we can find its\ncamera coordinates\n$\\vect{p} = \\begin{mymatrix}{c} p_x \\\\ p_y \\\\ p_z \\end{mymatrix}$ by\nthe following formula:\n\\begin{equation*}\n  \\vect{p} = \\vect{q} + x\\vect{a}_x + y\\vect{a}_y + z\\vect{a}_z.\n\\end{equation*}\nIf we write $A$ for the $3\\times 3$-matrix whose columns are $\\vect{a}_x$,\n$\\vect{a}_y$, and $\\vect{a}_z$, we can also write this formula more succinctly as\n\\begin{equation*}\n  \\vect{p} = \\vect{q} + A\\vect{v}.\n\\end{equation*}\n\n\\begin{example}{Converting object coordinates to camera coordinates}{object-to-camera}\n  Let\n  \\begin{equation*}\n    \\vect{q} = \\begin{mymatrix}{c} 0 \\\\ 0.5 \\\\ 5 \\end{mymatrix},\\quad\n    A = \\begin{mymatrix}{ccc}\n      0.8 & 0.6 & 0 \\\\\n      0 & 0 & 1 \\\\\n      0.6 & -0.8 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Convert each of the 8 corners of the standard cube from object\n  coordinates to camera coordinates.\n\\end{example}\n\n\\begin{solution}\n  Let $\\vect{v}_1,\\ldots,\\vect{v}_8$ be the object coordinates of the\n  8 corners of the cube:\n  \\begin{equation*}\n    \\begin{mymatrix}{r}  1 \\\\ 1 \\\\ 1 \\end{mymatrix},~\n    \\begin{mymatrix}{r}  1 \\\\ 1 \\\\ -1 \\end{mymatrix},~\n    \\begin{mymatrix}{r}  1 \\\\ -1 \\\\ 1 \\end{mymatrix},~\n    \\begin{mymatrix}{r}  1 \\\\ -1 \\\\ -1 \\end{mymatrix},~\n    \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 1 \\end{mymatrix},~\n    \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ -1 \\end{mymatrix},~\n    \\begin{mymatrix}{r} -1 \\\\ -1 \\\\ 1 \\end{mymatrix},~\n    \\begin{mymatrix}{r} -1 \\\\ -1 \\\\ -1 \\end{mymatrix}.\n  \\end{equation*}\n  We convert each of them to camera coordinates using the formula\n  $\\vect{p}_i = \\vect{q} + A\\vect{v}_i$:\n  \\begin{eqnarray*}\n    \\vect{p}_1 &=&\n    \\begin{mymatrix}{c} 0 \\\\ 0.5 \\\\ 5 \\end{mymatrix}\n    + \\begin{mymatrix}{ccc}\n      0.8 & 0.6 & 0 \\\\\n      0 & 0 & 1 \\\\\n      0.6 & -0.8 & 0 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{r}  1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r}  1.4 \\\\ 1.5 \\\\ 4.8 \\end{mymatrix}, \\\\\n    \\vect{p}_2 &=&\n    \\begin{mymatrix}{c} 0 \\\\ 0.5 \\\\ 5 \\end{mymatrix}\n    + \\begin{mymatrix}{ccc}\n      0.8 & 0.6 & 0 \\\\\n      0 & 0 & 1 \\\\\n      0.6 & -0.8 & 0 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{r}  1 \\\\ 1 \\\\ -1 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r}  1.4 \\\\ -0.5 \\\\ 4.8 \\end{mymatrix}, \\\\\n    \\vect{p}_3 &=&\n    \\begin{mymatrix}{c} 0 \\\\ 0.5 \\\\ 5 \\end{mymatrix}\n    + \\begin{mymatrix}{ccc}\n      0.8 & 0.6 & 0 \\\\\n      0 & 0 & 1 \\\\\n      0.6 & -0.8 & 0 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{r}  1 \\\\ -1 \\\\ 1 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r}  0.2 \\\\ 1.5 \\\\ 6.4 \\end{mymatrix},\n  \\end{eqnarray*}\n  and so on. Continuing in the same fashion, we find\n  $\\vect{p}_1,\\ldots,\\vect{p}_8$:\n  \\begin{equation}\\label{eqn:object-to-camera}\n    \\begin{mymatrix}{r}  1.4 \\\\ 1.5 \\\\ 4.8 \\end{mymatrix},\n    \\begin{mymatrix}{r}  1.4 \\\\ -0.5 \\\\ 4.8 \\end{mymatrix},\n    \\begin{mymatrix}{r}  0.2 \\\\ 1.5 \\\\ 6.4 \\end{mymatrix},\n    \\begin{mymatrix}{r}  0.2 \\\\ -0.5 \\\\ 6.4 \\end{mymatrix},\n    \\begin{mymatrix}{r} -0.2 \\\\ 1.5 \\\\ 3.6 \\end{mymatrix},\n    \\begin{mymatrix}{r} -0.2 \\\\ -0.5 \\\\ 3.6 \\end{mymatrix},\n    \\begin{mymatrix}{r} -1.4 \\\\ 1.5 \\\\ 5.2 \\end{mymatrix},\n    \\begin{mymatrix}{r} -1.4 \\\\ -0.5 \\\\ 5.2 \\end{mymatrix}.\n  \\end{equation}\n\\end{solution}\n\nWe can also write $f:\\R^3 \\to \\R^3$ for the function that converts\nobject coordinates to camera coordinates, i.e.,\n\\begin{equation*}\n  f(\\vect{v}) = \\vect{q} + A\\vect{v}.\n\\end{equation*}\nWe note that this is not a linear function, because\n$f(\\vect{0})\\neq \\vect{0}$. The function $f$ is called an\n\\textbf{affine function}%\n\\index{function!affine}%\n\\index{affine function}, which means that it is a linear function\n$\\vect{v}\\mapsto A\\vect{v}$ followed by a translation\n$\\vect{v}\\mapsto \\vect{q}+\\vect{v}$.\n\n% ----------------------------------------------------------------------\n\\subsection*{Rendering}\n\nOnce we know the camera coordinates\n$\\vect{p}=\\begin{mymatrix}{c} p_x \\\\ p_y \\\\ p_z \\end{mymatrix}$ of a point,\nwe need to render the point, i.e., find its coordinates in the image plane.\n\\begin{equation*}\n  \\begin{tikzpicture}\n    \\fill (0,0) circle (0.1) node[below] {Camera};\n    \\begin{scope}[x={(-0.8cm,0.45cm)},z={(1cm,0.3cm)},y={(0cm,1.1cm)}]\n      \\draw[->] (0,0,0) -- (2,0,0) node[left]{$x$};\n      \\draw[->] (0,0,0) -- (0,2,0) node[left]{$y$};\n      \\draw[->] (0,0,0) -- (0,0,5) node[right]{$z$};\n      \\draw[dashed,blue] (0,0,0) -- (1,2,5);\n      \\draw[fill=white] (-1.5,-1.5,2) -- (-1.5,1.5,2) -- (1.5,1.5,2) -- (1.5,-1.5,2) -- cycle;\n      \\draw[thin,black!20] (-1.5,-0.75,2) -- (1.5,-0.75,2);\n      \\draw[thin,black!20] (-1.5,0,2) -- (1.5,0,2);\n      \\draw[thin,black!20] (-1.5,0.75,2) -- (1.5,0.75,2);\n      \\draw[thin,black!20] (-0.75,-1.5,2) -- (-0.75,1.5,2);\n      \\draw[thin,black!20] (0,-1.5,2) -- (0,1.5,2);\n      \\draw[thin,black!20] (0.75,-1.5,2) -- (0.75,1.5,2);\n      \\fill[blue] (1,2,5) circle (0.06) +(0,0.1,0) node[left] {$\\vect{p}$};\n      \\fill[blue] (0.4,0.8,2) circle (0.06) +(0,0.1,0) node[left] {$\\vect{p}'$};\n      \\draw (0,0,0) -- (0,0,2);\n      \\draw[dashed,blue] (0,0,0) -- (0.4,0.8,2);\n      \\path (0,-1.9,2) node[below] {Image plane};\n    \\end{scope}\n  \\end{tikzpicture}\n\\end{equation*}\nSince the camera is located at the origin, the line that passes\nthrough the camera and the point $\\vect{p}$ has the parametric equation\n\\begin{equation*}\n  \\vect{r} = t\\vect{p} = \\begin{mymatrix}{c} tp_x \\\\ tp_y \\\\ tp_z \\end{mymatrix}.\n\\end{equation*}\nSince the image plane is the plane $z=1$, we must set $t$ such that\n$tp_z = 1$, i.e., $t=\\frac{1}{p_z}$. Therefore, the coordinates of the\nrendered point are\n\\begin{equation*}\n  \\vect{p}' = \\frac{1}{p_z}\\vect{p} =\n  \\begin{mymatrix}{c} p_x/p_z \\\\ p_y/p_z \\\\ 1 \\end{mymatrix}.\n\\end{equation*}\nFinally, since the image plane is $2$-dimensional, we can forget the\nnow useless $z$-coordinate, and render the point at the coordinates\n$\\begin{mymatrix}{c} p_x/p_z \\\\ p_y/p_z \\end{mymatrix}$ in the\n$2$-dimensional image plane.\n\n\\begin{example}{Rendering}{rendering}\n  Render the cube from Example~\\ref{exa:object-to-camera}.\n\\end{example}\n\n\\begin{solution}\n  We must apply the rendering function\n  \\begin{equation*}\n    g\\paren{\\begin{mymatrix}{c} p_x \\\\ p_y \\\\ p_z \\end{mymatrix}}\n    = \\begin{mymatrix}{c} p_x/p_z \\\\ p_y/p_z \\end{mymatrix}\n  \\end{equation*}\n  to each of the corners of the cube from\n  {\\eqref{eqn:object-to-camera}}.\n  We have\n  \\begin{eqnarray*}\n    g\\paren{\\begin{mymatrix}{r}  1.4 \\\\ 1.5 \\\\ 4.8 \\end{mymatrix}}\n    &=& \\begin{mymatrix}{r} 1.4/4.8 \\\\ 1.5/4.8 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{r} 0.292 \\\\ 0.312 \\end{mymatrix}, \\\\\n    g\\paren{\\begin{mymatrix}{r}  1.4 \\\\ -0.5 \\\\ 4.8 \\end{mymatrix}}\n    &=& \\begin{mymatrix}{r} 1.4/4.8 \\\\ -0.5/4.8 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{r} 0.292 \\\\ -0.104 \\end{mymatrix}, \\\\\n    g\\paren{\\begin{mymatrix}{r}  0.2 \\\\ 1.5 \\\\ 6.4 \\end{mymatrix}}\n    &=& \\begin{mymatrix}{r} 0.2/6.4 \\\\ 1.5/6.4 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{r} 0.031 \\\\ 0.234 \\end{mymatrix},\n  \\end{eqnarray*}\n  and so on. The 8 rendered points are:\n  \\begin{equation*}\n    \\begin{mymatrix}{r} 0.292 \\\\ 0.312 \\end{mymatrix}\\!,\\,\n    \\begin{mymatrix}{r} 0.292 \\\\ -0.104 \\end{mymatrix}\\!,\\,\n    \\begin{mymatrix}{r} 0.031 \\\\ 0.234 \\end{mymatrix}\\!,\\,\n    \\begin{mymatrix}{r} 0.031 \\\\ -0.078 \\end{mymatrix}\\!,\\,\n    \\begin{mymatrix}{r} -0.056 \\\\ 0.417 \\end{mymatrix}\\!,\\,\n    \\begin{mymatrix}{r} -0.056 \\\\ -0.139 \\end{mymatrix}\\!,\\,\n    \\begin{mymatrix}{r} -0.269 \\\\ 0.288 \\end{mymatrix}\\!,\\,\n    \\begin{mymatrix}{r} -0.269 \\\\ -0.096 \\end{mymatrix}\\!.\n  \\end{equation*}\n  Drawing these in the 2-dimensional image plane, we get the following\n  picture, which is the final perspective-rendered image of the cube:\n  \\begin{equation*}\n    \\begin{tikzpicture}[scale=10, thick]\n      \\draw[black!20, fill=blue!3] (0.292,0.312) -- (0.292,-0.104) -- (0.031,-0.078) -- (0.031,0.234) -- cycle;\n      \\draw[black!20, fill=blue!3] (0.031,0.234) -- (0.031,-0.078) -- (-0.269,-0.096) -- (-0.269,0.288) -- cycle;\n      \\draw[black!20, fill=blue!3] (0.292,0.312) -- (0.031,0.234) -- (-0.269,0.288) -- (-0.056,0.417) -- cycle;\n      \\draw[black!20, fill=blue!3] (0.292,-0.104) -- (0.031,-0.078) -- (-0.269,-0.096) -- (-0.056,-0.139) -- cycle;\n      \\draw (-0.056,0.417) -- (-0.056,-0.139) -- (-0.269,-0.096) -- (-0.269,0.288) -- cycle;\n      \\draw (0.292,0.312) -- (0.292,-0.104) -- (-0.056,-0.139) -- (-0.056,0.417) -- cycle;\n    \\end{tikzpicture}\n  \\end{equation*}\n\\end{solution}\n\n% ----------------------------------------------------------------------\n\\subsection*{Animation}\n\nWe placed our object in the camera coordinate system using a\ncoordinate transformation function\n\\begin{equation*}\n  f(\\vect{v}) = \\vect{q} + A\\vect{v}.\n\\end{equation*}\nOne of the advantages of using such a coordinate transformation (as\nopposed to specifying the object points directly in the camera\ncoordinate system) is that this makes it very easy to move the objects\naround, rotate them, scale and shrink them, etc. For example:\n\\begin{enumerate}\n\\item To move the object to a different location, we only have to\n  change the vector $\\vect{q}$.\n\\item To rotate the object about its own $z$-axis, we only have to\n  replace $\\vect{v}$ by $R_{\\theta}\\vect{v}$, where $R_{\\theta}$ is the matrix for a\n  rotation about the $z$-axis by angle $\\theta$:\n  \\begin{equation*}\n    R_{\\theta} = \\begin{mymatrix}{ccc}\n      \\cos\\theta & -\\sin\\theta & 0 \\\\\n      \\sin\\theta & \\cos\\theta & 0 \\\\\n      0 & 0 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{enumerate}\nSimilarly to $R_{\\theta}$, we can also insert other transformation\nmatrices (for example, we could rotate the object about its $x$-axis\ninstead of its $z$-axis, scale the object, etc).  We can even make an\nanimation by rendering the object repeatedly for different values of\nthese parameters.\n\n\\begin{example}{An animated cube}{animation}\n  Make an animation of a rotating, moving cube. The animation is 5\n  seconds long (i.e., time $t$ ranges from $0$ to $5$). The location\n  of the cube at time $t$, in camera coordinates, is given by\n  \\begin{equation*}\n    \\vect{q}(t) =\n    \\begin{mymatrix}{c} -3+3t \\\\ -3 \\\\ 8+3t \\end{mymatrix}.\n  \\end{equation*}\n  The transformation matrix $A$ is as in\n  Example~\\ref{exa:object-to-camera}. Moreover, the cube should make\n  one quarter rotation about its $z$-axis during the time of the\n  animation, i.e., it should be transformed by $R_{\\theta}$, where\n  $\\theta=\\frac{\\pi}{10}t$. Compute $6$ frames of the animation, for\n  $t=0$, $t=1$, \\ldots, $t=5$.\n\\end{example}\n\n\\begin{solution}\n  For each of the animation frames $t\\in\\set{0,1,2,3,4,5}$, we do a\n  calculation very similar to that of\n  Examples~\\ref{exa:object-to-camera} to convert the cube coordinates\n  to camera coordinates, using the coordinate transformation\n  \\begin{equation*}\n    f(\\vect{v}) = \\vect{q}(t) + AR_{\\theta}\\vect{v},\n  \\end{equation*}\n  where $\\theta=\\frac{\\pi}{10}t$. We then render each of the frames\n  using the same method as in Example~\\ref{exa:rendering}. We skip the\n  detailed calculations, which are best done by computer (though they\n  could be done by hand, of course, as we did in\n  Examples~\\ref{exa:object-to-camera} and {\\ref{exa:rendering}}). The\n  final rendered frames look like this:\n  \\begin{equation*}\n    \\begin{tikzpicture}[scale=12, thick]\n      % Background:\n      \\draw[black!20,fill=blue!3] (-0.2979,-0.2128) -- (-0.5366,-0.2439) -- (-0.5366,-0.4878) -- (-0.2979,-0.4255) -- cycle;\n      \\draw[black!20,fill=blue!3] (-0.2051,-0.5128) -- (-0.2979,-0.4255) -- (-0.5366,-0.4878) -- (-0.4848,-0.6061) -- cycle;\n      \\draw[black!20,fill=blue!3] (-0.2051,-0.2564) -- (-0.2979,-0.2128) -- (-0.2979,-0.4255) -- (-0.2051,-0.5128) -- cycle;\n\n      \\draw[black!20,fill=blue!3] (0.0508,-0.1630) -- (-0.1092,-0.1721) -- (-0.1092,-0.3442) -- (0.0508,-0.3260) -- cycle;\n      \\draw[black!20,fill=blue!3] (0.1224,-0.3855) -- (0.0508,-0.3260) -- (-0.1092,-0.3442) -- (-0.0640,-0.4111) -- cycle;\n      \\draw[black!20,fill=blue!3] (0.1224,-0.1927) -- (0.0508,-0.1630) -- (0.0508,-0.3260) -- (0.1224,-0.3855) -- cycle;\n\n      \\draw[black!20,fill=blue!3] (0.2654,-0.1332) -- (0.1325,-0.1335) -- (0.1325,-0.2669) -- (0.2654,-0.2664) -- cycle;\n      \\draw[black!20,fill=blue!3] (0.3085,-0.3073) -- (0.2654,-0.2664) -- (0.1325,-0.2669) -- (0.1552,-0.3080) -- cycle;\n      \\draw[black!20,fill=blue!3] (0.3085,-0.1537) -- (0.2654,-0.1332) -- (0.2654,-0.2664) -- (0.3085,-0.3073) -- cycle;\n\n      \\draw[black!20,fill=blue!3] (0.2907,-0.1224) -- (0.2907,-0.2448) -- (0.2925,-0.2192) -- (0.2925,-0.1096) -- cycle;\n      \\draw[black!20,fill=blue!3] (0.4105,-0.1132) -- (0.2925,-0.1096) -- (0.2925,-0.2192) -- (0.4105,-0.2265) -- cycle;\n      \\draw[black!20,fill=blue!3] (0.4229,-0.2540) -- (0.4105,-0.2265) -- (0.2925,-0.2192) -- (0.2907,-0.2448) -- cycle;\n      \\draw[black!20,fill=blue!3] (0.4229,-0.1270) -- (0.4105,-0.1132) -- (0.4105,-0.2265) -- (0.4229,-0.2540) -- cycle;\n\n      \\draw[black!20,fill=blue!3] (0.3850,-0.1012) -- (0.3850,-0.2025) -- (0.4094,-0.1870) -- (0.4094,-0.0935) -- cycle;\n      \\draw[black!20,fill=blue!3] (0.5134,-0.0988) -- (0.4094,-0.0935) -- (0.4094,-0.1870) -- (0.5134,-0.1976) -- cycle;\n      \\draw[black!20,fill=blue!3] (0.4967,-0.2150) -- (0.5134,-0.1976) -- (0.4094,-0.1870) -- (0.3850,-0.2025) -- cycle;\n\n      \\draw[black!20,fill=blue!3] (0.4569,-0.0862) -- (0.4569,-0.1724) -- (0.5000,-0.1639) -- (0.5000,-0.0820) -- cycle;\n      \\draw[black!20,fill=blue!3] (0.5877,-0.0877) -- (0.5000,-0.0820) -- (0.5000,-0.1639) -- (0.5877,-0.1754) -- cycle;\n      \\draw[black!20,fill=blue!3] (0.5463,-0.1852) -- (0.5877,-0.1754) -- (0.5000,-0.1639) -- (0.4569,-0.1724) -- cycle;\n\n      % Foreground:\n      \\draw (-0.4848,-0.3030) -- (-0.4848,-0.6061) -- (-0.5366,-0.4878) -- (-0.5366,-0.2439) -- cycle;\n      \\draw (-0.2051,-0.2564) -- (-0.2051,-0.5128) -- (-0.4848,-0.6061) -- (-0.4848,-0.3030) -- cycle;\n      \\draw (-0.2051,-0.2564) -- (-0.4848,-0.3030) -- (-0.5366,-0.2439) -- (-0.2979,-0.2128) -- cycle;\n\n      \\draw (-0.0640,-0.2055) -- (-0.0640,-0.4111) -- (-0.1092,-0.3442) -- (-0.1092,-0.1721) -- cycle;\n      \\draw (0.1224,-0.1927) -- (0.1224,-0.3855) -- (-0.0640,-0.4111) -- (-0.0640,-0.2055) -- cycle;\n      \\draw (0.1224,-0.1927) -- (-0.0640,-0.2055) -- (-0.1092,-0.1721) -- (0.0508,-0.1630) -- cycle;\n\n      \\draw (0.1552,-0.1540) -- (0.1552,-0.3080) -- (0.1325,-0.2669) -- (0.1325,-0.1335) -- cycle;\n      \\draw (0.3085,-0.1537) -- (0.3085,-0.3073) -- (0.1552,-0.3080) -- (0.1552,-0.1540) -- cycle;\n      \\draw (0.3085,-0.1537) -- (0.1552,-0.1540) -- (0.1325,-0.1335) -- (0.2654,-0.1332) -- cycle;\n\n      \\draw (0.4229,-0.1270) -- (0.4229,-0.2540) -- (0.2907,-0.2448) -- (0.2907,-0.1224) -- cycle;\n      \\draw (0.4229,-0.1270) -- (0.2907,-0.1224) -- (0.2925,-0.1096) -- (0.4105,-0.1132) -- cycle;\n\n      \\draw (0.4967,-0.1075) -- (0.5134,-0.0988) -- (0.5134,-0.1976) -- (0.4967,-0.2150) -- cycle;\n      \\draw (0.4967,-0.1075) -- (0.4967,-0.2150) -- (0.3850,-0.2025) -- (0.3850,-0.1012) -- cycle;\n      \\draw (0.4967,-0.1075) -- (0.3850,-0.1012) -- (0.4094,-0.0935) -- (0.5134,-0.0988) -- cycle;\n\n      \\draw (0.5463,-0.0926) -- (0.5877,-0.0877) -- (0.5877,-0.1754) -- (0.5463,-0.1852) -- cycle;\n      \\draw (0.5463,-0.0926) -- (0.5463,-0.1852) -- (0.4569,-0.1724) -- (0.4569,-0.0862) -- cycle;\n      \\draw (0.5463,-0.0926) -- (0.4569,-0.0862) -- (0.5000,-0.0820) -- (0.5877,-0.0877) -- cycle;\n\n      % Labels:\n      \\path (-0.3750,-0.1250) node {$t=0$};\n      \\path (0.0000,-0.0909) node {$t=1$};\n      \\path (0.2143,-0.0714) node {$t=2$};\n      \\path (0.3529,-0.0588) node {$t=3$};\n      \\path (0.4500,-0.0500) node {$t=4$};\n      \\path (0.5217,-0.0435) node {$t=5$};\n    \\end{tikzpicture}\n  \\end{equation*}\n  Note that there is a bit of distortion in the first and last cubes.\n  This is because the camera is very close to the image plane (the\n  scene has been ``filmed'' with a wide-angle camera). The distortion\n  goes away if you close one eye and bring the other eye very close to\n  the page.\n\\end{solution}\n", "meta": {"hexsha": "e96b9a635f3fa1c161d552aa94e9a6e4c129fa83", "size": 21474, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/LinearTransformationsRn-Application-Perspective.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/LinearTransformationsRn-Application-Perspective.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/LinearTransformationsRn-Application-Perspective.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 48.693877551, "max_line_length": 124, "alphanum_fraction": 0.5767905374, "num_tokens": 8978, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.8539127603871312, "lm_q1q2_score": 0.7040185520202441}}
{"text": "\\section{World to image plane}\n\\label{sec:wrd2cam}\nAccordingly with what we reported in Section \\ref{sec:pinhole_camera}, the second step is to determine the 3D point coordinates in a reference system concordant with the image plane. The plane of interest $S$ is a plane parallel with lens plane and passing through the plane parallel to the sensor.  This choice is due to the possibility to tilt the lens with respect to the sensor, accordingly with the Scheimpflug principle, described above. If we consider the image plane parallel to the sensor directly, some issue arises. Tilting the lens changes the focal length of the camera, that varies point by point, resulting in a distorted image. This problem can be simplified observing that if we tilt the lens, we add an image plane rotated with respect to the classical image plane. In this way, the transformation between the two planes is a simple projection between planes. So we decided to split the problem in two subproblems: the first, described in this section, requires to change coordinates reference system; the second, described in Section \\ref{sec:scheimflug}, needs to project the point on a different plane. Furthermore, this choice allows to simplify the mathematical model. \\\\\n\nLet's focus on the Figure \\ref{fig:laser-triang-a}.\n  \\begin{figure}[t!]\n    \\centering\n    \\includegraphics[width=0.7\\textwidth]{./images/model/laser_triang_alpha.png}\n    \\caption{World to image plane}\n    \\label{fig:laser-triang-a}\n  \\end{figure}\nAs we can see, a change in the 3D point coordinates causes a variation in the image plane. However this alterations deals with the angle $\\alpha$, estimated as offset from the triangulation angle $\\phi$. Furthermore, laser plane and image plane are not parallel: this means that the two variations are different. What we are interested in, is the variation on the image plane, not in the world, so we can formulate this problem, accordingly with \\cite{th:quattrini}, as:\n  \\begin{equation}\n  \t\\alpha_i = \\arctan\\left( \\frac{y_{s_i}}{f} \\right)\n    \\label{eq:model:alpha}\n  \\end{equation}\nwhere $y_{s_i}$ is the $i^{th}$ points in the image plane $S$. Being careful, it is simple to observe that the same relation is valid when determining the error due evaluating the $x$ coordinate, but with respect to the optical axis:\n  \\begin{equation*}\n  \t\\beta_i = \\arctan\\left( \\frac{x_{s_i}}{f} \\right)\n  \\end{equation*}\nNote that this step is important also to determine the natural camera resolution, in fact it allows to define the minimum variation appreciated by the sensor while it is observing the world.\n\nSo we can conclude writing that:\n  \\begin{equation}\n    \\label{eq:det_a}\n  \t\\sigma_{\\alpha_i} = \\sqrt{\n  \t  \\left( \\frac{\\partial \\alpha_i}{\\partial y_{s_i}} \\right)^2 \\sigma_{y_{s_i}}^2\n  \t  + \\left( \\frac{\\partial \\alpha_i}{\\partial f} \\right)^2 \\sigma_f^2\n  \t}\n  \\end{equation} \\\\\n\nAlso in this case, $f$ is a parameter estimated thanks to the calibration processes, so we can consider it as negligible. Then, we can simplify Equation \\ref{eq:det_a} as\n  \\begin{equation*}\n  \t\\sigma_{\\alpha_i} = \\sqrt{\n  \t  \\left( \\frac{\\partial \\alpha_i}{\\partial y_{s_i}} \\right)^2 \\sigma_{y_{s_i}}^2\n  \t}\n  \\end{equation*}\nThe same conclusions can be applied to $\\beta_i$. \\\\\n\nAs we will see later, this transformation is the most delicate one, probably because of the change of reference system. In fact we can consider it as a passage from 3D to 2D reference system.\n", "meta": {"hexsha": "6e510ec7a890461ba54ef5235e7448fd7891bc88", "size": 3461, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/thesis/src/chapters/ch4-Model/3_wrd2cam.tex", "max_stars_repo_name": "extoxesses/LaserMat", "max_stars_repo_head_hexsha": "4e893cd56ecea8497918ecafb642b2fbf9a085a2", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-05-12T08:53:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T06:36:55.000Z", "max_issues_repo_path": "report/thesis/src/chapters/ch4-Model/3_wrd2cam.tex", "max_issues_repo_name": "extoxesses/LaserMat", "max_issues_repo_head_hexsha": "4e893cd56ecea8497918ecafb642b2fbf9a085a2", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/thesis/src/chapters/ch4-Model/3_wrd2cam.tex", "max_forks_repo_name": "extoxesses/LaserMat", "max_forks_repo_head_hexsha": "4e893cd56ecea8497918ecafb642b2fbf9a085a2", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.4146341463, "max_line_length": 1194, "alphanum_fraction": 0.752672638, "num_tokens": 899, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7040185409956295}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{amsmath}\n\n\\title{Hello, World!}\n\\author{your name goes here}\n\\date{\\today}\n\n\\begin{document}\n    \\maketitle\n\n    Hello, world!\n\n    \\section{Inline Math}\n    % Here we use \\( and \\) to write math inline with normal text.\n    One of the trigonometric sum identities is \n    \\( \\sin (x) + \\sin (y) = 2 \\sin (\\frac{x+y}{2}) \\cos (\\frac{x-y}{2}) \\).\n\n    \\section{Separate Math}\n    % Here we use \\[ and \\] to write math separate from normal text.\n    \\[ \\forall x \\in X, \\quad \\exists y \\leq \\epsilon  \\]\n\n    \\subsection{Product Rule}\n    % Here we use both techniques\n    If \\(f\\) and \\(g\\) are differentiable at \\(x\\), then\n\n    \\[ \\frac{d}{dx}(f(x)g(x)) = f'(x)g(x) + f(x)g'(x) \\]\n\n\\end{document}\n", "meta": {"hexsha": "a04727781bfd6d785d53176ea00645c0c462f777", "size": 741, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "presentation/code-snippets/hello-world-math.tex", "max_stars_repo_name": "mesbahamin/latex-workshop", "max_stars_repo_head_hexsha": "36dfc6f18038c8e642c98a2c27c476646bf62728", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-10-27T17:44:25.000Z", "max_stars_repo_stars_event_max_datetime": "2017-10-27T17:44:25.000Z", "max_issues_repo_path": "presentation/code-snippets/hello-world-math.tex", "max_issues_repo_name": "mesbahamin/latex-workshop", "max_issues_repo_head_hexsha": "36dfc6f18038c8e642c98a2c27c476646bf62728", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "presentation/code-snippets/hello-world-math.tex", "max_forks_repo_name": "mesbahamin/latex-workshop", "max_forks_repo_head_hexsha": "36dfc6f18038c8e642c98a2c27c476646bf62728", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.7, "max_line_length": 76, "alphanum_fraction": 0.5991902834, "num_tokens": 247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467801752451, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.7039258039171437}}
{"text": "\n\\subsection{Representing integers}\n\nWe can expand the natural numbers to the integers.\n\nConsider a byte representing the natural numbers. Previously this would have gone from \\(0\\) to \\(255\\), with a series of all \\(1\\)s representing \\(255\\).\n\nTo introduce integers all numbers with a \\(1\\) in the leftmost bit are considered to be negative.\n\n\\subsection{Two's complement}\n\nWe represent the value of these negative numbers with two’s complement. With two’s complement the number “after” \\(127\\) is \\(-128\\). Note that this does not just use the first bit as a sign. The use of two’s complement allows us to use the arithmetical logical units for the integers.\n\n", "meta": {"hexsha": "519c84cf77e9b4efb47764510314cb6787a36191", "size": 662, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/numbers/02-01-integers.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/computer/numbers/02-01-integers.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/computer/numbers/02-01-integers.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.2857142857, "max_line_length": 285, "alphanum_fraction": 0.7583081571, "num_tokens": 148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7039257803427227}}
{"text": "%---------------------------Shape---------------------------\n\\section{Shape\\label{s:hex-shape}}\n\nThe shape metric is 3 divided by the minimum mean ratio\nof the Jacobian matrix evaluated at the element corners:\n\\[\n  q = 3\\min_{i\\in\\{0,1,\\ldots,8\\}}\n  \\left\\{\n    \\frac{{\\alpha_i}^{\\frac {2}{3}}} {|A_i|^2}, \n  \\right\\}.\n\\]\n\nNote that if $\\alpha_i \\leq DBL\\_MIN$ or $|A_i|^2 \\leq DBL\\_MIN$ for any $i$, we set $q = 0$.\n\n\\hexmetrictable{shape}%\n{$1$}%                                        Dimension\n{$[0.3,1]$}%                                  Acceptable range\n{$[0,1]$}%                                    Normal range\n{$[0,1]$}%                                    Full range\n{$1$}%                                        Cube\n{\\cite{knu:03}}%                              Citation\n{v\\_hex\\_shape}%                              Verdict function name\n", "meta": {"hexsha": "de1d3fabd6aaeb221b69bcd11a05c02132f23a08", "size": 851, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexShape.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexShape.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexShape.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 37.0, "max_line_length": 93, "alphanum_fraction": 0.4112808461, "num_tokens": 229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533051062238, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.703922969437416}}
{"text": "\\section{Generative models}\n\\subsection*{Variational AEs}\n$\\mathbb{E}_x[f(x)]=\\mathbb{E}_z[f(F_\\theta(z))]$ law of the unconscious stat. \\\\\n$\\textbf{ELBO}(\\phi, \\theta)=\\mathbb{E}_{z\\sim q_\\phi(z\\vert x)}[log p_\\theta (x\\vert z)] - D_{\\textbf{KL}}(q_\\phi (z \\vert x) \\| p_\\theta (z))$, $p_\\theta (z)$ chosen prior. \\\\\n$\\nabla_\\theta \\mathbb{E}_{q_\\phi}[log p_\\theta (x\\vert z)] \\stackrel{\\textit{Leibniz}}{=}  \\mathbb{E}_{q_\\phi}[\\nabla_\\theta log p_\\theta (x\\vert z)] \\approx \\frac{1}{N}\\sum_{n\\leq N} \\nabla_\\theta log p_\\theta (x\\vert z^{(n)}), z^{(n)} \\sim q_\\phi(.\\vert x)$ \\\\\n$\\nabla_\\phi \\mathbb{E}_{q_\\phi}[L(x,z)] =  \\mathbb{E}_{q_\\phi}[L(x,z)\\nabla_\\phi q_\\phi(z\\vert x)]$, (reinforcement trick) but high variance! $\\rightarrow$ reparam.\\\\\n$\\nabla_\\phi \\mathbb{E}_{q_\\phi}[L(x,z)] =  \\mathbb{E}_{\\epsilon}[\\nabla_\\phi L(x, g_\\phi(\\epsilon))]$ estimated via MC sampling \\\\\n$z\\sim \\mathcal{N}(\\mu, C),\\, \\nabla_\\mu \\mathbb{E}[f(z)] = \\mathbb{E}[\\nabla_z f(z)]$, (Bonnet)\\\\\n$\\nabla_U \\mathbb{E}[f(z)] = \\mathbb{E}_\\epsilon[\\epsilon^\\top g], g := \\nabla_\\xi f(\\xi) \\vert_{\\xi + U\\epsilon + \\mu} $\n\n\\subsection*{GANs}\nBaye's optimal classifier: $q_\\theta(x) = p / (p + p_\\theta)$ \nObjective: $\\mathbb{E}_{\\tilde p_\\theta}[y ln(q_\\theta(x) + (1-y)ln(1-q_\\theta(x)))]$ \\\\\n\\textbf{Optimizing GANs}: saddle-points problem, mode-collapse, unstability,... WIP\n", "meta": {"hexsha": "fcb654d48f0b9a779f3a7adf1a43fdde14afdd0a", "size": 1359, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Generative.tex", "max_stars_repo_name": "Emilien-P/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "ebda1cb98b2e3d17e055b05cb0fd1e7decce507f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-17T18:13:31.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-17T18:13:31.000Z", "max_issues_repo_path": "Generative.tex", "max_issues_repo_name": "Emilien-P/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "ebda1cb98b2e3d17e055b05cb0fd1e7decce507f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Generative.tex", "max_forks_repo_name": "Emilien-P/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "ebda1cb98b2e3d17e055b05cb0fd1e7decce507f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 90.6, "max_line_length": 263, "alphanum_fraction": 0.6335540839, "num_tokens": 568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921834855049, "lm_q2_score": 0.7634837743174789, "lm_q1q2_score": 0.7038723621008283}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath, amsfonts}\n\\title{An ideal non-extended formulation for leaky ReLU}\n\\begin{document}\n\\maketitle\n\\section{Objective}\nFor a leaky ReLU unit\n\\begin{subequations}\n\\begin{align}\n\ty = \\max(c(w^Tx+b), w^Tx+b)\\\\\n\tL \\le x \\le U\n\\end{align}\n\\end{subequations}\nwhere $0\\le c < 1$, we will find an ideal non-extended formulation. Please refer to \\cite{Anderson2020} for an explanation on the ideal formulation. In \\cite{Anderson2020} they derived the ideal formulation for a ReLU neuron $y = \\max(0, w^Tx+b)$, here we extend their approach to leaky ReLU neuron.\n\n\\section{Big-M formulation}\nIf we denote $m^+ = \\sum_i \\max(w_iU_i, w_iL_i) + b_i, m^- = \\sum_i \\min(w_iU_i, w_iL_i) + b_i$, then big-M formulation is\n\\begin{subequations}\n\\begin{align}\n\ty \\ge c(w^Tx+b)\\\\\n\ty \\ge w^Tx+b\\\\\n    y \\le c(w^Tx+b) + (1-c)m^+\\beta\\\\\n    y \\le w^Tx+b - (1-c)m^-(1-\\beta)\\\\\n    L \\le x \\le U\\\\\n\\end{align}\n\\end{subequations}\nThis formulation is not ideal, as explained in Fig 1 of \\cite{Anderson2020}.\n\n\\section{Ideal extended formulation}\nWe consider an ideal extended formulation with new slack continuous variables\n\\begin{subequations}\n\\begin{align}\n\tx = x^0 + x^1\\\\\n\ty = y^0 + y^1\\\\\n\ty^0 = c(w^Tx^0 + b(1-\\beta)) \\le 0\\\\\n\ty^1 = w^Tx^1 + b\\beta\\ge 0\\\\\n\tL(1-\\beta) \\le x^0 \\le U(1-\\beta)\\\\\n\tL\\beta \\le x^1 \\le U\\beta\n\\end{align}\n\\end{subequations}\nThis ideal formulation is extended as it introduces new slack variables $x^0, x^1, y^0, y^1$.\n\n\\section{Ideal non-extended formulation}\nTo derive the ideal non-extended formulation, we want to remove the slack variables $x^0, x^1, y^0, y^1$ in the ideal extended formulation. We first write $x^1, y^0, y^1$ as function of $x, \\beta, x^0$\n\\begin{subequations}\n\\begin{align}\n\tx^1 = x - x^0\\\\\n\ty^0 = c(w^Tx^0 + b(1-\\beta))\\\\\n\ty^1 = w^Tx^1 + b\\beta = w^Tx - w^Tx^0 + b\\beta\\\\\n\ty = y^0 + y^1 = w^Tx - (1-c)w^Tx^0 + cb + b(1-c)\\beta\n\\end{align}\n\\end{subequations}\nHence we can express $(1-c)w^1x^0_1$ as\n\\begin{align}\n\t(1-c)w_1x^0_1 = w^Tx - (1-c)\\sum_{i>1}w_ix^0_i + cb  + b(1-c)\\beta - y\\label{eq:1_c_w1_x01}\n\\end{align}\nWe define \n\\begin{align}\n\t\\bar{L}_i = \\begin{cases}L_i\\text{ if } w_i > 0\\\\U_i\\text{ if } w_i < 0\\end{cases}\n\t\\bar{U}_i = \\begin{cases}U_i\\text{ if } w_i > 0\\\\L_i\\text{ if } w_i < 0\\end{cases}\n\\end{align}\nWe have\n\\begin{subequations}\n\\begin{align}\n\t(1-c)w_1\\bar{L}_1(1-\\beta) \\le (1-c)w_1x^0_1\\le (1-c)w_1\\bar{U}_1(1-\\beta)\\\\\n\t(1-c)w_1(x_1-\\bar{U}_1\\beta)\\le (1-c)w_1x^0_1\\le(1-c)w_1(x_1-\\bar{L}_1\\beta)\n\\end{align}\n\\end{subequations}\nreplacing $(1-c)w_1x^0_1$ with the right-hand side of \\eqref{eq:1_c_w1_x01} we get\n\\begin{subequations}\n\t\\begin{align}\n\t\ty \\le w^Tx + cb + b(1-c)\\beta - (1-c)w_1\\bar{L}_1(1-\\beta)-(1-c)\\sum_{i>1}w_ix^0_i\\\\\n\t\ty \\le cw_1x_1 + \\sum_{i>1}w_ix_i + cb + b(1-c)\\beta + (1-c)w_1\\bar{U}_1\\beta - (1-c)\\sum_{i>1}w_ix^0_i\\\\\n\t\ty \\ge w^Tx + cb + b(1-c)\\beta - (1-c)w_1\\bar{U}_1(1-\\beta)-(1-c)\\sum_{i>1}w_ix^0_i\\\\\n\t\ty \\ge cw_1x_1 + \\sum_{i>1}w_ix_i + cb + b(1-c)\\beta + (1-c)w_1\\bar{L}_1\\beta - (1-c)\\sum_{i>1}w_ix^0_i\n\t\\end{align}\n\\end{subequations}\nNow we proceed to get rid of $x^0_2$, we have\n\\begin{align}\n\t\\begin{split}\n\t\\begin{cases}\n\t\tw^Tx + cb + b(1-c)\\beta - (1-c)w_1\\bar{U}_1(1-\\beta) - (1-c)\\sum_{i>2}w_ix^0_i - y\\\\\n\t\tcw_1x_1 + \\sum_{i>1}w_ix_i + cb + b(1-c)\\beta + (1-c)\\bar{L}_1\\beta - (1-c)\\sum_{i>2}w_ix^0_i-y\\\\\n\t\t(1-c)w_2\\bar{L}_2(1-\\beta)\\\\\n\t\t(1-c)w_2(x_2-\\bar{U}_2\\beta)\n\t\\end{cases}\\\\\n\t\\le (1-c)w_wx^0_2\\le\\\\\n\t\\begin{cases}\n\t\tw^Tx + cb + b(1-c)\\beta - (1-c)w_1\\bar{L}_1(1-\\beta) - (1-c)\\sum_{i>2}w_ix^0_i - y\\\\\n\t\tcw_1x_1 + \\sum_{i>1}w_ix_i+cb+b(1-c)\\beta + (1-c)\\bar{U}_1\\beta - (1-c)\\sum_{i>2}w_ix^0_i-y\\\\\n\t\t(1-c)w_2\\bar{U}_2(1-\\beta)\\\\\n\t\t(1-c)w_2(x_2-\\bar{L}_2\\beta)\n\t\\end{cases}\n\\end{split}\n\\end{align}\nSo we end up with the constraints\n\\begin{subequations}\n\\begin{align}\n\ty\\ge cb + b(1-c)\\beta + \\sum_{i\\in\\mathcal{I}}w_ix_i - (1-c)(1-\\beta)\\sum_{i\\in\\mathcal{I}}w_i\\bar{U}_i + c\\sum_{i\\notin\\mathcal{I}}w_ix_i + (1-c)\\beta\\sum_{i\\notin\\mathcal{I}}w_i\\bar{L}_i \\label{eq:leaky_relu_nonextended_ideal_ge}\\\\\n\ty \\le cb + b(1-c)\\beta + \\sum_{i\\in\\mathcal{I}}w_ix_i -(1-c)(1-\\beta)\\sum_{i\\in\\mathcal{I}}w_i\\bar{L}_i + c\\sum_{i\\notin\\mathcal{I}}w_ix_i + (1-c)\\beta\\sum_{i\\notin\\mathcal{I}}w_i\\bar{U}_i \\label{eq:leaky_relu_nonextended_ideal_le}\n\\end{align}\n\\end{subequations}\nwhere $\\mathcal{I}$ is a subset of $\\{1, 2, ..., n\\}$. Moreover, \\eqref{eq:leaky_relu_nonextended_ideal_ge} is redundant.\n\nIn the end, we obtain the following non-extended ideal formulation\n\\begin{subequations}\n\\begin{align}\n\ty \\ge c(w^Tx+b)\\label{eq:leaky_relu_nonextended_ideal1}\\\\\n\ty \\ge w^Tx+b\\label{eq:leaky_relu_nonextended_ideal2}\\\\\n\t\\begin{split}\n\t\ty \\le cb + b(1-c)\\beta + \\sum_{i\\in\\mathcal{I}}\\left(w_ix_i -(1-c)(1-\\beta)w_i\\bar{L}_i\\right) +\\\\ \\sum_{i\\notin\\mathcal{I}}\\left(cw_ix_i + (1-c)\\beta w_i\\bar{U}_i\\right)\\label{eq:leaky_relu_nonextended_ideal3}\n\t\\end{split}\\\\\n\tL\\le x \\le U\\label{eq:leaky_relu_nonextended_ideal4}\n\\end{align}\n\\end{subequations}\nNotice that there are exponential number of subsets $\\mathcal{I}$. To find $\\mathcal{I}$, we consider to take a point $\\hat{x}, \\hat{y}, \\hat{\\beta}$ satisfying the constraints in the big-M formulation, with $\\hat{\\beta}$ being the continuous relaxation $0 \\le \\hat{\\beta} \\le 1$. Then we take $\\mathcal{I}$ as\n\\begin{align}\n\t\\mathcal{I} = \\{i|w_i\\hat{x}_i \\le (1-\\hat{\\beta})w_i\\bar{L}_i + \\hat{\\beta}w_i\\bar{U}_i\\}\\label{eq:find_index_set}\n\\end{align}\n\nWe take an iterative procedure to strengthen the big-M formulation. Say in the current iterations, the strengthened big-M formulation already contains the constraint with $\\mathcal{I}_1,\\hdots, \\mathcal{I}_k$, then for an $\\hat{x}$ at the boundary of the box $L \\le x \\le U$, we first compute its range of $\\hat{\\beta}$ under the existing constraint\n\\begin{align}\n\t\\max(c(w^T\\hat{x}+b), w^T\\hat{x}+b) \\le cb + b(1-c)\\hat{\\beta} + \\sum_{i\\in\\mathcal{I}_k}(w_ix_i - (1-c)(1-\\hat{\\beta})w_i\\bar{L}_i) + \\sum_{i\\notin\\mathcal{I}_k}(cw_ix_i+(1-c)\\hat{\\beta}w_i\\bar{U}_i)\n\\end{align}\nThen for each extreme $\\hat{x},\\hat{\\beta}$, we compute the corresponding index set $\\mathcal{I}$ from \\eqref{eq:find_index_set}. We then decide whether to enforce this cutting plane, by whether this new cutting plane shrinks the righ-hand side of \\eqref{eq:leaky_relu_nonextended_ideal3} at $\\hat{x}, \\hat{\\beta}$.\n\n\\section{Adding bounds on ReLU input}\nIf the lower and upper bound of the ReLU input $m^+/m^-$ is not computed as $\\max/\\min_{L\\le x\\le U} w^Tx+b$ (for example, we compute the bounds by solving an LP/MIP), then the leaky ReLU constraint $y = \\max(cw^Tx+b, w^Tx+b)$ has the following ideal extended formulation\n\\begin{subequations}\n\t\\begin{align}\n\tx = x^0 + x^1\\\\\n\ty = y^0 + y^1\\\\\n\ty^0 = c(w^Tx^0 + b(1-\\beta))\\le 0\\\\\n\ty^1 = w^Tx^1+b\\beta \\ge 0\\\\\n\t(m^--b)(1-\\beta) \\le w^Tx^0 \\le(m^+-b)(1-\\beta)\\\\\n\t(m^--b)\\beta\\le w^Tx^1\\le(m^+-b)\\beta\\\\\n\tL(1-\\beta)\\le x^0\\le U(1-\\beta)\\\\\n\tL\\beta\\le x^1\\le U\\beta\n\\end{align}\n\\end{subequations}\nHence we have the condition\n\\begin{align}\n\t\\begin{split}\n\t\\begin{cases}\n\t\t(1-c)(m^--b)(1-\\beta) - (1-c)\\sum_{i>1}w_ix^0_i\\\\\n\t\t(1-c)w^Tx - (1-c)(m^+-b)\\beta - (1-c)\\sum_{i>1}w_ix^0_i\\\\\n\t\t(1-c)w_1\\bar{L}_1(1-\\beta)\\\\\n\t\t(1-c)w_1(x_1-\\bar{U}_1\\beta)\n\t\\end{cases}\\\\\n\t\\le (1-c)w_1x^0_1\\le\\\\\n\t\\begin{cases}\n\t\t(1-c)(m^+-b)(1-\\beta) - (1-c)\\sum_{i>1}w_ix^0_i\\\\\n\t\t(1-c)w^Tx - (1-c)(m^--b)\\beta - (1-c)\\sum_{i>1}w_ix^0_i\\\\\n\t\t(1-c)w_1\\bar{U}_1(1-\\beta)\\\\\n\t\t(1-c)w_1(x_1-\\bar{L}_1\\beta)\n\t\\end{cases}\n\\end{split}\n\\end{align}\nUsing the relationship\n\\begin{align}\n\t(1-c)w_1x^0_1 = w^Tx - (1-c)\\sum_{i>1}w_ix^0_i + cb  + b(1-c)\\beta - y\\label{eq:1_c_w1_x01}\n\\end{align}\nwe get\n\\begin{align}\n\t\\begin{split}\n\t\\begin{cases}\n\t\tw^Tx + cb + b(1-c)\\beta - (1-c)w_1\\bar{U}_1(1-\\beta)-(1-c)\\sum_{i>1}w_ix^0_i\\\\\n\t\tcw_1x_1 + \\sum_{i>1}w_ix_i + cb + b(1-c)\\beta + (1-c)w_1\\bar{L}_1\\beta - (1-c)\\sum_{i>1}w_ix^0_i\\\\\n\t\tw^Tx+b - (1-\\beta)(1-c)m^+\\\\\n\t\tc(w^Tx+b) + m^-\\beta(1-c)\n\t\\end{cases}\\\\\n\t\\le y \\le\\\\\n\t\\begin{cases}\n\t\tw^Tx + cb + b(1-c)\\beta - (1-c)w_1\\bar{L}_1(1-\\beta)-(1-c)\\sum_{i>1}w_ix^0_i\\\\\n\t\tcw_1x_1 + \\sum_{i>1}w_ix_i + cb + b(1-c)\\beta + (1-c)w_1\\bar{U}_1\\beta - (1-c)\\sum_{i>1}w_ix^0_i\\\\\n\t\tw^Tx+b - (1-\\beta)(1-c)m^-\\\\\n\t\tc(w^Tx+b) + m^+\\beta(1-c)\n\t\\end{cases}\n\\end{split}\n\\end{align}\n\n\n\\section{Appendix}\nIn this appendix, we try to derive the ideal non-extended formulation for ReLU unit (not the leaky ReLU) unit \n\\begin{subequations}\n\\begin{align}\n\ty = \\max(0, w^Tx + b)\\\\\n\tL \\le x \\le U\n\\end{align}\n\\end{subequations}\n\\subsection{big-M formulation}\nWe denote $m^+ = \\sum_i \\max(w_iL_i, w_iU_i), m^- = \\sum_i \\min(w_iL_i, w_iU_i)$, and get the following big-M formulation\n\\begin{subequations}\n\\begin{align}\n\ty \\ge 0\\\\\n\ty \\ge w^Tx + b\\\\\n\ty \\le m^+\\beta\\\\\n\ty \\le w^Tx+b - m^-(1-\\beta)\\\\\n\tL \\le x \\le U\n\\end{align}\n\\end{subequations}\n\\subsection{Ideal extended formulation}\nUsing the multiple-choice trick, we get the following ideal formulation with slack variables\n\\begin{subequations}\n\\begin{align}\n\tx = x^0 + x^1\\\\\n\ty = y^0 + y^1\\\\\n\ty^0 = 0 \\ge w^Tx^0 + b(1-\\beta)\\\\\n\ty^1 = w^Tx^1 + b\\beta\\ge 0\\\\\n\tL(1-\\beta)\\le x^0\\le U(1-\\beta)\\\\\n\tL\\beta\\le x^1\\le U\\beta\n\\end{align}\n\\end{subequations}\n\n\\subsection{Ideal non-extended formulation}\nTo derive the ideal non-extended formulation, we will need to remove the slack variable $x^0, x^1, y^0, y^1$ from the ideal extended formulation. To do so, we first remove $x^1, y^0, y^1$ as\n\\begin{align}\n\tx^1 = x - x^0\\\\\n\ty^0 = 0\\\\\n\ty^1 = w^T(x-x^0) + b\\beta = y\n\\end{align}\nHence we have\n\\begin{align}\n\tw^Tx^0 = w^Tx + b\\beta-y\\\\\n\t\\Leftrightarrow w_1x^0_1 = w^Tx + b\\beta -\\sum_{i>1}w_ix^0_i - y\\label{eq:w1x01}\n\\end{align}\nWithout loss of generality, we assume $w_i > 0\\; \\forall i$, hence\n\\begin{subequations}\n\\begin{align}\n\tw_1L_1(1-\\beta)\\le w_1x^0_1\\le w_1U_1(1-\\beta)\\\\\n\tw_1x_1 - w_1U_1\\beta \\le w_1x^0_1 \\le w_1x_1 - w_1L_1\\beta\n\\end{align}\n\\label{eq:w1x01_bounds}\n\\end{subequations}\nSubstituting $w_1x^0_1$ in the inequalities \\eqref{eq:w1x01_bounds} with the right hand side of \\eqref{eq:w1x01}, we get the following inequalities\n\\begin{subequations}\n\t\\begin{align}\n\t\ty \\ge w^Tx + b\\beta - \\sum_{i>1}w_ix^0_i - w_1U_1(1-\\beta)\\\\\n\t\ty \\ge \\sum_{i>1}w_ix_i + b\\beta - \\sum_{i>1}w_ix^0_i + w_1L_1\\beta\\\\\n\t\ty \\le w^Tx + b\\beta - \\sum_{i>1}w_ix^0_i - w_1L_1(1-\\beta)\\\\\n\t\ty \\le \\sum_{i>1}w_ix_i + b\\beta - \\sum_{i>1}w_ix^0_i  + w_1U_1\\beta\n\t\\end{align}\n\\end{subequations}\nthese inequalities remove the slack variable $x^0_1$.\n\nNow we proceed to remove the slack variable $x^0_2$, we have\n\\begin{align}\n\t\\begin{split}\n\t\\max\\begin{cases}\n\t\tw^Tx + b\\beta -\\sum_{i>2}w_ix^0_i - y - w_1U_1(1-\\beta)\\\\\n\t\t\\sum_{i>1}w_ix_i + b\\beta - \\sum_{i>2}w_ix^0_i -y + w_1L_1\\beta\\\\\n\t\tw_2L_2(1-\\beta)\\\\\n\t\tw_2x_2 - w_2U_2\\beta\n\t\\end{cases}\\\\\n\t\\le w_2x^0_2\\le\\\\\n\t\\min\\begin{cases}\n\t\tw^Tx + b\\beta - \\sum_{i>2}w_ix^0_i-y - w_1L_1(1-\\beta)\\\\\n\t\t\\sum_{i>1}w_ix_i + b\\beta - \\sum_{i>2}w_ix^0_i-y+w_1U_1\\beta\\\\\n\t\tw_2U_2(1-\\beta)\\\\\n\t\tw_2x_2-w_2L_2\\beta\n\t\\end{cases}\n\\end{split}\n\\end{align}\nwe get the inequalities\n\\begin{subequations}\n\\begin{align}\n\ty \\ge w^Tx + b\\beta - \\sum_{i>2}w_ix^0_i - \\sum_{i \\le 2}w_iU_i(1-\\beta)\\\\\n\ty \\ge \\sum_{i\\neq 2}w_ix_i + b\\beta - \\sum_{i>2}w_ix^0_i - w_1U_1(1-\\beta) + w_2L_2\\beta\\\\\n\ty \\ge \\sum_{i>1}w_ix_i + b\\beta - \\sum_{i>2}w_ix^0_i + w_1L_1\\beta - w_2U_2(1-\\beta)\\\\\n\ty \\ge \\sum_{i>2}w_ix_i + b\\beta - \\sum_{i>2}w_ix^0_i  + \\sum_{i\\le 2}w_iL_i\\beta\\\\\n\ty \\le w^Tx + b + b\\beta - \\sum_{i>2}w_ix^0_i - \\sum_{i\\le 2}w_iL_i(1-\\beta)\\\\\n\ty \\le \\sum_{i>1}w_ix_i + b\\beta - \\sum_{i>2}w_ix^0_i  + w_1U_1\\beta - w_2L_2(1-\\beta)\\\\\n\ty \\le \\sum_{i\\neq 2}w_ix_i + b\\beta - \\sum_{i>2}w_ix^0_i - w_1L_1(1-\\beta) + w_2U_2\\beta\\\\\n\ty \\le \\sum_{i > 2}w_ix_i + b\\beta - \\sum_{i>2}w_ix^0_i + \\sum_{i\\le 2}w_iU_i\\beta\n\\end{align}\n\\end{subequations}\nIf we follow this procedure to remove the remaining slack variables, we end up with the inequalities\n\\begin{subequations}\n\t\\begin{align}\n\t\ty \\ge \\sum_{i\\in\\mathcal{I}}w_ix_i + b\\beta - \\sum_{i\\in\\mathcal{I}}w_iU_i(1-\\beta) + \\sum_{i\\notin\\mathcal{I}}w_iL_i\\beta\\\\\n\t\ty \\le \\sum_{i\\in\\mathcal{I}}w_ix_i + b\\beta - \\sum_{i\\in\\mathcal{I}}w_iL_i(1-\\beta) + \\sum_{i\\notin\\mathcal{I}}w_iU_i\\beta\n\t\\end{align}\n\\end{subequations}\nwhere $I$ is a subset of the set $\\{1, 2, \\hdots, n\\}$.\n\n\n\n\\begin{thebibliography}{9}\n\t\\bibitem{Anderson2020}\n\tRoss Anderson, Joey Huchette, Christian Tjandraatmadja and Juan Pablo Vielma \\textit{Strong mixed-integer programming formulations for trained neural networks}, Mathematical Programming, 2020\n\\end{thebibliography}\n\\end{document}\n", "meta": {"hexsha": "e2b07f4ea98e4a91738ebde7f4e32da34bc38d71", "size": 12467, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/ideal_formulation.tex", "max_stars_repo_name": "hongkai-dai/neural-network-lyapunov-1", "max_stars_repo_head_hexsha": "8843c13f69f7f39cbb939ab250413e76f61843f6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 58, "max_stars_repo_stars_event_min_datetime": "2021-06-21T08:59:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T14:35:23.000Z", "max_issues_repo_path": "doc/ideal_formulation.tex", "max_issues_repo_name": "StanfordASL/neural-network-lyapunov", "max_issues_repo_head_hexsha": "9e5db1c7f91b42df729026c9aa8575bc126f66b6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-08-22T05:31:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T03:47:07.000Z", "max_forks_repo_path": "doc/ideal_formulation.tex", "max_forks_repo_name": "StanfordASL/neural-network-lyapunov", "max_forks_repo_head_hexsha": "9e5db1c7f91b42df729026c9aa8575bc126f66b6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2021-06-21T04:29:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T05:54:43.000Z", "avg_line_length": 42.5494880546, "max_line_length": 349, "alphanum_fraction": 0.6537258362, "num_tokens": 5635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7038648990711551}}
{"text": "\\section{Multi-class}\n\n\\textbf{1-vs-all}: $c$ models, confidence $f^{(i)} (x) = w^{(i )\\top} x$\n\n\\textbf{1-vs-1}: $c\\frac{c-1}{2}$ models, voting scheme\n\n% ===\n\\emph{Multi-class Hinge loss}\\\\\n\\vspace{-12pt}\n$\\ell(w^{(1:c)};x,y) = \\max\\{ 0, 1\\! + \\overbracket[.7pt][.7pt]{\\max\\limits_{i:\\,j\\neq y} w^{(j)\\top}x}^{(\\ast\\ast)} - \\overbracket[.7pt][.7pt]{w^{(y)\\top}x}^{(\\ast\\ast\\ast)} \\}$\n\n\\textbf{Confidence:} $w^{(y)\\top}x \\geq \\max\\limits_{j\\neq y} w^{(i)\\top}x + 1$ {\\footnotesize$(\\ast)$}\n\n{\\setstretch{0.9}\n$\\nabla\\!_{w^{(j)}} \\ell =\n\\begin{cases}\n\t0\t& (\\ast)\\text{ satisfied \\textit{or} } j\\notin\\{y,\\hat y\\}\\\\\n\t-x\t& \\neg(\\ast) \\text{ and } j=y\t\t\\rightsquigarrow (\\ast\\ast)\\\\\n\t+x\t& \\neg(\\ast) \\text{ and } j=\\hat y\t\\rightsquigarrow (\\ast\\ast\\ast)\n\\end{cases}$\n}\n", "meta": {"hexsha": "419e04e16ccf6970fac77e106feb21e277f58d9b", "size": 766, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/IML19/sections/Multi-class.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/IML19/sections/Multi-class.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/IML19/sections/Multi-class.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.8181818182, "max_line_length": 178, "alphanum_fraction": 0.5652741514, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912913, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.703833885098487}}
{"text": "\n\\subsection{Covers}\n\nA space \\(X\\) is covered by a set of subsets of \\(X\\), \\(C\\), if the union of \\(C\\) is \\(X\\).\n\n\\subsection{Subcover}\n\nA subset of \\(C\\) which still covers \\(X\\) is a a subcover.\n\n\\subsection{Open cover}\n\n\\(C\\) is an open cover if each member is an open set.\n\n\\subsection{Universal cover}\n\n", "meta": {"hexsha": "92d41ccac2e07558609ca034872dcaa6b806d94c", "size": 311, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/topologyFinite/03-01-cover.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/topologyFinite/03-01-cover.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/topologyFinite/03-01-cover.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.4375, "max_line_length": 93, "alphanum_fraction": 0.6559485531, "num_tokens": 91, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802484881363, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.7038255855207506}}
{"text": "%!TEX root = ClementiCooperBarba2018.tex\n\nThe original implementation of \\pygbe used continuum electrostatic theory to compute\nthe solvation energy of biomolecular systems. In that setting, biomolecules are modeled as \ndielectric cavities inside an infinite continuum solvent, \nleading to a Poisson equation inside the molecules and Laplace or Poisson-Boltzmann in the solvent medium (with appropriate boundary conditions).\nThis set of partial differential equations can be \nexpressed with the corresponding boundary integral equation along the molecular interface, \nwhich \\pygbe solves using a boundary element method \\cite{CooperBardhanBarba2013,CooperClementiBarba2015}.\n\nThe present work extends \\pygbe to the LSPR biosensing application. \nIn the long-wavelength limit, Maxwell's equations can be approximated by a Laplace equation,\nwhich permits using the methods implemented in \\pygbe, with modifications\nto allow for complex-valued permittivities, and to include the\neffect of an external electric field.\nThis section describes the mathematical formulation for computing electromagnetic scattering \nin the long-wavelength setting, and develops the associated boundary integral equations \nand their discretized form.\n\n\\subsection{Scattering of small particles} \\label{sec:scattering_small}\n\nElectromagnetic scattering is usually modeled with Maxwell's equations.\nWhen the wavelength of the incoming wave is much larger than the\nscatterer, these can be reduced to a \\emph{quasi-static} \nfirst-order approximation \\cite{MayergoyzZhang2007}:\n%\n\\begin{align} \\label{eq:electrostatic_scatter_E}\n\\nabla \\cdot \\mathbf{E}_{1s} &= 0 \\qquad \\nabla \\times \\mathbf{E}_{1s} = 0, \\nonumber \\\\\n\\nabla \\cdot \\mathbf{E}_{2s} &= 0 \\qquad \\nabla \\times \\mathbf{E}_{2s} = 0, \\nonumber \\\\\n\\text{with interface conditions, } \\nonumber \\\\\n(\\epsilon_1\\mathbf{E}_{1s} - \\epsilon_2\\mathbf{E}_{2s})\\cdot\\mathbf{n} &= (\\epsilon_2-\\epsilon_1)\\mathbf{E}_i\\cdot \\mathbf{n}.\n\\end{align}\n%\nIn Equation \\eqref{eq:electrostatic_scatter_E}, $\\mathbf{E}_{1s}$ and $\\mathbf{E}_{2s}$ \nare the electric fields of the scattered wave in the nanoparticle and host regions, respectively \n(see Figure \\ref{fig:part_wave}), \n$\\mathbf{E}_{i}$ is the field of the incoming wave, and $\\epsilon_1$ \nand $\\epsilon_2$ are the permittivities.\nThis approximation decouples the electric and magnetic fields, neglects the magnetic field, \nand describes the electric field as a curl-free vector field.\nHence, we can reformulate Equation \\eqref{eq:electrostatic_scatter_E} with a scalar potential\n($-\\nabla \\phi_{js} = \\mathbf{E}_{js}$), as follows:\n%\n\\begin{align} \\label{eq:electrostatic_scatter}\n\\nabla^2 \\phi_{1s} &= 0 \\qquad \\nabla^2 \\phi_{2s} = 0 \\qquad\\text{on $\\Omega_1$, $\\Omega_2$} \\nonumber \\\\\n\\epsilon_1\\frac{\\partial\\phi_{1s}}{\\partial \\mathbf{n}} - \\epsilon_2\\frac{\\partial\\phi_{2s}}{\\partial\\mathbf{n}} &= (\\epsilon_2-\\epsilon_1)\\frac{\\partial\\phi_i}{\\partial\\mathbf{n}} \\quad \\phi_{1s} = \\phi_{2s} \\quad \\text{on $\\Gamma$}.\n\\end{align}\n%\nEquation \\eqref{eq:electrostatic_scatter} is an electrostatic equation \nwith an imposed electric field $\\mathbf{E}_i=-\\nabla\\phi_i$, where $\\Gamma$ \nis the boundary between regions $\\Omega_1$ and $\\Omega_2$.\n\n\\begin{figure}%[h] %  figure placement: here, top, bottom, or page\n   \\centering\n   \\includegraphics[width=0.45\\textwidth]{particle_wave.pdf} \n   \\caption{Nanoparticle interacting with an electromagnetic wave.}\n   \\label{fig:part_wave}\n\\end{figure}\n\n\\subsection{Far-field scattering} \\label{sec:ff_scattering}\n\nIn LSPR, the scattered electromagnetic wave is measured by a detector located far away \nfrom the scatterer (nanoparticle), and plasmon resonance is identified when the energy \ndetected is minimum. In the far-field limit, the scattered field\nin the outside region ($\\Omega_2$) is given by: \n\n\\begin{equation} \\label{eq:scat_efield_long_range}\n    \\mathbf{E}_{2s} = \\frac{1}{4\\pi\\epsilon_2}k^2\\frac{e^{ikr}}{r} (\\mathbf{\\hat{r}} \\times \\mathbf{p})\\times\\mathbf{\\hat{r}}.\n\\end{equation} \n\n\\noindent where $k=2\\pi/\\lambda$ is the wave number and $\\lambda$ the wavelength, $\\mathbf{\\hat{r}}$ \nis a unit vector in the direction of the observation point, and $\\mathbf{p}$ is\nthe dipole moment.\nWe can obtain the scattered field using the \nscattering amplitude \\cite{Jackson}:\n\n\\begin{equation} \\label{eq:scat_efield_fwa}\n    \\mathbf{E}_{2s}(\\mathbf{r})_{r\\to\\infty} = \\frac{e^{ikr}}{r} \\mathbf{F}(\\mathbf{k},\\mathbf{k}_0),\n\\end{equation}\n\n\\noindent where $\\mathbf{F}$ is the scattering amplitude, $\\mathbf{k}$ is the \nscattered wave vector in the direction of propagation, and $\\mathbf{k}_0$ the \nwave vector of the incident field. \n\n\\subsection{Extinction cross-section and optical theorem} \\label{sec:cext_ot}\n\nThe extinction cross-section ($C_\\text{ext}$) is a measure of the energy that \ndoes not reach the detector, either because of scattering in other directions,\nor absorption. This quantity is defined as the ratio between the lost energy and \nthe intensity of the incoming wave, and has units of area. \nThe extinction cross-section peaks at resonance of plasmons.\n\nThe extinction cross-section is related to the forward-scattering amplitude via the optical theorem. \nThe traditional expression for this relationship applies for non-absorbing media \n\\cite{MayergoyzZhang2007, Jackson}; \nMishchenko \\cite{Mishchenko2007} corrected it for absorbing media, \ngiving an expression that can be re-written using Jackson's notation \\cite{Jackson} as follows:\n\n\\begin{equation} \\label{eq:cext_fwa}\n    C_\\text{ext} = \\frac{4\\pi}{k^\\prime} \\operatorname{Im} \\left[ \\frac{\\mathbf{\\hat{e}}_i}{|\\mathbf{E}_i|}\\mathbf{F}(\\mathbf{k}=\\mathbf{k}_0, \\mathbf{k}_0) \\right].\n\\end{equation}\n\n\\noindent Here, $k^\\prime$ is the real part of the complex wave number, \n\n\\begin{equation}\n    k = k^\\prime + ik^{\\prime\\prime} = \\frac{2\\pi}{\\lambda} n,\n\\end{equation}\n\n\\noindent and $n$ is the refraction index of the host medium.\n\nCombining Equations \\eqref{eq:scat_efield_long_range} and \\eqref{eq:scat_efield_fwa},\nwe can compute the scattering amplitude to then obtain the extinction cross-section \nwith Equation \\eqref{eq:cext_fwa}.\n\n\n\\subsection{The boundary element method} \\label{sec:lspr_bem}\n\n\\subsubsection{Electrostatic potential of a nanoparticle under an electric field} \\label{sec:pot_elec_field}\n\n\\paragraph{Integral formulation}\n\nUsing Green's second identity, the system of partial differential equations \nin Equation \\eqref{eq:electrostatic_scatter} can be rewritten as a system \nof boundary integral equations \\cite{BrebbiaDominguez1992}. Evaluating on the surface $\\Gamma$, this\nbecomes\n%\n\\begin{align} \\label{eq:integral_eq_lspr_nobc}\n\\frac{\\phi_{1s,\\Gamma}}{2}+ K_{L}^{\\Gamma}(\\phi_{1s,\\Gamma}) - V_{L}^{\\Gamma} \\left(\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{1s,\\Gamma} \\right) = 0&  \\nonumber \\\\\n\\frac{\\phi_{2s,\\Gamma}}{2} - K_{L}^{\\Gamma}(\\phi_{2s,\\Gamma}) + V_{L}^{\\Gamma} \\left( \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{2s,\\Gamma} \\right) = 0&,\n\\end{align}\n%\nwhere $V$ and $K$ are the single- and double-layer operators, respectively:\n%\n\\begin{equation}\\label{eq:single_layer}\nV^{\\Gamma}_L (\\psi(\\mathbf{r}_\\Gamma)) = \\oint_\\Gamma \\psi(\\mathbf{r}'_\\Gamma) G_L(\\mathbf{r}_\\Gamma, \\mathbf{r}'_\\Gamma) \\text{d} \\Gamma',\n\\end{equation}\n%\n\\begin{equation}\\label{eq:double_layer}\nK^{\\Gamma}_L (\\psi(\\mathbf{r}_\\Gamma)) = \\oint_\\Gamma \\psi(\\mathbf{r}'_\\Gamma) \\frac{\\partial}{\\partial \\mathbf{n}}G_L(\\mathbf{r}_\\Gamma, \\mathbf{r}'_\\Gamma) \\text{d} \\Gamma'.\n\\end{equation}\n%\n\\noindent Here, $G_L$ is the free-space Green's function of the Laplace equation:\n%\n\\begin{equation}\nG_L(\\mathbf{r},\\mathbf{r}') = \\frac{1}{4\\pi|\\mathbf{r}-\\mathbf{r}'|}\n\\end{equation}\n\n\\noindent Applying the interface conditions of Equation \\eqref{eq:electrostatic_scatter},\nleads to:\n%\n\\begin{align} \\label{eq:integral_eq_lspr}\n\\frac{\\phi_{1s,\\Gamma}}{2}+ K_{L}^{\\Gamma}(\\phi_{1s,\\Gamma}) - V_{L}^{\\Gamma} \\left(\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{1s,\\Gamma} \\right) &= 0  \\nonumber \\\\\n\\frac{\\phi_{1s,\\Gamma}}{2} - K_{L}^{\\Gamma}(\\phi_{1s,\\Gamma}) + \\frac{\\epsilon_1}{\\epsilon_2}V_{L}^{\\Gamma} \\left( \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{1s,\\Gamma}  \\right) &= \\nonumber \\\\\n \\frac{\\epsilon_2-\\epsilon_1}{\\epsilon_2}V_{L}^{\\Gamma}\\left( \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{i,\\Gamma} \\right)\\quad \\text{on $\\Gamma$.}\n\\end{align}\n\n%The weak formulation of Laplace equation with test function $w$:\n\n%\\begin{equation} \\label{eq:lap_weak}\n%\\int_\\Omega \\nabla^2 \\phi(\\mathbf{r}_\\Omega') w(\\mathbf{r}_\\Omega') \\text{d} \\Omega^\\prime= 0.\n%\\end{equation}\n\n%\\noindent where the evaluation point is $\\mathbf{r}_\\Omega$ a location in the domain $\\Omega$.\n\n%If we use the Laplace's free-space Green's function as the test function $w$ we\n%get:\n\n%\\begin{equation} \\label{eq:lap_weak2}\n%\\int_\\Omega \\nabla^2 \\phi(\\mathbf{r}'_\\Omega) G_L(\\mathbf{r}_\\Omega,\\mathbf{r}'_\\Omega) \\text{d} \\Omega^\\prime= 0.\n%\\end{equation}\n\n%Manipulating the integrand using the product rule and later the divergence \n%theorem, we get:\n\n%\\begin{equation} \\label{eq:lap_bie_dom}\n%\\phi(\\mathbf{r}_\\Omega) = \\oint_\\Gamma G_L(\\mathbf{r}_\\Omega,\\mathbf{r}'_\\Gamma)  \\frac{\\partial} {\\partial \\mathbf{n}} \\phi(\\mathbf{r}'_\\Gamma)  \\text{d} \\Gamma^\\prime - \\oint_\\Gamma \\phi(\\mathbf{r}'_\\Gamma)  \\frac{\\partial}{\\partial \\mathbf{n}} G_L(\\mathbf{r}_\\Omega,\\mathbf{r}'_\\Gamma) \\text{d} \\Gamma^\\prime\n%\\end{equation}\n\n%\\noindent where \\eqref{eq:lap_bie_dom}, $\\mathbf{r}$ can be anywhere in the domain $\\Omega$, \n%and $\\mathbf{r}'$ runs only on the boundary $\\Gamma$. This equation has a \n%singularity when $\\mathbf{r}=\\mathbf{r}'$. To handle this problem, we perform the\n%integral on a surface $\\Gamma'$ that is like $\\Gamma$ but with a hemisphere of \n%radius $\\varepsilon$ center at $\\mathbf{r}$. We split the integrals into the part\n%that we have no singularity and the part that has the hemisphere. After solving these\n%equations when $\\varepsilon \\to 0$, equation \\eqref{eq:lap_bie_dom} results in:\n\n%\\begin{equation} \\label{eq:lap_bie}\n%\\frac{\\phi(\\mathbf{r}_\\Gamma)}{2} +  \\oint_\\Gamma \\phi(\\mathbf{r}'_\\Gamma)  \\frac{\\partial}{\\partial \\mathbf{n}} G_L(\\mathbf{r}_\\Gamma,\\mathbf{r}'_\\Gamma) \\text{d} \\Gamma^\\prime = \\oint_\\Gamma G_L(\\mathbf{r}_\\Gamma,\\mathbf{r}'_\\Gamma)  \\frac{\\partial} {\\partial \\mathbf{n}} \\phi(\\mathbf{r}'_\\Gamma)  \\text{d} \\Gamma^\\prime,\n%\\end{equation}\n\n%\\noindent where these are Cauchy principal value integrals.\n\n%Using the single and double layer operators:\n\n%{\\color{red} Chris, V is single layer operator but is it K the double layer one? \n%In your thesis you have that the double layer is W and you refers as K as\n%\"an operator\" eq 2.108 and 2.112 in your thesis. Also shouldn't the $\\text{d} \\Gamma$\n%be $\\text{d} \\Gamma'$? }\n\n%\\begin{equation}\\label{eq:single_layer}\n%V^{\\mathbf{r}_\\Gamma}_L (\\psi(\\mathbf{r}_\\Gamma)) = \\oint_\\Gamma \\psi(\\mathbf{r}'_\\Gamma) G_L(\\mathbf{r}_\\Gamma, \\mathbf{r}'_\\Gamma) \\text{d} \\Gamma.\n%\\end{equation}\n\n%\\begin{equation}\\label{eq:double_layer}\n%K^{\\mathbf{r}_\\Gamma}_L (\\psi(\\mathbf{r}_\\Gamma)) = \\oint_\\Gamma \\psi(\\mathbf{r}'_\\Gamma) \\frac{\\partial}{\\partial \\mathbf{n}}G_L(\\mathbf{r}_\\Gamma, \\mathbf{r}'_\\Gamma) \\text{d} \\Gamma.\n%\\end{equation}\n\n%We can rewrite equation \\eqref{eq:lap_bie} using the operator notation, as:\n\n%\\begin{equation} \\label{eq:lap_operator}\n%\\left[ \\frac{\\mathbb{I}}{2} + K_L^{\\mathbf{r}_\\Gamma} \\right] \\left( \\phi_\\Gamma \\right) = V_L^{\\mathbf{r}_\\Gamma} \\left( \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_\\Gamma \\right),\n%\\end{equation}\n\n%\\noindent where $\\mathbb{I}$ is the identity operator.\n\n%Following the same steps, we can rewrite the Laplace equations in equation\n%\\eqref{eq:electrostatic_scatter} as:\n\n%\n%\\begin{align} \\label{eq:integral_eq_lspr_nobc}\n%\\frac{\\phi_{1s,\\Gamma}}{2}+ K_{L}^{\\Gamma}(\\phi_{1s,\\Gamma}) - V_{L}^{\\Gamma} \\left(\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{1s,\\Gamma} \\right) = 0&  \\nonumber \\\\\n%\\frac{\\phi_{2s,\\Gamma}}{2} - K_{L}^{\\Gamma}(\\phi_{2s,\\Gamma}) + V_{L}^{\\Gamma} \\left( \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{2s,\\Gamma} \\right) = 0& \\quad \\text{on $\\Gamma$,}\n%\\end{align}\n\n%Applying the interface conditions of Equation \\eqref{eq:electrostatic_scatter},\n%we get:\n\n%\\begin{align} \\label{eq:integral_eq_lspr}\n%\\frac{\\phi_{1s,\\Gamma}}{2}+ K_{L}^{\\Gamma}(\\phi_{1s,\\Gamma}) - V_{L}^{\\Gamma} \\left(\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{1s,\\Gamma} \\right) = 0&  \\nonumber \\\\\n%\\frac{\\phi_{1s,\\Gamma}}{2} - K_{L}^{\\Gamma}(\\phi_{1s,\\Gamma}) + \\frac{1}{\\epsilon_2}V_{L}^{\\Gamma} \\left( \\epsilon_1 \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{1s,\\Gamma} - (\\epsilon_2-\\epsilon_1) \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{i,\\Gamma} \\right) = 0& \\quad \\text{on $\\Gamma$.}\n%\\end{align}\n\n\\newpage\n\\subsubsection{Analyte-sensor electrostatic potential under an electric field}\n\n\nThe sketch in Figure \\ref{fig:analyte-sensor} shows a metallic nanoparticle ($\\Omega_1$) interacting with an analyte ($\\Omega_3$), under an external electric field.\nMathematically, this situation can be modeled as\n\n\\begin{align}\\label{eq:electrostatic_scatter_prot_sen}\n\\nabla^2 \\phi_{1s} &= 0, \\qquad \\nabla^2 \\phi_{2s} = 0 \\qquad\\text{on $\\Omega_1$, $\\Omega_2$} \\nonumber\\\\\n\\nabla^2 \\phi_{3s} &= -\\frac{1}{\\epsilon_3} \\sum_{k=0}^{N_q} \\delta(|\\mathbf{r}-\\mathbf{r}_k|) q_k \\qquad\\text{on $\\Omega_3$} \\nonumber \\\\\n\\epsilon_1\\frac{\\partial\\phi_{1s}}{\\partial \\mathbf{n}} - \\epsilon_2\\frac{\\partial\\phi_{2s}}{\\partial\\mathbf{n}} &= (\\epsilon_2-\\epsilon_1)\\frac{\\partial\\phi_i}{\\partial\\mathbf{n}} \\quad \\phi_{1s} = \\phi_{2s} \\quad \\text{on $\\Gamma_1$}. \\nonumber\\\\\n\\epsilon_3\\frac{\\partial\\phi_{3s}}{\\partial \\mathbf{n}} - \\epsilon_2\\frac{\\partial\\phi_{2s}}{\\partial\\mathbf{n}} &= (\\epsilon_2-\\epsilon_3)\\frac{\\partial\\phi_i}{\\partial\\mathbf{n}} \\quad \\phi_{3s} = \\phi_{2s} \\quad \\text{on $\\Gamma_2$}.\n\\end{align}\n%\nwhere $q_k$ are the point charges of the atoms inside the protein, located at $\\mathbf{r}_k$.\n\n\\paragraph{Integral formulation}\n\nSimilar to Equation \\eqref{eq:integral_eq_lspr}, we can write the system of partial differential equations in \\eqref{eq:electrostatic_scatter_prot_sen} as\n\n\n\\begin{widetext} % to get the full-pagewidth equations in the two-column layout\n\n\n\\begin{align} \\label{eq:integral_eq_lspr_nobc_system}\n\\frac{\\phi_{1s,\\Gamma_1}}{2}+ K_{L,\\Gamma_1}^{\\Gamma_1}(\\phi_{1s,\\Gamma_1}) - V_{L,\\Gamma_1}^{\\Gamma_1} \\left(\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{1s,\\Gamma_1} \\right) &= 0  \\nonumber \\\\\n\\frac{\\phi_{2s,\\Gamma_1}}{2} - K_{L,\\Gamma_1}^{\\Gamma_1}(\\phi_{2s,\\Gamma_1}) + V_{L,\\Gamma_1}^{\\Gamma_1} \\left(\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{2s,\\Gamma_1} \\right) \n - K_{L,\\Gamma_2}^{\\Gamma_1}(\\phi_{2s,\\Gamma_2}) + V_{L,\\Gamma_2}^{\\Gamma_1} \\left(\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{2s,\\Gamma_2} \\right) &= 0  \\nonumber \\\\\n\\frac{\\phi_{2s,\\Gamma_2}}{2} - K_{L,\\Gamma_1}^{\\Gamma_2}(\\phi_{2s,\\Gamma_1}) + V_{L,\\Gamma_1}^{\\Gamma_2} \\left(\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{2s,\\Gamma_1} \\right)  \n- K_{L,\\Gamma_2}^{\\Gamma_2}(\\phi_{2s,\\Gamma_2}) + V_{L,\\Gamma_2}^{\\Gamma_2} \\left(\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{2s,\\Gamma_2} \\right) &= 0  \\nonumber \\\\\n\\frac{\\phi_{3s,\\Gamma_2}}{2} + K_{L,\\Gamma_2}^{\\Gamma_2}(\\phi_{3s,\\Gamma_2}) - V_{L,\\Gamma_2}^{\\Gamma_2} \\left( \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{3s,\\Gamma_2} \\right) &= \\frac{1}{4\\pi\\epsilon_3} \\sum_{k=0}^{N_q} \\frac{q_k}{|\\mathbf{r}_{\\Gamma_2} - \\mathbf{r}_k|} ,\n\\end{align}\n%\n\\noindent where $V$ and $K$ are the single- and double-layer operators in equations \n\\eqref{eq:single_layer} and \\eqref{eq:double_layer}. In this case, we distinguish between the\nsurface where the integrals run (subindex), and the surface that contains the evaluation point (superindex).\n\nApplying the interface conditions of equation \\eqref{eq:electrostatic_scatter_prot_sen},\nleads to: \n\n\n\\begin{align} \\label{eq:integral_eq_lspr_system}\n\\frac{\\phi_{1s,\\Gamma_1}}{2}&+ K_{L,\\Gamma_1}^{\\Gamma_1}(\\phi_{1s,\\Gamma_1}) - V_{L,\\Gamma_1}^{\\Gamma_1} \\left(\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{1s,\\Gamma_1} \\right) = 0  \\nonumber \\\\\n \\frac{\\phi_{1s,\\Gamma_1}}{2}& - K_{L,\\Gamma_1}^{\\Gamma_1}(\\phi_{1s,\\Gamma_1}) + V_{L,\\Gamma_1}^{\\Gamma_1} \\left(\\frac{\\epsilon_1}{\\epsilon_2}\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{1s,\\Gamma_1} \\right) - V_{L,\\Gamma_1}^{\\Gamma_1} \\left(\\frac{\\epsilon_2-\\epsilon_1}{\\epsilon_2}\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{i,\\Gamma_1} \\right) \\nonumber\\\\ \n & - K_{L,\\Gamma_2}^{\\Gamma_1}(\\phi_{3s,\\Gamma_2}) + V_{L,\\Gamma_2}^{\\Gamma_1} \\left(\\frac{\\epsilon_3}{\\epsilon_2}\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{3s,\\Gamma_2} \\right)  - V_{L,\\Gamma_2}^{\\Gamma_1} \\left(\\frac{\\epsilon_2 -\\epsilon_3}{\\epsilon_2}\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{i,\\Gamma_2} \\right) = 0   \\nonumber \\\\\n \\frac{\\phi_{3s,\\Gamma_1}}{2}& - K_{L,\\Gamma_1}^{\\Gamma_2}(\\phi_{1s,\\Gamma_1}) + V_{L,\\Gamma_1}^{\\Gamma_2} \\left(\\frac{\\epsilon_1}{\\epsilon_2}\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{1s,\\Gamma_1} \\right) - V_{L,\\Gamma_1}^{\\Gamma_2} \\left(\\frac{\\epsilon_2-\\epsilon_1}{\\epsilon_2}\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{i,\\Gamma_1} \\right) \\nonumber \\\\\n& - K_{L,\\Gamma_2}^{\\Gamma_2}(\\phi_{3s,\\Gamma_2}) + V_{L,\\Gamma_2}^{\\Gamma_2} \\left(\\frac{\\epsilon_3}{\\epsilon_2}\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{3s,\\Gamma_2} \\right)  - V_{L,\\Gamma_2}^{\\Gamma_2} \\left(\\frac{\\epsilon_2 -\\epsilon_3}{\\epsilon_2}\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{i,\\Gamma_2} \\right) = 0  \\nonumber \\\\\n\\frac{\\phi_{3s,\\Gamma_2}}{2}& + K_{L,\\Gamma_2}^{\\Gamma_2}(\\phi_{3s,\\Gamma_2}) - V_{L,\\Gamma_2}^{\\Gamma_2} \\left( \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{3s,\\Gamma_2} \\right) = \\frac{1}{4\\pi\\epsilon_3} \\sum_{k=0}^{N_q} \\frac{q_k}{|\\mathbf{r}_{\\Gamma_2} - \\mathbf{r}_k|} \n\\end{align}\n\\end{widetext}\n\n\n\\begin{figure}%[b] %  figure placement: here, top, bottom, or page\n    \\centering\n    \\includegraphics[width=0.25\\textwidth]{protein_sensor_regions.pdf} \n    \\caption{Analyte-sensor system under electric field.}\n    \\label{fig:analyte-sensor}\n \\end{figure}\n\n\\paragraph{Discretization and linear system}\n\nWe discretize the surface into flat triangles, and assume that  $\\phi$ and \n$\\partial \\phi/\\partial \\mathbf{n}$ are constant within each element. We can\nthen write the layer operators in their discretized form as follows:\n%\n\\begin{align} \\label{eq:layers_disc}\nV_{L,\\text{disc}}^{\\mathbf{r}_\\Gamma} \\left( \\frac{\\partial}{\\partial \\mathbf{n}} \\phi(\\mathbf{r}_{\\Gamma}) \\right) &= \\sum_{j=1}^{N_p} \\frac{\\partial}{\\partial \\mathbf{n}} \\phi(\\mathbf{r}_{\\Gamma_j}) \\int_{\\Gamma_j} G_L(\\mathbf{r}_\\Gamma,\\mathbf{r}_{\\Gamma_j})  \\mathrm{d} \\Gamma_j  \\nonumber \\\\\nK_{L,\\text{disc}}^{\\mathbf{r}_\\Gamma}(\\phi(\\mathbf{r}_{\\Gamma})) &=  \\sum_{j=1}^{N_p}\\phi(\\mathbf{r}_{\\Gamma_j})\\int_{\\Gamma_j} \\frac{\\partial}{\\partial \\mathbf{n}} \\left[ G_L(\\mathbf{r}_\\Gamma,\\mathbf{r}_{\\Gamma_j}) \\right]\\mathrm{d} \\Gamma_j\n\\end{align}\n%\n\\noindent where $N_p$ is the number of discretization elements on $\\Gamma$, \nand $\\phi(\\mathbf{r}_{\\Gamma_j})$ and $\\frac{\\partial}{\\partial \\mathbf{n}} \n\\phi(\\mathbf{r}_{\\Gamma_j})$ are the values of $\\phi$ and \n$\\frac{\\partial \\phi}{\\partial \\mathbf{n}}$ on panel $\\Gamma_j$.\nUsing centroid collocation, we can write equation \\eqref{eq:integral_eq_lspr} in matrix form as:\n%\n \\begin{equation} \\label{eq:matrix_lspr}\n \\left[\n    \\begin{matrix} \n       \\frac{1}{2} + K_{L}^{\\Gamma} & -V_{L}^{\\Gamma}  \\vspace{0.2cm} \\\\\n       \\frac{1}{2} - K_{L}^{\\Gamma} &  \\frac{\\epsilon_1}{\\epsilon_2} V_{L}^{\\Gamma}  \\vspace{0.2cm} \n    \\end{matrix}\n    \\right] \\left[ \n    \\begin{matrix} \n       \\phi_{1s,\\Gamma} \\vspace{0.2cm} \\\\\n       \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{1s,\\Gamma} \\vspace{0.2cm}\n    \\end{matrix} \n     \\right] =   \n    \\left[\n    \\begin{matrix} \n       0 \\\\\n       V_{L}^{\\Gamma} \\left(\\frac{\\epsilon_2-\\epsilon_1}{\\epsilon_2} \\frac{\\partial\\phi_i}{\\partial\\mathbf{n}}\\right) \\vspace{0.2cm} \n    \\end{matrix}\n    \\right]\n \\end{equation}\n%\nEquation \\eqref{eq:integral_eq_lspr_system} can be represented as:\n%\n\\begin{align} \\label{eq:matrix_multi}\n \\left[\n    \\begin{matrix} \n       \\frac{1}{2}+K_{L, \\Gamma_1}^{\\Gamma_1} & -V_{L, \\Gamma_1}^{\\Gamma_1} & 0 &  0   \\vspace{0.2cm} \\\\\n       \\frac{1}{2}-K_{L, \\Gamma_1}^{\\Gamma_1} & \\frac{\\epsilon_1}{\\epsilon_2} V_{L, \\Gamma_1}^{\\Gamma_1} & -K_{L, \\Gamma_2}^{\\Gamma_1} & \\frac{\\epsilon_3}{\\epsilon_2} V_{L, \\Gamma_2}^{\\Gamma_1} \\vspace{0.2cm}  \\\\\n        -K_{L, \\Gamma_1}^{\\Gamma_2}&\\frac{\\epsilon_1}{\\epsilon_2} V_{L, \\Gamma_1}^{\\Gamma_2} & \\frac{1}{2}-K_{L, \\Gamma_2}^{\\Gamma_2}  &  \\frac{\\epsilon_3}{\\epsilon_2} V_{L, \\Gamma_2}^{\\Gamma_2} \\vspace{0.2cm} \\\\\n       0 & 0 & \\frac{1}{2}+K_{L, \\Gamma_2}^{\\Gamma_2}&  - V_{L, \\Gamma_2}^{\\Gamma_2}   \\vspace{0.2cm} \\\\\n    \\end{matrix}\n    \\right] \n\\cdot\n \\left[\n    \\begin{matrix}\n    \\phi_{1,\\Gamma_1} \\vspace{0.2cm} \\\\\n    \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{1,\\Gamma_1} \\vspace{0.2cm} \\\\\n    \\phi_{3,\\Gamma_2} \\vspace{0.2cm} \\\\\n    \\frac{\\partial}{\\partial \\mathbf{n}} \\phi_{3,\\Gamma_2} \\vspace{0.2cm} \\\\\n    \\end{matrix}\n\\right]&\n \\nonumber \\\\\n = \\left[\n    \\begin{matrix}\n    0 \\vspace{0.2cm} \\\\\n    V_{L,\\Gamma_1}^{\\Gamma_1} \\left(\\frac{\\epsilon_2-\\epsilon_1}{\\epsilon_2}\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{i,\\Gamma_1} \\right)\n    + V_{L,\\Gamma_2}^{\\Gamma_1} \\left(\\frac{\\epsilon_2 -\\epsilon_3}{\\epsilon_2}\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{i,\\Gamma_2} \\right)\n    \\vspace{0.2cm}\\\\\n    V_{L,\\Gamma_1}^{\\Gamma_2} \\left(\\frac{\\epsilon_2-\\epsilon_1}{\\epsilon_2}\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{i,\\Gamma_1} \\right)\n    + V_{L,\\Gamma_2}^{\\Gamma_2} \\left(\\frac{\\epsilon_2 -\\epsilon_3}{\\epsilon_2}\\frac{\\partial}{\\partial \\mathbf{n}}\\phi_{i,\\Gamma_2} \\right)\n    \\vspace{0.2cm}\\\\\n    \\frac{1}{4\\pi\\epsilon_3}\\sum_{k=0}^{N_q} \\frac{q_k}{|\\mathbf{r}_{\\Gamma_2} - \\mathbf{r}_k|} \\vspace{0.2cm}  \\\\\n    \\end{matrix}\n\\right]&\n\\end{align}\n%\n\\noindent where the elements of the matrix are\n%\n\\begin{align} \\label{eq:layers_element}\nV_{L,ij}^{\\Gamma} &= \\int_{\\Gamma_j} G_L(\\mathbf{r}_{\\Gamma_i},\\mathbf{r}_{\\Gamma_j})  \\mathrm{d} \\Gamma_j, \\nonumber \\\\\nK_{L,ij}^{\\Gamma} &= \\int_{\\Gamma_j} \\frac{\\partial}{\\partial \\mathbf{n}} \\left[ G_L(\\mathbf{r}_{\\Gamma_i},\\mathbf{r}_{\\Gamma_j}) \\right]\\mathrm{d} \\Gamma_j,\n\\end{align}\n%\n\\noindent with $\\mathbf{r}_{\\Gamma_i}$ being at the center of panel $\\Gamma_i$.\n\n\n\\paragraph{Integral evaluation}\n\nWe evaluate the integrals in Equation \\eqref{eq:layers_element} with Gauss quadrature\nrules. The $1/r$ singularity of the Green's function poses a\nproblem to obtaining good accuracy when the integral is \nsingular or near-singular. Therefore, we define three different regions, as follows.\n\\begin{description}\n\\item[Singular integrals:] If the collocation point is in the integration element,\nthe singularity is difficult to resolve with standard\nGauss integration schemes. In this case, we use a semi-analytical technique \n\\cite{HessSmith1967,ZhuHuangSongWhite2001} that places $N_k$ quadrature nodes on the \nedges of the triangle.\n\n\\item[Near-singular integrals:] If the collocation point is close to the integration element,\nthe integrand has a high gradient, and high-order quadrature rules are required. \nWe use the representative length of the integrated triangle ($L = \\sqrt{2\\cdot\\text{Area}}$)\nto define a threshold of the \\emph{nearby} region, for example, when the integration panel \nis $2L$ or less away from the collocation point. For near-singular integrals, we use \n$K_{fine}=19, 25  \\text{ or }  37$ points per triangle. \n\n\\item[Far-away integrals:] When the distance between the collocation point and the integration\nelement is beyond the threshold, they are considered to be far-away. \nAt this point, the integrand is smooth enough that we obtain good \naccuracy with low-order integration, for example, with \n$K=1, 3  \\text{ or } 4$ Gauss quadrature points per boundary element. \n\\end{description}\n\n\\subsubsection{Boundary integral expression of the dipole moment}\n\nAs shown in Equation \\eqref{eq:scat_efield_long_range}, the scattered electric \nfield in the far-away limit depends on the dipole moment. The dipole moment is \ndefined as \n%\n\\begin{equation} \\label{eq:dipole_def}\n\\mathbf{p} = \\int_\\Omega \\mathbf{r} \\rho \\text{d}\\Omega,\n\\end{equation}\n%\nand rewriting this equation using Gauss' law, we obtain\n%\n\\begin{equation} \\label{eq:dipole_def_gauss}\n\\mathbf{p} = -\\epsilon_2\\int_\\Omega \\mathbf{r} \\nabla^2 \\phi_{2s} \\text{d}\\Omega.\n\\end{equation}\n%\nFor component $i$, this becomes:\n%\n\\begin{equation} \\label{eq:dipole_def_gauss_i}\n{p_i} = -\\epsilon_2\\int_\\Omega {x_i} \\nabla^2 \\phi_{2s} \\text{d}\\Omega.\n\\end{equation}\n%\nUsing the identity\n%\n\\begin{equation} \\label{eq:identity_grad}\n  \\nabla \\cdot \\left(f \\mathbf{v}\\right) = \\left( \\nabla f \\right)\\cdot \\mathbf{v} + f\\left(\\nabla \\cdot \\mathbf{v}\\right)\n\\end{equation}\n%\nwith $f=x_i$ and $\\mathbf{v} = \\nabla\\phi_{2s}$, we can rewrite Equation \\eqref{eq:dipole_def_gauss_i}\nas \n%\n\\begin{equation}\n- \\frac{p_i}{\\epsilon_2} = \\int_\\Omega \\nabla \\cdot \\left( x_i \\nabla \\phi_{2s} \\right) \\; \\text{d}\\Omega - \\int_\\Omega \\nabla x_i \\cdot \\nabla\\phi_{2s} \\; \\text{d}\\Omega, \\nonumber \n\\end{equation}\n\\noindent and applying the divergence theorem\n\\begin{equation} \\label{eq:dip_gauss_interm_1}\n- \\frac{p_i}{\\epsilon_2}= \\oint_\\Gamma  x_i  \\nabla \\phi_{2s} \\cdot \\mathbf{n} \\; \\text{d}\\Gamma - \\int_\\Omega \\nabla x_i \\cdot \\nabla\\phi_{2s} \\; \\text{d}\\Omega.\n\\end{equation}\n%\nUsing the identity \\eqref{eq:identity_grad} again in Equation \\eqref{eq:dip_gauss_interm_1}, this time \ntaking $f=\\phi_{2s}$ and $\\mathbf{v} = \\nabla x_i$, we get:\n%\n\\begin{align} \\label{eq:dip_gauss_interm_2}\n - \\frac{p_i}{\\epsilon_2} =& \\oint_\\Gamma  x_i  \\frac{\\partial \\phi_{2s}}{\\partial \\mathbf{n}} \\text{d}\\Gamma - \\nonumber \\\\\n & \\left[ \\int_\\Omega \\nabla \\cdot \\left( \\phi_{2s} \\nabla x_i \\right)\\;\\text{d}\\Omega - \\int_\\Omega  \\phi_{2s} \\nabla^2 x_i \\;\\text{d}\\Omega\\right] \\nonumber\\\\\n%&\\text{and applying the divergence theorem} \\nonumber \\\\\n=& \\oint_\\Gamma  x_i  \\frac{\\partial \\phi_{2s}}{\\partial \\mathbf{n}} \\; \\text{d}\\Gamma - \\oint_\\Gamma \\phi_{2s} \\nabla x_i \\cdot \\mathbf{n} \\; \\text{d}\\Gamma \\nonumber \\\\\n=& \\oint_\\Gamma  x_i  \\frac{\\partial \\phi_{2s}}{\\partial \\mathbf{n}} \\; \\text{d}\\Gamma - \\oint_\\Gamma \\phi_{2s} n_i \\;\\text{d}\\Gamma\n\\end{align}\n%\nThroughout this derivation, the normals are pointing into $\\Omega_1$. However, in our implementation \nall normals are pointing outwards, and we need to include an extra negative sign, yielding:\n%\n\\begin{equation} \\label{eq:dipole_def_gauss_i_final}\n{p_i} = \\epsilon_2 \\left[ \\oint_\\Gamma  x_i  \\frac{\\partial \\phi_{2s}}{\\partial \\mathbf{n}} \\text{d}\\Gamma - \\oint_\\Gamma \\phi_{2s} n_i \\; \\text{d}\\Gamma \\right].\n\\end{equation}\n\nUsing BEM, we obtain the electrostatic potential and its normal derivative, on the surface of the nanoparticle, \nwhich we use in Equation \\eqref{eq:dipole_def_gauss_i_final} to get the dipole \nmoment, and in Equation \\eqref{eq:scat_efield_long_range} to obtain the scattered\nelectric field. We can then use Equation \\eqref{eq:scat_efield_fwa} and Equation \n\\eqref{eq:cext_fwa} to get the extinction cross section.\n\n\\subsection{Acceleration strategies} \\label{sec:acc_strategies}\n\nOne disadvantage of the Boundary Element Method (BEM) is that it generates dense matrices\nafter discretization. Solving the resulting linear system using\nGaussian elimination would require $\\O{N^3}$ computations and $\\O{N^2}$ storage, whereas for a\nKrylov-subspace iterative solver, like the Generalized Minimal Residual Method (GMRES),\ncomputations drop to $\\O{N^2}$ because they are dominated by dense matrix-vector \nproducts. This makes BEM inefficient with more than a few thousand boundary elements,\nwhich are the mesh sizes required for real applications. \n\nIn our formulation with Gaussian quadrature and collocation, the matrix-vector product\nbecomes an $N$-body problem, with Gauss nodes acting as centers of mass (\\emph{sources}), \nand the collocation points acting as evaluation points for the potential (\\emph{targets}).\nTo overcome the unfavorable scaling,\nwe accelerate the matrix-vector product using a treecode algorithm \\cite{BarnesHut1986,DuanKrasny2001}, \nwhich is a fast-summation algorithm capable of reducing $\\O{N^2}$\ncomputational patterns like\n%\n\\begin{equation} \\label{eq:summation}\nV(\\mathbf{x}_i) = \\sum_{j=1}^{N} q_j \\psi(\\mathbf{x}_i, \\mathbf{y}_j) \n\\end{equation}\n%\n\\noindent to a computational complexity of $\\O{N \\log N}$. In Equation \\eqref{eq:summation} \n$q_j$ is the weight, $\\psi$ the kernel, $\\mathbf{y}_j$ the locations of sources and \n$\\mathbf{x}_i$ the locations of targets.\n\nThe treecode groups sources geometrically in boxes of an octree, built ensuring\nthat no box in the lowest level has more than $N_\\text{crit}$ sources. If a group of\nsources is far away from a target, their influence is aggregated at an expansion center,\nand the target interacts with the box, rather than with each source independently.\nIf the group of targets is  close, the treecode queries the child\nboxes. If the box has no children and still is not far enough, the interaction is \nperformed directly via \\eqref{eq:summation}.\n The threshold to decide if a box is far enough is called the multipole-\nacceptance criterion (MAC), defined as:\n%\n\\begin{equation}\n\\theta > \\frac{r_b}{r},\n\\end{equation}\n%\n\\noindent where $r_b$ is the box size and $r$ the distance between the box center and the target.\nCommon values of $\\theta$ are $1/2$ and $2/3$.\nTo approximate the contribution of the sources, we use Taylor expansions\nof order $P$.\nThe treecode allows us to control the accuracy of the approximation by modifying $\\theta$ and $P$.\nFurther details of the treecode implementation in \\pygbe can be found in \\cite{CooperBarba-share154331,CooperBardhanBarba2013}.\n\n\\subsection{Code modifications and added features} \\label{sec:code_imp}\n\nAs mentioned at the beginning of this section, the present work extends the \\pygbe code\nto allow its application to nano-plasmonics. \nThe code required the following modifications and added features:\n\n\\begin{itemize}\n    \\item Re-writing the GMRES solver to accept complex numbers. \n    \\item Splitting treecode calculations into real and imaginary parts.\n    \\item Re-formatting configuration files to include electric field intensity and  wavelength.\n    \\item Adding the new function \\texttt{read\\_electric\\_field}, to read the electric field intensity and its wavelength from configuration files.\n    \\item Adding the new function \\texttt{dipole\\_moment} to compute numerically the dipole moment by Equation \\eqref{eq:dipole_def_gauss_i_final}.\n    \\item Adding a new function to compute the  extinction cross section (\\texttt{extinction\\_cross\\_section}).\n    \\item Organizing LSPR computations on a different main script (called \\texttt{lspr.py}).\n\\end{itemize}\n\n\\noindent For information about how to use the code, run examples and tests, see the\n\\pygbe documentation at \\url{http://barbagroup.github.io/pygbe/docs/}\n\n\\subsection{Protein mesh preparation}\nIn Figure \\ref{fig:analyte-sensor}, $\\Omega_3$ is a region that represents the analyte molecule, which contains a point charge distribution of the partial charges, and is interfaced with the solvent by $\\Gamma_2$, the solvent excluded surface (\\texttt{SES}).\nThe \\texttt{SES} is generated by rolling a spherical probe of the size of a water molecule ($1.4$\\AA~ radius) around the analyte, and tracking the points where the probe and molecule make contact.\nThe open-source software Nanoshaper \\cite{Nanoshaper} uses the molecular structure to produce a triangulation of the \\texttt{SES}, which can be read by our software.\nIn particular, Nanoshaper takes as inputs the atomic coordinates, obtained from the Protein Data Bank, and radii, which were \nextracted from a \\texttt{pqr} file generated with \\texttt{pdb2pqr} \\cite{Dolinsky04}.\nWe obtained the charge and van der Waals parameters of the analyte from \\texttt{pdb2pqr} using the built-in \\texttt{amber} force field.\nIn support of the reproducibility of our results, we deposited the final meshes in the Zenodo data repository.\nSee section \\ref{sec:repro} for details.\n\n", "meta": {"hexsha": "2c13b19cb3c612ca7ddc629f61a11735eb1014e9", "size": 32033, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/methods.tex", "max_stars_repo_name": "barbagroup/pygbe_lspr_paper", "max_stars_repo_head_hexsha": "4517bb350646fdbab483b68fd0685600149faa12", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-12-01T03:19:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-02T21:00:00.000Z", "max_issues_repo_path": "tex/methods.tex", "max_issues_repo_name": "barbagroup/pygbe_lspr_paper", "max_issues_repo_head_hexsha": "4517bb350646fdbab483b68fd0685600149faa12", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2018-08-03T15:45:54.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-03T22:28:51.000Z", "max_forks_repo_path": "tex/methods.tex", "max_forks_repo_name": "barbagroup/pygbe_lspr_paper", "max_forks_repo_head_hexsha": "4517bb350646fdbab483b68fd0685600149faa12", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-01T03:19:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-01T03:19:36.000Z", "avg_line_length": 59.3203703704, "max_line_length": 353, "alphanum_fraction": 0.7155121281, "num_tokens": 10851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.7662936430859598, "lm_q1q2_score": 0.703825572296614}}
{"text": "\\documentclass[letterpaper,12pt,leqno]{article}\n\\usepackage{paper,math,notes}\n\n\\begin{document}\n\n\\title{Mathematical Methods for Macroeconomics: One-Hour Exam}\n\\author{Pascal Michaillat}\n\\date{}\n\n\\begin{titlepage}\n\\maketitle\n\\end{titlepage}\n\n\\section*{Question 1. (50 pts)}\n\nLet $\\a \\in (0,1)$, $\\d  \\in (0,1)$, $\\rho \\in (0,1)$, and $\\s>0$. Impose that $\\rho+\\d<1$. Given $k(0)$, we want to find the function $c(t) $ to maximize \n\\begin{equation*}\n\\int_{0}^{+\\infty }e^{-\\rho\\cdot  t}\\cdot \\frac{c(t)^{1-\\s}-1}{1-\\s} dt,\n\\end{equation*}\nsubject to the law of motion\n\\begin{equation*}\n\\dot{k}(t) =k(t)^{\\a}-c(t)-\\d \\cdot k(t).\n\\end{equation*}\n\n\\begin{enumerate}\n\n\\item (20 pts) Which variable do you choose as a state variable? Which variable do you choose as a control variable? Write down the current-value Hamiltonian and derive the optimality conditions.\n\n\\item (5 pts) The Euler equation is the first-order differential equation that characterizes the optimal function $c(t)$. Determine the Euler equation.\n\n\\item (10 pts) Suppose $\\a =1$ and $\\s =1$. Show that the system describing the optimal functions $\\{k(t),c(t)\\}$ reduces to a linear, homogenous system of first-order differential equations. Show that the system is unstable by computing the eigenvalues. \n\n\\item (15 pts) Suppose $\\a <1$ and $\\s >0$. Show that the system describing the optimal functions $\\{k(t),c(t)\\}$ reduces to a nonlinear system of first-order differential equations. Use a phase-diagram to show that the steady state of the system is a saddle point. Explain how you draw the phase diagram.\n\n\\end{enumerate}\n\n\\section*{Question 2. (50 pts)}\n\nLet $\\b \\in (0,1)$ and $r>0$. Given $k_{0}>0$, we want to find a collection of sequences $\\{c_{t},k_{t+1}\\}_{t=0}^{+\\infty}$ to maximize \n\\begin{equation*}\n\\sum_{t=0}^{\\infty }\\b^{t} \\cdot \\ln(c_{t}), \n\\end{equation*}\nsubject to the constraints\n\\begin{equation*}\nk_{t+1}=(1+r)\\cdot k_{t}-c_{t}\n\\end{equation*}\nfor all $t\\geq 0$.\n\n\\paragraph{Lagragian} We first solve the maximization problem using the Lagrangian method.\n\n\\begin{enumerate}\n\\item (5 pts) Write down the Lagrangian of the problem.\n\\item (5 pts) Derive the first-order condition(s) of the maximization problem.\n\\item (5 pts) Derive the Euler equation.\n\\end{enumerate}\n\n\\paragraph{Dynamic Programming} Next we solve the maximization problem using the dynamic programming method.\n\n\\begin{enumerate}\\setcounter{enumi}{3}\n\n\\item (5 pts) Which variable do you choose as a state variable? Which variable do you choose as a control variable? Write down the Bellman equation.\n\n\\item (5 pts)  Derive the first-order condition associated with the Bellman equation.\n\n\\item (5 pts)  Derive the Benveniste-Scheinkman equation.\n\n\\item (5 pts)  Derive the Euler equation. Compare it with the Euler equation obtained with the Lagrangian method and discuss.\n\n\\item (5 pts) Suppose that the policy function takes the form $h(k)=A\\cdot (1+r)\\cdot k$ where $A\\in (0,1) $. Derive $A$.\n\n\\item (10 pts) Suppose that the value function takes the form $V(k)=B+D\\cdot \\ln(k),$ where $B$ and $D$ are constants. Using the expression for the policy function that you derived in the previous question, derive $B$ and $D$.\n\n\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "92cd0093c14e792e9a664878dd57f0759a790481", "size": 3214, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exam/exam.tex", "max_stars_repo_name": "pascalmichaillat/math-for-macro", "max_stars_repo_head_hexsha": "e78569b10b76f4bec2af50360eb07a11089d782b", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 59, "max_stars_repo_stars_event_min_datetime": "2022-01-24T10:22:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T13:17:46.000Z", "max_issues_repo_path": "exam/exam.tex", "max_issues_repo_name": "pascalmichaillat/math-for-macro", "max_issues_repo_head_hexsha": "e78569b10b76f4bec2af50360eb07a11089d782b", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exam/exam.tex", "max_forks_repo_name": "pascalmichaillat/math-for-macro", "max_forks_repo_head_hexsha": "e78569b10b76f4bec2af50360eb07a11089d782b", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2022-01-25T18:14:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T16:38:21.000Z", "avg_line_length": 43.4324324324, "max_line_length": 305, "alphanum_fraction": 0.7205973864, "num_tokens": 958, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092415, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.703800324496946}}
{"text": "%!TEX root = head-full.tex\n\n\\section{Metropolis-Hastings} \\label{sec:metropolis_hastings}\nIn the Introduction, we have shown the main idea of an MCMC sampling method. In this section, we will introduce the Metropolis Hastings Algorithm and conduct an experiment.\n\n\n\n\\subsection{Algorithm\\protect\\footnote{Available at \\protect\\url{https://github.com/lzhbrian/MCMC/blob/master/src/MH/metropolis_hasting.R} in R\\cite{R}}}\n\n\\subsubsection{Detailed Balance Condition}\nBefore stepping further into the MH Algorithm, We would first introduce a theorem called the Detailed Balance Condition. \n\nIn the introduction, we said that we want to construct a Markov Chain which its stationary distribution $\\pi(x)$ just equals to the required probability distribution $p(x)$.\n\nAt first, a theorem is needed.\n\\begin{theorem}[Detail Balance Condition] \\label{theo:detail_balance_condition}\nGiven a non periodic Markov Chain, if \n\\begin{equation} \n\\pi(i) P_{ij} = \\pi(j) P_{ji}~~for~all~i,j \n\\end{equation}\nthen $\\pi(x)$ is the stationary distribution of this Markov Chain.\n\\end{theorem}\nSo, the key question will be how to construct a Markov Chain which satisfy this Detail Balance Condition.\n\n\\subsubsection{MCMC sampling method}\nSuppose we already have a transition matrix $Q$ for a Markov Chain, $q(i,j)$ denote the probabilty of transition from state $i$ to state $j$. For the general case, \n$$p(i) q(i,j) \\neq p(j) q(j,i)$$\nThat is to say, we do not have the detailed balance condition (Theorem~\\ref{theo:detail_balance_condition})\nSo we introduce an $\\alpha(i,j)$ s.t.\n\\begin{equation} \np(i) q(i,j)\\alpha(i,j) = p(j) q(j,i)\\alpha(j,i) \n\\end{equation}\nBy sysmetrical characteristic, we choose:\n\\begin{equation} \n\\alpha(i,j)= p(j) q(j,i)， \\quad \\alpha(j,i) = p(i) q(i,j)\n\\end{equation}\nSo the new Markov Chain $Q'$ would have the property of which its stationary distribution is $p(x)$\n\\begin{equation}\n\\label{detailed-balance} \np(i) \\underbrace{q(i,j)\\alpha(i,j)}_{Q'(i,j)} \n= p(j) \\underbrace{q(j,i)\\alpha(j,i)}_{Q'(j,i)}\n\\end{equation}\n\nWe call the $\\alpha(i,j)$ we introduced, accepting ratio. It means that, in the original Markov Chain $Q$, when state $i$ transits to state $j$ with a probability of $q(i,j)$, we accept this transition with a probabilty of $\\alpha(i,j)$\n\nNow, we have derived the MCMC sampling method.\n\n\\subsubsection{Metropolis-Hastings Algorithm}\nThe MCMC sampling method is a marvellous work. However, it has a critical drawback that if $\\alpha(i,j)$ \\& $\\alpha(j,i)$ are too small, we would seldom accept the transition.\n\nA solution is that we multiply both $\\alpha(i,j)$ \\& $\\alpha(j,i)$ with a constant to make sure that the larger one between them equals $1$. By doing so, we change the accepting ratio to\n\\begin{equation}\n\\alpha(i,j) = \\min\\left\\{\\frac{p(j)q(j,i)}{p(i)q(i,j)},1\\right\\}\n\\end{equation}\nand now, we get Metropolis-Hastings Algorithm\\cite{hastings1970monte}.\n\nI would like to further introduce one more concept called accepting rate(not accepting ratio), which denotes the statistic ratio of accepting the transition. i.e. If we request 10 transition and we accept 8 times, then the accepting rate would be 0.8. This concept is crucial when we are dealing with a continual Markov Chain to use the MH algorithm.\n\n\n\n\\subsubsection{Symmetric Case}\nIn a Markov Chain whose transition matrix is symmetric, we have\n$$q(i,j)=q(j,i)$$\nso the accepting ratio could be simplified to \n\\begin{equation}\n\\alpha(i,j) = \\min\\left\\{\\frac{p(j)}{p(i)},1\\right\\}\n\\end{equation}\nwhich is also known as the Metropolis Algorithm\\cite{metropolis1953equation}.\n\n\\subsubsection{Continual Case}\nIn a continual Markov Chain, such as the experiment we are going to do in the next subsection, we have a vague definition of transition matrix $Q$. So we introduce a concept called the proposal jump size, $sd.T$.\n\nThe method we get $x_{k+1}$ from $x_{k}$ is to add a sampled point of a normal distribution with a variance of the jump size and $\\mu=0$. For a two dimension example, we have:\n\\begin{equation}\nx_{k+1} = x_{k} + sd.T \\left( \\begin{array}{ccc}\nn_{1} \\\\\nn_{2} \\end{array} \\right) \n\\end{equation}\n\n\t\\begin{algorithm}\n        \\caption{Metropolis-Hastings}\n        \\begin{algorithmic}\n        \t\\Require Required distribution $p$, Transfer Matrix $Q$\n        \t\\State Initialize $x_{1}$ \n            \\For{$t = 1 \\to \\inf$}\n                \\State Sample $y \\sim q(x|x_{t})$\n\t            \\State Sample $u \\sim U{[0,1]}$\n\t            \\If {$u < \\alpha(x_{t},y)=min\\{\\frac{p(y)q(x_{t}|y)}{p(x_{t})q(y|x_{t})},1\\}$}\n\t                \\State $x_{t+1} \\gets y$\n\t            \\Else\n\t            \t\\State $x_{t+1} \\gets x_{t}$\n\t            \\EndIf\n\t\t\t\\EndFor\n        \\end{algorithmic}\n    \\end{algorithm}\n\n\n\n\n\\subsection{Sampling Experiment}\nFor our experiment, we use an example of a bivariate Normal distribution, with\n$$ \\mu = \\left( \\begin{array}{ccc}\n5 \\\\\n10 \\end{array} \\right), \n\\Sigma = \\left( \\begin{array}{ccc}\n1 & 1\\\\\n1 & 4\\end{array} \\right)$$\n\nBy theoretical computation, we can easily compute the the pearson correlation between the two dimensional value is 0.5.\n$$ \\rho = 0.5 $$\n\nWe then generate 10,000 samples using the MH algorithm and take the second half (i.e. the last 5,000 points), setting the standard deviation of proposal to 3.0. We can see from the result (Figure~\\ref{fig:sample_result}) that we have derived 5,000 sampled points whose pearson correlation value $\\rho=0.50009$, which matches the theoretical value.\n\n\\begin{figure}[tb]\n\\vspace{-0.5in}\n  \t\\centering\n  \t\\includegraphics[width=0.4\\textwidth]{figure/sample_result.eps}\n\\vspace{-0.2in}\n\t\\caption{Sampling result of 5,000 points \\protect\\\\ correlation = 0.50009 , set sd.T = 3.0}\n\t\\label{fig:sample_result}\n\\end{figure}\n\n\n\n\n\\subsection{Performance Analysis}\n\n\\subsubsection{Choice of proposal jump size}\nMH algorithm is an effective MCMC method for many diverse problems. However, for a continual case in MH algorithm, its performance somewhat depends on the selection of the proposal density. With the proposal jump size being small, the accepting rate would be very low and eventually stick to only one point(eg. the initial point); When the proposal jump size is too big, the accepting rate would be too high. \n\nRoberts et al. have shown in previous work\\cite{roberts1997weak} that the optimal accepting rate of the MH algorithm should approximately be at 0.234 for the case of an N-dimensional Gaussian target distribution. We test the accepting rates in different proposal jump size(Figure~\\ref{fig:acc_sdt}) and find that the optimal value should be at appoximately 3.0 to acquire a model with accepting rate being close to 0.234. That is the reason why we choose 3.0 as our proposal jump size.\n\n\\begin{figure}[tb]\n\\vspace{-0.2in}\n  \t\\centering\n  \t\\includegraphics[width=0.4\\textwidth]{figure/acc_sdt.eps}\n\\vspace{-0.2in}\n\t\\caption{Accepting rate on different proposal jump size.}\n\t\\label{fig:acc_sdt}\n\\end{figure}\n\n\\subsubsection{Efficiency}\nDue to the limit of the accepting rate, for a high dimensional condition, using the MH sampling methods may spend more time in traverse all of the possible states, which could sometimes be be less satisfying. Thus, many would switch to Gibbs Sampling Algorithm.\n\n\n\n\n\\subsection{Gibbs Sampling}\nGibbs Sampling is a special case of Metropolis Hastings Algorithm, by letting the accepting rate = 1, we will get a Gibbs Sampler. As the length \\& time limit, we will not specify more here.\nBut it is worthy to notice that Gibbs sampling method is used more often than Metropolis-Hastings method in the real practice, probably because it has a slightly simpler process.\n\n\n\n\n\n\n", "meta": {"hexsha": "34a3e86dd3e73c064ff63ebf0c58d597eaf3fa5e", "size": 7601, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/Metropolis_hastings.tex", "max_stars_repo_name": "lzhbrian/MCMC", "max_stars_repo_head_hexsha": "0dd3aadd1ed2833aff76bd7af4b014282739984b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-09-10T04:42:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-21T16:07:29.000Z", "max_issues_repo_path": "tex/Metropolis_hastings.tex", "max_issues_repo_name": "lzhbrian/MCMC", "max_issues_repo_head_hexsha": "0dd3aadd1ed2833aff76bd7af4b014282739984b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/Metropolis_hastings.tex", "max_forks_repo_name": "lzhbrian/MCMC", "max_forks_repo_head_hexsha": "0dd3aadd1ed2833aff76bd7af4b014282739984b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-03-03T17:34:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-24T10:54:53.000Z", "avg_line_length": 48.4140127389, "max_line_length": 485, "alphanum_fraction": 0.7301670833, "num_tokens": 2096, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7036715220204487}}
{"text": "\\documentclass[10pt]{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage[margin=1in]{geometry}\n\\usepackage[]{amsmath}\n\\usepackage{amsthm}\n\\usepackage{amssymb}\n\n\\newcommand{\\RR}{\\mathbb{R}}\n\\newcommand{\\abs}[1]{\\vert#1\\vert}\n\\newcommand{\\set}[1]{\\{#1\\}}\n\\DeclareMathOperator*{\\argmin}{\\textrm{arg\\,min}}\n\n\\theoremstyle{definition}\n\\newtheorem{definition}{Definition}[section]\n\n\\title{Fatness of Simple Polygons}\n\\author{Sharmila Duppala \\and David Kraemer}\n\\date{April 2018}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Problem Statement} \n\n\\paragraph{Professor Mitchell's description.}\nComputing the Niceness of a Polygonal Shape. There are various notions of\nquantifying how “nice” or how “fat” a simple polygon $P$ is. A “nicest” polygon\nmight be a regular $n$-gon, which most closely approximates a circular disk. This\nproject seeks to implement some precise metrics for niceness, and compare them\non simple polygons (possibly moused in by a user or read in from a file, etc).\nTo make it simple and discrete, I propose that you discretize the boundary of\n$P$ with discrete points $p_i$ (additional vertices), with a prescribed spacing,\n$\\delta$. (That is, for edges of $P$ longer than $\\delta$, add vertices along\n  the edge so that the new sub-segments are of length at most $\\delta$, for a\nuser-specified parameter $\\delta$.)\n\nThen, consider discrete choices of radii $r = \\rho, 2\\rho, 3\\rho, \\ldots$ for\ndisks, $B(p_i,r)$, centered at the discrete boundary points $p_i$, for each\nradius $r$. The (discrete) fatness of $P$ is given by the smallest value of the\nratio $\\lambda (B(p_i,r)\\cap P)/\\lambda (B(p_i, r))$, over all choices of $p_i$\nand $r = \\rho, 2\\rho, 3\\rho, \\ldots$ such that $P$ is not contained fully inside\n$B(p_i,r)$.\n\n  Implement and experiment with this fatness measure. It may be possible to use\n  the algorithm to assist a project at Harvard on Gerrymandering, where the goal\n  is to quantify how “compact” polygonal election districts are. (So I hope that\n  at least a couple of people choose to do this project! We can discuss\nfurther.)\n\n(Theoretically, we are interested in finding an algorithm to compute the “exact”\n  fatness of $P$ (which allows disks centered anywhere inside $P$, of any radius\n  such that the disk does not contain all of $P$), without resorting to the\n  simple discretization. Or, can we compute a provable approximation to the\nexact fatness?)\n\n\\section{Definitions}\n\nOur present objective is to develop rigorous measures of the ``niceness'' of\nsimple bounded closed planar polygons with the intuitive hierarchy that regular\n$n$-gons are ``nicest'' followed by convex $n$-gons and proceeded by ``fat''\npolygons---i.e., polygons which retain their structure under smoothing filters.\n\nThroughout we assume that $P \\subseteq \\RR^2$ is a simple bounded closed\npolygon. We shall denote by $\\partial P$ the boundary of $P$, with\n$\\abs{\\partial P}$ denoting the perimeter and $\\lambda(P)$ denoting the area.\nFor given points $x,y \\in \\RR$, denote the closed line segment bounded by $x$\nand $y$ by $[x,y]$.  The class of such polygons is denoted by $\\mathcal{P}$.\n\nOne class of ``fatness'' measures arises through partitioning $P$ into two\n(interior disjoint) polygons $P = P' \\cup P''$ via chords.  A chord is a pair\n$x,y \\in \\partial P$ such that the segment $[x,y]$ is contained by the relative\ninterior of $P$ except at the endpoints $x$ and $y$.  Such a chord $[x,y]$\ndefines a partition of $P = P' \\cup P''$ by orientation, so that $\\partial P'$\nis the arc from $x$ to $y$ with $[y,x]$ and that $\\partial P''$ is the arc from\n$y$ to $x$ with $[x,y]$. \n\n\\begin{definition}\n  Let $f : \\mathcal{P} \\to \\RR$. For a given $P \\in \\mathcal{P}$,\n  its \\emph{chord-$f$ score} is given by\n  \\begin{equation*}\n    s_f(P) = \\inf_{x,y \\in \\partial P} \\max(f(P'), f(P''))\n  \\end{equation*}\n  where the chord $[x,y]$ partitions $P = P' \\cup P''$.\n\\end{definition}\n\nIntuitively, $f$ represents a polygon's cost with respect to a certain\nmeasurement.  For example, if $f$ indicates the perimeter of $P$, then $s_f$ is\nassociated with a partition of $P$ such that the maximum perimeter of either\nsubpolygon is minimized. Indeed, measures such as perimeter or area are the\ntypical choices of $f$, but any suitable property of the polygon may be\nemployed.\n\nThe visibility kernel of $P$, denoted by $\\ker P$, is the subset of $P$ which\n``sees'' all of $P$. That is, if $x \\in \\ker P$ and $y \\in P$, then $[x,y]\n\\subseteq P$. Another proposed measure of polygonal ``niceness'' utilizes the\nvisibility kernel.\n\n\\begin{definition}\n  The \\emph{visibility kernel score} is given by\n  \\begin{equation*}\n    s_{\\textrm{vis}}(P) = \\frac{\\lambda(\\ker P)}{\\lambda(P)}.\n  \\end{equation*}\n\\end{definition}\n\nIf $P$ is a regular $n$-gon or convex $s_{\\textrm{vis}}(P) = 1$, since trivially\n$\\ker P = P$. On the other hand, if $P$ is not star shaped, then\n$s_{\\textrm{vis}}(P) = 0$.\n\nEquipped with an $L_p$ norm ($p \\in [1,\\infty]$), denote by $B(x,\\rho)$ the\nclosed ball of radius $\\rho > 0$ centered at $x \\in \\RR^2$.  The natural choice\nis simply the Euclidean norm, but $L_{\\infty}$ provides a setting for which\ncomputing $B(x,\\rho) \\cap P$ resolves to polygonal intersection. By topological\nequivalence, we lose no specificity. A final measure of ``fatness'' measures\nlocal nonconvexities of $P$ and identifies the most offending ratio.\n\\begin{definition}\n  The \\emph{$\\alpha$-fatness score} is given by\n  \\begin{equation*}\n    \\alpha(P) = \\inf\\set{\\frac{\\lambda(B(x,\\rho) \\cap\n    P)}{\\lambda(B(x,\\rho))} : x \\in \\partial P, \\rho > 0, P \\not\\subseteq B(x,\\rho)}\n  \\end{equation*}\n\\end{definition}\t\n\nFor a given $S \\subseteq \\RR^2$, let $\\mathcal{C}(x,S)$ denote the connected\ncomponent of $S$ containing $x$. An alternative formulation of $\\alpha$-fatness\nreplaces $B(x,\\rho) \\cap P$ with its connected component: $\\mathcal{C}(x,\nB(x,\\rho) \\cap P)$. In principle, $\\alpha(P)$ is computed by sweeping\ncontinuously, but for simplicity we can merely discretize $\\partial P$ with a\nparameter $\\delta > 0$ indicating the maximal distance between points in\n$\\partial P$.\n\n\\section{Implementation}\n\nWe plan to implement these measures of polygonal ``fatness'' and compare them\nfor assorted collections of polygons, from theoretical and\nrandomly-generated examples to historical electoral map data. We hope to\ndetermine the relative strengths of these measures as heuristics for polygonal\n``fatness'' individually or in an ensemble on this data. \n\n\\end{document}\n", "meta": {"hexsha": "2f9021fe89b6d9f39f9115d06f135ff5a3b4fbb3", "size": 6467, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "proposal/main.tex", "max_stars_repo_name": "DavidNKraemer/polygonal-niceness", "max_stars_repo_head_hexsha": "6bf89adeee7586ea66d96a4682ad0662c4e0ab67", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "proposal/main.tex", "max_issues_repo_name": "DavidNKraemer/polygonal-niceness", "max_issues_repo_head_hexsha": "6bf89adeee7586ea66d96a4682ad0662c4e0ab67", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "proposal/main.tex", "max_forks_repo_name": "DavidNKraemer/polygonal-niceness", "max_forks_repo_head_hexsha": "6bf89adeee7586ea66d96a4682ad0662c4e0ab67", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.5422535211, "max_line_length": 84, "alphanum_fraction": 0.7207360445, "num_tokens": 1892, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891261650248, "lm_q2_score": 0.8558511396138366, "lm_q1q2_score": 0.703671500606441}}
{"text": "\\section{Elementary number theory}\n\nOne of the things type theory is great for, is for the formalization of mathematics in a computer proof assistant. Those are programs that can compile any type theoretical construction to check that this construction indeed has the type it was claimed it has.\n\nAt this point in our development of type theory there are two areas of mathematics that would be natural to try to do in type theory: discrete mathematics and elementary number theory. Indeed, how does one define in type theory the greatest common divisor of two natural numbers, or how does one show that there are infinitely many primes? How does one even formalize that every non-empty subset of the natural numbers has a least element?\n\nTo answer these questions we will run into questions of decidability. How do we write a term that decides wheter a number is prime or not? Or indeed, is it even true that every non-empty subset of the natural numbers has a least element? What about the subset of $\\N$ that contains $1$, and it contains $0$ if and only if Goldbach's conjecture holds? Finding the least element of this subset is equivalent to settling the conjecture!\n\nTherefore, we will prove the well-foundedness of the natural numbers for decidable subsets of $\\N$. In fact, we will show it for decidable families, because sometimes we don't know in advance whether a family of types is in fact a subtype. A consequence of involving decidability in the well-foundedness of the natural numbers is that for many properties one has to prove that they are decidable. Luckily this is the case: many of the familiar properties that one encounters in number theory are indeed decidable.\n\n\\subsection{Decidability}\n\nA common way of reasoning in mathematics is via a proof by contradiction: ``in order to show that $P$ holds we show that it cannot be the case that $P$ doesn't hold\". There are no inference rules in type theory that allow us to obtain a term of type $P$ from a term of type $\\neg\\neg P$. However, for some propositions $P$ one can construct a function $\\neg\\neg P \\to P$. The \\emph{decidable propositions} from a class of such propositions $P$ for which we can show $\\neg\\neg P \\to P$.\n\n\\begin{defn}\n  A type $A$ is said to be decidable if it comes equipped with a term of type\n  \\begin{equation*}\n    \\mathsf{is\\usc{}decidable}(A)\\defeq A+\\neg A.\n  \\end{equation*}\n  Decidable propositions are called \\define{classical}. We will write\n  \\begin{equation*}\n    \\mathsf{classical\\usc{}Prop} \\defeq \\sm{P:\\mathsf{Prop}}\\mathsf{is\\usc{}decidable}(P)\n  \\end{equation*}\n  for the type of all classical propositions (with respect to a universe $\\UU$).\n\\end{defn}\n\n\\begin{eg}\n  The types $\\unit$ and $\\emptyt$ are decidable. Indeed, we have\n  \\begin{align*}\n    \\inl(\\ttt) & :\\mathsf{is\\usc{}decidable}(\\unit) \\\\\n    \\inr(\\idfunc) & : \\mathsf{is\\usc{}decidable}(\\emptyt).\\qedhere\n  \\end{align*}\n  Any type $A$ equipped with a point $a:A$ is decidable.\n\\end{eg}\n\n\\begin{lem}\n  For each $m,n:\\N$, the types $\\EqN(m,n)$, $m\\leq n$ and $m<n$ are decidable.\n\\end{lem}\n\n\\begin{proof}\n  The proofs in each of the three cases is similar, so we only show that $\\EqN(m,n)$ is decidable for each $m,n:\\N$. This is done by induction on $m$ and $n$. Note that the types\n  \\begin{align*}\n    \\EqN(\\zeroN,\\zeroN) & \\jdeq \\unit \\\\\n    \\EqN(\\zeroN,\\succN(n)) & \\jdeq \\emptyt \\\\\n    \\EqN(\\succN(m),\\zeroN) & \\jdeq \\emptyt \n  \\end{align*}\n  are all decidable. Moreover, the type $\\EqN(\\succN(m),\\succN(n))\\jdeq \\EqN(m,n)$ is decidable by the inductive hypothesis.\n\\end{proof}\n\nTypically we are mostly interested in decidability of propositions. However, we have defined the notion of decidability for general types, because the condition on an arbitrary type that its identity types are decidable is of some interest. We now study such types.\n\n\\begin{defn}\n  We say that a type $A$ has decidable equality if the identity type $x=y$ is decidable for every $x,y:A$. \n\\end{defn}\n\n\\begin{cor}\n  Equality on the natural numbers is decidable.\n\\end{cor}\n\n\\begin{proof}\n  This follows immediately from the equivalences $(m=n)\\simeq \\EqN(m,n)$, and the fact that $\\EqN(m,n)$ is decidable.\n\\end{proof}\n\n\\begin{lem}\n  Suppose that $A$ and $B$ are types with decidable equality. Then the coproduct $A+B$ also has decidable equality.\n\\end{lem}\n\n\\begin{proof}\n  Our goal is to construct a dependent function\n  \\begin{equation*}\n    d_{A+B} : \\prd{z,z':A+B}\\mathsf{is\\usc{}decidable}(z=z').\n  \\end{equation*}\n  This function is constructed by coproduct induction on both $z$ and $z'$, so we have four cases to consider. Recall from \\cref{thm:id-coprod-compute} that we have equivalences\n  \\begin{align*}\n    (\\inl(x)=\\inl(x')) & \\simeq (x=x') \\\\\n    (\\inl(x)=\\inr(y')) & \\simeq \\emptyt \\\\\n    (\\inr(y)=\\inl(x')) & \\simeq \\emptyt \\\\\n    (\\inr(y)=\\inr(y')) & \\simeq (y=y').\n  \\end{align*}\n  Therefore the type $z=z'$ is equivalent to a decidable type in each of the four cases.\n\\end{proof}\n\n\\begin{cor}\n  The type $\\Z$ has decidable equality.\n\\end{cor}\n\n\\begin{cor}\n  For any $n:\\N$ the type $\\mathsf{Fin}(n)$ has decidable equality. \n\\end{cor}\n\nWe have already shown in \\cref{thm:eq_nat} that the type of natural numbers is a set. In fact, any type with decidable equality is a set. This fact is known as Hedberg's theorem. Our proof of Hedberg's theorem might appear to be slightly complicated compared to the proof in \\cite{hottbook}. This is due to the fact that we haven't introduced function extensionality yet, which is used there to observe that $\\neg\\neg(x=y)$ is a proposition for any $x,y:A$.\n\n\\begin{thm}[Hedberg]\n  Any type with decidable equality is a set.\n\\end{thm}\n\n\\begin{proof}\n  Let $A$ be a type, and let\n  \\begin{equation*}\n    d:\\prd{x,y:A}(x=y)+\\neg(x=y).\n  \\end{equation*}\n  Our proof is an application of \\cref{lem:prop_to_id}. In order to construct a binary relation $R$, we first consider the type family $D(x,y):((\\id{x}{y})+\\neg(\\id{x}{y}))\\to\\UU$ given by\n  \\begin{align*}\n    D(x,y,\\inl(p)) & \\defeq \\unit \\\\\n    D(x,y,\\inr(p)) & \\defeq \\emptyt.\n  \\end{align*}\n  Now we define the binary relation $R:A\\to (A\\to\\UU)$ by\n  \\begin{equation*}\n    R(x,y)\\defeq D(x,y,d(x,y)).\n  \\end{equation*}\n  It follows that $R(x,y)$ is a proposition for every $x,y:A$, since $D(x,y,z)$ is a proposition for every $z:(x=y)+\\neg(x=y)$.\n\n  To see that $R$ is reflexive it suffices to construct a term of type\n  \\begin{equation*}\n    \\rho':\\prd{x:A}{p:(x=x)+\\neg(x=x)}D(x,x,p)\n  \\end{equation*}\n  For any $x:A$ we define $\\rho'(x)$ by case analysis on $p:(x=x)+\\neg(x=x)$. Given $p:x=x$, we take $\\rho'(x,\\inl(p))\\defeq\\ttt$. Given $p:\\neg(x=x)$, we obtain $p(\\refl{x}):\\emptyt$, so there is nothing to define in this case. This completes the definition of $\\rho'$.\n  \n  It remains to show that $R(x,y)\\to (x=y)$ for any $x,y:A$. Note that it suffices to construct a function\n  \\begin{equation*}\n    \\alpha:D(x,y,p)\\to (x=y)\n  \\end{equation*}\n  for any $x,y:A$ and $p:(x=y)+\\neg(x=y)$. This function is constructed by case analisys on $p$. Given $p:x=y$, we simply define $\\alpha(x,y,\\inl(p))\\defeq p$. Given $p:\\neg(x=y)$ the type $D(x,y,p)$ is empty, so there is nothing to define.\n\\end{proof}\n\n\\subsection{The well-ordering principle for decidable families over \\texorpdfstring{$\\N$}{ℕ}}\n\n\\begin{defn}\n  A family $P$ over a type $A$ is said to be decidable if $P(x)$ is decidable for every $x:A$. A \\define{decidable subset} of a type $A$ is a map\n  \\begin{equation*}\n    P:A\\to\\mathsf{classical\\usc{}Prop}.\n  \\end{equation*}\n\\end{defn}\n\n\\begin{defn}\n  Let $P$ be a decidable family over $\\N$, and let $n:\\N$ be a natural number equipped with $p:P(n)$. We say that $n$ is a \\define{minimal $P$-element} if it comes equipped with a term of type\n  \\begin{equation*}\n    \\mathsf{is\\usc{}minimal}_P(n,p)\\defeq \\Big(\\prd{m:\\N}P(m)\\to (n\\leq m)\\Big)\n  \\end{equation*}\n\\end{defn}\n\nNote that the type $\\mathsf{is\\usc{}minimal}_P(n,p)$ doesn't depend on $p$. However, it doesn't make much sense that $n$ is a minimal element of $P$ unless we already know that $n$ is in $P$. Indeed, if we would omit the hypothesis that $n$ is in $P$, it would be more accurate to say that $n$ is a \\emph{lower bound} of $P$. The following theorem is the well-ordering principle of $\\N$. \n\n\\begin{thm}\n  Let $P$ be a decidable family over $\\N$. Then there is a function\n  \\begin{equation*}\n    \\Big(\\sm{n:\\N}P(n)\\Big)\\to\\Big(\\sm{m:\\N}{p:P(m)}\\mathsf{is\\usc{}minimal}_P(m,p)\\Big).\n  \\end{equation*}\n\\end{thm}\n\n\\begin{proof}\n  Consider a universe $\\UU$ that contains $P$. We show by induction on $n:\\N$ that there is a function\n  \\begin{equation*}\n    Q(n)\\to \\Big(\\sm{m:\\N}{p:Q(m)}\\mathsf{is\\usc{}minimal}_Q(m,p)\\Big) \n  \\end{equation*}\n  for every decidable family $Q:\\N\\to\\UU$. Note that we performed a swap in the order of quantification, using the universe that contains $P$. This slightly strengthens the inductive hypothesis, which we will be able to exploit.\n\n  The base case is trivial, since $\\zeroN$ is the least natural number. For the inductive step, suppose that $Q(\\succN(n))$ holds. Note that $Q(\\zeroN)$ is assumed to be decidable, so we proceed by case analysis on $Q(\\zeroN)+\\neg Q(\\zeroN)$. Given $q:Q(\\zeroN)$, it follows immediately that $\\zeroN$ must be minimal. In the case where $\\neg Q(\\zeroN)$, we consider the decidable subset $Q'$ of $\\N$ given by\n  \\begin{equation*}\n    Q'(n)\\defeq Q(\\succN(n)).\n  \\end{equation*}\n  Since we have $q:Q'(n)$, we obtain a minimal element in $Q'$ by the inductive hypothesis. Of course, by the assumption that $Q(\\zeroN)$ doesn't hold, the minimal element of $Q'$ is also the minimal element of $Q$.\n\\end{proof}\n\n\\subsection{The pigeonhole principle}\n\nThe pigeonhole principle states that if we place more than $n$ balls in $n$ bags, then at least one bag will contain more than one ball. In this section we will give a type theoretical proof of the pigeonhole principle.\n\nFirst we give a definition of a function that counts the number of elements in a decidable subset of $\\mathsf{Fin}(n)$.\n\n\\begin{defn}\n  Let $P$ be a decidable subset of $\\mathsf{Fin}(n)$. We define the number $|P|:\\N$ of elements in $P$.\n\\end{defn}\n\n\\begin{proof}[Construction]\n  We give the construction of $|P|$ by induction on $n:\\N$. In the base case we note that $\\mathsf{Fin}(\\zeroN)$ has no elements, so we define $|P|\\defeq\\zeroN$.\n\n  For the inductive step, we define $|P|$ by case analysis on $P(\\inr(\\ttt))+\\neg P(\\inr(\\ttt))$. Let $P'$ be the family over $\\mathsf{Fin}(n)$ given by $P'(i)\\defeq P(\\inl(i))$. In the case where $P(\\inr(\\ttt))$ holds, then we define $|P|\\defeq \\succN |P'|$. In the case where $P(\\inr(\\ttt))$ doesn't hold we define $|P|\\defeq |P'|$.\n\\end{proof}\n\n\\begin{defn}\n  For any $i:\\mathsf{Fin}(\\succN(n))$ we define a function\n  \\begin{equation*}\n    \\mathsf{skip}(i):\\mathsf{Fin}(n)\\to\\mathsf{Fin}(\\succN(n)).\n  \\end{equation*}\n\\end{defn}\n\n\\begin{proof}[Construction]\n  The function $\\mathsf{skip}(i)$ is defined by induction on $n:\\N$. In the base case, the function\n  \\begin{equation*}\n    \\mathsf{skip}(i):\\mathsf{Fin}(\\zeroN)\\to\\mathsf{Fin}(\\succN(\\zeroN))\n  \\end{equation*}\n  is defined to be the unique map out of the empty type. In the successor case we define\n  \\begin{equation*}\n    \\mathsf{skip}(i) : \\mathsf{Fin}(\\succN(n))\\to\\mathsf{Fin}(\\succN(\\succN(n))) \n  \\end{equation*}\n  by induction on $i:\\mathsf{Fin}(\\succN(\\succN(n)))$. The function\n  \\begin{equation*}\n    \\mathsf{skip}(\\inl(i)):\\mathsf{Fin}(\\succN(n))\\to\\mathsf{Fin}(\\succN(\\succN(n)))\n  \\end{equation*}\n  is a map between coproducts, so it can be defined using the functorial action of coproducts of \\cref{ex:coproduct_functor}. We take\n  \\begin{equation*}\n    \\mathsf{skip}(\\inl(i))\\defeq \\mathsf{skip}(i)+\\idfunc.\n  \\end{equation*}\n  The function \n  \\begin{equation*}\n    \\mathsf{skip}(\\inr(i)):\\mathsf{Fin}(\\succN(n))\\to\\mathsf{Fin}(\\succN(\\succN(n)))\n  \\end{equation*}\n  is just the function $\\inl$.\n\\end{proof}\n\n\\begin{lem}\n  For each $i:\\mathsf{Fin}(\\succN(n))$, the function\n  \\begin{equation*}\n    \\mathsf{skip}(i):\\mathsf{Fin}(n)\\to\\mathsf{Fin}(\\succN(n))\n  \\end{equation*}\n  is an embedding.\n\\end{lem}\n\n\\begin{proof}\n  This assertion is proven by induction on $n$. In the base case, we note that any map out of the empty type is an embedding, by \\cref{ex:is-emb-empty}. In the inductive step we proceed by case analysis on $i:\\mathsf{Fin}(\\succN(\\succN(n)))$. In the case of $\\inl(i)$ we note that\n  \\begin{equation*}\n    \\mathsf{skip}(\\inl(i))\\jdeq \\mathsf{skip}(i)+\\idfunc\n  \\end{equation*}\n  is the functorial action of coproducts on two embeddings. Therefore we conclude by \\cref{ex:is-emb-coprod} that this map is an embedding. In the case of $\\inr(i)$ we note that $\\inl$ is an embedding by \\cref{ex:is-emb-inl-inr}.\n\\end{proof}\n\n\\begin{lem}\n  Consider a map $g:\\mathsf{Fin}(m)\\to\\mathsf{Fin}(\\succN(n))$. Furthermore, suppose that $i:\\mathsf{Fin}(\\succN(n))$ is not in the image of $g$, i.e.~that $\\neg(\\fib{g}{i})$. Then we can construct a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}\n      & \\mathsf{Fin}(n) \\arrow[d,\"\\mathsf{skip}(i)\"] \\\\\n      \\mathsf{Fin}(m) \\arrow[r,swap,\"g\"] \\arrow[ur,densely dotted,\"f\"] & \\mathsf{Fin}(\\succN(n)).\n    \\end{tikzcd}\n  \\end{equation*}\n\\end{lem}\n\nFinally, we prove the pigeonhole principle.\n\n\\begin{thm}\\label{thm:pigeonhole}\n  For any $m,n:\\N$ and any function $f:\\mathsf{Fin}(m)\\to\\mathsf{Fin}(n)$, if $m>n$, then there is an $i:\\mathsf{Fin}(n)$ which is in the image of more than one point in $\\mathsf{Fin}(m)$.\n\\end{thm}\n\n\\begin{proof}\n  The pigeonhole principle is proven by induction on $m,n:\\N$. In the base case for $m$ there is nothing to show because $m>n$ is empty. For the inductive step on $m$ and the base case for $n$, we note that $\\mathsf{Fin}(\\succN(m))\\jdeq \\mathsf{Fin}(m)+\\unit$ and $\\mathsf{Fin}(\\zeroN)\\jdeq \\emptyt$. Therefore $f:\\mathsf{Fin}(\\succN(m))\\to\\mathsf{Fin}(\\zeroN)$ is a function from a pointed type to the empty type, which gives us a contradiction.\n\n  It remains to give the inductive step for $n$. Let $i\\defeq f(\\inr(\\ttt)):\\mathsf{Fin}(\\succN(n))$. Since the ordering relation $<$ on $\\N$ is decidable, we can decide whether $i$ is in the image of more than one point in $\\mathsf{Fin}(m)$ by deciding whether or not $1<|P|$ holds for\n  \\begin{equation*}\n    P(j)\\defeq (f(j)=i)\n  \\end{equation*}\n  If this is the case, this completes the proof.\n\n  Now suppose that $1\\not<|P|$. Since $P(\\inr(\\ttt))$ holds it follows that $|P|=1$. Now we observe that $i$ is not in the image of $f\\circ \\inl$. Therefore we obtain a commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\mathsf{Fin}(m) \\arrow[r,densely dotted,\"{f'}\"] \\arrow[d,swap,\"\\inl\"] & \\mathsf{Fin}(n) \\arrow[d,\"{\\mathsf{skip}(i)}\"] \\\\\n      \\mathsf{Fin}(\\succN(m)) \\arrow[r,swap,\"f\"] & \\mathsf{Fin}(\\succN(n)).\n    \\end{tikzcd}\n  \\end{equation*}\n\n  Note that the induction hypothesis the pigeonhole principle applies to the function $f':\\mathsf{Fin}(m)\\to\\mathsf{Fin}(n)$. Since $m>n$ it follows that there is an element $j:\\mathsf{Fin}(n)$ that is in the image of $f'$ of more than one element of $\\mathsf{Fin}(m)$. Now we observe that there is an equivalence\n  \\begin{equation*}\n    \\fib{f'}{j}\\simeq \\fib{f}{\\mathsf{skip}(i,j)}\n  \\end{equation*}\n  because both the left and right maps in the commuting square are embeddings. Therefore we conclude that $\\mathsf{skip}(i,j)$ is in the image of $f$ of more than one element of $\\mathsf{Fin}(\\succN(m))$. \n \\end{proof}\n\n\\begin{cor}\\label{cor:pigeonhole}\n  Given $m>n$, no function $\\mathsf{Fin}(m)\\to\\mathsf{Fin}(n)$ is an embedding.\n\\end{cor}\n\nIt is straightforward to see that the statements of \\cref{thm:pigeonhole,cor:pigeonhole} are equivalent, and one might argue that the statement of \\cref{cor:pigeonhole} is the more `type theoretical way' of phrasing the pigeonhole principle. However, the relation to counting the number of points that get mapped to \n\n\\begin{thm}\\label{thm:generalized-pigeonhole}\n  For any $m,n:\\N$ and any function $f:\\mathsf{Fin}(m)\\to\\mathsf{Fin}(n)$, if $m>kn$ for some $k:\\N$, then there is an $i:\\mathsf{Fin}(n)$ which is in the image of more than $k$ points in $\\mathsf{Fin}(m)$. \n\\end{thm}\n\n\\subsection{Defining the greatest common divisor}\n\n\\begin{lem}\n  For any $d,n:\\N$, the type $d\\mid n$ is decidable.\n\\end{lem}\n\n\\begin{proof}\n  We give the proof by case analysis on $(d=\\zeroN)+(d\\neq\\zeroN)$. If $d=\\zeroN$, then $d\\mid n$ holds if and only if $\\zeroN=n$, which is decidable.\n\n  If $d\\neq\\zeroN$, then it follows that $n\\leq nd$. Therefore we obtain by the well-ordering principle of the natural numbers a minimal $m:\\N$ that satisfies the decidable property $n\\leq md$. Now we observe that $d\\mid n$ holds if and only if $n=md$, which is decidable.\n\\end{proof}\n\n\\begin{defn}\n  A type family $P$ over $\\N$ is said to be \\define{bounded from above} by $m$ for some natural number $m$, if it comes equipped with a term of type\n  \\begin{equation*}\n    \\mathsf{is\\usc{}bounded}_m(P) \\defeq \\prd{n:\\N}P(n)\\to (n\\leq m).\n  \\end{equation*}\n\\end{defn}\n\n\\begin{defn}\n  Let $P$ be a type family over $\\N$, and consider $p:P(n)$. We say that $n$ is the maximal $P$-number if it comes equipped with a term of type\n  \\begin{equation*}\n    \\mathsf{is\\usc{}maximal}_P(n,p) \\defeq \\prd{m:\\N} P(m)\\to m\\leq n.\n  \\end{equation*}\n\\end{defn}\n\nIn the following lemma we show that if a decidable family $P$ is bounded from above and inhabited, then it possesses a maximal element.\n\n\\begin{lem}\\label{lem:maximal}\n  Consider a decidable type family $P$ over $\\N$ which is bounded from above by $m$. Then there is a function\n  \\begin{equation*}\n    \\mathsf{maximum}_P:\\Big(\\sm{n:\\N}P(n)\\Big)\\to\\Big(\\sm{n:\\N}{p:P(n)}\\mathsf{is\\usc{}maximal}_P(n,p)\\Big).\n  \\end{equation*}\n\\end{lem}\n\n\\begin{proof}\n  We define the asserted function by induction on $m$. In the base case, if we have $p:P(n)$, then it follows from $n\\leq 0$ that $n=0$. It follows by the boundedness of $P$ that $(n,p)$ is maximal.\n\n  In the inductive step we proceed by case analysis on $P(\\succN(m))$. This is allowed because $P$ is decidable. If we have $q:P(\\succN(m))$, then it follows by the boundedness of $P$ that $(\\succN(m),q)$ is maximal. If $\\neg P(\\succN(m))$, then it follows that $P$ is bounded by $m$, which allows us to proceed by recursion.\n\\end{proof}\n\n\\begin{defn}\n  For any two natural numbers $m,n$ we define the \\define{greatest common divisor} $\\gcd(m,n)$, which satisfies the following two properties:\n  \\begin{enumerate}\n  \\item We have both $\\gcd(m,n)\\mid m$ and $\\gcd(m,n)\\mid n$.\n  \\item For any $d:\\N$ we have $d\\mid \\gcd(m,n)$ if and only if both $d\\mid m$ and $d\\mid n$ hold.\n  \\end{enumerate}\n\\end{defn}\n\n\\begin{proof}[Construction]\n  Consider the type family $P(d)\\defeq (d\\mid m)\\times (d\\mid n)$. Then $P$ is bounded from above by $m$. Moreover, $P(1)$ holds since $1\\mid n$ for any natural number $n$. Furthermore, the divisibility relation is decidable, so it follows that $P$ is a family of decidable types. Now the greatest common divisor is defined as the maximal $P$-element, which is obtained by \\cref{lem:maximal}\n\\end{proof}\n\n\\subsection{The trial division primality test}\n\n\\begin{thm}\n  For any $n:\\N$, the proposition $\\mathsf{is\\usc{}prime}(n)$ is decidable.\n\\end{thm}\n\nIt is important to note that, even when we prove that a type such as $\\mathsf{is\\usc{}prime}(n)$ is decidable, it is only after we \\emph{evaluate} the proof term that we know whether the type under consideration has a term or not. In other words, for any given $n$ we don't know right away whether it is prime or not. Evaluating whether $n$ is prime can be computationally costly, so it may be desirable in any specific situation to give a separate mathematical \\emph{argument} that decides whether or not the number is prime.\n\n\\subsection{Prime decomposition}\n\nWe will show now that any natural number $n>0$ can be written as a product of primes\n\\begin{equation*}\n  n=p_1^{k_1}\\cdots p_{m}^{k_m}\n\\end{equation*}\nThis prime decomposition is unique if we require that the primes $p_i<p_{i+1}$ for each $0<i<m$. In order to establish these facts in type theory, we first have to define finite products.\n\n\\subsection{The infinitude of primes}\n\nRecall that Euclid's proof\n\n\\begin{thm}\n  There are infinitely many primes.\n\\end{thm}\n\n\\begin{proof}\n  We will show that for every $n:\\N$ there is a prime number that is larger than $n$. In other words, we will construct a term of type\n  \\begin{equation*}\n    \\prd{n:\\N}\\sm{p:\\N}\\mathsf{is\\usc{}prime}(p)\\times (n\\leq p).\n  \\end{equation*}\n  To show this, let $P$ be the type family over $\\N$ given by\n  \\begin{equation*}\n    P(m)\\defeq \\mathsf{is\\usc{}prime}(m)\\times (m\\leq n).\n  \\end{equation*}\n  Since $P$ is decidable and bounded from above by $n$, we can take the product of all $m:\\N$ for which $P$ holds. Write $k$ for this product. Then $k+1$ is coprime to every prime less than $n$. Therefore the primes in its prime factorization must all be larger than $n$.  \n\\end{proof}\n\n\\begin{cor}\n  There is a function\n  \\begin{equation*}\n    \\mathsf{prime} : \\N \\to \\sm{p:\\N}\\mathsf{is\\usc{}prime}(p)\n  \\end{equation*}\n  that sends $n$ to the $n$-th prime. This function is strictly monotone, so it is an embedding.\n\\end{cor}\n\nSome further ideas to include in this chapter:\n\\begin{enumerate}\n\\item If $2^n-1$ is prime, then $n$ is prime.\n\\item Fermat's little theorem.\n\\end{enumerate}\n\n\\begin{exercises}\n\\item Show that for any $f:\\mathsf{Fin}(m)\\to\\mathsf{Fin}(n)$ and any $i:\\mathsf{Fin}(n)$, the type $\\fib{f}{i}$ is decidable.\n\\item Consider a decidable type $P(i)$ indexed by $i:\\mathsf{Fin}(n)$.\n  \\begin{subexenum}\n  \\item Show that the type\n    \\begin{equation*}\n      \\prd{i:\\mathsf{Fin}(n)}P(i)\n    \\end{equation*}\n    is decidable.\n  \\item Show that the type\n    \\begin{equation*}\n      \\sm{i:\\mathsf{Fin}(n)}P(i)\n    \\end{equation*}\n    is decidable.\n  \\end{subexenum}\n\\item\n  \\begin{subexenum}\n  \\item Show that $\\nat$ and $\\bool$ have decidable equality. Hint: to show that $\\mathbb{N}$ has decidable equality, show first that the successor function is injective.\n  \\item Show that if $A$ and $B$ have decidable equality, then so do $A+B$ and $A\\times B$. Conclude that $\\Z$ has decidable equality.\n  \\item Show that if $A$ is a retract of a type $B$ with decidable equality, then $A$ also has decidable equality.\n  \\end{subexenum}\n\\item Define the prime-counting function $\\pi:\\N\\to\\N$.\n\\item (The Cantor-Schr\\\"oder-Bernstein theorem) Let $X$ and $Y$ be two sets with decidable equality, and consider two maps $f:X\\to Y$ and $g:Y\\to X$, both of which we assume to be injective. Construct an equivalence $X\\simeq Y$.\n\\item For any $k:\\Z$, define a function $i\\mapsto i+k \\mod n$ of type $\\mathsf{Fin}(n)\\to\\mathsf{Fin}(n)$. Show that this function is an equivalence.\n\\item For any $k:\\Z$, define a function $i\\mapsto i\\cdot k \\mod n$ of type $\\mathsf{Fin}(n)\\to\\mathsf{Fin}(n)$. Show that this function is an equivalence if and only if $\\gcd(n,k)=1$.\n\\item Show that\n  \\begin{equation*}\n    \\sum_{i=0}^n \\binom{n-i}{i}=F_{n+1}\n  \\end{equation*}\n\\end{exercises}\n", "meta": {"hexsha": "ff59f9fe34367a4a64847562d8f5c01b0096ced7", "size": 23043, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/number-theory.tex", "max_stars_repo_name": "tadejpetric/HoTT-Intro", "max_stars_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Book/number-theory.tex", "max_issues_repo_name": "tadejpetric/HoTT-Intro", "max_issues_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Book/number-theory.tex", "max_forks_repo_name": "tadejpetric/HoTT-Intro", "max_forks_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.0656934307, "max_line_length": 526, "alphanum_fraction": 0.691359632, "num_tokens": 7448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046026642944, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7036472567989395}}
{"text": "\\subsubsection{Cross-Validation}\n\\label{cv}\n\nBecause ML models are trained by minimizing a loss function $L$, the\n    resulting value of $L$ underestimates the true error we see when\n    predicting into the actual future by design.\nTo counter that, one popular and model-agnostic approach is cross-validation\n    (CV), as summarized, for example, by \\cite{hastie2013}.\nCV is a resampling technique, which ranomdly splits the samples into a\n    training and a test set.\nTrained on the former, an ML model makes forecasts on the latter.\nThen, the value of $L$ calculated only on the test set gives a realistic and\n    unbiased estimate of the true forecasting error, and may be used for one\n    of two distinct aspects:\nFirst, it assesses the quality of a fit and provides an idea as to how the\n    model would perform in production when predicting into the actual future.\nSecond, the errors of models of either different methods or the same method\n    with different parameters may be compared with each other to select the\n    best model.\nIn order to first select the best model and then assess its quality, one must\n    apply two chained CVs:\nThe samples are divided into training, validation, and test sets, and all\n    models are trained on the training set and compared on the validation set.\nThen, the winner is retrained on the union of the training and validation\n    sets and assessed on the test set.\n\nRegarding the splitting, there are various approaches, and we choose the\n    so-called $k$-fold CV, where the samples are randomly divided into $k$\n    folds of the same size.\nEach fold is used as a test set once and the remaining $k-1$ folds become\n    the corresponding training set.\nThe resulting $k$ error measures are averaged.\nA $k$-fold CV with $k=5$ or $k=10$ is a compromise between the two extreme\n    cases of having only one split and the so-called leave-one-out CV\n    where $k = m$: Computation is still relatively fast and each sample is\n    part of several training sets maximizing the learning from the data.\nWe adapt the $k$-fold CV to the ordinal stucture in $\\mat{X}$ and $\\vec{y}$ in\n    Sub-section \\ref{unified_cv}.\n", "meta": {"hexsha": "86621897f74f2d4a440b6670cbb9e7cdd73209d9", "size": 2150, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2_lit/3_ml/3_cv.tex", "max_stars_repo_name": "webartifex/urban-meal-delivery-paper-demand-forecasting", "max_stars_repo_head_hexsha": "9ee3396a24ce20c9886b4cde5cfe2665fd5a8102", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-25T19:40:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T19:40:56.000Z", "max_issues_repo_path": "tex/2_lit/3_ml/3_cv.tex", "max_issues_repo_name": "webartifex/urban-meal-delivery-demand-forecasting", "max_issues_repo_head_hexsha": "9ee3396a24ce20c9886b4cde5cfe2665fd5a8102", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/2_lit/3_ml/3_cv.tex", "max_forks_repo_name": "webartifex/urban-meal-delivery-demand-forecasting", "max_forks_repo_head_hexsha": "9ee3396a24ce20c9886b4cde5cfe2665fd5a8102", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.1282051282, "max_line_length": 78, "alphanum_fraction": 0.7572093023, "num_tokens": 505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.7036472477295929}}
{"text": "% ------------------------------------------------------------------\n\\chapter{Geometry}\\label{s:geometry}\n% ------------------------------------------------------------------\n\nThis chapter looks at the geometry of the CNN input-output mapping.\n\n% ------------------------------------------------------------------\n\\section{Receptive fields and transformations}\\label{s:receptive}\n% ------------------------------------------------------------------\n\nVery often it is interesting to map a convolutional operator back to image space. Due to various downsampling and padding operations, this is not entirely trivial and analysed in this section. Considering a 1D example will be enough; hence, consider an input signal $x_i$, a filter $f_{i'}$ and an output signal $y_{i''}$, where\n\\[\n   1 - P_w^- \\leq i \\leq W + P_w^+,  \\qquad 1 \\leq i' \\leq W'.\n\\]\nwhere $P_w^-,P_w^+ \\geq 0$ is the amount of padding applied to the input signal to the left and right respectively. The output $y_i$ is obtained by applying a filter of size $W'$ in the following range\n\\[\n   - P_w^- + S (i'' - 1) + [1, W'] = [1 - P_w^- + S(i'' - 1), - P_w^- + S(i''-1) + W']\n\\]\nwhere $S$ is the subsampling factor. For $i'' = 1$, the leftmost sample of this window falls at the leftmost sample of the padded input signal. The rightmost sample $W'' \\geq i''$ of the output signal is obtained by guaranteeing that the filter window stays within the padded input signal:\n\\[\n- P_w^- + S(i''-1) + W' \\leq W + P_w^+\n\\qquad\\Rightarrow\\qquad\ni'' \\leq \\frac{W - W' + P_w^- + P_w^+}{S} + 1\n\\]\nSince $i''$ is an integer quantity, the maximum value is:\n\\begin{equation}\\label{e:width}\nW'' = \n\\left\\lfloor \\frac{W - W' + P_w^- + P_w^+}{S} \\right\\rfloor\n+ 1.\n\\end{equation}\nNote that $W''$ is smaller than 1 if $W' > W + P_w^- + P_w^+$; in this case the filter $f_{i'}$ is wider than the padded input signal $x_i$ and the domain of $y_{i''}$ becomes empty (this generates an error in most MatConvNet functions).\n\nNow consider a sequence of convolutional operators. One starts from an input signal $x_0$ of width $W_0$ and applies a sequence of  operators of parameters\n$\n(P_{w1}^-,  P_{w1}^+, S_1, W'_1), \n$\n$\n(P_{w2}^-,  P_{w2}^+, S_2, W'_2), \n$\n$\\dots,\n$\n$\n(P_{wL}^-,  P_{wL},^+ S_L, W'_L)\n$\nto obtain signals $x_1,x_2,\\dots,x_L$ of width $W_1,W_2,\\dots,W_L$ respectively. First, note that the widths of these signals are obtained from $W_0$ and the operator parameters by a recursive application of~\\eqref{e:width}. Due to the flooring operation, unfortunately it does not seem possible to simplify significantly the resulting expression. However, disregarding this operation one obtains the approximate expression\n\\[\nW_l \\approx\n\\frac{W_0}{\\prod_{p=1}^l S_q}\n-\n\\sum_{p=1}^l\n\\frac\n{W'_p - P_{wp}^- - P_{wp}^+  - S_{p}}\n{\\prod_{q=p}^l S_q}.\n\\]\nThis expression is exact when $S_1 = S_2 =\\dots = S_l =1$:\n\\[\nW_l = W_0 - \\sum_{p=1}^l (W'_p - P_{wp}^- - P_{wp}^+ - 1).\n\\]\nNote in particular that without padding and filters $W_p' >1$ the widths decrease with depth. \n\n\nNext, we are interested in computing the samples $x_{0,i_0}$ of the input signal that affect a particular sample $x_{L,i_L}$ at the end of the chain (this we call the \\emph{receptive field} of the operator). Suppose that at level $l$ we have determined that samples $i_l \\in [I_l^-(i_L), I_l^+(i_L)]$ affect $x_{L,i_L}$ and compute the samples at the level below. These are given by the union of filter applications:\n\\[\n \\cup_{I_l^-(i_L) \\leq i_l \\leq I_l^+(i_L)} \\left(-P_{wl}^- + S_l (i_l-1)  + [1, W_l'] \\right).\n\\]\nHence we find the recurrences:\n\\begin{align*}\n I_{l-1}^-(i_L) &= - P_{wl}^- + S_l (I_l^-(i_L)-1) + 1,\n \\\\\n I_{l-1}^+(i_L) &= - P_{wl}^- + S_l (I_l^+(i_L)-1) + W_l'.\n\\end{align*}\nGiven the base case $I_L^-(i_L) = I_L^+(i_L) = i_L$,  one gets:\n\\begin{align*}\nI_{l}^-(i_L)\n&=\n1 \n+ \\left(\\prod_{p=l+1}^L S_p\\right) (i_L - 1)\n- \\sum_{p =l+1}^L  \\left(\\prod_{q=l+1}^{p-1} S_q\\right)P_{wp}^-,\n\\\\\nI_{l}^-(i_L)\n&=\n1 \n+ \\left(\\prod_{p=l+1}^L S_p\\right) (i_L - 1)\n+ \\sum_{p = l+1}^L  \\left(\\prod_{q=l+1}^{p-1} S_q\\right)(W_p' - 1 - P_{wp}^-).\n\\end{align*}\nWe can now compute several quantities of interest. First, the receptive field width on the image is:\n\\[\n \\Delta \n = I_0^+(i_L) - I_0^-(i_L) + 1\n = 1+ \\sum_{p = 1}^L  \\left(\\prod_{q=1}^{p-1} S_q\\right)(W_p' - 1).\n\\]\nSecond, the leftmost sample of the input signal $x_{0,i_0}$ affecting output sample $x_{l,i_L}$ is\n\\[\ni_0(i_L)  =\n1 \n+ \\left(\\prod_{p=1}^L S_p\\right) (i_L - 1)\n- \\sum_{p =1}^L  \\left(\\prod_{q=1}^{p-1} S_q\\right)P_{wp}^-\n\\]\nNote that the effect of padding at different layers accumulates, resulting in an overall padding potentially larger than the padding $P_{w1}^-$ specified by the first operator (i.e. $i_0(1) \\leq - P_{w1}^-$).\n\nFinally, it is interesting to reparametrise these coordinates as if the discrete signal were continuous and if (as it is usually the case) all the convolutional operators are ``centred''. For example, the operators could be filters with an odd size $W_l'$ equal to the delta function (e.g. for $W_l'=5$ then $f_l = (0,0,1,0,0)$). Let $u_L = i_L$ be the ``continuous'' version of index $i_L$, where each discrete sample corresponds, as per MATLAB's convention, to a tile of extent $u_L \\in [-1/2,1/2] + i_L$ (hence $u_L$ is the centre coordinate of a sample). As before, $x_L(u_L)$ is obtained by applying an operator to the input signal $x_0$; the centre of the support of this operator falls at coordinate:\n\\[\n  u_0(u_L) = \\alpha\\, (u_L - 1) + \\beta = i_0(u_L) + \\frac{\\Delta-1}{2} = \\alpha\\, (u_L - 1) + \\beta.\n\\]\nHence\n\\[\n\\alpha = \\prod_{p=1}^L S_p,\n\\qquad\n\\beta\n = \n1\n+ \n\\sum_{p = 1}^L  \\left(\\prod_{q=1}^{p-1} S_q\\right)\n\\left(\n\\frac{W_p' - 1}{2}  - P_{wp}^-\n\\right).\n\\]\nNote in particular that the offset is zero if $S_1 =\\dots=S_L=1$ and $P_{wp}^- = (W_p'-1)/2$ as in this case the padding is just enough such that the leftmost application of each convolutional operator has the centre that falls on the first sample of the corresponding input signal.", "meta": {"hexsha": "c4b155ee331abff6cdcb663b3a5c179d9b282f57", "size": 5988, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/geometry.tex", "max_stars_repo_name": "Yijunmaverick/DeepJointFilter", "max_stars_repo_head_hexsha": "e6f2c8206937e8bd502749d026d688e62867f34a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 88, "max_stars_repo_stars_event_min_datetime": "2016-09-05T20:11:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T14:03:53.000Z", "max_issues_repo_path": "doc/geometry.tex", "max_issues_repo_name": "Yijunmaverick/DeepJointFilter", "max_issues_repo_head_hexsha": "e6f2c8206937e8bd502749d026d688e62867f34a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-10-24T00:50:50.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-07T07:11:04.000Z", "max_forks_repo_path": "doc/geometry.tex", "max_forks_repo_name": "Yijunmaverick/DeepJointFilter", "max_forks_repo_head_hexsha": "e6f2c8206937e8bd502749d026d688e62867f34a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 31, "max_forks_repo_forks_event_min_datetime": "2016-10-11T09:10:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-13T12:25:17.000Z", "avg_line_length": 50.7457627119, "max_line_length": 707, "alphanum_fraction": 0.6346025384, "num_tokens": 2065, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.7036472477295929}}
{"text": "\\section{Derivatives of Inverse Functions}\\label{sec:DerivativesofInverse}\r\nSuppose we wanted to find the \\ifont{derivative of the inverse}, but do not have an actual formula for the inverse function?\r\nThen we can use the following derivative formula for the inverse evaluated at $a$.\r\n\r\n%\\begin{formulabox}[Derivative of $f^{-1}(x)$]\r\n%Given an invertible function $f(x)$, the derivative of its inverse function $f^{-1}(x)$ evaluated at $x=a$ is:\r\n%$$\\left[f^{-1}\\right]'(a)=\\frac{1}{f'\\left[ f^{-1}(a) \\right]}$$\r\n%\\end{formulabox}\r\n\r\n\\begin{theorem}{Derivatives of Inverse Functions}{deriv_inverse_functions}\r\n{Let $f$ be differentiable and one to one on an open interval $I$, where $\\fp(x) \\neq 0$ for all $x$ in $I$, let $J$ be the range of $f$ on $I$, let $g$ be the inverse function of $f$, and let $f(a) = b$ for some $a$ in $I$. Then $g$ is a differentiable function on $J$, and in particular,\r\n\t\r\n%\t\\begin{center}\r\n\\hskip-7pt\t\\begin{tabular}{ccc}\r\n\t1. $\\ds \\left(f\\primeskip^{-1}\\right)'(b)=g\\primeskip'(b) = \\frac{1}{\\fp(a)}$ &\\hskip 4pt and \\hskip 4pt&  2. $\\ds \\left(f\\primeskip^{-1}\\right)'(x)=g\\primeskip'(x) = \\frac{1}{\\fp(g(x))}$\r\n\t\\end{tabular}\r\n%\t\\end{center}\r\n}\r\n\\end{theorem}\r\n\r\n\r\nTo see why this is true, start with the function $y=f^{-1}(x)$.\r\nWrite this as $x=f(y)$  and differentiate both sides implicitly with respect to $x$ using the chain rule:\r\n$$1=f'(y)\\cdot \\frac{dy}{dx}.$$\r\nThus,\r\n$$\\frac{dy}{dx}=\\frac{1}{f'(y)},$$\r\nbut $y=f^{-1}(x)$, thus,\r\n$$\\left[f^{-1}\\right]'(x)=\\frac{1}{f'\\left[ f^{-1}(x) \\right]}.$$\r\nAt the point $x=a$ this becomes:\r\n$$\\left[f^{-1}\\right]'(a)=\\frac{1}{f'\\left[ f^{-1}(a) \\right]}$$\r\n\r\nIn Section \\ref{sec:DerivativeExpLog}, we saw that $\\ds \\frac{d}{dx}\\big(\\ln x\\big) = \\frac{1}{x}$. We can justify that now using Theorem \\ref{thm:deriv_inverse_functions}, as shown in the example.\\\\\r\n\r\n\\begin{example}{Finding the derivative of $y=\\ln x$}{ex_deriv_lnx}\r\n{\r\nUse Theorem \\ref{thm:deriv_inverse_functions} to compute $\\ds \\frac{d}{dx}\\big(\\ln x\\big)$.}\r\n{View $y= \\ln x$ as the inverse of $y = e^x$. Therefore, using our standard notation, let $f(x) = e^x$ and $g(x) = \\ln x$. We wish to find $g\\primeskip'(x)$. Theorem \\ref{thm:deriv_inverse_functions} gives:\r\n\t\t\\begin{align*}\r\n\t\tg\\primeskip'(x) &= \\frac{1}{\\fp(g(x))} \\\\\r\n\t\t\t\t\t&=\t\\frac{1}{e^{\\ln x}}\\rule{0pt}{15pt} \\\\\r\n\t\t\t\t\t&= \\frac{1}{x}.\\rule{0pt}{17pt}\r\n\t\t\\end{align*}\r\n\\vskip-\\baselineskip\r\n}\r\n\\end{example}\r\n\r\n\r\n\r\n\\begin{example}{Derivatives of Inverse Functions}{DerivativesInverseFunctions}\r\nSuppose $f(x)=x^5+2x^3+7x+1$.\r\nFind $\\left[f^{-1}\\right]'(1)$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nFirst we should show that $f^{-1}$ exists (i.e. that $f$ is one-to-one). In this case the derivative $f'(x)=5x^4+6x^2+7$ is strictly greater than 0 for all $x$, so $f$ is strictly increasing and thus one-to-one.\r\n\r\nIt's difficult to find the inverse of $f(x)$ (and then take the derivative).\r\nThus, we use the above formula evaluated at $1$:\r\n$$\\left[f^{-1}\\right]'(1)=\\frac{1}{f'\\left[ f^{-1}(1) \\right]}.$$\r\nNote that to use this formula we need to know what $f^{-1}(1)$ is, and the derivative $f'(x)$.\r\nTo find $f^{-1}(1)$ we make a table of values (plugging in $x=-3,-2,-1,0,1,2,3$ into $f(x)$) and see what value of $x$ gives $1$.\r\nWe omit the table and simply observe that $f(0)=1$.\r\nThus, \r\n$$f^{-1}(1)=0.$$\r\nNow we have:\r\n$$\\left[f^{-1}\\right]'(1)=\\frac{1}{f'\\left( 0 \\right)}.$$\r\nAnd so, $f'(0)=7$.\r\nTherefore, $$\\left[f^{-1}\\right]'(1)=\\frac{1}{7}.$$\r\n\\end{solution}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n% Subsections to include\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\input{4-derivatives/4-9-1-der-inv-trig}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for \\ref{sec:DerivativesofInverse}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n\tGiven $f(x)=1+\\ln(x-2)$, first show that $f^{-1}$ exists, then compute $\\left[f^{-1}\\right]'(1)$.\r\n\\begin{sol}\r\n\t$1$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nThe \\dfont{inverse cotangent function}, denoted by $\\cot^{-1}(x)$, is defined to be the inverse of the restricted cotangent function: $\\cot (x)$, $0<x<\\pi$. Find the derivative of $\\cot^{-1}(x)$.\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nThe \\dfont{inverse secant function}, denoted by $\\sec^{-1}(x)$, is defined to be the inverse of the restricted secant function: $\\sec(x)$, $x\\in[0,\\pi/2)\\cup[\\pi,3\\pi/2)$. Find the derivative of $\\sec^{-1}(x)$.\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nThe \\dfont{inverse cosecant function}, denoted by $\\csc^{-1}(x)$, is defined to be the inverse of the restricted cosecant function: $\\csc(x)$, $x\\in(0,\\pi/2]\\cup(\\pi,3\\pi/2]$. Find the derivative of $\\csc^{-1}(x)$.\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nSuppose $f(x)=x^3+4x+2$. Find the slope of the tangent line to the graph of $g(x)=xf^{-1}(x)$ at the point where $x=7$.\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nFind the derivatives of $\\sin^{-1}(x)+\\cos^{-1}(x)$ and $(x^2+1)\\tan^{-1}(x)$.\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nDifferentiate $y=\\sin^{-1}(x^2)$ and $y=\\tan^{-1}(3x)$.\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "8ea40e15ca3af891b002c67ec252dbbfab712893", "size": 5047, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-derivatives/4-9-0-inv-der.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4-derivatives/4-9-0-inv-der.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4-derivatives/4-9-0-inv-der.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.8869565217, "max_line_length": 290, "alphanum_fraction": 0.6128393105, "num_tokens": 1782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.808067208930584, "lm_q2_score": 0.8705972583359805, "lm_q1q2_score": 0.7035010966461743}}
{"text": "\\subsection{Damage Evolution and Stiffness Degredation}\n\nThe evolution of the equivalent plastic strains are formulated by assuming the stress-strain curves can be converted  into stress vs plastic strain curves where the tensile and compressive stresses are streated seperately:\n\\begin{equation}\n\\label{eqn:dam1}\n\\begin{aligned}\n\\boldsymbol{\\sigma}_t = \\boldsymbol{\\sigma}_t(\\boldsymbol{\\bar{\\epsilon}^{pl}_t},\n\t\\boldsymbol{\\dot{\\bar{\\epsilon}}^{pl}_t}) \\\\\n\\boldsymbol{\\sigma}_c = \\boldsymbol{\\sigma}_c(\\boldsymbol{\\bar{\\epsilon}^{pl}_c},\n\t\\boldsymbol{\\dot{\\bar{\\epsilon}}^{pl}_c})\n\\end{aligned}\n\\end{equation}\n\nLoading a quasi-brittle in compression or tension causes damage in the material, which reduces the effective stiffness, weakening the unloading response. This damage is characterized by two damage variables, one of which represents the damage due to tensile loading, the other represents damage due to compressive loading. \n\\begin{equation}\n\\label{eqn:dam2}\n\\begin{aligned}\nD_t = D_t(\\boldsymbol{\\bar{\\epsilon}^{pl}_t}),\\qquad 0 \\leq D_t \\leq 1 \\\\\nD_c = D_c(\\boldsymbol{\\bar{\\epsilon}^{pl}_c}),\\qquad 0 \\leq D_t \\leq 1\n\\end{aligned}\n\\end{equation}\n\nThe damage in both compression and tension is a neccesarily increasing function of the equivalent plastic strains. This formulation will adopt the convention where $\\boldsymbol{sigma_c}$ is positive in compression, as with the respectiove strains.\n\\begin{equation}\n\\label{eqn:dam3}\n\\begin{aligned}\n\\boldsymbol{\\sigma}_t = (1-D_t)\\mathbf{E}:(\\boldsymbol{\\epsilon_t} - \\boldsymbol{\\bar{\\epsilon}^{pl}_t}) \\\\\n\\boldsymbol{\\sigma}_c = (1-D_c)\\mathbf{E}:(\\boldsymbol{\\epsilon_c} - \\boldsymbol{\\bar{\\epsilon}^{pl}_c})\n\\end{aligned}\n\\end{equation}\n\nFor cyclic loading, both the compressive and tensile damage need to be considered. Two stiffness recovery factors are introduced, $s_t$ and $s_c$, which represent the stiffness recovery effects associated with stress reversals. The damage can be said to take the form of:\n\\begin{equation}\n\\label{eqn:dam4}\n(1-D) = (1-s_t D_c)(1-s_c D_t),\\qquad 0 \\leq s_t, s_c, \\leq 1\n\\end{equation}\n\nIn the case of tensile loading followed by compressive loading, the stiffness is assumed to completely recover\n\n\n\n\n", "meta": {"hexsha": "a5f9ae1d54c86d8682d43d802f7af92309e8ad2c", "size": 2202, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "unused/subsection_damageEvolutionAndStiffnessDegredation.tex", "max_stars_repo_name": "yetisir/up-scaling-dem-simulations", "max_stars_repo_head_hexsha": "9c9043effdb72a608ffec11726af97154751722e", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "unused/subsection_damageEvolutionAndStiffnessDegredation.tex", "max_issues_repo_name": "yetisir/up-scaling-dem-simulations", "max_issues_repo_head_hexsha": "9c9043effdb72a608ffec11726af97154751722e", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "unused/subsection_damageEvolutionAndStiffnessDegredation.tex", "max_forks_repo_name": "yetisir/up-scaling-dem-simulations", "max_forks_repo_head_hexsha": "9c9043effdb72a608ffec11726af97154751722e", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-29T23:14:09.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-29T23:14:09.000Z", "avg_line_length": 51.2093023256, "max_line_length": 323, "alphanum_fraction": 0.759763851, "num_tokens": 628, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7034917181165206}}
{"text": "\\subsection{Neural Network Design and Training}\n\\label{subsec:nntraining}\n\n%\\begin{wrapfigure}{r}{0.5\\textwidth}\n%\t\\centering\n%    \\includegraphics[width=0.35\\textwidth]{img/nnlayout}\n%\t\\caption{Network Layers}\n%\t\\label{fig:network-layers}\n%\\end{wrapfigure}\n\n\nThe network was implemented in PyTorch \\cite{Paszke:2019aa} as well as Tensorflow \\cite{MartinAbadi:2015aa}. The backend was later exclusively switched to PyTorch (which is also the most common deep learning framework in Science) due to its better support of quantization. The layers of the neural network are depicted in Figure~\\ref{fig:eggnet}. \nThe network was trained on the \\emph{MNIST} dataset which consists of 60.000 images of handwritten digits. Those where split up in 50.000 images used for training and 10.000 used for evaluation. The network maps mathematically an $28 \\times 28$ input image $x \\in \\mathbb{R}^{28,28}$ to an output of vector of probabilities $y \\in \\mathbb{R}^{10}$ where each value corresponds how likely the input image belongs to that class. The layers of the network are listed in Table~\\ref{tab:eggnet-layers}.\n\n\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{clcl}\n\t\t\\toprule\n\t\tLayer & Type\t& \tData Size (output)\t& Purpose \\\\\n\t\t\\midrule\n\t\t 1 & Conv01\t\t&\t$[28,28,16]$\t& Extract features ($[3,3]$ kernels)\t\t  \\\\\n\t\t 2 & ReLU\t\t&\t$[28,28,16]$\t& Introduce nonlinearity  \\\\\n\t\t 3 & Pool01\t\t&\t$[14,14,16]$\t& Introduce nonlinearity, reduce dimensions  \\\\\n\t\t 4 & Conv02 \t&\t$[14,14,32]$\t& Extract features \t($[3,3]$ kernels)\t  \\\\\n\t\t 5 & ReLU\t\t&\t$[14,14,32]$\t& Introduce nonlinearity  \\\\\n\t\t 6 & Pool02\t\t&\t$[7,7,32]$\t& Introduce nonlinearity, reduce dimensions  \\\\\n\t\t 7 & Dense01\t&\t$[32]$\t\t& Combine features  \\\\\n\t\t 8 & ReLU\t\t&\t$[32]$\t\t& Introduce nonlinearity  \\\\\n\t\t 9 & Dense02\t&\t$[10]$\t\t& Combine features  \\\\\n\t\t10 & Softmax \t&\t$[10]$\t\t& Normalize output  \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\t\\caption{Eggnet Layers}\n\t\\label{tab:eggnet-layers}\n\\end{table}\n\nFurther for training of the network the \\emph{ADAM} optimization algorithm \\cite{Kingma:2014aa} was used to minimize the cross-entropy-loss function which is defined as\n\\begin{equation}\n    J = - y  \\log(h) + (1-y)  \\log(1-h)\n\\end{equation}\nThis loss function is standard for classification problems where each sample belongs to exactly one class. \nThe ADAM algorithm can be adjusted by parameters, which control the speed of convergence. The recommended values, listed in Table~\\ref{tab:train-params}, by \\cite{Kingma:2014aa} were used.\n\\begin{table}[ht]\n\t\\centering\n    \\begin{tabular}{cc}\n        \\toprule\n            Parameter & Value \\\\\n        \\midrule\n            $\\alpha$   & $0.001$ \\\\\n            $\\beta_1$  & $0.9$   \\\\\n            $\\beta_2$  & $0.999$  \\\\          \n        \\bottomrule\n    \\end{tabular}\n    \\caption{Network Training Parameters}\n    \\label{tab:train-params}\n\\end{table}\n\n\nA useful guide for implementing convolutions can be found in \\cite{dumoulin2016guide}. The training of the network yielded very high accuracy rates that are typical for the MNIST dataset, which is an easy challenge for machine learning. Even though the network performance could be improved, e.g. by hyperparameter tuning the results were acceptable for our case. The progress of the training in terms of accuracy and loss can be seen in Figure~\\ref{fig:network-train-acc} respectively in Figure~\\ref{fig:network-train-loss}. The final output of the network over the training is evaluated in Figure~\\ref{fig:network-test-cm} for real values and in Figure~\\ref{fig:network-test-qcm} for fake quantized values.\n\nBoth, PyTorch and Tensorflow/Keras are Python libraries but most \\gls{acr:NN} operations are not implemented in Python directly because of performance reasons. This makes debugging more difficult which is why we reimplemented the operations we needed in Python. This was done using NumPy and SWIG, which will be discussed more extensively in Section~\\ref{sec:sw-python}, and enabled us to verify the correct ordering of parameters, weights and activations.\n\n\\begin{figure}[hbtp]\n\\centering\n\\begin{subfigure}[t]{0.5\\textwidth}\n\t\\includegraphics[width=0.8\\textwidth]{../../net/images/training_loss}\n\t\\caption{Training Loss}\t\t\n\t\\label{fig:network-train-loss}\n\\end{subfigure}%\n~\n\\begin{subfigure}[t]{0.5\\textwidth}\n\t\\includegraphics[width=0.8\\textwidth]{../../net/images/training_accuracy}\n\t\\caption{Training Accuracy}\n\t\\label{fig:network-train-acc}\t\t\n\\end{subfigure}\n\\caption[Network loss and accuracy over the training iterations]{Network loss and accuracy over the training iterations. The blue lines show spikes which occur because of the randomly selected mini batches. The orange line shows the smoothed version over 50 periods}\n\\label{fig:network-training-graphs}\n\\end{figure}\n\n\\begin{figure}[hbtp]\n\\centering\n\\begin{subfigure}[t]{0.5\\textwidth}\n\t\\includegraphics[width=0.9\\textwidth]{../../net/images/cm}\n\t\\caption{Floating Point}\n\t\\label{fig:network-test-cm}\n\\end{subfigure}%\n~\n\\begin{subfigure}[t]{0.5\\textwidth}\n\t\\includegraphics[width=0.9\\textwidth]{../../net/images/qcm}\n\t\\caption{Quantized Values}\n\t\\label{fig:network-test-qcm}\n\\end{subfigure}\n\\caption{Confusion matrix for the floating point and quantized version of the network.}\n\\label{fig:network-confusion-matrix}\n\\end{figure}\n\n\n\\subsection{Quantization}\n\\label{sec:nn-quant}\n\nThe network is trained and created using \\SI{32}{\\bit} floating point values in Python. Directly porting this all the weights and biases to the FPGA is due to the limited amount of available resources not feasible. The goal is therefore to reduce the amount of required hardware cells by switching from floating point arithmetic to the less expensive integer arithmetic. Then a floating point value $v$ can be approximately represented as \n\\begin{equation}\n\tv \\approx Q \\cdot 2 ^{-m}\n\\end{equation}\nwhere $Q$ and $m$ are integers. In our case all input values of the first layer are guaranteed to lie in the interval $[0,1]$ and all layer weights are known from training. It is therefore possible to precompute the expected range where the output values will be. Depending on this range it is then possible to select a suitable bit width for both $Q$ and $m$.\n\nThis is a cost-accuracy trade-off where higher bit widths would improve accuracy as well as increase the amount of hardware resources needed.\nIn \\cite{Wu:2018aa} different strategies of choosing bit widths for $Q$ and $m$ are compared and they observed three main configurations, which are (from simple to advanced):\n\\begin{enumerate}\n\t\\item Use a $(Q,m)$ configuration for the whole network\n\t\\item Use a $(Q,m)$ configuration for each layer\n\t\\item Use a $(Q,m)$ configuration for each output channel \n\\end{enumerate}\nIn the third configuration the authors could reduce the bit widths the most without sacrificing accuracy this increases the complexity in transferring the weights from layer to layer because the additional shift operations are necessary in order to adjust for the different values of $m$.\nIn \\cite{Wu:2018aa} the authors also deduced from their experiments that the accuracy of the weights can be reduced the most, followed by the activations. By analysing the weights of our network (see Figure~\\ref{fig:network-weight-distributions}) a per channel quantization is not necessary, because all weights in a Convolutional Layer are equally distributed among the output channels. Another important property that can be noted is the that the weights do have zero mean and most of the values lie very close to zero. Because of the usage of ReLU layer the situation is different for the activations where unsigned integers can be used, the distributions are shown in Figure~\\ref{fig:network-activations-distributions}.\n\nUsing the distribution histograms we then derived the necessary bitwidths for $Q$ and $m$. In our experiments we were able to reduce them to \\SI{8}{\\bit}, if we used a single configuration for the whole network and also reducing them down to \\SI{4}{\\bit} if the bitwidth configuration is selected for each layer independently with an accuracy drop from around \\SI{98.35}{\\percent} to \\SI{97.37}{\\percent}. The strategy to the select the values for $(Q,m)$ was\n\\begin{enumerate}\n\t\\item Find the value range of the weights and output activations of each layer\n\t\\item Select suitable $(Q,m)$ values that most activations fall in that range\n\t\\item Calculate the bit widths and exponents of the multiplication operation\n\t\\item Add $\\lceil \\log_2(n) \\rceil$ extra bits to account for the accumulation of $n$ values\n\t\\item Compare the accumulated exponents and with the exponents of the successive layers input exponents. The difference is the amount of shift required\n\\end{enumerate}\nIt is noteworthy that the values for $m$ do not need to be stored in the final network, because those are only used to determine the amount of shifts between the layers. Also the values need to be clipped to their maximum and minimum values. The complete configuration of the network is summarized in Table~\\ref{tab:quantization-linear-params}.\n\nAd 4 and 5: The transition from a layer to the next often changes the exponent $m$ and the available bitwidth. To account for this the values need to accordingly shifted. Also the decreased bitwidth needs clipping to maximum available values for the target bitwidth. This directly alters the behaviour of the network which should be accounted for during training, which is done via a saturated version of ReLU, defined as:\n\\begin{equation}\n    \\text{ReLU}_{\\text{sat}}: ~ f(x;p) = \\begin{cases}\n\t\t0 \t\\quad \\text{if} \\quad x < 0 \\\\\n\t\tp \t\\quad \\text{if} \\quad x > p \\\\\n\t\tx\t\\quad \\text{else}\n\t\\end{cases}\n\\end{equation}\n\nFor our network only linear quantization has been used but also non-linear quantization, e.g. in a $\\log_2$ way which is proposed in \\cite{Lee:2017aa}. Experiments showed that using this technique even further down to \\SI{3}{\\bit} weights in our case.\nAnother optimization technique that could be explored is the systematically removing of weights (connections) of the network and reduce the amount of operations needed to be performed, a process referred to as ''pruning'' \\cite{Zhu:2017aa}. This was not explicitly performed but is implicitly done by low bit quantization.\n\n\\begin{table}[hbt]\n  \\centering\n  \\begin{tabular}{lcccc}\n\t\\toprule\n    Network Part \t  & $|Q|$ & $m$ & $\\pm$ & $v$ (real value range) \\\\\n\t\\midrule\n    Input \t\t \t  &  8    & 8  & $+$   & $[0,1]  $ \\\\\n    L1: Weights \t  &  4    & 2  & $\\pm$ & $[-2,2] $ \\\\\n    L1: Intermediates & 12    & 10 & $\\pm$ & $[-2,2] $ \\\\\n    L1: Accumulated   & 16    & 10 & $\\pm$ & \t\t   \\\\\n    \\midrule\n    L1 $\\to$ L2 \t  & \\multicolumn{4}{c}{Rshift by $10-2$ and clip values in range $[0,15]$} \\\\\n    \\midrule\n    L2: Input \t\t  &  4    & 2  & $+$   & $[-2,2] $ \t   \\\\\n    L2: Weights \t  &  4    & 5  & $\\pm$ & $[-0.5,0.5] $ \\\\\n    L2: Intermediates &  8    & 7  & $\\pm$ & $[-1,1] $ \\\\\n    L2: Accumulated   & 16    & 7  & $\\pm$ &  \t\t\t   \\\\\n    \\midrule\n    L2 $\\to$ L3 \t  & \\multicolumn{4}{c}{Rshift by $7-0$ and clip values in range $[0,15]$} \\\\\n    \\midrule\n    L3: Input \t\t  &  4    & 0  & $+$   & $[0,15] $     \\\\\n    L3: Weights \t  &  4    & 5  & $\\pm$ & $[-0.5,0.5] $ \\\\\n    L3: Intermediates &  8    & 5  & $\\pm$ & $[-7.5,7.5] $ \\\\\n    L3: Accumulated   & 19    & 5  & $\\pm$ &               \\\\\n    \\midrule\n    L3 $\\to$ L4 \t  & \\multicolumn{4}{c}{Rshift by $5-0$ and clip values in range $[0,15]$} \\\\\n    \\midrule\n    L4: Input \t\t  &  4    & 0  & $+$   & $[0,15] $ \\\\\n    L4: Weights \t  &  4    & 5  & $\\pm$ & $[-0.5,0.5] $ \\\\\n    L4: Intermediates &  8    & 5  & $\\pm$ & $[-7.5,7.5] $ \\\\\n    L4: Accumulated   & 14    & 5  & $\\pm$ & $[0,1] $ \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\caption[Quantization parameters for the \\SI{4}{\\bit} network]{Quantization parameters for the \\SI{4}{\\bit} network. The intermediate terms are the values after the multiplication operation and the accumulated term denotes values after summing up of weighted inputs including bias in a channel.}\n  \\label{tab:quantization-linear-params}\n\\end{table}\n\n\n%% WEIGHT DISTTRIBUTIONS\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{subfigure}[t]{0.5\\textwidth}\n        \\centering\n        \\includegraphics[height=1.6in]{../../net/images/hist_cn1_k}\n        \\caption{Convolutional Layer 1}\n    \\end{subfigure}%\n    ~ \n    \\begin{subfigure}[t]{0.5\\textwidth}\n        \\centering\n         \\includegraphics[height=1.6in]{../../net/images/hist_cn2_k}\n        \\caption{Convolutional Layer 2}\n    \\end{subfigure}%\n    \\\\\n    \\begin{subfigure}[t]{0.5\\textwidth}\n        \\centering\n        \\includegraphics[height=1.6in]{../../net/images/hist_fc1_w}\n        \\caption{Fully Connected Layer 1}\n    \\end{subfigure}%\n    ~ \n    \\begin{subfigure}[t]{0.5\\textwidth}\n        \\centering\n         \\includegraphics[height=1.6in]{../../net/images/hist_fc2_w}\n        \\caption{Fully Connected Layer 2}\n    \\end{subfigure}\n    \\caption[Distribution of the network weights for the different layers]{Distribution of the network weights for the different layers. It can be seen that the weights are distributed close to zero.}\n    \\label{fig:network-weight-distributions}\n\\end{figure}\n\n\n%% ACTIVATIONS DISTTRIBUTIONS\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{subfigure}[t]{0.5\\textwidth}\n        \\centering\n        \\includegraphics[height=1.6in]{../../net/images/hist_ao1}\n        \\caption{Convolutional Layer 1}\n    \\end{subfigure}%\n    ~ \n    \\begin{subfigure}[t]{0.5\\textwidth}\n        \\centering\n         \\includegraphics[height=1.6in]{../../net/images/hist_ao2}\n        \\caption{Convolutional Layer 2}\n    \\end{subfigure}%\n    \\\\\n    \\begin{subfigure}[t]{0.5\\textwidth}\n        \\centering\n        \\includegraphics[height=1.6in]{../../net/images/hist_ao3}\n        \\caption{Fully Connected Layer 1}\n    \\end{subfigure}%\n    ~ \n    \\begin{subfigure}[t]{0.5\\textwidth}\n        \\centering\n         \\includegraphics[height=1.6in]{../../net/images/hist_ao4}\n        \\caption{Fully Connected Layer 2}\n    \\end{subfigure}\n    \\caption[Distribution of the activations for a randomly selected batch of the input data]{Distribution of the activations for a randomly selected batch of the input data. The occurring minimum and maximum values were used to define the quantization bit width.}\n    \\label{fig:network-activations-distributions}\n\\end{figure}\n\n", "meta": {"hexsha": "b5e213b55da8b4da6e3f9a491bdcf906a715b7fa", "size": 14279, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/documentation/nntraining.tex", "max_stars_repo_name": "marbleton/FPGA_MNIST", "max_stars_repo_head_hexsha": "4b4a30e0adca35de9adcad7b3fec08c516260790", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-11-13T12:24:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-31T02:39:35.000Z", "max_issues_repo_path": "tex/documentation/nntraining.tex", "max_issues_repo_name": "marbleton/FPGA_MNIST", "max_issues_repo_head_hexsha": "4b4a30e0adca35de9adcad7b3fec08c516260790", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2019-12-17T22:06:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T00:20:45.000Z", "max_forks_repo_path": "tex/documentation/nntraining.tex", "max_forks_repo_name": "marbleton/FPGA_MNIST", "max_forks_repo_head_hexsha": "4b4a30e0adca35de9adcad7b3fec08c516260790", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-10-20T15:12:52.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-13T13:36:37.000Z", "avg_line_length": 59.9957983193, "max_line_length": 723, "alphanum_fraction": 0.7039708663, "num_tokens": 4107, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160257, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.703409179486661}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 3}\n\nProve that a simple loop contains no edge more than one.\n\n\\subsection*{Solution}\n\nBy definition, the loop $v_0 \\rightarrow v_1 \\rightarrow \\cdots \\rightarrow v_k$ is simple if $k \\geq 3$ and it contains no vertex more than once except for the first and last vertex which are the same and occur only twice.\n\nProof is thus given by contradiction.\nWe assume that a simple loop might contain the edge $v_i \\rightarrow v_{i+1}$ more than once, where $0 \\leq i < k$.\nIf $i \\neq 0$, $v_i$ (and $v_{i+1}$) would occur twice while neither of them are first or last vertex.\nTherefore, the assumption would violate definition of the simple loop.\nIf $i = 0$, the path would be of the form $v_i \\rightarrow \\cdots \\rightarrow v_i \\rightarrow \\cdots \\rightarrow v_k$.\nIn this case, since $v_0$ and $v_k$ are the same, $v_i$ will occur more than twice which again violates the definition.\nTherefore the assumption is false and proof is complete.\n", "meta": {"hexsha": "ee38661d4ca6f6fd0ebaf53b02e355a814f64559", "size": 1309, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q03.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q03.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q03.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 56.9130434783, "max_line_length": 223, "alphanum_fraction": 0.679144385, "num_tokens": 330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479465, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.7034091628818713}}
{"text": "\\section{Functions}\n\n\\begin{definition}\n  We define the \\textbf{composite} $g \\circ f$ of $f : A \\to B$ and $g : B \\to C$ as the function $g \\circ f : A \\to C$ defined by the equation\n  \\begin{equation}\n    (g \\circ f)(a) = g(f(a))\n  \\end{equation}\n\n  and\n\n  \\begin{equation}\n    \\pbrac{(a, c) \\mid \\text{for some } b \\in B, f(a) = b \\text{ and } g(b) = c}\n  \\end{equation}\n\\end{definition}\n\n\\begin{definition}\n  A function $f$ is \\textbf{injective} if\n  \\begin{equation}\n    \\pbra{\n      f(a) = f(a')\n    } \\implies \\pbra{\n      a = a'\n    }\n  \\end{equation}\n\\end{definition}\n\n\\begin{definition}\n  A function $f$ is \\textbf{surjective} if\n  \\begin{equation}\n    \\pbra{b \\in B} \\implies \\pbra{\n      \\exists a \\in A, b = f(a)\n    }\n  \\end{equation}\n\\end{definition}\n\n\\begin{lemma}\n  Let $f : A \\to B$. If there are functions $g : B \\to A$ and $h : B \\to A$ such\n  that $g(f(a) = a, \\forall a \\in A$ and $f(h(b)) = b, \\forall b \\in B$, then\n  $f$ is bijective and $g = h = f^{-1}$.\n\\end{lemma}\n\n\\begin{definition}\n  $f(A_0)$ is the \\textbf{image} of $A_0$, and\n  \\begin{equation}\n    f(A_0) = \\pbrac{\n      b \\mid \\exists a \\in A_0, b = f(a)\n    }\n  \\end{equation}\n\\end{definition}\n\n\\begin{definition}\n  $f^{-1}(B_0)$ is the preimage of $B_0$ under $f$, formally\n  \\begin{equation}\n    f^{-1}(B_0) = \\pbrac{\n      a \\mid f(a) \\in B_0\n    }\n  \\end{equation}\n\\end{definition}\n\n\\section*{Exercises}\n\n\\bx{\n  \\ea{\n    \\item Suppose $x \\in A_0$. Then consider\n\n    \\begin{equation*}\n      f^{-1}(f(A_0)) = \\pbrac{x' \\mid f(x') \\in f(A_0)}.\n    \\end{equation*}\n\n    Since $x \\in A_0$, we know $f(x) \\in f(A_0)$, and so we can conclude $x \\in f^{-1}(f(A_0))$.\n\n    If $f$ is injective, then we know $f(x) = f(x'), x' \\in A_0$ implies that $x = x' \\implies x \\in A_0$, proving equality.\n\n    \\item Suppose $y \\in f(f^{-1}(B_0)) = \\pbrac{y' \\mid \\exists x \\in f^{-1}(B_0), y' = f(x)}$.\n\n    We have $x \\in \\pbrac{x' \\mid f(x') \\in B_0}$, which means $y' = f(x) \\in B_0$, so therefore $y \\in B_0$.\n\n    If $f$ is surjective, then we know $y \\in B_0 \\implies \\exists x \\in A$ such that $f(x) = y$.\n\n    In particular, $f(x) = y \\in B_0$, this set of $x \\in f^{-1}(B_0)$, so we can conclude that $y \\in f(f^{-1}(B_0))$.\n  }\n}\n\n\\bx{\n  \\ea{\n    \\item We can write some definitions first\n    \\begin{itemize}\n      \\item $f^{-1}(B_0) = \\pbrac{x \\mid f(x) \\in B_0}$\n      \\item $f^{-1}(B_1) = \\pbrac{x \\mid f(x) \\in B_1}$\n    \\end{itemize}\n\n    If we know $B_0 \\subset B_1$, then for some $x \\in B_0$, we know $x \\in B_1$.\n\n    This means for some $f(x) \\in B_0, f(x) \\in B_1$ as well, so therefore $f^{-1}(B_0) \\subset f^{-1}(B_1)$.\n\n    \\item\n    \\begin{align*}\n      f^{-1}(B_0 \\cup B_1) &= \\pbrac{x \\mid f(x) \\in B_0 \\cup B_1}\\\\\n      &= \\pbrac{x \\mid f(x) \\in B_0 \\text{ or } f(x) \\in B_1}\\\\\n      &= \\pbrac{x \\mid f(x) \\in B_0} \\cup \\pbrac{x \\mid f(x) \\in B_1}\\\\\n      &= f^{-1}(B_0) \\cup f^{-1}(B_1)\n    \\end{align*}\n\n    \\label{item:inverse_or}\n\n    \\item Basically the same proof as \\ref{item:inverse_or}.\n    \\item Basically the same proof as \\ref{item:inverse_or}.\n    \\item Suppose $x \\in A_0$ means $x \\in A_1$ as well.\n    Consider $y \\in f(A_0) = \\pbrac{y' \\mid y' = f(x) \\text{ for some } x \\in A_0}$. Because of our assumptions, it is also the case that\n    $y \\in \\pbrac{y' \\mid y' \\text{ for some } x \\in A_1} = f(A_1)$.\n\n    Notice that $f(A_0) \\subset f(A_1)$ does not imply that $A_0 \\subset A_1$. E.g. think parabola.\n\n    \\item\n    \\begin{align*}\n      f(A_0 \\cup A_1)\n      &= \\pbrac{y \\mid y = f(x) \\text{ for some } x \\in A_0 \\cup A_1} \\\\\n      &= \\pbrac{y \\mid y = f(x) \\text{ for some } x \\in A_0 \\text{ or } x \\in A_1} \\\\\n      &= \\pbrac{y \\mid y = f(x) \\text{ for some } x \\in A_0} \\cup \\pbrac{y \\mid y \\text{ for some } x \\in A_1} \\\\\n      &= f(A_0) \\cup f(A_1)\n    \\end{align*}\n\n    \\item\n    \\begin{equation*}\n      f(A_0 \\cap A_1) = \\pbrac{y \\mid y = f(x) \\text{ for some } x \\in A_0 \\cap A_1}\n    \\end{equation*}\n    which implies that $f(A_0 \\cap A_1) \\in f(A_0)$, since $x \\in A_0$ and $f(A_0 \\cap A_1) \\in f(A_1)$, since $x \\in A_1$.\n\n    This means that $f(A_0 \\cap A_1) \\subset f(A_0) \\cap f(A_1)$.\n\n    Now, if $f$ is injective, then if we start with $y \\in f(A_0) \\cap f(A_1)$,\n    we know $y \\in \\pbrac{y' \\mid y' = f(x), x \\in A_0}$ and\n    $y \\in \\pbrac{y' \\mid y' = f(x), x \\in A_1}$. Since $f$ is injective, the\n    common $y'$ values in $f(A_0)$ and $f(A_1)$ will map to the same $x$ values\n    in $A_0$ and $A_1$, which means $y \\in \\pbrac{y' \\mid y' = f(x), x \\in A_0 \\cap A_1} = f(A_0 \\cap A_1)$.\n  }\n}\n\n\\bx{\n  too lazy\n}\n\n\\bx{\n  \\ea{\n    \\item Consider\n    \\begin{align*}\n      (g \\circ f)^{-1}(C_0)\n      &= \\pbrac{a \\mid (g \\circ f)(x) \\in C_0} \\tag{by definition}\\\\\n      &= \\pbrac{a \\mid \\text{for some } b \\in B, f(a) = b, g(b) = c \\in C_0} \\\\\n      &= \\pbrac{a \\mid \\text{for some } b \\in B, f(a) = b, b \\in g^{-1}(C_0)} \\tag{we know $b \\in g^{-1}(C_0)$ since $C_0 \\subset C$}\\\\\n      &= \\pbrac{a \\mid f(a) \\in g^{-1}(C_0)}\\\\\n      &= f^{-1}\\pa{g^{-1}\\pa{C_0}}\n    \\end{align*}\n\n    Just a note for this problem, it's easy to get caught up with definitions\n    and forget why we need assumptions. It might seem easy to do this problem\n    without the fact that $C_0 \\subset C$, but if you look at the step where we\n    use that property, if $C_0 \\not\\subset C$, we cannot assume that $b \\in\n    g^{-1}(C_0)$, e.g. if $C_0$ contains elements that are not in $C$.\n\n    \\item Suppose we have\n    \\begin{align*}\n      (g \\circ f)(a) &= (g \\circ f)(a')\\\\\n      g(f(a)) &= g(f(a'))\\tag{by def.}\\\\\n      f(a) &= f(a')\\tag{because $g$ is injective}\\\\\n      a &= a'\\tag{because $f$ is injective}\n    \\end{align*}\n    therefore we conclude that $g \\circ f$ is also injective.\n\n    \\item If we know that $g \\circ f$ is injective,\n    \\begin{itemize}\n      \\item \\AFSOC $f$ is not injective. Then $\\exists a_1, a_2$ such that\n      $f(a_1) = f(a_2)$ but $a_1 \\neq a_2$. If this is the case, then $(g \\circ\n      f)(a_1) = g(f(a_1)) = g(f(a_2)) = (g \\circ f)(a_2)$ which shows that $g\n      \\circ f$ is not injective. Which is a contradiction. Therefore, $f$ must\n      be injective.\n\n      \\item It is possible for $g$ to not be injective. We can have some $b \\in\n      B$ that $\\not\\exists a \\in A$ such that $f(a) = b$. In this case, we will\n      not be able to find some input $a \\neq a' \\in $ where we break injectivity\n      for $g \\circ f$.\n    \\end{itemize}\n\n    \\item Suppose $f$ and $g$ are surjective. Now consider some $c \\in C$.\n    Since $g$ is surjective, we know $\\exists b \\in B$ such that $g(b) = c$.\n    For this $b \\in B$, since $f$ is surjective, we know that $\\exists a \\in A$\n    such that $f(a) = b$.\n    This means for any $c \\in C$, we know $\\exists a$ such that $g(f(a)) = (g\n    \\circ f)(a) = c$, which means $g \\circ f$ is surjective.\n\n    \\item If we know that $g \\circ f$ is surjective,\n    \\begin{itemize}\n      \\item It is possible for $f$ to not be surjective. Intuitively, a\n      counterexample would show that there is some $b \\in B$ such that\n      $\\not\\exists a \\in A$ such that $f(a) = b$. But all we have to make sure\n      in our example is that whatever $g(b) = c$ maps to, $\\exists a' \\neq a \\in\n      A$ such that $(g \\circ f)(a') = c$.\n\n      \\item \\AFSOC $g$ is not surjective. Then $\\exists c \\in C$ such that\n      $\\not\\exists b \\in B$ such that $g(b) = c$. If this is the case, then\n      $\\not\\exists a \\in A$ such that $(g \\circ f)(a) = c$, which means $g \\circ\n      f$ is not surjective. This is a contradiction, therefore $g$ must be\n      surjective.\n    \\end{itemize}\n\n    \\item Summary should be pretty clear :) from the results above.\n  }\n}\n\n\\bx{\n  \\item Alright let's consider the two cases in this problem\n  \\begin{itemize}\n    \\item $f$ has a left inverse, i.e. $\\exists g, g \\circ f = i_A$.\n\n    \\AFSOC $f$ is not injective. This means that $f(a) = f(a') = b \\in B$ but $a \\neq a' \\in A$.\n\n    If this is the case, then $g(b) = a$ or $g(b) = a'$, but cannot be both, by the definition of a function, which means that $g \\circ f$ is not $i_A$ by counterexample of either $a$ or $a'$.\n\n    \\item $f$ has a right inverse, i.e. $\\exists h, f \\circ h = i_B$.\n\n    \\AFSOC $f$ is not surjective. Then $\\exists b \\in B$ such that $\\not\\exists a \\in A$ such that $f(a) = b$. If this is the case, then for this $b$, $(f \\circ h)(b) \\neq b$, in which case $f \\circ h \\neq i_B$.\n  \\end{itemize}\n\n  \\label{chap1:p5:part:a}\n\n  \\item The proofs above in \\ref{chap1:p5:part:a} are by contradiction, and illustrate how to construct such a counterexample.\n  \\item The proofs above in \\ref{chap1:p5:part:a} are by contradiction, and illustrate how to construct such a counterexample.\n  \\item No, these left/right inverses are unique. Not rigorous, but if you have an identity mapping and you change any of the mappings, it will no longer be an identity mapping.\n  \\item So we have $f$ that has both a left and right inverse, $g, h$\n  respectively.In that case, we know that $f$ is injective and surjective, by\n  the results of \\ref{chap1:p5:part:a}, so we can conclude that $f$ is\n  bijective. We have $g = h = f^{-1}$ by Lemma 2.1 in the text.\n\n  (We could've just used Lemma 2.1 directly, but I think it's important to\n  remind ourselves that showing a function is injective and surjective is a\n  problem solving technique for showing a function is bijective.)\n}\n\n\\bx{\n  Let us draw out our function first,\n\n  \\begin{figure}[H]\n    \\centering\n    \\def\\domainSize{2}\n    \\begin{tikzpicture}\n      \\begin{axis}[\n        axis y line = middle,\n        axis x line = middle,\n      ]\n\n      \\addplot[\n        domain=-\\domainSize:\\domainSize,\n        samples=100\n      ]{\n        x^3 - x\n      };\n\n      \\end{axis}\n    \\end{tikzpicture}\n    \\caption{Plotting $f(x) = x^3 - x$}\n    \\label{chap1:sec2:p6:fig:1}\n  \\end{figure}\n\n  A less formal way to imagine injective functions is to use the horizontal line\n  test. If you sweep a horizontal line and it intersects the plot in more than 1\n  spot, then you know the function is not injective. We see our function $f(x)$\n  here has issues between $[-1, 1]$.\n\n  For surjectivity, we just need to map all of $\\mathbb{R}$ on the $y$-axis. Our\n  function does this nicely already, so we just have to make our function\n  injective, and then make sure to keep the surjectivity.\n\n  We have two choices here, we can either restrict our domain to be\n  \\begin{itemize}\n    \\item $D = (-\\infty, -1) \\cup [-1, \\infty)$\n    \\item $D = (-\\infty, -1] \\cup (-1, \\infty)$\n  \\end{itemize}\n\n  If we use the first choice, we will get the following plot as $g$:\n  \\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}\n      \\begin{axis}[\n        axis y line = middle,\n        axis x line = middle,\n      ]\n\n      \\addplot[\n        domain=-2:-1,\n        samples=100\n      ]{\n        x^3 - x\n      };\n\n      \\addplot[\n        domain=1:2,\n        samples=100\n      ]{\n        x^3 - x\n      };\n\n      \\addplot[only marks, mark=o] table[row sep=crcr] {\n        x y\\\\\n        -1 0\\\\\n      };\n\n      \\addplot[only marks] table[row sep=crcr] {\n        x 0\\\\\n        1 0\\\\\n      };\n      \\end{axis}\n    \\end{tikzpicture}\n    \\caption{Plotting $g(x)$, a bijective function. Open circles are exclusive, closed circles are inclusive.}\n    \\label{chap1:sec2:p6:fig:2}\n  \\end{figure}\n\n  To find $g^{-1}$, a classic algebra way to do this is to solve the function in\n  terms of $x$. Because of the horizontal line issues from before, we will\n  encounter, some issues, but because of our domain restriction, things should\n  be ok.\n\n  Instead of solving for $x$, since we already have a plot, we can just do a\n  reflection across $y=x$, and we will get the inverse function $g^{-1}$. The\n  intuitive way to think about this is that we are essentially swapping all $(x,\n  y)$ coordinates to become $(y, x)$.\n\n  \\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}\n      \\begin{axis}[\n        axis y line = middle,\n        axis x line = middle,\n      ]\n\n      \\addplot[domain=-2:-1] (x^3 - x, x);\n\n      \\addplot[domain=1:2] (x^3 - x, x);\n\n      \\addplot[only marks, mark=o] table[row sep=crcr] {\n        x y\\\\\n        0 -1\\\\\n      };\n\n      \\addplot[only marks] table[row sep=crcr] {\n        x y\\\\\n        0 1\\\\\n      };\n      \\end{axis}\n    \\end{tikzpicture}\n    \\caption{Plotting $g(x)$, a bijective function. Open circles are exclusive, closed circles are inclusive.}\n    \\label{chap1:sec2:p6:fig:3}\n  \\end{figure}\n}", "meta": {"hexsha": "c9244f279959323cb0e9ccc628ad710ddfa99445", "size": 12402, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter1/chapter1-2.tex", "max_stars_repo_name": "mikinty/Topology-Munkres-Solutions", "max_stars_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2021-07-02T05:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T04:11:03.000Z", "max_issues_repo_path": "chapters/chapter1/chapter1-2.tex", "max_issues_repo_name": "mikinty/Topology-Munkres-Solutions", "max_issues_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter1/chapter1-2.tex", "max_forks_repo_name": "mikinty/Topology-Munkres-Solutions", "max_forks_repo_head_hexsha": "0151a189acb30089e25db1f587300bc530c76273", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.1331444759, "max_line_length": 211, "alphanum_fraction": 0.5861957749, "num_tokens": 4533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540518, "lm_q2_score": 0.8840392802184581, "lm_q1q2_score": 0.7033930226469509}}
{"text": "\\documentclass{memoir}\n\\usepackage{notestemplate}\n\n\\begin{document}\n\\section{Sums of Subspaces}\nLet $(V,F,+,\\cdot )$ be a vector space, and let $U_1,\\ldots,U_m$ be subspaces. Define \n\\begin{align*}\n\tU_1 +\\ldots+U_m := \\left\\{ u_1+\\ldots+u_m \\mid u_i \\in U_i \\text{ for } i=1,\\ldots,m \\right\\}\n\\end{align*}\nto be the sum of two subspaces.\n\n\\begin{exmp}\nLet $V = \\R^{3}$, $F=\\R$ and consider\n\\begin{align*}\n\tU_1 = \\left\\{ (x,0,0) \\mid x\\in \\R \\right\\} \\in \\R^{3}\\\\\n\tU_2 = \\left\\{ (0,y,0) \\mid y \\in \\R \\right\\} \\in \\R^{3}\n\\end{align*}. Then\n\\begin{align*}\n\tU_1 + U_2 = \\left\\{ (x,y,0) \\mid x,y\\in \\R \\right\\} .\n\\end{align*}\n\\end{exmp}\n\n\\begin{thm}[Sum of subspaces]\n\tIf $U_1,\\ldots,U_m \\subseteq V$ are subspaces of $(V,F,+,\\cdot )$, then $U_1+\\ldots+U_m$ is the \"smallest\" subspace of $V$ that contains $U_1,\\ldots,U_m$. That is, if there exists \\(U'\\subset V\\) such that \\(U_1,\\ldots,U_m\\subset U'\\), then \\(U_1+\\ldots+U_m \\subset U'\\).\n\\end{thm}\n\\begin{proof}\n\tFirst we show that $U_1 + \\ldots + U_m$ is a subspace of $V$. It is easy to see that $\\overline{0} = \\overline{0}+\\ldots+\\overline{0}$ and so the zero vector is in our space. We also know that\n\t\\begin{align*}\n\t\t(u_1+\\ldots+u_m) + (v_1+\\ldots+v_m) = (u_1+v_1)+(u_2+v_2)+\\ldots+(u_m+v_m) \\in U_1+\\ldots+U_m\n\t\\end{align*}\n\tFinally, \n\n\t\\begin{align*}\n\t\t\\lambda \\cdot (u_1+\\ldots+u_m) = \\lambda \\cdot u_1 + \\ldots + \\lambda \\cdot u_m \\in U_1 + \\ldots+U_m.\n\t\\end{align*}\n\twhich gives us that \\(U_1+\\ldots+U_m\\) is a subspace of \\(V\\) as desired.\\\\\n\n\tNow we show that $U_i \\subseteq U_1 + \\ldots + U_m$. Let $u_i \\in U_i.$ Then \n\t\\begin{align*}\n\t\tu_2 = \\overline{0} + \\ldots + \\overline{0} + u_i + \\overline{0} + \\ldots + \\overline{0} \\implies u_i \\in U_1 + \\ldots + U_m\n\t\\end{align*}\n\tas desired.\n\nFinally, we want to show the statement. Let $U' \\subseteq V$ be a subspace with $U_1,\\ldots,U_m \\subseteq U'$, and let $u_1+\\ldots+u_m \\in U_1+\\ldots+U_m$. Our work above gives us that $u_i \\in U_i$. Because we have \\(U_i \\subset U'\\), that implies that each \\(u_i \\in U'\\), and so\n\\begin{align*}\n\tu_1 + \\ldots+ u_m \\in U'\n\\end{align*}\nas desired.\n\\end{proof}\n\n\t\\section{Direct sums}\n\t\\begin{defn}[Direct sum]\n\t\tLet $U_1,\\ldots,U_m$ be subspace of $(V,F,+,\\cdot )$. If each $v \\in U_1 + \\ldots +U_m$ can be written in \\textit{exactly} one way as\n\\begin{align*}\n\tv = u_1 + \\ldots +u_m \\quad u_i \\in  U_i\n\\end{align*}\n\t\t then we say $U_1 + \\ldots + U_m$ is a \\textbf{direct sum}, and denote it by\n\t\t\\begin{align*}\n\t\tU_1 \\oplus U_2 \\oplus \\ldots \\oplus U_m .\n\t\t\\end{align*}\n\t\\end{defn}\n\t\\begin{exmp}\n\tLet $V = \\R^{3}$, $F = \\R$, and consider $U_1 = \\left\\{ (x,y,0) \\mid x,y \\in R \\right\\} $ and $U_2 = \\left\\{ (0,0,z) | z \\in \\R \\right\\} $. Then $U_1 \\bigoplus U_2$ is direct.\\\\\n\n\tBut consider $U_3 = \\left\\{ (0,y,y) \\mid y \\in \\R \\right\\} $. Then $U_1 + U_2 + U_3$ is NOT direct. \n\\end{exmp}\n\\begin{lemma}[Criterion for direct sums]\n\t$U_1 \\oplus \\ldots \\oplus U_m \\iff \\left[ u_1 + \\ldots + u_m = 0 \\implies u_1,\\ldots,u_m=0\\right]$ where $u_i \\in U_i$.\n\\end{lemma}\n\t\\begin{proof}\n\tFirst we will prove the forward direction. Observe that $\\overline{0} = \\overline{0} + \\ldots + \\overline{0}$. Because it is a direct sum, it is the only way to write the zero vector, and so each $u_i \\in U_i$ must be $\\overline{0}$. \\\\ \n\n\tFor the reverse direction, suppose that the only way to write $\\overline{0} = u_1 + \\ldots + u_m$ is to take $u_i = \\overline{0}$ . \\\\ Let $v \\in U_1 + \\ldots + U_m$. Suppose that\n\t\\begin{align*}\n\tv = u_1+\\ldots+u_m \\quad u_i \\in U_i \\\\\n\tv = u'_1+\\ldots+u'_m \\quad u'_i \\in U_i\n\t\\end{align*}\n\tSubtraction yields $\\overline{0}=(u_1 - u'_1) + \\ldots + (u_m - u'_m)$. By hypothesis, each parentheses must be zero, and so \\(u_i = u'_i\\) and hence the representation of \\(v\\) is unique.\n\\end{proof}\n\n\\begin{lemma}[Direct sum of two subspaces]\nLet $U,W \\subseteq V$ be two subspaces. Then\n\\begin{align*}\n\tU\\oplus W \\iff U\\cap W = \\left\\{ \\vec{0} \\right\\} . \n\\end{align*}\n\\end{lemma}\n\n\\end{document}\n", "meta": {"hexsha": "f7d10847f6dd87dcf986a3b2262c869fdb5bded5", "size": 3967, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear Algebra/Notes/source/09-06-19-DirectSums.tex", "max_stars_repo_name": "gjgress/Libera-Mentis", "max_stars_repo_head_hexsha": "d9f1bfd9e6ea62a9d56292f7890f99c450b54c9b", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-07-16T23:18:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-16T23:18:15.000Z", "max_issues_repo_path": "Linear Algebra/Notes/source/09-06-19-DirectSums.tex", "max_issues_repo_name": "gjgress/Libera-Mentis", "max_issues_repo_head_hexsha": "d9f1bfd9e6ea62a9d56292f7890f99c450b54c9b", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2021-05-20T22:09:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-20T23:23:22.000Z", "max_forks_repo_path": "Linear Algebra/Notes/source/09-06-19-DirectSums.tex", "max_forks_repo_name": "gjgress/LibreMath", "max_forks_repo_head_hexsha": "d9f1bfd9e6ea62a9d56292f7890f99c450b54c9b", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.5730337079, "max_line_length": 281, "alphanum_fraction": 0.6349886564, "num_tokens": 1651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540518, "lm_q2_score": 0.8840392756357327, "lm_q1q2_score": 0.7033930190006683}}
{"text": "\\subsection{The type of interaction that the OSLR algorithm can and cannot model, and how to improve it for the latter situation.}\n    The algorithm can model linear data interactions. However, it would not perform well with data that display non-linearity, for example, a quadratic distribution of data. In this case, the model could work better by transforming the variables to square-root to get a linear relationship. Yo\n    \n    \\subsection{Assumptions and Derivation of Analytical Solution}\n    \\textbf{Assumptions:}\n    \\begin{enumerate}\n    \\item expected residual error value is zero. $\\forall : E(\\varepsilon_i) = 0$\n    \\item zero correlation and equal variance of residuals. $\\forall : Var(\\varepsilon_i) = \\sigma^2$\n   \\item the residuals are normally distributed. $\\varepsilon_i \\sim N(0,\\sigma^2)$\n   \\end{enumerate}\n   \\textbf {Derivation:}\\\\\n    Consider the augmented vector notation:\n    \\begin{equation*}\n        y = Xw + \\epsilon\n    \\end{equation*}\n    To minimize the sum of squared residual errors,\n    \\newcommand{\\argmin}{\\mathop{\\mathrm{argmin}}}\n    \\begin{equation*}\n        \\argmin_w ||\\varepsilon||^2 = \\argmin_w ||y - Xw||^2\n    \\end{equation*}\n    Here,\n    \\begin{align*}\n        \\argmin_w ||y - Xw||^2 &= (y-Xw)^T (y-Xw)\\\\\n        &= y^Ty - (Xw)^Ty - y^TXw + (Xw)^TXw\\\\\n        &= y^Ty - w^TX^Ty - y^TXw + w^TX^TXw\\\\\n        \\intertext{Since $w^TX^Ty$ is scalar, so $w^TX^Ty = (w^TX^Ty)^T = y^TXw$. Therefore,} \n        &= y^Ty - 2y^TXw + w^TX^TXw\\\\\n        \\intertext{applying partial derivatives with respect to $w$ and equating it to 0}\n        \\frac{\\partial}{\\partial w} (y^Ty - 2y^TXw + w^TX^TXw)   &= 0\\\\\n        - 2y^TX + w^T(X^TX + (X^TX)^T) &= 0\\\\\n        - 2y^TX + 2w^TX^TX &= 0\\\\\n         \\intertext{dividing by 2,}\n        - y^TX + w^TX^TX &= 0\\\\\n        \\intertext{adding $y^TX$ on both sides,}\n        w^TX^TX &= y^TX\\\\\n        X^TXw &= X^Ty\\\\\n        \\intertext{multiplying by inverse of $X^TX$,}\n        w &= (X^TX)^{-1}X^Ty\n    \\end{align*}\n    \\subsection{Situation when squared error loss function would not perform well and alternative loss functions.}\n    This method is highly sensitive to outliers, since squares of the residual errors of outliers would be large, which would significantly influence the decision. Thus, it would not perform well on noisy data. Some alternative loss functions that could be used include the absolute loss (L1) function and Huber loss function.  BLAH BLAH\n", "meta": {"hexsha": "d1a64d0f6265588b554e3a456989fa3e1a7168b1", "size": 2447, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ml-ex2.tex", "max_stars_repo_name": "Ayesha9916/Workshop-website-trial-", "max_stars_repo_head_hexsha": "707f73f608a00f5a2c5784ad9bbc78effa0812e7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ml-ex2.tex", "max_issues_repo_name": "Ayesha9916/Workshop-website-trial-", "max_issues_repo_head_hexsha": "707f73f608a00f5a2c5784ad9bbc78effa0812e7", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ml-ex2.tex", "max_forks_repo_name": "Ayesha9916/Workshop-website-trial-", "max_forks_repo_head_hexsha": "707f73f608a00f5a2c5784ad9bbc78effa0812e7", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.2619047619, "max_line_length": 337, "alphanum_fraction": 0.6481405803, "num_tokens": 761, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581049086031, "lm_q2_score": 0.8840392756357327, "lm_q1q2_score": 0.7033930147171014}}
{"text": "%------------------------------------------------\n% FILENAME: assignment_0_key.tex\n%  PROJECT: mathbootcamp\n%   AUTHOR: Brett R. Devine\n%    EMAIL: brett.devine@wsu.edu\n%  WEBSITE: http://brettdevine.github.io\n%------------------------------------------------\n\\documentclass[a4paper, 11pt]{article}\n\\usepackage{assignment_0_style}\n\n\\title{ Assignment 0 Key }\n\\author{ Brett Devine }\n\\date{ Jun 19, 2016 }\n\n\\begin{document}\n\\maketitle\n\n\\section{Limits}\n\\label{sec:limits}\n\n\\paragraph{Problem 1} Compute\n\\begin{align}\n    \\lim_{x\\rightarrow 3} \\frac{5x^2 - 8x -13}{x^2-5}  \\nonumber\n\\end{align}\n\n%------------------------------------------------\n%   BEGIN Problem 1 Answer\n%------------------------------------------------\n\\paragraph{Problem 1 Answer}\n\\begin{align}\n    \\lim_{x\\rightarrow 3} \\frac{5x^2-8x-13}{x^2-5} &= \\frac{5(3)^2-8(3)-13}{(3)^2-5} \\nonumber \\\\\n    &= \\frac{8}{2} = 2 \\nonumber \n\\end{align}\n\n%------------------------------------------------\n%   END Problem 1 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 2} Compute\n\\begin{align}\n    \\lim_{x\\rightarrow 3} \\frac{x^4 - 81}{2x^2-5x-3}  \\nonumber\n\\end{align}\n\n%------------------------------------------------\n%   BEGIN Problem 2 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 2 Answer}\nSubstitution of 3 into the expression will result in the indeterminate form $0/0$ so factor out the expressions causing the indeterminate form\n\\begin{align}\n    \\lim_{x\\rightarrow 3} \\frac{x^4 - 81}{2x^2-5x-3} &= \\lim_{x\\rightarrow 3} \\frac{(x^2-9)(x^2+9)}{(x-3)(2x+1)} \\nonumber \\\\\n    &= \\lim_{x\\rightarrow 3} \\frac{(x-3)(x+3)(x^2+9)}{(x-3)(2x+1)} \\nonumber \\\\\n    &= \\lim_{x\\rightarrow 3} \\frac{(x+3)(x^2+9)}{(2x+1)} \\nonumber \\\\\n    &= \\frac{((3) + 3)((3)^2 + 9)}{2(3) + 1} \\nonumber \\\\\n    &= \\frac{108}{7} \\nonumber   \n\\end{align}\n\n%------------------------------------------------\n%   END Problem 2 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 3}\nCompute\n\\begin{align}\n    \\lim_{x\\rightarrow 4} \\frac{3-\\sqrt{x+5}}{x-4}  \\nonumber\n\\end{align}\n\n%------------------------------------------------\n%   BEGIN Problem 3 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 3 Answer}\n\\begin{align}\n    &= \\lim_{x\\rightarrow 4} \\frac{3-\\sqrt{x+5}}{x-4} \\cdot \\frac{3+\\sqrt{x+5}}{3 + \\sqrt{x+5}}  \\nonumber \\\\\n    &= \\lim_{x\\rightarrow 4} \\frac{9-(x+5)}{(x-4)(3+\\sqrt{x+5})} \\nonumber \\\\\n    &= \\lim_{x\\rightarrow 4} \\frac{4-x}{(x-4)(3 + \\sqrt{x + 5}} \\nonumber \\\\\n    &= \\lim_{x\\rightarrow 4} \\frac{-(x-4)}{(x-4)(3 + \\sqrt{x + 5})} \\nonumber \\\\\n    &= \\lim_{x\\rightarrow 4} \\frac{-1}{3 + \\sqrt{x+5}} \\nonumber \\\\\n    &= \\frac{-1}{3 + \\sqrt{4 + 5}} \\nonumber \\\\\n    &= -\\frac{1}{6} \\nonumber \n\\end{align}\n\n%------------------------------------------------\n%   END Problem 3 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 4}\nConsider the values of constants $a$ and $b$ so that $\\lim_{x \\rightarrow 2} f(x)$ exists and is equal to $f(2)$ where $f(x)$ is defined as below.\n\\begin{align}\n    f(x) = \\begin{cases}\n    \t\t\ta + bx & \\text{ if } x > 2 \\\\\n    \t\t\t3 & \\text{ if } x=2 \\\\\n    \t\t\tb-ax^2 & \\text{ if } x < 2\n    \t   \\end{cases}  \\nonumber\n\\end{align}\n\n%------------------------------------------------\n%   BEGIN Problem 4 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 4 Answer}\n\\begin{align}\n    \\lim_{x\\rightarrow 2+} f(x) = \\lim_{x\\rightarrow 2+} (a+bx) &= a + 2b = 3  \\nonumber \\\\\n    \\lim_{x\\rightarrow 2-} f(x) = \\lim_{x\\rightarrow 2-} (b-ax^2) &= b - 4a = 3 \\nonumber\n\\end{align}\nThe above expressions give us a system of equations\n\\begin{align}\n    a + 2b &= 3  \\nonumber \\\\\n    b-4a &= 3 \\nonumber \n\\end{align}\nSolving the system of 2 equations in 2 unknowns gives us $a = -\\frac{1}{3}$ and $b = \\frac{5}{3}$.\n\n%------------------------------------------------\n%   END Problem 4 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 5}\nCompute the following limit.\n\\begin{align}\n    \\lim_{x\\rightarrow \\infty} \\frac{100}{x^2 + 5}  \\nonumber\n\\end{align}\n\n%------------------------------------------------\n%   BEGIN Problem 5 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 5 Answer}\n\\begin{align}\n    \\lim_{x\\rightarrow \\infty} \\frac{100}{x^2 + 5} = \\frac{100}{\\infty} = 0  \\nonumber\n\\end{align}\n\n%------------------------------------------------\n%   END Problem 5 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 6}\nCompute\n\\begin{align}\n    \\lim_{x\\rightarrow \\infty} (3x^3 - 1000x^2)  \\nonumber\n\\end{align}\n\n%------------------------------------------------\n%   BEGIN Problem 6 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 6 Answer}\nSubstitution yields an indeterminate form ``$\\infty - \\infty$'' which we circumvent by factoring.\n\\begin{align}\n    &= \\lim_{x\\rightarrow 3} x^2(3x - 1000)  \\nonumber \\\\\n    &= \\infty \\cdot \\infty \\nonumber\n\\end{align}\nwhich means that the limit does not exist.\n\n%------------------------------------------------\n%   END Problem 6 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 7}\nCompute\n\\begin{align}\n    \\lim_{x\\rightarrow \\infty} \\frac{7x^2 + x - 100}{2x^2 - 5x}  \\nonumber\n\\end{align}\n\n%------------------------------------------------\n%   BEGIN Problem 7 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 7 Answer}\n\\begin{align}\n    &= \\lim_{x\\rightarrow \\infty} \\frac{7x^2 + x - 100}{2x^2 - 5x} \\cdot \\frac{\\frac{1}{x^2}}{\\frac{1}{x^2}} \\nonumber \\\\\n    &= \\lim_{x\\rightarrow \\infty} \\frac{\\frac{7x^2}{x^2} + \\frac{x}{x^2} - \\frac{100}{x^2}}{ \\frac{2x^2}{x^2} - \\frac{5x}{x^2} } \\nonumber \\\\\n    &= \\lim_{x\\rightarrow \\infty} \\frac{ 7 + \\frac{1}{x} - \\frac{100}{x^2} }{ 2 - \\frac{5}{x} } \\nonumber \\\\\n    &= \\frac{7 + 0 - 0}{2 - 0} \\nonumber \\\\\n    &= \\frac{7}{2} \\nonumber \n\\end{align}\n\n%------------------------------------------------\n%   END Problem 7 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 8}\nCompute\n\\begin{align}\n    \\lim_{x\\rightarrow \\infty} \\left( 3^x + 3^{2x} \\right)^{\\frac{1}{x}}  \\nonumber\n\\end{align}\n\n%------------------------------------------------\n%   BEGIN Problem 8 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 8 Answer}\n\\begin{align}\n    &= \\lim_{x\\rightarrow \\infty} \\left( 3^x + \\left[3^2\\right]^x \\right)^{\\frac{1}{x}}  \\nonumber \\\\\n    &= \\lim_{x\\rightarrow \\infty} \\left( 3^x + 9^x \\right)^{\\frac{1}{x}} \\nonumber \\\\\n    &= \\lim_{x\\rightarrow \\infty} \\left( 9^x \\left[ \\frac{3^x}{9^x} + \\frac{9^x}{9^x} \\right] \\right)^{\\frac{1}{x}} \\nonumber \\\\\n    &= \\lim_{x\\rightarrow \\infty} \\left( 9^x \\left[ \\left(\\frac{3}{9}\\right)^x + 1 \\right] \\right)^{\\frac{1}{x}} \\nonumber \\\\\n    &= \\lim_{x\\rightarrow \\infty} \\left( 9^x \\left[ \\left(\\frac{1}{3}\\right) + 1 \\right] \\right)^{\\frac{1}{x}} \\nonumber \\\\\n    &= \\lim_{x\\rightarrow \\infty} \\left(9^x \\right)^{\\frac{1}{x}} \\cdot \\left[ \\left(\\frac{1}{3}\\right)^x + 1 \\right]^{\\frac{1}{x}} \\nonumber \\\\\n    &= \\lim_{x\\rightarrow \\infty} 9 \\left[ \\left(\\frac{1}{3}\\right)^x + 1 \\right]^{\\frac{1}{x}} \\nonumber \\\\\n    &= (9)[0 + 1]^0 \\nonumber \\\\\n    &= 9 \\nonumber \n\\end{align}\n\n%------------------------------------------------\n%   END Problem 8 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 9}\nCompute $\\lim_{x\\rightarrow 0^+} \\; x \\cdot \\ln x$.\n\n%------------------------------------------------\n%   BEGIN Problem 9 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 9 Answer}\n\\begin{align}\n    &= \\lim_{x\\rightarrow 0^+} \\frac{\\ln x}{1/x} \\nonumber \\\\\n    &= \\frac{\\ln 0}{1/0^+} \\nonumber\n\\end{align}\nwhich leads to the indeterminate form $-\\infty / \\infty$ so use l'Hopital's Rule.\n\\begin{align}\n    &= \\lim_{x\\rightarrow 0^+} \\frac{1/x}{-1/x^2}  \\nonumber \\\\\n    &= \\lim_{x\\rightarrow 0^+} \\frac{1}{x} \\cdot \\frac{x^2}{-1} \\nonumber \\\\\n    &= \\lim_{x\\rightarrow 0^+} (-x) \\nonumber \\\\\n    &= 0 \\nonumber \n\\end{align}\n%------------------------------------------------\n%   END Problem 9 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 10}\nCompute $\\lim_{x \\rightarrow 0^+} x \\cdot \\left( \\ln x \\right)^2$.\n\n%------------------------------------------------\n%   BEGIN Problem 10 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 10 Answer}\n\\begin{align}\n    &= \\lim_{x\\rightarrow 0^+} \\frac{\\left(\\ln x\\right)^2}{1/x} = \\frac{\\infty}{\\infty}  \\nonumber\n\\end{align}\nUse l'Hopital's Rule\n\\begin{align}\n    &= \\lim_{x\\rightarrow 0^+} \\frac{2\\ln x \\cdot (1/x)}{\\frac{-1}{x^2}} = \\frac{\\infty}{\\infty}  \\nonumber\n\\end{align}\nSo use l'Hopital's Rule again\n\\begin{align}\n    &= \\lim_{x\\rightarrow 0^+} \\frac{2 \\cdot 1/x}{\\frac{1}{x^2}}  \\nonumber \\\\\n    &= \\lim_{x\\rightarrow 0^+} 2x \\nonumber \\\\\n    &= 2 \\cdot 0 \\nonumber \\\\\n    &= 0 \\nonumber \n\\end{align}\n\n%------------------------------------------------\n%   END Problem 10 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 11}\nCompute $\\lim_{x \\rightarrow 0 } (1-x)^{1/x}$.\n\n%------------------------------------------------\n%   BEGIN Problem 11 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 11 Answer}\nRewrite problem\n\\begin{align}\n    \\lim_{x\\rightarrow 0} (1-x)^{1/x} &= \\lim_{x\\rightarrow 0} e^{\\ln(1-x)^{1/x}}  \\nonumber \\\\\n    &= \\lim_{x\\rightarrow 0} e^{(1/x)\\cdot \\ln(1-x)} \\nonumber \\\\\n    &= e^{\\lim_{x\\rightarrow 0} \\frac{\\ln(1-x)}{x} } \\nonumber \\\\\n    &= e^{(\\ln 1)/0} = e^{0/0} \\nonumber\n\\end{align}\nUse l'Hopital's rule for the indeterminate form\n\\begin{align}\n    &= e^{\\lim_{x\\rightarrow 0} \\frac{\\frac{1}{1-x} \\cdot (-1)}{1} }  \\nonumber \\\\\n    &= e^{-1/(1-0)} \\nonumber \\\\\n    &= e^{-1} \\nonumber \\\\\n    &= \\frac{1}{e} \\nonumber \n\\end{align}\n%------------------------------------------------\n%   END Problem 11 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 12}\nConsider the following functions for $w \\geq 0$ and $0 < \\sigma < 1$.\n\\begin{align}\n    u(w) &= \\frac{w^{1-\\sigma}-1}{1-\\sigma}  \\nonumber \\\\\n    u(w) &= \\ln(w) \\nonumber \\nonumber \\\\\n    u(w) &= \\sqrt{w} \\nonumber \n\\end{align}\nFor each function above, find the following limits (if they exist) where $u'(\\cdot)$ and $u''(\\cdot)$ represent the first and second derivatives respectively.\n\\begin{enumerate}[(i)]\n\t\\item $\\lim_{w\\rightarrow 0} \\; -u''(w)/u'(w)$.\n\t\\item $\\lim_{w\\rightarrow \\infty} \\; -u''(w)/u'(w)$.\n\t\\item $\\lim_{w\\rightarrow 0} \\; (-u''(w)\\cdot w)/u'(w)$.\n\t\\item $\\lim_{w\\rightarrow \\infty} \\; (-u''(w)\\cdot w)/u'(w)$.\n\\end{enumerate}\n\n\n\\paragraph{Problem 13} Differentiate $y = x^x$ (with respect to $x$).\n\n%------------------------------------------------\n%   BEGIN Problem 13 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 13 Answer}\n$x^{x} (1 + \\ln x)$.\n\n%------------------------------------------------\n%   END Problem 13 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 14} Differentiate $y = x^{e^x}$ (with respect to $x$).\n\n%------------------------------------------------\n%   BEGIN Problem 14 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 14 Answer} $x^{e^x-1} e^{x} (1 + x \\ln x)$\n\n%------------------------------------------------\n%   END Problem 14 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 15} Compute the following limits associated with the functions $f(x) = |x|$.\n\\begin{align}\n    &\\lim_{h\\rightarrow 0} \\frac{f(-2 + h) - f(-2)}{h}  \\nonumber \\\\\n    &\\lim_{h\\rightarrow 0} \\frac{f(0 + h) - f(0)}{h} \\nonumber \\\\\n    &\\lim_{h\\rightarrow 0} \\frac{f(3 + h) + f(3)}{h} \\nonumber\n\\end{align}\n\n\\paragraph{Problem 16}\nDefine the intervals (if any) over which the following function is continuous.\n\\[\n\tf(x) = \\frac{7x^5 + x - 2}{x^2-4}\n\\]\n\n%------------------------------------------------\n%   BEGIN Problem 16 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 16 Answer} \\; $(-\\infty, -2) \\cup (-2,2) \\cup (2, \\infty)$.\n\n%------------------------------------------------\n%   END Problem 16 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 17}\nShow that there is a root of the equation $3x^7 - 2x^5 + x -1 = 0$ between $0$ and $1$.\n\n%------------------------------------------------\n%   BEGIN Problem 17 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 17 Answer}\nWe see that $f(0) = -1 < 0$ and $f(1) = 3 - 2 + 1 - 1 = 1 > 0$.\nBy the Intermediate Value Theorem it follows that there exists a number $c$ in $(0,1)$ such that $f(c)=0$ since $f(x)$ is continuous and 0 is between $f(0)$ and $f(1)$.\n\n%------------------------------------------------\n%   END Problem 17 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 18}\nCompute the following limit associated with $f(x) = x^2 - 8x + 9$.\n\\[\n\t\\lim_{x\\rightarrow a} \\; \\frac{(x^2-8x+9)-(a^2-8a+9)}{x-a}\n\\]\n\n%------------------------------------------------\n%   BEGIN Problem 18 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 18 Answer}\n\\; $2a - 8$.\n\n%------------------------------------------------\n%   END Problem 18 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 19}\nIf the function $f(x)$ is differentiable in the interval $(a,b)$ and $|f'(x)| \\leq B < \\infty$ for all $x$ in the interval $(a,b)$ then is the maximum change in the function over any sub interval $(c,d) \\subseteq (a,b)$ finite or infinite? Prove it.\n\n\\paragraph{Problem 20}\nIf the function $f(x)$ is differentiable on $(a,b)$, but not continuously differentiable, then is $f$ continuous everywhere on $(a,b)$? Prove it.\n\n\\paragraph{Problem 21}\nCan you differentiate the expression $2x = 1$? If so what is the derivative?  If not, why not?\n\n\\paragraph{Problem 22} Find the derivative of the function\n\\[\n\tf(x) = \\frac{\\sqrt[4]{x}}{x^{-1} \\sqrt{x^5}}\n\\]\n\n%------------------------------------------------\n%   BEGIN Problem 22 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 22 Answer}\n\\[\n\tf'(x) = - \\frac{5}{4x^2 \\sqrt[4]{x} }\n\\]\n\n%------------------------------------------------\n%   END Problem 22 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 23} Differentiate the function\n\\[\n\tf(x) = \\frac{3x^2 - 5\\sqrt{x} }{ 6x^4 }\n\\]\n\n%------------------------------------------------\n%   BEGIN Problem 23 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 23 Answer}\n\\[\n\tf'(x) = -x^{-3} + \\frac{35}{12} x^{-9/2}\n\\]\n\n%------------------------------------------------\n%   END Problem 23 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 24}\nFind the linearization of the function $f(x) = \\sqrt[3]{1+x}$ at $a=0$ and use it to approximate the numbers $f(-0.05)$ and $f(0.1)$.\nAre these approximations overestimates or underestimates?\n\n%------------------------------------------------\n%   BEGIN Problem 24 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 24 Answer}\n\\begin{align}\n    L(x) &= f(0) + f'(0)(x-0) = 1 + \\frac{x}{3}  \\nonumber \\\\\n    L(-0.05) &= 0.9833 \\approx 0.98305 \\quad \\text{over estimate} \\nonumber \\\\\n    L(0.1) &= 1.0333 \\approx 1.0323 \\quad \\text{over estimate} \\nonumber\n\\end{align}\n\n%------------------------------------------------\n%   END Problem 24 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 25}\nLet $f(x) = (3x-5)/(4-2x)$ and find $f^{-1}(x)$.  Then compare $f'(x)$ and $\\frac{d}{dx} f^{-1}(x)$ and describe the relationship (if any).\n\n%------------------------------------------------\n%   BEGIN Problem 25 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 25 Answer}\nThe inverse function is\n\\[\n\tf^{-1}(x) = \\frac{4x+5}{3+2x}\n\\]\n\n%------------------------------------------------\n%   END Problem 25 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 26}\nCompute the derivative of the following function, $H(p)$, with respect to $p$ and use it to show the answer to the following questions.\n\\begin{align}\n    H(p) &= p \\log_2 \\left(\\frac{1}{p} \\right) + (1-p)\\log_2 \\left(\\frac{1}{1-p} \\right)  \\nonumber\n\\end{align}\n\\begin{enumerate}[(i)]\n\t\\item Is there a global maximum and minimum over the interval $[0,1]$, if so, what is it?\n\t\\item If so, over what subset of $[0,1]$, if any, is the function increasing?\n\t\\item If so, over what subset of $[0,1]$, if any, is the function decreasing?\n\\end{enumerate}\n\n%------------------------------------------------\n%   BEGIN Problem 26 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 26 Answer}\n\\begin{enumerate}[(i)]\n\t\\item Yes, there is a global max because it is a continuous function on a compact set.  The maximum is $p^* = 0.5$.\n\t\\item The function increases over $[0,0.5]$.\n\t\\item The function decreases over $[0.5,1]$.\n\\end{enumerate}\n\n%------------------------------------------------\n%   END Problem 26 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 27}\nConsider the function $f(x) = x^4 e^x$ with domain all real numbers.\n\\begin{enumerate}[(i)]\n\t\\item Find the $x$-value(s) of all roots ($x$-intercepts) of $f$.\n\t\\item Find the $x$- and $y$-value(s) of all critical points and identify each as a local max, local min, or neither.\n\t\\item Find the $x$- and $y$-value(s) of all global extrema and identify each as a global max or global min.\n\t\\item Find the $x$-value(s) of all inflection points.\n\\end{enumerate}\n\n%------------------------------------------------\n%   BEGIN Problem 27 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 27 Answer}\n\\begin{enumerate}[(i)]\n\t\\item The equation $x^4e^x=0$ means $x^4=0 \\implies x=0$ so the only root is $x=0$.\n\t\\item $f'(x) = 4x^3 e^x + x^4 e^x = 0 \\implies x = 0,-4$.  Plugging in values shows us that $f$ has a local max at $(-4, 256e^{-4})$ and a local min at $(0,0)$.\n\t\\item There is a global minimum at $(0,0)$, but there is no global maximum since $f(x)\\rightarrow \\infty$ as $x\\rightarrow \\infty$.\n\t\\item Look for solutions to $f''(x) = 0$ which yields $x=\\{0,-2,-6\\}$.  Checking the value of $f$ and $f''$ at those points tells us that the inflection points are $x=\\{-2,-6\\}$ but not $x=0$.\n\\end{enumerate}\n\n%------------------------------------------------\n%   END Problem 27 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 28}\nUse the Intermediate Value Theorem to show that $f(x) = x^3 - 2x - 1$ has a root on $[1,2]$.\n\n%------------------------------------------------\n%   BEGIN Problem 28 Answer\n%------------------------------------------------\n\nIVT: if $f$ is continuous on $[a,b]$ and $y$ is a number between $f(a)$ and $f(b)$, then there is a number $c$ between $a$ and $b$ such that $f(c)=y$.\nFor the function given above, $f(1)=-2$ and $f(2)=3$.\nSince $0$ is a number between $-2$ and $3$, the IVT says there is a number $c$ between $1$ and $2$ such that $f(c)=0$; this $c$ is the desired root.\n\n%------------------------------------------------\n%   END Problem 28 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 29}\nDoes the Extreme Value Theorem say anything about the function $f(x) = x^2$ on each of the following intervals? If so what does it say?  In either case, explain why.\n\\begin{enumerate}[(i)]\n\t\\item $[1,4]$\n\t\\item $(1,4)$\n\\end{enumerate}\n\n%------------------------------------------------\n%   BEGIN Problem 29 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 29 Answer}\n\\begin{enumerate}[(i)]\n\t\\item $f$ has a maximum and a mininum on $[1,4]$ by EVT.\n\t\\item Because $(1,4)$ is not compact, the EVT does not apply and so although there may be, the theorem doesn't say anything to us in this case.\n\\end{enumerate}\n\n%------------------------------------------------\n%   END Problem 29 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 30}\nFind the value of the constant $c$ that the Mean Value Theorem specifies for $f(x)=x^3 + x$ on the interval $[0,3]$.\n\n%------------------------------------------------\n%   BEGIN Problem 30 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 30 Answer}\nMVT: If $f$ is continuous on $[a,b]$, then there is a number $c$ between $a$ and $b$ such that $f'(c) = (f(b)-f(a))/(b-a)$.\n\nFor the provided function we have $\\frac{f(3)-f(0)}{3-0} = \\frac{30-0}{3} = 10$.\nAnd $f'(x) = 3x^2 + 1$ so we know $f'(c) = 3c^2 + 1$.\nSolving $f'(c)=3c^2 + 1 = 10$ for $c$ yields $c = \\sqrt{3}$.\n\n%------------------------------------------------\n%   END Problem 30 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 31}\nFor the equation $x^3 + y^3 = \\ln(xy) - 1$ use implicit differentiation to find $\\dd y/ \\dd x$.\n\n%------------------------------------------------\n%   BEGIN Problem 31 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 31 Answer}\n\\begin{align}\n    \\frac{\\dd y}{\\dd x} &= \\frac{y - 3x^3 y}{3xy^3-x} = \\frac{\\frac{1}{x}-3x^2}{3y^2-\\frac{1}{y}}  \\nonumber\n\\end{align}\n\n%------------------------------------------------\n%   END Problem 31 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 32}\nConsider the function\n\\[\n\tf(x) = \\begin{cases}\n\t\t\t\tb-x^2 & \\text{ if } x < 3 \\\\\n\t\t\t\tax & \\text{ if } x \\geq 3\n\t \t   \\end{cases}\n\\]\n\\begin{enumerate}[(i)]\n\t\\item What condition(s) must be placed on the constants $a$ and $b$ in order for $f$ to be continuous on $(-\\infty, \\infty)$?\n\t\\item For what values of the constants $a$ and $b$ will $f$ be differentiable on $(-\\infty, \\infty)$?\n\\end{enumerate}\n\n%------------------------------------------------\n%   BEGIN Problem 32 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 32 Answer}\n\\begin{enumerate}[(i)]\n\t\\item The only problem area is $x=3$ so we want $\\lim_{x \\rightarrow 3^-} f(x) = \\lim_{x\\rightarrow 3^+} f(x)$.\n\tThis gives us limits $b-9$ and $3a$ so we need $3a=b-9 \\iff a = (1/3)b - 3$.\n\t\\item Diffentiate piecewise to find $f'(x)$ for $x < 3$ and $x > 3$ giving us $-2x$ and $a$ respectively.\n\tExistence will require that $\\lim_{x\\rightarrow 3^-} f'(x) = \\lim_{x\\rightarrow 3^+} f'(x) = f'(3)$.\n\tThe piecewise limits of the derivatives are $-6$ and $a$ so $a=-6$ and using the equation found before we know $3(-6) = b-9$ which implies $-18 + 9 = -9 = b$ so we have $\\{a=-6, b=-9\\}$.\n\\end{enumerate}\n\n%------------------------------------------------\n%   END Problem 32 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 33}\nConsider the function $f(x) = \\ln(x^2)$.\nFind the fourth-order Taylor polynomial for $f(x)$ centered at $x_0=1$.\n\n%------------------------------------------------\n%   BEGIN Problem 33 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 33 Answer}\n\\[\n\tP_3(x) = 2(x-1) - (x-1)^2 + \\frac{2}{3}(x-1)^3 - \\frac{1}{2}(x-1)^4\n\\]\n\n%------------------------------------------------\n%   END Problem 33 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 34}\nLet $X$ be a random variable with a probability density function (PDF) $f(x)$\n\\[\n\tf(x) = \\begin{cases}\n \t\t\t\tce^{-x/3} & \\text{ for } x > 0 \\\\\n \t\t\t\t0 & \\text{ otherwise }\n \t\t   \\end{cases}\n\\]\nRemember that a PDF has the property that $\\int_{\\infty}^{\\infty} f(x)\\dd x = 1$.\n\\begin{enumerate}[(i)]\n\t\\item Find the value of the constant $c$ that makes $f(x)$ a valid PDF.\n\t\\item Find the probability that $X \\leq 1/4$.\n\\end{enumerate}\n\n%------------------------------------------------\n%   BEGIN Problem 34 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 34 Answer}\n\\begin{enumerate}[(i)]\n\t\\item $c = - \\frac{1}{3}$.\n\t\\item $1 - e^{-1/12}$.\n\\end{enumerate}\n\n%------------------------------------------------\n%   END Problem 34 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 35}\nFind the derivative of the following function\n\\[\n\tG(x) = \\int_{1}^{\\sin{x}} t \\dd t\n\\]\n\n%------------------------------------------------\n%   BEGIN Problem 35 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 35 Answer}\n\\[\n\tG'(x) = \\sin{x} \\cdot \\cos{x}\n\\]\n\n%------------------------------------------------\n%   END Problem 35 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 36}\nFind the derivative of the following function\n\\[\n\tG(x) = \\int_{72}^{\\ln(x)} t \\dd t\n\\]\n\n%------------------------------------------------\n%   BEGIN Problem 36 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 36 Answer}\n\\[\n\tG'(x) = \\frac{\\ln x}{x}\n\\]\n\n%------------------------------------------------\n%   END Problem 36 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 37}\nSuppose that $\\sum_{n=1}^{\\infty} a_n$ represents a convergent series and that no term of the series equals zero, i.e., $a_n \\neq 0$ for all $n=1,2, \\dots$.\nProve that $\\sum_{n=1}^{\\infty} 1/a_n$ is a divergent series.\n\n%------------------------------------------------\n%   BEGIN Problem 37 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 37 Answer}\nIf $\\sum_{n=1}^{\\infty} a_n$ is a convergent series, then $a_n \\rightarrow 0$ (i.e., the terms go to zero).\nIf $a_n \\rightarrow 0$, then $|1/a_n| \\rightarrow \\infty $.\nAs the terms of $\\sum_{n=1}^{\\infty} 1/a_n$ do not go to zero, by the $n$th term test for divergence, the series diverges.\n\n%------------------------------------------------\n%   END Problem 37 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 38}\nDetermine whether the give sequence is increasing, decreasing, or not monotonic.\nIs the sequence bounded?  On the basis of what you find, does the series converge, diverge or can't be determined?\n\\[\n\ta_n = \\frac{1}{5^n}\n\\]\n\n%------------------------------------------------\n%   BEGIN Problem 38 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 38 Answer}\nThe sequence is \\textbf{decreasing} and the sequence is \\textbf{bounded} between 0 and 1 and by the monotonic sequence theorem the sequence is \\textbf{convergent}.\n\n%------------------------------------------------\n%   END Problem 38 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 39}\nDifferentiate the function $y = 3(x^2-1)^3 (x^2 + 1)^5$.\n\n%------------------------------------------------\n%   BEGIN Problem 39 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 39 Answer}\n\\[\n\ty' = 18x(x^2-1)^2 (x^2+1)^5 + 30x(x^2-1)^3 (x^2 + 1)^4\n\\]\n\n%------------------------------------------------\n%   END Problem 39 Answer\n%------------------------------------------------\n\n\\paragraph{Problem 40}\nConsider a continuously differentiable utility function $u(\\cdot)$ such that $u'>0$ and $u'' < 0$.\nUtility comes from income $I$ which takes on two different values $I_H(x)$ and $I_L(x)$ and that the probability of that $I=I_H$ is given by $p(x)$ where $x\\geq 0$ and $p'(x)>0$.\nDifferentiate the expected utility with respect to $x$.\n\\[\n\tE[u] = p(x)u[I_H(x)] + (1-p(x))u[I_L(x)]\n\\]\n\n\n\\paragraph{Problem 41}\nConsider a twice continuously differentiable utility function $U(\\cdot)$ such that $U'>0$ and $U''< 0$.\nUtility comes from wealth $W$ and a person takes a gamble $h$ that represents a gain or loss to the a person's wealth and $h=0$ on average ($E(h)=0$).\nLet $p$ represent the size of an insurance premium paid to avoid taking the gamble and makes the person exactly indifferent between the gamble $h$ and paying $p$ with certainty.\nLet $E$ represent the expectation operator.\nUse the identity below to answer the questions.\n\\[\n\tE[U(W + h)] \\equiv U(W-p)\n\\]\n\\begin{enumerate}[(i)]\n\t\\item Derive a linear (first order) Taylor approximation of the right-hand side of the identity.\n\t\\item Derive a quadratic (second order) Taylor approximation of the left-hand side of the identity.\n\t\\item Let $r(W) = -U''(W)/U'(W)$ (this is the Arrow-Pratt measure of risk-aversion) use the previous approximations and the identity relationship to sign the derivative $\\dd P / \\dd r(W)$.  What is the sign and what relationship does this imply about the level of risk aversion and the amount of insurance premium an individual is willing to pay?\n\\end{enumerate}\n\n\n\\paragraph{Problem 42}\nA new machine as a rental rate $v(s)$ at any time $s$ and depreciates at rate $d$.\nWith interest rate $r$ the present discounted value of this machine is \n\\[\n\tPDV(t) = \\int_{t}^{\\infty} e^{(r+d)t} v(s) e^{-(r+d)s} \\dd s\n\\]\nLet $p(t)$ be the purchase price of the machine at time $t$.\nIn equilibrium the purchase price at time $t$, $p(t)$ will equal the present discounted value and hence we have\n\\[\n\tp(t) = \\int_{t}^{\\infty} e^{(r+d)t} v(s)e^{-(r+d)s} \\dd s\n\\]\n\\begin{enumerate}[(i)]\n\t\\item Using the last expression for $p(t)$, find $\\frac{dp(t)}{dt}$.\n\t\\item Using your expression for $\\frac{dp(t)}{dt}$ solve for $v(t)$ in terms of $p(t)$ to show the relationship between a new machines rental rate at time $t$ and the machine's purchase price at time $t$.\n\\end{enumerate}\n\n\n\\paragraph{Problem 43}\nA forester must decide when to cut down a growing tree.\nThe value at any time $t$ is given by $f(t)$ where $f' > 0$ and $f'' < 0$ and there was an initial investment of $L$.\nThe continuous interest rate is $r$.\nThe forester must choose $t$ (the time of harvest) to maximize the present discounted value of her profits.\n\\[\n\tPDV(t) = e^{-rt}f(t) - L\n\\]\n\\begin{enumerate}[(i)]\n\t\\item Differentiate $PDV(t)$ with respect to $t$.\n\t\\item Use the derivative as a first order condition to characterize the relationship between the $t$ that maximizes the forester's present discounted value of profit and the interest rate $r$.\n\\end{enumerate}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\end{document}", "meta": {"hexsha": "8e8fc31c2529d38bfed2d92e59a3e28dcceae61e", "size": 29881, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/pdfs/math_bootcamp/bootcamp_repo/assignment_0/assignment_0_key.tex", "max_stars_repo_name": "joepatten/joepatten.github.io", "max_stars_repo_head_hexsha": "4b9acc8720f3a33337368fee719902b54a6f2f68", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assets/pdfs/math_bootcamp/bootcamp_repo/assignment_0/assignment_0_key.tex", "max_issues_repo_name": "joepatten/joepatten.github.io", "max_issues_repo_head_hexsha": "4b9acc8720f3a33337368fee719902b54a6f2f68", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-08-09T16:28:31.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-10T14:48:57.000Z", "max_forks_repo_path": "assets/pdfs/math_bootcamp/bootcamp_repo/assignment_0/assignment_0_key.tex", "max_forks_repo_name": "joepatten/joepatten.github.io", "max_forks_repo_head_hexsha": "4b9acc8720f3a33337368fee719902b54a6f2f68", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.3074119077, "max_line_length": 347, "alphanum_fraction": 0.4922860681, "num_tokens": 8777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7033779435437262}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 5}\n\nGive asymptotic upper and lower bounds for $T(n)$ in each of the following recurrences.\nAssume that $T(n)$ is constant for $n \\leq 2$.\nMake your bounds as tight as possible, and justify your answers.\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item $T(n) = 2T(n/2) + n^4$.\n\\item $T(n) = T(7n/10) + n$.\n\\item $T(n) = 16T(n/4) + n^2$.\n\\item $T(n) = 2T(n/4) + \\sqrt{n}$.\n\\item $T(n) = T(n-2) + n^2$.\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item $T(n) = 2T(n/2) + n^4$\n\nRecurrence is of the form $T(n) = aT(n/b)+f(n)$ where $a=2 \\geq 1$, $b=2 > 1$ and $f(n) = n^4$ is ultimately positive.\nTherefore the \\emph{Master Theorem} can be applied, according to which $T(n)$ can be asymptotically estimated as follows.\n\nSince $f(n) = n^4$ is significantly large compared to $n^{\\log_b a}=n$, $f(n)$ can be written as $f(n) = \\Omega(n^{1+\\epsilon})$ for $0 < \\epsilon \\leq 1$ provided that for some $0<c<1$ and $n_0$, if $n > n_0$, $af(n/b) \\leq c f(n)$.\nThis is true because by choosing $0.125 \\leq c < 1$, $2f(n/2)=2\\frac{n^4}{16}\\leq cf(n)=cn^4$ for all $n$.\n\nTherefore,\n\\begin{equation}\nT(n) = \\Theta(f(n)) = \\Theta(n^4)\n\\end{equation}\n\n\\item $T(n) = T(7n/10) + n$\n\nRecurrence is of the form $T(n) = aT(n/b) + f(n)$ where $a = 1 \\geq 1$, $b = \\frac{10}{7} > 1$ and $f(n) = n$ is ultimately positive.\nWith conditions of the \\emph{Master Theorem} satisfied, $T(n)$ can be asymptotically estimated as follows.\n\nAs $\\log_b a = \\log_{10/7} 1 = 0$, $f(n) = n$ is larger than $n^{\\log_b a} = 1$.\nTherefore, $f(n) = \\Omega(n^\\epsilon)$ for $0 < \\epsilon \\leq 1$ provided that for some $0<c<1$ and $n_0$, if $n > n_0$, $af(n/b) \\leq c f(n)$.\nThis is true because by choosing $0.7 \\leq c < 1$, $f(7n/10) = 0.7n \\leq cf(n) = cn$ for all $n \\geq n_0 = 0$.\n\nTherefore,\n\\begin{equation}\nT(n) = \\Theta(f(n)) = \\Theta(n)\n\\end{equation}\n\n\\item $T(n) = 16T(n/4) + n^2$\n\nRecurrence is of the form $T(n) = aT(n/b)+f(n)$ where $a=16 \\geq 1$, $b=4 > 1$ and $f(n) = n^2$ is ultimately positive.\nTherefore the \\emph{Master Theorem} can be applied, according to which $T(n)$ can be asymptotically estimated as follows.\n\nSince $f(n) = n^2$ is comparable to $n^{\\log_b a}=n^{\\log_4 16}=n^2$, we have $ f(n) = \\Theta(n^2)$ and thus\n\n\\begin{equation}\nT(n) = \\Theta(n^{\\log_b a}\\log n) = \\Theta(n^2\\log n)\n\\end{equation}\n\n\\item $T(n) = 2T(n/4) + \\sqrt{n}$\n\nRecurrence is of the form $T(n) = aT(n/b)+f(n)$ where $a=2 \\geq 1$, $b=4 > 1$ and $f(n) = \\sqrt{n}$ is ultimately positive.\nTherefore the \\emph{Master Theorem} can be applied, according to which $T(n)$ can be asymptotically estimated as follows.\n\nSince $f(n) = \\sqrt{n}$ is comparable to $n^{\\log_b a}=n^{\\log_4 2}=\\sqrt{n}$, we have $ f(n) = \\Theta(\\sqrt{n})$ and thus\n\n\\begin{equation}\nT(n) = \\Theta(n^{\\log_b a}\\log n) = \\Theta(\\sqrt{n} \\log n)\n\\end{equation}\n\n\\item $T(n) = T(n-2) + n^2$\n\nIt is claimed that the given recurrence is bound by $T(n) = \\mathcal{O}(n^2)$.\nProof is given by induction on $n$.\n\n\\emph{Base step}: As stated by the question, $T(n)$ is constant for $n \\leq 2$.\nLet $T(n) = c$ for any $n \\leq 2$.\nWe can take any $n_0 \\leq 2$ as base step of the induction and show that $T(n) = c + n^2 = \\mathcal{O}(n^2)$.\nThis is directly obtained by choosing $n_0 = 2$ and $d = c$ to satisfy $c + n^2 \\leq d n^2$.\n\n\\emph{Induction Step}: Inductive hypothesis is formed as $T(n) = \\mathcal{O}(n^2)$ for any $n \\leq n_1$.\nIt suffices to show that $T(n_1+1) = \\mathcal{O}(n^2)$.\nUsing the inductive hypothesis, $T(n_1+1) = T(n_1-1) + n^2$.\nBut it is explicitly stated by inductive hypothesis that $T(n_1-1) = \\mathcal{O}(n^2)$.\nWe also know that $n^2 = \\mathcal{O}(n^2)$.\nTherefore, $T(n_1+1) = \\mathcal{O}(n^2) + \\mathcal{O}(n^2) = \\mathcal{O}(n^2)$.\n\nTherefore,\n\\begin{equation}\nT(n) = \\mathcal{O}(n^2)\n\\end{equation}\n\n\\end{enumerate}\n", "meta": {"hexsha": "ec3800cd9c87556e836c7669d57575e462182b1f", "size": 4171, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q05.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q05.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q05.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 43.0, "max_line_length": 233, "alphanum_fraction": 0.6096859266, "num_tokens": 1614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7033779386151968}}
{"text": "\\documentclass{notes}\n\n  \\title{Pumping Lemma}\n  \\author{ian.mcloughlin@gmit.ie}\n  \\date{\\today}\n\n\\begin{document}\n\n  \\section*{Theorem}\n    Let \\(L\\) be an infinite regular language.\n    Let \\(p\\) be the number of states in a deterministic finite automaton that recognises \\(L\\).\n    Then any string \\(s\\) in \\(L\\) of length at least \\(p = |s|\\) can be broken into three substrings \\(s=xyz\\) such that:\n    \\begin{itemize}\n      \\item \\(|y| > 0\\) ,\n      \\item \\(|xy| \\leq p\\), and\n      \\item \\(xy^iz \\in L\\) for all \\(i \\in \\mathbb{N}_0\\).\n    \\end{itemize}\n  \n    \\section*{Rationale}\n      Once we read \\(p\\) characters from \\(s\\), we must have visited some state twice\\footnote{At least one state at least twice.}.\n      Suppose \\(q\\) is a state we visit twice, and call \\(y\\) the substring of \\(s\\) that we read between the two visits.\n\n      When we can delete \\(y\\) from \\(s\\) and the automaton must accept this new string also.\n      Likewise we can repeat \\(y\\) any number of times to create a new string that must also be accepted.\n\n      Note the automaton essentially forgets the path it took to a given state -- once it arrives at a given state it can't remember how it got there.\n\n    \\section*{Example}\n\n    \\section*{Non-regular example}\n      \\[L = \\{0^i1^i | i \\in \\mathbb{N}_0\\}\\]\n      \\[s = 0^p1^p = xyz \\]\n      \\[|xy| \\leq p \\Rightarrow y = 0^n, n \\in \\mathbb{N}\\]\n      \\[\\Rightarrow 0^{p-n}0^{2n}1^n \\in L \\]\n      That's a contradiction.\n\n  %\\bibliography{bibliography}\n\\end{document}", "meta": {"hexsha": "a859e561e348554f320b07f8522166f12416a7f4", "size": 1512, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "finite-pumping.tex", "max_stars_repo_name": "ianmcloughlin/latex-notes", "max_stars_repo_head_hexsha": "2ce8e4de828f7ff916d8e21d46ad610f62653acb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "finite-pumping.tex", "max_issues_repo_name": "ianmcloughlin/latex-notes", "max_issues_repo_head_hexsha": "2ce8e4de828f7ff916d8e21d46ad610f62653acb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "finite-pumping.tex", "max_forks_repo_name": "ianmcloughlin/latex-notes", "max_forks_repo_head_hexsha": "2ce8e4de828f7ff916d8e21d46ad610f62653acb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7894736842, "max_line_length": 150, "alphanum_fraction": 0.6276455026, "num_tokens": 468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7033779234750911}}
{"text": "\\chapter{Kernels}\n\\label{chap:Kernels}\n\n\\section{Introduction}\nSo far in this book, we have been assuming that each object that we wish to classify or cluster or process in anyway can be represented as a fixed-size feature vector, typically of the form $\\vec{x}_i \\in \\mathbb{R}^D$. However, for certain kinds of objects, it is not clear how to best represent them as fixed-sized feature vectors. For example, how do we represent a text document or protein sequence, which can be of variable length? or a molecular structure, which has complex 3d geometry? or an evolutionary tree, which has variable size and shape?\n\nOne approach to such problems is to define a generative model for the data, and use the inferred latent representation and/or the parameters of the model as features, and then to plug these features in to standard methods. For example, in Chapter 28 TODO, we discuss deep learning, which is essentially an unsupervised way to learn good feature representations.\n\nAnother approach is to assume that we have some way of measuring the similarity between objects, that doesn’t require preprocessing them into feature vector format. For example, when comparing strings, we can compute the edit distance between them. Let $\\kappa(\\vec{x},\\vec{x}') \\geq 0$ be some measure of similarity between objects $\\kappa(\\vec{x},\\vec{x}') \\in \\mathcal{X}$,  we will call $\\kappa$ a \\textbf{kernel function}. Note that the word “kernel” has several meanings; we will discuss a different interpretation in Section 14.7.1 TODO.\n\nIn this chapter, we will discuss several kinds of kernel functions. We then describe some algorithms that can be written purely in terms of kernel function computations. Such methods can be used when we don’t have access to (or choose not to look at) the “inside” of the objects $\\vec{x}$ that we are processing.\n\n\n\\section{Kernel functions}\n\\begin{definition}\nA \\textbf{kernel function}\\footnote{\\url{http://en.wikipedia.org/wiki/Kernel_function}} is a real-valued function of two arguments, $\\kappa(\\vec{x},\\vec{x}') \\in \\mathbb{R}$. Typically the function is symmetric (i.e., $\\kappa(\\vec{x},\\vec{x}')=\\kappa(\\vec{x}',\\vec{x})$, and non-negative (i.e., $\\kappa(\\vec{x},\\vec{x}') \\geq 0$). \n\\end{definition}\n\nWe give several examples below.\n\n\\subsection{RBF kernels}\nThe \\textbf{Gaussian kernel} or \\textbf{squared exponential kernel}(SE kernel) is defined by\n\\begin{equation}\n\\kappa(\\vec{x},\\vec{x}')=\\exp\\left(-\\frac{1}{2}(\\vec{x}-\\vec{x}')^T\\vec{\\Sigma}^{-1}(\\vec{x}-\\vec{x}')\\right)\n\\end{equation}\n\nIf $\\vec{\\Sigma}$ is diagonal, this can be written as\n\\begin{equation}\n\\kappa(\\vec{x},\\vec{x}')=\\exp\\left(-\\frac{1}{2}\\sum\\limits_{j=1}^D \\frac{1}{\\sigma_j^2}(x_j-x_j')^2\\right)\n\\end{equation}\n\nWe can interpret the $\\sigma_j$ as defining the \\textbf{characteristic length scale} of dimension $j$.If $\\sigma_j = \\infty$, the corresponding dimension is ignored; hence this is known as the \\textbf{ARD kernel}. If $\\vec{\\Sigma}$ is spherical, we get the isotropic kernel\n\\begin{equation}\\label{eqn:RBF-kernel}\n\\kappa(\\vec{x},\\vec{x}')=\\exp\\left(-\\frac{\\lVert\\vec{x}-\\vec{x}'\\rVert^2}{2\\sigma^2}\\right)\n\\end{equation}\n\nHere $\\sigma^2$ is known as the \\textbf{bandwidth}. Equation \\ref{eqn:RBF-kernel} is an example of a \\textbf{radial basis function} or \\textbf{RBF} kernel, since it is only a function of $\\lVert\\vec{x}-\\vec{x}'\\rVert^2$.\n\n\n\\subsection{TF-IDF kernels}\n\\begin{equation}\\label{eqn:RBF-kernel}\n\\kappa(\\vec{x},\\vec{x}')=\\frac{\\phi(\\vec{x})^T\\phi(\\vec{x}')}{\\lVert\\phi(vec{x})\\rVert_2\\lVert\\phi(\\vec{x}')\\rVert_2}\n\\end{equation}\nwhere $\\phi(\\vec{x})=\\text{tf-idf}(\\vec{x})$.\n\n\\subsection{Mercer (positive definite) kernels}\n\\label{sec:Mercer-kernels}\nIf the kernel function satisfies the requirement that the \\textbf{Gram matrix}, defined by\n\\begin{equation}\n\\vec{K} \\triangleq \\left(\\begin{array}{ccc}\n\\kappa(\\vec{x}_1,\\vec{x}_2) & \\cdots \\kappa(\\vec{x}_1,\\vec{x}_N) \\\\\n\\vdots & \\vdots & \\vdots \\\\\n\\kappa(\\vec{x}_N,\\vec{x}_1) & \\cdots \\kappa(\\vec{x}_N,\\vec{x}_N) \n\\end{array}\\right)\n\\end{equation}\nbe positive definite for any set of inputs $\\{\\vec{x}_i\\}_{i=1}^N$. We call such a kernel a \\textbf{Mercer kernel},or \\textbf{positive definite kernel}.\n\nIf the Gram matrix is positive definite, we can compute an eigenvector decomposition of it as follows\n\\begin{equation}\n\\vec{K}=\\vec{U}^T\\vec{\\Lambda}\\vec{U}\n\\end{equation}\n\nwhere $\\vec{\\Lambda}$ is a diagonal matrix of eigenvalues $\\lambda_i >0$. Now consider an element of $\\vec{K}$:\n\\begin{equation}\nk_{ij}=(\\vec{\\Lambda}^{\\frac{1}{2}}\\vec{U}_{:,i})^T(\\vec{\\Lambda}^{\\frac{1}{2}}\\vec{U}_{:,j})\n\\end{equation}\n\nLet us define $\\phi(\\vec{x}_i)=\\vec{\\Lambda}^{\\frac{1}{2}}\\vec{U}_{:,i}$, then we can write\n\\begin{equation}\nk_{ij}=\\phi(\\vec{x}_i)^T\\phi(\\vec{x}_j)\n\\end{equation}\n\nThus we see that the entries in the kernel matrix can be computed by performing an inner product of some feature vectors that are implicitly defined by the eigenvectors $\\vec{U}$. In general, if the kernel is Mercer, then there exists a function $\\phi$ mapping $\\vec{x} \\in \\mathcal{X}$ to $\\mathbb{R}^D$ such that\n\\begin{equation}\n\\kappa(\\vec{x},\\vec{x}')=\\phi(\\vec{x})^T\\phi(\\vec{x}')\n\\end{equation}\nwhere $\\phi$ depends on the eigen functions of $\\kappa$(so $D$ is a potentially infinite dimensional space).\n\nFor example, consider the (non-stationary) \\textbf{polynomial kernel} $\\kappa(\\vec{x},\\vec{x}')=(\\gamma \\vec{x}\\vec{x}'+r)^M$, where $r>0$. One can show that the corresponding feature vector $\\phi(\\vec{x})$ will contain all terms up to degree $M$. For example, if $M=2, \\gamma=r=1$ and $\\vec{x}, \\vec{x}' \\in \\mathbb{R}^2$, we have\n\\begin{align*}\n(\\vec{x}\\vec{x}'+1)^2 & =(1+x_1x_1'+x_2+x_2')^2 \\\\\n    & = 1+2x_1x_1'+2x_2x_2'+(x_1x_1')^2+(x_2x_2')^2x_1x_1'x_2x_2' \\\\\n\t& = \\phi(\\vec{x})^T\\phi(\\vec{x}') \\\\\n\\text{where } & \\phi(\\vec{x})=(1,\\sqrt{2}x_1,\\sqrt{2}x_2,x_1^2,x_2^2,\\sqrt{2}x_1x_2)\n\\end{align*}\n\nIn the case of a Gaussian kernel, the feature map lives in an infinite dimensional space. In such a case, it is clearly infeasible to explicitly represent the feature vectors.\n\nIn general, establishing that a kernel is a Mercer kernel is difficult, and requires techniques from functional analysis. However, one can show that it is possible to build up new Mercer kernels from simpler ones using a set of standard rules. For example, if $\\kappa_1$ and $\\kappa_2$ are both Mercer, so is $\\kappa(\\vec{x},\\vec{x}')=\\kappa_1(\\vec{x},\\vec{x}')+\\kappa_2(\\vec{x},\\vec{x}')=$. See e.g., (Schoelkopf and Smola 2002) for details.\n\n\n\\subsection{Linear kernels}\n\\begin{equation}\n\\kappa(\\vec{x},\\vec{x}')=\\vec{x}^T\\vec{x}'\n\\end{equation}\n\n\\subsection{Matern kernels}\nThe \\textbf{Matern kernel}, which is commonly used in Gaussian process regression (see Section 15.2), has the following form\n\\begin{equation}\n\\kappa(r)=\\frac{2^{1-\\nu}}{\\Gamma(\\nu)}\\left(\\frac{\\sqrt{2\\nu}r}{\\ell}\\right)^{\\nu}K_{\\nu}\\frac{\\sqrt{2\\nu}r}{\\ell}\n\\end{equation}\nwhere $r=\\lVert\\vec{x}-\\vec{x}'\\rVert$, $\\nu>0$, $\\ell>0$, and $K_{\\nu}$ is a modified Bessel function. As $\\nu \\rightarrow \\infty$, this approaches the SE kernel. If $\\nu=\\frac{1}{2}$, the kernel simplifies to\n\\begin{equation}\n\\kappa(r)=\\exp(-r/\\ell)\n\\end{equation}\n\nIf $D=1$, and we use this kernel to define a Gaussian process (see Chapter 15 TODO), we get the \\textbf{Ornstein-Uhlenbeck process}, which describes the velocity of a particle undergoing Brownian motion (the corresponding function is continuous but not differentiable, and hence is very “jagged”).\n\n\n\\subsection{String kernels}\n\\label{sec:String-kernels}\nNow let $\\phi_s(\\vec{x})$ denote the number of times that substrings appears in string $\\vec{x}$. We define the kernel between two strings $\\vec{x}$ and $\\vec{x}'$ as\n\\begin{equation}\n\\kappa(\\vec{x},\\vec{x}')=\\sum\\limits_{s \\in \\mathcal{A}^*} w_s\\phi_s(\\vec{x})\\phi_s(\\vec{x}')\n\\end{equation}\nwhere $w_s \\geq 0$ and $\\mathcal{A}^*$ is the set of all strings (of any length) from the alphabet $\\mathcal{A}$(this is known as the Kleene star operator). This is a Mercer kernel, and be computed in $O(|\\vec{x}|+|\\vec{x}'|)$ time (for certain settings of the weights $\\{ws\\}$) using suffix trees (Leslie et al. 2003; Vishwanathan and Smola 2003; Shawe-Taylor and Cristianini 2004).\n\nThere are various cases of interest. If we set $w_s =0$for $|s| >1$ we get a bag-of-characters kernel. This defines $\\phi(\\vec{x})$ to be the number of times each character in $\\mathcal{A}$ occurs in $\\vec{x}$.If we require $s$ to be bordered by white-space, we get a bag-of-words kernel, where $\\phi(\\vec{x})$ counts how many times each possible word occurs. Note that this is a very sparse vector, since most words will not be present. If we only consider strings of a fixed lengthk, we get the \\textbf{k-spectrum} kernel. This has been used to classify proteins into SCOP superfamilies (Leslie et al. 2003).\n\n\n\\subsection{Pyramid match kernels}\n% \\begin{figure}[hbtp]\n% \\centering\n%     \\includegraphics[scale=.70]{pyramid-match-kernel.png}\n% \\caption{Illustration of a pyramid match kernel computed from two images. Used with kind permission of Kristen Grauman.}\n% \\label{fig:pyramid-match-kernel}\n% \\end{figure}\n\n\n\\subsection{Kernels derived from probabilistic generative models}\nSuppose we have a probabilistic generative model of feature vectors, $p(\\vec{x}|\\vec{\\theta})$. Then there are several ways we can use this model to define kernel functions, and thereby make the model suitable for discriminative tasks. We sketch two approaches below.\n\n\n\\subsubsection{Probability product kernels}\n\\begin{equation}\\label{eqn:Probability-product-kernels}\n\\kappa(\\vec{x}_i,\\vec{x}_j)=\\int p(\\vec{x}|\\vec{x}_i)^{\\rho}p(\\vec{x}|\\vec{x}_j)^{\\rho}\\mathrm{d}\\vec{x}\n\\end{equation}\nwhere $\\rho>0$, and $p(\\vec{x}|\\vec{x}_i)$ is often approximated by $p(\\vec{x}|\\hat{\\vec{\\theta}}(\\vec{x}_i))$,where $\\hat{\\vec{\\theta}}(\\vec{x}_i)$ is a parameter estimate computed using a single data vector. This is called a \\textbf{probability product kernel}(Jebara et al. 2004).\n\nAlthough it seems strange to fit a model to a single data point, it is important to bear in mind that the fitted model is only being used to see how similar two objects are. In particular, if we fit the model to $\\vec{x}_i$ and then the model thinks $\\vec{x}_j$ is likely, this means that $\\vec{x}_i$ and $\\vec{x}_j$ are similar. For example, suppose $p(\\vec{x}|\\vec{\\theta}) \\sim \\mathcal{N}(\\vec{\\mu},\\sigma^2\\vec{I})$, where $\\sigma^2$ is fixed. If $\\rho=1$, and we use $\\hat{\\vec{\\mu}}(\\vec{x}_i)=\\vec{x}_i$ and $\\hat{\\vec{\\mu}}(\\vec{x}_j)=\\vec{x}_j$, we find (Jebara et al. 2004, p825) that\n\\begin{equation}\n\\kappa(\\vec{x}_i,\\vec{x}_j)=\\frac{1}{(4\\pi\\sigma^2)^{D/2}}\\exp\\left(-\\frac{1}{4\\sigma^2}\\lVert\\vec{x}_i-\\vec{x}_j\\rVert^2\\right)\n\\end{equation}\nwhich is (up to a constant factor) the RBF kernel.\n\nIt turns out that one can compute Equation \\ref{eqn:Probability-product-kernels} for a variety of generative models, including ones with latent variables, such as HMMs. This provides one way to define kernels on variable length sequences. Furthermore, this technique works even if the sequences are of real-valued vectors, unlike the string kernel in Section \\ref{sec:String-kernels}. See (Jebara et al. 2004) for further details\n\n\n\\subsubsection{Fisher kernels}\nA more efficient way to use generative models to define kernels is to use a \\textbf{Fisher kernel} (Jaakkola and Haussler 1998) which is defined as follows:\n\\begin{equation}\n\\kappa(\\vec{x}_i,\\vec{x}_j)=g(\\vec{x}_i)^T\\vec{F}^{-1}g(\\vec{x}_j)\n\\end{equation}\nwhere $g$ is the gradient of the log likelihood, or \\textbf{score vector}, evaluated at the MLE $\\hat{\\vec{\\theta}}$\n\\begin{equation}\ng(\\vec{x}) \\triangleq \\frac{\\mathrm{d}}{\\mathrm{d}\\vec{\\theta}}\\log p(\\vec{x}|\\vec{\\theta})|_{\\hat{\\vec{\\theta}}}\n\\end{equation}\nand $\\vec{F}$ is the Fisher information matrix, which is essentially the Hessian:\n\\begin{equation}\n\\vec{F} \\triangleq \\left[\\frac{\\partial^2}{\\partial \\theta_i \\partial \\theta_j}\\log p(\\vec{x}|\\vec{\\theta})\\right]|_{\\hat{\\vec{\\theta}}}\n\\end{equation}\n\nNote that $\\hat{\\vec{\\theta}}$ is a function of all the data, so the similarity of $\\vec{x}_i$ and $\\vec{x}_j$ is computed in the context of all the data as well. Also, note that we only have to fit one model.\n\n\n\\section{Using kernels inside GLMs}\n\n\n\\subsection{Kernel machines}\nWe define a \\textbf{kernel machine} to be a GLM where the input feature vector has the form\n\\begin{equation}\\label{eqn:kernel-machine}\n\\phi(\\vec{x})=(\\kappa(\\vec{x},\\vec{\\mu}_1),\\cdots,\\kappa(\\vec{x},\\vec{\\mu}_K))\n\\end{equation}\n\nwhere $\\vec{\\mu}_k \\in \\mathcal{X}$ are a set of $K$ centroids. If $\\kappa$ is an RBF kernel, this is called an \\textbf{RBF network}. We discuss ways to choose the $\\vec{\\mu}_k$ parameters below. We will call Equation \\ref{eqn:kernel-machine} a \\textbf{kernelised feature vector}. Note that in this approach, the kernel need not be a Mercer kernel.\n\nWe can use the kernelized feature vector for logistic regression by defining $p(y|\\vec{x},\\vec{\\theta})=\\mathrm{Ber}(y|\\vec{w}^T\\phi(\\vec{x}))$. This provides a simple way to define a non-linear decision boundary. For example, see Figure \\ref{fig:kenel-machine-xor}.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.70]{kenel-machine-xor-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.70]{kenel-machine-xor-b.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.70]{kenel-machine-xor-c.png}}\n\\caption{(a) xor truth table. (b) Fitting a linear logistic regression classifier using degree 10 polynomial expansion. (c) Same model, but using an RBF kernel with centroids specified by the 4 black crosses.}\n\\label{fig:kenel-machine-xor} \n\\end{figure}\n\nWe can also use the kernelized feature vector inside a linear regression model by defining $p(y|\\vec{x},\\vec{\\theta})=\\mathcal{N}(y|\\vec{w}^T\\phi(\\vec{x}),\\sigma^2)$. \n\n\n\\subsection{L1VMs, RVMs, and other sparse vector machines}\n\\label{sec:sparse-kernel-machines}\nThe main issue with kernel machines is: how do we choose the centroids $\\vec{\\mu}_k$? We can use \\textbf{sparse vector machine}, \\textbf{L1VM}, \\textbf{L2VM}, \\textbf{RVM}, \\textbf{SVM}.\n\n% In Figure \\ref{fig:L2VM-L1VM-RVM-SVM-2d}, we compare L2VM, L1VM, RVM and an SVM using the same RBF kernel on a binary classification problem in 2d.\n\n% \\begin{figure}[hbtp]\n% \\centering\n% \\subfloat[]{\\includegraphics[scale=.50]{L2VM-L1VM-RVM-SVM-2d-a.png}} \\\\\n% \\subfloat[]{\\includegraphics[scale=.50]{L2VM-L1VM-RVM-SVM-2d-b.png}} \\\\\n% \\subfloat[]{\\includegraphics[scale=.50]{L2VM-L1VM-RVM-SVM-2d-c.png}} \\\\\n% \\subfloat[]{\\includegraphics[scale=.50]{L2VM-L1VM-RVM-SVM-2d-d.png}}\n% \\caption{Example of non-linear binary classification using an RBF kernel with bandwidth $\\sigma=0.3$. (a) L2VM with $\\lambda=5$. (b) L1VM with $\\lambda=1$. (c) RVM. (d) SVM with $C=1/\\lambda$ chosen by cross validation. Black circles denote the support vectors.}\n% \\label{fig:L2VM-L1VM-RVM-SVM-2d} \n% \\end{figure}\n\n% In Figure \\ref{fig:L2VM-L1VM-RVM-SVM-1d}, we compare L2VM, L1VM, RVM and an SVM using an RBF kernel on a 1d regression problem. \n% \\begin{figure}[hbtp]\n% \\centering\n%     \\includegraphics[scale=.70]{L2VM-L1VM-RVM-SVM-1d.png}\n% \\caption{Example of kernel based regression on the noisy sinc function using an RBF kernel with bandwidth $\\sigma=0.3$. (a) L2VM with $\\lambda=0.5$. (b) L1VM with $\\lambda=0.5$. (c) RVM. (d) SVM regression with $C=1/\\lambda$ chosen by cross validation, and $\\epsilon=0.1$ (the default for SVMlight). Red circles denote the retained training exemplars.}\n% \\label{fig:L2VM-L1VM-RVM-SVM-1d} \n% \\end{figure}\n\n\n\\section{The kernel trick}\nRather than defining our feature vector in terms of kernels, $\\phi(\\vec{x})=(\\kappa(\\vec{x},\\vec{x}_1),\\cdots,\\kappa(\\vec{x},\\vec{x}_N))$, we can instead work with the original feature vectors $\\vec{x}$, but modify the algorithm so that it replaces all inner products of the form $<\\vec{x}_i,\\vec{x}_j>$ with a call to the kernel function, $\\kappa(\\vec{x}_i,\\vec{x}_j)$. This is called the \\textbf{kernel trick}. It turns out that many algorithms can be kernelized in this way. We give some examples below. Note that we require that the kernel be a Mercer kernel for this trick to work.\n\n\n\\subsection{Kernelized KNN}\nThe Euclidean distance can be unrolled as\n\\begin{equation}\\label{eqn:Euclidean-distance}\n\\lVert\\vec{x}_i-\\vec{x}_j\\rVert=<\\vec{x}_i,\\vec{x}_i>+<\\vec{x}_j,\\vec{x}_j>-2<\\vec{x}_i,\\vec{x}_j>\n\\end{equation}\nthen by replacing all $<\\vec{x}_i,\\vec{x}_j>$ with $\\kappa(\\vec{x}_i,\\vec{x}_j)$ we get Kernelized KNN.\n\n\n\\subsection{Kernelized K-medoids clustering}\n\\textbf{K-medoids algorothm} is similar to K-means(see Section \\ref{sec:K-means}), but instead of representing each cluster’s centroid by the mean of all data vectors assigned to this cluster, we make each centroid be one of the data vectors themselves. Thus we always deal with integer indexes, rather than data objects.\n\nThis algorithm can be kernelized by using Equation \\ref{eqn:Euclidean-distance} to replace the distance computation.\n\n\n\\subsection{Kernelized ridge regression}\nApplying the kernel trick to distance-based methods was straightforward. It is not so obvious how to apply it to parametric models such as ridge regression. However, it can be done, as we now explain. This will serve as a good “warm up” for studying SVMs.\n\n\n\\subsubsection{The primal problem}\nwe rewrite Equation \\ref{eqn:Ridge-regression-J} as the following\n\\begin{equation}\\label{eqn:Ridge-regression-primal-form}\nJ(\\vec{w})=(\\vec{y}-\\vec{X}\\vec{w})^T(\\vec{y}-\\vec{X}\\vec{w})+\\lambda\\lVert\\vec{w}\\rVert^2\n\\end{equation}\nand its solution is given by Equation \\ref{eqn:Ridge-regression-solution}.\n\n\n\\subsubsection{The dual problem}\nEquation \\ref{eqn:Ridge-regression-primal-form} is not yet in the form of inner products. However, using the matrix inversion lemma (Equation 4.107 TODO) we rewrite the ridge estimate as follows\n\\begin{equation}\n\\vec{w}=\\vec{X}^T(\\vec{X}\\vec{X}^T+\\lambda\\vec{I}_N)^{-1}\\vec{y}\n\\end{equation}\nwhich takes $O(N^3+N^2D)$ time to compute. This can be advantageous if $D$ is large. Furthermore, we see that we can partially kernelize this, by replacing $\\vec{X}\\vec{X}^T$ with the Gram matrix $\\vec{K}$. But what about the leading $\\vec{X}^T$ term?\n\nLet us define the following \\textbf{dual variables}:\n\\begin{equation}\n\\vec{\\alpha}=(\\vec{K}+\\lambda\\vec{I}_N)^{-1}\\vec{y}\n\\end{equation}\n\nThen we can rewrite the \\textbf{primal variables} as follows\n\\begin{equation}\n\\vec{w}=\\vec{X}^T\\vec{\\alpha}=\\sum\\limits_{i=1}^N \\alpha_i\\vec{x}_i\n\\end{equation}\n\nThis tells us that the solution vector is just a linear sum of the $N$ training vectors. When we plug this in at test time to compute the predictive mean, we get\n\\begin{equation}\ny=f(\\vec{x})=\\sum\\limits_{i=1}^N \\alpha_i\\vec{x}_i^T\\vec{x}=\\sum\\limits_{i=1}^N \\alpha_i\\kappa(\\vec{x}_i,\\vec{x})\n\\end{equation}\n\nSo we have succesfully kernelized ridge regression by changing from primal to dual variables. This technique can be applied to many other linear models, such as logistic regression.\n\n\n\\subsubsection{Computational cost}\nThe cost of computing the dual variables $\\vec{\\alpha}$ is $O(N^3)$, whereas the cost of computing the primal variables $\\vec{w}$ is $O(D^3)$. Hence the kernel method can be useful in high dimensional settings, even if we only use a linear kernel (c.f., the SVD trick in Equation \\ref{eqn:Ridge-regression-SVD}). However, prediction using the dual variables takes $O(ND)$ time, while prediction using the primal variables only takes $O(D)$ time. We can speedup prediction by making $\\vec{\\alpha}$ sparse, as we discuss in Section \\ref{sec:SVMs}.\n\n\n\\subsection{Kernel PCA}\nTODO\n\n\n\\section{Support vector machines (SVMs)}\n\\label{sec:SVMs}\nIn Section \\ref{sec:sparse-kernel-machines}, we saw one way to derive a sparse kernel machine, namely by using a GLM with kernel basis functions, plus a sparsity-promoting prior such as $\\ell_1$ or ARD. An alternative approach is to change the objective function from negative log likelihood to some other loss function, as we discussed in Section \\ref{sec:Surrogate-loss-functions}. In particular, consider the $\\ell_2$ regularized empirical risk function\n\\begin{equation}\nJ(\\vec{w}, \\lambda)=\\sum\\limits{i=1}^N L(y_i, \\hat{y_i})+\\lambda\\lVert\\vec{w}\\rVert^2\n\\end{equation}\nwhere $\\hat{y_i}=\\vec{w}^T\\vec{x}_i+w_0$.\n\nIf $L$ is quadratic loss, this is equivalent to ridge regression, and if $L$ is the log-loss defined in Equation \\ref{eqn:log-loss}, this is equivalent to logistic regression.\n\nHowever, if we replace the loss function with some other loss function, to be explained below, we can ensure that the solution is sparse, so that predictions only depend on a subset of the training data, known as \\textbf{support vectors}. This combination of the kernel trick plus a modified loss function is known as a \\textbf{support vector machine} or \\textbf{SVM}. \n\nNote that SVMs are very unnatural from a probabilistic point of view. \n\\begin{itemize}\n\\item{First, they encode sparsity in the loss function rather than the prior.}\n\\item{Second, they encode kernels by using an algorithmic trick, rather than being an explicit part of the model. }\n\\item{Finally, SVMs do not result in probabilistic outputs, which causes various difficulties, especially in the multi-class classification setting (see Section 14.5.2.4 TODO for details).}\n\\end{itemize}\n\nIt is possible to obtain sparse, probabilistic, multi-class kernel-based classifiers, which work as well or better than SVMs, using techniques such as the L1VM or RVM, discussed in Section \\ref{sec:sparse-kernel-machines}. However, we include a discussion of SVMs, despite their non-probabilistic nature, for two main reasons. \n\\begin{itemize}\n\\item{First, they are very popular and widely used, so all students of machine learning should know about them.}\n\\item{Second, they have some computational advantages over probabilistic methods in the structured output case; see Section 19.7 TODO.}\n\\end{itemize}\n\n\n\\subsection{SVMs for classification}\n\n\n\\subsubsection{Primal form}\n\\textbf{Representation}\n\\begin{equation}\n\\mathcal{H}:y=f(\\vec{x})=\\text{sign}(\\vec{w}\\vec{x}+b)\n\\end{equation}\n\n\\textbf{Evaluation}\n\\begin{eqnarray}\n\\min_{\\vec{w},b}  && \\frac{1}{2}\\|\\vec{w}\\|^2 \\\\\n       & s.t. \\quad & y_i(\\vec{w}\\vec{x}_i+b)\\geqslant 1, i=1,2, \\dots , N\n\\end{eqnarray}\n\n\n\\subsubsection{Dual form}\n\\textbf{Representation}\n\\begin{equation}\n\\mathcal{H}:y=f(\\vec{x})=\\text{sign}\\left(\\sum\\limits_{i=1}^N{\\alpha_iy_i(\\vec{x} \\cdot \\vec{x}_i)}+b\\right)\n\\end{equation}\n\n\\textbf{Evaluation}\n\\begin{eqnarray}\n \\min_{\\alpha} && \\frac{1}{2} \\sum\\limits_{i=1}^N\\sum\\limits_{j=1}^N \\alpha_i\\alpha_j y_i y_j (\\vec{x}_i \\cdot \\vec{x}_j) - \\sum\\limits_{i=1}^N \\alpha_i \\\\\n               & s.t.  \\quad &\\sum\\limits_{i=1}^N\\alpha_i y_i=0 \\\\\n               && \\alpha_i \\geqslant 0, i=1,2, \\dots, N\n\\end{eqnarray}\n\n\n\\subsubsection{Primal form with slack variables}\n\\textbf{Representation}\n\\begin{equation}\n\\mathcal{H}:y=f(\\vec{x})=\\text{sign}(\\vec{w}\\vec{x}+b)\n\\end{equation}\n\n\\textbf{Evaluation}\n\\begin{eqnarray}\n\\min_{\\vec{w},b}  &&  C \\sum\\limits_{i=1}^N\\xi_i + \\frac{1}{2}\\|\\vec{w}\\|^2 \\label{eqn:pfwr1} \\\\\n      & s.t. \\quad & y_i(\\vec{w}\\vec{x}_i+b)\\geqslant 1-\\xi_i  \\label{eqn:pfwr2} \\\\\n                  && \\xi_i \\geqslant 0, \\quad i=1,2, \\dots, N \\label{eqn:pfwr3}\n\\end{eqnarray}\n\n\n\\subsubsection{Dual form with slack variables}\n\\textbf{Representation}\n\\begin{equation}\n\\mathcal{H}:y=f(\\vec{x})=\\text{sign}\\left(\\sum\\limits_{i=1}^N{\\alpha_iy_i(\\vec{x} \\cdot \\vec{x}_i)}+b\\right)\n\\end{equation}\n\n\\textbf{Evaluation}\n\\begin{eqnarray}\n \\min_{\\alpha} && \\frac{1}{2} \\sum\\limits_{i=1}^N\\sum\\limits_{j=1}^N \\alpha_i\\alpha_j y_i y_j (\\vec{x}_i \\cdot \\vec{x}_j) - \\sum\\limits_{i=1}^N \\alpha_i \\\\\n               & s.t.  \\quad & \\sum\\limits_{i=1}^N\\alpha_i y_i=0 \\\\\n               && 0 \\leqslant  \\alpha_i \\leqslant C, i=1,2, \\dots, N\n\\end{eqnarray}\n\n\\begin{eqnarray}\n\\alpha_i=0 \\Rightarrow y_i(\\vec{w} \\cdot \\vec{x}_i+b)\\geqslant 1 \\\\\n\\alpha_i=C \\Rightarrow y_i(\\vec{w} \\cdot \\vec{x}_i+b)\\leqslant 1 \\\\\n0<\\alpha_i<C \\Rightarrow y_i(\\vec{w} \\cdot \\vec{x}_i+b)= 1\n\\end{eqnarray}\n\n\n\\subsubsection{Hinge Loss}\nLinear support vector machines can also be interpreted as hinge loss minimization:\n\\begin{equation}\\label{eqn:Hinge-Loss-objective}\n\\min_{\\vec{w},b} \\sum\\limits_{i=1}^N{L(y_i,f(\\vec{x}_i))} + \\lambda\\|\\vec{w}\\|^2\n\\end{equation}\nwhere $L(y, f(\\vec{x}))$ is a \\textbf{hinge loss function}:\n\\begin{equation}\nL(y, f(\\vec{x})) = \\begin{cases}\n1-yf(x),  & 1-yf(x) > 0 \\\\\n0,  & 1-yf(x) \\leqslant 0\n\\end{cases}\n\\end{equation}\n\n\\begin{proof}\nWe can write equation \\ref{eqn:Hinge-Loss-objective} as equations \\ref{eqn:pfwr1} $\\sim$ \\ref{eqn:pfwr3}.\n\nDefine slack variables\n\\begin{equation}\n\\xi_i \\triangleq 1-y_i(\\vec{w} \\cdot \\vec{x}_i + b),\\xi_i \\geqslant 0\n\\end{equation}\n\nThen $\\vec{w},b,\\xi_i$ satisfy the constraints \\ref{eqn:pfwr1} and \\ref{eqn:pfwr2}. And objective function \\ref{eqn:pfwr3} can be written as\n\\begin{equation}\n\\min_{\\vec{w},b} \\sum\\limits_{i=1}^N{\\xi_i}+ \\lambda\\|\\vec{w}\\|^2 \\nonumber\n\\end{equation}\n\nIf $\\lambda=\\dfrac{1}{2C}$, then \n\\begin{equation}\n\\min_{\\vec{w},b} \\dfrac{1}{C}\\left(C\\sum\\limits_{i=1}^N{\\xi_i}+\\dfrac{1}{2}\\|\\vec{w}\\|^2\\right)\n\\end{equation}\nIt is equivalent to equation \\ref{eqn:pfwr1}.\n\n\\end{proof}\n\n\n\\subsubsection{Optimization}\nQP, SMO\n\n\n\\subsection{SVMs for regression}\n\n\n\\subsubsection{Representation}\n\\begin{equation}\n\\mathcal{H}: y=f(\\vec{x})=\\vec{w}^T\\vec{x}+b\n\\end{equation}\n\n\n\\subsubsection{Evaluation}\n\\begin{equation}\nJ(\\vec{w})=C\\sum\\limits_{i=1}^N L(y_i,f(\\vec{x}_i))++\\dfrac{1}{2}\\lVert\\vec{w}\\rVert^2\n\\end{equation}\nwhere $L(y,f(\\vec{x}))$ is a \\textbf{epsilon insensitive loss function}:\n\\begin{equation}\nL(y,f(\\vec{x})) = \\begin{cases}\n0  & , |y-f(\\vec{x})|<\\epsilon \\\\\n|y-f(\\vec{x})|-\\epsilon  & , \\text{ otherwise}\n\\end{cases}\n\\end{equation}\nand $C=1/\\lambda$ is a regularization constant. \n\nThis objective is convex and unconstrained, but not differentiable, because of the absolute value function in the loss term. As in Section 13.4 TODO, where we discussed the lasso problem, there are several possible algorithms we could use. One popular approach is to formulate the problem as a constrained optimization problem. In particular, we introduce \\textbf{slack variables} to represent the degree to which each point lies outside the tube:\n\\begin{align*}\ny_i \\leq & f(\\vec{x}_i)+\\epsilon+\\xi_i^+ \\\\\ny_i \\geq & f(\\vec{x}_i)-\\epsilon-\\xi_i^- \n\\end{align*}\n\nGiven this, we can rewrite the objective as follows:\n\\begin{equation}\nJ(\\vec{w})=C\\sum\\limits_{i=1}^N (\\xi_i^+ + \\xi_i^-)++\\dfrac{1}{2}\\lVert\\vec{w}\\rVert^2\n\\end{equation}\nThis is a standard quadratic problem in $2N+D+1$ variables.\n\n\n\\subsection{Choosing $C$}\n\\label{sec:SVM-Choosing-C}\nSVMs for both classification and regression require that you specify the kernel function and the parameter $C$. Typically $C$ is chosen by cross-validation. Note, however, that $C$ interacts quite strongly with the kernel parameters. For example, suppose we are using an RBF kernel with precision $\\gamma=\\frac{1}{2\\sigma^2}$. If $\\gamma=5$, corresponding to narrow kernels, we need heavy regularization, and hence small $C$(so $\\lambda=1/C$is big). If $\\gamma=1$, a larger value of $C$should be used. So we see that $\\gamma$ and $C$ are tightly coupled. This is illustrated in Figure \\ref{fig:choosing-C}, which shows the CV estimate of the 0-1 risk as a function of $C$ and $\\gamma$.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.50]{choosing-C-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.50]{choosing-C-b.png}}\n\\caption{(a) A cross validation estimate of the 0-1 error for an SVM classifier with RBF kernel with different precisions $\\gamma=1/(2\\sigma^2)$ and different regularizer $\\gamma=1/C$, applied to a synthetic data set drawn from a mixture of 2 Gaussians. (b) A slice through this surface for $\\gamma=5$ The red dotted line is the Bayes optimal error, computed using Bayes rule applied to the model used to generate the data. Based on Figure 12.6 of (Hastie et al. 2009). }\n\\label{fig:choosing-C} \n\\end{figure}\n\nThe authors of libsvm recommend (Hsu et al. 2009) using CV over a 2d grid with values $C \\in \\{2^{−5},2^{−3},\\cdots,2^{15}\\}$ and $\\gamma \\in \\{2^{−15},2^{−13},\\cdots,2^3\\}$. In addition, it is important to standardize the data first, for a spherical Gaussian kernel to make sense.\n\nTo choose $C$ efficiently, one can develop a path following algorithm in the spirit of lars (Section 13.3.4 TODO). The basic idea is to start with $\\lambda$ large, so that the margin $1/\\lVert\\vec{w}(\\lambda)\\rVert$ is wide, and hence all points are inside of it and have $\\alpha_i =1$. By slowly decreasing $\\lambda$, a small set of points will move from inside the margin to outside, and their $\\alpha_i$ values will change from 1 to 0, as they cease to be support vectors. When $\\lambda$ is maximal, the function is completely smoothed, and no support vectors remain. See (Hastie et al. 2004) for the details.\n\n\n\\subsection{A probabilistic interpretation of SVMs}\nTODO see MLAPP Section 14.5.5\n\n\n\\subsection{Summary of key points}\nSummarizing the above discussion, we recognize that SVM classifiers involve three key ingredients: the kernel trick, sparsity, and the large margin principle. The kernel trick is necessary to prevent underfitting, i.e., to ensure that the feature vector is sufficiently rich that a linear classifier can separate the data. (Recall from Section \\ref{sec:Mercer-kernels} that any Mercer kernel can be viewed as implicitly defining a potentially high dimensional feature vector.) If the original features are already high dimensional (as in many gene expression and text classification problems), it suffices to use a linear kernel, $\\kappa(\\vec{x},\\vec{x}')=\\vec{x}^T\\vec{x}'$ , which is equivalent to working with the original features.\n\nThe sparsity and large margin principles are necessary to prevent overfitting, i.e., to ensure that we do not use all the basis functions. These two ideas are closely related to each other, and both arise (in this case) from the use of the hinge loss function. However, there are other methods of achieving sparsity (such as $\\ell_1$), and also other methods of maximizing the margin(such as boosting). A deeper discussion of this point takes us outside of the scope of this book. See e.g., (Hastie et al. 2009) for more information.\n\n\n\\section{Comparison of discriminative kernel methods}\nWe have mentioned several different methods for classification and regression based on kernels, which we summarize in Table \\ref{tab:Comparison-of-kernel-based-classifiers}. (GP stands for “Gaussian process”, which we discuss in Chapter 15 TODO.) The columns have the following meaning:\n\\begin{itemize}\n\\item{Optimize $\\vec{w}$: a key question is whether the objective $J(\\vec{w}=-\\log p(\\mathcal{D}|\\vec{w})-\\log p(\\vec{w}))$ is convex or not. L2VM, L1VM and SVMs have convex objectives. RVMs do not. GPs are Bayesian methods that do not perform parameter estimation.}\n\\item{Optimize kernel: all the methods require that one “tune” the kernel parameters, such as the bandwidth of the RBF kernel, as well as the level of regularization. For methods based on Gaussians, including L2VM, RVMs and GPs, we can use efficient gradient based optimizers to maximize the marginal likelihood. For SVMs, and L1VM, we must use cross validation, which is slower (see Section \\ref{sec:SVM-Choosing-C}).}\n\\item{Sparse: L1VM, RVMs and SVMs are sparse kernel methods, in that they only use a subset of the training examples. GPs and L2VM are not sparse: they use all the training examples. The principle advantage of sparsity is that prediction at test time is usually faster. In addition, one can sometimes get improved accuracy.}\n\\item{Probabilistic: All the methods except for SVMs produce probabilistic output of the form $p(y|\\vec{x})$. SVMs produce a “confidence” value that can be converted to a probability, but such probabilities are usually very poorly calibrated (see Section 14.5.2.3 TODO).}\n\\item{Multiclass: All the methods except for SVMs naturally work in the multiclass setting, by using a multinoulli output instead of Bernoulli. The SVM can be made into a multiclass classifier, but there are various difficulties with this approach, as discussed in Section 14.5.2.4 TODO.}\n\\item{Mercer kernel: SVMs and GPs require that the kernel is positive definite; the other techniques do not.}\n\\end{itemize}\n\n\\begin{table}\n\\centering\n\\begin{tabular}{llllllll}\n\\hline\\noalign{\\smallskip}\nMethod & Opt. \\vec{w} & Opt. & Sparse & Prob. & Multiclass & Non-Mercer & Section \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\nL2VM & Convex & EB & No & Yes & Yes & Yes & 14.3.2 \\\\\nL1VM & Convex & CV & Yes & Yes & Yes & Yes & 14.3.2 \\\\\nRVM & Not convex & EB & Yes & Yes & Yes & Yes & 14.3.2 \\\\\nSVM & Convex & CV & Yes & No & Indirectly & No & 14.5 \\\\\nGP & N/A & EB & No & Yes & Yes & No & 15 \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\caption{Comparison of various kernel based classifiers. EB = empirical Bayes, CV = cross validation. See text for details}\\label{tab:Comparison-of-kernel-based-classifiers}\n\\end{table}\n\n\n\\section{Kernels for building generative models}\nTODO\n", "meta": {"hexsha": "54ef434b498aa88b776fc1f486a54d9db4409547", "size": 33135, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mlapp/chapterKernels.tex", "max_stars_repo_name": "Alexoner/Statistical-formula", "max_stars_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-02-15T17:00:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-24T13:46:00.000Z", "max_issues_repo_path": "mlapp/chapterKernels.tex", "max_issues_repo_name": "Alexoner/Statistical-formula", "max_issues_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mlapp/chapterKernels.tex", "max_forks_repo_name": "Alexoner/Statistical-formula", "max_forks_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-02-25T15:40:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-25T04:26:03.000Z", "avg_line_length": 66.27, "max_line_length": 735, "alphanum_fraction": 0.7253659273, "num_tokens": 10242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.7033314526798006}}
{"text": "\\chapter{Scattering theory}\n\\section{The scattering cross section}\nA parallel beam of particle of given momentum is directed towards a target which deflects or scatters the particle in various directions.The scattered particles diverge. Eventually at large distance from the target, their motion is directed radially outwards.It is convenient to choose a system with the origin at the position of the target or scattering center. and with Z-axis in the direction of the incident beam .The direction of any scattered particle is indicated by polar angles ($\\theta, \\phi$) with the z-axis taken as the polar axis.Then $\\theta$ is the angle of scattering ie the angle between the scattered and the incident direction .These two directions together define the plane of scattering .The azimuthal angle $\\phi$ specifies the orientation of the this plane with respect to some reference plane containing z-axis.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm,width=8cm]{diagram-20220131-crop}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\n\\par Let the incident flux F is independent of time.There will then be steady stream of particles too.Let $\\Delta N$ be the number of particles scattered in to a small solid angle $\\Delta \\Omega$ about the direction $(\\theta \\phi)$ in time $\\Delta t$.Evidently \n$\\Delta N$ must be proportional to $\\Delta \\Omega \\Delta t$ and to the incident flux F.The proportionality factor which depends in general on $\\theta$ and $\\phi$ is called the differential scattering cross section, and is denoted by ($\\frac{d\\sigma}{d\\Omega}$)\\\\\n$$ \\Delta N=\\frac{d\\sigma(\\theta,\\phi)}{d\\Omega}\\Delta t \\Delta \\Omega F$$\n$\\frac{d\\sigma}{d\\Omega}$ has a dimension of area,it depends only on the parameters of the incident particle and nature of the target.\\\\\nThe total scattering crosssection $\\sigma$ may be obtained from it by integration over all directions:\\\\\n$$\\sigma=\\int (\\frac{d\\sigma}{d\\Omega})d\\Omega=\\int_{0}^{2\\pi}\\int_{0}^{\\pi}(\\frac{d\\sigma}{d\\Omega})\\sin \\theta d\\theta d\\phi$$\nIn most cases we consider ($\\frac{d\\sigma}{d\\Omega}$) is independent of $\\phi$\\\\\nThen $$\\sigma=\\int (\\frac{d\\sigma}{d\\Omega}) 2\\pi \\sin \\theta d \\theta$$\n\\subsection{The scattering amplitude}\nWhen the particle involved in the scattering process are quantum mechanical objects ,we must describe them by a wave function.At large distance from the scattering centre ($r\\rightarrow \\infty$) the form of the wavefunction must consist of a part $u_{inc}$ corresponding to the parallel beam of incident particles and the other part $u_{sc}$ representing the scattered particle moving radially outwards from the center.\\\\\n$$u(\\mathbf{x}) \\underset{r \\rightarrow \\infty}{\\longrightarrow} u_{i n c}+u_{s c}$$\nThe beam of incident particles with momentum $p=\\hbar k$ along the $z$-axis must evidently be described by the plane wave (momentum eigenfunction) $u_{i n c}=e^{i k z}$.\\\\\n $\\left\\lfloor\\left. u_{\\text {inc }}\\right|^{2}\\right.$ is to be understood as the number of incident particles per unit volume. The incident flux is obtained by multiplying this quantity by the particle velocity $v$.\n$$\nF=\\left|u_{\\text {inc }}\\right|^{2} v=\\hbar k / m\n$$ \nSuppose that the scattering is elastic. Then the wave $u_{s c}$ representing them must have the same propagation constant $k_{i}$ but it must be a spherical wave since these particles move radially. The only such waves are $e^{i k r}$ and $e^{-i k r}$; the latter is an incoming wave (contracting towards the origin). Since the scattercd particles move outwards, we must choose the outgoing wave $_{2} u_{s c} \\propto e^{i k r}$. Further, the flux of scattered particles, $\\left|u_{s c}\\right|^{2}(\\hbar k / m)$ must evidently decrease as $\\left(1 / r^{2}\\right)$ as $r$ increases. Hence $u_{s c} \\propto(1 / r)$ also, and we writê\n$$\nu_{s c}=f(\\theta, \\varphi) \\frac{e^{i k r}}{r}\n$$\nThe dependence of the proportionality factor $f$ on $\\theta, \\varphi$ allows for the fact that the scattered flux is, in gencral, direction-dependent. We observe now that $\\triangle \\mathcal{N}$ is nothing but the radial flux times $\\triangle S \\Delta t$, where $\\Delta S \\equiv r^{2} d \\Omega$ is the element of area (normal to the radial direction) covered by the solid angle $\\Delta \\Omega$. Thus\n$$\n\\begin{aligned}\n\\Delta \\mathcal{N} &=\\left|u_{s c}\\right|^{2}(\\hbar k / m) \\cdot r^{2} \\Delta \\Omega \\Delta t \\\\\n&=|f(\\theta, \\varphi)|_{0}^{2}(\\hbar k / m) \\Delta \\Omega \\Delta t\n\\end{aligned}\n$$\nOn substituting this together with $F=\\frac{\\hbar k}{m}$ in $ \\Delta N=\\frac{d\\sigma(\\theta,\\phi)}{d\\Omega}\\Delta t \\Delta \\Omega F$, we obtain\\\\\n$$\\frac{d \\sigma(\\theta, \\varphi)}{d \\Omega}=|f(\\theta, \\varphi)|^{2}$$\n\\textbf{$f(\\theta, \\varphi) \\text { is called the scattering amplitude. }$}\\\\\nThe particular stationary  wavefunction can be written as \\\\\n$$u(\\mathbf{x}) \\underset{r \\rightarrow \\infty}{\\longrightarrow} e^{i k z}+f(\\theta, \\varphi) \\frac{e^{i k r}}{r}$$\nSince any stationary wave function must satisfy the time independent Schrcdinger equation, we must have\n$$\n-\\frac{\\hbar^{2}}{2 m} \\nabla^{2} u(\\mathbf{x})+V(\\mathbf{x}) u(\\mathbf{x})=E u(\\mathbf{x}), \\quad E=\\frac{\\hbar^{2} k^{2}}{2 m}\n$$\nHere $V(\\mathbf{x})$ is the potential energy function for the projectile particle in the force field of the scattering centre. \\\\\n\\textbf{Formal expression for scattering amplitude}\n$$\\begin{aligned}\n\tf(\\theta, \\varphi) &=-\\frac{1}{4 \\pi} \\int e^{-i \\mathbf{k} \\cdot \\mathbf{x}} U(\\mathbf{x}) u(\\mathbf{x}) d \\tau, \\\\\n\t&=-\\frac{m}{2 \\pi \\hbar^{2}} \\int e^{-i \\mathbf{k} \\cdot \\mathbf{x}} V(\\mathbf{x}) u(\\mathbf{x}) d \\tau\n\\end{aligned}$$\n\\subsection{First Born approximation}\n$$f(\\theta, \\varphi)=-\\frac{1}{4 \\pi} \\int e^{-i \\mathbf{k} \\cdot \\mathbf{x}} U(\\mathbf{x}) u(\\mathbf{x}) d \\tau$$\nSuppose that $\\left|u(\\mathbf{x})-e^{i k z}\\right|<\\left|e^{i k z}\\right|=1$\\\\\nThen we can replace the unknown $u(\\mathbf{x})$ in $f(\\theta, \\varphi)$ to a good approximation, by $e^{i k z} \\equiv e^{t \\mathbf{k}_{0} \\cdot \\mathbf{x}}$ where $k_{0}$ is the vector of magnitude $k$ in the incident direction. The resulting expression is called the \\textbf{first Born approximation} to $f(\\theta, \\varphi)$ and is given by\n$$\nf_{\\mathrm{H}}(\\theta, \\varphi)=-(4 \\pi)^{-1} \\int e^{-i \\mathbf{K} \\cdot \\mathbf{x}} U(\\mathbf{x}) d \\tau \\text {. }\n$$\nThe scattering. cross-scction in this approximation is\n$$\n\\left(\\frac{d \\sigma}{d \\Omega}\\right)_{\\mathrm{B}}=(4 \\pi)^{-2}\\left|\\int e^{-i} \\mathbf{K} \\cdot \\mathbf{x} U(\\mathbf{x}) d \\tau\\right|^{2} .\n$$\nIn equation $f_{\\mathrm{H}}(\\theta, \\varphi)$  $\\mathbf{K}=\\mathbf{k}- \\mathbf{k}_{0}$. It may be noted that $\\hbar \\mathbf{K}$ is the momentum transferred to the particle in its encounter with the potential. Since $\\left|k_{0}\\right|=|\\mathbf{k}|$ $=k$, it follows (from the figure )that\n$$K \\equiv|\\mathbf{K}|=2 k \\sin \\frac{1}{2} \\theta$$\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=5cm]{nimi1-crop}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\nThe scattcring amplitude in the Born approximation, considered as ifunction of $\\mathrm{K}$ : is the Fourier transform of the potcntial (apart from constant facturs;)\\\\\nIn the most important special case when V is sphcrically symmetric, $V(\\mathbf{x})$ - V $(r)$, we can reduce $\nf_{\\mathrm{H}}(\\theta, \\varphi)$ to an integral over $r$ alone, by going over to spherical polar coordinates $(r, \\alpha, \\beta)$ with the direction of $\\mathbf{K}$ chosen as the polar axis. Then $\\mathbf{K} . \\mathbf{x}=K_{r} \\cos \\alpha$ and on carrying out the angular integrations one $\\operatorname{gcts}$\n$$\nf_{B}(\\theta)=-K^{-1} \\int_{0}^{\\infty} r \\sin K r U(r) d r\n$$\n\\subsection{Partial wave analysis}\nWhile the Born approximation is basically a truncation of a perturbation expansion of $u(x)$, the method of partial waves is based upon an expansion of $u(\\mathbf{x})$ in terms of angular momentum eigenfunctions. It is applicable if the potential is spherically symmetric. one gets a fornial expression for the scattering amplitude as an infinite scries; cach term of the series is the contribution to $f(\\theta, \\varphi)$ from a partial wave characterized by a particular angular momentum. We shall see that the first few terms in the series approximate $f(\\theta, \\varphi)$ if the incident particle is of low energy. Thus the partial wave method leads to a low energy approximation which complements the Born approximation (good at high energies).\n\\subsubsection{Partial waves}\nIf the potential has sphencal symmetry we can separate the Schrödinger equation into radial and angular parts, and obtain solutions in the form $R_{l}(r) Y_{l m}{(\\theta, \\varphi)}$, where the radial wave functions $R_{l}(r)$ satisfy the equation\n$$\n1/r^2 \\frac{d}{dr}\\left(r^{2} \\frac{d R_l}{d r}\\right)+\\frac{2 \\mu}{\\hbar^{2}}\\left[E-V-\\frac{l(l+1) \\hbar^{2}}{2 \\mu r^{2}}\\right] R_l=0\n$$\nThe general solution of the Schrödinger equation can be written as a linear combination of such solutions. In the scattering problem which we are considering, only the function $R_{l}(r) \\bar{\\gamma}_{l o}(\\theta, \\varphi) \\propto R_{l}(r) P_{l}(\\cos \\theta)$ appears in the linear combination. This is because we have assumed the particle to be travelling in the $z$-direction initially, so that the $z$-component of its angular momentum is zero; it continues to be zero because a spherically symmetric potential does not disturb the angular momentum. Thus we can write\n$$\nu(\\mathbf{x})=\\sum_{l=0}^{\\infty} R_{l}(r) P_{l}(\\cos \\theta)\n$$\nThe term corresponding to a particular $l$ in this series is called the lth partial wave.\\\\\n\\textbf{Asymptotic form of radial function}\\\\\n We must now require that $u(\\mathbf{x})$ should have the asymptotic form of$u(\\mathbf{x}) \\underset{r \\rightarrow \\infty}{\\longrightarrow} e^{i k z}+f(\\theta, \\varphi) \\frac{e^{i k r}}{r}$ \\\\\n  This condition places constraints on the radial wave functions $R l(r)$. To see what they are, we need to have the asymptotic $(r \\rightarrow \\infty)$ form of $R_{l}(r)$. We can infer it from the radial wave equation  which we rewrite as\n$$\n\\left.\\begin{array}{l}\n\\frac{d^{2} \\chi_{l}}{d r^{2}}+\\left[k^{2}-U(r)-\\frac{l(l+1)}{r^{2}}\\right] \\chi_{l}=0, \\\\\n\\chi_{l}=r R_{l}(r), k^{2}=\\left(2 m E / \\hbar^{2}\\right), U(r)=2 m V / \\hbar^{2}\n\\end{array}\\right\\}\n$$\nIn the asymptotic region, both $U(r)$ and the centrifugal potential $\\left(\\propto 1 / r^{2}\\right)$ are very small. On neglecting these, in comparison with $k^{2}$, we obtain the approximate asymptotic solution $\\chi_{l}(r) \\propto e^{\\pm i k r}$. To improve this approximation, let us suppose that\n$$\\chi_{l}(r)=v_{l}(r) e^{\\pm i k r}$$\nwhere $v_{l}(r)$ is expected to be very slowly varying in the asymptotic region. On introducing this into Eq in to new radial equation we get\n$$\nd^{2} v_{l} / d r^{2} \\pm 2 i k d v_{l} / d r-\\left[U+l(l+1) / r^{2}\\right] v_{l}=0\n$$\non solving this we will get\\\\\n$$\\ln v_{l} \\approx \\mp \\frac{i}{2 k} \\int^{r}\\left[U+\\frac{l(l+1)}{r^{2}}\\right] d r$$\n\\textcolor{red}{some text missing} if $1/r$ is large enough the value of the integral is effectively independent of $r$ and hence $v_{l}(r)$ is a constant in the asymptotic region. In the following, we will confine our attention to such potentials, leaving the Coulomb case to be dealt with later. Then the asymptotic form of $\\chi_{l}(r)$ is, in general, some linear combination of the two solutions with $v_{l}$ constant, i.e. of $e^{i k r}$ and $e^{-ikr}$. Without loss of generality, we can write any such combination in the form\\\\\n$${\\chi}_{l} \\rightarrow C_{l} \\sin \\left(k r+\\Delta_{l}\\right)$$\n$\\text { where } C_{l}, \\Delta_{l} \\text { are constants. }$\\\\\n\\textbf{Phase shift}\\\\\n Let us compare the above asymptotic behaviour with that of the partial waves for a free particle $\\left(V^{\\prime}(r)=0\\right)$. We have already seen  that in any range of $r$ over which $V(r)$ is constant, the solutions of the radial wave equation are the spherical Bessel functions $j_{l}$ or $n_{l}$. In particular, if $V=0$ everywhere, the only admissible solution is $j_{l}(k r) ; n_{l}$ is ruled out because it becomes infinite at $r=0$. Thus $R_{l}(r)=$ const. $j_{l}(k r)$ in the free-particle case. Since the asymptotic forms of the spherical Bessel functions are known to be given by\n $$\\begin{aligned}\n \t&j_{l}(k r) \\rightarrow(k r)^{-1} \\sin \\left(k r-\\frac{1}{2} l \\pi\\right) \\\\\n \t&n_{l}(k r) \\rightarrow-(k r)^{-1} \\cos \\left(k r-\\frac{1}{2} l \\pi\\right)\n \\end{aligned}$$\n (as $r \\rightarrow \\infty$ ), it follows tha $\\chi_{l}(r)=r R_{l}(r) \\rightarrow$ const. $\\sin \\left(k r-\\frac{1}{2} l \\pi\\right)$. Hence $\\chi_{l}$ in this case has the asymptotic form ${\\chi}_{l} \\rightarrow C_{l} \\sin \\left(k r+\\Delta_{l}\\right)$ with the particular value $-\\frac{1}{2} l \\pi$ for $\\Delta_{l}$.\\\\\n The effect of the potential on the partial waves in the asymptotic region is, therefore, simply to change the phase from - $\\frac{1}{2} \\pi l$ to some other value $\\triangle_{l}$. This change,\n $$\n \\delta_{l}=\\Delta_{l}+\\frac{1}{2} l \\pi\n $$\n is called the phase shift in the lth partial wave.\n \\newpage\n \\begin{abox}\n \tPractice set 1\n \t\\end{abox}\n \\begin{enumerate}\n \t\\begin{minipage}{\\textwidth}\n \t\\item A free particle described by a plane wave and moving in the positive $z$-direction undergoes scattering by a potential\n \t$$\n \tV(r)= \\begin{cases}V_{0}, & \\text { if } r \\leq R \\\\ 0, & \\text { if } r>R\\end{cases}\n \t$$\n \tIf $V_{0}$ is changed to $2 V_{0}$, keeping $R$ fixed, then the differential scattering cross-section, in the Born approximation.\n \t\\exyear{NET JUNE 2012}\n \\end{minipage}\n \\begin{tasks}(2)\n \t\\task[\\textbf{A.}]increases to four times the original value\n \t\\task[\\textbf{B.}]increases to twice the original value\n \t\\task[\\textbf{C.}]decreases to half the original value\n \t\\task[\\textbf{D.}]decreases to one fourth the original value\n \\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The differential cross-section for scattering by a target is given by\n\t$$\n\t\\frac{d \\sigma}{d \\Omega}(\\theta, \\phi)=a^{2}+b^{2} \\cos ^{2} \\theta\n\t$$\n\tIf $N$ is the flux of the incoming particles, the number of particles scattered per unit time is\n\t\\exyear{NET JUNE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{4 \\pi}{3} N\\left(a^{2}+b^{2}\\right)$\n\t\\task[\\textbf{B.}]$4 \\pi N\\left(a^{2}+\\frac{1}{6} b^{2}\\right)$\n\t\\task[\\textbf{C.}]$4 \\pi N\\left(\\frac{1}{2} a^{2}+\\frac{1}{3} b^{2}\\right)$\n\t\\task[\\textbf{D.}]$4 \\pi N\\left(a^{2}+\\frac{1}{3} b^{2}\\right)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle of energy $E$ scatters off a repulsive spherical potential\n\t$$\n\tV(r)=\\left\\{\\begin{array}{ccc}\n\tV_{0} & \\text { for } & r<a \\\\\n\t0 & \\text { for } & r \\leq a\n\t\\end{array}\\right.\n\t$$\n\twhere $V_{0}$ and $a$ are positive constants. In the low energy limit, the total scattering crosssection is $\\sigma=4 \\pi a^{2}\\left(\\frac{1}{k a} \\tanh k a-1\\right)^{2}$, where $k^{2}=\\frac{2 m}{h^{2}}\\left(V_{0}-E\\right)>0$. In the limit $V_{0} \\rightarrow \\infty$ the ratio of $\\sigma$ to the classical scattering cross-section off a sphere of radius $a$ is\n\t\\exyear{NET JUNE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] 4\n\t\\task[\\textbf{B.}]3\n\t\\task[\\textbf{C.}]1\n\t\\task[\\textbf{D.}]$\\frac{1}{2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A particle is scattered by a central potential $V(r)=V_{0} r e^{-\\mu r}$, where $V_{0}$ and $\\mu$ are positive constants. If the momentum transfer $\\vec{q}$ is such that $q=|\\vec{q}| \\gg \\mu$, the scattering crosssection in the Born approximation, as $q \\rightarrow \\infty$, depends on $q$ as\n\t[You may use $\\left.\\int x^{n} e^{a x} d x=\\frac{d^{n}}{d a^{n}} \\int e^{a x} d x\\right]$\n\t\\exyear{NET DEC 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]$q^{-8}$\n\t\\task[\\textbf{B.}]$q^{-2}$\n\t\\task[\\textbf{C.}]$q^{2}$\n\t\\task[\\textbf{D.}]$q^{6}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider the potential\n\t$$\n\tV(\\vec{r})=\\sum_{i} V_{0} a^{3} \\delta^{(3)}\\left(\\vec{r}-\\vec{r}_{i}\\right)\n\t$$\n\twhere $\\vec{r}_{i}$ are the position vectors of the vertices of a cube of length $a$ centered at the origin and $V_{0}$ is a constant. If $V_{0} a^{2}<<\\frac{\\hbar^{2}}{m}$, the total scattering cross-section, in the lowenergy limit, is\n\t\\exyear{NET JUNE 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $16 a^{2}\\left(\\frac{m V_{0} a^{2}}{\\hbar^{2}}\\right)$\n\t\\task[\\textbf{B.}]$\\frac{16 a^{2}}{\\pi^{2}}\\left(\\frac{m V_{0} a^{2}}{\\hbar^{2}}\\right)^{2}$\n\t\\task[\\textbf{C.}]$\\frac{64 a^{2}}{\\pi}\\left(\\frac{m V_{0} a^{2}}{\\hbar^{2}}\\right)^{2}$\n\t\\task[\\textbf{D.}]$\\frac{64 a^{2}}{\\pi^{2}}\\left(\\frac{m V_{0} a^{2}}{\\hbar^{2}}\\right)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A phase shift of $30^{\\circ}$ is observed when a beam of particles of energy $0.1 \\mathrm{MeV}$ is scattered by a target. When the beam energy is changed, the observed phase shift is $60^{\\circ}$. Assuming that only $s$-wave scattering is relevant and that the cross-section does not change with energy, the beam energy is\n\t\\exyear{NET DEC 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $0.4 \\mathrm{MeV}$\n\t\\task[\\textbf{B.}]$0.3 \\mathrm{MeV}$\n\t\\task[\\textbf{C.}]$0.2 \\mathrm{MeV}$\n\t\\task[\\textbf{D.}]$0.15 \\mathrm{MeV}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The differential scattering cross-section $\\frac{d \\sigma}{d \\Omega}$ for the central potential $V(r)=\\frac{\\beta}{r} e^{-\\mu r}$, where $\\beta$ and $\\mu$ are positive constants, is calculated in thee first Born approximation. Its dependence on the scattering angle $\\theta$ is proportional to ( $A$ is a constant below)\n\t\\exyear{NET JUNE 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\left(A^{2}+\\sin ^{2} \\frac{\\theta}{2}\\right)$\n\t\\task[\\textbf{B.}]$\\left(A^{2}+\\sin ^{2} \\frac{\\theta}{2}\\right)^{-1}$\n\t\\task[\\textbf{C.}]$\\left(A^{2}+\\sin ^{2} \\frac{\\theta}{2}\\right)^{-2}$\n\t\\task[\\textbf{D.}]$\\left(A^{2}+\\sin ^{2} \\frac{\\theta}{2}\\right)^{2}$\n\\end{tasks}\n \\end{enumerate}\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{a}&2&\\textbf{d}\\\\\\hline\n\t\t3&\\textbf{a}&4&\\textbf{a}\\\\\\hline\n\t\t5&\\textbf{c}&6&\\textbf{b}\\\\\\hline\n\t\t7&\\textbf{c}&&\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\\newpage\n\\begin{abox}\n\tPractice set 2 \n\t\\end{abox}\n\\begin{enumerate}\n\t\t\\begin{minipage}{\\textwidth}\n\t\t\\item Find the angular distribution and total cross section for the scattering of small marbles of mass $m$ and radius $r$ from a massive billiard ball of mass $M$ and radius $R(m<<M)$.\n\t\tYou should treat the scattering as elastic involving no frictional forces.\n\t\\end{minipage}\n\t\\begin{answer}\n\t\t\\begin{minipage}{0.5\\textwidth}\n\t\t As $m \\ll M$, the massive billiard ball will remain stationary during scattering. As the scattering is elastic (see figure), the scattering angle $\\Theta$ is related to the angle of incidence by\\\\\n\t\t$\n\t\t\\theta=\\pi-2 \\alpha \\Rightarrow \\alpha=\\frac{\\pi}{2}-\\frac{\\theta}{2}\n\t\t$\n\t\t\\end{minipage}\n\t\\begin{minipage}{0.5\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20220213-20220213123239-crop}\n\t\\end{figure}\n\t\\end{minipage}\n\n\t\t\t$$\\text { where } \\theta \\text { is given by }(R+r) \\sin \\alpha=b \\Rightarrow b=(R+r) \\sin \\left(\\frac{\\pi}{2}-\\frac{\\theta}{2}\\right) \\Rightarrow b=(R+r) \\cos \\frac{\\theta}{2}$$\n\t\t\tThe differential scattering cross section is\n\t\t\t\\begin{align*}\n\t\t\t&D(\\theta)=\\frac{d \\sigma}{d \\Omega}=\\frac{b}{\\sin \\theta}\\left|\\frac{d b}{d \\theta}\\right|=\\frac{(R+r) \\cos \\frac{\\theta}{2}}{\\sin \\theta} \\cdot(R+r) \\sin \\frac{\\theta}{2} \\cdot \\frac{1}{2}=\\frac{(R+r)^{2}}{4} \\\\\n\t\t\t&\\Rightarrow D(\\theta)=\\frac{d \\sigma}{d \\Omega}=\\frac{(R+r)^{2}}{4}\\\\\n\t\t\t&\\sigma=\\int_{0}^{\\pi} \\int_{0}^{2 \\pi} D(\\theta) \\sin \\theta d \\theta d \\phi \\Rightarrow \\int_{0}^{\\pi} \\int_{0}^{2 \\pi} \\frac{(R+r)^{2}}{4} \\sin \\theta d \\theta d \\phi=\\pi(R+r)^{2}\n\t\t\t\\end{align*}\t\n\t\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item If differential scattering cross-section is given by $D(\\theta)=a^{2} \\sin ^{2} \\theta+b^{2} \\cos ^{2} \\theta$. If $N$ is the flux of incoming particle then find the number of scattered particle per unit time.\n\\end{minipage}\n\\begin{answer}\n\t\\begin{align*}\n\t&\\sigma=\\int_{0}^{\\pi} \\int_{0}^{2 \\pi} D(\\theta) \\sin \\theta d \\theta d \\phi\\\\\n\t\t\\sigma &=\\int_{0}^{\\pi} \\int_{0}^{2 \\pi} a^{2} \\sin ^{2} \\theta \\sin \\theta d \\theta d \\phi+\\int_{0}^{\\pi} \\int_{0}^{2 \\pi} b^{2} \\cos ^{2} \\theta \\sin \\theta d \\theta d \\phi \\\\\n\t\t&=2 \\pi\\left(a^{2} \\int_{0}^{\\pi} \\sin ^{3} \\theta d \\theta+b^{2} \\int_{0}^{\\pi} \\cos ^{2} \\theta \\sin \\theta d \\theta\\right) \\\\\n\t\t\\sigma &=2 \\pi\\left(\\frac{4}{3} a^{2}+\\frac{2}{3} b^{2}\\right) \\Rightarrow \\sigma=\\frac{4 \\pi}{3}\\left(2 a^{2}+b^{2}\\right)\n\t\\end{align*}\n\t$\\text { Number of scattered particle } N_{S C}=N \\sigma \\Rightarrow N_{S C}=N \\frac{4 \\pi}{3}\\left(2 a^{2}+b^{2}\\right)$\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item Yukawa potential is defined as $V(r)=\\beta \\frac{e^{-\\mu r}}{r}$ where $\\beta>0$ and $\\mu>0$.\\\\\n\t(a) Using born approximation for for high energy $k=\\sqrt{\\frac{2 m E}{\\hbar^{2}}}$ if $\\theta$ is scattering angle with parameter $q=2 k \\sin \\theta / 2$ find differential scattering cross section\\\\\n\t(b) Discuss the differential scattering cross section for case $q \\gg \\mu$\n\\end{minipage}\n\\begin{answer}\n\t$\\text { (a) } f(\\theta)=-\\frac{2 m}{\\hbar^{2} q} \\int_{0}^{\\infty} r V(r) \\sin (q r) d r$\n\t\\begin{align*}\n\t\t&=\\frac{-2 m \\beta}{\\hbar^{2} q} \\int_{0}^{\\infty} e^{-\\mu r} \\sin (q r) d r=\\frac{-2 m \\beta}{\\hbar^{2} q} \\frac{1}{2 i} \\int_{0}^{\\infty} e^{-\\mu r} \\exp i q r-\\exp (-i q r) d r \\\\\n\t\t&\\frac{-2 m \\beta}{\\hbar^{2} q} \\frac{1}{2 i}\\left(\\int_{0}^{\\infty} \\exp -r(\\mu-i q) d r-\\int_{0}^{\\infty} \\exp -r(\\mu+i q) d r\\right)=-\\frac{m \\beta}{i \\hbar^{2} q}\\left(\\frac{1}{\\mu-i q}-\\frac{1}{\\mu+i q}\\right) \\\\\n\t\t&=-\\frac{m \\beta}{i \\hbar^{2} q}\\left(\\frac{(\\mu+i q)-(\\mu-i q)}{\\mu^{2}+q^{2}}\\right)=-\\frac{2 m \\beta q}{\\hbar^{2} q} \\cdot \\frac{1}{\\mu^{2}+q^{2}}=-\\frac{2 m \\beta}{\\hbar^{2}} \\cdot \\frac{1}{\\mu^{2}+q^{2}} \\\\\n\t\t&D(\\theta)=|f(\\theta)|^{2}=\\left|-\\frac{2 m \\beta}{\\hbar^{2}} \\cdot \\frac{1}{\\mu^{2}+q^{2}}\\right|^{2}=\\frac{4 m^{2} \\beta^{2}}{\\hbar^{4}} \\cdot\\left(\\frac{1}{\\mu^{2}+q^{2}}\\right)^{2}\n\t\\end{align*}\n\t(b) for case $q>>\\mu$\n\t$$\n\tD(\\theta)=\\frac{4 m^{2} \\beta^{2}}{\\hbar^{4}} \\cdot \\frac{1}{q^{4}}\\left(\\frac{1}{(\\mu / q)^{2}+1}\\right)^{2}=\\frac{4 m^{2} \\beta^{2}}{\\hbar^{4}} \\cdot \\frac{1}{q^{4}}\n\t$$\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item A particle of energy $E$ scatters off a repulsive spherical potential\n\t$$\n\tV(r)=\\left\\{\\begin{array}{ccc}\n\tV_{0} & \\text { for } & r<a \\\\\n\t0 & \\text { for } & r \\leq a\n\t\\end{array}\\right.\n\t$$\n\twhere $V_{0}$ and $a$ are positive constants. In the low energy limit, the total scattering crosssection is $\\sigma=4 \\pi a^{2}\\left(\\frac{1}{k a} \\tanh k a-1\\right)^{2}$, where $k^{2}=\\frac{2 m}{h^{2}}\\left(V_{0}-E\\right)>0 .$\\\\\n\t(a) In the limit $V_{0} \\rightarrow \\infty$ find the total scattering cross section.\\\\\n\t(b) Compare the total scattering cross section from (a) to classical scattering cross section Consider the notentiol\n\\end{minipage}\n\\begin{answer}\n\t$\\text { (a) } \\sigma=4 \\pi a^{2}\\left[\\frac{1}{k a} \\tanh k a-1\\right]^{2}$\\\\\n\t$V_{0} \\rightarrow \\infty, k a \\rightarrow \\infty, \\tanh k a \\rightarrow 1 \\Rightarrow \\sigma=4 \\pi a^{2}\\left(\\frac{1}{k a}-1\\right)^{2} \\text { and } k a \\rightarrow \\infty, \\lim _{k a \\rightarrow \\infty} \\sigma=4 \\pi a^{2}$\\\\\n\t$\\text { (b) Classically } \\sigma_{c}=\\pi a^{2}, \\frac{\\sigma}{\\sigma_{c}}=4$\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item Consider the potential\n\t$$\n\tV(x, y, z)=\\sum_{i} V_{0} a^{3} \\delta\\left(x-x_{i}\\right) \\delta\\left(y-y_{i}\\right) \\delta\\left(z-z_{i}\\right)\n\t$$\n\twhere $x_{i}, y_{i}, z_{i}$ are the position vectors of the vertices of a cube of length $a$ centered at the origin and $V_{0}$ is a constant. If $V_{0} a^{2}<<\\frac{\\hbar^{2}}{m}$ for low energy limit\\\\\n\t(a) Find differential cross section .\\\\\n\t(b) The total scattering cross-section\n\\end{minipage}\n\\begin{answer}\n\t $\\sum_{i} V_{0} a^{3} \\delta\\left(x-x_{i}\\right) \\delta\\left(y-y_{i}\\right) \\delta\\left(z-z_{i}\\right)$, where $x_{i}, y_{i}, z_{i}$ are co-ordinate at 8 corner cube whose center is at origin.\\\\\n\t \\begin{align*}\n\t \tf(\\theta) &=-\\frac{m}{2 \\pi \\hbar^{2}} \\int V(r) d^{3} r \\\\\n\t \t&=\\frac{-m}{2 \\pi \\hbar^{2}} V_{0} a^{3} \\iint_{-\\infty}^{\\infty} \\int \\sum_{i=1}^{8} \\delta\\left(x-x_{i}\\right) \\delta\\left(y-y_{i}\\right) \\delta\\left(z-z_{i}\\right) d x d y d z \\\\\n\t \t&=\\frac{-m}{2 \\pi \\hbar^{2}} V_{0} a^{3}[1+1+1+1+1+1+1+1] \\\\\n\t \t&=\\frac{-8 m V_{0} a^{3}}{2 \\pi \\hbar^{2}}=\\frac{-4 m V_{0} a^{3}}{\\pi \\hbar^{2}}\n\t \\end{align*}\n\t $\\text { Differential scattering cross section } D(\\theta)=|f(\\theta)|^{2}=\\frac{16 m^{2} V_{0}^{2} a^{6}}{\\pi^{2} \\hbar^{4}}$\\\\\n\t (b) Total scattering cross section $\\sigma=\\int|f(\\theta)|^{2} \\sin \\theta d \\theta d \\phi$.\n\t \\begin{align*}\n\t &=\\frac{16 m^{2} V_{0}^{2} a^{6}}{\\pi^{2} \\hbar^{4} \\cdot 4 \\pi}=\\frac{64 a^{2}}{\\pi}\\left(\\frac{m^{2} V_{0}^{2} a^{4}}{h^{4}}\\right) \\\\\n\t \\sigma &=\\frac{64 a^{2}}{\\pi}\\left(\\frac{m V_{0} a^{2}}{\\hbar^{2}}\\right)^{2}\n\t \\end{align*}\n\\end{answer}\n\n\\end{enumerate}", "meta": {"hexsha": "20f06a0394bfa5e13be9cf625e136e4ba38bbcab", "size": 25278, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "QM -CSIR/chapter/scattering theory.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "QM -CSIR/chapter/scattering theory.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "QM -CSIR/chapter/scattering theory.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 75.0089020772, "max_line_length": 838, "alphanum_fraction": 0.6635809795, "num_tokens": 9039, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029117, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7033123917300891}}
{"text": "\\lab{NumPy and SciPy}{NumPy and SciPy} \n\\objective{Create and manipulate NumPy arrays and learn features available in NumPy and SciPy.}\n\\label{lab:NumPyArrays}\n\n\\section*{Introduction}\n\nNumPy and SciPy\\footnote{SciPy is also the name of a Python coding environment that includes the NumPy and SciPy libraries, as well as IPython, matplotlib, and other tools.} \nare the two Python libraries most used for scientific computing. \nNumPy is a package for manipulating vectors and arrays, and SciPy is a higher-level library built on NumPy. \nThe basic object in NumPy is the \\emph{array}, which is conceptually similar to a matrix. \nHowever, unlike a matrix, which has two dimensions, a NumPy \\li{array} can have arbitrarily many dimensions. \nNumPy is optimized for fast array computations.\n\nThe convention is to import NumPy as follows.\n\n\\begin{lstlisting}\n>>> import numpy as np\n\\end{lstlisting}\n\n\\section*{Learning NumPy}\nThe strategies discussed in the section ``Learning Python'' of Lab \\ref{lab:Essential_Python} will also help you learn NumPy and SciPy. \nThe following online resources are specific to SciPy.\n\\begin{itemize}\n\\item Official SciPy Documentation (\\url{http://docs.scipy.org/doc/})\n\\item Sections 1.3 and 1.5 of the SciPy Lecture Notes (\\url{http://scipy-lectures.github.io/})\n\\end{itemize}\nThe remainder of this lab is a brief summary of the tools available in NumPy and SciPy, beginning with NumPy arrays.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section*{Arrays}\n\nConceptually, a 1-dimensional array (called a 1-D array) is just a list of numbers. \nAn $n$-dimensional array (or $n$-D array) is an array of $(n-1)$-dimensional arrays. \nThus, any 2-D array is conceptually a matrix, and a 3-D array is a list of matrices, which can be visualized as a cube of numbers. \nEach dimension is called an \\emph{axis}. \nWhen a 2-D array is printed to the screen, the 0-axis indexes the rows and the 1-axis indexes the columns.\n\nThe NumPy array class is called \\li{ndarray}. \nThe simplest way to create an \\li{ndarray} is to define it explicitly using nested lists.\n\\begin{lstlisting}\n# Create a 1-D array\n>>> np.array([0, 3, 8, 6, 3.14])\narray([0, 3, 8, 6, 3.14]) \n\n# Create a 2-D array\n>>> ex1 = np.array([[1, 1, 2], [3, 3, 4]])\n>>> ex1\narray([[1, 1, 2],\n       [3, 3, 4]])\n\n\\end{lstlisting} \n\nYou can view the length of each dimension with the \\li{shape} command, and change the shape of an array with the \\li{np.reshape()} function. \nThe number of arguments passed to \\li{reshape} tells NumPy the dimension of the new array, and the arguments specify the length of each dimension. \nAn argument of \\li{-1} tells NumPy to make that dimension as long a necessary.\n\\begin{lstlisting}\n# The 0-axis of ex1 has length 2\n>>> ex1.shape\n(2, 3)\n>>> ex1.reshape(3, 2)\narray([[1, 1],\n       [2, 3],\n       [3, 4]])\n>>> ex1.reshape(-1)\narray([1, 1, 2, 3, 3, 4])\n\\end{lstlisting}\n\nArray objects also support the usual binary operators, including addition \\li{+} and componentwise multiplication \\li{*}.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Why Use Arrays?}\nNumPy arrays are drastically more efficient than nested Python lists for large computations. \nIn this section we will compare matrix multiplication in Python and NumPy.\n\n\\begin{problem}\\label{prob:multiply_problem}\nA matrix in NumPy is just a 2-D array. How can you multiply two 2-D NumPy arrays as matrices? \nHint: Use the strategies outlined in the section ``Learning Numpy''.\n\\end{problem}\n\nAfter doing the previous problem, you should know how to implement matrix multiplication in NumPy. \nOn the other hand, a matrix in Python can be implemented as a list of lists. \nThe following function will multiply two such matrices.\n\n\\lstinputlisting[style=fromfile]{arr_mult.py}\n\nTable \\ref{table:square_times} documents how long\\footnote{You can replicate this experiment yourself. In IPython, you can find the execution time of a line of code by prefacing it with \\li{\\%timeit}. \nIf you aren't using IPython, you will need\nto use the timeit function documented here: \\url{https://docs.python.org/2/library/timeit.html}.} \none computer took to square a $k \\times k$ matrix in both Python (using the function \\li{arr_mult}) and Numpy (using the method you found in Problem \\ref{prob:multiply_problem}) for various values of $k$. \nAs you can see, NumPy is much faster. One reason for this is that algorithms in NumPy are usually implemented in C or Fortran. \n\n\\begin{table}\n \\begin{tabular}{|c|l|l|} \\hline Data Structure & $k$ & Time (s) \\\\ \\hline \n Python List  \t& $10\\times10$ \t& 0.0002758503 \\\\ \n \\cline{2-3} \t& $100\\times100$ \t& 0.1336028576 \\\\ \n \\cline{2-3} \t& $1000\\times1000$ & 200.4009799957 \\\\ \n %& $1\\times1$ \t\t& 0.0000181198 \\\\ \n\\hline \\hline \n NumPy Array \t& $10\\times10$ \t& 0.0000109673 \\\\\n \\cline{2-3} \t& $100\\times100$ \t& 0.0009210110 \\\\ \n \\cline{2-3} \t& $1000\\times1000$ & 2.1682999134 \\\\\n %& $1\\times1$ \t\t& 0.0000298023 \\\\ \n \\hline \\end{tabular}\n \\caption{Time for one computer to square a $k \\times k$ matrix in Python and NumPy.}\n\\label{table:square_times} \n\\end{table}\n \n \n% \n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Data Types}\nUnlike Python containers, a NumPy array requires all its elements to have the same data type. \nThe data types used by NumPy arrays are machine-native and avoid the overhead of Python objects, meaning that they are faster to compute with. \nA NumPy \\li{int} and a Python \\li{int} are not the same; the former has been optimized to speed up numerical computations. \nDatatypes supported by NumPy are shown in Table \\ref{table:numpytypes}.\n\n\\begin{table}\n\\begin{tabular}{l|l} \nData type & Description \n\\\\ \\hline \n\\li{bool} & Boolean \\\\ \n\\li{int8} & 8-bit integer \\\\ \n\\li{int16} & 16-bit integer \\\\ \n\\li{int32} & 32-bit integer \\\\\n\\li{int64} & 64-bit integer \\\\ \n\\li{int} & Platform integer (depends on platform) \\\\ \n\\li{uint8} & Unsigned 8-bit integer \\\\ \n\\li{uint16} & Unsigned 16-bit integer \\\\ \n\\li{uint32} & Unsigned 32-bit integer \\\\\n\\li{uint64} & Unsigned 64-bit integer \\\\ \n\\li{float16} & Half precision float \\\\ \n\\li{float32} & Single precision float \\\\ \n\\li{float64} & Double precision float (also \\li{float}) \\\\ \n\\li{complex64} & Complex number represented by two single precision floats \\\\ \n\\li{complex128} & Complex number represented by two double precision floats (also \\li{complex})\n\\end{tabular} \n\\caption{Native numerical data types available in NumPy.}\n\\label{table:numpytypes} \n\\end{table} \n\nHere are some examples of how to manipulate data types in NumPy.\n\\begin{lstlisting}\n# Access the data type of an array\n>>> ex2 = np.array(range(5))\n>>> ex2.dtype\ndtype('int64')\n\n# Specify the data type of an array\n>>> ex3 = np.array(range(5), dtype=np.float)\n>>> ex3.dtype\ndtype('float64')\n\\end{lstlisting}\n\n\\begin{comment}\nMost floating point numbers cannot be represented perfectly \nas a binary fraction and are thus an approximation when stored. \nConsider the following example where \\li{x_1, x_2, x_3} are all \nincreasingly better approximations of 1/3, but no matter how\nmany more digits you're willing to append, the value will never be \nexactly 1/3. \n\\begin{lstlisting}\n>>> x_1 = .333\n>>> x_2 = .33333\n>>> x_3 = .3333333 \n>>> x_1 == x_2\nFalse\n>>> x_2 == x_3\nFalse\n\\end{lstlisting}\nIt is almost impossible to accurately test the equality\nof elements within two arrays. NumPy provides a special function,\n\\li{np.allclose}, to check if two arrays are \\emph{almost} the same (or\nwithin some specified tolerances). \n\\begin {lstlisting}\n>>> np.allclose(x_1, x_2)\nFalse\n>>> np.allclose(x_1, x_2, .001)\nTrue\n>>> np.allclose(x_2, x_3)\nTrue\n>>> np.allclose(x_2, x_3, .000001)\nFalse\n\\end{lstlisting}\n\\emph{Please note that in some rare\ncases} \\li{np.allclose(a, b)} \\emph{will not match} \\li{np.allclose(b,\na)}. This is because the equation the function uses for checking\ncloseness is not symmetric ($\\abs{a-b} \\leq \\mbox{atol} +\n\\mbox{rtol}*\\abs{b}$). \n\n\n\nNumPy also allows bitwise operations on arrays\nusing the standard Python bitwise operators: \\li{&}, \\li{|}, and \\li{^},\nas well as \\li{&=}, \\li{|=}, and \\li{^=}.\n\\end{comment}\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Creating Arrays}\nIn addition to \\li{np.array()}, NumPy provides efficient ways to create special kinds of arrays. The function \\li{np.arange([start], stop, [step])} is similar to the Python function \\li{range()}.\n\n\\begin{lstlisting}\n>>> np.arange(10, 20, 2) \narray([10, 12, 14, 16, 18])\n\\end{lstlisting}\n \nUse \\li{np.linspace(start, stop, num=50)} to create an array of \\li{num} numbers evenly spaced in the interval from \\li{start} to \\li{stop}.\n\\begin{lstlisting}\n>>> np.linspace(0, 32, 4) \narray([  0.        ,  10.66666667,  21.33333333,  32.        ])\n\\end{lstlisting} \n\nWe can even create arrays of random values chosen\nfrom probability distributions. These probability distributions are stored\nin the submodule \\li{np.random}. \n\\begin{lstlisting}\n>>> np.random.rand(5) # uniformly distributed values in [0, 1)\narray([ 0.21845499,  0.73352537,  0.28064456,  0.66878454,  0.44138609])\n\\end{lstlisting} \nSome other commonly used functions are \\li{np.random.normal}, which samples from the normal distribution, and \\li{np.random.randint}, which randomly selects integers from a range.\n\nThere are many functions for creating arrays besides these, some of which are described in Table \\ref{table:numpycreate}. \nSee \\url{http://docs.scipy.org/doc/numpy/reference/routines.array-creation.html} for more details.\n\n\\begin{table}\n\\begin{tabular}{l|l} \nFunction & Description \n\\\\ \\hline \n\\li{diag} & Extract a diagonal or construct a diagonal array.\\\\\n\\li{empty} & Return a new array of given shape and type, without initializing entries. \\\\ \n\\li{empty_like} & Return a new array with the same shape and type as a given array. \\\\\n\\li{eye} & Return a 2-D array with ones on the diagonal and zeros elsewhere. \\\\ \n\\li{identity} & Return the identity array. \\\\ \n\\li{meshgrid} & Return coordinate matrices from two coordinate vectors.\\\\ \n\\li{ones} & Return a new array of given shape and type, filled with ones. \\\\ \n\\li{ones_like} & Returns an array of ones with the same shape and type as a given array. \\\\ \n\\li{zeros} & Return a new array of given shape and type, filled with zeros. \\\\ \n\\li{zeros_like} & Return an array of zeros with the same shape and type as a given array. \\\\ \n\\end{tabular} \n\\caption{Some functions for creating arrays in NumPy.}\n\\label{table:numpycreate} \n\\end{table} \n\n\\begin{comment}\nWe can create arrays that\nconsist entirely of ones or zeros using \\li{np.ones()} and\n\\li{np.zeros()} respectively. We can also allocate an ``empty'' array without initializing its values. The syntax for these commands is similar.\n\\begin{lstlisting}\n>>> np.zeros([2, 4])\narray([[ 0.,  0.,  0.,  0.],\n       [ 0.,  0.,  0.,  0.]])\n       \n>>> np.empty(5)\narray([  0.00000000e+000,   1.30586451e-316,   1.17126324e-316,\n0.00000000e+000,   2.37151510e-322])\n\\end{lstlisting} \n\nNote that the final array is not really ``empty''; it just has garbage entries.\n\nThe following functions can also be useful for creating arrays. \nSee the documentation for more information and examples. \n\nIf \\li{a} is an array, we can create a new empty array with the same shape and data type with the function \\li{np.empty_like()}. \nThe analogous functions \\li{np.ones_like} and\n\\li{np.zeros_like} for create arrays of ones or zeros, respectively.\n\nThe function \\li{np.identity(n)} returns an $n \\times n$ identity matrix. \n\nThe function \\li{np.eye(N, M, k)} returns an $N \\times M$ matrix with ones on the diagonal specified by \\li{k} and zeros elsewhere. \n\nIf \\li{v} is a 1-D array, the function \\li{np.diag(v, k)} returns a 2-D array with \\li{v} on the diagonal specified by \\li{k}. \nIf \\li{v} is a 2-D array, \\li{np.diag(v, k)} returns the diagonal of \\li{v} specified by \\li{k}.\n\nThe function \\li{np.tile()} constructs an array by repeating an existing array\n in a specified pattern. \n\nWe finish this section by demonstrating the function \\li{meshgrid}, which is used to create arrays that represent a\ntwo-dimensional grid of coordinates.\n\\begin{lstlisting}\n>>> x = np.arange(3) \n>>> y = np.arange(4, 8) \n>>> X, Y = np.meshgrid(x, y) \n>>> X\narray([[0, 1, 2],\n       [0, 1, 2],\n       [0, 1, 2],\n       [0, 1, 2]])\n>>> Y\narray([[4, 4, 4],\n       [5, 5, 5],\n       [6, 6, 6],\n       [7, 7, 7]])\n\\end{lstlisting} \n\\li{X} is the set of x-coordinates of pairs in the cartesian product of \\li{x} with \\li{y}, and \\li{Y} is the set of y-coordinates. That is, \\li{(X[i, j], Y[i, j]) = (x[i], y[j])}.\n\\end{comment}\n\n\\begin{comment} \nWhen\ncreating large grids of points this can use large amounts of RAM, so the\nmeshgrid function includes the \\li{copy} argument which, when set to\nfalse, returns arrays that are views of the original arrays instead of\ncopies (views and copies are discussed later in this lab). For example,\ninstead of running \\li{np.meshgrid(x, y)} you could run\n\\li{np.meshgrid(x, y, copy=False)}. This can be much faster, but should\nprobably only be used if you do not intend to make any additional\nchanges to the coordinates grid independent of the values stored in the\noriginal arrays.\n\nEvery NumPy array has five flags that give important information about\nthe array. We can check if an array is read-only by looking at its\nflags, or we can check how the array's contents are laid out in memory.\nOnly the \\texttt{WRITEABLE} and \\texttt{ALIGNED} flags can be modified. \nThe other flags are read-only. The \\texttt{OWNDATA} flag lets us know if\nthe array is a view or not. We will explain array views later in this\nlab. \\begin{lstlisting}\n>>> i.flags\n  C_CONTIGUOUS : True F_CONTIGUOUS : False OWNDATA : True WRITEABLE :\n  True ALIGNED : True UPDATEIFCOPY : False \\end{lstlisting} NumPy has\n  two different memory orderings for an array. Many array constructors\n  allow you to specify an \\li{order} keyword that determines the memory\n  layout of the array. \\begin{description} \\item[Row-major:] Arrays are\n  stored by rows in continuous memory. Languages such as C and Python\n  use row-major indexing. NumPy arrays by default use this indexing\n  convention. When an array is stored in memory the addresses to its\n  values are stored linearly. In simplest terms, the ordering of an\n  array determines whether its rows or its columns are stored in\n  contiguous blocks (for example: row 0, row 1, row 2, ... as opposed to\n  column 1, column 2, column 3, ...). For an array where the rows are in\n  contiguous blocks in memory, performing any sort of operation along a\n  column will be slower than performing that same operation along a row\n  of the same length. This difference is because of the irregular memory\n  access pattern. In NumPy, row-major arrays are identified as \\emph{C\n  contiguous} (\\li{order=`C'}). \\item[Column-major:] Arrays are stored\n  by columns in contiguous memory. Languages like FORTRAN, MATLAB, and R\n  use column-major indexing. For a column major array, operations that\n  run along rows are slower. In NumPy, column-major arrays are\n  identified as \\emph{FORTRAN contiguous} (\\li{order=`F'}).\n  \\end{description} Paying attention to how your arrays are indexed will\n  be beneficial to the performance of your algorithms. Speed is not\n  usually a critical concern, but it is good to know these things when\n  speed does become an issue.\n\\end{comment}\n\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Indexing and Slicing} \nIndexing for a 1-D NumPy array works exactly like indexing for a Python list. \nTo access a single entry of a multi-dimenional array, say a 3-D array, you should use the syntax \\li{f[i, j, k]}. \nWhile the syntax \\li{f[i][j][k]} will also work, it is significantly slower because each bracket returns an array slice. \nSimilarly, slicing an array works just like slicing a list, but with more dimensions.\n\\begin{lstlisting}\n>>> ex4 = np.arange(25).reshape((5,5)) \n>>> ex4\narray([[ 0,  1,  2,  3,  4],\n       [ 5,  6,  7,  8,  9],\n       [10, 11, 12, 13, 14],\n       [15, 16, 17, 18, 19],\n       [20, 21, 22, 23, 24]])\n>>> ex4[4, -2]\n23\n\n# Extract the lower right 2x2 subarray.\n>>> ex4[3:, 3:] \narray([[18, 19],\n       [23, 24]])\n       \n# Extract the second column. The returned array is 1-D.\n>>> ex4[:, 1] \narray([ 1,  6, 11, 16, 21]) \n\n# Reverse the order of the columns.\n>>> ex4[:, ::-1] \narray([[ 4,  3,  2,  1,  0],\n       [ 9,  8,  7,  6,  5],\n       [14, 13, 12, 11, 10],\n       [19, 18, 17, 16, 15],\n       [24, 23, 22, 21, 20]])\n\\end{lstlisting}\n\nFancy indexing is a second way to access elements of an array. \nThere are two types of fancy indexing: boolean and integer. \nBoolean indexing uses an array of \\li{True} or \\li{False} values to \ndetermine which elements of the array to take. \nYou can create true-false valued arrays by using logical operations on arrays. \nSee \\url{https://scipy-lectures.github.io/intro/numpy/operations.html#other-operations} for examples and \\url{http://docs.scipy.org/doc/numpy/reference/routines.logic.html} for a full list of such operations.\n\n\n\n\\begin{lstlisting}\n# Logic operations on arrays result in true-false valued arrays.\n>>> ex4mask = np.logical_and(ex4<23, ex4>15)\n>>> ex4mask \narray([[False, False, False, False, False],\n       [False, False, False, False, False],\n       [False, False, False, False, False],\n       [False,  True,  True,  True,  True],\n       [ True,  True,  True, False, False]], dtype=bool)\n\n>>> ex4[ex4mask]\narray([16, 17, 18, 19, 20, 21, 22])\n\\end{lstlisting}\n\nInteger indexing uses Python lists to determine what array values to access.\n\\begin{lstlisting}\n# Return an array of elements ex4[0,0], ex4[0, 0], ex4[2,3], and ex4[4,1].\n>>> ex4[[0, 0, 2, 4], [0, 0, 3, 1]] \narray([ 0,  0, 13, 21])\n# Take the first (0) and last (-1) columns.\n>>> ex4[:, [0, -1]]  \narray([[ 0,  4], [ 5,  9], [10, 14], [15, 19], [20, 24]])\n\\end{lstlisting}\n\nFancy indexing can\nbe used for assignment. For example, we can set all values of an array\nthat are less than \\li{10} to \\li{0} in the following way.\n\\begin{lstlisting} \n>>> ex4[ex4<10] = 0\n>>> ex4\narray([[ 0,  0,  0,  0,  0],\n       [ 0,  0,  0,  0,  0],\n       [10, 11, 12, 13, 14],\n       [15, 16, 17, 18, 19],\n       [20, 21, 22, 23, 24]])\n\\end{lstlisting}\n\n\n\n% \\begin{problem} Generate a random $1000 \\times 1000$ array \\li{A}. Now\n% create an uninitialized array \\li{B} with all the same attributes as\n% \\li{A}. Now do the following 100 times: \\begin{itemize} \\item\n% Overwrite \\li{B} so that it is an array of new random values like\n% \\li{A}. This can be done like this: \\li{B[:] = rand(1000,1000)} \\item\n% Use fancy indexing to make \\li{A} the maximum of \\li{A} and \\li{B}.\n% \\end{itemize} Now take \\li{exp(A)} and have NumPy store the output\n% directly in \\li{A}. Take the maximum along the vertical axis and\n% average the result. The final number should be very close to $e$.\n% \\end{problem}\n% \n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Array Views and Copies} \nNumPy has two ways of returning an array. Slice operations and indexing always return\na \\emph{view} and fancy indexing always returns a \\emph{copy}.\nUnderstand that even though they may look the same, views and copies are different.\n\n\nA view of an array is a distinct object from the original array in Python, but it references the same place in memory. \nThus, when you change elements in a view, you also change the array it references.\n\\begin{lstlisting}\n>>> ex5 = np.arange(5)\n\n# Slicing produces a view of k. \n>>> view_ex5 = ex5[:]\n>>> view_ex5\n\n# Check that m and k are distinct objects in Python.\n>>> id(view_ex5) == id(ex5) \nFalse\n\n# Change the third element of view_ex5 to 500\n# Changing view_ex5 also changes ex5.\n>>> view_ex5[2] = 500 \n>>> view_ex5\narray([  0,   1, 500,   3,   4])\n>>> ex5 \narray([  0,   1, 500,   3,   4])\n\\end{lstlisting} \n\nA copy of an array is a separate array with its own memory. \nThus, when you change a copy of an array, you do not affect the original array. \nBecause copying an array uses more memory and also more time, it should only be done when necessary. \nAn array can be copied using the \\li{np.copy()} function (also available as a method of \nthe array object). \n\n\\begin{lstlisting}\n>>> copy_ex5 = np.copy(ex5) \n\n# Check that j and n are distinct objects in Python.\n>>> id(copy_ex5) == id(ex5) \nFalse\n\n# Change the third element of copy_ex5 to 1000\n# Changing copy_ex5 does not affect ex5.\n>>> copy_ex5[2] = 500 \n>>> copy_ex5\narray([  0,   1, 1000,   3,   4])\n>>> ex5\narray([  0,   1, 500,   3,   4])\n\\end{lstlisting} \n\nWhenever possible, the function \\li{np.reshape()} returns a view. \nSee the documentation for more information. \n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section*{More Methods of NumPy Arrays} \nSome of the more common methods of NumPy arrays are described in Table \\ref{table:ndarraymethods}. \nA more comprehensive list can be found at\n\\url{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.\nhtml}.\n\n\\begin{table}\n\\centering \n\\begin{tabular}{l|p{10cm}}\n    \\hline\n    Function & Description \\\\\n    \\hline\n    \\li{all} & returns True if all elements evaluate to True \\\\\n    \\li{any} & returns True if any elements evaluate to True \\\\\n    \\li{argmax} & indices of maximum value(s) \\\\\n    \\li{argmin} & indices of minimum value(s) \\\\\n    \\li{argsort} & indices that would sort the array \\\\\n    \\li{astype} & casts a copy of an array to a different data type \\\\\n    \\li{clip} & restrict values in an array to fit within a given range\\\\\n    \\li{conj} & return the complex conjugate of the array \\\\\n    \\li{copy} & return a copy of the array\\\\\n    \\li{diagonal} & return a given diagonal of the array \\\\\n    \\li{dot} & matrix multiplication \\\\\n    \\li{max} & max element of the array \\\\\n    \\li{mean} & average of the array \\\\\n    \\li{min} & minimum element of the array \\\\\n    \\li{vstack}\n    \\li{prod} & product of elements of the array \\\\\n    \\li{ravel} & make a flattened version of an array, return a view if\n    possible \\\\\n    \\li{reshape} & return a view of the array with a changed shape \\\\\n    \\li{round} & return a rounded version of the array \\\\\n    \\li{sort} & sort the array in place \\\\\n    \\li{std} & compute the standard deviation \\\\\n    \\li{sum} & sum the elements of the array \\\\\n    \\li{swapaxes} & return a view with the given axes swapped \\\\\n    \\li{tolist} & return the array represented as a list or nested list\\\\\n    \\li{trace} & return the sum of the elements along the main diagonal\\\\\n    \\li{var} & return the variance of the array \\\\\n    \\hline\n    \\end{tabular} \\caption{A few of the methods of NumPy arrays.}\n    \\label{table:ndarraymethods} \\end{table}\n\nMany of these methods have the option to operate \\emph{along an axis}. \nWhen called in this way on an $n$-D array, these methods return an $(n-1)$-D array (the specified axis is collapsed in the evaluation process).\n\n\\begin{lstlisting}\n>>> ex6 = np.arange(9).reshape(3, 3)\n>>> ex6\narray([[0, 1, 2],\n       [3, 4, 5],\n       [6, 7, 8]])\n       \n# Return the maximum value in the array\n>>> ex6.max() \n8\n\n# Return the maximum values evaluated along the 0-axis\n>>> ex6.max(axis=0)\narray([6, 7, 8])\n\n# Return the maximum values evaluated along the 1-axis\n>>> ex6.max(axis=1)\narray([2, 5, 8])\n\\end{lstlisting}\n\n\n\\begin{problem}\n% There should be more problems like this in the vectorization lab. I'll\n% include this one here for now though.\nWrite a function which accepts an integer $n$ as input and does the following:\n\\begin{enumerate}\n\\item Creates an $n\\times n$ array of \\li{floats} randomly chosen from a normal distribution\n\\item Computes the mean of each row (use a built-in command)\n\\item Computes the variance of these means (use a built-in command).\n\\end{enumerate}\nAs you increase $n$, what happens to the output of \nyour function? This illustrates one version of\nthe Law of Large Numbers, about which you will learn more later on.\n\\end{problem}\n\n\n\n\n\n\n\\begin{comment}\nThe transpose \\li{np.T} is another efficient NumPy operation that returns an array\nview. \n\n\\begin{lstlisting}\n>>> b = np.arange(16).reshape((4,4)) \n>>> b.T\narray([[ 0,  4,  8, 12],\n       [ 1,  5,  9, 13],\n       [ 2,  6, 10, 14],\n       [ 3,  7, 11, 15]])\n\\end{lstlisting}\n\nWe can also manipulate the axes of an existing array using\n\\li{np.swapaxes} and \\li{np.rollaxis}. Functions can also be applied\nacross one or more axes using \\li{np.apply_across_axis} or\n\\li{np.apply_across_axes}. The function \\li{np.unique} will return the\nsorted unique elements of the input array. There are also methods for\nconstructing arrays from individual subarrays. While they may be useful,\nuse them very carefully as they can have a very negative impact on\nperformance. Functions like \\li{np.hstack} and \\li{np.vstack} will\nhorizontally or vertically stack the input arrays into a new NumPy\narray.\n\n\\end{comment}\n\n\\begin{comment}\n\\begin{problem} \nOperations that create new arrays are often slower than \noperations that create views because allocating an array can be time \nconsuming. \n\\begin{enumerate}\n\\item Create an $1000 \\times 1000$ array \\li{A} of random floating point values. \n\\item Compare the speed of the operations \\li{A.reshape(A.size)}\nand \\li{A.flatten()}. Note that we are calling the methods of the arrays. \nThey are the same as \\li{np.reshape(A, A.size)}, and \\li{np.flatten(A)}\nrespectively. \n\\item Why is there such a difference in speed? \n\\end{enumerate}\n\\end{problem}\n\\end{comment}\n\n\\begin{problem} \nOne good application of array slicing is the Jacobi\nmethod for solving Laplace's equation, which is used to model\nsteady-state heat flow on a square. This problem will help you implement the Jacobi method.\n\nMake a function that accepts an array and a tolerance as input and does the\nfollowing: \n\\begin{enumerate}\n\\item Makes a copy of the array. \n\\item Creates a variable to track the difference between the arrays. Initialize\nit as the tolerance parameter your function accepts. \n\\item While the difference is greater than or equal\nto the tolerance \n\\begin{enumerate} \n\\item Sets all points that are not on an edge of the new array equal to the average of their 4 immediate neighbors. \nUse the values from the old array for this computation. \nThis should only take one line and should be based entirely on array slicing, NOT iterating through the array.\n(Hint: given a 2D array \\li{A}, the slice \\li{A[1:-1,1:-1]} references\nall non-edge entries, \\li{A[:-2,1:-1]} references the upper neighbors,\nand \\li{A[1:-1,2:]} references the right neighbors.) \n\\item Updates the difference to be the maximum of the absolute value of the new array\nminus the old one. \n\\item Copies the values from the new array into the old\none (without creating a new array). \n\\end{enumerate} \n\\end{enumerate}\n\nNow use the following code to generate a plot of your results.\n\\lstinputlisting[style=fromfile]{laplace_plot.py} \nIt should resemble the following figure.\n\n\\begin{figure} [H]\n\\includegraphics[width=.75\\textwidth]{laplace.pdf}\n\\end{figure} \n\\end{problem}\n\n\n\\begin{comment}\n\\section*{Saving Arrays} It is often useful to save an array as a file.\nNumPy provides several easy methods for saving and loading array data.\n\n\\begin{table*}\n\\begin{tabular}{l|l}\n\\hline\n\\li{np.save(file, arr)} & Save an array to a binary file \\\\\n\\li{np.savez(file, *arrs)} & Save multiple arrays to a binary file \\\\\n\\li{np.savetxt(file, arr)} & Save an array to a text file \\\\\n\\hline\n\\end{tabular}\n\\end{table*}\n\n\\begin{table*}\n\\begin{tabular}{l|l}\n\\hline\n\\li{np.load(file)} & Load and return an array from a binary file \\\\\n\\li{np.loadtxt(file)} & Load and return an array from text file \\\\\n\\hline\n\\end{tabular}\n\\end{table*}\n\nLet's practice saving an array to a file and loading it again.\nNote that, when saving an array, NumPy automatically appends the extension \\li{.npy} if it is not already present.\n\\begin{lstlisting}\na = np.arange(30)\nnp.save('test_arr', a)\nnew_a = np.load('test_arr.npy')\nnp.savez('test_multi', a=a, new_a=new_a)\narrs = np.load('test_multi.npz')\n\\end{lstlisting}\nThe variable \\li{arrs} points to a dictionary object with the keys \\li{a} and \\li{new_a} which reference the arrays that have been saved.\nThe \\li{.npz} file extension is the file type used to store multiple arrays.\n\\end{comment}\n\n\\begin{comment}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Manipulating Arrays} \nSometimes it is best to work on the entire array in single dimension. \nNumPy provides several ways to do this, each optimized for a different purpose.\n\nThe function \\li{np.ravel()} returns a 1-D view of an array. It behave exactly like calling \\li{reshape(-1)} on the array, but it executes faster.On the other hand, the array method \\li{flatten()} returns a 1-D copy of the array.\n\nFinally, the array method \\li{flat} lets you iterate over the array as if it were 1-dimensional. Here is an example.\n\\begin{lstlisting}\n>>> a = np.arange(4).reshape(2, 2)\n\n# Iterate through the rows of a\n>>> for i in a:\n...     print i,\n...     \n[0 1] [2 3]\n\n# Iterate through the entries of a\n>>> for i in a.flat:\n...     print i,\n...\n0 1 2 3\n\\end{lstlisting}\n\\end{comment}\n\n\n\n\\subsection*{Iterating Through Arrays}\n\nIterating through an array undoes most speed advantages of NumPy. \nYou should avoid doing this whenever possible.\nYou can often avoid iterating through arrays by using \\emph{array broadcasting} and \\emph{universal functions}, discussed in the next section.\n\nIt is occasionally valid to iterate through an array. \nThe function \\li{np.nditer()} will create an object that iterates through an array as quickly as possible.\n\n\n\\section*{NumPy and SciPy}\nWe now introduce some additional features of NumPy and SciPy.\n\n\\subsection*{Array Broadcasting}\nMany matrix operations make sense only when the two operands have the same shape. \nTwo examples are addition and component-wise multiplication. \nBroadcasting is NumPy's way of extending such operations to accept some (not all) operands with different shapes. \nBroadcasting happens automatically whenever it is necessary. \n\nTo understand broadcasting, let us look at an example. \n\\begin{lstlisting}\n>>> A = np.ones(3);\n>>> A\narray([ 1.,  1.,  1.])\n>>> B = np.vstack([1, 2, 3])\n>>> B\narray([[1],\n       [2],\n       [3]])\n>>> A+B\narray([[ 2.,  2.,  2.],\n       [ 3.,  3.,  3.],\n       [ 4.,  4.,  4.]])\n\\end{lstlisting}\nWe will now describe the algorithm used to obtain the result for \\li{A+B} above. \nFirst, the shapes of \\li{A} and \\li{B} are lined up, starting at the far right, and 1's are prepended to the shorter tuple. So\n\\begin{lstlisting}\nA \t(1-D array):     3\nB\t(2-D array): 3 x 1\n\\end{lstlisting}\nbecomes\n\\begin{lstlisting}\nA \t(1-D array): 1 x 3\nB\t(2-D array): 3 x 1\n\\end{lstlisting}\nFor broadcasting to work, the dimensions must be compatible; that is, in a given axis, the lengths are equal, or one of the lengths is 1. \nSecond, the arrays \\li{A} and \\li{B} are ``stretched'' one axis at a time until the lengths of their axes are the same. \nIn each axis, if the lengths are different, the smaller array is copied along that axis (or ``stretched''), until it is the size of the larger array. \nConceptually, we are creating new $3 \\times 3$ arrays $A'$ and $B'$ where\n\\[\nA' = \\left[ \\begin{array}{ccc}\n1 & 1 & 1\\\\\n1 & 1 & 1\\\\\n1 & 1 & 1 \\end{array} \\right] \\qquad \\text{and} \\qquad B' =  \\left[ \\begin{array}{ccc}\n1 & 1 & 1\\\\\n2 & 2 & 2\\\\\n3 & 3 & 3\\end{array} \\right].\n\\]\nFinally, NumPy returns the sum $A'+B'$.\n\nWe emphasize that the ``stretching'' in this example is only conceptual, and no new array $A'$ or $B'$ is created. However, \nyou should still be careful when broadcasting large arrays because you can fill the \nRAM on your computer, which can sometimes freeze the system.\nFor a more detailed description of array broadcasting rules, see \n\\url{http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html}.\n\n\\begin{problem}\nCreate a $100\\times100\\times3$ array of random integers taking values in the range \n[0, 256]. Such an array can represent an RGB image of $100\\times100$ pixels, \nwhere each pixel is associated with an array of three integers indicating the \namounts of red, green, and blue color present in that pixel.\nUse array broadcasting to multiply the red and green values by $0.5$. \n(Such an operation would tone down the red and green colors and make the \nimage appear more blue.) \n\\end{problem}\n\n\\subsection*{Universal Functions}\n\nA universal function, or \\li{ufunc}, operates on an array elementwise. \nIt outputs an array of the same shape and datatype as the input array. \nUsing a universal function is usually much faster than iterating through the array yourself.\n\nMany scalar functions from the Python standard library have a universal analog that operates on arrays. \nFor example, \\li{math.sin()} operates on scalars, and \\li{numpy.sin()} operates on arrays. \nIf you have a simple operation that you want to perform elementwise on an array, you should see if SciPy has a universal function that will do it (it probably does). \nFor a list of available \\li{ufuncs}, see \\url{http://docs.scipy.org/doc/numpy/reference/ufuncs.html#available-ufuncs}.\n\nMost universal functions also allow you to specify an output array, which must have the same shape as the input array.\nDoing so can reduce memory allocation. \n\n\\begin{lstlisting}\n>>> ex7 = np.arange(3, dtype=float)\n\n# Take exp(ex7) and store the result in ex7.\n>>> np.exp(ex7, out=ex7) \n>>> ex7\narray([ 1.        ,  2.71828183,  7.3890561 ])\n\\end{lstlisting}\n\n\\begin{comment}\nOther useful examples are \\li{max}, \\li{min}, \\li{absolute}, and \\li{average}.\nEach of these operations also allows you to specify whether you want to \noperate across a particular axis or over the entire array.\nFor example:\n\nThe above example returns a row of A which represents the maximum of all the \nrows of A. If we had set \\li{axis=1}, it would have taken the maximum of all \nthe columns. If, for purposes of broadcasting (discussed later) you need the \noutput of one of these functions to have the same number of dimensions as the \noriginal array, you can also include the argument \\li{keepdims=True}.\n\n\\end{comment}\n\n\nAlthough universal functions also accept scalar inputs, they can be much slower than the corresponding standard library function. \nThus, use standard library functions on scalars and universal functions on arrays.\n\n\\begin{comment}\n\n\\begin{lstlisting}\n>>> timeit np.sin(.5)\n1000000 loops, best of 3: 1.37 muµs per loop\n>>> timeit np.math.sin(.5)\n10000000 loops, best of 3: 144 ns per loop\n\\end{lstlisting}\n\nWe can see that performance increases when we know how to use a \n\\texttt{ufunc}. However, they should only be used on arrays as they are \nnot designed to handle single values efficiently.\n\\end{comment}\n\n\\subsection*{Linear Algebra}\nBoth NumPy and SciPy have a linear algebra library, but the SciPy library is larger. The SciPy linear algebra library is typically imported as follows.\n\n\\begin{lstlisting}\nfrom scipy import linalg as la\n\\end{lstlisting}\n\n\\begin{comment}\nTo shorten the amount of typing, it can be aliased as \n\\li{from scipy import linalg as la}.\n\\end{comment}\n\nThe linear algebra library contains several functions to construct special \nmatrices, located in \n\\li{linalg.special_matrices}. There are also functions that will invert matrices, find determinants and norms, solve linear systems and least squares problems, and find special matrix decompositions. You can read more about the linear algebra capabilities of SciPy in the \ndocumentation for the \\li{linalg} module found at\n(\\url{http://docs.scipy.org/doc/scipy/reference/linalg.html}).\n\nFinally, the \\li{scipy.linalg} library has a \\li{matrix} class that is very \nsimilar to a 2-D NumPy array. The matrix class can be convenient when doing matrix \noperations. However, in such situations we still recommend using NumPy arrrays, which have many of the same features and are also compatible with all other SciPy operations.\n\n\\begin{comment}\n\\begin{problem}\nBlock ciphers are ciphers that encode blocks of input symbols at a time \ninstead of one symbol at a time. In the days before computers, the Hill \ncipher was the first cipher that allowed practical encoding of more than \nthree symbols at a time. It was invented by Lester Hill in 1929.\nThe Hill cipher is considered a classical substitution cipher.\nThe entire cipher is based on linear algebra and uses a matrix key.\nAll substitution ciphers work with the 26 letters.\nThus, all our operations will be done mod 26 (modulo 26).\nTo do this, we introduce you to the \\li{\\%} operator in Python.\nThis new operator allows us to do modular arithmetic.\nWhen applied to an array it takes the elementwise mod.\n\nThis problem has a number of parts.  You will write a function that \naccepts \\emph{plaintext} and returns the encoded \\emph{ciphertext}.\nYou will also write a decoder that will accept ciphertext and return \nplaintext.\n\nThe Encoder: \\begin{enumerate}\n\\item We must first gather the plaintext to encode and a block size, $n$.\nWe must split this plaintext into blocks removing any spaces.  We need to \nconvert each character to a number. We use the index of \\li{string.lowercase} \n(found in the \\li{string} module of the Python standard library).\nWe can easily build a lookup table that will let you easily find the index.\nWith a lookup table, we map each letter to its index.\n\n\\begin{lstlisting}\nfrom string import lowercase\nlut = {a:i for i, a in enumerate(lowercase)}\ns = \"this is a message\"\ns = \"\".join(s.split()) #remove all whitespace\nmap(lut.__getitem__, s) #return a list of indices\n[19, 7, 8, 18, 8, 18, 0, 12, 4, 18, 18, 0, 6, 4]\n\\end{lstlisting}\n\nAnother way is to use \\li{lowercase.index()} in a loop to find the index \neach time.\n% \\begin{lstlisting}\n% >>> indices = []\n% >>> for letter in s:\n%         indices.append(lowercase.index(letter))\n% \\end{lstlisting}\nWe need to split the list of indices into $n$-length arrays and store them \nin a list. If the input is not a multiple of $n$, you will need to pad the \ninput until it is a multiple of $n$. Pick any character to pad the input \n(typically it is a rarely used letter). The \\li{itertools} module is useful \nfor this.  One of the common recipes for doing this task is available in \nthe \\li{itertools} documentation.\n\n\\begin{lstlisting}\ndef grouper(iterable, n, fillvalue=None):\n    \"Collect data into fixed-length chunks or blocks\"\n    # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx\n    args = [iter(iterable)] * n\n    return itertools.izip_longest(fillvalue=fillvalue, *args)\n\\end{lstlisting}\n\nIt will be useful to wrap all of this step in a separate function as we will \nneed to do the same thing when decoding (except for removing whitespace).\n\n\\item Find a suitable cipher key.  The keys of a Hill cipher are square \nmatrices.  Let $K$, be our key. $K$ must be invertible mod 26.\nRemember from linear algebra, that the determinant of square matrix will \ntell you if that matrix is invertible. To find a matrix that is invertible \nmod 26, we need to find a matrix with a determinant that is relatively prime \nto 26 (they share no common factors). The Euclidean algorithm can be used to \ndetermine if two numbers are co-prime (i.e. $\\gcd(d, 26) = 1$). Write a \nfunction that generate random integer matrices using NumPy, checking the \ndeterminant, and returns a suitable key, $K$.\n\n\\item Write a function that will accept a message and a key matrix.\nThe message should already be broken into $n$ length blocks (you can do this \ninside the encode function if needed) and the matrix should be $n \\times n$.\nA Hill cipher is the dot product of the block with the key.  Return a \nciphertext that is letters (the numbers correspond the indices in \n\\li{string.lower}).\n\n\\item Write a function that will compute $K^{-1} \\pmod{26}$.  This will \nnecessarily be an integer inverse.\nUse \\li{linalg.inv} to find the inverse of $K$.\nThen \\[K^{-1} = \\det(K)K^{-1}\\det(K)^{-1}  \\pmod{26}\\] where $\\det(K)^{-1}$ \nis the inverse of the determinant mod 26.\nYou will need to round the determinant to the nearest integer before doing \nthese steps.  You will also need to round the results of each of your \nmultiplications.\nYou can check that you have the integer inverse by checking $KK^{-1} = I$.\n\n\\item Write a function that will decode a message given a ciphertext and the \nkey. You will need to invert the key before decoding.  Break the message into \nblocks of size $n$ and calculate the dot product of each block with the \ninverted key. Return a plaintext that is letters (the numbers, again, \ncorrespond to indices in \\li{string.lower}).\n\\end{enumerate}\n\nExperiment with your Hill cipher.  If you are in a classroom setting, try \nsending encoded messages to friends (they will need the key you used to \nencode).\n\\end{problem}\n\\end{comment}\n\n\\subsection*{Polynomials}\nThe \\li{np.poly1d} object represents a polynomial in NumPy. The constructor is called with the coefficients of the desired polynomial. \n\n\\begin{lstlisting}\n>>> poly_array = np.poly1d([3, 5, 1, 2, 0, 1])\n>>> print poly_array\n   5     4     3     2\n3 x + 5 x + 1 x + 2 x + 1\n\\end{lstlisting}\n\nThe object \\li{poly_array} represents the polynomial $3x^5+5x^4+x^3+2x^2+1$.\nNumPy provides many functions to operate on \\li{poly1d} objects (see \\url{http://docs.scipy.org/doc/numpy/reference/routines.polynomials.polynomial.html}).\n\n\\begin{comment}\n\\begin{table}\n\\centering\n\\begin{tabular}{l|l}\nFunction & Description \\\\\n\\hline\n\\li{np.polyadd} & Add two polynomial arrays \\\\\n\\li{np.polyder} & Find the derivative of a polynomial array \\\\\n\\li{np.polydiv} & Divide two polynomial arrays \\\\\n\\li{np.polyfit} & Find a least squares polynomial fit \\\\\n\\li{np.polyint} & Find the integral of a polynomial array \\\\\n\\li{np.polymul} & Multiply two polynomial arrays \\\\\n\\li{np.polysub} & Subtract two polynomial arrays \\\\\n\\li{np.polyval} & Evaluate a polynomial at specific points\n\\end{tabular} \\caption{A few methods of NumPy polynomial arrays.}\n\\label{table:poly1dmethods}\\end{table}\n\\end{comment}\n\nHere is an example using the \\li{poly1d} class. Recall that\n\\[\ne^x = \\sum_{n=0}^{\\infty} \\frac{x^n}{n!}.\n\\]\nThe following function evaluates the $n^{th}$ partial sum of this series at the value $a$.\n\n\\lstinputlisting[style=fromfile]{exp.py}\n\\begin{comment}\n\\begin{lstlisting}\nfrom scipy.misc import factorial\nn = 18 # number of terms\np = 1. / factorial(np.arange(18, -1, -1)) # compute coefficients\nX = np.random.rand(10000) # where to evaluate the series\nP = np.poly1d(p) # make polynomial object\nP(X)\n\\end{lstlisting}\n\\end{comment}\nThe last two lines can be condensed by using the following command.\n\n\\begin{lstlisting}\nnp.polyval(p, a)\n\\end{lstlisting}\n\n\\begin{problem}\n\\leavevmode\n\\begin{enumerate}\n\\item Use NumPy's polynomial objects to approximate the following series.\n\\[\n\\arcsin x = \\sum_{n=0}^{\\infty} \\frac{\\left(2 n\\right) ! x^{2 n + 1}}{\\left(2 n + 1\\right)\\left(n!\\right)^2 4^n}\n\\]\nThis series converges on $(-1, 1)$. Use your series approximation to approximate $\\pi$. Hint: think of the powers of $x$ that\nare not included in the series as having zero coefficients.\n\n\\item The lambert W function is the inverse of $x e^x$.\nIts Taylor series is below (note the index starts at 1).\n\\[\nW(x) = \\sum_{n=1}^{\\infty} \\frac{\\left(-n\\right)^{n-1} x^n}{n!}\n\\]\nThis series has a radius of convergence of $\\frac{1}{e}$.\nUse the series to approximate a number $x$ such that $x e^x = \\frac{1}{4}$.\nVerify that your approximation is close.\n\n\n\\end{enumerate}\n\\end{problem}\n\n\\begin{comment}\n\\section*{Useful Functions}\nThe following table contains a list of useful NumPy functions. \nFor more information please refer to the NumPy documentation.\n\\begin{table}\n\\centering\n\\begin{tabular}{l|l}\nFunction & Description \\\\\n\\hline\n\\li{np.intersect1d} & Return the intersection of two flattened arrays. \\\\\n\\li{np.union} & Return the union of two flattened arrays. \\\\\n\\li{np.diff} & Calculates a discrete difference of order $n$. \\\\\n\\li{np.absolute} & Return the elementwise absolute value of an array. \\\\\n\\li{np.pad} & \\\\\n\\li{np.nonzero} & \\\\\n\\li{np.count_nonzero} & \\\\\n\\li{np.select} & \\\\\n\\li{np.nan} & Represent IEEE NAN (not-a-number). \\\\\n\\li{np.inf} & Represent IEEE INF (infinity). \\\\\n\\li{np.who} & Print information about defined NumPy arrays in a variable scope. \\\\\n\\li{np.unique} & Return a sorted array of unique elements of an array. \\\\\n\\end{tabular} \n\\end{table}\n\\end{comment}\n\n", "meta": {"hexsha": "6902f37ab9a737c94de62350c5ee0c1af77f4b00", "size": 44441, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Python/Arrays/Arrays.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Python/Arrays/Arrays.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Python/Arrays/Arrays.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 40.5853881279, "max_line_length": 272, "alphanum_fraction": 0.7082648905, "num_tokens": 12622, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.8652240791017535, "lm_q1q2_score": 0.7033123765079268}}
{"text": "Source: waynedisonitau123\n\n\\subsubsection{Kirchhoff's Theorem}\nDenote $L$ be a $n \\times n$ matrix as the Laplacian matrix of graph $G$, where $L_{ii} = d(i)$, $L_{ij} = -c$ where $c$ is the number of edge $(i, j)$ in $G$.\n\\begin{itemize}\n    \\itemsep-0.5em\n    \\item The number of undirected spanning in $G$ is $\\lvert \\det(\\tilde{L}_{11}) \\rvert$.\n    \\item The number of directed spanning tree rooted at $r$ in $G$ is $\\lvert \\det(\\tilde{L}_{rr}) \\rvert$.\n\\end{itemize}\n\n\\subsubsection{Tutte's Matrix}\nLet $D$ be a $n \\times n$ matrix, where $d_{ij} = x_{ij}$ ($x_{ij}$ is chosen uniformly at random) if $i < j$ and $(i, j) \\in E$, otherwise $d_{ij} = -d_{ji}$. $\\frac{rank(D)}{2}$ is the maximum matching on $G$.\n\n\\subsubsection{Cayley's Formula}\n\\begin{itemize}\n    \\itemsep-0.5em\n  \\item Given a degree sequence $d_1, d_2, \\ldots, d_n$ for each \\textit{labeled} vertices, there are $\\frac{(n - 2)!}{(d_1 - 1)!(d_2 - 1)!\\cdots(d_n - 1)!}$ spanning trees.\n  \\item Let $T_{n, k}$ be the number of \\textit{labeled} forests on $n$ vertices with $k$ components, such that vertex $1, 2, \\ldots, k$ belong to different components. Then $T_{n, k} = kn^{n - k - 1}$.\n\\end{itemize}\n\n\\subsubsection{Erdős–Gallai Theorem}\nA sequence of non-negative integers $d_1 \\geq d_2 \\geq \\ldots \\geq d_n$ can be represented as the degree sequence of a finite simple graph on $n$ vertices if and only if $d_1 + d_2 + \\ldots + d_n$ is even and\n$$ \\sum_{i = 1}^{k}d_i \\leq k(k - 1) + \\sum_{i = k + 1}^{n}\\min(d_i, k) $$\nholds for all $1 \\leq k \\leq n$.\n", "meta": {"hexsha": "865541d97d3db2e4909550ccad9cc32b81a05bee", "size": 1532, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/math/theorem.tex", "max_stars_repo_name": "ToxicPie/codebook", "max_stars_repo_head_hexsha": "fc084c4b61026f33a03f2901430b6fe36d2c1e6f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-28T06:58:24.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-13T04:51:48.000Z", "max_issues_repo_path": "content/math/theorem.tex", "max_issues_repo_name": "ToxicPie/codebook", "max_issues_repo_head_hexsha": "fc084c4b61026f33a03f2901430b6fe36d2c1e6f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "content/math/theorem.tex", "max_forks_repo_name": "ToxicPie/codebook", "max_forks_repo_head_hexsha": "fc084c4b61026f33a03f2901430b6fe36d2c1e6f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-06T12:17:34.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-06T12:17:34.000Z", "avg_line_length": 61.28, "max_line_length": 211, "alphanum_fraction": 0.6514360313, "num_tokens": 587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7033123725855618}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\hbadness=99999\n\\voffset=-1in\n\\oddsidemargin=5pt\n\\textwidth=450pt\n\\textheight=700pt\n\n\\begin{document}\n\\title{Linear Algebra: Week 3 Notes and Exercises}\n\\author{Christopher Aytona}\n\\maketitle\n\n\\section{Notes}\nExercises\\\\\n\n1) Find the length of the vectors $a = \\begin{bmatrix}\n-10\\\\\n5\n\\end{bmatrix}$ and $b = \\begin{bmatrix}\n3\\\\\n3\n\\end{bmatrix}$\n\n$||\\vec{a}|| = \\sqrt{(-10)^2+5^2}$\n\n$||\\vec{a}|| = \\sqrt{125}$\n\n$||\\vec{b}|| = \\sqrt{(3)^2+(3)^2}$\n\n$||\\vec{b}|| = \\sqrt{18}$\\\\\n\n2) Find the magnitude of the vectors $r = \\begin{bmatrix}\n7\\\\\n-3\n\\end{bmatrix}$ and $q = \\begin{bmatrix}\n-3\\\\\n7\n\\end{bmatrix}$\n\n$||\\vec{r}|| = \\sqrt{(7)^2+(-3)^2}$\n\n$||\\vec{r}|| = \\sqrt{58}$\n\n$||\\vec{q}|| = \\sqrt{(-3)^2+(7)^2}$\n\n$||\\vec{q}|| = \\sqrt{58}$\\\\\n\n3) Normalize the vectors in $\\mathbb{R}^2$ $a = \\begin{bmatrix}\n4\\\\\n5\n\\end{bmatrix}$ and $b = \\begin{bmatrix}\n5\\\\\n-4\n\\end{bmatrix}$\n\n$||\\vec{a}|| = \\sqrt{(4)^2+(5)^2}$\n\n$||\\vec{a}|| = \\sqrt{41}$\n\n$\\frac{\\vec{a}}{||\\vec{a}||} = \\frac{\\begin{bmatrix}\n4&5\n\\end{bmatrix}}{\\sqrt{41}} = \\begin{bmatrix}\n\\frac{4}{\\sqrt{41}}&\\frac{5}{\\sqrt{41}}\n\\end{bmatrix}$\n\n$||\\vec{b}|| = \\sqrt{(5)^2+(-4)^2}$\n\n$||\\vec{b}|| = \\sqrt{41}$\n\n$\\frac{\\vec{b}}{||\\vec{b}||} = \\frac{\\begin{bmatrix}\n5&-4\n\\end{bmatrix}}{\\sqrt{41}} = \\begin{bmatrix}\n\\frac{5}{\\sqrt{41}}&\\frac{-4}{\\sqrt{41}}\n\\end{bmatrix}$\\\\\n\n4) Normalize the vectors in $\\mathbb{R}^2$ $q = \\begin{bmatrix}\n-3\\\\\n6\n\\end{bmatrix}$ and $p = \\begin{bmatrix}\n-1\\\\\n-1\n\\end{bmatrix}$\n\n$||\\vec{q}|| = \\sqrt{(-3)^2+(6)^2}$\n\n$||\\vec{q}|| = \\sqrt{41}$\n\n$\\frac{\\vec{q}}{||\\vec{q}||} = \\begin{bmatrix}\n\\frac{-3}{\\sqrt{41}}&\\frac{6}{\\sqrt{41}}\n\\end{bmatrix}$\n\n$||\\vec{p}|| = \\sqrt{(-1)^2+(-1)^2}$\n\n$||\\vec{p}|| = \\sqrt{2}$\n\n$\\frac{\\vec{p}}{||\\vec{p}||} = \\begin{bmatrix}\n\\frac{-1}{\\sqrt{2}}&\\frac{-1}{\\sqrt{2}}\n\\end{bmatrix}$\n\n5) Find the distance between the points $a = \\begin{bmatrix}\n-10\\\\\n5\n\\end{bmatrix}$ and $b = \\begin{bmatrix}\n3\\\\\n3\n\\end{bmatrix}$\n\n$\\vec{a}-\\vec{b} = \\begin{bmatrix}\n-13\\\\\n2\n\\end{bmatrix}$\n\n$||\\vec{a}-\\vec{b}|| = \\sqrt{(-13)^2+(2)^2}$\n\n$||\\vec{a}-\\vec{b}|| = \\sqrt{173}$\\\\\n\n6) Find the distance between the points $q = \\begin{bmatrix}\n-3\\\\\n7\n\\end{bmatrix}$ and $r = \\begin{bmatrix}\n7\\\\\n-3\n\\end{bmatrix}$\n\n$\\vec{q}-\\vec{r} = \\begin{bmatrix}\n-10\\\\\n10\n\\end{bmatrix}$\n\n$||\\vec{q}-\\vec{r}|| = \\sqrt{(-10)^2+(10)^2}$\n\n$||\\vec{q}-\\vec{r}|| = \\sqrt{200}$\\\\\n\n10) Find the dot product of the two vectors. Are the two vectors perpendicular?\n\na) $$v_1 = \\begin{bmatrix}\n-1\\\\\n-1\n\\end{bmatrix} v_2 =\n\\begin{bmatrix}\n2\\\\\n-2\n\\end{bmatrix}$$\n\n$v_1 \\cdot v_2 = \\begin{bmatrix}\n-1\\times2+(-1)\\times-2\n\\end{bmatrix} = \\begin{bmatrix}\n0\n\\end{bmatrix}$\n\n$||\\vec{v_1}|| = \\sqrt{(-1)^2+(-1)^2}$\n\n$||\\vec{v_1}|| = \\sqrt{2}$\n\n$||\\vec{v_2}|| = \\sqrt{(2)^2+(-2)^2}$\n\n$||\\vec{v_2}|| = \\sqrt{8}$\n\n$\\cos\\theta = \\frac{\\vec{v_1}\\cdot\\vec{v_2}}{||\\vec{v_1}||\\cdot||\\vec{v_2}||} = \\frac{0}{\\sqrt{2}\\cdot\\sqrt{8}} = \\frac{0}{\\sqrt{16}} = 0$ \n\n$\\therefore$ it is perpendicular.\\\\\n\nb) $$a = \\begin{bmatrix}\n-10\\\\\n5\n\\end{bmatrix} b = \\begin{bmatrix}\n3\\\\\n3\n\\end{bmatrix}$$\n\n$a \\cdot b = \\begin{bmatrix}\n-10\\times3+5\\times3\n\\end{bmatrix} =\n\\begin{bmatrix}\n-15\n\\end{bmatrix}$\n\n$||\\vec{a}|| = \\sqrt{(-10)^2+(5)^2}$\n\n$||\\vec{a}|| = \\sqrt{125}$\n\n$||\\vec{b}|| = \\sqrt{(3)^2+(3)^2}$\n\n$||\\vec{b}|| = \\sqrt{18} $\n\n$\\cos\\theta = \\frac{\\vec{a}\\cdot\\vec{b}}{||\\vec{a}||\\cdot||\\vec{b}||} = \\frac{-15}{\\sqrt{125}\\cdot\\sqrt{18}}$\n\n$\\cos\\theta = -\\frac{15}{\\sqrt{2250}}$\n\n$\\therefore$ it is not perpendicular.\\\\\n\nc) $$v = \\begin{bmatrix}\n3\\\\\n6\n\\end{bmatrix} w = \\begin{bmatrix}\n1\\\\\n2\n\\end{bmatrix}$$\n\n$v \\cdot w = \\begin{bmatrix}\n3\\times1+6\\times2\n\\end{bmatrix} = \\begin{bmatrix}\n15\n\\end{bmatrix}$\n\n$||\\vec{v}|| = \\sqrt{(3)^2+(6)^2}$\n\n$||\\vec{v}|| = \\sqrt{45}$\n\n$||\\vec{w}|| = \\sqrt{(1)^2 + (2)^2}$\n\n$||\\vec{w}|| = \\sqrt{5}$\n\n$\\cos\\theta = \\frac{\\vec{v}\\cdot\\vec{w}}{||\\vec{v}||\\cdot||\\vec{w}||} = \\frac{15}{\\sqrt{45}\\cdot\\sqrt{5}}$\n\n$\\cos\\theta = \\frac{15}{\\sqrt{225}} = 1$\n\n$\\therefore$ it is not perpendicular.\\\\\n\n11) Compute the cosine of the angle formed by the vectors $r = \\begin{bmatrix}\n7\\\\\n-3\n\\end{bmatrix}$ and $m = \\begin{bmatrix}\n2\\\\\n-5\n\\end{bmatrix}$\n\n$r \\cdot m = \\begin{bmatrix}\n7\\times2+(-3)\\times-5\n\\end{bmatrix} = \\begin{bmatrix}\n29\n\\end{bmatrix}$\n\n$||\\vec{r}|| = \\sqrt{(7)^2 + (-3)^2}$\n\n$||\\vec{r}|| = \\sqrt{58}$\n\n$||\\vec{m}|| = \\sqrt{(2)^2 + (-5)^2}$\n\n$||\\vec{m}|| = \\sqrt{29}$\n\n$\\cos\\theta = \\frac{29}{\\sqrt{58}\\cdot\\sqrt{29}} = \\frac{29}{1682} = \\frac{1}{58} > 0$\n\n$\\therefore$ the angle is going to be acute.\\\\\n\n12) Are the following angles acute, obtuse or right angle?\n\n$\\cos\\theta_1 = -0.3$, $\\cos\\theta_2 = 0$, $\\cos\\theta_3 = 0.75$\n\n$\\theta_1$ is an obtuse angle, $\\theta_2$ is a right angle, $\\theta_3$ is an acute angle.\\\\\n\n13) Given the target box $(min_1, min_2) = (4,3)$, $(max_1, max_2) = (6,5)$. Find the local point $(\\frac{1}{2}, \\frac{1}{2})$ in the target box.\n\n$x_1 = (1 - u_1)min_1 + u_1max_1$\n\n$x_1 = (1 - \\frac{1}{2})4 + \\frac{1}{2}6$\n\n$x_1 = 5$\n\n$x_2 = (1-u_2)min_2 + u_2max_2$\n\n$x_2 = (1-\\frac{1}{2})3+\\frac{1}{2}5$\n\n$x_2 = 4$\n\n$\\therefore$ the local point $(\\frac{1}{2},\\frac{1}{2})$ in the target box is $(5,4)$.\\\\\n\n14) Given the target box $(min_1, min_2) = (1,3)$, $(max_1, max_2) = (6,8)$. Find the local point $(\\frac{1}{2},\\frac{1}{4})$ in the target box.\n\n$x_1 = (1 - \\frac{1}{2})1+\\frac{1}{2}6$\n\n$x_1 = 3\\frac{1}{2}$\n\n$x_2 = (1-\\frac{1}{4})3+\\frac{1}{4}8$\n\n$x_2 = 1\\frac{1}{2}+2$\n\n$x_2 = 3\\frac{1}{2}$\n\n$\\therefore$ the local point $(\\frac{1}{2},\\frac{1}{4})$ in the target box is $(3\\frac{1}{2}, 3\\frac{1}{2})$.\\\\\n\n\\end{document}", "meta": {"hexsha": "ad31039638c715e38eba647eda9f24290fa86532", "size": 5589, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/Week3/Week3Notes.tex", "max_stars_repo_name": "aytona/LinearAlgebra", "max_stars_repo_head_hexsha": "2a278b2957bc12456eb4bbc3f4d13b3c06d8d8d1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Notes/Week3/Week3Notes.tex", "max_issues_repo_name": "aytona/LinearAlgebra", "max_issues_repo_head_hexsha": "2a278b2957bc12456eb4bbc3f4d13b3c06d8d8d1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/Week3/Week3Notes.tex", "max_forks_repo_name": "aytona/LinearAlgebra", "max_forks_repo_head_hexsha": "2a278b2957bc12456eb4bbc3f4d13b3c06d8d8d1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.541958042, "max_line_length": 145, "alphanum_fraction": 0.5544820183, "num_tokens": 2634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.9111797106148062, "lm_q1q2_score": 0.7032881350009279}}
{"text": "\\chapter{Generative models for discrete data}\n\n\\section{Generative classifier}\n\\begin{equation}\\label{eqn:Generative-classifier}\np(y=c|\\vec{x},\\vec{\\theta})=\\dfrac{p(y=c|\\vec{\\theta})p(\\vec{x}|y=c,\\vec{\\theta})}{\\sum_{c'}{p(y=c'|\\vec{\\theta})p(\\vec{x}|y=c',\\vec{\\theta})}}\n\\end{equation}\n\nThis is called a \\textbf{generative classifier}, since it specifies how to generate the data using the \\textbf{class conditional density} $p(\\vec{x}|y=c)$ and the class prior $p(y=c)$. An alternative approach is to directly fit the class posterior, $p(y=c|\\vec{x})$ ;this is known as a \\textbf{discriminative classifier}. \n\n\n\\section{Bayesian concept learning}\nPsychological research has shown that people can learn concepts from positive examples alone (Xu and Tenenbaum 2007).\n\nWe can think of learning the meaning of a word as equivalent to \\textbf{concept learning}, which in turn is equivalent to binary classification. To see this, define $f(\\vec{x})=1$ if xis an example of the concept $C$, and $f(\\vec{x})=0$ otherwise. Then the goal is to learn the indicator function $f$, which just defines which elements are in the set $C$.\n\n\n\\subsection{Likelihood}\n\\begin{equation}\np(\\mathcal{D}|h) \\triangleq \\left(\\dfrac{1}{\\text{size}(h)}\\right)^N=\\left(\\dfrac{1}{|h|}\\right)^N\n\\end{equation}\n\nThis crucial equation embodies what Tenenbaum calls the \\textbf{size principle}, which means the model favours the simplest (smallest) hypothesis consistent with the data. This is more commonly known as \\textbf{Occam’s razor}\\footnote{\\url{http://en.wikipedia.org/wiki/Occam\\%27s_razor}}.\n\n\n\\subsection{Prior}\nThe prior is decided by human, not machines, so it is subjective. The subjectivity of the prior is controversial. For example, that a child and a math professor will reach different answers. In fact, they presumably not only have different priors, but also different hypothesis spaces. However, we can finesse that by defining the hypothesis space of the child and the math professor to be the same, and then setting the child’s prior weight to be zero on certain “advanced” concepts. Thus there is no sharp distinction between the prior and the hypothesis space.\n\nHowever, the prior is the mechanism by which background knowledge can be brought to bear on a problem. Without this, rapid learning (i.e., from small samples sizes) is impossible.\n\n\n\\subsection{Posterior}\nThe posterior is simply the likelihood times the prior, normalized.\n\\begin{equation}\np(h|\\mathcal{D}) \\triangleq \\dfrac{p(\\mathcal{D}|h)p(h)}{\\sum_{h' \\in \\mathcal{H}}p(\\mathcal{D}|h')p(h')}=\\dfrac{\\mathbb{I}(\\mathcal{D} \\in h)p(h)}{\\sum_{h' \\in \\mathcal{H}}\\mathbb{I}(\\mathcal{D} \\in h')p(h')}\n\\end{equation}\nwhere $\\mathbb{I}(\\mathcal{D} \\in h)p(h)$ is 1 \\textbf{iff}(iff and only if) all the data are in the extension of the hypothesis $h$.\n\nIn general, when we have enough data, the posterior $p(h|\\mathcal{D})$ becomes peaked on a single concept, namely the MAP estimate, i.e.,\n\\begin{equation}\np(h|\\mathcal{D}) \\rightarrow \\hat{h}^{MAP}\n\\end{equation}\nwhere $\\hat{h}^{MAP}$ is the posterior mode,\n\\begin{equation}\\begin{split}\n\\hat{h}^{MAP} & \\triangleq \\arg\\max\\limits_h p(h|\\mathcal{D})=\\arg\\max\\limits_h p(\\mathcal{D}|h)p(h) \\\\\n    & =\\arg\\max\\limits_h [\\log p(\\mathcal{D}|h) + \\log p(h)]\n\\end{split}\\end{equation}\n\nSince the likelihood term depends exponentially on $N$, and the prior stays constant, as we get more and more data, the MAP estimate converges towards the \\textbf{maximum likelihood estimate} or \\textbf{MLE}:\n\\begin{equation}\n\\hat{h}^{MLE} \\triangleq \\arg\\max\\limits_h p(\\mathcal{D}|h)=\\arg\\max\\limits_h \\log p(\\mathcal{D}|h)\n\\end{equation}\n\nIn other words, if we have enough data, we see that the \\textbf{data overwhelms the prior}.\n\n\n\\subsection{Posterior predictive distribution}\nThe concept of \\textbf{posterior predictive distribution}\\footnote{\\url{http://en.wikipedia.org/wiki/Posterior_predictive_distribution}} is normally used in a Bayesian context, where it makes use of the entire posterior distribution of the parameters given the observed data to yield a probability distribution over an interval rather than simply a point estimate. \n\\begin{equation}\np(\\tilde{\\vec{x}}|\\mathcal{D}) \\triangleq \\mathbb{E}_{h|\\mathcal{D}}[p(\\tilde{\\vec{x}}|h)] = \\begin{cases}\n\\sum_h p(\\tilde{\\vec{x}}|h)p(h|\\mathcal{D}) \\\\\n\\int p(\\tilde{\\vec{x}}|h)p(h|\\mathcal{D})\\mathrm{d}h\n\\end{cases}\n\\end{equation}\n\nThis is just a weighted average of the predictions of each individual hypothesis and is called \\textbf{Bayes model averaging}(Hoeting et al. 1999). \n\n\n\\section{The beta-binomial model}\n\n\n\\subsection{Likelihood}\nGiven $X \\sim \\text{Bin}(\\theta)$, the likelihood of $\\mathcal{D}$ is given by\n\\begin{equation}\np(\\mathcal{D}|\\theta)= \\text{Bin}(N_1|N,\\theta)\n\\end{equation}\n\n\n\\subsection{Prior}\n\\begin{equation}\n\\text{Beta}(\\theta|a,b) \\propto \\theta^{a-1}(1-\\theta)^{b-1}\n\\end{equation}\n\nThe parameters of the prior are called \\textbf{hyper-parameters}.\n\n\n\\subsection{Posterior}\n\\begin{equation}\\begin{split}\\label{eqn:beta-binomial-posterior}\np(\\theta|\\mathcal{D}) & \\propto \\text{Bin}(N_1|N_1+N_0,\\theta)\\text{Beta}(\\theta|a,b) \\\\\n    & =\\text{Beta}(\\theta|N_1+a,N_0b)\n\\end{split}\\end{equation}\n\nNote that updating the posterior sequentially is equivalent to updating in a single batch. To see this, suppose we have two data sets $\\mathcal{D}_a$ and $\\mathcal{D}_b$ with sufficient statistics $N_1^a,N_0^a$ and $N_1^b,N_0^b$. Let $N_1=N_1^a+N_1^b$ and $N_0=N_0^a+N_0^b$ be the sufficient statistics of the combined datasets. In batch mode we have\n\\begin{align*}\np(\\theta|\\mathcal{D}_a,\\mathcal{D}_b)& = p(\\theta,\\mathcal{D}_b|\\mathcal{D}_a)p(\\mathcal{D}_a) \\\\\n               &\\propto p(\\theta,\\mathcal{D}_b|\\mathcal{D}_a) \\\\\n               & = p(\\mathcal{D}_b,\\theta|\\mathcal{D}_a) \\\\\n\t\t\t   & = p(\\mathcal{D}_b|\\theta)p(\\theta|\\mathcal{D}_a) \\\\\n\t\t\t   & \\text{Combine Equation \\ref{eqn:beta-binomial-posterior} and \\ref{eqn:binomial-pmf}} \\\\\n\t\t\t   & =\\text{Bin}(N_1^b|\\theta, N_1^b+N_0^b)\\text{Beta}(\\theta|N_1^a+a,N_0^a+b) \\\\\n\t\t\t   & =\\text{Beta}(\\theta|N_1^a+N_1^b+a,N_0^a+N_0^b+b)\n\\end{align*}\n\nThis makes Bayesian inference particularly well-suited to \\textbf{online learning}, as we will see later.\n\n\\subsubsection{Posterior mean and mode}\n\\label{sec:beta-binomial-Posterior-mean-and-mode}\nFrom Table \\ref{tab:beta-distribution}, the posterior mean is given by\n\\begin{equation}\n\\bar{\\theta}=\\dfrac{a+N_1}{a+b+N}\n\\end{equation}\n\nThe mode is given by\n\\begin{equation}\n\\hat{\\theta}_{MAP}=\\dfrac{a+N_1-1}{a+b+N-2}\n\\end{equation}\n\nIf we use a uniform prior, then the MAP estimate reduces to the MLE,\n\\begin{equation}\n\\hat{\\theta}_{MLE}=\\dfrac{N_1}{N}\n\\end{equation}\n\nWe will now show that the posterior mean is convex combination of the prior mean and the MLE, which captures the notion that the posterior is a compromise between what we previously believed and what the data is telling us.\n\n\\subsubsection{Posterior variance}\nThe mean and mode are point estimates, but it is useful to know how much we can trust them. The variance of the posterior is one way to measure this. The variance of the Beta posterior is given by\n\\begin{equation}\n\\text{var}(\\theta|\\mathcal{D})=\\dfrac{(a+N_1)(b+N_0)}{(a+N_1+b+N_0)^2(a+N_1+b+N_0+1)}\n\\end{equation}\n\nWe can simplify this formidable expression in the case that $N \\gg a, b$, to get\n\\begin{equation}\n\\text{var}(\\theta|\\mathcal{D}) \\approx \\dfrac{N_1N_0}{NNN}=\\dfrac{\\hat{\\theta}_{MLE}(1-\\hat{\\theta}_{MLE})}{N}\n\\end{equation}\n\n\n\\subsection{Posterior predictive distribution}\nSo far, we have been focusing on inference of the unknown parameter(s). Let us now turn our attention to prediction of future observable data.\n\nConsider predicting the probability of heads in a single future trial under a Beta$(a, b)$posterior. We have\n\\begin{align}\np(\\tilde{x}|\\mathcal{D})& =\\int_0^1 p(\\tilde{x}|\\theta)p(\\theta|\\mathcal{D})\\mathrm{d}\\theta \\nonumber \\\\\n                        & =\\int_0^1 \\theta\\text{Beta}(\\theta|a,b)\\mathrm{d}\\theta \\nonumber \\\\\n\t\t\t\t\t\t& =\\mathbb{E}[\\theta|\\mathcal{D}]=\\dfrac{a}{a+b}\n\\end{align}\n\n\\subsubsection{Overfitting and the black swan paradox}\nLet us now derive a simple Bayesian solution to the problem. We will use a uniform prior, so $a=b=1$. In this case, plugging in the posterior mean gives \\textbf{Laplace’s rule of succession}\n\\begin{equation}\np(\\tilde{x}|\\mathcal{D})=\\dfrac{N_1+1}{N_0+N_1+1}\n\\end{equation}\n\nThis justifies the common practice of adding 1 to the empirical counts, normalizing and then plugging them in, a technique known as \\textbf{add-one smoothing}. (Note that plugging in the MAP parameters would not have this smoothing effect, since the mode becomes the MLE if $a=b=1$, see Section \\ref{sec:beta-binomial-Posterior-mean-and-mode}.)\n\n\\subsubsection{Predicting the outcome of multiple future trials}\nSuppose now we were interested in predicting the number of heads, $\\tilde{x}$, in $M$ future trials. This is given by\n\\begin{align}\np(\\tilde{x}|\\mathcal{D})& =\\int_0^1 \\text{Bin}(\\tilde{x}|M,\\theta)\\text{Beta}(\\theta|a,b)\\mathrm{d}\\theta \\\\\n                        & =\\dbinom{M}{\\tilde{x}}\\dfrac{1}{B(a,b)}\\int_0^1 \\theta^{\\tilde{x}}(1-\\theta)^{M-\\tilde{x}}\\theta^{a-1}(1-\\theta)^{b-1}\\mathrm{d}\\theta\n\\end{align}\n\nWe recognize the integral as the normalization constant for a Beta$(a+\\tilde{x}, M−\\tilde{x}+b)$ distribution. Hence\n\\begin{equation}\n\\int_0^1 \\theta^{\\tilde{x}}(1-\\theta)^{M-\\tilde{x}}\\theta^{a-1}(1-\\theta)^{b-1}\\mathrm{d}\\theta=B(\\tilde{x}+a,M-\\tilde{x}+b)\n\\end{equation}\n\nThus we find that the posterior predictive is given by the following, known as the (compound) \\textbf{beta-binomial distribution}:\n\\begin{equation}\nBb(x|a,b,M) \\triangleq \\dbinom{M}{x}\\dfrac{B(x+a,M-x+b)}{B(a,b)}\n\\end{equation}\n\nThis distribution has the following mean and variance\n\\begin{equation}\n\\text{mean}=M\\dfrac{a}{a+b} \\text{ , var}=\\dfrac{Mab}{(a+b)^2}\\dfrac{a+b+M}{a+b+1}\n\\end{equation}\n\nThis process is illustrated in Figure \\ref{fig:beta-binomial-distribution}. We start with a Beta$(2,2)$ prior, and plot the posterior predictive density after seeing $N_1 =3$ heads and $N_0 =17$ tails. Figure \\ref{fig:beta-binomial-distribution}(b) plots a plug-in approximation using a MAP estimate. We see that the Bayesian prediction has longer tails, spreading its probability mass more widely, and is therefore less prone to overfitting and blackswan type paradoxes.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.60]{beta-binomial-distribution-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{beta-binomial-distribution-b.png}}\n\\caption{(a) Posterior predictive distributions after seeing $N_1=3,N_0=17$. (b) MAP estimation.}\n\\label{fig:beta-binomial-distribution} \n\\end{figure}\n\n\n\\section{The Dirichlet-multinomial model}\nIn the previous section, we discussed how to infer the probability that a coin comes up heads. In this section, we generalize these results to infer the probability that a dice with $K$ sides comes up as face $k$. \n\n\n\\subsection{Likelihood}\nSuppose we observe $N$ dice rolls, $\\mathcal{D}=\\{x_1,x_2,\\cdots,x_N\\}$, where $x_i \\in \\{1,2,\\cdots,K\\}$. The likelihood has the form\n\\begin{equation}\np(\\mathcal{D}|\\vec{\\theta}) = \\dbinom{N}{N_1 \\cdots N_k} \\prod\\limits_{k=1}^K\\theta_k^{N_k} \\quad \\text{where } N_k=\\sum\\limits_{i=1}^N \\mathbb{I}(y_i=k)\n\\end{equation}\nalmost the same as Equation \\ref{eqn:multinomial-pmf}.\n\n\n\\subsection{Prior}\n\\begin{equation}\n\\text{Dir}(\\vec{\\theta}|\\vec{\\alpha}) = \\dfrac{1}{B(\\vec{\\alpha})}\\prod\\limits_{k=1}^K \\theta_k^{\\alpha_k-1}\\mathbb{I}(\\vec{\\theta} \\in S_K)\n\\end{equation}\n\n\n\\subsection{Posterior}\n\\begin{align}\np(\\vec{\\theta}|\\mathcal{D})& \\propto p(\\mathcal{D}|\\vec{\\theta})p(\\vec{\\theta}) \\\\\n     & \\propto \\prod\\limits_{k=1}^K\\theta_k^{N_k}\\theta_k^{\\alpha_k-1} = \\prod\\limits_{k=1}^K\\theta_k^{N_k+\\alpha_k-1}\\\\\n\t & =\\text{Dir}(\\vec{\\theta}|\\alpha_1+N_1,\\cdots,\\alpha_K+N_K)\n\\end{align}\n\nFrom Equation \\ref{eqn:Dirichlet-properties}, the MAP estimate is given by\n\\begin{equation}\\label{eqn:Dir-MAP}\n\\hat{\\theta}_k=\\dfrac{N_k+\\alpha_k-1}{N+\\alpha_0-K}\n\\end{equation}\n\nIf we use a uniform prior, $\\alpha_k=1$, we recover the MLE:\n\\begin{equation}\\label{eqn:Dirichlet-multinomial-posterior-MLE}\n\\hat{\\theta}_k=\\dfrac{N_k}{N}\n\\end{equation}\n\n\n\\subsection{Posterior predictive distribution}\nThe posterior predictive distribution for a single multinoulli trial is given by the following expression:\n\\begin{align}\np(X=j|\\mathcal{D})& =\\int p(X=j|\\vec{\\theta})p(\\vec{\\theta}|\\mathcal{D})\\mathrm{d}\\vec{\\theta} \\\\\n    & =\\int p(X=j|\\theta_j)\\left[\\int p(\\vec{\\theta}_{-j}, \\theta_j|\\mathcal{D})\\mathrm{d}\\vec{\\theta}_{-j}\\right]\\mathrm{d}\\theta_j \\\\\n\t& =\\int \\theta_jp(\\theta_j|\\mathcal{D})\\mathrm{d}\\theta_j=\\mathbb{E}[\\theta_j|\\mathcal{D}]=\\dfrac{\\alpha_j+N_j}{\\alpha_0+N}\n\\end{align}\nwhere $\\vec{\\theta}_{-j}$ are all the components of \\vec{\\theta} except $\\theta_j$.\n\nThe above expression avoids the zero-count problem. In fact, this form of Bayesian smoothing is even more important in the multinomial case than the binary case, since the likelihood of data sparsity increases once we start partitioning the data into many categories.\n\n\n\\section{Naive Bayes classifiers}\n\\label{sec:NBC}\nAssume the features are \\textbf{conditionally independent} given the class label, then the class conditional density has the following form\n\\begin{equation}\np(\\vec{x}|y=c,\\vec{\\theta})=\\prod\\limits_{j=1}^D p(x_j|y=c,\\vec{\\theta}_{jc})\n\\end{equation}\n\nThe resulting model is called a \\textbf{naive Bayes classifier}(NBC).\n\nThe form of the class-conditional density depends on the type of each feature. We give some possibilities below:\n\\begin{itemize}\n\\item{In the case of real-valued features, we can use the Gaussian distribution: $p(\\vec{x}|y,\\vec{\\theta})=\\prod_{j=1}^D \\mathcal{N}(x_j|\\mu_{jc},\\sigma_{jc}^2)$, where $\\mu_{jc}$ is the mean of feature $j$ in objects of class $c$, and $\\sigma_{jc}^2$ is its variance.}\n\\item{In the case of binary features, $x_j \\in \\{0,1\\}$, we can use the Bernoulli distribution: $p(\\vec{x}|y,\\vec{\\theta})=\\prod_{j=1}^D \\text{Ber}(x_j|\\mu_{jc})$, where $\\mu_{jc}$ is the probability that feature $j$ occurs in class $c$. This is sometimes called the \\textbf{multivariate Bernoulli naive Bayes} model. We will see an application of this below.}\n\\item{In the case of categorical features, $x_j \\in \\{a_{j1},a_{j2},\\cdots, a_{jS_j}\\}$, we can use the multinoulli distribution: $p(\\vec{x}|y,\\vec{\\theta})=\\prod_{j=1}^D \\text{Cat}(x_j|\\vec{\\mu}_{jc})$, where $\\vec{\\mu}_{jc}$ is a histogram over the $K$ possible values for $x_j$ in class $c$.}\n\\end{itemize}\n\nObviously we can handle other kinds of features, or use different distributional assumptions. Also, it is easy to mix and match features of different types.\n\n\n\\subsection{Optimization}\n\\label{sec:NBC-Optimization}\nWe now discuss how to “train” a naive Bayes classifier. This usually means computing the MLE or the MAP estimate for the parameters. However, we will also discuss how to compute the full posterior, $p(\\vec{\\theta}|\\mathcal{D})$.\n\n\\subsubsection{MLE for NBC}\nThe probability for a single data case is given by\n\\begin{equation}\\begin{split}\np(\\vec{x}_i,y_i|\\vec{\\theta}) & =p(y_i|\\vec{\\pi})\\prod\\limits_j p(x_{ij}|\\vec{\\theta}_j) \\\\\n  & =\\prod\\limits_c \\pi_c^{\\mathbb{I}(y_i=c)} \\prod\\limits_j\\prod\\limits_c p(x_{ij}|\\vec{\\theta}_{jc})^{\\mathbb{I}(y_i=c)}\n\\end{split}\\end{equation}\n\nHence the log-likelihood is given by\n\\begin{equation}\np(\\mathcal{D}|\\vec{\\theta})=\\sum\\limits_{c=1}^C{N_c\\log\\pi_c}+ \\sum\\limits_{j=1}^D{\\sum\\limits_{c=1}^C{\\sum\\limits_{i:y_i=c}{\\log p(x_{ij}|\\vec{\\theta}_{jc})}}}\n\\end{equation}\nwhere $N_c \\triangleq \\sum\\limits_i \\mathbb{I}(y_i=c)$ is the number of feature vectors in class $c$.\n\nWe see that this expression decomposes into a series of terms, one concerning $\\vec{\\pi}$, and $DC$ terms containing the $\\theta_{jc}$’s. Hence we can optimize all these parameters separately.\n\nFrom Equation \\ref{eqn:Dirichlet-multinomial-posterior-MLE}, the MLE for the class prior is given by\n\\begin{equation}\n\\hat{\\pi}_c=\\dfrac{N_c}{N}\n\\end{equation}\n\nThe MLE for $\\theta_{jc}$’s depends on the type of distribution we choose to use for each feature. \n\nIn the case of binary features, $x_j \\in \\{0,1\\}$, $x_j|y=c \\sim \\text{Ber}(\\theta_{jc})$, hence\n\\begin{equation}\n\\hat{\\theta}_{jc}=\\dfrac{N_{jc}}{N_c}\n\\end{equation}\nwhere $N_{jc} \\triangleq \\sum\\limits_{i:y_i=c} \\mathbb{I}(y_i=c)$ is the number that feature $j$ occurs in class $c$.\n\nIn the case of categorical features, $x_j \\in \\{a_{j1},a_{j2},\\cdots, a_{jS_j}\\}$, $x_j|y=c \\sim \\text{Cat}(\\vec{\\theta}_{jc})$, hence\n\\begin{equation}\n\\hat{\\vec{\\theta}}_{jc}=(\\dfrac{N_{j1c}}{N_c},\\dfrac{N_{j2c}}{N_c}, \\cdots, \\dfrac{N_{jS_j}}{N_c})^T\n\\end{equation}\nwhere $N_{jkc} \\triangleq \\sum\\limits_{i=1}^N \\mathbb{I}(x_{ij}=a_{jk}, y_i=c)$ is the number that feature $x_j=a_{jk}$ occurs in class $c$.\n\n\n\\subsubsection{Bayesian naive Bayes}\n\\label{sec:Bayesian-naive-Bayes}\nUse a Dir$(\\vec{\\alpha})$ prior for $\\vec{\\pi}$.\n\nIn the case of binary features, use a Beta$(\\beta0,\\beta1)$ prior for each $\\theta_{jc}$; in the case of categorical features, use a Dir$(\\vec{\\alpha})$ prior for each  $\\vec{\\theta}_{jc}$. Often we just take $\\vec{\\alpha}=\\vec{1}$ and $\\vec{\\beta}=\\vec{1}$, corresponding to \\textbf{add-one} or \\textbf{Laplace smoothing}.\n\n\n\\subsection{Using the model for prediction}\nThe goal is to compute\n\\begin{equation}\\begin{split}\ny=f(\\vec{x}) & =\\arg\\max\\limits_{c}{P(y=c|\\vec{x},\\vec{\\theta})} \\\\\n   & =P(y=c|\\vec{\\theta})\\prod_{j=1}^D P(x_j|y=c,\\vec{\\theta})\n\\end{split}\\end{equation}\n\nWe can the estimate parameters using MLE or MAP, then the posterior predictive density is obtained by simply plugging in the parameters $\\bar{\\vec{\\theta}}$(MLE) or $\\hat{\\vec{\\theta}}$(MAP). \n\nOr we can use BMA, just integrate out the unknown parameters.\n\n\n\\subsection{The log-sum-exp trick}\nwhen using generative classifiers of any kind, computing the posterior over class labels using Equation \\ref{eqn:Generative-classifier} can fail due to \\textbf{numerical underflow}. The problem is that $p(\\vec{x}|y=c)$ is often a very small number, especially if \\vec{x} is a high-dimensional vector. This is because we require that $\\sum_{\\vec{x}}p(\\vec{x}|y)=1$, so the probability of observing any particular high-dimensional vector is small. The obvious solution is to take logs when applying Bayes rule, as follows:\n\\begin{equation}\n\\log p(y=c|\\vec{x},\\vec{\\theta})=b_c-\\log\\left(\\sum\\limits_{c'}e^{b_{c'}}\\right)\n\\end{equation}\nwhere $b_c \\triangleq \\log p(\\vec{x}|y=c,\\vec{\\theta})+\\log p(y=c|\\vec{\\theta})$.\n\nWe can factor out the largest term, and just represent the remaining numbers relative to that. For example,\n\\begin{equation}\\begin{split}\n\\log(e^{-120}+e^{-121}) & =\\log(e^{-120}(1+e^{-1})) \\\\\n   & =\\log(1+e^{-1})-120\n\\end{split}\\end{equation}\n\nIn general, we have\n\\begin{equation}\n\\sum\\limits_{c}e^{b_{c}}=\\log\\left[(\\sum e^{b_c-B})e^B\\right]=\\log\\left(\\sum e^{b_c-B}\\right)+B\n\\end{equation}\nwhere $B \\triangleq \\max\\{b_c\\}$.\n\nThis is called the \\textbf{log-sum-exp} trick, and is widely used. \n\n\n\\subsection{Feature selection using mutual information}\nSince an NBC is fitting a joint distribution over potentially many features, it can suffer from overfitting. In addition, the run-time cost is $O(D)$, which may be too high for some applications. \n\nOne common approach to tackling both of these problems is to perform \\textbf{feature selection}, to remove “irrelevant” features that do not help much with the classification problem. The simplest approach to feature selection is to evaluate the relevance of each feature separately, and then take the top K,whereKis chosen based on some tradeoff between accuracy and complexity. This approach is known as \\textbf{variable ranking}, \\textbf{filtering}, or \\textbf{screening}.\n\nOne way to measure relevance is to use mutual information (Section \\ref{sec:Mutual-information}) between feature $X_j$ and the class label $Y$\n\\begin{equation}\n\\mathbb{I}(X_j,Y)=\\sum\\limits_{x_j}{\\sum\\limits_{y}{p(x_j,y)\\log \\dfrac{p(x_j,y)}{p(x_j)p(y)}}}\n\\end{equation}\n\nIf the features are binary, it is easy to show that the MI can be computed as follows\n\\begin{equation}\n\\mathbb{I}_j = \\sum\\limits_c \\left[\\theta_{jc}\\pi_c\\log{\\dfrac{\\theta_{jc}}{\\theta_j}}+(1-\\theta_{jc})\\pi_c\\log{\\dfrac{1-\\theta_{jc}}{1-\\theta_j}}\\right]\n\\end{equation}\nwhere $\\pi_c=p(y=c)$, $\\theta_{jc}=p(x_j=1|y=c)$, and $\\theta_j=p(x_j=1)=\\sum_{c} \\pi_c\\theta_{jc}$.\n\n\n\\subsection{Classifying documents using bag of words}\n\\textbf{Document classification} is the problem of classifying text documents into different categories.\n\n\n\\subsubsection{Bernoulli product model}\nOne simple approach is to represent each document as a binary vector, which records whether each word is present or not, so $x_{ij} =1$ iff word $j$ occurs in document $i$, otherwise $x_{ij}=0$. We can then use the following class conditional density:\n\\begin{equation}\\begin{split}\np(\\vec{x}_i|y_i=c,\\vec{\\theta}) & =\\prod\\limits_{j=1}^D \\mathrm{Ber}(x_{ij}|\\theta_{jc}) \\\\\n  & =\\prod\\limits_{j=1}^D \\theta_{jc}^{x_{ij}}(1-\\theta_{jc})^{1-x_{ij}}\n\\end{split}\\end{equation}\n\nThis is called the \\textbf{Bernoulli product model}, or the \\textbf{binary independence model}.\n\n\\subsubsection{Multinomial document classifier}\nHowever, ignoring the number of times each word occurs in a document loses some information (McCallum and Nigam 1998). A more accurate representation counts the number of occurrences of each word. Specifically, let $\\vec{x}_i$ be a vector of counts for document $i$, so $x_{ij} \\in \\{0,1,\\cdots,N_i\\}$, where $N_i$ is the number of terms in document $i$(so $\\sum\\limits_{j=1}^D x_{ij}=N_i$). For the class conditional densities, we can use a multinomial distribution:\n\\begin{equation}\\label{eqn:Multinomial-document-classifier}\np(\\vec{x}_i|y_i=c,\\vec{\\theta})=\\text{Mu}(\\vec{x}_i|N_i,\\vec{\\theta}_c)=\\dfrac{N_i!}{\\prod_{j=1}^D x_{ij}!}\\prod\\limits_{j=1}^D \\theta_{jc}^{x_{ij}}\n\\end{equation}\nwhere we have implicitly assumed that the document length $N_i$ is independent of the class. Here $θ_{jc}$ is the probability of generating word $j$ in documents of class $c$; these parameters satisfy the constraint that $\\sum_{j=1}^D \\theta_{jc}=1$ for each class c.\n\nAlthough the multinomial classifier is easy to train and easy to use at test time, it does not work particularly well for document classification. One reason for this is that it does not take into account the \\textbf{burstiness} of word usage. This refers to the phenomenon that most words never appear in any given document, but if they do appear once, they are likely to appear more than once, i.e., words occur in bursts.\n\nThe multinomial model cannot capture the burstiness phenomenon. To see why, note that Equation \\ref{eqn:Multinomial-document-classifier} has the form $\\theta_{jc}^{x_{ij}}$, and since $\\theta_{jc} \\ll 1$ for rare words, it becomes increasingly unlikely to generate many of them. For more frequent words, the decay rate is not as fast. To see why intuitively, note that the most frequent words are function words which are not specific to the class, such as “and”, “the”, and “but”; the chance of the word “and” occuring is pretty much the same no matter how many time it has previously occurred (modulo document length), so the independence assumption is more reasonable for common words. However, since rare words are the ones that matter most for classification purposes, these are the ones we want to model the most carefully.\n\n\\subsubsection{DCM model}\nVarious ad hoc heuristics have been proposed to improve the performance of the multinomial document classifier (Rennie et al. 2003). We now present an alternative class conditional density that performs as well as these ad hoc methods, yet is probabilistically sound (Madsen et al. 2005).\n\nSuppose we simply replace the multinomial class conditional density with the \\textbf{Dirichlet Compound Multinomial} or \\textbf{DCM} density, defined as follows:\n\\begin{equation}\\begin{split}\np(\\vec{x}_i|y_i=c,\\vec{\\alpha}) & =\\int \\text{Mu}(\\vec{x}_i|N_i,\\vec{\\theta}_c)\\text{Dir}(\\vec{\\theta}_c|\\vec{\\alpha}_c) \\\\\n   & =\\dfrac{N_i!}{\\prod_{j=1}^D x_{ij}!}\\prod\\limits_{j=1}^D\\dfrac{B(\\vec{x}_i+\\vec{\\alpha}_c)}{B(\\vec{\\alpha}_c)}\n\\end{split}\\end{equation}\n\n(This equation is derived in Equation TODO.) Surprisingly this simple change is all that is needed to capture the burstiness phenomenon. The intuitive reason for this is as follows: After seeing one occurence of a word, say wordj, the posterior counts on θj gets updated, making another occurence of wordjmore likely. By contrast, ifθj is fixed, then the occurences of each word are independent. The multinomial model corresponds to drawing a ball from an urn with Kcolors of ball, recording its color, and then replacing it. By contrast, the DCM model corresponds to drawing a ball, recording its color, and then replacing it with one additional copy; this is called the \\textbf{Polya urn}.\n\nUsing the DCM as the class conditional density gives much better results than using the multinomial, and has performance comparable to state of the art methods, as described in (Madsen et al. 2005). The only disadvantage is that fitting the DCM model is more complex; see (Minka 2000e; Elkan 2006) for the details.\n", "meta": {"hexsha": "71ff81b7903db2c0c3811583be5055abd3f9d663", "size": 25229, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/GenerativeModels.tex", "max_stars_repo_name": "Alexoner/Statistical-formula", "max_stars_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-02-15T17:00:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-24T13:46:00.000Z", "max_issues_repo_path": "prml/GenerativeModels.tex", "max_issues_repo_name": "Alexoner/Statistical-formula", "max_issues_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "prml/GenerativeModels.tex", "max_forks_repo_name": "Alexoner/Statistical-formula", "max_forks_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-02-25T15:40:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-25T04:26:03.000Z", "avg_line_length": 65.1912144703, "max_line_length": 829, "alphanum_fraction": 0.7272979508, "num_tokens": 7846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.819893335913536, "lm_q1q2_score": 0.7032783649649076}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage[letterpaper, total={7.5in, 9in}]{geometry}\n\n\\title{Linear Algebra}\n\\author{Grant Smith}\n\\date{Spring 2022}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{The Four Subspaces}\n\nFirst of all, we know that there is a row space and a column space. We also know that the column space of $A$ is the row space of $A^T$ and the row space of $A$ is the column space of $A^T$. Next are questions about the null space.  But first, I want to discuss how Gaussian Elimination changes (or doesn't change) the row space.\n\\subsection{Gaussian Elimination} \nGaussian Elimination does not change the row space. We'll prove this in a couple steps. First of all, we have to prove that Gaussian Elimination doesn't generate rows outside of the original row space, and then we have to prove that it doesn't remove anything from the original space. First, we show that it doesn't add anything to the space. This is because whenever Gaussian Elimination is being used, the rows are just being added and scaled. Which means all of the row vectors in the end are linear combinations of the original row vectors we had. So we know that it didn't add any row vectors that weren't there previously. Next we need to prove that it doesn't take anything away. And right now, I don't know how to prove this.\n\nAlso, just to be clear, Gaussian Elimination does indeed change the column space, but it doesn't change it's dimension. We'll prove the part about it not changing the dimension, but the best way to see that it does change the column space is to think about a matrix: \n\n$$\\begin{bmatrix}\n  1  & 5 \\\\\n  2  & 10 \\\\\n   \\end{bmatrix}$$\n\nAnd with Gaussian Elimination, that is:\n\n$$\\begin{bmatrix}\n    1  & 5 \\\\\n    0  & 0 \\\\\n\\end{bmatrix}$$\n\nWhich certainly has a different column space, but the column space has the same dimension, which, again, we will show soon.\n\\subsection{The Row Space and the Column Space dimensions are equal}\nFirst of all, let's start with an $m \\times n$ matrix called $A$. \n\n$$A = \\begin{bmatrix}\n    a_{1,1} & \\dots & a_{1,n} \\\\\n    \\vdots & \\ddots &  \\\\\n    a_{m,1}&  & a_{m,n} \\\\\n\\end{bmatrix}$$\n\nNotice that the dimension of the row space and the column space are both at most $\\min (m,n)$. This is because if $m$ is bigger, then we have $m$ rows, but they are only $n$ wide, so they can't span a space with higher dimension than $n$.  And for the columns, we only have $n$ columns, so they can't span a space of dimension $> n$. The same argument would work for if $n$ was bigger. This is nice because it sets a ceiling on the two dimensions, and they are the same for the rows and columns. So this is just a hint and a nice fact, but it doesn't prove that they're the same.\n\nNext, let's say the column space is $b$ dimensional, and $b \\leq \\min (m,n)$. Then there is a basis of $b$ column vectors (each of which is $m$-dimensional) that can be used to create our matrix. So let's arrange those into a matrix $B$.  And since those column vectors span the row space of $A$, we can write $A = BC$ where the columns of $C$ are the linear weightings of $B$'s columns that make $A$'s columns.\n\n$$A = \\begin{bmatrix}\n    a_{1,1} & \\dots & a_{1,b}  & \\dots & a_{1,n} \\\\\n    \\vdots & \\ddots &  \\vdots & \\ddots & \\vdots \\\\\n    a_{b,1} & \\dots & a_{b,b} & \\dots & a_{b,n} \\\\\n    \\vdots & \\ddots & \\vdots & \\ddots & \\vdots \\\\\n    a_{m,1}& \\dots & a_{m,b} & \\dots & a_{m,n} \\\\\n\\end{bmatrix} = \\begin{bmatrix}\n    b_{1,1} & \\dots & b_{1,b}\\\\\n    \\vdots & \\ddots &  \\vdots \\\\\n    b_{b,1} & \\dots & b_{b,b} \\\\\n    \\vdots & \\ddots & \\vdots \\\\\n    b_{m,1}& \\dots & b_{m,b} \\\\\n\\end{bmatrix}\\begin{bmatrix}\n    c_{1,1} & \\dots & c_{1,b}  & \\dots & c_{1,n} \\\\\n    \\vdots & \\ddots &  \\vdots & \\ddots & \\vdots \\\\\n    c_{b,1} & \\dots & c_{b,b} & \\dots & c_{b,n} \\\\\n\n\\end{bmatrix}$$\n\nBut we could also view this as a statement about $C$'s rows spanning $A$'s rows. So that means that $dim (row(A)) \\leq dim(col A)$\n\nLet's do a similar argument, but by spanning the row space initially instead of the column space. let's say the row space is $e$ dimensional. Then we can write the rows of $A$ as linear combinations of $e$ row vectors, and let's put those into a matrix $E$. Now we can say that $A = DE$ where $D$ contains the weightings of $E$'s row vectors that make $A$'s row vectors.  Thus, we have  \n\n$$A = \\begin{bmatrix}\n    a_{1,1} & \\dots & a_{1,e}  & \\dots & a_{1,n} \\\\\n    \\vdots & \\ddots &  \\vdots & \\ddots & \\vdots \\\\\n    a_{e,1} & \\dots & a_{e,e} & \\dots & a_{e,n} \\\\\n    \\vdots & \\ddots & \\vdots & \\ddots & \\vdots \\\\\n    a_{m,1}& \\dots & a_{m,e} & \\dots & a_{m,n} \\\\\n\\end{bmatrix} = \\begin{bmatrix}\n    d_{1,1} & \\dots & d_{1,e}\\\\\n    \\vdots & \\ddots &  \\vdots \\\\\n    d_{e,1} & \\dots & d_{e,e} \\\\\n    \\vdots & \\ddots & \\vdots \\\\\n    d_{m,1}& \\dots & d_{m,e} \\\\\n\\end{bmatrix}\\begin{bmatrix}\n    e_{1,1} & \\dots & e_{1,e}  & \\dots & e_{1,n} \\\\\n    \\vdots & \\ddots &  \\vdots & \\ddots & \\vdots \\\\\n    e_{e,1} & \\dots & e_{e,e} & \\dots & e_{e,n} \\\\\n\n\\end{bmatrix}$$\n\nWhich means that $A$'s columns can be spanned by $e$ or fewer columns, where $e$ was the dimension of the row space. This means that $dim (row(A)) \\geq dim(col A)$ but now we have both sides of the inequality, so the two dimensions are equal. \n\nAnd this means that $e = b$, so the two factorizations above are the same dimension. They don't have to be the exact same because there are many available bases for the two spaces, but they are at least the same dimension. \n\nThanks to Sean Owen on Quora for this explanation.\n\n\\subsection{Back To Gauss Jordan}\n\nNow that we know the dimension of the row space is equal to the dimension of the column space, We can combine that with what we know about Gaussian Elimination not changing the row space: if the row space dimension and the column space dimension of any matrix are equal, and Gaussian Elimination does not change the row space at all (let alone its dimension), then Gaussian Elimination doesn't change the column space dimension.\n\n\\subsection{Back to the end of the Row Space and The Column Space Being Equal Section}\n\nAt this point, we could make one of those two matrices orthogonal or orthonormal. That would be nice because orthogonal and orthonormal bases are great. The problem is we can only really do one at a time. For example, if we make $C (or E)$ orthonormal (and there are infinite options of orthonormal bases), then that specifies the weightings on $B (or D)$.  And vice versa if we chose to make the left matrix orthonormal, then that would change the numbers in the right matrix. \n\nBut! If you choose your orthonormal vectors just right on either side (i.e. choose the right one of the infinite options), then you can allow the vectors on the other side to be orthogonal as well, and you can factor out their sizes to make them orthonormal. And this is the SVD.  If we choose just the right orthonormal basis of the row space, then we can actually make the column space orthonormal too.  And same for the other way around. We'll talk more about how to do this, but for now just know that there is something coming.\n\\newpage\n\\section{LU Decomposition}\n\nWe will do the LU decomposition of:\n\n$$A = \\begin{bmatrix}\n  1  & 0 & 3 \\\\\n   1 & -1 & -3 \\\\\n  5  & -1 & 6 \\\\\n   \\end{bmatrix}\n$$\n\n$$\n\\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    0 & 1 & 0 \\\\\n    0 & 0 & 1 \\\\\n\\end{bmatrix}\n\\begin{bmatrix}\n    1  & 0 & 3 \\\\\n    1 & -1 & -3 \\\\\n    5  & -1 & 6 \\\\\n\\end{bmatrix} = \n\\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    0 & 1 & 0 \\\\\n    0 & 0 & 1 \\\\\n\\end{bmatrix}\n\\begin{bmatrix}\n    1  & 0 & 3 \\\\\n    1 & -1 & -3 \\\\\n    5  & -1 & 6 \\\\\n\\end{bmatrix}\n  $$\n\n\n  $$\n  \\begin{bmatrix}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & 0 & 1 \\\\\n  \\end{bmatrix}\n  A = \n  \\begin{bmatrix}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & 0 & 1 \\\\\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    0 & 0 & 1 \\\\\n    0 & 1 & 0 \\\\\n    1 & 0 & 0 \\\\\n\\end{bmatrix}\n  \\begin{bmatrix}\n    5  & -1 & 6 \\\\\n      1 & -1 & -3 \\\\\n      1  & 0 & 3 \\\\\n  \\end{bmatrix}\n    $$\n\n    $$\n    \\begin{bmatrix}\n        1 & 0 & 0 \\\\\n        0 & 1 & 0 \\\\\n        0 & 0 & 1 \\\\\n    \\end{bmatrix}\n    A = \n    \\begin{bmatrix}\n      0 & 0 & 1 \\\\\n      0 & 1 & 0 \\\\\n      1 & 0 & 0 \\\\\n  \\end{bmatrix}\n    \\begin{bmatrix}\n      5  & -1 & 6 \\\\\n        1 & -1 & -3 \\\\\n        1  & 0 & 3 \\\\\n    \\end{bmatrix}\n      $$\n\n      $$\n      \\begin{bmatrix}\n        0 & 0 & 1 \\\\\n        0 & 1 & 0 \\\\\n        1 & 0 & 0 \\\\\n    \\end{bmatrix}\n      \\begin{bmatrix}\n          1 & 0 & 0 \\\\\n          0 & 1 & 0 \\\\\n          0 & 0 & 1 \\\\\n      \\end{bmatrix}\n      A = \n      \\begin{bmatrix}\n        0 & 0 & 1 \\\\\n        0 & 1 & 0 \\\\\n        1 & 0 & 0 \\\\\n    \\end{bmatrix}\n      \\begin{bmatrix}\n        0 & 0 & 1 \\\\\n        0 & 1 & 0 \\\\\n        1 & 0 & 0 \\\\\n    \\end{bmatrix}\n      \\begin{bmatrix}\n        5  & -1 & 6 \\\\\n          1 & -1 & -3 \\\\\n          1  & 0 & 3 \\\\\n      \\end{bmatrix}\n        $$\n\n\n        $$\n        \\begin{bmatrix}\n          0 & 0 & 1 \\\\\n          0 & 1 & 0 \\\\\n          1 & 0 & 0 \\\\\n      \\end{bmatrix}\n        A = \n        \\begin{bmatrix}\n            1 & 0 & 0 \\\\\n            0 & 1 & 0 \\\\\n            0 & 0 & 1 \\\\\n        \\end{bmatrix}\n        \\begin{bmatrix}\n          5  & -1 & 6 \\\\\n            1 & -1 & -3 \\\\\n            1  & 0 & 3 \\\\\n        \\end{bmatrix}\n          $$\n          $$\n          P\n          A = \n          \\begin{bmatrix}\n            1 & 0 & 0 \\\\\n            0 & 1 & 0 \\\\\n            0 & 0 & 1 \\\\\n        \\end{bmatrix}\n          \\begin{bmatrix}\n              1 & 0 & 0 \\\\\n              \\frac{1}{5} & 1 & 0 \\\\\n              \\frac{1}{5} & 0 & 1 \\\\\n          \\end{bmatrix}\n          \\begin{bmatrix}\n            5  & -1 & 6 \\\\\n              0 & -\\frac{4}{5} & -\\frac{21}{5} \\\\\n              0  & \\frac{1}{5} & \\frac{9}{5} \\\\\n          \\end{bmatrix}\n            $$\n            $$\n            P\n            A = \n            \\begin{bmatrix}\n                1 & 0 & 0 \\\\\n                \\frac{1}{5} & 1 & 0 \\\\\n                \\frac{1}{5} & 0 & 1 \\\\\n            \\end{bmatrix}\n            \\begin{bmatrix}\n              5  & -1 & 6 \\\\\n                0 & -\\frac{4}{5} & -\\frac{21}{5} \\\\\n                0  & \\frac{1}{5} & \\frac{9}{5} \\\\\n            \\end{bmatrix}\n              $$\nWe don't need to permute here because $|-4/5| > |1/5|$.\n$$\nP\nA = \n\\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    \\frac{1}{5} & 1 & 0 \\\\\n    \\frac{1}{5} & 0 & 1 \\\\\n\\end{bmatrix}\n\\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    0 & 1 & 0 \\\\\n    0 & -\\frac{1}{4} & 1 \\\\\n\\end{bmatrix}\n\\begin{bmatrix}\n  5  & -1 & 6 \\\\\n    0 & -\\frac{4}{5} & -\\frac{21}{5} \\\\\n    0  & 0 & \\frac{3}{4} \\\\\n\\end{bmatrix}\n  $$\n  $$\n  PA =\n  \\begin{bmatrix}\n      1 & 0 & 0 \\\\\n      \\frac{1}{5} & 1 & 0 \\\\\n      \\frac{1}{5} & -\\frac{1}{4} & 1 \\\\\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    5  & -1 & 6 \\\\\n      0 & -\\frac{4}{5} & -\\frac{21}{5} \\\\\n      0  & 0 & \\frac{3}{4} \\\\\n  \\end{bmatrix}\n    $$\n\nNow we need to solve $Ax = b$ where $b = [-1, 2, 1]^T$.  To do this, we first note that $PAx = Pb$, so $LUx = Pb$.  So we first solve $Lc = Pb$ for $c$, then solve $Ux = c$ for $x$.\n\n$$Pb = \\begin{bmatrix}\n    1  \\\\\n    2  \\\\\n    -1  \\\\\n\\end{bmatrix}$$\n\nSo \n\n$$ \\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    \\frac{1}{5} & 1 & 0 \\\\\n    \\frac{1}{5} & -\\frac{1}{4} & 1 \\\\\n\\end{bmatrix}c = \\begin{bmatrix}\n    1  \\\\\n    2  \\\\\n    -1  \\\\\n\\end{bmatrix}$$\n\n$$ \\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    0 & 1 & 0 \\\\\n    \\frac{1}{5} & -\\frac{1}{4} & 1 \\\\\n\\end{bmatrix}c = \\begin{bmatrix}\n    1  \\\\\n    2  - \\frac{1}{5} = \\frac{9}{5} \\\\\n    -1  \\\\\n\\end{bmatrix}$$\n$$ \\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    0 & 1 & 0 \\\\\n    0 & 0 & 1 \\\\\n\\end{bmatrix}c = \\begin{bmatrix}\n    1  \\\\\n    \\frac{9}{5} \\\\\n    -\\frac{20}{20} -\\frac{4}{20} + \\frac{9}{20} = -\\frac{3}{4}\\\\\n\\end{bmatrix} = c = \\begin{bmatrix}\n    1  \\\\\n    \\frac{9}{5} \\\\\n    -\\frac{3}{4}\\\\\n\\end{bmatrix}$$\n\nNow we need to solve $Ux = c$\n\n$$\\begin{bmatrix}\n    5  & -1 & 6 \\\\\n      0 & -\\frac{4}{5} & -\\frac{21}{5} \\\\\n      0  & 0 & \\frac{3}{4} \\\\\n  \\end{bmatrix}x = \\begin{bmatrix}\n    1  \\\\\n    \\frac{9}{5} \\\\\n    -\\frac{3}{4}\\\\\n\\end{bmatrix}$$\n\nScaling all to have 1 as a pivot:\n\n$$\\begin{bmatrix}\n  1  & \\frac{-1}{5} & \\frac{6}{5} \\\\\n    0 & 1 & \\frac{21}{4} \\\\\n    0  & 0 & 1 \\\\\n\\end{bmatrix}x = \\begin{bmatrix}\n  \\frac{1}{5}  \\\\\n  -\\frac{9}{4} \\\\\n  -1\\\\\n\\end{bmatrix}$$\n\n$$\\begin{bmatrix}\n  1  & \\frac{-1}{5} & \\frac{6}{5} \\\\\n    0 & 1 & 0 \\\\\n    0  & 0 & 1 \\\\\n\\end{bmatrix}x = \\begin{bmatrix}\n  \\frac{1}{5}  \\\\\n  3 \\\\\n  -1\\\\\n\\end{bmatrix}$$\n\n$$\\begin{bmatrix}\n  1  & 0 & 0 \\\\\n    0 & 1 & 0 \\\\\n    0  & 0 & 1 \\\\\n\\end{bmatrix}x = \\begin{bmatrix}\n  \\frac{1}{5} + \\frac{3}{5} + \\frac{6}{5}  \\\\\n  3 \\\\\n  -1\\\\\n\\end{bmatrix}$$\n\n$$\\begin{bmatrix}\n  1  & 0 & 0 \\\\\n    0 & 1 & 0 \\\\\n    0  & 0 & 1 \\\\\n\\end{bmatrix}x = \\begin{bmatrix}\n  2  \\\\\n  3 \\\\\n  -1\\\\\n\\end{bmatrix}$$\n\n$$x = \\begin{bmatrix}\n  2  \\\\\n  3 \\\\\n  -1\\\\\n\\end{bmatrix}$$\n\nWhich matches what I got by using RREF on the augmented matrix in Julia.\n\n\\end{document}\n", "meta": {"hexsha": "decf51756275bd08f7bee6fbb6b1262a42119b16", "size": 12930, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main.tex", "max_stars_repo_name": "GSmithApps/Computational-Linear-Algebra", "max_stars_repo_head_hexsha": "767577abd50fc0bc494443f468da074b247f0a9d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "main.tex", "max_issues_repo_name": "GSmithApps/Computational-Linear-Algebra", "max_issues_repo_head_hexsha": "767577abd50fc0bc494443f468da074b247f0a9d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "main.tex", "max_forks_repo_name": "GSmithApps/Computational-Linear-Algebra", "max_forks_repo_head_hexsha": "767577abd50fc0bc494443f468da074b247f0a9d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.8472906404, "max_line_length": 733, "alphanum_fraction": 0.5428460944, "num_tokens": 4700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7032783635714824}}
{"text": "\\section{Appendix}\n\n% ===\n\\subsection{Tips and Tricks}\n\n\\emph{Complete the square:}\n\\\\\nIf $p(\\bm x) \\propto \\exp(-\\frac12 \\bm x\\!^\\top \\!\\bm{{\\color{orange} A}x} + \\bm x\\!^\\top {\\color{orange} \\bm b})$,\\\\\nthen $p(\\bm x) = \\Gauss{\\bm x \\mid \\bm A^{-1} \\bm b, \\bm A^{-1}}$\n\n\\emph{Constrained optimisation:}\n\\\\\n\\textit{primal}: \\enspace \\highlight{$\\min_{\\bm x} f(\\bm x)$ \\enspace s.t. \\enspace $g_i(\\bm x) = 0$; \\enspace $h_j(\\bm x) \\leq 0$}\n\\\\\n\\textbf{Lagrangian:} \\enspace with each $\\alpha_j \\geq 0$\\\\\n\\enspace $\\mathcal L(\\bm x,\\lambda,\\alpha) = f(\\bm x) + \\sum_i \\lambda_i g_i(\\bm x) + \\sum_j \\alpha_j h_j(\\bm x)$\n\\\\\nSolve: \\: $\\pderiv{\\mathcal L}{\\bm x} = 0$; \\: $g_i(\\bm x) = 0$; \\: $\\alpha_j \\geq 0$; \\: $h_j(\\bm x) \\leq 0$\n\\\\\nIf \\textbf{Slater's cond.} holds, $\\exists \\bm x : g_i(\\bm x) = 0, h_j(\\bm x) {\\color{red}\\,<\\,} 0$, then we can solve the \\textit{dual} instead:\\\\\n\\enskip \\highlight{$\\max_{\\bm \\lambda, \\bm \\alpha} \\brace{ \\min_{\\bm x} \\mathcal L(\\bm x, \\bm \\lambda, \\bm \\alpha) }$ \\: s.t. \\: $\\alpha_j \\geq 0$}\\\\\nSolve: \\: $\\pderiv{\\mathcal L}{\\bm x} = 0$; \\: $\\pderiv{\\mathcal L}{\\bm \\lambda} = 0$; \\: $\\alpha_j h_j(\\bm x) {\\color{red}\\,=\\,} 0$; \\: $\\alpha_j \\geq 0$\n\n\\iffalse\n    \\emph{Lagrange Multipliers:}\n    \\\\\n    Problem $\\mathcal P : \\begin{cases}\n        \\min f(\\bm x),      & \\bm x\\in\\mathbb R^d \\\\\n        \\text{s.t. } g_i(\\bm x)=0,      & i\\leq m \\\\\n        \\phantom{\\text{s.t. }} h_j(\\bm x) \\leq 0,       & j\\leq n\n    \\end{cases}$\n    \\\\\n    Lagrangian: $\\mathcal L(\\bm x,\\lambda,\\alpha) = f(\\bm x) + \\sum_{i\\leq m} \\lambda_i g_i(\\bm x) + \\sum_{j\\leq n} \\alpha_j h_j(\\bm x)$ with each $\\alpha_j \\geq 0$.\n    \\\\\n    Solution must satisfy\n    $\\pderiv{\\mathcal L}{\\bm x} = 0$ and $\\pderiv{\\mathcal L}{\\lambda} = 0$,\n    $\\alpha_j h_j(\\bm x) = 0$, and\n    $\\alpha_j \\geq 0, \\forall j\\leq n$.\n\\fi\n\n\\emph{Euler-Lagrange:}\nFind extrema of functional $\\mathcal F[f] = \\int G(x, f(x), f’(x)) \\diff x$,\nthus $\\pderiv{\\mathcal F}{f} \\overset!= 0$.\n\\\\\nIf $G$ is twice diff'able, then\n\\\\\n$\\pderiv{\\mathcal F}{f} = \\pderiv{G}{f(x)} - \\deriv{}{x} \\paren*{ \\pderiv{G}{f'(x)} } \\overset{(\\ast)}= \\pderiv{G}{f(x)}$.\n\\\\\n$(\\ast)$ : when $G$ does not depend on $f'$.\n\n% ===\n\\subsection{Approximations}\n\n\\emph{Laplace Approximation:}\n$\\deriv{f}{x} \\big\\vert_{x_0} \\!= 0$\\\\\n$\\implies \\int_{\\mathbb R} \\eu^{C f(x)} \\diff x \\approx \\sqrt{2\\pi} C \\cdot \\abs{f''(x_0)} \\cdot \\eu^{C f(x_0)}$\n\n% ===\n", "meta": {"hexsha": "b87e43f013b8e91a2bed883bedbe9493690c3806", "size": 2406, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/SLT21/sections/99_appendix.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/SLT21/sections/99_appendix.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/SLT21/sections/99_appendix.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.7796610169, "max_line_length": 165, "alphanum_fraction": 0.5544472153, "num_tokens": 1063, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681158979307, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7032783600963656}}
{"text": "If you haven't downloaded and unzipped \\href{https://libaoj.in/courses/2021f/MATH3341/zip/Math.3341.zip}{\\texttt{Math.3341.zip}}. Download and unzip it under \\verb|H:| (H Drive if you are working on the Remote Lab). Change the current working directory by typing \\verb|cd H:\\Math.3341\\Math.3341.Lab.04| in the Command Window, and type \\verb|edit lab_04_script| in the Command Window to edit \\verb|lab_04_script.m|.\n\n%---------------------------------------------\n\\section{Basics of Plotting Functions}\n%---------------------------------------------\n\\begin{enumerate}[(a)]\n    \\item \\label{enu:1a} Plot $y = x^3$. Define a vector \\verb|x|, of which the range is from $-10$ to $10$ with step size $4$, then define \\verb|y| by aforementioned $y$. Plot in \\verb|subplot(2, 2, 1)|. Add labels \\verb|$x$|, \\verb|$y$| to $x$, $y$ axis, respectively, and add title \\verb|$y = x^{3}$ (step size = 4)|.\n    \\item Repeat (\\ref{enu:1a}) but change the step size of vector \\verb|x| to $0.1$, and put the plot in \\verb|subplot(2, 2, 2)|. Observe the difference between two plots.\n    \\item \\label{enu:1c} Plot the curve $(x(t), y(t))$ whose parametrization is\n        \\begin{equation}\n        \\label{eq:heart}\n        \\begin{cases}\n        x(t) = 13 \\sin^{3}{t}, \\\\\n        y(t) = 13 \\cos{t} - 5 \\cos{2t} - 2 \\cos{3t} - \\cos{4t},\n        \\end{cases}\n        t \\in [0, 2\\pi].\n        \\end{equation}\n        First, define a vector \\verb|t| using \\verb|linspace|, then define \\verb|x|, \\verb|y| by \\eqref{eq:heart}. Plot in \\verb|subplot(2, 2, 3)| with \\emph{red dash-dot} line. Add labels, title as shown in the third plot of Figure \\ref{fig:1}.\n    \\item \\label{enu:1c} Plot the curve $(x(t), y(t))$ whose parametrization is\n        \\begin{equation}\n        \\label{eq:fancy}\n        \\begin{cases}\n        x(t) = 4 \\sin{\\frac{24t}{25}}, \\\\\n        y(t) = 3 \\sin{t},\n        \\end{cases}\n        t \\in [-25 \\pi, 25\\pi].\n        \\end{equation}\n        First, define a vector \\verb|t| using \\verb|linspace| with $5000$ entries, then define \\verb|x|, \\verb|y| by \\eqref{eq:fancy}. Plot in \\verb|subplot(2, 2, 4)|. Add labels, title as shown in the fourth plot of Figure \\ref{fig:1}.\n\\begin{figure}[!hbtp]\n    \\centering\n    \\includegraphics[height=0.27\\textheight]{./fig/lab_04_plot_1.pdf}\n    \\caption{Expected Result for Part 1}\n    \\label{fig:1}\n\\end{figure}\n\\end{enumerate}\n%---------------------------------------------\n\\section{Set Properties for Plotting}\n%---------------------------------------------\n\\begin{enumerate}[(a)]\n    \\item Define \\verb|x|, which ranges from $0$ to $2\\pi$ with $1000$ points, and define \\verb|y1|, \\verb|y2|, and \\verb|y3| as follows\n        $$\n        y_1 = \\sin(x/2), \\quad\n        y_2 = \\sin(x), \\quad\n        y_3 = \\sin(2x).\n        $$\n    \\item Plot \\verb|y1|, \\verb|y2|, \\verb|y3| versus \\verb|x| in the same figure window with line style (\\verb|'LineWidth'|, 2), legend, labels, grid, and title in Figure \\ref{fig:2}. Change the range of $x$-axis to $[0, 2\\pi]$, and that of $y$-axis to $[-1, 1]$.\n\\item Use \\verb|set| to set the following properties:\n    \\begin{itemize}\n        \\item \\verb|XTick| to \\verb|[0, pi / 2, pi, 3 * pi / 2, 2 * pi]|;\n        \\item \\verb|XTickLabel| to \\verb|{'0', '$\\pi/2$', '$\\pi$', '$3 \\pi/2$', '$2\\pi$'}|;\n        \\item \\verb|GridLineStyle| to \\verb|'--'|;\n        \\item \\verb|Box| to \\verb|'on'|;\n        \\item \\verb|BoxStyle| to \\verb|'full'|.\n    \\end{itemize}\n\\begin{figure}[!hbtp]\n    \\centering\n    \\includegraphics[height=0.27\\textheight]{./fig/lab_04_plot_2.pdf}\n    \\caption{Expected Result for Part 2}\n    \\label{fig:2}\n\\end{figure}\n\\end{enumerate}\n%---------------------------------------------\n\\section{Plotting Piecewise Function on Different Scales}\n%---------------------------------------------\n\\begin{enumerate}[(a)]\n    \\item Define \\verb|x| to be a vector from $0$ to $10$ with step size $0.01$, and the piecewise function \\verb|y| as below\n        $$\n        y =\n        \\begin{cases}\n            \\frac{e^{8}}{8} x & x \\leq 8, \\\\\n            e^{x} & 8 < x.\n        \\end{cases}\n        $$\n    \\item \\label{enu:3b} In \\verb|subplot(2, 2, 1)|, use \\verb|plot| to plot \\verb|y| versus \\verb|x|. Set \\verb|grid minor|, add labels and title as shown in the first plot in Figure \\ref{fig:3}.\n    \\item Repeat (\\ref{enu:3b}), then set $y$-axis to log scale using \\verb|set(gca, 'YScale', 'log');|.\n    \\item Repeat (\\ref{enu:3b}), but use \\verb|semilogy| to plot \\verb|y| versus \\verb|x| instead.\n    \\item Combine the first and the third figure in \\verb|subplot(2, 2, 4)| using \\verb|plotyy|, then add labels, title, etc. as shown in the fourth plot in Figure \\ref{fig:3}.\n\n\\begin{figure}[!hbtp]\n    \\centering\n    \\includegraphics[height=0.25\\textheight]{./fig/lab_04_plot_3.pdf}\n    \\caption{Expected Result for Part 3}\n    \\label{fig:3}\n\\end{figure}\n\\end{enumerate}\n%---------------------------------------------\n\\section{Save Plots}\nUse the following script to save the figures.\n\n\\begin{lstlisting}[style=MATLAB]\nprefix = 'lab_04_plot_';\nfor i = 1:3\n    name = strcat(prefix, num2str(i));       % Set filename for figure i\n    fig = figure(i);                         % Set figure i as current figure window\n    set(fig, 'PaperPositionMode', 'auto');   % Set paper position mode to 'auto'\n    pos = get(fig, 'PaperPosition');         % Get figure window paper position\n    set(fig, 'PaperSize', [pos(3) pos(4)]);  % Set figure paper size\n    print(fig, '-dpdf', name);               % Save figure\nend\n\\end{lstlisting}\n\nOnce you finish, upload the script file \\verb|lab_04_script.m| to the folder \\verb|src|, figure files \\verb|lab_04_plot_1.pdf|,  \\verb|lab_04_plot_2.pdf|, and \\verb|lab_04_plot_3.pdf| to the folder \\verb|figure| on Overleaf. Recompile, and submit the generated \\verb|.pdf| file to WyoCourses.\n", "meta": {"hexsha": "e0f720da549d608f0a4f61c2eb4feb58f0e43e93", "size": 5783, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/Math.3341.Lab.04/exercise/body.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/Math.3341.Lab.04/exercise/body.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/Math.3341.Lab.04/exercise/body.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.145631068, "max_line_length": 414, "alphanum_fraction": 0.5901781082, "num_tokens": 1893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933315126791, "lm_q2_score": 0.8577680977182187, "lm_q1q2_score": 0.7032783433034836}}
{"text": "\\section{Deep Neural Networks}\n\nIn this section, we will talk about some recent extension version of DNN models which\nactually comes form the generalization of convolutional neural networks.\n\nFirst, the so-called one hidden layer neural networks can be defined by\n\\begin{equation}\nDNN_1=span\\{\\sigma(wx+b), w\\in\\mathbb{R}^n ,b\\in\\mathbb{R} \\}\n\\end{equation}\nwith\n$$\n\\theta(x) = wx+b \\in\\mathbb{R}^m, w=(w_i,\\cdots,w_m)^T,\\ w_i\\in\\mathbb{R}^{1\\times n}\n$$\t\nand\n\\begin{equation*}\n\\theta(x) = \twx+b=\\left(\\begin{array}{c}\n\t\tw_1x+b \\\\ \n\t\t\\vdots \\\\ \n\t\tw_m x+b_m\n\t\\end{array} \n\t\\right)\n\\end{equation*}\nLet $\\sigma$ be the activation function, say Heaviside, sigmoid, $\\tanh x$, ReLU. The deep neural network is defined as \n\\begin{equation*}\n\t\\begin{aligned}\n\t\t&x^0 = x,\\\\\n\t\t&f^{n+1}=\\sigma(w^n x^n+b^n)=(\\sigma\\circ\\theta)(f^n)\\\\\n\t\t&DNN_i = \\{w^i f^i +b^i \\}\n\t\\end{aligned}\n\\end{equation*}\nThen we have\n\\begin{equation}\n  \\label{eq:1}\nDNN_{i+1} = \\{\\theta(f^{i+1}) \\}\n=\\{\\theta(\\sigma\\circ\\theta)(f^i) \\}\n=(\\theta\\circ\\sigma) DNN_{i} \n\\end{equation}\nand $\\#$ of layers = $\\#$ of $\\sigma$ applied.\n\n\nMore general DNN:\n\\begin{equation}\n\t\\begin{aligned}\n\t\tDNN_0&=\\{wx+b\\}\\\\\n\t\tDNN_J&=\\{(\\theta\\circ\\sigma)\\circ f_{J-1}, \\ f_{J-1}\\in DNN_{J-1}\\}\n\t\\end{aligned}\n\\end{equation}\nDNN contains ResNet, iResNet, DenseNet, MgNet.\n\nThe question is whether $DNN_k\\subset DNN_{k+1}$ is true. The answer is that $DNN_k\\subset DNN_{k+1}$ is only true for the case that the activation function is ReLU, since $x=ReLU(x)-ReLU(-x)$.\n\n\\chapter{The Sparse Grid Method}\nIt is well-known that a smooth function defined on $[0,1]^d$\ncan be pointwisely approximated with $O(h^2)$ accuracy by\na piecewise bilinear function in a subspace $V_h$ of dimension $O(h^{-d})$.\nIn the socalled sparse grid method proposed by\nZenger \\cite{zenger1990sparse}, an $O(h^2|\\log h|^{d-1})$ pointwise\naccuracy can be achieved by using a  substantially smaller\nsubspace $S_h\\subset V_h$ of dimension $O(h^{-1}|\\log h|^{d-1})$.\nAs a result, a function $u$ on a general domain in $\\R^d$\ncan be approximated with $O(h|\\log h|^{d-1})$ in $H^1$ norm\nwith only $O(h^{-1}|\\log h|^{d-1})$ number of operations.\n\n\\section{Multi-linear finite elements}\n\nFor simplicity, we take\n$$\nD_s=(0,1)^s,\\ 1\\leq s\\leq d.\n$$\nFor $D_1$, let the first grid $\\mathcal{T}_0^1$ be itself, namely $\\mathcal T_0^1=\\{(0, 1)\\}$. Divide each\nelement of $\\mathcal{T}_k^1$ into two equal intervals and obtain the\nnext level grid $\\mathcal{T}_{k+1}^1$ . For $s=1$, denote the basis function of nodal value interpolation to the vertex $x_{k,i}=ih_k$ by $\\phi_{k,i}(x)$ with $0\\leq i\\leq n_k$.   \n\\begin{figure}[!ht]\n\\begin{center}\n\\begin{tikzpicture}[xscale=4,yscale=4]\n\\draw[-] (0,0.9) -- (1,0.9);\n\\draw[-] (0,0) -- (1,0);\n\\draw[-] (0,0.3) -- (1,0.3);\n\\draw[-] (0,0.6) -- (1,0.6);\n\\fill(0,0.9) circle(0.5pt);\n\\fill(1,0.9) circle(0.5pt);\n\n\\fill(0,0.6) circle(0.5pt);\n\\fill(0.5,0.6) circle(0.5pt);\n\\fill(1,0.6) circle(0.5pt);\n\n\\fill(0,0.3) circle(0.5pt);\n\\fill(0.25,0.3) circle(0.5pt);\n\\fill(0.5,0.3) circle(0.5pt);\n\\fill(0.75,0.3) circle(0.5pt);\n\\fill(1,0.3) circle(0.5pt);\n\n\\fill(0,0) circle(0.5pt);\n\\fill(0.125,0) circle(0.5pt);\n\\fill(0.25,0) circle(0.5pt);\n\\fill(0.375,0) circle(0.5pt);\n\\fill(0.5,0) circle(0.5pt);\n\\fill(0.625,0) circle(0.5pt);\n\\fill(0.75,0) circle(0.5pt);\n\\fill(0.875,0) circle(0.5pt);\n\\fill(1,0) circle(0.5pt);\n\n\\node at (-0.15,0) {$\\mathcal{T}_3^1$};\n\\node at (-0.15,0.3) {$\\mathcal{T}_2^1$};\n\\node at (-0.15,0.6) {$\\mathcal{T}_1^1$};\n\\node at (-0.15,0.9) {$\\mathcal{T}_0^1$};\n\\node at (-0.05,0) {$0$};\n\\node at (-0.05,0.3) {$0$};\n\\node at (-0.05,0.6) {$0$};\n\\node at (-0.05,0.9) {$0$};\n\\node at (1.05,0.9) {$1$};\n\\node at (1.05,0) {$1$};\n\\node at (1.05,0.3) {$1$};\n\\node at (1.05,0.6) {$1$};\n\\end{tikzpicture}\n\\end{center}\n\\end{figure}\n\nConsider a cubic grid $\n\\mathcal{T}_k^s$ of the domain $D_s$, which is a tensor product of\n$\\mathcal{T}_k^1$. The vertice of elements there are $(i_1h_k, \\cdots\n, i_s h_k)$, with $0\\leq i_1, \\cdots, i_s\\leq n_k$, $n_k=h_k^{-1}$\nand $h_k=2^k$. For $1\\leq s\\leq d$, let\n$$\n\\textbf{i}=(i_1,\\cdots,i_s) \\text{ and } x_{k,\\textbf{i}}=(i_1h_k,\\cdots, i_sh_k)\n$$\nand $\\psi_{k, \\textbf{i}}^s (x_1,\\cdots,x_s)$ be the basis function of the nodal value interpolation(bilinear interpolation) corresponding to the vertex $(i_1h_k, \\cdots , i_s h_k)$ on the grid $\\mathcal{V}_k$. Then\n\\begin{equation}\n\\psi_{k, \\textbf{i}}^s(x)=\\prod_{j=1}^s\\phi_{k,i_j}^j(x_j),\n\\quad 0\\le i_j\\le n_k,\\quad 1\\le s\\le d.\n\\end{equation}\nHere we add a superscript $j$ to each basis function $\\phi_{k,i_j}$ to represent that the corresponding function is the basis function with respect to $x_j$ of $x=(x_1,\\cdots,x_s)$. In other words, the grid $\\mathcal{T}_k^s$ is obtained by cutting each cubic of $\\mathcal{T}_{k-1}^s$ into $2^s$ equal cubics. Then the number of elements in $\\mathcal{T}_k^s$ is $(n_k)^s=2^{ks}$ and the number of interior nodes is $(n_k-1)^s=(2^k-1)^s$.\n\n\\begin{lemma}\\Label{lm:1}\nAssume that $\\Pi_k^s: C(\\bar D_s)\\mapsto \\mathcal{T}_k^s(D_s)$ is the nodal value interpolant on $\\mathcal{T}_k$ and $I_k^s$ is the nodal value interpolant with respect to the variable $x_s$.  Then\n%: C(\\bar D_1)\\mapsto \\mathcal{T}_k^s(D_1)\n$$\\Pi_k^d u=\\prod_{s=1}^d I^s_k u.$$\n\\end{lemma}\n\\begin{proof}\nFor each $1\\leq s\\leq d$, let\n$$\n\\mathcal{I}_k^s=\\{\\textbf{i}=(i_1,\\cdots,i_s),\\ 0\\leq i_1,\\cdots ,i_s\\leq n_k\\}.\n$$\n\\begin{equation}\n\\begin{split}\n\\Pi_k^d u&= \\sum_{\\textbf{i}\\in \\mathcal{I}_k^d} u(x_{k,\\textbf{i}}) \\psi_{k,\\textbf{i}}^d\\\\\n&= \\sum_{\\textbf{i}\\in \\mathcal{I}_k^d} u(x_{k,\\textbf{i}})  \\prod_{s=1}^d\\phi_{k,i_s}^s(x_s)\\\\\n&= \\sum_{\\textbf{i}\\in \\mathcal{I}_k^d}  \\prod_{s=1}^{d-1}\\phi_{i_s}^s(x_{s})\\sum_{1\\leq i_d\\leq n_k-1} u(x_{k,\\textbf{i}})\\phi_{i_d}^d(x_d)\\\\\n&=\\sum_{\\textbf{i}\\in \\mathcal{I}_k^{d-1}}  \\prod_{s=1}^{d-1}\\phi_{i_s}^s(x_{s})  (I_k^d u)(x_{k,\\textbf{i}}) \\\\\n&=(\\prod_{s=1}^d I_k^s) u.\n\\end{split}\n\\end{equation}\n\\end{proof}\n\\input{3FEM/1DHBasis}\n\nFrom this one dimensional hierarchical basis, a multi-dimensional discrete space on the $d$-dimensional unite cube $D_d$ is obtain by a tensor product construction:\n\\begin{equation}\n\\begin{aligned}\n\\m_J^d &= \\otimes_{s=1}^d \\m_J\\\\%\\overbrace{\\m_J\\otimes \\m_J\\otimes \\cdots \\otimes \\m_J}^{d}\\\\\n&= \\bigoplus_{k_1,k_2,\\cdots k_d=0}^J  \\otimes_{s=1}^d V_{k_s}^s%( \\mathcal V_{k_1}^1 \\otimes  \\mathcal V_{k_2}^2\\otimes\\cdots \\otimes  \\mathcal V_{k_d}^d)\\\\\n&= \\bigoplus_{j=0}^{dJ}\\bigoplus_{k_1+k_2+\\cdots + k_d= j}  \\otimes_{s=1}^d V_{k_s}^s.%( \\mathcal V_{k_1}^1 \\otimes  \\mathcal V_{k_2}^2\\otimes\\cdots \\otimes  \\mathcal V_{k_d}^d).\n\\end{aligned}\n\\end{equation}\nHere the superscript $i$ of $V_{k_i}^i$ represents that this is the subspace for the $i$-th coordinate space.\nLet $\\mathbf{k}=(k_1,k_2,\\cdots,k_d)$ be a multi-index. Denote\n$$\n\\mathcal V_{\\mathbf{k}} = \\mathcal V_{k_1}^1 \\otimes  \\mathcal V_{k_2}^2\\otimes\\cdots \\otimes  \\mathcal V_{k_d}^d.\n$$\nThe discrete space $\\m_J^d$ can be written as \n\\begin{equation}\n\\begin{aligned}\n\\m_J^d &= \\bigoplus_{|\\mathbf{k}|_\\infty=J} \\mathcal V_{\\mathbf{k}} \\\\\n&= \\bigoplus_{j=0}^{dJ}\\bigoplus_{|\\mathbf{k}|_1=j} \\mathcal V_{\\mathbf{k}}.\n\\end{aligned}\n\\end{equation}\nLet \n$$\n\\mathbf{I_l}=\\{\\mathbf{i}\\in \\mathbb{N}^d: \\mathbf{1}\\le \\mathbf{i}\\le 2^\\mathbf{l}-1, i_j \\text{ is odd for all }1\\le j\\le d\\},\n$$\nand the hierarchical basis \n$$\n\\{\\psi_\\mathbf{k, i}^d: \\mathbf{i}\\in \\mathbf{I_k}, \\mathbf{k}\\le \\mathbf{l}\\}\\quad \\mbox{with}\\quad \\psi_\\mathbf{k, i}=\\Pi_{s=1}^d\\phi_{k_s,x_s}^s.\n$$\nFor the $d$-dimensional hierarchical basis functions with $d\\neq 2$, it is often more convenient to use the scaled HB\n(hierarchical basis)\nas follows\n\\begin{equation}\n\\label{shb}\n\\{\\psi_\\mathbf{k, i} \\in {\\cal V}_{\\mathbf{k}}: \\psi_\\mathbf{k, i}=2^{-(|\\mathbf{k}|_1+d)}\\psi_{ \\textbf{k, i}}^d, |\\mathbf{k}|_\\infty\\le J\\}. \n\\end{equation}\nWith a proper ordering, we shall denote the scaled HB by $\\{\\psi_i,\ni=1:N\\}$. The HB in multiple dimensions is formally a direct generalization of the\nHB in the one dimensional case.  But the property for the corresponding\nstiffness matrix in multiple dimensions is not at all as clear as in one\ndimension where the stiffness matrix is an identity matrix in some\nspecial cases.  In this section, we shall show that at least in two\ndimensions, a hierarchical basis is still very useful.\n\n\n\n\nFor the linear finite element,\n$\n\\|u-u_I\\|_0\\lesssim h^2|u|_2.\n$\nSince $h\\approx N^{-1/d}$, where $N$ is the number of the total degree of freedom, we have\n$$\n\\|u-u_I\\|_0\\lesssim N^{-2/d}|u|_2.\n$$\nIt implies that for a fixed number of degrees of freedom $N$, a large dimension results in pretty low accuracy.\n\nIn order to overcome the curse of dimensionality, we intend to choose a small subspace properly and throw away a large number of useless information. In the following, we introduce an interpolation operator $R_h$ which interpolates functions into finite element spaces on coarse meshes. Denote the range of $R_k^d$ by $S_k^d$, which is the desirable subspace.\n\nNext we consider the approximation property and dimension  of the following subspace:\n$$\nS_{J,r}^d = \\bigoplus_{|\\mathbf{k}|_1 \\le r}\\mathcal V_{\\mathbf{k}}.\n$$\nDenote\n$$\n\\mathcal F_{J,r}=\\{\\mathbf k=(k_1,\\cdots,k_d): 0\\leq k_i\\leq J, \\ |\\mathbf k|_1\\leq r\\},\n$$\n$$\n\\mathcal F_{J,r}^c=\\{\\mathbf k=(k_1,\\cdots,k_d): 0\\leq k_i\\leq J, \\ |\\mathbf k|_1> r\\},\n$$\n$$\n\\mathcal F_{J,r}^o=\\{\\mathbf k=(k_1,\\cdots,k_d): 0\\leq k_i\\leq J, \\ |\\mathbf k|_1= r\\}.\n$$\n\n\n%Next, we discuss the number $2^{-(2-m)r}\\#\\  \\mathcal F_{J,r}^o$.\n%\\begin{enumerate}\n%\\item $r\\leq J$: $\\# \\ \\mathcal F_{J,r}^o=\\#\\ \\{\\mathbf k:  |\\mathbf k|_1= r\\}=C_{r+d-1}^r$. In this case, $r$ is usually small, we have\n%$$\n%\\# \\ \\mathcal F_{J,r}^o= \\frac{d(d+1)\\cdots (d+r-1)}{r!}\\approx d^r,\\ \\text{ and }2^{-(2-m)r}\\#\\  \\mathcal F_{J,r}^o\\approx 2^{-(2-m)r}d^r;\n%$$\n%\\item $J<r\\leq Jd$: For 2 dimensional case, let $k_i=a_i^2$, $r=r_0^2$. Then \n%$$\n%\\#\\  \\mathcal F_{J,r}^o=\\# \\{\\mathbf{a}=(a_1,\\cdots,a_d): \\sum_{i=1}^da_i^2=r_0^2,\\ 0\\leq a_i\\leq \\sqrt{J}\\}.\n%$$\n%We consider the length $l_\\theta=r_0(2 \\theta-\\frac{\\pi}{2})$ with $r_0\\sin \\theta=\\sqrt{J}$. Then \n%$$\n%l_\\theta=\\frac{\\sqrt{J}}{\\sin \\theta}(2 \\theta-\\frac{\\pi}{2}).\n%$$\n%A simple computation gives\n%$$\n%\\sin \\theta l_\\theta'+\\cos \\theta l_\\theta=2\\sqrt{J},\n%$$\n%thus,\n%$$\n%\\sin \\theta l_\\theta=\\frac{\\pi\\sqrt{J}}{2} -2\\sqrt{J}(\\frac{\\pi}{2}-\\theta)=2\\sqrt{J}(\\theta-\\frac{\\pi}{4}),\n%$$\n%namely $l_\\theta= 2\\sqrt{J}(\\theta-\\frac{\\pi}{4})/\\sin \\theta$. As $r$ grows larger, $l_\\theta$ approximates $2\\sqrt{J}$.\n%\n%\\item $r> Jd$: $\\# \\ \\mathcal F_{J,r}^o=0$.\n%\\end{enumerate}\n\n\\begin{lemma}\\Label{lm:2}\nAssume that\n$I^s_k: C(\\bar D)\\mapsto \\m_l(D_1)$ is the nodal value interpolant\nwith respect to the variable $x_s$.  Define\n$$\nF_{J,r}^d=\\sum_{\\mathbf k\\in \\mathcal{F}_{J,r}}\\prod_{s=1}^d(I^s_{k_s}-I^s_{k_{s}-1})\n$$\nand\n$$\nS_{J,r}^d=F_{J,r}^d\\m.\n$$\nThen for $m=0,1$,\n$$\n\\inf_{\\chi\\in S_{J,r}^d}\\nm{v-\\chi}{m, D_d}\\le C h_J^{(2-m)(r+1)/J}|\\log h_J|^{d-1}\\max_{|\\mathbf k|_1> r}\\nm {\\partial^{2\\text{sign}(\\mathbf k)}v}{0,D_d}.\n$$\n\\end{lemma}\n\\begin{proof}\nUsing the obvious identity (with $I_{-1}^s=0$)\n$$I^s_J=\\sum_{k=0}^J(I^s_k-I^s_{k-1}),$$\nit follows from the commutative property and Lemma \\ref{lm:1} that\n$$\n\\Pi_J^d=\\prod_{s=1}^d\\sum_{k=0}^J(I^s_{k}-I^s_{k-1})\n=\\sum_{k_1,k_2,\\cdots, k_d=0}^J\\prod_{s=1}^d(I^s_{k_s}-I^s_{k_s-1}). \n$$\nThus,\n\\begin{equation}\\label{multiNote1}\n(\\Pi_J^d-F_{J,r}^d)v=\n\\sum_{\\mathbf k\\in \\mathcal{F}_{J,r}^c}\\prod_{s=1}^d(I^s_{k_s}-I^s_{k_s-1})v.\n\\end{equation}\nNote that if $k_1\\neq 0$ and $m\\le 2$,\n\\begin{equation}\\label{multiNote201}\n\\begin{split}\n\\nm { \\prod_{s=1}^d(I^s_{k_s}-I^s_{k_s-1})v}{m,D_d}\n&\\lesssim h^{2-m}_{k_1}\\nm {\\partial^2_{x_1}\\prod_{s=2}^d(I^s_{k_s}-I^s_{k_s-1})v}{0, D_d} \\\\\n&=  h^{2-m}_{k_1}\\nm {\\prod_{s=2}^d(I^s_{k_s}-I^s_{k_s-1}) \\partial^2_{x_1} v}{0, D_d} \\\\\n&=2^{-k_1(2-m)}\\nm {\\prod_{s=2}^d(I^s_{k_s}-I^s_{k_s-1}) \\partial^2_{x_1} v}{0, D_d}.\n%&\\lesssim  h^{2-m}_{k_1}h^{2-m}_{k_2}\\nm {\\prod_{s=3}^d(I^s_{k_s}-I^s_{k_s-1}) \\partial^2_{x_1} v}{L^{p}(D_d)} \\\\\n%&\\le Ch^{2-m}_{k_1}h^{2-m}_{k_2}\\cdots h^{2-m}_{k_d}\n%\\nm{\\partial^2_{x_1}\\partial^2_{x_2}\\cdots \\partial^2_{x_d}v}{L^p(D_d)}.\n\\end{split}\n\\end{equation}\nIf $k_1=0$ and $m\\le 2$,\n\\begin{equation}\\label{multiNote202}\n\\begin{split}\n\\nm { \\prod_{s=1}^d(I^s_{k_s}-I^s_{k_s-1})v}{m,D_d}\n&= \\nm { I_0^1 \\prod_{s=2}^d(I^s_{k_s}-I^s_{k_s-1})v}{m,D_d} \\\\ \n&=2^{-k_1(2-m)}\\nm {\\prod_{s=2}^d(I^s_{k_s}-I^s_{k_s-1})  I_0^1  v}{m,D_d}.\n\\end{split}\n\\end{equation}\nA combination of \\eqref{multiNote201} and \\eqref{multiNote202} gives\n\\begin{equation}\\label{multiNote2}\n\\nm {\\prod_{s=1}^d(I^s_{k_s}-I^s_{k_s-1})v}{0, D_d} \n\\lesssim 2^{-(2-m)|\\mathbf k |_1}\\nm {\\partial^{2\\text{sign}(\\mathbf k)}v}{0,D_d}.\n\\end{equation}\nAn elementary calculation shows that\n\\begin{equation}\\label{multiNote3}\n\\begin{split}\n\\sum_{\\mathbf k\\in \\mathcal{F}_{J,r}^c}2^{-(2-m)|\\mathbf k |_1}\\nm {\\partial^{2\\text{sign}(\\mathbf k)}v}{0,D_d}\n&=\\sum_{j=r+1}^{Jd}\\sum_{\\mathbf k \\in \\mathcal F_{J,j}^o}2^{-(2-m)|\\mathbf k |_1}\\nm {\\partial^{2\\text{sign}(\\mathbf k)}v}{0,D_d}\\\\\n&\\leq\\sum_{j=r+1}^{Jd} 2^{-(2-m)j}  \\max_{\\mathbf k \\in \\mathcal F_{J,j}^o}\\nm {\\partial^{2\\text{sign}(\\mathbf k)}v}{0,D_d}\\sum_{\\mathbf k \\in \\mathcal F_{J,j}^o}1\\\\\n&\\le J^{d-1}\\sum_{j=r+1}^{Jd} 2^{-(2-m)j} \\max_{\\mathbf k\\in \\mathcal{F}_{J,r}^c}\\nm {\\partial^{2\\text{sign}(\\mathbf k)}v}{0,D_d}\\\\\n&=\\frac{1-2^{-(2-m)(Jd-r-1)}}{1-2^{-(2-m)}} J^{d-1}2^{-(r+1)(2-m)}\\max_{\\mathbf k\\in \\mathcal{F}_{J,r}^c}\\nm {\\partial^{2\\text{sign}(\\mathbf k)}v}{0,D_d}\\\\\n&\\le C h_J^{(2-m)(r+1)/J}|\\log h_J|^{d-1}\\max_{\\mathbf k\\in \\mathcal{F}_{J,r}^c}\\nm {\\partial^{2\\text{sign}(\\mathbf k)}v}{0,D_d}.\n\\end{split}\n\\end{equation}\n%Given an integer $p\\ge1$, an elementary calculation shows that\n%\\begin{equation}\\label{multiNote2}\n%\\begin{split}\n%\\sum_{k_1+k_2+\\cdots+ k_d\\ge p}h^{2}_{k_1}h^{2}_{k_2}\\cdots h^{2}_{k_d}\\\\\n%&=\\sum_{k_1+k_2+\\cdots+ k_d\\ge p}2^{-(k_1+k_2+\\cdots+k_d)}\\\\\n%&=\\sum_{j=p}^{Jd}\\sum_{k_1+k_2+\\cdots+ k_d= j}2^{-(k_1+k_2+\\cdots+k_d)}\\\\\n%&=\\sum_{j=p}^{Jd}\\sum_{k_1+k_2+\\cdots+ k_d= j}2^{-j}\\\\\n%&=\\frac{1-h^{(2)(d-1)}}{1-\\gamma^{2(2)}} J^{d-1}\\gamma^{2J(2)}\\le C h^{2}|\\log h|^{d-1}.\n%\\end{split}\n%\\end{equation}\nA combination of \\eqref{multiNote1}, \\eqref{multiNote2} and \\eqref{multiNote3} yields\n\\begin{equation} \n\\begin{split}\n\\| v-F_{J,r}^d v\\|_{m, D_d}&\\leq \\| v-\\Pi_k^d v\\|_{m,D_d} + \\| \\Pi_k^d v-F_{J,r}^d v\\|_{m,D_d}\n\\\\\n&\\le C h_J^{(2-m)(r+1)/J}|\\log h_J|^{d-1}\\max_{|\\mathbf k|_1> r}\\nm {\\partial^{2\\text{sign}(\\mathbf k)}v}{0,D_d}. \n\\end{split}\n\\end{equation}\nwhich completes the proof.\n\\end{proof}\n\\begin{remark}\nLet $ \\lceil p/2\\rceil$ be the smallest integer larger than $p/2$. For any positive integer $p$, if $r\\ge \\lceil p/2\\rceil J$, there are at least $\\lceil p/2\\rceil$ components of $\\mathbf{k}$ which are nonzero, namely, $2\\text{sign} (\\mathbf{k})> p$. Thus, for any polynomial $v$ with degree not larger than $p$, $\\max_{\\mathbf k\\in \\mathcal{F}_{J,r}^c}\\nm {\\partial^{2\\text{sign}(\\mathbf k)}v}{0,D_d}=0.$\n\\end{remark}\n\n%\\newcommand{S_h}{{\\cal S}_h}\n\\begin{lemma}\\label{lm:sparseN}\nBy the definition of $S_{J,r}^d$, we have\n$$\nS_{J,r}^d={\\rm span}\\{\\prod_{s=1}^d\\phi_{k_s, i_s}^s,\\quad\n|\\mathbf{k}|_1< r,\\quad i_sh_{k_s}\\in {\\cal N}_{k_s}\\setminus {\\cal N}_{k_s-1}\\},\n$$\nand\n$$\n\\dim(S_{J,r}^d)=O(h_J^{-(r+1)/J}|\\log h_J|^{d-1}).\n$$\n\\end{lemma}\n\\begin{proof}\nIt is easy to see that\n\\begin{equation*}\n\\begin{split}\n\\dim(S_{J,r}^d) &\\le C\\sum_{|\\mathbf k|_1\\leq r}2^{k_1+k_2+\\cdots+k_d}\\\\\n&= C \\sum_{j=0}^r 2^{j}\\# \\mathcal F_{J, j}^o\\\\\n&\\leq 2^{r+1}J^{d-1}\\\\\n&\\leq Ch_J^{-(r+1)/J}|\\log h_J|^{d-1}.\n\\end{split}\n\\end{equation*}\n\\end{proof}\n\nA combination of Lemma \\ref{lm:2} and Lemma \\ref{lm:sparseN} leads to the following result.\n\\begin{theorem}\n$$\n\\inf_{\\chi\\in S_{J,r}^d}\\nm{v-\\chi}{m, D_d}\\le C N^{-(2-m)}|\\log N|^{d-1}\\max_{|\\mathbf k|_1> r}\\nm {\\partial^{2\\text{sign}(\\mathbf k)}v}{0,D_d},\n$$\nwhere $N$ is the number of the degree of freedom. \n\\end{theorem}\nThis indicates that the sparse grid method overcomes the curse of dimensionality.\n\n\\input{6DL/SparseGridModify}\n\n\\section{The sparse grid method using high order polynomials}\nIn this section, we consider the high order method. Let $\\mathcal{M}_k, k =0,1,\\cdots $ denote the one-dimensional Lagrange finite element spaces of order $p$ on the grids $\\mathcal{T}_k$.  Let $I_k$ be the Lagrange interpolant of order $p$. Thus,\n$$\n\\mathcal{M}_k = I_k\\m.\n$$\nNote that the number of elements on  $\\mathcal{T}_k, k = 0,1,\\cdots$ is $2^k$. Thus, the number of degrees of freedom of the space $\\mathcal{M}_k$ is\n$$\n\\text{Dim}(\\mathcal{M}_k) = p2^k+1 \\quad \\text{ for } k\\ge 1,\n$$\nand $\\text{Dim}(\\mathcal{M}_0)=p+1$. \nSetting $\\mathcal{V}_0= \\mathcal{M}_0$ and \n$$\n\\mathcal{V}_k=(I_k - I_{k-1}) \\mathcal{M}_k  \\quad \\text{ for } k\\ge 1.\n$$ \nThus, the dimension of the spaces is \n$$\n\\text{Dim}(\\mathcal{V}_k) = p2^{k-1} \\quad \\text{ for } k\\ge 1,\n$$\nand $\\text{Dim}(\\mathcal{V}_0)=p+1$. It is easy to see that\n\\begin{equation}\\label{hbk}\n\\mathcal V_k=\\{\\phi_{k,i}: x_{k,i}\\in {\\cal N}_k\\setminus {\\cal N}_{k-1}\\},\n\\end{equation}\nwhere ${\\cal N}_k$ denotes the set of nodes of Lagrange finite element space of order $k$.  The above subspaces obviously give rise to a direct sum decomposition of the space $\\m_J$ as follows:\n$$\n        \\mathcal M_\\infty=\\bigoplus_{k=0}^\\infty \\mathcal V_k.\n$$\n\nConsider the $d$-dimensional unite cube $D_d$, let $\\Pi_k^s: C(\\bar D_s)\\mapsto \\mathcal{T}_k^s(D_s)$ is the Lagrange interpolant on $\\mathcal{T}_k$ of order $p$.  A multi-dimensional basis on the $d$-dimensional unite cube $D_d$ is obtain by a tensor product construction:\n\\begin{equation}\n\\begin{aligned}\n\\m^d &= \\overbrace{\\m \\otimes \\m \\otimes \\cdots \\otimes \\m }^{d}\\\\\n&= \\bigoplus_{k_1,k_2,\\cdots k_d=0}^\\infty ( \\mathcal V_{k_1}^1 \\otimes  \\mathcal V_{k_2}^2\\otimes\\cdots \\otimes  \\mathcal V_{k_d}^d)\\\\\n&= \\bigoplus_{j=0}^{\\infty}\\bigoplus_{k_1+k_2+\\cdots + k_d= j} ( \\mathcal V_{k_1}^1 \\otimes  \\mathcal V_{k_2}^2\\otimes\\cdots \\otimes  \\mathcal V_{k_d}^d)\\\\\n\\end{aligned}\n\\end{equation}\nLet $\\mathbf{k}=(k_1,k_2,\\cdots,k_d)$ be a multi-index. Denote\n$\n\\mathcal V_{\\mathbf{k}} = \\mathcal V_{k_1}^1 \\otimes  \\mathcal V_{k_2}^2\\otimes\\cdots \\otimes  \\mathcal V_{k_d}^d.\n$\nWe make the following truncation:\n$$\n\\mathcal{M}^d = \\left(\\bigoplus_{|\\mathbf{k}|_1 < L}\\mathcal{V}_{\\mathbf{k}} \\right) \\bigoplus \\left(\\bigoplus_{|\\mathbf{k}|_1 \\ge L}\\mathcal{V}_{\\mathbf{k}} \\right). \n$$\nNext we consider the approximation property and dimension  of  $\\mathcal{M}^{d,L,p} : =\\bigoplus_{|\\mathbf{k}|_1 < L}\\mathcal{V}_{\\mathbf{k}}$.\n\n\n\\begin{lemma}\nIt holds that \n\\begin{equation}\n\\text{Dim}(\\mathcal{M}^{d,L,p}) =\\mathcal{O}\\left( (p+1)^d L^{-1}(L+2)^d 2^{L-d}\\right).\n\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\\begin{equation}\n\\begin{aligned}\n\\text{Dim}(\\mathcal{M}^{d,L,p})& = \\text{Dim}(\\bigoplus_{|\\mathbf{k}|_1 < L} \\mathcal V_{k_1}^1 \\otimes  \\mathcal V_{k_2}^2\\otimes\\cdots \\otimes  \\mathcal V_{k_d}^d )\\\\\n& = \\sum_{i=0}^d C_d^i (p+1)^i \\sum_{k_1+\\cdots +k_{d-i} <L}^{k_j \\ge 1} p^{d-i}2^{k_1+\\cdots+k_{d-i} -(d-i)} \\\\\n& = \\sum_{i=0}^d C_d^i (p+1)^i \\sum_{k_1+\\cdots +k_{d-i} <L-(d-i)}^{k_j \\ge 0} p^{d-i}2^{k_1+\\cdots+k_{d-i} } \\\\\n& \\le \\sum_{i=0}^d  C_d^i    (p+1)^i p^{d-i} (L-d+i)^{d-i-1}2^{L-d+i}\\\\\n&\\le (p+1)^d L^{-1}2^{L-d} \\sum_{i=0}^d C_d^i L^{d-i} 2^i\\\\\n&\\le (p+1)^d L^{-1}(L+2)^d 2^{L-d}.\n\\end{aligned}\n\\end{equation}\nIn the first inequality of above estimation, we use the fact that \n$$\n\\sum_{k_1+\\cdots+k_d < L }2^{k_1+\\cdots +k_d} = \\sum_{j=0}^{L-1} \\sum_{k_1+\\cdots+k_d =j}2^j =  \\sum_{j=0}^{L-1} C_{j+d-1}^{d-1}2^j,\n$$\nand \n$$\n\\frac{(L-1+d-1)!}{(d-1)!(L-1)!} 2^{L-1} < \\sum_{j=0}^{L-1} C_{j+d-1}^{d-1}2^j <  \\sum_{j=0}^{L-1} L^{d-1}2^j =L^{d-1}2^L.\n$$\nThus,\n$$\n\\sum_{k_1+\\cdots+k_d < L }2^{k_1+\\cdots +k_d} \\approx  L^{d-1}2^L.\n$$\n\n\\end{proof}\n\n\\begin{lemma}\\label{lm:spare_grid_decay}\nIt holds that \n\\begin{equation}\n\\|\\Pi_{i=1}^d (I_{k_i}^i -I_{k_i-1}^i) v\\|_0  \\le C^{d} 2^{-(p+1)|\\mathbf{k}|_1}\\|\\partial^{(p+1)\\text{sign}(\\mathbf{k})}v\\|_0.\n\\end{equation}\nHere $I_{k_i}^i$ is the Lagrange interpolant onto $\\m_{k_i}$ with respect to the $i$-th variable, and $C$ is a constant independent of $p,d,\\mathbf{k}$.\n\\end{lemma}\n\\begin{proof}\nSimilar to the analysis in Lemma \\ref{lm:2},\n\\begin{equation}\n\\begin{aligned}\n\\|\\Pi_{i=1}^d (I_{k_i}^i -I_{k_i-1}^i) v\\|_0  &\\le Ch_{k_i}^{p+1} \\|\\Pi_{i=2}^d (I_{k_i}^i -I_{k_i-1}^i)  \\partial^{(p+1)\\text{sign}(k_1)}v \\|_0\\\\\n&\\le C^{d} 2^{-(p+1)|\\mathbf{k}|_1}\\|\\partial^{(p+1)\\text{sign}(\\mathbf{k})}v\\|_0.\n\\end{aligned}\n\\end{equation}\n\\end{proof}\n\nFor any $v$, we denote $v_{\\mathbf{k}} = \\Pi_{i=1}^d (I_{k_i}^i -I_{k_i-1}^i) v$. It is obvious that \n$$\nv \\approx \\sum_{\\mathbf{k} } v_{\\mathbf{k}}.\n$$\nThe above lemma indicates that  $v_{\\mathbf{k}}$ decays as  $C^{d} 2^{-(p+1)|\\mathbf{k}|_1}$.\n\n\\begin{lemma}\nSetting  $v_{\\mathbf{k}} = \\Pi_{i=1}^d (I_{k_i}^i -I_{k_i-1}^i) v$. It hold that \n\\begin{equation}\n\\|\\sum_{|\\mathbf{k}|_1 \\ge L } v_{\\mathbf{k}}\\|_0 \\le C^d 2^{-(p+1)L + \\frac{1}{2^{p+1}\\ln 2}d}\\sum_{i=0}^{d-1}\\frac{\\left((1-\\frac{1}{2^{p+1}})L\\right)^{i}}{i!} \\max_{|\\mathbf{k}|_1\\ge L}\\|\\partial^{(p+1)\\text{sign}(\\mathbf{k})} v\\|_0\n\\end{equation}\n\\end{lemma}\n\\begin{proof}\nBy Lemma \\ref{lm:spare_grid_decay}, we have\n\\begin{equation}\\label{pest}\n\\|\\sum_{|\\mathbf{k}|_1 \\ge L } v_{\\mathbf{k}}\\|_0 \\le C^d \\max_{|\\mathbf{k}|_1\\ge L }\\|\\partial^{(p+1)\\text{sign}(\\mathbf{k})} v\\|_0  \\sum_{|\\mathbf{k}|_1 \\ge L} 2^{-(p+1)|\\mathbf{k}|_1}.\n\\end{equation}\nSetting \n$\ns_{d, L} = \\sum_{|\\mathbf{k}|_1 \\ge L} 2^{-(p+1)|\\mathbf{k}|_1}.\n$\nNote that \n$$\n\\begin{aligned}\ns_{d, L} &= \\sum_{|\\mathbf{k}|_1 \\ge L} 2^{-(p+1)|\\mathbf{k}|_1}\\\\\n&= \\sum_{k_2+\\cdots+k_d\\ge L-1, k_1\\neq 0} 2^{-(p+1) (k_1+1 +k_2+\\cdots+k_d)}  + \\sum_{k_2+\\cdots+k_d \\ge L, k_1=0} 2^{-(p+1) ( 0+k_2+\\cdots+k_d)}\\\\\n& =  2^{-(p+1)} s_{d,L-1} +s_{d-1,L}\n\\end{aligned}\n$$\nand $s_{1,L} = \\frac{2^{-(p+1)L}}{1 - 2^{-p-1}}$, $s_{d,0} = (\\frac{1}{1 - 2^{-p-1}})^d$.  \nLet $t_{d,L} = 2^{(p+1)L} s_{d,L}$, $\\gamma = \\frac{1}{1 - 2^{-p-1}}$. We have the following induction\n$$\nt_{d,L} =t_{d,L-1} +t_{d-1,L}\\quad \\text{with}\\quad  t_{1,L} = \\gamma, t_{d,0} = \\gamma^d.\n$$\nBy induction, we have\n$$\nt_{d,L}\\lesssim \\gamma^d(1 + \\frac{L}{\\gamma } +\\cdots +\\frac{ L^{d-1} }{(d-1)!\\gamma^{d-1}}).\n$$\nThus,\n$$\ns_{d,L} \\lesssim 2^{-(p+1)L} (1-2^{-p-1})^{-d} (1 +\\frac{(1-2^{-p-1})L}{1}+\\cdots + \\frac{ \\left((1-2^{-p-1}) L\\right)^{d-1} }{(d-1)!}  )\n$$\nSince $-\\ln(1-x)\\le x$, we have\n$$\n(1 - 2^{-p-1})^{-d} = 2^{-d \\ln (1-2^{-p-1}) /\\ln 2} \\le 2^{ \\frac{1}{2^{p+1}\\ln 2}d}.\n$$\nA combination of this and \\eqref{pest} completes  the proof.\n\\end{proof}\n\n\n", "meta": {"hexsha": "213735ad010d2049ff2b4f9292ff5b978c64e3bb", "size": 22581, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Limin-Backup.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/Limin-Backup.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/Limin-Backup.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.9296577947, "max_line_length": 436, "alphanum_fraction": 0.6259687348, "num_tokens": 10239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933183101078, "lm_q2_score": 0.8577681086260461, "lm_q1q2_score": 0.7032783409219939}}
{"text": "\\documentclass[11pt]{article}\n\\renewcommand{\\baselinestretch}{1.05}\n\\usepackage{amsmath,amsthm,verbatim,amssymb,amsfonts,amscd, graphicx}\n\\usepackage{graphics}\n\\topmargin0.0cm\n\\headheight0.0cm\n\\headsep0.0cm\n\\oddsidemargin0.0cm\n\\textheight23.0cm\n\\textwidth16.5cm\n\\footskip1.0cm\n\n\\begin{document}\n\n\\title{Assignment 3 Solution}\n\\author{Rochan Avlur Venkat}\n\\maketitle\n\n\\section{}\nGiven that $$f(x,y) = \\frac{x^{2}y^{2}}{x^{2}y^{2} + (x-y)^{2}}$$\n\nwhenever $x^{2}y^{2} + (x - y)^{2} \\neq 0$. Now, applying the first limit, we get\n\n$$\\lim_{y\\to0}f = \\frac{x^{2}y^{2}}{x^{2}y^{2} + (x-y)^{2}} = \\frac{0}{0 + (x)^{2}} = 0$$\n\nNow, applying the outer limit we get\n\n$$\\lim_{x\\to0}\\lim_{y\\to0}f = 0$$\n\nSimilarly, we get\n\n$$\\lim_{x\\to0}f = \\frac{x^{2}y^{2}}{x^{2}y^{2} + (x-y)^{2}} = \\frac{0}{0 + (y)^{2}} = 0$$\n\nAnd applying the outer limit we get\n\n$$\\lim_{y\\to0}\\lim_{x\\to0}f = 0$$\n\nHence, $$\\lim_{y\\to0}\\lim_{x\\to0}f = \\lim_{x\\to0}\\lim_{y\\to0}f$$\n\nNow, $\\lim_{(x,y)\\to(0,0)}f(x,y)$ along the $y=x$ line, we get\n\n$$\\lim_{(x,y)\\to(0,0)}f = \\frac{x^{4}}{x^{4}} = 1$$\n\nSimilarly, $\\lim_{(x,y)\\to(0,0)}f(x,y)$ along the $y=2x$ line, we get\n\n$$\\lim_{(x,y)\\to(0,0)}f = \\frac{4x^{4}}{4x^{4} + x^{2}} = \\frac{4x^{2}}{4x^{2} + 1} = 0$$\n\nHence, limit does not exits at $(x,y) \\to (0,0)$.\n\n\\section{}\n\nSee appended section.\n\n\\section{}\nGiven that $$f(x,y) = \\frac{x^{2} - y^{2}}{x^{2} + y^{2}}$$\n\\\\\nWe need to find the limit along $y = mx$ as $(x,y) \\rightarrow (0,0)$\n\\\\\n\\\\\nReplacing the value of $y$ with $mx$ in the given function, we get $$f = \\frac{x^{2} - m^{2}x^{2}}{x^{2} + m^{2}x^{2}}$$\n\\\\\nSolving the limit, we get $$\\lim_{x\\to0} \\frac{x^{2} - m^{2}x^{2}}{x^{2} + m^{2}x^{2}} = \\frac{1 - m^{2}}{1 + m^{2}}$$\n\\\\\nIn order to define a $f(x,y)$ so as to make it continuous at $(0,0)$, $$\\lim_{(x,y)\\to(0,0)} \\frac{x^{2} - y^{2}}{x^{2} + y^{2}}$$ should be equal along every path $y = mx + c$ taken. Since this is not true in the given function, we cannot define $f(x,y)$ so as to make it continuous at $(0,0)$.\n\n\\section{}\nGiven a scalar field\n$$f(\\textbf{x}) = ||\\textbf{x}||^{4}$$\n\nNow, assume that\n\n$$g(t) = f(\\textbf{x} + t\\textbf{y})$$\n\nSince\n\n$$f(\\textbf{x}) = (\\textbf{x}\\cdot\\textbf{x})\\times(\\textbf{x}\\cdot\\textbf{x})$$\n\nWe get\n\n$$g(t) = (\\textbf{x} + t\\textbf{y})\\cdot(\\textbf{x} + t\\textbf{y})\\times(\\textbf{x} + t\\textbf{y})\\cdot(\\textbf{x} + t\\textbf{y})$$\n\n$$g(t) = (\\textbf{x}\\cdot\\textbf{x}+2t\\textbf{x}\\cdot\\textbf{y}+t^{2}\\textbf{y}\\cdot\\textbf{y})\\times(\\textbf{x}\\cdot\\textbf{x}+2t\\textbf{x}\\cdot\\textbf{y}+t^{2}\\textbf{y}\\cdot\\textbf{y})$$\n\n$$g\\prime(0) = f\\prime(\\textbf{x};\\textbf{y}) = 4||\\textbf{x}||^{2}(\\textbf{x}\\cdot\\textbf{y})$$\n\n\\section{}\n\\subsection{}\n\nGiven that\n\n$$f(x,y) = \\frac{x}{\\sqrt{x^{2} + y^{2}}}$$\n\nThen the first order partial derivative can be calculated as\n\n$$\\frac{\\partial f}{\\partial x} = \\frac{\\partial \\frac{x}{\\sqrt{x^{2} + y^{2}}}}{\\partial x}$$\n\nUsing division rule, we get\n\n$$\\frac{\\partial f}{\\partial x} = \\frac{\\frac{\\partial \\:}{\\partial \\:x}\\left(x\\right)\\sqrt{x^2+y^2}-\\frac{\\partial \\:}{\\partial \\:x}\\left(\\sqrt{x^2+y^2}\\right)x}{\\left(\\sqrt{x^2+y^2}\\right)^2}$$\n\n$$\\frac{\\partial f}{\\partial x} = \\frac{1\\cdot \\sqrt{x^2+y^2}-\\frac{x}{\\sqrt{x^2+y^2}}x}{\\left(\\sqrt{x^2+y^2}\\right)^2} = \\frac{y^2}{\\left(x^2+y^2\\right)\\sqrt{x^2+y^2}}$$\n\nThe partial derivative with respect to y is\n\n$$\\frac{\\partial f}{\\partial y} = \\frac{\\partial \\frac{x}{\\sqrt{x^{2} + y^{2}}}}{\\partial y}$$\n\n$$\\frac{\\partial f}{\\partial y} = x\\frac{\\partial \\:}{\\partial \\:y}\\left(\\left(x^2+y^2\\right)^{-\\frac{1}{2}}\\right)$$\n\nAnd using chain rule, replacing $u = x^{2} + y^{2}$, we get\n\n$$\\frac{\\partial f}{\\partial y} = x\\frac{\\partial \\:}{\\partial \\:u}\\left(u^{-\\frac{1}{2}}\\right)\\frac{\\partial \\:}{\\partial \\:y}\\left(x^2+y^2\\right)$$\n\n$$\\frac{\\partial f}{\\partial y} = x\\left(-\\frac{1}{2u^{\\frac{3}{2}}}\\right)\\cdot \\:2y$$\n\nReplacing the back the value of $u$, we get\n\n$$\\frac{\\partial f}{\\partial y} = -\\frac{xy}{\\left(x^2+y^2\\right)^{\\frac{3}{2}}}$$\n\n\\subsection{}\n\nGiven $$f(x) = \\vec{a}.\\vec{x}$$\n\n$\\vec{a}$ being fixed, $f$ is defined on $R^{n}$ and $\\vec{a} = a_{1}i + a_{2}j + ...$\n\nThen, the partial derivative in the $x$ direction is\n\n$$\\frac{\\partial f}{\\partial x} = \\lim_{h\\to0}\\frac{f((x,y,z...) + h(1,0,0,0...)) - f(x,y,z...)}{h}$$\n\n$$= \\lim_{h\\to0}\\frac{\\vec{a}\\cdot(x+h,y,z..) - \\vec{a}\\cdot(x,y,z...)}{h}$$\n\n$$= a_{1}$$\n\nThen, the partial derivative in the $y$ direction is\n\n$$\\frac{\\partial f}{\\partial y} = \\lim_{h\\to0}\\frac{f((x,y,z...) + h(0,1,0,0...)) - f(x,y,z...)}{h}$$\n\n$$= \\lim_{h\\to0}\\frac{\\vec{a}\\cdot(x,y+h,z..) - \\vec{a}\\cdot(x,y,z...)}{h}$$\n\n$$= a_{2}$$\n\nAnd so on.\n\n\n\\section{}\n\nGiven the function $$f(x,y) = \\frac{1}{y}\\cos{x^{2}}$$\n\nWe have $$D_{2}f = \\frac{\\partial \\frac{1}{y}\\cos{x^{2}}}{\\partial y} = \\frac{-1}{y^{2}}\\cos{x^{2}}$$ $$D_{1}f = \\frac{\\partial \\frac{1}{y}\\cos{x^{2}}}{\\partial x} = \\frac{-2x}{y}\\sin{x^{2}}$$\n\nThen, the mixed partial derivatives $D_{1}(D_{2}f)$ and $D_{2}(D_{1}f)$ are given by\n$$D_{1}(D_{2}f) = \\frac{2x}{y^{2}}\\sin{x^{2}}$$\n\n$$D_{2}(D_{1}f) = \\frac{2x}{y^{2}}\\sin{x^{2}}$$\n\nSince $D_{1}(D_{2}f) = D_{2}(D_{1}f)$ for all values of $(x,y)$\n\\\\\nHence, Proved\n\n\\section{}\n\nGiven the scalar field $$f(x,y,z) = x^{2} + 2y^{2} + 3z^{2}$$\n\nand the unit vector $\\frac{i - j + 2k}{\\sqrt{6}}$\n\nThe directional derivative at $(1, 1, 0)$ in the direction of $\\vec{v} = i - j + 2k$ equals to\n\n$$DD = f((1,1,0);(\\frac{1}{\\sqrt{6}}, \\frac{-1}{\\sqrt{6}}, \\frac{2}{\\sqrt{6}})) = \\lim_{h\\to0}\\frac{f((1,1,0) + h(\\frac{1}{\\sqrt{6}}, \\frac{-1}{\\sqrt{6}}, \\frac{2}{\\sqrt{6}})) - f(1,1,0)}{h}$$\n\n$$= \\lim_{h\\to0}\\frac{\\frac{(h + \\sqrt{6})^{2}}{6} + \\frac{(-h + \\sqrt{6})^{2}}{6} + \\frac{12h^{2}}{6} - 3}{h}$$\n\nApplying L' Hopitals rule, we get\n\n$$\\lim_{h\\to0}\\frac{15h^{2} - 2\\sqrt{6}h}{6h} = \\frac{-2}{\\sqrt{6}}$$\n\n\n\n\\section{}\n\nGiven the scalar field $$f(x,y,z) = axy^{2} + byz + cz^{2}x^{3}$$\n  has a maximum value of 64 in a direction parallel\nto the z -axis.\n\nThe directional derivative at $(1, 2, −1)$ in the direction parallel to the $z$ axis being $\\vec{v} = k$ equals to\n\n$${\\Big(\\frac{\\partial f}{\\partial x}i + \\frac{\\partial f}{\\partial y}j + \\frac{\\partial f}{\\partial z}k}\\Big)\\cdot\\big({k}\\big)$$\n\nReplacing values, we get\n\n$$\\Big((ay^{2} + 3cz^{2}x{2})i + (2axy + bz)j + (by + 2czx^{3})k\\Big)\\cdot\\big({k}\\big)$$\n\nwhere $(x,y,z) \\rightarrow (0,0,1)$, we get\n\n$$\\Big((4a + 3c)i + (4a - b)j + (2b - 2c)k\\Big)\\cdot\\big({k}\\big) = \\big(\\frac{2b - 2c}{\\sqrt{1}}\\big) = 64$$\n\nHence, we get \n\n$$b - c = 32$$\n\\\\\n\\\\\nIf maximum occurs along a direction, then the minimum occurs along a direction perpendicular to it.\n\n$$4a + 3c = 0$$\n$$4a - b = 0$$\n\nSolving these equations, we get\n\n$$a = 6, b = 24, c = -8$$\n\n\n\n\\section{}\n\nGiven \n$$\\textbf{r}(x,y,z) = xi + yj + zk$$ and $$r(x,y,z) = ||\\textbf{r}(x,y,z)|| = \\sqrt{x^{2} + y^{2} + z^{2}}$$\n\nAlso \n$$r^{n} = \\sqrt[n/2]{x^{2} + y^{2} + z^{2}}$$\n\nComputing for some value $n$, a positive integer, the gradient of $r^{n}$\n\n$$ \\nabla(r^{n}) = \\Big(\\frac{\\partial r^{n}}{\\partial x}i + \\frac{\\partial r^{n}}{\\partial y}j + \\frac{\\partial r^{n}}{\\partial z}k\\Big)$$\n\n$$\\nabla(r^{n}) = \\Big(\\frac{2nx\\sqrt[(n-2)/2]{x^{2} + y^{2} + z^{2}}}{2}i + \\frac{2ny\\sqrt[(n-2)/2]{x^{2} + y^{2} + z^{2}}}{2}j + \\frac{2nz\\sqrt[(n-2)/2]{x^{2} + y^{2} + z^{2}}}{2}k\\Big)$$\n\n$$\\nabla(r^{n}) = \\Big(nx\\sqrt[(n-2)/2]{x^{2} + y^{2} + z^{2}}i + ny\\sqrt[(n-2)/2]{x^{2} + y^{2} + z^{2}}j + nz\\sqrt[(n-2)/2]{x^{2} + y^{2} + z^{2}}k\\Big)$$\n\n$$\\nabla(r^{n}) = \\Big(n\\sqrt[(n-2)/2]{x^{2} + y^{2} + z^{2}}\\Big)\\times\\Big(xi + yj + zk\\Big)$$\n\n$$\\nabla(r^{n}) = \\Big(nr^{n-2}\\Big)\\times\\Big(xi + yj + zk\\Big)$$\n\n$$\\nabla(r^{n}) = nr^{n-2}\\textbf{r}$$\n\n\\section{}\n\nGiven a function $u = f(x,y)$, $x = X(t)$, $y = Y(t)$ define $u$ as a function of $t$, say $u = F(t)$\n\n\\subsection{}\n\nGiven $$f(x,y) = x^{2} + y^{2} , X(t) = t, Y(t) = t^{2}$$\n\nReplacing the given values of $(x,y)$ as $(X(t),Y(t))$, we get\n\n$$u(t) = t^{2} + t^{4}$$\n\n$F\\prime(t)$ can be calculated as\n\n$$F\\prime(t) = \\frac{du(t)}{dt}$$\n\n$$F\\prime(t) = \\frac{d(t^{2} + t^{4})}{dt}$$\n\n$$F\\prime(t) = 2t + 4t^{3}$$\n\n$F\\prime\\prime(t)$ can be calculated as\n\n$$F\\prime\\prime(t) = \\frac{dF\\prime(t)}{dt}$$\n\n$$F\\prime\\prime(t) = \\frac{d(2t + 4t^{3})}{dt}$$\n\n$$F\\prime\\prime(t) = 2 + 12t^{2}$$\n\n\\subsection{}\n\nGiven $$f(x,y) = e^{xy}\\cos(xy^{2}), X(t) = \\cos(t), Y(t) = \\sin(t)$$\n\nReplacing the given values of $(x,y)$ as $(X(t),Y(t))$, we get\n\n$$u(t) = e^{\\cos(t)\\sin(t)}\\cos(\\cos(t)(\\sin(t))^{2})$$\n\n$F\\prime(t)$ can be calculated as\n\n$$F\\prime(t) = \\frac{du(t)}{dt}$$\n\n$$F\\prime(t) = \\frac{d(e^{\\cos(t)\\sin(t)}\\cos(\\cos(t)(\\sin(t))^{2}))}{dt}$$\n\nHave to add.\n\n\\section{}\nSee appended section \n\\section{}\nSee appended section\n\\section{}\nSee appended section\n\\section{}\nSee appended section\n\\section{}\nSee appended section\n\\section{}\nSee appended section\n\\section{}\nSee appended section\n\\section{}\n\n\\subsection{}\n\nGiven $$f(x,y,z) = (y^{2} − z^{2})i + 2yzj − x^{2}k$$\n\nalong the path described by $\\alpha(t) = ti + t^{2}j + t^{3}k$\n\\\\\n\\\\\nThe line integral of the vector field is\n\n$$\\int{f(\\alpha(t))}\\cdot{d\\alpha} = \\int {((t^{4} − t^{6})i + 2t^{5}j − t^{2}k)}\\cdot{(i + 2tj + 3t^{2}k)}dt$$\n\n$$= \\int{(t^{4} - t^{6}) + 4t^{6} - 3t^{4}}dt$$\n\n$$= \\Big(\\frac{-2t^{5}}{5} + \\frac{3t^{7}}{7}\\Big)$$\n\n\\subsection{}\n\nSee appended section\n\n\\section{}\n\n\\subsection{}\n\nGiven $$\\int_{C}(x^{2} - 2xy)dx + (y^{2} - 2xy)dy$$\n\nwhere $C$ is a path from $(−2,4)$ to $(1,1)$ along the parabola $C$ $y = x^{2}$.\n\\\\\n\\\\\nThe parametric equation of the curve is $x = t$ and $y = t^{2}$, then the line integral is\n\n$$= \\int_{-2}^{1}(t^{2} - 2t^{3})dt + 2(t^{5} - 2t^{4})dt$$\n\n$$= \\int_{-2}^{1}(t^{2} - 2t^{3} + 2t^{5} - 4t^{4})dt$$\n\n$$= \\Big(\\frac{t^{3}}{3} - \\frac{t^{4}}{2} + \\frac{t^{6}}{3} - \\frac{4t^{5}}{5}\\Big)_{-2}^{1}$$\n\n$$= \\frac{396}{10}$$\n\n\\subsection{}\n\nGiven $$\\int_{C}\\frac{(x+y)dx - (x-y)dy}{x^{2} + y^{2}}$$\n\nwhere $C$ is is the circle $x^{2} + y^{2} = a^{2}$ traversed once in a counter-clockwise direction.\n\\\\\n\\\\\nThe parametric equation of the curve is $x = a\\cos{t}$ and $y = a\\sin{t}$, then the line integral is\n\n$$= \\int_{0}^{2\\pi}\\frac{-a\\sin{t}(\\cos{t}+\\sin{t})dt - a\\cos{t}(\\cos{t}-\\sin{t})dt}{a^{2}({\\cos{t}}^{2} + {\\sin{t}}^{2})}$$\n\n$$= \\int_{0}^{2\\pi}\\frac{-a({\\sin{t}}^{2} + {\\cos{t}}^{2})dt}{a^{2}}$$\n\n$$= \\int_{0}^{2\\pi}\\frac{-dt}{a}$$\n\n$$= \\int_{0}^{2\\pi}\\frac{-dt}{a}$$\n\n$$= \\Big(\\frac{-t}{a}\\Big)_{0}^{2\\pi}$$\n\n$$= \\frac{-2\\pi}{a}$$\n\\section{}\n\\subsection{}\nGiven the vector field $$f(x, y) = (2xe^{y} + y)i + (x^{2}e^{y} + x − 2y)j$$\n\nWe have $$f_{1}(x,y) = 2xe^{y} + y$$ and $$f_{2}(x,y) = x^{2}e^{y} + x − 2y$$\n\nThen, the partial derivatives $D_{2}f_{1}$ and $D_{1}f_{2}$ are given by\n$$D_{2}f_{1} = 2xe^{y} + 1$$\n\nand\n\n$$D_{1}f_{2} = 2xe^{y} + 1$$\n\nSince $D_{2}f_{1} = D_{1}f_{2}$ for all values of $(x,y)$, this vector field is a gradient on any open subset of $R^{2}$.\n\\\\\nWe know that $$\\frac{\\partial \\phi}{\\partial x} = 2xe^{y} + 1$$ and $$\\frac{\\partial \\phi}{\\partial y} = 2xe^{y} + 1$$ \n\nUsing indefinite integrals and integrating the first of these equations with respect to x (holding y constant) we find\n\n$$\\phi(x,y) = \\int(2xe^{y} + 1)dx + A(y) = x^{2}e^{y} + x + A(y)$$\n\nand\n\n$$\\phi(x,y) = \\int(2xe^{y} + 1)dy + B(x) = 2xe^{y} + y + B(x)$$\n\n\\subsection{}\n\nGiven the vector field $$f(x,y,z) = 2xy^{3}i + x^{2}z^{3}j + 3x^{2}yz^{2}k$$\n\nWe have $$f_{1}(x,y) = 2xy^{3}$$ $$f_{2}(x,z) = x^{2}z^{3}$$ $$f_{3}(x,y,z) = 3x^{2}yz^{2}$$\n\nThen, the partial derivatives $D_{3}f_{1}$, $D_{2}f_{2}$ and $D_{1}f_{3}$ are given by\n$$D_{3}f_{1} = 0$$\n\n$$D_{2}f_{2} = 0$$\n\n$$D_{1}f_{3} = 6xyz^{2}$$\n\nSince $D_{3}f_{1} = D_{2}f_{2} = D_{1}f_{3}$ only when either $x, y$ or $z$ is equal to $0$\n\nHence, this vector is not a gradient of a scalar field $\\phi$\n\n\\newpage\n\n\\section{Appendix}\n\nDue to time constrains, I haven't been able to type all the solutions for the assignments in LaTeX. The answers that refer to this section are in the other document.\n\n\\end{document}", "meta": {"hexsha": "7b54366dc135ed0f60670b0db51ed7f274211dac", "size": 11922, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "I/SemI/Mathematics/calculus/Assignment3/template.tex", "max_stars_repo_name": "Rochan-A/MECAcademicResources", "max_stars_repo_head_hexsha": "9bfca3e5480537cfbe75b4e23e2ec5f8ab627945", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-01-08T14:12:31.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-08T14:12:31.000Z", "max_issues_repo_path": "I/SemI/Mathematics/calculus/Assignment3/template.tex", "max_issues_repo_name": "Rochan-A/MECAcademicResources", "max_issues_repo_head_hexsha": "9bfca3e5480537cfbe75b4e23e2ec5f8ab627945", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "I/SemI/Mathematics/calculus/Assignment3/template.tex", "max_forks_repo_name": "Rochan-A/MECAcademicResources", "max_forks_repo_head_hexsha": "9bfca3e5480537cfbe75b4e23e2ec5f8ab627945", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.8796992481, "max_line_length": 295, "alphanum_fraction": 0.5470558631, "num_tokens": 5368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950907764118, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7032385402468665}}
{"text": "\\section{Simulation}\n\nWe need to simulate a data set to train, tune and selecting an algorithm for stock picking. As described in section \\ref{sec:model} the returns on the stocks are drawn from a distribution (here assumed to be normal):\n\n\\begin{equation}\n    \\rr^{(t)} \\sim N(\\mu^{(t)}, \\Omega^{(t)})\n\\end{equation}\n\n\\subsection{Sampling of expected returns}\n\nInvestigating the distribution of means, we find it is reasonable to assume the expected return for an individual stocks follows a normal distribution:\n\n\\begin{equation}\n    \\mu^{(t)}_{i} \\sim N(\\xi, \\sigma_{r})\n\\end{equation}\n\nTo estimate the parameters $\\xi$, $\\sigma_r$ we perform a log-likelihood estimation which yields the following values: $\\xi=0.000461$ and $\\sigma_r = 0.00123$. Figure \\ref{fig:distmeans} plots the fitted distribution vs. the empirical distribution, and even though the fourth moment of the distribution seems not to exactly follow the normal distribution, the normal distribution appears to be a good approximation of the data generating process of $\\mu_i^{(t)}$.\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.3]{figures/distribution_means.png}\n\\caption{Distribution of individual means $\\mu_i^{(t)}$}\n\\label{fig:distmeans}\n\\end{figure}\n\n\n\\subsection{Sampling of covariance matrix}\n\nSampling the covariance matrix is more involved than sampling $\\mu$. I go the following way about in in this paper: Realize that a transformation from a covariance matrix to a correlation matrix is possible:\n\n\\begin{equation}\n    \\text{corr}_{x, y} = \\frac{\\sigma_{x,y}^{2}}{\\sigma_x \\cdot \\sigma_y}\n\\end{equation}\n\nTherefore we first need to sample a correlation matrix, then a vector of variances, then transform the correlation matrix to the covariance matrix $\\Omega^{(t)}$.\n\n\\subsubsection{Sampling of correlation matrix}\n\nSampling a correlation matrix is not as straightforward as sampling the individual stock returns, $\\mu_i^{(t)}$. This is due to the fact, the correlation matrix should adhere to multiple criteria:\n\n\\begin{enumerate}\n    \\item A correlation matrix is a positive definite matrix.\n    \\item The individual values (apart from the diagonal) of the correlation matrix should follow a normal distribution $\\rho_{i}^{(t)} \\sim N(\\kappa, \\sigma_\\rho)$.\n\\end{enumerate}\n\nIn this paper to accomplish the desired I use the following sampling scheme:\n\n\\begin{enumerate}\n    \\item Initialize an empty matrix $M$ of size $k \\times k$.\n    \\item sample individual observations $\\rho_{i,j}=\\rho_{j,i}$ from a fitted normal distribtuion.\n    \\item Replace the diagonal of $M$ with 1.\n    \\item Save the matrix $M$ if all eigenvalues are positive, i.e. $M$ is positive definite.\n\\end{enumerate}\n\nFigure \\ref{fig:distcorrs} shows the fitted distribution plotted against the empirical distribution with regards to the individual $\\rho_{i,j}^{(t)}$ not considering the diagonal. Again log-likelihood estimation is used to estimate the parameters: $\\kappa=0.313, \\sigma_\\rho=0.188$. Again we see that, the actual distribution does not perfectly follow a normal distribution, but passes for a good approximation. It should be noted that when sampling from this distribution, the distribution is truncated at $(-1, 1)$.\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.3]{figures/correlation_distribution.png}\n\\caption{Distribution of individual correlates $\\rho_{i,j}^{(t)}$}\n\\label{fig:distcorrs}\n\\end{figure}\n\n\\subsubsection{Sampling of variances}\n\nThe variances does not follow a normal distribution, this is obvious, since the variance by definition is a positive measure. I model the variances to be exponentially distributed: $\\sigma^2_{i} \\sim expon(\\lambda)$. Using log-likelihood estimation we find the $\\lambda=0.000346$. Figure \\ref{fig:distvars} displays the fitted distribution against the empirical distribution. I conclude that the exponential distribution is a reasonable approximation of the true distribution.\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.3]{figures/distribution_variances.png}\n\\caption{Distribution of individual variances}\n\\label{fig:distvars}\n\\end{figure}\n\n\n\\subsubsection{The simulated covariance distribution vs. the empirical distribution}\n\nUsing the scheme described above, I simulate a set of covariance matrices. Figure \\ref{fig:distcovars} displays the simulated distribution of individual covariances vs. the empirical distribution of individual covariances. From the figure, we see that the simulated distribution, seems slightly biased towards 0. However I conclude that for the purpose of this paper the simulation passes as a good approximation.\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.3]{figures/dist_simulated_covariances.png}\n\\caption{Distribution of individual covariances}\n\\label{fig:distcovars}\n\\end{figure}\n\n\\subsubsection{The simulated data set}\n\nNow having simulated covariance matrices, and returns, we can simulate an entire data set, that corresponds to our model. We simulate a data set of $11$ columns and $2.000.0000$ rows, which is more than necessary for the further investigation in this paper. We set the parameter $p=0.047$, so we have just slightly less then $10.000$ structural breaks in the simulated data set. Since we have the underlying $\\mu^{(t)}$ and $\\Omega^{(t)}$ in each period, we can calculate the Sharpe ratios for each of the simulated stocks throughout the period assuming the risk free asset having a return of $\\bar{r}=2 \\%$ annually.\n\nSumming it all up: A dataset is now constructed based on a structural model. The data set consists of not only the simulated returns, but also the Sharpe ratios of the individual stocks, which in the real data set are latent variables. The simulated data set allows for training, tuning and selecting between algorithms.\n\n", "meta": {"hexsha": "b45649141489e1bd4783888947a1e3e41dc4ec93", "size": 5766, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/simulation.tex", "max_stars_repo_name": "JakartaLaw/ACFS", "max_stars_repo_head_hexsha": "dd7e6107ae22e987923dd5b81a8605d88650fce9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-04T01:20:46.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-04T01:20:46.000Z", "max_issues_repo_path": "chapters/simulation.tex", "max_issues_repo_name": "JakartaLaw/ACFS", "max_issues_repo_head_hexsha": "dd7e6107ae22e987923dd5b81a8605d88650fce9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2020-03-24T17:21:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-13T20:09:54.000Z", "max_forks_repo_path": "chapters/simulation.tex", "max_forks_repo_name": "JakartaLaw/ACFS", "max_forks_repo_head_hexsha": "dd7e6107ae22e987923dd5b81a8605d88650fce9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-07T07:34:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-07T07:34:46.000Z", "avg_line_length": 62.0, "max_line_length": 617, "alphanum_fraction": 0.7752341311, "num_tokens": 1361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603726, "lm_q2_score": 0.8311430499496095, "lm_q1q2_score": 0.703099187110766}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Signed variables}\\label{sec:}\n\nRandom variables that take both positive and negative values are called \\emph{signed variables}. \n\n\\begin{definition}\nThe \\emph{positive part} and \\emph{negative part} of a random variable $X$ are\n\\begin{align*}\nX^{+}(\\omega) \n\t& = \\begin{cases} \n\t\t\tX(\\omega)\t& \\text{if } X(\\omega)\\geq 0, \\\\\n\t   \t\t0 \t\t \t& \\text{if } X(\\omega) < 0, \\text{ and}\n\t\\end{cases} \\\\[2ex]\nX^{-}(\\omega)\t\n\t& = \\begin{cases} \n\t\t\t-X(\\omega)\t& \\text{if } X(\\omega) < 0, \\\\\n\t\t\t0 \t\t \t& \\text{if } X(\\omega) \\geq 0.\n\t\t\\end{cases}\n\\end{align*}\nrespectively. \n\\end{definition}\n\nNote that $X^{+}$ and $X^{-}$ are both non-negative random variables with\n\\[\nX = X^{+} - X^{-}\n\\qquad\\text{and}\\qquad\n|X| = X^{+} + X^{-}.\n\\]\n\n\\begin{definition}[Expectation of signed random variables]\nThe \\emph{expectation} of a signed random variable $X$ is\n\\[\n\\expe(X) = \\expe(X^{+}) - \\expe(X^{-})\n\\]\nprovided that $\\expe(X^{+})$ and $\\expe(X^{-})$ are not both infinite.\n\\end{definition}\n\n\\begin{remark}\nIf $\\expe(X^{+})$ and $\\expe(X^{-})$ are both infinite, the expectation of $X$ is \\emph{undefined} because we cannot make sense of the expression ``$\\infty - \\infty$''. In this case we say that the expectation of $X$ \\emph{does not exist}.\n\\end{remark}\n\n\\begin{example} % discrete, undefined\nLet $X$ be a discrete random variable with the following PMF:\n\\[\nf(k) = \\begin{cases}\n\t\\displaystyle\\frac{3}{\\pi^2 k^2} \t& \\text{if }\\ k\\in\\{\\pm 1,\\pm 2, \\ldots\\} \\\\[1ex]\n\t0\t\t\t\t\t\t& \\text{otherwise.}\n\\end{cases}\t\n\\]\nShow that $\\expe(X)$ is undefined.\n\\begin{solution}\n$X$ is a signed random variable, so we must deal with its positive and negative parts separately:\n\\[\nX^{+}\t= \\begin{cases}  X & \\text{ if } X \\geq 0, \\\\ 0 & \\text{otherwise.}\\end{cases}\n\\qquad\\text{and}\\qquad\nX^{-}\t= \\begin{cases} -X & \\text{ if } X <    0, \\\\ 0 & \\text{otherwise.}\\end{cases}\n\\]\nThe expected values of $X^{+}$ and $X^{-}$ are\n\\[\\begin{array}{lll}\n\\expe(X^{+})\t\n\t& = \\displaystyle \\sum_{k=1}^{\\infty} k \\left(\\frac{3}{\\pi^2 k^2}\\right)\n\t& = \\displaystyle \\frac{3}{\\pi^2} \\sum_{k=1}^{\\infty}\\frac{1}{k} = \\infty \\\\[2ex]\n\\expe(X^{-})\t\n\t& = \\displaystyle \\sum_{k=-\\infty}^{-1} (-k) \\left(\\frac{3}{\\pi^2 k^2}\\right)\n\t& = \\displaystyle \\frac{3}{\\pi^2} \\sum_{k=1}^{\\infty}\\frac{1}{k} = \\infty \\\\\n\\end{array}\\]\nso $\\expe(X) = \\expe(X^{+}) - \\expe(X^{-})$ is undefined.\n\\end{solution}\n\\end{example}\n\n\\begin{example}[Cauchy distribution]% continuous - undefined\nLet $X$ be a continuous random variable having the following PDF,\n\\[\nf(x) = \\frac{1}{\\pi(1+x^2)}\\qquad\\text{for all $x\\in\\R$.}\n\\]\nShow that $\\expe(X)$ is undefined.\n\\begin{solution}\n$X$ is a signed variable, so we must deal with its positive and negative parts separately:\n\n\\[\\begin{array}{lll}\n\\expe(X^{+}) \n\t& = \\displaystyle\\int_0^\\infty xf(x)\\,dx \n\t& = \\displaystyle\\frac{1}{\\pi}\\int_0^\\infty \\frac{x}{1+x^2}\\,dx  \\\\[2ex]\n\\expe(X^{-})\t\n\t& = \\displaystyle\\int_{-\\infty}^0 (-x)f(x)\\,dx\n\t& = \\displaystyle\\frac{1}{\\pi}\\int_0^{\\infty} \\frac{x}{1+x^2}\\,dx\n\\end{array}\\]\nThus $\\expe(X) = \\expe(X^{+}) - \\expe(X^{-})$ is given by\n\\begin{align*}\n\\expe(X)\n%\t& = \\expe(X^{+}) - \\expe(X^{-}) \\\\\n\t& = \\frac{1}{\\pi}\\left[\\int_0^{\\infty} \\frac{x}{1+x^2}\\,dx - \\int_0^{\\infty} \\frac{x}{1+x^2}\\,dx\\right].\n\\end{align*}\n\nAt this point, it might be tempting to conclude that $\\expe(X)=0$. However if $x>1$ then $x^2 > 1$ and therefore $2x^2 > 1+x^2$, so\n\\[\n\\frac{x}{1+x^2} > \\frac{1}{2x} \\qquad\\text{for all } x > 1\n\\]\nConsequently,\n\\[\n\\int_{0}^{\\infty}\\frac{x}{1+x^2}\\,dx\n\t> \\int_{1}^{\\infty}\\frac{x}{1+x^2}\\,dx\n\t> \\frac{1}{2}\\int_{1}^{\\infty}\\frac{1}{x}\\,dx\n\t= \\infty,\n\\]\nso $\\expe(X)$ is undefined.\n\\end{solution}\n\\end{example}\n\n", "meta": {"hexsha": "11d6322421c99701edb2482e1b7915e28a8e5ce7", "size": 3717, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/04C_signed.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/04C_signed.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/04C_signed.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 33.1875, "max_line_length": 239, "alphanum_fraction": 0.5934893732, "num_tokens": 1474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234877, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7030991811196847}}
{"text": "% LinearSpace.tex\n\\documentclass[12pt]{article}\n\\usepackage[T1]{fontenc}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{amsmath, amsfonts, amsthm}\n\\usepackage{verbatim}\n\n\\newcommand{\\xmax}{x_{\\max}}\n\\newcommand{\\xmin}{x_{\\min}}\n\\newcommand{\\xmid}{x_{\\mathrm{mid}}}\n\\newcommand{\\xt}{x-\\xmid}\n\\newcommand{\\xg}{2\\left[ \\frac{x-\\xmin}{\\xmax - \\xmin} \\right] - 1}\n\\newcommand{\\dd}{\\mathop{}\\!\\mathrm{d}}\n\\newcommand{\\Pc}{\\overline{Pc}}\n\n\\title{Hand Calculation of a Linear Space Source Scoring}\n\\author{Jeremy Lloyd Conlin}\n\n\\begin{document}\n\\maketitle\nIn this document, I will try to figure out why my LinearSpace scoring isn't working properly.  The calculations will be done ``by hand'' or at least manually instead of a C++ code.\n\n\\section{Approximating $f(x)$}\nWe will approximate $f(x)$ as a linear combination of polynomials\n\\begin{equation}\n    \\tilde{f}(x) = \\sum_{n=1}^N a_n \\Psi_n(x) \\hspace{0.5in} \\xmin \\leq x \\leq \\xmax\n    \\label{eq:fApproximation}\n\\end{equation}\nwhere $a_n$ is an expansion coefficient and $\\Psi_n(x)$ is some polynomial which has a few properties\n\\begin{equation}\n    \\int_{\\xmin}^{\\xmax} \\Psi_m(x)\\Psi_n(x) \\dd x = \n    \\begin{cases}\n        1 & m = n \\\\\n        0 & m \\neq n.\n    \\end{cases}\n    \\label{eq:Orthonormalized}\n\\end{equation}\nEquation \\ref{eq:Orthonormalized} states that the polynomials $\\Psi_n(x)$ must be normalized and orthogonal to each other.  \n\nWe will make our polynomials the Legendre polynomials $\\Psi_n(x) = P_n(x)$.\n\n\\subsection{Determining the Expansion Coefficients}\nWe can determine the expansion coefficients as \n\\begin{align}\n    \\begin{split}\n        \\int_{\\xmin}^{\\xmax} P_m(x)\\tilde{f}(x) \\dd x  &=\\\\\n        &= \\int_{\\xmin}^{\\xmax} P_m(x)\\sum_{n=1}^{N_p} a_n \\Psi_n(x)\\dd x \\\\\n        &= \\int_{\\xmin}^{\\xmax} P_m(x)\\sum_{n=1}^{N_p} a_n P_n(x)\\dd x \\\\\n        &= \\sum_{n=1}^{N_p}a_n\\int_{\\xmin}^{\\xmax} P_m(x) P_n(x)\\dd x \\\\\n        &= a_n\\int_{\\xmin}^{\\xmax}P_n(x)^2 \\dd x.\n    \\end{split}\n    \\intertext{Therefore}\n    a_n &= \\frac{1}{k_n}\\int_{\\xmin}^{\\xmax} P_n(x)\\tilde{f}(x) \\dd x,\n    \\label{eq:CoefficientDefined}\n    \\intertext{where}\n    k_n &= \\left( \\int_{\\xmin}^{\\xmax} P_n(x)^2 \\dd x \\right)^{1/2}.\n    \\label{eq:NormalizingConstant}\n\\end{align}\nEquation \\ref{eq:CoefficientDefined} uses the orthonormalizing definition in equation \\ref{eq:Orthonormalized}.\n\nEquation \\ref{eq:CoefficientDefined} is---by definition---the expected value of the function $P_n(x)/k_n$ where samples of $x$ are taken from $\\tilde{f}(x)$.  It is much simpler to sample from a uniform distribution.  It is a simple change of variable to allow this;\n\\begin{equation}\n        a_n = \\frac{1}{k_n}\\int_{\\xmin}^{\\xmax} P_n(x)\\omega(x)U(x) \\dd x \\\\\n    \\label{eq:WeightedCoefficient}\n\\end{equation}\nwhere \n\\begin{subequations}\n    \\begin{align}\n        \\omega(x) &= \\frac{\\tilde{f}(x)}{U(x)}\n        \\label{eq:WeightingFunction}\n        \\intertext{is a weighting function, and}\n        U(x) &= \\frac{1}{\\xmax-\\xmin}\n        \\label{eq:UniformDistribution}\n    \\end{align}\n\\end{subequations}\nis a uniformly distributed PDF.  \n\nA careful comparison between equations \\ref{eq:CoefficientDefined} and \\ref{eq:WeightedCoefficient} reveals we have only multiplied the integrand by $U(x)/U(x) = 1$, but we have changed the nature of the problem to make it simpler; we can now sample from a uniform distribution and score the weighted Legendre polynomial $P_n(x)\\omega(x)$.  We can sample and score $N_i$ times; the mean of these evaluations is an estimate of the expansion coefficient:\n\\begin{equation}\n    \\hat{a}_n = \\frac{1}{N_i}\\frac{1}{k_n} \\sum_{i=1}^{N_i} P_n(x_i) \\omega(x_i).\n    \\label{eq:MCCoefficient}\n\\end{equation}\n\nIn this paper I will only use expansions with two basis functions, $N=2$ so we can write out the functions that we will need.\n\\begin{subequations}\n    \\begin{align}\n        P_0(x) & = 1 \\\\\n        P_1(x) & = x \\\\\n    \\end{align}\n    \\label{eq:LegendrePolynomials}\n\\end{subequations}\n\\begin{subequations}\n    \\begin{align}\n        k_0 = \\int_{\\xmin}^{\\xmax} P_0(x) \\dd x = \\int_{\\xmin}^{\\xmax}  \\dd x &= \\boxed{\\left(\\xmax - \\xmin\\right) = k_0} \\\\\n        k_1 = \\int_{\\xmin}^{\\xmax} P_1(x) \\dd x = \\int_{\\xmin}^{\\xmax} x^2 \\dd x &= \\boxed{\\frac{1}{3}\\left(\\xmax^3 - \\xmin^3\\right) = k_1}\n    \\end{align}\n    \\label{eq:ConstantsDefined}\n\\end{subequations}\n\n\\section{Simple Example}\n\\begin{equation}\n    f(x) = \\frac{1}{2}\\left( x+1 \\right), \\hspace{0.5in} -1 \\leq x \\leq 1.\n    \\label{eq:original}\n\\end{equation}\n$f(x)$ is already normalized so it is ready for sampling.  The normalization constants for this problem are\n\\begin{subequations}\n    \\begin{align}\n        k_0 &= \\int_{\\xmin}^{\\xmax}  \\dd x = \\left(\\xmax - \\xmin\\right) = \\left(1 - (-1)\\right) = 2 \\\\\n        k_1 &= \\int_{\\xmin}^{\\xmax} x^2 \\dd x = \\frac{1}{3}\\left(\\xmax^3 - \\xmin^3\\right) = \\frac{1}{3}\\left(1^3 - (-1)^3\\right) = \\frac{2}{3}.\n    \\end{align}\n\\end{subequations}\nWe can also define the uniform distribution and weighting functions, respectively\n\\begin{subequations}\n    \\begin{align}\n        U(x) &= \\frac{1}{\\xmax - \\xmin} = \\frac{1}{2} \\\\\n        \\omega(x) &= \\frac{\\tilde{f}(x)}{U(x)} = x+1.\n    \\end{align}\n\\end{subequations}\nThe expansion coefficients:\n\\begin{subequations}\n    \\begin{align}\n        \\hat{a}_0 &= \\frac{1}{N_i}\\frac{1}{k_0} \\sum_{i=1}^{N_i} P_0(x_i)\\omega(x_i) = \\frac{1}{N_i}\\frac{1}{2} \\sum_{i=1}^{N_i} \\omega(x_i) \\\\\n        \\hat{a}_1 &= \\frac{1}{N_i}\\frac{1}{k_1} \\sum_{i=1}^{N_i} P_1(x_i)\\omega(x_i) = \\frac{1}{N_i}\\frac{3}{2} \\sum_{i=1}^{N_i} x_i\\,\\omega(x_i).\n    \\end{align}\n    \\label{eq:MCCoeffSimple}\n\\end{subequations}\n\nWe learned that you can't perform a simulation by performing this calculation by hand, that is, you can't do just a few points and expect the answer to be correct.  The variance of this is just too large.  We can evaluate the coefficients many times easily with a computer then we can have enough data points to make it good enough.  \n    \nIt works!\n\n\\section{Harder Example}\nThis section has a function that is not on the traditional range $[-1,1]$.  The function used for this example is:\n\\begin{equation}\n    f(x) = x-1, \\hspace{0.5in} 1 \\leq x \\leq 5.\n    \\label{eq:original}\n\\end{equation}\nNormalized such that \n\\begin{equation}\n    \\int_1^5 f(x)^2 \\dd x = 1,\n\\end{equation}\nEquation \\ref{eq:original} becomes\n\\begin{equation}\n    f(x) = 0.125\\left( x-1 \\right) \\hspace{0.5in} 1 \\leq x \\leq 5.\n    \\label{eq:normalized}\n\\end{equation}\nThe midpoint of this ``bin'' is\n\\begin{equation}\n    \\xmid = \\frac{\\xmax + \\xmin}{2.0} = \\frac{5 + 1}{2.0} = 3.0\n    \\label{eq:xmid}\n\\end{equation}\nand we will define\n\\begin{equation}\n    \\tilde{x} \\equiv x - \\xmid. \\label{eq:xTilde}\n\\end{equation}\n\nThe thing that makes this function more difficult is the fact that the Legendre polynomials are not naturally orthogonal to each other on the range $[1,5]$.  We can show that they are orthogonal to each other if the range is centered at 0 (at least we can show that the 0th and 1st basis functions are orthogonal to each other if they are centered at 0).  To do so, we shift the Legendre polynomial by subtracting the midpoint of the range from the x point and then we can integrate:\n\nNow we need to be a bit more careful with this new derivation.  So I'll try to be a bit more formal.\n\n\\subsection{More formal}\nWe can define our function as an expansion of basis functions as before,\n\\begin{equation}\n    \\tilde{f}(x) = \\sum a_m P_m(x).\n    \\label{eq:fExpansion}\n\\end{equation}\n\nFinding the expansion coefficients is similar to how this is done before, but we must shift our Legendre polynomials and $\\tilde{f}(x)$ so that the range is centered about zero.  The simplest way to do this is to subtract the midpoint of the original range as I defined as $\\tilde{x}$.  Now we can proceed as usual:\n\\begin{equation}\n    \\begin{split}\n        \\int_{\\xmin}^{\\xmin} P_n(\\xt)\\tilde{f}(\\xt) \\dd x &= \\\\\n        &= \\int_{\\xmin}^{\\xmin} P_n(\\tilde{x})\\tilde{f}(\\tilde{x}) \\dd x \\\\\n        &= \\int_{\\xmin}^{\\xmin} P_n(\\tilde{x})\\sum a_m P_m(\\tilde{x}) \\dd x \\\\\n        &= \\sum a_m \\int_{\\xmin}^{\\xmin} P_n(\\tilde{x})P_m(\\tilde{x}) \\dd x \\\\\n        &= a_n k_n\n    \\end{split}\n    \\label{eq:Coefficients}\n\\end{equation}\nwhere\n\\begin{equation}\n    k_n = \\int_{\\xmin}^{\\xmax} P_n(\\xt)^2 \\dd x.\n    \\label{eq:knDefined}\n\\end{equation}\nSolving equation \\eqref{eq:Coefficients} for $a_n$ we get\n\\begin{equation}\n    a_n = \\frac{1}{k_n}\\int_{\\xmin}^{\\xmin} P_n(\\xt)\\tilde{f}(\\xt) \\dd x.\n    \\label{eq:CoeffDefined}\n\\end{equation}\nOf course we want to be able to sample from a uniform distribution when doing our Monte Carlo so now we rewrite equation \\eqref{eq:CoeffDefined} as\n\\begin{equation}\n    a_n = \\frac{1}{k_n}\\int_{\\xmin}^{\\xmin} P_n(\\xt)\\underbrace{\\frac{\\tilde{f}(\\xt)}{U(\\xt)}}_{\\omega(\\xt)}U(\\xt) \\dd x.\n    \\label{eq:CoeffDefined}\n\\end{equation}\nOur Monte Carlo approximation for this coefficient is then\n\\begin{equation}\n    \\hat{a}_n = \\frac{1}{k_n}\\frac{1}{N} \\sum_{i=1}^N P_n(x_i - \\xmid) \\omega(x_i - \\xmid)\n    \\label{eq:MCCoefficients}\n\\end{equation}\nwhere the $x_i$s are sampled from the uniform distribution $U(x)$.\n\nThis derivation requires that the shifted Legendre polynomials are orthogonal to each other on the range $[\\xmin, \\xmax]$.  We can do this for $n=1$ and $m=0$:\n\\begin{equation}\n    \\begin{split}\n        \\int_{\\xmin}^{\\xmax} P_0(x-\\xmid)P_1(x-\\xmid) \\dd x &= \\\\\n         &=\\int_{\\xmin}^{\\xmax} (1) \\left( x-\\xmid \\right) \\dd x \\\\\n         &=\\int_{\\xmin}^{\\xmax} \\left( x-\\xmid \\right) \\dd x \\\\\n         &=\\left[\\frac{1}{2}x^2-\\xmid\\; x\\right]_{\\xmin}^{\\xmax} \\\\\n         &=\\frac{1}{2}\\left(\\xmax^2 - \\xmin^2\\right)-\\xmid\\left(\\xmax-\\xmin\\right)\\\\\n         &=\\frac{1}{2}\\left(\\xmax^2 - \\xmin^2\\right)-\\left(\\frac{\\xmax+\\xmin}{2}\\right)\\left(\\xmax-\\xmin\\right)\\\\\n         &=\\frac{1}{2}\\left(\\xmax^2 - \\xmin^2\\right)-\\frac{1}{2}\\left(\\xmax^2-\\xmin^2\\right)\\\\\n         &= 0.\n    \\end{split}\n\\end{equation}\nThis can be done in general as\n\\begin{equation}\n    \\int_{\\xmin}^{\\xmax}P_n(\\xt)P_m(\\xt) \\dd x.\n\\end{equation}\nWe first need to make a change of variable\n\\begin{equation}\n   u = \\xt, \\qquad  \\dd u = \\dd x\n   \\label{eq:VariableChange}\n\\end{equation}\n\\begin{subequations}\n    \\label{eq:uLimits}\n    \\begin{alignat}{4}\n        u_{max} &= u(\\xmax) &= \\xmax - \\xmid &= \\frac{\\xmax - \\xmin}{2} & &=t \\\\\n        u_{min} &= u(\\xmin) &= \\xmin - \\xmid &= \\frac{\\xmin - \\xmax}{2} &=-\\frac{\\xmax - \\xmin}{2} &= -t\n    \\end{alignat}\n\\end{subequations}\nInserting equations \\eqref{eq:VariableChange} and \\eqref{eq:uLimits} we obtain\n\\begin{equation}\n    \\int_{-t}^{t}P_n(u)P_m(u) \\dd u.\n    \\label{eq:NewIntegral}\n\\end{equation}\nEquation \\eqref{eq:NewIntegral} is valid for any value of $t$.  We know that for $t=1$ this integral evaluates to zero.  However this is not true for any $n$ and $m$.  It is true for $n+m = 2i+1 = \\mathrm{odd}$.  This can be seen by noting that $P_n(x)$ is a polynomial of degree $n$ and that $P_n(x)P_m(x)$ is a polynomial of degree $n+m$.  A polynomial with an odd degree is an odd function and therefore will integrate to zero if the limits of integration are centered about zero.  If the degree is even, the polynomial is an even function and the integral will not be zero.  Therefore shifting the Legendre polynomials will not work in general this way.  I will have to move to David Griesheimer's version of the shifted polynomials.  My method will work if I am just using a second order expansion.\n\n\\section{Griesheimer's Method of Shifting}\nGriesheimer defined his expansion not too differently from what I have been doing;\n\\begin{equation}\n    \\tilde{f}(x) = \\sum a_mP_m\\!\\left(\\hat{x}(x)(x)\\right).\n    \\label{eq:GrExpansion}\n\\end{equation}\nIn Dave's thesis, he (correctly) shifts his Legendre polynomials so that they are not only centered at zero, but also fall in the range $[-1,1]$.  To do this it is a simple scaling\n\\begin{equation}\n    \\hat{x}(x) = \\xg.\n    \\label{eq:xScaled}\n\\end{equation}\nWith this scaling it is easy to see that the range of $\\hat{x}(x)$ is what we desire.\n\nWe can determine our expansion coefficients similarly to what we have already done\n\\begin{equation}\n    \\begin{split}\n        \\int_{\\xmin}^{\\xmax} P_n\\!\\left[\\hat{x}(x)\\right]\\tilde{f}(x) \\dd x &= \\\\\n        &= \\int_{\\xmin}^{\\xmax} P_n\\!\\left[\\hat{x}(x)\\right] \\sum a_mP_m\\!\\left[ \\hat{x}(x) \\right] \\dd x \\\\\n         &=  \\sum a_m\\int_{\\xmin}^{\\xmax} P_n\\!\\left[ \\hat{x}(x) \\right]P_m\\!\\left[ \\hat{x}(x) \\right] \\dd x \\\\\n         &=  a_nk_n.\n    \\end{split}\n    \\label{eq:CoeffsG}\n\\end{equation}\nNow $k_n$ is non-zero whenever $m = n$.  We can evaluate the integral by a change of variable from $x$ to $\\hat{x}(x)$.\n\\begin{equation}\n    k_n = \\int_{\\xmin}^{\\xmax} P_n^2\\left[ \\hat{x}(x) \\right] \\dd x \\label{eq:kn}\n\\end{equation}\nLet \n\\begin{alignat}{2}\n    y &= \\hat{x}(x) & \\qquad y\\!\\left(\\xmin\\right) &= -1 \\\\\n    \\dd y &= \\frac{2}{\\xmax - \\xmin} \\dd x & \\qquad y\\!\\left(\\xmax\\right) &= 1.\n\\end{alignat}\nEquation \\eqref{eq:kn} becomes\n\\begin{equation}\n    k_n = \\frac{\\xmax-\\xmin}{2}\\int_{-1}^{1} P_n^2\\left( y \\right) \\dd y = \\frac{\\xmax-\\xmin}{2}\\frac{2}{2n+1} = \\frac{\\xmax-\\xmin}{2n+1}.\n\\end{equation}\n\nSolving equation \\eqref{eq:CoeffsG} for $a_n$ we obtain\n\\begin{equation}\n    \\begin{split}\n        a_n &= \\frac{1}{k_n}\\int_{\\xmin}^{\\xmax}P_n(\\hat{x}(x))\\tilde{f}(x) \\dd x \\\\\n         &= \\frac{1}{k_n}\\int_{\\xmin}^{\\xmax}P_n\\!\\left( \\xg \\right)\\tilde{f}(x) \\dd x \\\\\n    \\end{split}\n\\end{equation}\nWe want this weighted as before so we can sample from a uniform distribution\n\\begin{equation}\n    a_n = \\frac{1}{k_n} \\int_{\\xmin}^{\\xmax} P_n\\left[ \\hat{x}(x) \\right] \\underbrace{\\frac{\\tilde{f}(x)}{U(x)} U(x)}_{\\omega(x)} \\dd x \\\\\n\\end{equation}\n\n\\begin{equation}\n    a_n = \\frac{1}{k_n}\\frac{1}{N}\\sum_{i=1}^{N}P_n\\!\\left( 2\\left[\\frac{x_i-\\xmin}{\\xmax-\\xmin}\\right]-1 \\right)\\omega_n\\!\\left(x_i\\right)\n\\end{equation}\nwhere of course the $x_i$s have been sampled from the uniform distribution $U(x)$.\n\nNow we want our expansion to use just the first two Legendre polynomials, $P_0(x)$ and $P_1(x)$.  We need two expansion coefficients\n\\begin{subequations}\n    \\begin{align}\n        \\begin{split}\n            a_0 &= \\frac{1}{k_0}\\frac{1}{N}\\sum_{i=1}^N P_0\\!\\left( 2\\left[\\frac{x_i-\\xmin}{\\xmax-\\xmin}\\right]-1 \\right)\\omega(x_i) \\\\\n             &=  \\frac{1}{k_0}\\frac{1}{N}\\sum_{i=1}^N \\omega(x_i) \\\\\n        \\end{split}\\\\\n        \\begin{split}\n            a_1 &= \\frac{1}{k_1}\\frac{1}{N}\\sum_{i=1}^N P_1\\!\\left( 2\\left[\\frac{x_i-\\xmin}{\\xmax-\\xmin}\\right]-1 \\right)\\omega(x_i) \\\\\n             &= \\frac{1}{k_1}\\frac{1}{N}\\sum_{i=1}^N  \\left( 2\\left[\\frac{x_i-\\xmin}{\\xmax-\\xmin}\\right]-1 \\right)\\omega(x_i)\\\\\n        \\end{split}\n    \\end{align}\n\\end{subequations}\nOur expanded function becomes\n\\begin{equation}\n    \\begin{split}\n        \\tilde{f}(x) &= a_0P_0\\left(\\hat{x}\\right) + a_1P_1\\left(\\hat{x}\\right) \\\\\n         &= a_0 + a_1\\left( \\xg \\right).\n    \\end{split}\n    \\label{eq:2TermExpansion}\n\\end{equation}\nWhat we would really like is a function of the traditional form \\[ \\tilde{f}(x) = mx+b.\\]  This can be obtained from equation \\eqref{eq:2TermExpansion} with just a bit of algebra\n\\begin{equation}\n    \\tilde{f}(x) = a_1\\left(\\frac{2}{\\xmax-\\xmin}\\right)x + \\left[a_0 - a_1\\left(\\frac{\\xmax+\\xmin}{\\xmax-\\xmin}\\right)\\right].\n    \\label{eq:2TermPointSlope}\n\\end{equation}\n\\end{document}\n", "meta": {"hexsha": "f199af56c818ca6151f29da6c4364e9e26e987f4", "size": 15330, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/LinearSpace/LinearSpace.tex", "max_stars_repo_name": "jlconlin/PhDThesis", "max_stars_repo_head_hexsha": "8e704613721a800ce1c59576e94f40fa6f7cd986", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Notes/LinearSpace/LinearSpace.tex", "max_issues_repo_name": "jlconlin/PhDThesis", "max_issues_repo_head_hexsha": "8e704613721a800ce1c59576e94f40fa6f7cd986", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/LinearSpace/LinearSpace.tex", "max_forks_repo_name": "jlconlin/PhDThesis", "max_forks_repo_head_hexsha": "8e704613721a800ce1c59576e94f40fa6f7cd986", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.2075471698, "max_line_length": 803, "alphanum_fraction": 0.6488584475, "num_tokens": 5411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.703099175657292}}
{"text": "\\subsection{Step Response Characterisation}\n\nThe first step to calculating $T$, $r$, and $n$ is to  understand  how the order\n$n$ influences the shape of the transfer function's step response.\n\nIt is important to realise that no matter how a step response function is scaled\nor  offset  (defined  by the parameters $K_s$ for amplitude, $T$ for time scale,\n$x_0$ and $y_0$ for offset) the actual \\textit{shape}  always  remains the same.\nThus, only its shape tells us something about its complexity.\n\nTherein  lies  the  key. A method  needs  to  be  devised  for  determining  how\n``simple''  or  how ``complex'' a step response is -- independent of  scale  and\noffset -- before  it  is possible to start modelling and fitting a system to it.\n\nThis ``complexity'' is \\textbf{directly related}  to  the  required order $n$ of\nthe transfer function.\n\n\n\\subsubsection*{P. Hudzovic's Approach}\n\nP. Hudzovic proposed the following method (see figure \\ref{fig:tu_tg}):\n\n\\begin{itemize}\n    \\item\nFind  the  point  of  inflection of the step function. This  typically  involves\ncalculating the derivative and searching for a maximum.\n    \\item\nPlace a tangent  in  said  point and find the intersections with the minimum and\nmaximum horizontal lines.\n    \\item\nThe distance between the two intersections  is  referred  to  as  $T_g$, and the\ndistance between  the minimum intersection point and the beginning of the signal\nis referred to as $T_u$.\n\\end{itemize}\n\nThe ``complexity'' of the  step  response  is  defined by the ratio of $T_u$ and\n$T_g$ and is written as:\n\n\\begin{equation}\n    \\textrm{plant}_{Tu/Tg} = \\frac{T_u}{T_g}\n    \\label{eq:tu_tg}\n\\end{equation}\n\n\n\\subsubsection*{L. Sani's Approach}\n\nL.  Sani  proposed   a  different  method  (see  figure  \\ref{fig:t10_t50_t90}):\nDetermine the  times  $t_{10}$,  $t_{50}$ and $t_{90}$ required for reaching the\nvalues   at    \\SI{10}{\\percent},    \\SI{50}{\\percent}    and   \\SI{90}{percent}\nrespectively.\n\nThe   ``complexity''   of  the  step  response  is  defined  by  the  ratio   of\n$t_{90}-t_{10}$   and   $t_{50}$,   otherwise   referred   to   as    $\\lambda$:\n\n\\begin{equation}\n    \\textrm{plant}_{\\lambda} = \\frac{t_{90}-t_{10}}{t_{50}}\n    \\label{eq:t10_t50_t90}\n\\end{equation}\n\n\n\\subsubsection*{Short Visual Explanation}\n\nVisually, one can see how decreasing $T_g$ in figure \\ref{fig:tu_tg}  causes the\nstep  response  to become steeper (i.e. it becomes  more  ``complex''  and  thus\nrequires  a  higher  order  $n$)  and the value of $\\textrm{plant}_{T_u/T_g}$ in\nequation  \\ref{eq:tu_tg}  increases.   Similarly,   decreasing   the  difference\n$t_{90}-t_{10}$ in figure \\ref{fig:t10_t50_t90} also causes the step response to\nbecome  steeper  and causes the value of  $\\textrm{plant}_{\\lambda}$  increases.\n\nOn the other hand, one can  also see how increasing $T_u$ and $t_{50}$ increases\nthe delay  time  of  the  step  response,  which  similarly  leads  to  a higher\n``complexity'', and thus, a higher order $n$.\n\nHow $n$ is calculated will become clear in the next section.\n\n\\begin{figure}[t]\n    \\includegraphics[width=\\linewidth]{images/step_response_tu_tg}\n    \\caption{Method of P. Hudzovic, determine Tu and Tg}\n    \\label{fig:tu_tg}\n\\end{figure}\n\\begin{figure}[t]\n    \\includegraphics[width=\\linewidth]{images/step_response_t10_t50_t90}\n    \\caption{Method of L. Sani, determine t10, t50 and t90}\n    \\label{fig:t10_t50_t90}\n\\end{figure}\n\n", "meta": {"hexsha": "d9ecda4ca872c65932e1ee10d97bccf4c98b1505", "size": 3413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "versuche/mlab/sections/theory/characterisation_of_step_responses.tex", "max_stars_repo_name": "TheComet93/laborjournal", "max_stars_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "versuche/mlab/sections/theory/characterisation_of_step_responses.tex", "max_issues_repo_name": "TheComet93/laborjournal", "max_issues_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "versuche/mlab/sections/theory/characterisation_of_step_responses.tex", "max_forks_repo_name": "TheComet93/laborjournal", "max_forks_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.2298850575, "max_line_length": 80, "alphanum_fraction": 0.7122765895, "num_tokens": 1040, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.7030991692010511}}
{"text": "\n\\subsection{Slater's condition}\n\n\\subsubsection{Strong duality}\n\nStrong duality is where the duality gap is \\(0\\).\n\\subsubsection{Slater's condition}\n\nSlater's condition says that strong duality holds if there is an input where the inequality constraints are satisified strictly.\n\nThat is they are \\(g(x)<0\\), not \\(g(x)\\le 0\\)\n\nThis means that the conditions are slack.\n\nThis only applies if the problem is convex. That is, if Slater's condition holds, and the problem is convex, then strong duality holds.\n\n", "meta": {"hexsha": "5f9e6c1ff0bf419101f9dcda3e9877751ab0ef6f", "size": 510, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/optimisationMulti/06-01-slater.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/optimisationMulti/06-01-slater.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/optimisationMulti/06-01-slater.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0, "max_line_length": 135, "alphanum_fraction": 0.7647058824, "num_tokens": 124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7030405928514358}}
{"text": "\\subsection{Trigonometric polynomials}\\label{subsec:trigonometric_polynomials}\n\n\\begin{definition}\\label{def:ring_of_laurent_polynomials}\n  The ring of \\term{Laurent polynomials} in the indeterminates \\( \\mscrX \\) over the integral domain \\( D \\) is obtained from the \\hyperref[def:polynomial_algebra]{polynomial ring} \\( D[\\mscrX] \\) by \\hyperref[thm:adjoining_elements_to_field]{adjoining} to \\( D[\\mscrX] \\) the set\n  \\begin{equation*}\n    \\set*{ \\frac 1 X \\given* X \\in \\mscrX }\n  \\end{equation*}\n  of reciprocals of the indeterminates from the field of rational functions \\( D(\\mscrX) \\).\n\n  If \\( \\mscrX = \\set{ X_1, \\ldots, X_n } \\), this ring is denoted by \\( R[X_1^\\pm, \\ldots, X_n^\\pm] \\) or \\( R[X_1, X_1^{-1}, \\ldots, X_n, X_n^{-1}] \\). Individual polynomials are written as\n  \\begin{equation*}\n    p(X_1, \\ldots, X_n) = \\sum_{k_1=-\\infty}^\\infty \\cdots \\sum_{k_n=-\\infty}^\\infty a_{k_1, \\ldots, k_n} X^{k_1} \\cdots X_n^{k_n}.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}\\label{def:trigonometric_polynomial}\n  We define the \\term{trigonometric polynomials} over \\( \\BbbC \\) as the \\hyperref[def:ring_of_laurent_polynomials]{Laurent polynomials} \\( \\BbbC[e^{iz}] \\). A trigonometric polynomial \\( p \\in \\BbbC[e^{iz}] \\) can be written as\n  \\begin{equation}\\label{def:trigonometric_polynomial/exponential}\n    p(z) = \\sum_{k \\in \\BbbZ} c_k e^{ikz}\n  \\end{equation}\n  or, using \\hyperref[thm:exponential_trigonometric_identities/eulers_formula]{Euler's formula}, rewritten in the more conventional notation (see \\cite[1]{Боянов2008} or \\cite[88]{Rudin1987RealAndComplex}):\n  \\begin{equation}\\label{def:trigonometric_polynomial/trigonometric}\n    p(z) = a_0 + \\sum_{k=1}^\\infty [ a_k \\cos(kz) + b_k \\sin(kz) ],\n  \\end{equation}\n  where we denote \\( a_k \\coloneqq c_k \\) and \\( b_k \\coloneqq ic_k \\).\n\n  In particular, when using \\fullref{def:trigonometric_polynomial/trigonometric}, we may regard the coefficients \\( \\{ a_k \\}_{k=0}^\\infty \\) and \\( \\{ b_k \\}_{k=1}^\\infty \\) as either real or complex, which is a downside of \\fullref{def:trigonometric_polynomial/exponential}.\n\n  Denote by \\( \\tau_n(\\BbbK) \\) the vector space of all trigonometric polynomials of degree at most \\( n \\) with coefficients in \\( \\BbbK \\). We also introduce the subspaces \\( \\tau_n^\\alpha{\\BbbK} \\) of those polynomials which \\( a_0 = 0 \\).\n\\end{definition}\n", "meta": {"hexsha": "6c43473351bd09b28aa4c04de23c93501494a038", "size": 2357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/trigonometric_polynomials.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/trigonometric_polynomials.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/trigonometric_polynomials.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 76.0322580645, "max_line_length": 280, "alphanum_fraction": 0.7042851082, "num_tokens": 822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359876, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7030405907372161}}
{"text": "\\lab{Algorithms}{Moore-Penrose Pseudo-Inverse}{Moore-Penrose}\n\n\\objective{This section explains several methods for numerically computing the Moore-Penrose Pseudo-Inverse. It also compares performance of the different methods.}\n \nThe generalized inverse of a matrix $A$ is a matrix (which we will denote $A^\\dagger$ for now) that satisfies the following:\n\\begin{equation} \\label{cond:one}\nAA^\\dagger A = A \n\\end{equation}\n\n\\begin{equation} \\label{cond:two}\nA^\\dagger A A^\\dagger = A^\\dagger \n\\end{equation}\n\nFor any matrix $A$ there exists a generalized inverse. Note that in the case that $A$ is invertible, $A^{-1}$ satisfies the conditions \\ref{cond:one} and \\ref{cond:two}. However, it is not generally unique. For this reason, we usually add additional conditions that make the generalized inverse unique.\n\nFor example, we can specify the following two additional conditions:\n\n\\begin{equation} \\label{cond:three}\n(AA^\\dagger)^* = AA^\\dagger\n\\end{equation}\n\n\\begin{equation} \\label{cond:four}\n(A^\\dagger A)^* = A^\\dagger A\n\\end{equation}\n\nThese four conditions guarantee both the existence and uniqueness of the matrix $A^\\dagger$ for any matrix $A$. The matrix $A^\\dagger$ is known as the Moore-Penrose inverse. In some settings it is simply called the pseudo-inverse.\\footnote{For the rest of this section we will use the notation $A^\\dagger$ to represent the Moore-Penrose inverse, although in some books that notation is used a generalized inverse.}\n\n%{\\bf We could add some exposition here about examples of the MP inverse for specific matrices, but I don't know if Jeff is doing that in the book or not...}\n\n\\subsection{Calculating the Moore-Penrose Inverse}\n\nThere are several different methods for calculating the Moore-Penrose Inverse. We will consider the most general method first, and then compare its performance to a few specialized methods.\n\nRecall that the SVD of a matrix $A$ is of the form\n\n\\[\nA = U \\Sigma V^*\n\\]\n\nWhere $U$ and $V$ are unitary (i.e. $U^*U = I$) and $\\Sigma$ is diagonal. Consider the matrix\n\n\\[\nB = V \\Sigma^\\dagger U^*\n\\]\n\nWhere $\\Sigma^\\dagger$ is the pseudo-inverse of $\\Sigma$. Since $\\Sigma$ is diagonal, the pseudo-inverse is simply found by replacing each non-zero entry with its multiplicative inverse and transposing the matrix. We write, for ease of notation $\\Sigma^\\dagger \\Sigma = I_A$ Now we have the following:\n\n\\[\nABA = U \\Sigma V^* = A\n\\]\n\n\\[\nBAB = V \\Sigma^\\dagger U^* = B\n\\]\n\n\\[\n(AB)^* = U \\Sigma^{\\dagger *} V^* V \\Sigma^* U^* = U (\\Sigma \\Sigma^\\dagger)^* U^* = U \\Sigma \\Sigma^\\dagger U^* = U \\Sigma V^* V \\Sigma^\\dagger U^* = AB\n\\]\n\n\\[\n(BA)^* =  V \\Sigma^* U^* U \\Sigma^{\\dagger *} V^* = V (\\Sigma^\\dagger \\Sigma)^* V^* = V  \\Sigma^\\dagger \\Sigma V^* =  V \\Sigma^\\dagger U^* U \\Sigma V^* = BA\n\\]\n\nThus $B$ satisfies all of the properties of the pseudo-inverse, and since the pseudo-inverse is unique it is the only such matrix.\n\nTherefore, we can easily calculate the pseudo-inverse of a matrix using the SVD. Write the following code in Python:\n\n\\begin{lstlisting}[style=python]\nU,s,Vh = la.svd(A,full_matrices=False)\nS = sp.diag(s)\n\\end{lstlisting}\nWe can then calculate the pseudo-inverse by using the following line of code:\n\n\\begin{lstlisting}[style=python]\nApinv = sp.dot(sp.dot(Vh.T,sp.diag(1./s)),U.T)\n\\end{lstlisting}\n\nThis line uses the matrices that \\li{svd} created to calculate the pseudo-inverse, using the formula we established above. Note that we used \\li{diag} twice to invert just the singular values (and not the zeros). \n\\begin{problem}\nPython has the built-in functions \\li{la.pinv} and \\li{la.pinv2} to calculate the pseudo-inverse. Write a script that compares the performance of \\li{la.pinv},\\li{la.pinv2}, and the implementation that we demonstrated above. Use a matrix generated by  \\li{sp.rand}.\n Try the following matrix sizes:\n\\begin{itemize}\n\\item $1000 \\times 1$\n\\item $1000 \\times 20$\n\\item $1000 \\times 500$\n\\item $1000 \\times 1000$\n\\end{itemize}\nHow do the performances compare?\n\\end{problem}\n\n\\begin{problem}\n{\\bf Continuity of the pseudo-inverse:} This problem demonstrates why the pseudo-inverse is not generally a continous operation. Create a random $5 \\times 5$ matrix $A$, and find its SVD using the code:\n%should we use 'econ' here? I haven't read whatever section that comes from\n\\begin{lstlisting}[style=python]\nU,s,Vh = la.svd(A,full_matrices=False)\nV = Vh.T\nS = sp.diag(s)\n\\end{lstlisting}\nSet the bottom right entry of $S$ to zero, and then set $A = U*S*V'$. Now set $S(5,5)$ to be $.01$. Now calculate \\li{la.norm(A - sp.dot(sp.dot(U,S),Vh))}. The value should be $.01$. This is because the matrix $2$-norm is simply the value of the largest singular value. Now calculate \\li{la.norm(la.pinv(A) - la.pinv(sp.dot(sp.dot(U,S),Vh)))}. You should get $100$. Why is this? Hint: Think of how we calculated the pseudo-inverse. This example, and your explanation, should explain why two matrices, that are arbitrarily close together, can have pseudo-inverses that are arbitrarily far apart. Thus the pseudo-inverse is not a continuous operator.\n\\end{problem}\n\n\\subsection*{Other methods for calculating the Pseudo-Inverse}\n\nThe SVD is a powerful tool for calculating the pseudo-inverse. However, for large matrices it can be costly to calculate the SVD. Accordingly, there are several other methods for calculating the pseudo-inverse of a matrix.\n\nOne method is an iterative approach established by Ben-Israel and Cohen\\footnote{Ben-Israel, Adi; Cohen, Dan (1966). \"On Iterative Computation of Generalized Inverses and Associated Projections\". SIAM Journal on Numerical Analysis 3: 410–419.}. This method uses the recursive sequence\n\n\\[\nA_{i+1} = 2A_i - A_i A A_i\n\\]\n\nWith $A_0$ satisfying the equation $A_0 A = (A_0 A)^*$. The convergence of this sequence eventually becomes quadractic, which is a very desirable property. The simplest choice for $A_0$ is $\\alpha A^*$, with $0 < \\alpha < 2/\\sigma_1^2(A)$, where $\\sigma_1$ denotes the largest singular value (the condition on $\\alpha$ is a technical condition established in the original paper to guarantee fast convergence).\n\nOne tricky part of developing this method is finding an appropriate $\\alpha$. We don't want to waste much time calculating $\\sigma_1$. Luckily there is an easy equivalence that we can leverage:\n\n\\[\n||A||_2 = \\sigma_1(A) = \\sqrt{\\lambda_{max} (A^* A)}\n\\]\n%Python: no eigs function -- but it appears to be a topic of interest in the community, perhaps a future addition\nThus, we can calculate the largest singular value of $A$ quickly in some cases using. We stress that this is not always the fastest way. For example, if $A$ is a million by one column vector then calculating the 2-norm of $A$ is much faster than calculating the largest eigenvalue of a million by million matrix. However, with these equivalences we have some tools at our disposal to easily calculate the largest singular value of $A$.\n\nNow, using these tools, we can write a simple function to calculate the pseudo-inverse using this iterative method:\n\n\\begin{lstlisting}[style=python]\nfunction out = IterativePInv(A)\n\nalpha = 2/(1.1*eigs(A'*A,1));\nout = alpha*A';\nC = out + 1;\nwhile max(sum(abs(C-out))) > 1e-4\n    C = out;\n    out = 2*out - out*A*out;\nend\n\\end{lstlisting}\nAs you can see, the implementation of this algorithm is fairly straightforward. We used the matrix $1$-norm (the maximum absolute column sum) to detect convergence of our sequence, since it is very fast to compute.\n\n\\begin{problem}\nThe implementation we wrote above is naive in a few ways. Make the following three adaptations to your code:\n\\begin{itemize}\n\\item Allow variable tolerance in the detection of convergence of the sequence. Use \\li{*args} so that the user only specifies the tolerance if they want to.\n\\item We used the value $1.1$ rather arbitrarily in our selection of $\\alpha$. The original paper proves that the optimal value is $2/(\\sigma_1^2 + \\sigma_r^2)$, where $\\sigma_r$ is the smallest non-zero singular value. Use again to find the value of $\\sigma_r$, and use that value to set $\\alpha$.\n\\item If $A$ isn't close to square then it is not advantageous to use at all, as we explained above. Adapt the code to only use \\li{eigs} as you think it's appropriate. Remember that you can use the matrix $2$-norm and a constant like $1.1$ in cases where  isn't appropriate.\n\\end{itemize}\n\nNow test your code against the svd method, using the same cases that you did for that method. How does it perform?\n\\end{problem}\n\nIt should be noted that this method, although powerful, sometimes performs worse than the svd method. Specifically, when the matrix is ill-conditioned, it may take a long time for the sequence to enter the region of quadratic convergence, making this method a poor choice.\n\n\\subsection*{The QR method}\n\nThis final method, while only applicable in certain cases, offers a very fast method for calculating the pseudo-inverse. Suppose that $A$ has full column rank. We could show that the pseudo-inverse is then:\n\\[\nA^\\dagger = (A^* A)^{-1} A^*\n\\]\n\nDirect calculation of the pseudo-inverse using this formula is not very helpful, since matrix inversion is so costly. However, since $A$ is full rank, then $A^*A$ is positive definite, and thus has a cholesky decomposition. Therefore, we can rewrite this equation as:\n\n\\[\nR^*R A^\\dagger = A^*\n\\]\n\nwith $R$ being upper-triangular. This equation can be solved quickly by using forward and backward substitution.\n\nWe can speed calculation even further by noting that we don't even have to calculate $A^* A$, which can be costly (again, imagine the million by one vector). We can calculate R using the QR-decomposition of A:\n\n\\[\nA^* A = R^*Q^*QR = R^* R\n\\]\n\nThese equalities hold since $Q$ is orthogonal. Further, in the QR decomposition $R$ is upper-triangular, and thus we can calculate the cholesky factorization easily using the QR decomposition.\n\nCombining these facts we can write the following code to calculate the pseudo-inverse for a matrix that has full column rank as follows:\n\n\\begin{lstlisting}[style=python]\nR = la.qr(A)[1];\n\nAinv = la.lstsq(R,la.lstsq(R.T,A.T)[0])[0];\n\\end{lstlisting}\n\n\nThe first line performs QR decomposition for $R$. The second line conducts the backwards and forwards substitutions.\n\n\\begin{problem}\n%This Problem did not exactly work in Python, my function was slower when A was square when using la.lstsq\nCompare the run-time of this code against SciPy's \\li{la.pinv}, for the values used in the other problems. Also, make sure to use a non-square matrix for A, or for square matricies change the \\li{la.lstsq}'s to \\li{la.solve}'s to maximize performance.  How does it compare? It should be a lot faster. This demonstrates that by leveraging the correct information (full column rank) we can significantly improve the speed of this operation. Note that we can beat SciPy's own implementation significantly in this case.\n\n\\end{problem}\n\n\\begin{problem}\nThis method can also be adapted to use for matrices that have full row rank. In the case of full column rank the following formula holds:\n\\[\nA^\\dagger = A^*(A A^*)^{-1}\n\\]\nUse the same technique to write a function that finds the pseudo-inverse for a matrix of full row rank. Note that you will have to find the QR-decomposition of $A^*$ this time, and that it may be helpful to take the transpose so that you can use the backslash operator.\n\\end{problem}\n", "meta": {"hexsha": "edfa0037b9989b58b61278e96e1a19188a12d378", "size": 11353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/MoorePenrose/MP.tex", "max_stars_repo_name": "jasongrout/numerical_computing", "max_stars_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/MoorePenrose/MP.tex", "max_issues_repo_name": "jasongrout/numerical_computing", "max_issues_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/MoorePenrose/MP.tex", "max_forks_repo_name": "jasongrout/numerical_computing", "max_forks_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-21T23:06:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-21T23:06:27.000Z", "avg_line_length": 57.6294416244, "max_line_length": 648, "alphanum_fraction": 0.7454417335, "num_tokens": 2987, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8807970811069351, "lm_q1q2_score": 0.7030405840112083}}
{"text": "\n\\documentclass{homework}\n\\course{Math 5522H}\n\\author{Alex Li}\n\\input{preamble}\n\n\\begin{document}\n\\maketitle\n\n\\begin{inspiration}\nSome of the most important results (e.g. Cauchy's theorem) are so surprising at first sight that nothing short of a proof can make them credible.\n\\byline{Sir Harold Jeffreys} % and where is this quotation from?\n\\end{inspiration}\n\n\\section{Terminology}\n\n\\begin{problem}\n  What is a \\textbf{Jordan curve}?\n  \\end{problem}\n  \\begin{solution}\n  A Jordan curve is a simple closed piecewise smooth function $\\gamma:[a,b]\\mapsto \\C$.\n  \\end{solution}\n  \\begin{problem}\n    Define the \\textbf{winding number} $n(\\gamma,z)$ of a piecewise\n      smooth closed curve $\\gamma$ around a point $z \\in \\C$.\n      \\end{problem}\n      \\begin{solution}\n      It's the net number of times you spin around clockwise, or\n      \\[n(\\gamma, z) = \\frac{1}{2\\pi i}\\int_\\gamma \\frac{1}{x-z}dx \\]\n\n      \\end{solution}\n      \\section{Numericals}\n\n      \\begin{problem}\\label{Fresnel integral}\n      Compute the \\textbf{Fresnel integrals}\n        \\[\n            \\int_0^\\infty \\sin \\left( x^2 \\right) \\, dx \\mbox{ and } \\int_0^\\infty \\cos \\left( x^2 \\right) \\, dx.\n              \\]\n              \\end{problem}\n              We can do them both at once, let $f(x) = \\cos(x^2) + i\\sin(x^2)$. Then the real part of $\\int_0^\\infty f(x)dx$ is the value of the cosine integral, and the imaginary part is the value of the sin integral. Noting that $f(x) = e^{ix^2}$, we itegrate around the eighth circle of radius $R$, $\\gamma$ in figure \\ref{octant-tikz}. \n\n              \\begin{figure}[h]\n              \\begin{tikzpicture}\n              \\draw [<->] (-4, 0) -- (4, 0);\n              \\draw [<->] (0, -4) -- (0, 4);\n              \\node [below] at (4.24, 0) {$R$};\n              \\node [right] at (3, 3) {$\\theta=\\pi/4$};\n              \\begin{scope}[very thick,decoration={\n                  markings,\n                      mark=at position 0.5 with {\\arrow{>}}}\n                          ] \n                          \\draw[postaction={decorate}] (0,0) -- (4.24, 0);\n                          \\draw[postaction={decorate}] (3,3) -- (0,0);\n                          \\draw[postaction={decorate}] (4.24, 0) arc [radius=4.24, start angle=0, end angle=45];\n                          \\end{scope}\n                          \\end{tikzpicture}\n                          \\caption{The curve $\\gamma$ for \\ref{Fresnel integral}}\n                          \\label{octant-tikz}\n                          \\end{figure}\n                          \\begin{align*}\n                          \\int_\\gamma e^{iz^2}\n                          &= \\int_0^R e^{iz^2}dz + \\int_0^{\\frac{\\pi}{4}} (ie^{i\\theta}) e^{i(Re^{i\\theta})^2} d\\theta + \\int_0^R e^{5\\pi/4}e^{i(ze^{i\\pi/4})^2)}dz \\\\\n                          &= \\int_0^R e^{iz^2}dz + \\int_0^{\\frac{\\pi}{4}} ie^{iR^2\\cos(2\\theta) - R^2\\sin(2\\theta) + i\\theta} d\\theta - e^{\\pi/4} \\int_0^R e^{-z^2}dz\n                          \\end{align*}\n                          Letting $R$ go to infinity, the middle term vanishes since the real part of the exponent $R^2\\sin(2\\theta) + \\cos(\\theta)$ goes to $-\\infty$. The last term becomes the classic statistics integral with value $\\frac{\\sqrt{\\pi}}{2}$. Since $\\int_\\gamma f(x)$ is the integral of a holomorphic function around a closed curve, by cauchy's theorem it's value is 0 so we can deduce that \n                          \\[\\int_0^\\infty e^{iz^2}dz = e^{\\pi/4} \\int_0^R e^{-z^2}dz =  \\frac{1+i}{\\sqrt{2}}\\frac{\\sqrt{\\pi}}{2} = \\frac{\\sqrt{\\pi}}{\\sqrt{8}} + \\frac{i\\sqrt{\\pi}}{\\sqrt{8}}\\]\n                          so \n                            \\[\n                                \\int_0^\\infty \\sin \\left( x^2 \\right) \\, dx = \\int_0^\\infty \\cos \\left( x^2 \\right) \\, dx = \\frac{\\sqrt{\\pi}}{\\sqrt{8}}\n                                  \\]\n                                  \\begin{problem}\n                                    For an integrable function $f : \\R \\to \\C$, define the\n                                      \\textbf{Fourier transform} of $f$, denoted $\\hat{f}$, by\n                                        \\[\n                                            {\\hat {f}}(\\xi ) := \\int _{-\\infty }^{\\infty} f(x) \\, e^{-2\\pi ix \\xi} \\,dx.\n                                              \\]\n                                                Find the Fourier transform of $f(x) = e^{-\\pi x^2}$.\n                                                \\end{problem}\n                                                \\begin{solution}\n                                                We solve this by completing the square in the exponent:\n                                                \\begin{align}\\label{completed_square_fourier}\n                                                -\\pi x^2 - 2\\pi ix\\xi = -\\pi(x-i\\xi)^2 - \\pi \\xi^2\n                                                \\end{align}\n                                                We want to do something like below,\n                                                \\begin{align*}\n                                                {\\hat {f}}(\\xi ) &=  \\int _{-\\infty }^{\\infty} e^{-\\pi x^2 -2\\pi ix \\xi} \\,dx\\\\\n                                                &=  e^{-\\xi^2\\pi}\\int _{-\\infty }^{\\infty} e^{-\\pi (x-i\\xi)^2} \\,dx\\quad \\color{purple} \\text{ By Eq. \\ref{completed_square_fourier}}\n                                                \\end{align*}\n                                                This integral can almost be evaluated with a $u$ subsitution of \n                                                \\[u = x-i\\xi.\\]\n                                                However, the bounds of integration will be messed up and we will be going over the complex numbers. So let's consider the closed rectangular contour that goes on a straight line between the four points below.\n                                                \\[R \\mapsto R - i\\zeta \\mapsto - R - i\\zeta \\mapsto -R\\]\n                                                As $R\\to\\infty$, the sides of this rectangle with nonzero imaginary derivative will disappear as\n                                                \\[\n                                                \\abs{\\int_{-\\zeta}^{0} e^{-\\pi((\\pm R+ix) -i\\zeta)^2} dx} \\leq \\abs{\\zeta} \\abs{e^{-\\pi R}}\\to 0.\n                                                \\]\n                                                Thus the integral of the bottom of the rectangle is equal to the integral going backwards along the top of the rectangle, which we can compute\n                                                \\begin{align*}\n                                                \\hat f(\\zeta) &=  e^{-\\xi^2\\pi}\\int_{-\\infty}^\\infty e^{-\\pi x^2} \\,dx\\\\\n                                                &=  \\frac{e^{-\\xi^2\\pi}}{\\sqrt{\\pi}}\\int_{-\\infty}^\\infty e^{-x^2} \\,dx\\quad \\color{purple} u = \\sqrt{\\pi}x, du = \\sqrt{\\pi} dx\\\\\n                                                &=  \\frac{e^{-\\xi^2\\pi}}{\\sqrt{\\pi}} \\sqrt{\\pi} =  e^{-\\xi^2\\pi}\n                                                \\end{align*}\n\n                                                \\end{solution}\n                                                \\section{Exploration}\n\n                                                \\begin{problem}\\label{conjz_no_primitive}\n                                                  Does the function $f : \\C \\to \\C$ given by $f(z) = \\conj{z}$ have a\n                                                    primitive?\n                                                    \\end{problem}\n                                                    \\begin{solution}\n                                                    Let $F$ be a primitive for $f$ and $\\gamma: [0,1]\\mapsto \\C$ with $\\gamma(t)=e^{it2\\pi}$ be a closed curve.\n                                                    Then\n                                                    \\begin{align*}\n                                                        0 = F(\\gamma(2\\pi)) - F(\\gamma(0)) = \\int_\\gamma \\conj{z} = \\int_\\gamma \\frac{1}{z} = 2\\pi i,\n                                                        \\end{align*}\n                                                        a contradiction.\n                                                        \\end{solution}\n                                                        \\begin{problem}\n                                                          We proved Goursat's theorem for rectangles.  Without simply\n                                                            recapitalulating the proof (e.g., your argument should not again\n                                                              invoke \\ref{nested-subsets-convergence}), deduce a theorem for\n                                                                \\textit{triangles} from our result about rectangles.\n                                                                \\end{problem}\n                                                                \\begin{solution}\n                                                                We will prove the following:\n                                                                \\begin{theorem}\\label{triangle-theorem}\n                                                                Let $\\gamma_{\\Delta}$ be a curve around some triangle be a triangle contained in an open set $S$, and $f:S\\mapsto \\C$ be holomorphic. Then\n                                                                \\[\\int_{\\gamma_{\\Delta}} f = 0\\]\n                                                                In fact, this generalizes to any polygon with no holes in it whose interior is contained in $S$ (by gluing positively oriented triangles together to make that polygon and cancelling).\n                                                                \\end{theorem}\n                                                                Choose some side of the triangle as well as a small $\\delta$. Now, draw a rectangle parallel to that side of height $\\delta$ as wide as possible, and then draw a rectangle on that and so on until you can't anymore. (See Figure \\ref{curve-triangle-rectangles}). \n                                                                \\begin{figure}[h]\n                                                                \\begin{tikzpicture}\n                                                                \\begin{scope}[very thick,decoration={\n                                                                    markings,\n                                                                        mark=at position 0.2 with {\\arrow{>}},\n                                                                            mark=at position 0.5 with {\\arrow{>}},\n                                                                                mark=at position 0.8 with {\\arrow{>}}}\n                                                                                    ] \n                                                                                    \\draw[postaction={decorate}] (0,0) -- (4, 0) -- (8, 4) -- (0,0);\n                                                                                    \\end{scope}\n                                                                                    \\begin{scope}[decoration={\n                                                                                        markings,\n                                                                                            mark=at position 0.2 with {\\arrow{>}}}\n                                                                                                ]\n                                                                                                \\draw[postaction={decorate}] (1, 0) -- (1, .5) -- (4, .5) -- (4, 0) -- (1, 0);\n                                                                                                \\draw[postaction={decorate}] (2, .5) -- (2, 1) -- (4.5, 1) -- (4.5, .5) -- (2, .5);\n                                                                                                \\draw[postaction={decorate}] (3, 1) -- (3, 1.5) -- (5, 1.5) -- (5, 1) -- (3, 1);\n                                                                                                \\draw[postaction={decorate}] (4, 1.5) -- (4, 2) -- (5.5, 2) -- (5.5, 1.5) -- (4, 1.5);\n                                                                                                \\draw[postaction={decorate}] (5, 2) -- (5, 2.5) -- (6, 2.5) -- (6, 2) -- (5, 2);\n                                                                                                \\draw[postaction={decorate}] (6, 2.5) -- (6, 3) -- (6.5, 3) -- (6.5, 2.5) -- (6, 2.5);\n                                                                                                \\end{scope}\n                                                                                                \\end{tikzpicture}\n                                                                                                \\caption{Cutting a triangle into small rectangles}\n                                                                                                \\label{curve-triangle-rectangles}\n                                                                                                \\end{figure}\n                                                                                                Since each of the rectangles have a value of 0, the integral around the triangle is equal to the sum of the integrals around the smaller triangles between the thin rectangles and the big triangle.\n\n                                                                                                Now, because $f$ is continous on the compact set that is the interior of $\\gamma_{\\Delta}$ it is uniformly continuous, so we can choose $\\delta$ such that the value of $f$ varies by less than $\\epsilon$ at any two points on the same small cut up piece. As the pieces get smaller, the top strangely shaped piece will have a very small arc length and so the value of the integral around it goes to 0, so we can ignore it. Next we can bound the integral around any other triangle $\\gamma_{i}$. If $f$ is a constant, then the integral around the triangle is 0, so\n                                                                                                \\[\\abs{\\int_{\\gamma_i} f dz} = \\abs{\\int_{\\gamma_i} f dz- \\inf_{\\gamma_i}(f)} \\leq |\\gamma_i|\\epsilon\\].\n\n                                                                                                Now, any given small triangle has it's longest side as part of the contour $\\gamma_{\\Delta}$, so the sum of the perimeters of all of the triangles is bounded above by $3\\abs{\\gamma_{\\Delta}}$. Thus we can bound the integral around $\\gamma_\\Delta$ by choosing $\\delta$ so as to make $\\epsilon$ tiny:\n                                                                                                \\[\\abs{\\int_{\\gamma_\\Delta} f}\\leq 3\\abs{\\gamma_{\\Delta}}\\epsilon\\to 0\\]\n                                                                                                \\end{solution}\n\n                                                                                                \\begin{problem}\n                                                                                                  Suppose $f, g : \\C \\to \\C$ are holomorphic and agree on the unit\n                                                                                                    circle.  How do $f$ and $g$ relate?  Morally, this problem is\n                                                                                                      related to \\ref{identity-theorem}.\n                                                                                                      \\end{problem}\n                                                                                                      \\begin{solution}\n                                                                                                      Let's consider $f-g$, it's holomorphic and equal to 0 on the unit circle. Call the positively oriented curve going around the unit circle $\\gamma$. By Cauchy's Integral formula, \n                                                                                                      \\[(f-g)(z) = \\frac{1}{2\\pi i}\\int_{\\gamma}\\frac{(f-g)(w)}{z-w}dw\\]\n                                                                                                      And this is $0$ since the numerator is $0$.\n                                                                                                      \\end{solution}\n\n                                                                                                       \\begin{problem}\n                                                                                                          Suppose $f : \\C \\to \\C$ is holomorphic, and consider the circle\n                                                                                                             $\\gamma$ with center $z_0$.  How does the real part of the average\n                                                                                                                value of $f$ on the circle $\\gamma$ relate to $f(z_0)$?\n                                                                                                                 \\end{problem}\n                                                                                                                 \\begin{solution}\n                                                                                                                 By Cauchy's integral formula, \n                                                                                                                 \\begin{align*}\n                                                                                                                 f(z_0) &= \\frac{1}{2\\pi i}\\int_{\\gamma} \\frac{f(z)}{z_0 - z}dz\\\\\n                                                                                                                 &= \\frac{1}{2\\pi i}\\int_{0}^{2\\pi} \\frac{f(z_0 + e^{it})}{e^{it}}ie^{it} dz\\\\\n                                                                                                                 &= \\frac{1}{2\\pi}\\int_{0}^{2\\pi} f(z_0 + e^{it}) dz\n                                                                                                                 \\end{align*}\n                                                                                                                 And this last expression is the average value of $f$ on the circle $\\gamma$, so $f(z_0)$ is is equal to average value of $f$ on the circle $\\gamma$.\n\n                                                                                                                 \\end{solution}\n                                                                                                                  \\begin{problem}\n                                                                                                                     Recalling \\ref{harmonic-conjugate}, suppose $u, v : \\C \\to \\R$ are\n                                                                                                                        harmonic functions and $f = u + iv$ is holomorphic, so $u$ and $v$\n                                                                                                                           are harmonic conjugates.  Find the \\textbf{Poisson kernel} for the\n                                                                                                                              unit disc, i.e., find a function $P_r(\\theta)$ so that\n                                                                                                                                 \\[\n                                                                                                                                      u(re^{i\\theta}) = \\frac {1}{2\\pi} \\int_{-\\pi }^{\\pi } P_{r}(\\theta -t) \\, u(e^{it}) \\, dt\n                                                                                                                                         \\]\n                                                                                                                                            for $r < 1$.\n                                                                                                                                             \\end{problem}\n                                                                                                                                             \\begin{solution}\n                                                                                                                                             We can recover the value at $re^{i\\theta}$ by an integral of $u$ over the unit circle using Cauchy's integral formula\n                                                                                                                                             \\begin{align*}\n                                                                                                                                             u(re^{i\\theta}) &= \\frac{1}{2\\pi i}\\int_{\\gamma} \\frac{u(e^{it})}{re^{i\\theta} - e^{it}}\\\\\n                                                                                                                                             &= \\frac{1}{2\\pi i}\\int_{-\\pi}^{\\pi} \\frac{u(e^{it})ie^{it}}{re^{i\\theta} - e^{it}}\\\\\n                                                                                                                                             &= \\frac{1}{2\\pi}\\int_{-\\pi}^{\\pi} \\frac{u(e^{it})}{re^{i(\\theta - t)} - 1}\\\\\n                                                                                                                                             \\end{align*}\n                                                                                                                                             Thus \n                                                                                                                                             \\[P_r(\\theta) = \\frac{1}{re^{i\\theta} - 1}\\]\n                                                                                                                                             is the Poisson kernel.\n\n                                                                                                                                             \\end{solution}\n                                                                                                                                             \\section{Prove or Disprove and Salvage if Possible}\n\n                                                                                                                                             \\begin{problem}\n                                                                                                                                               Suppose $D = \\{ z \\in \\C : \\abs{z} < 1 \\}$ and $f : D \\to \\C$ is\n                                                                                                                                                 continuous and $\\gamma : [a,b] \\to D$ is a piecewise smooth curve.\n                                                                                                                                                   Then $\\displaystyle\\int_\\gamma f\\, dz = 0$.\n                                                                                                                                                   \\end{problem}\n                                                                                                                                                    \\begin{solution}\n                                                                                                                                                     No, let $f(x)=1$ and $\\gamma$ be any non-closed curve. Even if it's closed, if $f$ is not holomorphic, then going around a rectangle may be a problem (for example consider the computation in \\ref{conjz_no_primitive}). So we really want to suppose that $\\gamma$ is closed and $f$ is holomorphic. We will prove the following.\n                                                                                                                                                     \\begin{theorem}\\label{general-curve-theorem}\n                                                                                                                                                     Let $\\gamma$ be a piecewise smooth curve in an open set $S$, and $f:S\\mapsto \\C$ be holomorphic. If the interior of $\\gamma$ is contained in $S$, then \\[\\int_{\\gamma} fdz = 0\\].\n                                                                                                                                                     \\end{theorem}\n                                                                                                                                                     Theorem \\ref{triangle-theorem} tells use this is true if $\\gamma$ is the curve of a polygon. Since $\\gamma$ is smooth, it is rectifiable, so we can draw a polygonal path $\\gamma(t_0), \\gamma(t_1), \\dots, \\gamma(t_{n-1}), \\gamma(t_n)$ with $\\gamma(t_n)=\\gamma(t_0)$ that approximates $\\gamma$. Since $S$ is open we can ensure this path in contained inside of it. By rectifiablity, we can choose the path such that for any $\\delta > 0$,\n                                                                                                                                                     \\[\\sum_{i=0}^{n-1}\\abs{\\gamma(t_i) - \\gamma(t_{i+1})} - \\int_{t_i}^{t_{i+1}} f(\\gamma(t)) dt \\leq \\delta \\]\n                                                                                                                                                     Let $\\gamma_{i}'$ be the integral on the line directly from $t_i$ to $t_{i+1}$ and then back from $t_{i+1}$ to $t_{i}$ along the curve $\\gamma$. We can choose $t_i$ to be close enough to each other that any two points on $\\gamma_{i}'$ are at most $\\delta$ away from each other, and since the polygon is compact and $f$ is continuous, for any $\\epsilon > 0$ we can choose $\\delta$ such that \n                                                                                                                                                     \\[x - y < \\delta \\implies f(x) - f(y) < \\epsilon\\].\n\n                                                                                                                                                     Now, since the line integral of interior of the polygon is 0 by Theorem \\ref{triangle-theorem}, the value of the line integral around $\\gamma$ is bounded by the sum of the integrals of the segments between the approximating polygon and the curve. Then\n                                                                                                                                                     \\begin{align*}\n                                                                                                                                                     \\abs{\\int_{\\gamma} fdz} &\\leq \\sum_{i=0}^{n-1}\\abs{\\int_{\\gamma_{i}'} f dt}\\\\\n                                                                                                                                                     &= \\sum_{i=0}^{n-1}\\abs{\\int_{\\gamma_{i}'} f - \\inf_{\\gamma_{i}'}f dt}\\color{purple}\\text{ closed line integral of constant is 0}\\\\\n                                                                                                                                                     &\\leq \\sum_{i=0}^{n-1}\\abs{\\gamma_{i}'}(\\sup_{\\gamma_{i}'}f - \\inf_{\\gamma_{i}'}f)  dt\\\\\n                                                                                                                                                     &\\leq \\sum_{i=0}^{n-1}\\abs{\\gamma_{i}'}\\epsilon dt\\\\\n                                                                                                                                                     &\\leq \\epsilon((2\\int_{\\gamma(t)}dt +\\delta)\\to 0\n                                                                                                                                                     \\end{align*}    \n                                                                                                                                                     Thus the line integral around $\\gamma$ is 0.\n                                                                                                                                                      \\end{solution} \n                                                                                                                                                       \n                                                                                                                                                       \\begin{problem}\n                                                                                                                                                         Suppose $U$ is an open set and $f : U \\to \\C$ is analytic and\n                                                                                                                                                           $\\gamma : [a,b] \\to U$ is a piecewise smooth curve.  Then\n                                                                                                                                                             $\\displaystyle\\int_\\gamma f \\, dz = 0$.\n                                                                                                                                                             \\end{problem}\n                                                                                                                                                             \\begin{solution}\n                                                                                                                                                             False- again, $\\gamma$ must be closed, and the interior of $\\gamma$ should be contained in $U$. In this case we can apply \\ref{general-curve-theorem}.\n                                                                                                                                                             Otherwise a counter-example can be given by noting that $1/z$ is defined on the open set $\\C/\\{0\\}$. For $\\gamma$ the unit circle, $\\int_\\gamma 1/z=2\\pi i\\neq 0$.\n                                                                                                                                                             \\end{solution}\n\n\n                                                                                                                                                             \\begin{problem}\n                                                                                                                                                               Define $\\gamma_r : [0,2\\pi] \\to \\C$ by\n                                                                                                                                                                 $\\gamma_r(\\theta) = r e^{i \\theta}$, and for real numbers\n                                                                                                                                                                   $R > r > 0$, define the annulus\n                                                                                                                                                                     \\[\n                                                                                                                                                                         A(r,R) := \\{ z \\in \\C : r < |z| < R \\}\n                                                                                                                                                                           \\]\n                                                                                                                                                                             and suppose $f : A(r/2,2R) \\to \\C$ is holomorphic.  Then\n                                                                                                                                                                               \\[\n                                                                                                                                                                                   \\int_{\\gamma_r} f \\, dz = \\int_{\\gamma_R} f \\, dz.\n                                                                                                                                                                                     \\]\n                                                                                                                                                                                     \\end{problem}\n                                                                                                                                                                                     \\begin{solution}\n                                                                                                                                                                                     True. Consider integrating along the 2 curves in Fig. \\ref{annulus-curve}. The two curves are closed and can be compressed to a point along the holomorphic region, so the integral along them both is 0. The two horizontal lines will cancel out, so we have the claim.\n                                                                                                                                                                                     \\begin{figure}[h]\n                                                                                                                                                                                     \\begin{tikzpicture}\n                                                                                                                                                                                     \\begin{scope}[very thick,decoration={\n                                                                                                                                                                                         markings,\n                                                                                                                                                                                             mark=at position 0.3 with {\\arrow{>}}}\n                                                                                                                                                                                                 ] \n                                                                                                                                                                                                 \\draw[postaction={decorate}] (-1, 0) arc [radius=1, start angle=180, end angle=0];\n                                                                                                                                                                                                 \\draw[postaction={decorate}] (2, 0) arc [radius=2, start angle=0, end angle=180];\n                                                                                                                                                                                                 \\draw[postaction={decorate}] (-2, 0) arc [radius=2, start angle=180, end angle=360];\n                                                                                                                                                                                                 \\draw[postaction={decorate}] (1, 0) arc [radius=1, start angle=360, end angle=180];\n                                                                                                                                                                                                 \\draw[postaction={decorate}] (1,0) -- (2,0);\n                                                                                                                                                                                                 \\draw[postaction={decorate}] (2,0) -- (1,0);\n                                                                                                                                                                                                 \\draw[postaction={decorate}] (-1,0) -- (-2,0);\n                                                                                                                                                                                                 \\draw[postaction={decorate}] (-2,0) -- (-1,0);\n                                                                                                                                                                                                 \\end{scope}\n                                                                                                                                                                                                 \\end{tikzpicture}\n                                                                                                                                                                                                 \\caption{Annulus Curves, one is on the top half and the other is on the bottom half.}\n                                                                                                                                                                                                 \\label{annulus-curve}\n                                                                                                                                                                                                 \\end{figure}\n                                                                                                                                                                                                 \\end{solution}\n                                                                                                                                                                                                 \\pagebreak\n                                                                                                                                                                                                 \\begin{problem}\\label{cauchy-integral-formula}\n                                                                                                                                                                                                 Define $B_R(0) := \\{ z \\in C : \\abs{z} < R \\}$ and suppose\n                                                                                                                                                                                                   $f : B_R(0) \\to \\C$ is holomorphic and let $\\gamma$ be the\n                                                                                                                                                                                                     positively-oriented circle of positive radius $r < R$.  Then\n                                                                                                                                                                                                       \\[\n                                                                                                                                                                                                           f(a) = \\int_\\gamma \\frac{f(z)}{z-a} \\, dz.\n                                                                                                                                                                                                             \\]\n                                                                                                                                                                                                               and moreover\n                                                                                                                                                                                                                 \\[\n                                                                                                                                                                                                                     f'(a) = \\int_\\gamma \\frac{f(z)}{(z-a)^2} \\, dz.\n                                                                                                                                                                                                                       \\]  \n                                                                                                                                                                                                                       \\end{problem}\n                                                                                                                                                                                                                       \\begin{solution}\n                                                                                                                                                                                                                       This is true up to a factor of $2\\pi i$ for any $a$ in the interior of $\\gamma$. For the first claim,\n                                                                                                                                                                                                                       \\begin{align*}\n                                                                                                                                                                                                                       \\int_\\gamma \\frac{f(z)}{z-a}dz &= \\int_\\gamma \\frac{f(z) - f(a)}{z-a}dz + f(a)\\int_\\gamma \\frac{1}{z-a}dz\n                                                                                                                                                                                                                       \\end{align*}\n                                                                                                                                                                                                                       The rightmost integral is the integral of $\\frac{1}{z}$ around a circle containing the origin shifted by $a$, so it is $2\\pi i$.\n                                                                                                                                                                                                                       \\begin{align}\n                                                                                                                                                                                                                       \\label{cauchys-integral-formula-really}\n                                                                                                                                                                                                                       \\int_\\gamma \\frac{f(z)}{z-a}dz &= \\int_\\gamma \\frac{f(z) - f(a)}{z-a}dz + f(a)2\\pi i\n                                                                                                                                                                                                                       \\end{align}\n                                                                                                                                                                                                                       Now, we can draw a super small circle of radius $\\delta$ around $a$ contained in $B_R(0)$. Splitting this circle up into 2 curves in the spirit of the image \\ref{annulus-curve}, and noting that the two curves have line integral 0, we see that the integral around $B_R(0)$ is equivalent to the integral around the small circle centered at $a$. Letting $\\delta$ go to 0, \n                                                                                                                                                                                                                       \\begin{align*}\n                                                                                                                                                                                                                       \\lim_{\\delta\\to 0} \\int_{\\gamma_{\\delta}} \\frac{f(z)-f(a)}{z-a} dz &= \\lim_{\\delta\\to 0} \\int_{\\gamma_{\\delta}} \\frac{f(a+h)-f(a)}{h} dz \\color{purple}\\quad |h| = \\delta\\\\\n                                                                                                                                                                                                                       &\\leq \\frac{|2\\gamma_{\\delta}|}{\\delta}\\sup{f(a+h) - f(a)}\\\\\n                                                                                                                                                                                                                       &\\leq \\frac{2\\pi\\delta}{\\delta}\\epsilon \\leq 0 \n                                                                                                                                                                                                                       \\end{align*}\n                                                                                                                                                                                                                       Here we can use the continuity of $f$ to ensure that we can choose a $\\delta$ such that $a+h - a<\\delta \\implies f(a+h) - f(a) < \\epsilon$. Thus by Eq. \\ref{cauchys-integral-formula-really}\n                                                                                                                                                                                                                       \\begin{align}\\label{cauchys-integral-formula-clean}\n                                                                                                                                                                                                                       \\frac{1}{2\\pi i}\\int_\\gamma \\frac{f(z)}{z-a}dz &= f(a)\n                                                                                                                                                                                                                       \\end{align}\n                                                                                                                                                                                                                       For the second equation, let's take the derivative of both sides with respect to $a$ with the quotient rule\n                                                                                                                                                                                                                       \\begin{align}\\label{cauchys-integral-formula-clean-d}\n                                                                                                                                                                                                                       \\frac{1}{2\\pi i}\\int_\\gamma \\frac{f(z)}{(z-a)^2}dz &= f'(a)\n                                                                                                                                                                                                                       \\end{align}\n                                                                                                                                                                                                                       \\end{solution}\n\n                                                                                                                                                                                                                       \\begin{problem}\\label{cauchy-inequalities}If $f : U \\to \\C$ is\n                                                                                                                                                                                                                         holomorphic and $U \\supset B_r(z_0)$, then\n                                                                                                                                                                                                                           \\[\n                                                                                                                                                                                                                                \\abs{f(z_0)} \\leq \\sup_{z \\in \\partial B_r(z_0)} \\abs{f(z)}\n                                                                                                                                                                                                                                   \\]\n                                                                                                                                                                                                                                      and\n                                                                                                                                                                                                                                         \\[\n                                                                                                                                                                                                                                              \\abs{f'(z_0)} \\leq \\sup_{z \\in \\partial B_r(z_0)} \\abs{f(z)}. % missing (1/r) factor\n                                                                                                                                                                                                                                                 \\]\n                                                                                                                                                                                                                                                  \\end{problem}\n                                                                                                                                                                                                                                                   \\begin{solution}\n                                                                                                                                                                                                                                                   WLOG let $z_0=0.$ By Eq. \\ref{cauchys-integral-formula-clean},\n                                                                                                                                                                                                                                                   \\begin{align*}\n                                                                                                                                                                                                                                                   f(0) &= \\frac{1}{2\\pi i}\\int_0^{2\\pi} \\frac{f(re^{it})ire^{it}}{re^{it}}dt\\\\\n                                                                                                                                                                                                                                                   &= \\frac{1}{2\\pi}\\int_0^{2\\pi} f(re^{it}) dt\n                                                                                                                                                                                                                                                   \\end{align*}\n                                                                                                                                                                                                                                                   So $f(0)$ is the average value on the boundary, and thus $\\abs{f(z_0)} \\leq \\displaystyle\\sup_{z \\in \\partial B_r(z_0)} |f(z)|$.\n                                                                                                                                                                                                                                                   By Eq. \\ref{cauchys-integral-formula-clean-d},\n                                                                                                                                                                                                                                                   \\begin{align*}\n                                                                                                                                                                                                                                                   \\abs{f'(0)} &= \\abs{\\frac{1}{2\\pi i}\\int_0^{2\\pi} \\frac{f(re^{it})ire^{it}}{(re^{it})^2}dt}\\\\\n                                                                                                                                                                                                                                                   &\\leq \\frac{1}{2\\pi r}\\int_0^{2\\pi} \\frac{\\abs{f(re^{it})}}{\\abs{e^{it}}} dt\\\\\n                                                                                                                                                                                                                                                   &\\leq \\frac{1}{r}\\left(\\frac{1}{2\\pi}\\int_0^{2\\pi} \\abs{f(re^{it})} dt\\right)\n                                                                                                                                                                                                                                                   \\end{align*}\n                                                                                                                                                                                                                                                   Thus \n                                                                                                                                                                                                                                                   \\begin{align}\\label{derivative-dies-holomorphic}\n                                                                                                                                                                                                                                                   \\abs{f'(z_0)} \\leq \\frac{1}{r}\\displaystyle\\sup_{z \\in \\partial B_r(z_0)} |f(z)|\n                                                                                                                                                                                                                                                   \\end{align}\n                                                                                                                                                                                                                                                    \\end{solution}\n\n                                                                                                                                                                                                                                                    \\begin{problem}\\label{liouville-theorem}Recall that a function $f : U \\to \\C$ is\n                                                                                                                                                                                                                                                      \\textbf{bounded} if there exists $M > 0$ so that for all $z \\in U$\n                                                                                                                                                                                                                                                        we have $\\abs{f(z)} \\leq M$.  A bounded holomorphic function\n                                                                                                                                                                                                                                                          $f : U \\to \\C$ is constant.\n                                                                                                                                                                                                                                                          \\end{problem}\n                                                                                                                                                                                                                                                          \\begin{solution}\n                                                                                                                                                                                                                                                          False, consider $f:B_1(0)\\mapsto \\C, f(z) = z$. This is bounded, since $\\abs{f(z)}\\leq 1$. But it's clearly not constant. However, we can prove it if we take $U=\\C$.\n\n                                                                                                                                                                                                                                                          Choose a point $z_0$, and construct a ball of a massive radius $r$ around it. Then by \\ref{derivative-dies-holomorphic}, \n                                                                                                                                                                                                                                                          \\[\\abs{f'(z_0)} \\leq \\frac{1}{r}\\sup_{z \\in \\partial B_r(z_0)} \\abs{f(z)} \\leq rM \\to 0\\]\n                                                                                                                                                                                                                                                          Thus the derivative of $f$ is 0 everywhere, so $f$ is constant.\n                                                                                                                                                                                                                                                          \\end{solution}\n                                                                                                                                                                                                                                                          \\begin{problem}\n                                                                                                                                                                                                                                                            For every polynomial $p \\in \\C[z]$ there is $z \\in \\C$ so that $p(z) = 0$.\n                                                                                                                                                                                                                                                            \\end{problem}\n                                                                                                                                                                                                                                                            \\begin{proof}\n                                                                                                                                                                                                                                                            False. Consider the polynomial $p(z)=1$. Instead we prove the following:\n                                                                                                                                                                                                                                                            \\begin{theorem}\n                                                                                                                                                                                                                                                            If a polynomial $p \\in \\C[z]$ has no zeros, it is constant.\n                                                                                                                                                                                                                                                            \\end{theorem}\n                                                                                                                                                                                                                                                            \\[\n                                                                                                                                                                                                                                                            \\abs{p(z)} = \\abs{\\sum_{n=0}^d a_nz^n} \\geq \\abs{z}^d - \\sum_{n=0}^{d-1} \\abs{a_n}\\abs{z}^n\n                                                                                                                                                                                                                                                            \\]\n                                                                                                                                                                                                                                                            Once $\\abs{z}$ gets sufficently big (say $\\abs{z}>M$), the leading term will dominate and we can say that, for some $M_2$ $\\abs{p(z)}>M_2$.\n\n                                                                                                                                                                                                                                                            Suppose that $p(z)$ never takes on the value $0$. Then $\\frac{1}{p(z)}$ is holomorphic, and outside of the ball of radius $M$, it's value is at most $\\frac{1}{M_2}$. And it's holomorphic hence continuous and thus also bounded inside the compact set that is the ball of radius $M$. Thus $\\frac{1}{p(z)}$ is bounded, and by \\ref{liouville-theorem}, it is constant.\n                                                                                                                                                                                                                                                            \\end{proof}\n                                                                                                                                                                                                                                                            \\end{document}\n", "meta": {"hexsha": "6c79cde69fe5e1b435b5e4a1bc85d202c3138be4", "size": 64580, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem-solutions/sol4.tex", "max_stars_repo_name": "Alex7Li/math5522h", "max_stars_repo_head_hexsha": "9f1fa070997f40e11e981c49e7d6fb9556e128d6", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "problem-solutions/sol4.tex", "max_issues_repo_name": "Alex7Li/math5522h", "max_issues_repo_head_hexsha": "9f1fa070997f40e11e981c49e7d6fb9556e128d6", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "problem-solutions/sol4.tex", "max_forks_repo_name": "Alex7Li/math5522h", "max_forks_repo_head_hexsha": "9f1fa070997f40e11e981c49e7d6fb9556e128d6", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 168.1770833333, "max_line_length": 655, "alphanum_fraction": 0.2039176216, "num_tokens": 7890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778825, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7030405836278597}}
{"text": "\\chapter*{Notation} \\addcontentsline{toc}{chapter}{Notation}\n\nFollowing notation is used throughout this text:\n\n\\bigskip\n\n\\begin{tabular}{l p{0.8\\textwidth}}\n\t\\(\\mathbb{N}\\) & set of natural numbers excluding zero \\\\\n\t\\(\\mathbb{N}_0\\) & set of natural numbers including zero \\\\\n\t\\(\\mathbb{R}\\) & set of real numbers \\\\\n\t\\(t\\) & discrete time moment; \\(t \\in \\mathbb{N}_0\\) \\\\\n\t\\(a_t\\) & value of quantity \\(a\\) at time \\(t\\); \\(a_t \\in \\mathbb{R}^n, n \\in \\mathbb{N}\\) \\\\\n\t\\(a_{t|t'}\\) & quantity with two indices: \\(t\\) and \\(t'\\) \\\\\n\t\t& there is no implicit link between \\(a_{t}\\), \\(a_{t|t'}\\) and \\(a_{t'}\\) \\\\\n\t\\(a_{t:t'}\\) & sequence of quantities \\((a_t, a_{t+1}, \\dotsc, a_{t'-1}, a_{t'})\\) \\\\\n\t\\(p(a_t)\\) & probability density function{\\footnotemark[1]} of quantity \\(a\\) at time \\(t\\) (unless\n\t\tnoted otherwise) \\\\\n\t\\(p(a_t|b_{t'})\\) & conditional {\\pdf} of quantity \\(a\\) at time \\(t\\) given value of quantity\n\t\t\\(b\\) at time \\(t'\\) \\\\\n\t\\(\\delta(a)\\) & Dirac delta function; used exclusively in context of {\\pdfs} to denote discrete\n\t\tdistribution within framework of continuous distributions{\\footnotemark[2]} \\\\\n\t\\(\\mathcal{N}(\\mu, \\Sigma)\\) & multivariate normal (Gaussian) {\\pdf} with mean vector \\(\\mu\\)\n\t\tand covariance matrix \\(\\Sigma\\) \\\\\n\\end{tabular}\n\n% \\footnote does not work in tabular environment, - this can be worked around with this\n\\footnotetext[1]{for the purpose of this text, {\\pdf} \\(p\\) is multivariate non-negative function\n\\(\\mathbb{R}^n \\rightarrow \\mathbb{R}; \\; \\int_{\\supp p} p(x_1, x_2, \\dotsc, x_n) \\; \\dx_1 \\dx_2 \\dotsb \\dx_n = 1\\)}\n\n\\footnotetext[2]{so that \\(\\int_{-\\infty}^{\\infty} f(x) \\delta(x - \\mu) \\; \\dx = f(\\mu)\\) and more\ncomplex expressions can be derived using integral linearity and Fubini's theorem.}\n", "meta": {"hexsha": "f5010c60608ad1c8610becec32da73e9c4fae8a7", "size": 1759, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chap0-notation.tex", "max_stars_repo_name": "strohel/PyBayes", "max_stars_repo_head_hexsha": "76d3ad12c20e29c5aadb688c4323fb0f1784f8ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 66, "max_stars_repo_stars_event_min_datetime": "2015-01-05T13:36:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-15T18:26:28.000Z", "max_issues_repo_path": "thesis/chap0-notation.tex", "max_issues_repo_name": "strohel/PyBayes", "max_issues_repo_head_hexsha": "76d3ad12c20e29c5aadb688c4323fb0f1784f8ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-02-23T19:45:11.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-21T08:21:52.000Z", "max_forks_repo_path": "thesis/chap0-notation.tex", "max_forks_repo_name": "strohel/PyBayes", "max_forks_repo_head_hexsha": "76d3ad12c20e29c5aadb688c4323fb0f1784f8ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 22, "max_forks_repo_forks_event_min_datetime": "2015-02-11T23:45:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-16T18:53:25.000Z", "avg_line_length": 54.96875, "max_line_length": 116, "alphanum_fraction": 0.6412734508, "num_tokens": 603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.7030405832445107}}
{"text": "\\subsection{Functions of rational numbers}\n\n\\subsubsection{Rational addition}\n\nThen we can define addition as:\n\n\\((a,b)+(c,d)=(a.d+b.c,b.d)\\)\n\n\\(a+b=c\\)\n\n\\(c_1=a_1b_2+a_2b_1\\)\n\n\\(c_1=a_2b_2\\)\n\n\\subsubsection{Rational subtraction}\n\n\\(a-b=c\\)\n\n\\(c_1=a_1b_2-a_2b_1\\)\n\n\\(c_1=a_2b_2\\)\n\n\\subsubsection{Rational multiplication}\n\nSimilarly, multiplication can be defined as:\n\n\\((a,b).(c,d)=(a.c, b.d)\\)\n\n\\(ab=c\\)\n\n\\(c_1=a_1b_1\\)\n\n\\(c_1=a_2b_2\\)\n\n\\subsubsection{Rational division}\n\n\\(\\dfrac{a}{b}=c\\)\n\n\\(c_1=a_1b_2\\)\n\n\\(c_1=a_2b_1\\)\n\n", "meta": {"hexsha": "71dee8565f4de10c6cc9cf6143248376d3c358c7", "size": 525, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/rational/01-03-rationalsFunctions.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/rational/01-03-rationalsFunctions.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/rational/01-03-rationalsFunctions.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 12.2093023256, "max_line_length": 44, "alphanum_fraction": 0.6514285714, "num_tokens": 223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464796, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.702923208350496}}
{"text": "\\gotosection{1}{1}\n\\subsection{Points and vectors}\n\n\\begin{exercise}{1}\n  All sketches are hand-drawn in the separate sketch paper.\n  \n  \\begin{enumerate}\n  \\item $\\begin{bmatrix}1\\\\3\\end{bmatrix} +\n         \\begin{bmatrix}2\\\\1\\end{bmatrix} =\n         \\begin{bmatrix}1+2\\\\3+1\\end{bmatrix} =\n         \\begin{bmatrix}3\\\\4\\end{bmatrix}$\n  \\item $2\\begin{bmatrix}2\\\\4\\end{bmatrix} =\n         \\begin{bmatrix}2 \\times 2\\\\2 \\times 4\\end{bmatrix} =\n         \\begin{bmatrix}4\\\\8\\end{bmatrix}$\n\n  \\item $\\begin{bmatrix}1\\\\3\\end{bmatrix} -\n         \\begin{bmatrix}2\\\\1\\end{bmatrix} =\n         \\begin{bmatrix}1-2\\\\3-1\\end{bmatrix} =\n         \\begin{bmatrix}-1\\\\2\\end{bmatrix}$\n\n  \\item $\\begin{bmatrix}3\\\\2\\end{bmatrix} + \\vec{\\mathbf{e}}_1 =\n         \\begin{bmatrix}3\\\\2\\end{bmatrix} +\n         \\begin{bmatrix}1\\\\0\\end{bmatrix} =\n         \\begin{bmatrix}3+1\\\\2+0\\end{bmatrix}=\n         \\begin{bmatrix}4\\\\2\\end{bmatrix}$\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{4}\n  \\begin{enumerate}\n    \\item The first trivial subspace is $V = \\{\\vec{\\mathbf{0}}\\}$, a singleton set containing only the zero       vector. The second one is $V = \\mathbb{R}^n$, namely the whole vector space itself.\n    \n    \\item Such two elements exist, which can be proven geometrically, as shown in the figure. Picking two vectors $\\Vect{x} = \\Vect{OA}$ and $\\Vect{y} = \\Vect{OB}$ from $S_1$, it is obvious that $\\Vect{x} + \\Vect{y} = \\Vect{OC}$ is the diagonal of the parallelogram OACB. If $\\Vect{x} + \\Vect{y} \\in S_1$, the sum vector must has the same length as $\\Vect{x}$ and $\\vec{y}$, being the radius of the unit circle. Therefore, triangle ACO and triangle COB must be equilateral triangles. In other words, as long as angle AOB is 120 degrees, which is evidently possible, the sum $\\Vect{x} + \\Vect{y} \\in S_1$. \\QED\n\n    \\begin{figure}[h]\n      \\begin{center}\n        \\begin{tikzpicture}\n          \\tkzInit[xmax=2.1,ymax=2.1,xmin=-2.1,ymin=-2.1]\n          \\tkzDrawX[noticks]\n          \\tkzDrawY[noticks]\n          \\tkzDefPoint(0,0){O}\n          \\tkzDefPoint[label=above:$A$](-1,1.732){A}\n          \\tkzCalcLength[cm](O,A)\n          \\tkzGetLength{rOA}\n          \\tkzDefPoint(\\rOA,0){B}\n          \\tkzDefPoint[label=above:$C$]({-1 + \\rOA}, 1.732){C}\n          \\tkzDrawCircle[R](O,\\rOA cm)\n          \\draw[thick,->] (O) -- (A);\n          \\draw[thick,->] (O) -- (B);\n          \\draw[thick,->] (O) -- (C);\n          \\tkzDrawSegments[postaction={decorate},dashed](A,C)\n          \\tkzDrawSegments[postaction={decorate},dashed](B,C)\n          \\tkzDrawPoints(O,A,B,C)\n          \\tkzLabelPoints(O,B)\n        \\end{tikzpicture}\n      \\end{center}\n    \\end{figure}\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{5}\n  $$\n    \\begin{bmatrix}1\\\\1\\\\\\vdots\\\\1\\\\1\\end{bmatrix} = \\sum\\limits_{i=1}^n \\Vect{e}_i\n    \\quad\\quad\\quad\n    \\begin{bmatrix}1\\\\2\\\\\\vdots\\\\n-1\\\\n\\end{bmatrix} = \\sum\\limits_{i=1}^n i\\Vect{e}_i\n    \\quad\\quad\\quad\n    \\begin{bmatrix}0\\\\0\\\\3\\\\4\\\\\\vdots\\\\n-1\\\\n\\end{bmatrix} = \\sum\\limits_{i=3}^n \\Vect{e}_i\n  $$\n\\end{exercise}\n\n\\begin{exercise}{6}\n  All sketches are hand-drawn in the separate sketch paper.\n\\end{exercise}\n\n\\begin{exercise}{8}\n  \\begin{enumerate}\n    \\item Suppose the axis of the pipe is the point set $\\{\\begin{pmatrix}x_0\\\\y_0\\\\z_0\\end{pmatrix}: z_0 \\in \\mathbb{R}\\}$.\n    Let $\\vec{F}$ be the vector field. It's obvious that outside the pipe the water speed is 0, namely for all $p \\in \\{\\begin{pmatrix}x\\\\y\\\\z\\end{pmatrix} : (x-x_0)^2 + (y-y_0)^2 > r^2, z \\in \\mathbb{R}\\}$, $\\vec{F}(p) = 0$.\n    \\footnote{More precisely, $\\vec{F}(p)$ is meaningless for those $p$, since there is no water. However, since vector field is a function whose domain is the whole vector space, I have to give it a default value. When grading please take into account that I have considered this.}\n    \n    For $p \\in \\{\\begin{pmatrix}x\\\\y\\\\z\\end{pmatrix}\\} : (x-x_0)^2 + (y-y_0)^2 \\leq r^2, z \\in \\mathbb{R}$, let $p = \\begin{pmatrix}x\\\\y\\\\z\\end{pmatrix}$, the distance between the axis and $p$ is $a = \\sqrt{(x - x_0)^2 + (y - y_0)^2}$. The water is flowing in the direction of the $z$-axis, so $z$ equals the water speed. Therefore:\n    \n    $$\\vec{F}(\\begin{pmatrix}x\\\\y\\\\z\\end{pmatrix}) =\n      \\begin{bmatrix}0\\\\0\\\\r^2 - a^2\\end{bmatrix} =\n      \\begin{bmatrix}0\\\\0\\\\1 - a^2\\end{bmatrix} =\n      \\begin{bmatrix}0\\\\0\\\\1 - (x-x_0)^2 - (y-y_0)^2\\end{bmatrix}$$\n    \n    \\item Assuming that the flow's direction is anticlockwise. Since the axis of\n    the pipe is the unit circle $S_2$ in the $(x, y)$-plane, the water speed in\n    the direction of the $z$-axis is 0, and the direction of the flow is tangent\n    to the pipe. For any point $p = \\begin{pmatrix}x\\\\y\\\\0\\end{pmatrix} \\in S_2$\n    , we can have a plane $P_p$ intersecting $p$ and the origin point. Let the\n    point set of the pipe be $D$, and $P_p' = D \\cap P_p$, then we have:\n    \n    \\begin{enumerate}\n      \\item Since $\\begin{bmatrix}x\\\\y\\\\0\\end{bmatrix}$ is a vector on $P_p$ and perpendicular\n      to $\\vec{dir} = \\begin{bmatrix}-y\\\\x\\\\0\\end{bmatrix}$, $P_p$ is also perpendicular to\n      $\\vec{dir}$. That is to say, for all $\\begin{pmatrix}x'\\\\y'\\\\z'\\end{pmatrix} \\in P_p$,\n      $\\begin{pmatrix}x'\\\\y'\\\\z'\\end{pmatrix}\\begin{bmatrix}-y\\\\x\\\\0\\end{bmatrix} = 0$.\n      \n      \\item $\\begin{bmatrix}-y\\\\x\\\\0\\end{bmatrix}$ is also the direction of water flow for points\n      in $P_p'$, since the direction of flow is tangent to the pipe, which also means that\n      it is tangent to the unit circle. Therefore, the water velocity for a point\n      $q \\in P_p'$, $\\vec{F}(q) = \\begin{bmatrix}v_x\\\\v_y\\\\0\\end{bmatrix}$, is parallel to\n      $\\begin{bmatrix}-y\\\\x\\\\0\\end{bmatrix}$, or $\\frac{v_x}{v_y} = \\frac{-y}{x}$.\n    \\end{enumerate}\n    \n    $D$ is the union of all sets $Pq'$ where $q$ is a point of the unit circle $S_2$:\n\n    $$D = \\bigcup\\limits_{(x, y, 0) \\in S_2}\n            \\{(x_1, y_1, z_1): (x_1 - x)^2 + (y_1 - y)^2 + z_1^2 \\leq r^2,\n                               \\begin{pmatrix}x_1\\\\y_1\\\\z_1\\end{pmatrix}\n                               \\begin{bmatrix}-y\\\\x\\\\0\\end{bmatrix} = 0\\}$$\n    \n    For every point $p \\in D$, let $p = \\begin{pmatrix}x\\\\y\\\\z\\end{pmatrix}$ and\n    $\\vec{F}(p) = \\begin{bmatrix}v_x\\\\v_y\\\\0\\end{bmatrix}$. From (b)\n    we know that:\n    \\begin{align*}\n      \\frac{v_x}{v_y} &= \\frac{-y}{x} \\\\\n                  v_x &= -\\frac{y}{x}v_y \n    \\end{align*}\n    \n    Next, we need to figure out what $a$ is. One way to do it is to omit the $z$\n    -component for now, and figure the distance $a'$ between the axis and $p$'s\n    projection $p'$ on $(x, y)$-plane, which is also the difference between the\n    distance from the axis to the origin point and that from $p'$ to the origin\n    point: $a' = \\sqrt{x^2 + y^2} - 1$. Obviously\n    $$a^2 = a'^2 + z^2 = (\\sqrt{x^2 + y^2} - 1)^2 + z^2$$\n\n\n    \\def \\tmp{(\\sqrt{x^2 + y^2} - 1)^2 - z^2}\n    Then,\n    \\begin{align*}\n                         |\\vec{F}(p)| &= r^2 - a^2 \\\\\n                 \\sqrt{v_x^2 + v_y^2} &= r^2 - \\tmp \\\\\n      \\sqrt{\\frac{y^2+x^2}{x^2}v_y^2} &= r^2 - \\tmp \\\\\n        \\frac{\\sqrt{y^2 + x^2}}{x}v_y &= \\pm (r^2 - \\tmp) \\\\\n      v_y &= \\pm \\frac{x(r^2 - \\tmp)}{\\sqrt{y^2 + x^2}} \\\\ & \\\\\n      v_x &= \\mp \\frac{y(r^2 - \\tmp)}{\\sqrt{y^2 + x^2}}\n    \\end{align*}\n    \n    With a bit simplification, for $p = \\begin{pmatrix}x\\\\y\\\\z\\end{pmatrix}$, we have\n    \n    $$\\vec{F}(p) =\n      \\left\\{\n      \\begin{array}{lcr}\n        0, & \\quad & p \\notin D \\\\ & & \\\\\n        \\frac{r^2 - \\tmp}{\\sqrt{y^2 + x^2}}\n        \\begin{bmatrix}-y\\\\x\\\\0\\end{bmatrix},\n           & \\quad & p \\in D\n      \\end{array}\n      \\right.$$\n      \n    One should note the assumption that the direction of flow is anticlockwise, which means\n    $v_y$ is negative and $v_y$ is positive when both $x$ and $y$ is positive. If the flow\n    is clockwise, the result should be ``inversed\":\n    \n    $$\\vec{F}(p) =\n      \\left\\{\n      \\begin{array}{lcr}\n        0, & \\quad & p \\notin D \\\\ & & \\\\\n        \\frac{r^2 - \\tmp}{\\sqrt{y^2 + x^2}}\n        \\begin{bmatrix}y\\\\-x\\\\0\\end{bmatrix},\n           & \\quad & p \\in D\n      \\end{array}\n      \\right.$$\n    \n  \\end{enumerate}\n\\end{exercise}", "meta": {"hexsha": "03dbd9f098f99c56ec76400c102e0d023f9ba0c1", "size": 8111, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW1/sec0101.tex", "max_stars_repo_name": "notcome/fa15-linear-algebra", "max_stars_repo_head_hexsha": "0ee2fbe81d901271d747e5b314101378a1633852", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW1/sec0101.tex", "max_issues_repo_name": "notcome/fa15-linear-algebra", "max_issues_repo_head_hexsha": "0ee2fbe81d901271d747e5b314101378a1633852", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW1/sec0101.tex", "max_forks_repo_name": "notcome/fa15-linear-algebra", "max_forks_repo_head_hexsha": "0ee2fbe81d901271d747e5b314101378a1633852", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.9940828402, "max_line_length": 609, "alphanum_fraction": 0.5777339416, "num_tokens": 3012, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7029133884998975}}
{"text": "\\part{Example Models}\\label{example-models.part}\n\n\\chapter{Regression Models}\n\n\\noindent\nStan supports regression models from simple linear regressions to\nmultilevel generalized linear models.\n\n\\section{Linear Regression}\n\nThe simplest linear regression model is the following, with a single\npredictor and a slope and intercept coefficient, and normally\ndistributed noise.  This model can be written using standard\nregression notation as\n%\n\\[\ny_n = \\alpha + \\beta x_n + \\epsilon_n\n\\ \\ \\ \\mbox{where} \\ \\ \\\n\\epsilon_n \\sim \\distro{Normal}(0,\\sigma).\n\\]\nThis is equivalent to the following sampling involving the\nresidual,\n\\[\ny_n - (\\alpha + \\beta X_n) \\sim \\distro{Normal}(0,\\sigma),\n\\]\nand reducing still further, to\n\\[\ny_n \\sim \\distro{Normal}(\\alpha + \\beta X_n, \\, \\sigma).\n\\]\n%\nThis latter form of the model is coded in Stan as follows.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N;\n  vector[N] x;\n  vector[N] y;\n}\nparameters {\n  real alpha;\n  real beta;\n  real<lower=0> sigma;\n}\nmodel {\n  y ~ normal(alpha + beta * x, sigma);\n}\n\\end{stancode}\n%\nThere are \\code{N} observations, each with predictor \\code{x[n]} and\noutcome \\code{y[n]}.  The intercept and slope parameters are\n\\code{alpha} and \\code{beta}.  The model assumes a normally\ndistributed noise term with scale \\code{sigma}.  This model has\nimproper priors for the two regression coefficients.\n\n\\subsection{Matrix Notation and Vectorization}\n\nThe sampling statement in the previous model is vectorized, with\n%\n\\begin{quote}\n\\begin{Verbatim}\n  y ~ normal(alpha + beta * x, sigma);\n\\end{Verbatim}\n\\end{quote}\n%\nproviding the same model as the unvectorized version,\n%\n\\begin{stancode}\n  for (n in 1:N)\n    y[n] ~ normal(alpha + beta * x[n], sigma);\n\\end{stancode}\n%\nIn addition to being more concise, the vectorized form is much faster.%\n%\n\\footnote{Unlike in Python and R, which are interpreted, Stan is\n  translated to \\Cpp and compiled, so loops and assignment statements\n  are fast.  Vectorized code is faster in Stan because (a) the\n  expression tree used to compute derivatives can be simplified,\n  leading to fewer virtual function calls, and (b) computations that\n  would be repeated in the looping version, such as \\code{log(sigma)}\n  in the above model, will be computed once and reused.}\n\nIn general, Stan allows the arguments to distributions such as\n\\code{normal} to be vectors.  If any of the other arguments are\nvectors or arrays, they have to be the same size.  If any of the other\narguments is a scalar, it is reused for each vector entry.  See\n\\refsection{vectorization} for more information on vectorization of\nprobability functions.\n\nThe other reason this works is that Stan's arithmetic operators are\noverloaded to perform matrix arithmetic on matrices.  In this case,\nbecause \\code{x} is of type \\code{vector} and \\code{beta} of type\n\\code{real}, the expression \\code{beta * x} is of type \\code{vector}.\nBecause Stan supports vectorization, a regression model with more than\none predictor can be written directly using matrix notation.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N;   // number of data items\n  int<lower=0> K;   // number of predictors\n  matrix[N, K] x;   // predictor matrix\n  vector[N] y;      // outcome vector\n}\nparameters {\n  real alpha;           // intercept\n  vector[K] beta;       // coefficients for predictors\n  real<lower=0> sigma;  // error scale\n}\nmodel {\n  y ~ normal(x * beta + alpha, sigma);  // likelihood\n}\n\\end{stancode}\n%\nThe constraint \\code{lower=0} in the declaration of \\code{sigma}\nconstrains the value to be greater than or equal to 0.  With no prior\nin the model block, the effect is an improper prior on non-negative\nreal numbers.  Although a more informative prior may be added, improper\npriors are acceptable as long as they lead to proper posteriors.\n\nIn the model above, \\code{x} is an $N \\times K$ matrix of predictors\nand \\code{beta} a $K$-vector of coefficients, so \\code{x * beta} is an\n$N$-vector of predictions, one for each of the $N$ data items.  These\npredictions line up with the outcomes in the $N$-vector \\code{y}, so\nthe entire model may be written using matrix arithmetic as shown.  It\nwould be possible to include a column of 1 values in \\code{x} and\nremove the \\code{alpha} parameter.\n\nThe sampling statement in the model above is just a more efficient,\nvector-based approach to coding the model with a loop, as in the\nfollowing statistically equivalent model.\n%\n\\begin{stancode}\nmodel {\n  for (n in 1:N)\n    y[n] ~ normal(x[n] * beta, sigma);\n}\n\\end{stancode}\n%\nWith Stan's matrix indexing scheme, \\code{x[n]} picks out row \\code{n}\nof the matrix \\code{x};  because \\code{beta} is a column vector,\nthe product \\code{x[n] * beta} is a scalar of type \\code{real}.\n\n\\subsubsection{Intercepts as Inputs}\n\nIn the model formulation\n%\n\\begin{stancode}\n  y ~ normal(x * beta, sigma);\n\\end{stancode}\n%\nthere is no longer an intercept coefficient \\code{alpha}.  Instead, we\nhave assumed that the first column of the input matrix \\code{x} is a\ncolumn of 1 values.  This way, \\code{beta[1]} plays the role of the\nintercept.  If the intercept gets a different prior than the slope\nterms, then it would be clearer to break it out.  It is also slightly\nmore efficient in its explicit form with the intercept variable\nsingled out because there's one fewer multiplications; it should not\nmake that much of a difference to speed, though, so the choice should\nbe based on clarity.\n\n\\section{The QR Reparameterization}\\label{QR-reparameterization.section}\n\nIn the previous example, the linear predictor can be written as\n$\\eta = x \\beta$, where $\\eta$ is a $N$-vector of predictions,\n$x$ is a $N \\times K$ matrix, and $\\beta$ is a $K$-vector of coefficients.\nPresuming $N \\geq K$, we can exploit the fact that any design matrix, $x$\ncan be decomposed using the thin QR decomposition into an orthogonal matrix\n$Q$ and an upper-triangular matrix $R$, i.e. $x = Q R$. See \\ref{QR-decomposition}\nfor more information on the QR decomposition but note that \\code{qr\\_Q} and\n\\code{qr\\_R} implement the fat QR decomposition so here we thin it by including\nonly $K$ columns in $Q$ and $K$ rows in $R$. Also, in practice, it is best to\nwrite $x = Q^\\ast R^\\ast$ where $Q^\\ast = Q \\times \\sqrt{n - 1}$ and\n$R^\\ast = \\frac{1}{\\sqrt{n - 1}} R$. Thus, we can equivalently write\n$\\eta = x \\beta = Q R \\beta = Q^\\ast R^\\ast \\beta$. If we let\n$\\theta = R^\\ast \\beta$, then we have $\\eta = Q^\\ast \\theta$ and\n$\\beta = R^{\\ast^{-1}} \\theta$. In that case, the previous Stan program becomes\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N;   // number of data items\n  int<lower=0> K;   // number of predictors\n  matrix[N, K] x;   // predictor matrix\n  vector[N] y;      // outcome vector\n}\ntransformed data {\n  matrix[N, K] Q_ast;\n  matrix[K, K] R_ast;\n  matrix[K, K] R_ast_inverse;\n  // thin and scale the QR decomposition\n  Q_ast = qr_Q(x)[, 1:K] * sqrt(N - 1);\n  R_ast = qr_R(x)[1:K, ] / sqrt(N - 1);\n  R_ast_inverse = inverse(R_ast);\n}\nparameters {\n  real alpha;           // intercept\n  vector[K] theta;      // coefficients on Q_ast\n  real<lower=0> sigma;  // error scale\n}\nmodel {\n  y ~ normal(Q_ast * theta + alpha, sigma);  // likelihood\n}\ngenerated quantities {\n  vector[K] beta;\n  beta = R_ast_inverse * theta; // coefficients on x\n}\n\\end{stancode}\n%\nSince this Stan program generates equivalent predictions for $y$ and\nthe same posterior distribution for $\\alpha$, $\\beta$, and $\\sigma$ as\nthe previous Stan program, many wonder why the version with this QR\nreparameterization performs so much better in practice, often both in\nterms of wall time and in terms of effective sample size. The\nreasoning is threefold:\n%\n\\begin{enumerate}\n\\item The columns of $Q^\\ast$ are orthogonal whereas the columns of\n  $x$ generally are not. Thus, it is easier for a Markov Chain to move\n  around in $\\theta$-space than in $\\beta$-space.\n\\item The columns of $Q^\\ast$ have the same scale whereas the columns\n  of $x$ generally do not. Thus, a Hamiltonian Monte Carlo algorithm\n  can move around the parameter space with a smaller number of larger\n  steps\n\\item Since the covariance matrix for the columns of $Q\\ast$ is an\n  identity matrix, $\\theta$ typically has a reasonable scale if the\n  units of $y$ are also reasonable. This also helps HMC move\n  efficiently without compromising numerical accuracy.\n\\end{enumerate}\n%\nConsequently, this QR reparameterization is recommended for linear and\ngeneralized linear models in Stan whenever $K > 1$ and you do not have\nan informative prior on the \\emph{location} of $\\beta$. It can also be\nworthwhile to subtract the mean from each column of $x$ before\nobtaining the QR decomposition, which does not affect the posterior\ndistribution of $\\theta$ or $\\beta$ but does affect $\\alpha$ and\nallows you to interpret $\\alpha$ as the expectation of $y$ in a linear\nmodel.\n\n\\section{Priors for Coefficients and Scales}\\label{regression-priors.section}\n\nThis section describes the choices available for modeling priors for\nregression coefficients and scales.  Priors for univariate parameters\nin hierarchical models are discussed in\n\\refsection{hierarchical-priors} and multivariate parameters in\n\\refsection{multivariate-hierarchical-priors}. There is also a\ndiscussion of priors used to identify models in\n\\refsection{priors-for-identification}.\n\nHowever, as described in \\refsection{QR-reparameterization}, if you do\nnot have an informative prior on the \\emph{location} of the regression\ncoefficients, then you are better off reparameterizing your model so\nthat the regression coefficients are a generated quantity. In that case,\nit usually does not matter very much what prior is used on on the\nreparameterized regression coefficients and almost any weakly informative\nprior that scales with the outcome will do.\n\n\\subsection{Background Reading}\n\nSee \\citep{Gelman:2006} for an overview of choices for priors for\nscale parameters, \\citep{ChungEtAl:2013} for an overview of choices\nfor scale priors in penalized maximum likelihood estimates, and\n\\cite{GelmanJakulinPittauEtAl:2008} for a discussion of prior choice\nfor regression coefficients.\n\n\\subsection{Improper Uniform Priors}\n\nThe default in Stan is to provide uniform (or ``flat'') priors on\nparameters over their legal values as determined by their declared\nconstraints.  A parameter declared without constraints is thus given a\nuniform prior on $(-\\infty,\\infty)$ by default, whereas a scale\nparameter declared with a lower bound of zero gets an improper uniform\nprior on $(0,\\infty)$.  Both of these priors are improper in the sense\nthat there is no way formulate a density function for them that\nintegrates to 1 over its support.\n\nStan allows models to be formulated with improper priors, but in order\nfor sampling or optimization to work, the data provided must ensure a\nproper posterior.  This usually requires a minimum quantity of data,\nbut can be useful as a starting point for inference and as a baseline\nfor sensitivity analysis (i.e., considering the effect the prior\nhas on the posterior).\n\nUniform priors are specific to the scale on which they are formulated.\nFor instance, we could give a scale parameter $\\sigma > 0$ a uniform\nprior on $(0,\\infty)$, $q(\\sigma) = c$ (we use $q$ because the\n``density'' is not only unnormalized, but unnormalizable), or we could\nwork on the log scale and provide $\\log \\sigma$ a uniform prior on\n$(-\\infty,\\infty)$, $q(\\log \\sigma) = c$.  These work out to be\ndifferent priors on $\\sigma$ due to the Jacobian adjustment necessary\nfor the log transform; see \\refsection{change-of-variables} for more\ninformation on changes of variables and their requisite Jacobian\nadjustments.\n\nStan automatically applies the necessary Jacobian adjustment for\nvariables declared with constraints to ensure a uniform density on the\nlegal constrained values.  This Jacobian adjustment is turned off when\noptimization is being applied in order to produce appropriate maximum\nlikelihood estimates.\n\n\\subsection{Proper Uniform Priors: Interval Constraints}\n\nIt is possible to declare a variable with a proper uniform prior by\nimposing both an upper and lower bound on it, for example,\n%\n\\begin{stancode}\nreal<lower=0.1, upper=2.7> sigma;\n\\end{stancode}\n%\nThis will implicitly give \\code{sigma} a $\\distro{Uniform}(0.1, 2.7)$\nprior.\n\n\\subsubsection{Matching Support to Constraints}\n\nAs with all constraints, it is important that the model\nprovide support for all legal values of \\code{sigma}.  For example,\nthe following code constraints \\code{sigma} to be positive, but then\nimposes a bounded uniform prior on it.\n%\n\\begin{stancode}\nparameters {\n  real<lower=0> sigma;\n  ...\nmodel {\n  // *** bad *** : support narrower than constraint\n  sigma ~ uniform(0.1, 2.7);\n\\end{stancode}\n%\nThe sampling statement imposes a limited support for \\code{sigma} in\n(0.1, 2.7), which is narrower than the support declared in the\nconstraint, namely $(0, \\infty)$.  This can cause the Stan program to\nbe difficult to initialize, hang during sampling, or devolve to a\nrandom walk.\n\n\\subsubsection{Boundary Estimates}\n\nEstimates near boundaries for interval-constrained parameters\ntypically signal that the prior is not appropriate for the model.  It\ncan also cause numerical problems with underflow and overflow when\nsampling or optimizing.\n\n\\subsection{``Uninformative'' Proper Priors}\n\nIt is not uncommon to see models with priors on regression\ncoefficients such as $\\distro{Normal}(0,1000)$.%\n%\n\\footnote{The practice was common in BUGS and can be seen in most of\n  their examples \\cite{LunnEtAl:2012}.}\n%\nIf the prior scale, such as 1000, is several orders of magnitude\nlarger than the estimated coefficients, then such a prior is\neffectively providing no effect whatsoever.\n\nWe actively discourage users from using the default scale priors\nsuggested through the BUGS examples \\citep{LunnEtAl:2012}, such as\n\\[\n\\sigma^2 \\sim \\distro{InvGamma}(0.001, 0.001).\n\\]\n%\nSuch priors concentrate too much probability mass outside of\nreasonable posterior values, and unlike the symmetric wide normal\npriors, can have the profound effect of skewing posteriors; see\n\\citep{Gelman:2006} for examples and discussion.\n\n\\subsection{Truncated Priors}\n\nIf a variable is declared with a lower bound of zero, then assigning\nit a normal prior in a Stan model produces the same effect as\nproviding a properly truncated half-normal prior.  The truncation at\nzero need not be specified as Stan only requires the density up to a\nproportion.  So a variable declared with\n%\n\\begin{stancode}\nreal<lower=0> sigma;\n\\end{stancode}\n%\nand given a prior\n\\begin{stancode}\nsigma ~ normal(0, 1000);\n\\end{stancode}\n%\ngives \\code{sigma} a half-normal prior, technically\n%\n\\[\np(\\sigma)\n\\ = \\\n\\frac{\\distro{Normal}(\\sigma | 0, 1000)}\n     {1 - \\distro{NormalCDF}(0 | 0, 1000)}\n\\ \\propto \\\n\\distro{Normal}(\\sigma | 0, 1000),\n\\]\n%\nbut Stan is able to avoid the calculation of the normal cumulative\ndistribution (CDF) function required to normalize the half-normal density.\nIf either the prior location or scale is a parameter or if the\ntruncation point is a parameter, the truncation cannot be dropped,\nbecause the normal CDF term will not be a constant.\n\n\n\\subsection{Weakly Informative Priors}\n\nTypically a researcher will have some knowledge of the scale of the\nvariables being estimated.  For instance, if we're estimating an\nintercept-only model for the mean population height for adult women,\nthen we know the answer is going to be somewhere in the one to three\nmeter range.  That gives us information around which to form a weakly\ninformative prior.\n\nSimilarly, a logistic regression with predictors on the standard scale\n(roughly zero mean, unit variance) is unlikely to have a\ncoefficient that's larger than five in absolute value.  In these\ncases, it makes sense to provide a weakly informative prior such as\n$\\distro{Normal}(0,5)$ for such a coefficient.\n\nWeakly informative priors help control inference computationally and\nstatistically.  Computationally, a prior increases the curvature\naround the volume where the solution is expected to lie, which in turn\nguides both gradient-based like L-BFGS and Hamiltonian Monte Carlo\nsampling by not allowing them to stray too far from the location of a\nsurface.  Statistically, a weakly informative prior is more sensible\nfor a problem like women's mean height, because a very diffuse prior\nlike $\\distro{Normal}(0,1000)$ will ensure that the vast majority of\nthe prior probability mass is outside the range of the expected\nanswer, which can overwhelm the inferences available from a small data\nset.\n\n\\subsection{Bounded Priors}\n\nConsider the women's height example again.  One way to formulate a\nproper prior is to impose a uniform prior on a bounded scale.  For\nexample, we could declare the parameter for mean women's height to\nhave a lower bound of one meter and an upper bound of three meters.\nSurely the answer has to lie in that range.\n\nSimilarly, it is not uncommon to see priors for scale parameters that\nimpose lower bounds of zero and upper bounds of very large numbers,\nsuch as 10,000.%\n%\n\\footnote{This was also a popular strategy in the BUGS example models\n  \\citep{LunnEtAl:2012}, which often went one step further and set the\n  lower bounds to a small number like 0.001 to discourage numerical\n  underflow to zero.}\n%\nThis provides roughly the same problem for estimation as a very\ndiffuse inverse gamma prior on variance.  We prefer to leave\nparameters which are not absolutely physically constrained to float\nand provide them informative priors.  In the case of women's height,\nsuch a prior might be $\\distro{Normal}(2,0.5)$ on the scale of meters;\nit concentrates 95\\% of its mass in the interval $(1,3)$, but still\nallows values outside of that region.\n\nIn cases where bounded priors are used, the posterior fits should be\nchecked to make sure the parameter is not estimated at or very close\nto a boundary.  This will not only cause computational problems, it\nindicates a problem with the way the model is formulated.  In such\ncases, the interval should be widened to see where the parameter fits\nwithout such constraints, or boundary-avoid priors should be used (see\n\\refsection{hierarchical-priors}.)\n\n\\subsection{Fat-Tailed Priors and ``Default'' Priors}\n\nA reasonable alternative if we want to accommodate outliers is to use a\nprior that concentrates most of mass around the area where values are\nexpected to be, but still leaves a lot of mass in its tails.  The\nusual choice in such a situation is to use a Cauchy distribution for a\nprior, which can concentrate its mass around its median, but has tails\nthat are so fat that the variance is infinite.\n\nWithout specific information, the Cauchy prior is a very good default\nparameter choice for regression coefficients\n\\citep{GelmanJakulinPittauEtAl:2008} and the half-Cauchy (coded\nimplicitly in Stan) a good default choice for scale parameters\n\\citep{Gelman:2006}.\n\n\n\n\\subsection{Informative Priors}\n\nIdeally, there will be substantive information about a problem that\ncan be included in an even tighter prior than a weakly informative\nprior.  This may come from actual prior experiments and thus be the\nposterior of other data, it may come from meta-analysis, or it may\ncome simply by soliciting it from domain experts.  All the goodness of\nweakly informative priors applies, only with more strength.\n\n\\subsection{Conjugacy}\n\nUnlike in Gibbs sampling, there is no computational advantage to\nproviding conjugate priors (i.e., priors that produce posteriors in\nthe same family) in a Stan program.%\n%\n\\footnote{BUGS and JAGS both support conjugate sampling through Gibbs\n  sampling.  JAGS extended the range of conjugacy that could be\n  exploited with its GLM module.  Unlike Stan, both BUGS and JAGS are\n  restricted to conjugate priors for constrained multivariate\n  quantities such as covariance matrices or simplexes.}\n%\nNeither the Hamiltonian Monte Carlo samplers or the optimizers make\nuse of conjugacy, working only on the log density and its derivatives.\n\n\n\n\\section{Robust Noise Models}\n\nThe standard approach to linear regression is to model the noise\nterm $\\epsilon$ as having a normal distribution.  From Stan's\nperspective, there is nothing special about normally distributed\nnoise.  For instance, robust regression can be accommodated by giving\nthe noise term a Student-$t$ distribution.  To code this in Stan, the\nsampling distribution is changed to the following.\n%\n\n\\begin{stancode}\ndata {\n  ...\n  real<lower=0> nu;\n}\n...\nmodel {\n  y ~ student_t(nu, alpha + beta * x, sigma);\n}\n\\end{stancode}\n%\nThe degrees of freedom constant \\code{nu} is specified as data.\n\n\\section{Logistic and Probit Regression}\\label{logistic-probit-regression.section}\n\nFor binary outcomes, either of the closely related logistic or probit\nregression models may be used.  These generalized linear models vary\nonly in the link function they use to map linear predictions in\n$(-\\infty,\\infty)$ to probability values in $(0,1)$.  Their respective\nlink functions, the logistic function and the unit normal cumulative distribution\nfunction, are both sigmoid functions (i.e., they are both {\\it S}-shaped).\n\nA logistic regression model with one predictor and an intercept is coded as\nfollows.\n%\n\n\\begin{stancode}\ndata {\n  int<lower=0> N;\n  vector[N] x;\n  int<lower=0,upper=1> y[N];\n}\nparameters {\n  real alpha;\n  real beta;\n}\nmodel {\n  y ~ bernoulli_logit(alpha + beta * x);\n}\n\\end{stancode}\n%\nThe noise parameter is built into the Bernoulli formulation here\nrather than specified directly.\n\nLogistic regression is a kind of generalized linear model with binary\noutcomes and the log odds (logit) link function, defined by\n%\n\\[\n\\mbox{logit}(v) = \\log \\left( \\frac{v}{1-v} \\right).\n\\]\n%\nThe inverse of the link function appears in the model.\n%\n\\[\n\\mbox{logit}^{-1}(u) = \\frac{1}{1 + \\exp(-u)}.\n\\]\n%\n\nThe model formulation above uses the logit-parameterized version of\nthe Bernoulli distribution, which is defined by\n%\n\\[\n\\distro{BernoulliLogit}(y|\\alpha)\n=\n\\distro{Bernoulli}(y | \\mbox{logit}^{-1}(\\alpha)).\n\\]\n%\nThe formulation is also vectorized in the sense that \\code{alpha} and\n\\code{beta} are scalars and \\code{x} is a vector, so that \\code{alpha\n  + beta * x} is a vector.  The vectorized formulation is equivalent\nto the less efficient version\n%\n\n\\begin{stancode}\nfor (n in 1:N)\n  y[n] ~ bernoulli_logit(alpha + beta * x[n]);\n\\end{stancode}\n%\nExpanding out the Bernoulli logit, the model is equivalent to the more\nexplicit, but less efficient and less arithmetically stable\n%\n\n\\begin{stancode}\nfor (n in 1:N)\n  y[n] ~ bernoulli(inv_logit(alpha + beta * x[n]));\n\\end{stancode}\n\nOther link functions may be used in the same way.  For example, probit\nregression uses the cumulative normal distribution function, which is\ntypically written as\n\\[\n\\Phi(x) = \\int_{-\\infty}^x \\distro{Normal}(y|0,1) \\, dy.\n\\]\n%\nThe cumulative unit normal distribution function $\\Phi$ is implemented\nin Stan as the function \\code{Phi}.  The probit regression model\nmay be coded in Stan by replacing the logistic model's sampling\nstatement with the following.\n%\n\n\\begin{stancode}\n        y[n] ~ bernoulli(Phi(alpha + beta * x[n]));\n\\end{stancode}\n%\nA fast approximation to the cumulative unit normal distribution function\n$\\Phi$ is implemented in Stan as the function \\code{Phi\\_approx}.  The\napproximate probit regression model may be coded with the following.\n%\n\n\\begin{stancode}\n        y[n] ~ bernoulli(Phi_approx(alpha + beta * x[n]));\n\\end{stancode}\n\n\\section{Multi-Logit Regression}\\label{multi-logit.section}\n\nMultiple outcome forms of logistic regression can be coded directly in\nStan.  For instance, suppose there are $K$ possible outcomes for each\noutput variable $y_n$.  Also suppose that there is a $D$-dimensional\nvector $x_n$ of predictors for $y_n$.  The multi-logit model with\n$\\distro{Normal}(0,5)$ priors on the coefficients is coded as follows.\n%\n\n\\begin{stancode}\ndata {\n  int K;\n  int N;\n  int D;\n  int y[N];\n  matrix[N, D] x;\n}\nparameters {\n  matrix[D, K] beta;\n}\nmodel {\n  matrix[N, K] x_beta = x * beta;\n\n  to_vector(beta) ~ normal(0, 2);\n\n  for (n in 1:N)\n    y[n] ~ categorical_logit(x_beta[n]);\n}\n\\end{stancode}\n%\nThe matrix multiplication is pulled out to define a local variable for\nall of the predictors.   Then the prior on \\code{beta} is coded in\nvectorized form.    Then, the categorical is expressed on the log-odds\n(logit) scale; an equivalent form without the matrix multiplication\n\nThe categorical distribution with log-odds (logit) scaled parameters\nused above is equivalent to writing\n%\n\\begin{stancode}\n    y[n] ~ categorical(softmax(x[n] * beta));\n\\end{stancode}\n%\nSee \\refsection{softmax} for a definition of the softmax function and\n\\refsection{categorical-distribution} for a full definition of\n\\code{categorical\\_logit}.\n\n\n\\subsubsection{Constraints on Data Declarations}\n\nThe data block in the above model is defined without constraints on\nsizes \\code{K}, \\code{N}, and \\code{D} or on the outcome array\n\\code{y}.  Constraints on data declarations provide error checking at\nthe point data is read (or transformed data is defined), which is\nbefore sampling begins.  Constraints on data declarations also make\nthe model author's intentions more explicit, which can help with\nreadability.  The above model's declarations could be tightened to\n%\n\n\\begin{stancode}\n  int<lower = 2> K;\n  int<lower = 0> N;\n  int<lower = 1> D;\n  int<lower = 1, upper = K> y[N];\n\\end{stancode}\n%\nThese constraints arise because the number of categories, \\code{K},\nmust be at least two in order for a categorical model to be useful.\nThe number of data items, \\code{N}, can be zero, but not negative;\nunlike R, Stan's for-loops always move forward, so that a loop extent\nof \\code{1:N} when \\code{N} is equal to zero ensures the loop's body\nwill not be executed.  The number of predictors, \\code{D}, must be at\nleast one in order for \\code{beta * x[n]} to produce an\nappropriate argument for \\code{softmax()}.  The categorical outcomes\n\\code{y[n]} must be between \\code{1} and \\code{K} in order for the\ndiscrete sampling to be well defined.\n\nConstraints on data declarations are optional.  Constraints on\nparameters declared in the \\code{parameters} block, on the other hand,\nare {\\it not}\\ optional---they are required to ensure support for all\nparameter values satisfying their constraints.  Constraints on\ntransformed data, transformed parameters, and generated quantities are\nalso optional.\n\n\\subsection{Identifiability}\n\nBecause softmax is invariant under adding a constant to each component\nof its input, the model is typically only identified if there is a\nsuitable prior on the coefficients.\n\nAn alternative is to use $(K-1)$-vectors by fixing one of them to be\nzero. \\refsection{partially-known-parameters} discusses how to mix\nconstants and parameters in a vector.  In the multi-logit case, the\nparameter block would be redefined to use $(K-1)$-vectors\n%\n\\begin{stancode}\nparameters {\n  matrix[K - 1, D] beta_raw;\n}\n\\end{stancode}\n%\nand then these are transformed to parameters to use in the model.\nFirst, a transformed data block is added before the parameters block\nto define a row vector of zero values,\n%\n\\begin{stancode}\ntransformed data {\n  row_vector[D] zeros = rep_row_vector(0, D);\n}\n\\end{stancode}\n%\nwhich can then be appended to \\code{beta\\_row} to produce the\ncoefficient matrix \\code{beta},\n%\n\\begin{stancode}\ntransformed parameters {\n  matrix[K, D] beta;\n  beta = append_row(beta_raw, zeros);\n}\n\\end{stancode}\n%\nSee \\refsection{matrix-broadcast} for a definition of\n\\code{rep\\_row\\_vector} and \\refsection{matrix-concatenation} for a\ndefinition of \\code{append\\_row}.\n\nThis is not quite the same model as using $K$-vectors as parameters,\nbecause now the prior only applies to $(K-1)$-vectors.  In practice,\nthis will cause the maximum likelihood solutions to be different and\nalso the posteriors to be slightly different when taking priors\ncentered around zero, as is typical for regression coefficients.\n\n\\section{Parameterizing Centered Vectors}\n\nIt is often convenient to define a parameter vector $\\beta$ that is\ncentered in the sense of satisfying the sum-to-zero constraint,\n%\n\\[\n\\sum_{k=1}^K \\beta_k = 0.\n\\]\n%\nSuch a parameter vector may be used to identify a multi-logit\nregression parameter vector (see \\refsection{multi-logit}), or may be\nused for ability or difficulty parameters (but not both) in an IRT\nmodel (see \\refsection{item-response-models}).\n\n\n\\subsection{$K-1$ Degrees of Freedom}\n\nThere is more than one way to enforce a sum-to-zero constraint on a\nparameter vector, the most efficient of which is to define the $K$-th\nelement as the negation of the sum of the elements $1$ through $K-1$.\n%\n\\begin{stancode}\nparameters {\n  vector[K-1] beta_raw;\n  ...\ntransformed parameters {\n  vector[K] beta;  // centered\n\n  beta[1 : K - 1] = beta_raw;\n  beta[K] = -sum(beta_raw);\n  ...\n\\end{stancode}\n\nPlacing a prior on \\code{beta\\_raw} in this parameterization leads to\na subtly different posterior than that resulting from the same prior\non \\code{beta} in the original parameterization without the\nsum-to-zero constraint.  Most notably, a simple prior on each\ncomponent of \\code{beta\\_raw} produces different results than putting\nthe same prior on each component of an unconstrained $K$-vector\n\\code{beta}.  For example, providing a $\\distro{Normal}(0,5)$ prior\non \\code{beta} will produce a different posterior mode than placing\nthe same prior on \\code{beta\\_raw}.\n\n\n\\subsection{Translated and Scaled Simplex}\n\nAn alternative approach that's less efficient, but amenable to a\nsymmetric prior, is to offset and scale a simplex.\n%\n\\begin{stancode}\nparameters {\n  simplex[K] beta_raw;\n  real beta_scale;\n  ...\ntransformed parameters {\n  vector[K] beta;\n  beta = beta_scale * (beta_raw - inv(K));\n  ...\n\\end{stancode}\n%\nHere \\code{inv(K)} is just a short way to write \\code{1.0~/~K}.  Given\nthat \\code{beta\\_raw} sums to 1 because it is a simplex, the\nelementwise subtraction of \\code{inv(K)} is guaranteed to sum to zero.\nBecause the magnitude of the elements of the simplex is bounded, a\nscaling factor is required to provide \\code{beta} with $K$ degrees of\nfreedom necessary to take on every possible value that sums to zero.\n\nWith this parameterization, a Dirichlet prior can be placed on\n\\code{beta\\_raw}, perhaps uniform, and another prior put on\n\\code{beta\\_scale}, typically for ``shrinkage.''\n\n\n\\subsection{Soft Centering}\n\nAdding a prior such as $\\beta \\sim \\distro{Normal}(0,\\sigma)$ will provide a kind\nof soft centering of a parameter vector $\\beta$ by preferring, all\nelse being equal, that $\\sum_{k=1}^K \\beta_k = 0$.  This approach is only\nguaranteed to roughly center  if $\\beta$ and the elementwise addition $\\beta + c$\nfor a scalar constant $c$ produce the same likelihood (perhaps by\nanother vector $\\alpha$ being transformed to $\\alpha - c$, as in the\nIRT models).  This is another way of achieving a symmetric prior.\n\n\n\\section{Ordered Logistic and Probit Regression}\\label{ordered-logistic.section}\n\nOrdered regression for an outcome $y_n \\in \\setlist{1,\\ldots, k}$ with\npredictors $x_n \\in \\reals^D$ is determined by a single coefficient\nvector $\\beta \\in \\reals^D$ along with a sequence of cutpoints $c \\in\n\\reals^{K-1}$ sorted so that $c_d < c_{d+1}$.  The discrete output is\n$k$ if the linear predictor $x_n \\beta$ falls between $c_{k-1}$ and\n$c_k$, assuming $c_0 = -\\infty$ and $c_K = \\infty$.  The noise term is\nfixed by the form of regression, with examples for ordered logistic\nand ordered probit models.\n\n\\subsection{Ordered Logistic Regression}\n\nThe ordered logistic model can be coded in Stan using the\n\\code{ordered} data type for the cutpoints and the built-in\n\\code{ordered\\_logistic} distribution.\n%\n\n\\begin{stancode}\ndata {\n  int<lower=2> K;\n  int<lower=0> N;\n  int<lower=1> D;\n  int<lower=1,upper=K> y[N];\n  row_vector[D] x[N];\n}\nparameters {\n  vector[D] beta;\n  ordered[K-1] c;\n}\nmodel {\n  for (n in 1:N)\n    y[n] ~ ordered_logistic(x[n] * beta, c);\n}\n\\end{stancode}\n%\nThe vector of cutpoints \\code{c} is declared as \\code{ordered[K-1]},\nwhich guarantees that \\code{c[k]} is less than \\code{c[k+1]}.\n\nIf the cutpoints were assigned independent priors, the constraint\neffectively truncates the joint prior to support over points that\nsatisfy the ordering constraint.  Luckily, Stan does not need to\ncompute the effect of the constraint on the normalizing term because\nthe probability is needed only up to a proportion.\n\n\n\\subsubsection{Ordered Probit}\n\nAn ordered probit model could be coded in exactly the same way by\nswapping the cumulative logistic (\\code{inv\\_logit}) for the cumulative\nnormal (\\code{Phi}).\n%\n\n\\begin{stancode}\ndata {\n  int<lower=2> K;\n  int<lower=0> N;\n  int<lower=1> D;\n  int<lower=1,upper=K> y[N];\n  row_vector[D] x[N];\n}\nparameters {\n  vector[D] beta;\n  ordered[K-1] c;\n}\nmodel {\n  vector[K] theta;\n  for (n in 1:N) {\n    real eta;\n    eta = x[n] * beta;\n    theta[1] = 1 - Phi(eta - c[1]);\n    for (k in 2:(K-1))\n      theta[k] = Phi(eta - c[k-1]) - Phi(eta - c[k]);\n    theta[K] = Phi(eta - c[K-1]);\n    y[n] ~ categorical(theta);\n  }\n}\n\\end{stancode}\n%\nThe logistic model could also be coded this way by replacing\n\\code{Phi} with \\code{inv\\_logit}, though the built-in encoding based\non the softmax transform is more efficient and more numerically\nstable.  A small efficiency gain could be achieved by computing the\nvalues \\code{Phi(eta - c[k])} once and storing them for re-use.\n\n\n\\section{Hierarchical Logistic Regression}\n\nThe simplest multilevel model is a hierarchical model in which the\ndata is grouped into $L$ distinct categories (or levels).  An extreme\napproach would be to completely pool all the data and estimate a\ncommon vector of regression coefficients $\\beta$.  At the other\nextreme, an approach with no pooling assigns each level $l$ its own\ncoefficient vector $\\beta_l$ that is estimated separately from the\nother levels.  A hierarchical model is an intermediate solution where\nthe degree of pooling is determined by the data and a prior on the\namount of pooling.\n\nSuppose each binary outcome $y_n \\in \\setlist{0,1}$ has an associated\nlevel, $ll_n \\in \\setlist{1,\\ldots,L}$.  Each outcome will also have\nan associated predictor vector $x_n \\in \\reals^D$.  Each level $l$\ngets its own coefficient vector $\\beta_l \\in \\reals^D$.  The\nhierarchical structure involves drawing the coefficients $\\beta_{l,d}\n\\in \\reals$ from a prior that is also estimated with the data.  This\nhierarchically estimated prior determines the amount of pooling.  If\nthe data in each level are very similar, strong pooling will be\nreflected in low hierarchical variance.  If the data in the levels are\ndissimilar, weaker pooling will be reflected in higher hierarchical variance.\n\nThe following model encodes a hierarchical logistic regression model\nwith a hierarchical prior on the regression coefficients.\n%\n\n\\begin{stancode}\ndata {\n  int<lower=1> D;\n  int<lower=0> N;\n  int<lower=1> L;\n  int<lower=0,upper=1> y[N];\n  int<lower=1,upper=L> ll[N];\n  row_vector[D] x[N];\n}\nparameters {\n  real mu[D];\n  real<lower=0> sigma[D];\n  vector[D] beta[L];\n}\nmodel {\n  for (d in 1:D) {\n    mu[d] ~ normal(0, 100);\n    for (l in 1:L)\n      beta[l,d] ~ normal(mu[d], sigma[d]);\n  }\n  for (n in 1:N)\n    y[n] ~ bernoulli(inv_logit(x[n] * beta[ll[n]]));\n}\n\\end{stancode}\n%\nThe standard deviation parameter \\code{sigma} gets an implicit uniform\nprior on $(0,\\infty)$ because of its declaration with a lower-bound\nconstraint of zero.  Stan allows improper priors as long as the\nposterior is proper.  Nevertheless, it is usually helpful to have\ninformative or at least weakly informative priors for all parameters;\nsee \\refsection{regression-priors} for recommendations on priors for\nregression coefficients and scales.\n\n\\subsubsection{Optimizing the Model}\n\nWhere possible, vectorizing sampling statements leads to faster log\nprobability and derivative evaluations.  The speed boost is not\nbecause loops are eliminated, but because vectorization allows sharing\nsubcomputations in the log probability and gradient calculations and\nbecause it reduces the size of the expression tree required for\ngradient calculations.\n\nThe first optimization vectorizes the for-loop over \\code{D} as\n%\n\n\\begin{stancode}\n  mu ~ normal(0, 100);\n  for (l in 1:L)\n    beta[l] ~ normal(mu, sigma);\n\\end{stancode}\n%\nThe declaration of \\code{beta} as an array of vectors means that the\nexpression \\code{beta[l]} denotes a vector.  Although \\code{beta}\ncould have been declared as a matrix, an array of vectors (or a\ntwo-dimensional array) is more efficient for accessing rows; see\n\\refsection{indexingefficiency} for more information on the efficiency\ntradeoffs among arrays, vectors, and matrices.\n\nThis model can be further sped up and at the same time made more\narithmetically stable by replacing the application of inverse-logit\ninside the Bernoulli distribution with the logit-parameterized\nBernoulli,\n%\n\n\\begin{stancode}\n  for (n in 1:N)\n    y[n] ~ bernoulli_logit(x[n] * beta[ll[n]]);\n\\end{stancode}\n%\nSee \\refsection{bernoulli-logit-distribution} for a definition of\n\\code{bernoulli\\_logit}.\n\nUnlike in R or BUGS, loops, array access and assignments are fast in\nStan because they are translated directly to \\Cpp.  In most cases, the\ncost of allocating and assigning to a container is more than made up\nfor by the increased efficiency due to vectorizing the log probability\nand gradient calculations.  Thus the following version is faster than\nthe original formulation as a loop over a sampling statement.\n%\n\n\\begin{stancode}\n  {\n    vector[N] x_beta_ll;\n    for (n in 1:N)\n      x_beta_ll[n] = x[n] * beta[ll[n]];\n    y ~ bernoulli_logit(x_beta_ll);\n  }\n\\end{stancode}\n%\nThe brackets introduce a new scope for the local variable\n\\code{x\\_beta\\_ll}; alternatively, the variable may be declared at the\ntop of the model block.\n\nIn some cases, such as the above, the local variable assignment leads\nto models that are less readable.  The recommended practice in such\ncases is to first develop and debug the more transparent version of\nthe model and only work on optimizations when the simpler formulation\nhas been debugged.\n\n\n\\section{Hierarchical Priors}\\label{hierarchical-priors.section}\n\nPriors on priors, also known as ``hyperpriors,'' should be treated the\nsame way as priors on lower-level parameters in that as much prior\ninformation as is available should be brought to bear.  Because\nhyperpriors often apply to only a handful of lower-level parameters,\ncare must be taken to ensure the posterior is both proper and not\noverly sensitive either statistically or computationally to wide tails\nin the priors.\n\n\\subsection{Boundary-Avoiding Priors for MLE in Hierarchical\nModels}\\label{bound-avoid-priors.subsection}\n\nThe fundamental problem with maximum likelihood estimation (MLE) in\nthe hierarchical model setting is that as the hierarchical variance\ndrops and the values cluster around the hierarchical mean, the overall\ndensity grows without bound.  As an illustration, consider a simple\nhierarchical linear regression (with fixed prior mean) of $y_n \\in\n\\reals$ on $x_n \\in \\reals^K$, formulated as\n%\n\\begin{eqnarray*}\ny_n & \\sim & \\distro{Normal}(x_n \\beta, \\sigma)\n\\\\[3pt]\n\\beta_k & \\sim & \\distro{Normal}(0,\\tau)\n\\\\[3pt]\n\\tau & \\sim & \\distro{Cauchy}(0,2.5)\n\\end{eqnarray*}\n%\nIn this case, as $\\tau \\rightarrow 0$ and $\\beta_k \\rightarrow 0$, the\nposterior density\n\\[\np(\\beta,\\tau,\\sigma|y,x) \\propto p(y|x,\\beta,\\tau,\\sigma)\n\\]\ngrows without bound.  There is a plot of a Neal's funnel density in\n\\reffigure{funnel}, which has similar behavior.\n\nThere is obviously no MLE estimate for $\\beta,\\tau,\\sigma$ in such a\ncase, and therefore the model must be modified if posterior modes are\nto be used for inference.  The approach recommended by\n\\cite{ChungEtAl:2013} is to use a gamma distribution as a prior, such\nas\n%\n\\[\n\\sigma \\sim \\distro{Gamma}(2, 1/A),\n\\]\n%\nfor a reasonably large value of $A$, such as $A = 10$.\n\n\n\\section{Item-Response Theory Models}\\label{item-response-models.section}\n\nItem-response theory (IRT) models the situation in which a number of\nstudents each answer one or more of a group of test questions.  The\nmodel is based on parameters for the ability of the students, the\ndifficulty of the questions, and in more articulated models, the\ndiscriminativeness of the questions and the probability of guessing\ncorrectly; see \\citep[pps.~314--320]{GelmanHill:2007} for a textbook\nintroduction to hierarchical IRT models and \\citep{Curtis:2010} for\nencodings of a range of IRT models in BUGS.\n\n\n\\subsection{Data Declaration with Missingness}\n\nThe data provided for an IRT model may be declared as follows\nto account for the fact that not every student is required to answer\nevery question.\n%\n\n\\begin{stancode}\ndata {\n  int<lower=1> J;              // number of students\n  int<lower=1> K;              // number of questions\n  int<lower=1> N;              // number of observations\n  int<lower=1,upper=J> jj[N];  // student for observation n\n  int<lower=1,upper=K> kk[N];  // question for observation n\n  int<lower=0,upper=1> y[N];   // correctness for observation n\n}\n\\end{stancode}\n%\nThis declares a total of \\code{N} student-question pairs in the data\nset, where each \\code{n} in \\code{1:N} indexes a binary observation\n\\code{y[n]} of the correctness of the answer of student \\code{jj[n]}\non question \\code{kk[n]}.\n\nThe prior hyperparameters will be hard coded in the rest of this\nsection for simplicity, though they could be coded as data in\nStan for more flexibility.\n\n\\subsection{1PL (Rasch) Model}\n\nThe 1PL item-response model, also known as the Rasch model, has one\nparameter (1P) for questions and uses the logistic link function (L).%\n%\n\n\nThe model parameters are declared as follows.\n%\n\n\\begin{stancode}\nparameters {\n  real delta;         // mean student ability\n  real alpha[J];      // ability of student j - mean ability\n  real beta[K];       // difficulty of question k\n}\n\\end{stancode}\n%\nThe parameter \\code{alpha[j]} is the ability coefficient for student\n\\code{j} and \\code{beta[k]} is the difficulty coefficient for question\n\\code{k}.  The non-standard parameterization used here also includes\nan intercept term \\code{delta}, which represents the average student's\nresponse to the average question.%\n%\n\\footnote{\\citep{GelmanHill:2007} treat the $\\delta$ term equivalently\n  as the location parameter in the distribution of student abilities.}\n%\nThe model itself is as follows.\n%\n\n\\begin{stancode}\nmodel {\n  alpha ~ normal(0, 1);         // informative true prior\n  beta ~ normal(0, 1);          // informative true prior\n  delta ~ normal(0.75, 1);      // informative true prior\n  for (n in 1:N)\n    y[n] ~ bernoulli_logit(alpha[jj[n]] - beta[kk[n]] + delta);\n}\n\\end{stancode}\n%\nThis model uses the logit-parameterized Bernoulli distribution, where\n\\[\n\\code{bernoulli\\_logit}(y|\\alpha) =\n\\code{bernoulli}(y|\\mbox{logit}^{-1}(\\alpha)).\n\\]\n%\nThe key to understanding it is the term inside the\n\\code{bernoulli\\_logit} distribution, from which it follows that\n\\[\n\\mbox{Pr}[y_n = 1] = \\mbox{logit}^{-1}(\\alpha_{jj[n]} - \\beta_{kk[n]}\n+ \\delta).\n\\]\n%\nThe model suffers from additive identifiability issues without the\npriors.  For example, adding a term $\\xi$ to each $\\alpha_j$ and\n$\\beta_k$ results in the same predictions.  The use of priors for\n$\\alpha$ and $\\beta$ located at 0 identifies the parameters; see\n\\citep{GelmanHill:2007} for a discussion of identifiability issues and\nalternative approaches to identification.\n\nFor testing purposes, the IRT 1PL model distributed with Stan uses\ninformative priors that match the actual data generation process used\nto simulate the data in R (the simulation code is supplied in the same\ndirectory as the models).  This is unrealistic for most practical\napplications, but allows Stan's inferences to be validated.  A simple\nsensitivity analysis with fatter priors shows that the posterior is\nfairly sensitive to the prior even with 400 students and 100 questions\nand only 25\\% missingness at random.  For real applications, the\npriors should be fit hierarchically along with the other parameters,\nas described in the next section.\n\n\n\\subsection{Multilevel 2PL Model}\n\nThe simple 1PL model described in the previous section is generalized\nin this section with the addition of a discrimination parameter to\nmodel how noisy a question is and by adding multilevel priors for the\nquestion difficulty and discrimination parameters.  The model\nparameters are declared as follows.\n%\n\n\\begin{stancode}\nparameters {\n  real mu_beta;                // mean question difficulty\n  real alpha[J];               // ability for j - mean\n  real beta[K];                // difficulty for k\n  real<lower=0> gamma[K];      // discrimination of k\n  real<lower=0> sigma_beta;    // scale of difficulties\n  real<lower=0> sigma_gamma;   // scale of log discrimination\n}\n\\end{stancode}\n%\nThe parameters should be clearer after the model definition.\n%\n\\begin{stancode}\nmodel {\n  alpha ~ normal(0, 1);\n  beta ~ normal(0, sigma_beta);\n  gamma ~ lognormal(0, sigma_gamma);\n  mu_beta ~ cauchy(0, 5);\n  sigma_beta ~ cauchy(0, 5);\n  sigma_gamma ~ cauchy(0, 5);\n  for (n in 1:N)\n    y[n] ~ bernoulli_logit(gamma[kk[n]]\n                           * (alpha[jj[n]] - (beta[kk[n]] + mu_beta)));\n}\n\\end{stancode}\n%\nThis is similar to the 1PL model, with the additional parameter\n\\code{gamma[k]} modeling how discriminative question \\code{k} is.  If\n\\code{gamma[k]} is greater than 1, responses are more attenuated with\nless chance of getting a question right at random.  The parameter\n\\code{gamma[k]} is constrained to be positive, which prohibits there\nbeing questions that are easier for students of lesser ability;  such\nquestions are not unheard of, but they tend to be eliminated from most\ntesting situations where an IRT model would be applied.\n\nThe model is parameterized here with student abilities \\code{alpha}\nbeing given a unit normal prior.  This is to identify both the scale\nand the location of the parameters, both of which would be\nunidentified otherwise; see \\refchapter{problematic-posteriors} for\nfurther discussion of identifiability. The difficulty and\ndiscrimination parameters \\code{beta} and \\code{gamma} then have\nvarying scales given hierarchically in this model.  They could also be\ngiven weakly informative non-hierarchical priors, such as\n%\n\\begin{stancode}\n  beta ~ normal(0, 5);\n  gamma ~ lognormal(0, 2);\n\\end{stancode}\n%\nThe point is that the \\code{alpha} determines the scale and location\nand \\code{beta} and \\code{gamma} are allowed to float.\n\nThe \\code{beta} parameter is here given a non-centered\nparameterization, with parameter \\code{mu\\_beta} serving as the mean\n\\code{beta} location. An alternative would've been to take:\n%\n\\begin{stancode}\n  beta ~ normal(mu_beta, sigma_beta);\n\\end{stancode}\n%\nand\n%\n\\begin{stancode}\n  y[n] ~ bernoulli_logit(gamma[kk[n]] * (alpha[jj[n]] - beta[kk[n]]));\n\\end{stancode}\n%\nNon-centered parameterizations tend to be more efficient in\nhierarchical models; see \\refsection{reparameterization} for more\ninformation on non-centered reparameterizations.\n\nThe intercept term \\code{mu\\_beta} can't itself be modeled\nhierarchically, so it is given a weakly informative\n$\\distro{Cauchy}(0,5)$ prior.  Similarly, the scale terms,\n\\code{sigma\\_beta}, and \\code{sigma\\_gamma}, are given half-Cauchy\npriors.  As mentioned earlier, the scale and location for \\code{alpha}\nare fixed to ensure identifiability.  The truncation in the\nhalf-Cauchy prior is implicit; explicit truncation is not necessary\nbecause the log probability need only be calculated up to a proportion\nand the scale variables are constrained to $(0,\\infty)$ by their\ndeclarations.\n\n\n\n\\section{Priors for Identifiability}\\label{priors-for-identification.section}\n\n\\subsection{Location and Scale Invariance}\n\nOne application of (hierarchical) priors is to identify the scale\nand/or location of a group of parameters. For example, in the IRT\nmodels discussed in the previous section, there is both a location and\nscale non-identifiability.  With uniform priors, the posteriors will\nfloat in terms of both scale and location.  See\n\\refsection{collinearity} for a simple example of the problems this\nposes for estimation.\n\nThe non-identifiability is resolved by providing a unit normal (i.e.,\n$\\distro{Normal}(0,1)$) prior on one group of coefficients, such as\nthe student abilities.  With a unit normal prior on the student\nabilities, the IRT model is identified in that the posterior will\nproduce a group of estimates for student ability parameters that have\na sample mean of close to zero and a sample variance of close to one.\nThe difficulty and discrimination parameters for the questions should\nthen be given a diffuse, or ideally a hierarchical prior, which will\nidentify these parameters by scaling and locating relative to the\nstudent ability parameters.\n\n\\subsection{Collinearity}\n\nAnother case in which priors can help provide identifiability is in\nthe case of collinearity in a linear regression.  In linear\nregression, if two predictors are collinear (i.e, one is a linear\nfunction of the other), then their coefficients will have a\ncorrelation of 1 (or -1) in the posterior.  This leads to\nnon-identifiability.  By placing normal priors on the coefficients,\nthe maximum likelihood solution of two duplicated predictors (trivially\ncollinear) will be half the value than would be obtained by only\nincluding one.\n\n\\subsection{Separability}\n\nIn a logistic regression, if a predictor is positive in cases of 1\noutcomes and negative in cases of 0 outcomes, then the maximum\nlikelihood estimate for the coefficient for that predictor diverges to\ninfinity.  This divergence can be controlled by providing a prior for\nthe coefficient, which will ``shrink'' the estimate back toward zero\nand thus identify the model in the posterior.\n\nSimilar problems arise for sampling with improper flat priors.  The\nsampler will try to draw very large values.  By providing a prior,\nthe posterior will be concentrated around finite values, leading to\nwell-behaved sampling.\n\n\n\n\\section{Multivariate Priors for Hierarchical Models}\\label{multivariate-hierarchical-priors.section}\n\nIn hierarchical regression models (and other situations), several\nindividual-level variables may be assigned hierarchical priors.  For\nexample, a model with multiple varying intercepts and slopes within\nmight assign them a multivariate prior.\n\nAs an example, the individuals might be people and the outcome income,\nwith predictors such as education level and age, and the groups might be states\nor other geographic divisions.  The effect of education level and age\nas well as an intercept might be allowed to vary by state.\nFurthermore, there might be state-level predictors, such as average\nstate income and unemployment level.\n\n\\subsection{Multivariate Regression Example}\n\n\\cite[Chapter 13, Chapter 17]{GelmanHill:2007} discuss a hierarchical\nmodel with $N$ individuals organized into $J$ groups.  Each individual\nhas a predictor row vector $x_n$ of size $K$; to unify the notation, they\nassume that $x_{n,1} = 1$ is a fixed ``intercept'' predictor.  To\nencode group membership, they assume individual $n$ belongs to group\n$jj[n] \\in 1{:}J$.  Each individual $n$ also has an observed outcome\n$y_n$ taking on real values.\n\n\\subsubsection{Likelihood}\n\nThe model is a linear regression with slope and intercept coefficients\nvarying by group, so that $\\beta_j$ is the coefficient $K$-vector for\ngroup $j$.  The likelihood function for individual $n$ is then just\n%\n\\[\ny_n \\sim \\distro{Normal}(x_n \\, \\beta_{jj[n]}, \\, \\sigma)\n\\mbox{ for } n \\in 1{:}N.\n\\]\n%\n\n\\subsubsection{Coefficient Prior}\n\nGelman and Hill model the coefficient vectors $\\beta_j$ as being drawn\nfrom a multivariate distribution with mean vector $\\mu$ and\ncovariance matrix $\\Sigma$,%\n%\n\\[\n\\beta_j \\sim \\distro{MultiNormal}(\\mu, \\, \\Sigma)\n\\mbox{ for } j \\in 1{:}J.\n\\]\n%\nBelow, we discuss the full model of Gelman and Hill, which uses\ngroup-level predictors to model $\\mu$; for now, we assume $\\mu$ is a\nsimple vector parameter.\n\n\\subsubsection{Hyperpriors}\n\nFor hierarchical modeling, the group-level mean vector $\\mu$ and\ncovariance matrix $\\Sigma$ must themselves be given priors.  The\ngroup-level mean vector can be given a reasonable weakly-informative\nprior for independent coefficients, such as\n%\n\\[\n\\mu_j \\sim \\distro{Normal}(0,5).\n\\]\nOf course, if more is known about the expected coefficient values\n$\\beta_{j, k}$, this information can be incorporated into the prior for\n$\\mu_k$.\n\nFor the prior on the covariance matrix, Gelman and Hill suggest using\na scaled inverse Wishart.  That choice was motivated primarily by\nconvenience as it is conjugate to the multivariate likelihood function\nand thus simplifies Gibbs sampling.\n\nIn Stan, there is no restriction to conjugacy for multivariate priors,\nand we in fact recommend a slightly different approach.  Like Gelman\nand Hill, we decompose our prior into a scale and a matrix, but are\nable to do so in a more natural way based on the actual variable\nscales and a correlation matrix.  Specifically, we define\n\\[\n\\Sigma = \\mbox{diag\\_matrix}(\\tau) \\ \\Omega \\ \\mbox{diag\\_matrix}(\\tau),\n\\]\nwhere $\\Omega$ is a correlation matrix and $\\tau$ is the vector of\ncoefficient scales.   This mapping from scale vector $\\tau$ and\ncorrelation matrix $\\Omega$ can be inverted, using\n\\[\n\\tau_k = \\sqrt{\\, \\Sigma_{k,k}}\n\\]\nand\n\\[\n\\Omega_{i, j} = \\frac{\\Sigma_{i, j}}{\\tau_i \\, \\tau_j}.\n\\]\n\nThe components of the scale vector $\\tau$ can be given any reasonable\nprior for scales, but we recommend something weakly informative like a\nhalf-Cauchy distribution with a small scale, such as\n\\[\n\\tau_k \\sim \\distro{Cauchy}(0, 2.5)\n\\mbox{ for } k \\in 1{:}K \\mbox{ constrained by } \\tau_k > 0.\n\\]\nAs for the prior means, if there is information about the scale of\nvariation of coefficients across groups, it should be incorporated\ninto the prior for $\\tau$.  For large numbers of exchangeable\ncoefficients, the components of $\\tau$ itself (perhaps excluding the\nintercept) may themselves be given a hierarchical prior.\n\nOur final recommendation is to give the correlation matrix $\\Omega$ an\nLKJ prior with shape $\\nu \\geq 1$,\n\\[\n\\Omega \\sim \\distro{LKJCorr}(\\nu).\n\\]\nThe LKJ correlation distribution is defined in\n\\refsection{lkj-correlation}, but the basic idea for modeling is that\nas $\\nu$ increases, the prior increasingly concentrates around the\nunit correlation matrix (i.e., favors less correlation among the\ncomponents of $\\beta_{j}$).  At $\\nu = 1$, the LKJ correlation\ndistribution reduces to the identity distribution over correlation\nmatrices.  The LKJ prior may thus be used to control the expected\namount of correlation among the parameters $\\beta_j$.\n\n\\subsubsection{Group-Level Predictors for Prior Mean}\n\nTo complete Gelman and Hill's model, suppose each group $j \\in 1{:}J$\nis supplied with an $L$-dimensional row-vector of group-level\npredictors $u_j$.  The prior mean for the $\\beta_j$ can then itself be\nmodeled as a regression, using an $L$-dimensional coefficient vector\n$\\gamma$.  The prior for the group-level coefficients then becomes\n\\[\n\\beta_j \\sim \\distro{MultiNormal}(u_j \\, \\gamma, \\Sigma)\n\\]\n\nThe group-level coefficients $\\gamma$ may themselves be given\nindependent weakly informative priors, such as\n\\[\n\\gamma_l \\sim \\distro{Normal}(0,5).\n\\]\nAs usual, information about the group-level means should be\nincorporated into this prior.\n\n\n\\subsubsection{Coding the Model in Stan}\n\nThe Stan code for the full hierarchical model with multivariate priors\non the group-level coefficients and group-level prior means follows\nits definition.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N;              // num individuals\n  int<lower=1> K;              // num ind predictors\n  int<lower=1> J;              // num groups\n  int<lower=1> L;              // num group predictors\n  int<lower=1,upper=J> jj[N];  // group for individual\n  matrix[N, K] x;               // individual predictors\n  row_vector[L] u[J];          // group predictors\n  vector[N] y;                 // outcomes\n}\nparameters {\n  corr_matrix[K] Omega;        // prior correlation\n  vector<lower=0>[K] tau;      // prior scale\n  matrix[L, K] gamma;           // group coeffs\n  vector[K] beta[J];           // indiv coeffs by group\n  real<lower=0> sigma;         // prediction error scale\n}\nmodel {\n  tau ~ cauchy(0, 2.5);\n  Omega ~ lkj_corr(2);\n  to_vector(gamma) ~ normal(0, 5);\n  {\n    row_vector[K] u_gamma[J];\n    for (j in 1:J)\n      u_gamma[j] = u[j] * gamma;\n    beta ~ multi_normal(u_gamma, quad_form_diag(Omega, tau));\n  }\n  for (n in 1:N)\n    y[n] ~ normal(x[n] * beta[jj[n]], sigma);\n}\n\\end{stancode}\n%\nThe hyperprior covariance matrix is defined implicitly through the\na quadratic form in the code\nbecause the correlation matrix \\code{Omega} and scale vector\n\\code{tau} are more natural to inspect in the output; to output\n\\code{Sigma}, define it as a transformed parameter.  The function\n\\code{quad\\_form\\_diag} is defined so that\n\\code{quad\\_form\\_diag(Sigma,~tau)} is equivalent to\n\\code{diag\\_matrix(tau) * Sigma * diag\\_matrix(tau)}, where\n\\code{diag\\_matrix(tau)} returns the matrix with \\code{tau} on the\ndiagonal and zeroes off diagonal; the version using\n\\code{quad\\_form\\_diag} should be faster.  See\n\\refsection{matrix-arithmetic-operators} for more information on\nspecialized matrix operations.\n\n\\subsubsection{Optimization through Vectorization}\n\nThe code in the Stan program above can be sped up dramatically by replacing:\n%\n\\begin{stancode}\n  for (n in 1:N)\n    y[n] ~ normal(x[n] * beta[jj[n]], sigma);\n\\end{stancode}\n%\nwith the vectorized form:\n%\n\\begin{stancode}\n  {\n    vector[N] x_beta_jj;\n    for (n in 1:N)\n      x_beta_jj[n] = x[n] * beta[jj[n]];\n    y ~ normal(x_beta_jj, sigma);\n  }\n\\end{stancode}\n%\nThe outer brackets create a local scope in which to define the\nvariable \\code{x\\_beta\\_jj}, which is then filled in a loop and used\nto define a vectorized sampling statement.  The reason this is such a\nbig win is that it allows us to take the log of sigma only once and it\ngreatly reduces the size of the resulting expression graph by packing\nall of the work into a single density function.\n\nAlthough it is tempting to redeclare \\code{beta} and include a revised\nmodel block sampling statement,\n%\n\\begin{stancode}\nparameters {\n  matrix[J, K] beta;\n...\nmodel {\n  y ~ normal(rows_dot_product(x, beta[jj]), sigma);\n  ...\n\\end{stancode}\n%\nthis fails because it breaks the vectorization of sampling for\n\\code{beta},%\n%\n\\footnote{Thanks to Mike Lawrence for pointing this out in the GitHub\n  issue for the manual.}\n%\n\\begin{stancode}\n  beta ~ multi_normal(...);\n\\end{stancode}\n%\nwhich requires \\code{beta} to be an array of vectors.  Both\nvectorizations are important, so the best solution is to just use the\nloop above, because \\code{rows\\_dot\\_product} cannot do much\noptimization in and of itself because there are no shared computations.\n\nThe code in the Stan program above also builds up an array of vectors\nfor the outcomes and for the multivariate normal, which provides a\nvery significant speedup by reducing the number of linear systems that\nneed to be solved and differentiated.\n%\n\\begin{stancode}\n  {\n    matrix[K, K] Sigma_beta;\n    Sigma_beta = quad_form_diag(Omega, tau);\n    for (j in 1:J)\n      beta[j] ~ multi_normal((u[j] * gamma)', Sigma_beta);\n  }\n\\end{stancode}\n%\nIn this example, the covariance matrix \\code{Sigma\\_beta} is defined\nas a local variable so as not to have to repeat the quadratic form\ncomputation $J$ times.  This vectorization can be combined with the\nCholesky-factor optimization in the next section.\n\n\\subsubsection{Optimization through Cholesky Factorization}\n\nThe multivariate normal density and LKJ prior on correlation matrices\nboth require their matrix parameters to be factored.  Vectorizing, as\nin the previous section, ensures this is only done once for each\ndensity.  An even better solution, both in terms of efficiency and\nnumerical stability, is to parameterize the model directly in terms of\nCholesky factors of correlation matrices using the multivariate\nversion of the non-centered parameterization.  For the model in the\nprevious section, the program fragment to replace the full matrix\nprior with an equivalent Cholesky factorized prior is as follows.\n%\n\\begin{stancode}\ndata {\n  matrix[J, L] u;\n  ...\nparameters {\n  matrix[K, J] z;\n  cholesky_factor_corr[K] L_Omega;\n  ...\ntransformed parameters {\n  matrix[J, K] beta;\n  beta = u * gamma + (diag_pre_multiply(tau,L_Omega) * z)';\n}\nmodel {\n  to_vector(z) ~ normal(0, 1);\n  L_Omega ~ lkj_corr_cholesky(2);\n  ...\n\\end{stancode}\n%\nThe data variable \\code{u} was originally an array of vectors, which\nis efficient for access; here it is redeclared as a matrix in order to\nuse it in matrix arithmetic.  The new parameter \\code{L\\_Omega} is\nthe Cholesky factor of the original correlation matrix \\code{Omega},\nso that\n%\n\\begin{stancode}\nOmega = L_Omega * L_Omega'\n\\end{stancode}\n%\nThe prior scale vector \\code{tau} is unchanged, and furthermore,\nPre-multiplying the Cholesky factor by the scale produces the Cholesky\nfactor of the final covariance matrix,\n%\n\\begin{stancode}\n  Sigma_beta\n  = quad_form_diag(Omega, tau)\n  = diag_pre_multiply(tau, L_Omega) * diag_pre_multiply(tau, L_Omega)'\n\\end{stancode}\n%\nwhere the diagonal pre-multiply compound operation is defined by\n%\n\\begin{stancode}\ndiag_pre_multiply(a, b) = diag_matrix(a) * b\n\\end{stancode}\n%\nThe new variable \\code{z} is declared as a matrix, the entries of\nwhich are given independent unit normal priors; the \\code{to\\_vector}\noperation turns the matrix into a vector so that it can be used as a\nvectorized argument to the univariate normal density.  Multiplying the\nCholesky factor of the covariance matrix by \\code{z} and adding the\nmean \\code{(u\\,*\\,gamma)'} produces a \\code{beta} distributed as in\nthe original model.\n\nOmitting the data declarations, which are the same as before, the\noptimized model is as follows.\n%\n\\begin{stancode}\nparameters {\n  matrix[K, J] z;\n  cholesky_factor_corr[K] L_Omega;\n  vector<lower=0,upper=pi()/2>[K] tau_unif;\n  matrix[L, K] gamma;                         // group coeffs\n  real<lower=0> sigma;                       // prediction error scale\n}\ntransformed parameters {\n  matrix[J, K] beta;\n  vector<lower=0>[K] tau;     // prior scale\n  for (k in 1:K) tau[k] = 2.5 * tan(tau_unif[k]);\n  beta = u * gamma + (diag_pre_multiply(tau,L_Omega) * z)';\n}\nmodel {\n  to_vector(z) ~ normal(0, 1);\n  L_Omega ~ lkj_corr_cholesky(2);\n  to_vector(gamma) ~ normal(0, 5);\n  y ~ normal(rows_dot_product(beta[jj] , x), sigma);\n}\n\\end{stancode}\n\nThis model also reparameterizes the prior scale \\code{tau} to avoid potential problems with the heavy tails of the Cauchy distribution. The statement \\code{tau\\_unif ~ uniform(0,pi()/2)} can be omitted from the model block because stan increments the log posterior for parameters with uniform priors without it.\n\n% \\begin{quote}\n% \\begin{stancode}\n% parameters {\n%   vector[3] mu;\n%   matrix[3, M] z;\n%   cholesky_factor_corr[3] L_Sigma;\n%   vector<lower=0>[3] sigma_Sigma;\n%   ...\n% transformed parameters {\n%   matrix[M,3] alpha;\n%   alpha\n%     = transpose(rep_matrix(mu, M)\n%                  + diag_pre_multiply(sigma_Sigma,L_Sigma) * z);\n%   ...\n% model {\n%   to_vector(z) ~ normal(0, 1);\n%   gamma ~ normal(0, 5);\n%   sigma_Sigma ~ cauchy(0, 2.5);\n%   L_Sigma ~ lkj_corr_cholesky(3);\n%   ...\n% \\end{stancode}\n% \\end{quote}\n% %\n% Taken together, this Stan program amounts to\n% %\n% \\begin{eqnarray*}\n% \\sigma & \\sim & \\mbox{Cauchy}(0, 2.5)\n% \\\\[3pt]\n% \\Omega & \\sim & \\mbox{Lkj}(3)\n% \\\\[3pt]\n% \\Sigma & = & \\mbox{diag}(\\sigma) \\times \\Omega \\times \\mbox{diag}(\\sigma)\n% \\\\[3pt]\n% \\alpha_m & \\sim & \\mbox{MultiNormal}(\\mu, \\Sigma)\n% \\end{eqnarray*}\n\n\n\n\\section{Prediction, Forecasting, and Backcasting}\n\nStan models can be used for ``predicting'' the values of arbitrary\nmodel unknowns.  When predictions are about the future, they're called\n``forecasts;'' when they are predictions about the past, as in climate\nreconstruction or cosmology, they are sometimes called ``backcasts''\n(or ``aftcasts'' or ``hindcasts'' or ``antecasts,'' depending on the\nauthor's feelings about the opposite of ``fore'').\n\n\\subsection{Programming Predictions}\n\nAs a simple example, the following linear regression provides the same\nsetup for estimating the coefficients \\code{beta} as in our very first\nexample above, using \\code{y} for the \\code{N} observations and\n\\code{x} for the \\code{N} predictor vectors.  The model parameters and\nmodel for observations are exactly the same as before.\n\nTo make predictions, we need to be given the number of predictions,\n\\code{N\\_new}, and their predictor matrix, \\code{x\\_new}.  The\npredictions themselves are modeled as a parameter \\code{y\\_new}.  The\nmodel statement for the predictions is exactly the same as for the\nobservations, with the new outcome vector \\code{y\\_new} and prediction\nmatrix \\code{x\\_new}.\n%\n\\begin{stancode}\ndata {\n  int<lower=1> K;\n  int<lower=0> N;\n  matrix[N, K] x;\n  vector[N] y;\n\n  int<lower=0> N_new;\n  matrix[N_new, K] x_new;\n}\nparameters {\n  vector[K] beta;\n  real<lower=0> sigma;\n\n  vector[N_new] y_new;                  // predictions\n}\nmodel {\n  y ~ normal(x * beta, sigma);          // observed model\n\n  y_new ~ normal(x_new * beta, sigma);  // prediction model\n}\n\\end{stancode}\n\n\n\\subsection{Predictions as Generated Quantities}\n\nWhere possible, the most efficient way to generate predictions is to\nuse the generated quantities block.  This provides proper Monte Carlo\n(not Markov chain Monte Carlo) inference, which can have a much higher\neffective sample size per iteration.\n%\n\\begin{stancode}\n...data as above...\n\nparameters {\n  vector[K] beta;\n  real<lower=0> sigma;\n}\nmodel {\n  y ~ normal(x * beta, sigma);\n}\ngenerated quantities {\n  vector[N_new] y_new;\n  for (n in 1:N_new)\n    y_new[n] = normal_rng(x_new[n] * beta, sigma);\n}\n\\end{stancode}\n%\nNow the data is just as before, but the parameter \\code{y\\_new} is now\ndeclared as a generated quantity, and the prediction model is\nremoved from the model and replaced by a pseudo-random draw from a\nnormal distribution.\n\n\\subsubsection{Overflow in Generated Quantities}\n\nIt is possible for values to overflow or underflow in generated\nquantities.  The problem is that if the result is NaN, then any\nconstraints placed on the variables will be violated.  It is possible\nto check a value assigned by an RNG and reject it if it overflows, but\nthis is both inefficient and leads to biased posterior estimates.\nInstead, the conditions causing overflow, such as trying to generate a\nnegative binomial random variate with a mean of $2^{31}$.  These must\nbe intercepted and dealt with, typically be reparameterizing or\nreimplementing the random number generator using real values rather\nthan integers, which are upper-bounded by $2^{31} - 1$ in Stan.\n\n\n\\section{Multivariate Outcomes}\n\nMost regressions are set up to model univariate observations (be they\nscalar, boolean, categorical, ordinal, or count).  Even multinomial\nregressions are just repeated categorical regressions.  In contrast,\nthis section discusses regression when each observed value is\nmultivariate.  To relate multiple outcomes in a regression setting,\ntheir error terms are provided with covariance structure.\n\nThis section considers two cases, seemingly unrelated regressions for\ncontinuous multivariate quantities and multivariate probit regression\nfor boolean multivariate quantities.\n\n\\subsection{Seemingly Unrelated Regressions}\n\nThe first model considered is the ``seemingly unrelated'' regressions\n(SUR) of econometrics where several linear regressions share\npredictors and use a covariance error structure rather than\nindependent errors \\citep{Zellner:1962,Greene:2011}.\n\nThe model is easy to write down as a regression,\n%\n\\begin{eqnarray*}\n y_n & = & x_n \\, \\beta + \\epsilon_n\n\\\\[4pt]\n \\epsilon_n & \\sim & \\distro{MultiNormal}(0, \\Sigma)\n\\end{eqnarray*}\n%\nwhere $x_n$ is a $J$-row-vector of predictors ($x$ is an $(N \\times\nJ)$-matrix), $y_n$ is a $K$-vector of observations, $\\beta$ is a $(K\n\\times J)$-matrix of regression coefficients (vector $\\beta_k$ holds\ncoefficients for outcome $k$), and $\\Sigma$ is covariance matrix\ngoverning the error.  As usual, the intercept can be rolled into $x$\nas a column of ones.\n\nThe basic Stan code is straightforward (though see below for more\noptimized code for use with LKJ priors on correlation).\n%\n\\begin{stancode}\ndata {\n  int<lower=1> K;\n  int<lower=1> J;\n  int<lower=0> N;\n  vector[J] x[N];\n  vector[K] y[N];\n}\nparameters {\n  matrix[K, J] beta;\n  cov_matrix[K] Sigma;\n}\nmodel {\n  vector[K] mu[N];\n  for (n in 1:N)\n    mu[n] = beta * x[n];\n  y ~ multi_normal(mu, Sigma);\n}\n\\end{stancode}\n%\nFor efficiency, the multivariate normal is vectorized by precomputing\nthe array of mean vectors and sharing the same covariance matrix.\n\nFollowing the advice in \\refsection{multivariate-hierarchical-priors},\nwe will place a weakly informative normal prior on the regression\ncoefficients, an LKJ prior on the correlations and a half-Cauchy prior\non standard deviations.  The covariance structure is parameterized in\nterms of Cholesky factors for efficiency and arithmetic stability.\n%\n\\begin{stancode}\n...\nparameters {\n  matrix[K, J] beta;\n  cholesky_factor_corr[K] L_Omega;\n  vector<lower=0>[K] L_sigma;\n}\nmodel {\n  vector[K] mu[N];\n  matrix[K, K] L_Sigma;\n\n  for (n in 1:N)\n    mu[n] = beta * x[n];\n\n  L_Sigma = diag_pre_multiply(L_sigma, L_Omega);\n\n  to_vector(beta) ~ normal(0, 5);\n  L_Omega ~ lkj_corr_cholesky(4);\n  L_sigma ~ cauchy(0, 2.5);\n\n  y ~ multi_normal_cholesky(mu, L_Sigma);\n}\n\\end{stancode}\n%\nThe Cholesky factor of the covariance matrix is then reconstructed as\na local variable and used in the model by scaling the Cholesky factor\nof the correlation matrices. The regression coefficients get a prior\nall at once by converting the matrix \\code{beta} to a vector.\n\nIf required, the full correlation or covariance matrices may be\nreconstructed from their Cholesky factors in the generated quantities\nblock.\n\n\n\\subsection{Multivariate Probit Regression}\n\nThe multivariate probit model generates sequences of boolean variables\nby applying a step function to the output of a seemingly unrelated\nregression.\n\nThe observations $y_n$ are $D$-vectors of boolean values (coded 0 for\nfalse, 1 for true).  The values for the observations $y_n$ are based\non latent values $z_n$ drawn from a seemingly unrelated regression\nmodel (see the previous section),\n%\n\\begin{eqnarray*}\n z_n & = & x_n \\, \\beta + \\epsilon_n\n\\\\[4pt]\n \\epsilon_n & \\sim & \\distro{MultiNormal}(0, \\Sigma)\n\\end{eqnarray*}\n%\nThese are then put through the step function to produce a $K$-vector $z_n$\nof boolean values with elements defined by\n\\[\ny_{n, k} = \\mathrm{I}(z_{n, k} > 0),\n\\]\nwhere $\\mathrm{I}()$ is the indicator function taking the value 1 if its\nargument is true and 0 otherwise.\n\nUnlike in the seemingly unrelated regressions case, here the\ncovariance matrix $\\Sigma$ has unit standard deviations (i.e., it is a\ncorrelation matrix).  As with ordinary probit and logistic\nregressions, letting the scale vary causes the model (which is defined\nonly by a cutpoint at 0, not a scale) to be unidentified (see\n\\citep{Greene:2011}).\n\nMultivariate probit regression can be coded in Stan using the trick\nintroduced by \\cite{AlbertChib:1993}, where the underlying continuous\nvalue vectors $y_n$ are coded as truncated parameters.  The key to\ncoding the model in Stan is declaring the latent vector $z$ in two\nparts, based on whether the corresponding value of $y$ is 0 or 1.\nOtherwise, the model is identical to the seemingly unrelated\nregression model in the previous section.\n\nFirst, we introduce a sum function for two-dimensional arrays of\nintegers;  this is going to help us calculate how many total 1 values\nthere are in $y$.\n%\n\\begin{stancode}\nfunctions {\n  int sum(int[,] a) {\n    int s = 0;\n    for (i in 1:size(a))\n      s += sum(a[i]);\n    return s;\n  }\n}\n\\end{stancode}\n%\nThe function is trivial, but it's not a built-in for Stan and it's easier to\nunderstand the rest of the model if it's pulled into its own function\nso as not to create a distraction.\n\nThe data declaration block is much like for the seemingly unrelated\nregressions, but the observations \\code{y} are now integers\nconstrained to be 0 or 1.\n%\n\\begin{stancode}\ndata {\n  int<lower=1> K;\n  int<lower=1> D;\n  int<lower=0> N;\n  int<lower=0,upper=1> y[N,D];\n  vector[K] x[N];\n}\n\\end{stancode}\n\nAfter declaring the data, there is a rather involved transformed data\nblock whose sole purpose is to sort the data array \\code{y} into\npositive and negative components, keeping track of indexes so that\n\\code{z} can be easily reassembled in the transformed parameters\nblock.\n%\n\\begin{stancode}\ntransformed data {\n  int<lower=0> N_pos;\n  int<lower=1,upper=N> n_pos[sum(y)];\n  int<lower=1,upper=D> d_pos[size(n_pos)];\n  int<lower=0> N_neg;\n  int<lower=1,upper=N> n_neg[(N * D) - size(n_pos)];\n  int<lower=1,upper=D> d_neg[size(n_neg)];\n\n  N_pos = size(n_pos);\n  N_neg = size(n_neg);\n  {\n    int i;\n    int j;\n    i = 1;\n    j = 1;\n    for (n in 1:N) {\n      for (d in 1:D) {\n        if (y[n,d] == 1) {\n          n_pos[i] = n;\n          d_pos[i] = d;\n          i += 1;\n        } else {\n          n_neg[j] = n;\n          d_neg[j] = d;\n          j += 1;\n        }\n      }\n    }\n  }\n}\n\\end{stancode}\n%\nThe variables \\code{N\\_pos} and \\code{N\\_neg} are set to the number of\ntrue (1) and number of false (0) observations in \\code{y}.  The loop\nthen fills in the sequence of indexes for the positive and negative\nvalues in four arrays.\n\nThe parameters are declared as follows.\n%\n\\begin{stancode}\nparameters {\n  matrix[D, K] beta;\n  cholesky_factor_corr[D] L_Omega;\n  vector<lower=0>[N_pos] z_pos;\n  vector<upper=0>[N_neg] z_neg;\n}\n\\end{stancode}\n%\nThese include the regression coefficients \\code{beta} and the Cholesky\nfactor of the correlation matrix, \\code{L\\_Omega}.  This time there is\nno scaling because the covariance matrix has unit scale (i.e., it is a\ncorrelation matrix;  see above).\n\nThe critical part of the parameter declaration is that the latent real\nvalue $z$ is broken into positive-constrained and negative-constrained\ncomponents, whose size was conveniently calculated in the transformed\ndata block.  The transformed data block's real work was to allow the\ntransformed parameter block to reconstruct $z$.\n%\n\\begin{stancode}\ntransformed parameters {\n  vector[D] z[N];\n  for (n in 1:N_pos)\n    z[n_pos[n], d_pos[n]] = z_pos[n];\n  for (n in 1:N_neg)\n    z[n_neg[n], d_neg[n]] = z_neg[n];\n}\n\\end{stancode}\n\nAt this point, the model is simple, pretty much recreating the\nseemingly unrelated regression.\n%\n\\begin{stancode}\nmodel {\n  L_Omega ~ lkj_corr_cholesky(4);\n  to_vector(beta) ~ normal(0, 5);\n  {\n    vector[D] beta_x[N];\n    for (n in 1:N)\n      beta_x[n] = beta * x[n];\n    z ~ multi_normal_cholesky(beta_x, L_Omega);\n  }\n}\n\\end{stancode}\n%\nThis simple form of model is made possible by the Albert and\nChib-style constraints on \\code{z}.\n\nFinally, the correlation matrix itself can be put back together in the\ngenerated quantities block if desired.\n%\n\\begin{stancode}\ngenerated quantities {\n  corr_matrix[D] Omega;\n  Omega = multiply_lower_tri_self_transpose(L_Omega);\n}\n\\end{stancode}\n%\nOf course, the same could be done for the seemingly unrelated\nregressions in the previous section.\n\n\\section{Applications of Pseudorandom Number Generation}\n\nThe main application of pseudorandom number generator (PRNGs) is for\nposterior inference, including prediction and posterior predictive\nchecks.  They can also be used for pure data simulation, which is like\na posterior predictive check with no conditioning.  See\n\\refsection{distributions-prng} for a description of their syntax and\nthe scope of their usage.\n\n\\subsection{Prediction}\n\nConsider predicting unobserved outcomes using linear\nregression.  Given predictors $x_1, \\ldots, x_N$ and observed outcomes\n$y_1,\\ldots,y_N$, and assuming a standard linear regression with\nintercept $\\alpha$, slope $\\beta$, and error scale $\\sigma$, along with\nimproper uniform priors, the posterior over the parameters given $x$\nand $y$ is\n%\n\\[\np(\\alpha, \\beta, \\sigma \\, | \\, x, y)\n\\propto\n\\prod_{n=1}^N\n  \\distro{Normal}(y_n \\, | \\, \\alpha + \\beta x_n, \\sigma).\n\\]\n%\nFor this model, the posterior predictive inference for a new outcome\n$\\tilde{y}_m$ given a predictor $\\tilde{x}_m$, conditioned on the\nobserved data $x$ and $y$, is\n\\[\np(\\tilde{y}_n \\, | \\, \\tilde{x}_n, x, y)\n= \\int_{(\\alpha,\\beta,\\sigma)}\n  \\distro{Normal}(\\tilde{y}_n \\, | \\, \\alpha + \\beta \\tilde{x}_n, \\sigma)\n  \\times\n  p(\\alpha, \\beta, \\sigma \\, | \\, x, y)\n  \\\n  \\mathrm{d}(\\alpha,\\beta,\\sigma).\n\\]\n%\nTo code the posterior predictive inference in Stan, a standard linear\nregression is combined with a random number in the generated\nquantities block.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N;\n  vector[N] y;\n  vector[N] x;\n  int<lower=0> N_tilde;\n  vector[N_tilde] x_tilde;\n}\nparameters {\n  real alpha;\n  real beta;\n  real<lower=0> sigma;\n}\nmodel {\n  y ~ normal(alpha + beta * x, sigma);\n}\ngenerated quantities {\n  vector[N_tilde] y_tilde;\n  for (n in 1:N_tilde)\n    y_tilde[n] = normal_rng(alpha + beta * x_tilde[n], sigma);\n}\n\\end{stancode}\n%\nGiven observed predictors $x$ and outcomes $y$, \\code{y\\_tilde} will\nbe drawn according to $p(\\tilde{y} \\, | \\, \\tilde{x}, y, x)$.  This\nmeans that, for example, the posterior mean for \\code{y\\_tilde} is the\nestimate of the outcome that minimizes expected square error\n(conditioned on the data and model, of course).\n\n\\subsection{Posterior Predictive Checks}\n\nA good way to investigate the fit of a model to the data, a critical\nstep in Bayesian data analysis, is to generate simulated data\naccording to the parameters of the model.  This is carried out with\nexactly the same procedure as before, only the observed data\npredictors $x$ are used in place of new predictors $\\tilde{x}$ for\nunobserved outcomes.  If the model fits the data well, the predictions\nfor $\\tilde{y}$ based on $x$ should match the observed data $y$.\n\nTo code posterior predictive checks in Stan requires only a slight\nmodification of the prediction code to use $x$ and $N$ in place of\n$\\tilde{x}$ and $\\tilde{N}$,\n%\n\\begin{stancode}\ngenerated quantities {\n  vector[N] y_tilde;\n  for (n in 1:N)\n    y_tilde[n] = normal_rng(alpha + beta * x[n], sigma);\n}\n\\end{stancode}\n%\n\\cite{GelmanEtAl:2013} recommend choosing several posterior draws\n$\\tilde{y}^{(1)}, \\ldots, \\tilde{y}^{(M)}$ and plotting each of them\nalongside the data $y$ that was actually observed.  If the model fits\nwell, the simulated $\\tilde{y}$ will look like the actual data $y$.\n\n\n\n\n\\chapter{Time-Series Models}\\label{time-series.chapter}\n\n\\noindent\nTimes series data come arranged in temporal order.  This chapter\npresents two kinds of time series models, regression-like models such\nas autoregressive and moving average models, and hidden Markov models.\n\n\\refchapter{gaussian-processes} presents Gaussian processes, which may\nalso be used for time-series (and spatial) data.\n\n\n\\section{Autoregressive Models}\\label{autoregressive.section}\n\nA first-order autoregressive model (AR(1)) with normal noise takes\neach point $y_n$ in a sequence $y$ to be generated according to\n%\n\\[\ny_n \\sim \\distro{Normal}(\\alpha + \\beta y_{n-1}, \\sigma).\n\\]\n%\nThat is, the expected value of $y_n$ is $\\alpha + \\beta y_{n-1}$, with\nnoise scaled as $\\sigma$.\n\n\\subsection{AR(1) Models}\n\nWith improper flat priors on the regression coefficients for slope\n($\\beta$), intercept ($\\alpha$), and noise scale ($\\sigma$),\nthe Stan program for the AR(1) model is as follows.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N;\n  vector[N] y;\n}\nparameters {\n  real alpha;\n  real beta;\n  real<lower=0> sigma;\n}\nmodel {\n  for (n in 2:N)\n    y[n] ~ normal(alpha + beta * y[n-1], sigma);\n}\n\\end{stancode}\n%\nThe first observed data point, \\code{y[1]}, is not modeled here\nbecause there is nothing to condition on; instead, it acts to\ncondition \\code{y[2]}.  This model also uses an improper prior for\n\\code{sigma}, but there is no obstacle to adding an informative prior\nif information is available on the scale of the changes in \\code{y}\nover time, or a weakly informative prior to help guide inference if\nrough knowledge of the scale of \\code{y} is available.\n\n\\subsubsection{Slicing for Efficiency}\n\nAlthough perhaps a bit more difficult to read, a much more efficient\nway to write the above model is by slicing the vectors, with the model\nabove being replaced with the one-liner\n%\n\\begin{stancode}\nmodel {\n  y[2:N] ~ normal(alpha + beta * y[1:(N - 1)], sigma);\n}\n\\end{stancode}\n%\nThe left-hand side slicing operation pulls out the last $N-1$\nelements and the right-hand side version pulls out the first $N-1$.\n\n\n\n\\subsection{Extensions to the AR(1) Model}\n\nProper priors of a range of different families may be added for the\nregression coefficients and noise scale.  The normal noise model can\nbe changed to a Student-$t$ distribution or any other distribution\nwith unbounded support.  The model could also be made hierarchical if\nmultiple series of observations are available.\n\nTo enforce the estimation of a stationary AR(1) process, the slope\ncoefficient \\code{beta} may be constrained with bounds as follows.\n%\n\\begin{stancode}\nreal<lower=-1,upper=1> beta;\n\\end{stancode}\n%\nIn practice, such a constraint is not recommended.  If the data is not\nstationary, it is best to discover this while fitting the model.\nStationary parameter estimates can be encouraged with a prior favoring\nvalues of \\code{beta} near zero.\n\n\n\\subsection{AR(2) Models}\n\nExtending the order of the model is also straightforward.  For\nexample, an AR(2) model could be coded with the second-order\ncoefficient \\code{gamma} and the following model statement.\n%\n\\begin{stancode}\nfor (n in 3:N)\n  y[n] ~ normal(alpha + beta*y[n-1] + gamma*y[n-2], sigma);\n\\end{stancode}\n\n\n\\subsection{AR($K$) Models}\n\nA general model where the order is itself given as data can be coded\nby putting the coefficients in an array and computing the linear\npredictor in a loop.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> K;\n  int<lower=0> N;\n  real y[N];\n}\nparameters {\n  real alpha;\n  real beta[K];\n  real sigma;\n}\nmodel {\n  for (n in (K+1):N) {\n    real mu = alpha;\n    for (k in 1:K)\n      mu += beta[k] * y[n-k];\n    y[n] ~ normal(mu, sigma);\n  }\n}\n\\end{stancode}\n\n\\subsection{ARCH(1) Models}\n\nEconometric and financial time-series models usually assume\nheteroscedasticity (i.e., they allow the scale of the noise terms\ndefining the series to vary over time).\nThe simplest such model is the autoregressive conditional\nheteroscedasticity (ARCH) model \\citep{Engle:1982}.  Unlike the\nautoregressive model AR(1), which modeled the mean of the series as\nvarying over time but left the noise term fixed, the ARCH(1) model\ntakes the scale of the noise terms to vary over time but leaves the\nmean term fixed.  Of course, models could be defined where both the\nmean and scale vary over time; the econometrics literature presents a\nwide range of time-series modeling choices.\n\nThe ARCH(1) model is typically presented as the following sequence of\nequations, where $r_t$ is the observed return at time point $t$\nand $\\mu$, $\\alpha_0$, and $\\alpha_1$ are unknown regression coefficient parameters.\n%\n\\begin{eqnarray*}\nr_t & = & \\mu + a_t\n\\\\[2pt]\na_t & = & \\sigma_t \\epsilon_t\n\\\\[2pt]\n\\epsilon_t & \\sim & \\distro{Normal}(0,1)\n\\\\[2pt]\n\\sigma^2_t & = & \\alpha_0 + \\alpha_1 a_{t-1}^2\n\\end{eqnarray*}\n%\nIn order to ensure the noise terms $\\sigma^2_t$ are positive, the\nscale coefficients are constrained to be positive, $\\alpha_0, \\alpha_1\n> 0$.  To ensure stationarity of the time series, the slope is\nconstrained to to be less than one, $\\alpha_1 < 1$.%\n%\n\\footnote{In practice, it can be useful to remove the constraint to\n  test whether a non-stationary set of coefficients provides a better\n  fit to the data.  It can also be useful to add a trend term to the\n  model, because an unfitted trend will manifest as non-stationarity.}\n%\nThe ARCH(1) model may be coded directly in Stan as follows.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> T;   // number of time points\n  real r[T];        // return at time t\n}\nparameters {\n  real mu;                       // average return\n  real<lower=0> alpha0;          // noise intercept\n  real<lower=0,upper=1> alpha1;  // noise slope\n}\nmodel {\n  for (t in 2:T)\n    r[t] ~ normal(mu, sqrt(alpha0 + alpha1 * pow(r[t-1] - mu,2)));\n}\n\\end{stancode}\n%\nThe loop in the model is defined so that the return at time $t=1$ is\nnot modeled; the model in the next section shows how to model the\nreturn at $t=1$.  The model can be vectorized to be more efficient;\nthe model in the next section provides an example.\n\n\\section{Modeling Temporal Heteroscedasticity}\n\nA set of variables is homoscedastic if their variances are all the\nsame; the variables are heteroscedastic if they do not all have the\nsame variance.  Heteroscedastic time-series models allow the noise\nterm to vary over time.\n\n\\subsection{GARCH(1,1) Models}\n\nThe basic generalized autoregressive conditional heteroscedasticity\n(GARCH) model, GARCH(1,1), extends the ARCH(1) model by including the\nsquared previous difference in return from the mean at time $t-1$ as a\npredictor of volatility at time $t$, defining\n%\n\\[\n\\sigma^2_t = \\alpha_0 + \\alpha_1 a^2_{t-1} + \\beta_1 \\sigma^2_{t-1}.\n\\]\n%\nTo ensure the scale term is positive and the resulting time series\nstationary, the coefficients must all satisfy $\\alpha_0, \\alpha_1,\n\\beta_1 > 0$ and the slopes $\\alpha_1 + \\beta_1 < 1$.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> T;\n  real r[T];\n  real<lower=0> sigma1;\n}\nparameters {\n  real mu;\n  real<lower=0> alpha0;\n  real<lower=0,upper=1> alpha1;\n  real<lower=0,upper=(1-alpha1)> beta1;\n}\ntransformed parameters {\n  real<lower=0> sigma[T];\n  sigma[1] = sigma1;\n  for (t in 2:T)\n    sigma[t] = sqrt(alpha0\n                     + alpha1 * pow(r[t-1] - mu, 2)\n                     + beta1 * pow(sigma[t-1], 2));\n}\nmodel {\n  r ~ normal(mu, sigma);\n}\n\\end{stancode}\n%\nTo get the recursive definition of the volatility regression off the\nground, the data declaration includes a non-negative value\n\\code{sigma1} for the scale of the noise at $t = 1$.\n\nThe constraints are coded directly on the parameter declarations.\nThis declaration is order-specific in that the constraint on \\code{beta1}\ndepends on the value of \\code{alpha1}.\n\nA transformed parameter array of non-negative values \\code{sigma} is\nused to store the scale values at each time point.  The definition of\nthese values in the transformed parameters block is where the\nregression is now defined.  There is an intercept \\code{alpha0}, a\nslope \\code{alpha1} for the squared difference in return from the mean\nat the previous time, and a slope \\code{beta1} for the previous noise\nscale squared.  Finally, the whole regression is inside the\n\\code{sqrt} function because Stan requires scale (deviation) parameters (not\nvariance parameters) for the normal distribution.\n\nWith the regression in the transformed parameters block, the model\nreduces a single vectorized sampling statement.  Because \\code{r} and\n\\code{sigma} are of length \\code{T}, all of the data is modeled\ndirectly.\n\n\n\\section{Moving Average Models}\n\nA moving average model uses previous errors as predictors for future\noutcomes.  For a moving average model of order $Q$, $\\mbox{MA}(Q)$,\nthere is an overall mean parameter $\\mu$ and regression coefficients\n$\\theta_q$ for previous error terms.  With $\\epsilon_t$ being the\nnoise at time $t$, the model for outcome $y_t$ is defined by\n\\[\ny_t = \\mu + \\theta_1 \\epsilon_{t-1} + \\cdots + \\theta_Q \\epsilon_{t-Q}\n+ \\epsilon_t,\n\\]\nwith the noise term $\\epsilon_t$ for outcome $y_t$ modeled as\nnormal,\n\\[\n\\epsilon_t \\sim \\distro{Normal}(0,\\sigma).\n\\]\nIn a proper Bayesian model, the parameters $\\mu$, $\\theta$, and\n$\\sigma$ must all be given priors.\n\n\\subsection{$\\mbox{MA}(2)$ Example}\n\nAn $\\mbox{MA}(2)$ model can be coded in Stan as follows.\n%\n\\begin{stancode}\ndata {\n  int<lower=3> T;  // number of observations\n  vector[T] y;     // observation at time T\n}\nparameters {\n  real mu;              // mean\n  real<lower=0> sigma;  // error scale\n  vector[2] theta;      // lag coefficients\n}\ntransformed parameters {\n  vector[T] epsilon;    // error terms\n  epsilon[1] = y[1] - mu;\n  epsilon[2] = y[2] - mu - theta[1] * epsilon[1];\n  for (t in 3:T)\n    epsilon[t] = ( y[t] - mu\n                    - theta[1] * epsilon[t - 1]\n                    - theta[2] * epsilon[t - 2] );\n}\nmodel {\n  mu ~ cauchy(0, 2.5);\n  theta ~ cauchy(0, 2.5);\n  sigma ~ cauchy(0, 2.5);\n  for (t in 3:T)\n    y[t] ~ normal(mu\n                  + theta[1] * epsilon[t - 1]\n                  + theta[2] * epsilon[t - 2],\n                  sigma);\n}\n\\end{stancode}\n%\nThe error terms $\\epsilon_t$ are defined as transformed parameters in\nterms of the observations and parameters.  The definition of the\nsampling statement (defining the likelihood) follows the definition,\nwhich can only be applied to $y_n$ for $n > Q$.  In this example, the\nparameters are all given Cauchy (half-Cauchy for $\\sigma$) priors,\nalthough other priors can be used just as easily.\n\nThis model could be improved in terms of speed by vectorizing the\nsampling statement in the model block.  Vectorizing the calculation of\nthe $\\epsilon_t$ could also be sped up by using a dot product instead\nof a loop.\n\n\n\\subsection{Vectorized $\\mbox{MA}(Q)$ Model}\n\nA general $\\mbox{MA}(Q)$ model with a vectorized sampling probability\nmay be defined as follows.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> Q;  // num previous noise terms\n  int<lower=3> T;  // num observations\n  vector[T] y;     // observation at time t\n}\nparameters {\n  real mu;              // mean\n  real<lower=0> sigma;  // error scale\n  vector[Q] theta;      // error coeff, lag -t\n}\ntransformed parameters {\n  vector[T] epsilon;    // error term at time t\n  for (t in 1:T) {\n    epsilon[t] = y[t] - mu;\n    for (q in 1:min(t - 1, Q))\n      epsilon[t] = epsilon[t] - theta[q] * epsilon[t - q];\n  }\n}\nmodel {\n  vector[T] eta;\n  mu ~ cauchy(0, 2.5);\n  theta ~ cauchy(0, 2.5);\n  sigma ~ cauchy(0, 2.5);\n  for (t in 1:T) {\n    eta[t] = mu;\n    for (q in 1:min(t - 1, Q))\n      eta[t] = eta[t] + theta[q] * epsilon[t - q];\n  }\n  y ~ normal(eta, sigma);\n}\n\\end{stancode}\n%\nHere all of the data is modeled, with missing terms just dropped from\nthe regressions as in the calculation of the error terms.  Both models\nconverge very quickly and mix very well at convergence, with the\nvectorized model being quite a bit faster (per iteration, not to\nconverge --- they compute the same model).\n\n\n\\section{Autoregressive Moving Average Models}\n\nAutoregressive moving-average models (ARMA), combine the predictors\nof the autoregressive model and the moving average model.  An\nARMA(1,1) model, with a single state of history, can be encoded in\nStan as follows.\n%\n\\begin{stancode}\ndata {\n  int<lower=1> T;            // num observations\n  real y[T];                 // observed outputs\n}\nparameters {\n  real mu;                   // mean coeff\n  real phi;                  // autoregression coeff\n  real theta;                // moving avg coeff\n  real<lower=0> sigma;       // noise scale\n}\nmodel {\n  vector[T] nu;              // prediction for time t\n  vector[T] err;             // error for time t\n  nu[1] = mu + phi * mu;    // assume err[0] == 0\n  err[1] = y[1] - nu[1];\n  for (t in 2:T) {\n    nu[t] = mu + phi * y[t-1] + theta * err[t-1];\n    err[t] = y[t] - nu[t];\n  }\n  mu ~ normal(0, 10);         // priors\n  phi ~ normal(0, 2);\n  theta ~ normal(0, 2);\n  sigma ~ cauchy(0, 5);\n  err ~ normal(0, sigma);    // likelihood\n}\n\\end{stancode}\n%\nThe data is declared in the same way as the other time-series\nregressions and the parameters are documented in the code.\n\nIn the model block, the local vector \\code{nu} stores the predictions\nand \\code{err} the errors.  These are computed similarly to the\nerrors in the moving average models described in the previous section.\n\nThe priors are weakly informative for stationary processes.  The\nlikelihood only involves the error term, which is efficiently\nvectorized here.\n\nOften in models such as these, it is desirable to inspect the\ncalculated error terms.  This could easily be accomplished in Stan by\ndeclaring \\code{err} as a transformed parameter, then defining it the\nsame way as in the model above.  The vector \\code{nu} could still be a\nlocal variable, only now it will be in the transformed parameter block.\n\nWayne Folta suggested encoding the model without local vector\nvariables as follows.\n%\n\\begin{stancode}\nmodel {\n  real err;\n  mu ~ normal(0, 10);\n  phi ~ normal(0, 2);\n  theta ~ normal(0, 2);\n  sigma ~ cauchy(0, 5);\n  err = y[1] - mu + phi * mu;\n  err ~ normal(0, sigma);\n  for (t in 2:T) {\n    err = y[t] - (mu + phi * y[t-1] + theta * err);\n    err ~ normal(0, sigma);\n  }\n}\n\\end{stancode}\n%\nThis approach to ARMA models provides a nice example of how local\nvariables, such as \\code{err} in this case, can be reused in Stan.\nFolta's approach could be extended to higher order moving-average\nmodels by storing more than one error term as a local variable and\nreassigning them in the loop.\n\nBoth encodings are very fast.  The original encoding has the advantage\nof vectorizing the normal distribution, but it uses a bit more memory.\nA halfway point would be to vectorize just \\code{err}.\n\n\\subsection{Identifiability and Stationarity}%\n\nMA and ARMA models are not identifiable if the roots of the\ncharacteristic polynomial for the MA part lie inside the unit circle,\nso it's necessary to add the following constraint.%\n%\n\\footnote{This subsection is a lightly edited comment of Jonathan\n  Gilligan's on GitHub; see\n  \\url{https://github.com/stan-dev/stan/issues/1617\\#issuecomment-160249142}.}\n%\n\\begin{stancode}\nreal<lower = -1, upper = 1> theta;\n\\end{stancode}\n%\nWhen the model is run without the constraint, using synthetic data\ngenerated from the model, the simulation can sometimes find modes for\n(\\code{theta}, \\code{phi}) outside the $[-1,1]$ interval, which\ncreates a multiple mode problem in the posterior and also causes the\nNUTS tree depth to get very large (often above 10). Adding the\nconstraint both improves the accuracy of the posterior and\ndramatically reduces the tree depth, which speeds up the simulation\nconsiderably (typically by much more than an order of magnitude).\n\nFurther, unless one thinks that the process is really non-stationary,\nit's worth adding the following constraint to ensure stationarity.\n%\n\\begin{stancode}\nreal<lower = -1, upper = 1> phi;\n\\end{stancode}\n\n\n\n\\section{Stochastic Volatility Models}\n\nStochastic volatility models treat the volatility (i.e., variance) of\na return on an asset, such as an option to buy a security, as\nfollowing a latent stochastic process in discrete time\n\\citep{KimShephardChib:1998}.  The data consist of mean corrected\n(i.e., centered) returns $y_t$ on an underlying asset at $T$ equally\nspaced time points.  Kim et al.\\ formulate a typical stochastic\nvolatility model using the following regression-like equations, with a\nlatent parameter $h_t$ for the log volatility, along with parameters\n$\\mu$ for the mean log volatility, and $\\phi$ for the persistence of\nthe volatility term.  The variable $\\epsilon_t$ represents the\nwhite-noise shock (i.e., multiplicative error) on the asset return at\ntime $t$, whereas $\\delta_t$ represents the shock on volatility at\ntime $t$.\n\\[\ny_t = \\epsilon_t \\exp(h_t / 2),\n\\]\n\\[\nh_{t+1} = \\mu + \\phi (h_t - \\mu) + \\delta_t \\sigma\n\\]\n\\[\nh_1 \\sim \\distro{Normal}\\left( \\mu, \\frac{\\sigma}{\\sqrt{1 - \\phi^2}} \\right)\n\\]\n\\[\n\\epsilon_t \\sim \\distro{Normal}(0,1); \\ \\ \\ \\ \\  \\delta_t \\sim \\distro{Normal}(0,1)\n\\]\n%\nRearranging the first line, $\\epsilon_t = y_t \\exp(-h_t / 2)$,\nallowing the sampling distribution for $y_t$ to be written as\n\\[\ny_t \\sim \\distro{Normal}(0,\\exp(h_t/2)).\n\\]\nThe recurrence equation for $h_{t+1}$ may be combined with the\nscaling and sampling of $\\delta_t$ to yield the sampling distribution\n\\[\nh_t \\sim \\distro{Normal}(\\mu + \\phi(h_t - \\mu), \\sigma).\n\\]\nThis formulation can be directly encoded, as shown in the following\nStan model.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> T;   // # time points (equally spaced)\n  vector[T] y;      // mean corrected return at time t\n}\nparameters {\n  real mu;                     // mean log volatility\n  real<lower=-1,upper=1> phi;  // persistence of volatility\n  real<lower=0> sigma;         // white noise shock scale\n  vector[T] h;                 // log volatility at time t\n}\nmodel {\n  phi ~ uniform(-1, 1);\n  sigma ~ cauchy(0, 5);\n  mu ~ cauchy(0, 10);\n  h[1] ~ normal(mu, sigma / sqrt(1 - phi * phi));\n  for (t in 2:T)\n    h[t] ~ normal(mu + phi * (h[t - 1] -  mu), sigma);\n  for (t in 1:T)\n    y[t] ~ normal(0, exp(h[t] / 2));\n}\n\\end{stancode}\n%\nCompared to the Kim et al.\\ formulation, the Stan model adds priors\nfor the parameters $\\phi$, $\\sigma$, and $\\mu$.  Note that the shock\nterms $\\epsilon_t$ and $\\delta_t$ do not appear explicitly in the\nmodel, although they could be calculated efficiently in a generated\nquantities block.\n\nThe posterior of a stochastic volatility model such as this one\ntypically has high posterior variance.  For example, simulating 500\ndata points from the above model with $\\mu = -1.02$, $\\phi = 0.95$,\nand $\\sigma = 0.25$ leads to 95\\% posterior intervals for $\\mu$ of\n$(-1.23, -0.54)$, for $\\phi$ of $(0.82,0.98 )$ and for $\\sigma$ of\n$(0.16,0.38)$.\n\nThe samples using NUTS show a high degree of autocorrelation among the\nsamples, both for this model and the stochastic volatility model\nevaluated in \\citep{Hoffman-Gelman:2011, Hoffman-Gelman:2014}.\nUsing a non-diagonal mass\nmatrix provides faster convergence and more effective samples than a\ndiagonal mass matrix, but will not scale to large values of $T$.\n\nIt is relatively straightforward to speed up the effective samples per\nsecond generated by this model by one or more orders of magnitude.\nFirst, the sampling statements for return $y$ is easily vectorized to\n%\n\\begin{stancode}\ny ~ normal(0, exp(h / 2));\n\\end{stancode}\n%\nThis speeds up the iterations, but does not change the effective\nsample size because the underlying parameterization and log\nprobability function have not changed.  Mixing is improved by by\nreparameterizing in terms of a standardized volatility, then\nrescaling.  This requires a standardized parameter \\code{h\\_std} to be\ndeclared instead of \\code{h}.\n\\begin{stancode}\nparameters {\n  ...\n  vector[T] h_std;             // std log volatility time t\n\\end{stancode}\n%\nThe original value of \\code{h} is then defined in a transformed\nparameter block.\n%\n\\begin{stancode}\ntransformed parameters {\n  vector[T] h = h_std * sigma;  // now h ~ normal(0, sigma)\n  h[1] /= sqrt(1 - phi * phi);  // rescale h[1]\n  h += mu;\n  for (t in 2:T)\n    h[t] += phi * (h[t-1] - mu);\n}\n\\end{stancode}\n%\nThe first assignment rescales \\code{h\\_std} to have a\n$\\distro{Normal}(0,\\sigma)$ distribution and temporarily assigns it to\n\\code{h}.  The second assignment rescales \\code{h[1]} so that its\nprior differs from that of \\code{h[2]} through \\code{h[T]}.  The next\nassignment supplies a \\code{mu} offset, so that \\code{h[2]} through\n\\code{h[T]} are now distributed $\\distro{Normal}(\\mu,\\sigma)$; note\nthat this shift must be done after the rescaling of \\code{h[1]}.  The\nfinal loop adds in the moving average so that \\code{h[2]} through\n\\code{h[T]} are appropriately modeled relative to \\code{phi} and\n\\code{mu}.\n\nAs a final improvement, the sampling statement for \\code{h[1]} and\nloop for sampling \\code{h[2]} to \\code{h[T]} are replaced with a\nsingle vectorized unit normal sampling statement.\n%\n\\begin{stancode}\nmodel {\n  ...\n  h_std ~ normal(0, 1);\n\\end{stancode}\n%\nAlthough the original model can take hundreds and sometimes thousands\nof iterations to converge, the reparameterized model reliably\nconverges in tens of iterations.  Mixing is also dramatically\nimproved, which results in higher effective sample sizes per\niteration.  Finally, each iteration runs in roughly a quarter of the\ntime of the original iterations.\n\n\\section{Hidden Markov Models}\\label{hmms.section}\n\nA hidden Markov model (HMM) generates a sequence of $T$ output\nvariables $y_t$ conditioned on a parallel sequence of latent\ncategorical state variables $z_t \\in \\{1,\\ldots, K\\}$.  These\n``hidden'' state variables are assumed to form a Markov chain so that\n$z_t$ is conditionally independent of other variables given $z_{t-1}$.\nThis Markov chain is parameterized by a transition matrix $\\theta$\nwhere $\\theta_k$ is a $K$-simplex for $k \\in \\{1,\\ldots, K\\}$.  The\nprobability of transitioning to state $z_t$ from state $z_{t-1}$ is\n\\[\nz_t \\sim \\distro{Categorical}(\\theta_{z[t-1]}).\n\\]\nThe output $y_t$ at time $t$ is generated conditionally independently\nbased on the latent state $z_t$.\n\nThis section describes HMMs with a simple categorical model for\noutputs $y_t \\in \\{1,\\ldots,V\\}$.  The categorical distribution for\nlatent state $k$ is parameterized by a $V$-simplex $\\phi_k$.  The\nobserved output $y_t$ at time $t$ is generated based on the hidden\nstate indicator $z_t$ at time $t$,\n\\[\ny_t \\sim \\distro{Categorical}(\\phi_{z[t]}).\n\\]\nIn short, HMMs form a discrete mixture model where the mixture\ncomponent indicators form a latent Markov chain.\n\n\n\n\\subsection{Supervised Parameter Estimation}\n\nIn the situation where the hidden states are known, the following\nnaive model can be used to fit the parameters $\\theta$ and $\\phi$.\n%\n\\begin{stancode}\ndata {\n  int<lower=1> K;  // num categories\n  int<lower=1> V;  // num words\n  int<lower=0> T;  // num instances\n  int<lower=1,upper=V> w[T]; // words\n  int<lower=1,upper=K> z[T]; // categories\n  vector<lower=0>[K] alpha;  // transit prior\n  vector<lower=0>[V] beta;   // emit prior\n}\nparameters {\n  simplex[K] theta[K];  // transit probs\n  simplex[V] phi[K];    // emit probs\n}\nmodel {\n  for (k in 1:K)\n    theta[k] ~ dirichlet(alpha);\n  for (k in 1:K)\n    phi[k] ~ dirichlet(beta);\n  for (t in 1:T)\n    w[t] ~ categorical(phi[z[t]]);\n  for (t in 2:T)\n    z[t] ~ categorical(theta[z[t - 1]]);\n}\n\\end{stancode}\n%\nExplicit Dirichlet priors have been provided for $\\theta_k$ and\n$\\phi_k$; dropping these two statements would implicitly take the\nprior to be uniform over all valid simplexes.\n\n\\subsection{Start-State and End-State Probabilities}\n\nAlthough workable, the above description of HMMs is incomplete because\nthe start state $z_1$ is not modeled (the index runs from 2 to $T$).\nIf the data are conceived as a subsequence of a long-running process,\nthe probability of $z_1$ should be set to the stationary state\nprobabilities in the Markov chain.  In this case, there is no distinct\nend to the data, so there is no need to model the probability that the\nsequence ends at $z_T$.\n\nAn alternative conception of HMMs is as models of finite-length\nsequences.  For example, human language sentences have distinct\nstarting distributions (usually a capital letter) and ending\ndistributions (usually some kind of punctuation).  The simplest way to\nmodel the sequence boundaries is to add a new latent state $K+1$,\ngenerate the first state from a categorical distribution with\nparameter vector $\\theta_{K+1}$, and restrict the transitions so that\na transition to state $K+1$ is forced to occur at the end of the\nsentence and is prohibited elsewhere.\n\n\\subsection{Calculating Sufficient Statistics}\n\nThe naive HMM estimation model presented above can be sped up\ndramatically by replacing the loops over categorical distributions\nwith a single multinomial distribution.%\n%\n\\footnote{The program is available in the Stan example model repository;\nsee \\url{http://mc-stan.org/users/documentation}.}\n%\nThe data is declared as before, but now a transformed data blocks\ncomputes the sufficient statistics for estimating the transition and\nemission matrices.\n%\n\\begin{stancode}\ntransformed data {\n  int<lower=0> trans[K, K];\n  int<lower=0> emit[K, V];\n  for (k1 in 1:K)\n    for (k2 in 1:K)\n      trans[k1, k2] = 0;\n  for (t in 2:T)\n    trans[z[t - 1], z[t]] += 1;\n  for (k in 1:K)\n    for (v in 1:V)\n      emit[k,v] = 0;\n  for (t in 1:T)\n    emit[z[t], w[t]] += 1;\n}\n\\end{stancode}\n%\nThe likelihood component of the model based on looping over the input\nis replaced with multinomials as follows.\n%\n\\begin{stancode}\nmodel {\n  ...\n  for (k in 1:K)\n    trans[k] ~ multinomial(theta[k]);\n  for (k in 1:K)\n    emit[k] ~ multinomial(phi[k]);\n}\n\\end{stancode}\n%\nIn a continuous HMM with normal emission probabilities could be sped\nup in the same way by computing sufficient statistics.\n\n\\subsection{Analytic Posterior}\n\nWith the Dirichlet-multinomial HMM, the posterior can be computed\nanalytically because the Dirichlet is the conjugate prior to the\nmultinomial.  The following example%\n%\n\\footnote{The program is available in the Stan example model repository;\nsee \\url{http://mc-stan.org/users/documentation}.}\n%\nillustrates how a Stan model can define the posterior analytically.\nThis is possible in the Stan language because the model only needs to\ndefine the conditional probability of the parameters given the data up\nto a proportion, which can be done by defining the (unnormalized)\njoint probability or the (unnormalized) conditional posterior, or\nanything in between.\n\nThe model has the same data and parameters as the previous models, but\nnow computes the posterior Dirichlet parameters in the transformed\ndata block.\n%\n\\begin{stancode}\ntransformed data {\n  vector<lower=0>[K] alpha_post[K];\n  vector<lower=0>[V] beta_post[K];\n  for (k in 1:K)\n    alpha_post[k] = alpha;\n  for (t in 2:T)\n    alpha_post[z[t-1], z[t]] += 1;\n  for (k in 1:K)\n    beta_post[k] = beta;\n  for (t in 1:T)\n    beta_post[z[t], w[t]] += 1;\n}\n\\end{stancode}\n%\nThe posterior can now be written analytically as follows.\n%\n\\begin{stancode}\nmodel {\n  for (k in 1:K)\n    theta[k] ~ dirichlet(alpha_post[k]);\n  for (k in 1:K)\n    phi[k] ~ dirichlet(beta_post[k]);\n}\n\\end{stancode}\n\n\n\\subsection{Semisupervised Estimation}\n\nHMMs can be estimated in a fully unsupervised fashion without any data\nfor which latent states are known.  The resulting posteriors are\ntypically extremely multimodal.  An intermediate solution is to use\nsemisupervised estimation, which is based on a combination of\nsupervised and unsupervised data.  Implementing this estimation\nstrategy in Stan requires calculating the probability of an output\nsequence with an unknown state sequence.  This is a marginalization\nproblem, and for HMMs, it is computed with the so-called forward\nalgorithm.\n\nIn Stan, the forward algorithm is coded as follows.%\n%\n\\footnote{The program is available in the Stan example model repository;\nsee \\url{http://mc-stan.org/users/documentation}.}\n%\nFirst, two additional data variable are declared for the unsupervised\ndata.\n%\n\\begin{stancode}\ndata {\n  ...\n  int<lower=1> T_unsup;  // num unsupervised items\n  int<lower=1,upper=V> u[T_unsup]; // unsup words\n  ...\n\\end{stancode}\n%\nThe model for the supervised data does not change; the unsupervised\ndata is handled with the following Stan implementation of the forward\nalgorithm.\n%\n\\begin{stancode}\nmodel {\n ...\n  {\n    real acc[K];\n    real gamma[T_unsup, K];\n    for (k in 1:K)\n      gamma[1, k] = log(phi[k, u[1]]);\n    for (t in 2:T_unsup) {\n      for (k in 1:K) {\n        for (j in 1:K)\n          acc[j] = gamma[t-1, j] + log(theta[j, k]) + log(phi[k, u[t]]);\n        gamma[t, k] = log_sum_exp(acc);\n      }\n    }\n    target += log_sum_exp(gamma[T_unsup]);\n  }\n\\end{stancode}\n%\nThe forward values \\code{gamma[t,~k]} are defined to be the log\nmarginal probability of the inputs \\code{u[1],...,u[t]} up to time\n\\code{t} and the latent state being equal to \\code{k} at time\n\\code{t}; the previous latent states are marginalized out.  The first\nrow of \\code{gamma} is initialized by setting \\code{gamma[1,~k]} equal\nto the log probability of latent state \\code{k} generating the first\noutput \\code{u[1]}; as before, the probability of the first latent\nstate is not itself modeled.  For each subsequent time \\code{t} and\noutput \\code{j}, the value \\code{acc[j]} is set to the probability of\nthe latent state at time \\code{t-1} being \\code{j}, plus the log\ntransition probability from state \\code{j} at time \\code{t-1} to state\n\\code{k} at time \\code{t}, plus the log probability of the output\n\\code{u[t]} being generated by state \\code{k}.  The\n\\code{log\\_sum\\_exp} operation just multiplies the probabilities for\neach prior state \\code{j} on the log scale in an arithmetically stable\nway.\n\nThe brackets provide the scope for the local variables \\code{acc} and\n\\code{gamma}; these could have been declared earlier, but it is\nclearer to keep their declaration near their use.\n\n\n\\subsection{Predictive Inference}\n\nGiven the transition and emission parameters, $\\theta_{k, k'}$ and\n$\\phi_{k,v}$ and an observation sequence $u_1,\\ldots,u_T \\in \\{\n1,\\ldots,V \\}$, the Viterbi (dynamic programming) algorithm\ncomputes the state sequence which is most likely to have generated the\nobserved output $u$.\n\nThe Viterbi algorithm can be coded in Stan in the generated quantities\nblock as follows.  The predictions here is the most likely state\nsequence \\code{y\\_star[1], ..., y\\_star[T\\_unsup]} underlying the\narray of observations \\code{u[1], ..., u[T\\_unsup]}.  Because this\nsequence is determined from the transition probabilities\n\\code{theta} and emission probabilities \\code{phi}, it may be\ndifferent from sample to sample in the posterior.\n%\n\\begin{stancode}\ngenerated quantities {\n  int<lower=1,upper=K> y_star[T_unsup];\n  real log_p_y_star;\n  {\n    int back_ptr[T_unsup, K];\n    real best_logp[T_unsup, K];\n    real best_total_logp;\n    for (k in 1:K)\n      best_logp[1, k] = log(phi[k, u[1]]);\n    for (t in 2:T_unsup) {\n      for (k in 1:K) {\n        best_logp[t, k] = negative_infinity();\n        for (j in 1:K) {\n          real logp;\n          logp = best_logp[t-1, j]\n                  + log(theta[j, k]) + log(phi[k, u[t]]);\n          if (logp > best_logp[t, k]) {\n            back_ptr[t, k] = j;\n            best_logp[t, k] = logp;\n          }\n        }\n      }\n    }\n    log_p_y_star = max(best_logp[T_unsup]);\n    for (k in 1:K)\n      if (best_logp[T_unsup, k] == log_p_y_star)\n        y_star[T_unsup] = k;\n    for (t in 1:(T_unsup - 1))\n      y_star[T_unsup - t] = back_ptr[T_unsup - t + 1,\n                                      y_star[T_unsup - t + 1]];\n  }\n}\n\\end{stancode}\n%\nThe bracketed block is used to make the three variables\n\\code{back\\_ptr}, \\code{best\\_logp}, and \\code{best\\_total\\_logp}\nlocal so they will not be output.  The variable \\code{y\\_star} will\nhold the label sequence with the highest probability given the input\nsequence \\code{u}.  Unlike the forward algorithm, where the\nintermediate quantities were total probability, here they consist of\nthe maximum probability \\code{best\\_logp[t,~k]} for the sequence up to\ntime \\code{t} with final output category \\code{k} for time \\code{t},\nalong with a backpointer to the source of the link.  Following the\nbackpointers from the best final log probability for the final time\n\\code{t} yields the optimal state sequence.\n\nThis inference can be run for the same unsupervised outputs \\code{u}\nas are used to fit the semisupervised model.  The above code can be\nfound in the same model file as the unsupervised fit.  This is the\nBayesian approach to inference, where the data being reasoned about is\nused in a semisupervised way to train the model.  It is not\n``cheating'' because the underlying states for \\code{u} are never\nobserved --- they are just estimated along with all of the other\nparameters.\n\nIf the outputs \\code{u} are not used for semisupervised estimation but\nsimply as the basis for prediction, the result is equivalent to what\nis represented in the BUGS modeling language via the cut operation.\nThat is, the model is fit independently of \\code{u}, then those\nparameters used to find the most likely state to have generated\n\\code{u}.\n\n\n\\chapter{Missing Data \\& Partially Known Parameters}\n\n\\noindent\nBayesian inference supports a very general approach to missing data in\nwhich any missing data item is represented as a parameter that is\nestimated in the posterior \\citep{GelmanEtAl:2013}.  If the missing\ndata is not explicitly modeled, as in the predictors for most\nregression models, then the result is an improper prior on the\nparameter representing the missing predictor.\n\nMixing arrays of observed and missing data can be difficult to\ninclude in Stan, partly because it can be tricky to model discrete\nunknowns in Stan and partly because unlike some other statistical\nlanguages (for example, R and Bugs), Stan requires observed and\nunknown quantities to be defined in separate places in the model. Thus\nit can be necessary to include code in a Stan program to splice\ntogether observed and missing parts of a data structure.  Examples are\nprovided later in the chapter.\n\n\\section{Missing Data}\n\nStan treats variables declared in the \\code{data} and\n\\code{transformed data} blocks as known and the variables in the\n\\code{parameters} block as unknown.\n\nAn example involving missing normal observations%\n%\n\\footnote{A more meaningful estimation example would involve a\n  regression of the observed and missing observations using predictors\n  that were known for each and specified in the \\code{data} block.}\n%\ncould be coded as follows.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N_obs;\n  int<lower=0> N_mis;\n  real y_obs[N_obs];\n}\nparameters {\n  real mu;\n  real<lower=0> sigma;\n  real y_mis[N_mis];\n}\nmodel {\n  y_obs ~ normal(mu, sigma);\n  y_mis ~ normal(mu, sigma);\n}\n\\end{stancode}\n%\nThe number of observed and missing data points are coded as data with\nnon-negative integer variables \\code{N\\_obs} and \\code{N\\_mis}.  The\nobserved data is provided as an array data variable \\code{y\\_obs}.\nThe missing data is coded as an array parameter, \\code{y\\_mis}.  The\nordinary parameters being estimated, the location \\code{mu} and scale\n\\code{sigma}, are also coded as parameters.  The model is vectorized\non the observed and missing data; combining them in this case would be\nless efficient because the data observations would be promoted and\nhave needless derivatives calculated.\n\n\n\\section{Partially Known Parameters}\\label{partially-known-parameters.section}\n\nIn some situations, such as when a multivariate probability function\nhas partially observed outcomes or parameters, it will be necessary to\ncreate a vector mixing known (data) and unknown (parameter) values.\nThis can be done in Stan by creating a vector or array in the\n\\code{transformed parameters} block and assigning to it.\n\nThe following example involves a bivariate covariance matrix in which the\nvariances are known, but the covariance is not.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N;\n  vector[2] y[N];\n  real<lower=0> var1;     real<lower=0> var2;\n}\ntransformed data {\n  real<lower=0> max_cov = sqrt(var1 * var2);\n  real<upper=0> min_cov = -max_cov;\n}\nparameters {\n  vector[2] mu;\n  real<lower=min_cov, upper=max_cov> cov;\n}\ntransformed parameters {\n  matrix[2, 2] Sigma;\n  Sigma[1, 1] = var1;     Sigma[1, 2] = cov;\n  Sigma[2, 1] = cov;      Sigma[2, 2] = var2;\n}\nmodel {\n  y ~ multi_normal(mu, Sigma);\n}\n\\end{stancode}\n%\nThe variances are defined as data in variables \\code{var1} and\n\\code{var2}, whereas the covariance is defined as a parameter in\nvariable \\code{cov}.  The $2 \\times 2$ covariance matrix \\code{Sigma}\nis defined as a transformed parameter, with the variances assigned to\nthe two diagonal elements and the covariance to the two off-diagonal\nelements.\n\nThe constraint on the covariance declaration ensures that the\nresulting covariance matrix \\code{sigma} is positive definite.  The\nbound, plus or minus the square root of the product of the variances,\nis defined as transformed data so that it is only calculated once.\n\nThe vectorization of the multivariate normal is critical for\nefficiency here.  The transformed parameter \\code{Sigma} could be\ndefined as a local variable within the model block if\n\n\\section{Sliced Missing Data}\n\nIf the missing data is part of some larger data structure, then it can\noften be effectively reassembled using index arrays and slicing.\nHere's an example for time-series data, where only some entries in the\nseries are observed.\n%\n\\begin{stancode}\ndata {\n  int<lower = 0> N_obs;\n  int<lower = 0> N_mis;\n  int<lower = 1, upper = N_obs + N_mis> ii_obs[N_obs];\n  int<lower = 1, upper = N_obs + N_mis> ii_mis[N_mis];\n  real y_obs[N_obs];\n}\ntransformed data {\n  int<lower = 0> N = N_obs + N_mis;\n}\nparameters {\n  real y_mis[N_mis];\n  real<lower=0> sigma;\n}\ntransformed parameters {\n  real y[N];\n  y[ii_obs] = y_obs;\n  y[ii_mis] = y_mis;\n}\nmodel {\n  sigma ~ gamma(1, 1);\n  y[1] ~ normal(0, 100);\n  y[2:N] ~ normal(y[1:(N - 1)], sigma);\n}\n\\end{stancode}\n%\nThe index arrays \\code{ii\\_obs} and \\code{ii\\_mis} contain the indexes\ninto the final array \\code{y} of the observed data (coded as a data\nvector \\code{y\\_obs}) and the missing data (coded as a parameter\nvector \\code{y\\_mis}).  See \\refchapter{time-series} for further\ndiscussion of time-series model and specifically\n\\refsection{autoregressive} for an explanation of the vectorization\nfor \\code{y} as well as an explanation of how to convert this example\nto a full AR(1) model.  To ensure \\code{y[1]} has a proper posterior\nin case it is missing, we have given it an explicit, albeit broad,\nprior.\n\nAnother potential application would be filling the\ncolumns of a data matrix of predictors for which some predictors are\nmissing; matrix columns can be accessed as vectors and assigned the\nsame way, as in\n%\n\\begin{stancode}\n  x[N_obs_2, 2] = x_obs_2;\n  x[N_mis_2, 2] = x_mis_2;\n\\end{stancode}\n%\nwhere the relevant variables are all hard coded with index \\code{2}\nbecause Stan doesn't support ragged arrays.  These could all be packed\ninto a single array with more fiddly indexing that slices out vectors\nfrom longer vectors (see \\refsection{ragged-data-structs} for a\ngeneral discussion of coding ragged data structures in Stan).\n\n\\section{Loading matrix for factor analysis}\n\nRick Farouni, on the Stan users group, inquired as to how to build\na Cholesky factor for a covariance matrix with a unit diagonal, as\nused in Bayesian factor analysis \\cite{aguilar-west:2000}.  This\ncan be accomplished by declaring the below-diagonal elements as\nparameters, then filling the full matrix as a transformed parameter.\n%\n\\begin{stancode}\ndata {\n  int<lower=2> K;\n}\ntransformed data {\n  int<lower=1> K_choose_2;\n  K_choose_2 = (K * (K - 1)) / 2;\n}\nparameters {\n  vector[K_choose_2] L_lower;\n}\ntransformed parameters {\n  cholesky_factor_cov[K] L;\n  for (k in 1:K)\n    L[k, k] = 1;\n  {\n    int i;\n    for (m in 2:K) {\n      for (n in 1:(m - 1)) {\n        L[m, n] = L_lower[i];\n        L[n, m] = 0;\n        i += 1;\n      }\n    }\n  }\n}\n\\end{stancode}\n%\nIt is most convenient to place a prior directly on \\code{L\\_lower}.\nAn alternative would be a prior for the full Cholesky factor \\code{L},\nbecause the transform from \\code{L\\_lower} to \\code{L} is just the\nidentity and thus does not require a Jacobian adjustment (despite the\nwarning from the parser, which is not smart enough to do the code\nanalysis to infer that the transform is linear).  It would not be at\nall convenient to place a prior on the full covariance matrix \\code{L\n  * L'}, because that would require a Jacobian adjustment; the exact\nadjustment is provided in the subsection of\n\\refsection{change-of-variables} devoted to covariance matrices.\n\n\\section{Missing Multivariate Data}\n\nIt's often the case that one or more components of a multivariate\noutcome are missing.%\n%\n\\footnote{Note that this is not the same as missing components of a\n  multivariate predictor in a regression problem;  in that case, you\n  will need to represent the missing data as a parameter and impute\n  missing values in order to feed them into the regression.}\n%\nAs an example, we'll consider the bivariate distribution, which is\neasily marginalized.  The coding here is brute force, representing\nboth an array of vector observations \\code{y} and a boolean array\n\\code{y\\_observed} to indicate which values were observed (others can\nhave dummy values in the input).\n\n\\begin{stancode}\nvector[2] y[N];\nint<lower=0, upper=1> y_observed[N, 2];\n\\end{stancode}\n\nIf both components are observed, we model them using the full\nmulti-normal, otherwise we model the marginal distribution of the\ncomponent that is observed.\n\n\\begin{stancode}\nfor (n in 1:N) {\n  if (y_observed[n, 1] && y_observed[n, 2])\n    y[n] ~ multi_normal(mu, Sigma);\n  else if (y_observed[n, 1])\n    y[n, 1] ~ normal(mu[1], sqrt(Sigma[1, 1]));\n  else if (y_observed[n, 2])\n    y[n, 2] ~ normal(mu[2], sqrt(Sigma[2, 2]));\n}\n\\end{stancode}\n\nIt's a bit more work, but much more efficient to vectorize these\nsampling statements.  In transformed data, build up three vectors of\nindices, for the three cases above:\n%\n\\begin{stancode}\ntransformed data {\n  int ns12[observed_12(y_observed)];\n  int ns1[observed_1(y_observed)];\n  int ns2[observed_2(y_observed)];\n}\n\\end{stancode}\n%\nYou will need to write functions that pull out the count of\nobservations in each of the three sampling situations.  This must be\ndone with functions because the result needs to go in top-level block\nvariable size declaration.  Then the rest of transformed data just\nfills in the values using three counters.\n%\n\\begin{stancode}\nint n12 = 1;\nint n1 = 1;\nint n2 = 1;\nfor (n in 1:N) {\n  if (y_observed[n, 1] && y_observed[n, 2]) {\n    ns12[n12] = n;\n    n12 += 1;\n  } else if (y_observed[n, 1]) {\n    ns1[n1] = n;\n    n1 += 1;\n  } else if (y_observed[n, 2]) {\n    ns2[n2] = n;\n    n2 += 1;\n  }\n}\n\\end{stancode}\n%\nThen, in the model block, everything's nice and vectorizable\nusing those indexes constructed once in transformed data:\n%\n\\begin{stancode}\ny[ns12] ~ multi_normal(mu, Sigma);\ny[ns1] ~ normal(mu[1], sqrt(Sigma[1, 1]));\ny[ns2] ~ normal(mu[2], sqrt(Sigma[2, 2]));\n\\end{stancode}\n%\nThe result will be much more efficient than using latent variables for\nthe missing data, but requires the multivariate distribution to be\nmarginalized analytically.  It'd be more efficient still to precompute\nthe three arrays in the transformed data block, though the efficiency\nimprovement will be relatively minor compared to vectorizing the\nprobability functions.\n\nThis approach can easily be generalized with some index fiddling to\nthe general multivariate case.  The trick is to pull out entries in\nthe covariance matrix for the missing components.  It can also be used\nin situations such as multivariate differential equation solutions\nwhere only one component is observed, as in a phase-space experiment\nrecording only time and position of a pendulum (and not recording\nmomentum).\n\n\n\\chapter{Truncated or Censored Data}\n\n\\noindent\nData in which measurements have been truncated or censored can be\ncoded in Stan following their respective probability models.\n\n\\section{Truncated Distributions}\\label{truncation.section}\n\nTruncation in Stan is restricted to univariate distributions for which\nthe corresponding log cumulative distribution function (cdf) and log\ncomplementary cumulative distribution (ccdf) functions are available.\nSee the subsection on truncated distributions in\n\\refsection{sampling-statements} for more information on truncated\ndistributions, cdfs, and ccdfs.\n\n\\section{Truncated Data}\\label{truncated-data.section}\n\nTruncated data is data for which measurements are only reported if\nthey fall above a lower bound, below an upper bound, or between a\nlower and upper bound.\n\nTruncated data may be modeled in Stan using truncated distributions.\nFor example, suppose the truncated data is $y_n$ with an upper\ntruncation point of $U = 300$ so that $y_n < 300$.  In Stan, this\ndata can be modeled as following a truncated normal distribution for\nthe observations as follows.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N;\n  real U;\n  real<upper=U> y[N];\n}\nparameters {\n  real mu;\n  real<lower=0> sigma;\n}\nmodel {\n  for (n in 1:N)\n    y[n] ~ normal(mu, sigma) T[,U];\n}\n\\end{stancode}\n%\nThe model declares an upper bound \\code{U} as data and constrains\nthe data for \\code{y} to respect the constraint;  this will be checked\nwhen the data is loaded into the model before sampling begins.\n\nThis model implicitly uses an improper flat prior on the scale and\nlocation parameters; these could be given priors in the model using\nsampling statements.\n\n\\subsection{Constraints and Out-of-Bounds Returns}\n\nIf the sampled variate in a truncated distribution lies outside of\nthe truncation range, the probability is zero, so the log probability\nwill evaluate to $-\\infty$.  For instance, if variate \\code{y} is\nsampled with the statement.\n%\n\\begin{stancode}\nfor (n in 1:N)\n  y[n] ~ normal(mu, sigma) T[L,U];\n\\end{stancode}\n%\nthen if the value of \\code{y[n]} is less than the value of \\code{L}\nor greater than the value of \\code{U}, the sampling statement produces\na zero-probability estimate.  For user-defined truncation, this\nzeroing outside of truncation bounds must be handled explicitly.\n\nTo avoid variables straying outside of truncation bounds, appropriate\nconstraints are required.  For example, if \\code{y} is a parameter in\nthe above model, the declaration should constrain it to fall between\nthe values of \\code{L} and \\code{U}.\n%\n\\begin{stancode}\nparameters {\n  real<lower=L,upper=U> y[N];\n  ...\n\\end{stancode}\n\nIf in the above model, \\code{L} or \\code{U} is a parameter and\n\\code{y} is data, then \\code{L} and \\code{U} must be appropriately\nconstrained so that all data is in range and the value of \\code{L} is\nless than that of \\code{U} (if they are equal, the parameter range\ncollapses to a single point and the Hamiltonian dynamics used by\nthe sampler break down).  The following declarations ensure the bounds\nare well behaved.\n%\n\\begin{stancode}\nparameters {\n  real<upper=min(y)> L; // L < y[n]\n  real<lower=fmax(L, max(y))> U; // L < U; y[n] < U\n\\end{stancode}\n%\nNote that for pairs of real numbers, the function \\code{fmax} is used\nrather than \\code{max}.\n\n\n\n\n\n\n\n\\subsection{Unknown Truncation Points}\n\nIf the truncation points are unknown, they may be estimated as\nparameters.  This can be done with a slight rearrangement of the\nvariable declarations from the model in the previous section with\nknown truncation points.\n%\n\\begin{stancode}\ndata {\n  int<lower=1> N;\n  real y[N];\n}\nparameters {\n  real<upper = min(y)> L;\n  real<lower = max(y)> U;\n  real mu;\n  real<lower=0> sigma;\n}\nmodel {\n  L ~ ...;\n  U ~ ...;\n  for (n in 1:N)\n    y[n] ~ normal(mu, sigma) T[L,U];\n}\n\\end{stancode}\n%\nHere there is a lower truncation point \\code{L} which is declared to\nbe less than or equal to the minimum value of \\code{y}.  The upper\ntruncation point \\code{U} is declared to be larger than the maximum\nvalue of \\code{y}.  This declaration, although dependent on the data,\nonly enforces the constraint that the data fall within the truncation\nbounds.  With \\code{N} declared as type \\code{int<lower=1>}, there must be\nat least one data point.  The constraint that \\code{L} is less than\n\\code{U} is enforced indirectly, based on the non-empty data.\n\nThe ellipses where the priors for the bounds \\code{L} and \\code{U}\nshould go should be filled in with a an informative prior in\norder for this model to not concentrate \\code{L} strongly around\n\\code{min(y)} and \\code{U} strongly around \\code{max(y)}.\n\n\n\\section{Censored Data}\n\nCensoring hides values from points that are too large, too small, or\nboth.  Unlike with truncated data, the number of data points that were\ncensored is known.  The textbook example is the household scale which\ndoes not report values above 300 pounds.\n\n\\subsection{Estimating Censored Values}\n\nOne way to model censored data is to treat the censored data as\nmissing data that is constrained to fall in the censored range of\nvalues.  Since Stan does not allow unknown values in its arrays or\nmatrices, the censored values must be represented explicitly, as in the\nfollowing right-censored case.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N_obs;\n  int<lower=0> N_cens;\n  real y_obs[N_obs];\n  real<lower=max(y_obs)> U;\n}\nparameters {\n  real<lower=U> y_cens[N_cens];\n  real mu;\n  real<lower=0> sigma;\n}\nmodel {\n  y_obs ~ normal(mu, sigma);\n  y_cens ~ normal(mu, sigma);\n}\n\\end{stancode}\n%\nBecause the censored data array \\code{y\\_cens} is declared to be a parameter, it\nwill be sampled along with the location and scale parameters \\code{mu}\nand \\code{sigma}.  Because the censored data array \\code{y\\_cens} is\ndeclared to have values of type \\code{real<lower=U>}, all imputed values\nfor censored data will be greater than \\code{U}.  The imputed censored\ndata affects the location and scale parameters through the last\nsampling statement in the model.\n\n\\subsection{Integrating out Censored Values}\n\nAlthough it is wrong to ignore the censored values in estimating\nlocation and scale, it is not necessary to impute values.  Instead,\nthe values can be integrated out.  Each censored data point has a\nprobability of\n%\n\\[\n\\mbox{Pr}[y > U]\n= \\int_U^{\\infty} \\distro{Normal}(y|\\mu,\\sigma) \\, dy\n= 1 - \\Phi\\left(\\frac{y - \\mu}{\\sigma}\\right),\n\\]\n%\nwhere $\\Phi()$ is the unit normal cumulative distribution function.\nWith $M$ censored observations, the total probability on the log scale\nis\n\\[\n\\log \\prod_{m=1}^M \\mbox{Pr}[y_m > U]\n= \\log \\left( 1 - \\Phi\\left(\\frac{y - \\mu}{\\sigma}\\right)\\right)^{M}\n= M \\, \\code{normal\\_lccdf}(y | \\mu, \\sigma),\n\\]\n%\nwhere \\code{normal\\_lccdf} is the log of complementary CDF\n(Stan provides \\code{<distr>\\_lccdf} for each distribution\nimplemented in Stan).\n\nThe following right-censored model assumes\nthat the censoring point is known, so it is declared as data.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N_obs;\n  int<lower=0> N_cens;\n  real y_obs[N_obs];\n  real<lower=max(y_obs)> U;\n}\nparameters {\n  real mu;\n  real<lower=0> sigma;\n}\nmodel {\n  y_obs ~ normal(mu, sigma);\n  target += N_cens * normal_lccdf(U | mu, sigma);\n}\n\\end{stancode}\n%\nFor the observed values in \\code{y\\_obs}, the normal sampling model is\nused without truncation.  The log probability is directly incremented\nusing the calculated log cumulative normal probability of the censored\ndata items.\n\nFor the left-censored data the CDF (\\code{normal\\_lcdf}) has to be\nused instead of complementary CDF.  If the censoring point variable\n(\\code{L}) is unknown, its declaration should be moved from the data\nto the parameters block.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N_obs;\n  int<lower=0> N_cens;\n  real y_obs[N_obs];\n}\nparameters {\n  real<upper=min(y_obs)> L;\n  real mu;\n  real<lower=0> sigma;\n}\nmodel {\n  L ~ normal(mu, sigma);\n  y_obs ~ normal(mu, sigma);\n  target += N_cens * normal_lcdf(L | mu, sigma);\n}\n\\end{stancode}\n%\n\n\n\\chapter{Finite Mixtures}\\label{mixture-modeling.chapter}\n\n\\noindent\nFinite mixture models of an outcome assume that the outcome is drawn\nfrom one of several distributions, the identity of which is controlled\nby a categorical mixing distribution.  Mixture models typically have\nmultimodal densities with modes near the modes of the mixture\ncomponents.  Mixture models may be parameterized in several ways, as\ndescribed in the following sections.  Mixture models may be used\ndirectly for modeling data with multimodal distributions, or they may\nbe used as priors for other parameters.\n\n\\section{Relation to Clustering}\\label{clustering-mixture.section}\n\nClustering models, as discussed in \\refchapter{clustering}, are just a\nparticular class of mixture models that have been widely applied to\nclustering in the engineering and machine-learning literature.  The\nnormal mixture model discussed in this chapter reappears in\nmultivariate form as the statistical basis for the $K$-means\nalgorithm;  the latent Dirichlet allocation model, usually applied to\nclustering problems, can be viewed as a mixed-membership multinomial\nmixture model.\n\n\n\\section{Latent Discrete Parameterization}\n\nOne way to parameterize a mixture model is with a latent categorical\nvariable indicating which mixture component was responsible for the\noutcome. For example, consider $K$ normal distributions with locations\n$\\mu_k \\in \\reals$ and scales $\\sigma_k \\in (0,\\infty)$.  Now consider\nmixing them in proportion $\\lambda$, where $\\lambda_k \\geq 0$ and\n$\\sum_{k=1}^K \\lambda_k = 1$ (i.e., $\\lambda$ lies in the unit $K$-simplex).\nFor each outcome $y_n$ there is a latent variable $z_n$ in\n$\\setlist{1,\\ldots,K}$ with a categorical distribution parameterized\nby $\\lambda$,\n%\n\\[\nz_n \\sim \\distro{Categorical}(\\lambda).\n\\]\n%\nThe variable $y_n$ is distributed according to the parameters\nof the mixture component $z_n$,\n\\[\ny_n \\sim \\distro{Normal}(\\mu_{z[n]},\\sigma_{z[n]}).\n\\]\n%\nThis model is not directly supported by Stan because it involves\ndiscrete parameters $z_n$, but Stan can sample $\\mu$ and $\\sigma$\nby summing out the $z$ parameter as described in the next section.\n\n\n\\section{Summing out the Responsibility Parameter}\n\nTo implement the normal mixture model outlined in the previous\nsection in Stan, the discrete parameters can be summed out of the\nmodel. If $Y$ is a mixture of $K$ normal distributions with\nlocations $\\mu_k$ and scales $\\sigma_k$ with mixing proportions\n$\\lambda$ in the unit $K$-simplex, then\n\\[\np_Y(y | \\lambda, \\mu, \\sigma)\n\\ = \\\n\\sum_{k=1}^K \\lambda_k \\, \\distro{Normal}(y \\, | \\, \\mu_k, \\sigma_k).\n\\]\n\n\\section{Log Sum of Exponentials: Linear Sums on the Log Scale}\n\nThe log sum of exponentials function is used to define mixtures on the\nlog scale.  It is defined for two inputs by\n%\n\\[\n\\mbox{log\\_sum\\_exp}(a, b) = \\log (\\exp(a) + \\exp(b)).\n\\]\n%\nIf $a$ and $b$ are probabilities on the log scale, then $\\exp(a) +\n\\exp(b)$ is their sum on the linear scale, and the outer log converts\nthe result back to the log scale; to summarize, log\\_sum\\_exp does\nlinear addition on the log scale.   The reason to use Stan's built-in\nlog\\_sum\\_exp function is that it can prevent underflow and overflow\nin the exponentiation, by calculating the result as\n%\n\\[\n\\log\\left( \\exp(a) + \\exp(b)\\right)\n= c\n  + \\log \\left( \\exp(a - c) + \\exp(b - c) \\right),\n\\]\n%\nwhere $c = \\max(a, b)$.\nIn this evaluation, one of the terms, $a - c$ or $b -\nc$, is zero and the other is negative, thus eliminating the\npossibility of overflow or underflow in the leading term and eking the\nmost arithmetic precision possible out of the operation.\n\nFor example, the mixture of $\\code{Normal}(-1,2)$ and\n$\\code{Normal}(3,1)$ with mixing proportion $\\lambda =\n(0.3,0.7)^{\\top}$ can be implemented in Stan as follows.\n%\n\\begin{stancode}\nparameters {\n  real y;\n}\nmodel {\n  target += log_sum_exp(log(0.3) + normal_lpdf(y | -1, 2),\n                        log(0.7) + normal_lpdf(y | 3, 1));\n}\n\\end{stancode}\n%\nThe log probability term is derived by taking\n%\n\\begin{eqnarray*}\n\\log p_Y(y | \\lambda,\\mu,\\sigma) & = & \\log\\!\\left( 0.3 \\times \\distro{Normal}(y|-1,2) \\, + \\,\n  0.7 \\times\n  \\distro{Normal}(y|3,1) \\, \\right)\n\\\\[2pt]\n& = & \\log(\\hspace*{-5pt} \\begin{array}[t]{l}\n                 \\exp(\\log(0.3 \\times \\distro{Normal}(y|-1,2))) \\\\\n                 + \\exp(\\log(0.7 \\times \\distro{Normal}(y|3,1))) \\ )\n              \\end{array}\n\\\\[2pt]\n& = & \\mbox{log\\_sum\\_exp}(\\hspace*{-5pt}\\begin{array}[t]{l}\n                         \\log(0.3) + \\log \\distro{Normal}(y|-1,2),\n                         \\\\\n                         \\log(0.7) + \\log \\distro{Normal}(y|3,1) \\ ).\n                       \\end{array}\n\\end{eqnarray*}\n%\n\n\\subsubsection{Dropping uniform mixture ratios}\n\nIf a two-component mixture has a mixing ratio of 0.5, then the mixing\nratios can be dropped, because\n%\n\\begin{stancode}\nneg_log_half = -log(0.5);\nfor (n in 1:N)\n  target\n    += log_sum_exp(neg_log_half + normal_lpdf(y[n] | mu[1], sigma[1]),\n                   neg_log_half + normal_lpdf(y[n] | mu[2], sigma[2]));\n\\end{stancode}\n%\nthen the $-\\log 0.5$ term isn't contributing to the proportional\ndensity, and the above can be replaced with the more efficient version\n%\n\\begin{stancode}\nfor (n in 1:N)\n  target += log_sum_exp(normal_lpdf(y[n] | mu[1], sigma[1]),\n                        normal_lpdf(y[n] | mu[2], sigma[2]));\n\\end{stancode}\n%\nThe same result holds if there are $K$ components and the mixing\nsimplex $\\lambda$ is symmetric, i.e.,\n%\n\\[\n\\lambda = \\left( \\frac{1}{K},   \\ldots, \\frac{1}{K} \\right).\n\\]\n%\nThe result follows from the identity\n%\n\\[\n\\mbox{log\\_sum\\_exp}(c + a, c + b)\n\\ = \\\nc + \\mbox{log\\_sum\\_exp(a, b)}\n\\]\n%\nand the fact that adding a constant $c$ to the log density accumulator\nhas no effect because the log density is only specified up to an\nadditive constant in the first place.  There is nothing specific to\nthe normal distribution here; constants may always be dropped from the\ntarget.\n\n\n\\subsection{Estimating Parameters of a Mixture}\n\nGiven the scheme for representing mixtures, it may be moved to an\nestimation setting, where the locations, scales, and mixture\ncomponents are unknown.  Further generalizing to a number of mixture\ncomponents specified as data yields the following model.\n%\n\\begin{stancode}\ndata {\n  int<lower=1> K;          // number of mixture components\n  int<lower=1> N;          // number of data points\n  real y[N];               // observations\n}\nparameters {\n  simplex[K] theta;          // mixing proportions\n  ordered[K] mu;             // locations of mixture components\n  vector<lower=0>[K] sigma;  // scales of mixture components\n}\nmodel {\n  vector[K] log_theta = log(theta);  // cache log calculation\n  sigma ~ lognormal(0, 2);\n  mu ~ normal(0, 10);\n  for (n in 1:N) {\n    vector[K] lps = log_theta;\n    for (k in 1:K)\n      lps[k] += normal_lpdf(y[n] | mu[k], sigma[k]);\n    target += log_sum_exp(lps);\n  }\n}\n\\end{stancode}\n%\nThe model involves \\code{K} mixture components and \\code{N} data\npoints. The mixing proportion parameter \\code{theta} is declared to be\na unit $K$-simplex, whereas the component location parameter \\code{mu}\nand scale parameter \\code{sigma} are both defined to be\n\\code{K}-vectors.\n\nThe location parameter \\code{mu} is declared to be an ordered vector\nin order to identify the model.  This will not affect inferences that\ndo not depend on the ordering of the components as long as the prior\nfor the components \\code{mu[k]} is symmetric, as it is here (each\ncomponent has an independent $\\mathsf{Normal}(0, 10)$ prior).  It\nwould even be possible to include a hierarchical prior for the components.\n\nThe values in the scale array \\code{sigma} are constrained to be\nnon-negative, and have a weakly informative prior given in the model\nchosen to avoid zero values and thus collapsing components.\n\nThe model declares a local array variable \\code{lps} to be size\n\\code{K} and uses it to accumulate the log contributions from the\nmixture components.  The main action is in the loop over data points\n\\code{n}.  For each such point, the log of $\\theta_k \\times\n\\distro{Normal}(y_n \\, | \\, \\mu_k,\\sigma_k)$ is calculated and added to the\narray \\code{lpps}.  Then the log probability is incremented with the log\nsum of exponentials of those values.\n\n\\section{Vectorizing Mixtures}\n\nThere is (currently) no way to vectorize mixture models at the\nobservation level in Stan.  This section is to warn users away from\nattempting to vectorize naively, as it results in a different model.\nA proper mixture at the observation level is defined as follows, where\nwe assume that \\code{lambda}, \\code{y[n]}, \\code{mu[1], mu[2]}, and\n\\code{sigma[1], sigma[2]} are all scalars and \\code{lambda} is between\n0 and 1.\n%\n\\begin{stancode}\nfor (n in 1:N) {\n  target += log_sum_exp(log(lambda)\n                          + normal_lpdf(y[n] | mu[1], sigma[1]),\n                        log1m(lambda)\n                          + normal_lpdf(y[n] | mu[2], sigma[2]));\n\\end{stancode}\n%\nor equivalently\n%\n\\begin{stancode}\nfor (n in 1:N)\n  target += log_mix(lambda,\n                    normal_lpdf(y[n] | mu[1], sigma[1]),\n                    normal_lpdf(y[n] | mu[2], sigma[2]));\n\\end{stancode}\n%\nThis definition assumes that each observation $y_n$ may have arisen\nfrom either of the mixture components. The density is\n\\[\np(y \\, | \\, \\lambda, \\mu, \\sigma)\n= \\prod_{n=1}^N (\\lambda \\times \\distro{Normal}(y_n \\, | \\, \\mu_1, \\sigma_1)\n                 + (1 - \\lambda) \\times \\distro{Normal}(y_n \\, | \\, \\mu_2, \\sigma_2).\n\\]\n%\nContrast the previous model with the following (erroneous) attempt to\nvectorize the model.\n%\n\\begin{stancode}\ntarget += log_sum_exp(log(lambda)\n                        + normal_lpdf(y | mu[1], sigma[1]),\n                      log1m(lambda)\n                        + normal_lpdf(y | mu[2], sigma[2]));\n\\end{stancode}\n%\nor equivalently,\n%\n\\begin{stancode}\ntarget += log_mix(lambda,\n                  normal_lpdf(y | mu[1], sigma[1]),\n                  normal_lpdf(y | mu[2], sigma[2]));\n\\end{stancode}\n%\nThis second definition implies that the entire sequence $y_1, \\ldots, y_n$ of\nobservations comes form one component or the other, defining a\ndifferent density,\n\\[\np(y \\, | \\, \\lambda, \\mu, \\sigma)\n= \\lambda \\times \\prod_{n=1}^N \\mbox{Normal}(y_n \\, | \\, \\mu_1, \\sigma_1)\n+ (1 - \\lambda) \\times \\prod_{n=1}^N \\mbox{Normal}(y_n \\, | \\, \\mu_2, \\sigma_2).\n\\]\n\n\n\\section{Inferences Supported by\n  Mixtures}\\label{mixture-inference.section}\n\nIn many mixture models, the mixture components are underlyingly\nexchangeable in the model and thus not identifiable.  This arises if\nthe parameters of the mixture components have exchangeable priors and\nthe mixture ratio gets a uniform prior so that the parameters of the\nmixture components are also exchangeable in the likelihood.\n\nWe have finessed this basic problem by ordering the parameters.  This\nwill allow us in some cases to pick out mixture components either\nahead of time or after fitting (e.g., male vs. female, or Democrat\nvs.\\ Republican).\n\nIn other cases, we do not care about the actual identities of the\nmixture components and want to consider inferences that are\nindependent of indexes.  For example, we might only be interested\nin posterior predictions for new observations.\n\n\\subsection{Mixtures with Unidentifiable Components}\n\nAs an example, consider the normal mixture from the previous section,\nwhich provides an exchangeable prior on the pairs of parameters\n$(\\mu_1, \\sigma_1)$ and $(\\mu_2, \\sigma_2)$,\n%\n\\begin{eqnarray*}\n\\mu_1, \\mu_2 & \\sim & \\distro{Normal}(0, 10)\n\\\\[8pt]\n\\sigma_1, \\sigma_2 & \\sim & \\distro{HalfNormal}(0, 10)\n\\end{eqnarray*}\n%\nThe prior on the mixture ratio is uniform,\n%\n\\[\n\\lambda \\sim \\distro{Uniform}(0, 1),\n\\]\n%\nso that with the likelihood\n%\n\\[\np(y_n \\, | \\, \\mu, \\sigma)\n= \\lambda \\, \\distro{Normal}(y_n \\, | \\, \\mu_1, \\sigma_1)\n+ (1 - \\lambda) \\, \\distro{Normal}(y_n \\, | \\, \\mu_2, \\sigma_2),\n\\]\n%\nthe joint distribution $p(y, \\mu, \\sigma, \\lambda)$ is exchangeable\nin the parameters $(\\mu_1, \\sigma_1)$ and $(\\mu_2, \\sigma_2)$ with\n$\\lambda$ flipping to $1 - \\lambda$.%\n%\n\\footnote{Imposing a constraint such as $\\theta < 0.5$ will resolve\n  the symmetry, but fundamentally changes the model and its posterior\n  inferences.}\n\n\\subsection{Inference under Label Switching}\n\nIn cases where the mixture components are not identifiable, it can be\ndifficult to diagnose convergence of sampling or optimization\nalgorithms because the labels will switch, or be permuted, in\ndifferent MCMC chains or different optimization runs.  Luckily,\nposterior inferences which do not refer to specific component labels\nare invariant under label switching and may be used directly.  This\nsubsection considers a pair of examples.\n\n\\subsubsection{Predictive likelihood}\n\nPredictive likelihood for a new observation $\\tilde{y}$ given the\ncomplete parameter vector $\\theta$ will be\n%\n\\[\np(\\tilde{y} \\, | \\, y)\n=\n\\int_{\\theta}\np(\\tilde{y} \\, | \\, \\theta)\n\\, p(\\theta | y)\n\\, \\mbox{d}\\theta.\n\\]\n%\nThe normal mixture example from the previous section, with $\\theta =\n(\\mu, \\sigma, \\lambda)$, shows that the likelihood returns the same\ndensity under label switching and thus the predictive inference is\nsound.  In Stan, that predictive inference can be done either by\ncomputing $p(\\tilde{y} \\, | \\, y)$, which is more efficient\nstatistically in terms of effective sample size, or simulating draws\nof $\\tilde{y}$, which is easier to plug into other inferences.  Both\napproaches can be coded directly in the generated quantities block of\nthe program.  Here's an example of the direct (non-sampling) approach.\n%\n\\begin{stancode}\ndata {\n  int<lower = 0> N_tilde;\n  vector[N_tilde] y_tilde;\n  ...\ngenerated quantities {\n  vector[N_tilde] log_p_y_tilde;\n  for (n in 1:N_tilde)\n    log_p_y_tilde[n]\n      = log_mix(lambda,\n                normal_lpdf(y_tilde[n] | mu[1], sigma[1])\n                normal_lpdf(y_tilde[n] | mu[2], sigma[2]));\n}\n\\end{stancode}\n%\nIt is a bit of a bother afterwards, because the logarithm function\nisn't linear and hence doesn't distribute through averages (Jensen's\ninequality shows which way the inequality goes).  The right thing to\ndo is to apply \\code{log\\_sum\\_exp} of the posterior draws of\n\\code{log\\_p\\_y\\_tilde}.  The average log predictive density is then\ngiven by subtracting \\code{log(N\\_new)}.\n\n\n\\subsubsection{Clustering and similarity}\n\nOften a mixture model will be applied to a clustering problem and\nthere might be two data items $y_i$ and $y_j$ for which there is a\nquestion of whether they arose from the same mixture component.  If we\ntake $z_i$ and $z_j$ to be the component responsibility discrete\nvariables, then the quantity of interest is $z_i = z_j$, which can be\nsummarized as an event probability\n%\n\\[\n\\mbox{Pr}[z_i = z_j \\, | \\, y]\n=\n\\int_{\\theta}\n\\frac{\\sum_{k=0}^1 p(z_i=k, z_j = k, y_i, y_j \\, | \\, \\theta)}\n     {\\sum_{k=0}^1 \\sum_{m=0}^1 p(z_i = k, z_j = m, y_i, y_j \\, | \\,\n       \\theta)}\n\\\np(\\theta \\, | \\, y)\n\\\n\\mbox{d}\\theta.\n\\]\n%\nAs with other event probabilities, this can be calculated in the\ngenerated quantities block either by sampling $z_i$ and $z_j$ and\nusing the indicator function on their equality, or by computing the\nterm inside the integral as a generated quantity.  As with predictive\nlikelihood, working in expectation is more statistically efficient than\nsampling.\n\n\\section{Zero-Inflated and Hurdle Models}\\label{zero-inflated.section}\n\nZero-inflated and hurdle models both provide mixtures of a Poisson and\nBernoulli probability mass function to allow more flexibility in\nmodeling the probability of a zero outcome.  Zero-inflated models, as\ndefined by \\citet{Lambert:1992}, add additional probability mass to\nthe outcome of zero.  Hurdle models, on the other hand, are formulated\nas pure mixtures of zero and non-zero outcomes.\n\nZero inflation and hurdle models can be formulated for discrete\ndistributions other than the Poisson.  Zero inflation does not work\nfor continuous distributions in Stan because of issues with\nderivatives; in particular, there is no way to add a point mass to a\ncontinuous distribution, such as zero-inflating a normal as a\nregression coefficient prior.\n\n\n\\subsection{Zero Inflation}\n\nConsider the following example for zero-inflated Poisson\ndistributions.  It uses a parameter \\code{theta} here there is a\nprobability $\\theta$ of drawing a zero, and a probability $1 - \\theta$\nof drawing from $\\distro{Poisson}(\\lambda)$ (now $\\theta$ is being\nused for mixing proportions because $\\lambda$ is the traditional\nnotation for a Poisson mean parameter).  The probability function is\nthus\n\\[\np(y_n|\\theta,\\lambda)\n=\n\\left\\{\n\\begin{array}{ll}\n\\theta + (1 - \\theta) \\times \\distro{Poisson}(0|\\lambda) & \\mbox{ if } y_n = 0, \\mbox{ and}\n\\\\[3pt]\n(1-\\theta) \\times \\distro{Poisson}(y_n|\\lambda) & \\mbox{ if } y_n > 0.\n\\end{array}\n\\right.\n\\]\n%\nThe log probability function can be implemented directly in Stan as follows.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N;\n  int<lower=0> y[N];\n}\nparameters {\n  real<lower=0, upper=1> theta;\n  real<lower=0> lambda;\n}\nmodel {\n  for (n in 1:N) {\n    if (y[n] == 0)\n      target += log_sum_exp(bernoulli_lpmf(1 | theta),\n                            bernoulli_lpmf(0 | theta)\n                              + poisson_lpmf(y[n] | lambda));\n    else\n      target += bernoulli_lpmf(0 | theta)\n                  + poisson_lpmf(y[n] | lambda);\n  }\n}\n\\end{stancode}\n%\nThe \\code{log\\_sum\\_exp(lp1,lp2)} function adds the log probabilities\non the linear scale; it is defined to be equal to \\code{log(exp(lp1) +\n  exp(lp2))}, but is more arithmetically stable and faster.  This\ncould also be written using the conditional operator; see\n\\refsection{conditional-operator}.\n\n\\subsection{Hurdle Models}\n\nThe hurdle model is similar to the zero-inflated model, but more\nflexible in that the zero outcomes can be deflated as well as\ninflated.  The probability mass function for the hurdle likelihood is\ndefined by\n%\n\\[\np(y|\\theta,\\lambda)\n=\n\\begin{cases}\n\\ \\theta & \\mbox{if } y = 0, \\mbox{ and}\n\\\\\n\\ (1 - \\theta)\n  \\\n   \\frac{\\displaystyle \\distro{Poisson}(y | \\lambda)}\n        {\\displaystyle \\vspace*{8pt} 1 - \\distro{PoissonCDF}(0 | \\lambda)}\n& \\mbox{if } y > 0,\n\\end{cases}\n\\]\n%\nwhere \\distro{PoissonCDF} is the cumulative distribution function for\nthe Poisson distribution.  The hurdle model is even more straightforward to\nprogram in Stan, as it does not require an explicit mixture.\n%\n\\begin{stancode}\n   if (y[n] == 0)\n      1 ~ bernoulli(theta);\n    else {\n      0 ~ bernoulli(theta);\n      y[n] ~ poisson(lambda) T[1, ];\n    }\n\\end{stancode}\n%\nThe Bernoulli statements are just shorthand for adding $\\log \\theta$\nand $\\log (1 - \\theta)$ to the log density.  The \\code{T[1,]} after\nthe Poisson indicates that it is truncated below at 1; see\n\\refsection{truncation} for more about truncation and\n\\refsection{poisson} for the specifics of the Poisson CDF.  The net\neffect is equivalent to the direct definition of the log likelihood.\n%\n\\begin{stancode}\n   if (y[n] == 0)\n      target += log(theta);\n    else\n      target += log1m(theta) + poisson_lpmf(y[n] | lambda)\n                - poisson_lccdf(0 | lambda));\n\\end{stancode}\n\nJulian King pointed out that because\n\\[\n\\log \\left( 1 - \\distro{PoissonCDF}(0 | \\lambda) \\right)\n\\ = \\ \\log \\left( 1 - \\distro{Poisson}(0 | \\lambda) \\right)\n\\ = \\ \\log(1 - \\exp(-\\lambda))\n\\]\nthe CCDF in the else clause can be replaced with a simpler expression.\n%\n\\begin{stancode}\n      target += log1m(theta) + poisson_lpmf(y[n] | lambda)\n                - log1m_exp(-lambda));\n\\end{stancode}\n%\nThe resulting code is about 15\\% faster than the code with the CCDF.\n\nThis is an example where collecting counts ahead of time can also\ngreatly speed up the execution speed without changing the density.\nFor data size $N=200$ and parameters $\\theta=0.3$ and $\\lambda = 8$,\nthe speedup is a factor of 10; it will be lower for smaller $N$ and\ngreater for larger $N$; it will also be greater for larger $\\theta$.\n\nTo achieve this speedup, it helps to have a function to count the\nnumber of non-zero entries in an array of integers,\n%\n\\begin{stancode}\nfunctions {\n  int num_zero(int[] y) {\n    int nz = 0;\n    for (n in 1:size(y))\n      if (y[n] == 0)\n        nz += 1;\n    return nz;\n  }\n}\n\\end{stancode}\n%\nThen a transformed data block can be used to store the sufficient\nstatistics,\n%\n\\begin{stancode}\ntransformed data {\n  int<lower=0, upper=N> N0 = num_zero(y);\n  int<lower=0, upper=N> Ngt0 = N - N0;\n  int<lower=1> y_nz[N - num_zero(y)];\n  {\n    int pos = 1;\n    for (n in 1:N) {\n      if (y[n] != 0) {\n        y_nz[pos] = y[n];\n        pos += 1;\n      }\n    }\n  }\n}\n\\end{stancode}\n%\nThe model block can then be reduced to three statements.\n%\n\\begin{stancode}\nmodel {\n  N0 ~ binomial(N, theta);\n  y_nz ~ poisson(lambda);\n  target += -Ngt0 * log1m_exp(-lambda);\n}\n\\end{stancode}\n%\nThe first statement accounts for the Bernoulli contribution to both\nthe zero and non-zero counts.  The second line is the Poisson\ncontribution from the non-zero counts, which is now vectorized.\nFinally, the normalization for the truncation is a single line, so\nthat the expression for the log CCDF at 0 isn't repeated.  Also note\nthat the negation is applied to the constant \\code{Ngt0}; whenever\npossible, leave subexpressions constant because then gradients need\nnot be propagated until a non-constant term is encountered.\n\n\n\\section{Priors and Effective Data Size in Mixture Models}\n\nSuppose we have a two-component mixture model with mixing rate\n$\\lambda \\in (0, 1)$.  Because the likelihood for the mixture\ncomponents is proportionally weighted by the mixture weights, the\neffective data size used to estimate each of the mixture components\nwill also be weighted as a fraction of the overall data size.  Thus\nalthough there are $N$ observations, the mixture components will be\nestimated with effective data sizes of $\\theta \\, N$ and $(1 - \\theta)\n\\, N$ for the two components for some $\\theta \\in (0, 1)$.  The\neffective weighting size is determined by posterior responsibility,\nnot simply by the mixing rate $\\lambda$.\n\n\\subsection{Comparison to Model Averaging}\n\nIn contrast to mixture models, which create mixtures at the\nobservation level, model averaging creates mixtures over the\nposteriors of models separately fit with the entire data set.  In this\nsituation, the priors work as expected when fitting the models\nindependently, with the posteriors being based on the complete observed\ndata $y$.\n\nIf different models are expected to account for different\nobservations, we recommend building mixture models directly.  If the\nmodels being mixed are similar, often a single expanded model will\ncapture the features of both and may be used on its own for\ninferential purposes (estimation, decision making, prediction, etc.).\nFor example, rather than fitting an intercept-only regression and a\nslope-only regression and averaging their predictions, even as a\nmixture model, we would recommend building a single regression with\nboth a slope and an intercept.  Model complexity, such as having more\npredictors than data points, can be tamed using appropriately\nregularizing priors.  If computation becomes a bottleneck, the only\nrecourse can be model averaging, which can be calculated after fitting\neach model independently (see \\citep{HoetingEtAl:1999} and\n\\citep{GelmanEtAl:2013} for theoretical and computational details).\n\n\n\\chapter{Measurement Error and Meta-Analysis}\n\n\\noindent\nMost quantities used in statistical models arise from measurements.\nMost of these measurements are taken with some error.  When the\nmeasurement error is small relative to the quantity being measured,\nits effect on a model is usually small.  When measurement error is\nlarge relative to the quantity being measured, or when very precise\nrelations can be estimated being measured quantities, it is useful to\nintroduce an explicit model of measurement error.  One kind of\nmeasurement error is rounding.\n\nMeta-analysis plays out statistically very much like measurement error\nmodels, where the inferences drawn from multiple data sets are\ncombined to do inference over all of them.  Inferences for each data\nset are treated as providing a kind of measurement error with respect\nto true parameter values.\n\n\n\\section{Bayesian Measurement Error Model}\n\nA Bayesian approach to measurement error can be formulated directly by\ntreating the true quantities being measured as missing data\n\\citep{Clayton:1992, RichardsonGilks:1993}.  This requires a model of\nhow the measurements are derived from the true values.\n\n\\subsection{Regression with Measurement Error}\n\nBefore considering regression with measurement error, first consider a\nlinear regression model where the observed data for $N$ cases includes\na predictor $x_n$ and outcome $y_n$.  In Stan, a linear regression for\n$y$ based on $x$ with a slope and intercept is modeled as follows.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N;       // number of cases\n  vector[N] x;          // predictor (covariate)\n  vector[N] y;          // outcome (variate)\n}\nparameters {\n  real alpha;           // intercept\n  real beta;            // slope\n  real<lower=0> sigma;  // outcome noise\n}\nmodel {\n  y ~ normal(alpha + beta * x, sigma);\n  alpha ~ normal(0, 10);\n  beta ~ normal(0, 10);\n  sigma ~ cauchy(0, 5);\n}\n\\end{stancode}\n%\n\nNow suppose that the true values of the predictors $x_n$ are not\nknown, but for each $n$, a measurement $x^{\\mbox{\\footnotesize meas}}_n$ of $x_n$ is available.\nIf the error in measurement can be modeled, the measured value\n$x^{\\mbox{\\footnotesize meas}}_n$ can be modeled in terms of the true value $x_n$ plus measurement\nnoise.  The true value $x_n$ is treated as missing data and estimated\nalong with other quantities in the model.  A very simple approach is\nto assume the measurement error is normal with known deviation $\\tau$.\nThis leads to the following regression model with constant measurement\nerror.\n%\n\\begin{stancode}\ndata {\n  ...\n  real x_meas[N];     // measurement of x\n  real<lower=0> tau;  // measurement noise\n}\nparameters {\n  real x[N];          // unknown true value\n  real mu_x;          // prior location\n  real sigma_x;       // prior scale\n  ...\n}\nmodel {\n  x ~ normal(mu_x, sigma_x);  // prior\n  x_meas ~ normal(x, tau);    // measurement model\n  y ~ normal(alpha + beta * x, sigma);\n  ...\n}\n\\end{stancode}\n%\nThe regression coefficients \\code{alpha} and \\code{beta} and\nregression noise scale \\code{sigma} are the same as before, but now\n\\code{x} is declared as a parameter rather than as data.  The data is\nnow \\code{x\\_meas}, which is a measurement of the true \\code{x} value\nwith noise scale \\code{tau}.  The model then specifies that the\nmeasurement error for \\code{x\\_meas[n]} given true value \\code{x[n]}\nis normal with deviation \\code{tau}.  Furthermore, the true values\n\\code{x} are given a hierarchical prior here.\n\nIn cases where the measurement errors are not normal, richer\nmeasurement error models may be specified.  The prior on the true\nvalues may also be enriched.  For instance, \\citep{Clayton:1992}\nintroduces an exposure model for the unknown (but noisily measured)\nrisk factors $x$ in terms of known (without measurement error) risk\nfactors $c$.  A simple model would regress $x_n$ on the covariates\n$c_n$ with noise term $\\upsilon$,\n\\[\nx_n \\sim \\distro{Normal}(\\gamma^{\\top}c, \\upsilon).\n\\]\nThis can be coded in Stan just like any other regression.  And, of\ncourse, other exposure models can be provided.\n\n\n\\subsection{Rounding}\n\nA common form of measurement error arises from rounding measurements.\nRounding may be done in many ways, such as rounding weights to the\nnearest milligram, or to the nearest pound; rounding may even be done\nby rounding down to the nearest integer.\n\nExercise 3.5(b) from \\citep{GelmanEtAl:2013} provides an example.\n%\n\\begin{quote}\n  3.5. \\ Suppose we weigh an object five times and measure\n  weights, rounded to the nearest pound, of 10, 10, 12, 11, 9.  Assume\n  the unrounded measurements are normally distributed with a\n  noninformative prior distribution on $\\mu$ and $\\sigma^2$.\n  \\\\[4pt]\n  (b) \\ Give the correct posterior distribution for $(\\mu, \\sigma^2)$,\n  treating the measurements as rounded.\n\\end{quote}\n%\nLetting $z_n$ be the unrounded measurement for $y_n$, the problem\nas stated assumes the likelihood\n%\n\\[\nz_n \\sim \\distro{Normal}(\\mu, \\sigma).\n\\]\n%\nThe rounding process entails that $z_n \\in (y_n - 0.5, y_n + 0.5)$.\nThe probability mass function for the discrete observation $y$ is then given\nby marginalizing out the unrounded measurement, producing the likelihood\n\\[\np(y_n \\, | \\, \\mu, \\sigma)\n=\n\\int_{y_n - 0.5}^{y_n + 0.5}\n\\\n\\distro{Normal}(z_n \\, | \\, \\mu, \\sigma)\n\\\n\\mathrm{d}z_n\n=\n\\Phi\\!\\left(\\frac{y_n + 0.5 - \\mu}{\\sigma}\\right)\n-\n\\Phi\\!\\left(\\frac{y_n - 0.5 - \\mu}{\\sigma}\\right).\n\\]\nGelman's answer for this problem took the noninformative prior to be\nuniform in the variance $\\sigma^2$ on the log scale, which yields (due\nto the Jacobian adjustment), the prior density\n\\[\np(\\mu, \\sigma^2) \\propto \\frac{1}{\\sigma^2}.\n\\]\nThe posterior after observing $y = (10, 10, 12, 11, 9)$ can be\ncalculated by Bayes's rule as\n%\n\\begin{eqnarray*}\np(\\mu, \\sigma^2 \\, | \\, y)\n& \\propto &\np(\\mu, \\sigma^2) \\ p(y \\, | \\, \\mu, \\sigma^2)\n\\\\[6pt]\n&  \\propto &\n\\frac{1}{\\sigma^2}\n\\\n\\mathlarger{\\mathlarger{\\prod}}_{n=1}^5\n\\left(\n\\Phi\\!\\left(\\frac{y_n + 0.5 - \\mu}{\\sigma}\\right)\n-\n\\Phi\\!\\left(\\frac{y_n - 0.5 - \\mu}{\\sigma}\\right)\n\\right).\n\\end{eqnarray*}\n%\n\nThe Stan code simply follows the mathematical definition, providing an\nexample of the direct definition of a probability function up to a\nproportion.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N;\n  vector[N] y;\n}\nparameters {\n  real mu;\n  real<lower=0> sigma_sq;\n}\ntransformed parameters {\n  real<lower=0> sigma;\n  sigma = sqrt(sigma_sq);\n}\nmodel {\n  target += -2 * log(sigma);\n  for (n in 1:N)\n    target += log(Phi((y[n] + 0.5 - mu) / sigma)\n                  - Phi((y[n] - 0.5 - mu) / sigma));\n}\n\\end{stancode}\n\nAlternatively, the model may be defined with latent parameters for the\nunrounded measurements $z_n$.  The Stan code in this case uses the\nlikelihood for $z_n$ directly while respecting the constraint $z_n \\in\n(y_n - 0.5, y_n + 0.5)$.  Because Stan does not allow varying upper-\nand lower-bound constraints on the elements of a vector (or array),\nthe parameters are declared to be the rounding error $y - z$, and\nthen $z$ is defined as a transformed parameter.\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N;\n  vector[N] y;\n}\nparameters {\n  real mu;\n  real<lower=0> sigma_sq;\n  vector<lower=-0.5, upper=0.5>[N] y_err;\n}\ntransformed parameters {\n  real<lower=0> sigma;\n  vector[N] z;\n  sigma = sqrt(sigma_sq);\n  z = y + y_err;\n}\nmodel {\n  target += -2 * log(sigma);\n  z ~ normal(mu, sigma);\n}\n\\end{stancode}\n%\nThis explicit model for the unrounded measurements $z$ produces the\nsame posterior for $\\mu$ and $\\sigma$ as the previous model that\nmarginalizes $z$ out.  Both approaches mix well, but the latent\nparameter version is about twice as efficient in terms of effective\nsamples per iteration, as well as providing a posterior for the\nunrounded parameters.\n\n\n\\section{Meta-Analysis}\n\nMeta-analysis aims to pool the data from several studies, such as the\napplication of a tutoring program in several schools or treatment\nusing a drug in several clinical trials.\n\nThe Bayesian framework is particularly convenient for meta-analysis,\nbecause each previous study can be treated as providing a noisy\nmeasurement of some underlying quantity of interest.  The model then\nfollows directly from two components, a prior on the underlying\nquantities of interest and a measurement-error style model for each of\nthe studies being analyzed.\n\n\\subsection{Treatment Effects in Controlled Studies}\n\nSuppose the data in question arise from a total of $M$ studies\nproviding paired binomial data for a treatment and control group.  For\ninstance, the data might be post-surgical pain reduction under a treatment\nof ibuprofen \\citep{WarnThompsonSpiegelhalter:2002} or mortality after\nmyocardial infarction under a treatment of beta blockers\n\\citep[Section~5.6]{GelmanEtAl:2013}.\n\n\\subsubsection{Data}\n\nThe clinical data consists of $J$ trials, each with $n^t$ treatment\ncases, $n^c$ control cases, $r^t$ successful outcomes among those treated and\n$r^c$ successful outcomes among those in the control group.  This data\ncan be declared in Stan as follows.%\n%\n\\footnote{Stan's integer constraints are not powerful enough to express the\nconstraint that $\\mbox{\\code{r\\_t[j]}} \\leq \\mbox{\\code{n\\_t[j]}}$,\nbut this constraint could be checked in the transformed data block.}\n%\n\\begin{stancode}\ndata {\n  int<lower=0> J;\n  int<lower=0> n_t[J];  // num cases, treatment\n  int<lower=0> r_t[J];  // num successes, treatment\n  int<lower=0> n_c[J];  // num cases, control\n  int<lower=0> r_c[J];  // num successes, control\n}\n\\end{stancode}\n%\n\n\\subsubsection{Converting to Log Odds and Standard Error}\n\nAlthough the clinical trial data is binomial in its raw format, it may\nbe transformed to an unbounded scale by considering the log odds ratio\n\\[\ny_j = \\log \\left( \\frac{r^t_j / (n^t_j - r^t_j)}\n                       {r^c_j / (n^c_j - r^c_j)} \\right)\n\\ \\ = \\ \\\n\\log \\left( \\frac{r^t_j}{n^t_j - r^t_j} \\right)\n-\n\\log \\left( \\frac{r^c_j}{n^c_j - r^c_j} \\right)\n\\]\nand corresponding standard errors\n\\[\n\\sigma_j = \\sqrt{\n\\frac{1}{r^T_i}\n+ \\frac{1}{n^T_i - r^T_i}\n+ \\frac{1}{r^C_i}\n+ \\frac{1}{n^C_i - r^C_i}\n}.\n\\]\n%\nThe log odds and standard errors can be defined in a\ntransformed parameter block, though care must be taken not to use\ninteger division (see \\refsection{int-arithmetic}).\n%\n\\begin{stancode}\ntransformed data {\n  real y[J];\n  real<lower=0> sigma[J];\n  for (j in 1:J)\n    y[j] = log(r_t[j]) - log(n_t[j] - r_t[j])\n            - (log(r_c[j]) - log(n_c[j] - r_c[j]);\n  for (j in 1:J)\n    sigma[j] = sqrt(1 / r_t[j] + 1 / (n_t[j] - r_t[j])\n                     + 1 / r_c[j] + 1 / (n_c[j] - r_c[j]));\n}\n\\end{stancode}\n%\nThis definition will be problematic if any of the success counts is\nzero or equal to the number of trials.\nIf that arises, a direct binomial model will be required or other\ntransforms must be used than the unregularized sample log odds.\n\n\\subsubsection{Non-Hierarchical Model}\n\nWith the transformed data in hand, two standard forms of meta-analysis\ncan be applied.  The first is a so-called ``fixed effects'' model,\nwhich assumes a single parameter for the global odds ratio.  This\nmodel is coded in Stan as follows.\n%\n\\begin{stancode}\nparameters {\n  real theta;  // global treatment effect, log odds\n}\nmodel {\n  y ~ normal(theta, sigma);\n}\n\\end{stancode}\n%\nThe sampling statement for \\code{y} is vectorized; it has the same\neffect as the following.\n\\begin{stancode}\n  for (j in 1:J)\n    y[j] ~ normal(theta, sigma[j]);\n\\end{stancode}\n%\nIt is common to include a prior for \\code{theta} in this model, but it\nis not strictly necessary for the model to be proper because \\code{y}\nis fixed and $\\distro{Normal}(y|\\mu,\\sigma) =\n\\distro{Normal}(\\mu|y,\\sigma)$.\n\n\\subsubsection{Hierarchical Model}\n\nTo model so-called ``random effects,'' where the treatment effect may\nvary by clinical trial, a hierarchical model can be used.  The\nparameters include per-trial treatment effects and the hierarchical\nprior parameters, which will be estimated along with other unknown\nquantities.\n%\n\\begin{stancode}\nparameters {\n  real theta[J];      // per-trial treatment effect\n  real mu;            // mean treatment effect\n  real<lower=0> tau;  // deviation of treatment effects\n}\nmodel {\n  y ~ normal(theta, sigma);\n  theta ~ normal(mu, tau);\n  mu ~ normal(0, 10);\n  tau ~ cauchy(0, 5);\n}\n\\end{stancode}\n%\nAlthough the vectorized sampling statement for \\code{y} appears\nunchanged, the parameter \\code{theta} is now a vector.  The sampling\nstatement for \\code{theta} is also vectorized, with the\nhyperparameters \\code{mu} and \\code{tau} themselves being given wide\npriors compared to the scale of the data.\n\n\\citet{Rubin:1981} provided a hierarchical Bayesian meta-analysis of\nthe treatment effect of Scholastic Aptitude Test (SAT) coaching in\neight schools based on the sample treatment effect and standard error\nin each school.%\n%\n\\footnote{The model provided for this data in\n\\citep[Section~5.5]{GelmanEtAl:2013} is included with the\ndata in the Stan example model repository,\n\\url{http://mc-stan.org/users/documentation}.}\n\n\\subsubsection{Extensions and Alternatives}\n\n\\citet{SmithSpiegelhalterThomas:1995} and\n\\citet[Section~19.4]{GelmanEtAl:2013} provide\nmeta-analyses based directly on binomial data.\n\\citet{WarnThompsonSpiegelhalter:2002} consider the modeling\nimplications of using alternatives to the log-odds ratio in\ntransforming the binomial data.\n\nIf trial-specific predictors are available, these can be included\ndirectly in a regression model for the per-trial treatment effects\n$\\theta_j$.\n\n\n\\chapter{Latent Discrete Parameters}\\label{latent-discrete.chapter}\n\n\\noindent\nStan does not support sampling discrete parameters.  So it is not\npossible to directly translate BUGS or JAGS models with discrete\nparameters (i.e., discrete stochastic nodes).  Nevertheless, it is\npossible to code many models that involve bounded discrete\nparameters by marginalizing out the discrete parameters.%\n%\n\\footnote{The computations are similar to those involved in\n  expectation maximization (EM) algorithms\n  \\citep{dempster-et-al:1977}.}\n%\nThis chapter shows how to code several widely-used models involving\nlatent discrete parameters.  The next chapter,\n\\refchapter{clustering}, on clustering models, considers further\nmodels involving latent discrete parameters.\n\n\\section{The Benefits of Marginalization}\\label{rao-blackwell.section}\n\nAlthough it requires some algebra on the joint probability function,\na pleasant byproduct of the required calculations is the posterior\nexpectation of the marginalized variable, which is often the quantity\nof interest for a model.  This allows far greater exploration of the\ntails of the distribution as well as more efficient sampling on an\niteration-by-iteration basis because the expectation at all possible\nvalues is being used rather than itself being estimated through\nsampling a discrete parameter.\n\nStandard optimization algorithms, including expectation maximization\n(EM), are often provided in applied statistics papers to describe\nmaximum likelihood estimation algorithms.  Such derivations provide\nexactly the marginalization needed for coding the model in Stan.\n\n\\section{Change Point Models}\n\nThe first example is a model of coal mining disasters in the U.K.\\\nfor the years 1851--1962.%\n%\n\\footnote{The original source of the data is \\citep{Jarret:1979},\n  which itself is a note correcting an earlier data collection.}\n%\n\n\\subsection{Model with Latent Discrete Parameter}\n\n\\citep[Section 3.1]{PyMC:2014} provide a Poisson model of disaster\nrate $D_t$ in year $t$ with two rate parameters, an early rate ($e$)\nand late rate ($l$), that change at a given point in time $s$.  The\nfull model expressed using a latent discrete parameter $s$ is\n%\n\\begin{eqnarray*}\ne & \\sim & \\distro{Exponential}(r_e)\n\\\\\nl & \\sim & \\distro{Exponential}(r_l)\n\\\\\ns & \\sim & \\distro{Uniform}(1, T)\n\\\\\nD_t & \\sim & \\distro{Poisson}(t < s \\ ? \\ e \\ : \\ l)\n\\end{eqnarray*}\n%\nThe last line uses the conditional operator (also known as the ternary\noperator), which is borrowed from C and related languages.  The\nconditional operator has the same behavior as the \\code{ifelse}\nfunction in R, but uses a more compact notation involving separating\nits three arguments by a question mark (\\code{?})  and colon\n(\\code{:}).  The conditional operator is defined by\n%\n\\[\nc \\ ? \\ x_1 \\ : \\ x_2\n=\n\\begin{cases}\n\\ x_1 & \\mbox{if } c \\mbox{ is true (i.e., non-zero), and}\n\\\\\n\\ x_2 & \\mbox{if } c \\mbox{ is false (i.e., zero).}\n\\end{cases}\n\\]\nAs of version 2.10, Stan supports the conditional operator.\n\n\n\\subsection{Marginalizing out the Discrete Parameter}\n\nTo code this model in Stan, the discrete parameter $s$ must be\nmarginalized out to produce a model defining the log of the\nprobability function $p(e,l,D_t)$.  The full joint probability factors\nas\n%\n\\begin{eqnarray*}\np(e,l,s,D)\n& = & p(e) \\, p(l) \\, p(s) \\, p(D | s, e, l)\n\\\\[3pt]\n& = &\n\\begin{array}[t]{l}\n\\distro{Exponential}(e|r_e) \\ \\distro{Exponential}(l|r_l) \\\n\\distro{Uniform}(s|1, T)\n\\\\[3pt]\n\\prod_{t=1}^T \\distro{Poisson}(D_t | t < s \\ ? \\ e \\ : \\ l),\n\\end{array}\n\\end{eqnarray*}\n%\nTo marginalize, an alternative factorization into prior and likelihood\nis used,\n%\n\\begin{eqnarray*}\np(e,l,D) & = & p(e,l) \\, p(D|e,l),\n\\end{eqnarray*}\n%\nwhere the likelihood is defined by marginalizing $s$ as\n%\n\\begin{eqnarray*}\np(D | e,l)\n& = &\n\\sum_{s=1}^T p(s, D | e,l)\n\\\\[3pt]\n& = &\n\\sum_{s=1}^T p(s) p(D | s,e,l)\n\\\\[3pt]\n& = &\n\\sum_{s=1}^T \\distro{Uniform}(s | 1,T)\n\\, \\prod_{t=1}^T \\distro{Poisson}(D_t | t < s \\ ? \\ e \\ : \\ l)\n\\end{eqnarray*}\n%\nStan operates on the log scale and thus requires the log likelihood,\n%\n\\[\n\\log p(D | e,l)\n\\\\[3pt]\n\\mbox{ } \\ \\ = \\\n\\mbox{log\\_sum\\_exp}_{s=1}^T\n\\begin{array}[t]{l}\n\\big(\n \\log \\distro{Uniform}(s \\, | \\, 1, T)\n\\\\[3pt]\n{} \\hspace*{4pt} + \\sum_{t=1}^T \\log \\distro{Poisson}(D_t \\, | \\, t < s \\ ?\n\\ e \\ : \\ l) \\big),\n\\end{array}\n\\]\n%\nwhere the log sum of exponents function is defined by\n\\[\n\\mbox{log\\_sum\\_exp}_{n=1}^N \\, \\alpha_n\n\\ = \\\n\\log \\sum_{n=1}^N \\mbox{exp}(\\alpha_n).\n\\]\n%\nThe log sum of exponents function allows the model to be coded\ndirectly in Stan using the built-in function \\code{log\\_sum\\_exp},\nwhich provides both arithmetic stability and efficiency for mixture\nmodel calculations.\n\n\n\\subsection{Coding the Model in Stan}\n\nThe Stan program for the change point model is shown in\n\\reffigure{change-point-model}.  The transformed parameter\n\\code{lp[s]} stores the quantity $\\log p(s, D \\, | \\, e, l)$.\n%\n\\begin{figure}\n\\begin{stancode}\ndata {\n  real<lower=0> r_e;\n  real<lower=0> r_l;\n\n  int<lower=1> T;\n  int<lower=0> D[T];\n}\ntransformed data {\n  real log_unif;\n  log_unif = -log(T);\n}\nparameters {\n  real<lower=0> e;\n  real<lower=0> l;\n}\ntransformed parameters {\n  vector[T] lp;\n  lp = rep_vector(log_unif, T);\n  for (s in 1:T)\n    for (t in 1:T)\n      lp[s] = lp[s] + poisson_lpmf(D[t] | t < s ? e : l);\n}\nmodel {\n  e ~ exponential(r_e);\n  l ~ exponential(r_l);\n  target += log_sum_exp(lp);\n}\n\\end{stancode}\n\\vspace*{-6pt}\n\\caption{\\small\\it A change point model in which disaster rates\n  \\code{D[t]} have one rate, \\code{e}, before the change point and a\n  different rate, \\code{l}, after the change point.  The change point\n  itself, \\code{s}, is marginalized out as described in the\n  text.}\\label{change-point-model.figure}\n\\end{figure}\n\nAlthough the model in \\reffigure{change-point-model} is easy to\nunderstand, the doubly nested loop used for \\code{s} and \\code{t} is\nquadratic in \\code{T}.  Luke Wiklendt pointed out that a linear\nalternative can be achieved by the use of dynamic programming similar\nto the forward-backward algorithm for Hidden Markov models;  he\nsubmitted a slight variant of the following code to replace the\ntransformed parameters block of the above Stan program.\n%\n\\begin{stancode}\ntransformed parameters {\n    vector[T] lp;\n    {\n      vector[T + 1] lp_e;\n      vector[T + 1] lp_l;\n      lp_e[1] = 0;\n      lp_l[1] = 0;\n      for (t in 1:T) {\n        lp_e[t + 1] = lp_e[t] + poisson_lpmf(D[t] | e);\n        lp_l[t + 1] = lp_l[t] + poisson_lpmf(D[t] | l);\n      }\n      lp = rep_vector(log_unif + lp_l[T + 1], T)\n           + head(lp_e, T) - head(lp_l, T);\n    }\n  }\n\\end{stancode}\n%\nAs should be obvious from looking at it, it has linear complexity in\n\\code{T} rather than quadratic.  The result for the mining-disaster\ndata is about 20 times faster;  the improvement will be greater for\nlarger \\code{T}.\n\nThe key to understanding Wiklendt's dynamic programming version is to\nsee that \\code{head(lp\\_e)} holds the forward values, whereas\n\\code{lp\\_l[T + 1] - head(lp\\_l, T)} holds the backward values; the\nclever use of subtraction allows \\code{lp\\_l} to be accumulated\nnaturally in the forward direction.\n\n\n\\subsection{Fitting the Model with MCMC}\n\nThis model is easy to fit using MCMC with NUTS in its default\nconfiguration.  Convergence is very fast and sampling produces roughly\none effective sample every two iterations.  Because it is a relatively\nsmall model (the inner double loop over time is roughly 20,000 steps),\nit is very fast.\n\nThe value of \\code{lp} for each iteration for each change point is\navailable because it is declared as a transformed parameter.  If the\nvalue of \\code{lp} were not of interest, it could be coded as a local\nvariable in the model block and thus avoid the I/O overhead of saving\nvalues every iteration.\n\n\\subsection{Posterior Distribution of the Discrete Change Point}\n\nThe value of \\code{lp[s]} in a given iteration is given by $\\log\np(s,D|e,l)$ for the values of the early and late rates, $e$ and $l$,\nin the iteration.  In each iteration after convergence, the early and\nlate disaster rates, $e$ and $l$, are drawn from the posterior\n$p(e,l|D)$ by MCMC sampling and the associated \\code{lp} calculated.\nThe value of \\code{lp} may be normalized to calculate $p(s|e,l,D)$ in\neach iteration, based on on the current values of $e$ and $l$.\nAveraging over iterations provides an unnormalized probability\nestimate of the change point being $s$ (see below for the normalizing\nconstant),\n%\n\\begin{eqnarray*}\np(s | D)\n& \\propto &\nq(s | D)\n\\\\[3pt]\n& = &\n\\frac{1}{M} \\sum_{m=1}^{M} \\exp(\\code{lp}[m,s]).\n\\end{eqnarray*}\n%\nwhere $\\mbox{\\code{lp}}[m,s]$ represents the value of \\code{lp} in\nposterior draw $m$ for change point $s$.  By averaging over draws,\n$e$ and $l$ are themselves marginalized out, and the result has no\ndependence on a given iteration's value for $e$ and $l$.  A final\nnormalization then produces the quantity of interest, the posterior\nprobability of the change point being $s$ conditioned on the data $D$,\n%\n\\[\np(s | D)\n=\n\\frac{q(s|D)}{\\sum_{s'=1}^T q(s' | D)}.\n\\]\n%\nA plot of the values of $\\log p(s|D)$ computed using Stan 2.4's\ndefault MCMC implementation is shown in\n\\reffigure{change-point-posterior}.\n%\n\\begin{figure}\n\\begin{center}\n\\includegraphics[height=2in]{img/change-point-posterior.pdf}\n\\ \\ \\ \\ \\\n\\includegraphics[height=2in]{img/s-discrete-posterior.pdf}\n\\end{center}\n\\vspace*{-12pt}\n\\caption{\\small\\it The posterior estimates for the change point.  \\\n  {\\rm Left)} log probability of change point being in year,\n  calculated analytically using \\code{lp}; \\ {\\rm Right)}\\ frequency\n  of change point draws in the posterior generated using\n  \\code{lp}. The plot on the left is on the log scale and the plot on\n  the right on the linear scale; note the narrower range of years in\n  the right-hand plot resulting from sampling. The posterior mean of\n  $s$ is roughly 1891.}%\n\\label{change-point-posterior.figure}\n\\end{figure}\n%\n\n\n\n\\subsection{Discrete Sampling}\n\nThe generated quantities block may be used to draw discrete parameter\nvalues using the built-in pseudo-random number generators.  For\nexample, with \\code{lp} defined as above, the following program\ndraws a random value for \\code{s} at every iteration.\n%\n\\begin{stancode}\ngenerated quantities {\n  int<lower=1,upper=T> s;\n  s = categorical_logit_rng(lp);\n}\n\\end{stancode}\n%\nA posterior histogram of draws for $s$ is shown on the right side of\n\\reffigure{change-point-posterior}.\n\nCompared to working in terms of expectations, discrete sampling is\nhighly inefficient, especially for tails of distributions, so this\napproach should only be used if draws from a distribution are\nexplicitly required.   Otherwise, expectations should be computed in\nthe generated quantities block based on the posterior distribution for\n\\code{s} given by \\code{softmax(lp)}.\n\n\n\\subsection{Posterior Covariance}\n\nThe discrete sample generated for $s$ can be used to calculate\ncovariance with other parameters.  Although the sampling approach is\nstraightforward, it is more statistically efficient (in the sense of\nrequiring far fewer iterations for the same degree of accuracy) to\ncalculate these covariances in expectation using \\code{lp}.\n\n\n\\subsection{Multiple Change Points}\n\nThere is no obstacle in principle to allowing multiple change points.\nThe only issue is that computation increases from linear to quadratic\nin marginalizing out two change points, cubic for three change points,\nand so on.  There are three parameters, \\code{e}, \\code{m}, and\n\\code{l}, and two loops for the change point and then one over time,\nwith log densities being stored in a matrix.\n%\n\\begin{stancode}\nmatrix[T, T] lp;\nlp = rep_matrix(log_unif, T);\nfor (s1 in 1:T)\n  for (s2 in 1:T)\n    for (t in 1:T)\n      lp[s1,s2] = lp[s1,s2]\n        + poisson_lpmf(D[t] | t < s1 ? e : (t < s2 ? m : l));\n\\end{stancode}\n%\nThe matrix can then be converted back to a vector using\n\\code{to\\_vector} before being passed to \\code{log\\_sum\\_exp}.\n\n\\section{Mark-Recapture Models}\n\nA widely applied field method in ecology is to capture (or sight)\nanimals, mark them (e.g., by tagging), then release them.  This\nprocess is then repeated one or more times, and is often done for\npopulations on an ongoing basis.  The resulting data may be used to\nestimate population size.\n\nThe first subsection describes a very simple mark-recapture model that does\nnot involve any latent discrete parameters.  The following subsections\ndescribes the Cormack-Jolly-Seber model, which involves latent\ndiscrete parameters for animal death.\n\n\\subsection{Simple Mark-Recapture Model}\n\nIn the simplest case, a one-stage mark-recapture study produces the\nfollowing data\n%\n\\begin{itemize}\n\\item $M$ : number of animals marked in first capture,\n\\item $C$ : number animals in second capture, and\n\\item $R$ : number of marked animals in second capture.\n\\end{itemize}\n%\nThe estimand of interest is\n%\n\\begin{itemize}\n\\item $N$ : number of animals in the population.\n\\end{itemize}\n%\nDespite the notation, the model will take $N$ to be a continuous\nparameter; just because the population must be finite doesn't mean the\nparameter representing it must be.  The parameter will be used to\nproduce a real-valued estimate of the population size.\n\nThe Lincoln-Petersen \\citep{Lincoln:1930,Petersen:1896} method for\nestimating population size is\n%\n\\[\n\\hat{N} = \\frac{M C}{R}.\n\\]\n%\nThis population estimate would arise from a probabilistic model in\nwhich the number of recaptured animals is distributed binomially,\n\\[\nR \\sim \\distro{Binomial}(C, M / N)\n\\]\ngiven the total number of animals captured in the second round ($C$)\nwith a recapture probability of $M/N$, the fraction of the total\npopulation $N$ marked in the first round.\n\n%\n\\begin{figure}\n\\begin{stancode}\ndata {\n  int<lower=0> M;\n  int<lower=0> C;\n  int<lower=0,upper=min(M,C)> R;\n}\nparameters {\n  real<lower=(C - R + M)> N;\n}\nmodel {\n  R ~ binomial(C, M / N);\n}\n\\end{stancode}\n\\vspace*{-6pt}\n\\caption{\\small\\it A probabilistic formulation of the Lincoln-Petersen\nestimator for population size based on data from a one-step\nmark-recapture study.  The lower bound on $N$ is necessary to\nefficiently eliminate impossible values.}%\n\\label{lincoln-petersen-model.figure}\n\\end{figure}\n%\nThe probabilistic variant of the Lincoln-Petersen estimator can be\ndirectly coded in Stan as shown in \\reffigure{lincoln-petersen-model}.\nThe Lincoln-Petersen estimate is the maximum likelihood estimate (MLE)\nfor this model.\n\nTo ensure the MLE is the Lincoln-Petersen estimate, an improper\nuniform prior for $N$ is used; this could (and should) be replaced\nwith a more informative prior if possible based on knowledge of the\npopulation under study.\n\nThe one tricky part of the model is the lower bound $C - R + M$ placed\non the population size $N$.  Values below this bound are impossible\nbecause it is otherwise not possible to draw $R$ samples out of the\n$C$ animals recaptured.  Implementing this lower bound is necessary to\nensure sampling and optimization can be carried out in an\nunconstrained manner with unbounded support for parameters on the\ntransformed (unconstrained) space.  The lower bound in the declaration\nfor $C$ implies a variable transform $f : (C-R+M,\\infty) \\rightarrow\n(-\\infty,+\\infty)$ defined by $f(N) = \\log(N - (C - R + M))$; see\n\\refsection{lower-bound-transform} for more information on the\ntransform used for variables declared with a lower bound.\n\n\\subsection{Cormack-Jolly-Seber with Discrete Parameter}\n\nThe Cormack-Jolly-Seber (CJS) model\n\\citep{Cormack:1964,Jolly:1965,Seber:1965} is an open-population model\nin which the population may change over time due to death; the\npresentation here draws heavily on \\citep{Schofield:2007}.\n\nThe basic data is\n%\n\\begin{itemize}\n\\item $I$ : number of individuals,\n\\item $T$ : number of capture periods, and\n\\item $y_{i,t}$ : boolean indicating if individual $i$ was captured at\n  time $t$.\n\\end{itemize}\n%\nEach individual is assumed to have been captured at least once because\nan individual only contributes information conditionally after they\nhave been captured the first time.\n\nThere are two Bernoulli parameters in the model,\n%\n\\begin{itemize}\n\\item $\\phi_t$ : probability that animal alive at time $t$ survives\n  until $t + 1$ and\n\\item $p_t$ : probability that animal alive at time $t$ is captured at\n  time $t$.\n\\end{itemize}\n%\nThese parameters will both be given uniform priors, but information\nshould be used to tighten these priors in practice.\n\nThe CJS model also employs a latent discrete parameter $z_{i,t}$\nindicating for each individual $i$ whether it is alive at time $t$,\ndistributed as\n%\n\\[\nz_{i,t} \\sim \\distro{Bernoulli}(\\ternary{z_{i,t-1}}{0}{\\phi_{t-1}}).\n\\]\n%\nThe conditional prevents the model positing zombies; once an animal is\ndead, it stays dead.  The data distribution is then simple to express\nconditional on $z$ as\n%\n\\[\ny_{i,t} \\sim \\distro{Bernoulli}(\\ternary{z_{i,t}}{0}{p_t})\n\\]\n%\nThe conditional enforces the constraint that dead animals cannot be captured.\n\n\n\\subsection{Collective Cormack-Jolly-Seber Model}\n\nThis subsection presents an implementation of the model in terms of\ncounts for different history profiles for individuals over three\ncapture times. It assumes exchangeability of the animals in that each\nis assigned the same capture and survival probabilities.\n\nIn order to ease the marginalization of the latent discrete parameter\n$z_{i,t}$, the Stan models rely on a derived quantity $\\chi_t$ for\nthe probability that an individual is never captured again if it is\nalive at time $t$ (if it is dead, the recapture probability is zero).\nthis quantity is defined recursively by\n\\[\n\\chi_t\n=\n\\begin{cases}\n1\n& \\mbox{if } t = T\n\\\\[3pt]\n(1 - \\phi_t) + \\phi_t (1 - p_{t+1}) \\chi_{t+1}\n& \\mbox{ if } t < T\n\\end{cases}\n\\]\n%\nThe base case arises because if an animal was captured in the last\ntime period, the probability it is never captured again is 1 because\nthere are no more capture periods.  The recursive case defining\n$\\chi_{t}$ in terms of $\\chi_{t+1}$ involves two possibilities: (1)\nnot surviving to the next time period, with probability $(1 -\n\\phi_t)$, or (2) surviving to the next time period with probability\n$\\phi_t$, not being captured in the next time period with probability\n$(1 - p_{t+1})$, and not being captured again after being alive in\nperiod $t+1$ with probability $\\chi_{t+1}$.\n\nWith three capture times, there are three captured/not-captured\nprofiles an individual may have.  These may be naturally coded as\nbinary numbers as follows.\n%\n\\begin{center}\n\\begin{tabular}{c|ccc|c}\n& \\multicolumn{3}{|c|}{{\\it captures}}\n\\\\\n{\\it profile} & 1 & 2 & 3 & {\\it probability}\n\\\\ \\hline\n{0} & - & - & - & n/a\n\\\\\n{1} & - & - & + & n/a\n\\\\ \\hline\n{2} & - & + & - & $\\chi_2$\n\\\\\n{3} & - & + & + & $\\phi_2 \\, p_3$\n\\\\ \\hline\n{4} & + & - & - & $\\chi_1$\n\\\\\n{5} & + & - & + & $\\phi_1 \\, (1 - p_2) \\, \\phi_2 \\, p_3$\n\\\\ \\hline\n{6} & + & + & - & $ \\phi_1 \\, p_2 \\, \\chi_2$\n\\\\\n{7} & + & + & + & $\\phi_1 \\, p_2 \\, \\phi_2 \\, p_3$\n\\end{tabular}\n\\end{center}\n%\nHistory 0, for animals that are never captured, is unobservable\nbecause only animals that are captured are observed. History 1, for\nanimals that are only captured in the last round, provides no\ninformation for the CJS model, because capture/non-capture status is\nonly informative when conditioned on earlier captures.  For the\nremaining cases, the contribution to the likelihood is provided in the\nfinal column.\n\nBy defining these probabilities in terms of $\\chi$ directly, there is\nno need for a latent binary parameter indicating whether an animal is\nalive at time $t$ or not.  The definition of $\\chi$ is typically used\nto define the likelihood (i.e., marginalize out the latent discrete\nparameter) for the CJS model \\citep[page 9]{Schofield:2007}.\n\nThe Stan model defines $\\chi$ as a transformed parameter based on\nparameters $\\phi$ and $p$.  In the model block, the log probability is\nincremented for each history based on its count.  This second step is\nsimilar to collecting Bernoulli observations into a binomial or\ncategorical observations into a multinomial, only it is coded directly\nin the Stan program using \\code{target~+=} rather than\nbeing part of a built-in probability function.\n%\n\\begin{figure}\n\\begin{stancode}\ndata {\n  int<lower=0> history[7];\n}\nparameters {\n  real<lower=0,upper=1> phi[2];\n  real<lower=0,upper=1> p[3];\n}\ntransformed parameters {\n  real<lower=0,upper=1> chi[2];\n  chi[2] = (1 - phi[2]) + phi[2] * (1 - p[3]);\n  chi[1] = (1 - phi[1]) + phi[1] * (1 - p[2]) * chi[2];\n}\nmodel {\n  target += history[2] * log(chi[2]);\n  target += history[3] * (log(phi[2]) + log(p[3]));\n  target += history[4] * (log(chi[1]));\n  target += history[5] * (log(phi[1]) + log1m(p[2])\n                            + log(phi[2]) + log(p[3]));\n  target += history[6] * (log(phi[1]) + log(p[2])\n                            + log(chi[2]));\n  target += history[7] * (log(phi[1]) + log(p[2])\n                            + log(phi[2]) + log(p[3]));\n}\ngenerated quantities {\n  real<lower=0,upper=1> beta3;\n  beta3 = phi[2] * p[3];\n}\n\\end{stancode}\n\\vspace*{-12pt}\n\\caption{\\small\\it A Stan program for the Cormack-Jolly-Seber\n  mark-recapture model that considers counts of individuals with\n  observation histories of being observed or not in three capture\n  periods.}\\label{cjs-history.figure}\n\\end{figure}\n%\n\n\\subsubsection{Identifiability}\n\nThe parameters $\\phi_2$ and $p_3$, the probability of death at time 2\nand probability of capture at time 3 are not identifiable, because both\nmay be used to account for lack of capture at time 3.  Their product,\n$\\beta_3 = \\phi_2 \\, p_3$, is identified.  The Stan model defines\n\\code{beta3} as a generated quantity.  Unidentified parameters pose a\nproblem for Stan's samplers' adaptation.  Although the problem posed\nfor adaptation is mild here because the parameters are bounded and\nthus have proper uniform priors, it would be better to formulate an\nidentified parameterization.  One way to do this would be to formulate\na hierarchical model for the $p$ and $\\phi$ parameters.\n\n\\subsection{Individual Cormack-Jolly-Seber Model}\n\nThis section presents a version of the Cormack-Jolly-Seber (CJS) model\ncast at the individual level rather than collectively as in the\nprevious subsection.  It also extends the model to allow an arbitrary\nnumber of time periods.  The data will consist of the number $T$ of\ncapture events, the number $I$ of individuals, and a boolean flag\n$y_{i,t}$ indicating if individual $i$ was observed at time $t$.  In\nStan,\n%\n\\begin{stancode}\ndata {\n  int<lower=2> T;\n  int<lower=0> I;\n  int<lower=0,upper=1> y[I, T];\n}\n\\end{stancode}\n\nThe advantages to the individual-level model is that it becomes\npossible to add individual ``random effects'' that affect survival or\ncapture probability, as well as to avoid the combinatorics involved in\nunfolding $2^T$ observation histories for $T$ capture times.\n\n\\subsubsection{Utility Functions}\n\nThe individual CJS model is written involves several function\ndefinitions.  The first two are used in the transformed data block to\ncompute the first and last time period in which an animal was\ncaptured.%\n%\n\\footnote{An alternative would be to compute this on the outside and\nfeed it into the Stan model as preprocessed data.  Yet another\nalternative encoding would be a sparse one recording only the\ncapture events along with their time and identifying the individual\ncaptured.}\n%\n\\begin{stancode}\nfunctions {\n  int first_capture(int[] y_i) {\n    for (k in 1:size(y_i))\n      if (y_i[k])\n        return k;\n    return 0;\n  }\n  int last_capture(int[] y_i) {\n    for (k_rev in 0:(size(y_i) - 1)) {\n      int k;\n      k = size(y_i) - k_rev;\n      if (y_i[k])\n        return k;\n    }\n    return 0;\n  }\n  ...\n}\n\\end{stancode}\n%\nThese two functions are used to define the first and last capture time\nfor each individual in the transformed data block.%\n%\n\\footnote{Both functions return 0 if the individual represented by the\n  input array was never captured.  Individuals with no captures are\n  not relevant for estimating the model because all probability\n  statements are conditional on earlier captures.  Typically they\n  would be removed from the data, but the program allows them to be\n  included even though they make not contribution to the log\n  probability function.}\n%\n\\begin{stancode}\ntransformed data {\n  int<lower=0,upper=T> first[I];\n  int<lower=0,upper=T> last[I];\n  vector<lower=0,upper=I>[T] n_captured;\n  for (i in 1:I)\n    first[i] = first_capture(y[i]);\n  for (i in 1:I)\n    last[i] = last_capture(y[i]);\n  n_captured = rep_vector(0, T);\n  for (t in 1:T)\n    for (i in 1:I)\n      if (y[i, t])\n        n_captured[t] = n_captured[t] + 1;\n}\n\\end{stancode}\n%\nThe transformed data block also defines \\code{n\\_captured[t]}, which is\nthe total number of captures at time \\code{t}.  The variable\n\\code{n\\_captured} is defined as a vector instead of an integer array\nso that it can be used in an elementwise vector operation in the generated\nquantities block to model the population estimates at each time point.\n\nThe parameters and transformed parameters are as before, but now there\nis a function definition for computing the entire vector \\code{chi}, the\nprobability that if an individual is alive at \\code{t} that it will\nnever be captured again.\n%\n\\begin{stancode}\nparameters {\n  vector<lower=0,upper=1>[T-1] phi;\n  vector<lower=0,upper=1>[T] p;\n}\ntransformed parameters {\n  vector<lower=0,upper=1>[T] chi;\n  chi = prob_uncaptured(T,p,phi);\n}\n\\end{stancode}\n%\nThe definition of \\code{prob\\_uncaptured}, from the functions block,\nis\n%\n\\begin{stancode}\nfunctions {\n  ...\n  vector prob_uncaptured(int T, vector p, vector phi) {\n    vector[T] chi;\n    chi[T] = 1.0;\n    for (t in 1:(T - 1)) {\n      int t_curr;\n      int t_next;\n      t_curr = T - t;\n      t_next = t_curr + 1;\n      chi[t_curr] = (1 - phi[t_curr])\n                     + phi[t_curr]\n                       * (1 - p[t_next])\n                       * chi[t_next];\n    }\n    return chi;\n  }\n}\n\\end{stancode}\n%\nThe function definition directly follows the mathematical definition\nof $\\chi_t$, unrolling the recursion into an iteration and\ndefining the elements of \\code{chi} from \\code{T} down to 1.\n\n\\subsubsection{The Model}\n\nGiven the precomputed quantities, the model block directly encodes the\nCJS model's log likelihood function.  All parameters are left with\ntheir default uniform priors and the model simply encodes the log\nprobability of the observations \\code{q} given the parameters \\code{p}\nand \\code{phi} as well as the transformed parameter \\code{chi} defined\nin terms of \\code{p} and \\code{phi}.\n%\n\\begin{stancode}\nmodel {\n  for (i in 1:I) {\n    if (first[i] > 0) {\n      for (t in (first[i]+1):last[i]) {\n        1 ~ bernoulli(phi[t-1]);\n        y[i, t] ~ bernoulli(p[t]);\n      }\n      1 ~ bernoulli(chi[last[i]]);\n    }\n  }\n}\n\\end{stancode}\n%\nThe outer loop is over individuals, conditional skipping individuals\n\\code{i} which are never captured.  The never-captured check depends\non the convention of the first-capture and last-capture functions\nreturning 0 for \\code{first} if an individual is never captured.\n\nThe inner loop for individual \\code{i} first increments the log\nprobability based on the survival of the individual with probability\n\\code{phi[t-1]}.  The outcome of 1 is fixed because the individual\nmust survive between the first and last capture (i.e., no zombies).\nNote that the loop starts after the first capture, because all\ninformation in the CJS model is conditional on the first capture.\n\nIn the inner loop, the observed capture status \\code{y[i,~t]} for\nindividual \\code{i} at time \\code{t} has a Bernoulli distribution\nbased on the capture probability \\code{p[t]} at time \\code{t}.\n\nAfter the inner loop, the probability of an animal never being seen\nagain after being observed at time \\code{last[i]} is included, because\n\\code{last[i]} was defined to be the last time period in which animal\n\\code{i} was observed.\n\n\\subsubsection{Identified Parameters}\n\nAs with the collective model described in the previous subsection,\nthis model does not identify \\code{phi[T-1]} and \\code{p[T]}, but\ndoes identify their product, \\code{beta}.  Thus \\code{beta} is defined\nas a generated quantity to monitor convergence and report.\n%\n\\begin{stancode}\ngenerated quantities {\n  real beta;\n  ...\n\n  beta = phi[T-1] * p[T];\n  ...\n}\n\\end{stancode}\n%\n\nThe parameter \\code{p[1]} is also not modeled and will just be uniform\nbetween 0 and 1.  A more finely articulated model might have a\nhierarchical or time-series component, in which case \\code{p[1]} would\nbe an unknown initial condition and both \\code{phi[T-1]} and\n\\code{p[T]} could be identified.\n\n\\subsubsection{Population Size Estimates}\n\nThe generated quantities also calculates an estimate of the population\nmean at each time \\code{t} in the same way as in the simple\nmark-recapture model as the number of individuals captured at time\n\\code{t} divided by the probability of capture at time \\code{t}.  This\nis done with the elementwise division operation for vectors\n(\\code{./}) in the generated quantities block.\n%\n\\begin{stancode}\ngenerated quantities {\n  ...\n  vector<lower=0>[T] pop;\n  ...\n  pop = n_captured ./ p;\n  pop[1] = -1;\n}\n\\end{stancode}\n\n\\subsubsection{Generalizing to Individual Effects}\n\nAll individuals are modeled as having the same capture probability,\nbut this model could be easily generalized to use a logistic\nregression here based on individual-level inputs to be used as\npredictors.\n\n\n\n\\section{Data Coding and Diagnostic Accuracy Models}\n\nAlthough seemingly disparate tasks, the rating/coding/annotation of\nitems with categories and diagnostic testing for disease or other\nconditions share several characteristics which allow their statistical\nproperties to modeled similarly.\n\n\\subsection{Diagnostic Accuracy}\n\nSuppose you have diagnostic tests for a condition of varying\nsensitivity and specificity.  Sensitivity is the probability a test\nreturns positive when the patient has the condition and specificity is\nthe probability that a test returns negative when the patient does not\nhave the condition.  For example, mammograms and puncture biopsy tests\nboth test for the presence of breast cancer.  Mammograms have high\nsensitivity and low specificity, meaning lots of false positives,\nwhereas puncture biopsies are the opposite, with low sensitivity and\nhigh specificity, meaning lots of false negatives.\n\nThere are several estimands of interest in such studies.  An\nepidemiological study may be interested in the prevalence of a kind of\ninfection, such as malaria, in a population.  A test development study\nmight be interested in the diagnostic accuracy of a new test. A health\ncare worker performing tests might be interested in the disease status\nof a particular patient.\n\n\\subsection{Data Coding}\n\nHumans are often given the task of coding (equivalently rating or\nannotating) data.  For example, journal or grant reviewers rate\nsubmissions, a political study may code campaign commercials as to\nwhether they are attack ads or not, a natural language processing\nstudy might annotate Tweets as to whether they are positive or\nnegative in overall sentiment, or a dentist looking at an X-ray\nclassifies a patient as having a cavity or not.  In all of these\ncases, the data coders play the role of the diagnostic tests and all\nof the same estimands are in play --- data coder accuracy and bias,\ntrue categories of items being coded, or the prevalence of various\ncategories of items in the data.\n\n\\subsection{Noisy Categorical Measurement Model}\n\nIn this section, only categorical ratings are considered, and the\nchallenge in the modeling for Stan is to marginalize out the discrete\nparameters.\n\n\\cite{DawidSkene:1979} introduce a noisy-measurement model for\ndata coding and apply in the epidemiological setting of coding what\ndoctor notes say about patient histories;  the same model can be used\nfor diagnostic procedures.\n\n\\subsubsection{Data}\n\nThe data for the model consists of $J$ raters (diagnostic tests), $I$\nitems (patients), and $K$ categories (condition statuses) to annotate,\nwith $y_{i, j} \\in 1{:}K$ being the rating provided by rater $j$ for\nitem $i$.  In a diagnostic test setting for a particular condition,\nthe raters are diagnostic procedures and often $K=2$, with values\nsignaling the presence or absence of the condition.%\n%\n\\footnote{Diagnostic procedures are often ordinal, as in stages of\n  cancer in oncological diagnosis or the severity of a cavity in\n  dental diagnosis.  Dawid and Skene's model may be used as is or\n  naturally generalized for ordinal ratings using a latent continuous\n  rating and cutpoints as in ordinal logistic regression.}\n\nIt is relatively straightforward to extend Dawid and Skene's model to\ndeal with the situation where not every rater rates each item exactly\nonce.\n\n\\subsection{Model Parameters}\n\nThe model is based on three parameters, the first of which is discrete:\n%\n\\begin{itemize}\n\\item $z_i$ : a value in $1{:}K$ indicating the true category of item $i$,\n\\item $\\pi$ : a $K$-simplex for the prevalence of the $K$\n  categories in the population, and\n\\item $\\theta_{j,k}$ : a $K$-simplex for the response of annotator $j$\n  to an item of true category $k$.\n\\end{itemize}\n\n\\subsection{Noisy Measurement Model}\n\nThe true category of an item is assumed to be generated by a simple\ncategorical distribution based on item prevalence,\n\\[\nz_i \\sim \\distro{Categorical}(\\pi).\n\\]\n%\nThe rating $y_{i, j}$ provided for item $i$ by rater $j$ is modeled as\na categorical response of rater $i$ to an item of category $z_i$,%\n%\n\\footnote{In the subscript, $z[i]$ is written as $z_i$ to\n  improve legibility.}\n%\n\\[\ny_{i, j} \\sim \\distro{Categorical}(\\theta_{j,\\pi_{z[i]}}).\n\\]\n\n\\subsubsection{Priors and Hierarchical Modeling}\n\nDawid and Skene provided maximum likelihood estimates for $\\theta$ and\n$\\pi$, which allows them to generate probability estimates for each $z_i$.\n\nTo mimic Dawid and Skene's maximum likelihood model, the parameters\n$\\theta_{j,k}$ and $\\pi$ can be given uniform priors over\n$K$-simplexes.  It is straightforward to generalize to Dirichlet\npriors,\n\\[\n\\pi \\sim \\distro{Dirichlet}(\\alpha)\n\\]\nand\n\\[\n\\theta_{j,k} \\sim \\distro{Dirichlet}(\\beta_k)\n\\]\nwith fixed hyperparameters $\\alpha$ (a vector) and $\\beta$ (a matrix\nor array of vectors).  The prior for $\\theta_{j,k}$ must be allowed to\nvary in $k$, so that, for instance, $\\beta_{k,k}$ is large enough to\nallow the prior to favor better-than-chance annotators over random or\nadversarial ones.\n\nBecause there are $J$ coders, it would be natural to extend the model\nto include a hierarchical prior for $\\beta$ and to partially pool the\nestimates of coder accuracy and bias.\n\n\\subsubsection{Marginalizing out the True Category}\n\nBecause the true category parameter $z$ is discrete, it must be\nmarginalized out of the joint posterior in order to carry out sampling\nor maximum likelihood estimation in Stan. The joint posterior factors\nas\n\\[\np(y, \\theta, \\pi) = p(y | \\theta,\\pi) \\, p(\\pi) \\, p(\\theta),\n\\]\nwhere $p(y | \\theta,\\pi)$ is derived by marginalizing $z$ out of\n%\n\\[\np(z, y | \\theta, \\pi)\n\\ = \\\n\\prod_{i=1}^I \\left( \\distro{Categorical}(z_i | \\pi)\n                     \\prod_{j=1}^J\n                     \\distro{Categorical}(y_{i, j}|\\theta_{j, z[i]})\n              \\right).\n\\]\n%\nThis can be done item by item, with\n\\[\np(y | \\theta, \\pi)\n\\ = \\\n\\prod_{i=1}^I \\sum_{k=1}^K\n  \\left( \\distro{Categorical}(z_i | \\pi)\n         \\prod_{j=1}^J\n         \\distro{Categorical}(y_{i, j}|\\theta_{j, z[i]})\n  \\right).\n\\]\n%\nIn the missing data model, only the observed labels would be used in\nthe inner product.\n\n\\cite{DawidSkene:1979} derive exactly the same equation in their\nEquation~(2.7), required for the E-step in their expectation\nmaximization (EM) algorithm.  Stan requires the marginalized\nprobability function on the log scale,\n\\[\n\\begin{array}{l}\n\\mbox{ } \\ \\log p(y | \\theta, \\pi)\n\\\\[3pt]\n\\mbox{ } \\  = \\\n\\sum_{i=1}^I \\log \\left( \\sum_{k=1}^K \\exp\n  \\left( \\log \\distro{Categorical}(z_i | \\pi)\n         + \\sum_{j=1}^J\n         \\log \\distro{Categorical}(y_{i, j}|\\theta_{j, z[i]})\n  \\right) \\right),\n\\end{array}\n\\]\nwhich can be directly coded using Stan's built-in \\code{log\\_sum\\_exp}\nfunction.\n\n\n\\subsection{Stan Implementation}\n\nThe Stan program for the Dawid and Skene model is provided in\n\\reffigure{dawid-skene-model}.\n%\n\\begin{figure}\n\\begin{stancode}\ndata {\n  int<lower=2> K;\n  int<lower=1> I;\n  int<lower=1> J;\n\n  int<lower=1,upper=K> y[I, J];\n\n  vector<lower=0>[K] alpha;\n  vector<lower=0>[K] beta[K];\n}\nparameters {\n  simplex[K] pi;\n  simplex[K] theta[J, K];\n}\ntransformed parameters {\n  vector[K] log_q_z[I];\n  for (i in 1:I) {\n    log_q_z[i] = log(pi);\n    for (j in 1:J)\n      for (k in 1:K)\n        log_q_z[i, k] = log_q_z[i, k]\n                         + log(theta[j, k, y[i, j]]);\n  }\n}\nmodel {\n  pi ~ dirichlet(alpha);\n  for (j in 1:J)\n    for (k in 1:K)\n      theta[j, k] ~ dirichlet(beta[k]);\n\n  for (i in 1:I)\n    target += log_sum_exp(log_q_z[i]);\n}\n\\end{stancode}\n\\vspace*{-12pt}\n\\caption{\\small\\it Stan program for the rating (or diagnostic\n  accuracy) model of \\cite{DawidSkene:1979}. The model marginalizes\n  out the discrete parameter $z$, storing the unnormalized conditional\n  probability $\\log q(z_i=k|\\theta,\\pi)$ in\\ \\code{log\\_q\\_z[i,~k]}.}%\n\\label{dawid-skene-model.figure}\n\\end{figure}\n%\nThe Stan model converges quickly and mixes well using NUTS starting at\ndiffuse initial points, unlike the equivalent model implemented with\nGibbs sampling over the discrete parameter.  Reasonable weakly\ninformative priors are $\\alpha_k = 3$ and $\\beta_{k,k} = 2.5 K$ and\n$\\beta_{k,k'} = 1$ if $k \\neq k'$.  Taking $\\alpha$ and $\\beta_k$ to\nbe unit vectors and applying optimization will produce the same answer\nas the expectation maximization (EM) algorithm of\n\\cite{DawidSkene:1979}.\n\n\\subsubsection{Inference for the True Category}\n\nThe quantity \\code{log\\_q\\_z[i]} is defined as a transformed\nparameter.  It encodes the (unnormalized) log of $p(z_i | \\theta,\n\\pi)$.  Each iteration provides a value conditioned on that\niteration's values for $\\theta$ and $\\pi$.  Applying the softmax\nfunction to \\code{log\\_q\\_z[i]} provides a simplex corresponding to\nthe probability mass function of $z_i$ in the posterior.   These may\nbe averaged across the iterations to provide the posterior probability\ndistribution over each $z_i$.\n\n\n\\chapter{Sparse and Ragged Data Structures}\\label{sparse-ragged.chapter}\n\n\\noindent\nStan does not directly support either sparse or ragged data\nstructures, though both can be accommodated with some programming\neffort.  \\refchapter{sparse-matrices} introduces a special-purpose\nsparse matrix times dense vector multiplication, which should be used\nwhere applicable;  this chapter covers more general data structures.\n\n\\section{Sparse Data Structures}\n\nCoding sparse data structures is as easy as moving from a matrix-like\ndata structure to a database-like data structure.  For example,\nconsider the coding of sparse data for the IRT models discussed in\n\\refsection{item-response-models}.  There are $J$ students and $K$\nquestions, and if every student answers every question, then it is\npractical to declare the data as a $J \\times K$ array of answers.\n%\n\\begin{quote}\n\\begin{Verbatim}\ndata {\n  int<lower=1> J;\n  int<lower=1> K;\n  int<lower=0,upper=1> y[J, K];\n  ...\nmodel {\n  for (j in 1:J)\n    for (k in 1:K)\n      y[j, k] ~ bernoulli_logit(delta[k] * (alpha[j] - beta[k]));\n  ...\n\\end{Verbatim}\n\\end{quote}\n%\n\n\\begin{figure}\n\\begin{center}\n\\begin{minipage}[c]{0.45\\textwidth}\n\\[\ny\n=\n\\left[\n\\begin{array}{cccc}\n0 & 1 & \\mbox{NA} & 1\n\\\\\n0 & \\mbox{NA} & \\mbox{NA} & 1\n\\\\\n\\mbox{NA} & 0 & \\mbox{NA} & \\mbox{NA}\n\\end{array}\n\\right]\n\\]\n\\end{minipage}\n\\ \\ \\\n\\begin{minipage}[c]{0.45\\textwidth}\n\\begin{tabular}{ll|l}\n$jj$ & $kk$ & $y$\n\\\\ \\hline\n1 & 1 & 0\n\\\\\n1 & 2 & 1\n\\\\\n1 & 4 & 1\n\\\\\n2 & 1 & 0\n\\\\\n2 & 4 & 1\n\\\\\n3 & 2 & 0\n\\end{tabular}\n\\end{minipage}\n\\end{center}\n\\vspace*{-12pt}\n\\caption{\\small\\it  Example of coding sparse arrays in Stan.  On the left is a definition\n  of a sparse matrix $y$ using the NA notation from R (which is not\n  supported by Stan).  On the right is a database-like encoding of the\n  same sparse matrix $y$ that can be used directly in Stan.  The first\n  two columns, $jj$ and $kk$, denote the indexes and the final column,\n  $y$, the value.  For example, the fifth row of the database-like\n  data structure on the right indicates that $y_{2,4} = 1$.}\\label{sparse-data.figure}\n\\end{figure}\n%\nWhen not every student is given every question, the dense array coding\nwill no longer work, because Stan does not support undefined values.\n\\reffigure{sparse-data} shows an example with $J=3$ and $K=4$, with\nmissing responses shown as NA, as in R.  There is no support within\nStan for R's NA values, so this data structure cannot be used\ndirectly.  Instead, it must be converted to a ``long form'' as in a\ndatabase, with columns indicating the $j$ and $k$ indexes along with\nthe value.  For instance, with $jj$ and $kk$ used for the indexes\n(following \\citep{GelmanHill:2007}), the data structure can be coded\nas in the right-hand example in \\reffigure{sparse-data}.  This says\nthat $y_{1,1} = 0$, $y_{1,2} = 1$, and so on, up to $y_{3,2} = 1$,\nwith all other entries undefined.\n\nLetting $N$ be the number of $y$ that are defined, here $N=6$,\nthe data and model can be formulated as follows.\n%\n\\begin{quote}\n\\begin{Verbatim}\ndata {\n  ...\n  int<lower=1> N;\n  int<lower=1,upper=J> jj[N];\n  int<lower=1,upper=K> kk[N];\n  int<lower=0,upper=1> y[N];\n  ...\nmodel {\n  for (n in 1:N)\n    y[n] ~ bernoulli_logit(delta[kk[n]]\n                           * (alpha[jj[n]] - beta[kk[n]]));\n  ...\n\\end{Verbatim}\n\\end{quote}\n%\nIn the situation where there are no missing values, the two model\nformulations produce exactly the same log posterior density.\n\n\n\\section{Ragged Data Structures}\\label{ragged-data-structs.section}\n\nRagged arrays are arrays that are not rectangular, but have different\nsized entries.  This kind of structure crops up when there are\ndifferent numbers of observations per entry.\n\nA general approach to dealing with ragged structure is to move to a\nfull database-like data structure as discussed in the previous\nsection.  A more compact approach is possible with some indexing into\na linear array.\n\nFor example, consider a data structure for three groups, each of which\nhas a different number of observations.\n%\n\\begin{figure}\n\\begin{center}\n\\begin{minipage}[c]{0.35\\textwidth}\n$y_1 =  \\left[1.3 \\ \\ 2.4 \\ \\ 0.9\\right]$\n\\\\[3pt]\n$y_2 = \\left[-1.8 \\ \\ -0.1\\right]$\n\\\\[3pt]\n$y_3 = \\left[12.9 \\ \\ 18.7 \\ \\ 42.9 \\ \\ 4.7\\right]$\n\\end{minipage}\n\\ \\ \\\n\\begin{minipage}[c]{0.60\\textwidth}\n$z = [1.3 \\ \\ 2.4 \\ \\ 0.9 \\ \\ -1.8 \\ \\ -0.1 \\ \\ 12.9 \\ \\ 18.7 \\ \\ 42.9\n\\ \\ 4.7]$\n\\\\[3pt]\n$s  =  \\{ 3 \\ \\ 2 \\ \\ 4 \\}$\n\\end{minipage}\n\\end{center}\n\\caption{\\small\\it Example of coding ragged arrays in Stan.  On the\n  left is the definition of a ragged data structure $y$ with three\n  rows of different sizes ($y_1$ is size 3, $y_2$ size 2, and $y_3$\n  size 4).  On the right is an example of how to code the data in Stan,\n  using a single vector $y$ to hold all the values and a separate\n  array of integers $s$ to hold the group row sizes.  In this\n  example, $y_1 = z_{1:3}$, $y_2 =\n  z_{4:5}$, and $y_3 = z_{6:9}$.}\\label{ragged-data.figure}\n\\end{figure}\n%\n\nSuppose the model is a very simple varying intercept model, which,\nusing vectorized notation, would yield a likelihood\n\\[\n\\prod_{n=1}^3 \\log \\distro{Normal}(y_n | \\mu_n, \\sigma).\n\\]\nThere's no direct way to encode this in Stan.\n\nA full database type structure could be used, as in the sparse\nexample, but this is inefficient, wasting space for unnecessary\nindices and not allowing vector-based density operations.  A better\nway to code this data is as a single list of values, with a separate\ndata structure indicating the sizes of each subarray.  This is\nindicated on the right of \\reffigure{ragged-data}.  This coding uses a\nsingle array for the values and a separate array for the sizes of each\nrow.\n\nThe model can then be coded up using slicing operations as follows.\n\\begin{quote}\n\\begin{Verbatim}\ndata {\n  int<lower=0> N;   // # observations\n  int<lower=0> K;   // # of groups\n  vector[N] y;      // observations\n  int s[K];         // group sizes\n  ...\nmodel {\n  int pos;\n  pos = 1;\n  for (k in 1:K) {\n    segment(y, pos, s[k]) ~ normal(mu[k], sigma);\n    pos = pos + s[k];\n  }\n\\end{Verbatim}\n\\end{quote}\n%\nThis coding allows for efficient vectorization, which is worth the\ncopy cost entailed by the \\code{segment()} vector slicing operation.\n\n\n\\chapter{Clustering Models}\\label{clustering.chapter}\n\n\\noindent\nUnsupervised methods for organizing data into groups are collectively\nreferred to as clustering.  This chapter describes the implementation\nin Stan of two widely used statistical clustering models, soft\n$K$-means and latent Dirichlet allocation (LDA).  In addition, this\nchapter includes naive Bayesian classification, which can be viewed as\na form of clustering which may be supervised.  These models are\ntypically expressed using discrete parameters for cluster assignments.\nNevertheless, they can be implemented in Stan like any other mixture\nmodel by marginalizing out the discrete parameters (see\n\\refchapter{mixture-modeling}).\n\n\\section{Relation to Finite Mixture Models}\n\nAs mentioned in \\refsection{clustering-mixture}, clustering models and\nfinite mixture models are really just two sides of the same coin.  The\n``soft'' $K$-means model described in the next section is a normal\nmixture model (with varying assumptions about covariance in higher\ndimensions leading to variants of $K$-means).  Latent Dirichlet\nallocation is a mixed-membership multinomial mixture.\n\n\\section{Soft $K$-Means}\n\n$K$-means clustering is a method of clustering data represented as\n$D$-dimensional vectors.  Specifically, there will be $N$ items to be\nclustered, each represented as a vector $y_n \\in \\reals^D$.  In the\n``soft'' version of $K$-means, the assignments to clusters will be\nprobabilistic.\n\n\\subsection{Geometric Hard  $K$-Means Clustering}\n\n$K$-means clustering is typically described geometrically in terms of\nthe following algorithm, which assumes the number of clusters $K$ and\ndata vectors $y$ as input.\n%\n\\begin{enumerate}\n\\item For each $n$ in $1:N$, randomly assign vector $y_n$ to a cluster in $1{:}K$;\n\\item Repeat\n\\begin{enumerate}\n\\item For each cluster $k$ in $1{:}K$, compute the cluster centroid $\\mu_k$  by averaging the\n  vectors assigned to that cluster;\n\\item For each $n$ in $1:N$, reassign $y_n$ to the cluster $k$\n  for which the (Euclidean) distance from $y_n$ to $\\mu_k$ is smallest;\n\\item If no vectors changed cluster, return the cluster assignments.\n\\end{enumerate}\n\\end{enumerate}\n%\nThis algorithm is guaranteed to terminate.\n\n\\subsection{Soft $K$-Means Clustering}\n\nSoft $K$-means clustering treats the cluster assignments as\nprobability distributions over the clusters.  Because of the\nconnection between Euclidean distance and multivariate normal models\nwith a fixed covariance, soft $K$-means can be expressed (and coded in\nStan) as a multivariate normal mixture model.\n\nIn the full generative model, each data point $n$ in $1{:}N$ is assigned\na cluster $z_n \\in 1{:}K$ with symmetric uniform probability,\n%\n\\[\nz_n \\sim \\distro{Categorical}({\\bf 1}/K),\n\\]\nwhere ${\\bf 1}$ is the unit vector of $K$ dimensions, so that ${\\bf\n  1}/K$ is the symmetric $K$-simplex.  Thus the model assumes that\neach data point is drawn from a hard decision about cluster\nmembership.  The softness arises only from the uncertainty about which\ncluster generated a data point.\n\nThe data points themselves are generated from a multivariate normal\ndistribution whose parameters are determined by the cluster assignment\n$z_n$,\n\\[\ny_n \\sim  \\distro{Normal}(\\mu_{z[n]},\\Sigma_{z[n]})\n\\]\n\nThe sample implementation in this section assumes a fixed unit\ncovariance matrix shared by all clusters $k$,\n\\[\n\\Sigma_k = \\mbox{diag\\_matrix}({\\bf 1}),\n\\]\nso that the log multivariate normal can be implemented directly up to a proportion\nby\n\\[\n\\mbox{Normal}\\left( y_n | \\mu_k, \\mbox{diag\\_matrix}({\\bf 1}) \\right)\n\\propto \\exp \\left (- \\frac{1}{2} \\sum_{d=1}^D \\left( \\mu_{k,d} - y_{n,d}\n  \\right)^2 \\right).\n\\]\nThe spatial perspective on $K$-means arises by noting that the inner\nterm is just half the negative Euclidean distance from the cluster\nmean $\\mu_k$ to the data point $y_n$.\n\n\\subsection{Stan Implementation of Soft $K$-Means}\n\nConsider the following Stan program for implementing $K$-means\nclustering.%\n%\n\\footnote{The model is available in the Stan example model repository;\nsee \\url{http://mc-stan.org/users/documentation}.}\n%\n\\begin{stancode}\ndata {\n  int<lower=0> N;  // number of data points\n  int<lower=1> D;  // number of dimensions\n  int<lower=1> K;  // number of clusters\n  vector[D] y[N];  // observations\n}\ntransformed data {\n  real<upper=0> neg_log_K;\n  neg_log_K = -log(K);\n}\nparameters {\n  vector[D] mu[K]; // cluster means\n}\ntransformed parameters {\n  real<upper=0> soft_z[N, K]; // log unnormalized clusters\n  for (n in 1:N)\n    for (k in 1:K)\n      soft_z[n, k] = neg_log_K\n                     - 0.5 * dot_self(mu[k] - y[n]);\n}\nmodel {\n  // prior\n  for (k in 1:K)\n    mu[k] ~ normal(0, 1);\n\n  // likelihood\n  for (n in 1:N)\n    target += log_sum_exp(soft_z[n]));\n}\n\\end{stancode}\n%\nThere is an independent unit normal prior on the centroid parameters;\nthis prior could be swapped with other priors, or even a hierarchical\nmodel to fit an overall problem scale and location.\n\nThe only parameter is \\code{mu}, where \\code{mu[k]} is the centroid\nfor cluster $k$.  The transformed parameters \\code{soft\\_z[n]} contain\nthe log of the unnormalized cluster assignment probabilities.  The\nvector \\code{soft\\_z[n]} can be converted back to a normalized simplex\nusing the softmax function (see \\refsection{softmax}), either\nexternally or within the model's generated quantities block.\n\n\\subsection{Generalizing Soft $K$-Means}\n\nThe multivariate normal distribution with unit covariance matrix\nproduces a log probability density proportional to Euclidean distance\n(i.e., $L_2$ distance).  Other distributions relate to other\ngeometries.  For instance, replacing the normal distribution with the\ndouble exponential (Laplace) distribution produces a clustering model\nbased on $L_1$ distance (i.e., Manhattan or taxicab\ndistance).\n\nWithin the multivariate normal version of $K$-means, replacing the\nunit covariance matrix with a shared covariance matrix amounts to\nworking with distances defined in a space transformed by the inverse\ncovariance matrix.\n\nAlthough there is no global spatial analog, it is common to see soft\n$K$-means specified with a per-cluster covariance matrix. In this\nsituation, a hierarchical prior may be used for the covariance matrices.\n\n\n\n\\section{The Difficulty of Bayesian Inference for Clustering}\n\nTwo problems make it pretty much impossible to perform full Bayesian\ninference for clustering models, the lack of parameter identifiability\nand the extreme multimodality of the posteriors.  There is additional\ndiscussion related to the non-identifiability due to label switching\nin \\refsection{label-switching-problematic}.\n\n\\subsection{Non-Identifiability}\n\nCluster assignments are not identified --- permuting the cluster mean\nvectors \\code{mu} leads to a model with identical likelihoods.  For\ninstance, permuting the first two indexes in \\code{mu} and the first\ntwo indexes in each \\code{soft\\_z[n]} leads to an identical likelihood\n(and prior).\n\nThe lack of identifiability means that the cluster parameters\ncannot be compared across multiple Markov chains.  In fact, the only\nparameter in soft $K$-means is not identified, leading to problems in\nmonitoring convergence.  Clusters can even fail to be identified\nwithin a single chain, with indices swapping if the chain is long\nenough or the data is not cleanly separated.\n\n\\subsection{Multimodality}\n\nThe other problem with clustering models is that their posteriors are\nhighly multimodal.  One form of multimodality is the\nnon-identifiability leading to index swapping.  But even without\nthe index problems the posteriors are highly multimodal.\n\nBayesian inference fails in cases of high multimodality because there\nis no way to visit all of the modes in the posterior in appropriate\nproportions and thus no way to evaluate integrals involved in\nposterior predictive inference.\n\nIn light of these two problems, the advice often given in fitting\nclustering models is to try many different initializations and select\nthe sample with the highest overall probability.  It is also popular\nto use optimization-based point estimators such as expectation\nmaximization or variational Bayes, which can be much more efficient\nthan sampling-based approaches.\n\n\n\\section{Naive Bayes Classification and Clustering}\n\nNaive Bayes is a kind of mixture model that can be used for\nclassification or for clustering (or a mix of both), depending on\nwhich labels for items are observed.%\n%\n\\footnote{For clustering, the non-identifiability problems for all\n  mixture models present a problem, whereas there is no such problem\n  for classification.  Despite the difficulties with full Bayesian\n  inference for clustering, researchers continue to use it, often in\n  an exploratory data analysis setting rather than for predictive\n  modeling.}\n\nMultinomial mixture models are referred to as ``naive Bayes'' because\nthey are often applied to classification problems where the\nmultinomial independence assumptions are clearly false.\n\nNaive Bayes classification and clustering can be applied to any data\nwith multinomial structure.  A typical example of this is natural\nlanguage text classification and clustering, which is used an example\nin what follows.\n\nThe observed data consists of a sequence of $M$ documents made up of\nbags of words drawn from a vocabulary of $V$ distinct words.  A\ndocument $m$ has $N_m$ words, which are indexed as $w_{m,1}, \\ldots,\nw_{m,N[m]} \\in 1{:}V$.  Despite the ordered indexing of words in a\ndocument, this order is not part of the model, which is clearly\ndefective for natural human language data.  A number of topics (or\ncategories) $K$ is fixed.\n\nThe multinomial mixture model generates a single category $z_m \\in\n1{:}K$ for each document $m \\in 1{:}M$ according to a categorical\ndistribution,\n\\[\nz_m \\sim \\distro{Categorical}(\\theta).\n\\]\nThe $K$-simplex parameter $\\theta$ represents the prevalence of each\ncategory in the data.\n\nNext, the words in each document are generated conditionally\nindependently of each other and the words in other documents based on\nthe category of the document, with word $n$ of document $m$ being\ngenerated as\n\\[\nw_{m,n} \\sim \\distro{Categorical}(\\phi_{z[m]}).\n\\]\nThe parameter $\\phi_{z[m]}$ is a $V$-simplex representing the\nprobability of each word in the vocabulary in documents of category\n$z_m$.\n\nThe parameters $\\theta$ and $\\phi$ are typically given symmetric\nDirichlet priors.  The prevalence $\\theta$ is sometimes fixed to\nproduce equal probabilities for each category $k \\in 1:K$.\n\n\\subsection{Coding Ragged Arrays}\n\nThe specification for naive Bayes in the previous sections have used a ragged\narray notation for the words $w$.  Because Stan does not support\nragged arrays, the models are coded using an alternative strategy that\nprovides an index for each word in a global list of words.   The data\nis organized as follows, with the word arrays laid out in a column and each\nassigned to its document in a second column.\n%\n\\begin{center}\n\\begin{tabular}{r|cc}\n\\code{n} & \\code{w[n]} & \\code{doc[n]} \\\\ \\hline\n1 & $w_{1,1}$ & 1 \\\\\n2 & $w_{1,2}$ & 1 \\\\\n\\vdots & \\vdots & \\vdots \\\\\n$N_1$ & $w_{1,N[1]}$ & 1 \\\\\n$N_1 + 1$ & $w_{2,1}$ & 2 \\\\\n$N_1 + 2$ & $w_{2,2}$ & 2 \\\\\n\\vdots & \\vdots & \\vdots \\\\\n$N_1 + N_2$ & $w_{2,N[2]}$ & 2 \\\\\n$N_1 + N_2 + 1$ & $w_{3,1}$ & 3 \\\\\n\\vdots & \\vdots & \\vdots \\\\\n$\\code{N} = \\sum_{m=1}^M N_m$ & $w_{M,N[M]}$ & $M$ \\\\\n\\end{tabular}\n\\end{center}\n%\nThe relevant variables for the program are \\code{N}, the total number\nof words in all the documents, the word array \\code{w}, and the\ndocument identity array \\code{doc}.\n\n\\subsection{Estimation with Category-Labeled Training Data}\n\n\nA naive Bayes model for estimating the simplex parameters given\ntraining data with documents of known categories can be coded in Stan\nas follows%\n%\n\\footnote{This model is available in the example model repository;\n  see \\url{http://mc-stan.org/users/documentation}.}\n%\n\\begin{stancode}\ndata {\n  // training data\n  int<lower=1> K;               // num topics\n  int<lower=1> V;               // num words\n  int<lower=0> M;               // num docs\n  int<lower=0> N;               // total word instances\n  int<lower=1,upper=K> z[M];    // topic for doc m\n  int<lower=1,upper=V> w[N];    // word n\n  int<lower=1,upper=M> doc[N];  // doc ID for word n\n  // hyperparameters\n  vector<lower=0>[K] alpha;     // topic prior\n  vector<lower=0>[V] beta;      // word prior\n}\nparameters {\n  simplex[K] theta;   // topic prevalence\n  simplex[V] phi[K];  // word dist for topic k\n}\nmodel {\n  theta ~ dirichlet(alpha);\n  for (k in 1:K)\n    phi[k] ~ dirichlet(beta);\n  for (m in 1:M)\n    z[m] ~ categorical(theta);\n  for (n in 1:N)\n    w[n] ~ categorical(phi[z[doc[n]]]);\n}\n\\end{stancode}\n%\nNote that the topic identifiers $z_m$ are declared as data and the\nlatent category assignments are included as part of the likelihood\nfunction.\n\n\\subsection{Estimation without Category-Labeled Training Data}\n\nNaive Bayes models can be used in an unsupervised fashion to cluster\nmultinomial-structured data into a fixed number $K$ of categories.\nThe data declaration includes the same variables as the model in the\nprevious section excluding the topic labels \\code{z}.   Because\n\\code{z} is discrete, it needs to be summed out of the model\ncalculation.  This is done for naive Bayes as for other mixture\nmodels.  The parameters are the same up to the priors, but the\nlikelihood is now computed as the marginal document probability\n\\[\n\\begin{array}{l}\n\\log p(w_{m,1},\\ldots,w_{m,N_m}|\\theta,\\phi)\n\\\\[2pt]\n\\ \\ \\ = \\\n\\log \\sum_{k=1}^K\n\\left( \\distro{Categorical}(k|\\theta)\n        \\times \\prod_{n=1}^{N_m} \\distro{Categorical}(w_{m,n}|\\phi_k)\n\\right)\n\\\\[6pt]\n\\ \\ \\ = \\\n\\log \\sum_{k=1}^K \\exp \\left(\n\\log \\distro{Categorical}(k|\\theta)\n+ \\sum_{n=1}^{N_m} \\log \\distro{Categorical}(w_{m,n}|\\phi_k)\n\\right).\n\\end{array}\n\\]\n%\nThe last step shows how the \\code{log\\_sum\\_exp} function can be used\nto stabilize the numerical calculation and return a result on the log\nscale.\n%\n\\begin{stancode}\nmodel {\n  real gamma[M, K];\n  theta ~ dirichlet(alpha);\n  for (k in 1:K)\n    phi[k] ~ dirichlet(beta);\n  for (m in 1:M)\n    for (k in 1:K)\n      gamma[m, k] = categorical_lpmf(k | theta);\n  for (n in 1:N)\n    for (k in 1:K)\n      gamma[doc[n], k] = gamma[doc[n], k]\n                         + categorical_lpmf(w[n] | phi[k]);\n  for (m in 1:M)\n    target += log_sum_exp(gamma[m]);\n}\n\\end{stancode}\n%\nThe local variable \\code{gamma[m, k]} represents the value\n\\[\n\\gamma_{m,k} = \\log \\distro{Categorical}(k|\\theta)\n+ \\sum_{n=1}^{N_m} \\log \\distro{Categorical}(w_{m,n}|\\phi_k).\n\\]\n%\nGiven $\\gamma$, the posterior probability that document\n$m$ is assigned category $k$ is\n\\[\n\\mbox{Pr}[z_m = k|w,\\alpha,\\beta]\n=\n\\exp \\left(\n\\gamma_{m,k}\n- \\log \\sum_{k=1}^K \\exp \\left( \\gamma_{m,k} \\right)\n\\right).\n\\]\n%\nIf the variable \\code{gamma} were declared and defined in the\ntransformed parameter block, its sampled values would be saved by\nStan.  The normalized posterior probabilities could also be defined as\ngenerated quantities.\n\n\\subsection{Full Bayesian Inference for Naive Bayes}\n\nFull Bayesian posterior predictive inference for the naive Bayes model\ncan be implemented in Stan by combining the models for labeled and\nunlabeled data.  The estimands include both the model parameters and\nthe posterior distribution over categories for the unlabeled data.  The\nmodel is essentially a missing data model assuming the unknown\ncategory labels are missing completely at random; see\n\\citep{GelmanEtAl:2013,GelmanHill:2007} for more\ninformation on missing data imputation.  The model is also an instance\nof semisupervised learning because the unlabeled data contributes to\nthe parameter estimations.\n\nTo specify a Stan model for performing full Bayesian inference, the\nmodel for labeled data is combined with the model for unlabeled data.\nA second document collection is declared as data, but without the\ncategory labels, leading to new variables \\code{M2} \\code{N2},\n\\code{w2}, \\and \\code{doc2}.  The number of categories and number of\nwords, as well as the hyperparameters are shared and only declared\nonce.  Similarly, there is only one set of parameters.  Then the model\ncontains a single set of statements for the prior, a set of statements\nfor the labeled data, and a set of statements for the unlabeled data.\n\n\\subsection{Prediction without Model Updates}\n\nAn alternative to full Bayesian inference involves estimating a model\nusing labeled data, then applying it to unlabeled data without\nupdating the parameter estimates based on the unlabeled data.  This\nbehavior can be implemented by moving the definition of \\code{gamma}\nfor the unlabeled documents to the generated quantities block.\nBecause the variables no longer contribute to the log probability,\nthey no longer jointly contribute to the estimation of the model\nparameters.\n\n\n\\section{Latent Dirichlet Allocation}\n\nLatent Dirichlet allocation (LDA) is a mixed-membership multinomial\nclustering model \\citep{BleiNgJordan:2003} that generalized naive\nBayes.  Using the topic and document terminology common in discussions of\nLDA, each document is modeled as having a mixture of topics, with each\nword drawn from a topic based on the mixing proportions.\n\n\\subsection{The LDA Model}\n\nThe basic model assumes each document is generated independently based\non fixed hyperparameters. For document $m$, the first step is to draw a topic\ndistribution simplex $\\theta_m$ over the $K$ topics,\n%\n\\[\n\\theta_m \\sim \\distro{Dirichlet}(\\alpha).\n\\]\n%\nThe prior hyperparameter $\\alpha$ is fixed to a $K$-vector of positive\nvalues.  Each word in the document is generated independently\nconditional on the distribution $\\theta_m$.  First, a topic\n$z_{m,n} \\in 1{:}K$ is drawn for the word based on the\ndocument-specific topic-distribution,\n\\[\nz_{m,n} \\sim \\distro{Categorical}(\\theta_m).\n\\]\n%\nFinally, the word $w_{m,n}$ is drawn according to the word distribution\nfor topic $z_{m,n}$,\n\\[\nw_{m,n} \\sim \\distro{Categorical}(\\phi_{z[m,n]}).\n\\]\nThe distributions $\\phi_k$ over words for topic $k$ are also given a\nDirichlet prior,\n\\[\n\\phi_k \\sim \\distro{Dirichlet}(\\beta)\n\\]\n%\nwhere $\\beta$ is a fixed $V$-vector of positive values.\n\n\\subsection{Summing out the Discrete Parameters}\n\nAlthough Stan does not (yet) support discrete sampling, it is possible\nto calculate the marginal distribution over the continuous parameters\nby summing out the discrete parameters as in other mixture models.\nThe marginal posterior of the topic and word variables is\n%\n\\begin{eqnarray*}\np(\\theta,\\phi|w,\\alpha,\\beta)\n& \\propto &\np(\\theta|\\alpha) \\times p(\\phi|\\beta) \\times p(w|\\theta,\\phi)\n\\\\[4pt]\n& = &\n\\prod_{m=1}^M p(\\theta_m|\\alpha)\n\\times\n\\prod_{k=1}^K p(\\phi_k|\\beta)\n\\times\n\\prod_{m=1}^M \\prod_{n=1}^{M[n]} p(w_{m,n}|\\theta_m,\\phi).\n\\end{eqnarray*}\n%\nThe inner word-probability term is defined by summing out the\ntopic assignments,\n\\begin{eqnarray*}\np(w_{m,n}|\\theta_m,\\phi)\n& = &\n\\sum_{z=1}^K p(z,w_{m,n}|\\theta_m,\\phi).\n\\\\[4pt]\n& = &\n\\sum_{z=1}^K p(z|\\theta_m) \\times p(w_{m,n}|\\phi_z).\n\\end{eqnarray*}\n%\nPlugging the distributions in and converting to the log scale provides a\nformula that can be implemented directly in Stan,\n\\[\n\\begin{array}{l}\n\\log p(\\theta,\\phi|w,\\alpha,\\beta)\n\\\\[6pt]\n{ } \\ \\\n\\begin{array}{l}\n{ } = \\sum_{m=1}^M \\log \\distro{Dirichlet}(\\theta_m|\\alpha)\n\\ + \\\n\\sum_{k=1}^K \\log \\distro{Dirichlet}(\\phi_k|\\beta)\n\\\\[6pt]\n{ } \\ \\ \\ \\ \\\n+ \\sum_{m=1}^M \\sum_{n=1}^{N[m]} \\log \\left(\n\\sum_{z=1}^K\n  \\distro{Categorical}(z|\\theta_m)\n   \\times \\distro{Categorical}(w_{m,n}|\\phi_z)\n \\right)\n\\end{array}\n\\end{array}\n\\]\n\n\\subsection{Implementation of LDA}\n\n\nApplying the marginal derived in the last section to the data\nstructure described in this section leads to the following Stan\nprogram for LDA.\n%\n\\begin{stancode}\ndata {\n  int<lower=2> K;               // num topics\n  int<lower=2> V;               // num words\n  int<lower=1> M;               // num docs\n  int<lower=1> N;               // total word instances\n  int<lower=1,upper=V> w[N];    // word n\n  int<lower=1,upper=M> doc[N];  // doc ID for word n\n  vector<lower=0>[K] alpha;     // topic prior\n  vector<lower=0>[V] beta;      // word prior\n}\nparameters {\n  simplex[K] theta[M];   // topic dist for doc m\n  simplex[V] phi[K];     // word dist for topic k\n}\nmodel {\n  for (m in 1:M)\n    theta[m] ~ dirichlet(alpha);  // prior\n  for (k in 1:K)\n    phi[k] ~ dirichlet(beta);     // prior\n  for (n in 1:N) {\n    real gamma[K];\n    for (k in 1:K)\n      gamma[k] = log(theta[doc[n], k]) + log(phi[k, w[n]]);\n    target += log_sum_exp(gamma);  // likelihood;\n  }\n}\n\\end{stancode}\n%\nAs in the other mixture models, the log-sum-of-exponents function is\nused to stabilize the numerical arithmetic.\n\n\\subsection{Correlated Topic Model}\n\nTo account for correlations in the distribution of topics for\ndocuments, \\citep{BleiLafferty:2007} introduced a variant of LDA in\nwhich the Dirichlet prior on the per-document topic distribution is\nreplaced with a multivariate logistic normal distribution.\n\nThe authors treat the prior as a fixed hyperparameter.  They use an\n$L_1$-regularized estimate of covariance, which is equivalent to the\nmaximum a posteriori estimate given a double-exponential prior.  Stan\ndoes not (yet) support maximum a posteriori estimation, so the mean and\ncovariance of the multivariate logistic normal must be specified as\ndata.\n\n\\subsubsection{Fixed Hyperparameter Correlated Topic Model}\n\nThe Stan model in the previous section can be modified to implement\nthe correlated topic model by replacing the Dirichlet topic prior\n\\code{alpha} in the data declaration with the mean and covariance of\nthe multivariate logistic normal prior.\n%\n\\begin{stancode}\ndata {\n  ... data as before without alpha ...\n  vector[K] mu;          // topic mean\n  cov_matrix[K] Sigma;   // topic covariance\n}\n\\end{stancode}\n%\nRather than drawing the simplex parameter \\code{theta} from a\nDirichlet, a parameter \\code{eta} is drawn from a multivariate normal\ndistribution and then transformed using softmax into a simplex.\n%\n\\begin{stancode}\nparameters {\n  simplex[V] phi[K];  // word dist for topic k\n  vector[K] eta[M];   // topic dist for doc m\n}\ntransformed parameters {\n  simplex[K] theta[M];\n  for (m in 1:M)\n    theta[m] = softmax(eta[m]);\n}\nmodel {\n  for (m in 1:M)\n    eta[m] ~ multi_normal(mu, Sigma);\n  ... model as before w/o prior for theta ...\n}\n\\end{stancode}\n\n\\subsubsection{Full Bayes Correlated Topic Model}\n\nBy adding a prior for the mean and covariance, Stan supports full\nBayesian inference for the correlated topic model.  This requires\nmoving the declarations of topic mean \\code{mu} and covariance \\code{Sigma}\nfrom the data block to the parameters block and providing them with\npriors in the model.  A relatively efficient and interpretable prior\nfor the covariance matrix \\code{Sigma} may be encoded as follows.\n%\n\\begin{stancode}\n... data block as before, but without alpha ...\nparameters {\n  vector[K] mu;              // topic mean\n  corr_matrix[K] Omega;      // correlation matrix\n  vector<lower=0>[K] sigma;  // scales\n  vector[K] eta[M];          // logit topic dist for doc m\n  simplex[V] phi[K];         // word dist for topic k\n}\ntransformed parameters {\n  ... eta as above ...\n  cov_matrix[K] Sigma;       // covariance matrix\n  for (m in 1:K)\n    Sigma[m, m] = sigma[m] * sigma[m] * Omega[m, m];\n  for (m in 1:(K-1)) {\n    for (n in (m+1):K) {\n      Sigma[m, n] = sigma[m] * sigma[n] * Omega[m, n];\n      Sigma[n, m] = Sigma[m, n];\n    }\n  }\n}\nmodel {\n  mu ~ normal(0, 5);      // vectorized, diffuse\n  Omega ~ lkj_corr(2.0);  // regularize to unit correlation\n  sigma ~ cauchy(0, 5);   // half-Cauchy due to constraint\n  ... words sampled as above ...\n}\n\\end{stancode}\n%\nThe $\\distro{LkjCorr}$ distribution with shape $\\alpha > 0$ has support\non correlation matrices (i.e., symmetric positive definite with unit\ndiagonal).  Its density is defined by\n\\[\n\\distro{LkjCorr}(\\Omega|\\alpha) \\propto \\mbox{det}(\\Omega)^{\\alpha - 1}\n\\]\nWith a scale of $\\alpha = 2$, the weakly informative prior favors a\nunit correlation matrix.  Thus the compound effect of this prior on\nthe covariance matrix $\\Sigma$ for the multivariate logistic normal is\na slight concentration around diagonal covariance matrices with scales\ndetermined by the prior on \\code{sigma}.\n\n\n\\chapter{Gaussian Processes}\\label{gaussian-processes.chapter}\n\n\\noindent\nGaussian processes are continuous stochastic processes and thus may be\ninterpreted as providing a probability distribution over functions.  A\nprobability distribution over continuous functions may be viewed,\nroughly, as an uncountably infinite collection of random variables,\none for each valid input.  The generality of the supported functions\nmakes Gaussian priors popular choices for priors in general\nmultivariate (non-linear) regression problems.\n\nThe defining feature of a Gaussian process is that the joint distribution of\nthe function's value at a finite number of input points is a multivariate\nnormal distribution.  This makes it tractable to both fit models from finite\namounts of observed data and make predictions for finitely many new data\npoints.\n\nUnlike a simple multivariate normal distribution, which is\nparameterized by a mean vector and covariance matrix, a Gaussian\nprocess is parameterized by a mean function and covariance function.\nThe mean and covariance functions apply to vectors of inputs and\nreturn a mean vector and covariance matrix which provide the mean and\ncovariance of the outputs corresponding to those input points in the\nfunctions drawn from the process.\n\nGaussian processes can be encoded in Stan by implementing their mean and\ncovariance functions and plugging the result into the Gaussian form of their\nsampling distribution, or by using the specialized covariance functions\noutlined below.  This form of model is straightforward and may be used for\nsimulation, model fitting, or posterior predictive inference. A more efficient\nStan implementation for the GP with a normally distributed outcome marginalizes\nover the latent Gaussian process, and applies a Cholesky-factor\nreparameterization of the Gaussian to compute the likelihood and the posterior\npredictive distribution analytically.\n\nAfter defining Gaussian processes, this chapter covers the basic\nimplementations for simulation, hyperparameter estimation, and\nposterior predictive inference for univariate regressions,\nmultivariate regressions, and multivariate logistic regressions.\nGaussian processes are very general, and by necessity this chapter\nonly touches on some basic models.  For more information, see\n\\citep{RasmussenWilliams:2006}.\n\n\n\\section{Gaussian Process Regression}\n\nThe data for a multivariate Gaussian process regression consists of a\nseries of $N$ inputs $x_1,\\ldots,x_N \\in \\reals^D$ paired with outputs\n$y_1,\\ldots,y_N \\in \\reals$.  The defining feature of Gaussian\nprocesses is that the probability of a finite number of outputs $y$\nconditioned on their inputs $x$ is Gaussian:\n\\[\ny \\sim \\distro{MultiNormal}(m(x), K(x | \\theta)),\n\\]\nwhere $m(x)$ is an $N$-vector and $K(x | \\theta)$ is an $N \\times N$\ncovariance matrix.  The mean function $m : \\reals^{N \\times D}\n\\rightarrow \\reals^{N}$ can be anything, but the covariance function\n$K : \\reals^{N \\times D} \\rightarrow \\reals^{N \\times N}$ must produce\na positive-definite matrix for any input $x$.%\n%\n\\footnote{Gaussian processes can be extended to covariance functions\n  producing positive semi-definite matrices, but Stan does not support\n  inference in the resulting models because the resulting distribution\n  does not have unconstrained support.}\n\nA popular covariance function, which will be used in the implementations later\nin this chapter, is an exponentiated quadratic function,\n\\[\n  K(x | \\alpha, \\rho, \\sigma)_{i, j}\n= \\alpha^2\n\\exp \\left(\n- \\dfrac{1}{2 \\rho^2} \\sum_{d=1}^D (x_{i,d} - x_{j,d})^2\n\\right)\n+ \\delta_{i, j} \\sigma^2,\n\\]\nwhere $\\alpha$, $\\rho$, and $\\sigma$ are hyperparameters defining the\ncovariance function and where $\\delta_{i, j}$ is the Kronecker delta\nfunction with value 1 if $i = j$ and value 0 otherwise; note that this\ntest is between the indexes $i$ and $j$, not between values $x_i$ and\n$x_j$. Note that this kernel is obtained through a convolution of two\nindependent Gaussian processes, $f_1$ and $f_2$, with kernels\n\\[\n  K_1(x | \\alpha, \\rho)_{i, j}\n= \\alpha^2\n\\exp \\left(\n- \\dfrac{1}{2 \\rho^2} \\sum_{d=1}^D (x_{i,d} - x_{j,d})^2\n\\right)\n\\]\nand\n\\[\n  K_2(x | \\sigma)_{i, j}\n=\n \\delta_{i, j} \\sigma^2,\n\\]\n\nThe addition of $\\sigma^2$ on the diagonal is important\nto ensure the positive definiteness of the resulting matrix in the case of\ntwo identical inputs $x_i = x_j$.  In statistical terms, $\\sigma$ is\nthe scale of the noise term in the regression.\n\nThe hyperparameter $\\rho$ is the \\emph{length-scale}, and corresponds to the\nfrequency of the functions represented by the Gaussian process prior with\nrespect to the domain. Values of $\\rho$ closer to zero lead the GP to represent\nhigh-frequency functions, whereas larger values of $\\rho$ lead to low-frequency\nfunctions. The hyperparameter $\\alpha$ is the \\emph{marginal standard\ndeviation}. It controls the magnitude of the range of the function represented\nby the GP. If you were to take the standard deviation of many draws from the GP\n$f_1$ prior at a single input $x$ conditional on one value of $\\alpha$ one\nwould recover $\\alpha$.\n\nThe only term in the squared exponential covariance function involving\nthe inputs $x_i$ and $x_j$ is their vector difference, $x_i - x_j$.\nThis produces a process with stationary covariance in the sense that\nif an input vector $x$ is translated by a vector $\\epsilon$ to $x +\n\\epsilon$, the covariance at any pair of outputs is unchanged, because\n$K(x | \\theta) = K(x + \\epsilon| \\theta)$.\n\nThe summation involved is just the squared Euclidean distance between\n$x_i$ and $x_j$ (i.e., the $L_2$ norm of their difference, $x_i -\nx_j$). This results in support for smooth functions in the process.\nThe amount of variation in the function is controlled by the free\nhyperparameters $\\alpha$, $\\rho$, and $\\sigma$.\n\nChanging the notion of distance from Euclidean to taxicab distance\n(i.e., an $L_1$ norm) changes the support to functions which are\ncontinuous but not smooth.\n\n\\section{Simulating from a Gaussian Process}\n\nIt is simplest to start with a Stan model that does nothing more than\nsimulate draws of functions $f$ from a Gaussian process.  In practical\nterms, the model will draw values $y_n = f(x_n)$ for finitely many\ninput points $x_n$.\n\nThe Stan model defines the mean and covariance functions in a\ntransformed data block and then samples outputs $y$ in the model using\na multivariate normal distribution.  To make the model concrete, the\nsquared exponential covariance function described in the previous section\nwill be used with hyperparameters set to $\\alpha^2 = 1$, $\\rho^2 = 1$,\nand $\\sigma^2 = 0.1$, and the mean function $m$ is defined to always\nreturn the zero vector, $m(x) = {\\bf 0}$.  Consider the following\nimplementation of a Gaussian process simulator.%\n%\n\\footnote{This model is available in the example model repository;\n  see \\url{http://mc-stan.org/users/documentation}.}\n%\n\\begin{stancode}\ndata {\n  int<lower=1> N;\n  real x[N];\n}\ntransformed data {\n  matrix[N, N] K;\n  vector[N] mu = rep_vector(0, N);\n  for (i in 1:(N - 1)) {\n    K[i, i] = 1 + 0.1;\n    for (j in (i + 1):N) {\n      K[i, j] = exp(-0.5 * square(x[i] - x[j]));\n      K[j, i] = K[i, j];\n    }\n  }\n  K[N, N] = 1 + 0.1;\n}\nparameters {\n  vector[N] y;\n}\nmodel {\n  y ~ multi_normal(mu, K);\n}\n\\end{stancode}\n%\nThe above model can also be written more compactly using the specialized\ncovariance function that implements the exponentiated quadratic kernel.\n%\n\\begin{stancode}\ndata {\n  int<lower=1> N;\n  real x[N];\n}\ntransformed data {\n  matrix[N, N] K = cov_exp_quad(x, 1.0, 1.0);\n  vector[N] mu = rep_vector(0, N);\n  for (n in 1:N)\n    K[n, n] = K[n, n] + 0.1;\n}\nparameters {\n  vector[N] y;\n}\nmodel {\n  y ~ multi_normal(mu, K);\n}\n\\end{stancode}\n%\nThe input data is just the vector of inputs \\code{x} and its size\n\\code{N}.  Such a model can be used with values of \\code{x} evenly\nspaced over some interval in order to plot sample draws of functions\nfrom a Gaussian process.\n\n\\subsection{Multivariate Inputs}\n\nOnly the input data needs to change in moving from a univariate model to a\nmultivariate model.%\n%\n\\footnote{The model is available in the Stan example model repository;\nsee \\url{http://mc-stan.org/users/documentation}.}\n%\nThe only lines that change from the univariate model above are as follows.\n%\n\\begin{stancode}\ndata {\n  int<lower=1> N;\n  int<lower=1> D;\n  vector[D] x[N];\n}\ntransformed data {\n...\n...\n\\end{stancode}\n%\nThe data is now declared as an array of vectors instead of an array of\nscalars; the dimensionality \\code{D} is also declared.\n\nIn the remainder of the chapter, univariate models will be used for simplicity,\nbut any of the models could be changed to multivariate in the same way as the\nsimple sampling model. The only extra computational overhead from a\nmultivariate model is in the distance calculation.\n\n\\subsection{Cholesky Factored and Transformed Implementation}\n\nA more efficient implementation of the simulation model can be\ncoded in Stan by relocating, rescaling and rotating an isotropic unit\nnormal variate.  Suppose $\\eta$ is an an isotropic unit normal variate\n\\[\n\\eta \\sim \\distro{Normal}({\\bf 0}, {\\bf 1}),\n\\]\nwhere ${\\bf 0}$ is an $N$-vector of 0 values and ${\\bf 1}$ is the $N\n\\times N$ identity matrix.  Let $L$ be the Cholesky decomposition of\n$K(x | \\theta)$, i.e., the lower-triangular matrix $L$ such that $LL^{\\top} =\nK(x | \\theta)$.  Then the transformed variable $\\mu + L\\eta$ has the intended\ntarget distribution,\n\\[\n  \\mu + L\\eta \\sim \\distro{MultiNormal}(\\mu(x), K(x | \\theta)).\n\\]\n\nThis transform can be applied directly to Gaussian process\nsimulation.%\n%\n\\footnote{The code is available in the Stan example model repository;\nsee \\url{http://mc-stan.org/users/documentation}.}\n%\nThis model has the same data declarations for \\code{N} and \\code{x},\nand the same transformed data definitions of \\code{mu} and\n\\code{K} as the previous model, with the addition of a transformed\ndata variable for the Cholesky decomposition.  The parameters change\nto the raw parameters sampled from an isotropic unit normal, and the\nactual samples are defined as generated quantities.\n%\n\\begin{stancode}\n...\ntransformed data {\n  matrix[N, N] L;\n...\n  L = cholesky_decompose(K);\n}\nparameters {\n  vector[N] eta;\n}\nmodel {\n  eta ~ normal(0, 1);\n}\ngenerated quantities {\n  vector[N] y;\n  y = mu + L * eta;\n}\n\\end{stancode}\n%\nThe Cholesky decomposition is only computed once, after the data is\nloaded and the covariance matrix \\code{K} computed.  The isotropic\nnormal distribution for \\code{eta} is specified as a vectorized\nunivariate distribution for efficiency; this specifies that each\n\\code{eta[n]} has an independent unit normal distribution.  The sampled\nvector \\code{y} is then defined as a generated quantity using a direct\nencoding of the transform described above.\n\n\\section{Fitting a Gaussian Process}\\label{fit-gp.section}\n\n\\subsection{GP with a normal outcome}\n\nThe full generative model for a GP with a normal outcome,\n$y \\in \\R^N$, with inputs $x \\in \\R^N$, for a finite $N$:\n\n\\begin{align*}\n  \\rho & \\sim \\distro{InvGamma}(5, 5) \\\\\n  \\alpha & \\sim \\distro{Normal}(0, 1) \\\\\n  \\sigma & \\sim \\distro{Normal}(0, 1) \\\\\n  f & \\sim \\distro{MultiNormal}\\left(0, K(x | \\alpha, \\rho)\\right) \\\\\n  y_i & \\sim \\distro{Normal}(f_i, \\sigma) \\, \\forall i \\in \\{1, \\dots, N\\}\n\\end{align*}\n\nWith a normal outcome, it is possible to integrate out the Gaussian\nprocess $f$, yielding the more parsimonious model:\n\n\\begin{align*}\n  \\rho & \\sim \\distro{InvGamma}(5, 5) \\\\\n  \\alpha & \\sim \\distro{Normal}(0, 1) \\\\\n  \\sigma & \\sim \\distro{Normal}(0, 1) \\\\\n  y & \\sim \\distro{MultiNormal}\n  \\left(0, K(x | \\alpha, \\rho) + \\mathbf{I}_N \\sigma^2\\right) \\\\\n\\end{align*}\n\nIt can be more computationally efficient when dealing with a normal\noutcome to integrate out the Gaussian process, because this yields a\nlower-dimensional parameter space over which to do inference. We'll fit\nboth models in Stan. The former model will be referred to as the latent\nvariable GP, while the latter will be called the marginal likelihood\nGP.\n\nThe hyperparameters controlling the covariance function of a Gaussian process\ncan be fit by assigning them priors, like we have in the generative models\nabove, and then computing the posterior distribution of the hyperparameters\ngiven observed data. The priors on the parameters should be defined\nbased on prior knowledge of the scale of the output values ($\\alpha$), the\nscale of the output noise ($\\sigma$), and the scale at which distances are\nmeasured among inputs ($\\rho$). See \\refsection{priors-gp} for more information\nabout how to specify appropriate priors for the hyperparameters.\n\nThe Stan program implementing the marginal likelihood GP is shown below. The\nprogram is similar to the Stan programs that implement the simulation GPs\nabove, but because we are doing inference on the hyperparameters, we need to\ncalculate the covariance matrix \\code{K} in the model block, rather than\nthe transformed data block.\n%\n\\footnote{The program code is available in the Stan example model repository;\nsee \\url{http://mc-stan.org/users/documentation}.}\n\n%\n\\begin{stancode}\ndata {\n  int<lower=1> N;\n  real x[N];\n  vector[N] y;\n}\ntransformed data {\n  vector[N] mu = rep_vector(0, N);\n}\nparameters {\n  real<lower=0> rho;\n  real<lower=0> alpha;\n  real<lower=0> sigma;\n}\nmodel {\n  matrix[N, N] L_K;\n  matrix[N, N] K = cov_exp_quad(x, alpha, rho);\n  real sq_sigma = square(sigma);\n\n  // diagonal elements\n  for (n in 1:N)\n    K[n, n] = K[n, n] + sq_sigma;\n\n  L_K = cholesky_decompose(K);\n\n  rho ~ inv_gamma(5, 5);\n  alpha ~ normal(0, 1);\n  sigma ~ normal(0, 1);\n\n  y ~ multi_normal_cholesky(mu, L_K);\n}\n\\end{stancode}\n%\nThe data block now declares a vector \\code{y} of observed values \\code{y[n]}\nfor inputs \\code{x[n]}.  The transformed data block now only defines the mean\nvector to be zero.  The three hyperparameters are defined as parameters\nconstrained to be non-negative.  The computation of the covariance matrix\n\\code{K} is now in the model block because it involves unknown parameters and\nthus can't simply be precomputed as transformed data.  The rest of the model\nconsists of the priors for the hyperparameters and the multivariate\nCholesky-parameterized normal likelihood, only now the value \\code{y} is known\nand the covariance matrix \\code{K} is an unknown dependent on the\nhyperparameters, allowing us to learn the hyperparameters.\n\nWe have used the Cholesky parameterized \\distro{MultiNormal} rather than the\nstandard \\distro{MultiNormal} because it allows us to the\n\\code{cholesky\\_decompose} function which has been optimized for both small and\nlarge matrices. When working with small matrices the differences in\ncomputational speed between the two approaches will not be noticeable, but for\nlarger matrices ($N \\gtrsim 100$) the Cholesky decomposition version will be\nfaster.\n\nHamiltonian Monte Carlo sampling is quite fast and effective for hyperparameter\ninference in this model \\citep{Neal:1997}. If the posterior is\nwell-concentrated for the hyperparameters the Stan implementation will fit\nhyperparameters in models with a few hundred data points in seconds.\n\n\\subsubsection{Latent variable GP}\n\nWe can also explicitly code the latent variable formulation of a GP in Stan.\nThis will be useful for when the outcome is not normal. We'll need to add a\nsmall positive term, $\\delta$ to the diagonal of the covariance matrix in order\nto ensure that our covariance matrix remains positive definite.\n\n%\n\\begin{stancode}\ndata {\n  int<lower=1> N;\n  real x[N];\n  vector[N] y;\n}\ntransformed data {\n  real delta = 1e-9;\n}\nparameters {\n  real<lower=0> rho;\n  real<lower=0> alpha;\n  real<lower=0> sigma;\n  vector[N] eta;\n}\nmodel {\n  vector[N] f;\n  {\n    matrix[N, N] L_K;\n    matrix[N, N] K = cov_exp_quad(x, alpha, rho);\n\n    // diagonal elements\n    for (n in 1:N)\n      K[n, n] = K[n, n] + delta;\n\n    L_K = cholesky_decompose(K);\n    f = L_K * eta;\n  }\n\n  rho ~ inv_gamma(5, 5);\n  alpha ~ normal(0, 1);\n  sigma ~ normal(0, 1);\n  eta ~ normal(0, 1);\n\n  y ~ normal(f, sigma);\n}\n\\end{stancode}\n%\n\nTwo differences between the latent variable GP and the marginal likelihood GP\nare worth noting. The first is that we have augmented our parameter block with\na new parameter vector of length $N$ called $\\code{eta}$. This is used in the model\nblock to generate a multivariate normal vector called $f$, corresponding to the\nlatent GP. We put a $\\distro{Normal}(0,1)$ prior on $\\code{eta}$ like we did in the\nCholesky-parameterized GP in the simulation section.  The second difference is\nthat our likelihood is now univariate, though we could code $N$ likelihood\nterms as one $N$-dimensional multivariate normal with an identity covariance\nmatrix multiplied by $\\sigma^2$. However, it is more efficient to use the\nvectorized statement as shown above.\n\n\\subsection{Discrete outcomes with Gaussian Processes}\n\nGaussian processes can be generalized the same way as standard linear\nmodels by introducing a link function.  This allows them to be used as\ndiscrete data models.\n\n\\subsubsection{Poisson GP}\n\nIf we want to model count data, we can remove the $\\sigma$ parameter, and use\n\\code{poisson\\_log}, which implements a log link, for our likelihood rather\nthan \\code{normal}. We can also add an overall mean parameter, $a$, which\nwill account for the marginal expected value for $y$. We do this because we\ncannot center count data like we would for normally distributed data.\n\n%\n\\begin{stancode}\ndata {\n...\n  int<lower=0> y[N];\n...\n}\n...\nparameters {\n  real<lower=0> rho;\n  real<lower=0> alpha;\n  real a;\n  vector[N] eta;\n}\nmodel {\n...\n  rho ~ inv_gamma(5, 5);\n  alpha ~ normal(0, 1);\n  a ~ normal(0, 1);\n  eta ~ normal(0, 1);\n\n  y ~ poisson_log(a + f);\n}\n\\end{stancode}\n%\n\n\\subsubsection{Logistic Gaussian Process Regression}\n\nFor binary classification problems, the observed outputs $z_n \\in\n\\setlist{0,1}$ are binary.  These outputs are modeled using a Gaussian\nprocess with (unobserved) outputs $y_n$ through the logistic link,\n\\[\nz_n \\sim \\distro{Bernoulli}(\\mbox{logit}^{-1}(y_n)),\n\\]\nor in other words,\n\\[\n\\mbox{Pr}[z_n = 1] = \\mbox{logit}^{-1}(y_n).\n\\]\n\nWe can extend our latent variable GP Stan program to deal with classification\nproblems. Below $a$ is the bias term, which can help account for imbalanced\nclasses in the training data:\n\n%\n\\begin{stancode}\ndata {\n...\n  int<lower=0, upper=1> z[N];\n...\n}\n...\nmodel {\n...\n\n  y ~ bernoulli_logit(a + f);\n}\n\\end{stancode}\n%\n\n\\subsection{Automatic Relevance Determination}\n\nIf we have multivariate inputs $x \\in \\reals^D$, the squared exponential\ncovariance function can be further generalized by fitting a scale\nparameter $\\rho_d$ for each dimension $d$,\n\\[\n  k(x | \\alpha, \\vec{\\rho}, \\sigma)_{i, j} = \\alpha^2 \\exp\n\\left(-\\dfrac{1}{2}\n\\sum_{d=1}^D \\dfrac{1}{\\rho_d^2} (x_{i,d} - x_{j,d})^2\n\\right)\n+ \\delta_{i, j}\\sigma^2.\n\\]\nThe estimation of $\\rho$ was termed ``automatic relevance determination'' in\n\\citep{Neal:1996}, but this is misleading, because the magnitude the scale of\nthe posterior for each $\\rho_d$ is dependent on the scaling of the input data\nalong dimension $d$. Moreover, the scale of the parameters $\\rho_d$ measures\nnon-linearity along the $d$-th dimension, rather than ``relevance''\n\\citep{PiironenVehtari:2016}.\n\nA priori, the closer $\\rho_d$ is to zero, the more nonlinear the\nconditional mean in dimension $d$ is.  A posteriori, the actual dependencies\nbetween $x$ and $y$ play a role.  With one covariate $x_1$ having a\nlinear effect and another covariate $x_2$ having a nonlinear effect,\nit is possible that $\\rho_1 > \\rho_2$ even if the predictive relevance\nof $x_1$ is higher \\cite[page~80]{RasmussenWilliams:2006}.\nThe collection of $\\rho_d$ (or $1/\\rho_d$) parameters can also be\nmodeled hierarchically.\n\nThe implementation of automatic relevance determination in Stan is\nstraightforward, though it currently requires the user to directly code the\ncovariance matrix. We'll write a function to generate the Cholesky of the\ncovariance matrix called \\code{L\\_cov\\_exp\\_quad\\_ARD}.\n\n%\n\\begin{stancode}\nfunctions {\n  matrix L_cov_exp_quad_ARD(vector[] x,\n                            real alpha,\n                            vector rho,\n                            real delta) {\n    int N = size(x);\n    matrix[N, N] K;\n    real sq_alpha = square(alpha);\n    for (i in 1:(N-1)) {\n      K[i, i] = sq_alpha + delta;\n      for (j in (i + 1):N) {\n        K[i, j] = sq_alpha\n                      * exp(-0.5 * dot_self((x[i] - x[j]) ./ rho));\n        K[j, i] = K[i, j];\n      }\n    }\n    K[N, N] = sq_alpha + delta;\n    return cholesky_decompose(K);\n  }\n}\ndata {\n  int<lower=1> N;\n  int<lower=1> D;\n  vector[D] x[N];\n  vector[N] y;\n}\ntransformed data {\n  real delta = 1e-9;\n}\nparameters {\n  vector<lower=0>[D] rho;\n  real<lower=0> alpha;\n  real<lower=0> sigma;\n  vector[N] eta;\n}\nmodel {\n  vector[N] f;\n  {\n    matrix[N, N] L_K = L_cov_exp_quad_ARD(x, alpha, rho, delta);\n    f = L_K * eta;\n  }\n\n  rho ~ inv_gamma(5, 5);\n  alpha ~ normal(0, 1);\n  sigma ~ normal(0, 1);\n  eta ~ normal(0, 1);\n\n  y ~ normal(f, sigma);\n}\n\\end{stancode}\n%\n\n\\subsection{Priors for Gaussian Process Parameters}\\label{priors-gp.section}\n\nFormulating priors for GP hyperparameters requires the analyst to consider the\ninherent statistical properties of a GP, the GP's purpose in the model, and the\nnumerical issues that may arise in Stan when estimating a GP.\n\nPerhaps most importantly, the parameters $\\rho$ and $\\alpha$ are weakly\nidentified \\citep{zhang-gp:2004}. The ratio of the two\nparameters is well-identified, but in practice we put independent priors on the\ntwo hyperparameters because these two quantities are more interpretable than\ntheir ratio.\n\n\\subsubsection{Priors for length-scale}\n\nGPs are a flexible class of priors, and as such, can represent a wide spectrum\nof functions.  For length scales below the minimum spacing of the covariates\nthe GP likelihood plateaus.  Unless regularized by a prior, this flat\nlikelihood induces considerable posterior mass at small length scales where the\nobservation variance drops to zero and the functions supported by the GP being\nto exactly interpolate between the input data.  The resulting posterior not\nonly significantly overfits to the input data, it also becomes hard to\naccurately sample using Euclidean HMC.\n\nWe may wish to put further soft constraints on the length-scale, but these are\ndependent on how the GP is used in our statistical model.\n\nIf our model consists of only the GP, i.e.:\n%\n\\begin{align*}\n  f & \\sim \\distro{MultiNormal}\\left(0, K(x | \\alpha, \\rho)\\right) \\\\\n  y_i & \\sim \\distro{Normal}(f_i, \\sigma) \\, \\forall i \\in \\{1, \\dots, N\\} \\\\\n  & x \\in \\reals^{N \\times D}, \\, f \\in \\reals^N\n\\end{align*}\n%\nwe likely don't need constraints beyond penalizing small\nlength-scales.  We'd like to allow the GP prior to represent both\nhigh-frequency and low-frequency functions, so our prior should put\nnon-negligible mass on both sets of functions.  In this case, an\ninverse gamma, \\code{inv\\_gamma\\_lpdf} in Stan’s language, will work\nwell as it has a sharp left tail that puts negligible mass on\ninfinitesimal length-scales, but a generous right tail, allowing for\nlarge length-scales. Inverse gamma priors will avoid infinitesimal length-scales\nbecause the density is zero at zero, so the posterior for length-scale will be\npushed away from zero. An inverse gamma distribution is one of many\nzero-avoiding or boundary-avoiding distributions. See\n\\ref{bound-avoid-priors.subsection} for more on boundary-avoiding priors.\n\nIf we're using the GP as a component in a larger model that includes an overall\nmean and fixed effects for the same variables we're using as the domain for the\nGP, i.e.:\n%\n\\begin{align*}\n  f & \\sim \\distro{MultiNormal}\\left(0, K(x | \\alpha, \\rho)\\right) \\\\ y_i &\n  \\sim \\distro{Normal}(\\beta_0 + x_i \\beta_{[1:D]} + f_i, \\sigma) \\, \\forall i\n  \\in \\{1, \\dots, N\\} \\\\ & x_i^T, \\beta_{[1:D]} \\in \\reals^D,\\, x \\in \\reals^{N\n  \\times D},\\, f \\in \\reals^N\n\\end{align*}\n%\nwe'll likely want to constrain large length-scales as well.  A length scale\nthat is larger than the scale of the data yields a GP posterior that is\npractically linear (with respect to the particular covariate) and increasing\nthe length scale has little impact on the likelihood. This will introduce\nnonidentifiability in our model, as both the fixed effects and the GP will\nexplain similar variation. In order to limit the amount of overlap between the\nGP and the linear regression, we should use a prior with a sharper right tail\nto limit the GP to higher-frequency functions. We can use a generalized inverse\nGaussian distribution:\n%\n\\begin{align*}\n  f(x | a, b, p) & = \\dfrac{(a/b)^{p/2}}{2K_p(\\sqrt{ab})} x^{p - 1}\\exp(-(ax + b\n  / x)/2) \\\\\n  & x, a, b \\in \\reals^{+}, \\, p \\in \\mathbb{Z}\n\\end{align*}\n%\nwhich has an inverse gamma left tail if $p \\leq 0$ and an inverse Gaussian\nright tail.  This has not yet been implemented in Stan's math library, but it\nis possible to implement as a user defined function:\n\\begin{stancode}\nfunctions {\n  real generalized_inverse_gaussian_lpdf(real x, int p,\n                                        real a, real b) {\n    return p * 0.5 * log(a / b)\n      - log(2 * modified_bessel_second_kind(p, sqrt(a * b)))\n      + (p - 1) * log(x)\n      - (a * x + b / x) * 0.5;\n }\n}\ndata {\n...\n\\end{stancode}\n\nIf we have high-frequency covariates in our fixed effects, we may wish to\nfurther regularize the GP away from high-frequency functions, which means we'll\nneed to penalize smaller length-scales. Luckily, we have a useful way of\nthinking about how length-scale affects the frequency of the functions\nsupported the GP. If we were to repeatedly draw from a zero-mean GP with a\nlength-scale of $\\rho$ in a fixed-domain $[0,T]$, we would get a distribution\nfor the number of times each draw of the GP crossed the zero axis. The\nexpectation of this random variable, the number of zero crossings, is $T / \\pi\n\\rho$. You can see that as $\\rho$ decreases, the expectation of the number of\nupcrossings increases as the GP is representing higher-frequency functions.\nThus, this is a good statistic to keep in mind when setting a lower-bound for\nour prior on length-scale in the presence of high-frequency covariates.\nHowever, this statistic is only valid for one-dimensional inputs.\n\n\\subsubsection{Priors for marginal standard deviation}\n\nThe parameter $\\alpha$ corresponds to how much of the variation is\nexplained by the regression function and has a similar role to the\nprior variance for linear model weights.  This means the prior can be\nthe same as used in linear models, such as a half-$t$ prior on $\\alpha$.\n\nA half-$t$ or half-Gaussian prior on alpha also has the benefit of putting\nnontrivial prior mass around zero. This allows the GP support the zero\nfunctions and allows the possibility that the GP won't contribute to the\nconditional mean of the total output.\n\n\\subsection{Predictive Inference with a Gaussian Process}\n\nSuppose for a given sequence of inputs $x$ that the corresponding\noutputs $y$ are observed.  Given a new sequence of inputs $\\tilde{x}$,\nthe posterior predictive distribution of their labels is computed by\nsampling outputs $\\tilde{y}$ according to\n\\[\np(\\tilde{y}|\\tilde{x},x,y)\n\\ = \\\n\\frac{p(\\tilde{y}, y|\\tilde{x},x)}\n     {p(y|x)}\n\\ \\propto \\\np(\\tilde{y}, y|\\tilde{x},x).\n\\]\n\nA direct implementation in Stan defines a model in terms of the\njoint distribution of the observed $y$ and unobserved $\\tilde{y}$.\n%\n\\begin{stancode}\ndata {\n  int<lower=1> N1;\n  real x1[N1];\n  vector[N1] y1;\n  int<lower=1> N2;\n  real x2[N2];\n}\ntransformed data {\n  real delta = 1e-9;\n  int<lower=1> N = N1 + N2;\n  real x[N];\n  for (n1 in 1:N1) x[n1] = x1[n1];\n  for (n2 in 1:N2) x[N1 + n2] = x2[n2];\n}\nparameters {\n  real<lower=0> rho;\n  real<lower=0> alpha;\n  real<lower=0> sigma;\n  vector[N] eta;\n}\ntransformed parameters {\n  vector[N] f;\n  {\n    matrix[N, N] L_K;\n    matrix[N, N] K = cov_exp_quad(x, alpha, rho);\n\n    // diagonal elements\n    for (n in 1:N)\n      K[n, n] = K[n, n] + delta;\n\n    L_K = cholesky_decompose(K);\n    f = L_K * eta;\n  }\n}\nmodel {\n  rho ~ inv_gamma(5, 5);\n  alpha ~ normal(0, 1);\n  sigma ~ normal(0, 1);\n  eta ~ normal(0, 1);\n\n  y1 ~ normal(f[1:N1], sigma);\n}\ngenerated quantities {\n  vector[N2] y2;\n  for (n2 in 1:N2)\n    y2[n2] = normal_rng(f[N1 + n2], sigma);\n}\n\\end{stancode}\n%\n\nThe input vectors \\code{x1} and \\code{x2} are declared as data, as is the\nobserved output vector \\code{y1}.  The unknown output vector \\code{y2}, which\ncorresponds to input vector \\code{x2}, is declared in the generated quantities\nblock and will be sampled when the model is executed.\n\nA transformed data block is used to combine the input vectors\n\\code{x1} and \\code{x2} into a single vector \\code{x}.\n\nThe model block declares and defines a local variable for the combined output\nvector \\code{f}, which consists of the concatenation of the conditional mean\nfor known outputs \\code{y1} and unknown outputs \\code{y2}.  Thus the\ncombined output vector \\code{f} is aligned with the combined\ninput vector \\code{x}.  All that is left is to define the univariate\nnormal sampling statement for \\code{y}.\n\nThe generated quantities block defines the quantity \\code{y2}. We generate\n\\code{y2} by sampling \\code{N2} univariate normals with each mean corresponding\nto the appropriate element in \\code{f}.\n\\footnote{The program code is available in the Stan example model repository;\nsee \\url{http://mc-stan.org/users/documentation}.}\n%\n\n\\subsubsection{Predictive Inference in non-Gaussian GPs}\n\nWe can do predictive inference in non-Gaussian GPs in much the\nsame way as we do with Gaussian GPs.\n\nConsider the following full model for prediction using logistic Gaussian\nprocess regression.\n%\n\\footnote{The model is available in the Stan example model repository;\nsee \\url{http://mc-stan.org/users/documentation}.}\n%\n%\n\\begin{stancode}\ndata {\n  int<lower=1> N1;\n  real x1[N1];\n  int<lower=0, upper=1> z1[N1];\n  int<lower=1> N2;\n  real x2[N2];\n}\ntransformed data {\n  real delta = 1e-9;\n  int<lower=1> N = N1 + N2;\n  real x[N];\n  for (n1 in 1:N1) x[n1] = x1[n1];\n  for (n2 in 1:N2) x[N1 + n2] = x2[n2];\n}\nparameters {\n  real<lower=0> rho;\n  real<lower=0> alpha;\n  real a;\n  vector[N] eta;\n}\ntransformed parameters {\n  vector[N] f;\n  {\n    matrix[N, N] L_K;\n    matrix[N, N] K = cov_exp_quad(x, alpha, rho);\n\n    // diagonal elements\n    for (n in 1:N)\n      K[n, n] = K[n, n] + delta;\n\n    L_K = cholesky_decompose(K);\n    f = L_K * eta;\n  }\n}\nmodel {\n  rho ~ inv_gamma(5, 5);\n  alpha ~ normal(0, 1);\n  a ~ normal(0, 1);\n  eta ~ normal(0, 1);\n\n  z1 ~ bernoulli_logit(a + f[1:N1]);\n}\ngenerated quantities {\n  int z2[N2];\n  for (n2 in 1:N2)\n    z2[n2] = bernoulli_logit_rng(a + f[N1 + n2]);\n}\n\\end{stancode}\n%\n\n\\subsubsection{Analytical Form of Joint Predictive Inference}\n\nBayesian predictive inference for Gaussian processes with Gaussian observations\ncan be sped up by deriving the posterior analytically, then directly sampling\nfrom it.\n\nJumping straight to the result,\n\\[\np(\\tilde{y}|\\tilde{x},y,x)\n=\n\\distro{Normal}(K^{\\top}\\Sigma^{-1}y,\\\n                \\Omega - K^{\\top}\\Sigma^{-1}K),\n\\]\nwhere $\\Sigma = K(x | \\alpha, \\rho, \\sigma)$ is the result of applying the covariance\nfunction to the inputs $x$ with observed outputs $y$, $\\Omega =\nK(\\tilde{x} | \\alpha, \\rho)$ is the result of applying the covariance function to the\ninputs $\\tilde{x}$ for which predictions are to be inferred, and $K$\nis the matrix of covariances between inputs $x$ and $\\tilde{x}$, which\nin the case of the exponentiated quadratic covariance function\nwould be\n\\[ K(x | \\alpha, \\rho)_{i, j} = \\eta^2 \\exp(-\\dfrac{1}{2 \\rho^2}\n\\sum_{d=1}^D (x_{i,d} - \\tilde{x}_{j,d})^2).  \\]\nThere is no noise term including $\\sigma^2$ because the indexes of\nelements in $x$ and $\\tilde{x}$ are never the same.\n\n%\n\\footnote{The program code is available in the Stan example model repository;\nsee \\url{http://mc-stan.org/users/documentation}.}\n%\nThis Stan code below uses the analytic form of the posterior and provides\nsampling of the resulting multivariate normal through the Cholesky\ndecomposition. The data declaration is the same as for the latent variable\nexample, but we've defined a function called \\code{gp\\_pred\\_rng} which will\ngenerate a draw from the posterior predictive mean conditioned on observed data\n\\code{y1}. The code uses a Cholesky decomposition in triangular solves in order\nto cut down on the the number of matrix-matrix multiplications when computing\nthe conditional mean and the conditional covariance of $p(\\tilde{y})$.\n\n\\begin{stancode}\nfunctions {\n  vector gp_pred_rng(real[] x2,\n                     vector y1,\n                     real[] x1,\n                     real alpha,\n                     real rho,\n                     real sigma,\n                     real delta) {\n    int N1 = rows(y1);\n    int N2 = size(x2);\n    vector[N2] f2;\n    {\n      matrix[N1, N1] L_K;\n      vector[N1] K_div_y1;\n      matrix[N1, N2] k_x1_x2;\n      matrix[N1, N2] v_pred;\n      vector[N2] f2_mu;\n      matrix[N2, N2] cov_f2;\n      matrix[N2, N2] diag_delta;\n      matrix[N1, N1] K;\n      K = cov_exp_quad(x1, alpha, rho);\n      for (n in 1:N1)\n        K[n, n] = K[n,n] + square(sigma);\n      L_K = cholesky_decompose(K);\n      K_div_y1 = mdivide_left_tri_low(L_K, y1);\n      K_div_y1 = mdivide_right_tri_low(K_div_y1',L_K)';\n      k_x1_x2 = cov_exp_quad(x1, x2, alpha, rho);\n      f2_mu = (k_x1_x2' * K_div_y1);\n      v_pred = mdivide_left_tri_low(L_K, k_x1_x2);\n      cov_f2 = cov_exp_quad(x2, alpha, rho) - v_pred' * v_pred;\n      diag_delta = diag_matrix(rep_vector(delta,N2));\n\n      f2 = multi_normal_rng(f2_mu, cov_f2 + diag_delta);\n    }\n    return f2;\n  }\n}\ndata {\n  int<lower=1> N1;\n  real x1[N1];\n  vector[N1] y1;\n  int<lower=1> N2;\n  real x2[N2];\n}\ntransformed data {\n  vector[N1] mu = rep_vector(0, N1);\n  real delta = 1e-9;\n}\nparameters {\n  real<lower=0> rho;\n  real<lower=0> alpha;\n  real<lower=0> sigma;\n}\nmodel {\n  matrix[N1, N1] L_K;\n  {\n    matrix[N1, N1] K = cov_exp_quad(x1, alpha, rho);\n    real sq_sigma = square(sigma);\n\n    // diagonal elements\n    for (n1 in 1:N1)\n      K[n1, n1] = K[n1, n1] + sq_sigma;\n\n    L_K = cholesky_decompose(K);\n  }\n\n  rho ~ inv_gamma(5, 5);\n  alpha ~ normal(0, 1);\n  sigma ~ normal(0, 1);\n\n  y1 ~ multi_normal_cholesky(mu, L_K);\n}\ngenerated quantities {\n  vector[N2] f2;\n  vector[N2] y2;\n\n  f2 = gp_pred_rng(x2, y1, x1, alpha, rho, sigma, delta);\n  for (n2 in 1:N2)\n    y2[n2] = normal_rng(f2[n2], sigma);\n}\n\\end{stancode}\n\n\\subsection{Multiple-output Gaussian processes}\n\nSuppose we have observations $y_i \\in \\reals^M$ observed at\n$x_i \\in \\reals^K$. One can model the data like so:\n\\begin{align*}\n  y_i & \\sim \\distro{MultiNormal}(f(x_i), \\mathbf{I}_M \\sigma^2) \\\\\n  f(x) & \\sim \\distro{GP}(m(x), K(x | \\theta, \\phi)) \\\\\n  K(x & | \\theta) \\in \\reals^{M \\times M}, \\, f(x), \\, m(x) \\in \\reals^M\n\\end{align*}\nwhere the $K(x, x^\\prime | \\theta, \\phi)_{[m, m^\\prime]}$ entry defines the\ncovariance between $f_m(x)$ and $f_{m^\\prime}(x^\\prime)(x)$. This construction\nof Gaussian processes allows us to learn the covariance between the output\ndimensions of $f(x)$. If we parameterize our kernel $K$:\n\\begin{align*} K(x, x^\\prime | \\theta, \\phi)_{[m, m^\\prime]} = k(x, x^\\prime |\n\\theta) k(m, m^\\prime | \\phi) \\end{align*}\nthen our finite dimensional generative model for the above is:\n\\begin{align*}\n  f & \\sim \\distro{MatrixNormal}(m(x), K(x | \\alpha, \\rho), C(\\phi)) \\\\\n  y_{i, m} & \\sim \\distro{Normal}(f_{i,m}, \\sigma) \\\\\n  f & \\in \\reals^{N \\times M}\n\\end{align*}\nwhere $K(x | \\alpha, \\rho)$ is the exponentiated quadratic kernel we've used\nthroughout this chapter, and $C(\\phi)$ is a positive-definite matrix,\nparameterized by some vector $\\phi$.\n\nThe \\distro{MatrixNormal} distribution has two covariance matrices: $K(x |\n\\alpha, \\rho)$ to encode column covariance, and $C(\\phi)$ to define row\ncovariance. The salient features of the \\distro{MatrixNormal} are that the rows\nof the matrix $f$ are distributed:\n\\begin{align*} f_{[n,]} \\sim \\distro{MultiNormal}(m(x)_{[n,]}, K(x | \\alpha,\n\\rho)_{[n,n]} C(\\phi)) \\end{align*} and that the columns of the matrix $f$ are\ndistributed: \\begin{align*} f_{[,m]} \\sim \\distro{MultiNormal}(m(x)_{[,m]}, K(x\n  | \\alpha, \\rho) C(\\phi)_{[m,m]}) \\end{align*}\nThis also means means that $\\E\\left[f^T f\\right]$ is equal to\n$\\text{trace}(K(x | \\alpha, \\rho)) \\times C$, whereas $\\E\\left[ff^T\\right]$\nis $\\text{trace}(C) \\times K(x | \\alpha, \\rho)$. We can derive this using\nproperties of expectation and the \\distro{MatrixNormal} density.\n\nWe should set $\\alpha$ to $1.0$ because the parameter is not identified unless\nwe constrain $\\text{trace}(C) = 1$. Otherwise, we can multiply $\\alpha$ by a scalar $d$ and\n$C$ by $1/d$ and our likelihood will not change.\n%\nWe can generate a random variable $f$ from a \\distro{MatrixNormal} density in\n$\\reals^{N \\times M}$ using the following algorithm:\n%\n\\begin{align*}\n  \\eta_{i,j} & \\sim \\distro{Normal}(0, 1) \\, \\forall i,j \\\\\n  f & = L_{K(x | 1.0, \\rho)} \\, \\eta \\, L_C(\\phi)^T \\\\\n  f & \\sim \\distro{MatrixNormal}(0, K(x | 1.0, \\rho), C(\\phi)) \\\\\n  \\eta & \\in \\reals^{N \\times M} \\\\\n  L_C(\\phi) & = \\text{cholesky\\_decompose}(C(\\phi)) \\\\\n  L_{K(x | 1.0, \\rho)} & = \\text{cholesky\\_decompose}(K(x | 1.0, \\rho))\n\\end{align*}\n\nThis can be implemented in Stan using a latent-variable GP formulation. We've used\n\\distro{LkjCorr} for $C(\\phi)$, but any positive-definite matrix will do.\n\n\n\\begin{stancode}\ndata {\n  int<lower=1> N;\n  int<lower=1> D;\n  real x[N];\n  matrix[N, D] y;\n}\ntransformed data {\n  real delta = 1e-9;\n}\nparameters {\n  real<lower=0> rho;\n  vector<lower=0>[D] alpha;\n  real<lower=0> sigma;\n  cholesky_factor_corr[D] L_Omega;\n  matrix[N, D] eta;\n}\nmodel {\n  matrix[N, D] f;\n  {\n    matrix[N, N] K = cov_exp_quad(x, 1.0, rho);\n    matrix[N, N] L_K;\n\n    // diagonal elements\n    for (n in 1:N)\n      K[n, n] = K[n, n] + delta;\n\n    L_K = cholesky_decompose(K);\n    f = L_K * eta\n        * diag_pre_multiply(alpha, L_Omega)';\n  }\n\n  rho ~ inv_gamma(5, 5);\n  alpha ~ normal(0, 1);\n  sigma ~ normal(0, 1);\n  L_Omega ~ lkj_corr_cholesky(3);\n  to_vector(eta) ~ normal(0, 1);\n\n  to_vector(y) ~ normal(to_vector(f), sigma);\n}\ngenerated quantities {\n  matrix[D, D] Omega;\n  Omega = L_Omega * L_Omega';\n}\n\\end{stancode}\n\n\\chapter{Directions, Rotations, and Hyperspheres}\n\nDirectional statistics involve data and/or parameters that are\nconstrained to be directions.  The set of directions forms a sphere,\nthe geometry of which is not smoothly mappable to that of a Euclidean\nspace because you can move around a sphere and come back to where you\nstarted.  This is why it is impossible to make a map of the globe on a\nflat piece of paper where all points that are close to each other on\nthe globe are close to each other on the flat map.  The fundamental\nproblem is easy to visualize in two dimensions, because as you move\naround a circle, you wind up back where you started.  In other words,\n0 degrees and 360 degrees (equivalently, 0 and $2 \\pi$ radians) pick\nout the same point, and the distance between 359 degrees and 2 degrees\nis the same as the distance between 137 and 140 degrees.\n\nStan supports directional statistics by providing a unit-vector data\ntype, the values of which determine points on a hypersphere (circle in\ntwo dimensions, sphere in three dimensions).\n\n\\section{Unit Vectors}\n\nThe length of a vector $x \\in \\reals^K$ is given by\n\\[\n\\Vert x \\Vert\n\\ = \\ \\sqrt{x^{\\top}\\,x}\n\\ = \\ \\sqrt{x_1^2 + x_2^2 + \\cdots + x_K^2}.\n\\]\nUnit vectors are defined to be vectors of unit length (i.e., length\none).\n\nWith a variable declaration such as\n%\n\\begin{stancode}\nunit_vector[K] x;\n\\end{stancode}\n%\nthe value of \\code{x} will be constrained to be a vector of size\n\\code{K} with unit length.  \\refsection{unit-vector} provides details\non how a parameter constrained to be a unit-vector is transformed to\nunconstrained space for use in Stan's algorithms.\n\n\\section{Circles, Spheres, and Hyperspheres}\n\nAn $n$-sphere, written $S^{n}$, is defined as the set of $(n +\n1)$-dimensional unit vectors,\n\\[\nS^{n} = \\{ x \\in \\reals^{n+1} \\, : \\, \\Vert x \\Vert = 1 \\}.\n\\]\n%\nEven though $S^n$ is made up of points in $(n+1)$ dimensions, it is\nonly an $n$-dimensional manifold.  For example, $S^2$ is defined as a\nset of points in $\\reals^3$, but each such point may be described\nuniquely by a latitude and longitude.  Geometrically, the surface\ndefined by $S^2$ in $\\reals^3$ behaves locally like a plane, i.e.,\n$\\reals^2$.  However, the overall shape of $S^2$ is not like a plane\nin that is compact (i.e., there is a maximum distance between points).\nIf you set off around the globe in a ``straight line'' (i.e., a\ngeodesic), you wind up back where you started eventually; that is why\nthe geodesics on the sphere ($S^2$) are called ``great circles,'' and\nwhy we need to use some clever representations to do circular or\nspherical statistics.\n\nEven though $S^{n-1}$ behaves locally like $\\reals^{n-1}$, there is no\nway to smoothly map between them. For example, because\nlatitude and longitude work on a modular basis (wrapping at $2\\pi$\nradians in natural units), they do not produce a smooth map.\n\nLike a bounded interval $(a, b)$, in geometric terms, a sphere is\ncompact in that the distance between any two points is bounded.\n\n\n\\section{Transforming to Unconstrained Parameters}\n\nStan (inverse) transforms arbitrary points in $\\reals^{K+1}$ to points\nin $S^K$ using the auxiliary variable approach of\n\\cite{Marsaglia:1972}.  A point $y \\in \\reals^K$ is transformed to a\npoint $x \\in S^{K-1}$ by\n%\n\\[\nx = \\frac{y}{\\sqrt{y^{\\top} y}}.\n\\]\n%\nThe problem with this mapping is that it's many to one; any point\nlying on a vector out of the origin is projected to the same point on\nthe surface of the sphere.  \\cite{Marsaglia:1972} introduced an\nauxiliary variable interpretation of this mapping that provides the\ndesired properties of uniformity; see \\refsection{unit-vector} for\ndetails.\n\n\n\\subsubsection{Warning: undefined at zero!}\n\nThe above mapping from $\\reals^n$ to $S^n$ is not defined at zero.\nWhile this point outcome has measure zero during sampling, and may\nthus be ignored, it is the default initialization point and thus unit\nvector parameters cannot be initialized at zero.  A simple workaround\nis to initialize from a very small interval around zero, which is an\noption built into all of the Stan interfaces.\n\n\n\n\\section{Unit Vectors and Rotations}\n\nUnit vectors correspond directly to angles and thus to rotations.\nThis is easy to see in two dimensions, where a point on a circle\ndetermines a compass direction, or equivalently, an angle $\\theta$).\nGiven an angle $\\theta$, a matrix can be defined, the\npre-multiplication by which rotates a point by an angle of $\\theta$.\nFor angle $\\theta$ (in two dimensions), the $2 \\times 2$ rotation\nmatrix is defined by\n\\[\nR_{\\theta}\n=\n\\begin{bmatrix}\n\\cos \\theta & - \\sin \\theta\n\\\\\n\\sin \\theta & \\cos \\theta\n\\end{bmatrix}.\n\\]\nGiven a two-dimensional vector $x$, $R_{\\theta} \\, x$ is the rotation\nof $x$ (around the origin) by $\\theta$ degrees.\n\n\\section{Circular Representations of Days and Years}\n\nA 24-hour clock naturally represents the progression of time through\nthe day, moving from midnight to noon and back again in one rotation.\nA point on a circle divided into 24 hours is thus a natural\nrepresentation for the time of day.  Similarly, years cycle through\nthe seasons and return to the season from which they started.\n\nIn human affairs, temporal effects often arise by convention.  These\ncan be modeled directly with ad-hoc predictors for holidays and\nweekends, or with data normalization back to natural scales for\ndaylight savings time.\n\n\\chapter{Solving Algebraic Equations}\\label{algebra-solver.chapter}\n\n\\noindent\nStan provides a built-in mechanism for specifying and solving systems\nof algebraic equations, using the Powell hybrid method \\citep{Powell:1970}.\nThe function signatures for Stan's algebraic solver can be found in\n\\refsection{functions-algebraic-solver}.\n%\nSolving any system of algebraic equations can be translated into a root-finding\nproblem, that is, given a function $f$, we wish to find $y$ such that\n$f(y) = 0$.\n\n\\section{Example: System of Nonlinear Algebraic Equations}\n\nFor systems of linear algebraic equations, we recommend solving the system\nusing matrix division. The algebraic solver becomes handy when we want\nto solve nonlinear equations.\n%\nAs an illustrative example, we consider a nonlinear system of two equations\nwith two unknowns. Our goal is to simultaneously solve all equations for\n$y_1$ and $y_2$, such that the vector $z$ goes to 0.\n%\n\\begin{eqnarray}\\label{algebra.equation}\n  \\begin{aligned}\n  z_1 &= y_1 - \\theta_1 \\\\\n  z_2 &= y_1 y_2 + \\theta_2 \\\\\n  \\end{aligned}\n\\end{eqnarray}\n%\n\n\\section{Coding an Algebraic System}\n\nA system of algebraic equations is coded directly in Stan as a function with a\nstrictly specified signature. For example, the nonlinear system given by\n\\refequation{algebra} can be coded using the following function\nin Stan (see \\refchapter{functions-programming} for\nmore information on coding user-defined functions).\n%\n\\begin{stancode}\nvector system(vector y,        // unknowns\n              vector theta,    // parameters\n              real[] x_r,      // data (real)\n              int[] x_i) {     // data (integer)\n  vector[2] z;\n  z[1] = y[1] - theta[1];\n  z[2] = y[1] * y[2] - theta[2];\n  return z;\n}\n\\end{stancode}\n%\nThe function takes the unknowns we wish to solve for in \\code{y} (a vector),\nthe system parameters in \\code{theta} (a vector), the real data in\n\\code{x\\_r} (a real array) and the integer data in \\code{x\\_i} (an integer array). The\nsystem function returns the value of the function (a vector), for which we want to compute\nthe roots. Our example does not use real or integer data. Nevertheless, these\nunused arguments must be included in the system function with exactly the\nsignature above.\n\n\\subsubsection{Strict Signature}\n%\nThe function defining the system must have exactly these argument types and\nreturn type. This may require passing in zero-length arrays for data or a zero-length\nvector for parameters if the system does not involve data or parameters.\n\n\\section{Calling the Algebraic Solver}\n%\nLet's suppose $\\theta = \\{3, 6\\}$. To call the algebraic solver, we need to\nprovide an initial guess. This varies on a case-by-case basis, but in general\na good guess will speed up the solver and, in pathological cases, even determine\nwhether the solver converges or not. If the solver does not converge, the metropolis\nproposal gets rejected and a warning message, stating no acceptable solution was\nfound, is issued.\n\nThe solver has three tuning parameters to determine convergence: the relative tolerance,\nthe function tolerance, and the maximum number of steps. Their default values are respectively\n\\code{1e-10} ($10^{-10}$), \\code{1e-6} ($10^{-6}$), and \\code{1e3} ($10^3$). Their\nbehavior is explained in \\refsection{algebra-control}.\n%\nThe following code returns the solution to our nonlinear algebraic system:\n%\n\\begin{stancode}\ntransformed data {\n  vector[2] y_guess = {1, 1};\n  real x_r[0];\n  int x_i[0];\n}\n\ntransformed parameters {\n  vector[2] theta = {3, 6};\n  vector[2] y;\n\n  y = algebra_solver(system, y_guess, theta, x_r, x_i);\n}\n\\end{stancode}\n\nwhich returns $y = \\{3, -2\\}$.\n\n\\subsection{Data versus Parameters}\nThe arguments for the real data \\code{x\\_r} and\nthe integer data \\code{x\\_i} must be expressions that only involve data or\ntransformed data variables. \\code{theta}, on the other hand,\nmust only involve parameters. Note there are no restrictions on the initial guess,\n\\code{y\\_guess}, which may be a data or a parameter vector.\n\n\\subsection{Length of the Algebraic Function and of the Vector of Unknowns}\nThe Jacobian of the solution with respect to the parameters is computed\nusing the implicit function theorem, which imposes certain restrictions. In particular,\nthe Jacobian of the algebraic function $f$ with respect to the unknowns $x$ must\nbe invertible. This requires the Jacobian to be square, meaning \\textit{$f(y)$ and\n$y$ have the same length} or, in other words \\textit{the number of equations in\nthe system is the same as the number of unknowns.}\n\n\\subsection{Pathological Solutions}\nCertain systems may be degenerate, meaning they have multiple solutions. The\nalgebraic solver will not report these cases, as the algorithm stops once it has found\nan acceptable solution. The initial guess will often determine which solution gets found\nfirst. The degeneracy may be broken by putting additional constraints on the solution.\nFor instance, it might make ``physical sense'' for a solution to be positive or negative.\n\nOn the other hand, a system may not have a solution (for a given point in the parameter\nspace). In that case, the solver will not converge to a solution. When the solver fails to\ndo so, the current metropolis proposal gets rejected.\n\n\\section{Control Parameters for the Algebraic Solver}\\label{algebra-control.section}\n%\nThe call to the algebraic solver shown above uses the default control settings. The solver\nallows three additional parameters, all of which must be supplied if any of them is\nsupplied.\n%\n\\begin{stancode}\n  y = algebra_solver(system, y_guess, theta, x_r, x_i,\n                     rel_tol, f_tol, max_steps);\n\\end{stancode}\n\nThe three control arguments are relative tolerance, function tolerance, and maximum\nnumber of steps. Both tolerances need to be satisfied. If one of them is not met, the\nmetropolis proposal gets rejected with a warning message explaining which criterion\nwas not satisfied. The default values for the control arguments are respectively\n\\code{1e-10} ($10^{-10}$), \\code{1e-6} ($10^{-6}$), and \\code{1e3} ($10^3$).\n\n\\subsection{Tolerance}\n%\nThe relative and function tolerances control the accuracy of the solution generated by\nthe solver. Relative tolerances are relative to the solution value. The function tolerance\nis the norm of the algebraic function, once we plug in the proposed solution. This norm\nshould go to 0 (equivalently, all elements of the vector function are 0). It helps to think about this\ngeometrically. Ideally the output of the algebraic function is at the origin; the norm measures\ndeviations from this ideal. As the length of the return vector increases, a certain\nfunction tolerance becomes an increasingly difficult criterion to meet, given each\nindividual element of the vector contribute to the norm.\n\nSmaller relative tolerances produce more accurate solutions but require more computational time.\n\n\\subsubsection{Sensitivity Analysis} \\ \\\\\nThe tolerances should be set low enough that setting them lower does not change the\nstatistical properties of posterior samples generated by the Stan program.\n\n\\subsection{Maximum Number of Steps}\n%\nThe maximum number of steps can be used to stop a runaway simulation. This can arise in\nMCMC when a bad jump is taken, particularly during warmup. If the limit is hit, the\ncurrent metropolis proposal gets rejected. Users will see a  warning message stating the\nmaximum number of steps has been exceeded.\n\n\n\\chapter{Solving Differential Equations}\\label{ode-solver.chapter}\n\n\\noindent\nStan provides a built-in mechanism for specifying and solving systems\nof ordinary differential equations (ODEs).  Stan provides two\ndifferent integrators, one tuned for solving non-stiff systems and one\nfor stiff systems.\n%\n\\begin{itemize}\n\\item \\code{rk45}: a fourth and fifth order Runge-Kutta method for\n  non-stiff systems \\citep{DormandPrince:1980,AhnertMulansky:2011}, and\n\\item \\code{bdf}: a variable-step, variable-order,\n  backward-differentiation formula implementation for stiff systems\n  \\citep{CohenHindmarsh:1996,SerbanHindmarsh:2005}\n\\end{itemize}\n%\nFor a discussion of stiff ODE systems, see \\refsection{stiff-ode}.  In\na nutshell, the stiff solvers are slower, but more robust;  how much\nso depends on the system and the region of parameter space.\nThe function signatures for Stan's ODE solvers can be found in\n\\refsection{functions-ode-solver}.\n\n\n\\section{Example: Simple Harmonic Oscillator}\n\nAs a concrete example of a system of ODEs, consider a harmonic\noscillator, which is characterized by an equilibrium position and a\nrestoring force proportional to the displacement with friction.\nThe system state will be a pair $y = (y_1, y_2)$ representing position\nand momentum (i.e., a point in phase space).  The change in the system\nwith respect to time is given by the following differential equations.%\n%\n\\footnote{This example is drawn from the documentation for the Boost\n  Numeric Odeint library \\citep{AhnertMulansky:2011}, which Stan uses\n  to implement the \\code{rk45} solver.}\n%\n\\begin{equation}\\label{ode-sho.equation}\n\\frac{d}{dt} y_1 = y_2\n\\hspace*{0.5in}\n\\frac{d}{dt} y_2 = -y_1 - \\theta y_2\n\\end{equation}\n%\nThe state equations implicitly define the system state at a given time\nas a function of an initial state, elapsed time since the initial\nstate, and the system parameters.\n\n\\subsection{Solutions Given Initial Conditions}\n\nGiven a value of the system parameter $\\theta$ and an initial state\n$y(t_0)$ at time $t_0$, it is possible to simulate the evolution of\nthe solution numerically in order to calculate $y(t)$ for a specified\nsequence of times $t_0 < t_1 < t_2 < \\cdots$.\n\n\\section{Coding an ODE System}\n\nA system of ODEs is coded directly in Stan as a function with a\nstrictly specified signature.  For example, the simple harmonic\noscillator given in \\refequation{ode-sho}, can be coded using the\nfollowing function in Stan (see \\refchapter{functions-programming} for\nmore information on coding user-defined functions).\n%\n\\begin{stancode}\nreal[] sho(real t,        // time\n           real[] y,      // state\n           real[] theta,  // parameters\n           real[] x_r,    // data (real)\n           int[] x_i) {   // data (integer)\n  real dydt[2];\n  dydt[1] = y[2];\n  dydt[2] = -y[1] - theta[1] * y[2];\n  return dydt;\n}\n\\end{stancode}\n%\nThe function takes in a time \\code{t} (a real value), a a system state\n\\code{y} (real array), system parameters \\code{theta} (a real array),\nalong with real data in variable \\code{x\\_r} (a real array) and\ninteger data in variable \\code{x\\_i} (an integer array).  The system\nfunction returns the array of derivatives of the system state with\nrespect to time, evaluated at time \\code{t} and state \\code{y}.  The\nsimple harmonic oscillator coded here does not have time-sensitive\nequations; that is, \\code{t} does not show up in the definition of\n\\code{dydt}.  The simple harmonic oscillator does not use real or\ninteger data, either.  Nevertheless, these unused arguments must be\nincluded as arguments in the system function with exactly the\nsignature shown above.\n\n\n\\subsection{Strict Signature}\n\nThe function defining the system must have exactly these argument\ntypes and return type.  This may require passing in zero-length arrays\nfor data or parameters if the system does not involve data or\nparameters.  A full example for the simple harmonic oscillator, which\ndoes not depend on any constant data variables, is provided in\n\\reffigure{sho-trajectory}.\n\n\\subsection{Discontinuous ODE System Function}\n\nThe ODE integrator is able to integrate over discontinuities in the\nstate function, although the accuracy of points near the discontinuity\nmay be problematic (requiring many small steps).  An example of such a\ndiscontinuity is a lag in a pharmacokinetic model, where a\nconcentration is going to be zero for times $0 < t < t'$ for some\nlag-time $t'$, whereas it will be nonzero for times $t \\geq t'$.  As\nan example, would involve code in the system such as\n%\n\\begin{stancode}\nif (t < t_lag)\n  return 0;\nelse\n  ... return non-zero value...;\n\\end{stancode}\n\n\n\\subsection{Varying Initial Time}\n\nStan's ODE solvers require the initial time argument to be a constant\n(i.e., a function of data or transformed data variables and\nconstants).  This means that, in general, there's no way to use the\n\\code{integrate\\_ode} function to accept a parameter for the initial\ntime and thus no way in general to estimate the initial time of an ODE\nsystem from measurements.\n\n\\section{Solving a System of Linear ODEs using a Matrix Exponential}\n\nThe solution to $\\frac{d}{dt} y = ay$ is $y = y_0e^{at}$, where the constant\n$y_0$ is determined by boundary conditions. We can extend this solution\nto the vector case:\n\n\\begin{equation}\\label{ode.linODEs}\n\\frac{d}{dt}y = A y\n\\end{equation}\n\nwhere $y$ is now a vector of length $n$ and $A$ is an $n$ by $n$ matrix. The\nsolution is then given by:\n\\begin{equation}\\label{ode.linOEs.sln}\ny = e^{tA}y_0\n\\end{equation}\nwhere the matrix exponential is formally defined by the convergent power series:\n\n\\begin{equation}\\label{ode.matrix_exp.def}\ne^{tA} = \\sum_{n=0}^{\\infty} \\dfrac{tA^n}{n!} = I + tA + \\frac{t^2A^2}{2!} + ...\n\\end{equation}\n\nWe can apply this technique to the simple harmonic oscillator example, by\nsetting\n\n\\begin{equation}\\label{ode.sho_matrix}\n  y = \\left[\\begin{array}{c}\n        y_1 \\\\\n        y_2 \\\\\n        \\end{array}\\right] \\ \\ \\ \\ \\\n   A = \\left[\\begin{array}{cc}\n\t0 & 1 \\\\\n\t-1 & -\\theta \\\\\n\t\\end{array}\\right]\n\\end{equation}\n\nThe Stan model to simulate noisy observations using a matrix exponential function\nis given by \\reffigure{sho-sim-me}. Note that because we are performing matrix\noperations, we declare \\code{y0} and \\code{y\\_hat} as vectors, instead of using arrays,\nas in the previous example code (\\reffigure{sho-sim}). \\\\\n\nIn general, computing a matrix exponential will be more efficient than using a numerical\nsolver. We can however only apply this technique to systems of \\underline{linear} ODEs.\n%\n\\begin{figure}\n\\begin{stancode}\ndata {\n  int<lower=1> T;\n  vector[2] y0;\n  real ts[T];\n  real theta[1];\n}\nmodel {\n}\ngenerated quantities {\n  vector[2] y_hat[T];\n  matrix[2, 2] A = [[ 0,  1],\n                    [-1, -theta[1]]]\n  for (t in 1:T)\n    y_hat[t] = matrix_exp((t - 1) * A) * y0;\n  // add measurement error\n  for (t in 1:T) {\n    y_hat[t, 1] += normal_rng(0, 0.1);\n    y_hat[t, 2] += normal_rng(0, 0.1);\n  }\n}\n\\end{stancode}\n\\vspace*{-0.2in}\n\\caption{\\small\\it Stan program to simulate noisy measurements from a\n  simple harmonic oscillator.  The system of linear differential equations is\n  coded as a matrix. The system parameters \\code{theta} and initial\n  state \\code{y0} are read in as data along  observation times \\code{ts}.\n  The generated quantities block is used to solve the ODE for the specified\n  times and then add random measurement error, producing observations\n  \\code{y\\_hat}. Because the ODEs are linear, we can use the \\code{matrix\\_exp}\n  function to solve the system. }\\label{sho-sim-me.figure}\n\\end{figure}\n\n\n\\section{Measurement Error Models}\n\nStatistical models or differential equations may be used to estimate\nthe parameters and/or initial state of a dynamic system given noisy\nmeasurements of the system state at a finite number of time points.\n\nFor instance, suppose the simple harmonic oscillator has a parameter\nvalue of $\\theta = 0.15$ and initial state $y(t=0) = (1,0)$.  Now\nsuppose the system is observed at 10 time points, say $t=1, 2, ...,\n10$, where each measurement of $y(t)$ has independent\n$\\distro{Normal}(0, 0.1)$ error in both dimensions ($y_1(t)$ and\n$y_2(t)$).  A plot of such measurements is shown in\n\\reffigure{sho-trajectory}.\n%\n\\begin{figure}\n\\begin{center}\n\\includegraphics[height=2in]{img/sho-ode-trajectory.pdf}%\n\\end{center}\n\\vspace*{-0.25in}\n\\caption{\\small\\it Trajectory of the simple harmonic oscillator given\n  parameter $\\theta=0.15$ and initial condition $y(t=0) = (1,0)$ with\n  additional independent\\ $\\distro{Normal}(0,0.1)$ measurement error\n  in both dimensions.}%\n\\label{sho-trajectory.figure}\n\\end{figure}\n\n\n\n\\subsection{Simulating Noisy Measurements}\n\nThe data used to make this plot is derived from the Stan model to\nsimulate noisy observations given in \\reffigure{sho-sim}.\n%\n\\begin{figure}\n\\begin{stancode}\nfunctions {\n  real[] sho(real t,\n             real[] y,\n             real[] theta,\n             real[] x_r,\n             int[] x_i) {\n    real dydt[2];\n    dydt[1] = y[2];\n    dydt[2] = -y[1] - theta[1] * y[2];\n    return dydt;\n  }\n}\ndata {\n  int<lower=1> T;\n  real y0[2];\n  real t0;\n  real ts[T];\n  real theta[1];\n}\ntransformed data {\n  real x_r[0];\n  int x_i[0];\n}\nmodel {\n}\ngenerated quantities {\n  real y_hat[T,2] = integrate_ode_rk45(sho, y0, t0, ts, theta, x_r, x_i);\n  // add measurement error\n  for (t in 1:T) {\n    y_hat[t, 1] += normal_rng(0, 0.1);\n    y_hat[t, 2] += normal_rng(0, 0.1);\n  }\n}\n\\end{stancode}\n\\vspace*{-0.2in}\n\\caption{\\small\\it Stan program to simulate noisy measurements from a\n  simple harmonic oscillator.  The system of differential equations is\n  coded as a function.  The system parameters \\code{theta} and initial\n  state \\code{y0} are read in as data along with the initial time\n  \\code{t0} and observation times \\code{ts}. The generated quantities\n  block is used to solve the ODE for the specified times and then add\n  random measurement error, producing observations \\code{y\\_hat}.\n  Because the system is not stiff, the \\code{rk45} solver is used.}\\label{sho-sim.figure}\n\\end{figure}\n\nThis program illustrates the way in which the ODE solver is called in\na Stan program,\n%\n\\begin{stancode}\ny_hat = integrate_ode_rk45(sho, y0, t0, ts, theta, x_r, x_i);\n\\end{stancode}\n%\nThis assigns the solutions to the system defined by function\n\\code{sho}, given initial state \\code{y0}, initial time \\code{t0},\nrequested solution times \\code{ts}, parameters \\code{theta}, real data\n\\code{x}, and integer data \\code{x\\_int}.  The call explicitly\nspecifies the Runge-Kutta solver (for non-stiff systems).\n\nHere, the ODE solver is called in the generated quantities block to\nprovide a $10 \\times 2$ array of solutions \\code{y\\_hat} to\nwhich measurement error is added using the normal pseudo-random number\ngenerating function \\code{normal\\_rng}.  The number of rows in the\nsolution array is the same as the size of \\code{ts}, the requested\nsolution times.\n\n\\subsection{Data versus Parameters}\n\nUnlike other functions, the integration functions for ODEs are limited\nas to the origins of variables in their arguments.  In particular, the\ntime \\code{t}, real data \\code{x}, and integer data \\code{x\\_int} must\nbe expressions that only involve data or transformed data variables.\nThe initial state \\code{y} or the parameters \\code{theta} are the only\narguments which may involve parameters.\n\n\n\\subsection{Estimating System Parameters and Initial State}\n\nStan provides statistical inference for unknown initial states and/or\nparameters.  The ODE solver will be used deterministically to produce\npredictions, much like the linear predictor does in a generalized\nlinear model.  These states will then be observed with measurement error.\n\n%\n\\begin{figure}\n\\begin{stancode}\nfunctions {\n  real[] sho(real t,\n             real[] y,\n             real[] theta,\n             real[] x_r,\n             int[] x_i) {\n    real dydt[2];\n    dydt[1] = y[2];\n    dydt[2] = -y[1] - theta[1] * y[2];\n    return dydt;\n  }\n}\ndata {\n  int<lower=1> T;\n  real y[T,2];\n  real t0;\n  real ts[T];\n}\ntransformed data {\n  real x_r[0];\n  int x_i[0];\n}\nparameters {\n  real y0[2];\n  vector<lower=0>[2] sigma;\n  real theta[1];\n}\nmodel {\n  real y_hat[T,2];\n  sigma ~ cauchy(0, 2.5);\n  theta ~ normal(0, 1);\n  y0 ~ normal(0, 1);\n  y_hat = integrate_ode_rk45(sho, y0, t0, ts, theta, x_r, x_i);\n  for (t in 1:T)\n    y[t] ~ normal(y_hat[t], sigma);\n}\n\\end{stancode}\n\\vspace*{-0.2in}\n\\caption{\\small\\it Stan program to estimate unknown initial conditions\n  \\code{y0} and system parameter \\code{theta} for the simple harmonic\n  oscillator with independent normal measurement\n  error.}\\label{sho-both.figure}\n\\end{figure}\n%\nA Stan program that can be used to estimate both the initial state and\nparameter value for the simple harmonic oscillator given noisy\nobservations is given in \\reffigure{sho-both}.  Compared to the\nsimulation model in \\reffigure{sho-sim}, the model to estimate\nparameters uses the \\code{integrate\\_ode} function in the model block\nrather than the generated quantities block.  There are Cauchy priors on the\nmeasurement error scales \\code{sigma} and unit normal priors on the\ncomponents of parameter array \\code{theta} and initial state parameter\narray \\code{y0}.  The solutions to the ODE are then assigned to an\narray \\code{y\\_hat}, which is then used as the location in the\nobservation noise model as follows.\n%\n\\begin{stancode}\ny_hat = integrate_ode_rk45(sho, y0, t0, ts, theta, x_r, x_i);\nfor (t in 1:T)\n  y[t] ~ normal(y_hat[t], sigma);\n\\end{stancode}\n%\nAs with other regression-like models, it's easy to change the noise\nmodel to be robust (e.g., Student-t distributed), to be correlated in\nthe state variables (e.g., with a multivariate normal distribution),\nor both (e.g., with a multivariate Student-t distribution).\n\nIn this simple model with independent noise scales of 0.10, 10\nobserved data points for times $t = 1, ..., 10$ is sufficient to\nreliably estimate the ODE parameter, initial state, and noise scales.\n\n\n\\section{Stiff ODEs}\\label{stiff-ode.section}\n\nA stiff system of ordinary differential equations can be roughly\ncharacterized as systems presenting numerical difficulties for\ngradient-based stepwise solvers.  Stiffness typically arises due to\nvarying curvature in the dimensions of the state, for instance one\ncomponent evolving orders of magnitude more slowly than another.%\n%\n\\footnote{Not coincidentally, high curvature in the posterior of a\n  general Stan model poses the same kind of problem for Euclidean\n  Hamiltonian Monte Carlo (HMC) sampling.  The reason is that HMC is\n  based on the leapfrog algorithm, a gradient-based, stepwise\n  numerical differential equation solver specialized for Hamiltonian\n  systems with separable potential and kinetic energy terms.}\n%\n\nStan provides a specialized solver for stiff ODEs\n\\citep{CohenHindmarsh:1996,SerbanHindmarsh:2005}.  An ODE system is\nspecified exactly the same way with a function of exactly the same\nsignature.  The only difference is in the call to the integrator for\nthe solution; the \\code{rk45} suffix is replaced with \\code{bdf}, as in\n%\n\\begin{stancode}\ny_hat = integrate_ode_bdf(sho, y0, t0, ts, theta, x_r, x_i);\n\\end{stancode}\n%\n\nUsing the stiff (\\code{bdf}) integrator on a system that is not stiff\nmay be much slower than using the non-stiff (\\code{rk45}) integrator;\nthis is because it computes additional Jacobians to guide the\nintegrator.  On the other hand, attempting to use the non-stiff\nintegrator for a stiff system will fail due to requiring a small step\nsize and too many steps.\n\n\\section{Control Parameters for ODE Solving}\n\nThe calls to the integrators shown above just used the default\ncontrol settings.  Both the non-stiff and stiff integrators allow\nthree additional arguments, all of which must be supplied if any of\nthem is required.\n%\n\\begin{stancode}\ny_hat = integrate_ode_bdf(sho, y0, t0, ts, theta, x_r, x_i,\n                          rel_tol, abs_tol, max_steps);\n\\end{stancode}\n%\nThe three control arguments are relative tolerance, absolute\ntolerance, and maximum number of steps.   The default values for\nrelative and absolute tolerance are both \\code{1e-6} ($10^{-6}$), and\nthe default maximum number of steps is \\code{1e6} ($10^6$).\n\n\\subsection{Tolerance}\n\nThe relative and absolute tolerance control the accuracy of the\nsolutions generated by the integrator.  Relative tolerances are\nrelative to the solution value, whereas absolute tolerances is the\nmaximum absolute error allowed in a solution.\n\nSmaller tolerances produce more accurate solutions.  Smaller\ntolerances also require more computation time.\n\n\\subsubsection{Sensitivity Analysis}\n\nThe tolerances should be set low enough that setting them lower does\nnot change the statistical properties of posterior samples generated\nby the Stan program.\n\n\\subsection{Maximum Number of Steps}\n\nThe maximum number of steps can be used to stop a runaway simulation.\nThis can arise in MCMC when a bad jump is taken, particularly during\nwarmup.  With the non-stiff solver, this may result in jumping into a\nstiff region of the parameter space, which would require a very small\nstep size and very many steps to satisfy even modest tolerances.\n", "meta": {"hexsha": "e8eee2823f64712edfa5f6ecae5215b0c4c518f6", "size": 304265, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/docs/stan-reference/examples.tex", "max_stars_repo_name": "rleonid/stan", "max_stars_repo_head_hexsha": "85cce4c4d702f739a1e5bf2aaa23de80cd50f89e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/docs/stan-reference/examples.tex", "max_issues_repo_name": "rleonid/stan", "max_issues_repo_head_hexsha": "85cce4c4d702f739a1e5bf2aaa23de80cd50f89e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/docs/stan-reference/examples.tex", "max_forks_repo_name": "rleonid/stan", "max_forks_repo_head_hexsha": "85cce4c4d702f739a1e5bf2aaa23de80cd50f89e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.9971244536, "max_line_length": 311, "alphanum_fraction": 0.7271753241, "num_tokens": 83948, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677545357568, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7029133835233239}}
{"text": "\\documentclass[./\\jobname.tex]{subfiles}\n\\begin{document}\n\t\n\\section{Universial Approximation Theorem for GSK}\n\\label{chap:gsin_approximation_theorem}\n\nThe Gauss kernel is able to approximate all functions that are part of the Lebesgue space $f(\\mathbf{x}) \\in L^1(\\mathbb{R}^n)$ arbitrarily close. This has been proven by various works (\\cite{park_universal_1991}, \\cite{hangelbroek_nonlinear_2010}). In particular, \\cite{park_universal_1991} extends the universal approximation theorem to other kernels. The following paragraphs show that the \\gls{gsk} fulfils the posed conditions and thus can benefit from the approximation theorem.  \n\n\\begin{equation}\n\\label{eq:gsin_kernel_theoretical_notes}\ngsk(\\mathbf{x}) = \\omega e^{-\\gamma ||\\mathbf{x} - \\mathbf{c}||^2} sin(f ||\\mathbf{x} - \\mathbf{c}||^2 - \\varphi)\n\\end{equation}\n\nTo prove that the universal approximation theorem is also applicable to the \\gls{gsk}, it must comply with the conditions placed by \\cite{park_universal_1991}. At first, a kernel, in this case the $gsk(\\mathbf{x})$, must be continuous and bounded. This already restricts $\\gamma > 0$. However, \\cite{chaquet_using_2019} found that not placing any limits on the parameters results in a better performance. Thus, this constraint is not implemented in the current version of the algorithm. Secondly, the integral over the whole domain of the kernel $K(\\mathbf{x})$ must not be $0$. Thus, it needs to be shown that \n\n\\begin{equation}\n\\int_{\\mathbf{x} = -\\mathbf{\\infty}}^{\\infty} gsk(\\mathbf{x}) \\text{ } d\\mathbf{x} \\neq 0\n\\end{equation} \n\nIntuitively, the next restriction on $\\omega \\neq 0$ is found. \n\nTo simplify the following calculations, the \\gls{gsk} is rewritten into polar coordinates. Further, the offsets by $c_0$ and $c_1$ are accounted for by an appropriate coordinate transformation. This results in \n\n\\begin{equation}\n\\lim_{t \\to \\infty} \\int_{r=0}^{t} \\int_{\\theta = 0}^{2 \\pi} e^{-\\gamma(r^2)} sin(f r^2 - \\varphi) r \\text{ } dr \\text{ } d\\theta\n\\end{equation}\n\nSince the kernel is radial symmetric and thus has no dependency on $\\theta$, the respective integral can be solved immediately which results in a multiplicative factor of $2 \\pi$. The integral can be further simplified by substituting $r^2 = u$.\nThe resulting expression can be solved with ``integration by part'' $\\int f(u) \\frac{g(u)}{du} = f(u) g(u) - \\int g(u) \\frac{f(u)}{du}$. The formula has to be applied twice. The same integral is retrieved. Thus, the equation can be rearranged and solved for the integral. Considering the constant factors and the integral limits gives \n\n\\begin{equation}\n\\lim_{t \\to \\infty} \\frac{\\pi e^{-\\gamma r^2}(- \\gamma sin(f r^2 - \\varphi) - f cos(f r^2 - \\varphi))}{ \\gamma^2 + f^2} + C \\text{ } \\Bigg|_{r=0}^{t}.\n\\end{equation}\n\nTo resolve the limit of the function towards $\\infty$, the function value must be bounded. Therefore, $\\gamma$ must be positive, which is already required. Finally, this results in \n\n\\begin{equation}\n\t\\frac{-\\pi (\\gamma sin(\\varphi) + f cos(\\varphi))}{\\gamma^2 + f^2} \\neq 0.\n\\end{equation}\n\nThis places more constraints on the parameter of the \\gls{gsk} as seen in the equation \\eqref{eq:gsk_param_restrictions} below. \n\n\\begin{equation}\n\\label{eq:gsk_param_restrictions}\n\t\\begin{split}\n\t\\gamma & > 0 \\\\\n\t\\omega & \\neq 0 \\\\\n\t\\gamma & sin(\\varphi) + f cos(\\varphi) \\neq 0 \\\\\n\t\\end{split}\n\\end{equation}\n\nThese restrictions on the parameters could be enforced during the optimisation process. They could further be used to limit the search dimension. Thus, other optimisation algorithms that are good at handling constraints must be used. \n\n\n\n\\end{document}", "meta": {"hexsha": "c3f0adb1231140d46773c2edda0011943eb1fed5", "size": 3628, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "master_thesis_paper/tex/UAT_Gauss_Sine_Kernel.tex", "max_stars_repo_name": "nicolai-schwartze/Masterthesis", "max_stars_repo_head_hexsha": "7857af20c6b233901ab3cedc325bd64704111e16", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-13T10:02:02.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-13T10:02:02.000Z", "max_issues_repo_path": "master_thesis_paper/tex/UAT_Gauss_Sine_Kernel.tex", "max_issues_repo_name": "nicolai-schwartze/Masterthesis", "max_issues_repo_head_hexsha": "7857af20c6b233901ab3cedc325bd64704111e16", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "master_thesis_paper/tex/UAT_Gauss_Sine_Kernel.tex", "max_forks_repo_name": "nicolai-schwartze/Masterthesis", "max_forks_repo_head_hexsha": "7857af20c6b233901ab3cedc325bd64704111e16", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.7857142857, "max_line_length": 611, "alphanum_fraction": 0.7342888644, "num_tokens": 1067, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677545357568, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7029133781481234}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Hold Power Steady}\n\\subsubsection{Vary Root}\n\\begin{align*}\n\\tripow{m}{}{x} \\pplus \\tripow{n}{}{x} &= \\tripow{m\\cdot{}n}{}{x} & \\quad\n\t\\log_m{x} \\pplus \\log_n{x} & = \\log_{m\\cdot{}n}{x} \\\\\n\\tripow{m}{}{x} \\pminus \\tripow{n}{}{x} &= \\tripow{m \\div n}{}{x} & \\quad\n\t\\log_m{x} \\pminus \\log_n{x} & = \\log_{m \\div n}{x} \\\\\n\\tripow{\\tripow{m}{n}{}}{}{x} &= \\frac{1}{n} \\tripow{m}{}{x} & \\quad\n\t\\log_{m^n}{x} &= \\frac{1}{n}\\log_m{x}\\\\\n\\end{align*}\n\n\n\\subsubsection{Vary Exponent}\n\\begin{align*}\n\\tripow{}{m}{x} \\cdot \\tripow{}{n}{x} &= \\tripow{}{m\\pplus{}n}{x} & \\quad\n\t\\sqrt[m]{x} \\cdot \\sqrt[n]{x} &= \\sqrt[m\\pplus{}n]{x} \\\\\n\\tripow{}{m}{x} \\div \\tripow{}{n}{x} &= \\tripow{}{m\\pminus{}n}{x} & \\quad\n\t\\sqrt[m]{x} \\div \\sqrt[n]{x} &= \\sqrt[m\\pminus{}n]{x} \\\\\n\\tripow{}{m\\cdot{}n}{x} &= \\tripow{}{n}{\\tripow{}{m}{x}} & \\quad\n\t\\sqrt[m\\cdot{}n]{x} &= \\sqrt[n]{\\sqrt[m]{x}} \\\\\n\\end{align*}\n\n\\subsection{Hold Exponent Steady}\n\\subsubsection{Vary Power}\n\\begin{align*}\n\\tripow{}{x}{m} \\cdot \\tripow{}{x}{n} &= \\tripow{}{x}{m\\cdot{}n} & \\quad\n\t\\sqrt[x]{m} \\cdot \\sqrt[x]{n} &= \\sqrt[x]{m\\cdot{}n} \\\\\n\\tripow{}{x}{m} \\div \\tripow{}{x}{n} &= \\tripow{}{x}{m\\div{}n} & \\quad\n\t\\sqrt[x]{m} \\div \\sqrt[x]{n} &= \\sqrt[x]{m\\div{}n} \\\\\n\\tripow{}{x}{\\tripow{m}{n}{}} & = \\tripow{\\tripow{}{x}{m}}{n}{} & \\quad\n\t\\sqrt[x]{m^n} &= \\sqrt[x]{m}^n\\\\\n\\end{align*}\n\n\\subsubsection{Vary Root}\n\\begin{align*}\n\\tripow{m}{x}{} \\cdot \\tripow{n}{x}{} &= \\tripow{m\\cdot{}n}{x}{} & \\quad\n\tm^x \\cdot n^x &= (m\\cdot{}n)^x \\\\\n\\tripow{m}{x}{} \\div \\tripow{n}{x}{} &= \\tripow{m\\div{}n}{x}{} & \\quad\n\tm^x \\div n^x &= (m\\div{}n)^x \\\\\n\\tripow{\\tripow{m}{n}{}}{x}{} &= \\tripow{m}{x\\cdot{}n}{} & \\quad\n\t(m^n)^x &= m^{x\\cdot{}n} \\\\\n\\end{align*}\n\n\\subsection{Hold Root Steady}\n\\subsubsection{Vary Exponent}\n\\begin{align*}\n\\tripow{x}{m}{} \\cdot \\tripow{x}{n}{} &= \\tripow{x}{m+n}{} & \\quad\n\tx^m \\cdot x^n = x^{m+n}\\\\\n\\tripow{x}{m}{} \\div \\tripow{x}{n}{} &= \\tripow{x}{m-n}{} & \\quad\n\tx^m \\div x^n = x^{m-n}\\\\\n\\tripow{\\tripow{x}{m}{}}{n}{} &= \\tripow{x}{m\\cdot{}n}{} & \\quad\n\t(x^m)^n &= x^{m\\cdot{}n} \\\\\n\\end{align*}\n\n\\subsubsection{Vary Power}\n\\begin{align*}\n\\tripow{x}{}{m} + \\tripow{x}{}{n} &= \\tripow{x}{}{m\\cdot{}n} & \\quad\n\t\\log_x{m} + \\log_x{n} &= \\log_x{(m\\cdot{}n)}\\\\\n\\tripow{x}{}{m} - \\tripow{x}{}{n} &= \\tripow{x}{}{m\\div{}n} & \\quad\n\t\\log_x{m} - \\log_x{n} &= \\log_x{(m\\div{}n)}\\\\\n\\tripow{x}{}{\\tripow{m}{n}{}} &= n \\cdot \\tripow{x}{}{n} & \\quad\n\t\\log_x{(m^n)} &= n\\cdot{}\\log_x{m}\\\\\n\\end{align*}\n\n\n\\subsection{Inverse Operations}\n$$\n\\tripow{}{\\tripow{x}{}{b}}{b} =\n\\tripow{b}{\\tripow{b}{}{x}}{} = \n\\tripow{b}{}{\\tripow{b}{x}{}} =\n\\tripow{}{b}{\\tripow{x}{b}{}} =\n\\tripow{\\tripow{}{b}{x}}{b}{} =\n\\tripow{\\tripow{}{x}{b}}{}{b} =\nx\n$$\n\n$$\n\\sqrt[\\log_x{b}]{b} =\nb^{\\log_b{x}} =\n\\log_b{b^x} =\n\\sqrt[b]{x^b} =\n(\\sqrt[b]{x})^b =\n\\log_{\\sqrt[x]{b}}{b} =\nx\n$$\n", "meta": {"hexsha": "4af5e9a059ca4d65c068bd6f52e289509293a13b", "size": 2845, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch07/0706.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch07/0706.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch07/0706.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3295454545, "max_line_length": 73, "alphanum_fraction": 0.5188049209, "num_tokens": 1387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145053, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.702839139496856}}
{"text": "\\chapter{Introduction to Discrete Probability}\n\nFirst, let's take care of the word \\emph{discrete} vs \\emph{discreet}.\nThey sound exactly same, but ``discrete'' means ``individually\nseparate and distinct'' and ``discreet'' means ``careful about what\nother people know''.  So you might say, ``You can think of light as a\ncontinuous wave or as a blast of discrete particles.'' And you might\nsay, ``Please go get the box of doughnuts from the kitchen. Oh, and\nthere are a lot of hungry people in the house, so be\ndiscreet.''\\index{discrete vs. discreet}\n\nWhen we are talking about probabilities, there are problems that deal\nwith discrete quantities like ``What is the probability that I will\nthrow these three dice and the numbers that come up sum to 9?''. There\nare also problems that deal with continuous properties like ``What is\nthe probability that the next bird to fly over my house will weigh\nbetween 97.2 and 98.1 grams ?'' In this module, we are going to focus\non the probability problems that deal with discrete quantities.\n\nWatch Khan Academy's Introduction to Probability at \\url{https://youtu.be/uzkc-qNVoOk}.\n\nLet's say that I have a cloth sac filled with 100 marbles; 99 are red\nand 1 is white. If I ask you to reach in without looking and pull out\none marble, you will probably pull out a red one. We say that ``There\nis a 1 in 100 chance that you would pull out a white marble.'' Or we\ncan use percentages and say ``There is a 1\\% chance that you will pull\nout a white marble.'' Or we can use decimals and say ``There is a 0.01\nprobability that you will pull out a white marble.''\n\nIn probability, we often talk about the probability of certain\nevents. ``Pulling out a white marble'' is an event, and we can give it\na symbol like $W$. Then, in equations we use $p$ to mean ``the\nprobability of''.  Thus, we can say ``There is a 0.01 probability that\nyou will pull out a white marble'' becomes the equation\n\\begin{equation*}\n  p(W) = 0.01\n\\end{equation*}\\index{probability}\n% ADD: Make sure functions come before this chapter, connect to functions\n\n\\section{The Probability of All Possibilities is 1.0}\n\nWe know that you are either going to pull out a red marble or a white marble,\nso the probability of a white marble being pulled and the probability\nof a red marble being pulled must add up to be 100\\%. Therefore, the odds of\npulling out a red marble must be 99\\% or 0.99. If we let the event ``Pull out a red marble'' be given by the symbol $R$, we can say:\n\\begin{equation*}\n  p(R) = 1.0 - P(W) = 1.0 - 0.01 = 0.99\n\\end{equation*}\n\nNow, let's say that I make you take a marble from the bag and then\ntoss a coin. What is the probability that you will pull a white marble\nand then get heads on the coin? It is the product of the two\nprobabilities: $0.01 \\times 0.5 = 0.005$, so one half of a one percent\nchance. Do the probabilities still sum to 1?\n\\begin{itemize}\n\\item White and Heads = $0.01 \\times 0.5 = 0.005$\n\\item White and Tails = $0.01 \\times 0.5 = 0.005$\n\\item Red and Heads = $0.99 \\times 0.5 = 0.495$\n\\item Red and Tails = $0.99 \\times 0.5 = 0.495$\n% ADD: add up the values at the end for clarity\n\\end{itemize}\nYes, the probabilitites of all the possibilities still add to 1.\n\n\\section{Independence}\n\nIn the last section, I told you that the probability of two events\n(``Pulling a red marble from the bag'' and ``Getting tails in a coin\ntoss'') is the product of the probability of each event: $0.99 \\times 0.5 = 0.495$.\n\nThis is true if the two events are \\textit{independent}, that is the\noutcome of one doesn't change the probabilty of the other.  The\nexample I gave is independent: It doesn't matter what ball you pull\nfrom the bag, the outcome of the coin toss will always be 50-50.\\index{independent}\n\nWhat are two events that are not independent? The probability that a\nperson is a professional basketball player and the probability that\nsomeone wears a shoe that is size 13 or larger are \\textit{not}\nindependent. After all, height is an advantage in basketball and most\ntall people also have large feet. So if you know someone is a\nbasketball player, it is very likely that they wear a large shoe.\n% ADD: Correlation for Causeation \n% Weird Correlations Website: https://www.tylervigen.com/spurious-correlations\n% KA: https://youtu.be/R-NeYKSEqns\n\n\\begin{Exercise}[title={Rolling Dice}, label=rolling-dice]\n  If I give you three dice to roll, what is the\n  probability that you will roll a 5 on all three dice?\n\\end{Exercise}\n\\begin{Answer}[ref=rolling-dice]\n  probability of all 5's $ = \\frac{1}{6}\\times\\frac{1}{6}\\times\\frac{1}{6} = \\left(\\frac{1}{6}\\right)^3 = \\frac{1}{216} \\approx 0.0046$\n  \\end{Answer}\n    \n\\begin{Exercise}[title={Flipping Coins}, label=flipping-coins]\n  If I give you five coins to flip, what is the\n  probability that at least one coin will come up heads?\n\\end{Exercise}\n\\begin{Answer}[ref=rolling-dice]\n  probability of at least one heads = 1.0 - probability of all tails $ = 1.0 - \\left(\\frac{1}{2}\\right)^5 =1.0 - \\frac{1}{32} = \\frac{31}{32} = \\approx 0.97$ \n  \\end{Answer}\n    \n\\section{Why 7 is the mostly likely sum of two dice}\n\nIf you roll two dice, the sum will can be 2 or 12 or any number in\nbetween. It is very tempting to assume that the likelihood of any of\nthose numbers is the same. In fact, the probability of a 2 is\n$\\frac{1}{36} \\approx 3\\%$ and the probability of a 7 is $\\frac{1}{6}\n\\approx 17\\%$. A 7 is six times more likely than a 12! Why?\n\nWhen you roll the first die, there are six possibilities with equal\nprobability. When you roll the second die, there are six possibilities\nwith equal probability. so there are a total of 36 possible events\nwith equal probabilities: 1 then 1, 1 then 2, 2 then 1, 1 then 3, 3\nthen 1, etc. Only one of these (1 then 1) adds to 2.  But six of these\nsum to 7: 1 then 6, 6 then 1, 2 then 5, 5 then 2, 3 then 4, 4 then\n3. So a 7 is six times more likely than a 2.\n\nHere is the complete table:\n\n\\begin{tabular}{c| c c c c c c | c | c}\n  Sum &     &     &     &     &     &     & Count & Probability \\\\\n  \\hline\n  2   & 1,1 &     &     &     &     &     &   1    & 1/36 \\\\\n  3   & 1,2 & 2,1 &     &     &     &     &   2    & 1/18 \\\\\n  4   & 1,3 & 2,2 & 3,1 &     &     &     &   3    & 1/12 \\\\\n  5   & 1,4 & 2,3 & 3,2 & 4,1 &     &     &   4    & 1/9 \\\\\n  6   & 1,5 & 2,4 & 3,3 & 4,2 & 5,1 &     &   5    & 5/36 \\\\\n  7   & 1,6 & 2,5 & 3,4 & 4,3 & 5,2 & 6,1 &   6    & 1/6 \\\\\n  8   &     & 2,6 & 3,5 & 4,4 & 5,3 & 6,2 &   5    & 5/36 \\\\\n  9   &     &     & 3,6 & 4,5 & 5,4 & 6,3 &   4    & 1/9 \\\\\n  10  &     &     &     & 4,6 & 5,5 & 6,4 &   3    & 1/22 \\\\\n  11  &     &     &     &     & 5,6 & 6,5 &   2    & 1/18 \\\\\n  12  &     &     &     &     &     & 6,6 &   1    & 1/36\n\\end{tabular}\n\nWhen I bumped into this, I was skeptical. I decided to test it, so I\nrolled a pair of dice hundreds of times and made a histogram. It was a\ntedious and time-consuming task -- just the sort of thing that we make\ncomputers do for us.\n% ADD: Define Histogram\n\n\\section{Random Numbers and Python}\n\nYou are going to write a simulation of rolling dice in Python. To do\nthis, you will need to generate a random sequence of numbers. The\nnumbers will need to be in the range 1 to 6, and they will need to\nappear in the sequence with the same frequency.  We say the sequence\nwill follow \\textit{the uniform distribution}.  That is, the\nprobability is uniformly distributed among the 6 possibilities.\\index{random number generation}\n\nStart python and try a few of the different ways to generate random numbers:\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n> \\textbf{python3}\n>>> \\textbf{import random}\n>>> \\textbf{random.random()}  # Generates a random floating point number between 0 and 1\n0.6840892758539989\n>>> \\textbf{randrange(5)}      # Generates an integer in the range 0 - 4\n2\n>>> \\textbf{x = ['Rock', 'Paper', 'Scissors']}\n>>> \\textbf{random.choice(x)}   # Pick a random entry from the sequence\n'Paper'\n>>> \\textbf{x}\n['Rock', 'Paper', 'Scissors'] \n>>> \\textbf{random.shuffle(x)}   # Shuffle the order of the sequence\n>>> \\textbf{x}\n['Scissors', 'Paper', 'Rock']\n>>> \\textbf{a = list(range(30))}\n>>> \\textbf{a}\n[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,\n  16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 29]\n>>> \\textbf{random.sample(a, 10)} # Return 10 randomly chosen items from the sequence\n[8, 7, 20, 9, 25, 13, 23, 11, 14, 16]\n\\end{Verbatim}\n% KA: https://www.youtube.com/watch?v=Jua-KWBdzfU\nClearly Python has a lot of ways to do things that look random. I\nshould be honest with you at this point: they aren't really\nrandom. The computer that you are using can't generate random\ndata. Instead, it uses tricks to create data that looks random; we\ncall this \\textit{pseudorandom} data. Good pseudorandom algorithms are\nvery important for cryptography and data security.\n\nWhat if you want real random data? There are companies that are using\nthe decay of radioactive materials to generate real random data. You\ncan pay to download it. For our purposes, Python's pseudorandom\nnumbers are quite sufficient.\n\nIf we generate two random numbers in the range 1 through 6 and add them together, we\nwill have simulated rolling a pair of dice. Like this:\n\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n>>> \\textbf{a = random.randrange(6) + 1}\n>>> \\textbf{b = random.randrange(6) + 1}\n>>> \\textbf{a + b}\n8\n\\end{Verbatim}\n\nFirst, let's write a program that just rolls the dice 100 times and shows the result. Make a file \\url{dice.py}:\n\\begin{Verbatim}\nimport random\n\nroll_count = 100\n\nfor i in range(roll_count):\n    a = random.randrange(6) + 1\n    b = random.randrange(6) + 1\n    roll = a + b\n    print(f\"Toss {i}: {a} + {b} = {roll}\")\n\\end{Verbatim}\n\nWhen you run it, you should see something like:\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n> \\textbf{python3 dice.py}\nToss 0: 6 + 6 = 12\nToss 1: 4 + 4 = 8\nToss 2: 4 + 2 = 6\nToss 3: 4 + 6 = 10\nToss 4: 4 + 4 = 8\n...\nToss 98: 5 + 2 = 7\nToss 99: 5 + 2 = 7\n\\end{Verbatim}\n\nNow we want to count occurences of each possible outcome. Let's use an\narray of integers. We will start with an array of zeros. And, for\nexample, when we roll a 3, we'll add 1 to item 3 in the array. (We can\nnever roll a zero or a one, so those two entries will always be zero.)\n% ADD: Define Array\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\nimport random\n\nroll_count = 100\n\n\\textbf{# Make an array containing 13 zeros}\n\\textbf{counts = [0] * 13}\n\nfor i in range(roll_count):\n    a = random.randrange(6) + 1\n    b = random.randrange(6) + 1\n    roll = a + b\n    print(f\"Toss {i}: {a} + {b} = {roll}\")\n\n    \\textbf{# Increment the count for roll}\n    \\textbf{counts[roll] += 1}\n\n\\textbf{print(f\"Counts: {counts}\")}\n\\end{Verbatim}\n\nWhen you run this, at the end you will see a count for each possible outcome :\n\n\\begin{Verbatim}\n...\nToss 98: 3 + 2 = 5\nToss 99: 6 + 1 = 7\nCounts: [0, 0, 2, 6, 16, 11, 13, 14, 11, 11, 6, 9, 1]\n\\end{Verbatim}\n\nWhat was the count that we expected? For example, we expected to see a\n2 about once every 36 rolls, right? It might be nice to compare our\ncount to what we expected. Add a few more lines, and we are going to\nincrease the number of rolls. You will probably want to delete the\nline that prints each roll separately:\n\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\nimport random\n\n\\textbf{# Can't ever be 0 or 1}\n\\textbf{p = [0.0, 0.0, 1/36, 1/18, 1/12, 1/9, 5/36, 1/6, 5/36, 1/9, 1/12, 1/18, 1/36]}\nroll_count = 1000\n\n# Make an array containing 13 zeros\ncounts = [0] * 13\n\nfor i in range(roll_count):\n    a = random.randrange(6) + 1\n    b = random.randrange(6) + 1\n    roll = a + b\n\n    # Increment the count for roll\n    counts[roll] += 1\n\n\\textbf{for i in range(2,13):}\n    \\textbf{print(f\"{i} appeared {counts[i]} times, expected {p[i] * roll_count:.1f}\")}\n\\end{Verbatim}\n\nNow you should see something like:\n\\begin{Verbatim}\n2 appeared 39 times, expected 27.8\n3 appeared 55 times, expected 55.6\n4 appeared 84 times, expected 83.3\n5 appeared 110 times, expected 111.1\n6 appeared 160 times, expected 138.9\n7 appeared 176 times, expected 166.7\n8 appeared 124 times, expected 138.9\n9 appeared 93 times, expected 111.1\n10 appeared 87 times, expected 83.3\n11 appeared 49 times, expected 55.6\n12 appeared 23 times, expected 27.8\n\\end{Verbatim}\n\nWhenever you are dealing with random numbers, the outcome will seldom\nbe \\textit{exactly} what you expected. In this case, however, you should see that you\npredictions are pretty close.\n\n\\subsection{Making a bar graph}\n\n\n\nA bar graph is a nice way to look at quantities like this.  Let's make a bar graph that shows the actual count and the expected count:\\index{bar graph!in python}\n\n\\includegraphics[width= 0.85\\textwidth]{dice1.png}\n\nWe need to describe the set of rectangles, to do this we will loop through each possible roll (2 - 12) and put data in four lists for each:\n% ADD: Define lists\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\nimport random\n\\textbf{import matplotlib.pyplot as plt}\n\n# Can't ever be 0 or 1\np = [0.0, 0.0, 1/36, 1/18, 1/12, 1/9, 5/36, 1/6, 5/36, 1/9, 1/12, 1/18, 1/36]\nroll_count = 1000\n\n# Make an array containing 13 zeros\ncounts = [0] * 13\n\nfor i in range(roll_count):\n    a = random.randrange(6) + 1\n    b = random.randrange(6) + 1\n    roll = a + b\n\n    # Increment the count for roll\n    counts[roll] += 1\n\n\\textbf{# Gather data for bar chart}\n\\textbf{bar_width = 0.35}\n\\textbf{expected = []}\n\\textbf{actual_starts = []}\n\\textbf{expected_starts = []}\n\\textbf{labels = []}\n\\textbf{actual = []}\nfor i in range(2,13):\n    \\textbf{expected.append(p[i] * roll_count)}\n    \\textbf{actual.append(counts[i])}      \n    \\textbf{actual_starts.append(i - bar_width/2)}\n    \\textbf{expected_starts.append(i + bar_width/2)}\n    \\textbf{labels.append(i)}\n    \n\\textbf{fig, ax = plt.subplots()}\n    \n\\textbf{# Create the bars}\n\\textbf{ax.bar(actual_starts, actual, bar_width, label='Actual')}\n\\textbf{ax.bar(expected_starts, expected, bar_width, label='Expected')}\n\\textbf{ax.set_xticks(labels)}\n\n\\textbf{# Provide labels}\n\\textbf{ax.set_ylabel('Occurences')}\n\\textbf{ax.set_title('Dice Rolls')}\n\\textbf{ax.legend()}\n\\textbf{plt.show()}\n\\end{Verbatim}\n\n% ADD: For extra guideance: https://pythoniseasytolearn.blogspot.com/2019/09/rolling-two-dice.html", "meta": {"hexsha": "b317a57e6fc3314d5e6f031ab273242ed9d68fa7", "size": 14151, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/DiscreteProbability/intro-en_US.tex", "max_stars_repo_name": "hillegass/sequence", "max_stars_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/DiscreteProbability/intro-en_US.tex", "max_issues_repo_name": "hillegass/sequence", "max_issues_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/DiscreteProbability/intro-en_US.tex", "max_forks_repo_name": "hillegass/sequence", "max_forks_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 39.3083333333, "max_line_length": 161, "alphanum_fraction": 0.6861705887, "num_tokens": 4612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8596637433190939, "lm_q1q2_score": 0.7028391346467752}}
{"text": "%\\input{../macros.tex}\n%\\begin{document}\n\\begin{answer}\nFor the semi supervised M-step we maximise over $\\theta = \\phi, \\mu, \\Sigma$ while keeping $Q$ fixed the expression $ELBO(Q, \\theta) + l_{\\text{sup}}(\\theta) = \\sum_{i=1}^n \\sum_{j=1}^k Q_i(z_i)_j \\log \\frac{p(x_i,z_i; \\phi, \\mu, \\Sigma)}{Q_i(z_i)_j} + \\alpha \\sum_{i=1}^{\\tilde{n}} \\log p(x_i, z_i; \\phi, \\mu, \\Sigma)$\n\\linebreak\nSo having pre-computed in E-step the fixed $Q_i(z_i)_j = w^i_j$, we can differentiate in turn for each of $\\phi, \\mu, \\Sigma$. Rewriting the whole expression to be maximised as\n\\begin{equation*}\n\\sum_{i=1}^n \\sum_{j=1}^k w^i_j \\log \\frac{\\phi_j \\; N(x_i ; \\mu_j, \\Sigma_j)}{w^i_j} + \\alpha \\sum_{i=1}^{\\tilde{n}} \\log  \\left ( \\phi_{\\tilde{z}_i} \\; N(\\tilde{x_i} | \\tilde{z_i}; \\mu, \\Sigma) \\right )\n\\end{equation*}\n\\subsection*{mu}\nWe get\n\\begin{align*}\n\\frac{\\partial}{\\partial \\mu_l} &=\n\\sum_{i=1}^n w^i_l \\frac{\\partial}{\\partial \\mu_l} \\log  N(x_i ; \\mu_j, \\Sigma_j) +\n\\alpha \\sum_{i=1}^{\\tilde{n}} \\frac{\\partial}{\\partial \\mu_l} \\log N(\\tilde{x}_i | \\tilde{z_i}; \\mu, \\Sigma)\n\\\\\n&= \\sum_{i=1}^n w^i_l \\Sigma_l^{-1} (x_i - \\mu_l) + \n\\alpha \\sum_{\\tilde{z}_i = l} \\Sigma_l^{-1} (\\tilde{x}_i - \\mu_l)\n\\end{align*}\nSetting this to $0$ we get\n\\begin{align*}\n\\mu_l =\n\\frac{\n\t\\sum_{i=1}^n w^i_l x_i + \\alpha \\sum_{\\tilde{z}_i = l} \\tilde{x}_i\n}\n{\n\t\\sum_{i=1}^n w^i_l + \\alpha \\#\\{\\tilde{z}_i = l\\}\n}\n\\end{align*}\n\\subsection*{phi}\nSimilarly for $\\phi$ we have\n\\begin{align*}\n\\frac{\\partial}{\\partial \\phi_l} = \\sum_{i=1}^n w^i_l (1/\\phi_l) + \\alpha \\sum_{\\tilde{z}_i = l} (1/\\phi_l) = (1/\\phi_l) \\sum_{i=1}^n w^i_l + \\alpha \\#\\{\\tilde{z}_i = l\\}\n\\end{align*}\nwith constraint that $\\sum_l \\phi_l = 1$, so we apply the Lagrangian multipliers method:\n\\begin{align*}\n\\mathcal{L}(\\phi, \\lambda) = \\sum_{l=1}^k \\sum_{i=1}^n w^i_l \\log \\phi_l + \\alpha \\#\\{\\tilde{z}_i = l\\} \\phi_l \\;+\\; \\lambda( \\sum_l \\phi_l - 1)\n\\\\\n\\frac{\\partial \\mathcal{L}}{\\partial \\phi_l} = (1/\\phi_l) \\sum_{i=1}^n w^i_l + \\alpha \\#\\{\\tilde{z}_i = l\\} \\;+\\; \\lambda = 0\n\\\\\n\\text{this applies for each $l=1,...,k$, with $\\lambda$ constant, so we surmise that}\n\\\\\n\\phi_l = C \\sum_{i=1}^n w^i_l + \\alpha \\#\\{\\tilde{z}_i = l\\} \\quad \\text{for some constant $C$, again constant across each $l$}\n\\\\\n\\text{so applying constraint $\\sum_l \\phi_l = 1$ we get} \\quad\n\\phi_l = \\frac{\\sum_{i=1}^n w^i_l + \\alpha \\#\\{\\tilde{z}_i = l\\}}\n{n + \\alpha \\tilde{n}}\n\\end{align*}\n\n\n\\subsection*{Sigma}\nI cannot be bothered to write this all out again, you get the pattern, so we end up with \n\\begin{align*}\n\\Sigma_l = \n\\frac{\n\t\t\\sum_{i=1}^n w^i_l (x_i - \\mu_l)(x_i - \\mu_l)^T \\;+\\;\n\t\t\\alpha  \\sum_{\\tilde{z}_i = l} (\\tilde{x}_i - \\mu_l)(\\tilde{x_i} -  \\mu_l)^T\n\t}\n\t{\n\t\t\\sum_{i=1}^n w^i_l \\;+\\;\n\t\t\\alpha \\#\\{\\tilde{z}_i = l\\}\n\t}\n\\end{align*}\n\\end{answer}\n%\\end{document}", "meta": {"hexsha": "675ccb0f4e73304207b79699a79acc7902e4c314", "size": 2801, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ps3/tex/semi_supervised_em/03-m-step-sol.tex", "max_stars_repo_name": "Ziggareto/cs229", "max_stars_repo_head_hexsha": "10b03b68b24d252dad3e3437561976d9509ebdd0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ps3/tex/semi_supervised_em/03-m-step-sol.tex", "max_issues_repo_name": "Ziggareto/cs229", "max_issues_repo_head_hexsha": "10b03b68b24d252dad3e3437561976d9509ebdd0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ps3/tex/semi_supervised_em/03-m-step-sol.tex", "max_forks_repo_name": "Ziggareto/cs229", "max_forks_repo_head_hexsha": "10b03b68b24d252dad3e3437561976d9509ebdd0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.0923076923, "max_line_length": 319, "alphanum_fraction": 0.6062120671, "num_tokens": 1240, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282707, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7028391344994344}}
{"text": "\\documentclass[a4paper]{article}\n\n\\input{temp}\n\n\\begin{document}\n\n\\title{Analysis II}\n\n\\maketitle\n\n\\newpage\n\n\\tableofcontents\n\n\\newpage\n\n\\section{Vector spaces}\n\n\\subsection{Vector spaces}\nIf $a_n\\in \\R$, $\\left(a_n\\right)\\to a$ if for every $\\epsilon > 0$, $\\exists N$ such that $|a_n-a|<\\epsilon$ whenever $n>N$.\\\\\nNow consider a general vector space:\n\\begin{defi}\nLet $V$ be a real vector space. A \\emph{norm} on $V$ is a function $||\\cdot ||:V\\to \\R$ satisfying:\\\\\n$\\bullet$ $||\\mathbf{v}|| \\geq 0$ $\\forall \\mathbf{v} \\in V$, and $||\\mathbf{v}|| = 0 \\iff \\mathbf{v} = \\mathbf{0}$;\\\\\n$\\bullet ||\\lambda \\mathbf{v}|| = |\\lambda| \\cdot ||\\mathbf{v}||$, $\\forall \\lambda \\in \\R$ and $\\mathbf{v} \\in V$;\\\\\n$\\bullet ||\\mathbf{v}+\\mathbf{w}|| \\leq ||\\mathbf{v}|| + ||\\mathbf{w}||$, $\\forall \\mathbf{v},\\mathbf{w}\\in V$ (triangle inequality).\n\\end{defi}\n\n\\begin{eg}\n$||\\mathbf{v}||_2 = \\left(\\sum v_i^2\\right)^\\frac{1}{2}$, the Euclidean norm;\\\\\n$||\\mathbf{v}||_1 = \\sum |v_i|$;\\\\\n$||\\mathbf{v}||_\\infty = \\max\\left\\{|v_1|,...,|v_n|\\right\\}$.\n\\end{eg}\n\n\\begin{eg}\nLet $V=C\\left[0,1\\right] = \\left\\{ f:\\left[0,1\\right]\\to\\R | f\\text{ is continuous}\\right\\}$. Then we can have the following norms:\\\\\n$\\bullet$ $||f||_1 = \\int_0^1 |f\\left(x\\right)| dx$;\\\\\n$\\bullet$ $||f||_2 = \\left(\\int_0^1 f\\left(x\\right)^2 dx\\right)^\\frac{1}{2}$;\\\\\n$\\bullet$ $||f||_\\infty = \\max_{x\\in\\left[0,1\\right]} |f\\left(x\\right)|$.\n\\end{eg}\n\n\\begin{notation}\nIf $||\\cdot||$ is a norm on $V$, we say the pair $\\left(V,||\\cdot||\\right)$ is a \\emph{normed space}.\n\\end{notation}\n\n\\begin{defi}\nSuppose $\\left(V,||\\cdot||\\right)$ is a normed vector space, and $\\left(\\mathbf{v}_n\\right)$ is a sequence in $V$. We say $\\left(\\mathbf{v}_n\\right)$ converges to $\\mathbf{v} \\in V$ if $\\forall \\varepsilon > 0$, $\\exists N$ such that $\\forall n>N$, $||\\mathbf{v}_n - \\mathbf{v}|| < \\varepsilon$.\\\\\nEquivalently, $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$ if and only if $||\\mathbf{v}_n-\\mathbf{v}|| \\to 0$ in $\\R$.\n\\end{defi}\n\n\\begin{eg}\nLet $V=\\R^n$, $\\mathbf{v}_k = \\left(v_{k,1},...,v_{k,n}\\right)$.\\\\\n(a) $\\left(\\mathbf{v}_k\\right) \\to \\mathbf{v}$ with respect to $||\\cdot||_\\infty$\\\\\n$\\iff ||\\mathbf{v}_k-\\mathbf{v}||_\\infty \\to 0$\\\\\n$\\iff \\max \\left\\{| v_{k,i} - v_i|\\right\\} \\to 0$\\\\\n$\\iff |v_{k,i} - v_i| \\to 0$ for all $1\\leq i \\leq n$\\\\\n$\\iff v_{k,i} \\to v_i$.\n\nSo sequence converges if and only if every component converges.\n\n(b) $\\left(\\mathbf{v}_k\\right)\\to \\mathbf{v}$ with respect to $||\\cdot||_1$\\\\\n$\\iff \\sum_{i=1}^n |v_{k,i}-v_i| \\to 0$\\\\\n$\\iff |v_{k,i} - v_i| \\to 0$ for all $1\\leq i \\leq n$\\\\\n$\\iff v_{k,i} \\to v_i$.\n\nNote the two different norms in (a) and (b) give the same notion of convergence.\n\nWe set a convention that, when talking about convergence in $\\R^n$ without mentioning a norm, then it's with respect to $||\\cdot||_1$ (or $||\\cdot||_\\infty$ or $||\\cdot||_2$) (these all give the same notion of convergence).\n\\end{eg}\n\n\\begin{eg}\nLet $V=C\\left[0,1\\right]$,\n\\begin{equation*}\n\\begin{aligned}\nf_n\\left(x\\right) = \\left\\{\n\\begin{array}{ll}\n1-nx & x\\in\\left[0,\\frac{1}{n}\\right)\\\\\\\\\n0 & x\\in \\left[\\frac{1}{n},1\\right]\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\nSo\n\\begin{equation*}\n\\begin{aligned}\n||f_n||_1 = \\int_0^1 |f_n\\left(x\\right)| dx = \\frac{1}{2n} \\to 0\n\\end{aligned}\n\\end{equation*}\nas $n\\to \\infty$. So $\\left(f_n\\right) \\to 0$ with respect to $||\\cdot||_1$.\n\nOn the other hand, $||f_n||_\\infty = 1 \\not\\to 0$, so $\\left(f_n\\right) \\not\\to 0$ with respect to $||\\cdot||_\\infty$. Here the two different norms give two different notions of convergence.\n\\end{eg}\n\n\\subsection{Continuity}\nLet $\\left(V,||\\cdot||\\right)$ be a normed vector space.\n\nRecall: If $\\mathbf{v}_n \\in V$ and $\\mathbf{v} \\in V$, the sequence $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$ if for every $\\varepsilon>0$, there exists $n$ such that $||\\mathbf{v}_n - \\mathbf{v}|| < \\varepsilon$ when $n>N$.\n\n\\begin{defi}\nSuppose $V$ and $W$ are normed spaces, and $f:V\\to W$. We say $f$ is \\emph{continuous} if the sequence $\\left(f\\left(\\mathbf{v}_n\\right)\\right) \\to f\\left(\\mathbf{v}\\right)$ in $W$ whenever $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$ in $V$.\n\n\\begin{eg}\n(1)$f:V \\to \\R^n$, $f\\left(\\mathbf{v}\\right) = \\left(f_1\\left(\\mathbf{v}\\right),...,f_n\\left(\\mathbf{v}\\right)\\right)$. Then $f$ is continuous if and only if $f_1,...,f_n$ are all continuous.\\\\\n(2) $p_i:\\R^n \\to \\R$ by $p_i\\left(\\mathbf{v}\\right) = v_i$. Then $p_i$ is continuous.\\\\\n(3) $V=C\\left[0,1\\right]$, $x\\in \\left[0,1\\right]$, $p_x:C\\left[0,1\\right]\\to \\R$ by $p_x\\left(f\\right) = f\\left(x\\right)$ (linear map). Then $p_x$ is continuous with respect to the uniform norm on $C\\left[0,1\\right]$:\\\\\n\\begin{equation*}\n\\begin{aligned}\n&\\left(f_n\\right) \\to f \\text{ wrt } ||\\cdot||_\\infty\\\\\n&\\iff \\max_{y\\in\\left[0,1\\right]} |f_n\\left(x\\right) - f\\left(x\\right) | \\to 0\\\\\n&\\implies |f_n\\left(x\\right)-f\\left(x\\right)| \\to 0\\\\\n&\\implies \\left(f_n\\left(x\\right)\\right) \\to f\\left(x\\right)\n\\end{aligned}\n\\end{equation*}\nHowever, $p_x$ is not continuous with respect to $||\\cdot||_1$ on $C\\left[0,1\\right]$. See examples in M\\&T.\n\\end{eg}\nSo linear maps may not be continuous.\\\\\n(4) If $f:V_1 \\to V_2$ and $g:V_2\\to V_3$ are continuous, so is $g\\circ f: V_1 \\to V_3$.\\\\\n(5) $||\\cdot||: V\\to \\R$ is continuous.\n\\end{defi}\n\n\\begin{lemma}\nIf $\\mathbf{v},\\mathbf{w}\\in V$, then $||\\mathbf{w}-\\mathbf{v}|| \\geq \\left| ||\\mathbf{w}|| - ||\\mathbf{v}|| \\right|$.\n\\begin{proof}\nSince $||\\mathbf{v}|| + ||\\mathbf{w}-\\mathbf{v}|| \\geq ||\\mathbf{w}||$,\\\\\n$||\\mathbf{w}-\\mathbf{v}|| \\geq ||\\mathbf{w}|| - ||\\mathbf{v}||$.\\\\\nSimilarly, $||\\mathbf{w}-\\mathbf{v}|| = ||\\mathbf{v}-\\mathbf{w}|| \\geq ||\\mathbf{v}||-||\\mathbf{w}||$. So $||\\mathbf{w}-\\mathbf{v}|| \\geq \\left| ||\\mathbf{w}|| - ||\\mathbf{v}|| \\right|$.\n\\end{proof}\n\\end{lemma}\n\nNow we can prove the $5^{th}$ example above:\n\\begin{proof}\nLet $f\\left(\\mathbf{v}\\right) = ||\\mathbf{v}||$. Then if $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$, $\\left(||\\mathbf{v}_n - \\mathbf{v}||\\right) \\to 0$. But $||\\mathbf{v}_n-\\mathbf{v}|| \\geq \\left| ||\\mathbf{v}_n|| - ||\\mathbf{v}|| \\right| = |f\\left(\\mathbf{v}_n\\right) - f\\left(\\mathbf{v}\\right)| \\geq 0$.\\\\\nSo by squeeze rule, $\\left(|f\\left(\\mathbf{v}_n\\right) - f\\left(\\mathbf{v}\\right) | \\right) \\to 0$, i.e. $f\\left(\\mathbf{v}_n\\right) \\to f\\left(\\mathbf{v}\\right)$.\n\\end{proof}\n\n\\begin{prop}\n$f:V \\to W$ is continuous if and only if for every $\\mathbf{v}\\in V$ and $\\varepsilon > 0$, there exists $\\delta > 0$ such that\n\\begin{equation*}\n\\begin{aligned}\n||f\\left(\\mathbf{w}\\right) - f\\left(\\mathbf{v}\\right) ||_W < \\varepsilon\n\\end{aligned}\n\\end{equation*}\nwhenever $||\\mathbf{w}-\\mathbf{v}||_V < \\delta$.\n\\begin{proof}\nSuppose the $\\varepsilon-\\delta$ condition hold. We'll show that $f$ is continuous, i.e. if $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$, then $\\left(f\\left(\\mathbf{v}_n\\right)\\right) \\to f\\left(\\mathbf{v}\\right)$.\\\\\nGiven $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$ and $\\varepsilon > 0$, pick $\\delta > 0$ such that $||f\\left(\\mathbf{w}\\right) - f\\left(\\mathbf{v}\\right) || < \\varepsilon$ whenever $|| \\mathbf{w}-\\mathbf{v}|| < \\delta$. Since $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$, there exists $N$ such that $||\\mathbf{v}_n-\\mathbf{v}|| < \\delta$ whenever $n>N$, i.e. $||f\\left(\\mathbf{v}_n\\right) - f\\left(\\mathbf{v}\\right)|| < \\varepsilon$ when $n>N$. So $\\left(f\\left(\\mathbf{v}_n\\right)\\right) \\to f\\left(\\mathbf{v}\\right)$. So $f$ is continuous.\\\\\nIf the $\\varepsilon-\\delta$ condition does not hold, then there exists $\\mathbf{v}\\in V$ and $\\varepsilon>0$ such that for every $n>0$, there exists $\\mathbf{v}_n$ with\n\\begin{equation*}\n\\begin{aligned}\n||\\mathbf{v}-\\mathbf{v}_n|| < \\frac{1}{n}\n\\end{aligned}\n\\end{equation*}\nbut\n\\begin{equation*}\n\\begin{aligned}\n||f\\left(\\mathbf{v}\\right) - f\\left(\\mathbf{v}_n\\right)|| > \\varepsilon\n\\end{aligned}\n\\end{equation*}\n(Otherwise, take $\\delta = \\frac{1}{n}$ and we get a contradiction). Then $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$, but $\\left(f\\left(\\mathbf{v}_n\\right)\\right) \\not \\to f\\left(\\mathbf{v}\\right)$. So $f$ is not continuous.\n\\end{proof}\n\\end{prop}\n\n\\subsubsection{Addendum}\nSuppose $V,W$ are normed spaces and $U_\\alpha$ is an open subset of $V$ for all $\\alpha \\in A$. Let $U = \\cup_{\\alpha \\in A} U_\\alpha$.\n\n\\begin{prop}\nSuppose $f:U \\to W$ and $f$ is continuous on all $U_\\alpha$. Then $f$ is continuous on $U$.\nIt's important that $U_\\alpha$'s are all open. For example, any $f:V\\to W$ is continuous on $\\left\\{\\mathbf{v}\\right\\}$, but may not be continuous on $\\cup_{\\mathbf{v} \\in V} \\left\\{\\mathbf{v}\\right\\} = V$.\n\\begin{proof}\nMust show that given $\\mathbf{v} \\in U$ and $\\varepsilon > 0$, $\\exists \\delta>0$ s.t.\n\\begin{equation*}\n\\begin{aligned}\nf\\left(B_\\delta\\left(\\mathbf{v}\\right) \\cap U\\right) \\subset B_\\varepsilon\\left(f\\left(\\mathbf{v}\\right)\\right)\n\\end{aligned}\n\\end{equation*}\n$\\mathbf{v} \\in \\cup_{\\alpha \\in A} U_\\alpha$, so $\\mathbf{v} \\in U_{\\alpha_0}$ for some $\\alpha_0 \\in A$. $f$ is continuous on $U_{\\alpha_0}$, so $\\exists \\delta_1 > 0$ s.t.\n\\begin{equation*}\n\\begin{aligned}\nf\\left(B_{\\delta_1}\\left(\\mathbf{v}\\right) \\cap U_{\\alpha_0}\\right) \\subset B_\\varepsilon\\left(f\\left(\\mathbf{v}\\right)\\right)\n\\end{aligned}\n\\end{equation*}\n$U_{\\alpha_0}$ is open, so $\\exists \\delta_2 > 0$ s.t. $B_{\\delta_2}\\left(\\mathbf{v}\\right) \\subset U_{\\alpha_0}$.\\\\\nLet $\\delta = \\min\\left(\\delta_1,\\delta_2\\right)$. Then $B_\\delta\\left(\\mathbf{v}\\right) \\subset B_{\\delta_1} \\left(\\mathbf{v}\\right)$ and $B_\\delta\\left(\\mathbf{v}\\right) \\subset B_{\\delta_2}\\left(\\mathbf{v}\\right) \\subset U_{\\alpha_0}$. \\\\\nSo $B_\\delta\\left(\\mathbf{v}\\right) \\subset B_{\\delta_1}\\left(\\mathbf{v}\\right)\\cap U_{\\alpha_0}$.\\\\\nThus\n\\begin{equation*}\n\\begin{aligned}\nf\\left(B_\\delta\\left(\\mathbf{v}\\right)\\cap U\\right) = f\\left(B_\\delta\\left(\\mathbf{v}\\right)\\right) \\subset f\\left(B_{\\delta_1} \\left(\\mathbf{v}\\right) \\cap U_{\\alpha_0}\\right) \\subset B_\\varepsilon\\left(f\\left(\\mathbf{v}\\right)\\right)\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{prop}\n\n\\subsection{Open and Closed Subsets}\n\n\\begin{defi}\nIf $\\mathbf{v}\\in V$ and $r>0$,\n\\begin{equation*}\n\\begin{aligned}\nB_r\\left(\\mathbf{v}\\right) = \\left\\{\\mathbf{w}\\in V| ||\\mathbf{v}-\\mathbf{w}|| < r\\right\\}\n\\end{aligned}\n\\end{equation*}\nis the \\emph{open ball} of radius $r$ centered at $\\mathbf{v}$,\n\\begin{equation*}\n\\begin{aligned}\nB_r\\left(\\mathbf{v}\\right) = \\left\\{\\mathbf{w}\\in V| ||\\mathbf{v}-\\mathbf{w}|| \\leq r\\right\\}\n\\end{aligned}\n\\end{equation*}\\\nis the \\emph{closed ball} of radius $r$ centered at $\\mathbf{v}$.\n\\end{defi}\n\nNow we can get an alternative definition of continuous:\\\\\n$\\bullet$ $f$ is continuous if and only if for every $\\mathbf{v}\\in V$ and $\\varepsilon > 0$, there exists $\\delta > 0$ such that $f\\left(B_\\delta\\left(\\mathbf{v}\\right)\\right) \\subset B_\\varepsilon\\left(f\\left(\\mathbf{v}\\right)\\right)$.\n\n\\begin{defi}\n$U \\subset V$ is an \\emph{open subset} of $V$ if for every $\\mathbf{u} \\in U$, there exists $\\varepsilon > 0$ such that $B_\\varepsilon\\left(\\mathbf{u}\\right) \\subset U$.\n\\end{defi}\n\n\\begin{prop}\nIf $f:V\\to W$ is continuous and $U \\subset W$ is open, then $f^{-1} \\left(U\\right)$ is open in $V$.\n\\begin{proof}\nSuppose $\\mathbf{v} \\in f^{-1}\\left(U\\right)$, i.e. $f\\left(\\mathbf{v}\\right) \\in U$.\\\\\n$U$ is open, so there exists $\\varepsilon > 0$ such that $B_\\varepsilon\\left(f\\left(\\mathbf{v}\\right)\\right) \\subset U$.\\\\\n$f$ is continuous, so $\\exists \\delta > 0$ such that $f\\left(B_\\delta \\left(\\mathbf{v}\\right)\\right) \\subset B_\\varepsilon\\left(f\\left(\\mathbf{v}\\right)\\right) \\subset U$, i.e. $B_\\delta\\left(\\mathbf{v}\\right) \\subset f^{-1} \\left(U\\right)$ so $f^{-1}\\left(U\\right)$ is open.\\\\\nThe converse is also true(see M\\&T).\n\\end{proof}\n\\end{prop}\n\n\\begin{defi} (Open subsets) Recall $U \\subset V$ is \\emph{open} in $V$ if for every $\\mathbf{u} \\in U$, $\\exists \\varepsilon > 0$ s.t. $B_\\varepsilon\\left(\\mathbf{u}\\right) \\subset U$.\n\\end{defi}\n\n\\begin{prop}\nIf $f:V \\to W$ is continuous and $U \\subset W$ is open, then $f^{-1}\\left(U\\right)$ is open in $V$.\n\\begin{eg}\nGiven $\\mathbf{v}\\in V$, define\n\\begin{equation*}\n\\begin{aligned}\nf_\\mathbf{v}: V \\to \\R\\\\\nf_\\mathbf{v}\\left(\\mathbf{w}\\right) = ||\\mathbf{v}-\\mathbf{w}||\n\\end{aligned}\n\\end{equation*}\nThen $f_\\mathbf{v}$ is continuous, so\n\\begin{equation*}\n\\begin{aligned}\nB_r\\left(\\mathbf{v}\\right) = f^{-1}_\\mathbf{v} \\left(\\left(-r,r\\right)\\right)\n\\end{aligned}\n\\end{equation*}\nis open in $V$, i.e. open balls are open.\n\\end{eg}\n\\end{prop}\n\n\\begin{defi} (Closed subsets) Recall if $C \\subset V$, $V-C = \\left\\{\\mathbf{v}\\in V | \\mathbf{v} \\not \\in C\\right\\}$ is the \\emph{complement} of $C$. $C \\subset V$ is \\emph{closed} if $V-C$ is an open subset of $V$.\n\\end{defi}\n\n\\begin{coro}\nIf $f:V \\to W$ is continuous and $C$ is closed in $W$, then $f^{-1}\\left(C\\right)$ is closed in $V$.\n\\end{coro}\n\n\\begin{eg}\nLet\n\\begin{equation*}\n\\begin{aligned}\nC = \\left\\{\\left(x,f\\left(x\\right)\\right) | x\\in \\R\\right\\}\n\\end{aligned}\n\\end{equation*}\nwhere $f:\\R \\to \\R$ is continuous. Then $C$ is closed in $\\R^2$.\n\\begin{proof}\nLet $F: \\R^2 \\to \\R$ by $F\\left(x,y\\right) = f\\left(x\\right) - y$ which is continuous.\\\\\nThen $C=F^{-1}\\left(\\left\\{0\\right\\}\\right)$ is closed, since $\\left\\{0\\right\\}$ is closed in $\\R$.\n\\end{proof}\n\\end{eg}\n\n\\begin{eg}\n\\begin{equation*}\n\\begin{aligned}\n\\overline{B}_r\\left(\\mathbf{v}\\right) = f_\\mathbf{v}^{-1} \\left(\\left[0,r\\right]\\right)\n\\end{aligned}\n\\end{equation*}\nis closed in any normed space $V$.\n\\end{eg}\n\n\\begin{eg}\n$\\Q \\subset \\R$ is neither open nor closed.\n\\end{eg}\n\n\\begin{eg}\n$V \\subset V$, $\\phi \\subset V$ are both open and closed.\n\\end{eg}\n\n\\begin{prop}\n$C$ is closed in $V$ if and only if for every sequence $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v} \\in V$ which satisfies $\\mathbf{v}_n \\in C$ for all $n$, we have $\\mathbf{v} \\in C$ as well.\n\\begin{proof}\nSuppose $C$ is closed in $V$, and $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$ with $\\mathbf{v} \\not \\in C$.\\\\\nNow $V-C$ is open, and $\\mathbf{v} \\in V-C$. So $\\exists \\varepsilon > 0$ s.t. $B_\\varepsilon\\left(\\mathbf{v}\\right) \\subset V-C$.\\\\\nSince $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$, there exists $N$ s.t. $\\mathbf{v}_n \\in B_\\varepsilon\\left(\\mathbf{v}\\right) \\subset V-C$ for all $n>N$. So $\\mathbf{v}_n \\not \\in C$. Contradiction.\n\nConversely, suppose that $C$ is not closed. Then $V-C$ is not open. So there exists $\\mathbf{u} \\in V-C$ such that for every $\\varepsilon > 0$, $B_\\varepsilon\\left(\\mathbf{v}\\right) \\not \\subset V-C$, i.e. $B_\\varepsilon\\left(\\mathbf{v}\\right) \\cap C \\neq \\phi$.\\\\\nNow pick $\\mathbf{v}_n$ s.t. $\\mathbf{v}_n \\in B_{1/n}\\left(\\mathbf{v}\\right) \\cap C$. Then $||\\mathbf{v}_n-\\mathbf{v}|| < \\frac{1}{n} \\to 0$, so $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$ for all $\\mathbf{v}n \\in C$, but $\\mathbf{v} \\not \\in C$. Contradiction.\n\\end{proof}\n\\end{prop}\n\n\\subsection{Lipschitz equivalence}\nWe've seen in the first lecture that $||\\cdot||_1$,$||\\cdot||_2$,$||\\cdot||_\\infty$ all induce the same notion of convergence on $\\R^n$. So $f:\\R^n \\to V$ is continuous with respect to $||\\cdot||$ if and only if  it's continuous with respect to $||\\cdot||_\\infty$.\n\n\\begin{prop}\nSuppose $||\\cdot||$,$||\\cdot||'$ are two norms on $V$. The map $id: \\left(V,||\\cdot||\\right) \\to \\left(V,||\\cdot||'\\right)$ by $id\\left(\\mathbf{v}\\right) = \\mathbf{v}$ is continuous if and only if there exists some constants $C>0$ such that\n\\begin{equation*}\n\\begin{aligned}\n||\\mathbf{v}||' \\leq C ||\\mathbf{v}||\n\\end{aligned}\n\\end{equation*}\nfor all $\\mathbf{v} \\in V$.\n\\begin{proof}\nSuppose $||\\mathbf{v}||' \\leq C ||\\mathbf{v}||$ for all $\\mathbf{v} \\in V$.\\\\\nIf $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$ with respect to $||\\cdot||$, then $\\left(||\\mathbf{v}-\\mathbf{v}_n||\\right) \\to 0$. But then\n\\begin{equation*}\n\\begin{aligned}\n0 \\leq ||\\mathbf{v} - \\mathbf{v}_n||' \\leq C ||\\mathbf{v} - \\mathbf{v}_n||\n\\end{aligned}\n\\end{equation*}\nBy the squeeze law, $||\\mathbf{v}-\\mathbf{v}_n||' \\to 0$ as well. So $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$ with respect to $||\\cdot||'$. This means $id:\\left(V,||\\cdot||\\right) \\to \\left(V,||\\cdot||'\\right)$ is continuous.\n\nConversely, suppose $id:\\left(V,||\\cdot||\\right) \\to \\left(V,||\\cdot||'\\right)$ is continuous. Then there exists $\\delta > 0$ s.t. $B_\\delta\\left(\\mathbf{0},||\\cdot||\\right) \\subset B_1\\left(\\mathbf{0},||\\cdot||'\\right)$.\\\\\nFor any $\\mathbf{v} \\in V, \\mathbf{v} \\neq 0$, there exists $k$ s.t. $||k\\mathbf{v}|| = \\frac{\\delta}{2}$. So $k\\mathbf{v} \\in B_\\delta \\left(\\mathbf{0},||\\cdot||\\right)$, so $k\\mathbf{v} \\in B_1\\left(\\mathbf{0},||\\cdot||'\\right)$, i.e. $||k\\mathbf{v}||' < 1 = \\frac{2}{\\delta} ||k\\mathbf{v}||$. Divide by $|k|$ we get\n\\begin{equation*}\n\\begin{aligned}\n||\\mathbf{v}||' \\leq \\frac{2}{\\delta}||\\mathbf{v}||\n\\end{aligned}\n\\end{equation*}\nfor all $\\mathbf{v} \\neq \\mathbf{0}$. So we can take $C = \\frac{2}{\\delta}$. The case $\\mathbf{v} = \\mathbf{0}$ is trivial.\n\\end{proof}\n\\end{prop}\n\n\\begin{defi}\nIf $||\\cdot||$ and $||\\cdot||'$ are two norms on $V$, we say they are \\emph{Lipschitz equivalent} if there exists $C>0$ s.t.\n\\begin{equation*}\n\\begin{aligned}\n\\frac{1}{C}||\\mathbf{v}|| \\leq ||\\mathbf{v}||' \\leq C||\\mathbf{v}||\n\\end{aligned}\n\\end{equation*}\nfor all $\\mathbf{v} \\in V$, or say there exists $C_1,C_2$ such that\n\\begin{equation*}\n\\begin{aligned}\n||\\mathbf{v}|| \\leq C_1 ||\\mathbf{v}||'\n\\end{aligned}\n\\end{equation*}\nand\n\\begin{equation*}\n\\begin{aligned}\n||\\mathbf{v}||' \\leq C_2 ||\\mathbf{v}||\n\\end{aligned}\n\\end{equation*}\nThat is also equivalent to\n\\begin{equation*}\n\\begin{aligned}\nid:\\left(V,||\\cdot||\\right) \\to \\left(V,||\\cdot||'\\right)\n\\end{aligned}\n\\end{equation*}\nand\n\\begin{equation*}\n\\begin{aligned}\nid:\\left(V,||\\cdot||'\\right) \\to \\left(V,||\\cdot||\\right)\n\\end{aligned}\n\\end{equation*}\nbeing both continuous.\n\\end{defi}\n\n\\begin{coro}\nIf $||\\cdot||$ and $||\\cdot||'$ are Lipschitz equivalent, then:\\\\\n(a) $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$ with respect to $||\\cdot||$ if and only if $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$ with respect to $||\\cdot||'$.\\\\\n(b) $f:V \\to W$ is continuous with respect to $||\\cdot||$ if and only if $f:V \\to W$ is continuous with respect to $||\\cdot||'$.\\\\\n(c) $g:W \\to V$ is continuous with respect to $||\\cdot||$ if and only if $g:W \\to V$ is continuous with respect to $||\\cdot||'$.\n\\end{coro}\n\n\\begin{eg}\n$||\\mathbf{v}||_\\infty \\leq ||\\mathbf{v}||_2 \\leq ||\\mathbf{v}||_1 \\leq n||\\mathbf{v}||_\\infty$ for all $\\mathbf{v} \\in \\R^n$. So $||\\cdot||_\\infty$, $||\\cdot||_2$, $||\\cdot||_1$ are all Lipschitz equivalent.\n\\end{eg}\n\n\\begin{prob}\nCan we find a norm on $\\R^n$ that is not Lipschitz equivalent to these?\n\\end{prob}\n\n\\newpage\n\n\\section{Uniform Convergence}\n\n\\subsection{Notions of Convergence}\n\nLet $A \\subset \\R$, $f,f_n: A \\to \\R$.\n\nWe've known the definition of continuous and boundedness from Analysis I. Now define $C\\left(A\\right)$ to be the set of continuous functions $f:A \\to \\R$, and $B\\left(A\\right)$ to be the set of bounded functions $F:A \\to \\R$. Both of these are vector spaces.\n\nWe have $C\\left[0,1\\right] \\subset B\\left[0,1\\right]$ by maximum value theorem, while $C\\left(0,1\\right) \\not\\subset B\\left(0,1\\right)$ (take $f\\left(x\\right) = \\frac{1}{x}$).\n\n\\begin{defi}\nIf $f,f_n : A \\to \\R$, we say $\\left(f_n\\right) \\to f$ \\emph{pointwise} if $\\left(f_n\\left(x\\right)\\right) \\to f\\left(x\\right)$ for every $x\\in A$.\n\\end{defi}\n\n\\begin{defi}\nThe \\emph{uniform norm} $||\\cdot||_\\infty$ on $B\\left(A\\right)$ is given by\n\\begin{equation*}\n\\begin{aligned}\n||f||_\\infty = \\sup_{x \\in A} \\left|f\\left(x\\right)\\right|\n\\end{aligned}\n\\end{equation*}\nIf $f,f_n:A \\to \\R$, we say $\\left(f_n\\right) \\to f$ \\emph{uniformly} if $||f-f_n||_\\infty \\to 0$.\n\nEquivalently, if $\\left(f_n\\right) \\to f$ pointwise, then for every $x \\in A$ and $\\epsilon >0$, $\\exists N$ s.t. $\\left|f_n\\left(x\\right) - f\\left(x\\right)\\right| < \\varepsilon$ whenever $n>N$.\\\\\nIf $\\left(f_n\\right) \\to f$ uniformly, given $\\varepsilon$, we need to find some $N$ that works for all $x \\in A$.\n\\end{defi}\n\n\\begin{eg}\nLet $A = \\R$, $f_n\\left(x\\right) = x+ \\frac{1}{n}$, $f\\left(x\\right) = x$. Then $\\left(f_n\\right) \\to f$ pointwise and uniformly.\n\\end{eg}\n\n\\begin{eg}\nLet $A = \\R$, $g_n\\left(x\\right) = \\left(x+\\frac{1}{n}\\right)^2$, $g\\left(x\\right) = x^2$. Then $g\\left(n\\right) \\to g$ pointwise, but $g_n-g = \\frac{2x}{n}+\\frac{1}{n^2}$ is not even bounded. So $\\left(g_n\\right)$ does not converge to $g$ uniformly. Nevertheless, $\\left(g_n\\right) \\to g$ uniformly on $\\left[a,b\\right]$ for any $a,b\\in \\R$) (since convergence and uniform convergence is the same on compact sets).\n\\end{eg}\n\n\\begin{eg}\nIf $\\left(f_n\\right) \\to f$ uniformly, then $\\left(f_n\\right) \\to f$ pointwise (Immediate from definition).\n\\end{eg}\n\n\\begin{thm}\nSuppose $f_n \\in C\\left(A\\right)$ and $\\left(f_n\\right) \\to f$ uniformly on $A$. Then $f \\in C\\left(A\\right)$.\n\n\\begin{proof}\nGiven $x \\in A$ and $\\varepsilon > 0$, we need to find $\\delta > 0$ s.t.\n\\begin{equation*}\n\\begin{aligned}\n\\left|f\\left(x\\right) - f\\left(y\\right) \\right| < \\varepsilon\n\\end{aligned}\n\\end{equation*}\nwhenever $\\left|x-y\\right| < \\delta$ and $y \\in A$.\\\\\nSince $\\left(f_n\\right) \\to f$ uniformly, $\\exists N$ s.t.\n\\begin{equation*}\n\\begin{aligned}\n\\left|f_n\\left(y\\right) - f\\left(y\\right)\\right| < \\frac{\\varepsilon}{4}\n\\end{aligned}\n\\end{equation*}\nwhenever $n \\geq N$ and $y \\in A$.\\\\\nSince $f_N$ is continuous, $\\exists \\delta > 0$ s.t.\n\\begin{equation*}\n\\begin{aligned}\n\\left|f_N\\left(x\\right) - f_N\\left(y\\right) \\right| < \\frac{\\varepsilon}{2}\n\\end{aligned}\n\\end{equation*}\nwhenever $\\left|x-y\\right| < \\delta$ and $y \\in A$. Then for $|x-y| < \\delta$ and $y \\in A$,\n\\begin{equation*}\n\\begin{aligned}\n\\left|f\\left(x\\right)-f\\left(y\\right)\\right| &\\leq \\left|f\\left(x\\right)-f_N\\left(x\\right)\\right| + \\left|f_N\\left(x\\right)-f_N\\left(y\\right)\\right| + \\left|f_N\\left(y\\right) - f\\left(y\\right) \\right|\\\\\n&<\\frac{\\varepsilon}{4} + \\frac{\\varepsilon}{2} + \\frac{\\varepsilon}{4} = \\varepsilon\n\\end{aligned}\n\\end{equation*}\nwhich is what we wanted to prove.\n\\end{proof}\n\\end{thm}\n\n\\begin{coro}\n$C\\left[a,b\\right]$ is a closed subset of $B\\left[a,b\\right]$ with respect to $||\\cdot||_\\infty$.\n\\begin{proof}\nRecall that $C$ is closed if $c \\in C$ whenever $\\left(c_n\\right) \\to c$ and $c_n \\in C$.\n\\end{proof}\n\\end{coro}\n\n\\begin{eg}\nLet $A = \\left[0,1\\right]$, $f_n\\left(x\\right) = x^n$, $f\\left(x\\right) =\\left\\{ \\begin{array}{ll} 0 & x \\in \\left[0,1\\right) \\\\ 1 & x = 1\\end{array}\\right.$.\\\\\nThen $\\left(f_n\\right) \\to f$ pointwise but not uniformly, since $f_n\\in C\\left[0,1\\right]$, but $f \\not\\in C\\left[0,1\\right]$.\n\\end{eg}\n\n\\begin{eg}\nLet $f_n\\left(x\\right) = \\left(1-x\\right)x^n$. Then $\\left(f_n\\right) \\to 0$ pointwise. In fact $\\left(f_n\\right) \\to 0$ uniformly.\n\\begin{proof}\nGiven $\\varepsilon>0$, we must find $N$ s.t. $|f_n\\left(x\\right)| < \\varepsilon$ for all $x \\in \\left[0,1\\right]$ whenever $n>N$.\n\nWe know $1-\\varepsilon < 1$, so $\\left(1-\\varepsilon\\right)^n \\to 0$. Pick $N$ s.t. $\\left(1-\\varepsilon\\right)^n < \\varepsilon$ whenever $n>N$. Then for $n>N$, \n\\begin{equation*}\n\\begin{aligned}\n\\left| \\left(1-x\\right)x^n\\right| < 1 \\cdot \\left(1-\\varepsilon\\right)^n < \\varepsilon\n\\end{aligned}\n\\end{equation*}\nfor $x \\in \\left[0,1-\\varepsilon\\right]$, and\n\\begin{equation*}\n\\begin{aligned}\n\\left|\\left(1-x\\right)x^n\\right| < \\varepsilon \\cdot 1^n = \\varepsilon\n\\end{aligned}\n\\end{equation*}\nfor $x \\in \\left(1-\\varepsilon,1\\right]$.\n\\end{proof}\n\\end{eg}\n\nEverything so far in this chapter works for $f:A \\to W$, where $A \\subset V$ and $V$, $W$ are both normed spaces. (exercise)\n\nRecall that if $f,f_n\\in C\\left[a,b\\right]$ with $a,b\\in \\R$, then $\\left(f_n\\right) \\to f$ in $L^1$ (with respect to $||\\cdot||_1$) if \n\\begin{equation*}\n\\begin{aligned}\n||f_n - f||_1 = \\int_a^b \\left|f_n\\left(x\\right) - f\\left(x\\right) \\right| \\to 0\n\\end{aligned}\n\\end{equation*}\n\n\\begin{lemma}\nIf $\\left(f_n\\right) \\to f$ uniformly on $\\left[a,b\\right]$ and $f_n\\in C\\left[a,b\\right]$, then $\\left(f_n\\right) \\to f$ in $L^1$ on $\\left[a,b\\right]$.\n\\begin{proof}\n$\\left(f_n\\right) \\to f$ uniformly implies that $f \\in C\\left[a,b\\right]$.\\\\\nGiven $\\varepsilon>0$, pick $N$ s.t.\n\\begin{equation*}\n\\begin{aligned}\n\\left|f_n\\left(x\\right) - f\\left(x\\right) \\right| < \\frac{\\varepsilon}{\\left(b-a\\right)}\n\\end{aligned}\n\\end{equation*}\nfor $n>N$ and $x \\in \\left[a,b\\right]$. Then\n\\begin{equation*}\n\\begin{aligned}\n||f_n-f||_1 = \\int_a^b \\left|f_n\\left(x\\right) - f\\left(x\\right) \\right| dx < \\int_a^b \\frac{\\varepsilon}{b-a} dx = \\varepsilon\n\\end{aligned}\n\\end{equation*}\nSo $\\left(f_n\\right) \\to f$ in $L^1$.\n\\end{proof}\n\\end{lemma}\n\n\\begin{eg}\nLet $A = \\left[0,1\\right]$,\n\\begin{equation*}\n\\begin{aligned}\nf_n\\left(x\\right) = \\left\\{\n\\begin{array}{ll}\nnx & x\\in\\left[0,\\frac{1}{n}\\right]\\\\\n2-nx & x \\in \\left[\\frac{1}{n},\\frac{2}{n}\\right]\\\\\n0 & x\\in \\left[\\frac{2}{n},1\\right]\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\nThen $\\left(f_n\\right) \\to 0$ pointwise, and in $L^1$, but not uniformly.\n\\end{eg}\n\n\\begin{eg}\nLet $A=\\left[0,1\\right]$,\n\\begin{equation*}\n\\begin{aligned}\nf_n\\left(x\\right) = \\left\\{\n\\begin{array}{ll}\nn^2 x & x\\in\\left[0,\\frac{1}{n}\\right]\\\\\n2n-n^2 x & x\\in\\left[\\frac{1}{n},\\frac{2}{n}\\right]\\\\\n0 & x\\in\\left[\\frac{2}{n},1\\right]\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\nThen $\\left(f_n\\right) \\to f$ pointwise, but not in $L^1$, nor uniformly.\n\\end{eg}\n\nWe woud like to say that a sequence of bounded integrable functions on $\\left[0,1\\right]$ that converges pointwise converges in $L^1$. But for this to be true, we need a better definition of $\\int$ (in measure and probability).\n\n\\subsection{Power series}\nRecall some facts about series of complex numbers from Analysis I, for $\\sum_{i=0}^\\infty c_i$, $c_i \\in \\C$:\\\\\n1) $\\sum_{i=0}^\\infty c_i = c$ means $\\left(\\sum_{i=0}^n c_i\\right) \\to c$;\\\\\n2) $\\sum_{i=0}^\\infty c_i$ converges if and only if $\\sum_{i=k}^\\infty c_i$ converges;\\\\\n3) $\\sum_{i=k}^\\infty \\alpha^i = \\frac{\\alpha^k}{1-\\alpha}$ if $|\\alpha|<1$;\\\\\n4) If $\\sum_{i=0}^\\infty c_i$ converges, then $\\left(c_n\\right) \\to 0$;\\\\\n5) If $0<a_i<b_i$ for all $i$ (here $a_i,b_i\\in\\R$), and $\\sum_{i=0}^\\infty b_i$ converges, then $\\sum_{i=0}^\\infty a_i$ converges as well;\\\\\n6) If $\\sum_{i=0}^\\infty |c_i|$ converges, then $\\sum_{i=0}^\\infty c_i$ converges.\n\n\\begin{coro}\nIf $|c_i| < b_i$ for all $i$ and $\\sum_{i=0}^\\infty b_i$ converges, then $\\sum_{i=0}^\\infty c_i$ converges.\n\\begin{proof}\nFollows from (5) and (6).\n\\end{proof}\n\\end{coro}\n\n\\begin{defi}\nA \\emph{power series} is \n\\begin{equation*}\n\\begin{aligned}\n\\sum_{i=0}^\\infty a_i \\left(z_i\\right)^i\n\\end{aligned}\n\\end{equation*}\nwhere $a_i,c,z\\in \\C$. Call $c$ the \\emph{center} of the series.\n\\end{defi}\n\n\\begin{prop}\nSuppose $\\sum_{i=0}^\\infty a_i\\left(z_0-c\\right)^i$ converges for some $z_0 \\in \\C$. Then the series $\\sum_{i=0}^\\infty a_i\\left(z_0-c\\right)^i$ converges for all $z$ with $|z-c| < |z_0 - c|$.\n\\begin{proof}\nBy (4), $\\left(a_i\\left(z_0-c\\right)^i\\right) \\to 0$. Pick $N$ such that $|a_i\\left(z_0-c\\right)^i| < 1$ for all $i \\geq N$.\\\\\nBy (2), suffices to show that $\\sum_{i=N}^\\infty a_i\\left(z-c\\right)^i$ converges. Now\n\\begin{equation*}\n\\begin{aligned}\n|a_i\\left(z-c\\right)^i| = |a_i\\left(z_0-c\\right)^i | \\cdot \\left|\\frac{z-c}{z_0-c}\\right|^i \\leq 1\\cdot \\alpha^i\n\\end{aligned}\n\\end{equation*}\n(call this 'Key Estimate', to be used later) for $i \\geq N$ where $\\alpha = \\left|\\frac{z-c}{z_0-c}\\right|$.\\\\\nFor $|z-c| < |z_0-c|$, $\\alpha<1$, so $\\sum_{i=N}^\\infty \\alpha^i$ converges.\\\\\nBy corollary, it follows that $\\sum_{i=0}^\\infty a_i\\left(z-c\\right)^i$ converges.\n\\end{proof}\n\\end{prop}\n\n\\begin{defi}\n\\begin{equation*}\n\\begin{aligned}\nR=\\sup\\left\\{|z-c| |\\sum_{i=0}^\\infty a_i\\left(z-c\\right)^i\\text{ converges }\\right\\}\n\\end{aligned}\n\\end{equation*}\nis the \\emph{radius of convergence} of this series.\n\\end{defi}\nThe above proposition says that $\\sum_{i=0}^\\infty a_i\\left(z-c\\right)^i$ converges for all $z \\in B_R\\left(c\\right) = \\left\\{z \\in \\C | |z-c|<R\\right\\}$.\n\nWe can define $f:B_R \\left(c\\right) \\to \\C$ by\n\\begin{equation*}\n\\begin{aligned}\nf\\left(z\\right) = \\sum_{i=0}^\\infty a_i\\left(z-c\\right)^i\n\\end{aligned}\n\\end{equation*}\n\nLet\n\\begin{equation*}\n\\begin{aligned}\np_n\\left(z\\right) = a_i\\left(z-c\\right)^i\n\\end{aligned}\n\\end{equation*}\nThen $\\left(p_n\\right) \\to f$ pointwise on $B_R\\left(c\\right)$.\n\n\\begin{thm}\nWith notation as above, $\\left(p_n\\right) \\to f$ uniformly on $\\bar{B}_r\\left(c\\right) = \\left\\{z \\in \\C | |z-c| \\leq r\\right\\}$ for any $r < R$.\n\\begin{proof}\nFix $z_0 \\in \\C$ with $r < |z_0-c| < R$. Then $\\sum_{i=0}^\\infty a_i\\left(z_0-c\\right)^i$ converges. Let\n\\begin{equation*}\n\\begin{aligned}\nE_n\\left(z\\right) = f\\left(z\\right) - p_n\\left(z\\right) = \\sum_{i=n+1}^\\infty a_i\\left(z-c\\right)^i\n\\end{aligned}\n\\end{equation*}\nWe want to show that given $\\varepsilon>0$, $\\exists N$ s.t. $|E_n\\left(z\\right)|<\\varepsilon$ for all $n>N$ and $z \\in \\bar{B}_r\\left(c\\right)$.\n\nPick $N_0$ with $|a_i\\left(z_0-c\\right)^i | < 1$ for all $i \\geq N_0$ as in the proof of the previous proposition.\n\nNow for $n > N_0$, Key Estimate says that\n\\begin{equation*}\n\\begin{aligned}\n|E_n\\left(z\\right)| &= \\left|\\sum_{i=m}^\\infty a_i\\left(z-c\\right)^i \\right| \\\\\n&\\leq\\sum_{i=n+1}^\\infty |a_i\\left(z-c\\right)^i|\\\\\n&\\leq\\sum_{i=n+1}^\\infty \\alpha\\left(z\\right)^i\n\\end{aligned}\n\\end{equation*}\nwhere $\\alpha\\left(z\\right) = \\frac{|z-c|}{|z_0-c|}$.\\\\\nIf $z \\in \\bar{B}_r\\left(c\\right)$, $\\alpha\\left(z\\right) \\leq \\alpha_0 = \\frac{r}{|z_0-c|} < 1$. So\n\\begin{equation*}\n\\begin{aligned}\n\\left|E_n\\left(z\\right) \\right| \\leq \\sum_{i=1}^\\infty \\alpha^i = \\frac{\\alpha_0^{n+1}}{1-\\alpha_0}\n\\end{aligned}\n\\end{equation*}\nNow $\\alpha_0 < 1$, so $\\frac{\\alpha_0^{n+1}}{1-\\alpha_0} \\to 0$ as $n \\to \\infty$. Pick $N>N_0$ s.t. $\\frac{\\alpha_0^{n+1}}{1-\\alpha_0} < \\varepsilon$ for $n>N$. Then $|E_n\\left(z\\right)| < \\varepsilon$ for all $n>N$ and $z \\in \\bar{B}_r \\left(c\\right)$ which is what we wanted.\n\\end{proof}\n\\end{thm}\n\n\\begin{rem}\n$\\left(p_n\\right)$ may not converge uniformly on $B_R\\left(c\\right)$. For example, $\\sum_{i=0}^\\infty x^i$ has $R=1$, and equals $f\\left(x\\right) = \\frac{1}{1-x}$ on $B_1\\left(0\\right)$, but $p_n$ is a polynomial, so bounded on $\\bar{B}_1\\left(0\\right)$, so $f\\left(x\\right) - p_n\\left(x\\right)$ is not even a bounded function on $B_1\\left(0\\right)$.\n\\end{rem}\n\n\\begin{coro}\n\\begin{equation*}\n\\begin{aligned}\nf\\left(z\\right) = \\sum_{i=0}^\\infty a_i\\left(z-c\\right)^i\n\\end{aligned}\n\\end{equation*}\nis a continuous map $f:B_R\\left(c\\right) \\to \\C$.\n\\begin{proof}\n$p_n = \\sum_{i=0}^n a_I\\left(z-c\\right)^i$ is a polynomial, so is continuous as a map $\\C \\to \\C$. $\\left(p_n\\right) \\to f$ uniformly on $\\bar{B}_r\\left(c\\right)$ for any $r<R$, so $f:\\bar{B}_r\\left(c\\right) \\to \\C$ is continuous for any $r<R$. \\\\\nGiven $z \\in B_R\\left(c\\right)$, pick $r$ with $z \\in B_r\\left(c\\right)$. Then $f$ is continuous at $z$. So $f$ is continuous at all $z \\in B_R\\left(c\\right)$, i.e. $f:B_R\\left(c\\right) \\to \\C$ is continuous.\n\\end{proof}\n\\end{coro}\n\nWe can now construct lots of continuous functions using power series.\n\n\\begin{eg}\n\\begin{equation*}\n\\begin{aligned}\n\\exp\\left(z\\right) = \\sum_{i=0}^\\infty \\frac{z^i}{i!}\n\\end{aligned}\n\\end{equation*}\nhas $R = \\infty$, so is a well defined, continuous function on $\\C$.\n\\end{eg}\n\nLet $f\\left(x\\right) = \\exp\\left(x\\right)$ for $x \\in \\R$. We want to show that $f'\\left(x\\right) = f\\left(x\\right)$:\n\\begin{equation*}\n\\begin{aligned}\n\\frac{d}{dx}\\left(\\sum_{i=0}^\\infty \\frac{x_i}{i!}\\right) = \\sum_{i=0}^\\infty \\frac{ix^{i-1}}{i!} = \\sum_{i=1}^\\infty \\frac{x^{i-1}}{\\left(i-1\\right)!} = \\exp\\left(x\\right)\n\\end{aligned}\n\\end{equation*}\nthis looks easy, but why does the first equality hold?\n\n\\begin{eg}\nSuppose $$\\sum_{i=0}^\\infty a_i\\left(z-c\\right)$$ has radius of convergence $R$. Then if $p_n = \\sum_{i=0}^\\infty a_i \\left(z-c\\right)^i$, $\\left(p_n\\right) \\to f\\left(z\\right) = \\sum_{i=0}^\\infty a_i\\left(z-c\\right)^i$ uniformly on $\\bar{B}_r\\left(c\\right)$ for all $r<R \\implies$ $f$ is continuous on $\\bar{B}_r\\left(c\\right)$ for $r\\in R$.\\\\\nTake $U_r = B_r\\left(c\\right)$, so $f$ is continuous on $U_r$ for $r<R$. $U_r$ is open. So $f$ is continuous on $\\cup_{r<R} U_r = B_R\\left(c\\right)$.\n\\end{eg}\n\n\\subsection{Integration and Differentiation}\nRecall from Analysis I:\n\n\\begin{thm} (Fundamental Theorem of Calculus) If $f\\in C\\left[a,b\\right]$, then\n\\begin{equation*}\n\\begin{aligned}\nF\\left(x\\right) = \\int_{x_0}^x f\\left(y\\right) dy\n\\end{aligned}\n\\end{equation*}\nexists, and \n\\begin{equation*}\n\\begin{aligned}\nF'\\left(x\\right) = f\\left(x\\right).\n\\end{aligned}\n\\end{equation*}\n\\end{thm}\n\nSome properties of integral:\\\\\nSuppose $f,g \\in C\\left[a,b\\right]$.\\\\\n(1)\n\\begin{equation*}\n\\begin{aligned}\n\\int_{x_0}^x f\\left(y\\right)+\\lambda g\\left(y\\right) dy = \\int_{x_0}^x f\\left(y\\right) dy + \\lambda \\int_{x_0}^x g\\left(y\\right) dy\n\\end{aligned}\n\\end{equation*}\n\n(2) If $f\\left(y\\right) \\leq g\\left(y\\right)$ for all $y\\in\\left[a,b\\right]$, then\n\\begin{equation*}\n\\begin{aligned}\n\\int_{x_0}^x f\\left(y\\right)dy \\leq \\int_{x_0}^x g\\left(y\\right) dy\n\\end{aligned}\n\\end{equation*}\n\n(3) \n\\begin{equation*}\n\\begin{aligned}\n\\end{aligned}\n\\left|\\int_{x}^{x_0} f\\left(y\\right) dy \\right| \\leq \\left|\\int_x^{x_0} \\left|f\\left(y\\right)\\right|dy\\right|\n\\end{equation*}\n\nSuppose $f_n \\in C\\left[a,b\\right]$ and $\\left(f_n\\right) \\to f$ uniformly on $\\left[a,b\\right]$. So $f\\in C\\left[a,b\\right]$. Thus\n\\begin{equation*}\n\\begin{aligned}\nF\\left(x\\right) = \\int_{x_0}^x f_n\\left(y\\right) dy\n\\end{aligned}\n\\end{equation*}\nand\n\\begin{equation*}\n\\begin{aligned}\nF\\left(x\\right) = \\int_{x_0}^x f\\left(y\\right) dy\n\\end{aligned}\n\\end{equation*}\nare defined.\n\n\\begin{prop}\n$\\left(F_n\\right) \\to F$ uniformly on $\\left[a,b\\right]$.\n\\begin{proof}\n$\\left(f_n\\right) \\to f$ uniformly, so given $\\varepsilon>0$, $\\exists N$ s.t.\n\\begin{equation*}\n\\begin{aligned}\n\\left|f_n\\left(x\\right) - f\\left(x\\right) \\right| < \\varepsilon\n\\end{aligned}\n\\end{equation*}\nfor all $n>N$ and $x \\in \\left[a,b\\right]$.\nChoose $N$ s.t.\n\\begin{equation*}\n\\begin{aligned}\n\\left|f_n\\left(x\\right) - f\\left(x\\right) \\right| < \\frac{\\varepsilon}{b-a}\n\\end{aligned}\n\\end{equation*}\nfor all $n>N$ and $x \\in \\left[a,b\\right]$. Then for $x \\in \\left[a,b\\right]$,\n\\begin{equation*}\n\\begin{aligned}\n\\left|F_n\\left(x\\right) - F\\left(x\\right)\\right| &= \\left|\\int_{x_0}^x \\left(f_n\\left(y\\right) - f\\left(y\\right)\\right) dy\\right|\\\\\n&\\leq \\left|\\int_{x_0}^x \\left|f_n\\left(y\\right)-f\\left(y\\right)\\right|dy\\right|\\\\\n&\\leq \\left| \\int_{x_0}^x \\frac{\\varepsilon}{b-a} dy\\right| dy\\\\\n&= \\frac{\\varepsilon \\left|x-x_0\\right|}{\\left|b-a\\right|}\\\\\n&\\leq \\varepsilon\n\\end{aligned}\n\\end{equation*}\nSo $\\left(F_n\\right) \\to F$ uniformly on $\\left[a,b\\right]$.\n\\end{proof}\n\\end{prop}\n\nNote that $\\left(f_n\\right) \\in C\\left(\\R\\right)$, $\\left(f_n\\right) \\to f$ uniformly does not imply $\\left(F_n\\right) \\to F$ uniformly on $\\R$. (But does on $\\left[a,b\\right]$ for $a,b\\in \\R$).\n\nLet $$f\\left(y\\right) = \\sum_{i=0}^\\infty a_i \\left(y-c\\right)^i$$ be a real power series ($a_i,c,y \\in \\R$) with radius of convergence $R$. Then if the partial sum $p_n\\left(y\\right) = \\sum_{i=0}^n a_i\\left(y-c\\right)^i$, then $\\left(p_n\\right) \\to f$ uniformly on $\\left[c-r,c+r\\right]$ for any $r<R$.\n\n\\begin{coro}\n\\begin{equation*}\n\\begin{aligned}\n\\int_c^x f\\left(y\\right)dy = \\sum_{i=0}^\\infty \\frac{a_i}{i+1}\\left(x-c\\right)^{i+1}\n\\end{aligned}\n\\end{equation*}\nfor all $x \\in \\left(c-R,c+R\\right)$.\n\\begin{proof}\nGiven $x \\in \\left(c-R,c+R\\right)$, pick $r$ with $|x-c|<r<R$. Then $\\left(p_n\\right) \\to f$ uniformly on $\\left[c-r,c+r\\right]$, so by proposition\n\\begin{equation*}\n\\begin{aligned}\n\\left(P_n\\right) \\to \\int_c^x f\\left(y\\right)dy\n\\end{aligned}\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\begin{aligned}\nP_n = \\int_c^x p_n\\left(y\\right)dy = \\sum_{i=0}^n \\frac{a_i}{i+1} \\left(x-c\\right)^{i+1}\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{coro}\n\nQ: If $\\left(f_n\\right) \\to f$ uniformly, what can I say about $\\left(f_n\\right)$?\\\\\nA: Nothing, because:\n\n\\begin{eg}\nTake $f_n\\left(x\\right) = \\frac{1}{n}\\sin nx$, $x \\in \\left[0,\\pi\\right]$. Then $\\left(f_n\\right) \\to 0$ uniformly on $\\left[0,\\pi\\right]$, but $f_n' \\left(x\\right) = \\cos nx$ doesn't converge for any $x \\in \\left(0,\\pi\\right)$.\n\\end{eg}\n\n\\begin{tikzpicture}\n\\draw (0,0) -- (3,0);\n\\draw (0,0) -- (0,3);\n\\draw (0,1) .. controls (0.7,2.0) and (1.5,0.8) .. (2.5,1.5);\n\\end{tikzpicture}\n\n\\begin{prop}\nIf\n\\begin{equation*}\n\\begin{aligned}\nf\\left(y\\right) = \\sum_{i=0}^\\infty a_i\\left(y-c\\right)^i\n\\end{aligned}\n\\end{equation*}\nconverges on $\\left(c-R,c+R\\right)$, then\n\\begin{equation*}\n\\begin{aligned}\nf\\left(y\\right) = \\sum_{i=0}^\\infty ia_i \\left(y-c\\right)^{i-1}\n\\end{aligned}\n\\end{equation*}\non $\\left(c-R,c+R\\right)$.\n\\begin{proof}\n\\begin{lemma}\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{i=0}^\\infty ia_i \\left(y-c\\right)^{i-1}\n\\end{aligned}\n\\end{equation*}\nconverges for all $y \\in \\left(c-R,c+R\\right)$.\n\n\\begin{proof}\nPick $y_0$ with $|y-c| < |y_0-c| < R$.\\\\\n$\\sum_{i=0}^\\infty a_i \\left(y-c\\right)^i$ converges, so by 'Key Estimate', $\\exists N$ s.t.\n\\begin{equation*}\n\\begin{aligned}\n|a_i\\left(y-c\\right)|^i < \\alpha^i\n\\end{aligned}\n\\end{equation*}\nfor all $i\\geq N$, where $\\alpha = \\left|\\frac{y-c}{y_0-c}\\right|<1$.\n\nIf $y=c$, $\\sum ia_i\\left(y-c\\right)^{i-1}$ obviously converges. If not, estimate\n\\begin{equation*}\n\\begin{aligned}\n\\left|ia_i\\left(y-c\\right)^{i-1}\\right| < \\frac{i}{|y-c|}\\alpha^i\n\\end{aligned}\n\\end{equation*}\nNow $\\sum_{i=0}^\\infty \\frac{i}{|y-c|}\\alpha^i$ converges by Ratio Test. So $\\sum_{i=0}^\\infty ia_i \\left(y-c\\right)^{i-1}$ converges as well.\n\\end{proof}\n\\end{lemma}\n\nNow begin the proof of proposition:\n\n\\begin{equation*}\n\\begin{aligned}\ng\\left(y\\right) = \\sum_{i=0}^\\infty ia_i \\left(y-c\\right)^{i-1}\n\\end{aligned}\n\\end{equation*}\nis continuous on $\\left(c-R,c+R\\right)$. So by corollary,\n\\begin{equation*}\n\\begin{aligned}\n\\int_c^x g\\left(y\\right) dy = \\sum_{i=1}^\\infty a_i \\left(x-c\\right)^i = f\\left(x\\right) - f\\left(c\\right)\n\\end{aligned}\n\\end{equation*}\nBy Fundamental Theorem of Calculus, $f'\\left(x\\right) = g\\left(x\\right)$.\n\\end{proof}\n\\end{prop}\n\nApplication: Power series solutions of ODEs are legit (as long as we check the radius of convergence).\n\n\\newpage\n\n\\section{Compactness}\n\n\\subsection{Compact subsets of $\\R^n$}\n\nLet $V$ be a normed space. Then if $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v} \\in V$ and $\\left(\\mathbf{v_{n_j}}\\right) $ is a subsequence of $\\left(\\mathbf{v}_n\\right)$, then $\\left(\\mathbf{v_{n_j}}\\right) \\to \\mathbf{v}$. We leave this as an exercise.\n\n\\begin{defi}\n$A \\subset V$ is bounded if $\\exists M \\in \\R$ s.t. $||\\mathbf{v}|| \\leq M$ for all $\\mathbf{v} \\in A$.\n\nIf $||\\cdot||$ and $||\\cdot||'$ are Lipschitz equivalent, then boundedness with respect to the two norms are equivalent.\n\\end{defi}\n\n\\begin{coro} (Bolzano-Weierstrass in $\\R^n$)\nIf $\\left(\\mathbf{v}_k\\right)$ is a bounded sequence in $\\R^n$, it has a converging subsequence.\n\\begin{proof}\nTo prove this, simply pick a subsequence with the first coordinate convergent, then pick a subsequence of that subsequence with the second coordinate convergent, etc..\n\nLet $\\mathbf{v}_k = \\left(v_{1,k},...,v_{n,k}\\right)$.\\\\\n$\\left(\\mathbf{v}_k\\right)$ is bounded, so $\\left(v_{i,k}\\right)$ is bounded for all $1\\leq i\\leq n$. By B-W theorem, there exists a convergent subsequence $\\left(v_{1,k_j^1}\\right)$ of $\\left(v_{1,k}\\right)$. Now the sequence $\\left(v_{2,k_j^1}\\right)$ is bounded. So by B-W, there exists a subsequence $\\left(v_{2,k_j^2}\\right)$ which converges. Then by the previous exercise, $\\left(v_{1,k_j^2}\\right)$ converges.\\\\\nNow consider the sequence $\\left(v_{3,k_j^2}\\right)$. By B-W, it has a convergent subsequence $\\left(v_{3,k_j^3}\\right)$. etc.\n\nApply B-W $n$ times, we get $\\left(\\mathbf{v}_{k_j^n}\\right)$ of original $\\left(\\mathbf{v}_n\\right)$ s.t. $\\left(v_{i,k_j^n}\\right)$ converges for $1\\leq i\\leq n$. So $\\left(\\mathbf{v}_{k_j^n}\\right)$ converges.\n\\end{proof}\n\\end{coro}\n\n\\begin{eg}\nLet $V=C\\left[0,1\\right]$ with $||\\cdot||_\\infty$, and\n\\begin{equation*}\n\\begin{aligned}\nf_n\\left(x\\right) = \\left\\{ \\begin{array}{ll}\n1-nx & x \\in \\left[0,\\frac{1}{n}\\right]\\\\\n0 & x\\in\\left[\\frac{1}{n},1\\right]\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\n\n\\begin{tikzpicture}\n\\draw (0,0) -- (1.5,0);\n\\draw (0,0) -- (0,1.5);\n\\draw[red] (0,1) -- (0.5,0);\n\\draw[blue] (0,1) -- (0.33,0);\n\\end{tikzpicture}\n\nIf\n\\begin{equation*}\n\\begin{aligned}\nf\\left(x\\right) = \\left\\{\\begin{array}{ll}\n1 & x=0\\\\\n0 & x>0\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\nthen $\\left(f_n\\right) \\to f$ pointwise. Then $\\left(f_n\\right)$ is bounded with respect to $||\\cdot||_\\infty$ but has no convergent subsequence.\n\\begin{proof}\nSuppose $\\left(f_{n_j}\\right) \\to g$ uniformly, then $\\left(f_{n_j}\\right) \\to g$ pointwise, so $g=f$. But $f \\not\\in C\\left[0,1\\right]$, so $\\left(f_{n_j}\\right) \\not\\to f$ uniformly.\n\\end{proof}\n\\end{eg}\n\n\\begin{defi}\nWe say $A \\subset V$ is sequentially compact (s.compact) if any sequence $\\left(\\mathbf{v}_n\\right)$ in $A$ has a convergent subsequence $\\left(\\mathbf{v}_{n_j}\\right) \\to \\mathbf{v} \\in A$.\n\\end{defi}\n\n\\begin{eg}\n$R$ is not s.compact, since $\\left(n\\right)$ has no convergent subsequence.\n\\end{eg}\n\n\\begin{eg}\n$A=\\left(0,2\\right)$ is not s.compact, since $\\left(\\frac{1}{n}\\right) \\to 0 \\not\\in A$.\n\\end{eg}\n\n\\begin{prop}\nSuppose $A \\subset V$ is s.compact. Then $A$ is closed in $V$ and bounded.\n\\begin{proof}\nWe prove the contrapositive:\n\nIf $A$ is not closed, then there exists a sequence $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$ with $\\mathbf{v}_n \\in A$ for all $n$ but $\\mathbf{v} \\not\\in A$. By the exercise, any subsequence $\\left(\\mathbf{v}_{n_j}\\right)$ converges to $\\mathbf{v} \\not\\in A$. So $A$ is not s.compact.\n\nIf $A$ is not bounded, then for all $n \\in \\N$ we can find $\\mathbf{v}_n \\in A$ with $||\\mathbf{v}_n|| \\geq n$. We claim that $\\left(\\mathbf{v}_{n_j}\\right)$ has no convergent subsequence: if $\\left(\\mathbf{v}_{n_j}\\right) \\to \\mathbf{v}$, then $\\exists J$ s.t. $||\\mathbf{v}_{n_j} - \\mathbf{v}|| < 1$ for all $j > J$. So\n\\begin{equation*}\n\\begin{aligned}\n||v_{n_j}|| \\leq ||\\mathbf{v}|| + ||\\mathbf{v_{n_j}} - \\mathbf{v}|| \\leq ||\\mathbf{v}|| + 1\n\\end{aligned}\n\\end{equation*}\nfor all $j>J$, but this is impossible since $n_j\\geq j$, so $||v_{n_j}|| \\geq j \\to \\infty$ as $j \\to \\infty$.\n\nIt follows that $\\mathbf{v}_n$ has no convergent subsequence, so $A$ is not s.compact.\n\\end{proof}\n\\end{prop}\n\n\\begin{thm} (Heine-Borel) $A \\subset \\R^n$ is s.compact if and only if $A$ is closed and bounded.\n\\begin{proof}\nBy the proposition, $A$ is s.compact $\\implies$ $A$ is closed and bounded.\\\\\nConversely, suppose $A$ is closed and bounded, and $\\left(\\mathbf{v}_n\\right)$ is a sequence in $A$. Then $\\left(\\mathbf{v}_n\\right)$ is bounded (since $A$ is). So by B-W, it has a convergent subsequence. Since $A$ is closed, $\\mathbf{v} \\in A$. So $A$ is s.compact.\n\\end{proof}\n\\end{thm}\n\n\\begin{rem}\nBy previous example, $\\bar{B}_1\\left(0\\right)$ in $C\\left[0,1\\right]$ with $||\\cdot||_\\infty$ is closed and bounded but not s.compact since $\\left(f_n\\right)$ has no convergent subsequence. So Heine-Borel theorem does not hold in general spaces.\n\\end{rem}\n\n\\begin{rem} If $A \\subset V$ a normed space, then $A$ is s.compact $\\iff$ $A$ is compact.\n\\end{rem}\n\n\\begin{prop}\nSuppose $C \\subset V$ is s.compact and $f:C\\to W$ is continuous. Then $f\\left(C\\right)$ is s.compact.\n\\begin{proof}\nSuppose $\\left(\\mathbf{w}_n\\right)$ is a sequence in $f\\left(C\\right)$. Pick $\\mathbf{v}_n \\in C$ with $f\\left(\\mathbf{v}n\\right) = \\mathbf{w}_n$. We know $C$ is s.compact, so $\\left(\\mathbf{v}_n\\right)$ has a convergent subsequence $\\left(\\mathbf{v}_{n_j}\\right) \\to \\mathbf{v} \\in C$.\n\nNow $f$ is continuous, so $\\left(\\mathbf{w}_{n_j}\\right) = \\left(f\\left(\\mathbf{v}_{n_j}\\right)\\right) \\to \\left(f\\left(\\mathbf{v}\\right)\\right) \\in f\\left(C\\right)$. So $f\\left(C\\right)$ is s.compact.\n\\end{proof}\n\\end{prop}\n\nWe'll use the above to prove maximum value theorem.\n\n\\begin{lemma}\nIf $A \\subset \\R$ is closed and bounded, then $\\sup A\\in A$.\n\\begin{proof}\n$A$ is bounded, so $\\sup A$ exists. Pick $x_n \\in A$ with $\\sup A - \\frac{1}{n} \\leq x_n \\leq \\sup A$. Then $\\left(x_n\\right) \\to \\sup A$. The result follows since $A$ is closed.\n\\end{proof}\n\\end{lemma}\n\n\\begin{thm} (Maximum value theorem) Suppose $C$ is s.compact, $f:C\\to \\R$ is continuous. Then there exists $\\mathbf{v} \\in V$ s.t.\n\\begin{equation*}\n\\begin{aligned}\nf\\left(\\mathbf{v}\\right) \\geq f\\left(\\mathbf{v'}\\right)\n\\end{aligned}\n\\end{equation*}\nfor all $\\mathbf{v'} \\in C$.\n\\begin{proof}\nWe know $A = f\\left(C\\right)$ is a s.compact subset of $\\R$, so it is closed and bounded. So by the lemma, $\\sup A$ is in $A = f\\left(C\\right)$. So pick $\\mathbf{v}\\in C$ with $f\\left(\\mathbf{v}\\right) = \\sup A$.\n\\end{proof}\n\\end{thm}\n\nApplication: Norms on $\\R^n$:\n\nLet $||\\cdot||$ be a norm on $\\R^n$.\n\n\\begin{lemma}\nThe map id:$\\left(\\R^n,||\\cdot||_1\\right) \\to \\left(\\R^n,||\\cdot||\\right)$ is continuous.\n\\begin{proof}\nWrite $\\mathbf{v} = \\left(v_1,...,v_n\\right) = \\sum_{i=1}^n v_i \\mathbf{e}_i$. By the triangle inequality,\n\\begin{equation*}\n\\begin{aligned}\n||\\mathbf{v}|| \\leq \\sum_{i=1}^n ||v_i\\mathbf{e}_i|| = \\sum_{i=1}^n |v_i| ||\\mathbf{e}_i|| \\leq C \\sum_{i=1}^n |v_i| = C||\\mathbf{v}||_1\n\\end{aligned}\n\\end{equation*}\nWhere $C = \\max_{1\\leq i} \\leq n\\left\\{||\\mathbf{e}_j||\\right\\}$. By criterion of section 1.4, the given map is continuous.\n\\end{proof}\n\\end{lemma}\n\n\\begin{coro}\nThe map $f:\\left(\\R^n, ||\\cdot||_1\\right) \\to \\R$ given by $f\\left(\\mathbf{v}\\right) = ||\\mathbf{v}||$ is continuous.\n\\end{coro}\n\n\\begin{thm}\n$||\\cdot||$ is Lipschitz equivalent to $||\\cdot||_1$.\n\\begin{proof}\nLet $S = \\left\\{\\mathbf{v}\\in\\R^n \\mid ||\\mathbf{v}_1 = 1\\right\\} = g^{-1}\\left(\\left\\{1\\right\\}\\right)$, where $g\\left(\\mathbf{v}\\right) = ||\\mathbf{v}||_1$.\n\nNow $g:\\left(\\R^n,||\\cdot||_1\\right) \\to \\R$ is continuous, $\\left\\{1\\right\\}$ is closed in $\\R$, so $g^{-1}\\left(\\left\\{1\\right\\}\\right)$ is closed in $\\left(\\R^n,||\\cdot||_1\\right)$. $S$ is also obviously bounded in $\\left(\\R^n,||\\cdot||_1\\right)$. So $S$ is s.compact by Heine-Borel.\n\n$f:\\left(\\R^n,||\\cdot||_1\\right) \\to \\R$, $f\\left(\\mathbf{v}\\right) = ||\\mathbf{v}||$ is continuous by corollary. So by maximum value theorem, there exists $\\mathbf{v_\\pm} \\in S$ s.t.\n\\begin{equation*}\n\\begin{aligned}\nC_- = f\\left(\\mathbf{v}_-\\right) \\leq f\\left(\\mathbf{v}\\right) \\leq f\\left(\\mathbf{v}_+\\right) = C_+\n\\end{aligned}\n\\end{equation*}\nfor all $\\mathbf{v} \\in S$, i.e. $C_- \\leq \\mathbf{v} \\leq \\C_+$ for all $\\mathbf{v} \\in S$ where $C_- = ||\\mathbf{v}_-||>0$ since $\\mathbf{v}_- \\in S \\implies \\mathbf{v_-} \\neq \\mathbf{0} \\implies \\mathbf{v_-} \\neq 0$.\n\nThen for $\\mathbf{v} \\neq 0$ in $\\R^n$, $\\mathbf{v}/||\\mathbf{v}||_1 \\in S$. So\n\\begin{equation*}\n\\begin{aligned}\n0 < C_- \\leq ||\\frac{\\mathbf{v}}{||\\mathbf{v}||_1} \\leq C_+\n\\end{aligned}\n\\end{equation*}\ni.e.\n\\begin{equation*}\n\\begin{aligned}\nC_-||\\mathbf{v}||_1 \\leq ||\\mathbf{v}|| \\leq C_+ ||\\mathbf{v}||_1\n\\end{aligned}\n\\end{equation*}\nwhere $C_-,C_+ > 0$. So the two norms are Lipschitz equivalent.\n\\end{proof}\n\\end{thm}\n\n\\begin{coro}\nAny two norms on $\\R^n$ are Lipschitz equivalent.\n\\end{coro}\n\n\\subsection{Completeness}\nLet $V$ be a normed space, and let $\\left(\\mathbf{v}_n\\right)$ be a sequence in $V$.\n\n\\begin{defi}\nThe sequence $\\left(\\mathbf{v}\\right)_n$ is \\emph{Cauchy} if given $\\varepsilon > 0$, there exists $N$ s.t. $||\\mathbf{v}_n - \\mathbf{v}_m|| < \\varepsilon$ for all $n,m \\geq N$.\n\\end{defi}\n\n\\begin{eg}\nIf $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$, then $\\left(\\mathbf{v}_n\\right)$ is Cauchy.\n\\begin{proof}\nGiven $\\varepsilon>0$, pick $N$ s.t. $||\\mathbf{v}_n-\\mathbf{v}|| < \\frac{\\varepsilon}{2}$ for all $n \\geq N$. Then for $n,m \\geq N$, by triangle inequality,\n\\begin{equation*}\n\\begin{aligned}\n||\\mathbf{v}_n - \\mathbf{v}_m|| \\leq ||\\mathbf{v}_n - \\mathbf{v}||+||\\mathbf{v}-\\mathbf{v}_m|| < \\varepsilon\n\\end{aligned}\n\\end{equation*}\ni.e. $\\left(\\mathbf{v}_n\\right)$ is Cauchy.\n\\end{proof}\n\\end{eg}\n\n\\begin{eg}\nLet $s_n = \\sum_{i=1}^n \\frac{1}{i}$. Then $s_n$ diverges. Also it is not Cauchy, even though $|s_n - s_{n+1}| \\to 0$ as $n \\to \\infty$.\n\\end{eg}\n\nCauchy sequences \\emph{want} to converge.\n\n\\begin{eg}\nGiven $\\varepsilon>0$, pick $N$ s.t. $||\\mathbf{v}_n - \\mathbf{v}_m|| < \\varepsilon$ for all $n,m \\geq N$. Then all but finitely many terms of $\\left(\\mathbf{v}_n\\right)$ are contained in $B_\\varepsilon\\left(\\mathbf{v}_N\\right)$.\n\\end{eg}\n\nHowever they may not have an element of $V$ to converge to.\n\n\\begin{eg}\nLet $V=C\\left[0,1\\right]$ with $||\\cdot||_1$. Take\n\\begin{equation*}\n\\begin{aligned}\nf_n = \\left\\{\\begin{array}{ll}\n0 & x\\in\\left[0,1/2\\right]\\\\\nn\\left(x-1/2\\right) & x\\in\\left[1/2,1/2+1/n\\right]\\\\\n1 & x \\in \\left[1/2+1/n,1\\right]\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\n\n\\begin{tikzpicture}\n\\begin{axis}[xmin=0,xmax=1.5,ymin=0,ymax=1.5]\n\\addplot coordinates {\n\t(0,0)\n\t(0.5,0)\n\t(0.6,1)\n\t(1,1)\n};\n\\end{axis}\n\\end{tikzpicture}\n\n$f\\left(n\\right)$ is Cauchy:\\\\\nIf $m,n \\geq >N$, $|f_n\\left(x\\right) - f_m\\left(x\\right)| = 0$ if $x \\not\\in A_n = \\left[1/2,1/2+1/N\\right]$, and $<1$ if $x \\in A_N$. Then\n\\begin{equation*}\n\\begin{aligned}\n||f_n - f_m||_1 = \\int_0^1 |f_n\\left(x\\right) - f_m\\left(x\\right)| dx \\leq \\int_{1/2}^{1/2+1/N} 1 dx = \\frac{1}{N}\n\\end{aligned}\n\\end{equation*}\n\nso $\\left(f_n\\right)$ is Cauchy.\n\nNow let $$f\\left(x\\right) = \\left\\{\\begin{array}{ll}\n0 & x\\in\\left[0,1/2\\right]\\\\\n1 & x\\in\\left(1/2,1\\right]\n\\end{array}\n\\right.$$\nwhich is not in $C\\left[0,1\\right]$.\n\nIf $\\left(f_n\\right) \\to g \\in C\\left[0,1\\right]$ then $\\left(f_n\\right) \\to g$ with respect to $||\\cdot||_1$ on $\\left[0,1\\right] - A_n$ for any $N>0$. On the other hand, $\\left(f_n\\right) \\to f$ uniformly on $\\left[0,1\\right]-A_N$ for any $N>0$.\n\nOn the other hand, $\\left(f_n\\right) \\to f$ uniformly on $\\left[0,1\\right] - A_N$ for any $N>0$. So $\\left(f_n\\right) \\to f$ with respect to $||\\cdot||_1$ on $\\left[0,1\\right]-A_N$ for all $N>0$. Therefore $g\\left(x\\right) = f\\left(x\\right)$ for all $x \\in \\left[0,1\\right]$. Contradiction.\n\\end{eg}\n\n\\begin{defi}\nA normed space $V$ is \\emph{complete} if every Cauchy sequence $\\left(\\mathbf{v}_n\\right)$ in $V$ converges to a limit $\\mathbf{v} \\in V$.\n\\end{defi}\n\n\\begin{eg}\n$\\left(C\\left[0,1\\right],||\\cdot||_1\\right)$ is not complete.\n\\end{eg}\n\nApplication: Completeness of $\\R^n$.\n\nLet $V$ be a normed vector space, and suppose $\\left(\\mathbf{v}_n\\right)$ is a Cauchy sequence in $V$.\n\n\\begin{lemma}\n$\\left(\\mathbf{v}_n\\right)$ is bounded. (Exercise)\n\\end{lemma}\n\n\\begin{lemma}\nIf $\\left(\\mathbf{v}_n\\right)$ has a convergent subsequence $\\left(\\mathbf{v}_{n_i}\\right) \\to \\mathbf{v} \\in V$, then $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$.\n\\begin{proof}\nGiven $\\varepsilon>0$, pick $M$ s.t. $||\\mathbf{v}_n - \\mathbf{v}_m|| < \\frac{\\varepsilon}{2}$ whenever $n,m > M$. Now $\\mathbf{v}_{n_i}$ converges to $\\mathbf{v}$, so pick $I$ s.t. $||\\mathbf{v}_{n_i}-\\mathbf{v}|| < \\frac{\\varepsilon}{2}$ whenever $i>I$.\\\\\nSo choose $I'>I$ s.t. $n_{I'} \\geq M$. Then for $n>n_{I'}$,\n\\begin{equation*}\n\\begin{aligned}\n||\\mathbf{v}_n - \\mathbf{v}|| \\leq ||\\mathbf{v}_n - \\mathbf{v}_{n_{I'}}|| + ||\\mathbf{v}_{n_{I'}} - \\mathbf{v}|| < \\varepsilon\n\\end{aligned}\n\\end{equation*}\nSo $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$.\n\\end{proof}\n\\end{lemma}\n\n\\begin{thm}\n$\\R^n$ is complete.\n\\begin{proof}\nSuppose $\\left(\\mathbf{v}_n\\right)$ is a Cauchy sequence in $\\R^n$. By lemma 1, $\\left(\\mathbf{v}_n\\right)$ is bounded. By B-W, $\\left(\\mathbf{v}_n\\right)$ has a convergent subsequence $\\left(\\mathbf{v}_{n_i}\\right)\\to \\mathbf{v}$. By lemma 2, $\\left(\\mathbf{v}_n\\right) \\to \\mathbf{v}$, i.e. every Cauchy sequence converges. So $\\R^n$ is complete.\n\\end{proof}\n\\end{thm}\n\n\\begin{rem}\nIf $||\\cdot||$ and $||\\cdot||'$ are Lipschitz equivalent, then $\\left(\\mathbf{v}_n\\right)$ is Cauchy with respect to the two norms are equivalent. So Completeness with respect to the two norms are equivalent.\n\nSince all norms on $\\R^n$ are Lipschitz equivalent, the the theorem holds for any norm. \n\nWe saw $\\left(C\\left[0,1\\right],||\\cdot||_1\\right)$ is not complete. What about $\\left(C\\left[0,1\\right],||\\cdot||_\\infty\\right)$?\n\nBounded sequences need not have convergent subsequences.\n\\end{rem}\n\n\\begin{thm}\n$C\\left[0,1\\right]$ is complete with respect to $||\\cdot||_\\infty$.\n\\begin{proof}\nGiven a Cauchy sequence $\\left(f_n\\right)$, we must find $f\\in C\\left[0,1\\right]$ s.t. $\\left(f_n\\right) \\to f$ uniformly.\n\nGiven $\\varepsilon>0$, choose $N$ s.t. $||f_n-f_m||<\\varepsilon/2$ for all $n,m \\geq N.$ Then if $x \\in \\left[0,1\\right]$,\n\\begin{equation*}\n\\begin{aligned}\n|f_n\\left(x\\right) - f_m\\left(x\\right) &\\leq \\max_{x \\in \\left[0,1\\right]} |f_n\\left(x\\right) - f_m\\left(x\\right)|\\\\\n&= ||f_n-f_m||_\\infty\\\\\n&<\\varepsilon/2 < \\varepsilon\n\\end{aligned}\n\\end{equation*}\nFor $n,m \\geq N$.\n\nSo $\\left(f_n\\left(x\\right)\\right)$ is a Cauchy sequence in $\\R$. But $\\R$ is complete. So $\\lim_{n \\to \\infty} f_n\\left(x\\right)$ exists.\n\nDefine $f\\left(x\\right) = \\lim_{n\\to\\infty} f_n\\left(x\\right)$. Then $\\left(f_n\\right) \\to f$ pointwise.\n\nNow we want to prove $\\left(f_n\\right) \\to f$ uniformly. Given $\\varepsilon>0$, and $x \\in \\left[0,1\\right]$, pick $M$ (depending on $x$) s.t. $|f_n\\left(x\\right)-f\\left(x\\right) < \\varepsilon/2$ whenever $n\\geq M$.\n\nLet $R = \\max\\left(N,M\\right)$, then for $n\\geq N$,\n\\begin{equation*}\n\\begin{aligned}\n|f_n\\left(x\\right) - f\\left(x\\right)| &\\leq |f_n\\left(x\\right)-f_R\\left(x\\right)| + |f_R\\left(x\\right) - f\\left(x\\right)|\\\\\n&< \\varepsilon/2 + \\varepsilon/2 = \\varepsilon\n\\end{aligned}\n\\end{equation*}\nfor $n,R \\geq N$.\ni.e. $|f_n\\left(x\\right) - f\\left(x\\right)| < \\varepsilon$ for all $x \\in \\left[0,1\\right]$ i.e. $||f_n-f||_\\infty < \\varepsilon$.\\\\\nSo $\\left(f_n\\right) \\to f$ uniformly.\n\n$f_n\\in C\\left[0,1\\right] \\implies f\\in C\\left[0,1\\right]$. So $\\left(f_n\\right) \\to f\\in C\\left[0,1\\right]$ uniformly.\n\\end{proof}\n\\end{thm}\n\n\\subsection{Uniform continuity}\nSuppose $V,W$ are normed spaces, $A \\subset V$.\n\n\\begin{defi}\n$f:A \\to W$ is \\emph{uniformly continuous} if for every $\\varepsilon>0$, $\\exists \\delta > 0$ s.t. $||f\\left(\\mathbf{v}\\right) - f\\left(\\mathbf{v}'\\right) || < \\varepsilon$ whenever $||\\mathbf{v}-\\mathbf{v}'||<\\delta$.\n\\end{defi}\n\n\\begin{eg}\nLet $f:\\R \\to \\R$ by $f\\left(x\\right) = x^2$. Then $f\\left(x+\\delta\\right) - f\\left(x\\right) = 2x\\delta + \\delta^2$. For fixed $\\delta$, $2x\\delta+\\delta^2 \\to \\infty$ as $x \\to \\infty$. So $f\\left(x\\right) =x^2$ is not uniformly continuous.\n\\end{eg}\n\n\\begin{eg}\nLet $f:\\left(0,1\\right] \\to \\R$ with $f\\left(x\\right) = \\frac{1}{x}$. This is not uniformly continuous as well (consider $x \\to 0$).\n\\end{eg}\n\n\\begin{thm}\nIf $C$ is s.compact, and $f:C \\to W$ is continuous, then $f$ is uniformly continuous.\n\\begin{proof}\nSuppose $f$ is not uniformly continuous. Then there exists $\\varepsilon>0$ s.t. for all $n>0$ we can find $\\mathbf{v}_n,\\mathbf{w}_n\\in C$ with $||\\mathbf{v}_n-\\mathbf{w}_n|| < \\frac{1}{n}$, and $||f\\left(\\mathbf{v}_n\\right)-f\\left(\\mathbf{w}_n\\right)|| \\geq \\varepsilon$ (else $f$ is uniformly continuous).\n\nSince $C$ is s.compact, $\\left(\\mathbf{v}_n\\right)$ has a convergent subsequence $\\left(\\mathbf{v}_{n_i}\\right) \\to \\mathbf{v^*} \\in C$.\n\n$f$ is continuous and $\\mathbf{v}^* \\in C$, so $\\exists \\delta > 0$ s.t. $||f\\left(\\mathbf{v}\\right)-f\\left(\\mathbf{v^*}\\right)|| < \\varepsilon/2$ whenever $\\mathbf{v}\\in B_\\delta\\left(\\mathbf{v^*}\\right)$.\n\nIf $\\mathbf{v},\\mathbf{v'} \\in B_\\delta\\left(\\mathbf{v^*}\\right)$, then\n\\begin{equation*}\n\\begin{aligned}\n||f\\left(\\mathbf{v}\\right) - f\\left(\\mathbf{v}'\\right) || &\\leq ||f\\left(\\mathbf{v}\\right)-f\\left(\\mathbf{v}^*\\right)|| + ||f\\left(\\mathbf{v}^*\\right)-f\\left(\\mathbf{v}'\\right)||\\\\ &< \\varepsilon/2+\\varepsilon/2 = \\varepsilon\n\\end{aligned}\n\\end{equation*}\n$\\left(\\mathbf{v}_{n_i}\\right) \\to \\mathbf{v}^*$, so pick $I_1$ s.t. $||\\mathbf{v}_{n_i} - \\mathbf{v}^*|| < \\delta/2$ when $i \\geq I_1$.\n\nPick $I_2$ s.t. $1/I_2 < \\delta/2$. Then for $i \\geq \\max\\left(I_1,I_2\\right)$, we have $||\\mathbf{v}_{n_i} - \\mathbf{v}^*|| < \\delta/2$ and $||\\mathbf{v}_{n_i} - \\mathbf{w}_{n_i} || < \\frac{1}{n_i} < \\frac{1}{i} < \\frac{1}{I_2} < \\frac{\\delta}{2}$.\n\nSo $||\\mathbf{w}_{n_i} - \\mathbf{v}^*|| < ||\\mathbf{w}_{n_i} - \\mathbf{v}_{n_i}|| + ||\\mathbf{v}_{n_i} - \\mathbf{v}^*|| < \\delta/2+\\delta/2 = \\delta$, i.e. $\\mathbf{w}_{n_i},\\mathbf{v}_{n_i} \\in B_\\delta \\left(\\mathbf{v}^*\\right)$, $||f\\left(\\mathbf{v}_{n_i}\\right) - f\\left(\\mathbf{w}_{n_i}\\right)|| \\geq \\varepsilon$. Contradiction. So $f$ must be uniformly continuous.\n\\end{proof}\n\\end{thm}\n\n\\subsection{Application: Integration}\nRecall from Analysis I:\nWe say $f: \\left[a,b\\right] \\to \\R$ is piecewise constant if $\\exists a=a_0<a_1<...<a_n=b$ and $c_1,...,c_n \\in \\R$ s.t. $f\\left(x\\right) = c_i$ if $x\\in \\left(a_{i-1},a_i\\right)$.\n\n\\begin{tikzpicture}\n\\begin{axis}[xmin=0,xmax=1.5,ymin=0,ymax=1.5]\n\\addplot coordinates {\n\t(0.2,0.5) (0.5,0.5)\n\t\n\t(0.5,1) (1,1)\n\t\n\t(1,0.2) (1.2,0.2)\n};\n\\end{axis}\n\\end{tikzpicture}\n\nLet $P\\left[a,b\\right] = \\left\\{ f:\\left[a,b\\right] \\to \\R \\mid f \\text{ is piecewise constant} \\right\\}$. If $f \\in P\\left[a,b\\right]$ is as above, then\n\\begin{equation*}\n\\begin{aligned}\nI\\left(f\\right) = \\sum_{i=1}^n c_i \\left(a_i - a_{i-1}\\right) = \"\\int\" f\n\\end{aligned}\n\\end{equation*}\n\n\\begin{lemma}\nIf $f,g \\in P\\left[a,b\\right]$, $\\lambda \\in \\R$, then\n\\begin{equation*}\n\\begin{aligned}\nf-\\lambda g \\in P\\left[a,b\\right]\n\\end{aligned}\n\\end{equation*}\nand $I\\left(f-\\lambda g\\right) = I\\left(f\\right) - \\lambda I\\left(g\\right)$.\n\\end{lemma}\n\nWrite $f\\geq g$ if $f\\left(x\\right) \\geq g\\left(x\\right)$ for all $x\\in\\left[a,b\\right]$.\n\n\\begin{lemma}\nIf $f\\geq 0$, $I\\left(f\\right) \\geq 0$.\n\\end{lemma}\n\nSo if $f,g\\in P\\left[a,b\\right], f\\geq g$, then $I\\left(f\\right) \\geq I\\left(g\\right)$.\n\n\\begin{defi} (Riemann Integral) Suppose $f:\\left[a,b\\right] \\to \\R$ is bounded. Let\n\\begin{equation*}\n\\begin{aligned}\n\\mathcal{U}\\left(f\\right) = \\left\\{ g\\in P\\left[a,b\\right] \\mid g\\geq f\\right\\},\\\\\n\\mathcal{L}\\left(f\\right) = \\left\\{ g\\in P\\left[a,b\\right] \\mid g\\leq f\\right\\}\n\\end{aligned}\n\\end{equation*}\nsince $f$ is bounded, these are not empty.\\\\\nLet \n\\begin{equation*}\n\\begin{aligned}\nU\\left(f\\right) = \\left\\{I\\left(g\\right) \\mid g \\in \\mathcal{U}\\left(f\\right)\\right\\},\\\\\nL\\left(f\\right) = \\left\\{I\\left(g\\right) \\mid g \\in \\mathcal{L}\\left(f\\right)\\right\\}\n\\end{aligned}\n\\end{equation*}\n\nIf $g^+ \\in \\mathcal{U}\\left(f\\right)$ and $g^- \\in \\mathcal{L}\\left(f\\right)$, then $g^+ \\geq f \\geq g^-$. So $I\\left(g^+\\right) \\geq I\\left(g^-\\right)$. If $u \\in U\\left(f\\right)$ and $l \\in L\\left(f\\right)$, then $u \\geq l$. So $U\\left(f\\right)$ is bounded below, $L\\left(f\\right)$ is bounded above.\n\nNow let \n\\begin{equation*}\n\\begin{aligned}\nu\\left(f\\right) = \\inf U\\left(f\\right),\\\\\nl\\left(f\\right) = \\inf L\\left(f\\right)\n\\end{aligned}\n\\end{equation*}\n\nNote that $u\\left(f\\right) \\geq l\\left(f\\right)$.\n\nWe say $f$ is Riemann integrable if $u\\left(f\\right) = l\\left(f\\right)$, in which case we define \n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f\\left(x\\right) dx = u\\left(f\\right) = l\\left(f\\right)\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\n\nIf $f \\in P\\left[a,b\\right]$, then $u\\left(f\\right) = I\\left(f\\right) = l\\left(f\\right)$, so $f$ is RI.\n\n\\begin{thm}\nIf $f\\in C\\left[a,b\\right]$, then $f$ is RI.\n\\end{thm}\n\n\\begin{lemma}\nGiven $\\varepsilon>0$, $\\exists g^+ \\in \\mathcal{U}\\left(f\\right)$ and $g^- \\in \\mathcal{L}\\left(f\\right)$ s.t. $I\\left(g^+\\right) - I\\left(g^-\\right) < \\varepsilon$.\n\\begin{proof}\n$\\left[a,b\\right]$ is closed and bounded in $\\R$, so it is s.compact. By last lecture's theorem, $f: \\left[a,b\\right] \\to \\R$ is uniformly continuous.\\\\\nSo pick $\\delta$ s.t.\n\\begin{equation*}\n\\begin{aligned}\n|f\\left(x\\right) - f\\left(y\\right) | < \\frac{\\varepsilon}{b-a}\n\\end{aligned}\n\\end{equation*}\nwhenever $|x-y| < \\delta$. Choose $a=a_0<a_1<...<a_n = b$ such that $a_{i+1}-a_i < \\delta$ for all $i$.\n\nDefine\n\\begin{equation*}\n\\begin{aligned}\nc_i^+ = \\max_{x\\in\\left[a_{i-1},a_i\\right]} f\\left(x\\right),\\\\\nc_i^- = \\min_{x\\in\\left[a_{i-1},a_i\\right]} f\\left(x\\right)\n\\end{aligned}\n\\end{equation*}\n(These exist by Maximum value theorem) So \n\\begin{equation*}\n\\begin{aligned}\nc_i^+ = f\\left(x^+\\right) \\geq f\\left(x^-\\right) \\forall x \\in \\left[a_{i-1},a_i\\right],\\\\\nc_i^- = f\\left(x^-\\right) \\leq f\\left(x\\right) \\forall x\\in\\left[a_{i-1},a_i\\right]\n\\end{aligned}\n\\end{equation*}\n$x^+,x^- \\in \\left[a_{i-1},a_i\\right] \\implies |x^+ - x^-| < \\delta$.\n\nDefine \n\\begin{equation*}\n\\begin{aligned}\ng^+\\left(x\\right) = c_i^+ \\text{ if } x \\in \\left[a_{i-1},a_i\\right),\\\\\ng^-\\left(x\\right) = c_i^- \\text{ if } x \\in \\left[a_{i-1},a_i\\right)\n\\end{aligned}\n\\end{equation*}\nThen $|x^+ - x^-| < \\delta \\implies c_i^+ - c_i^- < \\frac{\\varepsilon}{b-a}$ for all $i$. So to sum up, $g^+ \\geq f \\geq g^-$ and $g^+ - g^- \\leq \\frac{\\varepsilon}{b-a}$.\\\\\nThus $g^+ \\in \\mathcal{U}\\left(f\\right)$, $g^- \\in \\mathcal{L}\\left(f\\right)$, and \n\\begin{equation*}\n\\begin{aligned}\nI\\left(g^+\\right) - I\\left(g^-\\right) = I\\left(g^+-g^-\\right) \\leq I\\left(\\frac{\\varepsilon}{b-a}\\right) = \\varepsilon\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{lemma}\n\nNow prove the theorem:\n\\begin{proof}\n$I\\left(g^+\\right) \\geq u\\left(f\\right) \\geq l\\left(f\\right) \\geq I\\left(g^-\\right)$. So $u\\left(f\\right) - l\\left(f\\right) \\leq I\\left(g^+\\right) - I\\left(g^-\\right) < \\varepsilon$ for all $\\varepsilon>0$, which implies $u\\left(f\\right) = l\\left(f\\right)$.\n\\end{proof}\n\n\\begin{coro}\nIf $f \\in C\\left[a,b\\right]$, $\\exists f_k \\in P\\left(a,b\\right)$ s.t. $\\left(f_k\\right) \\to f$ uniformly on $\\left[a,b\\right]$.\n\\begin{proof}\nFor each $k$, choose $g_k^+$ as in the proof of lemma with $\\varepsilon = \\frac{1}{k}$. Then $\\left(g_k^+\\right) \\to f$ uniformly.\n\\end{proof}\n\\end{coro}\n\n\\begin{eg}(Speed and Distance)\nSuppose $f\\left[a,b\\right] \\to \\R^n$ is continuous. $f\\left(t\\right) = \\left(f_1\\left(t\\right),...,f_n\\left(t\\right)\\right)$ where all $f_i$ are continuous.\\\\\nDefine $\\int_a^b f\\left(t\\right) dt = \\left(f_1\\left(t\\right) dt, ..., \\int_a^b f_n\\left(t\\right) dt\\right)$ (Integrating pointwise).\n\nIf $f\\left(t\\right) = \\mathbf{v}\\left(t\\right) = $velocity of a particle in $\\R^n$ at time $t$, then $\\mathbf{p}\\left(b\\right) - \\mathbf{p}\\left(a\\right) = \\int_a^b f\\left(t\\right) dt$ is the displacement of particle from its position at $t=a$. $||\\mathbf{v}\\left(t\\right)||$ is the speed of particle.\n\\end{eg}\n\n\\begin{prop}\nIf $f: \\left[a,b\\right] \\to \\R^n$ is continuous, then\n\\begin{equation*}\n\\begin{aligned}\n||\\int_a^b f\\left(t\\right) dt|| \\leq \\int_a^b ||f\\left(t\\right)|| dt\n\\end{aligned}\n\\end{equation*}\n\\end{prop}\n\n\\begin{lemma}\nIf $x_i,y_i \\in \\R$ satisfy:\\\\\n(1) $x_i \\leq y_i$ for all $i$;\\\\\n(2) $\\left(x_i\\right) \\to x$ and $\\left(y_i\\right) \\to y$\\\\\nThen $x \\leq y$.\n\\begin{proof}\n$y_i - x_i \\geq 0, \\left(y_i-x_i\\right) \\to y-x \\implies y-x\\geq 0$.\n\\end{proof}\n\\end{lemma}\n\n\\begin{lemma}\nThe proposition holds if $f$ is piecewise constant (maybe not continuous).\n\\begin{proof}\nSuppose $f\\left(t\\right) = \\mathbf{v}_i$ for $t\\in\\left(a_{i-1},a_i\\right)$. Then\n\\begin{equation*}\n\\begin{aligned}\n||\\int_a^b f\\left(t\\right) dt || &= ||I\\left(f\\right)||\\\\\n&= ||\\sum_{i=1}^n \\left(a_{i+1}-a_i\\right)\\mathbf{v}_i||\\\\\n&\\leq \\sum_{i=1}^n \\left(a_i-a_{i-1}\\right) ||\\mathbf{v}_i||\\\\\n&= I\\left(||f||\\right)\\\\\n&= \\int_a^b ||f|| dt.\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{lemma}\n\nProof of proposition:\n\\begin{proof}\nChoose a sequence of piecewise constant functions $f_k: \\left[a,b\\right] \\to \\R^n$ s.t. $\\left(f_k\\right) \\to f$ uniformly.\\\\\nThen\n\\begin{equation*}\n\\begin{aligned}\n\\int_a^b f_k \\to \\int_a^b f\n\\end{aligned}\n\\end{equation*}\n(uniformly convergence $\\implies$ $L^1$ convergence) and\n\\begin{equation*}\n\\begin{aligned}\n\\left(\\left|\\left|\\int_a^b f_k\\right|\\right|\\right) \\to \\left(\\left|\\left|\\int_a^b f\\right|\\right| \\right)\n\\end{aligned}\n\\end{equation*}\nsince $||\\cdot||$ is continuous.\n\nAlso $\\left(||\\mathbf{f}_k||\\right) \\to ||f||$ uniformly ($||\\cdot||$ is continuous). So\n\\begin{equation*}\n\\begin{aligned}\n\\left(\\int_a^b ||f_k||\\right) \\to \\int_a^b ||f||\n\\end{aligned}\n\\end{equation*}\n\nSo now take $x_k = ||\\int_a^b f_k||, x=||\\int_a^b f||, y_k = \\int_a^b ||f_k||, y=\\int_a^b ||f||$.\n\nThen $x_k \\leq y_k$, so $x \\leq y$.\n\\end{proof}\n\n\\newpage\n\n\\section{Differentiation}\nSlogan: \\emph{The derivative is a linear map}.\n\n\\subsection{Derivative}\n\\begin{defi}\nLet $U\\subset \\R^n$ be open, $f:U-\\left\\{x_0\\right\\}\\to \\R^m$. We say\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{x\\to x_0} f\\left(x\\right)=y\n\\end{aligned}\n\\end{equation*}\nif the function $\\bar{f}:U \\to \\R^m$ given by\n\\begin{equation*}\n\\begin{aligned}\n\\bar{f}\\left(x\\right) = \\left\\{\\begin{array}{ll}\nf\\left(x\\right) & x \\neq x_0\\\\\ny & x=x_0\n\\end{array}\\right.\n\\end{aligned}\n\\end{equation*}\nis continuous at $x_0$.\n\nNote that we don't care which norms on $\\R^n$ or $\\R^m$ we use: all the norms on $\\R^n$ are Lipschitz equivalent, so they determine the same continuous functions.\n\\end{defi}\n\n\\begin{defi}\nSuppose $U \\subset \\R^n$ is open, $x_0 \\in U$ and $f:U\\to \\R^m$. We say $f$ is differentiable at $x_0$ if there is a linear map $L:\\R^n \\to \\R^m$ s.t.\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{v\\to 0} \\frac{f\\left(x_0+v\\right)-(f(x_0)+L(v))}{||v||} = 0\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\n\nIf such an $L$ exists, it is unique.\n\\begin{proof}\nSuppose $L_1,L_2$ exist. Subtracting the two limit equations gives\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{v \\to 0} \\frac{L_2(v)-L_1(v)}{||v||} = 0\n\\end{aligned}\n\\end{equation*}\nIf $v \\in \\R^n$, $v\\neq 0$, then $tv \\to 0$ as $t\\to 0^+$. So\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{t\\to 0^+} \\frac{L_2(tv)-L_1(tv)}{||tv||} = 0\n\\end{aligned}\n\\end{equation*}\nSince $L_1,L_2$ are linear maps, simplify that and we get $L_2(v)=L_1(v)$. But $v$ is arbitrary. So $L_1=L_2$.\n\\end{proof}\n\nWhen the equation in the definition of differentiability holds, we say\n\\begin{equation*}\n\\begin{aligned}\nDf|_{x_0} = L\n\\end{aligned}\n\\end{equation*}\nis the \\emph{derivative} of $f$ at $x_0$. Note that $Df|_{x_0}$ is a \\emph{linear map} from $\\R^n$ to $\\R^m$.\n\nEquivalently, $f$ is differentiable at $x_0$ with $Df|_{x_0}=L$ if \n\\begin{equation*}\n\\begin{aligned}\nf(x_0+v)=f(x_0)+L(v)+||v||\\alpha(v)\n\\end{aligned}\n\\end{equation*}\nwhere $\\lim_{v\\to 0} \\alpha(v) = 0$.\n\n\\begin{prop}\nSuppose $f:U\\to \\R^m$ is differentiable at $x_0 \\in U$. Then $f$ is continuous at $x_0$.\n\\end{prop}\n\n\\begin{lemma}\nSuppose $L:\\R^n \\to (W,||\\cdot||)$ is a linear map where $W$ is a normed space. Then $\\lim_{v \\to 0} L(v) = 0$.\n\\end{lemma}\n\nNote that the lemma is false if $\\R^n$ is replaced by an arbitrary normed space.\n\n\\begin{proof}\nLet $v=(v_1,...,v_n) = \\sum_{i=1}^n v_i e_i$. Then\n\\begin{equation*}\n\\begin{aligned}\n||L(v)||&=||\\sum_{i=1}^n v_i L(e_i)||\\\\\n&\\leq \\sum_{i=1}^n |v_i| \\cdot ||L(e_i)||\\\\\n&\\leq C\\sum_{i=1}^n |v_i| \\\\\n&= C||v||_1\n\\end{aligned}\n\\end{equation*}\nWhere $C=\\max \\{||L(e_1)||,...,||L(e_n)||\\}$.\n\nGiven $\\varepsilon>0$, pick $\\delta > \\varepsilon/C$. If $||v||_1 < \\delta$ then $||L(v)||<\\varepsilon$, so $\\lim_{v\\to 0}L(v) = 0$.\n\\end{proof}\n\nProve of proposition:\n\\begin{proof}\nSince $f$ is differentiable at $x_0$, we have\n\\begin{equation*}\n\\begin{aligned}\nf(x_0+v) = f(x_0)+L(v)+||v||\\alpha(v)\n\\end{aligned}\n\\end{equation*}\nwhere $\\lim_{v\\to 0} \\alpha(v) = 0$. Now take the limit $v \\to 0$ of both sides we have\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{v\\to 0} f(x_0+v) = f(x_0)\n\\end{aligned}\n\\end{equation*}\nSo $f$ is continuous at $x_0$.\n\\end{proof}\n\n\\subsection{The derivative as a matrix}\nSuppose $U \\subset \\R^n$ is open, $f:U \\to \\R^m$.\n\nWe say $f$ is differentiable if $f$ is differentiable at all $x \\in U$.\n\nIf so, we have $Df:U \\to \\mathcal{L}(\\R^n,\\R^m)$.\n\nFrom Linear Algebra we know that there is a bijection between $\\mathcal{L}(\\R^n,\\R^m)$ and the set of $m\\times n$ real matrix:\n\\begin{equation*}\n\\begin{aligned}\n[a_{ij}] \\longleftrightarrow L(e_j) = \\sum a_{ij} e_i\n\\end{aligned}\n\\end{equation*}\n\nNow let's consider given $f:U \\to \\R^m$, how we compute $Df=[a_{ij}(x)]$. We first reduce to the case $m=1$ by writing\n\\begin{equation*}\n\\begin{aligned}\nf(x) = (f_1(x),...,f_n(x))\n\\end{aligned}\n\\end{equation*}\nThen think about $F:U \\to \\R$.\n\n\\begin{prop}\n$f$ is differentiable at $x_0$ if and only if $f_i$ is differentiable for all $1\\leq i \\leq m$. If so,\n\\begin{equation*}\n\\begin{aligned}\nDf|_{x_0} = (Df_1|_{x_0},...,Df_m|_{x_0}).\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nSuppose $g: U \\to \\R^m$. Using the uniform norm on $\\R^m$, we see that $\\lim_{v\\to 0} g(v) = 0$ iff $\\lim_{v \\to 0} g_i(v) = 0$ for all $1 \\leq i \\leq m$.\n\nNow let $L: \\R^n \\to \\R^m$. Then\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{v\\to 0} \\frac{f(x_0+v)-(f(x_0)+L(v))}{||v||} = 0\n\\end{aligned}\n\\end{equation*}\nif and only if\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{v\\to 0} \\frac{f_i(x_0+v)-(f_i(x_0)+L_i(v))}{||v||} = 0\n\\end{aligned}\n\\end{equation*}\nfor all $1 \\leq i \\leq m$, i.e. $f_i$ is differentiable at $x_0$ and $Df_i|_{x_0} = L_i$.\n\\end{proof}\n\\end{prop}\n\nSummary: \n\\begin{equation*}\n\\begin{aligned}\nDf|_{x_0} = \\left[\\begin{array}{ll}\nDf_1|_{x_0}\\\\\n...\\\\\nDf_m|_{x_0}\n\\end{array}\\right]\n\\end{aligned}\n\\end{equation*}\nwhere $Df_i|_{x_0} : \\R^n \\to \\R$ is a $1 \\times n$ matrix $[a_1,...,a_n]$.\n\n\\begin{defi} (Directional Derivative)\\\\\nSuppose $F:U\\to\\R$. If $v \\in \\R^n$, the \\emph{directional derivative} of $F$ in direction $v$ at $x$ is\n\\begin{equation*}\n\\begin{aligned}\nD_v F|_x &= \\lim_{t \\to 0} \\frac{F(x+tv)-F(x)}{t}\\\\\n&= \\frac{d}{dt} (F(x+tv))|_{t=0}\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\n\n$D_v F$ measures the rate of change of $F$ if I walk away from $x$ at velocity $v$.\n\nIt's also helpful to consider\n\\begin{equation*}\n\\begin{aligned}\nD_v^+ F = \\lim_{t \\to 0^+} \\frac{F(x+tv)-F(x)}{t}\n\\end{aligned}\n\\end{equation*}\nand similarly for $D_v^- F$. We can prove that\n\\begin{equation*}\n\\begin{aligned}\nD_v^- F|_x = -D_{-v}^+ F|_x\n\\end{aligned}\n\\end{equation*}\n\nNote: $D_v F$ exists iff $D_v^+ F, D_v^- F$ both exist and are equal.\n\n\\begin{eg}\nConsider a special case $v=e_i$. Then\n\\begin{equation*}\n\\begin{aligned}\nD_i F|_x &= \\frac{\\partial F}{\\partial x_i}|_x\\\\\n&=D_{e_i}F|_x\\\\\n&=\\frac{d}{dt} (F(x_1,...,x_i+t,...,x_n))|_{t=0}\\\\\n&= \\frac{d}{dt} (F(x_1,...,x_{i-1},t,x_{i+1},...,x_n))|_{t=x}\n\\end{aligned}\n\\end{equation*}\nis the $i$th partial derivative of $F$.\n\\end{eg}\n\n\\begin{prop}\nIf $F: U \\to \\R$ is differentiable at $x$, then $D_v F|_x = DF|_x(v)$.\n\\begin{proof}\nIf $v=0$ then both sides are $0$.\n\nIf $v \\neq 0$, then $tv \\to 0$ as $t \\to 0^+$, so differentiability of $F$ implies\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{t \\to 0^+} \\frac{F(x+tv)-((F(x)+L(tv))}{||tv||} = 0\n\\end{aligned}\n\\end{equation*}\nwhere $L=DF|_{x}$. So\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{t\\to 0^+}\\frac{F(x+tv)-F(x)}{t} - L(v) = 0\n\\end{aligned}\n\\end{equation*}\ni.e. $D_v^+ F|_x = DF|_x(v)$. Then $D_v^-F|_x = -D_{-v}^+ F|_x = -L(-v)=L(v)$.\n\\end{proof}\n\\end{prop}\n\nIf $DF|_x = [a_1,...,a_n]$ then $a_i = DF|_x(e_i) = D_{e_i} F|_x = D_i F|_x$. So we have\n\\begin{equation*}\n\\begin{aligned}\nDF|_x = [D_1F|_x,...,D_n F|_x]\n\\end{aligned}\n\\end{equation*}\n\nSummary: if $f:\\R^n \\to \\R^m$, then\n\\begin{equation*}\n\\begin{aligned}\nDf = \\left[\\begin{array}{ll}\nDf_1\\\\\n...\\\\\nDf_m\n\\end{array}\\right]=[D_jf_i]\n\\end{aligned}\n\\end{equation*}\n\n\\begin{eg}\nLet $f:\\R^3 \\to \\R^2$ with $f(x,y,z)=(x^2+y^2+z^2,xyz)$. Then\n\\begin{equation*}\n\\begin{aligned}\nDf = \\left[\\begin{matrix}\n1 & 2y & 3z^2\\\\\nyz & xz & xy\n\\end{matrix}\\right]\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\n\nNote: Just because $D_i F_x$ all exists doesn't mean that $F$ is differentiable at $x$.\n\n\\begin{eg}\nLet $F:\\R^2 \\to \\R$ be given by\n\\begin{equation*}\n\\begin{aligned}\nF(x,y) = \\left\\{\n\\begin{array}{ll}\n0 & xy=0\\\\\nH(x,y) & \\text{ otherwise}\n\\end{array}\\right.\n\\end{aligned}\n\\end{equation*}\nwhere $H(x,y)$ is any arbitrary horrible function. Then\n\\begin{equation*}\n\\begin{aligned}\nD_1F|_0 = D_2F|_0 = 0\n\\end{aligned}\n\\end{equation*}\nbut $F$ may not even be continuous.\n\\end{eg}\n\nWe can even have $D_v F$ well defined for every $v$, but $F$ is not differentiable.\n\\begin{eg}\nLet $S^1 = \\{v \\in \\R^2 | ||v||=1\\}$. Choose $h:S  \\to \\R$ to be any function. Define $F: \\R^2 \\to \\R$ by\n\\begin{equation*}\n\\begin{aligned}\nF(v)=\\left\\{\\begin{array}{ll}\n||v||h(\\frac{v}{||v||}) & v \\neq 0\\\\\n0 & v = 0\n\\end{array}\\right.\n\\end{aligned}\n\\end{equation*}\nThen $D_v^+ F|_0 = ||v||h(\\frac{v}{||v||})$. If we let $h(-v)=-h(v)$ then $D_v^+ F = D_v^- F$, so $D_v F$ is well defined. Now if $F$ is differentiable, $D_v F|_0 = DF|_0(v)$, so $h(v)$ would have to be a linear function on $S^1$; but $h$ is arbitrary except the one condition above.\n\\end{eg}\n\nA criterion for differentiability:\nLet $U \\subset \\R^n$ be open.\n\n\\begin{defi}\n$C^1(U)=\\{f:U \\to \\R|$ for $1 \\leq i \\leq n$, the partial derivative $D_i f|_x$ exists for all $x \\in U$ and is a continuous function of $x\\}$.\n\\end{defi}\n\n\\begin{eg}\n\\begin{equation*}\n\\begin{aligned}\nF(x,y,z) = e^{\\cos x^2y+z}-y^2z \\in C^1(\\R^3)\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\n\n\\begin{thm}\nIf $F \\in C^1(U)$, then $F$ is differentiable on $U$.\nTools used in proof:\\\\\n$\\bullet$ Alternative characterisation of differentiability in 4.1;\\\\\n$\\bullet$ If $\\lim_{v\\to 0} g(v) = w_0$ and $\\lim_{v\\to w_0} f(v)=z$, then $\\lim_{v \\to 0}f(g(v)) = z$;\\\\\n$\\bullet$ Suppose $b: U \\to \\R$ is bounded on $B_r(v_0)$ for some $r>0$. Then $\\lim_{v \\to v_0} b(v)\\alpha(v)=0$ if $\\lim_{v\\to v_0} \\alpha(v) = 0$.\n\\begin{proof} (of the bullet point):\\\\\nSince $b$ is bounded, there exists $M \\in \\R$ s.t. $|b(x)| \\leq M$ for all $v \\in B_r(v_0)$. Since $\\lim_{v \\to 0} \\alpha(v)=0$, given $\\varepsilon>0$, there exists $\\delta > 0$ s.t. $||\\alpha(v)||<\\frac{\\varepsilon}{M}$ whenever $v \\in B_\\delta(v_0)$. Then let $\\delta' = \\min(\\delta,r)$. We have $||b(v)\\alpha(v)|| = ||b(v)||||\\alpha(v)||<\\varepsilon$ for $v \\in B_\\delta(v_0)$. So $\\lim_{v \\to v_0} b(v)\\alpha(v) = 0$.\n\\end{proof}\n\\begin{proof} (for $n=2$)\\\\\nWe want to estimate $F(x+v)-F(x)$ for small $v$. Since $U$ is open, $\\exists r>0$ s.t. $B_r(x) \\subset U$.\n\nFrom now on we assume $||v||<r$ (since $v$ is small that's reasonable). So $x' \\in U$. Since $D_1 F$ exists, we write\n\\begin{equation*}\n\\begin{aligned}\nF(x')-F(x) = F(x_1+v_1,x_2)-F(x_1,x_2) = v_1DF|_x + |v_1|\\alpha_1(v_1)\n\\end{aligned}\n\\end{equation*}\nwhere $\\lim_{v_1 \\to 0} \\alpha_1(v_1) = 0$.\nSimilarly\n\\begin{equation*}\n\\begin{aligned}\nF(x+v)-F(x')=v_2 \\cdot D_2 F|_x + |v_2| \\alpha_2(v_2)\n\\end{aligned}\n\\end{equation*}\nwhere $\\lim_{v_2 \\to 0} \\alpha_2(v_2) = 0$.\\\\\n\\textit{\\textbf{Mistake!}} Here $\\alpha_2(v_2)$ depends on $v_1$.\n\nInstead, apply 1-variable mean value theorem to $f(t)=F(x_1+v_1,x_2+t)$ to write\n\\begin{equation*}\n\\begin{aligned}\nF(x+v)-F(x')=v_2D_2F|_{x''(v)}\n\\end{aligned}\n\\end{equation*}\nwhere $x''(v)=(x_1+v_1,x_2+h(v))$ where $0<h(v)<v_2$. Then as before, we can add to get\n\\begin{equation*}\n\\begin{aligned}\nF(x+v)-F(x)=L(v)+||v||E(v)\n\\end{aligned}\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\begin{aligned}\nE(v)&=\\frac{|v_1|}{||v||}\\alpha_1(v_1)&+&\\frac{|v_2|}{||v||}(D_2 F|_{x'(v)}-D_2F|_x)\n\\\\&=E_2(v) &+& E_1(v)\n\\end{aligned}\n\\end{equation*}\n\nNote that $||x''(v)-x||_2 = (v_1^2+h(v)^2)^{0.5} \\leq ||v||_2$. So $\\lim_{v \\to 0} x''(v) = x$.\n\nNow $D_2 F$ is continuous, so $\\lim_{v \\to 0} D_2 F|_{x''} - D_2 F|_x = 0$.\n\nWe'll show that as $v\\to 0$, $E_1(v),E_2(v) \\to 0$, then we are done.\n\n$\\bullet$ $E_1$: As $v \\to 0$, $x' \\to x$. Now $D_2 F$ is continuous, so \n\\begin{equation*}\n\\begin{aligned}\n\\lim_{x' \\to x}(D_2 F|_{x'}-D_2 F|_x) = 0\n\\end{aligned}\n\\end{equation*}\nSo\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{v \\to 0} (D_2 F|_{x'}-D_2 F|_x) = 0\n\\end{aligned}\n\\end{equation*}\nNow $\\frac{|v_2|}{||v||}<1$ for all $v \\in \\R^2 \\backslash \\{0\\}$, so by lemma $E_1\\to 0$.\n\n$\\bullet$ $E_2$: $\\lim_{v\\to 0} v_1 = 0$ and $\\lim_{v_1\\to 0} \\alpha (v_1)=0$, so $\\lim_{v \\to 0} \\alpha_1(v_1) = 0$. Same as above we get $E_2 \\to 0$.\n\n(Refer to DC notes last page of Section 6.1 (p66).)\n\n\\end{proof}\n\\end{thm}\n\n\\begin{eg}\nLet $V=M_{n\\times n} (\\F) \\cong \\R^{n^2}$, $f:V \\to V$ by $f(x)=x^2$. Then\n\\begin{equation*}\n\\begin{aligned}\nf(x+v)=(x+v)^2=x^2+xv+vx+v^2=f(x)+L_x(v)+v^2\n\\end{aligned}\n\\end{equation*}\nwhere \n\\begin{equation*}\n\\begin{aligned}\nL_x(v)=xv+vx\n\\end{aligned}\n\\end{equation*}\nis linear in $V$. Compare with the definition we get\n\\begin{equation*}\n\\begin{aligned}\nDF|_x = Lx.\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\n\n\\subsection{The Chain Rule}\n\\begin{thm} (Chain Rule)\\\\\nSuppose $g:\\R^n \\to \\R^m$ is differentiable at $x$, and $f:\\R^m \\to \\R^l$ is differentiable at $g(x)$. Then $f \\circ g : \\R^n \\to \\R^l$ is differentiable at $x$, and \n\\begin{equation*}\n\\begin{aligned}\nD(f\\circ g)|_x = Df|_{g(x)} \\circ Dg|_x\n\\end{aligned}\n\\end{equation*}\n\\end{thm}\n\\begin{eg}\nSuppose $r:\\R \\to \\R^n$ by $r(t)=(r_1(t),...,r_n(t))$, $F:\\R^n \\to \\R$, $F \\circ r:\\R \\to \\R$.\n\nThen $D(F\\circ r)|_t$ is a linear map $\\R \\to \\R$ given by $1\\times 1$ matrix $[\\frac{d}{dt}(F\\circ r)]$, $Dr|_t:\\R\\to \\R^n$ is given by\n\\begin{equation*}\n\\begin{aligned}\n\\left[\\begin{matrix}\nr'_1|_t\\\\\n...\\\\\nr'_n|_t\n\\end{matrix}\\right]\n\\end{aligned}\n\\end{equation*}\nand $DF|_t:\\R^n \\to \\R$ given by\n\\begin{equation*}\n\\begin{aligned}\n[D_1F|_{r(t)},...,D_nF|_{r(t)}]\n\\end{aligned}\n\\end{equation*}\nSo $D(F\\circ r)$ is given by matrix multiplication:\n\\begin{equation*}\n\\begin{aligned}\nD(F\\circ r) &= \\sum_{i=1}^n D_i F|_{r(t)} \\cdot r'_i(t)|_t\\\\\n&=\\sum \\frac{\\partial F}{\\partial x_i}r'_i\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\n\nNow back to the theorem. Since $g$ is differentiable, $g(x+v)=g(x)+(L_1(v)+||v||\\alpha(v))(=e(v))$ at $x$ where $L_1 = Dg|_x:\\R^n \\to \\R^m$ and $\\lim_{v \\to 0}\\alpha(v)=0$.\n\n\\begin{lemma}\n$\\lim_{v \\to 0} e(v)=0$.\n\\begin{proof}\n$g$ is differentiable at $x$ $\\implies$ $g$ is continuous at $x$. Done.\n\\end{proof}\n\\end{lemma}\n\n\\begin{lemma}\n$\\exists r>0$, s.t. $\\frac{||e(v)||}{||v||}$ is bounded on $B_r(0)$.\n\\begin{proof}\n\\begin{equation*}\n\\begin{aligned}\n\\frac{||e(v)||}{||v||} &= ||L_1(\\frac{v}{||v||})+\\alpha(v)||\\\\\n&\\leq ||L_1(\\frac{v}{||v||})|| + ||\\alpha(v)||\\\\\n\\end{aligned}\n\\end{equation*}\nwrite $v'=\\frac{v}{||v||}$, so $||v'||=1$.\n\n$L_1$ is linear, so continuous. $\\{v \\in \\R^n | ||v||=1\\}$ is closed and bounded in $\\R^n$, so by MVT, $\\exists M$ s.t. $||L_1(v')||\\leq M$ for all $v'$ with $||v'||=1$.\n\n$\\lim_{v\\to 0}\\alpha(v) = 0$, so $\\exists r$ s.t. $||\\alpha(v)||<1$ for $v \\in B_r(0)$.\n\nThen for $v \\in B_r(0)$,$\\frac{||e(v)||}{||v||} \\leq <M+1$.\n\\end{proof}\n\\end{lemma}\n\n\\begin{proof} (of Chain Rule)\\\\\n$f$ is differentiable at $g(x)$, so\n\\begin{equation*}\n\\begin{aligned}\nf(g(x)+w)=f(g(x))+LL_2(w)+||w||B(w)\n\\end{aligned}\n\\end{equation*}\nwhere $L_2 = Df|_{g(x)}$ and $\\lim_{w \\to 0}B(w)=0$.\n\n\\begin{equation*}\n\\begin{aligned}\nf(g(x+v))&=f(g(x)+e(v))\\\\\n&=fg(x)+L_2(e(v))+||e(v)||B(e(v))\\\\\n&=fg(x)+L_2(L_1(v))+L_2(||v||\\alpha(v))+||e(v)||B(e(v))\\\\\n&=fg(x)+(Df|_{g(x)}\\cdot Dg|_x)(v)+||v||E(v)\n\\end{aligned}\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\begin{aligned}\nE(v)=L_2(\\alpha(v))+\\frac{||e(v)||}{||v||}B(e(v))\n\\end{aligned}\n\\end{equation*}\nwe must show that $\\lim_{v\\to 0}E(v)=0$ and then we are done.\n\nWe know $\\lim_{v\\to 0}\\alpha(v)=0$. $L_2$ is linear, hence continuous, so $\\lim_{w\\to 0}L_2(w)=L_2(0)=0$. Thus $\\lim_{v\\to 0} L_2(\\alpha(v))=0$.\n\nBy the above second lemma, $\\exists r>0$ s.t. $\\frac{||e(v)||}{||v||}$ is bounded on $B_r(0)$. By the above first lemma $\\lim_{v \\to 0}e(v)=0$. \n\nWe know $\\lim_{w \\to 0} B(w)=0$ $\\implies$ $\\lim_{v \\to 0}B(e(v))=0$.\n\nThen by last lecture's lemma,\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{v \\to 0}\\frac{||e(v)||}{||v||}B(e(v))=0\n\\end{aligned}\n\\end{equation*}\nSo $\\lim_{v \\to 0}E(v)=0$.\n\\end{proof}\n\n\\textbf{Application of Chain Rule:}\\\\\n$\\bullet$ The gradient.\n\nSuppose $F: U \\to \\R$, where $U \\subset \\R^n$ is open. $DF|_x \\in \\mathcal{L}(\\R^n,\\R)$.\n\nRecall from LA that $\\R^n \\cong \\mathcal{L}(\\R^n,\\R)$ by $v \\to \\phi_v:\\phi_v(w)=v \\cdot w$. That sends $\\nabla F|_x$ to $DF|_x = [D_1F|_x,...,D_n F|_x]$ where $\\nabla F|_x = (D_1F|_x,...,D_nF|_x)$ is the \\emph{gradient} of $F$ at $x$.\n\nSo\n\\begin{equation*}\n\\begin{aligned}\nD_v F|_x = DF|_x(v) = \\nabla F|_x \\cdot v\n\\end{aligned}\n\\end{equation*}\n\n$\\bullet$ Mean value inequality.\n\n\\begin{defi}(Convex)\\\\\nl$\\ddot{u}$e\n\\end{defi}\n\n\\begin{prop}\nSuppose $U \\subset \\R^n$ is open and convex, and $F:U\\to \\R$ is differentiable. If $||\\nabla F|_x||_2 \\leq M$ $\\forall x \\in U_1$. Then\n\\begin{equation*}\n\\begin{aligned}\n|F(x_1)-F(x_0)|\\leq M||x_1-x_0||_2\n\\end{aligned}\n\\end{equation*}\nfor all $x_0,x_1 \\in U$.\n\\begin{proof}\nLet $\\gamma:[0,1] \\to \\R^n$ be given by\n\\begin{equation*}\n\\begin{aligned}\n\\gamma(t)=(1-t)x_0 + tx_1\n\\end{aligned}\n\\end{equation*}\nthen $\\gamma$ is differentiable and $\\gamma'(t)=x_1-x_0$.\n\nLet $f(t)=F(\\gamma(t))$. By Chain rule, $f$ is differentiable and $f'(t)=\\nabla F|_{\\gamma(t)} \\cdot \\gamma'(t)$.\n\nBy Cauchy-Schwartz,\n\\begin{equation*}\n\\begin{aligned}\n|f'(t)| &\\leq ||\\nabla F|_{\\gamma(t)}|| \\cdot ||x_1-x_0||\\\\\n&\\leq M||x_1-x_0||\n\\end{aligned}\n\\end{equation*}\nApply 1-variable MVT to $f(t)$, we see that \n\\begin{equation*}\n\\begin{aligned}\n|F(x_1)-F(x_0)| &= |f(1)-f(0)| = |f'(c)|\n\\end{aligned}\n\\end{equation*}\nfor some $c \\in [0,1]$\n\\begin{equation*}\n\\begin{aligned}\n\\leq M||x_1-x_0||\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{prop}\n\n\\begin{coro}\nIf $U \\subset \\R^n$ is open and convex, $F:U \\to \\R$ has $D_i F \\equiv 0$ for $1 \\leq i \\leq n$. Then $F(x) \\equiv c$ for some $c \\in \\R$.\n\\begin{proof}\n$D_i F \\equiv 0$ $\\implies$ $F$ differentiable $\\implies$\n\\begin{equation*}\n\\begin{aligned}\n|F(x_1)-F(x_0)|\\leq 0\\cdot ||x_1-x_0|| = 0\n\\end{aligned}\n\\end{equation*}\nfor all $x_1,x_0 \\in U$.\n\\end{proof}\n\\end{coro}\n\n\\begin{rem}\nThe hypothesis that $U$ is convex is needed for the proposition, but can be weakened for the corollary.\n\\end{rem}\n\\begin{eg}\nSuppose any 2 points $x_1,x_0$ in $U$ can be joined by a differentiable path $\\gamma:[0,1] \\to U$ with $\\gamma(0)=x_0$, $\\gamma(1) = x_1$. Then the corollary still holds.\n\\begin{proof}\nConsider $f(t)=F(\\gamma(t))$. Then $f'(t) = DF|_{\\gamma(t)}(\\gamma'(t))$ by the chain rule. $D_i F \\equiv 0$ $\\implies$ $DF \\equiv 0$ $\\implies$ $f'(t) \\equiv 0$ $\\implies$ $f(t)$ is constant. So $F(x_0) = f(0) = f(1)=F(x_1)$ for any $x_0,x_1$ in $U$.\n\\end{proof}\n\\end{eg}\n\nHowever, the corollary does not hold if $U$ is disconnected. In fact it holds whenever $U \\subset \\R^n$ is open and connected.\n\n\\subsection{Higher Derivatives}\nQ: If the derivative is a linear map, what is the 2nd derivative?\\\\\nA: 2nd derivative is a symmetric bilinear form.\n\nSuppose $U \\subset \\R^n$ is open, $f:U \\to \\R^m$ is differentiable.\n\nFix $v \\in \\R^n$ and define $g_v:U \\to \\R^m$ by\n\\begin{equation*}\n\\begin{aligned}\ng_v(x)=Df|_x(v).\n\\end{aligned}\n\\end{equation*}\n\n\\begin{defi}\n$f$ is twice differentiable if all $g_v$ are differentiable. If so, define $D^2f|_x(v,w)=D_{g_v}(w)$, i.e.\n\\begin{equation*}\n\\begin{aligned}\nD^2 f|_x: \\R^n \\times \\R^n \\to \\R^m\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\n\n\\begin{eg}\n$V=M_{n\\times n}(\\R) \\cong \\R^{n^2}$. $f:V \\to V$ is given by $f(x)=x^2$. Then from previous section we know\n\\begin{equation*}\n\\begin{aligned}\ng_A(X)=DF|_X(A)=XA+AX\n\\end{aligned}\n\\end{equation*}\nDifferentiate $g_A(X)$, get\n\\begin{equation*}\n\\begin{aligned}\ng_A(X+B)&=A(X+B)+(X+B)A\\\\\n&=(AX+XA)+AB+BA\\\\\n&=g_A(X)+L_A(B)\n\\end{aligned}\n\\end{equation*}\nwhere $L_A(B)=AB+BA$ is linear in $B$.\n\nSo $D_{g_A}|_X(B)=AB+BA=D^2f|_X(A,B)$.\n\nNote: $D^2 f_X(A,B)=D^2f|_X(B,A)$.\n\\end{eg}\n\n\\begin{lemma}\nSuppose $f:U \\to \\R^m$ is twice differentiable, let $B(v,w)=D^2f|_x(v,w)$. Then $B$ is a bilinear form.\n\\begin{proof}\n\\begin{equation*}\n\\begin{aligned}\ng_{v_1+\\lambda v_2} (x) &= Df|_x (v_1+\\lambda v_2)\\\\\n&=Df|_x(v_1)+\\lambda Df|_x(v_2) = g_{v_1}(x)+\\lambda g_{v_2}(x)\n\\end{aligned}\n\\end{equation*}\nSo differentiating we get linearity in the first argument. Similarly we can prove linearity in the second argument.\n\\end{proof}\n\\end{lemma}\n\nSuppose $F:U \\to \\R$ is differentiable. Then the partial derivatives $D_i F: U \\to \\R$ are all defined.\n\n\\begin{notation}\nWrite $D_{ij}F = D_i (D_j F)$ if it exists.\n\\end{notation}\n\n\\begin{defi}\n$C^2 (U) = \\{ F:U \\to \\R|$ all 1st and 2nd order partial derivatives of $F$ are defined and continuous $\\}$.\n\\end{defi}\n\n\\begin{prop}\nIf $F \\in C^2 (U)$, then $F$ is twice differentiable and\n\\begin{equation*}\n\\begin{aligned}\nD^2 F|_x (v,w) = \\sum_{1 \\leq i,j \\leq n} v_i w_j D_{ji} F(x)\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nLet $G_`i = D_i F$. Then all 1st order partial derivatives of $G_i$ are defined and continuous so $G_i$ is differentiable.\n\nThen for $v \\in \\R^n$, $G_{v(x)} = DF|_x(v) = \\sum_{1 \\leq i \\leq n} v_i D_i F|_x = \\sum v_i G(x)$.\n\nSo for a fixed value of $v$, $G_v(x)$ is a linear combination of the $G_i$s. Since all of them are differentiable, $G_v$ is differentiable. So $F$ is twice differentiable, and $D^2 F|_x(v,w) = DG_v|_x(w) = \\sum_{1 \\leq j \\leq n} w_j D_j G_v|_x = \\sum_{1 \\leq j,i\\leq n} v_i w_j D_{ji} F|_x$.\n\\end{proof}\n\\end{prop}\n\nNow $D_j (G_v) = D_j (\\sum_{i=1}^n v_i G_i) = \\sum_{i=1}^n v_i D_j G_i = \\sum_{i=1}^n v_i D_{ji} F$.\n\nEquivalently, $D^2 F|_x (v,w) = W^t B v$ where $B=[D_{ij}F|_x]$ is the \\emph{Hessian} matrix of 2nd order partial derivatives.\n\n\\begin{eg}\n$F(x,y)=x^2 y^3$. Then\n\\begin{equation*}\n\\begin{aligned}\nB=\\left(\\begin{matrix}\n2y^3 & 6xy^2\\\\\n6xy^2 & 6x^2y\n\\end{matrix}\\right)\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\n\nRecall that if $U \\subset \\R^n$ is open and $F \\in C^2(U)$, then $D^2 F|_x: \\R^n \\times \\R^n \\to \\R$ is bilinear and given by\n\\begin{equation*}\n\\begin{aligned}\nD^2 F|_x (v,w) = \\sum_{1 \\leq i,j\\leq n} v_i w_j D_{ji}F|_x = w^T H(x) v\n\\end{aligned}\n\\end{equation*}\n\nwhere $H(x)=[D_{ji}F|_x]$ is the \\emph{Hessian matrix}.\n\n\\begin{thm} (symmetry of mixed partials)\\\\\nSuppose $U \\subset \\R^2$ is open and $F \\in C^2(U)$. Then $D_{12}F = D_{21}F$.\n\nNote that it's not enough for the partial derivatives to be defined. They must be continuous or the theorem may fail (see example sheet).\n\\end{thm}\n\n\\begin{lemma}\n\\begin{equation*}\n\\begin{aligned}\nD_{12}F|_{(x_0,y_0)} = \\lim_{v \\to 0} \\frac{S(v)}{v^2}\n\\end{aligned}\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\begin{aligned}\nS(v) = F(x_0+v,y_0+v)-F(x_0+v,y_0)-F(x_0,y_0+v)+F(x_0,y_0)\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nSince $U$ is open, there exists $\\varepsilon>0$ s.t. $B_\\varepsilon((x_0,y_0),||\\cdot||_\\infty) \\subset U$.\n\nFrom now on, assume $|v|<\\varepsilon/2$.\n\nConsider $A(y)=F(x_0+v,y)-F(x_0,y)$. Fix $v$ with $|v|<\\varepsilon/2$. Then $A$ is differentiable on $(y_0-\\varepsilon/2,y_0+\\varepsilon/2)$, and\n\\begin{equation*}\n\\begin{aligned}\nA'(y)=D_2 F(x_0+v,y)-D_2F(x_0,y)\n\\end{aligned}\n\\end{equation*}\nNote that $S(v) = A(y_0+v)-A(y_0)$. So by MVT,\n\\begin{equation*}\n\\begin{aligned}\nS(v)&=vA'(y^*)\n\\end{aligned}\n\\end{equation*}\nfor some $y^* \\in [y_0,y_0+v]$\n\\begin{equation*}\n\\begin{aligned}\n&=v[D_2 F(x_0+v,y^*)-D_2F(x_0,y^*)]\\\\\n&=v[B(x_0+v)-B(x_0)]\n\\end{aligned}\n\\end{equation*}\nwhere $B(x)=D_2F(x,y^*)$.\n\n$B$ is differentiable on $(x_0-\\varepsilon/2,x_0+\\varepsilon/2)$, aget$B'(x)=D_{12}F(x,y^*)$. Applying MVT to $B$ we get\n\\begin{equation*}\n\\begin{aligned}\nS(v)=v^2 B'(x^*)=v^2D_{12}F(x^*,y^*)\n\\end{aligned}\n\\end{equation*}\nfor some $x^* \\in [x_0,x_0+v]$. Note that we have\n\\begin{equation*}\n\\begin{aligned}\n||(x^*(v),y^*(v))-(x_0,y_0)||_\\infty \\leq ||v||_\\infty\n\\end{aligned}\n\\end{equation*}\nSo\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{v \\to 0} (x^*(v),y^*(v)) = (x_0,y_0)\n\\end{aligned}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{v \\to 0} \\frac{S(v)}{v^2}&=\\lim_{v \\to 0} D_{12} F(x^*(v),y^*(v))\\\\\n&=D_{12}F(x_0,y_0)\n\\end{aligned}\n\\end{equation*}\nSince $D_{12}$ is continuous.\n\\end{proof}\n\\end{lemma}\n\n\\begin{proof} (of theorem)\\\\\nThe expression $S(v)$ is symmetric under interchanging roles of $x$ and $y$. Similar arguments as in the above proof shows\n\\begin{equation*}\n\\begin{aligned}\nD_{21}F(x_0,y_0) = \\lim_{v \\to 0} \\frac{S(v)}{v^2} = D_{12}F(x_0,y_0)\n\\end{aligned}\n\\end{equation*}\nSo they are equal.\n\n\\end{proof}\n\n\\begin{coro}\nIf $U \\subset \\R^n$ is open, $G \\in C^2(U)$, then $D_{ij} G=D_{ji} G$ for all $1\\leq i,j \\leq n$.\n\\begin{proof}\nApply the theorem to $F(z_1,z_2 = G(x_1,x_2,...z_1(i),...,z_2(j),...,x_n)$.\n\\end{proof}\n\\end{coro}\nIn other words, if $G \\in C^2(U)$, the Hessian matrix $H=[D_{ji}G|_x]$ is symmetric: $H^T = H$.\n\n\\begin{coro}\n$D^2 G|_x$ is symmetric. i.e. $D^2 G|_x(v,w) = D^2 G|_x(w,v)$.\n\\begin{proof}\n$D^2G|_x (v,w)=w^THv$ is a $1\\times 1$ matrix, so symmetric. Take its transpose and we get the other side of the equation.\n\\end{proof}\n\\end{coro}\n\nHigher derivatives are defined inductively: If $F:U \\to \\R$ is $(k-1)$ times differentiable, then\n\\begin{equation*}\n\\begin{aligned}\nD^k F|_x (v_1,...,v_k) = DG|_x(v_k)\n\\end{aligned}\n\\end{equation*}\n(if exists) where\n\\begin{equation*}\n\\begin{aligned}\nG(x)=D^{k-1} F|_x(v_1,...,v_{k-1})\n\\end{aligned}\n\\end{equation*}\n\nThe same proof as for $k=2$ shows that if $F \\in C^k(U)$ then $F$ is $k$ times differentiable, and\n\\begin{equation*}\n\\begin{aligned}\nD^k F|_x (v_1,...,v_k) = \\sum_{\\alpha\\in\\{1,...,n\\}^k} v^\\alpha D_\\alpha F|_x\n\\end{aligned}\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\begin{aligned}\nv^\\alpha = \\prod_{i=1}^k v_{i,\\alpha_i}\n\\end{aligned}\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\begin{aligned}\nv_i&=(v_{i,1},...,v_{i,n})\\\\\n\\alpha&=(\\alpha_1,...,\\alpha_k)\n\\end{aligned}\n\\end{equation*}\nIf we let $A(v_1,...,v_k)=D^kF|_\\alpha (v_1,...,v_k)$, then $A$ is\\\\\n1) Symmetric: $A(v_1,...,v_k) = A(v_i,...,v_{i_k})$ where $(i_1,...,i_k)$ is any permutation of $(1,...,k)$;\\\\\n2) Multilinear: $(v_1+\\lambda v'_1,v_2,...,v_k)=A(v_1,v_2,...,v_k)+\\lambda A(v'_1,v_2,...,v_k)$.\n\n\\begin{prop}\nSuppose $F \\in C^k (U)$ and define\n\\begin{equation*}\n\\begin{aligned}\nf(t)=F(x_0+tv)\n\\end{aligned}\n\\end{equation*}\nfor $x_0 \\in U$. Since $U$ is open, $f$ is defined on $(-\\varepsilon,\\varepsilon)$.\n\nThen $f$ is $k-$times differentiable and\n\\begin{equation*}\n\\begin{aligned}\nf^k(t)=D^k F|_{x_0+tv}(v,v,...,v) (\\text{ k times})\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nRecall that if $G \\in C^1(U)$ and $g=G(x_0+tv)$ then $g'(t) = D_v G|_{x_0+tv}=DG|_{x_0+tv}(v)$.\n\nThe proof is by induction on $k$:\n\n$k=1$ is exactly the above equation applied to $G=F$.\n\nFor the general case, suppose the proposition holds for $k-1$. Then let\n\\begin{equation*}\n\\begin{aligned}\nh(t)&=f^{(k-1)}(t)\\\\\n&=D^{k-1} F|_{x_0+tv}(v,...,v)\\\\\n&= H(x_0+tv)\n\\end{aligned}\n\\end{equation*}\nwhere $H(x)=D^{k-1}F|_x (v,...,v)$.\n\nApply the above equation to $G=H$, get\n\\begin{equation*}\n\\begin{aligned}\nf^k(t)=h'(t)=DH|_{x_0+tv}(v)=D^k F|_{x_0+tv}(v,...,v) \\text{ (k times)}\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{prop}\n\n\\begin{thm} (Taylor's Theorem)\\\\\nIf $F \\in C^k (\\R^n)$, then\n\\begin{equation*}\n\\begin{aligned}\nF(x_0+v)=\\sum_{i=0}^{k-1} \\frac{1}{i!} D^i F|_{x_0}(v,...,v)+\\frac{1}{k!}D^k F|_{x_0+tv}(v,...,v)\n\\end{aligned}\n\\end{equation*}\nfor some $t \\in [0,1]$.\n\\begin{proof}\nConsider $f(t)=F(x_0+tv)$ as above. Then by Taylor's theorem in 1 variable, we have\n\\begin{equation*}\n\\begin{aligned}\nf(1)= \\sum_{i=0}^{k-1}\\frac{1}{i!}f^{(i)} (0) \\cdot 1^i + \\frac{1}{k!} f^{(k)} (t) 1^k\n\\end{aligned}\n\\end{equation*}\nfor some $t \\in [0,1]$, i.e.\n\\begin{equation*}\n\\begin{aligned}\nF(x+v)=\\sum_{i=0}^{k-1}\\frac{1}{i!}D^i F|_{x_0} (v,...,v)+\\frac{1}{k!} D^k|_{x_0+tv}(v,...,v)\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{thm}\n\n\\begin{rem}\n$D^k F|_{x_0}(v,...,v)$ is a degree $k$ polynomial in the coefficients of $v$ s.t. all the $k^{th}$ order partial derivatives agree with $k^{th}$ order partial derivatives of $F$ at $x_0$.\n\\end{rem}\n\n\\newpage\n\n\\section{Metric spaces}\n\\subsection{Basics}\n\\begin{defi}\nl$\\ddot{u}$e\n\\end{defi}\n\n\\begin{eg}\nl$\\ddot{u}$e\n\\end{eg}\n\n\\begin{defi}(open and closed sets)\\\\\nl$\\ddot{u}$e\n\\end{defi}\n\n\\subsection{Lipschitz Maps}\nSuppose $\\left(X,d_X\\right)$ and $\\left(Y,d_Y\\right)$ are metric spaces.\n\n\\begin{defi}\n$f:X\\to Y$ is $k-$Lipschitz ($k \\in \\R^+$) if $d_Y\\left(f\\left(x_1\\right),f\\left(x_2\\right)\\right) \\leq kd_X\\left(x_1,x_2\\right)$ for all $x_1,x_2 \\in X$.\\\\\n$f$ is Lipschitz if it's $k-$Lipschitz for some $k \\in \\R^+$.\n\\end{defi}\n\n\\begin{prop}\n$f$ is Lipschitz implies that $f$ is uniformly continuous.\n\\begin{proof}\nSuppose $f$ is $k-$Lipschitz. If $d\\left(x_1,x_2\\right) < \\varepsilon/k$, then $d\\left(f\\left(x_1\\right),f\\left(x_2\\right)\\right) < \\varepsilon$.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}\nSuppose $U \\subset \\R^n$ is open, $F \\in C^1 \\left(U\\right)$, and $k = \\bar{B}_r\\left(\\mathbf{x}_0\\right) \\subset U$. Then $F|_k$ is Lipschitz.\n\\begin{proof}\n$F$ is $C^1$, so the map\n\\begin{equation*}\n\\begin{aligned}\nU &\\to \\R^n &\\to \\R\\\\\n\\mathbf{x} &\\to \\nabla F|_\\mathbf{x} &\\to ||\\nabla F|_\\mathbf{x}||\n\\end{aligned}\n\\end{equation*}\nis continuous.\n\n$k=\\bar{B}_r\\left(\\mathbf{x}_0\\right)$ is a closed and bounded subset of $\\R^n$. By the Maximum Value Theorem, $\\exists M \\in \\R$ s.t. $||\\nabla F|_\\mathbf{x}|| \\leq M$ for all $\\mathbf{x} \\in k$. $k=\\bar{B}_r\\left(\\mathbf{x}_0\\right)$ is convex, so by Mean Value Inequality,\n\\begin{equation*}\n\\begin{aligned}\n|F\\left(\\mathbf{x}_1\\right)-F\\left(\\mathbf{x}_2\\right)| \\leq M||\\mathbf{x}_1-\\mathbf{x}_2||_2\n\\end{aligned}\n\\end{equation*}\ni.e.\n\\begin{equation*}\n\\begin{aligned}\nd\\left(F\\left(\\mathbf{x}_1\\right),F\\left(\\mathbf{x}_2\\right)\\right) \\leq M d\\left(\\mathbf{x}_1,\\mathbf{x}_2\\right)\n\\end{aligned}\n\\end{equation*}\nfor $\\mathbf{x}_1,\\mathbf{x}_2 \\in k$.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}\nIf $f:Y \\to Z$ is $k_1-$Lipschitz, $g:X \\to Y$ is $k_2-$Lipschitz, then $f\\circ g: X \\to Z$ is $k_1k_2-$Lipschitz.\n\\begin{proof}\n\\begin{equation*}\n\\begin{aligned}\nd_2\\left(f\\left(g\\left(x_1\\right)\\right),f\\left(g\\left(x_2\\right)\\right)\\right) &\\leq k_1 d_y\\left(g\\left(x_1\\right),g\\left(x_2\\right)\\right)\\\\\n&\\leq k_1k_2d_x\\left(x_1,x_2\\right)\n\\end{aligned}\n\\end{equation*}\nSo The composition of Lipschitz maps is Lipschitz.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}\nIf $||\\cdot||$ and $||\\cdot||'$ are two norms on a vector space $V$, then $||\\cdot||$ is Lipschitz equivalent to $||\\cdot||'$ if and only if both the identity maps from $V$ equipped with one norm to the other norm are Lipschitz.\n\\end{prop}\n\n\\begin{defi}\nSuppose $V,W$ are finite dimensional normed vector spaces.\\\\\nIf $L \\in \\mathcal{L}\\left(V,W\\right)$, the operator norm\n\\begin{equation*}\n\\begin{aligned}\n||L||_{op} = \\sup_{\\mathbf{v} \\in V,\\mathbf{v} \\neq 0} \\frac{||L\\left(\\mathbf{v}\\right)||_W}{||\\mathbf{v}||_V} = \\max_{||\\mathbf{v}||=1}||L\\left(\\mathbf{v}\\right)||_W.\n\\end{aligned}\n\\end{equation*}\nThe maximum exists since $S^1$ is closed and bounded in $V=\\R^n$.\n\\end{defi}\n\n\\begin{lemma}\n$||\\cdot||_{op}$ is a norm on $\\mathcal{L}\\left(V,W\\right)$.\n\\begin{proof}\nOmitted.\n\\end{proof}\n\\end{lemma}\n\n\\begin{prop}\nIf $||L_1||_{op} = k$, then $L_1$ is $k-$Lipschitz.\n\\begin{proof}\n\\begin{equation*}\n\\begin{aligned}\n||L\\left(\\mathbf{v}_1\\right)-L\\left(\\mathbf{v}_2\\right)|| &= ||L\\left(\\mathbf{v}_1\\mathbf{v}_2\\right)||\\\\&\\leq k||\\mathbf{v}_1-\\mathbf{v}_2||\n\\end{aligned}\n\\end{equation*}\nSince $||L||_{op} = k$.\n\\end{proof}\n\\end{prop}\n\n\\subsection{Contraction maps}\nSuppose $X$ is a metric space and $f:X \\to X$.\n\n\\begin{defi}\n$x \\in X$ is a \\emph{fixed point} of $f$ if $f\\left(x\\right) = x$.\n\\end{defi}\n\n\\begin{defi}\n$f^n = f\\circ f\\circ ...\\circ f$ ($n$ times) :$X\\to X$it the composition of $f$ with itself $n$ times.\n\\end{defi}\n\nIf $f$ is $k-$Lipschitz, then $f^n$ is $k^n$-Lipschitz.\n\n\\begin{defi}\n$f:X\\to X$ is a \\emph{contraction map} if $f$ is $k-$Lipschitz for some $k<1$.\n\\end{defi}\n\n\\begin{thm}\nSuppose $X$ is a complete metric space, $f:X\\to X$ is a contraction map. Then $f$ has a unique fixed point.\n\\begin{proof}\nSuppose $f$ is $k-$Lipschitz for some $k<1$.\n\\begin{lemma}\nIf $x \\in X$, then $d\\left(x,f^n\\left(x\\right)\\right) \\leq \\frac{1}{1-k} d\\left(x,f\\left(x\\right)\\right)$ regardless of $n$.\n\\begin{proof}\n$f^n$ is $k^n$ Lipschitz, so\n\\begin{equation*}\n\\begin{aligned}\nd\\left(f^n\\left(x\\right),f^{(n+1)}\\left(x\\right)\\right) &= d\\left(f^n\\left(x\\right),f^n\\left(f\\left(x\\right)\\right)\\right)\\\\ &\\leq k^n d\\left(x,f\\left(x\\right)\\right)\n\\end{aligned}\n\\end{equation*}\nSo\n\\begin{equation*}\n\\begin{aligned}\nd\\left(x,f^n\\left(x\\right)\\right) & \\leq d\\left(x,f\\left(x\\right)\\right)+...+d\\left(f^{n-1}\\left(x\\right),f^n\\left(x\\right)\\right)\\\\\n&\\leq d\\left(x,f\\left(x\\right)\\right)+kd\\left(x,f\\left(x\\right)\\right)+...+k^{n-1}d\\left(x,f\\left(x\\right)\\right)\\\\\n&=\\frac{1-k^n}{1-k}d\\left(x,f\\left(x\\right)\\right)\\\\\n&\\leq \\frac{1}{1-k}d\\left(x,f\\left(x\\right)\\right)\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{lemma}\nProof of Theorem:\\\\\nPick $x \\in X$ and consider $\\left(f^n\\left(x\\right)\\right)$.\n\nThis sequence is Cauchy: if $m \\geq n$, then \n\\begin{equation*}\n\\begin{aligned}\nd\\left(f^m\\left(x\\right),f^n\\left(x\\right)\\right) &= d\\left(f^n\\left(x\\right),f^n\\left(f^{m-n}\\left(x\\right)\\right)\\right)\\\\\n&\\leq k^n d\\left(x,f^{m-n}\\left(x\\right)\\right)\\\\\n&\\leq \\frac{k^n}{1-k}d\\left(x,f\\left(x\\right)\\right)\n\\end{aligned}\n\\end{equation*}\nWe know $k<1$, so\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{n \\to \\infty} k^n \\left(\\frac{d\\left(x,f\\left(x\\right)\\right)}{1-k}\\right) = 0\n\\end{aligned}\n\\end{equation*}\nSo pick $N$ s.t. the above is less than $\\varepsilon$ for all $n \\geq N$. Then if $m \\geq n \\geq N$,\n\\begin{equation*}\n\\begin{aligned}\nd\\left(f^n\\left(x\\right),f^m\\left(x\\right)\\right) &\\leq \\frac{k^n}{1-k}d\\left(x,f\\left(x\\right)\\right) < \\varepsilon\n\\end{aligned}\n\\end{equation*}\nSo $\\left(f^n\\left(x\\right)\\right)$ is Cauchy. So it converges to some $x^*$.\n\nWe claim that $f\\left(x^*\\right) = x^*$: since $f$ is Lipschitz, $f$ is continuous, and $f^n\\left(x\\right) \\to x^*$, so $f\\left(f^n\\left(x\\right)\\right) \\to f\\left(x^*\\right)$. But $f^{n+1}\\left(x\\right) \\to x^*$. So $f\\left(x^*\\right) = x^*$.\n\nWe also claim that $x^*$ is the only fixed point: Suppose $f\\left(y\\right) = y$. Then $d\\left(f\\left(x^*\\right),f\\left(y\\right)\\right) = d\\left(x^*,y\\right)$. But $d\\left(f\\left(x^*\\right),f\\left(y\\right)\\right) \\leq k d\\left(x^*,y\\right)$, since $f$ is a contraction where $k<1$, this can only happen if $d\\left(x^*,y\\right) =0 $, i.e $x^* = y$.\n\\end{proof}\n\\end{thm}\n\n\\newpage\n\n\\section{Solving Equations}\nProblem: Suppose $U \\subset \\R^n$ is open. $f:U \\to \\R^m$ is $C^1$ and $f(x_0)=y_0$. Can we solve $f(x)=y$ for $y$ close to $y_0$?\n\nIf so, what does the set of $x$ close to $x_0$ solution look like?\n\nThere are three cases:\\\\\na) $n<m$. For 'most' $y \\in \\R^m$, there is no solution. Idea: $\\dim(U) \\leq n < m$.\n\nb) $m=n$. If $y$ is sufficiently close to $y_0$ and $Df|_{x_0}$ is an isomorphism, then there is a unique solution near $x_0$ (inverse function theorem).\n\nc) $m<n$. If $Df|_{x_0}$ is surjective and $y$ is close to $y_0$, set of solutions near $x_0$ looks like $B_{\\varepsilon} (0) \\subset \\R^{n-m}$ (implicit function theorem).\n\nWe'll prove (b) and use it to prove (c).\n\n\\subsection{Newton's method}\n$n=1$: solve $f(x)=y^*=y$.\n\nApproximate $f$ by graph of it's tangent line at $(x_0,f(x_0))$.\n\n\\begin{equation*}\n\\begin{aligned}\ng(x)=f(x_0)+f'(x_0)(x-x_0)\n\\end{aligned}\n\\end{equation*}\nsolve $g(x_1)=y^*$:\n\\begin{equation*}\n\\begin{aligned}\nx_1=x_0+\\frac{y^*-f(x_0)}{f'(x_0)}\n\\end{aligned}\n\\end{equation*}\nNow repeat:\n\\begin{equation*}\n\\begin{aligned}\nx_2=x_1+\\frac{y^*-f(x_1)}{f'(x_1)}\n\\end{aligned}\n\\end{equation*}\nand etc. Hope that $(x_n) \\to x^*$ with $f(x^*) = y^*$.\n\nGeneral case: $f: U \\subset \\R^n \\to \\R^m$: approximate $f(x)$ near $x=x_0$ by\n\\begin{equation*}\n\\begin{aligned}\ng(x)=f(x_0)+Df|_{x_0}(x-x_0)\n\\end{aligned}\n\\end{equation*}\nsolve equation $g(x_1)=y$: $x_1=x_0+(Df|_{x_0})^{-1}(y-f(x_0))$.\n\nRepeat: $x_2=x_1+(Df|_{x_1})^{-1}(y-f(x_1))$ etc.\n\nEquivalently: define $n_y(x)=x+(Df|_x)^{-1}(y-f(x))$. Then\n\\begin{equation*}\n\\begin{aligned}\n(x_k)=(n^k_y(x_0))\n\\end{aligned}\n\\end{equation*}\n(the $k^{th}$ iterate of $n_y$).\n\nIf $x$ is a fixed point of $n_y$, then\n\\begin{equation*}\n\\begin{aligned}\nx=x+(Df|_x)^{-1}(y-f(x))\\\\\n\\implies 0=(Df|_x)^{-1}(y-f(x))\\\\\n\\implies 0=y-f(x)\\\\\n\\implies f(x)=y\n\\end{aligned}\n\\end{equation*}\nso we have a solution.\n\nSo if we knew $n_y$ was a contraction map, we would get a solution.\n\nProblem: This only makes sense if $Df|_x$ is invertible. Analyzing $(Df|_x)^{-1}$ term is painful.\n\nModified Newton's method:\n\nSuppose $f:U \\to \\R^n$ is $C^1$, $f(x_0)=y_0$ and $Df|_{x_0} = A$ is invertible where $A:\\R^n \\to \\R^n$ is a linear map.\n\nApproximate $Df|_x$ by $Df|_{x_0} = A$, i.e. consider\n\\begin{equation*}\n\\begin{aligned}\nN_y(x)=x+A^{-1}(y-f(x))\n\\end{aligned}\n\\end{equation*}\n\nIf $N_y(x)=x$, then $f(x)=y$ so we found a solution.\n\nIs $N_y$ a contraction map when $x$ is close to $x_0$?\n\nCompute \n\\begin{equation*}\n\\begin{aligned}\nN_y(x)-N_y(x') &= x+A^{-1}(y+f(x))-(x'+A^{-1}(y-f(x'))\\\\\n&=x-x'+A^{-1}(f(x')-f(x))\\\\\n&=A^{-1}(A(x)-f(x)-(A(x')-f(x')))\\\\\n&= A^{-1}(h(x)-h(x'))\n\\end{aligned}\n\\end{equation*}\nwhere $h(x)=A(x)-f(x)$.\n\nNotice:\n\\begin{equation*}\n\\begin{aligned}\nDh|_x &= DA|_x - Df|_x\\\\\n&=A|_x - Df|_x\\\\\n&=Df|_{x_0}-Df|_x\n\\end{aligned}\n\\end{equation*}\n\n$C^1$ maps: $Df = U \\to \\mathcal{L}(\\R^n,\\R^n) = M_{n\\times n} (\\R) = \\R^{n^2}$.\n\n$f$ is $C^1$ if $Df$ is continuous.\n\nNote: Since all norms on $\\R^{n^2}$ are equivalent, we can use whatever norm on $\\mathcal{L}(\\R^n,\\R^n)$ we like.\n\nFor applications: use operator norm $||\\cdot||_{op}$.\n\n\\begin{lemma}\nIf $||Dh|_x||_{op} < M$ for all $x \\in B_r (x_0)$, then $||h(x)-h(x')||_2 \\leq M\\sqrt{n}||x-x'||$ for $x,x' \\in B_r(x_0)$ ($n$ is the dimension of space).\n\\begin{proof}\nlet $h_i$ be the $i^{th}$ component of $h$. Then\n\\begin{equation*}\n\\begin{aligned}\n||Dh_i|_x|| = ||Dh|_x(e_i)|| \\leq M\\cdot||e_i||_2=M\n\\end{aligned}\n\\end{equation*}\nSo by Mean value inequality, $|h_i(x)-h_i(x')| \\leq M\\cdot ||x-x'||_2$. So\n\\begin{equation*}\n\\begin{aligned}\n||h(x)-h(x')\\leq \\sqrt{n} M\\cdot ||x-x'||\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{lemma}\n\n\\begin{prop}\nGiven $\\varepsilon>0$, there exists $\\delta>0$ s.t. $N_y$ is $\\varepsilon-$lipschitz on $B_\\delta(x_0)$.\n\\begin{proof}\n$f$ is $C^1$, so choose $\\delta>0$ s.t.\n\\begin{equation*}\n\\begin{aligned}\n||Dh|_x||=||Df|_x-Df|_{x_0}||_{op} \\leq \\frac{\\varepsilon}{||A^{-1}||_{op}\\cdot \\sqrt{n}}\n\\end{aligned}\n\\end{equation*}\nfor $x \\in B_\\delta (x_0)$, so\n\\begin{equation*}\n\\begin{aligned}\n||N_y(x)-N_y(x')|| &= ||A^{-1}(h(x)-h(x'))||\\\\\n&\\leq ||A^{-1}||_{op} ||h(x)-h(x')||\\\\\n&\\leq ||A^{-1}||_{op} \\cdot \\sqrt{n}(\\varepsilon/\\sqrt{n}\\cdot ||A^{-1}||_{op})\\cdot (||x-x'||)\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{prop}\n\n\\subsection{The Inverse Function Theorem (See alternative notes)}\nLet $U \\subset \\R^n$ be open, $f\\left(\\mathbf{x}_0\\right) = \\mathbf{y}_0$, and $f:U \\to \\R^n$ is $C^1$, $A = Df|_{\\mathbf{x}_0}$ is invertible.\n\nLet $a = ||A^{-1}||_{op}$, so that\n\\begin{equation*}\n\\begin{aligned}\n||A^{-1}\\left(v\\right)|| \\leq a||\\mathbf{v}||\n\\end{aligned}\n\\end{equation*}\nfor all $v \\in \\R^n$.\n\n\\begin{lemma}\n$\\exists n>0$ s.t. $Df|_\\mathbf{x}$ is invertible for all $\\mathbf{x} \\in B_n \\left(\\mathbf{x}_0\\right)$.\n\\begin{proof}\n$f:U \\to \\R^n$ is $C^1$, so the map\n\\begin{equation*}\n\\begin{aligned}\n\\alpha: & U &\\to& \\mathcal{L}\\left(\\R^n,\\R^n\\right) &\\to \\R\\\\\n&\\mathbf{x} &\\to& Df|_\\mathbf{x} &\\to \\det\\left(Df|_\\mathbf{x}\\right)\n\\end{aligned}\n\\end{equation*}\nis continuous.\n\n$\\R-\\left\\{0\\right\\}$ is open in $\\R$, so $\\alpha^{-1} \\left(\\R - 0\\right)$ is open in $U$.\n\n$\\alpha^{-1}\\left(\\R-\\left\\{0\\right\\}\\right) = \\left\\{\\mathbf{x} \\in U | Df_\\mathbf{x} \\text{ is invertible}\\right\\}$. $\\mathbf{x}_0 \\in \\alpha^{-1} \\left(\\mathbf{\\R} - \\left\\{0\\right\\}\\right)$, so $\\exists n > 0$ s.t. $B_n\\left(\\mathbf{x}_0\\right) \\subset \\alpha^{-1} \\left(\\R = 0\\right)$.\n\\end{proof}\n\\end{lemma}\n\nConsider $N_\\mathbf{y}\\left(\\mathbf{x}\\right) = \\mathbf{x}+A^{-1}\\left(\\mathbf{y}-f\\left(\\mathbf{x}\\right)\\right)$ (Modified Newton's Method).\n\nFix $r_0$ s.t. $0<r_0<n$ and $N_\\mathbf{y}$ is $\\frac{1}{2}$-Lipschitz on $\\bar{B}_{r_0}\\left(\\mathbf{x}_0\\right)$. By the lemma, $Df|_\\mathbf{x}$ is invertible for $\\mathbf{x} \\in \\bar{B}_{r_0}\\left(x_0\\right)$.\n\nWe want $N_y$ to be a contraction map.\n\nProblem: $N_y\\left(B_{r_0}\\left(\\mathbf{x}_0\\right)\\right)$ need not be in the region where $N_y$ is contracting.\n\nSolution: require $\\mathbf{y}$ to be close to $y_0$.\n\n\\begin{prop}(2)\nLet $r\\left(\\mathbf{y}\\right) =2a||\\mathbf{y}-\\mathbf{y}_0||$. If $r\\left(\\mathbf{y}\\right) \\leq r_0$, then $N_\\mathbf{y}: \\bar{B}_{r\\left(\\mathbf{y}\\right)} \\left(\\mathbf{x}_0\\right) \\to \\bar{B}_{r\\left(\\mathbf{y}\\right)} \\left(\\mathbf{x}_0\\right)$.\n\\begin{proof}\nSuppose $\\mathbf{x} \\in B_{r\\left(\\mathbf{y}\\right)} \\left(\\mathbf{x}_0\\right)$. Then\n\\begin{equation*}\n\\begin{aligned}\n||N_\\mathbf{y}\\left(\\mathbf{x}_0\\right)|| &\\leq N_\\mathbf{y}\\left(\\mathbf{x}\\right) - N_\\mathbf{y}\\left(\\mathbf{x}_0\\right)|| + ||N_y\\left(\\mathbf{x}_0\\right) - \\mathbf{x}_0||\\\\\n&\\leq \\frac{1}{2}||\\mathbf{x}-\\mathbf{x}_0|| + ||A^{-1}\\left(\\mathbf{y}-\\mathbf{y}_0\\right)||\\\\\n&\\leq \\frac{1}{2}r\\left(\\mathbf{y}\\right) + a||\\mathbf{y}-\\mathbf{y}_0||\\\\\n&=\\frac{1}{2}r\\left(\\mathbf{y}\\right) + \\frac{1}{2}r\\left(\\mathbf{y}\\right)\\\\\n&=r\\left(\\mathbf{y}\\right)\n\\end{aligned}\n\\end{equation*}\nSo $N_\\mathbf{y}\\left(\\mathbf{x}_0\\right) \\in B_{r\\left(\\mathbf{y}\\right)}\\left(\\mathbf{x}_0\\right)$.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}(3)\nSuppose $r \\leq r_0$. If $\\mathbf{y} \\in B_{\\frac{r}{2a}} \\left(\\mathbf{y}_0\\right)$, then there is a unique $\\mathbf{x} \\in B_r\\left(\\mathbf{x}_0\\right)$ s.t. $f\\left(\\mathbf{x}\\right) = \\mathbf{y}$.\n\\begin{proof}\n$f\\left(\\mathbf{x}\\right) = \\mathbf{y} \\iff N_\\mathbf{y} \\left(\\mathbf{x}\\right) = \\mathbf{x}$.\n\n$N_\\mathbf{y}$: If $\\mathbf{y} \\in \\bar{B}_{r/2a}\\left(\\mathbf{y}_0\\right)$, then $r\\left(\\mathbf{y}\\right) = r$, so by the previous proposition,\n\\begin{equation*}\n\\begin{aligned}\nN_\\mathbf{y}: \\bar{B}_r\\left(\\mathbf{x}_0\\right) \\to \\bar{B}_r\\left(\\mathbf{x}_0\\right)\n\\end{aligned}\n\\end{equation*}\n$r \\leq r_0$, so $N_\\mathbf{y}$ is $\\frac{1}{2}-$ Lipschitz on $\\bar{B}_r\\left(\\mathbf{x}_0\\right)$, i.e. $N_\\mathbf{y}:\\bar{B}_r\\left(\\mathbf{x}_0\\right) \\to \\bar{B}_r\\left(\\mathbf{x}_0\\right)$ is a contraction.\n\n$\\bar{B}_r\\left(\\mathbf{x}_0\\right)$ is a closed subset of $\\R^n$, which is complete, so $\\bar{B}_r\\left(x_0\\right)$ is complete. Thus there is a unique $\\mathbf{x} \\in \\mathbf{B}_r\\left(\\mathbf{x}_0\\right)$ such that $N_\\mathbf{y}\\left(\\mathbf{x}\\right) = \\mathbf{x}$, i.e. there exists a unique $\\mathbf{x} \\in \\bar{B}_r\\left(\\mathbf{x}_0\\right)$ s.t. $f\\left(\\mathbf{x}\\right) = \\mathbf{y}$.\n\\end{proof}\n\\end{prop}\n\nNote: $r\\left(\\mathbf{y}\\right) = 2a||\\mathbf{y}-\\mathbf{y}_0||$, so $r\\left(\\mathbf{y}\\right) \\leq r \\implies y \\in \\bar{B}_{r/2a} \\left(\\mathbf{y}_0\\right)$.\n\n\\begin{rem}\nIf $y\\in \\bar{B}_{r/2a} \\left(\\mathbf{y}_0\\right)$ for $r<r_0$, then it's in $\\bar{B}_{r_0/2a} \\left(\\mathbf{y}_0\\right)$, so the proposition implies that there is a unique $\\mathbf{x} \\in \\bar{B}_{r_0/2a}\\left(\\mathbf{y}_0\\right)$ with $f\\left(\\mathbf{x}\\right) = y$ and $\\mathbf{x} \\in B_r\\left(\\mathbf{x}_0\\right)$.\n\\end{rem}\n\n\\begin{prop}(4)\nThere are open sets $V \\subset U$, $\\mathbf{x}_0 \\in V$, $W \\subset \\R^n$, $\\mathbf{y}_0 \\in W$ s.t. $f|_V:V \\to W$ bijectively.\n\\begin{proof}\nTake $W = B_{r_0/4a}\\left(\\mathbf{y}_0\\right)$. $f$ is continuous, so $f^{-1}\\left(W\\right)$ is open. Take\n\\begin{equation*}\n\\begin{aligned}]\nV = f^{-1}\\left(W\\right) \\cap B_{r_0}\\left(\\mathbf{x}_0\\right)\n\\end{aligned}\n\\end{equation*}\nwhich is open.\n\nGiven $\\mathbf{y} \\in W$, there exists $x \\in \\bar{B}_{r_0/2} \\left(\\mathbf{x}_0\\right)$ with $f\\left(\\mathbf{x}\\right) = y$ by the previous proposition. Moreover, this $\\mathbf{x}$ is the unique $\\mathbf{x}$ in that open ball. So $\\mathbf{x} \\in V = f^{-1}\\left(W\\right) \\cap B_r\\left(\\mathbf{x}_0\\right)$ and is the unique such element.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}(5)\nLet $g:W \\to V$ be the inverse of $f$. Then $g$ is continuous at $\\mathbf{y}_0$.\n\\begin{proof}\nIf $\\mathbf{y} \\in \\bar{B}_{r/2a}\\left(\\mathbf{y}_0\\right)$, then $g\\left(\\mathbf{y}\\right) \\in \\bar{B}_r\\left(\\mathbf{x}_0\\right)$ by proposition 3, i.e. if $||\\mathbf{y}-\\mathbf{y}_0|| \\leq \\delta$, then $||g\\left(\\mathbf{y}\\right) - g\\left(\\mathbf{y}_0\\right)|| \\leq 2a\\delta$. So $g$ is continuous at $\\mathbf{y}_0$.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}(6)\n$g$ is differentiable at $\\mathbf{y}_0$ and $Dg|_{y_0} = A^{-1}$.\n\\begin{proof}\nNote that $g\\left(\\mathbf{y}\\right)$ satisfies $N_\\mathbf{y}\\left(g\\left(\\mathbf{y}\\right)\\right) = g\\left(\\mathbf{y}\\right)$, so if $\\mathbf{y} \\in \\bar{B}_{r/2a}\\left(\\mathbf{y}_0\\right)$, $g\\left(\\mathbf{y}\\right) \\in N_y\\left(\\bar{B}_{r\\left(\\mathbf{y}\\right)} \\left(\\mathbf{x}_0\\right)\\right)$.\n\nNow $N_y: \\bar{B}_{r(\\mathbf{y})} \\left(\\mathbf{x}_0\\right) \\to \\bar{B}_{r(\\mathbf{y})} \\left(\\mathbf{x}_0\\right)$ is $\\varepsilon\\left(r\\left(\\mathbf{y}\\right)\\right)-$ Lipschitz, by proposition 1 where $\\varepsilon\\left(r\\left(\\mathbf{y}\\right)\\right) \\to 0$ as $r\\left(\\mathbf{y}\\right) \\to 0$.\n\nSo $N_y\\left(B_{r(\\mathbf{y})} \\left(\\mathbf{x}_0\\right)\\right) \\subset B_{\\varepsilon(r(\\mathbf{y})) \\cdot r(\\mathbf{y})}\\left(N_y\\left(\\mathbf{x}_0\\right)\\right)$, i.e. $g\\left(y\\right) = N_\\mathbf{y}\\left(\\mathbf{x}_0\\right) + E\\left(\\mathbf{y}\\right)$, where \n\\begin{equation*}\n\\begin{aligned}\n||E\\left(\\mathbf{y}\\right)|| &\\leq \\varepsilon(r(\\mathbf{y})) \\cdot r(\\mathbf{y}) \n\\\\&= \\varepsilon(r(\\mathbf{y}))2a||\\mathbf{y}-\\mathbf{y}_0||\\\\\n&=\\mathbf{x}_0+A^{-1}\\left(\\mathbf{y}-\\mathbf{y}_0\\right) + E\\left(\\mathbf{y}\\right)\n\\end{aligned}\n\\end{equation*}\nwhere \n\\begin{equation*}\n\\begin{aligned}\n\\frac{||E\\left(\\mathbf{y}\\right)||}{||\\mathbf{y}-\\mathbf{y}_0||} \\leq 2a\\varepsilon(r(\\mathbf{y}))\n\\end{aligned}\n\\end{equation*}\nand $\\varepsilon(r(\\mathbf{y})) \\to 0$ as $||\\mathbf{y}-\\mathbf{y}_0|| \\to 0$. So the above equation says that $g$ is differentiable at $\\mathbf{y}_0$, and $Dg|_{\\mathbf{y}_0} = A^{-1}$.\n\\end{proof}\n\\end{prop}\n\n\\begin{defi}\nSuppose $V,W \\subset \\R^n$ are open. $f:V \\to W$ is a \\emph{diffeomorphism} if\\\\\n$\\bullet$ $f$ is bijective;\\\\\n$\\bullet$ $f$ and $f^{-1}$ are both $C^1$.\n\\end{defi}\n\n\\begin{thm} (Inverse function theorem)\nSuppose  $U \\subset \\R^n$ is open, $f:U \\to \\R^n$ is $C^1$ with $f\\left(\\mathbf{x}_0\\right) = \\mathbf{y}_0$ and $Df|_{\\mathbf{x}_0}$ is invertible. Then there are open subsets $V \\subset U$ and $\\mathbf{x}_0 \\in V$, $W \\subset R^n$ and $\\mathbf{y}_0 \\in W$ s.t. $f|_V : V \\to W$ is a diffeomorphism. \n\\begin{proof}\nLet $V$ and $W$ be as in Proposition 4. Then $f:V \\to W$ bijectively. Let $g=f^{-1}: W \\to V$. Must show $g$ is $C^1$.\\\\\nWe know $V \\subset B_{r_0} \\left(\\mathbf{x}_0\\right)$ where $Df|_\\mathbf{x}$ is invertible for all $\\mathbf{x} \\in B_r\\left(\\mathbf{x}_0\\right)$ (hypothesis of this subsection).\\\\\nApply proposition 6 with $\\mathbf{x}$ in place of $\\mathbf{x}_0$, we see that $g$ is differentiable at $\\mathbf{x}$, and $Dg|_\\mathbf{x} = \\left(Df|_\\mathbf{x}\\right)^{-1}$.\\\\\n$g$ is differentiable implies that $g$ is continuous. To see $g$ is $C^1$, note that $Dg: W \\to \\mathcal{L}\\left(\\R^n,\\R^n\\right)$ is a composition\n\\begin{equation*}\n\\begin{aligned}\nW &\\to &V &\\to &\\mathcal{L}\\left(\\R^n,\\R^n\\right) &\\to &\\mathcal{L}\\left(\\R^n,\\R^n\\right)\\\\\n\\mathbf{y} &\\to &g\\left(\\mathbf{y}\\right) & & & &\\\\\n& &x &\\to &Df|_\\mathbf{x} & &\\\\\n& & & &A &\\to &A^{-1} \n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{thm}\n\nReformulation: Local change of coordinates:\\\\\nSuppose $U_i = f_i\\left(x_1,...,x_n\\right)$ for $1\\leq i \\leq n$.\\\\\nConsider $J = \\left(\\frac{\\partial u_i}{\\partial x_j}\\right) = \\left(D_j f_i\\right) = $ matrix representing $Df$.\\\\\nIf $\\det \\left(J|_{\\mathbf{x}_0}\\right) \\neq 0$ (i.e. $Df|_{\\mathbf{x}_0}$) then we can use $\\left(U_1,...,u_n\\right)$ as a local system of coordinates near $\\mathbf{x}_0$.\\\\\ni.e. we can solve for $x_j$'s in terms of $u_i$'s:\n\\begin{equation*}\n\\begin{aligned}\nx_j = g_j\\left(u_1,...,u_n\\right).\n\\end{aligned}\n\\end{equation*}\n\n\\begin{eg}\nPolar coordinates: $x=r\\cos \\theta$, $y=r\\sin\\theta$,\n\\begin{equation*}\n\\begin{aligned}\nJ=\\left(\\begin{matrix}\n\\cos\\theta & -r\\sin\\theta\\\\\n\\sin\\theta & r\\cos\\theta\n\\end{matrix}\n\\right)\n\\end{aligned}\n\\end{equation*}\n$\\det J = r$ i.e. there's a good change of coordinates between polar and rectangular coordinates except when $r=0$.\n\\end{eg}\n\n\\subsection{The implicit function theorem}\nLet $F:\\R^n \\to \\R^m$ be $C^1$ ($n \\geq m$), $F\\left(\\mathbf{x}_0\\right) = \\mathbf{y}_0$.\n\nProblem: Describe $F^{-1}\\left(\\mathbf{y}_0\\right)$ near $\\mathbf{x}_0$.\n\n\\begin{eg}\n$F:\\R^2 \\to \\R$, $F\\left(x,y\\right) = x^2-y^2$.\n\n\\begin{tikzpicture}\n\\begin{axis}\n\\addplot {x^2+1};\n\\addplot {-x^2-1};\n\\end{axis}\n\\end{tikzpicture}\n\n\\end{eg}\n\n\\begin{notation}\n$B_\\varepsilon^k = B_\\varepsilon\\left(\\mathbf{0}\\right) \\subset \\R^k$ = $k-$dimensional open ball.\n\\end{notation}\n\n\\begin{thm}\nSuppose $F:\\R^n \\to \\R^m$ is $C^1$, $f\\left(\\mathbf{x}_0\\right) = \\mathbf{y}_0$, and $DF|_{\\mathbf{x}_0}$ is surjective. Then there's an open set $V \\subset \\R^n$, $\\mathbf{x}_0 \\in V$, and a $C^1$ map $G: B_\\varepsilon^{n-m} \\to \\R^n$ such that:\\\\\n1) $F^{-1} \\left(\\mathbf{y}_0\\right) \\cap V = \\im G$;\\\\\n2) $G$ is injective;\\\\\n3) $DG|_\\mathbf{z}$ is injective for all $\\mathbf{z} \\in B_\\varepsilon^{n-m}$.\\\\\ni.e. if $n-m=1$, $B'_\\varepsilon = \\left(-\\varepsilon,\\varepsilon\\right)$, $F^{-1}\\left(\\mathbf{y}_0\\right) \\cap V$ is a paramterized curve;\\\\\nif $n-m = 2$ then this is a parametrized surface.\\\\\nFor general $n-m$, we call this is a parametrized $(n-m)$-manifold.\n\\end{thm}\n\n\\begin{eg}\n$F\\left(x,y\\right) = x^2-y^2$, $DF|_{(x,y)} = \\left[2x,-2y\\right]$ is surjective $\\iff$ $\\left(x,y\\right) \\neq \\left(0,0\\right)$.\n\\end{eg}\n\n\\begin{defi}\n$F^{-1}\\left(\\mathbf{y}_0\\right)$ is \\emph{smooth} at $\\mathbf{x}_0$ if $DF|_{\\mathbf{x}_0}$ is surjective, \\emph{singular} at $\\mathbf{x}_0$ otherwise.\\\\\n$F^{-1}\\left(\\mathbf{y}_0\\right)$ is smooth if it is smooth at all $\\mathbf{x} \\in F^{-1} \\left(\\mathbf{y}_0\\right)$.\n\\end{defi}\n\nProof of theorem:\n\\begin{proof}\n$DF|_{\\mathbf{x}_0}: \\R^n \\to \\R^m$ is surjective. So $K := \\ker DF|_{\\mathbf{x}_0}$ has dimension $(n-m)$. Choose any $\\pi \\in \\mathcal{L}\\left(\\R^n,\\R^m\\right)$ with $\\pi\\left(K\\right) = \\R^{n-m}$. Define $f: \\R^n \\to \\R^m \\times \\R^{n-m} = \\R^n$ by $f\\left(\\mathbf{x}\\right) = \\left(F\\left(\\mathbf{x}\\right),\\pi\\left(\\mathbf{x}\\right)\\right)$. So $Df:\\R^n \\to \\R^m \\oplus \\R^{n-m}$.\\\\\n$Df_{\\mathbf{x}_0} \\left(\\mathbf{v}\\right) = \\left(DF|_{\\mathbf{x}_0} \\left(\\mathbf{v}\\right), \\pi\\left(\\mathbf{v}\\right)\\right)$ since $D\\pi = \\pi$.\\\\\nClaim: $Df|_{\\mathbf{x}_0}$ is an isomorphism: If $Df|_{\\mathbf{x}_0} \\left(\\mathbf{v}\\right) = \\mathbf{0}$, then $DF|_{\\mathbf{x}_0} \\left(\\mathbf{v}\\right) = 0 \\implies \\mathbf{v} \\in K$. But $\\pi: K \\to \\R^{n-m}$ is an isomorphism, so $\\pi\\left(\\mathbf{v}\\right) = 0 \\implies \\mathbf{v} = 0$. So $\\ker Df|_{\\mathbf{x}_0} = \\left\\{\\mathbf{0}\\right\\}$ $\\implies$ $Df|_{\\mathbf{x}_0}$ is an isomorphism.\n\nBy the inverse function theorem, there exists $V \\subset \\R^n$, $\\mathbf{x}_0 \\in V$, $W \\subset \\R^m \\times \\R^{n-m}$, $\\left(\\mathbf{y}_0,\\pi\\left(\\mathbf{x}_0\\right)\\right) \\in W$, s.t. $f:V \\to W$ is an diffeomorphism. Let $g = f^{-1} : W \\to V$\n\nThen $F^{-1}\\left(\\mathbf{y}_0\\right) \\cap V = f^{-1} \\left(\\mathbf{y}_0 \\times \\R^{n-m}\\right) \\cap V$, so $g\\left(\\mathbf{y}_0 \\times \\R^{n-m} \\right) \\cap W = F^{-1}\\left(\\mathbf{y}_0\\right) \\cap V$.\n\nDefine $G\\left(\\mathbf{z}\\right) = g\\left(\\mathbf{y}_0,\\mathbf{z}_0\\right)$, $g$ is injective implies that $G$ is injective, and $D_g$ injective $\\implies$ $DG$ injective.\n\\end{proof}\n\n\\end{document}", "meta": {"hexsha": "d7671b4587544a385bccb443d114307bdb77ad88", "size": 115176, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/Analysis II.tex", "max_stars_repo_name": "raoxiaojia/raoxiaojia.github.io", "max_stars_repo_head_hexsha": "d20c23a64794b500f2e0356fd01017ee31830fa2", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-25T17:34:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-25T17:34:25.000Z", "max_issues_repo_path": "Notes/Analysis II.tex", "max_issues_repo_name": "raoxiaojia/raoxiaojia.github.io", "max_issues_repo_head_hexsha": "d20c23a64794b500f2e0356fd01017ee31830fa2", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/Analysis II.tex", "max_forks_repo_name": "raoxiaojia/raoxiaojia.github.io", "max_forks_repo_head_hexsha": "d20c23a64794b500f2e0356fd01017ee31830fa2", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9634641407, "max_line_length": 542, "alphanum_fraction": 0.6336302702, "num_tokens": 48726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.7027911371665393}}
{"text": "The mathematical laws describing the deformation of a solid body are summarized in this section. First, the kinematic laws governing the motion of each material point belonging to a solid are considered. Then \\textit{strain} measures are associated with internal forces through the thermodynamic framework so that \\textit{constitutive equations} are derived. For a more exhaustive review of governing equations, see for instance \\cite{Belytschko,Foundation_of_elasticity,Truesdell,Simo}.\n\n\\subsection{Kinematic laws -- Strain measures}\nConsider a three-dimensional solid with volume denoted by $\\Omega \\subset \\Rbb^3$ bounded by the surface $\\partial \\Omega$. This body undergoes external forces that can either be localized on a part of the external surface of the body (\\textit{i.e. surface forces}) or act in the whole solid domain (\\textit{i.e. volume forces}). Due to the presence of such loads, the domain may change within the time interval $\\tau = \\[0,T\\]$ and is hence written as a function of time $\\Omega(t)$ ($t\\in \\tau$). The state of the solid at time $t=0$, corresponding to a non-deformed state with volume $\\Omega(t=0)=\\Omega_0$, is referred to as the \\textit{initial configuration}. Some problems require the use of a \\textit{reference configuration} that can be deformed and to which equations are referred. In what follows, the reference and initial configurations are identical. At a given time $t>0$, the volume is $\\Omega(t)=\\Omega_t$ and the state of the solid corresponds to the \\textit{current configuration}. These configurations are depicted in figure \\ref{fig:deformationFunction}.\n\\begin{figure}[h]\n  \\centering\n  \\input{chapter2/pgfFigures/deformationFunction}\n  \\caption{Deformation of a solid body between a reference state $\\Omega_0$ to a subsequent state $\\Omega_t$.}\n  \\label{fig:deformationFunction}\n\\end{figure}\nThe points of $\\Rbb^3$ are located with \\textit{Eulerian} or \\textit{spatial coordinates} $\\vect{x}=x_i\\vect{e}_i$ while material particles in the reference configuration are located with \\textit{Lagrangian coordinates} $\\vect{X}=X_\\alpha \\vect{E}_\\alpha$.\n%Two different bases $(\\vect{E}_1,\\vect{E}_2,\\vect{E}_3)$ and $(\\vect{e}_1,\\vect{e}_2,\\vect{e}_3)$, that may be different are not, allow the use of \\textit{Lagrangian coordinates} and $\\vect{E}_\\alpha$ or \\textit{Eulerian coordinates} $\\vect{x}=x_i\\vect{e}_i$ respectively. %Lagrangian coordinates give the location of material particles in the reference configuration while Eulerian coordinates are used to locate the point of space at which a particle may be at a given time.\n%In the reference configuration, all material particles are located by their position vectors: $\\vect{X}=X_\\alpha \\vect{E}_\\alpha$.\nAt time $t$, the particle initially located at $\\vect{X}$ may have moved to a different position given by the smooth mapping $\\vect{\\phi}(\\vect{X},t)=\\phi_i(\\vect{X},t)\\vect{e}_i$, providing the path of every particle of the solid during the deformation.\nThus, the current volume of the solid is defined by means of Eulerian coordinates and the \\textit{deformation function} $\\vect{\\phi}(\\vect{X},t)$ as: $\\Omega(t)=\\{\\vect{x}\\in \\Rbb^3: \\vect{x}=\\vect{\\phi}(\\vect{X},t),\\: \\vect{X},t\\in\\Omega_0\\times \\tau\\}$.\n% The restriction of Eulerian coordinates to the current volume, namely $\\vect{x}\\in\\Omega(t)$, allows to write the bijective relation $\\vect{x}=\\vect{\\phi}(\\vect{X},t)$.\n%Thus, the mapping $\\vect{\\phi}$ provides the path of every particle of the solid during the deformation.\n% In the Lagrangian coordinates system, particles are tracked during the deformation while the \\textit{Eulerian coordinates}, denoted by $\\vect{x}=x_i\\vect{e}_i$, correspond to a \\textit{spatial description}.\nNote that in the above definitions Greek indices are used for quantities evaluated in the reference configuration whereas Latin ones refer to quantities defined in the current configuration.\n\nThe \\textit{displacement} and \\textit{velocity} vectors of a particle at time $t$ are respectively:\n\\begin{align}\n    &\\vect{u}(\\vect{X},t)=\\vect{\\phi}(\\vect{X},t) - \\vect{X} \\qquad \\forall\\:\\: \\vect{X},t \\in \\Omega_0\\times \\tau  \\label{eq:displacement}\\\\\n    &\\vect{v}(\\vect{X},t)=\\drond{\\vect{\\phi}}{t}(\\vect{X},t) = \\vect{\\dot{\\phi}}(\\vect{X},t) \\qquad  \\forall\\: \\: \\vect{X},t \\in \\Omega_0\\times \\tau  \\label{eq:velocity}\n\\end{align}\nwhere the superposed dot denotes the material time derivative. The second-order two-point \\textit{deformation gradient} tensor is defined as:\n\\begin{equation}\n  \\label{eq:F_phi}\n    \\tens{F}=\\nablat_0 \\vect{\\phi} (\\vect{X},t)\n\\end{equation}\nwhere $\\nablat_0 (\\bullet)$ is the gradient operator in the reference configuration. This tensor can also be written by using equation \\eqref{eq:displacement}:\n\\begin{equation}\n  \\tens{F}= \\nablat_0 \\vect{u}(\\vect{X},t) + \\tens{I} \\label{eq:F_displacement}\n\\end{equation}\nwith $\\tens{I}$, the second-order identity tensor. The deformation gradient tensor characterizes the variations of lengths, angles, areas and volumes. Indeed, the infinitesimal vector, oriented surface and volume elements in the reference configuration, respectively denoted by $\\vect{dX},\\vect{dS}$ and $dV$, transform respectively to:\n\\begin{equation}\n  \\label{eq:transport_equations}\n  \\begin{aligned}\n    & dx_i=F_{i\\alpha}dX_\\alpha \\\\\n    & ds_i=J F_{\\alpha i}^{-1}dS_{\\alpha} \\\\\n    & dv=JdV \n  \\end{aligned}\n\\end{equation}\nin the current configuration. Transport equations \\eqref{eq:transport_equations} involve the determinant of the deformation gradient $J=\\det(\\tens{F})>0$, also called the \\textit{Jacobian of the deformation}.\n\nSince it accounts for changes in lengths and angles (\\textit{i.e. the change of shape of a body}), the deformation gradient is one strain measure among others. For instance, one also defines the \\textit{right Cauchy-Green} and the \\textit{Green-Lagrange} tensors as:\n\\begin{equation*}\n  \\tens{C}=\\tens{F}^T\\tens{F} \\quad ; \\quad \\tens{E}=\\frac{1}{2}(\\tens{C}-\\tens{I})\n\\end{equation*}\nrespectively. Making use of equation \\eqref{eq:F_displacement}, the Green-Lagrange tensor reads:\n\\begin{equation*}\n  \\tens{E}=\\frac{1}{2}(\\nablat_0 \\vect{u} + \\nablat_0 \\vect{u}^T + \\nablat_0 \\vect{u}^T \\nablat_0 \\vect{u})\n\\end{equation*}\nIn particular, when a deformation involves displacement vectors such that $\\norm{\\nablat_0 \\vect{u}} \\ll 1$, the last term of the previous definition can be neglected, leading to:\n\\begin{equation}\n  \\label{eq:epsilon}\n  \\tens{E} \\approx \\frac{1}{2}(\\nablat_0 \\vect{u} + \\nablat_0 \\vect{u}^T) = \\tens{\\eps}\n\\end{equation}\nwith $\\tens{\\eps}$ the symmetric \\textit{linearized strain tensor}. Such deformations fall in the \\textit{small strains} framework and are characterized by small strains but possibly large displacements. Furthermore, when the deformation leads to a displacement vector $\\frac{\\norm{\\vect{u}}}{L} \\ll 1$, where $L$ is a characteristic length of the domain, reference and current configurations are considered as identical within equations of the Initial Boundary Value Problem (IBVP). The aforementioned situations correspond to the \\textit{linearized geometrical} framework  or \\textit{infinitesimal theory}.\n\n\\subsection{Balance equations}\n% In this section a solid domain $\\Omega(t)$ undergoing a deformation is still considered within the time interval $\\tau = \\[0,T\\]$.\nThe time derivative of equations \\eqref{eq:F_phi} and \\eqref{eq:epsilon} combined with the definition of the velocity field \\eqref{eq:velocity} yield respectively:\n\\begin{equation}\n  \\begin{aligned}\n    & \\tens{\\dot{F}} - \\nablat_0\\vect{v} = \\tens{0} \\\\\n    & \\tens{\\dot{\\eps}} - \\nablat^s\\vect{v} = \\tens{0}\n  \\end{aligned} \\label{eq:geometrical_conservation}\n\\end{equation}\nwhere $\\nablat^s(\\bullet)$ denotes the symmetric gradient operator. By rewriting the gradient operators as:\n\\begin{align}\n  & \\nablat_0 \\vect{v} = \\nablav_0 \\cdot \\(\\vect{v}\\otimes\\tens{I}\\) \\\\\n  & \\nablat^s \\vect{v} = \\frac{1}{2}\\nablav \\cdot \\(\\vect{v}\\otimes\\tens{I}+\\tens{I}\\otimes \\vect{v}\\)\n\\end{align}\nwith $\\nablav_0 \\cdot \\(\\bullet\\)$ and $\\nablav \\cdot\\(\\bullet\\)$, the right divergence operators in reference and current configurations respectively. With these forms of gradient operators, geometrical relations \\eqref{eq:geometrical_conservation} can be written as kinematic or geometrical balance laws \\cite{Plohr,Haider_FVM,Gil_HE,Gil_SPH_HE}:\n\\begin{align}\n  & \\tens{\\dot{F}} - \\nablav_0 \\cdot \\(\\vect{v}\\otimes\\tens{I}\\) = \\tens{0} \\label{eq:HE_kinematic} \\\\\n  & \\tens{\\dot{\\eps}} - \\frac{1}{2}\\nablav \\cdot \\(\\vect{v}\\otimes\\tens{I}+\\tens{I}\\otimes \\vect{v}\\) = \\tens{0} \\label{eq:HPP_kinematic}\n\\end{align}\n\nThen, assuming that the mass of some amount of matter remains constant during the deformation, one writes the conservation of mass in integral form:\n\\begin{equation*}\n  \\int_\\Omega \\rho dv = \\int_{\\Omega_0} \\rho_0 dV \\qquad \\forall \\: t \\in  \\tau,\\: \\forall \\:\\Omega_0\n\\end{equation*}\nwhich, with the third transport formula reads:\n\\begin{equation}\n  \\label{eq:mass_conservation_law}\n  \\int_{\\Omega_0} \\(J\\rho - \\rho_0\\) dV = 0 \\qquad \\forall \\:\\Omega_0\n\\end{equation}\nSince equation \\eqref{eq:mass_conservation_law} holds regardless of the volume $\\Omega_0$, the integrand must vanish so that the local conservation of mass is written:\n\\begin{equation}\n  \\label{eq:mass_balance}\n  \\rho\\(\\vect{\\phi}(\\vect{X},t),t\\) = \\frac{\\rho_0\\(\\vect{X}\\)}{J} \\qquad \\forall \\: \\vect{X},t \\: \\in \\Omega_0\\times \\tau\n\\end{equation}\n\nFurthermore, \\textit{Newton's second law} states the equilibrium between inertia and external forces undergone by a solid $\\Omega$. In the current configuration this conservation law consists of the \\textit{translational} and \\textit{rotational} balances, also known as \\textit{linear momentum} and \\textit{angular momentum} balance equations, which are respectively:\n\\begin{subequations}\n  \\begin{alignat}{1}\n    \\label{eq:linear_momentum}\n    & \\ddroit{}{t}\\int_\\Omega \\rho \\vect{v} dv = \\int_{\\partial \\Omega} \\vect{t} ds + \\int_{\\Omega} \\rho\\vect{b}dv \\qquad \\forall \\: t \\in  \\tau,\\: \\forall \\:\\Omega  \\\\\n    \\label{eq:angular_momentum}\n    & \\ddroit{}{t}\\int_\\Omega \\rho \\vect{x} \\times \\vect{v} dv = \\int_{\\partial \\Omega} \\vect{x} \\times\\vect{t} ds + \\int_{\\Omega} \\rho \\vect{x} \\times\\vect{b}dv \\qquad \\forall \\: t \\in  \\tau,\\: \\forall \\:\\Omega\n  \\end{alignat}\n\\end{subequations}\nwhere $\\vect{t}$ and $\\vect{b}$ denote surface and volume forces and the cross operator denotes the vector product. The second-order \\textit{Cauchy stress tensor} $\\tens{\\sigma}$ is then introduced by using Cauchy's theorem $\\vect{t}=\\tens{\\sigma}\\cdot \\vect{n}$ where $\\vect{n}$ is the outward normal vector to the surface element $ds$. \n\n\\begin{theorem}[Ostrogradski]\n  The \\textbf{divergence theorem} relates the flow of a quantity through a closed surface $\\partial\\Omega$ to the divergence of this quantity inside the volume $\\Omega$ delimited by $\\partial \\Omega$:\n\\begin{equation}\n  \\label{eq:Ostrogradski_th}\n  \\int_{\\partial \\Omega} (\\bullet)\\cdot \\vect{n}\\:ds=\\int_\\Omega \\nablav \\cdot (\\bullet) \\: dv \\qquad \\forall\\:\\Omega\n\\end{equation}\n\\end{theorem}\n\n% \\begin{theorem}[Reynolds]\n%   The \\textbf{Reynolds transport theorem} relates the flow of a quantity through a closed surface $\\partial\\Omega$ to the divergence of this quantity inside the volume $\\Omega$ delimited by $\\partial \\Omega$:\n% \\begin{equation}\n%   \\label{eq:Ostrogradski_th}\n%   \\int_{\\partial \\Omega} (\\bullet)\\cdot \\vect{n}\\:ds=\\int_\\Omega \\nablav \\cdot (\\bullet) \\: dv \\qquad \\forall\\:\\Omega\n% \\end{equation}\n% \\end{theorem}\n\n\\begin{definition}\n  \\label{def:Piola_transform}\n  The Piola transform $\\tens{T}^P$ of a second-order tensor $\\tens{T}$ is defined as:\n  \\begin{equation*}\n    \\tens{T}^P=J\\tens{T}\\cdot\\tens{F}^{-T}\n  \\end{equation*}\n  and satisfies:\n  \\begin{equation*}\n    \\nablav_0\\cdot \\tens{T}^P = J \\nablav \\cdot \\tens{T}\n  \\end{equation*}\n\\end{definition}\n\nThe conservation of linear momentum \\eqref{eq:linear_momentum}, combined with the volume transport theorem \\eqref{eq:transport_equations}, reads in the reference configuration:\n\\begin{equation}\n  \\label{eq:1}\n    \\ddroit{}{t}\\int_{\\Omega_0} \\rho_0 \\vect{v} \\: dV = \\int_{\\Omega_0} J\\nablav \\cdot\\tens{\\sigma} \\: dV + \\int_{\\Omega_0} \\rho_0\\vect{b}\\:dV \\qquad \\forall \\: t \\in  \\tau,\\: \\forall \\:\\Omega_0\n\\end{equation}\n% Thus, by using the divergence theorem \\eqref{eq:Ostrogradski_th} in the second law of Newton combined with the conservation of mass and the transport theorem, one gets:\n% \\begin{equation}\n%   \\label{eq:Linear_momentum_conservation_eulerian}\n%   \\int_{\\Omega} \\( \\rho \\vect{\\dot{v}} - \\nablav \\cdot \\tens{\\sigma} -  \\rho\\vect{b} \\) dV = \\vect{0} \\qquad \\forall \\:t \\in  \\tau,\\: \\forall \\:\\Omega\n% \\end{equation}\n% The transport formula of volume elements \\eqref{eq:transport_equations} are then combined to the mass balance equation \\eqref{eq:mass_balance} in order to write the equation \\eqref{eq:Linear_momentum_conservation_eulerian} in the reference configuration:\n% \\begin{equation}\n%   \\int_{\\Omega_0} \\( \\rho_0 \\vect{\\dot{v}} - J \\nablav \\cdot \\tens{\\sigma} -  \\rho_0\\vect{b} \\) dV = \\vect{0} \\qquad \\forall \\: t \\in\\tau,\\: \\forall \\:\\Omega_0\n% \\end{equation}\nor, by using definition \\ref{def:Piola_transform}:\n\\begin{equation}\n  \\label{eq:Linear_momentum_conservation}\n  \\int_{\\Omega_0} \\( \\rho_0 \\vect{\\dot{v}} - \\nablav_0 \\cdot \\tens{\\Pi} -  \\rho_0\\vect{b} \\) dV = \\vect{0} \\qquad \\forall \\: t \\in\\tau,\\: \\forall \\:\\Omega_0\n\\end{equation}\nwhere the \\textit{first Piola-Kirchhoff stress tensor} (PK1) $\\tens{\\Pi}=J\\tens{\\sigma}\\cdot\\tens{F}^{-T}$ is the Piola transform of Cauchy stress tensor. Thus, the vanishing of the integrand in equation \\eqref{eq:Linear_momentum_conservation} yields the balance equation of the \\textit{Lagrangian linear momentum}:\n\\begin{equation}\n  \\label{eq:Lagrangian_linear_momentum}\n  \\rho_0 \\vect{\\dot{v}} - \\nablav_0 \\cdot \\tens{\\Pi} = \\rho_0 \\vect{b} \\qquad \\forall \\: \\: \\vect{X},t \\in \\Omega_0 \\times \\tau \n\\end{equation}\nor equivalently for the current configuration:\n\\begin{equation}\n  \\label{eq:HPP_linear_momentum}\n  \\rho \\vect{\\dot{v}} - \\nablav \\cdot \\tens{\\sigma} = \\rho \\vect{b}  \\qquad \\forall \\: \\: \\vect{x},t \\in \\Omega \\times \\tau \n\\end{equation}\nOn the other hand, the conservation of angular momentum \\eqref{eq:angular_momentum} leads to the symmetry of Cauchy stress tensor $\\tens{\\sigma}=\\tens{\\sigma}^T$, or equivalently from the definition of PK1 tensor, $\\tens{\\Pi}\\cdot \\tens{F}^T=\\tens{\\Pi}^T\\cdot \\tens{F}$ \\cite{Foundation_of_elasticity}.\n\nWe complete the set of balance laws by considering the \\textit{first law of thermodynamics}. This law is a balance between the rates of change of \\textit{kinetic} and \\textit{internal} energies, the power of external forces, and the amount of heat entering the system as \\textit{volume} or \\textit{surface heat sources}.\n\\begin{equation*}\n  \\ddroit{}{t}\\int_{\\Omega} \\(\\frac{1}{2}\\rho \\vect{v}\\cdot\\vect{v} + \\rho e\\) dv = \\int_{\\partial \\Omega} \\(\\tens{\\sigma}\\cdot\\vect{n}\\)\\cdot\\vect{v} \\: ds + \\int_{\\Omega} \\rho\\vect{b}\\cdot\\vect{v} \\: dv + \\int_{\\Omega} \\rho r \\:dv - \\int_{\\partial \\Omega} \\vect{q}\\cdot\\vect{n} \\: ds \\qquad \\forall \\: t \\in  \\tau ,\\: \\forall \\:\\Omega\n\\end{equation*}\nwhere $\\vect{q}$ is the outward heat flux vector, $r$ is a volume heat source and $e$ is the internal energy density. The divergence theorem \\eqref{eq:Ostrogradski_th} yields:\n\\begin{equation*}\n\\ddroit{}{t}\\int_{\\Omega} \\(\\frac{1}{2}\\rho \\vect{v}\\cdot\\vect{v} + \\rho e\\) dv = \\int_{\\Omega} \\(\\nablav\\cdot(\\tens{\\sigma}\\cdot\\vect{v}) +  \\rho\\vect{b}\\cdot\\vect{v} \\) dv + \\int_{\\Omega} \\rho r \\: dv  - \\int_{\\partial \\Omega} \\vect{q}\\cdot\\vect{n} \\: ds \\qquad \\forall \\: t \\in  \\tau ,\\: \\forall \\:\\Omega\n\\end{equation*}\nThe transport of this relation in the reference configuration and introduction of the Lagrangian linear momentum \\eqref{eq:Lagrangian_linear_momentum} and of kinetic conservation laws \\eqref{eq:HE_kinematic} lead to:\n\\begin{equation}\n  \\label{eq:conservation_law_energy}\n  \\int_{\\Omega_0} \\rho_0 \\dot{e} dV = \\int_{\\Omega_0} \\tens{\\Pi}:\\tens{\\dot{F}}\\: dV + \\int_{\\Omega_0} \\(\\rho_0 r  - \\nablav_0 \\cdot \\vect{Q}\\) dV \\qquad \\forall \\: t \\in  \\tau \n\\end{equation}\nwhere $\\vect{Q}=J\\vect{q}\\cdot \\tens{F}^{-1}$ is the Lagrangian heat flux vector. One thus deduces the balance equation of internal energy in the reference configuration:\n\\begin{equation}\n  \\label{eq:energy_balance}\n  \\rho_0 \\dot{e} -  \\tens{\\Pi}:\\tens{\\dot{F}}  + \\nablav_0 \\cdot \\vect{Q}  = \\rho_0 r \\qquad \\forall \\: \\: \\vect{X},t \\in \\Omega_0 \\times \\tau \n\\end{equation}\nFinally, the small strain version of equation \\eqref{eq:energy_balance} is: \n\\begin{equation}\n  \\label{eq:energy_balance_euler}\n  \\rho \\dot{e} -  \\tens{\\sigma}:\\tens{\\dot{\\eps}}  + \\nablav \\cdot \\vect{q}  = \\rho r \\qquad \\forall \\: \\: \\vect{x},t \\in \\Omega \\times \\tau \n\\end{equation}\nStrain and stress are then conjugate fields through an energy function. The former are referred to as \\textit{state variables} describing the evolution of the thermodynamic system while the latter are \\textit{thermodynamic forces} governed by \\textit{constitutive equations}. In what follows, such constitutive equations are derived.\n\n\\subsection{Constitutive equations -- Thermodynamics}\n\\label{sec:constitutive-equations}\nThe closure of the continuum equations is given by constitutive equations for the stress. Once and for all, we consider here constitutive models within the \\textit{Generalized Standard Materials} (GSM) framework \\cite{GSM}.\n\n\\subsubsection*{The general hyperelasticity formulation}\nFirst, the \\textit{Clausius-Duhem} inequality resulting from combination of first and second laws of thermodynamics, reads: \n\\begin{equation}\n  \\label{eq:Clausius-Duhem}\n  \\underbrace{\\phantom{\\frac{1}{\\theta}} \\tens{\\Pi}:\\tens{\\dot{F}} + \\rho_0 \\(\\theta \\dot{\\eta} -\\dot{e}\\)}_{\\Dscr^{int}} \\:  \\underbrace{-\\:\\frac{1}{\\theta} \\vect{q} \\cdot \\nablav_0 \\theta}_{\\Dscr^{th}} \\geq 0  \\qquad \\forall \\: \\: \\vect{X},t \\in \\Omega_0 \\times \\tau \n\\end{equation}\nwhere $\\theta$ and $\\eta$ denote the temperature and the entropy, and $\\Dscr^{int}$ and $\\Dscr^{th}$ are respectively the mechanical and thermal dissipations. The relation \\eqref{eq:Clausius-Duhem} becomes an equality for \\textit{reversible} processes and a strict inequality for \\textit{irreversible} ones. Furthermore, a widely used assumption consists in considering that mechanical and thermal dissipations simultaneously satisfy non-negativeness.\nNote that the \\textit{Fourier's law} of conduction is based on the non-negativeness of the thermal dissipation and leads to the following definition of the heat flux vector in order to ensure the positiveness of the thermal dissipation:\n\\begin{equation*}\n  \\label{eq:Fourier_law}\n  \\vect{q}=-\\tens{k}\\cdot\\nablav_0 \\theta\n\\end{equation*}\nwhere $\\tens{k}$ is a positive-definite second-order tensor.\n\nWe assume that the internal energy density is a function of strain, entropy and additional internal variables $\\Vc_p \\: (1\\leq p \\leq N)$, describing irreversible processes. The Helmholtz free energy density on the other hand, defined as the \\textit{Legendre transform} of internal energy, is a function of temperature and not of entropy: $\\psi\\(\\tens{F},\\theta,\\Vcb\\)=e\\(\\tens{F},\\eta,\\Vcb\\)-\\theta \\eta$. The free energy density is supposed \\textit{objective} or \\textit{frame indifferent} \\cite[p.255]{Simo}, concave with respect to temperature and convex with respect to other variables. The mechanical dissipation thus reads:\n\\begin{equation*}\n  \\Dscr^{int} = \\tens{\\Pi}:\\tens{\\dot{F}} - \\rho_0 \\(\\dot{\\psi} +\\eta \\dot{\\theta}\\) \n\\end{equation*}\nor, by introducing the time derivative of the Helmholtz free energy density $\\dot{\\psi} = \\drond{\\psi}{\\tens{F}}:\\tens{\\dot{F}} + \\drond{\\psi}{\\theta}\\dot{\\theta} + \\drond{\\psi}{\\Vcb}\\dot{\\Vcb}$\n\\begin{equation}\n  \\label{eq:Dint_psi_factor}\n  \\Dscr^{int} = \\(\\tens{\\Pi}- \\rho_0 \\drond{\\psi}{\\tens{F}} \\):\\tens{\\dot{F}} - \\rho_0 \\(\\drond{\\psi}{\\theta} +\\eta\\) \\dot{\\theta}  - \\rho_0\\drond{\\psi}{\\Vcb}\\dot{\\Vcb} \n\\end{equation}\n\n\nSince the mechanical dissipation must be non-negative regardless of the nature of the transformation, it must in particular vanish for a reversible isothermal process (\\textit{i.e. $\\theta=const$}) for which every additional internal variable is constant (\\textit{i.e. $\\dot{\\Vc}=0$}). With these considerations, we are left with the relation:\n\\begin{equation*}\n  \\( \\tens{\\Pi} - \\rho_0\\drond{\\psi}{\\tens{F}} \\): \\tens{\\dot{F}} = 0\n\\end{equation*}\nholding regardless of the deformation, and hence:\n\\begin{equation}\n  \\label{eq:PK1_definition}\n  \\rho_0\\drond{\\psi}{\\tens{F}} = \\tens{\\Pi}\n\\end{equation}\nA material is said \\textit{hyperelastic} if there exists a \\textit{stored energy density function} $\\rho_0\\psi$ from which can be derived the first Piola-Kirchhoff stress tensor \\cite[p.8]{Foundation_of_elasticity}. \n\nSimilar considerations lead to the state laws for entropy and are assumed for additional thermodynamic forces associated with internal variables $\\Vcb$:\n\\begin{equation}\n  \\label{eq:thermodynamic_forces}\n  \\drond{\\psi}{\\theta} = - \\eta \\quad ; \\quad \\rho_0\\drond{\\psi}{\\Vcb}=-\\Acb\n\\end{equation}\n\n\n\\begin{remark}\n  \\label{rq:isothermal_deformation}\n  Temperature has been introduced as a state variable and requires the first principle of thermodynamics, rewritten as the heat equation, in order to close the system:\n  \\begin{equation*}\n    \\rho_0 C \\dot{\\theta} = \\rho_0 r - \\nablav_0 \\cdot \\vect{Q} - \\rho_0 \\drond{\\psi}{\\Vcb}\\dot{\\Vcb} + \\theta \\(\\drond{\\tens{\\Pi}}{\\theta}:\\tens{\\dot{F}} - \\drond{\\Acb}{\\theta}\\dot{\\Vcb} \\)\n  \\end{equation*}\n  Nevertheless, we will restrict our attention in the following to isothermal deformations so that temperature can be omitted and internal energy balance equations \\eqref{eq:energy_balance} or \\eqref{eq:energy_balance_euler} are not considered.\n  % automatically satisfied. Indeed, for isothermal processes the heat equation leads to:\n  % \\begin{equation*}\n  %   \\rho_0 r - \\nablav_0 \\cdot \\vect{Q} = \\rho_0 \\drond{\\psi}{\\Vcb}\\dot{\\Vcb}\n  % \\end{equation*}\n  % which, once introduced in the energy balance \\eqref{eq:energy_balance} yields:\n  % \\begin{equation*}\n  %   \\rho_0 \\dot{e} - \\tens{\\Pi}:\\tens{\\dot{F}} = \\rho_0 \\drond{\\psi}{\\Vcb}\\dot{\\Vcb}\n  % \\end{equation*}\n  % By using the time derivative of free energy density and noting that $\\eta=-\\drond{\\psi}{\\theta} =0$, we get that each side of the previous equation simplify.\n\\end{remark}\n\nFor isothermal reversible deformations in hyperelastic solids, the time derivative of equation \\eqref{eq:PK1_definition} leads to:\n\\begin{equation}\n  \\label{eq:HE_tangent}\n  \\tens{\\dot{\\Pi}} = \\rho_0\\ddrond{\\psi}{\\tens{F}}{\\tens{F}}:\\tens{\\dot{F}} = \\Hbb:\\tens{\\dot{F}}   \n\\end{equation}\nwhere $\\Hbb$ is the fourth-order \\textit{tangent modulus} tensor (major symmetric).\n%\\subsubsection*{Examples of hyperelastic constitutive laws}\nThe above discussion is now specified to constitutive models that will be used in the remainder of the manuscript.\n\\begin{example}[Nearly incompressible Neo-Hookean]\nThe nearly incompressible neo-Hookean hyperelastic model is well-suited to describe rubber-like materials and is based on the polyconvex stored energy function (\\textit{i.e. convex with respect to all its arguments}):\n\\begin{equation}\n  \\label{eq:neo-hook_energy}\n  \\rho_0 \\psi(J,\\tens{F})= \\frac{\\kappa}{2}(J-1)^2 + \\frac{\\mu}{2}\\[J^{-2/3} (\\tens{F}:\\tens{F})-3 \\]\n\\end{equation}\nwhere $\\kappa$ is the bulk modulus and $\\mu$ the Lam\\'e shear modulus. The first Piola-Kirchhoff stress and the acoustic tensor $A_{ij}=N_\\alpha H_{i\\alpha j\\beta} N_\\beta$ are for this model \\cite{Haider_FVM}:\n\\begin{equation}\n  \\label{eq:PK1_neo-hook}\n  \\tens{\\Pi} = \\mu J^{-2/3} \\[\\tens{F}- \\frac{1}{3}\\(\\tens{F}:\\tens{F}\\) \\tens{F}^{-T}\\] + \\kappa \\(J-1\\)\\tens{H}\n\\end{equation}\nand\n\\begin{equation}\n  \\label{eq:neo-hook_acoustic}\n  \\begin{split}\n      \\tens{A}=\\[\\frac{5}{9}\\mu J^{-8/3}\\(\\tens{F}:\\tens{F}\\)   + \\kappa \\]&(\\tens{H}\\cdot\\vect{N})\\otimes\\(\\tens{H}\\cdot\\vect{N} \\)  + \\mu J^{-2/3} \\tens{I}  \\\\ &-\\frac{2}{3}\\mu J^{-5/3}\\[(\\tens{H}\\cdot\\vect{N})\\otimes\\(\\tens{F}\\cdot\\vect{N} \\)\t+  (\\tens{F}\\cdot\\vect{N})\\otimes\\(\\tens{H}\\cdot\\vect{N} \\)\\]\n  \\end{split}\n\\end{equation}\nwhere $\\tens{H}=J\\tens{F}^{-T}$ is the \\textit{adjoint tensor} of the deformation gradient. The polyconvexity of this model ensures the positive definiteness of the acoustic tensor \\eqref{eq:neo-hook_acoustic} \\cite{Kluth}.\n\\end{example}\n\n\\begin{example}[Saint-Venant-Kirchhoff]\nThe Saint-Venant-Kirchhoff hyperelastic model is based on the stored energy function:\n\\begin{equation}\n  \\label{eq:SVK_energy}\n  \\rho_0\\psi=\\frac{1}{8}\\(\\tens{F}^T\\tens{F}- \\tens{I}\\):\\Cbb:\\(\\tens{F}^T\\tens{F}- \\tens{I}\\)\n\\end{equation}\nwhere $\\Cbb$ is the fourth-order elasticity tensor defined as: $C_{i\\alpha j\\beta}= \\lambda \\delta_{i\\alpha}\\delta_{j\\beta} + \\mu \\(\\delta_{ij}\\delta_{\\alpha\\beta}+\\delta_{i\\beta}\\delta_{j\\alpha}\\)$, with Lamé parameters $(\\lambda,\\mu)$. By differentiating the stored energy function \\eqref{eq:SVK_energy} with respect to the deformation gradient, the PK1 stress is:\n\\begin{equation}\n  \\label{eq:SVK_PK1}\n  \\tens{\\Pi} = \\frac{1}{2}\\lambda \\(\\tens{F}:\\tens{F}- 3\\) \\tens{F} + \\mu\\tens{F}\\(\\tens{F}^T\\tens{F}- \\tens{I}\\)\n\\end{equation}\nwhose derivative with respect to $\\tens{F}$ yields the tangent modulus:\n\\begin{equation}\n  \\label{eq:SVK_tangent}\n  \\Hbb = \\lambda \\[\\tens{F}\\otimes\\tens{F} + \\frac{1}{2} (\\tens{F}:\\tens{F}- 3)\\Ibb\\]+ \\mu\\(\\Bbb- \\Ibb \\)\n\\end{equation}\nwith $B_{i\\alpha j \\beta}=F_{k\\alpha}F_{k\\beta}\\delta_{ij} + F_{j\\alpha}F_{i\\beta} +F_{i\\mu} F_{j\\mu}\\delta_{\\alpha\\beta}$ and the fourth order identity tensor $I_{i\\alpha j \\beta}=\\delta_{ij}\\delta_{\\alpha \\beta}$. The previous tangent modulus finally leads to the acoustic tensor:\n\\begin{equation}\n  \\label{eq:SVK_acoustic}\n  \\begin{split}\n    \\tens{A} = \\lambda \\[\\vphantom{\\frac{1}{2}} (\\tens{F}\\cdot\\vect{N})\\otimes(\\tens{F}\\cdot\\vect{N}) \\right.+ &\\left.\\frac{1}{2} (\\tens{F}:\\tens{F}- 3)\\tens{I}\\] \\\\\n    + & \\mu\\[(\\tens{F}\\cdot\\vect{N})\\cdot(\\tens{F}\\cdot\\vect{N})\\tens{I} + (\\tens{F}\\cdot\\vect{N})\\otimes(\\tens{F}\\cdot\\vect{N}) + \\tens{F}\\cdot\\tens{F}^T- \\tens{I} \\]\n  \\end{split}\n\\end{equation}\nEven though this model can lead to non-physical solutions, as we shall see in section \\ref{sec:SVK_solution}, it will be used for a one-dimensional strain problem for it enables the development of an exact solution.  \n\\end{example}\n\n\n%\\subsubsection*{History-dependent models in small strain}\n\\subsubsection*{The infinitesimal theory formulation}\n%Analogously to the hyperelastic case, constitutive equations within the small strain framework are derived from the Eulerian Clausius-Duhem inequality. Then, by assuming the existence of a Helmholtz free energy density $\\psi$ depending on the temperature $\\theta$, the linearized strain tensor $\\tens{\\eps}$ and additional internal variables $\\Vcb$, \n\nThe linearized geometrical framework leads, by assuming the existence of a Helmholtz free energy density $\\psi$ that depends on the temperature $\\theta$, the infinitesimal strain tensor $\\tens{\\eps}$ and additional internal variables $\\Vcb$, to the following relation \\cite[Ch.2]{Simo}:\n\\begin{equation}\n  \\label{eq:Cauchy_definition}\n  \\rho \\drond{\\psi}{\\tens{\\eps}} = \\tens{\\sigma}\n\\end{equation}\n% which time derivative yields:\n% \\begin{equation}\n%   \\label{eq:HPP_tangent}\n%   \\tens{\\dot{\\sigma}} = \\rho\\ddrond{\\psi}{\\tens{\\eps}}{\\tens{\\eps}}:\\tens{\\dot{\\eps}} = \\Cbb:\\tens{\\dot{\\eps}}\n% \\end{equation}\nThe infinitesimal strain tensor is further assumed to be additively decomposed into an elastic and a plastic part: $\\tens{\\eps} = \\tens{\\eps}^e + \\tens{\\eps}^p$. Then, with irreversible deformations due to plastic strains, the mechanical dissipation reads:\n\\begin{equation}\n  \\label{eq:HPP_dissipation}\n  \\Dscr^{int}=\\tens{\\sigma}:\\tens{\\dot{\\eps}}^p -\\rho \\drond{\\psi}{\\Vcb}\\dot{\\Vcb} \\geq 0\n\\end{equation}\n\nA \\textit{yield condition} is defined by means of function $f(\\tens{\\sigma},\\Acb)$ so that the elastic domain $\\Ebb$ in forces space $(\\tens{\\sigma},\\Acb)$ corresponds to:\n\\begin{equation}\n  \\label{eq:elastic_convex}\n  \\Ebb = \\{ (\\tens{\\sigma},\\Acb)\\: | \\: f(\\tens{\\sigma},\\Acb) \\leq 0\\}\n\\end{equation}\nAccording to the GSM framework \\cite{GSM} we assume the existence of a dissipation pseudo-potential $\\Phi(\\tens{\\sigma},\\Vcb)$, convex with respect to thermodynamic forces and vanishing at the origin of the $(\\tens{\\sigma},\\Vcb)$ space. This pseudo-potential enables the derivation of the plastic \\textit{flow} and \\textit{hardening} rules:\n\\begin{subequations}\n  \\begin{alignat}{2}\n    \\label{eq:flow_rule_plast}\n     \\tens{\\dot{\\eps}}^p&=&\\drond{\\Phi}{f}\\drond{f}{\\tens{\\sigma}}\\\\\n    \\label{eq:hardening_rule_plast}\n     \\dot{\\Vcb}& = -&\\drond{\\Phi}{f}\\drond{f}{\\Acb}\n  \\end{alignat}\n\\end{subequations}\nwhere $\\drond{\\Phi}{f}=\\dot{p}$ is the equivalent plastic strain rate.\nAn example of a model used for metals is the \\textit{plastic $J_2$ flow theory} where the elastic domain is here described by a yield function that depends on the deviatoric part of the Cauchy stress, $\\tens{s}=\\tens{\\sigma}-\\frac{1}{3}\\tr \\tens{\\sigma}\\tens{I}$, through its second invariant $J_2(\\tens{s})=\\frac{1}{2}\\tens{s}:\\tens{s}$. \n%The elastic domain is here described by a yield function that depends on the deviatoric part of the Cauchy stress, $\\tens{s}=\\tens{\\sigma}-\\frac{1}{3}\\tr \\tens{\\sigma}\\tens{I}$, through its second invariant $J_2(\\tens{s})=\\frac{1}{2}\\tens{s}:\\tens{s}$ according to the \\textit{plastic $J_2$ flow theory} generally used to model metals.\nIn addition, a set of internal variables and associated forces describing the plastic hardening of the material is used $\\{\\Vcb,\\Acb\\}=\\{\\[\\tens{\\eps}^p,p\\],\\[\\tens{s}-\\tens{Y},-R(r)\\]\\}$ in order to define the \\textit{von-Mises yield surface}:\n\\begin{equation}\n  \\label{eq:von-Mises_yield}\n  f\\(\\tens{\\sigma},\\Acb \\)= \\sqrt{\\frac{3}{2}}\\norm{\\tens{s}-\\tens{Y}} - \\(R(r)+\\sigma^y\\) \\equiv 0\n\\end{equation}\nwhere $\\sigma^y$ is the tensile yield stress and $r$ is to be defined. In deviatoric stress space, the von-Mises yield surface is a circle whose center and radius are $\\tens{Y}$ and $R(r)$. These thermodynamic forces hence respectively describe the displacement of the elastic domain center due to \\textit{kinematic hardening}, and the evolution of its radius due to \\textit{isotropic hardening}.\nSetting $R(r)$ (\\textit{resp.} $\\tens{Y}$) to zero amounts to specializing the yield surface \\eqref{eq:von-Mises_yield} to kinematic (\\textit{resp. isotropic}) hardening.\n%The specialization of the yield surface \\eqref{eq:von-Mises_yield} to kinematic or isotropic hardenings is made by respectively setting $R(r)=0$ or $\\tens{Y}=\\tens{0}$.\n% In the following, linear hardening will be considered here by setting either $\\tens{Y}=\\tens{0}$ for isotropic or $R(r)=0$ for kinematic hardening.\nThen, flow rules \\eqref{eq:flow_rule_plast} and \\eqref{eq:hardening_rule_plast} applied to the yield function \\eqref{eq:von-Mises_yield} lead to:\n\\begin{subequations}\n  \\begin{alignat}{1}\n    \\label{eq:plastic_strain_rate}\n    &\\tens{\\dot{\\eps}}^p=\\dot{p}\\sqrt{\\frac{3}{2}}\\frac{\\tens{s}-\\tens{Y}}{\\norm{\\tens{s}-\\tens{Y}}}=\\dot{p}\\:\\sqrt{\\frac{3}{2}}\\tens{m} \\\\\n    \\label{eq:equiv_plastic_strain_rate}\n    &\\dot{r}=\\dot{p}\n  \\end{alignat}\n\\end{subequations}\nwhere $r$ is identified from \\eqref{eq:equiv_plastic_strain_rate} as the equivalent plastic strain and $\\tens{m}$ is referred to as the \\textit{plastic flow direction}.\n\nNext, assuming a Prager-Ziegler linear kinematic hardening \\cite[p.91]{Simo}, the Helmholtz free energy density takes the form: \n%By considering internal variables and associated forces as: $\\{\\Vcb,\\Acb\\}=\\{\\[\\tens{\\eps}^p,p\\],\\[\\tens{s}-\\tens{Y},-R(p)\\]\\}$, one defines the following Helmholtz free energy density:\n\\begin{equation}\n  \\label{eq:EP_helmoltz}\n  \\rho \\psi = \\frac{1}{2}\\tens{\\eps}^e:\\Cbb:\\tens{\\eps}^e + \\frac{2}{3}C\\tens{\\eps}^p:\\tens{\\eps}^p + H(p)\n\\end{equation}\nwhere $H(p)$ is defined so that $H''(p)=C$ is the \\textit{hardening modulus}, and $\\Cbb$ is the fourth-order \\textit{elastic stiffness} tensor (major and minor symmetric) defined for isotropic materials as $C_{ijkl}=\\lambda \\delta_{ij}\\delta_{kl} + \\mu \\(\\delta_{ik}\\delta_{jl}+\\delta_{il}\\delta_{jk}\\)$.\nThermodynamic forces are finally related to internal variables by means of equation \\eqref{eq:thermodynamic_forces}, that is:\n\\begin{subequations}\n  \\begin{alignat}{1}\n    \\label{eq:eta}\n    \\tens{Y}&=\\frac{2}{3}C\\tens{\\eps}^p \\\\\n    \\label{eq:isotropic_hardening}\n    R &=H'(p)\n  \\end{alignat}\n\\end{subequations}\n\nWe consider in what follows isothermal deformations of isotropic solids, that may be irreversible by specifying the above developments to some well-known small strain constitutive models.\n\\begin{example}[Linear elasticity]\n  The simplest case that is considered hereinafter does not involve irreversible deformations, and hence additional internal variables (\\textit{i.e. $\\tens{\\eps}^p\\equiv \\tens{0}$}), and is referred to as linear elasticity. The combination of equations \\eqref{eq:Cauchy_definition} and \\eqref{eq:EP_helmoltz} then leads to \\textit{Hooke's law}:\n  \\begin{equation}\n    \\label{eq:Hooke}\n    \\tens{\\sigma}=\\Cbb:\\tens{\\eps}\n  \\end{equation}\n  or in rate form:\n  \\begin{equation}\n    \\label{eq:elastic_law}\n    \\tens{\\dot{\\sigma}}=\\Cbb:\\tens{\\dot{\\eps}}\n  \\end{equation}\n  The elastic acoustic tensor is further defined as:\n  \\begin{equation}\n    \\label{eq:elasticity_acoustic}\n    A^{\\text{elast}}_{ij}= n_k C_{kijl}n_l= \\lambda n_in_j + \\mu \\(n_in_j + \\delta_{ij}\\)\n  \\end{equation}\n\\end{example}\n\n\\begin{example}[Elastoplasticity]\n  Rate-independent plasticity or elastoplasticity is based on the assumption that admissible thermodynamic forces lie within or on the boundary of the elastic domain \\eqref{eq:elastic_convex}. The equivalent plastic strain rate becomes a Lagrange multiplier in order to ensure $f(\\tens{\\sigma},\\Acb)\\leq 0$ and must obey the \\textit{K{\\\"u}hn-Tucker compatibility conditions}:\n\\begin{equation}\n  \\label{eq:Kuhn_Tucker}\n  \\dot{p} \\geq 0 \\quad ; \\quad f \\leq 0 \\quad ; \\quad \\dot{p}f =0 \n\\end{equation}\nThe equivalent plastic strain rate, is determined by the \\textit{consistency condition} $\\dot{f}=\\drond{f}{(\\tens{s}-\\tens{Y})}:(\\tens{\\dot{s}}-\\tens{\\dot{Y}}) - \\drond{f}{R}\\dot{R}=0$ that leads to:\n\\begin{equation}\n   \\sqrt{\\frac{3}{2}}\\tens{m}:\\dot{\\tens{Y}} + \\dot{R} =\\sqrt{\\frac{3}{2}}\\tens{m}:\\dot{\\tens{\\sigma}}\n\\end{equation}\nThen, combination of the above equation with the elastic law $\\tens{\\dot{\\sigma}}=\\Cbb:\\(\\tens{\\dot{\\eps}}-\\tens{\\dot{\\eps}}^p\\)$ and equation \\eqref{eq:plastic_strain_rate} yields:\n\\begin{equation}\n  \\label{eq:p_evolution}\n  \\dot{p}=\\sqrt{\\frac{3}{2}}\\frac{2\\mu}{3\\mu+(C+R')}\\tens{m}:\\tens{\\dot{\\eps}}=\\sqrt{\\frac{3}{2}}\\frac{2\\mu}{3\\mu+(C+R')}\\tens{m}:\\tens{\\dot{\\eps}}\n\\end{equation}\nAt last, equations \\eqref{eq:plastic_strain_rate} and \\eqref{eq:p_evolution} can be successively introduced in the elastic law so that one gets \\cite[eq (2.2.22)]{Simo}:\n\\begin{equation}\n  \\label{eq:elastoplastic_tangent}\n  \\tens{\\dot{\\sigma}}=\\(\\Cbb - \\frac{6\\mu^2}{3\\mu +(C+R')}\\tens{m}\\otimes\\tens{m} \\):\\tens{\\dot{\\eps}} = \\Cbb^{ep}:\\tens{\\dot{\\eps}}\n\\end{equation}\nwith $\\Cbb^{ep}$ the \\textit{elastoplastic tangent modulus}.\nThe \\textit{elastoplastic acoustic tensor} is defined as:\n\\begin{equation}\n  \\label{eq:EP_acoustic}\n  A_{ij}^{ep}= n_k C^{ep}_{ikjl}n_l = A_{ij}^{elast} -  \\frac{6\\mu^2}{3\\mu +(C+R')} (n_k m_{ik})(m_{jl}n_l)\n\\end{equation}\nwhich is positive-definite for positive linear hardening ($C>0 \\:;\\: R'>0$).\n\\end{example}\n\n\n\\begin{example}[Elasto-viscoplasticity]\n  Viscoplasticity or rate-dependent plasticity can be seen as a regularization of rate-independent plasticity that relaxes the condition $f(\\tens{\\sigma},\\Acb)\\leq 0$ and thus leads to admissible thermodynamic forces lying outside the elastic domain \\cite[p.58]{Simo}.\n  %%\n  Viscoplasticity provides on the other hand an explicit definition of the equivalent plastic strain, for example the Perzyna or Sokolowskii-Malvern model \\cite{Perzyna} is governed by:\n  \\begin{equation}\n    \\label{eq:EVP_creep_law}\n    \\dot{p}=\\left\\langle \\frac{f}{\\gamma}\\right\\rangle^n\n  \\end{equation}\n  where $\\left\\langle\\bullet\\right\\rangle=\\frac{\\bullet + \\abs{\\bullet}}{2}$ is the positive part function, and $n$ and $\\gamma$ are parameters. % arising from the relaxation of the condition $f\\leq 0$.\n  %%\n  Hence, the plastic fluxes $\\tens{\\dot{\\eps}}^p, \\dot{\\Vcb}$ are completely determined by \\eqref{eq:flow_rule_plast} and \\eqref{eq:hardening_rule_plast}.\n  %%\n  It then comes out that rate-dependent plasticity is driven by the elastic law:\n  \\begin{equation}\n    %\\label{eq:elastic_law}\n    \\tens{\\dot{\\sigma}}=\\Cbb:\\(\\tens{\\dot{\\eps}}-\\tens{\\dot{\\eps}}^p\\)\n  \\end{equation}\n  in which $\\tens{\\dot{\\eps}^p}$ is given by the combination of equations \\eqref{eq:flow_rule_plast} and \\eqref{eq:EVP_creep_law}, namely:\n  \\begin{equation}\n    \\label{eq:EVP_plastic_strain_rate}\n    \\tens{\\dot{\\eps}}^p=\\left\\langle \\frac{f}{\\gamma}\\right\\rangle^n\\:\\sqrt{\\frac{3}{2}}\\tens{m}\n  \\end{equation}\n\\end{example}\n\n\n\\subsection{The general formulation}\n\\label{sec:general-formulation}\nBalance and constitutive equations obtained previously are now summarized for various classes of materials and regimes of deformation. Recall that the deformations are assumed isothermal and that history effects are considered within the infinitesimal theory only.\n\n\\subsubsection*{Hyperelasticity}\n%The non-linear constitutive equations of elastoplasticity and hyperelasticity prevent the writing of a conservative form with the previous approach.\nThe system of conservation laws for problems involving hyperelastic solids is composed of kinematic laws \\eqref{eq:HE_kinematic} and the balance equation of Lagrangian linear momentum \\eqref{eq:Lagrangian_linear_momentum}, repeated here for convenience:\n\\begin{align}\n  & \\tens{\\dot{F}} - \\nablav_0 \\cdot \\(\\vect{v}\\otimes\\tens{I}\\) = \\tens{0}\\\\\n  & \\rho_0 \\vect{\\dot{v}} - \\nablav_0 \\cdot \\tens{\\Pi} = \\rho_0 \\vect{b} \n\\end{align}\nAssuming a Cartesian coordinate system, this system can be written in \\textit{conservative form}:\n\\begin{equation}\n  \\label{eq:general_conservative_HE}\n  \\Ucb_t + \\sum_{\\alpha=1}^D \\drond{\\Fcb\\cdot \\vect{E}_\\alpha}{X_\\alpha} = \\Scb\n\\end{equation}\nwhere the vector of conserved quantities $\\Ucb$, flux vectors $\\Fcb\\cdot \\vect{E}_\\alpha$ and the source term $\\Scb$ are:\n\\begin{equation}\n  \\label{eq:vectors_hyperelasticity}\n  \\Ucb =\\matrice{\\rho_0\\vect{v} \\\\ \\tens{F}} \\quad ; \\quad \\Fcb\\cdot\\vect{E}_\\alpha = \\matrice{-\\tens{\\Pi}\\cdot\\vect{E}_\\alpha\\\\-\\vect{v}\\otimes\\vect{E}_\\alpha } \\quad; \\quad \\Scb = \\matrice{ \\rho_0\\vect{b} \\\\ \\tens{0}}\n\\end{equation}\nA quasi-linear system may then be built by introducing an auxiliary vector $\\Qcb=\\matrice{\\vect{v}\\\\ \\tens{\\Pi}}$ and using the chain rule according to \\cite{Trangenstein91}:\n\\begin{equation}\n  \\label{eq:quasi-linear_Trangenstein}\n  \\drond{\\Qcb}{t} + \\(\\drond{\\Ucb}{\\Qcb}\\)^{-1}\\drond{\\Fcb\\cdot\\vect{E}_\\alpha}{\\Qcb} \\drond{\\Qcb}{X_\\alpha} = \\(\\drond{\\Ucb}{\\Qcb}\\)^{-1}\\Scb = \\tilde{\\Scb}\n\\end{equation}\nIn the quasi-linear form, the derivative of the vector of conserved quantities with respect to the auxiliary vector leads to the diagonal matrices:\n\\begin{equation*}\n  \\drond{\\Ucb}{\\Qcb}=\\matrice{\\tens{I} & \\tens{0}^3 \\\\ \\tens{0}^3  & \\drond{\\tens{F}}{\\tens{\\Pi}}} \\Rightarrow \\(\\drond{\\Ucb}{\\Qcb}\\)^{-1}=\\matrice{\\tens{I} & \\tens{0}^3 \\\\ \\tens{0}^3  & \\drond{\\tens{\\Pi}}{\\tens{F}}}\n\\end{equation*}\nwhere the tangent modulus $\\drond{\\tens{\\Pi}}{\\tens{F}}=\\Hbb$ arises and $\\tens{0}^p$ is a $p$th-order zero tensor. Moreover, the derivative of the flux vectors with respect to the auxiliary vector reads:\n\\begin{equation}\n  \\drond{\\Fcb\\cdot\\vect{E}_\\alpha}{\\Qcb}=-\\matrice{\\tens{0}^2 & \\frac{1}{\\rho_0}\\tens{I}\\otimes\\vect{E}_\\alpha \\\\    \\tens{I}\\boxtimes \\vect{E}_\\alpha & \\tens{0}^4}\n\\end{equation}\nin which the operator $\\tens{I}\\boxtimes\\vect{E}_\\alpha$ is the transpose on second and third indices of the classical tensor product, namely: $\\tens{I}\\boxtimes\\vect{E}_\\alpha=\\delta_{jk} \\vect{e}_j\\otimes \\vect{E}_\\alpha\\otimes\\vect{e}_k$.\nFinally, the quasi-linear form associated with hyperelastic problems is:\n\\begin{equation}\n  \\Qcb_t + \\Absf^\\alpha \\drond{\\Qcb}{X_\\alpha} = \\Scb \\qquad \\text{with: }\\Absf^\\alpha = -\\matrice{ \\tens{0}^2 & \\frac{1}{\\rho_0}\\tens{I}\\otimes\\vect{E}_\\alpha \\\\ \\Hbb\\cdot\\vect{E}_\\alpha & \\tens{0}^4} \\label{eq:HE_quasilinear}\n\\end{equation}\nwhere the dependence on $\\Qcb$ of matrices $\\Absf^\\alpha(\\Qcb)$ has been omitted for simplicity.\n\n\\subsubsection*{Linear elasticity and elasto-viscoplasticity}\nThe governing equations of elasticity and elasto-viscoplasticity within the linearized geometrical framework consist of the kinematic law \\eqref{eq:HPP_kinematic}, the balance equation of linear momentum \\eqref{eq:HPP_linear_momentum} and the elastic law \\eqref{eq:elastic_law}:\n\\begin{align*}\n  & \\tens{\\dot{\\eps}}-\\nablav \\cdot \\(\\frac{\\vect{v}\\otimes\\tens{I}+\\tens{I}\\otimes \\vect{v}}{2}\\) =\\tens{0} \\\\\n  & \\rho \\vect{\\dot{v}} - \\nablav \\cdot \\tens{\\sigma} = \\rho \\vect{b} \\\\\n  & \\tens{\\dot{\\sigma}} - \\Cbb :\\(\\tens{\\dot{\\eps}}-\\tens{\\dot{\\eps}}^p\\) =\\tens{0}\n\\end{align*}\nCombining kinematic and elastic laws and considering again a Cartesian coordinates system yields, for a homogeneous media (\\textit{i.e. $\\nablav \\rho=\\vect{0}$}), the following \\textit{conservative form}:\n%Hence, introduction of kinematic laws in the elastic law yields, by assuming a Cartesian coordinates system and homogeneous media (\\textit{i.e. $\\nablav \\rho=\\vect{0}$}), the following \\textit{conservative form}:\n\\begin{equation}\n  \\label{eq:general_conservative}\n  \\Qcb_t + \\sum_{i=1}^D \\drond{\\Fcb\\cdot \\vect{e}_i}{x_i} = \\Scb\n\\end{equation}\nwith conserved quantities, flux and source term vectors respectively defined as:\n\\begin{equation}\n  \\label{eq:vectors_elasticity}\n  \\Qcb =\\matrice{\\vect{v} \\\\ \\tens{\\sigma}} \\quad ; \\quad \\Fcb\\cdot\\vect{e}_i = \\matrice{-\\frac{1}{\\rho}\\tens{\\sigma}\\cdot\\vect{e}_i\\\\-\\Cbb:\\frac{\\vect{v}\\otimes\\vect{e}_i +\\vect{e}_i \\otimes\\vect{v} }{2} } \\quad ; \\quad \\Scb = \\matrice{ \\vect{b} \\\\ -\\Cbb:\\tens{\\dot{\\eps}}^p}\n\\end{equation}\nNote that here, the direct writing of the conservative form in terms of $\\vect{v}$ and $\\tens{\\sigma}$ is made possible by the linearity of the elasticity tensor, avoiding thus the introduction of an auxiliary vector. The quasi-linear form of equation \\eqref{eq:general_conservative} is derived by means of the chain rule:\n\\begin{equation}\n  \\label{eq:HPP_quasi-linear}\n  \\Qcb_t + \\Absf^i \\drond{\\Qcb}{x_i} = \\Scb\n\\end{equation}\nwhere:\n\\begin{equation*}\n  \\Absf^i=\\drond{\\Fcb\\cdot \\vect{e}_i}{\\Qcb}=-\\matrice{\\tens{0}^3 & \\frac{1}{\\rho}\\tens{I}\\otimes\\vect{e}_i\\\\\\Cbb\\cdot\\vect{e}_i & \\tens{0}^4}\n\\end{equation*}\nin which symmetries of the elastic stiffness tensor have been used. Since the elastic stiffness tensor is constant, system \\eqref{eq:HPP_quasi-linear} is linear for elasticity and semi or non-linear for elasto-viscoplasticity depending on the flow rule \\eqref{eq:flow_rule_plast}. Moreover, the source term arising due to the viscoplastic flow rule \\eqref{eq:EVP_plastic_strain_rate} can be written in terms of a relaxation term $\\bar{\\Scb}$ and a relaxation time $\\tau=(\\gamma/\\sigma^y)^n$ as $\\Scb=\\bar{\\Scb}/\\tau$ \\cite{Thomas_EVP}, so that the system \\eqref{eq:HPP_quasi-linear} can be identified to a \\textit{relaxation system} \\cite{Relaxation_syst}. In the asymptotic limit $\\tau \\rightarrow 0$ or in the \\textit{vanishing viscosity limit}, system \\eqref{eq:HPP_quasi-linear} tends to the \\textit{equilibrium system} corresponding to elastoplasticity \\cite{Thomas_EVP}.\n\n\\subsubsection*{Elastoplasticity}\nThe writing of a conservative form for elastoplasticity is similar to what was done for hyperelastic solids. Indeed, the system composed of kinematic laws \\eqref{eq:HPP_kinematic} and the balance equation of linear momentum \\eqref{eq:HPP_linear_momentum}:\n%The system of conservation laws for non-linear problems are based on kinematic laws \\eqref{eq:HPP_kinematic} so that a conservative form \\eqref{eq:general_conservative} is also written:\n\\begin{align*}\n  & \\tens{\\dot{\\eps}}-\\nablav \\cdot \\(\\frac{\\vect{v}\\otimes\\tens{I}+\\tens{I}\\otimes \\vect{v}}{2}\\) =\\tens{0} \\\\\n  & \\rho \\vect{\\dot{v}} - \\nablav \\cdot \\tens{\\sigma} = \\rho \\vect{b} \n\\end{align*}\ncan be written as:\n\\begin{equation}\n  \\label{eq:general_conservative_EP}\n  \\Ucb_t + \\sum_{i=1}^D \\drond{\\Fcb\\cdot \\vect{e}_i}{x_i} = \\Scb\n\\end{equation}\n where the conserved quantities, flux and source term vectors are:\n\\begin{equation}\n  \\label{eq:vectors_plasticity}\n  \\Ucb =\\matrice{\\vect{v} \\\\ \\tens{\\eps}} \\quad ; \\quad \\Fcb\\cdot\\vect{e}_i = \\matrice{-\\frac{1}{\\rho}\\tens{\\sigma}\\cdot\\vect{e}_i\\\\-\\frac{\\vect{v}\\otimes\\vect{e}_i +\\vect{e}_i \\otimes\\vect{v} }{2} } \\quad ; \\quad \\Scb = \\matrice{ \\vect{b} \\\\\\tens{0}} \n\\end{equation}\nAnalogously to hyperelasticity, a quasi-linear form involving the elastoplastic tangent modulus \\eqref{eq:elastoplastic_tangent} is derived by means of the auxiliary vector $\\Qcb=\\matrice{\\vect{v}\\\\ \\tens{\\sigma}}$ and the chain rule:\n\\begin{equation}\n  \\Qcb_t + \\Absf^i \\drond{\\Qcb}{x_i} = \\Scb \\qquad \\text{with: }\\Absf^i = -\\matrice{\\tens{0}^2 & \\frac{1}{\\rho}\\tens{I}\\otimes\\vect{e}_i\\\\ \\Cbb^{ep}\\cdot \\vect{e}_i & \\tens{0}^4}  \\label{eq:EP_quasilinear}\n\\end{equation}\n\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% ispell-local-dictionary: \"american\"\n%%% TeX-master: \"../mainManuscript\"\n%%% End:\n", "meta": {"hexsha": "c5aa0d704c3d9fe5f416307badedf836a412e4fd", "size": 45564, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/chapter2/conservationLaws.tex", "max_stars_repo_name": "adRenaud/research", "max_stars_repo_head_hexsha": "2f0062a1800d7a17577bbfc2393b084253d567f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-18T14:52:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-18T14:52:03.000Z", "max_issues_repo_path": "manuscript/chapter2/conservationLaws.tex", "max_issues_repo_name": "adRenaud/research", "max_issues_repo_head_hexsha": "2f0062a1800d7a17577bbfc2393b084253d567f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-01-07T13:11:11.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-07T13:11:11.000Z", "max_forks_repo_path": "manuscript/chapter2/conservationLaws.tex", "max_forks_repo_name": "adRenaud/research", "max_forks_repo_head_hexsha": "2f0062a1800d7a17577bbfc2393b084253d567f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 81.2192513369, "max_line_length": 1074, "alphanum_fraction": 0.7178474234, "num_tokens": 15040, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7027889717543556}}
{"text": "\\section*{Problem 1 Solution}\n\n\\begin{enumerate}[a)]\n\n\\item\n\n In a symmetric spherical system, the one-speed, steady-state diffusion equation is\n$$ -D \\lap \\phi(r) + \\Sigma_a (r) \\phi(r) = \\nu \\Sigma_f(r) \\phi(r) + S(r) .$$\nFor any arbitrary function, $f(r,\\theta,\\varphi)$, the full Laplacian in spherical coordinates is\n$$ \\lap f(r,\\theta,\\varphi) = \\frac{1}{r^2}\\frac{\\p}{\\p r}\\left(r^2 \\frac{\\p f}{\\p r}\\right) +  \\frac{1}{r^2 \\sin\\theta} \\frac{\\p}{\\p \\theta}\\left(\\sin\\theta \\frac{\\p f}{\\p \\theta}\\right) + \\frac{1}{r^2 \\sin^2 \\theta} \\frac{\\p^2 f}{\\p \\varphi^2} .$$\nIf the function $f(r,\\theta,\\varphi)$ is radially symmetric then $f(r,\\theta,\\varphi) = f(r)$, and there will be no variation in the $\\theta$ or $\\varphi$ directions ($\\frac{\\p f}{\\p \\theta} = 0$ and $\\frac{\\p f}{\\p \\varphi} = 0$).  The second and third terms vanish, and\n$$ \\lap f(r) = \\frac{1}{r^2}\\frac{\\p}{\\p r}\\left(r^2 \\frac{\\p f}{\\p r}\\right) .$$\nWe substitute this back into our one-speed, steady-state diffusion equation, using $\\phi(r)$ instead of $f(r)$.\n$$ -D \\frac{1}{r^2}\\frac{\\p}{\\p r}\\left(r^2 \\frac{\\p \\phi(r)}{\\p r}\\right) + \\Sigma_a (r) \\phi(r) = \\nu \\Sigma_f(r) \\phi(r) + S(r) .$$\nFinally, we recognize that our problem has two regions. There is no external source in either, so $S(r) = 0$. Since the regions are homogeneous, the diffusion coefficients and cross sections are constant in each: $D_C$, $\\Sigma_{a,C}$, $\\nu$, and $\\Sigma_f$ in the core; $D_R$ and $\\Sigma_{a,R}$ in the reflector. We will define the outer radius of the core as $a$, and the outer radius of the reflector as $\\frac{3a}{2}$. Then, our diffusion equations for both regions are:\n$$ -D_C \\frac{1}{r^2}\\frac{\\p}{\\p r}\\left(r^2 \\frac{\\p \\phi(r)}{\\p r}\\right) + \\Sigma_{a,C} \\phi(r) = \\nu \\Sigma_f \\phi(r), \\quad 0 < r < a \\quad\\text{(core)} $$\n$$ -D_R \\frac{1}{r^2}\\frac{\\p}{\\p r}\\left(r^2 \\frac{\\p \\phi(r)}{\\p r}\\right) + \\Sigma_{a,R}\\phi(r) = 0, \\quad a < r < \\frac{3a}{2} \\quad\\text{(reflector)}.$$\nFor our final solution, we will make two more substitutions, $B_C^2 = \\frac{\\nu\\Sigma_f - \\Sigma_{a,C}}{D_C}$ and $L_R^2 = \\frac{D_R}{\\Sigma_{a,R}}$, to get\n$$ \\frac{1}{r^2}\\frac{\\p}{\\p r}\\left(r^2 \\frac{\\p \\phi(r)}{\\p r}\\right) - B_C^2 \\phi(r) = 0, \\quad 0 < r < a \\quad\\text{(core)} $$\n$$ \\frac{1}{r^2}\\frac{\\p}{\\p r}\\left(r^2 \\frac{\\p \\phi(r)}{\\p r}\\right) - \\frac{1}{L_R^2}\\phi(r) = 0, \\quad a < r < \\frac{3a}{2} \\quad\\text{(reflector)} .$$\nThere are also four boundary conditions that accompany these equations. A vacuum boundary condition (where we will use the extrapolated distance $d$ to indicate where the flux goes to zero), a finiteness condition, and two interface conditions (both continuous current and flux at the boundary). \n\\begin{align*}\n&(1)& \\phi(r) &< \\infty  \t\t\t\t\t\t& &\\text{(flux finiteness)} \\\\\n&(2)& \\phi_R\\left(\\frac{3a}{2} + d\\right) &= 0 \t& &\\text{(vacuum)} \\\\\n&(3)& \\phi_C(a) &= \\phi_R(a)\t\t\t\t\t& &\\text{(continuous flux)} \\\\\n&(4)& J_C(a) &= J_R(a)\t\t\t\t\t\t\t& &\\text{(continuous current)}\n\\end{align*} \n\n\\item\n\nSince the diffusion equation takes a different form in each region, the solutions describing the flux shapes in those regions are also different. In the core, the flux has the functional form\n$$ \\phi_C(r) = \\frac{A_C}{r} \\sin\\left(B_C r\\right) + \\frac{B_C}{r} \\cos\\left(B_C r\\right) , \\quad 0 < r < a,$$\nand in the reflector,\n$$ \\phi_R(r) = \\frac{A_R}{r}\\sinh\\left(\\frac{r+\\omega}{L_R}\\right) + \\frac{B_R}{r} \\cosh\\left(\\frac{r+\\omega}{L_R}\\right), \\quad\\quad\\quad a < r < \\frac{3a}{2} .$$\nHere we have included the shift in position of the hyperbolic sines and cosines, which is an equally valid solution to the diffusion equation in the reflector region. The usefulness of this parameter will become apparent shortly.\n\nImposing our first boundary condition (finite flux everywhere), we notice that the second term in the flux solution for the core goes to infinity as $r$ goes to zero ($\\frac{1}{r} \\rightarrow \\infty$ and $\\cos(\\kappa r) \\rightarrow 1$). For the finiteness condition to be satisfied, we must set $B_C = 0$. Considering the second boundary condition (vacuum outside of the reflector), we have the equation\n$$ \\phi_R\\left(\\frac{3a}{2}+d\\right) = 0 = \\frac{A_R}{\\frac{3a}{2}+d}\\sinh\\left(\\frac{\\frac{3a}{2}+d+\\omega}{L_R}\\right) + \\frac{B_R}{\\frac{3a}{2}+d} \\cosh\\left(\\frac{\\frac{3a}{2}+d+\\omega}{L_R}\\right) .$$\nNoting that the hyperbolic cosine never gives a value of zero, we can conclude that $B_R = 0$.  Furthermore, the value of the hyperbolic sine only gives a value of zero when it's argument is equal to zero. To satisfy this, $\\omega = -\\left(\\frac{3a}{2}+d\\right)/L_R$.\n\nFrom these two boundary conditions, our flux shapes simplify to\n$$ \\phi_C(r) = \\frac{A_C}{r} \\sin\\left(B_C r\\right) , \\quad 0 < r < a,$$\n$$ \\phi_R(r) = \\frac{A_R}{r}\\sinh\\left(\\frac{r-\\left(\\frac{3a}{2}+d\\right)}{L_R}\\right), \\quad a < r < \\frac{3a}{2} .$$\nWe now use these simpler equations together with our second two boundary conditions. Starting with the flux continuity equation:\n$$ \\phi_C(a) = \\phi_R(a) $$\n$$ \\frac{A_C}{a} \\sin\\left(B_C a\\right) = \\frac{A_R}{a}\\sinh\\left(\\frac{a-\\left(\\frac{3a}{2}+d\\right)}{L_R}\\right) $$\n$$ A_C = A_R \\frac{\\sinh\\left(-\\frac{a+2d}{2L_R}\\right)}{\\sin\\left(B_C a\\right)} .$$\n\nNext we move to the current continuity equation, first writing the condition in terms of flux using Fick's law: \n$$ J_C(a) = J_R(a) $$\n$$ -D_C\\frac{d}{dr}\\phi_C(a) = -D_R\\frac{d}{dr}\\phi_R(a) .$$\nSubstituting in our flux equations, \n$$ -D_C\\frac{d}{dr}\\left(\\frac{A_C}{r} \\sin\\left(B_C r\\right)\\right)\\bigg|_{r=a} = -D_R\\frac{d}{dr}\\left(\\frac{A_R}{r}\\sinh\\left(\\frac{r-\\left(\\frac{3a}{2}+d\\right)}{L_R}\\right)\\right)\\bigg|_{r=a} $$\n$$ -D_C \\left[\\frac{A_C B_C}{r}\\cos\\left(B_C r\\right) - \\frac{A_C}{r^2}\\sin\\left(B_C r\\right)\\right]_{r=a} = -D_R \\left[\\frac{A_R}{r L_R}\\cosh\\left(\\frac{r-\\left(\\frac{3a}{2}+d\\right)}{L_R}\\right) - \\frac{A_R}{r^2}\\sinh\\left(\\frac{r-\\left(\\frac{3a}{2}+d\\right)}{L_R}\\right)\\right]_{r=a} $$\n$$ -A_C D_C \\left[\\frac{B_C}{a}\\cos\\left(B_C a\\right) - \\frac{1}{a^2}\\sin\\left(B_C a\\right)\\right] = -A_R D_R \\left[\\frac{1}{a L_R}\\cosh\\left(\\frac{a-\\left(\\frac{3a}{2}+d\\right)}{L_R}\\right) - \\frac{1}{a^2}\\sinh\\left(\\frac{a-\\left(\\frac{3a}{2}+d\\right)}{L_R}\\right)\\right]$$\n$$ A_C = A_R \\frac{D_R \\left[\\frac{a}{L_R}\\cosh\\left(-\\frac{a+2d}{2L_R}\\right) - \\sinh\\left(-\\frac{a+2d}{2L_R}\\right)\\right]}{D_C \\left[a B_C \\cos\\left(B_C a\\right) - \\sin\\left(B_C a\\right)\\right]}.$$\nAt this point, we may realize that these two continuity boundary conditions have given us two equations where $A_C$ is just proportional to $A_R$. In both cases the factor multiplying $A_R$ is a constant, where $a$, $L_R$, and $B_C$ are known quantities. Intuitively, this means that if our reflected reactor is critical then we may have many different flux magnitudes, but always the same general shape. (In other words, a reactor may be critical with many different neutron populations---this is how reactors can be critical over a range of different power levels---but the general function describing where those neutrons are is always similar.) The answer to the question can the be left as\n$$\\boxed{\\begin{aligned}\n\\quad \\phi_C(r) &= \\frac{A}{r} \\sin\\left(B_C r\\right) ,& \\quad 0 <& r < a \\quad \\\\\n\\quad \\phi_R(r) &= \\frac{A \\sin\\left(B_C a\\right)}{r \\sinh\\left(-\\frac{a+2d}{2L_R}\\right)}\\sinh\\left(\\frac{r-\\left(\\frac{3a}{2}+d\\right)}{L_R}\\right),& \\quad a <& r < \\frac{3a}{2} \\quad \n\\end{aligned}}$$\nwhere we have dropped the subscript from the constant, $A$. \\\\\n\n\\item \n\nThe reflector savings is given by the difference between the critical dimensions of a reflected reactor and a bare reactor of the same shape.\n$$ \\mathcal{S} = a_{\\text{ref}} - a_{\\text{bare}} $$\nFrom the previous section, for both equations we found to be true, the two factors multiplying $A_R$ must be equal. While we cannot determine a unique flux magnitude, we can relate the given quantities to find $a$:\n$$ \\frac{\\sinh\\left(\\frac{a}{L_R}\\right)}{\\sin\\left(B_C a\\right)} = \\frac{D_R \\left[\\frac{a}{L_R}\\cosh\\left(-\\frac{a+2d}{2L_R}\\right) - \\sinh\\left(-\\frac{a+2d}{2L_R}\\right)\\right]}{D_C \\left[a B_C \\cos\\left(B_C a\\right) - \\sin\\left(B_C a\\right)\\right]}.$$\nThis equation is transcendental and it is impossible to calculate a solution analytically, so instead we must solve it numerically. Though we won't actually perform the numerical calculation here,\n$$ a_{\\text{ref}} = a .$$\n\nFor a bare sphere, $a_{\\text{bare}}$ can be found using the geometric buckling (equal to the material buckling which is the same for both cores): \n$$ B_{g,\\text{bare}}^2 = B_C^2 = \\left(\\frac{\\pi}{\\tilde{a}_{\\text{bare}}}\\right)^2 .$$\nWe note $\\tilde{a}_{\\text{bare}} = a_{\\text{bare}} + d_{\\text{bare}}$, and \n$$ a_{\\text{bare}} = \\frac{\\pi}{B_C} - d_{\\text{bare}} .$$\nWe plug these in to find the reactor savings.\n$$\\boxed{ \\mathcal{S} = a - \\frac{\\pi}{B_C} + d_{\\text{bare}} }$$\n\\end{enumerate}\n\n", "meta": {"hexsha": "1028117f939fd434204e3a9abdca0b32053ac4ca", "size": 8888, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc12/disc12_solution01.tex", "max_stars_repo_name": "mitchnegus/NE150-discussion", "max_stars_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/drafts/disc12/disc12_solution01.tex", "max_issues_repo_name": "mitchnegus/NE150-discussion", "max_issues_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/drafts/disc12/disc12_solution01.tex", "max_forks_repo_name": "mitchnegus/NE150-discussion", "max_forks_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 109.7283950617, "max_line_length": 694, "alphanum_fraction": 0.6641539154, "num_tokens": 3188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242073, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.7027506708586416}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage[english]{babel}\n\\usepackage[utf8x]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\n\\title{MATH 542 Homework 8}\n\\author{Saket Choudhary\\\\skchoudh@usc.edu}\n\n\\begin{document}\n\\maketitle \n\\subsection*{Problem 3a.2}\nConsider $||\\boldmath{Y}-\\boldmath{X\\beta}||^2$.  Since X is full rank $\\hat{\\beta} = (X'X)^{-1}X'Y$\nThis involves $\\frac{||\\boldmath{Y}-\\boldmath{X\\beta}||^2}{\\partial \\beta_i}=0$\nAlso $\\hat{Y_i}=\\beta_0+x_{i1}\\beta_1 + \\dots + x_{ip-1}\\beta_{p-1} $\nFor $i=0$:\n\\begin{align*}\n\\frac{||\\boldmath{Y}-\\boldmath{X\\beta}||^2}{\\partial \\beta_i}&=0\\\\\n\\frac{\\sum( Y_i-(\\beta_0+x_{i1}\\beta_1 + \\dots + x_{ip-1}\\beta_{p-1} ) )^2 }{\\partial \\beta_0} &= 0\\\\\n\\sum( Y_i-(\\beta_0+x_{i1}\\beta_1 + \\dots + x_{ip-1}\\beta_{p-1} ) ) &= 0\\\\\n\\sum( Y_i-\\hat{Y_i} ) &= 0\\\\\n\\end{align*}\n\\subsection*{Problem 3a.3}\n\\begin{align*}\n\\begin{pmatrix}Y_1\\\\Y_2\\\\Y_3\n\\end{pmatrix}&= \\begin{pmatrix}1 &0\\\\ 2 & -1\\\\ 1 & 2\\end{pmatrix}\\begin{pmatrix}\\theta\\\\ \\phi \\end{pmatrix}\\\\\n\\end{align*}\nThus $X=\\begin{pmatrix}1 &0\\\\ 2 & -1\\\\ 1 & 22\\end{pmatrix}$\n$\\beta=X'X$ and hence using R:\n\\begin{align*}\n\\theta = 0.167 Y_1 + 0.333 Y_2 + 0.167 Y_3\\\\\n\\phi = -0.2Y_2+0.4Y_3\n\\end{align*}\n\\subsection*{Problem 3a.4}\n\\begin{align*}\n\\begin{pmatrix}Y_1\\\\Y_2\\\\Y_3\n\\end{pmatrix}&= \\begin{pmatrix}1 &-1 &1\\\\ 1 & 0 & -2\\\\ 1 & 1 &1\\end{pmatrix}\\begin{pmatrix}\\beta_0\\\\ \\beta_1 \\\\ \\beta_2\\end{pmatrix}\\\\\n\\end{align*}\n\n\\begin{align*}\n\\begin{pmatrix}\\beta_0\\\\ \\beta_1 \\\\ \\beta_2\\end{pmatrix}&= (X'X)^{-1}X'Y\\\\\n\\begin{pmatrix}\\beta_0\\\\ \\beta_1 \\\\ \\beta_2\\end{pmatrix}&= \\begin{pmatrix}\\frac{1}{3} & \\frac{1}{3} & \\frac{1}{3}\\\\ -0.5 & 0 & 0.5\\\\ \\frac{1}{6} & -\\frac{1}{3} & \\frac{1}{6}\\end{pmatrix}\\begin{pmatrix}Y_1\\\\Y_2\\\\Y_3\n\\end{pmatrix}\n\\end{align*}\nConsider $\\beta_2=0$:\n\n\n\\begin{align*}\n\\begin{pmatrix}Y_1\\\\Y_2\\\\Y_3\n\\end{pmatrix}&= \\begin{pmatrix}1 &-1 \\\\ 1 & 0 \\\\ 1 & 1\\end{pmatrix}\\begin{pmatrix}\\beta_0\\\\ \\beta_1 \\\\\\end{pmatrix}\\\\\n\\end{align*}\n\nThen using R:\n\\begin{align*}\n\\begin{pmatrix}\\beta_0\\\\ \\beta_1\\end{pmatrix}&= (X'X)^{-1}X'Y\\\\\n\\begin{pmatrix}\\beta_0\\\\ \\beta_1\\end{pmatrix}&= \\begin{pmatrix}\\frac{1}{3} & \\frac{1}{3} & \\frac{1}{3}\\\\ -0.5 & 0 & 0.5\\\\ \\end{pmatrix}\\begin{pmatrix}Y_1\\\\Y_2\\\\Y_3\n\\end{pmatrix}\n\\end{align*}\n\n\\subsection*{Problem 3a.7}\n$\\hat{Y} = X\\hat{\\beta} = PY$\n\\begin{align*}\n\\sum \\hat{Y_i}(Y_i-\\hat{Y_i}) &= \\hat{Y'}(Y-\\hat{Y'}\\\\\n&= Y'P'(Y-PY)\\\\\n&= Y'P(I_n-P)Y\\\\\n&= Y'(P-P^2)Y\\\\\n&=0\\text{ Since P is idempotent}\n\\end{align*}\n\\subsection*{Problem 3b.3}\nConsider $\\bar{Y} = \\frac{\\sum_i Y_i}{n}$\n\n$E[\\bar{Y}] = \\theta$ so $\\bar{Y}$ is unbiased estimate.\n\nAlso using Rao's minimum variance lower bound, $\\alpha'\\beta$ is a minimum variance estimate for $\\mathcal{N}(X\\beta, \\sigma^2)$, Thus $\\bar{Y}$ is both unbiased and minimum variance.\n\n\\subsection*{Problem 3b.4}\n\n\\begin{align*}\nY_i &= \\beta_0+\\beta_1(x_{i1}-\\bar{x_1}) + \\beta_2(x_{i2}-\\bar{x_2})+\\epsilon_i\\\\\n\\begin{pmatrix}Y_1\\\\Y_2\\\\Y_3\\\\\\vdots\\\\Y_n\n\\end{pmatrix}&= \\begin{pmatrix} 1 & x_{11}-\\bar{x_1} & x_{12}-\\bar{x_2}\\\\\n 1 & x_{21}-\\bar{x_1} & x_{22}-\\bar{x_2}\\\\\n \\vdots & \\vdots & \\vdots\\\\\n 1 & x_{n1}-\\bar{x_1} & x_{n2}-\\bar{x_2}\\\\\n\\end{pmatrix}\\begin{pmatrix}\n\\beta_0\\\\\\beta_1\\\\\\beta_2\n\\end{pmatrix}\\\\\nX &= \\begin{pmatrix} 1 & x_{11}-\\bar{x_1} & x_{12}-\\bar{x_2}\\\\\n 1 & x_{21}-\\bar{x_1} & x_{22}-\\bar{x_2}\\\\\n \\vdots & \\vdots & \\vdots\\\\\n 1 & x_{n1}-\\bar{x_1} & x_{n2}-\\bar{x_2}\\\\\n\\end{pmatrix}\\\\\nX'X &= \\begin{pmatrix}\nn & \\sum x_{i1}-n\\bar{x_1} & \\sum x_{i2} - n \\bar{x_2}\\\\\n\\sum x_{i1}-n\\bar{x_1} & \\sum(x_{i1}-\\bar{x_1})^2 & \\sum (x_{i1}-\\bar{x_1})(x_{i2}-\\bar{x_2})\\\\\n\\sum x_{i2}-n\\bar{x_2} & \\sum (x_{i1}-\\bar{x_1})(x_{i2}-\\bar{x_2}) & \\sum(x_{i2}-\\bar{x_2})^2\n\\end{pmatrix}\\\\\n& = \\begin{pmatrix}\nn & 0 & 0\\\\\n0 & \\sigma^2_{1} & r\\sigma_1\\sigma_2\\\\\n0 & r\\sigma_1\\sigma_2 & \\sigma_2^2\n\\end{pmatrix}\\\\ \n(X'X)^{-1} & = \\frac{1}{\\sigma_1^2\\sigma_2^2(1-r^2)} \\begin{pmatrix}\n\\frac{1}{n(\\sigma_1^2\\sigma_2^2(1-r^2))} & 0 & 0\\\\\n0 & \\sigma^2_{2} & r\\sigma_1\\sigma_2\\\\\n0 & r\\sigma_1\\sigma_2 & \\sigma_1^2\n\\end{pmatrix}\\\\ \n\\end{align*}\nThus $Var(\\beta_1) = \\sigma^2 (X'X)^{-1} = \\frac{\\sigma^2 \\sigma_2^2}{\\sigma_1^2\\sigma_2^2(1-r^2)} = \\frac{\\sigma^2}{\\sigma_1^2(1-r^2)}$\n\\end{document}\n\n\n\n", "meta": {"hexsha": "67187e221c57460d29f49d419b9565c176f8fdfa", "size": 4184, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016_Spring/MATH-542/HW08/hw08.tex", "max_stars_repo_name": "NeveIsa/hatex", "max_stars_repo_head_hexsha": "c5cfa2410d47c7e43a476a8c8a9795182fe8f836", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2015-09-10T02:45:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T03:20:47.000Z", "max_issues_repo_path": "2016_Spring/MATH-542/HW08/hw08.tex", "max_issues_repo_name": "NeveIsa/hatex", "max_issues_repo_head_hexsha": "c5cfa2410d47c7e43a476a8c8a9795182fe8f836", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-09-16T23:11:00.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-23T21:21:52.000Z", "max_forks_repo_path": "2016_Spring/MATH-542/HW08/hw08.tex", "max_forks_repo_name": "saketkc/hatex", "max_forks_repo_head_hexsha": "c5cfa2410d47c7e43a476a8c8a9795182fe8f836", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-09-25T19:06:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T03:21:09.000Z", "avg_line_length": 36.3826086957, "max_line_length": 214, "alphanum_fraction": 0.6101816444, "num_tokens": 2045, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7027142095055533}}
{"text": "\\section{2D \\texorpdfstring{$U(1)$}{U (1)} Lattice Gauge Theory}%\n\\label{sec:l2hmc_u1} \nAll lattice QCD simulations are performed at finite\nlattice spacing $a$ and need an extrapolation to the continuum in order to be\nused for computing values of physical quantities.\n%\nMore reliable extrapolations can be done by simulating the theory at\nincreasingly smaller lattice spacings.\n%\nThe picture that results when the lattice spacing is reduced and the physics\nkept constant is that all finite physical quantities of negative mass dimension\ndiverge if measured in lattice units.\n%\nIn statistical mechanics language, this states that the continuum limit is a\ncritical point of the theory since correlation lengths diverge.\n%\nMCMC algorithms are known to encounter difficulties when used for simulating\ntheories close to a critical point, an issue known as the \\emph{critical slowing\ndown} of the algorithm.\n%\nThis effect is most prominent in the topological charge, whose auto-correlation\ntime increases dramatically with finer lattice spacings.\n%\nAs a result, there is a growing interest in developing new sampling techniques\nfor generating equilibrium configurations. \n%\nIn particular, algorithms that are able to offer improvements in efficiency\nthrough a reduction of statistical autocorrelations are highly desired. \n%\nWe begin with the two-dimensional $U{(1)}$ lattice gauge theory with dynamical\nvariables $U_{\\mu}{(i)}$ defined on the links of a lattice, where $i$ labels a\nsite and $\\mu$ specifies the direction.\n%\nEach link $U_{\\mu}{(i)}$ can be expressed in terms of an angle $0 <\n\\phi_{\\mu}{(i)} \\leq 2 \\pi$.\n%\n\\begin{equation}\n    U_{\\mu}{(i)} = e^{i\\phi_{\\mu}{(i)}}\n    \\label{eq:link_variable}\n\\end{equation}\n%\nwith the Wilson action defined as:\n%\n\\begin{equation}\n    \\beta S = \\beta \\sum_{P}{(1 - \\cos{(\\phi_{P})})}\n    \\label{eq:wilson_action}\n\\end{equation}\n%\nwhere\n%\n\\begin{equation}\n    \\phi_{P} \\equiv \\phi_{\\mu\\nu}(i) = \n        \\phi_{\\mu}{(i)} + \\phi_{\\nu}{(i + \\hat{\\mu})} \n        - \\phi_{\\mu}{(i + \\hat{\\nu})} - \\phi_{\\nu}{(i)}\n    \\label{eq:phi_plaquette}\n\\end{equation}\n%theta_\nand $\\beta = 1/e^{2}$ is the gauge coupling, and the sum $\\sum_{P}$ runs over\nall plaquettes of the lattice.\n%\nAn illustration showing how these variables are defined for an elementary\nplaquette is shown in Fig.~\\ref{fig:plaquette}.\n%\n\\begin{figure}[htpb]\n  \\centering\n  \\includegraphics[width=0.5\\textwidth]{gauge_figures/plaq.png}\n  \\caption{Illustration of an elementary plaquette on the lattice.}%\n\\label{fig:plaquette}\n\\end{figure}\n\nWe can define the topological charge, $\\mathcal{Q} \\in \\mathbb{Z}$, as\n%\n\\begin{equation}\n  \\mathcal{Q} \\equiv \\frac{1}{2\\pi}\\sum_{P} \\tilde \\phi_{P} =\n    \\frac{1}{2\\pi}\\sum_{\\substack{{i; \\mu, \\nu}\\\\{\\nu > \\mu}}}\n    \\tilde \\phi_{\\mu\\nu}{(i)}\n    \\label{eq:topological_charge}\n\\end{equation}\n%\nwhere\n%\n\\begin{equation}\n  \\tilde{\\phi}_{P} \\equiv \\phi_{P} - 2\\pi {\\bigg\\lfloor{\\frac{\\phi_{P} +\n  \\pi}{2\\pi}\\bigg\\rfloor}}\n  % \\tilde{\\phi}_{P} \\equiv \\phi_{P} - 2 \\pi \\left \\lfloor{\\frac{\\phi_{P} +\n  % \\pi}{2 \\pi}\\right \\rfloor}\n\\end{equation}\n%\nis the sum of the link variables around the elementary plaquette, projected\nonto the interval $\\left[0, 2 \\pi\\right)$.\n%\nFrom this, we can define topological susceptibility\n%\n\\begin{equation}\n    \\chi \\equiv \\frac{\\langle \\mathcal{Q}^2\\rangle - \\langle \\mathcal{Q} \\rangle^2}{V}\n    % \\label{eq:topological_susceptibility}\n\\end{equation}\n%\nBy parity symmetry, $\\langle \\mathcal{Q} \\rangle = 0$, so we have that\n\\begin{equation}\n    \\chi = \\frac{\\langle \\mathcal{Q}^2\\rangle}{V}\n    \\label{eq:topological_susceptibility}\n\\end{equation}\n%\nUnfortunately, the measurement of $\\chi$ is often difficult due to the fact\nthat the autocorrelation time with respect to $\\mathcal{Q}$ tends to be extremely long.\n%\nThis is a consequence of the fact that the Markov chain tends to get stuck in a\ntopological sector (characterized by $\\mathcal{Q} = const$.), a phenomenon known as\n\\emph{topological freezing}.\n%\n% (right) Topological charge vs.\\ step generated using the trained\n% L2HMC sampler.}%\n\\begin{figure}[htpb]\n  \\centering\n    % \\includegraphics[width=0.49\\textwidth]{top_charge_vs_step_hmc.eps}\n    % \\includegraphics[width=0.49\\textwidth]{top_charge_vs_step_l2hmc.eps}\n    \\includegraphics[width=0.6\\textwidth]{charge_plots/top_charge_vs_step_HMC}\n    % \\includegraphics[width=0.49\\textwidth]{charge_plots/compare/top_charge_vs_step_hmc}\n    % \\includegraphics[width=0.49\\textwidth]{charge_plots/compare/top_charge_vs_step_l2hmc}\n    \\caption{Example of topological freezing in the $2D$ $U{(1)}$\n      lattice gauge theory. The above result was generated using generic HMC\n      sampling for a $8\\times8$ lattice. Note that for the majority of the\n      simulation $\\mathcal{Q}=0$, making it virtually impossible to get a reasonable\n    estimate of $\\chi$.}\\label{fig:top_charge} \n  \\end{figure}\n%\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Annealing Schedule}% \n\\label{subsec:l2hmc_u1annealing}\n% In addition to modifying the neural network architecture, we also modified\n% the training algorithm to follow a simulated annealing schedule.\n%\nProceeding as in the example of the Gaussian Mixture Model, we include a\nsimulated annealing schedule in which the value of the gauge coupling $\\beta$\nis continuously updated according to the annealing schedule shown in\nEq.~\\ref{eq:annealing_schedule}.\n%\n% Explicitly, the value of the gauge coupling $\\beta$ is continuously updated\n% according to the annealing schedule shown in Eq.~\\ref{eq:annealing_schedule}.\n%\nThis was done in order to encourage sampling from multiple different\ntopological charge sectors, since our sampler is less `restricted' at lower\nvalues of $\\beta$.\n%This was don\n\\begin{equation} \n  \\frac{1}{\\beta(n)} = {\\left(\\frac{1}{\\beta_{i}} \n    - \\frac{1}{\\beta_{f}}\\right)}\n    {\\left(\\frac{1 - n}{N_{\\mathrm{train}}}\\right)} \n    + \\frac{1}{\\beta_{f}} \n\\label{eq:annealing_schedule} \n\\end{equation}\n%\nHere $\\beta(n)$ denotes the value of $\\beta$ to be used for the\n$n^{\\mathrm{th}}$ training step ($n = 1, \\ldots, N_{\\mathrm{train}}$),\n$\\beta_{i}$ represents the initial value of $\\beta$ at the beginning of the\ntraining, and $\\beta_{f}$ represents the final value of $\\beta$ at the end of\ntraining.\n%\nFor a typical training session, $N_{\\mathrm{train}} = 25,000$, $\\beta_{i} = 2$\nand $\\beta_{f} = 5$.\n% For all of the exmaples above, $N_{\\mathrm{train}} = 25,000$, $\\beta_{0} = 2$\n% and $\\beta_{N_{\\mathrm{train}}} = 5$.\n%\n% As can be seen in Fig.~\\ref{fig:top_charge}\n\n\\subsection{Modified metric for \\texorpdfstring{$U(1)$}{U (1)} Gauge\nModel}%\n\\label{subsec:l2hmc_modifiedloss}\n%\nIn order to more accurately define the ``distance'' between two different\nlattice configurations, we redefine the metric in Eq.~\\ref{eq:metric_orig} to\nbe\n%\n\\begin{equation}\n  % \\delta(\\xi(\\phi_{\\mu}(x)), \\xip(\\phi_{\\mu}(x))) \\equiv 1 -\n  % \\cos\\left(\\xi(\\phi_{\\mu}(x)) - \\xi^{\\prime}(\\phi_{\\mu}(x))\\right)\n  \\delta(\\xi, \\xip) \\equiv 1 - \\cos\\left(\\xi - \\xi^{\\prime}\\right)\n\\label{eq:new_metric}\n\\end{equation}\n%\nwhere now $\\xi \\equiv {\\left(\\phi_{\\mu}^{x}(i), \\,\\phi_{\\mu}^{v}(i),\\,\nd\\right)}$, with $\\phi_{\\mu}^{x}$ representing the lattice of (`position')\ngauge variables (what we called $x$ previously), and $\\phi_{\\mu}^{v}$\nrepresenting the lattice of (`momentum') gauge variables (what we called $v$\npreviously). Note that $i$ runs over all lattice sites\\footnote{In what\n  follows, we will refrain from explicitly including the site index and make\n  the assumption that it implicitly extends over all sites on the lattice.} and\n  $\\mu=0, 1$ for the two dimensional case.\n%\nWe see that this metric gives the expected behavior, since $\\delta \\rightarrow\n0$ for $\\xi \\approx \\xip$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\subsection{Issues with the Average Plaquette}\n% %\n% When running inference using the trained sampler, an issue was encountered in\n% which the average plaquette, $\\langle \\phi_{P}\\rangle$ seems to converge to a\n% value which is noticeably different from the expected value in the infinite\n% volume limit, and can be seen in Fig.~\\ref{fig:bad_convergence}.\n% %\n% In order to quantify this unexpected behavior, we can calculate the difference\n% between the observed value of the average plaquette, $\\langle \\phi_{P}\\rangle$\n% and the expected value $\\phi_{P}^{(*)}$ (calculated from the infinite volume\n% limit):\n% %\n% \\begin{equation}\n%   {\\delta_{\\phi_P}}(\\alpha_Q, N_{\\mathrm{LF}}) \\equiv \\langle \\phi_P\\rangle -\n%   \\phi_{P}^{(*)} \\neq 0.\n%   % - \\langle{\\phi_{P}^{\\mathrm{(exact)}}}\\rangle \\neq 0}.\n% \\end{equation}\n% %\n% % Which allows us to quantify this difference.%\n%\n%\n% % Upon further testing, an issue was encountered in which the\n% % of the average plaquette\n% % $\\langle \\phi_{P}\\rangle$ seems to converge to a value which is noticeably\n% % different from the expected value in the infinite volume limit.\n% %\n% % This behavior can be seen in Fig.~\\ref{fig:bad_convergence}, and seems to\n% % depend on both the number of augmented leapfrog steps used by our integrator,\n% % as well as the `strength' of the topological loss term in\n% % Eq.~\\ref{eq:topological_loss_term}.\n% %\n% % The parameters used in Fig~\\ref{fig:bad_convergence} are as follows: $L = 8$,\n% % $N_{\\mathrm{LF}} = 7$, and $N_{\\mathrm{samples}} = 128$,\n% % and the sampler was trained for $N_{\\mathrm{train}} = 1\\times10^{4}$.\n% %\n% % In Fig~\\ref{fig:good_convergence}, the only change was the weight factor for\n% % the topological charge term in the loss function $\\alpha_{Q} = 0$.\n% %\n% \\begin{figure}[htpb]%\n%   \\centering\n%     \\includegraphics[width=0.49\\textwidth]{new_figures/plaq_error/plaqs_diffs_vs_step_l2hmc_lf16.pdf}\n%     \\includegraphics[width=0.49\\textwidth]{new_figures/plaq_error/plaqs_diffs_vs_step_hmc_lf16.pdf}\n%     % \\includegraphics[width=0.49\\textwidth]{plaq_plots/plaqs_diffs_vs_step_bad.pdf}\n%     \\caption{Difference between the observed and expected value of the average\n%       plaquette, $\\delta_{\\phi_{P}}$, \\textbf{(left)}: using the trained L2HMC\n%       sampler, and \\textbf{(right)}: using generic HMC.}%\n%       % trained L2HMC sampler \\textbf{(left)} and generic HMC \\textbf{(right)} .\n%       % HMC result, obtained by setting $\\alpha_{S} = \\alpha_{Q} = \\alpha{T} = 0$\n%       % \\textbf{(right)}:\n%       % \\ref{subsec:net_weights}).}%\n% \\label{fig:bad_convergence}\n% \\end{figure}%\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "f79381f542d83c367e385060051a13181485e4bd", "size": 10613, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/gauge/gauge.tex", "max_stars_repo_name": "saforem2/l2hmc-qcd", "max_stars_repo_head_hexsha": "b5fe06243fae663607b6c88e71373b68b19558fc", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2019-04-18T18:50:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T18:30:48.000Z", "max_issues_repo_path": "doc/gauge/gauge.tex", "max_issues_repo_name": "saforem2/l2hmc-qcd", "max_issues_repo_head_hexsha": "b5fe06243fae663607b6c88e71373b68b19558fc", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 21, "max_issues_repo_issues_event_min_datetime": "2019-09-09T21:10:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T17:43:51.000Z", "max_forks_repo_path": "doc/gauge/gauge.tex", "max_forks_repo_name": "saforem2/l2hmc-qcd", "max_forks_repo_head_hexsha": "b5fe06243fae663607b6c88e71373b68b19558fc", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-10-31T02:25:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-25T00:49:14.000Z", "avg_line_length": 42.2828685259, "max_line_length": 103, "alphanum_fraction": 0.6886836898, "num_tokens": 3148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7027142039363424}}
{"text": "%!TEX root = ../thesis.tex\n% ******************************* Thesis Appendix A ****************************\n\n\\chapter{Additional Derivations}\n\n\\section{Holland cost}\n\\label{app:holland-cost}\nFollowing Holland's~\\cite{holland1977cost} derivation of a stochastic control problem for the Schr\\\" odinger equation. We start by introducing the exponential transform\n\\begin{equation}\n\t\\psi(x)=\\exp [-U(x)],\n\\end{equation}\ninto the Schro\\\" odinger equation for $x \\in \\mathbb{R}^{n}$\n\\begin{equation}\n\tH \\psi=\\left[-\\frac{1}{2} \\nabla^{2}+V(x)\\right] \\psi=\\lambda \\psi,\n\\end{equation}\nto obtain\n\\begin{equation}\n\t\\label{eq:a-hc1}\n\t\\frac{1}{2} \\nabla^{2} U-\\frac{1}{2}(\\nabla U)^{2}+V(x)=\\lambda.\n\\end{equation}\nWe can reinterpret the second term in eq.~\\eqref{eq:a-hc1} as a minimum over all vectors $v$ for every $x \\in \\mathbb{R}^{n}$\n\\begin{equation}\n\t\\label{eq:a-hc2}\n\t\\frac{1}{2} \\nabla^{2} U+\\min_{v}\\left[v \\cdot \\nabla U+\\frac{1}{2}|v|^{2}+V(x)\\right]=\\lambda.\n\\end{equation}\nWe define $v$ to be a Lipshitz continuous function, i.e. the drift $v(x)$. Each drift now generates an It\\^ o process\n\\begin{equation}\n\t\\label{eq:a-hc3}\n\t\\mathrm{d}X_{t}=\\mathrm{d}W_{t}+v\\left(X_{t}\\right) \\mathrm{d}t \\quad \\text{ and } \\quad X_0 = x,\n\\end{equation}\nand we can define the cost function $C[v]$ for each $v$ as\n\\begin{equation}\n\t\\label{eq:a-hc4}\n\tC[v]=\\lim _{T \\rightarrow \\infty} \\frac{1}{T} \\mathbb{E}\\left[\\int \\left(\\frac{1}{2}\\left|v\\left(X_{t}\\right)\\right|^{2}+V\\left(X_{t}\\right)\\right)\\mathrm{d}x \\right].\n\\end{equation}\nHolland~\\cite{holland1977cost} proves the following theorem.\n\\begin{theorem}[Holland cost function]\n\tThe minimum $\\lambda = \\min_{v} C[v]$, where the minimum is taken over drift functions $v: \\Omega \\rightarrow \\mathbb{R}^n$, $\\Omega \\subset \\mathbb{R}^n$ with Neumann boundary conditions $\\frac{\\partial \\psi}{\\partial n}=0 \\text{ on } \\partial \\Omega$, is obtained only for $v=\\frac{\\nabla \\psi}{\\psi}=-\\nabla U$.\n\\end{theorem}\n\\begin{proof}\n\tFrom eq.~\\eqref{eq:a-hc2} follows the inequality\n\t\\begin{equation}\n\t\t\\label{eq:a-hc5}\n\t\t\\frac{1}{2} \\nabla^{2} U+v \\cdot \\nabla U+\\frac{1}{2}|v(x)|^{2}+V(x) \\geq \\lambda,\n\t\\end{equation}\n\twe notice that the first two terms are an infinitesimal generator $[\\mathcal{L}_G U](x)$ of the process in eq.~\\eqref{eq:a-hc3}, which is defined as\n\t\\begin{equation}\n\t\t\\left[\\mathcal{L}_{\\mathrm{G}} \\psi\\right](x) \\equiv \\lim _{t \\rightarrow 0} \\frac{\\mathbb{E}_{x}\\left[\\psi\\left(X_{t}\\right)\\right]-\\psi(x)}{t},\n\t\\end{equation} \n\twhere $\\mathbb{E}_x$ is over processes with initial condition $X_0 = x$.\n\tWith this in mind, we evaluate eq.~\\eqref{eq:a-hc5} on the process $X_t$ and integrate over time to obtain\n\t\\begin{equation}\n\t\t\\frac{\\mathbb{E}\\left[U\\left(X_{T}\\right)-U(x)\\right]}{T}+\\mathbb{E}\\left[\\frac{1}{T}\\int_{0}^{T} \\left(\\frac{1}{2}\\left|v\\left(X_{t}\\right)\\right|^{2}+V\\left(X_{t}\\right)\\right)\\mathrm dt\\right] \\geq \\lambda.\n\t\\end{equation}\n\tIn the $T \\rightarrow \\infty$ limit, the first terms disappears, so long as $U$ is bounded, and we are left with $C[v]$, meaning that we have proven the bound \n\t\\begin{equation}\n\t\tC[v] \\geq \\lambda.\n\t\\end{equation}\n\tWe see that the minimum $\\lambda$ is achieved for control function\n\t\\begin{equation}\n\t\tv = \\frac{\\nabla \\psi}{\\psi} = -\\nabla U,\n\t\\end{equation}\n\tin eq.~\\eqref{eq:a-hc2}, the uniqueness of this optimal $v$ is due to the fact that if $v \\neq \\frac{\\nabla \\psi}{\\psi}$ there cannot be a full equality in eq.~\\eqref{eq:a-hc5}.\n\\end{proof}\n\n\n\\section{Probabilistic interpretation of Holland's cost function}\n\\label{app:holland-prob}\nThis section follows Barr et al.~\\cite{barr2020quantum} which is closely related to previous work~\\cite{dai1990markov}. To express the RN derivative we use the Girsanov theorem for both $\\mathbb{P}_v$\n\\begin{equation}\n\t\\frac{\\mathrm{d} \\mathbb{P}_{v}}{\\mathrm{d} \\mathbb{P}_{0}}=\\exp \\left(\\int v\\left(X_{t}\\right) \\mathrm{d} X_{t}-\\frac{1}{2} \\int\\left|v\\left(X_{t}\\right)\\right|^{2} \\mathrm{d} t\\right),\n\\end{equation}\nand $\\mathbb{P}_{\\mathrm{FK}}$\n\\begin{equation}\n\t\\label{eq:a-hp2}\n\t\\frac{\\mathrm{d} \\mathbb{P}_{\\mathrm{FK}}}{\\mathrm{d} \\mathbb{P}_{0}}=\\mathcal{N} \\exp \\left(-\\int V\\left(X_{t}\\right) \\mathrm{d} t\\right).\n\\end{equation}\nWe combine both, and we have up to exponential accuracy $\\mathcal{N} \\sim e^{\\lambda T}$\n\\begin{equation}\n\t\\log \\left(\\frac{\\mathrm{d} \\mathbb{P}_{v}}{\\mathrm{d} \\mathbb{P}_{\\mathrm{FK}}}\\right)=\\log \\left(\\frac{\\mathrm{d} \\mathbb{P}_{v}}{\\mathrm{d} \\mathbb{P}_{0}} \\frac{\\mathrm{d} \\mathbb{P}_{0}}{\\mathrm{d} \\mathbb{P}_{\\mathrm{FK}}}\\right) = \\int v\\left(X_{t}\\right) \\mathrm{d} X_{t}+\\int \\left(-\\frac{1}{2}\\left|v\\left(X_{t}\\right)\\right|^{2}+V\\left(X_{t}\\right)\\right)\\mathrm{d} t - \\lambda T,\n\\end{equation}\nfinally we substitute $\\mathrm{d} X_t = \\mathrm{d}W_t + v(X_t)\\mathrm{d}t$ to get\n\\begin{equation}\n\t\\begin{aligned}\n\t\\log \\left(\\frac{\\mathrm{d} \\mathbb{P}_{v}}{\\mathrm{d} \\mathbb{P}_{\\mathrm{FK}}}\\right) \n\t& =  \\int v\\left(X_{t}\\right) \\mathrm{d} W_{t} + \\int |v(X_t)|^2 \\mathrm{d}t + \\int \\left(-\\frac{1}{2}\\left|v\\left(X_{t}\\right)\\right|^{2}+V\\left(X_{t}\\right)\\right)\\mathrm{d} t\\\\\n\t& =  \\int v\\left(X_{t}\\right) d W_{t}+\\int \\left(\\frac{1}{2}\\left|v\\left(X_{t}\\right)\\right|^{2}+V\\left(X_{t}\\right)\\right) \\mathrm{d}t  - \\lambda T.\n\t\\end{aligned}\n\\end{equation}\nA closer look at the normalisation constant $\\mathcal{N}$ in eq.~\\eqref{eq:a-hp2} gives rise to the boundary term. The normalisation is given by\n\\begin{equation}\n\t\\mathcal N = \\frac{\\tilde{\\psi}\\left(r_{T}, T\\right)}{\\bar{\\psi}\\left(r_{0}, 0\\right)},\n\\end{equation}\nwhere $\\tilde{\\psi}\\left(r_{t}, t\\right)$ is the solution to the backwards imaginary time Schr\\\" odinger equation~\\cite{barr2020quantum}, and is related to the distribution of the stochastic process in eq.~\\eqref{eq:a-hc3} as\n\\begin{equation}\n\t\\pi(r, t) = \\tilde{\\psi}\\left(r, t\\right) \\psi\\left(r, t\\right).\n\\end{equation}\nIf we now take both distributions at initial time $\\pi(r, 0)$ and terminal time $\\pi(r, T)$ to be the ground state the normalisation constant becomes\n\\begin{equation}\n\t\\frac{\\tilde{\\psi}\\left(r_{T}, T\\right)}{\\bar{\\psi}\\left(r_{0}, 0\\right)} = e^{E_{0} T} \\frac{\\varphi_{0}\\left(r_{T}\\right)}{\\varphi_{0}\\left(r_{0}\\right)},\n\\end{equation}\nand accounts for the boundary term and $E_0 T$ term in the Kullback-Leibler divergence.\n\n\\section{Todorov cost}\n\\label{app:todorov-cost}\nOptimal decision processes are formalised using Markov Decision processes, here we follow work of Todorov~\\cite{todorov2007linearly, todorov2009efficient} to fit the imaginary Schr\\\" odinger equation in this mould. An MDP is a $4$-tuple $\\left(S, A, P_{a}, R_{a}\\right)$:\n\\begin{itemize}\n\t\\item $S$: Is the \\emph{state space}, i.e. all possible configurations of the system $s_k$\n\t\\item $U$: Is the \\emph{control space}, i.e. all possible single-spin flips in each configuration\n\t\\item $P_u$: Is the probability  $p(s^{(t+1)} = s^\\prime | s^{(t)} = s, u^{(t)} = u)$ of control $u$ in state $s$ leading to state $s^\\prime$ in the next time step\n\t\\item $g$: Is the cost received when moving from state $s$ to $s^\\prime$ due to $u$\n\\end{itemize}\nThe optimal decision/control problem is then given by the Bellman equation for the optimal cost-to-go function $v(s)$\n\\begin{equation}\n\t\\nu(s)=\\min _{u}\\left\\{\n\t\\underbrace{\\ell(s, u)}_{\\text{immediate cost}}\n\t+\n\t\\underbrace{\\mathbb{E}_{s^{\\prime} \\sim p(\\cdot \\mid s, u)}\\left[\\nu\\left(x^{\\prime}\\right)\\right]}_{\\text{expected cost of next state}}\n\t\\right\\}.\n\\end{equation}\nTodorov introduces a formalism where the agent does not perform specific symbolic actions (e.g. flips a certain spin) but is instead allowed to specify transition probabilities $u(s^\\prime|s)$. Formally this means that\n\\begin{equation}\n\tp\\left(s^{\\prime} \\mid s, u\\right)=u\\left(s^{\\prime} \\mid s\\right),\n\\end{equation}\nand the agent reshapes the dynamics of the system as it wishes, but for this it pays a price depending on how much it changes the dynamics. In absence of controls $u$ the system follows \\emph{passive dynamics} $p(s^\\prime | s)$ which correspond to the first term in eq.~\\eqref{eq:hamilton_split} of the stoquastic Hamiltonian. The cost is thus\n\\begin{equation}\n\t\\ell(s, u)=\\underbrace{q(s)}_{\\text{state cost}}+\\underbrace{D_\\mathrm{KL}((\\cdot \\mid s) \\| p(\\cdot \\mid s))}_{\\text{control cost}}.\n\\end{equation}\nOptimal control problem in this form can be linearised in terms of the \\emph{desirability} function $z(s, t)=\\exp (-\\nu(s, t))$, yielding optimal dynamics $\\nu^\\prime$\n\\begin{equation}\n\t\\nu^{\\prime}(s_j \\mid s_k)=\\frac{p(s_j \\mid s_k) z(s_j)}{\\sum_{s_l} p(s_l \\mid s_k) z(s_l)},\n\\end{equation}\nwith\n\\begin{equation}\n\t\\label{eq:lintod}\n\tz(s_k, t)=e^{-q(s_k)} \\sum_{s_j} p(s_j \\mid s_k) z(s_j, t+1).\n\\end{equation}\nIt is this linear equation, that we can connect to the imaginary time Schr\\\" odinger equation. We start by transforming the MDP into continuous time (transition probabilities to rates $p, u \\rightarrow \\Gamma, \\Gamma^{(v)}$) as\n\\begin{equation}\n\tp(s_j \\mid s_k)=\\left\\{\\begin{array}{ll}\n\t1-\\Delta t \\sum_{s_l} \\Gamma_{s_k \\rightarrow s_l} & s_j=s_k \\\\\n\t\\Delta t \\Gamma_{s_k \\rightarrow s_j} & s_j \\neq s_k\n\t\\end{array}\\right.\n\t, \\quad \\text{and} \\quad \n\tu(s_j \\mid s_k)=\\left\\{\\begin{array}{ll}\n\t1-\\Delta t \\sum_{s_l} \\Gamma_{s_k \\rightarrow s_l}^{(v)} & s_j=s_k \\\\\n\t\\Delta t \\Gamma_{s_k \\rightarrow s_j}^{(v)} & s_j \\neq s_k\n\t\\end{array}\\right.\n\\end{equation}\nand setting $q(s_j) = \\Delta t V(s_j)$ eq.~\\eqref{eq:lintod} becomes\n\\begin{equation}\n\t\\begin{aligned}\n\tz(s_k, t) &= e^{-\\Delta t V(s_k)} \\left[\n\t\t\t\t\\underbrace{z(s_k, t + \\Delta t) - \\Delta t \\sum_{s_l \\neq s_k}\\Gamma_{s_{k} \\rightarrow s_{l}} z(s_k, t + \\Delta t)}_{\\text{from } s_j = s_k}\n\t\t\t\t+\n\t\t\t\t \\underbrace{\\Delta t \\sum_{s_j \\neq s_k} \\Gamma_{s_k \\rightarrow s_j} z(s_j, t + \\Delta t)}_{\\text{from } s_j \\neq s_k}\n\t\t\t\t\\right] \\\\\n\t\t\t  &= \\left[1 - \\Delta t V(s_k) + \\ldots\\right]\\cdot\n\t\t\t     \\left[z(s_k, t + \\Delta t) \n\t\t\t     - \\sum_{s_j \\neq s_k} \\Gamma_{s_k \\rightarrow s_j} \n\t\t\t     \t\\left[\n\t\t\t     \tz(s_j, t + \\Delta t) - z(s_k, t + \\Delta t)\\right]\n\t\t     \t\\right]\n\t\\end{aligned}\n\\end{equation}\nkeeping only the first order in $\\Delta t$, dropping the unnecessary $\\neq$ in the sum\n\\begin{equation}\n\t\\frac{z(s_k, t) - z(s_k, t + \\Delta t)}{\\Delta t} = V(s_k) z(s_k, t + \\Delta t) - \\sum_{s_j} \\Gamma_{s_k \\rightarrow s_j} \n\t\\left[\n\tz(s_j, t + \\Delta t) - z(s_k, t + \\Delta t)\\right]\n\\end{equation}\nand taking the limit $\\Delta t \\rightarrow 0$ finally gives\n\\begin{equation}\n\t-\\frac{\\mathrm{d} z(s_k, t)}{\\mathrm{d} t} =  V(s_k) z(s_k, t) - \\sum_{s_j} \\Gamma_{s_k \\rightarrow s_j} \n\t\\left[\n\tz(s_j, t) - z(s_k, t)\\right],\n\\end{equation}\nwhich is the imaginary time Schr\\\" odinger equation~\\eqref{eq:sch_split}. \n\nThe $D_{\\mathrm{KL}}$ in the loss $\\ell (s, v)$ is expressed in the same manner\n\\begin{equation}\n\t\\begin{aligned}\n\t\tD_{\\mathrm{KL}}(v(\\cdot \\mid s_k) \\| p(\\cdot \\mid s_k))\n\t\t&=\\left[1-\\Delta t \\sum_{s_l} \\Gamma_{s_k \\rightarrow s_l}^{(v)}\\right] \\log \\left[\\frac{1-\\Delta t \\sum_{s_l} \\Gamma_{s_k \\rightarrow s_l}^{(v)}}{1-\\Delta t \\sum_{s_l} \\Gamma_{s_k \\rightarrow s_l}}\\right]+\\Delta t \\sum_{s_j \\neq s_k} \\Gamma_{s_k \\rightarrow s_j}^{(v)} \\log \\left[\\frac{\\Gamma_{s_k \\rightarrow s_j}^{(v)}}{\\Gamma_{s_k \\rightarrow s_j}}\\right]\\\\\n\t\t&= \\Delta t \\sum_{s_j \\neq s_k} \\Gamma_{s_k \\rightarrow s_j}^{(v)}\\underbrace{\\left(\\log \\left[\\frac{\\Gamma_{s_k \\rightarrow s_j}^{(v)}}{\\Gamma_{s_k \\rightarrow s_j}}\\right]+\\frac{\\Gamma_{s_k \\rightarrow s_j}}{\\Gamma_{s_k \\rightarrow s_j}^{(v)}}-1\\right)}_{\\mathrm{Itakura-Saito~divergence~} D_{\\mathrm{IS}}(\\Gamma_{s_k \\rightarrow s_j}^{(v)}, \\Gamma_{s_k \\rightarrow s_j})}.\n\t\\end{aligned}\n\\end{equation}\nIf we consider an ensemble of systems in state $s_k$ there is a $\\Delta t \\Gamma_{s_k \\rightarrow s_j}^{(v)}$ probability of transitioning $s_k \\rightarrow s_j$ in the next time increment, meaning that the ensemble contribution to the $D_{\\mathrm{KL}}$ each time increment is $\\sum_{s_j} \\Delta t \\Gamma_{s_k \\rightarrow s_j}^{(v)} D_{\\mathrm{IS}}\\left(\\Gamma_{s_k \\rightarrow s_j}^{(v)}, \\Gamma_{s_k \\rightarrow s_j}\\right)$, thus we can express the Kullback-Liebler divergence as\n\\begin{equation}\n\tD_{\\mathrm{KL}}=\\underset{\\Sigma_{[0, t]}=k_{t} \\sim \\Gamma^{(v)}}{\\mathbb{E}}\\left[\\sum_{n} D_{\\mathrm{IS}}\\left(\\Gamma_{k^{(n)} \\rightarrow k^{(n+1)}}^{(v)}, \\Gamma_{k^{(n)} \\rightarrow k^{(n+1)}}\\right)\\right].\n\\end{equation}\n\\section{Probabilistic interpretation of Todorov's cost function}\n\\label{app:todorov-prob}\nTo find the Radon-Nikodym derivative between $\\mathbb{P}_v$ and $\\mathbb{P}_{\\mathrm{FK}}$ we proceed analogous to the continuous case, by first finding the respective RN derivatives with the passive process. From the discrete space Feynman-Kac formula~\\eqref{eq:fkac_disc} follows\n\\begin{equation}\n\t\\log \\left(\\frac{\\mathrm{d} \\mathbb{P}_{0}}{\\mathrm{d} \\mathbb{P}_{F K}}(k(t))\\right)=\\int V(k(t)) d t-E_{0} T-\\log \\left(\\frac{\\varphi(k^{(N)})}{\\varphi(k^{(0)})}\\right),\n\\end{equation}\nand by using the Girsanov theorem equivalent for discrete space\\footnote{see proposition 2.6 in Appendix 1 of~\\cite{kipnis1998scaling}} we obtain\n\\begin{equation}\n\t\\log \\left(\\frac{\\mathrm{d} \\mathbb{P}_{v}}{\\mathrm{d} \\mathbb{P}_{0}}(k(t))\\right)\n\t=\n\t\\int \\sum_{l \\neq k(t)}\\left(\\Gamma_{k(t) \\rightarrow l}-\\Gamma_{k(t) \\rightarrow l}^{(v)}\\right) d t+\\sum_{n} \\log \\left(\\frac{\\Gamma_{k^{(n)} \\rightarrow k^{(n+1)}}^{(v)}}{\\Gamma_{k^{(n)} \\rightarrow k^{(n+1)}}}\\right).\n\\end{equation}\nWe combine both to get\n\\begin{equation}\n\t\\begin{aligned}\n\t\\log \\left(\\frac{\\mathrm{d} \\mathbb{P}_{v}}{\\mathrm{~d} \\mathbb{P}_{\\mathrm{FK}}}\\right)\n\t=\n\t\\log \\left(\\frac{\\mathrm{d} \\mathbb{P}_{v}}{\\mathrm{~d} \\mathbb{P}_{0}} \\frac{\\mathrm{d} \\mathbb{P}_{0}}{\\mathrm{~d} \\mathbb{P}_{\\mathrm{FK}}}\\right)\n\t= \\tilde \\ell\n\t+\\sum_{n} \\log \\left(\\frac{\\Gamma_{k^{(n)} \\rightarrow k^{(n+1)}}^{(v)}}{\\Gamma_{k^{(n)} \\rightarrow k^{(n+1)}}}\\right)-E_{0} T-\\log \\left(\\frac{\\varphi(k^{(N)})}{\\varphi(k^{(0)})}\\right),\n\t\\end{aligned}\n\\end{equation}\nwith\n\\begin{equation}\n\t\\tilde \\ell = \\int \\left[V(k(t))+\\sum_{l \\neq k(t)}\\left(\\Gamma_{k(t) \\rightarrow l}-\\Gamma_{k(t) \\rightarrow l}^{(v)}\\right)\\right] \\mathrm{d}t.\n\\end{equation}\nTo see that zero $D_{K L}\\left(\\mathbb{P}_{v} \\| \\mathbb{P}_{\\mathrm{F K}}\\right)$ coincides with rates that minimize Todorov's cost, we need\n\\begin{equation}\n\t\\underset{\\mathbb{P}_v}{\\mathbb{E}}\n\t\\left[\n\t\\sum_{n} \\log \\left(\\frac{\\Gamma_{k^{(n)} \\rightarrow k^{(n+1)}}^{(v)}}{\\Gamma_{k^{(n)} \\rightarrow k^{(n+1)}}}\\right)\n\t\\right]\n\t= \n\t\\underset{\\mathbb{P}_v}{\\mathbb{E}} \n\t\\left[\n\t\\int \n\t\\sum_{l \\neq k(t)}\n\t\\Gamma_{k(t) \\rightarrow l}^{(v)} \\log \\left(\\frac{\\Gamma_{k(t) \\rightarrow l}^{(v)}}{\\Gamma_{k(t) \\rightarrow l}}\\right) \\mathrm{d} t\n\t\\right],\n\\end{equation}\nwhich holds because the expectation of a contribution of a single step of the trajectory $k^{(n)} \\rightarrow k^{(n+1)}$ is equivalent to an ensemble average starting from the same state weighted by the probability of jump $\\Gamma_{k(t) \\rightarrow l}^{(v)} \\Delta t$, this holds separately for each step in the trajectory and by writing $\\sum_{t_i} \\cdots~\\Delta t_i \\rightarrow \\int \\cdots~\\mathrm{d}t$ we obtain above equality. The KL divergence then becomes\n\\begin{equation}\n\t\\begin{aligned}\n\t\tD_{\\mathrm{KL}}\\left(\\mathbb{P}_{v} \\| \\mathbb{P}_{\\mathrm{FK}}\\right) = \n\t\t\\underset{\\mathbb{P}_{v}}{\\mathbb{E}}\\Bigg[\\int V(k(t))+\\sum_{l \\neq k(t)}\\Big(\\Gamma_{k(t) \\rightarrow l}&-\\Gamma_{k(t) \\rightarrow l}^{(v)}\\Big) \\mathrm{d} t +\\sum_{n} \\log \\left(\\frac{\\Gamma_{k^{(n)} \\rightarrow k^{(n+1)}}^{(v)}}{\\Gamma_{k^{(n)} \\rightarrow k^{(n+1)}}}\\right) \\\\\n\t\t&-\\log \\left(\\frac{\\varphi(k^{(N)})}{\\varphi(k^{(0)})}\\right)\\Bigg]-E_{0} T \n\t\\end{aligned}\n\\end{equation}\n\\begin{equation}\n\\begin{aligned}\nD_{\\mathrm{KL}}\\left(\\mathbb{P}_{v} \\| \\mathbb{P}_{\\mathrm{FK}}\\right) = \\underset{\\mathbb{P}_{v}}{\\mathbb{E}}\\Bigg[\\int V(k(t))+\\sum_{l \\neq k(t)}\\big(\\Gamma_{k(t) \\rightarrow l}&-\\Gamma_{k(t) \\rightarrow l}^{(v)}\\big)+\\Gamma_{k(t) \\rightarrow l}^{(v)} \\log \\left(\\frac{\\Gamma_{k(t) \\rightarrow l}^{(v)}}{\\Gamma_{k(t) \\rightarrow l}}\\right) \\mathrm{d} t\\\\\n&-\\log \\left(\\frac{\\varphi(k^{(N)})}{\\varphi(k^{(0)})}\\right)\\Bigg]-E_{0} T,\n\\end{aligned}\n\\end{equation}\nwhich agrees with Todorov.", "meta": {"hexsha": "53bf23b8582ed392ff7ea296a9916062abd38de2", "size": 16223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix1/appendix1.tex", "max_stars_repo_name": "BlazStojanovic/MPhil_Thesis", "max_stars_repo_head_hexsha": "682aa0448efe563a8a8aee87d979628a890ce150", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Appendix1/appendix1.tex", "max_issues_repo_name": "BlazStojanovic/MPhil_Thesis", "max_issues_repo_head_hexsha": "682aa0448efe563a8a8aee87d979628a890ce150", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Appendix1/appendix1.tex", "max_forks_repo_name": "BlazStojanovic/MPhil_Thesis", "max_forks_repo_head_hexsha": "682aa0448efe563a8a8aee87d979628a890ce150", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.9471544715, "max_line_length": 481, "alphanum_fraction": 0.66596807, "num_tokens": 6064, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8670357615200474, "lm_q1q2_score": 0.7027141977749098}}
{"text": "%---------------------------Maximum Angle-----------------------------\n\\section{Maximum Angle\\label{s:tri-max-angle}}\n\nThe maximum included angle of the triangle is\n\\[\n  q =\n    \\max_{n\\in\\{0,1,2\\}}\\left\\{\\arccos{\\left(\n      \\frac{\\vec L_n\\cdot\\vec L_{n+1}}{\\normvec{ L_n}\\normvec{ L_{n+1}}}\n    \\right)}\\left(\\frac{180\\dgr}{\\pi}\\right)\\right\\}\n\\]\nmeasured in degrees.\n\nNote that if any edge vector has zero length, \\verd\\ will return $q = 0\\dgr$.\n\n\\trimetrictable{maximum included angle}%\n{$A^1$}%                                              Dimension\n{$[60\\dgr,90\\dgr]$}%                                  Acceptable range\n{$[60\\dgr,180\\dgr]$}%                                 Normal range\n{$[0\\dgr,180\\dgr]$}%                                  Full range\n{$60\\dgr$}%                                           Unit equilateral triangle value\n{--}%                                                 Reference(s)                   \n{v\\_tri\\_maximum\\_angle}%                             Verdict function name\n\n", "meta": {"hexsha": "3c88cb88e9425c41fd8e58ed9637a7e5c7ea6853", "size": 1007, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TriMaximumAngle.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TriMaximumAngle.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TriMaximumAngle.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 41.9583333333, "max_line_length": 85, "alphanum_fraction": 0.4448857994, "num_tokens": 249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.7026905656844077}}
{"text": "\\section{High-Degree Indicator Matrix}\n\\SecLabel{hdim}\n\nIn~\\cite{LeoRE} Perrin and Biryukov suggested looking at the visual representation of the LAT of an S-Box with the goal of finding non-random patterns. The suggested representation is a heatmap of the LAT matrix and was named \"a Jackson Pollock representation\" of the LAT, after the famous abstract expressionist painter. The success of this method is illustrated in this chapter.\n\nConsider a 4- and 5-round Feistel Network. For a tiny branch size (for example, 3 bits) it is possible to generate the whole codebook and compute the LAT and its visualization. Figure~\\Ref{fig:lat8motiv} shows the Pollock representations of the LAT of Feistel Networks with randomly generated bijective round functions with 3-bit branches (6-bit block size), taken modulo 8.\n\n\\FigTex{lat-mod-4.tex}\n\nThe images yield a lot of patterns. The patterns are even more clear when observed on multiple random instances of the Feistel Network. In particular, the 4-round structure always yields LAT consisting of $8\\times8$ single-colored squares. The 5-round structure still has a visible square structure, but not all squares are single-colored. The topmost leftmost square is always white, the topmost (resp. leftmost) squares consist of horizontal (resp. vertical) lines. Furthermore, linear patterns can be noticed: many columns/rows are inverted versions of other columns/rows, and many columns/rows can be expressed as sums of other columns/rows (modulo 8). The 6-round structure still has linear patterns but no clear squared structure.\n\nAfter studying these patterns, we observed that the LAT modulo 8 is a bilinear form directly related to the monomials of degree $n-1$ in the ANF of the analyzed $n$-bit permutation. This is formally stated and proved in the following section.\n\n% ======================================\n\n\\subsection{Relation between HDIM, LAT and ANF}\n\n\\begin{definition}[HDIM]\nLet $S\\colon \\field{n} \\to \\field{m}$ and $\\deg{S}\\le n-1$. The HDIM of $S$ is the $m\\times n$ matrix $\\HDIM{S}$ over $\\field{}$ given by\n$$\n\\HDIM{S}[i,j] \\eqdef \\bigoplus_{x \\in \\field{n}} \\inprod{e_i, S(x)}\\inprod{e_j, x}.\n$$\n\\end{definition}\n\n\\begin{proposition}[HDIM and ANF]\n\\Label{hdim-anf}\n$\\HDIM{S}[i,j] = 1$ if and only if the ANF of the $i$-th coordinate of $S$ contains the monomial $\\prod_{k \\ne j}x_k=x_1\\ldots x_n/x_j$.\n\\end{proposition}\n\\begin{proof}\nThe sum over $\\field{n}$ is equal to 1 if and only if the summed expression contains the monomial $x_1\\ldots x_n$. Since no coordinate of $S$ has term of degree $n$, $\\HDIM{S}[i,j] = 1$ is equivalent to $\\inprod{e_i,S(x)}$ having the monomial $x_1\\ldots x_n/x_j$.\n\\end{proof}\n\nProposition~\\Ref{hdim-anf} shows that a known value of a cell of the HDIM corresponds to a known ANF coefficient, i.e. an integral distinguisher. The following theorem describes the relation between the HDIM and the LAT of a function.\n\n\\begin{theorem}[HDIM and LAT]\nLet $S\\colon \\field{n} \\to \\field{m}, n \\ge 3$ be a balanced function. Then\n$$(\\LAT{S}(a,b) \\mod{8})/4 = b^\\top \\times \\HDIM{S} \\times a.$$\n\\end{theorem}\n\\begin{proof}\nBy linearity of the inner product,\n$$\nb^\\top \\times \\HDIM{S} \\times a = \\bigoplus_{x\\in \\field{n}} \\inprod{b,S(x)}\\inprod{a,x}.\n$$\nOn the other hand, using $(-1)^z = 1-2z$ for $z\\in\\field{}$ we obtain:\n$$\n\\LAT{S}(a,b) =\n\\sum_{x\\in \\field{n}}(-1)^{\\inprod{a,x} \\oplus \\inprod{b,S(x)}} =\n\\sum_{x\\in \\field{n}} (1-2\\inprod{a,x})(1-2\\inprod{b,S(x)}).\n$$\nObserve that\n$$\n\\sum_{x\\in\\field{n}}\\inprod{a,x} = 2^{n-1} = \\sum_{x\\in\\field{n}}\\inprod{b,S(x)},\n$$\nwhere the last equality holds because $S$ is balanced.\nIt follows that\n$$\n\\LAT{S}(a,b) =\n4\\sum_{x\\in\\field{n}}\\inprod{a,x}\\inprod{b,S(x)} - 2^n\n$$\nand, for $n \\ge 3$, $\\LAT{S}(a,b) \\equiv 4\\sum_{x\\in \\field{n}}\\inprod{a,x}\\inprod{b,S(x)}\\pmod{8}$.\n\\end{proof}\n\nThe HDIM serves as an interesting link between the algebraic normal form and the linear approximation table of a function. It captures all the information in the LAT modulo 8 and explains the (bi)linear patterns. However, the square patterns in \\FigRef{lat8motiv} are artifacts of the 3- and 4-round Feistel Network structure. These patterns have a simple expression in terms of the HDIM. They will be formalized and proved in \\SecRef{hdim-feistel}.\n\n\\Todo{algorithm for HDIM $\\OO(n2^n)$}\n\n% ======================================\n\n\\subsection{Properties of the HDIM}\n\nThe HDIM inherits some properties from the LAT. In particular, taking the inverse of a permutation or composing a function with affine mappings has a simple effect on the HDIM.\n\n\\begin{proposition}\nLet $S$ be a permutation of $\\field{n}$. Then $$\\HDIM{S^{-1}} = \\HDIM{S}^{\\top}.$$\n\\end{proposition}\n\\begin{proof}\nIt follows from the fact that $\\LAT{S^{-1}} = \\LAT{S}^{\\top}$.\n\\end{proof}\n\n\\begin{proposition}\n\\Label{prop:hdim-linear-effect}\nLet $S\\colon \\field{n} \\to \\field{m}$, and let $\\mu$ and $\\eta$ be linear permutations of $\\field{n}$ and $\\field{m}$ respectively. Let $T=\\eta \\circ S \\circ \\mu$. Then\n$$\n\\HDIM{T} = \\eta \\times \\HDIM{S} \\times (\\mu^{\\top})^{-1}.\n$$\n\\end{proposition}\n\\begin{proof}\n\\begin{align*}\n\\HDIM{T}[i,j] & = e_i^{\\top} \\times \\HDIM{T} \\times e_j = \\\\\n& = \\bigoplus_{x\\in \\field{n}} \\inprod{e_i,\\eta(S(\\mu(x)))} \\inprod{e_j,x} = \\\\\n& = \\bigoplus_{z\\in \\field{n}} \\inprod{e_i,\\eta(S(z))} \\inprod{e_j,\\mu^{-1}\\times z} = \\\\\n& = \\bigoplus_{z\\in \\field{n}} \\inprod{\\eta^{\\top}\\times e_i,S(z)} \\inprod{(\\mu^{\\top})^{-1}\\times e_j, z} = \\\\\n& = (e_i^{\\top} \\times \\eta) \\times \\HDIM{S} \\times ((\\mu^{\\top})^{-1} \\times e_j).\n\\end{align*}\nThe proposition follows.\n\\end{proof}\n\n% ======================================\n\n\\subsection{Generalization of the LAT-ANF link}\n\\SecLabel{gen-lat-anf}\n\nFor the rest of the chapter, the link between the HDIM and the LAT will not be used. However, I would like to note a generalization of this link for congruences of the LAT modulo higher powers of 2, for example, modulo 16, 32, etc. The link connects \\emph{sums} of the Walsh transform over subspaces with ANF coefficients of lower degree. It is based on the following theorem that relates the sum of a Boolean function $f$ over a linear subspace $V\\subseteq\\field{n}$ with the sum of the Walsh transform of $f$ over the orthogonal complement of $V$. The first quantity is directly related to the ANF of $f$.\n\n\\begin{theorem}[Poisson Summation,{\\cite[p.147]{LehmerPoisson}}]\nLet $f\\colon \\field{n} \\to \\field{}$ and let $V\\subseteq \\field{n}$ be a linear subspace. Then\n$$\n\\sum_{a \\in V}\\walsh{f}(a) = 2^n-2^{\\dim{V}+1}\\sum_{x \\in V^{\\bot}}f(x).\n$$\n\\end{theorem}\n\\begin{proof}\nObserve that\n$$\n\\sum_{a \\in V}\\walsh{f}(a) =\n\\sum_{a \\in V}\\sum_{x \\in \\field{n}}(-1)^{\\inprod{a,x}\\oplus f(x)} =\n\\sum_{x \\in \\field{n}}(-1)^{f(x)} \\sum_{a \\in V} (-1)^{\\inprod{a,x}}.\n$$\nIf $x \\in V^{\\bot}$, then $\\sum_{a\\in V}(-1)^{\\inprod{a,x}}=|V|$. Otherwise, $\\inprod{a,x}=1$ exactly for half of $V$ and therefore, $\\sum_{a\\in V}(-1)^{\\inprod{a,x}}=0$. It follows that\n$$\n\\sum_{a \\in V}\\walsh{f}(a) =\n|V|\\sum_{x \\in V^{\\bot}}(-1)^{f(x)} = \n|V|\\pround{|V^{\\bot}|-2\\sum_{x \\in V^{\\bot}}f(x)} = \n2^n-2^{\\dim{V}+1}\\sum_{x \\in V^{\\bot}}f(x).\n$$\n\\end{proof}\n\n\\begin{corollary}\nLet $f\\colon \\field{n} \\to \\field{}$ be balanced. For any linear subspace $V \\subseteq \\field{n}$\n$$\n2^n - \\sum_{a \\in V}\\walsh{f}(a)\n\\equiv\n2^{\\dim{V}+1} \\pround{\\bigoplus_{x\\in \\field{V^{\\bot}}} f(x)} \\pmod{{2^{\\dim{V}+2}}}.\n$$\nIn particular, the link between the LAT and the ANF established using HDIM follows for $n\\ge 3$:\n$$\n\\pround{\\walsh{f}(e_j) \\mod{8}}/4 = \\bigoplus_{x \\in \\field{n},\\inprod{e_j,x}=0} f(x),\n$$\nwhere the last expression is the ANF coefficient of the monomial $x_1\\ldots x_n/x_j$.\n\\end{corollary}\n\n\\begin{example}\nConsider the monomial $x^u = x_3x_4\\ldots x_{n}$ of degree $n-2$. The corresponding coefficient $a_u$ in the ANF of $f$ can be expressed as (for $n \\ge 4$):\n$$\na_u = \\frac{1}{8}\\proundd{\\pround{\n\\walsh{f}(e_{1})+\\walsh{f}(e_{2})+\\walsh{f}(e_{1}+e_{2})\n} \\mod{16}}.\n$$\n\\end{example}\n\n\\Todo{check with code}\n\n% ======================================\n\n\\subsection{Generalization of the HDIM-ANF link}\n\\SecLabel{gen-hdim-anf}\n\nThe HDIM-ANF link provides an expression for a coefficient of the monomial $x_1\\ldots x_n/x_j$ in the ANF of a balanced Boolean function $f\\colon \\field{n} \\to \\field{}$,\n$$\na_u = \\bigoplus_{x \\in \\field{n}} f(x) \\cdot \\inprod{e_j, x},\n$$\nwhere $1 \\le j \\le n$ and $u \\in \\field{n}$ is such that $u_i = 1$ if and only if $i \\ne j$. This idea can be generalized for monomials of lower degrees:\n\n\\begin{proposition}\n\\PropLabel{anf-alternative}\nLet $f\\colon \\field{n} \\to \\field{}$ and $u \\in \\field{n}$. Then the coefficient $a_u$ of the monomial $x^u \\eqdef x_1^{u_1}\\ldots x_n^{u_n}$ can be computed as:\n$$\na_u = \\bigoplus_{x \\in \\field{n}} f(x) \\cdot (\\lnot x)^{\\lnot u},\n$$\nwhere $(\\lnot x)^{\\lnot u} \\eqdef (x_1 \\oplus 1)^{u_1 \\oplus 1}\\ldots (x_n \\oplus 1)^{u_n \\oplus 1}$.\n\\end{proposition}\n\\begin{proof}\nThe term $(\\lnot x)^{\\lnot u}$ is equal to one if and only if $x_i = 0$ for all $i$ such that $u_i = 0$, or, equivalently, $x \\preceq u$. It follows that the equation from the proposition is equivalent to\n$$\na_u = \\bigoplus_{x\\preceq u} f(x),\n$$\nwhich is exactly the expression of the ANF coefficient $a_u$ obtained from the \\Mobius{} inversion formula.\n\\end{proof}\n\n\\begin{remark}\nThe Boolean function $f$ can be replaced by a coordinate $\\inprod{e_i, S}$ of vectorial Boolean function $S$.\n\\end{remark}\n\n\\begin{remark}\nThe HDIM expression involves $\\inprod{x, e_i} = x^e_i = x^{\\lnot u}$. Since $f$ is balanced (i.e. \\txor{}s to zero), it is indeed equivalent to $(\\lnot x)^{\\lnot u}$. For degrees lower than $n-1$, this is not true in general.\n\\end{remark}\n\nThe generalization of the HDIM-ANF link can be used to directly prove a useful general composition bound by Boura and Canteaut~\\cite[Corollary~2]{influence}.\n\n\\begin{proposition}\n\\PropLabel{deficiency}\nLet $F$ be a permutation of $\\field{n}$ and let $g\\colon \\field{n} \\to \\field{}$. Then\n$$\n\\deg{g\\circ F} \\le n - \\ceil{\\frac{n- \\deg{g}}{\\deg{F^{-1}}}}.\n$$\n\\end{proposition}\n\\begin{proof}\nBy \\PropRef{anf-alternative}, the coefficient $a_u$ of the monomial $x^u$ in the ANF of $g \\circ F$ can be computed as\n$$\na_u = \\bigoplus_{x\\in \\field{n}} g(F(x)) \\cdot (\\lnot x)^{\\lnot u} = \\bigoplus_{z \\in \\field{n}} g(z) \\cdot (\\lnot F^{-1}(z))^{\\lnot u}.\n$$\nIf follows that $a_u = 0$ if\n$$\n\\deg{\\pround{g(z) \\cdot (\\lnot F^{-1}(z))^{\\lnot u}}} < n,\n$$\nwhich is definitely true if\n$$\n\\deg{g} + (n - \\wt(u)) \\cdot \\deg{F^{-1}} < n.\n$$\nEquivalently, $a_u = 0$ if\n$$\n\\wt(u) > n - \\frac{n-\\deg{g}}{\\deg{F^{-1}}}.\n$$\nIt follows that\n$$\n\\deg{g\\circ F} \\le n - \\frac{n-\\deg{g}}{\\deg{F^{-1}}} \\le n - \\ceil{\\frac{n-\\deg{g}}{\\deg{F^{-1}}}}.\n$$\n\nI remark that strict inequality from Corollary~2 from~\\cite{influence} is equivalent to this inequality by switching the rounding up to the rounding down.\n\\end{proof}", "meta": {"hexsha": "684a73339aa1dc9ec76b37afe04f6ed747579ffb", "size": 10887, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/9strFeistel/1hdim.tex", "max_stars_repo_name": "hellman/thesis", "max_stars_repo_head_hexsha": "6ba1c2b241e63c07cf76108481c1b67f21a50f12", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2019-05-16T19:55:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T15:36:12.000Z", "max_issues_repo_path": "thesis-source/9strFeistel/1hdim.tex", "max_issues_repo_name": "hellman/thesis", "max_issues_repo_head_hexsha": "6ba1c2b241e63c07cf76108481c1b67f21a50f12", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-08-09T11:26:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-09T11:26:45.000Z", "max_forks_repo_path": "thesis-source/9strFeistel/1hdim.tex", "max_forks_repo_name": "hellman/thesis", "max_forks_repo_head_hexsha": "6ba1c2b241e63c07cf76108481c1b67f21a50f12", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-05T19:40:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T19:40:16.000Z", "avg_line_length": 49.7123287671, "max_line_length": 736, "alphanum_fraction": 0.6729126481, "num_tokens": 3760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7026812036343599}}
{"text": "\\section{Some Properties of Probability Measure and More Counting}\r\n\\subsection{Elementary Results}\r\nLet $(\\Omega,\\mathscr F,\\mathbb P)$ be a probability space.\r\n\\begin{proposition}[Countable Subadditivity]\r\n    Let $(A_n)_{n\\in\\mathbb N}\\in\\mathscr F$, then\r\n    $$\\mathbb P\\left( \\bigcup_{n\\in\\mathbb N}A_n \\right)\\le\\sum_{n=1}^\\infty \\mathbb P(A_n)$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Consider $B_1=A_1$ and $B_n=A_n\\setminus (A_1\\cup A_2\\cup\\cdots\\cup A_{n-1})$.\r\n    The result follows.\r\n\\end{proof}\r\n$\\mathbb P$ is upward continuous.\r\n\\begin{proposition}\r\n    Suppose $(A_n)_n\\in\\mathbb N\\in\\mathscr F$ is increasing, then\r\n    $$\\mathbb P(A_n)\\to \\mathbb P\\left( \\bigcup_{n\\in\\mathbb N} A_n\\right)$$\r\n    as $n\\to\\infty$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Consider $B_1=A_1$ and $B_n=A_n\\setminus (A_1\\cup A_2\\cup\\cdots\\cup A_{n-1})$.\r\n    Note that $\\mathbb P(A_n)=\\mathbb P(B_1)+\\cdots+\\mathbb P(B_n)$, so\r\n    $$\\mathbb P(A_n)=\\sum_{k=1}^n\\mathbb P(B_k)=\\mathbb P\\left(\\bigcup_{k=1}^nB_n\\right)=\\mathbb P\\left( \\bigcup_{k=1}^nA_n \\right)\\to\\mathbb P\\left( \\bigcup_{n\\in\\mathbb N} A_n\\right)$$\r\n    As desired.\r\n\\end{proof}\r\nBy taking complement, we know that $\\mathbb P$ is also downward continuous.\r\n\\begin{proposition}[Inclusion-Exclusion Principle]\r\n    Let $A_1,A_2,\\ldots,A_n$ be events, then we have\r\n    $$\\mathbb P(A_1\\cup\\cdots\\cup A_n)=\\sum_{k=1}^n(-1)^{k+1}\\sum_{1\\le i_1<\\cdots<i_k\\le n}\\mathbb P(A_{i_1}\\cap\\cdots\\cap A_{i_k})$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Induction.\r\n\\end{proof}\r\nFor the probability on finite sample space with equally likely outcomes, the principle reduced to the known inclusion-exclusion principle on finite sets.\r\n\\begin{corollary}\r\n    Let $A_1,A_2,\\ldots,A_n$ be sets, then we have\r\n    $$|A_1\\cup\\cdots\\cup A_n|=\\sum_{k=1}^n(-1)^{k+1}\\sum_{1\\le i_1<\\cdots<i_k\\le n}|A_{i_1}\\cap\\cdots\\cap A_{i_k}|$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Follows directly.\r\n\\end{proof}\r\n\\begin{proposition}[Bonferroni Inequality]\r\n    Truncating the inclusion-exclusion formula after the $n^{th}$ term gives an overestimate if $n$ is odd and underestimate if $n$ is even.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\subsection{Counting by Inclusion-Exclusion}\r\nInclusion-Exclusion allows us to do some more counting.\\\\\r\nWe want to count the number of surjections $\\{1,2,\\ldots,n\\}\\to\\{1,2,\\ldots,m\\}$ for $m\\le n$.\r\nTake $\\Omega=\\{f:\\{1,2,\\ldots,n\\}\\to\\{1,2,\\ldots,m\\}\\}$ and $A$ be the set of surjections.\r\nLet $A_i=\\{f\\in\\Omega:i\\notin \\operatorname{Im}f\\}$, so $A=A_1^c\\cap\\cdots\\cap A_m^c=(A_1\\cup\\cdots\\cup A_m)^c$.\r\nNow since we have $|A_{i_1}\\cap\\cdots\\cap A_{i_k}|=(m-k)^n$, hence by Inclusion-Exclusion, we have\r\n$$|A|=\\sum_{k=0}^m(-1)^k\\binom{m}{k}(m-k)^n$$\r\n(Note that a complement has been taken.)\\\\\r\nWe now want to count the number of derangements of $\\{1,2,\\ldots,n\\}$.\r\nLet $\\Omega=S_n$ and $A$ be the set of derangements.\r\nLet $A_i=\\{\\sigma\\in\\Omega:\\sigma(i)=i\\}$, so again $A=(A_1\\cup\\cdots\\cup A_n)^c$.\r\nBut we have $|A_{i_1}\\cap\\cdots\\cap A_{i_k}|=(n-k)!$, so assume an equally likely probability measure $\\mathbb P$, we then have\r\n$$\\mathbb P(A^c)=\\sum_{k=1}^n(-1)^{k+1}\\frac{n}{k}\\frac{(n-k)!}{n!}\\implies \\mathbb P(A)=\\sum_{k=0}^n(-1)^k\\frac{1}{k!}\\to \\frac{1}{e}$$\r\nSo asymptopically $|A|\\sim n!/e$.\r\n\\subsection{Independence}\r\n\\begin{definition}\r\n    $A,B\\in\\mathscr F$ are said to be independent if $\\mathbb P(A)\\mathbb P(B)=\\mathbb (A\\cap B)$.\\\\\r\n    A countable sequence $(A_n)_{n\\in\\mathbb N}$ of events is independent if $\\forall k\\ge 2$ and for any set of indices $i_1,i_2,\\ldots,i_k$ we have\r\n    $$\\mathbb P(A_{i_1}\\cap\\cdots\\cap A_{i_k})=\\mathbb P(A_{i_1})\\cdots\\mathbb P(A_{i_k})$$\r\n\\end{definition}\r\n\\begin{remark}\r\n    1. Pairwise independence does not imply independence.\r\n    Say we flip a fair coin twice, then $\\Omega=\\{(0,0),(0,1),(1,0),(1,1)\\}$ and $A=\\{(0,0),(0,1)\\},B=\\{(0,0),(1,0)\\},C=\\{(0,1),(1,0)\\}$, then they are pairwisely independent but not independent.\\\\\r\n    2. If $A$ is independent of $B$, then $A$ is also independence of $B^c$.\r\n\\end{remark}\r\n\\begin{definition}\r\n    Let $A,B$ be events such that $\\mathbb P(B)>0$.\r\n    The conditional probability is defined as\r\n    $$\\mathbb P(A|B)=\\frac{\\mathbb P(A\\cap B)}{\\mathbb P(B)}$$\r\n\\end{definition}\r\nIn particular, $\\mathbb P(A|B)=\\mathbb P(A)$ iff $A,B$ are independent.\r\n\\begin{proposition}\r\n    Let $(A_n)_{n\\in\\mathbb N}$ be a sequence of disjoint events, then\r\n    $$\\mathbb P\\left( \\bigcup_{n\\in\\mathbb N}A_n\\middle|B \\right)=\\sum_{n\\in\\mathbb N}\\mathbb P(A_n|B)$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nSo conditional probability measure is also a probability measure.\r\n\\begin{theorem}[Law of Total Probability]\r\n    Suppose $(B_n)_{n\\in\\mathbb N}$ is a disjoint sequence of events such that $\\mathbb P(B_n)>0$ for all $n$ and $\\bigcup B_n=\\Omega$.\r\n    Then\r\n    $$\\mathbb P(A)=\\sum_{n\\in\\mathbb N}\\mathbb P(A|B_n)\\mathbb P(B_n)$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\n\\begin{theorem}[Bayes' Formula]\r\n    Let $(B_n)_{n\\in\\mathbb N}$ be as above and $\\mathbb P(A)>0$, then\r\n    $$\\mathbb P(B_n|A)=\\frac{\\mathbb P(A|B_n)\\mathbb P(B_n)}{\\sum_{k}\\mathbb P(A|B_k)\\mathbb P(B_k)}$$\r\n\\end{theorem}\r\n\\begin{example}[False Positives for a Rare Condition]\r\n    Consider a rare medical condition $A$ which affects $0.1\\%$ of the population and a medical test which is positive for $98\\%$ of the people affected and $1\\%$ of those unaffected by the condition.\r\n    Take a random person, then we want to know the probablity that he has condition $A$ given that he was tested positive.\r\n    Let $A$ be the event of individuals suffering from the condition and $P$ be the individuals being tested positive.\r\n    Hence\r\n    $$\\mathbb P(A|P)=\\frac{\\mathbb P(P|A)\\mathbb P(A)}{\\mathbb P(P|A^c)\\mathbb P(A^c)+\\mathbb P(P|A)\\mathbb P(A)}\\approx 8.9\\%$$\r\n    This may seems counterintuitive since this probability seems low, but the thing is that $\\mathbb P(P|A^c)>>\\mathbb P(P|A)$ since the medical condition is so rare.\r\n\\end{example}\r\n\\begin{example}[Extra Knowledge Changes Probability]\r\n    Consider the following statements:\\\\\r\n    (a) I have $2$ childrens, the elder of whom is a boy.\\\\\r\n    (b) I have $2$ childrens, one of whom is a boy.\\\\\r\n    (c) I have $2$ childrens, one of whom is a boy who is born on a Tuesday.\\\\\r\n    We assume equally likely distributions.\r\n    Let $GB$ denotes that the younger is a girl and the elder is a boy.\r\n    Similar for $BG,BB,GG$.\r\n    $$\\mathbb P(BB|a)=\\mathbb P(BB|BG\\cup BB)=\\frac{1}{2}$$\r\n    $$\\mathbb P(BB|b)=\\mathbb P(BB|BG\\cup GB\\cup BB)=\\frac{1}{3}$$\r\n    Write $TN$ be that there are two boy, the younger is born on Tuesday but the elder is not, similar for ($2$-)combinations of $T,N,G$.\r\n    \\begin{align*}\r\n        \\mathbb P(BB|c)&=\\mathbb P(TT\\cup TN\\cup NT|TT\\cup TN\\cup NT\\cup TG\\cup GT)\\\\\r\n        &=\\frac{\\mathbb P(TT\\cup TN\\cup NT)}{\\mathbb P(TT\\cup TN\\cup NT\\cup GT\\cup TG)}\\\\\r\n        &=\\frac{13}{27}\r\n    \\end{align*}\r\n\\end{example}\r\n\\begin{example}[Simpson's Paradox]\r\n    There are $50$ men and $50$ women applying to a college.\r\n    \\begin{center}\r\n        \\begin{tabular}{c|c|c|c}\r\n            \\hline\r\n            All applicants&Admitted&Rejected&Success Rate\\\\\r\n            \\hline\r\n            State&25&25&50\\%\\\\\r\n            Indep&28&22&56\\%\\\\\r\n            \\hline\r\n            Men Only&Admitted&Rejected&Success Rate\\\\\r\n            \\hline\r\n            State&15&22&41\\%\\\\\r\n            Indep&5&8&38\\%\\\\\r\n            \\hline\r\n            Women Only&Admitted&Rejected&Success Rate\\\\\r\n            \\hline\r\n            State&10&3&77\\%\\\\\r\n            Indep&23&14&68\\%\r\n        \\end{tabular}\r\n    \\end{center}\r\n    So both men and women in state schools have higher acceptance rate, but the overall acceptance rate of state schools is still lower than that in independent schools.\r\n    This is because the overall acceptance rate for women in this set of data is larger and there are much more of them in independent schools than state schools.\r\n    Basically it is because $A/B>a/b$ and $C/D>c/d$ does not imply $(A+C)/(B+D)>(a+c)/(b+d)$.\r\n\\end{example}\r\n", "meta": {"hexsha": "5d90b1666915d8c507baa513e1d1941cf10a3020", "size": 8124, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/prop.tex", "max_stars_repo_name": "david-bai-notes/IA-Probability", "max_stars_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3/prop.tex", "max_issues_repo_name": "david-bai-notes/IA-Probability", "max_issues_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3/prop.tex", "max_forks_repo_name": "david-bai-notes/IA-Probability", "max_forks_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.2653061224, "max_line_length": 201, "alphanum_fraction": 0.6493106844, "num_tokens": 2868, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706735, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7026812002489833}}
{"text": "% declare document class and geometry\n\\documentclass[12pt]{article} % use larger type; default would be 10pt\n\\usepackage[margin=1in]{geometry} % handle page geometry\n\n\\input{../header2.tex}\n\n\\title{Phys 220A -- Classical Mechanics -- Lec09}\n\\author{UCLA, Fall 2014}\n\\date{\\formatdate{30}{10}{2014}} % Activate to display a given date or no date (if empty),\n         % otherwise the current date is printed \n\n\\begin{document}\n\\setlength{\\unitlength}{1mm}\n\\maketitle\n\n\n\\section{Proof of Liouville's theorem}\n\nIf we imagine we have $N$ coordinates $x^i$ and we consider an infinitesimal volume element then we can consider a change in coordinates that if we define new coordinates as a function of the old coordinates we have\n\\begin{equation}\n\\widetilde{x}^i = f^i(x^j), \\qquad \\dif^n \\widetilde{x} = J \\, \\dif^n x.\n\\end{equation}\nwhere $J$ is the Jacobian,\n\\begin{equation}\nJ = \\det \\pd{\\widetilde{x}^i}{{x^j}}.\n\\end{equation} \nFor an infinitesimal change, what does this mean? It's close to an identity so our new coordinates can be written\n\\begin{equation}\n\\widetilde{x}^i = x^i + \\epsilon v^i (x^j)\n\\end{equation}\nfor some function $V^i(x^j)$. Then the Jacobian is just\n\\begin{equation}\nJ = \\det(\\delta^i_j + \\epsilon \\pd{v^i}{{x^j}}).\n\\end{equation}\nOne can show using linear algebra that when we expanding this the term of order $\\epsilon$ is simply the trace. So up to first order\n\\begin{equation}\nJ = 1 + \\epsilon \\tr \\left( \\dpd{v^i}{{x^j}} \\right) \n\t= 1 + \\epsilon \\sum_i \\dpd{v^i}{{x^i}}.\n\\end{equation}\nSo now our volume element is\n\\begin{equation}\n\\dif^n \\widetilde{x} = \\dif^n x \\, J = \\dif^n x \\left( 1 + \\epsilon \\sum_i \\dpd{v^i}{{x^i}} \\right).\n\\end{equation}\nThe volume element does not change if the vector field $v_i$ is divergence free, i.e.\n\\begin{equation}\n\\sum_i \\pd{v^i}{{x^i}} = 0.\n\\end{equation}\nNow we'll apply this to the Hamilton's equations. Now instead of $x^i$ we really have a set of coordinates $\\set{q_i, p_i}$ where both position and momentum are coordinates. And then we have our Hamilton's equations. How do we now view those? The equations are time evolution equations but now we map it to an infinitesimal time, i.e.\n\\begin{equation}\nq_i(t + \\dif{t}) = \\widetilde{q_i}, \\qquad \np_i(t + \\dif{t}) = \\widetilde{p_i}.\n\\end{equation}\nNow hamilton's equations become\n\\begin{equation}\n\\widetilde{q_i} = q_i + \\pd{H}{p_i} \\dif{t}, \\qquad\n\\widetilde{p_i} = p_i - \\pd{H}{q_i} \\dif{t}.\n\\end{equation}\nOur $\\epsilon$ here is an infinitesimal time step $\\dif{t}$, our $V$ becomes\n\\begin{equation}\nV^k = \\set{ \\dpd{H}{p_i}, - \\dpd{H}{q_i} },\n\\end{equation}\nand our volume element is\n\\begin{equation}\n\\dif^nx \\rightarrow \\dif^N q \\, \\dif^N p\n\\end{equation}\nApplying the general formula\n\\begin{equation}\n\\dif^N \\widetilde{q} \\, \\dif^N \\widetilde{p} =\\dif^N q \\, \\dif^N p \\left[ 1 + \\dif{t} \\sum_{i=1}^N \\left( \\dpd{}{q_i} \\dpd{H}{p_i} - \\dpd{}{p_i} \\dpd{H}{q_i} \\right) \\right],\n\\end{equation}\nthe second term is zero,\n\\begin{equation}\n\\dif^N \\widetilde{q} \\, \\dif^N \\widetilde{p} =\\dif^N q \\, \\dif^N p.\n\\end{equation}\nUnder Hamiltonian time evolution, the volume of phase space is invariant. The flow in phase space is incompressible. Note however that volume is not conserved in certain cases, for example when there is friction.\n\n\n\\section{Phase space density}\n\nFrom here we can start to see a route to classical statistical mechanics. Suppose we have some phase space density\n\\begin{equation}\n\\rho(p_i, q_i, t) \n\\end{equation}\nwhich depends on all $2N$ coordinates in phase space. We can normalize so that it is a probability distribution,\n\\begin{equation}\n\\int \\dif^n p \\, \\dif^n q \\, \\rho(p_i q_i, t) = 1,\n\\end{equation}\nbut we won't go into that and instead save it for later. An example will be the classical Boltzmann distribution\n\\begin{equation}\n\\rho \\propto \\exp \\left(-\\frac{H(p, q, t)}{kt} \\right).\n\\end{equation}\nThe volume element stays invariant so basically you then realize that we can say what the time evolution of this distribution. So we can take the time derivative and think about the time evolution from Liouville theorem and find that\n\\begin{equation}\n\\d{}{t} \\rho(p_i, q_i, t) = 0.\n\\end{equation}\nWorking around with this a bit, we find\n\\begin{align}\n0 &= \\dpd{\\rho}{t} + \\dpd{\\rho}{p_i} \\dot{p}_i + \\dpd{\\rho}{q_i} \\dot{q}_i \\\\\n\t&= \\dpd{\\rho}{t} + \\sum_i \\left( -\\dpd{\\rho}{p_i} \\dpd{H}{q_i} + \\dpd{\\rho}{q_i} \\dpd{H}{p_i} \\right),\n\\end{align}\nthus we have\n\\begin{equation}\n\\pd{\\rho}{t} = \\sum_i \\left( \\dpd{\\rho}{q_i} \\dpd{H}{p_i} - \\dpd{\\rho}{p_i} \\dpd{H}{q_i} \\right).\n\\end{equation}\nSo this gives us a continuity equation for $\\rho$. \n\n\n\\section{Poincare Recurrence Theorem}\n\nWhat can we say about staying at point in phase space and evolving in time. Basically we can pick a small neighborhood about the point and if you wait long enough, the point will come back to that neighborhood and come arbitrary close. So we'll have Hamiltonian evolution. Also we have to say that this is in a bounded phase space. \n\n\\begin{theorem}\nUnder Hamiltonian evolution in a system with bounded phases space $M$ (i.e. the allowed region in phase space has finite volume). Given an initial point $P = \\set{p_i(t_0), q_i(t_0)}$ and a neighborhood $U$ of $P$, there is a point $P'$ in $U$ which returns to $U$ in finite time. \n\\end{theorem}\n\n\\begin{proof}\nConsider a map that evolves in time points in phase space\n\\begin{eqn}\ng_t : \\set{p_i(0), q_i(0)} \\mapsto \\set{p_i(t), q_i(t)},\n\\end{eqn}\nwhich maps phase space to phase space. Consider taking the map many times on itself, i.e.\n\\[\nU \\rightarrow g_t(U) \\rightarrow g_t^2 (U) \\rightarrow g_t^3 (U) \\rightarrow \\dots.\n\\]\nNow, there must be some intersecting $g^k(U)$ and $g^\\ell(U)$, since otherwise we would have\n\\begin{eqn}\n\\opname{Vol} M > \\sum_{n=0}^\\infty \\opname{Vol} g^n (U) = \\infty \\times \\opname{Vol} U.\n\\end{eqn}\nThen taking the inverse map $g^{-\\ell}$ of $g^k (U) \\cap g^\\ell (U) \\neq \\varnothing$, we have\n\\begin{eqn}\ng^{k-\\ell} (U) \\cap U \\neq \\varnothing.\n\\end{eqn}\nThus, calling $n = k - \\ell$, if \n\\begin{eqn}\ny \\in g^n(U) \\cap U,\n\\end{eqn}\nthen \n\\begin{eqn}\ny = g^n (x) \\in U\n\\end{eqn}\nfor some $x \\in U$. \n\\end{proof}\n\n\n\\section{Poisson Brackets}\n\n\\begin{itemize}\n\\item Geometrical structure on phase space (symmetric structure)\n\\item New higher level understanding of symmetry (Algebra of charges)\n\\item Makes classical mechanics almost look like QM\n\\end{itemize}\nRecall that time dependence of a ``phase space observable'' $A(p, q, t)$ can be written\n\\begin{align}\n\\dod{A}{t} &= \\dpd{A}{t} + \\sum_i\\left( \\dpd{A}{p_i} \\dod{p_i}{t} + \\dpd{A}{q_i} \\dpd{q_i}{t} \\right) \\\\\n\t&= \\dpd{A}{t} + \\sum_i \\left( \\dpd{A}{q_i} \\dpd{H}{p_i} - \\dpd{A}{p_i} \\dpd{H}{q_i} \\right) \\\\\n\t&= \\dpd{A}{t} + \\{A, H\\}\n\\end{align}\nwhere $\\{A, B\\}$ is the Poisson bracket\n\\begin{eqn}\n\\{A,B\\} \\equiv \\sum_i \\left( \\dpd{A}{q_i} \\dpd{B}{p_i} - \\dpd{A}{p_i} \\dpd{B}{q_i} \\right).\n\\end{eqn}\n\nLet's look at the algebraic properties. We have antisymmetry\n\\begin{equation}\n\\{A, B\\} = - \\{B, A\\},\n\\end{equation}\nlinearity across real numbers\n\\begin{equation}\n\\{\\alpha A + \\beta B, C\\} = \\alpha\\{ A, C\\} + \\beta\\{B, C\\},\n\\end{equation}\nLeibnitz rule\n\\begin{equation}\n\\{AB, C\\} = A\\{B, C\\} + \\{ A, C\\} B,\n\\end{equation}\nand the Jacobi identity\n\\begin{equation}\n\\{A, \\{B, C\\}\\} + \\{B, \\{C, A\\}\\} + \\{C, \\{A, B\\}\\} = 0.\n\\end{equation}\n\nThese are the properties that also hold for the commutator in quantum mechanics and the Lie bracket for Lie algebras and Lie derivatives for manifolds. But In quantum mechanics, the objects you put into the commutator are not $c$-numbers but operators, so that order matters, i.e.\n\\begin{equation}\n\\{AB, C\\} = A\\{B, C\\}+ \\{A, C\\} B\n\\end{equation}\nis NOT the same as\n\\begin{equation}\n\\{AB, C\\} = A\\{B, C\\}+ B\\{A, C\\} \n\\end{equation}\nfor Lie brackets and commutators. \n\nWe can now rewrite Hamilton's equations as\n\\begin{equation}\n\\dot{q_i} = \\{q_i, H\\}, \\qquad \n\\dot{p_i} = \\{ p_i, H\\}.\n\\end{equation}\n(Note that conservation laws for some quantity $A$ assume that $A$ does not have explicit time dependence.)\n\nIf $A$ and $B$ are conserved then so is $\\{A, B\\}$. So if we have\n\\begin{equation}\n\\{A, H\\} = 0, \\qquad \n\\{B, H\\} = 0\n\\end{equation}\nThen the quantity\n\\begin{equation}\nC = \\{A, B\\}\n\\end{equation}\nis also conserved. Using the Jacobi identity\n\\begin{equation}\n\\{H, C\\} = \\{H, \\{A, B\\}\\} = -\\{A, \\{B, H\\}\\} + \\{B, \\{A, H\\}\\} = 0,\n\\end{equation}\nso we see that $C$ is also conserved.\n\nFor example, angular momentum components $L_1$ and $L_2$ are conserved. Then $\\{L_1, L_2\\}$ is conserved\n\n[incomplete. continued in next lecture?]\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "7361fc83045561ebf0c3538b8d8322a87311a128", "size": 8561, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "classical/lec09.tex", "max_stars_repo_name": "paulinearriaga/phys-ucla", "max_stars_repo_head_hexsha": "48084dbbac2f8a4748c1fdaaf63a4cebaae16809", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "classical/lec09.tex", "max_issues_repo_name": "paulinearriaga/phys-ucla", "max_issues_repo_head_hexsha": "48084dbbac2f8a4748c1fdaaf63a4cebaae16809", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "classical/lec09.tex", "max_forks_repo_name": "paulinearriaga/phys-ucla", "max_forks_repo_head_hexsha": "48084dbbac2f8a4748c1fdaaf63a4cebaae16809", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9136363636, "max_line_length": 334, "alphanum_fraction": 0.6815792548, "num_tokens": 3075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7026811892525664}}
{"text": "%\n% Chapter 1.4\n%\n\n\\section*{1.4 Tangent and Velocity} \n\nA \\textbf{tangent} is a line touching a curve. A tangent line has the same direction as the curve at the point of contact. A secant line, on the other hand, cuts through the curve more than once.\n\\\\\\\\\nTo find the tangent at a point on a curve (in slope-intercept form: \\(y=mx+b\\)), we must find the slope \\(m\\) at that point and use it to find \\(b\\) (the \\(y\\)-intercept). \n\n\\subsection*{Average Velocity}\n\n$$\\text{average velocity} = \\frac{\\text{change in position}}{\\text{elapsed time}}$$ \n", "meta": {"hexsha": "5540f713fb50ba14a84390ba1783ed44a3ce0857", "size": 549, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/1-4.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/1-4.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/1-4.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.2142857143, "max_line_length": 195, "alphanum_fraction": 0.6994535519, "num_tokens": 158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.7025924381931681}}
{"text": "\\section{Statistical Analysis}\n\\label{sec:statisticalAnalysis}\nOne of the most assessed ways to investigate the impact of the intrinsic variation of the input space is through the computation of\nstatistical moments and linear correlation among variables/parameters/FOMs.\n\nAs shown in Section~\\ref{sec:forwardSamplingStrategies}, RAVEN employs several different sampling methodologies to explore the response of a model subject to uncertainties. In order to correctly compute the statistical moments a weight-based approach is used. Each \\textit{Sampler} in RAVEN associate to each ``sample'' (i.e.\nrealization in the input/uncertain space) a \\textbf{weight}  to represent the \\textit{importance} of the particular\ncombination of input values from a statistical point of view (e.g., reliability weights). These weights are used in subsequential\nsteps in order to compute the previously listed statistical moments and correlation metrics.\n\\\\In the following subsections, the formulation of these statistical moments is reported.\n\\subsection{Expected Value}\nThe expected value represents one of the most fundamental metrics in probability theory: it represents a measurement of the center of the distribution (mean) of the random variable.\nFrom a practical point of view, the expected value of a discrete random variable is the probability-weighted average of all possible values of the subjected variable. Formally, the expected value of a random variable $X$:\n\\begin{equation}\n\\begin{matrix}\n\\mathbb{E}(X) = \\mu = \\sum_{x \\in \\chi} x  pdf_{X}(x) & \\text{if  $X$  discrete} \\\\\n\\\\\n\\mathbb{E}(X) = \\mu = \\int_{x \\in \\chi} x pdf_{X}(x) & \\, \\text{if $X$ continuous}\n\\end{matrix}\n\\end{equation}\nIn RAVEN, the expected value (i.e. first central moment) is computed as follows:\n\\begin{equation}\n\\begin{matrix}\n\\mathbb{E}(X) = \\mu \\approx \\overline{x} = \\frac{1}{n} \\sum_{i=1}^{n}  x_{i} & \\text{if  random sampling} \\\\\n\\\\\n\\mathbb{E}(X) = \\mu \\approx \\overline{x} = \\frac{1}{V_{1}} \\sum_{i=1}^{n} w_{i}  x_{i}  & \\, \\text{otherwise}\n\\end{matrix}\n\\end{equation}\nwhere:\n\\begin{itemize}\n  \\item $w_{i}$ is the weight associated with the sample $i$\n  \\item $n$ are the total number of samples\n  \\item $V_{1} = \\sum_{i=1}^{n} w_{i}$.\n\\end{itemize}\n\\subsection{Standard Deviation and Variance}\nThe variance ($\\sigma^{2}$) and standard deviation ($\\sigma$) of $X$ are both measures of the spread of the distribution of the random variable about the\nmean. Simplistically, the variance measures how far a set of realizations of a random variable are spread out.\nThe standard deviation is the square root of the variance. The standard deviation has the same unit of the original data, and hence is comparable to deviations from the mean.\n\\\\Formally:\n\\begin{equation}\n  \\begin{matrix}\n  \\sigma^{2}(X)= \\mathbb{E}\\left(\\left[X - \\mathbb{E}(X)\\right]^{2}\\right) = \\int_{x \\in \\chi} (x - \\mu)^2 pdf(x) dx  & \\,\\text{if $X$ continuous} \\\\\n  \\sigma^{2}(X)= \\mathbb{E}\\left(\\left[X - \\mathbb{E}(X)\\right]^{2}\\right)  = \\sum_{x \\in \\chi} (x - \\mu)^2 pdf(x)  & \\text{if  $X$ discrete}\n  \\\\\n  \\\\\n  \\sigma(X)= \\mathbb{E}\\left(\\left[X - \\mathbb{E}(X)\\right]\\right)  = \\sqrt{\\sigma^{2}(X)}\n  \\end{matrix}\n\\end{equation}\nIn RAVEN, variance (i.e., second central moment) and standard deviation are computed as follows:\n\\begin{equation}\n\\begin{matrix}\n\\mathbb{E}\\left(\\left[X - \\mathbb{E}(X)\\right]^{2}\\right)  \\approx  m_{2} = \\frac{1}{n} \\sum_{i=1}^{n}  (x_{i} - \\overline{x})^{2} & \\text{if  random sampling} \\\\\n\\\\\n\\\\\n\\mathbb{E}\\left(\\left[X - \\mathbb{E}(X)\\right]^{2}\\right)  \\approx m_{2}  = \\frac{1}{V_{1}} \\sum_{i=1}^{n} w_{i}  (x_{i} - \\overline{x})^{2}  & \\, \\text{otherwise}\n\\\\\n\\\\\n\\mathbb{E}\\left(\\left[X - \\mathbb{E}(X)\\right]^{2}\\right)  \\approx s  =  \\sqrt{m_{2}}\n\\end{matrix}\n\\end{equation}\nwhere:\n\\begin{itemize}\n  \\item $w_{i}$ is the weight associated with the sample $i$\n  \\item $n$ are the total number of samples\n  \\item $V_{1} = \\sum_{i=1}^{n} w_{i}$.\n\\end{itemize}\nRAVEN performs an additional correction of variance to obtain an unbiased estimation  with respect to the sample-size~\\cite{RimoldiniUnbiased}:\n\\begin{equation}\n\\begin{matrix}\n\\mathbb{E}\\left(\\left[X - \\mathbb{E}(X)\\right]^{2}\\right)  \\approx M_{2} = \\displaystyle \\frac{n}{n-1}m_{2} & & \\text{if random sampling}\n\\\\\n\\mathbb{E}\\left(\\left[X - \\mathbb{E}(X)\\right]^{2}\\right)  \\approx M_{2} = \\frac{V_{1}^{2}}{V_{1}^{2} - V_{2}}m_{2} &  text{otherwise}\n\\end{matrix}\n\\end{equation}\n\\begin{equation}\nS = \\sqrt{M_{2}}\n\\end{equation}\nwhere:\n\\begin{itemize}\n  \\item $w_{i}$ is the weight associated with the sample $i$\n  \\item $n$ are the total number of samples\n  \\item $V_{1} = \\sum_{i=1}^{n} w_{i}^{1}$.\n  \\item $V_{2} = \\sum_{i=1}^{n} w_{i}^{2}$.\n\\end{itemize}\nIt is important to notice that $S$ is not an unbiased estimator.\n\n\\subsection{Skewness}\nThe Skewness is a measure of the asymmetry of the distribution of a\nreal-valued random variable about its mean. Negative skewness\nindicates that the tail on the left side of the distribution is longer or fatter\nthan the right side.  Positive skewness indicates that the tail on the right\nside is longer or fatter than the left side. From a practical point of view, the\nskewness is useful to identify distortion  of the random variable with respect to\nthe Normal distribution function.\n\\\\Formally,\n\\begin{equation}\n\\gamma_{1} = \\mathbb{E} \\left [ \\left ( \\frac{X-\\mu}{\\sigma} \\right )^{3} \\right ] = \\frac{ \\mathbb{E}\\left [ \\left ( X-\\mu \\right )^{3} \\right ]}{\\left ( \\mathbb{E}\\left [ \\left ( X-\\mu \\right )^{2} \\right ] \\right )^{3/2}}\n\\end{equation}\nIn RAVEN, the skewness is computed as follows:\n\\begin{equation}\n\\begin{matrix}\n\\mathbb{E} \\left [ \\left ( \\frac{X-\\mu}{\\sigma} \\right )^{3} \\right ]  \\approx \\frac{m_{3}}{m_{2}^{3/2}} = \\frac{  \\frac{1}{n} \\sum_{i=1}^{n}  (x_{i} - \\overline{x})^{3} }{\\left ( \\frac{1}{n} \\sum_{i=1}^{n}  (x_{i} - \\overline{x})^{2} \\right )^{3/2}} & \\text{if random sampling}\n\\\\\n\\\\\n\\mathbb{E} \\left [ \\left ( \\frac{X-\\mu}{\\sigma} \\right )^{3} \\right ]  \\approx \\frac{m_{3}}{m_{2}^{3/2}} = \\frac{  \\frac{1}{V_{1}} \\sum_{i=1}^{n} w_{i} \\times (x_{i} - \\overline{x})^{3} }{\\left ( \\frac{1}{V_{1}} \\sum_{i=1}^{n}  w_{i} \\times (x_{i} - \\overline{x})^{2} \\right )^{3/2}} &  \\, \\text{otherwise}\n\\end{matrix}\n\\end{equation}\nwhere:\n\\begin{itemize}\n  \\item $w_{i}$ is the weight associated with the sample $i$\n  \\item $n$ are the total number of samples\n  \\item $V_{1} = \\sum_{i=1}^{n} w_{i}$.\n\\end{itemize}\nRAVEN performs an additional correction of skewness to obtain an unbiased estimation  with respect to the sample-size~\\cite{RimoldiniUnbiased}:\n\\begin{equation}\n\\begin{matrix}\n\\mathbb{E} \\left [ \\left ( \\frac{X-\\mu}{\\sigma} \\right )^{3} \\right ]  \\approx \\frac{M_{3}}{M_{2}^{3/2}}  = \\displaystyle \\frac{n^{2}}{(n-1)(n-2)}m_{3}\\times \\frac{1}{\\left ( \\displaystyle \\frac{n}{n-1}m_{2}  \\right )^{3/2}} & \\text{if random sampling}\n\\\\\n\\\\\n\\mathbb{E} \\left [ \\left ( \\frac{X-\\mu}{\\sigma} \\right )^{3} \\right ]  \\approx \\frac{M_{3}}{M_{2}^{3/2}}  = \\displaystyle \\frac{V_{1}^{3}}{V_{1}^{3}-3V_{1}V_{2}+2V_{3}}m_{3} \\times \\frac{1}{\\left ( \\displaystyle \\frac{V_{1}^{2}}{V_{1}^{2}-V_{2}}m_{2}  \\right )^{3/2}} &  \\,  \\text{otherwise}\n\\end{matrix}\n\\end{equation}\nwhere:\n\\begin{itemize}\n  \\item $w_{i}$ is the weight associated with the sample $i$\n  \\item $n$ are the total number of samples\n  \\item $V_{1} = \\sum_{i=1}^{n} w_{i}^{1}$\n  \\item $V_{2} = \\sum_{i=1}^{n} w_{i}^{2}$\n  \\item $V_{3} = \\sum_{i=1}^{n} w_{i}^{3}$.\n\\end{itemize}\n\n\\subsection{Excess Kurtosis}\nThe  Kurtosis~\\cite{Abramowitz}  is the degree of peakedness of a distribution of a real-valued random variable. In a similar way to the concept of skewness, kurtosis describes the shape of the distribution. The Kurtosis is defined in order to\nobtain a value of $0$ for a Normal distribution. If it is greater than zero, it indicates that the distribution is high peaked; If it is smaller\nthat zero, it testifies that the distribution is flat-topped.\n\\\\Formally, the Kurtosis can be expressed as follows:\n\\begin{equation}\n\\gamma_{2} = \\frac{ \\mathbb{E}\\left [ \\left ( X-\\mu \\right )^{4} \\right ]}{\\left ( \\mathbb{E}\\left [ \\left ( X-\\mu \\right )^{2} \\right ] \\right )^{2}}\n\\end{equation}\nIn RAVEN, the kurtosis (excess) is computed as follows:\n\\begin{equation}\n\\begin{matrix}\n\\frac{ \\mathbb{E}\\left [ \\left ( X-\\mu \\right )^{4} \\right ]}{\\left ( \\mathbb{E}\\left [ \\left ( X-\\mu \\right )^{2} \\right ] \\right )^{2}}   \\approx \\frac{m_{4}-3m_{2}^{2}}{m_{2}^{2}} = \\displaystyle  \\frac{  \\frac{1}{n} \\sum_{i=1}^{n}  (x_{i} - \\overline{x})^{4} -3\\left ( \\frac{1}{n} \\sum_{i=1}^{n}  (x_{i} - \\overline{x})^{2} \\right )^{2}}{\\left ( \\frac{1}{n} \\sum_{i=1}^{n}  (x_{i} - \\overline{x})^{2} \\right )^{2}} & \\text{if random sampling}\n\\\\\n\\\\\n\\frac{ \\mathbb{E}\\left [ \\left ( X-\\mu \\right )^{4} \\right ]}{\\left ( \\mathbb{E}\\left [ \\left ( X-\\mu \\right )^{2} \\right ] \\right )^{2}}   \\approx \\frac{m_{4}-3m_{2}^{2}}{m_{2}^{2}} = \\displaystyle  \\frac{  \\frac{1}{V_{1}} \\sum_{i=1}^{n} w_{i} \\times (x_{i} - \\overline{x})^{4} -3\\left ( \\frac{1}{V_{1}} \\sum_{i=1}^{n}  w_{i} \\times (x_{i} - \\overline{x})^{2} \\right )^{2}}{\\left ( \\frac{1}{V_{1}} \\sum_{i=1}^{n}  w_{i} \\times (x_{i} - \\overline{x})^{2} \\right )^{2}} &   \\text{otherwise}\n\\end{matrix}\n\\end{equation}\nwhere:\n\\begin{itemize}\n  \\item $w_{i}$ is the weight associated with the sample $i$\n  \\item $n$ are the total number of samples\n  \\item $V_{1} = \\sum_{i=1}^{n} w_{i}$.\n\\end{itemize}\nRAVEN performs an additional correction of kurtosis (excess) to obtain an unbiased estimation  with respect to the sample-size~\\cite{RimoldiniUnbiased}:\n\\begin{equation}\n\\begin{split}\n\\begin{matrix}\n\\frac{ \\mathbb{E}\\left [ \\left ( X-\\mu \\right )^{4} \\right ]}{\\left ( \\mathbb{E}\\left [ \\left ( X-\\mu \\right )^{2} \\right ] \\right )^{2}}   \\approx \\frac{M_{4}-3M_{2}^{2}}{M_{2}^{2}}  = \\displaystyle \\frac{n^{2}(n+1)}{(n-1)(n-2)(n-3)}m_{4}-\\frac{3n^{2}}{(n-2)(n-3)}m_{2}^{2} & \\text{if random sampling}\n\\\\\n\\\\\n\\frac{ \\mathbb{E}\\left [ \\left ( X-\\mu \\right )^{4} \\right ]}{\\left ( \\mathbb{E}\\left [ \\left ( X-\\mu \\right )^{2} \\right ] \\right )^{2}}    \\approx \\frac{M_{4}-3M_{2}^{2}}{M_{2}^{2}}  = \\displaystyle  \\frac{V_{1}^{2}(V_{1}^{4}-4V_{1}V_{3}+3V_{2}^{2})}{(V_{1}^{2}-V_{2})(V_{1}^{4}-6V_{1}^{2}V_{2}+8V_{1}V_{3}+3V_{2}^{2}-6V_{4})}m_{4}\n- \\\\\n\\displaystyle \\frac{3V_{1}^{2}(V_{1}^{4}-2V_{1}^{2}V_{2}+4V_{1}V_{3}-3V_{2}^{2})}{(V_{1}^{2}-V_{2})(V_{1}^{4}-6V_{1}^{2}V_{2}+8V_{1}V_{3}+3V_{2}^{2}-6V_{4})}m_{2}^{2} & \\text{otherwise}\n\\end{matrix}\n\\end{split}\n\\end{equation}\nwhere:\n\\begin{itemize}\n  \\item $w_{i}$ is the weight associated with the sample $i$\n  \\item $n$ are the total number of samples\n  \\item $V_{1} = \\sum_{i=1}^{n} w_{i}^{1}$\n  \\item $V_{2} = \\sum_{i=1}^{n} w_{i}^{2}$\n  \\item $V_{3} = \\sum_{i=1}^{n} w_{i}^{3}$\n  \\item $V_{4} = \\sum_{i=1}^{n} w_{i}^{4}$.\n\\end{itemize}\n\n\\subsection{Median}\nThe median of the distribution of a real-valued random variable is the number separating the higher half from the lower half of all\nthe possible values. The median of a finite list of numbers can be found by arranging all the observations from lowest value to highest value and picking the middle value.\n\\\\Formally, the median $m$ can be cast as the number that satisfy the following relation:\n\\begin{equation}\n  P(X\\leq m) = P(X \\geq m) = \\int_{-\\infty}^{m} pdf(x) dx=\\frac{1}{2}\n\\end{equation}\n\n\\subsection{Percentile}\nA percentile (or a centile) is a measure indicating the value below which a given percentage of observations in a group of observations fall.\n\n\\subsection{Covariance and Correlation Matrices}\nSimplistically, the Covariance is a measure of how much two random variables variate together. In other words, It represents a\nmeasurement of the correlation, in terms of variance,  among different variables. If the greater values of one variable mainly\ncorrespond with the greater values of the other variable, and the same holds for the lesser values (i.e., the variables tend to show\nsimilar behavior) the covariance is positive. In the opposite case, when the greater values of one variable mainly correspond to the\nlesser values of the other (i.e., the variables tend to show opposite behavior) the covariance is negative.\nFormally, the Covariance can be expressed as\n\\begin{equation}\n \\boldsymbol{\\Sigma}(\\boldsymbol{X},\\boldsymbol{Y})  = \\mathbb{E} \\left [ \\left ( \\boldsymbol{X}- \\mathbb{E}\\left [ \\boldsymbol{X} \\right ] \\right ) \\left ( \\boldsymbol{Y}- \\mathbb{E}\\left [ \\boldsymbol{Y} \\right ] \\right )^{T}\\right ]\n\\end{equation}\nBased on the previous equation, in RAVEN each entry of the Covariance matrix is computed as follows:\n\\begin{equation}\n\\begin{matrix}\n \\mathbb{E} \\left [ \\left ( X- \\mathbb{E}\\left [ X \\right ] \\right ) \\left ( Y- \\mathbb{E}\\left [ Y \\right ] \\right )\\right ] \\approx\n \\frac{1}{n}\\sum_{i=1}^{n} (x_{i} - \\mu_{x})(y_{i} -  \\mu_{y})  & \\text{if random sampling}\n\\\\\n\\\\\n \\mathbb{E} \\left [ \\left ( X- \\mathbb{E}\\left [ X \\right ] \\right ) \\left ( Y- \\mathbb{E}\\left [ Y \\right ] \\right )\\right ] \\approx\n\\frac{1}{V_{1}} \\sum_{i=1}^{n} w_{i} \\times (x_{i} -  \\mu_{x})(y_{i} -  \\mu_{y}) &   \\text{otherwise}\n\\end{matrix}\n\\end{equation}\nwhere:\n\\begin{itemize}\n  \\item $w_{i}$ is the weight associated with the sample $i$\n  \\item $n$ are the total number of samples\n  \\item $V_{1} = \\sum_{i=1}^{n} w_{i}$.\n\\end{itemize}\nThe correlation matrix (Pearson product-moment correlation coefficient matrix) can be obtained through the Covariance matrix, as follows:\n\\begin{equation}\n\\boldsymbol{\\Gamma}(\\boldsymbol{X},\\boldsymbol{Y}) = \\frac{\\boldsymbol{\\Sigma}(\\boldsymbol{X},\\boldsymbol{Y})}{\\sigma_{x} \\sigma_{y}}\n\\end{equation}\nAs it can be seen, The correlation between $X$ and $Y$ is the\ncovariance of the corresponding standard scores.\n\n\\subsection{Variance-Dependent Sensitivity Matrix}\nThe variance dependent sensitivity matrix is the matrix of the sensitivity\ncoefficients that show the relationship of the individual uncertainty\ncomponent to the standard deviation of the reported value for a test\nitem.\n\\\\ Formally:\n\\begin{equation}\n\\boldsymbol{\\Lambda}= \\boldsymbol{\\Sigma}(\\boldsymbol{X},\\boldsymbol{Y})  vc^{-1}(\\boldsymbol{Y})\n\\end{equation}\nwhere:\n\\begin{itemize}\n  \\item $vc^{-1}(\\boldsymbol{Y})$ is the inverse of the covariance of the\n  input space.\n\\end{itemize}\n\n", "meta": {"hexsha": "c638531c678320fd8917f525746cc4268da5def1", "size": 14251, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/theory_manual/statisticalAnalysis.tex", "max_stars_repo_name": "milljm/raven", "max_stars_repo_head_hexsha": "5f29fe81b75e2ffbeb54a55aa63647e7b2f6457b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/theory_manual/statisticalAnalysis.tex", "max_issues_repo_name": "milljm/raven", "max_issues_repo_head_hexsha": "5f29fe81b75e2ffbeb54a55aa63647e7b2f6457b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/theory_manual/statisticalAnalysis.tex", "max_forks_repo_name": "milljm/raven", "max_forks_repo_head_hexsha": "5f29fe81b75e2ffbeb54a55aa63647e7b2f6457b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.8781512605, "max_line_length": 489, "alphanum_fraction": 0.6669707389, "num_tokens": 5123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.7025924274824351}}
{"text": "%!TEX root = Calculus_I.tex\n\\chapter{Key Concept: The Definite Integral}\n\n\\section{How Do We Measure Distance Traveled?}\nThe \\textbf{\\textit{distance}} formula is commonly referred to as:\n%\n\\begin{equation}\n\\text{Distance} = \\text{Velocity} \\cdot \\text{Time}\n\\end{equation}\n%\nRecall that \\textbf{\\textit{velocity}} has both magnitude \\textit{and} direction. Thus, it is important to know what direction indicates positive \\textbf{\\textit{velocity}}. This section will estimate \\textbf{\\textit{distance}} when \\textbf{\\textit{velocity}} is time-varying.\n\n\\vspace{0.1in}\nWhen estimating the \\textbf{\\textit{distance}} traveled, it is important to know how often the \\textbf{\\textit{velocity}} measurements are taken. For example, consider this table with measurements taken every 2 seconds:\n%\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{ccccccc}\n\\hline\nTime (sec) & 0 & 2 & 4 & 6 & 8 & 10\\\\\n\\hline\nVelocity $\\left(\\frac{\\text{ft}}{\\text{s}}\\right)$ & 20 & 30 & 38 & 44 & 38 & 50\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\end{table}\n%\nHigher frequency \\textbf{\\textit{velocity}} measurements result in less \\textbf{\\textit{distance}} estimation error, but an estimate can still be made. This results in:\n%\n\\begin{equation}\n20\\cdot2 + 30\\cdot2 + 38\\cdot2 + 44\\cdot2 + 48\\cdot2 = 360 \\text{feet}\n\\end{equation}\n%\nThis serves as a lower limit because we know the car has moved at these speeds when it was measured. An upper limit considers the fact that the car instantaneously accelerated to the maximum velocity from the next measurement, yielding:\n%\n\\begin{equation}\n30\\cdot2 + 38\\cdot2 + 44\\cdot2 + 48\\cdot2 + 50\\cdot2 = 420 \\text{feet}\n\\end{equation}\n%\nThus, we can conclude that:\n%\n\\begin{equation}\n360 \\leq \\text{Total Distance Traveled} \\leq 420 \\text{feet}\n\\end{equation}\n%\nA smaller difference between the upper and lower estimates can be obtained by increasing the measurement frequency. Each time interval between measurements can be represented by a rectangle on the \\textit{Time-Velocity}-axes. As the time intervals get smaller, the rectangles become thinner. The \\textbf{\\textit{limit}} of this is as the time interval approaches zero, the rectangles are infinitesimally thin, and the distance error between the lower and upper estimates approaches zero. It will be shown later that, in the \\textbf{\\textit{distance}} and \\textbf{\\textit{velocity}} relationship, the \\textbf{\\textbf{area under the curve}} of the \\textit{Time-Velocity}-axes is equivalent to the \\textbf{\\textit{total distance}} traveled, if \\textbf{\\textit{velocity}} is strictly positive.\n\n\\vspace{0.1in}\nIf \\textbf{\\textit{velocity}} is ever negative, then the object is traveling back towards the starting position. Thus, its \\textbf{\\textit{distance}} from the starting position is decreasing, but the \\textbf{\\textit{total distance}} traveled is increasing.\n\n\\vspace{0.1in}\nIn the general case, let $v = f(t)$ be a non-negative \\textbf{\\textit{velocity}} function, $t \\geq 0$. One may wish to determine the \\textbf{\\textit{distance}} traveled between times $a$ and $b$. Measurements are taken at evenly spaced times, $t_0$, $t_1$, ... $t_n$. If $a = t_0$ and $b = t_n$, then the time interval between any two measurements is given by:\n%\n\\begin{equation}\n\\Delta t = \\frac{b - a}{n}\n\\end{equation}\n%\nFor each time interval, $t_i$, the \\textbf{\\textit{distance}} traveled is given by:\n%\n\\begin{equation}\n\\text{Distance} = f\\left(t_i\\right)\\Delta t\n\\end{equation}\n%\nSumming all of the distances between each subsequent time interval between $a$ and $b$ yields:\n%\n\\begin{equation}\n\\label{eq:LHSum}\n\\text{Distance} \\approx \\sum_{i=0}^{n-1} f\\left(t_i\\right)\\Delta t\n\\end{equation}\n%\nThis is a \\textbf{\\textit{Left-Hand Sum}} because it includes all velocities from the left-side of the rectangular intervals. The \\textbf{\\textit{Right-Hand Sum}} can be written as:\n%\n\\begin{equation}\n\\label{eq:RHSum}\n\\textbf{Distance} \\approx \\sum_{i=1}^n f\\left(t_i\\right)\\Delta t\n\\end{equation}\n%\nIf $f$ is an \\textbf{\\textit{increasing function}}, then the \\textbf{\\textit{Left-Hand Sum}} underestimates the \\textbf{\\textit{total distance}} and \\textbf{\\textit{Right-Hand Sum}} overestimates it. Conversely, if $f$ is \\textbf{\\textit{decreasing}}, then the \\textbf{\\textit{Left-Hand Sum}} overestimates the \\textbf{\\textit{total distance}} and \\textbf{\\textit{Right-Hand Sum}} underestimates it. For a \\textbf{\\textit{monotonically increasing}} or \\textbf{\\textit{monotonically decreasing}} function, the accuracy of the estimates is given by:\n%\n\\begin{equation}\n\\text{Error} = |f(b) - f(a)| \\cdot \\Delta t\n\\end{equation}\n%\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{The Definite Integral}\nThe \\textbf{\\textit{Definite Integral}} is defined by taking the \\textbf{\\textit{limit}} of the \\textbf{\\textit{Left-Hand Sum}} or \\textbf{\\textit{Right-Hand Sum}} as the parameter $n$ approaches $+\\infty$, provided the function $f(x)$ is \\textbf{\\textit{continuous}} on $[a, b]$. This can be written as:\n%\n\\begin{equation}\n\\int_a^b f(x)dx\n\\end{equation}\n%\nThe summations represented by Equations (\\ref{eq:LHSum}) and (\\ref{eq:RHSum}) are referred to as \\textbf{\\textit{Riemann Sums}}. The \\textbf{\\textit{integrand}} is the function being integrated, $f(x)$, and the \\textbf{\\textit{limits of integration}} are the endpoints of the interval, $a$ and $b$.\n\n\\vspace{0.1in}\nMore specifically, Equations (\\ref{eq:LHSum}) and (\\ref{eq:RHSum}) are special cases of \\textbf{\\textit{Riemann Sums}}. The general form of the \\textbf{\\textit{Riemann Sum}} for a function, $f(x), x \\in [a, b]$, is given by:\n%\n\\begin{equation}\n\\sum_{i=1}^n f\\left(c_i\\right) \\Delta t_i\n\\end{equation}\n%\nwhere $a = t_0 < t_1 <$ ... $t_n = b$ and, for $i = 1, 2$ ..., $n$, $\\Delta t_i = t_i - t_{i-1}$, and $t_{i-1} \\leq c_i \\leq t_i$.\n\\vspace{0.1in}\nThe \\textbf{\\textit{Definite Integral}} approximates the area under the curve down to the $x$-axis by summing the areas of $n$ rectangles in the \\textbf{\\textit{Riemann Sum}}. When the \\textbf{\\textit{integrand}} is negative, the distance to the $x$-axis is above the curve. Because as positive sign convention is used, the resulting area above the curve found through  \\textbf{\\textit{integration}} is negative. This is what causes \\textbf{\\textit{integrations}} such as $\\int_0^{2\\pi} \\sin x$ $dx$ to equal zero.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{The Fundamental Theorem and Interpretations}\nThe \\textbf{\\textit{Fundamental Theorem of Calculus}} is written as:\n\n\\vspace{0.2in}\nIf $f$ is \\textbf{\\textit{continuous}} on $[a, b]$, and $f(x) = F\\prime(x)$, then:\n%\n\\begin{equation}\n\\int_a^b f(x)dx = F(b) - F(a)\n\\end{equation}\n%\nThus, if a function $f$ is equal to the \\textbf{\\textit{rate of change}} of a quantity, then the \\textbf{\\textit{definite integral}} results in the total change.\n\n\\vspace{0.1in}\nThe \\textbf{\\textit{integral}} can also be used to approximate the average value of a function, $f$, over a given interval, $[a, b]$:\n%\n\\begin{equation}\n\\text{Average Value of } f = \\frac{1}{b-a}\\int_a^bf(x)dx\n\\end{equation}\n%\n\\vspace{0.1in}\nLastly, the \\textbf{\\textit{Fundamental Theorem of Calculus}} can be used to compute \\textbf{\\textit{definite integrals}} exactly.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Theorems About Definite Integrals}\nSo far, we have only considered the \\textbf{\\textit{Definite Integral}} when $a < b$. Recall that:\n%\n\\begin{equation}\n\\int_a^b f(x)dx = \\lim_{n \\rightarrow \\infty} \\sum_{i=1}^n f\\left(x_i\\right) \\Delta x\n\\end{equation}\n%\nThen, provided $f(x)$ is \\textbf{\\textit{continuous}}, for any numbers, $a$, $b$, and $c$:\n%\n\\begin{enumerate}\n\\item $\\int_b^a f(x)$ $dx = - \\int_a^b f(x)$ $dx$\\\\\n\\item $\\int_a^c f(x)$ $dx + \\int_c^b f(x)$ $dx = \\int_a^b f(x)$ $dx$\n\\end{enumerate}\n%\nThe first result can be derived from the definition of $\\Delta x$, namely:\n%\n\\begin{equation}\n\\Delta x = \\frac{(a - b)}{n} = -\\frac{(b - a)}{n}\n\\end{equation}\n%\nThe second result is true because of the definition of $\\Delta x$ and that the upper limit of integration of the first is equal to the lower limit of integration for the second, $c$.\n\n\\vspace{0.1in}\nWe can also evaluate properties of \\textbf{\\textit{integrals}} for multiple functions. Suppose $f$ and $g$ are both continuous functions, and $c$ is an arbitrary constant. Then:\n%\n\\begin{enumerate}\n\\item $\\int_a^b \\left(f(x) \\pm g(x)\\right)$ $dx = \\int_a^b f(x)$ $dx \\pm \\int_a^b g(x)$ $dx$\\\\\n\\item $\\int_a^b c \\cdot f(x)$ $dx = c\\int_a^b f(x)$ $dx$\n\\end{enumerate}\n%\nThese properties hold because of the \\textbf{\\textit{Principle of Superposition}} and that $c$ is simply a scaling factor.\n\n\\vspace{0.1in}\nThe area between curves can also be calculated, provided $f(x)$ lies above $g(x)$ for $a \\leq x \\leq b$:\n%\n\\begin{equation}\n\\text{Area between $f$ and $g$} = \\int_a^b\\left(f(x) - g(x)\\right)dx\n\\end{equation}\n%\n\\vspace{0.1in}\nSymmetry can also be used to aid in the evaluation of \\textbf{\\textit{integrals}}. For \\textbf{\\textit{Even Functions}}:\n%\n\\begin{equation}\n\\int_{-a}^a f(x)dx = 2\\int_0^a f(x)dx\n\\end{equation}\n%\nand for \\textbf{\\textit{Odd Functions}}:\n%\n\\begin{equation}\n\\int_{-a}^a f(x)dx = 0\n\\end{equation}\n%\nThis is because of the definition of \\textbf{\\textit{Even}} and \\textbf{\\textit{Odd Functions}}.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}", "meta": {"hexsha": "1a58fa2de3c85b949dff7b69863bd4e247b2007c", "size": 9423, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus I/Notes/chapter5.tex", "max_stars_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_stars_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-06T01:05:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-06T01:05:34.000Z", "max_issues_repo_path": "Calculus I/Notes/chapter5.tex", "max_issues_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_issues_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Calculus I/Notes/chapter5.tex", "max_forks_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_forks_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.351758794, "max_line_length": 789, "alphanum_fraction": 0.7178181046, "num_tokens": 3034, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8976952927915968, "lm_q1q2_score": 0.7025924232006542}}
{"text": "\\section{Introduction to Ordinary Differential Equations}\n\nDifferential equations come from real-world problems and problems in applied mathematics. When mathematics is applied to real-world problems, it is often the case that finding a relation between a function and its rate of change is easier than finding a formula for the function itself; it is this relation between an unknown function and its derivatives that produces a differential equation.\\newline\nTo give a very simple example, a biologist studying the growth of a population with size at time $t$ given by the function $P(t)$, might make the very simple, but logical, assumption that a population grows at a rate directly proportional to its size. In mathematical notation, the equation for $P(t)$ could then be written as:\n\n\\[\n  \\frac{dp}{dt} = rP(t)\n\\]\n\nWhere the constant of proportionality, $r$ would probably be determined experimentally by biologists working in the field. Equations used for modeling population growth can be much more complicated than this, sometimes involving scores of interacting populations with different properties.\n\n\\subsection{Basic Terminology}\n\n  \\begin{definition}\n    A differential equation is any equation involving an unknown function and one or more if its derivatives.\n  \\end{definition}\n\n  The following are examples of differential equations:\n\n    \\begin{enumerate}\n      \\item $P'(t)=rP(t)(1-P(t)/N)-H$ harvested population growth\n      \\item $\\frac{d^2x}{d\\tau^2}+0.9\\frac{dx}{d\\tau}+2x=0$ spring mass equation\n      \\item $I''(t)+4I(t)=sin(\\omega t) $ RCL circuit showing beats\n      \\item $y''(t) + \\mu(y^2(t)-1)y'(t)+y(t)$ ban der Pol equation\n      \\item $\\frac{\\partial^2}{\\partial x^2}u(x,y)+\\frac{\\partial^2}{\\partial y^2}u(x,y) = 0$ Laplace's equation\n    \\end{enumerate}\n\n  \\subsubsection{Ordinary vs. Partial Differential Equations}\n\n    Differential equations fall into two very broad categories, called ordinary differential equations and partial differential equations. If the unknown function in the equation is a function of only one variable, the equation is called an ordinary differential equation. If the unknown function in the equation depends on more than one independent variable, the equation is called a partial differential equation, and in this case, the derivatives appearing in the equation will be partial derivatives.\n\n  \\subsubsection{Independent Variables, Dependent Variables, and Parameters}\n\n   Three different types of quantities can appear in a differential equation. The unknown function, for which the equation is to be solved, is called the dependent variable, and when considering ordinary differential equations, the dependent variable is a function of a single independent variable. In addition to the independent and dependent variables, a third type of variable, called a parameter, may appear in the equation. A parameter is a quantity that remains fixed in any specification of the problem, but can very from problem to problem.\n  \n  \\subsubsection{Order of a Differential Equation}\n\n    Another important way in which differential equations are classified is in terms of their order.\n\n    \\begin{definition}\n      The order of a differential equation is the order of the highest derivative of the unknown function that appears in the equation.\n    \\end{definition}\n\n    The differential equation 1 is a first-order equation and the others are all second-order. Even though equation 5 is a partial differential equation, it is still said to be of second order since no derivatives of order higher than two appear in the equation.\n\n  \\subsubsection{What is a solution}\n\n    Given a differential equation, what is a solution? We must realize that we are looking for a function, and therefore it needs to be defined on some interval of its independent variable.\n\n    \\begin{definition}\n      An analytic solution of a differential equation is a sufficiently differentiable function that, if substituted into the equation, together with the necessary derivatives, makes the equation an identity (a true statement for all values of the independent variable) over some interval of the independent variables.\n    \\end{definition}\n\n    \\begin{problem}\n      Show that the function $p(t)=e^{-2t}$ is a solution to the differential equation:\n\n      \\[\n        x'' + 3x' + 3x = 0\n      \\]\n  \n      Solution. To show that it is a solution, compute the first and second derivatives of $p(t)$:\n  \n      \\begin{align*}\n        p'(t) &=- 2e^{ - 2t}\\\\\n        p''(t) &= 4e^{ - 2t}\n      \\end{align*}\n  \n      When the three functions $p(t)$, $p'(t)$, and $p''(t)$ are substituted into the differential equation in place of $x$, $x'$, and $x''$, it becomes:\n  \n      \\begin{align*}\n        (4e^{ - 2t}) + 3( - 2e^{ - 2t}) + 2(e^{ - 2t})&\\equiv 0\\\\\n        (4 - 6 + 2)(e^{ - 2t})&\\equiv0\\\\\n        (0)(e^{ - 2t})&\\equiv0\n      \\end{align*}\n  \n      which is an identity (in the independent variable $t$ for all real values of $t$).\n      When showing that both sides of an equation are identical for all values of the variables, we will use the equivalence sign $\\equiv$.\n    \\end{problem}\n\n    \\begin{problem}\n      Show that the function $\\phi(t)=(1-t^2)^{1/2}\\equiv\\sqrt{1-t^2}$ is a solution of the differential equation $x'=-t/x$.\n\n      Solution. First, notice that $\\phi(t)$ is not even defined outside the interval $-1\\le t\\le 1$. In the interval $-1<t<1$, $\\phi(t)$ can be differentiated by the chain rule (for powers of functions):\n\n      \\[\n        \\phi'(t) =\\frac{1}{2}(1 - t^2)^{ - \\frac{1}{2}}( - 2t) =- \\frac{t}{(1 - t^2)^{\\frac{1}{2}}}\n      \\]\n\n      The right-hand side of the equation $x'=-t/x$, with $phi(x)$ substituted for $x$, is \n\n      \\[\n        - \\frac{t}{\\phi (t)} =- \\frac{t}{(1 - t^2)^{\\frac{1}{2}}}\n      \\]\n\n      which is identically equal to $\\phi(t)$ wherever $\\phi$ and $\\phi'$ are both defined. Therefore, $\\phi(t)$ is a solution to the differential equation $x'=-t/x$ on the interval (-1, 1).\n    \\end{problem}\n\n\\subsection{Systems of Differential Equations}\n\n  \\begin{problem}\n    Show that the functions $x(t)=e^{-t},y(t)=-4e^{-t}$ form a solution of the system of differential equations\n\n    \\[\n      x'(t) = 3x + y\\newline\n      y'(t) =- 4x - 2y\n    \\]\n\n    Solution. The derivatives that we need are $x'(t)=-e^-t$ and $y'(t)=-(-4e^{-t})=4e^{-t}$. Then substitution into the second equation gives:\n\n    \\begin{align*}\n      3x+y=(2e^{-t})+(-4e^{-t})=(3-4)e^{-t}=-e^{-t}\\equiv x'(t),\\\\\n      -4x-2y=-4(e^{-t})-2(-4e^{-t})=(-4+8)e^{-t}=4e^{-t}\\equiv y'(t);\n    \\end{align*}\n\n    therefore, the given functions of x and y form a solution for the system.\n  \\end{problem}\n\n\\subsection{Families of Solutions, Initial-Value Problems}\n  In this section the solutions of some very simple differential equations will be examined in order to give us an understanding of the terms $n$-parameter family of solutions and general solution of a differential equation. We will also be shown how to use certain types of information to pick one particular solution out of a set of solutions.\n\n  While we do not yet have any formal methods for solving differential equations, there are some very simple equations that can be solved by inspection. One of these is:\n\n  \\[\n    x' = x\n  \\]\n\n  This first-order differential equation asks you to find a function $x(t)$ which is equal to its own derivative at every value of $t$.\n\n  \\begin{definition}\n    A first-order differential equation with one initial condition specified is called an initial-value problem, usually abbreviated as an IVP. The solution of an IVP will be called a particular solution of the differential equation.\n  \\end{definition}\n\n  \\begin{problem}\n    Solve the IVP $x'=x, x(0)=\\frac{1}{2}$.\n\n    Solution. Since we just found that the general solution of $x'=x$ is $x(t)=Ce^t$, we only need to use the initial condition to determine the value of C. This will pick out one particular curve in the family. Substituting $t=0$ and $x(0)=\\frac{1}{2}$ into the general solution,\n\n    \\[\n      x(0)=Ce^0=C=\\frac{1}{2}.\n    \\]\n\n    With $C=\\frac{1}{2}$, the solution of the IVP is $x(t)=\\frac{1}{2}e^t$. This particular solution is the dotted curve shown in Figure 1.1, with the initial point $(0,\\frac{1}{2})$ circled.\n  \\end{problem}\n", "meta": {"hexsha": "3d6176236b4dda6a103645eabd26e3faa0cacc79", "size": 8259, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math260/chapters/1.tex", "max_stars_repo_name": "CameronSWilliamson/GU-MATH", "max_stars_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-18T00:49:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T00:49:14.000Z", "max_issues_repo_path": "math260/chapters/1.tex", "max_issues_repo_name": "therealkeyisme/Math-Notes", "max_issues_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math260/chapters/1.tex", "max_forks_repo_name": "therealkeyisme/Math-Notes", "max_forks_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.3541666667, "max_line_length": 548, "alphanum_fraction": 0.7019009565, "num_tokens": 2147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952838963489, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7025924207894829}}
{"text": "\\chapter{Binomial Coefficients}\n\\label{chapter:binomials}\n\\marginurl{%\n  Permutations and Binomial Coefficients:\\\\\\noindent\n  Introduction to Combinatorics \\#4\n}{youtu.be/HLClazoqqzg}\nThis chapter studies the following question:\n``how many ways to take $k$ objects out of a box with $n$ objects''.\nWe assume that the objects are taken one by one; note that there are four modes\nfor this question.\n\\begin{enumerate}\n  \\item we return objects to the box after we take them and the order in which\n    we take them matters,\n  \\item we are \\emph{do not} return the objects and the order in which\n    we take them matters,\n  \\item we return objects to the box after we take them and the order in which\n    we take them \\emph{does not} matter,\n  \\item we are \\emph{do not} return the objects and the order in which\n    we take them \\emph{does not} matter.\n\\end{enumerate}\n\nThe Table~\\ref{table:selections} summarizes the results we are going\nto prove.\n\\begin{table}[h!]\n  \\centering\n  \\begin{tabular}{lll}\n    \\toprule\n    Object's name & Parameters & Formula \\\\\n    \\midrule\n    \\multirow{2}{*}{Functions} & we return objects and & \\multirow{2}{*}{$n^k$} \\\\\n                               & the order \\emph{is} important & \\\\\n    \\multirow{2}{*}{Injections} & we \\emph{do not} return objects and &\n      \\multirow{2}{*}{$\\numberOfPermutations[k]{n}$} \\\\\n                                & the order \\emph{is} important & \\\\\n    \\multirow{2}{*}{Subsets} & we \\emph{do not} return objects and & \\multirow{2}{*}{$\\binom{n}{k}$} \\\\\n                             & the order \\emph{is not} important & \\\\\n    \\multirow{2}{*}{Multisets} & we return objects and & \\multirow{2}{*}{$\\binom{n + k - 1}{k}$} \\\\\n                               & the order \\emph{is not} important & \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\caption{Formulas for the numbers of ways to take $k$ objects out of a box\n  with $n$ objects}\n  \\label{table:selections}\n\\end{table}\n\n\\section{Counting Functions}\nNote that if we number objects using numbers from $1$ to $n$, then in the first\nmode the answer is the same as the number of functions from $[n]$ to $[k]$ since\nwe need to just choose which objects is selected on the $i$th step for\n$i \\in \\range{k}$.\n\nLet us solve a more general question; assume we have two finite sets $X$ and\n$Y$: how many functions exist from $X$ to $Y$?\n\n\n\\begin{theorem}\n\\label{theorem:number-of-functions}\n  Let $X$ and $Y$ be some finite sets. $\\functions{X}{Y}$ represents the set of all\n  functions from $X$ to $Y$. Then $\\cardinality{\\functions{X}{Y}} =\n  \\cardinality{Y}^{\\cardinality{X}}$.\n\\end{theorem}\n\\nomenclature[S]{$\\functions{A}{B}$}{denotes the set of functions from $A$ to $B$}\n\\begin{proof}\n  For simplicity we prove the statement in the case when $X = \\range{n}$. Fix some\n  finite set $Y$. We prove the statement using induction by $n$. The base case\n  for $n = 1$ is obvious, since there are $\\cardinality{Y}$ different functions\n  from $\\range{1}$ to $Y$. Let us prove the induction step, by the induction\n  hypothesis, $\\cardinality{\\functions{\\range{n - 1}}{Y}} = \n  \\cardinality{Y}^{n - 1}$. Note that\n  \\begin{multline*}\n    \\cardinality{\\functions{\\range{n}}{Y}} = \n      \\cardinality{\\set[f \\in Y^{[ n - 1]}, y \\in Y]{(f, y)}} = \\\\\n    \\cardinality{\\functions{\\range{n - 1}}{Y} \\times Y} = \n      \\cardinality{\\functions{\\range{n - 1}}{Y}} \\cdot \\cardinality{Y} =\n      \\cardinality{Y}^n.\n  \\end{multline*}\n\\end{proof}\n\n\\begin{corollary}\n  There are $n^k$ ways to select $k$ objects out of $n$ if the order matters\n  and we return objects to the box after we pick them.\n\\end{corollary}\n\n\\begin{exercise}\n  Finish the proof of Theorem~\\ref{theorem:number-of-functions} by proving that\n  the statement holds for any set $X$.\n\\end{exercise}\n\nHowever, what if we need to find size of a subset of $Y^X$ satisfying some\nconstraint? For example, we may try to find the size of the set\n\\[\n  \\injections{X}{Y} = \\set[f\\text{ is an injection}]{f \\in \\functions{X}{Y}}.\n\\]\n\\nomenclature[S]{$\\injections{A}{B}$}{denotes the set of injections from $A$ to $B$}\nFirst, let us try to do this informally. Assume that $X = \\range{n}$ and\n$\\cardinality{Y} = m$,\nto define $f \\in \\injections{X}{Y}$ we need to choose images of $1$, $2$, \\dots,\n$n$. There are $m$ possible ways to select an image of $1$, $m - 1$ ways to\ndefine $f(2)$ since we cannot use the value selected for $1$ etc. Hence,\n$\\cardinality{\\injections{X}{Y}} = m (m - 1) \\dots (m - n + 1)$ (we denote this\nnumber as $\\numberOfPermutations[n]{m}$\\footnote{%\n  In combinatorics the notation $\\numberOfPermutations[n]{m}$ is widely used and\n  is also called the Pochhammer symbol. However, Knuth's $m^{\\underline{n}}$\n  notation is increasingly popular. It is also important to note that sometimes \n  $\\numberOfPermutations[n]{m}$ denotes $m (m + 1) \\dots (m + n - 1)$. Moreover,\n  Leo August Pochhammer, the author of the Pochhammer symbol, used the\n  Pochhammer symbol to denote the binomial coefficients.\n}).\n\\nomenclature[C]{$\\numberOfPermutations[n]{m}$}{denotes the number of ways to choose a\nsubset of $n$ elements from a fixed set of $m$ elements}\n\n\\begin{theorem}\n\\label{theorem:number-of-injections}\n  Let $X$ and $Y$ be some finite sets. Then $\\cardinality{\\injections{X}{Y}} =\n  \\numberOfPermutations[\\cardinality{X}]{\\cardinality{Y}}$.\n\\end{theorem}\n\\begin{proof}\n  Let us prove this statement for $X = \\range{n}$. We prove this using induction by\n  $n$. The base case, for $n = 1$, is clear. Now we need to prove the induction\n  step from $n$ to $n + 1$. By the induction hypothesis, for any $m$, the\n  number of injections from $\\range{n}$ to $Y$ is equal to\n  $\\numberOfPermutations[n]{\\cardinality{Y}}$.\n\n  Fix some $m$ and some set $Y$ of cardinality $m$. Note that\n  \\[\n    \\cardinality{\\injections{X}{Y}} =\n    \\cardinality{\n      \\set[v \\not\\in \\Im f]{(f, v) \\in \\injections{\\range{n - 1}}{Y} \\times \\range{m}}\n    }.\n  \\]\n  It is easy to see that $\\cardinality{\\set[v \\not\\in \\Im f]{(f, v)}} = m - n + 1$\n  for any $f \\in \\injections{\\range{n - 1}}{Y}$ and\n  \\[\n    \\set[v \\not\\in \\Im f]{(f, v) \\in \\injections{\\range{n - 1}}{Y} \\times\n      \\range{m}} =\n    \\bigcup_{f \\in \\injections{\\range{n - 1}}{Y}} \\set[v \\not\\in \\Im f]{(f, v)}.\n  \\]\n  As a result, $\\cardinality{\\injections{X}{Y}} = \n    \\numberOfPermutations[n - 1]{m} \\cdot (m - n + 1) =\n    \\numberOfPermutations[n]{m}$.\n\\end{proof}\n\nThe special case of this result is that there are\n$n \\cdot (n - 1) \\cdot  \\dots \\cdot  1$ different\npermutations of $\\range{n}$ (recall that the number is denoted by\n$\\numberOfPermutations{n}$).\n\n\\begin{exercise}\n  Finish the proof of Theorem~\\ref{theorem:number-of-injections} by proving that\n  the statement holds for any finite set $X$.\n\\end{exercise}\n\n\\begin{corollary}\n  There are $\\numberOfPermutations[k]{n}$ ways to select $k$ objects out of $n$ if the order matters\n  and we do not return objects to the box after we pick them.\n\\end{corollary}\n\n\\section{Counting Subsets}\nIn this section we study the version of the question when we do not return the\nobjects back to the box; i.e., we cannot select an object twice.\n\nRecall that we denoted the set of all subsets of $X$ by $2^X$. The reason for\nthis notation is that $\\cardinality{\\subsets{X}} = 2^{\\cardinality{X}}$. A quite\nfamous example of a subset of this set is the set\n\\[\n  \\subsets[n]{X} = \\set[\\cardinality{A} = n]{A \\subseteq X}.\n\\]\n\\nomenclature[S]{$\\subsets[k]{A}$}{denotes the set of subsets of $A$ of\ncardinality $k$}\nIn other words, it is the set of all possible ways to select $n$ elements from\n$X$. Size of the set $\\subsets[n]{\\range{m}}$ we denote by $\\binom{m}{n}$ and\ncall it a binomial coefficient.\n\\nomenclature[C]{$\\binom{m}{n}$}{denotes the number of ways to choose an\nunordered subset of $n$ elements from a fixed set of $m$ elements}\n\\begin{exercise}\n  Show that for any two finite sets $X$ and $Y$, if $\\cardinality{X} =\n  \\cardinality{Y}$, then\n  $\\cardinality{\\subsets[k]{X}} = \\cardinality{\\subsets[k]{Y}}$.\n\\end{exercise}\n\nNote that by any ordered selection of $n$ object out of $m$, one may construct\nan unordered selection of $n$ objects out of $m$, and each unordered selection\nis counted $n!$.\n\\begin{theorem}\n\\label{theorem:binomial-coefficients-explicit}\n  For any $n > k \\ge 0$,\n  $\\binom{n}{k} = \\frac{\\numberOfPermutations[k]{n}}{k!} = \\frac{n!}{k!  (n - k)!}$.\n\\end{theorem}\n\n\\begin{exercise}\n  Show that $\\binom{n}{k} = \\binom{n}{n - k}$ for any $n > k$.\n\\end{exercise}\n\nThe formula in the Theorem~\\ref{theorem:binomial-coefficients-explicit} allows\nto find the values of binomial coefficients, however, it is not very convenient\nsince $n!$ is growing very fast. Thus the following theorem provides a much more\nefficient way to compute the values of binomial coefficients.\n\n\\begin{theorem}[Pascal's rule]\n\\label{theorem:pascals-rule}\n  For $n > k \\ge 1$, $\\binom{n}{k} = \\binom{n - 1}{k - 1} + \\binom{n - 1}{k}$.\n\\end{theorem}\n\\begin{proof}\n  The first, algebraic, proof of this theorem is quite simple, we just notice\n  that\n  \\begin{multline*}\n    \\binom{n - 1}{k - 1} + \\binom{n - 1}{k} =\n      \\frac{(n - 1)!}{(k - 1)!(n - k)!} + \\frac{(n - 1)!}{k!(n - k - 1)!} = \\\\\n      \\frac{(n - 1)!}{(k - 1)! (n - k - 1)!}\n        \\left(\n          \\frac{1}{n - k} + \\frac{1}{k}\n        \\right) = \\frac{n!}{k! (n - k)!} = \\binom{n}{k}.\n  \\end{multline*}\n\n  However, this proof does not explain \\emph{why} the statement is true.\n  So we consider an alternative proof, which informally can be explained as\n  follows. Assume we need to choose $k$ objects out of $n$. There are two\n  possible ways:\n  \\begin{itemize}\n    \\item we may select $n$ and choose $k - 1$ objects from the rest,\n    \\item or we may decide to not select $n$ choose $k$ objects from the rest.\n  \\end{itemize}\n  In the first case we have $\\binom{n - 1}{k - 1}$ ways to select objects and\n  in the second case we have $\\binom{n - 1}{k}$ ways to select objects.\n\n  Let us prove the statement a bit more formally. Note that\n  \\begin{multline*}\n    \\subsets[k]{\\range{n}} = \n      \\set[\\cardinality{A} = k \\text{ and } n \\in A]{A \\subseteq \\range{n}} \\cup \\\\\n    \\set[\\cardinality{A} = k \\text{ and } n \\notin A]{A \\subseteq \\range{n}}.\n  \\end{multline*}\n  Since these sets are disjoint and \n  $\\set[\\cardinality{A} = k \\text{ and } n \\notin A]{A \\subseteq \\range{n}} = \n  \\subsets[k]{\\range{n - 1]}}$, we get the following equality\n  \\[\n    \\binom{n}{k} = \n    \\cardinality{\\set[\\cardinality{A} = k \\text{ and } n \\in A]{A \\subseteq \\range{n}}} +\n    \\binom{n - 1}{k}.\n  \\]\n\n  Hence, to finish the proof we need to explain that\n  \\[\n    \\cardinality{\\set[\\cardinality{A} = k \\text{ and } n \\in A]{A \\subseteq \\range{n}}} =\n    \\binom{n - 1}{k - 1}.\n  \\]\n  To prove this statement we construct a bijection\n  \\[\n    f : \\set[\\cardinality{A} = k \\text{ and } n \\in A]{A \\subseteq \\range{n}} \\to\n      \\subsets[k]{\\range{n - 1}}\n  \\]\n  such that $f(A) = A \\setminus \\set{n}$.\n  It is clear that this is a bijection. Thus, we prove the statement.\n\\end{proof}\n\nA mnemonic rule for the Pascal's rule is to use Pascal's triangle.\n\\footnote[][-8cm]{\n  The pattern of numbers that forms Pascal's triangle was known well before\n  Pascal's time.  Halayudha, around 975 explained obscure references to\n  Meru-prastaara, the Staircase of Mount Meru, giving the first surviving\n  description of the arrangement of these numbers into a triangle.\n\n  The Persian mathematician Al-Karaji (953–1029) wrote a now lost book which\n  contained the first description of Pascal's triangle. It was later repeated by\n  the Persian poet-astronomer-mathematician Omar Khayyám (1048–1131); thus the\n  triangle is also referred to as the Khayyam triangle in Iran.\n\n  Pascal's triangle was known in China in the early 11th century through the\n  work of the Chinese mathematician Jia Xian (1010–1070). In the 13th century,\n  Yang Hui (1238–1298) presented the triangle and hence it is still called Yang\n  Hui's triangle in China.\n\n  Pascal's Traité du triangle arithmétique (Treatise on Arithmetical Triangle)\n  was published in 1655. In this, Pascal collected several results then known\n  about the triangle, and employed them to solve problems in probability theory.\n  The triangle was later named after Pascal by Pierre Raymond de Montmort (1708)\n  who called it ``Table de M. Pascal pour les combinaisons'' (French: Table of\n  Mr. Pascal for combinations) and Abraham de Moivre (1730) who called it\n  ``Triangulum Arithmeticum PASCALIANUM'' (Latin: Pascal's Arithmetic Triangle),\n  which became the modern Western name.\n}\n\\begin{figure}\n  \\centering\n  \\begin{tabular}{lccccccccc}\n    &    &    &    &  1\\\\\\noalign{\\smallskip\\smallskip}\n    &    &    &  1 &    &  1\\\\\\noalign{\\smallskip\\smallskip}\n    &    &  1 &    &  2 &    &  1\\\\\\noalign{\\smallskip\\smallskip}\n    &  1 &    &  3 &    &  3 &    &  1\\\\\\noalign{\\smallskip\\smallskip}\n    1 &    &  4 &    &  6 &    &  4 &    &  1\\\\\\noalign{\\smallskip\\smallskip}\n  \\end{tabular}\n\\end{figure}\nIn this diagram the $k$th entry of the $n$th row\n(entries and rows have numbers starting from $0$) is equal to $\\binom{n}{k}$.\nThus the rule for the triangle is very simple, the value of an entry is equal\nto $1$ if it is the first or the last in the row or it is equal to the sum\nof the two entries to the left and right on the row above.\n\n\\begin{exercise}\n  Show that $\\binom{n}{k} = \\binom{n}{n - k}$ for any integers $n > k \\ge 0$\n\\end{exercise}\n\n\n\\subsection{Binomial Theorem}\nNow we are ready to prove the theorem which gave the name to binomial\ncoefficients.\n\\begin{theorem}[Binomial theorem]\n\\label{theorem:binomial}\n  For any real numbers $x$ and $y$,\n    \\[\n      \\sum_{k = 0}^n \\binom{n}{k} x^k y^{n - k} = (x + y)^n.\n    \\]\n\\end{theorem}\n\\begin{proof}\n  Informally, the explanation of the equality is as follows.\n  If we consider the product\n  \\[\n    \\underbrace{(x + y) \\cdot (x + y) \\cdot\n      \\ldots \\cdot (x + y)}_{n \\text{ times}},\n  \\]\n  then for every $k$ there are exactly $\\binom{n}{k}$ possibilities to obtain\n  $x^k y^{n - k}$. Indeed, to obtain $x^k y^{n - k}$ we need to choose $x$ from\n  $n$ possibilities (corresponding to the multiplier $x + y$) exactly $k$ times.\n\n  A formal proof uses the induction by $n$. The base case is\n  true, since $\\sum_{k = 0}^1 \\binom{1}{k} x^k y^{1 - k} = x + y =\n  (x + y)^1$. Assume that\n  \\[\n    \\sum_{k = 0}^n \\binom{n}{k} x^k y^{n - k} = (x + y)^n,\n  \\]\n  we wish to prove that\n  \\[\n    \\sum_{k = 0}^{n + 1} \\binom{n + 1}{k} x^k y^{n + 1 - k} =\n      (x + y)^{n + 1}.\n  \\]\n  Note that\n  \\begin{multline*}\n    (x + y)^{n + 1} = (x + y)\n      \\left(\n        \\sum_{k = 0}^n \\binom{n}{k} x^k y^{n - k}\n      \\right) = \\\\\n    \\sum_{k = 0}^n \\binom{n}{k} x^{k + 1} y^{n - k} +\n      \\sum_{k = 0}^n \\binom{n}{k} x^{k} y^{n + 1 - k} = \\\\\n    \\sum_{k = 1}^{n + 1} \\binom{n}{k - 1} x^k y^{n + 1 - k} +\n      \\sum_{k = 0}^n \\binom{n}{k} x^k y^{n + 1 - k} = \\\\\n    \\sum_{k = 0}^{n + 1}\n      \\left(\n        \\binom{n}{k - 1} + \\binom{n}{k}\n      \\right)\n      x^k y^{n + 1 - k} =\n    \\sum_{k = 0}^{n + 1} \\binom{n + 1}{k} x^k y^{n + 1 - k}.\n  \\end{multline*}\n\\end{proof}\n\nFinally, we need to answer the question in the mode, when the order does not\nmatter and we do not return the objects to the box. The answer to this question\nis clearly equal to the number of multisets of $\\range{n}$ containing $k$\nobjects.\n\\begin{theorem}\n\\label{theorem:multisets}\n  The number of $k$-element multisets whose elements all belong to $\\range{n}$ is\n  $\\binom{n + k - 1}{k}$.\n\\end{theorem}\n\n\\begin{exercise}\n  Prove Theorem~\\ref{theorem:multisets}\n\\end{exercise}\n\nUsing \\Cref{theorem:binomial} one may prove several important equalities of sums\nof binomial coefficients.\n\\begin{corollary}\n\\label{corollary:binommials-equality}\n  Let $n \\in \\N$. Then\n  \\begin{enumerate}\n    \\item $\\sum_{k = 0}^n (-1)^k \\binom{n}{k} = 0$ and\n    \\item $\\sum_{k = 0}^n k \\binom{n}{k} = n 2^{n - 1}$.\n  \\end{enumerate}\n\\end{corollary}\n\\begin{proof}\n  \\begin{enumerate}\n    \\item Let $x = -1$. We may notice that, by \\Cref{theorem:binomial}, \n      \\[\n        \\sum_{k = 0}^n (-1)^k \\binom{n}{k} = \n        \\sum_{k = 0}^n 1^{n - k} x^k \\binom{n}{k} = (1 - 1)^n = 0.\n      \\]\n    \\item This equality is a bit more tricky. Let $x = 1$. Note that\n      \\[\n        \\sum_{k = 0}^n k \\binom{n}{k} = \n\t\\sum_{k = 0}^n k x^{k - 1} 1^{n - k} \\binom{n}{k} =\n        \\frac{d \\sum_{k = 0}^n x^k \\binom{n}{k}}{dx} = n (1 + x)^{n - 1}.\n      \\]\n      As a result, $\\sum_{k = 0}^n k \\binom{n}{k} = n 2^n$.\n  \\end{enumerate}\n\\end{proof}\n\n\nUsing the idea of the second equality, we can give an alternative --- more\nexplicit --- proof of \\Cref{claim:guess-one-out-of-many}.\n\\begin{proof}[Proof of \\Cref{claim:guess-one-out-of-many}]\n\\label{proof-claim:guess-one-out-of-many}\n  Let $x = 1 / 2$. Then the value we would like to compute is \n  $\\sum_{k = 1}^n k x^k$. Note that\n  \\begin{multline*}\n    \\sum_{k = 1}^n k x^k = x \\sum_{k = 1}^n k x^{k - 1} =\n    x \\frac{d \\sum_{k = 0}^n x^k}{dx} = \\\\\n    x \\frac{d}{dx} \\frac{1 - x^{n + 1}}{1 - x} = \n    x \\frac{-(n + 1) x^n (1 - x) + (1 - x^{n + 1})}{(1 - x)^2} =  \\\\\n    2\\left(\n      1 - \\frac{1}{2^{n + 1}} - (n + 1) \\frac{1}{2^{n + 1}}\n    \\right) = 2 - \\frac{n + 2}{2^n}.\n  \\end{multline*}\n\\end{proof}\n\n\\subsection{Counting Groups of Subsets}\nIn this section we study a generalization of the question we study in the\nprevious sections: ``How many ways to select $\\ell$ groups made of $k_1$, $k_2$,\n\\dots, $k_\\ell$ objects, respectively, out of $n$''. We denote this number by\n$\\binom{n}{k_1 \\ k_2 \\ \\dots \\ k_\\ell \\  (n - m)}$, where\n$m = k_1 + \\dots + k_\\ell$.\n\nClearly selecting these objects is the same as selecting $k_1$ objects out of\n$n$, after that selecting $k_2$ objects out of $n - k_1$ etc. As a result,\n\\begin{multline*}\n  \\binom{n}{k_1 \\ k_2 \\ \\dots \\ k_\\ell \\ (n - m)} = \\\\\n  \\frac{n!}{k_1! (n - k_1)!} \\cdot \\frac{(n - k_1)!}{k_2! (n - k_1 - k_2)!}\n  \\cdot \\ldots \\cdot\n  \\frac{\n    (n - k_1 - k_2 - \\dots - k_{\\ell - 1})!\n  }{\n    k_\\ell! (n - k_1 - k_2 - \\dots - k_\\ell)!\n  } = \\\\\n  \\frac{n!}{k_1! k_2! \\dots k_\\ell! (n - k_1 - k_2 - \\dots - k_\\ell)!}.\n\\end{multline*}\n\nSimilarly to the Binomial theorem, we can prove the following.\n\\begin{theorem}[Multinomial theorem]\n\\label{theorem:multinomial-coefficients}\n  For any real numbers $x_1$, $x_2$, \\dots, $x_\\ell$ and integer $n$,\n  \\[\n    (x_1 + x_2 + \\dots + x_\\ell)^n =\n    \\sum_{k_1, k_2, \\dots, k_\\ell ~:~ k_1 + k_2 + \\dots + k_\\ell = n}\n      \\binom{n}{k_1 \\ k_2 \\ \\dots \\ k_\\ell} \\prod_{i = 1}^n x_i^{k_i}.\n  \\]\n\\end{theorem}\n\n\\begin{exercise}\n  Prove Theorem~\\ref{theorem:multinomial-coefficients}.\n\\end{exercise}\n\n\\section{Double Counting}\n\\marginurl{%\n  Double Counting:\\\\\\noindent\n  Introduction to Combinatorics \\#4\n}{youtu.be/OrzMP8nuuho}\nThe method that was used to prove Theorem~\\ref{theorem:pascals-rule} can be\ngeneralized to a method that is called \\emph{double counting principle}.\nThe double counting principle states the following “obvious” fact: if the\nsize of a set is counted in two different ways, the answers are the same.\n\nUsing this principle we may prove the following theorem.\n\\begin{theorem}[Vandermonde's identity]\n  For any integers $n, m > k$,\n  $\\sum_{i = 0}^k \\binom{n}{i} \\binom{m}{k - i} = \\binom{n + m}{k}$.\n\\end{theorem}\n\\begin{proof}\n  The idea is as follows, let us imagine that we have $n$ parrots and $m$ crows,\n  and we need to find how many ways to select $k$ birds.\n  It is easy to see that it is equal to $\\binom{n + m}{k}$. At the same\n  if we need to select $i$ parrots there are $\\binom{n}{i}\\binom{m}{k - i}$\n  ways to do this. Thus the number is also equal to\n  $\\sum_{i = 0}^k \\binom{n}{i}\\binom{m}{k - i}$.\n\\end{proof}\n\nHowever, the method can be used in a more sophisticated way.\n\\begin{lemma}[Handshaking Lemma]\n\\label{lemma:handshaking}\n  Suppose some number of people meet at a party and some shake hands. Assume\n  that no person shakes his or her own hand and furthermore no two people shake\n  hands more than once.\n\n  The number of guests who shake hands an odd number of times is even.\n\\end{lemma}\n\\begin{proof}\n  Let $1$, \\dots, $n$ be the people at the party. We apply double counting to\n  the set of ordered pairs $(i, j)$ for which $i$ and $j$ shake hands with each\n  other at the party. Let $d_i$ be the number of times that $i$ shakes hands,\n  and $e$ be the total number of handshakes that occur. On one hand, the number\n  of pairs is $\\sum_{i = 1}^n d_i$, since for each $i$ the number of choices of\n  $j$ is equal to $d_i$. On the other hand, each handshake gives rise to two\n  pairs $(i, j)$ and $(j, i)$; so the total is $2e$.\n  Thus $\\sum_{i = 1}^n d_i = 2e$. But, if the sum of $n$ numbers is even, then\n  evenly many of the numbers are odd.\n  (Because if we add an odd number of odd numbers and any number of even\n  numbers, the sum will be always odd).\n\\end{proof}\n\n\n\\begin{chapterendexercises}\n  \\exercise Let $m$ be some integer. Show that product of $m$ consecutive\n    integers is divisible by $m!$.\n    \\begin{solution}\n     In other words we need to show that \n     $\\frac{n \\cdot (n + 1) \\cdot \\dots \\cdot (n + m - 1)}{m!}$ is an integer,\n     for any integer $n$. But one may notice that \n     $\\frac{n \\cdot (n + 1) \\cdot \\dots \\cdot (n + m - 1)}{m!} = \n      \\binom{n + m - 1}{m}$ which is an integer.\n    \\end{solution}\n  \\exercise Show that\n    $\\numberOfPermutations[n]{x + y} = \\sum_{k = 0}^n \\binom{n}{k}\n      \\numberOfPermutations[k]{x} \\numberOfPermutations[n - k]{y}$.\n  \\exercise Show that\n    $\\sum_{k = 0}^n \\binom{n}{k}^2 = \\binom{2n}{n}$.\n  \\exercise Show that $\\sum_{m = k}^n \\binom{m}{k} =\n    \\binom{n + 1}{k + 1}$.\n    \\hint{Note that the formula on the right corresponds to the number of ways\n      to select $k + 1$ elements out of $n + 1$; $m$ in the summation on the\n      left denotes the maximum of this selected set minus one.}\n  \\exercise Using the previous formula, find the formulas for the following\n    expressions:\n    \\begin{enumerate*}\n      \\item $\\sum_{k = 0}^n k$,\n      \\item $\\sum_{k = 0}^n k^2$, and\n      \\item $\\sum_{k = 0}^n k^3$.\n    \\end{enumerate*}\n  \\exercise Prove the second statement from \\Cref{corollary:binommials-equality}\n\tusing double counting.\n  \\exercise Show that \n    $\\sum_{k = 2}^n k (k - 1) \\binom{n}{k} = n (n - 1) 2^{n - 2}$ for any\n    positive integer $n > 2$.\n    \\begin{solution}\n      There are several possible solutions. We present two of them: the first\n      one is similar to \\Cref{corollary:binommials-equality}, and the second is\n      based on the combinatorual meaning of the equality.\n      \\begin{enumerate}\n        \\item Note that $k (k - 1) \\binom{n}{k} = \n          k (k - 1) \\frac{n!}{k! (n - k)!} = n (n - 1) \\binom{n - 2}{k - 2}$.\n          Thus\n          \\begin{multline*}\n            \\sum_{k = 2}^n k (k - 1) \\binom{n}{k} =\n            \\sum_{k = 2}^n n (n - 1) \\binom{n - 2}{k - 2} =  \\\\\n              n (n - 1) \\sum_{k = 0}^{n - 2} \\binom{n - 2}{k} = \n              n (n - 1) 2^{n - 2}.\n          \\end{multline*}\n        \\item Another solution is the following. Imagine that we have $n$ people in a\n          group and we need to choose a subgroup of them, a head of this subgroup, and\n          a vice-head of this group.\n\n          It is easy to see that we have $n$ ways to select the head, $n - 1$\n          ways to select the vice-head, and $2^{n - 2}$ ways\n          to select the rest of the subgroup. On the other hand, if we know that the\n          subgroup has $i$ members, then there are $\\binom{n}{i}$ ways to select the\n          subgroup, $i$ ways to select the head, and $i - 1$ ways to select the\n          vice-head, thus there are $\\sum_{k = 2}^n k (k - 1) \\binom{n}{k}$ ways to\n          select the subgroup, its leader, and its vice-leader. As a result,\n          $n (n - 1) 2^{n - 2} = \\sum_{k = 2}^n k (k - 1) \\binom{n}{k}$.\n      \\end{enumerate}\n    \\end{solution}\n\n\n  \\exercise Using the binomial theorem, explain the following equalities:\n    \\begin{enumerate*}\n      \\item $\\sum_{k = 0}^{n} \\binom{2n}{2k} =\n        \\sum_{k = 0}^{n - 1} \\binom{2n}{2k + 1}$,\n        and\n      \\item $\\sum_{k = 0}^{n} \\binom{2n + 1}{2k} =\n        \\sum_{k = 0}^n \\binom{2n + 1}{2k + 1}$.\n    \\end{enumerate*}\n\n  \\exercise[recommended] Show that $\\sum_{k = 0}^n \\binom{m + k}{k} =\n    \\binom{m + n + 1}{n}$.\n  \\exercise Show that $\\sum_{k = 0}^n \\binom{n - k}{k} = f_{n + 1}$,\n    where $f_1 = 1$, $f_2 = 1$, and $f_{n + 2} = f_{n + 1} + f_n$ for $n > 0$.\n  \\exercise Show that $\\binom{n}{m} \\binom{m}{k} =\n    \\binom{n}{k} \\binom{n - k}{m - k}$.\n  \\exercise[recommended] Show that\n    $(a + 1)^p \\equiv a^p + 1 \\pmod{p}$.\n    \\hint{Use the binomial theorem.}\n  \\exercise[recommended] We say that a function \n    $f : \\set{0, 1}^n \\to \\set{0, 1}$ depends on the $i$th argument iff for some\n    $a_1, \\dots, a_{i - 1}, a_{i + 1}, \\dots, a_n \\in \\set{0, 1}$\n    \\[\n      f(a_1, \\dots, a_{i - 1}, 0, a_{i + 1}, \\dots, a_n) \\neq\n      f(a_1, \\dots, a_{i - 1}, 1, a_{i + 1}, \\dots, a_n).\n    \\]\n    We also say that the function $f$ depends on all the arguments iff for all\n    $i \\in \\range{n}$ it depends on $i$th argument.\n\n    Find the number of functions $f : \\set{0, 1}^n \\to \\set{0, 1}$ depending on all\n    arguments.\n\n    \\begin{solution}\n      Let $S \\subseteq \\range{n}$ and $F_i$ be the set of function from $\\set{0,\n      1}^n$ to $\\set{0, 1}$ not depending on the $i$th input. It is easy to see\n      that there are $2^{2^{n - 1}}$ elements in $F_i$ and moreover, there are\n      $2^{2^{n - \\cardinality{S}}}$ elements in the set $\\cap_{i \\in S} F_i$.\n      Thus by the inclusion-exclusion principle, there are\n      \\[\n        \\sum_{S \\subseteq [n] ~:~ S \\neq \\emptyset} \n          (-1)^{\\cardinality{S} + 1} 2^{2^{n - \\cardinality{S}}} =\n        \\sum_{k = 1}^n (-1)^k 2^{2^{n - k}} \\binom{n}{k}\n      \\]\n      functions not depending on at least one argument.\n      As a result, the answer is $2^{2^n} -\n      \\sum_{k = 1}^n (-1)^k 2^{2^{n - k}} \\binom{n}{k}$.\n    \\end{solution}\n  \\exercise Find the largest coefficient of $(x_1 + x_2 + \\dots + x_k)^k$.\n  \\exercise Prove that,\n    without using Theorem~\\ref{theorem:multinomial-coefficients},\n    \\[\n      \\sum_{k_1, k_2, k_3 ~:~ k_1 + k_2 + k_3 = n} \\binom{n}{k_1 \\ k_2 \\ k_3} =\n      3^n.\n    \\]\n  \\exercise How many different words one can get by reordering the letters of\n    the word ``combinatorics'' (these words may be meaningless)?\n    \\begin{solution}\n      Note that the word ``combinatorics'' has $13$ letters, two of them are\n      ``o'', two of them are ``c'', two of them are ``i'', and all other are\n      different. Hence, if we assume for a second that all the letters are\n      different, we can get $13!$ different words. But note that we can exchange\n      ``o''s and it does not change the word, we can also exchange ``c''s etc.\n      Hence, we need to divide $13!$ by $2 \\cdot 2 \\cdot 2$. As a result, the\n      answer is $\\frac{13!}{8}$.\n    \\end{solution}\n\\end{chapterendexercises}\n", "meta": {"hexsha": "cfe2fcb50bdae5a51f5cf7440ffc48e7b787386f", "size": 26908, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_4/chapter_20_binomial_coefficients.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_4/chapter_20_binomial_coefficients.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_4/chapter_20_binomial_coefficients.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 43.191011236, "max_line_length": 103, "alphanum_fraction": 0.6262449829, "num_tokens": 9292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.8887587964389112, "lm_q1q2_score": 0.7025907745693291}}
{"text": "\\chapter{Gaussian processes}\n\n\n\\section{Introduction}\nIn supervised learning, we observe some inputs $\\vec{x}_i$ and some outputs $y_i$. We assume that $y_i =f(\\vec{x}_i)$, for some unknown function $f$, possibly corrupted by noise. The optimal approach is to infer a \\emph{distribution over functions} given the data, $p(f|\\mathcal{D})$, and then to use this to make predictions given new inputs, i.e., to compute\n\\begin{equation}\np(y|\\vec{x},\\mathcal{D})=\\int p(y|f,\\vec{x})p(f|\\mathcal{D})\\mathrm{d}f\n\\end{equation}\n\nUp until now, we have focussed on parametric representations for the function $f$, so that instead of inferring $p(f|\\mathcal{D})$, we infer $p(\\vec{\\theta}|\\mathcal{D})$. In this chapter, we discuss a way to perform Bayesian inference over functions themselves.\n\nOur approach will be based on \\textbf{Gaussian processes} or \\textbf{GP}s. A GP defines a prior over functions, which can be converted into a posterior over functions once we have seen some data. \n\nIt turns out that, in the regression setting, all these computations can be done in closed form, in $O(N^3)$ time. (We discuss faster approximations in Section \\ref{sec:Approximation-methods-for-large-datasets}.) In the classification setting, we must use approximations, such as the Gaussian approximation, since the posterior is no longer exactly Gaussian.\n\nGPs can be thought of as a Bayesian alternative to the kernel methods we discussed in Chapter \\ref{chap:Kernels}, including L1VM, RVM and SVM.\n\n\n\\section{GPs for regression}\nLet the prior on the regression function be a GP, denoted by\n\\begin{equation}\nf(\\vec{x}) \\sim GP(m(\\vec{x}),\\kappa(\\vec{x},\\vec{x}'))\n\\end{equation}\nwhere $m(\\vec{x}$ is the mean function and $\\kappa(\\vec{x},\\vec{x}')$ is the kernel or covariance function, i.e.,\n\\begin{align}\nm(\\vec{x} & = \\mathbb{E}[f(\\vec{x})] \\\\\n\\kappa(\\vec{x},\\vec{x}') & = \\mathbb{E}[(f(\\vec{x})-m(\\vec{x}))(f(\\vec{x})-m(\\vec{x}))^T]\n\\end{align}\nwhere $\\kappa$ is a positive definite kernel.\n\n\n\\section{GPs meet GLMs}\n\n\n\\section{Connection with other methods}\n\n\n\\section{GP latent variable model}\n\n\n\\section{Approximation methods for large datasets}\n\\label{sec:Approximation-methods-for-large-datasets}\n\n\n", "meta": {"hexsha": "7409a21497ef85609629fcaa94e25445169ec83e", "size": 2194, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mlapp/chapterGP.tex", "max_stars_repo_name": "Alexoner/Statistical-formula", "max_stars_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-02-15T17:00:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-24T13:46:00.000Z", "max_issues_repo_path": "mlapp/chapterGP.tex", "max_issues_repo_name": "Alexoner/Statistical-formula", "max_issues_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mlapp/chapterGP.tex", "max_forks_repo_name": "Alexoner/Statistical-formula", "max_forks_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-02-25T15:40:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-25T04:26:03.000Z", "avg_line_length": 48.7555555556, "max_line_length": 360, "alphanum_fraction": 0.7324521422, "num_tokens": 613, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.7025886374150312}}
{"text": "\\section{Residual systematics}\nWe measure the mean density of the data as a function imaging parameters, but limited to the mock footprint. This enables a null test based on the $\\chi^{2}$ statistics to evaluate the performance of systematics mitigation. The null hypothesis is that the mean density in each bin of a particular imaging systematic $s_{k}$ should be equal to the global average density $\\overline{n}_{tot}$, or the ratio should be one. Then, we have \n\\begin{equation}\\label{eq:chi2nnbar}\n    \\chi^{2} = \\sum_{s}\\sum_{k} (1/\\sigma^{2})[\\frac{\\overline{n}(s_{k})}{\\overline{n}_{tot}}-1]^{2},\n\\end{equation}\nwhere index k runs over the different bins, and index s runs over the different imaging systematics (see eqs. \\ref{eq:nnbar_stat} and \\ref{eq:error_jack}). The total number of terms is the number of bins multiplied by the number of the imaging maps, 20x18=360. We construct the distribution of the $\\chi^{2}$ statistics by measuring the same quantity with the simulated data sets. Fig. \\ref{fig:chi2pdf} represents the distributions of the $\\chi^{2}$ for the null mocks (solid), contaminated mocks (dashed), and contaminated mocks after mitigation (dot-dashed). The vertical lines show the $\\chi^{2}$ values of the data. The $\\chi^{2}$ values observed in the data are 9567.1 (before treatment), 2066.7 (linear treatment), 1212.0 (quadratic treatment), 767.3 (Neural Network treatment), and 744.4 (Neural Network plain treatment). We also compute the observed $\\chi^{2}$ value in the data after applying masking on the galactic extinction. With the NN-based treatment, we obtain 766.6 and 714.4 respectively for masking out EBV > 0.15 and EBV > 0.12.\n\nThe mean and standard deviation for the distribution of $\\chi^{2}$  values observed in the null mocks are 487.1 and 49.2, respectively. The same quantities in the contaminated mocks are 2819.0 and 293.0, while in the contaminated mocks after Neural Network mitigation are 472.0 and 65.9. The mean $\\chi^{2}$ observed in the contaminated mocks is much smaller than the value observed in the data (2819.0 < 9567.1). This indicates that the contamination introduced in the mocks is not as strong as in the real data. Future work will incorporate much more sophisticated systematics. \n\n\nWe perform a hypothesis testing given the $\\chi^{2}$ value observed in the data after neural network mitigation (767.3) and the distribution of $\\chi^{2}$ values in the null mocks.\nIf the terms in Eq. \\ref{eq:chi2nnbar} were independent and normal deviates, we would have expected that $\\chi^{2}$ follow a Chi-squared distribution with the mean being around 360. Nevertheless, we assume that the $\\chi^{2}$ values observed in the mocks follow a Chi-squared distribution with the degree of freedom (dof) being equal to 487. We set the threshold of $\\alpha$=0.05 and perform a one-tail test. For dof=487,\n\\begin{equation}\n    P(\\chi^{2}>593.4 | dof=487) = 0.05\n\\end{equation}\nGiven that the observed $\\chi^{2}$ value in the data (after treatment) 767.3 is larger than 593.4, we can reject the null hypothesis that the data is completely clean. Therefore, this data set cannot be used for cosmology. This means that the 40\\% excess in the residual squared could have been removed if we had achieved a 20\\% better modeling of the target density or kept the errorbars under the control by 20\\%. \n\nThe residual systematic effects are going to be due to known systematics that we had the template for since this test was based on the mean density vs the imaging systematics. Fig. \\ref{fig:chi2breakdown} shows the contribution of each systematic to Eq. \\ref{eq:chi2nnbar} for the $\\chi^{2}$ values observed in the data after linear (light blue), quadratic (red), and neural network plain (dark blue) treatments. Further investigations on the templates for the depth-g, skymag-g, skymag-z, EBV, lnHI, and MJD-z along with the resolution used for pixelization or the cost function are needed, however the suggested analysis is beyond the scope of this paper. Also, our test does not show that there is no unknown systematic effects. We suggest that further analyses on the moments of density contrast ($\\delta$) incorporating more realistic mock datasets could provide an insight on unknown systematics.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.45\\textwidth]{fig25-crop.pdf}\n    \\caption{\\textit{Left}: $\\chi^{2}$ distribution for the null mocks (solid black), contaminated mocks (dashed black), and contaminated mocks with NN mitigation (dot-dashed black). The vertical dotted lines overlay the $\\chi^{2}$ values for the data with NN correction (blue), quadratic correction (purple), and linear correction (dark red). The $\\chi^{2}$ statistics before treatment is shown on the right (red).}\n    \\label{fig:chi2pdf}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.45\\textwidth]{fig26-crop.pdf}\n    \\caption{ The breakdown of $\\chi^{2}$ values observed in the data after linear (light purple), quadratic (dark purple), neural network with feature selection (red), and neural network plain (light blue) treatments. We also plot the 95-th percentile of the same quantity observed in the null mocks by a solid orange curve (note that $\\chi^{2}(\\textbf{s)}$ is not a continuous quantity). Given the 5\\% threshold, we can argue that there exists known residual systematics against EBV, depth-g, skymag-gz, and MJD-z.}\n    \\label{fig:chi2breakdown}\n\\end{figure}\n", "meta": {"hexsha": "8024f888026e1b311c858bfa66705cd7e2a06958", "size": 5444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/residuals.tex", "max_stars_repo_name": "mehdirezaie/SYSNet", "max_stars_repo_head_hexsha": "8da75f54177e460e6e446bfc2207dd82a76ac4cc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-07-29T11:55:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-25T21:50:52.000Z", "max_issues_repo_path": "paper/sections/residuals.tex", "max_issues_repo_name": "mehdirezaie/SYSNet", "max_issues_repo_head_hexsha": "8da75f54177e460e6e446bfc2207dd82a76ac4cc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/sections/residuals.tex", "max_forks_repo_name": "mehdirezaie/SYSNet", "max_forks_repo_head_hexsha": "8da75f54177e460e6e446bfc2207dd82a76ac4cc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-17T18:07:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-17T18:07:47.000Z", "avg_line_length": 164.9696969697, "max_line_length": 1049, "alphanum_fraction": 0.7615723733, "num_tokens": 1370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.7024168839462582}}
{"text": "%---------------------------Distortion---------------------------\n\\section{Distortion}\n\nThe distortion is a measure of how well-behaved the mapping from\nparameter space to world coordinates is.\nThe parameter space is defined using a ``master'' tetrahedron\nwith vertices\n\\[\n\\begin{array}{lcrcrcrc}\n \\vec P_0 &= (& -1&,& -\\frac{ \\sqrt{3}}{3}&,& -\\frac{2\\sqrt{6}}{9}&)\\\\\n \\vec P_1 &= (&  1&,& -\\frac{ \\sqrt{3}}{3}&,& -\\frac{2\\sqrt{6}}{9}&)\\\\\n \\vec P_2 &= (&  0&,&  \\frac{2\\sqrt{3}}{3}&,& -\\frac{2\\sqrt{6}}{9}&)\\\\\n \\vec P_3 &= (&  0&,&                    0&,&  \\frac{4\\sqrt{6}}{9}&)\n\\end{array}\n\\]\nand volume $V_m$.\nThe behavior of the map is measured by sampling the determinant of the\nJacobian at Gauss points $G = \\{g_k\\}$.\nThe minimum of these is then used to scale the ratio of the\n``master'' tetrahedron to the tetrahedron of interest:\n\\[\nq = \\frac{\\min_k\\{\\det(J_{g_k})\\} V_m}{V}\n\\]\n\nNote that if $V < DBL\\_MIN$, we set $q = DBL\\_MAX$.\nThis metric is currently unsupported.\n\n\\tetmetrictable{distortion}%\n{$1$}%                          Dimension\n{$[0.5,1]$}%                    Acceptable range\n{$[0,1]$}%                      Normal range\n{$[-DBL\\_MAX,DBL\\_MAX]$}%       Full range\n{$0$}%                          Equilateral tet\n{Adapted from \\cite{ideas:xx}}% Citation\n{v\\_tet\\_distortion}%                            Verdict function name\n\n", "meta": {"hexsha": "50fbb00a63cf173c55ed75e604fe64bc2c17bf4b", "size": 1347, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetDistortion.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetDistortion.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetDistortion.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 36.4054054054, "max_line_length": 70, "alphanum_fraction": 0.5515961396, "num_tokens": 443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396141, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7024068267048375}}
{"text": "\\appendix\n\\appendixpage\n\\section{Terms That Need More Explanation Then A Footnote}\n\\subsection{Potential} \\label{sec:potential}\nPotential is the energy change that occurs when the position of an object changes \\cite{potential}. There are many potentials, like electric potential, gravitational potential and elastic \npotential. Let me explain the concept with an example. Say you are walking on a set of stairs in the upwards direction. As your muscles move to bring you one step upwards, energy that is used\nby your muscles is converted into gravitational potential. Now imagine you turn around and go downwards instead. Notice how that is easier? That is due to the gravitational potential being \nconverted back into energy so your muscles have to deliver less energy to get you down. The potential is usually tied to a force, like the gravitational force.\n\n\\subsection{Laplacian Operator} \\label{sec:laplace}\nThe Laplacian operator ($\\nabla^2$, sometimes also seen as $\\Delta$) has two definitions, one for a vector field and one for a scalar field. The two concepts are not indpendent, a vector field \nis composed of scalar fields \\cite{vectorscalarfields}. Let us define a vector field first. A vector field is a function whose domain and range are a subset of the Eucledian $\\mathbb{R}^3$ space. \nA scalar field is then a function consisting out of several real variables (meaning that the variables can only take real numbers as valid values). So for instance the circle equation \n$x^2 + y^2 = r^2$ is a scalar field as $x, y$ and $r$ are only allowed to take real numbers as their values. \n\nWith the vector and scalar fields defined, let us take a look at the Laplacian operator. For a scalar field $\\phi$ the laplacian operator is defined as the divergence of the gradient of $\\phi$\n\\cite{laplacian}. But what are the divergence and gradient? The gradient is defined in \\autoref{eq:gradient} and the divergence is defined in \\autoref{eq:divergence}. Here $\\phi$ is a vector \nwith components $x, y, z$ and $\\Phi$ is a vector field with components $x, y, z$. $\\Phi_1, \\Phi_2$ and $\\Phi_3$ refer to the functions that result in the corresponding $x, y$ and $z$ values \n\\cite{vectorscalarfields}. Also, $i, j$ and $k$ are the basis vectors of $\\mathbb{R^3}$, and the multiplication of each term with their basis vector results in $\\Phi_1, \\Phi_2$ and $\\Phi_3$\nrespectively. If we then combine the two we get the Laplacian operator, as in \\autoref{eq:laplacian scalar}.\n\n\\begin{subequations}\n    \\begin{equation}\n        \\text{grad } \\phi = \\nabla \\phi = \\frac{\\delta \\phi}{\\delta x}i + \\frac{\\delta \\phi}{\\delta y}j + \\frac{\\delta \\phi}{\\delta z}k\n        \\label{eq:gradient}\n    \\end{equation}\n    \\begin{equation}\n        \\text{div} \\Phi = \\nabla \\cdot \\Phi = \\frac{\\delta \\Phi_1}{\\delta x} + \\frac{\\delta \\Phi_2}{\\delta y} + \\frac{\\delta \\Phi_3}{\\delta z}\n        \\label{eq:divergence}\n    \\end{equation}\n    \\begin{equation}\n        \\nabla^2 \\phi = \\nabla \\cdot \\nabla \\phi = \\frac{\\delta^2 \\phi}{\\delta x^2} + \\frac{\\delta^2 \\phi}{\\delta y^2} + \\frac{\\delta^2 \\phi}{\\delta z^2}\n        \\label{eq:laplacian scalar}\n    \\end{equation}\n\\end{subequations}\n\nFor a vector field $\\Phi$ the Laplacian operator is defined as in \\autoref{eq:laplacian vector}. Which essential boils down to taking the Laplacian operator of each function and multiply it by\nthe basis vector.\n\n\\begin{equation}\n    \\nabla^2 \\Phi = (\\nabla^2 \\Phi_1)i + (\\nabla^2 \\Phi_2)j + (\\nabla^2 \\Phi_3)k\n    \\label{eq:laplacian vector}\n\\end{equation}\n\n\\subsection{Interpolation} \\label{sec:interpolation}\nInterpolation is a form of estimation, where one has a set of data points and desires to know the values of other data points that are not in the original set of data points\\cite{interpolation}. \nBased on the original data points, it is estimated what the values of the new data points will be. There are various forms of interpolation like linear interpolation, polynomial interpolation \nand spline interpolation. The CLAuDE model uses linear interpolation which is specified in \\autoref{eq:interpolation}. Here $z$ is the point inbetween the known data points $x$ and $y$. \n$\\lambda$ is the factor that tells us how close $z$ is to $y$ in the interval $[0, 1]$. If $z$ is very close to $y$, $\\lambda$ will have the value on the larger end of the interval, like 0.9.\nWhereas if $z$ is close to $x$ then $\\lambda$ will have a value on the lower end of the interval, like 0.1.\n\n\\begin{equation}\n    z = (1 - \\lambda)x + \\lambda y\n    \\label{eq:interpolation}\n\\end{equation}", "meta": {"hexsha": "d2f90f08314a3f3c10e16886376d767f34586153", "size": 4546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex-docs/streams/TTNMETAF.tex", "max_stars_repo_name": "balintf/claude", "max_stars_repo_head_hexsha": "a3ebf0605ca26c4aadd0273f6b70813bdf931c9c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex-docs/streams/TTNMETAF.tex", "max_issues_repo_name": "balintf/claude", "max_issues_repo_head_hexsha": "a3ebf0605ca26c4aadd0273f6b70813bdf931c9c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex-docs/streams/TTNMETAF.tex", "max_forks_repo_name": "balintf/claude", "max_forks_repo_head_hexsha": "a3ebf0605ca26c4aadd0273f6b70813bdf931c9c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 82.6545454545, "max_line_length": 196, "alphanum_fraction": 0.7362516498, "num_tokens": 1272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528132451417, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7024026594273177}}
{"text": "\\mychapter{12}{Lesson 12} %181107\n\\section{Hashing}\n\nRemember one solution to domain-extension for \\prf{}s, as a composition of a \\prf{} $F$ with an almost universal hash function $H$. Hash functions compress their arguments to some ``fingerprint'', which is assumed to be unique. However, since this compression in this context inherently introduces information loss, it is not guaranteed that every message gets its own unique fingerprint; indeed, there will be some instances where two messages yield the same hash value, or in other words, the hashes \\emph{collide}. It is desirable for a hash function to be \\emph{resistant} to these events, meaning that it is hard to reproduce such collisions.\n\n\\begin{definition}\n    A hash function family $H$ is deemed \\emph{collision-resistant}, denoted as $H \\in \\crh$ iff the probability of finding a collision is negligible, even when knowing the seed $s$. Formally:\n    \\[\n        \\forall \\adversary \\in \\ppt \\implies \\Pr(\\cryptog{crh}(\\lambda) = 1) \\in \\negl(\\lambda)\n    \\]\n\n    \\begin{cryptogame}\n        {crh}\n        {The \\emph{collision-resistance} game}\n        {crh}\n\n        \\receive{$s \\pickUAR \\binary^\\lambda$}{$s$}{}\n\n        \\send{}{$x, y$}{\\textsc{Output 1 iff} $h_s(x) = h_s(y)$}\n        \n    \\end{cryptogame}\n\\end{definition}\n\nA note: before, we were dealing with unbounded adversaries, and the key was hidden. Now the key is public, but the adversary must be efficient.\n\n\\begin{exercise}\n    Let $\\Pi$ be a \\ufcma{} authentication scheme over the message space $\\binary^n$. Show that $\\Pi' = (\\Tag', \\Ver') : \\Tag'_{k, s}(m) = \\Tag_k(h_s(m))$ is \\ufcma-secure over $\\binary^l$, where $l \\in \\poly(n)$, as long as $h_s$ itself is \\crh.\n\\end{exercise}\n\n\\subsection{Merkle-Damg\\r{a}rd construction}\n\nA construct for starters has been defined by Ralph Merkle and Ivan Damg\\r{a}rd, which revolves around the use of a \\crh{} function $h_s \\in \\binary^{n + c} \\to \\binary^n$, where $c$ is the size of one ``block'' of a message. For now, consider the messages to be of an arbitrarily fixed length $l$, and let $c$ be 1.  The steps to follow are:\n\n\\begin{enumerate}\n    \\item Let $\\textsc{iv} \\in \\binary^b$ be an \\emph{initialization vector}\n    \\item Initialize $t_0 := \\textsc{iv}$\n    \\item For each bit $b_i$ of the message to hash $m$:\n    \\begin{enumerate}\n        \\item Compute $t_i := h_s(b_i, t_{i - 1})$\n    \\end{enumerate}\n    \\item Return $\\phi = t_n$\n\\end{enumerate}\n\n% AP190203: To review, it is somewhat confused\n%First step: Compress the original message (assuming fixed size) by one bit\n\n%Let $H$ be a one-bit shrinking function. Then, it can be used to construct a hash function H' that splits an arbitrary-size message into fixed-size blocks, apply H onto them, and return a digest of fixed length. This is exemplified by the diagram in figure \\ref{fig:mdbase}\n\n\\begin{figure}\n    \\centering\n\n    \\tikzstyle{int}   = [draw, minimum size=2em]\n    \\tikzstyle{empty} = [minimum size=2em]\n    \\tikzstyle{init}  = [pin edge={to-,thin,black}]\n\n    \\begin{tikzpicture}[node distance = 1.9cm, auto, >=latex']\n\n        \\node (a) [empty] {$\\textsc{iv}$};\n        \\node (r) [int, pin={[init]above:$b_1$}] [right of=a] {$h_s$};\n        \\node (d) [int, pin={[init]above:$b_2$}] [right of=r] {$h_s$};\n        \\node (e) [int, pin={[init]above:$b_3$}] [right of=d] {$h_s$};\n        \\node (f) [empty] [right of=e] {$...$};\n        \\node (g) [int, pin={[init]above:$b_n$}] [right of=f] {$h_s$};\n        \\node (h) [empty, right of=g] {$\\phi$};\n\n        \\path[->] (a) edge (r);\n        \\path[->] (r) edge node {$t_1$} (d);\n        \\path[->] (d) edge node {$t_2$} (e);\n        \\path[->] (e) edge node {$t_3$} (f);\n        \\path[->] (f) edge node {$t_{n-1}$} (g);\n        \\path[->] (g) edge (h);\n    \n    \\end{tikzpicture}\n    \\caption{Basic outline of a Merkle-Damg\\r{a}rd construction}\n    \\label{fig:mdbase}\n\\end{figure}\n\nFigure \\ref{fig:mdbase} depicts a general view of the algorithm. Let it be denoted as another hash function $h'_s \\in \\binary^l \\to \\binary^n$.\n\n\\begin{theorem}\n    The construction $H'$ obtained by Merkle-Damg\\r{a}rd is a \\textsc{crh} function.\n\\end{theorem}\n\n% AP190204: Tentative\n\\begin{proof}\n    Assume $H'$ can be broken efficiently by a distinguisher $\\distinguisher^{\\crh}$, meaning that finding two distinct block sequences that give the same hash is easy. Consider the reduction to $H$'s \\crh-ness in figure \\ref{cryptoredux:mdcrh}\n\n    \\begin{cryptoredux}\n        {mdcrh}\n        {Breaking the underlying \\crh-ness of $H$}\n        {h-crh}\n        {h'-crh}[3]\n\n        \\receive{}{$s$}{}\n        \\invoke{}{$s$}{}\n        \\return{}{$x, y$}{}\n\n        \\cseqdelay\n\n        % AP190911: need a better way to convey meaning here\n        \\send{\\shortstack[r]{\n            \\textsc{Find} $j :$ \\\\\n            $h'_{s, (j - 1)}(x) \\neq h'_{s, (j - 1)}(y)$ \\\\\n            $\\wedge\\: h'_{s, (j)}(x) = h'_{s, (j)}(y)$\n        }}{$h'_{s, (j - 1)}(x), h'_{s, (j - 1)}(y)$}{}\n\n    \\end{cryptoredux}\n\n    Ignore same blocks: find the largest j such that:\n    \\[\n        (b_j, x_{j - 1}) \\neq (b'_j, y_{j - 1}) \\wedge h_s(b_j, x_{j - 1}) = h_s(b'_j, y_{j - 1})\n    \\]\n    this implies the rest of the message is equal, then the resulting final hash will be equal, thus for $j > 0$ we have a collision.\n\n\\end{proof}\n\n%AP190911: Not clear at all\n\\subsubsection{Domain extension}\n\nIn order to adapt the MD-construct to messages of variable length, some sort of ``strengthening'' is required: \n\n% Also called MD-strengthening\n\\begin{lemma}[Length padding]\n    Let $H_s \\in \\binary^{n + l} \\to \\binary^n$, then:\n    %AP190911: This needs to be rewritten correctly\n    \\[\n        H'_s = H_s(\\left<l'\\right>, H_s(x_{l'}, \\dots , H_s(x_1, 0^n) \\dots)), |l'|, |x_i| \\in \\binary^c \n    \\]\n\\end{lemma}\n\nThis is an example of padding which encodes the message length in itself.\n\n\\begin{theorem}\n    The strengthened construct is collision-resistant for variable-length messages.\n\\end{theorem}\n\n\\begin{proof}\n    Hint: similar as above, case by case\n\\end{proof}\n\n\\subsubsection{Merkle trees}\n\nThis is an alternative construction to the ``linear'' approach used beforehand: it starts from the message's blocks acting as leaves of a complete binary tree, and using a halving compression function on each node from the bottom up, and outputting the final tag as the image of the root invocation. It also has nice properties, such as easy verification of the presence of a single specific block in the message.\n\n\\subsection{Compression functions}\n\nThe compression functions are the central point of these kinds of ``fingerprinting'' tag schemes. They are, essentially, hash functions with a smaller codomain than its domain, thereby forcing the existence of collisions.\n\nLet ($\\textsf{Gen} : 0 \\mapsto (\\pk, \\sk), f, g)$ be a \\pke{} scheme, where the functions $f$ and $g$ are keyed \\prp{}s. A \\emph{claw} is a couple of values $(x, x')$ such that:\n\\[\n    f(\\pk, x) = g(\\pk, x')\n\\]\n\n\\begin{cryptogame}\n    {cfp}\n    {The game of claw-free permutations}\n    {cfp}\n    \n    \\receive{$(\\pk, \\sk) \\pickUAR \\textsf{Gen}$}{$\\pk$}{}\n    \\send{}{$x, x'$}{\\textsc{Output 1 iff} $f(\\pk, x) = g(\\pk, x')$}\n\n\\end{cryptogame}\n\n\\begin{theorem}\n    Assuming $\\mathcal{F}$ is claw-free, then $h_\\pk$ is \\crh{} from $n + l$ bits to $n$.\n\\end{theorem}\n\n\\subsubsection{Davies-Meyer construct}\n\n% AP190911: How does AES come in here?!\n\\begin{definition}\n    $x_{i + 1} = E_k(x_i) \\oplus x_i$, maps n+$\\lambda$ to n. E is AES\n\\end{definition}\n", "meta": {"hexsha": "1a9f1d7ef28a1e96421b22c8c664e89ee10a994e", "size": 7475, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lessons/lesson_12.tex", "max_stars_repo_name": "Project2100/Cryptography-2018_19", "max_stars_repo_head_hexsha": "da5dcf51b0396bd26d7fd0445feceef365950757", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-15T09:22:45.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-15T09:22:45.000Z", "max_issues_repo_path": "lessons/lesson_12.tex", "max_issues_repo_name": "Project2100/cryptography_1819", "max_issues_repo_head_hexsha": "da5dcf51b0396bd26d7fd0445feceef365950757", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-07-18T15:45:10.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-27T20:36:12.000Z", "max_forks_repo_path": "lessons/lesson_12.tex", "max_forks_repo_name": "Project2100/cryptography_1819", "max_forks_repo_head_hexsha": "da5dcf51b0396bd26d7fd0445feceef365950757", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-07-17T14:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-03T15:23:22.000Z", "avg_line_length": 42.9597701149, "max_line_length": 647, "alphanum_fraction": 0.645083612, "num_tokens": 2366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028205, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.702402654092315}}
{"text": "\\documentclass{article}\n\n\\usepackage{mathrsfs,amssymb,amsmath}\n\n\\begin{document}\n\n\\section{Show that the particular point topology is $T_0$ but not $T_1$}\n\nConsider the particular point topology of a set $X$ cardinality $\\ge 3$ with particular point $x$, that is all sets containing $x$ are open as is the empty set, but no other sets.\n\nConsider two arbitrary \"other\" points $x_1$ and $x_2$. \n\nTo show $X$ is $T_0$ consider the two cases:\n\nCase 1: $x$ and $x_1$. $x$ has an open neighborhood $\\{x\\}$ that does not contain $x_1$.\n\nCase 2: $x_1$ and $x_2$. $x_1$ has an open neighborhood $\\{x, x_1\\}$ that does not contain $x_2$.\n\nThis is sufficient to prove the statement for all pairs of points, since $x_1$ and $x_2$ were chosen arbitrarily, and every pair of points falls into one of these cases.\n\nTo show $X$ is not $T_1$, consider the case $x$ and $x_1$. Every open set containing $x_1$ will also contain $x$ (since all non-empty open sets contain $x$)\n\n\\section{Show that the particular point topology is not Hausdorf}\n\nObviously if a space is not $T_1$ it can't be $T_2$.\n\nA more illustrative proof starts with the fact limits in Hausdorf are unique. So we must construct a sequence that converges to more than one point.\n\nConsider any sequence $s_n$ that is eventually $x$. This sequence has $x$ as a limit, but it also has every other point in the space. In the case of $x_1$, every neighborhood contains of $\\{x, x_1\\}$, which $s_n$ eventually never leaves.\n\n\\end{document}\n", "meta": {"hexsha": "89e6b9007f7ba7bb4c7987890d5afa70695d0d35", "size": 1483, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "analysis/5_Weak_Topologies/particular_point_topology.tex", "max_stars_repo_name": "lukemassa/math-exercises", "max_stars_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "analysis/5_Weak_Topologies/particular_point_topology.tex", "max_issues_repo_name": "lukemassa/math-exercises", "max_issues_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "analysis/5_Weak_Topologies/particular_point_topology.tex", "max_forks_repo_name": "lukemassa/math-exercises", "max_forks_repo_head_hexsha": "765b84eb0a1b5ab59576172e2a814a1862a4f129", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.34375, "max_line_length": 237, "alphanum_fraction": 0.7309507755, "num_tokens": 437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7024026455922113}}
{"text": "\\section{Summary for CNN Models From the Viewpoint of Multigrid}\nFor a general classification problem, the data sets $X : = \\{x_i: i = 1:N\\}$ can be separated by many \nsubsets: \n\\begin{equation}\n\\{A_1, \\cdots, A_{\\kappa}\\} = X,\n\\end{equation}\nby different labels. \n\nIf these $A_i$ are already linear separable, then we can just apply some linear model\nsuch as logistic regression or SVM to finish the classification task.\n\nHowever, generally speaking, these data sets are not linear separable, so the role for CNN\nis just to map the original data $X : = \\{x_i: i = 1:N\\}$ into $f_{\\rm CNN} (X) : =  \\{f_{\\rm CNN}(x_i): i = 1:N\\}$,\nthen \n\\begin{equation}\n\\{f_{\\rm CNN}(A_1), \\cdots, f_{\\rm CNN}(A_{\\kappa})\\} = f_{\\rm CNN} (X),\n\\end{equation}\nare linear separable.\n\nA key observation in our MgNet is: we have feature-data mapping in each grid:\n\\begin{itemize}\n\t\\item $g \\longleftarrow$ image,\n\t\\item $u \\longleftarrow$ feature,\n\\end{itemize}\nwith the next control equation:\n\\begin{equation}\\label{eq:f-d-mapping}\nA \\ast u = g.\n\\end{equation}\nWe have many numerical evidences to show this is indeed a good model.\n\nHowever, there are still some things mystery: \n\\begin{itemize}\n\t\\item Why only use the coarse grid?\n\t\\item Why this is enough?\n\\end{itemize}\n\n\\paragraph{Explanation:} Think about the one dimension case with $\\ell=1$ i.e. the finest grid.\nWe have the formula for $u$ with just one channel then:\n\\begin{equation}\nu(x) = \\sum_{i=1}^{n_1} \\alpha_i \\phi_i^1(x).\n\\end{equation}\nHere we can recover these $\\phi_{i}^1$ with one channel in coarse grid as\n\\begin{equation}\n\\phi_i^1(x) = \\phi_1^2(\\frac{x-x_i}{h}),\n\\end{equation} \nwhich means\n\\begin{equation}\nu(x) = \\sum_{i=1}^{n_1} \\alpha_i \\phi_i^1(x) = \\sum_{i=1}^{n_1} \\alpha_i \\phi_1^2(\\frac{x-x_i}{h}).\n\\end{equation}\nThis means that, we can recover a one channel function $u(x)$ in fine grid\nby multi-channel in coarse grid.\n\nThus to say, after each restriction operation in CNN models, we need to increase the channels.\nAs a result, the number of channels in last few coarse grids needs to be very large. This is the main factor\nthat why a CNN model has so many parameters.\n\nThere are some classical method to deal with this problem caused by the dense connection in channel dimension in CNN models. For example, dense connections in channel dimension corresponds to the \nmultiplication for dense matrix. So, they would like to use the special matrix theory such as H-matrix and Fourier transform to reduce the complexity of dense connection in channels.\nfor multiplication of dense matrix \n\n\nHere, our idea is to propose some better structure to \nreduce the complexity of these CNN models. \nWe find that we can reconstruct these CNN models from the \niterative methods for solving the feature-data mapping.\nActually, we can model them in two different ways:\n\\begin{enumerate}\n\t\\item \\begin{equation}\n\t\\min_{\\theta} f(\\theta) \n\t\\end{equation}\n\t\\item \\begin{equation}Au=g \\end{equation}\n\\end{enumerate}\n\nWe have dynamic system approach:\n(1) Optimization: \n\\begin{equation}\n\\theta^*\\in \\arg\\min_{\\theta} f(\\theta)\\to \\nabla f(\\theta^*)=0 ,\n\\end{equation}\nwhich means that\n\\begin{equation}\n\\frac{d\\theta}{dt}=-\\nabla f(\\theta(t)) .\n\\end{equation}\nBy Euler's method,\n\\begin{equation}\n\\frac{\\theta^{i+1}-\\theta^i}{\\eta}=-\\nabla f(\\theta^i) ,\n\\end{equation}\nthus we have\n\\begin{equation}\n\\theta^{i+1}=\\theta^i-\\eta\\nabla f(\\theta^i) .\n\\end{equation}\n(2) For linear equation system:\n\\begin{align}\nAu&=g  \\\\\\notag\nu&=u(t) \\\\\\notag\nu_t&=g-Au\\\\\\notag\nu^*&=\\lim_{t\\to \\infty}u(t)\\\\\\notag\ng-Au^*&=0\n\\end{align}\n\nMoreover, we can apply a preconditionor for the above system:\n\\begin{equation}\nAu=g \\Leftrightarrow B(Au-g)=0, \n\\end{equation} \nwhere $B$ is nonsingular. \nA simple choice for $B$ is $B=D^{-1}$, where $D=\\diag(A)$.\n\nFor Euler's method,\n\\begin{equation}\\frac{u^{i+1}-u^i}{\\eta}=B(g-Au^i)\\equiv r_i \\end{equation}\n\\begin{equation} u^{i+1}=u^i+\\eta r_i. \\end{equation}\n\n\\subsection{How we involve multigrid in this viewpoint}\n\n\\subsubsection{A closer look at a one dimensional problem: continuous case}\n\\begin{equation}\n\\left\\{\n\\begin{array}{rcll}\nu_t-u_{xx} & = & f(x) & x\\in (0,1), t>0\\\\\nu(x,t) & = & 0 & x\\in \\{0,1\\}, t>0\\\\\nu(x,0) & = & u_0(x) & x\\in (0,1)\n\\end{array}\n\\right.\n\\end{equation}\n\nBy the theorem we proved earlier, as $t\\rightarrow \\infty$, $u(x,t)$ approaches\nto the solution of the steady state problem:\n\\begin{equation}\\Label{1dSteady}\n\\left\\{\n\\begin{array}{rcll}\n-v_{xx} & = & f(x) & x\\in (0,1)\\\\\nv(x) & = & 0 & x=0,1.\n\\end{array}\n\\right.\n\\end{equation}\n\nWe will take a closer look at the convergence pattern using Fourier series.\n\nWe write\n$$\nf(x)=\\sum_{k=1}^\\infty\\beta_k\\sin(k\\pi x)\n$$\nand\n$$\nu_0(x)=\\sum_{k=1}^\\infty\\mu^0_k\\sin(k\\pi x).\n$$\nUsing a standard separation of variable technique, we obtain\n$$\nu(x,t)=v(x)+\\sum_{k=1}^\\infty\\bigg(\\mu^0_k-\\frac{\\beta_k}{(k\\pi)^2}\\bigg)\ne^{-(k\\pi)^2t}\\sin(k\\pi x).\n$$\nwhere\n$$\nv(x)=\\sum_{k=1}^\\infty \\frac{\\beta_k}{(k\\pi)^2}\\sin(k\\pi x)\n$$\nis the solution to (\\ref{1dSteady}).\n\n\nWe have the following {\\bf Observations:}\n\n\\begin{enumerate}\n\t\\item $u(x,t)$ converges to $v(x)$ faster on higher frequency\n\tcomponents.  More precisely\n\t$$ \\int_0^1 (u(x,t)-v(x))\\sin(k\\pi\n\tx)dx=\\left(\\mu^0_k-\\frac{\\beta_k}{(k\\pi)^2}\\right)e^{-(k\\pi)^2t}\n\t$$\n\twhich converges to zero faster for larger $k$.\n\t\n\t\\item The error $u(x,t)-v(x)$, as a function of $x$, gets smoother\n\t(namely fewer and smaller oscillations) as $t$ gets larger. \n\\end{enumerate}\nFrom the above observation, we know the key idea in accelerating\nEuler's scheme is try to make all components to be high frequency.\nHere Multigrid plays a key role because of the fact that:\n{\tthe restriction of the low frequency in fine grid is a relatively high \n\tfrequency in coarse grids. }\nThis explains the reason for using multigrid and why multigrid works. \n\n\\subsection{Residual and other methods}\nWhy do we consider the residual?\nFor $Au=g$, we want to know whether $u^i \\to u^{i+1}$.\nConsider $Ae=r=g-Au^i$, we have the update $u^{i+1}=u^i+e$.\nAfter solving $Ae=r$ ``approximately'', say \n\\begin{equation} \n\\hat{e}=Br, B\\approx A^{-1}. \n\\end{equation} \nWe can have \n\\begin{equation} u^{i+1}=u^i+\\hat{e}=u^i+B(g-Au^i). \\end{equation}\n\nApply the numerical ODE methods.\n\\begin{itemize}\n\t\\item The explicit Euler's method:\n\\begin{equation} \\theta^{i+1}=\\theta^i-\\eta_i\\nabla f(\\theta^i). \\end{equation}\n\\item The implicit Euler's method:\n\\begin{equation} \\theta^{i+1}=\\theta^i-\\eta_i\\nabla f(\\theta^{i+1}). \\end{equation}\n\\item  Multistep method:\n\\begin{equation} u^{i+1}= \\sum_{j=0}^{i} \\eta_j(u^j+B^j r_j ). \n\\end{equation}\n\\end{itemize}\nThen we can apply the explicit Euler's method and multi-step ODE solver\nto get the ResNet and DenseNet as shown in the previous sections.\n\nFinally, Y. LeCun mentioned the evolution of the CNN models as:\n\\begin{enumerate}\n\t\\item LeNet,\n\t\\item AlexNet,\n\t\\item ResNet,\n\t\\item DenseNet.\n\\end{enumerate}\nSo, can MgNet be the next evolution of CNN?\n\n\n", "meta": {"hexsha": "2283387fdd5b0a993b45eef7fea891f0ec1315fe", "size": 6944, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/mgnet_summary.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/mgnet_summary.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/mgnet_summary.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.9099526066, "max_line_length": 196, "alphanum_fraction": 0.701468894, "num_tokens": 2348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619220634457, "lm_q2_score": 0.8519528019683105, "lm_q1q2_score": 0.7024026446181314}}
{"text": "% !TEX root = ../../main.tex\n\\subsection{Mutation}\\label{seq_determ_mut}\n\nOne of the ingredients for evolution to take place is the constant appearance\nof genetic variability. After all, the raw material for evolution to act on is\nthe appearance of new mutations in the population. This is what we will model\nnow for our one-locus two-allele case. We will think of mutations between both\nalleles $A$ and $a$ as a simple first-order chemical reaction of the form\n\\begin{equation}\n  A \\xrightleftharpoons[\\mu_{a A}]\n  {\\,\\mu_{A a}\\,} a,\n\\end{equation}\nwhere $\\mu_{A a}$ is the mutation rate from $A$ to $a$ and \n$\\mu_{a A}$ is the mutation rate from $a$ to $A$. A useful way to\ninterpret the mutation rate is as the probability of switching allele per unit\ntime. That means that on a small time window $\\Dt$ a single organism has a\nprobability of switching from $A$ to $a$ of\n\\begin{equation}\n  P(A \\rightarrow a \\mid \\Dt) = \\mu_{A a} \\Dt, \\quad \n  \\text{for } \\Dt \\ll \\mu_{Aa}.\n\\end{equation}\nWhat this implies is that for this small time window every organism carrying\nallele $A$ flips a coin with probability $\\mu_{A a} \\Dt$ of getting\nheads. If the outcome of the coin is indeed heads, the allele is mutated,\notherwise it remains the same. So when writing a differential equation to model\nthis phenomena we must multiply the number of organisms by the mutation rate.\nThis results in a differential equation for the change in number of organisms\ncarrying $A$ of the form\n\\begin{equation}\n  \\dt{N_A} = \n  \\underbrace{- \\mu_{A a} N_A(t)}_{\\text{loss } A \\rightarrow a}\n  \\underbrace{- \\mu_{a A} N_a(t)}_{\\text{gain } a \\rightarrow A},\n\\end{equation}\nwhere, as indicated, we must account for number of organisms that ``exit'' the\n$A$ allele state by mutating to $a$, and the number of organisms that ``enter''\nthe state by mutating from $a$ to $A$. We can write an equivalent equation for\n$N_a$ where the signs would be simply flipped since every time an organism is\nlost from allele $A$ it must be gained in allele $a$, and vice versa. This\nimplies that for this case where there is only mutation $N\\tot$ does not change\nover time since the number of organisms is assumed to be conserved.\n\nLet us now write the dynamics that we actually care about, that is the allele\nfrequency $x(t)$. This takes the form\n\\begin{equation}\n  \\dt{x} = \\dt{}\\left( {N_A \\over N\\tot} \\right) = {1 \\over N\\tot} \\dt{N_A},\n\\end{equation}\nwhere we took $N\\tot$ out of the derivative since for this case we said it\ndoesn't change over time. Substituting the dynamics of $N_A$ and using the\ndefinition of the allele frequency we obtain\n\\begin{equation}\n  \\dt{x} = - \\mu_{A a} x + \\mu_{a A} (1 - x),\n  \\label{eq_mutation_ode}\n\\end{equation}\nwhere we again suppressed the time dependence for notation simplicity. This\nequation can also be solved analytically, but before getting to that solution\nlet's take a look at the steady state value. After all we know that these are\ndeterministic dynamics so the allele fraction will reach a unique point. The\nsteady state results in\n\\begin{equation}\n  \\mu_{A a} x_{ss} = \\mu_{a A} (1 - x_{ss}),\n\\end{equation}\nwhere $x_{ss}$ indicates that it is the steady state allele frequency. If we\nnow solve for $x_{ss}$ this results in\n\\begin{equation}\n  x = {\\mu_{a A} \\over \\mu_{a A} + \\mu_{A a}}.\n\\end{equation}\nSo the equilibrium allele frequency for this case is given by the rate of how\noften strains mutate from $a$ to $A$ divided by the sum of those rates. That\nmeans that in the limit where it is much more likely to mutate from $a$ to $A$,\ni.e. $\\mu_{a A} \\gg \\mu_{A a}$ the allele frequency goes\nto one, i.e. allele $A$ will go into fixation. The opposite would be true for a\nmuch larger mutation rate from $A$ to $a$.\n\nNow let's go ahead and solve the actual dynamics. \\eref{eq_mutation_ode} is an\nordinary differential equation that can again be solved by separation of\nvariables. This is\n\\begin{equation}\n  \\int {dx \\over - \\mu_{A a} x + \\mu_{a A} (1 - x)} = \n  \\int dt.\n\\end{equation}\nEvaluating the integrals results in\n\\begin{equation}\n  -{1 \\over \\mu_{a A} + \\mu_{A a}}\n  \\ln \\left( \\mu_{A a} x - \\mu_{a A} (1 - x) \\right) =\n  t + C,\n  \\label{eq_mutation_int}\n\\end{equation}\nwhere $C$ is an integration constant. Using again the initial condition where\n$x(t=0) = x_o$ we have that\n\\begin{equation}\n  C =  -{1 \\over \\mu_{a A} + \\mu_{A a}}\n  \\ln \\left( \\mu_{A a} x_o - \\mu_{a A} (1 - x_o) \\right).\n\\end{equation}\nUsing this result we can rewrite \\eref{eq_mutation_int} as\n\\begin{equation}\n  -{1 \\over \\mu_{a A} + \\mu_{A a}}\n  \\ln \\left( { \\mu_{A a} x - \\mu_{a A} (1 - x)\n    \\over\n  \\mu_{A a} x_o - \\mu_{a A} (1 - x_o)} \\right) = t.\n\\end{equation}\nExponentiating both sides gives\n\\begin{equation}\n  \\left( { \\mu_{A a} x - \\mu_{a A} (1 - x)\n    \\over\n  \\mu_{A a} x_o - \\mu_{a A} (1 - x_o)} \\right)^{\n    -{1 \\over \\mu_{a A} + \\mu_{A a}}} = \\E^t\n\\end{equation}\nIf we now elevate both sides to the $\\mu_{a A} + \\mu_{A\\rightarrow\na}$ power we obtain\n\\begin{equation}\n  \\left( { \\mu_{A a} x - \\mu_{a A} (1 - x)\n    \\over\n  \\mu_{A a} x_o - \\mu_{a A} (1 - x_o)} \\right) =\n  \\E^{- (\\mu_{a A} + \\mu_{A a}) t}.\n\\end{equation}\nWe can now solve for $x$ and after a little bit of algebra we find that\n\\begin{equation}\n  x(t) = {\\mu_{a A} \n  \\over \n  \\mu_{a A} + \\mu_{A a}} -\n  {\\left[  \n  \\mu_{a A} -\n  (\\mu_{a A} + \\mu_{A a}) x_o\n  \\right] \n  \\E^{- (\\mu_{a A} + \\mu_{A a}) t}.\n  \\over\n  \\mu_{a A} + \\mu_{A a}}.\n\\end{equation}\nA little tricky solution, but we can easily see that in the limit when $t\n\\rightarrow \\infty$ the second term on the right hand side goes to zero,\nleaving behind the steady state solution we found before.\n\\fref{fig_deterministic_mut} shows the dynamics for different ratios of the\nmutation rates. We can see that as expected the allele frequency converges to\nthe steady state value we derived.\n\n\\begin{figure}[h!]\n\t\\centering \\includegraphics\n  {../../fig/deterministic_evo/01_02_01_deterministic_mut.png}\n\t\\caption{\\textbf{Allele frequency for mutation only}. The different curves\n\tshow allele frequency dynamics for a one-locus two-allele system mutating\n\tbetween both alleles. The steady state allele frequency is set by the ratio\n\tof the mutation rates.}\n  \\label{fig_deterministic_mut}\n\\end{figure}\n\n\\subsubsection{Mutation-Selection Balance}\n\nNow that we have modeled two of the three forces we will be using throughout\nthe notes let us try to put them together. Since both selection and mutation\nare directional deterministic forces we can easily add them together for our\nallele frequency dynamics and still obtain a deterministic answer. The dynamics\nfor our single-locus two-allele system subject to both selection and mutation\nare given by the sum of the dynamics for each case. This is\n\\begin{equation}\n  \\dt{x} = s x (1 - x) - \\mu_{Aa} x + \\mu_{aA} (1 - x).\n  \\label{eq_sel_mut}\n\\end{equation}\nThis linear ODE can be solved analytically as you can asses yourself by plugin\nthis equation into a symbolic math package such as Mathematica or Sympy. The\nproblem is that the solution is not intuitive with a bunch of tangents and\narctangents that make it very difficult to look at. Nevertheless we can still\ngain intuition from \\eref{eq_sel_mut}. An interesting setting to analyze is the\ncase where one of the alleles, let's say $a$ is deleterious, i.e. $s < 0$. If\nthat were the case our results from \\secref{sec_selection} tell us that natural\nselection would remove this allele from the population. But if mutation keeps\nbringing the allele back over and over again, there should be a balance between\nmutation and selection. This is a plausible scenario if we think of allele $A$\nas a functional protein, and $a$ is a coarse-grained state of all\nnon-functional proteins for example. To compute this equilibrium we need to\ncompute the steady state for \\eref{eq_sel_mut} as\n\\begin{equation}\n  0 = s x_{ss}^2 + (\\mu_{Aa} + \\mu_{aA} - s) x_{ss} - \\mu_{aA},\n\\end{equation}\nwhere we already expanded the terms and group by powers of $x_ss$, the steady\nstate allele frequency. The roots of this quadratic equation are given by\n\\begin{equation}\n  x_{ss} = {(s - \\mu_{Aa} - \\mu_{aA}) \\pm \n    \\sqrt{(\\mu_{Aa} - \\mu_{aA} - s)^2 + 4 s \\mu_{aA}}\n    \\over 2s}.\n\\end{equation}\nIf again we take $a$ as a coarse-grained state for a non-functional gene we can\nassume that reversing the mutation to the functional allele is very unlikely,\ntherefore we can set $\\mu_{aA} \\approx 0$. This results in\n\\begin{equation}\n  x_{ss} = {(s - \\mu_{Aa}) \\mp (s - \\mu_{Aa}) \\over 2s}.\n\\end{equation}\nThe resulting two possible steady states are then\n\\begin{equation}\n  x_{ss1} = 0, \\quad x_{ss2} = 1 - {\\mu_{Aa} \\over s}.\n\\end{equation}\nThe first case shows that if allele $A$ were to go extinct it would stay as\nsuch. The more interesting and relevant case is the second root. This shows\nthat the allele frequency decreases from the fixation value 1 depending on the\nrelative strengths of mutation and selection.", "meta": {"hexsha": "064f82f55752ae5ebd9d8a87563d2ea56514628e", "size": 8927, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/book_draft/chapters/deterministic_evo/02_mutation.tex", "max_stars_repo_name": "mrazomej/stat_gen", "max_stars_repo_head_hexsha": "abafd9ecc63ae8a804c8df5b9658e47cabf951fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/book_draft/chapters/deterministic_evo/02_mutation.tex", "max_issues_repo_name": "mrazomej/stat_gen", "max_issues_repo_head_hexsha": "abafd9ecc63ae8a804c8df5b9658e47cabf951fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-03-05T00:17:26.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-05T00:17:26.000Z", "max_forks_repo_path": "doc/book_draft/chapters/deterministic_evo/02_mutation.tex", "max_forks_repo_name": "mrazomej/pop_gen", "max_forks_repo_head_hexsha": "abafd9ecc63ae8a804c8df5b9658e47cabf951fa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.0154639175, "max_line_length": 79, "alphanum_fraction": 0.7149098241, "num_tokens": 2720, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7023539488103435}}
{"text": "\\chapter{Natural Deduction}\n\\marginurl{%\n  Natural Deduction for Predicate Logic:\\\\\\noindent\n  Introduction to Mathematical Logic \\#6\n}{youtu.be/GVht3ES2qqo}\nBy analogy with the tautology, in the predicate logic we wish to prove that a\nformula is true, whenever the structure and the values of the variables we\nchoose. Such formulas are called \\textit{logically valid}.\n\nIn addition, we may define semantic implication for predicate formulas.\nWe say that a set of predicate formulas $\\Sigma$ in a signature $\\mathcal{S}$\nsemantically implies a formula $\\phi$ ($\\Sigma \\models \\phi$) in the signature\niff any structure with the signature $\\mathcal{S}$ modeling $\\Sigma$ models\n$\\phi$ as well.\n\nNatural deduction for the predicate formulas is defined in the same manner as\nthe natural deduction for the propositional formulas but now the lines are\npredicate formulas and we can use four additional rules.\n\n\\paragraph{Universal quantifier.}\nThe first logically-valid formula we use as a rule is\n$A(x) \\implies (\\forall y \\ A(y))$,\nthis rule allows us to introduce a universal quantifier.\nIn order to use the following rule, $x$ should not be a free variable of\nan open hypothesis.\n\\[\n  \\begin{nd}\n    \\have [m] {1} {A(x)}\n    \\have [~] {2} {\\forall y \\  A(y)} \\Ai{1}\n  \\end{nd}\n\\]\nThe second logically-valid formula we use as a rule says that if a statement is\ntrue for all the values of a variable, then it is also true when you substitute\nsome specific term instead of the variable, i.e. $(\\forall x \\ A(x)) \\implies\nA(t))$, this rule allows us to eliminate an universal quantifier.\n\\[\n  \\begin{nd}\n    \\have [m] {1} {\\forall x \\  A(x)}\n    \\have [~] {2} {A(t)} \\Ae{1}\n  \\end{nd}\n\\]\n\n\\paragraph{Existential quantifier.}\nThe first formula for the exisential quantifier says that you can name any term\nin the formula by a variable and formula is still true for some value of the\nvariable. The corresponding formula is $A(t) \\implies (\\exists x \\ A(x))$.\n\\[\n  \\begin{nd}\n    \\have [m] {1} {A(t)}\n    \\have [~] {2} {\\exists x \\ A(x)} \\Ei{1}\n  \\end{nd}\n\\]\n\nThe last rule says that if $A(x)$ is true for some $x$ and we know that $A(y)$\nimplies $B$, then we can derive $B$ (note that this is true only when\n$y$ is not used in $B$). Thus we can apply the following rule when $y$ is not\nbe a free variable neither of $B$ nor of any open hypothesis.\n\\[\n  \\begin{nd}\n    \\have [m] {1} {\\exists x \\ A(x)}\n    \\open\n      \\hypo [i] {2} {A(y)}\n      \\have[j] {3} {B}\n    \\close\n    \\have [~] {4} {B} \\Ee{1, 2-3}\n  \\end{nd}\n\\]\n\\section{Examples of Derivations}\nFirst example $\\forall x \\ F(x) \\lor \\lnot(\\forall x \\ F(x))$ is a special form\nof the law of excluded middle, which we proved\nin the previous chapter. However, in order to emphasize that the propositional\nlogic can prove all the statements provable in the predicate case we present\nthe proof of this statement as well.\n\n\\noindent $\n  \\begin{nd}\n    \\hypo {1} {}\n    \\open\n      \\hypo {2} {\\lnot (\\forall x \\  F(x) \\lor \\lnot (\\forall x \\  F(x)))}\n      \\open\n        \\hypo {3} {\\forall x \\  F(x)}\n        \\have {4} {\\forall x \\  F(x) \\lor \\lnot (\\forall x \\  F(x))} \\oi{3}\n        \\have {5} {\\perp} \\ne{2, 4}\n      \\close\n      \\have {6} {\\lnot (\\forall x \\  F(x))} \\ni{3-5}\n      \\have {7} {\\forall x \\  F(x) \\lor \\lnot (\\forall x \\  F(x))} \\oi{6}\n      \\have {8} {\\perp} \\ne{2, 8}\n    \\close\n    \\have {9} {\\forall x \\  F(x) \\lor \\lnot (\\forall x \\  F(x))} \\by{IP}{2-8}\n  \\end{nd}\n$\n\nUnfortunately, this example just shows that a statement provable in the\npropositional logic can be proven in the predicate logic. The next example is\nan example that cannot be expressed in the propositional logic, we\nprove that if we know that\n$\\forall x \\forall y \\ R(x, y) \\implies R(y, x)$, the we can derive\n$\\forall x \\forall y \\ ((R(x, y) \\implies R(y, x)) \\land\n  (R(y, x) \\implies R(x, y)))$.\n\n\n\\noindent $\n  \\begin{nd}\n    \\hypo {1} {\\forall x \\forall y \\ R(x, y) \\implies R(y, x)}\n\n    \\have {2} {\\forall y \\ R(x', y) \\implies R(y, x')} \\Ae{1}\n    \\have {3} {R(x', y') \\implies R(y', x')} \\Ae{2}\n    \\have {4} {\\forall y \\ R(y', y) \\implies R(y, y')} \\Ae{1}\n    \\have {5} {R(y', x') \\implies R(x', y')} \\Ae{4}\n    \\have {6} {(R(x', y') \\implies R(y', x')) \\land R(y', x') \\implies R(x', y')}\n              \\ai{3, 5}\n    \\have {6} {\\forall y \\ (R(x', y) \\implies R(y, x')) \\land\n      (R(y, x') \\implies R(x', y))}\n              \\Ai{6}\n    \\have {6} {\\forall x \\forall y \\ (R(x, y) \\implies R(y, x)) \\land\n      (R(y, x) \\implies R(x, y))}\n              \\Ai{7}\n  \\end{nd}\n$\n\n\\section{Soundness and Completeness}\nLike in the propositional case, the most important properties of the natural\ndeduction are the following two theorems.\n\n\\begin{theorem}[completeness of natural deductions, G\\\"odel]\n    Let $\\phi$ be a predicate formula. If $\\phi$ is logically valid, then\n    there is a proof of $\\phi$. Moreover, if $\\Sigma \\models \\phi$,\n    for some finite set of predicate formulas $\\Sigma$, then there is a\n    derivation of $\\phi$ from $\\Sigma$.\n\\end{theorem}\n\n\\begin{theorem}[soundness of natural deductions]\n    Let $\\phi$ be a predicate formula. If there is a proof of $\\phi$, then\n    $\\phi$ is logically valid. Moreover, if there is a derivation of $\\phi$ from\n    $\\Sigma$, for some finite set of predicate formulas $\\Sigma$, then\n    $\\Sigma \\models \\phi$.\n\\end{theorem}\n\n\\begin{chapterendexercises}\n  \\exercise Give a natural deduction derivation of\n    $\\forall x \\ A(x) \\implies \\forall x \\ B(x)$ from\n    $\\forall x \\ (A(x) \\implies B(x))$.\n  \\exercise Give a natural deduction derivation of\n    $\\exists x \\ ( A(x) \\lor B(x))$ from\n    $\\exists x \\  A(x) \\lor \\exists x \\  B(x)$.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "7e4ebb69a050ce648f2679e919ca17366696f722", "size": 5661, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_7/chapter_34_natural_deduction_predicate.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_7/chapter_34_natural_deduction_predicate.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_7/chapter_34_natural_deduction_predicate.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 38.5102040816, "max_line_length": 81, "alphanum_fraction": 0.6368132839, "num_tokens": 1817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324938410784, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7023539430138405}}
{"text": "\\paragraph{Parametric test}\nis created in a following way:\n\n\\begin{enumerate}\n\n  \\item Specify the statistical model, i.e. set of assumptions about the sample (examples are given\n  on previous page).\n\n  \\item Collect data. This step occurs after the 1st, because the model must not depend on data,\n  because specifying statistical model on the basis of some properties of the sample leads to\n  overestimation of significance level.\n\n  \\item Specify the null hypothesis $H$.\n\n  \\item Specify the significance level $\\alpha$.\n\n  \\item \n\n  \\item Calculate the critical region $K_\\alpha$.\n\n  \\item Make a decision.\n\n\\end{enumerate}\n\n\\paragraph{Test for goodness-of-fit}\ndetermines if an unknown distribution of interest $F$, given a sample $X$ i.i.d. $F$:\n\n\\noindent \\textbf{\\em Case 1}:\nis similar to a given, known distribution, i.e. fits some other distribution\n\n$F_0$ is a specific distribution, $H_0: F=F_0$\n\n\\noindent \\textbf{\\em Case 2}:\nbelongs to a given, known family of distributions, i.e. fits some family of distributions\n\n$\\mathcal{F}_0$ is a family of distributions, $H_0: F \\in \\mathcal{F}_0$\n\n\\paragraph{Test for normality}\nis a special case of a goodness-of-fit test, in which we test fitness of our distribution to a normal\ndistribution (or the whole family of normal distributions).\n\n\\paragraph{Test for independence}\ndetermines if two samples are independent.\n", "meta": {"hexsha": "9d763eb6b8efdabdb7a53194ac81b51ae6132b9d", "size": 1377, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_7c_tests_adv.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_stars_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs_7c_tests_adv.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_issues_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs_7c_tests_adv.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_forks_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.2954545455, "max_line_length": 101, "alphanum_fraction": 0.7538126362, "num_tokens": 350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7023539410800842}}
{"text": "% Section X: Optimal Transport and Wasserstein GAN: A Machine Learning Perspective\n\n\\vspace{10ex}\n\\section{Optimal Transport and Wasserstein GAN: A Machine Learning Perspective}\nOptimal Transport is widely used in applied ML, such as a large class of generative models. Among its many successful cases, Wasserstein GAN is supported by OT. Starting from theoretical analysis,  with small changes we can solve the training stability problem of original GAN , collapse mode problem, and so on. \n\n\\subsection{Optimal Transport Divergence}\nIn many cases, what we need and care about is not the mapping $\\mathbf{\\pi}$ here, but the final minimum cost (the minimum cost of transportation). For example, when we need to measure the distance between two probability distributions, we can use this optimal transport divergence as an effective metric. In original Wasserstein GAN\\cite{Arjovsky2017}, the author found:\n\nUnder the optimal discriminator of the original GAN, minimizing the loss of the generator is equivalent to minimizing the JS divergence of the distribution generated by the generator and the target distribution. But there is a fatal flaw in using JS divergence as a metric, that is, in the case where the two distributions do not intersect each other, the JS divergence of the two distributions is always a constant $\\log 2$,  and due to the generator generated distribution and the target support set It is a low-dimensional manifold embedded in a high-dimensional space, so the measure of their overlapping part is almost 0. This makes it impossible to measure the distance between two distributions disjointed. There is also a zero gradient when computing gradients. Because JS divergence and KL divergence both suffer from the above metric problems, this method of measuring distance is not continuous and derivable everywhere. But our GANs need metric methods that are differentiable and continuous. \n\nUsing optimal transport divergence as a measurement method can solve the above problems of JS divergence and KL divergence. (The distance between the two distributions $P$, $Q$ can be measured from another angle, that is, the distance between the two distributions is defined as the minimum cost to transport from the distribution P to the distribution $Q$.)\n\nOptimal Transport Divergence is defined as follows:\n\\begin{equation}\n  \\label{eq:OTD}\n  O T(P \\| Q)=\\inf _{\\pi} \\int_{X \\times Y} \\pi(x, y) c(x, y) d x d y  \n\\end{equation}\n\nConstraints are $\\int_{y} \\pi(x, y) d y=P(x)$ and $\\int_{x} \\pi(x, y) d x=Q(y)$.\n\nIn order to calculate the square of the commonly used $L_2$ norm to define the cost, that is, $c(x,y) = ||x - y||_2^2$, then we can get the 2-Wasserstein Distance\n\\begin{equation}\n  W_{2}(P, Q)=\\inf _{\\pi} \\int_{X \\times Y} \\pi(x, y)\\|x-y\\|_{2}^{2} d x d y  \n\\end{equation}\n\nIn a more general case, the k-Wasserstein Distance is:\n\\begin{equation}\n  W_{k}(P, Q)=\\inf _{\\pi} \\int_{X \\times Y} \\pi(x, y)\\|x-y\\|_{k}^{k} d x d y  \n\\end{equation}\n\nAlthough we got this kind of good-quality measurement method, if we look further, we will find some problems. Then as the dimension of the input random variable that needs to be compared grows, the problem size grows exponentially. For example, for a binary image of size $32 \\times 32$, then the dimension of each input random variable has nearly 1000, then the scale of the problem we have now is $O(2^{1024})$, which is impossible to calculate.\n\n\\subsection{Dual Form}\nThe Optimal transport problem is actually a linear programming problem because the problems we need to optimize and their constraints are linear functions. And for any linear programming problem, it can be transformed into its dual problem, and the solution of the dual problem is the lower bound of the optimal solution of the original problem.\n\nThen the dual problem of Optimal transport problem is defined as follows:\n\\begin{equation}\n  OT(P \\| Q)=\\sup _{f \\in L}\\left(\\int \\psi(x) P(x) d x+\\int \\phi(y) Q(y) d y\\right)  \n\\end{equation}\n\nwhere $L=\\{f: \\mathfrak{R} \\rightarrow \\mathfrak{R} | \\psi(x)+\\phi(y) \\leq c(x, y)\\}$.\n\nBecause the original problem \\ref{eq:OTD} contains constraints, we need to find a way to remove it first, so consider the following questions:\n\\begin{equation}\n    \\label{eq:p2}\n  \\sup _{\\psi}\\left(\\int_{x^{\\prime}} \\psi\\left(x^{\\prime}\\right) P\\left(x^{\\prime}\\right) d x^{\\prime}-\\int_{x} \\int_{y} \\psi(x) \\pi(x, y) d x d y\\right)\n\\end{equation}\n\nThe problem $\\int_{x^{\\prime}} \\psi\\left(x^{\\prime}\\right) P\\left(x^{\\prime}\\right) d x^{\\prime}$ is the expectation of $\\psi$ under the distribution $P$, and $\\int_{x} \\int_{y} \\psi(x) \\pi(x, y) d x d y$ is the expectation of $\\psi$ under the marginal probability distribution $\\int_{y} \\pi(x, y) d y$. Obviously, when $\\int_{y} \\pi(x, y) d y=P(x)$, for any function $\\psi$, formula \\ref{eq:p2} is 0; if it is not equal, it is easy to find $\\psi$ to make formula \\ref{eq:p2} also infinite. The same principle applies\n\n\\begin{equation}\n    \\label{eq:p3}\n  \\sup _{\\phi}\\left(\\int_{y^{\\prime}} \\phi\\left(y^{\\prime}\\right) Q\\left(y^{\\prime}\\right) d y^{\\prime}-\\int_{x} \\int_{y} \\phi(y) \\pi(x, y) d x d y\\right)\n\\end{equation}\n\nIt can be found that if you add \\ref{eq:p2} \\ref{eq:p3} to the original problem \\ref{eq:OTD}, in the case of $\\int_{y} \\pi(x, y) d y=P(x)$ and $\\int_{x} \\pi(x, y) d x=Q(y)$,  it will not affect the optimization problem. If it is not satisfied, there is no solution. At the same time, with a little transformation on \\ref{eq:p2} \\ref{eq:p3}, we can get\n\n\\begin{equation}\n\\begin{array}{l}{\\sup _{\\psi}\\left(\\int_{x} \\int_{y}\\left[\\int_{x^{\\prime}} \\psi\\left(x^{\\prime}\\right) P\\left(x^{\\prime}\\right) d x^{\\prime}-\\psi(x)\\right] \\pi(x, y) d x d y\\right)} \\\\ {\\sup _{\\phi}\\left(\\int_{x} \\int_{y}\\left[\\int_{y^{\\prime}} \\phi\\left(y^{\\prime}\\right) Q\\left(y^{\\prime}\\right) d y^{\\prime}-\\phi(y)\\right] \\pi(x, y) d x d y\\right)}\\end{array}\n\\end{equation}\n\nBecause $\\int_{x^{\\prime}} \\psi\\left(x^{\\prime}\\right) P\\left(x^{\\prime}\\right) d x^{\\prime}$ is constant for $\\int_{x} \\int_{y} \\psi(y) \\pi(x, y) d x d y$, the expectation of the constant is the constant itself.\n\nLet\n\\begin{equation}\n  L=\\int_{x} \\int_{y}\\left[\\int_{x^{\\prime}} \\psi\\left(x^{\\prime}\\right) P\\left(x^{\\prime}\\right) d x^{\\prime}-\\psi(x)\\right] \\pi(x, y) d x d y+\\int_{x} \\int_{y}\\left[\\int_{y^{\\prime}} \\phi\\left(y^{\\prime}\\right) Q\\left(y^{\\prime}\\right) d y^{\\prime}-\\phi(y)\\right] \\pi(x, y) d x d y\n\\end{equation}\n\nSo after adding it to \\ref{eq:OTD}, we get:\n\\begin{equation}\n  \\inf _{\\pi}\\left[\\int \\pi(x, y) c(x, y) d x d y+\\sup _{\\psi, \\phi} L\\right]\n\\end{equation}\n\nBecause formula above is a linear function of $\\psi, \\phi$ and $\\pi$, Sion's minimax theorem guaranteed that the order could be exchanged:\n\n\\begin{equation}\n    \\label{eq:sion}\n  \\sup _{\\psi, \\phi}\\left[\\int_{x^{\\prime}} \\psi\\left(x^{\\prime}\\right) P\\left(x^{\\prime}\\right) d x^{\\prime}+\\int_{y^{\\prime}} \\phi\\left(y^{\\prime}\\right) Q\\left(y^{\\prime}\\right) d y^{\\prime}+\\inf _{\\pi} \\int_{y}[c(x, y)-(\\psi(x)+\\phi(y))] \\pi(x, y) d x d y\\right]\n\\end{equation}\n\nLet $l=c(x, y)-(\\psi(x)+\\phi(y))$, then formula \\ref{eq:sion} for the optimization problem of $\\pi$, if $l \\geq 0$, then for any $x, y$, \n\n\\begin{equation}\n  \\inf _{\\pi} \\int_{y}[c(x, y)-(\\psi(x)+\\phi(y))] \\pi(x, y) d x d y=0\n\\end{equation}\n\nIn order to have a solution, Equation \\ref{eq:sion} can be transformed into a problem with constraints, as follows:\n\n\\begin{equation}\n\\begin{array}{l}{\\sup _{\\psi, \\phi \\in L}\\left(\\int \\psi(x) P(x) d x+\\int \\phi(y) Q(y) d y\\right) \\text { s.t. }} \\\\ {L=\\{\\psi, \\phi: \\mathfrak{R} \\rightarrow \\mathfrak{R} | \\psi(x)+\\phi(y) \\leq c(x, y)\\}}\\end{array}\n\\end{equation}\n\n\\subsection{Solving the OT Divergence Problem}\nNext, we will introduce an effective method for solving OTD, and add regularization to the original problem \\ref{eq:OTD}. The idea of adding regularization to the original problem can be traced back to Wilson's research on traffic patterns in 1969. They found that the traffic pattern of a transportation network actually does not meet the optimal solution they obtained through the optimal transport problem. They found that the true traffic pattern is more diffuse than the prediction of the optimal transport problem, which means that the true traffic pattern depends on many paths instead of the optimal results obtained by the optimal transport problem, which depends on only a few paths.\n\nAfter adding entropic regularization, we will get several benefits: firstly, dual problems with entropic regularization are smooth. (can be used as loss function directly). Secondly, the problem solved becomes an unconstrained, convex problem.\n\nLooking back, we let regularized optimal transport as follows:\n\n\\begin{equation}\n  O T_{c, \\lambda}(P, Q)=\\min _{\\pi \\in U(P, Q)} \\int_{a} \\int \\pi(x, y) c(x, y) d x d y+\\varepsilon E(\\pi)\n\\end{equation}\n\nHere $E(\\pi)$ is a regularization term, and commonly used are relative entropy, $L_2$ norm, etc. Taking relative entropy as an example, $E(\\pi)=\\int_{x} \\int_{y} \\pi(x, y) \\log \\left(\\frac{\\pi(x, y)}{P(x) Q(y)}\\right) d x d y$, then formula (13) is:\n\n\\begin{equation}\n\\begin{aligned} O T_{c, \\lambda}(P, Q)=& \\min _{\\pi \\in U(P, Q)} \\int_{x} \\int_{y} \\pi(x, y) c(x, y) d x d y+\\varepsilon \\int_{x} \\int_{y} \\pi(x, y) \\log \\left(\\frac{\\pi(x, y)}{P(x) Q(y)}\\right) d x d y \\\\ & \\text { s.t. } \\int_{y} \\pi(x, y) d y=P(x), \\int_{x} \\pi(x, y) d x=Q(y) \\end{aligned}\n\\end{equation}\n\n  Let $\\psi(x)$ and $\\phi(y)$ be Lagrange multipliers with two constraints, respectively. Then we have\n\n\\begin{equation}\n\\begin{array}{l}{\\min _{\\pi \\geq 0} \\int_{x} \\int_{y}\\left[\\pi(x, y) c(x, y)+\\varepsilon \\pi(x, y) \\log \\left(\\frac{\\pi(x, y)}{P(x) Q(y)}\\right)\\right.} \\\\ {+\\psi(x)(\\pi(x, y)-P(x))+\\phi(y)(\\pi(x, y)-Q(y))] d x d y}\\end{array}\n\\end{equation}\n\n  And because of $\\pi(x,y) \\geq 0$, then there is,\n\n  \\begin{equation}\n    \\pi^{*}(x, y)=P(x) Q(y) \\exp \\left(-\\frac{1}{\\varepsilon}(c(x, y)+\\psi(x)+\\phi(y))+1\\right)\n  \\end{equation}\n\n  Similarly we can get its dual problem\n\n  \\begin{equation}\n  \\max _{\\psi, \\phi} \\int_{x} \\psi(x) P(x) d x+\\int_{y} \\phi(y) Q(y) d y+\\frac{\\varepsilon}{e} \\int_{x} \\int_{y} \\exp \\left(-\\frac{1}{\\varepsilon}(c(x, y)+\\psi(x)+\\phi(y))\\right) \\pi(x, y) d x d y\n\\end{equation}", "meta": {"hexsha": "e8bf9f17c7cba2dc8afaff39b9b5c8bed2022ac3", "size": 10247, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/content-x.tex", "max_stars_repo_name": "CrazyIvanPro/Optimal_Transport", "max_stars_repo_head_hexsha": "aa782820a5ca5a01909ed3c32acbada43f6cfa0f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-09T10:37:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-06T09:24:30.000Z", "max_issues_repo_path": "doc/content-x.tex", "max_issues_repo_name": "CrazyIvanPro/Optimal_Transport", "max_issues_repo_head_hexsha": "aa782820a5ca5a01909ed3c32acbada43f6cfa0f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/content-x.tex", "max_forks_repo_name": "CrazyIvanPro/Optimal_Transport", "max_forks_repo_head_hexsha": "aa782820a5ca5a01909ed3c32acbada43f6cfa0f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-03T17:07:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-03T17:07:01.000Z", "avg_line_length": 80.6850393701, "max_line_length": 1005, "alphanum_fraction": 0.696398946, "num_tokens": 3244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7023539256147994}}
{"text": "\\section{Work and Energy}\n\nWork is the result of a motive cause acting over a path\n\\begin{align*}\n  dW &= \\vec{F}\\cdot d\\vec{s}   & dW &= \\vec{\\tau} \\cdot d\\theta \\hat{q}\\\\\n  dW &= \\vec{F}\\cdot \\vec{v}dt   & dW &= \\vec{\\tau} \\cdot \\vec{\\omega} dt.\n\\end{align*}\nKinetic energy expressions for translational and rotational motion are\n\\begin{align*}\n  K &= \\tfrac{1}{2}mv^2   & K &= \\tfrac{1}{2}I\\omega^2.\n\\end{align*}\nTwo conservative potential energies of interest are gravitational and elastic\n\\begin{align*}\n  U_{\\text{grav}} &= mgh\\\\\n  U_{\\text{el}} &= \\tfrac{1}{2} k x^2.\n\\end{align*}\nConservative potentials yield forces via the spatial gradient (derivative)\n\\begin{equation*}\n  \\vec{F} = -\\nabla U_{\\text{cons}}.\n\\end{equation*}\nSymmetry of physical laws with respect to time begets conservation of\nenergy\n\\begin{equation*}\n  E_1 = E_2.\n\\end{equation*}\nConservation of energy can be written to highlight the work done or the\ninternal energy change\n\\begin{align*}\n  U_1 + K_1 + W_{\\text{other}} &= U_2 + K_2\\\\\n  U_1 + K_1 &= U_2 + K_2 + \\Delta U_{\\text{int}}.\n\\end{align*}\nThe work-energy theorem always relates how much work is required to change the\nkinetic energy \n\\begin{equation*}\n  W = \\Delta K.\n\\end{equation*}\n\n", "meta": {"hexsha": "fc3707fddc5dd5934f5300d6cb72f5cbc90698fa", "size": 1223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_Energy-01.tex", "max_stars_repo_name": "tcburt/hodudodi", "max_stars_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_Energy-01.tex", "max_issues_repo_name": "tcburt/hodudodi", "max_issues_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-18T22:55:02.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-18T23:01:00.000Z", "max_forks_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_Energy-01.tex", "max_forks_repo_name": "tcburt/hodudodi", "max_forks_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.1842105263, "max_line_length": 78, "alphanum_fraction": 0.6843826656, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.7023058137913962}}
{"text": "\\section{Theory}\n\n% Combinatorics {{{\n\\Section{Combinatorics}\n\n\\Topic{Sums}\n\n\\begin{tabular}{l l}\n    $\\sum_{k=0}^n k = n(n+1)/2$\t\t& ${n \\choose k} = \\frac{n!}{(n-k)!k!}$ \\\\\n    $\\sum_{k=a}^b k = (a+b)(b-a+1)/2$   & ${n \\choose k} = {n-1 \\choose k} + {n-1 \\choose k-1}$ \\\\\n    $\\sum_{k=0}^n k^2 = n(n+1)(2n+1)/6$ & ${n+1 \\choose k} = \\frac{n+1}{n-k+1} {n \\choose k}$   \\\\\n    $\\sum_{k=0}^n k^3 = n^2(n+1)^2/4$   & ${n \\choose k+1} = \\frac{n-k}{k+1} {n \\choose k}$     \\\\\n    $\\sum_{k=0}^n k^4 = (6n^5 + 15n^4 + 10n^3 - n)/30$  & ${n \\choose k} = \\frac{n}{n-k} {n-1 \\choose k}$       \\\\\n    $\\sum_{k=0}^n k^5 = (2n^6 + 6n^5 + 5n^4 - n^2)/12$  & ${n \\choose k} = \\frac{n-k+1}{k} {n \\choose k-1}$     \\\\\n    $\\sum_{k=0}^n x^k = (x^{n+1} - 1)/(x - 1)$  & $12! \\approx 2^{28.8}$ \\\\\n    $\\sum_{k=0}^n kx^k = (x - (n+1)x^{n+1} + nx^{n+2})/(x-1)^2$\t& $20! \\approx 2^{61.1}$ \\\\\n    $1 + x + x^2 + \\dots = 1 / (1 - x)$\n\\end{tabular}\n\n%$(x+a)^{-n} = \\sum_{k=0}^{\\infty} {-n \\choose k} x^k a^{-n-k}$ \\\\\n%$(x+y)^z = \\sum_{k=0}^{\\infty} {z \\choose k} x^k y^{z-k}$,\\\\\n%with ${z \\choose k} = \\frac{z\\dots(z-k+1)}{k!}$.\n\n\\Topic{Binomial coefficients}\n\n\\iffalse\n\\begin{tabular}{r|rrrrrrrrrrrrr}\n    & $0$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ & $7$ & $8$ & $9$ & $10$ & $11$ & $12$ \\\\\n    \\hline\n    $0$ & $1$\\\\\n    $1$ & $1$ & $1$\\\\\n    $2$ & $1$ & $2$ & $1$\\\\\n    $3$ & $1$ & $3$ & $3$ & $1$\\\\\n    $4$ & $1$ & $4$ & $6$ & $4$ & $1$\\\\\n    $5$ & $1$ & $5$ & $10$ & $10$ & $5$ & $1$\\\\\n    $6$ & $1$ & $6$ & $15$ & $20$ & $15$ & $6$ & $1$\\\\\n    $7$ & $1$ & $7$ & $21$ & $35$ & $35$ & $21$ & $7$ & $1$\\\\\n    $8$ & $1$ & $8$ & $28$ & $56$ & $70$ & $56$ & $28$ & $8$ & $1$\\\\\n    $9$ & $1$ & $9$ & $36$ & $84$ & $126$ & $126$ & $84$ & $36$ & $9$ & $1$\\\\\n    $10$ & $1$ & $10$ & $45$ & $120$ & $210$ & $252$ & $210$ & $120$ & $45$ & $10$ & $1$\\\\\n    $11$ & $1$ & $11$ & $55$ & $165$ & $330$ & $462$ & $462$ & $330$ & $165$ & $55$ & $11$ & $1$\\\\\n    $12$ & $1$ & $12$ & $66$ & $220$ & $495$ & $792$ & $924$ & $792$ & $495$ & $220$ & $66$ & $12$ & $1$ \\\\\n    \\hline\n    & $0$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ & $7$ & $8$ & $9$ & $10$ & $11$ & $12$\n\\end{tabular}\n\\fi\n\nNumber of ways to pick a multiset of size $k$ from $n$ elements: ${n+k-1 \\choose k}$ \\\\\nNumber of $n$-tuples of non-negative integers with sum $s$:\n${{s+n-1} \\choose {n-1}}$, at most $s$: ${{s + n} \\choose {n}}$ \\\\\nNumber of $n$-tuples of positive integers with sum $s$:\n${{s-1} \\choose {n-1}}$ \\\\\nNumber of lattice paths from $(0,0)$ to $(a,b)$, restricted to east and north\nsteps: ${a+b \\choose a}$\n\n\\Topic{Multinomial theorem}.\n$(a_1+\\dots+a_k)^n = \\sum {n \\choose n_1,\\dots,n_k} a_1^{n_1} \\dots a_k^{n_k}$,\nwhere $n_i \\ge 0$ and $\\sum n_i=n$. \\\\\n$${n \\choose n_1,\\dots,n_k} = M(n_1,\\dots,n_k) = \\frac{n!}{n_1! \\dots n_k!}$$\n$$M(a,\\dots,b,c,\\dots) = M(a+\\dots+b,c,\\dots) M(a,\\dots,b)$$\n\n\\Topic{Catalan numbers}.\n$C_n = \\frac{1}{n+1} {2n \\choose n}$.\n\\quad $C_0=1$, $C_n=\\sum_{i=0}^{n-1} C_i C_{n-1-i}$.\n\\quad $C_{n+1} = C_n \\frac{4n+2}{n+2}$. \\\\\n$C_0, C_1, \\ldots = 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796,\n\t\t58786, 208012, 742900, \\ldots$ \\\\\n%\\quad GF: $\\frac{1-\\sqrt{1-4x}}{2x}=\\sum_{n=0}^{\\infty} C_n x^n$. \\\\\n$C_n$ is the number of:\nproperly nested sequences of $n$ pairs of parentheses;\nrooted ordered binary trees with $n+1$ leaves;\ntriangulations of a convex $(n+2)$-gon.\n\n\\Topic{Derangements}.\nNumber of permutations of $n=0,1,2,\\dots$ elements without fixed points is\n$1, 0, 1, 2, 9, 44, 265, 1854, 14833, \\dots$\nRecurrence: $D_n = (n-1)(D_{n-1} + D_{n-2}) = n D_{n-1} + (-1)^n$.\nCorollary: number of permutations with exactly $k$ fixed points is ${n \\choose k} D_{n-k}$.\n\n\\Topic{Stirling numbers of $1^{st}$ kind}.\n$s_{n,k}$ is $(-1)^{n-k}$ times the number of permutations of $n$ elements with\nexactly $k$ permutation cycles.\n$|s_{n,k}| = |s_{n-1,k-1}| + (n-1) |s_{n-1,k}|$. \\quad\n$\\sum_{k=0}^n s_{n,k}\\,x^k = x^{\\underline n}$\n\n% Number of permutations of $n$ elements with exactly $k$ cycles,\n% all of length $\\ge r$: \\\\\n% $d_r(n,k) = (n-1) d_r(n-1,k) + (n-1)^{\\underline {r-1}}\\ d_r(n-r,k-1),\n% \\quad d_r(n,k)=0 $ for $ n\\le kr-1, \\quad d_r(n,1)=(n-1)!$.\n\n\\Topic{Stirling numbers of $2^{nd}$ kind}.\n$S_{n,k}$ is the number of ways to partition a set of $n$ elements into\nexactly $k$ non-empty subsets.\n$S_{n,k} = S_{n-1,k-1} + k S_{n-1,k}$.\n$S_{n,1} = S_{n,n} = 1$.\n$x^n = \\sum_{k=0}^n S_{n,k}\\,x^{\\underline k}$\n\n\\Topic{Bell numbers}.\n$B_n$ is the number of partitions of $n$ elements.\n$B_0, \\ldots = 1,1,2,5,15,52,203,\\ldots$ \\\\\n$B_{n+1} = \\sum_{k=0}^n {n \\choose k} B_k = \\sum_{k=1}^n S_{n,k}$.\nBell triangle: $B_r=a_{r,1}=a_{r-1,r-1}$, $a_{r,c}=a_{r-1,c-1}+a_{r,c-1}$.\n%Bell triangle: 1, 1 2, 2 3 5, 5 7 10 15, 15 20 27 37 52, (last) ... (left + left above).\n\n\\Topic{Bernoulli numbers}.\n%GF: $\\frac{x}{e^x - 1} = \\sum_{n=0}^{\\infty} B_n \\frac{x^n}{n!}$. \\quad\n$\\sum_{k=0}^{m-1} k^n =\n\\frac{1}{n+1} \\sum_{k=0}^n {n+1 \\choose k} B_k m^{n+1-k}$. \\\\\n$\\sum_{j=0}^m {m+1 \\choose j} B_j = 0$.\n\\quad $B_0=1$, $B_1=-\\frac{1}{2}$. $B_n=0$, for all odd $n \\ne 1$.\n\n%\\Topic{Pentagonal theorem}.\n%$\\prod_{k=1}^{\\infty} (1-x^k) = \\sum_{n=-\\infty}^{\\infty} (-1)^n x^{n(3n+1)/2}$.\n%$\\sum_{n=0}^{\\infty}p(n) x^n = \\prod_{k=1}^{\\infty} \\left(\\frac{1}{1-x^k}\\right) = (\\sum x^i)(\\sum x^{2i})(\\sum x^{3i}) \\dots$ \\\\\n%$p(0) = 1$, $p(n) - p(n-1) - p(n-2) + p(n-5) + p(n-7) - \\dots = 0$ ($+,+,-,-$ goes on; same for $s(n)$, but $s(0)\\to n$.)\n\n\\Topic{Eulerian numbers}.\n$E(n,k)$ is the number of permutations with exactly\n$k$ descents ($i: \\pi_i < \\pi_{i+1}$) /\nascents ($\\pi_i > \\pi_{i+1}$) /\nexcedances ($\\pi_i > i$) /\n$k+1$ weak excedances ($\\pi_i \\ge i$). \\\\\nFormula: $E(n,k)=(k+1)E(n-1,k)+(n-k)E(n-1,k-1)$. \\quad\n$x^n = \\sum_{k=0}^{n-1} E(n,k) {x+k \\choose n}$.\n\n\\Topic{Burnside's lemma}.\nThe number of orbits under group $G$'s action on set $X$:\\\\\n$|X/G| = \\frac{1}{|G|} \\sum_{g \\in G} |X_g|$,\nwhere $X_g=\\{ x \\in X: g(x)=x \\}$. (``Average number of fixed points.'') \\\\\nLet $w(x)$ be weight of $x$'s orbit. Sum of all orbits' weights:\n$\\sum_{o \\in X/G} w(o) = \\frac{1}{|G|} \\sum_{g \\in G} \\sum_{x \\in X_g} w(x)$.\n\n%\\Topic{Number of $k$-ary necklaces}.\n%$\\frac{1}{n}\\sum_{d|n} \\phi(\\frac{n}{d}) k^d$. \\\\\n%\\Topic{Number of Lyndon words} (aperiodic necklaces).\n%$\\frac{1}{n}\\sum_{d|n} \\mu(\\frac{n}{d}) k^d$.\n\n%De Bruijn sequences over alphabet of size $k$, containing all $n$-substrings.\n%Length: $n^k$. Number: ${k!}^{k^{n-1}} / k^n$.\n\n% }}}\n\n% Number Theory {{{\n\\Section{Number Theory}\n\n\\Topic{Linear diophantine equation}. $ax+by=c$.\nLet $d=\\gcd(a,b)$. A solution exists iff $d|c$.\nIf $(x_0,y_0)$ is any solution, then all solutions are given by\n$(x,y) = (x_0 + \\frac{b}{d}t, y_0 - \\frac{a}{d}t)$, $t \\in {\\mathbb Z}$.\nTo find some solution $(x_0, y_0)$, use extended GCD to solve\n$ax_0 + by_0 = d = \\gcd(a, b)$, and multiply its solutions by $\\frac{c}{d}$.\n\nLinear diophantine equation in $n$ variables:\n$a_1 x_1 + \\dots + a_n x_n = c$ has solutions iff $\\gcd(a_1, \\dots, a_n) | c$.\nTo find some solution, let $b=\\gcd(a_2, \\dots, a_n)$,\nsolve $a_1 x_1 + by = c$, and iterate with $a_2 x_2 + \\dots = y$.\n\n\\Topic{Extended GCD}\n\\begin{verbatim}\n// Finds g = gcd(a,b) and x, y such that ax+by=g.\n// Bounds: |x|<=b+1, |y|<=a+1.\nvoid gcdext(int &g, int &x, int &y, int a, int b)\n{ if (b == 0) { g = a; x = 1; y = 0; }\n  else        { gcdext(g, y, x, b, a % b); y = y - (a / b) * x; } }\n\\end{verbatim}\n\nMultiplicative inverse of $a$ modulo $m$:\n$x$ in $ax + my = 1$, or $a^{\\phi(m)-1} \\pmod{m}$.\n\n\\Topic{Chinese Remainder Theorem}.\nSystem $x \\equiv a_i \\pmod{m_i}$ for $i=1,\\dots,n$, with\npairwise relatively-prime $m_i$ has a unique solution modulo $M = m_1 m_2 \\dots m_n$:\n$x = a_1 b_1 \\frac{M}{m_1} + \\dots + a_n b_n \\frac{M}{m_n} \\pmod{M}$,\nwhere $b_i$ is modular inverse of $\\frac{M}{m_i}$ modulo $m_i$.\n\n%\\Topic{Generalized CRT}.\nSystem $x \\equiv a \\pmod{m}$, $x \\equiv b \\pmod{n}$ has solutions\niff $a \\equiv b \\pmod{g}$, where $g=\\gcd(m,n)$.\nThe solution is unique modulo $L=\\frac{mn}{g}$, and equals:\n$x \\equiv a + T(b-a) m/g \\equiv b + S(a-b) n/g \\pmod{L}$,\nwhere $S$ and $T$ are integer solutions of $mT + nS = \\gcd(m,n)$.\n\n\\Topic{Prime-counting function}. $\\pi(n) = |\\{p \\le n : p \\hbox{ is prime}\\}|$.\n$n/\\ln(n) < \\pi(n) < 1.3 n/\\ln(n)$.\n$\\pi(1000) = 168$, $\\pi(10^6) = 78498$, $\\pi(10^9) = 50\\ 847\\ 534$.\n\\quad $n$-th prime $\\approx n \\ln n$.\n\n\\Topic{Miller-Rabin's primality test}.\nGiven $n = 2^r s + 1$ with odd $s$, and a random integer $1 < a < n$. \\\\\nIf $a^s \\equiv 1 {\\pmod n}$ or $a^{2^j s} \\equiv -1 {\\pmod n}$ for some\n$0 \\le j \\le r-1$, then $n$ is a probable prime.\nWith bases 2, 7 and 61, the test indentifies all composites below $2^{32}$.\nProbability of failure for a random $a$ is at most 1/4.\n\n\\Topic{Pollard-$\\rho$}.\nChoose random $x_1$, and let $x_{i+1} = x_i^2 - 1 \\pmod{n}$.\nTest $\\gcd(n, x_{2^k+i} - x_{2^k})$ as possible $n$'s factors for $k=0,1,\\ldots$\nExpected time to find a factor: $O(\\sqrt{m})$, where $m$ is smallest\nprime power in $n$'s factorization.\nThat's $O(n^{1/4})$ if you check $n = p^k$ as a special case before factorization.\n\n\\Topic{Fermat primes}.  A Fermat prime is a prime of form $2^{2^n}+1$.\nThe only known Fermat primes are 3, 5, 17, 257, 65537.\nA number of form $2^n+1$ is prime only if it is a Fermat prime.\n\n%\\Topic{Mersenne primes}.  A Mersenne prime is a prime of form $2^n-1$.\n%Known Mersenne primes correspond to (necessarily prime) indexes\n%2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279,\n%2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937,\n%21701, 23209, 44497, 86243, 110503, 132049, 216091,\n%756839, 859433, 1257787, 1398269, 2976221, 3021377,\n%6972593, 13466917.\n\n\\Topic{Perfect numbers}.  $n>1$ is called perfect if it equals\nsum of its proper divisors and $1$.  Even $n$ is perfect iff $n = 2^{p-1} (2^p - 1)$\nand $2^p - 1$ is prime (Mersenne's). No odd perfect numbers are yet found.\n\n\\Topic{Carmichael numbers}.\nA positive composite $n$ is a Carmichael number\n($a^{n-1} \\equiv 1 \\pmod{n}$ for all $a$: $\\gcd(a,n)=1$),\niff $n$ is square-free, and for all prime divisors $p$ of $n$, $p-1$ divides $n-1$.\n\n\\Topic{Number/sum of divisors}.\n$\\tau(p_1^{a_1} \\dots p_k^{a_k}) = \\prod_{j=1}^k (a_j+1)$. \\quad\n$\\sigma(p_1^{a_1} \\dots p_k^{a_k}) = \\prod_{j=1}^k \\frac{p_j^{a_j+1}-1}{p_j-1}$.\n\n\\Topic{Euler's phi function}.\n$\\phi(n)=|\\{m \\in {\\mathbb N}, m \\le n, \\gcd(m, n) = 1 \\}|$. \\\\\n$\\phi(mn) = \\frac{\\phi(m) \\phi(n) \\gcd(m,n)}{\\phi(\\gcd(m,n))}$. \\quad\n$\\phi(p^a) = p^{a-1} (p-1)$. \\quad\n$\\sum_{d|n} \\phi(d) = \\sum_{d|n} \\phi(\\frac{n}{d}) = n$.\n\n%\\Topic{Fermat's theorem}.  $a^p \\equiv a \\pmod{p}$ if $p$ is prime. \\\\\n%For any polynomial $f(x)$ with integer coefficients and prime $p$,\n%$f(x)^{p^n} \\equiv f(x^{p^n}) \\pmod{p}$\n\\Topic{Euler's theorem}. $a^{\\phi(n)} \\equiv 1\\pmod{n}$, if $\\gcd(a,n)=1$. \\\\\n\\Topic{Wilson's theorem}. $p$ is prime iff $(p - 1)! \\equiv -1 \\pmod p$.\n\n\\Topic{Mobius function}.\n$\\mu(1) = 1$. $\\mu(n) = 0$, if $n$ is not squarefree.\n$\\mu(n) = (-1)^s$, if $n$ is the product of $s$ distinct primes.\nLet $f$, $F$ be functions on positive integers.\nIf for all $n \\in N$, $F(n)=\\sum_{d|n} f(d)$, then $f(n) = \\sum_{d|n} \\mu(d) F(\\frac{n}{d})$,\nand vice versa. \\quad\n$\\phi(n) = \\sum_{d|n} \\mu(d) \\frac{n}{d}$.\n\\quad $\\sum_{d|n} \\mu(d) = 1$. \\\\\nIf $f$ is multiplicative, then $\\sum_{d|n} \\mu(d) f(d) = \\prod_{p|n}(1-f(p))$,\n$\\sum_{d|n} \\mu(d)^2 f(d) = \\prod_{p|n} (1+f(p))$.\n\n\\Topic{Legendre symbol}. If $p$ is an odd prime, $a \\in {\\mathbb Z}$, then\n$\\left(\\frac{a}{p}\\right)$ equals $0$, if $p | a$; $1$ if $a$ is a quadratic\nresidue modulo $p$; and $-1$ otherwise.\nEuler's criterion:\n$\\left(\\frac{a}{p}\\right)=a^{\\left(\\frac{p-1}{2}\\right)} \\pmod p$. \\\\\n%$\\left(\\frac{a}{p}\\right) \\left(\\frac{b}{p}\\right) = \\left(\\frac{ab}{p}\\right)$\n%Law of Quadratic Reciprocity: for any distinct odd primes $p$ and $q$,\n%$\\left(\\frac{p}{q}\\right) \\left(\\frac{q}{p}\\right) = (-1)^{\\frac{p-1}{2} \\cdot \\frac{q-1}{2}}$\n\\Topic{Jacobi symbol}.  %Generalization of Legendre's symbol to any odd modulus. \\\\\nIf $n=p_1^{a_1} \\cdots p_k^{a_k}$ is odd, then\n$\\left(\\frac{a}{n}\\right) = \\prod_{i=1}^k \\left(\\frac{a}{p_i}\\right)^{k_i}$.\n\n%\\Topic{Kronecker symbol}.\n%Let $a$ be a positive integer, which is not a perfect square and\n%$a \\equiv 0$ or $1 {\\pmod 4}$. \\\\\n%$\\left(\\frac{a}{2}\\right) = \\{ 1$, if $a \\equiv 1 {\\pmod 8}$;\n%$-1$, if $a \\equiv 5 {\\pmod 8} \\}$. \\\\\n%$\\left(\\frac{a}{n}\\right) = \\prod_{j=1}^k p_j^{k_j}$,\n%if gcd$(a,n) \\ne 1$ and $n=\\prod p_i^{k_i}$.\n%$\\left(\\frac{a}{n}\\right)$ equals Jacobi symbol otherwise.\n\n\\Topic{Primitive roots}.  If the order of $g$ modulo $m$ (min $n>0$:\n$g^n \\equiv 1 \\pmod{m}$) is $\\phi(m)$, then $g$ is called a primitive root.\nIf $Z_m$ has a primitive root, then it has $\\phi(\\phi(m))$ distinct primitive\nroots. $Z_m$ has a primitive root iff $m$ is one of $2$, $4$,\n$p^k$, $2p^k$, where $p$ is an odd prime.\nIf $Z_m$ has a primitive root $g$, then for all $a$ coprime to $m$,\nthere exists unique integer $i=\\text{ind}_g(a)$ modulo $\\phi(m)$,\nsuch that $g^i \\equiv a \\pmod{m}$.\n$\\text{ind}_g(a)$ has logarithm-like properties:\n$\\text{ind}(1) = 0$, $\\text{ind}(ab) = \\text{ind}(a) + \\text{ind}(b)$.\n\nIf $p$ is prime and $a$ is not divisible by $p$, then congruence\n$x^n \\equiv a \\pmod{p}$ has $\\gcd(n, p-1)$ solutions if\n$a^{(p-1)/\\gcd(n,p-1)} \\equiv 1 \\pmod{p}$, and no solutions otherwise.\n(Proof sketch: let $g$ be a primitive root, and\n$g^i \\equiv a \\pmod{p}$, $g^u \\equiv x \\pmod{p}$.\n$x^n \\equiv a \\pmod{p}$ iff $g^{nu} \\equiv g^i \\pmod{p}$ iff $nu \\equiv i \\pmod{p}$.)\n\n\\Topic{Discrete logarithm problem}.  Find $x$ from $a^x \\equiv b \\pmod{m}$.\nCan be solved in $O(\\sqrt{m})$ time and space with a meet-in-the-middle trick.\nLet $n = \\lceil \\sqrt{m} \\rceil$, and $x = ny - z$.\nEquation becomes $a^{ny} \\equiv b a^z \\pmod{m}$.  Precompute all values that\nthe RHS can take for $z = 0, 1, \\dots, n-1$, and brute force $y$ on the LHS,\neach time checking whether there's a corresponding value for RHS.\n\n\\Topic{Pythagorean triples}.  Integer solutions of $x^2 + y^2 = z^2$\nAll relatively prime triples are given by:\n$x=2mn, y=m^2-n^2, z=m^2+n^2$ where $m>n, \\gcd(m,n)=1$ and $m \\not\\equiv n \\pmod{2}$.\nAll other triples are multiples of these.\nEquation $x^2 + y^2 = 2z^2$ is equivalent to $(\\frac{x+y}{2})^2 + (\\frac{x-y}{2})^2 = z^2$.\n\n\\Topic{Postage stamps/McNuggets problem}.  Let $a$, $b$ be relatively-prime integers.\nThere are exactly $\\frac{1}{2}(a-1)(b-1)$ numbers \\emph{not} of form $ax+by$ ($x,y \\ge 0$),\nand the largest is $(a-1)(b-1)-1 = ab - a - b$.\n\n\\Topic{Fermat's two-squares theorem}.  Odd prime $p$ can be represented\nas a sum of two squares iff $p \\equiv 1 {\\pmod 4}$.\nA product of two sums of two squares is a sum of two squares.\nThus, $n$ is a sum of two squares iff every prime of\nform $p=4k+3$ occurs an even number of times in $n$'s factorization.\n\n\\Topic{RSA}. Let $p$ and $q$ be random distinct large primes, $n = pq$.\nChoose a small odd integer $e$, relatively prime to $\\phi(n) = (p-1)(q-1)$,\nand let $d = e^{-1} \\pmod{\\phi(n)}$. Pairs $(e,n)$ and $(d,n)$ are\nthe public and secret keys, respectively.\nEncryption is done by raising a message $M \\in Z_n$ to the power $e$ or $d$,\nmodulo $n$.\n\n% }}}\n\n% String Algorithms {{{\n\n\\Section{String Algorithms}\n\n\\Topic{Burrows-Wheeler inverse transform}.\nLet $B[1..n]$ be the input (last column of sorted matrix of string's rotations.)\nGet the first column, $A[1..n]$, by sorting $B$.\nFor each $k$-th occurence of a character $c$ at index $i$ in $A$,\nlet $next[i]$ be the index of corresponding $k$-th occurence of $c$ in $B$.\nThe $r$-th fow of the matrix is $A[r]$, $A[next[r]]$, $A[next[next[r]]]$, ...\n\n\\Topic{Huffman's algorithm}.  Start with a forest, consisting of isolated\nvertices.  Repeatedly merge two trees with the lowest weights.\n% }}}\n\n% Graph Theory {{{\n\\Section{Graph Theory}\n\n\\Topic{Euler's theorem}. For any planar graph, $V - E + F = 1 + C$,\nwhere $V$ is the number of graph's vertices, $E$ is the number of edges,\n$F$ is the number of faces in graph's planar drawing, and $C$ is the number\nof connected components.  Corollary: $V - E + F = 2$ for a 3D polyhedron.\n\n%\\Topic{Schlafli's}. A convex polyhedron in $R^n$, which has $N_0$ vertices, $N_1$ edges,\n%$N_i$ $i$-dimensional faces, satisfies: $N_0-N_1+N_2-\\dots=1-(-1)^n$.\n\n\\Topic{Vertex covers and independent sets}.\nLet $M$, $C$, $I$ be a max matching, a min vertex cover, and a max independent set.\nThen $|M| \\le |C| = N - |I|$, with equality for bipartite graphs.\nComplement of an MVC is always a MIS, and vice versa.\nGiven a bipartite graph with partitions $(A, B)$, build a network:\nconnect source to $A$, and $B$ to sink with edges of capacities, equal to\nthe corresponding nodes' weights, or $1$ in the unweighted case.\nSet capacities of the original graph's edges to the infinity.\nLet $(S,T)$ be a minimum $s$-$t$ cut.\nThen a maximum(-weighted) independent set is $I = (A \\cap S) \\cup (B \\cap T)$,\nand a minimum(-weighted) vertex cover is $C = (A \\cap T) \\cup (B \\cap S)$.\n\n\\Topic{Matrix-tree theorem}.\nLet matrix $T = [t_{ij}]$, where $t_{ij}$ is the number of multiedges\nbetween $i$ and $j$, for $i \\ne j$, and $t_{ii} = -\\mbox{deg}_i$.\nNumber of spanning trees of a graph is equal to the determinant of\na matrix obtained by deleting any $k$-th row and $k$-th column from $T$.\n%If $G$ is a multigraph and $e$ is an edge of $G$, then the number $\\tau(G)$ of\n%spanning trees of $G$ satisfies recurrence $\\tau(G) = \\tau(G-e) + \\tau(G/e)$,\n%when $G-e$ is the multigraph obtained by deleting $e$, and $G/e$ is\n%the contraction of $G$ by $e$ (multiple edges arising from the contraction\n%are preserved.)\n\n\\Topic{Euler tours}.\nEuler tour in an undirected graph exists iff the graph is connected and each\nvertex has an even degree.  Euler tour in a directed graph exists iff in-degree\nof each vertex equals its out-degree, and underlying undirected graph is connected.\n%Open Euler path exists if it's possible to make the graph Eulerian by adding a single edge.\nConstruction:\n\\vspace{-5mm}\n\\begin{verbatim}\n    doit(u):\n      for each edge e = (u, v) in E, do: erase e, doit(v)\n      prepend u to the list of vertices in the tour\n\\end{verbatim}\n\\vspace{-2mm}\n\n\\Topic{Stable marriages problem}.\nWhile there is a free man $m$: let $w$ be the most-preferred woman to whom he\nhas not yet proposed, and propose $m$ to $w$. If $w$ is free, or is engaged to someone whom\nshe prefers less than $m$, match $m$ with $w$, else deny proposal.\n\n\\Topic{Stoer-Wagner's min-cut algorithm}.\nStart from a set $A$ containing an arbitrary vertex.\nWhile $A \\ne V$, add to $A$ the most tightly connected vertex\n($z \\notin A$ such that $\\sum_{x \\in A} w(x, z)$ is maximized.)\nStore cut-of-the-phase (the cut between the last added vertex and rest of\nthe graph), and merge the two vertices added last.  Repeat until the graph\nis contracted to a single vertex.  Minimum cut is one of the cuts-of-the-phase.\n\n\\Topic{Tarjan's offline LCA algorithm}. (Based on DFS and union-find structure.)\n\\begin{verbatim}\n    DFS(x):\n      ancestor[Find(x)] = x\n      for all children y of x:\n         DFS(y); Union(x, y); ancestor[Find(x)] = x\n      seen[x] = true\n      for all queries {x, y}:\n        if seen[y] then output \"LCA(x, y) is ancestor[Find(y)]\"\n\\end{verbatim}\n\n\\Topic{Strongly-connected components}. Kosaraju's algorithm. \\\\\n1. Let $G^T$ be a transpose $G$ (graph with reversed edges.) \\\\\n1. Call DFS($G^T$) to compute finishing times $f[u]$ for each vertex $u$. \\\\\n3. For each vertex $u$, in the order of decreasing $f[u]$, perform DFS($G$, $u$). \\\\\n4. Each tree in the 3rd step's DFS forest is a separate SCC.\n\n\\Topic{2-SAT}. Build an implication graph with 2 vertices for each\nvariable -- for the variable and its inverse; for each clause $x \\lor y$\nadd edges $({\\overline x}, y)$ and $({\\overline y}, x)$.\nThe formula is satisfiable iff $x$ and ${\\overline x}$ are in distinct SCCs,\nfor all $x$. To find a satisfiable assignment, consider the graph's SCCs\nin topological order from sinks to sources (i.e. Kosaraju's last step), assigning `true' to\nall variables of the current SCC (if it hasn't been previously\nassigned `false'), and `false' to all inverses.\n\n\\Topic{Randomized algorithm for non-bipartite matching}.\nLet $G$ be a simple undirected graph with even $|V(G)|$.\nBuild a matrix $A$, which for each edge $(u,v) \\in E(G)$ has\n$A_{i,j}=x_{i,j}$, $A_{j,i}=-x_{i,j}$, and is zero elsewhere.\nTutte's theorem: $G$ has a perfect matching iff $\\det G$ (a multivariate\npolynomial) is identically zero.\nTesting the latter can be done by computing the determinant for\na few random values of $x_{i,j}$'s over some field.\n(e.g. $Z_p$ for a sufficiently large prime $p$)\n\n\\Topic{Prufer code of a tree}.\nLabel vertices with integers $1$ to $n$.\nRepeatedly remove the leaf with the smallest label, and output its only\nneighbor's label, until only one edge remains. The sequence has\nlength $n-2$.  Two isomorphic trees have the same sequence, and every sequence\nof integers from $1$ and $n$ corresponds to a tree.\nCorollary: the number of labelled trees with $n$ vertices is $n^{n-2}$.  % Cayley's theorem\n\n\\Topic{Erdos-Gallai theorem}.\nA sequence of integers $\\{ d_1, d_2, \\dots, d_n \\}$,\nwith $n-1 \\ge d_1 \\ge d_2 \\ge \\dots \\ge d_n \\ge 0$ is a degree sequence\nof some undirected simple graph iff $\\sum d_i$ is even and\n$d_1 + \\dots + d_k \\le k(k-1) + \\sum_{i=k+1}^n \\min(k, d_{i})$\nfor all $k=1,2,\\dots,n-1$.\n\n% }}}\n\n% Games {{{\n\n\\Section{Games}\n\n\\Topic{Grundy numbers}.\nFor a two-player, normal-play (last to move wins) game on a graph $(V,E)$:\n$G(x) = \\mbox{mex}(\\{ G(y) : (x, y) \\in E \\})$,\nwhere $\\mbox{mex}(S) = \\min \\{ n \\ge 0: n \\not\\in S \\}$.\n$x$ is losing iff $G(x) = 0$.\n\n\\Topic{Sums of games}.\n\n\\vspace{-4mm}\n\\begin{itemize}\n  \\item\n    \\emph{Player chooses a game and makes a move in it}.\n    Grundy number of a position is xor of grundy numbers of positions in summed games.\n  \\item\n    \\emph{Player chooses a non-empty subset of games (possibly, all) and makes moves in all of them}.\n    A position is losing iff each game is in a losing position.\n  \\item\n    \\emph{Player chooses a proper subset of games (not empty and not all),\n        and makes moves in all chosen ones.}\n    A position is losing iff grundy numbers of all games are equal.\n  \\item\n    \\emph{Player must move in all games, and loses if can't move in some game}.\n    A position is losing if any of the games is in a losing position.\n\\end{itemize}\n% http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=algorithmGames\n\n\\vspace{-3mm}\n\n\\Topic{Mis\\`{e}re Nim}.\nA position with pile sizes $a_1, a_2, \\dots, a_n \\ge 1$,\nnot all equal to $1$, is losing iff $a_1 \\oplus a_2 \\oplus \\dots \\oplus a_n = 0$\n(like in normal nim.)\nA position with $n$ piles of size $1$ is losing iff $n$ is \\emph{odd}.\n\n% }}}\n\n% Bit Tricks {{{\n\n\\Section{Bit tricks}\nClearing the lowest 1 bit: \\verb$x & (x - 1)$, all trailing 1's: \\verb$x & (x + 1)$ \\\\\nSetting the lowest 0 bit: \\verb$x | (x + 1)$ \\\\\nEnumerating subsets of a bitmask $m$: \\\\\n\\verb|x=0; do { ...; x=(x+1+~m)&m; } while (x!=0);| \\\\\n\\verb$__builtin_ctz/__builtin_clz$ returns the number of trailing/leading zero bits. \\\\\n\\verb$__builtin_popcount(unsigned x)$ counts 1-bits (slower than table lookups). \\\\\nFor 64-bit unsigned integer type, use the suffix `\\verb$ll$', i.e. \\verb$__builtin_popcountll$.\n\n% }}}\n\n% Math {{{\n\\Section{Math}\n\n\\Topic{Stirling's approximation}\n$z! = \\Gamma(z+1) = \\sqrt{2 \\pi}\\ z^{z+1/2}\\ e^{-z}\n(1 + \\frac{1}{12z} + \\frac{1}{288 z^2} - \\frac{139}{51840 z^3} + \\dots)$\n%$\\ln \\Gamma(z) = \\frac{1}{2} \\ln(2 \\pi) + (z - \\frac{1}{2}) \\ln z - z + \\sum_{n=1}^{\\infty} \\frac{B_{2n}}{2n(2n-1)} z^{-(2n-1)}$.\n%$\\sum = \\frac{1}{12 z} - \\frac{1}{360 z^3} + \\frac{1}{1260 z^5} - \\dots$\n\n\\Topic{Taylor series}.\n$f(x) = f(a) + \\frac{x-a}{1!} f'(a) + \\frac{(x-a)^2}{2!} f^{(2)}(a) + \\dots + \\frac{(x-a)^n}{n!} f^{(n)}(a) + \\dots$. \\\\\n$\\sin x = x - \\frac{x^3}{3!} + \\frac{x^5}{5!} - \\frac{x^7}{7!} + \\dots$ \\\\\n$\\ln x = 2(a+\\frac{a^3}{3}+\\frac{a^5}{5}+\\dots)$, where $a=\\frac{x-1}{x+1}$. $\\ln x^2 = 2 \\ln x$. \\\\\n$\\arctan x = x - \\frac{x^3}{3} + \\frac{x^5}{5} - \\frac{x^7}{7} + \\dots$,\n$\\arctan x = \\arctan c + \\arctan \\frac{x-c}{1+xc}$ (e.g c=.2) \\\\\n$\\pi = 4 \\arctan 1$, $\\pi = 6 \\arcsin \\frac{1}{2}$\n\n% }}}\n\n\\Topic{List of Primes}\n\n\\begin{tabular}{l l l l l l l l l l l l}\n    1e5 & 3 & 19 & 43 & 49 & 57 & 69 & 103 & 109 & 129 & 151 & 153 \\\\\n    1e6 & 33 & 37 & 39 & 81 & 99 & 117 & 121 & 133 & 171 & 183 \\\\\n    1e7 & 19 & 79 & 103 & 121 & 139 & 141 & 169 & 189 & 223 & 229 \\\\\n    1e8 & 7 & 39 & 49 & 73 & 81 & 123 & 127 & 183 & 213 \\\\\n\\end{tabular}\n", "meta": {"hexsha": "14616e647e84b4d047eb60549ac7885ef1ce14e5", "size": 24476, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Theory.tex", "max_stars_repo_name": "tulsyan/ACM-ICPC-Handbook", "max_stars_repo_head_hexsha": "fbadfd66017991d264071af3f2fa8e050e4f8e40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2017-12-24T20:00:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-09T14:53:25.000Z", "max_issues_repo_path": "Theory.tex", "max_issues_repo_name": "Zindastart/ACM-ICPC-Handbook", "max_issues_repo_head_hexsha": "fbadfd66017991d264071af3f2fa8e050e4f8e40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Theory.tex", "max_forks_repo_name": "Zindastart/ACM-ICPC-Handbook", "max_forks_repo_head_hexsha": "fbadfd66017991d264071af3f2fa8e050e4f8e40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2017-12-13T14:35:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-24T04:40:32.000Z", "avg_line_length": 46.1811320755, "max_line_length": 130, "alphanum_fraction": 0.6003431933, "num_tokens": 9855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294214513915, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.7021304768616213}}
{"text": "\\section{The Dispersion Counterterm}\n\\label{sec:dispersion-counterterm}\n\nTo evaluate the infinite-volume integral in \\eqref{dispersion-counter-integral}, we rescale the $n$ integration to extract $N$ out of the integral and rescale  $x \\to \\xtilde = 4 \\pi^2  x/(N/2)^2$\n\\begin{align}\\label{eq:rescaled-counterterm-integral}\n    \\int_{-N/2}^{+N/2} \\mathrm{d}^Dn\\; \\PV \\frac{1}{\\tilde K_{nn}^N - x}\n    =\n    4\\pi^2 \\left(\\frac{N}{2}\\right)^{D-2} \\int_{-1}^{+1} \\mathrm{d}^D\\nu\\; \\PV \\frac{1}{4\\sum_{ds} \\gamma^{(\\nstep)}_s \\cos \\pi \\nu s - \\xtilde}\n    \\, ,\n\\end{align}\nwhich is well defined for any dimension if $\\xtilde\\neq0$ and for $\\xtilde=0$ if $D>2$.\nFor $\\xtilde\\leq0$ the sum over dimensions can be isolated by introducing another integral\n\\begin{equation}\n    \\label{eq:dispersion counterterm}\n    \\eqref{rescaled-counterterm-integral}\n    =\n    4 \\pi^2 \\left(\\frac{N}{2}\\right)^{D-2}\\int_{0}^{\\infty} 2y\\; \\mathrm{d}y\\; e^{\\xtilde y^2}\\left(\\int_{-1}^{+1} \\mathrm{d}\\nu\\; e^{-4y^2 \\sum_s \\gamma_s^{(\\nstep)} \\cos \\pi \\nu s}\\right)^D\n\\end{equation}\nwhich can be numerically evaluated.\nThis trick relies on the Laplacian stencil not coupling momenta in different directions \\eqref{kinetic}.\n\nThe counterterm for the leading divergence $\\counterterm_D^{\\dispersion}$ is the $\\xtilde=0$ value.\nFor three dimensions, we show this counterterm and how it differs from the $\\nstep \\to \\infty$ counterterm in \\Figref{nstep counterterm} and provide precise values in table \\tabref{diserpersion-zeta-3d-counterterm-counterterm}.\n\\begin{table}[htb]\n    \\input{section/counterterm/diserpersion-zeta-3d-counterterm-table.tex}\n    \\caption{\n    \t\\label{tab:diserpersion-zeta-3d-counterterm-counterterm}\n\t\tCounter term coefficients for the three-dimensional dispersion zeta function defined in \\eqref{dispersion-zeta-contact}.\n    }\n\\end{table}\n\n\\begin{figure}[htb]\n    \\scalebox{0.9}{\\input{figure/counterterm-nstep.pgf}}\n    \\caption{\n    \tIn the top panel we show the dispersion counterterm $\\counterterm^{\\dispersion}_{3}$ in \\eqref{dispersion-zeta-contact} as a function of $\\nstep$, and the $\\nstep=\\infty$ result, as a dashed line.\n\tIn the bottom panel we show an alternate view into how the counterterm converges to the $\\nstep=\\infty$ value.\n    }\n    \\label{fig:nstep counterterm}\n\\end{figure}\n\nIf we assume $n_{s}=\\infty$ we can obtain analytic solutions when $\\tilde x=0$.  For $D=3$ we find\n\\begin{multline}\n\\counterterm_3^{\\dispersion}=-8 G-4 i \\left\\{2 \\text{Li}_2\\left(1-\\sqrt[4]{-1}\\right)-2 \\text{Li}_2\\left(1+(-1)^{3/4}\\right)+\\text{Li}_2\\left(3 i-2 i\n   \\sqrt{2}\\right)-2 \\text{Li}_2\\left(\\frac{1}{2} \\left((-1-i)+\\sqrt{2}\\right)\\right)\\right.\\\\\n   \\left.+2 \\text{Li}_2\\left(\\frac{1}{2}\n   \\left((-1+i)+\\sqrt{2}\\right)\\right)-2 \\text{Li}_2\\left(\\frac{2}{(1-i)+\\sqrt{2}}\\right)+2\n   \\text{Li}_2\\left(\\frac{2}{(1+i)+\\sqrt{2}}\\right)+2 \\text{Li}_2\\left(\\frac{2 i}{(1+3 i)+(1+2 i)\n   \\sqrt{2}}\\right)\\right.\\\\\n   \\left.-\\text{Li}_2\\left(i \\left(-3+2 \\sqrt{2}\\right)\\right)-2 \\text{Li}_2\\left(\\frac{2}{(3+i)+(2+i)\n   \\sqrt{2}}\\right)\\right\\}+\\pi  \\log \\left(7880+5572 \\sqrt{2}\\right)\\ ,\n   \\end{multline}\nwhere $G$ is Catalan's constant and $\\text{Li}_2$ is a polylogarithm of order 2.  For $D=2$ the dominant $N$ part of~\\eqref{rescaled-counterterm-integral}, after subtracting off the logarithmic singularity in $\\sqrt{x}$, is logarithmic,\n\\begin{equation}\n \\int_{-N/2}^{+N/2} \\mathrm{d}^2n\\; \\PV \\frac{1}{\\bm n^2 - x}-2\\pi\\log\\left(\\sqrt{x}\\right)= 2\\pi\\log\\left(\\frac{N}{2}\\right)-4\\left(G-\\frac{\\pi }{2}\\log(2)\\right)+\\mathcal{O}(N^{-1})=2\\pi\\log\\left(\\counterterm_2^{\\dispersion}\\frac{N}{2}\\right)+\\mathcal{O}(N^{-1})\\ ,\n\\end{equation}\nwith\n\\begin{equation}\n\\counterterm_2^\\dispersion=\\exp\\left(\\log(2)-G\\frac{2}{\\pi}\\right)\\ .\n\\end{equation}\n", "meta": {"hexsha": "42b1371873d7f97d8195707dda0220df1a4da969", "size": 3758, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/luescher-nd/section/counterterm/dispersion.tex", "max_stars_repo_name": "ckoerber/luescher-nd", "max_stars_repo_head_hexsha": "d1bc6bff0c6ee9f4dc0d1d0bb4bcfa842c44cceb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-12T22:19:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-26T14:06:49.000Z", "max_issues_repo_path": "paper/luescher-nd/section/counterterm/dispersion.tex", "max_issues_repo_name": "ckoerber/luescher-nd", "max_issues_repo_head_hexsha": "d1bc6bff0c6ee9f4dc0d1d0bb4bcfa842c44cceb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-12-16T19:49:19.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-02T00:50:31.000Z", "max_forks_repo_path": "paper/luescher-nd/section/counterterm/dispersion.tex", "max_forks_repo_name": "ckoerber/luescher-nd", "max_forks_repo_head_hexsha": "d1bc6bff0c6ee9f4dc0d1d0bb4bcfa842c44cceb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.6333333333, "max_line_length": 267, "alphanum_fraction": 0.6801490154, "num_tokens": 1403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7021304620836938}}
{"text": "\\subsection{Differentiable}\nNow that we have introduced the derivative\nof a function at a point, we can begin to use the adjective \\dfont{differentiable}.\n\n\\begin{definition}{Differentiable at a Point}{DifferentiablePoint}\nA function $f$ is\ndifferentiable at point $a$ if $f'(a)$ exists.\n\\end{definition}\n\n\\begin{definition}{Differentiable on an Interval}{Differentiable}\nA function $f$ is differentiable on an open interval if it is differentiable at every point in the interval.\n\\end{definition}\n\nSometimes one encounters a point in the domain of a function $y=f(x)$ where\nthere is {\\bf no derivative}, because there is no tangent line.  In order\nfor the notion of the tangent line at a point to make sense, the curve must\nbe ``smooth'' at that point.  This means that if you imagine a particle\ntraveling at some steady speed along the curve, then the particle does not\nexperience an abrupt change of direction.  There are two types of\nsituations you should be aware of---corners and cusps---where there's a\nsudden change of direction and hence no derivative.\n\n\\begin{example}{Derivative of the Absolute Value}{DerivativeAbsoluteValue}\nDiscuss the derivative of the absolute value function $y=f(x)=|x|$.\n\\end{example}\n\n\\begin{solution} \nIf $x$ is positive, then this is the function $y=x$, whose derivative is\nthe constant 1.  (Recall that when $y=f(x)=mx+b$, the derivative is the\nslope $m$.)  If $x$ is negative, then we're dealing with the function $y=-x$,\nwhose derivative is the constant $-1$.  If $x=0$, then the function has\na corner, i.e., there is no tangent line.  A tangent line \nwould have to point in the direction of the curve---but there are {\\it\ntwo} directions of the curve that come together at the origin.\n\n$$\\includegraphics[width=2.5in]{images/absvalue}$$\n\nWe can summarize this as\n$$ \ny'=\\left\\{\\begin{array}{rl}\n1, & \\mbox{if $x>0$,}\\\\\n-1, & \\mbox{if $x<0$,}\\\\\n\\hbox{undefined,} & \\mbox{if $x=0$.}\\\\\n\\end{array}\\right.\n$$\nIn particular, the absolute value function $f(x)=|x|$ is \\ifont{not} differentiable at $x=0$.\n\\end{solution}\n\nWe note that the following theorem can be proved using limits.\n\n\\begin{theorem}{Differentiable implies Continuity}{DifferentiableImpliesContinuity}\nIf $f$ is differentiable at $a$, then $f$ is continuous at $a$.\n\\end{theorem}\n\\begin{proof}\nSuppose that $f$ is differentiable at $a.$ That is,%\n\\begin{equation*}\n\tf^{\\prime }\\left( a\\right) =\\lim_{h\\rightarrow 0}\\frac{f\\left( a+h\\right)\n\t\t-f\\left( a\\right) }{h}\n\\end{equation*}%\nexists. At this stage, we find it convenient to write this limit in an\nalternative form so that its connection with continuity can become more\neasily seen. If we let $x=a+h,$ then $h=x-a.$ Furthermore, $h\\rightarrow 0$\nis equivalent to $x\\rightarrow a.$ So,%\n\\begin{equation*}\n\tf^{\\prime }\\left( a\\right) =\\lim_{x\\rightarrow a}\\frac{f\\left( x\\right)\n\t\t-f\\left( a\\right) }{x-a}.\n\\end{equation*}%\n(This alternative formulation of the derivative is also standard. We will\nuse it whenever we find it convenient to do so. You should get familiar with\nit.) Continuity at $a$ can now be proved as follows:%\n\\begin{eqnarray*}\n\t\\lim_{x\\rightarrow a}f\\left( x\\right) &=&\\lim_{x\\rightarrow a}\\left( \\frac{%\n\t\tf\\left( x\\right) -f\\left( a\\right) }{x-a}\\cdot \\left( x-a\\right) +f\\left(\n\ta\\right) \\right) \\\\\n\t&=&\\lim_{x\\rightarrow a}\\frac{f\\left( x\\right) -f\\left( a\\right) }{x-a}\\cdot\n\t\\lim_{x\\rightarrow a}\\left( x-a\\right) +\\lim_{x\\rightarrow a}f\\left( a\\right)\n\t\\\\\n\t&=&f^{\\prime }\\left( a\\right) \\cdot \\left( a-a\\right) +f\\left( a\\right) \\\\\n\t&=&f\\left( a\\right).\n\\end{eqnarray*}\n\\end{proof}\n\nHowever, if $f$ is continuous at $a$ it is \\ifont{not} necessarily\ntrue that $f$ is differentiable at $a$.  For example, it was shown\nthat $f(x)=|x|$ is not differentiable at $x=0$ in the previous\nexample, however, one can observe that $f(x)=|x|$ is continuous\neverywhere.\n\n\\begin{example}{Derivative of $\\ds y=x^{2/3}$}{Derivative}\nDiscuss the derivative of the function $\\ds y=x^{2/3}$, shown in\nFigure~\\ref{fig:cusp}. \n\\end{example}\n\n\\begin{solution} \nWe will later see how to compute this\nderivative; for now we use the fact that $\\ds\ny'=(2/3)x^{-1/3}$. Visually this looks much like the absolute value\nfunction, but it technically has a cusp, not a corner. The absolute\nvalue function has no tangent line at 0 because there are (at least)\ntwo obvious contenders---the tangent line of the left side of the\ncurve and the tangent line of the right side.\nThe function $\\ds y=x^{2/3}$ does not have a tangent line at 0, but\nunlike the absolute value function it can be said to have a single\ndirection: as we approach 0 from either side the tangent line becomes\ncloser and closer to a vertical line; the curve is vertical at 0. But\nas before, if you imagine traveling along the curve, an abrupt change\nin direction is required at 0: a full 180 degree turn.  \n\\end{solution}\n\n\\figure\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <2truecm,2truecm>\n\\setplotarea x from -2 to 2, y from 0 to 1.6\n\\axis left shiftedto x=0 ticks numbered from 0 to 1 by 1 /\n\\axis bottom ticks numbered from -2 to 2 by 1 /\n\\setquadratic\n\\plot -2.000 1.587 -1.933 1.552 -1.867 1.516 -1.800 1.480 -1.733 1.443 \n-1.667 1.406 -1.600 1.368 -1.533 1.330 -1.467 1.291 -1.400 1.251 \n-1.333 1.211 -1.267 1.171 -1.200 1.129 -1.133 1.087 -1.067 1.044 \n-1.000 1.000 -0.933 0.955 -0.867 0.909 -0.800 0.862 -0.733 0.813 \n-0.667 0.763 -0.600 0.711 -0.533 0.658 -0.467 0.602 -0.400 0.543 \n-0.333 0.481 -0.267 0.414 -0.200 0.342 -0.133 0.261 -0.067 0.164 \n0.000 0.000 0.067 0.164 0.133 0.261 0.200 0.342 0.267 0.414 \n0.333 0.481 0.400 0.543 0.467 0.602 0.533 0.658 0.600 0.711 \n0.667 0.763 0.733 0.813 0.800 0.862 0.867 0.909 0.933 0.955 \n1.000 1.000 1.067 1.044 1.133 1.087 1.200 1.129 1.267 1.171 \n1.333 1.211 1.400 1.251 1.467 1.291 1.533 1.330 1.600 1.368 \n1.667 1.406 1.733 1.443 1.800 1.480 1.867 1.516 1.933 1.552 \n2.000 1.587   /\n\\endpicture}}\n\\caption{A cusp on $\\ds x^{2/3}$. \\label{fig:cusp}}\n\\endfigure\n\nIn practice we won't worry much about the distinction between these\nexamples; in both cases the function has a ``sharp point'' where there\nis no tangent line and no derivative.", "meta": {"hexsha": "0951d336607aeb2ab032fa6277fd51dca41c0265", "size": 6155, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-derivatives/4-3-1-differentiable.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4-derivatives/4-3-1-differentiable.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4-derivatives/4-3-1-differentiable.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.6014492754, "max_line_length": 108, "alphanum_fraction": 0.714378554, "num_tokens": 2119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.903294206053042, "lm_q1q2_score": 0.7021304609649324}}
{"text": "% -*- root: 00-main.tex -*-\n\\onecolumn\n\\appendix\n\n\\section{Proof of duality between the probabilistic and the presented frameworks}\n\nIn the probabilistic approach to image segmentation, the smoothness constraints\ncan be introduced into the \\gls{map} criterion as a \\gls{mrf}. Accordingly to the\nHammersley-Clifford theorem (\\textbf{FIXME}: citations needed), an \\gls{mrf} can\nbe equivalently characterized by a Gibb's distribution:\n\\begin{equation}\nP(\\mathbf{K})=\\underset{i}{\\prod} Z(U)^{-1}\\,e^{-U(\\mathbf{x}_i \\mid \\beta,K)} = \\mathit{const.}\\,e^{- \\sum\\limits_i \\left( U(\\mathbf{x}_i \\mid \\beta,K) \\right) } \\sim e^{-\\nu_B \\left| K \\right| }.\n\\end{equation}\nThis way, we include the assumption that the total length of the edge set $K$ is small\nand we draw the equivalence with the \\gls{mrf} modeling, for $U(\\mathbf{x}_i \\mid \\beta,K)$\nbeing the Potts model.\n\nIn the probabilistic approach, the underlying concept to segmenting an image is the\nBayes' rule. For a discrete image of $N$ \\revcomment[R\\#3-C10]{voxel}s indexed by $i$, this rule reads as\nfollows:\n\\begin{equation}\nP(K|I)=P(I \\mid K)\\, P(K)=\\underset{i}{\\prod} p (\\mathbf{x}_i | K ) \\, p_i(K).\n\\end{equation}\nThe normalizer probability $P(I)$ has been omitted for simplicity.\n\nIn order to express the likelihood as an absolute energy in our variation framework,\nthe \\textit{log}-likelihood is computed:\n\\begin{equation}\nE(K)= -\\log( P(K|I) ) = \\sum\\limits_k \\int_{\\Omega_k} -\\log p_k(I(\\mathbf{x}),\\mathbf{x}) \\,d\\mathbf{x}+\\nu_B \\left|K\\right|,\n\\end{equation}\nwhere $\\mathbf{s} = I(\\mathbf{x})$, $\\mathbf{s} \\in \\mathbb{R}^C$ (a vector of $C$ scalar features).\nAdditionally, the discrete grid of $N$ \\revcomment[R\\#3-C10]{voxel}s has been converted to a continuous space by assuming\n$d\\mathbf{x}$ as infinitesimal bin size.\n\nTo explicitly define the likelihood, we firstly define the squared \\textit{Mahalanobis distance} that\nis the exponential of a multivariate normal distribution:\n\\begin{equation}\n\\Delta^2_k (\\mathbf{s}) = (\\mathbf{s} - \\boldsymbol{\\mu}_k)^T \\, \\Sigma^{-1}_k \\, (\\mathbf{s} - \\boldsymbol{\\mu}_k).\n\\end{equation}\n\nTherefore, the likelihood is defined as follows:\n\\begin{equation}\np_k(I(\\mathbf{x}),\\mathbf{x}) = p_k(\\mathbf{s},\\mathbf{x})= p_k(\\mathbf{s}) = \\frac{1}{ \\sqrt{(2\\pi)^{C}\\,\\left|\\boldsymbol{\\Sigma}_{k}\\right|}}\\,{e^{\\left(-\\frac{1}{2}  \\Delta^2_k (\\mathbf{s}) \\right)}}.\n\\end{equation}\n\nIntroducing this definition on (14), we have:\n\\begin{equation}\nE(K)= \\sum\\limits_k \\int_{\\Omega_k} -\\log{\\left[ \\frac{1}{ \\sqrt{(2\\pi)^{C}\\,\\left|\\boldsymbol{\\Sigma}_{k}\\right|}}\\,e^{\\left(-\\frac{1}{2}  \\Delta^2_k (\\mathbf{s}) \\right)} \\right] } \\,d\\mathbf{x}+\\nu_B \\left|K\\right|.\n\\end{equation}\n\n\\begin{equation}\nE(K) = \\sum\\limits_k \\int_{\\Omega_k} \\left( \\frac{1}{2} \\log{ \\left( (2\\pi)^{C}\\,\\left|\\boldsymbol{\\Sigma}_{k}\\right| \\right)} + \\frac{1}{2}  \\Delta^2_k (\\mathbf{s}) \\right) \\,d\\mathbf{x}+\\nu_B \\left|K\\right|\n\\end{equation}\n\n\\begin{equation}\nE(K) = \\sum\\limits_k \\left( \\frac{ V_k }{2} \\log{ \\left( (2\\pi)^{C}\\,\\left|\\boldsymbol{\\Sigma}_{k}\\right| \\right)}+ \\frac{1}{2} \\int_{\\Omega_k} \\Delta^2_k (\\mathbf{s}) \\,d\\mathbf{x}+\\nu_B \\left|K\\right| \\right)\n\\end{equation}\n\n{\\color{red} {Using the region descriptors derived in \\autoref{sec:regseg-methods_map}, we propose\nan \\gls{adf}-like, \\gls{acwe}-based, piece-wise constant, image segmentation\nmodel (where the unknown is the deformation field)\n\\cite{chan_active_2001} with the energy functional obtained in\n\\eqref{eq:regseg-final_map_energy}. This inverse problem is ill-posed\n\\cite{bertero_illposed_1988,hadamard_sur_1902}.\nIn order to account for deformation field regularity and to render the\nproblem well-posed, we include limiting and regularization terms into\nthe energy functional \\cite{morozov_linear_1975,tichonov_solution_1963}:\n%\n\\begin{multline}\nE(u) = \\sum\\limits_l \\int_{\\Omega'_l} \\mdist{f}{l} \\,d\\vec{x} \\\\\n+ \\int \\vec{u}^T \\, A \\, \\vec{u} \\, d\\vec{x} + \\int \\tr\\{(\\nabla \\vec{u}^T)^T B (\\nabla \\vec{u}^T)\\} d\\vec{x}\n\\label{eq:regseg-complete_energy}\n\\end{multline}\n%\nThese regularity terms ensure that the segmenting contours in\n\\gls{dwi} space are still close to their native shape. The model\neasily allows to incorporate inhomogeneous and anisotropic\nregularization \\cite{nagel_investigation_1986} to better regularize\nthe \\gls{epi} distortion.}}\n\n\\todo[inline]{this last paragraphs in red color were located a bit\nfurther, but I think we can keep some of the refs and still reproduce\nthe continuous version of the energy functional}\n\n\\section{Extensions}\n\n\\subsubsection{Semi-implicit Euler-forward optimization}\nIt is necessary to discretize $t$ in order to obtain a numerical\nimplementation of the equation \\eqref{eq:regseg-gradient_final}:\n\\begin{align}\n\\frac{\\vec{u}_k^{t+1}-\\vec{u}_k^t}{\\tau} =\n&- \\underset{l,m}{\\sum} \\underset{i}{\\sum}\n\\left[ \\mdist{f_i'}{l} - \\mdist{f_i'}{m}\\right]\n\\psi_k(\\vec{c}_i)\\, \\hat{\\vec{n}}_i \\notag\\\\\n&+2\\, \\boldsymbol{\\alpha} \\vec{u}_k^{t+1}\n-2\\, \\boldsymbol{\\beta} \\Delta \\vec{u}_k^{t+1}.\n\\end{align}\n\nThe associated Euler-Lagrange equation is found as:\n\\begin{equation}\n(\\tau^{-1} +2\\, \\boldsymbol{\\alpha} - 2\\, \\boldsymbol{\\beta} \\Delta )\\, \\vec{u}_k^{t+1} =\n\\tau^{-1} \\vec{u}_k^t - \\frac{\\partial}{\\partial \\vec{u}_k} E_{data}(\\vec{u}_k^t),\n\\end{equation}\nthat is a linear system that we translate into Fourier domain,\nto obtain the next deformation field $\\vec{u}_k^{t+1}$:\n\\begin{multline}\n\\vec{u}_k^{t+1} = \\\\\n \\mathcal{F}^{-1} \\left\\lbrace\n\\frac{\\mathcal{F}\\lbrace \\tau^{-1}\\vec{u}_{k}^{t} - \\underset{l,m}{\\sum} \\underset{i}{\\sum}\n\\left[ \\mdist{f_i'}{l} - \\mdist{f_i'}{m}\\right] \\rbrace}\n     {\\mathcal{F}\\lbrace (\\tau^{-1} +2\\,\\boldsymbol{\\alpha})\\mathcal{I} - 2\\,\\boldsymbol{\\beta} \\Delta ) \\rbrace}\n     \\right\\rbrace\n\\end{multline}\n\nHere, we rewrite the Laplacian as a linear combination of the identity and shift operators:\n\\begin{equation}\n\\Delta = \\sum\\limits_d \\mathcal{S}_d^- + \\mathcal{S}_d^+ - 2 \\mathcal{I}\n\\end{equation}\nwhere $\\mathcal{S}_{d}^{\\pm}$ stands for the forward ($+$) and backward ($-$) shift\noperator along coordinates axis $d$, of which the Fourier transform is found easily as\n\\begin{equation}\n\\mathcal{F}\\{\\mathcal{S}_{d}^{\\pm}\\} = e^{\\pm \\vec{i}\\omega_{d}},\n\\end{equation}\nwhere $\\omega_{d}$ is the normalized pulsation along $d$-direction. Accordingly, the\nFourier transform of the discrete Laplacian is found as\n\\begin{equation}\n\\mathcal{F}\\{\\Delta\\} = \\sum\\limits_d e^{-\\vec{i}\\omega_d } + e^{\\vec{i}\\omega_d } - 2 = \\sum\\limits_d \\left( 2\\cos(\\omega_d) - 2 \\right)\n\\end{equation}\n\nThe remaining transforms are trivial or can be computed using the \\gls{fft}\nas in \\citep{estellers_efficient_2011}.", "meta": {"hexsha": "0e96bd62ee59deb67d09b66e072c3e1e7673539c", "size": 6651, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2015-NeuroImage/08-appendix-01.tex", "max_stars_repo_name": "oesteban/RegSeg-NeuroImage2016", "max_stars_repo_head_hexsha": "434aba23a032a373b287fe72939cbfe4a6caedca", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2015-NeuroImage/08-appendix-01.tex", "max_issues_repo_name": "oesteban/RegSeg-NeuroImage2016", "max_issues_repo_head_hexsha": "434aba23a032a373b287fe72939cbfe4a6caedca", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2015-NeuroImage/08-appendix-01.tex", "max_forks_repo_name": "oesteban/RegSeg-NeuroImage2016", "max_forks_repo_head_hexsha": "434aba23a032a373b287fe72939cbfe4a6caedca", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.7709923664, "max_line_length": 218, "alphanum_fraction": 0.6979401594, "num_tokens": 2311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904955, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7021304533765064}}
{"text": "\\section{Continuity Definition}\r\nWhen we were looking at limits, we noticed that we can't always substitute to find the limit, even if the function is defined there.\r\nIn the example given to show that substitution and the limit can give different results, we saw a special type of function that seemed to have a ``hole'' at the point we were interested in finding the limit of.\r\nThis function is said to be discontinuous at this point, and in this section we'll define when a function is or isn't continuous at a point based on this idea of the limit and substitution giving different values.\r\n\r\n\\begin{definition}\r\n\tLet $f(x)$ be a real-valued function defined over $D \\subseteq \\R$.\r\n\t$f(x)$ is continuous at some point $x = c$ if all of the following hold.\r\n\t\\begin{enumerate}\r\n\t\t\\item $\\lim_{x \\to c}{f(x)}$ exists\r\n\t\t\\item $f(c)$ is defined\r\n\t\t\\item $\\lim_{x \\to c}{f(x)} = f(c)$ (substitution works)\r\n\t\\end{enumerate}\r\n\tOtherwise, $f(x)$ is discontinuous at $c$.\\footnote{Note that it's not necessary for $c \\in D$.}\r\n\\end{definition}\r\n\r\n\r\nWe say that a function is continuous on an interval if it's continuous on every point in that interval.\\footnote{If the interval is closed on one or both sides, we check continuity on the open interval. Then, we check the closed endpoints by looking at the limit from only one side.}\r\n\r\n\\begin{example}\r\n\tFind the points of continuity and discontinuity of the following functions\r\n\t\\begin{table}[H]\r\n\t\\begin{center}\r\n\t\\begin{tabular}{ l l }\r\n\t\t1. $\\begin{aligned}\r\n\t\t\tf(x) = \\frac{1}{x^2+1}\r\n\t\t\\end{aligned}$ &\r\n\t\t2. $\\begin{aligned}\r\n\t\t\tg(x) = e^{1/x}\r\n\t\t\\end{aligned}$\r\n\t\\end{tabular}\r\n\t\\end{center}\r\n\t\\end{table}\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{enumerate}\r\n\t\t\\item There are no points where $f(x)$ or its limit are undefined.\r\n\t\t\tFurther, there are no points where $f$ and its limit at that point are different.\r\n\t\t\tSo, $f$ is continuous on $(-\\infty, \\infty)$ and discontinuous on $\\emptyset$.\r\n\t\t\\item Since $1/x$ is undefined at $x = 0$, $g(x)$ is also undefined at $x=0$.\r\n\t\t\tAt every other point, $g$ and its limit are defined and are equal.\r\n\t\t\tSo, $g$ is continuous on $(\\infty, 0) \\cup (0, \\infty)$ and discontinuous on $[0]$.\r\n\t\\end{enumerate}\r\n\\end{answer}", "meta": {"hexsha": "fc907c74de3f5640606d7816b0ae81dcc26b29d8", "size": 2223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/limits_continuity/continuity_definition.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/limits_continuity/continuity_definition.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/limits_continuity/continuity_definition.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 50.5227272727, "max_line_length": 284, "alphanum_fraction": 0.6972559604, "num_tokens": 636, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891479496521, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7020778003010354}}
{"text": "\\section{Markov chain VS Simulation}\n\n\\subsection{Example model}\nConsider the Markov chain paradigm in figure \\ref{Model_mini}. \nThe illustrated model represents the unrealistically small system \nwith a system capacity of five and a buffer capacity of three. \nThe hospital in this particular example also has four servers and a threshold of \nthree; meaning that every ambulance that arrives in a time that there are three or \nmore individuals in the hospital, will proceed to the buffer centre.\n\n\\begin{figure}[h]\n    \\centering\n    \\input{Comparisons/Example_model/Tikz_code/main.tex}\n    \\caption{Markov chains: number of servers=4} \n    \\label{Model_mini}\n\\end{figure}\n\nIn addition to the Markov chain model a simulation model has also been built based \non the same parameters. \nComparing the results of the Markov model and the equivalent simulation model the \nresultant plots arose.\n\nThe heatmaps in figure \\ref{Heatmap_mini} represent the state probabilities for \nthe Markov chain model, the simulation model and the difference between the two. \nEach pixel of the heatmap corresponds to the equivalent state of figure \\ref{Model_mini} \nand represents the probability of being at that state in any particular moment of time.\n\nIt can be observed that both Markov chain and simulation models' state probabilities \nvary from 5\\% to 25\\% and that states \\( (0, 1) \\) and \\( (0, 2) \\) are the most \nvisited ones. \nLooking at the differences' heatmap, one may identify that the differences between \nthe two are minimal.\n\n\\newpage\n\n\\begin{figure}[h]\n    \\includegraphics[width=\\linewidth]{Comparisons/Example_model/Heatmap/main.pdf}\n    \\caption{Heatmaps of Simulation, Markov chains and differences of the two}\n    \\label{Heatmap_mini}\n\\end{figure}\n\n\n\n", "meta": {"hexsha": "473ad3065f7321472522d1fc005eb4db97492854", "size": 1751, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/main/Comparisons/Example_model/main.tex", "max_stars_repo_name": "11michalis11/AmbulanceDecisionGame", "max_stars_repo_head_hexsha": "45164ba51da0417297f715e41716cb91facc120f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/main/Comparisons/Example_model/main.tex", "max_issues_repo_name": "11michalis11/AmbulanceDecisionGame", "max_issues_repo_head_hexsha": "45164ba51da0417297f715e41716cb91facc120f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 20, "max_issues_repo_issues_event_min_datetime": "2020-04-20T09:08:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T11:09:25.000Z", "max_forks_repo_path": "tex/main/Comparisons/Example_model/main.tex", "max_forks_repo_name": "11michalis11/AmbulanceDecisionGame", "max_forks_repo_head_hexsha": "45164ba51da0417297f715e41716cb91facc120f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7954545455, "max_line_length": 89, "alphanum_fraction": 0.7778412336, "num_tokens": 407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048444, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7020777912007401}}
{"text": "\\section{Simplicial Complexes}\r\nOur next family of algebraic invariants is called homology, which are hard to define but easy to calculate when defined.\r\nBut first, let us talk about simplicial complexes.\r\n\\subsection{Definitions}\r\n\\begin{definition}\r\n    A finite set $V=\\{v_0,\\ldots,v_n\\}\\subset\\mathbb R^m$ is said to be in general position if the smallest affine linear subspace (translation of a linear subspace) of $\\mathbb R^m$ containing $V$ has dimension $n$.\r\n\\end{definition}\r\nConsequently, no set of $n$ points in $\\mathbb R^m$ would be in general position if $n>m$.\r\nAnother way of defining this is that $\\{v_1-v_0,\\ldots,v_n-v_0\\}$ are linearly independent.\r\n\\begin{definition}\r\n    The span or a convex hull of a set $V=\\{v_0,\\ldots,v_n\\}\\subset\\mathbb R^m$ is\r\n    $$\\langle V\\rangle=\\left\\{ \\sum_{i=0}^nt_iv_i:\\sum_{i=0}^nt_i=1,t_i\\ge 0\\right\\}$$\r\n    If $V$ is in general position, then $\\langle V\\rangle$ is said to be an $n$-simplex.\r\n\\end{definition}\r\nSometimes we omit the set bracket and just write $\\langle v_0,\\ldots,v_n\\rangle$ as $\\langle V\\rangle=\\langle \\{v_0,\\ldots,v_n\\}\\rangle$.\r\nSo a $0$-simplex is just a point, a $1$-simplex is a line segment, a $2$-simplex is a (solid) triangle and a $3$-simplex is a (solid) tetrahedron.\r\n\\begin{definition}\r\n    If $V\\subset\\mathbb R^n$ is in general position and $U\\subset V$, then $\\langle U\\rangle\\subset\\langle V\\rangle$ is said to be a face of $V$, and we write $\\langle U\\rangle\\subset\\langle V\\rangle$.\r\n    Furthermore, if $U\\le V$ and $U\\neq V$, then we call $\\langle U\\rangle$ a proper face of $\\langle V\\rangle$.\r\n\\end{definition}\r\nThe empty set is viewed as a face by convention.\r\n\\begin{definition}\r\n    A simplicial complex is a finite set $K$ of simplices in $\\mathbb R^m$ such that:\\\\\r\n    1. If $\\sigma\\in K$ and $\\tau\\le\\sigma$, then $\\tau\\in K$.\\\\\r\n    2. If $\\sigma,\\tau\\in K$, then $\\sigma\\cap\\tau$ is a face of both $\\sigma$ and $\\tau$.\r\n\\end{definition}\r\n\\begin{example}\r\n    Just glue (well, not really, but you know what I mean) line segments, triangles, tetrahdrons together along the faces (aka edges, endpoints, etc.).\r\n    But if we take a triangle (and its faces) and a line segment (ditto) pointing into its interior, then we do not get a simplicial complex.\r\n\\end{example}\r\n\\begin{definition}\r\n    For a simplicial complex $K$, the dimension $\\dim K$ of $K$ is the largest $n$ such that $K$ contains a $n$-simplex.\r\n    We write $K_{(d)}=\\{\\sigma\\in K:\\dim\\sigma\\le d\\}$ as the $d$-skeleton of $K$, which is also a simplicial complex.\r\n\\end{definition}\r\n\\begin{example}\r\n    The set $F$ of faces of an $n$-simplex $\\sigma$ is a simplicial complex, and the set of proper faces (which is called the boundary $\\partial\\sigma$ of $\\sigma$) of $\\sigma$ is also a simplicial complex and is the $(n-1)$ skeleton of $F$.\r\n    The interior $\\sigma^\\circ$ is the points in $\\sigma$ that is not contained in any simplex in $\\partial\\sigma$.\r\n\\end{example}\r\n\\begin{definition}\r\n    The realisation of a simplicial complex $K$ is\r\n    $$|K|=\\bigcup_{\\sigma\\in K}\\sigma\\subset\\mathbb R^m$$\r\n    viewed as a topological space with topology induced as a subset of $\\mathbb R^m$.\\\\\r\n    If $X$ is a space, then a triangulation of $X$ is a simplicial complex $K$ and a homeomorphism $|K|\\to X$.\r\n    If a triangulation of $X$ exists, then $X$ is said to be triangulable.\r\n\\end{definition}\r\n\\begin{example}\r\n    $D^n$ is triangulable as it is homeomorphic to the $n$-simplex.\r\n    The realisation of the boundary of the $n$-simplex is then homeomorphic to the boundary of $D^n$ which is $S^{n-1}$, so the $n$-spheres are also triangulable.\r\n\\end{example}\r\n\\begin{remark}\r\n    There might be many different triangulations of the same space.\r\n\\end{remark}\r\n\\begin{definition}\r\n    Let $K,L$ be simplicial complexes.\r\n    A simplicial map is a map $f:K\\to L$ such that:\r\n    1. Each $0$-simplex $\\langle v\\rangle\\in K$ is sent to a $0$-simplex $\\langle f(v)\\rangle$ of $L$.\\\\\r\n    2. For any $\\langle v_0,\\ldots,v_n\\rangle\\in K$, we have $f(\\langle v_0,\\ldots,v_n\\rangle)=\\langle f(v_0),\\ldots,f(v_n)\\rangle$.\\\\\r\n    The realisation of $f$ is the map $|f|$ defined in the following way:\r\n    On each $\\sigma=\\langle v_0,\\ldots,v_n\\rangle\\in K$, we want the restriction of $f$ to be\r\n    $$f|_\\sigma=f_\\sigma:\\sum_{i=0}^nt_iv_i\\mapsto\\sum_{i=0}^nt_if(v_i)$$\r\n    which is obviously continuous and consistent as $f_\\sigma|_\\tau=f|_\\tau$ for $\\tau\\le\\sigma$.\r\n    So we can glue them together to get the continuous map $|f|:|K|\\to |L|$.\r\n\\end{definition}\r\nHowever, there is simply not enough simplicial maps to capture all possible maps $|K|\\to|L|$ up to homotopy.\r\n\\begin{example}\r\n    Consider the triangulation of the circle by gluing three line segments together (which makes it the realisation of $\\partial\\sigma_2$, the boundary of the $2$-simplex).\r\n    There are at most $3^3$ simplicial maps from $\\partial\\sigma_2$ to itself but infinitely many different homeomorphisms (hence homotopy equivalences) from the circle to itself.\r\n\\end{example}\r\nThe solution to this problem is to introduce the barycentric subdivision to refine triangulations.\r\n\\subsection{Barycentric Subdivision and Simplicial Approximation}\r\n\\begin{definition}\r\n    Let $V=\\{v_0,\\ldots, v_n\\}$ be in general position, then\r\n    $$\\hat\\sigma=\\frac{1}{n+1}\\sum_{i=0}^nv_i$$\r\n    is the barycentre of $\\sigma=\\langle v\\rangle$, which resides in $\\sigma^\\circ$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    Let $K$ be a simplicial complex, a barycentric subdivision $K'$ of $K$ is the set of simplices such that:\\\\\r\n    1. The vertices ($0$-simplices) of $K'$ are the barycentres of simplices in $K$.\\\\\r\n    2. $\\hat\\sigma_0,\\ldots,\\hat\\sigma_n$ span a simplex of $K'$ iff $\\sigma_0<\\sigma_1<\\ldots<\\sigma_n$.\r\n\\end{definition}\r\nSo we are just dividing the original simplex with new vertices introduced by barycentres.\r\n\\begin{lemma}\r\n    Let $K$ be a simplicial complex, then $K'$ is a simplicial complex and $|K'|=|K|$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    First check that $\\hat\\sigma_0,\\ldots,\\hat\\sigma_n$ is indeed in general position if $\\sigma_0<\\sigma_1<\\ldots<\\sigma_n$.\r\n    Indeed, if we have $t_0,\\ldots,t_n$ such that\r\n    $$\\sum_{i=0}^nt_i=0,\\sum_{i=0}^nt_i\\hat\\sigma_i=0$$\r\n    Take $j$ to be the largest index such that $t_j\\neq 0$.\r\n    If no such $j$ exist then we are done, otherwise\r\n    $$\\hat{\\sigma}_j=\\sum_{i=0}^{j-1}\\left(-\\frac{t_i}{t_j}\\right)\\hat\\sigma_i$$\r\n    is contained in $\\sigma_{j-1}$ which is a proper face in $\\sigma_j$, contradiction.\r\n    Therefore $\\hat\\sigma_0,\\ldots,\\hat\\sigma_n$ is in general position.\\\\\r\n    Now $K'$ is clearly closed under passing to faces.\r\n    Furthermore, if we have two simplices $\\sigma',\\tau'\\in K'$, write $\\sigma'=\\langle\\hat\\sigma_0,\\ldots,\\hat\\sigma_m\\rangle$ for $\\sigma_0<\\cdots<\\sigma_m$ and $\\tau'=\\langle\\hat\\tau_0,\\ldots,\\hat\\tau_n\\rangle$ for $\\tau_0<\\cdots<\\tau_n$.\r\n    Obviously $\\sigma'\\cap\\tau'\\subset \\sigma_m\\cap\\tau_n$, whcih means that we can assume WLOG that $\\sigma',\\tau'\\in\\delta$ for some $\\delta\\in K$.\r\n    We proceed by induction in $\\dim K$.\r\n    If one of $\\sigma',\\tau'$ does not contain $\\hat\\delta$, then $\\sigma'\\cap\\tau'$ is contained in $\\partial\\delta$.\r\n    Otherwise, both $\\sigma',\\tau'$ contain $\\hat\\delta$, then $\\sigma'\\cap\\tau'$ is the convex hull of $\\{\\hat\\delta\\}\\cap(\\sigma'\\cap\\partial\\delta)\\cap(\\tau'\\cap\\partial\\delta)$.\r\n    We are done by induction.\\\\\r\n    To see $|K'|=|K|$, it suffices to show that $|K|\\subset |K'|$.\r\n    We will also use induction on $\\dim K$.\r\n    The base case is trivial.\r\n    Let $\\sigma=\\langle v_0,\\ldots,v_m\\rangle\\in K$ and $x\\in\\sigma$.\r\n    If $x=\\hat\\sigma$, then we are done.\r\n    Otherwise, we project $\\pi:\\sigma\\setminus\\{\\hat\\sigma\\}\\to|\\partial\\sigma|$ by mapping $y\\in\\sigma$ to the unique point in the intersection of the ray $\\hat\\sigma\\to y$ and $|\\partial\\sigma|$.\r\n    By the induction hypothesis, $\\pi(x)\\in\\langle\\hat\\sigma_1,\\ldots,\\hat\\sigma_n\\rangle\\in K'$ for some $\\sigma_1<\\cdots<\\sigma_n$, which implies $x\\in\\langle\\hat\\sigma_1,\\ldots,\\hat\\sigma_n,\\hat\\sigma\\rangle$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Set $K^{(0)}=K$ and $K^{(r)}=(K^{(r-1)})'$.\r\n    The simplicial complex $K^{(n)}$ is the $n^{th}$ barycentric subdivision of $K$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    If $K$ is a simplicial complex, we set the mesh of $K$ to be\r\n    $$\\operatorname{mesh}(K)=\\max_{\\langle u,v\\rangle\\in K}|u-v|$$\r\n\\end{definition}\r\n\\begin{lemma}\r\n    If $\\dim K=n$, then\r\n    $$\\operatorname{mesh}(K^{(r)})\\le\\left( \\frac{n}{n+1} \\right)^r\\operatorname{mesh}(K)$$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Suffices to show the case for $r=1$.\r\n    If $\\langle u,v\\rangle\\in K'=K^{(1)}$, then we know there is some $\\tau<\\sigma$ such that $u=\\hat\\tau,v=\\hat\\sigma$.\r\n    We can assume that $\\tau$ is a $0$-simplex as this maximises the distance between $\\hat\\sigma$ and $\\partial\\sigma$.\r\n    Suppose $\\sigma=\\langle v_0,\\ldots,v_n\\rangle$ and $\\hat\\tau=\\langle v_0\\rangle$, then\r\n    \\begin{align*}\r\n        |\\hat\\sigma-\\hat\\tau|&=\\left|v_0-\\sum_{i=0}^m\\frac{1}{m+1}v_i\\right|=\\left|\\frac{m}{m+1}v_0-\\frac{1}{m+1}\\sum_{i=1}^mv_i\\right|\\\\\r\n        &=\\left|\\frac{1}{m+1}\\sum_{i=1}^m(v_i-v_0)\\right|\\le\\frac{1}{m+1}\\sum_{i=1}^m|v_i-v_0|\\\\\r\n        &\\le\\frac{m}{m+1}\\operatorname{mesh}(K)\\\\\r\n        &\\le\\frac{n}{n+1}\\operatorname{mesh}(K)\r\n    \\end{align*}\r\n    The lemma follows.\r\n\\end{proof}\r\nTurns out, any map $|K|\\to|L|$ is homotopic to a realisation of a simplicial map between some barycentric subdivisions of $K,L$.\r\n\\begin{definition}\r\n    Let $K$ be a simplicial complex.\r\n    The (open) star of a vertex $v$ of $K$ is the union of the interiors of simplices of $K$ containing $V$, that is,\r\n    $$\\operatorname{St}_K(v)=\\bigcup_{v\\in\\sigma\\in K}\\sigma^\\circ$$\r\n\\end{definition}\r\n\\begin{definition}\r\n    Let $\\phi:|K|\\to|L|$ be a map.\r\n    A simplicial map $f:K\\to L$ is said to be a simplicial approximation to $\\phi$ if $\\phi(\\operatorname{St}_K(v))\\subset\\operatorname{St}_L(f(v))$ for any vertex $v$ of $K$.\r\n\\end{definition}\r\nIt is easy to see that composition of simplicial approximations is also a simplicial approximation.\r\n\\begin{note}\r\n    If $\\phi=|f|$, then the equality holds.\r\n\\end{note}\r\n\\begin{lemma}\r\n    If $f:K\\to L$ is a simplicial approximation to $\\phi:|K|\\to|L|$, then $\\phi\\simeq|f|$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Suppose $|L|\\subset\\mathbb R^m$.\r\n    We shall show that the straight line homotopy $H(x,t)=t\\phi(x)+(1-t)|f|(x)$ works.\r\n    It suffices to show that $\\operatorname{Im}H\\subset L$.\r\n    Let $x\\in |K|$ lie in the interior of some simplex $\\sigma$, then $\\phi(x)$ lies in the interior of some unique $\\tau\\in L$.\r\n    We claim that $f(\\sigma)\\subset\\tau$.\r\n    Indeed, for any vertex $v_i$ of $\\sigma$, $x\\in\\operatorname{St}_K(v_i)$, so $\\phi(x)\\in \\phi(\\operatorname{St}_K(v_i))\\subset\\operatorname{St}_L(f(v_i))$ as $f$ is a simplicial approximation of $\\phi$.\r\n    Thus $\\tau^\\circ\\subset\\operatorname{St}_L(f(v_i))$, so $f(v_i)$ is a vertex of $\\tau$ which exactly means $f(\\sigma)\\le\\tau$.\r\n    Now since $\\tau$ is convex, the line segment between $|f|(x)$ and $\\phi(x)$ is contained in $\\tau$, therefore $\\operatorname{Im}H\\subset |L|$ as desired.\r\n\\end{proof}\r\n\\begin{note}\r\n    We did not use the assumption of $f$ being a simplicial map in the proof of $f(\\sigma)\\subset\\tau$.\r\n\\end{note}\r\nDoes a simplicial approximation always exist?\r\n\\begin{theorem}[The Simplicial Approximation Theorem]\r\n    Let $K,L$ be simplicial complexes and $\\phi:|K|\\to |L|$ a map.\r\n    Then there exists a positive integer $r$ and a simplicial approximation $f:K^{(r)}\\to L$ to $\\phi:|K|=|K^{(r)}|\\to|L|$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Consider $\\mathcal U=\\{\\phi^{-1}(\\operatorname{St}_L(v)):v=\\langle v\\rangle\\in L\\}$ is an open cover of $|K|$.\r\n    We shall show that $\\exists \\delta>0$ such that $\\forall x\\in |K|\\subset\\mathbb R^m$, the ball $B(x,\\delta)$ is contained in some element of $\\mathcal U$.\r\n    Indeed, if this is not true, then for each $n$ there is some $x_n\\in |K|$ such that $B(x_n,1/n)$ is not contained in any open set of $\\mathcal U$.\r\n    By the compactness of $|K|$, we can assume $x_n$ converges to some $x\\in |K|$ by passing to a convergent subsequence.\r\n    But $x\\in U$ for some $U\\in\\mathcal U$, so there is some $\\epsilon>0$ such that $B(x,\\epsilon)\\subset U$.\r\n    Take $n$ large enough such that $|x_n-x|<\\epsilon/2$ and $1/n<\\epsilon/2$, then $B(x_n,1/n)\\subset U$, contradiction.\\\\\r\n    Choose $r$ sufficiently large such that $\\operatorname{mesh}(K^{(r)})<\\delta$, the for each vertex $v$ of $K^{(r)}$, we have $\\operatorname{St}_{K^{(r)}}(v)\\subset B(v,\\delta)\\subset U$ for some $U\\in\\mathcal U$.\r\n    But $U$ takes the form $\\phi^{-1}(\\operatorname{St}_L(u))$ for some vertex $u$ of $L$.\r\n    So $\\operatorname{St}_{K^{(r)}}(v)\\subset\\phi^{-1}(\\operatorname{St}_L(u))$.\r\n    We define $f(v)=u$.\r\n    If $\\sigma\\in K$ and $x\\in\\sigma^\\circ$, then $f(\\sigma)$ is a face of $\\tau$ which is the unique simplex of $L$ containing $\\phi(x)$ in its interior (this can be proved in the exact same way we proved the claim in the preceding lemma).\r\n    So $f(\\sigma)$ is a simplex of $L$, therefore $f$ is a simplicial map and hence approximation to $\\phi$ since we have proven $\\phi(\\operatorname{St}_{K^{(r)}}(v))\\subset\\operatorname{St}_L(u)$.\r\n\\end{proof}", "meta": {"hexsha": "45fa01919eed400e79879dc29b3fb0c4c84d4bd4", "size": 13343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/simp.tex", "max_stars_repo_name": "david-bai-notes/II-Algebraic-Topology", "max_stars_repo_head_hexsha": "05767a26daaddb170e563151393371d8213ee741", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-03T17:38:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-03T17:38:28.000Z", "max_issues_repo_path": "4/simp.tex", "max_issues_repo_name": "david-bai-notes/II-Algebraic-Topology", "max_issues_repo_head_hexsha": "05767a26daaddb170e563151393371d8213ee741", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4/simp.tex", "max_forks_repo_name": "david-bai-notes/II-Algebraic-Topology", "max_forks_repo_head_hexsha": "05767a26daaddb170e563151393371d8213ee741", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.3131868132, "max_line_length": 242, "alphanum_fraction": 0.670388968, "num_tokens": 4430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.702077785218508}}
{"text": "\\section{Set theory}\n\nIn this section we construct the quotient of a type by an equivalence relation. By an equivalence relation we understand a binary relation $R:A\\to(A\\to\\prop)$ which is reflexive, symmetric, and transitive. In particular, we note that equivalence relations take values in $\\prop$. The quotient $A/R$ is constructed as the type of equivalence classes, which is just the image of the map $R:A\\to (A\\to\\prop)$. Thus, our construction of the quotient by an equivalence relation is very much like the classical construction of a quotient set. Examples of set quotients are abundant. We cover two of them: the type of rational numbers and the set truncation of a type.\n\nThere is, however, a subtle issue with our construction of the set quotient as the image of the map $R:A\\to(A\\to\\prop)$. What is the universe level of the quotient $A/R$? Let us suppose that $\\UU$ is a universe that contains $A$ and each $R(x,y)$. Then $\\prop$, the type of propositions in $\\UU$, is a type in the universe $\\UU^+$, constructed in \\cref{rmk:universe-constructions}. Therefore the type $\\prop^A$ as well as the quotient $A/R$ are also types in $\\UU^+$. That seems unfortunate, because in Zermelo-Fraenkel set theory the quotient of a set by an equivalence relation is an ordinary set, and not a more general class.\n\nIn Zermelo-Fraenkel set theory quotients are are sets because of the axiom schema of replacement. The replacement axioms assert that the image of any function is again a set. This leads us to wonder about a type theoretical variant of the replacement axioms. Indeed, there is such a variant. The type theoretic replacement property asserts that for any map $f:A\\to B$ from a type $A$ in $\\UU$ to a type $B$ of which the \\emph{identity types} are equivalent to types in $\\UU$, the image of $f$ is also equivalent to a type in $\\UU$, and in fact this property is a theorem. We prove it in \\cref{thm:replacement}, using the univalence axiom and a new construction of the image of a map.\n\n\\subsection{Equivalence relations}\n\n\\begin{defn}\\label{defn:eq_rel}\nLet $R:A\\to (A\\to\\prop)$ be a binary relation valued in the propositions. We say that $R$ is an \\define{equivalence relation}\\index{equivalence relation} if $R$ comes equipped with\n\\begin{align*}\n\\rho & : \\prd{x:A}R(x,x) \\\\\n\\sigma & : \\prd{x,y:A} R(x,y)\\to R(y,x) \\\\\n\\tau & : \\prd{x,y,z:A} R(x,y)\\to (R(y,z)\\to R(x,z)),\n\\end{align*}\nwitnessing that $R$ is reflexive, symmetric, and transitive.\n\\end{defn}\n\n\\begin{defn}\n  Let $R:A\\to (A\\to\\prop)$ be an equivalence relation. The \\define{equivalence class} of $x:A$ is defined to be\n  \\begin{equation*}\n    [x]_R\\defeq R(x).\n  \\end{equation*}\n  More generally, a subtype $P:A\\to \\prop$ is said to be an \\define{equivalence class} if it satisfies\n  \\begin{equation*}\n    \\mathsf{is\\usc{}equivalence\\usc{}class}(P)\\defeq\\exists_{(x:A)}P=R(x).\n  \\end{equation*}\n  Furthermore, we define $A/R$ to be the type of equivalence classes, i.e., we define\n  \\begin{equation*}\n    A/R\\defeq \\sm{P:A\\to\\prop}\\mathsf{is\\usc{}equivalence\\usc{}class}(P).\n  \\end{equation*}\n\\end{defn}\n\nIn other words, $A/R$ is the image of the map $[{-}]_R:A\\to (A\\to\\prop)$. In the following proposition we characterize the identity type of $A/R$. As a corollary, we obtain equivalences\n\\begin{equation*}\n  ([x]_R=[y]_R)\\simeq R(x,y),\n\\end{equation*}\njustifying that the quotient $A/R$ is defined to be the type of equivalence classes. Note that in our characterization of the identity type of $A/R$ we make use of the univalence axiom.\n\n\\begin{prp}\\label{prp:eq-quotient}\n  Let $R:A\\to (A\\to\\prop)$ be an equivalence relation. Furthermore, consider $x:A$ and an equivalence class $P$. Then the canonical map\n  \\begin{equation*}\n    ([x]_R=P)\\to P(x)\n  \\end{equation*}\n  is an equivalence.\n\\end{prp}\n\n\\begin{proof}\n  By \\cref{thm:id_fundamental} it suffices to show that the total space\n  \\begin{equation*}\n    \\sm{P:A/R}P(x)\n  \\end{equation*}\n  is contractible. The center of contraction is of course $[x]_R$, which satisfies $[x]_R(x)$ by reflexivity of $R$. It remains to construct a contraction. Since $\\sm{P:A/R}P(x)$ is a subtype of $A/R$, we construct a contraction by showing that\n  \\begin{equation*}\n    [x]_R=P\n  \\end{equation*}\n  whenever $P(x)$ holds. Recall that $P$ is an equivalence relation, i.e., that there exists a $y:A$ such that $P=[y]_R$. Note that our goal is a proposition, so we may assume that we have such a $y$. Then we obtain that $R(x,y)$ holds from the assumption that $P(x)$ holds. Thus, we have to show that\n  \\begin{equation*}\n    [x]_R=[y]_R\n  \\end{equation*}\n  given that $R(x,y)$ holds. By function extensionality and the univalence axiom, it is equivalent to show that\n  \\begin{equation*}\n    \\prd{z:A}R(x,z)\\simeq R(y,z)\n  \\end{equation*}\n  We get a function $R(x,z)\\to R(y,z)$ by transitivity, since $R(y,x)$ holds by symmetry. Conversely, we get a function $R(y,z)\\to R(x,z)$ directly by transitivity. Thus, we obtain that\n  \\begin{equation*}\n    R(x,z)\\leftrightarrow R(y,z)\n  \\end{equation*}\n  for any $z:A$, which is sufficient to prove that they are equivalent because $R$ is valued in $\\prop$.\n\\end{proof}\n\n\\begin{cor}\\label{cor:eq-quotient}\n  Consider an equivalence relation $R$ on a type $A$, and let $x,y:A$. Then there is an equivalence\n  \\begin{equation*}\n    ([x]_R=[y]_R)\\simeq R(x,y).\n  \\end{equation*}\n\\end{cor}\n\n\\begin{proof}\n  By \\cref{prp:eq-quotient} we have an equivalence\n  \\begin{equation*}\n    ([x]_R=[y]_R)\\simeq R(y,x).\n  \\end{equation*}\n  Moreover, $R(y,x)$ is equivalent to $R(x,y)$ by symmetry of $R$.\n\\end{proof}\n\n\\begin{comment}\nThe notion of $0$-equivalence relation which we defined in \\cref{defn:eq_rel} fits in a hierarchy of `$n$-equivalence relations'\\index{n-equivalence relation@{$n$-equivalence relation}}, the study of which is a research topic on its own. However, we already know an example of a relation that should count as an `$\\infty$-equivalence relation'\\index{infinity-equivalence relation@{$\\infty$-equivalence relation}}: the identity type. Analogous to \\cref{thm:equivalence_classes}, the following theorem shows that the canonical map\n\\begin{equation*}\n(x=y)\\to (\\idtypevar{A}(x)=\\idtypevar{A}(y))\n\\end{equation*}\nis an equivalence, for any $x,y:A$. In other words, $\\idtypevar{A}(x)$ can be thought of as the equivalence class of $x$ with respect to the relation $\\idtypevar{A}$.\n\n\\begin{thm}\nAssuming the univalence axiom on $\\UU$, the map\n\\begin{equation*}\n\\idtypevar{A}:A\\to (A\\to\\UU)\n\\end{equation*}\nis an embedding, for any type $A:\\UU$.\\index{identity type!is an embedding}\n\\end{thm}\n\n\\begin{proof}\nLet $a:A$. By function extensionality it suffices to show that the canonical map\n\\begin{equation*}\n(a=b)\\to \\idtypevar{A}(a)\\htpy\\idtypevar{A}(b)\n\\end{equation*}\nthat sends $\\refl{a}$ to $\\lam{x}\\refl{(a=x)}$ is an equivalence for every $b:A$, and by univalence it therefore suffices to show that the canonical map\n\\begin{equation*}\n(a=b)\\to \\prd{x:A}\\eqv{(a=x)}{(b=x)}\n\\end{equation*}\nthat sends $\\refl{a}$ to $\\lam{x}\\idfunc[(a=x)]$ is an equivalence for every $b:B$. To do this we employ the type theoretic Yoneda lemma, \\cref{thm:yoneda}.\n\nBy the type theoretic Yoneda lemma\\index{Yoneda lemma} we have an equivalence\n\\begin{equation*}\n\\Big(\\prd{x:A} (b=x)\\to (a=x)\\Big)\\to (a=b)\n\\end{equation*}\ngiven by $\\lam{f} f(b,\\refl{b})$, for every $b:A$. Note that any family of maps $\\prd{x:A}(b=x)\\to (a=x)$ induces an equivalence of total spaces by \\cref{ex:contr_equiv}, since their total spaces are are both contractible by \\cref{cor:contr_path}. It follows that we have an equivalence\n\\begin{equation*}\n\\varphi_b:\\Big(\\prd{x:A} \\eqv{(b=x)}{(a=x)}\\Big)\\to (a=b)\n\\end{equation*}\ngiven by $\\lam{f} f(b,\\refl{b})$, for every $b:A$. \n\nNote that $\\varphi_a(\\lam{x}\\idfunc[(a=x)])\\jdeq\\refl{a}$. Therefore it follows by another application of \\cref{thm:yoneda} that the unique family of maps \n\\begin{equation*}\n\\alpha_b:(a=b)\\to \\Big(\\prd{x:A} \\eqv{(b=x)}{(a=x)}\\Big)\n\\end{equation*}\nthat satisfies $\\alpha_a(\\refl{a})=\\lam{x}\\idfunc[(a=x)]$ is a family of sections of $\\varphi$. \nIt follows that $\\alpha$ is a family of equivalences. Now the proof is completed by reverting the direction of the family of equivalences in the codomain.\n\\end{proof}\n\\end{comment}\n\n\\subsection{The universal property of set quotients}\n\nThe quotient $A/R$ is constructed as the image of $R$, so we obtain a commuting triangle\n\\begin{equation*}\n  \\begin{tikzcd}[column sep=-1em]\n    A \\arrow[rr,\"q_R\"] \\arrow[dr,swap,\"R\"] & & A/R \\arrow[dl,hook,\"i_R\"] \\\\\n    \\phantom{A/R} & \\prop^A,\n  \\end{tikzcd}\n\\end{equation*}\nand the embedding $i_R:A/R\\to\\prop^A$ satisfies the universal property of the image of $R$. This universal property is, however, not the usual universal property of the quotient.\n\n\\begin{defn}\n  Consider a map $q:A\\to B$ into a set $B$ satisfying the property that $f(x)=f(y)$ whenever $R(x,y)$ holds. We say that $q$ satisfies the \\define{universal property of the set quotient by $R$} if for every map $f:A\\to X$ into a set $X$ such that $f(x)=f(y)$ whenever $R(x,y)$ holds, there is a unique extension\n  \\begin{equation*}\n    \\begin{tikzcd}\n      A \\arrow[d,swap,\"q\"] \\arrow[dr,\"f\"] \\\\\n      B \\arrow[r,densely dotted] & X.\n    \\end{tikzcd}\n  \\end{equation*}\n\\end{defn}\n\n\\begin{rmk}\n  Formally, we express the universal property of the quotient by $R$ as follows. Consider a map $q:A\\to B$ that satisfies the property that\n  \\begin{equation*}\n    H:\\prd{x,y:A}R(x,y)\\to (f(x)=f(y)).\n  \\end{equation*}\n  Then there is for any set $X$ a map\n  \\begin{equation*}\n    q^\\ast:(B\\to X) \\to \\Big(\\sm{f:A\\to X}\\prd{x,y:A}R(x,y)\\to (f(x)=f(y))\\Big).\n  \\end{equation*}\n  This map takes a function $h:B\\to X$ to the pair\n  \\begin{equation*}\n    q^\\ast(h)\\defeq(h\\circ q,\\lam{x}{y}{r}\\ap{h}{H_{x,y}(r)}).\n  \\end{equation*}\n  The universal property of the set quotient of $R$ asserts that the map $q^\\ast$ is an equivalence for every set $X$. It is important to note that the universal property of set quotients is formulated with respect to sets.\n\\end{rmk}\n\n\\begin{thm}\\label{thm:quotient_up}\n  Let $R:A\\to (A\\to \\prop)$ be an equivalence relation\\index{equivalence relation}, and consider a map $q:A\\to B$ into a set $B$. Then the following are equivalent.\n  \\begin{enumerate}\n  \\item The map $q$ satisfies the property that\n    \\begin{equation*}\n      q(x)=q(y)\n    \\end{equation*}\n    for every $x,y:A$ for which $R(x,y)$ holds, and moreover $q$ satisfies the universal property of the set quotient of $R$.\n  \\item The map $q$ is surjective and \\define{effective}, which means that for each $x,y:A$ we have an equivalence\n    \\begin{equation*}\n      (q(x)=q(y))\\simeq R(x,y).\n    \\end{equation*}\n  \\item The map $R:A\\to (A\\to \\prop)$ extends along $q$ to an embedding\n    \\begin{equation*}\n      \\begin{tikzcd}[column sep=tiny]\n        A \\arrow[rr,\"q\"] \\arrow[dr,swap,\"R\"] & & B \\arrow[dl,densely dotted,\"i\"] \\\\\n        & \\prop^A\n      \\end{tikzcd}\n    \\end{equation*}\n    and the embedding $i$ satisfies the universal property of the image inclusion of $R$.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  We first show that (ii) is equivalent to (iii), since this is the easiest part. After that, we will show that (i) is equivalent to (ii).\n\n  Assume that (ii) holds. Then $q$ is surjective by \\cref{thm:surjective}. Moreover, we have\n  \\begin{align*}\n    R(x,y) & \\simeq R(x)=R(y) \\\\\n           & \\simeq i(q(x))=i(q(y)) \\\\\n           & \\simeq q(x)=q(y)\n  \\end{align*}\n  In this calculation, the first equivalence holds by \\cref{cor:eq-quotient}; the second equivalence holds since we have a homotopy $R\\htpy i\\circ q$; and the third equivalence holds since $i$ is an embedding. This completes the proof that (ii) implies (iii).\n\n  Next, we show that (iii) implies (ii). Assuming (iii), we define a map\n  \\begin{equation*}\n    i:B\\to\\prop^A\n  \\end{equation*}\n  by $i(b,a)\\defeq b=q(a)$. Then the triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      A \\arrow[rr,\"q\"] \\arrow[dr,swap,\"R\"] & & B \\arrow[dl,\"i\"] \\\\\n      & \\prop^A\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes, since we have an equivalence\n  \\begin{align*}\n    i(q(a),a') & \\simeq R(a,a')\n  \\end{align*}\n  for each $a,a':A$. To show that $i$ is an embedding, it suffices to show that $i$ is injective, i.e., that\n  \\begin{equation*}\n    \\prd{b,b':B}(i(b)=i(b'))\\to (b=b')\n  \\end{equation*}\n  Note that this is a property, and that $q$ is assumed to be surjective. Hence by \\cref{prp:surjective} it is equivalent to show that\n  \\begin{equation*}\n    \\prd{a,a':A}(i(q(a))=i(q(a')))\\to (q(a)=q(a')).\n  \\end{equation*}\n  Since $R\\htpy i\\circ q$, and $q(a)=q(a')$ is assumed to be equivalent to $R(a,a')$, it suffices to show that\n  \\begin{equation*}\n    \\prd{a,a':A}(R(a)=R(a'))\\to R(a,a'),\n  \\end{equation*}\n  which follows directly from \\cref{cor:eq-quotient}. Thus we have shown that the factorization $R\\htpy i\\circ q$ factors $R$ as a surjective map followed by an injective map. We conclude by \\cref{thm:surjective} that the embedding $i$ satisfies the universal property of the image factorization of $R$, which finishes the proof that (iii) implies (ii).\n  \n  Now we show that (i) implies (ii). To see that $q$ is surjective if it satisfies the assumptions in (i), consider the image factorization\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      A \\arrow[dr,swap,\"q\"] \\arrow[rr,\"q_q\"] & & \\im(q) \\arrow[dl,\"i_q\"] \\\\\n      \\phantom{\\im(q)} & B.\n    \\end{tikzcd}\n  \\end{equation*}\n  We claim that the map $i_q$ has a section. To see this, we first note that we have\n  \\begin{equation*}\n    q_q(x)=q_q(y)\n  \\end{equation*}\n  for any $x,y:A$ satisfying $R(x,y)$, because if $R(x,y)$ holds, then $q(x)=q(y)$ and hence $i_q(q_q(x))=i_q(q_q(y))$ holds and $i_q$ is an embedding. Since $\\im(q)$ is a set, we may apply the universal property of $q$ and we obtain a unique extension of $q_q$ along $q$\n  \\begin{equation*}\n    \\begin{tikzcd}\n      A \\arrow[d,swap,\"q\"] \\arrow[dr,\"q_q\"] \\\\\n      B \\arrow[r,densely dotted,swap,\"h\"] & \\im(q).\n    \\end{tikzcd}\n  \\end{equation*}\n  Now we observe that the composite $i_q\\circ h$ is an extension of $q$ along $q$, so it must be the identity function by uniqueness. Thus we have established that $h$ is a section of $i_q$. Now it follows from the fact that $i_q$ is an embedding with a section, that $i_q$ is an equivalence. We conclude that $q$ is surjective, because $q$ is the composite $i_q\\circ q_q$ of a surjective map followed by an equivalence.\n\n  Now we have to show that $q(x)=q(y)$ is equivalent to $R(x,y)$. We first apply the universal property of $q$ to obtain for each $x:A$ an extension of $R(x)$ along $q$\n  \\begin{equation*}\n    \\begin{tikzcd}\n      A \\arrow[d,swap,\"q\"] \\arrow[dr,\"R(x)\"] \\\\\n      B \\arrow[r,densely dotted,swap,\"\\tilde{R}(x)\"] & \\prop.\n    \\end{tikzcd}\n  \\end{equation*}\n  Since the triangle commutes, we have an equivalence $\\tilde{R}(x,q(x'))\\simeq R(x,x')$ for each $x':A$. Now we apply \\cref{thm:id_fundamental} to see that the canonical family of maps\n  \\begin{equation*}\n    \\prd{y:B}(q(x)=y)\\to \\tilde{R}(x,y)\n  \\end{equation*}\n  is a family of equivalences. Thus, we need to show that the type $\\sm{y:B}\\tilde{R}(x,y)$ is contractible. For the center of contraction, note that we have $q(x):B$, and the type $\\tilde{R}(x,q(x))$ is equivalent to the type $R(x,x)$, which is inhabited by reflexivity of $R$. To construct the contraction, it suffices to show that\n  \\begin{equation*}\n    \\prd{y:B}\\tilde{R}(x,y)\\to (q(x)=y).\n  \\end{equation*}\n  Since this is a property, and since we have already shown that $q$ is a surjective map, we may apply \\cref{prp:surjective}, by which it suffices to show that\n  \\begin{equation*}\n    \\prd{x':A}\\tilde{R}(x,q(x'))\\to (q(x)=q(x')).\n  \\end{equation*}\n  Since $\\tilde{R}(x,q(x'))\\simeq R(x,x')$, this is immediate from our assumption on $q$. Thus we obtain the contraction, and we conclude that we have an equivalence $\\tilde{R}(x,y)\\simeq (q(x)=y)$ for each $y:B$. It follows that we have an equivalence\n  \\begin{equation*}\n    R(x,y)\\simeq (q(x)=q(y))\n  \\end{equation*}\n  for each $x,y:A$, which completes the proof that (i) implies (ii).\n  \n  It remains to show that (iii) implies (i). Assume (iii), and let $f:A\\to X$ be a map into a set $X$, satisfying the property that\n  \\begin{equation*}\n    \\prd{a,a':A}R(a,a')\\to (f(a)=f(a')).\n  \\end{equation*}\n  Our goal is to show that the type of extensions of $f$ along $q$ is contractible. By \\cref{ex:surjective-precomp} it follows that there is at most one such an extension, so it suffices to construct one.\n\n  In order to construct an extension, we will construct for every $b:B$ a term $x:X$ satisfying the property\n  \\begin{equation*}\n    P(x)\\defeq \\exists_{(a:A)}(f(a)=x)\\land (q(a)=b).\n  \\end{equation*}\n  Before we make this construction, we first observe that there is at most one such $x$, i.e., that the type of $x:X$ satisfying $P(x)$ is in fact a proposition. To see this, we need to show that $x=x'$ for any $x,x':X$ satisfying $P(x)$ and $P(x')$. Since $X$ is assumed to be a set, our goal of showing that $x=x'$ is a property. Therefore we may assume that we have $a,a':A$ satisfying\n  \\begin{align*}\n    f(a) & = x & q(a) & = b \\\\\n    f(a') & = x' & q(a') & = b.\n  \\end{align*}\n  It follows from these assumptions that $q(a)=q(a')$, and hence that $R(a,a')$ holds. This in turn implies that $f(a)=f(a')$, and hence that $x=x'$.\n\n  Now let $b:B$. Our goal is to construct an $x:X$ that satisfies the property\n  \\begin{equation*}\n    \\exists_{(a:A)}(f(a)=x)\\land (q(a)=b).\n  \\end{equation*}\n  Since $q$ is assumed to be surjective, we have $\\brck{\\fib{q}{b}}$. Moreover, since we have shown that at most one $x:X$ exists with the asserted property, we get to assume that we have $a:A$ satisfying $q(a)=b$. Now we see that $x\\defeq f(a)$ satisfies the desired property.\n\n  Thus, we obtain a function $h:B\\to X$ satisfying the property that for all $b:B$ there exists an $a:A$ such that\n  \\begin{equation*}\n    f(a)=h(b)\\qquad\\text{and}\\qquad q(a)=b.\n  \\end{equation*}\n  In particular, it follows that $h(q(a))=f(a)$ for all $a:A$, which completes the proof that (ii) implies (i).  \n\\end{proof}\n\n\\subsection{The rational numbers}\n\n\\subsection{Set truncation}\\label{sec:set-truncation}\n\n\\begin{lem}\nFor each type $A$, the relation $I_{(-1)}:A\\to (A\\to\\prop)$ given by\n\\begin{equation*}\nI_{(-1)}(x,y)\\defeq\\brck{x=y}\n\\end{equation*}\nis an equivalence relation.\n\\end{lem}\n\n\\begin{proof}\nFor every $x:A$ we have $\\bproj{\\refl{x}}:\\brck{x=x}$, so the relation is reflexive. To see that the relation is symmetric note that by the universal property of propositional truncation there is a unique map $\\brck{\\invfunc}:\\brck{x=y}\\to\\brck{y=x}$ for which the square\n\\begin{equation*}\n\\begin{tikzcd}\n(x=y) \\arrow[r,\"\\invfunc\"] \\arrow[d,swap,\"\\bproj{\\blank}\"] & (y=x) \\arrow[d,\"\\bproj{\\blank}\"] \\\\\n\\brck{x=y} \\arrow[r,densely dotted,swap,\"\\brck{\\invfunc}\"] & \\brck{y=x}\n\\end{tikzcd}\n\\end{equation*}\ncommutes. This shows that the relation is symmetric. Similarly, we show by the universal property of propositional truncation that the relation is transitive.\n\\end{proof}\n\n\\begin{defn}\nFor each type $A$ we define the \\define{set truncation}\n\\begin{equation*}\n\\trunc{0}{A}\\defeq A/I_{(-1)},\n\\end{equation*}\nand the unit of the set truncation is defined to be the quotient map.\n\\end{defn}\n\n\\begin{thm}\nFor each type $A$, the set truncation satisfies the universal property of the set truncation.\n\\end{thm}\n\n\\begin{exercises}\n  \\exercise Consider a map $f:A\\to B$ into a set $B$, and let $R:A\\to(A\\to\\prop)$ be the equivalence relation given by\n  \\begin{equation*}\n    R(x,y)\\defeq f(x)=f(y).\n  \\end{equation*}\n  Show that the map $q_f:A\\to\\im(f)$ satisfies the universal property of the set quotient of $R$.\n  \\exercise Show that the set truncation of a loop space is a group.\n  \\exercise Recall that a normal subgroup $H$ of a group $G$ is a subgroup of $G$ such that $ghg^{-1}$ is in $H$ for every $h:H$ and $g:G$. Given a normal subgroup $H$ of $G$, we write $G/H$ for the quotient of $G$ by the equivalence relation where $g\\sim g'$ if and only if there is a $h:H$ such that $gh=g'$. Show that $G/H$ is again a group. \n\\exercise\n\\begin{subexenum}\n\\item Show that any proposition is locally small.\\index{proposition!is locally small}\n\\item Show that any essentially small type is locally small.\\index{essentially small!type!is locally small}\n\\item Show that the function type $A\\to X$ is locally small whenever $A$ is essentially small and $X$ is locally small.\n\\end{subexenum}\n\\exercise Let $f:A\\to B$ be a map. Show that the following are equivalent:\n\\begin{enumerate}\n\\item The map $f$ is \\define{locally small}\\index{locally small!map} in the sense that for every $x,y:A$, the action on paths of $f$\n\\begin{equation*}\n\\apfunc{f}:(x=y)\\to (f(x)=f(y))\n\\end{equation*}\nis an essentially small map.\n\\item The diagonal $\\delta_f$ of $f$ as defined in \\cref{ex:trunc_diagonal_map} is classified by the universal fibration.\n\\end{enumerate}\n\\exercise \\label{ex:span_rel}Use \\cref{thm:choice,thm:fam_proj,cor:times_up_out} to show that the type \n\\begin{equation*}\n\\mathsf{span}(A,B)\\defeq \\sm{S:\\UU} (S\\to A)\\times (S\\to B)\n\\end{equation*}\nof small spans from $A$ to $B$ is equivalent to the type $A\\to (B\\to\\UU)$ of small relations from $A$ to $B$.\n\\end{exercises}\n\n\\endinput\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{comment}\n\\begin{thm}\\label{thm:fam_proj}\nFor any small type $A:\\UU$ there is an equivalence\n\\begin{equation*}\n\\mathsf{map\\usc{}fam}_A:\\eqv{(A\\to \\UU)}{\\Big(\\sm{X:\\UU} X\\to A\\Big)}.\n\\end{equation*}\n\\end{thm}\n\n\\begin{proof}\nNote that we have the function\n\\begin{equation*}\n\\varphi :\\lam{B} \\Big(\\sm{x:A}B(x),\\proj 1\\Big) : (A\\to \\UU)\\to \\Big(\\sm{X:\\UU}X\\to A\\Big).\n\\end{equation*}\nThe fiber of this map at $(X,f)$ is by univalence and function extensionality equivalent to the type\n\\begin{equation*}\n\\sm{B:A\\to \\UU}{e:\\eqv{(\\sm{x:A}B(x))}{X}} \\proj 1\\htpy f\\circ e.\n\\end{equation*}\nBy \\cref{ex:triangle_fib} this type is equivalent to the type\n\\begin{equation*}\n\\sm{B:A\\to \\UU}\\prd{a:A} \\eqv{B(a)}{\\fib{f}{a}},\n\\end{equation*}\nand by `type theoretic choice', which was established in \\cref{thm:choice}, this type is equivalent to\n\\begin{equation*}\n\\prd{a:A}\\sm{X:\\UU}\\eqv{X}{\\fib{f}{a}}.\n\\end{equation*}\nWe conclude that the fiber of $\\varphi$ at $(X,f)$ is equivalent to the type $\\mathsf{ess\\usc{}small}(f)$. However, since $f:X\\to A$ is a map between small types it is essentially small. Moreover, since being essentially small is a proposition by \\cref{lem:isprop_ess_small}, it follows that $\\fib{\\varphi}{(X,f)}$ is contractible for every $f:X\\to A$. In other words, $\\varphi$ is a contractible map, and therefore it is an equivalence.\n\\end{proof}\n\n\\begin{rmk}\nThe inverse of the map\n\\begin{equation*}\n\\varphi : (A\\to \\UU)\\to \\Big(\\sm{X:\\UU}X\\to A\\Big).\n\\end{equation*}\nconstructed in \\cref{thm:fam_proj} is the map $(X,f)\\mapsto \\fibf{f}$.\n\\end{rmk}\n\n\\begin{thm}\\label{thm:classifier}\nLet $f:A\\to B$ be a map. Then there is an equivalence\n\\begin{equation*}\n\\eqv{\\mathsf{ess\\usc{}small}(f)}{\\mathsf{is\\usc{}classified}(f)},\n\\end{equation*}\nwhere $\\mathsf{is\\usc{}classified}(f)$\\index{is_classified(f)@{$\\mathsf{is\\usc{}classified}(f)$}} is the type of quadruples $(F,\\tilde{F},H,p)$ consisting of maps\n$F:B\\to \\UU$ and $\\tilde{F}:A\\to \\sm{X:\\UU}X$, a homotopy $H:F\\circ f\\htpy \\proj 1\\circ \\tilde{F}$,  such that the commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[r,\"\\tilde{F}\"] \\arrow[d,swap,\"f\"] & \\sm{X:\\UU}X \\arrow[d,\"\\proj 1\"] \\\\\nB \\arrow[r,swap,\"F\"] & \\UU\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square, as witnessed by $p$\\footnote{The universal property of the pullback is not expressible by a type. However, we may take the type of $p:\\isequiv(h)$, where $h:A\\to B\\times_\\UU\\big(\\sm{X:\\UU}X\\big)$ is the map obtained by the universal property of the canonical pullback.}. If $f$ comes equipped with a term of type $\\mathsf{is\\usc{}classified}(f)$, we also say that $f$ is \\define{classified}\\index{classified by the universal family} by the universal family. \n\\end{thm}\n\n\\begin{proof}\nFrom \\cref{ex:sq_fib} we obtain that the type of pairs $(\\tilde{F},H)$ is equivalent to the type of fiberwise transformations\n\\begin{equation*}\n\\prd{b:B}\\fib{f}{b}\\to F(b).\n\\end{equation*}\nBy \\cref{cor:pb_fibequiv} the square is a pullback square if and only if the induced map\n\\begin{equation*}\n\\prd{b:B}\\fib{f}{b}\\to F(b)\n\\end{equation*}\nis a fiberwise equivalence. Thus the data $(F,\\tilde{F},H,pb)$ is equivalent to the type of pairs $(F,e)$ where $e$ is a fiberwise equivalence from $\\fibf{f}$ to $F$. By \\cref{thm:choice} the type of pairs $(F,e)$ is equivalent to the type $\\mathsf{ess\\usc{}small}(f)$. \n\\end{proof}\n\n\\begin{rmk}\nFor any type $A$ (not necessarily small), and any $B:A\\to \\UU$, the square\\index{Sigma-type@{$\\Sigma$-type}!as pullback of universal family}\n\\begin{equation*}\n\\begin{tikzcd}[column sep=6em]\n\\sm{x:A}B(x) \\arrow[d,swap,\"\\proj 1\"] \\arrow[r,\"{\\lam{(x,y)}(B(x),y)}\"] & \\sm{X:\\UU}X \\arrow[d,\"\\proj 1\"] \\\\\nA \\arrow[r,swap,\"B\"] & \\UU\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square. Therefore it follows that for any family $B:A\\to\\UU$ of small types, the projection map $\\proj 1:\\sm{x:A}B(x)\\to A$ is an essentially small map.\nTo see that the claim is a direct consequence of \\cref{lem:pb_subst} we write the asserted square in its rudimentary form:\n\\begin{equation*}\n%\\begin{gathered}[b]\n\\begin{tikzcd}[column sep=6em]\n\\sm{x:A}\\mathrm{El}(B(x)) \\arrow[d,swap,\"\\proj 1\"] \\arrow[r,\"{\\lam{(x,y)}(B(x),y)}\"] & \\sm{X:\\UU}\\mathrm{El}(X) \\arrow[d,\"\\proj 1\"] \\\\\nA \\arrow[r,swap,\"B\"] & \\UU.\n\\end{tikzcd}%\\\\[-\\dp\\strutbox]\\end{gathered}\\qedhere\n\\end{equation*}\n\\end{rmk}\n\nIn the following theorem we show that a type is locally small if and only if its diagonal is classified by $\\UU$.\n\n\\begin{thm}\nLet $A$ be a type. The following are equivalent:\n\\begin{enumerate}\n\\item $A$ is locally small.\\index{locally small}\n\\item There are maps $I:A\\times A\\to\\UU$ and $\\tilde{I}:A\\to\\sm{X:\\UU}X$, and a homotopy $H:I\\circ \\delta_A\\htpy \\proj 1\\circ\\tilde{I}$\nsuch that the commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[r,\"\\tilde{I}\"] \\arrow[d,swap,\"\\delta_A\"] & \\sm{X:\\UU}X \\arrow[d,\"\\proj 1\"] \\\\\nA\\times A \\arrow[r,swap,\"{I}\"] & \\UU\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\\index{diagonal!of a type}\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nIn \\cref{ex:diagonal} we have established that the identity type $x=y$ is the fiber of $\\delta_A$ at $(x,y):A\\times A$. Therefore it follows that $A$ is locally small if and only if the diagonal $\\delta_A$ is essentially small.\nNow the result follows from \\cref{thm:classifier}.\n\\end{proof}\n\n\\subsubsection{Univalent universes are object classifiers}\n\n\\begin{defn}\n  Consider a map $p:E\\to B$ and a map $f:X\\to Y$. The type $\\cart(f,p)$ of \\define{cartesian morphisms} from $f$ to $p$ is the type of quadruples $(g,h,H,t)$ consisting of maps\n  \\begin{align*}\n    g & : Y\\to B \\\\\n    h & : X\\to E,\n  \\end{align*}\n  a homotopy $H:g\\circ f\\htpy p\\circ h$, and a term $t$ witnessing that the commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      X \\arrow[r,\"h\"] \\arrow[d,swap,\"f\"] & E \\arrow[d,\"p\"] \\\\\n      Y \\arrow[r,swap,\"g\"] & B\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pullback square.\n\\end{defn}\n\n\\begin{defn}\n  A map $p:E\\to B$ is called an \\define{object classifier} if for every map $f:X\\to Y$, the type $\\cart(f,p)$ of cartesian morphisms\n  \\begin{equation*}\n    \\begin{tikzcd}\n      X \\arrow[r] \\arrow[d,swap,\"f\"] & E \\arrow[d,\"p\"] \\\\\n      Y \\arrow[r] & B\n    \\end{tikzcd}\n  \\end{equation*}\n  from $f$ to $p$ is a proposition. \n\\end{defn}\n\n\\begin{prp}\n  Consider a map $p:E\\to B$. The following are equivalent:\n  \\begin{enumerate}\n  \\item The map $p$ is an object classifier.\n  \\item The function\n    \\begin{equation*}\n      \\tr_{\\fibf{p}}:(x=y)\\to (\\fib{p}{x}\\simeq\\fib{p}{y})\n    \\end{equation*}\n    is an equivalence.\n  \\end{enumerate}\n\\end{prp}\n\n\\begin{cor}\n  A universe is an object classifier if and only if it is univalent.\n\\end{cor}\n\\end{comment}", "meta": {"hexsha": "1a1ebb9d3a24a65045e53e70cfb2b2a871773680", "size": 28054, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/sets.tex", "max_stars_repo_name": "hemangandhi/HoTT-Intro", "max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 333, "max_stars_repo_stars_event_min_datetime": "2018-09-26T08:33:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:50:15.000Z", "max_issues_repo_path": "Book/sets.tex", "max_issues_repo_name": "hemangandhi/HoTT-Intro", "max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-06-18T04:16:04.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-16T15:27:01.000Z", "max_forks_repo_path": "Book/sets.tex", "max_forks_repo_name": "hemangandhi/HoTT-Intro", "max_forks_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2018-09-26T09:08:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T00:33:50.000Z", "avg_line_length": 53.3346007605, "max_line_length": 683, "alphanum_fraction": 0.6804733728, "num_tokens": 9375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7020777820307497}}
{"text": "\n\\section{Derivation of \\Cref{heuristic:error_quad_high_order} \\label{app:proof_of_error_quad_high_order}}\nWe are interested in computing the error incurred when approximating a \\twod surface integral with an interpolatory quadrature rule. \nIn \\oned on the interval $[-1,1]$, we're interested in the quantity\n%\\begin{equation}\n%    R_q[f] = I[f] - Q_q[f] \\label{eq:rem1d},\\quad\\mathrm{where}\\quad \n%  I[f] = \\int_{-1}^1 f(x) dx, \\quad\n%  Q_q[f] = \\sum_{i=0}^q f(x_i)w_i,\n%\\end{equation}\n\\begin{align}\n  R_q[f] &= I[f] - Q_q[f] \\label{eq:rem1d}\\\\\n  \\shortintertext{where}\n  I[f] &= \\int_{-1}^1 f(x) dx\\\\\n  Q_q[f] &= \\sum_{i=0}^q f(x_i)w_i,\\\\\n\\end{align}\nfor quadrature weights $w_i$ for a $q$-point quadrature rule.\nFor a \\twod double integral, we define a similar relationship between the remainder, the exact integral and the $q$th order quadrature rule:\n%\\begin{equation}\n%    R^{(2)}_q[f] = I^{(2)}[f] - Q^{(2)}_q[f]\\label{eq:rem2d}, \\quad\\mathrm{where}\\quad\n%    I^{(2)}[f] = \\int_{-1}^1\\int_{-1}^1 f(s,t) dsdt,\\quad\n%    Q^{(2)}_q[f] = \\sum_{j=0}^q\\sum_{i=0}^q f(s_i,t_j)w_iw_j.\n%\\end{equation}\n\\begin{align}\n  R^{(2)}_q[f] &= I^{(2)}[f] - Q^{(2)}_q[f]\\label{eq:rem2d}\\\\\n  \\shortintertext{where}\n    I^{(2)}[f] &= \\int_{-1}^1\\int_{-1}^1 f(s,t) dsdt\\\\\n  Q^{(2)}_q[f] &= \\sum_{j=0}^q\\sum_{i=0}^q f(s_i,t_j)w_iw_j,\n\\end{align}\n\nFor a function of two variables $f(s,t)$, we will denote $I_s[f] = \\int_{-1}^1f(s,\\cdot)ds$ as integration with respect to the $s$ variable only, which produces a function of $t$.\nThe same subscript notation applies to $R_{q,s}[f]$ and $Q_{q,s}[f]$ and use similar notation  for $t$: we apply the \\oned functional to the variable in the subscript, producing a \\oned function in the remaining variable.\nWe observe that \n\\begin{equation}\n  I^{(2)}[f] = \\int_{-1}^1\\left(\\int_{-1}^1 f(s,t) ds\\right)dt = \\int_{-1}^1 I_s[f] dt = I_t[I_s[f]]\n  \\label{eq:rem2d_to_1d}\n\\end{equation}\nFollowing the discussion in \\cite{aT2}, we substitute into \\cref{eq:rem2d_to_1d} and have\n\\begin{align}\n  %R^{(2)}_n[f] &= I^{(2)}[f] - Q^{(2)}_n[f]\\label{eq:rem2d}\\\\\n  I^{(2)}[f] &= I_t[R_{q,s}[f] + Q_{q,s}[f]]\\\\\n         &= R_{q,t}[R_{q,s}[f] + Q_{q,s}[f]] + Q_{q,t}[R_{q,s}[f] + Q_{q,s}[f]] \\\\\n         &= R_{q,t}[R_{q,s}[f]] + Q_{q,s}[R_{q,t}[f]] + Q_{q,t}[R_{q,s}[f]] +Q_{q,t}[Q_{q,s}[f]]\n\\end{align}\nWe assume that the higher-order ``remainder of remainder'' term contributes negligibly to the error.\nAlthough it has been shown that this term has a non-trivial contribution to a tight error estimate \\cite{elliott2015complete}, %here and in \\cref{sec:quad_error_heuristic}, \nwe are able to provide a sufficiently tight upper bound.\nFor large $q$, the quadrature rule approaches the value of the integral, i.e., $Q_{q,\\beta} \\approx I_\\beta$ for $\\beta =s,t$, we're left with:\n\\begin{align}\n  I^{(2)}[f] &\\approx  I_s[R_{q,t}[f]] + I_t[R_{q,s}[f]] +Q^{(2)}_q[f],\\\\\n  \\shortintertext{and hence:}\n  R^{(2)}_q[f] &\\lesssim  I_s[R_{q,t}[f]] + I_t[R_{q,s}[f]] \\label{eq:rem2d_int},\n\\end{align}\nwhere $\\lesssim$ means \"approximately less than or equal to.\"\nFrom \\cite[Theorem 5.1]{trefethen2008gauss}, we recall that for a \\oned function $\\theta$ defined on $[-1,1]$, if $Q_q[\\theta]$ is computed with Clenshaw-Curtis quadrature, $\\theta$ is $C^k$ and $\\|\\theta^{(k)}\\|_T < V$ on $[-1,1]$ for real finite $V$, then for sufficiently large $q$, the following inequality holds\n\\begin{equation}\n  R_q[\\theta] \\leq \\frac{32V}{15\\pi k(2q+1-k)^k},\n  \\label{eq:tref_ccquad2d}\n\\end{equation}\nwhere $\\|\\alpha(x)\\|_T = \\|\\alpha^\\prime/\\sqrt{1-x^2}\\|_1$.\nWe're interested in integrating a function $\\tilde{\\theta}$ over an interval $[-h,h]$ for various $h$.\nIf $\\tilde{\\theta}$ is $C^k$ and $\\|\\tilde{\\theta}\\|_T < V^\\prime$ on $[-h,h]$ for a real constant $V^\\prime$ independent of $h$, then we can define $\\theta(x) = \\tilde{\\theta}(hx)$ on $[-1,1]$ and apply \n\\cref{eq:tref_ccquad2d}:\n\\begin{equation}\n  R_q[\\tilde{\\theta}] \\leq \\frac{32h^{k+1}V^\\prime}{15\\pi k(2q+1-k)^k}.\n  \\label{eq:tref_ccquad2d_variable_interval}\n\\end{equation}\nThis follows directly from the proof of \\cite[Theorem 4.2]{trefethen2008gauss} applied to $\\theta$ by replacing $\\theta$ with $\\tilde{\\theta}(hx)$ and noting that $\\theta^{(k)}(x) = h^k \\tilde{\\theta}^{(k)}(hx)$.\nThe change of variables produces the first power of $h$, while each of the $k$ integration by parts produces an additional power of $h$.\nIn the context of \\qbkix, the size of $h$ is proportional to the edge length of the subdomain $D_i$ outlined in \\cref{sec:geom-def}.\n\nApplying \\cref{eq:tref_ccquad2d_variable_interval} to \\cref{eq:rem2d_int}, and again letting $f(s,t) = \\Theta(hs,ht)$, gives us\n\\begin{equation}\n  R^{(2)}_q[f] \\lesssim \\frac{32h^{k+1}}{15\\pi k (2q+1-k)^k}\\left[I_s[V^\\prime_t(s)] + I_t[V^\\prime_s(t)]\\right] \\label{eq:quad_err_1d}\n\\end{equation}\nwhere $V^\\prime_t(s)=\\max_t\\|\\Theta^{(k)}(hs, ht)\\|_T$ and $V^\\prime_s(t)=\\max_s\\|\\Theta^{(k)}(hs, ht)\\|_T$ for fixed values of $s,t$.\nIf we can choose a $\\tilde{V}$ that is strictly greater than $V^\\prime_s(t)$ and $V^\\prime_t(s)$ for any $s,t$ in $\\mathcal{I}^{(2)}$, we are left with\n\\begin{equation}\n  R^{(2)}_q[f] \\lesssim \\frac{128h^{k+1}\\tilde{V}}{15\\pi k (2q+1-k)^k}.\\label{eq:quad_err_final}\n\\end{equation}\n\nApplying this to the integration of double layer potentials, we can simply let $\\tilde{V}$ be the largest variation of the $k$th partial derivatives of the integrand of any single patch in \\cref{eq:double_layer_patches}.\nIn fact, we know that this value is achieved at the projection of $\\vx$ on the patch $P_i$ closest to $\\vx$, i.e., $(s^*,t^*) = \\mathrm{argmin}_{\\mathcal{I}^{(2)}} \\|\\vx - P_i(s,t)\\|_2$. \n We can also choose $h = \\max_i h_i$ to observe standard high-order convergence as a function of patch domain size, which we summarize in the following theorem.\n  The smoothness and bounded variation assumptions required to apply \\cref{eq:tref_ccquad2d} to our layer potential follow directly from the smoothness of $u(\\vx)$ in $\\Omega$.\n  Our heuristic directly follows.\n", "meta": {"hexsha": "6f80f503ad66b615d0eb2190fcc1e3c416e83a9c", "size": 6009, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hedgehog/quad_error_heuristic.tex", "max_stars_repo_name": "mmorse1217/nyu-thesis-template", "max_stars_repo_head_hexsha": "dbbef3f00a1e91d6f481b4c6cb480d40960b13c8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hedgehog/quad_error_heuristic.tex", "max_issues_repo_name": "mmorse1217/nyu-thesis-template", "max_issues_repo_head_hexsha": "dbbef3f00a1e91d6f481b4c6cb480d40960b13c8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hedgehog/quad_error_heuristic.tex", "max_forks_repo_name": "mmorse1217/nyu-thesis-template", "max_forks_repo_head_hexsha": "dbbef3f00a1e91d6f481b4c6cb480d40960b13c8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.8720930233, "max_line_length": 316, "alphanum_fraction": 0.663837577, "num_tokens": 2250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7020777740572052}}
{"text": "\\section{Complex: Complex Numbers}\nThis module has had an interesting history.  It started as a reimplementation\nof NR92's Appendix C.  I [HGG] didn't know about the section 5.4, which\nexplains the algorithms, so I had to reverse engineering the code itself.\nOnce I understood the issues, I reimplemented.  I also looked for\nand used alternative references for several of the functions.\n\nLater, I added the transcendentals from Krey88, ch 12, pp765-\n766. \n\nIn March of 1996, Warren Smith made contact and submitted a wealth of\nnew code, some dependent on his own Complex module.  I folded that into\nthe existing Complex, assuring both HGG and WDS conventions could be used.\nI removed some of my old code and replaced it with WDS implementations.\nSome of the old code I left as is.  Notice that the results depend on\nstructural equivalence in type checking --- doing this in a language\nwhich required name equivalence would have been grim. \n\nWDS generally documents his work meticulously in extended comments.  \nFor other modules I have translated those to \\TeX\\ format.  \nHowever, for this\nmodule there is relatively little documentation provided, so none is\npresented here.\n\n\\subsection*{add, sub}\nTrivial\n\n\\subsection*{mul}\nSee also Hopk88, pp35-36\n\\begin{verbatim}\n     c3.re:=c1.re*c2.re-c1.im*c2.im;\n     c3.im:=c1.im*c2.re+c1.re*c2.im\n\\end{verbatim}     \n\n\n\\subsection*{div}\nThis is retained as hgg\\_div, but WDS's implementation is exported.\n\nThe basic formula (CRC91, pg 337) is [x is re and y is im]:\n\\begin{equation}\n  \\frac{(x_1x_2+y_1y_2) + i(x_2y_1-x_1y_2)}\n       {x_2^2 + y_2^2}\n\\end{equation}\nHowever, this takes 8 multiplies.  Also, if x2 and y2 are\ndifferent in magnitude, there can be truncation errors.  So,\nif x2 is the biggest, we divide top and bottom by 1/x2:\n\\begin{equation}\n  \\frac{(x_1+y_1(y_2/x_2)) + i(y_1 - x_1(y_2/x_2))}\n       {x_2 + y_2*(y_2/x_2)}\n\\end{equation}\nNotice how the ratio $y_2/x_2$ repeats.  Also, we use the\ndenominator for both the re and im portions.  We now have 6\nmultiplies, and the opportunity to prevent at least some\ntruncations.\n\n\\subsection*{abs}\nSee WDS's Magnitude comments.\n\nThe basic formula (CRC91, pg 337) is\n\\begin{equation}\n  |z| = \\sqrt{(x^2 + y^2)}\n\\end{equation}\n     \nThe simple cases of $x=0$ or $y=0$ can be resolved right away.\n\nOtherwise, if x and y are different in magnitude, we can\nhave truncation error.  In 64-bits, we have $EPS=1e-17$, so\n$x/y$ (or $y/x$) would have to be that extreme to cause a\nproblem.  I'll take that chance.\n\nIf the problem does arise, or if one needs a 32-bit\nrepresentation (where the trouble arises much sooner), do a\nnormalization.  See also NR92:\n\\begin{verbatim}\n     x:=|x|; y:=|y|;\n     if x > y then r=y/x and:\n     \n     |z| = (x^2+y^2)^1/2\n         = [x^2*(1+y^2/x^2)]^1/2\n         = x*(1+(y^2/x^2)^1/2\n         = x*(1+(y/x)^2)^1/2\n         = x*(1+r*r)^1/2, x > 0\n\\end{verbatim}\n          \nNow we have $1 + something\\_less\\_than\\_one$, which might still\ngive a truncation error but has a better chance than just\nadding the squares.  It costs an extra multiply.  Of course,\nif $y >x$, then the analysis is reversed.\n\\begin{verbatim}\n     if y>x then r=x/y and:\n     \n       |z| = (x^2+y^2)^1/2\n           = [y^2*(x^2/y^2+1)]^1/2\n           = y*(x^2/y^2 +1)^1/2\n           = y*((x/y)+1)^1/2\n           = y*(r^2+1)^1/2, y > 0\n\\end{verbatim}\n\n\\subsection*{sqrt}\nSee WDS's Sqrt comments.\n\nThe basic formula (Krey88, pg 730, eqn 17) is\n\\begin{equation}\n  \\sqrt{z} = \\pm \\left[ \\sqrt{\\frac{1}{2}(|z| + x)} +\n     \\mbox{sign}(y)*i*\\sqrt{\\frac{1}{2}(|z| - x)}\\right]\n\\end{equation}\n\nThis seems to do ok.  NR92, pg177 provides a different set\nof formulas.  When time permits, we should do accuracy and\ntiming comparisons.\n\n\\subsection*{exp, ln}\nFrom Krey88.\n\n\\subsection*{powN, powXY}\nFrom Krey88.\n\n\n\\subsection*{cos, sin, tan}\nFor cos, the formula is:\n\\begin{equation}\n  \\cos(z)=\\cos(x)\\cosh(y) - i \\sin(x)\\sinh(y)\n\\end{equation}\n\nWhere:\n\\begin{equation}\n  \\cosh(x)=\\frac{1}{2}(e^{x} + e^{-x})\n\\end{equation}\n\nOr:\n\\begin{verbatim}\n     ex:=exp(x); ey:=exp(y);\n     tmp.re:=+0.5*cos(x)*(ex-1.0/ex)\n     tmp.im:=-0.5*sin(x)*(ey-1.0/ey)\n\\end{verbatim}\n\nClearly there is opportunity for truncation in the ex and ey\nterms.  Is it a problem? Taking the ex term to be specific:\nThere is truncation if the exponents of $e^x$ and $e^{-x}$ differ\nby more than 17.  This the exponent of $e^x$ can be up to $1/2$\nof this or $17/2 = 8$.  Thus x can be up to $\\ln(1E8)=~18$.  By\nusing MathCAD, we find we can get to $x=~20$ before blowing\nup.\n\nAlternatively, factor out $e^{-x}$:\n\\begin{verbatim}\n     tmp.re:=+0.5*cos(x)*(ex*ex+1.0)/ex;\n\\end{verbatim}\n\nThis may or may not be more stable, but doesn't fundamental\nshift x's range.  We are still in the $|x|<=18$ range.\n\nIs that enough?  CRC91 provides table values to $x=10$.  Let's\naccept 18 as the top end, document this, and report an\nexception if we go over that.  This will be true of both the\nx and y inputs.\n\\begin{tt} \\begin{verbatim}\n     IF ABS(c.re) > 18.0D0 OR ABS(c.im)> 18.0D0 THEN\n       RAISE Error{Err.out_of_range};\n     END;\n\\end{verbatim} \\end{tt}\n\nsin is of course similar.  Notice that for sin and cos there\nare no opportunities for ex and ey reuse.  We may as well\nuse the Math cosh, sinh functions (hoping they are more\nrobust than our own analysis here).\n\ntan is $sin/cos$:  In this case we can probably reuse ex, ey\nfrom the various cosh and sinh calculations. For now we\nhowever, we will do it naively.\n\n\n\\subsection*{cosh, sinh, tanh}\nThe formula is:\n\\begin{equation}\n  \\cosh(z)=\\frac{1}{2}(e^{z}+e^{-z})=\\cos(i z)\n\\end{equation}\n     \nWhere $e^z$ is found by\n\\begin{verbatim}\n       ex:=exp(z.re);\n       tmp.re:= ex*cos(z.im);\n       tmp.im:= ex*sin(z.im);\n\\end{verbatim}\n\nOnce again, we can do a full analysis, or just take the easy\nway out.  If we ever get into a problem space requiring\nhyperbolics in an inner loop, we should do timing analysis.\nFor now we will take the easy way out:\n\\begin{verbatim}\n     cosh(z) = cos(i*z) = cos(i*z.re + i*i*z.im) = cos(-z.im + i*z.re)\n     \n     tmp.re:=-z.im;\n     tmp.im:=+z.re;\n     tmp:=C.cos(tmp);\n     return tmp;\n\\end{verbatim}\n\nsin is similar:\n\\begin{verbatim}\n     sinh(z) = -i*sin(i*z) = -i*(-z.im + i*z.re)\n     \n     tmp.re:=-z.im;\n     tmp.im:=+z.re;\n     tmp:=C.sin(tmp);\n     (*tmp.re = -i*i*tmp.im = tmp.im*)\n     (*tmp.im = -i*tmp.re* = -tmp.re*)\n     t:=tmp.im;\n     tmp.im:=-tmp.re;\n     tmp.re:=t;\n     return tmp;\n\\end{verbatim}\n\n\\subsection*{pmul, pdiv}\nIf we happen to be in polar form, then multiplication and\ndivision are simple.  For pmul:\n\\begin{verbatim}\n     tmp.radius:=p1.radius*p2.radius;\n     tmp.angle:=p1.angle+p2.angle\n\\end{verbatim}\n\nFor pdiv:\n\\begin{verbatim}\n     tmp.radius:=p1.radius/p2.radius;\n     tmp.angle:=p1.angle-p2.angle\n\\end{verbatim}\n\nIn addition, we need to normalize the angles to the $-\\pi \\dots +\\pi$\nrange:\n\\begin{tt} \\begin{verbatim}\n     WHILE tmp.angle < -Pi DO\n       tmp.angle:=tmp.angle + TwoPi;\n     END;\n     WHILE tmp.angle > Pi DO\n       tmp.angle:=tmp.angle - TwoPi;\n     END;\n\\end{verbatim} \\end{tt}\n\nNOTE:  {\\tt arg} and {\\tt toPolar} use {\\tt atan2}, which does\nthe normalization itself, so we don't need to handcraft\nnormalization code for them.\n", "meta": {"hexsha": "ed393139a180554c172ea42d79e9c0be0900a073", "size": 7228, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "m3-libs/arithmetic/doc/complex.tex", "max_stars_repo_name": "jaykrell/cm3", "max_stars_repo_head_hexsha": "2aae7d9342b8e26680f6419f9296450fae8cbd4b", "max_stars_repo_licenses": ["BSD-4-Clause-UC", "BSD-4-Clause", "BSD-3-Clause"], "max_stars_count": 105, "max_stars_repo_stars_event_min_datetime": "2015-03-02T16:58:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T07:17:49.000Z", "max_issues_repo_path": "m3-libs/arithmetic/doc/complex.tex", "max_issues_repo_name": "jaykrell/cm3", "max_issues_repo_head_hexsha": "2aae7d9342b8e26680f6419f9296450fae8cbd4b", "max_issues_repo_licenses": ["BSD-4-Clause-UC", "BSD-4-Clause", "BSD-3-Clause"], "max_issues_count": 145, "max_issues_repo_issues_event_min_datetime": "2015-03-18T10:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T01:27:08.000Z", "max_forks_repo_path": "m3-libs/arithmetic/doc/complex.tex", "max_forks_repo_name": "jaykrell/cm3", "max_forks_repo_head_hexsha": "2aae7d9342b8e26680f6419f9296450fae8cbd4b", "max_forks_repo_licenses": ["BSD-4-Clause-UC", "BSD-4-Clause", "BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-10T09:37:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T02:02:05.000Z", "avg_line_length": 29.867768595, "max_line_length": 77, "alphanum_fraction": 0.6622855562, "num_tokens": 2368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127417985637, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7020777710005415}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{environ}\n\\usepackage{physics}\n\n\\NewEnviron{NORMAL}{% \n    \\scalebox{5}{$\\BODY$} \n} \n \n\n\\title{Using the Jacobian to map directional derivatives between coordinate systems}\n\\author{Max Sills }\n\\date{August 2020}\n\n% Defining bank of important matrices for easy reuuse\n\\newcommand{\\showMatrixOne}{\\ensuremath{\n\\begin{bmatrix}\n\\frac{x}{\\sqrt{x^2 + y^2}} & \\frac{y}{\\sqrt{x^2 + y^2}} \\\\\n\\frac{-y}{x^2 + y^2}       & \\frac{x}{x^2+y^2}          \n\\end{bmatrix}\n}}\n\n\\newcommand{\\showMatrixTwo}{\\ensuremath{\n\\begin{bmatrix}\n\\cos\\theta & sin\\theta  \\\\\n\\frac{-\\sin\\theta}{r} &  \\frac{\\cos\\theta}{r}\n\\end{bmatrix}\n}}\n\n\\newcommand{\\showMatrixThree}{\\ensuremath{\n\\begin{bmatrix}\n\\cos\\theta & -r\\,\\sin\\theta  \\\\\n\\sin\\theta &  r\\,\\cos\\theta\n\\end{bmatrix}\n}}\n\n\\newcommand{\\showMatrixFour}{\\ensuremath{\n\\begin{bmatrix}\n\\frac{x}{\\sqrt{x^2 + y^2}} & -y \\\\\n\\frac{y}{\\sqrt{x^2 + y^2}} & x     \n\\end{bmatrix}\n}}\n% End matrix bank\n\n\\begin{document}\n\\maketitle\n\n\\section{Mapping gradients between coordinate systems}\n\nStart with a function U in cartesian coordinates, and U' for that function expressed in polar coordinates.\n\nWe can use the change of coordinates formula to express U' given U\n\n\n\\[ x = r * cos(\\theta) \\]\n\\[ y = r * sin (\\theta)\\]\n\n\nNow say we were able to express the gradient of U in cartesian coordinates\n\\[\n\\nabla U = \\frac{\\partial U} {\\partial x}+\n\\frac{\\partial U} {\\partial y}\n\\]\n\nHow could we express the gradient of U' in polar coordinates? Well, we've already been given U' in polar coordinates, so we could compute the gradient directly. However, we can also use the chain rule, the change of coordinates formula, and our knowledge of the gradient in cartesian coordinates to directly derive the gradient in polar coordinates.\n\n$$\n\\nabla U' = \\frac{\\partial U'} {\\partial r}+\n\\frac{\\partial U'} {\\partial \\theta}\n$$\n\nBy the chain rule, \n\n$$\n\\frac{\\partial U'} {\\partial r} = \\frac{\\partial U'} {\\partial x}\\frac{\\partial x} {\\partial r}\n+ \n\\frac{\\partial U'} {\\partial y}\\frac{\\partial y} {\\partial r}\n$$\n\n$$\n\\frac{\\partial U'} {\\partial \\theta} = \\frac{\\partial U'} {\\partial x}\\frac{\\partial x} {\\partial \\theta}\n+ \n\\frac{\\partial U'} {\\partial y}\\frac{\\partial y} {\\partial \\theta}\n$$\n\nWe can rewrite these relations as a covector acting on a Jacobian\n\\begingroup\n\\LARGE\n\\begin{equation}\n\\left\\langle\n\\begin{matrix}\\frac{\\partial U}{\\partial r} & \\frac{\\partial U} {\\partial \\theta}\n\\end{matrix}\n\\right\\rangle=\\left\\langle\n\\begin{matrix}\\frac{\\partial U}{\\partial x} & \\frac{\\partial U} {\\partial y}\n\\end{matrix}\n\\right\\rangle\n*\n\\begin{bmatrix}\n\\frac{\\partial x}{\\partial r} & \\frac{\\partial y}{\\partial r}\\\\\\frac{\\partial x}{\\partial \\theta} & \\frac{\\partial y}{\\partial \\theta}\n\\end{bmatrix}\n\\end{equation}\n\\endgroup\n\nWe want to find the gradient of U in polar coordinates, which can be represented as the partials of U with respect to r and theta. This is equal to the matrix product of the covector of the gradient in cartesian coordinates which was found above, and the Jacobian, which can be entirely derived from the change of coordinates functions from cartesian to polar.\n\n\\section{Examples}\n\nBefore we work examples, let's identify the transition functions to and from polar coordinates and the corresponding Jacobians to make things easier.\n\n\\subsection{Cartesian to Polar}\n\n\n\\begin{align}\nr &= \\sqrt{x^2 + y^2} \\\\\n\\theta &= \\arctan{\\left(\\frac{y}{x}\\right)} \n\\end{align}\n\\begin{equation}\n\\showMatrixOne\n=\n\\showMatrixTwo\n\\end{equation}\n\n\\subsection{Polar to Cartesian}\n\\[ x = r * cos(\\theta) \\]\n\\[ y = r * sin (\\theta)\\]\n\n\\begin{equation}\n\\showMatrixThree \n=\n\\showMatrixFour\n\\end{equation}\n\n\\subsection{Example 1: U = x + y}\n\\[ U = x + y\\]\n\\[\\nabla U = \\pdv{U}{x} + \\pdv{U}{y} = <1,1>  \\]\n\nNow to express U in polar coordinates (r, theta) we find\n\\[ U = r*cos\\theta + r*sin\\theta  \\]\n\\[\\nabla U = cos\\theta + sin \\theta \\pdv{U}{r} \n+ r (cos\\theta - sin \\theta \\pdv{U}{\\theta} \\]\n\n\\begin{equation}\n\\begin{bmatrix}\ncos + sin & r(cos-sin)\n\\end{bmatrix}\n*\n\\begin{bmatrix}\n\\cos\\theta & sin\\theta  \\\\\n\\frac{-\\sin\\theta}{r} &  \\frac{\\cos\\theta}{r}\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n1 & 1\n\\end{bmatrix}\n\\end{equation}\n\nNow, how might we take an arbitrary directional derivative in the first coordinate system and map it to a directional derivative in the second?\n\nOur gradient in the first coordinate system is \n\\[\\begin{bmatrix}\n1 & 1\n\\end{bmatrix}\n\\]\n\nWhen we apply an arbitrary directional derivative (a, b), we produce a scalar:\n\\begin{displaymath}\n\\begin{bmatrix}\n1 & 1\n\\end{bmatrix}\n*\n\\begin{bmatrix}\na \\\\\nb\n\\end{bmatrix}\n=\na + b\n\\end{displaymath}\n\nApplying the Jacobian to the vector this time, instead of the gradient (covector) to the Jacobian, we find:\n\\begin{displaymath}\n\\showMatrixTwo\n*\n\\begin{bmatrix}\na \\\\\nb\n\\end{bmatrix}\n=\n\\begin{bmatrix}\na cos(\\theta) + b sin(\\theta) \\\\\n\\frac{-a sin(\\theta)}{r} +\n\\frac{b cos (\\theta)}{r}\n\\end{bmatrix}\n\\end{displaymath}\n\nFinally, applying this transformed vector to the gradient we found in polar coordinates we see:\n\n\n\\begin{displaymath}\n\\begin{bmatrix}\ncos + sin & r(cos-sin)\n\\end{bmatrix}\n*\n\\begin{bmatrix}\na cos(\\theta) + b sin (\\theta) \\\\\n\\frac{-a sin(\\theta)}{r} +\n\\frac{b cos (\\theta)}{r}\n\\end{bmatrix}\n=\n\\end{displaymath}\n\\begin{displaymath}\n\\begin{aligned}\n(acos + bsin)(cos + sin) + (cos- sin)(bcos -asin) \\\\\n= acos^2 + asin cos + bsin cos + bsin^2 \\\\\n+ bcos^2 - asin cos - bsin cos + a sin^2 \\\\\n= acos^2 + b sin^2 + bcos^2 + a sin^2 \\\\\n= a(cos^2 + sin^2) + b(cos^2 + sin^2) \\\\\n= a + b\n\\end{aligned}\n\\end{displaymath}\n\n\n\\subsection{Example 2: U(r, theta) = r *theta}\n\n\\[U = r * \\theta\\]\n\\[\\nabla U = \\theta \\pdv{U}{r}+ r \\pdv{U}{\\theta} \\]\n\nU(r, theta) in cartesian coordinates:\n\n\\[ U(x, y) =\\sqrt{x^2 +y^2}\n*\n\\arctan\\frac{y}{x} \\]\n\n\\begin{equation}\n\\nabla U =\n\\frac{x \\atan(y/x) - y}{\\sqrt{x^2 + y^2}}\n\\pdv{U}{x} \n+\n\\frac{y \\atan(y/x) + x}{\\sqrt{x^2 + y^2}}\n\\pdv{U}{y} \n\\end{equation}\n\\end{document}\n", "meta": {"hexsha": "63f7288c19420268c5858945d884e90d26ff6aeb", "size": 5954, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Jacobian.tex", "max_stars_repo_name": "sillsm/notes", "max_stars_repo_head_hexsha": "30c20e9e8fa35bea74beb061696ba945864062a6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Jacobian.tex", "max_issues_repo_name": "sillsm/notes", "max_issues_repo_head_hexsha": "30c20e9e8fa35bea74beb061696ba945864062a6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Jacobian.tex", "max_forks_repo_name": "sillsm/notes", "max_forks_repo_head_hexsha": "30c20e9e8fa35bea74beb061696ba945864062a6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.5020576132, "max_line_length": 360, "alphanum_fraction": 0.6741686261, "num_tokens": 1964, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891130942472, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7020777674808971}}
{"text": "\n\\subsection{Turbulence closure}\\label{sec-tur}\n\n\nWe use the \\citet{Umlauf2003} generic length-scale model:\n\\beqa\n  \\frac{\\D k}{\\D t}&=&\\frac{\\pd }{\\pd z}\\left( \\nu_k^\\Psi \\frac{\\pd k}{\\pd z} \\right)\n  +\\nu_t M^2+\\nu_t^\\theta N^2 -\\epsilon \\\\\n  \\frac{\\D \\Psi}{\\D t}&=& \\frac{\\pd }{\\pd z}\\left( \\nu_\\Psi \\frac{\\pd \\Psi}{\\pd z} \\right)\n    +\\frac{\\Psi}{k}(c_{\\Psi 1}\\nu_tM^2+c_{\\Psi 3}\\nu_t^\\theta N^2-c_{\\Psi 2}\\epsilon F_{wall})\n\\eeqa\nwith natural b.c.:\n\\beq\n   \\left\\{ \\begin{array}{ll}\n       \\nu_k^\\Psi \\frac{\\pd k}{\\pd z} &=0, \\mbox{ at } z=-h, \\mbox{ or } \\eta \\\\\n       \\nu_\\Psi\\frac{\\pd \\Psi}{\\pd z} &= \\kappa_0 n\\nu_\\Psi\\frac{\\Psi}{l} , \\mbox{ at } z=-h \\\\\n       \\nu_\\Psi\\frac{\\pd \\Psi}{\\pd z} &= -\\kappa_0 n\\nu_\\Psi\\frac{\\Psi}{l} , \\mbox{ at } z=\\eta \\\\\n           \\end{array}\n   \\right.  \\label{tur1}\n\\eeq\nand essential b.c.:\n\\beq\n   \\left\\{ \\begin{array}{ll}\n       k&=(c_\\mu^0)^{-2} \\nu|\\frac{\\pd \\bs{u}}{\\pd z}|, \\mbox{ at } z=-h, \\mbox{ or } \\eta\\\\\n       l&=\\kappa_0 \\D \\\\\n       \\Psi &= (c_\\mu^0)^pk^m(\\kappa_0 \\D)^n\n           \\end{array}\n   \\right.  \\label{tur2}\n\\eeq\nwhere $k$ is the TKE, $l$ is the mixing length, $c_{\\Psi *}$ are some constants and $\\Psi=(c_\\mu^0)^pk^m l^n$ is a generic length-scale variable.\nThe turbulence production and dissipation terms are:\n\\beqa\n  M^2&=&\\left( \\frac{\\pd u}{\\pd z}\\right)^2+\\left( \\frac{\\pd v}{\\pd z}\\right)^2 \\\\\n  N^2 &=&\\frac{g}{\\rho_0}\\frac{\\pd \\rho}{\\pd z} \\\\\n  \\epsilon &=& (c_\\mu^0)^3k^{1.5} l^{-1}\n\\eeqa\nIn the code, the natural b.c. is applied first (see the FEM formulation below), and the essential b.c. \n is then used to overwrite the boundary values of the unknown, as suggested by the \\gls{gotm} implementation.\n\nGOTM has also been coupled to SELFE, but the native (finite element) implementation is the one used for the Bay-Delta project.\n", "meta": {"hexsha": "8eb9b97af4d509b24805550e477f8e6fac467b8a", "size": 1815, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/form_turbulence.tex", "max_stars_repo_name": "water-e/BayDeltaSCHISM", "max_stars_repo_head_hexsha": "b532b51ef58a6ef3dbb4e74f82008a46db0f7686", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-15T20:59:16.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-15T20:59:16.000Z", "max_issues_repo_path": "documents/form_turbulence.tex", "max_issues_repo_name": "water-e/BayDeltaSCHISM", "max_issues_repo_head_hexsha": "b532b51ef58a6ef3dbb4e74f82008a46db0f7686", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2018-06-05T16:01:48.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-20T18:52:48.000Z", "max_forks_repo_path": "documents/form_turbulence.tex", "max_forks_repo_name": "water-e/BayDeltaSCHISM", "max_forks_repo_head_hexsha": "b532b51ef58a6ef3dbb4e74f82008a46db0f7686", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-06-04T16:45:56.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-29T23:01:47.000Z", "avg_line_length": 44.2682926829, "max_line_length": 145, "alphanum_fraction": 0.5928374656, "num_tokens": 727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567176, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.7020526263966067}}
{"text": " \n\\section{Soft-thresholding and Proximal gradient method}\n\\label{sec:soft-thresholding}\nRecall the unconstrained optimization problem\n$$\n\\min _{x} f(x)\n$$\nWe have seen the following results depending on the assumption for $f(x)$\n\\begin{enumerate}\n\\item If $f(x)$ is not smooth (for example: $L^1$ norm) which means $\\nabla f(x)$ is not continuous, subgradient descent method gives the $\\frac{1}{\\sqrt{n}}$ convergence.\n\\item If $f(x)$ is smooth (e.g. $\\nabla f(x)$ is L-Lipschitz continuous), gradient descent method gives the $\\frac{1}{n}$ convergence. \n\\end{enumerate}\nThere may be other methods (may be for particular functions) which can give better performance. Consider the following example:\n$$\nf(x)=\\frac{1}{2}\\|A x-b\\|_{2}^{2}+\\|x\\|_{1}\n$$\nThis is a type 1 problem described above, as the second term is not smooth. However, the objective has a special form. It can be represented as sum of smooth and non -smooth function. Also note that second term $\\|x\\|_{1}$ is \"simple\" in a sense that we describe precisely below. In this case, it is conceivable that some tailored method might do better than the generic guarantees offered by sub gradient descent. \n\nIn this section, we introduce what is known as the Proximal method, and show that it provides improved guarantees.  \n\n\\subsection{Proximal mapping}\\label{sec:proximal}\n\\begin{definition}\nThe proximal mapping or prox-operator of a function $f(x)$ is defined as\n\\begin{equation}\\label{pro:def}\n\\operatorname{Prox}_{f}(x)=\\arg \\min _{z}f(z)+\\frac{1}{2}\\|z-x\\|_{2}^{2}.\n\\end{equation}\n\\end{definition}\nNote that $f(x)$ is a convex function so the above problem \\eqref{pro:def} a strongly convex problem because of the added Euclidean norm term; therefore the solution is unique. Also for the proximal method to be efficient, we need that $f(x)$ should be simple in the sense that solving the problem \\eqref{pro:def}  should be easier and fast or may be even analytical solutions are possible. This condition is required to ensure that each step is not much costly. \n\n\\begin{properties}\nFrom the optimality conditions of minimization in the definition, we can see that $z^*$ is optimal point of $f(x)+\\frac12 \\|z-x\\|_2^2$ only if $0\\in \\partial f(x) + z^*-x$, namely\n\\begin{equation}\n\\begin{aligned}\nz^{*}=\\operatorname{Prox}_{f}(x) & \\Longleftrightarrow 0 \\in \\partial f(x)+\\left(z^{*}-x\\right) \\\\\n& \\Longleftrightarrow x-z^{*} \\in \\partial f(x) \\\\\n& \\Longleftrightarrow f(w)=f(z)+(x-z)^{T}(w-z)\\quad \\forall w\n\\end{aligned}\n\\end{equation}\n\\end{properties}\nThis property shows the relation between proximal mapping  and subgradient of  a function.\n\n\n\\begin{example}\nIf $f(x)=0$, \n$$\n\\operatorname{Prox}_{f}(x)=x.\n$$\n\\end{example}\n\\begin{example}\nIf $f(x)=|x|$\n$$\n\\begin{array}{l} \n\\operatorname{Prox}_{f}(x)=\\left\\{\\begin{array}{cl}\nx-1 & \\text { if } x\\geqslant 1 \\\\\n0 & \\text { if } -1 \\leqslant x \\leqslant 1    \\\\\nx+1 & \\text { if } x \\leqslant-1\n\\end{array}\\right.\n\\end{array}\n$$\t\n\t\\end{example}\n\\begin{example}\nIf \n\t$$\n\tf(x)=\\left\\{\\begin{array}{l}\n\t0 \\text { if } x \\in[-1,1] \\\\\n\t\\infty \\text { otherwise }\n\t\\end{array}\\right.\n\t$$\n$$ \t\\begin{array}{l}\n\t\\operatorname{Prox}_{f}(x)=\\left\\{\\begin{array}{cl}\n\t\t\tx & \\text { if } x \\in [-1, 1] \\\\\n\t\t\t1 & \\text { if } x>1   \\\\\n\t\t\t-1 & \\text { if } x < -1\n\t\t\\end{array}\\right.\n\t\\end{array}  $$\nwhich is the projection onto the set [-1,1].\nif $$\nf(x)=\\left\\{\\begin{array}{ll}\n0 & \\text { if } x \\in C \\\\\n\\infty & x \\notin C\n\\end{array}\\right.\n$$  these $ \\operatorname{prox}_{f}(x) $ is the projection onto C.\n\t\\end{example}\n\t\n%\\begin{example}\n%\tIf $ X=\\partial f $ where f is convex, what is $ prox_{f} $? \n%\t\n%\tFor $ x \\subset\\mathbb{R}^{d} $, solve for $ (x^{\\prime}, y^{\\prime}) \\in \\partial f $ s.t. \n%\t$$\n%\t x^{\\prime}+y^{\\prime}=x.\n%\t$$ Notice that \n%\t$$\n%\tx \\in \\operatorname{argmin} f \\Leftrightarrow 0 \\in \\partial f(x)\n%\t$$\n%\tAlso, for $ x \\in dom(f_{1}) \\cap dom(f_{2}) $, \n%\t$$\n%\t \\partial (f_{1}+f_{2}) (x)=\\partial f_{1}(x)+\\partial f_{2}(x)  :=\\left\\{y_{1}+y_{2} ; y_{1} \\in \\partial f_{1}(x), y_{2} \\in \\partial f_{2}(x)\\right\\}\n%\t $$ \n%\t$$\n%\t0\\in \\partial \\left(f(z)+\\frac{1}{2} \\|(x-z)\\|^{2}\\right)=\\partial f(z)-x+z\\Rightarrow x \\in z+ \\partial f(z).\n%\t$$\n%\t$$\n%\t\\operatorname{prox}_{f}(x)=\\operatorname{argmin}\\limits_{z}\\left(f(z)+\\frac{1}{2}\\|x-z\\|_2^{2}\\right)\n%\t$$\n%\t\\end{example}\n\t\n\\begin{theorem}[soft-thresholding]\nLet $f(x)=\\lambda\\|x\\|_1$. Soft-thresholding  is defined as \n\\begin{equation}\nprox_f(x) = \\arg\\min_z\\{\\frac{1}{2}\\|x-z\\|^2_2 + \\lambda\\|z\\|_1 \\},\n\\end{equation}\nwhich is shown in the following figure\n\\begin{figure}\n\\centering\n\\includegraphics[width=3in]{./6DL/figures/softthreshold}   \n%\\caption{Two linearly separable sets}\n\\end{figure}\nThe $l_1$-norm is is separable in indices. Each $i^{\\text {th }}$ coordinate can be optimized separately and the $i^{t h}$ coordinate is given as\n$$\nprox_f(x)_{i}=\\operatorname{sgn}\\left(x_{i}\\right)\\left[\\left|x_{i}\\right|-\\min \\left\\{\\left|x_{i}\\right|, \\lambda\\right\\}\\right]\n=\\begin{cases}\n0&|x_i|\\le \\lambda\n\\\\\nx_i-\\lambda&x_i>\\lambda\n\\\\\nx_i+\\lambda&x_i<-\\lambda\n\\end{cases}.\n$$ \n\\end{theorem}\n\n\\begin{proof}\nNote that\n\\begin{equation}\n0 \\in \\nabla(\\frac{1}{2}\\|x-z\\|^2_2) + \\partial(\\lambda\\|z\\|_1) \\Leftrightarrow 0 \\in z-x + \\lambda\\partial\\|z\\|_1\n\\end{equation}\nThe $l_1$-norm is separable and thus we can consider each of its components separately. Let's examine first the case where $z_i \\neq 0$. Then, $\\partial \\|z_i\\|=sign(z_i)$ and the optimum $z_i^*$ is obtained as\n\\begin{equation}\n0 = z_i-x_i + \\lambda sign(z_i) \\Leftrightarrow z_i^* = x_i - \\lambda sign(z_i^*)\n\\end{equation}\nNote also that if $z_i^* < 0$, then $x_i < -\\lambda$ and equivalently if $z_i^* > 0 \\Rightarrow x_i > \\lambda$. Thus, $|x_i| > \\lambda$ and $sign(z_i^*) = sign(x_i)$. Substituting in the previous equation we get \n\\begin{equation}\nz_i^* = x_i - \\lambda sign(x_i)\n\\end{equation}\nIn the case where $z_i = 0$, the subdifferential of the $l_1$-norm is the interval $[-1,1]$ and the optimality condition is\n\\begin{equation}\n0 \\in -x_i + \\lambda[-1,1] \\Leftrightarrow x_i \\in [-\\lambda,\\lambda] \\Leftrightarrow |x_i| \\leq \\lambda\n\\end{equation}\nPutting all together we get\n\\begin{equation}\n[prox_f(x)]_i = z_i^* = \n\\left\\{ \\begin{array}{lr} 0 & \\text{if } |x_i| \\leq \\lambda \\\\ \nx_i - \\lambda sign(x_i) &\\text{if } |x_i| > \\lambda \\end{array}\\right.\n\\end{equation}\nThe previous equation can also be written as\n\\begin{align*}\n[prox_f(x)]_i &= sign(x_i)\\max(|x_i|-\\lambda, 0) \\\\\n               &= sign(x_i)(|x_i|-\\lambda)_+\n\\end{align*}\nwhere $(\\cdot)_+$ denotes the positive part and it leads to sparse solution.\n\\end{proof}\n\n\\subsection{Properties of the proximal map}\t\n\\begin{definition}\n: A map g:$ \\mathbb{R}^{d} \\rightarrow \\mathbb{R}^{d} $ is called \n\\begin{itemize}\n\t\\item Non-expansive if $ \\|g(x)-g(y)\\| \\leqslant\\|x-y\\| $\n\t\\item Firauly Non-expansive if $ \\|g(x)-g(y)\\|^{2} \\leqslant\\langle g(x)-g(y), x-y\\rangle $\n\t\\item A contraction if $ \\|g(x)-g(y)\\| \\leqslant \\lambda\\|x-y\\| \\quad \\text { for } 0 \\leqslant \\lambda<1 $\n\\end{itemize}\n\\end{definition}\n\n\\begin{lemma}\n\tIf g is non-expansive, the $ \\frac{1}{2}(g+I) $ is \tfirmly non-expansive.\n\t$$\n\t\\frac{1}{2}(g+I)(x)=\\frac{1}{2}(g(x)+x)\n\t$$\n\tIf g is firmly non-expansive, then $ 2g-I $ is non-expansive.\n\\end{lemma}\n\n\\begin{proof}\n\t$$\n\t\\begin{aligned}\n\t\\|h(x)-h(y)\\|^{2}&=\\left\\langle\\frac{1}{2}[g(x)+x]-\\frac{1}{2}[g(y)+y], \\frac{1}{2}[g(x)+x]-\\frac{1}{2}[g(J)+y]\\right\\rangle\\\\\n\t&=\\left\\langle\\frac{1}{2}(g(x)-g(y))+\\frac{1}{2}(x-y), \\frac{1}{2}(g(x)-g(y))+\\frac{1}{2}(x-y)\\right\\rangle \\\\\n\t&=\\frac{1}{4} \\|g(x)-g(y)\\|^{2}\\|x-y\\|^{2}+\\frac{1}{2}(g(x)-g(y), x-y)+\\frac{1}{4}\\|x-y\\|^{2} \\\\\n\t& \\leqslant \\frac{1}{2}\\|x-y\\|^{2}+\\frac{1}{2}\\langle g(x)-g(y), x-y\\rangle \\\\\n\t&=\\left\\langle\\frac{1}{2}(g(x)-g(y))+\\frac{1}{2}(x-y), x-y\\right\\rangle\\\\\n\t&=\\langle h(x)-h(y), x-y\\rangle .\n\t\\end{aligned}\n\t$$\t\n\t\\end{proof}\n\n\\begin{example}\n\tNon-expansive $ \\mathbb{R}^{2}  $, rotate by $ \\theta $, has a fixed point, but we don't converge to it.\n\tNonexpansive maps may fail to converge to fixed points. Firmly nonexpanisve maps always converge to their fixed points.\n\tFixed points may not be unique though.\n\t\\end{example}\n\n\\begin{example}\n\t$ g: \\mathbb{R} \\rightarrow \\mathbb{R}$, \n\t$$  g(x)=\\left\\{\\begin{array}{cl}\n\tx & \\text { if } x\\in [-1,1] \\\\\n\t1 & \\text { if }  x > 1    \\\\\n\t-1 & \\text { if } x <-1\n\t\\end{array}\\right.$$\n\t\\end{example}\ng is firmly non-expansive. Set of fixed points [-1,1]\n\\begin{theorem}\nThe proximal map is always firmly non-expansive.\t\n\t\\end{theorem}\n\\begin{theorem}\nIf g is firmly nonexpansive and $ g(y)=y $\tfor some y, there if $ x_{n+1}=g(x_{n}) $,we have $ x_{n} \\rightarrow y^{\\prime} $ with $ g(y^{\\prime})=y^{\\prime} $\n\\end{theorem}\n\n\\begin{example}\n$ g: \\mathbb{R} \\rightarrow \\mathbb{R}, g(x)=x+1$ is firmly non-expansive in fact $ g(x)=prox_{f}(x), f(x)=-x$\n\t\\end{example}\n\t\n\\subsection{Proximal gradient method}\t\nProximal point algorithm: \n$$ \nx_{n+1}=prox_{f}(x_{n}).\n$$ \nBy the preceding if $ prox_{f}$ has a fixed point, then $ x_{n} $ converge to a fixed point.\nA fixed point of $ prox_{f}$ is a point x with $0 \\in \\partial f(x) $, which is a minimizer.\nUsually calculating $ prox_{f}$ is just as difficult as minimizing $f$ itself,\n$$\nprox_{f}=\\mathop{argmin}\\limits_{z} \\frac{1}{2}\\|x-z\\|_2^{2}+f(z)\n$$\n%Later we will use \t$ prox_{f}$ and $ prox_{g}$ to construct a firmly non-expansive map whose fixed points mininize $g+h $ Douglas-Rachfound splitting.\n%$$\n%x_{n+1}=x_{n}-s h_{n}, \\quad h_{n}=\\mathop{argmax}\\limits_{\\|h\\|_{1}}\\left\\langle h,\\nabla f\\left(x_{n}\\right)\\right\\rangle\n%$$\n%Boosting: $$ \\mathop{argmax}\\limits_{h \\in D}\\left\\langle h,\\nabla f\\left(x_{n}\\right)\\right\\rangle $$ \n%If $\n%f(x)=\\frac{1}{2}\\left\\|x-x_{0}\\right\\|^{2}\n%$get greedy approx.\n\n\nConsider unconstrained problem with cost function split in two components\n$$\n\\min f(x)=g(x)+h(x)\n$$\nwhere $h$ is convex and differentiable, \n$g$ is convex and possibly nondifferentiable, with inexpensive pro-operator.\nThe proximal gradient algorithm is\n$$\nx^{(k)}=\\operatorname{prox}_{t_{k} g}\\left(x^{(k-1)}-t_{k} \\nabla h\\left(x^{(k-1)}\\right)\\right)\n$$\nwhere $t_{k}>0$ is step size, constant or determined by line search. Note that if $g(x)=0$, then this method reduces to a gradient descent method.\n\nIf we apply the proximal mapping to update rule,\n$$\n\\begin{aligned}\nx^{+} &=\\underset{z}{\\operatorname{argmin}}\\left(g(z)+\\frac{1}{2 t}\\|z-x+t \\nabla h(x)\\|_{2}^{2}\\right) \\\\\n&=\\underset{z}{\\operatorname{argmin}}\\left(g(z)+h(x)+\\nabla h(x)^{T}(z-x)+\\frac{1}{2 t}\\|z-x\\|_{2}^{2}\\right).\n\\end{aligned}\n$$\nThis means that\n$x^{+}$ minimizes $g(z)$ plus a simple quadratic local model of $h(z)$ around $x$.\n\n\\begin{properties}\nIf \n$$\nu=\\operatorname{prox}_{f}(x), v= \\operatorname{prox}_{f}(y),\n$$\nthen \n$$\n(u-v)^{T}(x-y) \\geq\\|u-v\\|_{2}^{2}.\n$$\nThis implies that \n$$\nx-u \\in \\partial f(u), \\quad y-v \\in \\partial f(v) \\quad \\Longrightarrow \\quad(x-u-y+v)^{T}(u-v) \\geq 0,\n$$\nand \n$$\n\\left\\|\\operatorname{prox}_{f}(x)-\\operatorname{prox}_{f}(y)\\right\\|_{2} \\leq\\|x-y\\|_{2}\n$$\n$prox_{f}$ is nonexpansive or Lipschitz continuous with constant 1.\n\\end{properties}\n\n\\begin{definition}\n\t The proximal map of X, $ prox_{X}(x)=x^{1} $(\" Backward Euler\")\n\\end{definition}\n\n\n\n\n%\\begin{remark}\n%\\begin{enumerate}\n%\\item If the full gradient descent method is used, $\\eta$ is a given value.\n%\\item If the stochastic  gradient descent method is used, $\\eta$ is approaching 0 as t goes to infinity. We don't expect sparse 'minimization sequence'\n%\\item Can we find a different training algorithm that would give 'sparsity'?\n%\\end{enumerate}\n%\\end{remark}\n\n\n%\\section{Forward-Backward Splitting Algorithm(not included)}\n%\\begin{lemma}\n%$\\Theta=\\{\\theta:f(\\theta,x)\\ \\text{ is a classifier}\\}$ is a non-empty open set.\n%\\end{lemma}\n%\n%\n%\\begin{remark}\n%\\begin{enumerate}\n%\\item Question 1: Can we find some sparse $\\theta\\in \\Theta$ by certain training algorithm?\n%\\begin{itemize}\n%\\item The desirable training algorithm should converge.\n%\\item The desirable training algorithm generates 'sparse' minimization sequence.\n%\\end{itemize}\n%\n%\\item Question 2: Can we find a model $L(\\theta)+R(\\theta)$ with small $R(\\theta)$ s.t. $\\arg\\min(L(\\theta)+R(\\theta)) \\approx \\arg\\min L(\\theta)$.\n%\\end{enumerate}\n%\\end{remark}\n%A general approach is to use $L(\\theta)+R(\\theta)$, where $R(\\theta)=\\lambda \\|\\theta\\|_1$.\n%\n%Assume f is strongly convex and smooth function and R is convex. Thus $x^*= \\arg\\min (f(x)+R(x)) \\iff 0\\in \\nabla f(x^*)+\\partial R(x^*)$.\n%We have the following forward-backward splitting algorithm.\n\n%\\section{A summary of algorithms and convergence results}\n%\\includepdf[pages=-,angle=270]{6DL/SGD-summary.jpeg}\n\n", "meta": {"hexsha": "609a6a4f79e9bfed3c0ab0abb34f25ca7b505e8d", "size": 12658, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Prox_SGD.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/Prox_SGD.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/Prox_SGD.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.1888544892, "max_line_length": 463, "alphanum_fraction": 0.6577658398, "num_tokens": 4557, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.8740772417253256, "lm_q1q2_score": 0.7020359365456988}}
{"text": "\\section{Isomorphisms}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine if a linear transformation is an isomorphism.\n  \\item Determine if two subspaces of $\\R^n$ are isomorphic.\n  \\end{enumerate}\n\\end{outcome}\n\nRecall the definition of a linear transformation. Let $V$ and $W$ be two subspaces of $\\R^{n}$ and $\\R^{m}$\nrespectively. A mapping $T:V\\rightarrow W$ is called a\\textbf{\\ linear\ntransformation} or \\textbf{linear map} if it preserves the algebraic\noperations of addition and\n\\index{linear map}\n\\index{linear transformation} scalar multiplication. Specifically, if $a,b$\nare scalars and $\n\\vect{x},\\vect{y}$ are vectors,\n\\begin{equation*}\nT(a\\vect{x}+b\\vect{y}) =aT(\\vect{x})+bT(\\vect{y})\n\\end{equation*}\n\nConsider the following important definition.\n\n\\begin{definition}{Isomorphism}{isomorphism}\nA linear map $T$ is called an \\textbf{isomorphism}\n\\index{isomorphism}if the following two conditions are satisfied.\n\n\\begin{itemize}\n\\item $T$ is one to one. That is, if $T(\\vect{x})=T(\\vect{y})$, then $\\vect{x}=\\vect{y}$.\n\n\\item $T$ is onto. That is, if $\\vect{w}\\in W$, there exists $\n\\vect{v}\\in V$ such that $T(\\vect{v})=\\vect{w}$.\n\\end{itemize}\n\nTwo such subspaces which have an isomorphism as described above are said to\nbe \\textbf{isomorphic.}\n\\index{isomorphic}\n\\end{definition}\n\nConsider the following example of an isomorphism.\n\n\\begin{example}{Isomorphism}{isomorphism}\nLet $T: \\R^2 \\to \\R^2$ be defined by\n\\[\nT \\begin{mymatrix}{c}\nx \\\\\ny\n\\end{mymatrix} = \\begin{mymatrix}{c}\nx + y \\\\\nx - y\n\\end{mymatrix}\n\\]\nShow that $T$ is an isomorphism.\n\\end{example}\n\n\\begin{solution}\nTo prove that $T$ is an isomorphism we must show\n\\begin{enumerate}\n\\item $T$ is a linear transformation;\n\\item $T$ is one to one;\n\\item $T$ is onto.\n\\end{enumerate}\n\nWe proceed as follows.\n\n\\begin{enumerate}\n\\item $T$ is a linear transformation:\n\nLet $k, p$ be scalars.\n\\begin{eqnarray*}\nT \\paren{k \\begin{mymatrix}{c}\nx_1 \\\\\ny_1\n\\end{mymatrix} + p \\begin{mymatrix}{c}\nx_2 \\\\\ny_2\n\\end{mymatrix}} &=&\nT \\paren{\\begin{mymatrix}{c}\nkx_1 \\\\\nky_1\n\\end{mymatrix} + \\begin{mymatrix}{c}\npx_2 \\\\\npy_2\n\\end{mymatrix}} \\\\\n&=&\nT \\paren{\\begin{mymatrix}{c}\nkx_1 + px_2 \\\\\nky_1 + py_2\n\\end{mymatrix}} \\\\\n&=&\n\\begin{mymatrix}{c}\n(kx_1 + px_2) + (ky_1 + py_2) \\\\\n(kx_1 + px_2) - (ky_1 + py_2)\n\\end{mymatrix} \\\\\n&=&\n\\begin{mymatrix}{c}\n(kx_1 + ky_1) + (px_2 + py_2) \\\\\n(kx_1  - ky_1) + (px_2 - py_2)\n\\end{mymatrix} \\\\\n&=&\n\\begin{mymatrix}{c}\nkx_1 + ky_1  \\\\\nkx_1  - ky_1\n\\end{mymatrix} +\n\\begin{mymatrix}{c}\npx_2 + py_2 \\\\\npx_2 - py_2\n\\end{mymatrix} \\\\\n&=& k \\begin{mymatrix}{c}\nx_1 + y_1  \\\\\nx_1  - y_1\n\\end{mymatrix} +\np \\begin{mymatrix}{c}\nx_2 + y_2 \\\\\nx_2 - y_2\n\\end{mymatrix} \\\\\n&=&\nk T \\paren{\\begin{mymatrix}{c}\nx_1 \\\\\ny_1\n\\end{mymatrix}} + p T \\paren{\\begin{mymatrix}{c}\nx_2 \\\\\ny_2\n\\end{mymatrix}}\n\\end{eqnarray*}\n\nTherefore $T$ is linear.\n\n\\item $T$ is one to one:\n\nWe need to show that if $T (\\vect{x}) = \\vect{0}$ for a vector $\\vect{x} \\in \\R^2$, then it follows that $\\vect{x} = \\vect{0}$.  Let $\\vect{x} = \\begin{mymatrix}{c}\nx \\\\\ny\n\\end{mymatrix}$.\n\n\\[\nT  \\paren{\\begin{mymatrix}{c}\nx \\\\\ny\n\\end{mymatrix}} = \\begin{mymatrix}{c}\nx + y\\\\\nx - y\n\\end{mymatrix} = \\begin{mymatrix}{c}\n0 \\\\\n0\n\\end{mymatrix}\n\\]\nThis provides a system of equations given by\n\\begin{eqnarray*}\nx + y &=& 0\\\\\nx - y &=& 0\n\\end{eqnarray*}\nYou can verify that the solution to this system if $x = y =0$. Therefore\n\\[\n\\vect{x} = \\begin{mymatrix}{c}\nx \\\\\ny\n\\end{mymatrix}\n = \\begin{mymatrix}{c}\n0 \\\\\n0\n\\end{mymatrix}\n\\]\nand $T$ is one to one.\n\n\\item $T$ is onto:\n\nLet $a,b$ be scalars. We want to check if there is always a solution to\n\\[\nT  \\paren{\\begin{mymatrix}{c}\nx \\\\\ny\n\\end{mymatrix}} = \\begin{mymatrix}{c}\nx + y\\\\\nx - y\n\\end{mymatrix} = \\begin{mymatrix}{c}\na \\\\\nb\n\\end{mymatrix}\n\\]\n\nThis can be represented as the system of equations\n\\begin{eqnarray*}\nx + y &=& a\\\\\nx - y &=& b\n\\end{eqnarray*}\n\nSetting up the augmented matrix and row reducing gives\n\\[\n\\begin{mymatrix}{cc|c}\n1 & 1 & a \\\\\n1 & -1 & b\n\\end{mymatrix} \\roweq\\ldots\\roweq\n\\begin{mymatrix}{cc|c}\n1 & 0 & \\vspace{0.05in}\\frac{a+b}{2} \\\\\n0 & 1 & \\vspace{0.05in}\\frac{a-b}{2}\n\\end{mymatrix}\n\\]\nThis has a solution for all $a,b$ and therefore $T$ is onto.\n\\end{enumerate}\n\nTherefore $T$ is an isomorphism.\n\\end{solution}\n\nAn important property of isomorphisms is that its inverse is also an isomorphism.\n\n\\begin{proposition}{Inverse of an isomorphism}{inverse-isomorphism}\nLet $T:V\\rightarrow W$ be an isomorphism and $V,W$ be subspaces of $\\R^n$. Then $T^{-1}:W\\rightarrow V$ is\nalso an isomorphism.\n\\index{isomorphism!inverse}\n\\end{proposition}\n\n\\begin{proof} Let $T$ be an isomorphism.  Since $T$ is onto, a typical\nvector in $W$ is of the form $T(\\vect{v})$ where $\\vect{v} \\in V$. Consider then for $a,b$\nscalars,\n\\begin{equation*}\nT^{-1}(aT(\\vect{v}_{1})+bT(\\vect{v}_{2}))\n\\end{equation*}\nwhere $\\vect{v}_{1}, \\vect{v}_2 \\in V$. Is this equal to\n\\begin{equation*}\naT^{-1}(T (\\vect{v}_{1})) +bT^{-1}(T(\\vect{v}_{2})) =a\\vect{v}_{1}+b\\vect{v}_{2}?\n\\end{equation*}\nSince $T$ is one to one, this will be so if\n\\begin{equation*}\nT(a\\vect{v}_{1}+b\\vect{v}_{2}) =T(T^{-1}(aT(\\vect{v}_{1})+bT(\\vect{v}_{2}))\n) =aT(\\vect{v}_{1})+bT(\\vect{v}_{2}).\n\\end{equation*}\nHowever, the above statement is just the condition that $T$ is a linear map.\nThus $T^{-1}$ is indeed a linear map. If $\\vect{v} \\in V$ is given, then $\\vect{v}=T^{-1}(T(\\vect{v})) $ and so $T^{-1}$ is onto. If $T^{-1} (\\vect{v})=0$, then\n\\begin{equation*}\n\\vect{v}=T(T^{-1}(\\vect{v})) =T(\\vect{0})=\\vect{0}\n\\end{equation*}\nand so $T^{-1}$ is one to one.\n\\end{proof}\n\nAnother important result is that the composition of multiple isomorphisms is also an isomorphism.\n\n\\begin{proposition}{Composition of isomorphisms}{composition-isomorphisms}\nLet $T:V\\rightarrow W$ and  $S:W\\rightarrow Z$ be isomorphisms where $V,W,Z$ are subspaces of $\\R^n$. Then $S\\circ\nT $ defined by $(S\\circ T) (\\vect{v}) = S(\nT(\\vect{v})) $ is also an isomorphism.\n\\index{isomorphism!composition}\n\\end{proposition}\n\n\\begin{proof}\nSuppose $T:V\\rightarrow W$ and  $S:W\\rightarrow Z$ are isomorphisms. Why is $S\\circ T$ a linear map?\nFor $a,b$ scalars,\n\\begin{eqnarray*}\nS\\circ T(a\\vect{v}_{1}+b(\\vect{v}_{2}))\n&=& S(T(a\\vect{v}_{1}+b\\vect{v}_{2})) =S(aT\\vect{v}_{1}+bT\\vect{v}_{2}) \\\\\n&=&aS(T\\vect{v}_{1}) +bS(T\\vect{v}_{2}) = a(S\\circ\nT) (\\vect{v}_{1}) +b(S\\circ T) (\\vect{v}_{2})\n\\end{eqnarray*}\nHence $S\\circ T$ is a linear map. If $(S\\circ T) (\\vect{v})\n=0$, then $S(T(\\vect{v})) =0$ and it follows that $T(\\vect{v})=\\vect{0}$ and hence by this lemma again, $\\vect{v}=\\vect{0}$. Thus $S\\circ\nT $ is one to one. It remains to verify that it is onto. Let $\\vect{z} \\in Z$. Then\nsince $S$ is onto, there exists $\\vect{w} \\in W$ such that $S(\\vect{w})=\\vect{z}$. Also, since $T$\nis onto, there exists $\\vect{v}\\in V$ such that $T(\\vect{v})=\\vect{w}$. It follows that $S(\nT(\\vect{v})) =\\vect{z}$ and so $S\\circ T$ is also onto.\n\\end{proof}\n\nConsider two subspaces $V$ and $W$, and suppose there exists an isomorphism mapping one to the other. In this way the two subspaces are related, which we can write as $V\\iso W$. Then the previous two propositions together claim that $\\iso$ is an equivalence relation. That is: $\\iso$\nsatisfies the following conditions:\n\\index{isomorphic!equivalence relation}\n\n\\begin{itemize}\n\\item $V\\iso V$\n\n\\item If $V\\iso W$, it follows that $W\\iso V$\n\n\\item If $V\\iso W$ and $W\\iso Z$, then $V\\iso Z$\n\\end{itemize}\n\nWe leave the verification of these conditions as an exercise.\n\nConsider the following example.\n\n\\begin{example}{Matrix isomorphism}{matrix-isomorphism}\nLet $T:\\R^{n}\\rightarrow \\R^{n}$ be defined by $T(\\vect{x}) = A(\\vect{x})$ where $A$ is an invertible $n\\times n$-matrix. Then $T$ is\nan isomorphism.\n\\end{example}\n\n\\begin{solution}\nThe reason for this is that, since $A$ is invertible, the only vector it\nsends to $\\vect{0}$ is the zero vector. Hence if $A(\\vect{x})=A(\\vect{y})$, then $A(\\vect{x}-\\vect{y}) =\\vect{0}$ and so $\\vect{x}=\\vect{y}$. It is onto\nbecause if $\\vect{y}\\in \\R^{n},A(A^{-1} (\\vect{y})) =(\nAA^{-1}) (\\vect{y})$ $=\\vect{y}$.\n\\end{solution}\n\nIn fact, all isomorphisms from $\\R^{n}$ to $\\R^{n}$ can be expressed as $T(\\vect{x}) = A(\\vect{x})$ where $A$ is an invertible $n \\times n$-matrix. One\nsimply considers the matrix whose $i\\th$ column is $T\\vect{e}_{i}$.\n\nRecall that a basis of a subspace $V$ is a set of linearly independent vectors which span $V$. The following fundamental lemma describes the relation between bases and\nisomorphisms.\n\n\\begin{lemma}{Mapping bases}{mapping-bases}\nLet $T:V\\rightarrow W$ be a linear transformation where $V,W$ are\nsubspaces of $\\R^n$. If $T$ is one to one, then it has the property that if $\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{k}} $ is linearly independent, so is $\\set{T(\\vect{u}_{1}),\\ldots,T(\\vect{u}_{k})}$.\n\nMore generally, $T$ is an isomorphism if and only if whenever $\\set{\n\\vect{v}_{1},\\ldots,\\vect{v}_{n}} $ is a basis for $V$, it follows that $\\set{T\n(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n})} $ is a basis for $W$.\n\\index{isomorphism!bases}\n\\index{one to one!linear independence}\n\\end{lemma}\n\n\\begin{proof}First suppose that $T$ is a linear transformation and is one to one\nand $\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{k}} $ is linearly\nindependent. It is required to show that $\\set{T(\\vect{u}_{1}),\\ldots,T(\\vect{\nu}_{k})} $ is also linearly independent. Suppose then that\n\\begin{equation*}\n\\sum_{i=1}^{k}c_{i}T(\\vect{u}_{i})=\\vect{0}\n\\end{equation*}\nThen, since $T$ is linear,\n\\begin{equation*}\nT\\paren{\\sum_{i=1}^{n}c_{i}\\vect{u}_{i}} =\\vect{0}\n\\end{equation*}\nSince $T$ is one to one, it follows that\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}\\vect{u}_{i}=0\n\\end{equation*}\nNow the fact that $\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{n}} $ is\nlinearly independent implies that each $c_{i}=0$. Hence $\\set{T(\\vect{u}\n_{1}),\\ldots,T(\\vect{u}_{n})} $ is linearly independent.\n\nNow suppose that $T$ is an isomorphism and $\\set{\\vect{v}_{1},\\ldots,\\vect{\nv}_{n}} $ is a basis for $V$. It was just shown that $\\set{T(\\vect{v}\n_{1}),\\ldots,T(\\vect{v}_{n})} $ is linearly independent. It remains to\nverify that span$\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n})}=W$. If $\\vect{w}\\in W$, then since $T$ is onto there\nexists $\\vect{v}\\in V$ such that $T(\\vect{v})=\\vect{w}$. Since $\\set{\\vect{v}\n_{1},\\ldots,\\vect{v}_{n}} $ is a basis, it follows that there exists\nscalars $\\set{c_{i}} _{i=1}^{n}$ such that\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}=\\vect{v}.\n\\end{equation*}\nHence,\n\\begin{equation*}\n\\vect{w}=T(\\vect{v})=T\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}}\n=\\sum_{i=1}^{n}c_{i}T(\\vect{v}_{i})\n\\end{equation*}\nIt follows that span$\\set{T(\\vect{v}_{1}),\\ldots, T(\\vect{v}_{n})} =W$ showing that this set of vectors is a\nbasis for $W$.\n\nNext suppose that $T$ is a linear transformation which takes a basis to a basis. This means that if $\\set{\\vect{v}_{1},\\ldots,\\vect{v}_{n}} $ is a basis for $V$, it\nfollows $\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n})} $ is a basis for $\nW$. Then if $w\\in W$, there exist scalars $c_{i}$ such that $\nw=\\sum_{i=1}^{n}c_{i}T(\\vect{v}_{i})=T\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}} $\nshowing that $T$ is onto. If $T\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}} =\\vect{0}$\nthen $\\sum_{i=1}^{n}c_{i}T(\\vect{v}_{i})=\\vect{0}$ and since the vectors $\\set{T(\\vect{v}\n_{1}),\\ldots,T(\\vect{v}_{n})} $ are linearly independent, it follows\nthat each $c_{i}=0$. Since $\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}$ is a typical vector in\n$V$, this has shown that if $T(\\vect{v})=\\vect{0}$ then $\\vect{v}=\\vect{0}$ and so $T$ is also one to one.\nThus $T$ is an isomorphism.\n\\end{proof}\n\nThe following theorem illustrates a very useful idea for defining an\nisomorphism. Basically, if you know what it does to a basis, then you can\nconstruct the isomorphism.\n\n\\begin{theorem}{Isomorphic subspaces}{isomorphic-subspaces}\nSuppose $V$ and $W$ are two subspaces of $\\R^n$. Then the two\nsubspaces are isomorphic if and only if they have the same dimension. In the\ncase that the two subspaces have the same dimension, then for\n\\index{isomorphism!equivalence} a linear map $T:V\\rightarrow W$, the\nfollowing are equivalent.\n\n\\begin{enumerate}\n\\item $T$ is one to one.\n\n\\item $T$ is onto.\n\n\\item $T$ is an isomorphism.\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof} Suppose first that these two subspaces have the same\ndimension. Let a basis for $V$ be $\\set{\n\\vect{v}_{1},\\ldots,\\vect{v}_{n}} $ and let a basis for $W$ be $\n\\set{\\vect{w}_{1},\\ldots,\\vect{w}_{n}}$. Now define $T$ as\nfollows.\n\\begin{equation*}\nT(\\vect{v}_{i})=\\vect{w}_{i}\n\\end{equation*}\nfor $\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}$ an arbitrary vector of $V$,\n\\begin{equation*}\nT\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}} = \\sum_{i=1}^{n}c_{i}T\n\\vect{v}_{i}=\\sum_{i=1}^{n}c_{i}\\vect{w}_{i}.\n\\end{equation*}\nIt is necessary to verify that this is well-defined. Suppose then that\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}=\\sum_{i=1}^{n}\\hat{c}_{i}\\vect{v}_{i}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\sum_{i=1}^{n}(c_{i}-\\hat{c}_{i}) \\vect{v}_{i}=\\vect{0}\n\\end{equation*}\nand since $\\set{\\vect{v}_{1},\\ldots,\\vect{v}_{n}} $ is a basis, $\nc_{i}=\\hat{c}_{i}$ for each $i$. Hence\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}\\vect{w}_{i}=\\sum_{i=1}^{n}\\hat{c}_{i}\\vect{w}_{i}\n\\end{equation*}\nand so the mapping is well-defined. Also if $a,b$ are scalars,\n\\begin{eqnarray*}\nT\\paren{a\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}+b\\sum_{i=1}^{n}\\hat{c}_{i}\\vect{v}%\n_{i}} &=&T(\\sum_{i=1}^{n}(ac_{i}+b\\hat{c}_{i}) \\vect{v%\n}_{i}) =\\sum_{i=1}^{n}(ac_{i}+b\\hat{c}_{i}) \\vect{w}_{i} \\\\\n&=&a\\sum_{i=1}^{n}c_{i}\\vect{w}_{i}+b\\sum_{i=1}^{n}\\hat{c}_{i}\\vect{w}_{i} \\\\\n&=&aT\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}} +bT\\paren{\\sum_{i=1}^{n}%\n\\hat{c}_{i}\\vect{v}_{i}}\n\\end{eqnarray*}\nThus $T$ is a linear transformation.\n\nNow if\n\\begin{equation*}\nT\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}} =\\sum_{i=1}^{n}c_{i}\\vect{w}%\n_{i}=\\vect{0},\n\\end{equation*}\nthen since the $\\set{\\vect{w}_{1},\\ldots,\\vect{w}_{n}} $ are\nindependent, each $c_{i}=0$ and so $\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}=\\vect{0}$\nalso. Hence $T$ is one to one. If $\\sum_{i=1}^{n}c_{i}\\vect{w}_{i}$ is a\nvector in $W$, then it equals\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}T(\\vect{v}_{i})=T\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}}\n\\end{equation*}\nshowing that $T$ is also onto. Hence $T$ is an isomorphism and so $V$ and $W$\nare isomorphic.\n\nNext suppose $T:V \\to W$ is an isomorphism, so these two subspaces are isomorphic. Then for $\\set{\\vect{v}_{1},\\ldots,\\vect{v}_{n}} $ a\nbasis for $V$, it follows that a basis for $W$\nis $\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n})} $ showing that the two\nsubspaces have the same dimension.\n\nNow suppose the two subspaces have the same dimension. Consider the three\nclaimed equivalences.\n\nFirst consider the claim that $1.)\\Rightarrow 2.)$. If $T$ is one to one and if $\\set{\\vect{v}_{1},\\ldots,\\vect{v}\n_{n}} $ is a basis for $V$, then $\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v\n}_{n})} $ is linearly independent. If it is not a basis, then it must\nfail to span $W$. But then there would exist $\\vect{w}\\notin \\sspan\n\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n})} $ and it follows that $\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n}),\\vect{w}\n} $ would be linearly independent which is impossible because there exists a basis for $W$ of $n$ vectors.\n\nHence $\\sspan\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n})} =W$ and\nso $\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n})} $ is a basis. If $\\vect{w}\\in W$, there exist scalars $c_{i}$ such that\n\\begin{equation*}\n\\vect{w}=\\sum_{i=1}^{n}c_{i}T(\\vect{v}_{i})=T\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}\n_{i}}\n\\end{equation*}\nshowing that $T$ is onto. This shows that $1.)\\Rightarrow 2.)$.\n\nNext consider the claim that $2.)\\Rightarrow 3.)$. Since $2.)$ holds, it\nfollows that $T$ is onto. It remains to verify that $T$ is one to one. Since\n$T$ is onto, there exists a basis of the form $\\set{T(\\vect{v}_{i}),\\ldots,T(\\vect{v}_{n})}$. Then it follows that $\\set{\\vect{v}_{1},\\ldots,\n\\vect{v}_{n}} $ is linearly independent. Suppose\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}=\\vect{0}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}T(\\vect{v}_{i})=\\vect{0}\n\\end{equation*}\nHence each $c_{i}=0$ and so, $\\set{\\vect{v}_{1},\\ldots,\\vect{v}\n_{n}} $ is a basis for $V$. Now it follows that a typical vector in $\nV $ is of the form $\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}$. If $T\\paren{\n\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}} =\\vect{0}$, it follows that\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}T(\\vect{v}_{i})=\\vect{0}\n\\end{equation*}\nand so, since $\\set{T(\\vect{v}_{i}),\\ldots,T(\\vect{v}_{n})} $ is\nindependent, it follows each $c_{i}=0$ and hence $\\sum_{i=1}^{n}c_{i}\\vect{v}\n_{i}=\\vect{0}$. Thus $T$ is one to one as well as onto and so it is an\nisomorphism.\n\nIf $T$ is an isomorphism, it is both one to one and onto by definition so $\n3.)$ implies both $1.)$ and $2.)$.\n\\end{proof}\n\nNote the interesting way of defining a linear transformation in the first\npart of the argument by describing what it does to a basis and then\n``extending it linearly'' to the entire subspace.\n\\index{linear map!defining on a basis}\n\n\\begin{example}{Isomorphic subspaces}{}\nLet $V=\\R^{3}$ and let $W$ denote\n\\begin{equation*}\n\\sspan\\set{\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{r}\n0 \\\\\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n2 \\\\\n0\n\\end{mymatrix} }\n\\end{equation*}\nShow that $V$ and $W$ are isomorphic.\n\\end{example}\n\n\\begin{solution}\nFirst observe that these subspaces are both of dimension 3 and so they are isomorphic by Theorem~\\ref{thm:isomorphic-subspaces}. The\nthree vectors which span $W$ are easily seen to be linearly independent by\nmaking them the columns of a matrix and row reducing to the {\\rref}.\n\nYou can exhibit an isomorphism of these two spaces as follows.\n\\begin{equation*}\nT(\\vect{e}_{1})=\\begin{mymatrix}{c}\n1 \\\\\n2 \\\\\n1 \\\\\n1\n\\end{mymatrix}, T(\\vect{e}_{2})=\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix}, T(\\vect{e}_{3})=\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n2 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\nand extend linearly. Recall that the matrix of this linear transformation is\njust the matrix having these vectors as columns. Thus the matrix of this\nisomorphism is\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n1 & 0 & 1 \\\\\n2 & 1 & 1 \\\\\n1 & 0 & 2 \\\\\n1 & 1 & 0\n\\end{mymatrix}\n\\end{equation*}\nYou should check that multiplication on the left by this matrix does\nreproduce the claimed effect resulting from an application by $T$.\n\\end{solution}\n\nConsider the following example.\n\n\\begin{example}{Finding the matrix of an isomorphism}{matrix-of-isomorphism}\nLet $V=\\R^{3}$ and let $W$ denote\n\\begin{equation*}\n\\sspan\\set{\\begin{mymatrix}{c}\n1 \\\\\n2 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n2 \\\\\n0\n\\end{mymatrix} }\n\\end{equation*}\n\nLet $T: V \\to W$ be defined as follows.\n\\begin{equation*}\nT\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix} =\\begin{mymatrix}{c}\n1 \\\\\n2 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,T\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} ,T\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n2 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\nFind the matrix of this isomorphism $T$.\n\\end{example}\n\n\\begin{solution}\n First note that the vectors\n\\begin{equation*}\n\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\nare indeed a basis for $\\R^{3}$ as can be seen by making them the\ncolumns of a matrix and using the {\\rref}.\n\nNow recall the matrix of $T$ is a $4\\times 3$-matrix $A$ which gives the same\neffect as $T$. Thus, from the way we multiply matrices,\n\\begin{equation*}\nA\\begin{mymatrix}{rrr}\n1 & 0 & 1 \\\\\n1 & 1 & 1 \\\\\n0 & 1 & 1\n\\end{mymatrix} =\\begin{mymatrix}{rrr}\n1 & 0 & 1 \\\\\n2 & 1 & 1 \\\\\n1 & 0 & 2 \\\\\n1 & 1 & 0\n\\end{mymatrix}\n\\end{equation*}\nHence,\n\\begin{equation*}\nA=\\begin{mymatrix}{rrr}\n1 & 0 & 1 \\\\\n2 & 1 & 1 \\\\\n1 & 0 & 2 \\\\\n1 & 1 & 0\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n1 & 0 & 1 \\\\\n1 & 1 & 1 \\\\\n0 & 1 & 1\n\\end{mymatrix} ^{-1}=\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 2 & -1 \\\\\n2 & -1 & 1 \\\\\n-1 & 2 & -1\n\\end{mymatrix}\n\\end{equation*}\nNote how the span of the columns of this new matrix must be the same as the\nspan of the vectors defining $W$.\n\\end{solution}\n\nThis idea of defining a linear transformation by what it does on a basis\nworks for linear maps which are not necessarily isomorphisms.\n\n\\begin{example}{Finding the matrix of an isomorphism}{}\nLet $V=\\R^{3}$ and let $W$ denote\n\\begin{equation*}\n\\sspan\\set{\\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n1 \\\\\n2\n\\end{mymatrix} }\n\\end{equation*}\nLet $T: V \\to W$ be defined as follows.\n\\begin{equation*}\nT\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix} = \\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,T\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} ,T\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n1 \\\\\n2\n\\end{mymatrix}\n\\end{equation*}\n Find the matrix of this linear transformation.\n\\end{example}\n\n\\begin{solution}\nNote that in this case, the three vectors which span $W$ are not linearly independent. Nevertheless the above procedure will still work.\nThe reasoning is the same as before. If $A$ is this matrix, then\n\\begin{equation*}\nA\\begin{mymatrix}{rrr}\n1 & 0 & 1 \\\\\n1 & 1 & 1 \\\\\n0 & 1 & 1\n\\end{mymatrix} =\\begin{mymatrix}{rrr}\n1 & 0 & 1 \\\\\n0 & 1 & 1 \\\\\n1 & 0 & 1 \\\\\n1 & 1 & 2\n\\end{mymatrix}\n\\end{equation*}\nand so\n\\begin{equation*}\nA=\\begin{mymatrix}{rrr}\n1 & 0 & 1 \\\\\n0 & 1 & 1 \\\\\n1 & 0 & 1 \\\\\n1 & 1 & 2\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n1 & 0 & 1 \\\\\n1 & 1 & 1 \\\\\n0 & 1 & 1\n\\end{mymatrix} ^{-1}=\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 0 & 1 \\\\\n1 & 0 & 0 \\\\\n1 & 0 & 1\n\\end{mymatrix}\n\\end{equation*}\nThe columns of this last matrix are obviously not linearly independent.\n\\end{solution}\n", "meta": {"hexsha": "454af0f4bc104ed29b5bb0fe8fe048029b02fa85", "size": 21920, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/lineartransformationsIsomorphisms.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/lineartransformationsIsomorphisms.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/lineartransformationsIsomorphisms.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 29.2266666667, "max_line_length": 283, "alphanum_fraction": 0.6501824818, "num_tokens": 8535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.8740772351648677, "lm_q1q2_score": 0.702035931276511}}
{"text": "\\documentclass[11pt, a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{amsmath, amssymb, graphics, setspace}\n\\setlength\\parindent{0pt}\n\\begin{document}\n\nQuick tips before trying to solve the OLG model.\n\\begin{enumerate}\n    \\item Determine whether the zero steady state is possible: \\\\\n    If $f(0) = 0$ (or, equivalently, $w(0) = 0$), then the zero (autarky) steady state exists.\n    It may be stable or unstable, but it exists.\n    \\begin{itemize}\n    \\item Cobb-Douglas production function:\\\\\n    $f(k) = k^\\alpha \\implies f(0) = 0$\n    \\item CES production function: \\\\\n        \\textbf{Important remark}: verify the exact functional form of the production function, in particular how the exponents are written.\\\\\n        $f(k) = (\\alpha k^\\rho +(1-\\alpha))^\\frac{1}{\\rho}$\n        \\begin{itemize}\n            \\item Complementary inputs ($\\rho < 0$)\\\\\n            $\\lim_{k \\rightarrow 0} f(k) = 0,$ assuming $\\rho<0,\\alpha \\in (0,1).$ \n        \\item Substitue inputs ($\\rho > 0$)\\\\\n            $\\lim_{k \\rightarrow 0} f(k) = (1-\\alpha)^\\frac{1}{\\rho},$ assuming $\\rho>0,\\alpha \\in (0,1).$\n        \\end{itemize}\n    \\end{itemize}\n\n    \\item Determine whether the interest rate appears in the savings function:\n        \\begin{itemize}\n            \\item If log-utility, the interest rate does not appear.\\\\\n                $u(c) = \\log (c) \\implies u^\\prime(c) = \\frac{1}{c}$ \\\\\n                The savings function is obtained in this case by solving:\\\\\n                $u^\\prime(w-s) = \\beta R u^\\prime(Rs)$ so $s = \\frac{\\beta}{1+\\beta}w$\n            \\item Under a CIES, $R$ appears in the savings function:\\\\\n                $u^\\prime(c) = x^\\frac{-1}{\\sigma}$ \\\\\n                The savings function is obtained in this case by solving:\\\\\n                $(w-s)^\\frac{-1}{\\sigma} = \\beta R (Rs)^\\frac{-1}{\\sigma}$ \\\\\n                $s = \\frac{w}{1+\\beta^{-\\sigma}R^{1-\\sigma}}$\n        \\end{itemize}\n\\end{enumerate}\n\n\\section*{Examples}\n\\subsection*{Example 1}\nProduction function:    $f(k)=k^{0.5}$\n\nUtility function:       $u(c)=2 \\sqrt{c}$\n\nSavings function:       $s(w(k_t),f^\\prime(k_{t+1}))=\\frac{16. R w}{25.\\, +16. R}$\n\nSubstituting: $s(w(k_t),f^\\prime(k_{t+1}))= \\frac{4.}{25.\\, +\\frac{8.}{k^{0.5}}}$\n\nSteady States:          Solve $k_{t+1} = \\frac{1}{1+n}s(w(k_t),f^\\prime(k_{t+1}))$\n\nWith the parameters: $\\{k\\to 0.\\},\\{k\\to 0.0733398\\}$\n\nStability:             Compute the derivative of $k_{t+1}$ with respect to $k_t$ and evaluate at each steady state.\n\nWith the parameters:\n\n\\quad Steady state 1, Capital level: $0$. Derivative=$\\infty$ Unstable.\n\n\\quad Steady state 2, Capital level: $0.0733398$ Derivative=$0.406773$ Stable.\n\n\\includegraphics{xamples_gr1.eps}\n\\subsection*{Example 2}\nProduction function:    $f(k)=\\frac{1}{\\sqrt{0.5\\, +\\frac{0.5}{k^2}}}$\n\nUtility function:       $u(c)=2 \\sqrt{c}$\n\nSavings function:       $s(w(k_t),f^\\prime(k_{t+1}))= \\frac{16. R w}{25.\\, +16. R}$\n\nSubstituting:           $s(w(k_t),f^\\prime(k_{t+1}))= \\frac{8. \\left(\\frac{1}{\\sqrt{0.5\\, +\\frac{0.5}{k^2}}}-\\frac{0.5}{\\left(0.5\\, +\\frac{0.5}{k^2}\\right)^{3/2} k^2}\\right)}{\\left(25.\\, +\\frac{8.}{\\left(0.5\\, +\\frac{0.5}{k^2}\\right)^{3/2} k^3}\\right) \\left(0.5\\, +\\frac{0.5}{k^2}\\right)^{3/2} k^3}$\n\nSteady States:          Solve ${k}_{t+1}= \\frac{1}{(1+n)}s(w(k_t),f^\\prime(k_{t+1}))$\n\nWith the parameters: $\\{k\\to 0\\}\\}$\n\nStability:             Compute the derivative of $k_{t+1}$ with respect to $k_{t}$ and evaluate at each steady state.\n\nWith the parameters:\n\n\\quad Steady state 1, Capital level: $0$, Derivative=$0$. Stable.\n\n\\includegraphics{xamples_gr2.eps}\n\\subsection*{Examples 3}\nProduction function:    $f(k)=\\frac{1}{\\sqrt{0.5\\, +\\frac{0.5}{k^2}}}$\n\nUtility function:       $u(c)=\\log(c)$\n\nSavings function:       $s(w(k_t),f^\\prime(k_{t+1}))= 0.444444 w$\n\nSubstituting: $s(w(k_t),f^\\prime(k_{t+1}))= 0.444444 \\left(\\frac{1}{\\sqrt{0.5\\, +\\frac{0.5}{k^2}}}-\\frac{0.5}{\\left(0.5\\, +\\frac{0.5}{k^2}\\right)^{3/2} k^2}\\right)$\n\nSteady States:          Solve ${k}_{t+1}= \\frac{1}{(1+n)}s(w(k_t),f^\\prime(k_{t+1}))$\n\nWith the parameters: $\\{k\\to 0\\}\\}$\n\nStability:             Compute the derivative of $k_{t+1}$ with respect to $k_{t}$ and evaluate at each steady state.\n\nWith the parameters:\n\n\\quad Steady state 1, Capital level: $0$ Derivative=$0$. Stable.\n\n\\includegraphics{xamples_gr3.eps}\n\n\\subsection*{Example 4}\nProduction function:    $f(k)=\\left(0.5\\, +0.5 k^{0.5}\\right)^{2.}$\n\nUtility function:       $u(c)log(c)$\n\nSavings function:       $s(w(k_t),f^\\prime(k_{t+1}))= 0.444444 w$\n\nSubstituting: $s(w(k_t),f^prime(k_{t+1}))= 0.444444 \\left(\\left(0.5\\, +0.5 k^{0.5}\\right)^{2.}-0.5 \\left(0.5\\, +0.5 k^{0.5}\\right)^{1.} k^{0.5}\\right)$\n\nSteady States:          Solve ${k}_{t+1}= \\frac{1}{(1+n)}s(w(k_t),f^\\prime(k_{t+1}))$\n\nWith the parameters: $\\{k\\to 0.154832\\}\\}$\n\nStability:             Compute the derivative of $k_{t+1}$ with respect to $k_{t}$ and evaluate at each steady state.\n\nWith the parameters:\n\n\\quad Steady state 1, Capital level: $0.154832$ Derivative=$0.141188$  Stable.\n\n\\includegraphics{xamples_gr4.eps}\n\n\\subsection*{Example 5}\nProduction function:    $f(k)=\\left(0.5\\, +0.5 k^{0.5}\\right)^{2.}$\n\nUtility function:       $u(c)=2 \\sqrt{c}$\n\nSavings function:       $s(w(k_t),f^\\prime(k_{t+1}))= \\frac{16. R w}{25.\\, +16. R}$\n\nSubstituting:           $s(w(k_t),f^\\prime(k_{t+1}))= \\frac{\\left(8. \\left(0.5\\, +0.5 k^{0.5}\\right)^{1.} \\left(\\left(0.5\\, +0.5 k^{0.5}\\right)^{2.}-0.5 \\left(0.5\\, +0.5 k^{0.5}\\right)^{1.} k^{0.5}\\right)\\right)}{\\left(\\left(25.\\, +\\frac{8. \\left(0.5\\, +0.5 k^{0.5}\\right)^{1.}}{k^{0.5}}\\right) k^{0.5}\\right)}$\n\nSteady States:          Solve ${k}_{t+1}= \\frac{1}{(1+n)}s(w(k_t),f^\\prime(k_{t+1}))$\n\nWith the parameters: $\\{k\\to 0.128222\\}$\n\nStability:             Compute the derivative of $k_{t+1}$ with respect to $k_{t}$ and evaluate at each steady state.\nWith the parameters:\n\n\\quad Steady state 1, Capital level: $0.128222$ Derivative=$0.107258$ Stable.\n\n\\includegraphics{xamples_gr5.eps}\n\n\n\\subsection*{Example 6}\nProduction function:    $f(k)=k^{0.5}$\n\nUtility function:       $u(c)=\\log(c)$\n\nSavings function:       $s(w(k_t),f^\\prime(k_{t+1}))= 0.444444 w$\n\nSubstituting:      $s(w(k_t),if^\\prime(k_{t+1}))= 0.222222 k^{0.5}$\n\nSteady States:          Solve ${k}_{t+1}= \\frac{1}{(1+n)}s(w(k_t),f^\\prime(k_{t+1}))$\n\nWith the parameters: $\\{k\\to 0.\\},\\{k\\to 0.0493827\\}$\n\nStability:             Compute the derivative of $k_{t+1}$ with respect to $k_{t}$ and evaluate at each steady state.\n\nWith the parameters:\n\n\\quad Steady state 1, Capital level: $0$. Derivative=$\\infty$ Unstable.\n\n\\quad Steady state 2, Capital level: $0.0493827$ Derivative=$0.5$ Stable.\n\n\\includegraphics{xamples_gr6.eps}\n\n\\subsection*{Example 7}\nProduction function:    $f(k)=\\frac{1}{0.9\\, +\\frac{0.1}{k}}$\n\nUtility function:       $u(c)=2 \\sqrt{c}$\n\nSavings function:       $s(w(k_t),f^\\prime(k_{t+1}))= \\frac{16. R w}{25.\\, +16. R}$\n\nSubstituting:           $s(w(k_t),f^\\prime(k_{t+1})= \\frac{1.6 \\left(\\frac{1}{0.9\\, +\\frac{0.1}{k}}-\\frac{0.1}{\\left(0.9\\, +\\frac{0.1}{k}\\right)^2 k}\\right)}{\\left(25.\\, +\\frac{1.6}{\\left(0.9\\, +\\frac{0.1}{k}\\right)^2 k^2}\\right) \\left(0.9\\, +\\frac{0.1}{k}\\right)^2 k^2}$\n\nSteady States:          Solve ${k}_{t+1}= \\frac{1}{(1+n)}s(w(k_t),f^\\prime(k_{t+1}))$\n\nWith the parameters: $\\{k\\to 0.018251\\},\\{k\\to 0.206304\\}$\n\nStability:             Compute the derivative of $k_{t+1}$ with respect to $k_{t}$ and evaluate at each steady state.\n\n\\includegraphics{xamples_gr7.eps}\n\n\\end{document}\n", "meta": {"hexsha": "46e9554958c29faa658efcf0c182cdc82a91b839", "size": 7517, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/olg/Mathematica/xamples.tex", "max_stars_repo_name": "eric-roca/eric-roca.github.io", "max_stars_repo_head_hexsha": "b982961710055b7ff6f026c9292469d5efc16b8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/olg/Mathematica/xamples.tex", "max_issues_repo_name": "eric-roca/eric-roca.github.io", "max_issues_repo_head_hexsha": "b982961710055b7ff6f026c9292469d5efc16b8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/olg/Mathematica/xamples.tex", "max_forks_repo_name": "eric-roca/eric-roca.github.io", "max_forks_repo_head_hexsha": "b982961710055b7ff6f026c9292469d5efc16b8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.9840425532, "max_line_length": 311, "alphanum_fraction": 0.5931887721, "num_tokens": 2855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772220439509, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7020359248561914}}
{"text": "\\section{Algebra}\n\n\\formdesc{Arithmetic Operations}\n\\vspace{-3.5em}\n\\begin{center}\n\\[\n\\def\\arraystretch{2.5}\n \\begin{array}{ll}\n  a \\left( \\frac{b}{c} \\right) = \\frac{ab}{c}   & \\frac{\\frac{a}{b}}{c} = \\frac{a}{bc}               \\\\\n   \\frac{a}{\\frac{b}{c}} = \\frac{ac}{b}         & \\frac{a}{b} \\pm \\frac{c}{d} = \\frac{ad \\pm bc}{bd} \\\\\n   \\frac{a - b}{c - d} = \\frac{b - a}{d - c}    & \\frac{ab + ac}{a} = b + c,~ \\forall a \\neq 0        \\\\\n   \\frac{a + bc}{c} = \\frac{a}{c} = \\frac{b}{c} & \\frac{\\frac{a}{b}}{\\frac{c}{d}} = \\frac{ad}{bc} \n \\end{array}\n\\]\n\\end{center}\n\\hformbar\n\n\n\n\\formdesc{Exponents}\n\n\\vspace{-3.5em}\n\\begin{center}\n\\[\n\\def\\arraystretch{2.5}\n \\begin{array}{ll}\n   x^a \\cdot x^b = x^{a + b}           & \\frac{x^a}{x^b} = x^{a - b}     \\\\\n   (xy)^a = x^a y^a                    & \\frac{x}{y}^a = \\frac{x^a}{y^a} \\\\\n   x^0 = 1 \\note                       & x^{-n} = \\frac{1}{x} \\note      \\\\\n   x^{\\frac{1}{a}} = \\sqrt[a]{x} \\note & (xy)^a = x^a y^a                \\\\\n   x^{-a} = \\frac{1}{x^a}             & \\left( \\frac{x}{y}   \\right)^{-a} = \\left( \\frac{y}{x} \\right)^a = \\frac{y^a}{x^a} \n \\end{array}\n\\]\n\\end{center}\n\n$\\note \\forall x \\neq 0$\n\n\\hformbar\n\n\n\n\\formdesc{Radicals}\n\n\\vspace{-2.5em}\n\\begin{center}\n\\[\n\\def\\arraystretch{2.5}\n \\begin{array}{ll}\n   \\sqrt[a]{x} = x^{\\frac{1}{a}} & \\sqrt[a]{xy} = \\sqrt[a]{x} \\sqrt[a]{y}\n \\end{array}\n\\]\n\\end{center}\n\n\\hformbar\n\n\n\n\\formdesc{Logarithms}\n\nDefined as $y = log_b x \\equiv x = b^y$, with domain of $x > 0$\n\n\\begin{center}\n\\vspace{-2em}\n\\[\n\\def\\arraystretch{1.6}\n \\begin{array}{ll}\n   log_b b = 1 & log_b 1 = 0 \\\\\n   log_b b^x = x & b^{log_b x} = x \\\\\n   log_b \\left( x^r \\right) = r ~ log_b x &  \\\\\n   log_b \\left( \\frac{x}{y} \\right) = log_b x - log_b y & \\\\\n   log_b (xy) = log_b x + log_b y & \n \\end{array}\n\\]\n\\end{center}\n\n\\hformbar\n\n\n\n\\formdesc{Factoring}\n\n\\begin{center}\n\\vspace{-2em}\n\\[\n\\def\\arraystretch{1.6}\n \\begin{array}{c}\n   x^2 - a^2 = (x + a)(x -a ) \\\\\n   x^2 \\pm 2ax + a^2 = (x \\pm a)^2 \\\\\n   x^2 + (a + b)x + ab = (x + a)(x + b)\n \\end{array}\n\\]\n\\end{center}\n\n\\hformbar\n\n\n\n\n\n\\formdesc{Functions}\n\n\\begin{itemize}\n\t\\item A rule for a relationship between an input and an output quantity where each input \\textit{uniquely determines} an output value \n\t\\item Must be of the form $y = f(x)$\n\\end{itemize}\n\n\\begin{footnotesize}\n  \\begin{tabular}{ll}\n    \\textsc{type} & \\textsc{form} \\\\\n    \\midrule\n    Constant & $f(x) = c$ \\\\\n    Identity & $f(x) = x$ \\\\\n    Absolute & $f(x) = |x|$\\\\\n    Quadratic & $f(x) = x^2$  \\\\\n    Cubic     & $f(x) = x^3$  \\\\\n    Reciprocal & $f(x) = \\frac{1}{x^2}$  \\\\\n    Square root & $f(x) = \\sqrt{x}$  \\\\\n  \\end{tabular}\n\\end{footnotesize}\n\\hformbar\n\n\n\n\\formdesc{Transformations of Functions}\n\n\\vspace{.3em}\n\\begin{footnotesize}\n  \\begin{tabular}{ll}\n  \\centering\n    \\textsc{Transformation} & \\textsc{Form} \\\\\n    \\midrule\n    Vertical shift & $f'(x) = f(x) + k$ \\\\\n    Horizontal shift & $f'(x) = f(x - k)$\\\\\n    Horizontal reflection & $f'(x) = f(-x)$\\\\\n    Vertical reflection & $f'(x) = -f(x)$  \\\\\n    Vertical stretch     & $f'(x) = kf(x), ~ k > 1$ \\\\\n    Vertical compression & $f'(x) = kf(x), ~ k 0 < k < 1$  \\\\\n  \\end{tabular}\n\\end{footnotesize}\n\\hformbar\n\n\n\n\\formdesc{Distance Formula}\n\n\\begin{equation}\n\td(P_1, P_2) = \\sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}\n\\end{equation}\n\n\nis the distance between points $P_1 = (x_1, y_1)$ and $P_2 = (x_2, y_2)$\n\\hformbar\n\n\n\n\\formdesc{Linear Functions}\n\n\\begin{itemize}\n\t\\item Linear functions have a constant rate of change, $m$\n\n\t\t\\begin{equation}\n\t\t\tm = \\frac{\\Delta y}{\\Delta x} = \\frac{y_2 - y_1}{x_2 - x_1} = \\frac{f(x_2) - f(x_1)}{x_2 - x_1}\n\t\t\\end{equation}\n\t\\item Estimate horizontal line by solving $f(x) = 0$\n\t\\item Find the point where two non-parallel lines meet: set $f(x) = g(x)$ and solve for $x$\n\t\\item Estimate slope from two points by solving for $m$:\n\t    \\begin{equation}\n\t        y_1 - y_2 = m(x_1 - x_2)\n\t    \\end{equation}\n\\end{itemize}\n\\hformbar\n\n\n\n\\formdesc{Quadratic Functions}\n\n\\begin{center}\n  \\begin{tabular}{ll}\n    Standard form                  & $f(x) = ax^2 + bx + c$                   \\\\[.7em]\n    Vertex or transformation form  & $f(x) = a(x - h)^2 + k$                  \\\\[.7em]\n    Quadratic eq.                  & $x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$ \\\\[.7em]\n  \\end{tabular}\n\\end{center}\n\n\\begin{itemize}\n    \\item $b^2 - 4ac > 0 \\Rightarrow$ Two real unequal solutions\n    \\item $b^2 - 4ac = 0 \\Rightarrow$ Repeated real solution\n    \\item $b^2 - 4ac < 0 \\Rightarrow$ Two complex solutions\n\\end{itemize}\n\n\\hformbar\n\n\n\n\\formdesc{Polynomial Functions}\n\n\\begin{equation}\n  f(x) = a_0 + a_1x + a_2x^2 + \\cdots + a_nx^n = \\sum_{k=0}^n a_k x^{n-k}\n\\end{equation}\n\n\\begin{center}\n  \\begin{tabular}{ll}\n    $a_0$     & Constant term                         \\\\\n    $a_n$     & Polynomial coefficient                \\\\\n    $a_nx^m$  & Term ($m$ is called \\textit{degree})  \\\\\n  \\end{tabular}\n\\end{center}\n\n\\hformbar\n\n\n\n\\formdesc{Rational Functions}\n\nCan be written as a quotient of two polynomials $P(x)$ and $Q(x)$:\n\n\\begin{equation}\n  f(x) = \\frac{P(x)}{Q(x)} = \\frac{\\sum_{k=0}^n a_k x^{n-k}}{\\sum_{k=0}^n b_k x^{n-k}}\n\\end{equation}\n\n  \\begin{itemize}\n    \\item Horizontal Intercept is the inputs where the output is 0\n    \\item Vertical Intercept is where input is 0 (if defined)        \n  \\end{itemize}\n\n\\hformbar\n\n\n\n\\formdesc{Asymptotes}\n\nThe ``line'' a function approaches but never touches\n\n\\begin{description}\n\t\\item[Vertical] A vertical line $x = a$ where the graph tends towards positive or negative \n\t                infinity as the inputs approach $a$:\n\t                \\begin{equation}\n\t                    x \\rightarrow a,\\, f(x) \\rightarrow \\pm~ \\infty\n\t                \\end{equation}\n\t\\item[Horizontal] A horizontal line $y = b$ where the graph approaches the line as the\n\t                  input gets larger:\n\t                   \\begin{equation}\n\t                       x \\rightarrow \\pm~ \\infty,\\, f(x) \\rightarrow b\n\t                   \\end{equation}\n\\end{description}\n\\hformbar\n\n\n\n\\formdesc{Asymptotes of Rational Functions}\n\n\\begin{description}\n    \\item[Vertical] Where denominator = 0 but numerator $\\neq 0$\n    \\item[Horizontal] Determined by respective degrees of numerator and denominator:\n        \\begin{itemize}\n            \\item Degree of denominator $>$ degree of numerator $\\Rightarrow$ Horizontal asymptote at $y = 0$\n            \\item Degree of denominator $<$ degree of numerator $\\Rightarrow$ No horizontal asymptote\n            \\item Degree of denominator = degree of numerator $\\Rightarrow$ Horizontal asymptote is ratio of leading coefficients\n        \\end{itemize}\n\\end{description}\n\\hformbar\n\n\n\n\\formdesc{Exponential Functions}\n\nRate of change is as a percent, i.e., not an constant (absolute) rate. Takes the form:\n\n\\begin{equation}\n    f(x) = a(1 + r)^x\n\\end{equation}\n\nor, \n\n\\begin{equation}\n    f(x) = ab^x,~ b = 1 + r\n\\end{equation}\n\nCan always be rewritten in terms of logarithms:\n\n\\begin{equation}\n    b^a = c \\equiv log_b~ c = a\n\\end{equation}\n\n\\begin{description}\n    \\item[Continuous Growth] Use $e = 2.718282\\dots$ for continuous growth, often natural phenomena\n        \\begin{equation}\n            f(x) = ae^{rx}\n        \\end{equation}\n        \n        where\n        \n        \\begin{itemize}\n            \\item $a \\equiv$ initial quantity\n            \\item $r \\equiv$ continuous growth rate\n        \\end{itemize}\n\\end{description}\n\n\\textit{ALMOST ALWAYS USE CONTINUOUS $e$ FORM!}\\\\\n\nSolve by:\n\n\\begin{enumerate}\n    \\item Isolate exponential expression, where possible\n    \\item Take log on both sides\n    \\item Use \\textit{exponent property} of logs to pull variables of out exponent\n    \\item Use algebra to solve for variable\n\\end{enumerate}\n\\hformbar\n\n\n\n\\formdesc{Graphing Exponential Functions}\n\n\\begin{itemize}\n    \\item $a \\equiv$ vertical intercept\n        \\begin{itemize}\n            \\item $a > 0 \\Rightarrow$ concave up\n            \\item $a < 0 \\Rightarrow$ concave down\n        \\end{itemize}\n    \\item $b \\equiv$ rate of growth\n        \\begin{itemize}\n            \\item $b > 1 \\Rightarrow$ growing\n            \\item $0 < b < 1 \\Rightarrow$ decaying\n        \\end{itemize}\n    \\item Horizontal asymptote is where $y = 0$\n\\end{itemize}\n\\hformbar\n\n\n\n\\formdesc{Logarithmic Functions}\n\nThe inverse of exponential functions; use to solve exponential functions. Commonly used to express quantities that vary widely in size. Form:\n\n\\begin{equation}\n    log_b~ x\n\\end{equation}\n\nwhich can be rewritten in terms of exponents:\n\n\\begin{equation}\n    b^a = c \\equiv log_b~ c = a\n\\end{equation}\n\n\\begin{description}\n    \\item[Inverse Property of Logs] \n        \\begin{eqnarray}\n            log_b~ b^x &=& x \\\\\n            b^{log_b~ x} &=& x\n        \\end{eqnarray}\n        \n    \\item[Exponent Property]\n        \\begin{equation}\n            log_b~ A^r = r log_b~ A\n        \\end{equation}\n\\end{description}\n\n\n\n\\newpage\n", "meta": {"hexsha": "5d9f94b0d58e834718d66fea46db27b4c168b9bb", "size": 8861, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/functions.tex", "max_stars_repo_name": "benhorvath/math_notes", "max_stars_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/functions.tex", "max_issues_repo_name": "benhorvath/math_notes", "max_issues_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/functions.tex", "max_forks_repo_name": "benhorvath/math_notes", "max_forks_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.4779005525, "max_line_length": 141, "alphanum_fraction": 0.5799571154, "num_tokens": 3066, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7020089732635075}}
{"text": "\\section{Methods}\n\n\\subsection{Model design}\n\nWe modeled the vertical accretion of a tidal platform ($\\sfrac{d\\eta}{dt}$) using a zero-dimensional mass balance approach initially described by \\citet{kroneMethodSimulatingMarsh1987} and validated by subsequent studies \\citep{allenSaltmarshGrowthStratification1990,frenchNumericalSimulationVertical1993,temmermanModellingLongtermTidal2003,temmermanModellingEstuarineVariations2004}. The rate of vertical accretion is described as\n\\begin{equation}\\label{eq:mass_bal}\n\t\\frac{d\\eta(t)}{dt} = \\frac{dS_m(t)}{dt} + \\frac{dS_o(t)}{dt} + \\frac{dP(t)}{dt} + \\frac{dM(t)}{dt},\n\\end{equation}\nwhere $\\sfrac{dS_m(t)}{dt}$ is the rate of mineral sedimentation, $\\sfrac{dS_o(t)}{dt}$ is the rate of organic matter sedimentation, $\\sfrac{dP(t)}{dt}$ is the rate of shallow compaction after dewatering of the deposited sediment, and $\\sfrac{dM(t)}{dt}$ is the rate of tectonic subsidence. We considered $\\sfrac{dS_o(t)}{dt}$, $\\sfrac{dP(t)}{dt}$, $\\sfrac{dM(t)}{dt}$ to be constants and used characteristic yearly rates for each; while, $\\sfrac{dS_m(t)}{dt}$ varies within a tidal cycle \\citep{haleSeasonalVariabilityForces2019} and requires additional treatment.\n\nTo solve for $\\sfrac{dS_m(t)}{dt}$, we began by conceptualizing a tidal platform periodically inundated by sinusoidal tides. We first defined depth to be\n\\begin{equation}\\label{eq:depth}\n\th(t) = \\zeta(t) - \\eta(t),\n\\end{equation}\nwhere $\\zeta(t)$ is the water-surface elevation and $\\eta(t)$ is the sediment-surface elevation which also implies that\n\\begin{equation}\\label{eq:depth_dt}\n\t\\frac{dh(t)}{dt} = \\frac{d\\zeta(t)}{dt} - \\frac{d\\eta(t)}{dt}.\n\\end{equation}\nIndependently, we assume while $h(t) > 0$, the rate of mineral sedimentation is\n\\begin{equation}\\label{eq:sed_flux}\n\t\\frac{dS_m(t)}{dt} = \\frac{w_sC(t)}{\\rho_b},\n\\end{equation}\nwhere $w_s$ is the nominal settling velocity of a sediment grain, $C(t)$ is the depth-averaged suspended sediment concentration (SSC) in the water column, and $\\rho_b$ is the bulk density of the sediment. We assumed no resuspension of mineral sediment which is practical and consistent with previous studies \\citep{kroneMethodSimulatingMarsh1987, allenSaltmarshGrowthStratification1990, frenchNumericalSimulationVertical1993, temmermanModellingLongtermTidal2003, temmermanModellingEstuarineVariations2004}.\n\nIn order to solve for $C(t)$ in \\cref{eq:sed_flux}, we first defined a mass balance of sediment within the water column as\n\\begin{equation}\\label{eq:conc_mass_bal}\n\t\\frac{d}{dt}[h(t)C(t)] = -w_s C(t) + C_b \\frac{dh(t)}{dt},\n\\end{equation}\nwhich can be expanded and rerranged as\n\\begin{equation}\\label{eq:conc_dt}\n\t\\frac{dC(t)}{dt} = - \\frac{w_sC(t)}{h(t)} - \\frac{1}{h(t)}[C(t) - C_b]\\frac{dh(t)}{dt}.\n\\end{equation}\nWe assumed advection of new sediment to only occur during flood tide by constraining mass flux from the boundary term when $\\sfrac{dh}{dt} > 0$. We formalized this mathematically using a Heaviside function which serves as a binary switch and is given as\n\\begin{equation}\\label{eq:heaviside}\n\tS = \\frac{dh}{dt},\\quad\tH(S) =\n\t\\begin{cases}\n\t\t0 & \\text{if $S < 0$}\\\\\n\t\t1 & \\text{if $S \\geq 0$}.\n\t\\end{cases}\n\\end{equation}\n\\Cref{eq:conc_dt} then becomes\n\\begin{equation}\\label{eq:conc_sol}\n\t\\frac{dC(t)}{dt} = - \\frac{w_s C(t)}{h(t)} - \\frac{H(S)}{h(t)} [C(t) - C_b]\\frac{dh(t)}{dt}.\n\\end{equation}\n\\Crefnosort{eq:conc_sol,eq:sed_flux,eq:mass_bal} were then solved in that order to obtain the change in elevation during one time step.\n\nWe integrated this series of equations for each inundation cycle using an explicit Runge-Kutta method of order 5(4) \\citep{dormandFamilyEmbeddedRungeKutta1980} implemented in Python using SciPy \\citep{virtanenSciPyFundamentalAlgorithms2020}. We used an adaptive step size which provided computational efficiency by decreasing step size as needed - i.e. beginning and end of an inundation cycle. To avoid numerical errors due to very small depths in \\cref{eq:conc_sol}, we only allowed the model to integrate while water depths were \\SI{>1}{\\milli\\meter}. Outside of the integration (i.e. while the platform was dry), we continued to apply linear rates for $\\sfrac{dS_o(t)}{dt}$, $\\sfrac{dP(t)}{dt}$, $\\sfrac{dM(t)}{dt}$.\n\nWe indentified indundation cycles by filtering the tidal curve for water-surface elevations that were above the corresponding sediment-surface elevation. The time of first element of the filtered data was used to initialize the integration. The adaptive step size method required a continuous function for water-surface elevations so we converted the tidal data to an interpolated univariate spline during the integration. The integration continued until the water-surface elevation fell below the sediment-surface elevation. We repeated this process for all subsequent inundation cycles through the prescribed length of each simulation to obtain a final elevation.\n\n\\subsection{Field observations and model parameters}\n\n\\bigskip\n\n\\subsubsection*{Tidal data}\n\nThe tidal curve was derived from observations at Sutarkhali station. Water-surface elevations were collected every 10 minutes from January 1, 2019 to December 31, 2019 using an Onset U20L-01 HOBO water level data logger. The data were processed and upsampled to \\SI{1}{\\second} temporal resolution using the oce package in R (3.6.3) \\citep{kelleyOceAnalysisOceanographic2020}. The tidal curve was then shifted to place mean water at \\SI{\\approx1.6}{\\meter} below the Sundarban sediment-surface. This results in \\SIrange{\\approx 50}{60}{\\centi\\meter} of inundation during most spring high tides and is consistent with survey data \\citep{auerbachFloodRiskNatural2015,haleSeasonalVariabilityForces2019,bomerSurfaceElevationSedimentation2020}. We repeated this tidal curve for each subsequent year of the simulation with a superimposed sea level rise rate of \\SI{5}{\\milli\\meter\\per\\year}.\n\n\\subsubsection*{Organic matter, shallow compaction, and subsidence}\n\n\\citet{bomerProcessControlsLive2020} found organic matter only accounts for $\\sim$\\SI{0.9(1)}{\\percent} of the $\\sim$\\SI{2.42(26)}{\\centi\\meter\\per\\year} yearly bulk sedimentation. Using this, we set $\\sfrac{dS_o(t)}{dt}$ to \\SI{0.2}{\\milli\\meter\\per\\year}.\n\nShallow compaction is difficult to constrain for the region and likely varies significantly due to natural variability in stratigraphy and anthropogenic activity (e.g. subsurface fluid extraction and accelerated oxidation of below-ground biomass due to drying of the sediment). \\citet{auerbachFloodRiskNatural2015} suggested shallow compaction rates of \\SI{0.4}{\\centi\\meter\\per\\year} for natural compaction and \\SI{0.8}{\\centi\\meter\\per\\year} for accelerated compaction (combined natural and anthropogenic compaction). We adopted their values of $\\sfrac{dP(t)}{dt}$.\n\nEstimates of subsidence vary for the region and are hard to disentangle from compaction. Many studies \\citep{pethickRapidRiseEffective2013,goodbredSignificanceLargeSediment2000,stanleyHoloceneDepositionalPatterns2000} combine compaction and subsidence. \\citet{auerbachFloodRiskNatural2015} considered both compaction and subsidence separately by using values in the literature \\citep{pethickRapidRiseEffective2013,goodbredSignificanceLargeSediment2000,stanleyHoloceneDepositionalPatterns2000} estimated subsidence to be \\SI{0.3}{\\centi\\meter\\per\\year}. We set $\\sfrac{dM(t)}{dt}$ to this value.\n\n\\subsubsection*{Settling velocity, suspend sediment concentration, and bulk density}\n\nWe used Stoke's law to determine $w_s$. Stoke's law assumes unhindered settling which likely overestimates actual settling rates and, therefore, mineral sedimentation rates. However, we only considered settling for a singular, median grain size which likely underestimated mineral sedimentation rates from coarser grains. Model calibration further corrected for these errors. Thus, the $w_s$ given by Stoke's law should be considered an imprecise, but reasonable approximation.\n\nFor $C_{b}$, we use observed values of SSC from \\citet{haleObservationsScalingTidal2019} that are characteristic of the tidal channels in the region.\n\nFor $\\rho$, we used values derived from conversations with Steven Goodbred and Carol Wilson.", "meta": {"hexsha": "b90cf6ae0dad7a558becc84f6ce74996f5ac443c", "size": 8168, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/manuscript/sections/__latexindent_temp.tex", "max_stars_repo_name": "christasich/tidal_flat_0d", "max_stars_repo_head_hexsha": "873a0abf8409f7bb920e71fc92896b238c3cab2b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-07-17T20:03:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T21:46:36.000Z", "max_issues_repo_path": "reports/manuscript/sections/__latexindent_temp.tex", "max_issues_repo_name": "christasich/tidal_flat_0d", "max_issues_repo_head_hexsha": "873a0abf8409f7bb920e71fc92896b238c3cab2b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "reports/manuscript/sections/__latexindent_temp.tex", "max_forks_repo_name": "christasich/tidal_flat_0d", "max_forks_repo_head_hexsha": "873a0abf8409f7bb920e71fc92896b238c3cab2b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 111.8904109589, "max_line_length": 885, "alphanum_fraction": 0.7830558276, "num_tokens": 2302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7020089697532823}}
{"text": "\\chapter{Maximum likelihood estimation}\n\\label{chap:mle}\n\nThe technique used for the yield extraction is the method of maximum \nlikelihood, where an objective function is defined that assumes some particular \nmodel truly generated the data.\nThe vector of parameters $\\vec{\\theta}$ of that model are varied given a vector \n$\\vec{x}$ of $N$ independent, randomly distributed measurements $x_{i}$ until \nthe objective is maximised.\nThis objective is the likelihood \\likelihood, and is defined as\n\\begin{equation}\n  \\likelihood(\\vec{\\theta}|\\vec{x}) = \\prod_{i}^{N} f(x_{i}|\\vec{\\theta}),\n\\end{equation}\nwhere $f$ is the \\ac{PDF} that the data are assumed to have been sampled \nfrom.\\footnotemark\nPractically, it is useful to work with the logarithm of the likelihood, as sums \nare more convenient to work with numerically than products, and to use the \nnegative of this, in order to be able to exploit the available numerical \nalgorithms for minimisation problems such as the \\migrad\\ algorithm in the \n\\minuit\\ package~\\cite{James:1975dr,James:1994vla}\n\\begin{equation}\n  -\\ln{\\likelihood(\\vec{\\theta}|\\vec{x})} =\n  -\\sum_{i}^{N} \\ln{f(x_{i}|\\vec{\\theta})}.\n\\end{equation}\nThis is the \\acf{NLL}.\nThe practice of minimising the \\ac{NLL} is also called \\emph{fitting}.\n\n\\footnotetext{%\n  The properties of any given \\ac{PDF} $f(x)$ that are important here are: \n  $f(x) \\geq 0$ for all $x$; and $\\int_{-\\infty}^{\\infty} f(x)\\dif{x} = 1$.\n}\n\nFor the purposes of this analysis, the total \\ac{PDF} $f$ is the sum of several \nmodels $f_{s}$, one for each physical source $s$ under consideration, such as \nsignal and combinatorial background or different \\pTy\\ bins\n\\begin{equation}\n  \\ln{\\likelihood(\\vec{\\theta}|\\vec{x})} =\n  \\sum_{i}^{N} \\ln{\\sum_{s} f_{s}(x_{i}|\\vec{\\theta})}.\n\\end{equation}\nThe notation here that each model $f_{s}$ receives the full parameter vector \n$\\vec{\\theta}$ implies that each $f_{s}$ may share parameters with other \ncomponents.\nIn order to not only model the shape of the components but also their absolute \nsize, an \\emph{extended} maximum likelihood fit~\\cite{Barlow:1990vc} is \nperformed that relaxes the normalisation requirement on the total \\acp{PDF} to \nallow for Poisson fluctuations around the observed number of events \n$N_{\\text{obvs.}}$\n\\begin{equation}\n  \\ln{\\likelihood(\\vec{\\theta}, \\vec{N}|\\vec{x})} =\n  \\sum_{i}^{N}\n    \\ln{\\sum_{s} N_{s}f_{s}(x_{i}|\\vec{\\theta})}\n    - \\sum_{s} N_{s}\n  ,\n\\end{equation}\nwhere $N_{s}$ is the \\emph{yield} associated to each component model $f_{s}$ \nand $\\vec{N}$ is the vector of those yields.\n\nAfter defining the full model, the \\acl{NLL} is minimised numerically using \n\\minuit.\nMinimising the \\ac{NLL} is equivalent to finding the parameter vector \n$\\hat{\\theta}$ where the first derivatives of the likelihood with respect to \neach parameter are all zero\n\\begin{equation}\n  \\vec{u}(\\vec{\\theta}) = \\frac{%\n    \\partial\\ln{\\likelihood}\n  }{%\n    \\partial\\vec{\\theta}\n  },\\quad\n  \\vec{u}(\\hat{\\theta}) = \\vec{0},\n\\end{equation}\nwhere for compactness $\\vec{\\theta}$ includes the $\\vec{N}$ parameter vector.\nThe uncertainties on the parameters can be found by inspecting the diagonal \nterms of the covariance matrix, which can be computed numerically by inverting \nthe \\emph{observed} Fisher information matrix $I(\\hat{\\theta})$, defined via\n\\begin{equation}\n  I(\\vec{\\theta}) = \\frac{%\n    \\partial^{2}\\ln{\\likelihood}\n  }{%\n    \\partial\\vec{\\theta}\\partial\\vec{\\theta}'\n  }.\n\\end{equation}\nThe second derivative around the likelihood can be thought of as describing the \n`peakiness' of the minimum, where a shallower peak corresponds to less \ncertainty in the measurement of the parameter, and conversely a sharper peak \ncorresponds to a greater certainty in the value at the minimum.\nThe computation of the set of second derivatives, and the proceeding matrix \ninversion to obtain the covariance matrix, is performed numerically from the \nminimised \\ac{NLL} by the \\hesse\\ algorithm, part of \\minuit.\n\nTo estimate the yields in the data, suitable models must be constructed.\nThe following Sections shall describe the construction of these models for the \nvarious fits.\n", "meta": {"hexsha": "71ba8589fab986c2d4c56aa0405fdc43514be17c", "size": 4146, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/appendices/mle.tex", "max_stars_repo_name": "alexpearce/Thesis", "max_stars_repo_head_hexsha": "d727d04b7ee619ba0eb45c7faf1004eb418e046e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-18T00:58:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T00:58:34.000Z", "max_issues_repo_path": "chapters/appendices/mle.tex", "max_issues_repo_name": "alexpearce/Thesis", "max_issues_repo_head_hexsha": "d727d04b7ee619ba0eb45c7faf1004eb418e046e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/appendices/mle.tex", "max_forks_repo_name": "alexpearce/Thesis", "max_forks_repo_head_hexsha": "d727d04b7ee619ba0eb45c7faf1004eb418e046e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-05-13T07:54:57.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-06T23:42:27.000Z", "avg_line_length": 44.5806451613, "max_line_length": 80, "alphanum_fraction": 0.7301013025, "num_tokens": 1179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.7019477610577256}}
{"text": "\\begin{appendix}\n\\chapter{Formulae}\n\\begin{align}\n\\delta\\tensor{g}{^\\mu^\\nu}\n&=-\\tensor{g}{^\\varrho^{(\\mu}}\\tensor{g}{^{\\nu)}^\\sigma}\\delta\\tensor{g}{_\\mu_\\nu}\\label{eq:grels}\\\\\n\\delta\\det g&=\\det g \\tensor{g}{^\\mu^\\nu}\\delta\n\\tensor{g}{_\\mu_\\nu}\n\\end{align}\n\\begin{equation}\n\\mathrm{div} A=\\tensor{\\partial}{_i}\\tensor{A}{^i}=\\cSym{i}{i}{k}\\tensor{A}{^k}\n\\end{equation}\n\\begin{equation}\n\\tensor{\\partial}{_k}g=2g\\cSym{i}{i}{k}\n\\end{equation}\n\\begin{equation}\n\\cSym{i}{i}{k}=\\frac{1}{\\sqrt{g}}\\tensor{\\partial}{_k}\\sqrt{g}\n\\end{equation}\n\\begin{equation}\n\\mathrm{div}\nA=\\frac{1}{\\sqrt{g}}\\tensor{\\partial}{_k}\\left(\\sqrt{g}\\tensor{A}{^k}\\right)\n\\end{equation}\nIf further $A$ is derived from a potential\n$\\tensor{A}{_i}=\\tensor{\\partial}{_i}V$\n\\begin{equation}\n\\square V\n=\\mathrm{div}A\n=\\frac{1}{\\sqrt{g}}\\tensor{\\partial}{_k}\\left(\\sqrt{g}\\tensor{g}{^k^i}\\tensor{\\partial}{_i}V\\right)\\label{eq:quabla}\n\\end{equation}\n\\end{appendix}", "meta": {"hexsha": "f39876318cc0db1c10dc8764a81eeb141451007c", "size": 931, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/A-appendix.tex", "max_stars_repo_name": "Bigben37/GeneralRelativity", "max_stars_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-31T13:18:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-31T13:18:57.000Z", "max_issues_repo_path": "src/A-appendix.tex", "max_issues_repo_name": "QuantumDancer/GeneralRelativity", "max_issues_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/A-appendix.tex", "max_forks_repo_name": "QuantumDancer/GeneralRelativity", "max_forks_repo_head_hexsha": "c3ca730b97d2f90a6e74da296cf1b5bb0305126b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.1034482759, "max_line_length": 116, "alphanum_fraction": 0.6584317938, "num_tokens": 395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973295, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.7019477524657021}}
{"text": "\n\n\\textbf{Necessary and Sufficient Condition for Stability} \\newline\n\n\\begin{enumerate}\n\\item $|a_n| < |a_0|$ \n\\item $P(1) > 0$\n\\item \\begin{align*}\nP(-1) & > 0 \\ \\text{for n even } \\\\\n& < 0 \\ \\text{for n odd}\n\\end{align*}\n\\item $b_{n-1}> |b_0|, |c_{n-2}|>|c_0|, \\cdots |q_2| > |q_0|$\n\\end{enumerate}\n\n\\textbf{Special Case n =2} \\newline \n$P(z) =a_0z^2+a_1z+a_2$ \\newline \n\\begin{tabular}{c c c}\n$z^0$ & $z^1$& $z^2$ \\\\\n$a_2$ & $a_1$ & $a_0$\n\\end{tabular} \\newline\n$P(z) \\neq 0$ for $|z| \\geq 1$ if and only if \n\\begin{enumerate}\n\\item $|a_2| < |a_0|$\n\\item $P(1) > 0$\n\\item $P(-1) > 0 \\quad (n=2)$\n\\end{enumerate}\n\n \\textbf{Root Locus} presents the poles of the closed loop system when the gain K changes from zero to infinity.\n\n \\textbf{Construction of the Root Locus}\n\n Open loop transfer function\n $ \\displaystyle \\text{KH}\\left( s \\right)G\\left( s \\right) = K\\frac{B(s)}{A(s)}$\n\nm: the order of the \\textbf{open-loop} numerator polynomial.\n\n n: the order of the \\textbf{open-loop} denominator polynomial. $q=n-m$\n\n \\textbf{Rule 1:} number of branches equals the number of poles of the\n open-loop transfer function\n\n \\textbf{Rule 2:} If the total number of poles and zeros of the open-loop\n system to the right of the s-point on the real axis is odd, then this\n point lies on the locus.\n\n\\textbf{Rule 3:} The locus starting point (K=0) are at the open-loop\n poles and the locus ending points (K=$\\infty$) are at the open loop zeros and\n n-m branches terminate at infinity.\n\n\\textbf{Rule 4 and 5:} Slope of asymptotes of root locus as `s' approaches infinity. \\newline Abscissa of the intersection between asymptotes of root locus and real-axis.\n\\begin{align*}\n& \\sigma  = {\\frac{\\sum\\limits_{i = 1}^n {{p_i}}  - \\sum\\limits_{i = 1}^m {{z_i}} }{q}} \\quad \\theta = \\pm r{\\frac{180}{q}} \\quad \\text{where r=1, 3, 5} \\\\\n& f\\left( s \\right) = A\\left( s \\right) + KB\\left( s \\right) = 0\\ \\ \\ \\ and\\ \\ \\ \\ K = - \\frac{A\\left( s \\right)}{B\\left( s \\right)} \\\\\n& \\frac{\\text{dK}}{\\text{ds}} = - \\frac{A^{'}\\left( s \\right)B\\left( s \\right) - A\\left( s \\right)B^{'}\\left( s \\right)}{B^{2}\\left( s \\right)} = 0 \\\\\n \\end{align*}\n \\textbf{Rule 5:} \n\n \\textbf{Rule 6:} Break-away and break-in points. From the characteristic\n  equation\n\n  \\[f\\left( s \\right) = A\\left( s \\right) + KB\\left( s \\right) = 0\\ \\ \\ \\ and\\ \\ \\ \\ K = - \\frac{A\\left( s \\right)}{B\\left( s \\right)}\\]\n\n  The break-away and break-in points can be found from\n\n  \\[\\frac{\\text{dK}}{\\text{ds}} = - \\frac{A^{'}\\left( s \\right)B\\left( s \\right) - A\\left( s \\right)B^{'}\\left( s \\right)}{B^{2}\\left( s \\right)} = 0 \\]\n\n  \\textbf{Rule 7:} Angle of departure from complex poles or zeros.\n  Subtract from $180^o$ the sum of all angles from all other zeros and poles\n  of the open-loop system to the complex pole (or zero) with appropriate signs. \n\n \\begin{align*}\n& \\text{Z-transform: Definition} \\quad F(z)=Z[f(t)]-Z[f(kT)]=\\sum_{k=0}^{\\infty}f(kT)z^{-k} \\\\\n& e^\\ast(\\infty)=\\lim_{z \\rightarrow 1} (1-z^{-1})E(z) \\quad K_p=\\lim_{z \\rightarrow 1} GH(z), \\quad e^\\ast (\\infty) = \\frac{1}{1+K_p} \\\\\n& e^\\ast(\\infty) = \\frac{1}{K_v}, \\quad K_v =  \\lim_{z \\rightarrow 1} \\frac{(1-z^{-1}) GH(z)}{T}  \\\\\n& e^\\ast(\\infty) = \\frac{1}{K_a}, \\quad K_a =  \\lim_{z \\rightarrow 1}\\frac{(1-z^{-1})^2 GH(z)}{T^2}\n\\end{align*}\n\n{\\bf Linear Factor Rule.}  \n For each factor of $Q$ of the form $(ax+b)^m$, \n the partial fraction decomposition contains \n the following sum of $m$ partial fractions:  \n\\[\n\\frac{A_1}{ax+b} + \\frac{A_2}{(ax+b)^2} + \\cdots + \\frac{A_m}{(ax+b)^m},\n\\]\n where the $A_i$ are constants to be determined.  \n\n\\medskip\n\\noindent\n{\\bf Quadratic Factor Rule.}  \n For each factor of $Q$ of the form $(ax^2+bx+c)^m$, \n where $ax^2+bx+c$ is an irreducible quadratic, \n% the partial fraction decomposition contains \n the following sum of $m$ partial fractions:  \n\\[\n\\frac{A_1x+B_1}{ax^2+bx+c} + \\frac{A_2x+B_2}{(ax^2+bx+c)^2} + \\cdots \n  + \\frac{A_mx+B_m}{(ax^2+bx+c)^m},\n\\]\n where the $A_i$ and $B_i$ are constants to be determined. \n\n\nGeometric Sum $\\sum\\limits_{k = -N}^{N} {ar^{k - 1} = a\\frac{1-r^{N}}{{1 - r}}} \\sum_{i=0}^\\infty a^i=\\frac{1}{1-a}$\n\n$ x(k+2)-\\frac{3}{2}x(k+1)+\\frac{1}{2}x(k)=u(k), \\text(x(0)=1,x(1)=5/2) $\n\n$[z^2X(z)-z^2x(0)-zx(1)]-\\frac{3}{2}(zX(z)-zx(0)]+\\frac{1}{2}X(z)=\\frac{z}{z-1}$\n\n\n\\textbf{Effects of T on Transient Behaviour} \\hfill \\break \n$s= -\\zeta \\omega_n \\pm j \\omega_n \\sqrt{1-\\zeta^2}$,  \\hfill \\break \n$\\zeta$: damping ratio  \\hfill \\break \n$\\omega_n$: undamped natural frequency,  \\hfill \\break \n$\\omega_d$: damped natural frequency \\hfill \\break\n$z=e^{Ts} \\rightarrow z= \\exp\\left[T(-\\zeta \\omega_n +j\\omega_n \\sqrt{1-\\zeta^2})\\right]$, and\n$|z|=e^{-T \\zeta \\omega_n}$, $\\angle z = T \\omega_n \\sqrt{1-\\zeta^2}= T \\omega_d$. $\\uparrow T$ makes system less stable (for the same gain K) than $\\downarrow T$.\n\\textbf{Matrix Inverses for 2x2 and 3x3}\n\\begin{align*}\n& A^{-1} = \\begin{bmatrix}\na & b \\\\\nc & d\n\\end{bmatrix}^{-1}= \\frac{1}{|A|}\\begin{bmatrix}\nd & -b \\\\\n-c & a\n\\end{bmatrix} \\ \\begin{bmatrix}\na & b & c \\\\\nd & e & f \\\\\ng & h & i\n\\end{bmatrix}^{-1} \\\\\n& A^{-1} = \n\\frac{1}{|A|}\\begin{bmatrix}\n% Row one determinate\n+\\begin{vmatrix}\ne & f \\\\\nh & i\n\\end{vmatrix} & \n-\\begin{vmatrix}\nb & c \\\\\nh & i\n\\end{vmatrix} & \n+\\begin{vmatrix}\nb & c \\\\\ne & f\n\\end{vmatrix} \\\\\n& & \\\\\n-\\begin{vmatrix}\nd & f \\\\\ng & i\n\\end{vmatrix} & +\\begin{vmatrix}\na & c \\\\\ng & i\n\\end{vmatrix} &\n-\\begin{vmatrix}\na & c \\\\\nd & f\n\\end{vmatrix} \\\\\n& & \\\\\n+\\begin{vmatrix}\nd & e \\\\\ng & h\n\\end{vmatrix} &\n-\\begin{vmatrix}\na & b \\\\\ng & h\n\\end{vmatrix} &\n+\\begin{vmatrix}\na & b \\\\\nd & e\n\\end{vmatrix}\n\\end{bmatrix}^{-1}\n\\end{align*}\n\\textbf{Bilinear Transform}  \\hfill \\nopagebreak\n$s= \\frac{2(1-z^{-1})}{T(1+z^{-1})}$, $z=\\cfrac{1+0.5Ts}{1-0.5Ts}$.\n\n\\text{1. Stability} $\\Re[s] < 0$\n\n$\\displaystyle \\Re \\left(\\frac{2}{T} \\frac{1-z^{-1}}{1+z^{-1}}\\right)= \\Re \\left(\\frac{2}{T}\\frac{z-1}{z+1}\\right) < 0$, $z= \\sigma + j \\omega$ \\hfill \\nopagebreak\n\n$\\displaystyle \\Re \\frac{z-1}{z+1}=\\Re \\left[\\frac{\\sigma^2-1+\\omega^2+2j\\omega}{(\\sigma+1)^2+\\omega^2}\\right] \\rightarrow \\sigma^2-1+\\omega^2 < 0$.\n\n\n\\textbf{Solution of inhomogeneous state equations}\nscalar $\\dot{x}=ax+bu \\quad \\dot{x}-ax=bu$\n\\begin{align*}\n& e^{-at}[\\dot{x}(t)-ax(t)]=\\underbrace{\\frac{d}{dt}[e^{-at}x(t)]=e^{-at}bu(t)}_{\\text{integrate ~$0 \\rightarrow t$}} \\\\\n& e^{-at}x(t)-x(0) = \\int^t_0 e^{-a \\tau}bu(\\tau) d\\tau \\\\\n& \\rightarrow x(t)=e^{at}x(0)+e^{at}\\int_0^te^{-a\\tau}bu(\\tau)d\\tau\n\\end{align*}\nmatrix: $\\dot(x)=Ax+bu$, but taking $\\mathcal{L}^{-1}$ leads to  \\hfill \\break  $x(t)=e^{At}x(0)+\\int_{0}^{t}e^{A(t-\\tau)}bu(\\tau) d\\tau$\n\n\\textbf{Controllable Canonical Form} \\hfill \\nopagebreak\n\n% \\hfill \\break \\nopagebreak\n\\resizebox{.9\\linewidth}{!}{\n  \\begin{minipage}{\\linewidth}\n\\begin{align*}\n& G(z) = \\frac{b_0+b_1z^{-1}+ \\cdots + b_nz^{-n}}{1+a_1z^{-1}+ \\cdots + a_n}= \\frac{b_0z^n+b_1z^{n-1}+ \\cdots + b_n}{z^n+a_1z^{n-1}+\\cdots + a_n} \\\\\n& G(z)= b_0 + \\frac{(b_1-a_1b_0)z^{-1}+(b_2-a_2b_0)z^{-2}+ \\cdots + (b_n-a_nb_0)z^{-n-1}}{1+a_1z^{-1}+a_2z^{-2}+ \\cdots + a_nz^{-n}} \\\\\n& \\begin{bmatrix}\nx_1(k+1) \\\\\n \\vdots \\\\\nx_n(k+1)\n\\end{bmatrix}= \\begin{bmatrix}\n0      & 1         & 0      & \\cdots \\\\\n\\vdots & \\cdots    &        & \\vdots \\\\\n\\vdots &           &  \\cdots      &   1    \\\\\n-a_n   &  \\cdots   & \\cdots & -a_1\n\\end{bmatrix}\\begin{bmatrix}\nx_1(k) \\\\\n \\vdots \\\\\nx_n(k)\n\\end{bmatrix}+\\begin{bmatrix}\n0 \\\\\n \\vdots \\\\\n0 \\\\\n1\n\\end{bmatrix}u(k) \\\\\n& y(k) = \\begin{bmatrix}\nb_n-a_nb_0, & b_{n-1}a_{n-1}b_0, & b_1-a_1b_0\n\\end{bmatrix} \\begin{bmatrix}\nx_1(k) \\\\\n\\vdots \\\\\nx_n(k)\n\\end{bmatrix} + b_0 u(k) \\\\\n& z \\rightarrow s \\quad  zX(z) = \\mathcal{Z}[x(k+1)] \\quad  sX(s) = \\mathcal{L}[x(t)]\n\\end{align*}\n  \\end{minipage}\n} \\hfill \\nopagebreak\n\n\\textbf{Observable Canonical Form} \\hfill \\nopagebreak\n\n\\resizebox{.9\\linewidth}{!}{\n  \\begin{minipage}{\\linewidth}\n\\begin{align*}\n& \\begin{bmatrix}\n\\dot{x_1} \\\\\n \\vdots \\\\\n\\dot{x_n}\n\\end{bmatrix}= \\begin{bmatrix}\n0      & 0         & 0      & -a_n     \\\\\n1 & \\cdots    &        & -a_{n-1} \\\\\n0 &           & \\cdots &   \\vdots \\\\\n0   &  0   & 1 & -a_1\n\\end{bmatrix} \\begin{bmatrix}\nx_1 \\\\\n \\vdots \\\\\nx_n\n\\end{bmatrix}+\\begin{bmatrix}\nb_n-a_nb_0 \\\\\n \\vdots \\\\ \nb_1-a_1b_0\n\\end{bmatrix}u(k) \\\\\n& y(k) = \\begin{bmatrix}\n0, & \\cdots & \\cdots, & 0, & 1 \n\\end{bmatrix} \\begin{bmatrix}\nx_1 \\\\\n\\vdots \\\\\nx_n\n\\end{bmatrix} + b_0 u(k) \n\\end{align*}\n  \\end{minipage}\n} \\hfill \\nopagebreak\n\n\\textbf{Part-Frac-Expansion Method, Dia Canonical} %\\hfill \\nopagebreak\n\\vspace{-0.425cm}\n\\begin{align*}\n& G(z) =  b_0 + \\frac{c_1}{z-p_1} + \\cdots \\ \\cdots + \\frac{c_n}{z-p_n} \\\\\n& \\begin{bmatrix}\nx_1(k+1) \\\\\n\\vdots \\\\\n\\vdots \\\\\nx_n(k+1)\n\\end{bmatrix} =  \\begin{bmatrix}\np_1     & 0       & \\cdots  & 0      \\\\\n0       & \\vdots  &         & 0      \\\\\n\\vdots  &         &  \\vdots & \\vdots \\\\\n0       & 0       &  \\cdots & p_n\n\\end{bmatrix}\\begin{bmatrix}\nx_1(k) \\\\\n\\vdots \\\\\n\\vdots \\\\\nx_n(k)\n\\end{bmatrix} + \\begin{bmatrix}\n1 \\\\\n1 \\\\\n\\vdots \\\\\n1\n\\end{bmatrix} u(k) \\\\\n&  y(k) = \\begin{bmatrix}\nc_1 & \\cdots & c_n\n\\end{bmatrix} \\begin{bmatrix}\nx_1    \\\\\n\\vdots \\\\\nx_n\n\\end{bmatrix} + b_0 u(k)\n\\end{align*}\n\n\\textbf{Special Case} %hill \\nopagebreak\n%\n\\vspace{-0.425cm}\n\\begin{align*}\n& y^{(n)}+a_1y^{(n-1)}+ \\cdots + a_{n-1}y+a_{n}=u \\quad \\dot{x} = Ax + bu  \\\\\n& x = \\begin{bmatrix}\nx_1 \\\\\n\\vdots \\\\\n\\vdots \\\\\nx_n\n\\end{bmatrix} \\quad \nA = \\begin{bmatrix}\n0      & 1        &  \\vdots & \\vdots       & 0        \\\\\n0      & 0        &  1      &              & \\vdots   \\\\\n\\vdots &          &         & \\ddots       & \\vdots   \\\\\n0      &          &         &              &  1       \\\\\n-a_n   & -a_{n-1} &  \\cdots & \\cdots       & -a_1 \n\\end{bmatrix}\n\\end{align*}\n\n\\vspace*{-0.90cm}\n\n\\begin{minipage}[h]{0.25\\linewidth}\n\\[\nb = \\begin{bmatrix}\n0 \\\\\n0 \\\\\n\\vdots \\\\\n1\n\\end{bmatrix}\n\\]\n\\end{minipage}\n\\begin{minipage}[h]{0.75\\linewidth}\n\\begin{align*}\n& c = [1 \\ 0 \\ .. \\ 0] \\ \\quad y =cx+du \\ \\text{and} \\ d=0 \\\\\n& Y(s) = [c(sI-A)^{-1}b+d]U(s) \\quad \\\\ \n& \\frac{Y(z)}{U(z)} = c(zI-A)^{-1}b+d \n\\end{align*}\n\\end{minipage}\n\\textbf{Deadbeat Controller and Deadbeat Response}\n\\vspace*{-0.25cm}\n\\begin{align*}\n& x(k+1)=Gx(k)+Hu(k) \\quad u(k)=-Kx(k) \\\\\n& x(k+1)=(G-HK)x(k) \\quad x(k)=(G-HK)^kx(0) \\\\\n& x(k) = (G-HK)^kx(0) \\quad x(k) =0 \\quad \\text(for) k \\geq \\quad q (q \\leq n) \\\\\n& \\det(zI-G+HK)=z^n \\quad N^n =0, \\text{N is nilpotent matrix.}\n\\end{align*}\n\\vspace*{-0.7cm}\n\n\\textbf{Controllability} A system is controllable, if and only if, it is possible to transfer the system state from any arbitrary initial state x(0) to the origin in finite time. initial state x(0) $\\rightarrow$ desired state: x(n)=0.%\n%\n\\textbf{Controllability condition for SI continuous systems:} $\\det C = \\det[b, \\ \\ Ab, \\ \\, \\cdots, A^{n-1}b] \\neq 0$.\n\n\\textbf{Observability} A system is observable if any initial state x(0) can be determined from a finite number of output observations. $\\det O_c = \\det \\begin{bmatrix} \nc \\\\ cA \\\\ \\vdots \\\\ cA^{n-1} \\end{bmatrix} \\neq 0$.\n\n\\textbf{Continuous State Transition Matrix:} $\\phi(t)$,\n$\\phi(t)=e^{At}= \\mathcal{L}^{-1}[(sI-A)^{-1}]$, then $\\dot{\\phi}(t)=A\\phi(t) \\quad \\phi(0)=I$, $\\dot(x)=Ax$ %\\hfill \\linebreak\n\nVerification: $x(t)=\\phi(0)x(0)=Ix(0)$ \n$\\dot{x}(t)=\\dot{\\phi}(t)x(0)=A\\phi(t)x(0)=Ax(t)$. \n\nProperties of $\\phi(t)$:\n\\vspace*{-0.4cm}\n\\begin{align*}\n& 1) \\ \\ \\phi(0)=e^{A0}=I \\\\\n& 2) \\ \\ \\phi(t) = e^{At} = (e^{(-At)})^{-1}=[\\phi(-t)]^{-1} \\\\\n& 3) \\ \\ \\phi(t_1+t_2)=\\phi(t_1)\\phi(t_2)=\\phi(t_2)\\phi(t_1) \\\\\n& 4) \\ \\ [\\phi(t)]^n = \\phi(nt) \\\\\n& 5) \\phi(t_0-t_1)\\phi(t_1-t_2)=\\phi(t_0-t_2)=\\phi(-t_1+t_0)\\phi(-t_2+t_1) \\\\\n& e^{A(t_0-t_1)}e^{A(t_1-t_2)} = e^{A(t_0-t_2)}=e^{-A(t_1-t_0)}e^{-A(t_2-t_1)}\n\\end{align*}%\n%\n\\textbf{BIBO Stability}\nOutput is bounded for any bounded input.\nCTS systems : Poles in left half plane, Discrete Systems: poles inside unit circle.\n\n\\textbf{INTERNAL ( Also asymptotic stability)}\nDef: Equilibrium state:\n Continuous systems: Assume u(t) = 0;\n $\\dot{x}_e=0=Ax_e+bu \\rightarrow x_e=0$ \\hfill \\break \n  Discrete systems: Assume u(k) = 0;\n $x_e(k+1)=0=x_e(k)+Gx_e(k) \\rightarrow x_e=0$ \\hfill \\break\n\\textbf{Def:} A system is asymptotically stable if any initial condition x(0) converges to\nthe equilibrium state $x_e=0$.\n (It is assumed $u(t) = 0,t \\leq0$  or $u(k)=0, k\\geq 0$)\n \n \\textbf{Condition for asymptotic stability}: \\hfill \\break CTS $\\Re[\\lambda_i\\{A\\}]<0$ \\hfill \\break Discrete $|\\lambda_i \n \\{G\\}|$\n, all eigenvalues in unit circle\n\n%\\newpage \n%\\begin{multicols}{3}\n\n$\\text{BIBO Stability} \\rightarrow \\text{Asymptotic Stability (AS)}$ \\hfill \\break\nBIBO Stability \\& no pole zero cancellation $\\rightarrow $ AS \\hfill \\break \n%\nEigenvalues of A are the solutions of $\\det(I\\lambda -A) = 0$, \\hfill \\break\nPoles of G(z) are the zeros of denominator poly. \n$G(z)=d+c(zI-A)^{-1}b$ where $(zI-A)^{-1}=\\frac{\\text{adj}(zI-A)}{\\text{det}(zI-A)}$\n% $A_{ij}=(-1)^{i+j} M_{ij}$, (minor $M_{ij}$, $\\det$ with deleted i and j rows/col.\n% adj A\nC: nonsingular if system controllable. If the system is controllable,\nany closed-loop poles can be obtained, %i.e any desired transient response characteristics can be obtained\n%\\begin{comment}\n%Adding a comment here, make sure to add in information about the controlleres and go home and study tommorw\n%\\end{comment}\n\n\\textbf{Feed-forward observers} State Observer: $\\tilde{X}(k+1)=G\\tilde{x}(k)+Hu(k)$\n$\\tilde{y}(k)=c \\tilde{x}(k)$, Observed state: $\\tilde{x}(k)$, Observation error: $e(k)=x(k)-\\tilde{x}(k)$, $e(k+1)=Ge(k)$, Dynamics of error depend on G \\hfill \\break \n\\textbf{Prediction (full order) observer} where the estimate $\\bar{x}(k+1)$ is obtained based on measurements of up to y(k).\n\\vspace*{-0.2cm}\n\\begin{align*}\n& \\bar{x}(k+1)=G\\bar{x}(k)+Hu(k)+k_e[y(k)-\\bar{y}(k)] \\\\\n& \\bar{x}(k+1)=[G-k_e c] \\tilde{x}(k)+Hu(k)+k_ecx(k)\n\\end{align*}\n$k_e$ for this observer can be obtained \nusing $k_e=O^{-1}\\bar{A}^{-1}(\\alpha-a)^T$, where \\hfill \\break \n$\\tilde{A}=\\begin{bmatrix}\n1   & 0 \\cdots & \\cdots & 0 \\\\\na_1 & 1 & & \\\\\n\\vdots & a_1 & . &  \\\\\n\\vdots & . & . & \\\\\na_{n-1} & a_{n-2} & \\cdots & a_1 & 1\n\\end{bmatrix}$, \\hfill \\break  lower triangular Toeplitz matrix, A square matrix that is not singular, i.e., one that has a matrix inverse.\n\\textbf{Current observer} where the estimate is obtained based on measurements\nup to $y(k+1)$.\n\\vspace*{-0.15cm}\n\\begin{align*}\n& \\tilde{x}(k+1)=G\\tilde{x}(k)+Hu(k)+K_e[y(k+1)-c\\tilde{x}(k+1)] \\\\\n& \\bar{z}(k+1)=c\\bar{x}(k+1)\n\\end{align*}\n\\vspace*{-0.15cm}\n\\textbf{ASYMPTOTIC OBSERVERS 4 CTS\nSYS} \n\\vspace*{-0.15cm}\n\\begin{align*}\n& \\dot{x}(t) = A x(t)+bu(t) \\quad x(0-)=x_0 \\\\\n& y(t) = cx(t) \\quad t > 0- \\\\\n& O x(0-) = [y(0-), \\ \\cdots \\ y^{n-1}(0-)]\n\\end{align*}\n\\textbf{Open-loop Observer}\nUse ($\\{A,B,c\\}$, $\\{u(t), t> 0\\}$, and $x_0$) $\\rightarrow \\{x(t),t>0-\\}$,\n\nEffects of disturbance $\\epsilon$:\n$\\tilde{x}_0=x_0-\\epsilon$, $|\\epsilon| \\ll |x_0|$, $\\tilde{\\dot{x}}(t)=A \\tilde{x}(t)+bu(t)$, $\\tilde{x}(0-)=\\tilde{x}_0=x_0-\\epsilon$,\n$\\dot{e}(t)=Ae(t)$, $e(0-)=\\epsilon$, A is unstable $e(t) \\rightarrow \\infty$\n\n\\textbf{Closed-loop observer:}\nOutput Error: $y(t)-\\tilde{y}(t)=y(t)-c\\tilde{x}(t)=c[x(t)-\\tilde{x}(t=ce(t)$, Observer $\\tilde{x}(t)=A \\tilde{x}(t)+bu(t)+l[y(t)-c\\tilde{x}(t)$, $\\tilde{x}(t_o)=\\tilde{x}_o$ $\\tilde{x}_o$ an estimated initial state vector $l$: feedback gain vector.\n\\textbf{Observer design:}\n$l=O^{-1}\\tilde{A}^{-1}(\\alpha-a)^T$ \\hfill \\break \n%$\\det C = \\det[H, \\ GH, \\ G^2H, \\ \\cdots, \\ G^{n-1}H] \\neq 0$, \\\\ \\hfill\n%$O_d = \\begin{bmatrix}\n%c & cG & \\vdots & cG^{n-1}\n%\\end{bmatrix}^T$\n%$\\dot{\\hat{x}}=T^{-1}AT\\hat{x} + T^{-1}Bu$, $x = T\\hat{x}$,$T=MW$, control matrix $M$, W is like $\\tilde{A}$,but with upper triangular Toeplitiz matrix. $Q = (WN\\ast)^{-1}$, N is observability matrix, and $x = Q\\hat{x}$, $\\hat{\\dot{x}}= Q^{-1}AQ\\hat{x} + Q^{-1}\tBu$,\n%\\vspace*{-0.1cm}\n\\textbf{1. Pole Placement CTS}\n\\setlength{\\abovedisplayskip}{0pt}\n\\setlength{\\belowdisplayskip}{0pt}\n\\setlength{\\abovedisplayshortskip}{0pt}\n\\setlength{\\belowdisplayshortskip}{0pt}\n%\\vspace*{-0.3cm}\n\\begin{align*}\n& \\dot{x}(t)=Ax(t)+bu(t) \\quad y(t)=cx(t) \\\\\n& a(s) = \\det(sI-A)=s^n+a-1s^{n-1}+ \\cdots + a_n\n\\end{align*}\n%\\vspace*{-0.2cm}\n \\noindent Find a feedback gain vector K so that the characteristic polynomial of the resulting closed-loop system is given by the polynomial:\n %\\vspace*{-0.2cm}\n\\begin{align*}\n& \\alpha(s) =s^n+\\alpha_1s^{n-1}+ \\cdots + \\alpha_n \\quad u(t) =hr(t)- Kx(t) \\\\\n& \\dot{x}(t) = (A-bK)x(t)+b h r(t) \\quad y=cx(t) \\\\\n& \\alpha - a = K C \\tilde{A}^T \\quad K =(\\alpha -a)\\tilde{A}^{-T} C^{-1}\n\\end{align*}\n \\vspace*{-0.2cm}\n\\includegraphics[width=\\linewidth]{poleplacementPic.png}\n %\\vspace*{-0.2cm}\n\\textbf{2. Tracking a Reference Signal}\n %\\vspace*{-0.2cm}\n\\includegraphics[width=\\linewidth]{trackingRefSig.png}\n\\textbf{Tracking}: y(t) should follow r(t) at steady state(ss)\ni.e, y(k) follows r(k) at ss. Find $h$ in $u(k)=hr(k) -Kx(k)$ for tracking. ss $x(k+1)=x(k)$\n%\\vspace*{-0.2cm}\n\\begin{align*}\n& \\dot{x}(t)=Ax+bu=x(t) \\downarrow \\\\\n& x(t)=(A-bK)x(t)+bhr(t) \\\\\n& y(t)= c(I-G+HK)^{-1}Hr(t) \\quad y(t)=r(t) \\\\\n& h = \\frac{-1}{c(A-bK)^{-1}b}\n\\end{align*}\nEstimation of unmeasurable state variables is commonly called observation. $G(s)=C(sI-A)^{-1}B$,\n $\\Delta (\\lambda)= (\\lambda^2+2\\zeta \\omega_n+ \\omega_n^2)(\\lambda + \\zeta \\omega_n)$ \\hfill \\break \nOverdamped $\\zeta > 1$, Critically Damped $\\zeta=1$, Underdamped(oscillations) $0< \\zeta < 1$\n$\\zeta = \\frac{-\\ln(\\% OS /100)}{\\sqrt{\\pi^2 + \\ln^2(\\% OS /100)}}$\n$t_{s} = \\frac {4}{\\sigma } = \\frac {4}{\\zeta \\omega _{n}}\\ \\left ( 2\\%\\ band \\right )$,\n$t_{s} = \\frac {3}{\\sigma } = \\frac {3}{\\zeta \\omega _{n}}\\ \\left ( 5\\%\\ band \\right )$,\n% break to make column\n\\columnbreak\n\\textbf{Discretization of CTS-Time State Equations:}\n\\includegraphics[width=\\linewidth]{dis2CTS.png}\n%\\vspace*{-1.1cm}\n\\begin{align*}\n&  \\dot{x}=Ax+bu \\quad G(T)=e^{AT}= \\phi(T) \\ H(T) = (\\int_0^T e^{AT} \\ dt)b\n\\end{align*}\n%\\vspace*{-0.6cm}\n\\textbf{3. Integral Error Feedback Discrete}\n%\\vspace*{-0.05cm}\n$\nx(k+1)=Gx(k)+Hu(k)+w(k) \\quad y(k)=c(k)x(k) \n$\nw(k) is unknown but constant disturbance.\n\nProblem: Design a state-feedback controller so that\n1) The CL eigenvalues are at prescribed locations.\n\n2) The output y(k) follows the reference r(k) for any w(k)\n(constant, but unknown) at steady state.\n\n$\n \\begin{bmatrix} x(k+1) \\\\ q(k+1)\\end{bmatrix} =\n\\begin{bmatrix}G & 0 \\\\ -T_c & 1\\end{bmatrix}\\begin{bmatrix}x(k) \\\\ q(k)\\end{bmatrix}+\n\\begin{bmatrix}H \\\\ 0\\end{bmatrix}u(k)+\\begin{bmatrix} 0 \\\\ T\\end{bmatrix}r(k)+\\begin{bmatrix}w(k) \\\\ 0\\end{bmatrix} \\ \\\nq(k+1)=q(k)+T(r(k)-y(k)) \n$\n\nFind $K = [K_x, K_q]$,$K=(\\alpha-a)\\tilde{A}^{-T}C^{-1}$,\n\n$ \\begin{bmatrix} x(k+1) \\\\ q(k+1)\\end{bmatrix} =\n\\begin{bmatrix}G-HK_x & -HK_q \\\\ -T_c & 1\\end{bmatrix}\\begin{bmatrix}x(k) \\\\ q(k)\\end{bmatrix}+\n\\begin{bmatrix}0 \\\\ T\\end{bmatrix}u(k)+\\begin{bmatrix} 0 \\\\ T\\end{bmatrix}r(k)+\\begin{bmatrix}w(k) \\\\ 0\\end{bmatrix}$ $u(k)=-[K_x, K_q]\\begin{bmatrix} x(k) \\\\ q(k)\n\\end{bmatrix}$ %\\hfill \\break %using a(z) as given  given characteristic polynomial, and $\\alpha(z)$ as desired ch. eqn. \\hfill \\break \n%\\begin{minipage}[h]{1\\linewidth}\n%\\textbf{Discrete} \\hfill \\break \n\n\n\\includegraphics[width=\\linewidth]{DiscreteIntegralTracking.png}\n%\\end{minipage}\n%\\begin{minipage}[h]{1\\linewidth}\n%\\textbf{Continuous}\n\\textbf{3. Integral Error Feedback CTS} \n\n$ \\begin{bmatrix} x(k+1) \\\\ q(k+1)\\end{bmatrix} =\n\\begin{bmatrix}A & 0 \\\\ -c & 1\\end{bmatrix}\\begin{bmatrix}x(k) \\\\ q(k)\\end{bmatrix}+\n\\begin{bmatrix}b \\\\ 0\\end{bmatrix}u(k)+\\begin{bmatrix} 0 \\\\ 1\\end{bmatrix}r(k)+\\begin{bmatrix}w(k) \\\\ 0\\end{bmatrix} \\ \\\nq(k)=(r(k)-y(k)) $\n\\includegraphics[width=\\linewidth]{CTSIntegralTracking.png}\n%\\end{minipage}\n\\textbf{Combined Observer-Controller}\n\nObserver feedback: $l(y(t)-c\\tilde{x}(t))$,\n\nFeedback control signal $u(t)=-K\\tilde{x}(t)+v(t)$ \\hfill \\break \nObservation error: $\\dot{e}(t)=(A-lc)e(t)$\n$\\det \\begin{bmatrix}sI-A & bK \\\\\n-lc & sI-A+lc+bK\n\\end{bmatrix} \\\\ =\\det(sI-A+bk)\\det(sI-A+lc)$\n$\\begin{bmatrix}\n\\dot{x}(t) \\\\\n\\dot{\\tilde{x}}(t)\n\\end{bmatrix}= \\begin{bmatrix}\nA  & -bK \\\\\nlc & A-lc-bK\n\\end{bmatrix}\\begin{bmatrix}\nx(t) \\\\\n{\\tilde{x}}(t)\n\\end{bmatrix}+\n\\begin{bmatrix}\nb \\\\ b\n\\end{bmatrix} v(t) \\quad \n\\begin{bmatrix}\nx(t_0) \\\\ \\tilde{x}(t_0)\n\\end{bmatrix}=\n\\begin{bmatrix}\nx_0 \\\\ \\tilde{x}_0\n\\end{bmatrix}\n$\n\\vspace{0.1 cm}\nQuad Form: $ax^2+bx+c=0 \\quad x= \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}$,\nSteady-state error is defined as the difference between the input (command) and the output of a system in the limit as time goes to infinity. $x_1(1)=x_2(0)$.\n\\includegraphics[width=\\linewidth]{fullEstimateobs.png}\n\\includegraphics[width=\\linewidth]{keFeedback.png}\n\\includegraphics[width=\\linewidth]{whyNot.png}\n\\includegraphics[width=\\linewidth]{full-state-obs.png}\n\\includegraphics[width=\\linewidth]{min-order-observer.png}\n\n\n\n\n\\subsection{Stability Test for Digital Systems}\n\n\\textbf{Jury-Marden Table Uses function P of z} \\newline\n%\\vspace*{-0.25cm}\n\\begin{align*}\n& b_k = \\det \\begin{bmatrix}\na_n & a_{n-1-k} \\\\\na_0 & a_{k+1}\n\\end{bmatrix} \\\\\n& k = 0,1,  \\cdots n-1 \\\\\n& c_k = \\det \\begin{bmatrix}\nb_{n-1} & b_{n-2-k} \\\\\nb_0 & b_{k+1}\n\\end{bmatrix} \\\\\n& k = 0,1,  \\cdots n-1 \\\\\n& q_k = \\det \\begin{bmatrix}\np_{3} & p_{2-k} \\\\\np_0 & p_{k+1}\n\\end{bmatrix} \\\\\n& k =0,1,2\n\\end{align*}\n\n\\begin{tabular}{llllllll}\n\t\\cline{1-5}\n\tRow & $z^0$     & $z^1$     & $z^2$     &          & $z^{n-2}$ & $z^{n-1}$ & $z^n$ \\\\ %\\cline{1-5}\n\t1   & $a_n$     & $a_{n-1}$ & $a_{n-2}$ & $\\cdots$ & $a_2$     & $a_1$     & $a_0$ \\\\\n\t2   & $a_0$     & $a_1$     & $a_2$     & $\\cdots$ & $a_{n-2}$ & $a_{n-1}$ & $a_n$ \\\\\n\t3   & $b_{n-1}$ & $b_{n-2}$ & $b_{n-3}$ & $\\cdots$ & $b_1$     & $b_0$     &       \\\\ %\\cline{1-5}\n\t4   & $b_0$     & $b_1$     & $b_2$     & $\\cdots$ & $b_{n-2}$ & $b_{n-1}$ &       \\\\\n\t5   & $c_{n-2}$ & $c_{n-3}$ & $c_{n-4}$ & $\\cdots$ & $c_0$     &           &       \\\\\n\t6   & $c_0$     & $c_1$     & $c_2$     & $\\cdots$ & $c_{n-2}$ &           &      \\\\\n\t2n-5& $p_3$ & $p_2$ & $p_1$ & $p_0$ & & & \\\\\n\t2n-4& $p_0$ & $p_1$ & $p_2$ & $p_3$ & & & \\\\\n\t2n-3& $q_2$ & $q_1$ & $q_0$ & & & & \n\\end{tabular}\n\n\\begin{align*}\n& P(z) = a_0z^n+a_1z^{n-1} + \\cdots + a_{n-1}z+a_n \\quad G(z)= \\frac{A(z)}{P(z)} \\\\\n& \\text{Stability Condition:} \\quad P(z) \\neq 0 \\quad |z| \\geq 1 \\quad (\\text{Draw Unit Circle to test stability})\\\\\n& \\text{Routh-Stability in Digital Domain: } s = \\frac{z+1}{z-1} \\quad z=\\frac{s+1}{s-1}\n\\end{align*}\n\n\n\\begin{align*}\n& G(z) = \\mathcal{Z} \\left\\{\\left(\\frac{1-e^{-s}}{s}\\right) \\left[ \\frac{1}{s+1}\\right] \\left[\\frac{1}{s}\\right] \\right\\} \\rightarrow G_1(z) = (1-z^{-1})\\mathcal{Z} \\left\\{ \\frac{1}{s^2(s+1)} \\right\\}\n\\end{align*}\n\nAll first-column elements of the Routh array are to be of the same sign. $a_0s^n + a_1s^{n-1}+ \\cdots + a{n-1} s + a_n = 0$, first row is even entries $a_0$, $a_2$, next row is $a_1$, $a_2$, b entries are the same are jury-marden table.\n\n\n\\subsection{Z-transform}\n\n\n\n\\begin{tabular}{c c}\n\t$\\mathcal{Z} \\left\\{ f_1(t) \\pm f_2(t) \\right\\}=F_1(z)+F_2(z)$ & Addition\\\\\n\t$\\mathcal{Z} \\left\\{ af(t) \\right\\}= aF(z)$ & Multiplication by a Constant \\\\\n\t$\\mathcal{Z} \\left\\{ f(t-nT) \\right\\}=z^{-n}F(z)$ & Shifting \\\\\n\t$\\mathcal{Z} \\left\\{ f(t+kT) \\right\\}=z^{k}F(z)-z^{k}f(0)- \\cdots - z f(kT-T)$ & Shifting (cont'd) \\\\\n\t$\\mathcal{Z} \\left\\{ e^{\\mp at} f(t) \\right\\}=F(ze^{\\pm at})$ & Complex Translation \\\\\n\t$\\lim_{k \\rightarrow \\infty} f(kT)= \\lim_{z \\rightarrow 0}F(z)$ & Initial Value Theorem \\\\ \n\tIf $(1-z^{-1})F(z)$ has all singularities inside unit disk $|z|=1$, then & Final Value Theorem \\\\\n\t$\\lim_{k \\rightarrow \\infty} f(kT) = \\lim_{z \\rightarrow 1} (1-z^{-1})F(z)$ & \\\\\n\t$\\mathcal{Z} \\left\\{ \\frac{\\partial}{\\partial a} f(t,a) \\right\\} = \\frac{\\partial}{\\partial a} F(z,a)$ & Partial differentiation\n\\end{tabular}\n\n", "meta": {"hexsha": "bc61acdf187836dffa804536dca006cfd2e007ff", "size": 23674, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "public/CheatSheets/elec460FormFinal.tex", "max_stars_repo_name": "FriendlyUser/PortfolioWebsite", "max_stars_repo_head_hexsha": "82843816c07239c457d2d820bb50577333a75855", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/CheatSheets/elec460FormFinal.tex", "max_issues_repo_name": "FriendlyUser/PortfolioWebsite", "max_issues_repo_head_hexsha": "82843816c07239c457d2d820bb50577333a75855", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/CheatSheets/elec460FormFinal.tex", "max_forks_repo_name": "FriendlyUser/PortfolioWebsite", "max_forks_repo_head_hexsha": "82843816c07239c457d2d820bb50577333a75855", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.3655913978, "max_line_length": 267, "alphanum_fraction": 0.5949564924, "num_tokens": 9976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.8633916134888614, "lm_q1q2_score": 0.7018228251001457}}
{"text": "\\section{Review of Polar Coordinates}\r\n\\noindent\r\nPolar coordinates represent every point in 2D space as a distance from the origin $r$ and an angle from the horizontal $\\theta$. This means that unlike rectangular (Cartesian) $(x,y)$ coordinates, different polar coordinates can represent the same point: $(2, -\\pi/4) = (-2, 3\\pi/4)=(2, 7\\pi/4)$.\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nPolar coordinates can be transformed into rectangular coordinates by $x = r\\cos{\\theta}$ and $ y =r\\sin{\\theta}$. This means that $r = \\sqrt{x^2+y^2}$ and $\\theta = \\tan^{-1}{\\frac{y}{x}}$.\r\n\r\n\\input{./curvilinearCoordinates/circles_polar}\r\n\\input{./curvilinearCoordinates/lines_polar}\r\n\\input{./curvilinearCoordinates/integration_polar}", "meta": {"hexsha": "d875ac21e2a655f54c1e0f9196269f5ed5d2242b", "size": 716, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/curvilinearCoordinates/reviewPolarCoordinates.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/curvilinearCoordinates/reviewPolarCoordinates.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/curvilinearCoordinates/reviewPolarCoordinates.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 59.6666666667, "max_line_length": 297, "alphanum_fraction": 0.7248603352, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.7017366209451126}}
{"text": "% !TEX root = ./busty_transcription.tex\n\\section{Bayesian inference}\n\\label{sec:bayesian}\n\n\\subsection{The problem of parameter inference}\n\nOne could argue that the whole goal of formulating theoretical models about\nnature is to sharpen our understanding from qualitative statements to precise\nquantitative assertions about the relevant features of the natural phenomena in\nquestion \\cite{Gunawardena2014}. It is in these models that we intend to distill\nthe essential parts of the object of study. Writing down such models leads to a\npropagation of mathematical variables that parametrize our models. By assigning\nnumerical values to these parameters we can compute concrete predictions that\ncan be contrasted with experimental data. For these predictions to match the\ndata the parameter values have to carefully be chosen from the whole parameter\nspace. But how do we go about assessing the effectiveness of different regions\nof parameter space to speak to the ability of our model to reproduce the\nexperimental observations? The language of probability, and more specifically of\nBayesian statistics is --we think-- the natural language to tackle this\nquestion.\n\n\\subsubsection{Bayes' theorem}\n\nBayes' theorem is a simple mathematical statement that can apply to \\textit{any}\nlogical conjecture. For two particular events $A$ and $B$ that potentially \ndepend on each other Bayes' theorem gives us a recipe for how to update our \nbeliefs about one, let us say $B$, given some state of knowledge, or lack thereof, about\n$A$. In its most classic form Bayes' theorem is written as\n\\begin{equation}\nP(B \\mid A) = {P(A \\mid B) P(B) \\over P(A)},\n\\end{equation}\nwhere the vertical line $\\mid$ is read as ``given that''. So $P(B \\mid A)$ is\nread as probability of $B$ given that $A$ took place. $A$ and $B$ can be any\nlogical assertion. In particular the problem of Bayesian inference focuses on\nthe question of finding the probability distribution of a particular parameter\nvalue given the data.\n\nFor a given model with a set of parameters $\\vec{\\theta} = (\\theta_1, \\theta_2,\n\\ldots, \\theta_n)$, the so-called \\textit{posterior distribution} \n$P(\\vec{\\theta} \\mid D)$, where $D$ is the experimental data, quantifies the\nplausibility of a set of parameter values given our observation of some\nparticular dataset. In other words, through the application of Bayes' formula we\nupdate our beliefs on the possible values that parameters can take upon learning\nthe outcome of a particular experiment. We specify the word ``update'' as we\ncome to every inference problem with prior information about the plausibility of\nparticular regions of parameter space even before performing any experiment.\nEven when we claim as researchers that we are totally ignorant about the values\nthat the parameters in our models can take, we always come to a problem with\ndomain expertise that can be exploited. If this was not the case, it is likely\nthat the formulation of our model is not going to capture the phenomena we claim\nto want to understand. This prior information is captured in the \\textit{prior\nprobability} $P(\\vec{\\theta})$. The relationship between how parameter values\ncan connect with the data is enconded in the \\textit{likelihood function} $P(D\n\\mid \\vec{\\theta})$. Our theoretical model, whether deterministic or\nprobabilistic, is encoded in this term that can be intuitively understood as the\nprobability of having observed the particular experimental data we have at hand\ngiven that our model is parametrized with the concrete values $\\vec{\\theta}$. \nImplicitly here we are also conditioning on the fact that our theoretical model\nis ``true,'' i.e. the model itself if evaluated or simulated in the computer is\ncapable of generating equivalent datasets to the one we got to observe in an \nexperiment. In this way Bayesian inference consists of applying Bayes' formula \nas \n\\begin{equation}\nP(\\vec{\\theta} \\mid D) \\propto P(D \\mid \\vec{\\theta}) P(\\vec{\\theta}).\n\\end{equation}\nNotice than rather than writing the full form of Bayes' theorem, we limit \nourselves to the terms that depend on our quantity of interest --that is the \nparameter values themselves $\\vec{\\theta}$-- as the denominator $P(D)$ only\nserves as a normalization constant.\n\nWe also emphasize that the dichotomy we have presented between prior and\nlikelihood is more subtle. Although it is often stated that our prior\nknowledge is entirely encapsulated by the obviously named prior\nprobability $P(\\vec{\\theta})$, this is usually too simplistic.\nThe form(s) we choose for our likelihood function\n$P(D \\mid \\vec{\\theta})$ also draw heavily on our prior domain expertise\nand the assumptions, implicit and explicit, that these choices encode are\nat least as important, and often inseparable from,\nthe prior probability, as persuasively argued in~\\cite{Gelman2017}.\n\n\\subsubsection{The likelihood function}\n\nAs we alluded in the previous section it is through the likelihood function \n$P(D \\mid \\vec{\\theta})$ that we encode the connection between our parameter \nvalues and the experimental observables. Broadly speaking there are two classes\nof models that we might need to encode into our likelihood function:\n\\begin{itemize}\n        \\item Deterministic models: Models for which a concrete selection of\n        parameter values give a single output. Said differently, models \n        with a one-to-one mapping between inputs and outputs.\n        \\item Probabilistic models: As the name suggests, models that, rather than\n        having a one-to-one input-output mapping, describe the full\n        probability distribution of possible outputs.\n\\end{itemize}\nIn this paper we focus on inference done with probabilistic models. After all,\nthe chemical master equations we wrote down describe the time evolutions of the\nmRNA probability distribution. So all our terms $P(\\vec{\\theta} \\mid D)$ will be\ngiven by the steady-state solution of the corresponding chemical master equation\nin question. This is rather convenient as we do not have to worry about adding a\nstatistical model on top of our model to describe deviations from the\npredictions. Instead our models themselves focus on predicting such variation\nin cell count.\n\n\\subsubsection{Prior selection}\nThe different models explored in this work embraced different levels of\ncoarse-graining that resulted in a diverse number of parameters for different\nmodels. For each of these model configurations Bayes' theorem demands from us to\nrepresent our preconceptions on the possible parameter values in the form of the\nprior $P(\\vec{\\theta})$. Throughout this work for models with $> 1$ parameter we\nassign independent priors to each of the parameters; this is\n\\begin{equation}\nP(\\vec{\\theta}) = \\prod_{i=1}^n P(\\theta_i).\n\\end{equation}\nAlthough it is not uncommon practice to use non-informative, or maximally\nuninformative priors, we are of the mindset that this is a disservice to the\nphilosophical and practical implications of Bayes' theorem. It sounds almost\ncontradictory to claim that can we represent our thinking about a natural\nphenomenon in the form of a mathematical model --in the context of Bayesian\ninference this means choosing a form for the likelihoods, and even making\nthis choice presupposes prior understanding or assumptions as to the\nrelevant features in the system under study-- but that we have absolutely\nno idea what the parameter values could or could not be. We therefore make\nuse of our own expertise, many times in the form of order-of-magnitude\nestimates, to write down weakly-informative prior distributions\nfor our parameters.\n\nFor our particular case all of the datasets from~\\cite{Jones2014} used in this\npaper have $\\mathcal{O}(10^3)$ data points. What this implies is that our\nparticular choice of priors will not significantly affect our inference as long\nas they are broad enough. A way to see why this is the case is to simply look at\nBayes' theorem. For $N ~ 1000-3000$ datum all of the independent of each other\nand $n \\ll 10^3$ parameters Bayes' theorem reads as\n\\begin{equation}\nP(\\vec{\\theta} \\mid D) \\propto \\prod_{k=1}^{N} P(d_k \\mid \\vec{\\theta})\n\\prod_{i=1}^n P(\\theta_i),\n\\end{equation}\nwhere $d_k$ represents the $k$-th datum. That means that if our priors span a\nwide range of parameter space, the posterior distribution would be dominated by\nthe likelihood function.\n\n\\subsubsection{Expectations and marginalizations}\nFor models with more than one or two parameters, it is generally difficult\nto visualize or reason about the full joint posterior distribution\n$P(\\vec{\\theta} \\mid D)$ directly.\nOne of the great powers of Bayesian analysis is \\textit{marginalization},\nallowing us to reduce the dimensionality to only the parameters of\nimmediate interest by averaging over the other dimensions.\nFormally, for a three dimensional model with parameters\n$\\theta_1$, $\\theta_2$, and $\\theta_3$, we can for instance\nmarginalize away $\\theta_3$ to produce a 2D posterior as\n\\begin{equation}\nP(\\theta_1, \\theta_2 \\mid D) \\propto\n        \\int_{\\theta_3} d\\theta_3 \\,P(\\theta_1, \\theta_2, \\theta_3 \\mid D),\n\\end{equation}\nor we can marginalize away $\\theta_1$ and $\\theta_3$ to produce the\n1D marginal posterior of $\\theta_2$ alone, which would be\n\\begin{equation}\nP(\\theta_2 \\mid D) \\propto\n        \\int_{\\theta_1} d\\theta_1 \\int_{\\theta_3} d\\theta_3\n        \\,P(\\theta_1, \\theta_2, \\theta_3 \\mid D).\n\\end{equation}\nConceptually, this is what we did in generating the 2D slices of the\nfull 9D model in Figure~\\ref{fig4:repressed_post_full}(A).\nIn practice, this marginalization is even easier with Markov Chain Monte Carlo\nsamples in hand. Since each point is simply a list of parameter values,\nwe simply ignore the parameters which we want to marginalize\naway~\\cite{Gelman2013}.\n        \n\\subsubsection{Markov Chain Monte Carlo}\nThe theory and practice of Bayesian inference with Markov Chain Monte Carlo\n(MCMC) is a rich subject with fascinating and deep analogies to statistical\nmechanics, even drawing on classical Hamiltonian mechanics and general\nrelativity in its modern incarnations. We refer the interested reader\nto~\\cite{Gelman2013} and~\\cite{Betancourt2018} for excellent introductions.\nHere we merely give a brief summary of\nthe MCMC computations carried out in this work.\n\nWe used the Python package \\texttt{emcee} for most of the MCMC sampling\nin this work. For the constitutive promoter inference, we also ran\nsampling with the excellent Stan modeling language as a check. We did not\nuse Stan for the inference of the simple repression model because\nimplementing the gradients of the hypergeometric function ${_2F_1}$\nappearing in Eq.~\\ref{eq:p_m_bursty+rep_appdx}, the probability\ndistribution for our bursty model with repression, would have been\nan immensely challenging task. \\texttt{emcee} was more than adequate for\nour purposes, and we were perhaps lucky that the 9-D posterior model\nfor the model of simple repression with bursty promoter was quite well\nbehaved and did not require the extra power of the Hamiltonian Monte\nCarlo algorithm provided by Stan~\\cite{Carpenter2017}.\nSource code for all statistical inference will be made available at\n\\url{https://github.com/RPGroup-PBoC/bursty_transcription}.\n\n\\subsection{Bayesian inference on constitutive promoters}\n\\label{sec:si_bayes_unreg}\n\nHaving introduced the ideas behind Bayesian inference we are ready to apply the\ntheoretical machinery to our non-equilibrium models. In particular in this\nsection we will focus on model 1 and model 5 in\nFigure~\\ref{fig2:constit_cartoons}(A). Model 1, the Poisson promoter, will help\nus build practical intuition into the implementation of the Bayesian inference\npipeline. As we noted in Section~\\ref{sec:beyond_means} of the main text, this\nmodel cannot be reconciled with experimental data from observables such as the\nFano factor. In other words, we acknowledge that this model is ``wrong,'' but we\nstill see value in going through the analysis since the simple nature of the\nmodel translates into a neat statistical analysis.\n\n\\subsubsection{Model 1 - Poisson promoter}\n\nModel 1 in Figure~\\ref{fig2:constit_cartoons}(A) predicts a  mRNA distribution\nwhose steady-state solution is given by a Poisson distribution with parameter\n$\\lambda \\equiv r / \\gamma$, where $r$ is the mRNA production rate, and $\\gamma$\nis the mRNA degradation rate~\\cite{Sanchez2013}. The goal of our inference\nproblem is then to find the probability distribution for the parameter value\n$\\lambda$ given the experimental data. By Bayes' theorem this can be written as\n\\begin{equation}\np(\\lambda \\mid D) = {p(D \\mid \\lambda) p(\\lambda) \\over p(D)},\n\\end{equation}\nwhere $D = \\{m_1, m_2, \\ldots, m_N \\}$ are the single-cell mRNA experimental\ncounts. As is standard we will neglect the denominator $p(D)$ on the right\nhand side since it is independent of $\\lambda$ and serves only as a\nnormalization factor.\n\nThe steady-state solution for the master equation defines the likelihood term\nfor a single cell $p(m \\mid \\lambda)$. What this means is that for a given\nchoice of parameter $\\lambda$, under model 1 of\nFigure~\\ref{fig2:constit_cartoons}(A), we expect to observe $m$ mRNAs in a\nsingle cell with probability\n\\begin{equation}\np(m\\mid\\lambda) = \\frac{\\lambda^m e^{-\\lambda}}{m!}.\n\\label{eq:poisson_inference010}\n\\end{equation}\nAssuming each cell's mRNA count in our dataset is independent of others, the\nlikelihood of the full inference problem $p(D\\mid\\lambda)$ is simply a product\nof the single cell likelihoods given by Eq.~\\ref{eq:poisson_inference010} above, so\n\\begin{equation}\np(D\\mid\\lambda) = \\prod_{k=1}^N \\frac{\\lambda^{m_k}e^{-\\lambda}}{m_k!}.\n\\end{equation}\n\nThroughout this Appendix we will appeal to the convenient notation for\nprobability distributions of the form\n\\begin{equation}\nm \\sim \\text{Poisson}(\\lambda),\n\\end{equation}\nwhere the symbol ``$\\sim$'' can be read as \\textit{is distributed according to}.\nSo the previous equation can be read as: the mRNA copy number $m$ is distributed\naccording to a Poisson distribution with parameter $\\lambda$. Our objective then\nis to compute the posterior probability distribution $P(\\lambda \\mid D)$, where,\nas in the main text, $D = \\{ m_1, m_2, \\ldots, m_N \\}$ are the data consisting\nof single-cell mRNA counts. Since we can assume that each of the cells mRNA\ncounts are independent of any other cells, our likelihood function $P(D \\mid\n\\lambda)$ consists of the product of $N$ Poisson distributions.\n\nTo proceed with the inference problem we need to specify a prior. In this case\nwe are extremely data-rich, as the dataset from Jones et.\\ al~\\cite{Jones2014}\nhas of order 1000-3000 single-cell measurements for each promoter, so our choice\nof prior matters little here, as long as it is sufficiently broad. A convenient\nchoice for our problem is to use a \\textit{conjugate} prior. A conjugate prior\nis a special prior that causes the posterior to have the same functional form as\nthe prior, simply with updated model parameters. This makes calculations\nanalytically tractable and also offers a nice interpretation of the inference\nprocedure as updating our knowledge about the model parameters. This makes\nconjugate priors very useful when they exist. The caveat is that conjugate\npriors only exist for a very limited number of likelihoods, mostly with only one\nor two model parameters, so in almost all other Bayesian inference problems, we\nmust tackle the posterior numerically.\n\nBut, for the problem at hand, a conjugate prior does in fact exist. For a\nPoisson likelihood of identical and identically distributed data, the conjugate\nprior is a gamma distribution, as can be looked up in, e.g.,~\\cite{Gelman2013},\nSection 2.6. Putting a gamma prior on $\\lambda$ introduces two new parameters\n$\\alpha$ and $\\beta$ which parametrize the gamma distribution itself, which we\nuse to encode the range of $\\lambda$ values we view as reasonable. Recall\n$\\lambda$ is the mean steady-state mRNA count per cell, which \\textit{a priori}\ncould plausibly be anywhere from 0 to a few hundred. $\\alpha=1$ and $\\beta=1/50$\nachieve this, since the gamma distribution is strictly positive with mean\n$\\alpha/\\beta$ and standard deviation $\\sqrt{\\alpha}/\\beta$. To be explicit,\nthen, our prior is\n\\begin{equation}\n\\lambda \\sim \\text{Gamma}(\\alpha, \\beta)\n\\end{equation}\n\nAs an aside, note that if we did not know that our prior was a conjugate prior,\nwe could still write down our posterior distribution from its definition as\n\\begin{equation}\np(\\lambda\\mid D,\\alpha,\\beta)\n\\propto p(D\\mid\\lambda) p(\\lambda \\mid\\alpha,\\beta)\n\\propto \\left(\\prod_{k=1}^N \\frac{\\lambda^{m_k}e^{-\\lambda}}{m_k!}\\right)\n        \\frac{\\beta}{\\Gamma(\\alpha)}(\\beta\\lambda)^{\\alpha-1} e^{-\\beta\\lambda}\n.\n\\end{equation}\nWithout foreknowledge that this in fact reduces to a gamma distribution, this\nexpression might appear rather inscrutable. When conjugate priors are\nunavailable for the likelihood of interest - which is almost always the case for\nmodels with $>1$ model parameter - this inscrutability is the norm, and making\nsense of posteriors analytically is almost always impossible. Fortunately, MCMC\nsampling provides us a powerful method of constructing posteriors numerically\nwhich we will make use of extensively.\n\nSince we did use a conjugate prior, we may simply look up our posterior in any\nstandard reference such as~\\cite{Gelman2013}, Section 2.6,\nfrom which we find that\n\\begin{equation}\n\\lambda\n\\sim \\text{Gamma}\\left(\\alpha + \\bar{m}N, \\beta + N\\right),\n\\end{equation}\nwhere we defined the sample mean $\\bar{m} = \\frac{1}{N}\\sum_k m_k$ for\nnotational convenience. A glance at the FISH data from~\\cite{Jones2014} reveals\nthat $N$ is $\\mathcal{O}(10^3)$ and $\\langle m\\rangle \\gtrsim 0.1$ for all\nconstitutive strains in~\\cite{Jones2014}, so $\\bar{m}N \\gtrsim 10^2$. Therefore\nas we suspected, our prior parameters are completely overwhelmed by the data.\nThe prior behaves, in a sense, like $\\beta$ extra ``data points''\nwith a mean value of $(\\alpha-1)/\\beta$~\\cite{Gelman2013}, which\ngives us some intuition for how much data is needed to overwhelm\nthe prior in this case: enough data $N$ such that $\\beta\\ll N$\nand $\\alpha/\\beta \\ll \\bar{m}$. In\nfact, $\\bar{m}N$ and $N$ are so large that we can, to an excellent\napproximation, ignore the $\\alpha$ and $\\beta$ dependence and approximate the\ngamma distribution as a Gaussian with mean $\\bar{m}$ and standard deviation\n$\\sqrt{\\bar{m}/N}$, giving\n\\begin{equation}\n\\lambda\n\\sim \\text{Gamma}\\left(\\alpha + \\bar{m}N, \\beta + N\\right)\n\\approx \\text{Normal}\\left(\\bar{m}, \\sqrt{\\frac{\\bar{m}}{N}}\\right).\n\\end{equation}\nAs an example with real numbers, for the \\textit{lacUV5} promoter, Jones et.\\\nal~\\cite{Jones2014} measured 2648 cells with an average mRNA count per cell of\n$\\bar{m} \\approx 18.7$. In this case then, our posterior is\n\\begin{equation}\n\\lambda\n\\sim \\text{Normal}\\left(18.7, 0.08\\right),\n\\label{eq:gauss_posterior}\n\\end{equation}\nwhich suggests we have inferred our model's one parameter to a precision of\norder 1\\%.\n\nThis is not wrong, but it is not the full story. The model's posterior\ndistribution is tightly constrained, but is it a good generative model? In other\nwords, if we use the model to generate synthetic data in the computer does it\ngenerate data that look similar to our actual data, and is it therefore\nplausible that the model captures the important features of the data generating\nprocess? This intuitive notion can be codified with \\textit{posterior predictive\nchecks}, or PPCs, and we will see that this simple Poisson model fails badly.\n\nThe intuitive idea of posterior predictive checks is simple: \n\\begin{enumerate}\n\\item Make a random draw of the model parameter $\\lambda$ from the posterior\ndistribution.\n\\item Plug that draw into the likelihood and generate a synthetic dataset\n$\\{m_k\\}$ conditioned on $\\lambda$.\n\\item Repeat many times.\n\\end{enumerate}\nMore formally, the posterior predictive distribution can be thought of as the\ndistribution of future yet-to-be-observed data, conditioned on the data we have\nalready observed. Clearly if those data appear quite different, the model has a\nproblem. Put another way, if we suppose the generative model is true, i.e. we\nclaim that our model explains the process through which our observed\nexperimental data was generated, then the synthetic datasets we generate should\nresemble the actual observed data. If this is not the case, it suggests the\nmodel is missing important features. All the data we consider in this work are\n1D (distributions of mRNA counts over a population) so empirical cumulative\ndistribution functions ECDFs are an excellent visual means of comparing\nsynthetic and observed datasets. In general for higher dimensional datasets,\nmuch of the challenge is in merely designing good visualizations that can\nactually show if synthetic and observed data are similar or not.\n\nFor our example Poisson promoter model then, we merely draw many random numbers,\nsay 1000, from the Gaussian posterior in Eq.~\\ref{eq:gauss_posterior}. For each\none of those draws, we generate a dataset from the likelihood, i.e., we draw\n2648 (the number of observed cells in the actual dataset) Poisson-distributed\nnumbers for each of the 1000 posterior draws, for a total of 2648000 samples\nfrom the posterior predictive distribution.\n\nTo compare so many samples with the actual observed data, one excellent\nvisualization for 1D data is ECDFs of the quantiles, as shown for our Poisson\nmodel in~\\fig{fig:constit_post_full}(B) in the main text. \n\n\\subsubsection{Model 5 - Bursty promoter}\n\nLet us now consider the problem of parameter inference from FISH data for model\nfive from~\\fig{fig1:means_cartoons}(C). As derived in\nAppendix~\\ref{sec:gen_fcn_appdx}, the steady-state mRNA distribution in this\nmodel is a negative binomial distribution, given by\n\\begin{equation}\np(m) = \\frac{\\Gamma(m+k_i)}{\\Gamma(m+1)\\Gamma(k_i)}\n        \\left(\\frac{1}{1+b}\\right)^{k_i}\n        \\left(\\frac{b}{1+b}\\right)^m,\n\\label{eq:si_neg_bionom}\n\\end{equation}\nwhere $b$ is the mean burst size and $k_i$ is the burst rate nondimensionalized\nby the mRNA degradation rate $\\gamma$. As sketched earlier, we can intuitively\nthink about this distribution through a simple story. The story of this\ndistribution is that the promoter undergoes geometrically-distributed bursts of\nmRNA, where the arrival of bursts is a Poisson process with rate $k_i$ and the\nmean size of a burst is $b$.\n\nAs for the Poisson promoter model, this expression for the steady-state mRNA\ndistribution is exactly the likelihood we want to use in Bayes' theorem. Again\ndenoting the single-cell mRNA count data as $D=\\{m_1, m_2,\\dots, m_N\\}$, here\nBayes' theorem takes the form\n\\begin{equation}\np(k_i, b \\mid D) \\propto p(D\\mid k_i,b)p(k_i, b),\n\\end{equation}\nwhere the likelihood $p(D\\mid k_i,b)$ is given by the product of $N$ negative\nbinomials as in Eq.~\\ref{eq:si_neg_bionom}. We only need to choose priors on\n$k_i$ and $b$. For the datasets from~\\cite{Jones2014} that we are analyzing, as\nfor the Poisson promoter model above we are still data-rich so the prior's\ninfluence remains weak, but not nearly as weak because the dimensionality of our\nmodel has increased from one to two.\n\nWe follow the guidance of~\\cite{Gelman2013}, Section 2.9 in opting for\nweakly-informative priors on $k_i$ and $b$ (conjugate priors do not exist for\nthis problem), and we find ``street-fighting estimates''~\\cite{Mahajan2010} to\nbe an ideal way of constructing such priors. The idea of weakly informative\npriors is to allow all remotely plausible values of model parameters while\nexcluding the completely absurd or unphysical.\n\nConsider $k_i$. Some of the strongest known bacterial promoters control rRNA\ngenes and initiate transcripts no faster than $\\sim 1/\\text{sec}$. It would be\nexceedingly strange if any of the constitutive promoters from~\\cite{Jones2014}\nwere stronger than that, so we can take that as an upper bound. For a lower\nbound, if transcripts are produced too rarely, there would be nothing to see\nwith FISH. The datasets for each strain contain of order $10^3$ cells, and if\nthe $\\langle m \\rangle = k_i b/\\gamma \\lesssim 10^{-2}$, then the total number\nof expected mRNA detections would be single-digits or less and we would have\nessentially no data on which to carry out inference. So assuming $b$ is not too\ndifferent from 1, justified next, and an mRNA lifetime of $\\gamma^{-1}\\sim\n3-5~\\text{min}$, this gives us soft bounds on $k_i/\\gamma$ of perhaps $10^{-2}$\nand $3\\times 10^1$.\n\nNext consider mean burst size $b$. This parametrization of the geometric\ndistribution allows bursts of size zero (which could representing aborted\ntranscripts and initiations), but it would be quite strange for the mean burst\nsize $b$ to be below $\\sim10^{-1}$, for which nearly all bursts would be of size\nzero or one. For an upper bound, if transcripts are initiating at a rate\nsomewhat slower than rRNA promoters, then it would probably take a time\ncomparable to the lifetime of an mRNA to produce a burst larger than 10-20\ntranscripts, which would invalidate the approximation of the model that the\nduration of bursts are instantaneous compared to other timescales in the\nproblem. So we will take soft bounds of $10^{-1}$ and $10^1$ for $b$.\n\nNote that the natural scale for these ``street-fighting estimates'' was a log\nscale. This is commonly the case that our prior sense of reasonable and\nunreasonable parameters is set on a log scale. A natural way to enforce these\nsoft bounds is therefore to use a lognormal prior distribution, with the soft\nbounds set $\\pm2$ standard deviations from the mean.\n\nWith this, we are ready to write our full generative model as\n\\begin{equation}\n\\begin{split}\n\\ln k_i \\sim \\text{Normal}(-0.5, 2),\n\\\\\n\\ln b \\sim \\text{Normal}(0.5, 1),\n\\\\\nm \\sim \\text{NBinom}(k_i, b).\n\\end{split}\n\\end{equation}\nSection~\\ref{section_04_bayesian_inference} in the main text details the\nresults of applying this inference to the single-cell mRNA counts data. There\nwe show the posterior distribution for the two parameters for different \npromoters. Figure~\\ref{figS:ppc_unreg} shows the so-called posterior predictive\nchecks (see main text for explanation) for all 18 unregulated promoters shown\nin the main text.\n\n\\begin{figure}[p]\n\\centering\n\\includegraphics{../../figures/si/figS0X_ppc.pdf}\n\\caption{\\textbf{Theory-data comparison of inference on unregulated promoters.}\nComparison of the inference (red shaded area) vs the experimental measurements\n(black lines) for 18 different unregulated promoters with different mean mRNA\nexpression levels from Ref.~\\cite{Jones2014}. Upper panels show the empirical\ncumulative distribution function (ECDF), while the lower panels show the\ndifferences with respect to the median of the posterior samples. White numbers\nare the same as in Figure~\\ref{fig1:means_cartoons} for cross comparison. The\npredicted binding energies $\\beta\\Delta\\varepsilon_p$ were obtained from the\nenergy matrix model in Ref.~\\cite{Brewster2012}}\n\\label{figS:ppc_unreg}\n\\end{figure}\n\n\\subsection{Bayesian inference on the simple-repression architecture}\n\nAs detailed in~\\ref{section_04_bayesian_inference} in the main text the\ninference on the unregulated promoter served as a stepping stone towards our\nultimate goal of inferring repressor rates from the steady-state mRNA\ndistributions of simple-repression architectures. For this we expand the\none-state bursty promoter model to a two-state promoter as schematized in\nFigure~\\ref{fig1:means_cartoons}(C) as model 5. This model adds two new\nparameters: the repressor binding rate $k^+$, solely function of the repressor\nconcentration, and the repressor dissociation rate $k^-$, solely a function of\nthe repressor-DNA binding affinity.\n\nThe structure of the data in~\\cite{Jones2014} for regulated promoters tuned\nthese two parameters independently. In their work the production of the LacI\nrepressor was under the control of an inducible promoter regulated by the TetR\nrepressor as schematized in Figure~\\ref{figS:aTc_circuit}. When TetR binds to the\nsmall molecule anhydrotetracycline (aTc), it shifts to an inactive conformation\nunable to bind to the DNA. This translates into an increase in gene expression\nlevel. In other words, the higher the concentration of aTc added to the media,\nthe less TetR repressors that can control the expression of the \\textit{lacI}\ngene, so the higher the concentration of LacI repressors in the cell. So by \ntuning the amount of aTc in the media where the experimental strains were grown\nthey effectively tune $k^+$ in our simple theoretical model. On the other hand\nto tune $k^-$ the authors swap three different binding sites for the LacI \nrepressor, each with different repressor-DNA binding affinities previously \ncharacterized \\cite{Garcia2011a}.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics{../../figures/si/figS0X_aTc_circuit.pdf}\n\\caption{\\textbf{aTc controlled expression of LacI repressor.} Schematic of the\ncircuit used in~\\cite{Jones2014} to control the expression of the LacI\nrepressor. The \\textit{lacI} gene is under the control of the TetR repressor. As\nthe TetR repressor is inactivated upon binding of anhydrotetracycline or aTc,\nthe more aTc added to the media were cells are growing, the less TetR repressors\navailable to control the expression of the \\textit{lacI} gene, resulting in more\nLacI repressors per cell. LacI simultaneously controls the expression of the\nmRNA on which single-molecule mRNA FISH was performed for gene expression\nquantification.}\n\\label{figS:aTc_circuit}\n\\end{figure}\n\nWhat this means is that we have access to data with different combinations of\n$k^-$ and $k^+$. We could naively try to fit the kinetic parameters individually\nfor each of the datasets, but there is no reason to believe that the binding\nsite identity for the LacI repressor somehow affects its expression level\ncontrolled from a completely different location in the genome, nor vice versa.\nIn other words, what makes the most sense it to fit all datasets together to\nobtain a single value for each of the association and dissociation rates. What\nthis means, as described in Section~\\ref{section_04_bayesian_inference} of the main text\nis that we have a seven dimensional parameter space with four possible\nassociation rates $k^+$ given the four available aTc concentrations, and three\npossible dissociation rates $k^-$ given the three different binding sites\navailable in the dataset.\n\nFormally now, denote the set of seven repressor rates to be inferred as\n\\begin{equation}\n\\vect{k} =\\{k_{Oid}^-, k_{O1}^-, k_{O2}^-,\nk_{0.5}^+, k_{1}^+, k_{2}^+, k_{10}^+\\}.\n\\end{equation}\nNote that since the repressor copy numbers are not known directly as explained\nbefore, we label their association rates by the concentration of aTc. Bayes\ntheorem reads simply\n\\begin{equation}\np(\\vect{k}, k_i, b \\mid D)\n\\propto\np(D \\mid\\vect{k}, k_i, b) p(\\vect{k}, k_i, b),\n\\end{equation}\nwhere $D$ is the set of all $N$ observed single-cell mRNA counts across the\nvarious conditions. We assume that individual single-cell measurements are\nindependent so that the likelihood factorizes as\n\\begin{equation}\np(D \\mid\\vect{k}, k_i, b)\n= \\prod_{j=1}^N p(m\\mid \\vect{k}, k_i, b)\n= \\prod_{j=1}^N p(m\\mid k_j^+, k_j^-, k_i, b)\n\\end{equation}\nwhere $k_j^\\pm$ represent the appropriate binding and unbinding rates for the\n$j$-th measured cell. Our likelihood function, previously derived in\nAppendix~\\ref{sec:gen_fcn_appdx}, is given by the rather complicated result in\nEq.~\\ref{eq:p_m_bursty+rep_appdx}, which for completeness we reproduce here as\n\\begin{equation}\n\\begin{split}\np(m \\mid k_R^+, k_R^-, k_i, b) = & ~\\frac{\n        \\Gamma(\\alpha + m)\\Gamma(\\beta + m)\\Gamma(k_R^+ + k_R^-)\n        }\n        {\n        \\Gamma(\\alpha)\\Gamma(\\beta)\\Gamma(k_R^+ + k_R^- + m)\n        }\n\\frac{b^m}{m!}\n\\\\\n&\\times {_2F_1}(\\alpha+m, \\beta+m, k_R^++k_R^-+m; -b).\n\\end{split}\n\\label{eq:p_m_bursty+rep_infreprint}\n\\end{equation}\nwhere $\\alpha$ and $\\beta$, defined for notational convenience, are\n\\begin{equation}\n\\begin{split}\n\\alpha &= \\frac{1}{2}\n\\left(k_i+k_R^-+k_R^+ + \\sqrt{(k_i+k_R^-+k_R^+)^2 - 4k_i k_R^-}\\right)\n\\\\\n\\beta &= \\frac{1}{2}\n\\left(k_i+k_R^-+k_R^+ - \\sqrt{(k_i+k_R^-+k_R^+)^2 - 4k_i k_R^-}\\right).\n\\end{split}\n\\end{equation}\n\nNext we specify priors. As for the constitutive model, weakly informative\nlognormal priors are a natural choice for all our rates. We found that if the\npriors were too weak, our MCMC sampler would often become stuck in regions of\nparameter space with very low probability density, unable to move. We struck a\nbalance in choosing our prior widths between helping the sampler run while\nsimultaneously verifying that the marginal posteriors for each parameter were\nnot artificially constrained or distorted by the presence of the prior. The only\nexception to this is the highly informative priors we placed on $k_i$ and $b$,\nsince we have strong knowledge of them from our inference of constitutive\npromoters above.\n\nWith priors and likelihood specified we may write down our complete generative model as\n\\begin{equation}\n\\begin{split}\n\\log_{10}k_i &\\sim \\text{Normal}(0.725, 0.025)\\\\\n\\log_{10}b   &\\sim \\text{Normal}(0.55, 0.025)\\\\\n\\log_{10}k_{0.5}^+ &\\sim \\text{Normal}(-0.45, 0.3)\\\\\n\\log_{10}k_{1}^+   &\\sim \\text{Normal}(0.6, 0.3)\\\\\n\\log_{10}k_{2}^+   &\\sim \\text{Normal}(1.15, 0.3)\\\\\n\\log_{10}k_{10}^+  &\\sim \\text{Normal}(1.5, 0.3)\\\\\n\\log_{10}k_{Oid}^- &\\sim \\text{Normal}(-0.25, 0.3)\\\\\n\\log_{10}k_{O1}^-  &\\sim \\text{Normal}(0.1, 0.3)\\\\\n\\log_{10}k_{O2}^-  &\\sim \\text{Normal}(0.45, 0.3)\\\\\nm &\\sim \\text{Likelihood}(k_R^+, k_R^-, k_i, b),\n\\end{split}\n\\end{equation}\nwhere the likelihood is specified by Eq.~\\ref{eq:p_m_bursty+rep_infreprint}.\nWe ran MCMC sampling on the full nine dimensional posterior specified\nby this generative model.\n\nWe found that fitting a single operator/aTc concentration at a time with a\nsingle binding and unbinding rate did not yield a stable inference for most of\nthe possible operator/aTc combinations. In other words, a single dataset could\nnot independently resolve the binding and unbinding rates, only their ratio as\nset by the mean fold-change in Figure~\\ref{fig1:means_cartoons} in the main\ntext. Only by making the assumption of a single unique binding rate for each\nrepressor copy number and a single unique unbinding rate for each binding site,\nas done in Figure~\\ref{fig4:repressed_post_full}(A), was it possible to\nindependently resolve the rates and not merely their ratios.\n\nWe also note that we found it necessary to exclude the very weakly and very\nstrongly repressed datasets from Jones et.\\ al.~\\cite{Jones2014}. In both cases\nthere was, in a sense, not enough information in the distributions for our\ninference algorithm to extract, and their inclusion simply caused problems for\nthe MCMC sampler without yielding any new insight. For the strongly repressed\ndata (Oid, 10~ng/mL aTc), with $>$ 95\\% of cells with zero mRNA, there was quite\nliterally very little data from which to infer rates. And the weakly repressed\ndata, all with the repressor binding site O3, had an unbinding rate so fast that\nthe sampler essentially sampled from the prior; the likelihood had negligible\ninfluence, meaning the data was not informing the sampler in any meaningful way,\nso no inference was possible.\n\nAs suggested by one of our reviewers, in order for readers to judge the\nagreement between our predictions and the experimental data for the regulated\ncase, we include Figure~\\ref{figS:reg_histograms} that plot the same data as\nFigure~\\ref{fig4:repressed_post_full}(C), but rather than showing ECDF, we show\nhistograms of the individual distributions.\n\n\\begin{figure}[p]\n\\centering\n\\includegraphics[width=\\textwidth]{../../figures/si/figS0X_histograms.pdf}\n\\caption{\\textbf{Theory-experiment comparison of mRNA distributions for\nregulated promoters.} Comparison of the inference (color shaded area\nencloses the 95\\% of all posterior predictive check samples while the color\nsolid line represents the median of all samples) vs the experimental\nmeasurements (black lines) for different regulated promoters with different\noperators (columns) and aTc concentrations (rows) from\nRef.~\\cite{Jones2014}.}\n\\label{figS:reg_histograms}\n\\end{figure}", "meta": {"hexsha": "b3f88d094c8a385a27c30626e1c4c9fc066681a1", "size": 36180, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/resubmission/appendix_03_bayesian_inference.tex", "max_stars_repo_name": "RPGroup-PBoC/bursty_transcription", "max_stars_repo_head_hexsha": "cd3082c567168dfad12c08621976ea49d6706f89", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/resubmission/appendix_03_bayesian_inference.tex", "max_issues_repo_name": "RPGroup-PBoC/bursty_transcription", "max_issues_repo_head_hexsha": "cd3082c567168dfad12c08621976ea49d6706f89", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/resubmission/appendix_03_bayesian_inference.tex", "max_forks_repo_name": "RPGroup-PBoC/bursty_transcription", "max_forks_repo_head_hexsha": "cd3082c567168dfad12c08621976ea49d6706f89", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.4058192956, "max_line_length": 88, "alphanum_fraction": 0.77631288, "num_tokens": 9393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436167620237, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.7017366192759655}}
{"text": "\\subsection{Method Selection}\r\n\r\nBefore establishing models for prediction, we have to choose what algorithms to use in analyses.\r\n\r\nBesides common considerations, what we especially take into account is the global topology of the attribute space: because of the attributes WDF2 and WDF5, the space is in fact homeomorphic to $\\mathbb R^{p-2}\\times \\mathbb S^1\\times\\mathbb S^1$ instead of $\\mathbb R^p$. In this case, a hyperplane (or, more generally, an \\emph{open} hypersurface) may not be able to seperate it into two \\emph{disconnected} subspace.\r\n\r\nAs the result, we exclude LDA, QDA and several other well-developed classification methods because an open hypersurface is always needed for these. Instead, we tend to apply methods that do not heavily depend on global topology (random forest, $k$-NN) or that classify with a \\emph{closed} hypersurface (kernel SVM).", "meta": {"hexsha": "c060cc853948f37a468ac40e6cc6651d4852d850", "size": 871, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/topo.tex", "max_stars_repo_name": "shengchenHAO/Weather-Forecast-", "max_stars_repo_head_hexsha": "0c81dd5b8b3c4572464b0e0b841ca279ecb0d650", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Report/topo.tex", "max_issues_repo_name": "shengchenHAO/Weather-Forecast-", "max_issues_repo_head_hexsha": "0c81dd5b8b3c4572464b0e0b841ca279ecb0d650", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/topo.tex", "max_forks_repo_name": "shengchenHAO/Weather-Forecast-", "max_forks_repo_head_hexsha": "0c81dd5b8b3c4572464b0e0b841ca279ecb0d650", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 124.4285714286, "max_line_length": 419, "alphanum_fraction": 0.7818599311, "num_tokens": 210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.7017366174447097}}
{"text": "\\section{The Mean Value Theorem}\\label{sec:MVT}\r\nThere are numerous applications of the\r\nderivative through its \\textbf{definition} as rate of change and as the\r\nslope of the tangent line. In this section\r\nwe shall look at some deeper reasons why the derivative turns out to be so\r\nuseful. The simple answer is that \\textbf{the derivative of a function tells\r\nus a lot about the function}. More\r\nimportant, ``hard'' questions about a\r\nfunction can sometimes be answered by solving a relatively simple problem\r\nabout the derivative of the function.\r\n\r\n$$\\includegraphics[width=11cm]{images/mvt-intro-diagram-1}$$\r\n\r\nThe Mean Value Theore tells us that\r\nthere is an intimate connection between the net change of the value of any\r\n``sufficiently nice'' function over an\r\ninterval and the possible values of its derivative on that interval. Because\r\nof this connection, we can draw conclusions about the possible values of the\r\nderivative based on information about the values of the function, and\r\nconversely, we can draw conclusions about the values of the function based\r\non information about the values of its derivative.\r\n\r\n$$\\includegraphics[width=11cm]{images/mvt-intro-diagram-2}$$\r\n\r\nLet us illustrate the idea through the following two interesting questions\r\ninvolving derivatives:\r\n\r\n\\begin{enumerate}\r\n\t\\item Suppose two different functions have the same derivative;\r\n\t\t  what can you say about the relationship between the two functions?\r\n\t\\item Suppose you drive a car from toll booth on a toll road to\r\n\t\t  another toll booth at an average speed of 70 miles per hour. \r\n\t\t  What can be concluded about your actual speed during the trip? \r\n\t\t  In particular, did you exceed the 65 mile per hour speed limit?\r\n\\end{enumerate}\r\n\r\nWhile these sound very different, it turns out that the two problems\r\nare very closely related. We know that ``speed'' is really the\r\nderivative by a different name; let's start by translating the second\r\nquestion into something that may be easier to visualize. Suppose that\r\nthe function $f(t)$ gives the position of your car on the toll road at\r\ntime $t$. Your change in position between one toll booth and the next\r\nis given by $\\ds f(t_1)-f(t_0)$, assuming that at time $\\ds t_0$ you were at\r\nthe first booth and at time $\\ds t_1$ you arrived at the second\r\nbooth. Your average speed for the trip is\r\n$\\ds (f(t_1)-f(t_0))/(t_1-t_0)$. If we think about the graph of $f(t)$,\r\nthe average speed is the slope of the line that connects the two\r\npoints $\\ds (t_0,f(t_0))$ and $\\ds (t_1,f(t_1))$. Your speed at any particular time\r\n$t$ between $\\ds t_0$ and $\\ds t_1$ is $f'(t)$, the slope of the curve. Now\r\nquestion (2) becomes a question about slope. In particular, if the\r\nslope between endpoints is 70, what can be said of the slopes at\r\npoints between the endpoints?\r\n\r\nAs a general rule, when faced with a new problem it is often a good idea to\r\nexamine one or more simplified versions of the problem, in the hope\r\nthat this will lead to an understanding of the original problem.\r\nIn this case, the problem in its ``slope'' form is somewhat easier to\r\nsimplify than the original, but equivalent, problem.\r\n \r\nHere is a special instance of the problem. Suppose that\r\n$\\ds f(t_0)=f(t_1)$. Then the two endpoints have the same height and the\r\nslope of the line connecting the endpoints is zero. What can we say\r\nabout the slope between the endpoints? It shouldn't take much\r\nexperimentation before you are convinced of the truth of this\r\nstatement: Somewhere between $\\ds t_0$ and $\\ds t_1$ the slope is exactly\r\nzero, that is, somewhere between $\\ds t_0$ and $\\ds t_1$ the slope is equal to\r\nthe slope of the line between the endpoints. This suggests that\r\nperhaps the same is true even if the endpoints are at different\r\nheights, and again a bit of experimentation will probably convince you\r\nthat this is so. But we can do better than ``experimentation''---we\r\ncan prove that this is so.\r\n\r\nWe start with the simplified version:\r\n\r\n\\begin{theorem}{Rolle's Theorem}{rolle}\r\n(Rolle's Theorem) Suppose that $f(x)$ has a derivative on the\r\ninterval $(a,b)$, is continuous on the interval $[a,b]$, and\r\n$f(a)=f(b)$. Then at some value $c\\in (a,b)$, $f'(c)=0$.\r\n\\end{theorem}\r\n\r\n\\begin{proof}\r\nWe know that $f(x)$ has a maximum and minimum value on $[a,b]$\r\n(because it is continuous), and we\r\nalso know that the maximum and minimum must occur at an endpoint, at a\r\npoint at which the derivative is zero, or at a point where the\r\nderivative is undefined. Since the derivative is never undefined, that\r\npossibility is removed.\r\n\r\nIf the maximum or minimum occurs at a point $c$, other than an endpoint,\r\nwhere $f'(c)=0$, then we have found the point we seek. Otherwise, the\r\nmaximum and minimum both occur at an endpoint, and since the endpoints\r\nhave the same height, the maximum and minimum are the same. This means\r\nthat $f(x)=f(a)=f(b)$ at every $x \\in [a,b]$, so the function is a\r\nhorizontal line, and it has derivative zero everywhere in\r\n$(a,b)$. Then we may choose any $c$ at all to get $f'(c)=0$.\r\n\\end{proof}\r\n\r\nRolle's Theorem is illustrated below for a function $f(x)$ where $f'(x)=0$ holds for two values of $x=c_1$ and $x=c_2$:\r\n$$\\includegraphics[width=4in]{images/rolle}$$\r\n\r\nPerhaps remarkably, this special case is all we need to prove the more\r\ngeneral one as well.\r\n\r\n\\begin{theorem}{Mean Value Theorem}{mvt} \r\nSuppose that $f(x)$ has a derivative on the\r\ninterval $(a,b)$ and is continuous on the interval $[a,b]$. \r\nThen at some value $c\\in (a,b)$, $\\ds f'(c)={f(b)-f(a)\\over b-a}$.\r\n\\end{theorem}\r\n\r\n\\begin{proof}\r\nLet $\\ds m={f(b)-f(a)\\over b-a}$, and consider a new function\r\n$g(x)=f(x) - m(x-a)-f(a)$. We know that $g(x)$ has a derivative\r\neverywhere, since $g'(x)=f'(x)-m$. We can compute \r\n$g(a)=f(a)- m(a-a)-f(a) =0$ and\r\n\\begin{eqnarray*}\r\ng(b)=f(b)-m(b-a)-f(a)&=f(b)-{f(b)-f(a)\\over b-a}(b-a)-f(a)\\cr\r\n&=f(b)-(f(b)-f(a))-f(a)=0.\\cr\r\n\\end{eqnarray*}\r\nSo the height of $g(x)$ is the same at both endpoints. This means, by\r\nRolle's Theorem, that at some $c$, $g'(c)=0$. But we know that\r\n$g'(c)=f'(c)-m$, so\r\n$$0=f'(c)-m=f'(c)-{f(b)-f(a)\\over b-a},$$\r\nwhich turns into\r\n$$f'(c)={f(b)-f(a)\\over b-a},$$\r\nexactly what we want.\r\n\\end{proof}\r\n\r\nThe Mean Value Theorem is illustrated below showing the existence of a point $x=c$ for a function $f(x)$ where the tangent line at $x=c$ (with slope $f'(c)$) is parallel to the secant line connecting $A(a,f(a))$ and $B(b,f(b))$ (with slope ${f(b)-f(a)\\over b-a}$):\r\n$$\\includegraphics[width=2.0in]{images/mvt}$$\r\n\r\nReturning to the original formulation of question (2), we see that if\r\n$f(t)$ gives the position of your car at time $t$, then the Mean Value\r\nTheorem says that at some time $c$, $f'(c)=70$, that is, at some time\r\nyou must have been traveling at exactly your average speed for the\r\ntrip, and that indeed you exceeded the speed limit.\r\n\r\nNow let's return to question (1). Suppose, for example, that two\r\nfunctions are known to have derivative equal to 5 everywhere,\r\n$f'(x)=g'(x)=5$. It is easy to find such functions: $5x$, $5x+47$,\r\n$5x-132$, etc. Are there other, more complicated, examples? No---the\r\nonly functions that work are the ``obvious'' ones, namely, $5x$ plus\r\nsome constant. How can we see that this is true?\r\n\r\nAlthough ``5'' is a very simple derivative, let's look at an even\r\nsimpler one. Suppose that $f'(x)=g'(x)=0$. Again we can find examples:\r\n$f(x)=0$, $f(x)=47$, $f(x)=-511$ all have $f'(x)=0$. Are there\r\nnon-constant functions $f$ with derivative 0? No, and here's why:\r\nSuppose that $f(x)$ is not a constant function. This means that there\r\nare two points on the function with different heights, say\r\n$f(a)\\not=f(b)$. The Mean Value Theorem tells us that at some point\r\n$c$, $f'(c)=(f(b)-f(a))/(b-a)\\not=0$. So any non-constant function\r\ndoes not have a derivative that is zero everywhere; this is the same\r\nas saying that the only functions with zero derivative are the\r\nconstant functions.\r\n\r\nLet's go back to the slightly less easy example: suppose that \r\n$f'(x)=g'(x)=5$. Then $(f(x)-g(x))' = f'(x)-g'(x) = 5 -5 =0$. So using\r\nwhat we discovered in the previous paragraph, we know that\r\n$f(x)-g(x)=k$, for some constant $k$. So any two functions with\r\nderivative 5 must differ by a constant; since $5x$ is known to work,\r\nthe only other examples must look like $5x+k$.\r\n\r\nNow we can extend this to more complicated functions, without any\r\nextra work. Suppose that $f'(x)=g'(x)$. Then as before\r\n$(f(x)-g(x))' = f'(x)-g'(x) =0$, so $f(x)-g(x)=k$. Again this means\r\nthat if we find just a single function $g(x)$ with a certain\r\nderivative, then every other function with the same derivative must be\r\nof the form $g(x)+k$.\r\n\r\n\\begin{example}{Given Derivative}{givenderivative}\r\nDescribe all functions that have derivative $5x-3$. \r\n\\end{example}\r\n\r\n\\begin{solution} \r\nIt's easy to find\r\none: $\\ds g(x)=(5/2)x^2-3x$ has $g'(x)=5x-3$. The only other functions\r\nwith the same derivative are therefore of the form\r\n$\\ds f(x)=(5/2)x^2-3x+k$.\r\n\r\nAlternately, though not obviously, you might have first noticed that \r\n$\\ds g(x)=(5/2)x^2-3x+47$ has $g'(x)=5x-3$. Then every other function\r\nwith the same derivative must have the form $\\ds f(x)=(5/2)x^2-3x+47+k$.\r\nThis looks different, but it really isn't. The functions of the form\r\n$\\ds f(x)=(5/2)x^2-3x+k$ are exactly the same as the ones of the form\r\n$\\ds f(x)=(5/2)x^2-3x+47+k$. For example, $\\ds (5/2)x^2-3x+10$ is the same as\r\n$\\ds (5/2)x^2-3x+47+(-37)$, and the first is of the first form while\r\nthe second has the second form.\r\n\\end{solution}\r\n\r\nThis is worth calling a theorem:\r\n\r\n\\begin{theorem}{Functions with the Same Derivative}{FunctionsSameDerivative}\r\nIf $f'(x)=g'(x)$ for every $x\\in (a,b)$, then for some constant\r\n$k$, $f(x)=g(x)+k$ on the interval $(a,b)$.\r\n\\end{theorem} \r\n\r\n\\begin{example}{Same Derivative}{SameDerivative}\r\nDescribe all functions with derivative $\\ds \\sin x + e^x$. One such\r\nfunction is $\\ds -\\cos x+e^x$, so all such functions have the form\r\n$-\\cos x+e^x+k$.\r\n\\end{example}\r\n\r\nTheorem~\\ref{thm:FunctionsSameDerivative} and the above example illustrate what the Mean\r\nValue Theorem allows us to say about $f(x)$ when we have\r\nperfect information about $f^{\\prime}(x)$. Specifically, $f(x)$\r\nis determined up to a constant. Our next example\r\nillustrates almost the opposite extreme situation, one where we have much\r\nless information about $f^{\\prime}(x)$ beyond the fact that $f^{\\prime}(x)$\r\nexists. Specifically, assuming that we know an\r\nupper bound on the values of $f^{\\prime}(x)$, what can we say\r\nabout the values of $f(x)$?\r\n\r\n\\begin{example}{Conclusion Regarding Function Value Based on Derivative Information}{FuncValDerivativeInfo}\r\nSuppose that $f$ is a differentiable function such that $f^{\\prime }\\left(\r\nx\\right) \\leq 2$ for all $x.$ What is the largest possible value of $f\\left(\r\n7\\right) $ if $f\\left( 3\\right) =5?$\r\n\\end{example}\r\n\\begin{solution}\r\nWe are interested in the values of $f\\left( x\\right) $ at $x=3$\r\nand $x=7.$ It makes sense to focus our attention on the interval between 3\r\nand 7. It is given that $f\\left( x\\right) $ is differentiable for all $x.$\r\nSo, $f\\left( x\\right) $ is also continuous at all $x.$ In particular, $%\r\nf\\left( x\\right) $ is continuous on the interval $\\left[ 3,7\\right] $ and\r\ndifferentiable on the interval $\\left( 3,7\\right) .$ By the Mean Value\r\nTheorem, we know that there is some $c$ in $\\left( 3,7\\right) $ such that \r\n\\begin{equation*}\r\nf^{\\prime }\\left( c\\right) =\\frac{f\\left( 7\\right) -f\\left( 3\\right) }{7-3}.\r\n\\end{equation*}%\r\nSimplifying and using the given information $f\\left( 3\\right) =5$, we get \r\n\\begin{equation*}\r\nf^{\\prime }\\left( c\\right) =\\frac{f\\left( 7\\right) -5}{4},\r\n\\end{equation*}%\r\nor, after re-arranging the terms,%\r\n\\begin{equation*}\r\nf\\left( 7\\right) =4f^{\\prime }\\left( c\\right) +5.\r\n\\end{equation*}%\r\nWe do not know the exact value of $c,$ but we do know that $f^{\\prime\r\n}\\left( x\\right) \\leq 2$ for all $x.$ This implies that $f^{\\prime }\\left(\r\nc\\right) \\leq 2.$ Therefore,%\r\n\\begin{equation*}\r\nf\\left( 7\\right) \\leq 4\\cdot 2+5=13.\r\n\\end{equation*}%\r\nThat is, the value of $f\\left( 7\\right) $ cannot exceed 13. To convince\r\nourselves that 13 (as opposed to some smaller number) is the largest\r\npossible value of $f\\left( 7\\right) ,$ we still need to show that it is\r\npossible for the value of $f\\left( 7\\right) $ to reach 13. If we review our\r\nproof, we notice that the inequality will be an equality if $f^{\\prime\r\n}\\left( c\\right) =2.$ One way to guarantee this without knowing anything\r\nabout $c$ is to require $f^{\\prime }\\left( x\\right) =2$ for all $x.$ This\r\nmeans that $f\\left( x\\right) =2x+k$ for some constant $k.$ From the\r\ncondition $f\\left( 3\\right) =5,$ we see that $k=-1.$ We can easily verify\r\nthat indeed $f\\left( x\\right) =2x-1$ meets all our requirements and $f\\left(\r\n7\\right) =13$.\r\n\\end{solution}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:MVT}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Let $\\ds f(x) = x^2$.\r\nFind a value $c\\in (-1,2)$ so that $f'(c)$ equals the slope between\r\nthe endpoints of $f(x)$ on $[-1,2]$.\r\n\\begin{sol}\r\n $c=1/2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Verify that $f(x) = x/(x+2)$ satisfies the hypotheses of the\r\n Mean Value Theorem on the interval $[1,4]$ and then find all of the\r\n values, $c$, that satisfy the conclusion of the theorem.\r\n\\begin{sol}\r\n $\\ds c=\\sqrt{18}-2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nVerify that $f(x) = 3x/(x+7)$ satisfies the hypotheses of the\r\n Mean Value Theorem on the interval $[-2 , 6]$ and then find all of the\r\n values, $c$, that satisfy the conclusion of the theorem.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Let $f(x) = \\tan x $. Show that $f(\\pi ) = f(2\\pi)=0$ but\r\nthere is no number $c\\in (\\pi,2\\pi)$ such that $f'(c) =0$. Why does\r\nthis not contradict Rolle's theorem?\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Let $\\ds f(x) = (x-3)^{-2}$.  Show that there is no value \r\n$c\\in (1,4)$ such that $f'(c) = (f(4)-f(1))/(4-1)$.  Why is\r\nthis not a contradiction of the Mean Value Theorem?\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Describe all functions with derivative $\\ds x^2+47x-5$.\r\n\\begin{sol}\r\n $\\ds x^3/3+47x^2/2-5x+k$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Describe all functions with derivative $\\ds {1\\over 1+x^2}$.\r\n\\begin{sol}\r\n $\\arctan x + k$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Describe all functions with derivative $\\ds x^3-{1\\over x}$.\r\n\\begin{sol}\r\n $\\ds x^4/4 -\\ln x +k$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Describe all functions with derivative $\\sin(2x)$.\r\n\\begin{sol}\r\n $-\\cos(2x)/2 +k$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nFind $f\\left( x\\right) $ if $f^{\\prime }\\left( x\\right) =e^{-x}$ and $%\r\nf\\left( 0\\right) =2$.\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nSuppose that $f$ is a differentiable function such that $f^{\\prime }\\left(\r\nx\\right) \\geq -3$ for all $x.$ What is the smallest possible value of $%\r\nf\\left( 4\\right) $ if $f\\left( -1\\right) =2$?\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Show that the equation $\\ds 6x^4 -7x+1 =0$ does not have more\r\nthan two distinct real roots.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Let $f$ be differentiable on $\\R$. Suppose that $f'(x) \\neq\r\n0$ for every $x$. Prove that $f$ has at most one real root.\r\n\\end{ex}\r\n \r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Prove that for all real $x$ and $y$\r\n$|\\cos x -\\cos y | \\leq |x-y|$.\r\nState and prove an analogous result involving sine.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nShow that $\\ds \\sqrt{1+x} \\le 1 +(x/2)$ if $-1<x<1$.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nSuppose that $f(a)=g(a)$\r\nand that $f^{\\prime}(x)\\leq g^{\\prime}(x)$ for\r\nall $x\\geq a$.\r\n\\begin{enumerate}\r\n\t\\item\tProve that $f(x)\\leq g(x)$ for all $x\\geq a$.\r\n\t\\item\tUse part (a) to prove that $e^x\\geq 1+x$ for all $x\\geq\t0$.\r\n\t\\item\tUse parts (a) and (b) to prove that $e^x\\geq 1+x+\\dfrac{x^2}{2}$ for all $x\\geq 0$.\r\n\t\\item\tCan you generalize these results?\r\n\\end{enumerate}\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}\r\n", "meta": {"hexsha": "71c7a42f784ba6342900dbe46db7019da7c9a780", "size": 16030, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-3-mean-value-theorem.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5-applications-of-derivatives/5-3-mean-value-theorem.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5-applications-of-derivatives/5-3-mean-value-theorem.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.6363636364, "max_line_length": 265, "alphanum_fraction": 0.676481597, "num_tokens": 4951, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396211, "lm_q2_score": 0.8791467722591728, "lm_q1q2_score": 0.7017233293097377}}
{"text": "% ***********************************************************************************\r\n% Pure LaTeX part to be inserted in a document (be careful of depencies of packages & commands)\r\n% Prepared by XXX and YYY under the supervision of Arnaud de La Fortelle\r\n% Fall 2017\r\n% 1D heat diffusion subsection of the simulation part\r\n% ***********************************************************************************\r\n\r\n\\subgroup{1}{Lin Yang and Bradley Cage}\r\n\r\n\\paragraph{Model presentation}\r\n\r\n\\begin{figure}[htb]\r\n\t\\centering\r\n\t\\includegraphics[width=8cm]{Figures/Heat1D_model.png}       \r\n\t\\caption{The heated rod system, with the temperature at any point given by $T(x,t)$ }\r\n\t\\label{Heat1D_model.fig}\r\n\\end{figure}\r\n\r\nOur system is comprised of a rod fixed to a heated wall kept at constant temperature. The length of the rod is arbitrarily taken as 1m. The initial temperature of the rod is in equilibrium with the ambient temperature at 25$^{\\circ} $C and the temperature of the wall is 200$^{\\circ} $C.  We represent temperature at a point on the rod at some time with the function $T(x,t)$. Note that the rod is thin with respect to its length, thus is modeled as a 1D system, that is, temperature is solely a function of rod position and time. The goal of this simulation is to show the variations in temperature of various points on the rod over time. \r\n\r\nWe take our initial state as:\r\n\\begin{itemize}\r\n\t\\item $T(0,t)=200 ^{\\circ}$C\r\n    \\item $T(x,t)=25 ^{\\circ}$C, $x\\ne 0$\r\n\\end{itemize}\r\n\r\n\\noindent The partial differential equation of the 1D heat propagation:\r\n\\begin{equation}\r\n \\frac{\\partial T}{\\partial t} = \\alpha \\frac{\\partial^2 T}{\\partial x^2}\r\n\\end{equation}\r\n\\noindent We explicitly state that $u(\\cdot)$ is a function of $x$ and $t$\r\n\\begin{equation}\r\n \\frac{\\partial} {\\partial t}T(x,t) = \\alpha \\frac{\\partial^2}{\\partial x^2}T(x,t)\r\n\\end{equation}\r\n\\noindent We use a finite difference approximation to get compute the derivatives in space and time\r\n\\begin{equation}\r\n\\frac{T_{i}^{N+1}-T_{i}^{N}}{\\Delta t} =\\alpha\\frac{T_{i+1}^{N}-2T_{i}^{N}+T_{i-1}^{N}}{\\Delta x^2}\r\n\\end{equation}\r\n\r\n\\noindent Rearranging we reach the final form we need for our Forward Euler approximation. Note that the quantity $\\alpha\\frac{\\Delta t}{\\Delta x^2}$ is Fourier's number, with $\\alpha$ being the thermal diffusivity of a material. In the following simulations, we arbitrarily choose Aluminium with $\\alpha = 9.7e-5$.\r\n\r\n\\begin{equation}\r\nT_{i}^{N+1}=T_{i}^{N}+\\alpha\\frac{\\Delta t}{\\Delta x^2}\\big[ {T_{i+1}^{N}-2T_{i}^{N}+T_{i-1}^{N}}\\big]\r\n\\end{equation}\r\n\r\n\\paragraph{Implementation}\r\nWe provide an implementation in Matlab. \r\n\r\n\\begin{lstlisting}[language=Matlab, caption=Forward Euler and Plotting in MATLAB]\r\n\r\n  % Values arbitrarily chosen. It's a useful exercise to vary these and look at the results\r\n  T_final = 300;\r\n  N_t = 2000;\r\n  X_final = 1;\r\n  N_x = 100;\r\n  \r\n  % Calculate time and x steps based on sampling size and # of samples\r\n  T = linspace(0, T_final, N_t+1);\r\n  X = linspace(0, X_final, N_x+1);\r\n  dt = T(2) - T(1);  % Calculate delta t\r\n  dx = X(2) - X(1);  % Calculate delta x\r\n\r\n  alpha = 9.7e-5; % Thermal diffusivity of Aluminium in m^2/s\r\n  Fo = (alpha*dt)/(dx^2); % Fouriers number = diffusive transport rate/storage rate\r\n \r\n  % Define your initial condition here. This could be some function IC(x),\r\n  %  however for simplicity's sake we take a rod with a uniform temperature\r\n  %  and in contact with a hot plate at one end\r\n  wall_temp = 200;\r\n  init_temp = 25;\r\n  \r\n  % Initialize the N state and the N-1 state\r\n  u_old = zeros(1, N_x+1); \r\n  u_old(:) = init_temp;\r\n  u_old(1) = wall_temp;\r\n  u_cur = u_old;\r\n  u_plot = u_old;\r\n\r\n  for t = 1:N_t\r\n     for i = 2:N_x\r\n     \t % Forward Euler solution to heat equation\r\n         u_cur(i) = Fo*(u_old(i+1) - 2*u_old(i) + u_old(i-1)) + u_old(i);\r\n     end\r\n     u_cur(1) = wall_temp; % Set the left boundary to be our high of 200 \r\n     u_old(:) = u_cur; % We move to the next time step, reset N-1 state\r\n     u_plot = [u_plot; u_cur];\r\n  end\r\n\r\n  [X_plot,T_plot] = meshgrid(X,T); % Create 2D meshgrid to create surface plot\r\n\r\n  surf(X_plot,T_plot,u_plot,'EdgeColor','none') % Create surface plot\r\n  c = colorbar; % Attach colour bar and create scale\r\n  c.Label.String = 'Temperature [C]';\r\n\r\n  xlim([0 1]) % Add axis limits\r\n  xlabel('Distance along rod [m]'); % Add descriptive axis labels\r\n  ylabel('Time [s]');\r\n  zlabel('Temperature [C]')\r\n\r\n\\end{lstlisting}\r\n\r\n\r\n \\paragraph{Results}\r\n\\noindent We can create plots of the rods temperature as a function of time and position. This gives us insight into how the system evolves as we maintain our constant temperature. \r\n\\begin{figure}[htb]\r\n\t\\centering\r\n\t\\includegraphics[width=10cm]{Figures/Heat1D_1m.png}       \r\n\t\\caption{Temperature variation for the whole rod over 300 seconds}\r\n\t\\label{Heat1D_1m.fig}\r\n\\end{figure}\r\n\r\n\\begin{figure}[htb]\r\n\r\n\t\\centering\r\n\t\\includegraphics[width=9cm]{Figures/Heat1D_0_3m.png}       \r\n\t\\caption{Temperature variation for the rod segment with x varies from 0 to 0.3m over 300 seconds}\r\n\t\\label{Heat1D_0_3m.fig}\r\n\\end{figure}\r\n\\clearpage\r\n\\begin{figure}[!htb]\r\n\t\\centering\r\n\t\\includegraphics[width=9cm]{Figures/Heat1DTop.png}       \r\n\t\\caption{Top view of the temperature variation for the whole rod over 300 seconds}\r\n\t\\label{fig:Heat1D_top}\r\n\\end{figure}\r\n \r\n\\paragraph{Interpretation}\r\nThe results we obtain are consistent with our model and the physical characteristics. We can see that from the visualization the temperature varies in a logarithmic manner, which is \r\nconsitent with the fact that the Forward Euler scheme approximates the exact mathematical solution to the 2nd order PDE, which takes the form of an exponential. The exact rate at which heat moves through the rod is \r\ndependent on the thermal conductivity of the material, which makes up part of the exponent (i.e. $e^{-m}$), thus governing the rate. \r\nWe can see pathlines of the heat front evolve over time, especially when looking \r\nat the system from above. Given enough time, the rod will reach a steady state, which in this example would have the rod rest at a completely uniform temperature, since we have not incorporated any form of heat losses or sinks in the system.\r\n\r\n \\paragraph{Conclusion}\r\nHere we have learned that in examining systems such as the heated rod, we can safely analyze it as a 1D system. We were able to discretize the partial differential equations and \r\napply a forward Euler simluation to yield phyiscally relevant and meaningful simulations. Through the Matlab visualization, we gain a better understanding of how heat is moving \r\nthrough the rod and the system. From the resources and analysis provided, it is trivial to create other initial/boundary conditions and repeat the simulations to garner a deeper\r\ninsight into the heat behaviour. This is left as an exercise to the reader. \r\n \r\n", "meta": {"hexsha": "a6806f0b263bf1019dbd7a2caca9af335c93393c", "size": 6885, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "simulation-1Dheat.tex", "max_stars_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_stars_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-08T02:54:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-29T06:19:28.000Z", "max_issues_repo_path": "simulation-1Dheat.tex", "max_issues_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_issues_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "simulation-1Dheat.tex", "max_forks_repo_name": "QinganZhao/Course-Support-for-CE-291F-Control-and-Optimization-of-Distributed-Parameters-Systems", "max_forks_repo_head_hexsha": "3bbe532eab793efa6c3a3a4569d155dd39c0102c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-16T17:29:03.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-16T17:29:03.000Z", "avg_line_length": 49.1785714286, "max_line_length": 641, "alphanum_fraction": 0.6970225127, "num_tokens": 1884, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741041, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7017066696401739}}
{"text": "Our final goal is to define complex computational structures through the use of our inference system. The most complex computational structures known to us are programming languages, and as such we will set the mark there: we intend to define the syntax and semantics of a (small) programming language through a series of inference rules. Before we can dive into that, we need the ability to represent some basic algorithms which will prove of fundamental usefulness to defining a programming language. After all, our programming language will have memory of some sort, and as such we need to represent memory somehow.\n\nThe first, and perhaps most basic data structure that we can define is the \\textit{list}. A list is used to represent a sequence of values which may contain any number of elements: from no elements (the special \\textit{empty list}) to hundreds of thousands of elements.\n\n\\subsection{Lists of integers}\nFor our example, we will limit ourselves to lists of integers. It will be possible to extend this definition thanks to the use of inheritance (a list of \\texttt{Expr}) or with generic datatypes (which will be explored in a later section), but for now we shall keep things simple.\n\nA list is defined very much like Peano numbers or binary digits. We have a ``termination symbol'' \\texttt{nil}, which defines an empty list of integers:\n\n\\begin{lstlisting}\nData [] \"nil\" [] Priority 0 Type ListInt\n\\end{lstlisting}\n\nGiven a list of integers (commonly known as \\textit{tail}), we can add an integer to it (commonly known as \\textit{head}) and obtain a new list of integers. Head and tail are separated by a symbol such as:\n\n\\begin{lstlisting}\nData [<<int>>] \";\" [ListInt] Priority 1000 Type ListInt\n\\end{lstlisting}\n\nNotice that our language assumes the existance of \\textit{predefined data types}, which can be accessed with the special brackets \\texttt{<<} and \\texttt{>>}.\n\nThanks to this definition, we can now build a few example lists:\n\n\\begin{itemize}\n\\item \\texttt{nil}\n\\item \\texttt{1;nil}\n\\item \\texttt{0;(1;(2;(3;nil)))}\n\\item ...\n\\end{itemize}\n\n\\subsection{List querying}\nWe will now define a series of list operations that allow us to process a list and extract various properties from it.\n\n\\paragraph{Length of a list}\nAmong the most fundamental operations that we can perform on lists, we have the determination of the length of a list. We define the \\texttt{length} symbol that takes a parameter of type list and returns an integer\\footnote{Remember that \\texttt{<<} and \\texttt{>>} identify built-in types, so \\texttt{<<int>>} literally means a machine-integer.} as result (the length of the list):\n\n\\begin{lstlisting}\nFunc \"length\" [ListInt] Priority 100 Type Expr => <<int>>\n\\end{lstlisting}\n\nDetermining the length of the empty list is simple, as we can immediately answer that it has a length of zero:\n\n\\begin{lstlisting}\n----------------\nlength nil => 0\n\\end{lstlisting}\n\nIf the input list is not empty, then we compute the length of its tail (\\texttt{xs}) and then return this length plus one as the total length of the whole list:\n\n\\begin{lstlisting}\nlength xs => y\n--------------------------\nlength x;xs => <<1 + y>>\n\\end{lstlisting}\n\nConsider now execution of program \\texttt{length 1;2;3;nil}. We start with the initial proposition, which is clearly no instance of \\texttt{length nil}:\n\n\\begin{lstlisting}\n----------------------\nlength 1;2;3;nil => ?\n\\end{lstlisting}\n\nThe proposition above instances a recursive premise on the tail of the list:\n\n\\begin{lstlisting}\nlength 2;3;nil => y1\n-------------------------------\nlength 1;2;3;nil => <<1 + y1>>\n\\end{lstlisting}\n\nProposition \\texttt{length 2;3;nil} is, once again, clearly no instance of \\texttt{length nil}, and we proceed for a few steps\\footnote{Which, with a smile and some handwaving, allows us to skip a couple of boring paragraphs of the book, which you smart reader feel no need for.} until we get to the following derivation tree:\n\n\\begin{lstlisting}\nlength nil => y3\ny2 := <<1 + y3>>\n------------------------\nlength 3;nil => y2\ny1 := <<1 + y2>>\n------------------------\nlength 2;3;nil => y1\n-------------------------------\nlength 1;2;3;nil => <<1 + y1>>\n\\end{lstlisting}\n\nThe last premise, \\texttt{length nil}, is quite obviously an instance of \\texttt{length nil}, therefore we can directly jump to the result that \\texttt{y3 := 0}:\n\n\\begin{lstlisting}\ny3 := 0\n-----------------\nlength nil => y3\ny2 := <<1 + y3>>\n------------------------\nlength 3;nil => y2\ny1 := <<1 + y2>>\n------------------------\nlength 2;3;nil => y1\n-------------------------------\nlength 1;2;3;nil => <<1 + y1>>\n\\end{lstlisting}\n\nWe can now fold back the results, just like a stack unwinding in a series of recursive calls. The first unwinding step yields:\n\n\\begin{lstlisting}\nlength nil => 0\ny2 := <<1 + 0>>\n------------------------\nlength 3;nil => y2\ny1 := <<1 + y2>>\n------------------------\nlength 2;3;nil => y1\n-------------------------------\nlength 1;2;3;nil => <<1 + y1>>\n\\end{lstlisting}\n\nWe then proceed with the second unwinding step:\n\n\\begin{lstlisting}\n------------------------\nlength 3;nil => 1\ny1 := <<1 + 1>>\n------------------------\nlength 2;3;nil => y1\n-------------------------------\nlength 1;2;3;nil => <<1 + y1>>\n\\end{lstlisting}\n\nAnd so on, until we reach the final expected answer which was \\texttt{length 1;2;3;nil => 3}.\n\n\n\\paragraph{Searching}\nA slightly more complex operation that we can perform is searching. Search determines whether or not a list \\texttt{contains} an element. We define the \\texttt{contains} function that takes a list and an integer as parameters:\n\n\\begin{lstlisting}\nFunc \"contains\" [ListInt <<int>>] Priority 100 Type Expr => <<int>>\n\\end{lstlisting}\n\nThe simplest test we perform is on an empty list. An empty list \\texttt{nil} never contains a value \\texttt{k}, independently of its value. The \\texttt{contains} function in this case will thus return \\texttt{no}\\footnote{Assume we have defined symbols \\texttt{yes} and \\texttt{no}, but of course as a sane alternative boolean values can be used.} directly:\n\n\\begin{lstlisting}\n---------------------\nnil contains k => no\n\\end{lstlisting}\n\nIf the input list is not empty, then it means that it is not \\texttt{nil}, and therefore it is made up of an element \\texttt{x} followed by the rest of the list \\texttt{xs}: \\texttt{x;xs}. In this case, we check to see whether or not the head of the list is equal to the search element (the single premise \\texttt{x == k}). If the premise is positively discharged (it is true) then we can return \\texttt{yes} as the final result:\n\n\\begin{lstlisting}\nx == k\n-----------------------\nx;xs contains k => yes\n\\end{lstlisting}\n\nIf the input list is not empty, but the first element is not equal to the searched key, then we need to keep searching. The result of the overall search will therefore be the result of searching in the rest of the list \\texttt{xs} with the premise \\texttt{xs contains k => res}:\n\n\\begin{lstlisting}\nx != k\nxs contains k => res\n-----------------------\nx;xs contains k => res\n\\end{lstlisting}\n\n\n\\paragraph{Transforming}\nConsider now the problem of transforming a list by incrementing all of its elements by \\texttt{k}. This example is interesting because it shows how a new list can be rebuilt and returned, instead of a single value like we did in the previous examples. \n\nWe begin by deifning the \\texttt{plus} function which takes as input a list and an integer:\n\n\\begin{lstlisting}\nFunc [] \"plus\" [ListInt <<int>>] Priority 100 Type Expr => ListInt\n\\end{lstlisting}\n\nThe transformation of an empty list remains an empty list, as there are no elements to transform:\n\n\\begin{lstlisting}\n-------------------\nplus nil k => nil\n\\end{lstlisting}\n\nThe transform of the non-empty list proceeds first with the transformation of the rest of the list into \\texttt{xs'}, then it computes \\texttt{x+k} (the transformed head) into \\texttt{x'}, and finally it returns the list \\texttt{x';xs'} as the whole transformed list:\n\n\\begin{lstlisting}\nplus xs k => xs'\n<<x+k>> => x'\n----------------------\nplus x;xs k => x';xs'\n\\end{lstlisting}\n\n\nMany useful functions on lists take the general form above: an immediate (often trivial) answer for the case of an empty list, and a recursive step which somehow combines premises on the first element with premises on the remaining elements. In a sense, lists are the embodiement of the simplest principles of recursion.\n\n\n\\paragraph{Sorting}\nLet us now consider a slightly more complex algorithm, which allows us to test the algorithmic expressive power of the language. In particular, let us consider a powerful and fast sorting algorithm, the well-known \\textit{merge-sort}. Merge sort works by, recursively, dividing the list of elements into two sublists, sorting them separately, and then merging the two sorted lists into a single, final sorted list.\n\nWe need two auxiliary symbol definitions: one is the comma, which will be used to represent a pair of lists, and the other is the \\texttt{mergeSort} function itself:\n\n\\begin{lstlisting}\nData [] [ListInt] \",\" [ListInt] Priority 900 Type ListIntPair\nFunc [] \"mergeSort\" [ListInt] Priority 100 Type Expr => ListInt\n\\end{lstlisting}\n\nThe definition of \\texttt{mergeSort} then becomes quite simple. If the list is empty, or contains only one element, then no sorting needs to take place and we can immediately return the sorted list as an answer:\n\n\\begin{lstlisting}\n---------------------\nmergeSort nil => nil\n\n-------------------------\nmergeSort x;nil => x;nil\n\\end{lstlisting}\n\nIf the list contains at least two elements, then:\n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item we split it into two sub-lists \\texttt{l} and \\texttt{r};\n\\item we sort \\texttt{l} into \\texttt{l'} with a recursive call;\n\\item we sort \\texttt{r} into \\texttt{r'} with a recursive call;\n\\item we merge \\texttt{l'} and \\texttt{r'}, therefore obtaining the final sorted list.\n\\end{inparaenum}\n\n\\begin{lstlisting}\nsplit x;y;xs => l,r\nmergeSort l => l'\nmergeSort r => r'\nmerge l' r' => res\n------------------------\nmergeSort x;y;xs => res\n\\end{lstlisting}\n\nSplitting a list is done with function \\texttt{split}:\n\n\\begin{lstlisting}\nFunc [] \"split\" [ListInt] Priority 100 Type Expr => ListIntPair\n\\end{lstlisting}\n\nIf the list to split has less than two elements, then splitting is trivial:\n\n\\begin{lstlisting}\n---------------------\nsplit nil => nil,nil\n\n-------------------------\nsplit x;nil => x;nil,nil\n\\end{lstlisting}\n\nIf the list to split has at least two elements \\texttt{x} and \\texttt{y}, then:\n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item we split the remaining list recursively, obtaining partial splits \\texttt{l} and \\texttt{r};\n\\item list \\texttt{x;l} is the first item of the result;\n\\item list \\texttt{y;r} is the second item of the result.\n\\end{inparaenum}\n\n\\begin{lstlisting}\nsplit xs => l,r\n----------------------------\nsplit x;y;xs => (x;l),(y;r)\n\\end{lstlisting}\n\nLet us consider a short example of how split works on a list such as:\n\n\\begin{lstlisting}\n-------------------------\nsplit 0;1;2;3;4;nil => ?\n\\end{lstlisting}\n\nSince the list contains at least two elements, we apply the recursive rule for \\texttt{x=0}, \\texttt{y=1}, and \\texttt{xs=2;3;4;nil}:\n\n\\begin{lstlisting}\nsplit 2;3;4;nil => l,r\n-----------------------------------\nsplit 0;1;2;3;4;nil => (0;l),(1;r)\n\\end{lstlisting}\n\nWe apply the same rule again because \\texttt{2;3;4;nil} has at least two elements, thus:\n\n\\begin{lstlisting}\nsplit 4;nil => l',r'\nl := 2;l'\nr := 3;r'\n-----------------------\nsplit 2;3;4;nil => l,r\n-----------------------------------\nsplit 0;1;2;3;4;nil => (0;l),(1;r)\n\\end{lstlisting}\n\nWe end up with list \\texttt{4;nil}, which has only one element. This requires us to apply one of the trivial rules above:\n\n\\begin{lstlisting}\nl' := 4;nil\nr' := nil\n--------------------\nsplit 4;nil => l',r'\nl := 2;l'\nr := 3;r'\n-----------------------\nsplit 2;3;4;nil => l,r\n-----------------------------------\nsplit 0;1;2;3;4;nil => (0;l),(1;r)\n\\end{lstlisting}\n\nWe can now unwind the stack of intermediate results. The first unwind step yields:\n\n\\begin{lstlisting}\nl := 2;4;nil\nr := 3;nil\n-----------------------\nsplit 2;3;4;nil => l,r\n-----------------------------------\nsplit 0;1;2;3;4;nil => (0;l),(1;r)\n\\end{lstlisting}\n\nThe second and last unwind step returns the final result:\n\n\\begin{lstlisting}\n---------------------------------------------\nsplit 0;1;2;3;4;nil => (0;2;4;nil),(1;3;nil)\n\\end{lstlisting}\n\nThe role of \\texttt{split} is thus to split the list in two, but instead of taking the first half and then the second half of the list, we \\textit{interleave} the elements: elements in odd positions go in the first sublist, elements in even positions go in the second sublist.\n\nMerging two lists requires a bit of care, because we take as input two sorted lists and we must give as output a single list which contains all elements of the two lists to merge \\textit{in sorted order}. Merging is done with function \\texttt{merge}:\n\n\\begin{lstlisting}\nFunc [] \"merge\" [ListInt ListInt] Priority 100 Type Expr => ListInt\n\\end{lstlisting}\n\nIf any of the input lists to merge is empty, then the answer is trivial to find and return:\n\n\\begin{lstlisting}\n---------------------\nmerge nil nil => nil\n\n-----------------------\nmerge x;xs nil => x;xs\n\n-----------------------\nmerge nil y;ys => y;ys\n\\end{lstlisting}\n\nIf the first list begins with an element that is smaller than the first element of the second list, then the resulting list will need to start with that element (and vice-versa):\n\n\\begin{lstlisting}\nx <= y\nmerge xs y;ys => res\n-------------------------\nmerge x;xs y;ys => x;res\n\nx > y\nmerge x;xs ys => res\n-----------------------\nmerge x;xs y;ys => y;res\n\\end{lstlisting}\n\nConsider now the merging of two partial sorted lists \\texttt{0;2;nil} and \\texttt{1;3;nil} (the lists do not need to be of the same length, nor do the elements need to interleave so strictly):\n\n\\begin{lstlisting}\n---------------------------\nmerge 0;2;nil 1;3;nil => ?\n\\end{lstlisting}\n\nThe first element of the first list is smaller than the first element of the second list, thus it will become the first element of the result:\n\n\\begin{lstlisting}\nmerge 2;nil 1;3;nil => res\n-------------------------------\nmerge 0;2;nil 1;3;nil => 0;res\n\\end{lstlisting}\n\nThe first element of the second list is smaller than the first element of the first list, thus it will be selected as the first element of the (intermediate) result:\n\n\\begin{lstlisting}\n--------------------------\nmerge 2;nil 3;nil => res'\nres := 1;res'\n---------------------------\nmerge 2;nil 1;3;nil => res\n-------------------------------\nmerge 0;2;nil 1;3;nil => 0;res\n\\end{lstlisting}\n\nWe now select \\texttt{2} as the new head of the intermediate result:\n\n\\begin{lstlisting}\nmerge nil 3;nil => res''\nres' := 2;res''\n--------------------------\nmerge 2;nil 3;nil => res'\nres := 1;res'\n---------------------------\nmerge 2;nil 1;3;nil => res\n-------------------------------\nmerge 0;2;nil 1;3;nil => 0;res\n\\end{lstlisting}\n\nFinally, since the first list is empty, we directly return the second:\n\n\\begin{lstlisting}\nres'' := 3;nil\n-------------------------\nmerge nil 3;nil => res''\nres' := 2;res''\n--------------------------\nmerge 2;nil 3;nil => res'\nres := 1;res'\n---------------------------\nmerge 2;nil 1;3;nil => res\n-------------------------------\nmerge 0;2;nil 1;3;nil => 0;res\n\\end{lstlisting}\n\nSince we have no more intermediate results to process, we can now begin the unwinding. First of all \\texttt{res''} is replaced with \\texttt{3;nil}:\n\n\\begin{lstlisting}\nres' := 2;3;nil\n--------------------------\nmerge 2;nil 3;nil => res'\nres := 1;res'\n---------------------------\nmerge 2;nil 1;3;nil => res\n-------------------------------\nmerge 0;2;nil 1;3;nil => 0;res\n\\end{lstlisting}\n\nThen we replace \\texttt{res'} with its value of \\texttt{2;3;nil}:\n\n\\begin{lstlisting}\nres := 1;2;3;nil\n---------------------------\nmerge 2;nil 1;3;nil => res\n-------------------------------\nmerge 0;2;nil 1;3;nil => 0;res\n\\end{lstlisting}\n\nFinally we replace \\texttt{res}, therefore obtaining the final answer:\n\n\\begin{lstlisting}\nmerge 0;2;nil 1;3;nil => 0;1;2;3;nil\n\\end{lstlisting}\n\nAt this point we can better discuss what \\texttt{mergeSort} does, without doing the full derivation which would take too long. Suppose we wished to sort sequence \\texttt{5;4;3;2;1;nil}:\n\n\\begin{lstlisting}\nsplit 5;4;3;2;1;nil => l,r\nmergeSort l => l'\nmergeSort r => r'\nmerge l' r' => res\n------------------------\nmergeSort 5;4;3;2;1;nil => res\n\\end{lstlisting}\n\nWithout going (again) into the details of \\texttt{split}, we can just assume it will work as expected and obtain:\n\n\\begin{lstlisting}\nsplit 5;4;3;2;1;nil => (5;3;1;nil),(4;2;nil)\nmergeSort 5;3;1;nil => l'\nmergeSort 4;2;nil => r'\nmerge l' r' => res\n------------------------\nmergeSort 5;4;3;2;1;nil => res\n\\end{lstlisting}\n\nAt this point we make a strong assumption, which we can safely make because of the principle of induction, that is we assume that \\texttt{mergeSort 5;3;1;nil} and \\texttt{mergeSort 4;2;nil} will both return a sorted list. The next step is therefore:\n\n\\begin{lstlisting}\nmergeSort 5;3;1;nil => 1;3;5;nil\nmergeSort 4;2;nil => 2;4;nil\nmerge 1;3;5;nil 2;4;nil => res\n-------------------------------\nmergeSort 5;4;3;2;1;nil => res\n\\end{lstlisting}\n\nWithout going (again) into the details of \\texttt{merge}, we can just assume it will work as expected and obtain:\n\n\\begin{lstlisting}\nmerge 1;3;5;nil 2;4;nil => 1;2;3;4;5;nil\n-----------------------------------------\nmergeSort 5;4;3;2;1;nil => 1;2;3;4;5;nil\n\\end{lstlisting}\n\nwhich is precisely the expected result.\n\n\\paragraph{Conclusions}\nWhat we have seen so far extends (with more or less translation work depending on the circumstances) to all known algorithms on lists. It is possible to write algorithms such as insertion sort, various kinds of search, and so on with minimal adjustments. In the coming sections we will dig yet deeper into recursive data structures such as binary trees.\n", "meta": {"hexsha": "ae9378f0699df235ceb06cef3ffcd507dd44cc9d", "size": 17933, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Course materials/Dictaat/tex/Examples/lists.tex", "max_stars_repo_name": "vs-team/metacompiler", "max_stars_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-12-13T09:22:28.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-03T21:48:11.000Z", "max_issues_repo_path": "Course materials/Dictaat/tex/Examples/lists.tex", "max_issues_repo_name": "cult-of-giuseppe/metacompiler", "max_issues_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2015-08-14T06:48:43.000Z", "max_issues_repo_issues_event_max_datetime": "2015-08-16T09:37:03.000Z", "max_forks_repo_path": "Course materials/Dictaat/tex/Examples/lists.tex", "max_forks_repo_name": "cult-of-giuseppe/metacompiler", "max_forks_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-10-11T17:13:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-10T19:12:15.000Z", "avg_line_length": 37.2053941909, "max_line_length": 618, "alphanum_fraction": 0.6608487147, "num_tokens": 4909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.855851143290548, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7017066526843796}}
{"text": "\\chapter{Fourier Series}\n\\section{Series Expansion of Periodic Functions}\nThe basic fact about Fourier series is as follows.\\\\\nIf $f(x)$ is a periodic function of $x$,with a period $L$ . The \\textbf{Fundamental interval} is taken to be $(a,b)$, so that $L=(b-a)$\\\\\nThen, $f(x)=f(x+L)=f(x+nL)$ Where $n$ is any integer.\\\\If the function $f(x)$ also satisfies a set of conditions known as \\textbf{Drichlet's  Conditions} given as below\\\\\n\n\\begin{enumerate}\n\t\\item It is single-valued in the interval $(a, b)$\n\t\\item It is bounded in the interval $(a, b)$\n\t\\item It has at most a finite number of maxima and minima in the interval $(a, b)$\n\t\\item It has only a finite number of discontinuity in the interval $(a, b)$\n\\end{enumerate}\n\\begin{theorem}\\label{geneq}\n\tThen such a function can be expressed by a sum of a set  sine and cosine functions (or complex exponentials). This series is known as \\textbf{Fourier Series Expansion}\\index{Fourier Series}.\\\\\n\t\\begin{equation}\n\t\\begin{array}{c}\n\tf(x)=\\frac{a_{0}}{2}+\\sum_{n=1}^{\\infty} a_{n} \\cos \\frac{2n \\pi x}{L}+\\sum_{n=1}^{\\infty} b_{n} \\sin \\frac{2n \\pi x}{L}\n\t\\end{array}\n\t\\end{equation}\n\t\n\t$a_{0}, a_{n}, b_{n}$ are constants, known as Fourier co-efficients.\n\t\\begin{equation}\n\ta_{0}=\\frac{2}{b-a} \\int_{a}^{b} f(x) d x\n\t\\end{equation}\n\t\\begin{equation}\n\ta_{n}=\\frac{2}{b-a} \\int_{a}^{b} f(x) \\cdot \\cos \\left(\\frac{2 n \\pi x}{b-a}\\right) d x\n\t\\end{equation}\n\t\\begin{equation}\n\tb_{n}=\\frac{2}{b-a} \\int_{a}^{b} f(x) \\cdot \\sin \\left(\\frac{2 n \\pi x}{b-a}\\right) d x\n\t\\end{equation}\n\\end{theorem}\nThe Fourier expansion of a periodic function $f(x)$ consists of the following term\n\\begin{enumerate}\n\t\\item $a_{0}: a$ constant term or $D .$ C. term\n\t\\item $a_{1} \\cos \\frac{\\pi x}{L}$ and $b_{1} \\sin \\frac{\\pi x}{L}:$ Fundamental frequency term i.e term having lowest frequency\n\t\\item $a_{2} \\cos \\frac{2 \\pi x}{L}, a_{3} \\cos \\frac{3 \\pi x}{L} \\ldots \\ldots ., b_{2} \\sin \\frac{2 \\pi x}{L}, b_{3} \\sin \\frac{3 \\pi x}{L} \\ldots \\ldots .$ Overtones i.e terms having\n\tfrequencies integer multiple of fundamental frequency term.\n\\end{enumerate}\n\n\\subsection{Simplified formulas when $b-a=2\\pi$}\n\nWe have established the Euler formulas for a function having period $L$ and principal interval $(a,b)$.The formulas connected with fourier series expansion look a bit simpler if one choose the fundamental interval to be $(-\\pi,\\pi)$ or $(0,2\\pi)$, ie Period $L=2\\pi$.\\\\For the case $b-a=2\\pi$, the Euler formulas become\n\n\t\n\\begin{theorem}\\label{pareq}\n\n\n\\begin{equation}\na_{0}=\\frac{1}{\\pi} \\int_{a}^{b} f(x) d x\n\\end{equation}\n\\begin{equation}\na_{0n}=\\frac{1}{\\pi} \\int_{a}^{b} f(x) \\cdot \\cos n x d x\n\\end{equation}\n\\begin{equation}\nb_{n}=\\frac{1}{\\pi} \\int_{a}^{b} f(x) \\cdot \\sin n x d x\n\\end{equation}\nSo that the Fourier expansion becomes \n\\begin{equation}\nf(x)=\\frac{a_{0}}{2}+\\sum_{n=1}^{\\infty} a_{n} \\cdot \\cos n x+\\sum_{n=1}^{\\infty} b_{n} \\sin n x\n\\end{equation}\n\\end{theorem}\n\n\n\\begin{exercise}\n\t Find the Fourier series representing $$f(x)=x, \\quad 0<x<2 \\pi$$\n\\end{exercise}\n\\begin{answer}\nHere the interval is $(0,2\\pi)$ So L=$2\\pi$.From theorem \\ref{pareq} we have\n\\begin{equation}\n\\label{eq1}\nf(x)=\\frac{a_{0}}{2}+\\sum_{n=1}^{\\infty} a_{n} \\cdot \\cos n x+\\sum_{n=1}^{\\infty} b_{n} \\sin n x\n\\end{equation}\n$$h\n\\text { Hence } \\begin{aligned}\na_{0} &=\\frac{1}{\\pi} \\int_{0}^{2 \\pi} f(x) d x=\\frac{1}{\\pi} \\int_{0}^{2 \\pi} x d x=\\frac{1}{\\pi}\\left[\\frac{x^{2}}{2}\\right]_{0}^{2 \\pi}=2 \\pi \\\\\na_{n} &=\\frac{1}{\\pi} \\int_{0}^{2 \\pi} f(x) \\cos n x d x=\\frac{1}{\\pi} \\int_{0}^{2 \\pi} x \\cos n x d x \\\\\n&=\\frac{1}{\\pi}\\left[x \\frac{\\sin n x}{n}-1 \\cdot\\left(-\\frac{\\cos n x}{n^{2}}\\right)\\right]_{0}^{2 \\pi}=\\frac{1}{\\pi}\\left[\\frac{\\cos 2 n \\pi}{n^{2}}-\\frac{1}{n^{2}}\\right]=\\frac{1}{n^{2} \\pi}(1-1)=0 \\\\\nb_{n} &=\\frac{1}{\\pi} \\int_{0}^{2 \\pi} f(x) \\sin n x d x=\\frac{1}{\\pi} \\int_{0}^{2 \\pi} x \\sin n x d x \\\\\n&=\\frac{1}{\\pi}\\left[x\\left(-\\frac{\\cos n x}{n}\\right)-1 \\cdot\\left(\\frac{-\\sin n x}{n^{2}}\\right)\\right]_{0}^{2 \\pi}=\\frac{1}{\\pi}\\left[\\frac{-2 \\pi \\cos 2 n \\pi}{n}\\right]=-\\frac{2}{n}\n\\end{aligned}\n$$\nSubstituting the values of $a_{0}, a_{1}, a_{2} \\ldots, b_{1}, b_{2} \\ldots$ in Equation \\ref{eq1}, we get\n$$\nx=\\pi-2\\left[\\sin x+\\frac{1}{2} \\sin 2 x+\\frac{1}{3} \\sin 3 x+\\ldots\\right]\n$$\n\\end{answer}\n\\begin{exercise}\nGiven that $f(x)=x+x^{2}$ for $-\\pi<x<\\pi,$ find the Fourier expression of $f(x)$\n\\end{exercise}\n\n\\begin{answer}\n\t\\begin{equation}\n\\label{eq2}\n\t\\text { Let } x+x^{2}=\\frac{a_{0}}{2}+a_{1} \\cos x+a_{2} \\cos 2 x+\\ldots+b_{1} \\sin x+b_{2} \\sin 2 x+\\ldots\n\t\\end{equation}\n\t$\\begin{aligned} a_{0} &=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) d x=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi}\\left(x+x^{2}\\right) d x \\\\ &=\\frac{1}{\\pi}\\left[\\frac{x^{2}}{2}+\\frac{x^{3}}{3}\\right]_{-\\pi}^{\\pi}=\\frac{1}{\\pi}\\left[\\frac{\\pi^{2}}{2}+\\frac{\\pi^{3}}{3}-\\frac{\\pi^{2}}{2}+\\frac{\\pi^{3}}{3}\\right]=\\frac{2 \\pi^{2}}{3} \\\\ a_{n} &=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) \\cos n x d x=\\int_{-\\pi}^{\\pi}\\left(x+x^{2}\\right) \\cos n x d x \\end{aligned}$\\\\\n\t$\\begin{aligned} &=\\frac{1}{\\pi}\\left[\\left(x+x^{2}\\right) \\frac{\\sin n x}{n}-(2 x+1) \\frac{(-\\cos n x)}{n^{2}}+(2)\\left(-\\frac{\\sin n x}{n^{3}}\\right)\\right]_{-\\pi}^{\\pi} \\\\ &=\\frac{1}{\\pi}\\left[(2 \\pi+1) \\frac{\\cos n \\pi}{n^{2}}-(-2 \\pi+1) \\frac{\\cos (-n \\pi)}{n^{2}}\\right]=\\frac{1}{\\pi}\\left[4 \\pi \\frac{\\cos n \\pi}{n^{2}}\\right]=\\frac{4(-1)^{n}}{n^{2}} \\\\ b_{n} &=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) \\sin n x d x=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi}\\left(x+x^{2}\\right) \\sin n x d x \\\\ &=\\frac{1}{\\pi}\\left[\\left(x+x^{2}\\right)\\left(-\\frac{\\cos n x}{n}\\right)-(2 x+1)\\left(\\frac{-\\sin n x}{n^{2}}\\right)+2 \\frac{\\cos n x}{n^{3}}\\right]_{-\\pi}^{\\pi} \\\\ &=\\frac{1}{\\pi}\\left[-\\left(\\pi+\\pi^{2}\\right) \\frac{\\cos n \\pi}{n}+2 \\frac{\\cos n \\pi}{n^{3}}+\\left(-\\pi+\\pi^{2}\\right) \\frac{\\cos n \\pi}{n}-2 \\frac{\\cos n \\pi}{n^{3}}\\right] \\\\ &=\\frac{1}{\\pi}\\left[-\\frac{2 \\pi}{n} \\cos n \\pi\\right]=-\\frac{2}{n}(-1)^{n} \\end{aligned}$\\\\\n\tSubstituting the values of $a_{0}, a_{n}, b_{n},$ in Equation \\ref{eq2}, we get\n\t\\begin{equation}\n\t\\begin{array}{r}\n\tx+x^{2}=\\frac{\\pi^{2}}{3}+4\\left[-\\cos x+\\frac{1}{2^{2}} \\cos 2 x-\\frac{1}{3^{2}} \\cos 3 x+\\ldots\\right] \n\t-2\\left[-\\sin x+\\frac{1}{2} \\sin 2 x-\\frac{1}{3} \\sin 3 x+\\ldots\\right]\n\t\\end{array}\n\t\\end{equation}\n\\end{answer}\n\\section{Even and Odd Functions}\n\\subsection{Even Function}\nA function $f(x)$ is said to be \\textbf{even} (or \\textbf{symmetric}) function if, $f(-x)=f(x)$ The graph of such a function is symmetrical with respect to $y$ -axis . Here $y$ -axis is a mirror for the reflection of the curve.\n\\begin{example}\n\t$\\cos x,\\sec x ,x^2$ etc\n\n\\end{example}\nThe area under such a curve from $-\\pi$ to $\\pi$ is double the area from 0 to $\\pi$, ie\\\\\n$$\\quad \\int_{-\\pi}^{\\pi} f(x) d x=2 \\int_{0}^{\\pi} f(x) d x$$\n\\subsection{Odd Function}\nA function $f(x)$ is called \\textbf{odd} (or \\textbf{skew symmetric}) function if\n$$\nf(-x)=-f(x)\n$$ Odd functions will be symmetric about origin.\\\\\nHere the area under the curve from $-\\pi$ to $\\pi$ is zero.\n$$\n\\int_{-\\pi}^{\\pi} f(x) d x=0\n$$\n\n\\begin{note}\n\t\\[\n\t\\boxed{\n\t\t\\!\\begin{aligned}\n\t\t&Even \\times Even= Odd \\times Odd = Even\\\\\n\t\t&Odd \\times Even= Even \\times Odd = Odd\n\t\t\\end{aligned}\n\t}\n\t\\]\n\\end{note}\n\\section{Fourier Expansion of Even and Odd Functions}\n\\subsection{Even Function}\n$$\na_{0}=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) d x=\\frac{2}{\\pi} \\int_{0}^{\\pi} f(x) d x\n$$\n$$\na_{n}=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) \\cos n x d x=\\frac{2}{\\pi} \\int_{0}^{\\pi} f(x) \\cos n x d x\n$$\nAs $f(x)$ and $\\cos n x$ are both even functions, therefore, the product of $f(x) . \\cos n x$ is also an even function.\n$$\nb_{n}=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) \\sin n x d x=0\n$$\n\\textbf{So if $f(x)$ is an even function then Fourier coefficient $b_n$ will be zero in the expansion. }\\\\\nThe series of the even function will contain only cosine and DC terms.\n\\begin{exercise}\n\tFind the Fourier series expansion of the periodic function of period $2 \\pi$\n\t$$\n\tf(x)=x^{2},-\\pi \\leq x \\leq \\pi\n\t$$\n\\end{exercise}\n\\begin{answer}\n\tThis is an even function. $\\therefore b_{n}=0$\n\t$$\n\t\\begin{aligned}\n\tb_{n} &=0 \\quad[f(-x)=f(x)] \\\\\n\ta_{0} &=\\frac{2}{\\pi} \\int_{0}^{\\pi} f(x) d x=\\frac{2}{\\pi} \\int_{0}^{\\pi} x^{2} d x=\\frac{2}{\\pi}\\left[\\frac{x^{3}}{3}\\right]_{0}^{\\pi}=\\frac{2 \\pi^{2}}{3} \\\\\n\ta_{n} &=\\frac{2}{\\pi} \\int_{0}^{\\pi} f(x) \\cos n x d x=\\frac{2}{\\pi} \\int_{0}^{\\pi} x^{2} \\cos n x d x \\\\\n\t&=\\frac{2}{\\pi}\\left[x^{2}\\left(\\frac{\\sin n x}{n}\\right)-(2 x)\\left(-\\frac{\\cos n x}{n^{2}}\\right)+(2)\\left(-\\frac{\\sin n x}{n^{3}}\\right)\\right]_{0}^{\\pi} \\\\\n\t=& \\frac{2}{\\pi}\\left[\\frac{\\pi^{2} \\sin n \\pi}{n}+\\frac{2 \\pi \\cos n \\pi}{n^{2}}-\\frac{2 \\sin n \\pi}{n^{3}}\\right]=\\frac{4(-1)^{n}}{n^{2}}\n\t\\end{aligned}\n\t$$\n\t$\\begin{aligned} \\text { Fourier series is } & f(x)=\\frac{a_{0}}{2}+a_{1} \\cos x+a_{2} \\cos 2 x+a_{3} \\cos 3 x+\\ldots+a_{n} \\cos n x+\\ldots \\\\ x^{2} &=\\frac{\\pi^{2}}{3}-4\\left[\\frac{\\cos x}{1^{2}}-\\frac{\\cos 2 x}{2^{2}}+\\frac{\\cos 3 x}{3^{2}}-\\frac{\\cos 4 x}{4^{2}}+\\ldots\\right] \\end{aligned}$\n\\end{answer}\n\\subsection{Odd Function}\n$$\\begin{aligned}\n\t&a_{0}=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) d x=0\\\\\n\t&a_{n}=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) \\cos n x d x=0 \n\\end{aligned}$$\n(Since $f(x)$ is an odd function and $cos(x)$ is an even function their product will be odd and the integral vanishes)\n$$\\begin{aligned}\nb_{n}&=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) \\sin n x d x\\\\\n\\therefore b_{n}&=\\frac{2}{\\pi} \\int_{0}^{\\pi} f(x) \\sin n x d x\n\\end{aligned}$$\n\\textbf{So if $f(x)$ is an odd function then Fourier coefficient $a_0$ and $a_n$ will be zero in the expansion. }\\\\\nThe series of the odd function will contain only sine  terms.\n\n\\begin{exercise}\n\tObtain a Fourier expression for\n\t$$\n\tf(x)=x^{3} \\quad \\text { for }-\\pi<x<\\pi\n\t$$\n\\end{exercise}\n\\begin{answer}\n\t$f(x)=x^{3}$ is an odd function. \n\t$$\n\t\\begin{aligned}\n\t\\therefore \\quad a_{0} & =0 \\text { and } a_{n}=0 \\\\\n\t\\text{ Use tabular integration }\\\\\n\tb_{n} & =\\frac{2}{\\pi} \\int_{0}^{\\pi} f(x) \\sin n x d x=\\frac{2}{\\pi} \\int_{0}^{\\pi} x^{3} \\sin n x d x \\\\\n\t& =\\frac{2}{\\pi}\\left[x^{3}\\left(-\\frac{\\cos n x}{n}\\right)-3 x^{2}\\left(-\\frac{\\sin n x}{n^{2}}\\right)+6 x\\left(\\frac{\\cos n x}{n^{3}}\\right)-6\\left(\\frac{\\sin n x}{n^{4}}\\right)\\right]_{0}^{\\pi} \\\\\n\t& =\\frac{2}{\\pi}\\left[-\\frac{\\pi^{3} \\cos n \\pi}{n}+\\frac{6 \\pi \\cos n \\pi}{n^{3}}\\right]=2 \\cdot(-1)^{n}\\left[-\\frac{\\pi^{2}}{n}+\\frac{6}{n^{3}}\\right] \\\\\n \\text{ We have }f(x)&=b_{1} \\sin x+b_{2} \\sin 2 x+b_{3} \\sin 3 x+\\ldots \\ldots \\\\\n\t x^{3}&=2\\left[-\\left(-\\frac{\\pi^{2}}{1}+\\frac{6}{1^{3}}\\right) \\sin x+\\left(-\\frac{\\pi^{2}}{2}+\\frac{6}{2^{3}}\\right) \\sin 2 x-\\left(-\\frac{\\pi^{2}}{3}+\\frac{6}{3^{3}}\\right) \\sin 3 x+\\ldots\\right] \n\t\\end{aligned}\n\t$$\n\\end{answer}\n\n\\newpage\n\\begin{abox}\n\tPractise Set-1\n\\end{abox}\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\n\t\\item   The first few terms in the Laurent series for $\\frac{1}{(z-1)(z-2)}$ in the region $1 \\leq|z| \\leq 2$ and around $z=1$ is\n\t{\\exyear{NET/JRF(JUNE-2012)}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $\\frac{1}{2}\\left[1+z+z^{2}+\\ldots\\right]\\left[1+\\frac{z}{2}+\\frac{z^{2}}{4}+\\frac{z^{3}}{8}+\\ldots .\\right]$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{1-z}-z-(1-z)^{2}+(1-z)^{3}+\\ldots .$\n\t\t\\task[\\textbf{C.}] $\\frac{1}{\\mathrm{z}^{2}}\\left[1+\\frac{1}{\\mathrm{z}}+\\frac{1}{\\mathrm{z}^{2}}+\\ldots .\\right]\\left[1+\\frac{2}{\\mathrm{z}}+\\frac{4}{\\mathrm{z}^{2}}+\\ldots . .\\right]$\n\t\t\\task[\\textbf{D.}]  $2(z-1)+5(z-1)^{2}+7(z-1)^{3}+\\ldots$\n\t\\end{tasks}\n\t\\item Consider a sinusoidal waveform of amplitude $1 V$ and frequency $f_{0}$. Starting from an arbitrary initial time, the waveform is sampled at intervals of $\\frac{1}{2 f_{0}}$. If the corresponding Fourier spectrum peaks at a frequency $\\bar{f}$ and an amplitude $\\bar{A}$, them\n\t{\\exyear{NET/JRF(JUNE-2012)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\bar{f}=2 f_{0}$ and $\\bar{A}=1 V$\n\t\t\\task[\\textbf{B.}] $\\bar{f}=2 f_{0}$ and $0 \\leq \\bar{A} \\leq 1 V$\n\t\t\\task[\\textbf{C.}] $\\bar{f}=0$ and $\\bar{A}=1 V$\n\t\t\\task[\\textbf{D.}] $\\bar{f}=\\frac{f_{0}}{2}$ and $\\bar{A}=\\frac{1}{\\sqrt{2}} V$\n\t\\end{tasks}\n\t\\item The Fourier transform of the derivative of the Dirac $\\delta-$ function, namely $\\delta^{\\prime}(x)$, is proportional to\n\t{\\exyear{NET/JRF(DEC-2013)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 0\n\t\t\\task[\\textbf{B.}] 1\n\t\t\\task[\\textbf{C.}] $\\sin k$\n\t\t\\task[\\textbf{D.}] $i k$\n\t\\end{tasks}\n\t\\item The Laplace transform of $6 t^{3}+3 \\sin 4 t$ is\n\t{\\exyear{NET/JRF(JUNE-2015)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{36}{s^{4}}+\\frac{12}{s^{2}+16}$\n\t\t\\task[\\textbf{B.}] $\\frac{36}{s^{4}}+\\frac{12}{s^{2}-16}$\n\t\t\\task[\\textbf{C.}] $\\frac{18}{s^{4}}+\\frac{12}{s^{2}-16}$\n\t\t\\task[\\textbf{D.}] $\\frac{36}{s^{3}}+\\frac{12}{s^{2}+16}$\n\t\\end{tasks}\n\t\\item  The Fourier transform of $f(x)$ is $\\tilde{f}(k)=\\int_{-\\infty}^{+\\infty} d x e^{i k x} f(x)$.\n\tIf $f(x)=\\alpha \\delta(x)+\\beta \\delta^{\\prime}(x)+\\gamma \\delta^{\\prime \\prime}(x)$, where $\\delta(x)$ is the Dirac delta-function (and prime denotes derivative), what is $\\tilde{f}(k) ?$\n\t{\\exyear{NET/JRF(DEC-2015)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\alpha+i \\beta k+i \\gamma k^{2}$\n\t\t\\task[\\textbf{B.}] $\\alpha+\\beta k-\\gamma k^{2}$\n\t\t\\task[\\textbf{C.}]  $\\alpha-i \\beta k-\\gamma k^{2}$\n\t\t\\task[\\textbf{D.}] $i \\alpha+\\beta k-i \\gamma k^{2}$\n\t\\end{tasks}\n\t\\item  What is the Fourier transform $\\int d x e^{i l x} f(x)$ of\n\t$$\n\tf(x)=\\delta(x)+\\sum_{n=1}^{\\infty} \\frac{d^{n}}{d x^{n}} \\delta(x)\n\t$$\n\twhere $\\delta(x)$ is the Dirac delta-function?\n\t{\\exyear{NET/JRF(JUNE-2016)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}]  $\\frac{1}{1-i k}$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{1+i k}$\n\t\t\\task[\\textbf{C.}] $\\frac{1}{k+i}$\n\t\t\\task[\\textbf{D.}] $\\frac{1}{k-i}$\n\t\\end{tasks}\n\t\\item The Laplace transform of\n\t$$\n\tf(t)=\\left\\{\\begin{array}{cc}\n\t\\frac{t}{T}, & 0<t<T \\\\\n\t1 & t>T\n\t\\end{array}\\right.\n\t$$\n\tis\n\t{\\exyear{NET/JRF(DEC-2016)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{-\\left(1-e^{-s T}\\right)}{s^{2} T}$\n\t\t\\task[\\textbf{B.}] $\\frac{\\left(1-e^{-s T}\\right)}{s^{2} T}$\n\t\t\\task[\\textbf{C.}] $\\frac{\\left(1+e^{-s T}\\right)}{s^{2} T}$\n\t\t\\task[\\textbf{D.}] $\\frac{\\left(1-e^{s T}\\right)}{s^{2} T}$\n\t\\end{tasks}\n\t\\item The Fourier transform $\\int_{-\\infty}^{\\infty} d x f(x) e^{i k x}$ of the function $f(x)=\\frac{1}{x^{2}+2}$ is\n\t{\\exyear{NET/JRF(DEC-2016)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\sqrt{2} \\pi e^{-\\sqrt{2}|| \\mid}$\n\t\t\\task[\\textbf{B.}] $\\sqrt{2} \\pi e^{-\\sqrt{2 k}}$\n\t\t\\task[\\textbf{C.}] $\\frac{\\pi}{\\sqrt{2}} e^{-\\sqrt{2 k}}$\n\t\t\\task[\\textbf{D.}] $\\frac{\\pi}{\\sqrt{2}} e^{-\\sqrt{2}|k|}$\n\t\\end{tasks}\n\t\\item Consider the differential equation $\\frac{d y}{d t}+a y=e^{-b t}$ with the initial condition $y(0)=0$. Then the Laplace transform $Y(s)$ of the solution $y(t)$ is\n\t{\\exyear{NET/JRF(DEC-2017)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{1}{(s+a)(s+b)}$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{b(s+a)}$\n\t\t\\task[\\textbf{C.}] $\\frac{1}{a(s+b)}$\n\t\t\\task[\\textbf{D.}] $\\frac{e^{-a}-e^{-b}}{b-a}$\n\t\\end{tasks}\n\t\\item  The Fourier transform $\\int_{-\\infty}^{\\infty} d x f(x) e^{i k x}$ of the function $f(x)=e^{-|x|}$\n\t{\\exyear{NET/JRF(JUNE-2018)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $-\\frac{2}{1+k^{2}}$\n\t\t\\task[\\textbf{B.}] $-\\frac{1}{2\\left(1+k^{2}\\right)}$\n\t\t\\task[\\textbf{C.}] $\\frac{2}{1+k^{2}}$\n\t\t\\task[\\textbf{D.}] $\\frac{2}{\\left(2+k^{2}\\right)}$\n\t\\end{tasks}\n\t\\item The function $f(t)$ is a periodic function of period $2 \\pi$. In the range $(-\\pi, \\pi)$, it equals $e^{-t}$. If $f(t)=\\sum_{-\\infty}^{\\infty} c_{n} e^{\\text {int }}$ denotes its Fourier series expansion, the sum $\\sum_{-\\infty}^{\\infty}\\left|c_{n}\\right|^{2}$ is\n\t{\\exyear{NET/JRF(DEC-2019)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 1\n\t\t\\task[\\textbf{B.}] $\\frac{1}{2 \\pi}$\n\t\t\\task[\\textbf{C.}] $\\frac{1}{2 \\pi} \\cosh (2 \\pi)$\n\t\t\\task[\\textbf{D.}]  $\\frac{1}{2 \\pi} \\sinh (2 \\pi)$\n\t\\end{tasks}\n\t\\end{enumerate}\n \\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{B} &2&\\textbf{B}\\\\\\hline \n\t\t3&\\textbf{D} &4&\\textbf{A} \\\\\\hline\n\t\t5&\\textbf{C} &6&\\textbf{B} \\\\\\hline\n\t\t7&\\textbf{B}&8&\\textbf{D}\\\\\\hline\n\t\t9&\\textbf{A}&10&\\textbf{C}\\\\\\hline\n\t\t11&\\textbf{D} &&\\textbf{}\\\\\\hline\n\t\t\n\t\\end{tabular}\n\\end{table}\n\n\\newpage\n\\begin{abox}\n\tPractise Set-2\n\\end{abox}\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\n\\item If $f(x)=\\left\\{\\begin{array}{ll}0 & \\text { for } x<3, \\\\ x-3 & \\text { for } x \\geq 3\\end{array}\\right.$ then the Laplace transform of $f(x)$ is\n{\\exyear{GATE 2010}}\n\\begin{tasks}(4)\n\t\\task[\\textbf{A.}] $s^{-2} e^{3 s}$\n\t\\task[\\textbf{B.}] $s^{2} e^{3 s}$\n\t\\task[\\textbf{C.}] $s^{-2}$\n\t\\task[\\textbf{D.}] $s^{-2} e^{-3 s}$\n\\end{tasks}\n\\item The coefficient of $e^{i k x}$ in the Fourier expansion of $u(x)=A \\sin ^{2}(\\alpha x)$ for $k=-2 \\alpha$ is\n{\\exyear{GATE 2017}}\n\\begin{tasks}(4)\n\t\\task[\\textbf{A.}] $\\frac{A}{4}$\n\t\\task[\\textbf{B.}] $\\frac{-A}{4}$\n\t\\task[\\textbf{C.}] $\\frac{A}{2}$\n\t\\task[\\textbf{D.}] $\\frac{-A}{2}$\n\\end{tasks}\n\\item Given the fundamental constants $\\hbar$ (Planck's constant), $G$ (universal gravitation constant) and $c$ (speed of light), which of the following has dimension of length?\n{\\exyear{JEST 2014}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{A.}]$\\sqrt{\\frac{\\hbar G}{c^{3}}}$\n\t\\task[\\textbf{B.}] $\\sqrt{\\frac{\\hbar G}{c^{5}}}$\n\t\\task[\\textbf{C.}]$\\frac{\\hbar G}{c^{3}}$\n\t\\task[\\textbf{D.}] $\\sqrt{\\frac{\\hbar c}{8 \\pi G}}$\n\\end{tasks}\n\\item The Fourier transform of the function $\\frac{1}{x^{4}+3 x^{2}+2}$ up to proportionality constant is\n{\\exyear{JEST 2017}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{A.}]$\\sqrt{2} \\exp \\left(-k^{2}\\right)-\\exp \\left(-2 k^{2}\\right)$\n\t\\task[\\textbf{B.}]$\\sqrt{2} \\exp (-|k|)-\\exp (-\\sqrt{2}|k|)$\n\t\\task[\\textbf{C.}]$\\sqrt{2} \\exp (-\\sqrt{|k|})-\\exp (-\\sqrt{2|k|})$\n\t\\task[\\textbf{D.}]  $\\sqrt{2} \\exp \\left(-\\sqrt{2} k^{2}\\right)-\\exp \\left(-2 k^{2}\\right)$\n\\end{tasks}\n\\item The function $f(x)=\\cosh x$ which exists in the range $-\\pi \\leq x \\leq \\pi$ is periodically repeated between $x=(2 m-1) \\pi$ and $(2 m+1) \\pi$, where $m=-\\infty$ to $\\infty$. Using Fourier series, indicate the correct relation at $x=0$\n{\\exyear{JEST 2017}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\sum_{n=-\\infty}^{\\infty} \\frac{(-1)^{n}}{1-n^{2}}=\\frac{1}{2}\\left(\\frac{\\pi}{\\cosh \\pi}-1\\right)$\n\t\\task[\\textbf{B.}]$\\sum_{n=-\\infty}^{\\infty} \\frac{(-1)^{n}}{1-n^{2}}=2 \\frac{\\pi}{\\cosh \\pi}$\n\t\\task[\\textbf{C.}]$\\sum_{n=-\\infty}^{\\infty} \\frac{(-1)^{-n}}{1+n^{2}}=2 \\frac{\\pi}{\\sinh \\pi}$\n\t\\task[\\textbf{D.}] $\\sum_{n=1}^{\\infty} \\frac{(-1)^{n}}{1+n^{2}}=\\frac{1}{2}\\left(\\frac{\\pi}{\\sinh \\pi}-1\\right)$\n\\end{tasks}\n\\item The Laplace transform of $\\frac{(\\sin (a t)-a t \\cos (a t))}{\\left(2 a^{3}\\right)}$ is\n{\\exyear{JEST 2018}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{A.}]$\\frac{2 a s}{\\left(s^{2}+a^{2}\\right)^{2}}$\n\t\\task[\\textbf{B.}]$\\frac{s^{2}-a^{2}}{\\left(s^{2}+a^{2}\\right)^{2}}$\n\t\\task[\\textbf{C.}]$\\frac{1}{(s+a)^{2}}$\n\t\\task[\\textbf{D.}] $\\frac{1}{\\left(s^{2}+a^{2}\\right)^{2}}$\n\\end{tasks}\n\\end{enumerate}\n \\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{D} &2&\\textbf{B}\\\\\\hline \n\t\t3&\\textbf{A} &4&\\textbf{B} \\\\\\hline\n\t\t5&\\textbf{D} &6&\\textbf{D} \\\\\\hline\n\t\t\n\t\\end{tabular}\n\\end{table}\n\\newpage\n\\begin{abox}\n\tPractise Set-3\n\\end{abox}\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\n\t\\item  Find the fourier series to represent the function $f(x)$ given by\n\t$$\n\tf(x)=\\left[\\begin{array}{ll}\n\t-k & \\text { for }-\\pi<x<0 \\\\\n\tk & \\text { for } 0<x<\\pi\n\t\\end{array}\\right.\n\t$$\n\thence show that $1-\\frac{1}{3}+\\frac{1}{5}+\\frac{1}{7}+\\ldots \\ldots=\\frac{\\pi}{4}$\n\t\\begin{answer}\n\t\tGiven function is odd in nature, so $a_{0}=0$ and $a_{n}=0$\n\t\t\n\t\t\\begin{align*}\n\t\tb_{n} &=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) \\sin n x d x=\\frac{1}{\\pi}\\left[\\int_{-\\pi}^{0}-k \\sin n x d x+\\int_{0}^{\\pi} k \\sin n x d x\\right] \\\\\n\t\t&=\\frac{1}{\\pi} k\\left\\lbrace \\left[ \\frac{\\cos n x}{n}\\right] _{-\\pi}^{0}-\\left[ \\frac{\\cos n x}{n}\\right] _{0}^{\\pi}\\right\\rbrace  \\\\\n\t\t&=\\frac{1}{\\pi} k\\left\\lbrace \\frac{1}{n}-\\frac{(-1)^{n}}{n}-\\frac{(-1)^{n}}{n}+\\frac{1}{n}\\right\\rbrace =\\frac{1}{\\pi} k\\left[\\frac{2}{n}-\\frac{2(-1)^{n}}{n}\\right\\rbrace \\\\\n\t\t\\text{If $n$ is even}\\ b_{n}&=0\\\\\n\t\\text{\tIf $\\mathrm{n}$ is odd }\\ b_{n}&=\\frac{4 k}{n \\pi}\\\\\n\tf(x)&=\\frac{4 k}{\\pi} \\sin x+\\frac{4 k}{3 \\pi} \\sin 3 x+\\frac{4 k}{5 \\pi} \\sin 5 x+\\cdots\\\\\n\tf(x)&=\\frac{4 k}{\\pi}\\left[\\sin x+\\frac{1}{3} \\sin 3 x+\\frac{1}{5} \\sin 5 x+\\ldots\\right]\\\\\n\t\\text { At}\\ x&=\\frac{\\pi}{2} \\\\\n\tk&=\\frac{4 k}{\\pi} \\left[  \\sin \\frac{\\pi}{2}+\\frac{1}{3} \\sin \\frac{3 \\pi}{2} +\\frac{1}{5} \\sin \\frac{5 \\pi}{2}\\right]   \\\\\n\t1&=\\frac{4}{\\pi}\\left[1+\\frac{1}{3}(-1)+\\frac{1}{5}(1)+\\frac{1}{7}(-1)+\\ldots \\cdots\\right]\\\\&=\\frac{4}{\\pi}\\left[1-\\frac{1}{3}+\\frac{1}{5}-\\frac{1}{7}+\\ldots . .\\right] \\\\ \\frac{\\pi}{4}&=1-\\frac{1}{3}+\\frac{1}{5}-\\frac{1}{7}+\\ldots \\ldots\n\t\t\\end{align*}\n\t\n\t\t\n\t\\end{answer} \n\n\\item Find the fourier series of the function defined as\n$$\nf(x)=\\left\\{\\begin{array}{ll}\n \\left.  \\right. \\ x+\\pi, & \\text { for } 0 \\leq x \\leq \\pi \\\\\n-x-\\pi, & \\text { for }-\\pi \\leq x<0\n\\end{array} \\text { and } f(x+2 \\pi)=f(x)\\right.\n$$\t\n\\begin{answer}\n\t\\begin{align*}\n\t\ta_{0} &=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) d x=\\frac{1}{\\pi} \\int_{-\\pi}^{0} f(x) d x+\\frac{1}{\\pi} \\int_{0}^{\\pi} f(x) d x \\\\\n\t\t&=\\frac{1}{\\pi} \\int_{-\\pi}^{0}(-x-\\pi) d x+\\frac{1}{\\pi} \\int_{0}^{\\pi}(x+\\pi) d x\\\\&=\\frac{1}{\\pi}\\left(-\\frac{x^{2}}{2}-\\pi x\\right)_{-\\pi}^{0}+\\frac{1}{\\pi}\\left(\\frac{x^{2}}{2}+\\pi x\\right)_{0}^{\\pi} \\\\\n\t\t&=\\frac{1}{\\pi}\\left(\\frac{\\pi^{2}}{2}-\\pi^{2}\\right)+\\frac{1}{\\pi}\\left(\\frac{\\pi^{2}}{2}+\\pi^{2}\\right)\\\\&=\\pi\\left(\\frac{1}{2}-1\\right)+\\pi\\left(\\frac{1}{2}+1\\right)\\\\&=\\pi\n\t\\end{align*}\n\t\\begin{align*}\n\t\ta_{n} &=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) \\cos n x d x\\\\&=\\frac{1}{\\pi} \\int_{-\\pi}^{0} f(x) \\cos n x d x+\\frac{1}{\\pi} \\int_{0}^{\\pi} f(x) \\cos n x d x \\\\\n\t\t&=\\frac{1}{\\pi} \\int_{-\\pi}^{0}(-x-\\pi) \\cos n x d x+\\frac{1}{\\pi} \\int_{0}^{\\pi}(x+\\pi) \\cos n x d x \\\\\n\t\t&=\\frac{1}{\\pi}\\left[(-x-\\pi) \\frac{\\sin n x}{n}-(-1)\\left\\{-\\frac{\\cos n x}{n^{2}}\\right\\}\\right]_{-\\pi}^{0}+\\frac{1}{\\pi}\\left[(x+\\pi) \\frac{\\sin n x}{n}-(1)\\left\\{-\\frac{\\cos n x}{n^{2}}\\right\\}\\right]_{0}^{\\pi}\\\\\n\t\t&=\\frac{1}{\\pi}\\left[-\\frac{1}{n^{2}}+\\frac{(-1)^{n}}{n^{2}}\\right]+\\frac{1}{\\pi}\\left[\\frac{(-1)^{n}}{n^{2}}-\\frac{1}{n^{2}}\\right]=\\frac{2}{n^{2} \\pi}\\left[(-1)^{n}-1\\right]\\\\\n\t\t&=\\frac{-4}{n^{2} \\pi}\\quad \\text{if $n$ is odd}\\\\\n\t\t&=0 \\quad \\text{if $n$ is even}\n\t\\end{align*}\n\t\\begin{align*}\n\t\tb_{n} &=\\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) \\sin n x d x=\\frac{1}{\\pi} \\int_{-\\pi}^{0} f^{\\prime}(x) \\sin n x d x+\\frac{1}{\\pi} \\int_{0}^{\\pi} f(x) \\sin n x d x \\\\\n\t\t&=\\frac{1}{\\pi} \\int_{-\\pi}^{0}(-x-\\pi) \\sin n x d x+\\frac{1}{\\pi} \\int_{0}^{\\pi}(x+\\pi) \\sin n x d x \\\\\n\t\t&=\\frac{1}{\\pi}\\left[(-x-\\pi)\\left(\\frac{-\\cos n x}{n}\\right)-(-1)\\left(-\\frac{\\sin n x}{n^{2}}\\right)\\right]_{-\\pi}^{0}+\\frac{1}{\\pi}\\left[(x+\\pi)\\left(-\\frac{\\cos n x}{n}\\right)-(1)\\left(-\\frac{\\sin n x}{n^{2}}\\right)\\right]_{0}^{\\pi} \\\\\n\t\t&=\\frac{1}{\\pi}\\left[\\frac{\\pi}{n}\\right]+\\frac{1}{\\pi}\\left[-\\frac{2 \\pi}{n}(-1)^{n}+\\frac{\\pi}{n}\\right]=\\frac{1}{n}\\left[(1)-2(-1)^{n}\\right]=\\frac{2}{n}\\left[1-(-1)^{n}\\right]\\\\\n\t\t&=\\frac{4}{n}\\quad \\text{if $n$ is odd}\\\\\n\t\t&=0 \\quad \\text{if $n$ is even}\n\t\\end{align*}\n\tThe fourier series expansion of the function is\n\t\\begin{align*}\n\tf(x)&=\\frac{a_{0}}{2}+a_{1} \\cos x+a_{2} \\cos 2 x+\\ldots+b_{1} \\sin x+b_{2} \\sin 2 x+\\ldots \\\\\n\tf(x)&=\\frac{\\pi}{2}-\\frac{4}{\\pi}\\left(\\frac{\\cos x}{1^{2}}+\\frac{\\cos 3 x}{3^{2}}+\\ldots . .\\right)+4\\left(\\frac{\\sin x}{1}+\\frac{\\sin 3 x}{3}+\\ldots\\right)\n\t\\end{align*}\n\t\n\\end{answer}\n\\item  Find the Fourier sine series for the function\n$$\nf(x)=e^{a x} \\quad \\text { for }-\\pi \\leq x \\leq \\pi\n$$\nwhere $a$ is constant.\n\\begin{answer}\n\t\\begin{align*}\n\t\t\\int e^{a x} \\sin b x d x&=\\frac{e^{a x}}{a^{2}+b^{2}}[a \\sin b x-b \\cos b x] \\\\\n\t\tb_{n}&=\\frac{2}{\\pi} \\int e^{a x} \\sin n x d x \\\\\n\t\t&=\\frac{2}{\\pi}\\left[\\frac{e^{a x}}{a^{2}+n^{2}}(a \\sin n x-n \\cos n x)\\right]_{0}^{\\pi} \\\\\n\t\t&=\\frac{2}{\\pi}\\left[\\frac{e^{a \\pi}}{a^{2}+n^{2}}(a \\sin n \\pi-n \\cos n \\pi)+\\frac{n}{a^{2}+n^{2}}\\right] \\\\\n\t\t&=\\frac{2}{\\pi}\\left(\\frac{n}{a^{2}+n^{2}}\\right)\\left[-(-1)^{n} e^{a \\pi}+1\\right]\\\\&=\\frac{2 n}{\\left(a^{2}+n^{2}\\right) \\pi}\\left[1-(-1)^{n} e^{a \\pi}\\right] \\\\\\\\\n\t\tb_{1}&=\\frac{2\\left(1+e^{a \\pi}\\right)}{\\left(a^{2}+1^{2}\\right) \\pi} \\quad ; \\quad b_{2}=\\frac{2 \\cdot 2 \\cdot\\left(1-e^{a \\pi}\\right)}{\\left(a^{2}+2^{2}\\right) \\pi} \\\\\\\\\n\t\te^{a x}&=\\frac{2}{\\pi}\\left[\\frac{1+e^{a \\pi}}{a^{2}+1^{2}} \\sin x+\\frac{2\\left(1-e^{a \\pi}\\right)}{a^{2}+2^{2}} \\sin 2 x+\\ldots .\\right]\n\t\\end{align*}\n\\end{answer}\n\\item Obtain the half range cosine series for $\\mathrm{f}(\\mathrm{x})=(\\mathrm{x}-2)^{2}$ in the interval $(0,2)$.\n\\begin{answer}\n\t$f(x)=(x-2)^{2}$\n\tWe know that the Fourier half range cosine series is\n\t$$\n\tf(x)=\\frac{a_{0}}{2}+\\sum_{n=1}^{\\infty} a_{n} \\cos \\frac{n x \\pi}{l}\n\t$$\n\n\t\n\t\\begin{align*}\n\t\\text { Where } \\\\\n\ta_{0}&=\\frac{2}{l} \\int_{0}^{l} f(x) d x \\\\\n\ta_{n}&=\\frac{2}{l} \\int_{0}^{l} f(x) \\cos \\frac{n \\pi x}{l} d x\n\t\\end{align*}\n\n\tHere $l=2$\n\t\\begin{align*}\n\ta_{0}&=\\frac{2}{2} \\int_{0}^{2}(x-2)^{2} d x=\\left[\\frac{(x-2)^{3}}{3}\\right]_{0}^{2}\\\\\n\t&=\\left[0-\\frac{(-2)^{3}}{3}\\right]=\\frac{8}{3} \\\\\n\ta_{0}&=\\frac{8}{3}\\\\\n\ta_{n}&=\\frac{2}{2} \\int_{0}^{2}(x-2)^{2} \\cos \\frac{n \\pi x}{2} d x \\\\\n\ta_{n}&=\\left[(x-2)^{2}\\left(\\frac{\\sin \\frac{n \\pi x}{2}}{\\frac{n \\pi}{2}}\\right)-2(x-2)\\left(\\frac{-\\cos \\frac{n \\pi x}{2}}{\\frac{n^{2} \\pi^{2}}{2^{2}}}\\right)+2\\left(\\frac{-\\sin \\frac{n \\pi x}{2}}{\\frac{n^{3} \\pi^{3}}{2^{3}}}\\right)\\right]_{0}^{2} \\\\\n\ta_{n}&=\\left[0+0-2 \\frac{8}{n^{3} \\pi^{3}} \\sin n \\pi-0-2(-2) \\frac{4}{n^{2} \\pi^{2}}+0\\right] \\\\\n\ta_{n}&=\\frac{8}{n^{2} \\pi^{2}}\n\t\\end{align*}\n\n\n\t$$\n\t\\begin{array}{l}\n\tf(x)=\\frac{8}{2 x^3}+\\sum_{n=1}^{\\infty} \\frac{8}{n^{2} \\pi^{2}} \\cos \\frac{n x \\pi}{2} \\\\\\\\\n\tf(x)=\\frac{4}{3}+\\frac{8}{\\pi^{2}} \\sum_{n=1}^{\\infty} \\frac{1}{n^{2}} \\cos \\frac{n x \\pi}{2}\n\t\\end{array}\n\t$$\n\\end{answer}\n\\end{enumerate}\n\n\n\n\n\n", "meta": {"hexsha": "01b82e4528523d7a9b5ee3c1089c86e095860aee", "size": 26395, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/fourier.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CSIR- Mathematical Physics/chapter/fourier.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CSIR- Mathematical Physics/chapter/fourier.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.5651340996, "max_line_length": 926, "alphanum_fraction": 0.5689713961, "num_tokens": 12062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7017066443994553}}
{"text": "\n\\documentclass[12pt]{amsart}\n\\usepackage{amssymb,amsmath}\n\\usepackage{graphicx}\n\\usepackage{geometry} % see geometry.pdf on how to lay out the page. There's lots.\n\\geometry{a4paper} % or letter or a5paper or ... etc\n% \\geometry{landscape} % rotated page geometry\n\n\\newcommand{\\bigzero}{\\mbox{\\normalfont\\Large\\bfseries 0}}\n\\newcommand{\\rvline}{\\hspace*{-\\arraycolsep}\\vline\\hspace*{-\\arraycolsep}}\n\n\n% See the ``Article customise'' template for come common customisations\n\n\\title{Visualizing Grover's Search Algorithm}\n\\author{James Weaver \\& Paul Kassebaum}\n\\date{} % delete this line to display the current date\n\n%%% BEGIN DOCUMENT\n\\begin{document}\n\n\\maketitle\n\n\\section{Oracle operators}\n\nIf we want an operator $U_x$ with the following behavior\n\n\\begin{equation}\n\t\\begin{split}\n\t\tU_x |x\\rangle & = - |x\\rangle \\\\\n\t\tU_x |x_\\perp\\rangle & = |x_\\perp\\rangle \n\t\\end{split}\n\\end{equation}\n\nwhere all $|x_\\perp\\rangle$ are orthogonal to $|x\\rangle$, then the operator takes the form\n\n\\begin{equation}\n\tU_x = I - 2 |x\\rangle\\langle x|\n\\end{equation}\n\nLet's demonstrate this with a couple of examples.\n\n\\begin{equation}\n\t\\begin{split}\n\t\tU_x |x\\rangle & = (I - 2 |x\\rangle\\langle x| ) |x\\rangle \\\\\n\t\t& = |x\\rangle - 2 |x\\rangle\\langle x | x\\rangle \\\\\n\t\t& = |x\\rangle - 2 |x\\rangle \\\\\n\t\t& = - |x\\rangle\n\t\\end{split}\n\\end{equation}\n\nbecause $\\langle x | x\\rangle = 1$.\n\n\\begin{equation}\n\t\\begin{split}\n\t\tU_x |x_\\perp\\rangle & = (I - 2 |x\\rangle\\langle x| ) |x_\\perp\\rangle \\\\\n\t\t& = |x_\\perp\\rangle - 2 |x\\rangle\\langle x | x_\\perp\\rangle \\\\\n\t\t& = |x_\\perp\\rangle - 2 \\langle x | x_\\perp\\rangle  |x_\\perp\\rangle \\\\\n\t\t& = |x_\\perp\\rangle\n\t\\end{split}\n\\end{equation}\n\nbecause $\\langle x | x_\\perp\\rangle = 0$.\n\nNow let's look at the result of acting on an arbitrary state $|\\alpha\\rangle$, that is not completely orthogonal to $|x\\rangle$.\n\n\\begin{equation}\n\t\\begin{split}\n\t\tU_x |\\alpha\\rangle & = (I - 2 |x\\rangle\\langle x| ) |\\alpha\\rangle \\\\\n\t\t& = |\\alpha\\rangle - 2 |x\\rangle\\langle x | \\alpha\\rangle \\\\\n\t\t& = (1 - 2 \\langle x | \\alpha\\rangle)  |\\alpha\\rangle \\\\\n\t\\end{split}\n\\end{equation}\n\nIn words, the result is the original state vector minus twice the overlap or projection of $|\\alpha\\rangle$ on $|x\\rangle$. We can draw this out geometrically.\n\\begin{figure}[h]\n   \\centering\n   \\includegraphics[width=0.5\\textwidth]{./img/fig-00} % requires the graphicx package\n   \\caption{Geometric demonstration that the operator $U_x$ has the effect of reflecting $|\\alpha\\rangle$ across $|x_\\perp\\rangle$, the vector orthogonal to $|x\\rangle$.}\n   \\label{fig:example}\n\\end{figure}\n\n\n\n\n\\section{Symmetries of a single qubit system}\nA single qubit's state $|s\\rangle$ \n\n\\begin{equation}\n\t|s\\rangle = (a+ib)|0\\rangle + (c + id)|1\\rangle\n\\end{equation}\n\nwritten in terms of the 4 real numbers $a,b,c,d$ can be fully described by 3 real numbers, since the state must be normalized,\n\n\\begin{equation}\n\t\\langle s | s\\rangle = a^2 + b^2 + c^2 + d^2 = 1,\n\\end{equation}\n\nwhich makes one of the real numbers dependent on the other three.\n\nA single qubit's rotational symmetries can be described by the matrices\n\n\\begin{equation}\n\t\\begin{pmatrix}\n\t\ta + i b & -(c - id) \\\\\n\t\tc + id & -(a + i b)\n\t\\end{pmatrix}\n\\end{equation}\n\nwhere $a,b,c,d$ are real numbers. The normalization condition on the state of the qubit requires that the determinant of this matrix be 1. \n\nAnother way to describe a single qubit's rotational symmetries is by the quaternion:\n\n\\begin{equation}\n\ta +bi + cj + dk\n\\end{equation}\n\nwhere the real numbers $a,b,c,d$ of the matrix and quaternion are equal respectively. The determinant of the matrix is the norm of the corresponding quaternion. Since the matrix has determinant 1 as a consequence of the normalization condition of the qubit's state, the corresponding quaternion has norm 1.\n\n\n\\section{Symmetries of a two qubit system}\n\nA system of two qubits can be described by $2\\times3 = 6$ real numbers. The system transforms as the tensor product of two independent matrices that each describe a single qubit, as explained above.\n\n\\begin{equation}\n\t\\begin{pmatrix}\n  \\begin{matrix}\n  i a & -\\bar{z} \\\\\n  z & - i a\n  \\end{matrix}\n  & \\rvline & \\bigzero \\\\\n\\hline\n  \\bigzero & \\rvline &\n  \\begin{matrix}\n  i b & -\\bar{w} \\\\\n  w & -i b\n  \\end{matrix}\n\\end{pmatrix}\n\\end{equation}\n\nwhere $a,b$ are real numbers and $z,w$ are complex numbers. The numbers $a,z,b,w$ are made up of 6 independent real numbers. Each of the two block matrices can be related to independent quaternions.\n\nThe dynamics of a two qubit system can be thought of geometrically in 4D euclidean space where each of the two quaternions is acted upon independently by operators associated with each spin respectively.\n\n\n\n\n\\end{document}", "meta": {"hexsha": "dc77dbfb5ccff883be9aebd94d0405aa073b103f", "size": 4705, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "grovers.tex", "max_stars_repo_name": "derivation/visualizing_quantum_algorithms", "max_stars_repo_head_hexsha": "d034bdb5761f7dd562001e76a1b6c0d5f694e59f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "grovers.tex", "max_issues_repo_name": "derivation/visualizing_quantum_algorithms", "max_issues_repo_head_hexsha": "d034bdb5761f7dd562001e76a1b6c0d5f694e59f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "grovers.tex", "max_forks_repo_name": "derivation/visualizing_quantum_algorithms", "max_forks_repo_head_hexsha": "d034bdb5761f7dd562001e76a1b6c0d5f694e59f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7905405405, "max_line_length": 306, "alphanum_fraction": 0.7049946865, "num_tokens": 1477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7017066443994553}}
{"text": "\\chapter{Luminosity Calculation}\n\\label{lumi} \n\n\nThe probability of n interactions per bunch crossing is ( because a collision is a random process, the distribution will follow Poisson statistics.\n\\begin{equation}\nP = \\frac{\\mu^{N}}{N!} \\times e^{-\\mu}\n\\end{equation}\nThe probability of at least one bunch crossing is\n\\begin{equation}\nP = 1 -  e^{-\\mu}\n\\end{equation}\nThe average number of bunch crossings, $\\mu$, is defined as\n\\begin{equation}\n\\mu = \\frac{\\mathcal{L} \\times \\sigma_{\\rm{eff}}}{f_{\\rm{beam}}}\n\\end{equation}\nThus, the luminosity can be written as \n\\begin{equation}\n\\mathcal{L} = - \\frac{f_{\\rm{beam}}}{\\sigma_{\\rm{eff}}} \\rm{ln}(1-P(n>0))\n\\end{equation}\nBy recording the number of bunch crossings without an inelastic collision, the luminosity can be calculated.\n\n", "meta": {"hexsha": "f75e23437f13167fdc0f6467f3e994ae8d8b1721", "size": 781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Luminosity.tex", "max_stars_repo_name": "tgadf/thesis", "max_stars_repo_head_hexsha": "19d4a6bc7f7ac8660fce582322703d50e0d6bd31", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Luminosity.tex", "max_issues_repo_name": "tgadf/thesis", "max_issues_repo_head_hexsha": "19d4a6bc7f7ac8660fce582322703d50e0d6bd31", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Luminosity.tex", "max_forks_repo_name": "tgadf/thesis", "max_forks_repo_head_hexsha": "19d4a6bc7f7ac8660fce582322703d50e0d6bd31", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.9565217391, "max_line_length": 147, "alphanum_fraction": 0.7195902689, "num_tokens": 241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.959762055074521, "lm_q2_score": 0.7310585669110202, "lm_q1q2_score": 0.701642272558355}}
{"text": "\\chapter{Introduction}\nIn this course we will be concerned with ordinary differential equations, ODEs.\n\n\\begin{defin}\nAn ordinary differential equation (ODE) is a differential equation containing one or more functions of \\underline{\\textbf{exactly one}} independent variable and its derivatives.\n\\end{defin}\n\nODEs relate the change of one variable to changes in another variable and can be used to model and understand a wide variety of phenomena, such as projectile motion, animal population interactions and the progression of chemical reactions.\n\nIn these notes we consider two important aspects in the theory of ordinary differential equations. Specifically, we seek to\n\\begin{enumerate}\n\\item develop methods of modelling physical phenomena;\n\\item understand the properties of the equations without explicitly solving them.\n\\end{enumerate}\n\nPoint 2 may seem counter-intuitive as we have a variety of techniques that enable us to solve ODEs in closed form. Further, even if an explicit solution is not available, we can use numerical simulations to illustrate the dynamics of the ODEs. However, direct solutions are not always possible and, even when they are, they may not always enable clear interpretations and understanding of the underlying system. Equally, our analytical techniques will give us confidence in the solutions produced by numerical software.\n\nCritically, what we gain in analytical specificity, we lose in global accuracy. Namely, we are going to learn techniques that will allow us to rigorously examine small regions of the ODE space at the expense of losing knowledge of the global dynamics. However, by the end of the course we will be able to patch together multiple parts of the local analysis in order to give us an approximate understanding of the entire dynamical system.\n\n\\section{Preliminary definitions}\nWe will be considering the rate of change of a variable, $u$, with respect to another variable, $t$. This dependence will be denoted\n\\bb\nu(t).\n\\ee\nHere, $u$ is a scalar function (\\ie one-dimensional), but more generally, we will be considering systems of variables\n\\bb\n\\bm{u}(t)=\\l u_1(t),u_2(t),\\dots,u_k(t)\\r.\n\\ee\nOn the board we will usually write bold symbols with an underline\\footnote{I was once told that we use underlines to illustrate bold variables because when typesetting a document an underline would tell the printer that that symbol needed to be bold. However, if this is true, how did the writer indicate that they wanted a symbol underlined?} as it is easier to see, thus, $\\bm{u}=\\underline{u}$.\n\nThe values of $u$ or $\\bm{u}$ define quantities of interest. For example they could be an animal population density, a distance or a speed. Further, $t$ can be any variable which these quantities are dependent on. Generally, however, we will take $t$ to be time and we will be considering how these values temporally evolve.\n\nIn order to link the changes in these quantities we define a system of ODEs in the most general way possible,\n\\bb\n\\bm{F}\\l t,\\bm{u},\\frac{\\rd \\bm{u}}{\\rd t},\\frac{\\rd^2 \\bm{u}}{\\rd t^2},\\dots,\\frac{\\rd^n \\bm{u}}{\\rd t^n}\\r=0,\n\\ee\nwith initial condition given by\n\\bb\n\\bm{u}(0)=\\bm{u}_0.\n\\ee\nNote that the initial condition is kept general as we will usually be interested in how the dynamics of the system change for different starting points.\n\n\\begin{example}[frametitle=Bacteria population growth]\n\\label{Expo_growth}\n\\COL{In this case we are only considering one population, thus, $\\bm{u}=u$ and we specify $u(t)$ to be the population of E.Coli at time $t$. Initially, the population is $u_0$ and resources are abundant, thus, each E.Coli is able to double itself at a rate $r$/s. Explicitly, the population grows at a rate proportional to the population already present, \\ie\n\\bb\n\\frac{\\rd u}{\\rd t}=ru.\n\\ee\nThis equation can be trivially solved to give\n\\bb\nu(t)=u_0\\exp(rt),\\label{Intro_exp}\n\\ee\nsee \\fig{Exponential}.\n\nNote instead of specifying the time at which a population takes an arbitrary value, we can consider the more general time scale of how long does it take the population to double? Namely, at what point, $t_2$, is $u(t_2)=2u_0$. Rearranging \\eqn{Intro_exp} we derive that\n\\bb\nt_2=\\frac{1}{r}\\log\\l 2\\r.\n\\ee\n\nCritically, once a model is constructed and an answer is found, we must consider whether if it is a good model or not. Clearly this model has problems because it predicts the population will grow exponentially quickly, without bound. The key problematic assumption that we have made is that the resources (\\eg space, nutrients, etc.) do not run out. Although this may be a fine assumption to begin with, eventually the bacteria will be limited by competition.}\n%\\begin{figure}[!!!h!!!tb]\n{\\centering\n\\includegraphics[width=\\textwidth]{../Pictures/Bacteria.png}}\n%\\end{figure}\n\\end{example}\n\n\n\\begin{example}[frametitle=Bacteria and nutrient populations.]\\label{Logi_growth}\n\\COL{Imagine a case similar to the one above, but we introduce a nutrient population, $v$. We assume that a bacterium can divide at a rate $r$ if and only if it can interact with enough nutrient. However, the nutrient is depleted at a rate $r$ as the bacteria interacts with it.\n\nHere, the equation governing this system is going to be provided. However, later on we will learn how to write down and interpret interaction equations of the form\n\\bb\nu+v \\stackrel{r}{\\longrightarrow} 2u.\n\\ee\n\nThe governing equations are\n\\begin{align}\n\\frac{\\rd u}{\\rd t}&=ruv,\\quad u(0)=u_0,\\label{Pop_u}\\\\\n\\frac{\\rd v}{\\rd t}&=-ruv,\\quad v(0)=v_0.\n\\end{align}}\n\\COL{We notice that we can add the two equations and integrate to provide a conserved quantity,\n\\bb\nu+v=c.\\label{Conserved_c}\n\\ee\nWe can substitute \\eqn{Conserved_c} into \\eqn{Pop_u} to get\n\\bb\n\\frac{\\rd u}{\\rd t}=ru(c-u).\\label{Log_1}\n\\ee\nThis is known as the logistic equation and we will see it many times throughout these notes, it is a simple example of competition between species for resources.}\n\n\\COL{Using partial fractions, we can directly solve \\eqn{Log_1}. Specifically,\n\\begin{align}\n\\frac{\\rd u}{\\rd t}&=rcu\\l 1-\\frac{u}{c}\\r,\\nonumber\\\\\n\\Rightarrow\\int_0^T\\frac{\\rd u}{u(1-u/c)}&=\\int_0^Trc \\rd t,\\nonumber\\\\\n\\Rightarrow\\int_0^T \\frac{1}{u}+\\frac{1/c}{1-u/c}  \\rd u&=rcT,\\nonumber\\\\\n\\Rightarrow\\left[\\ln(u)-\\ln\\l 1- \\frac{u}{c} \\r \\right]^T_0&=rcT,\\nonumber\\\\\n\\Rightarrow\\ln\\l\\frac{u}{1- \\frac{u}{c}} \\r-\\ln\\l\\frac{u_0}{1- \\frac{u_0}{c}} \\r&=rcT,\\nonumber\\\\\n\\Rightarrow u(T)=\\frac{c}{1+\\frac{c-u_0}{u_0}\\exp\\l{-rcT}\\r},\n\\end{align}\nsee \\fig{Logistic}.\n\nComparing the models of bacteria growth, illustrated in \\fig{Growth_examples}, we see that \\eqn{Log_1} is a more realistic model for growth because there is a maximum population value which can be supported by the experiment. This maximum value is given by $c$ and is known as the carrying capacity. The parameter grouping $rc$ is also important as this control the time scale over which this maximum is obtained.}\n\\end{example}\n\\begin{figure}[!!!h!!!tb]\n{\\centering\n\\subfigure[\\label{Exponential}]{\\includegraphics[width=\\ttp]{../Pictures/Exponential.png}}\n\\subfigure[\\label{Logistic}]{\\includegraphics[width=\\ttp]{../Pictures/Logistic.png}}\n\\caption{(a) Exponential growth. Parameters are $r=u_0=0.1$. See example \\ref{Expo_growth}. (b) Logistic growth. Parameters are $c=10$, $r=u_0=0.1$. See example \\ref{Logi_growth}.}\\label{Growth_examples}}\n\\end{figure}\n\n\n\\begin{example}[frametitle=Duffing's equations.]\\label{Duffing_example}\nFor our last example, consider the Duffing oscillator. The equation is simply a toy example that can be used to examine complex phenomena in a simple equation. In terms of interpretation, you can think of the equation as modelling the displacement of a beam near two magnetics. Critically, the beam and magnets are being forced to oscillate with amplitude $\\gamma$ and frequency $\\omega$ \\see{Duffing_beam}.\n\\bb\n\\underbrace{\\frac{\\rd^2 x}{\\rd t^2}}_{\\textrm{Acceleration}}+\\underbrace{2\\delta\\frac{\\rd x}{\\rd t}}_{\\textrm{Air resistance}}+\\underbrace{\\beta x+\\alpha x^3}_{\\textrm{Beam's restorative force}}=\\underbrace{\\gamma\\cos(\\omega t)}_{\\textrm{Forcing term}}.\\label{Duffing_eqn}\n\\ee\n\nWe are not going to try and analytically solve or analyse Duffing's equation. Instead, we illustrate the dynamics that the equation produces as the amplitude of oscillation, $\\gamma$, increases. Specifically, as $\\gamma$ is increased the system becomes chaotic \\see{Duffing_equation}.\n\\end{example}\n\\begin{figure}[!!!h!!!tbp]\n\\centering\n\\subfigure[\\label{Duffing_beam}]{\\includegraphics[width=.3\\textwidth]{../Pictures/Duffing_beam.png}}\n\\subfigure[\\label{Duffing_equation}]{\\includegraphics[width=\\textwidth]{../Pictures/Duffing.png}}\n\\caption{\\label{Duffing}(a) Schematic diagram of the system underlying Duffing's equation. (b) Three simulations of \\eqn{Duffing_eqn} with increasing values of $\\gamma$.}\n\\end{figure}\n\n\\begin{defin}\nThe \\textbf{order} of a differential equation is the value of the highest derivative in the equation.\n\\end{defin}\nExamples \\ref{Logi_growth} and \\ref{Expo_growth} are both first order equations, whilst example \\ref{Duffing_example} is a second order equation. Generally (like polynomial equations of order) a differential equation of order $n$ will have $n$ linearly independent solutions.\n\n\\begin{defin}\nA system of differential equations is \\textbf{autonomous} if the system does not explicitly depend on the independent variable.\n\\end{defin}\nWhen the variable is time, they are also called time-invariant systems, this simply means that we are assuming that the defined underlying laws of the system are identical to those for any point in the past, or future.\n\n\\begin{defin}\nTo save time we use a dot or prime mark to denote a derivative with respect to the argument, thus,\n\\bb\n\\dot{\\bm{u}}(t)=\\bm{u}'(t)=\\frac{\\rd \\bm{u}}{\\rd t}.\n\\ee\n\\end{defin}\nTraditionally, dots are primarily used when the variable is time and primes are used otherwise. Note that higher orders derivatives are signified by the appropriate number of dots or primes. Namely, a second derivative would be denoted by two dots or primes, etc.\n\n\\begin{defin}\nA \\textbf{trajectory} is a solution, $u(t)$.\n\\end{defin}\nThe graphs in \\figs{Growth_examples}{Duffing} illustrate single trajectories of their respective systems.\n\n\n\nIn this course we are going to occupy ourselves with systems of autonomous first order equations, of the form\n\\bb\n\\frac{\\rd \\bm{u}}{\\rd t}=\\dot{\\bm{u}}=\\bm{F}(\\bm{u}).\\label{ODE}\n\\ee\nThis may seem highly restrictive. However, systems of first order equations can have extremely complicated properties, such as oscillations and chaos, which we will try to understand.\n\n\\COL{Critically, equations of higher order can be written as a system of first order equations. For example, if\n\\bb\n\\bm{G}\\l \\bm{u},\\frac{\\rd \\bm{u}}{\\rd t},\\frac{\\rd^2 \\bm{u}}{\\rd t^2},\\dots,\\frac{\\rd^n \\bm{u}}{\\rd t^n}\\r=0\n\\ee\nthen we can define $n-1$ new equations of the form $\\bm{v}_1=\\rd \\bm{u}/\\rd t$ and $\\bm{v}_i=\\rd \\bm{v}_{i-1}/\\rd t=\\rd^{i} \\bm{u}/\\rd t^{i}$ for $2\\leq i \\leq n-1$ to produce the first order system\n\\begin{align}\n&\\bm{G}\\l \\bm{u},\\bm{v}_1,\\dots,\\bm{v}_{n-1},\\frac{\\rd \\bm{v}_{n-1}}{\\rd t}\\r=0,\\\\\n&\\frac{\\rd \\bm{u}}{\\rd t}=\\bm{v}_1,\\\\\n&\\vdots\\nonumber\\\\\n&\\frac{\\rd \\bm{v}_{n-2}}{\\rd t}=\\bm{v}_{n-1}.\n\\end{align}}\n\\begin{example}[frametitle=Duffing's equations without forcing.]\\label{Duffing_example2}\n\\COL{Setting $\\gamma=0$ in Duffing's equation and letting\n\\bb\nv=\\frac{\\rd x}{\\rd t}\n\\ee\nthen we are able to convert the single second order equation seen in \\eqn{Duffing_equation} to two first}\\COL{ order ODEs,\n\\begin{align}\n\\frac{\\rd v}{\\rd t}&=-2\\delta v-(\\beta x+\\alpha x^3)\\\\\n\\frac{\\rd x}{\\rd t}&=v.\n\\end{align}\nNote that $v$ is an apt variable name for the variable, because, as discussed in example \\ref{Duffing_example}, $x$ can be thought of as position, making $v$ a velocity.}\n\\end{example}\n\\begin{thm}\nA solution trajectory, $\\bm{u}(t)$, of \\eqn{ODE} cannot self-intersect \\see{Trisectrix}.\n\\end{thm}\n\\begin{proof}\n\\COL{Suppose there is an intersection. Hence, there exist two points, $t_1$ and $t_2$, such that $\\bm{u}(t_1)=\\bm{u}(t_2)$ then we will also have that $\\bm{F}(\\bm{u}(t_1))=\\bm{F}(\\bm{u}(t_2))$. However, the curves intersect, thus, the curves must be travelling in different directions at $t_1$ and $t_2$ \\see{Intersect}, meaning that the derivatives are different there, \\ie $\\dot{\\bm{u}}(t_1)\\neq\\dot{\\bm{u}}(t_2)$. But\n\\bb\n\\dot{\\bm{u}}(t_1)=\\bm{F}(\\bm{u}(t_1))=\\bm{F}(\\bm{u}(t_2))=\\dot{\\bm{u}}(t_2),\n\\ee\nwhich produces a contradiction. Hence the curves cannot intersect.}\n\\end{proof}\n\\begin{figure}[!!!h!!!tb]\n\\centering\n\\includegraphics[width=\\ttp]{../Pictures/Trisectrix.png}\n\\caption{\\label{Trisectrix} A solution of \\eqn{ODE} cannot look like this.}\n\\end{figure}\n\n\n\\subsection{Existence and uniqueness}\nWith this being an applied mathematics course we are often very `fast and loose' with our rigour. However, it is good to know that theorems have been proven regarding the existence and unique of solution to \\eqn{ODE}. Here we will quote the theorem in one dimension, but the theorem can be expanded to any number of variables.\n\\begin{thm}Existence-Uniqueness theorem.\n\nSuppose the function $F(u)$ is differentiable and the derivative, $F'(u)$, is continuous for all values of $u$ then there will exist some constant $c>0$ such that\n\\bb\n\\dot{u}=F(u),\\quad u(t_0)=u_0,\n\\ee\nhas a solution and it is guaranteed to exist and be unique in some finite time interval $|t-t_0|<c$.\\label{Existence_Uniqueness}\n\\end{thm}\nNote that:\\COL{\n\\begin{itemize}\n\\item we will not consider the proof here. For those who are interested look up ``Picard's theorem''. Picard's theorem is actually weaker than the one specified above, but theorem \\ref{Existence_Uniqueness} expresses the statement in the most useful form for us.\n\\item in many cases solutions will exist and be unique for all time, but, the theorem hardly ever provides an optimal value for $c$. However, the theorem is general enough to include cases where `blow up' occurs. Namely, blow up occurs when a solution tends to infinity in finite time.\n\\item without loss of generality we can always take $t_0=0$ (why?). \\textbf{This is only true in autonomous systems}.\n\\item solution curves cannot intersect, otherwise there would be two different solutions going through the same point and there would not be uniqueness around the intersection \\see{Intersect}.\n\\item the case for higher dimensional systems is effectively the same except we need the function\n\\bb\n\\bm{F}(\\bm{u})=\\left(\n\\begin{array}{c}\n{F_1}(u_1,u_2,u_3,\\dots,u_n)\\\\\n{F_2}(u_1,u_2,u_3,\\dots,u_n)\\\\\n\\vdots\\\\\n{F_n}(u_1,u_2,u_3,\\dots,u_n)\n\\end{array}\n\\right)\n\\ee to be continuous in all of its derivatives.\n\\end{itemize}}\n\\begin{figure}[!!!h!!!tb]\n\\centering\n\\includegraphics[width=\\ttp]{../Pictures/Intersection.png}\n\\caption{\\label{Intersect}Two different solution curves of a one-dimensional ODE cannot intersect.}\n\\end{figure}\n\n\\begin{defin}\\label{Monotonic_def}\nA differentiable function is \\textbf{monotonic} if its derivative never changes sign. Moreover, the function is monotonically increasing (decreasing) if the derivative is positive (negative).\n\\end{defin}\n\\begin{defin}\\label{Strict_monotonic_def}\nA differentiable function is \\textbf{strictly monotonic} if its derivative never changes sign and is never zero.\n\\end{defin}\nSee \\fig{Monotonics} for examples of definitions \\ref{Monotonic_def} and \\ref{Strict_monotonic_def}.\n\\begin{figure}[!!!h!!!tb]\n\\centering\n\\subfigure[\\label{Non_monotonic}]{\\includegraphics[width=\\tttp]{../Pictures/Non_monotonic.png}}\n\\subfigure[\\label{Monotonic}]{\\includegraphics[width=\\tttp]{../Pictures/Monotonic.png}}\n\\subfigure[\\label{Strictly_monotonic}]{\\includegraphics[width=\\tttp]{../Pictures/Strictly_monotonic.png}}\n\\caption{\\label{Monotonics}(a)\\COL{ A non-monotonic function.} (b) \\COL{A monotonic function.} (c) \\COL{A strictly monotonic function.}}\n\\end{figure}\n\n\n\\begin{cor}\nSuppose $F(u)$ is a scalar function that is continuously differentiable. The solution, $u(t)$, of the one dimensional ODE,\n\\bb\n\\dot{u}=F(u),\\quad u(t_0)=u_0,\n\\ee\ncannot oscillate. Specifically, $u(t)$ must either be constant, or a monotonically increasing, or decreasing function.\n\\end{cor}\n\\begin{proof}\n\\COL{Suppose that $u^*(t)$ is non-monotonic. By definition its derivative changes sign. By continuity there is somewhere, $t_c$, such that $\\rd u^*(t_c)/\\rd t=0$.\nThus, $u^*$ is a solution of\n\\bb\n\\dot{u^*}=F(u^*),\\quad u^*(t_c)=u^*_c.\\label{Starred}\n\\ee\nLet us construct the constant function $u\\equiv u^*_c$. We note that, $F(u^*(t_c))=0$ and, thus,  $u$ is also a solution to \\eqn{Starred}. However, this means that we have two different solutions to \\eqn{Starred} violating theorem \\ref{Existence_Uniqueness}. By contradiction $u^*(t)$ has to be monotonic.}\n\\end{proof}\nThis means that to have oscillatory phenomena in a system either we need more than one population, or the system has to be non-autonomous. See example \\ref{Duffing_example} for a case where both of these factors are present and do indeed produce oscillations (and chaos).\n\n\n\n\\section{Taylor expansions}\nThis section is to remind you of the Taylor expansion technique. The Taylor expansion is one of the most powerful tools for an applied mathematician because very often we want to know what happens to a trajectory near some critical point. Although the kinetics maybe very non-linear and difficult to understand globally we can use the Taylor expansion to simplify the dynamics in a small region around the critical point in order to gain knowledge about the dynamics in this region.\n\n\\begin{thm}\\label{Taylor}\nSuppose $f(x)$ is infinitely differentiable at a point $a$ then the Taylor series of $f$ at $a$ is the power series\n\\bb\nf(x)=\\sum _{n=0}^{\\infty }{\\frac{f^n(a)}{n!}(x-a)^n},\n\\ee\nwhich is explicitly\n\\bb\nf(x)=f(a)+{\\frac {f'(a)}{1!}}(x-a)+{\\frac {f''(a)}{2!}}(x-a)^{2}+{\\frac {f'''(a)}{3!}}(x-a)^{3}+\\cdots,\n\\ee\nwhere $n!$ denotes the factorial of $n$ and $f^{(n)}(a)$ denotes the $n^{th}$ derivative of $f$ evaluated at the point $a$. The derivative of order zero of $f$ is defined to be $f$ itself and $(x-a)^0$ and $0!$ are both defined to be 1.\n\\end{thm}\n\\begin{example}[frametitle=Taylor expansions.]\n\\begin{itemize}\n\\item $\\exp(x)$ at $x=0$ \\see{Taylor_approximations}.\n\\COL{\n\\bb\n\\exp(x)=1+x+{\\frac {1}{2}}{x}^{2}+{\\frac {1}{6}}{x}^{3}+O \\left( {x}^{4}\n \\right) .\n \\ee}\n\\item $\\cos(x)$ at $x=0$.\n\\COL{\n\\bb\n\\cos(x)=1-{\\frac {1}{2}}{x}^{2}+O \\left( {x}^{4} \\right) .\n\\ee}\n\\item $1/\\l 1+x\\r$ at $x=0$\n\\COL{\n\\bb\n\\frac{1}{1+x}=1-x+{x}^{2}-{x}^{3}+O \\left( {x}^{4} \\right) .\n\\ee}\n\\item $\\sin(x)$ at $x=\\pi/2$.\n\\COL{\n\\bb\n\\sin(x)=1-{\\frac{1}{2}} \\left( x-{\\frac {\\pi}{2}} \\right) ^{2}+O \\left( \n \\left( x-{\\frac {\\pi}{2}} \\right) ^{4} \\right)  .\n\\ee}\n\\end{itemize}\n\\end{example}\n\\begin{figure}[!!!h!!!tb]\n\\centering\n\\includegraphics[width=\\textwidth]{../Pictures/Taylor_approximations.png}\n\\caption{\\label{Taylor_approximations} Approximating the exponential function with different orders of Taylor series.}\n\\end{figure}\n\n\\COL{Although Theorem \\ref{Taylor} is the most general form of Taylor's theorem we are frequently going to want to know what happens near a specific point. Namely, if $x$ is the point of interest, what does the function look like at $x+\\epsilon$, where $\\epsilon \\ll 1$. Specifically, this simply comes down to redefining $x\\coloneqq x+\\epsilon$ and $a\\coloneqq x$ in Theorem \\ref{Taylor}, namely\n\\bb\nf(x+\\epsilon)=f \\left( x \\right) +\\epsilon{\\frac {\\rm d}{{\\rm d}x}}f \\left( x \\right) \n+{\\frac {{\\epsilon}^{2}}{2}{\\frac {{\\rm d}^{2}}{{\\rm d}{x}^{2}}}f \\left( x\n \\right) }+{\\frac {{\\epsilon}^{3}}{6}{\\frac {{\\rm d}^{3}}{{\\rm d}{x}^{\n3}}}f \\left( x \\right) }+O \\left( {\\epsilon}^{4}\n \\right). \n\\ee}\\COL{\nSince $\\epsilon\\ll 1$ we can truncate this series to obtain a good estimate after only a first term in $\\epsilon$,\n\\bb\nf(x+\\epsilon)\\approx f \\left( x \\right) +\\epsilon{\\frac {\\rm d}{{\\rm d}x}}f \\left( x \\right).\n\\ee\nThis is known as linearisation. You are taking the (possibly complicated) function $f$ and rewriting it as a linear function in $\\epsilon$.}\n\nCourses in the third year will deal with what information you get in the case that you truncate at $\\epsilon^2$, or higher. This is non-linear analysis.\n\n\\subsection{Multivariate Taylor expansion}\nA similar theorem can be stated when the function $f$ has more than one argument.\n\\begin{defin}\nIf $f$ is a function of more than one variable it is called \\textbf{multivariate}.\n\\end{defin}\n\n\\COL{Here we simply state the expansion to first order expansion that we will be concerned with throughout the course.\n\\bb\nf(x+\\epsilon_1,y+\\epsilon_2)\\approx f(x,y)+\\epsilon_1 f_x+\\epsilon_2 f_y,\n\\ee\nwhere we observe that we have used a subscript $f_x$ to denote the partial derivative $\\partial f/\\partial x$ and similarly for $f_y$.}\n\\begin{defin}\nFor brevity we use subscripts to stand for partial derivatives,\n\\bb\nf_{x_1x_2\\dots x_n}=\\frac{\\partial^n f}{\\partial x_1\\partial x_2\\dots\\partial x_n}.\n\\ee\n\\end{defin}\n\\begin{example}[frametitle=Multivariate Taylor expansion.]\n\\begin{itemize}\n\\item $\\sin(x+y)$ at $x=y=0$.\n\\COL{\n\\bb\n\\sin(x+y)\\approx x+y.\n\\ee}\n\\item $\\sin(x)\\cos(y)$ at $x=y=0$.\n\\COL{\n\\bb\n\\sin(x)\\cos(y)\\approx x.\n\\ee}\n\\end{itemize}\n\\end{example}\n\n\\section{Polar coordinates}\nMany phenomena that we will model will fall under the consideration of spatial movement, for example in Chapter \\ref{How to model a system} and question sheet two we will be considering planetary movement. Critically, in many of these cases the objects tend to move in circular trajectories orbiting a single point. Thus, it is more natural to use polar coordinates $(r,\\theta)$ to describe the motion, rather than Cartesian coordinates $(x,y)$ \\see{Polars}. However, it may be easier to model the system in Cartesian coordinates. Thus, we need to know how to convert between one set and another.\n\\begin{figure}[h!!!tb]\n\\centering\n\\includegraphics[width=\\ttp]{../Pictures/Polars.png}\n\\caption{\\label{Polars} Cartesian and polar coordinates.}\n\\end{figure} \n\n\\fig{Polars} illustrates the fundamental relationships between the Cartesian and the polar coordinates, namely:\n\\begin{align}\nx=r\\cos(\\theta),\\\\\ny=r\\sin(\\theta).\n\\end{align}\nCritically, these specify $x$ and $y$ singly as functions $(r,\\theta)$. These, in turn, can be used to construct equations for $r$ and $\\theta$ separately as functions of $(x,y)$, namely,\n\\bb\nr^2=x^2+y^2,\n\\ee\nand\n\\bb\n\\theta=\\arctan\\l\\frac{y}{x}\\r,\\quad \\textrm{or}\\quad\\theta=\\arccos\\l\\frac{x}{\\sqrt{x^2+y^2}}\\r,\\quad \\textrm{or}\\quad\\theta=\\arcsin\\l\\frac{y}{\\sqrt{x^2+y^2}}\\r.\\label{theta_eqns}\n\\ee\nwhere the appropriate function $\\theta(x,y)$ is chosen depending on which ever is easiest to use.\n\n\\begin{example}[frametitle=Cartesian to polar conversion.]\n\\COL{Suppose\n\\begin{align}\n\\dot{x}&=f(x,y),\\\\\n\\dot{y}&=g(x,y)\n\\end{align}\nhow do we convert the system from Cartesian coordinates to polar coordinates?\n\nFirst we use the condition that $r^2=x^2+y^2$. Taking derivatives we get\n\\bb\n2r\\dot{r}=2x\\dot{x}+2y\\dot{y}.\n\\ee\nAt which point we can exchange all Cartesian coordinates for their polar analogues, namely:\n\\bb\n\\dot{r}=\\cos(\\theta)f(r\\cos(\\theta),r\\sin(\\theta))+\\sin(\\theta)g(r\\cos(\\theta),r\\sin(\\theta)).\n\\ee\nNext we need $\\dot{\\theta}$. Since there are multiple (equivalent) ways of representing $\\theta$ there are multiple (equivalent) forms of the derivative, here only one will be presented. Other forms follow exactly the same procedure. We note that\n\\bb\n\\dot{x}=f(r\\cos(\\theta),r\\sin(\\theta))=\\frac{\\rd \\l r\\cos(\\theta)\\r}{\\rd t}=\\dot{r}\\cos(\\theta)-r\\sin(\\theta)\\dot{\\theta}.\\label{xdot_to_r}\n\\ee\n}\\COL{Rearranging \\eqn{xdot_to_r} gives\n\\begin{align}\n\\dot{\\theta}&=\\frac{\\cos(\\theta)^2f+\\sin(\\theta)\\cos(\\theta)g-f}{r\\sin(\\theta)},\\\\\n&=\\frac{-\\sin(\\theta)f+\\sin(\\theta)\\cos(\\theta)g}{r\\sin(\\theta)},\\\\\n&=\\frac{\\cos(\\theta)g-f\\sin(\\theta)}{r}.\n\\end{align}\nwhere the arguments of $f$ and $g$ have been suppressed for brevity.}\n\\end{example}\n\nIn the above example we created $\\dot{r}$ first and then used this to produce $\\dot{\\theta}$. In following example we show how to do the substitution all in one go.\n\\begin{example}[frametitle= A quicker conversion]\n\\COL{From\n\\begin{align}\nx=r\\cos(\\theta),\\\\\ny=r\\sin(\\theta).\n\\end{align}\nwe generate\n\\begin{align}\n&\\dot{x}=f(x,y)=\\dot{r}\\cos(\\theta)-r\\sin(\\theta)\\dot{\\theta},\\\\\n&\\dot{y}=g(x,y)=\\dot{r}\\sin(\\theta)+r\\cos(\\theta)\\dot{\\theta}.\n\\end{align}\nThis can be seen as a set of simultaneous equations and, thus, solved as a matrix problem\n\\bb\n\\colvec{2}{f}{g}=\\begin{pmatrix}\n\\cos(\\theta)& -r\\sin(\\theta) \\\\\n\\sin(\\theta) & r\\cos(\\theta)\n\\end{pmatrix}\n\\colvec{2}{\\dot{r}}{\\dot{\\theta}}.\n\\ee\nThe matrix can be inverted to produce\n\\bb\n\\frac{1}{r}\\begin{pmatrix}\nr\\cos(\\theta)& r\\sin(\\theta) \\\\\n-\\sin(\\theta) & \\cos(\\theta)\n\\end{pmatrix}\\colvec{2}{f}{g}=\n\\colvec{2}{\\dot{r}}{\\dot{\\theta}},\n\\ee\nwhich allows us to reproduce\n\\bb\n\\dot{r}=\\cos(\\theta)f+\\sin(\\theta)g.\n\\ee\n\\bb\n\\dot{\\theta}=\\frac{\\cos(\\theta)g-f\\sin(\\theta)}{r}.\n\\ee\n}\n\\end{example}\nGenerally, nonlinear equations are not solvable however, we will see in the next example the polar coordinates can convert nonlinearities in $(x,r)$ to linearities in $(r,\\theta)$\n\\begin{example}[frametitle= Solving ODEs in polar coordinates]\n\\COL{Consider the following system\n\\begin{align}\n\\dot{x}=y+x\\l 1-x^2-y^2\\r,\\label{x_polar}\\\\\n\\dot{y}=-x+y\\l 1-x^2-y^2\\r\\label{y_polar}.\n\\end{align}\nConvert to polar coordinates\n\\begin{align}\n\\dot{r}&=\\frac{xy+x^2\\l 1-x^2-y^2\\r-xy+y^2\\l 1-x^2-y^2\\r}{r},\\\\\n&=\\frac{(x^2+y^2)\\l 1-x^2-y^2\\r}{r},\\\\\n&=r(1-r^2).\n\\end{align}\nand\n\\bb\n\\dot{x}=y+x\\l 1-x^2-y^2\\r=\\dot{r}\\cos(\\theta)-r\\sin(\\theta)\\dot{\\theta},\n\\ee\nwhich implies\n\\begin{align}\n\\dot{\\theta}&=\\frac{\\dot{r}\\cos(\\theta)-y-x\\l 1-x^2-y^2\\r}{r\\sin(\\theta)},\\\\\n&=\\frac{r(1-r^2)\\cos(\\theta)-r\\sin(\\theta)-r\\cos(\\theta)(1+r^2)}{r\\sin(\\theta)},\\\\\n&=-1.\n\\end{align}\nAssuming initial conditions $\\theta(0)=0$ and $r(0)=r_0>0$ we can immediately integrate to get $\\theta=-t$ and\n\\begin{align}\nt&=\\int^r_{r_0}\\frac{1}{r'(1-r'^2)}\\rd r',\\\\\n&=\\int^r_{r_0}\\frac{1}{r'}+\\frac{1/2}{1-r'}-\\frac{1/2}{1+r'}\\rd r',\\\\\n&=\\left[\\frac{1}{r'}+\\frac{1/2}{1-r'}-\\frac{1/2}{1+r'}\\right]^r_{r_0},\\\\\n&=\\left[\\ln(r')-1/2\\ln(1-r')-1/2\\ln(1+r')\\right]^r_{r_0},\\\\\n&=\\left[\\ln\\l \\frac{r'}{\\sqrt{1-r'^2}}\\r\\right]^r_{r_0},\\\\\n&=\\ln\\l \\frac{r}{\\sqrt{1-r^2}}\\frac{\\sqrt{1-r_0^2}}{r_0}\\r,\n\\end{align}\n\nRearranging this gives,\n\\bb\nr(t)=\\frac{r_0}{\\sqrt{r_0^2+e^{-2t}\\l 1-r_0^2\\r}}.\\label{r_lim}\n\\ee\nFrom \\eqn{r_lim} we can see that $r(t)\\rightarrow 1$ as $t\\rightarrow \\infty$. Critically, we can reconstruct the Cartesian solution by considering the polar identities. Firstly, since $\\theta=-t$ the solutions spiral at a constant rate. Note the spirals go clockwise as we normally take positive angles to be anticlockwise. Further, any trajectory must head towards the circle $r=1$.\n\nThe full dynamics are simulated in \\fig{Polar_plot}\n}\n\\end{example}\n\\begin{figure}[h!!!tb]\n\\centering\n\\includegraphics[width=\\ttp]{../Pictures/Polar_plot.png}\n\\caption{\\label{Polar_plot} Full dynamics of \\eqns{x_polar}{y_polar}.}\n\\end{figure} \n\\section{Check list}\nBy the end of this chapter you should be able to:\n\\begin{todolist}\n\\item reproduce all the definitions;\n\\item state all theorems;\n\\item solve simple linear ODE systems;\n\\item prove trajectories of autonomous systems cannot cross themselves;\n\\item prove that an ODE of one variable cannot oscillate;\n\\item derive single variable Taylor series of any order;\n\\item derive multivariate Taylor series up to first order;\n\\item convert systems of ODE equations of Cartesian variables in to polar variables and back again.\n\\end{todolist}\n\n\n\n\n", "meta": {"hexsha": "695275bb991fc66064fc86d35dc1f68b54e5838b", "size": 27643, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Latex/Introduction.tex", "max_stars_repo_name": "ThomasEWoolley/Modelling_with_Differential_Equations", "max_stars_repo_head_hexsha": "250ed551fa3f09e285ebcd7b2b3d86d01d9ee8e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Latex/Introduction.tex", "max_issues_repo_name": "ThomasEWoolley/Modelling_with_Differential_Equations", "max_issues_repo_head_hexsha": "250ed551fa3f09e285ebcd7b2b3d86d01d9ee8e6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Latex/Introduction.tex", "max_forks_repo_name": "ThomasEWoolley/Modelling_with_Differential_Equations", "max_forks_repo_head_hexsha": "250ed551fa3f09e285ebcd7b2b3d86d01d9ee8e6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.8849902534, "max_line_length": 596, "alphanum_fraction": 0.7275621315, "num_tokens": 8534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.701607196183882}}
{"text": "\\chapter{Network Analysis}\n\n\\newthought{Network analysis can tell us a lot about the most imporant elements of the graph and how well-connected each element is.} A common way is to count the number of connections, shortest paths to neighbors, and shapes that the network takes (i.e. number of triangles).\n\nSome common measures include:\n\\begin{itemize}\n    \\item \\emph{average degree}, which corresponds to the average number of edges per node. For lastfm, this would mean the average number of artists with whom the genre tag is shared. The higher the number, the more densely connected the network is. A similar measure is graph density, which corresponds to the ratio between number of edges and all possible number of edges.\n    \\begin{marginfigure}\n        \\centering\n        \\includegraphics[scale=0.3]{graph.png}\n        \\caption{The average degree of the above graph is 2.5 (The number of edges for each node divided by the number of nodes.). The degree of the blue node is 5, while the degree for the red node is 3. The degree centrality for the blue node is 0.5 (half of all edges are connected to it!), while for the red node it is 0.3.}\n    \\end{marginfigure}\n    \\item \\emph{degree}, which is the number of edges per node. The higher the number, the better connected the node is. For lastfm, this would mean the artist with the highest degree would be the one that shares the most genre tags with other artists.\n    \\item \\emph{degree centrality}, which is the ratio of nodes that connect to the given node. A high ratio would mean a node that can reach the most other nodes and that the node is very important in graph structure. In the case of lastfm, this would be the artist that represents the most widely used genre (perhaps pop, rock, jazz).\n\\end{itemize}\n    \nBut enough talk, let us observe this in practice! A widget that computes these statistics is called \\widget{Network Analysis}.\n\n\\begin{figure*}[h!]\n    \\centering\n    \\newcommand{\\hierclust}{\\includegraphics[scale=0.45]{net-analysis-graph.png}}\n    \\newcommand{\\imageview}{\\includegraphics[scale=0.45]{net-analysis-node.png}}\n    \\infinitewidthbox{\n    \\stackinset{r}{-0.45\\linewidth}{t}{0.0\\linewidth}{\\imageview}{\\hierclust}\\hspace{6cm}\n    }\n\\end{figure*}\n\n\\newpage\n\n\\begin{wrapfigure}{o}{0.8\\textwidth}\n    \\includegraphics[scale=0.6]{workflow.png}\n    \\label{fig:embedding}\n\\end{wrapfigure}\n\nSome statistics relate to graph properties, while others relate to node properties. Select the above three measures. Node statistics will be added to the data table, which means we can observe it in \\widget{Network Explorer}.\n\nSending additional node data to Network Explorer enables us to use the computed statistics in a visualization. We can color the nodes and set their size to degree centrality. This will expose the most central nodes - the ones that share the most tags with their neighbors. Unsurprisingly, we find The Rolling Stones and Britney Spears in the bunch.\n\n\\vspace{-0.2cm}\n\\begin{figure*}[h]\n  \\centering\n  \\includegraphics[width=\\linewidth]{network-explorer.png}%\n  \\caption{$\\;$}\n\\end{figure*}\n\\vspace{-0.3cm}\n", "meta": {"hexsha": "d740c5ec6380756c5159a6e1c406659c6ccf0108", "size": 3109, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/net-011-network-analysis/network-analysis.tex", "max_stars_repo_name": "PrimozGodec/orange-lecture-notes", "max_stars_repo_head_hexsha": "5072afa3e29cec77e1a7f6c0d1fd044e737fe378", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-10-13T14:31:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T03:47:06.000Z", "max_issues_repo_path": "chapters/net-011-network-analysis/network-analysis.tex", "max_issues_repo_name": "PrimozGodec/orange-lecture-notes", "max_issues_repo_head_hexsha": "5072afa3e29cec77e1a7f6c0d1fd044e737fe378", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2021-02-26T13:33:10.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-25T19:15:34.000Z", "max_forks_repo_path": "chapters/net-011-network-analysis/network-analysis.tex", "max_forks_repo_name": "PrimozGodec/orange-lecture-notes", "max_forks_repo_head_hexsha": "5072afa3e29cec77e1a7f6c0d1fd044e737fe378", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-01-19T16:55:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-21T20:35:41.000Z", "avg_line_length": 67.5869565217, "max_line_length": 375, "alphanum_fraction": 0.7565133483, "num_tokens": 773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199511728004, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7016071927885925}}
{"text": "\\chapter{Vector-valued Functions}\n\nIn the last chapter, you calculated the flight of the shell.  For any\ntime $t$, you could find a vector $[distance, height]$. This can be\nthought of as a function $f$ that takes a number and returns a\n2-dimensional vector.  We call this a \\newterm{vector-valued} function\nfrom $\\mathbb{R} \\rightarrow \\mathbb{R}^2$.\n\nWe often make a vector-valued function by defining several real-valued\nfunctions.  For example, if you threw a hammer with an initial upward\nspeed of 12 m/2 and a horizontal speed of 4 m/s along the $x$ axis from\nthe point $(1, 6, 2)$, its position at time $t$ (during its flight) would be given by:\n\n$$f(t) = [4t + 1, 6, -4.8t^2 + 12t + 2]$$\n\nThat is, $x$ is increasing with $t$, $y$ is constant, and $z$ is a parabola.\n\n\\tdplotsetmaincoords{80}{20} \n\\begin{tikzpicture} [scale=0.5, tdplot_main_coords, axis/.style={->,sdkblue}, \nvector/.style={-stealth,black,very thick}, \nvector guide/.style={dashed,sdkblue}]\n\n%standard tikz coordinate definition using x, y, z coords\n\\coordinate (O) at (0,0,0);\n\n%draw axes\n\\draw[axis] (0,0,0) -- (12,0,0) node[anchor=north east]{$x$};\n\\draw[axis] (0,0,0) -- (0,7,0) node[above]{$y$};\n\\draw[axis] (0,0,0) -- (0,0,10) node[anchor=south]{$z$};\n\n\\draw[thick,draw=black,\n      domain=0:2.60563,samples=300,variable=\\t] \n      plot ({4*\\t + 1},6, {-4.9*\\t^2 + 12*\\t + 2});\n\\draw[dashed,draw=sdkblue] (1, 6, 0) -- (11.42252, 6, 0);\n\\draw[dashed,draw=sdkblue] (11.42252, 0, 0) -- (11.42252, 6, 0);\n\\draw[dashed,draw=sdkblue] (1, 6, 0) -- (1, 6, 2);\n\\draw[dashed,draw=sdkblue] (1, 6, 0) -- (1, 6, 2);\n\\draw[dashed,draw=sdkblue] (1, 6, 0) -- (1, 0, 0);\n\n\\filldraw[black] (1,6,2) circle(4pt) node [left]{$f(0) = [1,6,2]$};\n\\filldraw[black] (5,6,9.1) circle(4pt) node [above]{$f(1) = [5, 6, 9.1]$};\n\\draw[dashed,draw=sdkblue] (5, 6, 0) -- (5, 6, 9.1);\n\\filldraw[black] (9,6,6.4) circle(4pt) node [right]{$f(2) = [9, 6, 6.4]$};\n\\draw[dashed,draw=sdkblue] (9, 6, 0) -- (9, 6, 6.4);\n\\filldraw[black] (11.42252,6,0) circle(4pt) node [right] {$f(2.6) = [11.4, 6, 0]$};\n\\end{tikzpicture}\n\n\\section{Finding the velocity vector}\n\n\nNow that we have its position vector, we can differentiate each\ncomponent separately to get its velocity as a vector-valued function:\n\n$$f'(t) = [4, 0, -9.8t + 12]$$\n\nThat is, the velocity is constant along the $x$-axis, zero along the\n$y$-axis, and decreasing with time along the $z$ axis.\n\n\\tdplotsetmaincoords{80}{20} \n\\begin{tikzpicture} [scale=0.5, tdplot_main_coords, axis/.style={->,sdkblue}, \nvector/.style={-stealth,black,very thick}, \nvector guide/.style={dashed,sdkblue}]\n\n%standard tikz coordinate definition using x, y, z coords\n\\coordinate (O) at (0,0,0);\n\n%draw axes\n\\draw[axis] (0,0,0) -- (14,0,0) node[anchor=north east]{$x$};\n\\draw[axis] (0,0,0) -- (0,7,0) node[above]{$y$};\n\\draw[axis] (0,0,0) -- (0,0,10) node[anchor=south]{$z$};\n\n\\draw[thick,dashed,draw=black,\n      domain=0:2.60563,samples=300,variable=\\t] \n      plot ({4*\\t + 1},6, {-4.9*\\t^2 + 12*\\t + 2});\n\n\\filldraw[black] (1,6,2) circle(4pt);\n\\draw[->, thick, draw=black] (1,6,2) -- (5, 6, 14) node [right] {$f'(0) = [4,0,12]$};\n\\draw[dashed, draw=sdkblue] (1,6,2) -- (5,6,2) -- (5,6,14);\n\\filldraw[black] (5,6,9.1) circle(4pt);\n\\draw[->, thick, draw=black] (5,6,9.1) -- (9, 6, 11.3) node [right] {$f'(1) = [4,0,2.2]$};\n\\draw[dashed, draw=sdkblue] (6,6,9.1) -- (9,6,9.1) -- (9,6,11.3);\n\\filldraw[black] (9,6,6.4) circle(4pt);\n\\draw[->, thick, draw=black] (9,6,6.4) -- (13, 6, -1.2) node [right] {$f'(2) = [4,0,-7.6]$};\n\\filldraw[black] (11.42252,6,0) circle(4pt);\n\\draw[dashed, draw=sdkblue] (9,6,6.4) -- (13,6,6.4) -- (13,6,-1.2);\n\\end{tikzpicture}\n\n\n\\section{Finding the acceleration vector}\n\n\nNow that we have its velocity, we can get its acceleration as a vector-valued function:\n\n$$f''(t) = [0, 0, -9.8]$$\n\nThere is no acceleration along the $x$ or $y$ axes. It is accerating\ndown at a constant $9.8 m/s^2$.\n\n\\tdplotsetmaincoords{80}{20} \n\\begin{tikzpicture} [scale=0.5, tdplot_main_coords, axis/.style={->,sdkblue}, \nvector/.style={-stealth,black,very thick}, \nvector guide/.style={dashed,sdkblue}]\n\n%standard tikz coordinate definition using x, y, z coords\n\\coordinate (O) at (0,0,0);\n\n%draw axes\n\\draw[axis] (0,0,0) -- (14,0,0) node[anchor=north east]{$x$};\n\\draw[axis] (0,0,0) -- (0,7,0) node[above]{$y$};\n\\draw[axis] (0,0,0) -- (0,0,10) node[anchor=south]{$z$};\n\n\\draw[thick,dashed,draw=black,\n      domain=0:2.60563,samples=300,variable=\\t] \n      plot ({4*\\t + 1},6, {-4.9*\\t^2 + 12*\\t + 2});\n\n\\filldraw[black] (1,6,2) circle(4pt);\n\\draw[->, thick, draw=black] (1,6,2) -- (1, 6, -7.8) node [right] {$f''(0) = [0,0,-9.8]$};\n\\filldraw[black] (5,6,9.1) circle(4pt);\n\\draw[->, thick, draw=black] (5,6,9.1) -- (5, 6, -0.7) node [below] {$f''(1) = [0,0,-9.8]$};\n\\filldraw[black] (9,6,6.4) circle(4pt);\n\\draw[->, thick, draw=black] (9,6,6.4) -- (9, 6, -3.4) node [right] {$f''(2) = [0,0,-9.8]$};\n\\filldraw[black] (11.42252,6,0) circle(4pt);\n\\end{tikzpicture}\n\n", "meta": {"hexsha": "1f8fe8f7b9bcb0f41b26f5ad3ec18f1dad81b881", "size": 4946, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Functions/vector_functions-en_US.tex", "max_stars_repo_name": "hillegass/sequence", "max_stars_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/Functions/vector_functions-en_US.tex", "max_issues_repo_name": "hillegass/sequence", "max_issues_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/Functions/vector_functions-en_US.tex", "max_forks_repo_name": "hillegass/sequence", "max_forks_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 39.568, "max_line_length": 92, "alphanum_fraction": 0.6200970481, "num_tokens": 2132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.835483553488848, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7015839142696288}}
{"text": "%================================\n\\section{Metrics versus Topologies}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\tLet $X$ be a set, and let $\\rho$ and $\\rho'$ be metrics on $X$. We say that $\\rho$ and $\\rho'$ are \\textit{topologically equivalent} if they induce the same topology on $X$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t$\\rho $ and $\\rho'$ are \\textit{Lipschitz equivalent} iff there exist $c, C \\in \\mathbb R_{>0}$ such that for all $x,y \\in X$,\n\t$$\n\tc \\rho(x,y) \\le \\rho'(x,y) \\le C\\rho(x,y).\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{lemma}\n\tLipschitz equivalence implies topological equivalence.\n\\end{lemma}\n%--------------------------------\n\n%--------------------------------\n\\begin{proof}\n\tAs $\\rho$ and $\\rho'$ are Lipschitz equivalent, by definition, there exist $c \\in \\mathbb R_{>0}$ such that for all $x,y \\in X$,\n\t$$\n\tc \\rho(x, y) \\le \\rho'(x, y).\n\t$$\n\t\n\tGiven $r > 0$ and $x \\in X$,\n\t$$\n\tB_{c\\rho}(x, r) = \\left\\{ y \\in X : c\\rho(x, r) < r \\right\\}\n\t$$\n\tand\n\t$$\n\tB_{\\rho'}(x,r) = \\{ y \\in X : \\rho'(x,r) < r \\}.\n\t$$\n\t\n\tAs $r$ is non-underestimated compared to $\\rho'$, then\n\t$$\n\tB_{\\rho'}(x,r) \\supseteq B_{c\\rho}(x, r) = B_{\\rho}\\left(x, \\frac{1}{c}r \\right)\n\t$$\n\tis an open neighbourhood of $x$ in $(X, \\rho')$ and is a subset\n\t\n\tLet $U \\in \\mathcal T_{\\rho'}$, then for some $\\varepsilon > 0$,\n\t$$\n\tU \\supseteq B_{\\rho'} (x, \\varepsilon) \\supseteq B_{\\rho}\\left( x, \\frac{1}{c}r \\right).\n\t$$\n\tThus $U$ is open with respect to $\\rho$, i.e., $U \\in \\mathcal T_{\\rho}$.\n\t\n\tIt is not necessary to prove converse for there always exists $C \\in \\mathbb R_{>0}$ such that $c = \\frac{1}{C}$.\n\\end{proof}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note} \\ \n\t\\begin{enumerate}\n\t\t%--------------------------------\n\t\t\\item For all $p \\ge 0$, $\\rho_p: \\mathbb R^n \\times \\mathbb R^n \\to \\mathbb R_{\\ge 0}$ are topologically equivalent.\n\t\t%--------------------------------\n\t\t\n\t\t%--------------------------------\n\t\t\\item On $C[a,b]$, $\\rho_1$ and $\\rho_\\infty$ induce different topologies, hence they are not topologically equivalent, and in particular, they are not Lipschitz equivalent. As Lipschitz equivalence implies topological equivalence, but not vice versa. So Lipschitz in-equivalence do nothing to the proof the topological in-equivalence between $\\rho_1$ and $\\rho_\\infty$. \n\t\t%--------------------------------\n\t\t\n\t\t%--------------------------------\n\t\t\\item $\\rho_p$ and $\\rho_\\text{disc}$ on $\\mathbb Z$ are topologically equivalent. Firstly, topology $\\mathcal T_{\\rho_p} = \\mathcal P(\\mathbb Z)$, because for all $B_{\\rho_p} (x, \\varepsilon)$ for all $x \\in \\mathbb Z$ and $\\varepsilon \\in \\mathbb R_{(0,1)}$,  $B_{\\rho_p}(x, \\varepsilon) = \\{x\\}$. Thus, for all, $U \\in \\mathcal P(\\mathbb Z)$,\n\t\t\t$$\n\t\t\tU = \\bigcup_{x \\in U} B_{\\rho_p}(x, \\varepsilon) = \\bigcup_{x \\in U} \\{x\\} \\in \\mathcal T_{\\rho_p}.\n\t\t\t$$\n\t\t\tThus $\\mathcal P(\\mathbb Z) \\subseteq \\mathcal T_{\\rho_p}$, but $\\mathcal T_{\\rho_p} \\subseteq \\mathcal P(\\mathbb Z)$, so $\\mathcal P(\\mathbb Z) = \\mathcal T_{\\rho_p}$. Thus $\\mathcal T_{\\rho_p} = \\mathcal T_\\text{disc}$.\n\t\t%--------------------------------\n\t\\end{enumerate}\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\tA topological space $(X, \\mathcal T)$ is \\textit{metrizable} iff $\\mathcal T$ is induced by some metric on $X$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note} \\\n\t\\begin{enumerate}\n\t\t\\item Let $(\\mathbb Z, \\mathcal T)$ with\n\t\t$$\n\t\t\\mathcal T = \\{ U \\in \\mathcal P(\\mathbb Z) : |U| \\le 1 \\},\n\t\t$$\n\t\tThen $\\mathcal T$ is not induced by any metric. Suppose it were, then all open set $U \\in \\mathcal T$ should be monotone, and for all $\\varepsilon > 0$, and for all $x \\in \\mathbb Z$, $B(x, \\varepsilon)$ should be monotone. But if $\\mathcal T$ is induced by some metric, then for all $I \\in \\mathcal P(X)$ with $|I| > 1$, a set\n\t\t$$\n\t\tW = \\bigcup_{x \\in I} B(x, \\varepsilon) \\in \\mathcal T,\n\t\t$$\n\t\tthen $|W| > 1$, which is contradicted to the conditions.\n\t\\end{enumerate}\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition} \\\n\t\\begin{enumerate}[(i)]\n\t\t\\item A topological space $(X, \\mathcal T)$ is said to be $T_1$ iff every monotone in $\\mathcal P(X)$ is closed.\n\t\t\\item A topological space $(X, \\mathcal T)$ is said to be $T_2$ or \\textit{Hausdorff} iff\n\t\t\t$$\n\t\t\t\\forall x, y \\in X \\ (x \\ne y), \\ \\exists U, W \\in \\mathcal T \\ (U \\cap W = \\emptyset), \\quad x \\in U \\land y \\in W.\n\t\t\t$$\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note} \\ \n\t\\begin{enumerate}\n\t\t\\item $(X, \\mathcal T_{\\rho_\\text{disc}})$ is $T_1$, for as any set $U \\subseteq X$ is closed for $X \\setminus U \\in \\mathcal T_{\\rho_\\text{disc}}$ as well. It is also Hausdorff, because for all $x,y \\in X$, $\\{x\\}, \\{y\\} \\in \\mathcal T_{\\rho_\\text{disc}}$ and $\\{x\\} \\cap \\{y\\} = \\emptyset$ if $x \\ne y$.\n\t\t\\item On the other hand, $(X, \\{\\emptyset, X\\})$ is $T_1$ iff $|X| = 1$. And $(X, \\{\\emptyset, X\\})$ is not Hausdorff, because there exist $x,y \\in X$ with $x \\ne y$, the only open set contains $x$ is $X$, and the only open set contains $y$ is $X$. Clearly, $X \\cap X$\n\t\\end{enumerate}\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{lemma} \\\n\t\\begin{enumerate}[(i)]\n\t\t\\item Every metrizable space is Hausdorff.\n\t\t\\item Every Hausdorff topological space is $T_1$.\n\t\\end{enumerate}\n\\end{lemma}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proof} \\\n\t\\begin{enumerate} [(i)]\n\t\t\\item Let $(X, \\rho)$ be metric space, then for all $x, y \\in X$, let $r = \\frac{\\rho(x,y)}{2}$. Suppose $(X, \\rho)$ is not Hausdorff, i.e., there is $z \\in B(x, r) \\cap B(y, r)$. By metric axioms, we have\n\t\t\t$$\n\t\t\t\\rho(x, z) + \\rho(y, z) \\ge \\rho (x,y) = 2r.\n\t\t\t$$\n\t\t\tBut $z \\in B(x, r)$ implies that $\\rho(x,z) < r$, and $z \\in B(y, r)$ implies that $\\rho(y,z) < r$, then we have\n\t\t\t$$\n\t\t\t\\rho(x, z) + \\rho(y, z) < \\rho(x,y),\n\t\t\t$$\n\t\t\twhich is contradicted to the metric axioms.\n\t\t\t\n\t\t\\item (Just an outline...) Let $(X, \\mathcal T)$ be Hausdorff. Suppose $X$ is not $T_1$, then there is $\\{x\\} \\subseteq X$ which is not closed. Then there must be a smallest $V \\supsetneq \\{x\\}$ which is closed (Why?). Then there must be a smallest $U \\in \\mathcal T$ with $U \\supseteq V$ (Why?). Then for all $x, y \\in U$, there is no disjoint $U_x, U_y$ such that $U_x \\ni x$ and $U_y \\ni y$.\n\t\\end{enumerate}\n\\end{proof}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\tLet $(X, \\mathcal T)$ be a topological space, let $\\{x_n\\}_{n = 1}^\\infty$ be a sequence in $X$, and let $x \\in X$. Then $\\{x_n\\}$ \\textit{converges} in $X$ iff there is an $x \\in X$, for all $U \\in \\mathcal T$ with $x \\in U$, $U$ contains all but finite elements in $\\{x_n\\}$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note} \\\n\t\\begin{enumerate}\n\t\t\\item If $(X, \\mathcal T)$ is metrizable, i.e., there is a metric $\\rho$ can induce $\\mathcal T$. If $\\{x_n\\} \\subseteq X$ converges in $X$, then there exists $x \\in X$, for all $\\varepsilon > 0$, $B(x, \\varepsilon)$ contains all but finite elements in $\\{x_n\\}$.\n\t\t\\item If $\\mathcal T$ is a discrete topology, a sequence $\\{x_n\\}$ converges in $(X, \\mathcal T)$ iff there is an $N$ such that for all $n \\ge N$, $x_n = x_{n + 1}$.\n\t\t\\item If $\\mathcal T$ is an indiscrete topology, then any $\\{x_n\\} \\subseteq X$ converges to any point in $X$, for there is only one non-empty open set which is $X$ itself.\n\t\\end{enumerate}\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{lemma}\n\tIn Hausdorff topological space, any convergent sequence converges to at most one point.\n\\end{lemma}\n%--------------------------------\n\n%--------------------------------\n\\begin{proof}\n\tLet $(X, \\mathcal T)$ be a Hausdorff topological space. Suppose there is a sequence $\\{x_n\\}$ converges to $x,y \\in X$ with $x \\ne y$. By the definition of topological convergence, there are $U_x, U_y \\in \\mathcal T$ both contains all but finite elements in $\\{x_n\\}$. $U_x \\cap U_y$ must be non-empty (Explain!). $x,y \\in U_x \\cap U_y$, for if they were not, by Hausdorff property, there must be open $V_x \\subseteq U_x$ and $V_y \\subseteq U_x$ with $V_x \\ni x$ and $V_y \\ni y$, and they both contains all but finite elements in $\\{x_n\\}$, which is not possible. Thus, there is no such open sets $V_x \\ni x$ and $V_y \\ni y$ with $V_x \\cap V_y = \\emptyset$, which implies $(X, \\mathcal T)$ is not Hausdorff. This is a contradition.\n\\end{proof}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition} \\\n\t\\begin{enumerate}[(i)]\n\t\t\\item A topological space $(X, \\mathcal T)$ is \\textit{regular} iff for all closed sets $V \\subseteq X$ and $x \\in X$ with $x \\notin V$, there exist disjoint open sets $U,W \\subseteq X$ such that $V \\subseteq U$ and $x \\in W$.\n\t\t\\item $(X, \\mathcal T)$ is \\textit{normal} iff for all disjoint closed sets $V, Z \\subseteq X$, there exist disjoint open sets $U, W \\subseteq X$ such that $V \\subseteq U$ and $Z \\subseteq W$.\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\t[To do] \\\n\t\\begin{enumerate}\n\t\t\\item Can I find a regular space which is not normal?\n\t\t\\item Can I find a normal space which is not regular?\n\t\t\\item Does regular implies normal or normal implies regular?\n\t\\end{enumerate}\n\\end{note}\n%--------------------------------\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n%", "meta": {"hexsha": "99c8116a8741600dc277594c8a37abdd76e472d6", "size": 9804, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-by-tom-leinster/c1_topological-space/s3_metrics-versus-topologies.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-by-tom-leinster/c1_topological-space/s3_metrics-versus-topologies.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-by-tom-leinster/c1_topological-space/s3_metrics-versus-topologies.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.1803278689, "max_line_length": 732, "alphanum_fraction": 0.5435536516, "num_tokens": 3193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339716830606, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7015839140474508}}
{"text": "\\chapter{Pythagorean Theorem}\n\nWatch's Khan Academy's Intro to the Pythagorean Theorem video at \\url{https://youtu.be/AA6RfgP-AHU}.\n\nIf you have a right triangle, the edges that touch the right angle are\ncalled \\emph{the legs}.  The third edge, which is always the longest,\nis known as \\emph{the hypotenuse}. The Pythagorean Theorem gives us\nthe relationship between the length of the legs and the length of the\nhypotenuse.\n\n\\begin{tikzpicture}[scale=1.2]\n  \\coordinate [circle, fill, inner sep=1pt] (a) at (0,0) ;\n  \\coordinate [circle, fill, inner sep=1pt] (b) at (0,4) ;\n  \\coordinate [circle, fill, inner sep=1pt] (c) at (3,0) ;\n  \\draw (a)--node [outer sep=3pt, left]{Length $a$}(b);\n  \\draw (b)--node[outer sep=3pt, right]{Length $c$}(c) ;\n  \\draw (c)--node[outer sep=3pt, below]{Length $b$}(a) ;\n  \\pic [draw, angle eccentricity=1.5] {right angle = c--a--b};\n\\end{tikzpicture}\n\nThe Pythagorean Theorem tells us that $a^2 + b^2 = c^2$.\\index{Pythagorean theorem}\n\nFor example, if one leg has length 3 and the other has length 4, then\n$a^2 + b^2 = 3^2 + 4^2 = 25$. Thus $c^2$ must equal 25. So you know\nthe hypotenuse must be of length 5.\n\n(In reality, it almost never works out to be such a tidy number. For\nexample, what is the length of the hypotenuse if the two legs are 3\nand 6? $a^2 + b^2 = 3^2 + 6^2 = 45$.  The length of the hypotenuse is\nthe square root of that: $\\sqrt{45} = \\sqrt{9 \\times 5} = 3 \\sqrt{5}$,\nwhich is approximately 6.708203932499369.)\n\n\\begin{Exercise}[title={Find the Missing Length}, label=missingsides]\n  What is the missing measure?\n  \\begin{multicols}{2}\nLeg 1 = 6, Leg 2 = 8, Hypotenuse = ? \\\\(It should be a whole number.)\n\nLeg 1 = 5, Leg 2 = ?, Hypotenuse = 13 \\\\(It should be a whole number.)\n  \nLeg 1 = ?, Leg 2 = 15, Hypotenuse = 17 \\\\(It should be a whole number.)\n\nLeg 1 = 3, Leg 2 = 3, Hypotenuse = ? \\\\(It is an irrational number. Give the exact answer and then use a calculator to get an approximation.)\n\\end{multicols}\n\\end{Exercise}\n\\begin{Answer}[ref=missingsides]\n  10 because $6^2 + 8^2 = 10^2$\n\n  12 because $5^2 + 12^2 = 13^2$\n\n  8 because $8^2 + 15^2 = 17^2$\n\n  $3\\sqrt{2} \\approx 4.24$ because $3^2 + 3^2 = \\left(3 \\sqrt{2}\\right)^2$\n\\end{Answer}\n\n\n\\section{Distance between Points}\n\nWhat is the distance between these two points?\\index{distance using Pythagorean theorme}\n\n\\begin{tikzpicture}\n  % axis\n  \\draw[thick, <->] (0, -4.1) -- (0, 4.1);\n  \\draw[thick, <->] (-4.1, 0) -- (4.1, 0);\n  \\coordinate [circle, fill, inner sep=2pt] (a) at (-1,-2) ;\n  \\coordinate [circle, fill, inner sep=2pt] (b) at (1,3) ;\n  \\node [left] at (a) {(-1,-2)};\n  \\node [right] at (b) {(1,3)};\n  % grid\n  \\draw[help lines, step = 1cm] (-4, -4) grid (4, 4);\n  \n\\end{tikzpicture}\n\nWe can draw a right triangle and use the Pythagorean Theorem:\n\n\\begin{tikzpicture}\n  % axis\n  \\draw[thick, <->] (0, -4.1) -- (0, 4.1);\n  \\draw[thick, <->] (-4.1, 0) -- (4.1, 0);\n  \\coordinate [circle, fill, inner sep=2pt] (a) at (-1,-2) ;\n  \\coordinate [circle, fill, inner sep=2pt] (b) at (1,3) ;\n    \\node [left] at (a) {(-1,-2)};\n  \\node [right] at (b) {(1,3)};\n  \\coordinate (c) at (1, -2);\n\n  \\draw [thick] (a) -- (b);\n  \\draw [thick] (a) -- node[outer sep = 3pt, below]{Length 2}(c);\n  \\draw [thick] (c) -- node[rotate=90, outer sep = 3pt, below]{Length 5}(b);\n  \\draw[help lines, step = 1cm] (-4, -4) grid (4, 4);\n \n\\end{tikzpicture}\n\n\nThe distance between the two points is $\\sqrt{2^2 + 5^2} = \\sqrt{29}\n\\approx 5.385165$. That is, you square the change in $x$ and add it to\nthe square of the change in $y$. The distance is the square root of\nthat sum.\n\n\\section{Distance in 3 Dimensions}\n\nWhat if the point is in three dimensional space?  That is, you move 2\nmeters East, 8 meters North, and 4 meters up in the air. How far are\nyou from where you started?  You just square each, sum them and take the square root:\n$\\sqrt{2^2 + 8^2 + 4^2} = \\sqrt{84} = 2\\sqrt{21} \\approx 9.165$ meters.\\index{distance!in 3 dimensions}\n\n\\begin{tikzpicture}\n  \\draw [thick, ->] (0,0,0) -- (9,0,0) node[outer sep = 1pt, right]{North} ; \n  \\draw [thick, ->]  (0,0,0) -- (0,3,0) node[outer sep = 1pt, above]{Up} ; \n  \\draw [thick, ->] (0,0,0) -- (0,0,4) node[outer sep = 1pt, below]{East} ; \n\n    \\draw [dashed]  (8,0,0) -- node[outer sep = 1pt, right]{2}  (8,0,2); \n\n  \\draw [dashed]  (0,0,2) -- node[outer sep = 1pt, below]{8} (8,0,2); \n  \\draw [dashed]  (8,0,2) -- node[outer sep = 1pt, right]{4} (8,4,2); \n  \\draw [thick]  (0,0,0) --  (8,4,2) node[circle, fill, inner sep=2pt]{}; \n  \\node [left] at (5, 2.7, 1){$\\sqrt{2^2 + 8^2 + 4^2} \\approx 9.165$};\n\n\\end{tikzpicture}\n\n", "meta": {"hexsha": "82612bb4e04e0c9bbd48f01ba152c765243b0652", "size": 4578, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/TrianglesCircles/pythagorean_theorem-en_US.tex", "max_stars_repo_name": "rajivjhoomuck/sequence", "max_stars_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Modules/TrianglesCircles/pythagorean_theorem-en_US.tex", "max_issues_repo_name": "rajivjhoomuck/sequence", "max_issues_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/TrianglesCircles/pythagorean_theorem-en_US.tex", "max_forks_repo_name": "rajivjhoomuck/sequence", "max_forks_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.4705882353, "max_line_length": 141, "alphanum_fraction": 0.629750983, "num_tokens": 1803, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.7015839124163988}}
{"text": "%!TEX root = TDT4265-Summary.tex\r\n\\section{Intensity transformations}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Basic functions}\r\nImage intensity levels are defined in the range $[0, L-1]$. $0$ is black, $L$ is white.\r\n\\begin{figure}[htbp]\r\n    \\centering\r\n    \\includegraphics[width=.8\\linewidth]{images/basic-transformations}\r\n    \\caption{Some basic grey-level transformations}\r\n    \\label{fig:basic-transformations}\r\n\\end{figure}\r\n\r\n\\subsubsection{Negative}\r\nInverts the intensity levels of the image (white becomes black and so on). Enhances details in dark regions.\r\n\\begin{equation}\r\n    s = L - 1 - r\r\n\\end{equation}\r\n\r\n\\subsubsection{Log transformation}\r\nUsed to expand dark areas and compress bright areas, i.e. give more shadow detail. Good for displaying images with very large dynamic range.\r\n\\begin{equation}\r\n    s = c \\log(1 + r), \\quad r \\geq 0\r\n\\end{equation}\r\n\r\n\\subsubsection{Gamma transformation}\r\nCan compress blacks or whites depending on the gamma value. Similar to the log transformation, but more versatile. Many devices have an inherent gamma transform response that can be compensated for by applying the opposite gamma transform. Can be used to improve detail by darkening a washed-out image or brightening a too dark image.\r\n\\begin{equation}\r\n    s = c r^\\gamma\r\n\\end{equation}\r\n\r\n\\subsubsection{Piecewise linear transformation}\r\nUse a piecewise linear function as the transformation (as opposed to the smooth transformations in Figure \\ref{fig:basic-transformations}). Many uses, depending on the function:\r\n\\begin{itemize}\r\n    \\item Contrast stretching: Increase the dynamic range of the grey levels, similar to a a sigmoid function. (Can also be done with a smooth function.)\r\n    \\item Grey-level slicing: Highlight a range of grey-levels. Either leave other values as they are or darken all other values.\r\n    \\item Bit-plane slicing: Consider e.g. an 8-bit image to be made of 8 bit `planes'. Extracting one or some of these is called bit-plane slicing. The most significant plane can be extracted to form a binary black or white image, for instance.\r\n\\end{itemize}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Histogram processing}\r\n\r\n\\subsubsection{Histogram equalization}\r\nThe cumulative probability density (CPD) of an image is\r\n\\begin{equation}\r\n    F(r) = \\int_0^r p_r (w) \\dif w ,\r\n\\end{equation}\r\nwhich leads to the transformation\r\n\\begin{equation}\r\n    s = T(r) = (L-1) F(r).\r\n\\end{equation}\r\n$p_r(w)$ is the probability for a pixel to be of intensity $w$. This transformation makes the histogram flat/uniform, which improves contrast by utilizing darks and lights equally much, rather than compressing the image into midtones.\r\n\r\n\\subsubsection{Histogram matching}\r\nSometimes you don't want a flat histogram, but a specific, nonflat distribution. Histogram matching is the method of transforming an image so that its histogram matches any given distribution.\r\n\r\n\\subsubsection{Local histogram processing}\r\nThe previous two methods are global, but sometimes a local method is better. This is done by iterating through pixels, looking at and changing the histogram of its neighborhood, and updating the pixel value according to the altered local histogram. An example is histogram equalization for a small moving window.\r\n", "meta": {"hexsha": "e0ce5d0884a45a005f9d9a4f7cda61cc23422af9", "size": 3334, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TDT4265 Computer vision/03a-intensity-transformations.tex", "max_stars_repo_name": "jakoblover/ntnu-course-summaries", "max_stars_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-11T02:42:40.000Z", "max_issues_repo_path": "TDT4265 Computer vision/03a-intensity-transformations.tex", "max_issues_repo_name": "jakoblover/ntnu-course-summaries", "max_issues_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TDT4265 Computer vision/03a-intensity-transformations.tex", "max_forks_repo_name": "jakoblover/ntnu-course-summaries", "max_forks_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.5084745763, "max_line_length": 335, "alphanum_fraction": 0.7339532094, "num_tokens": 747, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.701583908798809}}
{"text": "\\documentclass{article}\n\\usepackage[minionint,mathlf,textlf]{MinionPro} % To gussy up a bit\n\\usepackage[margin=1in]{geometry}\n\\usepackage{graphicx} % For .eps inclusion\n%\\usepackage{indentfirst} % Controls indentation\n\\usepackage[compact]{titlesec} % For regulating spacing before section titles\n\\usepackage{adjustbox} % For vertically-aligned side-by-side minipages\n\\usepackage{array, mathrsfs, mhchem, amsmath} % For centering of tabulars with text-wrapping columns\n\\usepackage{hyper ref}\n\\usepackage[autolinebreaks,framed,numbered]{mcode}\n\\pagenumbering{gobble} \n\\setlength\\parindent{0 cm}\n\\begin{document}\n\\large\n\n\\section*{The probability distribution of a diffusing particle}\nLet  $G(x,t)$ be the probability distribution of a certain particle, created at the origin at time zero, which diffuses in $n$ dimensions. According to Fick's second law of diffusion\\footnote{Notice that Fick's second law is intended to describe the change in concentration profile for an ensemble of molecules, but we have applied it to the probability distribution of a single particle.}:\n\\[ \\frac{\\partial G(\\mathbf{x},t)}{\\partial t} = D \\Delta G(\\mathbf{x},t) + \\delta(x,t) \\]\nRearrange and perform a Fourier transform ($\\mathbf{x} \\mapsto \\mathbf{k}$,t$\\mapsto \\omega$):\n\\begin{eqnarray}\n\\mathcal{L}G(\\mathbf{x},t) = \\left[ \\frac{\\partial}{\\partial t} - D \\Delta \\right]G(\\mathbf{x},t) & = & \\delta(\\mathbf{x},t) \\nonumber \\\\\n\\left(i\\omega + D|\\mathbf{k}|^2 \\right) \\tilde{g}(\\mathbf{k},\\omega) & = & 1 \\nonumber \\\\\n\\tilde{g}(\\mathbf{k},\\omega) & = & \\frac{1}{i\\omega + D|\\mathbf{k}|^2} \\nonumber\n\\end{eqnarray}\nNow perform an inverse Fourier transform ($\\omega \\mapsto$t) using a contour integral on the upper half plane to enclose the singularity at $\\omega=iD|\\mathbf{k}|^2$. We apply the residue theorem to evaluate this integral:\n\\begin{eqnarray}\n\\tilde{g}(\\mathbf{k},t) & = & \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} \\frac{e^{it\\omega}}{i\\omega + D|\\mathbf{k}|^2}\\,d\\omega \\nonumber \\\\\n& = & \\frac{1}{2\\pi} \\oint_{UHP} \\frac{e^{it\\omega}}{i\\omega + D|\\mathbf{k}|^2}\\,d\\omega \\nonumber \\\\\n& = & \\frac{2\\pi i}{2\\pi} \\textrm{Res} \\left( \\frac{\\omega - iD|\\mathbf{k}|^2}{i\\omega + D|\\mathbf{k}|^2}e^{it\\omega}, iD|\\mathbf{k}|^2 \\right) \\nonumber \\\\\n& = & \\lim_{\\omega \\to iD|\\mathbf{k}|^2} e^{it\\omega} \\nonumber \\\\\n& = & e^{-Dt|\\mathbf{k}|^2} \\nonumber\n\\end{eqnarray}\nNow we can perform another set of inverse Fourier transforms, completing the square to make a Gaussian function and shifting horizontally to simplify:\n\n\\begin{eqnarray}\nG(\\mathbf{x},t) & = & \\frac{1}{(2\\pi)^n} \\int^{\\infty}_{-\\infty} \\cdots \\int^{\\infty}_{-\\infty} e^{i\\mathbf{k} \\cdot \\mathbf{x}}e^{-Dt|\\mathbf{k}|^2}\\,dk_1 \\cdots \\,dk_n \\nonumber \\\\\n& = & \\frac{e^{-|\\mathbf{x}|^2/4Dt}}{(2\\pi)^n} \\int^{\\infty}_{-\\infty} \\cdots \\int^{\\infty}_{-\\infty} \\exp\\left(\\sum_{j=1}^n -Dtk_j^2 + ik_jx_j +  \\frac{x_j^2}{4Dt} \\right) \\,dk_1 \\cdots \\,dk_n \\nonumber \\\\\n& = & \\frac{e^{\\frac{-|\\mathbf{x}|^2}{4Dt}}}{(2\\pi)^n} \\int^{\\infty}_{-\\infty} \\cdots \\int^{\\infty}_{-\\infty} \\prod_{j=1}^n \\exp \\left(-Dtk_j^2 + ik_jx_j + \\frac{x_j^2}{4Dt} \\right) \\,dk_1 \\cdots \\,dk_n \\nonumber \\\\\n& = & \\frac{e^{\\frac{-|\\mathbf{x}|^2}{4Dt}}}{(2\\pi)^n} \\prod_{j=1}^n \\int^{\\infty}_{-\\infty} \\exp \\left(-Dtk_j^2 + ik_jx_j + \\frac{x_j^2}{4Dt} \\right) \\,dk_j \\nonumber \\\\\n& = & \\frac{e^{\\frac{-|\\mathbf{x}|^2}{4Dt}}}{(2\\pi)^n} \\prod_{j=1}^n \\int^{\\infty}_{-\\infty} \\exp \\left( \\left(ik_j\\sqrt{Dt} + \\frac{x_j}{2\\sqrt{Dt}}\\right)^2 \\right) \\,dk_j \\nonumber \\\\\n& = & \\frac{e^{\\frac{-|\\mathbf{x}|^2}{4Dt}}}{(2\\pi)^n} \\prod_{j=1}^n \\int^{\\infty}_{-\\infty} e^{-Dtk_j^2} \\,dk_j = \\frac{e^{\\frac{-|\\mathbf{x}|^2}{4Dt}}}{(2\\pi)^n} \\prod_{j=1}^n \\sqrt{\\frac{\\pi}{Dt}} = \\left( \\frac{\\pi}{Dt} \\right)^{n/2}{(2\\pi)^n} e^{\\frac{-|\\mathbf{x}|^2}{4Dt}} \\nonumber \\\\\n& = & \\frac{1}{\\left(4\\pi Dt\\right)^{n/2}} \\exp\\left(-|\\mathbf{x}|^2/4Dt\\right) \\nonumber\n\\end{eqnarray}\n$G(\\mathbf{x},t)$, the Green's function for a diffusing particle whose location at time $t=0$ is known with absolute accuracy, is a Gaussian function with mean zero. Its mean square displacement -- which in this case is also equal to the variance in position -- is:\n\\begin{eqnarray*}\n\\sigma^2 = \\left< |\\mathbf{x}|^2 \\right> & = & \\frac{1}{\\left(4\\pi Dt\\right)^{n/2}} \\int_{-\\infty}^{\\infty} \\cdots \\int_{-\\infty}^{\\infty} |\\mathbf{x}|^2 \\exp\\left(-|\\mathbf{x}|^2/4Dt\\right) \\,dx_1 \\cdots \\,dx_n \\\\\n& = & \\frac{1}{\\left(4\\pi Dt\\right)^{n/2}} \\int_{-\\infty}^{\\infty} \\cdots  \\int_{-\\infty}^{\\infty} \\exp\\left(- \\sum_{i=2}^{n} x_i^2/4Dt\\right) \\left[ \\int_{-\\infty}^{\\infty} |\\mathbf{x}|^2 e^{\\frac{-x_1^2}{4Dt}} \\,dx_1 \\right]\\, dx_2 \\cdots \\,dx_n\n\\end{eqnarray*}\nFocus on how to evaluate the innermost interval, using Gaussian integral identities:\n\\begin{eqnarray*}\n\\int_{-\\infty}^{\\infty} |\\mathbf{x}|^2 \\exp \\left( \\frac{-x_1^2}{4Dt} \\right) \\,dx_1 & = & \\int_{-\\infty}^{\\infty} x_1^2 \\exp \\left( \\frac{-x_1^2}{4Dt} \\right) \\,dx_1 + \\int_{-\\infty}^{\\infty} \\left(\\sum_{i=2}^{n} x_i^2\\right) \\exp \\left( \\frac{-x_1^2}{4Dt} \\right) \\,dx_1 \\\\\n& = & 2Dt\\sqrt{4\\pi Dt} + \\left(\\sum_{i=2}^{n} x_i^2\\right) \\sqrt{4\\pi Dt} \\\\\n& = & \\sqrt{4\\pi Dt} \\left[ 2Dt + \\sum_{i=2}^{n} x_i^2 \\right]\n\\end{eqnarray*}\nPlugging this result into the calculation for mean square distance, we get:\n\\begin{eqnarray*}\n\\left< |\\mathbf{x}|^2 \\right>  & = & \\frac{1}{\\left(4\\pi Dt\\right)^{(n-1)/2}} \\int_{-\\infty}^{\\infty} \\cdots \\int_{-\\infty}^{\\infty} \\exp\\left(- \\sum_{i=2}^{n} x_i^2/4Dt\\right) \\left[ 2Dt + \\sum_{i=2}^{n} x_i^2 \\right] \\,dx_2 \\cdots \\,dx_n \\\\\n& = & \\frac{1}{\\left(4\\pi Dt\\right)^{(n-2)/2}} \\int_{-\\infty}^{\\infty} \\cdots \\int_{-\\infty}^{\\infty} \\exp\\left(- \\sum_{i=3}^{n} x_i^2/4Dt\\right) \\left[ 4Dt + \\sum_{i=3}^{n} x_i^2 \\right] \\,dx_3 \\cdots \\,dx_n \\\\\n& = & 2nDt\n\\end{eqnarray*}\n\\end{document}", "meta": {"hexsha": "ac6b5973c902405e81fd498d3a70736fa7ecf17d", "size": 5777, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/Lecture 23 - Diffusion and Stochastic Differential Equations/greens function diffusion.tex", "max_stars_repo_name": "mewahl/intro-systems-biology", "max_stars_repo_head_hexsha": "95ad58ec50ef79d084e71f4380fbfbf5e1603836", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-01-20T17:43:31.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-31T17:23:09.000Z", "max_issues_repo_path": "lectures/Lecture 23 - Diffusion and Stochastic Differential Equations/greens function diffusion.tex", "max_issues_repo_name": "mewahl/intro-systems-biology", "max_issues_repo_head_hexsha": "95ad58ec50ef79d084e71f4380fbfbf5e1603836", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures/Lecture 23 - Diffusion and Stochastic Differential Equations/greens function diffusion.tex", "max_forks_repo_name": "mewahl/intro-systems-biology", "max_forks_repo_head_hexsha": "95ad58ec50ef79d084e71f4380fbfbf5e1603836", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-01-20T17:43:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-25T14:42:10.000Z", "avg_line_length": 94.7049180328, "max_line_length": 390, "alphanum_fraction": 0.6418556344, "num_tokens": 2384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505964, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7015838988347549}}
{"text": "\\chapter{Mathematical notation}\n\nThe table below gives a description of some of the commonly used symbols in this manual.\nNote that some symbols are used to denote multiple concepts, and therefore there are some repeated\nentries.\n\n\\begin{center}\n\\begin{longtable}{cl}\n\\hline\\hline\nSymbol & Definition\\\\\n\\hline\\hline\n\\endfirsthead\n%\n\\multicolumn{2}{c}{{\\tablename} -- Continued} \\\\[0.5ex]\n\\hline\\hline\nSymbol & Definition\\\\\n\\hline\\hline\n\\endhead\n%This is the footer for all pages except the last page of the table...\n  \\\\[0.5ex]\n  \\multicolumn{2}{l}{{Continued on Next Page\\ldots}} \\\\\n\\endfoot\n%This is the footer for the last page of the table...\n  \\hline\n\\endlastfoot\n%\n%\n\\multicolumn{2}{l}{{\\bf Mathematical symbols}} \\\\ \\hline\n%\n$\\nabla$     & gradient operator \\\\\n$\\partial$   & domain boundary \\\\\n\\hline\n%\n\\multicolumn{2}{l}{{\\bf Greek}} \\\\ \\hline\n%\n$\\alpha$     & thermal expansion coefficient\\\\\n$\\beta$      & saline contraction coefficient\\\\\n$\\gamma$     & isothermal compressibility coefficient\\\\\n$\\eta$       & free surface height\\\\\n$\\eta_{\\textrm{eq}}$ & equilibrium tide\\\\\n$\\kaptens$   & diffusivity tensor\\\\\n$\\lambda$    & longitude\\\\\n$\\mu$        & dynamic or molecular viscosity\\\\\n$\\nu$        & kinematic viscosity\\\\\n$\\phi$       & latitude\\\\\n$\\phi$       & test function\\\\\n$\\psi$       & trial function\\\\\n$\\rho$       & density\\\\\n$\\rho_0$     & constant background density\\\\\n$\\rho'$      & perturbation density\\\\\n$\\sigtens$   & stress tensor\\\\\n$\\bmtau$     & unit tangent vector\\\\\n$\\bmOmega$   & rotation vector\\\\\n\\hline\n%\n\\multicolumn{2}{l}{{\\bf Latin}} \\\\ \\hline\n%\n$\\vec{b}$      & buoyancy vector\\\\\n$c_p$       & specific heat constant\\\\\n$e$         & specific internal energy\\\\\n$E$         & total specific energy\\\\\n$f$         & Coriolis parameter\\\\\n$\\bmg$      & gravity vector\\\\\n$\\ktens$    & thermal conductivity tensor\\\\\n$\\mat{M}$   & mass matrix\\\\\n$\\metric$   & metric tensor\\\\\n$\\bmn$      & unit normal vector\\\\\n$p$         & pressure\\\\\n$p_a$       & air pressure\\\\\n$p_h$       & hydrostatic pressure\\\\\n$p'$        & perturbation pressure\\\\\n$\\bmq$      & thermal conduction\\\\\n$R_E$       & radius of the Earth\\\\\n$s$         & entropy\\\\\n$S$         & salinity\\\\\n$T$         & temperature\\\\\n$\\bmu$      & velocity vector\\\\\n$w$         & enthalpy\\\\\n\n\n\\end{longtable}\n\\end{center}\n", "meta": {"hexsha": "f3b7fadb9d6dcbd8f6063f85583f846d5385eedc", "size": 2305, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "software/multifluids_icferst/manual/mathematical_notation.tex", "max_stars_repo_name": "msc-acse/acse-9-independent-research-project-Wade003", "max_stars_repo_head_hexsha": "cfcba990d52ccf535171cf54c0a91b184db6f276", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-11T02:39:46.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-11T03:08:38.000Z", "max_issues_repo_path": "software/multifluids_icferst/manual/mathematical_notation.tex", "max_issues_repo_name": "msc-acse/acse-9-independent-research-project-Wade003", "max_issues_repo_head_hexsha": "cfcba990d52ccf535171cf54c0a91b184db6f276", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "software/multifluids_icferst/manual/mathematical_notation.tex", "max_forks_repo_name": "msc-acse/acse-9-independent-research-project-Wade003", "max_forks_repo_head_hexsha": "cfcba990d52ccf535171cf54c0a91b184db6f276", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-05-21T22:50:19.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-28T17:16:31.000Z", "avg_line_length": 27.7710843373, "max_line_length": 98, "alphanum_fraction": 0.6177874187, "num_tokens": 698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.893309411735131, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7015235509119537}}
{"text": "\\lab{Linear Systems}{Linear Systems}\n\\objective{The fundamental problem of linear algebra is solving the linear system $A\\x = \\b$, given that a solution exists.\nThere are many approaches to solving this problem, each with different pros and cons.\nIn this lab we implement the LU decomposition and use it to solve square linear systems.\nWe also introduce SciPy, together with its libraries for linear algebra and working with sparse matrices.\n}\n\n\\section*{Gaussian Elimination} % =============================================\n\nThe standard approach for solving the linear system $A\\x = \\b$ on paper is reducing the augmented matrix $\\left[A\\mid\\b\\right]$ to row-echelon form (REF) via \\emph{Gaussian elimination}, then using back substitution.\nThe matrix is in REF when the leading non-zero term in each row is the diagonal term, so the matrix is upper triangular.\n\nAt each step of Gaussian elimination, there are three possible operations: swapping two rows, multiplying one row by a scalar value, or adding a scalar multiple of one row to another.\nMany systems, like the one displayed below, can be reduced to REF using only the third type of operation.\nFirst, use multiples of the first row to get zeros below the diagonal in the first column, then use a multiple of the second row to get zeros below the diagonal in the second column.\n%\n\\begin{align*}\n\\left[\\begin{array}{ccc|c}\n1 & 1 & 1 & 1 \\\\\n1 & 4 & 2 & 3 \\\\\n4 & 7 & 8 & 9 \\\\\n\\end{array}\\right]\n\\longrightarrow\n\\left[\\begin{array}{ccc|c}\n1 & 1 & 1 & 1 \\\\\n\\textcolor{red}0 & 3 & 1 & 2 \\\\\n4 & 7 & 8 & 9 \\\\\n\\end{array}\\right]\n\\longrightarrow\n\\left[\\begin{array}{ccc|c}\n1 & 1 & 1 & 1 \\\\\n0 & 3 & 1 & 2 \\\\\n\\textcolor{red}0 & 3 & 4 & 5 \\\\\n\\end{array}\\right]\n\\longrightarrow\n\\left[\\begin{array}{ccc|c}\n1 & 1 & 1 & 1 \\\\\n0 & 3 & 1 & 2 \\\\\n0 & \\textcolor{red}0 & 3 & 3\n\\end{array}\\right]\n\\end{align*}\n\nEach of these operations is equivalent to left-multiplying by a \\emph{type III elementary matrix}, the identity with a single non-zero non-diagonal term.\nIf row operation $k$ corresponds to matrix $E_k$, the following equation is $E_3E_2E_1A = U$.\n%\n\\begin{align*}\n\\left[\\begin{array}{ccc}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n0 & -1 & 1 \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{ccc}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n-4 & 0 & 1 \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{ccc}\n1 & 0 & 0 \\\\\n-1 & 1 & 0 \\\\\n0 & 0 & 1 \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{ccc|c}\n1 & 1 & 1 & 1 \\\\\n1 & 4 & 2 & 3 \\\\\n4 & 7 & 8 & 9 \\\\\n\\end{array}\\right]\n=\n\\left[\\begin{array}{ccc|c}\n1 & 1 & 1 & 1 \\\\\n0 & 3 & 1 & 2 \\\\\n0 & 0 & 3 & 3\n\\end{array}\\right]\n\\end{align*}\n\nHowever, matrix multiplication is an inefficient way to implement row reduction.\nInstead, modify the matrix in place (without making a copy), changing only those entries that are affected by each row operation.\n\n\\begin{lstlisting}\n>>> import numpy as np\n\n>>> A = np.array([[1, 1, 1, 1],\n...               [1, 4, 2, 3],\n...               [4, 7, 8, 9]], dtype=np.<<float>>)\n\n# Reduce the 0th column to zeros below the diagonal.\n>>> A[1,0:] -= (A[1,0] / A[0,0]) * A[0]\n>>> A[2,0:] -= (A[2,0] / A[0,0]) * A[0]\n\n# Reduce the 1st column to zeros below the diagonal.\n>>> A[2,1:] -= (A[2,1] / A[1,1]) * A[1,1:]\n>>> print(A)\n[[ 1.  1.  1.  1.]\n [ 0.  3.  1.  2.]\n [ 0.  0.  3.  3.]]\n\\end{lstlisting}\n\nNote that the final row operation modifies only part of the third row to avoid spending the computation time of adding $0$ to $0$.\n\nIf a $0$ appears on the main diagonal during any part of row reduction, the approach given above tries to divide by $0$.\nSwapping the current row with one below it that does not have a $0$ in the same column solves this problem.\nThis is equivalent to left-multiplying by a type II elementary matrix, also called a \\emph{permutation matrix}.\n\n\\begin{warn} % Gaussian Elimination is numerically unstable!\nGaussian elimination is not always numerically stable.\nIn other words, it is susceptible to rounding error that may result in an incorrect final matrix.\nSuppose that, due to roundoff error, the matrix $A$ has a very small entry on the diagonal.\n\\begin{align*}\nA = \\left[\\begin{array}{cc}\n10^{-15} & 1 \\\\\n-1 & 0 \\\\\n\\end{array}\\right]\n\\end{align*}\nThough $10^{-15}$ is essentially zero, instead of swapping the first and second rows to put $A$ in REF, a computer might multiply the first row by $10^{15}$ and add it to the second row to eliminate the $-1$.\nThe resulting matrix is far from what it would be if the $10^{-15}$ were actually $0$.\n\\begin{align*}\n\\left[\\begin{array}{cc}\n10^{-15} & 1 \\\\\n-1 & 0 \\\\\n\\end{array}\\right]\n\\longrightarrow\n\\left[\\begin{array}{cc}\n10^{-15} & 1 \\\\\n0 & 10^{15} \\\\\n\\end{array}\\right]\n\\end{align*}\n\nRound-off error can propagate through many steps in a calculation. %, resulting in garbage output.\nThe NumPy routines that employ row reduction use several tricks to minimize the impact of round-off error, but these tricks cannot fix every matrix.\n\\end{warn}\n\n\\begin{problem} % Program simple row reduction to REF.\nWrite a function that reduces an arbitrary square matrix $A$ to REF.\nYou may assume that $A$ is invertible and that a $0$ will never appear on the main diagonal (so only use type III row reductions, not type II).\nAvoid operating on entries that you know will be $0$ before and after a row operation.\nUse at most two nested loops.\n\nTest your function with small test cases that you can check by hand.\nConsider using \\li{np.random.randint()} to generate a few manageable tests cases.\n\\label{prob:ref-row-reduction}\n\\end{problem}\n\n\\subsection*{The LU Decomposition} % ------------------------------------------\n\nThe \\emph{LU decomposition} of a square matrix $A$ is a factorization $A=LU$ where $U$ is the \\textbf{upper} triangular REF of $A$ and $L$ is the \\textbf{lower} triangular product of the type III elementary matrices whose inverses reduce $A$ to $U$.\n% Thus, the LU decomposition is an efficient way of storing the REF and how we got there.\nThe LU decomposition of $A$ exists when $A$ can be reduced to REF using only type III elementary matrices (without any row swaps).\nHowever, the rows of $A$ can always be permuted in a way such that the decomposition exists.\nIf $P$ is a permutation matrix encoding the appropriate row swaps, then the decomposition $PA = LU$ always exists.\n\nSuppose $A$ has an LU decomposition (not requiring row swaps).\nThen $A$ can be reduced to REF with $k$ row operations, corresponding to left-multiplying the type III elementary matrices $E_1, \\ldots, E_k$.\n% Then $U = E_k \\ldots E_2E_1A,$ where $U$ is the REF of $A$.\nBecause there were no row swaps, each $E_i$ is lower triangular, so each inverse $E_i^{-1}$ is also lower triangular.\nFurthermore, since the product of lower triangular matrices is lower triangular, $L$ is lower triangular:\n\\begin{align*}\nE_k\\ldots E_2E_1 A = U\\quad \\longrightarrow\\quad A &= (E_k \\ldots E_2E_1)^{-1} U \\\\\n&= E_1^{-1}E_2^{-1}\\ldots E_k^{-1}U \\\\\n&= LU.\n\\end{align*}\n\nThus, $L$ can be computed by right-multiplying the identity by the matrices used to reduce $U$.\nHowever, in this special situation, each right-multiplication only changes one entry of $L$, matrix multiplication can be avoided altogether.\nThe entire process, only slightly different than row reduction, is summarized below. % in Algorithm \\ref{alg:LU-Decomposition}.\n%\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{LU Decomposition}{$A$}\n    \\State $m, n \\gets \\shape{A}$\n        \\Comment{Store the dimensions of $A$.}\n    \\State $U \\gets \\makecopy{A}$\n        \\Comment{Make a copy of $A$ with \\li{np.copy()}.}\n    \\State $L \\gets I_m$\n        \\Comment{The $m\\times m$ identity matrix.}\n    \\For{$j=0 \\ldots n-1$}\n        \\For{$i=j+1 \\ldots m-1$}\n            \\State $L_{i,j} \\gets U_{i, j}/U_{j, j}$\n            \\State $U_{i,j:} \\gets U_{i,j:} - L_{i,j}U_{j,j:}$\n        \\EndFor\n    \\EndFor\n    \\State \\pseudoli{return} $L, U$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\label{alg:LU-Decomposition}\n\\end{algorithm}\n\n\\begin{problem}\nWrite a function that finds the LU decomposition of a square matrix.\nYou may assume that the decomposition exists and requires no row swaps.\n\\label{prob:LU-Decomposition}\n\\end{problem}\n\n\\subsection*{Forward and Backward Substitution} % -----------------------------\n\nIf $PA = LU$ and $A\\x = \\b$, then $LU\\x = PA\\x = P\\b$.\nThis system can be solved by first solving $L\\y = P\\b$, then $U\\x = \\y$.\nSince $L$ and $U$ are both triangular, these systems can be solved with backward and forward substitution.\nWe can thus compute the $LU$ factorization of $A$ once, then use substitution to efficiently solve $A\\x=\\b$ for various values of $\\b$.\n\nSince the diagonal entries of $L$ are all $1$, the triangular system $L\\y = \\b$ has the form\n\\begin{align*}\n\\left[\\begin{array}{ccccc}\n1      & 0      & 0      & \\cdots & 0 \\\\\nl_{21} & 1      & 0      & \\cdots & 0 \\\\\nl_{31} & l_{32} & 1      & \\cdots & 0 \\\\\n\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\nl_{n1} & l_{n2} & l_{n3} & \\cdots & 1\n\\end{array}\\right]\n\\left[\\begin{array}{c}\ny_1 \\\\ y_2 \\\\ y_3 \\\\ \\vdots \\\\ y_n \\\\\n\\end{array}\\right]\n=\n\\left[\\begin{array}{c}\nb_1 \\\\ b_2 \\\\ b_3 \\\\ \\vdots \\\\ b_n \\\\\n\\end{array}\\right].\n\\end{align*}\nMatrix multiplication yields the equations\n%\n\\begin{align}\n\\nonumber y_1 &= b_1, & y_1 &= b_1, \\\\\n\\nonumber l_{21}y_1 + y_2 &= b_2, & y_2 &= b_2 - l_{21}y_1, \\\\\n% \\nonumber l_{31}y_1 + l_{21}y_2 + y_3 &= b_3 & y_3 &= b_3 - l_{31}y_1 - l_{32}y_2 \\\\\n\\nonumber & \\vdots & \\vdots & \\\\\n\\sum_{j=1}^{k-1}l_{kj}y_j + y_k &= b_k, & y_k &= b_k - \\sum_{j=1}^{k-1}l_{kj}y_j.\n\\label{eq:forward-substitution}\n\\end{align}\nThe triangular system $U\\x = \\y$ yields similar equations, but in reverse order:\n\\begin{align*}\n\\left[\\begin{array}{ccccc}\nu_{11} & u_{12} & u_{13} & \\cdots & u_{1n} \\\\\n0      & u_{22} & u_{23} & \\cdots & u_{2n} \\\\\n0      & 0      & u_{33} & \\cdots & u_{3n} \\\\\n\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n0      & 0      & 0      & \\cdots & u_{nn}\n\\end{array}\\right]\n\\left[\\begin{array}{c}\nx_1 \\\\ x_2 \\\\ x_3 \\\\ \\vdots \\\\ x_n \\\\\n\\end{array}\\right]\n=\n\\left[\\begin{array}{c}\ny_1 \\\\ y_2 \\\\ y_3 \\\\ \\vdots \\\\ y_n \\\\\n\\end{array}\\right],\n\\end{align*}\n\\begin{align}\n\\nonumber u_{nn}x_n &= y_n, & x_n &= \\frac{1}{u_{nn}}y_n, \\\\\n\\nonumber u_{n-1,n-1}x_{n-1} + u_{n-1,n}x_{n} &= y_{n-1}, & x_{n-1} &= \\frac{1}{u_{n-1,n-1}}\\left(y_{n-1} - u_{n-1,n}x_{n}\\right),\\\\\n\\nonumber & \\vdots & \\vdots & \\\\\n\\sum_{j=k}^{n}u_{kj}x_j &= y_k, & x_k &= \\frac{1}{u_{kk}}\\left(y_k - \\sum_{j=k+1}^{n}u_{kj}x_j\\right).\n\\label{eq:backward-substitution}\n\\end{align}\n\n\\begin{problem} % Program back and forward substitution.\nWrite a function that, given $A$ and $\\b$, solves the square linear system $A\\x = \\b$.\nUse the function from Problem \\ref{prob:LU-Decomposition} to compute $L$ and $U$, then use (\\ref{eq:forward-substitution}) and (\\ref{eq:backward-substitution}) to solve for $\\y$, then $\\x$.\nYou may again assume that no row swaps are required ($P = I$ in this case).\n\\label{prob:substitute-solve}\n\\end{problem}\n\n\\section*{SciPy} % ============================================================\n\nSciPy \\cite{scipy} is a powerful scientific computing library built upon NumPy.\nIt includes high-level tools for linear algebra, statistics, signal processing, integration, optimization, machine learning, and more.\n\nSciPy is typically imported with the convention \\li{import scipy as sp}.\nHowever, SciPy is set up in a way that requires its submodules to be imported individually.%\n\\footnote{SciPy modules like \\lif{linalg} are really \\emph{packages}, which are not initialized when SciPy is imported alone.}\n\n\\begin{lstlisting}\n>>> import scipy as sp\n>>> hasattr(sp, \"stats\")            # The stats module isn't loaded yet.\n<<False>>\n\n>>> from scipy import stats         # Import stats explicitly. Access it\n>>> hasattr(sp, \"stats\")            # with 'stats' or 'sp.stats'.\n<<True>>\n\\end{lstlisting}\n\n\\subsection*{Linear Algebra} % ------------------------------------------------\n\nNumPy and SciPy both have a linear algebra module, each called \\li{linalg}, but SciPy's module is the larger of the two.\nSome of SciPy's common \\li{linalg} functions are listed below.\n% See \\url{http://docs.scipy.org/doc/scipy/reference/linalg.html} for more documentation.\n%\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{r|l}\n    Function & Returns \\\\ \\hline\n    \\li{det()} & The determinant of a square matrix. \\\\\n    \\li{eig()} & The eigenvalues and eigenvectors of a square matrix. \\\\\n    \\li{inv()} & The inverse of an invertible matrix. \\\\\n    \\li{norm()} & The norm of a vector or matrix norm of a matrix. \\\\\n    \\li{solve()} & The solution to $A\\x = \\b$ (the system need not be square).\n\\end{tabular}\n\\end{table}\n\nThis library also includes routines for computing matrix decompositions.\n\n\\begin{lstlisting}\n>>> from scipy import linalg as la\n\n# Make a random matrix and a random vector.\n>>> A = np.random.random((1000,1000))\n>>> b = np.random.random(1000)\n\n# Compute the LU decomposition of A, including pivots.\n>>> L, P = la.lu_factor(A)\n\n# Use the LU decomposition to solve Ax = b.\n>>> x = la.lu_solve((L,P), b)\n\n# Check that the solution is legitimate.\n>>> np.allclose(A @ x, b)\n<<True>>\n\\end{lstlisting}\n\nAs with NumPy, SciPy's routines are all highly optimized.\nHowever, some algorithms are, by nature, faster than others.\n\n\\begin{problem} % Time ways to solve Ax = b with scipy.linalg.\nWrite a function that times different \\li{scipy.linalg} functions for solving square linear systems.\n\nFor various values of $n$, generate a random $n \\times n$ matrix $A$ and a random $n$-vector $\\b$ using \\li{np.random.random()}.\nTime how long it takes to solve the system $A\\x = \\b$ with each of the following approaches:\n%\n\\begin{enumerate}\n\\item Invert $A$ with \\li{la.inv()} and left-multiply the inverse to $\\b$.\n\\item Use \\li{la.solve()}.\n\\item Use \\li{la.lu_factor()} and \\li{la.lu_solve()} to solve the system with the LU decomposition.\n\\item Use \\li{la.lu_factor()} and \\li{la.lu_solve()}, but only time \\li{la.lu_solve()} (not the time it takes to do the factorization with \\li{la.lu_factor()}).\n\\end{enumerate}\n%\nPlot the system size $n$ versus the execution times.\nUse log scales if needed.\n\\label{prob:linsystems-timing1}\n\\end{problem}\n\n\\begin{warn}\nProblem \\ref{prob:linsystems-timing1} demonstrates that computing a matrix inverse is computationally expensive.\nIn fact, numerically inverting matrices is so costly that there is hardly ever a good reason to do it.\nUse a specific solver like \\li{la.lu_solve()} whenever possible instead of using \\li{la.inv()}.\n\\end{warn}\n\n\\subsection*{Sparse Matrices} % -----------------------------------------------\n\nLarge linear systems can have tens of thousands of entries.\nStoring the corresponding matrices in memory can be difficult: a $10^{5} \\times 10^{5}$ system requires around 40 GB to store in a NumPy array (4 bytes per entry $\\times\\ 10^{10}$ entries).\nThis is well beyond the amount of RAM in a normal laptop.\n\nIn applications where systems of this size arise, it is often the case that the system is \\emph{sparse}, meaning that most of the entries of the matrix are $0$.\n% Taking advantage of the sparse structure of these matrices uses less memory and decreases computation time.\nSciPy's \\li{sparse} module provides tools for efficiently constructing and manipulating 1- and 2-D sparse matrices.\nA \\li{sparse} matrix only stores the nonzero values and the positions of these values.\nFor sufficiently sparse matrices, storing the matrix as a \\li{sparse} matrix may only take megabytes, rather than gigabytes.\n\nFor example, diagonal matrices are sparse.\nStoring an $n \\times n$ diagonal matrix in the na\\\"{i}ve way means storing $n^2$ values in memory.\nIt is more efficient to instead store the diagonal entries in a 1-D array of $n$ values.\nIn addition to using less storage space, this allows for much faster matrix operations: the standard algorithm to multiply a matrix by a diagonal matrix involves $n^3$ steps, but most of these are multiplying by or adding $0$.\nA smarter algorithm can accomplish the same task much faster.\n\nSciPy has seven sparse matrix types.\nEach type is optimized either for storing sparse matrices whose nonzero entries follow certain patterns, or for performing certain computations.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{c|c|l}\n    Name & Description & \\multicolumn{1}{c}{Advantages}\n    \\\\ \\hline\n    \\li{bsr_matrix} & Block Sparse Row & Specialized structure. \\\\\n    \\li{coo_matrix} & Coordinate Format & Conversion among sparse formats. \\\\\n    \\li{csc_matrix} & Compressed Sparse Column & Column-based operations and slicing.\\\\\n    \\li{csr_matrix} & Compressed Sparse Row & Row-based operations and slicing. \\\\\n    \\li{dia_matrix} & Diagonal Storage & Specialized structure. \\\\\n    \\li{dok_matrix} & Dictionary of Keys & Element access, incremental construction. \\\\\n    \\li{lil_matrix} & Row-based Linked List & Incremental construction.\n\\end{tabular}\n\\end{table}\n\n\\subsubsection*{Creating Sparse Matrices} % -----------------------------------\n\nA regular, non-sparse matrix is called \\emph{full} or \\emph{dense}.\nFull matrices can be converted to each of the sparse matrix formats listed above.\nHowever, it is more memory efficient to never create the full matrix in the first place.\nThere are three main approaches for creating sparse matrices from scratch.\n\n\\begin{itemize} % Sparse Construction Formats\n\n\\item \\textbf{Coordinate Format}:\nWhen all of the nonzero values and their positions are known, create the entire sparse matrix at once as a \\li{coo_matrix}.\nAll nonzero values are stored as a coordinate and a value.\nThis format also converts quickly to other sparse matrix types.\n\n\\begin{lstlisting}\n>>> from scipy import sparse\n\n# Define the rows, columns, and values separately.\n>>> rows = np.array([0, 1, 0])\n>>> cols = np.array([0, 1, 1])\n>>> vals = np.array([3, 5, 2])\n>>> A = sparse.coo_matrix((vals, (rows,cols)), shape=(3,3))\n>>> print(A)\n  (0, 0)    3\n  (1, 1)    5\n  (0, 1)    2\n\n# The toarray() method casts the sparse matrix as a NumPy array.\n>>> print(A.toarray())              # Note that this method forfeits\n[[3 2 0]                            # all sparsity-related optimizations.\n [0 5 0]\n [0 0 0]]\n\\end{lstlisting}\n\n\\item \\textbf{DOK and LIL Formats}:\nIf the matrix values and their locations are not known beforehand, construct the matrix incrementally with a \\li{dok_matrix} or a \\li{lil_matrix}.\nIndicate the size of the matrix, then change individual values with regular slicing syntax.\n\n\\begin{lstlisting}\n>>> B = sparse.lil_matrix((2,6))\n>>> B[0,2] = 4\n>>> B[1,3:] = 9\n\n>>> print(B.toarray())\n[[ 0.  0.  4.  0.  0.  0.]\n [ 0.  0.  0.  9.  9.  9.]]\n\\end{lstlisting}\n\n\\item \\textbf{DIA Format}: Use a \\li{dia_matrix} to store matrices that have nonzero entries on only certain diagonals.\nThe function \\li{sparse.diags()} is one convenient way to create a \\li{dia_matrix} from scratch.\nAdditionally, every sparse matrix has a \\li{setdiags()} method for modifying specified diagonals.\n\\begin{lstlisting}\n# Use sparse.diags() to create a matrix with diagonal entries.\n>>> diagonals = [[1,2],[3,4,5],[6]]     # List the diagonal entries.\n>>> offsets = [-1,0,3]                  # Specify the diagonal they go on.\n>>> print(sparse.diags(diagonals, offsets, shape=(3,4)).toarray())\n[[ 3.  0.  0.  6.]\n [ 1.  4.  0.  0.]\n [ 0.  2.  5.  0.]]\n\n# If all of the diagonals have the same entry, specify the entry alone.\n>>> A = sparse.diags([1,3,6], offsets, shape=(3,4))\n>>> print(A.toarray())\n[[ 3.  0.  0.  6.]\n [ 1.  3.  0.  0.]\n [ 0.  1.  3.  0.]]\n\n# Modify a diagonal with the setdiag() method.\n>>> A.setdiag([4,4,4], 0)\n>>> print(A.toarray())\n[[ 4.  0.  0.  6.]\n [ 1.  4.  0.  0.]\n [ 0.  1.  4.  0.]]\n\\end{lstlisting}\n\n\\item \\textbf{BSR Format}: Many sparse matrices can be formulated as block matrices, and a block matrix can be stored efficiently as a \\li{bsr_matrix}.\nUse \\li{sparse.bmat()} or \\li{sparse.block_diag()} to create a block matrix quickly.\n\\begin{lstlisting}\n# Use sparse.bmat() to create a block matrix. Use 'None' for zero blocks.\n>>> A = sparse.coo_matrix(np.ones((2,2)))\n>>> B = sparse.coo_matrix(np.full((2,2), 2.))\n>>> print(sparse.bmat([[  A , None,  A  ],\n                       [None,  B  , None]], <<format>>='bsr').toarray())\n[[ 1.  1.  0.  0.  1.  1.]\n [ 1.  1.  0.  0.  1.  1.]\n [ 0.  0.  2.  2.  0.  0.]\n [ 0.  0.  2.  2.  0.  0.]]\n\n # Use sparse.block_diag() to construct a block diagonal matrix.\n >>> print(sparse.block_diag((A,B)).toarray())\n[[ 1.  1.  0.  0.]\n [ 1.  1.  0.  0.]\n [ 0.  0.  2.  2.]\n [ 0.  0.  2.  2.]]\n \\end{lstlisting}\n\\end{itemize}\n\n\\begin{info} % plt.spy()\n% One way to view a sparse matrix is to convert it to a NumPy array with the \\li{toarray()} method.\nIf a sparse matrix is too large to fit in memory as an array, it can still be visualized with Matplotlib's \\li{plt.spy()}, which colors in the locations of the non-zero entries of the matrix.\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n\n# Construct and show a matrix with 50 2x3 diagonal blocks.\n>>> B = sparse.coo_matrix([[1,3,5],[7,9,11]])\n>>> A = sparse.block_diag([B]*50)\n>>> plt.spy(A, markersize=1)\n>>> plt.show()\n\\end{lstlisting}\n%\n\\begin{figure}[H]\n    \\includegraphics[width=.7\\textwidth]{figures/spydemo.pdf}\n\\end{figure}\n\\end{info}\n\n% This problem will be used later in the Iterative Solvers lab.\n\\begin{problem} % Construct a large sparse matrix.\n% Write a function that accepts an integer $n$.\nLet $I$ be the $n\\times n$ identity matrix, and define\n\\[\nA =\\left[\\begin{array}{ccccc}\nB & I &      &        & \\\\\nI & B &  I   &        & \\\\\n  & I & \\ddots & \\ddots & \\\\\n  &   & \\ddots & \\ddots & I \\\\\n  &   &        &    I   & B\n\\end{array}\\right],\n\\qquad\nB = \\left[\\begin{array}{rrrrr}\n-4 &  1 &      &        & \\\\\n 1 & -4 &  1   &        & \\\\\n   &  1 & \\ddots & \\ddots & \\\\\n   &    & \\ddots & \\ddots & 1 \\\\\n   &    &        &    1   & -4\n\\end{array}\\right],\n\\]\nwhere $A$ is $n^2\\times n^2$ and each block $B$ is $n\\times n$.\nThe large matrix $A$ is used in finite difference methods for solving Laplace's equation in two dimensions, $\\frac{\\partial^2u}{\\partial x^2} + \\frac{\\partial^2u}{\\partial y^2} = 0$.\n\nWrite a function that accepts an integer $n$ and constructs and returns $A$ as a sparse matrix.\nUse \\li{plt.spy()} to check that your matrix has nonzero values in the correct places.\n% \\\\ (Hint: Consider using \\li{setdiag()} method of sparse matrices to fill in some of the diagonals.)\n\\label{prob:sparse-construction}\n\\end{problem}\n\n\\begin{comment}\n\\begin{info} % Note about banded matrices.\nA \\emph{banded} matrix is a square matrix whose only non-zero entries are on the main diagonal and on some diagonals on either side.\nIf the nonzero entries are confined to the three central diagonals, the matrix is also called \\emph{tri-diagonal}.\nBanded matrices arise naturally in many applications, including numerical methods for solving certain kinds of differential equations.\n\\end{info}\n\\end{comment}\n\n\\subsubsection*{Sparse Matrix Operations} % -----------------------------------\n\nOnce a sparse matrix has been constructed, it should be converted to a \\li{csr_matrix} or a \\li{csc_matrix} with the matrix's \\li{tocsr()} or \\li{tocsc()} method.\nThe CSR and CSC formats are optimized for row or column operations, respectively.\nTo choose the correct format to use, determine what direction the matrix will be traversed.% (row-wise or column-wise).\n\nFor example, in the matrix-matrix multiplication $AB$, $A$ is traversed row-wise, but $B$ is traversed column-wise.\nThus $A$ should be converted to a \\li{csr_matrix} and $B$ should be converted to a \\li{csc_matrix}.\n\n\\begin{lstlisting}\n# Initialize a sparse matrix incrementally as a lil_matrix.\n>>> A = sparse.lil_matrix((10000,10000))\n>>> for k in range(10000):\n...     A[np.random.randint(0,9999), np.random.randint(0,9999)] = k\n...\n>>> A\n<<<10000x10000 sparse matrix of type '<type 'numpy.float64'>'\n    with 9999 stored elements in LInked List format>>>\n\n# Convert A to CSR and CSC formats to compute the matrix product AA.\n>>> Acsr = A.tocsr()\n>>> Acsc = A.tocsc()\n>>> Acsr.dot(Acsc)\n<<<10000x10000 sparse matrix of type '<type 'numpy.float64'>'\n    with 10142 stored elements in Compressed Sparse Row format>>>\n\\end{lstlisting}\n\nBeware that row-based operations on a \\li{csc_matrix} are very slow, and similarly, column-based operations on a \\li{csr_matrix} are very slow.\n\n% SciPy's \\li{sparse} methods work on NumPy arrays and dense matrices, but they take longer than using the usual methods for handling full matrices.\n\n\\begin{warn} % scipy.sparse matrices act differently than NumPy arrays.\nMany familiar NumPy operations have analogous routines in the \\li{sparse} module.\nThese methods take advantage of the sparse structure of the matrices and are, therefore, usually significantly faster.\nHowever, SciPy's \\li{sparse} matrices behave a little differently than NumPy arrays.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{r|c|c}\n    Operation & \\li{numpy} & \\li{scipy.sparse}\n    \\\\ \\hline\n    Component-wise Addition & \\li{A + B} & \\li{A + B} \\\\\n    Scalar Multiplication & \\li{2 * A} & \\li{2 * A} \\\\\n    Component-wise Multiplication  & \\li{A * B} & \\li{A.multiply(B)} \\\\\n    Matrix Multiplication & \\li{A.dot(B)}, \\li{A @ B} & \\li{A * B},\\ \\li{A.dot(B)}, \\li{A @ B} \\\\\n\\end{tabular}\n\\end{table}\n\nNote in particular the difference between \\li{A * B} for NumPy arrays and SciPy sparse matrices.\nDo \\textbf{not} use \\li{np.dot()} to try to multiply sparse matrices, as it may treat the inputs incorrectly.\nThe syntax \\li{A.dot(B)} is safest in most cases.\n\\end{warn}\n\nSciPy's sparse module has its own linear algebra library, \\li{scipy.sparse.linalg}, designed for operating on sparse matrices.\nLike other SciPy modules, it must be imported explicitly.\n\n\\begin{lstlisting}\n>>> from scipy.sparse import linalg as spla\n\\end{lstlisting}\n\n\\begin{problem} % Time scipy.sparse.linalg.spsolve() against sp.linalg.solve().\nWrite a function that times regular and sparse linear system solvers.\n\nFor various values of $n$, generate the $n^{2} \\times n^{2}$ matrix $A$ described in Problem \\ref{prob:sparse-construction} and a random vector $\\b$ with $n^2$ entries.\nTime how long it takes to solve the system $A\\x = \\b$ with each of the following approaches:\n%\n\\begin{enumerate}\n\\item Convert $A$ to CSR format and use \\li{scipy.sparse.linalg.spsolve()} (\\li{spla.spsolve()}).\n% Do not include the time it takes to convert $A$ to CSR format.\n\\item Convert $A$ to a NumPy array and use \\li{scipy.linalg.solve()} (\\li{la.solve()}).\n% Do not include the time it takes to convert $A$ to a NumPy array.\n\\end{enumerate}\nIn each experiment, only time how long it takes to solve the system (not how long it takes to convert $A$ to the appropriate format).\n\nPlot the system size $n^{2}$ versus the execution times.\nAs always, use log scales where appropriate and use a legend to label each line.\n\\end{problem}\n\n\\begin{warn} % Don't try to invert sparse matrices.\nEven though there are fast algorithms for solving certain sparse linear system, it is still very computationally difficult to invert sparse matrices.\nIn fact, the inverse of a sparse matrix is usually not sparse.\nThere is rarely a good reason to invert a matrix, sparse or dense.\n\\end{warn}\n\nSee \\url{http://docs.scipy.org/doc/scipy/reference/sparse.html} for additional details on SciPy's \\li{sparse} module.\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Improvements on the LU Decomposition} % --------------------------\n\n\\subsubsection*{Vectorization} % - - - - - - - - - - - - - - - - - - - - - - -\n\nAlgorithm \\ref{alg:LU-Decomposition} uses two loops to compute the LU decomposition.\nWith a little vectorization, the process can be reduced to a single loop.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{Fast LU Decomposition}{$A$}\n    \\State $m, n \\gets \\shape{A}$\n    \\State $U \\gets \\makecopy{A}$\n    \\State $L \\gets I_m$\n    \\For{$k=0 \\ldots n-1$}\n        \\State $L_{k+1:,k} \\gets U_{k+1:,k}/U_{k,k}$\n        \\State $U_{k+1:,k:} \\gets U_{k+1:,k:} - L_{k+1:,k}U_{k,k:}\\trp$\n        \\label{state:outer-product}\n    \\EndFor\n    \\State \\pseudoli{return} $L, U$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\end{algorithm}\n\nNote that step \\ref{state:outer-product} is an \\emph{outer product}, not the regular dot product ($\\x\\y\\trp$ instead of the usual $\\x\\trp\\y$).\nUse \\li{np.outer()} instead of \\li{np.dot()} or \\li{@} to get the desired result.\n\n\\subsubsection*{Pivoting} % - - - - - - - - - - - - - - - - - - - - - - - - - -\n\nGaussian elimination iterates through the rows of a matrix, using the diagonal entry $x_{k,k}$ of the matrix at the $k$th iteration to zero out all of the entries in the column below $x_{k,k}$ ($x_{i,k}$ for $i\\ge k$).\nThis diagonal entry is called the \\emph{pivot}.\nUnfortunately, Gaussian elimination, and hence the LU decomposition, can be very numerically unstable if at any step the pivot is a very small number.\nMost professional row reduction algorithms avoid this problem via \\emph{partial pivoting}.\n\nThe idea is to choose the largest number (in magnitude) possible to be the pivot by swapping the pivot row\\footnote{\\emph{Complete pivoting} involves row and column swaps, but doing both operations is usually considered overkill.}\n with another row before operating on the matrix.\nFor example, the second and fourth rows of the following matrix are exchanged so that the pivot is $-6$ instead of $2$.\n%\n\\begin{align*}\n\\left[\\begin{array}{cccc}\n\\times & \\times & \\times & \\times\\\\\n0 & 2 & \\times & \\times\\\\\n0 & 4 & \\times & \\times\\\\\n0 & \\textcolor{blue}{-6} & \\textcolor{blue}\\times & \\textcolor{blue}\\times\\\\\n\\end{array}\\right]\n\\longrightarrow\n\\left[\\begin{array}{cccc}\n\\times & \\times & \\times & \\times\\\\\n0 & \\textcolor{blue}{-6} & \\textcolor{blue}\\times & \\textcolor{blue}\\times\\\\\n0 & 4 & \\times & \\times\\\\\n0 & 2 & \\times & \\times\\\\\n\\end{array}\\right]\n\\longrightarrow\n\\left[\\begin{array}{cccc}\n\\times & \\times & \\times & \\times\\\\\n0 & \\textcolor{blue}{-6} & \\textcolor{blue}\\times & \\textcolor{blue}\\times\\\\\n0 & \\textcolor{red}0 & \\textcolor{red}\\times & \\textcolor{red}\\times\\\\\n0 & \\textcolor{red}0 & \\textcolor{red}\\times & \\textcolor{red}\\times\\\\\n\\end{array}\\right]\n\\end{align*}\n\nA row swap is equivalent to left-multiplying by a type II elementary matrix, also called a \\emph{permutation matrix}.\n%\n\\begin{align*}\n\\left[\\begin{array}{cccc}\n1 & 0 & 0 & 0 \\\\\n0 & 0 & 0 & 1 \\\\\n0 & 0 & 1 & 0 \\\\\n0 & 1 & 0 & 0 \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{cccc}\n\\times & \\times & \\times & \\times\\\\\n0 & 2 & \\times & \\times\\\\\n0 & 4 & \\times & \\times\\\\\n0 & \\textcolor{blue}{-6} & \\textcolor{blue}\\times & \\textcolor{blue}\\times\\\\\n\\end{array}\\right]\n=\n\\left[\\begin{array}{cccc}\n\\times & \\times & \\times & \\times\\\\\n0 & \\textcolor{blue}{-6} & \\textcolor{blue}\\times & \\textcolor{blue}\\times\\\\\n0 & 4 & \\times & \\times\\\\\n0 & 2 & \\times & \\times\\\\\n\\end{array}\\right]\n\\end{align*}\n\nFor the LU decomposition, if the permutation matrix at step $k$ is $P_k$, then $P = P_k\\ldots P_2P_1$ yields $PA = LU$.\nThe complete algorithm is given below.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{LU Decomposition with Partial Pivoting}{$A$}\n    \\State $m, n \\gets \\shape{A}$\n    \\State $U \\gets \\makecopy{A}$\n    \\State $L \\gets I_m$\n    \\State $P \\gets [0,\\ 1,\\ \\ldots,\\ n-1]$\n        \\Comment{See tip \\ref{tip:lu-decomposition-with-pivoting-P} below.}\n    \\For{$k=0 \\ldots n-1$}\n        \\State Select $i \\ge k$ that maximizes $|U_{i,k}|$\n        \\State $U_{k,k:} \\leftrightarrow U_{i,k:}$\n            \\Comment{Swap the two rows.}\n        \\State $L_{k,:k} \\leftrightarrow L_{i,:k}$\n            \\Comment{Swap the two rows.}\n        \\State $P_{k} \\leftrightarrow P_{i}$\n            \\Comment{Swap the two entries.}\n        \\State $L_{k+1:,k} \\gets U_{k+1:,k}/U_{k,k}$\n        \\State $U_{k+1:,k:} \\gets U_{k+1:,k:} - L_{k+1:,k}U_{k,k:}\\trp$\n    \\EndFor\n    \\State \\pseudoli{return} $L, U, P$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\end{algorithm}\n\nThe following tips may be helpful for implementing this algorithm:\n\\begin{enumerate}\n    \\item Since NumPy arrays are mutable, use \\li{np.copy()} to reassign the rows of an array simultaneously.\n    \\item Instead of storing $P$ as an $n \\times n$ array, fancy indexing allows us to encode row swaps in a 1-D array of length $n$.\n    Initialize $P$ as the array $[0, 1, \\ldots, n]$.\n    After performing a row swap on $A$, perform the same operations on $P$.\n    Then the matrix product $PA$ will be the same as \\li{A[P]}.\n    \\label{tip:lu-decomposition-with-pivoting-P}\n\\end{enumerate}\n\n\\begin{lstlisting}\n>>> A = np.zeros(3) + np.vstack(np.arange(3))\n>>> P = np.arange(3)\n>>> print(A)\n[[ 0.  0.  0.]\n [ 1.  1.  1.]\n [ 2.  2.  2.]]\n\n# Swap rows 1 and 2.\n>>> A[1], A[2] = np.copy(A[2]), np.copy(A[1])\n>>> P[1], P[2] = P[2], P[1]\n>>> print(A)                        # A with the new row arrangement.\n[[ 0.  0.  0.]\n [ 2.  2.  2.]\n [ 1.  1.  1.]]\n>>> print(P)                        # The permutation of the rows.\n[0 2 1]\n>>> print(A[P])                     # A with the original row arrangement.\n[[ 0.  0.  0.]\n [ 1.  1.  1.]\n [ 2.  2.  2.]]\n\\end{lstlisting}\n\nThere are potential cases where even partial pivoting does not eliminate catastrophic numerical errors in Gaussian elimination, but the odds of having such an amazingly poor matrix are essentially zero.\nThe numerical analyst J.H. Wilkinson captured the likelihood of encountering such a matrix in a natural application when he said, ``Anyone that unlucky has already been run over by a bus!''\n\n\\subsubsection*{In Place} % - - - - - - - - - - - - - - - - - - - - - - - - - -\n\nThe LU decomposition can be performed in place (overwriting the original matrix $A$) by storing $U$ on and above the main diagonal of the array and storing $L$ below it.\nThe main diagonal of $L$ does not need to be stored since all of its entries are $1$.\nThis format saves an entire array of memory, and is how \\li{scipy.linalg.lu_factor()} returns the factorization.\n\n\\subsection*{More Applications of the LU Decomposition} % ---------------------\n\nThe LU decomposition can also be used to compute inverses and determinants with relative efficiency.\n\n\\begin{itemize}\n\\item \\textbf{Inverse}:\n$(PA)^{-1} = (LU)^{-1} \\ \\Longrightarrow\\ A^{-1}P^{-1} = U^{-1}L^{-1} \\ \\Longrightarrow\\ LUA^{-1} = P$.\nSolve $LU\\a_i = \\p_i$ with forward and backward substitution (as in Problem \\ref{prob:substitute-solve}) for every column $\\p_i$ of $P$.\nThen\n\\begin{align*}\nA^{-1} =\n\\left[\\begin{array}{c|c|c|c}\n&&&\\\\\n\\a_1&\\a_2&\\cdots&\\a_n\n\\\\&&&\n\\end{array}\\right],\n\\end{align*}\nthe matrix where $\\a_k$ is the $k$th column.\n% Even this ``efficient'' method of inverting a matrix is computationally expensive.\n\n\\item \\textbf{Determinant}: % \\det(P^{-1})\\det(L)\\det(U) =\n$\\det(A) = \\det(P^{-1}LU) = \\frac{\\det(L)\\det(U)}{\\det(P)}$.\nThe determinant of a triangular matrix is the product of its diagonal entries. Since every diagonal entry of $L$ is 1, $\\det(L) = 1$.\nAlso, $P$ is just a row permutation of the identity matrix (which has determinant $1$), and a single row swap negates the determinant.\nThen if $S$ is the number of row swaps, the determinant is\n\\[\\det(A) = (-1)^S\\prod_{i=1}^nu_{ii}.\\]\n\\end{itemize}\n\n\\subsection*{The Cholesky Decomposition} % ------------------------------------\n\nA square matrix $A$ is called \\emph{positive definite} if $\\z\\trp A\\z > 0$ for all nonzero vectors $\\z$.\nIn addition, $A$ is called \\emph{Hermitian} if $A = A\\hrm = \\overline{A\\trp}$.\nIf $A$ is Hermitian positive definite, it has a \\emph{Cholesky Decomposition} $A = U\\hrm U$ where $U$ is upper triangular with real, positive entries on the diagonal.\nThis is the matrix equivalent to taking the square root of a positive real number.\n\nThe Cholesky decomposition takes advantage of the conjugate symmetry of $A$ to simultaneously reduce the columns \\emph{and} rows of $A$ to zeros (except for the diagonal).\nIt thus requires only half of the calculations and memory of the LU decomposition.\nFurthermore, the algorithm is \\emph{numerically stable}, which means, roughly speaking, that round-off errors do not propagate throughout the computation.\n% This decomposition is used when possible to solve least squares, optimization, and state estimation problems.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{Cholesky Decomposition}{$A$}\n\\State $n,n \\gets \\shape{A}$\n\\State $U \\gets$ \\li{np.triu(}$A$\\li{)}\n    \\Comment{Get the upper-triangular part of $A$.}\n\\For{$i=0 \\ldots n-1$}\n    \\For{$j=i+1 \\ldots n-1$}\n        \\State $U_{j,j:} \\gets U_{j,j:} - U_{i,j:}\\overline{U_{ij}}/U_{ii}$\n    \\EndFor\n    \\State $U_{i,i:} \\gets U_{i,i:}/\\sqrt{U_{ii}}$\n\\EndFor\n\\State \\pseudoli{return} $U$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\end{algorithm}\n%\nAs with the LU decomposition, SciPy's \\li{linalg} module has optimized routines,\\\\\\li{la.cho_factor()} and \\li{la.cho_solve()}, for using the Cholesky decomposition.\n\n\\begin{comment} % This uses the decomposition A = LL^H.\nThe entries of $L$ are calculated as follows.\n%\n\\begin{align*}\n&L_{i,j} = \\frac{1}{L_{j,j}}\\left(A_{i,j} -\\sum_{k=1}^{j-1}{L_{i,k}L_{j,k}}\\right) \\mbox{ for $i>j$} \\\\ \\\\\n&L_{i,i} = \\sqrt{A_{i,i} - \\sum_{k=1}^{i-1}{L_{i,k}L_{i,k}}}.\n\\end{align*}\n\nNotice that the entries of $L$ are defined recursively, with dependencies as diagrammed in Figure \\ref{fig:cholesky-decomposition-order}.\nThus, an implementation of the Cholesky decomposition must compute the entries of $L$ in the correct order.\n\n\\begin{figure}[H]\n\\begin{tikzpicture}[red dot/.style={draw, circle, fill=red, red},\n    norm/.style={draw=none}, xscale=1.5, yscale=1.5]\n\n\\begin{scope}[shift={(4,0)}]\n\\draw [-,ultra thick](-.2,0)--(-.2,2.5);\n\\draw [-,ultra thick](2.7,0)--(2.7,2.5);\n\\draw [-,ultra thick](-.2,0)--(0,0);\n\\draw [-,ultra thick](-.2,2.5)--(0,2.5);\n\\draw [-,ultra thick](2.7,2.5)--(2.5,2.5);\n\\draw [-,ultra thick](2.7,0)--(2.5,0);\n\n\\node[norm,black](bk1)at(.25,2.25){\\LARGE \\textbullet};\n\\node[norm,black](bk2)at(.75,1.75){\\LARGE \\textbullet};\n\\node[norm,black!25!](b1)at(1.25,1.25){\\LARGE \\textbullet};\n\\node[norm,black](bk3)at(1.75,.75){\\LARGE \\textbullet};\n\\node[norm, black](bk4)at(2.25,.25){\\LARGE \\textbullet};\n\\node[norm, black!25!](b2)at(.25,1.25){\\LARGE \\textbullet};\n\\node[norm,black!25!](b3)at(.75,1.25){\\LARGE \\textbullet};\n\\node[norm,black!25!](b4)at(.25,.25){\\LARGE \\textbullet};\n\\node[norm,black!25!](b3)at(.75,.25){\\LARGE \\textbullet};\n\\node[norm, shadecolor](r1)at(1.25,.25){\\Huge \\textbullet};\n\\end{scope}\n\n\\begin{scope}\n\\draw [-,ultra thick](-.2,0)--(-.2,2.5);\n\\draw [-,ultra thick](2.7,0)--(2.7,2.5);\n\\draw [-,ultra thick](-.2,0)--(0,0);\n\\draw [-,ultra thick](-.2,2.5)--(0,2.5);\n\\draw [-,ultra thick](2.7,2.5)--(2.5,2.5);\n\\draw [-,ultra thick](2.7,0)--(2.5,0);\n\n\\node[norm, shadecolor](r1)at(1.75,.75){\\Huge \\textbullet};\n\\node[norm,black](bk1)at(.25,2.25){\\LARGE \\textbullet};\n\\node[norm,black](bk2)at(1.25,1.25){\\LARGE \\textbullet};\n\\node[norm,black](bk3)at(.75,1.75){\\LARGE \\textbullet};\n\\node[norm,black](bk4)at(2.25,.25){\\LARGE \\textbullet};\n\\node[norm,black!25!](bk1)at(.25,.75){\\LARGE \\textbullet};\n\\node[norm,black!25!](bk1)at(.75,.75){\\LARGE \\textbullet};\n\\node[norm, black!25!](bk1)at(1.25,.75){\\LARGE \\textbullet};\n\\end{scope}\n\\end{tikzpicture}\n\\caption{The entries of $L$ in the Cholesky decomposition are defined recursively.\nTo calculate the green entry, you need to know each of the light gray entries.}\n\\label{fig:cholesky-decomposition-order}\n\\end{figure}\n\\end{comment}\n\n% TODO: Thomas algorithm for solving tridiagonal systems?\n", "meta": {"hexsha": "b62f3b5b1f75a423ae532675cfc5ccccd827efbc", "size": 39410, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume1/LinearSystems/LinearSystems.tex", "max_stars_repo_name": "chrismmuir/Labs-1", "max_stars_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 190, "max_stars_repo_stars_event_min_datetime": "2015-07-17T01:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T19:16:19.000Z", "max_issues_repo_path": "Volume1/LinearSystems/LinearSystems.tex", "max_issues_repo_name": "chrismmuir/Labs-1", "max_issues_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 184, "max_issues_repo_issues_event_min_datetime": "2015-07-16T17:56:06.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T23:47:14.000Z", "max_forks_repo_path": "Volume1/LinearSystems/LinearSystems.tex", "max_forks_repo_name": "chrismmuir/Labs-1", "max_forks_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 76, "max_forks_repo_forks_event_min_datetime": "2015-08-06T02:53:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T11:08:57.000Z", "avg_line_length": 43.9353400223, "max_line_length": 249, "alphanum_fraction": 0.6701344836, "num_tokens": 12325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370421, "lm_q2_score": 0.8933093989533707, "lm_q1q2_score": 0.7015235453628875}}
{"text": "\\subsection{Randomness Analysis}\n\\label{sec:evaluation-randomness-analysis}\nThe randomness degree of the adopted pseudo-random number generator has been evaluated with the following standard tests:\n\n\\begin{itemize}\n\t\\item \\textbf{Spectral Test:} this test is considered one of the most intuitive and widely adopted tests to assess the quality of linear congruential generators \\cite{knuth1981art}. \n\tIt relies on the fact that the output of such generators form lines or hyperplanes when plotted on 2 or more dimensions. The less the distance between these lines or planes, the better is the generator. \n\tIn fact, a smaller distance between lines or planes highlights a better uniform distribution.\n\t\n\tIn Figure~\\ref{fig:evaluation-randomness-spectral-16807},\\ref{fig:evaluation-randomness-spectral-48271} and \\ref{fig:evaluation-randomness-spectral-50812} we show the test results for generators $(16807,2^{31}-1)$, $(48271,2^{31}-1)$ and $(50812,2^{31}-1)$, respectively.\n\n\tThe results show that the adopted generator $(50812,2^{31}-1)$ is much better than $(16807, 2^{31}-1)$, which has been widely adopted in the past, and it is really similar to $(48271,2^{31}-1)$, which is the current 32-bit de-facto standard, according to \\cite{leemis2006discrete}.\n\t\n\t\\item \\textbf{Test of Extremes:} this test relies on the fact that if $U=U_{0},...,U_{d-1}$ is an independent identically distributed sequence of $Uniform(0,1)$ random variables, then $\\max(U)^{d}$ is also a $Uniform(0,1)$. The test leverages this property to measures, for every stream, how much the generated random values differ from the theoretical uniform distribution.\n\t\n\tGiven a number of streams $s$ and a level of confidence $c=1-\\alpha$, the more the total number of fails is close to the expected value $s \\cdot \\alpha$, the better is the generator.\n\t\n\tIn Figure~\\ref{fig:evaluation-randomness-extremes-50812} we show the results for the adopted generator $(508012,2^{31}-1, 256)$ with sample size $n=10000$, $k=1000$ bins, sequence size $d=5$ and $95\\%$ level of confidence.\n\t\n\tThe adopted generator shows critical values $v_{min}=913$ and $v_{max}=1088$ and $14$ total fails ($7$ lower and $7$ upper fails), that is not far from the theoretical accepted number of fails, i.e. $256*0.05=13$.\n\tThe proposed generator successfully passed the test with a $94.531\\%$ level of confidence.\n\t\n\t\\item \\textbf{Kolmogorov-Smirnov Test:} the test measures, at a given level of confidence, the biggest vertical distance between the theoretical cumulative distribution function and the empirical cumulative distribution function.\n\tThe more the recorded distance $d$ is less than the critical value $d^*$ for the considered level of confidence, the better the generator is.\n\tAs the Kolmogorov-Smirnov analysis relies on pre-calculated randomness statistics, we have chosen to take into account the statistics obtained by the previous Test of Extremes.\n\t\n\tIn Figure~\\ref{fig:evaluation-randomness-kolmogorov-smirnov-50812} we show the test results for the proposed generator $(50812,2^{31}-1, 256)$ with a $95\\%$ level of confidence.\n\t%\n\tThe proposed generator successfully passed the test, as $d=0.041<0.081=d^*$.\n\t\n\\end{itemize}\n\nWe can conclude that the adopted generator $(50812,2^{31}-1, 256)$ provides a satisfying randomness degree.\n\n\\begin{figure}\n\t\\includegraphics[width=\\columnwidth]{fig/evaluation-randomness-spectral-16807}\n\t\\caption{The Spectral Test for the generator $(16807,2^{31}-1, 1)$ in the interval $(0, 10^{-3})$.}\n\t\\label{fig:evaluation-randomness-spectral-16807}\n\\end{figure}\n\n\\begin{figure}\n\t\\includegraphics[width=\\columnwidth]{fig/evaluation-randomness-spectral-48271}\n\t\\caption{The Spectral Test for the generator $(48271,2^{31}-1, 1)$ in the interval $(0, 10^{-3})$.}\n\t\\label{fig:evaluation-randomness-spectral-48271}\n\\end{figure}\n\n\\begin{figure}\n\t\\includegraphics[width=\\columnwidth]{fig/evaluation-randomness-spectral-50812}\n\t\\caption{The Spectral Test for the generator $(50812,2^{31}-1, 1)$ in the interval $(0, 10^{-3})$.}\n\t\\label{fig:evaluation-randomness-spectral-50812}\n\\end{figure}\n\n\\begin{figure}\n\t\\includegraphics[width=\\columnwidth]{fig/evaluation-randomness-extremes-50812}\n\t\\caption{The Test of Extremes with $d=5$ to evaluate the randomness of the random number generator $(50812,2^{31}-1, 256)$.}\n\t\\label{fig:evaluation-randomness-extremes-50812}\n\\end{figure}\n\n\\begin{figure}\n\t\\includegraphics[width=\\columnwidth]{fig/evaluation-randomness-kolmogorov-smirnov-50812}\n\t\\caption{The Kolmogorov-Smirnov Analysis (leveraging the Test of Extremes with $d=5$) to evaluate the randomness of the random number generator $(50812,2^{31}-1, 256)$ with $95\\%$ confidence.}\n\t\\label{fig:evaluation-randomness-kolmogorov-smirnov-50812}\n\\end{figure}", "meta": {"hexsha": "efec34442db470379b75b04c27b45d5ae9d6a3d2", "size": 4735, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pydes/sec/evaluation-randomness-analysis.tex", "max_stars_repo_name": "gmarciani/research", "max_stars_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-07-27T13:31:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-20T12:54:12.000Z", "max_issues_repo_path": "pydes/sec/evaluation-randomness-analysis.tex", "max_issues_repo_name": "gmarciani/research", "max_issues_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pydes/sec/evaluation-randomness-analysis.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 75.1587301587, "max_line_length": 375, "alphanum_fraction": 0.7619852165, "num_tokens": 1318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543487, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7015235374736665}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n        \\section{Velocity, Acceleration, \\& Frenet Frames}\n        In previous lectures, we have introduced vectors \\(\\vec{T}\\), \\(\\vec{N}\\), and \\(\\vec{B}\\) which are related to parameterized curves. We have also considered \\(\\vec{v}\\) and \\(\\vec{a}\\), which describe the velocity and acceleration of parameterized curves. We wish to find formulas relating these vectors. We also wish to find formulas for \\(\\vec{N}\\) and \\(\\vec{B}\\) which do not depend on arc length parameterization.\n\n        We begin be considering the components of the acceleration vector \\(\\vec{a}(t)\\). In particular, we wish to consider the components of the acceleration vector \\emph{in the Frenet frame}, whose basis is \\(\\{\\vec{T},\\vec{N},\\vec{B}\\}\\). In order to express \\(\\vec{a}\\) in the Frenet frame, it is helpful to write\n        \\[\n        \\vec{v}=\\vec{r}'(t)=|\\vec{r}'|\\vec{T}=v\\vec{T}\n        \\]\n        and\n        \\[\n        \\vec{a}=\\vec{v}'(t)=\\frac{d}{dt}v\\vec{T}=\\frac{dv}{dt}\\vec{T}+v\\frac{d\\vec{T}}{dt}\n        \\]\n        but we may use the definition of \\(\\vec{N}\\) to express this as\n        \\[\n        \\vec{a}=\\frac{dv}{dt}\\vec{T}+v|\\vec{T}'(t)|\\vec{N}\n        \\]\n        which may yet again be simplified using the definition of \\(\\kappa\\) to yield\n        \\[\n        \\vec{a}=\\frac{dv}{dt}\\vec{T}+v^2\\kappa\\vec{N}\n        \\]\n        which describes \\(\\vec{a}\\) in the Frenet frame. Note that it has two main ``parts\": there is the tangential component \\(v'\\vec{T}\\), which describes the change in velocity parallel to the curve, and the normal component \\(v^2\\kappa\\vec{N}\\), which describes the change in direction of the curve, and is always directed towards the centre of curvature. Note that there is no \\(\\vec{B}\\) component, so the acceleration vector is always parallel to the osculating plane.\n\n        We also wish to consider another method of computing \\(\\vec{B}\\) and \\(\\vec{N}\\) which does not depend on finding the arc length parameterization. We already have\n        \\[\n        \\vec{a}=v'\\vec{T}+v^2\\kappa\\vec{N}\n        \\]\n        so we consider \\(\\vec{v}\\times\\vec{a}\\). Since \\(\\vec{v}=v\\vec{T}\\), we have\n        \\[\n        \\vec{v}\\times\\vec{a}=v\\vec{T}\\times(v'\\vec{T}+v^2\\kappa\\vec{N})=v^3\\kappa\\vec{B}\n        \\]\n        which recovers a previously obtained formula for curvature, since if we take the absolute value of \\(\\vec{v}\\times\\vec{a}\\), we obtain\n        \\[\n        |\\vec{v}\\times\\vec{a}|=|v^3\\kappa\\vec{B}|=v^3\\kappa\n        \\]\n        which yields\n        \\[\n        \\kappa=\\frac{|\\vec{v}\\times\\vec{a}|}{v^3}\n        \\]\n        The same expression may also be used to obtain an expression for \\(\\vec{B}\\), namely\n        \\[\n        \\vec{B}=\\frac{\\vec{v}\\times\\vec{a}}{v^3\\kappa}=\\frac{\\vec{v}\\times\\vec{a}}{|\\vec{v}\\times\\vec{a}|}\n        \\]\n        which yields an expression for \\(\\vec{B}\\) which is independent of parameterization. Since we already have an expression for \\(\\vec{T}\\) which is independent of parameterization, we may obtain one for \\(\\vec{N}\\) using the cross product.\n\n        There is also another method for computing the components of the acceleration vector. Since\n        \\[\n        \\vec{a}=a_T\\vec{T}+a_N\\vec{N}\n        \\]\n        we may find the components of \\(\\vec{a}\\) by considering the projections of \\(\\vec{v}\\) on \\(\\vec{T}\\) and \\(\\vec{N}\\), or formally\n        \\[\n        a_T=\\vec{a}\\cdot\\vec{T}=\\frac{\\vec{a}\\cdot\\vec{v}}{|\\vec{v}|}\n        \\]\n        and\n        \\[\n        a_N=\\vec{a}\\cdot\\vec{N}=\\sqrt{a^2-a_T^2}\n        \\]\n\n        \\begin{example}{}{}\n                Find \\(\\vec{T}\\), \\(\\vec{N}\\), \\(\\vec{B}\\), and \\(\\kappa\\) for the curve parameterized by \\(\\vec{r}=2t\\i+t^2\\j+\\frac{t^3}{3}\\k\\).\n                \\tcblower\n                We have\n                \\[\n                \\vec{v}=2\\i+2t\\j+t^2\\k\n                \\]\n                and as a result\n                \\[\n                v=t^2+2\n                \\]\n\n                We also have\n                \\[\n                \\vec{a}=2\\j+2t\\k\n                \\]\n                using which we may compute\n                \\[\n                \\vec{v}\\times\\vec{a}=2t^2\\i-4t\\j+4\\k\n                \\]\n                and\n                \\[\n                |\\vec{v}\\times\\vec{a}|=2(t^2+2)\n                \\]\n                \n                Using these, we may compute the desired quantities. First,\n                \\[\n                \\kappa=\\frac{|\\vec{v}\\times\\vec{a}|}{v^3}=\\frac{2(t^2+2)}{(t^2+2)^3}=\\frac{2}{(t^2+2)^2}\n                \\]\n                then\n                \\[\n                \\vec{T}=\\frac{1}{t^2+2}(2\\i+2t\\j+t^2\\k)\n                \\]\n                as well as\n                \\[\n                \\vec{B}=\\frac{\\vec{v}\\times\\vec{a}}{|\\vec{v}\\times\\vec{a}|}=\\frac{1}{t^2+2}(t^2\\i-2t\\j+2\\k)\n                \\]\n                and finally\n                \\[\n                \\vec{N}=\\vec{B}\\times\\vec{T}\n                \\]\n                which is algebraically messy, and therefore the closed form is elided.\n        \\end{example}\n        \\begin{example}{}{}\n                Consider the curve parameterized by \\(\\vec{r}=\\cos{t}\\i+t\\j+t^2\\k\\). Find \\(\\kappa\\), \\(\\vec{T}\\), \\(\\vec{N}\\), and \\(\\vec{B}\\) at \\(t=0\\).\n                \\tcblower\n                We have\n                \\[\n                \\vec{v}(0)=-\\sin{0}\\i+\\j+2(0)\\k=\\j\n                \\]\n                and as a result\n                \\[\n                v=1\n                \\]\n\n                We also have\n                \\[\n                \\vec{a}(0)=-\\cos{t}\\i+2\\k\n                \\]\n                using which we may compute\n                \\[\n                \\vec{v}\\times\\vec{a}=2\\i+\\k\n                \\]\n                and\n                \\[\n                |\\vec{v}\\times\\vec{a}|=\\sqrt{5}\n                \\]\n\n                Using these, we may compute the desired quantities. First,\n                \\[\n                \\kappa=\\frac{|\\vec{v}\\times\\vec{a}|}{v^3}=\\sqrt{5}\n                \\]\n                then\n                \\[\n                \\vec{T}=\\frac{\\vec{v}}{v}=\\j\n                \\]\n                as well as\n                \\[\n                \\vec{B}=\\frac{\\vec{v}\\times\\vec{a}}{|\\vec{v}\\times\\vec{a}|}=\\frac{1}{\\sqrt{5}}(2\\i+\\k)\n                \\]\n                and finally\n                \\[\n                \\vec{N}=\\vec{B}\\times\\vec{T}=\\frac{1}{\\sqrt{5}}(-\\i+2\\k)\n                \\]\n        \\end{example}\n\\end{document}\n", "meta": {"hexsha": "a026e38a94f642442bbe3fb19283de130ba42565", "size": 6415, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/lec_7.tex", "max_stars_repo_name": "CrashAndSideburns/MATH227-Notes", "max_stars_repo_head_hexsha": "ec5356ff816c2f51828e4f8b64b5ae0a8b0c8cd3", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-25T04:16:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T04:16:23.000Z", "max_issues_repo_path": "src/lec_7.tex", "max_issues_repo_name": "CrashAndSideburns/MATH227-Notes", "max_issues_repo_head_hexsha": "ec5356ff816c2f51828e4f8b64b5ae0a8b0c8cd3", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lec_7.tex", "max_forks_repo_name": "CrashAndSideburns/MATH227-Notes", "max_forks_repo_head_hexsha": "ec5356ff816c2f51828e4f8b64b5ae0a8b0c8cd3", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.9383561644, "max_line_length": 476, "alphanum_fraction": 0.4727981294, "num_tokens": 1967, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882383, "lm_q2_score": 0.8333245994514082, "lm_q1q2_score": 0.701514026917658}}
{"text": "\\subsection{Least squares approximation}\n\nIt should not be surprising to hear that many problems do not have a\nperfect solution, and in these cases the objective is always to try to\ndo the best possible. For example what does one do if there are no\nsolutions to a system of linear equations $A\\vect{x}=\\vect{b}$? It\nturns out that what we do is find $\\vect{x}$ such that $A\\vect{x}$ is\nas close to $\\vect{b}$ as possible. A very important technique that\nfollows from orthogonal projections is that of the least square\napproximation\\index{least square approximation}, and allows us to do\nexactly that.\n\nWe begin with a lemma.\n\nRecall that we can form the image of an $m \\times n$-matrix $A$ by\n$\\func{im}(A) = \\set{A\\vect{x} \\mid \\vect{x} \\in\n\\R^n }$. Rephrasing Theorem~\\ref{thm:orthogonal-projection} using\nthe subspace $W=\\func{im}(A)$  gives the\nequivalence of an orthogonality condition with a minimization\ncondition\\index{orthogonality and minimization}. The following picture\nillustrates this orthogonality condition and geometric meaning of this\ntheorem.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\draw[fill=lightgray](-3,0,2)--(-2,0.75,0)--(2,0.75,0)--(1,0,2)--(-3,0,2);\n\\draw(-2,0,0) rectangle (-1.8, 0.2,0);\n\\draw[thick,->](0,0,0)--(-2,0,0);\n\\draw[thick,->](0,0,0)--(-2,2,0);\n\\draw[red,thick,->](-2,2,0)--(-2,0,0);\n\\draw[thick,->](0,0,0)--(-0.5,0,1);\n\\draw[blue, thick, ->](-2,2,0)--(-0.5,0,1);\n\\node[right] at (0,0,0){$0$};\n\\node[above] at (-1,0,0){$\\vect{z}=A\\vect{x}$};\n\\node[above right] at (-1,1,0){$\\vect{y}$};\n\\node[left] at (-2,1,0){$\\vect{y}-\\vect{z}$};\n\\node[right] at (-0.25,0,1){$\\vect{u}$};\n\\node at (1,0.5,0){$A(\\R^n)$};\n\\end{tikzpicture}\n\\end{center}\n\n\\begin{theorem}{Existence of minimizers}{existence-minimizer-hs}\\label{existence-minimizer-hs}\nLet $\\vect{y}\\in \\R^{m}$ and let $A$ be an $m\\times n$-matrix.\n\nChoose $\\vect{z}\\in W= \\func{im}(A)$ given by $\\vect{z} =\n\\proj_{W}(\\vect{y})$, and let $\\vect{x} \\in \\R^{n}$ such that $\\vect{z}=A\\vect{x}$.\n\nThen\n\\begin{enumerate}\n\\item $\\vect{y} - A\\vect{x} \\in W^{\\perp}$\n\\item $\\norm{\\vect{y} - A\\vect{x}} < \\norm{\\vect{y} - \\vect{u}}$ for all $\\vect{u} \\neq \\vect{z} \\in W$\n\\end{enumerate}\n\\end{theorem}\n\nWe note a simple but useful observation.\n\n\\begin{lemma}{Transpose and dot product}{transpose-and-dot-prod}\nLet $A$ be an $m\\times n$-matrix. Then\n\\begin{equation*}\nA\\vect{x} \\dotprod \\vect{y} = \\vect{x}\\dotprod A^T\\vect{y}\n\\end{equation*}\n\\end{lemma}\n\n\\begin{proof}\nThis follows from the definitions:\n\\[ A\\vect{x} \\dotprod \\vect{y}=\\sum_{i,j}a_{ij}x_{j} y_{i}\n=\\sum_{i,j}x_{j} a_{ji} y_{i}= \\vect{x} \\dotprod A^T\\vect{y}\n\\] \\end{proof}\n\nThe next corollary gives the technique of least squares.\n\n\\begin{corollary}{Least squares and normal equation}{normal-equation}\nA specific value of $\\vect{x}$ which solves the problem of Theorem~\\ref{thm:existenceminimizerhs} is obtained by solving the equation\n\\begin{equation*}\nA^TA\\vect{x}=A^T\\vect{y}\n\\end{equation*}\nFurthermore, there always exists a solution to this system of equations.\n\\end{corollary}\n\n\\begin{proof}\nFor $\\vect{x}$ the minimizer of Theorem~\\ref{thm:existenceminimizerhs}, $(\n\\vect{y}-A\\vect{x}) \\dotprod A \\vect{u} =0$ for all $\\vect{u} \\in \\R^{n}$ and from\nLemma~\\ref{lem:transpose-and-dot-prod}, this is the same as saying\n\\begin{equation*}\nA^T(\\vect{y}-A\\vect{x}) \\dotprod \\vect{u}=0\n\\end{equation*}\nfor all $\\vect{u} \\in \\R^{n}$. This implies\n\\begin{equation*}\nA^T\\vect{y}-A^TA\\vect{x}=\\vect{0}.\n\\end{equation*}\nTherefore, there is a solution to the equation of this corollary, and it\nsolves the minimization problem of Theorem~\\ref{thm:existenceminimizerhs}.\n\\end{proof}\n\nNote that $\\vect{x}$ might not be unique but $A\\vect{x}$, the closest\npoint of $A(\\R^{n})$ to $\\vect{y}$ is unique as was shown in the\nabove argument.\n\nConsider the following example.\n\n\\begin{example}{Least squares solution to a system}{}\nFind a least squares solution to the system\n\\begin{equation*}\n\\begin{mymatrix}{rr}\n2 & 1 \\\\\n-1 & 3 \\\\\n4 & 5\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny\n\\end{mymatrix} =\\begin{mymatrix}{c}\n2 \\\\\n1 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\n\\end{example}\n\n\\begin{solution}\nFirst, consider whether there exists a real solution. To do so, set up the augmented matrix given by\n\\begin{equation*}\n\\begin{mymatrix}{rr|r}\n2 & 1 & 2 \\\\\n-1 & 3 & 1 \\\\\n4 & 5 & 1\n\\end{mymatrix}\n\\end{equation*}\nThe {\\rref} of this augmented matrix is\n\\begin{equation*}\n\\begin{mymatrix}{rr|r}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{mymatrix}\n\\end{equation*}\n\nIt follows that there is no real solution to this system. Therefore we wish to find the least squares solution. The normal equations are\n\\begin{eqnarray*}\nA^T A \\vect{x} &=& A^T \\vect{y} \\\\\n\\begin{mymatrix}{rrr}\n2 & -1 & 4 \\\\\n1 & 3 & 5\n\\end{mymatrix} \\begin{mymatrix}{rr}\n2 & 1 \\\\\n-1 & 3 \\\\\n4 & 5\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny\n\\end{mymatrix} &=&\\begin{mymatrix}{rrr}\n2 & -1 & 4 \\\\\n1 & 3 & 5\n\\end{mymatrix} \\begin{mymatrix}{c}\n2 \\\\\n1 \\\\\n1\n\\end{mymatrix}\n\\end{eqnarray*}\nand so we need to solve the system\n\\begin{equation*}\n\\begin{mymatrix}{rr}\n21 & 19 \\\\\n19 & 35\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny\n\\end{mymatrix} =\\begin{mymatrix}{r}\n7 \\\\\n10\n\\end{mymatrix}\n\\end{equation*}\nThis is a familiar exercise and the solution is\n\\begin{equation*}\n\\begin{mymatrix}{c}\nx \\\\\ny\n\\end{mymatrix} =\\begin{mymatrix}{c}\n\\vspace{0.05in}\\frac{5}{34} \\\\\n\\vspace{0.05in}\\frac{7}{34}\n\\end{mymatrix}\n\\end{equation*}\n\\end{solution}\n\nConsider another example.\n\n\\begin{example}{Least squares solution to a system}{}\nFind a least squares solution to the system\n\\begin{equation*}\n\\begin{mymatrix}{rr}\n2 & 1 \\\\\n-1 & 3 \\\\\n4 & 5\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny\n\\end{mymatrix} =\\begin{mymatrix}{c}\n3 \\\\\n2 \\\\\n9\n\\end{mymatrix}\n\\end{equation*}\n\\end{example}\n\n\\begin{solution}\nFirst, consider whether there exists a real solution. To do so, set up the augmented matrix given by\n\\begin{equation*}\n\\begin{mymatrix}{rr|r}\n2 & 1 & 3 \\\\\n-1 & 3 & 2 \\\\\n4 & 5 & 9\n\\end{mymatrix}\n\\end{equation*}\nThe {\\rref} of this augmented matrix is\n\\begin{equation*}\n\\begin{mymatrix}{rr|r}\n1 & 0 & 1 \\\\\n0 & 1 & 1 \\\\\n0 & 0 & 0\n\\end{mymatrix}\n\\end{equation*}\n\nIt follows that the system has a solution given by $x=y=1$. However we can also use the normal equations and find\nthe least squares solution.\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n2 & -1 & 4 \\\\\n1 & 3 & 5\n\\end{mymatrix} \\begin{mymatrix}{rr}\n2 & 1 \\\\\n-1 & 3 \\\\\n4 & 5\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny\n\\end{mymatrix} =\\begin{mymatrix}{rrr}\n2 & -1 & 4 \\\\\n1 & 3 & 5\n\\end{mymatrix} \\begin{mymatrix}{r}\n3 \\\\\n2 \\\\\n9\n\\end{mymatrix}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\begin{mymatrix}{rr}\n21 & 19 \\\\\n19 & 35\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny\n\\end{mymatrix} =\\begin{mymatrix}{c}\n40 \\\\\n54\n\\end{mymatrix}\n\\end{equation*}\n\nThe least squares solution is\n\\begin{equation*}\n\\begin{mymatrix}{c}\nx \\\\\ny\n\\end{mymatrix} =\\begin{mymatrix}{c}\n1 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\nwhich is the same as the solution found above.\n\\end{solution}\n\nAn important application of Corollary~\\ref{cor:normal-equation} is the\nproblem of finding the least squares regression\nline\\index{regression line} in statistics.  Suppose you are given points in the $xy$ plane\n\\begin{equation*}\n\\set{(x_{1},y_{1}),  (x_{2},y_{2}),\\ldots,  (x_{n},y_{n})   }\n\\end{equation*}\nand you would like to find constants $m$ and $b$ such that the line $\\vect{y}=m\\vect{x}+b$\ngoes through all these points. Of course this will be impossible in general.\nTherefore, we try to find $m,b$ such that the line will be as close as possible. The desired system\nis\n\\begin{equation*}\n\\begin{mymatrix}{c}\ny_{1} \\\\\n\\vdots \\\\\ny_{n}\n\\end{mymatrix} =\\begin{mymatrix}{cc}\nx_{1} & 1 \\\\\n\\vdots & \\vdots \\\\\nx_{n} & 1\n\\end{mymatrix} \\begin{mymatrix}{c}\nm \\\\\nb\n\\end{mymatrix}\n\\end{equation*}\nwhich is of the form $\\vect{y}=A\\vect{x}$. It is desired to choose $m$\nand $b$ to make\n\\begin{equation*}\n\\norm{A\\begin{mymatrix}{c}\nm \\\\\nb\n\\end{mymatrix} -\\begin{mymatrix}{c}\ny_{1} \\\\\n\\vdots \\\\\ny_{n}\n\\end{mymatrix}} ^{2}\n\\end{equation*}\nas small as possible. According to Theorem~\\ref{thm:existenceminimizerhs} and\nCorollary~\\ref{cor:normal-equation}, the best values for $m$ and $b$ occur as the\nsolution to\n\\begin{equation*}\nA^{T}A\\begin{mymatrix}{c}\nm \\\\\nb\n\\end{mymatrix} =A^{T}\\begin{mymatrix}{c}\ny_{1} \\\\\n\\vdots \\\\\ny_{n}\n\\end{mymatrix} ,\\ \\;\\mbox{where}\\; A=\\begin{mymatrix}{cc}\nx_{1} & 1 \\\\\n\\vdots & \\vdots \\\\\nx_{n} & 1\n\\end{mymatrix}\n\\end{equation*}\nThus, computing $A^{T}A$,\n\\begin{equation*}\n\\begin{mymatrix}{cc}\n\\sum_{i=1}^{n}x_{i}^{2} & \\sum_{i=1}^{n}x_{i} \\\\\n\\sum_{i=1}^{n}x_{i} & n\n\\end{mymatrix} \\begin{mymatrix}{c}\nm \\\\\nb\n\\end{mymatrix} =\\begin{mymatrix}{c}\n\\sum_{i=1}^{n}x_{i}y_{i} \\\\\n\\sum_{i=1}^{n}y_{i}\n\\end{mymatrix}\n\\end{equation*}\nSolving this system of equations for $m$ and $b$ (using Cramer's rule for example) yields:\n\\begin{equation*}\nm=\n\\frac{-\\paren{\\sum_{i=1}^{n}x_{i}} \\paren{\\sum_{i=1}^{n}y_{i}}\n+\\paren{\\sum_{i=1}^{n}x_{i}y_{i}} n}{\\paren{\n\\sum_{i=1}^{n}x_{i}^{2}} n-\\paren{\\sum_{i=1}^{n}x_{i}} ^{2}}\n\\end{equation*}\nand\n\\begin{equation*}\nb=\\frac{-\\paren{\\sum_{i=1}^{n}x_{i}} \\sum_{i=1}^{n}x_{i}y_{i}+\\paren{\n\\sum_{i=1}^{n}y_{i}} \\sum_{i=1}^{n}x_{i}^{2}}{\\paren{\n\\sum_{i=1}^{n}x_{i}^{2}} n-\\paren{\\sum_{i=1}^{n}x_{i}} ^{2}}.\n\\end{equation*}\n\nConsider the following example.\n\n\\begin{example}{Least squares regression line}{least-squares-line}\nFind the least squares regression line $\\vect{y}=m\\vect{x}+b$ for the following set of data points:\n\\[ \\set{(0,1), (1,2), (2,2), (3,4), (4,5) } \\]\n\\end{example}\n\n\\begin{solution}\nIn this case we have $n=5$ data points and we obtain:\n\\begin{equation*}\n\\begin{array}{ll}\n\\sum_{i=1}^{5}x_{i} = 10 & \\sum_{i=1}^{5}y_{i} =  14 \\\\\n\\\\\n\\sum_{i=1}^{5}x_{i}y_{i}  =  38 & \\sum_{i=1}^{5}x_{i}^{2}  =   30\\\\\n\\end{array}\n\\end{equation*}\nand hence\n\\begin{eqnarray*}\nm &=& \\frac{- 10 * 14 + 5*38}{5*30-10^2} = 1.00 \\\\\n\\\\\nb &=& \\frac{- 10 * 38 + 14*30}{5*30-10^2} = 0.80\n\\end{eqnarray*}\n\nThe  least squares regression line for the set of data points is:\n\\[ \\vect{y} = \\vect{x}+0.8 \\]\n\nOne could use this line to approximate other values for the data. For\nexample for $x=6$ one could use $y(6)=6+0.8=6.8$ as an approximate\nvalue for the data.\n\nThe following diagram shows the data points and the corresponding regression line.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\begin{axis}[\n\txlabel=x,\n\tylabel=y,\n\txmin = -1,\n\txmax = 5,\n\tymin = -1,\n\tymax = 6,\n\taxis lines = center,\n\taxis on top = true,\n\tdomain = 0:5,\n\tlegend style = {at={(1.03,-0.03)}},\n\t%legend style = {legend pos=south east}\n\t]\n\n\t\\addplot [mark =none,color=blue, ultra thick] {x + 0.8};\n\t\\addlegendentry{Regression Line}\n\t\\addplot coordinates{\n\t(0,1)\n\t(1,2)\n\t(2,2)\n\t(3,4)\n\t(4,5)\n\t};\n\t\\addlegendentry{Data Points}\n\\end{axis}\n\\end{tikzpicture}\n\\end{center}\n\\end{solution}\n\nOne could clearly do a least squares fit for curves of the form $\ny=ax^{2}+bx+c$ in the same way. In this case you want to solve as well as\npossible for $a,b$, and $c$ the system\n\\begin{equation*}\n\\begin{mymatrix}{ccc}\nx_{1}^{2} & x_{1} & 1 \\\\\n\\vdots & \\vdots & \\vdots \\\\\nx_{n}^{2} & x_{n} & 1\n\\end{mymatrix} \\begin{mymatrix}{c}\na \\\\\nb \\\\\nc\n\\end{mymatrix} =\\begin{mymatrix}{c}\ny_{1} \\\\\n\\vdots \\\\\ny_{n}\n\\end{mymatrix}\n\\end{equation*}\nand one would use the same technique as above. Many other similar problems\nare important, including many in higher dimensions and they are all solved\nthe same way.\n", "meta": {"hexsha": "fe4ea5b8933fb95a03931b4554deb9ea2243a4f0", "size": 11315, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/RnVectorsOrthogonalityLeastSquares.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/RnVectorsOrthogonalityLeastSquares.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/RnVectorsOrthogonalityLeastSquares.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 26.0114942529, "max_line_length": 136, "alphanum_fraction": 0.6615996465, "num_tokens": 4446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.890294215206509, "lm_q1q2_score": 0.7014905854616172}}
{"text": "\\section{On Douglas-Rachford splittting} % (fold)\n\\label{sec:on_douglas_rachford_splittting}\n\nThis a short recap of a post at regularize.\\footnote\n\\footnotetext{\\url{https://regularize.wordpress.com/2017/02/24/the-origin-of-the-douglas-rachford-iteration/}}\n\nConsider a Hilbert space $(\\mathcal{H}, \\langle \\cdot, \\cdot\\rangle)$. A\npoint-set map $T\\colon \\mathcal{H} \\to \\mathcal{P}(\\mathcal{H})$ is a monotone\noperator if for any $x, y \\in \\mathcal{H}$ and any $u\\in Tx$ and $v\\in Ty$\nwe have\n$\n\\langle\n    x-y,\n    u-v\n\\rangle \\geq 0\n$.\n\nA problem of the form: find $x\\in \\mathcal{H}$ such that $0 \\in Tx$, --\nis called a \\textbf{monotone inclusion}. It is typically solved via splitting.\n\nWe first split an operator, then find the resolvents of the components, and\nfinally formulate a fixed point problem, that define an iterative algorithm.\n\n\\subsection{Splitting} % (fold)\n\\label{sub:splitting}\n\n% subsection splitting (end)\n\n% section on_douglas_rachford_splittting (end)\n", "meta": {"hexsha": "df34a52f3b59f58f01efefb83bd6f16839dc1c04", "size": 978, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/on-douglas-rachford.tex", "max_stars_repo_name": "ivannz/general-scribbles", "max_stars_repo_head_hexsha": "48652c077fa008be5af0db8ab24e7a39f2d03fe1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-07T20:41:34.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-28T12:47:40.000Z", "max_issues_repo_path": "notes/on-douglas-rachford.tex", "max_issues_repo_name": "ivannz/general-scribbles", "max_issues_repo_head_hexsha": "48652c077fa008be5af0db8ab24e7a39f2d03fe1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/on-douglas-rachford.tex", "max_forks_repo_name": "ivannz/general-scribbles", "max_forks_repo_head_hexsha": "48652c077fa008be5af0db8ab24e7a39f2d03fe1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6, "max_line_length": 110, "alphanum_fraction": 0.7341513292, "num_tokens": 311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.7014623234249067}}
{"text": "\\subsection{Rotational Invariance}\\label{ex:rotation}\nThis example shows that if $\\qoiA$ is defined by a rotation of $\\qoiB$, then the accuracy and convergence rates of $\\PP^{(a)}_{\\pspace, \\ndiscs, \\nsamps}$ are identical to $\\PP^{(b)}_{\\pspace, \\ndiscs, \\nsamps}$.\nWe expect this to be true since skewness is rotationally invariant, as we summarize in the following Proposition.\n\\begin{prop}\nThe quantity $S_\\qoi(\\param)$ is invariant under rotations performed on $\\qoi$ for any $\\param$. \\\\\n\\label{prop:rot_invariance}\n\\end{prop}\n\\begin{proof}\nIf we apply a rotation $\\qoi$, then the Jacobians $J_{\\qoi, \\param}$ are also subject to the same rotation at each $\\param$.\nSince rotations are unitary operators, the norms given in Eq.~\\eqref{eq:skewness} used to define skewness are unaffected.\n\\end{proof}\n\n\\begin{figure}\n\\begin{table}[H]\n\\begin{tabular}{ c | c | c | c }\n\\nsamps & $\\qoiA$ & $\\qoiB$ & $\\qoiC$\\\\ \\hline \\hline\n$200$ & $2.18E-01$ & $1.97E-01$ & $2.19E-01$\\\\ \\hline\n\n$400$ & $1.60E-01$ & $1.70E-01$ & $1.51E-01$\\\\ \\hline\n\n$800$ & $1.09E-01$ & $1.14E-01$ & $1.09E-01$\\\\ \\hline\n\n$1600$ & $7.43E-02$ & $7.76E-02$ & $7.53E-02$\\\\ \\hline\n\n$3200$ & $5.51E-02$ & $5.53E-02$ & $5.31E-02$\\\\ \\hline\n\n$6400$ & $4.19E-02$ & $4.09E-02$ & $4.19E-02$\\\\ \\hline\n\\end{tabular}\n\\end{table}\n\n\\includegraphics[width=0.45\\linewidth]{./images/Plot-orth-reg_BigN_40000_reg_M_1_rand_I_100000.png}\n\n\\caption{The results of $d^2_\\text{TV}(\\PP_{\\pspace, \\ndiscs, \\nsamps}, \\PP_{\\pspace, \\bar{\\nsamps}})$ for three maps generated by random rotations of orthogonal linear maps.}\n\\label{fig:M1orth}\n\\end{figure}\n\nTo demonstrate this Lemma numerically, we define the space of QoI maps $\\qspace = \\set{ \\qoiA , \\qoiB, \\qoiC }$, where all three are linear maps with the same local skewness $S_\\qoi (\\param) = 1 \\; \\forall \\param \\in \\pspace$.\nThe map $\\qoiA$ is the identity and the other two, $\\qoiB$ and $\\qoiC$ are rotations of $\\qoiA$ by randomly chosen angles.\nFollowing the algorithmic outline above, we perform a convergence study to $\\PP_{\\pspace,\\bar{\\nsamps}}$ with results summarized in Figure~\\ref{fig:M1orth}.\nThe convergence rates and expected errors in the SIPs associated with each of these maps are virtually indistinguishable.\nIn light of Proposition~\\ref{prop:rot_invariance} and these numerical results, we conclude that the accuracy of the numerical solution to the SIP is invariant under rotations to the QoI map.\n\n\\FloatBarrier\n", "meta": {"hexsha": "ee47e064781be396118722fb0f9ebed5479fa0ac", "size": 2430, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch03/rotation_example.tex", "max_stars_repo_name": "mathematicalmichael/thesis", "max_stars_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-24T08:05:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-28T20:34:29.000Z", "max_issues_repo_path": "ch03/rotation_example.tex", "max_issues_repo_name": "mathematicalmichael/thesis", "max_issues_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 59, "max_issues_repo_issues_event_min_datetime": "2019-12-27T23:15:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T17:52:57.000Z", "max_forks_repo_path": "ch03/rotation_example.tex", "max_forks_repo_name": "mathematicalmichael/thesis", "max_forks_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.2272727273, "max_line_length": 226, "alphanum_fraction": 0.7069958848, "num_tokens": 842, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587158, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7013975624271356}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\providecommand{\\e}[1]{\\ensuremath{\\times 10^{#1}}}\n\n\\setlength{\\oddsidemargin}{.1in}\n\\setlength{\\textwidth}{6.3in}\n\\setlength{\\textheight}{8.9in}\n\\setlength{\\topmargin}{-.5in}\n\n\\begin{document}\n\n\\section{Gamma distribution as the conjugate prior for a Poisson likelihood}\n\\label{a:conjugate_derivation}\nHere we show that the gamma distribution is the conjugate prior for a Poisson likelihood used in Bayes' theorem; that is, choosing a gamma-distributed prior also yields a gamma-distributed posterior if the likelihood is a Poisson distribution.\n\nAssume a series of observations $\\{n_1, n_2, \\ldots, n_M\\}$ are independent and identically distributed from a Poisson distribution $f_{Poisson(\\lambda)}(n)$. This gives a Bayesian likelihood term\n\n\\begin{align}\nP(\\{n_m\\}\\,|\\,\\lambda) &= \\prod_{m = 1}^{M} P(n_m\\,|\\,\\lambda) \\\\[5pt]\n&= \\prod_{m = 1}^{M} \\frac{e^{-\\lambda} \\lambda^{n_m}}{n_m!} \\\\[5pt]\n&= \\frac{e^{-M\\lambda} \\lambda^{\\sum_{m = 1}^{M} n_m}}{\\prod_{m = 1}^{M} n_m!}.\n\\end{align}\n\nWe choose the prior to be a gamma distribution over $\\lambda$ with shape and rate parameters $\\alpha, \\beta$:\n\n\\begin{equation}\nP(\\lambda) = \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\lambda^{\\alpha - 1} e^{-\\beta \\lambda}.\n\\end{equation}\n\nBayes' theorem gives the posterior\n\n\\begin{align}\nP(\\lambda\\,|\\,\\{n_m\\}) &= \\frac{P(\\{n_m\\}\\,|\\,\\lambda) P(\\lambda)}{\\int_{\\lambda' = 0}^{\\infty} P(\\{n_m\\}\\,|\\,\\lambda') P(\\lambda') \\, d\\lambda'} \\\\[5pt]\n&= \\frac{\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\lambda^{\\sum_{m = 1}^{M} n_m + \\alpha - 1} e^{-(M + \\beta) \\lambda}}{\\int_{\\lambda' = 0}^{\\infty} \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\lambda'^{\\sum_{m = 1}^{M} n_m + \\alpha - 1} e^{-(M + \\beta) \\lambda'} \\, d\\lambda'}.\n\\label{e:eq32}\n\\end{align}\n\nThe denominator of the above expression is an integral of the form\n\n\\begin{equation}\n\\label{e:eq33}\nc \\int x^a e^{bx} \\, dx\n\\end{equation}\n\nwhere $c = \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)}$, $a = \\sum_{m = 1}^{M} n_m + \\alpha - 1$, $b = -(M + \\beta)$, and $x = \\lambda'$. This integral can be treated by iteratively applying integration by parts:\n\n\\begin{align}\n\\int x^a e^{bx} \\, dx &= \\frac{1}{b} x^a e^{bx} - \\frac{a}{b} x^{a - 1} e^{bx} \\, dx \\\\[5pt]\n&= \\frac{1}{b} x^a e^{bx} - \\frac{a}{b}(\\frac{1}{b} x^{a - 1} e^{bx} - \\frac{a - 1}{b}\\int x^{a - 2} e^{bx} \\, dx) \\\\[5pt]\n&= \\frac{1}{b} x^a e^{bx} - \\frac{a}{b}\\Big[\\frac{1}{b} x^{a - 1} e^{bx} - \\frac{a - 1}{b}(\\frac{1}{b} x^{a - 2} e^{bx} \\int x^{a - 3} e^{bx} \\, dx)\\Big] \\\\[5pt]\n&\\ldots.  \\nonumber\n\\end{align}\n\nRewriting and combining terms, we see that the process of integration by parts proceeds indefinitely like so:\n\n\\begin{align}\n\\int x^a e^{bx} \\, dx &= \\frac{1}{b} x^a e^{bx} - \\frac{a}{b^2} x^{a - 1} e^{bx} + \\frac{a(a - 1)}{b^3} x^{a - 2} e^{bx} - \\frac{a(a - 1)(a - 2)}{b^4} x^{a - 3} e^{bx} + \\ldots \\nonumber \\\\[5pt]\n&+ \\frac{a(a - 1) \\ldots (a - a)}{b^{a + 2}} e^{bx} + \\ldots.\n\\end{align}\n\nNote that the last term written above is in fact zero, and all terms after it vanish as well. So we can rewrite our integral as the sum\n\n\\begin{equation}\n\\int x^a e^{bx} \\, dx = \\sum_{n = 0}^{a} (-1)^n \\frac{a!}{b^{n + 1} (a - n)!} x^{a - n} e^{bx}.\n\\end{equation}\n\nSubstituting our original symbols for the placeholders a, b, c, and x into expression (\\ref{e:eq33}) and evaluating the integral on the limits 0 to $\\infty$ gives\n\n\\begin{align}\n\\label{e:eq39}\n&\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\int_{\\lambda' = 0}^{\\infty} \\lambda'^{\\sum_{m = 1}^{M} n_m + \\alpha - 1} e^{-(M + \\beta) \\lambda'} \\, d\\lambda' \\nonumber \\\\[5pt]\n= &\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\sum_{n = 0}^{N + \\alpha - 1} (-1)^n \\frac{(N + \\alpha - 1)!}{\\Big[-(M + \\beta)\\Big]^{n + 1} (N + \\alpha - 1 - n)!} \\lambda'^{N + \\alpha - 1 - n} e^{-(M + \\beta)\\lambda'}\\Big|_{\\lambda' = 0}^{\\infty},\n\\end{align}\n\nwhere we have let $N = \\sum_{m = 1}^{M} n_m$. To evaluate the right hand side of the above equation, we can first note that the lower bound of the limit vanishes at $\\lambda' = 0$. We can compute the upper bound by noting that the final two terms after the fraction bar are of the form\n\n\\begin{equation}\nx^a e^{-bx},\n\\end{equation}\n\nwhere $a = N + \\alpha - 1 - n$, $b = M + \\beta$, and $x = \\lambda'$. Its limit as $x \\to \\infty$ can be evaluated using the Taylor series expansion of the exponential function:\n\n\\begin{align}\n\\lim_{x \\to \\infty} x^a e^{-bx} &= \\lim_{x \\to \\infty} \\frac{x^a}{e^{bx}} \\\\[5pt]\n&= \\lim_{x \\to \\infty} \\frac{x^a}{\\sum_{n = 0}^{\\infty} \\frac{b^n x^n}{n!}} \\\\[5pt]\n&= \\lim_{x \\to \\infty} \\frac{x^a}{\\frac{b^x x^x}{x!}} \\\\[5pt]\n&= \\lim_{x \\to \\infty} \\frac{x^a x!}{(bx)^x}.\n\\end{align}\n\nSince the $x^x$ term in the denominator increases more rapidly than the x! term in the numerator,\n\n\\begin{equation}\n\\lim_{x \\to \\infty} x^a e^{-bx} = 0.\n\\end{equation}\n\nThus it appears at first that the entire sum $\\sum_{n = 0}^{N + \\alpha - 1}$ in equation (\\ref{e:eq39}) collapses to zero! This is not the case, however: the single term in the sum where $N + \\alpha - 1 - n = 0$ leaves $\\lambda'^{N + \\alpha - 1 - n} e^{-(M + \\beta)\\lambda'}\\Big|_{\\lambda' = 0}^{\\infty}$ undefined. We see that at the lower bound, the $\\lambda'$ term is of the form\n\n\\begin{align}\n\\lim_{\\lambda' \\to 0} \\lambda'^0 &= \\lim_{\\lambda' \\to 0} 1 \\\\[5pt]\n&= 1,\n\\end{align}\n\nso\n\n\\begin{align}\n\\lambda'^{N + \\alpha - 1 - n} e^{-(M + \\beta)\\lambda'}\\Big|_{\\lambda' = 0}^{\\infty} &= e^{-(M + \\beta)\\lambda'}\\Big|_{\\lambda' = 0}^{\\infty} \\\\[5pt]\n&= -1.\n\\end{align}\n\nWe now see that the sum in the right hand side of equation (\\ref{e:eq39}) is nonzero for the single term where $n = N + \\alpha - 1$, and that this term is equal to\n\n\\begin{align}\n\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} (-1)^{N + \\alpha - 1} \\frac{(N + \\alpha - 1)!}{(-1)^{N + \\alpha} (M + \\beta)^{N + \\alpha}}(-1).\n\\end{align}\n\nNoting that all (-1) terms in the above expression cancel with one another, we find that both sides of equation (\\ref{e:eq39}), and thus also the denominator in equation (\\ref{e:eq32}), are equivalent to\n\n\\begin{equation}\n\\label{e:eq51}\n\\frac{\\beta^{\\alpha}}{(M + \\beta)^{N + \\alpha}}\\frac{\\Gamma(N + \\alpha)}{\\Gamma(\\alpha)}.\n\\end{equation}\n\nSubstituting this back into equation (\\ref{e:eq32}) gives \n\n\\begin{align}\nP(\\lambda\\,|\\,\\{n_m\\}) &= \\frac{\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\lambda^{N + \\alpha - 1} e^{-(M + \\beta) \\lambda}}{\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)}\\frac{\\Gamma(N + \\alpha)}{(M + \\beta)^{N + \\alpha}}} \\\\[5pt]\n&= \\frac{(M + \\beta)^{N + \\alpha}}{\\Gamma(N + \\alpha)} \\lambda^{N + \\alpha - 1} e^{-(M + \\beta) \\lambda} \\\\[5pt]\n&= f_{gamma(N + \\alpha,M + \\beta)}(\\lambda).\n\\end{align}\n\nAltogether, then, we see that for a series of sequential observations $\\{n_1, n_2, \\ldots, n_M\\}$, Bayes' theorem\n\n\\begin{equation}\nP(\\lambda\\,|\\,\\{n_m\\}) = \\frac{P(\\{n_m\\}\\,|\\,\\lambda) P(\\lambda)}{\\int_{\\lambda' = 0}^{\\infty} P(\\{n_m\\}\\,|\\,\\lambda') P(\\lambda') \\, d\\lambda'}\n\\end{equation}\n\nis equivalent to\n\n\\begin{equation}\nf_{gamma(\\sum_{m = 1}^{M} n_m + \\alpha,M + \\beta)}(\\lambda) = \\frac{\\Big[\\prod_{m = 1}^{M} f_{Poisson(\\lambda)}(n_m)\\Big] f_{gamma(\\alpha,\\beta)}(\\lambda)}{\\int_{\\lambda' = 0}^{\\infty} \\Big[\\prod_{m = 1}^{M} f_{Poisson(\\lambda')}(n_m)\\Big] f_{gamma(\\alpha,\\beta)}(\\lambda') \\, d\\lambda'}\n\\end{equation}\n\nfor a Poisson likelihood and a gamma-distributed prior. Note that this gives a posterior distribution of the same type as the prior distribution. Therefore, the conjugate prior to a Poisson likelihood is a gamma distribution.\n\n\\section{Mode of a gamma distribution}\n\\label{a:mode_derivation}\nHere we derive the expression for the mode of a gamma distribution as a function of its parameters.\n\nA gamma distribution over $\\lambda$ with shape and rate parameters $\\alpha,\\beta$ is given by the probability density function\n\n\\begin{equation}\nf_{gamma(\\alpha,\\beta)}(\\lambda) = \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\lambda^{\\alpha - 1} e^{-\\beta\\lambda}.\n\\end{equation}\n\nTo find the maximum we take the partial derivative with respect to $\\lambda$ and set it equal to zero:\n\n\\begin{align}\n\\frac{\\partial f_{gamma(\\alpha,\\beta)}(\\lambda)}{\\partial \\lambda} &= \\frac{\\partial}{\\partial \\lambda} \\Big(\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\lambda^{\\alpha - 1} e^{-\\beta\\lambda}\\Big) \\\\[5pt]\n&= \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\Big[(\\alpha - 1)\\lambda^{\\alpha - 2} e^{-\\beta\\lambda} - \\beta\\lambda^{\\alpha - 1} e^{-\\beta\\lambda}\\Big] \\\\[5pt]\n&= 0.\n\\end{align}\n\nSince $\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)}$ is assumed to be nonzero, this relation is satisfied when\n\n\\begin{equation}\n(\\alpha - 1)\\lambda^{\\alpha - 2} e^{-\\beta\\lambda} - \\beta\\lambda^{\\alpha - 1} e^{-\\beta\\lambda} = 0;\n\\end{equation}\n\nthat is, when\n\n\\begin{align}\n(\\alpha - 1)\\lambda^{\\alpha - 2} e^{-\\beta\\lambda} &= \\beta\\lambda^{\\alpha - 1} e^{-\\beta\\lambda} \\\\[5pt]\n(\\alpha - 1) &= \\beta\\lambda\n\\end{align}\n\nor when\n\n\\begin{equation}\n\\frac{\\alpha - 1}{\\beta} = \\lambda.\n\\end{equation}\n\nSo we take $\\hat\\lambda = \\frac{\\alpha - 1}{\\beta}$ to be the mode of a gamma distribution over $\\lambda$.\n\n\\section{Negative binomial distribution as a gamma-Poisson mixture}\n\\label{a:mixture_derivation}\nHere we show that a continuous mixture of Poisson distributions where the mixing distribution is a gamma distribution yields a negative binomial distribution.\n\nConsider the continuous mixture for positive $\\lambda$ of a Poisson distribution over $n$ with mean rate $\\lambda$ and a gamma distribution over $\\lambda$ with shape and rate parameters $\\alpha,\\beta$:\n\n\\begin{align}\n\\int_{\\lambda = 0}^{\\infty} f_{Poisson(\\lambda)}(n) f_{gamma(\\alpha,\\beta)}(\\lambda) \\, d\\lambda &= \\int_{\\lambda = 0}^{\\infty} \\frac{\\lambda^n e^{-\\lambda}}{n!} \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\lambda^{\\alpha - 1} e^{-\\beta\\lambda} \\, d\\lambda \\\\[5pt]\n&= \\frac{\\beta^{\\alpha}}{n!\\,\\Gamma(\\alpha)} \\int_{\\lambda = 0}^{\\infty} \\lambda^{\\alpha + n - 1} e^{-(1 + \\beta)\\lambda} \\, d\\lambda.\n\\label{e:eq58}\n\\end{align}\n\nThe right hand side of the above equation contains an integral of the form dealt with in equations (\\ref{e:eq33}-\\ref{e:eq51}). Using the same approach as before, we find that\n\n\\begin{equation}\n\\int_{\\lambda = 0}^{\\infty} \\lambda^{\\alpha + n - 1} e^{-(1 + \\beta)\\lambda} \\, d\\lambda = (n + \\alpha - 1)!\\,(1 + \\beta)^{-(\\alpha + n)}.\n\\end{equation}\n\nSubstituting this into the right hand side of equation (\\ref{e:eq58}) and performing further manipulations gives\n\n\\begin{align}\n\\frac{\\beta^{\\alpha}}{n!\\,\\Gamma(\\alpha)} (n + \\alpha - 1)!\\,(1 + \\beta)^{-(\\alpha + n)} &= \\frac{\\Gamma(\\alpha + n)}{n!\\,\\Gamma(\\alpha)} \\frac{\\beta^{\\alpha + n}}{(1 + \\beta)^{\\alpha + n} \\beta^n} \\\\[5pt]\n&= \\frac{\\Gamma(\\alpha + n)}{n!\\,\\Gamma(\\alpha)} \\Big(\\frac{\\beta}{1 + \\beta}\\Big)^{\\alpha + n} \\Big(\\frac{1}{\\beta}\\Big)^n.\n\\label{e:eq61}\n\\end{align}\n\nIsolating and performing manipulations on the two rightmost terms of the above equation gives\n\n\\begin{align}\n\\Big(\\frac{\\beta}{1 + \\beta}\\Big)^{\\alpha + n} \\Big(\\frac{1}{\\beta}\\Big)^n &= \\Big(\\frac{\\beta}{1 + \\beta}\\Big)^{\\alpha} \\Big(\\frac{\\beta}{1 + \\beta}\\Big)^n \\Big(\\frac{1}{\\beta}\\Big)^n \\\\[5pt]\n&= \\Big(\\frac{\\beta}{1 + \\beta}\\Big)^{\\alpha} \\Big(\\frac{1}{1 + \\beta}\\Big)^n \\\\[5pt]\n&= \\Big(\\frac{1}{1 + \\beta}\\Big)^n \\Big(1 - \\frac{1}{1 + \\beta}\\Big)^{\\alpha},\n\\end{align}\n\nonce it is seen that $\\frac{\\beta}{1 + \\beta} = \\frac{1 + \\beta - 1}{1 + \\beta} = 1 - \\frac{1}{1 - \\beta}$.\n\nSubstituting this back into the right hand side of equation (\\ref{e:eq61}) and reducing further, we have\n\n\\begin{align}\n\\frac{\\Gamma(\\alpha + n)}{n!\\,\\Gamma(\\alpha)} \\Big(\\frac{1}{1 + \\beta}\\Big)^n \\Big(1 - \\frac{1}{1 + \\beta}\\Big)^{\\alpha} &= \\frac{(n + \\alpha - 1)!}{n!\\,(\\alpha - 1)!} \\Big(\\frac{1}{1 + \\beta}\\Big)^n \\Big(1 - \\frac{1}{1 + \\beta}\\Big)^{\\alpha} \\\\[5pt]\n&= \\binom{n + \\alpha - 1}{n} \\Big(\\frac{1}{1 + \\beta}\\Big)^n \\Big(1 - \\frac{1}{1 + \\beta}\\Big)^{\\alpha} \\\\[5pt]\n&= f_{NB(\\alpha,\\frac{1}{1 + \\beta})}(n).\n\\end{align}\n\nThe result is a negative binomial distribution with parameters $\\alpha,\\frac{1}{1 + \\beta}$. So, altogether we can write\n\n\\begin{equation}\n\\int_{\\lambda = 0}^{\\infty} f_{Poisson(\\lambda)}(n) f_{gamma(\\alpha,\\beta)}(\\lambda) \\, d\\lambda = f_{NB(\\alpha,\\frac{1}{1 + \\beta})}(n).\n\\end{equation}\n\nTherefore, a continuous mixture of Poisson distributions where the mixing distribution is a gamma distribution yields a negative binomial distribution.\n\n\\end{document}\n", "meta": {"hexsha": "cf4ad283d55f3fa5deb7ccaa60e02212dd27fc83", "size": 12357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "proofs.tex", "max_stars_repo_name": "lukearend/bayesocampus", "max_stars_repo_head_hexsha": "52a67a2c4354cc11c88035b4474d1411fe9ba501", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-07-18T15:11:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-31T00:37:08.000Z", "max_issues_repo_path": "proofs.tex", "max_issues_repo_name": "lukearend/bayesocampus", "max_issues_repo_head_hexsha": "52a67a2c4354cc11c88035b4474d1411fe9ba501", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "proofs.tex", "max_forks_repo_name": "lukearend/bayesocampus", "max_forks_repo_head_hexsha": "52a67a2c4354cc11c88035b4474d1411fe9ba501", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-01T14:11:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-01T14:11:17.000Z", "avg_line_length": 51.9201680672, "max_line_length": 382, "alphanum_fraction": 0.627417658, "num_tokens": 4561, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587158, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7013975588974719}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Surface Area}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nVarious exercises related to the computation of areas of surfaces of revolution.\n\\end{abstract}\n\\maketitle\n\n\n\\begin{exercise}%[APEX0704ARCL29]\nFind the surface area of the solid formed by revolving \\(y=2x\\) on \\([0,1]\\) about the \\(x\\)-axis.\n\\[ A = \\answer{2\\pi\\sqrt{5}}. \\]\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0704ARCL30]\nFind the surface area of the solid formed by revolving \\(y=x^2\\) on \\([0,1]\\) about the \\(y\\)-axis.\n\\begin{hint}\nTo compute the integral, you will need to make a substitution like $u = 1 + 4x^2$ or something similar.\n\\end{hint}\n\\[ A = \\answer{\\frac{(5 \\sqrt{5} - 1) \\pi}{6}}. \\]\n%\\(2\\pi\\int_0^1 x\\sqrt{1+4x^2}\\ dx = \\pi/6(5\\sqrt{5}-1)\\)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0704ARCL31]\nFind the surface area of the solid formed by revolving \\(y=x^3\\) on \\([0,1]\\) about the \\(x\\)-axis.\n\\begin{hint}\nTo compute the integral, you will need to make a substitution like $u = 1 + 9 x^4$ or something similar.\n\\end{hint}\n\\[ L = \\answer{\\frac{(10 \\sqrt{10} - 1) \\pi}{27}}. \\]\n%\\(2\\pi\\int_0^1 x^3\\sqrt{1+9x^4}\\ dx = \\pi/27(10\\sqrt{10}-1)\\)\n%\n%\n\\end{exercise}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%%%%%[2016.36]\nGive an integral formula for the area of the surface generated by revolving the curve $y = \\ln x$ between $x=1$ and $x=2$ about the $y$-axis. Explain your answer. You do not need to evaluate the integral. \n\\begin{multiplechoice}\n\\choice[correct]{\\(\\displaystyle \\int_1^2 2 \\pi \\sqrt{x^2+1} ~ dx\\)}\n\\choice{\\(\\displaystyle \\int_1^2 2 \\pi (\\ln x) \\frac{\\sqrt{x^2+1}}{x} ~ dx\\)}\n\\choice{\\(\\displaystyle \\int_1^2 \\frac{2 \\pi}{x} \\sqrt{1 + (\\ln x)^2} ~ dx\\)} \n\\choice{\\(\\displaystyle \\int_1^2 \\frac{1}{2 \\pi \\sqrt{x^2+1}} ~ dx\\)}\n\\choice{\\(\\displaystyle \\int_1^2 2 \\pi (\\ln x) \\frac{x}{\\sqrt{x^2+1}} ~ dx\\)}\n\\choice{\\(\\displaystyle \\int_1^2 \\frac{2 \\pi x}{\\sqrt{1 + (\\ln x)^2}} ~ dx\\)}\n\\end{multiplechoice}\n\\end{question}\n\n\n\\begin{question}\n The curve $y = \\frac{x^2}{8}$ between $x=0$ and $x = 3$ is revolved around the $y$-axis. Compute the surface area of the resulting surface.\n\\begin{multipleChoice}\n\\choice{$\\displaystyle \\frac{31 \\pi}{6}$}\n\\choice{$\\displaystyle \\frac{41 \\pi}{6}$}\n\\choice[correct]{$\\displaystyle \\frac{61 \\pi}{6}$}\n\\choice{$\\displaystyle \\frac{71 \\pi}{6}$}\n\\choice{$\\displaystyle \\frac{91 \\pi}{6}$}\n\\choice{none of the above}\n\\end{multipleChoice}\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "1d8562a54d840f0dde199c68998c7d0aa8b74640", "size": 2493, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "arclengths/06surfacepractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "arclengths/06surfacepractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "arclengths/06surfacepractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.1126760563, "max_line_length": 205, "alphanum_fraction": 0.6586442038, "num_tokens": 917, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7013975493747211}}
{"text": "\\newpage\\section{Binomial Identities}\n\n\n\n\\theo{https://en.wikipedia.org/wiki/Vandermonde's_identity}{Vandermonde's identity}{\n    For every positive integer $m, n, k$\n    \\begin{center}\n        \\tcboxmath[arc=0mm, colback=black!5!white, boxrule=0mm]{\n            \\binom{m+n}{k} = \\sum_{i=0}^{k} \\binom{m}{i}\\binom{n}{k-i}\n        }\n    \\end{center}\n    \\begin{center}\n        \\tcboxmath[arc=0mm, colback=black!5!white, boxrule=0mm]{\n            {2n \\choose n} = {n \\choose 0}^2+ {n \\choose 1}^2 \\dots + {n \\choose n}^2\n        }\n    \\end{center}\n}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1061914p4600670}{Somewhere}{M}{\n    Let $n$ and $m$ be positive integers with $n<m$. Prove that \n    \\begin{center}\n        \\tcboxmath[arc=0mm, colback=black!5!white, boxrule=0mm]{\n        \\sum_{k=0}^n (-1)^{n-k}\\frac{1}{m-k}\\binom{n}{k}=\\frac{1}{(n+1)\\binom{m}{n+1}}\n        }\n    \\end{center} \n}\n\n\\solu{[MellowMelon]\n    The left side is the $n$th finite difference of the unique $n$th degree\n    polynomial satisfying $P(x) = \\frac{1}{m-x}$ for $x = 0,1, \\ldots, n$.\n    This means that if $a_n$ is the $x^n$ coefficient of $P$, then the left\n    side is equal to $n! \\cdot a_n$. Setting this equal to the right side, it\n    suffices to show that\n    \\[ a_n = \\frac{1}{(n+1)! \\binom{m}{n+1}} = \\frac{1}{m(m-1)\\cdots (m-n)}. \\]\n\n    Let $Q(x) = (x-m)P(x) + 1$. Then $Q$ is degree $n+1$, has roots\n    $0,1,\\ldots,n$, and has leading coefficient $a_n$. So\n    \\[ Q(x) = a_nx(x-1)(x-2)\\cdots (x-n). \\]\n    We also know $Q(m) = 1$. Plugging $x = m$ into the above equation and\n    isolating $a_n$ gives us exactly what we need to show.\n}\n\n\\rem{\n    The idea to express the left hand side with finite differences is pretty\n    simple. The crux idea is to finding a $Q$ that works. Since we have to\n    show $a_n\\left(m\\right)\\left(m-1\\right) \\dots \\left(m-n\\right) =1$, which\n    looks like a polynomial with leading coefficient $a_n$ with roots $0, 1, 2,\n    \\dots n$ and $Q(m) = 1$. How can we get that?\n\n    The takeaway is, if the problem requires you to find a polynomial that\n    almost looks like the one given in the problem, try to modify the given\n    polynomial in some way first.\n\n    In this particular case was to modify $P$ bu using the fact $(x-m)P(x) =\n    -1$.\n}\n\n\\solu{[Hydroxide]\n    Let $P$ be the unique polynomial of degree at most $n$ such that\n    $P(0)=P(1)=\\cdots=P(n)=1$. Obviously $P(x)=1$, but we can also find $P$\n    from Lagrange interpolation. This gives us the equality of polynomials\n\n    \\[ \\sum_{k=0}^n \\frac{(x-0)\\cdots (x-(k-1))(x-(k+1))\\cdots\n    (x-n)}{(k-0)\\cdots (k-(k-1))(k-(k+1))\\cdots (k-n)}=1. \\]\n\n    Plugging in $x=m$ and doing a ton of rearranging gives the desired result.\n}\n\n\\rem{\n    Both solutions can easily be extended to prove the more general result\n    that if $0\\le p<n<m$ are integers, then\n    \\begin{center}\n        \\tcboxmath[arc=0mm, colback=black!5!white, boxrule=0mm]{\n    \\sum_{k=0}^n (-1)^{n-k}\\frac{1}{m-k} \\binom{n}{k}k^p=\\frac{m^p}{(n+1)\\binom{m}{n+1}} \n        }\n    \\end{center}\n}\n\n\\prob{https://artofproblemsolving.com/community/c6h358774}{USA TST 2010\n    P8}{M, 10/10}{\n    Let $m,n$ be positive integers with $m \\geq n$, and let $S$ be the\n    set of all $n$-term sequences of positive integers $(a_1, a_2, \\ldots\n    a_n)$ such that $a_1 + a_2 + \\cdots + a_n = m$. Show that \n    \\begin{center}\n        \\tcboxmath[arc=0mm, colback=black!5!white, boxrule=0mm]{\n            \\sum_S 1^{a_1} 2^{a_2} \\cdots n^{a_n} = {n \\choose n} n^m - \n            {n \\choose n-1} (n-1)^m + \\cdots + (-1)^{n-2} {n \\choose 2} 2^m +\n            (-1)^{n-1} {n \\choose 1}\n        } \n    \\end{center}\n}\n \n\n\\solu{[Combinatorial, MellowMelon] \n    Look at the right side, try to translate it to\n    combinatorial model. If we had used the inclusion-exclusion method, the\n    right side would be the number of ways to color $ m $ balls with\n    $ n $ colors, with each color appearing at least once. Now our remaining\n    job is to prove the same for the left side.\\\\\n\n    Trying to interpret the left hand side, we first notice that we need to\n    partition the balls in $n$ parts with sizes $a_1, a_2, \\dots  a_n$ where\n    the first partition will have $1$ color to choose from, the second one\n    will have $2$ and so on. We need to refine this idea for using it.\n}\n\n\n\\solu{[Generating Function, MellowMelon]\n    The first step of a gf solution is to decide on a gf solution. Now we can\n    think of the left hand side as a function of $m$, namely $b_m$. So we can\n    make a generating function with it.\\\\\n\n    We let $F_n(x) = b_0 + b_1 x + b_2 x^2 + \\cdots$ and so we get:\n    \\begin{align*}\n        F_n(x) &= (x+x^2+\\cdots)(2x+4x^2+\\cdots)\\cdots (nx+n^2x^2+\\cdots), \\\\\n               &= \\frac{x}{1-x} \\frac{2x}{1-2x} \\cdots \\frac{nx}{1-nx}, \\\\\n               &= \\frac{n! x^n}{(1-x)(1-2x) \\cdots (1-nx)}. \\\\\n    \\end{align*}\n\n    Now we need a generating function for the right hand side as well. The\n    right hand side looks the $n$th finite difference of the function\n    $_mg_0(x) = x^m$, that is \n    \\[_mg_n(0) = {n \\choose n} n^m - {n \\choose n-1} (n-1)^m + \\cdots +\n    (-1)^{n-2} {n \\choose 2} 2^m + (-1)^{n-1} {n \\choose1}\\] \n\n    Now we can make a generating function with this:\n    \\[G(y) =\\ _0g_n(0)y^0 +\\ _1g_n(0)y^1 \\dots \\]  \n    But this isn't very useful as we are getting the $n$th finite differences\n    on the right side, where we want to work with the original polynomials.\\\\\n\n    So what we do is, we unravel the $_mg_n(0)$ as original polynomials and\n    get:\n    \\[G(x, y) = x^0y^0 + x^1y^1 + x^2+y^2\\dots \\]\n    Where our desired generating function for $n$ is:\n    \\[G_n(0, y) =\\ _0g_n(0)y^0 +\\ _1g_n(0)y^1 +\\dots \\] \n    \n    And we want to show that \n    \\[G_n(0, y) = \\frac{n! x^n}{(1-x)(1-2x) \\cdots (1-nx)} \\] \n\n    Now we notice that we can actually use induction on $n$ since we definded\n    \\[G_{n+1}(x, y) = G_n(x+1, y) - G_n(x, y)\\]\n\n    And so we are done.\n}\n\n\n\\lem{}{\n    \\[G(x)=\\sum_{n=0}^{\\infty} \\binom{n+k}{k} x^n=\\frac{1}{(1-x)^{k+1}}\\]\n}\n\n\\begin{prooof}\n    We have the above relation because ${n+k \\choose k}$ can be interpret as\n    the number of ways write $n$ as the sum of $k+1$ numbers. And the\n    generating function for that is:\n    \\[G(x) = (1+x+x^2\\dots )^{k+1}\\] \n\\end{prooof}\n\n\\prob{https://artofproblemsolving.com/community/c6h1076934p5964577}{Binom1}{}{\n    Solve for positive integer $n$\n    \\begin{center}\n        \\tcboxmath[arc=0mm, colback=black!5!white, boxrule=0mm]{\n            {2n \\choose 0}-{2n-1 \\choose 1}+{2n-2 \\choose 2}- \\dots  +(-1)^n\n            {n \\choose n}=?\n        }\n    \\end{center}\n}\n\n\\solu{[Generating funtion, Tintarn]\n    Denote this sum $a_n$. Denote $F(x)=\\sum_{n=0}^{\\infty} a_nx^{2n}$.\n    \\begin{align*}\n        F(x)&=\\sum_{k=0}^{\\infty} (-1)^k \\sum_{n=0}^{\\infty} \\binom{2n-k}{k}\n        x^{2n}\\\\\n        &=\\sum_{k=0}^{\\infty} (-x^2)^k \\sum_{n=0}^{\\infty} \\binom{2n+k}{k}\n        x^{2n}\n    .\\end{align*}\n    Now, using the well-known power series\n    \\[\\boxed{G(x)=\\sum_{n=0}^{\\infty} \\binom{n+k}{k}\n    x^n=\\frac{1}{(1-x)^{k+1}}}\\]\n    we find\n    \\[\\sum_{n=0}^{\\infty} \\binom{2n+k}{k} x^{2n}=\\frac{G(x)+G(-x)}{2}\\]\n    and hence\n    \\begin{align*}\n        F(x)&=\\frac{1}{2(1-x)} \\sum_{k=0}^{\\infty} \\left( \\frac{x^2}{x-1} \\right)^k\n        +\\frac{1}{2(1+x)} \\sum_{k=0}^{\\infty} \\left( \\frac{-x^2}{x+1} \\right)^k\\\\[.5em]\n            &=\\frac{1}{2(x^2-x+1)}+\\frac{1}{2(x^2+x+1)}\\\\[.5em]\n            &=\\frac{x^2+1}{x^4+x^2+1}\\\\[.5em]\n            &=\\frac{1-x^4}{1-x^6}\\\\\n            &=(1-x^4)(1+x^6+x^{12}+x^{18}+\\dotsc)\\\\\n            &=1-x^4+x^6-x^{10}+x^{12}-x^{16}+\\dots\n    .\\end{align*}\n\n    \\vspace{1em}\n    and hence $\\boxed{a_{3k}=1, a_{3k+1}=0, a_{3k+2}=-1}$.\n}\n\n\n\\solu{[Combinaorial Model, MellowMelon]\n    Consider the number of ways to tile a $1 \\times 2n$ rectangle with squares\n    and dominoes. Let $E$ be the set of ways to do it with an even number of\n    dominoes, and let $O$ be the same for odd. We want to find $|E| - |O|$.\\\\\n\n    Trying some basic cases, we see that the only values we get are $-1, 0,\n    1$. So we want to find a pairing between the two sets that is almost a\n    bijection, but doesn't work for only one element. And that bijection is:\\\\\n\n    \\textit{Consider the first consecutive pair of squares or domino which\n    either comes at the very start or comes right after another domino. Swap\n    the pair of squares to a domino or vice versa.}\n}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1076934p5964577}{Binom 2}{}{\n    \\[{n \\choose 0}^2-{n \\choose 1}^2+{n \\choose 2}^2-\\dots +(-1)^n{n \\choose n}^2=?\\]\n}\n\n\\solu{[Generating function, TinTarn]\n    Denote \\[f(m,n)=\\sum_{k=0}^{\\infty} (-1)^k \\binom{n}{k} \\binom{n}{m-k}\\]\n    We are looking for $f(n,n)$.  We have\n    \\begin{align*}\n        \\sum_{m=0}^{\\infty} f(m,n) x^m &=\\sum_{k=0}^{\\infty} (-1)^k \\binom{n}{k}\n        \\sum_{m=0}^{\\infty} \\binom{n}{m-k} x^m\\\\\n        &=\\left[\\sum_{k=0}^{\\infty} (-x)^k \\binom{n}{k} \\right]\n        \\left[\\sum_{m=0}^{\\infty} x^m \\binom{n}{m} \\right]\\\\\n        &=(1-x)^n(1+x)^n\\\\\n        &=(1-x^2)^n\\\\\n        &=\\sum_{t=0}^{\\infty} (-1)^t \\binom{n}{t} x^{2t}\n    .\\end{align*}\n\n    Hence we see that for odd $m$ we have $f(m,n)=0$ and hence for odd $n$ we have\n    $\\boxed{f(n,n)=0}$.\\\\\n    \n    Now, for $n=2k$ even, we find $\\boxed{f(2k,2k)=(-1)^k \\binom{2k}{k}}$.\n}\n\n\\solu{[Combinatorial, MellowMelon]\n    Consider the number of ways to paint the squares of a $2 \\times n$\n    rectangle red and blue such that both rows have the same number of red\n    squares. Let $E$ be the set of ways with an even number of red squares in each\n    row, and let $O$ be the same for odd. We want to find $|E| - |O|$.\\\\\n\n    \\textit{Pair the selections as follows: take the first column with both\n        squares the same color, and flip both colors. This maps elements in\n        $E$ to $O$ and vice versa and is invertible, so except cases where the\n    pairing is undefined, $E$ and $O$ have the same number of elements.}\n}\n", "meta": {"hexsha": "28bbea1212c1d17ca3992a07199a6189733b8b0e", "size": 9996, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combi/sec2_binom_iden.tex", "max_stars_repo_name": "M-Ahsan-Al-Mahir/BCS_Question_Bank", "max_stars_repo_head_hexsha": "83ff9b542999386ea182863e4f25f0b488d3984f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 48, "max_stars_repo_stars_event_min_datetime": "2020-10-14T17:15:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T19:47:04.000Z", "max_issues_repo_path": "combi/sec2_binom_iden.tex", "max_issues_repo_name": "AnglyPascal/BCS_Question_Bank", "max_issues_repo_head_hexsha": "83ff9b542999386ea182863e4f25f0b488d3984f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "combi/sec2_binom_iden.tex", "max_forks_repo_name": "AnglyPascal/BCS_Question_Bank", "max_forks_repo_head_hexsha": "83ff9b542999386ea182863e4f25f0b488d3984f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-10-15T08:59:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-27T15:19:26.000Z", "avg_line_length": 40.4696356275, "max_line_length": 89, "alphanum_fraction": 0.5915366146, "num_tokens": 3774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234878, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7013975481430086}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Integration by Parts}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nVarious exercises relating to integration by parts.\n\\end{abstract}\n\\maketitle\n\n\nCompute the indefinite integrals below. Since there are many possible answers (which differ by constant values), use the given instructions if needed to choose which possible answer to use.\n\n\\begin{exercise}%[APEX0602IBP05]\n\\[  \\int x\\sin x\\ dx = \\answer{\\sin x - x\\cos x} +C\\]\n(Add a constant to your answer if needed so that it equals $0$ at $x = 0$.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0602IBP06]\n\\[ \\int xe^{-x}\\ dx = \\answer{-e^{-x}-xe^{-x}}+C\\]\n(Add a constant to your answer if needed so that it equals $-1$ at $x = 0$.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0602IBP10]\n\\[  \\int x^3e^{x}\\ dx\\ = \\answer{x^3e^x-3x^2e^x+6xe^x-6e^x}+C\\]\n(Write your answer so that it has no constant term.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0602IBP25]\n\\[ \\int x^2\\ln |x| \\ dx = \\answer{\\frac{1}{3} x^3 \\ln |x|-\\frac{x^3}{9}}+C\\]\nDon't forget absolute values in your logarithm.\n(Add a constant to your answer as necessary so that it equals $-1/9$ at $x = 1$.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0602IBP12]\n\\[ \\int e^x\\sin x\\ dx = \\answer{\\frac{1}{2} e^x(\\sin x-\\cos x)}+C\\]\n(Add a constant to your answer if needed so that it equals $-1/2$ at $x = 0$.)\n\\begin{hint}\nThis is a case in which you need to treat the integration by parts as an equation and \\textit{solve} for the answer.\n\\end{hint}\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0602IBP17]\n\\[ \\int \\arcsin x\\ dx = \\answer{\\sqrt{1-x^2}+x \\arcsin(x)}+C \\]\n(Add a constant to your answer if needed so that it equals $1$ at $x = 0$.)\n\\begin{hint}\nWrite $\\arcsin x = 1 \\cdot \\arcsin x$.\n\\end{hint}\n%\n%\n\\end{exercise}\n\n\\section*{Sample Quiz Questions}\n\\begin{question}%%%%%[IBPibp:explin1413]\n\nCompute the definite integral \n\\[\\int_1^4 e^{3x} (x + 1) ~ dx.\\]\n(Hints won't be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice[correct]{\\(\\displaystyle \\frac{14}{9} e^{12} - \\frac{5}{9} e^{3}\\)}\n\\choice{\\(\\displaystyle \\frac{17}{9} e^{12} - \\frac{5}{9} e^{3}\\)}\n\\choice{\\(\\displaystyle \\frac{17}{9} e^{12} - \\frac{8}{9} e^{3}\\)}\n\\choice{\\(\\displaystyle \\frac{20}{9} e^{12} - \\frac{8}{9} e^{3}\\)}\n\\choice{\\(\\displaystyle \\frac{20}{9} e^{12} - \\frac{11}{9} e^{3}\\)}\n\\choice{\\(\\displaystyle \\frac{23}{9} e^{12} - \\frac{11}{9} e^{3}\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nIntegrate by parts, integrating the exponential and differentiating polynomials.\n\\begin{hint}\n\\[\\begin{aligned}\n    \\int_1^4 e^{3x} &  (x + 1) ~ dx \\\\\n    & = \\left. \\frac{e^{3x}}{3} (x+1) \\right|_1^4 - \\int_1^4 \\frac{e^{3x}}{3} dx \\\\\n    & = \\frac{5}{3} e^{12} - \\frac{2}{3} e^{3} - \\left. \\frac{e^{3x}}{9} \\right|_1^4 \\\\\n    & = \\frac{14}{9} e^{12} - \\frac{5}{9} e^{3}\n\\end{aligned}\\]\n\\end{hint}\n\\end{feedback}\n\n\\end{question}\n\\begin{question}%%%%%[IBPibp:fourier2alt4]\n\nCompute the definite integral \n\\[\\int_{\\pi}^{2 \\pi} x \\sin 4 x ~ dx.\\]\n(Hints won't be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle 0\\)}\n\\choice{\\(\\displaystyle \\frac{\\pi}{4}\\)}\n\\choice[correct]{\\(\\displaystyle -\\frac{\\pi}{4}\\)}\n\\choice{\\(\\displaystyle \\frac{3 \\pi}{4}\\)}\n\\choice{\\(\\displaystyle -\\frac{3 \\pi}{4}\\)}\n\\choice{\\(\\displaystyle \\frac{7 \\pi}{4}\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nIntegrate by parts, integrating the trig functions and differentiating polynomials.\n\\begin{hint}\n\\[ \\begin{aligned}\n    \\int_{\\pi}^{2 \\pi} x & \\sin 4 x ~ dx \\\\\n    & = \\left. - \\frac{\\cos 4x}{4} x \\right|_{\\pi}^{2 \\pi} + \\int_{\\pi}^{2 \\pi} \\frac{\\cos 4x}{4} dx \\\\\n    & = - \\frac{2 \\pi }{4} + \\frac{(-1)^{4} \\pi }{4} - \\left. \\frac{\\sin 4x}{16} \\right|_{\\pi}^{2 \\pi} = -\\frac{\\pi}{4}\n\\end{aligned}\\]\n\\end{hint}\n\\end{feedback}\n\n\\end{question}\n\\begin{question}%%%%%[IBPibp:miscarctan5]\n\nCompute the indefinite integral \n\\[\\int \\arctan 5x ~ dx.\\]\n(Hints won't be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice[correct]{\\(\\displaystyle x \\arctan 5x - \\frac{1}{10} \\ln | 1 + 25x^2|  + C\\)}\n\\choice{\\(\\displaystyle x \\arctan 5x - \\frac{1}{12} \\ln | 1 + 25x^2|  + C\\)}\n\\choice{\\(\\displaystyle x \\arctan 5x - \\frac{1}{14} \\ln | 1 + 25x^2|  + C\\)}\n\\choice{\\(\\displaystyle x \\arctan 5x + \\frac{1}{10} \\ln | 1 + 25x^2|  + C\\)}\n\\choice{\\(\\displaystyle x \\arctan 5x + \\frac{1}{12} \\ln | 1 + 25x^2|  + C\\)}\n\\choice{\\(\\displaystyle x \\arctan 5x + \\frac{1}{14} \\ln | 1 + 25x^2|  + C\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nIntegrate by parts, integrating the coefficient 1 and differentiating arctangent.\n\\begin{hint}\n\\[\\begin{aligned}\n    \\int & \\arctan 5x ~ dx \\\\\n    & = x \\arctan 5x - \\int \\frac{5x}{1+25x^2} ~ dx \\\\\n    & = x \\arctan 5x - \\frac{1}{10} \\int \\frac{50x}{1+25x^2} ~ dx \\\\\n    & = x \\arctan 5x - \\frac{1}{10} \\ln | 1 + 25x^2|  + C\n\\end{aligned}\\]\n\\end{hint}\n\\end{feedback}\n\n\\end{question}\n\\begin{question}%%%%%[IBPibp:expcos35]\n\nCompute the indefinite integral \n\\[\\int e^{3x}  \\cos 5x ~ dx.\\]\n(Hints won't be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\frac{e^{3x} (2 \\cos 5x + 5 \\sin 5x)}{29} + C\\)}\n\\choice[correct]{\\(\\displaystyle \\frac{e^{3x} (3 \\cos 5x + 5 \\sin 5x)}{34} + C\\)}\n\\choice{\\(\\displaystyle \\frac{e^{3x} ( \\cos 5x + 3 \\sin 5x)}{20} + C\\)}\n\\choice{\\(\\displaystyle \\frac{e^{3x} ( \\cos 5x + 2 \\sin 5x)}{15} + C\\)}\n\\choice{\\(\\displaystyle \\frac{e^{3x} (2 \\cos 5x + 7 \\sin 5x)}{53} + C\\)}\n\\choice{\\(\\displaystyle \\frac{e^{3x} (3 \\cos 5x + 7 \\sin 5x)}{58} + C\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nIntegrate by parts, integrating the exponential and differentiating cosine (or vice-versa), then solve for the antiderivative.\n\\begin{hint}\n\\[ \\begin{aligned}\n    \\int e^{3x} & \\cos 5x ~ dx \\\\\n    & = \\frac{e^{3x}}{3} \\cos 5x - \\int \\frac{e^{3x}}{3} (-5 \\sin 5x) ~ dx \\\\\n    & = \\frac{e^{3x} \\cos 5x}{3} + \\frac{5}{3} \\int e^{3x} \\sin 5x ~ dx \\\\\n    & = \\frac{e^{3x} \\cos 5x}{3} + \\frac{5}{3} \\frac{e^{3x}}{3} \\sin 5x - \\frac{5}{3} \\int \\frac{e^{3x}}{3} (5 \\cos 5x) ~ dx \\\\\n    & = \\frac{e^{3x} (3 \\cos 5x + 5 \\sin 5x)}{9} - \\frac{25}{9} \\int e^{3x} \\cos 5x ~ dx  \\\\\n    \\Rightarrow   & \\qquad \\frac{34}{9}  \\int e^{3x}  \\cos 5x ~ dx  = \\frac{e^{3x} (3 \\cos 5x + 5 \\sin 5x)}{9} \\\\\n    \\Rightarrow & \\qquad  \\int  e^{3x}  \\cos 5x ~ dx = \\frac{e^{3x} (3 \\cos 5x + 5 \\sin 5x)}{34} + C\n\\end{aligned}\\]\n\\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%%%%%[2015C.11]\n\nCompute the integral below.\n\\[ \\int_{\\frac{1}{2}}^\\infty \\frac{ \\ln (2x)}{x^2} dx \\]\n\\begin{multiplechoice}\n\\choice{\\(1 - \\ln 2\\)}\n\\choice[correct]{\\(2\\)}\n\\choice{\\(\\displaystyle \\ln 2 - \\frac{1}{2}\\)}\n\\choice{\\(\\displaystyle \\frac{1}{2}\\)}\n\\choice{\\(2 - 2 \\ln 2\\)}\n\\choice{the integral diverges}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2016C.05]\n\nCompute the indefinite integral indicated below. [Hint: Write \\(\\displaystyle \\frac{1}{\\cos^2 \\theta} = \\sec^2 \\theta\\) and integrate by parts.]\n\\[ \\int \\left( 1 + \\frac{\\ln | \\sin \\theta|}{\\cos^2 \\theta} \\right) d \\theta \\]\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle (\\sin \\theta) \\ln |\\sin \\theta| + C\\)}\n\\choice{\\(\\displaystyle (\\cos \\theta) \\ln |\\sin \\theta| + C\\)}\n\\choice[correct]{\\(\\displaystyle (\\tan \\theta) \\ln |\\sin \\theta| + C\\)} \n\\choice{\\(\\displaystyle (\\csc \\theta) \\ln |\\sin \\theta| + C\\)}\n\\choice{\\(\\displaystyle (\\sec \\theta) \\ln |\\sin \\theta| + C\\)}\n\\choice{\\(\\displaystyle (\\cot \\theta) \\ln |\\sin \\theta| + C\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\end{document}\n", "meta": {"hexsha": "1782fba75e200dec30107e6fb04c6b09b095b0c4", "size": 7561, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "techniques/09ibppractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "techniques/09ibppractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "techniques/09ibppractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.8829268293, "max_line_length": 189, "alphanum_fraction": 0.615394789, "num_tokens": 3028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.7013975356559067}}
{"text": "\\chapter{Second Order Boundary Value Problems}\n\n\\section{2nd order two-point boundary value problems}\n\n\\begin{intro}\n  We have already seen, that boundary value problems have very\n  different stability properties than initial value\n  problems. Here, we will discuss a special class of boundary value\n  problems of the form\n  \\begin{gather}\n    \\label{eq:bvp-second:1}\n    -u''(x) + \\beta(x) u'(x) + \\gamma(x)u(x) = f(x),\n    \\qquad u(a) = u_a,\n    \\quad u(b) = u_b.\n  \\end{gather}\n\n  In order to make this problem more amenable to mathematical\n  investigation, we introduce the set\n  \\begin{gather*}\n    \\mathcal B =\n    \\Bigl\\{ u\\in C^2(a,b) \\cap C[a,b]\n    \\;\\Big|\\; u(a) = u_a\\;\\wedge\\; u(b) = u_b\n    \\Bigr\\}.\n  \\end{gather*}\n\n  Then, we can see the left hand side of the differential equation as\n  a differential operator applied to $u$ and thus mapping $\\mathcal B$\n  to the set of continuous functions. Namely, we define\n  \\begin{gather}\n    \\label{eq:fd:2}\n    \\begin{split}\n      L: \\mathcal B &\\to C[a,b] \\\\\n      u & \\mapsto -u'' + \\beta u' + \\gamma u.\n    \\end{split}\n  \\end{gather}\n  In addition, we would like to simplify our life and get rid of the\n  inhomogeneous boundary values $u_a$ and $u_b$. To this end, let\n  \\begin{gather*}\n    u_B(x) = u_a \\frac{b-x}{b-a} + u_b \\frac{x-a}{b-a},\n  \\end{gather*}\n  and introduce the new function $u_0 = u+u_B$. Then, $u_0$ solves\n  the boudnary value problem\n  \\begin{multline*}\n    -u_0''(x) + \\beta(x) u'(x) + \\gamma(x)u(x) = f(x) -\n    \\beta(x)\\frac{u_b-u_a}{b-a} - \\gamma(x)u_B(x),\n    \\\\ u(a) =  u(b) = 0.\n  \\end{multline*}\n  Thus, it is sufficient to consider the boundary value problem\n\\end{intro}\n\n\\input{definitions/bvp-second}\n\n\\begin{remark}\n  This definition exhibits a major change in paradigm. Before, we\n  considered a differential equation as an equation which determines\n  the derivative of a function in a point. Now, we are looking at a\n  linear system of equations, albeit one, which is not of finite\n  dimension. This paradigm change will be essential when we consider\n  partial differential equations in future semesters.\n  \n  On the other hand, the equality in equation~\\eqref{eq:bvp-second:2}\n  is understood point-wise, such that in fact nothing but our point of\n  view has changed.\n\\end{remark}\n\n\\begin{intro}\n  Again, we subdivide the interval $I= [a,b]$ into subintervals, but\n  the subdivision does not involve IVP solvers on subintervals, but\n  much more like in the original subdivision in\n  Definition~\\ref{Definition:partitioning}, the the solution will only\n  be defined at the partitioning points $t_k$, $k=0,\\dots,n$.\n  \n  Thus, like with one-step and multistep methods we will have values\n  $y_0, y_1,\\dots, y_n$, but the sequence has a defined end at $y_n$\n  due to the right boundary of the interval.\n\n  While one-step methods directly discretize the Volterra integral\n  equation in order to compute a solution at every new step,\n  \\textbf{finite difference methods} discretize the differential\n  equation on the whole interval at once and then solve the resulting\n  discrete (finite-dimensional) system of equations.\n\n  We have accompished the first step and decided that instead of\n  function values in every point of the interval $I$, we only\n  approximate $u(t_k)$ in the points of the partition. What is left is\n  the definition of the discrete operator representing the equation.\n\\end{intro}\n\n\\input{definitions/difference-operators}\n\n\\begin{remark}\n  The 3-point stencil is the product of forward and backward\n  difference operators.\n  \\begin{gather*}\n    D^2_h u(x) = D^+_hu(x)D^-_hu(x) = D^-_hu(x)D^+_hu(x).\n  \\end{gather*}\n  For simplicity, we only present finite differences of uniform\n  subdivisions. Nevertheless, the definition of the operators can be\n  extended easily to $h$ changing between intervals.\n\\end{remark}\n\n\\input{definitions/fd-consistency}\n\\input{theorems/fd-consistency}\n\n\\begin{proof}\n  We begin to show consistency of the first two operators by Taylor\n  expansion: for some $\\xi\\in(x,x+h)$, there holds\n  \\begin{align*}\n    u'(x) - D^+_h u(x) &= u'(x) - \\frac{u(x+h) - u(x)}h \\\\\n    &= u'(x) - \\frac{u(x)+h u'(x) + \\tfrac{h^2}{2} u''(\\xi) - u(x)}h\n    \\\\\n    &= \\tfrac h2 u''(\\xi).\n  \\end{align*}\n  The same computation can be applied to $D^-_h u(x)$. It is clear\n  that we need an additional symmetry argument for te other two,\n  otherwise their consistency order would be lower. Therefore, we\n  follow the line of argument that we introduced in\n  Lemma~\\ref{Lemma:lmm-bramble-hilbert}, and which here reads: a\n  difference operator $D^\\alpha_h$ approximating a derivative of order\n  $\\alpha$ is consistent of order $p$, if and only if it is exact for all\n  polynomials of degree $p+\\alpha-1$. We realize this by computing the\n  Taylor polynomial $p(h)$ of degree $p+\\alpha-1$ and the remainder term\n  involving $u^{(p+\\alpha)}(\\xi)$. Then,\n  \\begin{gather*}\n    D^\\alpha_h u(x) = \\frac{p(h)+\\frac{h^{\\alpha+p}}{(\\alpha+p)!}u^{(p+\\alpha)}(\\xi)}{h^\\alpha}.\n  \\end{gather*}\n  Now we employ that the formula is exact for $p(h)$ and thus\n  \\begin{gather*}\n    u^{(\\alpha)}(x) - D^\\alpha_h u(x)\n    = \\frac{h^p}{(\\alpha+p)!}u^{(p+\\alpha)}(\\xi).\n  \\end{gather*}\n  We now write\n  \\begin{gather*}\n    p(\\xi) = a_0 + a_1 (\\xi-x) + a_2 (\\xi-x)^2 + a_3 (\\xi-x)^3 + \\cdots\n  \\end{gather*}\n  The central difference $D^c_h$ is exact for linear polynomials,\n  since ti evaluates to zero for a constant and $D^c_h (\\xi-x) =\n  1$. But additionally, we observe\n  \\begin{gather*}\n    \\frac{d}{d\\xi} (\\xi-x)^2 \\Bigr|_{\\xi=x}\n    = D^c_h (\\xi-x)^2 \\Bigr|_{\\xi=x}= 0.\n  \\end{gather*}\n  Thus, the central difference is exact for polynomials of degree 2\n  and consistent of second order.\n\n  For the 3-point stencil, we observe that $D^2_h u(x)=0$ for any\n  function $u$ such that $u(x+h) - u(x-h) = u(x)$, in particular any\n  odd polynomial in $\\xi-x$. Furthermore,\n  \\begin{gather*}\n    D^2_h  (\\xi-x)^2 \\Bigr|_{\\xi=x}= \\frac{h^2-0+h^2}{h^2}\n    = 2 = \\frac{d^2}{d\\xi^2} (\\xi-x)^2\n  \\end{gather*}\n\\end{proof}\n\n\\begin{remark}\n  When applied to the equation $u'=f(t,u)$ the solutions obtained by\n  forward and backward differences correspond to the explicit and\n  implicit Euler methods, respectively.\n\\end{remark}\n\n\\input{definitions/fd}\n\n\\input{definitions/fd-example}\n\n\\begin{remark}\n  Like our view to the continuous boundary value problem has changed,\n  the discrete one is now a fully coupled linear system which has to\n  be solved by methods of linear algebra, not by time stepping\n  anymore. In fact, we have $n+1$ variables $y_0,\\dots, y_n$ and $n+1$\n  equations, such that here existence and uniqueness of solutions are\n  equivalent.\n\\end{remark}\n\n\\input{definitions/fd-matrix}\n\n\\begin{remark}\n  The first and last row of the matrix $L_h$ are redundant, since they\n  simply say $y_0 = y_n = 0$. They can be eliminated, such that we\n  obtain the reduced system\n  \\begin{gather}\n    \\label{eq:fd:8}\n    L_h y =\n    \\begin{pmatrix}\n      \\lambda_1 & \\nu_1\\\\\n      \\mu_2 & \\lambda_2 & \\ddots \\\\\n      & \\ddots & \\ddots & \\nu_{n-2} \\\\\n      &&\\mu_{n-1}& \\lambda_{n-1}\n    \\end{pmatrix}\n    \\begin{pmatrix}\n      y_1\\\\\\vdots\\\\y_{n-1}\n    \\end{pmatrix}\n    =\n    \\begin{pmatrix}\n      f_1 \\\\\\vdots\\\\f_{n-1}\n    \\end{pmatrix} = f_h.\n  \\end{gather}\n  In this form, the operator $L_h$ is consistent with $L$ in the sense\n  that it only describes the differential operator, not the boundary\n  values. Therefore, we will use this form in our further analysis.\n\n  When it comes to implementation, both versions have their\n  merits. Obviously, the new operator involves less unknowns. On the\n  other hand, the discretization with boundary unknowns is more\n  straight-forward.\n\\end{remark}\n\n\\section{Existence, stability, and convergence}\n\n\\begin{intro}\n  Since the solution of the discretized boundary value problem is a\n  problem in linear algebra, we have to study properties of the matrix\n  $L_h$. The shortest and most elegant way to prove stability is\n  through the properties of M-matrices, which we present here very\n  shortly. We are not dwelling on this approach too long, since it is\n  sufficient for stability, but by far not necessary and constrained\n  to low order methods.\n\n  The fact that $L_h$ is an M-matrix requires some knowledge of\n  irreducible weakly diagonal dominant matrices, which the author\n  considers as outdated as the whole concept of m-matrices. We will\n  just quote this result without proof.\n\\end{intro}\n\n\\input{definitions/m-matrix}\n\n\\begin{Lemma}{m-matrix-fd1}\n  The matrix $L_h$ defined above is an M-matrix provided that\n  \\begin{gather}\n    \\label{eq:fd:3}\n    \\gamma_k \\ge 0, % > -\\frac2{h^2},\n    \\qquad\n    \\abs{\\beta_k} < \\frac2h.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  It is clear that these two conditions are sufficient for the first\n  M-matrix property. The proof of positivity of the inverse is based\n  on irreducible diagonal dominance, which is too long and too\n  specialized for these notes.\n\\end{proof}\n\n\\begin{remark}\n  The finite element method provides much more powerful to deduce\n  solvability and stability of the discrete problem.\n\\end{remark}\n\n\\input{theorems/m-matrix-inverse}\n\n\\begin{proof}\n  Let $x\\in \\R^n$ and $y = A^{-1} x$. Then,\n  \\begin{align*}\n    \\abs{y_i} & = \\abs{\\sum c_{ij} x_j} \\\\\n    & \\le \\sum c_{ij} \\abs{x_j} \\\\\n    & \\le \\norm{x}_\\infty \\sum c_{ij} v_j.\n  \\end{align*}\n  Thus,\n  \\begin{gather*}\n    \\abs{y_i} \\le  \\norm{x}_\\infty \\bigl(A^{-1} v\\bigr)_i\n    = \\norm{x}_\\infty \\bigl(A^{-1} Aw\\bigr)_i \\le \\norm{x}_\\infty \\abs{w_i}.\n  \\end{gather*}\n  Taking the maximum over all $i$, we obtain\n  \\begin{gather*}\n    \\norm{A^{-1}}_\\infty = \\sup_{u\\in\n      \\R^n}\\frac{\\norm{A^{-1}u}_\\infty}{\\norm{u}_\\infty}\n    \\le \\norm{w}_\\infty.\n  \\end{gather*}\n\\end{proof}\n\n\\input{theorems/fd-stability}\n\n\\begin{proof}\n  Take the function\n  \\begin{gather*}\n    p(x) = (x-a)(b-x) = -x^2+(a+b)x-ab,\n  \\end{gather*}\n  with derivatives $p'(x) = a+b-2x$ and $p''(x) = -2$, and a maximum\n  of $(b-a)^2/4$ at $x=(a+b)/2$. Choose the values $p_k = p(x_k)$. By\n  consistency, we have and $k=1,\\dots,n-1$\n  \\begin{gather*}\n    (L_h p)_k \\ge 2 - \\beta_k\\abs{b-a} + \\gamma_k \\abs{b-a}^2\n    \\ge 2-\\delta.\n  \\end{gather*}\n  Thus, the vector with entries $w_k = p_k/(2-\\delta)$ can be used to\n  bound the inverse of $L_h$ by Lemma~\\ref{Lemma:m-matrix-inverse}.\n\\end{proof}\n\n\\begin{remark}\n  The assumptions of the previous theorem involve two sets of\n  conditions on the parameters $\\beta_k$ and\n  $\\gamma_k$. Condition~\\eqref{eq:fd:1} is actually a condition on the\n  continuous problem. The condition on $\\gamma_k$ is indeed necessary,\n  as will be seen when we study partial differential equations. The\n  condition on $\\beta_k$ is not necessary in this form, but a better\n  estimate again requires far advanced analysis.\n\n  The other set of conditions relates the coefficients to the mesh\n  size. Again, the condition on $\\beta_k$ can be avoided as seen in\n  the next example. The condition on $\\gamma_k$ is already implied by\n  $-\\gamma_k \\le (b-a)^2$, which is a small restriction compared\n  to~\\eqref{eq:fd:1}, as soon as the partition has 3 interior\n  points. Thus, it is not crucial.\n\\end{remark}\n\n\\input{definitions/upwind}\n\\input{theorems/fd-convergence}\n\n\\begin{proof}\n  We apply the difference operator $L_h$ to $u$ (as the vector of\n  function values in the points $t_k$) and $y$ to obtain\n  \\begin{gather*}\n    L_h(u-y) = (L_h - L) u + Lu - L_h y = \\tau + f - f = \\tau,\n  \\end{gather*}\n  where $\\tau = (\\tau_1,\\dots,\\tau_{n-1})^T$ is the vector, which\n  measures the consistency error  $(L_h-L) u$ in each $t_k$. The\n  entries $\\tau_k$ are bounded by $c h^p$ by the consistency estimate.\n  For the error, there holds\n  \\begin{gather*}\n    u-y = L_h^{-1} L_h(u-y) =  L_h^{-1} \\tau.\n  \\end{gather*}\n  Using the stability assumption, we obtain\n  \\begin{gather*}\n    \\norm{u-y}_\\infty \\le \\norm{L_h^{-1}}_\\infty \\norm{\\tau}_\\infty\n    \\le c h^p,\n  \\end{gather*}\n  where the constant $c$ depends on $\\norm{L_h^{-1}}_\\infty$ and the\n  constant in the consistency estimate, but not on $h$.\n\\end{proof}\n\n\\begin{remark}\n  Finite differences can be generalized to higher order by extending\n  the stencils by more than one point to the left and right of the\n  current point. Whenever we add two points to the symmetric\n  difference formulas, we can gain two orders of consistency.\n  \\begin{gather*}\n    \\underbrace{\\bullet\\quad\n      \\underbrace{\\bullet\\quad\n        \\underbrace{\\bullet\\quad\\phantom{\\bullet}\\quad\\bullet}_{u'+\\mathcal O(h^2)}\n        \\quad\\bullet}_{u'+\\mathcal O(h^4)}\n      \\quad\\bullet}_{u'+\\mathcal O(h^6)}\n    \\qquad\\qquad\n    \\underbrace{\\bullet\\quad\n      \\underbrace{\\bullet\\quad\n        \\underbrace{\\bullet\\quad\\bullet\\quad\\bullet}_{u''+\\mathcal O(h^2)}\n        \\quad\\bullet}_{u''+\\mathcal O(h^4)}\n      \\quad\\bullet}_{u''+\\mathcal O(h^6)}\n  \\end{gather*}\n  Similarly, we can define one-sided difference formulas, which get us\n  close to multistep methods. The matrices generated by these formulas\n  are not M-matrices anymore, although you can show for the 4th order\n  formula for the second derivative that it yields a product of two\n  M-matrices. While this rescues the theory in a particular instance,\n  M-matrices do not provide a theoretical framework for general high\n  order finite differences anymore.\n\n  Very much like the starting procedures for high order multistep\n  methods, high order finite differences cause problems at the\n  boundaries. Here, the formulas must be truncated and for instance be\n  replaced by one-sided formulas of equal order.\n  \n  All these issues motivate the study of different discretization\n  methods in the next course.\n\\end{remark}\n\n\\section{The Laplacian and harmonic functions}\n\n\\begin{intro}\n  The two-point boundary value problem has a natural extension to\n  higher dimensions. There, we deal with partial derivatives\n  $\\frac{\\partial}{\\partial x}$, $\\frac{\\partial}{\\partial y}$, and\n  $\\frac{\\partial}{\\partial z}$. As an outlook towards topics\n  discussed in classes on partial differential equations and their\n  numerical analysis, we close these notes by a short introduction at\n  hand of examples.\n\\end{intro}\n\n\\begin{Definition}{laplace-equation}\n  the \\define{Laplacian} in two (three) space dimensions is the sum of\n  the second partial derivatives\n  \\begin{gather}\n    \\label{eq:fd:10}\n    \\Delta u = \\frac{\\partial^2}{\\partial x^2}u\n    + \\frac{\\partial^2}{\\partial y^2}u\n    \\left(+ \\frac{\\partial^2}{\\partial z^2}u\\right)\n    = \\operatorname{div}(\\nabla u)\n  \\end{gather}\n  The \\define{Laplace equation} is the partial differential equation\n  \\begin{gather}\n    \\label{eq:fd:11}\n    -\\Delta u = 0.\n  \\end{gather}\n  The \\define{Poisson equation} is the partial differential equation\n  \\begin{gather}\n    \\label{eq:fd:9}\n    -\\Delta u = f.\n  \\end{gather}\n  Solutions to the Laplace equations are called \\define{harmonic functions}.\n\\end{Definition}\n\n\\subsection{Properties of harmonic functions}\n\n\\begin{Theorem*}{mean-value}{Mean-value formula for harmonic functions}\n  Let $u\\in C^2(\\Omega)$ be a solution to the Laplace equation. Then,\n  $u$ has the mean value property\n  \\begin{gather}\n    \\label{eq:mean-value:1}\n    u(\\mathbf x) = \\frac1{r^{d-1}\\omega(d)}\n    \\int_{\\partial B_r(\\mathbf x)} u(\\mathbf y) \\,ds,\n  \\end{gather}\n  where $\\partial B_r(\\mathbf x) \\subset \\Omega$ is the sphere of\n  radius $r$ around $\\mathbf x$ and $\\omega(d)$ is the volume of the\n  unit sphere in $\\R^d$.\n\\end{Theorem*}\n\n\\begin{proof}\n  First, we rescale the problem to\n  \\begin{gather*}\n    \\Phi(r) = \\frac1{r^{d-1}\\omega(d)}\n    \\int_{\\partial B_r(\\mathbf x)} u(\\mathbf y) \\,ds\n    = \\frac1{\\omega(d)} \\int_{\\partial B_1(0)} u(\\mathbf x+r\\mathbf z) \\,ds.\n  \\end{gather*}\n  Then, we notice that\n  \\begin{align*}\n    \\Phi'(r)\n    &= \\frac1{\\omega(d)} \\int_{\\partial B_1(0)}\n      \\nabla u(\\mathbf x+r\\mathbf z)\\cdot \\mathbf z \\,ds_z\\\\\n    &= \\frac1{r^{d-1}\\omega(d)} \\int_{\\partial B_r(\\mathbf x)}\n      \\nabla u(\\mathbf y)\\cdot\\frac{\\mathbf y-\\mathbf x}{r} \\,ds_y\\\\\n    &= \\frac1{r^{d-1}\\omega(d)} \\int_{\\partial B_r(\\mathbf x)}\n    \\frac{\\partial}{\\partial \\mathbf n} u(\\mathbf y) \\,ds_y\\\\\n    &= \\frac1{r^{d-1}\\omega(d)} \\int_{B_r(\\mathbf x)}\n    \\Delta u(\\mathbf y)\\,d\\mathbf y = 0.\n  \\end{align*}\n  Between the last two lines, we used the Gauß theorem for the vector\n  valued function $\\nabla u$. Therefore, $\\Phi(r)$ is\n  constant. Because of continuity, we have\n  \\begin{gather*}\n    \\lim_{r\\to 0} \\Phi(r) =\n    \\lim_{r\\to 0}\\frac1{r^{d-1}\\omega(d)} \\int_{\\partial B_r(\\mathbf x)} u(\\mathbf y)\n    \\,ds\n    = u(\\mathbf x),\n  \\end{gather*}\n  which proves our theorem.\n\\end{proof}\n\n\\input{theorems/maximum}\n\n\\begin{proof}\n  Let $\\mathbf x_0$ be such a maximum and let $r>0$ such that\n  $B_r(\\mathbf x_0) \\subset \\Omega$. Assume that there is a point\n  $\\mathbf x$ on $\\partial B_r(\\mathbf x_0)$, such that $u(\\mathbf x)\n  < u(\\mathbf x_0)$. Then, this holds for points $\\mathbf y$ in a\n  neighborhood of $\\mathbf x$. Thus, in order that the mean value\n  property holds, there must be a subset of $\\partial B_r(\\mathbf\n  x_0)$ where $u(\\mathbf y) > u(\\mathbf x_0)$, contradicting that\n  $\\mathbf x_0$ is a maximum. Thus, $u(\\mathbf x) = u(\\mathbf x_0)$\n  for all $\\mathbf x \\in B_r(\\mathbf x_0)$ for all $r$ such that\n  $B_r(\\mathbf x_0) \\subset \\Omega$.\n\n  Let now $\\mathbf x\\in \\Omega$ be arbitrary. Then, there is a\n  (compact) path from $\\mathbf x_0$ to $\\mathbf x$ in $\\Omega$. Thus,\n  the path can be covered by a finite set of overlapping balls inside\n  $\\Omega$, and the argument above can be used iteratively to conclude\n  $u(\\mathbf x) = u(\\mathbf x_0)$.\n\\end{proof}\n\n\\begin{corollary}\n  Let $u \\in C^2(\\Omega)$ be a solution to the Laplace equation. Then,\n  its maximum and its minimum lie on the boundary, that is, there are\n  points\n  $\\underline{\\mathbf x}, \\overline{\\mathbf x} \\in\\partial\\Omega$,\n  such that\n  \\begin{gather*}\n    u(\\underline{\\mathbf x}) \\le u(\\mathbf x)\n    \\le u(\\overline{\\mathbf x})\n    \\quad\\forall \\mathbf x\\in\\Omega.\n  \\end{gather*}\n\\end{corollary}\n\n\\begin{proof}\n  If the maximum of $u$ is attained in an interior point, the maximum\n  principle yields a constant solution and the theorem holds\n  trivially. On the other hand, the maximum principle does not make\n  any prediction on points at the boundary, which therefore can be\n  maxima. The same holds for the minimum, since $-u$ is a solution to\n  the Laplace equation as well.\n\\end{proof}\n\n\\begin{corollary}\n  Solutions to the Poisson equation with homogeneous boundary\n  conditions are unique.\n\\end{corollary}\n\n\\begin{proof}\n  Assume there are two functions $u,v\\in C^2(\\Omega)$ with $u=v=0$ on\n  $\\partial\\Omega$ such that\n  \\begin{gather*}\n    -\\Delta u = -\\Delta v = f.\n  \\end{gather*}\n  Then, $w=u-v$ solves the Laplace equation with $w=0$ on\n  $\\partial\\Omega$. Due to the maximum principle, $w \\equiv 0$ and\n  $u=v$.\n\\end{proof}\n\n\n\\section{Finite differences}\n\\input{definitions/square-domain}\n\\input{definitions/dirichlet}\n\\input{definitions/cartesian-grid}\n\\input{definitions/lexicographic}\n\\input{definitions/5-point-stencil}\n\n\\begin{remark}\n  From now on, we will call the discrete solution $u_h$ in order to\n  avoid confusion with the coordinate direction $y$.\n\\end{remark}\n\n\\input{theorems/fd-matrix}\n\n\\begin{Theorem}{5-point-m-matrix}\n  The matrix generated by the 5-point stencil is an M-matrix and the\n  discrete problem\n  \\begin{gather*}\n    L_h u_h = f\n  \\end{gather*}\n  is stable in the sense that there is a constant $c$ independent of\n  the grid spacing $h$ such that\n  \\begin{gather*}\n    \\norm{L_h^{-1}} \\le c.\n  \\end{gather*}\n\\end{Theorem}\n\n\\begin{proof}\n  The proof of M-matrix property is identical to the proof for 2-point\n  boundary value problems, which was omitted there.  The same way as\n  there, the function\n  \\begin{gather*}\n    w(x,y) = (x-a)(b-x)(y-a)(b-y)\n  \\end{gather*}\n  can be employed to show boundedness of $\\norm{L_h^{-1}}$.\n\\end{proof}\n\n\\input{theorems/fd2-consistency}\n\n\\begin{proof}\n  We apply the analysis of Lemma~\\ref{Lemma:fd-consistency} in $x$-\n  and $y$-directions separately, obtaining\n  \\begin{align*}\n    \\abs{\\frac{\\partial^2}{\\partial x^2} u(x,y)\n      - \\frac{u(x+h,y) -2u(x,y) + u(x-h,y)}{h^2}} & \\le c h^2 \\\\\n    \\abs{\\frac{\\partial^2}{\\partial y^2} u(x,y)\n      - \\frac{u(x,y+h) -2u(x,y) + u(x,y-h)}{h^2}} & \\le c h^2,\n  \\end{align*}\n  an conclude consistency of the sum.\n\\end{proof}\n\n\\input{theorems/fd2-maximum}\n\n\\begin{proof}\n  From equation~\\eqref{eq:5-point-stencil:1}, it is clear that a\n  discrete mean value property holds, that is, $y_k$ is the mean value\n  of its four neighbors. Therefore, if $y_k \\ge y_j$, for all\n  neighboring indices $j$ of $k$, we have $y_j = y_k$. We conclude by\n  following a path through the grid points.\n\\end{proof}\n\n\\section{Evolution equations}\n\nAfter an excursion to second order differential equations depending on\na spatial variable, we are now returning to problems depending on\ntime. But this time, on time \\emph{and} space. As for the\nnomenclature, we have encountered ordinary differential equations as\nequations or systems depending on a time variable only, then partial\ndifferential equations (PDE) with several, typically a spatial\nindependent variables. While the problems considered here are covered\nby the definition of PDE, time and space are fundamentally different\nas long as we stay away from black holes, such that a distinction is\nreasonable. Therefore, we introduce the concept of\n\n\\begin{Definition}{evolution-equation}\n  An equation of the form\n  \\begin{gather}\n    \\partial_t u(t,x) + F(t,u(t,x)) = 0,\n  \\end{gather}\n  where $u(t,.)$ is in a function space $V$ on a domain $\\Omega$, and\n  $F$ is a differential operator with respect to the spatial variables\n  $x$ only, is an \\define{evolution equation} of first order (in\n  time).\n\n  An \\define{initial boundary value problem} (\\define{IBVP}) for this\n  evolution equation completes the differential equation by conditions\n  \\begin{xalignat}2\n    u(0,x) &= u_0 & x&\\in\\Omega \\\\\n    u(t,x) &= g & x&\\in\\partial\\Omega,\\; t>0.\n  \\end{xalignat}\n\\end{Definition}\n\n\\section{Fundamental solutions}\n\n\\begin{Definition}\n  The function\n  \\begin{gather}\n    \\label{eq:fd:fundamental}\n    \\Phi(x) =\n    \\begin{cases}\n      -\\tfrac{1}{2\\pi} \\log \\abs{x} & d=2\\\\\n      \\tfrac1{d(d-2)\\omega_d} \\frac1{\\abs{x}^{d-2}} & d\\ge 3,\n    \\end{cases}\n  \\end{gather}\n  for $x\\in \\R^d$ is the \\define{fundamental solution} to the Laplace\n  equation. Here, $\\omega_d$ is the volume of the unit ball in $\\R^d$.\n\\end{Definition}\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"notes\"\n%%% End:\n", "meta": {"hexsha": "fb43aea03e6f00885cdb212db2a757635ac8a2c2", "size": 22575, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ode/fd.tex", "max_stars_repo_name": "ahumanita/notes", "max_stars_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ode/fd.tex", "max_issues_repo_name": "ahumanita/notes", "max_issues_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-05-24T07:31:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-31T12:58:14.000Z", "max_forks_repo_path": "ode/fd.tex", "max_forks_repo_name": "ahumanita/notes", "max_forks_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-05-15T19:28:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-05T19:07:29.000Z", "avg_line_length": 36.4112903226, "max_line_length": 96, "alphanum_fraction": 0.6844296788, "num_tokens": 7136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.7013811830689293}}
{"text": "\\documentclass[10pt]{article}\n\n\\title{Alignment with dynamic programming}\n\\author{Heng Li}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{General notations}\n\nSuppose we have two sequences: a \\emph{target} sequence and a \\emph{query}\nsequence. The length of the target sequence is $\\ell_t$ with each residue\nindexed by $i$.  The length of query is $\\ell_q$ with each residue indexed by\n$j$. Gaps on the target sequence are \\emph{deletions} and gaps on the query are\n\\emph{insertions}. Function $S(i,j)$ gives the score between two residues on\nthe target and the query, respectively. $q>0$ is the gap open/initiation\npenalty and $e>0$ the gap extension penalty. A gap of length $k$ costs\n$q+k\\cdot e$.\n\n\\section{Global alignment with affine-gap penalties}\n\n\\subsection{Durbin's formulation}\n\nThe original Durbin's formulation is:\n\\begin{eqnarray*}\nM_{ij}&=&\\max\\{M_{i-1,j-1}, E_{i-1,j-1}, F_{i-1,j-1}\\} + S(i,j)\\\\\nE_{ij}&=&\\max\\{M_{i-1,j}-q, E_{i-1,j}\\} - e\\\\\nF_{ij}&=&\\max\\{M_{i,j-1}-q, F_{i,j-1}\\} - e\n\\end{eqnarray*}\nThis formulation disallows a deletion immediately followed an insertion, or\nvice versa. A more general form is:\n\\begin{eqnarray*}\nM_{ij}&=&\\max\\{M_{i-1,j-1}, E_{i-1,j-1}, F_{i-1,j-1}\\} + S(i,j)\\\\\nE_{ij}&=&\\max\\{M_{i-1,j}-q, E_{i-1,j}, F_{i-1,j}-q\\} - e\\\\\nF_{ij}&=&\\max\\{M_{i,j-1}-q, E_{i,j-1}-q, F_{i,j-1}\\} - e\n\\end{eqnarray*}\n\n\\subsection{Green's formulation}\n\nIf we define:\n\\[H_{ij}=\\max\\{M_{ij},E_{ij},F_{ij}\\}\\]\nthe Durbin's formulation can be transformed to\n\\begin{eqnarray*}\nE_{ij} &=& \\max\\{H_{i-1,j}-q, E_{i-1,j}\\} - e \\\\\nF_{ij} &=& \\max\\{H_{i,j-1}-q, F_{i,j-1}\\} - e \\\\\nH_{ij} &=& \\max\\{H_{i-1,j-1}+S(i,j), E_{ij}, F_{ij}\\}\n\\end{eqnarray*}\nI first saw this formulation in Phrap developed by Phil Green, though it may\nhave been used earlier. If we further introduce\n\\begin{eqnarray*}\nE'_{ij}&=&E_{i+1,j}\\\\\nF'_{ij}&=&F_{i,j+1}\n\\end{eqnarray*}\nwe have\n\\begin{eqnarray*}\nH_{ij} &=& \\max\\{H_{i-1,j-1}+S(i,j),E'_{i-1,j},F'_{i,j-1}\\}\\\\\nE'_{ij}&=& \\max\\{H_{ij}-q,E'_{i-1,j}\\}-e\\\\\nF'_{ij}&=& \\max\\{H_{ij}-q,F'_{i,j-1}\\}-e\n\\end{eqnarray*}\nIn fact, we more often use this set of equations in practical implementations.\nThe initial conditions are\n\\begin{eqnarray*}\nH_{-1,j}&=&\n  \\left\\{\\begin{array}{ll}\n    0 & (j=-1)\\\\\n\t-q-(j+1)\\cdot e & (0\\le j<\\ell_q)\n  \\end{array}\\right.\\\\\nH_{i,-1}&=&\n  \\left\\{\\begin{array}{ll}\n    0 & (i=-1)\\\\\n\t-q-(i+1)\\cdot e & (0\\le i<\\ell_t)\n  \\end{array}\\right.\\\\\nE'_{-1,j}&=&E_{0,j}=H_{-1,j}-q-e=-2q-(j+2)\\cdot e\\\\\nF'_{i,-1}&=&F_{i,0}=-2q-(i+2)\\cdot e\n\\end{eqnarray*}\n\n\\subsection{Suzuki's formulation}\n\n\\subsubsection{Standard coordinate}\nNow let\n\\begin{eqnarray*}\nu'_{ij}&=&H_{ij}-H_{i-1,j}\\\\\nv'_{ij}&=&H_{ij}-H_{i,j-1}\\\\\nx'_{ij}&=&E'_{ij}-H_{ij}\\\\\ny'_{ij}&=&F'_{ij}-H_{ij}\n\\end{eqnarray*}\nWe have\n\\begin{eqnarray}\\label{eq:x}\nx'_{ij}&=&\\max\\{-q,E'_{i-1,j}-H_{i-1,j}+H_{i-1,j}-H_{ij}\\}-e\\\\\\nonumber\n&=&\\max\\{-q,x'_{i-1,j}-u'_{ij}\\}-e\n\\end{eqnarray}\nSimilarly\n\\begin{equation}\ny'_{ij}=\\max\\{-q,y'_{i,j-1}-v'_{ij}\\}-e\n\\end{equation}\nTo derive the equation to compute $u'(i,j)$ and $v'(i,j)$, we note that\n\\begin{eqnarray*}\nH_{ij}-H_{i-1,j-1}\n&=&\\max\\{S(i,j),E'_{i-1,j}-H_{i-1,j-1},F'_{i,j-1}-H_{i-1,j-1}\\}\\\\\n&=&\\max\\{S(i,j),x'_{i-1,j}+v'_{i-1,j},y'_{i,j-1}+u'_{i,j-1}\\}\n\\end{eqnarray*}\nand\n\\[H_{ij}-H_{i-1,j-1}=u'_{ij}+v'_{i-1,j}=v'_{ij}+u'_{i,j-1}\\]\nWe can derive the recursive equation for $u'_{ij}$ and $v'_{ij}$:\n\\begin{eqnarray*}\nz'_{ij}&=&\\max\\{S(i,j),x'_{i-1,j}+v'_{i-1,j},y'_{i,j-1}+u'_{i,j-1}\\}\\\\\nu'_{ij}&=&z'_{ij}-v'_{i-1,j}\\\\\nv'_{ij}&=&z'_{ij}-u'_{i,j-1}\\\\\nx'_{ij}&=&\\max\\{0,x'_{i-1,j}+v'_{i-1,j}-z'_{ij}+q\\}-q-e\\\\\ny'_{ij}&=&\\max\\{0,y'_{i,j-1}+u'_{i,j-1}-z'_{ij}+q\\}-q-e\n\\end{eqnarray*}\n\nFrom eq.~(\\ref{eq:x}) we can infer that $x'_{ij}\\ge-q-e$ and similarly\n$y'_{ij}\\ge-q-e$. We further have:\n\\[\nu'_{ij}=H_{ij}-H_{i-1,j-1}-v'_{i-1,j}\\ge x'_{i-1,j}\\ge-q-e\n\\]\nTherefore, we have a lower bound $-q-e$ for $u'$, $v'$, $x'$ and $y'$.\nThis motivates us to redefine the four variables as:\n\\begin{eqnarray*}\nu''_{ij}&=&H_{ij}-H_{i-1,j}+q+e\\\\\nv''_{ij}&=&H_{ij}-H_{i,j-1}+q+e\\\\\nx''_{ij}&=&E'_{ij}-H_{ij}+q+e\\\\\ny''_{ij}&=&F'_{ij}-H_{ij}+q+e\n\\end{eqnarray*}\nThe recursion becomes\n\\begin{eqnarray*}\nz''_{ij}&=&\\max\\{S(i,j)+2q+2e,x''_{i-1,j}+v''_{i-1,j},y''_{i,j-1}+u''_{i,j-1}\\}\\\\\nu''_{ij}&=&z''_{ij}-v''_{i-1,j}\\\\\nv''_{ij}&=&z''_{ij}-u''_{i,j-1}\\\\\nx''_{ij}&=&\\max\\{0,x''_{i-1,j}-u''_{ij}+q\\}=\\max\\{0,x''_{i-1,j}+v''_{i-1,j}-z''_{ij}+q\\}\\\\\ny''_{ij}&=&\\max\\{0,y''_{i,j-1}-v''_{ij}+q\\}=\\max\\{0,y''_{i,j-1}+u''_{i,j-1}-z''_{ij}+q\\}\n\\end{eqnarray*}\nHere $z_{ij}$ is a temporary variable. $u''$, $v''$, $x''$ and $y''$ are all\nnon-negtive.\n\n\\subsubsection{Rotated coordinate}\n\nWe let\n\\begin{eqnarray*}\nr&=&i+j\\\\\nt&=&i\n\\end{eqnarray*}\nWe have\n\\begin{eqnarray*}\nz_{rt}&=&\\max\\{S(t,r-t)+2q+2e,x_{r-1,t-1}+v_{r-1,t-1},y_{r-1,t}+u_{r-1,t}\\}\\\\\nu_{rt}&=&z_{rt}-v_{r-1,t-1}\\\\\nv_{rt}&=&z_{rt}-u_{r-1,t}\\\\\nx_{rt}&=&\\max\\{0,x_{r-1,t-1}+v_{r-1,t-1}-z_{rt}+q\\}\\\\\ny_{rt}&=&\\max\\{0,y_{r-1,t}+u_{r-1,t}-z_{rt}+q\\}\n\\end{eqnarray*}\nDue to the definition of $r$ and $t$, the following inequation must stand:\n\\[0\\le r-t \\le\\ell_q-1\\]\n\\[0\\le t \\le\\ell_t-1\\]\nwhere $\\ell_t$ is the length of the sequence indexed by $i$ and $\\ell_q$ the\nlength indexed by $j$. In case of banded alignment with a fixed diagonal band\nof size $w$,\n\\[-w\\le j-i\\le w\\]\nIn the $(r,t)$ coordinate, it is:\n\\[\\frac{r-w}{2}\\le t\\le \\frac{r+w}{2}\\]\nPutting these together:\n\\[0\\le r\\le \\ell_q+\\ell_t-2\\]\n\\[\\max\\left\\{0,r-\\ell_q+1,\\frac{r-w}{2}\\right\\}\\le t\\le\\min\\left\\{\\ell_t-1,r,\\frac{r+w}{2}\\right\\}\\]\n\n\\subsubsection{Initial conditions}\n\\[x_{r-1,-1}=x''_{-1,r}=E'_{-1,r}-H_{-1,r}+q+e=0\\]\n\\[y_{r-1,r}=y''_{r,-1}=0\\]\n\\[v_{r-1,-1}=v''_{-1,r}=H_{-1,r}-H_{-1,r-1}+q+e=\\left\\{\\begin{array}{ll}\n  q & (r>0) \\\\\n  0 & (r=0)\n\\end{array}\\right.\\]\n\\[u_{r-1,r}=u''_{r,-1}=H_{r,-1}-H_{r-1,-1}+q+e=\\left\\{\\begin{array}{ll}\n  q & (r>0) \\\\\n  0 & (r=0)\n\\end{array}\\right.\\]\n\n\\section{Alignment with dual affine-gap penalties}\n\n\\subsection{Green's formulation}\n\n\\begin{eqnarray*}\nH_{ij} &=& \\max\\{H_{i-1,j-1}+S(i,j),E'_{i-1,j},F'_{i,j-1},\\tilde{E}'_{i-1,j},\\tilde{F}'_{i,j-1}\\}\\\\\nE'_{ij}&=& \\max\\{H_{ij}-q,E'_{i-1,j}\\}-e\\\\\nF'_{ij}&=& \\max\\{H_{ij}-q,F'_{i,j-1}\\}-e\\\\\n\\tilde{E}'_{ij}&=& \\max\\{H_{ij}-\\tilde{q},\\tilde{E}'_{i-1,j}\\}-\\tilde{e}\\\\\n\\tilde{F}'_{ij}&=& \\max\\{H_{ij}-\\tilde{q},\\tilde{F}'_{i,j-1}\\}-\\tilde{e}\n\\end{eqnarray*}\nThe initial conditions are:\n\\begin{eqnarray*}\nH_{-1,j}&=&\n  \\left\\{\\begin{array}{ll}\n    0 & (j=-1)\\\\\n\t\\max\\{-q-(j+1)\\cdot e,-\\tilde{q}-(j+1)\\cdot\\tilde{e}\\} & (0\\le j<\\ell_q)\n  \\end{array}\\right.\\\\\nH_{i,-1}&=&\n  \\left\\{\\begin{array}{ll}\n    0 & (i=-1)\\\\\n\t\\max\\{-q-(i+1)\\cdot e,-\\tilde{q}-(i+1)\\cdot\\tilde{e}\\} & (0\\le i<\\ell_t)\n  \\end{array}\\right.\\\\\nE'_{-1,j}&=&E_{0,j}=H_{-1,j}-q-e\\\\\nF'_{i,-1}&=&F_{i,0}=H_{i,-1}-q-e\\\\\n\\tilde{E}'_{-1,j}&=&\\tilde{E}_{0,j}=H_{-1,j}-\\tilde{q}-\\tilde{e}\\\\\n\\tilde{F}'_{i,-1}&=&\\tilde{F}_{i,0}=H_{i,-1}-\\tilde{q}-\\tilde{e}\n\\end{eqnarray*}\n\n\\subsection{Suzuki's formulation}\n\n\\begin{eqnarray*}\nz'_{ij}&=&\\max\\{S(i,j),x'_{i-1,j}+v'_{i-1,j},y'_{i,j-1}+u'_{i,j-1},\\\\\n&&\\tilde{x}'_{i-1,j}+v'_{i-1,j},\\tilde{y}'_{i,j-1}+u'_{i,j-1}\\}\\\\\nu'_{ij}&=&z'_{ij}-v'_{i-1,j}\\\\\nv'_{ij}&=&z'_{ij}-u'_{i,j-1}\\\\\nx'_{ij}&=&\\max\\{0,x'_{i-1,j}+v'_{i-1,j}-z'_{ij}+q\\}-q-e\\\\\ny'_{ij}&=&\\max\\{0,y'_{i,j-1}+u'_{i,j-1}-z'_{ij}+q\\}-q-e\\\\\n\\tilde{x}'_{ij}&=&\\max\\{0,\\tilde{x}'_{i-1,j}+v'_{i-1,j}-z'_{ij}+\\tilde{q}\\}-\\tilde{q}-\\tilde{e}\\\\\n\\tilde{y}'_{ij}&=&\\max\\{0,\\tilde{y}'_{i,j-1}+u'_{i,j-1}-z'_{ij}+\\tilde{q}\\}-\\tilde{q}-\\tilde{e}\n\\end{eqnarray*}\nIn the rotated coordinate:\n\\begin{eqnarray*}\nz_{rt}&=&\\max\\{S(t,r-t),x_{r-1,t-1}+v_{r-1,t-1},y_{r-1,t}+u_{r-1i,t},\\\\\n&&\\tilde{x}_{r-1,t-1}+v_{r-1,t-1},\\tilde{y}_{r-1,t}+u_{r-1,t}\\}\\\\\nu_{rt}&=&z_{rt}-v_{r-1,t-1}\\\\\nv_{rt}&=&z_{rt}-u_{r-1,t}\\\\\nx_{rt}&=&\\max\\{0,x_{r-1,t-1}+v_{r-1,t-1}-z_{rt}+q\\}-q-e\\\\\ny_{rt}&=&\\max\\{0,y_{r-1,t}+u_{r-1,t}-z_{rt}+q\\}-q-e\\\\\n\\tilde{x}_{rt}&=&\\max\\{0,\\tilde{x}_{r-1,t-1}+v_{r-1,t-1}-z_{rt}+\\tilde{q}\\}-\\tilde{q}-\\tilde{e}\\\\\n\\tilde{y}_{rt}&=&\\max\\{0,\\tilde{y}_{r-1,t}+u_{r-1,t}-z_{rt}+\\tilde{q}\\}-\\tilde{q}-\\tilde{e}\n\\end{eqnarray*}\nBy definition, it is easy to see the initial conditions except $u$ and $v$:\n\\[x_{r-1,-1}=x'_{-1,r}=E'_{-1,r}-H_{-1,r}=-q-e\\]\n\\[y_{r-1,r}=y'_{r,-1}=F'_{r,-1}-H_{r,-1}=-q-e\\]\n\\[\\tilde{x}_{r-1,-1}=-\\tilde{q}-\\tilde{e}\\]\n\\[\\tilde{y}_{r-1,-1}=-\\tilde{q}-\\tilde{e}\\]\n\\[v_{r-1,-1}=H_{-1,r}-H_{-1,r-1}=\\left\\{\\begin{array}{ll}\n\\max\\{-q-e,-\\tilde{q}-\\tilde{e}\\} & (r=0)\\\\\n-e & (r<\\lceil\\frac{\\tilde{q}-q}{e-\\tilde{e}}-1\\rceil)\\\\\nr(e-\\tilde{e})-(\\tilde{q}-q)-\\tilde{e} & (r=\\lceil\\frac{\\tilde{q}-q}{e-\\tilde{e}}-1\\rceil)\\\\\n-\\tilde{e} & (r>\\lceil\\frac{\\tilde{q}-q}{e-\\tilde{e}}-1\\rceil)\n\\end{array}\\right.\\]\n\n\\end{document}\n", "meta": {"hexsha": "1f508a2b8d50240a081cf556cb25c124efebc67e", "size": 8616, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "implementations/guidi2020/benchmark/tools/ksw2/tex/ksw2.tex", "max_stars_repo_name": "r-barnes/sw_comparison", "max_stars_repo_head_hexsha": "1ac2c9cc10a32badd6b8fb1e96516c97f7800176", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 108, "max_stars_repo_stars_event_min_datetime": "2017-06-22T16:49:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T22:55:14.000Z", "max_issues_repo_path": "implementations/guidi2020/benchmark/tools/ksw2/tex/ksw2.tex", "max_issues_repo_name": "r-barnes/sw_comparison", "max_issues_repo_head_hexsha": "1ac2c9cc10a32badd6b8fb1e96516c97f7800176", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-07-06T14:59:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T03:22:55.000Z", "max_forks_repo_path": "implementations/guidi2020/benchmark/tools/ksw2/tex/ksw2.tex", "max_forks_repo_name": "r-barnes/sw_comparison", "max_forks_repo_head_hexsha": "1ac2c9cc10a32badd6b8fb1e96516c97f7800176", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 22, "max_forks_repo_forks_event_min_datetime": "2017-06-23T05:33:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-27T16:46:12.000Z", "avg_line_length": 35.4567901235, "max_line_length": 100, "alphanum_fraction": 0.5645311049, "num_tokens": 4405, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046026642945, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7013621416477883}}
{"text": "\\section{The Fundamental Theorem of Calculus}\\label{sec:FTC}\r\nLet's recast the first example from the previous section. Suppose that\r\nthe speed of the object is $3t$ at time $t$. How far does the object\r\ntravel between time $t=a$ and time $t=b$? We are no longer assuming\r\nthat we know where the object is at time $t=0$ or at any other\r\ntime. It is certainly true that it is {\\it somewhere,} so let's\r\nsuppose that at $t=0$ the position is $k$. Then just as in the\r\nexample, we know that the position of the object at any time is \r\n$\\ds 3t^2/2+k$. This means that at time $t=a$ the position is \r\n$\\ds 3a^2/2+k$ and at time $t=b$ the position is $\\ds 3b^2/2+k$. Therefore the\r\nchange in position is $\\ds 3b^2/2+k-(3a^2/2+k)=3b^2/2-3a^2/2$. Notice that\r\nthe $k$ drops out; this means that it doesn't matter that we don't\r\nknow $k$, it doesn't even matter if we use the wrong $k$, we get the\r\ncorrect answer. \r\n\r\nWhat about the second approach to this problem, in the new form? We\r\nnow want to approximate the change in position between time $a$ and\r\ntime $b$. We take the interval of time between $a$ and $b$, divide it\r\ninto $n$ subintervals, and approximate the distance traveled during\r\neach. The starting time of subinterval number $i$ is now \r\n$a+(i-1)(b-a)/n$, which we abbreviate as $\\ds t_{i-1}$, so that \r\n$\\ds t_0=a$, $\\ds t_1=a+(b-a)/n$, and so on. The speed of the object is\r\n$f(t)=3t$, and each subinterval is $(b-a)/n=\\Delta t$ seconds long.\r\nThe distance traveled during subinterval number\r\n$i$ is approximately $\\ds f(t_{i-1})\\Delta t$, and the total change in\r\ndistance is approximately\r\n$$\r\n  f(t_0)\\Delta t+f(t_1)\\Delta t+\\cdots+f(t_{n-1})\\Delta t.\r\n$$\r\nThe exact change in position is the limit of this sum as $n$ goes to\r\ninfinity. We abbreviate this sum using \\dfont{sigma notation}:\r\n$$\r\n  \\sum_{i=0}^{n-1} f(t_i)\\Delta t =\r\nf(t_0)\\Delta t+f(t_1)\\Delta t+\\cdots+f(t_{n-1})\\Delta t.\r\n$$\r\nThe notation on the left side of the equal sign uses a large capital\r\nsigma, a Greek letter, and the left side is an abbreviation for the\r\nright side. The answer we seek is\r\n$$\r\n  \\lim_{n\\to\\infty}\\sum_{i=0}^{n-1} f(t_i)\\Delta t.\r\n$$ \r\nSince this must be the same as the answer we have already obtained, we\r\nknow that \r\n$$\r\n  \\lim_{n\\to\\infty}\\sum_{i=0}^{n-1} f(t_i)\\Delta t={3b^2\\over\r\n  2}-{3a^2\\over 2}.\r\n$$\r\nThe significance of $\\ds 3t^2/2$, into which we substitute $t=b$ and\r\n$t=a$, is of course that it is a function whose derivative is $f(t)$.\r\nAs we have discussed, by the time we know that we want to compute\r\n$$\r\n  \\lim_{n\\to\\infty}\\sum_{i=0}^{n-1} f(t_i)\\Delta t,\r\n$$\r\nit no longer matters what $f(t)$ stands for---it could be a speed, or\r\nthe height of a curve, or something else entirely. We know that\r\nthe limit can be computed by finding any function with derivative\r\n$f(t)$, substituting $a$ and $b$, and subtracting. We summarize this\r\nin a theorem. First, we introduce some new notation and terms.\r\n\r\nWe write\r\n$$\r\n  \\int_a^b f(t)\\,dt = \\lim_{n\\to\\infty}\\sum_{i=0}^{n-1} f(t_i)\\Delta t\r\n$$ \r\nif the limit exists. That is, the left hand side means, or is an\r\nabbreviation for, the right hand side. The symbol $\\int$ is called an\r\n\\dfont{integral sign}, and the whole\r\nexpression is read as ``the integral of $f(t)$ from $a$ to $b$.'' What\r\nwe have learned is that this integral can be computed by finding a\r\nfunction, say $F(t)$, with the property that $F'(t)=f(t)$, and then\r\ncomputing $F(b)-F(a)$. The function $F(t)$ is called an \\dfont{antiderivative} of $f(t)$. \r\nNow the theorem:\r\n\r\n\\begin{theorem}{Fundamental Theorem of Calculus}{fundamental_theorem_I}\r\nSuppose that $f(x)$ is\r\ncontinuous on the interval $[a,b]$. If $F(x)$ is any antiderivative of\r\n$f(x)$, then \r\n$$\r\n  \\int_a^b f(x)\\,dx = F(b)-F(a).\r\n$$\r\n\\end{theorem}\r\n\r\nLet's rewrite this slightly: \r\n$$\r\n  \\int_a^x f(t)\\,dt = F(x)-F(a).\r\n$$\r\nWe've replaced the variable $x$ by $t$ and $b$ by $x$. These are just\r\ndifferent names for quantities, so the substitution doesn't change the\r\nmeaning. It does make it easier to think of the two sides of the\r\nequation as functions. The expression\r\n$$\r\n  \\int_a^x f(t)\\,dt\r\n$$\r\nis a function: plug in a value for $x$, get out some other value. The\r\nexpression $F(x)-F(a)$ is of course also a function, and it has a nice\r\nproperty: \r\n$$\r\n  {d\\over dx} (F(x)-F(a)) = F'(x) = f(x),\r\n$$\r\nsince $F(a)$ is a constant and has derivative zero. In other words, by\r\nshifting our point of view slightly, we see that the odd looking\r\nfunction\r\n$$\r\n  G(x)=\\int_a^x f(t)\\,dt\r\n$$\r\nhas a derivative, and that in fact $G'(x)=f(x)$. This is really just a\r\nrestatement of the Fundamental Theorem of Calculus, and indeed is\r\noften called the Fundamental Theorem of Calculus. To avoid confusion,\r\nsome people call the two versions of the theorem ``The Fundamental\r\nTheorem of Calculus, part I'' and ``The Fundamental\r\nTheorem of Calculus, part II'', although unfortunately there is no\r\nuniversal agreement as to which is part I and which part II. Since it\r\nreally is the same theorem, differently stated, some people simply\r\ncall them both ``The Fundamental\r\nTheorem of Calculus.''\r\n\r\n\\begin{theorem}{Fundamental Theorem of Calculus}{fundamental_theorem_II}\r\nSuppose that $f(x)$ is\r\ncontinuous on the interval $[a,b]$ and let\r\n$$\r\n  G(x)=\\int_a^x f(t)\\,dt.\r\n$$\r\nThen $G'(x)=f(x)$.\r\n\\end{theorem}\r\n\r\nWe have not really proved the Fundamental Theorem. In a nutshell, we\r\ngave the following argument to justify it: Suppose we want to know the\r\nvalue of \r\n$$\r\n  \\int_a^b f(t)\\,dt = \\lim_{n\\to\\infty}\\sum_{i=0}^{n-1} f(t_i)\\Delta t.\r\n$$\r\nWe can interpret the right hand side as the distance traveled by an\r\nobject whose speed is given by $f(t)$. We know another way to compute\r\nthe answer to such a problem: find the position of the object by\r\nfinding an antiderivative of $f(t)$, then substitute $t=a$ and $t=b$\r\nand subtract to find the distance traveled. This must be the answer to\r\nthe original problem as well, even if $f(t)$ does not represent a\r\nspeed.\r\n\r\nWhat's wrong with this? In some sense, nothing. As a practical matter\r\nit is a very convincing argument, because our understanding of the\r\nrelationship between speed and distance seems to be quite solid. From\r\nthe point of view of mathematics, however, it is unsatisfactory to\r\njustify a purely mathematical relationship by appealing to our\r\nunderstanding of the physical universe, which could, however unlikely\r\nit is in this case, be wrong.\r\n\r\nA complete proof is a bit too involved to include here, but we will\r\nindicate how it goes. First, if we can prove the second version of the\r\nFundamental Theorem, Theorem~\\ref{thm:fundamental_theorem_II}, then\r\nwe can prove the first version from that:\r\n\r\n\\begin{proof} Proof of Theorem~\\ref{thm:fundamental_theorem_I}.\r\n\r\nWe know from Theorem~\\ref{thm:fundamental_theorem_II} that \r\n$$\r\n  G(x)=\\int_a^x f(t)\\,dt\r\n$$\r\nis an antiderivative of $f(x)$, and therefore any antiderivative\r\n$F(x)$ of $f(x)$ is of the form $F(x)=G(x)+k$. Then \r\n\\begin{eqnarray*}\r\n  F(b)-F(a)=G(b)+k-(G(a)+k) &=& G(b)-G(a)\\cr\r\n  &=&\\int_a^b f(t)\\,dt-\\int_a^a f(t)\\,dt.\\cr\r\n\\end{eqnarray*}\r\nIt is not hard to see that $\\ds \\int_a^a f(t)\\,dt=0$, so this means that\r\n$$\r\n  F(b)-F(a)=\\int_a^b f(t)\\,dt,\r\n$$\r\nwhich is exactly what Theorem~\\ref{thm:fundamental_theorem_I} says.\r\n\\end{proof}\r\n\r\nSo the real job is to prove\r\nTheorem~\\ref{thm:fundamental_theorem_II}. We will sketch the proof,\r\nusing some facts that we do not prove. First, the following identity\r\nis true of integrals:\r\n$$\r\n  \\int_a^b f(t)\\,dt = \\int_a^c f(t)\\,dt + \\int_c^b f(t)\\,dt.\r\n$$\r\nThis can be proved directly from the definition of the integral, that\r\nis, using the limits of sums. It is quite easy to see that it must be\r\ntrue by thinking of either of the two applications of integrals that\r\nwe have seen. It turns out that the identity is true no matter what\r\n$c$ is, but it is easiest to think about the meaning when \r\n$a\\le c\\le b$.\r\n\r\nFirst, if $f(t)$ represents a speed, then we know that the three\r\nintegrals represent the distance traveled between time $a$ and time $b$;\r\nthe distance traveled between time $a$ and time $c$; and \r\nthe distance traveled between time $c$ and time $b$. Clearly the sum of\r\nthe latter two is equal to the first of these.\r\n\r\nSecond, if $f(t)$ represents the height of a curve, the three\r\nintegrals represent the area under the curve between $a$ and $b$;\r\nthe area under the curve between $a$ and $c$;\r\nand the area under the curve between $c$ and $b$. Again it is clear\r\nfrom the geometry that the first is equal to the sum of the second and\r\nthird. \r\n\r\n\\begin{proof} Proof of Theorem~\\ref{thm:fundamental_theorem_II}.\r\n\r\nWe want to compute $G'(x)$, so we start with the definition of the\r\nderivative in terms of a limit:\r\n\\begin{eqnarray*}\r\n  G'(x)&=&\\lim_{\\Delta x\\to0}{G(x+\\Delta x)-G(x)\\over\\Delta x}\\cr\r\n  &=&\\lim_{\\Delta x\\to0}{1\\over \\Delta x}\\left(\r\n  \\int_a^{x+\\Delta x} f(t)\\,dt - \\int_a^x f(t)\\,dt\\right)\\cr\r\n  &=&\\lim_{\\Delta x\\to0}{1\\over \\Delta x}\\left(\r\n  \\int_a^{x} f(t)\\,dt + \\int_x^{x+\\Delta x} f(t)\\,dt - \r\n  \\int_a^x f(t)\\,dt\\right)\\cr\r\n  &=&\\lim_{\\Delta x\\to0}{1\\over \\Delta x}\\int_x^{x+\\Delta x} f(t)\\,dt.\\cr\r\n\\end{eqnarray*}\r\nNow we need to know something about \r\n$$\r\n  \\int_x^{x+\\Delta x} f(t)\\,dt\r\n$$\r\nwhen $\\Delta x$ is small; in fact, it is very close to \r\n$\\Delta x f(x)$, but we will not prove this. Once again, it is easy to\r\nbelieve this is true by thinking of our two applications:\r\nThe integral \r\n$$\r\n  \\int_x^{x+\\Delta x} f(t)\\,dt\r\n$$\r\ncan be interpreted as the distance traveled by an object over a very\r\nshort interval of time. Over a sufficiently short period of time, the\r\nspeed of the object will not change very much, so the distance\r\ntraveled will be approximately the length of time multiplied by the\r\nspeed at the beginning of the interval, namely, $\\Delta x\r\nf(x)$. Alternately, the integral may be interpreted as the area under\r\nthe curve between $x$ and $x+\\Delta x$. When $\\Delta x$ is very small,\r\nthis will be very close to the area of the rectangle with base $\\Delta\r\nx$ and height $f(x)$; again this is $\\Delta x\r\nf(x)$. If we accept this, we may proceed:\r\n$$\r\n  \\lim_{\\Delta x\\to0}{1\\over \\Delta x}\\int_x^{x+\\Delta x} f(t)\\,dt\r\n  =\\lim_{\\Delta x\\to0}{\\Delta x f(x)\\over \\Delta x}=f(x),\r\n$$\r\nwhich is what we wanted to show.\r\n\\end{proof}\r\n\r\nIt is still true that we are depending on an interpretation of the\r\nintegral to justify the argument, but we have isolated this part of\r\nthe argument into two facts that are not too hard to prove. Once the\r\nlast reference to interpretation has been removed from the proofs of\r\nthese facts, we will have a real proof of the Fundamental Theorem.\r\n\r\nNow we know that to solve certain kinds of problems, those that lead\r\nto a sum of a certain form, we ``merely'' find an antiderivative and\r\nsubstitute two values and subtract. Unfortunately, finding\r\nantiderivatives can be quite difficult. While there are a small number\r\nof rules that allow us to compute the derivative of any common\r\nfunction, there are no such rules for antiderivatives. There are some\r\ntechniques that frequently prove useful, but we will never be able to\r\nreduce the problem to a completely mechanical process.\r\n\r\nDue to the close relationship between an integral and an\r\nantiderivative, the integral sign is also used to mean\r\n``antiderivative''. You can tell which is intended by whether the\r\nlimits of integration are included:\r\n$$\r\n  \\int_1^2 x^2\\,dx\r\n$$\r\nis an ordinary integral, also called a \r\n\\dfont{definite integral},\r\nbecause it has a definite value, namely\r\n$$\r\n  \\int_1^2 x^2\\,dx={2^3\\over3}-{1^3\\over3}={7\\over3}.\r\n$$\r\nWe use\r\n$$\r\n  \\int x^2\\,dx\r\n$$\r\nto denote the antiderivative of $\\ds x^2$, also called an\r\n\\dfont{indefinite integral}.\r\nSo this is evaluated as\r\n$$\r\n  \\int x^2\\,dx = {x^3\\over 3}+C.\r\n$$\r\nIt is customary to include the constant $C$ to indicate that there are\r\nreally an infinite number of antiderivatives. We do not need this $C$\r\nto compute definite integrals, but in other circumstances we will need\r\nto remember that the $C$ is there, so it is best to get into the habit\r\nof writing the $C$.\r\nWhen we compute a definite integral, we first find an antiderivative\r\nand then substitute. It is convenient to first display the\r\nantiderivative and then do the substitution; we need a notation\r\nindicating that the substitution is yet to be done. A typical solution\r\nwould look like this:\r\n$$\r\n  \\int_1^2 x^2\\,dx=\\left.{x^3\\over 3}\\right|_1^2 = \r\n  {2^3\\over3}-{1^3\\over3}={7\\over3}.\r\n$$\r\nThe vertical line with subscript and superscript is used to indicate\r\nthe operation ``substitute and subtract'' that is needed to finish the\r\nevaluation.\r\n\r\nWe seem to have found a pattern. When attempting to solve a previous question, we found the antiderivative of $x^2$ to be $x^3/3+c$ (as it was when solving the indefinite integral). Likewise, when we first began, we were trying to determine a position based on velocity, and $3t$ gave rise to $3t^2/2+k$.\r\n\r\nAs will be formalized later, we see that in these cases, the power is increased to $n+1$, but we also divide through by this factor, $n+1$. So $x$ becomes $x^2/2$, $x^2$ becomes $x^3/3$, and $x^3$ will become $x^4/4$.\r\n\r\nNow we will also try with negative and fraction values in the following example.\r\n\r\n\\begin{example}{Fundamental Theorem of Calculus}{FundamentalTheoremCalculus}\r\nEvaluate $\\ds\\int_1^4 x^3+\\sqrt{x}+\\frac{1}{x^2}\\,dx $.\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n\\[ \\begin{array}{lcl}\r\n\\ds\\int_1^4 x^3+\\sqrt{x}+\\frac{1}{x^2}\\,dx \r\n\t& = & \\ds\\left.\\frac{x^4}{4}+\\frac{2x^{3/2}}{3}-x^{-1}\\right|_1^4\\\\\r\n\\\\\r\n\t& = & \\ds\\left(\\frac{(4)^4}{4}+\\frac{2(4)^{3/2}}{3}-4^{-1}\\right) \\\\\r\n\\\\\r\n\t& & \\ds-\\left(\\frac{(1)^4}{4}+\\frac{2(1)^{3/2}}{3}-1^{-1}\\right)\\\\\r\n\\\\\r\n\t& = & \\ds\\frac{415}{6}\r\n\\end{array}\\]\\\r\n\\end{solution}\r\n\r\n\\begin{formulabox}[Properties of Definite Integrals]\r\nSome properties are as follows:\r\n$$\\mbox{Order of limits matters:}\\qquad\\int_a^b f(x)\\,dx=-\\int_b^a f(x)\\,dx$$\r\n$$\\mbox{If interval is empty, integral is zero:}\\qquad\\int_a^a f(x)\\,dx=0$$\r\n$$\\mbox{Constant Multiple Rule:}\\qquad\\int_a^b cf(x)\\,dx=c\\int_a^b f(x)\\,dx$$\r\n$$\\mbox{Sum/Difference Rule:}\\qquad\\int_a^b f(x)\\pm g(x)\\,dx=\\int_a^b f(x)\\,dx\\pm\\int_a^b g(x)\\,dx$$\r\n$$\\mbox{Can split up interval $[a,b]=[a,c]\\cup[c,b]$:}\\qquad\\int_a^b f(x)\\,dx=\\int_a^c f(x)\\,dx+\\int_c^b f(x)\\,dx$$\r\n$$\\mbox{The variable does not matter!:}\\qquad\\int_a^b f(x)\\,dx=\\int_a^b f(t)\\,dt$$\r\n\\end{formulabox}\r\n\r\nThe reason for the last property is that a definite integral is a \\ifont{number}, not a function, so the variable is just a placeholder that won't appear in the final answer.\r\n\r\nSome additional properties are \\ifont{comparison} types of properties.\r\n\r\n\\begin{formulabox}[Comparison Properties of Definite Integrals]\r\n$$\\mbox{If $f(x)\\geq 0$ for $x\\in[a,b]$, then:}\\qquad\\int_a^b f(x)\\,dx\\geq 0.$$\r\n$$\\mbox{If $f(x)\\geq g(x)$ for $x\\in[a,b]$, then:}\\qquad\\int_a^b f(x)\\,dx\\geq \\int_a^b g(x)\\,dx.$$\r\n$$\\mbox{If $m\\leq f(x)\\leq M$ for $x\\in[a,b]$, then:}\\qquad m(b-a)\\leq \\int_a^b f(x)\\,dx\\leq M(b-a).$$\r\n\\end{formulabox}\r\n\r\n\\begin{example}{Properties of Definite Integrals}{PropertiesDefiniteIntegrals}\r\nSuppose $\\ds{\\int_a^b f(x)~dx=7}$ and $\\ds{\\int_a^b g(x)~dx=3}$. Find:\r\n\\begin{multicols}{2}\r\n\\begin{enumerate}\r\n\t\\item\t$\\ds\\int_a^b 2f(x)-3g(x)\\,dx$.\r\n\t\\item\t$\\ds\\int_{b}^{a} 2g(x)\\,dx$.\r\n\t\\item\t$\\ds\\int_a^a f(x)\\cdot g(x)\\,dx$.\r\n\t\\item\t$\\ds\\int_a^c f(x)~dx+\\int_c^b f(x)\\,dx$.\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\vspace{5mm}\r\n\\end{example}\r\n\\begin{solution}\r\n\\begin{enumerate}\r\n\t\\item\t$\\ds\\int_a^b 2f(x)-3g(x)\\,dx=\\ds 2\\int_a^b f(x)\\,dx-3\\int_a^b g(x)\\,dx=2(7)-3(3)=5$.\r\n\t\\item\t$\\ds\\int_{b}^{a} 2g(x)\\,dx=\\ds -2\\int_{a}^{b} g(x)\\,dx=-2(3)=-6$.\r\n\t\\item\t$\\ds\\int_a^a f(x)\\cdot g(x)\\,dx=0$.\r\n\t\\item\t$\\ds\\int_a^c f(x)\\,dx+\\int_c^b f(x)\\,dx=\\ds\\int_a^b f(x)\\,dx=7$.\r\n\\end{enumerate}\r\n\\end{solution}\r\n\r\nWe next evaluate a definite integral using three different techniques.\r\n\r\n\\begin{example}{Three Different Techniques}{ThreeDifferentTechniques}\r\nEvaluate $\\ds{\\int_0^2 x+1~dx}$ by\r\n\\begin{enumerate}\r\n\\item Using FTC II (the shortcut)\r\n\\item Using the definition of a definite integral (the limit sum definition)\r\n\\item Interpreting the problem in terms of areas (graphically)\r\n\\end{enumerate}\r\n\\end{example}\r\n\r\n\\begin{solution} \r\n1. The shortcut (FTC II) is the method of choice as it is the fastest.\r\nIntegrating and using the `\\ifont{top minus bottom}' rule we have:\r\n\\begin{eqnarray*}\r\n\\int_0^2 x+1~dx&=&\\left.\\frac{x^2}{2}+x\\right|_0^2\\\\\r\n&=&\\left[\\frac{2^2}{2}+2\\right]-\\left[\\frac{0^2}{2}+0\\right]=4.\r\n\\end{eqnarray*}\r\n\r\n2. We now use the definition of a definite integral.\r\nWe divide the interval $[0,2]$ into $n$ subintervals of equal width $\\Delta x$, and from each interval choose a point $x_i^*$.\r\nUsing the formulas\r\n$$\\Delta x = \\frac{b-a}{n}\\qquad\\mbox{and}\\qquad x_i=a+i\\Delta x,$$\r\nwe have\r\n$$\\Delta x = \\frac{2}{n}\\qquad\\mbox{and}\\qquad x_i=0+i\\Delta x=\\frac{2i}{n}.$$\r\nThen taking $x_i^*$'s as right endpoints for convenience (so that $x_i^*=x_i$), we have:\r\n\\begin{eqnarray*}\r\n\\int_0^2 x+1~dx & = & \\ds\\lim_{n\\to\\infty}\\sum_{i=1}^n f(x_i^*)\\Delta x\\\\\r\n\\\\\r\n& = & \\ds\\lim_{n\\to\\infty}\\sum_{i=1}^n f\\left(\\frac{2i}{n}\\right) \\frac{2}{n}\\\\\r\n\\\\\r\n& = & \\ds\\lim_{n\\to\\infty}\\sum_{i=1}^n \\left(\\frac{2i}{n}+1\\right) \\frac{2}{n}\\\\\r\n\\\\\r\n& = & \\ds\\lim_{n\\to\\infty}\\sum_{i=1}^n \\left(\\frac{4i}{n^2}+\\frac{2}{n}\\right)\\\\\r\n\\\\\r\n& = & \\ds\\lim_{n\\to\\infty}\\left(\\sum_{i=1}^n \\frac{4i}{n^2}+\\sum_{i=1}^n \\frac{2}{n} \\right)\\\\\r\n\\\\\r\n& = & \\ds\\lim_{n\\to\\infty}\\left(\\frac{4}{n^2}\\sum_{i=1}^n i+\\frac{2}{n}\\sum_{i=1}^n 1 \\right)\\\\\r\n\\\\\r\n& = & \\ds\\lim_{n\\to\\infty}\\left(\\frac{4}{n^2}\\frac{n(n+1)}{2}+\\frac{2}{n}n \\right)\\\\\r\n\\\\\r\n& = & \\ds\\lim_{n\\to\\infty}\\left(2+\\frac{2}{n}+2 \\right)\\\\\r\n\\\\\r\n& = & 4.\r\n\\end{eqnarray*}\r\n\r\n3. Finally, let's evaluate the net area under $x+1$ from $0$ to $2$.\r\n$$\\includegraphics[width=5in]{images/int-ex}$$\r\nThus, the area is the sum of the areas of a rectangle and a triangle.\r\nHence,\r\n\\begin{eqnarray*}\r\n\\int_0^2 x+1~dx&=&\\mbox{Net Area}\\\\\r\n&=&\\mbox{Area of rectangle} + \\mbox{Area of triangle}\\\\\r\n&=&(2)(1)+\\frac{1}{2}(2)(2)\\\\\r\n&=&4.\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\nWe next apply FTC to differentiate a function.\r\n\r\n\\begin{example}{Using FTC}{UsingFTC}\r\n\\exfont{Differentiate} the following function:\r\n$$g(x)=\\int_{-2}^x \\cos(1+5t)\\sin t\\,dt.$$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe simply apply the Fundamental Theorem of Calculus directly to get:\r\n$$g'(x)=\\cos(1+5x)\\sin x.$$\r\n\\end{solution}\r\n\r\nUsing the Chain Rule we can derive a formula for some more complicated problems.\r\nWe have:\r\n$$\\frac{d}{dx}\\int_a^{v(x)}f(t)\\,dt=f(v(x))\\cdot v'(x).$$\r\n\r\nNow what if the upper limit is constant and the lower limit is a function of $x$?\r\nThen we interchange the limits and add a minus sign to get:\r\n$$\\frac{d}{dx}\\int_{u(x)}^af(t)\\,dt=-\\frac{d}{dx}\\int_a^{u(x)} f(t)\\,dt=-f(u(x))\\cdot u'(x).$$\r\n\r\nCombining these two we can get a formula where both limits are a function of $x$.\r\nWe break up the integral as follows:\r\n$$\\int_{u(x)}^{v(x)} f(t)\\,dt=\\int_{u(x)}^a f(t)\\,dt+\\int_a^{v(x)}f(t)\\,dt.$$\r\nWe just need to make sure $f(a)$ exists after we break up the integral.\r\nThen differentiating and using the above two formulas gives:\r\n\r\n\\begin{formulabox}[FTC I + Chain Rule:]\r\n$$\\frac{d}{dx}\\int_{{u(x)}}^{{v(x)}} f(t)\\,dt=f({v(x)}){v'(x)}-f({u(x)}){u'(x)}$$\r\n\\end{formulabox}\r\n\r\nMany textbooks do not show this formula and instead to solve these types of problems will use FTC I along with the tricks we used to derive the formula above.\r\nEither method is perfectly fine.\r\n\r\n\\begin{example}{FTC I + Chain Rule}{FTCIChainRule}\r\nDifferentiate the following integral:\r\n$$\\int_{10x}^{x^2} t^3\\sin(1+t) \\,dt.$$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe will use the formula above.\r\nWe have $f(t)=t^3\\sin(1+t)$, $u(x)=10x$ and $v(x)=x^2$.\r\nThen $u'(x)=10$ and $v'(x)=2x$.\r\nThus,\r\n\\begin{eqnarray*}\r\n\\frac{d}{dx}\\int_{10x}^{x^2} t^3\\sin(1+t) \\,dt&=&(x^2)^3\\sin(1+(x^2))(2x)-(10x)^3\\sin(1+(10x))(10)\\\\\r\n\\\\\r\n&=&2x^7\\sin(1+x^2)-10000x^3\\sin(1+10x)\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\n\\begin{example}{FTC I + Chain Rule}{FTCIChainRule2}\r\nDifferentiate the following integral with respect to $x$:\r\n$$\\int_{x^3}^{2x} 1+\\cos t\\,dt$$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nUsing the formula we have:\r\n$$\\frac{d}{dx}\\int_{x^3}^{2x} 1+\\cos t\\,dt=(1+\\cos(2x))(2)-(1+\\cos(x^3))(3x^2).$$\r\n\\end{solution}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:FTC}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nEvaluate $\\ds \\int_1^4 t^2+3t\\,dt$\r\n\\begin{sol}\r\n $87/2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nEvaluate $\\ds \\int_0^\\pi \\sin t\\,dt$\r\n\\begin{sol}\r\n $2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nEvaluate $\\ds \\int_1^{10} {1\\over x}\\,dx$\r\n\\begin{sol}\r\n $\\ln(10)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nEvaluate $\\ds \\int_0^5 e^x\\,dx$\r\n\\begin{sol}\r\n $\\ds e^5-1$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nEvaluate $\\ds \\int_0^3 x^3\\,dx$\r\n\\begin{sol}\r\n $\\ds 3^4/4$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nEvaluate $\\ds \\int_1^2 x^5\\,dx$\r\n\\begin{sol}\r\n $\\ds 2^6/6 -1/6$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Find the derivative of $\\ds G(x)=\\int_1^x t^2-3t\\,dt$\r\n\\begin{sol}\r\n $\\ds x^2-3x$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Find the derivative of $\\ds G(x)=\\int_1^{x^2} t^2-3t\\,dt$\r\n\\begin{sol}\r\n $\\ds 2x(x^4-3x^2)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Find the derivative of $\\ds G(x)=\\int_1^x e^{t^2}\\,dt$\r\n\\begin{sol}\r\n $\\ds e^{x^2}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Find the derivative of $\\ds G(x)=\\int_1^{x^2} e^{t^2}\\,dt$\r\n\\begin{sol}\r\n $\\ds 2xe^{x^4}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Find the derivative of $\\ds G(x)=\\int_1^x \\tan(t^2)\\,dt$\r\n\\begin{sol}\r\n $\\ds \\tan(x^2)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Find the derivative of $\\ds G(x)=\\int_{10x}^{x^2} \\tan(t^2)\\,dt$\r\n\\begin{sol}\r\n $\\ds 2x\\tan(x^4)-10\\tan(100x^2)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nSuppose $\\int_{1}^{4}f(x)\\,dx=2$ and $\\int_{1}^{4}g(x)\\,dx=7$. Find $\\int_{1}^{4}(5f(x)+3g(x))\\,dx$ and $\\int_{1}^{4}(6-2f(x))\\,dx$.\r\n\\begin{sol}\r\n\t31, 14\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nSuppose $\\int_{-2}^{5}f(x)\\,dx=3$ and $\\int_{1}^{5}f(x)\\,dx=-2$. Find $\\int_{-2}^{1}f(x)\\,dx$.\r\n\\begin{sol}\r\n\t5\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nIf $f$ is continuous on $[a,b]$, we define the average of $f(x)$ on $[a,b]$ to be\r\n\\begin{equation*}\r\n\\text{avg}_{[a,b]}(f)=\\frac{1}{b-a}\\int_{a}^{b}f(x)\\,dx.\r\n\\end{equation*}\r\n\\begin{enumerate}\r\n\t\\item\tWhat is the average of $\\sqrt{x}$ on the interval $[0,1]?$\r\n\t\\item\tIf the average of $f(x)$ on $[0,2]$ and on $[2,5]$ are 6 and 4 respectively, then what is its average on $[0,5]$?\r\n\\end{enumerate}\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\t\\item\t2/3\r\n\t\\item\t24/5\r\n\\end{enumerate}\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "f6fb0a240df14315708a06411f47619a45d96289", "size": 22892, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6-integration/6-2-ftc.old.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6-integration/6-2-ftc.old.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6-integration/6-2-ftc.old.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.2833876221, "max_line_length": 305, "alphanum_fraction": 0.6580027957, "num_tokens": 7925, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.8872045937171068, "lm_q1q2_score": 0.7013621301963838}}
{"text": "In this work, we present a data-driven IRL-based social navigation pipeline.\\\\\nAn overview of the pipeline:\n\\\\ \\textbf{An image showing the block diagram of the pipeline including the environment, the feature extractor and the other components}\nWe will describe each component of the pipeline in greater detail.\n\\section*{The IRL block:}\nInverse reinforcement learning(IRL) or inverse optimal control(IOC) has been in vogue in recent years when it comes to training robots to perform real-world tasks. This is understandable as assigning rewards to individual states to illicit out desired behaviors is challenging. IRL provides a better alternative of obtaining the underlying reward function as well as a trained agent on the obtained reward function using demonstrations from the expert.\n\nTo keep the chapter self-contained, we will briefly go over the definition of a Markov decision process, which is at the base of reinforcement and inverse reinforcement learning.\nA Markov decision process or MDP can be defined as a tuple ($\\mathcal{S}$,$\\mathcal{A}$,T,$\\gamma$, $\\mathcal{R}$)  where,\n\\begin{itemize}\n\t\\item $\\mathcal{S}$ is the set of all possible states.\n\t\\item $\\mathcal{A}$ is the set of all possible actions.\n\t\\item T is the state transition dynamics, i.e. the probability of moving to a state given its previous state and action, $P(s^{'}|s,a)$ .\n\t\\item $\\gamma$ is the discounting factor.\n\t\\item $\\mathcal{R}$ is the set of rewards $R:  \\mathcal{S} \\mapsto \\mathbb{R} $ is the reward function. In practice, instead of using the raw states, hand engineered features are extracted from the states with are then used to calculate the reward of a particular state. This alleviates a lot of complexity when dealing with large continuous state-spaces. \n\t\\end{itemize}  \nThe goal of the IRL is to infer a reward function that best explains the behavior of the expert. The expert behavior is represented in terms of expert demonstrations or trajectories, $D = \\{ \\tau_1, \\tau_2, \\tau_3, \\dots, \n\\tau_{M} \\}$ in the context of navigation. Each of these trajectories, in turn, can be further broken down into a collection of states $\\tau_{i} = \\{ s_{0}, s_{1}, s_{2}, \\dots, s_{T} \\}$ as visited by the expert in the trajectory. \n\nWe base our work on Wulfmeier's paper, which in turn is a neural network adaptation of the work done by Ziebart 2008. \nAccording to the max entropy formulation, the probability of the occurrence of a trajectory is directly proportional to the reward it receives.\n\\begin{align}\nEntropy equation - Ziebart equation 2\n\\end{align}\nand is equal to:\n\\begin{align}\nequation with z\n\\end{align}\nGiven a set of expert demonstrations, an optimal reward structure should maximize the probability of the occurrence of the expert demonstrations and their associated states. Mathematically, this is given by \n\\begin{align}\nthe equation for the loglikelihood-Ziebart equation 6\n\\end{align}\nThe original paper by Ziebart used a linear combination of weights as reward functions. But linear representations have limited capabilities when it comes to expressing complex reward functions. This problem is addressed by Wulfmeier 2015 where they restructure the maxent IRL formulation using neural networks. Neural networks are universal function approximators, and this vastly improves on the amount of complexity the reward functions can encapsulate.\n\n\\begin{align}\nderive the gradient expression in equation 3 of iros paper\n\\end{align}\n\nThe original formulation of MEDIRL was in the context of a model-based setting and the state transition matrix was used to calculate the agent SVF. While this produces an exact value of the agent SVF, assuming the availability of the state transition matrix is fairly optimistic for most real-world tasks including navigation. In an attempt to make things less constrained we take the model-free approach and focus on calculating the SVF using sampling-based methods. \nThe SVF calculation:\nThe main challenge going model free is the calculation of the Z value, which previously could be calculated using dynamic programming [citation of the paper]. \nUnder the assumption of a model-free but deterministic environment, the SVF of a deterministic policy can be reasonably computed by taking trajectory samples of the policy from the context of all the existing pedestrians in the scene. \n\\begin{align}\nequation 4 from iros2020\n\\end{align}\nwhere the $\\mathcal{P}$ represents state transitions obtained from sampling and not the state transition dynamics. \\textbf{We argue that this assumption is reasonable in a navigation setting because the task is not inherently uncertain, and most transition dynamic uncertainty can be attributed to sensory noise and control error. We summarize our approach in algorithm 1. (Taken word-to-word from iros manuscript)}\n\\begin{algorithm}\n\talgorithm 1 from iros2020\n\\end{algorithm}\n\nFor solving the MDP, we employ actor-critic methods, which we will describe in detail in the next section.\n\n%\\subsection*{Overview of the algorithm used}\n%The algorithm trains for two networks, the reward network that, given the features of a state returns the reward associated with it,\\\\\n%\\textbf{equation}\\\\ stating this.\n%and the policy network, which given the same, returns the best possible action.\\\\\n%\\textbf{equation}\\\\\n%The method starts with randomly initializing the weights of the reward network. This reward network is then used in the  RL block to train an agent which is optimal for the current reward structure. Once, an optimal policy is obtained, the policy is then sampled from, in the environment to obtain roll outs or trajectories in this case. A trajectory is given by the sequence of states visited by the agent {s1, s2, ... sn}.\n%Once the trajectories are obtained, they are used to calculate the state visitation frequency. The difference between the expert and the agent SVF is used to calculate the loss\n%\\textbf{equation}\n%This loss is then back propagated through the reward network to update the weights.\n%Once the weights are updated, the new network is again fed into the RL block. This iterative process continues until completion.\n%Explanation of the L1 regularization over l2 regularization \n\n\\section*{The RL block:}\n\nActor-critic methods are a class of reinforcement learning algorithms that are built upon policy gradient methods. \nIn policy-gradient methods, the goal is to iteratively improve the performance of a given policy which is achieved by maximizing the expected return of the policy. Mathematically, the objective of a policy gradient method can be expressed as:\n\\begin{align}\nmaximize \\;\\; J( \\theta )  &\\; = \\; \\mathbb{E} [ R | \\pi_{\\theta} ] \\\\\n\t\t\t\t\t   & \\; = \\; \\mathbb{E}[ \\sum^{T-1}_{t=0} r_{t+1}| \\pi_{\\theta}] \n\\end{align}\nwhere, $r_{t}$ is the reward obtained at time $t$ and $\\pi_{\\theta}$ is the policy with parameters $\\theta$.\\\\\nThis leads to an update function:\n\\begin{align}\n\\delta J ( \\theta ) = \n\\end{align} \nVanilla policy gradient methods suffer from high biases because they do not have a normalizing factor for the second term. This is addressed by introducing a \nbaseline. \n\\begin{align}\nEquation with the baseline to the vanilla policy gradient.\n\\end{align}\nThe baseline can be calculated in various ways. One of the resulting algorithms is the A2C or the Advantage actor-critic algorithm, which we use to solve our MDP.\nThe A2C method:\nTwo symbiotic agents at play here. The actor and the critic. \nThe critic estimates the value function of a given state.\nThe actor uses this information to update its policy distribution.\n\\begin{algorithm}\n\tThe actor-critic algorithm.\n\\end{algorithm}\n\n\n\\section*{The feature extractor}\nThe feature extractor is a vital component in the navigation pipeline. It acts as a medium that enables the learning algorithm to interact with the environment. The performance of a learning agent is highly contingent on the design of the feature extractor. \\cite{vasquez_et_al}\\\\\n\nThe feature vector generated by the feature extractor can be broken down into 2 broad components: local and global components.\n\\begin{itemize}\n\t\\item The \\textbf{local component}, as the name suggests, comprises of the information from nearby surroundings of the agent captured in the form of a binary feature vector. This provides an approximate idea of the obstacles in the vicinity.\n\t\\item The \\textbf{global component}, on the other hand, provides a rough direction of where the goal is with respect to the agent. This provides the agent with a purpose of navigation, preventing it from just rambling around the map.\n\\end{itemize}\n The environment, by design, publishes a detailed description of obstacles in the map, including their location, orientation, and velocity, and the goal. Having access to such a detailed picture of the surroundings on a mobile robot navigating any given scene in the real world is highly unlikely and difficult to obtain. This is additionally addressed by the feature extractor, which also acts as an information moderator, receiving raw information from the environment and packaging it in a feature vector that can be readily constructed by a mobile robot on the go using off-the-shelf sensors.\\\\\n Both the local and the global components along with their subcomponents are described in greater detail below.\nTalk about the relative orientation calculation\n\n\n\\subsection*{The global component}\nThe global information is further comprised of 3 elements:\n\n\\subsubsection*{Relative goal orientation} \nThis acts as a compass, providing a rough estimate of the location of the goal based on the current position and orientation of the agent. This is denoted by a $9 \\times 1$ one-hot vector, where the presence of the goal in any one of the bins is marked by a $1$ keeping the rest to $0$. The $360 \\degree$ around the agent are divided into $8$ equal divisions forming the first 8 bins of $45 \\degree$ each. The $9^{th}$ bin denotes the contact of the agent with the goal. The structuring of the bins is shown below. \n\\begin{figure}[!htbp]\n\tFigure showing the relative goal orientation\n\\end{figure}\n\n\\subsubsection*{Change in orientation}\nRepresented by a $5 \\times 1$ one-hot vector, the change in orientation captures the magnitude of the change in the orientation of the agent in consecutive steps. The value ranges between $0 \\degree$ -  $ 180 \\degree$. This value is binned in one of 5 asymmetric bins. The rationale behind the uneven distribution is that empirically we have observed that human motion is smooth. So, the bins are constructed in a way to have a finer resolution in the lower range. This helps capture the nuances in the human motion in greater detail leading to better encapsulation of the essence of the navigational pattern. The division of the range is shown below.\n\n\\begin{table}[htbp]\n\t\\caption{Bin thresholds orientation change features.}\n\t\\label{orientation-change-bins}\n\t\\begin{center}\n\t\t\\renewcommand{\\arraystretch}{1.3}\n\t\t\\begin{tabular}{|c|c|}\n\t\t\t\\hline\n\t\t\tFeature & Threshold \\\\\n\t\t\t\\hline\n\t\t\t$\\phi_{O1}$ & $\\alpha_{OC} \\in \\left[ 0 , \\frac{\\pi}{9} \\right)$ \\\\\n\t\t\t\n\t\t\t$\\phi_{O2}$ & $\\alpha_{OC} \\in \\left[ \\frac{\\pi}{9} , \\frac{2\\pi}{9} \\right)$ \\\\\n\t\t\t\n\t\t\t$\\phi_{O3}$ & $\\alpha_{OC} \\in \\left[ \\frac{2\\pi}{9} , \\frac{3\\pi}{9} \\right)$ \\\\\n\t\n\t\t\t\n\t\t\t$\\phi_{O5}$ & $\\alpha_{OC} \\in \\left[ \\frac{3\\pi}{9} , \\frac{4\\pi}{9} \\right)$ \\\\\n\t\t\t\n\t\t\t$\\phi_{O6}$ & $\\alpha_{OC} \\in \\left[ \\frac{4\\pi}{9} , \\pi \\right)$ \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\\subsection*{Deviation from the goal}\nRepresented by a $4 \\times 1$ one-hot vector, the deviation from goal captures the magnitude of the angle between the vector to the goal from the current position of the agent and the current orientation vector of the agent. The value ranges from $0 \\degree$ - $ 180 \\degree$ which is again asymmetrically divided into 4 bins, with greater emphasis is laid on the lower degrees due to reasons mentioned earlier.\n\n\\begin{table}[htbp]\n\t\\caption{Bin thresholds for deviation from the goal.}\n\t\\label{deviation-from-goal-bins}\n\t\\begin{center}\n\t\t\\renewcommand{\\arraystretch}{1.3}\n\t\t\\begin{tabular}{|c|c|}\n\t\t\t\\hline\n\t\t\tFeature & Threshold \\\\\n\t\t\t\\hline\n\t\t\t$\\phi_{GA1}$ & $\\alpha_{GA} \\in \\left[ 0 , \\frac{\\pi}{8} \\right)$ \\\\\n\t\t\t\n\t\t\t$\\phi_{GA2}$ & $\\alpha_{GA} \\in \\left[ \\frac{\\pi}{8} , \\frac{\\pi}{4} \\right)$ \\\\\n\t\t\t\n\t\t\t$\\phi_{GA3}$ & $\\alpha_{GA} \\in \\left[ \\frac{\\pi}{4} , \\frac{3\\pi}{4} \\right)$ \\\\\n\t\t\t\n\t\t\t$\\phi_{GA4}$ & $\\alpha_{GA} \\in \\left[ \\frac{3\\pi}{4} , \\pi \\right]$ \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\subsubsection*{Speed}\nThe entire range of all possible speed values are divided into 6 divisions and the current speed of the agent is represented by a $ 6 \\times 1$ one-hot feature vector. The entire range of possible speeds are divided into 6 divisions with each division corresponding to an element of the one-hot vector.\n\n%\\begin{table}[htbp]\n%\t\\caption{Thresholds for the qantization of the speed of the agent.}\n%\t\\label{deviation-from-goal-bins}\n%\t\\begin{center}\n%\t\t\\renewcommand{\\arraystretch}{1.3}\n%\t\t\\begin{tabular}{|c|c|}\n%\t\t\t\\hline\n%\t\t\tRaw speed & Speed bin \\\\\n%\t\t\t\\hline\n%\t\t\t0 - 0.2 & 0 \\\\\n%\t\t\t0.2 - 0.4 & 1 \\\\\n%\t\t\t0.4 - 0.6 & 2 \\\\\n%\t\t\t\\hline\n%\t\t\\end{tabular}\n%\t\\end{center}\n%\t\\end{table}\n\n\\subsection*{The local information}\nTaking inspiration from previous works in this field \\cite{fahad-et-al} \\cite{vasquez-et-al}, we use spatial bins to effectively break the region surrounding the agent into discrete segments and calculate a 'risk' metric for each of these bins.\n\n\\subsubsection*{Creation of the bins}\nThere are 16 spatial bins surrounding the agent. They are arranged in two concentric circles around the agent. The region between the agent and the inner circle is then broken into 8 equal divisions. These form bins from 1 - 8. Similarly, the region between the first and the second bin is again divided into 8 equal divisions which form bins 9 - 16.\n\\subsubsection*{Calculation of the risk}\n'Risk' is a term we label the 'threat' the agent faces at a given time from any of these bins. Here 'threat' can loosely be seen as a measure of the possibility of hitting an obstacle. The higher the threat, the greater the chance that if the agent and the obstacles continue on their current course it will end in a collision.\nThe 'risk factor' is divided in 3 levels: high, low and something in between.\n\\begin{itemize}\n\t\\item High risk:\nWhen the relative motion of an obstacle is towards the agent and can lead to a collision if not intervened.\n\t\\item Low risk:\nWhen the relative motion of an obstacle is away from the agent.\n\t\\item Med risk:\nAnything in between\n\\end{itemize}\nThe calculation of the risk values are based on the following entities:\n\\begin{align}\n\t\\vec{o}_{rel} = & \\;\\; \\vec{o}_{obs} - \\vec{o}_{agent}  \\\\\n\t\\vec{d}_{rel} =  &\\;\\; \\vec{d}_{agent} - \\vec{d}_{obs} \\\\\n\t\\theta_{risk} =  & \\;\\; \\angle (\\vec{o}_{rel}, \\vec{o}_{rel}) \\\\\n\t\\mathbf{s}_{obs} = & \\;\\; \\tan(\\theta_{risk}) \\times |\\vec{d_{rel}}| \\\\\n\t\\mathbf{T} = & \\;\\; \\text{agent witdh} + \\text{obstacle witdh}\n\\end{align}\nwhere $\\vec{o}_{rel}$ is the relative orientation of the obstacle w.r.t the agent, $\\vec{d}_{rel}$ is the relative position of the agent w.r.t to the obstacle, $\\theta_{risk}$ is the angle between the vectors, $\\vec{o}_{rel}$ and $\\vec{d}_{rel}$,  $\\mathbf{s}_{obs}$ is the estimated \\textbf{safety margin} between the agent and the obstacle and $\\mathbf{T}$ is a predefined value which if maintained between the agent and an obstacle should guarantee a collision-free trajectory.\\\\\nAn obstacle is marked as 'high risk' when $\\theta$ is less than $90\\degree$ and the safety margin is less than $\\mathbf{T}$. If $\\theta$ < $90 \\degree$, this indicates that the obstacle is moving away from the agent and hence chances of collision are less and hence low risk. Anything that does not fall in the above two categories are considered as medium risk. The risk calculation conditions and values are summarized in Table \\ref{risk-categorization-table}\n\n\\begin{table}[htbp]\n\t\\caption{Categorization of the risk.}\n\t\\label{risk-categorization-table}\n\t\\begin{center}\n\t\t\\renewcommand{\\arraystretch}{1.3}\n\t\t\\begin{tabular}{|c|c|}\n\t\t\t\\hline\n\t\t\tRisk value & Risk condition \\\\\n\t\t\t\\hline\n\t\t\tHigh & $\\theta < 90\\degree$ \\&  $\\mathbf{s}_{obs}$ < $\\mathbf{T}$   \\\\\n\t\t\t\n\t\t\tLow & $\\theta > 90\\degree$\\\\\n\t\t\t\n\t\t\tMedium & otherwise \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\nThe risk value of each bin is represented using a $3 \\times 1$ one-hot vector. One thing to note is the risk is calculated for individual obstacles present in the bin separately. And it is not uncommon to have more than one obstacle falling in different risk divisions from the same spatial bin. In that case, the risk value assigned to that bin is the highest risk posed among all the obstacles that fall under that spatial bin.\n\\begin{figure}[!htbp]\n\t\\text{Graphics that shows each of the risk conditions}\n\\end{figure}\n\n\\section*{The SVF calculation}\nOne of the main challenges of IRL is calculating the expected state distribution or the state visitation frequency (svf) of a given agent. (equation x). In model-based environments, this can be calculated using the state transition matrix and dynamic programming \\cite{wulfmeier-deepirl}. Having access to the state dynamics of the environment might be difficult and not always readily available, especially in real-world applications like navigation. Instead, we relax this assumption for a model-free but deterministic environment. \\textbf{Explanation as to why this is a reasonable assumption} This is a reasonable assumption in the context of a navigation problem because the movements of pedestrians in general are inherently deterministic. %and any observed uncertainty by the agent can be attributed to the error in measurement by the onboard sensors.\\\\\n\nDue to the lack of state dynamics we use sampling techniques to get a \\textbf{good} estimate of the svf. While this can be time consuming and computationally expensive, the problem is drastically simplified when using greedy policies. (greedy soft actor critic).\\textbf{Why?} \nSvf calculation for an agent following a greedy policy in a deterministic environment can be calculated by taking a single sample trajectory for each pedestrian by replacing them with the agent and letting it run till completion. The calculation of the expected state visitation frequency of the agent is shown in equation \\ref{agent-approx}\n\\begin{align}\n\\label{agent-approx}\n\\text{Equation to calculate the state visitation frequency}\n\\end{align}\nAdditionally, we also introduce a \\textbf{smoothing technique} for the calculated svf. \\\\\n\\textbf{What is smoothing?}\\\\\nIn the traditional way of calculating the SVF, the observation of a given state contributes to the increment of the visitation frequency of that state by 1. \nInstead for a single observation, we opt for the increment in the visitation frequency of a set of neighboring states based on the closeness of the neighboring states to the state observed. Here smoothing is defined as the distribution of the visitation weight of a state over its set of neighboring states based on their spatial similarity.\\\\\n\\textbf{Why smoothing?}\nHaving a 1 to 1 mapping between the observation and the increment of the SVF misses out on the fact that not all states \\textit{are equally different.} \\textbf{differ from each other in equal magnitude} \\\\\n\\textbf{For example:} consider 3 different states, which differ only in their goal location component. Now, if two of the states indicated the goal to be in the $2^{nd}$ spatial bin and $3^{rd}$ spatial bin, then the difference between these two states are smaller than a $3^{rd}$ state where the goal is in the $6^{th}$ bin.\nThis inequality in the differences among different states are accounted for in the smoothing, by increasing the weighted increment of a set of neighboring states of the observed state (based on their similarity) rather than increasing the value of the observed state only. \\\\ \n\\textbf{How smoothing?}\nThe state vector comprises of different components, and the 'smoothed' state is obtained by convolving a smoothing kernel to each of them separately. The values used in the kernel, and the type of convolution applied depends on the nature of the spatial division the feature represents and is summarised in the Table \\ref{conv-table}.\n\n\\begin{table}\n\t\\caption{Table showing the details of the convolution used for smoothing the state feature vector.}\n\t\\label{conv-table}\n\t\\begin{center}\n\t\t\\renewcommand{\\arraystretch}{1.3}\n\t\t\\begin{tabular}{|c|c|c|}\n\t\t\t\\hline\n\t\t\tFeature component & Convolution Kernel & Convolution type\\\\\n\t\t\t\\hline\n\t\t\tRelative goal orientation & $ [0.1, \\;0.8, \\; 0.1 ]$ & Wrap  \\\\\n\t\t\t\n\t\t\tChange in orientation & $[ 0.1, \\; 0.8; \\;0.1 ]$ & Same \\\\\n\t\t\t\n\t\t\tDeviation from goal & $[0.9,\\; 0.1]$, $[0.1,\\; 0.9]$,\n\t\t\t\t\t\t\t\t\t      $[0.05, \\; 0.9, \\; 0.05]$, $[0.1,\\; 0.9]$ & Same \\\\\n\t\t\tLocal spatial bins & $[ 0.1, \\; 0.8,\\;0.1 ]$ & Wrap \\\\\n\t\t\tSpeed info & $[ 0.1, \\; 0.8,\\;0.1 ]$  & Same \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n", "meta": {"hexsha": "6df50650973ee74580221d20a3d1bc144b97de93", "size": 21090, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX-Thesis-Template/base/chapter/old_thesis_structure/part3_chapter2.tex", "max_stars_repo_name": "ranok92/my_masters_thesis", "max_stars_repo_head_hexsha": "5a66e039b5702ff8045bd3f635572ada1d4482ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-17T08:30:52.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-17T08:30:52.000Z", "max_issues_repo_path": "LaTeX-Thesis-Template/base/chapter/old_thesis_structure/part3_chapter2.tex", "max_issues_repo_name": "ranok92/my_masters_thesis", "max_issues_repo_head_hexsha": "5a66e039b5702ff8045bd3f635572ada1d4482ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LaTeX-Thesis-Template/base/chapter/old_thesis_structure/part3_chapter2.tex", "max_forks_repo_name": "ranok92/my_masters_thesis", "max_forks_repo_head_hexsha": "5a66e039b5702ff8045bd3f635572ada1d4482ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 76.4130434783, "max_line_length": 860, "alphanum_fraction": 0.7548601233, "num_tokens": 5297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7013108090892406}}
{"text": "\n\\section{Expression types}\\label{sec:dsdl_expression_types}\n\nExpression types are a special category of data types whose instances can only exist and be operated upon\nat the time of DSDL definition processing.\nAs such, expression types cannot be used to define attributes,\nand their instances cannot be exchanged between nodes.\n\nExpression types are used to represent values of constant expressions which are evaluated\nwhen a DSDL definition is processed.\nResults of such expressions can be used to define various constant properties,\nsuch as array length boundaries or values of constant attributes.\n\nExpression types are specified in this section.\nEach expression type has a formal DSDL name for completeness;\neven if such types can't be used to define attributes,\na well-defined formal name allows DSDL processing tools to emit well-formed\nand understandable diagnostic messages.\n\n\\subsection{Rational number}\\label{sec:dsdl_rational}\n\nAt the time of DSDL definition processing, integer and real numbers are represented internally as rational numbers\nwhere the range of numerator and denominator is unlimited\\footnote{%\nTechnically, the range may only be limited by the memory resources available to the DSDL processing tool.}.\nDSDL processing tools are not permitted to introduce any implicit rational number transformations that\nmay result in a loss of information.\n\nThe DSDL name of the rational number type is ``\\verb|rational|''.\n\nRational numbers are assumed to be stored in a normalized form, where the denominator is positive\nand the greatest common divisor of the numerator and the denominator is one.\n\nA rational number can be used in a context where an integer value is expected only if its denominator equals one.\n\nImplicit conversions between boolean-valued entities and rational numbers are not allowed.\n\n\\begin{UAVCANSimpleTable}{Operators defined on instances of rational numbers}{|l l X X|}\n    Op & Type & Constraints & Description\n    \\label{table:dsdl_operators_rational} \\\\\n\n    \\texttt{\\textbf{+}}     & $(\\texttt{rational}) \\rightarrow \\texttt{rational}$ & &\n    No effect. \\\\\n    \\texttt{\\textbf{-}}     & $(\\texttt{rational}) \\rightarrow \\texttt{rational}$ & &\n    Negation. \\\\\n\n    \\texttt{\\textbf{**}}    & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{rational}$ &\n    Power denominator equals one &\n    Exact exponentiation. \\\\\n\n    \\texttt{\\textbf{**}}    & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{rational}$ &\n    Power denominator greater than one &\n    Exponentiation with imp\\-lem\\-en\\-ta\\-ti\\-on-de\\-fin\\-ed accuracy. \\\\\n\n    \\texttt{\\textbf{*}}  & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{rational}$ & &\n    Exact multiplication. \\\\\n\n    \\texttt{\\textbf{/}}  & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{rational}$ &\n    Non-zero divisor &\n    Exact division. \\\\\n\n    \\texttt{\\textbf{\\%}} & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{rational}$ &\n    Non-zero divisor &\n    Exact modulo. \\\\\n\n    \\texttt{\\textbf{+}}  & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{rational}$ & &\n    Exact addition. \\\\\n\n    \\texttt{\\textbf{-}}  & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{rational}$ & &\n    Exact subtraction. \\\\\n\n    \\texttt{\\textbf{|}}  & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{rational}$ &\n    Denominators equal one &\n    Bitwise or. \\\\\n\n    \\texttt{\\textbf{\\textasciicircum{}}} & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{rational}$ &\n    Denominators equal one &\n    Bitwise xor. \\\\\n\n    \\texttt{\\textbf{\\&}} & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{rational}$ &\n    Denominators equal one &\n    Bitwise and. \\\\\n\n    \\texttt{\\textbf{!=}} & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{bool}$ & & Exact inequality. \\\\\n    \\texttt{\\textbf{==}} & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{bool}$ & & Exact equality. \\\\\n    \\texttt{\\textbf{<=}} & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{bool}$ & & Less or equal. \\\\\n    \\texttt{\\textbf{>=}} & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{bool}$ & & Greater or equal. \\\\\n    \\texttt{\\textbf{<}}  & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{bool}$ & & Strictly less. \\\\\n    \\texttt{\\textbf{>}}  & $(\\texttt{rational}, \\texttt{rational}) \\rightarrow \\texttt{bool}$ & & Strictly greater. \\\\\n\n\\end{UAVCANSimpleTable}\n\n\\subsection{Unicode string}\\label{sec:dsdl_string}\n\nThis type contains a sequence of Unicode characters.\nIt is used to represent string literals internally.\n\nThe DSDL name of the Unicode string type is ``\\verb|string|''.\n\nA Unicode string containing one symbol whose code point is within $[0, 127]$\n(i.e., an ASCII character) is implicitly convertible into a \\verb|uint8|-typed constant attribute value,\nwhere the value of the constant is to be equal the code point of the symbol.\n\n\\begin{UAVCANSimpleTable}{Operators defined on instances of Unicode strings}{|l l X|}\n    Op & Type & Description\n    \\label{table:dsdl_operators_string} \\\\\n\n    \\texttt{\\textbf{+}}  & $(\\texttt{string}, \\texttt{string}) \\rightarrow \\texttt{string}$ &\n    Concatenation. \\\\\n\n    \\texttt{\\textbf{!=}} & $(\\texttt{string}, \\texttt{string}) \\rightarrow \\texttt{bool}$ &\n    Inequality of Unicode NFC normalized forms.\n    NFC stands for \\emph{Normalization Form Canonical Composition} --\n    one of standard Unicode normalization forms where characters are recomposed by canonical equivalence. \\\\\n\n    \\texttt{\\textbf{==}} & $(\\texttt{string}, \\texttt{string}) \\rightarrow \\texttt{bool}$ &\n    Equality of Unicode NFC normalized forms. \\\\\n\n\\end{UAVCANSimpleTable}\n\nThe set of operations and conversions defined for Unicode strings is to be extended in future versions of\nthe specification.\n\n\\subsection{Set}\\label{sec:dsdl_set}\n\nA set type represents an unordered collection of unique objects.\nAll objects must be of the same type.\nUniqueness of elements is determined by application of the equality operator ``\\verb|==|''.\n\nThe DSDL name of the set type is ``\\verb|set|''.\n\nA set can be constructed from a set literal, in which case such set must contain at least one element.\n\nThe attributes and operators defined on set instances are listed in the tables~\\ref{table:dsdl_set_attributes}\nand~\\ref{table:dsdl_set_operators}, where $E$ represents the set element type.\n\n\\begin{UAVCANSimpleTable}{Attributes defined on instances of sets}{|l l X X|}\n    Name & Type & Constraints & Description\n    \\label{table:dsdl_set_attributes} \\\\\n\n    \\texttt{min} & $E$ &\n    Operator ``\\texttt{<}'' is defined \\mbox{$(E, E) \\rightarrow \\texttt{bool}$} &\n    Smallest element in the set determined by sequential application of the operator ``\\texttt{<}''. \\\\\n\n    \\texttt{max} & $E$ &\n    Operator ``\\texttt{>}'' is defined \\mbox{$(E, E) \\rightarrow \\texttt{bool}$} &\n    Greatest element in the set determined by sequential application of the operator ``\\texttt{>}''. \\\\\n\n    \\texttt{count} & \\texttt{rational} & &\n    Cardinality. \\\\\n\n\\end{UAVCANSimpleTable}\n\n\\newcommand\\SetElementwiseOperator[1]{%\n    \\texttt{\\textbf{#1}} & $(\\texttt{set}_\\texttt{<E>}, E) \\rightarrow \\texttt{set}_\\texttt{<R>}$ & $E$ is not a set &\n    Elementwise $(E, E) \\rightarrow R$.\\\\\n\n    \\texttt{\\textbf{#1}} & $(E, \\texttt{set}_\\texttt{<E>}) \\rightarrow \\texttt{set}_\\texttt{<R>}$ & $E$ is not a set &\n    Elementwise $(E, E) \\rightarrow R$.\\\\\n}\n\n\\begin{UAVCANSimpleTable}{Operators defined on instances of sets}{|l l l X|}%\n    \\label{table:dsdl_set_operators}%\n    Op & Type & Constraints & Description \\\\\n\n    \\texttt{\\textbf{==}} & $(\\texttt{set}_\\texttt{<E>}, \\texttt{set}_\\texttt{<E>}) \\rightarrow \\texttt{bool}$ & &\n    Left equals right. \\\\\n\n    \\texttt{\\textbf{!=}} & $(\\texttt{set}_\\texttt{<E>}, \\texttt{set}_\\texttt{<E>}) \\rightarrow \\texttt{bool}$ & &\n    Left does not equal right. \\\\\n\n    \\texttt{\\textbf{<=}} & $(\\texttt{set}_\\texttt{<E>}, \\texttt{set}_\\texttt{<E>}) \\rightarrow \\texttt{bool}$ & &\n    Left is a subset of right. \\\\\n\n    \\texttt{\\textbf{>=}} & $(\\texttt{set}_\\texttt{<E>}, \\texttt{set}_\\texttt{<E>}) \\rightarrow \\texttt{bool}$ & &\n    Left is a superset of right. \\\\\n\n    \\texttt{\\textbf{<}}  & $(\\texttt{set}_\\texttt{<E>}, \\texttt{set}_\\texttt{<E>}) \\rightarrow \\texttt{bool}$ & &\n    Left is a proper subset of right. \\\\\n\n    \\texttt{\\textbf{>}}  & $(\\texttt{set}_\\texttt{<E>}, \\texttt{set}_\\texttt{<E>}) \\rightarrow \\texttt{bool}$ & &\n    Left is a proper superset of right. \\\\\n\n    \\texttt{\\textbf{|}} &\n    $(\\texttt{set}_\\texttt{<E>}, \\texttt{set}_\\texttt{<E>}) \\rightarrow \\texttt{set}_\\texttt{<E>}$ & &\n    Union. \\\\\n\n    \\texttt{\\textbf{\\textasciicircum{}}} &\n    $(\\texttt{set}_\\texttt{<E>}, \\texttt{set}_\\texttt{<E>}) \\rightarrow \\texttt{set}_\\texttt{<E>}$ & &\n    Disjunctive union. \\\\\n\n    \\texttt{\\textbf{\\&}} &\n    $(\\texttt{set}_\\texttt{<E>}, \\texttt{set}_\\texttt{<E>}) \\rightarrow \\texttt{set}_\\texttt{<E>}$ & &\n    Intersection. \\\\\n\n    \\SetElementwiseOperator{**}\n    \\SetElementwiseOperator{*}\n    \\SetElementwiseOperator{/}\n    \\SetElementwiseOperator{\\%}\n    \\SetElementwiseOperator{+}\n    \\SetElementwiseOperator{-}\n\n\\end{UAVCANSimpleTable}\n\n\\subsection{Serializable metatype}\\label{sec:dsdl_metaserializable}\n\nSerializable types (which are reviewed in section \\ref{sec:dsdl_serializable_types})\nare instances of the serializable metatype.\nThis metatype is convenient for expression of various relations and attributes defined on serializable types.\n\nThe DSDL name of the serializable metatype is ``\\verb|metaserializable|''.\n\nAvailable attributes are defined on a per-instance basis.\n", "meta": {"hexsha": "b982adfac763f113898220976f05f3ab7471c281", "size": 9657, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "specification/dsdl/expression_types.tex", "max_stars_repo_name": "veronistar/specification", "max_stars_repo_head_hexsha": "5fd0f0aed2a255007cefc0f29b48f2ba9cb88931", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "specification/dsdl/expression_types.tex", "max_issues_repo_name": "veronistar/specification", "max_issues_repo_head_hexsha": "5fd0f0aed2a255007cefc0f29b48f2ba9cb88931", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "specification/dsdl/expression_types.tex", "max_forks_repo_name": "veronistar/specification", "max_forks_repo_head_hexsha": "5fd0f0aed2a255007cefc0f29b48f2ba9cb88931", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.338028169, "max_line_length": 118, "alphanum_fraction": 0.6957647302, "num_tokens": 2830, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574068, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.7013082731069805}}
{"text": "\\section{Elimination of nondeterminism}\n\n\\subsection{Elimination of $\\epsilon$-moves}\nFor each $p \\xrightarrow{\\epsilon} q$:\n\\begin{itemize}\n    \\item For each $q \\xrightarrow{a} r$ where $a$ can be anything (including $\\epsilon$) add an arc $p \\xrightarrow{a} r$\n    \\item If $q$ was final, $p$ becomes final\n    \\item Remove $p \\xrightarrow{\\epsilon} q$\n\\end{itemize}\n\nIf there is a cycle of $\\epsilon$-moves all the involved nodes can be merged.\n\n\\subsection{Berry-Sethi Method}\n\\begin{itemize}\n    \\item Number non-$\\epsilon$ arcs and add $\\dashv$ on exiting final states\n    \\item Compute $Ini$ and $Fin$ with the same rules as r.e.\n    \\item Apply Berry-Sethi construction\n\\end{itemize}\nThe automaton obtained is deterministic but can be non-minimal.\n", "meta": {"hexsha": "874be395bad598be035da1737a2439c8761736bd", "size": 757, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "automata/elimination-of-nondeterminism.tex", "max_stars_repo_name": "TiberioG/FLC-cheatsheet", "max_stars_repo_head_hexsha": "d86e8ba9c80fece75ffccf47c273334b677f4934", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-01-13T14:36:20.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-18T16:22:18.000Z", "max_issues_repo_path": "automata/elimination-of-nondeterminism.tex", "max_issues_repo_name": "TiberioG/FLC-cheatsheet", "max_issues_repo_head_hexsha": "d86e8ba9c80fece75ffccf47c273334b677f4934", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "automata/elimination-of-nondeterminism.tex", "max_forks_repo_name": "TiberioG/FLC-cheatsheet", "max_forks_repo_head_hexsha": "d86e8ba9c80fece75ffccf47c273334b677f4934", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-05-21T11:05:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-17T14:59:50.000Z", "avg_line_length": 37.85, "max_line_length": 122, "alphanum_fraction": 0.7186261559, "num_tokens": 221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7012893091328983}}
{"text": "\\subsection{The singular value decomposition}\n\nWe begin this section with an important definition.\n\n\\begin{definition}{Singular values}{singular-values}\nLet $A$ be an $m\\times n$-matrix. The singular values of $A$ are the square roots of the positive\neigenvalues of $A^TA$\\index{singular values}.\n\\end{definition}\n\nSingular Value Decomposition (SVD) can be thought of as\na generalization of orthogonal diagonalization of a symmetric matrix\nto an arbitrary $m\\times n$-matrix. This decomposition is the focus of this section.\n\nThe following is a useful result that will help when computing the SVD of matrices.\n\n\\begin{proposition}{}{same-non-zero-eigenvalues}\nLet $A$ be an $m \\times n$-matrix. Then $A^TA$ and $AA^T$ have the same \\bf{non-zero} eigenvalues.\n\\end{proposition}\n\n\\begin{proof}\nSuppose $A$ is an $m\\times n$-matrix, and suppose that  $\\lambda$ is a non-zero eigenvalue of $A^TA$.\nThen there exists a non-zero vector $X\\in \\R^n$ such that\n\n\\begin{equation}\\label{non-zero}\n(A^TA)X=\\lambda X.\n\\end{equation}\n\nMultiplying both sides of this equation by $A$ yields:\n\\begin{eqnarray*}\nA(A^TA)X & = & A\\lambda X\\\\\n(AA^T)(AX) & = & \\lambda (AX).\n\\end{eqnarray*}\nSince $\\lambda\\neq 0$ and $X\\neq 0_n$, $\\lambda X\\neq 0_n$,\nand thus by equation~\\eqref{non-zero},\n$(A^TA)X\\neq 0_m$; thus $A^T(AX)\\neq 0_m$,\nimplying that $AX\\neq 0_m$.\n\nTherefore $AX$ is an eigenvector of $AA^T$ corresponding to eigenvalue\n$\\lambda$.  An analogous argument can be used to show that every\nnon-zero eigenvalue of $AA^T$ is an eigenvalue of $A^TA$, thus\ncompleting the proof.\n\\end{proof}\n\nGiven an $m\\times n$-matrix $A$, we will see how to express $A$ as a product\n\\[ A=U\\Sigma V^T\\]\nwhere\n\\begin{itemize}\n\\item $U$ is an $m\\times m$ orthogonal matrix whose columns are\neigenvectors of $AA^T$.\n\\item $V$ is an $n\\times n$ orthogonal matrix whose columns are\neigenvectors of $A^TA$.\n\\item $\\Sigma$ is an $m\\times n$-matrix whose only non-zero values\nlie on its main diagonal, and are the singular values of $A$.\n\\end{itemize}\n\nHow can we find such a decomposition? We are aiming to decompose $A$ in the following form:\n\n\\begin{equation*}\nA=U\\begin{mymatrix}{cc}\n\\sigma & 0 \\\\\n0 & 0\n\\end{mymatrix} V^T\n\\end{equation*}\n\nwhere $\\sigma $ is of the form\n\\[\n\\sigma =\\begin{mymatrix}{ccc}\n\\sigma _{1} &  & 0 \\\\\n& \\ddots &  \\\\\n0 &  & \\sigma _{k}\n\\end{mymatrix}\n\\]\n\nThus $A^T=V\\begin{mymatrix}{cc}\n\\sigma & 0 \\\\\n0 & 0\n\\end{mymatrix} U^T$ and it follows that\n\\begin{equation*}\nA^TA=V\\begin{mymatrix}{cc}\n\\sigma & 0 \\\\\n0 & 0\n\\end{mymatrix} U^TU\\begin{mymatrix}{cc}\n\\sigma & 0 \\\\\n0 & 0\n\\end{mymatrix} V^T=V\\begin{mymatrix}{cc}\n\\sigma ^{2} & 0 \\\\\n0 & 0\n\\end{mymatrix} V^T\n\\end{equation*}\nand so $A^TAV=V\\begin{mymatrix}{cc}\n\\sigma ^{2} & 0 \\\\\n0 & 0\n\\end{mymatrix}$. Similarly, $AA^TU=U\\begin{mymatrix}{cc}\n\\sigma ^{2} & 0 \\\\\n0 & 0\n\\end{mymatrix}$. Therefore, you would find an orthonormal basis of eigenvectors\nfor $AA^T$ make them the columns of a matrix such that the\ncorresponding eigenvalues are decreasing. This gives $U$. You could then do\nthe same for $A^TA$ to get $V$.\n\nWe formalize this discussion in the following theorem.\n\n\\begin{theorem}{Singular value decomposition}{singular-value-decomposition}\nLet $A$ be an $m\\times n$-matrix. Then there exist\northogonal matrices $U$ and $V$ of the appropriate size such that $A= U \\Sigma V^T$ where $\\Sigma$ is of the form\n\\[\n\\Sigma =\n\\begin{mymatrix}{cc}\n\\sigma & 0 \\\\\n0 & 0\n\\end{mymatrix}\n\\]\nand $\\sigma $ is of the form\n\\[\n\\sigma =\\begin{mymatrix}{ccc}\n\\sigma _{1} &  & 0 \\\\\n& \\ddots &  \\\\\n0 &  & \\sigma _{k}\n\\end{mymatrix}\n\\]\nfor the $\\sigma _{i}$ the singular values of $A$.\n\\end{theorem}\n\n\\begin{proof}\nThere exists an orthonormal basis, $\\set{\\vect{v}_{i}} _{i=1}^{n}$ such that $\nA^TA\\vect{v}_{i}=\\sigma _{i}^{2}\\vect{v}_{i}$ where $\\sigma\n_{i}^{2}>0$ for $i=1,\\ldots,k,(\\sigma _{i}>0) $ and equals zero\nif $i>k$. Thus for $i>k$, $A\\vect{v}_{i}=\\vect{0}$ because\n\\begin{equation*}\n A\\vect{v}_{i}\\dotprod A\\vect{v}_{i} = A^TA\\vect{v}_{i} \\dotprod \\vect{v}_{i}  = \\vect{0} \\dotprod \\vect{v}_{i} =0.\n\\end{equation*}\nFor $i=1,\\ldots,k$, define $\\vect{u}_{i}\\in \\R^{m}$ by\n\\begin{equation*}\n\\vect{u}_{i}= \\sigma _{i}^{-1}A\\vect{v}_{i}.\n\\end{equation*}\n\nThus $A\\vect{v}_{i}=\\sigma _{i}\\vect{u}_{i}$. Now\n\\begin{eqnarray*}\n\\vect{u}_{i} \\dotprod \\vect{u}_{j} &=&  \\sigma _{i}^{-1}A\n\\vect{v}_{i} \\dotprod \\sigma _{j}^{-1}A\\vect{v}_{j}  = \\sigma_{i}^{-1}\\vect{v}_{i} \\dotprod \\sigma _{j}^{-1}A^TA\\vect{v}_{j} \\\\\n&=& \\sigma _{i}^{-1}\\vect{v}_{i} \\dotprod \\sigma _{j}^{-1}\\sigma _{j}^{2} \\vect{v}_{j} =\n\\frac{\\sigma _{j}}{\\sigma _{i}}(\\vect{v}_{i} \\dotprod \\vect{v}_{j})\n=\\delta _{ij}.\n\\end{eqnarray*}\nThus $\\set{\\vect{u}_{i}} _{i=1}^{k}$ is an orthonormal set of\nvectors in $\\R^{m}$. Also,\n\\begin{equation*}\nAA^T\\vect{u}_{i}=AA^T\\sigma _{i}^{-1}A\\vect{v}_{i}=\\sigma\n_{i}^{-1}AA^TA\\vect{v}_{i}=\\sigma _{i}^{-1}A\\sigma _{i}^{2}\\vect{v}\n_{i}=\\sigma _{i}^{2}\\vect{u}_{i}.\n\\end{equation*}\nNow extend $\\set{\\vect{u}_{i}} _{i=1}^{k}$ to an orthonormal\nbasis for all of $\\R^{m}$, $\\set{\\vect{u}_{i}} _{i=1}^{m}$\nand let\n\\begin{equation*}\nU= \\begin{mymatrix}{ccc}\n\\vect{u}_{1} & \\cdots & \\vect{u}_{m}\n\\end{mymatrix}\n\\end{equation*}\nwhile $V= \\mat{\\vect{v}_{1},\\ldots,\\vect{v}_{n}}$. Thus $U$\nis the matrix which has the $\\vect{u}_{i}$ as columns and $V$ is defined\nas the matrix which has the $\\vect{v}_{i}$ as columns. Then\n\\begin{equation*}\nU^TAV=\\begin{mymatrix}{c}\n\\vect{u}_{1}^T \\\\\n\\vdots \\\\\n\\vect{u}_{k}^T \\\\\n\\vdots \\\\\n\\vect{u}_{m}^T\n\\end{mymatrix} A\\mat{\\vect{v}_{1},\\ldots,\\vect{v}_{n}}\n\\end{equation*}\n\\begin{equation*}\n=\\begin{mymatrix}{c}\n\\vect{u}_{1}^T \\\\\n\\vdots \\\\\n\\vect{u}_{k}^T \\\\\n\\vdots \\\\\n\\vect{u}_{m}^T\n\\end{mymatrix} \\begin{mymatrix}{cccccc}\n\\sigma _{1}\\vect{u}_{1} & \\cdots & \\sigma _{k}\\vect{u}_{k} & \\vect{0}\n& \\cdots & \\vect{0}\n\\end{mymatrix} =\\begin{mymatrix}{cc}\n\\sigma & 0 \\\\\n0 & 0\n\\end{mymatrix}\n\\end{equation*}\nwhere $\\sigma $ is given in the statement of the theorem.\n\\end{proof}\n\nThe singular value decomposition has as an immediate corollary which is given in the following interesting result.\n\n\\begin{corollary}{Rank and singular values}{rank-singular-values}\nLet $A$ be an $m\\times n$-matrix. Then the rank of $A$ and $A^T$equals\nthe number of singular values.\n\\end{corollary}\n\n%%\\begin{proof}\n%%Since $V$ and $U$ are unitary, it follows that\n%%\\begin{eqnarray*}\n%%\\rank(A) &=&\\rank(U^TAV) =\n%%\\rank\\mat{\n%%\\begin{array}{cc}\n%%\\sigma & 0 \\\\\n%%0 & 0\n%%\\end{array}\n%%} \\\\\n%%&=&\\text{number of singular values.}\n%%\\end{eqnarray*}\n%%Also since $U,V$ are unitary,\n%%\\begin{equation*}\n%%\\rank(A^T) =\\rank(V^TA^{\\ast\n%%}U) =\\rank((U^TAV)^T)\n%%\\end{equation*}\n%%\\begin{equation*}\n%%=\\rank\\paren{\\mat{\n%%\\begin{array}{cc}\n%%\\sigma & 0 \\\\\n%%0 & 0\n%%\\end{array}\n%%} ^T} =\\text{number of singular values.}\n%%\\end{equation*}\n%%\\end{proof}\n%%\n%%\\medskip\n\nLet's compute the Singular Value Decomposition of a simple matrix.\n\n\\begin{example}{Singular value decomposition}{SVD}\nLet\n$A=\\begin{mymatrix}{rrr} 1 & -1 & 3 \\\\ 3 & 1 & 1 \\end{mymatrix}$.\nFind the Singular Value Decomposition (SVD) of $A$.\n\\end{example}\n\n\\begin{solution}\nTo begin, we compute $AA^T$ and $A^TA$.\n\\[ AA^T = \\begin{mymatrix}{rrr} 1 & -1 & 3 \\\\ 3 & 1 & 1 \\end{mymatrix}\n\\begin{mymatrix}{rr} 1 & 3 \\\\ -1 & 1 \\\\ 3 & 1  \\end{mymatrix}\n= \\begin{mymatrix}{rr} 11 & 5 \\\\ 5 & 11  \\end{mymatrix}.\\]\n\n\\[ A^TA = \\begin{mymatrix}{rr} 1 & 3 \\\\ -1 & 1 \\\\ 3 & 1  \\end{mymatrix}\n\\begin{mymatrix}{rrr} 1 & -1 & 3 \\\\ 3 & 1 & 1 \\end{mymatrix}\n= \\begin{mymatrix}{rrr} 10 & 2 & 6 \\\\ 2 & 2 & -2\\\\\n6 & -2 & 10 \\end{mymatrix}.\\]\n\nSince $AA^T$ is $2\\times 2$ while $A^T A$ is $3\\times 3$, and $AA^T$\nand $A^TA$ have the same {\\em non-zero} eigenvalues (by Proposition~\\ref{prop:same-non-zero-eigenvalues}), we compute the characteristic polynomial  $c_{AA^T}(x)$ (because it's\neasier to compute than $c_{A^TA}(x)$).\n\n\\begin{eqnarray*}\nc_{AA^T}(x)& = &\\det(xI-AA^T)= \\begin{absmatrix}{cc}\nx-11 & -5 \\\\ -5 & x-11 \\end{absmatrix}\\\\\n& = &(x-11)^2 - 25 \\\\\n& = & x^2-22x+121-25\\\\\n& = & x^2-22x+96\\\\\n& = & (x-16)(x-6)\n\\end{eqnarray*}\n\nTherefore, the eigenvalues of $AA^T$ are $\\lambda_1=16$ and $\\lambda_2=6$.\n\nThe eigenvalues of $A^TA$ are $\\lambda_1=16$, $\\lambda_2=6$, and\n$\\lambda_3=0$, and the singular values of $A$ are $\\sigma_1=\\sqrt{16}=4$ and\n$\\sigma_2=\\sqrt{6}$.\nBy convention, we list the eigenvalues (and corresponding singular values)\nin non-increasing order (i.e., from largest to smallest).\n\n{\\bf To find the matrix $V$}:\n\nTo construct the matrix $V$ we need to find eigenvectors for $A^TA$.\nSince the eigenvalues of $AA^T$ are distinct, the corresponding\neigenvectors are orthogonal, and we need only normalize them.\n\n$\\lambda_1=16$: solve $(16I-A^TA)Y= 0$.\n\n\\[ \\begin{mymatrix}{rrr|r}\n6 & -2 & -6 & 0 \\\\ -2 & 14 & 2 & 0 \\\\ -6 & 2 & 6 & 0\n\\end{mymatrix}\n\\rightarrow\n\\begin{mymatrix}{rrr|r}\n1 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 0\n\\end{mymatrix},\n\\mbox{ so }\nY=\\begin{mymatrix}{r} t \\\\ 0 \\\\ t \\end{mymatrix}\n=t\\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 1 \\end{mymatrix},\nt\\in \\R. \\]\n\n$\\lambda_2=6$: solve $(6I-A^TA)Y= 0$.\n\n\\[ \\begin{mymatrix}{rrr|r}\n-4 & -2 & -6 & 0 \\\\ -2 & 4 & 2 & 0 \\\\ -6 & 2 & -4 & 0\n\\end{mymatrix}\n\\rightarrow\n\\begin{mymatrix}{rrr|r}\n1 & 0 & 1 & 0 \\\\ 0 & 1 & 1 & 0 \\\\ 0 & 0 & 0 & 0\n\\end{mymatrix},\n\\mbox{ so }\nY=\\begin{mymatrix}{r} -s \\\\ -s \\\\ s \\end{mymatrix}\n=s\\begin{mymatrix}{r} -1 \\\\ -1 \\\\ 1 \\end{mymatrix},\ns\\in \\R. \\]\n\n$\\lambda_3=0$: solve $(-A^TA)Y= 0$.\n\\[ \\begin{mymatrix}{rrr|r}\n-10 & -2 & -6 & 0 \\\\ -2 & -2 & 2 & 0 \\\\ -6 & 2 & -10 & 0\n\\end{mymatrix}\n\\rightarrow\n\\begin{mymatrix}{rrr|r}\n1 & 0 & 1 & 0 \\\\ 0 & 1 & -2 & 0 \\\\ 0 & 0 & 0 & 0\n\\end{mymatrix},\n\\mbox{ so }\nY=\\begin{mymatrix}{r} -r \\\\ 2r \\\\ r \\end{mymatrix}\n=r\\begin{mymatrix}{r} -1 \\\\ 2 \\\\ 1 \\end{mymatrix},\nr\\in \\R. \\]\n\nLet\n\\[ V_1=\\frac{1}{\\sqrt{2}}\\begin{mymatrix}{r} 1\\\\ 0\\\\ 1 \\end{mymatrix},\nV_2=\\frac{1}{\\sqrt{3}}\\begin{mymatrix}{r} -1\\\\ -1\\\\ 1 \\end{mymatrix},\nV_3=\\frac{1}{\\sqrt{6}}\\begin{mymatrix}{r} -1\\\\ 2\\\\ 1 \\end{mymatrix}.\\]\n\nThen\n\\[ V=\\frac{1}{\\sqrt{6}}\\begin{mymatrix}{rrr}\n\\sqrt 3 & -\\sqrt 2 & -1  \\\\\n0 & -\\sqrt 2 & 2 \\\\\n\\sqrt 3 & \\sqrt 2 & 1 \\end{mymatrix}.\\]\n\nAlso,\n\\[ \\Sigma = \\begin{mymatrix}{rrr} 4 & 0 & 0 \\\\\n0 & \\sqrt 6 & 0 \\end{mymatrix},\\]\nand we use $A$, $V^T$, and $\\Sigma$ to find $U$.\n\nSince $V$ is orthogonal and $A=U\\Sigma V^T$, it follows that $AV=U\\Sigma$.\nLet $V=\\begin{mymatrix}{ccc} V_1 & V_2 & V_3 \\end{mymatrix}$, and\nlet $U=\\begin{mymatrix}{cc} U_1 & U_2 \\end{mymatrix}$, where\n$U_1$ and $U_2$ are the two columns of $U$.\n\nThen we have\n\\begin{eqnarray*}\nA\\begin{mymatrix}{ccc} V_1 & V_2 & V_3 \\end{mymatrix}\n&=& \\begin{mymatrix}{cc} U_1 & U_2 \\end{mymatrix}\\Sigma\\\\\n\\begin{mymatrix}{ccc} AV_1 & AV_2 & AV_3 \\end{mymatrix}\n&=& \\begin{mymatrix}{ccc} \\sigma_1U_1 + 0U_2 &\n0U_1 + \\sigma_2 U_2 & 0 U_1 + 0 U_2 \\end{mymatrix} \\\\\n&=& \\begin{mymatrix}{ccc} \\sigma_1U_1 & \\sigma_2 U_2 &\n0 \\end{mymatrix}\n\\end{eqnarray*}\nwhich implies that $AV_1=\\sigma_1U_1 = 4U_1$ and\n$AV_2=\\sigma_2U_2 = \\sqrt 6 U_2$.\n\nThus,\n\\[ U_1 = \\frac{1}{4}AV_1\n= \\frac{1}{4}\n\\begin{mymatrix}{rrr} 1 & -1 & 3 \\\\ 3 & 1 & 1 \\end{mymatrix}\n\\frac{1}{\\sqrt{2}}\\begin{mymatrix}{r} 1\\\\ 0\\\\ 1 \\end{mymatrix}\n= \\frac{1}{4\\sqrt 2}\\begin{mymatrix}{r} 4\\\\ 4 \\end{mymatrix}\n= \\frac{1}{\\sqrt 2}\\begin{mymatrix}{r} 1\\\\ 1 \\end{mymatrix},\\]\nand\n\\[ U_2 = \\frac{1}{\\sqrt 6}AV_2\n= \\frac{1}{\\sqrt 6}\n\\begin{mymatrix}{rrr} 1 & -1 & 3 \\\\ 3 & 1 & 1 \\end{mymatrix}\n\\frac{1}{\\sqrt{3}}\\begin{mymatrix}{r} -1\\\\ -1\\\\ 1 \\end{mymatrix}\n=\\frac{1}{3\\sqrt 2}\\begin{mymatrix}{r} 3\\\\ -3 \\end{mymatrix}\n=\\frac{1}{\\sqrt 2}\\begin{mymatrix}{r} 1\\\\ -1 \\end{mymatrix}.\n\\]\nTherefore,\n\\[ U=\\frac{1}{\\sqrt{2}}\\begin{mymatrix}{rr} 1 & 1 \\\\\n1 & -1 \\end{mymatrix},\\]\nand\n\\begin{eqnarray*}\nA & = & \\begin{mymatrix}{rrr} 1 & -1 & 3 \\\\ 3 & 1 & 1 \\end{mymatrix}\\\\\n& = & \\paren{\\frac{1}{\\sqrt{2}}\\begin{mymatrix}{rr} 1 & 1 \\\\\n1 & -1 \\end{mymatrix}}\n\\begin{mymatrix}{rrr} 4 & 0 & 0 \\\\\n0 & \\sqrt 6 & 0 \\end{mymatrix}\n\\paren{\\frac{1}{\\sqrt{6}}\\begin{mymatrix}{rrr}\n\\sqrt 3 & 0 & \\sqrt 3  \\\\\n-\\sqrt 2 & -\\sqrt 2 & \\sqrt2 \\\\\n-1 & 2 & 1 \\end{mymatrix}}.\n\\end{eqnarray*}\n\\end{solution}\n\nHere is another example.\n\n\\begin{example}{Finding the SVD}{SVD2}\nFind an SVD for\n$A=\\begin{mymatrix}{r} -1 \\\\ 2\\\\ 2 \\end{mymatrix}$.\n\\end{example}\n\n\\begin{solution}\nSince $A$ is $3\\times 1$, $A^T A$ is a $1\\times 1$-matrix\nwhose eigenvalues are easier to find than the eigenvalues of\nthe $3\\times 3$-matrix $AA^T$.\n\n\\[ A^TA=\\begin{mymatrix}{ccc} -1 & 2 & 2 \\end{mymatrix}\n\\begin{mymatrix}{r} -1 \\\\ 2 \\\\ 2 \\end{mymatrix}\n=\\begin{mymatrix}{r} 9 \\end{mymatrix}.\\]\n\nThus $A^TA$ has eigenvalue $\\lambda_1=9$, and\nthe eigenvalues of $AA^T$ are $\\lambda_1=9$, $\\lambda_2=0$, and\n$\\lambda_3=0$.\nFurthermore, $A$ has only one singular value, $\\sigma_1=3$.\n\n{\\bf To find the matrix $V$}:\nTo do so we find an eigenvector for $A^TA$ and\nnormalize it.\nIn this case, finding a unit eigenvector is trivial:\n$V_1=\\begin{mymatrix}{r} 1 \\end{mymatrix}$, and\n\\[ V=\\begin{mymatrix}{r} 1 \\end{mymatrix}.\\]\n\nAlso,\n$\\Sigma =\\begin{mymatrix}{r} 3 \\\\ 0\\\\ 0 \\end{mymatrix}$,\nand we use $A$, $V^T$, and $\\Sigma$ to find $U$.\n\nNow $AV=U\\Sigma$, with\n$V=\\begin{mymatrix}{r} V_1 \\end{mymatrix}$,\nand $U=\\begin{mymatrix}{rrr} U_1 & U_2 & U_3 \\end{mymatrix}$,\nwhere $U_1$, $U_2$, and $U_3$ are the columns of $U$.\nThus\n\\begin{eqnarray*}\nA\\begin{mymatrix}{r} V_1 \\end{mymatrix}\n&=& \\begin{mymatrix}{rrr} U_1 & U_2 & U_3 \\end{mymatrix}\\Sigma\\\\\n\\begin{mymatrix}{r} AV_1 \\end{mymatrix}\n&=& \\begin{mymatrix}{r} \\sigma_1 U_1+0U_2+0U_3 \\end{mymatrix}\\\\\n&=& \\begin{mymatrix}{r} \\sigma_1 U_1 \\end{mymatrix}\n\\end{eqnarray*}\nThis gives us $AV_1=\\sigma_1 U_1= 3U_1$, so\n\n\\[ U_1 = \\frac{1}{3}AV_1\n= \\frac{1}{3}\n\\begin{mymatrix}{r} -1 \\\\ 2 \\\\ 2 \\end{mymatrix}\n\\begin{mymatrix}{r} 1 \\end{mymatrix}\n= \\frac{1}{3}\n\\begin{mymatrix}{r} -1 \\\\ 2 \\\\ 2 \\end{mymatrix}.\\]\n\nThe vectors $U_2$ and $U_3$ are eigenvectors of $AA^T$ corresponding\nto the eigenvalue $\\lambda_2=\\lambda_3=0$.\nInstead of solving the system $(0I-AA^T)X= 0$ and then using the\nGram-Schmidt process on the resulting set of\ntwo basic eigenvectors, the following approach may be used.\n\nFind vectors $U_2$ and $U_3$ by first extending $\\set{U_1}$ to a basis of\n$\\R^3$, then using the Gram-Schmidt algorithm to orthogonalize the basis,\nand finally normalizing the vectors.\n\nStarting with $\\set{3U_1}$ instead of $\\set{U_1}$ makes the\narithmetic a bit easier.\nIt is easy to verify that\n\n\\[ \\set{\\begin{mymatrix}{r} -1 \\\\ 2 \\\\ 2 \\end{mymatrix},\n\\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 0 \\end{mymatrix},\n\\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix}}\\]\nis a basis of $\\R^3$.  Set\n\n\\[ E_1 = \\begin{mymatrix}{r} -1 \\\\ 2 \\\\ 2 \\end{mymatrix},\nX_2 = \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 0 \\end{mymatrix},\nX_3 =\\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix},\\]\n\nand apply the Gram-Schmidt algorithm to\n$\\set{E_1, X_2, X_3}$.\n\nThis gives us\n\n\\[ E_2 = \\begin{mymatrix}{r} 4 \\\\ 1 \\\\ 1 \\end{mymatrix}\n\\mbox{ and }\nE_3 = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ -1 \\end{mymatrix}.\\]\n\nTherefore,\n\\[ U_2 = \\frac{1}{\\sqrt{18}}\n \\begin{mymatrix}{r} 4 \\\\ 1 \\\\ 1 \\end{mymatrix},\nU_3 = \\frac{1}{\\sqrt 2}\n\\begin{mymatrix}{r} 0 \\\\ 1 \\\\ -1 \\end{mymatrix},\\]\nand\n\n\\[ U = \\begin{mymatrix}{rrr} -\\frac{1}{3} & \\frac{4}{\\sqrt{18}} & 0 \\\\\n\\frac{2}{3} & \\frac{1}{\\sqrt{18}} & \\frac{1}{\\sqrt 2} \\\\\n\\frac{2}{3} & \\frac{1}{\\sqrt{18}} & -\\frac{1}{\\sqrt 2} \\end{mymatrix}.\\]\n\nFinally,\n\n\\[ A =\n\\begin{mymatrix}{r} -1 \\\\ 2 \\\\ 2 \\end{mymatrix}\n=\n\\begin{mymatrix}{rrr} -\\frac{1}{3} & \\frac{4}{\\sqrt{18}} & 0 \\\\\n\\frac{2}{3} & \\frac{1}{\\sqrt{18}} & \\frac{1}{\\sqrt 2} \\\\\n\\frac{2}{3} & \\frac{1}{\\sqrt{18}} & -\\frac{1}{\\sqrt 2} \\end{mymatrix}\n\\begin{mymatrix}{r} 3 \\\\ 0 \\\\ 0 \\end{mymatrix}\n\\begin{mymatrix}{r} 1 \\end{mymatrix}.\\]\n\n\\end{solution}\n\nConsider another example.\n\n\\begin{example}{Find the SVD}{SVD3}\nFind a singular value decomposition for the matrix\n\\begin{equation*}\nA= \\begin{mymatrix}{ccc}\n\\frac{2}{5}\\sqrt{2}\\sqrt{5} & \\frac{4}{5}\\sqrt{2}\\sqrt{5} & 0 \\\\\n\\frac{2}{5}\\sqrt{2}\\sqrt{5} & \\frac{4}{5}\\sqrt{2}\\sqrt{5} & 0\n\\end{mymatrix}\n\\end{equation*}\n\\end{example}\n\nFirst consider $A^TA$\n\\begin{equation*}\n\\begin{mymatrix}{ccc}\n\\frac{16}{5} & \\frac{32}{5} & 0 \\\\\n\\frac{32}{5} & \\frac{64}{5} & 0 \\\\\n0 & 0 & 0\n\\end{mymatrix}\n\\end{equation*}\nWhat are some eigenvalues and eigenvectors? Some computing shows these are\n\n\\begin{equation*}\n\\set{\\begin{mymatrix}{c}\n0 \\\\\n0 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n-\\frac{2}{5}\\sqrt{5} \\\\\n\\frac{1}{5}\\sqrt{5} \\\\\n0\n\\end{mymatrix} } \\leftrightarrow 0,\\set{\\begin{mymatrix}{c}\n\\frac{1}{5}\\sqrt{5} \\\\\n\\frac{2}{5}\\sqrt{5} \\\\\n0\n\\end{mymatrix} } \\leftrightarrow 16\n\\end{equation*}\nThus the matrix $V$ is given by\n\\begin{equation*}\nV=\\begin{mymatrix}{ccc}\n\\frac{1}{5}\\sqrt{5} & -\\frac{2}{5}\\sqrt{5} & 0 \\\\\n\\frac{2}{5}\\sqrt{5} & \\frac{1}{5}\\sqrt{5} & 0 \\\\\n0 & 0 & 1\n\\end{mymatrix}\n\\end{equation*}\nNext consider $AA^T$\n\\begin{equation*}\n\\begin{mymatrix}{cc}\n8 & 8 \\\\\n8 & 8\n\\end{mymatrix}\n\\end{equation*}\nEigenvectors and eigenvalues are\n\n\\begin{equation*}\n\\set{\\begin{mymatrix}{c}\n-\\frac{1}{2}\\sqrt{2} \\\\\n\\frac{1}{2}\\sqrt{2}\n\\end{mymatrix} } \\leftrightarrow 0,\\set{\\begin{mymatrix}{c}\n\\frac{1}{2}\\sqrt{2} \\\\\n\\frac{1}{2}\\sqrt{2}\n\\end{mymatrix} } \\leftrightarrow 16\n\\end{equation*}\nThus you can let $U$ be given by\n\\begin{equation*}\nU=\\begin{mymatrix}{cc}\n\\frac{1}{2}\\sqrt{2} & -\\frac{1}{2}\\sqrt{2} \\\\\n\\frac{1}{2}\\sqrt{2} & \\frac{1}{2}\\sqrt{2}\n\\end{mymatrix}\n\\end{equation*}\nLet us check this. $U^TAV=$\n\\begin{equation*}\n\\begin{mymatrix}{cc}\n\\frac{1}{2}\\sqrt{2} & \\frac{1}{2}\\sqrt{2} \\\\\n-\\frac{1}{2}\\sqrt{2} & \\frac{1}{2}\\sqrt{2}\n\\end{mymatrix} \\begin{mymatrix}{ccc}\n\\frac{2}{5}\\sqrt{2}\\sqrt{5} & \\frac{4}{5}\\sqrt{2}\\sqrt{5} & 0 \\\\\n\\frac{2}{5}\\sqrt{2}\\sqrt{5} & \\frac{4}{5}\\sqrt{2}\\sqrt{5} & 0\n\\end{mymatrix} \\begin{mymatrix}{ccc}\n\\frac{1}{5}\\sqrt{5} & -\\frac{2}{5}\\sqrt{5} & 0 \\\\\n\\frac{2}{5}\\sqrt{5} & \\frac{1}{5}\\sqrt{5} & 0 \\\\\n0 & 0 & 1\n\\end{mymatrix}\n\\end{equation*}\n\\begin{equation*}\n=\\begin{mymatrix}{ccc}\n4 & 0 & 0 \\\\\n0 & 0 & 0\n\\end{mymatrix}\n\\end{equation*}\n\nThis illustrates that if you have a good way to find the eigenvectors and\neigenvalues for a Hermitian matrix which has non-negative eigenvalues, then\nyou also have a good way to find the singular value decomposition of an\narbitrary matrix.\n", "meta": {"hexsha": "995518aaab0ae2fcf1f3c8e25ee098a4f3fb8a36", "size": 18088, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryOrthogonalitySingularValue.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/spectraltheoryOrthogonalitySingularValue.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/spectraltheoryOrthogonalitySingularValue.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 31.025728988, "max_line_length": 176, "alphanum_fraction": 0.628869969, "num_tokens": 7808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8652240860523328, "lm_q1q2_score": 0.7012458730189719}}
{"text": "\\section{}\nThe network presented in \\ref{sec:sgd} uses a sigmoid function as the activation function\nof neurons. Using the same structure and initial weights given in \\ref{sec:weights} we replace\nthe sigmoid function with a bipolar sigmoid function given in equation \\ref{eq:bipolar_sigmoid}\n\n\\begin{equation}\n\\label{eq:bipolar_sigmoid}\n f(x)= \\frac{2}{1 + e^{-x}} - 1\n\\end{equation}\n\n\\begin{equation}\n\\label{eq:bipolar_sigmoid_derivative}\n f'(x)= \\frac{1}{2} (1 - f(x)^2)\n\\end{equation}\n\nThe input and output to the network are too converted into their bipolar representation. The\nplot of training cost vs iterations is shown in figure \\ref{fig:cost_bipolar}. Comparing \nfigures \\ref{fig:cost_sgd} and \\ref{fig:cost_bipolar} we can see that the network using bipolar\nsigmoid with bipolar XOR representation converged in fewer number of iterations then original\nnetwork.\n\n\\section{}\nIn order to evaluate the impact of Nguyen-Widrow approach of weight initialization on convergence\na neural network similar to the one described in \\ref{sec:sgd} was constructed. Then the\nsigmoid function was replaced with hyperbolic tangent function and bipolar representation of XOR\ngate was used as the training data. The training cost with respect to the iterations is given in figure\n\\ref{fig:cost_tanh}. \\newline\n\nAbove experiment was repeated after initializing the weights and biases as per the Nguyen-Widrow\napproach. The plot of the training cost with respect iterations is shown in figure \\ref{fig:cost_tanh_nw}.\nComparing figure \\ref{fig:cost_tanh_nw} with figure \\ref{fig:cost_tanh} it can seen that using Nguyen-Widrow approach\nto initialize the weights smoothens the decrease in cost per iteration. Figure \\ref{fig:tanh_nw_first_2500_compare} shows\nthe training cost for the first 2500 iteration of both cases.\n\n\\section{}\nInitially a neural network with 3 units in first hidden layer and 2 units in second hidden layer was constructed.\nThe weights of the network is randomly initialized in the range $[-0.5, 0.5]$. As for the activation function,\nhyperbolic tangent function was used and SGD with momentum coefficient($\\mu$)$=0.5$ was used to optimize the parameters.\nThe plot for training cost with respect to iteration is given in figure \\ref{fig:cost_two_hidden_layer}\n", "meta": {"hexsha": "05bba8d95c17ddb027458a7824eb913b62aa828b", "size": 2270, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_4/hyperbolictan.tex", "max_stars_repo_name": "diwasblack/machine_learning", "max_stars_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_4/hyperbolictan.tex", "max_issues_repo_name": "diwasblack/machine_learning", "max_issues_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_4/hyperbolictan.tex", "max_forks_repo_name": "diwasblack/machine_learning", "max_forks_repo_head_hexsha": "83bf5af98a3db5e13f628f39d7519575c580497d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.75, "max_line_length": 121, "alphanum_fraction": 0.7955947137, "num_tokens": 560, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.7012458716106474}}
{"text": "\\chapter{Short-rate models}\n\\label{chap:shortrate}\n\n\\added{This chapter introduces basics of short-rate modeling and short-rate models iwth affine term-structures.}\n\n\\section{Introduction to short-rate models}\n\n\\subsection{Term-structure equation}\n\n\\added{The derivation of the term-structure equation follows closely} \\textcite[pp. 319--324]{bjork2004arbitrage}.\n\nIn this chapter we assume that the short rate process follows\n\\begin{align}\n\\label{short-ratedynamicsundersomemeasure}\n\\dx r(t) = \\mu(t,r(t)) \\dx t + \\sigma(t,r(t)) \\dx W(t) ,\n\\end{align}\nwhere $W(t)$ is a Brownian motion under some measure $\\Pm^*$ (this may be also physical measure) and $\\mu$ and $\\sigma$ are well-behaved functions. If $V(t,r(t))$ is a smooth function, then It\\'{o}s lemma says that\n\\begin{align}\n\\dx V = \\left( \\frac{\\partial V}{\\partial t} + \\mu \\frac{\\partial V}{\\partial x} +\\frac{1}{2} \\sigma^2 \\frac{\\partial^2 V}{\\partial x^2} \\right) \\dx t + \\sigma \\frac{\\partial V}{\\partial x} \\dx W\n\\end{align}\nHere we have dropped arguments for functions. Unlike in Black-Scholes model, we may not trade short rate $r(t)$ directly and it may not be used in hedging. But we may consider how to hedge a derivative using another contingent claim.\n\nWe consider two contingent claims with value processes $V_1(t, r(t))$ and $V_2(t,r(t))$. It\\'{o}'s lemma gives us that\n\\begin{align}\n\\dx V_i = M_i \\dx t + N_i \\dx W,\n\\end{align}\nwhere\n\\begin{align}\nM_i &= \\frac{\\partial V_i}{\\partial t} + \\mu \\frac{\\partial V_i}{\\partial r} + \\frac{1}{2} \\sigma^2 \\frac{\\partial^2 V_i}{\\partial r^2}, \\\\\nN_i &= \\sigma \\frac{\\partial V_i}{\\partial r} .\n\\end{align}\nIf $\\Pi = V_1 + \\delta V_2$ is a portfolio, then\n\\begin{align}\n\\dx \\Pi = \\left( M_1 + \\delta M_2 \\right) \\dx t + \\left( N_1 + \\delta N_2 \\right) \\dx W .\n\\end{align}\nBy choosing $\\delta = - \\frac{N_1}{N_2}$, the Brownian motion disappears. In order to maintain absence of arbitrage, we have that \n\\begin{align}\n\\dx \\Pi &= r \\Pi \\dx t \\\\\n\\left( M_1 - \\frac{N_1}{N_2} M_2 \\right) \\dx t &= r \\left( V_1 - \\frac{N_1}{N_2} V_2 \\right) \\dx t .\n\\end{align}\nThus\n\\begin{align}\n\\frac{M_1 - r V_1}{N_1 } = \\frac{M_2 - r V_2}{N_2}\n\\end{align}\nNow $M_i, N_i$ and $V_i$ are functions of $t$ and $r(t)$. The left-hand side is independent of the portfolio $V_2$ and the right-hand size is independent of portfolio $V_1$. Hence there exist a function\n\\begin{align}\n\\lambda(t,r(t)) = \\frac{M(t,r(t)) - r(t) V(t,r(t))}{N(t,r(t))}\n\\end{align}\ncalled the market-price of risk, where $V$ is any interest-rate derivative with dynamics\n\\begin{align}\n\\dx V = M \\dx t + N \\dx W .\n\\end{align}\nBy combining this with earlier results, we get that the price process $V$ must satisfy partial differential equation\n\\begin{align}\n\\label{termstructureequation}\n0 &= M - rV - \\lambda N \\\\\n&= \\frac{\\partial V}{\\partial t} + \\mu \\frac{\\partial V}{\\partial r} + \\frac{1}{2} \\sigma^2 \\frac{\\partial^2 V}{\\partial r^2} - rV - \\lambda \\sigma \\frac{\\partial V}{\\partial r} \\\\\n&= \\frac{\\partial V}{\\partial t} + \\left( \\mu - \\lambda \\sigma \\right) \\frac{\\partial V}{\\partial r} + \\frac{1}{2} \\sigma^2 \\frac{\\partial^2 V}{\\partial r^2} - rV\n\\end{align}\nwith the boundary condition given by the value $V(T, r(T))$.\n\n\\subsection{Fundamental models}\n\nSuppose that $\\Pm^* = \\Pf$ is the physical measure. Models that are defined under the physical measure, are often called as fundamental models. If we denote\n\t\\begin{align}\n\t\t\\theta(t,r(t)) = \\mu(t,r(t)) - \\lambda(t,r(t)) \\sigma(t,r(t))\n\t\\end{align}\nand assume that\n\t\\begin{align}\n\t\t\\lambda(t,r(t)) = \\frac{\\theta(t,r(t)) - \\mu(t,r(t))}{\\sigma(t,r(t))}\n\t\\end{align}\nmay be used as a Girsanov kernel, then we get a new measure $\\Pm_{\\theta}$ under which\n\t\\begin{align}\n\t\tr(t) = \\theta(t,r(t)) \\dx t + \\sigma(t,r(t)) \\dx W_{\\theta} (t)\n\t\\end{align}\nand $W_{\\theta} (t)$ is a Brownian motion. Now Feynman-Kac theorem implies that\n\t\\begin{align}\n\t\tV(t) = \\E_{\\Pm_{\\theta}} \\left( \\e^{-\\int_t^T r(s) \\dx s} V(T) \\ | \\ \\F_t \\right) .\n\t\\end{align}\nUnlike in the Black-Scholes model, the market price of risk $\\lambda$ is not uniquely determined endogenously within the model. Here, the market price of risk is endogenously determined. The equivalent martingale measure (if it exists), it is not unique and prices depend on the choice of the function $\\lambda$. However, the $\\lambda$ is uniquely determined by the price of any interest rate derivative. Since the dynamic of Equation \\ref{short-ratedynamicsundersomemeasure} are under the physical measure, we could use econometric time-series to estimate model parameters and market price of risk. This approach is problematic since neither the short-rate nor the market price of risk are not directly observable. According to \\cite{chapmanlongpearson1999usingproxies}, using proxies to estimate parameters of short-rate models for single-factor affine models does not cause economically significant problems, but for more complex models, proxies cause significant errors. Also, for estimation, we usually have to assume a functional form for the market price of risk, which may be misspecified. Fundamental models have no guarantee that they will fit the observed term or volatility structures. If these obstacles are overcome, then the model may be used to price any instrument and forecast interest rates.\n\n\\subsection{Preference-free models}\n\nAnother approach is to assume that the Equation \\ref{short-ratedynamicsundersomemeasure} holds under the risk-free measure $\\Pm_0$. This means choosing $\\lambda = 0$ in the Equation \\ref{termstructureequation}, which will now read\n\\begin{align}\n\\label{termstructureequation2}\n0 &= \\frac{\\partial V}{\\partial t} + \\mu \\frac{\\partial V}{\\partial r} + \\frac{1}{2} \\sigma^2 \\frac{\\partial^2 V}{\\partial r^2} - rV .\n\\end{align}\nTherefore Feynman-Kac theorem implies that\n\t\\begin{align}\n\t\tV(t) = \\E_{\\Pm_0} \\left( \\e^{-\\int_t^T r(s) \\dx s} V(T) \\ | \\ \\F_t \\right) .\n\t\\end{align}\nfor all assets. Thus all discounted asset price process, where the num\\'{e}raire is the bank account, are martingales under $\\Pm_0$.\n\nUnder this methodology, we may use calibrate the model parameters using observed market prices. We may take liquid instruments and then use their prices to calibrate the model. We may not use historical data in calibration, since the assumed process is under the risk-free measure. The physical measure will be different from the risk-free measure, unless we explicitly make the strong assumption that the market price of risk will be zero. However, as the volatility term does not change under measure changes, diffusion term may be estimated with data that is collected under the risk-free measure. Models under this methodology may or may not be guaranteed to fit the observed term and volatility structures. They could be useful for pricing. They may not be used to forecast prices or interest rates without further assumptions.\n\n\\subsubsection{Preference-free +-models}\n\nPreference-free models which have constant parameters $k, \\theta, \\sigma$ are notated with single plus sign. They do not probably fit the observed term and volatility structures. Most of the early fundamental models can be also interpreted as preference-free $+$-models.\n\n\\subsubsection{Preference-free ++-models}\n\nPreference-free models which have constant parameters $k, \\sigma$ but time-varying $\\theta(t)$ are notated with double plus sign. They can be made to fit  the observed term structure but they probably do not match the volatility surface. \\textcite{hull1990pricing} is often the prototypical example of a $++$-model.\n\nWhen matched to term-structure and calibrated with cap or swaption prices, they can be useful in pricing of exotic interest-rate options.\n\n\\subsubsection{Preference-free +++-models}\n\nPreference-free models which have time-varying $\\theta(t), \\sigma(t)$ (and sometimes $k$) are notated with triple plus sign. They can be made to fit both the observed term structure and some of the volatility surface. Variants of Hull-White models are sometimes $+++$-models. \n\nTriple plus models can be useful in pricing but they could be prone to over-fitting.\n\n\\section{One-factor short-rate models}\n\nOne-factor short-rate model is model that has one underlying state variable that drives the evolution of the interest rates. This factor is often the short-rate itself. Often used form for one-factor short-rate process is\n\\begin{align}\n\\dx r (t) = k( \\theta (t) - r (t) ) \\dx t + \\sigma (t) r (t)^{\\gamma} \\dx W (t) \n\\end{align}\nThe following table gives a quick overview of some of the models of this form.\n\\begin{center}\n\t\\begin{tabular}{|l|l|l|l|l|}\n\t\t\\hline\n\t\tModel & $k(t)$ & $\\theta (t)$ & $\\sigma (t)$ & $\\gamma$ \\\\\n\t\t\\hline\n\t\t\\hline\n\t\t\\cite{vasicek1977equilibrium} & $k$ & $\\theta$ & $\\sigma$ & $-$ \\\\\n\t\t\\hline\n\t\t\\cite{dothan1978term} & $-k(t)$ & $-$ & $\\sigma$ & $-$ \\\\\n\t\t\\hline\n\t\t\\cite{coxingersollross1985theory} & $k$ & $\\theta$ & $\\sigma$ & $\\frac{1}{2}$ \\\\\n\t\t\\hline\n\t\t\\cite{hull1990pricing} & $k$ & $\\theta (t)$ & $\\sigma (t)$ & $-$ \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{center}\n\n\\subsection{Affine one-factor term-structures models}\n\n\\added{The derivation of the following theorem is based on } \\textcite[pp. 329--331]{bjork2004arbitrage}.\n\nA one-factor short-rate model has affine term-structure if the zero-coupon bond price is\n\\begin{align}\n\\label{affinitytermstructureequation}\n\\Bond(t,T) = \\e^{A(t,T) - B(t,T)r(t)}\n\\end{align}\nfor all $0 \\leq t \\leq T$, where $A(t,T)$ and $B(t,T)$ deterministic and smooth functions. Since $\\Bond(T,T) = 1$, we have that\n\\begin{align}\nA(T,T) = B(T,T) = 0.\n\\end{align}\nUnder the assumption of affinity the instantaneous forward rate is\n\\begin{align}\nf(t,T) &= - \\frac{\\partial \\log \\Bond(t,T)}{\\partial T} \\\\\n&= \\frac{\\partial (B(t,T)r(t) - A(t,T))}{\\partial T} \\\\\n&= \\frac{\\partial B(t,T)}{\\partial T}r(t) - \\frac{\\partial A(t,T)}{\\partial T}\n\\end{align}\nfor all $0 \\leq t \\leq T$.\n\nIf we denote that $p(t,T) = F(t,T,r)$ to make clear that $\\Bond(t,T)$ is also a function of $r$, then we have that\n\\begin{align}\n\\frac{\\partial F}{\\partial t} &= \\left( \\frac{\\partial A}{\\partial t} - \\frac{\\partial B}{\\partial t} r \\right) F \\\\\n\\frac{\\partial F}{\\partial r} &= - B F \\\\\n\\frac{\\partial^2 F}{\\partial r^2} &= B^2 F\n\\end{align}\nas the derivative of $r$ with respect to $t$ vanishes. Since the price of a zero-coupon price must satisfy \\ref{fundamentaltermstructure_equationinaffine}, we have that\n\\begin{align}\n\\frac{\\partial F}{\\partial t} + \\mu^* \\frac{\\partial F}{\\partial r} + \\frac{1}{2} \\sigma^2 \\frac{\\partial^2 F}{\\partial r^2} - r F &= 0 \\\\\nF(T,T,r) = 1.\n\\end{align}\nBy combining these, we have that\n\\begin{align}\n0 &= \\left( \\frac{\\partial A}{\\partial t} - \\frac{\\partial B}{\\partial t} r \\right) F - \\mu^* B F + \\frac{1}{2} \\sigma^2 B^2 F - r F, \\\\\n0 &= \\frac{\\partial A}{\\partial t} - \\frac{\\partial B}{\\partial t} r - \\mu^* B + \\frac{1}{2} \\sigma^2 B^2 - r \\\\\n&= \\frac{\\partial A}{\\partial t} - ( 1 + \\frac{\\partial B}{\\partial t} ) r - \\mu^* B + \\frac{1}{2} \\sigma^2 B^2\n\\end{align}\n\n\nIf we suppose that$\\mu^*(t)$ and $\\sigma^2(t)$ are affine in short-rate $r(t)$, meaning that\n\\begin{align}\n\\mu^*(t) &= a(t)r(t) + b(t) \\\\\n\\sigma^2(t) &= c(t)r(t) + d(t),\n\\end{align}\nwhere $a,b,c$ and $d$ are deterministic functions. Thus\n\\begin{align}\n0 \t&= \\frac{\\partial A}{\\partial t} - ( 1 + \\frac{\\partial B}{\\partial t} ) r - \\mu^* B + \\frac{1}{2} \\sigma^2 B^2 \\\\\n&= \\frac{\\partial A}{\\partial t} - ( 1 + \\frac{\\partial B}{\\partial t} ) r - \\left( ar+b \\right) B + \\frac{1}{2} \\left( cr+d \\right) B^2 \\\\\n&= \\left( \\frac{\\partial A}{\\partial t} - bB + \\frac{1}{2} d B^2 \\right) +\n\\left( \\frac{1}{2} cB^2 - \\frac{\\partial B}{\\partial t} -aB - 1 \\right) r\n\\end{align}\nand this must hold for all $t, T$ and $r(t)$. Thus the coefficients must equal zero and we have that\n\\begin{align}\n\\frac{\\partial A}{\\partial t} - bB + \\frac{1}{2} d B^2 &= 0, \\\\\nA(T,T) &= 0, \\\\\n\\frac{1}{2} cB^2 - \\frac{\\partial B}{\\partial t} -aB - 1 &= 0, \\\\\nB(T,T) &= 0 .\n\\end{align}\n\nThus we have proved the following.\n\n\\begin{thm}\n\t\\label{affineconfition}\n\tIf \n\t\\begin{align}\n\t\\mu^*(t) &= a(t) r + b(t) \\\\\n\t\\sigma^2(t) &= c(t) r + d(t),\n\t\\end{align}\n\tthen the short-rate model has an affine term-structure model and the following equations holds:\n\t\\begin{align}\n\t&\\begin{cases}\n\t\\frac{\\partial B}{\\partial t} = \\frac{1}{2} c B^2  -a B - 1 \\\\\n\tB(T,T) = 0\n\t\\end{cases} \\\\\n\t&\\begin{cases}    \n\t\\frac{\\partial A}{\\partial t} - bB + \\frac{1}{2} d B^2 &= 0 \\\\\n\tA(T,T) = 0 .\n\t\\end{cases}\n\t\\end{align}\n\\end{thm}\n\nEquations of this type are Riccati Equations and they are easy to solved efficiently.\n\n\\subsection{Va\\v{s}\\'{i}\\v{c}ek--model}\n\nThe material from this section is from \\textcite[pp. 58--62]{brigo2007interest}.\n\n\\textcite{vasicek1977equilibrium} showed that under certain economic assumptions, the short-rate process is a Ornstein-Uhlenbeck process. This particular form was earlier suggest by \\textcite{merton1971optimum}. Under the Va\\v{s}\\'{i}\\v{c}ek--model, the short-rate process $r(t)$ is given by\n\\begin{align}\n\\dx r(t) = k ( \\theta - r(t) ) \\dx t + \\sigma \\dx W(t) ,\n\\end{align}\nwhere $k, \\theta, \\sigma > 0$ and $r(0) = r_0$ are constants. Thus\n\t\\begin{align}\n\t\t\\mu(t,r(t)) &= k ( \\theta - r(t) ) \\\\\n\t\t\\sigma(r,t(t)) &= \\sigma .\n\t\\end{align}\nEquivalent parametrization is\n\\begin{align}\n\\dx r(t) = ( \\theta^* - k r(t) ) \\dx t + \\sigma \\dx W(t) ,\n\\end{align}\nwhere $\\theta^* = \\theta k$. We could also write\n\t\\begin{align}\n\t\tr(t) &= \\theta + Y(t) \\\\\n\t\t\\dx Y(t) &= - k Y(t) \\dx t + \\sigma \\dx W(t).\n\t\\end{align}\nNow $r(t) = g(t,Y(t))$, where $g(t,y) = m + y$ actually and It\\^{o}'s lemma gives\n\t\\begin{align}\n\t\t\\dx r(t, Y(t)) &= - k Y(t) \\dx t + \\sigma \\dx W(t) \\\\\n\t\t\t&= k ( \\theta - r(t) ) \\dx t + \\sigma \\dx W(t) .\n\t\\end{align}\n\nWe consider a process $X(t) = \\int_0^t \\e^{k s} \\dx W(s)$ so that $\\dx X(t) = \\e^{k t} \\dx W(t)$. Now we define the function\n\\begin{align}\ng(x,t) &= r_0 \\e^{-k t} + \\theta (1 - \\e^{-k t}) + \\sigma \\e^{-k t} x \\\\\n\t&= \\theta + \\e^{-k t} \\left( r_0 - \\theta + \\sigma x \\right) \n\\end{align}\nand\n\\begin{align}\n\\frac{ \\partial g(x,t)}{ \\partial x} &= \\sigma \\e^{-k t}, \\\\\n\\frac{ \\partial^2 g(x,t)}{ \\partial x^2} &= 0, \\\\\n\\frac{ \\partial g(x,t)}{ \\partial t} &= - k \\e^{- k t} (r_0 - \\theta +\\sigma x ) \\\\\n&= k (\\theta -g(x,t) ). \n\\end{align}\nSince the drift term for $X$ is zero and diffusion factor is $\\e^{k t}$, It\\^{o}'s lemma for the process $X(t)$ yields\n\\begin{align}\n\\dx g (X(t),t) &= \\frac{ \\partial g(X(t),t) }{ \\partial t} \\dx t + \\e^{k t} \\frac{ \\partial g(X(t),t)}{ \\partial x} \\dx W \\\\\n&= k (\\theta -g(X(t),t) ) \\dx t + \\sigma W(t) .\n\\end{align}\nAs $X(0)=0$, we have that $g(X(0),0) = r_0$. Thus\n\\begin{align}\n\\label{vasiceksolution}\nr(t) = g(X(t),t) = r_0 \\e^{-k t} + \\theta (1 - \\e^{-k t}) + \\sigma \\e^{-k t} \\int_0^t \\e^{k s} \\dx W(s) .\n\\end{align}\nBy Theorem \\ref{gaussiancalculation}, the expected value of the integral in the equation \\ref{vasiceksolution} is zero and it has variance of\n\\begin{align}\n\\int_0^t \\e^{2 k s} \\dx s = \\frac{1}{2 k} (\\e^{2 k t} -1).\n\\end{align}\nHence\n\\begin{align}\nr(t) \\sim N \\left( r_0 \\e^{-k t} + \\theta (1 - \\e^{-k t}), \\frac{\\sigma^2}{2k } (1-\\e^{2k t}) \\right) .\n\\end{align}\nSince $r(t)$ is normally distributed in the Va\\v{s}\\'{i}\\v{c}ek--model, there is a positive change that short-rate will be negative in a given time frame. If $t \\rightarrow \\infty$, then \n\\begin{align}\n\\E (r(t)) &\\rightarrow \\theta , \\\\\n\\Var ( r(t) ) &\\rightarrow \\frac{\\sigma^2}{2k} .\n\\end{align}\nWe see that the parameter $\\theta$ can be seen as the long-term mean and the short-rate has a tendency to move toward it. The parameter $k$ signifies the speed of this mean-reversion while $\\sigma$ controls the volatility.\n\nOne of the features of the Va\\v{s}\\'{i}\\v{c}ek--model is that there is a non-zero probability for negative rates. Earlier this was seen as a major drawback of the model.\n\n\\subsubsection{Bond pricing in the Va\\v{s}\\'{i}\\v{c}ek--model}\n\nIf we assume that the short-rate process $r(t)$ is given by\n\\begin{align}\n\\dx r(t) = k ( \\theta - r(t) ) \\dx t + \\sigma \\dx W(t)^*\n\\end{align}\nunder the risk neutral measure. Now $\\mu(t) = k \\theta - k r(t)$ and $\\sigma(t) = \\sigma$ are affine in $r(t)$. By Theorem \\ref{affineconfition}, Va\\v{s}\\'{i}\\v{c}ek-model has affine term-structure and\n\\begin{align}\n\\label{vasicekaffine}\n\\begin{cases}\n\\frac{\\partial B}{\\partial t} = k B - 1 \\\\\n\\frac{\\partial A}{\\partial t} = k \\theta B - \\frac{1}{2} \\sigma^2 B^2 \\\\\nA(T,T) = B(T,T) = 0, \n\\end{cases}\n\\end{align}\nNow\n\\begin{align}\nB(t,T) = \\frac{1}{k} \\left( 1 - \\e^{-k (T-t)} \\right)\n\\end{align}\nsatisfies \\ref{vasicekaffine} and therefore we might solve $A(t,T)$ by calculation the integral\n\\begin{align}\nA(t,T) = A(t,T) - A(T,T) = - \\int_t^T A(s,T) \\dx s.\n\\end{align}\nWe note that $B^2 = \\frac{B}{k} \\left( \\frac{\\partial B}{\\partial t} + 1 \\right)$ and hence\n\\begin{align}\nk \\theta B - \\frac{1}{2} \\sigma^2 B^2 &= k \\theta B - \\frac{\\sigma^2}{2k} B(1+\\frac{\\partial B}{\\partial t}) \\\\\n&= \\frac{k^2 \\theta - \\frac{1}{2}\\sigma^2}{k} B  - \\frac{\\sigma^2}{2k} \\frac{\\partial B}{\\partial t} B \\\\\n&= \\frac{k^2 \\theta - \\frac{1}{2}\\sigma^2}{k^2} (\\frac{\\partial B}{\\partial t} + 1) - \\frac{\\sigma^2}{2k} B\\frac{\\partial B}{\\partial t} .\n\\end{align} \nNow the conditions in Equation \\ref{vasicekaffine} will be satisfied by\n\\begin{align}\nA(t,T) = \\frac{k^2 \\theta - \\frac{1}{2}\\sigma^2}{k^2} (B(t,T) - (T - t)) - \\frac{\\sigma^2}{4 k} B^2(t,T) .\n\\end{align}\nTherefore Va\\v{s}\\'{i}\\v{c}ek-model has term-structure defined by\n\\begin{align}\nP(t,T) = \\e^{A(t,T) - B(t,T)r(t)},\n\\end{align}\nwhere \n\\begin{align}\nB(t,T) &= \\frac{1}{ k} \\left( 1 - \\e^{-k (T-t)} \\right), \\\\\nA(t,T) &= \\frac{k^2 \\theta - \\frac{1}{2}\\sigma^2}{k^2} (B(t,T) - (T - t)) - \\frac{\\sigma^2}{4k} B^2(t,T).\n\\end{align}\n\n\\subsubsection{Option pricing in the Va\\v{s}\\'{i}\\v{c}ek--model}\n\nSince the short-rate follows a Gaussian distribution, the price of a option on a zero-coupon bond can be calculated explicitly. We shall not do that. A European call option with maturity $S$ on a $T$-bond and exercise price $K$ has a price\n\t\\begin{align}\n\t\t\\ZBC(t, S, T, K) = \\Bond(t,T) N(d_1) - K \\Bond(t,S) N(d_2),\n\t\\end{align}\nat the time $t$, where\n\t\\begin{align}\n\t\td_1 &= \\frac{ \\log \\frac{\\Bond(t,T)}{K \\Bond(t,S)} + \\frac{V}{2} }{ \\sqrt{V} } \\\\\n\t\td_2 &= \\frac{ \\log \\frac{\\Bond(t,T)}{K \\Bond(t,S)} - \\frac{V}{2} }{ \\sqrt{V} } \\\\\n\t\tV &= \\sigma^2 \\left( \\frac{1 - \\e^{-2k(T-S)}}{k} \\right)^2 \\frac{1 - \\e^{-2k(S-t)}}{2k} .\n\t\\end{align}\nA European put option with maturity $S$ on a $T$-bond and exercise price $K$ has a price\n\\begin{align}\n\\ZBP(t, S, T, K) = K \\Bond(t,S) N( - d_2) - \\Bond(t,T) N(-d_1)\n\\end{align}\nat the time $t$\n\n\\subsection{Cox-Ingersol-Ross--model (CIR)}\n\\label{sec:cir}\n\nThe material from this section is mainly from \\textcite[pp. 64--68]{brigo2007interest}.\n\n\\textcite{coxingersollross1985theory} introduced the Cox-Ingersol-Ross--model (CIR) where the short-rate process $r_t$ is given by\n\\begin{align}\n\\dx r(t) = k( \\theta - r(t) ) \\dx t + \\sigma \\sqrt{r(t)} \\dx W(t) ,\n\\end{align}\nwhere $r_0, k, \\theta$ and $\\sigma$ are positive constants. Another widely used parametrization is\n\\begin{align}\n\\dx r(t) = ( \\alpha - k r(t) ) \\dx t + \\sigma \\sqrt{r(t)} \\dx W(t) ,\n\\end{align}\nwhere $\\alpha = k \\theta$. Like Va\\v{s}\\'{i}\\v{c}ek--model, CIR features reversion toward the mean $\\theta$ with $k$ as the strength of the reversion. But it also has non-constant volatility as the diffusion term is $\\sigma \\sqrt{r(t)}$. CIR model also has affine term-structure and therefore the bond prices can be efficiently solved. Unlike Va\\v{s}\\'{i}\\v{c}ek--model, CIR--model can be specified so that the short-rate will be always positive.\n\n\\subsubsection{Bond pricing in the CIR--model}\n\nBy solving the Riccati equation, which we shall not do, we get that the bond price in CIR model is\n\t\\begin{align}\n\t\t\\Bond(t,T) = \\e^{A(t,T) - B(t,T)r(t)} ,\n\t\\end{align}\nwhere\n\t\\begin{align}\n\t\tA(t,T) &= \\frac{2k\\theta}{\\sigma^2} \\log \\left( \\frac{2 \\beta \\e^{ \\frac{(\\beta + k)(T-t)}{2} } }{(\\beta + k)(\\e^{\\beta(T-t)} - 1) + 2\\beta}  \\right) \\\\\n\t\tB(t,T) &= \\frac{ 2(\\e^{\\beta(T-t)} - 1) }{ (\\beta + k)(\\e^{\\beta(T-t)} - 1) + 2\\beta } \\\\\n\t\t\\beta &= \\sqrt{k^2+ 2\\sigma^2}\t\t\n\t\\end{align}\n\n\\subsubsection{Option pricing in the CIR--model}\n\nA European call option with maturity $S$ on a $T$-bond and exercise price $K$ has a price\n\\begin{align}\n\\ZBC(t, S, T, K) = \\Bond(t,T) \\chi_1^2 - K \\Bond(t,S) \\chi_2^2,\n\\end{align}\nat the time $t$, where\n\\begin{align}\n\t\\chi_1^2 &= \\chi^2 \\left( v_1, \\frac{4k\\theta}{\\sigma^2}, \\frac{2\\beta_3^2 r(t) \\e^{\\beta (S-t)} }{\\beta_2 + \\beta_3 + B(S,T)} \\right) \\\\\n\t\\chi_2^2 &= \\chi^2 \\left( v_2, \\frac{4k\\theta}{\\sigma^2}, \\frac{2\\beta_3^2 r(t) \\e^{\\beta (S-t)} }{\\beta_2 + \\beta_3} \\right) \\\\\n\tv_1 &= 2( \\beta_2 + \\beta_3 + B(S,T) ) \\frac{A(S,T)-\\log(K)}{B(S,T)} \\\\\n\tv_2 &= 2( \\beta_2 + \\beta_3 ) \\frac{A(S,T)-\\log(K)}{B(S,T)} \\\\\n\t\\beta_2 &= \\frac{k+\\beta}{\\sigma^2}\\\\\n\t\\beta_3 &= \\frac{2\\beta}{\\sigma^2 (\\e^{\\beta(S-t)} - 1) }\n\\end{align}\nand $\\chi^2(v,a,b)$ is the cumulative non-central chi-squared distribution with $A$ degrees of freedom and non-centrality parameter $b$.\n\n\\iffalse\n\n\\subsubsection{Glasserman algorithm}\n\nGlasserman gives the following algorithm to generate a sampling of a path in a CIR-model on time grid $0 = t_0 < t_1 < \\ldots < t_n$. We denote $d = \\frac{k \\theta}{\\sigma^2}$.\n\n\\begin{description}\n\t\\item[Case $d>1$]: For $i=0,1, \\ldots, n$:\n\t\\begin{enumerate}\n\t\t\\item Set         \n\t\t\\begin{align}\n\t\tc &= \\sigma^2 \\frac{ 1 - \\exp^{ - k ( t_{i+1} - t_i ) } }{4 k}, \\\\\n\t\t\\lambda &= r(t_i) \\frac{ \\exp^{ - k ( t_{i+1} - t_i ) } }{ c }.\n\t\t\\end{align}\n\t\t\\item Generate\n\t\t\\begin{align}\n\t\tZ &\\sim N(0,1), \\\\\n\t\tX &\\sim \\chi_{d-1}^2.\n\t\t\\end{align}\n\t\t\\item Set\n\t\t\\begin{align}\n\t\tr(t_{i+1}) = \\left( (Z + \\sqrt{\\lambda})^2 + X \\right) .\n\t\t\\end{align}\n\t\\end{enumerate}\n\t\\item[Case $d \\leq 1$]: For $i=0,1, \\ldots, n$:\n\t\\begin{enumerate}\n\t\t\\item Set         \n\t\t\\begin{align}\n\t\tc &= \\sigma^2 \\frac{ 1 - \\exp^{ - k ( t_{i+1} - t_i ) } }{4 k}, \\\\\n\t\t\\lambda &= r(t_i) \\frac{ \\exp^{ - k ( t_{i+1} - t_i ) } }{ c }.\n\t\t\\end{align}\n\t\t\\item Generate\n\t\t\\begin{align}\n\t\tZ &\\sim \\text{Poisson} ( \\frac{\\lambda}{2} ), \\\\\n\t\tX &\\sim \\chi_{d+2Z}^2.\n\t\t\\end{align}\n\t\t\\item Set\n\t\t\\begin{align}\n\t\tr(t_{i+1}) = cX .\n\t\t\\end{align}\n\t\\end{enumerate}\n\\end{description}\n\n\\fi\n\n\\section{Multi-factor short-rate models}\n\nMulti-factor short-rate models have more than one state variables that drive the evolution of the short-rate. \\textcite{litterman1991common} demonstrated that while the majority of the yield curve movements can be explained by a single factor, it can not explain it all. Usually it is considered that at least 3 factors are needed.\n\nOne problem with one-factor affine one-factor term-structures models is that rates of different maturities are perfectly correlated. By Equation \\ref{affinitytermstructureequation},\n\\begin{align}\n\\Bond(t,T) = \\e^{A(t,T) - B(t,T)r(t)}\n\\end{align}\nand the continuously compounded rate satisfies $\\e^{R(t,T)(T-t)} \\Bond(t,T) = 1$, we see that\n\\begin{align}\n\tR(t,T) = \\frac{B(t,T)}{T-t} r(t) - \\frac{A(t,T)}{T-t} .\n\\end{align}\nThis implies that rates are perfectly correlated. Thus multiple factors are needed to induce realistic correlations among the rates of different maturities.\n\nIn this section we shall follow the presentation based on \\textcite[pp. 425--435]{nawalkabeliaevasoto2007dynamic}.\n\n\\subsection{Simple $A(M,N)$--models}\n\\label{subsec-AMN-interestrate}\n\nWe now define a class of models $A(M,N)$ with $N-M$ correlated Gaussian processes and $M$ uncorrelated square-root processes. The correlated gaussian processes are\n\\begin{align}\n\\dx Y_i(t) &= - k_i Y_i(t) \\dx t + \\nu_i \\dx W_i (t),\n\\end{align}\nwhere $W_i$ is a Wiener process and \n\\begin{align}\n\\dx W_i (t) \\dx W_j (t) &= \\rho_{ij} \\dx t    \n\\end{align}\nfor all $i,j = 1,2, \\ldots, N-M$. Here $-1 < \\rho_{ij} = \\rho_{ji} < 1$ and $\\rho_{ii} = 1$. The $M$ square-root processes are\n\\begin{align}\n\\dx X_m(t) = \\alpha_m ( \\theta_m - X_m(t) ) \\dx t + \\sigma_m \\sqrt{ X_m(t) } \\dx Z_m (t)\n\\end{align}\nwhere $Z_m$ are independent Wiener process and\n\\begin{align}\n\\dx W_i (t) \\dx Z_m (t) &= 0    \n\\end{align}\nfor all $i = 1,2, \\ldots, N-M$ and $m = 1,2, \\ldots, M$. The short-rate is defined by\n\\begin{align}\nr(t) = \\delta + \\sum_{m=1}^{M} X_m(t) + \\sum_{i=1}^{N-M} Y_i(t),\n\\end{align}\nwhere $\\delta$ is a constant. Thus\n\\begin{align}\n\\dx r(t) &= \\left( \\sum_{m=1}^{M} \\alpha_m ( \\theta_m - X_m(t) ) - \\sum_{i=1}^{N-M} k_i Y_i(t) \\right) \\dx t \\\\\n&+ \\sum_{m=1}^{M} \\sigma_m \\sqrt{ X_m(t) } \\dx Z_m (t) + \\sum_{i=1}^{N-M} \\nu_i \\dx W_i (t) .\n\\end{align}\n\nIf we define\n\\begin{align}\nH(t,T) &= \\int_t^T \\delta \\dx x = (T-t) \\delta, \\\\\n\\beta_m &= \\sqrt{\\alpha_m^2 + 2 \\sigma_m^2} , \\\\\nC_i(x) &= \\frac{1 - \\e^{-k_i x}}{k_i}, \\\\\nB_m(x) &= \\frac{ 2 ( \\e^{\\beta_m x} - 1 ) }{ (\\beta_m + \\alpha_m)( \\e^{\\beta_m x} - 1) + 2 \\beta_m }, \\\\\nA(x) &= \\sum_{m=1}^M \\frac{2 \\alpha_m \\theta_m }{\\sigma_m^2} \\log \\left( \\frac{ 2 \\beta_m \\e^{ \\frac{1}{2} (\\beta_m + \\alpha_m) x } }{ (\\beta_m + \\alpha_m)( \\e^{\\beta_m x -1} ) + 2 \\beta_m } \\right) \\\\\n&+ \\frac{1}{2} \\sum_{i=1}^{N-M} \\sum_{j=1}^{N-M} \\frac{\\nu_i \\nu_j \\rho_{ij}}{k_i k_j} \\left( x - C_i(x) - C_j(x) + \\frac{1-\\e^{(k_i+k_j)x}}{k_i + k_j} \\right)\n\\end{align}\nfor all $i = 1,2, \\ldots, N-M$ and $m=1,2, \\ldots, M$, then the price of a zero coupon bond is given by\n\\begin{align}\n\\Bond (t,T) = \\exp{ \\left( A(\\tau) - \\sum_{m=1}^M B_m(\\tau) X_m(t) - \\sum_{i=1}^{N-M} C_i(\\tau) Y_i(t) - H(t,T) \\right) },\n\\end{align}\nwhere $\\tau = T-t$. This model also has a semi-explicit formula for options on zero-coupon bonds. The method to calculate this will introduced in Section \\ref{chap:fourier}.\n\nWe note that  Va\\v{s}\\'{i}\\v{c}ek--model is $A(0,1)$ and CIR--model is $A(1,1)$ in this notation.\n\nThese $A(M,N)$--models can be made into $A(M,N)++$ models by using the following dynamic extension.\n\n\\section{Dynamic extension to match the given term-structure}\n\\label{sec:dynamicextension}\n\nThis section follows the paper by \\textcite{brigomercurio2001deterministic}.\n\nLet $(\\Omega^x, \\Pm^x, \\F^x)$ be a probability space. We first assume the process $(x_{\\alpha}(t))$ follows\n\t\\begin{align}\n\t\t\\dx x_{\\alpha}(t) &= \\mu(x_{\\alpha}(t); \\alpha) \\dx t + \\sigma(x_{\\alpha}(t)); \\alpha) \\dx W_x(t) , \\\\\n\t\tx_{\\alpha}(0) &= x_0\n\t\\end{align}\nunder the measure $\\Pm^x$, where $\\alpha$ is a parameter vector. Let $\\F_t^x$ be the member of a filtration generated by $x_{\\alpha}$ up to time $t$. Suppose that the process $(x_{\\alpha}(t))$ is the short-rate process under the risk-free measure $\\Pm_x$ and the price of a zero-coupon bond is \n\t\\begin{align}\n\t\t\\Bond^x(t,T) &= \\E_{\\Pm_x} \\left( \\e^{ - \\int_t^T x_{\\alpha}(s) \\ \\dx s} \\ | \\ \\F_t^{x_{\\alpha}} \\right) ,\n\t\\end{align}\nwhich is a function of $(t,T,x_{\\alpha}, \\alpha)$. \\textcite{brigomercurio2001deterministic} calls this as a reference model. It is not guaranteed that the implied zero-curve structure by this model will match the observed market data.\n\nLet $\\varphi(t; \\alpha, x_0) = \\varphi(t; \\alpha^*)$ be a deterministic real-valued function that it is at least integrable under any closed interval. Suppose that the short-rate follows\n\t\\begin{align}\n\t\tr(t) = x(t) + \\varphi(t; \\alpha^*)\n\t\\end{align}\nand $(x(t))$ follows that same process under the risk-free measure $\\Pm_0$ as $(x_{\\alpha}(t))$ does under the measure $\\Pm^x$. This model is the shifted model. This implies that\n\t\\begin{align}\n\t\t\\Bond(t,T) &= \\E_{\\Pm_0} \\left( \\e^{ - \\int_t^T r(s) \\ \\dx s} \\ | \\ \\F_t \\right) \\\\\n\t\t\t&= \\E_{\\Pm_0} \\left( \\e^{ - \\int_t^T (x(s) + \\varphi(s; \\alpha^*)) \\ \\dx s} \\ | \\ \\F_t \\right) \\\\\n\t\t\t&=  \\E_{\\Pm_0} \\left( \\e^{ - \\int_t^T x(s)  \\ \\dx s} \\ | \\ \\F_t \\right) \\e^{ - \\int_t^T \\varphi(s; \\alpha^*) \\ \\dx s} \\\\\n\t\t\t&=  \\E_{\\Pm^x} \\left( \\e^{ - \\int_t^T x_{\\alpha}(s)  \\ \\dx s} \\ | \\ \\F_t^{x_{\\alpha}} \\right) \\e^{ - \\int_t^T \\varphi(s; \\alpha^*) \\ \\dx s} \\\\\n\t\t\t&= \\Bond^x(t,T) \\e^{ - \\int_t^T \\varphi(s; \\alpha^*) \\ \\dx s} .\n\t\\end{align}\nIf we have a method to calculate the bond price under the reference model, then bond prices under the shifted can be calculated by a making a deterministic discounting based on the function $\\varphi(t, \\alpha^*)$.\n\nIn order to shorten the notations, we denote\n\t\\begin{align}\n\t\tI(t,T,f) = \\e^{ \\int_t^T f(s) \\ \\dx s } ,\n\t\\end{align}\nwhere $f$ is a real valued function. If there is also a function\n\\begin{align}\n\\ZBC^x (t,S,T,K) = \\E_{\\Pm_x} \\left( \\e^{ - \\int_t^S x_{\\alpha}(s) \\ \\dx s} \\left( \\Bond^x(t,T) - K \\right)^+ \\ | \\ \\F_t^{x_{\\alpha}} \\right) \n\\end{align}\nfor the price at time $t$ of a call option maturing at $S$ for a $T$-bond under the reference model. Now the price under the shifted model is\n\t\\begin{align}\n\t&\\ZBC(t,S,T,K) \\\\ = &\\E_{\\Pm_0} \\left( \\e^{ - \\int_t^S r(s) \\ \\dx s} \\left( \\Bond(S,T) - K \\right)^+ \\ | \\ \\F_t \\right) \\\\\n\t\t= &\\e^{ - \\int_t^S \\varphi(s; \\alpha^*) \\ \\dx s} \\E_{\\Pm_0} \\left( \\e^{ - \\int_t^S x(s) \\ \\dx s} \\left( \\Bond(S,T) - K \\right)^+ \\ | \\ \\F_t \\right) \\\\\n\t\t= &I(t,S, -\\varphi) \\E_{\\Pm_0} \\left( I(t,S,-x) \\left( \\Bond(S,T) - K \\right)^+ \\ | \\ \\F_t \\right)\n\t\\end{align}\nAs\n\t\\begin{align}\n\t\t&\\E_{\\Pm_0} \\left( I(t,S,-x) \\left( \\Bond(S,T) - K \\right)^+ \\ | \\ \\F_t \\right) \\\\\n\t\t= &\\E_{\\Pm_0} \\left( I(t,S,-x) \\left( \\Bond^x(S,T) I(S,T,-\\varphi) - K \\right)^+ \\ | \\ \\F_t \\right) \\\\\n\t\t= &\\E_{\\Pm_0} \\left( I(t,S,-x) \\left( \\Bond^x(S,T) - I(S,T,\\varphi) K \\right)^+ \\ | \\ \\F_t \\right) I(S,T,-\\varphi) \\\\\n\t\t= &\\ZBC^x(t,S,T,K\\e^{ \\int_S^T \\varphi(s; \\alpha^*) \\ \\dx s}) \\e^{ - \\int_S^T \\varphi(s; \\alpha^*) \\ \\dx s} .\n\t\\end{align}\nHere we have used again the equivalence on processes $x(t)$ and $x_{\\alpha(t)}$. Hence\n\t\\begin{align}\n\t\t&\\ZBC(t,S,T,K) \\\\ = &\\e^{ - \\int_t^S \\varphi(s; \\alpha^*) \\ \\dx s} \\ZBC^x(t,S,T,K\\e^{ \\int_S^T \\varphi(s; \\alpha^*) \\ \\dx s}) \\e^{ - \\int_S^T \\varphi(s; \\alpha) \\ \\dx s} \\\\\n\t\t= & \\ZBC^x(t,S,T,K\\e^{ \\int_S^T \\varphi(s; \\alpha^*) \\ \\dx s}) \\e^{ - \\int_t^T \\varphi(s; \\alpha^*) \\ \\dx s}\n\t\\end{align}\nWe see that the options prices for the shifted model can be computed easily, if the options prices can be calculated efficiently under the reference model. But not pure discounting is not enough, as we also have to shift probabilities by shifting the target strike.  \n\nThus the following holds.\n\n\\begin{thm}\n\\label{bondandoptionpricesinextension}\n\tUnder the earlier assumptions, the $T$-bond has a price\n\t\\begin{align}\n\t\\Bond(t,T) =  \\Bond^x(t,T) \\e^{ - \\int_t^T \\varphi(s; \\alpha^*) \\ \\dx s}\n\t\\end{align}\n\tand a call option with maturity $S$ on this bond has price\n\t\\begin{align}\n\t\\ZBC(t,S,T,K) =  \\ZBC^x(t,S,T,K\\e^{ \\int_S^T \\varphi(s; \\alpha^*) \\ \\dx s}) \\e^{ - \\int_t^S \\varphi(s; \\alpha^*) \\ \\dx s}\n\t\\end{align}\n\tat the time $t$. \t\n\\end{thm}\n\nThis model can achieve a perfect fit to the initial interest-rate term structure.\n\n\\begin{thm}\n\\label{extensionequivalentandfactor}\n\tUnder the earlier assumptions, the following are equivalent:\n\\begin{itemize} \n\t\\item The model\n\t\t\\begin{align}\n\t\t\tr(t) = x(t) + \\varphi(t; \\alpha^*)\n\t\t\\end{align}\n\thas a perfect fit to the given interest-rate term structure,\n\t\\item for all $t \\geq 0$\n\t\t\\begin{align}\n\t\t\t\\e^{-\\int_t^T \\varphi(s; \\alpha^*) \\dx s} = \\frac{\\Bond^M(0,T) \\Bond^x(0,t)}{\\Bond^M(0,t) \\Bond^x(0,T)}, \n\t\t\\end{align}\n\t\\item for all $t \\geq 0$\n\t\\begin{align}\n\t\t\\varphi( t, \\alpha^*) = \\Forwardrate^M(0,t) - \\Forwardrate^x(0,t)\n\t\\end{align}\n\\end{itemize}\nwhere $\\Bond^M$ are observed market prices of zero-coupon bonds, $\\Forwardrate^M(0,t)$ is the market implied forward-rate and $\\Forwardrate^x(0,t)$ is the forward-rate implied by the reference model.\n\\end{thm}\n\n\\begin{proof}\nWe note that the perfect fit to market rates is equivalent to\n\t\\begin{align}\n\t\t\\label{perfectfitequationindynamicextension}\n\t\t\\Bond^M(0,t) = \\Bond(0,t) = \\e^{ - \\int_0^t \\varphi(s; \\alpha^*) \\ \\dx s} \\Bond^x(0,t) .\n\t\\end{align}\nThat is equivalent to\n\t\\begin{align}\n\\e^{ - \\int_t^T \\varphi(s; \\alpha^*) \\ \\dx s} &= \\e^{ - \\int_0^T \\varphi(s; \\alpha^*) \\ \\dx s} \\e^{ \\int_0^t \\varphi(s; \\alpha^*) \\ \\dx s} \\\\\n\t&= \\frac{\\Bond^M(0,T) }{ \\Bond^x(0,T)} \\frac{ \\Bond^x(0,t)}{\\Bond^M(0,t) }\n\\end{align}\nEquation \\ref{perfectfitequationindynamicextension} is also equivalent to \n\t\\begin{align}\n\t\t\\log \\Bond^M(0,t) = \\log \\Bond^x(0,t) - \\int_0^t \\varphi(s; \\alpha^*) \\ \\dx s\n\t\\end{align}\nfor all $t \\geq 0$ and this implies that the $-f^M(0,t) = - f^x(0,t) -  \\varphi(t; \\alpha^*)$. \n\\end{proof}\n\nTheorem \\ref{extensionequivalentandfactor} guarantees that no matter how the term-structure is shaped, we can fit it exactly with a suitable function. If we want to price bonds and options on bonds in the shifted model, then the calculation of the whole function $\\varphi$ is unnecessary as we need only the values\n\t\t\\begin{align}\n\\e^{-\\int_t^T \\varphi(s; \\alpha^*) \\dx s} = \\frac{\\Bond^M(0,T) \\Bond^x(0,t)}{\\Bond^M(0,t) \\Bond^x(0,T)} .\n\\end{align}\t\nUsing the market values is preferable to estimating the forward curve, as the curve fitting may cause errors.\n\nWe note that if $\\varphi(t) = \\varphi(t; \\alpha^*)$ is differentiable, then\n\t\\begin{align}\n\t\t\\dx r(t) &= \\dx x(t) + \\frac{\\partial}{\\partial t} \\varphi(t; \\alpha, x_0) \\dx t \\\\\n\t\t\t&= \\mu(x_{\\alpha}(t); \\alpha) \\dx t + \\sigma(x_{\\alpha}(t)); \\alpha) \\dx W_x(t) + \\frac{\\partial}{\\partial t} \\varphi(t) \\dx t \\\\\n\t\t\t&= \\left( \\mu(r(t) - \\varphi(t); \\alpha) + \\frac{\\partial}{\\partial t} \\varphi(t) \\right) \\dx t + \\sigma(r(t) - \\varphi(t)); \\alpha) \\dx W_x(t) .\n\t\\end{align}\n\t\nWe also note that if $t=0$, then\n\t\\begin{align}\n\t\t\\Bond(0,T) &= \\Bond^M(0,T) \\\\ &=  \\Bond^x(0,T) \\e^{ - \\int_0^T \\varphi(s; \\alpha^*) \\ \\dx s}\n\t\\end{align}\nand\n\t\\begin{align}\n\t\t\\ZBC(0,S,T,K) &=  \\ZBC^x(0,S,T,K\\e^{ \\int_S^T \\varphi(s; \\alpha^*) \\ \\dx s}) \\e^{ - \\int_0^S \\varphi(s; \\alpha^*) \\ \\dx s}\n\t\\end{align}\n\n\n\\subsection{Va\\v{s}\\'{i}\\v{c}ek++--model}\n\\label{sex:vasicek++}\n\nBy dynamically extending Va\\v{s}\\'{i}\\v{c}ek--model, we get a model that is equivalent to a variant of Hull-White--model (\\cite{hull1990pricing}, \\cite{brigomercurio2001deterministic}). \\added{This section follows } \\textcite[pp. 100--102]{brigo2007interest}.\n\nSuppose that we bootstrap the prices of $T_i$-bonds from the market for some $i=1,2, \\ldots, n$. Let them be $\\Bond^M(0,T_1), \\Bond^M(0,T_2), \\ldots , \\Bond^M(0,T_n)$.\n\nWe assume that the evolution of $x(t)$ is given by\n\\begin{align}\n\\dx x(t) = k ( \\theta - x(t) ) \\dx t + \\sigma \\dx W(t) ,\n\\end{align}\nwhere $k, \\theta, \\sigma > 0$ and $x(0) = x_0$ are constants and $W(t)$ is a brownian motion under the risk-free measure. We make the explicit assumption that $\\theta = 0$, hence\n\\begin{align}\n\\dx x(t) = - k x(t) ) \\dx t + \\sigma \\dx W(t) .\n\\end{align}\nThis assumption does not actually restrict the model at all. It only changes the center of the distribution, which does not matter as dynamic shift will be shifted similarly.\n\nNow we know that\n\\begin{align}\n\\Bond^x(t,T) = \\e^{- B(t,T)x(t)} ,\n\\end{align}\nwhere\n\\begin{align}\nB(t,T) &= \\frac{ 2(\\e^{\\beta(T-t)} - 1) }{ (\\beta + k)(\\e^{\\beta(T-t)} - 1) + 2\\beta }, \\\\\n\\beta &= \\sqrt{k^2+ 2\\sigma^2}\t.\t\n\\end{align}\nWe now define the short-rate by\n\t\\begin{align}\n\t\tr(t) = x(t) + \\varphi(t),\n\t\\end{align}\nwhere the function $\\varphi$ is taken as in the Theorem \\ref{extensionequivalentandfactor}. Now\n\t\\begin{align}\n\t\t\\dx r(t) &= \\left( -kx(t) + \\frac{\\partial}{\\partial t} \\varphi(t) \\right) \\dx t + \\sigma \\dx W(t) \\\\\n\t\t\t&= \\left( k( \\varphi(t) -r(t) ) + \\frac{\\partial}{\\partial t} \\varphi(t) \\right) \\dx t + \\sigma \\dx W(t) .\n\t\\end{align}\n\t\nBy Theorems \\ref{bondandoptionpricesinextension} and \\ref{extensionequivalentandfactor}, we have that\n\t\\begin{align}\n\t\t\\Bond(t,T) &= \\Bond^x(t,T) \\e^{ - \\int_t^T \\varphi(s; \\alpha^*) \\ \\dx s} \\\\\n\t\t\t&= \\Bond^x(t,T) \\frac{\\Bond^M(0,T) \\Bond^x(0,t)}{\\Bond^M(0,t \\Bond^x(0,T)} \\\\\n\t\t\t&= \\frac{\\Bond^M(0,T) }{\\Bond^M(0,t)} \\e^{ -B(t,T)x(t) -B(0,t)x(0) + B(0,T)x(0) }\n\t\\end{align}\nif $t = T_i$ and $T = T_j$ for some $i < j$. If $t=0$, then $\\Bond(0,T) = \\Bond^M(0,T)$, as was expected.\n\nA European call option with maturity $S$ on a $T$-bond and exercise price $K$ has a price\n\\begin{align}\n\\ZBC^x(t, S, T, K) = \\Bond^x(t,T) N(d_1) - K \\Bond^x(t,S) N(d_2),\n\\end{align}\nat the time $t$ under the dynamics of $x(t)$, where\n\\begin{align}\nd_1 &= \\frac{ \\log \\frac{\\Bond^x(t,T)}{K \\Bond^x(t,S)} + \\frac{V}{2} }{ \\sqrt{V} } \\\\\nd_2 &= \\frac{ \\log \\frac{\\Bond^x(t,T)}{K \\Bond^x(t,S)} - \\frac{V}{2} }{ \\sqrt{V} } \\\\\nV &= \\sigma^2 \\left( \\frac{1 - \\e^{-2k(T-S)}}{k} \\right)^2 \\frac{1 - \\e^{-2k(S-t)}}{2k} .\n\\end{align}\nNow, by Theorems \\ref{bondandoptionpricesinextension} and \\ref{extensionequivalentandfactor}, we have that\n\t\\begin{align}\n\t\\ZBC(t,S,T,K) &=  \\ZBC^x(t,S,T,K\\e^{ \\int_S^T \\varphi(s; \\alpha^*) \\ \\dx s}) \\e^{ - \\int_t^S \\varphi(s; \\alpha^*) \\ \\dx s} \\\\\n\t\t&= \\ZBC^x(t,S,T,K/I(S,T)) I(t,S),\n\t\\end{align}\nwhere\n\t\\begin{align}\n\t\tI(t,S) &= \\frac{\\Bond^M(0,S) \\Bond^x(0,t)}{\\Bond^M(0,t) \\Bond^x(0,S)} \\\\\n\t\t\t\t&= \\frac{\\Bond^M(0,S) }{\\Bond^M(0,t)} \\e^{ -B(0,t)x(0) + B(0,S)x(0) } \\end{align}\nand\n\t\\begin{align}\n\t\tI(S,T) &= \\frac{\\Bond^M(0,T) \\Bond^x(0,S)}{\\Bond^M(0,S) \\Bond^x(0,T)} \\\\\n\t\t\t&= \\frac{\\Bond^M(0,T) }{\\Bond^M(0,S)} \\e^{ -B(0,S)x(0) + B(0,T)x(0) } .\n\t\\end{align}\n\t\n\\subsection{CIR++--model}\n\nExtended CIR--model, or CIR++--model, can be constructed by combining the formulas in section \\ref{sec:cir} with the results from section \\ref{sec:dynamicextension} as was done in section \\ref{sex:vasicek++}. As this is trivial, we shall writing the formulas again.\n\n\\subsection{G2++--model}\n\n$A(2,2)++$--model is achieved by extending $A(2,2)$--model as above. Thus model is equivalent to model by \\textcite{hull1994numerical} and it is called as  $G2++$--model by \\textcite{brigo2007interest}. \n\n\\textcite[pp. 153--156, 172--173]{brigo2007interest} contains the proof for the following.\n\n\\begin{thm}\nA European call option with maturity $S$ on a $T$-bond and exercise price $K$ has a price\n\\begin{align}\n\\ZBC^x(t, S, T, K) &= \\Bond(t, T) \\Phi \\left( K^* + \\frac{1}{2} S(t,S,T) \\right) \\\\ \n&- \\Bond(t, S) K \\Phi \\left( K^* - \\frac{1}{2} S(t,S,T) \\right)\n\\end{align}\nwhere\n\\begin{align}\nK^* & = \\frac{\\log \\frac{\\Bond(t,T)}{K\\Bond(t,S)}}{S(t,S,T)} \\\\\nS(t,S,T)^2 &= \\sum_{i=1}^2 \\frac{\\nu_i^2}{2 k_i^3} \\left( 1 - \\e^{ -k_i(T-S) } \\right)^2 \\left( 1 - \\e^{-2k_i(S-t)} \\right) \\\\\n&+ 2 \\rho \\frac{\\nu_1 \\nu_2}{ k_1 k_2 (k_1 + k_2) }  \\left( 1 - \\e^{ -k_1(T-S) } \\right)  \\left( 1 - \\e^{ -k_2(T-S) } \\right)  \\left( 1 - \\e^{ -(k_1 + k_2)(S-t) } \\right)\n\\end{align}\n\\end{thm}", "meta": {"hexsha": "2e79ca2b7790a00a69cec94417c1bc27b7919150", "size": 38316, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "shortrate.tex", "max_stars_repo_name": "mrytty/gradu-public", "max_stars_repo_head_hexsha": "537337ab3dc49be9f1f4283706b0f4dcbc8cb059", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "shortrate.tex", "max_issues_repo_name": "mrytty/gradu-public", "max_issues_repo_head_hexsha": "537337ab3dc49be9f1f4283706b0f4dcbc8cb059", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "shortrate.tex", "max_forks_repo_name": "mrytty/gradu-public", "max_forks_repo_head_hexsha": "537337ab3dc49be9f1f4283706b0f4dcbc8cb059", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.4158686731, "max_line_length": 1310, "alphanum_fraction": 0.6387670947, "num_tokens": 14188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.865224072151174, "lm_q1q2_score": 0.7012458617523759}}
{"text": "\\subsection{Horizontal Asymptotes}\\label{subsec:HorizontalAsymptotes}\nThe line $y=L$ is a \\dfont{horizontal asymptote} of $f(x)$ if either\n$$\\lim_{x\\to\\infty}f(x)=L\\qquad\\mbox{or}\\qquad\\lim_{x\\to-\\infty}f(x)=L.$$\n\n\\begin{example}{Horizontal Asymptotes}{HorizontalAsymptotes}\nFind the horizontal asymptotes of $\\ds f(x)=\\frac{|x|}{x}$.\n\\end{example}\n\n\\begin{solution} \nWe must compute two infinite limits.\nFirst,\n$$\\lim_{x\\to\\infty}\\frac{|x|}{x}.$$\nNotice that for $x$ arbitrarily large that $x>0$, so that $|x|=x$.\nIn particular, for $x$ in the interval $(0,\\infty)$ we have\n$$\\lim_{x\\to\\infty}\\frac{|x|}{x}=\\lim_{x\\to\\infty}\\frac{x}{x}=1.$$\nSecond, we must compute\n$$\\lim_{x\\to-\\infty}\\frac{|x|}{x}.$$\nNotice that for $x$ arbitrarily large negative that $x<0$, so that $|x|=-x$.\nIn particular, for $x$ in the interval $(-\\infty,0)$ we have\n$$\\lim_{x\\to -\\infty}\\frac{|x|}{x}=\\lim_{x\\to -\\infty}\\frac{-x}{x}=-1.$$\nTherefore there are two horizontal asymptotes, namely, $y=1$ and $y=-1$.\n\\end{solution}", "meta": {"hexsha": "979985fd8b94721965fcf6a40c07572c5c454699", "size": 1001, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3-limits/3-5-2-horizontal-asymptotes.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3-limits/3-5-2-horizontal-asymptotes.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3-limits/3-5-2-horizontal-asymptotes.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.5, "max_line_length": 76, "alphanum_fraction": 0.6743256743, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7012458606082699}}
{"text": "\\section{Pi Digits Computation}\n\\paragraph{Goals and algorithms.}\nThe goal of these program implementations were to compute the number pi using\nRiemann sums. In other words combining the area under the curve split into small\nrectangular intervals. For\nparallelization, the strategy used was to evenly distribute the\nnumber interval areas to be calculated among the threads created by the\nprogram, and then join the results of each thread at the end to form the final\nanswer for pi. To allow for a substantial enough runtime to measure, the\nprograms were run using an absurdly high number of intervals.\n\n\\paragraph{Pi Implemented in C++.}\nThe C++ implementation used the POSIX pthread library, and creates $n$\nthreads, as the user specifies, to compute the area under the curve. In order\nto isolate the performance of the thread creation, deletion, and parallelization\nof pthreads, the timer used for measuring the program's runtime is started after\nall initialization of variables occurs, and just before creation of the child\nthreads.\n\nOnce all\nthreads are created, the main thread waits idle while trying to join all child\nthreads. As each child thread terminates, the final sum of pi is added to. Once\nall threads are finished, the final result is calculated and the timer stops.\n\n\\paragraph{Pi Implemented in Rust.}\nThe Rust implementation, like the C++ implementation, takes $n$ threads, as the\nuser specifies, to compute the area under the curve. Another similarity the Rust\nversion shares with its C++ counterpart is that it's timer begins after the all\ninitialization of variables, and just before creation of the child threads.\n\nOnce each thread finishes its work, it sends it's solution to a channel located\non the main thread where it is added to a global sum. Once all threads are\nfinished, the final sum is calculated and the timer stops.\n\n\\paragraph{User Experience writing pi in C++.}\nOverall this program was trivial to implement in C++, as the problem is not very\ncomplex, and room for memory errors to appear is narrow. There were no recorded\nmemory errors encountered during the writing of the C++ program, and no major\nusability faults regarding pthreads, with one exception: Passing arguments to\na child thread is certainly type unsafe, and memory unsafe, and could be\na potential culprit for many runtime errors if not carefully managed. This is\ndue to C++ pthreads requiring a single {\\cf void *} for all arguments, which\nguarantees almost nothing about the data being passed into the thread, and\ncannot allow for the compiler to check for safety. In the case of Pi, this was\nnot a major issue. Only a single integer value was to be passed into each\nthread upon its creation, and so no risk for accessing out-of-bounds memory was\npresent.\n\n\\paragraph{User Experience writing pi in Rust.}\nWriting this program felt much simpler and more inutitve than C++ with pthreads.\nSince channels make asynchronous sums very trivial, the hard part was pretty\nmuch already solved from the begining. The implementation looks nearly identical\nto what a single threaded pi solver implementation would look like, except for\nthe addition of a thread spawn occuring in the main loop and a channel being\nused to collect the sums. Even an individual with little knowledge of the\nlanguage could easily figure out whats going on, a feature that isn't shared\nwith the C++ implementation.\n", "meta": {"hexsha": "fcf317705d24ac8c8ef3c534c6aded84c73ea54c", "size": 3386, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/report/pi.tex", "max_stars_repo_name": "elarkham/Evaluating-Rust", "max_stars_repo_head_hexsha": "e613b07f6b36daf4937d7d47bde9b5db38cc1574", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-01-25T02:59:09.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-13T21:11:12.000Z", "max_issues_repo_path": "doc/report/pi.tex", "max_issues_repo_name": "elarkham/Evaluating-Rust", "max_issues_repo_head_hexsha": "e613b07f6b36daf4937d7d47bde9b5db38cc1574", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/report/pi.tex", "max_forks_repo_name": "elarkham/Evaluating-Rust", "max_forks_repo_head_hexsha": "e613b07f6b36daf4937d7d47bde9b5db38cc1574", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.3793103448, "max_line_length": 80, "alphanum_fraction": 0.8009450679, "num_tokens": 717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.8757869932689566, "lm_q1q2_score": 0.7012356493805736}}
{"text": "\\documentclass[12pt]{scrartcl}\n\n\\input{preamble}\n\n\\makeatletter\n\\title{Hack 12.0}\\let\\Title\\@title\n\\subtitle{Computer Science I\\\\\nRecursion \\& Memoization\\\\\n{\\small\n\\vskip1cm\nDepartment of Computer Science \\& Engineering \\\\\nUniversity of Nebraska--Lincoln}\n\\vskip-3cm}\n%\\author{Dr.\\ Chris Bourke}\n\\date{~}\n\\makeatother\n\n\\begin{document}\n\n\\maketitle\n\n\\hrule\n\n\\input{instructions.tex}\n\nCorrectness: proportionally for test cases; it \\textbf{must run on the grader} to\nreceive any points.\n\n\n\\section*{Problem Statement}\n\nA binomial coefficient, ``$n$ choose $k$'' is a number that corresponds \nto the number of ways to \\emph{choose} $k$ items from a set of $n$ distinct\nitems.  You may be familiar with some the notations, $C(n,k)$ or $C_n^k$ \nor ${}_{n}C_k $, but most commonly this is written as \n  $${n \\choose k}$$\nand read as ``$n$ choose $k$''.  There is an easy to compute formula involving\nfactorials:\n  $${n \\choose k} = \\frac{n!}{(n-k)!k!}$$\nFor example, if we have $n = 4$ items, say $\\{a, b, c, d\\}$ and want to choose\n$k=2$ of them, then there are \n  $${4 \\choose 2} = \\frac{4!}{(4-2)!2!} = 6$$\nways of doing this.  The six ways are:\n  $$\\{a, b\\}, \\{a, c\\}, \\{a, d\\}, \\{b, c\\}, \\{b, d\\}, \\{c, d\\}$$\nThere are a lot of other interpretations and applications for binomial \ncoefficients, but this hack will focus on computing their value using\na different formula, Pascal's Rule\\footnote{Which can be used to generate\nPascal's Triangle, \\url{https://en.wikipedia.org/wiki/Pascals_triangle}}:\n  $${n \\choose k} = {n-1 \\choose k} + {n-1 \\choose k-1}$$\nwhich is a recursive formula.  The base cases for Pascal's Rule are when\n$k = 0$ and $n = k$.  In both cases, the value is 1.  When $k = 0$, we are\nnot choosing any elements and so there is only one way of doing that (i.e.\\\nchoose nothing).  When $n = k$ we are choosing every element, again there\nis only one way of doing that.  \n\n\\subsection*{Writing a Naive Recursion}\n\nImplement and test the following function \\emph{using a recursive} \nsolution:\n\n\\mintinline{c}{long choose(int n, int k);}\n\nwhich takes $n$ and $k$ and computes ${n\\choose k}$ using Pascal's Rule.\nNote that the return type is a \\mintinline{c}{long}\\footnote{For those\nusing Windows, you may need to instead use a \\mintinline{c}{long long}\ndata type to get a 64-bit integer.} which is a 64-bit\ninteger allowing you to compute values up to \n  $$2^{63}-1 = 9,223,372,036,854,775,807$$\n(a little over 9 quintillion).  Write a \\mintinline{c}{main} function\nthat takes $n$ and $k$ as command line arguments and outputs the result\nto the standard output so you can easily test it.\n\n\\subsection*{Benchmarking}\n\nRun your program on values of $n, k$ in Table \\ref{table:easyValues} \nand time (roughly) how long it takes your program to execute.  You\ncan check your solutions with an online tool such as \n\\url{https://www.wolframalpha.com/}.\n\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{c|c}\n$n$ & $k$ \\\\\n\\hline\\hline\n4 & 2 \\\\\n10 & 5 \\\\\n32 & 16 \\\\  %5 seconds\n34 & 17 \\\\  %15 seconds\n36 & 18 \\\\ %60 seconds\n\\end{tabular}\n\\caption{Test Values}\n\\label{table:easyValues}\n\\end{table}\n\nNow formulate an estimate of how long your program would take to \nexecute with larger values.  You can make a \\emph{rough} estimate \nhow many function calls are made using the binomial value itself.  \nThat is, to compute ${n \\choose k}$ using Pascal's Rule would make \n\\emph{about} ${n \\choose k}$ function calls.\n\nUse the running time of your program from the test values to \nestimate how long your program would run for the values in \nTable \\ref{table:hardValues}.\n\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{c|r}\n${n \\choose k}$ &  value \\\\\n\\hline\\hline\n${54 \\choose 27}$ & =     1,946,939,425,648,112 \\\\\n${56 \\choose 28}$ & =     7,648,690,600,760,440 \\\\\n${58 \\choose 29}$ & =    30,067,266,499,541,040 \\\\\n${60 \\choose 30}$ & =   118,264,581,564,861,424 \\\\\n${62 \\choose 31}$ & =   465,428,353,255,261,088 \\\\\n${64 \\choose 32}$ & = 1,832,624,140,942,590,534 \\\\\n${66 \\choose 33}$ & = 7,219,428,434,016,265,740 \\\\\n\\end{tabular}\n\\caption{Larger Values}\n\\label{table:hardValues}\n\\end{table}\n\n\\subsection*{Improving Performance with Memoization}\n\nYou'll now improve your program's performance using memoization\nto avoid unnecessary repeated recursive calls.  \n\n\\begin{enumerate}\n  \\item Write code (either in the \\mintinline{c}{main} function or \n  using another ``entry point'' function) to create a memoization table \n  containing \\mintinline{c}{long} values of dimension $(n+1) \\times (k+1)$\n  \\item Initialize the values in the table to $-1$ as a flag value\n  to indicate that the value in the table has not yet been set.\n  \\item Using your previous recursive implementation as a guide, write\n  a new recursive function that also takes the table as a parameter.\n  When the function needs to compute ${n \\choose k}$ it checks the table\n  first: if the value has already been computed (is not $-1$) then it\n  returns that value.  Otherwise, it performs the recursive computation.\n  Before returning the value, however, it should store it (\\emph{cache}\n  it) in the table so that subsequent computations avoid the recursion.  \n  \\item Modify your \\mintinline{c}{main} function to use this more\n  efficient version and re-test it with the values above.  Compare the\n  time it took using memoization versus the naive recursion.\n  \\item Rerun your program with the values in Tables \\ref{table:easyValues} \n  and \\ref{table:hardValues} to verify they work and note the difference\n  in running time.  \n\\end{enumerate}\n\n\\section*{Instructions}\n\n\\begin{itemize}\n\n  \\item Place all of your function definitions in a source file named \n  \\mintinline{text}{binomial.c} and hand it in with your header file, \n  \\mintinline{text}{binomial.h}.  Place your \\mintinline{c}{main} \n  function in a file named \\mintinline{text}{binomialDemo.c} \n\n  \\item You are encouraged to collaborate any number of students \n  before, during, and after your scheduled hack session.  \n\n  \\item Include the name(s) of everyone who worked together on\n  this activity in your source file's header.\n\n  \\item Turn in all of your files via webhandin, making sure that \n  it runs and executes correctly in the webgrader.  Each individual \n  student will need to hand in their own copy and will receive \n  their own individual grade.\n\\end{itemize}  \n\n\n\\end{document}\n", "meta": {"hexsha": "6f925fc704a9de39e2735afa5400fdfac340b2ce", "size": 6327, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hacks/hack12.0.tex", "max_stars_repo_name": "hrithik125/ComputerScienceI", "max_stars_repo_head_hexsha": "40be47f15817a50497f6c6f7cdca9ee1db429b00", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-07T15:21:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T15:21:01.000Z", "max_issues_repo_path": "hacks/hack12.0.tex", "max_issues_repo_name": "hrithik125/ComputerScienceI", "max_issues_repo_head_hexsha": "40be47f15817a50497f6c6f7cdca9ee1db429b00", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hacks/hack12.0.tex", "max_forks_repo_name": "hrithik125/ComputerScienceI", "max_forks_repo_head_hexsha": "40be47f15817a50497f6c6f7cdca9ee1db429b00", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.0, "max_line_length": 81, "alphanum_fraction": 0.7125019757, "num_tokens": 1885, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.8757869835428965, "lm_q1q2_score": 0.7012356415929949}}
{"text": "\\lab{Hash Tables}{Hash Tables}\n\\label{lab:HashTables}\n\\objective{Empower students with basic knowledge of the fundamental, canonical data structures in order to understand performance and runtime characteristics.}\n\n\\section*{Hash Tables}\nA \\emph{hash table} is a very simple data structure that trades memory space for speed.\nThe key advantage of a hash table is this speed; most of the operations of a hash table execute very efficiently, independent of its size.\nAs such, hash tables have very fast lookup times; they form the underlying data structure for Python's set and dictionary types.\n\nOne of the key components of a hash table is a \\emph{hash function}.\nA hash function takes a piece data as an input and outputs a natural number which corresponds to the index for that piece of data.\nSince the hash function must be executed to perform any operation on the hash table (e.g. insertion or lookup), it is imperative that the hash function execute quickly.\nThus, the heart of a hash table is a good hash function.\n\nWe begin defining our \\li{HashTable} class, then, by allocating space within a one-dimensional array (in this case, a Python list) and by taking both the array size and the hash function as arguments.\n\\begin{lstlisting}\nclass HashTable(object):\n    def __init__(self, capacity):\n        # Efficiently extend a list to the designated hash table size\n        self.hashtable = [None] * capacity\n        # Keeps track of the number of elements within the hash table\n        self.size = 0\n        # Indicates the size of the hash table\n        self.capacity = capacity\n\n    def load_factor(self):\n        # The load factor tells how saturated a hash table is\n        return float(self.size)/self.capacity\n\\end{lstlisting}\n\n\nA good hash function will execute quickly and distribute items uniformly throughout the table.\nIn the hash tables in this lab, we will use Python's built-in \\li{hash} function.\nThis code demonstrates the principle steps of inserting into a hash function.\nInstead of using our \\li{HashTable} class, however, we simply use a similar construct to show how the steps might be implemented in a specific instance:\n\\begin{lstlisting}\n>>> capacity = 5\n>>> table = [None] * capacity\n>>> hash('three')\n8354070563160704301\n>>> hash('three') % capacity\n1\n>>> table[1] = 'one'\n>>> print table\n[None, 'three', None, None, None]\n>>> table[hash('four') % capacity] = 'four'\n>>> table[hash('five') % capacity] = 'five'\n>>> print table\n['four', 'three', 'five', None, None]\n\n# We can locate 'five' quickly\n# Notice that is faster than the list's builtin methods\n>>> %timeit table.index('five')\n1000000 loops, best of 3: 190 ns per loops\n>>> %timeit table[hash('five') % capacity]\n10000000 loops, best of 3: 111 ns per loop\n>>> table[hash('two') % capacity] = 'two'\n# Note that our load factor is 4/5.\n>>> print table\n['four', 'three', 'five', 'two', None]\n\n# When our load factor passes a certain threshold, we need to make the hash table bigger\n# Resizing the hash table means rehashing everything in it\n>>> def resize(table, new_cap):\n        new_table = [None] * new_cap\n        for i in table:\n            new_table[hash(i) % new_cap] = i\n        return new_table\n>>> table = resize(table, 7)\n>>> print table\n[None, None, None, 'two', None, None, 'four']\n\\end{lstlisting}\n\nThe ideal hash function maps unique inputs to unique outputs that are uniformly distributed over the hash space.\nHowever, it is extremely difficult to create an ideal hash function; most hash functions will experience hash collisions.\nHash collisions are when two unique inputs are mapped to the same index in the hash table (in our example above, resizing the hash table resulted in hash collisions that lost half the strings we stored in the table).\nFortunately, there are ways to handle hash collisions.\n\n\\paragraph{Probing.}\nOne method that we can use to resolve hash collisions is probing.\nA short example will be succintly illustrate this method.\n\\begin{lstlisting}\n>>> capacity = 5\n>>> table = [None] * capacity\n# Now we add the words 'one' and 'two'\n# Notice what happens when we add 'two'\n>>> table[hash('one') % capacity] = 'one'\n>>> print table\n[None, None, None, 'one', None]\n>>> table[hash('two') % capacity]\n'one'\n\n# We can resolve the collision by looking for the next available index\n# Starting at index 3, we look at index 3+1 % capacity, 3+2 % capacity, 3+3 % capacity, ..., until we find and empty index\n# Seeing that index 4 is None, we store 'two' there\n>>> table[4] = 'two'\n>>> print table\n[None, None, None, 'one', 'two']\n\\end{lstlisting}\nThis is called linear probing.\nThere are other variations of this idea which are more optimal.\n\n\\paragraph{Chaining.}\nAnother method for resolving hash collisions is chaining.\nThis method slightly alters the structure of our hash table, so that at each index, a list is stored.\nWhen an item is mapped to an index, it is appeneded to the list at that index.\n\\begin{lstlisting}\n>>> capacity = 5\n>>> table = [list() for i in xrange(capacity)]\n\n# Now we add the words 'one' and 'two'\n# Notice what happens when we add 'two'\n>>> table[hash('one') % capacity].append('one')\n>>> print table\n[[], [], [], ['one'], []]\n>>> table[hash('two') % capacity].append('two')\n>>> print table\n[[], [], [], ['one', 'two'], []]\n\\end{lstlisting}\n\n\\begin{problem}\nUsing the concepts illustrated in the examples above, and an insert method to your \\li{HashTable} class.\nDon't forget to update your size for the number of elements within the hashtable!\nUse chaining to handle hash collisions (namely, implement your insert method via chaining).\n\nThen, create a method for your hash table to resize.\nImplement this method such that, when your hash table exceeds a load factor of $.8$, it will resize the hash table so that the load factor is below $.3$.\nDon't forget to rehash the elements already within your table!\n\nInitialize a hash table of size 4 and insert the following felines: `lion', `tiger', `cheetah', `cougar', `colocolo', `cat', `clouded leopard', and `jaguar'.\nPrint your hash table.\n\\label{prob:hash_table}\n\\end{problem}\n\n\\begin{info}\nUsually exisiting implementations of data structures are better to use.\nThe implementations of linked lists, trees, and hash tables in this lab were designed to familiarize you with the data structure's mechanics through example and practice.\nIn real situations, you will likely use Python's deques, sets, or dictionaries.\nPython doesn't have a built-in implementation of trees, but there are several Python libraries that have highly optimized implementations of trees.\n\nPerformance tuning for data structures can be tricky even for professionals.\nFor this reason, it is better to avoid writing your implementation when one already exists.\n\\end{info}\n", "meta": {"hexsha": "81e68ded50b092279beb0560e08f29ce3499a1bb", "size": 6739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol2A/DataStructures1-LinkedLists/hashtables.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol2A/DataStructures1-LinkedLists/hashtables.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol2A/DataStructures1-LinkedLists/hashtables.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 46.7986111111, "max_line_length": 216, "alphanum_fraction": 0.7339367859, "num_tokens": 1609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.800691997339971, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.7012356355869589}}
{"text": "\\chapter{Radial Basis Function}\n\n\\section{Least Square Estimator}\nLinear Regression Equations:\n\\begin{equation*}\n\\begin{split}\ny &= \\sum_{i=1}^{n} w_i f_i(\\mathbf{x}) \\\\\n&= w_1 f_1(\\mathbf{x}) + w_2 f_2(\\mathbf{x}) + \\ldots + w_n f_n(\\mathbf{x})  \\\\\n\\mathbf{y} &= \\mathbf{Aw}\n\\end{split}\n\\end{equation*}\nThe squared error:\n\\begin{equation*}\n\\begin{split}\nE &=\\| \\mathbf{y -d} \\|^{2} \\\\\n&= \\| \\mathbf{d - Aw} \\|^{2} \\\\\n&= \\mathbf{(d-Aw)^{T}(d-Aw)} \\\\\n&= \\mathbf{d^{T}d - d^{T}Aw - (Aw)^{T}d + (Aw)^{T}(Aw)} \\\\\n&= \\mathbf{d^{T}d - 2w^{T}A^{T}d + w^{T}A^{T}Aw}\n\\end{split}\n\\end{equation*}\nFor least-square estimator:\n\\begin{equation*}\n\\begin{split}\n\\frac{\\partial E}{\\partial \\mathbf{w}} &= 0 \\\\\n2\\mathbf{A^{T}d} - 2\\mathbf{A^{T}Aw} &= 0 \\\\\n\\mathbf{A^{T}Aw} &= \\mathbf{A^{T}d} \\\\\n\\mathbf{w} &= \\mathbf{(A^{T}A)^{-1}A^{T}d}\n\\end{split}\n\\end{equation*}\nIf A is non-singular, $\\mathbf{(A^{T}A)^{-1}A^{T}}$ is pseudoinverse of A. \\\\\nIf A is singular, pseudoinverse is same as inverse of matrix. \\\\\nSingular matrix: Square matrix that is not invertible.\n\n\\section{Cover's Separability Theorem}\nA complex pattern-classification problem cast in a high-dimensional hidden space non-linearly is more likely to be linearly separable than in a low-dimensional input space.\n\n\\section{Basis Function Network}\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=10cm]{chapter5_1}\n\\end{figure}\n$$f(\\mathbf{x}) = y = \\sum_{i=1}^{N} w_i \\phi_i(\\mathbf{x})$$\nThe radial basis functions technique consists of choosing a basis function of the following form:\n$$f(\\mathbf{x}) = \\sum_{i=1}^{N} w_i \\phi(\\| \\mathbf{\\mathbf{x-\\mu_{i}}}\\|)$$\n\n\\section{Typical Radial Basis Functions}\nPiecewise linear approximation:\n$$\\phi(\\| \\mathbf{x} - \\pmb{\\mu_{i}}\\|) = \\| \\mathbf{x} - \\pmb{\\mu_{i}} \\|$$\nCubic approximation:\n$$\\phi(\\| \\mathbf{x} - \\pmb{\\mu_{i}}\\|) = \\| \\mathbf{x} - \\pmb{\\mu_{i}} \\|^{3}$$\nGaussian function:\n$$\\phi(\\| \\mathbf{x} - \\pmb{\\mu_{i}}\\|) = exp(-\\frac{\\| \\mathbf{x} - \\pmb{\\mu_{i}} \\|^{2}}{2 \\sigma^{2}})$$\nThin plate splines:\n$$\\phi(\\| \\mathbf{x} - \\pmb{\\mu_{i}}\\|) = \\| \\mathbf{x} - \\pmb{\\mu_{i}} \\|^{2} log(\\| \\mathbf{x} - \\pmb{\\mu_{i}} \\|)$$\nMultiquadratic function:\n$$\\phi(\\| \\mathbf{x} - \\pmb{\\mu_{i}}\\|) = (\\| \\mathbf{x} - \\pmb{\\mu_{i}} \\|^{2} + \\sigma^{2})^{1/2}$$\nInverse multiquadratic function:\n$$\\phi(\\| \\mathbf{x} - \\pmb{\\mu_{i}}\\|) = (\\| \\mathbf{x} - \\pmb{\\mu_{i}} \\|^{2} + \\sigma^{2})^{-1/2}$$\n\n\\section{RBF as Interpolation Networks}\nIn the interpolation approach,RBF technique consists of choosing a function such that:\n\\begin{equation}\nf(\\mathbf{x}) = y = \\sum_{i=1}^{L} w_i \\phi(\\| \\mathbf{x - x_{i}} \\|^{2})\n\\label{interpolation}\n\\end{equation}\nAnd the interpolation condition is:\n\\begin{equation}\nf(\\mathbf{x}) = \\mathbf{d}\n\\label{interpolation_condition}\n\\end{equation}\nLet:\n\\begin{equation}\n\\phi_{li} = \\phi(\\| \\mathbf{x_l - x_i} \\|)\n\\label{temp4}\n\\end{equation}\nSubstituting \\ref{interpolation_condition} and \\ref{temp4} to \\ref{interpolation}\n\\begin{equation}\n\\begin{split}\n\\sum_{i=1}^{L} w_i \\phi(\\| \\mathbf{x_l - x_{i}} \\|^{2}) &= d_l \\\\\n\\sum_{i=1}^{L} w_i \\phi_{li} &= d_l\n\\end{split}\n\\end{equation}\nRewrite the equation in matrix form:\n$$\n\\begin{bmatrix}\n\\phi_{11}  & \\cdots & \\phi_{1N} \\\\\n\\vdots     & \\ddots & \\vdots \\\\\n\\phi_{N1}  & \\cdots & \\phi_{NN}   \n\\end{bmatrix}\n\\begin{bmatrix}\nw_1 \\\\\n\\vdots \\\\\nw_N\n\\end{bmatrix} = \n\\begin{bmatrix}\nd_1 \\\\\n\\vdots \\\\\nd_N\n\\end{bmatrix}\n$$\n$$\\pmb{\\phi w = d}$$\nAssuming \\emph{Gram Matrix} $\\phi$ is non-singular:\n$$\\pmb{w = \\phi^{-1} d}$$\n\\textit{Note: The number of hidden nodes is equal to the number of data points}\n\n\\section{RBF as Approximation Networks}\nIn a generalized Gaussian RBF network, each hidden node represents a cluster of patterns. \n\\begin{equation}\n\\begin{split}\n\\phi(\\| \\mathbf{x} - \\pmb{\\mu_{i}}\\|) &= exp\\Big(-\\frac{\\| \\mathbf{x} - \\pmb{\\mu_{i}} \\|^{2}}{2 \\sigma^{2}} \\Big) \\\\\n&= exp\\Big(- \\frac{1}{2} (\\mathbf{x} - \\pmb{\\mu_i})^{T} \\mathbf{C_i^{-1}} (\\mathbf{x} - \\pmb{\\mu_i}) \\Big)\n\\end{split}\n\\end{equation}\nThe centroid $\\pmb{\\mu}$ and covariance matrix $\\mathbf{C}$: \n$$\\pmb{\\mu_{i}} = \\frac{1}{L} \\sum_{j=1}^{L} \\mathbf{x_j}$$\n$$\\mathbf{C_i} = \\frac{1}{L-1} \\sum_{j=1}^{L} (\\mathbf{x_j} - \\pmb{\\mu_i})(\\mathbf{x_j} - \\pmb{\\mu_i})^{T}$$\nRBF use k-means clustering algorithm to learn centroids of hidden layer neurons. ", "meta": {"hexsha": "fe63e5118899319c00d7e1d979a582ad0bcb7188", "size": 4300, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter5.tex", "max_stars_repo_name": "Andyccs/neural-network-summary", "max_stars_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter5.tex", "max_issues_repo_name": "Andyccs/neural-network-summary", "max_issues_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter5.tex", "max_forks_repo_name": "Andyccs/neural-network-summary", "max_forks_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.4406779661, "max_line_length": 172, "alphanum_fraction": 0.6211627907, "num_tokens": 1721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798663, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.7012356314513631}}
{"text": "\\begin{enumerate}\n\n\\item If $\\underline{s}$ is a maximum length LFSR sequence of an LFSR of length\n$L$, then it has period $2^L-1$ (as covered in lectures). This means that the\nLFSR goes through $2^L-1$ distinct states before repeating a state.\nSpecifically, these states are the members of $\\mathbb{F}_2^L \\setminus\n{(0,\\dots,0)}$. Also, the first bits of these states are the bits of the\nsequence in a single period.\n\nTo check whether $\\underline{s}$ is balanced, we just need to check whether the\nfirst bits of the members of $\\mathbb{F}_2^L \\setminus {(0,\\dots,0)}$ (the\nstates) are balanced. Clearly, there are $2^{L-1}$ states that start with 1 and\n$2^{L-1}-1$ states that start with 0 (since including $(0,\\dots,0)$ as a state\nimplies that it is the only state). Thus, the number of 0s and 1s differ by one\nand therefore the sequence is balanced: given a large $L$, a randomly chosen bit\nwill be 0 or 1 each with probability approximately $1/2$.\n\n\\item In a maximum length LFSR, the state of the LFSR register runs through all\nof the members of $\\mathbb{F}_2^L \\setminus {(0,\\dots,0)}$ in a single period\n(\\cite{slides}, Slide 36). A run of length $i$ occurs at a time $t$ with state\n$s_t$ if the preceding state $s_{t-1}$ (at time $t-1$) starts with a known\nsubstring of $i+2$ bits (eg. (0, 1, \\dots, 1, 0) - 1 repeated $i$ times - or (1,\n0, \\dots, 0, 1) (0 repeated $i$ times)). There are $2^{L-i-2}$ such states that\nprecede the start of a run of $i$ 0s or 1s. Accounting for both runs of ones and\nof zeros, the total number of states that precede the start of any run is $2\n\\times 2^{L-i-2} = 2^{L-i-1}$.\n\nAny state that precedes the start of a run either starts with 01 or 10. This\nshows that approximately half of the states precede the start of a run: the half\nthat begins with 01 or 10 rather than 11 or 00. If the total number of states is\n$tot_{states} = 2^L-1$ (excluding (0,\\dots,0) ), then the number of states that\nprecede the start of a run is $tot_{runs} = 2^{L-1}$ - half of the bit strings\nof length L.\n\nThis shows that the number of runs of length $k$ for $1 \\le k \\le L-1$ is\n\n\\[2^{L-1-k} = 2^{-k} \\times 2^{L-1}\\]\n\nwhich means that $2^{-k}$ of all runs are of length k.\n\nThis breaks down when you consider runs of length L. However, there can only be\none run of length L: the run of L 1s. The run of L 0s is the 0 state, and is\nnever reached in a maximum-length LFSR whose initial state is non-zero, as only\nnon-zero states are found in such an LFSR (\\cite{slides}, Slide 37).\n\n\\item We will prove the result with linear algebra.\n\n\\paragraph{Lemma:} Let $k$ be an integer with $1 \\le k < 2^L-1$ and let $T$\nbe a linear transformation $\\mathbb{F}^L_2 \\to \\mathbb{F}^L_2$ which\ngenerates an m-sequence $(s_i)_{i=1}^\\infty$. Then $\\text{ker}(T^k+\\mathbb{I})=\\{0\\}$.\n\n\\paragraph{Proof of Lemma:} Define $V$ as $\\text{im}(T^k+\\mathbb{I})$ and let\n$c_T$ be the characteristic (and, in this case, minimal) polynomial of $T$.\nSuppose this were not the case, that\n$\\text{dim ker}(T^k+\\mathbb{I})>0$. Then $\\text{dim}\\ V<L$ by Rank-Nullity Theorem.\nBut $V$ is $T$ invariant, since, for $v \\in \\mathbb{F}_2^L$,\n$T(T^k+\\mathbb{I})v=(T^k+\\mathbb{I})Tv$,\nso let $P$ be the characteristic polynomial of $T$ restricted to $V$.\nIf $v$ is a vector in $\\mathbb{F}^L_2$, then note $P(T)(T^k+\\mathbb{I})v=0$,\nby Cayley-Hamilton theorem on $V$. So $P(T)(T^k+\\mathbb{I})=0$, and hence\n$c_T(x) | P(x)(x^k+1)$ ($c_T$ is the minimal polynomial of the sequence\nsince it is irreducible). But $c_T$ is irreducible since $T$ generates an\nm-sequence, and $\\deg P<L=\\deg c_T$, so $c_T(x) | x^k+1$, which implies\n$k\\ge 2^L-1$ (\\cite{slides}, Slide 37), a contradiction. This concludes\nthe proof of the lemma.\n\n\\paragraph{Main Proof:} The $2^L-1$ $L$-vectors starting at each position\nin an m-sequence consist of every non-zero $L$-vector. Since \n$\\text{ker}(T^k+\\mathbb{I})=\\{0\\}$, these vectors are permuted in this map.\nSpecifically, there are $2^{L-1}-1$ vectors starting with $0$ and $2^{L-1}$ vectors\nstarting with $1$ in the image of this map. However, $s_x$ and $s_{x+k}$\ndisagree iff $s_{x+k}\\oplus s_x=1$, or iff $T^k{\\bf s_x}+{\\bf s_x}$ begins with\n$1$, where ${\\bf s_x}$ is the $L$-vector starting with $s_x$ in the m-sequence.\nHowever, the probability of $T^k{\\bf s_x}+{\\bf s_x}=(T^k+\\mathbb{I}){\\bf s_x}$\nstarting with $1$ is approximately $1/2$, since $T^k+\\mathbb{I}$ maps about half the non-zero\n$L$-vectors to vectors starting with $0$ and about half to vectors starting with\n$1$. So the m-sequence\nis approximately uncorrelated with itself shifted $k$ places whenever $k$ is not\na multiple of $2^L-1$.\n\n\\end{enumerate}\n", "meta": {"hexsha": "f528b892969fd76759e126ae341b78ff1fb3b1e8", "size": 4632, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tut2/q2.tex", "max_stars_repo_name": "h4tguy/crypto-hons", "max_stars_repo_head_hexsha": "3724eaf090f32e101504d8a73f94fddeebe2ddd9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tut2/q2.tex", "max_issues_repo_name": "h4tguy/crypto-hons", "max_issues_repo_head_hexsha": "3724eaf090f32e101504d8a73f94fddeebe2ddd9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tut2/q2.tex", "max_forks_repo_name": "h4tguy/crypto-hons", "max_forks_repo_head_hexsha": "3724eaf090f32e101504d8a73f94fddeebe2ddd9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.487804878, "max_line_length": 93, "alphanum_fraction": 0.6938687392, "num_tokens": 1586, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388209992571, "lm_q2_score": 0.8459424334245617, "lm_q1q2_score": 0.7012345233961986}}
{"text": "\\chapter{Electric Potential}\n\\subsection{Curl of the Electric field}\n\\begin{wrapfigure}{r}{0.35\\textwidth}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.35\\textwidth]{curl of electric field}\n\t\\end{center}\n\t\\caption{curl of electric field}\n\\end{wrapfigure}\n\nConsider a point charge situated at the origin, then electric field at a distance $r$ is given by,\n\\begin{align*}\n\\vec{E}=\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{q}{r^{2}} \\hat{r}\n\\end{align*}\nNow we will calculate the line integral of this field from  $a$ to $b$ as shown in the figure.\n\\begin{align*}\n\\int_{{a}}^{{b}} \\vec{E}& \\cdot \\vec{d {l}} \\\\\n\\text{In spherical coordinates,} \\quad \\vec{d {l}}&=d r \\hat{{r}}+r d \\theta \\hat{{\\theta}}+r \\sin \\theta d \\phi \\hat{{\\phi}}\\\\ \n\\text{So}\\quad\n\\vec{E} \\cdot \\vec{d {l}}&=\\frac{1}{4 \\pi \\epsilon_{0}} \\frac{q}{r^{2}} d r\\\\\n\\therefore \\int_{{a}}^{{b}} \\vec{E} \\cdot \\vec{d {l}}&=\\frac{1}{4 \\pi \\epsilon_{0}} \\int_{{a}}^{{b}} \\frac{q}{r^{2}} d r\\\\&=\\left.\\frac{-1}{4 \\pi \\epsilon_{0}} \\frac{q}{r}\\right|_{r_{a}} ^{r_{b}}\\\\&=\\frac{1}{4 \\pi \\epsilon_{0}}\\left(\\frac{q}{r_{a}}-\\frac{q}{r_{b}}\\right)\n\\end{align*}\nWhere $r_{a}$ is the distance from the origin to the point ${a}$ and $r_{b}$ is the distance to ${b}$. The integral around a closed path is evidently zero (for then $r_{a}=r_{b}$ ):\n$$\n\\oint \\vec{E} \\cdot \\vec{d {l}}=0\n$$\nOn applying Stokes theorem, we get, \n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][0.75cm]{4cm}{\n\t\t\t\n\t\t\t\\addvspace{0.2cm} \\centering \n\t\t\t\n\t\t\t$\\nabla\\times \\vec{E}=0$} }\n\\end{center}\nSince, the curl of electric field is zero, an electric field is a conservative field.\n\\begin{note}\n\tThe curl of Electric field obeys the principle of superposition,\n\t$\\vec{E}=\\vec{E}_{1}+\\vec{E}_{2}+\\ldots$\\\\Thus,\\\\\n\t$\\nabla \\times \\vec{E}=\\nabla \\times\\left(\\vec{E}_{1}+\\vec{E}_{2}+\\ldots\\right)=\\left(\\nabla \\times \\vec{E}_{1}\\right)+\\left(\\nabla \\times \\vec{E}_{2}\\right)+\\ldots=0$\n\\end{note}\n\\section{Electric potential}\n\\begin{definition}\n\tElectric potential is the amount of workdone need to bring a positive unit charge from infinity to a specific point.\\\\\nWe know that $\\oint \\vec{E} \\cdot d \\vec{r}=0$, the line integral is independent of path.\n\t\\\\So, we can define a function\\begin{equation}\n\t$$V(r)=-\\int_{O}^{p} \\vec{E} d \\vec{r}$$\n\t\\end{equation} \n\twhere $O$ is some standard reference point $V$ then depends only on the point $r .$ It is called the\n\telectric potential.\n\\end{definition}\nThen the potential difference between two points is,\\\\\n$\\begin{aligned} V({b})-V({a}) &=-\\int_{{O}}^{{b}} \\vec{E} \\cdot d \\vec{r}+\\int_{{O}}^{{a}} \\vec{E} \\cdot d \\vec{r} \\\\ &=-\\int_{{O}}^{{b}} \\vec{E} \\cdot d \\vec{r}-\\int_{{a}}^{{O}} \\vec{E} \\cdot d \\vec{r}=-\\int_{{a}}^{{b}} \\vec{E} \\cdot d \\vec{r} . \\end{aligned}$\\\\\nBy the fundamental theorem of gradients,\n\\begin{align*}\nV({b})-V({a})&=\\int_{a}^{b}(\\nabla V) \\cdot d \\vec{r} \\\\\n\\int_{{a}}^{{b}}(\\nabla V) \\cdot d {r}&=-\\int_{{a}}^{{b}} \\vec{E} \\cdot d \\vec{r}\\\\\n\\Longrightarrow \\vec{E}&=-(\\nabla V)\n\\end{align*}\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][0.75cm]{4cm}{\n\t\t\t\n\t\t\t\\addvspace{0.2cm} \\centering \n\t\t\t\n\t\t\t$\\vec{E}=-(\\nabla V)$} }\n\\end{center}\n\\begin{itemize}\n\t\\item Electric potential is a scalar quantity.\n\t\\item The potential and potential energy are totally different entities. The name \"potential\" is very similar to the phrase \"potential energy\" and this is often confusing because, though there is a connection between the two, they are different things. The relationship is understood by considering the work that needs to be done to bring a test charge q from the reference point to the point $\\mathrm{P}$ where it is to be placed, The work done by an external agency then becomes the potential energy of the system. Thus the potential at a point can be interpreted as the potential energy associated with a unit point charge at that point.\n\t\n\t\\item A surface over which the potential is constant is called\n\tan equipotential surafce.\n\t\\item Electric potential satisfies the principle of superposition, $$V=V_{1}+V_{2}+\\ldots$$\n\t\\item Unit of potential is newton-meters/coulomb or jules/coulomb or volt.\n\\end{itemize}\nIn short we can say that, The electric field being a conservative field, its curl is zero. Thus we can  express $\\vec{E}$ as a gradient of a scalar field, which we call as the electric potential. By convention to take the electric field as the negative gradient of potential, $\\vec{E}=-\\vec{\\nabla} V$. \n\\subsection{Electric potential due to point charge}\n\\begin{wrapfigure}{r}{0.40\\textwidth}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.30\\textwidth]{electric potential1}\n\t\\end{center}\n\t\\caption{Electric potential due to a point charge}\n\\end{wrapfigure}\nThe electric potential due to a point charge $q$ at origin at a distance $r$ is\n\\begin{align*}\nV(r)&=-\\int_{\\infty}^{r} \\vec{E} d \\vec{r}\\\\\n\\text{Here, }E&=\\frac{1}{4\\pi \\epsilon_{0}}\\frac{q}{r^{2}}\\\\\n\\text{then,}\\quad  V(r)&=- \\frac{q}{4\\pi \\epsilon_{0}}\\int_{\\infty}^{r} \n\\frac{ d \\vec{r}}{r^{2}}\\\\\n&=\\frac{1}{4\\pi \\epsilon_{0}}\\left[ \\frac{q}{r} \\right]_{\\infty}^{r}\\\\\n&=\\frac{1}{4\\pi \\epsilon_{0}} \\frac{q}{r} \n\\end{align*}\nFor continuous charge distribution,\n\\begin{align*}\n{V}({r})&=\\frac{1}{4 \\pi \\epsilon_{0}} \\int_{{P}} \\frac{\\lambda\\left({r}\\right)}{r} \\hat{{r}} d l\\quad\\rightarrow \\text{Linear charge distribution.}\\\\\n{V}({r})&=\\frac{1}{4 \\pi \\epsilon_{0}} \\int_{{S}} \\frac{\\sigma\\left({r}\\right)}{r} \\hat{{r}} d a\\quad\\rightarrow \\text{Surface charge distribution.}\\\\\n{V}({r})&=\\frac{1}{4 \\pi \\epsilon_{0}} \\int_{{V}} \\frac{\\rho\\left({r}\\right)}{r} \\hat{r} d \\tau\\quad \\rightarrow \\text{Volume charge distribution.}\n\\end{align*}\n\n\n\n\\subsection{Electric potential calculation}\n\n\\subsubsection{Uniformely charged spherical shell}\nConsider a uniformly charged spherical shell having radius $\\mathrm{R}$ and charge density$\\rho$. Then,\\\\\n\\begin{align*}\n\\text{Charge density}&:\\rho=\\frac{Q}{\\frac{4}{3} \\pi R^{3}}\\\\\n\\text{Electric field}&:\\text { For } r>R , \\quad E_{out}=\\frac{Q}{4 \\pi \\varepsilon_{0} r^{2}}\n\\\\&\\text {For}\\quad r<R, \\quad E_{in}=0\n\\\\&\\text {For}\\quad r=R, \\quad E_{on}=\\frac{Q}{4 \\pi \\varepsilon_{0} R^{2}}\n\\end{align*}\nThen the potentials are,\n\n\t  \\begin{align*}\n\t\\bullet\\text { For } r>R:\\\\\n\tV_{out}&=-\\int_{\\infty}^{r} \\vec{E}\\cdot d \\vec{r}\\\\\n\t&=-\\int_{\\infty}^{r} \\frac{Q}{4 \\pi \\varepsilon_{0} r^{2}}\\cdot d {r}\\\\\n\t&=\\frac{Q}{4 \\pi \\varepsilon_{0} r}\n\t\\end{align*}\n    \\begin{align*}\n \t\\bullet\t\\text { For } r<R:\\\\\n\tV_{in}&=-\\int_{\\infty}^{R} \\vec{E}\\cdot d \\vec{r}-\\int_{R}^{r} \\vec{E}\\cdot d \\vec{r}\\\\\n\t&=-\\int_{\\infty}^{R} \\frac{Q}{4 \\pi \\varepsilon_{0} r^{2}} \\cdot d {r}\\\\\n\t&=\\frac{Q}{4 \\pi \\varepsilon_{0} R}\n\t\\end{align*}\n\t \\begin{align*}\n\t\t\\bullet \\text { For } r=R:\\\\\n\tV_{on}&=-\\int_{\\infty}^{R} \\vec{E}\\cdot d \\vec{r}\\\\\n\t&=-\\int_{\\infty}^{R} \\frac{Q}{4 \\pi \\varepsilon_{0} R^{2}}\\cdot d {r}\\\\\n\t&=\\frac{Q}{4 \\pi \\varepsilon_{0} R}\n\t\\end{align*}\n\n\\begin{center}\n\\framebox{\n\t\\parbox[t][1.5cm]{8cm}{\n\t\t\n\t\t\\addvspace{0.2cm} \\centering \n\t\t\n\t\t\n\t$V_{in}=\\frac{Q}{4 \\pi \\varepsilon_{0} R}  ;\\quad V_{on}=\\frac{Q}{4 \\pi \\varepsilon_{0} R};\\quad  V_{out}=\\frac{Q}{4 \\pi \\varepsilon_{0} r}$} }\n\\end{center}\n\\subsubsection{Uniformely charged Solid sphere}\nFor a uniformely charged solid sphere of radius $R$ the elctric fields are,\n\\begin{align*}\n\t\\text{Charge density}&:\\rho=\\frac{Q}{\\frac{4}{3} \\pi R^{3}}\\\\\n\t\\text{Electric field}&:\\text { For, } r>R=E=\\frac{Q}{4 \\pi \\varepsilon_{0} r^{2}}\n\t\\\\&\\text {For}\\quad r<R, \\quad E=\\frac{Qr}{4 \\pi \\varepsilon_{0} R^{3}}\n\t\\end{align*}\n \\begin{align*}\n\t\\bullet\\text { For ,}\\quad r>R:\\\\\n\tV_{in}&=-\\int_{\\infty}^{r} \\vec{E}\\cdot d \\vec{r}\\\\\n\t&=-\\int_{\\infty}^{r} \\frac{Q}{4 \\pi \\varepsilon_{0} r^{2}}\\cdot d {r}\\\\\n\t&=\\frac{Q}{4 \\pi \\varepsilon_{0} r}\\\\\n\t\\text{In terms of charge density,}\\\\\n\tV_{in}&=\\frac{\\rho R^{3}}{3\\epsilon_{0} r}\n\\end{align*}\n \\begin{align*}\n\t\\bullet\t\\text { For, } \\quad r<R:\\\\\n\tV_{out}&=-\\int_{\\infty}^{R} \\vec{E}\\cdot d \\vec{r}-\\int_{R}^{r} \\vec{E}\\cdot d \\vec{r}\\\\\n\t&=-\\int_{\\infty}^{R} \\frac{Q}{4 \\pi \\varepsilon_{0} r^{2}}\\cdot d {r}-\\int_{R}^{r} \\frac{Qr}{4 \\pi \\varepsilon_{0} R^{3}} \\cdot d {r}\\\\\n\t&=\\frac{Q}{4 \\pi \\varepsilon_{0} R}-\\left[\\frac{Q }{4 \\pi \\varepsilon_{0} R^{3}} \\frac{r^{2}}{2} \\right]_{R}^{r}\\\\\n\t\t&=\\frac{Q}{4 \\pi \\varepsilon_{0} R}-\\left[\\frac{Q }{4 \\pi \\varepsilon_{0} R^{3}} \\frac{r^{2}}{2} \\right]+\\left[\\frac{Q }{4 \\pi \\varepsilon_{0} R^{3}} \\frac{R^{2}}{2} \\right]\\\\ \n\t\t&=\\frac{Q }{4 \\pi \\varepsilon_{0}}\\left[\\frac{3}{2R}-\\frac{r^{2}}{2R^{3}} \\right]\\\\ \n\t\t&=\\frac{Q }{8 \\pi \\varepsilon_{0}R^{3}}\\left[3R^{2}-r^{2} \\right]\\\\\n\t\\text{In terms of charge density,}\\\\\n\tV_{out}&=\\frac{\\rho }{6  \\varepsilon_{0}}\\left[3R^{2}-r^{2} \\right]\n\\end{align*}\n\\begin{note}\n$\tV_{at centre}=\\frac{3}{2}\\frac{Q}{4 \\pi \\varepsilon_{0} R}\\\\\n\tV_{at centre}=\\frac{3}{2}V_{on}$\n\\end{note}\n\\subsubsection{Uniformely charged  Circular disc}\n\nConsider a Uniformely charged  Circular disc of charge density $\\sigma$.Let us take an circular segment of radius $r$ and $r+d r$. The potential due to this element is\\\\\n\\begin{minipage}{0.65\\textwidth}\n\\begin{align*}\nd V&=\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{\\sigma da}{\\sqrt{r^{2}+z^{2}}} \\quad \\Longrightarrow \\quad da=d(\\pi r^{2})=2\\pi r dr \\\\\nd V&=\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{ \\sigma 2 \\pi r d r }{\\sqrt{r^{2}+z^{2}}} \\\\\nV&=\\frac{1}{4 \\pi \\varepsilon_{0}} 2 \\pi \\sigma \\int_{0}^{R} \\frac{2 r d r}{\\sqrt{z^{2}+r^{2}}}=\\frac{\\sigma}{2 \\varepsilon_{0}}\\left[\\sqrt{z^{2}+r^{2}}\\right]_{0}^{R} \\\\\n&=\\frac{\\sigma}{2 \\varepsilon_{0}}\\left(\\sqrt{z^{2}+R^{2}}-|z|\\right)\\\\\n\\end{align*}\n\\end{minipage}\n\\begin{minipage}{0.35\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\\includegraphics[width=0.85\\textwidth]{circular disc}\n\t\t\\caption{Uniformely charged circular disc}\n\t\t\\label{charged circular disc}\n\t\\end{figure}\n\t\n\\end{minipage}\n\n\n\\begin{exercise}\n\tThree concentric metallic shells $A, B$ and $C$ of radii $a, b$, and $c(a<b<c)$ have surface charge densities\n\t$\\sigma,-\\sigma$ and $\\sigma$ respectively.\\\\\n\t(\\textbf{1}) Find the potentials of three shells $A, B$ and $C$\\\\\n\t(\\textbf{2}) If the shells $A$ and $C$ are at the same potential, obtain the relation between the radii $a, b$ and $c .$\n\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=0.25\\textwidth]{exercise e-field1}\n\t\t\\end{center}\n\t\\end{figure}\n\\end{exercise}\n\\begin{answer}\\textbf{1.}\\\\\n\t\\begin{align*}\n\t\\text{Potential of } A =&(\\text{Potential of } A \\text{ due to }+\\sigma \\text{ on }A)+(\\text{Potential of } A \\text{ due to }-\\sigma \\text{ on }B)\\\\&+(\\text{Potential of } A \\text{ due to }+\\sigma \\text{ on }C)\\\\\n\t=&\\frac{1}{4 \\pi \\varepsilon_{0}}\\left[\\frac{4 \\pi a^{2} \\sigma}{a}-\\frac{4 \\pi b^{2} \\sigma}{b}+\\frac{4 \\pi c^{2} \\sigma}{c}\\right]\\\\\n\t=&\\frac{\\sigma}{\\varepsilon_{0}}[a-b+c]\\\\\n\t\\end{align*}\n\t\\begin{align*}\n\\text{Potential of } B =&( \\text{Potential due to} +\\sigma \\text{on} A)+( \\text{Potential due to} -\\sigma \\text{on} B)\\\\&+( \\text{Potential due to} +\\sigma \\text{on} C)\\\\\n=&\\frac{1}{4 \\pi \\varepsilon_{0}}\\left[\\frac{4 \\pi a^{2} \\sigma}{b}-\\frac{4 \\pi b^{2} \\sigma}{b}+\\frac{4 \\pi c^{2} \\sigma}{c}\\right]\\\\\n=&\\frac{\\sigma}{\\varepsilon_{0}}\\left[\\frac{a^{2}}{b}-b+c\\right]\n\t\\end{align*}\n\t\\begin{align*}\t\n\t\\text{Potential of } C =&( \\text{Potential due to}  +\\sigma \\text{ on } A)+( \\text{Potential due to} -\\sigma \\text{ on } B)\\\\&+( \\text{Potential due to} +\\sigma \\text{ on } C)\\\\\n\t=&\\frac{1}{4 \\pi \\varepsilon_{0}}\\left[\\frac{4 \\pi a^{2} \\sigma}{c}-\\frac{4 \\pi b^{2} \\sigma}{c}+\\frac{4 \\pi c^{2} \\sigma}{c}\\right]\\\\\n\t=&\\frac{\\sigma}{\\varepsilon_{0}}\\left[\\frac{a^{2}}{c}-\\frac{b^{2}}{c}+c\\right]\n\t\\end{align*}\n\t\\textbf{2.}\\\\\n\t\\begin{align*}\n\t\t\\text { Given that, } V_{A}&=V_{C}\\\\\n\t\t\\frac{\\sigma}{\\varepsilon_{0}}[a-b+c]&=\\frac{\\sigma}{\\varepsilon_{0}}\\left[\\frac{a^{2}}{c}-\\frac{b^{2}}{c}+c\\right] \\text { or } a-b-c=\\frac{a^{2}}{c}-\\frac{b^{2}}{c}+c\\\\\n\t\t\\text { Solving we get } c&=(a+b) \\text { . }\n\t\\end{align*}\n\n\t\n\\end{answer}\n\\subsection{Laplace and Poisson's eqautions}\nThe electric field is related to the charge density by the  differential form of Gauss' law as,\n\\begin{equation}\n$$\\left(\\vec{\\nabla} \\cdot \\vec{E}=\\frac{\\rho}{\\varepsilon_{0}}\\right)$$\\label{gauss law}\n\\end{equation}\nAnd from the idea of conservative field we know that,\\begin{equation}\n$$\\vec{E}=-\\vec{\\nabla} \\phi\\label{electric field}$$\n\\end{equation} \nThen putting, \\ eq.\\ref{electric field} in eq.\\ref{gauss law} we get,\n\\begin{equation}\n$$-\\vec{\\nabla} \\cdot \\vec{\\nabla} \\phi=\\frac{\\rho}{\\varepsilon_{0}}\\quad \\Longrightarrow \\quad \\nabla^{2} \\phi=-\\frac{\\rho}{\\varepsilon_{0}}\\label{poissons} $$\n\\end{equation}\nThe eq \\ref{poissons} is known as the Poisson's equation. \n\\begin{center}\n\\framebox{\n\t\\parbox[t][0.75cm]{4cm}{\n\t\t\n\t\t\\addvspace{0.2cm} \\centering \n\t\t$\\nabla^{2} \\phi=-\\frac{\\rho}{\\varepsilon_{0}}$} }\n\\end{center}\nLaplace's equation follows from Poisson's equation in the region where there is no charge density $\\rho=0 .$ The solutions of Laplace's equation are called harmonic functions. If we put $\\rho=0$ in eq.\\ref{poissons},  then we get,\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][0.75cm]{4cm}{\n\t\t\t\n\t\t\t\\addvspace{0.2cm} \\centering \n\t\t\t\n\t\t\t$\n\t\t\t\\nabla^{2} \\phi=0\n\t\t\t$} }\n\\end{center}\n\\begin{note}\nThis mathematical operation,$ \\nabla^{2}$, the divergence of the gradient of a function, is called the Laplacian.\n\\end{note}\n\\section{Laplace equation in different co-ordinate systems}\n\\subsection{Laplace's Equation in One Dimension}\nSuppose $V$ depends on only one variable, $x$. Then Laplace's equation becomes\n$$\n\\frac{d^{2} V}{d x^{2}}=0\n$$\nThe general solution is\n$$\nV(x)=m x+b,\n$$\nthe equation for a straight line. It contains two undetermined constants $(m$ and $b)$, as is appropriate for a second-order (ordinary) differential equation. They are fixed, in any particular case, by the boundary conditions of that problem.\\\\\nI want to call your attention to two features of this result; they may seem silly and obvious in one dimension, where I can write down the general solution explicitly, but the analogs in two and three dimensions are powerful and by no means obvious:\n1. $V(x)$ is the average of $V(x+a)$ and $V(x-a)$, for any $a$ :\n$$\nV(x)=\\frac{1}{2}[V(x+a)+V(x-a)] .\n$$\nLaplace's equation is a kind of averaging instruction; it tells you to assign to the point $x$ the average of the values to the left and to the right of $x$. Solutions to Laplace's equation are, in this sense, as boring as they could possibly be, and yet fit the end points properly.\n2. Laplace's equation tolerates no local maxima or minima; extreme values of $V$ must occur at the end points. Actually, this is a consequence of (1), for if there were a local maximum, $V$ at that point would be greater than on either side, and therefore could not be the average.\n\\subsection{Laplace's Equation in Two Dimensions}\nIf $V$ depends on two variables, Laplace's equation becomes\n$$\n\\frac{\\partial^{2} V}{\\partial x^{2}}+\\frac{\\partial^{2} V}{\\partial y^{2}}=0\n$$\nThis is no longer an ordinary differential equation (that is, one involving ordinary derivatives only); it is a partial differential equation. As a consequence, some of the simple rules you may be familiar with do not apply. For instance, the general solution to this equation doesn't contain just two arbitrary constants-or, for that matter, any finite number-despite the fact that it's a second-order equation. Indeed, one cannot write down a \"general solution\" . Nevertheless, it is possible to deduce certain properties common to all solutions.\\\\\n1. The value of $V$ at a point $(x, y)$ is the average of those around the point. More precisely, if you draw a circle of any radius $R$ about the point $(x, y)$, the average value of $V$ on the circle is equal to the value at the center:\n$$\nV(x, y)=\\frac{1}{2 \\pi R} \\oint_{\\text {circle }} V d l .\n$$\n2. $V$ has no local maxima or minima; all extrema occur at the boundaries. (As before, this follows from (1).) Again, Laplace's equation picks the most featureless function possible, consistent with the boundary conditions: no hills, no valleys, just the smoothest surface available.\n\\section{Laplace's Equation in Three Dimensions}\nIn three dimensions I can neither provide you with an explicit solution (as in one dimension) nor offer a suggestive physical example to guide your intuition (as I did in two dimensions). Nevertheless, the same two properties remain true, and this time I will sketch a proof.\\\\\\\\\n1. The value of $V$ at point $\\mathbf{r}$ is the average value of $V$ over a spherical surface of radius $R$ centered at $\\mathbf{r}$ :\n$$\nV(\\mathbf{r})=\\frac{1}{4 \\pi R^{2}} \\oint_{\\text {sphere }} V d a .\n$$\n2. As a consequence, $V$ can have no local maxima or minima; the extreme values of $V$ must occur at the boundaries. (For if $V$ had a local maximum at $\\mathbf{r}$, then by the very nature of maximum I could draw a sphere around $\\mathbf{r}$ over which all values of $V$-and a fortiori the average-would be less than at $\\mathbf{r}$.)\\\\\\\\\nProof: Let's begin by calculating the average potential over a spherical surface of radius $R$ due to a single point charge $q$ located outside the sphere. We may as well center the sphere at the origin and choose coordinates so that $q$ lies on the $z$-axis . The potential at a point on the surface is\n$$\nV=\\frac{1}{4 \\pi \\epsilon_{0}} \\frac{q}{r}\n$$\nwhere\n$$\nr^{2}=z^{2}+R^{2}-2 z R \\cos \\theta,\n$$\nso\n$$\n\\begin{aligned}\nV_{\\text {ave }} &=\\frac{1}{4 \\pi R^{2}} \\frac{q}{4 \\pi \\epsilon_{0}} \\int\\left[z^{2}+R^{2}-2 z R \\cos \\theta\\right]^{-1 / 2} R^{2} \\sin \\theta d \\theta d \\phi \\\\\n&=\\left.\\frac{q}{4 \\pi \\epsilon_{0}} \\frac{1}{2 z R} \\sqrt{z^{2}+R^{2}-2 z R \\cos \\theta}\\right|_{0} ^{\\pi} \\\\\n&=\\frac{q}{4 \\pi \\epsilon_{0}} \\frac{1}{2 z R}[(z+R)-(z-R)]=\\frac{1}{4 \\pi \\epsilon_{0}} \\frac{q}{z}\n\\end{aligned}\n$$\nBut this is precisely the potential due to $q$ at the center of the sphere! By the superposition principle, the same goes for any collection of charges outside the sphere: their average potential over the sphere is equal to the net potential they produce at the center. \n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=4cm]{electric potential 01}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\n\\section{Laplace equation in Spherical polar coordinates}\n\\begin{align}\n\\intertext{In  the spherical polar coordinate system, The Laplace equation is,}\n\\frac{1}{r^{2}} \\frac{\\partial}{\\partial r}\\left(r^{2} \\frac{\\partial V}{\\partial r}\\right)+\\frac{1}{r^{2} \\sin \\theta} \\frac{\\partial}{\\partial \\theta}\\left(\\sin \\theta \\frac{\\partial V}{\\partial \\theta}\\right)&+\\frac{1}{r^{2} \\sin ^{2} \\theta} \\frac{\\partial^{2} V}{\\partial \\phi^{2}}=0 \\label{Laplace in spc 1}\n\\intertext{Let us assume the system has an azimuthal symmetry such that \\ $V$\\ is independent of  $\\phi$.Then the solution of the above equation can be written as,}\nV(r, \\theta)&=R(r) \\Theta(\\theta)\\label{Laplace in spc 2}\n\\intertext{Dividing equation \\ref{Laplace in spc 1} by \\  $V$\\ ,\\ i.e \\ref{Laplace in spc 2} , \\ we get,}\n\\frac{1}{R} \\frac{d}{d r}\\left(r^{2} \\frac{d R}{d r}\\right)+\\frac{1}{\\Theta \\sin \\theta} \\frac{d}{d \\theta}\\left(\\sin \\theta \\frac{d \\Theta}{d \\theta}\\right)&=0\n\\intertext{The above equation can be written as, }\n\\frac{1}{R} \\frac{d}{d r}\\left(r^{2} \\frac{d R}{d r}\\right)&=l(l+1)\\\\ \\text{And,}\\quad \\frac{1}{\\Theta \\sin \\theta} \\frac{d}{d \\theta}\\left(\\sin \\theta \\frac{d \\Theta}{d \\theta}\\right)&=-l(l+1)\n\\intertext{Here $l(l+1)$ is just a  way of writing the separation constant. By the method of separation of variables, the equation can be  converted into ordinary differential equations. The radial equation is,}\n\\frac{d}{d r}\\left(r^{2} \\frac{d R}{d r}\\right)&=l(l+1) R\n\\intertext{It has the general solution,}\nR(r)&=A r^{l}+\\frac{B}{r^{l+1}}\n\\intertext{\tWhere $A$ and $B$ are  two arbitrary constants  in the solution of a second-order differential equation. Then the  angular equation,}\n\\frac{d}{d \\theta}\\left(\\sin \\theta \\frac{d \\Theta}{d \\theta}\\right)&=-l(l+1) \\sin \\theta \\Theta\n\\intertext{The solutions are Legendre polynomials in the variable $\\cos \\theta$ :}\n\\Theta(\\theta)&=P_{l}(\\cos \\theta)\n\\intertext{$P_{l}(x)$ is most conveniently defined by the Rodrigues formula:}\nP_{l}(x)&=\\frac{1}{2^{l} l !}\\left(\\frac{d}{d x}\\right)^{l}\\left(x^{2}-1\\right)^{l}\\\\\n\\Theta(\\theta)&=\\ln \\left(\\tan \\frac{\\theta}{2}\\right)\n\\intertext{In the case of azimuthal symmetry, the most general separable solution to Laplace's equation is,}\nV(r, \\theta)&=\\left(A r^{l}+\\frac{B}{r^{l+1}}\\right) P_{l}(\\cos \\theta)\n\\intertext{As before, separation of variables yields an infinite set of solutions,\n\tone for each $l$. The general solution is the linear combination of separable solutions,}\nV(r, \\theta)&=\\sum_{l=0}^{\\infty}\\left(A_{l} r^{l}+\\frac{B_{l}}{r^{l+1}}\\right) P_{l}(\\cos \\theta)\n\\end{align}\n\n\\begin{note}\n\tLegendre polynomials values.\n\t\\begin{align*}\n\tP_{0}(x) & =1 \\\\\n\tP_{1}^{\\prime}(x) & =x \\\\\n\tP_{2}(x) & =\\left(3 x^{2}-1\\right) / 2 \\\\\n\tP_{3}(x) & =\\left(5 x^{3}-3 x\\right) / 2 \\\\\n\tP_{4}(x) & =\\left(35 x^{4}-30 x^{2}+3\\right) / 8 \\\\\n\tP_{5}(x) & =\\left(63 x^{5}-70 x^{3}+15 x\\right) / 8\n\t\\end{align*}\n\\end{note}\n\\begin{note}\\textbf{Spherical Polar Coordinate System.}\n\t\\begin{align*}\n\t\\intertext{If $V$ is only a function of $r$ then,}\n\t\\frac{\\partial V}{\\partial \\theta}&=0 \\quad\t\\text{And} \\quad\n\t\\frac{\\partial V}{\\partial \\phi}=0\n\t\\intertext{Therefore, Laplace's equation can be rewritten as}\n\t\\frac{1}{r^{2}} \\frac{\\partial}{\\partial r}\\left(r^{2} \\frac{\\partial V}{\\partial r}\\right)&=0\\\\\n\tr^{2} \\frac{\\partial V}{\\partial r}&=A=\\text { constant }\\\\\n\t\\frac{\\partial V}{\\partial r}&=\\frac{A}{r^{2}}\n\t\\intertext{The general solution of this first-order differential equation is,}\n\tV(r)&=-\\frac{A}{r}+B\n\t\\intertext{Where $B$ is a constant. If $V=0$ at infinity then $B$ must be equal to zero, and consequently}\n\tV(r)&=-\\frac{A}{r}\n\t\\end{align*}\n\t\\begin{center}\n\t\t\\framebox{\n\t\t\t\\parbox[t][0.75cm]{4cm}{\n\t\t\t\t\n\t\t\t\t\\addvspace{0.2cm} \\centering \n\t\t\t\t\n\t\t\t\t$V(r)=-\\frac{A}{r}+B $} }\n\t\\end{center}\n\\end{note}\n\\begin{note}\n\t\\textbf{Laplace's equation in cylindrical coordinates is}\n\t\\begin{align*}\n\t\\frac{1}{r} \\frac{\\partial}{\\partial r}\\left(r \\frac{\\partial V}{\\partial r}\\right)+\\frac{1}{r^{2}} \\frac{\\partial^{2} V}{\\partial \\phi^{2}}&+\\frac{\\partial^{2} V}{\\partial z^{2}}=0\n\t\\intertext{If $V$ is only a function of $r$ then,}\n\t\\frac{\\partial V}{\\partial \\phi}&=0 \\\\\n\t\\frac{\\partial V}{\\partial z}&=0\n\t\\intertext{Therefore, Laplace's equation can be rewritten as,}\n\t\\frac{1}{r} \\frac{\\partial}{\\partial r}\\left(r \\frac{\\partial V}{\\partial r}\\right)&=0\n\t\\intertext{This differential equation can be rewritten as,}\n\t\\frac{\\partial V}{\\partial r}&=\\frac{A}{r}\n\t\\intertext{The general solution of this first-order differential equation is,}\n\tV(r)&=A \\ln (r)+B\\\\\n\t\\intertext{Where $b$ is a constant. The constants $A$ and $B$ are determined by the boundary conditions.}\n\t\\end{align*}\n\t\\begin{center}\n\t\t\\framebox{\n\t\t\t\\parbox[t][0.75cm]{4cm}{\n\t\t\t\t\n\t\t\t\t\\addvspace{0.2cm} \\centering \n\t\t\t\t\n\t\t\t\t$V(r)=A \\ln (r)+B $} }\n\t\\end{center}\t\n\t\n\t\n\\end{note}\n\\begin{exercise}\n\tPotential in a region of space is given by, $\\phi=\\phi_{0} e^{-a x^{2}}$ where $\\phi_{0}$ and $a$ is constant. Then\n\tfind the charge density in this region.\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\nabla^{2} \\phi&=-\\frac{\\rho}{\\varepsilon_{0}} \\\\ \\rho&=-\\varepsilon_{0}\\left(\\nabla^{2} \\phi\\right)\\\\&=2 a \\varepsilon_{0} \\phi\\left(1-2 a x^{2}\\right)\n\t\\end{align*}\n\\end{answer}\n\n\\begin{exercise}\n\tConsider two concentric spherical conducting shells centered at the origin. The outer\n\tradius of the inner shell is $r_{a}$ and the inner radius of the outer shell is $r_{b}$. The charge ensity\n\t$\\rho=0$ in the region $r_{a}<r<r_{b} .$ If $V=0$ at $r=r_{a}$ and $V=V_{0}$ at $r=r_{b}$, then find $V$ in the\n\tregion $r_{a}<r<r_{b}$.\n\\end{exercise}\n\\begin{answer}\n\t\\begin{alignat*}{2}\n\t&\\text {Here voltage is varying only with } r \\text { , then the  Laplace's equation is, }\\\\\n\t&\\nabla^{2} V=\\frac{1}{r^{2}} \\frac{d}{d r}\\left(r^{2} \\frac{d V}{d r}\\right)=0\\\\\n\t&\\text{Integrate twice to get the solution }V(r)=- \\frac{A}{r}+B\\\\\n\t&\\text{The boundary conditions are}\\\\\n\t&(1) V=0 \\text{ at } r=r_{a}\\\\\n\t&(2) V=V_{0} \\text{ at  }r=r_{b}\n\t\\end{alignat*}\n\t\\begin{align*}\n\t&\\text { Substituting these boundary conditions, we get }\\\\\n\t&\\text { At } r=r_{a}, 0=- \\frac{A}{r_{a}}+B \\Rightarrow B= \\frac{A}{r_{a}}\\\\\n\t&\\text { At } r=r_{b}, V_{0}=- \\frac{A}{r_{b}}+ \\frac{A}{r_{a}}=A\\left[ \\frac{1}{r_{a}}- \\frac{1}{r_{b}}\\right]\\\\\n\tV_{0}&=A \\frac{r_{b}-r_{a}}{r_{a} r_{b}}\\\\\n\tA&= V_{0}\\frac{r_{a} r_{b}}{r_{b}-r_{a}}\n\t\\intertext{Then, the constant B,}\n\tB&=\\frac{A}{r_{a}}=V_{0}\\frac{ r_{b}}{r_{b}-r_{a}}\\\\\n\t\\text{Then,}\\ V&=-  V_{0}\\frac{r_{a} r_{b}}{r_{b}-r_{a}}\\frac{1}{r}+V_{0}\\frac{ r_{b}}{r_{b}-r_{a}}\\\\\n\t&=V_{0}\\frac{ r_{b}}{r_{b}-r_{a}}\\left[- \\frac{r_{a}}{r}+1\\right]\\\\\n\tV&=V_{0}\\frac{ r_{b}}{r_{b}-r_{a}}\\left[1- \\frac{r_{a}}{r}\\right] \n\t\\end{align*}\n\t\n\\end{answer}\n\\subsection{Summary of Electrostatics}\nIn an Electrostatics  there are  three fundamental quantities : $\\rho$, $\\vec{E}$, and $V$. And we have six formulas interrelating them. These equations are  summarized below.\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.45\\textwidth]{summary}\n\t\\end{center}\n\\end{figure}\n\\subsection{Electrostatic boundary conditions}\n\\begin{wrapfigure}{r}{0.25\\textwidth}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.30\\textwidth]{e boundary3}\n\t\\end{center}\n\t\\caption{Electrostatic boundary}\n\t\\label{Electrostatic boundary1}\n\\end{wrapfigure}\n\\textbf{Electric field:}\\\\\\\\\nThe electric field always undergoes a discontinuity when you cross a surface charge $\\sigma$. We need to find the amount by which E changes at such a boundary.\\\\Consider a thin Gaussian pillbox, extending equally above and below the sheet as shown in fig.\\ref{Electrostatic boundary1} \\\\\nAccording to Gauss law,\n\n\\begin{align}\n\\oint_{S} \\vec{E} \\cdot d \\vec{a}=\\frac{1}{\\epsilon_{0}} Q_{\\mathrm{enc}}\n&=\\frac{1}{\\epsilon_{0}} \\sigma A \\notag\\\\\n\\text{\\ Then,}\\quad  E_{\\text {above }}^{\\perp} A-E_{\\text {below }}^{\\perp} A&=\\frac{\\sigma A}{\\varepsilon_{0}}\\notag \\\\\n\\Rightarrow E_{\\text {above }}^{\\perp}-E_{\\text {below }}^{\\perp}&=\\frac{\\sigma}{\\varepsilon_{0}}\n\\end{align}\n\n\\begin{wrapfigure}{r}{0.25\\textwidth}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.30\\textwidth]{e boundary1}\n\t\\end{center}\n\t\\caption{Electrostatics}\n\t\\label{Electrostatics boundary 2}\n\\end{wrapfigure}\n\nThe tangential component of $E$, by contrast, is always continuous.\n$$\n\\oint \\vec{E} \\cdot d \\vec{l}=0\n$$\nto the thin rectangular loop of Fig.\\ref{Electrostatic boundary1}, the ends give nothing $($ as $\\epsilon \\rightarrow 0)$, and the sides give $\\left(E_{\\text {above }}^{\\|} l-E_{\\text {below }}^{\\|} l\\right)$, so\n$$\n{E}_{\\text {above }}^{\\|}={E}_{\\text {below }}^{\\|}\n$$\nThen boundary conditions fo $E$ can be combined into a single formula:\n\\begin{equation}\n$$\n{E}_{\\text {above }}-{E}_{\\text {below }}=\\frac{\\sigma}{\\epsilon_{0}} \\hat{{n}}\n$$\n\\end{equation}\nwhere $\\hat{n}$ is unit vector perpendicular to the surface, pointing upward.\\\\\n\\textbf{Conclusions:} \n\\begin{itemize}\n\t\\item The normal component of $\\vec{E}$ is discontinuous by an amount $\\frac{\\sigma}{\\varepsilon_{0}}$ at any boundary. If there is no surface charge, $E^{\\perp}$ is continuous.\n\t\\item The tangential component of $E$,  is always continuous.\n\\end{itemize}\n\n\\opencutright\n\\renewcommand\\windowpagestuff{\n\t\\centering\\includegraphics[width=5cm]{e boundary2}}\n\\begin{cutout}{0}{\\dimexpr\\linewidth-3.5cm\\relax}{0pt}{5}\n\t\\textbf{Potential:}\n\t\n\t\\begin{align}\n\t\\text{The potential is continuous across any boundary, }\\notag\\\\\n\t\\text{Since }\\ V_{\\text {above }}-V_{\\text {below }}&=-\\int_{a}^{b} \\vec{E} \\cdot d \\vec{l}\\notag\\\\\n\t\\text{As the path shrinks to zero}\\notag\\\\\n\tV_{\\text {above }}&=V_{\\text {below }} \\notag\\\\\n\t\\vec{\\nabla} V_{\\text {above }}-\\vec{\\nabla} V_{\\text {below }}&=-\\frac{\\sigma}{\\varepsilon_{0}} \\hat{n}\\hspace{1cm} \\because\\vec{E}=-\\vec{\\nabla} V \\\\\n\t\\nabla V_{\\text {above }}-\\nabla V_{\\text {below }}&=-\\frac{1}{\\epsilon_{0}} \\sigma \\hat{n} \\notag \\\\\n\t\\frac{\\partial V_{\\text {above }}}{\\partial n}-\\frac{\\partial V_{\\text {below }}}{\\partial n}&=-\\frac{1}{\\epsilon_{0}} \\sigma \\notag\\\\\n\t\\frac{\\partial V}{\\partial n}&=\\nabla V \\cdot \\hat{{n}}\n\t\\end{align}\n\t$\\frac{\\partial V}{\\partial n}=\\vec{\\nabla} V \\cdot \\hat{n}$ denotes the normal derivative of $V$ (that is the rate of change in the direction perpendicular to the surface.)\n\\end{cutout}\n\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][4cm]{6cm}{\n\t\t\t\n\t\t\t\\addvspace{0.2cm} \\centering \n\t\t\t\\begin{align*}\n\t\t\tE_{\\text {above }}^{\\perp}-E_{\\text {below }}^{\\perp}&=\\frac{\\sigma}{\\varepsilon_{0}}\\\\\n\t\t\t{E}_{\\text {above }}^{\\|}-{E}_{\\text {below }}^{\\|}&=0\\\\\n\t\t\t{V}_{\\text {above }}-{V}_{\\text {below }}&=0\\\\\n\t\t\t\\nabla V_{\\text {above }}-\\nabla V_{\\text {below }}&=-\\frac{1}{\\epsilon_{0}} \\sigma \\hat{n}\n\t\t\t\\end{align*}\n\t\t\t\n\t} }\n\\end{center}\n\n\n\n\n\n\n\n\n\\newpage\n\n\\begin{table}[H]\n\t\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\\begin{tabular}{|p{3.5cm}|p{3.8cm}|p{4.6cm}|p{4.2cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Table of Electric field and Potential}}\\\\\\hline\\hline\n\t\tUniform charge distribution&Shape and Position of point&Electric field&Electric Potential\\\\\\hline\n\t\t\\multirow{2}{*}{Line charge}& At a distance $x$ from midpoint of line charge\n\t\t$x>>L$\\newline \\includegraphics[width=0.05\\textwidth]{line charge1}\n\t\t&$\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{Q}{x^{2}}$\\newline\\newline  \\includegraphics[width=0.20\\textwidth]{line charge1electric field}&$\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{Q}{x}$\\newline\\newline  \\includegraphics[width=0.20\\textwidth]{line charge1potential}\\\\\\cline{2-4}\n\t\t\n\t\t&At a distance $x$ from the one end of\\newline \\newline \\includegraphics[width=0.20\\textwidth]{line charge2}   &$\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{Q}{x(L+x)}$\\newline \\newline \\includegraphics[width=0.20\\textwidth]{line charge2electric field}   &$\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{Q}{L} \\ln \\left(1+\\frac{L}{x}\\right)$ \\newline\\newline \\includegraphics[width=0.20\\textwidth]{line charge2potential} \\\\\\hline\n\t\t\n\t\tCharged ring&On the axis at a distance $\\mathrm{x}$ from\n\t\tcentre \\newline\\newline \\includegraphics[width=0.15\\textwidth]{chargedring}  &$\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{Q x}{\\left(r^{2}+x^{2}\\right)^{3 / 2}} $ \\newline\\newline \\includegraphics[width=0.20\\textwidth]{chargedringelectricfield} &$\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{Q}{\\sqrt{r^{2}+x^{2}}}$ \\newline\\newline \\includegraphics[width=0.20\\textwidth]{chargedringpotential}\\\\\\hline\n\t\t\n\t\tCharged disc& On the axis at  a distance $x$ from centre\\newline\\newline \\includegraphics[width=0.17\\textwidth]{charged disc} &$\n\t\t\\begin{array}{l}\n\t\t\\frac{\\sigma}{2 \\varepsilon_{0}}\\left[1-\\frac{x}{\\sqrt{r^{2}+x^{2}}}\\right] x \\text { for } x>0 \\\\\n\t\t-\\frac{\\sigma}{2 \\varepsilon_{0}}\\left[1+\\frac{x}{\\sqrt{r^{2}+x^{2}}}\\right] x \\text { for } x<0\n\t\t\\end{array}\n\t\t$ \\newline\\newline \\includegraphics[width=0.20\\textwidth]{charged discelectricfied}  &$\\frac{\\sigma}{2 \\varepsilon_{0}}\\left[\\sqrt{r^{2}+x^{2}}-x\\right]$ \\newline\\newline \\includegraphics[width=0.20\\textwidth]{charged discpotential} \\\\\\hline\n\t\t\n\t\t\n\t\t\\multirow{2}{*}{\tCharged solid sphere}& Outside the sphere\n\t\t\\newline \\includegraphics[width=0.15\\textwidth]{hollowsphereout}\n\t\t&$\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{Q}{r^{2}}$ for $r>R$&$\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{Q}{r} $ for $r>R$\\\\\n\t\t&Inside the sphere\\newline \\newline \\includegraphics[width=0.09\\textwidth]{hollowspherein}   & $\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{Qr}{R^{3}}$for $r<R$\\newline \\newline \\includegraphics[width=0.18\\textwidth]{hollowsphereinelectricfield}   &$\\frac{Q}{4 \\pi \\varepsilon_{0} R}\\left[\\frac{3}{2}-\\frac{r^{2}}{2 R^{2}}\\right]$for $r<R$ \\newline\\newline \\includegraphics[width=0.18\\textwidth]{hollowsphereinpotential} \\\\\\hline\n\t\t\n\t\t\\multirow{2}{*}{Charged solid cylinder}& Inside the cylinder\n\t\t\\newline \\includegraphics[width=0.07\\textwidth]{solidcylinderin}\\newline Outside the cylinder\\newline \\newline \\includegraphics[width=0.08\\textwidth]{solidcylinderout} \n\t\t&$\\frac{\\rho r}{2 \\varepsilon_{0}}$ for $r<R$  \\newline \\newline $\\frac{\\rho R^{2}}{2 \\varepsilon_{0}r}$ for $r>R$\\newline \\newline\n\t\t\n\t\t\\includegraphics[width=0.20\\textwidth]{solidcylinderelectricfield} &$\\frac{R^{2} \\rho}{2 \\varepsilon_{0}} \\operatorname{ln}\\left(\\frac{r_{0}}{R}\\right)+\\frac{\\rho}{4 \\varepsilon_{0}}\\left(R^{2}-r^{2}\\right)$ for $r<R$ \\newline \\newline $\\frac{a^{2} \\rho}{2 \\varepsilon_{0}}\\left(\\ln\\left(\\frac{r_{0}}{r}\\right)\\right.$for $r>R$\n\t\t\\newline   \\newline ($r_{0}$ is the reference point.)\n\t\t\\\\\\hline\n\t\t\n\t\t\n\t\\end{tabular}\n\\end{table}\n\\newpage\n\\begin{abox}\n\tWork and Energy in Electrostatics\n\\end{abox}\n\\begin{minipage}{0.65\\textwidth}\n\t\\begin{align*}\n\t\\intertext{The work done in moving a test charge $Q$ in an external field $\\vec{E}$, from point $a$ to $b$ is,}\n\tW&=\\int_{a}^{b} \\vec{F} \\cdot d \\vec{l}\\\\&=-Q \\int_{a}^{b} \\vec{E} \\cdot d \\vec{l}=Q[V(b)-V(a)]\\\\\n\t[V(b)-V(a)]&=\\frac{W}{Q}\n\t\\intertext{Then the potential difference between points a and b is equal to the work per unit charge required to carry a particle from a to b. If $a=\\infty$ and $b=r$}\n\t\\Rightarrow W&=Q[V(r)-V(\\infty)]=Q V(r)\\qquad \\because V(\\infty)=0\n\t\\intertext{In this sense \\textbf{potential is potential energy (the work it takes to create the system) per unit charge (Just as the field is the force per unit charge).}}\n\t\\end{align*}\n\\end{minipage}\\hspace{0.5cm}\n\\begin{minipage}{0.25\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\includegraphics[width=0.85\\textwidth]{workdone}\n\t\t\\caption{Workdone in moving charge.}\n\t\\end{figure}\n\\end{minipage}\n\n\\section{Electrostatic energy}\nThe work necessary to assemble a system of charges against coulomb forces is stored in the field as potential energy. This is known as electrostatic energy.\n\\subsection{Electrostatic energy of system of point charges}\nLet us consider bringing point charges one by one, from far away.The first charge, $q_{1}$, takes no work, since there is no field yet to fight against. Bringing next charge $q_{2}$ cost a workdone. \n\\begin{align}\n\\intertext{When $q_{2}$ is placed work done}\nW_{2}&=q_{2} V_{1}\n\\intertext{where $V_{1}$ is the potential due to $q_{1}$ so,}\nW_{2}&=\\frac{1}{4 \\pi \\varepsilon_{0}} q_{2}\\left(\\frac{q_{1}}{R_{12}}\\right)\n\\intertext{Similiarly,}\nW_{3}&=\\frac{1}{4 \\pi \\epsilon_{0}} q_{3}\\left(\\frac{q_{1}}{r_{13}}+\\frac{q_{2}}{r_{23}}\\right)\n\\intertext{Similarly, the extra work to bring in $q_{4}$ will be}\nW_{4}&=\\frac{1}{4 \\pi \\epsilon_{0}} q_{4}\\left(\\frac{q_{1}}{r_{14}}+\\frac{q_{2}}{r_{24}}+\\frac{q_{3}}{r_{34}}\\right) .\n\\intertext{The total work necessary to assemble the first four charges, then, is}\nW&=\\frac{1}{4 \\pi \\epsilon_{0}}\\left(\\frac{q_{1} q_{2}}{r_{12}}+\\frac{q_{1} q_{3}}{r_{13}}+\\frac{q_{1} q_{4}}{r_{14}}+\\frac{q_{2} q_{3}}{r_{23}}+\\frac{q_{2} q_{4}}{r_{24}}+\\frac{q_{3} q_{4}}{r_{34}}\\right) .\n\\intertext{In general,}\nW&=\\frac{1}{4 \\pi \\varepsilon_{0}} \\sum_{i=1}^{n} \\sum_{j=1 \\atop j>i}^{n} \\frac{q_{i} q_{j}}{R_{i j}}=\\frac{1}{8 \\pi \\varepsilon_{0}} \\sum_{i=1}^{n} \\sum_{j=1 \\atop j \\neq i}^{n} \\frac{q_{i} q_{j}}{R_{i j}}\\\\&=\\frac{1}{2} \\sum_{i=1}^{n} q_{i} V\\left(r_{i}\\right)\\label{electrostatics energy\n}\n\\end{align}\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][0.75cm]{4cm}{\n\t\t\t\n\t\t\t\\addvspace{0.2cm} \\centering \n\t\t\t\n\t\t\t$ W= \\frac{1}{2} \\sum_{i=1}^{n} q_{i} V\\left(r_{i}\\right)$} }\n\\end{center}\nWhere $V\\left(r_{i}\\right)$ is the potential at point $r_{i}$ (the position of $q_{i}$ ) due to all other charges.\n\\begin{exercise}\n\tFour charges are situated at the corners of a square (side a ) as shown in figure. How much work does it take to assemble the whole configuration of four charges?\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=4cm]{potential new}\n\t\\end{figure}\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{Work done in placing first charge ( $-q$ charge upper left corner) }W_{1}&=0\\\\\n\t\\text{Work done in placing second charge ( $+q$ charge lower left corner)} W_{2}&=\\frac{1}{4\\pi \\epsilon_{0}}\\frac{-q^{2}}{a}\\\\\n\t\\text{Work done in placing third charge ( $-q$ charge lower right corner)} W_{3}&=\\frac{1}{4\\pi \\epsilon_{0}}\\left( \\frac{-q^{2}}{a}+\\frac{-q^{2}}{\\sqrt{2}a} \\right) \n\t\\end{align*}\n\tPotential at fourth corner $(+q$ charge upper right corner $)$\n\t\\begin{align*}\n\tV&=\\frac{1}{4 \\pi \\varepsilon_{0}} \\sum \\frac{q_{i}}{r_{i}}=\\frac{1}{4 \\pi \\varepsilon_{0}}\\left(-\\frac{q}{a}+\\frac{q}{\\sqrt{2} a}-\\frac{q}{a}\\right)\\\\&=\\frac{q}{4 \\pi \\varepsilon_{0} a}\\left(-2+\\frac{1}{\\sqrt{2}}\\right) \\\\\n\t\\Rightarrow W_{4}&=q V=\\frac{q^{2}}{4 \\pi \\varepsilon_{0} a}\\left(-2+\\frac{1}{\\sqrt{2}}\\right) \\\\\n\t\\text { Total work done }W&=W_{1}+W_{2}+W_{3}+W_{4}=\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{2 q^{2}}{a}\\left(-2+\\frac{1}{\\sqrt{2}}\\right)\\\\&=\\frac{q^{2}}{2 \\pi \\varepsilon_{0} a}\\left(-2+\\frac{1}{\\sqrt{2}}\\right)\n\t\\end{align*}\n\\end{answer}\n\\subsection{Energy of Continuous Charge Distribution}\nFor a system of volume charge density $\\rho$ ,the equation \\ref{electrostatics energy\n} changes to,\n\\begin{equation}\n$$W=\\frac{1}{2} \\int \\rho V d \\tau$$\\label{continous charge}\n\\end{equation}\nWe know that,$(\\vec{\\nabla} \\cdot \\vec{E})=\\frac{\\rho}{\\varepsilon_{0}}$\n$\\rightarrow$$\\rho=\\varepsilon_{0}(\\vec{\\nabla} \\cdot \\vec{E}) $ \\\\Then equation,\\ \\ref{continous charge} becomes,\n\\begin{align}\nW&=\\frac{\\varepsilon_{0}}{2} \\int(\\vec{\\nabla} \\cdot \\vec{E}) V d \\tau\\notag \\\\ W&=\\frac{\\varepsilon_{0}}{2}\\left[-\\int_{V} \\vec{E} \\cdot(\\vec{\\nabla} V) d \\tau+\\int_{V} \\vec{\\nabla} \\cdot(V \\vec{E}) d \\tau\\right]\\notag\\\\\nW&=\\frac{\\varepsilon_{0}}{2}\\left[\\int_{V} E^{2} d \\tau+\\oint_{S} V \\vec{E} \\cdot d \\vec{a}\\right] \\hspace{1cm}\\qquad\\because\\vec{E}=-\\vec{\\nabla} V \\label{Electrostatic energy }\n\\end{align}\nThe above eq.\\ref{Electrostatic energy } gives the correct energy $W$, whatever volume we use as long as it\nencloses all the charges, but the contribution from the volume integral goes up, and that of\nthe surface integral goes down, as we take larger and larger volumes. In particular, if we\nintegrate over all space, then the surface integral goes to zero, and we have\n$$\nW=\\frac{\\varepsilon_{0}}{2} \\int_{\\text {all space }} E^{2} d \\tau\n$$\n\\subsubsection{Energy of uniformly charged spherical shell}\nConsider a uniformly charged spherical shell of total charge $q$ and radius $R$.\n\\begin{align*}\n\\intertext{We know that,}\\vec{E}_{\\text {inside }}&=0, \\quad \\vec{E}_{\\text {outside }}=\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{q}{r^{2}} \\hat{r}\\\\\nW&=\\frac{\\varepsilon_{0}}{2} \\int_{\\text {all space }} E^{2} d \\tau\\\\&=\\frac{\\varepsilon_{0}}{2} \\int_{0}^{R} E_{i n}^{2} d \\tau+\\frac{\\varepsilon_{0}}{2} \\int_{R}^{\\infty} E_{\\text {out }}^{2} d \\tau\\\\&=\\frac{\\varepsilon_{0}}{2\\left(4 \\pi \\varepsilon_{0}\\right)^{2}} \\int_{\\text {outside }}\\left(\\frac{q^{2}}{r^{4}}\\right)\\left(r^{2} \\sin \\theta d r d \\theta d \\phi\\right) \\\\\nW&=\\frac{1}{32 \\pi^{2} \\varepsilon_{0}} q^{2} 4 \\pi \\int_{R}^{\\infty} \\frac{1}{r^{2}} d r\\\\ W&=\\frac{q^{2}}{8 \\pi \\varepsilon_{0} R}\n\\end{align*}\n\\subsubsection{Energy of uniformly charged solid sphere}\nConsider a uniformly charged solid sphere of radius $R$ and charge $q$.\n\\begin{align*}\n\\intertext{We know that,}\n\\vec{E}&=\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{q r}{R^{3}} \\hat{r}\\quad ; \\quad r>R \\text {  and  } \\vec{E}=\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{q}{r^{2}} \\hat{r}\\quad ; \\quad r<R \\\\\nW&=\\frac{\\varepsilon_{0}}{2} \\frac{q^{2}}{\\left(4 \\pi \\varepsilon_{0}\\right)^{2}}\\left\\{\\int_{R}^{\\infty} \\frac{1}{r^{4}}\\left(r^{2} 4 \\pi d r\\right)+\\int_{0}^{R}\\left(\\frac{r}{R^{3}}\\right)^{2}\\left(4 \\pi r^{2} d r\\right)\\right\\}\\\\&=\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{q^{2}}{2}\\left\\{\\frac{1}{R}+\\frac{1}{5 R}\\right\\} \\\\\nW&=\\frac{1}{20\\pi \\varepsilon_{0}} \\frac{3 q^{2}}{ R}\n\\end{align*}\n\\newpage \n\\begin{abox}\n\tThe Method of Images\n\\end{abox}\n\\section{The Method of Images}\n The method of images concerns itself with the problem of one or more points charges in the presence of boundary surfaces, for example, conductors either grounded or held at fixed potentials. Under favorable conditons it is possible to infer from the geometry of the situation that a small number of suitably placed charges of appropriate magnitudes, exernal to tje reion of interest, can simulate the required boundary conditions. These charges are called image charges, and the replacement of the actual problem with boundaries by an enlarged region with image charges but not boundaries is called the method of images. The image charges must be external to the volume of interest, since their potentials must be solutions of the Laplace equation inside the volume; the \"particular integral\" (i.e.,solution of the poisson equation) is peovided by the sum of the potentials of the charges inside the volume.\\\\\nA simple example is a point charge located in front of an infinite plane conductor at zero potential. \n\\subsection{Point Charge in the Presence of a Grounded Conducting Sphere}\nSuppose a point charge $q$ is held a distance $d$ above an infinite grounded conducting plane.$q$ will induce a certain amount of negative charge on the nearby surface of the conductor; the total potential is due in part to $q$ directly, and in part to this induced charge.\\\\\nFrom a mathematical point of view, our problem is to solve Poisson's equation in the region $z>0$, with a single point charge $q$ at $(0,0, d)$, subject to the boundary conditions:\\\\\n1. $V=0$ when $z=0$ (since the conducting plane is grounded), and\\\\\n2. $V \\rightarrow 0$ far from the charge (that is, for $x^{2}+y^{2}+z^{2} \\gg d^{2}$ ).\\\\\nThe first uniqueness theorem (actually, its corollary) guarantees that there is only one function that meets these requirements.\\\\\nConsider a new configuration consists of two point charges, $+q$ at \\\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3.5cm,width=9.5cm]{electric potential 02}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\n$(0,0, d)$ and $-q$ at $(0,0,-d)$, and no conducting plane . For this configuration, I can easily write down the potential:\n\\begin{equation}\nV(x, y, z)=\\frac{1}{4 \\pi \\epsilon_{0}}\\left[\\frac{q}{\\sqrt{x^{2}+y^{2}+(z-d)^{2}}}-\\frac{q}{\\sqrt{x^{2}+y^{2}+(z+d)^{2}}}\\right]\\label{image charge 1}\n\\end{equation}\n\n(The denominators represent the distances from $(x, y, z)$ to the charges $+q$ and $-q$, respectively.) It follows that\\\\\n1. $V=0$ when $z=0$,\\\\\n2. $V \\rightarrow 0$ for $x^{2}+y^{2}+z^{2} \\gg d^{2}$,\\\\\nand the only charge in the region $z>0$ is the point charge $+q$ at $(0,0, d)$. But these are precisely the conditions of the original problem! Evidently the second configuration happens to produce exactly the same potential as the first configuration, in the \"upper\" region $z \\geq 0 .$\n\\subsection{Induced Surface Charge}\nThe surface charge $\\sigma$ induced on the conductor.\n$$\\sigma=-\\in_{0}\\frac{\\partial V}{\\partial n}$$\nwhere $\\partial V / \\partial n$ is the normal derivative of $V$ at the surface. In this case the normal direction is the $z$ direction, so\n$$\n\\sigma=-\\left.\\epsilon_{0} \\frac{\\partial V}{\\partial z}\\right|_{z=0} .\n$$\nFrom Eq. \\ref{image charge 1} ,\n\\begin{align*}\n\\frac{\\partial V}{\\partial z}&=\\frac{1}{4 \\pi \\epsilon_{0}}\\left\\{\\frac{-q(z-d)}{\\left[x^{2}+y^{2}+(z-d)^{2}\\right]^{3 / 2}}+\\frac{q(z+d)}{\\left[x^{2}+y^{2}+(z+d)^{2}\\right]^{3 / 2}}\\right\\}\\\\\n\\mathrm{so}\\\\\n\\sigma(x, y)&=\\frac{-q d}{2 \\pi\\left(x^{2}+y^{2}+d^{2}\\right)^{3 / 2}} .\n\\end{align*}\nAs expected, the induced charge is negative (assuming $q$ is positive) and greatest at $x=y=0$.)\\\\\nThe total induced charge\n$$\nQ=\\int \\sigma d a .\n$$\nThis integral, over the $x y$ plane, could be done in Cartesian coordinates, with $d a=d x d y$, but it's a little easier to use polar coordinates $(r, \\phi)$, with $r^{2}=x^{2}+y^{2}$ and $d a=r d r d \\phi$. Then\n$$\n\\sigma(r)=\\frac{-q d}{2 \\pi\\left(r^{2}+d^{2}\\right)^{3 / 2}}\n$$\nand\n$$\nQ=\\int_{0}^{2 \\pi} \\int_{0}^{\\infty} \\frac{-q d}{2 \\pi\\left(r^{2}+d^{2}\\right)^{3 / 2}} r d r d \\phi=\\left.\\frac{q d}{\\sqrt{r^{2}+d^{2}}}\\right|_{0} ^{\\infty}=-q .\n$$\nThe total charge induced on the plane is $-q$ \n\\subsection{Force and Energy}\nThe charge $q$ is attracted toward the plane, because of the negative induced charge. Let's calculate the force of attraction. Since the potential in the vicinity of $q$ is the same as in the analog problem (the one with $+q$ and $-q$ but no conductor), so also is the field and, therefore, the force:\n$$\n\\mathbf{F}=-\\frac{1}{4 \\pi \\epsilon_{0}} \\frac{q^{2}}{(2 d)^{2}} \\hat{\\mathbf{z}} \n$$\nThink of the energy stored in the fields:\n$$\nW=\\frac{\\epsilon_{0}}{2} \\int E^{2} d \\tau .\n$$\nIn the first case, both the upper region $(z>0)$ and the lower region $(z<0)$ contribute-and by symmetry they contribute equally. But in the second case, only the upper region contains a nonzero field, and hence the energy is half as great.\\\\\nFor a single charge and conducting plane, the energy is half of energy due to two point charges\n$$W=-\\frac{1}{4 \\pi \\epsilon_{0}} \\frac{q^{2}}{4 d}$$\nwork required to bring $g$ in from infinity\n\\begin{align*}\n W &=\\int_{\\infty}^{d} \\mathbf{F} \\cdot d \\mathbf{l}=\\frac{1}{4 \\pi \\epsilon_{0}} \\int_{\\infty}^{d} \\frac{q^{2}}{4 z^{2}} d z \\\\\n&=\\left.\\frac{1}{4 \\pi \\epsilon_{0}}\\left(-\\frac{q^{2}}{4 z}\\right)\\right|_{\\infty} ^{d}=-\\frac{1}{4 \\pi \\epsilon_{0}} \\frac{q^{2}}{4 d} .\n\\end{align*}\n\\newpage \n\\begin{abox}\n\tMultipole Expansion\n\\end{abox}\n\\section{Multipole Expansion}\nIf you are very far away from a localized charge distribution, it \"looks\" like a point charge,and the potential is\n$$V=\\frac{1}{4\\pi \\varepsilon_{0}}\\frac{Q}{r}$$\nWhere $Q$ is the total charge\\\\\\\\\nBut what if $Q$ is zero?\n\\subsection{Electric Dipole}\n A physical electric dipole consists of two equal and opposite charges $(\\pm q)$ seperated by a distance $d$. \n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=4cm]{electric potential 17}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\nLet $r_{-}$be the distance from $-q$ and $r_{+}$the distance from $+q$ (Fig. 26). Then\n$$\nV(\\mathbf{r})\\approx\\frac{1}{4 \\pi \\epsilon_{0}}\\left(\\frac{q}{r_{+}}-\\frac{q}{r_{-}}\\right),\n$$\nand (from the law of cosines)\n$$\nr_{\\pm}^{2}=r^{2}+(d / 2)^{2} \\mp r d \\cos \\theta=r^{2}\\left(1 \\mp \\frac{d}{r} \\cos \\theta+\\frac{d^{2}}{4 r^{2}}\\right) .\n$$\nWe're interested in the régime $r \\gg d$, so the third term is negligible, and the binomial expansion yields\n$$\n\\frac{1}{r_{\\pm}} \\cong \\frac{1}{r}\\left(1 \\mp \\frac{d}{r} \\cos \\theta\\right)^{-1 / 2} \\cong \\frac{1}{r}\\left(1 \\pm \\frac{d}{2 r} \\cos \\theta\\right) \\text {. }\n$$\nThus\n$$\n\\frac{1}{r_{+}}-\\frac{1}{r_{-}} \\cong \\frac{d}{r^{2}} \\cos \\theta,\n$$\nand hence\n$$V(\\mathbf{r}) \\cong \\frac{1}{4 \\pi \\epsilon_{0}} \\frac{q d \\cos \\theta}{r^{2}}$$\nThe potential of a dipole goes like $1 / r^{2}$ at large $r$; as we might have anticipated, it falls off more rapidly than the potential of a point charge. If we put together a pair of equal and opposite dipoles to make a quadrupole, the potential goes like $1 / r^{3}$; for back-to-back quadrupoles (an octopole), it goes like $1 / r^{4}$; and so on. Figure 27 summarizes this hierarchy; for completeness I have included the electric monopole (point charge), whose potential, of course, goes like $1 / r$.\n\\begin{figure}[H]\n\t\\begin{minipage}{0.24\\textwidth}\n\t\t\\includegraphics[width=0.25\\textwidth]{monopole}\n\t\t\\caption{Monopole}\n\t\\end{minipage}\n\t\\begin{minipage}{0.24\\textwidth}\n\t\t\\includegraphics[width=0.65\\textwidth]{dipole}\n\t\t\\caption{Dipole}\n\t\\end{minipage}\n\t\\begin{minipage}{0.24\\textwidth}\n\t\t\\includegraphics[width=0.65\\textwidth]{quadrapole}\n\t\t\\caption{Quadrapole}\n\t\\end{minipage}\n\t\\begin{minipage}{0.24\\textwidth}\n\t\t\\includegraphics[width=0.65\\textwidth]{octapole}\n\t\t\\caption{Octapole}\n\t\\end{minipage}\n\\end{figure}\nTo develop a systematic expansion for the potential of any localized charge distribution, in powers of $1/r$, the potential at $r$ is given by \\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3.5cm,width=6cm]{Electric potential 19}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\n\\begin{equation}\nV(\\mathbf{r})=\\frac{1}{4 \\pi \\epsilon_{0}} \\int \\frac{1}{r_0} \\rho\\left(\\mathbf{r}^{\\prime}\\right) d \\tau^{\\prime}\\label{EP1}\n\\end{equation}\nUsing the law of cosines,\n\\begin{align*}\nr_0^{2}&=r^{2}+\\left(r^{\\prime}\\right)^{2}-2 r r^{\\prime} \\cos \\alpha\\\\&=r^{2}\\left[1+\\left(\\frac{r^{\\prime}}{r}\\right)^{2}-2\\left(\\frac{r^{\\prime}}{r}\\right) \\cos \\alpha\\right]\n\\intertext{where $\\alpha$ is the angle between $\\mathbf{r}$ and $\\mathbf{r}^{\\prime}$. Thus}\nr_0&=r \\sqrt{1+\\epsilon}\n\\intertext{with, $\\varepsilon \\equiv\\left(\\frac{r^{\\prime}}{r}\\right)\\left(\\frac{r^{\\prime}}{r}-2 \\cos \\alpha\\right)$}\n\\intertext{For points well outside the charge distribution, $\\epsilon$ is much less than 1 , and this invites a binomial expansion:}\n\\frac{1}{r_0}&=\\frac{1}{r}(1+\\epsilon)^{-1 / 2}\\\\&=\\frac{1}{r}\\left(1-\\frac{1}{2} \\epsilon+\\frac{3}{8} \\epsilon^{2}-\\frac{5}{16} \\epsilon^{3}+\\ldots\\right)\n\\intertext{or, in terms of $r, r^{\\prime}$, and $\\alpha$ :}\n\\frac{1}{r_0}&=\\frac{1}{r}\\left[1-\\frac{1}{2}\\left(\\frac{r^{\\prime}}{r}\\right)\\left(\\frac{r^{\\prime}}{r}-2 \\cos \\alpha\\right)+\\frac{3}{8}\\left(\\frac{r^{\\prime}}{r}\\right)^{2}\\left(\\frac{r^{\\prime}}{r}-2 \\cos \\alpha\\right)^{2}\\right. \\\\\n& \\left. \\right.  \\quad \\left.-\\frac{5}{16}\\left(\\frac{r^{\\prime}}{r}\\right)^{3}\\left(\\frac{r^{\\prime}}{r}-2 \\cos \\alpha\\right)^{3}+\\ldots\\right] \\\\\n&=\\frac{1}{r}\\left[1+\\left(\\frac{r^{\\prime}}{r}\\right)(\\cos \\alpha)+\\left(\\frac{r^{\\prime}}{r}\\right)^{2}\\left(\\frac{3 \\cos ^{2} \\alpha-1}{2}\\right)\\right. \\\\\n\\left. \\right.  \\quad &\\left.+\\left(\\frac{r^{\\prime}}{r}\\right)^{3}\\left(\\frac{5 \\cos ^{3} \\alpha-3 \\cos \\alpha}{2}\\right)+\\ldots\\right]\n\\end{align*}\n\\begin{align*}\n\\intertext{Here it is collected together like powers of $(r^\\prime/r)$ and their coefficients are Legendre polynomials.So, }\n\\frac{1}{r}&=\\frac{1}{r} \\sum_{n=0}^{\\infty}\\left(\\frac{r^{\\prime}}{r}\\right)^{n} P_{n}(\\cos \\alpha) \n\\intertext{Substituting this back into Eq. \\ref{EP1} , and noting that $r$ is a constant, as far as the integration is concerned, We get}\nV(\\mathbf{r})&=\\frac{1}{4 \\pi \\epsilon_{0}} \\sum_{n=0}^{\\infty} \\frac{1}{r^{(n+1)}} \\int\\left(r^{\\prime}\\right)^{n} P_{n}(\\cos \\alpha) \\rho\\left(\\mathbf{r}^{\\prime}\\right) d \\tau^{\\prime}\n\\intertext{or, more explicitly,}\nV(\\mathbf{r})&=\\frac{1}{4 \\pi \\epsilon_{0}}\\left[  \\frac{1}{r} \\int \\rho\\left(\\mathbf{r}^{\\prime}\\right) d \\tau^{\\prime}+\\frac{1}{r^{2}} \\int r^{\\prime} \\cos \\alpha \\rho\\left(\\mathbf{r}^{\\prime}\\right) d \\tau^{\\prime}\\right.  \\\\\n&\\left.+\\frac{1}{r^{3}} \\int\\left(r^{\\prime}\\right)^{2}\\left(\\frac{3}{2} \\cos ^{2} \\alpha-\\frac{1}{2}\\right) \\rho\\left(\\mathbf{r}^{\\prime}\\right) d \\tau^{\\prime}+\\ldots\\right] \n\\end{align*}\nThis is the desired result-the multipole expansion of $V$ in powers of $1/r$.\\\\\\\\\n\\textbf{Monopole Term}\n\\begin{itemize}\n\t\\item The first term $(n=0)$ is the monopole contribution (it goes like $1 / r)$\n\\item\tOrdinarily, the multipole expansion is dominated (at large $r$ ) by the monopole term:\n\t$$\n\tV_{\\text {mon }}(\\mathbf{r})=\\frac{1}{4 \\pi \\epsilon_{0}} \\frac{Q}{r},\n\t$$\n\twhere $Q=\\int \\rho d \\tau$ is the total charge of the configuration.\n\\end{itemize}\n\\textbf{Dipole Term}\n\\begin{itemize}\n\t\\item The second $(n=1)$ is the dipole (it goes like $\\left.1 / r^{2}\\right)$\n\\end{itemize}\nIf the total charge is zero, the dominant term in the potential will be the dipole (unless it also vanishes):\n$$\nV_{\\mathrm{dip}}(\\mathbf{r})=\\frac{1}{4 \\pi \\epsilon_{0}} \\frac{1}{r^{2}} \\int r^{\\prime} \\cos \\alpha \\rho\\left(\\mathbf{r}^{\\prime}\\right) d \\tau^{\\prime} .\n$$\nSince $\\alpha$ is the angle between $\\mathbf{r}^{\\prime}$ and $\\mathbf{r}$ ,\n$$\nr^{\\prime} \\cos \\alpha=\\hat{\\mathbf{r}} \\cdot \\mathbf{r}^{\\prime},\n$$\nand the dipole potential can be written as:\n$$\nV_{\\text {dip }}(\\mathbf{r})=\\frac{1}{4 \\pi \\epsilon_{0}} \\frac{1}{r^{2}} \\hat{\\mathbf{r}} \\cdot \\int \\mathbf{r}^{\\prime} \\rho\\left(\\mathbf{r}^{\\prime}\\right) d \\tau^{\\prime} .\n$$\nThis integral (which does not depend on $\\mathbf{r}$ ) is called the dipole moment of the distribution:\n$$\n\\mathbf{p} \\equiv \\int \\mathbf{r}^{\\prime} \\rho\\left(\\mathbf{r}^{\\prime}\\right) d \\tau^{\\prime}\n$$\nand the dipole contribution to the potential simplifies to\n$$\nV_{\\text {dip }}(\\mathbf{r})=\\frac{1}{4 \\pi \\epsilon_{0}} \\frac{\\mathbf{p} \\cdot \\hat{\\mathbf{r}}}{r^{2}}\n$$\nThe dipole moment is determined by the geometry of the charge distribution.\\\\ Dipole moment of a collection of point charges is\n$$\n\\mathbf{p}=\\sum_{i=1}^{n} q_{i} \\mathbf{r}_{i}^{\\prime} .\n$$\n\\begin{note}\n\tThe third is quadrupole,the fourth octopole and so on. Remember that $\\alpha$ is the angle between $\\mathbf{r}$ and $\\mathbf{r}^{\\prime}$, so the integrals depend on the direction to the field point.\n\\end{note}\n\\section{Potential energy of a dipole placed in an external electric field}\nLet we put a dipole whose $-q$ and $+$ q respectively at $\\vec{r}$ and $(\\vec{r}+\\vec{d})$\nThe potential energy,\n\\begin{align*}\nU&=-q V(\\vec{r})+q V(\\vec{r}+\\vec{d})\\\\\nU&=-q V(r)+q V(r)+q d \\cdot \\vec{\\nabla} V(r)\\quad \\text{(using Taylor expansion)}\\\\\n&=q d \\cdot \\vec{\\nabla} V(r) \\\\\nU&=\\vec{p} \\cdot \\vec{\\nabla} V(r) \\\\\nU&=-\\vec{p} \\cdot \\vec{E}(r) \\quad(\\because E(r)=-\\nabla V(r))\n\\end{align*}\n\\subsection{Force and torque on a dipole placed in an electric field:}\n\\subsubsection{Force }\nWe know that,\n\\begin{align*}\n\\vec{F} &=-\\vec{\\nabla} U=\\nabla(\\vec{p} \\cdot \\vec{E}) \\\\\n&=(\\vec{p} \\cdot \\vec{\\nabla}) \\vec{E}+(\\vec{E} \\cdot \\vec{\\nabla}) \\vec{p}+\\vec{p} \\times(\\vec{\\nabla} \\times \\vec{E})+\\vec{E} \\times(\\vec{\\nabla} \\times \\vec{p}) \\\\\n&=(\\vec{p} \\cdot \\vec{\\nabla}) \\bar{E}+0+0+0\\\\\n\\text{For uniform } \\vec{E},\\\\\n\\vec{F}&=(\\vec{p} \\cdot \\vec{\\nabla}) \\vec{E}=0\n\\end{align*}\n\nthat means there have no translational motion.\n\\subsubsection{Torque}\nWe know the potential energy of the dipole due external electrie field is $u=\\vec{p} \\cdot \\vec{E}=p E \\cos \\theta$\nTherefore, the torque about its own centre is\n$$\n\\begin{aligned}\n&\\tau=-\\frac{d u}{d \\theta}=p E \\sin \\theta\\\\\n&\\text { Or, }\\\\\n&\\vec{\\tau}=\\vec{p} \\times \\vec{E}\n\\end{aligned}\n$$\n\\textbf{Torque on the dipole in non-uniform electric field :}\\\\\nThe torque on a small dipole about its own centre is still\n$$\n\\vec{\\tau}=\\vec{p} \\times \\vec{E}\n$$\nBut since there is a net force $\\vec{F}$ on the dipole.\nTherefore, an extra torque act on the dipole is $\\vec{r} \\times \\vec{F}$ about any other point.\nTherefore, totaltorque about any other point is $\\vec{\\tau}=\\vec{p} \\times \\vec{E}+\\vec{r} \\times \\vec{F}$\\\\\n\\textbf{Mutual potential energy between two coplanar dipoles:}\\\\\nLet consider two diple of dipole moment $\\vec{p}_{1}$ and $\\vec{p}_{2}$ lying on a single plane, $\\vec{r}_{21}$ is the position vector of dipole\n2 with respect to 1 . The electric field at the centre of dipole 2 is,\n\n\n\\begin{align*}\n\\vec{E}_{1}&=\\frac{1}{4 \\pi \\varepsilon_{0}}\\left[\\frac{3\\left(\\vec{p}_{1} \\cdot \\vec{r}_{21}\\right) \\vec{r}_{21}}{r_{21}^{5}}-\\frac{\\vec{p}_{1}}{r_{21}^{3}}\\right]\n\\intertext{The mutual potential energy,}\nU_{21}&=-\\vec{p}_{2} \\cdot \\vec{E}_{1}=-\\vec{p}_{1} \\cdot \\vec{E}_{2}\\\\&=\\frac{1}{4 \\pi \\varepsilon_{0}}\\left[\\frac{\\vec{p}_{1} \\cdot \\vec{p}_{2}}{r_{21}^{3}}-\\frac{3\\left(\\vec{p}_{1} \\cdot \\vec{r}_{21}\\right)\\left(\\vec{p}_{2} \\cdot \\vec{r}_{21}\\right)}{r_{21}^{5}}\\right]\n\\end{align*}\n\n\n\n \n\\newpage\n\\begin{abox}\n\tPractise Set-1\n\t\\end{abox}\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\n\t\\item  The electrostatic potential $V(x, y)$ in free space in a region where the charge density $\\rho$ is zero is given by $V(x, y)=4 e^{2 x}+f(x)-3 y^{2}$. Given that the $x$-component of the electric field $E_{x}$, and $V$ are zero at the origin, $f(x)$ is\n\t{\\exyear{ NET/JRF(JUNE-2011)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $3 x^{2}-4 e^{2 x}+8 x$\n\t\t\\task[\\textbf{B.}] $3 x^{2}-4 e^{2 x}+16 x$\n\t\t\\task[\\textbf{C.}] $4 e^{2 x}-8$\n\t\t\\task[\\textbf{D.}] $3 x^{2}-4 e^{2 x}$\n\t\\end{tasks}\n\t\\item A static, spherically symmetric charge distribution is given by $\\rho(r)=\\frac{A}{r} e^{-K r}$ where $A$ and $K$ are positive constants. The electrostatic potential corresponding to this charge distribution varies with $r$ as\n\t{\\exyear{NET/JRF(JUNE-2011)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $r e^{-K r}$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{r} e^{-K r}$\n\t\t\\task[\\textbf{C.}] $\\frac{1}{r^{2}} e^{-K r}$\n\t\t\\task[\\textbf{D.}] $\\frac{1}{r}\\left(1-e^{-K r}\\right)$\n\t\\end{tasks}\n\t\\item Charges $Q, Q$ and $-2 Q$ are placed on the vertices of an equilateral triangle $A B C$ of sides of length $a$, as shown in the figure. The dipole moment of this configuration of charges, irrespective of the choice of origin, is\n\t{\\exyear{NET/JRF(JUNE-2012)}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.5cm,width=4cm]{Electric potential 03}\n\t\t\\caption{}\n\t\t\\label{}\n\t\\end{figure}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $+2 a Q \\hat{i}$\n\t\t\\task[\\textbf{B.}] $+\\sqrt{3} a Q \\hat{j}$\n\t\t\\task[\\textbf{C.}] $-\\sqrt{3} a Q \\hat{j}$\n\t\t\\task[\\textbf{D.}] 0\n\t\\end{tasks}\n\t\\item  Four charges (two $+q$ and two $-q$ ) are kept fixed at the four vertices of a square of side $a$ as shown. At the point $P$ which is at a distance $R$ from the centre $(R>>a)$, the potential is proportional to\n\t{\\exyear{NET/JRF(DEC-2012)}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=4.2cm]{electric potential 04}\n\t\\end{figure}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $1 / R$\n\t\t\\task[\\textbf{B.}] $1 / R^{2}$\n\t\t\\task[\\textbf{C.}] $1 / R^{3}$\n\t\t\\task[\\textbf{D.}] $1 / R^{4}$\n\t\\end{tasks}\n\t\\item  A point charges $q$ of mass $m$ is kept at a distance $d$ below a grounded infinite conducting sheet which lies in the $x y$ - plane. For what value of $d$ will the charge remains stationary?\n\t{\\exyear{NET/JRF(DEC-2012)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $q / 4 \\sqrt{m g \\pi \\varepsilon_{0}}$\n\t\t\\task[\\textbf{B.}] $q / \\sqrt{m g \\pi \\varepsilon_{0}}$\n\t\t\\task[\\textbf{C.}] There is no finite value of $d$\n\t\t\\task[\\textbf{D.}]  $\\sqrt{m g \\pi \\varepsilon_{0}} / q$\n\t\\end{tasks}\n\t\\item A particle of charge $e$ and mass $m$ is located at the midpoint of the line joining two fixed collinear dipoles with unit charges as shown in the figure. (The particle is constrained to move only along the line joining the dipoles). Assuming that the length of the dipoles is much shorter than their separation, the natural frequency of oscillation of the particle is\n\t{\\exyear{NET/JRF(JUNE-2013)}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3.5cm,width=7cm]{electric potential 05}\n\t\\end{figure}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\sqrt{\\frac{6 e R^{2}}{\\pi \\varepsilon_{0} m d^{5}}}$\n\t\t\\task[\\textbf{B.}] $\\sqrt{\\frac{6 e R}{\\pi \\varepsilon_{0} m d^{4}}}$\n\t\t\\task[\\textbf{C.}]  $\\sqrt{\\frac{6 e d^{2}}{\\pi \\varepsilon_{0} m R^{5}}}$\n\t\t\\task[\\textbf{D.}] $\\sqrt{\\frac{6 e d}{\\pi \\varepsilon_{0} m R^{4}}}$\n\t\\end{tasks}\n\t\\item Consider an axially symmetric static charge distribution of the form,\n\t$$\n\t\\rho=\\rho_{0}\\left(\\frac{r_{0}}{r}\\right)^{2} e^{-r / r_{0}} \\cos ^{2} \\varphi\n\t$$\n\tThe radial component of the dipole moment due to this charge distribution is\n\t{\\exyear{NET/JRF(JUNE-2013)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $2 \\pi \\rho_{0} r_{0}^{4}$\n\t\t\\task[\\textbf{B.}] $\\pi \\rho_{0} r_{0}^{4}$\n\t\t\\task[\\textbf{C.}] $\\rho_{0} r_{0}^{4}$\n\t\t\\task[\\textbf{D.}] $\\pi \\rho_{0} r_{0}^{4} / 2$\n\t\\end{tasks}\n\t\\item A point charge $q$ is placed symmetrically at a distance $d$ from two perpendicularly placed grounded conducting infinite plates as shown in the figure. The net force on the charge (in units of $1 / 4 \\pi \\varepsilon_{0}$ ) is\n\t{\\exyear{NET/JRF(DEC-2013)}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.5cm,width=5cm]{electric potential 07}\n\t\\end{figure}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\frac{q^{2}}{8 d^{2}}(2 \\sqrt{2}-1)$ away from the corner\n\t\t\\task[\\textbf{B.}] $\\frac{q^{2}}{8 d^{2}}(2 \\sqrt{2}-1)$ towards the corner\n\t\t\\task[\\textbf{C.}] $\\frac{q^{2}}{2 \\sqrt{2} d^{2}}$ towards the corner\n\t\t\\task[\\textbf{D.}] $\\frac{3 q^{2}}{8 d^{2}}$ away from the corner\n\t\\end{tasks}\n\t\\item If the electrostatic potential $V(r, \\theta, \\phi)$ in a charge free region has the form $V(r, \\theta, \\phi)=f(r) \\cos \\theta$, then the functional form of $f(r)$ (in the following $a$ and $b$ are constants) is:\n\t{\\exyear{NET/JRF(DEC-2013)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $a r^{2}+\\frac{b}{r}$\n\t\t\\task[\\textbf{B.}] $a r+\\frac{b}{r^{2}}$\n\t\t\\task[\\textbf{C.}] $a r+\\frac{b}{r}$\n\t\t\\task[\\textbf{D.}] $a \\ln \\left(\\frac{r}{b}\\right)$\n\t\\end{tasks}\n\t\\item  Let four point charges $q,-q / 2, q$ and $-q / 2$ be placed at the vertices of a square of side $a$. Let another point charge $-q$ be placed at the centre of the square (see the figure).\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.5cm,width=5cm]{electric potential 09}\n\t\\end{figure}\n\tLet $V(r)$ be the electrostatic potential at a point $P$ at a distance $r>>a$ from the centre of the square. Then $V(2 r) / V(r)$ is\n\t{\\exyear{NET/JRF(DEC-2013)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 1\n\t\t\\task[\\textbf{B.}]  $\\frac{1}{2}$\n\t\t\\task[\\textbf{C.}] $\\frac{1}{4}$\n\t\t\\task[\\textbf{D.}] $\\frac{1}{8}$\n\t\\end{tasks}\n\t\\item If the electrostatic potential in spherical polar coordinates is\n\t$$\n\t\\varphi(r)=\\varphi_{0} e^{-r / r_{0}}\n\t$$\n\twhere $\\varphi_{0}$ and $r_{0}$ are constants, then the charge density at a distance $r=r_{0}$ will be\n\t{\\exyear{NET/JRF(JUNE-2014)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{\\varepsilon_{0} \\varphi_{0}}{e r_{0}^{2}}$\n\t\t\\task[\\textbf{B.}] $\\frac{e \\varepsilon_{0} \\varphi_{0}}{2 r_{0}^{2}}$\n\t\t\\task[\\textbf{C.}] $-\\frac{\\varepsilon_{0} \\varphi_{0}}{e r_{0}^{2}}$\n\t\t\\task[\\textbf{D.}] $-\\frac{2 e \\varepsilon_{0} \\varphi_{0}}{r_{0}^{2}}$\n\t\\end{tasks}\n\t\\item A charge $(-e)$ is placed in vacuum at the point $(d, 0,0)$, where $d>0 .$ The region $x \\leq 0$ is filled uniformly with a metal. The electric field at the point $\\left(\\frac{d}{2}, 0,0\\right)$ is\n\t{\\exyear{NET/JRF(JUNE-2014)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}]  $-\\frac{10 e}{9 \\pi \\varepsilon_{0} d^{2}}(1,0,0)$\n\t\t\\task[\\textbf{B.}]  $\\frac{10 e}{9 \\pi \\varepsilon_{0} d^{2}}(1,0,0)$\n\t\t\\task[\\textbf{C.}] $\\frac{e}{\\pi \\varepsilon_{0} d^{2}}(1,0,0)$\n\t\t\\task[\\textbf{D.}] $-\\frac{e}{\\pi \\varepsilon_{0} d^{2}}(1,0,0)$\n\t\\end{tasks}\n\\item A charged particle is at a distance $d$ from an infinite conducting plane maintained at zero potential. When released from rest, the particle reaches a speed $u$ at a distance $d / 2$ from the plane. At what distance from the plane will the particle reach the speed $2 u ?$\n{\\exyear{NET/JRF(JUNE-2014)}}\n\\begin{tasks}(4)\n\t\\task[\\textbf{A.}] $d / 6$\n\t\\task[\\textbf{B.}] $d / 3$\n\t\\task[\\textbf{C.}] $d / 4$\n\t\\task[\\textbf{D.}] $d / 5$\n\\end{tasks}\n\\item  The electrostatic lines of force due to a system of four point charges is sketched here. At large distance $r$, the leading asymptotic behaviour of the electrostatic potential is proportional to\n{\\exyear{NET/JRF(DEC-2014)}}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4.5cm,width=4cm]{electric potential 12}\n\\end{figure}\n\\begin{tasks}(4)\n\t\\task[\\textbf{A.}] $r$\n\t\\task[\\textbf{B.}] $r^{-1}$\n\t\\task[\\textbf{C.}] $r^{-2}$\n\t\\task[\\textbf{D.}] $r^{-3}$\n\\end{tasks}\n\\item A hollow metallic sphere of radius $a$, which is kept at a potential $V_{0}$ has a charge $Q$ at its centre. The potential at a point outside the sphere, at a distance $r$ from the centre, is\n{\\exyear{NET/JRF(DEC-2015)}}\n\\begin{tasks}(4)\n\t\\task[\\textbf{A.}] $V_{0}$\n\t\\task[\\textbf{B.}] $\\frac{Q}{4 \\pi \\in_{0} r}+\\frac{V_{0} a}{r}$\n\t\\task[\\textbf{C.}] $\\frac{Q}{4 \\pi \\in_{0} r}+\\frac{V_{0} a^{2}}{r^{2}}$\n\t\\task[\\textbf{D.}] $\\frac{V_{0} a}{r}$\n\\end{tasks}\n\\item Two uniformly charged insulating solid spheres $A$ and $B$, both of radius $a$, carry total charges $+Q$ and $-Q$, respectively. The spheres are placed touching each other as shown in the figure.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=2.5cm,width=4.7cm]{diagram-20211011(50)-crop}\n\\end{figure}\nIf the potential at the centre of the sphere $A$ is $V_{A}$ and that at the centre of $B$ is $V_{B}$ then the difference $V_{A}-V_{B}$ is\n{\\exyear{NET/JRF(DEC-2016)}}\n\\begin{tasks}(4)\n\t\\task[\\textbf{A.}] $\\frac{Q}{4 \\pi \\varepsilon_{0} a}$\n\t\\task[\\textbf{B.}] $\\frac{-Q}{2 \\pi \\varepsilon_{0} a}$\n\t\\task[\\textbf{C.}] $\\frac{Q}{2 \\pi \\varepsilon_{0} a}$\n\t\\task[\\textbf{D.}] $\\frac{-Q}{4 \\pi \\varepsilon_{0} a}$\n\\end{tasks}\n\\item Two long hollow co-axial conducting cylinders of radii $R_{1}$ and $R_{2}\\left(R_{1}<R_{2}\\right)$ are placed in vacuum as shown in the figure below.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=2.5cm,width=7.5cm]{electric potential 13}\n\\end{figure}\nThe inner cylinder carries a charge $+\\lambda$ per unit length and the outer cylinder carries a charge $-\\lambda$ per unit length. The electrostatic energy per unit length of this system is\n{\\exyear{NET/JRF(JUNE-2017)}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{\\lambda^{2}}{\\pi \\in_{0}} \\ln \\left(R_{2} / R_{1}\\right)$\n\t\\task[\\textbf{B.}] $\\frac{\\lambda^{2}}{4 \\pi \\epsilon_{0}}\\left(R_{2}^{2} / R_{1}^{2}\\right)$\n\t\\task[\\textbf{C.}] $\\frac{\\lambda^{2}}{4 \\pi \\epsilon_{0}} \\ln \\left(R_{2} / R_{1}\\right)$\n\t\\task[\\textbf{D.}] $\\frac{\\lambda^{2}}{2 \\pi \\epsilon_{0}} \\ln \\left(R_{2} / R_{1}\\right)$\n\\end{tasks}\n\\item Two point charges $+3 Q$ and $-Q$ are placed at $(0,0, d)$ and $(0,0,2 d)$ respectively, above an infinite grounded conducting sheet kept in the $x y$ - plane. At a point $(0,0, z)$, where $z>>d$, the electrostatic potential of this charge configuration would approximately be\n{\\exyear{NET/JRF(DEC-2017)}}\n\\begin{tasks}(4)\n\t\\task[\\textbf{A.}] $\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{d^{2}}{z^{3}} Q$\n\t\\task[\\textbf{B.}] $\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{2 d}{z^{2}} Q$\n\t\\task[\\textbf{C.}] $\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{3 d}{z^{2}} Q$\n\t\\task[\\textbf{D.}] $-\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{d^{2}}{z^{3}} Q$\n\\end{tasks}\n\\item  Two point charges $+2 Q$ and $-Q$ are kept at point with Cartesian coordinates $(1,0,0)$, respectively, in front of an infinite grounded conducting plate at $x=0$. The potential at $(x, 0,0)$ for $x \\gg 1$ depends on $x$ as\n{\\exyear{NET/JRF(JUNE-2018)}}\n\\begin{tasks}(4)\n\t\\task[\\textbf{A.}] $x^{-3}$\n\t\\task[\\textbf{B.}]  $x^{-5}$\n\t\\task[\\textbf{C.}] $x^{-2}$\n\t\\task[\\textbf{D.}] $x^{-4}$\n\\end{tasks}\n\\item An electric dipole of dipole moment $\\vec{P}=q b \\hat{i}$ is placed at origin in the vicinity of two charges $+q$ and $-q$ at $(L, b)$ and $(L,-b)$, respectively, as shown in the figure. The electrostatic potential at the point $\\left(\\frac{L}{2}, 0\\right)$ is\n{\\exyear{NET/JRF(DEC-2018)}}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm,width=5cm]{electric potential 15}\n\\end{figure}\n\\begin{tasks}(4)\n\t\\task[\\textbf{A.}] $\\frac{q b}{\\pi \\varepsilon_{0}}\\left(\\frac{1}{L^{2}}+\\frac{2}{L^{2}+4 b^{2}}\\right)$\n\t\\task[\\textbf{B.}] $\\frac{4 q b L}{\\pi \\varepsilon_{0}\\left[L^{2}+4 b^{2}\\right]^{3 / 2}}$\n\t\\task[\\textbf{C.}] $\\frac{q b}{\\pi \\varepsilon_{0} L^{2}}$\n\t\\task[\\textbf{D.}] $\\frac{3 q b}{\\pi \\varepsilon_{0} L^{2}}$\n\\end{tasks}\n\\end{enumerate}\n \\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{D} &2&\\textbf{B}\\\\\\hline \n\t\t3&\\textbf{C} &4&\\textbf{C} \\\\\\hline\n\t\t5&\\textbf{A} &6&\\textbf{D} \\\\\\hline\n\t\t7&\\textbf{A}&8&\\textbf{B}\\\\\\hline\n\t\t9&\\textbf{B}&10&\\textbf{D}\\\\\\hline\n\t\t11&\\textbf{A} &12&\\textbf{B}\\\\\\hline\n\t\t13&\\textbf{D}&14&\\textbf{D}\\\\\\hline\n\t\t15&\\textbf{D}&16&\\textbf{C}\\\\\\hline\n\t\t17&\\textbf{C} &18&\\textbf{B}\\\\\\hline \n\t\t19&\\textbf{A} &20&\\textbf{C} \\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\\newpage\n\\begin{abox}\n\tPractise Set-2\n\\end{abox}\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\n\\item An insulating sphere of radius $a$ carries a charge density\n$$\n\\rho(\\vec{r})=\\rho_{0}\\left(a^{2}-r^{2}\\right) \\cos \\theta ; r<a\n$$\nThe leading order term for the electric field at a distance $d$, far away from the charge distribution, is proportional to\n{\\exyear{GATE 2010}}\n\n\\begin{tasks}(4)\n\\task[\\textbf{A.}] $d^{-1}$\n\\task[\\textbf{B.}] $d^{-2}$\n\\task[\\textbf{C.}] $d^{-3}$\n\\task[\\textbf{D.}] $d^{-4}$\n\\end{tasks}\t\n\\item Two charges $q$ and $2 q$ are placed along the $x$ -axis in front of a grounded, infinite conducting plane, as shown in the figure. They are located respectively at a distance of $0.5 \\mathrm{~m}$ and $1.5 \\mathrm{~m}$ from the plane. The force acting on the charge $q$ is\n{\\exyear{GATE 2011}}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[height=4cm,width=7.5cm]{diagram-20210817(15)-crop}\n\\end{figure}\n\\begin{tasks}(4)\n\\task[\\textbf{A.}] $\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{7 q^{2}}{2}$\n\\task[\\textbf{B.}] $\\frac{1}{4 \\pi \\varepsilon_{0}} 2 q^{2}$\n\\task[\\textbf{C.}] $\\frac{1}{4 \\pi \\varepsilon_{0}} q^{2}$\n\\task[\\textbf{D.}] $\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{q^{2}}{2}$\n\\end{tasks}\n\\item A spherical conductor of radius $a$ is placed in a uniform electric field $\\vec{E}=E_{0} \\hat{k}$. The potential at a point $P(r, \\theta)$ for $r>a$, is given by\n$$\n\\Phi(r, \\theta)=\\text { constant }-E_{0} r \\cos \\theta+\\frac{E_{0} a^{3}}{r^{2}} \\cos \\theta\n$$\nwhere $r$ is the distance of $P$ from the centre $\\mathrm{O}$ of the sphere and $\\theta$ is the angle OP makes with the $z$ -axis The charge density on the sphere at $\\theta=30^{\\circ}$ is\n{\\exyear{GATE 2011}}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[height=4.2cm,width=5cm]{diagram-20210817(17)-crop}\n\\end{figure}\n\\begin{tasks}(4)\n\\task[\\textbf{A.}] $3 \\sqrt{3} \\varepsilon_{0} E_{0} / 2$\n\\task[\\textbf{B.}] $3 \\varepsilon_{0} E_{0} / 2$\n\\task[\\textbf{C.}] $\\sqrt{3} \\varepsilon_{0} E_{0} / 2$\n\\task[\\textbf{D.}] $\\varepsilon_{0} E_{0} / 2$\n\\end{tasks}\n\t\\item For a scalar function $\\varphi$ satisfying the Laplace equation, $\\vec{\\nabla} \\varphi$ has\n{\\exyear{GATE 2013}}\n\n\\begin{tasks}(2)\n\\task[\\textbf{A.}] Zero curl and non-zero divergence\n\\task[\\textbf{B.}] Non-zero curl and zero divergence\n\\task[\\textbf{C.}] Zero curl and zero divergence\n\\task[\\textbf{D.}]  Non-zero curl and non-zero divergence\n\\end{tasks}\n\\item A charge distribution has the charge density given by $\\rho=Q\\left\\{\\delta\\left(x-x_{0}\\right)-\\delta\\left(x+x_{0}\\right)\\right\\}$. For\nthis charge distribution the electric field at $\\left(2 x_{0}, 0,0\\right)$\n{\\exyear{GATE 2013}}\n\n\\begin{tasks}(4)\n\t\\task[\\textbf{A.}] $\\frac{2 Q \\hat{x}}{9 \\pi \\varepsilon_{0} x_{0}^{2}}$\n\t\\task[\\textbf{B.}] $\\frac{Q \\hat{x}}{4 \\pi \\varepsilon_{0} x_{0}^{3}}$\n\t\\task[\\textbf{C.}] $\\frac{Q \\hat{x}}{4 \\pi \\varepsilon_{0} x_{0}^{2}}$\n\t\\task[\\textbf{D.}] $\\frac{Q \\hat{x}}{16 \\pi \\varepsilon_{0} x_{0}^{2}}$\n\\end{tasks}\n\\item A charge $-q$ is distributed uniformly over a sphere, with a positive charge $q$ at its center in (i). Also in (ii), a charge $-q$ is distributed uniformly over an ellipsoid with a positive charge $q$ at its center. With respect to the origin of the coordinate system, which one of the following statements is correct?\n{\\exyear{GATE 2015}}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm,width=10cm]{diagram-20210818(7)-crop}\n\\end{figure}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}] The dipole moment is zero in both (i) and (ii)\n\t\\task[\\textbf{B.}] The dipole moment is non-zero in (i) but zero in (ii)\n\t\\task[\\textbf{C.}] The dipole moment is zero in (i) but non-zero in (ii)\n\t\\task[\\textbf{D.}] The dipole moment is non-zero in both (i) and (ii)\n\\end{tasks}\n\\item Identical charges $q$ are placed at five vertices of a regular hexagon of side $a$. The magnitude of the electric field and the electrostatic potential at the centre of the hexagon are respectively\n{\\exyear{GATE 2017}}\n\n\\begin{tasks}(4)\n\t\\task[\\textbf{A.}] 0,0\n\t\\task[\\textbf{B.}] $\\frac{q}{4 \\pi \\varepsilon_{0} a^{2}}, \\frac{q}{4 \\pi \\varepsilon_{0} a}$\n\t\\task[\\textbf{C.}] $\\frac{q}{4 \\pi \\varepsilon_{0} a^{2}}, \\frac{5 q}{4 \\pi \\varepsilon_{0} a}$\n\t\\task[\\textbf{D.}]  $\\frac{\\sqrt{5} q}{4 \\pi \\varepsilon_{0} a^{2}}, \\frac{\\sqrt{5} q}{4 \\pi \\varepsilon_{0} a}$\n\\end{tasks}\n\\item Three charges $(2 C,-1 C,-1 C)$ are placed at the vertices of an equilateral triangle of side $1 m$ as shown in the figure. The component of the electric dipole moment about the marked origin along the $\\hat{y}$ direction is-------$C m$.\n{\\exyear{GATE 2017}}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4.5cm,width=6cm]{diagram-20210818(11)-crop}\n\\end{figure}\n\t\\question Consider a system of three charges as shown in the figure below:\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4.5cm,width=7cm]{diagram-20210818(17)-crop}\n\\end{figure}\nFor $r=10 \\mathrm{~m} ; \\theta=60$ degrees; $q=10^{-6}$ Coulomb, and $d=10^{-3} \\mathrm{~m}$, the electric dipole potential in volts (rounded off to three decimal places) at a point $(r, \\theta)$ is--------- [Use: $\\left.\\frac{1}{4 \\pi \\in_{0}}=9 \\times 10^{9} \\frac{\\mathrm{Nm}^{2}}{C^{2}}\\right]$\n{\\exyear{GATE 2019}}\n\\end{enumerate}\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{C} &2&\\textbf{A}\\\\\\hline \n\t\t3&\\textbf{A} &4&\\textbf{C} \\\\\\hline\n\t\t5&\\textbf{A} &6&\\textbf{A} \\\\\\hline\n\t\t7&\\textbf{C}&8&\\textbf{1.73}\\\\\\hline\n\t\t9&\\textbf{0.045}&10&\\textbf{}\\\\\\hline\n\t\t11&\\textbf{} &12&\\textbf{}\\\\\\hline\n\t\t13&\\textbf{}&14&\\textbf{}\\\\\\hline\n\t\t15&\\textbf{}& &\\\\\\hline\n\t\t\n\t\\end{tabular}\n\\end{table}\n\\newpage \n\\begin{abox}\n\tPractise Set-3\n\\end{abox}\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\n\t\\item  Two charges $q$ and $-q$ are placed at $(a, 0,0)$ and $(-a, 0,0)$ respectively. Calculate electric field at $(0, a, 0)$ using electric potential.\n\t\\begin{answer}\n\t\tLet's  find potential at a general point\\ (x,y,0)\\\\\n\t\t\n\t\t\\centering\n\t\t\\includegraphics[width=0.35\\textwidth]{potential pset-3-1}\n\t\t\\begin{align*}\n\t\tV(x, y, 0) &=\\frac{q}{4 \\pi \\varepsilon_{0} \\sqrt{(x-a)^{2}+y^{2}}}-\\frac{q}{4 \\pi \\varepsilon_{0} \\sqrt{(x+a)^{2}+y^{2}}} \\\\\n\t\tV(x, y, 0) &=\\frac{q}{4 \\pi \\varepsilon_{0}}\\left[\\frac{1}{\\sqrt{(x-a)^{2}+y^{2}}}-\\frac{1}{\\sqrt{(x+a)^{2}+y^{2}}}\\right] \\\\\n\t\tE_{x} &=-\\left.\\frac{\\partial V}{\\partial x}\\right|_{x=0, y=a}\n\t\t\\\\&=-\\frac{q}{4 \\pi \\varepsilon_{0}}\\left[-\\frac{(x-a)}{\\left((x-a)^{2}+y^{2}\\right)^{3 / 2}}+\\frac{(x+a)}{\\left[(x+a)^{2}+y^{2}\\right]^{3 / 2}}\\right]_{x=0, y=a}\\\\\n\t\t&=-\\frac{q}{4 \\pi \\varepsilon_{0}}\\left[\\frac{a}{\\left(2 a^{2}\\right)^{3 / 2}}+\\frac{a}{(2 a)^{3 / 2}}\\right] \\\\\n\t\t&=-\\frac{q}{4 \\pi \\varepsilon_{0} a^{2}} \\cdot \\frac{1}{\\sqrt{2}}=\\frac{q}{4 \\sqrt{2} \\pi \\varepsilon_{0} a^{2}}\\\\\n\t\tE_{y} &=-\\frac{\\partial V}{\\partial y}=-\\frac{q}{4 \\pi \\varepsilon_{0}}\\left[-\\frac{y}{\\left[(x-a)^{2}+y^{2}\\right]^{3 / 2}}+\\left.\\frac{y}{\\left[(x+a)^{2}+y^{2}\\right]^{3 / 2}}\\right|_{x=0_{0}, y=a}\\right.\\\\\n\t\t&=-\\frac{q}{4 \\pi \\varepsilon_{0}}\\left[-\\frac{a}{\\left(2 a^{2}\\right)^{3 / 2}}+\\frac{a}{\\left(2 a^{2}\\right)^{3 / 2}}\\right]\\\\\n\t\tE_{y}&=0 \\\\\n\t\t\\vec{E}&=E_{x} \\hat{i}+E_{y} \\hat{j} \\Rightarrow \\vec{E}=-\\frac{q}{4 \\sqrt{2 }\\pi \\varepsilon_{0} a^{2}} \\hat{i}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item An infinite number of charges each equal to $q$ are placed along the $x$ -axis at $x=1, x=4, x=8, \\ldots .$ and so on.\n\tFind the potential at the point $x=0$ due to this set of charges.{ What will be potential if in the above set up the consecutive charge have opposite sign? }\n\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=0.38\\textwidth]{pset2-2}\n\t\t\\end{center}\n\t\\end{figure}\n\t\\begin{answer}\n\t\t(1) The potential at $x=0$ due to all charges is given by\n\t\t\n\t\t\\begin{align*}\n\t\tV &=\\frac{1}{4 \\pi \\varepsilon_{0} d}\\left(\\frac{q}{1}+\\frac{q}{2}+\\frac{q}{4}+\\frac{q}{8}+\\cdots+\\infty\\right) \\\\\n\t\t&=\\frac{q}{4 \\pi \\varepsilon_{0} d}\\left(1+\\frac{1}{2}+\\frac{1}{4}+\\frac{1}{8}+\\cdots+\\infty\\right) \\\\\n\t\t&=\\frac{q}{4 \\pi \\varepsilon_{0} d}\\left[\\frac{1-\\left(\\frac{1}{2}\\right)^{\\infty}}{1-\\left(\\frac{1}{2}\\right)}\\right]=\\frac{q}{4 \\pi \\varepsilon_{0} d}\\left[\\frac{1-0}{\\left(1/2\\right)}\\right]=\\frac{q}{2 \\pi \\varepsilon_{0} d}\n\t\t\\end{align*}\n\t\t(2)When the consecutive charges are negative, then\n\t\t\\begin{align*}\n\t\tV &=\\frac{1}{4 \\pi \\varepsilon_{0} d}\\left[\\frac{q}{1}-\\frac{q}{2}+\\frac{q}{4}-\\frac{q}{8}+\\frac{q}{16}-\\frac{q}{32}+\\cdots \\infty\\right] \\\\\n\t\t&=\\frac{1}{4 \\pi \\varepsilon_{0} d}\\left[\\left(\\frac{q}{1}+\\frac{q}{4}+\\frac{q}{16}+\\ldots \\infty\\right)=\\left(\\frac{q}{2}+\\frac{q}{8}+\\frac{q}{32}+\\cdots \\infty\\right)\\right] \\\\\n\t\t&=\\frac{q}{4 \\pi \\varepsilon_{0} d}\\left[\\left(1+\\frac{1}{4}+\\frac{1}{16}+\\cdots \\infty\\right)-\\left(\\frac{1}{2}+8-\\frac{1}{32}+\\cdots \\infty\\right)\\right] \\\\\n\t\t&=\\frac{q}{4 \\pi \\varepsilon_{0} d}\\left[\\left(\\frac{1}{1-\\left(\\frac{1}{4}\\right)}\\right)-\\frac{1}{2}\\left(\\frac{1}{1-\\left(\\frac{1}{4}\\right)}\\right)\\right] \\\\\n\t\t&=\\frac{q}{4 \\pi \\varepsilon_{0} d}\\left[\\frac{4}{3}-\\frac{2}{3}\\right]=\\frac{2 q}{4 \\pi \\varepsilon_{0} d \\times 3}=\\frac{q}{6 \\pi \\varepsilon_{0} d}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Find the potential and field along the axis of circular ring with uniform charge density $\\lambda$.\n\t\n\t\n\t\n\t\\opencutright\n\t\\renewcommand\\windowpagestuff{\n\t\t\\centering\\includegraphics[width=3.5cm]{potential pset-3-3}}\n\t\\begin{answer}\n\t\tLet consider as elementary length on the surface.\n\t\tTherefore, the potential at the point $\\mathrm{P}$ due to elementary length $d l$ is\n\t\t\\begin{cutout}{1}{\\dimexpr\\linewidth-6cm\\relax}{1pt}{1}\n\t\t\t\\begin{align*}\n\t\t\td \\phi&=\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{\\lambda d \\ell}{\\sqrt{z^{2}+a^{2}}} \\\\\n\t\t\t\\phi&=\\frac{\\lambda}{4 \\pi \\varepsilon_{0}} \\frac{1}{\\sqrt{z^{2}+a^{2}}} \\int d \\ell\\\\\n\t\t\t&=\\frac{\\lambda}{4 \\pi \\varepsilon_{0}} \\frac{2 \\pi a}{\\sqrt{z^{2}+a^{2}}}=\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{2 \\pi \\lambda a}{\\sqrt{z^{2}+a^{2}}}\\\\\n\t\t\t&\\vec{E}=-\\frac{d \\phi}{d z}=\\frac{1}{4 \\pi \\varepsilon_{0}} \\frac{2 \\pi a \\lambda z}{\\left(z^{2}+a^{2}\\right)^{3 / 2}} \\hat{z}\n\t\t\t\\end{align*}\n\t\t\\end{cutout}\n\t\t\n\t\\end{answer}\n\t\\item  Find the potential a distance $r$ from an infinitely long straight wire that carries a uniform line charge $\\lambda$.\n\t\\begin{answer}\n\t\tHere, $\\vec{E}=\\frac{\\lambda}{2 \\pi \\varepsilon_{0} r} \\hat{r} .$ \\\\In this case we cannot set the reference point at $\\infty$, since the charge\n\t\titself extends to $\\infty$. \\\\Let's set it at $r=a$\n\t\t\\\\Then $V(r)=-\\int_{a}^{r}\\left(\\frac{1}{2 \\pi \\varepsilon_{0}} \\frac{\\lambda}{r}\\right) d r=-\\frac{\\lambda}{2 \\pi \\varepsilon_{0}} \\ln \\left(\\frac{r}{a}\\right)$\n\t\\end{answer}\n\t\\item The electrostatic potential due to a charge distribution is given by $V(r)=A \\frac{e^{-\\lambda r}}{r}$, where $A$ and $\\lambda$ are constants. The total charge enclosed within a sphere of radius $1 / \\lambda$, with its origin at $r=0$ is given by,\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{8 \\pi \\varepsilon_{0} A}{e}$  \n\t\t\\task[\\textbf{b.}] $\\frac{4 \\pi \\varepsilon_{0} A}{e}$\n\t\t\\task[\\textbf{c.}]$\\frac{\\pi \\varepsilon_{0} A}{e}$ \n\t\t\\task[\\textbf{d.}]0 \n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\n\t\t\n\t\t\\begin{align*}\n\t\t\\text{We have, } V(r)&=\\frac{A e^{-\\lambda r}}{r}\\\\\n\t\tE&=-\\frac{d V}{d r}=-\\hat{r} \\frac{d}{d r}\\left[\\frac{e^{-\\lambda r}}{r}\\right] A=\\left[\\frac{\\lambda e^{-\\lambda r}}{r}+\\frac{e^{-\\lambda r}}{r^{2}}\\right] A \\hat{r}\\\\\n\t\t\\text{According}&\\text{ to Poisson's law,}\\\\\n\t\t\\vec{\\nabla} \\cdot \\vec{E}&=\\frac{\\rho}{\\varepsilon_{0}} \\\\\n\t\t\\Rightarrow \\quad \\rho&=\\varepsilon_{0} \\vec{\\nabla} \\cdot \\vec{E}=\\varepsilon_{0} \\nabla \\cdot\\left[\\frac{\\lambda e^{-\\lambda r}}{r^{2}} \\vec{r}+\\frac{e^{-\\lambda r}}{r^{3}} \\vec{r}\\right] A\\\\&=\\varepsilon_{0} \\lambda A \\nabla \\cdot\\left(\\frac{e^{-\\lambda r}}{r^{2}} \\vec{r}\\right)+\\varepsilon_{0} A \\nabla \\cdot\\left(\\frac{e^{-\\lambda r}}{r^{3}} \\vec{r}\\right) \\\\\n\t\t&=\\varepsilon_{0} \\lambda A e^{-\\lambda r}\\left(\\vec{\\nabla} \\cdot \\frac{\\vec{r}}{r^{2}}\\right)+\\frac{\\vec{r}}{r^{2}} \\varepsilon_{0} \\lambda A \\cdot\\left(\\nabla e^{-\\lambda r}\\right)+\\varepsilon_{0} A e^{-\\lambda r}\\left(\\vec{\\nabla} \\cdot \\frac{\\vec{r}}{r^{3}}\\right)\\\\&+\\left(A \\varepsilon_{0} \\frac{\\vec{r}}{r^{3}} \\cdot \\vec{\\nabla} e^{-\\lambda r}\\right) \\\\\n\t\t&=\\varepsilon_{0} \\lambda A e^{-\\lambda r} \\frac{1}{r^{2}}-A \\varepsilon_{0} \\lambda^{2} \\frac{1}{r} e^{-\\lambda r}+A \\varepsilon_{0} e^{-\\lambda r} 4 \\pi \\delta(r)-A \\varepsilon_{0} \\lambda \\frac{1}{r^{2}} e^{-\\lambda r}\\\\\n\t\t&=4 \\pi A \\varepsilon_{0}\\left[\\delta(r)-\\frac{\\lambda^{2}}{4 \\pi} \\frac{1}{r}\\right] e^{-\\lambda r} \\\\\n\t\tq&=4 \\pi A \\varepsilon_{0} \\int \\delta(r) e^{-\\lambda r} d V-\\frac{4 \\pi A \\varepsilon_{0} \\lambda^{2}}{4 \\pi} \\int_{r}^{1} e^{-\\lambda r} 4 \\pi r^{2} d r \\\\\n\t\t&=4 \\pi \\varepsilon_{0} A-4 \\pi \\varepsilon_{0} A \\int_{0}^{1} e^{-z} z d z \\\\\n\t\t&=4 \\pi \\varepsilon_{0} A-4 \\pi \\varepsilon_{0} A\\left[-e^{-z} z-e^{-z}\\right]_{0}^{1} \\\\\n\t\t&=4 \\pi \\varepsilon_{0} A-4 \\pi \\varepsilon_{0} A\\left[-e^{-1}-e^{-1}+1\\right]=\\frac{8 \\pi \\varepsilon_{0} A}{e}\n\t\t\\end{align*}\n\t\t\n\t\\end{answer}\n\t\\item The plates of a parallel plate capacitor (which are normal to the $x$ -axis) are located at $x=0$\n\tand $x=L .$ The plate at $x=0$ is grounded while the other plate is at a potential $V_{0} .$ The\n\tspace between the plates has uniform volume charge density $\\rho .$ The potential $V(x)$\n\tbetween the plates is given by\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$-\\frac{\\rho}{2 \\varepsilon_{0}} x^{2}+\\left(\\frac{V_{0}}{L}+\\frac{\\rho L}{2 \\varepsilon_{0}}\\right) x$  \n\t\t\\task[\\textbf{b.}] $\\frac{\\rho}{2 \\varepsilon_{0}} x^{2}-\\left(\\frac{V_{0}}{L}+\\frac{\\rho L}{2 \\varepsilon_{0}}\\right) x$\n\t\t\\task[\\textbf{c.}]$-\\frac{\\rho}{2 \\varepsilon_{0}} x^{2}-\\left(\\frac{V_{0}}{L}+\\frac{\\rho L}{2 \\varepsilon_{0}}\\right) x$ \n\t\t\\task[\\textbf{d.}]$\\frac{\\rho}{2 \\varepsilon_{0}} x^{2}+\\left(\\frac{V_{0}}{L}+\\frac{\\rho L}{2 \\varepsilon_{0}}\\right) x$\n\t\t\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\n\t\t\\begin{align*}\n\t\t\\intertext{ The Laplace's equation in Cartesian coordinates system is}\n\t\t\\nabla^{2} V&=\\frac{\\partial^{2} V}{\\partial x^{2}}=\\frac{\\partial^{2} V}{\\partial y^{2}}+\\frac{\\partial^{2} V}{\\partial z^{2}}=-\\frac{\\rho}{\\varepsilon_{0}}\n\t\t\\intertext{As $V$ is only function of $x$, we have the differential equation,} \n\t\t\\frac{d^{2} V}{d x^{2}}&=-\\frac{\\rho}{\\varepsilon_{0}}\n\t\t\\intertext{By integrating we have the solution of this equation as}\n\t\t\\frac{d V}{d x}&=-\\frac{\\rho}{\\varepsilon_{0}} x+A \\Rightarrow V(x)=-\\frac{\\rho}{2 \\varepsilon_{0}} x^{2}+A x+B \\quad \\text{Where $A$ and $B$ are constants.}\n\t\t\\intertext{The two equations need to be solved for the following boundary conditions:}\n\t\t\\intertext{(i) $x=0 ; V=0$\n\t\t\t(ii) $x=L ; V=V_{0}$}\n\t\t\\intertext{Substituting these boundary conditions, we get,}\n\t\t\\text { At } x&=0, V(0)=0=0+0+B \\Rightarrow B=0 \\\\\n\t\t\\text { At } x&=L, V(L)=V_{0}=-\\frac{\\rho}{2 \\varepsilon_{0}} L^{2}+A L \\Rightarrow A=\\frac{V_{0}}{L}+\\frac{\\rho L}{2 \\varepsilon_{0}}\\\\ \\Rightarrow V(x)&=-\\frac{\\rho}{2 \\varepsilon_{0}} x^{2}+\\left(\\frac{V_{0}}{L}+\\frac{\\rho L}{2 \\varepsilon_{0}}\\right) x\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item If the electrostatic potential in spherical polar coordinates is\n\t$$\n\t\\phi(r)=\\phi_{0} e^{-r / r_{0}}\n\t$$\n\twhere $\\phi_{0}$ and $r_{0}$ are constants, then the charge density at a distance $r=r_{0}$ will be\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}] $\\frac{\\varepsilon_{0} \\phi_{0}}{e r_{0}^{2}}$  \n\t\t\\task[\\textbf{b.}]$\\frac{e \\varepsilon_{0} \\phi_{0}}{2 r_{0}^{2}}$\n\t\t\\task[\\textbf{c.}]$-\\frac{\\varepsilon_{0} \\phi_{0}}{e r_{0}^{2}}$ \n\t\t\\task[\\textbf{d.}]$-\\frac{2 e \\varepsilon_{0} \\phi_{0}}{r_{0}^{2}}$ \n\t\\end{tasks}\n\t\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\because \\nabla^{2} \\phi&=-\\frac{\\rho}{\\varepsilon_{0}} \\Rightarrow \\rho=-\\varepsilon_{0}\\left(\\nabla^{2} \\phi\\right) \\\\\n\t\t\\nabla^{2} \\phi&=\\frac{1}{r^{2}} \\frac{\\partial}{\\partial r}\\left(r^{2} \\frac{\\partial \\phi}{\\partial r}\\right)\\\\\n\t\t&=\\frac{1}{r^{2}} \\frac{\\partial}{\\partial r}\\left(r^{2} \\times-\\frac{\\phi_{0}}{r_{0}} e^{-r / r_{0}}\\right)\\\\&=-\\frac{1}{r^{2}} \\frac{\\phi_{0}}{r_{0}} \\frac{\\partial}{\\partial r}\\left(r^{2} \\times e^{-r / r_{0}}\\right) \\\\\n\t\t&=-\\frac{1}{r^{2}} \\frac{\\phi_{0}}{r_{0}}\\left[r^{2} \\times-\\frac{1}{r_{0}} e^{-r / r_{0}}+2 r e^{-r / r_{0}}\\right] \\\\\\Rightarrow \\nabla^{2} \\phi&=-\\frac{\\phi_{0}}{r_{0}}\\left[-\\frac{1}{r_{0}} e^{-r / r_{0}}+\\frac{2}{r} e^{-r / r_{0}}\\right] \\\\\n\t\t\\text { At a distance } r&=r_{0}\\\\ \\nabla^{2} \\phi&=-\\frac{\\phi_{0}}{r_{0}}\\left[\\frac{1}{r_{0}} e^{-1}+\\frac{2}{r_{0}} e^{-1}\\right]=-\\frac{\\phi_{0}}{r_{0}^{2} e} \\\\\\Rightarrow \\rho&=-\\varepsilon_{0}\\left(-\\frac{\\phi_{0}}{r_{0}^{2} e}\\right)=\\frac{\\phi_{0} \\varepsilon_{0}}{r_{0}^{2} e}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A particle of mass $40 \\mathrm{mg}$ and carrying a charge $5 \\times 10^{-9} \\mathrm{C}$ is moving directly towards a fixed positive point charge of magnitude $10^{-8} \\mathrm{C} .$ When it is at a distance of $10 \\mathrm{~cm}$ from the fixed positive point charge it has a velocity of $50 \\mathrm{~cm} \\mathrm{sec}^{-1}$. At what distance from the fixed point charge will the particle come momentarily to rest? Is the acceleration constant during motion?\n\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=0.25\\textwidth]{pset-3-8}\n\t\t\\end{center}\n\t\\end{figure}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{Use conservation of energy} (K.E. + P.E.) _{\\text {initial }}&=(\\mathrm{K.E.}+\\mathrm{P.E.})_{\\text {final }}\\\\\n\t\t\\frac{1}{2} \\times 40 \\times 10^{-6} \\times(0.5)^{2}+\\frac{10^{-8} \\times 5 \\times 9 \\times 10^{9}}{\\left(\\frac{1}{10}\\right)}&=0+\\frac{10^{-8} \\times 5 \\times 10^{-9} \\times 9 \\times 10^{9}}{x}\\\\\n\t\t\\text{Solving we get }r&=4.737 \\times 10^{-2} \\mathrm{~m}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\t\\item \t A \"pure\" dipole $\\vec{p}$ is situated at the origin, pointing in the $z$ -direction\n\t\\\\(a) What is the force on a point charge $q$ at $(a, 0,0)$ ?\n\t\\\\(b) What is the force on $q$ at $(0,0, a)$ ?\n\t\\\\(c) How much work does it take to move $q$ from $(a, 0,0)$ to $(0,0, a)$ ?\n\t\\begin{answer}\\hspace{0.5cm}\n\t\t\\begin{enumerate}\n\t\t\t\\item \\begin{align*}\n\t\t\tA t(a, 0,0), r&=a, \\theta=\\frac{\\pi}{2} ; \\\\\\vec{E}&=\\frac{p}{4 \\pi \\varepsilon_{0} r^{3}}(2 \\cos \\theta \\hat{r}+\\sin \\theta \\hat{\\theta})=\\frac{p}{4 \\pi \\varepsilon_{0} a^{3}} \\hat{\\theta} \\\\\n\t\t\t\\vec{E}&=-\\frac{p}{4 \\pi \\varepsilon_{0} a^{3}} \\hat{z} \\Rightarrow \\vec{F}=q \\vec{E}=-\\frac{p q}{4 \\pi \\varepsilon_{0} a^{3}} \\hat{z}\n\t\t\t\\end{align*}\n\t\t\t\\item \\begin{align*}\n\t\t\tA t(0,0, a), r&=a, \\theta=0 ;\\\\ \\vec{E}&=\\frac{p}{4 \\pi \\varepsilon_{0} r^{3}}(2 \\cos \\theta \\hat{r}+\\sin \\theta \\hat{\\theta})=\\frac{2 p}{4 \\pi \\varepsilon_{0} a^{3}} \\hat{r} \\\\\n\t\t\t\\vec{E}&=\\frac{2 p}{4 \\pi \\varepsilon_{0} a^{3}} \\hat{z} \\Rightarrow \\vec{F}=q \\vec{E}=\\frac{2 p q}{4 \\pi \\varepsilon_{0} a^{3}} \\hat{z}\n\t\t\t\\end{align*}\n\t\t\t\\item \\begin{align*}\n\t\t\tV_{d i p}(r, \\theta)&=\\frac{p \\cos \\theta}{4 \\pi \\varepsilon_{o} r^{2}} \\Rightarrow V(a, 0,0)=0 \\text { and } V(0,0, a)=\\frac{p}{4 \\pi \\varepsilon_{o} a^{2}}, \\\\\n\t\t\tW&=q[V(0,0, a)-V(a, 0,0)]=\\frac{p}{4 \\pi \\varepsilon_{o} a^{2}}\n\t\t\t\\end{align*}\n\t\t\\end{enumerate}\n\t\t\n\t\\end{answer}\n\\item The electric field at a point due to an electric dipole is perpendicular to the dipole axis, the\nangle between the dipole axis and the line joining the point with the centre of the dipole\nis $\\tan ^{-1}(\\beta)$. Then the value of $\\beta$ is $\\ldots \\ldots$.\n\\begin{answer}\n\t\n\t\n\t\\begin{align*}\n\t\\vec{E}(r, \\theta)&=\\frac{p}{4 \\pi \\varepsilon_{0} r^{3}}(2 \\cos \\theta \\hat{r}+\\sin \\theta \\hat{\\theta}) \\\\\n\t\\tan \\alpha&=\\frac{E_{\\theta}}{E_{r}}=\\frac{1}{2} \\tan \\theta \\quad \\because \\alpha=90-\\theta \\Rightarrow \\cot \\theta=\\frac{1}{2} \\tan \\theta \\\\\n\t\\Rightarrow \\tan ^{2} \\theta&=2 \\Rightarrow \\theta=\\tan ^{-1} \\sqrt{2}\n\t\\end{align*}\n\t\n\\end{answer}\n\\item Let four point charges $q,-q / 2, q$ and $-q / 2$ be placed at the vertices of a square of\nside $a$. Let another point charge $-q$ be placed at the cnetre of the square (see the figure).\nLet $V(r)$ be the electrostatic potential at a point $P$ at a distance $r \\gg a$ from the centre of\nthe square. Then $V(3 r) / V(r)$ is.....................\n\\begin{answer} the monopole moment,\\\\\n\t$Q_{\\text {mono }}=-\\frac{q}{2}+q-\\frac{q}{2}+q-q=0$\n\t\\begin{align*}\n\t\\vec{p}&=q(a \\hat{x}+a \\hat{y})-\\frac{q}{2}(a \\hat{x}+a \\hat{y})-q(a \\hat{x}-a \\hat{y})+q(-a \\hat{x}-a \\hat{y})-\\frac{q}{2}(-a \\hat{x}+a \\hat{y})+0=0 \\\\\n\t\\text { Thus } V &\\propto \\frac{1}{r^{3}} \\Rightarrow \\frac{V(3 r)}{V(r)}=\\frac{1}{27}=0.037\n\t\\end{align*}\n\t\n\\end{answer}\n\\item A \"pure\" dipole with dipole moment $\\vec{p}=p_{o} \\hat{z}$ is situated at the origin. A point charge $Q$ is\nmoved from the point $(\\mathrm{a}, 0,0)$ to $(0,0, \\mathrm{a})$ then the work done will be,\n\\begin{tasks}(4)\n\t\\task[\\textbf{a.}]  zero. \n\t\\task[\\textbf{b.}]$\\frac{p_{0} Q}{4 \\pi \\varepsilon_{0} a^{3}}$\n\t\\task[\\textbf{c.}] $\\frac{p_{0}}{4 \\pi \\varepsilon_{0} a^{2}}$\n\t\\task[\\textbf{d.}] $\\frac{p_{0} Q}{4 \\pi \\varepsilon_{0} a^{2}}$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\tW&=Q[V(0,0, a)-V(a, 0,0)]\\\\\n\tV(r, \\theta)&=\\frac{p_{0} \\cos \\theta}{4 \\pi \\varepsilon_{0} r^{2}}\\\\ \\Rightarrow V(0,0, a)&=\\frac{p_{0}}{4 \\pi \\varepsilon_{0} a^{2}} \\quad \\because \\theta=0 \\text { and } V(a, 0,0)=0 \\quad \\because \\theta=\\frac{\\pi}{2}\\\\\n\t\\Rightarrow W&=\\frac{p_{0} Q}{4 \\pi \\varepsilon_{0} a^{2}}\n\t\\end{align*}\n\t\n\\end{answer}\n\n\\end{enumerate}\n", "meta": {"hexsha": "5eade3a074e6c5e8d2c3217a0445b0c7696119d7", "size": 89061, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Electrodynamics- CSIR/chapter/Electric potential.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Electrodynamics- CSIR/chapter/Electric potential.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Electrodynamics- CSIR/chapter/Electric potential.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.0201954397, "max_line_length": 910, "alphanum_fraction": 0.6467365064, "num_tokens": 34530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727026, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7012345083751585}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{tikz}\n\\usepackage{hyperref}\n\\usepackage{enumitem}\n\n\\newcommand{\\f}[1]{o_{#1}x_{#1}y_{#1}z_{#1}}\n\\newcommand{\\fromslides}{{\\\\ \\color{blue} \\hspace*{\\fill}(from lecture slides)} \\\\}\n\\newcommand{\\bydefn}{{\\\\ \\color{blue} \\hspace*{\\fill}(by definition)} \\\\}\n\\newcommand{\\given}{{\\\\ \\color{blue} \\hspace*{\\fill}(given)} \\\\}\n\n\\newcommand{\\rx}[1]{\\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & cos(#1) & -sin(#1) \\\\ 0 & sin(#1) & cos(#1) \\end{bmatrix}}\n\\newcommand{\\ry}[1]{\\begin{bmatrix} cos(#1) & 0 & sin(#1) \\\\ 0 & 1 & 0 \\\\ -sin(#1) & 0 & cos(#1) \\end{bmatrix}}\n\\newcommand{\\rz}[1]{\\begin{bmatrix} cos(#1) & -sin(#1) & 0 \\\\ sin(#1) & cos(#1) & 0 \\\\ 0 & 0 & 1 \\end{bmatrix}}\n\n\\title{CSci 5551 - HW1}\n\\author{Yashasvi Sriram Patkuri\\\\patku001@umn.edu}\n\n\\begin{document}\n\\maketitle\n\\pagebreak\n\n%--------------------------------------------------------------------------------\n\\section{}\nLet $ \\f{\\frac{1}{2}} $ represent the coordinate system formed by rotating $ \\f{0} $ by $ \\frac{\\pi}{2} $ radians about the x-axis.\nLet this rotation be denoted by $ R_1 $. Using basic matrices\n\\begin{equation}\n  R_1 \\equiv \\rx{\\frac{\\pi}{2}} \\equiv \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 0 & -1 \\\\ 0 & 1 & 0 \\end{bmatrix}\n\\end{equation}\n\\fromslides\n\n$ \\f{1} $ represents the coordinate system formed by rotating $ \\f{\\frac{1}{2}} $ by$ \\frac{\\pi}{2} $ radians about the fixed frame Y-axis.\nLet this rotation be denoted by $ R_2 $. Using basic matrices\n\\begin{equation}\n  R_2 \\equiv \\ry{\\frac{\\pi}{2}} \\equiv \\begin{bmatrix} 0 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ -1 & 0 & 0 \\end{bmatrix}\n\\end{equation}\n\\fromslides\n\nFor two consecutive fixed frame rotations denoted by $ R_1, R_2 $ rotation matrices, the composite rotation matrix, say R $ \\equiv $ $ R_2 * R_1 $\n\n\\begin{equation}\n  R\n  \\equiv R_2 * R_1\n  \\equiv \\begin{bmatrix} 0 & 0 & 1 \\\\ 0 & 1 & 0 \\\\ -1 & 0 & 0 \\end{bmatrix} * \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 0 & -1 \\\\ 0 & 1 & 0 \\end{bmatrix}\n  \\equiv \\begin{bmatrix} 0 & 1 & 0 \\\\ 0 & 0 & -1 \\\\ -1 & 0 & 0 \\end{bmatrix}\n\\end{equation}\n\\fromslides\n\n\nThe sketches of frames $ \\f{1} $, $ \\f{\\frac{1}{2}} $ and $ \\f{1} $ are drawn in figure \\ref{fig:q1}.\n\n\\begin{figure}[htpb]\n  \\centering\n  \\begin{tikzpicture}[x=1cm, y=1cm, z=-0.6cm]\n      \\draw [->] (0,0,0) -- (4,0,0) node [right] {$x_0$};\n      \\draw [->] (0,0,0) -- (0,4,0) node [left] {$y_0$};\n      \\draw [->] (0,0,0) -- (0,0,4) node [left] {$z_0$};\n  \\end{tikzpicture}\n\n  \\begin{tikzpicture}[x=1cm, y=1cm, z=-0.6cm]\n      \\draw [->] (0,0,0) -- (4,0,0) node [right] {$x_{\\frac{1}{2}}$};\n      \\draw [->] (0,0,0) -- (0,0,4) node [left] {$y_{\\frac{1}{2}}$};\n      \\draw [->] (0,0,0) -- (0,-4,0) node [left] {$z_{\\frac{1}{2}}$};\n  \\end{tikzpicture}\n\n  \\begin{tikzpicture}[x=1cm, y=1cm, z=-0.6cm]\n      \\draw [->] (0,0,0) -- (0,0,-4) node [left] {$x_1$};\n      \\draw [->] (0,0,0) -- (4,0,0) node [right] {$y_1$};\n      \\draw [->] (0,0,0) -- (0,-4,0) node [left] {$z_1$};\n  \\end{tikzpicture}\n\\caption{Rotations by $ \\frac{\\pi}{2} $ radians about fixed X and Y axes consecutively}\n  \\label{fig:q1}\n\\end{figure}\n\n\\pagebreak\n\n%--------------------------------------------------------------------------------\n\\section{}\n\nGiven\n\\begin{equation}\n  R_{12} \\equiv \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & \\frac{1}{2} & -\\frac{\\sqrt{3}}{2} \\\\ 0 & \\frac{\\sqrt{3}}{2} & \\frac{1}{2} \\end{bmatrix}\n\\end{equation}\n\\begin{equation}\n  R_{13} \\equiv \\begin{bmatrix} 0 & 0 & -1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 0 \\end{bmatrix}\n\\end{equation}\n\nFor any physical vector p, let $ p^{i} $ be its representation in ith coordinate system\n\\begin{equation}\n  \\label{eq:21}\n  p^{2} \\equiv R_{21} * p^{1}\n\\end{equation}\n\\begin{equation}\n  \\label{eq:22}\n  p^{1} \\equiv R_{13} * p^{3}\n\\end{equation}\n\\bydefn\n\nIdentities \\ref{eq:21} and \\ref{eq:22} imply\n\\begin{equation}\n  \\label{eq:23}\n  p^{2} \\equiv R_{21} * R_{13} * p^{3}\n\\end{equation}\n\nBut\n\\begin{equation}\n  \\label{eq:24}\n  p^{2} \\equiv R_{23} * p^{3}\n\\end{equation}\n\\bydefn\n\nFrom identities \\ref{eq:23} and \\ref{eq:24}\n\\begin{equation}\n  \\label{eq:25}\n  R_{23} \\equiv R_{21} * R_{13}\n\\end{equation}\n\nBut\n\\begin{equation}\n  \\label{eq:26}\n  R_{21} \\equiv R_{12}^{T}\n\\end{equation}\n\\fromslides\n\nIdentities \\ref{eq:25} and \\ref{eq:26} imply\n\\begin{equation}\n  \\label{eq:27}\n  R_{23} \\equiv R_{12}^T * R_{13}\n  \\equiv \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & \\frac{1}{2} & \\frac{\\sqrt{3}}{2} \\\\ 0 & -\\frac{\\sqrt{3}}{2} & \\frac{1}{2} \\end{bmatrix} * \\begin{bmatrix} 0 & 0 & -1 \\\\ 0 & 1 & 0 \\\\ 1 & 0 & 0 \\end{bmatrix}\n  \\equiv \\begin{bmatrix} 0 & 0 & -1 \\\\ \\frac{\\sqrt{3}}{2} & \\frac{1}{2} & 0 \\\\ \\frac{1}{2} & -\\frac{\\sqrt{3}}{2} & 0 \\end{bmatrix}\n\\end{equation}\n\n\\pagebreak\n\n%--------------------------------------------------------------------------------\n\\section{}\n\nLet us represent the Z-X-Z angles by $ \\theta_1, \\theta_2, \\theta_3 $ instead of $ \\phi, \\theta, \\psi $ respectively for simplicity.\n\nFirst we build rotation matrix corresponding to each Eular angle.\nUsing basic rotation matrices we get\n\\begin{equation}\n  \\label{eq:31}\n  R_{\\theta_1,z} \\equiv \\rz{\\theta_1}\n\\end{equation}\n\\begin{equation}\n  \\label{eq:32}\n  R_{\\theta_2,x} \\equiv \\rx{\\theta_2}\n\\end{equation}\n\\begin{equation}\n  \\label{eq:33}\n  R_{\\theta_3,z} \\equiv \\rz{\\theta_3}\n\\end{equation}\n\nEular angles correspond to consecutive current frame rotations.\nFor consecutive current frame rotations $ R_1, R_2, R_3 $, the composite rotation matrix is say R is given by\n\\begin{equation}\n  \\label{eq:34}\n  R \\equiv R_1 * R_2 * R_3\n\\end{equation}\n\\fromslides\n\nSubstituting equations \\ref{eq:31}, \\ref{eq:32}, \\ref{eq:33} in \\ref{eq:34} we get,\n\\begin{equation}\n  \\label{eq:35}\n  R_{ZXZ} \\equiv R_{\\theta_1,z} * R_{\\theta_2,x} * R_{\\theta_3,z}\n\\end{equation}\nwhere $ R_{ZXZ} $ represents rotation matrix corresponding to the set of Z-X-Z eular angles.\n\n\\[\n  R_{ZXZ} \\equiv \\rz{\\theta_1} * \\rx{\\theta_2} * \\rz{\\theta_3}\n\\]\n\\[\n  R_{ZXZ} \\equiv \\begin{bmatrix} c1 & -s1.c2 & s1.s2 \\\\ s1 & c1.c2 & -c1.s2 \\\\ 0 & s2 & c2 \\end{bmatrix} * \\rz{\\theta_3}\n\\]\nWhere ci represents $ cos(\\theta_i) $ and si represents $ sin(\\theta_i) $\n\\begin{equation}\n  \\label{eq:36}\n  R_{ZXZ} \\equiv \\begin{bmatrix} c1.c3 - s1.c2.s3 & -c1.s3 - s1.c2.c3 & s1.s2 \\\\ s1.c3 + c1.c2.s3 & -s1.s3 + c1.c2.c3 & -c1.s2 \\\\ s2.s3 & s2.c3 & c2 \\end{bmatrix}\n\\end{equation}\n\nEquation \\ref{eq:36} is the rotation matrix corresponding to Z-X-Z Eular angles.\n\n\\subsection{$sin(\\theta) = 0$}\nFor us $\\theta_2$ represents $\\theta$.\n$sin(\\theta_2) = 0$ implies $cos(\\theta_2) = 1$. Substituting these in equation \\ref{eq:36} we get\n\\begin{equation}\n  \\label{eq:37}\n  R_{ZXZ} \\equiv \\begin{bmatrix} c1.c3 - s1.s3 & -c1.s3 - s1.c3 & 0 \\\\ s1.c3 + c1.s3 & -s1.s3 + c1.c3 & 0 \\\\ 0 & 0 & 1 \\end{bmatrix}\n\\end{equation}\nBut\n\\begin{equation}\n  \\label{eq:38}\n  sin(a + b) = sin(a)cos(b) + cos(a)sin(b)\n\\end{equation}\n\\begin{equation}\n  \\label{eq:39}\n  cos(a + b) = cos(a)cos(b) - sin(a)sin(b)\n\\end{equation}\n\nFrom equations \\ref{eq:37}, \\ref{eq:38} and \\ref{eq:39} we can write\n\\begin{equation}\n  \\label{eq:310}\n  R_{ZXZ} \\equiv \\rz{\\theta_1 + \\theta_3}\n\\end{equation}\nTherefore, when $sin(\\theta) = 0$ the composite rotation matrix is identical to rotation about Z-axis by $ \\theta_1 + \\theta_3 $.\nThis is an example of a gimbal lock.\n\n\\pagebreak\n\n%--------------------------------------------------------------------------------\n\\section{}\n\\subsection{}\nThe general form of a transformation matrix is\n\\[\n  H_{y}^{x} \\equiv \\begin{bmatrix} R_{y}^{x} & p_{y}^{x} \\\\ O_{1x3} & 1 \\end{bmatrix}\n\\]\nWhere\n\\begin{enumerate}[nolistsep]\n  \\item $ R_{y}^{x} $ represents rotation matrix of coordinate system y w.r.t coordinate system x\n  \\item $ p_{y}^{x} $ represents position vector of origin of coordinate system y in coordinate system x\n  \\item $ O_{1x3} $ represents a 1x3 zero matrix\n\\end{enumerate}\n\\bydefn\n\nAs there is no rotation b/w coordinate systems 1 and 0 and 2 and 0, the rotation matrices $ R_{1}^{0}, R_{2}^{0} \\equiv I_{3x3} $ where $ I_{3x3} $ represents identity matrix of order 3. Therefore to calculate $ H_{1}^{0}, H_{2}^{0} $ we only need $ p_{1}^{0}, p_{2}^{0} $.\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.8\\textwidth]{p4-fig.png}\n  \\caption{Arrangement of coordinate systems 0, 1, 2, 3}\n  \\label{fig:p4}\n\\end{figure}\n\nIn coordinate system 0, the origin $ p_{1} $ of coordinate system 1 has\n\\begin{enumerate}[nolistsep]\n  \\item x-coordinate = 0, because it is in YZ plane (assumed from figure \\ref{fig:p4})\n  \\item y-coordinate = 1, because it lies on nearest leg of the table which is 1m far from the origin of 0 in y direction.\n  \\item z-coordinate = 1, because it lies on table top which is 1m far from the origin of 0 in the z direction.\n\\end{enumerate}\nTherefore\n\\[\n  p_{1}^{0} \\equiv \\begin{bmatrix} 0 \\\\ 1 \\\\ 1 \\end{bmatrix}\n\\]\nWhich implies\n\\[\n  H_{1}^{0}\n  \\equiv \\begin{bmatrix} I_{3x3} & \\begin{bmatrix} 0 \\\\ 1 \\\\ 1 \\end{bmatrix} \\\\ O_{1x3} & 1 \\end{bmatrix}\n  \\equiv \\begin{bmatrix}\n          1 & 0 & 0 & 0\\\\\n          0 & 1 & 0 & 1\\\\\n          0 & 0 & 1 & 1\\\\\n          0 & 0 & 0 & 1\n        \\end{bmatrix}\n\\]\n\nIn coordinate system 0, the origin $ p_{2} $ of coordinate system 2 has\n\\begin{enumerate}[nolistsep]\n  \\item x-coordinate = -0.5, because it is at the center of cube which is at the center of table top. Distance from origin of 0 to center of table to is 0.5m in the opposite direction of x-axis and hence the coordinate value.\n  \\item y-coordinate = 1.5, because it is at the center of cube which is at the center of table top. Distance from origin of 0 to center of table to is 1.5m in the direction of y-axis and hence the coordinate value.\n  \\item z-coordinate = 1.1, because it is at the center of cube which is at the center of table top. Distance from origin of 0 to table top in z-direction is 1m. But the origin of 2 is at center of cube of width 0.2m. This adds a (0.2 / 2)m height and hence the coordinate value 1 + 0.1 = 1.1\n\\end{enumerate}\nTherefore\n\\[\n  p_{2}^{0} \\equiv \\begin{bmatrix} -0.5 \\\\ 1.5 \\\\ 1.1 \\end{bmatrix}\n\\]\nWhich implies\n\\[\n  H_{2}^{0}\n  \\equiv \\begin{bmatrix} I_{3x3} & \\begin{bmatrix} -0.5 \\\\ 1.5 \\\\ 1.1 \\end{bmatrix} \\\\ O_{1x3} & 1 \\end{bmatrix}\n  \\equiv \\begin{bmatrix}\n          1 & 0 & 0 & -0.5\\\\\n          0 & 1 & 0 & 1.5\\\\\n          0 & 0 & 1 & 1.1\\\\\n          0 & 0 & 0 & 1\n        \\end{bmatrix}\n\\]\n\nIn coordinate system 0, the origin $ p_{3} $ of coordinate system 3 has same x and y coordinates as $ p_{2}^{0} $ because the camera (the coordinate system 3 attached to it) is situated directly above center of cube 2m from table top.\n\\given\n\\begin{enumerate}[nolistsep]\n  \\item x-coordinate = -0.5\n  \\item y-coordinate = 1.5\n  \\item z-coordinate = 3, because it is 2m above the table top i.e. 1+2m above the ground\n\\end{enumerate}\nTherefore\n\\[\n  p_{1}^{0} \\equiv \\begin{bmatrix} -0.5 \\\\ 1.5 \\\\ 3 \\end{bmatrix}\n\\]\nCoordinate system 3 is rotated w.r.t coordinate system 0, therefore $ R_{3}^{0} \\not\\equiv I_{3x3} $.\n\\[\n  R_{3}^{0}\n  \\equiv \\begin{bmatrix}\n        i_3.i_0 & j_3.i_0 & k_3.i_0\\\\\n        i_3.j_0 & j_3.j_0 & k_3.j_0\\\\\n        i_3.k_0 & j_3.k_0 & k_3.k_0\\\\\n        \\end{bmatrix}\n  \\equiv \\begin{bmatrix}\n        0 & 1 & 0\\\\\n        1 & 0 & 0\\\\\n        0 & 0 & -1\\\\\n        \\end{bmatrix}\n\\]\n\\fromslides\n\nWhich implies\n\\[\n  H_{3}^{0}\n  \\equiv \\begin{bmatrix} I_{3x3} & \\begin{bmatrix} 0 \\\\ 1 \\\\ 1 \\end{bmatrix} \\\\ O_{1x3} & 1 \\end{bmatrix}\n  \\equiv \\begin{bmatrix}\n          0 & 1 & 0 & -0.5\\\\\n          1 & 0 & 0 & 1.5\\\\\n          0 & 0 & -1 & 3\\\\\n          0 & 0 & 0 & 1\n        \\end{bmatrix}\n\\]\n\n\\subsection{}\n\nFor any physical vector v,\n\\[\n  v^{0} \\equiv H_{2}^{0} * v^{2}\n\\]\n\\bydefn\nMultiplying by $ H_{2}^{0}^{-1} $ on both sides from right hand.\n\\[\n  H_{2}^{0}^{-1} * v^{0} \\equiv H_{2}^{0}^{-1} * H_{2}^{0} * v^{2}\n\\]\n\\[\n  H_{2}^{0}^{-1} * v^{0} \\equiv v^{2}\n\\]\n\\[\n  v^{2} \\equiv H_{2}^{0}^{-1} * v^{0}\n\\]\n\nBut also\n\\[\n  v^{2} \\equiv H_{0}^{2} * v^{0}\n\\]\n\\bydefn\nTherefore\n\\[\n  H_{0}^{2} \\equiv H_{2}^{0}^{-1}\n  \\equiv \\begin{bmatrix}\n          1 & 0 & 0 & -0.5\\\\\n          0 & 1 & 0 & 1.5\\\\\n          0 & 0 & 1 & 1.1\\\\\n          0 & 0 & 0 & 1\n        \\end{bmatrix}^{-1}\n  \\equiv \\begin{bmatrix}\n          1 & 0 & 0 & 0.5\\\\\n          0 & 1 & 0 & -1.5\\\\\n          0 & 0 & 1 & -1.1\\\\\n          0 & 0 & 0 & 1\n        \\end{bmatrix}\n\\]\nBut\n\\[\n  v^{0} \\equiv H_{3}^{0} * v^{3}\n\\]\n\\[\n  v^{2} \\equiv H_{0}^{2} * v^{0}\n\\]\n\\bydefn\n\nTherefore combining above two equations\n\\[\n  v^{2} \\equiv H_{0}^{2} * H_{3}^{0} * v^{3}\n\\]\nBut\n\\[\n  V^{2} \\equiv H_{3}^{2} * v^{3}\n\\]\n\\bydefn\n\nTherefore\n\\[\n  H_{3}^{2} \\equiv H_{0}^{2} * H_{3}^{0}\n  \\equiv \\begin{bmatrix}\n          1 & 0 & 0 & 0.5\\\\\n          0 & 1 & 0 & -1.5\\\\\n          0 & 0 & 1 & -1.1\\\\\n          0 & 0 & 0 & 1\n        \\end{bmatrix}\n        * \\begin{bmatrix}\n          0 & 1 & 0 & -0.5\\\\\n          1 & 0 & 0 & 1.5\\\\\n          0 & 0 & -1 & 3\\\\\n          0 & 0 & 0 & 1\n        \\end{bmatrix}\n  \\equiv \\begin{bmatrix}\n          0 & 1 & 0 & 0\\\\\n          1 & 0 & 0 & 0\\\\\n          0 & 0 & -1 & 1.9\\\\\n          0 & 0 & 0 & 1\n        \\end{bmatrix}\n\\]\n\n\\end{document}\n", "meta": {"hexsha": "9088c1a2fa69ea712296d0dd7132de43d4beed15", "size": 13047, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw1/hw1.tex", "max_stars_repo_name": "yashorts/robotmath-hws", "max_stars_repo_head_hexsha": "c1ec2612504bd7095af5518a71363d5633d108a6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hw1/hw1.tex", "max_issues_repo_name": "yashorts/robotmath-hws", "max_issues_repo_head_hexsha": "c1ec2612504bd7095af5518a71363d5633d108a6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hw1/hw1.tex", "max_forks_repo_name": "yashorts/robotmath-hws", "max_forks_repo_head_hexsha": "c1ec2612504bd7095af5518a71363d5633d108a6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.4552238806, "max_line_length": 292, "alphanum_fraction": 0.5723154748, "num_tokens": 5323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.701234502302099}}
{"text": "%-----------------------------------------------------------------------------------------------\n\\section{Example Applications}\n\n    %---------------------------------------------------------------------------------------\n    \\subsection{Iso-$s$ Process in const-$c_v$, van-der-Waals Substance}\n\n    Consider         a         substance         whose         Helmholtz          characteristic\n    function~\\cite{1986-JonesJB+HawkinsGA-Wiley} in reduced coordinates is given by:\n    %\n    \\begin{equation}\n        a_r = \\frac{8T_r}{3}\\left[\n                  \\phi\\left(1 - \\log T_r\\right) - \\log(3v_r - 1)\n              \\right] - \\frac{3}{v_r},\n        \\label{eq:ex.aTv}\n    \\end{equation}\n    %\n    \\noindent where $a_r \\equiv a / (P_{cr}v_{cr})$ is the reduced  specific  Helmholtz  energy,\n    $T_r \\equiv T / T_{cr}$ is the reduced temperature, $\\phi \\equiv \\bar{c}_v / \\bar{R}$  is  a\n    constant dimensionless isochoric specific heat, $v_r \\equiv  v  /  v_{cr}$  is  the  reduced\n    specific volume, $P_{cr}$ is the substance critical  pressure,  $T_{cr}$  is  the  substance\n    critical temperature, and $v_{cr} = Z_{cr}(RT_{cr}/P_{cr})$ is the substance model  critical\n    specific volume, with $Z_{cr} = 3/8$.\n\n    The  Equation  of  State,  EoS,  of  this   substance   is   obtained   by   differentiating\n    Eq.~(\\ref{eq:ex.aTv}) partially with respect to $v_r$~\\cite{1986-JonesJB+HawkinsGA-Wiley}:\n    %\n    \\begin{align}\n        P_r & = \\parxyz{a_r}{v_r}{T_r} & \\rightharpoondown\\\\\n        P_r & = \\frac{8T_r}{3v_r - 1} - \\frac{3}{v_r^2}, \\label{eq:ex.EoS}\n    \\end{align}\n    %\n    \\noindent where $P_r \\equiv P / P_{cr}$ is the reduced pressure, and $P$  the  (dimensional)\n    pressure. Eq.~(\\ref{eq:ex.EoS}) is  known  as  the  universal~\\cite{1899-MaxwellJC-Longmans}\n    van-der-Waals~\\cite{2006-BejanA-Wiley,                           2013-CengelYA+BolesMA-AMGH,\n    1986-JonesJB+HawkinsGA-Wiley} equation of state in reduced coordinates.\n\n    The entropy of this substance is obtained by differentiating Eq.~(\\ref{eq:ex.aTv}) partially\n    with respect to $T_r$~\\cite{1986-JonesJB+HawkinsGA-Wiley}:\n    %\n    \\begin{align}\n        s_r & = -\\parxyz{a_r}{T_r}{v_r} & \\rightharpoondown\\\\\n        s_r & = \\frac{8}{3}\\left[\\phi\\log T_r + \\log(3v_r - 1)\\right], \\label{eq:ex.sTv}\n    \\end{align}\n    %\n    \\noindent where $s_r \\equiv s(T_{cr} / P_{cr}v_{cr})$, is the reduced  specific  entropy  of\n    the substance and $s$ is the (dimensional) specific entropy.\n\n    Let\n    %\n    \\begin{equation}\n        \\omega_r \\equiv v_r - \\frac{1}{3},\n        \\label{eq:def.omega}\n    \\end{equation}\n    %\n    \\noindent be the reduced specific voids volume---since the minimum  van-der-Waals  substance\n    specific reduced volume, $v_{r,min} = 1/3$, for which $\\omega_{r,min} = 0$.\n\n    Therefore, \\emph{isentropic processes} in this const-$c_v$, van-der-Waals substance, between\n    states $(T_{r1}, \\omega_{r1})$ and $(T_{r2}, \\omega_{r2})$ are given by:\n    %\n    \\begin{align}\n        s_{r2} - s_{r1} & = 0 \\qquad\\rightharpoondown\\\\\n        \\phi\\log T_{r2} + \\log\\omega_{r2} & = \\phi\\log T_{r1} + \\log\\omega_{r1},\n    \\end{align}\n    %\n    \\noindent which, exponentiated and rearranged, leads to\n    %\n    \\begin{equation}\n        \\omega_{r2}T_{r2}^{\\phi} = \\omega_{r1}T_{r1}^{\\phi},\n        \\label{eq:vdW.polyek}\n    \\end{equation}\n    %\n    \\noindent which is a polyekthetic process of constant $ij^n$ with $i  \\equiv  \\omega_r$,  $j\n    \\equiv T_r$, and $n \\equiv \\phi$.\n\n    Since the process is also  isentropic,  one  has  the  following  constant-property  process\n    polyekthetic exponent\n    %\n    \\begin{equation}\n        k_{\\omega_rT_rs} = \\phi \\equiv \\frac{\\bar{c}_v}{\\bar{R}},\n        \\label{eq:vdW.kwTs}\n    \\end{equation}\n    %\n    \\noindent for this constant-$c_v$, van-der-Waals substance.\n\n    The `K-polytropic' theorem of reference~\\cite[p.~8]{2020-NaaktgeborenC-engrXiv} states\n\n    \\begin{quote}\n        ``Internally reversible processes in constant-specific-heat  unreactive  closed  systems\n        with negligible kinetic and potential energy changes  and  constant  heat-to-work  ratio\n        interactions, $K$, are exact polytropic processes only if  the  substance  is  an  ideal\n        gas.''\n    \\end{quote}\n\n    Isentropic compressions and expansions have  constant  heat-to-work  ratio  interactions  of\n    $K=0$, since isentropic processes are also adiabatic. Therefore, the `K-polytropic'  theorem\n    forbids non-ideal substances (such  as  van-der-Waals  ones)  to  display  exact  polytropic\n    processes under stated conditions.\n\n    Nonetheless,  Eqs.~(\\ref{eq:vdW.polyek})  and~(\\ref{eq:vdW.kwTs})   show   that   isentropic\n    processes in constant-$c_v$, van-der-Waals  substances  \\emph{can}  be  written  as  exactly\n    polyekthetic processes with constant polyekthetic exponents.\n\n    This one example illustrates how the polytropic process generalization proposed in this work\n    achieved the desired outcome of exactly representing a process that could not be  classified\n    as an exact polytropic process~\\cite{2020-NaaktgeborenC-engrXiv}.\n\n    %---------------------------------------------------------------------------------------\n    \\subsection{General Const-Property Polytropic Processes}\n\n    Since  polytropic  processes  are  also  polyekthetic  processes---by  fixing  the  base  as\n    $Pv$---one  can  apply  either  Eq.~(\\ref{eq:polyek.k})  or~(\\ref{eq:k.bri})   in   deriving\n    polytropic process exponents  $k_{Pv\\ell}$  for  $\\ell  \\in  \\{T,  u,  h,  s,  a,  g\\}$  for\n    (i)~generic  substance  models,  and  for  (ii)~particular  cases,  such  as  ideal   gases.\n    Table~\\ref{tab:kPv} brings such values \\emph{mostly} in terms of properties that are  easily\n    measurable in the laboratory, i.e., in terms of $P$, $T$, $v$, $c_p$, $\\beta$, $\\kappa$, and\n    $\\gamma \\equiv c_p / c_v$, of which some definitions are given on  Eq.~(\\ref{eq:auxs}),  but\n    also in terms of the specific entropy $s$:\n\n    \\begin{table}[ht]\n        \\centering\n        \\caption{General values for $k_{Pv\\ell}$ polyekthetic exponents, and for the  ideal  gas\n            limit}\n        \\vspace{4pt}\n        \\begin{tabular}{ccc}\n            \\toprule\n            Exponent    & General Value &\n            Ideal gas limit \\\\\n            \\midrule\n            $k_{PvP}$   &\n            $0$ &\n            $0$ \\\\[\\bigskipamount]\n            $k_{Pvv}$   &\n            $\\pm\\infty$ &\n            $\\pm\\infty$ \\\\[\\bigskipamount]\n            $k_{PvT}$   &\n            \\(\\displaystyle\\frac{1}{P\\kappa}\\) &\n            $1$ \\\\[\\bigskipamount]\n            $k_{Pvu}$   &\n            \\(\\displaystyle\\frac{c_p - \\beta Pv}{P(\\kappa c_p - T\\beta^2v)}\\) &\n            $1$ \\\\[\\bigskipamount]\n            $k_{Pvh}$   &\n            \\(\\displaystyle\\frac{c_p}{P[\\kappa c_p + \\beta v(1 - \\beta T)]}\\) &\n            $1$ \\\\[\\bigskipamount]\n            $k_{Pvs}$   &\n            \\(\\displaystyle\\frac{c_p}{P(\\kappa c_p - T\\beta^2v)}\\) &\n            $\\gamma$ \\\\[\\bigskipamount]\n            $k_{Pva}$   &\n            \\(\\displaystyle\\frac{s + \\beta Pv}{P\\kappa s}\\) &\n            \\(\\displaystyle 1 + \\frac{R}{s}\\) \\\\[\\bigskipamount]\n            $k_{Pvg}$   &\n            \\(\\displaystyle\\frac{s}{P(\\kappa s - \\beta v)}\\) &\n            \\(\\displaystyle\\frac{s}{s - R}\\) \\\\[\\bigskipamount]\n            \\bottomrule\n        \\end{tabular}\n        \\label{tab:kPv}\n    \\end{table}\n\n    \\begin{equation}\n        \\beta \\equiv \\frac{1}{v}\\parxyz vTP, \\qquad\n        \\kappa \\equiv \\frac{-1}{v} \\parxyz vPT.\n        \\label{eq:auxs}\n    \\end{equation}\n\n    Results  show  an  agreement  between  the  polytropic  and  the  corresponding   $Pv$-based\n    polyekthetic exponents. The polyekthetic exponent results also show  that  constant-$a$  and\n    constant-$g$ process aren't exactly polytropic, even for constant-specific-heat ideal gases,\n    given that such exponents are a function of the entropy.\n\n%-----------------------------------------------------------------------------------------------\n\\section{Conclusions}\n\n    In this work, a generalization of polytropic processes, inspired by their etymology (of many\n    ways,  many  forms)  and   by   the   works   of   Bejan~\\cite{2006-BejanA-Wiley}   and   of\n    Nederstigt~\\cite{2017-NederstigtP-TUDelft}, named `polyekthetic' (multi-exponent) processes,\n    is proposed.\n\n    It is shown that the  polytropic  process  set  is  a  proper  subset  of  the  polyekthetic\n    one---meaning that every polytropic process is also a polyekthetic one but  not  necessarily\n    the reverse.\n\n    Moreover, a useful kind  (or  subset)  of  polyekthetic  processes  consisting  of  constant\n    arbitrary  property,  and  their  respective  special-notation   $k_{ij\\ell}$   polyekthetic\n    exponents were defined. Their basic properties were determined, and a general  solution  was\n    found   for   them,   stated   either   in   terms   of   general    partial    derivatives,\n    Eq.~(\\ref{eq:polyek.k}), or of Bridgman's primitives, Eq.~(\\ref{eq:k.bri}).\n\n    An example of exact polyekthetic process that is not an exact polytropic process  was  given\n    for a van-der-Waals substance. Moreover, generalized polytropic relationships for \\emph{any}\n    substance model, and their corresponding ideal gas limit values were derived from Bridgman's\n    relations  and  listed  on  Table~\\ref{tab:kPv}.  Results  showed  that   constant-$a$   and\n    constant-$g$ process aren't exactly polytropic, even for constant-specific-heat ideal gases,\n    since the entropy explicitly appears in the polytropic exponent of such processes.\n\n%-----------------------------------------------------------------------------------------------\n\n", "meta": {"hexsha": "fe04271dcd978722b9ae038b9d8dd0a79877dcef", "size": 9711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01-04-Section-04.tex", "max_stars_repo_name": "cnaak/man-Polyekthetic", "max_stars_repo_head_hexsha": "0918d9d87e9e8841126059ce3346f15bd6826999", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "01-04-Section-04.tex", "max_issues_repo_name": "cnaak/man-Polyekthetic", "max_issues_repo_head_hexsha": "0918d9d87e9e8841126059ce3346f15bd6826999", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01-04-Section-04.tex", "max_forks_repo_name": "cnaak/man-Polyekthetic", "max_forks_repo_head_hexsha": "0918d9d87e9e8841126059ce3346f15bd6826999", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.2944162437, "max_line_length": 96, "alphanum_fraction": 0.5946864381, "num_tokens": 2963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7010249500189032}}
{"text": "\n% This LaTeX was auto-generated from an M-file by MATLAB.\n% To make changes, update the M-file and republish this document.\n\n%%% \\documentclass{article}\n%%% \\usepackage{graphicx}\n%%% \\usepackage{color}\n\n%%% \\sloppy\n%%% \\definecolor{lightgray}{gray}{0.5}\n\\setlength{\\parindent}{0pt}\n\n%%% \\begin{document}\n\n    \n    \n\\subsection*{Signal Spectrum by means of Fast fourier transform}\n\n\\begin{par}\nExample for algorithm SP-FFT.\n\\end{par} \\vspace{1em}\n\\begin{par}\nCalculates frequency and phase spectrum by means of Fast Fourier Transform algorithm. Result is normalized.\n\\end{par} \\vspace{1em}\n\n\\subsubsection*{Contents}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item Generate sample data\n   \\item Call algorithm\n   \\item Display results\n\\end{itemize}\n\n\n\\subsubsection*{Generate sample data}\n\n\\begin{par}\nTwo quantities are prepared: \\lstinline{y} and \\lstinline{fs}, representing 1 second of signal containing 5 harmonic components and one inter-harmonic component. Main signal component has nominal frequency 1 kHz, nominal amplitude 2 V, nominal phase 1 rad and offset 1 V sampled at sampling frequency 10 kHz.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDI = [];\nfsnom = 1e4; Anom = 2; fnom = 100; phnom = 1; Onom = 0.2;\nt = [0:1/fsnom:1-1/fsnom];\nDI.y.v = Anom*sin(2*pi*fnom*t + phnom);\nfor i = 2:45\n        DI.y.v = DI.y.v + Anom./i*sin(2*pi*fnom*i*t + phnom + i - 1);\nend\nDI.y.v = DI.y.v + 1*sin(2*pi*fnom*1.456*t + phnom);\nDI.fs.v = fsnom;\n\\end{lstlisting}\n\n\n\\subsubsection*{Call algorithm}\n\n\\begin{par}\nUse QWTB to apply algorithm \\lstinline{SP-FFT} to data \\lstinline{DI}.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDO = qwtb('SP-FFT', DI);\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nQWTB: no uncertainty calculation\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Display results}\n\n\\begin{par}\nResults is the amplitude and phase spectrum.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nfigure\nplot(DO.f.v, DO.A.v, '-x')\nxlabel('f (Hz)'); ylabel('A (V)'); title('Amplitude spectrum of the signal');\nfigure\nplot(DO.f.v, DO.ph.v, '-x')\nxlabel('f (Hz)'); ylabel('phase (rad)'); title('Phase spectrum of the signal');\n\\end{lstlisting}\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{algs_examples_published/SP-FFT_alg_example_01.pdf}\n\\end{center}\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{algs_examples_published/SP-FFT_alg_example_02.pdf}\n\\end{center}\n\n\n\n%%% \\end{document}\n    \n", "meta": {"hexsha": "6d5fc16c2f3bc625654f096f904d63b034edb234", "size": 2458, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/algs_examples_published/doc_SP-FFT.tex", "max_stars_repo_name": "qwtb/qwtb", "max_stars_repo_head_hexsha": "f6c79c7dca4065fd85d6f1c05257c1af34e85e34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-12-09T13:18:54.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-09T13:18:54.000Z", "max_issues_repo_path": "doc/algs_examples_published/doc_SP-FFT.tex", "max_issues_repo_name": "qwtb/qwtb", "max_issues_repo_head_hexsha": "f6c79c7dca4065fd85d6f1c05257c1af34e85e34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2015-12-09T13:08:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-13T11:33:41.000Z", "max_forks_repo_path": "doc/algs_examples_published/doc_SP-FFT.tex", "max_forks_repo_name": "qwtb/qwtb", "max_forks_repo_head_hexsha": "f6c79c7dca4065fd85d6f1c05257c1af34e85e34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-11-11T02:12:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-17T12:59:18.000Z", "avg_line_length": 26.1489361702, "max_line_length": 308, "alphanum_fraction": 0.7099267697, "num_tokens": 778, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677545357568, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7010249472867027}}
{"text": "\\chapter{Visualize spectral distances}\n\\label{ch:visualize-spectral-distances}\n\n\\newthought{Let's consider a spectrum}, or any other data entry for that matter, as a point in a multidimensional space. We can define distance metrics between these points and visualize the distance values from one another or from a selected reference point or reference spectrum. By doing so, we can explore how similar our measurements are to a selected reference. We can do this on a series of spectra or even on hyperspectral maps!\n\n\n\\begin{figure}[h]\n    \\centering\n\t\\vspace{0cm}\n    \\includegraphics[width=\\textwidth]{workflow.png}\n    \\caption{Load the \\textit{'Liver cirrhosis - spectral image'} dataset from the \\widget{Datasets} widget and calculate the \\textit{Euclidean distances} from the average spectrum with the \\widget{Neighbors} widget. Visualize them in \\widget{Hyperspectra}.}\n\\end{figure}\n\n\\vspace{-0.5cm}\n\n\\noindent Can you reproduce the results below? Pay attention to the color scheme.\n\n\\begin{figure*}[h]\n\\centering\n\\vspace{-0.5cm}\n\\infinitewidthbox{\n  \\stackinset{r}{-0.5\\linewidth}{t}{+0.1\\linewidth}\n  {\\includegraphics[scale=0.4]{ch-visualize_spectral_distances-fig3.png}}\n  {\\includegraphics[scale=0.6]{ch-visualize_spectral_distances-fig2.png}}\n  \\hspace{8cm}\n  }\n%\\caption{Try changing the parameters!}\n\\end{figure*}\n\n\\vspace{-0.5cm}\n\n\\noindent Explore different distance metrics, inspect distances in a \\widget{Data Table} widget. Don't forget, you can select points on the top map and see the corresponding spectra on the bottom in \\widget{Hyperspectra}.\n\n\\lecnotes{Possibility for discussion of the general mathematical properties of distance functions. See \\url{https://en.wikipedia.org/wiki/Metric_(mathematics)}}", "meta": {"hexsha": "2ca2314ddf64f8179a516d65b3dedc7128bbdb06", "size": 1731, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/spec-022-visualize-distances/visualize-distances.tex", "max_stars_repo_name": "PrimozGodec/orange-lecture-notes", "max_stars_repo_head_hexsha": "5072afa3e29cec77e1a7f6c0d1fd044e737fe378", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-10-13T14:31:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T03:47:06.000Z", "max_issues_repo_path": "chapters/spec-022-visualize-distances/visualize-distances.tex", "max_issues_repo_name": "PrimozGodec/orange-lecture-notes", "max_issues_repo_head_hexsha": "5072afa3e29cec77e1a7f6c0d1fd044e737fe378", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2021-02-26T13:33:10.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-25T19:15:34.000Z", "max_forks_repo_path": "chapters/spec-022-visualize-distances/visualize-distances.tex", "max_forks_repo_name": "PrimozGodec/orange-lecture-notes", "max_forks_repo_head_hexsha": "5072afa3e29cec77e1a7f6c0d1fd044e737fe378", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-01-19T16:55:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-21T20:35:41.000Z", "avg_line_length": 50.9117647059, "max_line_length": 436, "alphanum_fraction": 0.7770075101, "num_tokens": 448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.701024944366311}}
{"text": "\\chapter{Variational inference}\n\\section{Variational inference}\nVariational inference \\cite{Bishop_2007,Blei_2017,Murphy_2012,Zhang_2019} is an approximate inference technique that, as Laplace's approximation, tries to approximate a density $g(\\theta)$ by some density $q(\\theta)$, using the unnormalized density $\\gu(\\theta) = Z g(\\theta)$. In the context of variational inference, this $q(\\theta)$ will be called the \\textit{variational approximation}. Usually in the context of Bayesian inference, $g(\\theta) = p(\\theta|\\mathcal{D})$ and $\\gu(\\theta) = p(\\mathcal{D}|\\theta)p(\\theta)$.\n\nUnlike Laplace's approximation, variational inference is concerned in choosing $q(\\theta)$ by minimizing a global measure of dissimilarity between the distributions $q(\\theta)$ and $g(\\theta)$, called a \\textit{divergence}. A divergence $D$ on a space $S$ of probability densities with the same support is a function $D(\\cdot || \\cdot) : S \\times S \\to \\mathbb{R}$ such that:\n\\begin{equation}\n\\begin{split}\n& D(q||p) \\geq 0, \\, p,q \\in S \\\\\n& D(q||p) = 0 \\iff p = q.\n\\end{split}\n\\end{equation}\nThus divergences are a weaker form of a distance, and in general most important classes of divergences do not satisfy neither symmetry nor the triangle inequality. The objective of variational inference is then, given the target distribution $g$, and a set of candidate distributions $\\mathcal{Q}$, to use a divergence $D$ to find an approximation $q^* \\in \\mathcal{D}$ for $g$ such that\n\\begin{equation}\\label{viobjective1}\n q^* = \\argmin_{q \\in \\mathcal{Q}} D(q || g).\n\\end{equation}\n\nIf $g \\in \\mathcal{Q}$, then obviously $q^* = g$. However, $\\mathcal{Q}$ is a set of distributions chosen so that its elements are easy to work with, and this is not in general the case for $g$. Usually $\\mathcal{Q}$ is parameterized by a set of continuous parameters $\\Lambda \\subset \\mathbb{R}^m$, such that $q(\\theta) = q(\\theta;\\lambda)$. Then, the problem of minimizing \\eqref{viobjective1} becomes a continuous optimization problem\n\\begin{equation}\n \\lambda^* = \\argmin_{\\lambda \\in \\Lambda} D(q(\\cdot;\\lambda)||g),\n\\end{equation}\nand $q^*(\\theta) = q(\\theta;\\lambda^*)$\n\n\\subsection{KL divergence and evidence lower bound}\nArguably the most important divergence between probability distributions, widely used in information theory, is the \\textit{Kullback-Leibner} (KL) divergence $D_{KL}$, given by \\footnote{The KL divergence has origins in information theory, and for discrete distributions, it can be interpreted as the average additional information one has to transmit a receiver when you are modeling a random variable distributed according to $q$ by $p$ \\cite{Murphy_2012}}\n\\begin{equation}\nD_{KL}(q||p) = -\\Ev_{\\theta \\sim q(\\theta)} \\left[ \\log \\frac{p(\\theta)}{q(\\theta)} \\right].\n\\end{equation}\nVariational inference has in general the minimization objective $D_{KL}(q||g)$, although some recent methods have been concerned with other divergence objectives  \\cite{Hernandes-Lobato_2015,Yingzhen_2016,Wang_2018} \\footnote{Some authors reserve the term variational inference just for the objective $D_{KL}(q||g)$}. Notice that, since $D_{KL}(q||g) \\neq D_{KL}(g||q)$, minimizing $D_{KL}(q||g)$ is different from minimizing $D_{KL}(g||q)$. In fact, the later minimization objective ends up with the related \\textit{expectation propagation} technique for approximate inference \\cite{Bishop_2007}. In this work we are mainly concerned with the variational inference $D_{KL}(q||g)$ objective.\n\nSince $g(\\theta) = \\gu(\\theta)/Z$, $D_{KL}(q||g)$ can be rewritten as:\n\\begin{equation}\nD_{KL}(q||g) = -\\bigg(\\Ev_{\\theta \\sim q(\\theta)}[\\log \\gu(\\theta)] -\\Ev_{\\theta \\sim q(\\theta)}[\\log q(\\theta)]\\bigg) + \\log Z,\n\\end{equation}\nThe quantity inside parenthesis is called the \\textit{evidence lower bound} (ELBO)\n\\begin{equation}\\label{elbodef}\n\\mathcal{L}_\\gu(q) = \\Ev_{\\theta \\sim q(\\theta)}[\\log \\gu(\\theta)] + \\mathcal{H}(q),\n\\end{equation}\nwhere $\\mathcal{H}(q) := -\\Ev_{\\theta \\sim q(\\theta)}[\\log(q(\\theta))]$ is the differential entropy of $q$.\n\nIn general, the dependence on $\\gu$ will be omitted until Section \\ref{vbmc_section}, and the ELBO will be denoted as $\\mathcal{L}(q)$. Minimizing $D_{KL}(q||g)$ is equivalent to maximizing $\\mathcal{L}(q)$. This way, there is no need to calculate the normalization factor $Z$, thus markedly improving the flexibility of the method, and the goal becomes\n\\begin{equation}\nq^* = \\argmax_{q \\in \\mathcal{Q}} \\mathcal{L}(q).\n\\end{equation}\nThe ELBO is so called because, considering again $p(\\theta|\\mathcal{D})$, we have that \n\\begin{equation}\n\\begin{split}\n\\log p(\\mathcal{D}) & = \\log \\Ev_{\\theta \\sim p(\\theta)} [p(\\mathcal{D}|\\theta)] \\\\\n& = \\log \\Ev_{\\theta \\sim q(\\theta)} \\left[\\frac{p(\\mathcal{D}|\\theta) p(\\theta)}{q(\\theta)} \\right] \\\\\n& \\geq \\Ev_{\\theta \\sim q(\\theta)} \\left[ \\log \\frac{p(\\mathcal{D}|\\theta) p(\\theta)}{q(\\theta)} \\right] = \\mathcal{L}(q).\n\\end{split}\n\\end{equation}\nSo the ELBO provides a lower bound for the evidence of the model. This means that, when doing model selection between various models $M_1$,\\ldots,$M_t$, one can find their corresponding variational distributions $q^*_{M_1},\\ldots,q^*_{M_t}$ and $\\mathcal{L}(q^*_{M_t}),\\ldots,\\mathcal{L}(q^*_{M_t})$, and then choose the model $M$ with the maximum $\\mathcal{L}(q^*_{M})$, as a proxy for \\eqref{modelselectionobjective}. Notice that this is a heuristic, and there is no guarantee that the model with maximum ELBO is actually the one with maximum evidence.\n\n\\subsubsection{Qualitative interpretations}\nOne possible interpretation for maximizing the ELBO is that maximizing the first ELBO term \n\\begin{equation}\\label{elboterm1}\n \\Ev_{\\theta \\sim q(\\theta)}[\\log \\gu(\\theta)],\n\\end{equation}\nis the algorithm \\enquote{trying} to make $q$ have a high probability density wherever $\\gu$ has a high unnormalized density, while maximizing the second ELBO term,\n\\begin{equation}\n \\mathcal{H}(q) = -\\Ev_{\\theta \\sim q(\\theta)}[\\log q(\\theta)],\n\\end{equation}\nacts as a sort of regularizer preventing $q$ to degenerate to a point mass at the maximum of $\\gu$.\n\nIt is informative to understand qualitatively which kind of approximations of $g$ variational inference will seek. Suppose some algorithm minimizes $D_{KL}(q || g)$ for $q \\in \\mathcal{Q}$. Since the algorithm \\enquote{wants} to make the integrand $q(\\theta) (\\log q(\\theta) - \\log g(\\theta))$ small, where $g(\\theta)$ is close to zero, the $-\\log g(\\theta)$ term will quickly become large, unless $q(\\theta)$ is also close to zero there. However, where $g(\\theta)$ is reasonable far away from zero, the algorithm will not \\enquote{feel} as much pressure to match $q(\\theta)$ to the same value, provided that the algorithm assign large values for $q(\\theta)$ where $g(\\theta)$ is already large. Then, variational inference will tend to underestimate the region where $g(\\theta)$ is large. By contrast, expectation propagation will have the reverse behavior, overestimating the region where $g(\\theta)$ is far from zero \\cite{Bishop_2007}. This is shown in Figure \\ref{vixepfigure}.\n\n\\begin{figure}\n\t\\centering\n\t\\subfloat[$D_{KL}(q||g)$ ]{\\label{vixep1a}\\includegraphics[width=0.3\\textwidth]\n\t\t{figs/klil3a.png}}\n\t\\subfloat[$D_{KL}(g||q)$]{\\label{vixep1b}\\includegraphics[width=0.3\\textwidth]\n\t\t{figs/klil3b.png}}\n\n\n\t\\caption[Difference of behavior when minimizing $D_{KL}(q||g)$ and $D_{KL}(g||q)$]{\\label{vixepfigure} Difference of behavior when minimizing $D_{KL}(q||g)$ (a) and when minimizing $D_{KL}(g||q)$ (b). Here the true distribution (in blue) is approximated by a multivariate normal distribution with diagonal covariance (in red). Example inspired by \\cite{Bishop_2007}. Generating code can be found in \\url{https://github.com/DFNaiff/Dissertation/blob/master/illustrations_dissertation/kl_illustrative_2.py}.}\n\\end{figure}\n\n\\section{Mean field variational inference}\nTraditionally, variational inference has mainly been concerned with factorized variational approximations of the form $q(\\theta;\\lambda) = \\prod_{i=1}^D q_i(\\theta_i;\\lambda_i)$, called \\textit{mean field approximation}. The use of such variational posterior greatly simplifies the optimization of ELBO by coordinate descent. \n\nTo see this, consider a single term $j$ of the variational approximation $q(\\theta) = \\prod_{i=1}^D q_i(\\theta)$. The ELBO for $q(\\theta)$ is:\n\\begin{equation} \\label{mfviexpansion}\n\\begin{split}\n\\mathcal{L}(q) & = \\int \\log \\gu(\\theta) \\prod_{i=1}^D q_i(\\theta_i) d \\theta - \\int \\left(\\sum_{j=1}^D \\log q_i(\\theta_i) \\right) \\prod_{i=1}^D q_i(\\theta_i) d \\theta \\\\\n\t     & = \\int q_j(\\theta_j) \\left( \\int \\log \\gu(\\theta) \\prod_{i \\neq j} q_i(\\theta_i) d \\theta_i \\right) d\\theta_j + \\sum_{i=1}^D \\mathcal{H}(q_i) \\\\\n\t     & = \\int q_j(\\theta_j) \\log \\phi_j (\\theta_j) d\\theta_j + \\mathcal{H}(q_j) + \\sum_{i\\neq j} \\mathcal{H}(q_i),\n\\end{split}\n\\end{equation}\nWith\n\\begin{displaymath}\n\\log \\phi_j(\\theta_j) := \\int \\log(\\gu(\\theta)) q_{-j}(\\theta_{-j}) d\\theta_{-j} = \\Ev_{\\theta_{-j} \\sim q_{-j}} [ \\log \\gu(\\theta) ],\n\\end{displaymath}\nusing the notation $q_{-j}(\\theta_{-j}) = \\prod_{i\\neq j}q_i(\\theta_i)$.\nNow, assuming $\\exp ( \\log \\phi_j(\\theta_j))$ to be integrable over the support of $g(\\theta)$, fix every $q_i$ for $i \\neq j$, so that the only term to be maximized is $q_j$. Then, maximizing \\eqref{mfviexpansion} in respect to $q_j$ is equivalent to maximizing the ELBO between $q_j$ and $\\exp \\left(\\log \\phi_j(\\theta_j)\\right) $. Since there are not any constraints in the choice for $q_j$\n\\begin{equation} \\label{mfviqj}\nq^{*}_j(\\theta_j;q_{-j}) \\propto \\exp \\Ev_{\\theta_{-j} \\sim q_{-j}} [ \\log \\gu(\\theta)].\n\\end{equation}\nThis readily gives an algorithm to find $q^* = \\prod q^*_j$: initialize $q_1,\\ldots,q_D$ in a appropriate manner, and then optimize cyclically \\eqref{mfviqj}. \n\nConvergence is guaranteed due to the convexity of the bound with respect to each factor \\cite{Bishop_2007,Boyd_2004}. This algorithm interacts well with target densities whose conditional distributions $g(\\theta_j|\\theta_{-j})$ belongs to the exponential family, that is, \n\\begin{equation}\\label{exponential_family}\n g(\\theta_j|\\theta_{-j}) = h(\\theta_j) \\exp \\left( \\eta_j(\\theta_{-j})^T t(\\theta_j) - a(\\eta_j(\\theta_{-j})) \\right),\n\\end{equation}\n\\eqref{mfviqj} reduces to \\cite{Blei_2017} \n\\begin{equation}\n q^*_j(\\theta_j;q_{-j}) \\propto h(\\theta_j) \\exp \\left( \\Ev_{\\theta_j \\sim q_{-j}} [\\eta_j(\\theta_{-j})]^T t(\\theta_{-j}) \\right),\n\\end{equation}\nthus if $\\nu_j = \\Ev_{\\theta_{-j} \\sim q_{-j}}[\\eta_j(\\theta_{-j})]^T$ is available analytically, the coordinate descent becomes relatively simple.\n\nResearch to extend mean field variational inference to large datasets or dimensionality exists \\cite{Hensman_2012,Hoffman_2013,Zhang_2019}, however factorized limitations are limited, particularly in its independence assumption. Moreover, many distributions are not in the exponential family, which is the focus of the mean field method, so more generic methods are desirable.\n\n\\section{Generic variational inference}\nSome recent advances in variational inference \\cite{Zhang_2019} are concerned with expanding both the set of possible variational approximations $\\mathcal{Q}$ and approximating general classes of posterior distributions $g(\\theta)$. \n\nConsidering again $\\mathcal{Q}$ to be parameterized by a continuous set of parameters $\\Lambda$, and using the overloaded notation $\\mathcal{L}(\\lambda) = \\mathcal{L}(q(\\cdot;\\lambda))$, return to the optimization problem \n\\begin{equation}\n\\begin{split}\n\\lambda^* = \\argmax_{\\lambda \\in \\Lambda} \\mathcal{L}(\\lambda) & = \\argmax_{\\lambda \\in \\Lambda} \\left( \\Ev_{\\theta \\sim q(\\theta;\\lambda)}[\\log \\gu(\\theta)] + \\mathcal{H}(q(\\cdot;\\lambda)) \\right)\\\\\n& =  \\argmax_{\\lambda \\in \\Lambda} \\Ev_{\\theta \\sim q(\\theta;\\lambda)}\\left[\\log \\left(\\frac{\\gu(\\theta)}{q(\\theta;\\lambda)}\\right)\\right]\n\\end{split}\n\\end{equation}\nIn general the expectations involved cannot be calculated analytically. However, if one represents $\\nabla \\mathcal{L}(\\lambda)$ as expectations, then by using Monte Carlo methods it is possible to use stochastic gradients methods \\cite{Robbins_1951,Kingma_2014,Qian_1999,Ruder_2016} to maximize $\\mathcal{L}(\\lambda)$ \\footnote{In this aspect, modern variational inference research benefits greatly from deep learning research, the later relying heavily on stochastic gradient descent, driving much of the recent development of these algorithms.}.\n\n\\subsection{REINFORCE}\nOne proposal for doing this is given in \\cite{Wingate_2013} and \\cite{Ranganath_2014}, where $\\nabla \\mathcal{L}(\\lambda)$ is rewritten as \\footnote{A quick derivation of this approximation is done in the Appendix \\ref{appendixreinforce}.}\n\\begin{equation}\\label{reinforce}\n\\nabla \\mathcal{L}(\\lambda) = \\Ev_{\\theta \\sim q(\\theta;\\lambda)} \\left[ \\log \\frac{\\gu(\\theta)}{q(\\theta;\\lambda)} \\nabla_{\\lambda} \\log q(\\theta;\\lambda) \\right], \n\\end{equation}\nand is approximated with its Monte Carlo estimator \n\\begin{equation}\\label{reinforcemc}\n\\nabla \\mathcal{L}(\\lambda) \\approx \\frac{1}{K} \\sum_{i \\in [K], \\theta_i \\sim q(\\theta;\\lambda)} \\log \\frac{\\gu(\\theta_i)}{q(\\theta_i;\\lambda)} \\nabla_{\\lambda} \\log q(\\theta_i;\\lambda),\n\\end{equation}\nwhere $[K] = \\{1,\\ldots,K\\}$. In practice, this estimation suffers from high variance, which may hinder optimization. In \\cite{Wingate_2013}, \\eqref{reinforce} is substituted for \n\\begin{equation}\n\\nabla \\mathcal{L}(\\lambda) = \\Ev_{\\theta \\sim q(\\theta;\\lambda)} \\left[ \\left( \\log \\left( \\frac{\\gu(\\theta)}{q(\\theta;\\lambda)}\\right) + C\\right) \\nabla_{\\lambda} \\log q(\\theta;\\lambda) \\right], \n\\end{equation}\nwhere $C$ is an arbitrary constant, which is adjusted to control variance \\footnote{The reason that this constant can be added is because $\\int C \\nabla_\\lambda \\log q(\\theta;\\lambda) q(\\theta;\\lambda) d\\theta = C \\int \\nabla_\\lambda p(\\theta;\\lambda) d\\theta = C \\nabla_\\lambda \\int p(\\theta;\\lambda) d\\theta = 0$.}. In \\cite{Ranganath_2014}, the variance is controlled by Rao-Blackwellization and control variates instead. Other variance reduction methods for this gradient formulation are proposed in \\cite{Titsias_2015} and \\cite{Ruiz_2016}.\n\n\\subsection{Reparameterization trick}\\label{reparameterizationsection}\nAn alternative to calculate the gradient of $\\mathcal{L}(\\lambda)$ as an expectation is known as the \\textit{reparameterization trick} \\cite{Kingma_2013}, which is a general technique for calculating gradients of expectations of continuous random variables.\n\nTo explain the general ideia, assume $X_\\lambda$ is a continuous random variable distributed according to $f(x;\\lambda)$, and one wants to calculate the gradient (in relation to $\\lambda$) of\n\\begin{equation}\\label{reparamderiv1}\n\\Ev_{X_\\lambda} \\left[ h(X_\\lambda) \\right] = \\int h(x) f(x;\\lambda) dx.\n\\end{equation}\nWe approximate \\eqref{reparamderiv1} by Monte Carlo\n\\begin{equation}\\label{reparamderiv2}\n\\Ev_{X_\\lambda} \\left[ h(X_\\lambda) \\right] \\approx \\sum_{i=1}^N h(x_{i,\\lambda}), \\quad x_{i,\\lambda} \\sim f(x;\\lambda).\n\\end{equation}\nNow suppose that there is some random variable $Y$, \\textit{not depending on $\\lambda$}, with density $r(y)$, such that $X_\\lambda = s(Y;\\lambda)$ (for instance, if $X_{\\mu,\\sigma} \\sim \\mathcal{N}(\\mu,\\sigma^2)$, then being $Y \\sim \\mathcal{N}(0,1)$, we have that $X_{\\mu,\\sigma} = s(Y;\\mu,\\sigma) = \\sigma Y + \\mu$). In this case, the Monte Carlo estimator \\eqref{reparamderiv2} is rewritten as\n\\begin{equation}\n\\Ev_{X_\\lambda} \\left[ h(X_\\lambda) \\right] \\approx \\sum_{i=1}^N h(s(y_i,\\lambda)), \\quad y_i \\sim r(y),\n\\end{equation}\nwhich is an expression \\textit{whose gradient in relation to $\\lambda$ can be taken}, and is the Monte Carlo estimator of\n\\begin{equation}\n\\int h(s(y;\\lambda)) r(y) dy = \\Ev_Y [h(s(Y;\\lambda))]\n\\end{equation}\n\nFormally, by letting $A$ be the support of $Y$ and $B_\\lambda$ be the support of $X_\\lambda$, if $s(y;\\lambda)$ if bijective with injective derivative:\n\\begin{equation}\n\\begin{split}\n\\Ev_{X_\\lambda \\sim f(x;\\lambda)} [h(x)] & = \\int_{B_\\lambda} h(x) q(x;\\lambda) dx \\\\\n& = \\int_A h(s(y;\\lambda)) q(s(y;\\lambda);\\lambda) |\\text{det} (s'(y;\\lambda))| dy \\\\\n& = \\int_A h(s(y;\\lambda)) r(y) dy = \\Ev_{Y \\sim r(y)} [h(s(y;\\lambda))],\n\\end{split}\n\\end{equation}\nwhich shows that the reparameterization trick is valid.\n\nTo apply this to $\\mathcal{L}(\\lambda)$, assume $\\theta_\\lambda \\sim q(\\theta;\\lambda)$ is such that $\\theta_\\lambda = s(\\epsilon;\\lambda)$, with $\\epsilon \\sim r(\\epsilon)$. Then, applying reparameterization, we have\n\\begin{equation}\\label{mcreparameterization}\n\\begin{split}\n \\nabla \\mathcal{L}(\\lambda) & = \\nabla \\left(\\Ev_{\\theta \\sim  q(\\theta;\\lambda)}\\left[\\log \\frac{\\gu(\\theta)}{q(\\theta;\\lambda)}\\right] \\right) \\\\\n & =\\nabla \\left( \\Ev_{\\epsilon \\sim r(\\epsilon)} \\left[\\log \\frac{ \\gu(s(\\epsilon;\\lambda))}{q(s(\\epsilon;\\lambda);\\lambda)}\\right]\\right) \\\\\n & \\approx \\nabla_\\lambda \\left( \\frac{1}{K} \\sum_{i \\in [K], \\epsilon_i \\sim r(\\epsilon)} \\log \\frac{ \\gu(s(\\epsilon_i;\\lambda))}{q(s(\\epsilon_i;\\lambda);\\lambda)} \\right)\n\\end{split}\n\\end{equation}\nIn \\cite{Zhang_2019}, it is argued that the observed lower variance of this estimation methods, if compared to the one given by \\eqref{reinforce}, may be due to the fact that reparameterization trick takes in account the gradient of the target distribution, instead of just the gradient of the variational distribution as in \\eqref{reinforce}. Moreover, in cases that the entropy of $q(\\cdot;\\lambda)$ can be estimated analytically, the reparameterization trick can be applied only to $\\gu(\\theta)$, leading to lower variance. Finally, it is important to notice that this format is more readily integrated in an automatic differentiation package, since it suffices to calculate the sum inside the gradient and backpropagate it in relation to $\\lambda$.\n\n\\iffalse\nThese recent advances in the field, allowing the application of variational inference for a general variety of target distributions, has resulted in the technique return to some popularity, with recent probabilistic programming language focusing on it, such as Pyro \\cite{Bingham_2018} and Edward \\cite{Tran_2016}.\n\\fi\n\n\\section{Mixtures of gaussians for variational approximations}\\label{mixgaussiansvi}\n\nThe idea of using mixture distributions for variational inference dates back to the late 90s \\cite{Bishop_1997,Jaakkola_1998}, originally developed for a limited number of target distributions, and later is explored for approximating general distributions in \\cite{Gershman_2012,Salimans_2012}, leading to recent work in it \\cite{Acerbi_2018,Arenz_2018,Guo_2016,Jankowiak_2019,Miller_2016}. The technique presented here uses the reparameterization trick, in a vein similar to the one presented in \\cite{Miller_2016}. In general, the mixture distribution considered is one of Gaussian distributions (as it is in this work), although many of those extends to more general mixtures.\n\nMore formally, consider as the set of candidate proposals \n\\begin{equation}\n\\mathcal{Q}_k := \\left\\{\\sum_{i=1}^k w_i f(\\cdot;\\lambda_i) \\middle| f(\\cdot;\\lambda_i) \\in \\mathcal{Q}_1, 1 \\leq i \\leq k; (w_1,...,w_k) \\in \\Delta_k \\subset \\mathbb{R}^k \\right\\},\n\\end{equation}\nwher $\\Delta_k$ denotes the probability simplex $\\{(x_1,\\ldots,x_k) \\in {\\mathbb{R}^+}^k| \\sum_{i=1}^k x_k = 1\\}$, and $\\mathcal{Q}_1 = \\{f(\\cdot;\\lambda) | \\lambda \\in \\Lambda \\subset \\mathbb{R}^m\\}$ is a parameterized set of distributions. In the mixture of multivariate normals case,\n\\begin{equation}\n\\mathcal{Q}_1 := \\{f(\\cdot ; \\mu,\\Sigma) = \\mathcal{N}(\\cdot;\\mu,\\Sigma) | \\mu \\in \\mathbb{R}^d,\\Sigma \\in \\mathbb{R}^{d \\times d}, \\Sigma \\geq 0\\} \n\\end{equation}\nis the set of multivariate normal distributions. In many cases, it is interesting to restrict $\\mathcal{Q}_1$ further so that $\\Sigma$ is diagonal.\nMixtures of distributions are interesting as variational approximations since their expectations are easily available \n\\begin{equation}\n\\Ev_{X \\sim \\sum_i w_i f_i} [h(X)] = \\sum_i w_i \\Ev_{X_i \\sim f_i} [h(X_i)],\n\\end{equation}\nas well as their covariances\n\\begin{equation}\n\\begin{split}\n& \\Cov_{X \\sim \\sum_i w_i f_i}(X) = \\sum_i w_i \\left( \\Sigma_i +   \\mu_i \\mu_i^T \\right) - \\mu \\mu^T, \\\\\n& \\Sigma_i = \\Cov_{X_i \\sim f_i}(X_i), \\quad \\mu_i = \\Ev_{X_i \\sim f_i}[X], \\quad \\mu = \\Ev_{X \\sim \\sum_i w_i f_i} [X].\n\\end{split}\n\\end{equation}\nFurthermore, samples of mixtures can be easily generated from the base distributions, by choosing mixture $i$ with probability $w_i$, and then sampling $X$ from $f(\\cdot;\\lambda_i)$ \\footnote{Batching this process in order to sample many variables, escaping loops in interpreted languages with support for numerical operations (such as Python with Numpy) requires some care, but it is possible in few lines.}. Furthermore, letting $\\mathcal{Q}_\\infty = \\cup_{i=1}^\\infty \\mathcal{Q}_i$ and $\\mathcal{Q}_1$ be these set of Gaussian distributions, $\\mathcal{Q}_\\infty$ is dense in the set of continuous distributions \\cite{Epanechnikov_1969}, so in this case any continuous distribution can be approximated arbitrarily close, in principle.\n\nConsidering mixtures of Gaussians, for fixed $k$, in order to find the parameters\n\\begin{displaymath} \n\\lambda = (w_1,\\mu_1,\\Sigma_1,\\ldots,w_k,\\mu_k,\\Sigma_k)\n\\end{displaymath}\nof \n\\begin{equation}\n q^*_k = \\argmax_{q_k \\in \\mathcal{Q}_k} \\mathcal{L}(q_k),\n\\end{equation}\none needs first to find suitable parameterizations for $\\Sigma_i$ and $\\mathbf{w} := (w_1,...,w_k)$. For the covariance matrix, one can either consider only diagonal matrices\n\\begin{equation}\n\\Sigma_i = \\text{diag}(\\sigma^2_{i,1},\\ldots,\\sigma^2_{i,D}),\n\\end{equation}\nor consider matrices of the form\n\\begin{displaymath}\n \\Sigma_i = \\u_i \\u_i^T + \\text{diag}(\\sigma^2_{i,1},\\ldots,\\sigma^2_{i,D}),\n\\end{displaymath}\nor use more advanced parameterizations such as the ones found in \\cite{Pinheiro_1996}. Let $\\sigma_i$ be the parameters for $\\Sigma_i$, so that $\\Sigma_i = \\Sigma_i(\\sigma_i)$. For $\\mathbf{w}$, using some monotone bijective differentiable function $\\phi : \\mathbb{R} \\to \\mathbb{R}^+$ (for example, $\\phi = \\exp$), one can then consider the corresponding differentiable map $\\Phi : \\mathbb{R}^k \\to \\Delta_k$ as \n\\begin{equation}\n\\Phi(\\nu_i) = \\frac{\\phi(\\nu_i)}{\\sum_{i=1}^k \\phi(\\nu_k)} = w_i(\\nu_i).\n\\end{equation}\n\nThe parameter of interest $\\lambda$ becomes $(\\nu_1,\\mu_1,\\sigma_1,\\ldots,\\nu_k,\\mu_k,\\sigma_k)$, and\n\\begin{equation}\nq_k(\\theta) = \\sum_{i=1}^k w_i(\\nu_i) f_{\\mathcal{N}(\\mu_i,\\Sigma(\\sigma_i))}(\\theta).\n\\end{equation}\nThus, the ELBO objective becomes\n\\begin{equation}\\label{elbomixturegaussians}\n\\begin{split}\n\\mathcal{L}(\\lambda) & = \\int \\log \\gu(\\theta) q_k(\\theta) d\\theta - \\int \\log (q_k(\\theta)) q_k(\\theta) d \\theta \\\\\n& = \\sum_{i=1}^k w_i(\\nu_i) \\Ev_{\\theta_i \\sim \\mathcal{N}(\\mu_i;\\Sigma(\\sigma_i))}\\left[\\log \\frac{ \\gu(\\theta_i)}{q_k(\\theta_i;\\lambda)}\\right].\n\\end{split}\n\\end{equation}\n\nOne can adapt the reparameterization trick to rewrite $\\mathcal{L}(\\lambda)$ in a manner suitable to stochastic gradient optimization. First notice that any gaussian random variable $X \\sim \\mathcal{N}(\\mu,\\Sigma)$ can be written as $X = \\mu + A Z$, where $Z \\sim \\mathcal{N}(0,I)$ and $A$ is some matrix such that $\\Sigma = A A^T$. For instance, $A$ can be the lower Cholesky factor of $\\Sigma$, if the parameterization of $\\Sigma$ only supports positive-definite matrices. Then $A(\\sigma)$ is differentiable \\cite{Smith_1995,Murray_2016}, and $s(\\epsilon;\\mu_i,\\sigma_i) = \\mu_i + A(\\sigma) \\epsilon$, and \\eqref{elbomixturegaussians} is approximated by Monte Carlo,\n\\begin{equation}\\label{mcmixturegaussians}\n\\begin{split}\n\\mathcal{L}(\\lambda) & = \\sum_{i=1}^k w_i(\\nu_i) \\Ev_{\\epsilon \\sim \\mathcal{N}(0,I)}\\left[\\log \\frac{ \\gu(s(\\epsilon;\\mu_i,\\sigma_i))}{q_k(s(\\epsilon;\\mu_i,\\sigma_i);\\lambda)}\\right] \\\\\n& \\approx \\sum_{i=1}^k w_i(\\nu_i) \\left( \\frac{1}{K_i} \\sum_{k \\in [K_i], \\epsilon_{i,j} \\sim \\mathcal{N}(0,I)} \\log \\frac{ \\gu(s(\\epsilon_{i,j};\\mu_i,\\sigma_i))}{q_k(s(\\epsilon_{i,j};\\mu_i,\\sigma_i);\\lambda)} \\right),\n\\end{split}\n\\end{equation}\nwhich is an expression that can be differentiated to find an approximation for $\\nabla \\mathcal{L}(\\lambda)$.\n\nIn principle there is no way to know how many mixtures are necessary to return a good approximation. However, one can,for each $i \\in \\mathbb{N}$, starting with $i = 1$, sequentially find $q^*_i$ close to $\\argmax_{q_i \\in \\mathcal{Q}_i} \\mathcal{L}(q)$, and go to sequentially from $Q_i$ to $Q_{i+1} \\supset Q_i$, until the variational approximation is good enough. However, this procedure runs into computational issues, namely the number of optimization parameters scale linearly with the number of mixtures $k$, in a non-convex problem with non-trivial gradient evaluation, whose cost also scales linearly with $k$. Hence, the cost of improving the mixtures this way quickly becomes rather large. We next present an approach that mitigates this problem, at the cost of making a greedy approximation, thus potentially more inefficient in the number of mixtures.\n\n\\subsection{Boosting mixtures of gaussians}\\label{boostedvi_section}\nBoosting \\cite{Freund_1997,Freund_1999,Friedman_2000} is a standard technique in machine learning, usually used in classification problems, which tries to combine slighty better than chance algorithms, or \\textit{weak learners} in a reliable, accurate algorithm (a \\textit{strong learner}). The general framework is transferred to the problem of variational inference in concurrent works by \\cite{Miller_2016} and \\cite{Guo_2016}, using increasing mixtures distributions.\n\nIn this setting, start first with some distribution $q_1 \\in \\mathcal{Q}_1$. Then, recursively, given a proposal $q_{i-1}^*$,  it is considered the proposal set\n\\begin{equation}\n\\begin{split}\n\\mathcal{Q}_{i} = \\mathcal{Q}_{i}(q_{i-1}) = \\{ (& 1-w_{i}) q_{i-1} + w_{i}  f(\\cdot;\\mu_{i},\\Sigma_{i}) | \\\\  & w_i \\in [0,1], \\mu_i \\in \\mathbb{R}^d, \\Sigma_i \\in \\mathbb{R}^{d \\times d}, \\Sigma_i \\geq 0\\},\n\\end{split}\n\\end{equation}\nand then some $q_i$ is chosen from $\\mathcal{Q}_i$, in a manner that $\\mathcal{L}(q_i)$ is reasonably greater than the previous value $\\mathcal{L}(q_{i-1})$. One straightforward approach is to seek $\\lambda_i (w_{i}^*,\\mu_{i}^*,\\Sigma_{i}^*)$ such as the maximization objective becomes\n\\begin{equation}\\label{miller_objective}\n \\mathcal{L}_{i}(\\lambda_{i}) := \\mathcal{L}((1-w_{i}) q_{i-1} + w_{i}  f(\\cdot;\\mu_{i},\\Sigma_{i})),\n\\end{equation}\nwhich is the procedure proposed in \\cite{Miller_2016}. In \\cite{Guo_2016}, it is shown that the KL divergence satisfies the conditions estabilished by \\cite{Tong_Zhang_2003} that ensures if\n\\begin{equation}\n \\mathcal{L}((1-w_i){i-1} + w_i f_i) \\geq \\sup_{f \\in Q_1,w\\in[0,1]} \\mathcal{L}((1-w)q_{i-1} + w f) - \\epsilon_i,\n\\end{equation}\nas $\\epsilon_i \\to 0$, then\n\\begin{equation}\n \\lim_{i \\to \\infty} \\sup_{q \\in Q_\\infty} L(q) - \\mathcal{L}(q_i) = 0,\n\\end{equation}\nprovided that every $q \\in \\mathcal{Q}_1$ is bounded from below. In \\cite{Guo_2016}, it is shown that the KL divergence satisfies those two conditions, if every $q \\in \\mathcal{Q}_1$ is assumed to be bounded from below by a positive constant. Although this is not the case for Gaussian distributions, it is argued that since in actual implementations the practitioner works with a bounded set of interest, the result holds in practice.\n\n\\subsection{Gradient boosting mixture of gaussians}\\label{gradboostsection}\nAnother boosting proposal, due to \\cite{Guo_2016}, is to instead of trying to optimize jointly $(w_{i}^*,\\mu_{i}^*,\\Sigma_{i}^*)$ at each step, choosing first $f_{i} = f(\\cdot;\\mu_{i},\\Sigma_{i})$, and then choose $w_i$ as to maximize:\n\\begin{equation}\\label{boosting_objective_alpha}\n\\begin{split}\n \\mathcal{L}_{i}(w_{i}) & := \\mathcal{L}((1-w_{i}) q_{i-1} + w_{i}  f_{i}) \\\\\n & = \\int \\log \\frac{\\gu(\\theta)}\n\t\t\t\t {(1-w_{i}) q_{i-1}(\\theta) + w_{i} f_{i}(\\theta)} ((1-w_{i}) q_{i-1}(\\theta) + w_{i} f_{i}(\\theta)) d\\theta.\n \\end{split}\n\\end{equation}\nSince the KL divergence is convex in $q$, the ELBO is concave, so minimizing $w$ is easy, provided we can easily calculated $\\mathcal{L}'_i(w_i)$. Since we have \n\\begin{equation}\\label{boosting_objective_dalpha}\n\\begin{split}\n \\mathcal{L}'_{i}(w_{i}) & = \n\t \\int \\frac{\\partial}{\\partial w_{i}} \\left( \\log  \\frac{\\gu(\\theta)}\n\t {(1-w_{i}) q_{i-1}(\\theta) + w_{i} f_{i}(\\theta)} ((1-w_{i}) q_{i-1}(\\theta) + w_{i} f_{i}(\\theta))\\right) d\\theta \\\\\n\t & = \\int \\log (\\gu(\\theta)) (f_{i}(\\theta) - q_{i-1}(\\theta)) d\\theta - \\\\\n\t & \\qquad{} \\int \\log((1-w_{i}) q_{i-1}(\\theta) + w_{i} f_{i}(\\theta)) (f_i(\\theta) - q_{i-1}(\\theta)) d\\theta,\n\\end{split},\n\\end{equation}\nwe can then approximate the derivative by Monte Carlo\n\\begin{equation}\n\\begin{split}\n\\mathcal{L}'_i(w_i) = & \\frac{1}{J} \\sum_{j \\in [J] \\theta_{j} \\sim f_i} \\left(\\log(\\gu(\\theta_j)) - \\log((1-w_{i}) q_{i-1}(\\theta_j) + w_{i} f_{i}(\\theta_j))\\right) \\\\\n& -\\frac{1}{K} \\sum_{\\theta_{k} \\in [K], \\theta_k \\sim q_{i-1}} \\left(\\log(\\gu(\\theta_k)) - \\log((1-w_{i}) q_{i-1}(\\theta_k) + w_{i} f_{i}(\\theta_k))\\right),\n\\end{split}\n\\end{equation}\nand using it to maximize $\\mathcal{L}'_i(w_i)$.\n\nThe question becomes then how to choose $f_i$. In \\cite{Guo_2016}, the technique of gradient boosting \\cite{Friedman_2001} is borrowed for this purpose, so that $f_i$ is chosen as to minimize $\\nabla D_{KL} (q_{i-1}||g)  \\cdot f$, where $\\nabla D_{KL}(q || g)$ is the functional derivative of $D_{KL}(q || g)$ as a function of $q$. For $D_{KL}(q || p)$, we can use Taylor expansion to find the functional derivative\n\\begin{equation}\n\\begin{split}\n D_{KL}(q + \\delta h || p) & = \\int (q + \\delta h) \\log \\frac{q + \\delta h}{p} \\\\\n\t\t\t\t\t  & = \\int q \\left(\\log \\frac{q}{p} + \\frac{\\delta h/p}{q/p} + \\mathcal{O}(\\delta^2) \\right) + \\delta \\int h \\log \\frac{q}{p} + \\mathcal{O}(\\delta^2) \\\\\n\t\t\t\t\t  & = D(q||p) + \\delta \\int \\left(1 + \\log \\frac{q}{p}\\right) h + \\mathcal{O}(\\delta^2).\n\\end{split}\t\t\t  \n\\end{equation}\nHere the argument $\\theta$ is omitted to simplify the expression. Hence \n\\begin{equation} \\label{idealklgrad}\n\\begin{split}\nf_i = \\argmin_{f} \\nabla D_{KL}(q_{i-1} || g) \\cdot f & = \\argmin_{f} \\int \\left(1 + \\log \\frac{q_{i-1}(\\theta)}{g(\\theta)}\\right) f(\\theta) d \\theta = \\\\\n& = \\argmin_{f} \\int \\log \\frac{q_{i-1}(\\theta)}{g(\\theta)} f(\\theta) d\\theta.\n\\end{split}\n\\end{equation}\n\nSince the parameterization for $f_i(\\theta)$ allows degeneration to a point mass at $\\argmin_{\\theta} \\log (q_{i-1}(\\theta) / g(\\theta))$, and this point mass optimizes \\eqref{idealklgrad}, further constraints over $f_i(\\theta)$ are needed for getting a non-degenerate new basis function. In \\cite{Guo_2016} \\eqref{idealklgrad} is regularized by the logarithm of the $L_2$ norm of $f_i(\\theta)$\n\\begin{equation}\nf_i =  \\argmin_{f} \\left( \\int \\log \\frac{q_{i-1}(\\theta)}{g(\\theta)} f(\\theta) d\\theta +  \\frac{\\lambda}{2} \\log ||f||_2^2 \\right)\n\\end{equation}\nwhile in \\cite{Locatelo_2018}, \\eqref{idealklgrad} is regularized by negative of the entropy of $f$, as a proxy for the regularization of its $L_\\infty$ norm. Since for $f(\\theta) = \\mathcal{N}(\\theta|\\mu,\\Sigma)$, $\\log ||f||_2^2 = -\\frac{1}{2} \\log |\\Sigma| - \\frac{1}{2} \\log(2\\pi)$ and $-\\mathcal{H}(f) = -\\frac{1}{2} \\log |\\Sigma| - \\frac{1}{2} \\log(2\\pi e)$, both approaches are equivalent for mixture of Gaussians, yielding the maximization objective in relation to $\\mu_i,\\Sigma_i$:\n\\begin{equation}\\label{relbogaussian}\n\\begin{split}\n \\text{RELBO}(\\mu_i,\\Sigma_i) = & \\int \\log(\\gu(\\theta)) \\mathcal{N}(\\theta|\\mu,\\Sigma) d\\theta - \\int \\log(q_{i-1}(\\theta)) \\mathcal{N}(\\theta|\\mu,\\Sigma) d\\theta + \\\\\n & \\frac{\\lambda}{4} \\log |\\Sigma|,\n \\end{split}\n\\end{equation}\nwhere $\\lambda$ is a regularization constant (the name RELBO comes from \\cite{Locatelo_2018}). This constant may be set either as a fixed value or decaying as $i$ increases, as to permit increasingly narrower distributions as the algorithm runs. For example, in \\cite{Locatelo_2018} $\\lambda$ is set as $1/\\sqrt{i+1}$. \\footnote{In \\cite{Guo_2016} it is argued that this objective is still somewhat hard to maximize, so it is proposed an heuristic based on a local Laplace approximation. This heuristic was previously explored by the author of this work, however it ran into implementation issues, and moreover, it does not exactly attend the desiderata in this work, namely as few function evaluations as possible}. Finally, the gradients of \\eqref{relbogaussian} in relation to $\\mu_i,\\Sigma_i$ can be estimated by the reparameterization trick. \n\nThe resulting pseudo-algorithm is shown in Figure \\ref{vbalgorithm}.\n\\begin{Algorithm}\n\\begin{algorithmic}[1]\\label{vbalgorithm}\n\\Procedure{VariationalBoosting}{$\\log \\gu,\\mu_0$,$\\Sigma_0$}\n\\LineComment{$\\mu_0,\\Sigma_0$ the are initial boosting values}\n\\State $w_0 := 1.0$\n\\For{$t=1,...,T$}\n\t\\State $\\mu_{t},\\Sigma_{t} := \\argmax RELBO(\\mu_{t},\\Sigma_{t})$ \\Comment{Using reparameterization}\n\t\\State $w_{t} := \\argmax \\mathcal{L}_i(w_i)$ \\Comment{Using $\\mathcal{L}'_t(w_t)$ for gradient descent}\n\t\\For{$j=0,...,t-1$}\n\t\t\\State $w_{j} \\gets (1-w_t)w_j$\n\t\\EndFor\n\\EndFor\n\\State \\Return $\\{(\\mu_t,\\Sigma_t,w_t)\\}_{t=1}^T$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{\\label{vbalgorithm}Variational boosting algorithm.}\n\\end{Algorithm}\n\n\\section{Using Bayesian Monte Carlo in Variational Inference}\\label{vbmc_section}\n\nAll the approaches previously presented suffers from one major flaw: the need for a large number of evaluations of the unnormalized posterior $\\gu$ by Monte Carlo methods, in order to have a good estimation of the gradient. This is the same problem of integration that Bayesian Monte Carlo tries to solve, so one can try to use this technique when $\\gu$ is expensive to evaluate. In \\cite{Acerbi_2018}, it is developed a method called Variational Bayesian Monte Carlo (VBMC) that hinges on exactly this idea.\n\nConsider a parameterized variational proposal $q(\\theta;\\lambda)$, and the corresponding ELBO for $\\gu(\\theta)$:\n\\begin{displaymath}\n \\mathcal{L}(\\lambda) = \\mathcal{L}_\\gu(\\lambda) = \\int \\log \\gu(\\theta) q(\\theta;\\lambda) d\\theta - \\int \\log(q(\\theta;\\lambda)) q(\\theta;\\lambda) d\\theta.\n\\end{displaymath}\nAs in Chapter 4, setting as prior for $\\log \\gu(\\theta)$ the Gaussian process $GP(m,k)$, and given set of evaluations $\\mathcal{D}_0 = \\{(x_i,f(x_i))\\}_{i=1}^N$, $\\mathcal{L}_\\gu(\\lambda)$ can be replaced by the Gaussian distributed random variable\n\\begin{equation}\\label{vbmc_rvs}\n\\begin{split}\n\\mathcal{L}_\\mathcal{D}(\\lambda) := \\mathcal{L}_{\\gu_\\mathcal{D}}(\\lambda) &:= Z_\\mathcal{D}(\\lambda) - \\int \\log(q(\\theta;\\lambda)) q(\\theta;\\lambda) d\\theta, \\\\\nZ_\\mathcal{D}(\\lambda) & := \\int \\log \\gu_\\mathcal{D}(\\theta) q(\\theta;\\lambda) d\\theta,\n\\end{split}\n\\end{equation}\nwith mean\n\\begin{equation}\n\\begin{split}\n\\bar{\\mathcal{L}}_\\mathcal{D}(\\lambda) := \\Ev \\left[ \\mathcal{L}_{\\log \\gu_\\mathcal{D}}(\\lambda) \\right] & = \\Ev[Z_\\mathcal{D}(\\lambda)] - \\int \\log(q(\\theta;\\lambda)) q(\\theta;\\lambda) d\\theta \\\\\n& = \\int \\Ev[\\log \\gu_\\mathcal{D}(\\theta)] q(\\theta;\\lambda) d\\theta - \\int \\log(q(\\theta;\\lambda)) q(\\theta;\\lambda) d\\theta\\\\\n& = \\mathcal{L}_{\\Ev[\\log \\gu_\\mathcal{D}]} (\\lambda), \\\\\n\\end{split}\n\\end{equation}\nand variance\n\\begin{equation}\n\\Var(\\mathcal{L}_\\mathcal{D}(\\lambda)) = \\Var(Z_\\mathcal{D}(\\lambda)),\n\\end{equation}\nand $\\Ev[Z_\\mathcal{D}(\\lambda)]$ and $\\Var[Z_\\mathcal{D}(\\lambda)]$ being given by \\eqref{evvarbmc2}.\nThis approach enjoy the same benefits as the BMC approach:\n\\begin{itemize}\n\t\\item If the evaluation of $\\gu$ is expensive, it is not feasible to perform a Monte Carlo estimation of $\\int \\log \\gu(\\theta) q (\\theta;\\lambda) d \\theta$ at each step in optimizing the ELBO.\n\t\\item The function $\\gu$ does not need to be differentiable, and its evaluations may be noisy (although this last case is not considered in this work, the extension is straightforward).\n\\end{itemize}\nIn case $q(\\theta;\\lambda)$ is a mixture of $i$ Gaussians $q_i(\\theta;\\lambda)$, as in \\cite{Acerbi_2018}, the methods presented in \\ref{mixgaussiansvi} and the one in Chapter 4, by the discussion in Section \\ref{kerneldistributionbmc}, given a suitable kernel $k$, $\\Ev[Z_\\mathcal{D}(\\lambda)]$ and $\\Var[Z_\\mathcal{D}(\\lambda)]$ can be easily treated. In \\cite{Acerbi_2018}, $k$ is the SQE kernel \\eqref{sqekernel} with outputscale $r_0$ and lengthscales $l_1,\\ldots,l_D$, which by \\eqref{bmcmixgaussians} makes $\\Ev[Z_\\mathcal{D}(\\lambda)]$ and $\\Var[Z_\\mathcal{D}(\\lambda)]$ both analytical.\n\nThe entropy term $-\\int \\log(q(\\theta;\\lambda)) q(\\theta;\\lambda) d\\theta$ does not have in general a closed form, and must still be treated. Approximating $-\\log(q(\\theta;\\lambda))$ by BMC is possible, but since this term changes with $\\lambda$, this will be costly. However, since $\\log q(\\theta;\\lambda)$ is easy to evaluate, by construction, the entropy term can be treated with the reparameterization trick without much additional cost. Other possible approach to deal with this term, when using mixture of Gaussians, is to use one of the approximations proposed in \\cite{Huber_2008}. \n\nAn important point is that, since, by in the first equation of \\eqref{evvarbmc2}, only $\\mathbf{z}$ and $\\int m(\\theta) q(\\theta;\\lambda) d\\theta$ depends on $q(\\theta;\\lambda)$, one can rewrite\n\\begin{equation}\n\\begin{split}\n\\int \\Ev[\\log \\gu_\\mathcal{D}(\\theta)] q_k(\\theta;\\lambda) d\\theta & = M(\\lambda) + \\mathbf{z}^T \\mathbf{w} \\\\\n\\mathbf{w} & = K^{-1} \\mathbf{y} \\\\\nM(\\lambda) & = \\int m(\\theta) q(\\theta;\\lambda) d\\theta \\\\\n\\mathbf{z}_i & = \\int k(x,x_i) q(\\theta;\\lambda) dx.\n\\end{split}\n\\end{equation}\nThis way, with $\\mathbf{w}$ being previously computed, the computation of $\\bar{\\mathcal{L}}_\\mathcal{D}(\\lambda)$ can be calculated in $\\mathcal{O}(N)$ time for each $\\lambda$, while $\\Var(\\mathcal{L}_\\mathcal{D}(\\lambda))$ can be calculated in $\\mathcal{O}(N^2)$. The new variational objective becomes then simply $\\bar{\\mathcal{L}_\\mathcal{D}}(\\lambda)$.\n\n\\subsection{Quadratic mean function}\\label{quadmeanfnsection}\nWith the objective $\\bar{\\mathcal{L}}_\\mathcal{D}(\\lambda)$, the actual distribution that is being approximated by mixture of Gaussians is proportional to $\\exp \\Ev[\\log \\gu_\\mathcal{D}(\\theta)]$. From the variational inference approximation's point of view, the only information that it has on the original distribution $\\gu$ is by its GP approximation. \n\nThis raises some issues: if the mean function of the GP prior $m(\\theta)$ is either zero or a constant, and the kernel is one that decays to zero as $|x - x'|$ goes to infinity, such as \\eqref{sqekernel}, \\eqref{maternkernel} or \\eqref{spectralmixturekernel}, then $\\exp \\Ev[\\log \\gu_\\mathcal{D}(\\theta)]$ is not integrable, so it cannot define an unnormalized probability distribution. Hence, care must be taken with the mean function $m(\\theta)$.\n\nOne approach is to simply let $m(\\theta)$ have a very low value, so that in practice it resembles enough a probability distribution so that, for a reasonable number of mixtures $k$, convergence issues does not appear. This is the default approach used in the developed algorithm presented in Chapter 4. An alternative approach, used in \\cite{Acerbi_2018}, is to change the mean function so that $\\exp(m(\\theta))$, thus $\\exp \\log \\Ev[\\log \\gu_\\mathcal{D}(\\theta)]$ is an unnormalized probability distribution, while having the integral $\\int m(\\theta) q_k(\\theta) d \\theta$ being analytically tractable. In \\cite{Acerbi_2018}, the following mean function is proposed:\n\\begin{equation}\\label{vbmc_quadratic_mean}\n m_{Q}(\\theta;l,c) = - \\frac{1}{2} \\sum_{i=1}^D \\frac{(\\theta_i - c_i)^2}{l_i^2},\n\\end{equation}\nwhich then both makes $\\exp(m_Q(\\theta;l,c))$ integrable and yields, for $q_i(\\theta)$ being a mixture of Gaussians, \n\\begin{equation}\n \\int m_{Q}(\\theta;l,c) q_k(\\theta) d\\theta = \n \t-\\frac{1}{2} \\sum_{j=1}^k \\sum_{i=1}^D \\left[\\frac{(c_i - \\mu_{k,i})^2}{l_i^2} + \\frac{\\Sigma_{k,i,i}}{l_i^2} \\right].\n\\end{equation}\nThis comes immediately from the expectation of quadratic forms of normal distribution formula \\cite{Petersen_2012}. \n\n\\subsection{Remarks on acquisition functions for VBMC}\nAs in Bayesian Monte Carlo, a question that arises is one of active sampling. Notice that, fixed evaluations $\\mathcal{D}$, and assuming a fixed set of mixtures of $k$ Gaussians $\\mathcal{Q}_k$, associated with a fixed set of parameters $\\Lambda_k$, and letting\n\\begin{equation}\n\\lambda^*(\\mathcal{D}) = \\argmin_{\\lambda} \\mathcal{L}_\\mathcal{D}(\\lambda),\n\\end{equation}\nthe final ELBO is a random variable $\\mathcal{L}_{\\mathcal{D}}(\\lambda^*(\\mathcal{D}))$, which is normally distributed with variance $\\Var(Z_\\mathcal{D}(\\lambda^*))$. Since we want to have a high degree of certainty about the variational approximation's quality, one wants the final ELBO objective to have as lower variance as possible, since it is a measure of its uncertainty.\n\nIn this setting, one option would be, in a greedy approach, to choose $x_{N+1}$, so that, expanding $\\mathcal{D}$ to $\\mathcal{D}'(x,\\log \\gu(\\theta_{N+1})) = \\mathcal{D} \\cup \\{(x_{N+1},\\log \\gu(\\theta_{N+1}))\\}$, it minimizes the variance of $\\mathcal{L}_{\\mathcal{D'}}(\\lambda^*(\\mathcal{D'}))$. Since $\\log \\gu(\\theta_{N+1})$ is not known in advance, one could substitute this instead for\n\\begin{equation}\n\\begin{split}\n & \\Ev_\\mathcal{D'} \\left[ \\Var(Z_{\\mathcal{D'}}(\\lambda^*(\\mathcal{D'})) \\right] \\\\\n & \\mathcal{D}' = \\mathcal{D} \\cup \\{(\\theta_{N+1},\\log \\gu_\\mathcal{D}(\\theta_{N+1}))\\}.\n \\end{split}\n\\end{equation}\nHowever, it is not clear how to work with this random variable, and minimize a measure of its uncertainty. However, this intuition helps with constructing heuristic acquisition functions to seek $\\theta_{N+1}$.\n\n\\subsubsection{Uncertainty sampling and prospective prediction}\nOne option in order to tackle this problem is to consider the current variational proposal $q_k(\\theta;\\lambda)$ fixed, and consider the minimization objective\n\\begin{equation} \n \\alpha^\\mathcal{D}_\\text{VR}(\\theta_{N+1}) = \\Var\\left(Z_{\\mathcal{D}'(\\theta_{N+1})}(\\lambda)\\right).\n\\end{equation}\nHowever, since this is an expensive minimization objective, a proxy for this approach is to consider the integrand of\n\\begin{displaymath}\n \\int \\log \\gu_\\mathcal{D}(\\theta) q_k(\\theta;\\lambda) d\\theta,\n\\end{displaymath}\nand seek the integrand maximum variance instead, resulting in the \\textit{uncertainty sampling} maximization objective\n\\begin{equation}\\label{us_vbmc}\n \\alpha^\\mathcal{D}_{\\text{US}}(\\theta_{N+1}) = k_\\mathcal{D}(\\theta_{N+1},\\theta_{N+1}) q_k(\\theta_{N+1};\\lambda)^2.\n\\end{equation}\n\nThe above objective puts much weight in the current variational proposal, which may hinder exploration. Considering that future proposals will seek regions with high posterior density, the other objective proposed in \\cite{Acerbi_2018} is formed by multiplying $\\alpha^\\mathcal{D}_{\\text{US}}(\\theta_{N+1})$ by an exploration factor for high posterior denstiies  $\\exp(m_\\mathcal{D}(\\theta_{N+1}))$. This result in the \\textit{prospective prediction} maximization objective,\n\\begin{equation}\\label{prospective_vbmc}\n\\alpha^\\mathcal{D}_{\\text{PROP}}(\\theta_{N+1}) = k_\\mathcal{D}(\\theta_{N+1},\\theta_{N+1}) \\exp(m_\\mathcal{D}(\\theta_{N+1}))q_k(\\theta_{N+1};\\lambda)^2.\n\\end{equation}\nIt is reported in \\cite{Acerbi_2018} that the prospective prediction objective results in better approximations than the uncertainty sampling one. The objectives \\eqref{us_vbmc} and \\eqref{prospective_vbmc}, along with some newly proposed ones (\\eqref{soft_prospective_vbmc},\\eqref{mmlt_vbmc} and \\eqref{mmltprop_vbmc}), are used in the algorithm developed in this work, to be shown in the next chapter.\n\n\n\n\n", "meta": {"hexsha": "6f03dc8ea2b41e3636410c4441b7375f38950d86", "size": 43624, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex_copy/chapters/capituloD.tex", "max_stars_repo_name": "DFNaiff/Dissertation", "max_stars_repo_head_hexsha": "8db72a0e588042a582053625ec58cde6a661f2a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex_copy/chapters/capituloD.tex", "max_issues_repo_name": "DFNaiff/Dissertation", "max_issues_repo_head_hexsha": "8db72a0e588042a582053625ec58cde6a661f2a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex_copy/chapters/capituloD.tex", "max_forks_repo_name": "DFNaiff/Dissertation", "max_forks_repo_head_hexsha": "8db72a0e588042a582053625ec58cde6a661f2a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 95.8769230769, "max_line_length": 981, "alphanum_fraction": 0.7186181918, "num_tokens": 13851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282707, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7008257998912949}}
{"text": "\\section{Insights and Algorithms}\n\n\\subsection{Exercises}\n\n\\subsubsection{Exercise 3.1}\nAssume $f(n) = 2^{n} - 1$. Then $f(n + 1) = 2^{n + 1} - 2 + 1 = 2^{n + 1} - 1$.\n\n\\subsubsection{Exercise 3.2}\nWe have that\n\\begin{align*}\n        (QQ^* )_{ab} &= \\frac{1}{n}\\sum_{k = 0}^{n - 1} w_n^{ak} \\overline{w_n^{kb}} \\\\\n                     &= \\frac{1}{n}\\sum_{k = 0}^{n - 1} w_n^{k(i - j)}\\\\\n\\end{align*}\nIf $i = j$, then $(QQ^*)_{ab} = 1$. Otherwise, since $w_n^{(i - j)}$ is a root of unity,\n\\begin{align*}\n        (QQ^*)_{ab} &= w_n^{i - j} (QQ^*)_{ab} \\implies (1 - w_n^{i - j}) (QQ^*)_{ab} = 0 \\implies\n        (QQ^*)_{ab} = 0\n\\end{align*}\nAnd we have that $Q^* = Q^{-1}$ as desired.\n\n\\subsubsection{Exercise 3.3}\nExercise seems ambiguous - if we're just talking about $f(1)$, then we can simply add an $if$ case for it.\nOtherwise, we can return both $f_min$ and the index $j$. I don't think it's possible to \nreconstruct full scores from just returning the index by itself (without wasting computation).\n\n\\subsubsection{Exercise 3.4}\nIf we let $g(n)$ be the number of calculations for $f(n)$ after calling $f(1)$, then we have by definition\nof the algorithm that $g(n) = \\sum_{k = 1}^{n - 1} g(k)$ (since every call to $f(k)$ calls $f(n)$).\nWe see that $g(2) = g(1) = 2^0$, and we assume that $g(n) = 2^{n - 2}$. Then we have that\n\\begin{align*}\n        g(n + 1) = \\sum_{k = 1}^{n} g(k) = g(n) + \\sum_{k = 1}^{n - 1} g(k) = 2g(n) = 2^{n - 1}\n\\end{align*}\nSo we are done by induction.\n\n\\subsubsection{Exercise 3.5}\nSuppose we pick a subset of $j$ characters from both $s$ and $t$. Then there is a unique alignment that \ncorresponds to assigning the subsets to one another (in the order of characters) and then deleting/inserting\neverything else that's not aligned. This also covers all possible alignments, so we have that the number of\nalignments is $\\binom{2n}{n}$.\n\n\\subsubsection{Exercise 3.6}\nThere are $n$ choices for where to cut $s$ to make $s'$ and $n$ choices for where to cut $t$ to make $t'$,\nhence $O(n^2)$.\n\n\\subsubsection{Exercise 3.7}\nCalculating optimal edit distance finds an optimal alignment in the process; we only need to also return\nwith $d(s, t)$ the choice of operation that was used and then compose these operations across subproblems.\n\nThe edit distance problem is available to solve on \n\\href{https://leetcode.com/problems/edit-distance/}{LeetCode}. \nMy solution is as follows\n\\begin{lstlisting}[language=python]\n    def minDistance(self, word1, word2):\n        N, M = len(word1), len(word2)\n        DP = [[0] * (M+1) for i in range(N+1)]\n        for j in range(M):\n            DP[N][j] = M - j\n        for i in range(N):\n            DP[i][M] = N - i\n        for i in range(N-1, -1, -1):\n            for j in range(M-1, -1, -1):\n                not_eq = 1\n                if word1[i] == word2[j]:\n                    not_eq = 0\n                DP[i][j] = min(DP[i][j+1] + 1,\n                               DP[i+1][j] + 1,\n                               DP[i+1][j+1] + not_eq)\n                \n        return DP[0][0]\n\\end{lstlisting}\n\n\\subsubsection{Exercise 3.8}\nIf there is a path $s \\to t$, then there must be a product of the form $A_si A_ij ... A_kt$ that is non-zero \nand contains a maximum of $n-1$ terms. Any such product can be extended to $n-1$ terms if we introduce\nself-loops (since $A_ii = 1$), so we have that $(1 + A)_{st}^{n-1}$ is non-zero. The reverse direction can\nbe shown similarly.\n\n\\subsubsection{Exercise 3.9}\nAs hinted, we can maintain an array $V[i][j]$ that tracks which middle vertex $k$ was used to get the minimum \n$B_{ij}(\\log_2 n)$. Then, we can reconstruct the optimal path backwards by looking at\n$V[i][j] = k_1, V[i][k_1] = k_2, ...$ until we get to $i$.\n\n\\subsubsection{Exercise 3.10}\nIf there is a cycle whose total length is negative, then there is no fixed point (since we can repeatedly go\nthrough that cycle to decrease distance). Otherwise, there is no issue, since there is no way to reduce\ndistance by visiting a vertex more than once.\n\n\\subsubsection{Exercise 3.11}\nBy definition, $B_{ij}(m)$ must be an upper bound on the length of the shortest path from $i$ to $j$, as \notherwise we would be positing that there exists $k$ such that the shortest path from $i$ to $k$ to $j$ is\nshorter than the shortest path from  $i$ to  $j$. The term $B_{ij}(m)$ is the composition of paths \n$B{ik}(m-1)$ and  $B_{kj}(m-1)$, so the number of steps in $B_{ij}(m)$ is at most twice the maximum of\nthe number of steps in $B_{ik}(m-1)$ (over all $k$). From this it is clear that the number of steps after\n$m$ outermost iterations is at most $2^m$ (since $m = 0$ corresponds to a single step). If there are no\nnegative cycles, then the shortest path between two vertices will take at most $n-1$ steps, so we only need\nto iterate up to $m = \\log_2 m$.\n\n\\subsubsection{Exercise 3.12}\nSuppose we complete the for loop and there are two vertices that are not connected. Since the for loop \nconsiders every edge, there must be no path between these two vertices. However, this contradicts the\nassumption of the graph being connected, so the final result of the for loop must be a spanning tree.\n\n\\subsubsection{Exercise 3.13}\nFor $n = 2$, it is clear that a forest with $n-1$ edges must be a spanning tree. Now we assume the\nsame is true for $n$ and consider a forest with $n + 1$ vertices. By the inductive assumption, any sub-forest\nconsisting of $n - 1$ edges must be a spanning tree for the $n$ vertices it connects. Since these $n$ vertices\nare already connected, adding an edge between any of them would introduce a cycle. Thus, the only way to grow\nthis forest of $n$ vertices to a forest of $n + 1$ vertices is to add an edge to vertex $n + 1$, so a forest\nwith  $n$ edges must be a spanning tree for its $n + 1$ vertices. This proves one direction; the other \ndirection can be proved similarly.\n\n\\subsubsection{Exercise 3.14}\nJust add the bolded edges in Figure 3.16 in order of weight.\n\n\\subsubsection{Exercise 3.15}\nThe proof idea is the same as that of Lemma 3.1, except now replacing an edge $e$ with another edge $e'$ cannot\npreserve a minimum spanning tree, since $e \\neq e'$.\n\n\\subsubsection{Exercise 3.16}\nRun Kruskal's but negate the edges in the graph. This has to be the maximum, since we already proved Kruskal's\nto be optimal.\n\n\\subsubsection{Exercise 3.17}\nThe first axiom is vacuously true for linear independence. For the second axiom, if $Y$ were not linearly \nindependent then we could extend the nontrivial linear relation sending $Y$ to 0 to $X$, so the second axiom\nmust also be true. The third axiom holds similarly.\n\n\\subsubsection{Exercise 3.18}\nSuppose we obtain a maximum flow using Ford-Fulkerson. At each stage of Ford-Fulkerson, we increase the current\nflow $f$ by the minimum $c_f(e)$ in an augmenting path. Since the capacities are all integers, this means at \neach stage we increase $f$ by an integral amount, so there is a max flow obtained via Ford-Fulkerson that is\nan integer.\n\n\\subsubsection{Exercise 3.19}\nNo, the maximal flow need not be unique; consider a graph with only a single edge from the source to a fork\nconsisting of edges with equal capacity and connecting back to a single node (looks like a kite). The \ndifference between two max flows must be 0, since there must be some edge that they both share (otherwise we\ncould just combine both two get a larger flow).\n\n\\subsubsection{Exercise 3.20}\nThe min cut is not unique; we can remove the two edges from the source or we could remove the two edges to\nthe target. Additionally, we can also remove the lower edge from the source and the upper edge to the target.\n\n\\subsubsection{Exercise 3.21}\nIf there is a flow of value $m$, it must necessarily pass through $m$ of the original edges in the bipartite\ngraph $G$, since they were all assigned capacity 1. A matching consisting of $m$ edges in $G$ corresponds to\n$m$ unique left nodes (connected to $s$) and  $m$ unique right nodes (connected to $t $), so we can send a \nflow of $m$ through this matching.\n\n\\subsection{Problems}\n\n\\subsubsection{Problem 3.1}\nWe see that $n = 1$ requires only the single move of moving the one disk directly to the desired peg, and that\n$n = 2$ cannot be done in fewer than the 3 moves indicated by the recursive algorithm. Suppose the recursive\nalgorithm is optimal for $n$. To move $n + 1$ disks, we must move disk $n + 1$ to the bottom of the desired peg.\nThus, we first move $n$ disks to the non-desired peg, which\nrequires $2^n - 1$ moves. Now there is no ``better'' move than moving disk $n + 1$ to the desired peg, since\nit will be put in its final spot. After making this move, we again have to move the $n$ disks from the other \npeg to the desired peg, which takes another $2^n - 1$ moves, for a total of $2(2^n - 1) + 1 = 2^{n+1} - 1$ \nmoves, as desired.\n\n\\subsubsection{Problem 3.2}\nFigure 3.24 is very helpful. The recursive solution for Towers of Hanoi can be translated to finding a\nHamiltonian path on an $n$-dimensionl cube as follows\n\\begin{enumerate}\n        \\item Find a Hamiltonian path on one face of the cube, which is itself an $n-1$-dimensional hypercube.\n        \\item Now move from this face to the opposite face; this requires moving once along a single edge\n                connecting the two faces (this is how we create a hypercube in the first place).\n        \\item Now we can find a Hamiltonian path on the opposite face, and we are done.\n\\end{enumerate}\nThe vertices of the cube can be identified with different Hanoi states, and the edges can be identified with\nmoves.\n", "meta": {"hexsha": "60a48303c226867463a9dab38b14209904d9bf99", "size": 9541, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Nature_of_Computation_Moore_Mertens/chapter_3.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "Nature_of_Computation_Moore_Mertens/chapter_3.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Nature_of_Computation_Moore_Mertens/chapter_3.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.1502890173, "max_line_length": 112, "alphanum_fraction": 0.6922754428, "num_tokens": 2801, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8807970701552505, "lm_q1q2_score": 0.7008133233809194}}
{"text": " \\documentclass{article}\n\\usepackage[margin=1in]{geometry}\n\\setlength{\\parindent}{0in}\n\n\\usepackage[utf8]{inputenc}\n\n\\usepackage{latexsym,amsfonts,amssymb,amsthm,amsmath}\n\\usepackage {tikz}\n\\usetikzlibrary {positioning}\n\\usetikzlibrary{quantikz}\n\n\\usepackage{braket}\n\n\\newcommand{\\norm}[1]{\\left\\lVert#1\\right\\rVert}\n\n\\title{Quantum Computing - Assignment 2}\n\\author{Kishlaya Jaiswal}\n\n\\begin{document}\n\n\\maketitle\n\n\n\\subsection*{Exercise 1}\n\\begin{proof} .\n\n\\begin{center}\n\\begin{quantikz}\n\\lstick{$\\ket{0}^{\\otimes n}$} & \\gate{H^{\\otimes n}} & \\qw & \\gate[wires=2]{U_f} & \\qw & \\gate{H^{\\otimes n}} & \\qw & \\meter{} & \\qw \\\\\n\\lstick{$\\ket{1}$} & \\gate{H} & \\qw & & \\qw \\\\\n\\end{quantikz}\n\\end{center}\n\nwhere $f: \\mathbb{Z}_2^n \\rightarrow \\mathbb{Z}_2$, $f(x) = \\sum a_ix_i$ \\\\\n\nFirst we prepare the state: \n$$\\ket{0}^{\\otimes n} \\otimes \\ket{1}$$ \n\nApplying $n+1$ Hadamard gates, we get: \n$$\\left( \\frac{1}{2^{n/2}} \\sum_x \\ket x \\right) \\otimes \\left(\\frac{\\ket0 - \\ket1}{\\sqrt2}\\right) = \\frac{1}{2^{n/2}} \\frac{1}{\\sqrt2} \\sum_x \\ket x \\ket0 - \\ket x \\ket1$$\n\nApplying $U_f$, we get: \n$$\\frac{1}{2^{n/2}} \\frac{1}{\\sqrt2} \\sum_x \\ket x \\ket{f(x)} - \\ket x \\ket{\\overline{f(x)}} = \\left( \\frac{1}{2^{n/2}} \\sum_x (-1)^{f(x)} \\ket x \\right) \\otimes \\left(\\frac{\\ket0 - \\ket1}{\\sqrt2}\\right)$$\n\nLet us carefully examine the first $n$ qubits at this point.\n\nFirst, say $x = x_1\\ldots x_n$, then \n$$(-1)^{f(x)} \\ket x = (-1)^{a_1x_1 + \\cdots a_nx_n} \\ket{x_1 \\ldots x_n} = \\bigg((-1)^{a_1x_1} \\ket{x_1}\\bigg) \\otimes \\cdots \\otimes \\bigg((-1)^{a_nx_n} \\ket{x_n}\\bigg)$$ \n\nThus, the first $n$ qubits are: \n\\begin{align*}\n    \\frac{1}{2^{n/2}} \\sum_x (-1)^{f(x)} \\ket x &= \\bigg(\\sum_{x_1} \\frac{(-1)^{a_1x_1} \\ket{x_1}}{\\sqrt2}\\bigg) \\otimes \\cdots \\otimes \\bigg(\\sum_{x_n} \\frac{(-1)^{a_nx_n} \\ket{x_n}}{\\sqrt2}\\bigg) \\\\\n    &= \\bigg(\\frac{\\ket0 + (-1)^{a_1}\\ket1}{\\sqrt2} \\bigg) \\otimes \\cdots \\otimes \\bigg(\\frac{\\ket0 + (-1)^{a_n}\\ket1}{\\sqrt2} \\bigg) \\\\\n\\end{align*}\n\nNow we recall that $$H\\bigg(\\frac{\\ket0 + (-1)^x\\ket1}{\\sqrt2}\\bigg) = \\ket x$$\n\nThus applying $n$ Hadamard gates to the first $n$ qubits, we get:\n$$\\ket{a_1 \\ldots a_n}$$\n\\end{proof}\n\n\n\\subsection*{Exercise 2}\n\\begin{proof}\nFirst we prove by induction on $n$ that for $x \\in \\{0,1\\}^n$, $$H^{\\otimes n}\\ket x = \\frac{1}{2^{n/2}} \\sum_{z \\in \\{0,1\\}^n} (-1)^{x.z} \\ket z $$\n\nFor $n=1$, it follows immediately as \n$$H\\ket x = \\frac{1}{\\sqrt2} \\sum_z (-1)^{x.z} \\ket z = \\frac{\\ket0 + (-1)^x \\ket1}{\\sqrt2}$$\n\nSuppose it is true for some $n \\geq 1$, then for any $x' \\in \\{0,1\\}^{n+1}$, write $x' = xx_{n+1}$ where $x \\in \\{0,1\\}^n$, then\n\n\\begin{align*}\n    H^{\\otimes n+1}\\ket{x'} &= H^{\\otimes n+1}(\\ket{x} \\otimes \\ket{x_{n+1}}) \\\\\n    &= H^{\\otimes n}\\ket{x} \\otimes H\\ket{x_{n+1}} \\\\ \n    &= \\frac{1}{2^{n/2}} \\sum_{z \\in \\{0,1\\}^n} (-1)^{x.z} \\ket z \\otimes \\left(\\frac{\\ket0 + (-1)^{x_{n+1}}\\ket1}{\\sqrt2}\\right) \\\\\n    &= \\frac{1}{2^{n+1/2}} \\sum_{z \\in \\{0,1\\}^n} (-1)^{x.z + + x_{n+1}.0} \\ket z \\otimes \\ket0 + (-1)^{x.z + x_{n+1}.1} \\ket z \\otimes \\ket1 \\\\\n    &= \\frac{1}{2^{n+1/2}} \\sum_{z' \\in \\{0,1\\}^{n+1}} (-1)^{x'.z'} \\ket{z'}\n\\end{align*}\n\nNow, we consider\n\\begin{align*}\n    H\\left(\\frac{\\ket x + \\ket y}{\\sqrt2}\\right) &= H\\left(\\frac{\\ket x + \\ket{s \\oplus x}}{\\sqrt2}\\right) \\\\\n    &= \\frac{1}{\\sqrt2} H\\ket{x} + \\frac{1}{\\sqrt2} H\\ket{s \\oplus x} \\\\\n    &= \\frac{1}{\\sqrt2} \\frac{1}{2^{n/2}} \\sum_z (-1)^{x.z} \\ket z +  \\frac{1}{\\sqrt2} \\frac{1}{2^{n/2}} \\sum_z (-1)^{x.z + s.z} \\ket z \\\\\n    &= \\frac{1}{2^{n+1/2}} \\sum_z (-1)^{x.z} \\big(1 + (-1)^{s.z}\\big) \\ket z \\\\\n    &= \\frac{1}{2^{n-1/2}} \\sum_{s.z = 0} (-1)^{x.z} \\ket z \\\\\n    &= \\frac{1}{2^{n-1/2}} \\sum_{z \\perp s} (-1)^{x.z} \\ket z\n\\end{align*}\n\n\\end{proof}\n\n\n\\subsection*{Exercise 3}\n\\begin{proof}\n$\\ket S = \\sum_{s \\in S} \\frac{1}{2^{m/2}} \\ket s$\n\n\\begin{align*}\n    H\\ket S &=  \\sum_{s \\in S} \\frac{1}{2^{m/2}} H\\ket s \\\\\n    &=  \\sum_{s \\in S} \\frac{1}{2^{m/2}} \\frac{1}{2^{n/2}} \\sum_{w} (-1)^{s.w} \\ket w \\\\\n    &=  \\sum_{w} \\frac{1}{2^{(n+m)/2}} \\left(\\sum_{s \\in S} (-1)^{s.w} \\right) \\ket w \\\\\n\\end{align*}\n\n\\textbf{Claim}: $w \\in S^{\\perp} \\implies \\sum_{s \\in S} (-1)^{s.w} = 2^m$\n\nBecause if $w \\in S^{\\perp} \\implies s.w = 0, \\forall s \\in S \\implies \\sum_{s \\in S} (-1)^{s.w} = |S| = 2^m$ \\\\\n\n\\textbf{Claim}: $w \\not \\in S^{\\perp} \\implies \\sum_{s \\in S} (-1)^{s.w} = 0$\n\nFix a basis $\\{s_1, s_2, \\ldots, s_m\\}$ for $S$. Since $w \\not \\in S^{\\perp}$, there exists $i$ such that $s_i.w = 1$. Now for any $s \\in S$, $s = c_1s_1 + \\cdots + c_ms_m$, where $c = (c_1, c_2, \\ldots) \\in \\mathbb{Z}_2^m$. Thus,\n\n\\begin{align*}\n    \\sum_{s \\in S} (-1)^{s.w} &= \\sum_{c \\in \\mathbb{Z}_2^m} (-1)^{c_1 s_1.w}(-1)^{c_2 s_2.w} \\ldots (-1)^{c_m s_m.w} \\\\\n    &= (1 + (-1)^{s_1.w})(1 + (-1)^{s_2.w}) \\ldots (1 + (-1)^{s_i.w}) \\ldots (1 + (-1)^{s_m.w}) \\\\\n    &= (1 + (-1)^{s_1.w})(1 + (-1)^{s_2.w}) \\ldots (1 + (-1)) \\ldots (1 + (-1)^{s_m.w}) \\\\\n    &= 0\n\\end{align*}\n\nTherefore, \n$$H\\ket S = \\frac{1}{2^{(n-m)/2}} \\sum_{w \\in S^{\\perp}} \\ket w$$\n\nFurthermore, for any $y \\in \\mathbb{Z}_2^n$\n\n\\begin{align*}\n    H\\ket{y+S} &=  \\sum_{s \\in S} \\frac{1}{2^{m/2}} H\\ket{y+s} \\\\\n    &=  \\sum_{s \\in S} \\frac{1}{2^{(n+m)/2}} \\sum_{w} (-1)^{(y+s).w} \\ket w \\\\\n    &=  \\frac{1}{2^{(n+m)/2}} \\sum_{w} (-1)^{y.w} \\left(\\sum_{s \\in S} (-1)^{s.w} \\right) \\ket w \\\\\n    &= \\frac{1}{2^{(n-m)/2}} \\sum_{w \\in S^{\\perp}} (-1)^{y.w}\\ket w\n\\end{align*}\n\n\\end{proof}\n\n\\subsection*{Exercise 4}\n\n\\begin{proof}\n\nSuppose $X_j = i$ is known. So $V_i = \\langle w_1, \\ldots w_i \\rangle$ has dimension $j$.\n\n\\begin{align*}\n    P[X_{j+1} = i+1] = P[w_{i+1} \\not \\in V_i] = 1 - P[w_{i+1} \\in V_i] = 1 - \\frac{2^j}{2^m}\n\\end{align*}\n\n\\begin{align*}\n    P[X_{j+1} = i+2] &= P[w_{i+2} \\not \\in V_i, w_{i+1} \\in V_i] \\\\\n    &= P[w_{i+2} \\not \\in V_i] P[w_{i+1} \\in V_i] \\\\\n    &= \\frac{2^j}{2^m} \\left(1 - \\frac{2^j}{2^m}\\right)\n\\end{align*}\n\nSimilarly, \n\n\\begin{align*}\n    P[X_{j+1} = i+k] &= P[w_{i+k} \\not \\in V_i, w_{i+k-1} \\in V_i, \\ldots w_{i+1} \\in V_i] \\\\\n    &= P[w_{i+k} \\not \\in V_i] P[w_{i+k-1} \\in V_i] \\ldots P[w_{i+1} \\in V_i] \\\\\n    &= \\left(1 - \\frac{2^j}{2^m}\\right)\\left(\\frac{2^j}{2^m}\\right)^{k-1}\n\\end{align*}\n\nLet $p_j = 2^{j}/2^m$, then\n\n\\begin{align*}\n    E[X_{j+1} \\mid X_{j} = i] &= \\sum_{k \\geq 1} (i+k) P[X_{j+1} = i+k] \\\\\n    &= \\sum_{k \\geq 1} (i+k) \\left(1 - p_j\\right) p_j^{k-1} \\\\\n    &= i \\left(1 - p_j\\right) \\sum_{k \\geq 1} p_j^{k-1} + (1 - p_j) \\sum_{k \\geq 1} k p_j^{k-1} \\\\\n    &= i + \\frac{1}{1-p_j} \\\\\n\\end{align*}\n\nAs $E[X_{j+1} \\mid X_j] = X_j + \\frac{1}{1-p_j}$ and $E[X_{j+1}] = E[E[X_{j+1} \\mid X_j]]$, we get $E[X_{j+1}] = E[X_j] + \\frac{1}{1-p_j}$\n\nSimilarly, we can calculate $E[X_1] = \\frac{1}{1-p_0}$. Thus,\n\n\\begin{align*}\n    E[X_m] &= E[X_{m-1}] + \\frac{1}{1-p_{m-1}} \\\\\n    &= \\sum_{j=0}^{m-1} \\frac{1}{1-p_j} \\\\\n    &= \\sum_{j=0}^{m-1} \\frac{2^m}{2^m - 2^j} \\\\\n    &= \\sum_{j=0}^{m-1} 1 + \\frac{2^j}{2^m - 2^j} \\\\\n    &= m + \\left(\\sum_{j=1}^{m} \\frac{1}{2^j - 1 }\\right) \\\\\n    &< m + \\left(\\sum_{j=1}^{m} \\frac{1}{2^{j-1} }\\right) & (\\text{as } 1 \\leq 2^{j-1} \\forall j \\geq 1) \\\\ \n    &< m + \\left(\\sum_{j=0}^{\\infty} \\frac{1}{2^{j} }\\right) \\\\\n    &= m + 2\n\\end{align*}\n\nThus, $E[X_m] < m+2$\n\\end{proof}\n\n\\end{document}\n\n", "meta": {"hexsha": "9602fd032e16a17f60695c4928e239d42e1c2a92", "size": 7207, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "quantum_computing/assign2_soln.tex", "max_stars_repo_name": "kishlaya/assignments", "max_stars_repo_head_hexsha": "1aa76e32d7e5059499a93359cb52118ccbf07028", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-17T09:28:32.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-14T17:40:34.000Z", "max_issues_repo_path": "quantum_computing/assign2_soln.tex", "max_issues_repo_name": "kishlaya/assignments", "max_issues_repo_head_hexsha": "1aa76e32d7e5059499a93359cb52118ccbf07028", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "quantum_computing/assign2_soln.tex", "max_forks_repo_name": "kishlaya/assignments", "max_forks_repo_head_hexsha": "1aa76e32d7e5059499a93359cb52118ccbf07028", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9567567568, "max_line_length": 230, "alphanum_fraction": 0.5225475232, "num_tokens": 3529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7956580927949807, "lm_q1q2_score": 0.7008133182239615}}
{"text": "\\label{chapter:basic_latex}\n\n% Paragraph descriping what the chapter is about\n\\blindtext\n\n\\section{A section with a definition and a theorem}\n\\label{sec:a_section_with_a_definition_and_a_theorem}\n\nThe above is a section. Here's a definition.\n\n\\begin{definition}[Conditional probability]\n\t\\label{def:conditional_probability}\n\tThe conditional probability of $A$ given $B$ is defined as\n\t\\begin{equation*}\n\t\tP(A | B) = \\frac{P(A \\cap B)}{P(B)},\n\t\\end{equation*}\n\twhere $A \\cap B$ denotes the intersection of $A$ and $B$.\n\\end{definition}\n\n\\begin{theorem}[Bayes theorem]\n\tGiven $P(A | B)$, $P(A)$ and $P(B)$, we can compute $P(B | A)$ using \n\t\\begin{equation}\n\t\\label{eqn:bayes_theorem}\n\tP(B | A) = \\frac{P(A | B) P(B)}{P(A)}.\n\t\\end{equation}\n\\end{theorem}\n\\begin{proof}\n\tWrite $P(A \\cap B)$ in two ways using the Definition \\ref{def:conditional_probability} of conditional probability as follows.\n\t\\begin{equation*}\n\t\tP(A \\cap B) = P(A | B) P(B) \\qquad P(B \\cap A) = P(B | A) P(A)\n\t\\end{equation*}\n\tThe intersection is symmetric, meaning that $B \\cap A = B \\cap A$.\n\tThus we can compare terms and write $P(A | B) P(B) = P(B | A) P(A)$, rearranging this gives Bayes theorem.\n\\end{proof}\n\nBayes theorem has many applications, such as the \\emph{Naive Bayes Classifier}, which is a machine learning algorithm.\nThe classifier assigns a label to a piece of data, e.g. classifying an email as spam or not.\nIt's called ``naive'' since it assumes conditional independence.\nEquation \\eqref{eqn:bayes_theorem} has extensions when more variables are used.\n\n\\section{A section with an example}\nIn Section \\ref{sec:a_section_with_a_definition_and_a_theorem} we gave a theorem, here's an example with a real world application.\n\n\\begin{example}[An example with numbers]\n\tHere's a little example with some numbers.\n\t\\begin{align*}\n\t\tP(B | A) &= \\frac{P(A | B) P(B)}{P(A)} \\\\\n\t\t\t \t &= \\frac{(0.3) (0.4)}{0.24} = \\frac{0.12}{0.24} = \\frac{1}{2}\n\t\\end{align*}\n\tAs you see, applications are everywhere.\n\\end{example}\n\n\\blindtext\n\n\\section{A section with a figure}\n\\blindtext\n\t\\begin{figure}[ht!]\n\t\\centering\n\t\\includegraphics[width=0.3\\linewidth]{figs/truncatedoctahedron}\n\t\\caption{A pretty figure.}\n\t\\label{fig:truncatedoctahedron}\n\t\\end{figure}\n\\blindtext\n\n\n", "meta": {"hexsha": "1da6b3d4abf9a3ebf8da3c4c974ce5e6bdd3b32b", "size": 2237, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "large_thesis/chapters/2_basic_latex.tex", "max_stars_repo_name": "TommyOd/latex_templates", "max_stars_repo_head_hexsha": "6ff43421cbe6f9aca634f779f65cd62f87076be0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2018-08-23T09:46:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T20:28:59.000Z", "max_issues_repo_path": "large_thesis/chapters/2_basic_latex.tex", "max_issues_repo_name": "TommyOd/latex_templates", "max_issues_repo_head_hexsha": "6ff43421cbe6f9aca634f779f65cd62f87076be0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "large_thesis/chapters/2_basic_latex.tex", "max_forks_repo_name": "TommyOd/latex_templates", "max_forks_repo_head_hexsha": "6ff43421cbe6f9aca634f779f65cd62f87076be0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2018-04-03T18:26:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-20T14:53:16.000Z", "avg_line_length": 33.8939393939, "max_line_length": 130, "alphanum_fraction": 0.7103263299, "num_tokens": 707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.7007703110998782}}
{"text": "% !TEX root = index.tex\n\n\\section*{Solutions to selected problems - 2}\n\n\\begin{proof}[Solution to Q.33 Part 1]\n  For linear transformations $\\call: V \\rightarrow W$ and $\\call': W \\rightarrow U$,\n  \\begin{enumerate}\n    \\item \\begin{align*}\n      \\call' \\circ \\call(c \\vec{v})\n      &= \\call' ( \\call(c \\vec{v})) \\\\\n      &= \\call' ( c\\call(\\vec{v})) && \\mbox{ as $\\call$ is a linear transformation}\\\\\n      &= c \\call' ( \\call(\\vec{v})) && \\mbox{ as $\\call'$ is a linear transformation}\n    \\end{align*}\n    \\item \\begin{align*}\n      \\call' \\circ \\call(\\vec{v} + \\vec{w})\n      &= \\call' ( \\call(\\vec{v} + \\vec{w})) \\\\\n      &= \\call' ( \\call(\\vec{v}) + \\call(\\vec{w})) && \\mbox{ as $\\call$ is a linear transformation}\\\\\n      &= \\call' ( \\call(\\vec{v})) + \\call' ( \\call(\\vec{w})) && \\mbox{ as $\\call'$ is a linear transformation}\n    \\end{align*}\n  \\end{enumerate}\n  And so $\\call' \\circ \\call$ is a linear transformation.\n\\end{proof}\n\n\\begin{proof}[Solution to Q.35]\n  $\\call: \\bbr^2 \\rightarrow \\bbr^2$ sending $\\begin{bmatrix} x \\\\y \\end{bmatrix} \\mapsto \\begin{bmatrix} x + 1 \\\\ y \\end{bmatrix}$ is not a linear operator, as it preserves neither scalar multiplication nor vector addition.\n\n  $\\call(\\begin{bmatrix} x \\\\ y \\end{bmatrix}) + \\call(\\begin{bmatrix} x' \\\\ y' \\end{bmatrix}) = \\begin{bmatrix} x+1 \\\\ y \\end{bmatrix} + \\begin{bmatrix} x'+1 \\\\ y' \\end{bmatrix} = \\begin{bmatrix} x+x' + 2 \\\\ y + y' \\end{bmatrix}$\n\n  $\\call(\\begin{bmatrix} x \\\\ y \\end{bmatrix} + \\begin{bmatrix} x' \\\\ y' \\end{bmatrix}) = \\begin{bmatrix} x+x' \\\\ y + y' \\end{bmatrix} = \\begin{bmatrix} x+x' + 1 \\\\ y + y' \\end{bmatrix}$\n\n  so $\\call(\\begin{bmatrix} x \\\\ y \\end{bmatrix}) + \\call(\\begin{bmatrix} x' \\\\ y' \\end{bmatrix}) \\neq \\call(\\begin{bmatrix} x \\\\ y \\end{bmatrix} + \\begin{bmatrix} x' \\\\ y' \\end{bmatrix})$.\n\\end{proof}\n\n\\begin{proof}[Solution to Q.36]\n  A linear transformation $\\call: \\bbr^1 \\rightarrow \\bbr^1$ must preserve scalar multiplication.\n  Hence,\n  \\begin{align}\n    \\label{eq:tag1}\n    \\tag{*}\n    \\call([c]) = \\call(c[1]) = c \\call([1])\n  \\end{align}\n  The addition condition gives us\n  \\begin{align*}\n    \\call([c + d]) = \\call([c]) + \\call([d]) \\\\\n    \\implies (c+d) \\call([1]) = c \\call([1]) + d \\call([1]) && \\mbox{ by \\eqref{eq:tag1}}\n  \\end{align*}\n  But this is always true. So the addition condition does not provide us any new information about $\\call$.\n\n  There are no other conditions. Hence a linear transformation $\\call: \\bbr^1 \\rightarrow \\bbr^1$ is completely determined by $\\call([1])$, which can be any real number, say $[\\alpha]$.\n  Then $\\call([c])$ equals $ [c\\alpha]$, i.e. $\\call$ is a scaling by $\\alpha$.\n\\end{proof}\n\n\\begin{proof}[Solution to Q.38 Part 2]\n  In order to determine the matrix corresponding to $\\rot$ we need to determine $\\rot(\\vec{e}_1)$ and $\\rot(\\vec{e}_2)$.\n  By basic trigonometry,\n  \\begin{align*}\n    \\rot(\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}) &= \\begin{bmatrix} \\cos \\theta \\\\ \\sin \\theta \\end{bmatrix}\\\\\n    \\rot(\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}) &= \\begin{bmatrix} -\\sin \\theta \\\\ \\cos \\theta \\end{bmatrix}\n  \\end{align*}\n  Hence, the corresponding matrix is\n  \\begin{align*}\n    [\\rot] = \\begin{bmatrix} \\cos \\theta & - \\sin \\theta \\\\ \\sin \\theta & \\cos \\theta \\end{bmatrix}\n  \\end{align*}\n\\end{proof}\n\n\\begin{proof}[Solution to Q.39 Part 2]\n  Using the formula for matrix multiplication\n  \\begin{align*}\n    [\\rot] \\begin{bmatrix} x \\\\ y \\end{bmatrix}\n    &= \\begin{bmatrix} \\cos \\theta & - \\sin \\theta \\\\ \\sin \\theta & \\cos \\theta \\end{bmatrix} \\begin{bmatrix} x \\\\ y \\end{bmatrix}\\\\\n    &= x \\begin{bmatrix} \\cos \\theta \\\\ \\sin \\theta \\end{bmatrix} + y \\begin{bmatrix} -\\sin \\theta \\\\ \\cos \\theta \\end{bmatrix} \\\\\n    &= \\begin{bmatrix} x \\cos \\theta - y \\sin \\theta \\\\ x \\sin \\theta + y \\cos \\theta \\end{bmatrix}\n  \\end{align*}\n\\end{proof}\n", "meta": {"hexsha": "0306fc1ee6981b39a2adbcdaa87bb8254632ce56", "size": 3815, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03Supplement.tex", "max_stars_repo_name": "apurvnakade/mc2019-linear-algebra", "max_stars_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "03Supplement.tex", "max_issues_repo_name": "apurvnakade/mc2019-linear-algebra", "max_issues_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "03Supplement.tex", "max_forks_repo_name": "apurvnakade/mc2019-linear-algebra", "max_forks_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.8666666667, "max_line_length": 230, "alphanum_fraction": 0.6062909567, "num_tokens": 1363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.8499711813581708, "lm_q1q2_score": 0.7007688848791908}}
{"text": "\\section{Decision Tree Classifiers}\n\\begin{itemize}\n\t\\item Idea of a Tree: \n\t\\begin{itemize}\n\t\t\\item easy to read \\& interpret\n\t\t\\item robust, though lack of solid theoretical/statistical foundations\n\t\t\\item can use with Ensemble-Methods\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{Setup of a Decision Tree}\n\\begin{itemize}\n\t\\item internal node: test on a \\textbf{attribute}\n\t\\item branch: outcome of the test (eg: true/false, red/green)\n\t\\item leaf node: the \\textbf{classification label/result}\n\\end{itemize}\n\nBuilding an \\textbf{Optimal} Decision Tree:\n\\begin{itemize}\n\t\\item Search Space: $2^{2^m}$ possible trees (m: \\# attributes, 2 result classes)\n\t\\item Complexity: \\textbf{NP-complete}\n\t\\item Solution: \\textbf{Greedy Algorithm} in \\textbf{top-down} approach\n\t\\begin{itemize}\n\t\t\\item All training data at the \\textbf{root}.\n\t\t\\item Partition data \\textbf{recursively} by choosing \\textbf{one attribute} at each level.\n\t\t\\item Each split is assessed with a \\textbf{measure}\n\t\t\\item Attribute with \\textbf{best split} is chosen.\n\t\t\\item Repeat until all \\textbf{leaf nodes} are pure (Not all attributes are necessary).\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{Quality Metrics of a Splitting Attribute}\n\\begin{itemize}\n\t\\item Idea: \n\t\\begin{itemize}\n\t\t\\item the path to classification \\textbf{as easy as possible}. $\\rightarrow$ \\textbf{smallest} tree\n\t\t\\item good separation of classes $\\rightarrow$ leaf nodes gives \\textbf{one single class} $\\rightarrow$ direct decision\n\t\t\\item the separation shouldn't affect class distribution.\n\t\\end{itemize}\n\t\\item Evaluation function:\n\t\\begin{itemize}\n\t\t\\item \\textbf{information gain (ID3/C4.5)}\n\t\t\\item \\textbf{information gain ratio}\n\t\t\\item \\textbf{gini index (CART)}\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsubsection{Information Gain}\n\\begin{itemize}\n\t\\item Idea: choose the attribute that result in \\textbf{smallest tree} $\\rightarrow$ \\textbf{purest} nodes (one class)\n\t\n\t$\\rightarrow$ choose the attribute with \\textbf{greatest information gain}\n\t\n\t$\\rightarrow$ information gain $\\uparrow$, subset average purity $\\uparrow$\n\t\n\t\n\t\\item Parameters:\n\t\\begin{itemize}\n\t\t\\item $c_i$: the \\textbf{absolute frequency} of the training examples in the class $i$\n\t\t\\item $C$: the \\textbf{total number} of training example at the \\textbf{current stage/attribute value}.\n\t\t\\item $p_i$: the \\textbf{relative frequency} of class $i$, $$p_i = \\frac{c_i}{C}$$\n\t\t\\item $N$: the \\textbf{total number of training data}\n\t\\end{itemize}\n\\end{itemize}\n\n\\paragraph{Process: }\n\\begin{enumerate} [label= \\protect \\circled{\\arabic*} ]\n\t\\item calculate \\textbf{initial information} before any splits.\n\t\\item calculate \\textbf{information for each attribute value} using entropy\n\t\\paragraph{Entropy} $\\in [0,1]$, measures how much \\textbf{additional information required} in \\textbf{bits}\n\t$$\\text{entropy}(p_1, \\dots, p_n) = - \\Sigma_{i=1} ^n p_i \\cdot \\log_{2} p_i$$\n\t\\begin{itemize}\n\t\t\\item entropy = 0: pure\n\t\t\\item entropy = 1: maximum impurity (for boolean)\n\t\\end{itemize}\n\t\\paragraph{Information of Each Attribute Value} \n\t\n\t$$\\text{info}([c_1, \\dots, c_n]) = \\text{entropy}(\\frac{c_1}{C}, \\dots, \\frac{c_n}{C})$$ \n\t\\item calculate \\textbf{information of the attribute} \n\t\\paragraph{Information of the Attribute} the \\textbf{weighted average} of the \\textbf{information needed} from each attribute value. \n\t\n\tSay an attribute has $m$ attribute values/branches,\n\t\n\t$$\\text{info}([c_1, \\dots, c_n]_1, \\dots, [c_1, \\dots, c_n]_m) = \\Sigma_{i=1}^m  \\frac{C_m}{N} \\cdot \\text{info}([c_1, \\dots, c_n])_m$$\n\t\n\t\n\t\\item calculate the \\textbf{information gain}\t\n\t\n\t\\paragraph{Information Gain of the Attribute} \n\t\n\t$$\\text{Information\\_Gain(attribute)} = \\text{info(before split by attribute)} - \\text{info(after split by attribute)}$$ \n\t\n\t\\item choose the attribute with \\textbf{maximum} information gain. \n\t\\item continue to split. \n\t\n\t\\textbf{Attention}: the info \\textbf{before} the split is the \\textbf{info(attribute value)}, the information gain of the attribute changes to \n\t\n\teg: gain(Temperature) = \\textbf{info(Outlook = sunny)} - info(high, mild, cool)\n\\end{enumerate}\n\n\\paragraph{Limitations}\n\\begin{itemize}\n\t\\item \\textbf{biased} against \\textbf{highly-branching} attributes (eg: IDs)\n\t\n\t$\\rightarrow$ overfitting\n\t\n\t$\\rightarrow$ Alternative: \\textbf{Gain Ratio}\n\\end{itemize}\n\n\\subsubsection{Gain Ratio}\n\\begin{itemize}\n\t\\item Idea: modification of information gain, reduce bias on highly-branching attributes.\n\t\n\t$\\rightarrow$ considers \\textbf{number and size} of branches $\\rightarrow$ \\textbf{intrinsic information} of attribute\n\t\n\t\\item \\textbf{Intrinsic Information}, s: size of a leaf from each branch\n\t$$\\text{intrinsic\\_info}([s_1, \\dots, s_n]) = \\text{info}([s_1, \\dots, s_n])$$\n\teg: 14 IDs, intrinsic\\_info([1,1,...,1]) = info([1,1,...,1]) = $14 \\cdot (-\\frac{1}{14} \\cdot \\log_{2} \\frac{1}{14}) = 3.807$ bits \n\t\n\t\\item \\textbf{Gain Ratio}: \n\t\n\t$$\\text{Gain\\_Ratio(attribute)} = \\dfrac{\\text{Gain(attribute)}}{\\text{Intrinsic\\_Info(attribute)}}$$\n\t\n\t\\item Process:\n\t\\begin{itemize}\n\t\t\\item calculate the \\textbf{information gain} of the attribute\n\t\t\\item calculate the \\textbf{intrinsic information} of the attribute\n\t\t\\item calculate the \\textbf{gain ratio}\n\t\t\\item choose the attribute that has \\textbf{maximium} the gain ratio.\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsubsection{Gini Index}\n\\begin{itemize}\n\t\\item Use-case: in Classification and Regression Tree (CART)\n\t\\item Solution: select the split that \\textbf{decreases} the Gini Index \\textbf{the most}.\n\t\\item \\textbf{Gini Index}: \n\t$$Gini(S) = 1 - P^2 - N^2$$\n\t$$P = \\frac{p}{p+n}, N = \\frac{n}{p+n}$$\n\t\\item a dataset S is split into $S_1, S_2$, \n\t$$Gini_{split} (S_1,S_2) = \\frac{p_1 + n_1}{p+n} \\cdot Gini(S_1) + \\frac{p_2 + n_2}{p+n} \\cdot Gini(S_2)$$\n\t\n\t$\\rightarrow$ select the attribute with \\textbf{lowest} Gini-Index after split.\n\\end{itemize}\n\n\\subsection{Evaluation of Decision Tree Algorithm}\n\\begin{itemize}\n\t\\item Time Complexity: $\\mathcal{O}(m\\cdot n \\log n)$\n\t\n\t(m: \\# attributes, n: \\# instances)\n\t\\item Scalability for large data:\n\t\\begin{itemize}\n\t\t\\item number of attributes $\\uparrow$, tree size $\\uparrow$, computation time $\\uparrow$.\n\t\t\\item number of data instances $\\uparrow$, memory $\\uparrow$\n\t\\end{itemize} \n\\end{itemize}\n\n\\subsection{Possible Problems in Prediction}\n\\subsubsection{Numeric Attributes in Dataset}\n\\begin{itemize}\n\t\\item Solution: \\textbf{binary split}\n\t\\item Process:\n\t\\begin{itemize}\n\t\t\\item an \\textbf{initial split point} is either given or the middle of the sorted numeric values.\n\t\t\\item values are separated into 2 sections: \\textbf{below(<)} and \\textbf{above($\\geq$)} the split point.\n\t\t\\item calculate \\textbf{information gain}\n\t\t\\item repeat \\textbf{binary split}, choose the split with \\textbf{maiximum information gain}. \n\t\\end{itemize}\n\\end{itemize}\n\n\\subsubsection{Missing Values in Dataset}\n\\begin{itemize}\n\t\\item Possible solutions:\n\t\\begin{itemize}\n\t\t\\item \\textbf{ignore} the instance/attribute with missing values.\n\t\t\\item treat missing value as \\textbf{another nominal value}.\n\t\t\\item \\textbf{estimate} missing values (regression, imputation)\n\t\t\\item \\textbf{follow the leader}: if an instance has missing attribute value, follow the the \\textbf{branch with most instances}.\n\t\t\\item \\textbf{partition} the instance: send down instance \\textbf{proportionally} to the number of instances. \n\t\t\n\t\t$\\rightarrow$ classification result is \\textbf{weighted}.\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsubsection{Overfitting of the Decision Tree}\n\\begin{itemize}\n\t\\item Consequences in Overfitting:\n\t\\begin{itemize}\n\t\t\\item decision tree to \\textbf{large \\& complex}\n\t\t\\item \\textbf{low bias} on training set, \\textbf{high variance} on test set.\n\t\t\\item poor generalization to new data.\n\t\\end{itemize}\n\t\\item Solution: Pruning \n\\end{itemize}\n\n\\subsection{Pruning of Decision Trees}\n\\subsubsection{Prepruning}\nProcess:\n\\begin{itemize}\n\t\\item define a \\textbf{threshold} when to stop creating subtrees. This should be the same measure as determining attributes (eg: information gain)\n\t\\item \\textbf{stop} if the measure \\textbf{no longer exceeds threshold}. (eg: infomation gain)\n\t\\item leaf node: the \\textbf{most frequent class}\n\\end{itemize}\nDifficult to achieve high performance in practice.\n\n\\subsubsection{Postpruning}\n\\begin{itemize}\n\t\n\t\\item Process: \n\t\\begin{itemize}\n\t\t\\item construct a \\textbf{complete} decision tree.\n\t\t\\item prune back by \\textbf{subtree replacement}, replacing the subtree with \\textbf{a single leaf node}.\n\t\t\\item prune back criteria: \\textbf{error rate} estimate for the \\textbf{node} < \\textbf{combined error rates} of the \\textbf{children(weighted average)} \n\t\t\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.65\\textwidth]{prune.png}\n\t\t\\end{figure}\n\t\t$\\rightarrow$ error rate of the node = 0.28 < combined error rate of the children = 0.33 \n\t\t\n\t\t$\\rightarrow$ prune back, the leaf node is the \\textbf{most frequent class}.\n\t\\end{itemize}\n\t\\item Use-case: C4.5, CART, however, computationally expensive\n\t\\item Data for pruning:\n\t\\begin{itemize}\n\t\t\\item hold-out set: an \\textbf{independent} dataset from the training data. Best, but not practical when data is scarce.\n\t\t\\item training data: Used in C4.5, derive \\textbf{outer bound of confidence interval} from data, use a \\textbf{heuristic limit} for error rate. If the \\textbf{error rate is outside the confidence interval} $\\rightarrow$ \\textbf{prune} back. \n\t\t\n\t\t$\\rightarrow$ confidence limit c $\\downarrow$ (25\\% -> 10\\%), the tree prunes \\textbf{stronger}.\n\t\\end{itemize}\n\\end{itemize}\n\n\n\n", "meta": {"hexsha": "cd4308d29f185963c94230dfa697a27d0354e31e", "size": 9546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Business Analytics/lectures/decisiontree.tex", "max_stars_repo_name": "YourPsychiatrist/TUM", "max_stars_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 225, "max_stars_repo_stars_event_min_datetime": "2019-10-02T10:49:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T22:25:38.000Z", "max_issues_repo_path": "Business Analytics/lectures/decisiontree.tex", "max_issues_repo_name": "YourPsychiatrist/TUM", "max_issues_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-02-16T12:22:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-31T19:35:57.000Z", "max_forks_repo_path": "Business Analytics/lectures/decisiontree.tex", "max_forks_repo_name": "YourPsychiatrist/TUM", "max_forks_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 69, "max_forks_repo_forks_event_min_datetime": "2019-10-02T21:46:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T19:27:50.000Z", "avg_line_length": 40.6212765957, "max_line_length": 243, "alphanum_fraction": 0.7282631469, "num_tokens": 2936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7007688673481548}}
{"text": "\\section*{Task 1}\nTransform to $LL(1)$:\n\\begin{align*}\nS \\rightarrow sCT|sCTwB && \\\\\nC \\rightarrow c    && \\\\\nT \\rightarrow t|e  &&  \\\\\nB \\rightarrow Ba|a && \\\\\n&& \\\\\nB \\rightarrow aB' && \\textit{right-recursive} \\\\\nB' \\rightarrow \\epsilon | aB' && \\textit{right-recursive} \\\\\nS' \\rightarrow scT && \\textit{factoring } \\\\\nS{'}{'} \\rightarrow \\epsilon | wB && \\textit{factoring} \\\\\nS \\rightarrow S'S'' && \\textit{factoring} \n\\end{align*}\n\n\\subsection*{Task 1b}\n$\nFIRST(S) \\rightarrow  FIRST(S') \\rightarrow  \\{'s'\\} \\\\\nFIRST(B) \\rightarrow  {'a'} \\\\\nFIRST(B') \\rightarrow  \\{\\epsilon{'}, {'}a{'}\\} \\\\\nFIRST(T') \\rightarrow  \\{{'}sc{'}\\}\n$\n\\newline\n\n$\nFOLLOW(S) \\rightarrow \\{'\\$'\\} \\\\\nFOLLOW(S{'}) \\rightarrow \\{'\\$'\\, w\\} \\\\\nFOLLOW(B) \\rightarrow \\{'\\$'\\} \\\\\nFOLLOW(B{'}) \\rightarrow \\{'\\epsilon'\\} \\\\\nFOLLOW(T) \\rightarrow \\{'\\$'\\}\n$\n\n\\begin{tabular}{|l|l|l|l|l|l|l|}\n    T &w &c &t &a & s & \\$ \\\\\n    \\bottomrule\n    S &  & S' & & & S $\\rightarrow$ S'S''  & \\\\\n    \\bottomrule\n    S' & & & & & S' $\\rightarrow$ scT & \\\\\n    \\bottomrule\n    S'' &S' $\\rightarrow$ wB  & & & &  & \\\\\n    \\bottomrule\n    C & & C $\\rightarrow$ c & & & & \\\\\n    \\bottomrule\n    T & T $\\rightarrow $ w & & T $\\rightarrow$ t & & & T $\\rightarrow \\epsilon $ \\\\\n    \\bottomrule\n    B & & & & B $\\rightarrow$ aB'  &&  \\\\\n    \\bottomrule\n    B' & & & & B $\\rightarrow$ aB' & & B' $\\rightarrow \\epsilon $ \\\\\n    \\bottomrule\n\\end{tabular}\n\n\n\n\\section*{Task 2}\nNote: my VSL parse trees do not exactly match the expected output- an extra node\nis added for the parenthesis. I hope this is okay and simply a trivial error.\n", "meta": {"hexsha": "dd319b251efa0f4212a7fbd05a066bcc56885dd5", "size": 1590, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ex2/doc/src/content.tex", "max_stars_repo_name": "andsild/TDT4205", "max_stars_repo_head_hexsha": "3d7c1e7d0ed91fca280d4c7fedb01839ae49e97e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ex2/doc/src/content.tex", "max_issues_repo_name": "andsild/TDT4205", "max_issues_repo_head_hexsha": "3d7c1e7d0ed91fca280d4c7fedb01839ae49e97e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ex2/doc/src/content.tex", "max_forks_repo_name": "andsild/TDT4205", "max_forks_repo_head_hexsha": "3d7c1e7d0ed91fca280d4c7fedb01839ae49e97e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-02-25T18:27:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T14:50:40.000Z", "avg_line_length": 27.8947368421, "max_line_length": 83, "alphanum_fraction": 0.5490566038, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.84997116805678, "lm_q1q2_score": 0.7007688665806368}}
{"text": "\nIn this section a background of the theory behind the combinatorial games studied for this thesis is provided. In addition to this, the notation introduced here is used throughout the thesis. \n\n\\subsection{Partially Ordered Sets}\nThis thesis is about a type of combinatorial games called \\emph{poset games}. In order to be able to introduce the theory of these games, we must first define what a poset is.\n\\begin{defn}[Partially Ordered Sets{\\cite[p.~278]{stanley2011}}]\nA \\emph{partially ordered set} (\\emph{poset}) $(P,\\le)$ is a set with a binary order relation $\\le$ satisfying the following three axioms:\n\\begin{enumerate}\n\\item For all $t\\in P$, $t\\le t$ (reflexivity).\n\\item If $s\\le t$ and $t\\le s$,then $s=t$ (antisymmetry).\n\\item If $s\\le t$ and $t\\le u$,then $s\\le u$ (transitivity).\n\\end{enumerate}\n\\end{defn}\n~\\\\\nWe use the obvious notation $t\\ge s$ to mean $s\\le t$, $s<t$ to mean $s\\le t$ and $s\\ne t$, and $t>s$ to mean $s<t$. We say that two elements $s$ and $t$ of $P$ are \\emph{comparable} if $s\\le t$ or $t\\le s$, otherwise $s$ and $t$ are \\emph{incomparable}.\n\\\\\nWe define an \\emph{interval} $[p,q]$ of a poset to be $\\{x\\in P\\;|\\;p\\le x\\le q\\}$. We say that $v$ covers $u$ if $[u,v]=\\{u,v\\}$, and we denote this by $u\\lessdot v$.\n\\\\\\\\\nIn a partizan element removal game, every element must have a color.\n%\\\\\n\\begin{defn}[Colored Posets]\nA \\emph{colored poset} is a poset where each element has a color of either black or white.\n\\end{defn}\n\\begin{ex}{}\n\\label{ex:posets}\nAn example of a regular and a colored poset. %The elements higher up are greater than those lower down. The greatest element is comparable to all other elements, but the elements second highest up are not comparable to each other.\n\\\\\n\\begin{minipage}[b]{0.495\\textwidth}\n%\\begin{figure}[h]\n\\centering\n\\begin{tikzpicture}[scale=.45]\n  \\draw[thick] (0,0) -- (-3,2) -- (-3,5) -- (0,7) -- (3,5) -- (3,2) -- (0,0);\n  \\draw[thick] (3,5) -- (0,2) -- (-3,5);\n  \\draw[thick] (0,0) -- (0,2);\n  \\draw[thick] (-3,2) -- (0,5) -- (3,2);\n  \\draw[thick] (0,5) -- (0,7);\n  \\node (zero) at (0,0) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (1) at (-3,2) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (2) at (0,2) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (3) at (3,2) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (4) at (-3,5) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (5) at (0,5) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (6) at (3,5) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (7) at (0,7) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n\\end{tikzpicture}\n\\captionof{figure}{Example of a poset.}\n%\\end{figure}\n\\end{minipage}\n\\begin{minipage}{0.01\\textwidth}\n~\n\\end{minipage}\n\\begin{minipage}[b]{0.495\\textwidth}\n%\\begin{figure}[H]\n\\centering\n\\begin{tikzpicture}[scale=.45]\n  \\draw[thick] (0,0) -- (-3,2) -- (-3,5) -- (0,7) -- (3,5) -- (3,2) -- (0,0);\n  \\draw[thick] (3,5) -- (0,2) -- (-3,5);\n  \\draw[thick] (0,0) -- (0,2);\n  \\draw[thick] (-3,2) -- (0,5) -- (3,2);\n  \\draw[thick] (0,5) -- (0,7);\n  \\node (zero) at (0,0) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (1) at (-3,2) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (2) at (0,2) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n  \\node (3) at (3,2) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n  \\node (4) at (-3,5) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n  \\node (5) at (0,5) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (6) at (3,5) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (7) at (0,7) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n\\end{tikzpicture}\n\\captionof{figure}{Example of a colored poset.}\n%\\end{figure}\n\\end{minipage}\n\\end{ex}\n~\\\\%\\newpage\nIn particular, this thesis focuses on poset games with a specific coloring called chess-coloring.\n\\\\\n\\begin{minipage}[t]{0.40\\textwidth}\n\\begin{defn}[Chess-Colored Posets]\nA \\emph{chess-colored poset} is a colored poset such that no element covers an element of the same color. Equivalently we may regard $P=W\\cup B$ as a bipartite graph, with white vertices $W$ and black vertices $B$, with the cover relation as an edge relation.\n\\\\\nTo avoid confusion, we will assume that the least element is colored white when there is only one smallest element.\n\\end{defn}\n\\end{minipage}\n\\begin{minipage}{0.04\\textwidth}\n~\n\\end{minipage}\n%\\begin{figure}[h]\n\\begin{minipage}[t]{0.55\\textwidth}\n\\begin{ex}{}~\n\\\\\n\\begin{center}\n\\begin{tikzpicture}[baseline=0.65ex,scale=.5]\n  \\draw[thick] (0,0) -- (-3,2) -- (-3,5) -- (0,7) -- (3,5) -- (3,2) -- (0,0);\n  \\draw[thick] (3,5) -- (0,2) -- (-3,5);\n  \\draw[thick] (0,0) -- (0,2);\n  \\draw[thick] (-3,2) -- (0,5) -- (3,2);\n  \\draw[thick] (0,5) -- (0,7);\n  \\node (zero) at (0,0) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (1) at (-3,2) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n  \\node (2) at (0,2) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n  \\node (3) at (3,2) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n  \\node (4) at (-3,5) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (5) at (0,5) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (6) at (3,5) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (7) at (0,7) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n\\end{tikzpicture}\n%\\caption{Example of a chess-colored poset.}\n\\captionof{figure}{Example of a chess-colored poset.}\n\\end{center}\n\\end{ex}\n\\end{minipage}\n%\\end{figure}\n%\\begin{minipage}{0.05\\textwidth}\n%~\n%\\end{minipage}\n%\\begin{minipage}[b]{0.475\\textwidth}\n%\\centering\n%\\begin{tikzpicture}[scale=.5]\n%  \\node (zero) at (0,0) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n%  \\node (1) at (-3,2) {\\tikz\\draw[black,fill=black] (0,0) circle (.5ex);};\n%  \\node (2) at (0,2) {\\tikz\\draw[black,fill=black] (0,0) circle (.5ex);};\n%  \\node (3) at (3,2) {\\tikz\\draw[black,fill=black] (0,0) circle (.5ex);};\n%  \\node (4) at (-3,5) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n%  \\node (5) at (0,5) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n%  \\node (6) at (3,5) {\\tikz\\draw[black,fill=white] (0,0) circle (.5ex);};\n%  \\node (7) at (0,7) {\\tikz\\draw[black,fill=black] (0,0) circle (.5ex);};\n%  \\draw[thick] (zero) -- (1) -- (4);\n%  \\draw[thick] (6) -- (2) -- (zero);\n%  \\draw[thick] (5) -- (7);\n%  \\draw[thick] (1) -- (5) -- (7);\n%  \\draw[thick] (zero) -- (3);\n%\\end{tikzpicture}\n%\\captionof{figure}{Example of a (chess-colored) tree poset.}\n%\\end{minipage}\n%%\\end{figure}\n%\\\\\\\\\n%%\\begin{minipage}[b]{0.5\\textwidth}\n%\\begin{defn}[Tree Posets]\n%A \\emph{tree poset} is a poset that, when regarded as a graph with the cover relations as undirected edges, has no cycles. A forest poset is a poset where all components of the poset (when the poset is regarded as a graph with the cover relations as undirected edges) are tree posets.\n%\\end{defn}\n%%\\end{minipage}\n%%\\begin{minipage}{0.1\\textwidth}\n%%~\n%%\\end{minipage}\n%%\\begin{figure}[h]\n%%\n\\subsubsection{Young Diagrams}\nThis thesis mainly focuses on an object called \\emph{Young diagram}. We will formally define exactly what a Young diagram is in Definition \\ref{def:lambda}, but before that we need the following definition:\n\\begin{defn}\n\\label{def:lambda}\nLet $\\lambda=(\\lambda_1,\\dots,\\lambda_k)$ be a weakly decreasing sequence of positive integers, i.e., $\\lambda_1\\ge \\lambda_2\\ge\\dots\\ge \\lambda_k$. We say that $\\lambda$ partitions $n$, denoted by $\\lambda\\vdash n$, if $\\sum_{i=1}^k\\lambda_i =n$.\n\\end{defn}\n%~\n\\begin{defn}[Young Diagrams%{\\cite[p.~155]{hk2002}}\n]\nA \\emph{Young diagram} is a collection of boxes arranged in left-justified rows with a weakly decreasing number of boxes in each row. If the number of boxes is $n$ and $\\lambda\\vdash n$, we say that $\\lambda$ generate a Young diagram with $\\lambda_1$ boxes in the first row, $\\lambda_2$ boxes in the second row,$\\dots$, $\\lambda_k$ in the $k$'th row.\nMoreover, a Young diagram can always be represented as a poset.\n\\end{defn}\n~\\\\\nThis definition is best illustrated with an example. \n\\begin{ex}{}\nWith $\\lambda=(7,5,2,2,1)$ we have the Young diagram in Figure \\ref{fig:youngex} and the corresponding representation as a poset in Figure \\ref{fig:youngposetex}.\n\\\\\n%\\begin{picex}{}\n\\begin{minipage}[b]{0.45\\textwidth}\n%\\begin{math}\n\\centering\n\\begin{tabular}{ | c | c | c | c | c | c | c |}\n\\hline\n~&~&~&~&~&~&~\\\\\n\\hline\n~&~&~&~&~\\\\\n\\cline{1-5}\n~&~\\\\\n\\cline{1-2}\n~&~\\\\\n\\cline{1-2}\n~\\\\\n\\cline{1-1}\n\\end{tabular}\n%\\end{math}\n\\captionof{figure}{Young diagram generated by $\\lambda=(7,5,2,2,1)$.}\n\\label{fig:youngex}\n\\end{minipage}\n%\\begin{center}\n%\\begin{figure}\n%\\begin{Young}\n %& & & & & & \\cr\n %& & & & \\cr\n %& \\cr\n %& \\cr\n %\\cr\n%\\end{Young}\n%\\end{figure}\n%\\end{center}\n\\begin{minipage}{0.05\\textwidth}\n~%This Young diagram can also be represented as the following poset:\n\\end{minipage}\n\\begin{minipage}[b]{0.50\\textwidth}\n\\centering\n\\begin{tikzpicture}[scale=.5]\n  \\draw[thick] (0,0) -- (-1,1) -- (-2,2) -- (-3,3) -- (-4,4) -- (-5,5) -- (-6,6);\n  \\draw[thick] (1,1) -- (0,2) -- (-1,3) -- (-2,4) -- (-3,5);\n  \\draw[thick] (2,2) -- (1,3);\n  \\draw[thick] (3,3) -- (2,4);\n  \\draw[thick] (0,0) -- (1,1) -- (2,2) -- (3,3) -- (4,4);\n  \\draw[thick] (-1,1) -- (0,2) -- (1,3) -- (2,4);\n  \\draw[thick] (-2,2) -- (-1,3);\n  \\draw[thick] (-3,3) -- (-2,4);\n  \\draw[thick] (-4,4) -- (-3,5);\n  \\node (zero) at (0,0) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (1) at (-1,1) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (2) at (-2,2) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (3) at (-3,3) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (4) at (-4,4) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (5) at (-5,5) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (6) at (-6,6) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (7) at (1,1) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (8) at (0,2) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (9) at (-1,3) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (10) at (-2,4) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (11) at (-3,5) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (12) at (2,2) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (13) at (1,3) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (14) at (3,3) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (15) at (2,4) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (16) at (4,4) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n\\end{tikzpicture}\n\\captionof{figure}{Poset of the Young diagram generated by $\\lambda=(7,5,2,2,1)$.}\n\\label{fig:youngposetex}\n\\end{minipage}\n\\end{ex}\nIn analogy with the previous definitions, a colored Young diagram is a Young diagram where each box has a color of either black or white, and a chess-colored Young diagram is a Young diagram where no adjacent boxes have the same color.\n%\\\\\n\\begin{ex}{}\nWith $\\lambda=(7,5,2,2,1)$ as before, we have the chess-colored Young diagram and the corresponding chess-colored poset in Figures \\ref{fig:chessyoung} and \\ref{fig:chessyoungposet} respectively.\n\\\\\n%\\begin{picex}{}\n\\begin{minipage}[b]{0.45\\textwidth}\n%\\begin{figure}[H]\n\\centering\n\\begin{tabular}{ | c | c | c | c | c | c | c |}\n\\hline\n~&\\cellcolor[gray]{0}&~&\\cellcolor[gray]{0}&~&\\cellcolor[gray]{0}&~\\\\\n\\hline\n\\cellcolor[gray]{0}&~&\\cellcolor[gray]{0}&~&\\cellcolor[gray]{0}\\\\\n\\cline{1-5}\n~&\\cellcolor[gray]{0}\\\\\n\\cline{1-2}\n\\cellcolor[gray]{0}&~\\\\\n\\cline{1-2}\n~\\\\\n\\cline{1-1}\n\\end{tabular}\n\\captionof{figure}{Chess-colored Young diagram generated by $\\lambda=(7,5,2,2,1)$.}\n\\label{fig:chessyoung}\n%\\end{figure}\n\\end{minipage}\n\\begin{minipage}{0.05\\textwidth}\n~\n\\end{minipage}\n\\begin{minipage}[b]{0.5\\textwidth}\n%\\begin{figure}[H]\n\\centering\n\\begin{tikzpicture}[scale=.5]\n  \\draw[thick] (0,0) -- (-1,1) -- (-2,2) -- (-3,3) -- (-4,4) -- (-5,5) -- (-6,6);\n  \\draw[thick] (1,1) -- (0,2) -- (-1,3) -- (-2,4) -- (-3,5);\n  \\draw[thick] (2,2) -- (1,3);\n  \\draw[thick] (3,3) -- (2,4);\n  \\draw[thick] (0,0) -- (1,1) -- (2,2) -- (3,3) -- (4,4);\n  \\draw[thick] (-1,1) -- (0,2) -- (1,3) -- (2,4);\n  \\draw[thick] (-2,2) -- (-1,3);\n  \\draw[thick] (-3,3) -- (-2,4);\n  \\draw[thick] (-4,4) -- (-3,5);\n  \\node (zero) at (0,0) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (1) at (-1,1) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n  \\node (2) at (-2,2) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (3) at (-3,3) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n  \\node (4) at (-4,4) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (5) at (-5,5) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n  \\node (6) at (-6,6) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (7) at (1,1) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n  \\node (8) at (0,2) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (9) at (-1,3) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n  \\node (10) at (-2,4) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (11) at (-3,5) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n  \\node (12) at (2,2) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (13) at (1,3) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n  \\node (14) at (3,3) {\\tikz\\draw[black,fill=black] (0,0) circle (1ex);};\n  \\node (15) at (2,4) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n  \\node (16) at (4,4) {\\tikz\\draw[black,fill=white] (0,0) circle (1ex);};\n\\end{tikzpicture}\n\\captionof{figure}{Chess-colored poset of the Young diagram in figure \\ref{fig:chessyoung}.}\n\\label{fig:chessyoungposet}\n%\\end{figure}\n\\end{minipage}\n\\end{ex}\n\n\n\\subsection{Combinatorial Game Theory}\nThis thesis deals with combinatorial game theory, an area which studies sequential games with perfect information, that is, games where the players play in turns and where they have complete knowledge of the game, i.e., know all possible game options for all players. \n\\\\\nIn particular, the thesis will focus on two-player partizan combinatorial games, in which the game options of the two players can be different. Furthermore, we call the two players Left and Right (or White and Black or Blue and Red).\n\\\\\nIn general, a combinatorial game has \\emph{positions}, and at any given position every player has a set of \\emph{options} of moving to a new position. Under normal play convention a player loses if they have no options available at their turn to move.\n%\\\\\n\\begin{defn}[Partizan Game Position{\\cite[p.~71]{onag}}]\nA position in a partizan game is defined by its left and right options, and we denote it by $G=\\{L|R\\}$, where $L$ and $R$ are the sets of left and right options respectively. \n\\end{defn}\n~\\\\\nSince we will be using the notation used by Conway\\cite{onag}, the notation above will not always be used, and we will instead often abuse it by writing $G=\\{G_1,G_2,G_3|H_1,H_2\\}$ as short for $G=\\left\\{\\{G_1,G_2,G_3\\}|\\{H_1,H_2\\}\\right\\}$, and in the general case $G=\\{G^L|G^R\\}$.\n\\\\\nFollowing this we will introduce some notation for the games depending on the winner and who starts.\n%\\\\\n\\begin{defn}[Value Notation{\\cite[p.~73]{onag}}]\n\\label{def:value}\n~\n\\begin{itemize}\n\\item $G>0$ ($G$ is \\emph{positive}) if there is a winning strategy for Left.\n\\item $G<0$ ($G$ is \\emph{negative}) if there is a winning strategy for Right.\n\\item $G=0$ ($G$ is \\emph{zero}) if there is a winning strategy for the second player to move.\n\\item $G\\parallel0$ ($G$ is \\emph{fuzzy} to zero) if there is a winning strategy for first player move.\n\\end{itemize}\n\\end{defn}\n~\\\\\nThis notation is easy to understand with help of some examples.\n%\\\\\n\\begin{ex}{}\nConsider the simplest possible game, the game with no options for either player, i.e., $G_1=\\{|\\}$. We obviously have $G_1=0$, since the first player has no options to play and therefore loses. This game is denoted by $0:=\\{|\\}$.\n\\\\\nNow consider the game where Left has the option to move to $0$, but Right still has no options, i.e., $G_2=\\{0|\\}$. Here we have that $G_2>0$ since either Left starts and moves to $0$, and then Right has no option and loses, or Right starts and has no options and therefore loses, i.e., Left has a winning strategy. This game is denoted by $1:=\\{0|\\}$. Similarly we have that the game $-1<0$ where $-1$ is defined as $-1:=\\{|0\\}$.\n\\\\\nFinally, consider the game where both players have the option to move to $0$, i.e., $G_3=\\{0|0\\}$. We now have $G_3\\parallel0$ since both players have the option to move to $0$, where the second player then will lose. This game is denoted as $*:=\\{0|0\\}$.\n\\end{ex}\n%\\newpage\n~\\\\\nThe value notation of Definition \\ref{def:value} can be combined and extended in the following way.\n\\begin{defn}[Extended Value Notation{\\cite[p.~73]{onag}}]\n\\label{def:extvalue}~\n\\begin{itemize}\n\\item If $G\\ge0$, then Left always wins if Left is the second player to move.\n\\item If $G\\le0$, then Right always wins if Right is the player second to move.\n\\item If $G\\rhd0$, then Left always wins if Left is the first player to move.\n\\item If $G\\lhd0$, then Right always wins if Right is the first player to move.\n\\end{itemize}\n\\end{defn}\n~\\\\\nIn addition to the value notations, it is also possible to add and subtract games.\n\\begin{defn}[Addition and Negation{\\cite[p.~73]{onag}}]\n\\begin{align*}\nG+H&=\\left\\{G^L+H,G+H^L\\middle|G^R+H,G+H^R\\right\\}\\\\\n-G&=\\left\\{-G^R\\middle|-G^L\\right\\}\n\\end{align*}\n\\end{defn}\n~\\\\\nInformally, we can note that addition of two games is the same as playing in both games at the same time, and the negation of a game is the game with reversed roles of Left and Right. Combining these, it is possible to subtract games as $G-H=G+(-H)$. \n\\\\\nUsing this, we define the following relations between games:\n\\begin{defn}[Game Relations{\\cite[p.~78]{onag}}]\n~\n\\begin{itemize}\n\\item $G>H$ iff $G-H>0$.\n\\item $G<H$ iff $G-H<0$.\n\\item $G=H$ iff $G-H=0$.\n\\item $G\\parallel H$ iff $G-H\\parallel0$.\n\\end{itemize}\n\\end{defn}\n~\\\\\nUsing these relations, which can be combined and extended as the extended notation of Definition \\ref{def:extvalue}, we can define what a \\emph{dominated} option is.\n\\begin{defn}[Dominated Options{\\cite[p.~110]{onag}}]\n\\label{def:dominate}\nFor a game we say that a left option $G^{L_1}$ is dominated by another left option option $G^{L_0}$ if $G^{L_1}\\le G^{L_0}$. Similarly, a right option $G^{R_1}$ is dominated by another right option $G^{R_0}$ if $G^{R_1}\\ge G^{R_0}$.\n\\end{defn}\n~\\\\\nIn fact, an important property of a game is that you always can remove any dominated options{\\cite[p.~110]{onag}}.\n\\begin{thm}\n\\label{thm:domopt}\nLet $G=\\left\\{G^{L_0},G^{L_1},\\dots|G^{R_0},G^{R_1}\\dots,\\right\\}$. \n\\begin{itemize}\n\\item If $G^{L_0}\\le G^{L_1}$, then $G=G'$, where $G'=\\left\\{G^{L_1},\\dots|G^{R_0},G^{R_1}\\dots,\\right\\}$.\n\\item If $G^{R_0}\\ge G^{R_1}$, then $G=G''$, where $G''=\\left\\{G^{L_0},G^{L_1},\\dots|G^{R_1}\\dots,\\right\\}$.\n\\end{itemize}\n\\end{thm}\n~\\\\\nA significant class of games are the \\emph{short} games.\n\\begin{defn}[Short Games{\\cite[p.~3]{lip}\\cite[p.97]{onag}}]\nA game G is short if only a finite number of positions can be reached and a position may never be repeated.\n\\end{defn}\n~\\\\\nMoreover, every short game $G$ has a unique simplest form. This is called $G$'s canonical form{\\cite[p.~78]{lip}}. It is possible to reduce any short game to its canonical form by just removing dominated and \\emph{reversible} options{\\cite[p.~111]{onag}}.\n\\\\\\\\\nA methodology that is extremely useful when proving properties of games is \\emph{Conway induction}.\n\\begin{thm}[Conway Induction{\\cite[p.~5]{onag}}]\n\\label{thm:conind}\nLet $P$ be a property which games might have, such that any game $G$ has property $P$ whenever all left and right options of $G$ have this property. Then every game has property $P$.\n\\end{thm}\n~\\\\\nThe methodology using Conway induction makes it possible to prove that a game has a property by assuming that all its options have this property, and from this proving that the game itself has it. This methodology is using that the definitions of games are inductive.\n\\subsubsection{Numbers}\n\\label{section:numbers}\nAnother important property and concept in combinatorial games is that of numbers, which is a class of games with some special characteristics. \n%\\\\\n\\begin{defn}[Numbers{\\cite[p.~91]{lip}}]\nA number is any game $x$ such that all $x^L<x<x^R$ and $x^L$ and $x^R$ are numbers.\nFor short games, we can, equivalently, for $j>0$ and $m$ odd, define a number as\n\\begin{equation}\n\\frac{m}{2^j}=\\left\\{\\frac{m-1}{2^j}\\Bigg|\\frac{m+1}{2^j}\\right\\}.\n\\label{eq:number}\n\\end{equation}\n\\label{def:number}\n\\end{defn}\n~\\\\\nIt should also be noted that all games are not numbers. For $*=\\{0|0\\}$ we have $G^L=0=G^R$, and hence $G^L\\not<G^R$, i.e., $*$ is not a number.\n\\\\\nEquation (\\ref{eq:number}) can be generalized to recognize when $G$ is a number even if it is not in canonical form. For this, we need to define what the \\emph{simplest number} is.\n%\\\\\n\\begin{defn}[Simplest Number{\\cite[p.~93]{lip}}]\n\\label{def:simpnum}\nFor $x^L<x^R$, the simplest number $x$ between $x^L$ and $x^R$ is given by the following:\n\\begin{itemize}\n\\item If there are integer(s) $n$ such that $x^L<n<x^R$, $x$ is the one that is smallest in absolute value.\n\\item Otherwise, $x$ is the number of the form $\\frac{i}{2^j}$ between $x^L$ and $x^R$ for which $j$ is minimal.\n\\end{itemize}\n\\end{defn}\n%~\n\\begin{thm}[Numbers{\\cite[p.~93]{lip}}]\n\\label{thm:number}\nIf all options of a game $G$ are numbers and all $G^L<G^R$, then $G$ is the simplest number $x$ satisfying $G^L<x<G^R$. \n\\end{thm}\n~\\\\\nThis, together with Definition \\ref{def:dominate} and Theorem \\ref{thm:domopt}, yields that a game that is equal to a number is equal to the game consisting of only its greatest left options and smallest right options, i.e., \n$G\\equiv\\left\\{G^{L_0},G^{L_1},\\dots|G^{R_0},G^{R_1}\\dots,\\right\\}=\\left\\{G^{L_0}|G^{R_0}\\right\\}\\equiv G'$ if $G^{L_0}\\ge G^{L_i}$ and $G^{R_0}\\le G^{R_j}$ for $i,j>0$. \n\\\\\nIt should also be noted that equation (\\ref{eq:number}) is a number for integers $j>0$ and $m$, regardless if $m$ is odd or not.\n\n\\subsubsection{Hackenbush}\nA game with properties similar to the ones studied in this thesis is \\emph{Blue-Red Hackenbush}. Hackenbush is a partizan two-player game that may be played on any configuration of colored line segments connected to one another by their endpoints and to a \"ground\" line. In the Blue-Red Hackenbush, the line segments are colored either blue or red. It is played by, in turns, removing a line segment of your color, by which all segments that are unconnected to the ground vanishes, until a player has no move left.\n\\begin{ex}{}\n\\label{ex:hack}\nAn example of a game of Blue-Red Hackenbush and gameplay on that game.\n\\begin{figure}[H]\n\\centering\n{\\Large\n$\n\\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]\n    \\draw[densely dashed] (-1,-1) -- (1,-1);\n    \\node[hackennode] (middle) at ( 0,   0) {};\n    \\node[hackennode] (left)   at (-0.5,-1) {};\n    \\node[hackennode] (right)  at ( 0.5,-1) {};\n    \\node[hackennode] (top)    at ( 0,   1) {};\n    \\node[hackennode] (top2)   at ( 0,   2) {};\n\n    \\draw[hackenline,blue]\n        (left) -- (middle) -- (right);\n    \\draw[hackenline,red!75]\n        (middle) -- (top);\n    \\draw[hackenline,red!75]\n        (top) -- (top2);\n\\end{tikzpicture}\n=\n\\left\\{\n\\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]\n    \\draw[densely dashed] (-0.5,-1) -- (1,-1);\n    \\node[hackennode] (middle) at ( 0,   0) {};\n    \\node[hackennode] (right)  at ( 0.5,-1) {};\n    \\node[hackennode] (top)    at ( 0,   1) {};\n    \\node[hackennode] (top2)   at ( 0,   2) {};\n\n    \\draw[hackenline,blue]\n        (middle) -- (right);\n    \\draw[hackenline,red!75]\n        (middle) -- (top);\n    \\draw[hackenline,red!75]\n        (top) -- (top2);\n\\end{tikzpicture}\n\\tikz[baseline=-0.65ex,scale=0.5] \\node[inner sep=0] at (0,-1) {,\\,};\n\\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]\n    \\draw[densely dashed] (-1,-1) -- (0.5,-1);\n    \\node[hackennode] (middle) at ( 0,   0) {};\n    \\node[hackennode] (left)   at (-0.5,-1) {};\n    \\node[hackennode] (top)    at ( 0,   1) {};\n    \\node[hackennode] (top2)   at ( 0,   2) {};\n\n    \\draw[hackenline,blue]\n        (middle) -- (left);\n    \\draw[hackenline,red!75]\n        (middle) -- (top);\n    \\draw[hackenline,red!75]\n        (top) -- (top2);\n\\end{tikzpicture}\n\\middle|\n\\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]\n    \\draw[densely dashed] (-0.5,-1) -- (1,-1);\n    \\node[hackennode] (middle) at ( 0,   0) {};\n    \\node[hackennode] (left)   at (-0.5,-1) {};\n    \\node[hackennode] (right)  at ( 0.5,-1) {};\n    \\node[hackennode] (top)    at ( 0,   1) {};\n\n    \\draw[hackenline,blue]\n        (left) -- (middle) -- (right);\n    \\draw[hackenline,red!75]\n        (middle) -- (top);\n\\end{tikzpicture}\n\\tikz[baseline=-0.65ex,scale=0.5] \\node[inner sep=0] at (0,-1) {,\\,};\n\\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]\n    \\draw[densely dashed] (-1,-1) -- (0.5,-1);\n    \\node[hackennode] (middle) at ( 0,   0) {};\n    \\node[hackennode] (left)   at (-0.5,-1) {};\n    \\node[hackennode] (right)  at ( 0.5,-1) {};\n\n    \\draw[hackenline,blue]\n        (left) -- (middle) -- (right);\n\\end{tikzpicture}\n\\right\\}\n$\n}% End group with \\Large\n\\caption{A simple game of Blue-Red Hackenbush.}\n\\label{fig:hackenbush}\n\\end{figure}\n\\begin{figure}[H]\n{\\Large\n\\[\n\\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]\n    \\draw[densely dashed] (-1,-1) -- (1,-1);\n    \\node[hackennode] (middle) at ( 0,   0) {};\n    \\node[hackennode] (left)   at (-0.5,-1) {};\n    \\node[hackennode] (right)  at ( 0.5,-1) {};\n    \\node[hackennode] (top)    at ( 0,   1) {};\n    \\node[hackennode] (top2)   at ( 0,   2) {};\n\n    \\draw[hackenline,blue]\n        (left) -- (middle) -- node[strike out,draw=black,line width=1,-]{}(right);\n    \\draw[hackenline,red!75]\n        (middle) -- (top);\n    \\draw[hackenline,red!75]\n        (top) -- (top2);\n\\end{tikzpicture}\n\\overset{L}{\\longrightarrow}\n\\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]\n    \\draw[densely dashed] (-1,-1) -- (0.5,-1);\n    \\node[hackennode] (middle) at ( 0,   0) {};\n    \\node[hackennode] (left)   at (-0.5,-1) {};\n    \\node[hackennode] (top)    at ( 0,   1) {};\n    \\node[hackennode] (top2)   at ( 0,   2) {};\n\n    \\draw[hackenline,blue]\n        (middle) -- (left);\n    \\draw[hackenline,red!75]\n        (middle) -- (top);\n    \\draw[hackenline,red!75]\n        (top) -- node[strike out,draw=black,line width=1,-]{}(top2);\n\\end{tikzpicture}\n\\overset{R}{\\longrightarrow}\n\\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]\n    \\draw[densely dashed] (-0.5,-1) -- (1,-1);\n    \\node[hackennode] (middle) at ( 0,   0) {};\n    \\node[hackennode] (left)   at (-0.5,-1) {};\n    \\node[hackennode] (top)    at ( 0,   1) {};\n\n    \\draw[hackenline,blue]\n        (middle) -- node [sloped,strike out,draw=black,line width=1,-]{}(left);\n    \\draw[hackenline,red!75]\n        (middle) -- (top);\n\\end{tikzpicture}\n\\overset{L}{\\longrightarrow}\n\\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]\n    \\draw[densely dashed] (-1,-1) -- (0.5,-1);\n\\end{tikzpicture}\n\\]\n}% End group with \\Large\n\\caption{Example of gameplay on the Blue-Red Hackenbush in Figure \\ref{fig:hackenbush} where Left player wins.}\n\\end{figure}\n\\end{ex}\nIt is known that every game of Blue-Red Hackenbush is a surreal number, and in particular, any \\emph{finite} game of Blue-Red Hackenbush is a dyadic rational number, i.e., on the form $\\frac{m}{2^j}$ where $m$ and $j>0$ are integers.\n\\subsubsection{Chomp}\n\\label{section:chomp}\n\\begin{minipage}[b]{0.5\\textwidth}\nAnother game closely related to that of this thesis is the game of \\emph{Chomp}. Chomp is a impartial two-player game with the usual starting position consisting of a rectangle (possibly infinite) with one poison square in the lower-left corner. A move in Chomp is to choose a square and remove this and all other squares above or to the right of it, and a player loses if they has to choose the poison square.\n\\end{minipage}\n\\begin{minipage}{0.05\\textwidth}\n~\n\\end{minipage}\n\\begin{minipage}[b]{0.45\\textwidth}\n%\\begin{figure}[H]\n\\centering\n\\begin{tabular}{ | c | c | c | c | c |}\n\\hline\n~&~&~&~&~\\\\\n\\hline\n~&~&~&~&~\\\\\n\\hline\n~&~&~&~&~\\\\\n\\hline\n~&~&~&~&~\\\\\n\\hline\n~&~&~&~&~\\\\\n\\hline\n~&~&~&~&~\\\\\n\\hline\n\\cellcolor{red}&~&~&~&~\\\\\n\\hline\n\\end{tabular}\n\\captionof{figure}{Example of a starting position of a game of Chomp.}\n\\label{fig:chompstart}\n%\\end{figure}\n\\end{minipage}\n\\begin{ex}{}\n\\label{ex:chompgame}\nAn example of gameplay on a game of Chomp with starting position as in Figure \\ref{fig:chompstart}.\n\\begin{figure}[H]\n\\centering\n$\n\\begin{tabular}{ | c | c | c | c | c |}\n\\hhline{-----}\n~&~&~&\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}\\\\\n\\hhline{-----}\n~&~&~&\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}\\\\\n\\hhline{-----}\n~&~&~&\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}\\\\\n\\hhline{-----}\n~&~&~&\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}\\\\\n\\hhline{-----}\n~&~&~&\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}\\\\\n\\hhline{-----}\n~&~&~&\\cellcolor[gray]{0.6}&\\cellcolor[gray]{0.8}\\\\\n\\hhline{-----}\n\\cellcolor{red}&~&~&~&~\\\\\n\\hhline{-----}\n\\end{tabular}\n\\overset{L}{\\longrightarrow}\n\\begin{tabular}{ | c | c | c | c | c |}\n\\hhline{---~~}\n\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}\\\\\n\\hhline{---~~}\n\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}\\\\\n\\hhline{---~~}\n\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}\\\\\n\\hhline{---~~}\n\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}\\\\\n\\hhline{---~~}\n\\cellcolor[gray]{0.6}&\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}\\\\\n\\hhline{---~~}\n~&~&~\\\\\n\\hhline{-----}\n\\cellcolor{red}&~&~&~&~\\\\\n\\hhline{-----}\n\\end{tabular}\n\\overset{R}{\\longrightarrow}\n\\begin{tabular}{ | c | c | c | c | c |}\n\\hhline{---~~}\n~&\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}\\\\\n\\hhline{-----}\n\\cellcolor{red}&\\cellcolor[gray]{0.6}&\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}&\\cellcolor[gray]{0.8}\\\\\n\\hhline{-----}\n\\end{tabular}\n\\overset{L}{\\longrightarrow}\n\\begin{tabular}{ | c |}\n\\hhline{-}\n\\cellcolor[gray]{0.6}\\\\\n\\hhline{-}\n\\cellcolor{red}\\\\\n\\hhline{-}\n\\end{tabular}\n\\overset{R}{\\longrightarrow}\n\\begin{tabular}{ | c |}\n\\hline\n\\cellcolor{red}\\\\\n\\hline\n\\end{tabular}\n$\n\\captionof{figure}{Example of gameplay in the game of Chomp with starting position as in Figure \\ref{fig:chompstart} where Right player wins.}\n\\end{figure}\n\\end{ex}", "meta": {"hexsha": "da7d5b18f3dd9796479caed87d5b870a4cd32898", "size": 30396, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/thesis/fredriks/preliminaries.tex", "max_stars_repo_name": "ghw329/DDSC", "max_stars_repo_head_hexsha": "97262b7fe0f507a7860828060e43ae2e0c1f1495", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/thesis/fredriks/preliminaries.tex", "max_issues_repo_name": "ghw329/DDSC", "max_issues_repo_head_hexsha": "97262b7fe0f507a7860828060e43ae2e0c1f1495", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/thesis/fredriks/preliminaries.tex", "max_forks_repo_name": "ghw329/DDSC", "max_forks_repo_head_hexsha": "97262b7fe0f507a7860828060e43ae2e0c1f1495", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.1649331352, "max_line_length": 514, "alphanum_fraction": 0.6392288459, "num_tokens": 11787, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619091240701, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.7007688550497916}}
{"text": "\\chapter{Limits of Computability}\nEvery discipline of the sciences has its limits: Students of the medical sciences soon realize that\nit is difficult to \\href{http://www.wowhead.com/spell=61999}{raise the dead} and even religious zealots\nhave trouble \\href{http://www.youtube.com/watch?v=RUMX_b_m3Js}{to walk on water}.  Similarly,\ncomputer science has its limits.  We will discuss \nthese limits next.  First, we show that we cannot decide whether a computer program will eventually\nterminate or whether it will run forever.  \nSecond, we prove that it is impossible to automatically check whether two functions are equivalent.\n\n\n\\section{The Halting Problem}\nIn this subsection we prove that it is not possible for a computer program to decide whether \nanother computer program does terminate.  This problem is known as the \n\\href{http://en.wikipedia.org/wiki/Halting_problem}{\\emph{halting problem}}.\n\\index{halting problem}\nBefore we give a formal proof that the halting problem is undecidable, let us\ndiscuss one example that shows why it is indeed difficult to decide whether a program does always\nterminate.  Consider the program shown in Figure \\ref{fig:legendre.stlx} on page\n\\pageref{fig:legendre.stlx}.  This program contains a \\texttt{while}-loop in line 18.  \nIf there is a natural number $n \\geq m$ such that the expression,\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\mathtt{legendre}(n)$\n\\\\[0.2cm]\nin line 19 evaluates to \\texttt{false}, then the program prints a message and terminates.   However, if \n$\\mathtt{legendre}(n)$ is true for all $n \\geq m$, then the \\texttt{while}-loop does not terminate.\n\nGiven a natural number \\texttt{n}, the expression\n$\\texttt{legendre}(n)$ tests whether there is a prime number between $\\texttt{n}^2$ and $(\\texttt{n}+1)^2$.  \nIf, however, the set\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\{ k \\in \\mathbb{N} \\mid n^2 \\leq k \\wedge k \\leq (n+1)^2 \\}$\n\\\\[0.2cm]\ndoes not contain a prime number, then $\\texttt{legendre}(n)$ evaluates\nto \\texttt{False} for this value of $n$.  The function \\texttt{legendre} is defined in line 7.  \nGiven a natural number $n$, it returns \\texttt{True} if and only if the formula\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\exists k \\in \\mathbb{N}:\\bigl( n^2 < k \\wedge k < (n+1)^2 \\wedge \\textsl{isPrime}(k)\\bigr)$\n\\\\[0.2cm]\nholds true.  The French mathematican \n\\href{http://en.wikipedia.org/wiki/Adrien-Marie_Legendre}{Adrien-Marie Legendre} (1752 -- 1833) conjectured that\nfor any natural number $n \\in \\mathbb{N}$ there is prime number $p$ such that\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$n^2 < p \\wedge  p < (n+1)^2$\n\\\\[0.2cm]\nholds.  Although there are a number of arguments in support of Legendre's conjecture,  to this day\nnobody has been able to prove it.  The answer to the question, whether the invocation of the function $f$ will\nterminate for every user input is, therefore, unknown as it depends on the truth of \n\\href{http://en.wikipedia.org/wiki/Legendre's_conjecture}{Legendre's conjecture}:  If we\nhad some procedure that could check whether the function call $\\texttt{find\\_counter\\_example}(1)$ does terminate,\nthen this procedure would be able to decide whether Legendre's theorem is true.  Therefore, it\nshould come as no surprise that such a procedure does not exist.\n\n\n\\begin{figure}[!ht]\n\\centering\n\\begin{minted}[ frame         = lines, \n                framesep      = 0.3cm, \n                firstnumber   = 1,\n                numbers       = left,\n                numbersep     = -0.2cm,\n                bgcolor       = sepia,\n                xleftmargin   = 0.0cm,\n                xrightmargin  = 0.0cm,\n              ]{python3}\n    def divisors(k):\n        return { t for t in range(1, k+1) if k % t == 0 }\n\n    def is_prime(k):\n        return divisors(k) == {1, k}    \n    \n    def legendre(n):\n        k = n * n + 1;\n        while k < (n + 1) ** 2:\n            if is_prime(k):\n                print(f'{n}**2 < {k} < {n+1}**2')\n                return True\n            k += 1\n        return False\n\n    def find_counter_example(m):\n        n = m\n        while True:\n           if legendre(n):\n               n = n + 1\n           else:\n               print(f'Counter example found: No prime between {n}**2 and {n+1}**2!')\n               return\n\\end{minted}\n\\vspace*{-0.3cm}\n\\caption{A program checking Legendre's conjecture.}\n\\label{fig:legendre.stlx}\n\\end{figure}\n\nLet us proceed to prove formally that the halting problem is not solvable.  To this end, we need the\nfollowing definition.\n\n\\begin{Definition}[Test Function] \nA string $t$ is a \\blue{test function with name $f$} \n\\index{test function}\niff $t$ has the form \\\\[0.2cm]\n\\hspace*{1.3cm} \\texttt{\\symbol{34}\\symbol{34}\\symbol{34}}         \\\\\n\\hspace*{1.3cm} \\texttt{def $f$(x):} \\\\\n\\hspace*{1.8cm} \\textsl{body}        \\\\\n\\hspace*{1.3cm} \\texttt{\\symbol{34}\\symbol{34}\\symbol{34}}         \\\\[0.2cm]\nand, furthermore, the string $t$ can be parsed as a \\textsl{Python} function, that is the evaluation of\nthe expression\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\texttt{exec}(t)$\n\\\\[0.2cm]\ndoes not yield an error.  \nThe set of all test functions is denoted as $T\\!F$.  If $t \\in T\\!F$ and $t$ has the name $f$, then\nthis is written as \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\mathtt{name}(t) = f$. \\hspace*{\\fill} $\\Box$\n\\end{Definition}\n\n\\examplesEng\n\\begin{enumerate}\n\\item We define the string $s_1$ as follows:\n      \\begin{verbatim}\n      '''def simple(x): \n             return 0\n      '''\n      \\end{verbatim}\n      \\vspace*{-0.8cm}\n\n      Then $s_1$ is a test function with the name \\texttt{simple}.\n\\item We define the string $s_2$ as\n      \\begin{verbatim}\n      '''def loop(x): \n             while True: \n                 x = x + 1\n      '''\n      \\end{verbatim}\n      \\vspace*{-0.8cm}\n\n      Then $s_2$ is a test function with the name \\texttt{loop}. \n\\item We define the string $s_3$ as\n      \\begin{verbatim}\n      '''def hugo(x):\n             return ++x\n      '''\n      \\end{verbatim}\n      \\vspace*{-0.8cm}\n\n      Then $s_3$ is not a test function.  The reason is that \\textsl{Python} does not support the operator\n      ``\\texttt{++}''.  Therefore, \n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      \\texttt{exec(s3)}\n      \\\\[0.2cm]\n      yields an error message complaining about the two ``\\texttt{+}'' characters.\n\\end{enumerate}\nIn order to be able to formalize the halting problem succinctly, we introduce three additional\nnotations.\n\n\\begin{Notation}[$\\leadsto$, $\\downarrow$, $\\uparrow$]\nIf $n$ is the name of a \\textsl{Python} function that takes $k$ arguments $a_1$, $\\cdots$, $a_k$,\nthen we write \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n $n(a_1, \\cdots, a_k) \\leadsto r$ \n\\\\[0.2cm]\niff the evaluation of the expression $n(a_1, \\cdots, a_k)$ yields the result $r$.  If we are not\nconcerned with the result $r$ but only want to state that the evaluation terminates eventually,\nthen we will write\n\\\\[0.2cm]\n\\hspace*{1.3cm} $n(a_1, \\cdots, a_k) \\,\\downarrow$ \\\\[0.3cm]\nand read this notation as ``\\emph{evaluation of $n(a_1, \\cdots, a_k)$ terminates}''.\nIf the evaluation of the expression $n(a_1, \\cdots, a_k)$ does \\underline{not} terminate, this is\nwritten as \\\\[0.2cm]\n\\hspace*{1.3cm}\n $n(a_1, \\cdots, a_k) \\,\\uparrow$. \n\\\\[0.2cm]\nThis notation is read as ``\\emph{evaluation of $n(a_1, \\cdots, a_k)$ diverges}''.\n\\hspace*{\\fill} $\\Box$\n\\end{Notation}\n\n\\examplesEng  Using the test functions defined earlier, we have:\n\\begin{enumerate}\n\\item {\\tt simple(\\symbol{34}emil\\symbol{34}) $\\leadsto 0$},\n\\item {\\tt simple(\\symbol{34}emil\\symbol{34}) $\\downarrow$},\n\\item {\\tt loop(2) $\\uparrow$}.\n\\end{enumerate}\n\n\\noindent\nThe \\blue{halting problem} \\index{halting problem} for \\textsl{Python} functions is the question whether there is a\n\\textsl{Python} function \\\\[0.2cm]\n\\hspace*{1.3cm} \\texttt{def stops($t$,$\\;a$): } \\\\\n\\hspace*{2.3cm} $\\vdots$\n\\\\[0.2cm] \nthat takes as input a test function $t$ and a string $a$ and that satisfies the following specification:\n\\begin{enumerate}\n\\item $t \\not\\in T\\!F \\quad\\Leftrightarrow\\quad \\mathtt{stops}(t, a) \\leadsto 2$.\n\n      If the first argument of \\texttt{stops} is not a test function, then \n      \\texttt{stops($t$, $a$)} returns the number $2$.\n\n\\item $t \\in T\\!F \\,\\wedge\\, \\mathtt{name}(t) = n \\,\\wedge\\, n(a)\\downarrow \\quad\\Leftrightarrow\\quad\n       \\mathtt{stops}(t, a) \\leadsto 1$.\n\n      If the first argument of \\texttt{stops} is a test function and, furthermore,\n      the evaluation of $n(a)$ terminates, then \\texttt{stops($t$, $a$)} returns the number $1$.\n\n\\item $t \\in T\\!F \\,\\wedge\\, \\mathtt{name}(t) = n \\,\\wedge\\, n(a)\\uparrow \\quad\\Leftrightarrow\\quad\n       \\mathtt{stops}(t, a) \\leadsto 0$.\n\n      If the first argument of \\texttt{stops} is a test function but the evaluation of $n(a)$ \n      diverges, then \\linebreak\n      \\texttt{stops($t$, $a$)} returns the number $0$.\n\\end{enumerate}\nIf there was a \\textsl{Python} function \\texttt{stops} that did satisfy the specification given above,\nthen the halting problem for \\textsl{Python} would be \\blue{decidable}.\n\\index{decidable}\n\n\\begin{Theorem}[\\href{http://en.wikipedia.org/wiki/Alan_Turing}{Alan Turing}, 1936]\n  The halting problem is undecidable.\n\\end{Theorem}\n\\index{Turing, Alan}\n\n\\noindent\n\\textbf{Proof}:  In order to prove the undecidabilty of the halting problem we have to show that\nthere can be no function \\texttt{stops} satisfying the specification given above.  This calls for an\nindirect proof also known as a \\href{http://en.wikipedia.org/wiki/Indirect_proof}{\\emph{proof by contradiction}}.\nWe will therefore assume that a function \\texttt{stops} solving the halting problem does\nexist and we will then show that this assumption leads to a contradiction.  This contradiction will\nleave us with the conclusion that there can be no function \\texttt{stops} that satisfies\nthe specification given above and that, therefore, the halting problem is undecidable.\n\nIn order to proceed, let us assume that a \\textsl{Python} function \\texttt{stops}\nsatisfying the specification given above exists and let us define the string\n\\textsl{turing} as shown in Figure \\ref{fig:turing-string} below.\n\n\\begin{figure}[!h]\n  \\centering\n\\begin{minted}[ frame         = lines, \n                framesep      = 0.3cm, \n                numbers       = left,\n                numbersep     = -0.2cm,\n                bgcolor       = sepia,\n                xleftmargin   = 0.8cm,\n                xrightmargin  = 0.8cm,\n              ]{python3}  \n    turing = \"\"\"def alan(x):\n                    result = stops(x, x)\n                    if result == 1:\n                        while True:\n                            print(\"... looping ...\")\n                    return result\n             \"\"\" \n\\end{minted}\n  \\vspace*{-0.3cm}\n  \\caption{Definition of the string \\textsl{turing}.}\n  \\label{fig:turing-string}\n\\end{figure}\n\nGiven this definition it is easy to check that \\textsl{turing} is, indeed, a test function with the name\n``\\texttt{alan}'', that is we have \n\\\\[0.3cm]\n\\hspace*{1.3cm} \n$\\textsl{turing} \\in T\\!F \\;\\wedge\\; \\mathtt{name}(\\textsl{turing}) = \\mathtt{alan}$. \n\\\\[0.2cm]\nTherefore, we can use the string \\textsl{turing} as the first argument of the function\n\\texttt{stops}.  Let us determine the value of the following expression:\n\\\\[0.2cm]\n\\hspace*{1.3cm} \n\\texttt{stops(\\textsl{turing}, \\textsl{turing})} \n\\\\[0.2cm]\nSince we have already noted that \\textsl{turing} is test function, according to the specification of\nthe function \\texttt{stops} there are only two cases left:\n\\\\[0.2cm]\n\\hspace*{1.3cm} \n$\\mathtt{stops}(\\textsl{turing}, \\textsl{turing}) \\leadsto 0 \\quad \\vee\\quad\n \\mathtt{stops}(\\textsl{turing}, \\textsl{turing}) \\leadsto 1$. \n\\\\[0.2cm]\nLet us consider these cases in turn.\n\\begin{enumerate}\n\\item $\\mathtt{stops}(\\textsl{turing}, \\textsl{turing}) \\leadsto 0$. \n\n      According to the specification of \\texttt{stops} we should then have\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $\\mathtt{alan}(\\textsl{turing}) \\uparrow$.\n      \\\\[0.2cm]\n      Let us check whether this is true.  In order to do this, we have to check what happens when\n      the expression\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      \\texttt{alan(\\textsl{turing})} \n      \\\\[0.2cm]\n      is evaluated:\n      \\begin{enumerate}\n      \\item Since we have assumed for this case that the expression \n            $\\mathtt{stops}(\\textsl{turing}, \\textsl{turing})$ yields $0$, \n            in line 2, the variable \\texttt{result} is assigned the value 0. \n      \\item Line 3 now tests whether \\texttt{result} is $1$.  Of course,\n            this test fails.  Therefore, the block of the \\texttt{if}-statement is not executed.\n      \\item Finally, in line 8 the value of the variable \\texttt{result} is returned. \n      \\end{enumerate}\n      All in all we see that the call of the function \\texttt{alan} does terminate when given the argument\n      \\textsl{turing}.  However, this is the opposite of what the function \\texttt{stops} has claimed.\n      \n      Therefore, this case has lead us to a contradiction.\n\\item  $\\mathtt{stops}(\\textsl{turing}, \\textsl{turing}) \\leadsto 1$. \n\n      According to the specification of \\texttt{stops} we should then have\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $\\mathtt{alan}(\\textsl{turing}) \\downarrow$, \n      \\\\[0.2cm]\n      i.e.~the evaluation of $\\mathtt{alan}(\\textsl{turing}) \\downarrow$ should terminate.\n      \n      Again, let us check in detail whether this is true.  \n      \\begin{enumerate}\n      \\item Since we have assumed for this case that the expression \n            $\\mathtt{stops}(\\textsl{turing}, \\textsl{turing})$ yields $1$, \n            in line 2, the variable \\texttt{result} is assigned the value $1$. \n      \\item Line 3 now tests whether \\texttt{result} is $1$.  Of course,\n            this time the test succeeds.  \n            Therefore, the block of the \\texttt{if}-statement \\underline{is} executed.\n      \\item However, this block contains an infinite loop.  Therefore, the\n            evaluation of $\\mathtt{alan}(\\textsl{turing})$ \\underline{diver}g\\underline{es}.\n            But this contradicts the specification of \\texttt{stops}!\n      \\end{enumerate}   \n      Therefore, the second case also leads to a contradiction.\n\\end{enumerate}\nAs we have obtained contradictions in both cases, the assumption that there is a function\n\\texttt{stops} that solves the halting problem is refuted.\n\\hspace*{\\fill} $\\Box$\n\\vspace*{0.3cm}\n\n\\noindent\n\\textbf{Remark}:\nThe proof of the fact that the halting problem is undecidable was given 1936 by Alan Turing (1912 -- 1954)\n\\cite{turing:36}.  Of course, Turing did not solve the problem for \\textsl{Python} but rather\nfor the so called \n\\href{http://en.wikipedia.org/wiki/Indirect_proof}{\\emph{Turing machines}}.  \nA \\blue{Turing maschine} \\index{turing machine} \ncan be interpreted as a formal description of an algorithm.  \nTherefore, Turing has shown, that there is no algorithm that is able to decide whether some given\nalgorithm will always terminate.\n\\vspace*{0.3cm}\n\n\\noindent\n\\textbf{Remark}:\nAt this point you might wonder whether there might be another programming language\nthat is more powerful so that programming in this more powerful language it would be possible to\nsolve the halting problem.  However, if you check the proof given for \\textsl{Python} you will easily\nsee that this proof can be adapted to any other programming language that is as least as powerful as\n\\textsl{Python}. \n\nOf course, if a programming language is very restricted, then it might be possible to check the\nhalting problem for this weak programming language.  But for any programming language that supports\nat least \\texttt{while}-loops, \\texttt{if}-statements, and the definition of procedures the argument\ngiven above shows that the halting problem is not solvable.\n\n\\exerciseEng\nShow that if the halting problem would be solvable, then it would be possible to write a program that checks\nwhether there are infinitely many \\blue{twin primes}.  \n\\index{twin prime}\nA \\blue{twin prime} is pair of natural numbers\n$\\langle p, p + 2 \\rangle$ such that both $p$ and $p+2$ are prime numbers.  \nThe \\href{http://en.wikipedia.org/wiki/Twin_prime_conjecture}{\\emph{twin prime conjecture}} is one\nof the oldest unsolved mathematical problems.  \\eox\n\n\\exerciseEng\nA set $X$ is \\blue{countably infinite}\\index{countably infinite} iff $X$ is infinite and there is a function \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n $f: \\mathbb{N} \\rightarrow X$ \n\\\\[0.2cm]\nsuch that for all $x\\in X$ there is a $n \\in \\mathbb{N}$ such that $x$ is the image of\n$n$ under $f$: \n\\\\[0.2cm]\n\\hspace*{1.3cm} $\\forall x \\in X: \\exists n \\in \\mathbb{N}: x = f(n)$.\n\\\\[0.2cm]\n(A function of this kind is called \\blue{surjective}. \\index{surjective}\nSome authors define a set to be countably infinite iff\nthere is an \\blue{injective} \\index{injective} function $f:\\mathbb{N} \\rightarrow X$.  It can be shown that if there is a\nsurjective function $f:\\mathbb{N} \\rightarrow X$ and $X$ is infinite, then there also is an injective function\n$f:\\mathbb{N} \\rightarrow X$.  Therefore, these definitions are equivalent.) \nIf a set is infinite, but not countably infinite, we call it \\blue{uncountable}.\nProve that the set $2^\\mathbb{N}$, which is the set of all subsets of $\\mathbb{N}$ is \\underline{not} countably\ninfinite. \n\n\\vspace*{0.2cm}\n\n\\noindent\n\\textbf{Hint}:  Your proof should be similar to the proof that the halting problem is undecidable. \nProceed as follows:\nAssume that there is a function $f$ enumerating the subsets of $\\mathbb{N}$, that is assume that \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\forall x \\in 2^\\mathbb{N}: \\exists n \\in \\mathbb{N}: x = f(n)$\n\\\\[0.2cm]\nholds.  Next, and this is the crucial step, define a set \\texttt{Cantor} as follows:\n\\\\[0.2cm]\n\\hspace*{1.3cm} $\\mathtt{Cantor} := \\bigl\\{ n \\in \\mathbb{N} \\mid n \\notin f(n) \\bigr\\}$.\n\\\\[0.2cm]\nNow try to derive a contradiction.  \\eox\n\n\n\n\\section[The Equivalence Problem]{Undecidability of the Equivalence Problem}\nUnfortunately, the halting problem is not the only undecidable problem in computer science.  Another\nimportant problem that is undecidable is the question whether two given functions always compute the\nsame result.  To state this more formally, we need the following definition.\n\n\n\\begin{Definition}[$\\simeq$] \nAssume $n_1$ and $n_2$ are the names of two \\textsl{Python} functions that take arguments\n  $a_1$, $\\cdots$, $a_k$.  Let us define \\\\[0.2cm]\n\\hspace*{1.3cm} \n$n_1(a_1,\\cdots,a_k) \\simeq n_2(a_1,\\cdots,a_k)$ \n\\\\[0.2cm]\nif and only if either of the following cases is true:\n\\begin{enumerate}\n\\item $n_1(a_1,\\cdots,a_k)\\uparrow \\quad\\wedge\\quad n_2(a_1,\\cdots,a_k)\\uparrow$,\n\n      that is both function calls diverge.\n\\item $\\exists r: \\Bigl(n_1(a_1,\\cdots,a_k) \\leadsto r \\quad\\wedge\\quad n_2(a_1,\\cdots,a_k) \\leadsto\n  r\\Bigr)$\n\n      that is both function calls terminate and compute the same result.\n\\end{enumerate}\nIf $n_1(a_1,\\cdots,a_k) \\simeq n_2(a_1,\\cdots,a_k)$ holds, then the expressions $n_1(a_1,\\cdots,a_k)$ and $n_2(a_1,\\cdots,a_k)$ are \n\\blue{partially equivalent}. \n\\index{partially equivalent}\n\\hspace*{\\fill} $\\Box$\n\\end{Definition}\n\n\\noindent\nWe are now ready to state the \\blue{equivalence problem}.  A \\textsl{Python} function \\texttt{equal} solves the\n\\emph{equivalence problem} \\index{equivalence problem} if it is defined as\n\\\\[0.2cm]\n\\hspace*{1.3cm} \\texttt{def equal(p1, p2, a):}               \\\\\n\\hspace*{1.8cm} \\textsl{body}                                \\\\[0.2cm]\nand, furthermore, it satisfies the following specification:\n\\begin{enumerate}\n\\item $p_1 \\not\\in T\\!F \\;\\vee\\; p_2 \\not\\in T\\!F \\quad\\Leftrightarrow\\quad \\mathtt{equal}(p_1, p_2, a) \\leadsto 2$.\n\\item If \n      \\begin{enumerate}\n      \\item $p_1 \\in T\\!F \\;\\wedge\\; \\mathtt{name}(p_1) = n_1$,\n      \\item $p_2 \\in T\\!F \\;\\wedge\\; \\mathtt{name}(p_2) = n_2$ \\quad and\n      \\item $n_1(a) \\simeq n_2(a)$\n      \\end{enumerate}\n      holds, then we must have: \n      \\\\[0.2cm]\n      \\hspace*{1.3cm} \n      $\\mathtt{equal}(p_1, p_2, a) \\leadsto 1$.\n\\item Otherwise we must have \\\\[0.2cm]\n      \\hspace*{1.3cm} \n      $\\mathtt{equal}(p_1, p_2, a) \\leadsto 0$.\n\\end{enumerate}\n\n\n\\begin{Theorem}\nThe equivalence problem is undecidable.  \n\\end{Theorem}\n\n\\noindent\n\\textbf{Proof}:\nThe proof is by contradiction.  Therefore, assume that there is a function \\texttt{equal}\nsuch that \\texttt{equal} solves the equivalence problem.  Assuming \\texttt{equal} exists, we will\nthen proceed to define a function \\texttt{stops} that solves the halting problem.\nFigure \\ref{fig:stops} shows this construction of the function \\texttt{stops}.\n\n\n\\begin{figure}[!h]\n  \\centering\n\\begin{minted}[ frame         = lines, \n                framesep      = 0.3cm, \n                numbers       = left,\n                numbersep     = -0.2cm,\n                bgcolor       = sepia,\n                xleftmargin   = 0.3cm,\n                xrightmargin  = 0.3cm\n              ]{python3}\n     def stops(t, a):\n         l = \"\"\"def loop(x): \n                    while True:\n                        x = 1\n             \"\"\" \n         e = equal(l, t, a);\n         if e == 2:\n             return 2\n         else:\n             return 1 - e\n\\end{minted}\n  \\vspace*{-0.3cm}\n  \\caption{An implementation of the function \\texttt{stops}.}\n  \\label{fig:stops}\n\\end{figure}\n\nNotice that in line 6 the function \\texttt{equal} is called with a string that is test function with\nname \\texttt{loop}.  This test function has the following form:\n\\begin{verbatim}\n        def loop(x): \n             while True:\n                 x = 1\n\\end{verbatim}\nIndependent from the argument $x$, the function \\texttt{loop} does not terminate.\nTherefore, if the first argument $t$ of \\texttt{stops} is a test function with name $n$, \nthe function \\texttt{equal} will return $1$ if $n(a)$ diverges, and will return $0$ otherwise.\nBut this implementation of \\texttt{stops} would then solve the halting problem as\nfor a given test function $t$ with name $n$ and argument $a$ the function \\texttt{stops} would\nreturn 1 if and only the evaluation of $n(a)$ terminates.  As we have already proven that the\nhalting problem is undecidable, there can be no function \\texttt{equal} that solves the equivalence\nproblem either.\n\\qed\n\n\\remarkEng\nThe unsolvability of the equivalence problem has been proven by \\href{http://en.wikipedia.org/wiki/Henry_Gordon_Rice}{Henry Gordon Rice} \\cite{rice:1953} in 1953.\n\\eox\n\n\\section{Concluding Remarks}\nAlthough, in general, we cannot decide whether a program terminates for a given input, this does not mean\nthat we should not attempt to do so.  After all, we only have proven that there is no procedure that\ncan \\underline{alwa}y\\underline{s} check whether a given program will terminate.  There might well exist a\nprocedure for termination checking that works most of the time.  Indeed, there are a number of\nsystems that try to check whether a program will terminate for every input.  For example, for\n\\href{https://en.wikipedia.org/wiki/Prolog}{Prolog}\nprograms, the paper\n``\\href{http://link.springer.com/chapter/10.1007%2F3-540-61739-6_44}{\\emph{Automated Modular Termination Proofs for Real Prolog Programs}}''\n\\cite{mueller:1996} describes a successful approach.  The recent years have seen a lot of progress in\nthis area.  The article \n``\\href{http://dl.acm.org/citation.cfm?id=1941509}{{Proving Program Termination}}''\n\\cite{cook:2011} reviews these developments.  However, as the recently developed systems rely on both\n\\href{http://en.wikipedia.org/wiki/Automated_theorem_proving}{\\emph{automatic theorem proving}} and\n\\href{http://en.wikipedia.org/wiki/Ramsey_theory}{\\emph{Ramsey theory}} they are quite out of the\nscope of this lecture.\n\n\\section{Chapter Review}\nYou should be able to solve the following exercises.\n\\begin{enumerate}\n\\item Define the halting problem.\n\\item Define the equivalence problem.\n\\item Define the notion of a countable set.\n\\item Prove that the set $2^{\\mathbb{N}}$ is not countable.\n\\end{enumerate}\n\n\n\\section{Further Reading}\nThe book ``\\emph{Introduction to the Theory of Computation}'' by Michael Sipser \\cite{sipser:1996}\ndiscusses the undecidability of the halting problem in section 4.2.  It also covers many related\nundecidable problems.\n\nAnother good book discussing undecidability is the book \n``\\emph{Introduction to Automata Theory, Languages, and Computation}'' written by John E.~Hopcroft,\nRajeev Motwani and Jeffrey D.~Ullman \\cite{hopcroft:06}.  This book is the third edition of a\nclassic text.  In this book, the topic of undecidability is discussed in chapter 9.\n\nThe exposition in these books is based on\n\\href{https://en.wikipedia.org/wiki/Turing_machine}{Turing machines} and is therefore more formal than the\nexposition given here.  This increased formality seems necessary to prove that, for example, it is undecidable\nwhether two \\href{https://en.wikipedia.org/wiki/Context-free_grammar}{context free grammars} are equivalent.\n\n\n\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"logic.tex\"\n%%% End: \n", "meta": {"hexsha": "2026e50349bbbc915cf4638a7db04695f5f106c9", "size": 24876, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-Notes/limits.tex", "max_stars_repo_name": "Sarius5/Logic-1", "max_stars_repo_head_hexsha": "8b7812c3daa79f59d369b91965cf70f0fdfe5d1c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-24T00:41:43.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-24T00:41:43.000Z", "max_issues_repo_path": "Lecture-Notes/limits.tex", "max_issues_repo_name": "rahilchughtai/Logic", "max_issues_repo_head_hexsha": "ec015dcdfece8963e6817f1880c6411660a54421", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture-Notes/limits.tex", "max_forks_repo_name": "rahilchughtai/Logic", "max_forks_repo_head_hexsha": "ec015dcdfece8963e6817f1880c6411660a54421", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.4895104895, "max_line_length": 162, "alphanum_fraction": 0.6796912687, "num_tokens": 7550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969193, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7006465594376817}}
{"text": "\n\\chapter{Proof by induction}\n\n\\begin{example}\n    Prove that every term the sequence given by $a_1=3$ and $a_{n+1}=a_n+2$\n    is odd. \n    \\par\\noindent\\hrulefill\\par\\par \n    When $n=1$, $a_n=a_1=3$ which is odd. Therfor the theorem is true for $n=1$\n    \\par\n    Assume the theorem is true for $n=k$. Therefor $a_k=2p+1$ where $p\\in\\mathbb{Z}$\n    \\par\n    Now we need to show the theorem is true for $n=k+1$. \n    Target statement: $a_{k+1}=2q+1$ where $q\\in\\mathbb{Z}$.\n    \\begin{align*}\n        a_{k+1}&=a_k+2\\\\\n        &=2p+1+2 &\\text{ where } p\\in\\mathbb{Z}\\\\\n        &= 2(p+1)+1 \\\\\n        &= 2q+1 &\\text{ where } q\\in\\mathbb{Z}\n    \\end{align*}\n    Because it is true for $n=1$ and $n=k$ being true implys the theorem is \n    true for $n=k+1$, so it is true for all $n\\in\\mathbb{N}^+$\n\\end{example}\n\\begin{example}\n    \n\\end{example}\n\n", "meta": {"hexsha": "54bb00ab4c49946172ceee98db34373828e2d725", "size": 846, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/a-level-notes/furthermath/content/pure_core/induction.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/a-level-notes/furthermath/content/pure_core/induction.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/a-level-notes/furthermath/content/pure_core/induction.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.3333333333, "max_line_length": 84, "alphanum_fraction": 0.5898345154, "num_tokens": 335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7006465432213644}}
{"text": "\n\\subsection{Relations and equality}\n\n\\subsubsection{Relations}\n\nA special type of predicates is a relation. These take two terms and can be written differently:\n$P(x,y)\\Leftrightarrow x\\oplus y$\n\n\\subsubsection{Equality}\n\nIn preterite logic we define the relation for equality.\n\n\\(a=b\\)\n\nIt is defined by the following:\n\n\\begin{itemize}\n\\item Reflexivity : \\(x=x\\)\n\\item Symmetry: \\(x=y\\leftrightarrow y=x\\)\n\\item Transivity: \\(x=y\\land y=z \\rightarrow x=z\\)\n\\item Substitution for functions: \\(x=y\\rightarrow f(x)=f(y)\\)\n\\item Substitution for formulae: \\(x=y\\land P(x)\\rightarrow P(y)\\)\n\\end{itemize}\n\n", "meta": {"hexsha": "fe2496e1f4129c4a7186a40d74a1aedb1b60b828", "size": 605, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/preteriteLogic/01-02-relations.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/preteriteLogic/01-02-relations.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/preteriteLogic/01-02-relations.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.2, "max_line_length": 96, "alphanum_fraction": 0.7305785124, "num_tokens": 172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248208414329, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.7006430342535082}}
{"text": "\n\\subsection{Consistency and efficiency of estimators}\n\n\\subsubsection{Consistency}\n\nA statistic \\(\\hat \\theta \\) is a consistent estimator for \\(\\theta \\) if its error tends to \\(0\\).\n\nThat is:\n\n\\(\\hat \\theta\\rightarrow^p \\theta \\)\n\nWe can show that an estimator is consistent if we can write:\n\n\\(\\hat \\theta -\\theta \\) as a function of \\(n\\), causing it to tend to \\(0\\).\n\n\\subsubsection{Efficiency}\n\nEfficiency measures the speed at which a consistent estimator tends towards the true value.\n\nThe speed of this convergence is the efficiency. could be fairly efficient plus biased too\tp Measured as:\n\n\\(e(\\hat \\theta )=\\dfrac{\\dfrac{1}{I(\\theta )}}{Var (\\hat \\theta )}\\)\n\nIf an estimator as an efficiency of \\(1\\) and is unbiased, it is efficient.\n\n\\subsubsection{Relative efficiency}\n\nWe can measure the relative efficiency of two consistent estimators:\n\nThe relative efficiency is the variance of the first estimator, divided by the variance of the second.\n\n\\subsubsection{Root-n estimators}\n\nAn estimator is root-n consistent if it is consistent and its variance is:\n\n\\(O(\\dfrac{1}{n})\\)\n\n\\subsubsection{\\(n^\\delta \\)-convergent}\n\nA consistent estimator is \\(n^\\delta \\)-consistent if its variance is:\n\n\\(O(\\dfrac{1}{n^{2 \\delta }})\\)\n\n", "meta": {"hexsha": "1e8dd4c38cb33b23395a615a10a5acefda449095", "size": 1241, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/generative/02-04-consistency.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/generative/02-04-consistency.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/generative/02-04-consistency.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2045454545, "max_line_length": 105, "alphanum_fraction": 0.7276390008, "num_tokens": 315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7006231700151903}}
{"text": "\\section{Vector Fields}\r\n\\noindent\r\nVector fields are a function $f : \\mathbb{R}^n \\to \\mathbb{R}^n$. This is generally conceptualized as assigning an n-dimensional vector to every point in an n-dimensional space.\\\\\r\nMany physics concepts can be thought of as vector fields. The electric field due to some point charge $Q$ as some distance $r$ from $Q$ is $\\vec{E}(x,y,z) = \\frac{\\epsilon_{0}Q}{r^2}\\hat{r}$ where $\\epsilon_{0}$ is a constant and $\\hat{r}$ is a radial unit vector pointing away from $Q$.\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nA generic 2D vector field is \r\n\\begin{equation*}\r\n\t\\vec{F}(x,y) = \\langle P(x,y), Q(x,y) \\rangle\t\r\n\\end{equation*}\r\nVector fields work similarly to VVFs in that they are added component-wise.", "meta": {"hexsha": "c5e54aeb471372f91d12710266361ef8061078bd", "size": 728, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/lineSurfaceIntegrals/vectorFields.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/lineSurfaceIntegrals/vectorFields.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/lineSurfaceIntegrals/vectorFields.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.0, "max_line_length": 288, "alphanum_fraction": 0.7087912088, "num_tokens": 216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.7004715200872993}}
{"text": "%% -*- coding:utf-8 -*-\n\\begin{appendices}\n  \n\\chapter{Course prerequisites}\nThere are several prerequisites for the course there. They consists of\ndefinitions, theorems and examples mostly taken from Wikipedia. \n\n\\section{Sets}\n\n\\begin{definition}[Class]\n  A class is a collection of sets (or sometimes other mathematical\n  objects) that can be unambiguously defined by a property that all\n  its members share. \n  \\label{def:class}\n\\end{definition}\n\n\\begin{definition}[Disjoint union]\n  Let \\cite{wiki:disjointunion} $\\{A_i: i \\in I\\}$ be a family of sets\n  indexed by $I$. The \n  disjoint union of this family is the set\n  \\[\n  \\sqcup_{i \\in I} A_i = \\cup_{i \\in I}\\left\\{\n  \\left(x, i\\right): x \\in A_i\n  \\right\\}.\n  \\]\n  The elements of the disjoint union are ordered pairs $(x, i)$. Here $i$\n  serves as an auxiliary index that indicates which $A_i$ the element $x$\n  came from.\n  \\label{def:disjointunion}\n\\end{definition}\n\n\\begin{example}[Disjoint union]\n  Let \\cite{wiki:disjointunion} we have 2 sets $A_0 = \\{1,2,3\\}$ and\n  $A_1 = \\{1,2\\}$. \n  We can construct the following sets of pairs\n  \\begin{eqnarray}\n  A_0^\\ast = \\left\\{\n  \\left(1,0\\right),\n  \\left(2,0\\right),\n  \\left(3,0\\right)\n  \\right\\},\n  \\nonumber \\\\\n  A_1^\\ast = \\left\\{\n  \\left(1,1\\right),\n  \\left(2,1\\right)\n  \\right\\}  \n  \\nonumber\n  \\end{eqnarray}\n  so\n  \\[\n  A_0 \\sqcup A_1 = A_0^\\ast \\cup A_1^\\ast =\n  \\left\\{\n  \\left(1,0\\right),\n  \\left(2,0\\right),\n  \\left(3,0\\right),\n  \\left(1,1\\right),\n  \\left(2,1\\right)\n  \\right\\}\n  \\]\n  \\label{ex:disjointunion}\n\\end{example}\n\n\n\\section{Groups}\n\n\\begin{definition}[Monoid]\n  \\label{def:monoid}\n  The set of elements $M$ with defined binary operation $\\circ$ we will call\n  as a monoid if the following conditions are satisfied.\n  \\begin{enumerate}\n  \\item Closure: $\\forall a, b \\in M$: $a \\circ b \\in M$\n  \\item Associativity: $\\forall a, b, c \\in M$:\n    $a \\circ \\left( b \\circ c \\right) =\n    \\left( a \\circ b \\right) \\circ c$\n  \\item Identity element: $\\exists e \\in M$ such that\n    $\\forall a \\in M$: $e \\circ a = a \\circ e = a$\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{definition}[Group]\n  \\label{def:group}\n  Let we have a set of elements $G$ with a defined binary operation\n  $\\circ$ that satisfied the following properties.\n  \\begin{enumerate}\n  \\item Closure: $\\forall a, b \\in G$: $a \\circ b \\in G$\n  \\item Associativity: $\\forall a, b, c \\in G$:\n    $a \\circ \\left( b \\circ c \\right) =\n    \\left( a \\circ b \\right) \\circ c$\n  \\item Identity element: $\\exists e \\in G$ such that\n    $\\forall a \\in G$: $e \\circ a = a \\circ e = a$\n  \\item Inverse element: $\\forall a \\in G$ $\\exists a^{-1} \\in G$ such that\n    $a \\circ a^{-1} = e$\n  \\end{enumerate}\n  In this case $\\left(G, \\circ\\right)$ is called as group.\n\\end{definition}\nTherefore the group is a \\mynameref{def:monoid} with inverse element\nproperty. \n\n\\begin{example}[Group $\\mathbb{Z}/2\\mathbb{Z}$]\n  Consider a set of 2 elements: $G = \\left\\{0, 1\\right\\}$ with the\n  operation $\\circ$ defined by the table \\ref{tab:CayleyZ2Z}.\n  \\begin{table}\n    \\centering\n    \\caption{Cayley table for $\\mathbb{Z}/2\\mathbb{Z}$}\n    \\label{tab:CayleyZ2Z}\n    \\begin{tabular}{l|ll}\n      \\toprule\n      $\\circ$ & 0 & 1 \\\\\n      \\midrule\n      0 & 0 & 1 \\\\\n      1 & 1 & 0 \\\\\n      \\bottomrule\n    \\end{tabular}\n  \\end{table}\n\n  The identity element is $0$ i.e. $e = 0$.\n  Inverse element is the element itself\n  because $\\forall a \\in G$: $a \\circ a = 0 = e$.\n\n  See also example \\ref{ex:quotientgroup}\n  \\label{ex:groupZ2}\n\\end{example}\n\n\\begin{definition}[Order of element in group]\n  Order, sometimes period, of an element a of a group is the smallest\n  positive integer $m$ such that $a^m = e$ (where $e$ denotes the identity\n  element of the group, and am denotes the product of $m$ copies of\n  $a$). If no such m exists, a is said to have infinite order.\n  \\label{def:grouporder}\n\\end{definition}\n\n\\begin{theorem}[Lagrange]\n  For any finite group $G$, the order (number of elements) of every\n  subgroup $H$ of $G$ divides the order of $G$. \n  \\label{thm:lagrange}\n\\end{theorem}\n\n\\begin{theorem}[Finite group of prime order]\n  Let $G$ is a finite group of prime order i.e.\n  $\\left|G\\right| = p$, where $p$ is prime number. Then $G$ is a\n  \\mynameref{def:cyclicgroup}. \n  \\label{thm:finite_group_of_prime_order}\n  \\begin{proof}\n    Let $g \\in G$ such that $g \\ne e$ then, by theorem\n    \\ref{thm:lagrange},\n    we have \n    $\\left|\\left<g\\right>\\right| \\mid \\left|G\\right|$. Thus\n    $\\left|\\left<g\\right>\\right| = p$ because \n    $\\left|G\\right| = p$ and $p$ is a prime number. As result we have\n    $G = \\left<g\\right>$ and therefore $G$ is a cyclic group.\n  \\end{proof}\n\\end{theorem}\n\n\\begin{definition}[Subgroup]\n  Let we have a \\mynameref{def:group} $\\left(G, \\circ\\right)$. The\n  subset $S \\subset G$ is called as subgroup if $\\left(S,\n  \\circ\\right)$ is a \\mynameref{def:group}.\n  \\label{def:subgroup}\n\\end{definition}\n\n\\begin{definition}[Proper subgroup]\n  A proper subgroup of a group $G$ is a \\mynameref{def:subgroup} $H$\n  which is a proper subset of $G$ (i.e. $H \\ne G$) \\cite{wiki:group}\n  \\label{def:propersubgroup}\n\\end{definition}\n\n\\begin{definition}[Coset]\n  If $G$ is a group, and $H$ is a subgroup of $G$, and $g$ is an\n  element of $G$, then\n  \\[\n  gH = \\left\\{ gh \\vert h \\in H\\right\\}\n  \\]\n  is the left coset of $H$ in $G$ with respect to $g$, and\n  \\[\n  Hg = \\left\\{ hg \\vert h \\in H\\right\\}\n  \\]\n  is the right coset of $H$ in $G$ with respect to $g$.\n  \\label{def:coset}\n\\end{definition}\n\n\\begin{definition}[Normal subgroup]\n  A subgroup, $N$, of a group $G$, is called a normal subgroup if it\n  is invariant under conjugation i.e. \n  \\[\n  N \\triangleleft G \\Leftrightarrow\n  \\forall n \\in N, \\forall g \\in G, g n g^{-1} \\in N\n  \\]  \n  The definition taken from \\cite{wiki:normalsubgroup}\n\n  We also can write normality in the \\mynameref{def:coset} notation as\n  follows.\n  $N \\triangleleft G$ if $\\forall g \\in G: gN = Ng$.\n  \\label{def:normalsubgroup}\n\\end{definition}\n\n\\begin{definition}[Simple group]\n   A simple group is a nontrivial group whose only\n   \\mynameref{def:normalsubgroup}s are the trivial group and the group\n   itself.\n\n   The definition taken from \\cite{wiki:simplegroup}\n   \\label{def:simplegroup}\n\\end{definition}\n\n\\begin{definition}[Quotient group]\n  A quotient group or factor group is a mathematical group obtained by\n  aggregating similar elements of a larger group using an equivalence\n  relation that preserves the group structure. For example, the\n  \\mynameref{def:cyclicgroup} of addition modulo n can be obtained from\n  the integers by \n  identifying elements that differ by a multiple of n and defining a\n  group structure that operates on each such class (known as a\n  congruence class) as a single entity. It is part of the mathematical\n  field known as group theory \\cite{wiki:quotientgroup}. \n\n  In a quotient of a group, the equivalence class of the identity\n  element is always a normal subgroup of the original group, and the\n  other equivalence classes are precisely the cosets of that normal\n  subgroup. The resulting quotient is written $G / N$, where $G$ is the\n  original group and $N$ is the normal subgroup.\n\n  In other words the quotient group can be defined as a set of all\n  left \\mynameref{def:coset}s (they also equal to the right cosets as\n  soon as $N$ is a \\mynameref{def:normalsubgroup}):\n  \\[\n  G/N = \\left\\{a N: a \\in G\\right\\}\n  \\]\n\n  See also example \\mynameref{ex:s3a3quotientgroup}.\n  \\label{def:quotientgroup}\n\\end{definition}\n\n\\begin{theorem}[Quotient group]\n  If $G$ is a group and $H \\triangleleft G$ then the operation $aH\n  \\cdot bH = a \\cdot H$ makes $G/H$ a group with identity $H$ and\n  inverse element $\\left(a H\\right)^{-1} = a^{-1} H$.\n  \\begin{proof}\n    See \\cite{book:kostrikin} p. 33.\n  \\end{proof}\n  \\label{thm:quotientgroup}\n\\end{theorem}\n\n\\begin{example}[Quotient group]\n  Consider \\cite{wiki:quotientgroup} a group of integers $\\mathbb{Z}$\n  (under addition) and the \n  subgroup $2\\mathbb{Z}$ of all even integers. This is a normal\n  subgroup, because $\\mathbb{Z}$ is \\mynameref{def:abeliangroup}. There\n  are only two \\mynameref{def:coset}s: the set \n  of even integers and the set of odd integers; therefore, the\n  quotient group $\\mathbb{Z}/2\\mathbb{Z}$ is the\n  \\mynameref{def:cyclicgroup} with two \n  elements. This \n  quotient group is isomorphic with the set $\\left\\{ 0, 1 \\right\\}$\n  with addition modulo 2; informally, it is sometimes said that\n  $\\mathbb{Z}/2\\mathbb{Z}$\n  equals the set $\\left\\{ 0, 1 \\right\\}$ with addition modulo 2.\n\n  See also example \\ref{ex:groupZ2}.\n  \\label{ex:quotientgroup}\n\\end{example}\n\n\\begin{theorem}[Correspondence theorem]\n  The correspondence theorem, sometimes referred to as the fourth\n  isomorphism theorem or the lattice theorem, states that if \n  $N$ is a \\mynameref{def:normalsubgroup} of a group  $G$, then there\n  exists a bijection from the set of all subgroups $A$ of $G$\n  containing $N$, onto the set of all subgroups of the quotient group\n  $G/N$. The structure of the subgroups of $G/N$ is exactly the same\n  as the structure of the subgroups of $G$ containing $N$, with \n  $N$ collapsed to the identity element \\cite{wiki:correspondence}.\n  \\label{thm:correspondence}\n\\end{theorem}\n\n\\begin{definition}[Commutator]\n  The commutator of two elements, $g$ and $h$, of a group $G$, is the\n  element \\cite{wiki:commutator}\n  \\[\n  \\left[g, h\\right] = g^{-1} h^{-1} g h\n  \\]\n  \\label{def:commutator}\n\\end{definition}\n\n\\begin{definition}[Commutator subgroup]\n  The commutator subgroup or derived subgroup of a group is the\n  subgroup generated by all the \\mynameref{def:commutator}s of the group \n  \\cite{wiki:commutatorsubgroup}.\n  \\label{def:commutatorsubgroup}\n\\end{definition}\n\n\\begin{theorem}[About quotient group and commutator subgroup]\n  Given a group $G$ a \\mynameref{def:quotientgroup} $G/N$ is an\n  \\mynameref{def:abeliangroup} if and only if $N \\supseteq \\left[G,\n    G\\right]$\n  \\cite{wiki:commutatorsubgroup}\n  \\label{thm:about_quotient_group_and_commutatorsubgroup}\n\\end{theorem}\n\n\\begin{definition}[Abelianization]\n  The quotient $G/[G,G]$ is an abelian group\n  (as it follows from theorem \\ref{thm:about_quotient_group_and_commutatorsubgroup})\n  called the abelianization of $G$ or $G$ made abelian.\n  \\cite{wiki:commutatorsubgroup}\n  \\label{def:abelianization}\n\\end{definition}\n\n\\subsection{Cyclic group}\n\n\\begin{definition}[Cyclic group]\n  A cyclic group or monogenous group is a group that is generated by a\n  single element.\n  Note that \\mynameref{ex:groupZ2} is a cyclic group.\n  See example \\ref{ex:multiplicativegroup}.\n  \\label{def:cyclicgroup}\n\\end{definition}\n\n\\begin{theorem}[Fundamental theorem of cyclic groups]\n  In abstract algebra, every subgroup of a \\mynameref{def:cyclicgroup} is\n  cyclic. Moreover, for a finite cyclic group of order $n$, every\n  \\mynameref{def:subgroup}'s order is a divisor of $n$, and there is\n  exactly one subgroup for each divisor.This result has been called the\n  fundamental theorem of cyclic groups\n  \\cite{wiki:subgroups_of_cyclic_groups}\n  \\label{thm:fundamentaltheoremofcyclicgroup}\n\\end{theorem}\n\n\\begin{theorem}[About subgroups of a cyclic group]\n  Let \\cite{mathstackexchange:cyclicgroupssubgroup}\n    $G=\\left<a\\right>$ be a cyclic group. \n  \\begin{enumerate}\n  \\item Every subgroup $S$ of $G$ is cyclic\n  \\item If $\\left|G\\right| = n$, then $G$ has a unique subgroup of\n    order $d$ for each divisor $d$ of $n$\n  \\end{enumerate}\n  See example \\ref{ex:multiplicativegroup}\n  \\label{thm:subgroupofcyclicgroup}\n\\end{theorem}\n\n\n\\subsection{Group action}\n\n\\begin{definition}[Action]\n  An action of a group is a way of\n  interpreting the elements of the \n  group as \"acting\" on some space in a way that preserves the structure\n  of that space. See also \\cite{wiki:groupaction}.\n  \\label{def:action}\n\\end{definition}\n\n\\begin{definition}[Orbit]\n  Consider \\cite{wiki:groupaction} a group $G$ acting on a set\n  $X$. The orbit of an element $x \\in X$ \n  is the set of elements in $X$ to which $x$ can be moved by the elements\n  of $G$:\n  \\[\n  Orb\\left(x\\right) = \\left\\{y \\in X: \\exists g \\in G: y = g \\cdot x \\right\\}\n  \\]\n  The orbit of element $x$  is also denoted as $G\\left(x\\right)$.\n  \\label{def:orbit}\n\\end{definition}\n\n\\begin{definition}[Fixed point]\n  The set of points of $X$ fixed by a group action are called the\n  group's set of fixed points, defined by\n  \\[\n  \\left\\{\n  x: g x = x, \\forall g \\in G\n  \\right\\}.\n  \\]\n  see also \\cite{mathworld:groupfixedpoint}. \n  \\label{def:fixedpoint}\n\\end{definition}\n\n\\begin{definition}[Stabilizer subgroup]\n  For every $x$ in $X$, we define \\cite{wiki:groupaction} the\n  stabilizer subgroup of $G$ with \n  respect to $x$ (also called the isotropy group) as the set of all\n  elements in $G$ that fix $x$: \n  \\[\n  G_{x}=\\{g\\in G\\mid g\\cdot x=x\\}\n  \\]\n  \\label{def:stabilizersubgroup}\n\\end{definition}\n\n\\begin{theorem}[Orbit-stabilizer theorem]\n  If group $G$ and the set the group acting $X$ are finite then\n\n  \\[\n  \\left|G\\right| = \\left|Orb\\left(x\\right)\\right|\\left|G_x\\right|\n  \\]\n  where $x \\in X$, $G\\left(x\\right)$ - is the \\mynameref{def:orbit},\n  $G_x$ - \\mynameref{def:stabilizersubgroup}.\n  \n  Note: the result was got from \\cite{wiki:groupaction} as\n  orbit-stabilizer theorem + \\mynameref{thm:lagrange}\n  \\label{thm:orbitstabilizertheorem}\n\\end{theorem}\n\n\\begin{definition}[Transitive group action]\n  The action of $G$ on $X$ is called \\cite{wiki:groupaction}\n  transitive if $X$ is non-empty and if for each pair $x, y \\in X$ there\n  exists a $g \\in G$ such that $gx = y$.\n  \\label{def:transitive}\n\\end{definition}\n\n\\begin{definition}[Free group action]\n  The action of $G$ on $X$ is called \\cite{wiki:groupaction}\n  free if, given $g, h \\in G$, the existence of an $x \\in X$ with $g(x)\n  = h(x)$ implies $g = h$.\n  \\label{def:freeaction}\n\\end{definition}\n\n\\begin{definition}[Quotient of the group action]\n  Consider \\cite{wiki:groupaction} a group $G$ acting on a set\n  $X$. The set of all \\mynameref{def:orbit}s of $X$ under the action of\n  $G$ is written as $X/G$, and is called the quotient of the action.\n  \\label{def:quotientofgroupaction}\n\\end{definition}\n\n\\subsection{Direct product}\n\n\\begin{definition}[Direct product]\n  Given groups $G$ and $H$, the direct product $G \\times H$ is defined as follows:\n\n  The underlying set is the Cartesian product, $G \\times H$. That is, the\n  ordered pairs $\\left(g,h\\right)$, where $g \\in G$ and $h \\in H$. \n  The binary operation on $G \\times H$ is defined component-wise:\n  \\[\n  \\left(g_1,h_1\\right)\\left(g_2,h_2\\right) =\n  \\left(g_1 \\cdot g_2, h_1 \\circ h_2\\right)\n  \\]\n  The resulting algebraic object satisfies the axioms for a group.\n  See \\cite{wiki:directproduct}.\n\n  The direct product of 2 \\mynameref{def:abeliangroup}s is also called\n  \\mynameref{def:directsum} \n  \n  \\label{def:directproduct}\n\\end{definition}\n\n\\begin{property}[Direct product of groups]\n  Let $G_1$, $G_2$ - \\mynameref{def:group}s and $G = G_1 \\times G_2$ -\n  \\mynameref{def:directproduct} of the groups. Then\n  \\begin{enumerate}\n  \\item $G_1 \\cong \\left(G_1, 1_{G_2}\\right)$ and\n    $G_2 \\cong \\left(1_{G_1}, G_2\\right)$\n  \\item $G_1$ and $G_2$ are \\mynameref{def:normalsubgroup}s in $G$\n  \\end{enumerate}\n  See \\cite{wiki:directproduct}.\n  \\label{property:directproduct}\n\\end{property}\n\n\\begin{property}[Quotient of direct product]\n  Let $G_1$, $G_2$ - \\mynameref{def:group}s and $G = G_1 \\times G_2$ -\n  \\mynameref{def:directproduct} of the groups.\n  Then\n  \\[\n  G/G_1 \\cong G_2\n  \\]\n  and\n  \\[\n  G/G_2 \\cong G_1\n  \\]\n  \\label{property:directproductquotient}\n  \\begin{proof}\n    Lets prove the first claim:\n    $G/G_1 \\cong G_2$ (the second one is analogous).\n    Consider projection\n    $\\pi: G \\xrightarrow[(g_1, g_2) \\to (1_{G_1}, g_2)]{} G_2$. The\n    $\\pi$ is \\mynameref{def:homomorphism}. Really\n    let $a = (a_1, a_2), b = (b_1, b_2) \\in G$ where\n    $a_{1}, b_1 \\in G_1$, $a_2, b_{2} \\in G_2$:\n    \\begin{eqnarray}\n      \\pi\\left(a \\cdot b\\right) = \\pi\\left(\n      (a_1, a_2) \\cdot (b_1, b_2)\n      \\right) =\n      \\nonumber \\\\\n      = \\pi\\left(\n      (a_1 b_1, a_2 b_2)\n      \\right) = a_2 b_2 =\n      \\pi\\left(a\\right) \\pi\\left(b\\right)\n      \\nonumber\n    \\end{eqnarray}\n    As result $\\pi$ is a \\mynameref{def:homomorphism}.\n    \n    The $\\pi$ is also a \\mynameref{def:surjection} because $\\forall a_2\n    \\in G_2$ $\\exists a \\in G$ such that $\\pi(a) = a_2$. Really we can\n    use $a = (1_{G_1}, a_2)$.\n    \n    Therefore by \\mynameref{thm:firstisomorphism} one can get\n    \\[\n    G/\\ker{\\pi} \\cong G_2,\n    \\]\n    but $\\forall g_1 \\in G_1$ we have $(g_1, 1_{G_2}) \\in \\ker{\\pi}$.\n    And conversely $\\forall k \\in \\ker \\pi$ we have $k = (k_1, k_2)$\n    where $k_1 \\in G_1$ and $k_2 = 1_{G_2}$.\n    As result (see property \\ref{property:directproduct})\n    \\[\n    \\ker \\pi = \\left(G_1, 1_{G_2}\\right) \\cong G_1.\n    \\]\n    Therefore\n    \\[\n    G/G_1 \\cong G_2.\n    \\]\n  \\end{proof}\n\\end{property}\n\n\\subsection{Sylow theorems}\n\n\\begin{corollary}[Sylow]\n  Given a finite group $G$ and a prime number $p$ dividing the order of $G$,\n  then there exists an element (and hence a subgroup) of order $p$ in\n  $G$ \\cite{wiki:sylow}\n  \\label{cor:sylow}\n\\end{corollary}\n\n\\subsection{Abelian group}\n\n\\begin{definition}[Abelian group]\n  Let we have a \\mynameref{def:group} $\\left(G, \\circ\\right)$.\n  The group is called an Abelian or commutative if\n  $\\forall a, b \\in G$ it holds $a \\circ b = b \\circ a$.\n  \\label{def:abeliangroup}\n\\end{definition}\n\n\\begin{theorem}[About order of element of an Abelian group]\n  If $G$ is a finite \\mynameref{def:abeliangroup} and $m$ is the maximal\n  order of the elements of $G$ then the order of every element of $G$\n  divides $m$ \n  \\label{thm:abelianelementorder}\n\\end{theorem}\n\n\\begin{theorem}\n  Let $G$ is an \\mynameref{def:abeliangroup} and $n = \\left|G\\right|$\n  the group order (number of elements) then $\\forall g \\in G$ the\n  following statement holds\n  \\[\n  g^n = e,\n  \\]\n  there $e$ is the group identity.\n  \\begin{proof}\n    Let $m$ is the maximal order of group $G$. In this case by\n    \\mynameref{thm:lagrange} $m \\mid n$ i. e. $n = k_1 m$ where $k_1 \\in\n    \\mathbb{Z}$. Let $l$ is the order of $g$ i.e. $g^l = e$. By the\n    theorem \\ref{thm:abelianelementorder} $l \\mid m$ i.e.\n    $m = k_2 l$. Thus\n    \\[\n    g^n = \\left(g^m\\right)^{k_1} = \n    \\left(g^l\\right)^{k_2 k_1} = e.\n    \\]\n  \\end{proof}\n  \\label{thm:abelianelement}\n\\end{theorem}\n\n\\begin{theorem}[Cyclic Group is Abelian]\n  Let $G$ be a \\mynameref{def:cyclicgroup} then $G$ is\n  \\mynameref{def:abeliangroup} \n  \\label{thm:cyclic_group_is_abelian}\n  \\begin{proof}\n    As soon as $G = \\left<g\\right>$ then\n    $\\forall x,y \\in G, \\exists n,m \\in \\mathbb{N}$ such that\n    $x = g^n, y = g^m$. In the case\n    \\[\n    xy = g^n g^m = g^{n+m} = g^m g^n = yx,\n    \\]\n    i.e. $G$ is abelian. \n  \\end{proof}\n\\end{theorem}\n\n\\begin{remark}[Not every Abelian group is cyclic]\n  The theorem statement cannot be reversed i.e. there exist abelian\n  group that are not cyclic. For example well known \\mynameref{def:v4}\n  $V_4$  that is an\n  \\mynameref{def:abeliangroup} but not \\mynameref{def:cyclicgroup}\n\\end{remark}\n\n\\begin{definition}[Klein four group]\n  \\label{def:v4}\n  The Klein four group $V_4$ is a group of order 4\n  \\footnote{there are only 2 groups of order 4: $V_4$ and\n    $\\mathbb{Z}/4\\mathbb{Z}$ (the only cyclic group of order 4)}\n  The Cayley table for the group is on the table \\ref{tab:CayleyV4}\n  \\cite{wiki:klein4group}. \n  \\begin{table}\n    \\centering\n    \\caption{Cayley table for $V_4$}\n    \\label{tab:CayleyV4}\n    \\begin{tabular}{l|llll}\n      \\toprule\n      $\\circ$ & $e$ & $a$ & $b$ & $c$\\\\\n      \\midrule\n      $e$ & $e$ & $a$ & $b$ & $c$ \\\\\n      $a$ & $a$ & $e$ & $c$ & $b$ \\\\\n      $b$ & $b$ & $c$ & $e$ & $a$ \\\\\n      $c$ & $c$ & $b$ & $a$ & $e$ \\\\    \n      \\bottomrule\n    \\end{tabular}\n    \\end{table}  \n\\end{definition}\n\n\\begin{example}[Klein four group]\n  There are several examples of $V_4$:\n  \\begin{itemize}\n  \\item $V_4 \\cong \\mathbb{Z}/2\\mathbb{Z} \\oplus \\mathbb{Z}/2\\mathbb{Z}$\n  \\item $V_4 \\cong \\left(\\mathbb{Z}/8\\mathbb{Z}\\right)^\\times \\cong \\left(\\mathbb{Z}/12\\mathbb{Z}\\right)^\\times$\n  \\end{itemize}\n\\end{example}\n\n\\begin{definition}[Direct sum]\n  The direct sum of two abelian groups $A$ and\n  $B$ is another abelian group $A \\oplus B$ consisting of the ordered\n  pairs\n  $\\left(a, b\\right)$ where $a \\in A$ and $b \\in B$.\n  \\cite{wiki:directsum}\n  See also \\mynameref{def:directproduct}.\n  \n  \\label{def:directsum}\n\\end{definition}\n\n\\begin{definition}[Finitely generated abelian group]\n  An \\mynameref{def:abeliangroup} $(G, +)$ is called finitely generated\n  \\cite{wiki:fgagroup} \n  if there exist finitely many elements $x_1, \\dots, x_s$ in $G$ such that\n  $\\forall x \\in G$:\n  \\begin{equation}\n    x = n_1 x_1 + \\dots + n_s x_s\n    \\label{eq:fgagroup}\n  \\end{equation}\n  with $n_i \\in \\mathbb{Z}$. In this case we say that $\\{x_1, \\dots,\n  x_s\\}$ is a generating set of $G$.\n\n  In the (\\ref{eq:fgagroup}) we have the following:\n  \\[\n  n_i x_i = \\underbrace{x_i + \\dots x_i}_{n_i \\text{ times}}\n  \\]\n  \\label{def:fgagroup}\n\\end{definition}\n\n\\begin{theorem}[The fundamental theorem of finitely generated abelian\n    groups]\n  Every \\mynameref{def:fgagroup} $G$ is isomorphic to a\n  \\mynameref{def:directsum} of primary cyclic groups and infinite cyclic\n  groups. A primary cyclic group is one whose order is a power of a\n  prime. That is, every finitely generated abelian group is isomorphic\n  to a group of the form\n  \\[\n  \\mathbb{Z}^n \\oplus \\mathbb{Z}_{q_1} \\oplus\n  \\dots \\oplus \\mathbb{Z}_{q_t}\n  \\]\n  where the rank $n \\ge 0$, and the numbers $q_1, \\dots , q_t$ are\n  powers of (not \n  necessarily distinct) prime numbers. In particular, $G$ is finite if\n  and only if $n = 0$. The values of $n, q_1, \\dots , q_t$ are (up to\n  rearranging the indices) uniquely determined by $G$. \n  The statement was took from \\cite{wiki:fgagroup}.\n  \\label{thm:fgagroup}\n\\end{theorem}\n\n\\begin{theorem}[Simple subgroup of an abelian group]\n  Every non-simple abelian group has a simple normal subgroup.\n  ??? add link ???\n  \\label{thm:simple_subgroup_of_abelian}\n\\end{theorem}\n  \n\\section{Permutations}\n\n\\begin{example}[Permutation]\n  The following permutation\n  \\[ \\pi = \n  \\begin{array}{c}\n    1 \\to 2 \\\\\n    2 \\to 5 \\\\\n    3 \\to 4 \\\\\n    4 \\to 3 \\\\\n    5 \\to 1 \n  \\end{array}\n  \\]\n  can be also written in different forms. The most common one is the following:\n  \\[\n  \\pi = \\begin{pmatrix}\n    1 & 2 & 3 & 4 & 5 \\\\\n    2 & 5 & 4 & 3 & 1\n  \\end{pmatrix}.\n  \\]\n  In the permutation we can see 2 cycles:\n  $1 \\to 2 \\to 5 \\to 1$ and $3 \\to 4 \\to 3$. The first cycle can be\n  written as $(1,2,5)$ (or $(5,1,2)$ or $(2,5,1)$) and the second\n  one as $(3,4)$ (or $(4,3)$). The cycles gives us the shortest form\n  of writing the permutation:\n  \\[\n  \\pi = (1,2,5)(3,4) = (3,4)(5,1,2).\n  \\]\n  \n  If we have 2 permutations\n  \\[\n  \\pi_1 = \\begin{pmatrix}\n    1 & 2 & 3 & 4 & 5 \\\\\n    3 & 1 & 5 & 2 & 4\n  \\end{pmatrix}.\n  \\]\n  and\n  \\[\n  \\pi_2 = \\begin{pmatrix}\n    1 & 2 & 3 & 4 & 5 \\\\\n    2 & 5 & 4 & 3 & 1\n  \\end{pmatrix}.\n  \\]\n  then we can combine them into the new one (via a multiplication)\n  \\[ \\pi = \\pi_1 \\pi_2 = \n  \\begin{array}{c}\n    1 \\to 2 \\to 1 \\\\\n    2 \\to 5 \\to 4\\\\\n    3 \\to 4 \\to 2\\\\\n    4 \\to 3 \\to 5\\\\\n    5 \\to 1 \\to 3 \n  \\end{array} =\n  \\begin{pmatrix}\n    1 & 2 & 3 & 4 & 5 \\\\\n    1 & 4 & 2 & 5 & 3\n  \\end{pmatrix} = (1)(2,4,5,3) = (2,4,5,3)\n  \\]\n\n  We have identity element\n  \\[\n  e =  \\begin{pmatrix}\n    1 & 2 & 3 & 4 & 5 \\\\\n    1 & 2 & 3 & 4 & 5\n  \\end{pmatrix}\n  \\]\n  such that $\\forall \\pi: \\pi e = e \\pi = \\pi$.\n  \n  For every $\\pi$ we can define $\\pi^{-1}$ such that\n  $\\pi \\pi^{-1} = \\pi^{-1} \\pi = e$.\n\n  For our example\n  \\[\n  \\pi = \\begin{pmatrix}\n    1 & 2 & 3 & 4 & 5 \\\\\n    2 & 5 & 4 & 3 & 1\n  \\end{pmatrix} = (1,2,5)(3,4)\n  \\]\n  we have\n  \\[\n  \\pi^{-1} = \\begin{pmatrix}   \n    2 & 5 & 4 & 3 & 1 \\\\\n    1 & 2 & 3 & 4 & 5 \n  \\end{pmatrix} =\n  \\begin{pmatrix}   \n    1 & 2 & 3 & 4 & 5 \\\\\n    5 & 1 & 4 & 3 & 2 \n  \\end{pmatrix} = (1,5,2)(3,4)\n  \\]\n\n  As result we have a \\mynameref{def:group} of permutations.\n  \\label{ex:permutation}\n\\end{example}\n\n\\begin{definition}[Parity of a permutation]\n  When $X$ is a finite set of at least two elements, the permutations of\n  X (i.e. the bijective functions from $X$ to $X$) fall into two classes\n  of equal size: the even permutations and the odd permutations. If\n  any total ordering of $X$ is fixed, the parity (oddness or evenness)\n  of a permutation $\\sigma$ of $X$ can be defined as the\n  parity of the number of inversions for $\\sigma$, i.e., of pairs of elements\n  $x, y$ of $X$ such that $x < y$ and $\\sigma (x) > \\sigma (y)$\n  \\cite{wiki:paritypermutation}.  \n  \\label{def:paritypermutation}\n\\end{definition}\n\n\\begin{example}[Parity of a permutation]\n  For the following permutation $(2,5,4,1,3)$ we have the following\n  inversions\n  \\begin{eqnarray}\n    (2,5,4,1,3) \\to_{(1,2)}\n    (1,5,4,2,3) \\to_{(5,2)}\n    \\nonumber \\\\\n    (1,2,4,5,3) \\to_{(3,4)}\n    (1,2,3,5,4) \\to_{(5,4)}\n    (1,2,3,4,5)\n    \\nonumber\n  \\end{eqnarray}\n  We have made 4 inversions and as result the permutation is even.\n\n  The same result can be got if we use the following equation $l - 1$\n  where $l$ is the circle length (5 in our case) \n  \\label{ex:paritypermutation}\n\\end{example}\n\n\\begin{definition}[Alternating group]\n  Alternating group \\cite{wiki:alteringgroup} is the group of even\n  permutations (see definition \\ref{def:paritypermutation}) of a finite \n  set. The alternating group on a set of $n$ elements is called the\n  alternating group of degree n, or the alternating group on n letters\n  and denoted by $A_n$.\n  \\label{def:alternatinggroup}\n\\end{definition}\n\n\\begin{example}[$S_n$ group]\n  If we a have a permutation of $n$ elements then it's possible to do\n  by means of $n!$ ways.\n  \\label{ex:sngroup}\n\\end{example}\n\n\\begin{example}[$S_1$ group]\n  $S_1$ permutation of 1 element consists of only one element $e$ -\n  the simplest possible group\n  \\label{ex:s1group}\n\\end{example}\n\n\\begin{example}[$S_2$ group]\n  $S_2$ permutation consists of 2 elements:\n  \\begin{enumerate}\n  \\item identity:\n    \\(\n    e = \\begin{pmatrix}\n      1 & 2 \\\\\n      1 & 2\n    \\end{pmatrix}\n    \\) \n  \\item transposition:\n    \\(\n    \\tau = \\begin{pmatrix}\n      1 & 2 \\\\\n      2 & 1\n    \\end{pmatrix}\n    \\) \n  \\end{enumerate}\n  It's easy to see that the Cayley table has the form \\ref{tab:CayleyS2}\n    \\begin{table}\n    \\centering\n    \\caption{Cayley table for $S_2$}\n    \\label{tab:CayleyS2}\n    \\begin{tabular}{l|ll}\n      \\toprule\n      $\\circ$ & $e$ & $\\tau$ \\\\\n      \\midrule\n      $e$ & $e$ & $\\tau$ \\\\\n      $\\tau$ & $\\tau$ & $e$ \\\\\n      \\bottomrule\n    \\end{tabular}\n    \\end{table}\n  \\label{ex:s2group}\n\\end{example}\n\n\\begin{example}[$S_3$ group]\n    $S_3$ permutation consists of 6 elements: $e, \\tau, \\tau_1, \\tau_2,\n    \\sigma, \\sigma_1$. The most important are $e, \\tau$ and $\\sigma$\n    and all others can be obtained from this ones (see table\n    \\ref{tab:CayleyS3}).\n  \\begin{enumerate}\n  \\item identity\n    \\(\n    e = \\begin{pmatrix}\n      1 & 2 & 3\\\\\n      1 & 2 & 3\n    \\end{pmatrix}\n    \\) \n  \\item transposition:\n    \\(\n    \\tau = \\begin{pmatrix}\n      1 & 2 & 3\\\\\n      2 & 1 & 3\n    \\end{pmatrix}\n    \\) \n  \\item circle:\n    \\(\n    \\sigma = \\begin{pmatrix}\n      1 & 2 & 3\\\\\n      2 & 3 & 1\n    \\end{pmatrix}\n    \\) \n  \\end{enumerate}\n\n  Another elements of $S_3$:\n  \\(\n  \\tau_1 = \\begin{pmatrix}\n    1 & 2 & 3\\\\\n    1 & 3 & 2\n  \\end{pmatrix}\n  \\),\n  \\(\n  \\tau_2 = \\begin{pmatrix}\n    1 & 2 & 3\\\\\n    2 & 1 & 3\n  \\end{pmatrix}\n  \\) and\n  \\(\n  \\sigma_1 = \\begin{pmatrix}\n    1 & 2 & 3\\\\\n    3 & 1 & 2\n  \\end{pmatrix}\n  \\).    \n\n  \\begin{table}\n    \\centering\n    \\caption{Cayley table for $S_3$ \\cite{wiki:permutationgroups}}\n    \\label{tab:CayleyS3}\n    \\begin{tabular}{l|llllll}\n      \\toprule\n      $\\circ$ & $e$ & $\\sigma$ & $\\sigma_1$ & $\\tau$ & $\\tau_1$ & $\\tau_2$\\\\\n      \\midrule\n      $e$ & $e$ & $\\sigma$ & $\\sigma_1$ & $\\tau$ & $\\tau_1$ & $\\tau_2$\\\\\n      $\\sigma$ & $\\sigma$ & $\\sigma_1$ & $e$ & $\\tau_2$ & $\\tau$ & $\\tau_1$\\\\\n      $\\sigma_1$ & $\\sigma_1$ & $e$ & $\\sigma$ & $\\tau_1$ & $\\tau_2$ & $\\tau$\\\\\n      $\\tau$ & $\\tau$ & $\\tau_1$ & $\\tau_2$ & $e$ & $\\sigma_1$ & $\\sigma$\\\\\n      $\\tau_1$ & $\\tau_1$ & $\\tau_2$ & $\\tau$ & $\\sigma$ & $e$ & $\\sigma_1$\\\\\n      $\\tau_2$ & $\\tau_2$ & $\\tau$ & $\\tau_1$ & $\\sigma_1$ & $\\sigma$ & $e$\\\\\n      \\bottomrule\n    \\end{tabular}\n  \\end{table}\n  As we can see from the table \\ref{tab:CayleyS3} the elements $e,\n  \\sigma, \\sigma_1$ forms a subgroup of $S_3$ moreover all the\n  permutation (see definition \\ref{def:paritypermutation}). I.e. there\n  we will have \\mynameref{def:alternatinggroup} $A_3$.\n  \\label{ex:s3group}\n\\end{example}\n\n\\begin{example}[$S_3/A_3$ quotient group]\n  Lets consider the following \\mynameref{def:quotientgroup}\n  $S_3/A_3$. As we can see all elements of $S_3$ can be divided into 2\n  classes each of them with size $3 = \\left|A_3\\right|$: $E= A_3 =\n  \\left\\{e, \\sigma, \\sigma_1\\right\\}$ \n  and $G = \\left\\{\\tau, \\tau_1, \\tau_2\\right\\}$. If we take an element\n  $x_1 \\in E$ and multiply it on another element of $x_2 \\in E$ we\n  will get $x_1 x_2 \\in E$ (see table \\ref{tab:CayleyS3}) i.e. $E\n  \\cdot E =\n  E$. For $G$ we can get $G \\cdot G = E$ and $E \\cdot G = G \\cdot E =\n  G$. Therefore $S_3/A_3 = \\{E, G\\}$ forms a group of order 2. Thus\n  \\[\n  S_3/A_3 \\cong \\mathbb{Z}/2\\mathbb{Z}\n  \\]\n  \\label{ex:s3a3quotientgroup}\n\\end{example}\n\n\\begin{definition}[Cycle]\n  A cyclic permutation (or cycle) is a permutation of the elements of\n  some set $X$ which maps the elements of some subset $S$ of $X$ to each\n  other in a cyclic fashion, while fixing (that is, mapping to\n  themselves) all other elements of $X$. If $S$ has $k$ elements, the cycle\n  is called a $k$-cycle \\cite{wiki:cyclicpermutation}.\n  \\label{def:cycle}\n\\end{definition}\n\n\\begin{example}[Cycle]\n  The following permutation is a 3-cycle:\n  \\[\n  (1,2,3) = \\begin{array}{c}\n                1 \\to 2 \\\\\n                2 \\to 3 \\\\\n                3 \\to 1 \n              \\end{array}\n  \\]\n  \\label{ex:cycle}\n\\end{example}\n\n\\begin{definition}[Transposition]\n  A cycle with only two elements is called a transposition.\n  \\cite{wiki:cyclicpermutation}\n  \\label{def:transposition}\n\\end{definition}\n\n\\begin{example}[Transposition]\n  The following permutation is a transposition:\n  \\[\n  (1,2) = \\begin{array}{c}\n                1 \\to 2 \\\\\n                2 \\to 1 \n              \\end{array}\n  \\]\n  \\label{ex:transposition}\n  See also example \\ref{ex:transposition_product}\n\\end{example}\n\n\\begin{example}[Transposition product]\n  \\label{ex:transposition_product}\n  The example shows a product of 2 \\mynameref{def:transposition}s with a\n  same element:\n  \\begin{eqnarray}\n    (a,c)(a,b) = \n    \\begin{array}{c}\n      a \\to b \\\\\n      b \\to a \\to c\\\\\n      c \\to a \n    \\end{array} = (a,b,c)\n    \\nonumber\n  \\end{eqnarray}\n\\end{example}\n\n\n\\begin{theorem}\n  Every permutation can be represented as a product of\n  \\mynameref{def:transposition}s\n  \\begin{proof}\n    This is because any cycle $(a_1, a_2, a_3, \\dots, a_{n-1}, a_n)$\n    can be represented as a product of transpositions as follows\n    \\[\n    (a_1, a_2, a_3, \\dots, a_{n-1}, a_n) =\n    (a_1, a_n)(a_1, a_{n-1}) \\dots (a_1, a_3) (a_1, a_2)\n    \\]\n  \\end{proof}\n  \\label{thm:permutationrepresent}\n\\end{theorem}\n\n\\begin{corollary}\n  $S_n$ is generated by any combination of a \\mynameref{def:transposition} and\n  $n$-cycle if and only if $n$ is prime\n  \\label{cor:sn}\n  \\begin{proof}\n    See \\cite{mathstackexchange:sn}\n  \\end{proof}\n\\end{corollary}\n\n\\section{Rings and Fields}\n\n\\subsection{Rings}\n\n\\begin{definition}[Ring]\n  Consider a set $R$ with 2 binary operations defined. The first one\n  $\\oplus$ (addition) and elements of $R$ forms an\n  \\mynameref{def:abeliangroup}\n  under this operation. The second one is $\\odot$ (multiplication) and\n  the elements of $R$ forms a \\mynameref{def:monoid} under \n  the operation. The two binary operations are connected each other\n  via the following distributive law\n  \\begin{itemize}\n  \\item Left distributivity:\n    $\\forall a,b,c \\in R$:\n    $a \\odot \\left(b \\oplus c\\right) =\n    a \\odot b \\oplus a \\odot c$\n  \\item Right distributivity:\n    $\\forall a,b,c \\in R$:\n    $\\left( a \\oplus b \\right) \\odot c =\n    a \\odot c \\oplus b \\odot c$\n    \n  The identity element for $\\left(R, \\oplus\\right)$ is denoted as $0$\n  (additive identity).\n  The identity element for $\\left(R, \\odot\\right)$ is denoted as $1$\n  (multiplicative identity).\n\n  The inverse element to $a$ in $\\left(R, \\oplus\\right)$ is denoted as $-a$\n  \\end{itemize}\n\n  In this case $\\left(R, \\oplus, \\odot\\right)$ is called as ring.\n  \\label{def:ring}\n\\end{definition}\n\nThe \\mynameref{def:ring} is a generalization of integer numbers conception.\n\\begin{example}[Ring of integers $\\mathbb{Z}$]\n  The set of integer numbers $\\mathbb{Z}$ forms a \\mynameref{def:ring}\n  under $+$ and $\\cdot$ operations i.e. addition $\\oplus$ is\n  $+$ and multiplication $\\odot$ is $\\cdot$. Thus for integer\n  numbers we have the following \\mynameref{def:ring}:\n  $\\left(\\mathbb{Z}, +, \\cdot\\right)$\n  \\label{ex:ring}\n\\end{example}\n\n\\begin{definition}[Multiplicative group]\n  If $R$ is a ring then the multiplicative group\n  $\\left(R\\right)^\\times$\n  is a group of\n  invertible elements of $R$ with the defined multiplication operation.\n  \\label{def:multiplicativegroup}\n\\end{definition}\n\n\\begin{example}[Multiplicative group of integers modulo $n$]\n  Lets consider the following group\n  $\\left(\\mathbb{Z}/9\\mathbb{Z}\\right)^\\times =\n  \\left\\{1,2,4,5,7,8\\right\\}$\n  \\cite{wiki:multiplicativegroup}\n\n  The group has order 6. The group generator is $2$:\n  $2^1 = 2, 2^2 = 4, 2^3 = 8, 2^4 = 7, 2^5 = 5, 2^6 = 1$.\n  \n  Accordingly theorem\n  \\ref{thm:subgroupofcyclicgroup}, there are only 2\n  \\mynameref{def:propersubgroup} not equal to $id$.\n\n  One of them is a cyclic group of order 2: $\\left\\{1,8\\right\\} \\cong\n  \\mathbb{Z}/2\\mathbb{Z}$.\n\n  Another one is also cyclic and has order 3: $\\left\\{1, 4, 7\\right\\}\n  \\cong \n  \\mathbb{Z}/3\\mathbb{Z}$.\n  \n  \\label{ex:multiplicativegroup}\n\\end{example}\n\n\\subsection{Ideals}\n\n\\begin{definition}[Ideal]\n  \\label{def:ideal}\n  Lets we have the \\mynameref{def:ring}\n  $\\left(R, \\oplus, \\odot\\right)$. Subset $I \\subset R$ will be an\n  ideal if it satisfied the following conditions\n  \\begin{enumerate}\n  \\item $\\left(I, \\oplus\\right)$ is \\mynameref{def:subgroup} of\n    $\\left(R, \\oplus\\right)$\n  \\item $\\forall i \\in I$ and $\\forall r \\in R$:\n    $i \\odot r \\in I$ and $r \\odot i \\in I$\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{example}[Ideal $2 \\mathbb{Z}$]\n  Consider even numbers. They forms an \\mynameref{def:ideal} in\n  $\\mathbb{Z}$. Because multiplication of any even number to any\n  integer is an even. The ideal's symbolic name is $2 \\mathbb{Z}$.\n  \\label{ex:ideal}\n\\end{example}\n\n\\begin{example}[Ring of integers modulo $n$: $\\mathbb{Z}/n\\mathbb{Z}$]\n  Let $n \\in \\mathbb{Z}$ and $n > 1$. Then $n \\mathbb{Z}$ is an\n  \\mynameref{def:ideal}.\n\n  Two integer $a, b \\in \\mathbb{Z}$  are said to be congruent modulo\n  $n$, written\n  \\[\n  a \\equiv b ( \\mod n )\n  \\]\n  if their difference $a - b$ is an integer multiple of $n$.\n\n  Thus we have a separation of set $\\mathbb{Z}$ into subsets of\n  numbers that are congruent. Each subset has the following form\n  \\[\n  \\left\\{r\\right\\}_n = r + n \\mathbb{Z} =\n  \\left\\{r + n k \\mid k \\in \\mathbb{Z}\\right\\}\n  \\],\n  thus\n  \\[\n  \\mathbb{Z} = \\left\\{0\\right\\}_n \\cup \\left\\{1\\right\\}_n\n  \\cup \\dots \\cup \\left\\{n-1\\right\\}_n.\n  \\]\n\n  Very often use the following notation\n  \\[\n  \\bar{r} = \\left\\{r\\right\\}_n.\n  \\]\n\n  We can define the following operations\n  \\begin{eqnarray}\n    \\bar{k} \\oplus \\bar{l} = \\overline{k + l}\n    \\nonumber \\\\\n    \\bar{k} \\odot \\bar{l} = \\overline{k \\cdot l}\n    \\nonumber\n  \\end{eqnarray}\n  \n  The \\mynameref{def:ring} where the objects are defined is called as\n  $\\mathbb{Z}/n\\mathbb{Z}$.\n  \\label{ex:intmodulo}\n\\end{example}\n\n\\begin{definition}[Ideal generated by a set]\n  Let $R$ be a \\mynameref{def:ring} and $S$ is a sub set of $R$.\n  Consider the following set\n  \\[\n  I = \\left\\{\n  r_1 s_1 + \\dots + r_n s_n \\vert n \\in \\mathbb{N}, r_i \\in R, s_i \\in S\n  \\right\\}\n  \\]\n  $I$ is called by an ideal generated by set $S$ if\n  $\\forall r \\in R, i \\in I: r \\cdot i \\in I$.\n\n  The sum in the definition of the ideal should be finite. The ring is\n  assumed commutative in the definition.\n  \\label{def:idealset}\n\\end{definition}\n\n\\begin{definition}[Principal ideal]\n  The ideal that is generated by one element $a$ is called as\n  principal ideal and is denoted as $\\left(a\\right)$ i.e.\n  left principal ideal:\n  $\\left(a\\right) = \\left\\{r a \\mid \\forall r \\in R\\right\\}$ and\n  right principal ideal:\n  $\\left(a\\right) = \\left\\{a r \\mid \\forall r \\in R\\right\\}$\n  \\label{def:prinicipalideal}\n\\end{definition}\n\n\\begin{definition}[Integral domain]\nIn mathematics, and specifically in abstract algebra, an integral\ndomain is a nonzero commutative \\mynameref{def:ring} in which the\nproduct of any two nonzero elements is nonzero.\n\\label{def:integraldomain}\n\\end{definition}\n\n\\begin{definition}[Principal ideal domain]\n  In abstract algebra, a principal ideal domain, or PID, is an\n  \\mynameref{def:integraldomain} in which every ideal is principal, i.e., can be\n  generated by a single element.\n  \\label{def:pid}\n\\end{definition}\n\n\\begin{definition}[Maximal ideal]\n  A maximal ideal is an ideal that is maximal (with respect to set\n  inclusion) amongst all \\mynameref{def:properideal}s i.e.\n  $I$ is a maximal ideal of a ring $R$ if there are no other ideals\n  contained between $I$ and $R$ \\cite{wiki:maxideal}.\n\\label{def:maxideal}\n\\end{definition}\n\n\\begin{example}[Maximal ideal]\n  If $F$ is a \\mynameref{def:field} then the only maximal ideal is\n  $\\{0\\}$ \\cite{wiki:maxideal}.\n  \\label{ex:maxideal}\n\\end{example}\n\n\\begin{definition}[Prime ideal]\n  \\label {def:primeideal}\n  An ideal $I$ of a commutative ring $R$ is prime if it has the\n  following 2 properties \\cite{wiki:primeideal}\n  \\footnote{\n    There is a generalization of prime numbers in arithmetic\n  }\n  \\begin{enumerate}\n  \\item If $a,b \\in R$ such that $ab \\in I$ then $a \\in I$ or $b \\in I$\n  \\item$I$ is not equal the whole ring $R$\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{lemma}[$n\\mathbb{Z}$ prime ideal]\n  A positive integer $n$ is a prime if and only if $n\\mathbb{Z}$ is a\n  \\mynameref{def:primeideal} in $\\mathbb{Z}$ \\cite{wiki:primeideal}\n  \\label{lem:primeideal_in_Z}\n\\end{lemma}\n\n\\begin{lemma}\n  All nonzero \\mynameref{def:primeideal}s are maximal in a principal\n  ideal domain \\cite{wiki:maxideal}\n  \\label{lem:primeideal_is_maximal}\n\\end{lemma}\n\n\\begin{definition}[Proper ideal]\n$I$ is a proper ideal of a ring $R$ if $I \\subsetneq R$.\n\\label{def:properideal}\n\\end{definition}\n\n\\begin{theorem}[About proper ideal]\n  An ideal $I$ of ring $R$ is proper if and only if $1_R \\notin I$.\n  \\label{thm:properideal}\n\\end{theorem}\n\n\\begin{definition}[Quotient ring]\n  Quotient ring is a construction where one\n  starts with a ring $R$ and a two-sided ideal $I$ in $R$, and constructs a\n  new ring, the quotient ring $R/I$, whose elements are the\n  \\mynameref{def:coset}s of $I$ \n  in $R$ subject to special $+$ and $\\cdot$ operations.\n\n  Given a ring $R$ and a two-sided ideal $I \\subset R$, we may define\n  an equivalence relation $\\sim$ on $R$ as follows: \n  $a \\sim b$ if and only if $a - b \\in I$.\n  The equivalence class of the element $a$ in $R$ is given by\n  \\[\n  \\bar{a} = \\left\\{a\\right\\} = a + I := \\left\\{ a + r : r \\in I \\right\\}.\n  \\]\n  This equivalence class is also sometimes written as a mod $I$ and\n  called the \"residue class of a modulo I\" (see also example\n  \\ref{ex:intmodulo}).\n\n  The special $+$ and $\\cdot$ operations are defined as follows\n  \\[\n  \\forall \\bar{x},\\bar{y} \\in R/I:\n  \\bar{x} + \\bar{y} = \\left(x + I\\right) + \\left(y + I\\right) =\n  \\left(x+y\\right) + I = \\overline{x+y}.\n  \\]\n  \\[\n  \\forall \\bar{x},\\bar{y} \\in R/I:\n  \\bar{x} \\cdot \\bar{y} = \\left(x + I\\right) \\cdot \\left(y + I\\right) =\n  \\left(x \\cdot y\\right) + I = \\overline{x \\cdot y}.\n  \\]\n\n  As result we will get the following ring $\\left(R/I, +,\n  \\cdot\\right)$ is called the quotient ring of $R$ by $I$.\n\n  See also \\mynameref{def:quotientgroup}\n  \\label{def:quotientring}\n\\end{definition}\n\n\\subsection{Polynomial ring $K\\left[X\\right]$}\n\nLet we have a commutative \\mynameref{def:ring} $K$. Lets create a new\n\\mynameref{def:ring} $B$ with the following infinite sets as elements:\n\\begin{equation}\n  f = \\left(f_0, f_1, \\dots \\right), \\, f_i \\in K,\n  \\label{eq:polynomial}\n\\end{equation}\nsuch that only finite number of elements of the sets are non zero.\n\nWe can define addition and multiplication on $B$ as follows\n\\begin{eqnarray}\n  f + g = \\left(f_0 + g_0, f_1 + g_1, \\dots \\right),\n  \\nonumber \\\\\n  f \\cdot g = h = \\left(h_0, h_1, \\dots \\right),\n  \\label{eq:polynomialops}\n\\end{eqnarray}\nwhere\n\\[\nh_k = \\sum_{i + j =k} f_i g_j. \n\\]\n\nThe sequences (\\ref{eq:polynomial}) forms a \\mynameref{def:ring} with\nthe following identities:\n\\begin{itemize}\n\\item Additive identity: $\\left(0, 0, \\dots \\right)$\n\\item Multiplicative identity: $\\left(1, 0, \\dots \\right)$\n\\end{itemize}\n\nThe\nsequences $k = \\left(k, 0, \\dots \\right)$ added and multiplied as\nelements of $K$ this allows say that such elements are elements of\noriginal \\mynameref{def:ring} $K$. Thus $K$ is sub-ring of the new ring\n$B$.\n\nLet\n\\begin{eqnarray}\n  X = \\left(0, 1, 0, \\dots \\right),\n  \\nonumber \\\\\n  X^2 = \\left(0, 0, 1, \\dots \\right)\n  \\nonumber\n\\end{eqnarray}\nthus if we have\n\\[\nf = \\left(f_0, f_1, f_2, \\dots, f_n, 0, \\dots \\right),\n\\]\nwhere $f_n$ is the last non-zero element of (\\ref{eq:polynomial}),\nwhen one can get\n\\[\nf = f_0 + f_1 X + f_2 X^2 + \\dots + f_n X^n.\n\\]\n\n\\begin{definition}[Polynomial ring]\n  The \\mynameref{def:ring} of sequences (\\ref{eq:polynomial}) with\n  operations defined by (\\ref{eq:polynomialops}) is called as\n  polynomial ring $K\\left[X\\right]$.\n  \\label{def:polynomial}\n\\end{definition}\n\n\\begin{lemma}[Bézout]\n  Let $a$ and $b$ be nonzero integers and let $d$ be their greatest common\n  divisor. Then there exist integers $x$ and $y$ such that \n  \\[\n  a x + by = d.\n  \\]\n  \\label{lem:bezout}\n\\end{lemma}\n\n\\begin{definition}[Monic polynomial]\n  Monic polynomial is a univariate polynomial in which the leading\n  coefficient (the nonzero coefficient of highest degree) is equal to\n  1. Therefore, a monic polynomial has the form\n  \\[\n  x^n + a_{n-1}x^{n-1}+ \\dots + a_1 x + a_0\n  \\]\n  \\label{def:monicpolynomial}\n\\end{definition}\n\n\\begin{definition}[Irreducible polynomial]\n  An irreducible polynomial is, roughly speaking, a non-constant\n  polynomial that cannot be factored into the product of two\n  non-constant polynomials.\n  \\label{def:irreducible}\n\\end{definition}\n\n\\begin{example}[Irreducible polynomial]\n  The following polynomial is irreducible in\n  $\\mathbb{R}\\left[X\\right]$: $X^2 + 1$. The following one is also\n  irreducible despite it has a root: $X+1$.\n  \\label{ex:irreducible}\n\\end{example}\n\n\\begin{theorem}[About irreducible polynomials]\n  Let $\\pi(X)$ is an \\mynameref{def:irreducible} in $K\\left[X\\right]$ and let\n  $\\alpha$ be a root of $\\pi(X)$ in a some larger field.\n  $\\forall h(x) \\in K\\left(X\\right)$ if have the following statement:\n  $h\\left(\\alpha\\right) = 0$ if and only if $\\pi(X) \\mid h(X)$ in\n  $K\\left[X\\right]$.\n  \\begin{proof}\n    If $h(X) = \\pi(X) g(X)$ then $h(\\alpha) = 0$\n\n    From other side let $\\pi \\nmid h$ in $K\\left[X\\right]$ this means\n    that they are relatively prime in $K\\left[X\\right]$ and by\n    \\mynameref{lem:bezout} we can get $Q,R \\in K\\left[X\\right]$ such\n    that\n    \\[\n    \\pi(X) R(X) + h(X) Q(X) = 1,\n    \\]\n    and especially for $X = \\alpha$ we will get that $0 = 1$ that is\n    impossible. \n  \\end{proof}\n  \\label{thm:irreduciblediv}\n\\end{theorem}\n\n\\begin{theorem}[About ideal generated by irreducible polynomial]\n  Let $P \\in K\\left[X\\right]$ is a polynomial and $I = \\left(P\\right)$ is\n  an \\mynameref{def:ideal} generated by the polynomial. The $I$ is\n  \\mynameref{def:maxideal} if and only if $P$ is irreducible in\n  $K\\left[X\\right]$\n  \\begin{proof}\n    Let $P$ is reducible i.e. $P = G F$. In the case $(P) \\subset (G)$\n    and $(P) \\subset (F)$ i.e. by definition it is not a maximal\n    ideal.\n\n    If $P$ is irreducible then $K\\left[X\\right]/(P)$ is a field (see\n     claim \\ref{claim:lec1_sec14})\n    and by theorem \\ref{thm:maxideal} $(P)$\n    is a maximal ideal.\n  \\end{proof}\n  \\label{thm:irreducibleideal}\n\\end{theorem}\n\n\\subsection{Fields}\n\n\\begin{definition}[Field]\n  The ring $\\left(R, \\oplus, \\odot\\right)$ is called as a field if\n  $\\left(R \\setminus \\{0\\}, \\odot\\right)$ is an \\mynameref{def:abeliangroup}.\n\n  The inverse element to $a$ in\n  $\\left(R \\setminus\\{0\\}, \\odot\\right)$ is denoted as $a^{-1}$\n  \\label{def:field}\n\\end{definition}\n\n\\begin{example}[Field $\\mathbb{Q}$]\n  Note that $\\mathbb{Z}$ is not a field because not for every integer\n  number an inverse exists. But if we consider a set of fractions\n  $\\mathbb{Q} = \\left\\{a/b \\mid a \\in \\mathbb{Z}, b \\in\n  \\mathbb{Z}\\setminus\\{0\\}\\right\\}$ when it will be a field.\n\n  The\n  inverse element to $a/b$  in\n  $\\left(\\mathbb{Q}\\setminus\\{0\\}, \\cdot\\right)$  will be $b/a$.\n  \\label{ex:field}\n\\end{example}\n\n\\begin{definition}[Unique factorization domain]\n   Unique factorization domain (UFD) is a commutative ring, which is\n   an \\mynameref{def:integraldomain}, and in which every non-zero non-unit element\n   can be written as a product of prime elements (or irreducible\n   elements), uniquely up to order and units, analogous to the\n   fundamental theorem of arithmetic for the integers. \n  \\label{def:ufd}\n\\end{definition}\n\n\\begin{theorem}[About Quotient Ring and Maximal Ideal]\n  Let $\\left(R, +, \\cdot\\right)$ is a commutative \\mynameref{def:ring}\n  with additive identity $0_R$ and multiplicative identity $1_R$. Let\n  $I$ be an \\mynameref{def:ideal} of $R$ then $I$ is\n  \\mynameref{def:maxideal} if and only if \\mynameref{def:quotientring}\n  $R/I$ is a \\mynameref{def:field}\n  \\label{thm:maxideal}\n  \\begin{proof}\n    See the end of section \\ref{sec:lec2_ideals}.\n  \\end{proof}\n\\end{theorem}\n\n\\begin{definition}[Fraction field]\n  The field of fractions of an integral domain is the smallest field\n  in which it can be embedded. The elements of the field of fractions\n  of the integral domain $R$ are equivalence classes\n  (see the construction below) written as $\\frac{a}{b}$ with $a, b \\in\n  R$ and $b\\neq 0$. The field of\n  fractions of $R$ is sometimes denoted by\n  $\\mathrm{Quot} (R)$ or $\\mathrm {Frac}(R)$ \\cite{wiki:fractionfield}. \n  \\label{def:fractionfield}\n\\end{definition}\n\n\\subsection{Characters}\n\n\\begin{definition}[Character]\n  For an abelian group $G$, finite or infinite, a character of $G$ is\n  a group homomorphism $\\phi: G \\to F^\\times$ where $F$ is a field.\n\n  The definition was taken from \\cite{bib:KeithConradLinearchar}\n  \\label{def:character}\n\\end{definition}\n\n\\begin{example}[Character]\n  A field homomorphism $K \\to F$ is a character by restricting it to the\n  non- zero elements of $K$ (that is, using $G = K^\\times$) and ignoring the\n  additive aspect of a field homomorphism.  \n\n  The example was taken from \\cite{bib:KeithConradLinearchar}\n  \\label{ex:character}\n\\end{example}\n\n\\begin{theorem}[Dedekind]\n  If we have $n$ distinct \\mynameref{def:character}s $\\phi_1, \\dots,\n  \\phi_n: G \\to F^\\times$ then they are linearly independent i.e. if\n  $c_1, \\dots, c_n \\in F$ satisfy\n  \\[\n  c_1 \\phi_1(g) + \\dots + c_n \\phi_n(g) = 0\n  \\]\n  for all $g \\in G$ then $c_1 = \\dots = c_n = 0$\n  (see also \\cite{bib:KeithConradLinearchar}).\n  \\label{thm:dedekind}\n\\end{theorem}\n\n\\section{Modules and Vector spaces}\n\n\\subsection{Modules}\n\nA module over a ring is a generalization of the notion of vector space\nover a field, wherein the corresponding scalars are the elements of an\narbitrary given ring (with identity) and a multiplication (on the left\nand/or on the right) is defined between elements of the ring and\nelements of the module.\n\n\\begin{definition}[Module]\n  \\label{def:module}\n  Let $R$ is a \\mynameref{def:ring} and $1_R$ is it's multiplicative\n  identity. A left R-module $M$ consists of an \\mynameref{def:abeliangroup}\n  $\\left(M, +\\right)$ and an operation $\\cdot: R \\times M \\to M$ such\n  that $\\forall r,s \\in R$ and $\\forall x,y \\in M$ the following\n  relations are hold:\n  \\begin{enumerate}\n  \\item $r \\cdot \\left(x+y\\right) = r \\cdot x + r \\cdot y$\n  \\item $\\left(r + s \\right) \\cdot x = r \\cdot x + s \\cdot x$\n  \\item $\\left(rs\\right) \\cdot x = r \\cdot \\left(s \\cdot x\\right)$\n  \\item $1_R \\cdot x = x$\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{example}[Module]\n  If $K$ is a \\mynameref{def:field} then concepts of\n  K-\\mynameref{def:vectorspace} and $K$-module are the same\n\\end{example}\n\n\\begin{definition}[Generating set of a module]\n  A generating set $G$ of a module $M$ over a ring $R$ is a subset of\n  $M$ such that the smallest submodule of $M$ containing $G$ is $M$\n  itself \\cite{wiki:gsmodule}\n  \\label{def:gsmodule}\n\\end{definition}\n\n\\begin{definition}[Free module]\n  \\label{def:freemodule}\n  The \\mynameref{def:module} that has a basis (i.e. linearly independent\n  generating set) \n  is called as free module \\cite{wiki:freemodule}.\n\n  For a $R$-module $M$ the set $E \\subseteq M$ is a basic for $M$ if\n  \\begin{enumerate}\n  \\item $E$ is a generating set (see definition \\ref{def:gsmodule})\n    for $M$ i.e. $\\forall m \\in M$ \n    $\\exists n < \\infty$: $\\exists e_i \\in E, r_i \\in R$:\n    $m = \\sum_{i = 1}^n r_i e_i$\n  \\item $E$ is linearly independent, i.e. if $r_1 e_1 + \\dots + r_n\n    e_n = 0_M$ for distinct elements $e_1, \\dots, e_n \\in E$ then\n    $r_1 = \\dots = r_n = 0_R$.\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{definition}[Rank of free module]\n  The cardinality of any (and therefore every) basis is called the\n  rank of the free module $M$ \\cite{wiki:freemodule}.\n  \\label{def:rankfreemodule}\n\\end{definition}\n\n\\begin{definition}[Direct sum of modules]\n  In abstract algebra, the direct sum is a construction which combines\n  several modules into a new, larger module. The direct sum of modules\n  is the smallest module which contains the given modules as\n  submodules with no \"unnecessary\" constraints, making it an example\n  of a coproduct. Contrast with the direct product, which is the dual\n  notion \\cite{wiki:directsummodules}.\n  \\label{def:directsummodules}\n\\end{definition}\n\n\\begin{example}[Direct sum of modules]\n  If we have 2 \\mynameref{def:freemodule}s $M$ and $N$ with bases $m_1,\n  m_2, \\dots, m_m$ and $n_1, n_2, \\dots, n_n$. Then the\n  \\mynameref{def:directsummodules} $A = M \\oplus N$ will also be a free\n  module with composite basis: $m_1, m_2, \\dots, m_m, n_1, n_2, \\dots, n_n$\n  \\label{ex:directsummodules}\n\\end{example}\n\n\\begin{definition}[Finitely generated module]\n  Finitely generated module is a module that has a finite generating\n  set (see also definition \\ref{def:gsmodule}) \\cite{wiki:fgmodule}.\n  \\label{def:fgmodule}\n\\end{definition}\n\n\\begin{definition}[Cyclic module]\n  A (left) $R$-\\mynameref{def:module} $M$ is called cyclic if $M$ can be\n  generated by \n  a single element i.e.\n  \\[\n  M = \\left<x\\right>=R x = \\left\\{rx \\mid r \\in R\\right\\}\n  \\]\n  for some $x \\in M$ \\cite{wiki:cyclicmodule}.\n  \\label{def:cyclicmodule}\n\\end{definition}\n\n\\begin{claim}\n  $M$ is a cyclic $R$ module if and only if exists left ideal $I\n  \\subset R$ such that $M \\cong R/I$\n  \\begin{proof}\n    See \\cite{mathstackexchange:cyclicmodule}. Note that\n    \\cite{bib:lang} p. 149 has\n    the claim as a definition of the \\mynameref{def:cyclicmodule}.\n  \\end{proof}\n  \\label{claim:cyclicmodule}\n\\end{claim}\n\n\\subsection{Linear algebra}\n\n\\begin{definition}[Vector space]\n  \\label{def:vectorspace}\n  Let $F$ is a \\mynameref{def:field}. The set $V$ is called as vector\n  space under $F$ if the following conditions are satisfied\n  \\begin{enumerate}\n  \\item We have a binary operation $V \\times V \\rightarrow V$\n    (addition): $(x,y) \\rightarrow x + y$ with the following\n    properties:\n    \\begin{enumerate}\n    \\item $x + y = y + x$\n    \\item $(x + y) + z = x + ( y + z )$\n    \\item $\\exists 0 \\in V$ such that $\\forall x \\in V: x + 0 = x$\n    \\item $\\forall x \\in V \\exists -x \\in V$ such that $x + (-x) = x -\n      x = 0$ \n    \\end{enumerate}    \n  \\item We have a binary operation $F \\times V \\rightarrow V$ (scalar\n    multiplication) with the following properties\n    \\begin{enumerate}\n    \\item $1_F \\cdot x = x$\n    \\item $\\forall a,b \\in F, x \\in V$: $a\\cdot\\left(b \\cdot x\\right)\n      = \\left(a b\\right) \\cdot x$.\n    \\item $\\forall a,b \\in F, x \\in V$:\n      $(a+b)\\cdot x = a \\cdot x + b \\cdot x$\n    \\item $\\forall a \\in F, x, y \\in V$:\n      $a\\cdot(x+y) = a\\cdot x + a \\cdot y$\n    \\end{enumerate}        \n  \\end{enumerate}\n\\end{definition}\n\n\\begin{lemma}[About vector space isomorphism]\n  2 vector spaces $L$ and $M$ with same dimension $dim L = dim M$ then\n  there exists an \\mynameref{def:isomorphism} between them\n  \\label{lem:vsisomorphism}\n\\end{lemma}\n\n\\begin{definition}[Image]\n  The image or range of a linear map $f: V \\to W$ is the following\n  set \\cite{wiki:linearmap}:\n  \\[\n  \\Ima f = \\left\\{\n  w \\in W: w = f(v), v \\in V\n  \\right\\}\n  \\]\n  \\label{def:image}\n\\end{definition}\n\n\\begin{definition}[Kernel]\n  The kernel of a linear map $f: V \\to W$ is the following\n  set \\cite{wiki:kernel}:\n  \\[\n  \\ker f = \\left\\{\n  v \\in V: f(v) = 0\n  \\right\\}\n  \\]\n  \\label{def:kernel}\n\\end{definition}\n\n\n\\begin{definition}[Rank]\n  The rank of a linear map $f: V \\to W$ is dimension of\n  \\mynameref{def:image}: $rg f = \\dim \\Ima f$ \\cite{wiki:rank}:\n  \\label{def:rank}\n\\end{definition}\n\n\\begin{definition}[Nullity]\n  The nullity of a linear map $f: V \\to W$ is dimension of\n  \\mynameref{def:kernel}: $nul f = \\dim \\ker f$ \\cite{wiki:kernel}:\n  \\label{def:nullity}\n\\end{definition}\n\n\\begin{theorem}[Rank–nullity theorem]\n  Let $V$ and $W$ be vector spaces over some field and let $T: V \\to\n  W$ be a linear map. Then the \\mynameref{def:rank} of $T$ is the\n  dimension of the image of $T$ and the \\mynameref{def:nullity} of $T$\n  is the dimension of the kernel of $T$, so we have\n  \\[\n  \\dim\\left(\\Ima T\\right) + \\dim\\left(\\ker T\\right) = \\dim V\n  \\]\n  or, equivalently\n  \\[\n  rg(T) + nul(T) = \\dim(V)\n  \\]\n  \\label{thm:ranknullity}\n  \\begin{proof}\n    See \\cite{wiki:ranknullity}\n  \\end{proof}\n\\end{theorem}\n\n\\begin{definition}[General linear group of a vector space]\n  If $V$ is a \\mynameref{def:vectorspace} over field $K$  the general\n  linear group of $V$, written $GL\\left(V\\right)$ or\n  $Aut\\left(V\\right)$, is the group of all automorphisms of $V$,\n  i.e. the set of all bijective linear transformations $V \\to V$,\n  together with functional composition as group operation \\cite{wiki:glg}.  \n  \\label{def:glv}\n\\end{definition}\n\n\\begin{definition}[Dual space]\n  Given any vector space $V$ over a field $F$, the dual space $V^\\ast$\n  is defined as the set of all linear maps $\\phi: V \\to F$ (linear\n  functionals). The dual space $V^\\ast$ itself becomes a vector space\n  over $F$ when equipped with an addition and scalar multiplication\n  satisfying: \n  \\begin{eqnarray}\n    (\\varphi +\\psi )(x)=\\varphi (x)+\\psi (x)\n    \\nonumber \\\\\n    (a\\varphi )(x)=a\\left(\\varphi (x)\\right)\n    \\nonumber\n  \\end{eqnarray}\n  for all $\\phi, \\psi \\in V^\\ast$, $x \\in V$, and $a \\in F$.\n\n  This is also named as algebraic dual space at \\cite{wiki:dualspace}.\n  \\label{def:dualspace}\n\\end{definition}\n\n\\begin{definition}[Dual basis]\n  If $\\{e_i\\}$ is a basis of $V$ then exists a basis $\\{v_j\\}$ of\n  \\mynameref{def:dualspace} such that $v_j(e_i) = \\delta_{ij}$ and is\n  called as dual basis. \n  \\cite{wiki:dualbasis}\n  \\label{def:dualbasis}\n\\end{definition}\n\n\\begin{definition}[Degenerate bilinear form]\n  A degenerate bilinear form $f(x, y)$ on a vector space $V$ is a\n  bilinear form such that the map from $V$ to $V^\\ast$ (the\n  \\mynameref{def:dualspace} \n  of $V$) given by $v \\to (x \\to f(x, v) )$ is not an isomorphism\n  \\cite{wiki:dbf}. \n\n  An equivalent definition when $V$ is finite-dimensional is that it\n  has a non-trivial kernel: there exist some non-zero $x \\in V$ such\n  that \n  \\(\n  \\forall y \\in V f(x,y) = 0\n  \\)\n  \\label{def:degeneratebf}\n\\end{definition}\n\n\\begin{definition}[Non-degenerate bilinear form]\n  A nondegenerate or nonsingular form is one that is not degenerate,\n  meaning that the map from $V$ to $V^\\ast$ (the \\mynameref{def:dualspace}\n  of $V$) given by $v \\to (x \\to f(x, v) )$ is an isomorphism\n  \\cite{wiki:dbf} or equivalently when $V$ is finite-dimensional if\n  and only if\n  \\(\n  \\forall y \\in V f(x,y) = 0\n  \\)\n  implies $x = 0$, i.e. the map $f$ has a trivial kernel.\n  \\label{def:nondegeneratebf}\n\\end{definition}\n\n\\begin{definition}[Eigenspace]\n  Consider a linear map $T: V \\to V$.\n  The set of all eigenvectors of $T$ corresponding to the same\n  eigenvalue, together with the zero vector, is called an eigenspace\n  or characteristic space of $T$ \\cite{wiki:eigenvalues}\n  \\label{def:eigenspace}\n\\end{definition}\n\n\\begin{definition}[Diagonalizable map]\n  If $V$ is a finite-dimensional vector space, then a linear map\n  $T: V \\to V$ is called diagonalizable if there exists an ordered\n  basis of $V$ with respect to which $T$ is represented by a diagonal\n  matrix.\n\n  A linear map $T: V \\to V$ is diagonalizable if and only if the sum\n  of the dimensions of its \n  eigenspaces is equal to $n = dim(V)$, which is the case if and only if\n  there exists a basis of $V$ consisting of eigenvectors of $T$. With\n  respect to such a basis, $T$ will be represented by a diagonal\n  matrix. The diagonal entries of this matrix are the eigenvalues of\n  $T$ \\cite{wiki:diagonalizable_matrix}.\n  \\label{def:diagonalizable_map}\n\\end{definition}\n\n\\begin{theorem}[About eigenvalues of a diagonalizable linear map]\n  A linear map $T: V \\to V$ with $n = dim(V)$ is diagonalizable if it\n  has $n$ distinct eigenvalues \\cite{wiki:diagonalizable_matrix}.\n  \\label{thm:diagonalizable_map_eigenvalues}\n\\end{theorem}\n\n\\begin{theorem}[About invertible matrix]\n  Let $A$ be a matrix over $F$. If $A$ is diagonalizable, then so is\n  any power of it. Conversely, if $A$ is invertible, $F$ is\n  algebraically closed, and $A^n$ is diagonalizable for some $n$ that\n  is not an integer multiple of the characteristic of $F$, then $A$ is\n  diagonalizable.\n  \\begin{proof}\n    See \\cite{wiki:diagonalizable_matrix}\n  \\end{proof}\n  \\label{thm:diagonalizable_matrix}\n\\end{theorem}\n\n\n\n\\section{Functions aka maps}\n\n\\subsection{Functions}\n\n\\begin{definition}[Surjection]\n  The function $f: X \\rightarrow Y$ is surjective (or onto) if\n  $\\forall y \\in Y$, $\\exists x \\in X$ such that\n  $f\\left(x\\right) = y$.\n  \\label{def:surjection}\n\\end{definition}\n\n\\begin{definition}[Injection]\n  The function $f: X \\rightarrow Y$ is injective (or one-to-one function) if\n  $\\forall x_1, x_2 \\in X$, such that $x_1 \\ne x_2$ then\n  $f\\left(x_1\\right) \\ne f\\left(x_2\\right)$.\n  \\label{def:injection}\n\\end{definition}\n\n\\begin{definition}[Bijection]\n  The function $f: X \\rightarrow Y$ is bijective (or one-to-one\n  correspondence) if it is an \\mynameref{def:injection} and a\n  \\mynameref{def:surjection}. \n  \\label{def:bijection}\n\\end{definition}\n\n\\begin{definition}[Homomorphism]\n  The homomorphism is a function (map) between two sets that preserves\n  its algebraic structure. For the case of groups\n  $\\left(X, \\circ\\right)$ and $\\left(Y, \\odot\\right)$ the function\n  $\\phi: X \\rightarrow Y$ is called homomorphism if\n  $\\forall x_1, x_2 \\in X$ it holds\n  $\\phi\\left(x_1 \\circ x_2\\right) = \\phi\\left(x_1 \\right) \\odot\n  \\phi\\left( x_2\\right)$. \n  \\label{def:homomorphism}\n\\end{definition}\n\n\\begin{definition}[Field homomorphism]\n  Let \\cite{proofwiki:fieldhomomorphism} $\\left(F, +, \\times\\right)$\n  and $\\left(K, \\oplus, \\otimes\\right)$ are \n  \\mynameref{def:field}s. Let $\\phi: F \\rightarrow K$ is a mapping\n  such that both\n  $\\left(F, +\\right) \\rightarrow \\left(K, \\oplus\\right)$\n  and\n  $\\left(F, \\times\\right) \\rightarrow \\left(K, \\otimes\\right)$\n  are \\mynameref{def:homomorphism}s under $\\phi$.\n\n  That is $\\forall a, b \\in F$:\n  \\begin{enumerate}\n  \\item $\\phi\\left(a + b\\right) = \\phi\\left(a\\right) \\oplus \\phi\\left(b\\right)$\n  \\item $\\phi\\left(a \\times b\\right) = \\phi\\left(a\\right) \\otimes \\phi\\left(b\\right)$\n  \\end{enumerate}\n\n  Then $\\phi: \\left(F, +, \\times\\right) \\rightarrow \\left(K, \\oplus,\n  \\otimes\\right)$ is a field homomorphism.\n  \\label{def:fieldhomomorphism}\n\n  Note that in the lectures we often refer the Field homomorphism as\n  just \\mynameref{def:homomorphism}.\n\\end{definition}\n\n\n\\begin{definition}[Isomorphism]\n  If a map is \\mynameref{def:bijection} as well as\n  \\mynameref{def:homomorphism} when it is called as isomorphism.\n\n  We use the following symbolic notation for isomorphism between $X$\n  and $Y$: $X \\cong Y$.\n  \\label{def:isomorphism}\n\\end{definition}\n\n\\begin{definition}[Endomorphism]\n   An endomorphism is a morphism (or homomorphism) from a mathematical\n   object to itself \\cite{wiki:endomorphism}\n   \\label{def:endomorphism}\n\\end{definition}\n\n\\begin{definition}[Automorphism]\n  Automorphism is an isomorphism from a mathematical object to itself.\n  \\label{def:automorphism}\n\\end{definition}\n\n\\begin{definition}[Embedding]\n  When some object X is said to be embedded in another object $Y$, the\n  embedding is given by some injective and structure-preserving map\n  $f : X \\to Y$. The precise meaning of \"structure-preserving\" depends on\n  the kind of mathematical structure of which $X$ and $Y$ are\n  instances.\n  \n  The fact that a map $f : X \\to Y$ is an embedding is often indicated\n  by the use of a \"hooked arrow\", thus: $f:X\\hookrightarrow Y$. On the\n  other hand, this notation is sometimes reserved for inclusion maps.\n  \\label{def:embedding}\n\\end{definition}\n\n\\begin{theorem}[First isomorphism]\n  Let $G$ is a group and $\\phi: G \\to H$ is a\n  surjective \\mynameref{def:homomorphism}. Then if $N = \\ker \\phi$ we\n  have\n  \\[\n  H \\cong G/N\n  \\]\n  \\label{thm:firstisomorphism}\n\\end{theorem}\n\n\\begin{theorem}[Isomorphism extension theorem]\n  Let $F$ is a \\mynameref{def:field} and $E$ is an\n  \\mynameref{def:algebraicextension} of $F$.\n  $F'$ is another \\mynameref{def:field} and $E'$ the \n  \\mynameref{def:algebraicextension} of $F'$.\n\n  If there exists an \\mynameref{def:isomorphism} $\\phi: F \\to F'$ then\n  it can be extended to an isomorphism $\\tau: E \\to E'$.\n\n  \\begin{proof}\n    The proof of the isomorphism extension theorem depends on\n    \\mynameref{lem:zorn}.\n\n    ??? The theorem seems to be very close to the theorem\n    \\ref{thm:lec2_3}. \n  \\end{proof}\n  \n  \\label{thm:isomorphismextension}\n\\end{theorem}\n\n\\begin{theorem}[About group homomorphism]\n  A group homomorphism is \\mynameref{def:injection} iff the kernel is\n  trivial \\cite{wiki:grouphomomorphism}\n  \\label{thm:grouphomomorphsim}\n\\end{theorem}\n\n\\subsection{Category theory}\n\n\\begin{definition}[Commutative diagram]\n  A commutative diagram is a diagram of objects (also known as\n  vertices) and morphisms (also known as arrows or edges) such that\n  all directed paths in the diagram with the same start and endpoints\n  lead to the same result by composition\n  \\label{def:commutativediagram}\n\n  The following diagram commutes if $f_{AB} = f_{CB} f_{AC}$ or\n  $f_{AB}\\left(x\\right) = f_{CB} \\left(f_{AC}\\left(x\\right)\\right)$.\n  \\begin{tikzpicture}[description/.style={fill=white,inner sep=2pt}]\n    \\matrix (m) [matrix of math nodes, row sep=3em,\n      column sep=2.5em, text height=1.5ex, text depth=0.25ex]\n            { A& & B \\\\\n              & C & \\\\ };\n            %\\draw[double,double distance=5pt] (m-1-1) – (m-1-3);\n            \\path[->]\n            (m-1-1) edge node[description] {$ f_{AB} $} (m-1-3)\n            edge node[description] {$  f_{AC} $} (m-2-2)\n            (m-2-2) edge node[description] {$  f_{CB} $} (m-1-3);\n  \\end{tikzpicture}\n\n\\end{definition}\n\n\\section{Number theory}\n\n\\begin{definition}[Euler's totient function]\n  In number theory, Euler's totient function counts the positive\n  integers up to a given integer $n$ that are relatively prime to $n$. It\n  is written using the Greek letter phi as $\\phi\\left(n\\right)$, and\n  may also be called Euler's phi function. It can be defined more formally as\n  the number of integers $k$ in the range $1 \\le k \\le n$ for which the\n  greatest common divisor $gcd\\left(n, k\\right)$ = 1. The integers $k$ of this\n  form are sometimes referred to as totatives of $n$.\n\n  The definition was taken from \\cite{wiki:eulerfunction}\n  \\label{def:eulerfuction}\n\\end{definition}\n\n\\begin{example}[Euler's totient function]\n  For example \\cite{wiki:eulerfunction}, the totatives of $n = 9$ are\n  the six numbers 1, 2, 4, 5, \n  7 and 8. They are all relatively prime to 9, but the other three\n  numbers in this range, 3, 6, and 9 are not, because\n  $gcd\\left(9, 3\\right)$ =\n  $gcd\\left(9, 6\\right) = 3$ and $gcd\\left(9, 9\\right) = 9$.\n  Therefore, $\\phi\\left(9\\right) = 6$. As another\n  example, $\\phi\\left(1\\right) = 1$ since for $n = 1$ the only integer in the range from\n  1 to n is 1 itself, and $gcd\\left(1, 1\\right) = 1$. \n\\end{example}\n\n\\end{appendices}\n", "meta": {"hexsha": "06c8db8226ac95a855b4e384c5de25f85f518e8c", "size": 65021, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "requirements.tex", "max_stars_repo_name": "JiuziLau/courseragalois", "max_stars_repo_head_hexsha": "06423d7609caf8e083fe4c5a442ec01ea27018ef", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2016-06-21T07:34:33.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-23T00:14:44.000Z", "max_issues_repo_path": "requirements.tex", "max_issues_repo_name": "JiuziLau/courseragalois", "max_issues_repo_head_hexsha": "06423d7609caf8e083fe4c5a442ec01ea27018ef", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-06-28T21:26:22.000Z", "max_issues_repo_issues_event_max_datetime": "2016-06-30T05:36:37.000Z", "max_forks_repo_path": "requirements.tex", "max_forks_repo_name": "JiuziLau/courseragalois", "max_forks_repo_head_hexsha": "06423d7609caf8e083fe4c5a442ec01ea27018ef", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-08-08T07:47:20.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-25T06:16:07.000Z", "avg_line_length": 32.8057517659, "max_line_length": 112, "alphanum_fraction": 0.6628935267, "num_tokens": 22593, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.8519527982093668, "lm_q1q2_score": 0.7004663341173969}}
{"text": "\\section{Topology of Level Sets}\n\nLet $P$ be a probability measure on a product space $\\mathcal{X} \\times \\mathcal{Y}$, \nwhere we assume $\\mathcal{X}$ and $\\mathcal{Y}$ are Euclidean vector spaces for simplicity.\nLet $\\{ (x_i, y_i)\\}_i$ be an iid sample of size $L$ drawn from $P$ defining the training set.\nWe consider the classic empirical risk minimization of the form\n\\begin{equation}\n\\label{emp_risk_min}\n\\Fem(\\theta) = \\frac{1}{L} \\sum_{l=1}^L \\| \\Phi(x_i;\\theta) - y_i \\|^2 + \\kappa \\mathcal{R}(\\theta)~,\n\\end{equation}\nwhere $\\Phi(x ; \\theta)$ encapsulates the feature representation \nthat uses parameters $\\theta \\in \\R^S$ and $\\mathcal{R}(\\theta)$ is a regularization term. \n In a deep neural network, $\\theta$\ncontains the weights and biases used in all layers.\nFor convenience, in our analysis we will also use the oracle risk minimization:\n\\begin{equation}\n\\label{risk_min}\n\\Forr(\\theta) = \\E_{(X,Y) \\sim P} \\| \\Phi(X;\\theta) - Y \\|^2 + \\kappa \\mathcal{R}(\\theta)~.\n\\end{equation}\nOur setup considers the case where $\\mathcal{R}$ \nconsists on either $\\ell_1$ or $\\ell_2$ norms, as we shall describe below.\nThey correspond to well-known sparse and ridge regularization respectively.\n%\n% on all layers: $\\mathcal{R}(\\theta) = \\| \\theta \\|_1$, \n%which provides a sparse regularization prior, and the Ridge regression case  \n%$\\mathcal{R}(\\theta) = \\| \\theta\\|_2^2$ (also referred as weight decay). \n\n\\subsection{Poor local minima characterization from topological connectedness}\n\nWe define the level set of $F(\\theta)$ as \n\\begin{equation}\n\\Omega_F(\\lambda) = \\{ \\theta \\in \\R^S~;~F(\\theta) \\leq \\lambda \\}~. \n\\end{equation}\n\nThe first question we study is the structure of critical points of $\\Fem(\\theta)$ and $\\Forr(\\theta)$\nwhen $\\Phi$ is a multilayer neural network. \nFor simplicity, we consider first a strict notion of local minima: \n$\\theta \\in \\R^S $ is a strict local minima of $F$ if there is $\\epsilon>0$ with $F(\\theta') > F(\\theta)$ for all $\\theta' \\in B(\\theta,\\epsilon)$ and $\\theta'\\neq \\theta$.\n%$\\theta \\in \\R^N $ is a local minima of $F \\in C^\\infty(\\R^N,\\R)$ if for any differentiable curve $\\gamma: (-\\epsilon, \\epsilon) \\to \\R^N$ passing through $\\theta$ at $t=0$, there exists $K>1$ even such that the function $g(t) = F(\\gamma(t))$ satisfies $g^{(k)}(0) = 0 $ for all $k < K$ and\n%$g^{(K)}(0) > 0$.  \nIn particular, we are interested to know whether\n$\\Fem$ has local minima which are not global minima. \n %\\footnote{this implies $\\nabla F(\\theta) =0$ and $H F(\\theta) \\succeq 0$ but avoids degenerate cases where $F$ is constant along low\nThis question is answered by \nknowing whether $\\Omega_F(\\lambda)$ is connected at each energy level $\\lambda$:\n\n\\begin{proposition}\n\\label{connectedminima}\nIf $\\Omega_F(\\lambda)$ is connected for all $\\lambda$ then every local minima of $F(\\theta)$ is a global minima. \n\\end{proposition}\n\nStrict local minima implies that $\\nabla F(\\theta) =0$ and $H F(\\theta) \\succeq 0$, but avoids degenerate cases where $F$ is constant along a manifold intersecting $\\theta$. In that scenario, if $\\mathcal{U}_\\theta$ denotes that manifold, our reasoning immediately \nimplies that if $\\Omega_F(\\lambda)$ are connected, then for all $\\epsilon > 0$ there exists $\\theta'$ with $\\text{dist}(\\theta',\\mathcal{U}_\\theta) \\leq \\epsilon$ and $F(\\theta') < F(\\theta)$. In other words, some element at the boundary of $\\mathcal{U}_\\theta$ must be a saddle point. \nA stronger property that eliminates the risk of gradient descent getting stuck at $\\mathcal{U}_\\theta$ is \n  that \\emph{all} elements at the boundary of $\\mathcal{U}_\\theta$ are saddle points. This can be guaranteed if one can show that \n  there exists a path connecting any $\\theta$ to the lowest energy level such that $F$ is strictly decreasing along it. \n\nSuch degenerate cases arise in deep linear networks in absence of regularization. If $\\theta = (W_1, \\dots, W_K)$ denotes any parameter value, with $N_1, \\dots N_K$ denoting the hidden layer sizes, and $F_k \\in \\mathbf{GL}_{N_k}^{+}(\\R)$ are arbitrary elements of the general linear group of invertible $N_k \\times N_k$ matrices with positive determinant, then   \n$$\\mathcal{U}_\\theta = \\{ W_1 F_1^{-1}, F_1 W_2 F_2^{-1}, \\dots, F_K W_K  ~;~ F_k \\in \\mathbf{GL}_{N_k}^{+}(\\R) \\}~. $$\nIn particular, $\\mathcal{U}_\\theta$ has a Lie Group structure. In the half-rectified nonlinear case, the general linear group is replaced by the Lie group of homogeneous invertible matrices $F_k = \\text{diag}(\\alpha_1, \\dots, \\alpha_{N_k})$ with $\\alpha_j > 0$. \n\nThis proposition shows that a sufficient condition to prevent the existence of poor local minima is having connected level sets, but this condition is not necessary: one can have isolated local minima lying \nat the same energy level. This can be the case in systems that are defined up to \na discrete symmetry group, such as multilayer neural networks. However, as we shall see next, this case puts the system in a brittle position, since one needs to be able to account for all the local minima (and there can be exponentially many of them as the parameter dimensionality increases) and verify that their energy is indeed equal. \n\n\\subsection{The Linear Case}\n\nWe first consider the \nparticularly simple case where \n$F$ is a multilayer network defined by\n\\begin{equation}\n\\label{linearcase}\n\\Phi(x;\\theta) = W_K \\dots W_1 x~,~\\theta = (W_1, \\dots, W_K)~.\n\\end{equation}\nand the ridge regression $\\mathcal{R}(\\theta) =\\| \\theta \\|^2$. This model defines a non-convex (and non-concave) loss $\\Fem(\\theta)$.\nWhen $\\kappa = 0$, it has been shown in \\cite{saxe2013exact} and \\cite{kawaguchi2016deep} that in this case, \nevery local minima is a global minima.  \nWe provide here an alternative proof of that result that uses\na somewhat simpler argument and allows for $\\kappa > 0$ in the case $K=2$.\n\n%For that purpose, let $W_1, W_2, \\dots, W_K$ be weight matrices of sizes \n%$n_k \\times n_{k+1}$, $k < K$. Assume first that $n_j \\geq \\min(n_1, n_K)$ for $j=2 \\dots K-1$.\n%and let us define the following multilinear regression problem:\n%\\begin{equation}\n%\\label{multilinloss}\n%L_0(W_1, \\dots, W_K) = \\sum_i \\| W_K, \\dots W_1 x_i - y_i \\|^2~,\n%\\end{equation}\n%where $\\{ (x_i, y_i)\\,; x_i \\in \\mathbb{R}^{n_1}, y_i \\in \\mathbb{R}^{n_K} \\}_i$ is a given \n%training set. \n\n\\begin{proposition}\n\\label{proplinear}\nLet $W_1, W_2, \\dots, W_K$ be weight matrices of sizes \n$n_k \\times n_{k+1}$, $k < K$, and let $\\Fem(\\theta)$, $\\Forr(\\theta)$ \ndenote the risk minimizations using $\\Phi$ as in (\\ref{linearcase}). %and ridge regression.\nAssume that $n_j > \\min(n_1, n_K)$ for $j=2 \\dots K-1$.\nThen $\\Omega_{\\Fem}(\\lambda)$ (and $\\Omega_{\\Forr}$) is connected for all $\\lambda$ and all $K$ when $\\kappa=0$, and for $\\kappa>0$ when $K=2$; and therefore there are no poor local minima in these cases. \nMoreover, any $\\theta$ can be connected to the lowest energy level with a strictly decreasing path. %when $\\kappa=0$.\n\\end{proposition}\n\n%Let us highlight that this result is weaker than that obtained by \\cite{kawaguchi2016deep}, since it does not \n%control the behavior of non-strict local minima and does not inform about the strict saddle condition. \nLet us highlight that this result is slightly complementary than that of \\cite{kawaguchi2016deep}, Theorem 2.3.\nWhereas we require $n_j > \\min(n_1, n_K)$ for $j=2 \\dots K-1$ and our analysis does not inform about the order of the saddle points, \nwe do not need full rank assumptions on $\\Sigma_X$ nor the weights $W_k$. %We leave the consolidation of these results for future work\n\nThis result does also highlight a certain mismatch between the picture of having no poor local minima \nand generalization error. Incorporating regularization drastically changes the topology, and the \nfact that we are able to show connectedness only in the two-layer case with ridge regression is profound; we conjecture that extending it to deeper models requires a different regularization, perhaps using more general atomic norms \\cite{bach2013convex}. But we now move our interest to the nonlinear case, which is more relevant to our purposes. \n\n\\subsection{Half-Rectified Nonlinear Case}\n\nWe now study the setting given by \n\\begin{equation}\n\\label{relucase}\n\\Phi(x;\\theta) = W_K \\rho W_{K-1} \\rho \\dots \\rho W_1 x~,~\\theta = (W_1, \\dots, W_K)~,\n\\end{equation}\nwhere $\\rho(z) = \\max(0 ,z)$. \nThe biases can be implemented by replacing the input vector $x$ \nwith $\\overline{x}=(x, 1)$ and by rebranding each parameter matrix as \n$$\\overline{W}_i = \\left( \n\\begin{array}{c|c}\nW_i & b_i \\\\\n\\hline \n0 & 1 \n\\end{array}\n\\right)~,$$\nwhere $b_i$ contains the biases for each layer.\t\nFor simplicity, we continue to use $W_i$ and $x$ in the following.\n\n\\subsubsection{Nonlinear models are generally disconnected}\n\\label{disconnect}\n\nOne may wonder whether the same phenomena of global connectedness also holds \nin the half-rectified case. A simple motivating counterexample shows that this is not the case in \ngeneral. Consider a simple setup with $X \\in \\R^2$ drawn from a mixture of two Gaussians $\\mathcal{N}_{-1}$ \nand $\\mathcal{N}_{1}$, and let $Y = (X-\\mu_Z) \\cdot Z $ , where $Z$ is the (hidden) mixture component taking $\\{1,-1\\}$ values.  Let \n$\\hat{Y} = \\Phi(X; \\{ W_1, W_2\\} )$ be a single-hidden layer ReLU network, with two hidden units. \n%Since the model is homogeneous, one can think about $W_1$ as encoding two unitary vectors without loss of generality. \nLet $\\theta^A$ be a configuration that bisects the two mixture components, \nand let $\\theta^B$ the same configuration, but swapping the bisectrices. \nOne can verify that they can both achieve arbitrarily small risk by letting the covariance of the mixture components go to $0$. \nHowever, any path that connects $\\theta^A$ to $\\theta^B$ \nmust necessarily pass through a point in which $W_1$ has rank $1$, which leads to an estimator with risk at least $1/2$.  \n\nIn fact, it is easy to see that this counter-example can be extended to any generic half-rectified architecture, if one is \nallowed to adversarially design a data distribution. For any given $\\Phi(X; \\theta)$ with arbitrary architecture and current parameters \n$\\theta = (W_i)$, let $\\mathcal{P}_\\theta=\\{ \\mathcal{A}_1, \\dots, \\mathcal{A}_S\\}$ be the underlying tessellation of the input space given by our current choice of parameters; that is, $\\Phi(X; \\theta)$ is piece-wise linear and $\\mathcal{P}_\\theta$ contains those pieces. Now let \n$X$ be any arbitrary distribution with density $p(x) > 0$ for all $x \\in \\R^n$, for example a Gaussian, and let %$Y ~|~ \\{X \\in \\mathcal{A}_s\\} = s$. \n%It is the indicator function corresponding to the tesselation $\\mathcal{P}$. \n$Y ~|~X ~\\stackrel{d}{=} \\Phi(X ; \\theta)$~. Since $\\Phi$ is invariant under a subgroup of permutations $\\theta_\\sigma$ of its hidden layers, it is easy to see that one can find two parameter values $\\theta_A = \\theta$ and $\\theta_B = \\theta_\\sigma$ such that $\\Forr(\\theta_A) = \\Forr(\\theta_B) = 0$, but any continuous path $\\gamma(t)$ from $\\theta_A$ to $\\theta_B$ will have a different tessellation and therefore won't satisfy $\\Forr( \\gamma(t) ) = 0$. \nMoreover, one can build on this counter-example to show that not only the level sets are disconnected, but also that there exist poor local minima. Let $\\theta'$ be a different set of parameters, and $Y' ~|~X \\stackrel{d}{=} \\Phi(X; \\theta')$ be a different target distribution. Now consider the data distribution given by the mixture\n$$X ~|~p(x) ~~,~z \\sim \\text{Bernoulli}(\\pi)~,~Y ~|~X,z \\stackrel{d}{=} z \\Phi(X;\\theta) + (1-z) \\Phi(X; \\theta')~.$$\nBy adjusting the mixture component $\\pi$ we can clearly change the risk at $\\theta$ and $\\theta'$ and make them different, but we conjecture that this preserves the status of local minima of $\\theta$ and $\\theta'$. Appendix \\ref{sec:disconnect} constructs a counter-example numerically.\n \nThis illustrates an intrinsic difficulty in the optimization landscape if one is after \\emph{universal} \nguarantees that do not depend upon the data distribution. This difficulty is non-existent in the linear case \nand not easy to exploit in mean-field approaches such as \\cite{choromanska2015loss}, \nand shows that in general \nwe should not expect to obtain connected level sets. However, \nconnectedness can be recovered if one is willing to accept a small increase \nof energy and make some assumptions on the complexity of the regression task.\n Our main result shows that the amount by which the energy is \nallowed to increase is upper bounded by a quantity that trades-off model overparametrization \nand smoothness in the data distribution.\n\nFor that purpose, we start with a characterization of the oracle loss, and for simplicity let us assume \n$Y \\in \\R$ and let us first consider the case with a single hidden layer and $\\ell_1$ regularization:\n$\\mathcal{R}(\\theta) = \\| \\theta\\|_1$.\n\n\\subsubsection{Preliminaries}\n Before proving our main result, we need to introduce  preliminary notation and results. \nWe first describe the case with a single hidden layer of size $m$. \n\nWe define\n\\begin{equation}\n\\label{bla2}\ne(m) = \\min_{W_1 \\in \\R^{m \\times n}, \\|W_1(i) \\|_2 \\leq 1, W_2 \\in \\R^m} \\E\\{ | \\Phi(X; \\theta) - Y|^2 \\} + \\kappa  \\| W_2 \\|_1~.\n\\end{equation}\nto be the oracle risk using $m$ hidden units with norm $\\leq 1$ and using sparse regression. \nIt is a well known result by Hornik and Cybenko that a single hidden layer \nis a universal approximator under very mild assumptions, i.e. $\\lim_{m \\to \\infty} e(m) = 0$.\nThis result merely states that our statistical setup is consistent, and it should not be \nsurprising to the reader familiar with classic approximation theory.\n A more interesting question is the rate at which $e(m)$ decays, which depends \non the smoothness of the joint density $(X, Y) \\sim P$ relative to the nonlinear activation \nfamily we have chosen.\n\nFor convenience, we redefine $W = W_1$ and $\\beta = W_2$ and\n $Z(W) = \\max(0, W X)$. We also write $z(w) = \\max(0, \\langle w, X \\rangle)$ where $(X, Y) \\sim P$ and $w \\in \\R^N$ is any deterministic vector.\nLet $\\Sigma_X = \\E_{P} XX^T \\in \\R^{N \\times N}$ be the covariance operator of the random input $X$. We assume $\\| \\Sigma_X \\| < \\infty$. \n\n A fundamental property that will be essential to our analysis is that, despite \nthe fact that $Z$ is nonlinear, the quantity $[ w_1, w_2 ]_Z := \\E_P \\{ z(w_1) z(w_2) \\} $ \nis locally equivalent to the linear metric $\\langle w_1, w_2 \\rangle_X = \\E_P \\{ w_1^T X X^T w_2 \\} = \\langle w_1, \\Sigma_X w_2 \\rangle$, and that the linearization error decreases with the angle between $w_1$ and $w_2$. Without loss of generality, we assume here that $\\|w_1 \\| = \\| w_2 \\| = 1$, and we write $\\| w \\|_Z^2 = \\E \\{ | z(w) |^2 \\} $.\n\\begin{proposition}\n\\label{localdistprop}\nLet $\\alpha = \\cos^{-1}( \\langle w_1, w_2 \\rangle )$ be the angle between unitary vectors $w_1$ and $w_2$ and let $w_m =  \\frac{w_1 + w_2}{\\| w_1 + w_2 \\|}$ be their unitary bisector. \nThen\n\\begin{equation}\n\\label{localdisteq}\n \\frac{1 + \\cos \\alpha}{2}  \\| w_m  \\|_Z^2 - 2 \\| \\Sigma_X \\| \\left( \\frac{1-\\cos \\alpha}{2} + \\sin^2 \\alpha \\right) \\leq [ w_1, w_2 ]_Z \\leq \\frac{1+\\cos \\alpha}{2}  \\| w_m  \\|_Z^2 ~.\n\\end{equation}\n\\end{proposition} \nThe term $\\| \\Sigma_X \\| $ is overly pessimistic: we can replace it by the energy of $X$ projected into the subspace spanned by $w_1$ and $w_2$ (which is bounded by $2 \\| \\Sigma_X \\|$). \nWhen $\\alpha$ is small, a Taylor expansion of the trigonometric terms reveals that \n\\begin{eqnarray*}\n\\frac{2}{3 \\| \\Sigma_X \\|} \\langle w_1, w_2 \\rangle &=& \\frac{2}{3 \\| \\Sigma_X \\|} \\cos \\alpha = \\frac{2}{3\\| \\Sigma_X \\|}(1 - \\frac{\\alpha^2}{2} + O(\\alpha^4)) \\\\ \n&\\leq& ( 1 - \\alpha^2/4)\\| w_m \\|_Z^2 - \\| \\Sigma_X \\|( \\alpha^2/4 + \\alpha^2) + O(\\alpha^4) \\\\\n&\\leq & [ w_1, w_2 ]_Z + O(\\alpha^4) ~,\n\\end{eqnarray*}\nand similarly \n$$[ w_1, w_2 ]_Z \\leq \\langle w_1, w_2 \\rangle \\| w_m \\|_Z^2 \\leq \\| \\Sigma_X\\| \\langle w_1, w_2 \\rangle~.$$\nThe local behavior of parameters $w_1, w_2$ on our regression problem is thus equivalent to that of having a linear layer, provided $w_1$ and $w_2$ are sufficiently close to each other.\nThis result can be seen as a \\emph{spoiler} of what is coming: increasing the hidden layer dimensionality $m$ will increase the chances to encounter pairs of vectors $w_1, w_2$ with small angle; and with it some hope of approximating the previous linear behavior thanks to the small linearization error. \n\nIn order to control the connectedness, we need a last definition. Given a \nhidden layer of size $m$ with current parameters $W \\in \\R^{n \\times m}$, we define a\n``robust compressibility\" factor as \n\\begin{equation}\n\\label{compress}\n\\delta_W(l, \\alpha; m) = \\min_{ \\|\\gamma \\|_0 \\leq l, \\sup_i |\\angle(\\tilde{w}_i, w_i)| \\leq \\alpha} \\E \\{| Y - \\gamma Z(\\tilde{W}) |^2 + \\kappa \\| \\gamma \\|_1  \\}~,~(l \\leq m)~.\n\\end{equation} \nThis quantity thus measures how easily one can compress the current hidden layer representation, \nby keeping only a subset of $l$ its units, but allowing these units to move by a small amount controlled by $\\alpha$. It is a form \nof $n$-width similar to Kolmogorov width \\cite{donoho2006compressed} and is also related to robust sparse coding from \\cite{tang2013compressed, ekanadham2011recovery}.\n\n\n\\subsubsection{Main result}\n\nOur main result considers now a non-asymptotic scenario given by some fixed\nsize $m$ of the hidden layer. Given two parameter values $\\theta^A = (W_1^A, W_2^A) \\in \\mathcal{W}$ \nand $\\theta^B= (W_1^B, W_2^B)$ with $\\Forr(\\theta^{\\{A,B\\} } ) \\leq \\lambda$, \nwe show that there exists a continuous path \n$\\gamma: [0,1] \\to \\mathcal{W}$ connecting $\\theta^A$ and $\\theta^B$ \nsuch that its oracle risk is uniformly bounded by $\\max(\\lambda, \\epsilon)$, where $\\epsilon$ \ndecreases with model overparametrization. \n\\begin{theorem}\n\\label{maintheo}\nFor any $\\theta^A, \\theta^B \\in \\mathcal{W}$ and $\\lambda \\in \\R$ satisfying $\\Forr(\\theta^{\\{A,B\\}}) \\leq \\lambda$, there exists a continuous path $\\gamma: [0,1] \\to \\mathcal{W}$ such that\n$\\gamma(0) = \\theta^A$, $\\gamma(1) = \\theta^B$ and\n\\begin{equation}\n\\Forr( \\gamma(t) )  \\leq \\max( \\lambda, \\epsilon)~,\\text{ with}\n\\end{equation}\n\n\\begin{align}\n\\epsilon = \\inf_{l, \\alpha} \\Bigl(\\max \\Bigl\\{ e(l), &\\delta_{W_1^A}(m, 0; m ) , \\delta_{W_1^A}(m-l, \\alpha; m ) ,   \\\\ \n&\\delta_{W_1^B}(m, 0; m ) ,\\delta_{W_1^B} (m-l, \\alpha; m ) \\Bigr\\} + C_1 \\alpha  + O(\\alpha^2) \\Bigr)~,\n\\end{align}\n%with \n%$$f(\\alpha, M) = C_1 \\alpha  + C_2 M \\alpha^2 + O(\\alpha^2)~,$$\n%$$f(\\alpha) = ~,$$\nwhere $C_1$ is an absolute constant depending only on $\\kappa$ and $P$.\n\\end{theorem}\nSome remarks are in order. First, our regularization term is currently a mix between $\\ell_2$ norm constraints on the first layer and $\\ell_1$ norm constraints on the second layer. We believe this is an artifact of our proof technique, and we conjecture that more general regularizations yield similar results. Next, this result uses the data distribution through the oracle bound $e(m)$ and the covariance term. The \nextension to empirical risk is accomplished by replacing the probability measure $P$ by the empirical measure $\\hat{P} = \\frac{1}{L} \\sum_l \\delta\\left( (x,y) - (x_l, y_l)\\right) $. However, our asymptotic analysis has to be carefully reexamined to take into account and avoid the trivial regime when $M$ outgrows $L$.  \n%\\item Finally, another essential question is the extension of this result to several layers\n%\\end{itemize}\nA consequence of Theorem \\ref{maintheo} is that as $m$ increases, the model becomes asymptotically connected, as proven in the following corollary.\n\\begin{corollary}\n\\label{maincoro}\nAs $m$ increases, the energy gap $\\epsilon$ satisfies $\\epsilon = O( m^{-\\frac{1}{n}})$ and therefore the level sets become connected at all energy levels.\n%Here we use the fact that $\\delta(\\lambda m; \\epsilon(m); m) \\to 0$ as $m \\to \\infty$. (find the rate).\n\\end{corollary}\nThis is consistent with the overparametrization results from \\cite{safran2015quality,shamir2} and the general common knowledge amongst deep learning practitioners. Our next sections explore this question, and refine it by considering not only topological properties but also some rough geometrical measure of the level sets.\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "8ed173d5361c1798249dd21603a16274c2318c85", "size": 20217, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Writeup/iclr/topology.tex", "max_stars_repo_name": "danielfreeman11/convex-nets", "max_stars_repo_head_hexsha": "252a8230845fb2076221113ac8cabfade5152bfb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-08-09T00:48:46.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-03T09:04:59.000Z", "max_issues_repo_path": "Writeup/iclr/topology.tex", "max_issues_repo_name": "danielfreeman11/convex-nets", "max_issues_repo_head_hexsha": "252a8230845fb2076221113ac8cabfade5152bfb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Writeup/iclr/topology.tex", "max_forks_repo_name": "danielfreeman11/convex-nets", "max_forks_repo_head_hexsha": "252a8230845fb2076221113ac8cabfade5152bfb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.7846715328, "max_line_length": 456, "alphanum_fraction": 0.7142998467, "num_tokens": 6148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8519528019683106, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7004663316401172}}
{"text": "\\section{Natural Boundary; A Gluing Construction; Roots}\r\n\\subsection{Natural Boundary}\r\nSometimes, it is impossible to do analytic continuation.\r\nWrite $\\mathbb D=D(0,1)$ and $\\mathbb T=\\partial\\mathbb D=S^1$.\r\nConsider a power series $f(z)=\\sum_na_nz^n$ with radius of convergence $1$.\\\\\r\nWe say $z_0\\in\\mathbb T$ is regular if there is a neighbourhood $U$ of $z_0$ such that there exists a function element $(g,U)$ such that $f|_{U\\cap\\mathbb D}=g|_{U\\cap\\mathbb D}$.\r\nA point that is not regular is singular.\r\nEasily, the set of regular points is open in $\\mathbb T$, so the set of singular points has to be closed.\r\nThere are something to beware of which are illustrated in the example below.\r\n\\begin{example}\r\n    Consider $f(z)=\\frac{1}{1-z}=\\sum_{n\\ge 0}z^n$.\r\n    We know that the set of singular point is just $\\{1\\}$.\r\n    However, the power series evaluated at $-1$ does not converge.\r\n    So a regular point needs not guarantee that the power series converge there.\r\n\\end{example}\r\n\\begin{example}\r\n    Consider the power series\r\n    $$g(z)=\\sum_{n\\ge 2}\\frac{z^n}{n(n-1)}$$\r\n    Then the series converges at $z=1$, but $1$ is not regular for $g$ because it is singular for $f=g^{\\prime\\prime}$.\r\n\\end{example}\r\nThe moral od the examples is whether or not a point is regular does not relate directly to whether or not the power series converges there.\r\n\\begin{proposition}\r\n    If a power series $f(z)=\\sum_{n\\ge 0}a_nz^n$ has radius of convergence $1$, then some point of $\\mathbb T$ is singular.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Just use the compactness of $\\mathbb T$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    If every point of $\\mathbb T$ is singular, we say $\\mathbb T$ is the natural boundary of $f$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    We can extend this definition to other simple curves in $\\mathbb C_\\infty$.\r\n\\end{remark}\r\n\\begin{example}\r\n    Consider the function $f(z)=\\sum_{n\\ge 0}z^{n!}$.\r\n    We shall show that $\\mathbb T$ is its natural boundary.\r\n    It suffices to show any point in the form $\\omega=e^{2\\pi ip/q}$ is singular, where $p,q\\in\\mathbb Z,q\\neq 0$.\r\n    Indeed, fix such an $\\omega$ with corresponding $p,q$, then for $r\\in(0,1)$,\r\n    $$f(r\\omega)=\\sum_{n=0}^{q-1}r^{n!}\\omega^{n!}+\\sum_{n\\ge q}r^{n!}$$\r\n    But the second term definitely converge.\r\n    To see this, we observe that for any $M$,\r\n    $$\\lim_{r\\to 1}\\sum_{n=q}^{M+q}r^{n!}=M+1\\implies \\sum_{n=q}^{M+q}r^{n!}>M$$\r\n    for $r$ sufficiently close to $1$.\r\n    So the second term converges.\r\n    Yet the first term is bounded, therefore $f(r\\omega)\\to\\infty$ as $r\\to1$, so $\\omega$ has to be singular at $\\omega$.\r\n\\end{example}", "meta": {"hexsha": "7e566003312911051fe0b5f125022fbfc2545f4e", "size": 2645, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/nat.tex", "max_stars_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_stars_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2/nat.tex", "max_issues_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_issues_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2/nat.tex", "max_forks_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_forks_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.5, "max_line_length": 180, "alphanum_fraction": 0.6767485822, "num_tokens": 829, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7004663297922183}}
{"text": "\n\\subsection{Lerner index}\n\nMarginal profit. If high it suggests existing power prevents it from raising output.\n\n\\(L=\\dfrac{P-MC}{P}\\)\n\nFrom \\(0\\) to \\(1\\).\n\n", "meta": {"hexsha": "3eeb39267f170d8b17d0f69f5e0b60a836d62705", "size": 159, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/econometricsAggregate/06-03-lerner.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/econometricsAggregate/06-03-lerner.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/econometricsAggregate/06-03-lerner.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.9, "max_line_length": 84, "alphanum_fraction": 0.6855345912, "num_tokens": 46, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.7003456920370262}}
{"text": "\\section{Separable Differential Equations}\r\n\\noindent\r\nThe most basic approach for solving a 1st-order differential equation is simply integrating both sides. You're probably already familiar with this technique from taking indefinite integrals. This approach only works when the independent and dependent variables can be arranged on different sides of the equation. We'll formalize this idea with separability.\r\n\r\n\\begin{definition}\r\n\tA 1st order ODE is separable if it can be written in the form\r\n\t\\begin{equation*}\r\n\t\t\\frac{\\mathrm{d} y}{\\mathrm{d} x} = f(x)g(y)\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\r\n\\noindent\r\nSeparable equations provide a special way of solving them that can be useful. If we treat the derivative like a fraction (which is not formally allowed but OK here),\r\n\\begin{equation*}\r\n\t\\frac{\\mathrm{d} y}{\\mathrm{d} x} = f(x)g(y) \\implies \\frac{\\mathrm{d} y}{g(y)} = f(x) \\mathrm{d}x \\implies \\int{\\frac{\\mathrm{d} y}{g(y)}} = \\int{f(x) \\mathrm{d}x}\r\n\\end{equation*}\r\nWe then have a function in $y$ on the left and a function in $x$ on the right, meaning we only have to solve for $y$ to get the solution.\r\n\r\n\\ifodd\\includeFirstOrderLinearODEExamples\\input{./1stOrderLinearODE/separability/separability_example.tex}\\fi", "meta": {"hexsha": "645769898e40024dab749ddb49000513d1a370eb", "size": 1237, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/1stOrderLinearODE/separability/separability.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/1stOrderLinearODE/separability/separability.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/1stOrderLinearODE/separability/separability.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.1052631579, "max_line_length": 358, "alphanum_fraction": 0.7469684721, "num_tokens": 344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894717137997, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7003181460725119}}
{"text": "\\chapter{Fundamentals}\n\\label{chap:fund}\nThis chapter documents the definitions for fields, potentials, and \nFourier transforms that are employed in remainder of this document.\n\n\nWe restrict consideration to time-harmonic sources in simple, linear media,\nassuming and suppressing\na time dependence of $e^{j\\omega t}$.  RMS phasers are used throughout, employing\nrationalized MKS units. Thus,\nif $V$ is a (complex) phaser voltage, then the corresponding function of time\nis $v(t) = \\sqrt{2} \\Real{V e^{j\\omega t}}$.\n\nA right-handed Cartesian  coordinate system is adopted, with $x$, $y$, and \n$z$ axes, and unit vectors $\\x$, $\\y$, and $\\z$.  A point $P = (x,y,z)$ is \ntypically identified by the vector $\\r = x\\x + y\\y + z\\z$ which measures \nthe displacement of $P$ from the origin.\n\nThe medium under consideration is characterized by its scalar, complex permittivity\n$\\epsilon$ [F/m] and its scalar, complex permeability $\\mu$ [H/m], \nboth of which may be functions \nof position, $\\epsilon = \\epsilon(\\r)$, $\\mu = \\mu(\\r)$. Although these parameters are\nboth positive for lossless media, in the presence of electric and/or magnetic\nlosses the imaginary part of $\\epsilon$ and/or $\\mu$, respectively, is negative.\nThus, $\\epsilon$ and $\\mu$ both lie in the fourth quadrant (or positive real\naxis) of the complex plane.\n\nFor convenience we define the medium's intrinsic wavenumber\n\\begin{equation}\n  k = \\omega \\sqrt{\\mu\\epsilon} \\qquad \\text{(fourth quadrant)}\n\\end{equation}\nand intrinsic impedance\n\\begin{equation}\n  \\eta = \\sqrt{\\mu/\\epsilon} \\qquad \\left(\\abs{\\arg\\eta} < \\frac{\\pi}{4} \\right),\n\\end{equation}\nwhich, of course, vary with position if $\\epsilon$ or $\\mu$ do.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Maxwell's Equations and Potentials for Electric Sources}\nUnder the assumptions listed above, and postulating the existence of only\nelectric sources, Maxwell's curl equations \n(Ampere's Law and Faraday's Law) take the form\n\\begin{subequations}\n  \\begin{align}\n    \\curl \\H &= j\\omega\\epsilon \\E + \\J \\label{eq:AmpereE} \\\\\n    \\curl \\E &= -j\\omega\\mu \\H  \\label{eq:FaradayE}\n  \\end{align}\n\\end{subequations}\nwhere $\\E$ is the electric field vector [V/m], $\\H$ is the magnetic field\nvector [A/m], and $\\J$ is the electric current density [A/m$^2$].\nWhen combined with the equation of continuity\n\\begin{equation}\n  \\divergence \\J + j\\omega\\qe = 0\n\\end{equation}\nwe obtain the divergence relations\n\\begin{subequations}\n  \\begin{align}\n    \\divergence \\epsilon\\E &= \\qe  \\label{eq:divE}\\\\\n    \\divergence \\mu\\H       &= 0,\n  \\end{align}\n\\end{subequations}\nwhere $\\qe$ is the electric charge density,\nwith units of [C/m$^3$].\nThe fact that $\\mu\\H$ is divergenceless leads to \nthe introduction of the magnetic vector potential $\\A$\nhaving units of [Vs/m]:\n\\begin{equation}\n  \\boxed{\n  \\mu\\H = \\curl \\A.  \n  } \\label{eq:curlA}\n\\end{equation}\nSubstituting \\eqref{eq:curlA} into \\eqref{eq:FaradayE} we find that\n$-\\E - j\\omega\\A$ is curl-free, and so can be written as the gradient\nof the so-called electric scalar potential $\\Phi$ [V]:\n\\begin{equation}\n  \\label{eq:PhiE}\n  \\boxed{\n  \\E = -j\\omega\\A-\\gradient\\Phi.\n  }\n\\end{equation}\nTo derive the differential equations for $\\A$ and $\\Phi$ we\nbegin with the identity\n\\begin{equation}\n  \\curl \\curl \\A = \\curl \\mu\\H = \\mu \\curl \\H + \\gradient\\mu \\cross \\H\n\\end{equation}\nand use Equations \\eqref{eq:AmpereE} and \\eqref{eq:curlA} to eliminate\n$\\H$:\n\\begin{equation}\n  \\gradient\\divergence\\A - \\vlaplace\\A =\n  j\\omega\\epsilon\\mu\\E + \\mu\\J + \\gradient\\mu \\cross \n  \\left(\n    \\frac{1}{\\mu} \\curl\\A\n  \\right).\n\\end{equation}\nNote that we also employed the identity $\\curl\\curl\\A = \n  \\gradient\\divergence\\A - \\vlaplace\\A$.\nNow eliminating $\\E$ using \\eqref{eq:PhiE} we obtain\n\\begin{equation}\n  \\vlaplace\\A + k^2 \\A + \\gradient\\mu \\cross\n  \\left(\n    \\frac{1}{\\mu} \\curl\\A\n  \\right)\n  - \\gradient \n  \\left[\n    \\divergence\\A + j\\omega\\mu\\epsilon\\Phi\n  \\right]\n  = -\\mu\\J.\n\\end{equation}\nSince the divergence of the magnetic vector potential is as yet unspecified,\nwe may apply the Lorentz gauge, $\\divergence\\A = -j\\omega\\epsilon\\mu\\Phi$,\nand set the quantity in square brackets above to zero:\n\\begin{equation}\n  \\boxed{%\n  \\vlaplace\\A + k^2 \\A + \\frac{\\gradient\\mu}{\\mu} \\cross \\curl\\A\n  = -\\mu\\J.  \\label{eq:WaveAinhom}\n  }\n\\end{equation}\nEquation~\\eqref{eq:WaveAinhom} is the fundamental wave equation for \nthe magnetic vector potential under the Lorentz gauge in an inhomogeneous\nmedium.  \n\nAn equation for $\\Phi$ is now obtained by employing the\nidentity $\\divergence \\epsilon\\E = \\E\\bdot\\gradient \\epsilon\n+ \\epsilon \\divergence\\E$ in \\eqref{eq:divE} and then\neliminating $\\E$ using \\eqref{eq:PhiE}:\n\\begin{align}\n  \\qe\n  &= \\E \\bdot \\gradient \\epsilon + \\epsilon \\divergence\\E \\notag \\\\\n  &= -(j\\omega\\A + \\gradient\\Phi) \\bdot \\gradient\\epsilon\n  - \\epsilon \\divergence (j\\omega\\A + \\gradient\\Phi).\n\\end{align}\nAfter invoking the Lorentz gauge this can be written as\n\\begin{equation}\n  \\boxed{%\n  \\laplace\\Phi + k^2\\Phi + \\frac{\\gradient\\Phi \\bdot \\gradient\\epsilon}{\\epsilon}\n  = \n  -\\frac{\\qe}{\\epsilon} - \\frac{j\\omega\\A \\bdot \\gradient\\epsilon}{\\epsilon}.\n  } \\label{eq:WavePhiinhom}\n\\end{equation}\nEquation~\\eqref{eq:WavePhiinhom} is the wave equation for \nthe electric scalar potential under the Lorentz gauge in an inhomogeneous\nmedium.  \n\n\\subsection{Piecewise Homogeneous Medium}\nSuppose that the spatial domain $U$ of the boundary value problem\nfor which Maxwell's Equations are to be\nsolved consists of a disjoint union of a finite number $N$ of\nhomogeneous regions $U_i$, as in the case of a stratified medium:\n\\begin{equation}\n  U = \\union_{i=1}^{N} U_i,\n\\end{equation}\nand suppose that the permittivity and permeability of the $i$th region\nare the constants $\\epsilon_i$ and $\\mu_i$, respectively, with corresponding\nwavenumber $k_i$.  Then, for\npoints within the $i$th medium, the terms involving the gradient of\nthe permittivity and permeability are zero, and the \npotentials within the $i$th region are solutions to \n\\begin{subequations}\n  \\begin{gather}\n    \\vlaplace\\A^{(i)} + k_i^2 \\A^{(i)}  = -\\mu_i\\J, \\\\\n    \\laplace\\Phi^{(i)} + k_i^2 \\Phi^{(i)}  = -\\qe/\\epsilon_i.\n  \\end{gather}\n\\end{subequations}\nIf the $i$th region contains no sources, then the potentials\nin that region are solutions to the Helmholtz equation:\n\\begin{subequations}\n  \\begin{gather}\n    \\vlaplace\\A^{(i)} + k_i^2 \\A^{(i)}  = \\0, \\\\\n    \\laplace\\Phi^{(i)} + k_i^2 \\Phi^{(i)}  = 0.\n  \\end{gather}\n\\end{subequations}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Maxwell's Equations for Magnetic Sources}\nUnder the assumptions listed in the introduction, and postulating the existence of only\nmagnetic sources, Maxwell's curl equations \n(Ampere's Law and Faraday's Law) take the form\n\\begin{subequations}\n  \\begin{align}\n    \\curl \\H &= j\\omega\\epsilon \\E \\label{eq:AmpereM} \\\\\n    \\curl \\E &= -j\\omega\\mu \\H - \\M \\label{eq:FaradayM}\n  \\end{align}\n\\end{subequations}\nwhere $\\E$ is the electric field vector [V/m], $\\H$ is the magnetic field\nvector [A/m], and $\\M$ is the magnetic current density [V/m$^2$].\nWhen combined with the equation of continuity\n\\begin{equation}\n  \\divergence \\M + j\\omega\\qm = 0\n\\end{equation}\nwe obtain the divergence relations\n\\begin{subequations}\n  \\begin{align}\n    \\divergence \\epsilon\\E &= 0  \\label{eq:divEm}\\\\\n    \\divergence \\mu\\H &= \\qm,    \\label{eq:divHm}\n  \\end{align}\n\\end{subequations}\nwhere $\\qm$ is the magnetic charge density,\nwith units of [Wb/m$^3$].\nThe fact that $\\epsilon\\E$ is divergenceless leads to \nthe introduction of the electric vector potential $\\F$\nhaving units of [As/m]:\n\\begin{equation}\n  \\boxed{\n  \\epsilon\\E = \\curl \\F.  \n  } \\label{eq:curlF}\n\\end{equation}\nSubstituting \\eqref{eq:curlF} into \\eqref{eq:AmpereM} we find that\n$j\\omega\\F - \\H$ is curl-free, and so can be written as the gradient\nof the so-called magnetic scalar potential $\\Psi$ [A]:\n\\begin{equation}\n  \\label{eq:PsiM}\n  \\boxed{\n  \\H =  j\\omega\\F - \\gradient\\Psi.\n  }\n\\end{equation}\nTo derive the differential equations for $\\F$ and $\\Psi$ we\nbegin with the identity\n\\begin{equation}\n  \\curl \\curl \\F = \\curl \\epsilon\\E = \\epsilon \\curl \\E + \\gradient\\epsilon \\cross \\E\n\\end{equation}\nand use Equations \\eqref{eq:FaradayM} and \\eqref{eq:curlF} to eliminate\n$\\E$:\n\\begin{equation}\n  \\gradient\\divergence\\F - \\vlaplace\\F =\n  -j\\omega\\epsilon\\mu\\H - \\epsilon\\M + \\gradient\\epsilon \\cross \n  \\left(\n    \\frac{1}{\\epsilon} \\curl\\F\n  \\right).\n\\end{equation}\nNote that we also employed the identity $\\curl\\curl\\F = \n  \\gradient\\divergence\\F - \\vlaplace\\F$.\nNow eliminating $\\H$ using \\eqref{eq:PsiM} we obtain\n\\begin{equation}\n  \\vlaplace\\F + k^2 \\F + \\gradient\\epsilon \\cross\n  \\left(\n    \\frac{1}{\\epsilon} \\curl\\F\n  \\right)\n  - \\gradient \n  \\left[\n    \\divergence\\F - j\\omega\\mu\\epsilon\\Psi\n  \\right]\n  = \\epsilon\\M.\n\\end{equation}\nSince the divergence of the electric vector potential is as yet unspecified,\nwe may apply the Lorentz gauge, $\\divergence\\F = j\\omega\\epsilon\\mu\\Psi$,\nand set the quantity in square brackets above to zero:\n\\begin{equation}\n  \\boxed{%\n  \\vlaplace\\F + k^2 \\F + \\frac{\\gradient\\epsilon}{\\epsilon} \\cross\n  \\curl\\F\n  = \\epsilon\\M.\n  \\label{eq:WaveFinhom}\n  }\n\\end{equation}\nEquation~\\eqref{eq:WaveFinhom} is the fundamental wave equation for \nthe electric vector potential under the Lorentz gauge in an inhomogeneous\nmedium.  \n\nAn equation for $\\Psi$ is now obtained by employing the\nidentity $\\divergence \\mu\\H = \\H\\bdot\\gradient \\mu\n+ \\mu \\divergence\\H$ in \\eqref{eq:divHm} and then\neliminating $\\H$ using \\eqref{eq:PsiM}:\n\\begin{align}\n  \\qm\n  &= \\H \\bdot \\gradient \\mu + \\mu \\divergence\\H \\notag \\\\\n  &= (j\\omega\\F - \\gradient\\Psi) \\bdot \\gradient\\mu\n  + \\mu \\divergence (j\\omega\\F - \\gradient\\Psi).\n\\end{align}\nAfter invoking the Lorentz gauge this can be written as\n\\begin{equation}\n  \\boxed{%\n  \\laplace\\Psi + k^2\\Psi + \\frac{\\gradient\\Psi \\bdot \\gradient\\mu}{\\mu}\n  = \n  -\\frac{\\qm}{\\mu} + \\frac{j\\omega\\F \\bdot \\gradient\\mu}{\\mu}.\n  } \\label{eq:WavePsiinhom}\n\\end{equation}\nEquation~\\eqref{eq:WavePsiinhom} is the wave equation for \nthe electric scalar potential under the Lorentz gauge in an inhomogeneous\nmedium.  \n\n\\subsection{Piecewise Homogeneous Medium}\nSuppose that the spatial domain $U$ of the boundary value problem\nfor which Maxwell's Equations are to be\nsolved consists of a disjoint union of a finite number $N$ of\nhomogeneous regions $U_i$, as in the case of a stratified medium:\n\\begin{equation}\n  U = \\union_{i=1}^{N} U_i,\n\\end{equation}\nand suppose that the permittivity and permeability of the $i$th region\nare the constants $\\epsilon_i$ and $\\mu_i$, respectively, with corresponding\nwavenumber $k_i$.  Then, for\npoints within the $i$th medium, the terms involving the gradient of\nthe permittivity and permeability are zero, and the \npotentials within the $i$th region are solutions to \n\\begin{subequations}\n  \\begin{gather}\n    \\vlaplace\\F^{(i)} + k_i^2 \\F^{(i)}  = \\epsilon_i\\M, \\\\\n    \\laplace\\Psi^{(i)} + k_i^2 \\Psi^{(i)}  = -\\qm/\\mu_i.\n  \\end{gather}\n\\end{subequations}\nIf the $i$th region contains no sources, then the potentials\nin that region are solutions to the Helmholtz equation:\n\\begin{subequations}\n  \\begin{gather}\n    \\vlaplace\\F^{(i)} + k_i^2 \\F^{(i)}  = \\0, \\\\\n    \\laplace\\Psi^{(i)} + k_i^2 \\Psi^{(i)}  = 0.\n  \\end{gather}\n\\end{subequations}\n\n\\section{Duality}\nWe note that the cases of electric-only and magnetic-only sources are duals.\nAny valid equation involving electromagnetic quantities has a dual equation\nwhich can be obtained by applying the following rules:\n\\begin{enumerate}\n\\item Interchange $\\mu$ and $\\epsilon$.\n\\item Electric quantities are replaced by their corresponding magnetic quantity.\n\\item Magnetic quantities are replaced by the negative of their corresponding electric quantity.\n\\end{enumerate}\nThe mappings between original and dual quantities are given in \nTable~\\ref{tab:duals}.\n\\begin{table}[htbp]\n  \\begin{center}\n    \\leavevmode\n    \\begin{tabular}{|c|} \\hline\n      \\bfseries Original $\\boldsymbol{\\rightarrow}$ Dual \\\\ \\hline \\hline\n      $\\mu \\rightarrow \\epsilon$ \\\\ \\hline\n      $\\epsilon \\rightarrow \\mu$ \\\\ \\hline\n      $k \\rightarrow k$ \\\\ \\hline\n      $\\eta \\rightarrow 1/\\eta$ \\\\ \\hline\n      $\\E \\rightarrow \\H$ \\\\ \\hline\n      $\\J \\rightarrow \\M$ \\\\ \\hline\n      $\\F \\rightarrow \\A$ \\\\ \\hline\n      $\\Phi \\rightarrow \\Psi$ \\\\ \\hline\n      $\\qe \\rightarrow \\qm$ \\\\ \\hline\n      $\\H \\rightarrow -\\E$ \\\\ \\hline\n      $\\M \\rightarrow -\\J$ \\\\ \\hline\n      $\\A \\rightarrow -\\F$ \\\\ \\hline\n      $\\Psi \\rightarrow -\\Phi$ \\\\ \\hline\n      $\\qm \\rightarrow -\\qe$ \\\\ \\hline\n    \\end{tabular}\n    \\caption{Electromagnetic dual quantities.}\n    \\label{tab:duals}\n  \\end{center}\n\\end{table}\n\n\\section{Fourier Transform Definitions}\n\\subsection{One-dimensional Transform}\nThe Fourier transform of a function $f: \\Realnum \\rightarrow \\Complexnum$\nis $\\tilde{f} = \\Fourier \\{f\\}$, where\n\\begin{equation}\n  \\tilde{f}(k) = \\int_{-\\infty}^{\\infty} f(x) e^{jkx} \\d x,\n\\end{equation}\nso that \n\\begin{equation}\n  f(x) = \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} \\tilde{f}(k) e^{-jkx} \\d k.\n\\end{equation}\n\nThe completeness statement is\n\\begin{equation}\n  \\delta(x) = \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} e^{\\pm jkx} \\d k\n\\end{equation}\nand Parseval's relation is\n\\begin{equation}\n\\int_{-\\infty}^{\\infty} f(x) g^*(x) \\, \\d x =   \n\\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} \\tilde{f}(k) \\tilde{g}^*(k) \\, \\d k.\n\\end{equation}\nFinally, if \n\\begin{equation}\n  h(x) = \\int_{-\\infty}^{\\infty} f(x') g(x-x') \\, \\d x'\n\\end{equation}\nthen the convolution theorem states that\n\\begin{equation}\n  \\tilde{h}(k) = \\tilde{f}(k) \\tilde{g}(k).\n\\end{equation}\n\n\n\\subsection{Two-dimensional Transform}\nThe Fourier transform of a function $f: \\Realnum \\times \\Realnum\n\\rightarrow \\Complexnum$\nis $\\tilde{f} = \\Fourier \\{f\\}$, where\n\\begin{equation}\n  \\tilde{f}(k_x,k_y) = \n  \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} \n  f(x,y) e^{j(k_x x + k_y y)} \\d x  \\d y,\n\\end{equation}\nso that \n\\begin{equation}\n  f(x,y) = \\frac{1}{4\\pi^2} \n  \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty}\n \\tilde{f}(k_x,k_y) e^{-j(k_x x + k_y y)} \\d k_x  \\d k_y.\n\\end{equation}\n\nThe completeness statement is\n\\begin{equation}\n  \\delta(x) \\delta(y) = \\frac{1}{4\\pi^2} \n  \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty}\n  e^{\\pm j(k_x x + k_y y)} \\d k_x  \\d k_y\n\\end{equation}\nand Parseval's relation is\n\\begin{equation}\n\\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty}\n f(x,y) g^*(x,y) \\, \\d x  \\d y =   \n\\frac{1}{4\\pi^2} \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} \n\\tilde{f}(k_x,k_y) \\tilde{g}^*(k_x,k_y) \\, \\d k_x  \\d k_y.\n\\end{equation}\nFinally, if \n\\begin{equation}\n  h(x,y) = \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty}\n f(x',y') g(x-x',y-y') \\, \\d x'  \\d y'\n\\end{equation}\nthen the convolution theorem states that\n\\begin{equation}\n  \\tilde{h}(k_x,k_y) = \\tilde{f}(k_x,k_y) \\tilde{g}(k_x,k_y).\n\\end{equation}\n\n\n", "meta": {"hexsha": "fb5df0bea6127147d20989c15c3fe54c5a9f5489", "size": 14954, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/TheoryDocs/chapter1.tex", "max_stars_repo_name": "mortenpi/PSSFSS.jl", "max_stars_repo_head_hexsha": "9a3a6503d9266eee57771612a47a3e9b77bc9a2e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2021-05-21T15:44:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T17:29:19.000Z", "max_issues_repo_path": "docs/TheoryDocs/chapter1.tex", "max_issues_repo_name": "mortenpi/PSSFSS.jl", "max_issues_repo_head_hexsha": "9a3a6503d9266eee57771612a47a3e9b77bc9a2e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-10-08T22:20:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-26T01:01:09.000Z", "max_forks_repo_path": "docs/TheoryDocs/chapter1.tex", "max_forks_repo_name": "mortenpi/PSSFSS.jl", "max_forks_repo_head_hexsha": "9a3a6503d9266eee57771612a47a3e9b77bc9a2e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-20T13:58:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-24T09:16:48.000Z", "avg_line_length": 35.860911271, "max_line_length": 96, "alphanum_fraction": 0.6768757523, "num_tokens": 5032, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789452074398, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.700318130701489}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 7}\n\nGive a counter-example to the conjecture that if a directed graph $G$ contains a path from $u$ to $v$, then any depth-first search must result in $v.d \\leq u.f$.\n\n\\subsection*{Solution}\n\nThe counter-example proposed for previous question depicted in Figure \\ref{fig61} can be proposed again.\nStarting from node $a$ as the source vertex, if depth-first algorithm continues with vertex $b$ ($b.d = 2$), there is no child of $b$ not already visited and therefore, node $b$ will be marked as visited ($b.f = 3 $).\nGoing back to the partially visited vertex $a$, the algorithm would continue by discovering $c$ ($c.d = 5$).\nAnd this shows although there is a path from $b$ to $c$, $c.d \\nleq b.f$.\n", "meta": {"hexsha": "33aecd012fd989915c6b0f5a5589c39066baafc0", "size": 1071, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw05/hw05q07.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw05/hw05q07.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw05/hw05q07.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 59.5, "max_line_length": 217, "alphanum_fraction": 0.6442577031, "num_tokens": 266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7003162642159458}}
{"text": "\\documentclass[11pt,a4paper]{article}\n\n\\usepackage{tikz}\n\\usepackage[parfill]{parskip}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{placeins}\n\\usepackage{cleveref}\n\\usepackage{bm}\n\n\\newcommand{\\norm}[1]{\\left\\lVert#1\\right\\rVert}\n\\newcommand{\\p}[1]{\\left(#1\\right)}\n\n\\begin{document}\n\n\\usetikzlibrary{math}\n\n\\section{Introduction}\nThis document describes how we can generate and transform\nvarious shapes for rendering on a GPU. The output of each\nshape is a list of vertices and some parameters to tweak\nhow the shape is rendered.\n\n\\section{Transformations}\nThere are two main ways to transform a shape. We can transform\nthe underlying data that describes the shape, or we can transform\nthe shape itself. All shapes discussed here are described by a set\nof 2D points. When we transform the underlying data, it is these\npoints we refer to. Consider a point $\\mathbf{x} \\in \\mathbb{R}^2$.\nAny linear transformation can be described by\n%\n\\begin{align}\n  \\mathbf{y} = \\mathbf{A} \\mathbf{x} + \\mathbf{b}\n\\end{align}\n%\nIf we apply this to all points before rendering, we have\ntransformed the underlying data. To transform the shape\nwe instead apply it to the points defining the triangles\nthat are rendered by the GPU. Of course, both approaches\ncan be combined.\n\n\\subsection{Homogenous Coordinates}\nIt is often simpler to work in homogenous coordinates,\nsince chaining transformations can be done by multiplying\nmatrices. The point $\\mathbf{x}$ is represented as\n%\n\\begin{align}\n  \\mathbf{x}' = \\begin{bmatrix} \\mathbf{x} \\\\ 1 \\end{bmatrix}\n\\end{align}\n%\nDefine a matrix\n%\n\\begin{align}\n  \\mathbf{A}' = \\begin{bmatrix}\n    \\mathbf{A} & \\mathbf{b} \\\\\n    \\mathbf{0}^T & 1\n    \\end{bmatrix}\n\\end{align}\n%\nThen\n%\n\\begin{align}\n  \\mathbf{y}' = \\mathbf{A}' \\mathbf{x}'\n\\end{align}\n%\nwhere $\\mathbf{y}'$ is also a homogenous coordinate. Hence,\ntransformations are easily chained. We can also reverse the\ntransformation by inverting $\\mathbf{A}'$.\n\n\\subsection{Decomposition}\nIf we restrict ourselves to the transformations scaling, rotation and translation,\nthen any transformation can be decomposed as\n%\n\\begin{align}\n  \\mathbf{y} = \\mathbf{R} \\mathbf{S} \\mathbf{x} + \\mathbf{b}\n\\end{align}\n%\nwhere\n%\n\\begin{align}\n  \\mathbf{R} = \\begin{bmatrix}\n    \\cos(\\theta) & -\\sin(\\theta) \\\\\n    \\sin(\\theta) & \\cos(\\theta)\n  \\end{bmatrix}\\quad,\\quad\n  % \n  \\mathbf{S} = \\begin{bmatrix}\n    s_x & 0 \\\\ 0 & s_y                 \n  \\end{bmatrix}\n\\end{align}\n%\nwhere $\\theta$ is rotation, $s_x$ and $s_y$ is $x$ and $y$ scaling,\nand $\\mathbf{b}$ is translation. We thus have\n%\n\\begin{align}\n  \\mathbf{A} = \\mathbf{RS} = \\begin{bmatrix}\n    s_x \\cos(\\theta) & -s_y \\sin(\\theta) \\\\\n    s_x \\sin(\\theta) & s_y \\cos(\\theta)\n  \\end{bmatrix}\n\\end{align}\n%\nwhich yields $4$ equations with $3$ unknowns. We begin solving for $\\theta$.\n%\n\\begin{align}\n  \\frac{s_x \\sin(\\theta)}{s_x \\cos(\\theta)} = \\frac{A_{00}}{A_{10}}\n\\end{align}\n%\nwhich leads to\n%\n\\begin{align}\n  \\theta = \\tan^{-1}\\p{\\frac{A_{00}}{A_{10}}}\n\\end{align}\n% \n$A_{10}$ might be problematic. Hence, we also consider the solution\n%\n\\begin{align}\n  \\theta = \\tan^{-1}\\p{\\frac{A_{01}}{A_{11}}}\n\\end{align}\n%\nWith the transformations considered, $A_{10}$ and $A_{11}$ will never\nbe zero simultaneously.  From here it's easy to see that\n%\n\\begin{align}\n  s_x &= \\frac{A_{00}}{\\cos(\\theta)}\\\\\n  s_y &= \\frac{A_{11}}{\\cos(\\theta)}\n\\end{align}\n%\nThus, the decomposed quantities can easily be extracted from any\nhomogenous transformation matrix $\\mathbf{A}'$.\n\n\\FloatBarrier\n\\section{Lines}\n\\subsection{Single Line}\nLet $\\mathbf{x}_1$ be one side of the line and $\\mathbf{x}_2$ be the\nother.  Let $w$ be desired with of the line. \\Cref{fig:single-line}\nshows an example of a single drawn line. To draw this line on the GPU\nwe need to pass the points $a$, $b$, $c$, and $d$ to a vertex shader\nsomehow.  It is important that both the transformation matrix\n$\\mathbf{A}'$ and the line width $w$, is \\emph{only} used in the GPU.\nWith this constraint, the vertices need only be computed once.\n%\n\\begin{figure}\n  \\centering\n  \\begin{tikzpicture}\n    \\tikzmath{\n      \\x1 = 0;\n      \\y1 = 0;\n      \\x2 = 4;\n      \\y2 = 2;\n      \\l = sqrt((\\x2-\\x1)^2 + (\\y2-\\y1)^2);\n      \\w = 0.4;\n      \\dx = \\w * (\\x2 - \\x1) / \\l;\n      \\dy = \\w * (\\y2 - \\y1) / \\l;\n    }\n\n    \\coordinate (a) at (\\x1-\\dy, \\y1+\\dx);\n    \\coordinate (b) at (\\x1+\\dy, \\y1-\\dx);\n    \\coordinate (c) at (\\x2+\\dy, \\y2-\\dx);\n    \\coordinate (d) at (\\x2-\\dy, \\y2+\\dx);\n    \\filldraw[black] (\\x1, \\y1) circle (2pt) node [anchor=east] {$\\mathbf{y}_1$};\n    \\filldraw[black] (\\x2, \\y2) circle (2pt) node [anchor=west] {$\\mathbf{y}_2$};\n\n    \\draw[gray,thick] (a) node [anchor=south] {a} -- \n    (b) node [anchor=north] {b} -- \n    (c) node [anchor=north] {c} -- \n    (d) node [anchor=south] {d} -- (a);\n    \\draw[black,thick,dashed] (\\x1, \\y1) -- (\\x2, \\y2);\n  \\end{tikzpicture}\n  \\caption{Single line}\n  \\label{fig:single-line}\n\\end{figure}\n\nFirst, define\n%\n\\begin{align}\n  \\mathbf{y}_1 &= \\mathbf{A} \\mathbf{x}_1 + \\mathbf{b} \\\\\n  \\mathbf{y}_2 &= \\mathbf{A} \\mathbf{x}_2 + \\mathbf{b} \\\\\n\\end{align}\n%\nand\n%\n\\begin{align}\n  \\bm{\\Delta} &= \\mathbf{y}_2 - \\mathbf{y}_1\\\\\n  l &= \\norm{\\bm{\\Delta}}\n\\end{align}\n%\nNext, we define a matrix\n%\n\\begin{align}\n  \\mathbf{R} = \\begin{bmatrix} 0 & -1 \\\\ 1 & 0 \\end{bmatrix}\n\\end{align}\n% \nIn practice, applying this to a vector rotates the vector by 90 degrees\ncounter-clockwise. We now have what we need to define the corners\nof the rectangle defining the line.\n%\n\\begin{align}\n  \\mathbf{a} &= \\mathbf{y}_1 + \\frac{w}{l} \\mathbf{R} \\bm{\\Delta}\\\\\n  \\mathbf{b} &= \\mathbf{y}_1 - \\frac{w}{l} \\mathbf{R} \\bm{\\Delta}\\\\\n  \\mathbf{c} &= \\mathbf{y}_2 + \\frac{w}{l} \\mathbf{R} \\bm{\\Delta}\\\\\n  \\mathbf{d} &= \\mathbf{y}_2 - \\frac{w}{l} \\mathbf{R} \\bm{\\Delta}\\\\\n\\end{align}\n%\nThere is a problem here however. $\\mathbf{A}'$ is baked in to several\nof the elements. We replace the $\\mathbf{y}$s with $\\mathbf{x}$s. We\ndefine\n%\n\\begin{align}\n  \\bm{\\Delta}_x = \\p{\\mathbf{x}_2 - \\mathbf{x}_1}\n\\end{align}\n%\nwhich yields\n%\n\\begin{align}\n  \\bm{\\Delta} &= \\mathbf{A} \\bm{\\Delta}_x\\\\\n  l &= \\norm{\\mathbf{A} \\bm{\\Delta}_x}\n\\end{align}\n%\nWe can now rewrite the rectangles as\n%\n\\begin{align}\n  \\mathbf{a} &= \\mathbf{A} \\mathbf{x}_1 + \\mathbf{b} +\n               \\frac{w}{l} \\mathbf{R} \\mathbf{A} \\bm{\\Delta}_x\\\\\n  %\n  \\mathbf{b} &= \\mathbf{A} \\mathbf{x}_1 + \\mathbf{b} -\n               \\frac{w}{l} \\mathbf{R} \\mathbf{A} \\bm{\\Delta}_x\\\\\n  %\n  \\mathbf{c} &= \\mathbf{A} \\mathbf{x}_2 + \\mathbf{b} +\n               \\frac{w}{l} \\mathbf{R} \\mathbf{A} \\bm{\\Delta}_x\\\\\n  %\n  \\mathbf{d} &= \\mathbf{A} \\mathbf{x}_2 + \\mathbf{b} -\n               \\frac{w}{l} \\mathbf{R} \\mathbf{A} \\bm{\\Delta}_x\\\\\n\\end{align}\n%\nFrom this, we see that each vertex needs five attributes, its\nposition, $\\bm{\\Delta}$, and its offset direction.  Let\n$\\mathbf{v} \\in \\mathbb{R}^5$ represent a vertex. The 2D position to\ndraw each point is\n%\n\\begin{align}\n  \\mathbf{p} &= \\mathbf{A} \\begin{bmatrix} v_0 \\\\ v_1 \\end{bmatrix} + \\mathbf{b} +\n  \\frac{v_4 w}{l} \\mathbf{R} \\mathbf{A} \\begin{bmatrix} v_2 \\\\ v_3 \\end{bmatrix}\\\\\n  l &= \\norm{\\mathbf{A} \\begin{bmatrix} v_2 \\\\ v_3 \\end{bmatrix}}\n\\end{align}\n%\nwhere\n%\n\\begin{align}\n  \\mathbf{a} \\quad &=> \\quad \\mathbf{v} =\n            \\begin{bmatrix} \\mathbf{x}_1^T & \\bm{\\Delta}^T & 1 \\end{bmatrix}^T\\\\\n  %\n  \\mathbf{b} \\quad &=> \\quad \\mathbf{v} =\n            \\begin{bmatrix} \\mathbf{x}_1^T & \\bm{\\Delta}^T & -1 \\end{bmatrix}^T\\\\\n  %\n  \\mathbf{c} \\quad &=> \\quad \\mathbf{v} =\n            \\begin{bmatrix} \\mathbf{x}_2^T & \\bm{\\Delta}^T & 1 \\end{bmatrix}^T\\\\\n  %\n  \\mathbf{d} \\quad &=> \\quad \\mathbf{v} =\n            \\begin{bmatrix} \\mathbf{x}_2^T & \\bm{\\Delta}^T & -1 \\end{bmatrix}^T\\\\\n\\end{align}\n%\nand $\\mathbf{A}$, $\\mathbf{b}$ and $w$ are passed as uniforms. This way, the\nvertices only need to be computed once.\n\n\\FloatBarrier\n\\subsection{Multiple Lines}\nWhen drawing multiple lines, we have to make sure they intersect nicely.\nAn example is shown in \\cref{fig:multi-line}, and there is a gap between\nthe lines which must be filled in. To do this we draw an additional triangle\nbetween the black dot, corner d and corner e. If the angle between the \nlines went the other way the gap would occur between the black dot, corner\nf and corner c. Hence, we draw a triangle here as well.\n%\n\\begin{figure}\n  \\centering\n  \\begin{tikzpicture}\n    \\tikzmath{\n      \\x1 = 0;\n      \\y1 = 0;\n      \\x2 = 4;\n      \\y2 = 2;\n      \\x3 = 6;\n      \\y3 = 0;\n      \\w = 0.4;\n      %\n      \\l1 = sqrt((\\x2-\\x1)^2 + (\\y2-\\y1)^2);\n      \\dx1 = \\w * (\\x2 - \\x1) / \\l1;\n      \\dy1 = \\w * (\\y2 - \\y1) / \\l1;\n      %\n      \\l2 = sqrt((\\x3-\\x2)^2 + (\\y3-\\y2)^2);\n      \\dx2 = \\w * (\\x3 - \\x2) / \\l2;\n      \\dy2 = \\w * (\\y3 - \\y2) / \\l2;\n    }\n\n    \\coordinate (a) at (\\x1-\\dy1, \\y1+\\dx1);\n    \\coordinate (b) at (\\x1+\\dy1, \\y1-\\dx1);\n    \\coordinate (c) at (\\x2+\\dy1, \\y2-\\dx1);\n    \\coordinate (d) at (\\x2-\\dy1, \\y2+\\dx1);\n\n    \\coordinate (e) at (\\x2-\\dy2, \\y2+\\dx2);\n    \\coordinate (f) at (\\x2+\\dy2, \\y2-\\dx2);\n    \\coordinate (g) at (\\x3+\\dy2, \\y3-\\dx2);\n    \\coordinate (h) at (\\x3-\\dy2, \\y3+\\dx2);\n\n    \\filldraw[black] (\\x1, \\y1) circle (2pt);\n    \\filldraw[black] (\\x2, \\y2) circle (2pt);\n    \\filldraw[black] (\\x3, \\y3) circle (2pt);\n\n    \\draw[gray,thick] \n      (a) node [anchor=east] {a} -- \n      (b) node [anchor=north] {b} -- \n      (c) node [anchor=west] {c} -- \n      (d) node [anchor=south] {d} -- \n      (a);\n    \\draw[gray,thick] \n      (e) node [anchor=south] {e} -- \n      (f) node [anchor=east] {f} -- \n      (g) node [anchor=north] {g} -- \n      (h) node [anchor=west] {h} -- \n      (e);\n  \\end{tikzpicture}\n  \\caption{Multiple lines}\n  \\label{fig:multi-line}\n\\end{figure}\n\n\n\\end{document}\n", "meta": {"hexsha": "917b8da75a100fc4d8cd74ce96910d549c3e0f66", "size": 9699, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory/main.tex", "max_stars_repo_name": "maje91/draw", "max_stars_repo_head_hexsha": "59207fd3aad6c121dd0a08dee76cfd11f745a1d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "theory/main.tex", "max_issues_repo_name": "maje91/draw", "max_issues_repo_head_hexsha": "59207fd3aad6c121dd0a08dee76cfd11f745a1d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "theory/main.tex", "max_forks_repo_name": "maje91/draw", "max_forks_repo_head_hexsha": "59207fd3aad6c121dd0a08dee76cfd11f745a1d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.6605504587, "max_line_length": 82, "alphanum_fraction": 0.6141870296, "num_tokens": 3643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7003162535147915}}
{"text": "\\newcommand\\vol{\\mathit{vol}}\n\n\\chapter{Conductance, Expanders and Cheeger's Inequality}\n\\label{chap:cheegersInequality}\n\\sloppy\n\nA common algorithmic problem that arises is the problem of partitioning the vertex set $V$ of a graph $G$ into clusters $X_1, X_2, \\dots, X_k$ such that \n\\begin{itemize}\n    \\item for each $i$, the \\emph{induced} graph $G[X_i] = (X_i, E \\cap (X_i \\times X_i))$ is \"well-connected\", and\n    \\item only an $\\epsilon$-fraction of edges $e$ are not contained in any induced graph $G[X_i]$ (where $\\epsilon$ is a very small constant).\n\\end{itemize}\n\n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[scale=0.25]{fig/fig1_lecCheeger}\n    \\caption{After removing the red edges (of which there are few in relation to the total number of edges), each connected component in $G$ is \"well-connected\".}\n\\end{figure}\n\nIn this lecture, we make precise what \"well-connected\" means by introducing the notions of \\emph{conductance} and \\emph{expanders}. \n\nBuilding on the last two lectures, we show that the second eigenvalue of the Laplacian $L$ associated with graph $G$ can be used to certify that a graph is \"well-connected\" (more precisely the second eigenvalue of a normalized version of the Laplacian). This result, called Cheeger's inequality, is one of the key tools in Spectral Graph Theory. Moreover, it can be turned into an algorithm that computes the partition efficiently!\n\n\\section{Conductance and Expanders}\n\n\\paragraph{Graph Definitions.} In this lecture, we let $G=(V,E)$ be unweighted\\footnote{Everything we present here also works for weighted graphs, however, we focus on unweighted graphs for simplicity.} and always be \\emph{connected}, and let $\\dd(v)$ be the degree of a vertex $v$ in $G$. We define the \\emph{volume} $\\vol(S)$ for any vertex subset $S \\subseteq V$, to be the sum of degrees, i.e. $\\vol(S) = \\sum_{v \\in S} \\dd(v)$.\n\nFor any  $A, B \\subseteq V$, we define $E(A, B)$ to be the set of edges in $E \\cap (A \\times B)$, i.e. with one endpoint in $A$ and one endpoint in $B$. We let $G[A]$ be the \\emph{induced} graph $G$ by $A \\subseteq V$, which is the graph $G$ restricted to the vertices $A$, i.e. an edge $e$ in $G$ is in $G[A]$ iff both endpoints are in $A$.\n\n\\paragraph{Conductance.} Given set $\\emptyset \\subset S \\subset V$, then we define the conductance $\\phi(S)$ of $S$ by\n\\[\n\\phi(S) = \\frac{|E(S, V \\setminus S)|}{ \\min\\{\\vol(S), \\vol(V \\setminus S) \\} }.\n\\]\nIt can be seen that $\\phi(\\cdot)$ is symmetric in the sense that $\\phi(S) = \\phi(V \\setminus S)$. We define the conductance of the graph $G$ denoted $\\phi(G)$ by\n\\[\n    \\phi(G) = \\min_{\\emptyset \\subset S \\subset V} \\phi(S). \n\\]\nWe note that finding the conductance of a graph $G$ is NP-hard. However, good approximations can be found as we will see today (and in a later lecture).\n\n\\paragraph{Expander and Expander Decomposition.} For any $\\phi \\in (0, 1]$, we say that a graph $G$ is a \\emph{$\\phi$-expander} if $\\phi(G) \\geq \\phi$. We say that the partition $X_1, X_2, \\dots, X_k$ of the vertex set $V$ is a \\emph{$\\phi$-expander decomposition} of quality $q$ if\n\\begin{itemize}\n    \\item each induced graph $G[X_i]$ is a $\\phi$-expander, and\n    \\item the number of edges not contained in any $G[X_i]$ is at most $q \\cdot \\phi \\cdot m$.\n\\end{itemize}\nToday, we obtain a $\\phi$-expander decomposition of quality $q = O(\\phi^{-1/2} \\cdot \\log n)$. In a few lectures, we revisit the problem and obtain quality $q = O(\\log^c n)$ for some small constant $c$. In practice, we mostly care about values $\\phi \\approx 1$.\n\n\\paragraph{An Algorithm to Compute Conductance and Expander Decomposition.} \nIn this lecture, the main focus is \\emph{not} to obtain an algorithm to compute conductance but rather only to show that the conductance of a graph can be approximated using the eigenvalues of the \"normalized\" Laplacian. \n\nHowever, this proof gives then rise to an algorithm $\\textsc{CertifyOrCut}(G, \\phi)$ that given a graph $G$ and a parameter $\\phi$ either: \n\\begin{itemize}\n    \\item \\emph{Certifies} that $G$ is a $\\phi$-expander, or\n    \\item Presents a \\emph{cut} $S$ such that $\\phi(S) \\leq \\sqrt{2\\phi}$.\n\\end{itemize}\nIn the graded homework, we ask you to make the procedure $\\textsc{CertifyOrCut}(G, \\phi)$ explicit, and then to show how to use it to compute a $\\phi$-expander decomposition. \n\n\\section{A Lower Bound for Conductance via Eigenvalues}\n\n\\paragraph{An Alternative Characterization of Conductance.} Let us now take a closer look at the definition of conductance and observe that if a set $S$ has $\\vol(S) \\leq \\vol(V)/2$ then\n\\[\n\\phi(S) = \\frac{|E(S, V \\setminus S)|}{ \\min\\{\\vol(S), \\vol(V \\setminus S)\\} } = \\frac{|E(S, V \\setminus S)|}{ \\vol(S) } = \\frac{\\vecone_S^\\trp \\LL \\vecone_S}{\\vecone_S^\\trp \\DD \\vecone_S}.\n\\]\nTo see this, observe that we can rewrite the numerator above using the Laplacian of $G$ as\n\\[\n|E(S, V \\setminus S)| = \\sum_{(u,v)\\in E} (\\vecone_S(u) - \\vecone_S(v))^2 =  \\vecone_S^\\trp \\LL \\vecone_S\n\\]\nwhere $\\vecone_S$ is the characteristic vector of $S$. Further, we can rewrite the denominator as \n\\[\n\\vol(S) = \\vecone_S^\\trp \\dd = \\vecone_S^\\trp \\DD \\vecone_S\n\\]\nwhere $\\DD = \\diag(\\dd)$ is the degree-matrix. We can now alternatively define the graph conductance of $G$ by\n\\begin{equation}\\label{eq:conductanceAltDef}\n\\phi(G) = \\min_{\\stackrel{\\emptyset \\subset S \\subset V,} {\\vol(S) \\leq \\vol(V)/2}} \\frac{\\vecone_S^\\trp \\LL \\vecone_S}{\\vecone_S^\\trp \\DD \\vecone_S} \n\\end{equation}\nwhere we use that $\\phi(S) = \\phi(V \\setminus S)$ such that the objective value is unchanged as long as for each set $\\emptyset \\subset S \\subset V$ either $S$ or $V \\setminus S$ is in the set that we minimize over.\n\n\\paragraph{The Normalized Laplacian.} Let us next define the \\emph{normalized} Laplacian \\[\n\\NN = \\DD^{-1/2} \\LL \\DD^{-1/2} = \\II -  \\DD^{-1/2} \\AA \\DD^{-1/2}.\n\\]\nTo learn a bit about this new matrix, let us first look at the first eigenvalue where we use the test vector $y = \\DD^{1/2}\\vecone$, to get by Courant-Fischer (see \\Cref{thm:courant-fischer-eigvec}) that\n\\begin{align}\\label{eq:plugInNormalizedVector}\n    \\lambda_1(\\NN) =\n    \\min_{\n      \\substack{ \\xx \\neq \\veczero}\n    }\n    \\frac{\\xx^\\trp \\NN\\xx}{\\xx^\\trp\\xx}  \\leq \\frac{\\yy^\\trp\\DD^{-1/2} \\LL \\DD^{-1/2} \\yy}{\\yy^\\trp\\yy} = \\frac{\\vecone^\\trp \\LL \\vecone}{\\yy^\\trp\\yy} = 0\n\\end{align}\nbecause $\\DD^{-1/2} \\DD^{1/2} = I$ and $\\LL \\vecone = 0$ (for the former we use the assumption that $G$ is connected). Since $\\NN$ is PSD (as you will show in the exercises), we also know $\\lambda_1(\\NN) \\geq 0$, so $\\lambda_1(\\NN) = 0$.\n\nLet us use Courant-Fischer again to reason a bit about the second eigenvalue of $\\NN$:\n\\begin{align}\\label{eq:courantFisherSecondEig}\n    \\lambda_2(\\NN) =\n    \\min_{\n      \\substack{ \\xx \\perp \\DD^{1/2}\\vecone \\\\ \\xx \\neq \\veczero}\n    }\n    \\frac{\\xx^\\trp \\NN\\xx}{\\xx^\\trp\\xx} = \n    \\min_{\n      \\substack{ \\zz \\perp \\dd \\\\ \\zz \\neq \\veczero}\n    }\n    \\frac{\\zz^\\trp \\DD^{1/2}  \\NN \\DD^{1/2} \\zz}{\\zz^\\trp \\DD^{1/2}\\DD^{1/2}\\zz} = \\min_{\n      \\substack{ \\zz \\perp \\dd \\\\ \\zz \\neq \\veczero}\n    } \\frac{\\zz^\\trp \\LL \\zz}{\\zz^\\trp \\DD \\zz}.\n\\end{align}\n\n\\paragraph{Relating Conductance to the Normalized Laplacian.} At this point, it might become clearer why $\\NN$ is a natural matrix to consider when arguing about conductance: if we could argue that for every $\\emptyset \\subset S \\subset V, \\vol(S) \\leq \\vol(V)/2$, we have $\\vecone_S \\perp \\dd$, then it would be easy to see that taking the second eigenvalue of $\\NN$ in equation \\ref{eq:courantFisherSecondEig} is a relaxation of the minimization problem \\ref{eq:conductanceAltDef} defining $\\phi(G)$.\n\nWhile this is clearly not true, we can still argue along these lines.\n\n\\begin{theorem}[Cheeger's Inequality, Lower Bound]\\label{thm:cheegerInequLowerBound}\nWe have $\\frac{\\lambda_2(\\NN)}{2} \\leq \\phi(G)$.\n\\end{theorem}\n\\begin{proof}\nInstead of using $\\vecone_S$ directly, we shift $\\vecone_S$ by $\\vecone$ such that it is orthogonal to $\\dd$: we define $\\zz_S = \\vecone_S - \\alpha \\vecone$ where $\\alpha$ is the scalar that solves\n\\begin{align*}\n       0 &= \\dd^\\trp \\zz_S \\\\\n       \\iff 0 &= \\dd^\\trp(\\vecone_S - \\alpha \\vecone)\\\\\n       \\iff 0 &= \\dd^\\trp \\vecone_S - \\alpha  \\dd^\\trp\\vecone \\\\\n       \\iff \\alpha &= \\frac{\\dd^\\trp \\vecone_S}{\\dd^\\trp\\vecone} = \\frac{\\vol(S)}{\\vol(V)}.\n\\end{align*}\n\nTo conclude the proof, it remains to argue that $\\frac{\\vecone_S^\\trp \\LL \\vecone_S}{\\vecone_S^\\trp\\DD\\vecone_S} \\geq \\frac{1}{2} \\cdot \\frac{\\zz_S^\\trp \\LL \\zz_S}{\\zz_S^\\trp\\DD\\zz_S}$:\n\\begin{itemize}\n    \\item Numerator: since $\\vecone^\\trp \\LL \\vecone = 0$, we have that $\\vecone_S^\\trp \\LL \\vecone_S = \\zz_S^\\trp \\LL \\zz_S$.\n    \\item Denominator: observe by straight-forward calculations that \\begin{align*}\n        \\zz_S^\\trp\\DD\\zz_S &= \\vol(S) \\cdot (1-\\alpha)^2 + \\vol(V \\setminus S) \\cdot (-\\alpha)^2\\\\\n        &= \\vol(S) - 2\\vol(S) \\cdot \\alpha + \\vol(V) \\cdot \\alpha^2\\\\\n        & = \\vol(S) -   \\frac{\\vol(S)^2}{\\vol(V)} \\\\\n        & = \\vol(S) - \\vol(S) \\cdot  \\frac{\\vol(S)}{\\vol(V)}\\\\\n        & \\geq \\frac{1}{2}\\vol(S) = \\frac{1}{2}\\vecone_S^\\trp\\DD\\vecone_S\n    \\end{align*}\n    where we use the assumption that $\\vol(S) \\leq \\vol(V)/2$.\n\\end{itemize}\n\\end{proof}\n\n\\section{An Upper Bound for Conductance via Eigenvalues}\n\nSlightly more surprisingly, we can also show that the second eigenvalue $\\lambda_2(\\NN)$ can be used to upper bound the conductance.\n\n\\begin{theorem}[Cheeger's Inequality, Upper Bound]\\label{thm:cheegerInequUpperBound}\nWe have $\\phi(G) \\leq \\sqrt{2 \\cdot \\lambda_2(\\NN)}$.\n\\end{theorem}\n\\begin{proof}\nTo prove the theorem, we want to show that for \\emph{any} $\\zz \\perp \\dd$, we can find a set $\\emptyset \\subset S \\subset V$, such that \n\\begin{equation}\\label{eq:findTightCutCheeger}\n\\frac{\\vecone_S^\\trp \\LL \\vecone_S}{\\vecone_S^\\trp \\DD \\vecone_S}  \\leq \\sqrt{2 \\cdot \\frac{\\zz^\\trp \\LL \\zz}{\\zz^\\trp \\DD \\zz}}.    \n\\end{equation}\n\nAs a first step, we would like to change $\\zz$ slightly to make it more convenient to work with:\n\\begin{itemize}\n    \\item we \\emph{renumber} the vertices in $V$ such that we have\n    \\[\n    \\zz(1) \\leq \\zz(2) \\leq \\dots \\leq \\zz(n).\n    \\]\n    \\item we \\emph{center} $\\zz$, that is we let $\\zz_c = \\zz - \\alpha \\vecone$ where $\\alpha$ is chosen such that \\begin{align*}\n        \\sum_{\\zz_c(i) < 0} \\dd(i) < \\vol(V)/2 \\text{ and }\n        \\sum_{\\zz_c(i) \\leq 0} \\dd(i) \\geq \\vol(V)/2\n    \\end{align*}\n    i.e. $\\sum_{\\zz_c(i) > 0} \\dd(i) \\leq \\vol(V)/2$.\n    \\item we \\emph{scale}, let $\\zz_{sc} = \\beta \\zz_c$ for some scalar $\\beta$ such that $\\zz_{sc}(1)^2 + \\zz_{sc}(n)^2 = 1$. \n\\end{itemize}\nIn the exercises, you will show that changing $\\zz$ to $\\zz_{sc}$ can only make the ratio we are interested in smaller, i.e. that\n$\\frac{\\zz^\\trp \\LL \\zz}{\\zz^\\trp \\DD \\zz} \\geq \\frac{\\zz_{sc}^\\trp \\LL \\zz_{sc}}{\\zz_{sc}^\\trp \\DD \\zz_{sc}}$. Thus, if we can show that equation \\ref{eq:findTightCutCheeger} holds for $\\zz_{sc}$ in place of $\\zz$, then it also follows for $\\zz$ itself.\n\nWe now arrive at the main idea of the proof: we define the set $S_{\\tau} = \\{ i \\in V \\;|\\; \\zz_{sc}(i) < \\tau\\}$ for some random variable $\\tau$ with distribution with probability density function\n\\begin{align}\\label{eq:cheegerDefineDensityFun}\n    p(t) = \\begin{cases}\n        2 \\cdot |t| &t \\in [\\zz_{sc}(1), \\zz_{sc}(n)],\n        \\\\\n        0 &\\text{otherwise}.\n        \\end{cases}\n\\end{align}\nSo, we have probability $\\mathbb{P}[a < \\tau < b] = \\int_{t=a}^b p(t)\\; dt$.\n\nSince the volume incident to $S_{\\tau}$ might be quite large, let us define $S$ for convenience by\n\\[\nS = \\begin{cases}\n        S_{\\tau} & \\vol(S_{\\tau}) < \\vol(V)/2,\n        \\\\\n        V \\setminus S_{\\tau} &\\text{otherwise}.\n        \\end{cases}\n\\]\n\n\\begin{claim}\\label{clm:cheegersInequInExpectation}\nWe have  $\\frac{\\mathbb{E}_{\\tau}\\left[\\vecone_S^\\trp \\LL \\vecone_S\\right]}{\\mathbb{E}_{\\tau}\\left[{\\vecone_S^\\trp \\DD \\vecone_S}  \\right]} \\leq \\sqrt{2 \\cdot \\frac{\\zz_{sc}^\\trp \\LL \\zz_{sc}}{\\zz_{sc}^\\trp \\DD \\zz_{sc}}}$.\n\\end{claim}\n\\begin{proof}\nRecall $\\vecone_S^\\trp \\LL \\vecone_S = E(S_{\\tau}, V \\setminus S_{\\tau})$, and by choice of $\\tau$, we have for any edge $e = \\{i,j\\} \\in E$ where $\\zz_{sc}(i) \\leq \\zz_{sc}(j)$,\n\\begin{align*}\n    \\mathbb{P}_{\\tau}[e \\in E(S_{\\tau}, V \\setminus S_{\\tau})] &= \\mathbb{P}_{\\tau}[\\zz_{sc}(i) < \\tau \\leq \\zz_{sc}(j)] \\\\ &= \\int_{t=i}^j 2|t|\\; dt = \\sgn{j} \\cdot \\zz_{sc}(j)^2 - \\sgn{i} \\cdot \\zz_{sc}(i)^2.\n\\end{align*}\nDistinguishing by cases, we get\n\\[\n\\sgn{j} \\cdot \\zz_{sc}(j)^2 - \\sgn{i} \\cdot \\zz_{sc}(i)^2 = \\begin{cases}\n    |\\zz_{sc}(i)^2 - \\zz_{sc}(j)^2| & \\sgn{i} = \\sgn{j},\n    \\\\\n    \\zz_{sc}(i)^2 + \\zz_{sc}(j)^2 &\\text{otherwise}.\n    \\end{cases} \n\\]\nWe can further upper bound either case by $ |\\zz_{sc}(i) - \\zz_{sc}(j)| \\cdot (|\\zz_{sc}(i)| + |\\zz_{sc}(j)|)$ (we leave this as an exercise).\n\nUsing our new upper bound, we can sum over all edges $e \\in E$ to conclude that\n\\begin{align*}\n   \\mathbb{E}_{\\tau}[|E(S_{\\tau}, V \\setminus S_{\\tau})|] &\\leq \\sum_{i \\sim j} |\\zz_{sc}(i) - \\zz_{sc}(j)| \\cdot (|\\zz_{sc}(i)| + |\\zz_{sc}(j)|) \\\\\n   &\\leq \\sqrt{\\sum_{i \\sim j} (\\zz_{sc}(i) - \\zz_{sc}(j))^2 \\cdot \\sum_{i \\sim j} (|\\zz_{sc}(i)| + |\\zz_{sc}(j)|)^2 }\n\\end{align*}\nwhere the last line follows from $\\langle \\xx, \\yy \\rangle^2 \\leq \\langle \\xx, \\xx \\rangle \\cdot \\langle \\yy, \\yy \\rangle$ (i.e. Cauchy-Schwarz).\\\\\n\nThe first sum should look familiar by now: it is simply the Quadratic Laplacian Form $\\sum_{i \\sim j} (\\zz_{sc}(i) - \\zz_{sc}(j))^2 = \\zz_{sc}^\\trp \\LL \\zz_{sc}$. \\\\\n\nIt is not hard to reason about the second term either\n\\[\n\\sum_{i \\sim j} (|\\zz_{sc}(i)| + |\\zz_{sc}(j)|)^2 \\leq 2\\sum_{i \\sim j} \\zz_{sc}(i)^2 + \\zz_{sc}(j)^2 = 2\\sum_{i \\in V} \\dd(i) \\zz_{sc}(i)^2 = 2 \\zz_{sc}^{\\trp} \\DD \\zz_{sc}.\n\\]\n\nPutting everything together, we obtain\n\\begin{align}\\label{eq:cheegerInequAlmostDone}\n   \\mathbb{E}_{\\tau}[|E(S_{\\tau}, V \\setminus S_{\\tau})|] \\leq \\sqrt{\\zz_{sc}^\\trp \\LL \\zz_{sc} \\cdot 2 \\zz_{sc}^{\\trp} \\DD \\zz_{sc}} = \\sqrt{2 \\cdot \\frac{\\zz_{sc}^\\trp \\LL \\zz_{sc}}{\\zz_{sc}^{\\trp} \\DD \\zz_{sc}} }\\; \\cdot \\; \\zz_{sc}^{\\trp} \\DD \\zz_{sc}\n\\end{align}\n\nWhile this almost looks like what we want, we still have to argue that $\\zz_{sc}^\\trp \\DD \\zz_{sc} = \\mathbb{E}_{\\tau}[\\vecone_S^\\trp \\DD \\vecone_S]$ to finish the proof.\n\nTo this end, when unrolling the expectation, we use a simple trick that splits by cases:\n\\begin{align*}\n    \\mathbb{E}_{\\tau}[\\vecone_S^\\trp \\DD \\vecone_{S}] &=\\sum_{i \\in V} \\dd(i) \\cdot \\mathbb{P}[i \\in S] \\\\\n    &=\\sum_{i \\in V, \\zz_{sc}(i) < 0} \\dd(i) \\cdot \\mathbb{P}[i \\in S \\land S=S_{\\tau}] + \\sum_{i \\in V, \\zz_{sc}(i) \\geq 0} \\dd(i) \\cdot \\mathbb{P}[i \\in S \\land S \\neq S_{\\tau}]\\\\\n     &=\\sum_{i \\in V, \\zz_{sc}(i) < 0} \\dd(i) \\cdot \\mathbb{P}[\\zz_{sc}(i) < \\tau \\land \\tau < 0] + \\sum_{i \\in V, \\zz_{sc}(i) \\geq 0} \\dd(i) \\cdot \\mathbb{P}[\\zz_{sc}(i) \\geq \\tau \\land \\tau \\geq 0]\n\\end{align*}\nwhere we use the centering of $\\zz_{sc}$ the definition of $S$ and that the event $\\{i \\in S \\land S=S_{\\tau}\\}$ can be rewritten as the event $\\{i < \\tau \\land \\tau < 0\\}$ (the other case is analogous). \n\nLet $i$ be a vertex with $\\zz_{sc}(i) < 0$, then the probability $\\mathbb{P}[i \\in S \\land S=S_{\\tau}]$ is exactly $\\zz_{sc}(i)^2$ by choice of the density function of $\\tau$ (again the case for $i$ with $\\zz_{sc}(i)$ non-negative is analgous). Thus, summing over all vertices, we obtain \n\\begin{align*}\n    \\mathbb{E}_{\\tau}[\\vecone_S^\\trp \\DD \\vecone_{S}] \n     &=\\sum_{i \\in V, \\zz_{sc}(i) < 0} \\dd(i) \\cdot \\mathbb{P}[\\zz_{sc}(i) < \\tau \\land \\tau < 0] + \\sum_{i \\in V, \\zz_{sc}(i) \\geq 0} \\mathbb{P}[\\zz_{sc}(i) \\geq \\tau \\land \\tau \\geq 0]\\\\\n     & = \\sum_{i \\in V } \\dd(i) \\cdot \\zz_{sc}(i)^2 = \\zz_{sc}^\\trp \\DD \\zz_{sc}.\n\\end{align*}\nTherefore, we can plug in our result directly into Equation \n\\ref{eq:cheegerInequAlmostDone} and the proof is completed by dividing both sides by $\\mathbb{E}_{\\tau}[\\vecone_S^\\trp \\DD \\vecone_{S}]$. \n\\end{proof}\n\nWhile \\Cref{clm:cheegersInequInExpectation} only ensures our claim in expectation, this is already sufficient to conclude that there exists some set $S$ that satisfies the same guarantees deterministically, as you will prove in Problem Set 4. This is often called the \\emph{probabilistic method of expectation} and can be seen from the definition of expectation. We have thus proven the upper bound of Cheeger's inequality.\n\\end{proof}\n\n\\section{Conclusion}\n\nToday, we have introduced the concepts of conductance and formalized expanders and expander decompositions. These are crucial concepts that you will encounter often in literature and also again in this course. They are a key tool in many recent breakthroughs in Theoretical Computer Science.\n\nIn the second part of the lecture (the main part), we discussed Cheeger's inequality which allows to relate the second eigenvalue of the normalized Laplacian to a graphs conductance. We summarize the full statement here.\n\n\\begin{theorem}[Cheeger's Inequality]\\label{thm:cheegerInequFull}\nWe have $\\frac{\\lambda_2(\\NN)}{2} \\leq \\phi(G) \\leq \\sqrt{2 \\cdot \\lambda_2(\\NN)}$.\n\\end{theorem}\n\nWe point out that this Theorem is tight as you will show in the exercises. The proof for Cheeger's inequality is probably the most advanced proof, we have seen so far in the course. The many tricks that make the proof work might sometimes seem a bit magical but it is important to remember that they are a result of many people polishing this proof over and over. The proof techniques used are extremely useful and can be re-used in various contexts. We therefore strongly encourage you to really understand the proof yourself!\n", "meta": {"hexsha": "ce94354d98ebab8554d96bea08df443f98673f04", "size": 17614, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "agao21_script/lecture_CheegerAndExpanders.tex", "max_stars_repo_name": "csssaz/agao21_script", "max_stars_repo_head_hexsha": "51044f4775e5e20d2c5fc5c0d035363e5beb66be", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-15T09:04:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-26T05:39:09.000Z", "max_issues_repo_path": "agao21_script/lecture_CheegerAndExpanders.tex", "max_issues_repo_name": "csssaz/agao21_script", "max_issues_repo_head_hexsha": "51044f4775e5e20d2c5fc5c0d035363e5beb66be", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "agao21_script/lecture_CheegerAndExpanders.tex", "max_forks_repo_name": "csssaz/agao21_script", "max_forks_repo_head_hexsha": "51044f4775e5e20d2c5fc5c0d035363e5beb66be", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2021-03-11T12:35:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-13T06:04:51.000Z", "avg_line_length": 69.6205533597, "max_line_length": 527, "alphanum_fraction": 0.6597025094, "num_tokens": 6176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8887588008585925, "lm_q1q2_score": 0.7002807845986561}}
{"text": "\\section{Support Vector Machine (SVM)}\n\n\\iffalse\n    % Here: Data is assumed linearly separable\n    % Below: additionally (orange) soft margin when not\n    % ===\n    \\textit{Primal}: \\: $\\min\\limits_{\\bm w, w_0} \\frac12 \\norm{\\bm w}^2$ \\: s.t. \\: $y_i(\\bm w^\\top \\bm x_i + w_0) \\geq 1$\\\\\n    \\quad $\\hookrightarrow$ intractable if $\\varphi(\\bm x_i)$ instead of $\\bm x_i$\n    \n    \\textit{Dual}: \\: $\\max\\limits_{\\bm\\alpha} \\sum_i \\alpha_i - \\frac12 \\sum_{i,j} \\alpha_i \\alpha_j y_i y_j \\bm x_i^\\top \\bm x_j$\\\\\n    \\qquad\\qquad s.t. \\: $\\alpha_i \\geq 0$; \\: $\\sum_i \\alpha_i y_i = 0$\\\\\n    \\quad $\\hookrightarrow$ solve $\\alpha$ via quadratic optimisation\n    \n    Optimal hyperplane: \\: $\\bm w^\\ast = \\sum_i \\alpha_i^\\ast y_i \\bm x_i$\\\\\n    \\quad $\\hookrightarrow$ $\\alpha_i^\\ast \\neq 0$ only for \\textit{support vectors}\n\\fi\n\n% ===\n\\textit{Primal} \\textcolor{OrangeRed}{(soft margin)}: \\: $\\min\\limits_{\\bm w, w_0 \\color{OrangeRed}, \\xi} \\frac12 \\norm{\\bm w}^2 \\color{OrangeRed} + C\\sum_i \\xi_i$\\\\\n\\qquad s.t. \\: $y_i(\\bm w^\\top \\bm x_i + w_0) \\geq 1 \\color{OrangeRed} - \\xi_i$ \\: and \\: $\\color{OrangeRed} \\xi_i \\geq 0$\\\\\n\\quad $\\hookrightarrow$ intractable if $\\varphi(\\bm x_i)$ instead of $\\bm x_i$\\\\\n\\quad $\\hookrightarrow$ $\\xi_i = 0$ means $\\bm x_i$ was \\underline{not} neglected\n\n\\textit{Dual}: \\: $\\max\\limits_{\\bm\\alpha} \\sum_i \\alpha_i - \\frac12 \\sum_{(i,j)} \\alpha_i \\alpha_j y_i y_j \\bm x_i^\\top \\bm x_j$\\\\\n\\qquad\\qquad s.t. \\: $0 \\leq \\alpha_i \\color{OrangeRed} \\leq C$; \\: $\\sum_i \\alpha_i y_i = 0$\\\\\n\\quad $\\hookrightarrow$ solve $\\alpha$ via quadratic optimisation\n\nOptimal hyperplane: \\: $\\bm w^\\ast = \\sum_i \\alpha_i^\\ast y_i \\bm x_i$\\\\\n\\quad $\\hookrightarrow$ $\\alpha_i^\\ast \\neq 0$ only for \\textit{support vectors}\n\nOptimal slack: \\: $\\xi_i^\\ast = \\max(0, 1 - y_i(\\bm w^{\\ast\\top} \\!\\bm x_i {+} w_0^\\ast))$\n\n% ===\n\\subsection{Structural SVMs}\n\n$\\min\\limits_{\\bm w \\color{OrangeRed}, \\xi} \\frac12 \\norm{\\bm w}^2 \\color{OrangeRed} + \\frac{C}{n} \\sum\\limits_{i\\leq n} \\xi_i$\n\\quad s.t. $\\color{OrangeRed} \\xi_i \\geq 0$ and $\\forall y' \\neq y_i :$\\\\\n\\quad $\\bm w^\\top \\Psi(x_i, y_i) \\geq \\Delta(y_i, y') + \\underbracket[.7pt][.7pt]{\\bm w^\\top \\Psi(x_i, y')}_{\\hookrightarrow \\text{ mislabelings}} \\color{OrangeRed} - \\xi_i \\color{Green} - \\epsilon$\\\\\n\n% ---\n%\\columnbreak\n% ---\n\n$\\Psi$ : \\textit{joint-feature map}; \\:\n$\\Delta$ : loss / class dissimilarity func.; \\:\n$\\bm w^\\top \\Psi(x,y)$ : compatibility score btw. $x$ and $y$; \\:\n$\\color{Green} \\epsilon$ : tolerance / universal slack variable.\n\n\\textbf{Prediction:} \\: $c(x) = \\argmax_y \\bm w^\\top \\Psi(x,y)$\n\\vspace{-3pt}\n\n\\textit{Note:} For optimal $\\bm w^\\ast$, $\\xi^\\ast$, $\\textrm{emp. risk}(\\bm w^\\ast) \\leq \\frac1n \\sum_i \\xi_i^\\ast$\n\n\\textbf{Training:} Start without any constraints.\\\\\nIn each iteration, add for each $(x_i,y_i)$ the constraint with $y' {\\neq} y_i$ that is the ``most violated'' and solve again with quadr. optimisation.\n\n% ===\n", "meta": {"hexsha": "937eceeaf218772280941215d888801b271c23f0", "size": 2925, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/AML20/sections/06_support_vector.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/AML20/sections/06_support_vector.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/AML20/sections/06_support_vector.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.4310344828, "max_line_length": 200, "alphanum_fraction": 0.6321367521, "num_tokens": 1129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.79053032607222, "lm_q1q2_score": 0.7001185353909951}}
{"text": "\\section{Data Mining}\n\\label{sec:dataMining}\n\nData mining is the computational process of discovering patterns in large data sets (``big data'') involving methods at the intersection of artificial intelligence, machine learning, statistics, and database systems. The overall goal of the data mining process is to extract information from a data set and transform it into an understandable structure for further use.\n\\\\RAVEN has support of several different data mining algorithms,\nsuch as:\n\\begin{enumerate}\n  \\item \\textit{Hierarchical methodologies}\n  \\item \\textit{K-Means}\n  \\item \\textit{Mean-Shift}, etc.\n\\end{enumerate}\nIn this section only few algorithms will be explained \n\n\\subsection{Clustering}\n\\label{clustering}\nA loose definition of clustering is the process of organizing objects into groups whose members are, in some way, similar.\nTherefore, a cluster is a collection of objects that are similar to each other and are dissimilar to the objects belonging to other clusters~\\cite{SurveyClustering,MandelliClusteringRESS}.\n\nThe similarity criterion is distance. Two or more objects belong to the same cluster if they are ``close'' according to a specified distance. The approach of using distance metrics to clustering is called distance-based clustering and is used in this work.\n\nThe notion of distance implies that the data points lay in a metric space \\cite{Mendelson75introduction}:\n\n    \\begin{mydef}[Metric Space]\n    A metric space is a space X provided with a function \\emph{d}:\n    \\begin{math}\n    f: X\\times X\\rightarrow \\mathbb{R}\n    \\end{math}\n    satisfying the following properties \\begin{math}\\forall \\vec{x},\\vec{y} \\in X \\end{math} :\n\n    \\begin{itemize}\n      \\item \\begin{math} d(\\vec{x},\\vec{y}) \\geqslant 0 \\end{math}\n      \\item \\begin{math} d(\\vec{x},\\vec{y}) = d(\\vec{y},\\vec{x}) \\end{math}\n      \\item \\begin{math} d(\\vec{x},\\vec{y}) \\leqslant d(\\vec{x},\\vec{z}) + d(\\vec{z},\\vec{y}) \\end{math}\n    \\end{itemize}\n\n    \\end{mydef}\n\nThe function \\begin{math} d(\\vec{x},\\vec{y}) \\end{math} is usually called the distance function. In a 2-dimensional Euclidean space ($\\mathbb{R}^{2}$), the distance between points can be calculated using the Pythagorean theorem which is the direct application of the Euclidean distance and is a special case of the most general Minkowski distance \\begin{math}\\ d_{2}(\\vec{x},\\vec{y}) = \\sqrt{(x_{1}-y_{1})^{2}+(x_{2}-y_{2})^{2}} \\end{math} between two points $\\vec{x}=(x_{1},x_{2})$ and $\\vec{y}=(y_{1},y_{2})$ in $\\mathbb{R}^{2}$.\n\nIn the literature~\\cite{Mendelson75introduction}, it is possible to find several types of distances other than the Euclidean and the Minkowski distance as shown in Table~\\ref{table:tableDist}. The approach of using distance metrics is called distance-based clustering and will be used in this dissertation.\n\n    \\begin{table}[ht]\n    \\caption {\\small Summary of the commonly used measures \\cite{Mendelson75introduction}.}\n    \\centering\n    \\begin{tabular}{c c }\n    \\hline\\hline\n    Measure & Form \\\\ [0.5ex]\n    \\hline\n    \\hline\n    Minkowski distance & \\begin{math}\\ d_{n}(\\vec{x},\\vec{y}) = (\\displaystyle \\sum_{k=1}^\\delta |x_{k}-y_{k}|^{n})^{\\frac{1}{n}} \\end{math} \\\\\n    Euclidean distance & \\begin{math}\\ d_{2}(\\vec{x},\\vec{y}) = (\\displaystyle \\sum_{k=1}^\\delta |x_{k}-y_{k}|^{2})^{\\frac{1}{2}} \\end{math} \\\\\n    Taxicab distance & \\begin{math}\\ d_{1}(\\vec{x},\\vec{y}) = \\displaystyle \\sum_{k=1}^\\delta |x_{k}-y_{k}| \\end{math} \\\\\n    Supremum distance & \\begin{math}\\ d_{0}(\\vec{x},\\vec{y}) = \\displaystyle max_{k} |x_{k}-y_{k}| \\end{math} \\\\\n    Mahalanobis distance & \\begin{math}\\ d_{M}(\\vec{x},\\vec{y}) = (\\vec{x}-\\vec{y})^{T} S^{-1} (\\vec{x}-\\vec{y}) \\end{math} \\\\\n    \\hline\n    \\end{tabular}\n    \\label{table:tableDist}\n    \\end{table}\n\nFrom a mathematical viewpoint, the concept of clustering~\\cite{SurveyClustering} aims to find a partition $\\mathbf{C}=\\{C_{1},\\ldots,C_{l},\\ldots,{C_{L}}\\}$\nof the set of $I$ scenarios\n    $\\mathbf{X} = \\{\\vec{x_{1}},\\ldots,\\vec{x_{i}},\\ldots,\\vec{x_{I}}\\}$\nwhere each scenario $\\vec{x_{i}}$ is represented as a $\\delta$-dimensional vector.\nEach $C_{l}$ $(l=1,\\ldots,L)$ is called a cluster. The partition\n    $ \\mathbf{C} $ of $ \\mathbf{X} $\nis given as follows\\footnote{In most clustering algorithms each scenario belongs to only one cluster. However this is not always the case. In fuzzy clustering methodologies~\\cite{ZioMaio} a scenario may be allowed to belong to more than one cluster with a degree of membership\n\\begin{math} u_{i,j}\\in [0,1] \\end{math} which represents the member coefficient of the $j$ scenario for the $i^{th}$ cluster and satisfies the following properties:\n\n$ \\sum_{i=1}^{K}u_{i,j}=1,  \\text{ and }  \\sum_{j=1}^{N}u_{i,j}<N, \\forall j $}:\n\n    \\begin{equation}\\label{eq: ClassRequier}\n        \\begin{cases} \\mathbf{C}_{l}\\neq\\varnothing, l=1,\\ldots,L \\\\\n                        \\\\\n                     \\bigcup_{l=1}^{L}\\mathbf{C}_{l}= \\mathbf{X} \\\\\n        \\end{cases}\n    \\end{equation}\n\n\\subsection{Hierarchical Methodologies}\n\\label{Hierarchical}\n\nThese methodologies organize the data set into a hierarchical structure according to a proximity matrix. Each element $d(i,j)$ of this matrix contains the distance between the the $i^{th}$ and the $j^{th}$ cluster center. The final results of this technique is a tree commonly called a dendrogram. This kind of representation has the advantages of providing a very informative description and visualization of the data structure even for high values of dimensionality.\n\nThe procedure to determine the dendrogram for a data set of $I$ points in an $\\delta$-dimensional space is the following:\n\n\\begin{enumerate}\n  \\item Start the analysis with a set of $I$ clusters (i.e., each point is considered as a cluster).\n  \\item Determine the proximity matrix $M$ (dimension: $I\\times I$): $M(i,j)= d(\\vec{x_{i}},\\vec{x_{j}})$ where $\\vec{x_{i}}$ and $\\vec{x_{j}}$ are the position of the $i^{th}$ and the $j^{th}$ cluster.\n  \\item For each point $p$ find the closest neighbor $q$  from the proximity matrix $M$\n  \\item Combine the points $p$ and $q$\n  \\item Repeat Steps 2, 3 and 4 until all the points of the data set are in the same cluster\n\\end{enumerate}\n\nThe advantage of this kind of algorithm is the nice visualization of the results that show the underlying structure of the data set. However, the computational complexity for most of the hierarchical algorithm is of the order of $\\mathcal{O}(I^{2})$ (where \\emph{I} is the number of points in the data set).\n\n\\subsection{\\emph{K}-Means}\n\\label{KMeans}\n\n\\emph{K}-Means clustering algorithms belong to the more general family of Squared Error algorithms. The goal is to partition $I$ data points $\\vec{x_{i}}$ $(i=1,\\ldots,I)$ into \\emph{K} clusters in which each data point maps to the cluster with the nearest mean. The stopping criterion is to find the global minimum of the error squared function $\\chi$ defined as:\n\n\\begin{equation}\n    \\chi = \\displaystyle \\sum_{i=1}^K \\displaystyle \\sum_{x_{j}\\in C_{i}} |\\vec{x_{j}}-\\vec{\\mu_{i}}|^{2}\n\\end{equation}\n\nwhere $\\vec{\\mu_{i}}$ is the centroid (i.e., the center) of the cluster $C_{i}$.\n\nThe procedure to determine the centroids $\\vec{\\mu_{i}}$ of \\emph{K} clusters (${C_{1},\\ldots,C_{K}}$) is the following:\n\n\\begin{enumerate}\n  \\item Start with a set of $K$ random centroids distributed in the state space\n  \\item Assign each pattern to the the closest centroid\n  \\item Determine the new $K$ centroids according to the point-centroid membership\n\n    \\begin{equation}\n        \\mu_{i} = \\displaystyle \\frac{1}{N_{i}} \\sum_{\\vec{x_{j}}\\in C_{i}} \\vec{x_{j}}\n    \\end{equation}\n\n    where $N_{i}$ corresponds to the number of of data points in the $i^{th}$ cluster.\n\n  \\item Repeat Steps 2 and 3 until convergence is met (i.e., until a minima of the $\\chi$ function is reached)\n\\end{enumerate}\n\n\\emph{K}-Means algorithm is one of the most popular and used methodologies also due to the fact that is very straightforward to implement and the computational time is directly proportional to the cardinality of data points (i.e., $\\mathcal{O}(I)$ where \\emph{I} is the number of data points). The main disadvantage is that the algorithm is sensitive to the choice of the initial partition and may converge to a local minimum of the error squared function~\\cite{JainAlgor88}. Another disadvantage of this algorithm is that is only able to identify clusters having spherical or ellipsoidal geometry. Thus, \\emph{K}-Means is not able to identify clusters of points having arbitrary shapes. Moreover, the number of cluster \\emph{K} to be obtained is specified by the user prior the clustering process.\n\n%\\subsection{Fuzzy C-Means}\n%\\label{FuzzyCMeansn}\n%\n%Fuzzy \\emph{C}-Means clustering is a clustering methodology that is based on fuzzy sets and, hence, it allows a data point to belong to more that one cluster~\\cite{FuzzyBezdek,DunnFuzzy}. Similar to the \\emph{K}-Means clustering, the objective is to find a partition of $C$ fuzzy centers to minimize the function $J$ defined as following:\n%\n%\\begin{equation}\n%    J = \\displaystyle \\sum_{i=1}^I \\displaystyle \\sum_{j=1}^C u_{ij}^{m}|\\vec{x_{i}}-\\vec{\\mu_{j}}|^{2}\n%\\end{equation}\n%\n%where:\n% \\begin{itemize}\n%   \\item $u_{ij}^{m}\\in[0,1]$ is the membership coefficient of the data point $\\vec{x_{i}}$ for the $j^{th}$ cluster having centroid $\\vec{\\mu_{j}}$,\n%   \\item $m\\in[0,\\infty)$ is the fuzzification parameter (usually set to $m=2$), and,\n%   \\item $\\mu_{j}$ is the centroid of the $j^{th}$ cluster center\n% \\end{itemize}\n%\n%The procedure to determine the centroids (or, equivalently, cluster centers)\n%$ \\vec{\\mu_{j}}$ $(j=1,\\ldots,C)$ of $C$ clusters is the following:\n%\n%\\begin{enumerate}\n%  \\item Initialize the $U=[u_{ij}^{m}]$ matrix\n%  \\item Calculate the set of $C$ centroids  as following:\n%\n%          \\begin{equation}\n%            \\mu_{j}=\\frac{\\sum_{i=1}^N u_{ij}^{m}x_{i}}{\\sum_{i=1}^N u_{ij}^{m}}\n%          \\end{equation}\n%\n%  \\item Update the matrix $U=[u_{ij}^{m}]$ as following:\n%\n%          \\begin{equation}\n%            u_{ij}^{m}=\\frac{1}{\\sum_{k=1}^C (\\frac{|x_{i}-\\mu_{j}|}{|x_{i}-\\mu_{k}|})^{\\frac{2}{m-1}}}\n%          \\end{equation}\n%\n%  \\item Repeat Steps 2 and 3 until convergence, i.e. if \\begin{math} |U^{(K+1)}-U^{(K)}|<\\epsilon \\end{math}\n%\\end{enumerate}\n%\n%Fuzzy \\emph{C}-Means clustering is very similar to the \\emph{K}-Means. As seen for the \\emph{K}-Means, Fuzzy \\emph{C}-Means can also converge to a local minima of the convergence criterion function~\\cite{FuzzyBezdek}.\n%Like \\emph{K}-Means, it is not able to identify cluster of points having arbitrary shapes but only clusters having ellipsoidal or spherical geometry and the number of clusters \\emph{C} to be obtained is specified by the user prior the clustering process.\n%Fuzzy \\emph{C}-Means algorithms can be useful when the boundaries among clusters are ambiguous and not well defined.\n\n\\subsection{Mean-Shift}\n\\label{Mean-Shift}\n\nThe Mean-Shift algorithm~\\cite{EstimationGradient} is a non-parametric iterative procedure that can be used to assign each point to one cluster center through a set of local averaging operations~\\cite{EstimationGradient}. The local averaging operations provide empirical cluster centers within the locality and define the vector which denotes the direction of increase for the underlying unknown density function.\n\nThe underlying idea is to treat each point $\\vec{x_{i}}$ $(i=1,\\ldots, I)$ of the dataset as an empirical probability distribution function using  kernel $K(\\vec{x}): \\mathbb{R}^{M\\cdot K}\\rightarrow \\mathbb{R}$. This multivariate kernel density resides in a multidimensional space where regions with high data density (i.e., modes) correspond to local maxima of the density estimate $f_{I}(\\vec{x})$~\\cite{CacoullosEstimation}  defined by:\n\\begin{equation}\n    f_{I}(\\vec{x})=\\frac{1}{Ih^{d}}\\sum_{i=1}^{I} K\\left(\\frac{\\vec{x}-\\vec{x_{i}}}{h}\\right),\n    \\label{eq:density:estimate}\n\\end{equation}\nwhere $\\vec{x}\\in \\mathbb{R}^{M\\cdot K}$ and $h$ is often referred as the bandwidth associated with the kernel.\n\nThe kernel in Equation ~\\ref{eq:density:estimate} serves as a weighting function~\\cite{CacoullosEstimation} associated with each data point and is expressed as:\n\\begin{equation}\n    K(\\vec{x})=c_{k} k(\\norm{\\vec{x}}^{2})\n\\end{equation}\nwhere $k(x):[0,\\infty]\\rightarrow \\mathbb{R}$ is referred as the \\emph{kernel profile} and $c_{k}$ is a normalization constant. The profile satisfies the following properties:\n\\begin{itemize}\n  \\item $k(x)$ is non negative\n  \\item $k(x)$ is non increasing (i.e., $k(a)\\geq k(b)$ if $a<b$)\n  \\item $k(x)$ is piecewise continuous and $\\int_0^\\infty \\! k(x) \\, dx < \\infty$\n\\end{itemize}\n\nIn order to estimate the data points with highest probability from an initial estimate (i.e., the modes of $f_{I}(\\vec{x})$), consider the gradient of the density function $\\nabla_{x} f_{I}(\\vec{x})=0$ ~\\cite{EstimationGradient} where\n\\begin{eqnarray}\n\\label{gradient}\n    \\nabla_{x} f_{I}(\\vec{x}) & = & \\frac{2 c_{k}}{I h^{d+2}} \\sum_{i=1}^{I}(\\vec{x}-\\vec{x_{i}})k'\\left(\\norm{\\frac{\\vec{x}-\\vec{x_{i}}}{h}}^{2}\\right) \\nonumber \\\\\n    & = & \\underbrace{\\frac{2 c_{k}}{I h^{d+2}} \\left(\\sum_{i=1}^{I} g\\left(\\norm{\\frac{\\vec{x}-\\vec{x_{i}}}{h}}^{2}\\right)\\right)}_{A}\n    \\underbrace{\\left(\\frac{\\sum_{i=1}^{I}\n    \\vec{x} g\\left(\\norm{\\frac{\\vec{x}-\\vec{x_{i}}}{h}}^{2}\\right)}{\\sum_{i=1}^{I} g\\left(\\norm{\\frac{\\vec{x}-\\vec{x_{i}}}{h}}^{2}\\right)}-\\vec{x}\\right)}_{B},\n\\end{eqnarray}\nwhich points in the direction of the increase in kernel density estimate. The kernel $K(\\vec{x})$ is also referred to as the shadow of $G(\\vec{x})=c_{g} g(\\norm{\\vec{x}}^{2})$~\\cite{Mode-seekingMedoidshifts} where $c_{g}$, similar to $c_{k}$, is a normalization constant and $g(x)$ is the derivative of $k(x)$ over $x$, i.e., $g(x)=k'(x)$. In the equation above, the first term denoted as $A$ is a scalar proportional to the density estimate computed with the kernel $G(\\vec{x})$ and does not provide information regarding where the mode resides. Unlike $A$, the vector quantity $B$, which is the second term in the equation above, is difference between the weighted mean\n\\begin{equation}\n\tm(\\vec{x})=\\frac{\\sum_{i=1}^{I}\\vec{x} g(\\norm{\\frac{\\vec{x}-\\vec{x_{i}}}{h}}^{2})}{\\sum_{i=1}^{I} g(\\norm{\\frac{\\vec{x}-\\vec{x_{i}}}{h}}^{2})}.\n\\end{equation}\n\nand the initial estimate $\\vec{x}$. This term points in the direction of local increase in density using kernel $G(\\vec{x})$, hence provides a means to find the mode of the density. Note that all points used to compute a particular mode are considered to reside in the same cluster.\n\nSince each each data point $\\vec{x_{i}}$ (or scenario) is considered as an empirical probability distribution function, this consideration allows to include in the scenario clustering analysis also the possible uncertainty associated with each scenario.\n\n\\subsection{DBSCAN }\n\\label{DBSCAN }\n\nThe Density-Based Spatial Clustering of Applications with Noise (DBSCAN) algorithm views clusters as areas of high density of data points. The data points in the low-density areas are seen as noise and border points, which are actually separating the clusters. Clusters found by DBSCAN can be any shape because of this approach.\nThe main element of the DBSCAN algorithm is the concept of core samples, which are samples that are in areas of high density. Therefore, a cluster is a set of core samples, each close to each other (measured by some distance measure) and a set of non-core samples that are close to a core sample (but are not themselves core samples). There are two parameters to the algorithm: $min_samples$ and $eps$. Higher $min_samples$ or lower $eps$ indicate higher density necessary to form a cluster.\nA cluster is a set of core samples, that can be built by recursively by taking a core sample, finding all of its neighbors that are core samples, finding all of their neighbors that are core samples, and so on. A cluster also has a set of non-core samples, which are samples that are neighbors of a core sample in the cluster but are not themselves core samples; these are on the borders of a cluster.\nThe DBSCAN algorithm finds core samples of high density and expands clusters from them. It is good for data, which contains clusters of similar density.\n\n\\subsection{Dimensionality Reduction}\n\\label{sec:6DimRed.section}\n\nThe dimensionality $\\delta$ of each data point (i.e., each scenario) is equal to the product of the number of variables (i.e., $M$) chosen to represent each scenario multiplied by the number of times each variable has been sampled.\nIn order to reduce the computational time due to the high data dimensionality, the use of dimensionality reduction techniques was to reduce the number of variables $M$\\footnote{Other possible options are to reduce the number of sample instants $K$ or to observe the local properties of the covariance matrix $S$.}.\n\nThe raw data generated by DET methodologies contain the temporal behavior of a vast set of variables (e.g., temperature, pressure). These variables are often heavily correlated and, consequently, the information contained in the set of $M$ variables comprising the full state space can be condensed to a set of $N$ variables where $N <M$. The objective of the dimensionality reduction process is to determine those $N$ variables by finding the correlations among the original $M$ variables\\footnote{Note that those $N$ variables are not necessarily a subset of the original $M$ variables but, more likely, a combination of those $M$ variables.}.\n\nLinear algorithms, such as PCA~\\cite{JolliffePCA} or multidimensional scaling (MDS)~\\cite{MDS}, have the advantage that they are easier to implement but they can only identify linear correlation among variables. On the other hand, methodologies such as Local Linear Embedding~\\cite{lle} and ISOMAP~\\cite{isomap} are more computationally intensive but they are able to identify non-linear correlations.\n\nDimensionality reduction is the process of finding a bijective mapping function $\\mathfrak{F}$\n\\begin{equation}\\label{eq:dimRed}\n    \\mathfrak{F}:\\mathbb{R}^{D}\\mapsto\\mathbb{R}^{d} \\mbox{ (where $d<D$)}\n\\end{equation}\nwhich maps the data points from the $D$-dimensional space into a reduced $d$-dimensional space (i.e. embedding on a manifold) in such a way that the distances between each point and its neighbors are preserved. In our applications $D = M+1$, i.e. $M$ state variables plus time $t$.\n\n\n\\subsection{Dimensionality Reduction: Linear Algorithms}\n\\label{dimRed}\nThis section describes the two most important algorithms for dimensionality reduction:\n\\begin{enumerate}\n  \\item PCA (see Section~\\ref{pca}), and,\n  \\item MDS (see Section~\\ref{mds}).\n\\end{enumerate}\n\n\\subsection{Principal Component Analysis (PCA)}\n\\label{pca}\n\nThe main idea behind PCA~\\cite{JolliffePCA} is to perform a linear mapping of the data set onto a lower dimensional space such that the variance of the data in the low-dimensional representation is maximized.\n\nThis is accomplished by determining the eigenvectors and their corresponding eigenvalues of the data covariance matrix\\footnote{Given a data set in form of a vector $Z$, rows correspond to data dimensions ($D$) and columns correspond to data observations ($\\Lambda$), the covariance matrix $S$ is determined as: $S=\\frac{1}{\\Lambda-1}Z'Z$.}\n$S$.\nThe eigenvectors that correspond to the largest eigenvalues (i.e., the principal components) can be used as a set of basis functions. Thus, the original space is reduced to the space spanned by a few eigenvectors.\n\n\nThe algorithm is very straightforward to implement but, on the other hand, PCA is not able to identify non-linear correlations of more complex data sets.\n\n\n\\subsection{Multidimensional Scaling (MDS)}\n\\label{mds}\n\nMultidimensional scaling~\\cite{MDS} is a popular technique used to analyze the properties of data sets. The scope of this methodology is to find a set of dimensions that preserve distances between data points.\n\nThis is performed by:\n\\begin{enumerate}\n  \\item Creating dissimilarity matrix $D=[d_{ij}]$ where $d_{ij}$ is the distance between two points $x_i$ and $x_j$.\n  \\item Finding the hyper-plane that preserves the dissimilarity matrix $D$ (i.e., the \\emph{nearness} of points)\n\\end{enumerate}\n\nAs in PCA analysis, the algorithm can be easily implemented but it is not able to identify non-linear correlations of more complex data sets.\n\n", "meta": {"hexsha": "13294185c8352fc7ab8373b9cfe360df363fbafc", "size": 20401, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/theory_manual/dataMining.tex", "max_stars_repo_name": "rinelson456/raven", "max_stars_repo_head_hexsha": "1114246136a2f72969e75b5e99a11b35500d4eef", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 159, "max_stars_repo_stars_event_min_datetime": "2017-03-24T21:07:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:44:40.000Z", "max_issues_repo_path": "doc/theory_manual/dataMining.tex", "max_issues_repo_name": "rinelson456/raven", "max_issues_repo_head_hexsha": "1114246136a2f72969e75b5e99a11b35500d4eef", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1667, "max_issues_repo_issues_event_min_datetime": "2017-03-27T14:41:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T19:50:06.000Z", "max_forks_repo_path": "doc/theory_manual/dataMining.tex", "max_forks_repo_name": "rinelson456/raven", "max_forks_repo_head_hexsha": "1114246136a2f72969e75b5e99a11b35500d4eef", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 95, "max_forks_repo_forks_event_min_datetime": "2017-03-24T21:05:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-08T17:30:22.000Z", "avg_line_length": 77.5703422053, "max_line_length": 798, "alphanum_fraction": 0.7247193765, "num_tokens": 5724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7001185308193686}}
{"text": "\\section{The Axioms}\n\n\\subsection{Terms \\& Definitions}\n\n\\begin{itemize}\n\t\n\t\\item A \\textit{term} is well-defined in Set Theory if it \\textit{exists} and is \\textit{unique}\n\t\n\t\\item Term: $ x $ is a \\textit{subset} of $ y $ ($ x \\subseteq y$) if $ \\forall z (z \\in x \\implies z \\in y) $\n\t\n\\end{itemize}\n\n\\subsection{Extensionality}\n\\begin{equation*}\n\\forall x \\forall y (\\forall z (z \\in x \\iff z \\in y) \\implies x = y)\n\\end{equation*}\n\n\\begin{itemize}\n\t\n\t\\item If sets $ x $ and $ y $ have exactly the same members, then they are the same set\n\t\n\\end{itemize}\n\n\\subsection{Foundation}\n\\begin{equation*}\n\\forall x (\\exists y \\in x \\implies \\exists z (z \\in x \\land \\forall w (w \\in x \\implies w \\notin z)))\n\\end{equation*}\n\n\\begin{itemize}\n\t\n\t\\item If $ x $ is non-empty, then it has an $ \\in $-minimal member (there is some $ z \\in x $ such that every member of $ x $ is not a member of $ z $)\n\t\n\\end{itemize}\n\n\\subsection{Separation}\n\\begin{equation*}\n\\forall x_0 \\dots \\forall x_n \\forall w \\exists y \\forall z (z \\in y \\iff z \\in w \\land \\varphi (z, x_0 \\dots, x_n))\n\\end{equation*}\n\n\\begin{itemize}\n\t\n\t\\item Given any set $ w $,  there is a set $ y $ consisting of  exactly the elements $ z $ from $ w $ such that $ \\varphi(z) $. The $ \\varphi $s are \\textit{separated out} from $ w $ to get $ y $\n\t\t\n\t\\item Why do we need a $ w $? We would like to do na\\\"ive comprehension: $ \\exists y \\forall x (x \\in y \\iff \\varphi(x)) $\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item \\textit{(Russell) Any theory including na\\\"ive comprehension is inconsistent}\n\t\t\n\t\t%\t\\begin{proof}\n\t\t%\t\tLet $ \\varphi(x) = x \\notin x $ (i.e. $ \\varphi $ says $ x $ is not a member of itself).\n\t\t%\t\t\n\t\t%\t\tFix $ r $ such that for all $ x $,  $ x \\in r \\iff x \\notin x $. But then $ r \\in r \\iff r \\notin r $ which is a contradiction.\n\t\t%\t\\end{proof}\n\t\t\n\t\t\\item This also means there is no universal set, i.e. a set $ x $ such that $ \\forall y (y \\in x \\iff y = y) $\n\t\t\n\t\t%\t\\begin{proof}\n\t\t%\t\tSuppose there is such an $ x $. Then by separation we get $ \\RussellSet $.\n\t\t%\t\t\n\t\t%\t\tBut for all $ w $, $ w \\in \\RussellSet \\iff w \\notin w $. Since $ x $ contains all of the sets, $ \\RussellSet $ is Russell's set which is a contradiction.\n\t\t%\t\\end{proof}\n\t\t\n\t\\end{itemize}\n\t\n\n\t\n\\end{itemize}\n\n\\subsection{Pairing}\n\\begin{equation*}\n\\forall x \\forall y \\exists z (x \\in z \\land y \\in z)\n\\end{equation*}\n\n\\begin{itemize}\n\t\n\t\\item \n\t\n\\end{itemize}\n\n\\subsection{Union}\n\\begin{equation*}\n\\forall x \\exists z \\forall y \\forall w (y \\in w \\land w \\in x \\implies y \\in z)\n\\end{equation*}\n\n\n\\begin{itemize}\n\t\n\t\\item \n\t\n\\end{itemize}\n\n\\subsection{Powerset}\n\\begin{equation*}\n\\forall x \\exists y \\forall z (z \\subseteq x \\implies z \\in y)\n\\end{equation*}\n\n\\begin{itemize}\n\t\n\t\\item \n\t\n\\end{itemize}\n\n\n\\subsection{Replacement}\n\\begin{equation*}\naa\n\\end{equation*}\n\n\\begin{itemize}\n\t\n\t\\item \n\t\n\\end{itemize}\n\n\\subsection{Infinity}\n\\begin{equation*}\n\\exists x (\\exists y y \\in x \\land \\forall z (z \\in x \\implies \\set{z} \\in x))\n\\end{equation*}\n\n\\begin{itemize}\n\t\n\t\\item \n\t\n\\end{itemize}\n\n\\subsection{Choice}\n\\begin{equation*}\naa\n\\end{equation*}\n\n\\begin{itemize}\n\t\n\t\\item \n\t\n\\end{itemize}\n\n\n\n\n\n\n\n\n\n\n\n\n\\section{Models, Structures \\& Sequences}\n\n\\section{The Ordinals}\n\n\\section{Transfinite Induction and Recursion}\n\n\\section{The Cardinals}\n\n\\section{Infinite Cardinals \\& The Axiom of Choice}", "meta": {"hexsha": "41f3a39a3f7e58b36aa8238dc285842233dfe9b3", "size": 3327, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MATH3306/set_theory/set_theory.tex", "max_stars_repo_name": "mcoot/CourseNotes", "max_stars_repo_head_hexsha": "c643f46e32cdf4c567bf73d4a23784c834278803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATH3306/set_theory/set_theory.tex", "max_issues_repo_name": "mcoot/CourseNotes", "max_issues_repo_head_hexsha": "c643f46e32cdf4c567bf73d4a23784c834278803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATH3306/set_theory/set_theory.tex", "max_forks_repo_name": "mcoot/CourseNotes", "max_forks_repo_head_hexsha": "c643f46e32cdf4c567bf73d4a23784c834278803", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.1910828025, "max_line_length": 196, "alphanum_fraction": 0.6426209799, "num_tokens": 1174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623015, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.700118524062433}}
{"text": "\\lab{Invertible Affine Transformations and Linear Systems}{Invertible Affine Transformations and Linear Systems}\n\\label{lab:ChangeBasis}\n\\objective{Apply affine transformations to a set of vectors in $\\mathbb{R}^2$ and solve linear systems.}\n\n\\section*{Linear transformations in $\\mathbb{R}^2$}\n\\subsection*{Dilations}\nA \\emph{dilation} of the vector space rescales the vectors. \nGraphically, a dilation stretches or compresses the space. \nA linear transformation is a dilation if and only if its matrix representation is diagonal, so in particular all Type II elementary matrices are dilations. \nThe matrix $\\begin{pmatrix}\n1.5 & 0\\\\\n0 & 1.5 \\end{pmatrix}$ corresponds to the dilation in Figure \\ref{fig:dilation}.\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{stretch.pdf}\n\\caption{An example of a dilation. \nThe top image was stretched by a factor of $1.5$ in all directions, producing the bottom image.}\n\\label{fig:dilation}\n\\end{figure}\n\n\\begin{problem}\\label{prob:dilation}\nWrite a function that accepts an array of points and an array giving the stretching factors in each direction. \nYour function should return the dilated points. \nHint: To check your work, plot the original points and their images under the transformation using the function \\li{plotOldNew()} defined below.\n\\begin{lstlisting}\nimport numpy as np\nfrom matplotlib import pyplot as plt\n\ndef plotOldNew(old, new):\n    '''Inputs:\n    new -- a (2,n) numpy array containing x-coordinates on the \n            first row and y-coordinates on the second row.\n    old -- a (2,n) numpy array containing x-coordinates on the first\n            row and y-coordinates on the second row.\n    '''\n            \n    plt.subplot(2, 1, 1)\n    plt.scatter(old[0], old[1])\n    plt.axis('equal')\n    plt.subplot(2, 1, 2)\n    plt.scatter(new[0], new[1])\n    plt.show()\n\\end{lstlisting}\n\\end{problem}\n\n\\subsection*{Rotations}\nA second type of linear transformation is to rotate vectors around the origin. \nA rotation of $\\theta$ radians counterclockwise corresponds to the matrix $\\begin{pmatrix}\n\\cos(\\theta) & -\\sin(\\theta) \\\\\n\\sin(\\theta) & \\cos(\\theta)\n\\end{pmatrix}.$ \nWhen $\\theta = \\pi/3$ we get the rotation matrix illustrated in Figure \\ref{fig:rotate}.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{rotate.pdf}\n\\caption{An example of a rotation.\nThe top image was rotated by $\\pi/3$, producing the bottom image.}\n\\label{fig:rotate}\n\\end{figure}\n\n\\begin{problem}\n Write a function that accepts an array of points and the angle of rotation (in radians). \n Your function should return the rotated points. \n Hint: To check your work, plot the original points and their images under the transformation using the function \\li{plotOldNew()} defined in Problem \\ref{prob:dilation}.\n\\end{problem}\n\n\\subsection*{Shears}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{shear.pdf}\n\\caption{An example of a shear.\nThe top image was sheared horizontally to produce the bottom image.}\n\\label{fig:shear}\n\\end{figure}\n\nA third type of linear transformation is a \\emph{shear}, which ``slants'' a set of vectors. \nThe corresponding matrix is a Type III elementary matrix. \nA horizontal shear has the form $\\begin{pmatrix}\n1 & c \\\\\n0 & 1\n\\end{pmatrix}$ and a vertical skew has the form $\n \\begin{pmatrix}\n1 & 0 \\\\\nc & 1\n\\end{pmatrix}\n$. \nNotice that horizontal skews fix the $y$-coordinate of a vector while vertical skews fix the $x$-coordinate. \nThe horizontal shear in Figure \\ref{fig:shear} corresponds to the matrix $\\begin{pmatrix}\n1 & 1.02 \\\\\n0 & 1\n\\end{pmatrix}\n$.\n\n\n\\begin{problem}[Optional]\nWrite a function that accepts an array of points, a floating point argument that indicates the shearing amount, and an integer argument that indicates the direction of the shear (0 for horizontal, 1 for vertical). \nYour function should return the sheared points. \nHint: To check your work, plot the original points and their images under the transformation using the function \\li{plotOldNew()} defined in Problem \\ref{prob:dilation}.\n\\end{problem}\n\n\\subsection*{Reflections}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{reflect.pdf}\n\\caption{An example of a reflection. \nThe top image was reflected about the line $y = (1/\\sqrt{3})x$, producing the bottom image.}\n\\label{fig:reflect}\n\\end{figure}\nA fourth type of linear transformation is reflections about a line, also called \\emph{Householder transformations}. \nReflecting about a line spanned by $(l_1, l_2)$ corresponds to the matrix\n\\[\n\\frac{1}{l_1^2 + l_2^2}\n\\begin{pmatrix}\nl_1^2 - l_2^2 & 2l_1l_2 \\\\\n2l_1l_2 & l_2^2 - l_1^2\n\\end{pmatrix}.\n\\]\n\nFor example, the line $y=x$ is spanned by $(1, 1)$. \nIn this case the corresponding matrix $\\begin{pmatrix}\n0 & 1\\\\\n1 & 0\n\\end{pmatrix}$ is a Type I elementary matrix, in fact the only one of size $2 \\times 2$. \nAs another example, the reflection in Figure \\ref{fig:reflection} about the line $y = (1/\\sqrt{3})x$ corresponds to the matrix $\\frac{1}{4}\\begin{pmatrix}\n2 & 2\\sqrt{3}\\\\\n2\\sqrt{3} & -2\n\\end{pmatrix}$.\n\n\\begin{problem}[Optional]\nWrite a function that accepts an array of points and a 1-D array describing the axis of reflection (in the notation above, this argument is $(l_1, l_2)$. \nYour function should return the reflected points. \nHint: To check your work, plot the original points and their images under the transformation using the function \\li{plotOldNew()} defined in Problem \\ref{prob:dilation}.\n\\end{problem}\n\n\\subsection*{Composition of linear transformations}\nRecall that composition of linear transformations corresponds to matrix multiplication. \nFor example, if $S$ is a matrix representing a shear and $R$ is a matrix representing a rotation, then $RS$ represents a shear followed by a rotation.\n\nIn fact, any linear transformation of $\\mathbb{R}^2$ is a composition of the transformations discussed in this lab. \nThis is because reflections, dilations, and shears provide us with all the elementary matrices, and every matrix is a product of elementary matrices. \n\n\\section*{Affine transformations}\n\\subsection*{Translations}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{translate.pdf}\n\\caption{\nAn example of a translation.\nThe top image was translated by the vector $(2, 0)\\trp$ to produce the bottom image.}\n\\label{fig:translation}\n\\end{figure}\n\nA translation is a map $T: \\mathbb{R}^2 \\rightarrow \\mathbb{R}^2$ defined by $T(\\mathbf{x}) = \\mathbf{x}+\\mathbf{b}$ where $\\mathbf{b} \\in \\mathbb{R}^2$. \nFor example, if $\\mathbf{b} = (2, 0)\\trp$, then applying $T$ to an image will shift it left by 2. \nThis translation is illustrated in Figure \\ref{fig:translation}.\n\n\nTranslations are usually NOT linear maps. \nTherefore, they cannot be represented as matrix multiplication.\n\n\\begin{problem}\nWrite a function that accepts an array of points and an array indicating how much to shift them in each direction. \nThe function should return the translated points. \nHint: You can construct a $2 \\times 1$ array using the syntax \\li{np.array([[a], [b]])}. \nThis may be more convenient for broadcasting. \nAnother hint: To check your work, plot the original points and their images under the transformation using the function \\li{plotOldNew()} defined in Problem \\ref{prob:dilation}.\n\\end{problem}\n\n\\subsection*{Affine transformations}\nTranslations, together, with linear transformations, make up the broader class of transformations called ``affine transformations.\" \nThese are transformations of the form $T: \\mathbb{R}^2 \\to \\mathbb{R}^2$, $T(X) = AX + b$ where $A$ is an $n\\times n$ matrix and $b \\in \\mathbb{R}^n$. \nAffine transformations include all compositions of scalings, rotations, dilations, reflections, and translations. \nFor example, if $S$ represents a shear and $R$ a rotation, and if $\\mathbf{b}$ is a vector in $\\mathbb{R}^2$, then $T(\\mathbf{x}) = RS\\mathbf{x} + \\mathbf{b}$ first shears $\\mathbf{x}$, then rotates it, and finally translates it by $\\mathbf{b}$. \n\n\n\\begin{problem}\nImagine a particle $p_1$ rotating around a second particle $p_2$ which is moving through $\\mathbb{R}^2$ in a straight line. \nSuppose $p_2$ begins at the origin and $p_1$ begins at $(1, 0)$. \nWe can compute the trajectory of $p_1$ using affine transformations.\n\n\\begin{enumerate}\\label{prob:trajectory}\n\\item Write a function that returns the position of $p_1$ at a time $t$. \nYour function should accept a time $t$, an angular velocity $\\omega$, a direction vector $\\mathbf{v}$, and a speed $s$. \nAssume $p_1$ rotates with angular velocity $\\omega$ and $p_2$ moves in the direction of $\\mathbf{v}$ with speed $s$.\nThe location of $p_1$ at time $t$ can be computed as follows:\n\\begin{itemize}\n\\item Calculate the position of $p_2$ at time $t$ with the formula $(st/\\|\\mathbf{v}\\|) \\mathbf{v}$.\n\\item Calculate the position of $p_1$ as follows:\n\\begin{itemize}\n\\item Rotate $p_1$ by $t\\omega$ radians.\n\\item Translate the resulting vector by the vector equal to the position of $p_2$ at time $t$.\n\\end{itemize}\n\\end{itemize}\n\\end{enumerate}\n\\item Plot the trajectory of $p_1$ on the time interval $(0, 10)$ assuming $\\omega=\\pi$, $v=(1, 1)$, and $s=3$. \nYour graph should look something like Figure \\ref{fig:trajectory}.\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{trajectory.pdf}\n\\caption{Solution to Problem \\ref{prob:trajectory}.}\n\\label{fig:trajectory} \n\\end{figure}\n\\end{problem}\n\n\\section*{Linear systems}\nThis section describes efficient algorithms for solving systems of linear equations.\n\n\\subsection*{Programming elementry row operations}\nWhen you perform a row operation on a matrix, you are really left-multiplying by some elementary matrix. \nHowever, matrix multiplication is not the most efficient way to implement row operations. It is much faster to perform row operations by modifying the array in place, and only changing those entries that are affected by the operation. \nThe following code implements the three elementary row operations by modifying the array in place.\n\n\\lstinputlisting[style=fromfile]{row_opers.py}\n\n\\subsection*{Programming row reduction}\nWhen you solve a linear system by reducing the matrix with row operations, it is most efficient to reduce only to row echelon form (REF)\n\\footnote{We do not require leading coefficients to be 1 in the REF.} \nand then use back substitution. \nHere is some code that reduces a matrix to REF.\n\n\\begin{lstlisting}\n>>> A = np.array([[4., 5., 6., 3.],[2., 4., 6., 4.],[7., 8., 0., 5.]])\narray([[ 4.,  5.,  6.,  3.],\n       [ 2.,  4.,  6.,  4.],\n       [ 7.,  8.,  0.,  5.]])\n>>> A[1] -= (A[1,0]/A[0,0]) * A[0]\n>>> A[2] -= (A[2,0]/A[0,0]) * A[0]\n>>> A[2,1:] -= (A[2,1]/A[1,1]) * A[1,1:]\n>>> A\narray([[ 4. ,  5. ,  6. ,  3. ],\n       [ 0. ,  1.5,  3. ,  2.5],\n       [ 0. ,  0. , -9. ,  1. ]])\n\\end{lstlisting}\n\nIn the third row operation modified only a part of the third row because we knew that the first value would still be 0. \nModifying only those entries of the array that are affected by a row operation will save a lot of time when you are row reducing a large matrix.\n\nBeware that round-off error in row reduction can cause serious problems.\nSuppose we wish to row reduce a matrix $A$ as follows.\n\n\\begin{lstlisting}\n>>> A = np.array([[4., 5., 6., 3.],[2., 2.5, 6., 4.],[7., 8., 0., 5.]])\narray([[ 4.,  5.,  6.,  3.],\n       [ 2.,  2.5,  6.,  4.],\n       [ 7.,  8.,  0.,  5.]])\n>>> A[1] -= (A[1,0]/A[0,0]) * A[0]\n>>> A[2] -= (A[2,0]/A[0,0]) * A[0]\n\\end{lstlisting}\n\nIf we work this out by hand, at this point we have\n\n\\begin{equation}\\label{equ:correct_ans}\nA = \\begin{pmatrix}\n4&5&6&3 \\\\\n0&0&3&2.5 \\\\\n0&-7.5&-10.5&-.25\n\\end{pmatrix}.\n\\end{equation}\n\nIf we swap the second and third rows, then the matrix is in row echelon form. \nHowever, suppose that due to round-off error, the machine instead computes\n\n\\[\nA = \\begin{pmatrix}\n4&5&6&3 \\\\\n0&10^{-15}&3&2.5 \\\\\n0&-7.5&-10.5&-.25\n\\end{pmatrix}.\n\\]\n\nThe algorithm would then attempt to pivot on the \\li{A[1,1]} entry as follows.\n\n\\begin{lstlisting}\n>>> A[2,1:] -= (A[2,1]/A[1,1]) * A[1,1:]\n>>> A\narray([[ 4. ,  5.0e+00 , 6.00e+00 ,  3.000e-00 ],\n       [ 0. ,  1.0e-14 , 3.00e+00 ,  2.500e-00 ],\n       [ 0. ,  0.0e+00 , 2.25e+14 ,  1.875e+14 ]])\n\\end{lstlisting}\n\nThe round-off error in the \\li{A[1,1]} entry has affected the third row, and the matrix is now much different than the correct answer in (\\ref{equ:correct_ans}). \nIn larger matrices, round-off error can propagate through many steps in a calculation, resulting in garbage output.\n\nSome of NumPy's matrix algorithms use row reduction. \nNumPy's methods use several clever tricks to minimize the impact of round-off errors. \nHowever, these methods may still give you garbage output due to round-off error, especially if the matrix is \\emph{ill-conditioned}. \nYou should always be aware of this possibility.\n\n\\begin{problem}\n\\label{prob:REF}\nWrite a function which reduces a square matrix to REF. \nYou may make the following assumptions:\n\\begin{enumerate}\n\\item The matrix is invertible.\n\\item During your row reduction, a zero will never appear on the main diagonal.\n\\item All round-off errors may be ignored.\n\\end{enumerate}\nDuring a row operation, do not modify any entries that you know will be zero before and after the operation.\n\\end{problem}\n\n\\subsection*{The LU decomposition}\nThe LU decomposition of a square matrix $A$ is a factorization $A=LU$ where $U$ is an upper triangular and $L$ is a lower triangular matrix. \nIn fact, $U$ is the REF of $A$ and $L$ is a product of Type III elementary matrices whose inverses reduce $A$ to $U$. \nThus, the LU decomposition is a way of storing the REF and ``how we got there.''\n\nThe LU factorization of $A$ exists only when $A$ can be reduced to REF using only Type III elementary matrices (no row swaps). \nHowever, we can always permute the rows of $A$ to obtain a matrix that has an LU decomposition. \nIf $P$ encodes the row swaps, then a decomposition $PA = LU$ always exists. \n\nIf $A$ has an LU decomposition (not requiring row swaps), then we can find it as follows. \nReduce $A$ to REF with $k$ row operations, corresponding to matrices $E_1, \\ldots, E_k$. \nThen $U = E_k \\ldots E_2E_1A,$ where $U$ is the REF of $A$. \nBecause there were no row swaps, each $E_i$ is a lower triangular Type III matrix. Then $E_i^{-1}$ is also lower triangular. \nThus, $L=(E_k \\ldots E_2E_1)^{-1}$ is lower triangular, and $LU=A.$\n\nBecause $L=(E_k \\ldots E_2E_1)^{-1} = IE_1^{-1}E_2^{-1}\\ldots E_k^{-1}$, we can compute $L$ by right-multiplying the identity by the matrices we used to reduce $U$. \nIn fact, in this special situation, each right-multiplication will change only one entry of $L$. \nWe have the following algorithm for the LU decomposition, assuming it exists.\n\n%\n%\\begin{itemize}\n%\\item Make a copy, $U$, of $A$.\n%\\item Make an identity matrix $L$ that is the same shape as $A$.\n%\\item Iterate through the entries below the diagonal of $U$.\n%\n%Now for each entry below the main diagonal of $U$ do the following:\n%\t\\begin{itemize}\n%\t\\item Set the corresponding entry of $L$ to the quotient of the current entry of $U$ and the entry of the main diagonal of $U$ located above the current entry.\n%\t\\item Perform the type 3 row operation to set the current entry of $U$ to 0.\n%\t\tDo not modify any entries known to be 0.\n%\t\\end{itemize}\n%\\item Return $L$ and $U$\n%\\end{itemize}\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{LU Decomposition}{$A$}\n\\State $m, n \\gets \\shape{A}$ \n\\State $U \\gets \\makecopy{A}$\n\\State $L \\gets \\Id{n}$\n\\For{$j=0 \\ldots n-1$}\n    \\For{$i=j+1 \\ldots m-1$}\n    \\State $L[i,j] \\gets U[i, j]/U[j, j]$\n    \\State $U[i,j:] \\gets U[i,j:] - L[i,j]U[j, j:]$\n\t\\EndFor\n\\EndFor\n\\State \\pseudoli{return} $L, U$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The algorithm for LU decomposition of a matrix $A$. This algorithm returns lower triangular $L$ and upper triangular $U$ such that $A = LU$.}\n\\label{Alg:gram_schmidt}\n\\end{algorithm}\n\n\\begin{problem}\n\\label{prob:LU_copy}\nWrite a function that finds the LU decomposition of a square matrix. \nYou may assume that the matrix has an LU decomposition.\n\\end{problem}\n\nThe LU decomposition can be performed in-place by storing $U$ on and above the main diagonal of the array and storing $L$ below it.\nThe main diagonal of $L$ does not need to be stored since all its entries are ones.\n\n\n\\begin{problem}[Optional]\nModify your solution to Problem \\ref{prob:LU_copy} so that the function computes the LU decomposition in place.\n\\end{problem}\n\n\n\n\\subsection*{Applications of the LU decomposition}\nThe LU decomposition is a more efficient way to solve linear systems than row reduction, and it can also be used to quickly compute inverses and determinants. \nSciPy implements these methods in the \\li{linalg} module, specifically in the functions \\li{linalg.lu_factor}, \\li{linalg.solve}, \\li{linalg.inv}, and \\li{linalg.det}.\n\nLet us see how to use the LU decomposition to solve matrix equations. \nSuppose that after row swaps, $A$ has the decomposition $PA = LU$. \nThen $Ax=b$ is equivalent to $LUx=Pb$. \nWe can solve this system by first solving $Ly = Pb$ and then $Ux = y$. \nSince $L$ and $U$ are triangular, these systems can be solved with backward and forward substitution, which is faster than row reduction. \nThus, we can perform row reduction once to compute the $LU$ factorization of $A$, and then we can use substitution to solve $Ax=b$ many different values of $b$. \nThis technique is significantly faster than storing $A^{-1}$ and then computing $A^{-1}b$ (see Problem \\ref{prob:solve}).\n\n\\begin{problem}\\label{prob:solve}\nIn this problem you will solve the system $Ax = b$ for fixed $A$ and many different values of $b$. \nYou will do this in two ways. \nFor a random $1000 \\times 1000$ array $A$ and a random $1000 \\times 500$ array $B$ do the following.\n\\begin{enumerate}\n\\item Time \\li{la.lu_factor(A)}.\n\\item Time \\li{la.inv(A)}.\n\\item Store the output of \\li{la.lu_factor()}. Time \\li{la.lu_solve()} on this stored output and $B$.\n\\item Store the inverse of $A$. Time how long it takes to multiply $A^{-1}$ by $B$.\n\\item What can you conclude about the more efficient way to solve linear systems?\n\\end{enumerate}\n\\end{problem}\n\n\nOur technique for solving linear equations can also be used to invert matrices. \nWe can compute $A^{-1}$ by solving $LUx_i = P_i$ for every $P_i$ that is a column of $P$. \nThen $A^{-1}$ is the matrix with columns $x_1, x_2, \\ldots, x_n$. \n\nFinally, the LU decomposition also gives us an efficient way to compute determinants. \nFor if $PA=LU$, then $\\det(A) = [\\det(P)]^{-1}\\det(L)\\det(U)$. \nBut the determinant of a triangular matrix is the product of its diagonal entries, and every diagonal entry of $L$ is 1. \nAlso, $\\det(P)$ is the number of row swaps we applied to $A$ to put it in the appropriate form. \nSo if $U$ has diagonal entries $u_{ii}$ for $i=1, \\ldots, n$, then\n\n\\[\n\\det(A) = (-1)^S\\left(\\displaystyle\\prod_{i=1}^nu_{ii}\\right),\n\\]\n\nwhere $S$ is the number of row-swaps.\n\n\n\n%\\begin{problem}\n%\\label{prob:lusolve}\n%Write a function that takes the LU decomposition computed by the second function you made in Problem \\ref{prob:LU} and another array representing the right hand side of a linear system and modifies the second array in place so that it represents the solution to the linear system.\n%No changes to the array storing the LU decomposition are necessary.\n%\\end{problem}\n%\n\n\\begin{problem}[Optional]\n\\label{prob:det}\nWrite a function that finds the determinant of a matrix using \\li{la.lu_factor()} and the algorithm described above. \nRead the documentation to learn about the output of \\li{la.lu_factor()}.\nHint: If the $i^{th}$ entry of the output \\li{piv} does not equal $i$, this means that a row swap occurred.\n\\end{problem}\n\n\\subsection*{The Cholesky decomposition (Optional)}\nThe Cholesky decomposition requires half the calculations and memory of the LU decomposition. \nFurthermore, it is \\emph{numerically stable}, which means that round-off errors do not propagate throughout the computation. \nBecause of its efficiency and numerical stability, the Cholesky decomposition is used to solve least squares, optimization, and state estimation problems.\n\nHowever, the Cholesky decomposition is only applicable to Hermitian positive definite matrices. \nA matrix $A$ is positive definite if  $\\mathbf{z}\\trp A\\mathbf{z} > 0$ for all $\\mathbf{z} \\neq 0$. \nFurthermore, $A$ is Hermitian if $A = A^*$ where $A^* = \\overline{A\\trp }$, so a real Hermitian matrix is just a symmetric matrix. \nThe Cholesky decomposition is the matrix equivalent to taking the square root of a positive real number.\n\nThe Cholesky decomposition of a $A$ is a lower-triangular matrix $L$ such that\n\n\\begin{equation*}\n A = LL^*.\n\\end{equation*}\n\nThe entries of $L$ are calculated as follows.\n\n\\begin{align*}\n&L_{i,j} = \\frac{1}{L_{j,j}}\\left(A_{i,j} -\\sum_{k=1}^{j-1}{L_{i,k}L_{j,k}}\\right) \\mbox{ for $i>j$} \\\\ \\\\\n&L_{i,i} = \\sqrt{A_{i,i} - \\sum_{k=1}^{i-1}{L_{i,k}L_{i,k}}}.\n\\end{align*}\n\nNotice that the entries of $L$ are defined recursively, with dependencies as diagrammed in Figure \\ref{fig:cholesky}. \nThus, an implementation of the Cholesky decomposition must compute the entries of $L$ in the correct order.\n\n\\begin{figure}\n\\begin{tikzpicture}[red dot/.style={draw, circle, fill=red, red},\n\tnorm/.style={draw=none}, xscale=1.5, yscale=1.5]\n\n\\begin{scope}[shift={(4,0)}]\n\\draw [-,ultra thick](-.2,0)--(-.2,2.5);\n\\draw [-,ultra thick](2.7,0)--(2.7,2.5);\n\\draw [-,ultra thick](-.2,0)--(0,0);\n\\draw [-,ultra thick](-.2,2.5)--(0,2.5);\n\\draw [-,ultra thick](2.7,2.5)--(2.5,2.5);\n\\draw [-,ultra thick](2.7,0)--(2.5,0);\n\n\\node[norm,black](bk1)at(.25,2.25){\\LARGE \\textbullet};\n\\node[norm,black](bk2)at(.75,1.75){\\LARGE \\textbullet};\n\\node[norm,black!25!](b1)at(1.25,1.25){\\LARGE \\textbullet};\n\\node[norm,black](bk3)at(1.75,.75){\\LARGE \\textbullet};\n\\node[norm, black](bk4)at(2.25,.25){\\LARGE \\textbullet};\n\\node[norm, black!25!](b2)at(.25,1.25){\\LARGE \\textbullet};\n\\node[norm,black!25!](b3)at(.75,1.25){\\LARGE \\textbullet};\n\\node[norm,black!25!](b4)at(.25,.25){\\LARGE \\textbullet};\n\\node[norm,black!25!](b3)at(.75,.25){\\LARGE \\textbullet};\n\\node[norm, shadecolor](r1)at(1.25,.25){\\Huge \\textbullet};\n\n\\end{scope}\n\n\\begin{scope}\n\\draw [-,ultra thick](-.2,0)--(-.2,2.5);\n\\draw [-,ultra thick](2.7,0)--(2.7,2.5);\n\\draw [-,ultra thick](-.2,0)--(0,0);\n\\draw [-,ultra thick](-.2,2.5)--(0,2.5);\n\\draw [-,ultra thick](2.7,2.5)--(2.5,2.5);\n\\draw [-,ultra thick](2.7,0)--(2.5,0);\n\n\n\\node[norm, shadecolor](r1)at(1.75,.75){\\Huge \\textbullet};\n\\node[norm,black](bk1)at(.25,2.25){\\LARGE \\textbullet};\n\\node[norm,black](bk2)at(1.25,1.25){\\LARGE \\textbullet};\n\\node[norm,black](bk3)at(.75,1.75){\\LARGE \\textbullet};\n\\node[norm,black](bk4)at(2.25,.25){\\LARGE \\textbullet};\n\\node[norm,black!25!](bk1)at(.25,.75){\\LARGE \\textbullet};\n\\node[norm,black!25!](bk1)at(.75,.75){\\LARGE \\textbullet};\n\\node[norm, black!25!](bk1)at(1.25,.75){\\LARGE \\textbullet};\n\\end{scope}\n\\end{tikzpicture}\n\\label{fig:cholesky}\n\\caption{The entries of $L$ in the Cholesky decomposition are defined recursively, as illustrated in this picture. \nTo calculate the green entry, you need to know each of the light gray entries.}\n\\end{figure}\n\n\n\\begin{problem}[Optional]\nWrite a function that finds the Cholesky decomposition of a Hermitian positive definite matrix.\nHint: To generate symmetric positive definite matrices on which to test your function, recall that for any matrix $A$, the matrix $A\\trp A$ is symmetric and positive definite.\n\\end{problem}\n\nThe \\li{linalg} module of SciPy includes an optimized Cholesky decomposition. \nAs with the LU decomposition, SciPy has the methods \\li{la.cho_factor} and \\li{la.cho_solve}.\n\n\\begin{problem}[Optional]\nRepeat problem \\ref{prob:solve}, this time using the methods \\li{la.cho_factor} and \\li{la.cho_solve}.\n\\end{problem} \n", "meta": {"hexsha": "2416ff7119d4de6b2055efb386cdfb622ed4d559", "size": 23667, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/AffineTransformations/AffineTransformations.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Labs/AffineTransformations/AffineTransformations.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/AffineTransformations/AffineTransformations.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 46.134502924, "max_line_length": 281, "alphanum_fraction": 0.7165251194, "num_tokens": 7134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.853912760387131, "lm_q1q2_score": 0.7001173816929409}}
{"text": "\\chapter{Classification}\n\\begin{multicols*}{2}\n\n\\section{Naive Bayes Classifier}\n\n\\noindent Bayes' rule:\n$$P(c|d) = \\frac{P(d|c) P(c)}{P(d)}$$\n\n\\noindent Naive Bayes classifier:\n$$c=\\arg\\!\\max_{c_j \\in C} P(x_1, x_2, \\ldots,x_n|c_j)P(c_j)$$\n$$c=\\arg\\!\\max_{c_j \\in C} P(x_1|c_j)P(x_2|c_j)\\ldots P(x_n|c_j)P(c_j)$$\n$$c=\\arg\\!\\max_{c_j \\in C} P(x_j) \\prod_{i=1}^n P(x_i|c_j)$$\n\n\\noindent Smoothing:\n$$P(x_i|c_j) = \\frac{P(x_i,c_j)}{P(c_j)}$$\n$$P(x_i|c_j) = \\frac{P(x_i,c_j)+1}{P(c_j)+k}$$\n\n\\noindent where $k$ is the size of vocabulary\n\n\\section{K Nearest Neighbour Classification}\n\\noindent Algorithm:\n\\begin{itemize}\n    \\item Define $N$ as $k$ nearest neighbours of $d$\n    \\item Use majority vote in $N$ to classify $d$\n\\end{itemize}\n\\noindent kNN has high variance and low bias (memories more than generalise)\n\n\\section{Support Vector Machine (SVM)}\n\\noindent Idea: the original feature space can be mapped to some higher-dimensional feature space where the training set is separable\\\\\n\n\\noindent Linear separability means classes can be separated by a lines or hyperplanes\\\\\n\n\\noindent SVM maximises  the margin around the separating hyperplane. The decision function is specified by a subset of training samples called support vectors. \n\n\\section{Feature Selection: Chi-square}\n\\noindent Motivation: to reduce training time, improve generalisation, eliminate noise features, and avoids overfitting\\\\\n\n\\noindent The chi-square test is used to determine whether there is a significant difference between the expected frequencies and the observed frequencies in one or more categories. \n\n\\begin{center}\n\\begin{tabular}{ |c|c| } \n    \\hline\n    $A = \\#(t,c)$ & $B = \\#(\\sim t,c)$ \\\\\n    \\hline \n    $C = \\#(t,\\sim c)$ & $D = \\#(\\sim t,\\sim c)$ \\\\\n    \\hline\n\\end{tabular}\n\\end{center}\n\n$$\\chi^2(t,c) = \\frac{N\\times (AD - BC)^2}{(A+B) \\times (C+D) \\times (A+C) \\times (B+D)}$$\n$$N=A+B+C+D$$\n\n\\noindent If $\\chi^2 > 10.83$, we reject with 99\\% condident that the two variables / features are independent. Therefore, they are dependent and should be helpful as features for the classification.\n\n\\end{multicols*}\n", "meta": {"hexsha": "96277c6224ab5703a5f9401cb59dbfd34eb0ac6b", "size": 2111, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "classification.tex", "max_stars_repo_name": "Andyccs/CZ4034-information-retrieval-summary", "max_stars_repo_head_hexsha": "1636bbebc0fd7864e3d6234a57e0e978fbf7d5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2016-04-23T05:00:21.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-05T07:10:54.000Z", "max_issues_repo_path": "classification.tex", "max_issues_repo_name": "Andyccs/CZ4034-information-retrieval-summary", "max_issues_repo_head_hexsha": "1636bbebc0fd7864e3d6234a57e0e978fbf7d5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "classification.tex", "max_forks_repo_name": "Andyccs/CZ4034-information-retrieval-summary", "max_forks_repo_head_hexsha": "1636bbebc0fd7864e3d6234a57e0e978fbf7d5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.6964285714, "max_line_length": 199, "alphanum_fraction": 0.6968261487, "num_tokens": 692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694178, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7001173767658386}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\begin{document}\n\\section{ConstantAndMultiplicativeGaussianErrorModel}\n    An error model which assumes that the model error is a mixture between a\n    Gaussian base-level noise and a Gaussian heteroscedastic noise.\n\n    A mixture between a Gaussian base-level noise and a Gaussian\n    heteroscedastic noise assumes that the observable biomarker $X$\n    is related to the :class:`MechanisticModel` output by\n\n    $$\n        X(t, \\psi , \\sigma _{\\text{base}}, \\sigma _{\\text{rel}}) =\n        x^{\\text{m}} + \\left( \\sigma _{\\text{base}} + \\sigma _{\\text{rel}}\n        x^{\\text{m}}\\right) \\, \\epsilon ,\n    $$\n\n    where $x^{\\text{m}} := x^{\\text{m}}(t, \\psi )$ is the mechanistic\n    model output with parameters $\\psi$, and $\\epsilon$ is a\n    i.i.d. standard Gaussian random variable\n\n    $$\n        \\epsilon \\sim \\mathcal{N}(0, 1).\n    $$\n\n    As a result, this model assumes that the observed biomarker values\n    $x^{\\text{obs}}$ are realisations of the random variable\n    $X$.\n\n    At each time point $t$ the distribution of the observable biomarkers\n    can be expressed in terms of a Gaussian distribution\n\n    $$\n        p(x | \\psi , \\sigma _{\\text{base}}, \\sigma _{\\text{rel}}) =\n        \\frac{1}{\\sqrt{2\\pi} \\sigma _{\\text{tot}}}\n        \\exp{\\left(-\\frac{\\left(x-x^{\\text{m}}\\right) ^2}\n        {2\\sigma^2 _{\\text{tot}}} \\right)},\n    $$\n\n    where $\\sigma _{\\text{tot}} = \\sigma _{\\text{base}} +\n    \\sigma _{\\text{rel}}x^{\\text{m}}$.\n\n    Extends :class:`ErrorModel`.\n\n\n\\section{GaussianErrorModel}\n    An error model which assumes that the model error follows a Gaussian\n    distribution.\n\n    A Gaussian error model assumes that the observable\n    biomarker $X$ is related to the :class:`MechanisticModel`\n    output by\n\n    $$\n        X(t, \\psi , \\sigma) = x^{\\text{m}} + \\sigma \\epsilon ,\n    $$\n\n    where $x^{\\text{m}} := x^{\\text{m}}(t, \\psi )$ is the mechanistic\n    model output with parameters $\\psi$, and $\\epsilon$ is a\n    i.i.d. standard Gaussian random variable\n\n    $$\n        \\epsilon \\sim \\mathcal{N}(0, 1).\n    $$\n\n    As a result, this model assumes that the observed biomarker values\n    $x^{\\text{obs}}$ are realisations of the random variable\n    $X$.\n\n    At each time point $t$ the distribution of the observable biomarkers\n    can be expressed in terms of a Gaussian distribution\n\n    $$\n        p(x | \\psi , \\sigma ) =\n        \\frac{1}{\\sqrt{2\\pi} \\sigma }\n        \\exp{\\left(-\\frac{\\left(x-x^{\\text{m}}\\right) ^2}\n        {2\\sigma^2 } \\right)}.\n    $$\n\n    Extends :class:`ErrorModel`.\n\n\n\\section{LogNormalErrorModel}\n    An error model which assumes that the model error follows a Log-normal\n    distribution.\n\n    A log-normal error model assumes that the observable\n    biomarker $X$ is related to the :class:`MechanisticModel`\n    output by\n\n    $$\n        X(t, \\psi , \\sigma _{\\mathrm{log}}) =\n        y \\, \\mathrm{e}^{\\mu + \\sigma _{\\mathrm{log}} \\varepsilon },\n    $$\n\n    where $y := y(t, \\psi )$ is the mechanistic\n    model output with parameters $\\psi$, and $\\varepsilon$ is a\n    i.i.d. standard Gaussian random variable\n\n    $$\n        \\varepsilon \\sim \\mathcal{N}(0, 1).\n    $$\n\n    Here, $\\sigma _{\\mathrm{log}}$ is the standard deviation of\n    $\\log X$ and\n    $\\mu := -\\sigma _{\\mathrm{log}} ^2 / 2$ is chosen such that\n\n    $$\n        \\mathbb{E}[X] = y.\n    $$\n\n    As a result, this model assumes that the observed biomarker values\n    $x^{\\text{obs}}$ are realisations of the random variable\n    $X$.\n\n    At each time point $t$ the distribution of the observable biomarkers\n    can be expressed in terms of a log-normal distribution\n\n    $$\n        p(x | \\psi , \\sigma _{\\mathrm{log}} ) =\n        \\frac{1}{\\sqrt{2\\pi} \\sigma _{\\mathrm{log}} x}\n        \\exp{\\left(-\\frac{\n            \\left(\\log x - \\log y + \\sigma _{\\mathrm{log}}^2/2\\right) ^2}\n        {2\\sigma _{\\mathrm{log}}^2 } \\right)}.\n    $$\n\n    Extends :class:`ErrorModel`.\n\n\\section{MultiplicativeGaussianErrorModel}\n    An error model which assumes that the model error is a Gaussian\n    heteroscedastic noise.\n\n    A Gaussian heteroscedastic noise model assumes that the observable\n    biomarker $X$ is related to the :class:`MechanisticModel`\n    output by\n\n    $$\n        X(t, \\psi , \\sigma _{\\text{rel}}) =\n        x^{\\text{m}} + \\sigma _{\\text{rel}} x^{\\text{m}} \\, \\epsilon ,\n    $$\n\n    where $x^{\\text{m}} := x^{\\text{m}}(t, \\psi )$ is the mechanistic\n    model output with parameters $\\psi$, and $\\epsilon$ is a\n    i.i.d. standard Gaussian random variable\n\n    $$\n        \\epsilon \\sim \\mathcal{N}(0, 1).\n    $$\n\n    As a result, this model assumes that the observed biomarker values\n    $x^{\\text{obs}}$ are realisations of the random variable\n    $X$.\n\n    At each time point $t$ the distribution of the observable biomarkers\n    can be expressed in terms of a Gaussian distribution\n\n    $$\n        p(x | \\psi , \\sigma _{\\text{base}}, \\sigma _{\\text{rel}}) =\n        \\frac{1}{\\sqrt{2\\pi} \\sigma _{\\text{tot}}}\n        \\exp{\\left(-\\frac{\\left(x-x^{\\text{m}}\\right) ^2}\n        {2\\sigma^2 _{\\text{tot}}} \\right)},\n    $$\n\n    where $\\sigma _{\\text{tot}} = \\sigma _{\\text{rel}}x^{\\text{m}}$.\n\n    Extends :class:`ErrorModel`.\n\n\n\\end{document}", "meta": {"hexsha": "df1594e7ddaa0f7bc1f8b4d64392695c386ec2fb", "size": 5242, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chi/errorModelDocumentation.tex", "max_stars_repo_name": "Lethay/chi", "max_stars_repo_head_hexsha": "2182d8f9d54878b3f27670b157593f5a3bf9df4a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chi/errorModelDocumentation.tex", "max_issues_repo_name": "Lethay/chi", "max_issues_repo_head_hexsha": "2182d8f9d54878b3f27670b157593f5a3bf9df4a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chi/errorModelDocumentation.tex", "max_forks_repo_name": "Lethay/chi", "max_forks_repo_head_hexsha": "2182d8f9d54878b3f27670b157593f5a3bf9df4a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.8352941176, "max_line_length": 76, "alphanum_fraction": 0.6085463564, "num_tokens": 1596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542185, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.7000804618970736}}
